Bone world rotation quaternion vs absolute matrix rotation

I tried inputting a bone’s absolute matrix’s rotation quaternion into its bone.setRotationQuaternion() method with the parameter BABYLON.Space.WORLD, however the skeleton and mesh become messed up :frowning:

I thought that a bone’s (1) absolute matrix’s rotation quaternion and (2) world rotation quaternion are the same, so I expected that setting one to the other would have no effect, though it looks like I’m wrong.

Please see the Youtube video below where I uncomment lines in the PG linked below:

PG: https://playground.babylonjs.com/#BCU1XR#7552 (this PG is based on one in the official documentation)

Does anyone know the relationship between the (1) world rotation quaternion and (2) absolute matrix rotation? I’m trying to find the correct input quaternion for bone.setRotationQuaternion() with BABYLON.Space.WORLD.

Thank you for your help :slight_smile:

See how it is done in getRotationQuaternionToRef:

You are missing a multiplication of the first row by a scaling value, which is +1 or -1 depending on the bind matrix determinant. From _updateAbsoluteBindMatrices:

this._scalingDeterminant = this._absoluteBindMatrix.determinant() < 0 ? -1 : 1;

In your case, all bones have a -1 value.

1 Like

Thank you so much, @Evgeni_Popov! You’re a lifesaver :smile:

@Evgeni_Popov thank you for your tip on the scaling determinant. I’ve tried looking online to understand this term more, though haven’t found anything yet. Would you have any pointers on where I could read more on the scaling determinant’s purpose in the bone’s world rotation?

Unfortunately, I don’t really understand this part of our bone code, so I can’t really help…

From what I understand, it takes into account the fact that the matrix could be “left”/“right” handed (as we do for meshes coming from gltf files), and negate the X axis of the matrix (the first row) - we also negate scaling.x for the root bone in gltf case.

1 Like

These are great pointers :slight_smile: thank you so much!