# How can I decompose a matrix for use in DirectX?

I'm writing a custom exporter from Blender that will work with DirectX. I am using as a guideline the DirectX exporter found in Blender 2.76. The Blender export script for DirectX uses the following conversion matrix:

code:

# SystemMatrix converts from right-handed, z-up to the target coordinate system
self.SystemMatrix = Matrix()

if self.Config.CoordinateSystem == 'LEFT_HANDED':
self.SystemMatrix *= Matrix.Scale(-1, 4, Vector((0, 0, 1)))

if self.Config.UpAxis == 'Y':


matrix:

1, 0, 0, 0
0, 0, 1, 0
0, 1, 0, 0
0, 0, 0, 1


I want to write the components of this matrix so I decompose the matrix like so:

loc, rot, sca = self.SystemMatrix.decompose()


now I convert the rotation from quaternion to euler like so:

eul = rot.to_euler('XYZ')


write components ...

The problem is that when I try to recompose the matrix in my DirectX graphics application I get the wrong matrix...

code to recompose matrix:

Matrix m = Matrix.Scaling(sca.x, sca.y, sca.z) * Matrix.RotationYawPitchRoll(eul.x, eul.y, eul.z)
* Matrix.Translation(loc.x, loc.y, loc.z)


result:

0, 0, 1, 0
0, 1, 0, 0
1, 0, 0, 0
0, 0, 0, 1


Matrix m = Matrix.Translation(loc.x, loc.y, loc.z) * Matrix.RotationYawPitchRoll(eul.x, eul.y, eul.z) * Matrix.Scaling(sca.x, sca.y, sca.z)