I have been messing around with this example (Check When a Point is Inside a Mesh | Babylon.js Documentation) for checking if a point is inside a mesh.
While testing I found situations where the hit counting was skipping hits due to the step difference added to the ray and other situations where a mesh would get 20,000+ hits recorded and output the wrong value.
It got me thinking about having an option for ray.intersectsMesh(...) to return a complete list of hits instead of just the closest, or to add a separate method to return a list and keep this one returning the closest.
This could be a decent reduction in runtime for an even-odd hit method like in the babylon example, and guarantee the same triangles aren’t getting hit twice by the ray.
Looking at SubMesh._intersectTriangles(...) in SubMesh.ts, it already loops through every face and keeps the closest hit. It seems it would not be that difficult to create an alternate path that returns an array of hits rather than just the closest.
If this makes sense as a feature I would be happy to work on a PR for it, and if so the only question I would have is the expected output of a mesh with multiple submeshes (I would assume an allocation of all hits across all valid submeshes)
If there is any technical reason this wouldn’t work I am also just curious about the logic.
Thanks!