selectionList = om.MSelectionList()
selectionList.add(object_name)
pass_mtx_mobj= om.MObject()
selectionList.getDependNode(0, pass_mtx_mobj)
dep_node = om.MFnDependencyNode(pass_mtx_mobj)
plug = dep_node.findPlug('inMatrix')
# 复制插槽
in_matrix_plug = om.MPlug(plug)
mtime = om.MTime(frame, om.MTime_uiUnit())
in_matrix_val = in_matrix_plug.asMObject(MDGContext(mtime))
in_matrix_data = om.MFnMatrixData(in_matrix_val)
worldMatrix = in_matrix_data.matrix()
# 复制矩阵
transform_matrix = MTransformationMatrix(worldMatrix)
pos = transform_matrix.getTranslation(MSpace.kWorld)
print("pos = {}, {}, {}".format(pos[0], pos[1], pos[2]))
util = om.MScriptUtil()
util.createFromDouble(0)
scale_array_ptr = util.asDoublePtr()
transform_matrix.getScale(scale_array_ptr, MSpace.kWorld)
scale = [om.MScriptUtil.getDoubleArrayItem(scale_array_ptr, n) for n in range(3)]
print('scale == {}'.format(scale))
quaternion = transform_matrix.rotation()
euler_rot = quaternion.asEulerRotation()
rot = [round(math.degrees(euler_rot[n]), 3) for n in range(3)]
print('rot == {}'.format(rot))
Maya python API获取 位移旋转缩放
于 2024-06-04 12:16:37 首次发布