MCPcopy Index your code
hub / github.com/OpenMotionLab/MotionGPT / process_pose

Function process_pose

scripts/fbx_output.py:111–150  ·  view source on GitHub ↗
(current_frame, pose, trans, pelvis_position)

Source from the content-addressed store, hash-verified

109
110# Process single pose into keyframed bone orientations
111def process_pose(current_frame, pose, trans, pelvis_position):
112
113 if pose.shape[0] == 72:
114 rod_rots = pose.reshape(24, 3)
115 else:
116 rod_rots = pose.reshape(26, 3)
117
118 mat_rots = [Rodrigues(rod_rot) for rod_rot in rod_rots]
119
120 # Set the location of the Pelvis bone to the translation parameter
121 armature = bpy.data.objects['Armature']
122 bones = armature.pose.bones
123
124 # Pelvis: X-Right, Y-Up, Z-Forward (Blender -Y)
125
126 # Set absolute pelvis location relative to Pelvis bone head
127 bones[bone_name_from_index[0]].location = Vector((100*trans[1], 100*trans[2], 100*trans[0])) - pelvis_position
128
129 # bones['Root'].location = Vector(trans)
130 bones[bone_name_from_index[0]].keyframe_insert('location', frame=current_frame)
131
132 for index, mat_rot in enumerate(mat_rots, 0):
133 if index >= 24:
134 continue
135
136 bone = bones[bone_name_from_index[index]]
137
138 bone_rotation = Matrix(mat_rot).to_quaternion()
139 quat_x_90_cw = Quaternion((1.0, 0.0, 0.0), radians(-90))
140 quat_z_90_cw = Quaternion((0.0, 0.0, 1.0), radians(-90))
141
142 if index == 0:
143 # Rotate pelvis so that avatar stands upright and looks along negative Y avis
144 bone.rotation_quaternion = (quat_x_90_cw @ quat_z_90_cw) @ bone_rotation
145 else:
146 bone.rotation_quaternion = bone_rotation
147
148 bone.keyframe_insert('rotation_quaternion', frame=current_frame)
149
150 return
151
152
153# Process all the poses from the pose file

Callers 1

process_posesFunction · 0.70

Calls 1

RodriguesFunction · 0.70

Tested by

no test coverage detected