Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by Zbyl · Jun 19, 2012 at 08:26 PM · meshmeshcollidervolumetrianglequery

Find all triangles inside given bounds

I'd like to find all MeshCollider triangles inside a Sphere or a Box.

Unfortunately:

  • Physics.SphereCastAll() returns only first hit, so only one triangle.

  • Physics.RaycastAll() is not a volume query.

I want to analyze geometry around the character, so I need to limit the number of triangles to process. The physics engine has all the necessary data to answer such a query very quickly, but is there a way to do it using the provided interface?

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

1 Reply

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

Answer by Fattie · Jun 19, 2012 at 08:37 PM

You probably know, you could just look through the vertices, and determine if each one is in the box or not. (Couple lines of code.)

"The physics engine has all the necessary data to answer such a query very quickly"

Sounds vaguely sensible to me, but the answers to that type of question can be surprising !

http://answers.unity3d.com/questions/193695/in-unity-is-there-a-fast-way-to-find-nearby-triang.html

I don't necessarily see that PhysX would Know all the tris in a box. Just as you say, raycasting is not a volume query.


Aside: should one do spatial hashing?

In a word: no. I've never found it to be necessary.

Think about how incredibly fast it is to just check points in a box. (Even if you deliberately write the code AS BAD AS POSSIBLE, it's only gonna be two or three times slower than if you write the code as efficiently as possible! heh!!)

And don't forget - there are only a trivial amount of verts in video game meshes.

Quite simply, do it first with a couple of lines of code. If, incredibly, you find you need spatial hashing - just bolt it on LATER.

I take it back - once we had to use a spatial hash because of a weird algorithm that iteratively had to search various meshes many many times - so someone stuck in some hashing to speed it up a bit. ie, we replaced the couple of lines of code with some lame class that hashed it's way around space.

Don't forget during every everyday FRAME, for goodness sake, your 3D stack is performing miracles of computation, just to bring up the "click to continue" on the screen!

Comment
Add comment · Show 4 · 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 Zbyl · Jun 19, 2012 at 09:31 PM 0
Share

I've searched PhysX SD$$anonymous$$ and there seem to be no solution there either. Fortunately I've found octree implementation on Unity forums that looks promising for my purposes. Here's the link: http://forum.unity3d.com/threads/134554-A-solution-for-accurate-raycasting-without-mesh-colliders

avatar image Zbyl · Jun 19, 2012 at 09:34 PM 0
Share

I'm accepting this as an answer, cause building your own spatial tree, as suggested in the linked question, seems to be the only way.

avatar image Fattie · Jun 20, 2012 at 08:12 AM 0
Share

Hi Zbyl ...

for sure, but don't forget ... computers are incredibly fast these days Heh !!!

I do this sort of nonsense on a daily basis and I've never found the need to do any spatial hashing...

It's incredibly fast to just traverse ("use a for loop") any mesh you'd see in a video game.

So I'd encourage you to make a separate subsection of your project that has - err -- a for loop! and if you ever have any performance problems, have someone bolt in some spatial hashing at a later date.

I hope it helps in some way !!

avatar image Fattie · Jun 20, 2012 at 08:13 AM 0
Share

thanks for the big green tick BTW !

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Is it possible to select the colliding triangle of meshcollider? 1 Answer

Get the triangles of a convex mesh collider 1 Answer

Am I inside a volume? (Without ray cast and default colliders?) 0 Answers

Generate a highpoly sphere with mesh collider procedurally 2 Answers

combining meshes 0 Answers


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