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

[SM64] Fix SM64 binary geolayout exports #423

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
19 changes: 12 additions & 7 deletions fast64_internal/f3d/f3d_gbi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2951,14 +2951,17 @@ def get_ptr_addresses(self, f3d):
return self.triList.get_ptr_addresses(f3d)

def set_addr(self, startAddress, f3d):
addrRange = self.triList.set_addr(startAddress, f3d)
addrRange = (startAddress, startAddress)
if self.triList.tag.Export:
addrRange = self.triList.set_addr(startAddress, f3d)
addrRange = self.vertexList.set_addr(addrRange[1])
return startAddress, addrRange[1]

def save_binary(self, romfile, f3d, segments):
for celTriList in self.celTriLists:
celTriList.save_binary(romfile, f3d, segments)
self.triList.save_binary(romfile, f3d, segments)
if self.triList.tag.Export:
self.triList.save_binary(romfile, f3d, segments)
self.vertexList.save_binary(romfile)

def to_c(self, f3d, gfxFormatter):
Expand Down Expand Up @@ -3065,15 +3068,17 @@ def get_ptr_addresses(self, f3d):
return addresses

def set_addr(self, startAddress, f3d):
addrRange = self.material.set_addr(startAddress, f3d)
startAddress = addrRange[0]
if self.revert is not None:
addrRange = (startAddress, startAddress)
if self.material.tag.Export:
addrRange = self.material.set_addr(addrRange[1], f3d)
if self.revert is not None and self.revert.tag.Export:
addrRange = self.revert.set_addr(addrRange[1], f3d)
return startAddress, addrRange[1]

def save_binary(self, romfile, f3d, segments):
self.material.save_binary(romfile, f3d, segments)
if self.revert is not None:
if self.material.tag.Export:
self.material.save_binary(romfile, f3d, segments)
if self.revert is not None and self.revert.tag.Export:
self.revert.save_binary(romfile, f3d, segments)

def to_c(self, f3d):
Expand Down
19 changes: 10 additions & 9 deletions fast64_internal/sm64/sm64_geolayout_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,9 @@ class BaseDisplayListNode:
bleed_independently = False # base behavior, can be changed with obj boolProp

def get_dl_address(self):
if self.hasDL and (self.dlRef or self.DLmicrocode is not None):
return self.dlRef or self.DLmicrocode.startAddress
assert self.dlRef is None, "dlRef not implemented in binary"
if self.hasDL and self.DLmicrocode is not None:
return self.DLmicrocode.startAddress
return None

def get_dl_name(self):
Expand Down Expand Up @@ -352,8 +353,8 @@ def size(self):
size = self.node.size() if self.node is not None else 0
if len(self.children) > 0 and type(self.node) in nodeGroupClasses:
size += 8 # node open/close
for child in self.children:
size += child.size()
for child in self.children:
size += child.size()

return size

Expand All @@ -368,11 +369,11 @@ def to_binary(self, segmentData):
if type(self.node) is FunctionNode:
raise PluginError("An FunctionNode cannot have children.")

if data[0] in nodeGroupCmds:
if type(self.node) in nodeGroupClasses:
data.extend(bytearray([GEO_NODE_OPEN, 0x00, 0x00, 0x00]))
for child in self.children:
data.extend(child.to_binary(segmentData))
if data[0] in nodeGroupCmds:
if type(self.node) in nodeGroupClasses:
data.extend(bytearray([GEO_NODE_CLOSE, 0x00, 0x00, 0x00]))
elif type(self.node) is SwitchNode:
raise PluginError("A switch bone must have at least one child bone.")
Expand Down Expand Up @@ -411,11 +412,11 @@ def toTextDump(self, nodeLevel, segmentData):
data += "\n"

if len(self.children) > 0:
if len(command) == 0 or command[0] in nodeGroupCmds:
if type(self.node) in nodeGroupClasses:
data += "\t" * nodeLevel + "04 00 00 00\n"
for child in self.children:
data += child.toTextDump(nodeLevel + 1, segmentData)
if len(command) == 0 or command[0] in nodeGroupCmds:
data += child.toTextDump(nodeLevel + (1 if type(self.node) in nodeGroupClasses else 0), segmentData)
if type(self.node) in nodeGroupClasses:
data += "\t" * nodeLevel + "05 00 00 00\n"
elif type(self.node) is SwitchNode:
raise PluginError("A switch bone must have at least one child bone.")
Expand Down
6 changes: 4 additions & 2 deletions fast64_internal/sm64/sm64_geolayout_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1536,7 +1536,8 @@ def processMesh(

if len(src_meshes):
fMeshes = {}
node.dlRef = src_meshes[0]["name"]
if useGeoEmpty:
node.dlRef = src_meshes[0]["name"]
node.drawLayer = src_meshes[0]["layer"]
processed_inline_geo = True

Expand All @@ -1561,7 +1562,8 @@ def processMesh(
temp_obj["src_meshes"] = [
({"name": fMesh.draw.name, "layer": drawLayer}) for drawLayer, fMesh in fMeshes.items()
]
node.dlRef = temp_obj["src_meshes"][0]["name"]
if useGeoEmpty:
node.dlRef = temp_obj["src_meshes"][0]["name"]
else:
# TODO: Display warning to the user that there is an object that doesn't have polygons
print("Object", obj.original_name, "does not have any polygons.")
Expand Down
Loading