Merge pull request #8 from maximstewart/master

Add Animation Import(s) to NLA Track List
This commit is contained in:
Will 2023-10-01 08:43:52 -07:00 committed by GitHub
commit 806a7cc060
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 15 deletions

View File

@ -162,14 +162,14 @@ def menu_func_export(self, context):
class ImportMSH(Operator, ImportHelper): class ImportMSH(Operator, ImportHelper):
""" Import an SWBF .msh file. """ """ Import SWBF .msh file(s). """
bl_idname = "swbf_msh.import" bl_idname = "swbf_msh.import"
bl_label = "Import SWBF .msh File(s)" bl_label = "Import SWBF .msh File(s)"
filename_ext = ".msh" filename_ext = ".msh"
files: CollectionProperty( files: CollectionProperty(
name="File Path", name="File Path(s)",
type=bpy.types.OperatorFileListElement, type=bpy.types.OperatorFileListElement,
) )
@ -181,7 +181,7 @@ class ImportMSH(Operator, ImportHelper):
animation_only: BoolProperty( animation_only: BoolProperty(
name="Import Animation(s)", 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 default=False
) )

View File

@ -32,7 +32,6 @@ def extract_and_apply_anim(filename : str, scene : Scene):
if scene.animation is None: if scene.animation is None:
raise Exception("No animation found in msh file!") raise Exception("No animation found in msh file!")
else: else:
head, tail = os.path.split(filename) head, tail = os.path.split(filename)
anim_name = tail.split(".")[0] anim_name = tail.split(".")[0]
@ -40,6 +39,10 @@ def extract_and_apply_anim(filename : str, scene : Scene):
if anim_name in bpy.data.actions: if anim_name in bpy.data.actions:
bpy.data.actions.remove(bpy.data.actions[anim_name], do_unlink=True) 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 = bpy.data.actions.new(anim_name)
action.use_fake_user = True action.use_fake_user = True
@ -103,4 +106,5 @@ def extract_and_apply_anim(filename : str, scene : Scene):
fcurve_loc_z.keyframe_points.insert(i,t.z) fcurve_loc_z.keyframe_points.insert(i,t.z)
arma.animation_data.action = action arma.animation_data.action = action
track = arma.animation_data.nla_tracks.new()
track.strips.new(action.name, action.frame_range[0], action)