Skip to content

Commit 19253fc

Browse files
committed
Merge branch 'main' of https://github.com/Fast-64/fast64
2 parents 881a18e + ab1c074 commit 19253fc

5 files changed

Lines changed: 53 additions & 30 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
> [!IMPORTANT]
44
> This is the updated version of HM's fork of Fast64, the old version of HM's fork is [here](https://github.com/HarbourMasters/fast64/tree/legacy)
55
6-
This requires Blender 3.2 - 5.0.1. Blender 4.0+ is recommended.
6+
This requires Blender 3.2 - 5.1.2. Blender 4.0+ is recommended.
77

88
Forked from [kurethedead/fast64 on BitBucket](https://bitbucket.org/kurethedead/fast64/src).
99

fast64_internal/f3d/f3d_parser.py

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -371,13 +371,16 @@ def math_eval(s, f3d):
371371
def _eval(node):
372372
if isinstance(node, ast.Expression):
373373
return _eval(node.body)
374-
elif isinstance(node, ast.Str):
375-
return node.s
374+
elif isinstance(node, ast.Constant):
375+
if isinstance(node.value, str):
376+
return node.value
377+
elif isinstance(node.value, int):
378+
return int(node.value)
379+
else:
380+
raise Exception("Unsupported constant type {}".format(type(node.value)))
376381
elif isinstance(node, ast.Name):
377382
if hasattr(f3d, node.id):
378383
return getattr(f3d, node.id)
379-
elif isinstance(node, ast.Num):
380-
return node.n
381384
elif isinstance(node, ast.UnaryOp):
382385
if isinstance(node.op, ast.USub):
383386
return -1 * _eval(node.operand)
@@ -1861,7 +1864,7 @@ def deleteMaterialContext(self):
18611864
raise PluginError("Attempting to delete material context that is None.")
18621865

18631866
# if deleteMaterialContext is False, then manually call self.deleteMaterialContext() later.
1864-
def createMesh(self, obj, removeDoubles, importNormals, callDeleteMaterialContext: bool):
1867+
def createMesh(self, obj: bpy.types.Object, removeDoubles, importNormals, callDeleteMaterialContext: bool):
18651868
mesh = obj.data
18661869
if len(self.verts) % 3 != 0:
18671870
print(len(self.verts))
@@ -1899,13 +1902,26 @@ def createMesh(self, obj, removeDoubles, importNormals, callDeleteMaterialContex
18991902
# There will be one loop for every vertex
19001903
uv_layer[i].uv = self.verts[i].uv
19011904

1902-
color_layer = mesh.vertex_colors.new(name="Col").data
1903-
for i in range(len(mesh.loops)):
1904-
color_layer[i].color = self.verts[i].rgb.to_4d()
1905-
1906-
alpha_layer = mesh.vertex_colors.new(name="Alpha").data
1907-
for i in range(len(mesh.loops)):
1908-
alpha_layer[i].color = [self.verts[i].alpha] * 3 + [1]
1905+
# The mesh.vertex_colors API is deprecated since Blender 3.2,
1906+
# and its usage by fast64 here breaks in Blender 5.1 somehow.
1907+
# (can't replicate in simple cases)
1908+
if bpy.app.version < (3, 2, 0):
1909+
color_layer = mesh.vertex_colors.new(name="Col").data
1910+
for i in range(len(mesh.loops)):
1911+
color_layer[i].color = self.verts[i].rgb.to_4d()
1912+
1913+
alpha_layer = mesh.vertex_colors.new(name="Alpha").data
1914+
for i in range(len(mesh.loops)):
1915+
alpha_layer[i].color = [self.verts[i].alpha] * 3 + [1]
1916+
else:
1917+
col_attr = mesh.color_attributes.new("Col", "BYTE_COLOR", "CORNER")
1918+
for i in range(len(mesh.loops)):
1919+
col_attr.data[i].color = (*self.verts[i].rgb, 1)
1920+
1921+
alpha_attr = mesh.color_attributes.new("Alpha", "BYTE_COLOR", "CORNER")
1922+
for i in range(len(mesh.loops)):
1923+
a = self.verts[i].alpha
1924+
alpha_attr.data[i].color = (a, a, a, 1)
19091925

19101926
if bpy.context.mode != "OBJECT":
19111927
bpy.ops.object.mode_set(mode="OBJECT")

fast64_internal/sm64/animation/classes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def read_binary(self, indices_reader: RomReader, values_reader: RomReader, bone_
115115
indices_values = np.frombuffer(indices_reader.read_data(indices_size), dtype=">u2")
116116
for i in range(0, len(indices_values), 2):
117117
max_frame, offset = indices_values[i], indices_values[i + 1]
118-
address, size = values_reader.start_address + (offset * 2), max_frame * 2
118+
address, size = values_reader.start_address + int(offset * 2), int(max_frame) * 2
119119

120120
values = np.frombuffer(values_reader.read_data(size, address), dtype=">i2", count=max_frame)
121121
self.pairs.append(SM64_AnimPair(values, address, address + size, offset).clean_frames())

fast64_internal/sm64/sm64_level_writer.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -543,16 +543,19 @@ def add_act_selector_ignore(base_path, level_enum):
543543
file_path = os.path.join(base_path, "src/game/level_update.c")
544544
data = getDataFromFile(file_path)
545545

546-
function_start = re.search("s32\s*lvl\_set\_current\_level\s*\((((?!\)).)*)\)\s*\{", data, re.DOTALL)
547-
548-
if function_start is None:
546+
try:
547+
function_start = re.search("s32\s*lvl\_set\_current\_level\s*\((((?!\)).)*)\)\s*\{", data, re.DOTALL).end()
548+
except:
549549
raise PluginError('Could not find lvl_set_current_level in "' + file_path + '".')
550550

551-
function_end = re.search("\s*return\s*\!gDebugLevelSelect;\s*", data, re.DOTALL)
552-
if function_end is None:
553-
raise PluginError('Could not find return in lvl_set_current_level in "' + file_path + '".')
551+
try:
552+
function_end = (
553+
re.search("\s*return\s*(?:(?!(0|FALSE)).)*?;", data[function_start:], re.DOTALL).start() + function_start
554+
)
555+
except:
556+
raise PluginError('Could not find final return in lvl_set_current_level in "' + file_path + '".')
554557

555-
function_contents = data[function_start.end() : function_end.start()]
558+
function_contents = data[function_start:function_end]
556559

557560
check_result = re.search(
558561
"if\s*\(gCurrLevelNum\s*==\s*" + level_enum + "\)\s*return\s*0;", function_contents, re.DOTALL
@@ -562,7 +565,7 @@ def add_act_selector_ignore(base_path, level_enum):
562565

563566
function_contents += "\n\tif (gCurrLevelNum == " + level_enum + ") return 0;"
564567

565-
new_data = data[: function_start.end()] + function_contents + data[function_end.start() :]
568+
new_data = data[:function_start] + function_contents + data[function_end:]
566569

567570
saveDataToFile(file_path, new_data)
568571

@@ -571,23 +574,26 @@ def remove_act_selector_ignore(base_path, level_enum):
571574
file_path = os.path.join(base_path, "src/game/level_update.c")
572575
data = getDataFromFile(file_path)
573576

574-
function_start = re.search("s32\s*lvl\_set\_current\_level\s*\((((?!\)).)*)\)\s*\{", data, re.DOTALL)
575-
576-
if function_start is None:
577+
try:
578+
function_start = re.search("s32\s*lvl\_set\_current\_level\s*\((((?!\)).)*)\)\s*\{", data, re.DOTALL).end()
579+
except:
577580
raise PluginError('Could not find lvl_set_current_level in "' + file_path + '".')
578581

579-
function_end = re.search("\s*return\s*\!gDebugLevelSelect;\s*", data, re.DOTALL)
580-
if function_end is None:
581-
raise PluginError('Could not find return in lvl_set_current_level in "' + file_path + '".')
582+
try:
583+
function_end = (
584+
re.search("\s*return\s*(?:(?!(0|FALSE)).)*?;", data[function_start:], re.DOTALL).start() + function_start
585+
)
586+
except:
587+
raise PluginError('Could not find final return in lvl_set_current_level in "' + file_path + '".')
582588

583-
function_contents = data[function_start.end() : function_end.start()]
589+
function_contents = data[function_start:function_end]
584590

585591
new_function_contents = re.sub(
586592
"\s*?if\s*\(gCurrLevelNum\s*==\s*" + level_enum + "\)\s*return\s*0;", "", function_contents, re.DOTALL
587593
)
588594

589595
if function_contents != new_function_contents:
590-
new_data = data[: function_start.end()] + new_function_contents + data[function_end.start() :]
596+
new_data = data[:function_start] + new_function_contents + data[function_end:]
591597
saveDataToFile(file_path, new_data)
592598

593599

fast64_internal/utility.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,6 +1510,7 @@ def bytesToHexClean(value, byteSize=4):
15101510

15111511

15121512
def intToHex(value, byte_size=4, signed=True):
1513+
value = int(value)
15131514
return format(value if signed else cast_integer(value, byte_size * 8, False), f"#0{(byte_size * 2 + 2)}x")
15141515

15151516

0 commit comments

Comments
 (0)