Rotations from Blender don't match up with Babylon

Any idea why rotations from Blender, when entered exactly the same in Babylon would produce different results?

To demonstrate, I just made a simple box in Blender and rotated it. Then exported as GLB, opened in sandbox and then entered in the quaternion values. Rotation is different as you can see in screenshot.

Is it b/c Blender does WXYZ and Babylon does XYZW?

Looks like it is that. In Blender the W axis is the first value taken into account in the X axis in Babylon and produces this shift.

It’s probably a bug of the exporter Blender I suppose. Can be exported without using Quaternion will solve your problem if using Euler suits you. (The time that this bug is fixed)

pinging @JCPalmer or @Vinc3r or @gryff (the Blender Clan :))

Are you sure it’s an issue? Blender is Z-up while BJS is Y-up, so it looks like logic to me as I can guess from the screenshot.

So to set up the scene in BJS so that it mirrors the scene in Blender, one would do what? Like, to make a function called “MirrorBlender” it would require what - a reorientation of the camera? Or some kind of Z to Y up conversion?

Btw, the issue i’m trying to address is getting poses in BJS to match what I see in Blender. I’m getting legs pointing straight up in the air and twisted around the wrong way. Just trying to figure out how the heck I can get a pose in BJS to match what I see in Blender.

When using the .babylon / JSON exporter, a quaternion is writing using:

def format_quaternion(quaternion, precision = FLOAT_PRECISION_DEFAULT):
    fmt = '%.' + str(precision) + 'f'
    return format_float(quaternion.x, fmt) + ',' + format_float(quaternion.z, fmt) + ',' + format_float(quaternion.y, fmt) + ',' + format_float(-quaternion.w, fmt)

If you cannot read python, basically the z & y are flipped, and the sign is switched for w. I am not sure whether glTF is y or z up, but if it is y up, shouldn’t the BJS importer be doing the switch?

Well, I created a simplecube and rotated it on the Y axis and then exported it from Blender 2.80 as a .babylon file and and a glb file.

For the .glb export there is a little check box that allows you to export with “+y up”. @JCPalmer 's Babylon exporter does it automatically which is why I always use it :slight_smile:

Below is an image showing the two exports. Note that both rotations are around the Z-axis as would be expected.

Please try it yourself see if you get the same results

As for

With the babylon export that usually means that there scale/rotation differences between the rig and the mesh(es). Not sure how the glb exporter works with that.

cheers, gryff :slight_smile:

@Deltakosh : PS: Looks like all the old clan is out on this :grin:

1 Like

Didn’t get a chance to try the cube experiment yet… but the alternate ordering and any other ordering is giving me a jumble of body parts (see my poor guy below). Maybe I can’t simply set the rotation quaternions to the values in the matrix in the .babylon files? Beginning to think this approach is doomed.

All of these result in a jumble:
// tnodes[bonename].rotationQuaternion=new BABYLON.Quaternion(m[0],m[1],m[2],m[3]);
//tnodes[bonename].rotationQuaternion=new BABYLON.Quaternion(m[4],m[5],m[6],m[7]);
//tnodes[bonename].rotationQuaternion=new BABYLON.Quaternion(m[9],m[10],m[11],m[8]);
//tnodes[bonename].rotationQuaternion=new BABYLON.Quaternion(m[5],m[6],m[7],m[4]);
tnodes[bonename].rotationQuaternion=new BABYLON.Quaternion(m[5],m[7],m[6],-m[4]);

Where the matrix is in Json as follows (in the values array below). I’m just looping through all of the transform nodes for frame 1 - and setting the rotation values - to try to re-create a pose… and to animate the character from a data file (since i can’t get any of the animation functions working with GLBs unless i combine all animations into a single GLB… which is impractical for my use case).

Oh yes, the character is doing a lot of gymnastics. :slightly_smiling_face: Sorry this message is not helpful.

Try to use this to prevent the character from distorting :
mesh.updatePoseMatrix(BABYLON.Matrix.Identity());`

Or can be ignored Quaternion and use Euler for rotation.

mesh.rotationQuaternion= null;
Then use : mesh.rotation = new Vector3

1 Like

LOVE THAT!

Yea, i feel so sorry for the guy - with his legs coming out of his ears.

mesh.updatePoseMatrix doesn’t do anything unfortunately… even if i send it a matrix with arbitrary values - has no effect. tried updating the poseMatrix using the transform nodes also… still no effect.

Am thinking that the transform nodes / GLB format is adding a level of complexity. Going to try using an Obj instead.