MQuaternion is a good way to get the MEulerRotation. At least its the
only way I have used. There is actually a bug in the Maya API that
does not even let you get the rotation from the MTransformationMatrix
class.
This will error:
import maya.OpenMaya as OpenMaya
getMatrix = OpenMaya.MMatrix()
matrixList = ( 0.673, 1.545 , 0.0, 0.0,
-0.327, 2.545, 0.0, 0.0,
-0.327, 1.545, 1.0, 0.0,
-0.327, 1.545, 0.0, 1.0)
OpenMaya.MScriptUtil().createMatrixFromList(matrixList, getMatrix)
mTM = OpenMaya.MTransformationMatrix( getMatrix )
rotDoubleArray = OpenMaya.MScriptUtil()
rotDoubleArray.createFromList( [0.0, 0.0, 0.0], 3 )
rotDoubleArrayPtr = rotDoubleArray.asDoublePtr()
rotOrder = OpenMaya.MTransformationMatrix().kXYZ
mTM.getRotation( rotDoubleArrayPtr, rotOrder )
# Error: Wrong number of arguments for overloaded function
'MTransformationMatrix_getRotation'.
Possible C/C++ prototypes are:
getRotation(double [3],MTransformationMatrix::RotationOrder &)
getRotation(double [3],MTransformationMatrix::RotationOrder
&,MSpace::Space)
# Traceback (most recent call last):
# File "", line 1, in
# File "C:\buildforge\Maya_Main_Win32_Build\build\wrk\optim\runTime
\Python\Lib\site-packages\maya\OpenMaya.py", line 8044, in getRotation
# NotImplementedError: Wrong number of arguments for overloaded
function 'MTransformationMatrix_getRotation'.
# Possible C/C++ prototypes are:
# getRotation(double [3],MTransformationMatrix::RotationOrder &)
# getRotation(double [3],MTransformationMatrix::RotationOrder
&,MSpace::Space)
# #
The only way around it is with MQuaternion() example here:
import maya.OpenMaya as OpenMaya
getMatrix = OpenMaya.MMatrix()
matrixList = ( 0.673, 1.545 , 0.0, 0.0,
-0.327, 2.545, 0.0, 0.0,
-0.327, 1.545, 1.0, 0.0,
-0.327, 1.545, 0.0, 1.0)
OpenMaya.MScriptUtil().createMatrixFromList(matrixList, getMatrix)
mTM = OpenMaya.MTransformationMatrix( getMatrix )
rotOrder = OpenMaya.MTransformationMatrix().kXYZ
# Get the rotation as a quaternion then convert to Euler as needed
rotateOrder = 0
mquat = mTM.rotation()
rot = mquat.asEulerRotation()
rot.reorderIt( rotateOrder )
print rot.x, rot.y, rot.z
RyanT
Technical Artist
www.rtrowbridge.com/blog
Naughty Dog Inc.