Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by KeeganTawa · May 18, 2020 at 08:36 PM · raycastcollidermeshmeshestriangles

How to Detect All Mesh Triangles Within a Given Area

Hello - I'm looking for a way to detect all mesh triangles of a single mesh within a given area.

I've actually gotten this working, but ever method I've used is simply not performant enough - it totally crushes my framerate.

My current method of detection is to iterate through all mesh vertices and check their proximity to a RaycastHit.point on the mesh's surface.

When the icospherical mesh is sparse, as you can see in IcoPerformance_1.JPG, performance is good.

However, when the icospherical mesh becomes more dense, as you can see in IcoPerformance_2.JPG and IcoPerformance_3.JPG, performance simply tanks (as there are many more mesh vertices to iterate through).

Some other methods I've tried:

  • SphereCast and SphereCastAll only register the first impact with the mesh; not all impacted triangles.

  • I have tried casting a "cone" of RayCasts out to the surface of the mesh from the camera. This sortof works, but because of the nature of casting hundreds of individual rays, sometimes triangles get missed, especially small ones.

  • All of my triangles are linked to an abstract icospherical model in code. This model's triangular faces all have adjacency data; I have tried doing an adjacency search, and this works correctly, but unfortunately it also tanks performance.

There has got to be some method of simply detecting all mesh triangles within an area that I'm missing. Thank you in advance!

IcoPerformance 1: alt text

IcoPerformance 2: alt text

IcoPerformance 3:

icoperformance-1.jpg (143.0 kB)
icoperformance-2.jpg (202.9 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by KeeganTawa · May 20, 2020 at 03:42 PM

For anybody interested, I solved this problem by using a bounded volume search. My AbstractIcosphere, the data class that represents the icosphere before it reaches unity, is a QuadTree data structure. The shallowest level of the quad tree are the twenty icosahedral faces.

When "importing" the abstractIcosphere to unity, I set up the vertices using a "bounded volume" system. All vertices belong to one of the 20 parent icosahedral faces.

When making our vertex search, we first make a search for icosahedral regions that are within radius, and only search those regions for vertices.

This works very well up to a moderate density. For higher density regions, framerate drops to about 30fps. To solve this I will next create a second "bounded volume" tree...it will eventually become a bounded volume hierarchy.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image rguerrasa · Nov 30, 2020 at 12:53 AM 0
Share

Very interesting. I did a very similar thing with a plane in 2D. I wonder if there is a way to do this in the GPU instead, using shaders.

avatar image Navy_Seals · Oct 14, 2021 at 07:58 AM 0
Share

@KeeganTawa Thanks for the blog as well. I am trying to implement and test this from the blog

Can you share the example class for the class Triangle ? I get errors while implementing your code.

 [Serializable]
 public class Triangle
 {
     public Vector3 adjacency1;
     public Vector3 adjacency2;
     public Vector3 adjacency3;
 }

I get error here below as adjacency1, adjacency2, adjacency3.

  foreach (Triangle t in ring1)
             {
                 // Add adjacencies (duplicates will be skipped).
                 if (t.adjacency1.visible)
                 {
                     // Add adjacency 1 to all adjacencies.
                     allAdjacencies.Add(t.adjacency1);
 
                     // If adjacency 1 is not present in ring 2, save it to be added to the next ring 2.
                     if (!ring2.Contains(t.adjacency1))
                     {
                         // Save adjacency 1 to be added to Ring 2.
                         buffer.Add(t.adjacency1);
                     }
                 }
                 if (t.adjacency2.visible)
                 {
                     // Add adjacency 2 to all adjacencies.
                     allAdjacencies.Add(t.adjacency2);
 
                     // If adjacency 2 is not present in ring 2, save it to be added to the next ring 2.
                     if (!ring2.Contains(t.adjacency2))
                     {
                         // Save adjacency 2 to be added to Ring 2.
                         buffer.Add(t.adjacency2);
                     }
                 }
                 if (t.adjacency3.visible)
                 {
                     // Add adjacency 3 to all adjacencies.
                     allAdjacencies.Add(t.adjacency3);
 
                     // If adjacency 3 is not present in ring 2, save it to be added to the next ring 2.
                     if (!ring2.Contains(t.adjacency3))
                     {
                         // Save adjacency 3 to be added to Ring 2.
                         buffer.Add(t.adjacency3);
                     }
                 }
             }

Many thanks in advance

avatar image
0

Answer by Navy_Seals · Sep 29, 2021 at 10:25 AM

Do you have source code to this? I am trying to get triangles within a given area and find if the mesh is flat or not.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image KeeganTawa · Sep 29, 2021 at 05:23 PM 1
Share

Hey @Navy_Seals , I eventually wound up solving this in a much faster and more efficient way. I call it the "coupled ring search" and you can read about it here on my blog.

The big thing is that all of my triangles are "smart" triangles and have knowledge of their surroundings. Without this backing data structure, you won't be able to pull off the ring search.

avatar image Navy_Seals KeeganTawa · Oct 04, 2021 at 05:05 AM 0
Share

Dear @KeeganTawa, That's a fantastic blog! I really loved the simplicity of your explanation there. Please advice me how to make adjustment in the code to form a square or rectangle boundary by keeping the "observationCenter" in the middle. Many thanks and you saved the day!

avatar image Navy_Seals KeeganTawa · Oct 04, 2021 at 05:47 AM 0
Share

Also, Please share the code for the method "HighlightObservationGroup();". You have missed this in your blog. This will help a lot for me. I just bookmarked your blog. Wonderful work!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

220 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to find connected mesh triangles? 2 Answers

Mesh Collider Issue(?) - Raycast (ScreenPointToRay) Appears to Collide on Nothing 0 Answers

shooting raycast from each triangle on mesh and change its texture 0 Answers

Raycast to align character on MeshCollider normals 1 Answer

instanced mesh won't collide with raycast anymore 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges