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?
from bpy_extras.io_utils import axis_conversion
which creates a transform matrix from one def to the other. On the transpose, my guess is it is a quick way to invert an orthonormal matrix (eg a rotation matrix) $\endgroup$ – batFINGER Nov 15 '19 at 1:56