diff --git a/fast64_internal/sm64/animation/importing.py b/fast64_internal/sm64/animation/importing.py index ca6f27918..062871bd8 100644 --- a/fast64_internal/sm64/animation/importing.py +++ b/fast64_internal/sm64/animation/importing.py @@ -5,7 +5,7 @@ import os import bpy -from bpy.types import Object +from bpy.types import Object, Action from mathutils import Euler, Vector, Quaternion from ...utility import PluginError, decodeSegmentedAddr, path_checks @@ -90,25 +90,12 @@ def animation_data_to_blender( armature_obj: Object, blender_to_sm64_scale: float, anim_import: SM64_Anim, - actor_name: str, - remove_name_footer: bool = True, - use_custom_name: bool = True, + action: Action, ): anim_bones = get_anim_pose_bones(armature_obj) for pose_bone in anim_bones: pose_bone.rotation_mode = "QUATERNION" - action = bpy.data.actions.new("") - - if armature_obj.animation_data is None: - armature_obj.animation_data_create() - - stashActionInArmature(armature_obj, action) - armature_obj.animation_data.action = action - - if not anim_import.data: - return - bone_anim_data: list[SM64_AnimBone] = [] # TODO: Duplicate keyframe filter @@ -142,7 +129,26 @@ def animation_data_to_blender( for frame, rotation in enumerate(bone_data.rotation): f_curve.keyframe_points.insert(frame, rotation[property_index]) +def animation_import_to_blender( + armature_obj: Object, + blender_to_sm64_scale: float, + anim_import: SM64_Anim, + actor_name: str, + remove_name_footer: bool = True, + use_custom_name: bool = True, +): + action = bpy.data.actions.new("") + + if armature_obj.animation_data is None: + armature_obj.animation_data_create() + + if not anim_import.data: + animation_data_to_blender(armature_obj=armature_obj, blender_to_sm64_scale=blender_to_sm64_scale, anim_import=anim_import, action=action,) + anim_import.to_props(action, actor_name, remove_name_footer, use_custom_name) + + stashActionInArmature(armature_obj, action) + armature_obj.animation_data.action = action def import_animation_from_c_header( diff --git a/fast64_internal/sm64/animation/operators.py b/fast64_internal/sm64/animation/operators.py index e55400a5f..805b4f1cb 100644 --- a/fast64_internal/sm64/animation/operators.py +++ b/fast64_internal/sm64/animation/operators.py @@ -32,7 +32,7 @@ from .importing import ( import_binary_animations, import_binary_dma_animation, - animation_data_to_blender, + animation_import_to_blender, import_binary_header, import_c_animations, import_insertable_binary_animations, @@ -509,7 +509,7 @@ def execute_operator(self, context): raise PluginError("Unimplemented import type.") for _, data in animations.items(): - animation_data_to_blender(armatureObj, sm64_props.blender_to_sm64_scale, data) + animation_import_to_blender(armatureObj, sm64_props.blender_to_sm64_scale, data) sm64_props.anim_export.table.from_anim_table_class(table) self.report({"INFO"}, "Success!") @@ -591,7 +591,7 @@ def execute_operator(self, context): import_c_animations(c_path, animations, table) for data in animations.values(): - animation_data_to_blender( + animation_import_to_blender( context.selected_objects[0], sm64_props.blender_to_sm64_scale, data, diff --git a/fast64_internal/utility_anim.py b/fast64_internal/utility_anim.py index 982706a16..853de705b 100644 --- a/fast64_internal/utility_anim.py +++ b/fast64_internal/utility_anim.py @@ -197,6 +197,7 @@ def stashActionInArmature(armatureObj: bpy.types.Object, action: bpy.types.Actio print(f'Stashing "{action.name}" in the object "{armatureObj.name}".') track = armatureObj.animation_data.nla_tracks.new() + track.name = action.name track.strips.new(action.name, int(action.frame_range[0]), action)