Skip to content

Commit

Permalink
I NEED TO BED
Browse files Browse the repository at this point in the history
  • Loading branch information
Lilaa3 committed Apr 7, 2024
1 parent 82bc861 commit 825c610
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 32 deletions.
8 changes: 4 additions & 4 deletions fast64_internal/sm64/animation/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)
Expand Down
26 changes: 15 additions & 11 deletions fast64_internal/sm64/animation/exporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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


Expand Down
5 changes: 3 additions & 2 deletions fast64_internal/sm64/animation/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
)
from .utility import (
animation_operator_checks,
eval_num_from_str,
get_action,
)
from .constants import marioAnimationNames
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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"}

Expand Down
3 changes: 2 additions & 1 deletion fast64_internal/sm64/animation/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion fast64_internal/sm64/animation/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
14 changes: 1 addition & 13 deletions fast64_internal/sm64/sm64_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 825c610

Please sign in to comment.