# getBoundingInfo() after scaling a mesh is not correct

**URL:** <https://forum.babylonjs.com/t/getboundinginfo-after-scaling-a-mesh-is-not-correct/35495>\
**Category:** Questions\
**Created:** [November 8, 2022, 8:00am UTC](https://forum.babylonjs.com/t/getboundinginfo-after-scaling-a-mesh-is-not-correct/35495 "2022-11-08T08:00:14Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pe443](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pe443/32/22675_2.png) [@Pe443](https://forum.babylonjs.com/u/Pe443)\
**Post date:** [November 8, 2022, 8:00am UTC](https://forum.babylonjs.com/t/getboundinginfo-after-scaling-a-mesh-is-not-correct/35495/1 "2022-11-08T08:00:14Z")

</div>

Hi,  
I have a little problem getBoundingInfo().boundingSphere.radiusWorld.

My box has a width of 1:  
let radius = box.getBoundingInfo().boundingSphere.radiusWorld;  
 → radius = 1.1874342087037917;  
That’s OK.

Now I do the following:  
box.scaling.x = 3;  
let radius = box.getBoundingInfo().boundingSphere.radiusWorld;  
 → radius = 1.1874342087037917;  
That’s not OK, radius should be 3.562302626111375

I know I must use box.computeWorldMatrix(true) to get the right result  
 → radius=3.562302626111375

Is this by design or why does getBoundingInfo() does not take the scaling into account?

Thx …

---

<div class="post-metadata">

**Author:** ![neu5](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/neu5/32/24720_2.png) [@neu5](https://forum.babylonjs.com/u/neu5)\
**Post date:** [November 8, 2022, 8:31am UTC](https://forum.babylonjs.com/t/getboundinginfo-after-scaling-a-mesh-is-not-correct/35495/2 "2022-11-08T08:31:36Z")

</div>

Hey @Pe443,  
Are you checking the `getBoundingInfo` exactly after setting the scalling `box.scaling.x`?  
Or you do the check after the engine rendering loop make at least one step?

---

<div class="post-metadata">

**Author:** ![Pe443](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pe443/32/22675_2.png) [@Pe443](https://forum.babylonjs.com/u/Pe443)\
**Post date:** [November 8, 2022, 8:45am UTC](https://forum.babylonjs.com/t/getboundinginfo-after-scaling-a-mesh-is-not-correct/35495/3 "2022-11-08T08:45:25Z")

</div>

Hi,  
II must do the check direct after the scale, the scene is NOT rendert.  
This is because I have to calculate postions and so of other meshes bevor the scne is renderd.  
Especially I need this for placing objects BEVOR the first rendering of a scene.

---

<div class="post-metadata">

**Author:** ![JohnK](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/johnk/32/26764_2.png) [@JohnK](https://forum.babylonjs.com/u/JohnK)\
**Post date:** [November 8, 2022, 8:48am UTC](https://forum.babylonjs.com/t/getboundinginfo-after-scaling-a-mesh-is-not-correct/35495/4 "2022-11-08T08:48:36Z")

</div>

> [@Pe443](#):
>
> I know I must use box.computeWorldMatrix(true) to get the right result

See this [topic](https://forum.babylonjs.com/t/what-the-computeworldmatrix-does-and-when-to-use-it/35390) to understand why computeWorldMatrix is needed for scaling to be taken into account.

---

<div class="post-metadata">

**Author:** ![Pe443](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pe443/32/22675_2.png) [@Pe443](https://forum.babylonjs.com/u/Pe443)\
**Post date:** [November 8, 2022, 9:01am UTC](https://forum.babylonjs.com/t/getboundinginfo-after-scaling-a-mesh-is-not-correct/35495/5 "2022-11-08T09:01:40Z")

</div>

No this topic is why getBoundingInfo does give a wrong number and why?  
For me it makes no sense to use computeWorldMatrix every time, or lets say, why must the scene be rendred bevor I can get getBoundingInfo().

---

<div class="post-metadata">

**Author:** ![JohnK](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/johnk/32/26764_2.png) [@JohnK](https://forum.babylonjs.com/u/JohnK)\
**Post date:** [November 8, 2022, 9:59am UTC](https://forum.babylonjs.com/t/getboundinginfo-after-scaling-a-mesh-is-not-correct/35495/6 "2022-11-08T09:59:40Z")

</div>

> [@Pe443](#):
>
> No this topic is why getBoundingInfo does give a wrong number and why?

We understand what the topic is about. The why? is explained by the link I gave.

When you have

```javascript
box.scaling.x = 3

```

all this does is assign the value 3 to the x property of the scaling property of the box to 3.  
No ‘scaling’ of the box takes place because no code has been called to do that. So no change has been made to the bounding info yet.

The code to do the ‘scaling’ comes when the following code is called

```javascript
// Register a render loop to repeatedly render the scene
engine.runRenderLoop(function () {
    scene.render();
});

```

Check out this page [Getting Started - Chapter 1 - Setup Your First Web App | Babylon.js Documentation](https://doc.babylonjs.com/features/introductionToFeatures/chap1/first_app) or this page [Starter HTML Template | Babylon.js Documentation](https://doc.babylonjs.com/setup/starterHTML) to see where that occurs. In a playground this code is done in the background when the PG code is run.

Since there will be times, as in your case, when you want the ‘scaling’ or whatever to be in place before any rendering then Babylon.js exposes the computeWorldMatrix as a method so you can call it and have the ‘scaling’ take place as you require and the bounding info will be up to date.

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [November 8, 2022, 11:04am UTC](https://forum.babylonjs.com/t/getboundinginfo-after-scaling-a-mesh-is-not-correct/35495/7 "2022-11-08T11:04:30Z")

</div>

Have you tried calling `refreshBoundingInfo()`?

---

<div class="post-metadata">

**Author:** ![Pe443](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pe443/32/22675_2.png) [@Pe443](https://forum.babylonjs.com/u/Pe443)\
**Post date:** [November 8, 2022, 11:20am UTC](https://forum.babylonjs.com/t/getboundinginfo-after-scaling-a-mesh-is-not-correct/35495/8 "2022-11-08T11:20:51Z")

</div>

> [@JohnK](#):
>
> all this does is assign the value 3 to the x property of the scaling property of the box to 3.  
> No ‘scaling’ of the box takes place because no code has been called to do that. So no change has been made to the bounding info yet.

OK now I understand, I thought that scaling manipulates the mesh directly.

THX a lot

---

<div class="post-metadata">

**Author:** ![Pe443](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pe443/32/22675_2.png) [@Pe443](https://forum.babylonjs.com/u/Pe443)\
**Post date:** [November 8, 2022, 11:24am UTC](https://forum.babylonjs.com/t/getboundinginfo-after-scaling-a-mesh-is-not-correct/35495/9 "2022-11-08T11:24:14Z")

</div>

> [@Evgeni\_Popov](#):
>
> Have you tried calling `refreshBoundingInfo()`?

Does not work, with computeWorldMatrix(true) everything is Ok 😉
