本文整理汇总了Python中mathutils.Matrix.decompose方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.decompose方法的具体用法?Python Matrix.decompose怎么用?Python Matrix.decompose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mathutils.Matrix
的用法示例。
在下文中一共展示了Matrix.decompose方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getTranslationOrientation
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import decompose [as 别名]
def getTranslationOrientation(ob, file):
if isinstance(ob, bpy.types.Bone):
ob_matrix_local = ob.matrix_local.copy()
ob_matrix_local.transpose()
t = ob_matrix_local
ob_matrix_local = Matrix([[-t[2][0], -t[2][1], -t[2][2], -t[2][3]],
[t[1][0], t[1][1], t[1][2], t[1][3]],
[t[0][0], t[0][1], t[0][2], t[0][3]],
[t[3][0], t[3][1], t[3][2], t[3][3]]])
rotMatrix_z90_4x4 = Matrix.Rotation(math.radians(90.0), 4, 'Z')
rotMatrix_z90_4x4.transpose()
file.write('Name:%s\n' % ob.name)
t = rotMatrix_z90_4x4 * ob_matrix_local
matrix = Matrix([[t[0][0], t[0][1], t[0][2], t[0][3]],
[t[1][0], t[1][1], t[1][2], t[1][3]],
[t[2][0], t[2][1], t[2][2], t[2][3]],
[t[3][0], t[3][1], t[3][2], t[3][3]]])
parent = ob.parent
if parent:
parent_matrix_local = parent.matrix_local.copy()
parent_matrix_local.transpose()
t = parent_matrix_local
parent_matrix_local = Matrix([[-t[2][0], -t[2][1], -t[2][2], -t[2][3]],
[t[1][0], t[1][1], t[1][2], t[1][3]],
[t[0][0], t[0][1], t[0][2], t[0][3]],
[t[3][0], t[3][1], t[3][2], t[3][3]]])
par_matrix = rotMatrix_z90_4x4 * parent_matrix_local
par_matrix_cpy = par_matrix.copy()
par_matrix_cpy.invert()
matrix = matrix * par_matrix_cpy
matrix.transpose()
loc, rot, sca = matrix.decompose()
else:
matrix = ob.matrix_world
if matrix:
loc, rot, sca = matrix.decompose()
else:
raise "error: this should never happen!"
return loc, rot
示例2: assignFrame
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import decompose [as 别名]
def assignFrame(self, armature, frameNum, excludeFingers):
# this is REQUIRED to get something to actually get recorded other than just before assignment
bpy.context.scene.update()
for name in KINECT_BONES:
if excludeFingers and self.isFinger(name): continue
if name not in armature.data.bones: continue
bone = armature.pose.bones[name]
objectSpace = bone.matrix
localSpace = Matrix(armature.convert_space(bone, objectSpace, 'POSE', 'LOCAL'))
loc, rot, scale = localSpace.decompose()
if name == ROOT_BONE:
bone.location = self.relativeRootLoc(frameNum)
bone.keyframe_insert('location', frame = frameNum, group = name)
bone.rotation_quaternion = rot
bone.keyframe_insert('rotation_quaternion', frame = frameNum, group = name)
示例3: read_chan
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import decompose [as 别名]
def read_chan(context, filepath, z_up, rot_ord, sensor_width, sensor_height):
# get the active object
scene = context.scene
obj = context.active_object
camera = obj.data if obj.type == 'CAMERA' else None
# prepare the correcting matrix
rot_mat = Matrix.Rotation(radians(90.0), 4, 'X').to_4x4()
# read the file
filehandle = open(filepath, 'r')
# iterate throug the files lines
for line in filehandle:
# reset the target objects matrix
# (the one from whitch one we'll extract the final transforms)
m_trans_mat = Matrix()
# strip the line
data = line.split()
# test if the line is not commented out
if data and not data[0].startswith("#"):
# set the frame number basing on the chan file
scene.frame_set(int(data[0]))
# read the translation values from the first three columns of line
v_transl = Vector((float(data[1]),
float(data[2]),
float(data[3])))
translation_mat = Matrix.Translation(v_transl)
translation_mat.to_4x4()
# read the rotations, and set the rotation order basing on the
# order set during the export (it's not being saved in the chan
# file you have to keep it noted somewhere
# the actual objects rotation order doesn't matter since the
# rotations are being extracted from the matrix afterwards
e_rot = Euler((radians(float(data[4])),
radians(float(data[5])),
radians(float(data[6]))))
e_rot.order = rot_ord
mrot_mat = e_rot.to_matrix()
mrot_mat.resize_4x4()
# merge the rotation and translation
m_trans_mat = translation_mat * mrot_mat
# correct the world space
# (nuke's and blenders scene spaces are different)
if z_up:
m_trans_mat = rot_mat * m_trans_mat
# break the matrix into a set of the coordinates
trns = m_trans_mat.decompose()
# set the location and the location's keyframe
obj.location = trns[0]
obj.keyframe_insert("location")
# convert the rotation to euler angles (or not)
# basing on the objects rotation mode
if obj.rotation_mode == 'QUATERNION':
obj.rotation_quaternion = trns[1]
obj.keyframe_insert("rotation_quaternion")
elif obj.rotation_mode == 'AXIS_ANGLE':
tmp_rot = trns[1].to_axis_angle()
obj.rotation_axis_angle = (tmp_rot[1], *tmp_rot[0])
obj.keyframe_insert("rotation_axis_angle")
del tmp_rot
else:
obj.rotation_euler = trns[1].to_euler(obj.rotation_mode)
obj.keyframe_insert("rotation_euler")
# check if the object is camera and fov data is present
if camera and len(data) > 7:
camera.sensor_fit = 'HORIZONTAL'
camera.sensor_width = sensor_width
camera.sensor_height = sensor_height
camera.angle_y = radians(float(data[7]))
camera.keyframe_insert("lens")
filehandle.close()
return {'FINISHED'}