2
$\begingroup$

I am using https://github.com/KhronosGroup/glTF-Blender-Exporter in a script and trying to compare the exported rotation values. But none of them seem to match. Ie. for exported values in the gltf file such as :

"rotation": [0.7071068286895752, 0.0, 0.0, 0.7071067094802856]

the exported object in blender has the following values:

---> OBJECT ROTATION QUATERNION: <Quaternion (w=0.3715, x=0.6323, y=0.4318, z=-0.5251)>
---> OBJECT MATRIX LOCAL: <Quaternion (w=0.3715, x=0.6323, y=0.4318, z=-0.5251)>
---> OBJECT MATRIX WORLD: <Quaternion (w=0.3715, x=0.6323, y=0.4318, z=-0.5251)>

while exporting, the settings are set to export_yup=False so I guess no other transformation should be involved?

$\endgroup$
1
  • $\begingroup$ it seems that the tool exports raw matrix data instead of converting it to quaternions. The only true way is to find this piece of code in the source, and read it out. $\endgroup$
    – Mechanic
    Nov 24, 2018 at 23:01

1 Answer 1

1
$\begingroup$

I'm not seeing exactly the same issue. If I take the default Blender cube and rotate it, and look at the quaternion on the UI, this is what I see:

Blender screenshot

In glTF, the order of the quaternion's components is different. Blender is showing [W, X, Y, Z], but in glTF they are expressed as [X, Y, Z, W].

Thus, my exported cube (with export_yup turned off) looks like this:

VSCode screenshot

These are the same numbers, it's just that W has moved from the front to the back of the array.

Your example shows completely different numbers. There can be various reasons for this, including parent hierarchy and "parent inverse" transforms. But there's another potential explanation, too: The node orientation is being handled as matrices, not TRS (Translation, Rotation, Scale), in the exporter, and each matrix is being decomposed into TRS during the export process (source code). If the node's matrix happens to have more than one way to decompose into TRS, it's possible the decompose function will pick some other quaternion from the one you were expecting. But the end result should still work the same.

$\endgroup$
2
  • $\begingroup$ Thanks a lot for your answer! I've been implementing an open-source game engine and I was stuck in node tree rotation until I saw your solution. I don't understand the reason behind GLTF displaying quaternion as xyzw instead of wxyz. $\endgroup$
    – Mohammad f
    Apr 5, 2021 at 23:49
  • 2
    $\begingroup$ @Mohammadf The contents of glTF are closely tied to raw data formats needed by graphics APIs such as WebGL. The GLSL shading language for example will order its vec4 components as .xyzw, and that ordering is used in glTF as well. $\endgroup$
    – emackey
    Apr 6, 2021 at 13:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .