Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions fast64_internal/f3d/f3d_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1825,17 +1825,6 @@ def exportF3DtoC(dirPath, obj, DLFormat, transformMatrix, texDir, savePNG, texSe

if DLFormat == DLFormat.Static:
staticData.append(dynamicData)
else:
geoString = writeMaterialFiles(
dirPath,
modelDirPath,
'#include "actors/' + toAlnum(name) + '/header.h"',
'#include "actors/' + toAlnum(name) + '/material.inc.h"',
dynamicData.header,
dynamicData.source,
"",
True,
)

if texSeparate:
texCFile = open(os.path.join(modelDirPath, "texture.inc.c"), "w", newline="\n")
Expand Down
44 changes: 19 additions & 25 deletions fast64_internal/sm64/animation/exporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
encodeSegmentedAddr,
decodeSegmentedAddr,
get64bitAlignedAddr,
getPathAndLevel,
getExportDir,
intToHex,
applyBasicTweaks,
toAlnum,
Expand All @@ -34,6 +32,7 @@
update_actor_includes,
int_from_str,
write_or_delete_if_found,
get_export_dirs,
)
from ..sm64_classes import BinaryExporter, RomReader, InsertableBinaryData
from ..sm64_level_parser import parseLevelAtPointer
Expand Down Expand Up @@ -433,6 +432,7 @@ def to_table_class(


def update_includes(
sm64_props: "SM64_Properties",
combined_props: "SM64_CombinedObjectProperties",
header_dir: Path,
actor_name,
Expand All @@ -444,6 +444,7 @@ def update_includes(
data_includes.append(Path("anims/table.inc.c"))
header_includes.append(Path("anim_header.h"))
update_actor_includes(
sm64_props,
combined_props.export_header_type,
combined_props.actor_group_name,
header_dir,
Expand Down Expand Up @@ -732,10 +733,11 @@ def export_animation_table_insertable(table: SM64_AnimTable, is_dma: bool, direc

def create_and_get_paths(
anim_props: "SM64_ArmatureAnimProperties",
sm64_props: "SM64_Properties",
combined_props: "SM64_CombinedObjectProperties",
actor_name: str,
decomp: Path,
):
decomp = sm64_props.abs_decomp_path
anim_directory = geo_directory = header_directory = None
if anim_props.is_dma:
if combined_props.export_header_type == "Custom":
Expand All @@ -744,13 +746,9 @@ def create_and_get_paths(
else:
anim_directory = Path(decomp, anim_props.dma_folder)
else:
export_path, level_name = getPathAndLevel(
combined_props.is_actor_custom_export,
combined_props.actor_custom_path,
combined_props.export_level_name,
combined_props.level_name,
)
header_directory, _tex_dir = getExportDir(
export_path, level_name = combined_props.get_path_and_level(sm64_props)
header_directory, _tex_dir = get_export_dirs(
sm64_props,
combined_props.is_actor_custom_export,
export_path,
combined_props.export_header_type,
Expand All @@ -770,16 +768,16 @@ def create_and_get_paths(

def export_animation_table_c(
anim_props: "SM64_ArmatureAnimProperties",
sm64_props: "SM64_Properties",
combined_props: "SM64_CombinedObjectProperties",
table: SM64_AnimTable,
decomp: Path,
actor_name: str,
designated: bool,
):
designated = sm64_props.designated
if not combined_props.is_actor_custom_export:
applyBasicTweaks(decomp)
applyBasicTweaks(sm64_props.abs_decomp_path)
anim_directory, geo_directory, header_directory = create_and_get_paths(
anim_props, combined_props, actor_name, decomp
anim_props, sm64_props, combined_props, actor_name
)

print("Creating all animation C data")
Expand Down Expand Up @@ -815,7 +813,7 @@ def export_animation_table_c(
enum_list_path=anim_directory / "table_enum.h",
override_files=anim_props.override_files,
)
update_includes(combined_props, header_directory, actor_name, True)
update_includes(sm64_props, combined_props, header_directory, actor_name, True)


def export_animation_binary(
Expand Down Expand Up @@ -889,15 +887,15 @@ def export_animation_insertable(animation: SM64_Anim, is_dma: bool, directory: P
def export_animation_c(
animation: SM64_Anim,
anim_props: "SM64_ArmatureAnimProperties",
sm64_props: "SM64_Properties",
combined_props: "SM64_CombinedObjectProperties",
decomp: Path,
actor_name: str,
designated: bool,
):
designated = sm64_props.designated
if not combined_props.is_actor_custom_export:
applyBasicTweaks(decomp)
applyBasicTweaks(sm64_props.abs_decomp_path)
anim_directory, geo_directory, header_directory = create_and_get_paths(
anim_props, combined_props, actor_name, decomp
anim_props, sm64_props, combined_props, actor_name
)

(anim_directory / animation.file_name).write_text(animation.to_c(anim_props.is_dma))
Expand Down Expand Up @@ -956,9 +954,7 @@ def export_animation(context: Context, obj: Object):
except Exception as exc:
raise PluginError(f"Failed to generate animation class. {exc}") from exc
if sm64_props.export_type == "C":
export_animation_c(
animation, anim_props, combined_props, sm64_props.abs_decomp_path, actor_name, sm64_props.designated
)
export_animation_c(animation, anim_props, sm64_props, combined_props, actor_name)
elif sm64_props.export_type == "Insertable Binary":
export_animation_insertable(animation, anim_props.is_dma, Path(abspath(combined_props.insertable_directory)))
elif sm64_props.export_type == "Binary":
Expand Down Expand Up @@ -1011,9 +1007,7 @@ def export_animation_table(context: Context, obj: Object):

print("Exporting table data")
if sm64_props.export_type == "C":
export_animation_table_c(
anim_props, combined_props, table, sm64_props.abs_decomp_path, actor_name, sm64_props.designated
)
export_animation_table_c(anim_props, sm64_props, combined_props, table, actor_name)
elif sm64_props.export_type == "Insertable Binary":
export_animation_table_insertable(table, anim_props.is_dma, Path(abspath(combined_props.insertable_directory)))
elif sm64_props.export_type == "Binary":
Expand Down
13 changes: 11 additions & 2 deletions fast64_internal/sm64/animation/importing.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,9 +784,18 @@ def update_table_preset(import_props: "SM64_AnimImportProperties", context):
# If the previously selected animation isn't in this preset, select animation 0
import_props.preset_animation = "0"

sm64_props: SM64_Properties = context.scene.fast64.sm64
# C
decomp_path = import_props.decomp_path if import_props.decomp_path else context.scene.fast64.sm64.decomp_path
directory = preset.animation.directory if preset.animation.directory else f"{preset.decomp_path}/anims"
decomp_path = import_props.decomp_path if import_props.decomp_path else sm64_props.decomp_path
if preset.animation.dma:
directory = Path(sm64_props.vanilla_dma_anims_folder)
else:
if preset.typ == "ACTOR":
directory = Path(sm64_props.vanilla_actors_folder, preset.folder)
elif preset.typ == "LEVEL":
directory = Path(sm64_props.vanilla_levels_folder, preset.folder)
else:
raise ValueError(f"Unknown preset type {preset.typ}")
import_props.path = os.path.join(decomp_path, directory)

# Binary
Expand Down
43 changes: 43 additions & 0 deletions fast64_internal/sm64/settings/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
from ...utility import (
directory_path_checks,
directory_ui_warnings,
draw_directory,
prop_split,
set_prop_if_in_data,
upgrade_old_prop,
get_first_set_prop,
draw_and_check_tab,
)
from ..sm64_constants import defaultExtendSegment4, OLD_BINARY_LEVEL_ENUMS
from ..sm64_objects import SM64_CombinedObjectProperties
Expand Down Expand Up @@ -113,6 +115,16 @@ class SM64_Properties(PropertyGroup):
description="Extremely recommended but must be off when compiling with IDO. Included in Repo Setting file",
)

folders_tab: BoolProperty(default=True, name="Export Folders")
actors_folder: StringProperty(name="Actors Folder", default="actors")
levels_folder: StringProperty(name="Levels Folder", default="levels")
dma_anims_folder: StringProperty(name="DMA Animations Folder", default="assets/anims")

vanilla_folders_tab: BoolProperty(default=True, name="Vanilla Folders")
vanilla_actors_folder: StringProperty(name="Vanilla Actors Folder", default="actors")
vanilla_levels_folder: StringProperty(name="Vanilla Levels Folder", default="levels")
vanilla_dma_anims_folder: StringProperty(name="Vanilla DMA Animations Folder", default="assets/anims")

@property
def binary_export(self):
return self.export_type in {"Binary", "Insertable Binary"}
Expand Down Expand Up @@ -207,6 +219,14 @@ def to_repo_settings(self):
data["write_all"] = self.write_all
if not self.hackersm64:
data["designated"] = self.designated_prop
folders = {}
for is_vanilla in (False, True):
prefix = "vanilla_" if is_vanilla else ""
sub_categories = {}
for name in ("actors", "levels", "dma_anims"):
sub_categories[name] = getattr(self, f"{prefix}{name}_folder")
folders["vanilla" if is_vanilla else "export"] = sub_categories
data["folders"] = folders
if self.custom_cmds:
data["custom_cmds"] = [preset.to_dict("PRESET_EDIT") for preset in self.custom_cmds]
return data
Expand All @@ -219,6 +239,12 @@ def from_repo_settings(self, data: dict):
set_prop_if_in_data(self, "lighting_engine_presets", data, "lighting_engine_presets")
set_prop_if_in_data(self, "write_all", data, "write_all")
set_prop_if_in_data(self, "designated_prop", data, "designated")
folders = data.get("folders", {})
for is_vanilla in (False, True):
sub_categories = folders.get("vanilla" if is_vanilla else "export", {})
prefix = "vanilla_" if is_vanilla else ""
for name in ("actors", "levels", "dma_anims"):
set_prop_if_in_data(self, f"{prefix}{name}_folder", sub_categories, name)
if "custom_cmds" in data:
self.custom_cmds.clear()
for preset_data in data.get("custom_cmds", []):
Expand All @@ -236,6 +262,23 @@ def draw_repo_settings(self, layout: UILayout):
if self.matstack_fix:
col.prop(self, "lighting_engine_presets")
col.prop(self, "write_all")
for vanilla in (False, True):
prefix = "vanilla_" if vanilla else ""
if draw_and_check_tab(col, self, f"{prefix}folders_tab"):
name_prefix = "Vanilla" if vanilla else ""
draw_directory(
col, self, f"{prefix}actors_folder", name=f"{name_prefix} Actors", base_dir=self.abs_decomp_path
)
draw_directory(
col, self, f"{prefix}levels_folder", name=f"{name_prefix} Levels", base_dir=self.abs_decomp_path
)
draw_directory(
col,
self,
f"{prefix}dma_anims_folder",
name=f"{name_prefix} DMA Anims",
base_dir=self.abs_decomp_path,
)
draw_custom_cmd_presets(self, col.box())

def draw_props(self, layout: UILayout, show_repo_settings: bool = True):
Expand Down
44 changes: 29 additions & 15 deletions fast64_internal/sm64/sm64_collision.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
from pathlib import Path
import bpy, shutil, os, math, mathutils
from bpy.utils import register_class, unregister_class
from io import BytesIO
import shutil
import os
import math
import typing

import bpy
import mathutils
from bpy.utils import register_class, unregister_class

from .sm64_constants import insertableBinaryTypes, defaultExtendSegment4
from .sm64_utility import export_rom_checks, to_include_descriptor, update_actor_includes, write_or_delete_if_found
from .sm64_utility import (
export_rom_checks,
to_include_descriptor,
update_actor_includes,
write_or_delete_if_found,
get_export_dirs,
)
from .sm64_objects import SM64_Area, start_process_sm64_objects
from .sm64_level_parser import parse_level_binary
from .sm64_rom_tweaks import ExtendBank0x04
Expand All @@ -17,19 +30,20 @@
encodeSegmentedAddr,
get64bitAlignedAddr,
prop_split,
getExportDir,
duplicateHierarchy,
cleanupDuplicatedObjects,
writeInsertableFile,
applyRotation,
getPathAndLevel,
applyBasicTweaks,
tempName,
bytesToHex,
applyRotation,
selectSingleObject,
)

if typing.TYPE_CHECKING:
from .settings.properties import SM64_Properties


class CollisionVertex:
def __init__(self, position):
Expand Down Expand Up @@ -278,6 +292,7 @@ def exportCollisionBinary(obj, transformMatrix, romfile, startAddress, endAddres


def exportCollisionC(
sm64_props: "SM64_Properties",
obj,
transformMatrix,
dirPath,
Expand All @@ -290,7 +305,7 @@ def exportCollisionC(
groupName,
levelName,
):
dirPath, texDir = getExportDir(customExport, dirPath, headerType, levelName, "", name)
dirPath, texDir = get_export_dirs(sm64_props, customExport, dirPath, headerType, levelName, "", name)

name = toAlnum(name)
colDirPath = os.path.join(dirPath, toAlnum(name))
Expand Down Expand Up @@ -324,7 +339,7 @@ def exportCollisionC(
if writeRoomsFile:
data_includes.append(Path("rooms.inc.c"))
update_actor_includes(
headerType, groupName, Path(dirPath), name, levelName, data_includes, [Path("collision_header.h")]
sm64_props, headerType, groupName, Path(dirPath), name, levelName, data_includes, [Path("collision_header.h")]
)
if not writeRoomsFile: # TODO: Could be done better
if headerType == "Actor":
Expand All @@ -335,7 +350,9 @@ def exportCollisionC(
write_or_delete_if_found(
group_path_c,
to_remove=[
to_include_descriptor(Path(name, "rooms.inc.c"), Path("levels", levelName, name, "rooms.inc.c")),
to_include_descriptor(
Path(name, "rooms.inc.c"), Path(sm64_props.levels_folder, levelName, name, "rooms.inc.c")
),
],
)

Expand Down Expand Up @@ -461,7 +478,8 @@ class SM64_ExportCollision(bpy.types.Operator):
def execute(self, context):
romfileOutput = None
tempROM = None
props = context.scene.fast64.sm64.combined_export
sm64_props: SM64_Properties = context.scene.fast64.sm64
props = sm64_props.combined_export
try:
obj = None
if context.mode != "OBJECT":
Expand All @@ -479,15 +497,11 @@ def execute(self, context):
try:
applyRotation([obj], math.radians(90), "X")
if context.scene.fast64.sm64.export_type == "C":
export_path, level_name = getPathAndLevel(
props.is_actor_custom_export,
props.actor_custom_path,
props.export_level_name,
props.level_name,
)
export_path, level_name = props.get_path_and_level(sm64_props)
if not props.is_actor_custom_export:
applyBasicTweaks(export_path)
exportCollisionC(
sm64_props,
obj,
final_transform,
export_path,
Expand Down
Loading