Skip to content

Commit

Permalink
to do more
Browse files Browse the repository at this point in the history
  • Loading branch information
Lilaa3 committed Jan 7, 2024
1 parent ac54378 commit b90523e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 42 deletions.
80 changes: 40 additions & 40 deletions fast64_internal/sm64/animation/importing.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,23 @@ def __init__(self):
self.translation: list[mathutils.Vector] = []
self.rotation: list[mathutils.Quaternion] = []

def readPairs(self, pairs: list[SM64_AnimPair]):
def read_pairs(self, pairs: list[SM64_AnimPair]):
array: list[int] = []

maxFrame = max([len(pair.values) for pair in pairs])
for frame in range(maxFrame):
array.append([x.getFrame(frame) for x in pairs])
return array

def readTranslation(self, pairs: list[SM64_AnimPair], scale):
translationFrames = self.readPairs(pairs)
def read_translation(self, pairs: list[SM64_AnimPair], scale: float):
translationFrames = self.read_pairs(pairs)

for translationFrame in translationFrames:
scaledTrans = [(1.0 / scale) * x for x in translationFrame]
self.translation.append(scaledTrans)

def readRotation(self, pairs: list[SM64_AnimPair]):
rotationFrames: list[mathutils.Vector] = self.readPairs(pairs)
def read_rotation(self, pairs: list[SM64_AnimPair]):
rotationFrames: list[mathutils.Vector] = self.read_pairs(pairs)

prev = mathutils.Euler([0, 0, 0])

Expand All @@ -91,64 +91,63 @@ def readRotation(self, pairs: list[SM64_AnimPair]):
self.rotation.append(e.to_quaternion())


def animation_table_to_blender(table_elements, tableList: list["SM64_AnimHeader"]):
for header in tableList:
def animation_table_to_blender(table_elements, table_list: list[SM64_AnimHeader]):
for header in table_list:
table_elements.add()
table_elements[-1].action = bpy.data.actions[header.data.actionName]
table_elements[-1].headerVariant = header.headerVariant


def animationDataToBlender(armatureObj: bpy.types.Object, blender_to_sm64_scale: float, anim_import: SM64_Anim):
anim_bones = get_anim_pose_bones(armatureObj)
def animation_data_to_blender(armature_obj: Object, blender_to_sm64_scale: float, anim_import: SM64_Anim):
anim_bones = get_anim_pose_bones(armature_obj)
for pose_bone in anim_bones:
pose_bone.rotation_mode = "QUATERNION"

action = bpy.data.actions.new("")
anim_import.toAction(action)

if armatureObj.animation_data is None:
armatureObj.animation_data_create()
if armature_obj.animation_data is None:
armature_obj.animation_data_create()

stashActionInArmature(armatureObj, action)
armatureObj.animation_data.action = action
stashActionInArmature(armature_obj, action)
armature_obj.animation_data.action = action

boneAnimData: list[SM64_AnimBone] = []
bone_anim_data: list[SM64_AnimBone] = []

# TODO: Duplicate keyframe filter
pairs = anim_import.pairs
for pairNum in range(3, len(pairs), 3):
bone = SM64_AnimBone()
if pairNum == 3:
bone.readTranslation(pairs[0:3], blender_to_sm64_scale)
bone.readRotation(pairs[pairNum : pairNum + 3])

boneAnimData.append(bone)

isRootTranslation = True
for pose_bone, boneData in zip(anim_bones, boneAnimData):
if isRootTranslation:
for propertyIndex in range(3):
bone.read_translation(pairs[0:3], blender_to_sm64_scale)
bone.read_rotation(pairs[pairNum : pairNum + 3])
bone_anim_data.append(bone)

is_root_translation = True
for pose_bone, boneData in zip(anim_bones, bone_anim_data):
if is_root_translation:
for property_index in range(3):
fcurve = action.fcurves.new(
data_path='pose.bones["' + pose_bone.name + '"].location',
index=propertyIndex,
index=property_index,
action_group=pose_bone.name,
)
for frame in range(len(boneData.translation)):
fcurve.keyframe_points.insert(frame, boneData.translation[frame][propertyIndex])
isRootTranslation = False
fcurve.keyframe_points.insert(frame, boneData.translation[frame][property_index])
is_root_translation = False

for propertyIndex in range(4):
for property_index in range(4):
fcurve = action.fcurves.new(
data_path='pose.bones["' + pose_bone.name + '"].rotation_quaternion',
index=propertyIndex,
index=property_index,
action_group=pose_bone.name,
)
for frame in range(len(boneData.rotation)):
fcurve.keyframe_points.insert(frame, boneData.rotation[frame][propertyIndex])
fcurve.keyframe_points.insert(frame, boneData.rotation[frame][property_index])
return action


def importBinaryAnimations(
def import_binary_animations(
address: int,
is_segmented_pointer: bool,
level: str,
Expand Down Expand Up @@ -309,7 +308,7 @@ def importAnimation(dataDict, array: "ReadArray", arrays: list["ReadArray"]):
return header


def importCAnimations(
def import_c_animations(
path: str,
dataDict: dict[str, SM64_Anim],
tableList: list[SM64_Anim],
Expand Down Expand Up @@ -364,28 +363,29 @@ def import_animation_to_blender(
read_entire_table: Optional[bool] = None,
table_index: Optional[int] = None,
):
dataDict: dict[str, SM64_Anim] = {}
tableList: list[str] = []
data_dict: dict[str, SM64_Anim] = {}
table_list: list[str] = []

if import_type == "Binary":
import_rom_checks(import_rom_path)
with open(import_rom_path, "rb") as ROMData:
importBinaryAnimations(
import_binary_animations(
address,
is_segmented_pointer,
level,
binary_import_type,
read_entire_table,
table_index,
ROMData,
dataDict,
tableList,
data_dict,
table_list,
)
elif import_type == "C":
importCAnimations(c_path, dataDict, tableList)
import_c_animations(c_path, data_dict, table_list)
else:
raise PluginError("Unimplemented Import Type.")

for dataKey, data in dataDict.items():
animationDataToBlender(armature_obj, sm64_to_blender_scale, data)
animation_table_to_blender(table_elements, tableList)
for data in data_dict.values():
animation_data_to_blender(armature_obj, sm64_to_blender_scale, data)

animation_table_to_blender(table_elements, table_list)
4 changes: 2 additions & 2 deletions fast64_internal/sm64/animation/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from .importing import (
importBinaryDMAAnimation,
animationDataToBlender,
animation_data_to_blender,
animation_table_to_blender,
import_animation_to_blender,
)
Expand Down Expand Up @@ -328,7 +328,7 @@ def execute_operator(self, context):
raise PluginError("Unimplemented import type.")

for dataKey, data in dataDict.items():
animationDataToBlender(armatureObj, sm64Props.blender_to_sm64_scale, data)
animation_data_to_blender(armatureObj, sm64Props.blender_to_sm64_scale, data)
animation_table_to_blender(context, tableList)

return {"FINISHED"}
Expand Down

0 comments on commit b90523e

Please sign in to comment.