Detecting a mesh in front of another mesh

I’m trying to detect when a mesh is in front of another mesh from the perspective of the camera. Note I’m not using an ortho camera, but for my purposes a mesh is in front of another mesh if any part of the mesh is within the bounding box defined by projecting the other mesh’s edges in z to the camera radius. See Babylon.js Playground. For some reason, the BoundingBox.Intersects method is always returning false. Can anyone see what I am doing wrong? Is there a better way to do this? Is there a way to parent a bounding box to the mesh so that it always moves with the mesh as it is dragged and doesn’t need to be recreated every time I get a pointer event?

I solved the problem of the intersection not being detected. I wanted my BB to extend towards the camera which is minus z, so I need to put the minus z in the min, not the max. Still don’t understand how to keep the BB with the mesh when the mesh can be moved (dragged).

1 Like

Why does the bounding box need to move with the mesh? Maybe you can just move the plane with the mesh since that’s what’s being tested for intersection with the pointer?

I’ve gone down a completely different path to solve this problem, but to my original question, I wonder if instead of a bounding box, I could just project a plane to z = 0 for each of the meshes (parented to the mesh) and then fire an action when the planes intersect.

1 Like