Baking Quaternions Deforms Meshes

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
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!!!

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

2 Likes

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?

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).

1 Like

It should be available on the preview CDN by now ?

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

2 Likes

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?

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

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

3 Likes

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 :frowning:

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

Oh damn :sweat_smile: so I was doing something WAY wrong :smiley:

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

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.

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

1 Like