Fixed import of animations to allow for bulk import
This commit is contained in:
		@@ -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
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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,11 @@ 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 +107,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)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user