I’m trying to accomplish precise mesh intersection detection.
I’m working on a modeling tool where the user can drag and drop objects, and I would like to detect intersections between meshes on demand (real-time is not a must, just a nice-to-have).
To showcase the problem I’m trying to solve, I created this playground:
Please note that while I am using torus knots for this example, in the application I’m using imported meshes with complex real-life-object shapes and textures .
In the playground you can find 4 shapes:
- Shapes A & B: 2 torus knots where the bounding boxes intersect but the knots themselves do not.
- Shapes C & D: 2 torus knots where the knots themselves intersect.
I’m looking for the most performant way to detect intersections, such that:
- It correctly detects that knots A & B are not intersecting
- It correctly detects that knots C & D are intersecting
Based on my research, I considered the following approaches:
- Using mesh.IntersectsMesh(otherMesh) : this only does Oriented Bounding Box intersection at best, which is not enough for my purposes.
Using CSG : while I got this working with simple shapes like spheres, it seems to be very taxing on performance. Running it on 2 torus knots took more than 10 minutes, so I don’t think it’s viable for my purposes.
- I noticed csg.intersect(otherCsg) calculates the geometry of the intersection. Is there a more performant algorithm that only detects intersections (i.e. returns a boolean that is true if they intersect)?
- Using a physics engine : I haven’t looked too deeply into this option as I would like to avoid it if possible, since the application doesn’t need body dynamics, gravity, bouncing, etc.
Looking forward to your advice.