Skip to content

Commit

Permalink
nla tracks are properely named on import
Browse files Browse the repository at this point in the history
  • Loading branch information
Lilaa3 committed Apr 21, 2024
1 parent 4310699 commit 9c3a088
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
36 changes: 21 additions & 15 deletions fast64_internal/sm64/animation/importing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions fast64_internal/sm64/animation/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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!")
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions fast64_internal/utility_anim.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down

0 comments on commit 9c3a088

Please sign in to comment.