Search Unity

Figuring out if two concave meshes are colliding/triggering

Discussion in 'Physics' started by Julien-Lynge, Aug 27, 2020.

  1. Julien-Lynge

    Julien-Lynge

    Joined:
    Nov 5, 2010
    Posts:
    142
    Hey all!

    I need to calculate whether any meshes in a scene are overlapping - basically, treat them as trigger colliders and check for OnTriggerEnter. Unfortunately, there are complications which make this a nightmare:
    • The meshes are of unknown shape, and will often be concave in very complex ways
    • The mesh colliders are pulled from the meshes themselves. We'll be trying to do automatic mesh decimation, but likely can't decimate more than 90%, meaning the mesh colliders will have 10k - 100k vertices regularly (from 100k to 1Mk vert objects)
    • Because of this, we most likely can't use an off-the-shelf solution to convert to an equivalent set of convex meshes (though I'll be trying!)
    There are a couple details that could make this easier:
    • The scene is entirely non-physical - I have no need to use rigidibodies and colliders if there's a better solution without them. I just need to know when two meshes are intersecting in space
    • The objects are not large - typically 1-2m on a side. I really only need collision accuracy to 1 cm or so. So if there's a way to 'shrink wrap' simpler colliders onto the objects, I'm all ears.
    • Only one object at a time will be moving, and that object is moving slowly and non-physically.
    • The calculation doesn't have to be perfect. This is informational to the user, and if it's not perfect, that's okay.
    I have a few ideas I'm going to try, which I'll list below. But I'm curious if anyone has a more clever solution I haven't thought of. Or perhaps there's an out-of-the-box mathematics library out there I can use instead of PhysX - I started researching the math, and I really don't want to have to re-code octree checks and triangle overlap from first mathematical principles :)

    Here's what I've discovered so far:
    • There is simply no way to use colliders / rigidbodies to figure out collisions or triggering between two concave meshes. I read through the collision matrix in careful detail and performed my own tests just to double-check
    • There is nothing within the Physics class that I can use to check via code - Physics.ComputePenetration is the closest I found, but still doesn't work with two concave meshes
    • Trying to use many simple collider shapes (spheres, boxes) to approximate the overall object shape breaks down very quickly
    Here's what I'm thinking about trying:
    • Particles? Maybe I can calculate (for instance) a 100x100x100 grid within the object and place a particle wherever there's a face. Of course, that could be an insane number of particles, and breaks down if e.g. one object is entirely inside another.
    • A separate physics package? I know some of the soft-body physics packages support concave meshes
    Anybody have a better idea that I'm missing?
     
    Last edited: Aug 27, 2020