Skip to content

Commit

Permalink
[SM64] Fix SM64 binary geolayout exports (#423)
Browse files Browse the repository at this point in the history
* First pass

There seems to be something wrong with reverts still, will investigate

* currently hasn´t caused a bug but update this to be sure

* another similar issue
  • Loading branch information
Lilaa3 authored Jan 1, 2025
1 parent dac0a8f commit 98520f1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
19 changes: 12 additions & 7 deletions fast64_internal/f3d/f3d_gbi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2969,14 +2969,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 @@ -3083,15 +3086,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 @@ -1534,7 +1534,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 @@ -1559,7 +1560,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

0 comments on commit 98520f1

Please # to comment.