# Baking Quaternions Deforms Meshes

**URL:** <https://forum.babylonjs.com/t/baking-quaternions-deforms-meshes/22722>\
**Category:** Bugs\
**Tags:** quaternion\
**Created:** [July 30, 2021, 9:43am UTC](https://forum.babylonjs.com/t/baking-quaternions-deforms-meshes/22722 "2021-07-30T09:43:58Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Caner](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/caner/32/15711_2.png) [@Caner](https://forum.babylonjs.com/u/Caner)\
**Post date:** [July 30, 2021, 9:43am UTC](https://forum.babylonjs.com/t/baking-quaternions-deforms-meshes/22722/1 "2021-07-30T09:43:58Z")

</div>

Hello everyone!

I am trying to bake transformations of each mesh of an imported model and some meshes are distorted in the output. I figured that it is about transformations (mostly quaternions) and mesh hierarchy.

This is the PG link: [https://www.babylonjs-playground.com/#B0LTE1#1](https://www.babylonjs-playground.com/#B0LTE1#1)  
I have given some instructions as comments to try some combinations. Let me also state that I tried commenting out “boxQuat2” and give only Euler rotation to “boxQuat” with the same values, and problem continues.

The reason was to serialize the meshes for conversion and the output was distorted. I tried baking at that point and the distortion happened already before serialization. If I freeze mesh transformations in the 3D modeling software and get rid of quaternions and baking together, serialization output was successful. However, this requires me to modify all my models and do not use quaternions in my project, which is a big problem for my case.

I will be glad to receive any help. Thank you very much!!!

---

<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:** [July 30, 2021, 10:26am UTC](https://forum.babylonjs.com/t/baking-quaternions-deforms-meshes/22722/2 "2021-07-30T10:26:20Z")

</div>

It is a bug (two, actually), this PR will fix it:

> <https://github.com/BabylonJS/Babylon.js/pull/10776>
>
> See https://forum.babylonjs.com/t/baking-quaternions-deforms-meshes/22722

---

<div class="post-metadata">

**Author:** ![Caner](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/caner/32/15711_2.png) [@Caner](https://forum.babylonjs.com/u/Caner)\
**Post date:** [July 30, 2021, 3:01pm UTC](https://forum.babylonjs.com/t/baking-quaternions-deforms-meshes/22722/3 "2021-07-30T15:01:09Z")

</div>

Is that okay if the PG link results the same?  
In my local project I removed babylonjs from node\_modules and ran npm install but the problem continues. Or am I missing something taking changes in?

---

<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:** [July 30, 2021, 4:55pm UTC](https://forum.babylonjs.com/t/baking-quaternions-deforms-meshes/22722/4 "2021-07-30T16:55:32Z")

</div>

The changes are not merged yet. They will be available in the preview CDN in one or two days, and in NPM packages in one or two weeks (it depends on when the NPM packages are rebuilt).

---

<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:** [July 30, 2021, 6:44pm UTC](https://forum.babylonjs.com/t/baking-quaternions-deforms-meshes/22722/5 "2021-07-30T18:44:46Z")

</div>

It should be available on the preview CDN by now ?

---

<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:** [July 30, 2021, 8:02pm UTC](https://forum.babylonjs.com/t/baking-quaternions-deforms-meshes/22722/6 "2021-07-30T20:02:07Z")

</div>

Yes, the PG does now work (after clearing the browser cache).

---

<div class="post-metadata">

**Author:** ![Caner](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/caner/32/15711_2.png) [@Caner](https://forum.babylonjs.com/u/Caner)\
**Post date:** [August 2, 2021, 7:40am UTC](https://forum.babylonjs.com/t/baking-quaternions-deforms-meshes/22722/7 "2021-08-02T07:40:59Z")

</div>

Thank you very much! It works perfectly.

Yet I am not able to observe the solution in my local project which uses npm, what should I do to get it working there as well?

---

<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:** [August 2, 2021, 8:57am UTC](https://forum.babylonjs.com/t/baking-quaternions-deforms-meshes/22722/8 "2021-08-02T08:57:51Z")

</div>

I think you will need for the NPM packages to be regenerated. @sebavan may be able to give you a timeframe for this one.

---

<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:** [August 2, 2021, 1:44pm UTC](https://forum.babylonjs.com/t/baking-quaternions-deforms-meshes/22722/9 "2021-08-02T13:44:01Z")

</div>

I ll do one today as soon as the latest 2 none drafts PR are merged, so you can expect tomorrow morning worst case

---

<div class="post-metadata">

**Author:** ![Caner](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/caner/32/15711_2.png) [@Caner](https://forum.babylonjs.com/u/Caner)\
**Post date:** [August 4, 2021, 7:56am UTC](https://forum.babylonjs.com/t/baking-quaternions-deforms-meshes/22722/10 "2021-08-04T07:56:33Z")

</div>

I am really shy to ping you this much, is it done or am I doing something wrong? (Uninstalling node\_modules and reinstalling, packages:  
“babylonjs”: “^4.2.0”,  
“babylonjs-gui”: “4.2.0”,  
“babylonjs-loaders”: “4.2.0”,  
“babylonjs-serializers”: “^4.2.0”  
)

Excuse me for asking repeatedly ☹

---

<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:** [August 4, 2021, 8:12am UTC](https://forum.babylonjs.com/t/baking-quaternions-deforms-meshes/22722/11 "2021-08-04T08:12:34Z")

</div>

The fix is for 5.0 only, we don’t back report fixes to older Babylon versions.

---

<div class="post-metadata">

**Author:** ![Caner](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/caner/32/15711_2.png) [@Caner](https://forum.babylonjs.com/u/Caner)\
**Post date:** [August 4, 2021, 10:40am UTC](https://forum.babylonjs.com/t/baking-quaternions-deforms-meshes/22722/12 "2021-08-04T10:40:24Z")

</div>

Oh damn 😅 so I was doing something WAY wrong 😃

It works perfectly with the PG link, which creates and manipulates meshes programatically. But the problem continues with the imported models.

Here’s a new PG link to demonstrate with imported models: [https://www.babylonjs-playground.com/#B0LTE1#3](https://www.babylonjs-playground.com/#B0LTE1#3)

The model is just a dummy one, the output is somehow translated and scaled, but a complex model I am dealing with have some meshes disappear, make some flipped etc. after baking. Sorry that I am not able to share that one.

---

<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:** [August 4, 2021, 11:09am UTC](https://forum.babylonjs.com/t/baking-quaternions-deforms-meshes/22722/13 "2021-08-04T11:09:40Z")

</div>

You should unparent the root of your hierarchy (pCube1), else it will inherit its parent transformations. As they are already baked into the vertices (by the `bakeCurrentTransformIntoVertices` call), it means it will be applied twice:

[https://www.babylonjs-playground.com/#B0LTE1#4](https://www.babylonjs-playground.com/#B0LTE1#4)
