# How to compute bounding box of a GLTF mesh

**URL:** <https://discourse.threejs.org/t/how-to-compute-bounding-box-of-a-gltf-mesh/29437>\
**Category:** Questions\
**Tags:** bounding-box\
**Created:** [August 31, 2021, 5:06pm UTC](https://discourse.threejs.org/t/how-to-compute-bounding-box-of-a-gltf-mesh/29437 "2021-08-31T17:06:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cebugdev](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/cebugdev/32/20619_2.png) [@cebugdev](https://discourse.threejs.org/u/cebugdev)\
**Post date:** [August 31, 2021, 5:06pm UTC](https://discourse.threejs.org/t/how-to-compute-bounding-box-of-a-gltf-mesh/29437/1 "2021-08-31T17:06:57Z")

</div>

I want to get the bounding box of a GLTF model that covers its root and its children.  
This is what i did,

```javascript
loader.load('assets/a1/A1.glb',
     (gltf) => {
               const root = gltf.scene;
              const box = new THREE.Box3().setFromObject(root);
              const boxSize = box.getSize(new THREE.Vector3()).length();
              const boxCenter = box.getCenter(new THREE.Vector3());
});

```

But unfortunately, it doesnt compute or include the child meshes.

How to do this correctlt?

---

<div class="post-metadata">

**Author:** ![donmccurdy](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/donmccurdy/32/33209_2.png) [@donmccurdy](https://discourse.threejs.org/u/donmccurdy)\
**Post date:** [August 31, 2021, 5:52pm UTC](https://discourse.threejs.org/t/how-to-compute-bounding-box-of-a-gltf-mesh/29437/2 "2021-08-31T17:52:13Z")

</div>

Hm I’m pretty sure that does include child meshes, I use the same code in my viewer:

> <https://github.com/donmccurdy/three-gltf-viewer/blob/5c582afd7b625df63c60f58cd0a34fe5fbf86cac/src/viewer.js#L273-L275>

… can you share an example where it’s broken? The only case I know of is with SkinnedMesh, it doesn’t including skinning transforms in the bounding box.

---

<div class="post-metadata">

**Author:** ![cebugdev](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/cebugdev/32/20619_2.png) [@cebugdev](https://discourse.threejs.org/u/cebugdev)\
**Post date:** [September 1, 2021, 2:32am UTC](https://discourse.threejs.org/t/how-to-compute-bounding-box-of-a-gltf-mesh/29437/3 "2021-09-01T02:32:23Z")

</div>

Here is the model i am loading

[https://drive.google.com/drive/folders/1tXTW57mrLBLQ3T2JzA2lXLQjPqO7dkpN?usp=sharing](https://drive.google.com/drive/folders/1tXTW57mrLBLQ3T2JzA2lXLQjPqO7dkpN?usp=sharing)

displaying the size of the box for root results to 0.0000022626528104191175  
but displaying the box of each child mesh it displays  
child 1 = 0.22626528322871423  
child 2 = 0.057509041719473984

so if bounding box gets the larger size its it should be in the box, the value should be the 0.226 or around that  
here is a strip version of the code

```javascript
loader.load('assets/a1/A1.glb',
     (gltf) => {

           gltf.scene.traverse( function ( child )
      {
          if ( child.isMesh )
          {
              const box = new THREE.Box3().setFromObject(child);

              const boxSize = box.getSize(new THREE.Vector3()).length();
            
              console.log(boxSize);
              }
      } );

               const root = gltf.scene;
              const box = new THREE.Box3().setFromObject(root);
              const boxSize = box.getSize(new THREE.Vector3()).length();
              const boxCenter = box.getCenter(new THREE.Vector3());
});

```

---

<div class="post-metadata">

**Author:** ![donmccurdy](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/donmccurdy/32/33209_2.png) [@donmccurdy](https://discourse.threejs.org/u/donmccurdy)\
**Post date:** [September 1, 2021, 2:44am UTC](https://discourse.threejs.org/t/how-to-compute-bounding-box-of-a-gltf-mesh/29437/4 "2021-09-01T02:44:55Z")

</div>

I have a guess at what’s happening here… try calling `gltf.scene.updateMatrixWorld( true )` before traversing and calculating sizes, does that change the result?

The armature has a `1/100` scale on it, and everything else is nested under that.
