Raycaster not working when boundingbox apply object matrix

I find that when a mesh computing boundingbox and the box apply its mesh matrix, raycaster can’t catch the mesh. What causes this to happen?

object.geometry.computeBoundingBox();
object.geometry.boundingBox.applyMatrix4(object.matrix.clone()); // the reason

This is because how intersection is optimized.

  1. It first checks intersection with the bounding sphere. If there is no intersection, that’s all.
  2. Then it checks intersection with the bounding box. If there is no intersection, that’s all.
  3. Finally it checks intersection with the individual faces.

So, if you modify manually the bounding box, the raycasting reaches step 2 and exits.

Edit: The bounding box is Box3 object and it is always AABB. This pages shows how to update it:
https://threejs.org/docs/?q=Box3#api/en/math/Box3

Does it mean that we don’t modify the properties “object.geometry.boundingBox” in order to make raycaster normal working?

Yes, I expect that raycasting will still work if you move/scale/rotate the object.

You may need to recalculate the bounding box and bounding sphere only if you manually change the vertices in the geometry.