From 125ad2792c5629817296125b92ba310912ce95de Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Sun, 28 May 2023 13:47:33 -0500 Subject: [PATCH 1/3] Fixed import of animations to allow for bulk import --- addons/io_scene_swbf_msh/__init__.py | 18 +++++++++--------- addons/io_scene_swbf_msh/msh_anim_to_blend.py | 17 +++++++++++------ 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/addons/io_scene_swbf_msh/__init__.py b/addons/io_scene_swbf_msh/__init__.py index 16c5d49..3f0c56f 100644 --- a/addons/io_scene_swbf_msh/__init__.py +++ b/addons/io_scene_swbf_msh/__init__.py @@ -13,9 +13,9 @@ bl_info = { } # Taken from glTF-Blender-IO, because I do not understand Python that well -# (this is the first thing of substance I've created in it) and just wanted +# (this is the first thing of substance I've created in it) and just wanted # script reloading to work. -# +# # https://github.com/KhronosGroup/glTF-Blender-IO # # Copyright 2018-2019 The glTF-Blender-IO authors. @@ -124,7 +124,7 @@ class ExportMSH(Operator, ExportHelper): scene, armature_obj = create_scene( - generate_triangle_strips=self.generate_triangle_strips, + generate_triangle_strips=self.generate_triangle_strips, apply_modifiers=self.apply_modifiers, export_target=self.export_target, skel_only=self.animation_export != 'NONE') # Exclude geometry data (except root stuff) if we're doing anims @@ -141,7 +141,7 @@ class ExportMSH(Operator, ExportHelper): set_scene_animation(scene, armature_obj) write_scene_to_file(self.filepath, scene) - elif self.animation_export == 'BATCH': + elif self.animation_export == 'BATCH': export_dir = self.filepath if os.path.isdir(self.filepath) else os.path.dirname(self.filepath) for action in bpy.data.actions: @@ -162,14 +162,14 @@ def menu_func_export(self, context): class ImportMSH(Operator, ImportHelper): - """ Import an SWBF .msh file. """ + """ Import SWBF .msh file(s). """ bl_idname = "swbf_msh.import" bl_label = "Import SWBF .msh File(s)" filename_ext = ".msh" files: CollectionProperty( - name="File Path", + name="File Path(s)", type=bpy.types.OperatorFileListElement, ) @@ -181,7 +181,7 @@ class ImportMSH(Operator, ImportHelper): animation_only: BoolProperty( name="Import Animation(s)", - description="Import on or more animations from the selected files and append each as a new Action to currently selected Armature.", + description="Import one or more animations from the selected files and append each as a new Action to currently selected Armature.", default=False ) @@ -193,9 +193,9 @@ class ImportMSH(Operator, ImportHelper): if filepath.endswith(".zaabin") or filepath.endswith(".zaa"): extract_and_apply_munged_anim(filepath) else: - with open(filepath, 'rb') as input_file: + with open(filepath, 'rb') as input_file: scene = read_scene(input_file, self.animation_only) - + if not self.animation_only: extract_scene(filepath, scene) else: diff --git a/addons/io_scene_swbf_msh/msh_anim_to_blend.py b/addons/io_scene_swbf_msh/msh_anim_to_blend.py index 6a822a9..d76507b 100644 --- a/addons/io_scene_swbf_msh/msh_anim_to_blend.py +++ b/addons/io_scene_swbf_msh/msh_anim_to_blend.py @@ -32,7 +32,6 @@ def extract_and_apply_anim(filename : str, scene : Scene): if scene.animation is None: raise Exception("No animation found in msh file!") - else: head, tail = os.path.split(filename) anim_name = tail.split(".")[0] @@ -40,6 +39,11 @@ def extract_and_apply_anim(filename : str, scene : Scene): if anim_name in bpy.data.actions: bpy.data.actions.remove(bpy.data.actions[anim_name], do_unlink=True) + for nt in arma.animation_data.nla_tracks: + if anim_name == nt.strips[0].name: + arma.animation_data.nla_tracks.remove(nt) + + action = bpy.data.actions.new(anim_name) action.use_fake_user = True @@ -47,7 +51,7 @@ def extract_and_apply_anim(filename : str, scene : Scene): arma.animation_data_create() - # Record the starting transforms of each bone. Pose space is relative + # Record the starting transforms of each bone. Pose space is relative # to bones starting transforms. Starting = in edit mode bone_bind_poses = {} @@ -56,7 +60,7 @@ def extract_and_apply_anim(filename : str, scene : Scene): for edit_bone in arma.data.edit_bones: if edit_bone.parent: - bone_local = edit_bone.parent.matrix.inverted() @ edit_bone.matrix + bone_local = edit_bone.parent.matrix.inverted() @ edit_bone.matrix else: bone_local = arma.matrix_local @ edit_bone.matrix @@ -72,8 +76,8 @@ def extract_and_apply_anim(filename : str, scene : Scene): translation_frames, rotation_frames = scene.animation.bone_frames[to_crc(bone.name)] - loc_data_path = "pose.bones[\"{}\"].location".format(bone.name) - rot_data_path = "pose.bones[\"{}\"].rotation_quaternion".format(bone.name) + loc_data_path = "pose.bones[\"{}\"].location".format(bone.name) + rot_data_path = "pose.bones[\"{}\"].rotation_quaternion".format(bone.name) fcurve_rot_w = action.fcurves.new(rot_data_path, index=0, action_group=bone.name) @@ -103,4 +107,5 @@ def extract_and_apply_anim(filename : str, scene : Scene): fcurve_loc_z.keyframe_points.insert(i,t.z) arma.animation_data.action = action - + track = arma.animation_data.nla_tracks.new() + track.strips.new(action.name, action.frame_range[0], action) From 1ec43325766446850e468e4c59ae9c2623484539 Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Fri, 2 Jun 2023 21:49:24 -0500 Subject: [PATCH 2/3] Animation Track patch cleanup --- addons/io_scene_swbf_msh/msh_anim_to_blend.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/addons/io_scene_swbf_msh/msh_anim_to_blend.py b/addons/io_scene_swbf_msh/msh_anim_to_blend.py index d76507b..39dc5f5 100644 --- a/addons/io_scene_swbf_msh/msh_anim_to_blend.py +++ b/addons/io_scene_swbf_msh/msh_anim_to_blend.py @@ -43,7 +43,6 @@ def extract_and_apply_anim(filename : str, scene : Scene): if anim_name == nt.strips[0].name: arma.animation_data.nla_tracks.remove(nt) - action = bpy.data.actions.new(anim_name) action.use_fake_user = True @@ -106,6 +105,5 @@ def extract_and_apply_anim(filename : str, scene : Scene): fcurve_loc_y.keyframe_points.insert(i,t.y) fcurve_loc_z.keyframe_points.insert(i,t.z) - arma.animation_data.action = action track = arma.animation_data.nla_tracks.new() track.strips.new(action.name, action.frame_range[0], action) From d1d83d39affc7aff00902d839872baf3f3cc37aa Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Fri, 2 Jun 2023 22:27:58 -0500 Subject: [PATCH 3/3] Partial Revert: Animation Track patch cleanup --- addons/io_scene_swbf_msh/msh_anim_to_blend.py | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/io_scene_swbf_msh/msh_anim_to_blend.py b/addons/io_scene_swbf_msh/msh_anim_to_blend.py index 39dc5f5..79732ef 100644 --- a/addons/io_scene_swbf_msh/msh_anim_to_blend.py +++ b/addons/io_scene_swbf_msh/msh_anim_to_blend.py @@ -105,5 +105,6 @@ def extract_and_apply_anim(filename : str, scene : Scene): fcurve_loc_y.keyframe_points.insert(i,t.y) fcurve_loc_z.keyframe_points.insert(i,t.z) + arma.animation_data.action = action track = arma.animation_data.nla_tracks.new() track.strips.new(action.name, action.frame_range[0], action)