从矩阵中获得旋转,OpenMaya



我正在使用OpenMaya,我需要从矩阵中获得欧拉旋转,但当我启动这个简单的代码时,我得到了一个错误:

代码:

import maya.OpenMaya as OpenMaya
import maya.cmds as mc
crcl=mc.circle()
matrx=(OpenMaya.MMatrix(mc.xform(crcl,q=1,m=1)))
tMat = OpenMaya.MTransformationMatrix(matrx)
eulerRotation = tMat.rotation(asQuaternion=False)

误差

Error: in method 'new_MMatrix', argument 1 of type 'float const [4][4]'

问题是OpenMaya.MTransformationMatrix(matrx),看起来不接受我的矩阵。任何帮助吗?

MTransformationMatrix文档我肯定是一个简单的修复,我错过了

获取矩阵的一种方法是避免通过MEL命令,直接使用OpenMayaAPI。

import math
# I'm Using `maya.api.OpenMaya` here since I'm testing on Maya 2019.
# Change according to your version.
import maya.api.OpenMaya as OpenMaya
import maya.cmds as mc
crcl = mc.circle()
mc.rotate(45.0, 10.0, 5.0, crcl)
# Add the circle to the selection so we can retrieve its `MObject`.
selection = OpenMaya.MSelectionList()
selection.add(crcl[0])
# Get the circle `MObject` and create a `MFnDagNode` from it.
obj = selection.getDependNode(0)
dagNode = OpenMaya.MFnDagNode(obj)
matrix = dagNode.transformationMatrix()
tMat = OpenMaya.MTransformationMatrix(matrix)
eulerRotation = tMat.rotation(asQuaternion=False)
# This should print the following (only differences would potentially be in
# floating point accuracy):
# [45.0, 10.0, 5.0]
print(map(math.degrees, eulerRotation))

相关内容

  • 没有找到相关文章

最新更新