Any way to get a bounding box from a three.js Object3D?

You don’t need to iterate over all children of the object; there’s a method in the library to do this: THREE.Box3#setFromObject: see the docs. For example, you can do:

var bbox = new THREE.Box3().setFromObject(obj);

to get the bounding box of obj, including all of its children, and accounting for any translations, rotations, etc.

Note that the BoundingBox helper is intended to draw a bounding box in the scene, not for just calculating the bounding box of some object.

Leave a Comment