Custom camera exporter - rotation doesn't match Alembic export

I’m trying to make a custom exporter for cameras, but I have found some problems.

  • Change the rotation order of the camera in Blender to ZXY.
  • Export as Alembic and read into Nuke.
  • The Nuke camera matches the Blender camera.

When I try to do the same thing via a script it doesn’t match at all. This is the code I use (on the same camera, nothing changed):

import bpy
import mathutils
import math

item = bpy.data.objects[“Camera”]

rot_mat = mathutils.Matrix.Rotation(math.radians(-90.0), 4, ‘X’).to_4x4()

wm_src = item.matrix_world.copy()
wm = wm_src @ rot_mat

rot = wm.to_euler(“ZXY”)

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

print(rotx, rotz, roty)

If I use the default XYZ the result is closer, but still not correct. I think I did have this working some time ago though, so that might be a user error.

What special magic does the Alembic exporter do with rotations when exporting?

  • I’m fully aware this might be a user error.

After a bit more testing, this seems to match the Alembic export. Am I right in saying that the Alembic exporter always export in ZXY rotation order, no matter the rotation order in Blender?

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()

rot = wm.to_euler("ZXY")

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

rot_fix = (-(180-(-rotx)), -rotz, -roty) 

print(rot_fix)