# Rotation and scaling of child not preserved properly when parent is non-uniformly scaled and rotated

**URL:** <https://forum.babylonjs.com/t/rotation-and-scaling-of-child-not-preserved-properly-when-parent-is-non-uniformly-scaled-and-rotated/11092>\
**Category:** Questions\
**Created:** [May 23, 2020, 11:05pm UTC](https://forum.babylonjs.com/t/rotation-and-scaling-of-child-not-preserved-properly-when-parent-is-non-uniformly-scaled-and-rotated/11092 "2020-05-23T23:05:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![JesseDunlap](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jessedunlap/32/7168_2.png) [@JesseDunlap](https://forum.babylonjs.com/u/JesseDunlap)\
**Post date:** [May 23, 2020, 11:05pm UTC](https://forum.babylonjs.com/t/rotation-and-scaling-of-child-not-preserved-properly-when-parent-is-non-uniformly-scaled-and-rotated/11092/1 "2020-05-23T23:05:15Z")

</div>

I am attempting to set the parent of a child mesh, and my goal is to have the original “appearance” of the child mesh preserved. In other words, the global scale, position, and rotation of the child should not change.

Generally speaking, calling `child.setParent(parent)` works, and the correct calculations are done to make the child’s scaling, position, and rotation relative to the parent, but this is not working when the parent is non-uniformly scaled AND rotated along some axis.

Note in this example, everything works as expected:  
[https://playground.babylonjs.com/#0SE830#1](https://playground.babylonjs.com/#0SE830#1)

Despite the fact that the parent is non-uniformly scaled and rotated on the Y axis, the child mesh’s scaling, position, and rotation remain correct after the call to `setParent`. (You can comment and uncomment line 30 in the playground to verify this.)

Now, consider this playground example, where the parent is rotated on X axis instead:  
[https://playground.babylonjs.com/#GQVQ49#2](https://playground.babylonjs.com/#GQVQ49#2)

Now, the scaling and rotation of the child are not preserved properly and it is warped. Note that even in the first playground, you can get results like this by changing the rotation of either the child and the parent to certain values.

This seems like a common problem others would encounter. Is there some obvious or easy way to overcome it? Thank for any help that can be provided!

---

<div class="post-metadata">

**Author:** ![gbz](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/gbz/32/23780_2.png) [@gbz](https://forum.babylonjs.com/u/gbz)\
**Post date:** [May 23, 2020, 11:14pm UTC](https://forum.babylonjs.com/t/rotation-and-scaling-of-child-not-preserved-properly-when-parent-is-non-uniformly-scaled-and-rotated/11092/2 "2020-05-23T23:14:09Z")

</div>

Hey @JesseDunlap, added the line

```auto
parent.bakeCurrentTransformIntoVertices();

```

[https://playground.babylonjs.com/#GQVQ49#3](https://playground.babylonjs.com/#GQVQ49#3)

Hope this helps! I’m not sure if there are better ways to overcome this. Also not sure what are the full consequences of using `bakeCurrentTransformIntoVertices` and how that affects future parenting and rotating/scaling/translating

---

<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:** [May 24, 2020, 3:54pm UTC](https://forum.babylonjs.com/t/rotation-and-scaling-of-child-not-preserved-properly-when-parent-is-non-uniformly-scaled-and-rotated/11092/3 "2020-05-24T15:54:18Z")

</div>

The method you use to apply a parent affects the result [Use a Parent - Babylon.js Documentation](https://doc.babylonjs.com/how_to/parenting#overview-of-a-parent)

---

<div class="post-metadata">

**Author:** ![JesseDunlap](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jessedunlap/32/7168_2.png) [@JesseDunlap](https://forum.babylonjs.com/u/JesseDunlap)\
**Post date:** [May 24, 2020, 4:20pm UTC](https://forum.babylonjs.com/t/rotation-and-scaling-of-child-not-preserved-properly-when-parent-is-non-uniformly-scaled-and-rotated/11092/4 "2020-05-24T16:20:28Z")

</div>

Hi @gbz! I think there’s a bit of nuance to my project that might make this a little difficult to implement as a solution, but I’m talking through it now with the other two people I’m working with. In any sense, this seems to accomplish the task, so thank you for taking the time to reply! 🙂

---

<div class="post-metadata">

**Author:** ![JesseDunlap](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jessedunlap/32/7168_2.png) [@JesseDunlap](https://forum.babylonjs.com/u/JesseDunlap)\
**Post date:** [May 24, 2020, 4:21pm UTC](https://forum.babylonjs.com/t/rotation-and-scaling-of-child-not-preserved-properly-when-parent-is-non-uniformly-scaled-and-rotated/11092/5 "2020-05-24T16:21:48Z")

</div>

Good point, we noticed that as well. Originally we were attempting to just assign to the `parent` property, which wasn’t doing any kind of calculations/adjustments to keep the child from moving/rotating/scaling. `setParent` seems to get the closest, but not quite where we want it.

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [May 25, 2020, 11:00am UTC](https://forum.babylonjs.com/t/rotation-and-scaling-of-child-not-preserved-properly-when-parent-is-non-uniformly-scaled-and-rotated/11092/6 "2020-05-25T11:00:42Z")

</div>

At a first glance, it looks like a bug to me, I ll see what I can do but at least I ll try to find the culprit 🙂

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [May 25, 2020, 7:36pm UTC](https://forum.babylonjs.com/t/rotation-and-scaling-of-child-not-preserved-properly-when-parent-is-non-uniformly-scaled-and-rotated/11092/7 "2020-05-25T19:36:32Z")

</div>

Looking more into it, I do not think it is actually possible to solve without adding extra nodes in the tree ☹ due to the extra parent rotation adding shearing to the matrix. Basically, there is no transform that could cancel the shear induced by the parent not rotate+scale. Baking is probably the easiest here.
