- Home /
Mesh vs box collider collision
What would the best way to check a box collider vs a mesh to see what triangles intersect or are within a placed box collider, and if there are triangles that are cut by the box collider, identify those tri's specifically and their intersection points?
Would I have to make a mesh collider for the mesh than go from there?
Answer by Jesse Anders · Mar 22, 2011 at 08:00 PM
What you're describing is essentially a mesh clipping operation, which Unity doesn't have any built-in support for. Creating a mesh collider from the mesh probably won't help either, since the physics API doesn't support that sort of operation directly.
If you need to clip a mesh to a volume, you may have to code it yourself (or use an existing library that can be used with Unity). For the clipping process, check out Sutherland-Hodgman clipping.
Also, if you edit your post and provide some info about the higher-level problem you're trying to solve, people might be able to offer some more specific suggestions.
Do you happen to know of any libraries available? Or a good resource on OBB-Tri collision checking?
I don't know of any libraries off the top of my head that would be suitable and could be easily integrated with Unity. (That doesn't mean there aren't any though.) As far as resources go, Google (or the search engine of your choice) is probably your best bet. You could also try searching the forums at gamedev.net, checking geometrictools.com, etc. (The book 'Real-Time Collision Detection' also has some good info on clipping.)
Answer by efge · Mar 22, 2011 at 07:32 PM
You could use RaycastHit.triangleIndex. This function works only if the collider that was hit is a MeshCollider.
Its not a ray I need to test with though, but a whole box volume which will contain multiple triangles of a mesh.