Accurate GLTF bounding box

Here’s code for accurately fitting a THREE.Box3 to a THREE.SkinnedMesh —

const vector = new THREE.Vector3();
const box = new THREE.Box3().makeEmpty();
const position = mesh.geometry.attributes.position;

for ( let i = 0, il = position.count; i < il; i ++ ) {

	vector.fromBufferAttribute( position, i );
	mesh.boneTransform( i, vector );
	mesh.localToWorld( vector );
	box.expandByPoint( vector );

}

The code above computes the bounding box in world space; omit localToWorld if you prefer local space.

Preview:

NOTE: Only some portions of this character are skinned. I included only the skinned portions in this capture, which is why the legs do not display a bbox, but that’s an unusual situation.

2 Likes