Skip to content

Commit

Permalink
quick read ui
Browse files Browse the repository at this point in the history
  • Loading branch information
Lilaa3 committed Apr 20, 2024
1 parent de8f91c commit 1991d81
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 31 deletions.
46 changes: 21 additions & 25 deletions fast64_internal/sm64/animation/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ def execute_operator(self, context: Context):

scene = context.scene
sm64_props = scene.fast64.sm64
anim_export_props = sm64_props.anim_export
table_props = anim_export_props.table
export_props = sm64_props.anim_export
table_props = export_props.table

actions = table_props.actions
armature_obj: Object = context.selected_objects[0]
Expand All @@ -272,23 +272,24 @@ def execute_operator(self, context: Context):
for action in actions:
stashActionInArmature(armature_obj, action)

actor_name = anim_export_props.actor_name
actor_name = export_props.actor_name

print("Reading table data")

table: SM64_AnimTable = table_props.to_table_class(
armature_obj,
sm64_props.blender_to_sm64_scale,
sm64_props.export_type == "C" or not anim_export_props.is_binary_dma,
sm64_props.export_type == "C" or not export_props.is_binary_dma,
export_props.quick_read,
actor_name,
)

print("Exporting table data")

if sm64_props.export_type == "C":
header_type = anim_export_props.header_type
header_type = export_props.header_type

