Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OOT] Applied new organisation to remaining code from oot_anim.py #237

Merged
merged 5 commits into from
Jan 28, 2024
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
4 changes: 4 additions & 0 deletions fast64_internal/oot/animation/exporter/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .functions import (
ootExportLinkAnimation,
ootExportNonLinkAnimation,
)
116 changes: 116 additions & 0 deletions fast64_internal/oot/animation/exporter/classes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
from ....utility import CData, toAlnum


def convertToUnsignedShort(value: int) -> int:
return int.from_bytes(value.to_bytes(2, "big", signed=(value < 0)), "big", signed=False)


class OOTAnimation:
def __init__(self, name):
self.name = toAlnum(name)
self.segmentID = None
self.indices = {}
self.values = []
self.frameCount = None
self.limit = None

def valuesName(self):
return self.name + "FrameData"

def indicesName(self):
return self.name + "JointIndices"

def toC(self):
data = CData()
data.source += '#include "ultra64.h"\n#include "global.h"\n\n'

# values
data.source += "s16 " + self.valuesName() + "[" + str(len(self.values)) + "] = {\n"
counter = 0
for value in self.values:
if counter == 0:
data.source += "\t"
data.source += format(convertToUnsignedShort(value), "#06x") + ", "
counter += 1
if counter >= 16: # round number for finding/counting data
counter = 0
data.source += "\n"
data.source += "};\n\n"

# indices (index -1 => translation)
data.source += "JointIndex " + self.indicesName() + "[" + str(len(self.indices)) + "] = {\n"
for index in range(-1, len(self.indices) - 1):
data.source += "\t{ "
for field in range(3):
data.source += (
format(
convertToUnsignedShort(self.indices[index][field]),
"#06x",
)
+ ", "
)
data.source += "},\n"
data.source += "};\n\n"

# header
data.header += "extern AnimationHeader " + self.name + ";\n"
data.source += (
"AnimationHeader "
+ self.name
+ " = { { "
+ str(self.frameCount)
+ " }, "
+ self.valuesName()
+ ", "
+ self.indicesName()
+ ", "
+ str(self.limit)
+ " };\n\n"
)

return data


class OOTLinkAnimation:
def __init__(self, name):
self.headerName = toAlnum(name)
self.frameCount = None
self.data = []

def dataName(self):
return self.headerName + "Data"

def toC(self, isCustomExport: bool):
data = CData()
animHeaderData = CData()

data.source += '#include "ultra64.h"\n#include "global.h"\n\n'
animHeaderData.source += '#include "ultra64.h"\n#include "global.h"\n\n'

# TODO: handle custom import?
if isCustomExport:
animHeaderData.source += f'#include "{self.dataName()}.h"\n'
else:
animHeaderData.source += f'#include "assets/misc/link_animetion/{self.dataName()}.h"\n'

# data
data.header += f"extern s16 {self.dataName()}[];\n"
data.source += f"s16 {self.dataName()}[] = {{\n"
counter = 0
for value in self.data:
if counter == 0:
data.source += "\t"
data.source += format(convertToUnsignedShort(value), "#06x") + ", "
counter += 1
if counter >= 8: # round number for finding/counting data
counter = 0
data.source += "\n"
data.source += "\n};\n\n"

# header
animHeaderData.header += f"extern LinkAnimationHeader {self.headerName};\n"
animHeaderData.source += (
f"LinkAnimationHeader {self.headerName} = {{\n\t{{ {str(self.frameCount)} }}, {self.dataName()} \n}};\n\n"
)

return data, animHeaderData
Loading
Loading