| 149 | |
| 150 | # Process single pose into keyframed bone orientations |
| 151 | def process_pose(current_frame, pose, lhandpose, rhandpose, trans, pelvis_position): |
| 152 | |
| 153 | rod_rots = pose.reshape(24, 4) |
| 154 | lhrod_rots = lhandpose.reshape(15, 4) |
| 155 | rhrod_rots = rhandpose.reshape(15, 4) |
| 156 | |
| 157 | # rod_rots = pose.reshape(24, 3) |
| 158 | # lhrod_rots = lhandpose.reshape(15, 3) |
| 159 | # rhrod_rots = rhandpose.reshape(15, 3) |
| 160 | |
| 161 | # mat_rots = [Rodrigues(rod_rot) for rod_rot in rod_rots] |
| 162 | # lhmat_rots = [Rodrigues(rod_rot) for rod_rot in rod_rots] |
| 163 | # rhmat_rots = [Rodrigues(rod_rot) for rod_rot in rod_rots] |
| 164 | |
| 165 | # Set the location of the Pelvis bone to the translation parameter |
| 166 | armature = bpy.data.objects[ROOT_NAME] |
| 167 | bones = armature.pose.bones |
| 168 | |
| 169 | # Pelvis: X-Right, Y-Up, Z-Forward (Blender -Y) |
| 170 | |
| 171 | # Set absolute pelvis location relative to Pelvis bone head |
| 172 | bones[BODY_JOINT_NAMES[0]].location = Vector((100*trans[1], 100*trans[2], 100*trans[0])) - pelvis_position |
| 173 | |
| 174 | # bones['Root'].location = Vector(trans) |
| 175 | bones[BODY_JOINT_NAMES[0]].keyframe_insert('location', frame=current_frame) |
| 176 | |
| 177 | for index, mat_rot in enumerate(rod_rots, 0): |
| 178 | if index >= 24: |
| 179 | continue |
| 180 | |
| 181 | bone = bones[BODY_JOINT_NAMES[index]] |
| 182 | |
| 183 | # bone_rotation = Matrix(mat_rot).to_quaternion() |
| 184 | bone_rotation = Quaternion(mat_rot) |
| 185 | quat_x_90_cw = Quaternion((1.0, 0.0, 0.0), radians(-90)) |
| 186 | quat_z_90_cw = Quaternion((0.0, 0.0, 1.0), radians(-90)) |
| 187 | |
| 188 | if index == 0: |
| 189 | # Rotate pelvis so that avatar stands upright and looks along negative Y avis |
| 190 | bone.rotation_quaternion = (quat_x_90_cw @ quat_z_90_cw) @ bone_rotation |
| 191 | else: |
| 192 | bone.rotation_quaternion = bone_rotation |
| 193 | |
| 194 | bone.keyframe_insert('rotation_quaternion', frame=current_frame) |
| 195 | |
| 196 | for index, mat_rot in enumerate(lhrod_rots, 0): |
| 197 | if index >= 15: |
| 198 | continue |
| 199 | bone = bones[LHAND_JOINT_NAMES[index]] |
| 200 | bone_rotation = Quaternion(mat_rot) |
| 201 | bone.rotation_quaternion = bone_rotation |
| 202 | bone.keyframe_insert('rotation_quaternion', frame=current_frame) |
| 203 | |
| 204 | for index, mat_rot in enumerate(rhrod_rots, 0): |
| 205 | if index >= 15: |
| 206 | continue |
| 207 | bone = bones[RHAND_JOINT_NAMES[index]] |
| 208 | bone_rotation = Quaternion(mat_rot) |