Oversized bounding boxes for example models

I’m not sure if this is specific to animated models or not, but I’ve only seen it with animated examples such as
three.js/Horse.glb at 50380bd1b84a1c1fbd3bb7e41769c21f01f3b60f · mrdoob/three.js · GitHub and
three.js/Flamingo.glb at 50380bd1b84a1c1fbd3bb7e41769c21f01f3b60f · mrdoob/three.js · GitHub and
but not three.js/PrimaryIonDrive.glb at 50380bd1b84a1c1fbd3bb7e41769c21f01f3b60f · mrdoob/three.js · GitHub

Drop a model such as Horse.glb into three.js / editor and its bounding box is much bigger than it needs to be. This is problematic when I’m using @donmccurdy’s three-to-cannon package to build physics objects from Three objects. I’ve imported the models in Blender and don’t see any stray points. The models are insanely large; could it be some sort of scale/precision issue?

I do see that three.js docs says “The function may result in a larger box than strictly necessary.” Is that the problem? Any way to fix?

These models use morph target animation. Bounding box computation for such meshes honor the maximum extend of all morph targets (which is a critical requirement so raycasting or view frustum culling properly work).

Thanks @Mugen87, now that I know it’s morph targets causing this (and now that I’m learning about them), I see other posts/issues about this. I see https://jsfiddle.net/q4sjbLuk/ https://jsfiddle.net/qosuLyhf/ where you implement AABB for skinned meshes…is there a way to compute a smaller AABB for any Object3D? For my needs (approximate physics simulation) it doesn’t need to be perfect; it could just use the extent of the object when it first loads or something.

You could temporarily remove all morph target attributes, compute the AABB and the add them back to the geometry.

1 Like

That seems to be doing the trick, thanks! Here’s my function that removes/restores morphAttributes:

toggleMorphAttributes(obj, restore) {
  obj.traverse(c => {
    if (c.geometry) {
      if (restore) {
        c.geometry.morphAttributes =
          c.geometry.userData.morphAttributes || {};
        delete c.geometry.userData.morphAttributes;
      } else {
        c.geometry.userData.morphAttributes = c.geometry.morphAttributes;
        c.geometry.morphAttributes = {};
      c.geometry.boundingBox = null;