Brandon Rodriguez Brandon Rodriguez - 2 months ago 58
Javascript Question

JavaScript - Three.js compute bounding box of Object3D with BufferGeometry

I have an

Object3D
with many levels of children (more Object3Ds or Meshes/Lines). The
Box3
class has a
setFromObject()
method which will compute a bounding box of an object and all of its descendants. This is the behavior I am looking for.

I can't use the
setFromObject()
method of
Box3
, however, because I am not using
Geometry
objects. Instead, the project I'm working on uses
BufferGeometry
exclusively.
BufferGeometry
objects do not have a
.vertices
property, which is what the
setFromObject()
function looks for when computing a bounding box.

var bbox = new THREE.Box3().setFromObject(object);
console.log(bbox.min); // x, y, and z are all Infinity.
console.log(bbox.max); // x, y, and z are all -Infinity.


I have also been experimenting with using the
computeBoundingBox()
method of
BufferGeometry
, but it does not seem to update the bounding box when the geometry is manipulated. I think it might be related to
matrixAutoUpdate
being
false
, but I've also tried explicitly calling
updateMatrix()
to no avail.

Is there a way to compute a bounding box on an
Object3D
and all of its descendants if using the
BufferGeometry
class? I'm new to Three.js, so any help would be appreciated!

I am using Three.js r66.

Answer

Box3.setFromObject( object ) now supports BufferGeometry.

three.js r.69dev (dev version)

Comments