anim_dir_path, dir_path, geo_dir_path, level_name = anim_export_props.get_animation_paths(
anim_dir_path, dir_path, geo_dir_path, level_name = export_props.get_animation_paths(
create_directories=True
)

Expand All @@ -300,7 +301,7 @@ def execute_operator(self, context: Context):
files_data = table.to_c_dma()
else:
files_data = table.data_and_headers_to_c(
anim_export_props.is_c_dma_structure,
export_props.is_c_dma_structure,
sm64_props.refresh_version,
)
for file_name, file_data in files_data.items():
Expand All @@ -310,12 +311,7 @@ def execute_operator(self, context: Context):
update_data_file(os.path.join(anim_dir_path, "data.inc.c"), [file_name])
else:
with open(os.path.join(anim_dir_path, "data.inc.c"), "w", newline="\n") as file:
file.write(
table.combined_data_and_headers_to_c(
anim_export_props.is_c_dma_structure,
sm64_props.refresh_version,
)
)
file.write(table.combined_data_and_headers_to_c(sm64_props.refresh_version))

if header_type != "DMA":
write_anim_header(
Expand All @@ -341,7 +337,7 @@ def execute_operator(self, context: Context):
if not header_type in {"Custom", "DMA"}:
update_includes(
level_name,
anim_export_props.group_name,
export_props.group_name,
toAlnum(actor_name),
dir_path,
header_type,
Expand Down Expand Up @@ -375,26 +371,26 @@ def execute_operator(self, context: Context):

scene = context.scene
sm64_props = scene.fast64.sm64
anim_export_props = sm64_props.anim_export
table_props = anim_export_props.table
export_props = sm64_props.anim_export
table_props = export_props.table

action = anim_export_props.selected_action
action = export_props.selected_action
action_props = action.fast64.sm64
armature_obj: Object = context.selected_objects[0]
stashActionInArmature(armature_obj, action)

actor_name = anim_export_props.actor_name
actor_name = export_props.actor_name
animation: SM64_Anim = action_props.to_animation_class(
action,
armature_obj,
sm64_props.blender_to_sm64_scale,
sm64_props.export_type == "C" or not anim_export_props.is_binary_dma,
sm64_props.export_type == "C" or not export_props.is_binary_dma,
actor_name,
)
if sm64_props.export_type == "C":
header_type = anim_export_props.header_type
header_type = export_props.header_type

anim_dir_path, dir_path, geo_dir_path, level_name = anim_export_props.get_animation_paths(
anim_dir_path, dir_path, geo_dir_path, level_name = export_props.get_animation_paths(
create_directories=True
)
anim_file_name = action_props.get_anim_file_name(action)
Expand All @@ -406,7 +402,7 @@ def execute_operator(self, context: Context):
with open(anim_path, "w", newline="\n") as file:
file.write(
animation.to_c(
anim_export_props.is_c_dma_structure,
export_props.is_c_dma_structure,
sm64_props.refresh_version,
)
)
Expand Down Expand Up @@ -435,15 +431,15 @@ def execute_operator(self, context: Context):
if not header_type in {"Custom", "DMA"}:
update_includes(
level_name,
anim_export_props.group_name,
export_props.group_name,
toAlnum(actor_name),
dir_path,
header_type,
table_props.update_table,
)
elif sm64_props.export_type == "Insertable Binary":
data, ptrs = animation.to_binary(anim_export_props.is_binary_dma, 0)
path = abspath(anim_export_props.insertable_path)
data, ptrs = animation.to_binary(export_props.is_binary_dma, 0)
path = abspath(export_props.insertable_path)
writeInsertableFile(path, 2, ptrs, 0, data)
else:
raise PluginError(f"Unimplemented export type ({sm64_props.export_type})")
Expand Down
23 changes: 17 additions & 6 deletions fast64_internal/sm64/animation/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,10 +415,11 @@ def to_data_class(
action: Action,
armature_obj: Object,
blender_to_sm64_scale: float,
quick_read: bool,
file_name: str = "anim_00.inc.c",
):
data = SM64_AnimData()
pairs = get_animation_pairs(blender_to_sm64_scale, action, armature_obj)
pairs = get_animation_pairs(blender_to_sm64_scale, 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 All @@ -433,6 +434,7 @@ def to_animation_class(
armature_obj: Object,
blender_to_sm64_scale: float,
can_use_references: bool,
quick_read: bool,
actor_name: str,
):
animation = SM64_Anim()
Expand All @@ -442,7 +444,9 @@ def to_animation_class(
values_reference = self.values_table
indice_reference = self.indices_table
else:
animation.data = self.to_data_class(action, armature_obj, blender_to_sm64_scale, animation.file_name)
animation.data = self.to_data_class(
action, armature_obj, blender_to_sm64_scale, quick_read, animation.file_name
)
values_reference = None
indice_reference = None
bone_count = len(get_anim_pose_bones(armature_obj))
Expand Down Expand Up @@ -777,7 +781,8 @@ def to_table_class(
armature_obj: Object,
blender_to_sm64_scale: float,
can_use_references: bool,
actor_name: str,
quick_read: bool,
actor_name: str = "mario",
):
table = SM64_AnimTable()
table.reference = self.get_anim_table_name(actor_name)
Expand All @@ -795,12 +800,14 @@ def to_table_class(
header_props: SM64_AnimHeaderProps = action_props.headers[element.header_variant]

if can_use_references and action_props.reference_tables:
values_reference = self.values_table
indice_reference = self.indices_table
values_reference = action_props.values_table
indice_reference = action_props.indices_table
data = None
else:
if not action in existing_data:
existing_data[action] = action_props.to_data_class(action, armature_obj, blender_to_sm64_scale)
existing_data[action] = action_props.to_data_class(
action, armature_obj, blender_to_sm64_scale, quick_read
)
data = existing_data[action]
values_reference = None
indice_reference = None
Expand Down Expand Up @@ -1005,6 +1012,7 @@ class SM64_AnimExportProps(PropertyGroup):

table: PointerProperty(type=SM64_AnimTableProps)

quick_read: BoolProperty(name="Quick read", default=True, description="May break constraint based rigs")
dma_folder: StringProperty(name="DMA Folder", default="assets/anims/")
use_dma_structure: BoolProperty(
name="Use DMA Structure",
Expand Down Expand Up @@ -1181,6 +1189,9 @@ def draw_props(self, layout: UILayout, export_type: str):
self.draw_binary_settings(col, export_type)
col.separator()

col.prop(self, "quick_read")
col.separator()

if not is_dma:
box = col.box().column()
box.prop(self.table, "update_table")
Expand Down

0 comments on commit 1991d81

Please sign in to comment.