MCPcopy
hub / github.com/OpenMotionLab/MotionGPT / process_poses

Function process_poses

scripts/fbx_output.py:154–230  ·  view source on GitHub ↗
(
        input_path,
        gender,
        fps_source,
        fps_target,
        start_origin,
        person_id=1,
)

Source from the content-addressed store, hash-verified

152
153# Process all the poses from the pose file
154def process_poses(
155 input_path,
156 gender,
157 fps_source,
158 fps_target,
159 start_origin,
160 person_id=1,
161):
162
163 print('Processing: ' + input_path)
164
165 data = joblib.load(input_path)
166 person_id = list(data.keys())[0]
167 poses = data[person_id]['pose']
168 if 'trans' not in data[person_id].keys():
169 trans = np.zeros((poses.shape[0], 3))
170 else:
171 trans = data[person_id]['trans']
172
173 if gender == 'female':
174 model_path = female_model_path
175 for k,v in bone_name_from_index.items():
176 bone_name_from_index[k] = 'f_avg_' + v
177 elif gender == 'male':
178 model_path = male_model_path
179 for k,v in bone_name_from_index.items():
180 bone_name_from_index[k] = 'm_avg_' + v
181 else:
182 print('ERROR: Unsupported gender: ' + gender)
183 sys.exit(1)
184
185 # Limit target fps to source fps
186 if fps_target > fps_source:
187 fps_target = fps_source
188
189 print(f'Gender: {gender}')
190 print(f'Number of source poses: {str(poses.shape[0])}')
191 print(f'Source frames-per-second: {str(fps_source)}')
192 print(f'Target frames-per-second: {str(fps_target)}')
193 print('--------------------------------------------------')
194
195 setup_scene(model_path, fps_target)
196
197 scene = bpy.data.scenes['Scene']
198 sample_rate = int(fps_source/fps_target)
199 scene.frame_end = (int)(poses.shape[0]/sample_rate)
200
201 # Retrieve pelvis world position.
202 # Unit is [cm] due to Armature scaling.
203 # Need to make copy since reference will change when bone location is modified.
204 bpy.ops.object.mode_set(mode='EDIT')
205 pelvis_position = Vector(bpy.data.armatures[0].edit_bones[bone_name_from_index[0]].head)
206 bpy.ops.object.mode_set(mode='OBJECT')
207
208 source_index = 0
209 # source_index = 16
210 frame = 1
211

Callers 1

fbx_output.pyFile · 0.70

Calls 4

keysMethod · 0.80
itemsMethod · 0.80
setup_sceneFunction · 0.70
process_poseFunction · 0.70

Tested by

no test coverage detected