Exporting System Matrix to DirectX

I’m exporting a mesh to DirectX using Blender’s export script…the root frame has a transformation matrix ( SystemMatrix ) that cannot be correctly converted to a quaternion. The root matrix is the following:

._11 = 1;
._12 = 0;
._13 = 0;
._14 = 0;
._21 = 0;
._22 = 0;
._23 = 1;
._24 = 0;
._31 = 0;
._32 = 1;
._33 = 0;
._34 = 0;
._41 = 0;
._42 = 0;
._43 = 0;
._44 = 1;

this matrix is not an affine transformation…the data here does not represent, entirely, a rotation matrix and therefore DirectX is not able to create a quaternion from this matrix…I use quaternions in my coding because they are much more stable! Is there a rotation quaternion within the system’s configuration that I can access with python? I would like to create a rotation matrix from that instead and change the export script to write this newtransformation matrix within the root frame…

…part of this matrix’s function is to rotate the entire character around the x-axis by 90 degrees. I believe it also rotates the character around the z or the y axis by 180 degrees…

…what I’d like to know is how to create a rotation matrix that will transform the mesh from Blender space to a relative orientation in DirectX…

you can always access objects’ rotation quaternion like:


or if you set the rotation mode of objects to Quaternion, you can also access the rotation like:


thanks CodeManX…since posting this thread I figured out that the “System Matrix” referred to in the export script was calculated by the script using options ( Flip X 90 Degrees, and Coordinate System Type( Left Handed or Right Handed ) ). It turns out that the information in the matrix is a rotation about the X-axis by -90 degrees, and a conversion from right handed coordinate system( Blender ) to left handed( DirectX ). I was able to correctly decompose this matrix in directX with this information…

…how do you set the rotation mode of objects to quaternion? in Blender? or using script? I’ll have to take a closer look at the Blender SDK documentation…thanks.

you can do both

  • UI: object tab, rotation mode > Quaternion (WXYZ)
  • Python: bpy.context.object.rotation_mode = ‘QUATERNION’