Custom exporter and problems with matrix and rotation order I'm trying to write a custom exporter for cameras from/to Blender, but I'm having some problems with rotations and rotation order. In my mind I should be able to extract euler values from the world matrix in whatever rotation order I want, and as long as I make sure my camera in my other app use the same rotation order it should all work. But no.

Here's some example code:

import bpy
import mathutils
import math

item = bpy.data.objects["Camera"]

rot_mat = mathutils.Matrix.Rotation(math.radians(-90.0), 4, "X")

wm_src = item.matrix_world.copy()

wm = wm_src @ rot_mat

wm.transpose()

# Only works if rotation order is set to this.
rot = wm.to_euler("ZXY")

rotx = -math.degrees(rot.x)
roty = math.degrees(rot.y)
rotz = -math.degrees(rot.z)

rot_fix = (rotx, rotz, roty)

print(rot_fix)


This code works and the values match with the Alembic exporter.

However, it only works when I set the rotation order to ZXY. If I don't use ZXY, the camera is not rotated correctly. Am I missing something to be able to use whatever rotation order I want?

I'm not great with C++ code but is the Alembic exporter hardcoded to this order as well? It seems so.

Also, why do I need to transpose the matrix?
With ther help of batFINGER and the other post, here's the working code:

import bpy
import mathutils
import math
from bpy_extras.io_utils import axis_conversion

item = bpy.data.objects["Camera"]

wm_src = item.matrix_world.copy()

m = axis_conversion(from_forward='-Y', 
        from_up='Z',
        to_forward='Z',
        to_up='Y').to_4x4()

wm = m @ wm_src

rot = wm.to_euler("XYZ")

rotx = math.degrees(rot.x)
roty = math.degrees(rot.y)
rotz = math.degrees(rot.z)

rot_fix = (rotx, roty, rotz)

print(rot_fix)