Skip to content
Merged
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
39 changes: 31 additions & 8 deletions fast64_internal/z64/animation/operators.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import mathutils, bpy, os
from pathlib import Path
from bpy.types import Scene, Operator, Armature
from bpy.props import StringProperty, BoolProperty
from bpy.utils import register_class, unregister_class
Expand All @@ -11,23 +12,30 @@
from ..utility import (
ootGetPath,
addIncludeFiles,
addIncludeFilesExtension,
checkEmptyName,
ootGetObjectPath,
getOOTScale,
add_include_to_spec_segment,
)


def exportAnimationC(armatureObj: bpy.types.Object, settings: OOTAnimExportSettingsProperty):
if settings.isCustom:
checkEmptyName(settings.customPath)
else:
elif not settings.isLink:
checkEmptyName(settings.folderName)

if settings.isCustomFilename:
checkEmptyName(settings.filename)

path = bpy.path.abspath(settings.customPath)
exportPath = ootGetObjectPath(settings.isCustom, path, settings.folderName, False)
if settings.isCustom:
exportPath = path
elif not settings.isLink:
exportPath = ootGetObjectPath(settings.isCustom, path, settings.folderName, False)
else:
exportPath = None # Won't be used as the export is not custom

checkEmptyName(armatureObj.name)
name = toAlnum(armatureObj.name)
Expand All @@ -40,20 +48,21 @@ def exportAnimationC(armatureObj: bpy.types.Object, settings: OOTAnimExportSetti
if settings.isLink:
ootAnim = ootExportLinkAnimation(armatureObj, convertTransformMatrix, name)
ootAnimC, ootAnimHeaderC = ootAnim.toC(settings.isCustom)

path = ootGetPath(
exportPath,
settings.isCustom,
"assets/misc/link_animetion",
settings.folderName if settings.isCustom else "",
False,
"",
True,
False,
)
headerPath = ootGetPath(
exportPath,
settings.isCustom,
"assets/objects/gameplay_keep",
settings.folderName if settings.isCustom else "",
False,
"",
True,
False,
)
writeCData(
Expand All @@ -66,8 +75,22 @@ def exportAnimationC(armatureObj: bpy.types.Object, settings: OOTAnimExportSetti
)

if not settings.isCustom:
addIncludeFiles("link_animetion", path, ootAnim.dataName())
addIncludeFiles("gameplay_keep", headerPath, ootAnim.headerName)
if (Path(bpy.context.scene.ootDecompPath) / "assets/objects/gameplay_keep/gameplay_keep.c").exists():
# Pre "new" assets system
addIncludeFiles("link_animetion", path, ootAnim.dataName())
addIncludeFiles("gameplay_keep", headerPath, ootAnim.headerName)
else:
add_include_to_spec_segment(
Path(bpy.context.scene.ootDecompPath) / "spec/spec",
"link_animetion",
f"$(BUILD_DIR)/assets/misc/link_animetion/{ootAnim.dataName()}.o",
)
add_include_to_spec_segment(
Path(bpy.context.scene.ootDecompPath) / "spec/spec",
"gameplay_keep",
f"$(BUILD_DIR)/assets/objects/gameplay_keep/{ootAnim.headerName}.o",
)
addIncludeFilesExtension("gameplay_keep", headerPath, ootAnim.headerName, "h")

else:
ootAnim = ootExportNonLinkAnimation(armatureObj, convertTransformMatrix, name, filename)
Expand Down
7 changes: 4 additions & 3 deletions fast64_internal/z64/animation/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ class OOTAnimExportSettingsProperty(PropertyGroup):

def draw_props(self, layout: UILayout):
layout.label(text="Exports active animation on selected object.", icon="INFO")
layout.prop(self, "isCustomFilename")
if self.isCustomFilename:
prop_split(layout, self, "filename", "Filename")
if not self.isLink:
layout.prop(self, "isCustomFilename")
if self.isCustomFilename:
prop_split(layout, self, "filename", "Filename")
if self.isCustom:
prop_split(layout, self, "customPath", "Folder")
elif not self.isLink:
Expand Down
12 changes: 6 additions & 6 deletions fast64_internal/z64/exporter/animation/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,16 @@ def toC(self, isCustomExport: bool):
animHeaderData.header = f"#ifndef {self.headerName.upper()}_H\n" + f"#define {self.headerName.upper()}_H\n\n"

if bpy.context.scene.fast64.oot.is_globalh_present():
data.header = '#include "ultra64.h"\n' + '#include "global.h"\n\n'
animHeaderData.header = '#include "ultra64.h"\n' + '#include "global.h"\n\n'
data.header += '#include "ultra64.h"\n' + '#include "global.h"\n\n'
animHeaderData.header += '#include "ultra64.h"\n' + '#include "global.h"\n\n'
elif bpy.context.scene.fast64.oot.is_z64sceneh_present():
data.header = '#include "ultra64.h"\n' + '#include "array_count.h"\n' + '#include "z64animation.h"\n\n'
animHeaderData.header = (
data.header += '#include "ultra64.h"\n' + '#include "array_count.h"\n' + '#include "z64animation.h"\n\n'
animHeaderData.header += (
'#include "ultra64.h"\n' + '#include "array_count.h"\n' + '#include "z64animation.h"\n\n'
)
else:
data.header = '#include "ultra64.h"\n' + '#include "array_count.h"\n' + '#include "animation.h"\n\n'
animHeaderData.header = (
data.header += '#include "ultra64.h"\n' + '#include "array_count.h"\n' + '#include "animation.h"\n\n'
animHeaderData.header += (
'#include "ultra64.h"\n' + '#include "array_count.h"\n' + '#include "animation.h"\n\n'
)

Expand Down
26 changes: 26 additions & 0 deletions fast64_internal/z64/utility.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import bpy
import math
import os
from pathlib import Path
import re
import traceback

Expand Down Expand Up @@ -1031,3 +1032,28 @@ def is_oot_features():

def is_hackeroot():
return game_data.z64.is_oot() and bpy.context.scene.fast64.oot.feature_set == "hackeroot"


def add_include_to_spec_segment(spec_p: Path, segment: str, inc: str):
spec_content = spec_p.read_text()
new_spec_lines = []
in_segment = False
in_target_segment = False
found_existing_include = False
include_line_to_add = f' include "{inc}"\n'
for l in spec_content.splitlines(keepends=True):
if l.strip() == "beginseg":
in_segment = True
if l.strip() == "endseg":
if in_target_segment and not found_existing_include:
new_spec_lines.append(include_line_to_add)
in_segment = False
in_target_segment = False
if in_segment and l.split() == f'name "{segment}"'.split():
in_target_segment = True
if in_target_segment and l.split() == include_line_to_add.split():
found_existing_include = True
new_spec_lines.append(l)
new_spec_content = "".join(new_spec_lines)
if new_spec_content != spec_content:
spec_p.write_text(new_spec_content)