How to Get Accurate Bounding Boxes For Animated GLTF?

The bounding boxes are not even close…

I’ve solved this before by putting the bounding box on the SkeletonHelper using this technique with animated DAE file.

Sadly, this isn’t working for animated GLTF somehow.

Any suggestions/tips?

Can you demonstrate your issue in a jsfiddle or codepen? Is the SkeletonHelper working? Besides you could also do this without the SkeletonHelper, you just need to traverse through the skeleton hierarchy expanding a Box3 with the world position of every bone, additionally you can add a little padding to the box since either way you’re not considering the exact animated vertices.

Something like this

const box = new THREE.Box3;
const vec3 = new THREE.Vector3;
const padding = 10;

box.min.set( Infinity, Infinity, Infinity );
box.max.set( -Infinity, -Infinity, -Infinity );

rootBone.traverse( bone => {

	if ( bone.isBone ) {

		vec3.setFromMatrixPosition( bone.matrixWorld );
		box.expandByPoint( vec3 );

	}

});

box.expandByScalar( padding );

Thanks for the reply. I got it somewhat closer. But still off. Not sure why the skeleton and it’s boundingbox is displaced from the model.

Demo: https://glitch.com/~gltf-with-bbox

Bounding boxes are computed before skinning distortion is applied. In some models (like things converted from FBX, often) the skinning technique can apply a 100x or 1/100x scale to the model. A good workaround might be to export a box with the model, of the same size, and use that for the bounding box.

Related: Object bounds not updated with animation

1 Like

Anyone have any idea why in this demo https://glitch.com/~gltf-with-bbox the mesh and skeleton are aligned differently?

If I don’t add the skeleton/mesh to a parent group they align fine. But I have no idea why adding them to a parent group would throw them out of alignment.

Here is what happens when I add the mesh and skeleton to a group (NOT WORKS):
bbox_notworking

Here is what happens when I add the mesh and skeleton to the scene (WORKS):
bbox_working

https://glitch.com/edit/#!/join/1a4dbe64-d740-4426-a8eb-d8c68d327311
^ here is the link to edit the code on glitch.

Any idea? It must be something v simple I am missing…