diff --git a/blender/arm/exporter.py b/blender/arm/exporter.py index f9c24b61..5573b362 100755 --- a/blender/arm/exporter.py +++ b/blender/arm/exporter.py @@ -802,10 +802,16 @@ class ArmoryExporter: o['bone_actions'].append('action_' + armatureid + '_' + aname + ext) orig_action = bobject.animation_data.action + skelobj = bobject baked_actions = [] + if bdata.arm_autobake and bobject.name not in bpy.context.collection.all_objects: + #clone bjobject and put in the current scene so the bake operator can run + skelobj = bobject.copy() + bpy.context.collection.objects.link(skelobj) + for action in export_actions: aname = arm.utils.safestr(arm.utils.asset_name(action)) - bobject.animation_data.action = action + skelobj.animation_data.action = action fp = self.get_meshes_file_path('action_' + armatureid + '_' + aname, compressed=self.is_compress()) assets.add(fp) if bdata.arm_cached == False or not os.path.exists(fp): @@ -813,11 +819,10 @@ class ArmoryExporter: if bdata.arm_autobake: sel = bpy.context.selected_objects[:] for _o in sel: _o.select_set(False) - bobject.select_set(True) - print('Baking action '+aname) + skelobj.select_set(True) bpy.ops.nla.bake(frame_start = action.frame_range[0], frame_end=action.frame_range[1], step=1, only_selected=False, visual_keying=True) - action = bobject.animation_data.action - bobject.select_set(False) + action = skelobj.animation_data.action + skelobj.select_set(False) for _o in sel: _o.select_set(True) baked_actions.append(action) @@ -827,7 +832,7 @@ class ArmoryExporter: for bone in bdata.bones: if not bone.parent: boneo = {} - self.export_bone(bobject, bone, scene, boneo, action) + self.export_bone(skelobj, bone, scene, boneo, action) bones.append(boneo) self.write_bone_matrices(scene, action) if len(bones) > 0 and 'anim' in bones[0]: @@ -838,10 +843,13 @@ class ArmoryExporter: action_obj['objects'] = bones arm.utils.write_arm(fp, action_obj) - #clear baked actions - for a in baked_actions: - bpy.data.actions.remove( a, do_unlink=True) - bobject.animation_data.action = orig_action + #restore settings + skelobj.animation_data.action = orig_action + for a in baked_actions: bpy.data.actions.remove( a, do_unlink=True) + if skelobj != bobject: + bpy.context.collection.objects.unlink(skelobj) + bpy.data.objects.remove(skelobj, do_unlink=True) + # TODO: cache per action bdata.arm_cached = True