Skip to content

Commit

Permalink
Insertable binary combined table export works, along with import
Browse files Browse the repository at this point in the history
  • Loading branch information
Lilaa3 committed Apr 22, 2024
1 parent 936d16f commit dbedd48
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
10 changes: 5 additions & 5 deletions fast64_internal/sm64/animation/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,9 @@ def to_binary(self, is_dma: bool = False, start_address: int = 0):
headers_length = len(headers_set) * HEADER_SIZE
if data_set:
value_table, indice_tables = create_tables(data_set, "values")
indice_tables_offset = start_address + headers_length
indice_tables_length = sum([len(indice_table.data) for indice_table in indice_tables])
values_table_offset = indice_tables_length
indice_tables_offset = headers_offset + headers_length
indice_tables_length = sum([len(indice_table.data) * 2 for indice_table in indice_tables])
values_table_offset = indice_tables_offset + indice_tables_length

# Add the animation table
for anim_header in self.elements:
Expand All @@ -499,12 +499,12 @@ def to_binary(self, is_dma: bool = False, start_address: int = 0):
if anim_header.data:
ptrs.extend([start_address + len(data) + 12, start_address + len(data) + 16])
indice_offset = indice_tables_offset + sum(
[len(indice_table.data) for indice_table in indice_tables[: data_set.index(anim_header.data)]]
len(indice_table.data) * 2 for indice_table in indice_tables[: data_set.index(anim_header.data)]
)
data.extend(
anim_header.to_binary(
indice_offset,
values_table_offset,
indice_offset,
)
)
else:
Expand Down
3 changes: 1 addition & 2 deletions fast64_internal/sm64/animation/exporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,12 @@ def get_rotation_data(action: Action, bone: PoseBone, max_frame: int):


def get_animation_pairs(
blender_to_sm64_scale: float, action: Action, armature_obj: Object, quick_read: bool = True
blender_to_sm64_scale: float, max_frame: int, action: Action, armature_obj: Object, quick_read: bool = True
) -> tuple[list[int], list[int]]:
anim_bones = get_anim_pose_bones(armature_obj)
if len(anim_bones) < 1:
raise PluginError(f'No animation bones in armature "{armature_obj.name}"')

max_frame = action.fast64.sm64.get_max_frame(action)
pairs = []

print(f"Reading animation pair values from action {action.name}.")
Expand Down
2 changes: 1 addition & 1 deletion fast64_internal/sm64/animation/importing.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def import_insertable_binary_animations(

data_type = next(key for key, value in insertableBinaryTypes.items() if value == data_type_num)
if data_type == "Animation":
import_binary_header(data_reader, 0, False, animations)
import_binary_header(data_reader, False, animations)
elif data_type == "Animation Table":
import_binary_table(
table_reader=data_reader,
Expand Down
12 changes: 6 additions & 6 deletions fast64_internal/sm64/animation/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def execute_operator(self, context: Context):
export_props = context.scene.fast64.sm64.anim_export
table_elements = export_props.table.elements

if table_elements:
if self.array_index < len(table_elements):
table_element = table_elements[self.array_index]
else:
table_element = None
Expand Down Expand Up @@ -452,9 +452,10 @@ def execute_operator(self, context: Context):
table_props.update_table,
)
elif sm64_props.export_type == "Insertable Binary":
data, ptrs = animation.to_binary(export_props.is_binary_dma, 0)
path = abspath(export_props.insertable_path)
writeInsertableFile(path, 2, ptrs, 0, data)
#data, ptrs = animation.to_binary(export_props.is_binary_dma, 0)
#path = abspath(export_props.insertable_path)
#writeInsertableFile(path, 2, ptrs, 0, data)
pass
else:
raise PluginError(f"Unimplemented export type ({sm64_props.export_type})")
self.report({"INFO"}, "Animation exported successfully.")
Expand Down Expand Up @@ -582,8 +583,7 @@ def execute_operator(self, context):
insertable_data_reader=RomReading(insertable_file.read(), 0, None, rom_data, segment_data),
animations=animations,
table=table,
segment_data=segment_data,
table_index=import_props.mario_or_table_index if import_props.read_entire_table else None,
table_index=None if import_props.read_entire_table else import_props.mario_or_table_index,
ignore_null=import_props.ignore_null,
)
elif import_props.import_type == "C":
Expand Down
4 changes: 2 additions & 2 deletions fast64_internal/sm64/animation/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def to_data_class(
file_name: str = "anim_00.inc.c",
):
data = SM64_AnimData()
pairs = get_animation_pairs(blender_to_sm64_scale, action, armature_obj, quick_read)
pairs = get_animation_pairs(blender_to_sm64_scale, action.fast64.sm64.get_max_frame(action), action, armature_obj, quick_read)
data_name: str = toAlnum(f"anim_{action.name}")
values_reference = f"{data_name}_values"
indice_reference = f"{data_name}_indices"
Expand Down Expand Up @@ -1151,7 +1151,7 @@ def draw_binary_settings(self, layout: UILayout, export_type: str):
col.prop(self, "binary_level")

if export_type == "Insertable Binary":
prop_split(col, self, "insertable_path", "Path")
prop_split(col, self, "directory_path", "Path")

def draw_c_settings(self, layout: UILayout):
col = layout.column()
Expand Down

0 comments on commit dbedd48

Please sign in to comment.