# Scaling mesh and skeleton/bones?

**URL:** <https://forum.babylonjs.com/t/scaling-mesh-and-skeleton-bones/54018>\
**Category:** Questions\
**Tags:** animation, skeleton, bones\
**Created:** [October 9, 2024, 4:16am UTC](https://forum.babylonjs.com/t/scaling-mesh-and-skeleton-bones/54018 "2024-10-09T04:16:26Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![regna](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/regna/32/23915_2.png) [@regna](https://forum.babylonjs.com/u/regna)\
**Post date:** [October 9, 2024, 4:16am UTC](https://forum.babylonjs.com/t/scaling-mesh-and-skeleton-bones/54018/1 "2024-10-09T04:16:26Z")

</div>

Building on top of the [resolved question](https://forum.babylonjs.com/t/bone-world-rotation-quaternion-vs-absolute-matrix-rotation/53994):

In the Youtube video and PG below: If `SCALE = 1` (Line 15), things look fine. However, if I try `SCALE < 1`, the mesh and bones become messed up. If I change Line 69 to use `mat` instead of `mat2`, the mesh looks fine, but the bones have a larger scale compared to the mesh.

Is there a way to scale down both the mesh and bones? Thank you all for your help and @Evgeni_Popov if you could please bless us with your expertise again 🙂

PG: [https://playground.babylonjs.com/#BCU1XR#7562](https://playground.babylonjs.com/#BCU1XR#7562)

[![](https://img.youtube.com/vi/YXTxHAXlj28/hqdefault.jpg "Trying to scale mesh and skeleton/bones") ](https://www.youtube.com/watch?v=YXTxHAXlj28)

---

<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:** [October 9, 2024, 8:55am UTC](https://forum.babylonjs.com/t/scaling-mesh-and-skeleton-bones/54018/2 "2024-10-09T08:55:39Z")

</div>

You have bones whose scale is not (1,1,1), so you need to take this into account in the calculation. In addition, the scale matrix must be left-multiplied with `mat`, not right-multiplied:

> **[Babylon.js Playground](https://playground.babylonjs.com/#BCU1XR%237563)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL and WebGPU 3D scenes

---

<div class="post-metadata">

**Author:** ![regna](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/regna/32/23915_2.png) [@regna](https://forum.babylonjs.com/u/regna)\
**Post date:** [October 9, 2024, 2:43pm UTC](https://forum.babylonjs.com/t/scaling-mesh-and-skeleton-bones/54018/3 "2024-10-09T14:43:05Z")

</div>

Thank you for helping to look into this, @Evgeni_Popov. In the updated PG, it still seems like the bones have a larger scale than the mesh.

In the screenshots below, `SCALE = 1` has the bones and mesh matching nicely. However, `SCALE = 0.6` has the bones larger than the mesh.

 ![SCALE 0.6](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/4/b/4b50e86b7231c65012dd4c35d1478ed90a12eea7.png)

 ![SCALE 1](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/9/5/95918d44bf85e1e2290c2dac4bc863d6017143c1.png)

---

<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:** [October 9, 2024, 4:54pm UTC](https://forum.babylonjs.com/t/scaling-mesh-and-skeleton-bones/54018/4 "2024-10-09T16:54:33Z")

</div>

cc @Cedric, maybe there’s something that doesn’t work with the debug AxisViewer, because it does work when doing it in the inspector:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/4/d/4d5df97f0917de28994e8552ac6ce6b7018d5f6e.png)

---

<div class="post-metadata">

**Author:** ![regna](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/regna/32/23915_2.png) [@regna](https://forum.babylonjs.com/u/regna)\
**Post date:** [October 10, 2024, 5:37am UTC](https://forum.babylonjs.com/t/scaling-mesh-and-skeleton-bones/54018/5 "2024-10-10T05:37:04Z")

</div>

The bones unexpectedly have the same absolute position despite different scaling (e.g. `SCALE = 1`, `SCALE = 0.6`). So it seems that `Debug.AxesViewer` is working fine. Perhaps the Inspector is showing a different position instead of the bone’s absolute position? Please see the screenshot and PG below showing this:

PG with logging: [https://playground.babylonjs.com/#BCU1XR#7568](https://playground.babylonjs.com/#BCU1XR#7568)

 ![boneposition](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/4/5/45e3437e37643d57ff97a201ee2cdbccd77be298.png)

---

<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:** [October 11, 2024, 2:37pm UTC](https://forum.babylonjs.com/t/scaling-mesh-and-skeleton-bones/54018/6 "2024-10-11T14:37:09Z")

</div>

The absolute positions are the same because you applied the scaling on the mesh, not on the bones. So, from the point of the view of the bones, the scaling is unchanged whatever the value of SCALE is.

I think the debug viewer does not work because the mesh transformation would need to be applied to the bone transformation, but I don’t see a way to do it (axis from the debug viewer have bones as their parent)… cc @Cedric in case he would know.

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [October 11, 2024, 3:43pm UTC](https://forum.babylonjs.com/t/scaling-mesh-and-skeleton-bones/54018/7 "2024-10-11T15:43:31Z")

</div>

> I think the debug viewer does not work because the mesh transformation would need to be applied to the bone transformation

yes, that’s my guess too.

> maybe there’s something that doesn’t work with the debug AxisViewer, because it does work when doing it in the inspector:

I guess you’ve tried to use the position gizmo. gizmos have the ability to get the skeleton mesh linked to a bone

> <https://github.com/BabylonJS/Babylon.js/blob/4746b2a346ab9728de444fb158c8dc590913a4bb/packages/dev/core/src/Gizmos/gizmo.ts#L120>

---

<div class="post-metadata">

**Author:** ![regna](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/regna/32/23915_2.png) [@regna](https://forum.babylonjs.com/u/regna)\
**Post date:** [October 11, 2024, 3:57pm UTC](https://forum.babylonjs.com/t/scaling-mesh-and-skeleton-bones/54018/8 "2024-10-11T15:57:08Z")

</div>

Thank you, @Evgeni_Popov and @Cedric !

Would you know how I could change the PG to get the absolute position of the bones to match the scaled down mesh?

 ![SCALE 0.6 - Copy](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/e/9/e9d7ea102a046efd03a6f9cc089223505404a4bd.png)

* * *

```ts
const mat2 = scaleMatrix.multiply(mat);

tmpMat.copyFrom(mat2);

// ...

tmpMat.decompose(undefined, rotation, position);

// ...

bone.setAbsolutePosition(position);

```

I assumed that the `SCALE = 0.6` would get baked into `position` that we set the bone’s absolute position to, though it seems I’m wrong

---

<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:** [October 11, 2024, 5:02pm UTC](https://forum.babylonjs.com/t/scaling-mesh-and-skeleton-bones/54018/9 "2024-10-11T17:02:05Z")

</div>

You simply have to pass the base mesh to `getAbsolutePosition`, but you must make sure that the world matrix of this mesh is up to date (see line 40):

> **[Babylon.js Playground](https://playground.babylonjs.com/#BCU1XR%237569)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL and WebGPU 3D scenes

---

<div class="post-metadata">

**Author:** ![regna](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/regna/32/23915_2.png) [@regna](https://forum.babylonjs.com/u/regna)\
**Post date:** [October 11, 2024, 5:21pm UTC](https://forum.babylonjs.com/t/scaling-mesh-and-skeleton-bones/54018/10 "2024-10-11T17:21:55Z")

</div>

Ah, thank you, @Evgeni_Popov 🙂 I’ve added a `PointsCloudSystem` using the tip you shared above:

PG: [https://playground.babylonjs.com/#BCU1XR#7572](https://playground.babylonjs.com/#BCU1XR#7572)

 ![points](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/c/9/c947a819a26c852800aed16ceda7b92afe75724b.png)
