From 825c6103f2befc6db86033e898c23d10905cb24b Mon Sep 17 00:00:00 2001 From: Lila <87947656+Lilaa3@users.noreply.github.com> Date: Sun, 7 Apr 2024 23:27:57 +0100 Subject: [PATCH] I NEED TO BED --- fast64_internal/sm64/animation/classes.py | 8 +++--- fast64_internal/sm64/animation/exporting.py | 26 +++++++++++--------- fast64_internal/sm64/animation/operators.py | 5 ++-- fast64_internal/sm64/animation/properties.py | 3 ++- fast64_internal/sm64/animation/utility.py | 2 +- fast64_internal/sm64/sm64_utility.py | 14 +---------- 6 files changed, 26 insertions(+), 32 deletions(-) diff --git a/fast64_internal/sm64/animation/classes.py b/fast64_internal/sm64/animation/classes.py index 2dcee637a..c26bf543b 100644 --- a/fast64_internal/sm64/animation/classes.py +++ b/fast64_internal/sm64/animation/classes.py @@ -24,10 +24,11 @@ def clean_frames(self): last_value = self.values[-1] - for i, value in enumerate(reversed(self.values[:-1])): + i = 0 + for i, value in enumerate(reversed(self.values)): if value != last_value: - self.values = self.values[: len(self.values) - i] - return + break + self.values = self.values[:-i] def get_frame(self, frame: int): return self.values[frame] if frame < len(self.values) else self.values[-1] @@ -261,7 +262,6 @@ def find_offset(added_pairs: list[SM64_AnimPair], pair: SM64_AnimPair): if max_frame > MAX_U16: raise PluginError("Index pair has too many frames.") - pair.clean_frames() existing_offset = find_offset(added_pairs, pair) if existing_offset is None: offset = len(value_table.data) diff --git a/fast64_internal/sm64/animation/exporting.py b/fast64_internal/sm64/animation/exporting.py index a161e7a02..5eaa13f7b 100644 --- a/fast64_internal/sm64/animation/exporting.py +++ b/fast64_internal/sm64/animation/exporting.py @@ -4,10 +4,10 @@ import mathutils from ...utility import ( + radians_to_s16, writeIfNotFound, writeInsertableFile, ) -from ..sm64_utility import radian_to_sm64_degree from ..sm64_constants import NULL from .classes import SM64_Anim, SM64_AnimPair @@ -26,17 +26,17 @@ def get_animation_pairs( SM64_AnimPair(), SM64_AnimPair(), ] - transXPair, transYPair, transZPair = pairs + trans_x_pair, trans_y_pair, trans_z_pair = pairs - rotationPairs: list[tuple[SM64_AnimPair]] = [] + rotation_pairs: list[tuple[SM64_AnimPair]] = [] for _ in anim_bones: - xyzPairs = ( + rotation = ( SM64_AnimPair(), SM64_AnimPair(), SM64_AnimPair(), ) - pairs.extend(xyzPairs) - rotationPairs.append(xyzPairs) + rotation_pairs.append(rotation) + pairs.extend(rotation) scale: mathutils.Vector = armature_obj.matrix_world.to_scale() * blender_to_sm64_scale @@ -52,15 +52,19 @@ def get_animation_pairs( for i, pose_bone in enumerate(anim_bones): if i == 0: # Only first bone has translation. translation: mathutils.Vector = pose_bone.location * scale - transXPair.values.append(int(translation.x)) - transYPair.values.append(int(translation.y)) - transZPair.values.append(int(translation.z)) + trans_x_pair.values.append(int(translation.x)) + trans_y_pair.values.append(int(translation.y)) + trans_z_pair.values.append(int(translation.z)) - for angle, pair in zip(pose_bone.matrix_basis.to_euler(), rotationPairs[i]): - pair.values.append(radian_to_sm64_degree(angle)) + for angle, pair in zip(pose_bone.matrix_basis.to_euler(), rotation_pairs[i]): + pair.values.append(radians_to_s16(angle)) + + for pair in pairs: + pair.clean_frames() armature_obj.animation_data.action = pre_export_action bpy.context.scene.frame_current = pre_export_frame + return pairs diff --git a/fast64_internal/sm64/animation/operators.py b/fast64_internal/sm64/animation/operators.py index 62fad32b7..c2df0d64a 100644 --- a/fast64_internal/sm64/animation/operators.py +++ b/fast64_internal/sm64/animation/operators.py @@ -44,6 +44,7 @@ ) from .utility import ( animation_operator_checks, + eval_num_from_str, get_action, ) from .constants import marioAnimationNames @@ -445,7 +446,7 @@ def execute_operator(self, context): parseLevelAtPointer(data, level_pointers[anim_import_props.level]).segmentData, animations, anim_import_props.read_entire_table, - anim_import_props.get_table_index(), + anim_import_props.mario_or_table_index, anim_import_props.ignore_null, table, ) @@ -476,7 +477,7 @@ def execute_operator(self, context): def execute(self, context): try: return self.execute_operator(context) - except Exception as e: + except Exception as exc: raisePluginError(self, e) return {"CANCELLED"} diff --git a/fast64_internal/sm64/animation/properties.py b/fast64_internal/sm64/animation/properties.py index 874cd33ac..015e8b345 100644 --- a/fast64_internal/sm64/animation/properties.py +++ b/fast64_internal/sm64/animation/properties.py @@ -877,7 +877,8 @@ class SM64_AnimImportProps(PropertyGroup): insertable_path: StringProperty(name="Path", subtype="FILE_PATH", default="") - def get_mario_table_index(self): + @property + def mario_or_table_index(self): return ( self.mario_animation if self.binary_import_type == "DMA" and self.mario_animation != -1 diff --git a/fast64_internal/sm64/animation/utility.py b/fast64_internal/sm64/animation/utility.py index 438563987..9f874c206 100644 --- a/fast64_internal/sm64/animation/utility.py +++ b/fast64_internal/sm64/animation/utility.py @@ -60,7 +60,7 @@ def get_action(action_name: str): def sm64_to_radian(signed_sm64_angle: int) -> float: unsigned_sm64_angle = signed_sm64_angle + (1 << 16) - degree = unsigned_sm64_angle * (360.0 / (2.0**16.0)) + degree = unsigned_sm64_angle * (360.0 / (1 << 16)) return math.radians(degree % 360.0) diff --git a/fast64_internal/sm64/sm64_utility.py b/fast64_internal/sm64/sm64_utility.py index 57c8ebd3a..bdc6b8864 100644 --- a/fast64_internal/sm64/sm64_utility.py +++ b/fast64_internal/sm64/sm64_utility.py @@ -3,7 +3,7 @@ import os from bpy.path import abspath -from ..utility import PluginError, filepath_checks, to_s16 +from ..utility import PluginError, filepath_checks def starSelectWarning(operator, fileStatus): @@ -61,18 +61,6 @@ def check_expanded(filepath: str): ) -def degree_to_sm64_degree(degree: float): - normalized_degree = round(degree % 360.0, 5) - sm64_degree = int((normalized_degree / 360.0) * (2**16)) - sm64_degree = to_s16(sm64_degree) - - return sm64_degree - - -def radian_to_sm64_degree(radian: float): - return degree_to_sm64_degree(math.degrees(radian)) - - class SM64_ShortArray: def __init__(self, name, signed): self.name = name