From b1a4327ab077bff096c4c414be21dcbd983c31f0 Mon Sep 17 00:00:00 2001 From: MegaMech Date: Thu, 18 Dec 2025 17:10:42 -0700 Subject: [PATCH 1/4] Update mk64_course.py --- fast64_internal/mk64/mk64_course.py | 70 +++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 4 deletions(-) diff --git a/fast64_internal/mk64/mk64_course.py b/fast64_internal/mk64/mk64_course.py index 9369ff47c..d90cb4789 100644 --- a/fast64_internal/mk64/mk64_course.py +++ b/fast64_internal/mk64/mk64_course.py @@ -53,12 +53,22 @@ class MK64_BpyCourse: def __init__(self, course_root: bpy.types.Object): self.root = course_root + self.log_file = os.path.join(os.path.expanduser("~"), "mk64_debug.txt") - def make_mk64_course_from_bpy(self, context: bpy.Types.Context, scale: float, mat_write_method: GfxMatWriteMethod): + def debug(self, message: str): + """Append a message to the log file.""" + timestamp = datetime.now().strftime("%H:%M:%S") + with open(self.log_file, "a") as f: + f.write(f"[{timestamp}] {message}\n") + + def make_mk64_course_from_bpy(self, context: bpy.Types.Context, scale: float, mat_write_method: GfxMatWriteMethod, logging_func): """ Creates a MK64_fModel class with all model data ready to exported to c also generates lists for items, pathing and collision (in future) """ + + logging_func({'INFO'}, "IS IT WORKING?!?!?!?") + fModel = MK64_fModel(self.root, mat_write_method) # create duplicate objects to export from transform = Matrix.Diagonal(Vector((scale, scale, scale))).to_4x4() @@ -69,13 +79,34 @@ def make_mk64_course_from_bpy(self, context: bpy.Types.Context, scale: float, ma # retrieve data for items and pathing def loop_children(obj, fModel, parent_transform): + logging_func({'INFO'},"LOOPING OVER OBJECTS!") for child in obj.children: if child.type == "MESH": self.export_f3d_from_obj(context, child, fModel, parent_transform @ child.matrix_local) if self.is_mk64_actor(child): self.add_actor(child, parent_transform, fModel) if child.type == "CURVE": - self.add_path(child, parent_transform, fModel) + splines = child.data.splines + # if not splines: + # return + + if len(splines) > 1: + self.report( + {'WARNING'}, + f"Curve '{child.name}' has multiple splines. Only the first will be exported." + ) + + spline = splines[0] + logging_func({'INFO'}, f"Checking child: {child.name}, type: {child.type}") + logging_func({'INFO'}, f"spline type: {spline.type}") + + if spline.type == 'BEZIER': + logging_func({'INFO'},"FOUND BEZIER") + self.add_curve(child, parent_transform, fModel) + elif spline.type == 'NURBS': + logging_func({'INFO'},"FOUND NURBS") + self.add_path(child, parent_transform, fModel, logging_func) + if child.children: loop_children(child, fModel, parent_transform @ child.matrix_local) @@ -93,7 +124,7 @@ def add_actor(self, obj: bpy.Types.Object, transform: Matrix, fModel: FModel): fModel.actors.append(MK64_Actor(position, mk64_props.actor_type)) return - def add_path(self, obj: bpy.Types.Object, transform: Matrix, fModel: FModel): + def add_curve(self, obj: bpy.Types.Object, transform: Matrix, fModel: FModel): curve_data = obj.data points = [] @@ -120,6 +151,35 @@ def add_path(self, obj: bpy.Types.Object, transform: Matrix, fModel: FModel): fModel.path.append(MK64_Path(points)) return + def add_path(self, obj: bpy.types.Object, transform: Matrix, fModel: FModel, logging_func): + logging_func({'INFO'},"MAKING PATH") + depsgraph = bpy.context.evaluated_depsgraph_get() + + logging_func({'INFO'},"GOT GRAPH") + eval_obj = obj.evaluated_get(depsgraph) + logging_func({'INFO'},"EVALULATE GRAPH") + mesh = eval_obj.to_mesh(preserve_all_data_layers=True, depsgraph=bpy.context.evaluated_depsgraph_get()) + logging_func({'INFO'},"OBJ TO MESH") + if not mesh: + logging_func({'INFO'},"NO MESH") + return + + points = [] + logging_func({'INFO'},"Mesh Len " + str(len(mesh.vertices))) + for v in mesh.vertices: + world_pos = transform @ eval_obj.matrix_world @ v.co + points.append(( + int(round(world_pos.x)), + int(round(world_pos.y)), + int(round(world_pos.z)), + 0, + )) + + eval_obj.to_mesh_clear() + + if points: + fModel.path.append(MK64_Path(points)) + # look into speeding this up by calculating just the apprent # transform using transformMatrix vs clearing parent and applying # transform @@ -393,6 +453,7 @@ def to_c(self): return "\n".join(lines) def to_xml(self): + print("PATH TO XML TEST") lines = [] for x, y, z, pid in self.points: lines.append(f"{{ {x}, {y}, {z}, {pid} }},") @@ -447,7 +508,8 @@ def export_course_xml(obj: bpy.types.Object, context: bpy.types.Context, export_ bpy_course = MK64_BpyCourse(obj) - mk64_fModel = bpy_course.make_mk64_course_from_bpy(context, scale, mat_write_method) + logging_func({'INFO'}, "EXPORT_XML") + mk64_fModel = bpy_course.make_mk64_course_from_bpy(context, scale, mat_write_method, logging_func) bpy_course.cleanup_course() From 4a4d7db260f868486b5e4f3a1cc18b6a06f3622e Mon Sep 17 00:00:00 2001 From: MegaMech Date: Thu, 18 Dec 2025 17:12:27 -0700 Subject: [PATCH 2/4] Update mk64_course.py --- fast64_internal/mk64/mk64_course.py | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/fast64_internal/mk64/mk64_course.py b/fast64_internal/mk64/mk64_course.py index d90cb4789..e01306f2f 100644 --- a/fast64_internal/mk64/mk64_course.py +++ b/fast64_internal/mk64/mk64_course.py @@ -53,13 +53,6 @@ class MK64_BpyCourse: def __init__(self, course_root: bpy.types.Object): self.root = course_root - self.log_file = os.path.join(os.path.expanduser("~"), "mk64_debug.txt") - - def debug(self, message: str): - """Append a message to the log file.""" - timestamp = datetime.now().strftime("%H:%M:%S") - with open(self.log_file, "a") as f: - f.write(f"[{timestamp}] {message}\n") def make_mk64_course_from_bpy(self, context: bpy.Types.Context, scale: float, mat_write_method: GfxMatWriteMethod, logging_func): """ @@ -67,8 +60,6 @@ def make_mk64_course_from_bpy(self, context: bpy.Types.Context, scale: float, ma also generates lists for items, pathing and collision (in future) """ - logging_func({'INFO'}, "IS IT WORKING?!?!?!?") - fModel = MK64_fModel(self.root, mat_write_method) # create duplicate objects to export from transform = Matrix.Diagonal(Vector((scale, scale, scale))).to_4x4() @@ -79,7 +70,6 @@ def make_mk64_course_from_bpy(self, context: bpy.Types.Context, scale: float, ma # retrieve data for items and pathing def loop_children(obj, fModel, parent_transform): - logging_func({'INFO'},"LOOPING OVER OBJECTS!") for child in obj.children: if child.type == "MESH": self.export_f3d_from_obj(context, child, fModel, parent_transform @ child.matrix_local) @@ -97,14 +87,10 @@ def loop_children(obj, fModel, parent_transform): ) spline = splines[0] - logging_func({'INFO'}, f"Checking child: {child.name}, type: {child.type}") - logging_func({'INFO'}, f"spline type: {spline.type}") if spline.type == 'BEZIER': - logging_func({'INFO'},"FOUND BEZIER") self.add_curve(child, parent_transform, fModel) elif spline.type == 'NURBS': - logging_func({'INFO'},"FOUND NURBS") self.add_path(child, parent_transform, fModel, logging_func) if child.children: @@ -152,20 +138,14 @@ def add_curve(self, obj: bpy.Types.Object, transform: Matrix, fModel: FModel): return def add_path(self, obj: bpy.types.Object, transform: Matrix, fModel: FModel, logging_func): - logging_func({'INFO'},"MAKING PATH") depsgraph = bpy.context.evaluated_depsgraph_get() - logging_func({'INFO'},"GOT GRAPH") eval_obj = obj.evaluated_get(depsgraph) - logging_func({'INFO'},"EVALULATE GRAPH") mesh = eval_obj.to_mesh(preserve_all_data_layers=True, depsgraph=bpy.context.evaluated_depsgraph_get()) - logging_func({'INFO'},"OBJ TO MESH") if not mesh: - logging_func({'INFO'},"NO MESH") return points = [] - logging_func({'INFO'},"Mesh Len " + str(len(mesh.vertices))) for v in mesh.vertices: world_pos = transform @ eval_obj.matrix_world @ v.co points.append(( @@ -508,7 +488,6 @@ def export_course_xml(obj: bpy.types.Object, context: bpy.types.Context, export_ bpy_course = MK64_BpyCourse(obj) - logging_func({'INFO'}, "EXPORT_XML") mk64_fModel = bpy_course.make_mk64_course_from_bpy(context, scale, mat_write_method, logging_func) bpy_course.cleanup_course() From 2fc2f788c21cb3552be7375992ecaf4b1dc414e3 Mon Sep 17 00:00:00 2001 From: MegaMech Date: Thu, 18 Dec 2025 17:18:02 -0700 Subject: [PATCH 3/4] Update mk64_course.py --- fast64_internal/mk64/mk64_course.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/fast64_internal/mk64/mk64_course.py b/fast64_internal/mk64/mk64_course.py index e01306f2f..a7924742f 100644 --- a/fast64_internal/mk64/mk64_course.py +++ b/fast64_internal/mk64/mk64_course.py @@ -59,7 +59,6 @@ def make_mk64_course_from_bpy(self, context: bpy.Types.Context, scale: float, ma Creates a MK64_fModel class with all model data ready to exported to c also generates lists for items, pathing and collision (in future) """ - fModel = MK64_fModel(self.root, mat_write_method) # create duplicate objects to export from transform = Matrix.Diagonal(Vector((scale, scale, scale))).to_4x4() @@ -77,9 +76,9 @@ def loop_children(obj, fModel, parent_transform): self.add_actor(child, parent_transform, fModel) if child.type == "CURVE": splines = child.data.splines - # if not splines: - # return - + if not splines: + return + if len(splines) > 1: self.report( {'WARNING'}, @@ -433,7 +432,6 @@ def to_c(self): return "\n".join(lines) def to_xml(self): - print("PATH TO XML TEST") lines = [] for x, y, z, pid in self.points: lines.append(f"{{ {x}, {y}, {z}, {pid} }},") From e4493c83088562f3f068d85052c086e362bc4591 Mon Sep 17 00:00:00 2001 From: MegaMech Date: Thu, 18 Dec 2025 17:35:18 -0700 Subject: [PATCH 4/4] Update mk64_course.py --- fast64_internal/mk64/mk64_course.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/fast64_internal/mk64/mk64_course.py b/fast64_internal/mk64/mk64_course.py index a7924742f..bdbcf7723 100644 --- a/fast64_internal/mk64/mk64_course.py +++ b/fast64_internal/mk64/mk64_course.py @@ -307,19 +307,17 @@ def to_xml_track_sections(self, *args): if not self.track_sections: return + lines.append("") for i, section in enumerate(self.track_sections): sections = "\n\t".join([ f"
" - for section in self.track_sections ]) lines.extend(( - f"", f"\t{sections}", - "" )) - + lines.append("") data = "\n".join(lines) writeXMLData(data, os.path.join(export_dir, "data_track_sections"))