rookie
1
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.
- It first checks intersection with the bounding sphere. If there is no intersection, that’s all.
- Then it checks intersection with the bounding box. If there is no intersection, that’s all.
- 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
rookie
3
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.