Finding multiple intersection points on single mesh with pickingRay

Given a pointer-derived picking ray and an arbitrary mesh I can easily find the closest intersection of the ray with the mesh. Is there a built-in (or otherwise straightforward) way of determining not only the closest closest intersection point (call this the entry point) but also the far intersection (exit) point?

I’d hoped that setting sideOrientation to DOUBLESIDED, along with multipick, might help but apparently not. In my case it’s a sphere and I dare say I could create two partial (PI arc) spheres but there’s an Arcrotate camera involved so I’d have to manually rotate these and I worry about detecting and disambiguating coincident intersections on the edge. I couldn’t see a way to use the triangle predicate other than manual intersection checks.

Given it’s a sphere on the origin I can mirror the closest intersection across the camera’s OXY plane but, you know, Math, (and also, come to think of it, perspective distortions). I’ve got camera basis vectors, know how to find the back frustum ray (and intersect from the other side), and enough quaternion knowledge to do all the rotation calcs but would prefer not to if I don’t need to. TIA!

you could cast an inverted ray offset by the meshes position and the the length of the first ray prehaps.


Thanks for the suggestion! I’d not thought of that - essentially stepping through the camera’s Z, intersection by intersection (maybe with a tiny epsilon step to ensure we don’t pick up the same mesh poly twice?). If my mesh was more complicated than a sphere I think this would be a good approach, assuming precision doesn’t come into play towards edges. It would also allow for non-convex meshes - blasting holes in arbitrary shapes etc.

What I’ve gone for is a reverse ray projection from the local back of the scene which appears to be fast enough for what I need and - more importantly! - is working.

1 Like