Free Motion Capture for Everyone πβ¨
TypeScript
Merge branch 'blender_stuff' into blender_stuff
aaroncherian1c519adefa66
diff --cc freemocap/fmc_blender.pyindex 1d9b6858,e0469f4f..1c33162b--- a/freemocap/fmc_blender.py+++ b/freemocap/fmc_blender.py@@@ -519,57 -98,23 +519,61 @@@ bpy.ops.object.mode_set(mode='OBJECT'#set keyframes for whole animationfor frame in range(scene.frame_start, scene.frame_end):scene.frame_set(frame)++#Select objects to export+col = bpy.data.collections.get("Collection")+if col:+ for obj in col.objects:+ if "Armature" == obj.name:+ obj.select_set(True)++++#Bake the skeletal animation+# ensure that only the armature is selected in Object mode+bpy.ops.object.mode_set(mode='OBJECT')+bpy.ops.object.select_all(action='DESELECT')+#Set armature active+bpy.context.view_layer.objects.active = bpy.data.objects[get_armature().name]+#Set armature selected+bpy.data.objects[get_armature().name].select_set(state=True)++#Change to pose mode+bpy.ops.object.mode_set(mode='POSE')++#Bake the animation+bpy.ops.nla.bake(frame_start=scene.frame_start, frame_end=scene.frame_end, only_selected=False, visual_keying=True, clear_constraints=True, use_current_action=False, bake_types={'POSE'})++bpy.ops.object.mode_set(mode='OBJECT')++#delete empties+empties = [e for e in bpy.data.objects+ if e.type.startswith('EMPTY')]++while empties:+ bpy.data.objects.remove(empties.pop())++order_of_markers = []-#set export path-export_path = str(Path(__file__).parent.resolve() / "exported_animation_from_script")-export_path = r'C:\Users\aaron\Documents\GitHub\freemocap\FreeMocap_Data\sesh_2021-10-14_17_28_30'+#Select objects to exportcol = bpy.data.collections.get("Collection")if col:for obj in col.objects:- if "Sphere" in obj.name:- obj.select_set(True)-+ if "Armature" in obj.name:+ obj.select_set(True)+ if obj.name == "Cube":+ bpy.data.objects.remove(obj)+#save blender file-bpy.ops.wm.save_as_mainfile(filepath= export_path + "/blender_data.blend")+++bpy.ops.wm.save_as_mainfile(filepath= sesh_path + "skeletal_animation_session.blend")#export FBX-bpy.ops.export_scene.fbx(filepath=export_path + "/exported_fbx_animation_from_script.fbx", path_mode='RELATIVE', bake_anim=True, use_selection=True, object_types={'MESH'}, use_mesh_modifiers = False, add_leaf_bones = False, axis_forward = '-X', axis_up = 'Z', bake_anim_use_all_bones = False, bake_anim_use_nla_strips = False, bake_anim_use_all_actions = False, bake_anim_force_startend_keying = False)+bpy.ops.export_scene.fbx(filepath=sesh_path + "skeletal_animation_session.fbx", path_mode='RELATIVE', bake_anim=True, use_selection=True, object_types={'MESH', 'ARMATURE'}, use_mesh_modifiers = False, add_leaf_bones = False, axis_forward = '-X', axis_up = 'Z', bake_anim_use_all_bones = False, bake_anim_use_nla_strips = False, bake_anim_use_all_actions = False, bake_anim_force_startend_keying = False)#export GLTF-bpy.ops.export_scene.gltf(filepath=export_path + "/exported_gltf_animation_from_script.gltf", export_format='GLTF_EMBEDDED', export_selected=True, ui_tab='ANIMATION', export_nla_strips=False)+bpy.ops.export_scene.gltf(filepath=sesh_path + "skeletal_animation_session.gltf", export_format='GLTF_EMBEDDED', export_selected=True, ui_tab='ANIMATION')++#export USD+bpy.ops.wm.usd_export(filepath=sesh_path + 'skeletal_animation_session.usdc', selected_objects_only=True, export_animation=True)++