From a67236ba88b7d61a73e7a84ca1cd9be0d641c3a1 Mon Sep 17 00:00:00 2001 From: coco875 Date: Thu, 29 Feb 2024 12:35:36 +0100 Subject: [PATCH 01/46] start add mk64 course importer --- __init__.py | 8 ++ fast64_internal/mk64/__init__.py | 145 +++++++++++++++++++++++++++++++ fast64_internal/panels.py | 11 ++- 3 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 fast64_internal/mk64/__init__.py diff --git a/__init__.py b/__init__.py index dc57c59ba..20d9e3e49 100644 --- a/__init__.py +++ b/__init__.py @@ -15,6 +15,8 @@ from .fast64_internal.oot.props_panel_main import OOT_ObjectProperties from .fast64_internal.utility_anim import utility_anim_register, utility_anim_unregister, ArmatureApplyWithMeshOperator +from .fast64_internal.mk64 import MK64_Properties, mk64_register, mk64_unregister + from .fast64_internal.f3d.f3d_material import mat_register, mat_unregister from .fast64_internal.f3d.f3d_render_engine import render_engine_register, render_engine_unregister from .fast64_internal.f3d.f3d_writer import f3d_writer_register, f3d_writer_unregister @@ -51,6 +53,7 @@ gameEditorEnum = ( ("SM64", "SM64", "Super Mario 64"), ("OOT", "OOT", "Ocarina Of Time"), + ("MK64", "MK64", "Mario Kart 64"), ) @@ -260,6 +263,7 @@ class Fast64_Properties(bpy.types.PropertyGroup): sm64: bpy.props.PointerProperty(type=SM64_Properties, name="SM64 Properties") oot: bpy.props.PointerProperty(type=OOT_Properties, name="OOT Properties") + mk64: bpy.props.PointerProperty(type=MK64_Properties, name="MK64 Properties") settings: bpy.props.PointerProperty(type=Fast64Settings_Properties, name="Fast64 Settings") renderSettings: bpy.props.PointerProperty(type=Fast64RenderSettings_Properties, name="Fast64 Render Settings") @@ -408,6 +412,8 @@ def gameEditorUpdate(self, context): self.f3d_type = "F3D" elif self.gameEditorMode == "OOT": self.f3d_type = "F3DEX2/LX2" + elif self.gameEditorMode == "MK64": + self.f3d_type = "F3DEX/LX" # called on add-on enabling @@ -437,6 +443,7 @@ def register(): bsdf_conv_register() sm64_register(True) oot_register(True) + mk64_register(True) for cls in classes: register_class(cls) @@ -483,6 +490,7 @@ def unregister(): f3d_parser_unregister() sm64_unregister(True) oot_unregister(True) + mk64_unregister(True) mat_unregister() bsdf_conv_unregister() bsdf_conv_panel_unregsiter() diff --git a/fast64_internal/mk64/__init__.py b/fast64_internal/mk64/__init__.py new file mode 100644 index 000000000..5c1ae99e8 --- /dev/null +++ b/fast64_internal/mk64/__init__.py @@ -0,0 +1,145 @@ +import math +import bpy +from bpy_types import PropertyGroup +import mathutils +from ..f3d.f3d_gbi import get_F3D_GBI +from ..f3d.f3d_material import createF3DMat +from ..f3d.f3d_parser import F3DContext, getImportData, parseF3D +from ..panels import MK64_Panel +from ..utility import applyRotation, prop_split +from bpy.utils import register_class, unregister_class +from ..utility import raisePluginError + +class MK64_Properties(PropertyGroup): + """Global MK64 Scene Properties found under scene.fast64.mk64""" + + version: bpy.props.IntProperty(name="MK64_Properties Version", default=0) + +def importMeshC( + data: str, + name: str, + scale: float, + removeDoubles: bool, + importNormals: bool, + drawLayer: str, + f3dContext: F3DContext, + callClearMaterial: bool = True, +) -> bpy.types.Object: + mesh = bpy.data.meshes.new(name + "_mesh") + obj = bpy.data.objects.new(name + "_mesh", mesh) + bpy.context.collection.objects.link(obj) + + f3dContext.mat().draw_layer.oot = drawLayer + transformMatrix = mathutils.Matrix.Scale(1 / scale, 4) + + parseF3D(data, name, transformMatrix, name, name, "oot", drawLayer, f3dContext, True) + f3dContext.createMesh(obj, removeDoubles, importNormals, callClearMaterial) + + applyRotation([obj], math.radians(-90), "X") + return obj + +class MK64_ImportCourseDL(bpy.types.Operator): + # set bl_ properties + bl_idname = "object.f3d_import_dl" + bl_label = "Import DL" + bl_options = {"REGISTER", "UNDO", "PRESET"} + + # Called on demand (i.e. button press, menu item) + # Can also be called from operator search menu (Spacebar) + def execute(self, context): + obj = None + if context.mode != "OBJECT": + bpy.ops.object.mode_set(mode="OBJECT") + + try: + name = context.scene.DLImportName + importPath = bpy.path.abspath(context.scene.DLImportPath) + basePath = bpy.path.abspath(context.scene.DLImportBasePath) + scaleValue = context.scene.blenderF3DScale + + removeDoubles = context.scene.DLRemoveDoubles + importNormals = context.scene.DLImportNormals + drawLayer = context.scene.DLImportDrawLayer + + data = getImportData([importPath]) + + importMeshC( + data, + name, + scaleValue, + removeDoubles, + importNormals, + drawLayer, + F3DContext(get_F3D_GBI(), basePath, createF3DMat(None)), + ) + + self.report({"INFO"}, "Success!") + return {"FINISHED"} + + except Exception as e: + if context.mode != "OBJECT": + bpy.ops.object.mode_set(mode="OBJECT") + raisePluginError(self, e) + return {"CANCELLED"} # must return a set + + +class MK64_ImportCourseDLPanel(MK64_Panel): + bl_idname = "MK64_import_course_DL_panel_settings" + bl_label = "MK64 Import Course DL Panel Settings" + bl_options = set() # default to open + bl_order = 0 # force to front + + @classmethod + def poll(cls, context): + return True + + # called every frame + def draw(self, context): + col = self.layout.column() + col.scale_y = 1.1 # extra padding + + col.operator(MK64_ImportCourseDL.bl_idname) + prop_split(col, context.scene, "DLImportName", "Name") + prop_split(col, context.scene, "DLImportPath", "File") + prop_split(col, context.scene, "DLImportBasePath", "Base Path") + prop_split(col, context.scene, "blenderF3DScale", "Scale") + prop_split(col, context.scene, "DLImportDrawLayer", "Draw Layer") + col.prop(context.scene, "DLRemoveDoubles") + col.prop(context.scene, "DLImportNormals") + + box = col.box().column() + box.label(text="All data must be contained within file.") + box.label(text="The only exception are pngs converted to inc.c.") + + # col.template_list('F3D_UL_ImportDLPathList', '', context.scene, + # 'DLImportOtherFiles', context.scene, 'DLImportOtherFilesIndex') + + + + +mk64_classes = (MK64_Properties,) + +mk64_panel_classes = ( + MK64_ImportCourseDL, + MK64_ImportCourseDLPanel, +) + +def mk64_panel_register(): + for cls in mk64_panel_classes: + register_class(cls) + +def mk64_panel_unregister(): + for cls in mk64_panel_classes: + unregister_class(cls) + +def mk64_register(registerPanels): + for cls in mk64_classes: + register_class(cls) + if registerPanels: + mk64_panel_register() + +def mk64_unregister(registerPanel): + for cls in reversed(mk64_classes): + unregister_class(cls) + if registerPanel: + mk64_panel_unregister() \ No newline at end of file diff --git a/fast64_internal/panels.py b/fast64_internal/panels.py index adc5f97db..1a35b4dc2 100644 --- a/fast64_internal/panels.py +++ b/fast64_internal/panels.py @@ -9,7 +9,6 @@ ("Export UI Image", "Export UI Image", "Export UI Image"), ] - class SM64_Panel(bpy.types.Panel): bl_space_type = "VIEW_3D" bl_region_type = "UI" @@ -46,3 +45,13 @@ class OOT_Panel(bpy.types.Panel): @classmethod def poll(cls, context): return context.scene.gameEditorMode == "OOT" + +class MK64_Panel(bpy.types.Panel): + bl_space_type = "VIEW_3D" + bl_region_type = "UI" + bl_category = "MK64" + bl_options = {"DEFAULT_CLOSED"} + + @classmethod + def poll(cls, context): + return context.scene.gameEditorMode == "MK64" From 43c25b6050b4c2c56cac2bedb8f31a5dcacee73c Mon Sep 17 00:00:00 2001 From: coco875 Date: Thu, 29 Feb 2024 15:57:14 +0100 Subject: [PATCH 02/46] add the possibility to import course --- fast64_internal/mk64/__init__.py | 51 ++- fast64_internal/mk64/f3d_course_parser.py | 376 ++++++++++++++++++++++ 2 files changed, 398 insertions(+), 29 deletions(-) create mode 100644 fast64_internal/mk64/f3d_course_parser.py diff --git a/fast64_internal/mk64/__init__.py b/fast64_internal/mk64/__init__.py index 5c1ae99e8..bf9ea12d7 100644 --- a/fast64_internal/mk64/__init__.py +++ b/fast64_internal/mk64/__init__.py @@ -4,44 +4,22 @@ import mathutils from ..f3d.f3d_gbi import get_F3D_GBI from ..f3d.f3d_material import createF3DMat -from ..f3d.f3d_parser import F3DContext, getImportData, parseF3D +from ..f3d.f3d_parser import F3DContext, getImportData, importMeshC from ..panels import MK64_Panel -from ..utility import applyRotation, prop_split +from ..utility import prop_split from bpy.utils import register_class, unregister_class from ..utility import raisePluginError +from .f3d_course_parser import processCommands, parseCourseVtx class MK64_Properties(PropertyGroup): """Global MK64 Scene Properties found under scene.fast64.mk64""" version: bpy.props.IntProperty(name="MK64_Properties Version", default=0) -def importMeshC( - data: str, - name: str, - scale: float, - removeDoubles: bool, - importNormals: bool, - drawLayer: str, - f3dContext: F3DContext, - callClearMaterial: bool = True, -) -> bpy.types.Object: - mesh = bpy.data.meshes.new(name + "_mesh") - obj = bpy.data.objects.new(name + "_mesh", mesh) - bpy.context.collection.objects.link(obj) - - f3dContext.mat().draw_layer.oot = drawLayer - transformMatrix = mathutils.Matrix.Scale(1 / scale, 4) - - parseF3D(data, name, transformMatrix, name, name, "oot", drawLayer, f3dContext, True) - f3dContext.createMesh(obj, removeDoubles, importNormals, callClearMaterial) - - applyRotation([obj], math.radians(-90), "X") - return obj - class MK64_ImportCourseDL(bpy.types.Operator): # set bl_ properties - bl_idname = "object.f3d_import_dl" - bl_label = "Import DL" + bl_idname = "object.f3d_course_import_dl" + bl_label = "Import Course DL" bl_options = {"REGISTER", "UNDO", "PRESET"} # Called on demand (i.e. button press, menu item) @@ -61,7 +39,22 @@ def execute(self, context): importNormals = context.scene.DLImportNormals drawLayer = context.scene.DLImportDrawLayer - data = getImportData([importPath]) + paths = [importPath] + + if "course_data" in importPath: + paths += [importPath.replace("course_data", "course_displaylists")] + + paths += [importPath.replace("course_data.inc", "course_textures.linkonly").replace("course_displaylists.inc", "course_textures.linkonly")] + + data = getImportData(paths) + + + f3d_context = F3DContext(get_F3D_GBI(), basePath, createF3DMat(None)) + if "course_displaylists" in importPath or "course_data" in importPath: + vertexPath = importPath.replace("course_displaylists", "course_vertices").replace("course_data", "course_vertices") + print(vertexPath) + f3d_context.vertexData["0x4000000"] = parseCourseVtx(vertexPath, f3d_context.f3d) + f3d_context.processCommands = processCommands.__get__(f3d_context, F3DContext) importMeshC( data, @@ -70,7 +63,7 @@ def execute(self, context): removeDoubles, importNormals, drawLayer, - F3DContext(get_F3D_GBI(), basePath, createF3DMat(None)), + f3d_context, ) self.report({"INFO"}, "Success!") diff --git a/fast64_internal/mk64/f3d_course_parser.py b/fast64_internal/mk64/f3d_course_parser.py new file mode 100644 index 000000000..70039b0c5 --- /dev/null +++ b/fast64_internal/mk64/f3d_course_parser.py @@ -0,0 +1,376 @@ +import re +import traceback +from mathutils import Vector +from ..f3d.f3d_gbi import F3D +from ..f3d.f3d_material import RDPSettings +from ..f3d.f3d_parser import F3DContext, F3DParsedCommands, ParsedMacro, math_eval, parseDLData +from ..f3d.f3d_writer import F3DVert +from ..utility import PluginError, float_from_u16_str, gammaInverseValue, int_from_s16_str, readFile, unpackNormal + +def courseVertexFormatPatterns(): + # position, uv, color/normal + return [ + # decomp format + "\{\s*" + + "\{+([^,\}]*),([^,\}]*),([^,\}]*)\}\s*,\s*" + + "\{([^,\}]*),([^,\}]*)\}\s*,\s*" + + "\{MACRO_COLOR_FLAG\(([^,\}]*),([^,\}]*),([^,\}]*),([^,\}])*\),([^,\}]*)\}\s*" + + "\}", + ][0] + +def parseCourseVtx(path: str, f3d): + data = readFile(path) + pattern = courseVertexFormatPatterns() + vertexData = [] + for values in re.findall(pattern, data, re.DOTALL): + values = [math_eval(g, f3d) for g in values] + vertexData.append( + F3DVert( + Vector(values[0:3]), + Vector(values[3:5]), + Vector(values[5:8]), + unpackNormal(values[8]), + values[9], + ) + ) + return vertexData + +def getVertexDataStart(vertexDataParam: str, f3d: F3D): + matchResult = re.search(r"\&?([A-Za-z0-9\_]*)\s*(\[([^\]]*)\])?\s*(\+(.*))?", vertexDataParam) + if matchResult is None: + raise PluginError("SPVertex param " + vertexDataParam + " is malformed.") + + offset = 0 + if matchResult.group(3): + offset += math_eval(matchResult.group(3), f3d) + if matchResult.group(5): + offset += math_eval(matchResult.group(5), f3d) + + name = matchResult.group(1) + + if matchResult.group(1).startswith("0x04"): + offset = (int(matchResult.group(1), 16) - 0x04000000)//16 + name = hex(0x04000000) + return name, offset + +def parseVertexData(dlData: str, vertexDataName: str, f3dContext: F3DContext): + if vertexDataName in f3dContext.vertexData: + return f3dContext.vertexData[vertexDataName] + + matchResult = re.search( + r"Vtx\s*" + re.escape(vertexDataName) + r"\s*\[\s*[0-9x]*\s*\]\s*=\s*\{([^;]*);", dlData, re.DOTALL + ) + if matchResult is None: + raise PluginError("Cannot find vertex list named " + vertexDataName) + data = matchResult.group(1) + + pathMatch = re.search(r'\#include\s*"([^"]*)"', data) + if pathMatch is not None: + path = pathMatch.group(1) + data = readFile(f3dContext.getVTXPathFromInclude(path)) + + f3d = f3dContext.f3d + patterns = f3dContext.vertexFormatPatterns(data) + vertexData = [] + for pattern in patterns: + # For this step, store rgb/normal as rgb and packed normal as normal. + for match in re.finditer(pattern, data, re.DOTALL): + values = [math_eval(g, f3d) for g in match.groups()] + if len(values) == 9: + # A format without the flag / packed normal + values = values[0:3] + [0] + values[3:9] + vertexData.append( + F3DVert( + Vector(values[0:3]), + Vector(values[4:6]), + Vector(values[6:9]), + unpackNormal(values[3]), + values[9], + ) + ) + if len(vertexData) > 0: + break + f3dContext.vertexData[vertexDataName] = vertexData + + return f3dContext.vertexData[vertexDataName] + + +def processCommands(self, dlData: str, dlName: str, dlCommands: "list[ParsedMacro]"): + callStack = [F3DParsedCommands(dlName, dlCommands, 0)] + while len(callStack) > 0: + currentCommandList = callStack[-1] + command = currentCommandList.currentCommand() + + if currentCommandList.index >= len(currentCommandList.commands): + raise PluginError("Cannot handle unterminated static display lists: " + currentCommandList.name) + elif len(callStack) > 2**16: + raise PluginError("DL call stack larger than 2**16, assuming infinite loop: " + currentCommandList.name) + + # print(command.name + " " + str(command.params)) + if command.name == "gsSPVertex": + vertexDataName, vertexDataOffset = getVertexDataStart(command.params[0], self.f3d) + parseVertexData(dlData, vertexDataName, self) + self.addVertices(command.params[1], command.params[2], vertexDataName, vertexDataOffset) + elif command.name == "gsSPMatrix": + self.setCurrentTransform(command.params[0], command.params[1]) + elif command.name == "gsSPPopMatrix": + print("gsSPPopMatrix not handled.") + elif command.name == "gsSP1Triangle": + self.addTriangle(command.params[0:3], dlData) + elif command.name == "gsSP2Triangles": + self.addTriangle(command.params[0:3] + command.params[4:7], dlData) + elif command.name == "gsSPDisplayList" or command.name.startswith("gsSPBranch"): + newDLName = self.processDLName(command.params[0]) + if newDLName is not None: + newDLCommands = parseDLData(dlData, newDLName) + # Use -1 index so that it will be incremented to 0 at end of loop + parsedCommands = F3DParsedCommands(newDLName, newDLCommands, -1) + if command.name == "gsSPDisplayList": + callStack.append(parsedCommands) + elif command.name.startswith("gsSPBranch"): # TODO: Handle BranchZ? + callStack = callStack[:-1] + callStack.append(parsedCommands) + elif command.name == "gsSPEndDisplayList": + callStack = callStack[:-1] + + # Should we parse commands into f3d_gbi classes? + # No, because some parsing involves reading C files, which is separate. + + # Assumes macros use variable names instead of values + mat = self.mat() + try: + # Material Specific Commands + materialNotChanged = False + + rdp_settings: "RDPSettings" = mat.rdp_settings + + if command.name == "gsSPClipRatio": + rdp_settings.clip_ratio = math_eval(command.params[0], self.f3d) + elif command.name == "gsSPNumLights": + self.numLights = self.getLightCount(command.params[0]) + elif command.name == "gsSPLight": + self.setLight(dlData, command) + elif command.name == "gsSPLightColor": + self.setLightColor(dlData, command) + elif command.name[:13] == "gsSPSetLights": + self.setLights(dlData, command) + elif command.name == "gsSPAmbOcclusionAmb": + mat.ao_ambient = float_from_u16_str(command.params[0]) + mat.set_ao = True + elif command.name == "gsSPAmbOcclusionDir": + mat.ao_directional = float_from_u16_str(command.params[0]) + mat.set_ao = True + elif command.name == "gsSPAmbOcclusionPoint": + mat.ao_point = float_from_u16_str(command.params[0]) + mat.set_ao = True + elif command.name == "gsSPAmbOcclusionAmbDir": + mat.ao_ambient = float_from_u16_str(command.params[0]) + mat.ao_directional = float_from_u16_str(command.params[1]) + mat.set_ao = True + elif command.name == "gsSPAmbOcclusionDirPoint": + mat.ao_directional = float_from_u16_str(command.params[0]) + mat.ao_point = float_from_u16_str(command.params[1]) + mat.set_ao = True + elif command.name == "gsSPAmbOcclusion": + mat.ao_ambient = float_from_u16_str(command.params[0]) + mat.ao_directional = float_from_u16_str(command.params[1]) + mat.ao_point = float_from_u16_str(command.params[2]) + mat.set_ao = True + elif command.name == "gsSPFresnel": + scale = int_from_s16_str(command.params[0]) + offset = int_from_s16_str(command.params[1]) + dotMax = ((0x7F - offset) << 15) // scale + dotMin = ((0x00 - offset) << 15) // scale + mat.fresnel_hi = dotMax / float(0x7FFF) + mat.fresnel_lo = dotMin / float(0x7FFF) + mat.set_fresnel = True + elif command.name == "gsSPAttrOffsetST": + mat.attroffs_st = [ + int_from_s16_str(command.params[0]) / 32, + int_from_s16_str(command.params[1]) / 32, + ] + mat.set_attroffs_st = True + elif command.name == "gsSPAttrOffsetZ": + mat.attroffs_z = int_from_s16_str(command.params[0]) + mat.set_attroffs_z = True + elif command.name == "gsSPFogFactor": + pass + elif command.name == "gsSPFogPosition": + mat.fog_position = [math_eval(command.params[0], self.f3d), math_eval(command.params[1], self.f3d)] + mat.set_fog = True + elif command.name == "gsSPTexture" or command.name == "gsSPTextureL": + # scale_autoprop should always be false (set in init) + # This prevents issues with material caching where updating nodes on a material causes its key to change + if command.params[0] == 0xFFFF and command.params[1] == 0xFFFF: + mat.tex_scale = (1, 1) + else: + mat.tex_scale = [ + math_eval(command.params[0], self.f3d) / (2**16), + math_eval(command.params[1], self.f3d) / (2**16), + ] + # command.params[2] is "lod level", and for clarity we store this is the number of mipmapped textures (which is +1) + rdp_settings.num_textures_mipmapped = 1 + math_eval(command.params[2], self.f3d) + elif command.name == "gsSPSetGeometryMode": + self.setGeoFlags(command, True) + elif command.name == "gsSPClearGeometryMode": + self.setGeoFlags(command, False) + elif command.name == "gsSPLoadGeometryMode": + self.loadGeoFlags(command) + elif command.name == "gsSPSetOtherMode": + self.setOtherModeFlags(command) + elif command.name == "gsDPPipelineMode": + rdp_settings.g_mdsft_pipeline = command.params[0] + elif command.name == "gsDPSetCycleType": + rdp_settings.g_mdsft_cycletype = command.params[0] + elif command.name == "gsDPSetTexturePersp": + rdp_settings.g_mdsft_textpersp = command.params[0] + elif command.name == "gsDPSetTextureDetail": + rdp_settings.g_mdsft_textdetail = command.params[0] + elif command.name == "gsDPSetTextureLOD": + rdp_settings.g_mdsft_textlod = command.params[0] + elif command.name == "gsDPSetTextureLUT": + self.setTLUTMode(command.params[0]) + elif command.name == "gsDPSetTextureFilter": + rdp_settings.g_mdsft_text_filt = command.params[0] + elif command.name == "gsDPSetTextureConvert": + rdp_settings.g_mdsft_textconv = command.params[0] + elif command.name == "gsDPSetCombineKey": + rdp_settings.g_mdsft_combkey = command.params[0] + elif command.name == "gsDPSetColorDither": + rdp_settings.g_mdsft_color_dither = command.params[0] + elif command.name == "gsDPSetAlphaDither": + rdp_settings.g_mdsft_alpha_dither = command.params[0] + elif command.name == "gsDPSetAlphaCompare": + rdp_settings.g_mdsft_alpha_compare = command.params[0] + elif command.name == "gsDPSetDepthSource": + rdp_settings.g_mdsft_zsrcsel = command.params[0] + elif command.name == "gsDPSetRenderMode": + flags = math_eval(command.params[0] + " | " + command.params[1], self.f3d) + self.setRenderMode(flags) + elif command.name == "gsDPSetTextureImage": + # Are other params necessary? + # The params are set in SetTile commands. + self.currentTextureName = command.params[3] + elif command.name == "gsDPSetCombineMode": + self.setCombineMode(command) + elif command.name == "gsDPSetCombineLERP": + self.setCombineLerp(command.params[0:8], command.params[8:16]) + elif command.name == "gsDPSetEnvColor": + mat.env_color = self.gammaInverseParam(command.params) + mat.set_env = True + elif command.name == "gsDPSetBlendColor": + mat.blend_color = self.gammaInverseParam(command.params) + mat.set_blend = True + elif command.name == "gsDPSetFogColor": + mat.fog_color = self.gammaInverseParam(command.params) + mat.set_fog = True + elif command.name == "gsDPSetFillColor": + pass + elif command.name == "gsDPSetPrimDepth": + pass + elif command.name == "gsDPSetPrimColor": + mat.prim_lod_min = math_eval(command.params[0], self.f3d) / 255 + mat.prim_lod_frac = math_eval(command.params[1], self.f3d) / 255 + mat.prim_color = self.gammaInverseParam(command.params[2:6]) + mat.set_prim = True + elif command.name == "gsDPSetOtherMode": + print("gsDPSetOtherMode not handled.") + elif command.name == "DPSetConvert": + mat.set_k0_5 = True + for i in range(6): + setattr(mat, "k" + str(i), gammaInverseValue(math_eval(command.params[i], self.f3d) / 255)) + elif command.name == "DPSetKeyR": + mat.set_key = True + elif command.name == "DPSetKeyGB": + mat.set_key = True + else: + materialNotChanged = True + + if not materialNotChanged: + self.materialChanged = True + + # Texture Commands + # Assume file texture load + # SetTextureImage -> Load command -> Set Tile (0 or 1) + + if command.name == "gsDPSetTileSize": + self.setTileSize(command.params) + elif command.name == "gsDPLoadTile": + self.loadTile(command.params) + elif command.name == "gsDPSetTile": + self.setTile(command.params, dlData) + elif command.name == "gsDPLoadBlock": + self.loadTile(command.params) + elif command.name == "gsDPLoadTLUTCmd": + self.loadTLUT(command.params, dlData) + + # This all ignores S/T high/low values + # This is pretty bad/confusing + elif command.name.startswith("gsDPLoadTextureBlock"): + is4bit = "4b" in command.name + if is4bit: + self.loadMultiBlock( + [command.params[0]] + + [0, "G_TX_RENDERTILE"] + + [command.params[1], "G_IM_SIZ_4b"] + + command.params[2:], + dlData, + True, + ) + else: + self.loadMultiBlock( + [command.params[0]] + [0, "G_TX_RENDERTILE"] + command.params[1:], dlData, False + ) + elif command.name.startswith("gsDPLoadMultiBlock"): + is4bit = "4b" in command.name + if is4bit: + self.loadMultiBlock(command.params[:4] + ["G_IM_SIZ_4b"] + command.params[4:], dlData, True) + else: + self.loadMultiBlock(command.params, dlData, False) + elif command.name.startswith("gsDPLoadTextureTile"): + is4bit = "4b" in command.name + if is4bit: + self.loadMultiBlock( + [command.params[0]] + + [0, "G_TX_RENDERTILE"] + + [command.params[1], "G_IM_SIZ_4b"] + + command.params[2:4] + + command.params[9:], + "4b", # FIXME extra argument? + dlData, + True, + ) + else: + self.loadMultiBlock( + [command.params[0]] + [0, "G_TX_RENDERTILE"] + command.params[1:5] + command.params[9:], + "4b", # FIXME extra argument? + dlData, + False, + ) + elif command.name.startswith("gsDPLoadMultiTile"): + is4bit = "4b" in command.name + if is4bit: + self.loadMultiBlock( + command.params[:4] + ["G_IM_SIZ_4b"] + command.params[4:6] + command.params[10:], + dlData, + True, + ) + else: + self.loadMultiBlock(command.params[:7] + command.params[11:], dlData, False) + + # TODO: Only handles palettes at tmem = 256 + elif command.name == "gsDPLoadTLUT_pal16": + self.loadTLUTPal(command.params[1], dlData, 15) + elif command.name == "gsDPLoadTLUT_pal256": + self.loadTLUTPal(command.params[0], dlData, 255) + else: + pass + + except TypeError as e: + print(traceback.format_exc()) + # raise Exception(e) + # print(e) + + # Don't use currentCommandList because some commands may change that + if len(callStack) > 0: + callStack[-1].index += 1 From ebe1688bfad931a804a3af5dbb3987dc7a0457e7 Mon Sep 17 00:00:00 2001 From: coco875 Date: Thu, 29 Feb 2024 16:00:28 +0100 Subject: [PATCH 03/46] remove unmodified function --- fast64_internal/mk64/f3d_course_parser.py | 44 +---------------------- 1 file changed, 1 insertion(+), 43 deletions(-) diff --git a/fast64_internal/mk64/f3d_course_parser.py b/fast64_internal/mk64/f3d_course_parser.py index 70039b0c5..a5c9629c9 100644 --- a/fast64_internal/mk64/f3d_course_parser.py +++ b/fast64_internal/mk64/f3d_course_parser.py @@ -3,7 +3,7 @@ from mathutils import Vector from ..f3d.f3d_gbi import F3D from ..f3d.f3d_material import RDPSettings -from ..f3d.f3d_parser import F3DContext, F3DParsedCommands, ParsedMacro, math_eval, parseDLData +from ..f3d.f3d_parser import F3DParsedCommands, ParsedMacro, math_eval, parseDLData, parseVertexData from ..f3d.f3d_writer import F3DVert from ..utility import PluginError, float_from_u16_str, gammaInverseValue, int_from_s16_str, readFile, unpackNormal @@ -53,48 +53,6 @@ def getVertexDataStart(vertexDataParam: str, f3d: F3D): name = hex(0x04000000) return name, offset -def parseVertexData(dlData: str, vertexDataName: str, f3dContext: F3DContext): - if vertexDataName in f3dContext.vertexData: - return f3dContext.vertexData[vertexDataName] - - matchResult = re.search( - r"Vtx\s*" + re.escape(vertexDataName) + r"\s*\[\s*[0-9x]*\s*\]\s*=\s*\{([^;]*);", dlData, re.DOTALL - ) - if matchResult is None: - raise PluginError("Cannot find vertex list named " + vertexDataName) - data = matchResult.group(1) - - pathMatch = re.search(r'\#include\s*"([^"]*)"', data) - if pathMatch is not None: - path = pathMatch.group(1) - data = readFile(f3dContext.getVTXPathFromInclude(path)) - - f3d = f3dContext.f3d - patterns = f3dContext.vertexFormatPatterns(data) - vertexData = [] - for pattern in patterns: - # For this step, store rgb/normal as rgb and packed normal as normal. - for match in re.finditer(pattern, data, re.DOTALL): - values = [math_eval(g, f3d) for g in match.groups()] - if len(values) == 9: - # A format without the flag / packed normal - values = values[0:3] + [0] + values[3:9] - vertexData.append( - F3DVert( - Vector(values[0:3]), - Vector(values[4:6]), - Vector(values[6:9]), - unpackNormal(values[3]), - values[9], - ) - ) - if len(vertexData) > 0: - break - f3dContext.vertexData[vertexDataName] = vertexData - - return f3dContext.vertexData[vertexDataName] - - def processCommands(self, dlData: str, dlName: str, dlCommands: "list[ParsedMacro]"): callStack = [F3DParsedCommands(dlName, dlCommands, 0)] while len(callStack) > 0: From 758632c9cc2f7294dd2fcb69c9aa9aa26242f2b2 Mon Sep 17 00:00:00 2001 From: coco875 Date: Thu, 29 Feb 2024 16:02:10 +0100 Subject: [PATCH 04/46] Update panels.py --- fast64_internal/panels.py | 1 + 1 file changed, 1 insertion(+) diff --git a/fast64_internal/panels.py b/fast64_internal/panels.py index 1a35b4dc2..c58c0a5d6 100644 --- a/fast64_internal/panels.py +++ b/fast64_internal/panels.py @@ -9,6 +9,7 @@ ("Export UI Image", "Export UI Image", "Export UI Image"), ] + class SM64_Panel(bpy.types.Panel): bl_space_type = "VIEW_3D" bl_region_type = "UI" From c41cbf2b114c24bf5ced041c46e9364db57f9427 Mon Sep 17 00:00:00 2001 From: coco875 Date: Thu, 29 Feb 2024 16:10:56 +0100 Subject: [PATCH 05/46] reformat by using black --- fast64_internal/mk64/__init__.py | 23 ++++++++++++++------ fast64_internal/mk64/f3d_course_parser.py | 26 +++++++++++++---------- fast64_internal/panels.py | 3 ++- 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/fast64_internal/mk64/__init__.py b/fast64_internal/mk64/__init__.py index bf9ea12d7..613664cba 100644 --- a/fast64_internal/mk64/__init__.py +++ b/fast64_internal/mk64/__init__.py @@ -11,11 +11,13 @@ from ..utility import raisePluginError from .f3d_course_parser import processCommands, parseCourseVtx + class MK64_Properties(PropertyGroup): """Global MK64 Scene Properties found under scene.fast64.mk64""" version: bpy.props.IntProperty(name="MK64_Properties Version", default=0) + class MK64_ImportCourseDL(bpy.types.Operator): # set bl_ properties bl_idname = "object.f3d_course_import_dl" @@ -43,15 +45,20 @@ def execute(self, context): if "course_data" in importPath: paths += [importPath.replace("course_data", "course_displaylists")] - - paths += [importPath.replace("course_data.inc", "course_textures.linkonly").replace("course_displaylists.inc", "course_textures.linkonly")] - data = getImportData(paths) + paths += [ + importPath.replace("course_data.inc", "course_textures.linkonly").replace( + "course_displaylists.inc", "course_textures.linkonly" + ) + ] + data = getImportData(paths) f3d_context = F3DContext(get_F3D_GBI(), basePath, createF3DMat(None)) if "course_displaylists" in importPath or "course_data" in importPath: - vertexPath = importPath.replace("course_displaylists", "course_vertices").replace("course_data", "course_vertices") + vertexPath = importPath.replace("course_displaylists", "course_vertices").replace( + "course_data", "course_vertices" + ) print(vertexPath) f3d_context.vertexData["0x4000000"] = parseCourseVtx(vertexPath, f3d_context.f3d) f3d_context.processCommands = processCommands.__get__(f3d_context, F3DContext) @@ -108,8 +115,6 @@ def draw(self, context): # 'DLImportOtherFiles', context.scene, 'DLImportOtherFilesIndex') - - mk64_classes = (MK64_Properties,) mk64_panel_classes = ( @@ -117,22 +122,26 @@ def draw(self, context): MK64_ImportCourseDLPanel, ) + def mk64_panel_register(): for cls in mk64_panel_classes: register_class(cls) + def mk64_panel_unregister(): for cls in mk64_panel_classes: unregister_class(cls) + def mk64_register(registerPanels): for cls in mk64_classes: register_class(cls) if registerPanels: mk64_panel_register() + def mk64_unregister(registerPanel): for cls in reversed(mk64_classes): unregister_class(cls) if registerPanel: - mk64_panel_unregister() \ No newline at end of file + mk64_panel_unregister() diff --git a/fast64_internal/mk64/f3d_course_parser.py b/fast64_internal/mk64/f3d_course_parser.py index a5c9629c9..1d613c019 100644 --- a/fast64_internal/mk64/f3d_course_parser.py +++ b/fast64_internal/mk64/f3d_course_parser.py @@ -7,16 +7,18 @@ from ..f3d.f3d_writer import F3DVert from ..utility import PluginError, float_from_u16_str, gammaInverseValue, int_from_s16_str, readFile, unpackNormal + def courseVertexFormatPatterns(): - # position, uv, color/normal - return [ - # decomp format - "\{\s*" - + "\{+([^,\}]*),([^,\}]*),([^,\}]*)\}\s*,\s*" - + "\{([^,\}]*),([^,\}]*)\}\s*,\s*" - + "\{MACRO_COLOR_FLAG\(([^,\}]*),([^,\}]*),([^,\}]*),([^,\}])*\),([^,\}]*)\}\s*" - + "\}", - ][0] + # position, uv, color/normal + return [ + # decomp format + "\{\s*" + + "\{+([^,\}]*),([^,\}]*),([^,\}]*)\}\s*,\s*" + + "\{([^,\}]*),([^,\}]*)\}\s*,\s*" + + "\{MACRO_COLOR_FLAG\(([^,\}]*),([^,\}]*),([^,\}]*),([^,\}])*\),([^,\}]*)\}\s*" + + "\}", + ][0] + def parseCourseVtx(path: str, f3d): data = readFile(path) @@ -35,6 +37,7 @@ def parseCourseVtx(path: str, f3d): ) return vertexData + def getVertexDataStart(vertexDataParam: str, f3d: F3D): matchResult = re.search(r"\&?([A-Za-z0-9\_]*)\s*(\[([^\]]*)\])?\s*(\+(.*))?", vertexDataParam) if matchResult is None: @@ -45,14 +48,15 @@ def getVertexDataStart(vertexDataParam: str, f3d: F3D): offset += math_eval(matchResult.group(3), f3d) if matchResult.group(5): offset += math_eval(matchResult.group(5), f3d) - + name = matchResult.group(1) if matchResult.group(1).startswith("0x04"): - offset = (int(matchResult.group(1), 16) - 0x04000000)//16 + offset = (int(matchResult.group(1), 16) - 0x04000000) // 16 name = hex(0x04000000) return name, offset + def processCommands(self, dlData: str, dlName: str, dlCommands: "list[ParsedMacro]"): callStack = [F3DParsedCommands(dlName, dlCommands, 0)] while len(callStack) > 0: diff --git a/fast64_internal/panels.py b/fast64_internal/panels.py index c58c0a5d6..15776a81b 100644 --- a/fast64_internal/panels.py +++ b/fast64_internal/panels.py @@ -46,7 +46,8 @@ class OOT_Panel(bpy.types.Panel): @classmethod def poll(cls, context): return context.scene.gameEditorMode == "OOT" - + + class MK64_Panel(bpy.types.Panel): bl_space_type = "VIEW_3D" bl_region_type = "UI" From fe59e90ace71a34fef59cb61051fd73a096b3c74 Mon Sep 17 00:00:00 2001 From: coco875 <59367621+coco875@users.noreply.github.com> Date: Thu, 29 Feb 2024 16:24:38 +0100 Subject: [PATCH 06/46] Update fast64_internal/mk64/__init__.py Co-authored-by: Dragorn421 --- fast64_internal/mk64/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fast64_internal/mk64/__init__.py b/fast64_internal/mk64/__init__.py index 613664cba..9fc5fc92e 100644 --- a/fast64_internal/mk64/__init__.py +++ b/fast64_internal/mk64/__init__.py @@ -20,7 +20,7 @@ class MK64_Properties(PropertyGroup): class MK64_ImportCourseDL(bpy.types.Operator): # set bl_ properties - bl_idname = "object.f3d_course_import_dl" + bl_idname = "object.fast64_mk64_course_import_dl" bl_label = "Import Course DL" bl_options = {"REGISTER", "UNDO", "PRESET"} From 230cd6facfc56f04f398184b0c9636176107730f Mon Sep 17 00:00:00 2001 From: coco875 <59367621+coco875@users.noreply.github.com> Date: Thu, 29 Feb 2024 16:27:52 +0100 Subject: [PATCH 07/46] Update fast64_internal/mk64/f3d_course_parser.py Co-authored-by: Dragorn421 --- fast64_internal/mk64/f3d_course_parser.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/fast64_internal/mk64/f3d_course_parser.py b/fast64_internal/mk64/f3d_course_parser.py index 1d613c019..a9a2b3afe 100644 --- a/fast64_internal/mk64/f3d_course_parser.py +++ b/fast64_internal/mk64/f3d_course_parser.py @@ -10,14 +10,14 @@ def courseVertexFormatPatterns(): # position, uv, color/normal - return [ + return ( # decomp format - "\{\s*" - + "\{+([^,\}]*),([^,\}]*),([^,\}]*)\}\s*,\s*" - + "\{([^,\}]*),([^,\}]*)\}\s*,\s*" - + "\{MACRO_COLOR_FLAG\(([^,\}]*),([^,\}]*),([^,\}]*),([^,\}])*\),([^,\}]*)\}\s*" - + "\}", - ][0] + r"\{\s*" + r"\{+([^,\}]*),([^,\}]*),([^,\}]*)\}\s*,\s*" + r"\{([^,\}]*),([^,\}]*)\}\s*,\s*" + r"\{MACRO_COLOR_FLAG\(([^,\}]*),([^,\}]*),([^,\}]*),([^,\}])*\),([^,\}]*)\}\s*" + r"\}" + ) def parseCourseVtx(path: str, f3d): From a8eac6a7a5999bed3cd8f2e31df9cf580e5f090c Mon Sep 17 00:00:00 2001 From: coco875 Date: Thu, 29 Feb 2024 16:42:37 +0100 Subject: [PATCH 08/46] create MK64F3DContext class --- fast64_internal/mk64/__init__.py | 9 +- fast64_internal/mk64/f3d_course_parser.py | 560 +++++++++++----------- 2 files changed, 283 insertions(+), 286 deletions(-) diff --git a/fast64_internal/mk64/__init__.py b/fast64_internal/mk64/__init__.py index 613664cba..aff645094 100644 --- a/fast64_internal/mk64/__init__.py +++ b/fast64_internal/mk64/__init__.py @@ -1,15 +1,13 @@ -import math import bpy from bpy_types import PropertyGroup -import mathutils from ..f3d.f3d_gbi import get_F3D_GBI from ..f3d.f3d_material import createF3DMat -from ..f3d.f3d_parser import F3DContext, getImportData, importMeshC +from ..f3d.f3d_parser import getImportData, importMeshC from ..panels import MK64_Panel from ..utility import prop_split from bpy.utils import register_class, unregister_class from ..utility import raisePluginError -from .f3d_course_parser import processCommands, parseCourseVtx +from .f3d_course_parser import MK64F3DContext, parseCourseVtx class MK64_Properties(PropertyGroup): @@ -54,14 +52,13 @@ def execute(self, context): data = getImportData(paths) - f3d_context = F3DContext(get_F3D_GBI(), basePath, createF3DMat(None)) + f3d_context = MK64F3DContext(get_F3D_GBI(), basePath, createF3DMat(None)) if "course_displaylists" in importPath or "course_data" in importPath: vertexPath = importPath.replace("course_displaylists", "course_vertices").replace( "course_data", "course_vertices" ) print(vertexPath) f3d_context.vertexData["0x4000000"] = parseCourseVtx(vertexPath, f3d_context.f3d) - f3d_context.processCommands = processCommands.__get__(f3d_context, F3DContext) importMeshC( data, diff --git a/fast64_internal/mk64/f3d_course_parser.py b/fast64_internal/mk64/f3d_course_parser.py index 1d613c019..665defe15 100644 --- a/fast64_internal/mk64/f3d_course_parser.py +++ b/fast64_internal/mk64/f3d_course_parser.py @@ -38,301 +38,301 @@ def parseCourseVtx(path: str, f3d): return vertexData -def getVertexDataStart(vertexDataParam: str, f3d: F3D): - matchResult = re.search(r"\&?([A-Za-z0-9\_]*)\s*(\[([^\]]*)\])?\s*(\+(.*))?", vertexDataParam) - if matchResult is None: - raise PluginError("SPVertex param " + vertexDataParam + " is malformed.") +class MK64F3DContext: + def getVertexDataStart(vertexDataParam: str, f3d: F3D): + matchResult = re.search(r"\&?([A-Za-z0-9\_]*)\s*(\[([^\]]*)\])?\s*(\+(.*))?", vertexDataParam) + if matchResult is None: + raise PluginError("SPVertex param " + vertexDataParam + " is malformed.") - offset = 0 - if matchResult.group(3): - offset += math_eval(matchResult.group(3), f3d) - if matchResult.group(5): - offset += math_eval(matchResult.group(5), f3d) + offset = 0 + if matchResult.group(3): + offset += math_eval(matchResult.group(3), f3d) + if matchResult.group(5): + offset += math_eval(matchResult.group(5), f3d) - name = matchResult.group(1) + name = matchResult.group(1) - if matchResult.group(1).startswith("0x04"): - offset = (int(matchResult.group(1), 16) - 0x04000000) // 16 - name = hex(0x04000000) - return name, offset + if matchResult.group(1).startswith("0x04"): + offset = (int(matchResult.group(1), 16) - 0x04000000) // 16 + name = hex(0x04000000) + return name, offset + def processCommands(self, dlData: str, dlName: str, dlCommands: "list[ParsedMacro]"): + callStack = [F3DParsedCommands(dlName, dlCommands, 0)] + while len(callStack) > 0: + currentCommandList = callStack[-1] + command = currentCommandList.currentCommand() -def processCommands(self, dlData: str, dlName: str, dlCommands: "list[ParsedMacro]"): - callStack = [F3DParsedCommands(dlName, dlCommands, 0)] - while len(callStack) > 0: - currentCommandList = callStack[-1] - command = currentCommandList.currentCommand() + if currentCommandList.index >= len(currentCommandList.commands): + raise PluginError("Cannot handle unterminated static display lists: " + currentCommandList.name) + elif len(callStack) > 2**16: + raise PluginError("DL call stack larger than 2**16, assuming infinite loop: " + currentCommandList.name) - if currentCommandList.index >= len(currentCommandList.commands): - raise PluginError("Cannot handle unterminated static display lists: " + currentCommandList.name) - elif len(callStack) > 2**16: - raise PluginError("DL call stack larger than 2**16, assuming infinite loop: " + currentCommandList.name) + # print(command.name + " " + str(command.params)) + if command.name == "gsSPVertex": + vertexDataName, vertexDataOffset = self.getVertexDataStart(command.params[0], self.f3d) + parseVertexData(dlData, vertexDataName, self) + self.addVertices(command.params[1], command.params[2], vertexDataName, vertexDataOffset) + elif command.name == "gsSPMatrix": + self.setCurrentTransform(command.params[0], command.params[1]) + elif command.name == "gsSPPopMatrix": + print("gsSPPopMatrix not handled.") + elif command.name == "gsSP1Triangle": + self.addTriangle(command.params[0:3], dlData) + elif command.name == "gsSP2Triangles": + self.addTriangle(command.params[0:3] + command.params[4:7], dlData) + elif command.name == "gsSPDisplayList" or command.name.startswith("gsSPBranch"): + newDLName = self.processDLName(command.params[0]) + if newDLName is not None: + newDLCommands = parseDLData(dlData, newDLName) + # Use -1 index so that it will be incremented to 0 at end of loop + parsedCommands = F3DParsedCommands(newDLName, newDLCommands, -1) + if command.name == "gsSPDisplayList": + callStack.append(parsedCommands) + elif command.name.startswith("gsSPBranch"): # TODO: Handle BranchZ? + callStack = callStack[:-1] + callStack.append(parsedCommands) + elif command.name == "gsSPEndDisplayList": + callStack = callStack[:-1] - # print(command.name + " " + str(command.params)) - if command.name == "gsSPVertex": - vertexDataName, vertexDataOffset = getVertexDataStart(command.params[0], self.f3d) - parseVertexData(dlData, vertexDataName, self) - self.addVertices(command.params[1], command.params[2], vertexDataName, vertexDataOffset) - elif command.name == "gsSPMatrix": - self.setCurrentTransform(command.params[0], command.params[1]) - elif command.name == "gsSPPopMatrix": - print("gsSPPopMatrix not handled.") - elif command.name == "gsSP1Triangle": - self.addTriangle(command.params[0:3], dlData) - elif command.name == "gsSP2Triangles": - self.addTriangle(command.params[0:3] + command.params[4:7], dlData) - elif command.name == "gsSPDisplayList" or command.name.startswith("gsSPBranch"): - newDLName = self.processDLName(command.params[0]) - if newDLName is not None: - newDLCommands = parseDLData(dlData, newDLName) - # Use -1 index so that it will be incremented to 0 at end of loop - parsedCommands = F3DParsedCommands(newDLName, newDLCommands, -1) - if command.name == "gsSPDisplayList": - callStack.append(parsedCommands) - elif command.name.startswith("gsSPBranch"): # TODO: Handle BranchZ? - callStack = callStack[:-1] - callStack.append(parsedCommands) - elif command.name == "gsSPEndDisplayList": - callStack = callStack[:-1] + # Should we parse commands into f3d_gbi classes? + # No, because some parsing involves reading C files, which is separate. - # Should we parse commands into f3d_gbi classes? - # No, because some parsing involves reading C files, which is separate. + # Assumes macros use variable names instead of values + mat = self.mat() + try: + # Material Specific Commands + materialNotChanged = False - # Assumes macros use variable names instead of values - mat = self.mat() - try: - # Material Specific Commands - materialNotChanged = False + rdp_settings: "RDPSettings" = mat.rdp_settings - rdp_settings: "RDPSettings" = mat.rdp_settings - - if command.name == "gsSPClipRatio": - rdp_settings.clip_ratio = math_eval(command.params[0], self.f3d) - elif command.name == "gsSPNumLights": - self.numLights = self.getLightCount(command.params[0]) - elif command.name == "gsSPLight": - self.setLight(dlData, command) - elif command.name == "gsSPLightColor": - self.setLightColor(dlData, command) - elif command.name[:13] == "gsSPSetLights": - self.setLights(dlData, command) - elif command.name == "gsSPAmbOcclusionAmb": - mat.ao_ambient = float_from_u16_str(command.params[0]) - mat.set_ao = True - elif command.name == "gsSPAmbOcclusionDir": - mat.ao_directional = float_from_u16_str(command.params[0]) - mat.set_ao = True - elif command.name == "gsSPAmbOcclusionPoint": - mat.ao_point = float_from_u16_str(command.params[0]) - mat.set_ao = True - elif command.name == "gsSPAmbOcclusionAmbDir": - mat.ao_ambient = float_from_u16_str(command.params[0]) - mat.ao_directional = float_from_u16_str(command.params[1]) - mat.set_ao = True - elif command.name == "gsSPAmbOcclusionDirPoint": - mat.ao_directional = float_from_u16_str(command.params[0]) - mat.ao_point = float_from_u16_str(command.params[1]) - mat.set_ao = True - elif command.name == "gsSPAmbOcclusion": - mat.ao_ambient = float_from_u16_str(command.params[0]) - mat.ao_directional = float_from_u16_str(command.params[1]) - mat.ao_point = float_from_u16_str(command.params[2]) - mat.set_ao = True - elif command.name == "gsSPFresnel": - scale = int_from_s16_str(command.params[0]) - offset = int_from_s16_str(command.params[1]) - dotMax = ((0x7F - offset) << 15) // scale - dotMin = ((0x00 - offset) << 15) // scale - mat.fresnel_hi = dotMax / float(0x7FFF) - mat.fresnel_lo = dotMin / float(0x7FFF) - mat.set_fresnel = True - elif command.name == "gsSPAttrOffsetST": - mat.attroffs_st = [ - int_from_s16_str(command.params[0]) / 32, - int_from_s16_str(command.params[1]) / 32, - ] - mat.set_attroffs_st = True - elif command.name == "gsSPAttrOffsetZ": - mat.attroffs_z = int_from_s16_str(command.params[0]) - mat.set_attroffs_z = True - elif command.name == "gsSPFogFactor": - pass - elif command.name == "gsSPFogPosition": - mat.fog_position = [math_eval(command.params[0], self.f3d), math_eval(command.params[1], self.f3d)] - mat.set_fog = True - elif command.name == "gsSPTexture" or command.name == "gsSPTextureL": - # scale_autoprop should always be false (set in init) - # This prevents issues with material caching where updating nodes on a material causes its key to change - if command.params[0] == 0xFFFF and command.params[1] == 0xFFFF: - mat.tex_scale = (1, 1) - else: - mat.tex_scale = [ - math_eval(command.params[0], self.f3d) / (2**16), - math_eval(command.params[1], self.f3d) / (2**16), + if command.name == "gsSPClipRatio": + rdp_settings.clip_ratio = math_eval(command.params[0], self.f3d) + elif command.name == "gsSPNumLights": + self.numLights = self.getLightCount(command.params[0]) + elif command.name == "gsSPLight": + self.setLight(dlData, command) + elif command.name == "gsSPLightColor": + self.setLightColor(dlData, command) + elif command.name[:13] == "gsSPSetLights": + self.setLights(dlData, command) + elif command.name == "gsSPAmbOcclusionAmb": + mat.ao_ambient = float_from_u16_str(command.params[0]) + mat.set_ao = True + elif command.name == "gsSPAmbOcclusionDir": + mat.ao_directional = float_from_u16_str(command.params[0]) + mat.set_ao = True + elif command.name == "gsSPAmbOcclusionPoint": + mat.ao_point = float_from_u16_str(command.params[0]) + mat.set_ao = True + elif command.name == "gsSPAmbOcclusionAmbDir": + mat.ao_ambient = float_from_u16_str(command.params[0]) + mat.ao_directional = float_from_u16_str(command.params[1]) + mat.set_ao = True + elif command.name == "gsSPAmbOcclusionDirPoint": + mat.ao_directional = float_from_u16_str(command.params[0]) + mat.ao_point = float_from_u16_str(command.params[1]) + mat.set_ao = True + elif command.name == "gsSPAmbOcclusion": + mat.ao_ambient = float_from_u16_str(command.params[0]) + mat.ao_directional = float_from_u16_str(command.params[1]) + mat.ao_point = float_from_u16_str(command.params[2]) + mat.set_ao = True + elif command.name == "gsSPFresnel": + scale = int_from_s16_str(command.params[0]) + offset = int_from_s16_str(command.params[1]) + dotMax = ((0x7F - offset) << 15) // scale + dotMin = ((0x00 - offset) << 15) // scale + mat.fresnel_hi = dotMax / float(0x7FFF) + mat.fresnel_lo = dotMin / float(0x7FFF) + mat.set_fresnel = True + elif command.name == "gsSPAttrOffsetST": + mat.attroffs_st = [ + int_from_s16_str(command.params[0]) / 32, + int_from_s16_str(command.params[1]) / 32, ] - # command.params[2] is "lod level", and for clarity we store this is the number of mipmapped textures (which is +1) - rdp_settings.num_textures_mipmapped = 1 + math_eval(command.params[2], self.f3d) - elif command.name == "gsSPSetGeometryMode": - self.setGeoFlags(command, True) - elif command.name == "gsSPClearGeometryMode": - self.setGeoFlags(command, False) - elif command.name == "gsSPLoadGeometryMode": - self.loadGeoFlags(command) - elif command.name == "gsSPSetOtherMode": - self.setOtherModeFlags(command) - elif command.name == "gsDPPipelineMode": - rdp_settings.g_mdsft_pipeline = command.params[0] - elif command.name == "gsDPSetCycleType": - rdp_settings.g_mdsft_cycletype = command.params[0] - elif command.name == "gsDPSetTexturePersp": - rdp_settings.g_mdsft_textpersp = command.params[0] - elif command.name == "gsDPSetTextureDetail": - rdp_settings.g_mdsft_textdetail = command.params[0] - elif command.name == "gsDPSetTextureLOD": - rdp_settings.g_mdsft_textlod = command.params[0] - elif command.name == "gsDPSetTextureLUT": - self.setTLUTMode(command.params[0]) - elif command.name == "gsDPSetTextureFilter": - rdp_settings.g_mdsft_text_filt = command.params[0] - elif command.name == "gsDPSetTextureConvert": - rdp_settings.g_mdsft_textconv = command.params[0] - elif command.name == "gsDPSetCombineKey": - rdp_settings.g_mdsft_combkey = command.params[0] - elif command.name == "gsDPSetColorDither": - rdp_settings.g_mdsft_color_dither = command.params[0] - elif command.name == "gsDPSetAlphaDither": - rdp_settings.g_mdsft_alpha_dither = command.params[0] - elif command.name == "gsDPSetAlphaCompare": - rdp_settings.g_mdsft_alpha_compare = command.params[0] - elif command.name == "gsDPSetDepthSource": - rdp_settings.g_mdsft_zsrcsel = command.params[0] - elif command.name == "gsDPSetRenderMode": - flags = math_eval(command.params[0] + " | " + command.params[1], self.f3d) - self.setRenderMode(flags) - elif command.name == "gsDPSetTextureImage": - # Are other params necessary? - # The params are set in SetTile commands. - self.currentTextureName = command.params[3] - elif command.name == "gsDPSetCombineMode": - self.setCombineMode(command) - elif command.name == "gsDPSetCombineLERP": - self.setCombineLerp(command.params[0:8], command.params[8:16]) - elif command.name == "gsDPSetEnvColor": - mat.env_color = self.gammaInverseParam(command.params) - mat.set_env = True - elif command.name == "gsDPSetBlendColor": - mat.blend_color = self.gammaInverseParam(command.params) - mat.set_blend = True - elif command.name == "gsDPSetFogColor": - mat.fog_color = self.gammaInverseParam(command.params) - mat.set_fog = True - elif command.name == "gsDPSetFillColor": - pass - elif command.name == "gsDPSetPrimDepth": - pass - elif command.name == "gsDPSetPrimColor": - mat.prim_lod_min = math_eval(command.params[0], self.f3d) / 255 - mat.prim_lod_frac = math_eval(command.params[1], self.f3d) / 255 - mat.prim_color = self.gammaInverseParam(command.params[2:6]) - mat.set_prim = True - elif command.name == "gsDPSetOtherMode": - print("gsDPSetOtherMode not handled.") - elif command.name == "DPSetConvert": - mat.set_k0_5 = True - for i in range(6): - setattr(mat, "k" + str(i), gammaInverseValue(math_eval(command.params[i], self.f3d) / 255)) - elif command.name == "DPSetKeyR": - mat.set_key = True - elif command.name == "DPSetKeyGB": - mat.set_key = True - else: - materialNotChanged = True + mat.set_attroffs_st = True + elif command.name == "gsSPAttrOffsetZ": + mat.attroffs_z = int_from_s16_str(command.params[0]) + mat.set_attroffs_z = True + elif command.name == "gsSPFogFactor": + pass + elif command.name == "gsSPFogPosition": + mat.fog_position = [math_eval(command.params[0], self.f3d), math_eval(command.params[1], self.f3d)] + mat.set_fog = True + elif command.name == "gsSPTexture" or command.name == "gsSPTextureL": + # scale_autoprop should always be false (set in init) + # This prevents issues with material caching where updating nodes on a material causes its key to change + if command.params[0] == 0xFFFF and command.params[1] == 0xFFFF: + mat.tex_scale = (1, 1) + else: + mat.tex_scale = [ + math_eval(command.params[0], self.f3d) / (2**16), + math_eval(command.params[1], self.f3d) / (2**16), + ] + # command.params[2] is "lod level", and for clarity we store this is the number of mipmapped textures (which is +1) + rdp_settings.num_textures_mipmapped = 1 + math_eval(command.params[2], self.f3d) + elif command.name == "gsSPSetGeometryMode": + self.setGeoFlags(command, True) + elif command.name == "gsSPClearGeometryMode": + self.setGeoFlags(command, False) + elif command.name == "gsSPLoadGeometryMode": + self.loadGeoFlags(command) + elif command.name == "gsSPSetOtherMode": + self.setOtherModeFlags(command) + elif command.name == "gsDPPipelineMode": + rdp_settings.g_mdsft_pipeline = command.params[0] + elif command.name == "gsDPSetCycleType": + rdp_settings.g_mdsft_cycletype = command.params[0] + elif command.name == "gsDPSetTexturePersp": + rdp_settings.g_mdsft_textpersp = command.params[0] + elif command.name == "gsDPSetTextureDetail": + rdp_settings.g_mdsft_textdetail = command.params[0] + elif command.name == "gsDPSetTextureLOD": + rdp_settings.g_mdsft_textlod = command.params[0] + elif command.name == "gsDPSetTextureLUT": + self.setTLUTMode(command.params[0]) + elif command.name == "gsDPSetTextureFilter": + rdp_settings.g_mdsft_text_filt = command.params[0] + elif command.name == "gsDPSetTextureConvert": + rdp_settings.g_mdsft_textconv = command.params[0] + elif command.name == "gsDPSetCombineKey": + rdp_settings.g_mdsft_combkey = command.params[0] + elif command.name == "gsDPSetColorDither": + rdp_settings.g_mdsft_color_dither = command.params[0] + elif command.name == "gsDPSetAlphaDither": + rdp_settings.g_mdsft_alpha_dither = command.params[0] + elif command.name == "gsDPSetAlphaCompare": + rdp_settings.g_mdsft_alpha_compare = command.params[0] + elif command.name == "gsDPSetDepthSource": + rdp_settings.g_mdsft_zsrcsel = command.params[0] + elif command.name == "gsDPSetRenderMode": + flags = math_eval(command.params[0] + " | " + command.params[1], self.f3d) + self.setRenderMode(flags) + elif command.name == "gsDPSetTextureImage": + # Are other params necessary? + # The params are set in SetTile commands. + self.currentTextureName = command.params[3] + elif command.name == "gsDPSetCombineMode": + self.setCombineMode(command) + elif command.name == "gsDPSetCombineLERP": + self.setCombineLerp(command.params[0:8], command.params[8:16]) + elif command.name == "gsDPSetEnvColor": + mat.env_color = self.gammaInverseParam(command.params) + mat.set_env = True + elif command.name == "gsDPSetBlendColor": + mat.blend_color = self.gammaInverseParam(command.params) + mat.set_blend = True + elif command.name == "gsDPSetFogColor": + mat.fog_color = self.gammaInverseParam(command.params) + mat.set_fog = True + elif command.name == "gsDPSetFillColor": + pass + elif command.name == "gsDPSetPrimDepth": + pass + elif command.name == "gsDPSetPrimColor": + mat.prim_lod_min = math_eval(command.params[0], self.f3d) / 255 + mat.prim_lod_frac = math_eval(command.params[1], self.f3d) / 255 + mat.prim_color = self.gammaInverseParam(command.params[2:6]) + mat.set_prim = True + elif command.name == "gsDPSetOtherMode": + print("gsDPSetOtherMode not handled.") + elif command.name == "DPSetConvert": + mat.set_k0_5 = True + for i in range(6): + setattr(mat, "k" + str(i), gammaInverseValue(math_eval(command.params[i], self.f3d) / 255)) + elif command.name == "DPSetKeyR": + mat.set_key = True + elif command.name == "DPSetKeyGB": + mat.set_key = True + else: + materialNotChanged = True - if not materialNotChanged: - self.materialChanged = True + if not materialNotChanged: + self.materialChanged = True - # Texture Commands - # Assume file texture load - # SetTextureImage -> Load command -> Set Tile (0 or 1) + # Texture Commands + # Assume file texture load + # SetTextureImage -> Load command -> Set Tile (0 or 1) - if command.name == "gsDPSetTileSize": - self.setTileSize(command.params) - elif command.name == "gsDPLoadTile": - self.loadTile(command.params) - elif command.name == "gsDPSetTile": - self.setTile(command.params, dlData) - elif command.name == "gsDPLoadBlock": - self.loadTile(command.params) - elif command.name == "gsDPLoadTLUTCmd": - self.loadTLUT(command.params, dlData) + if command.name == "gsDPSetTileSize": + self.setTileSize(command.params) + elif command.name == "gsDPLoadTile": + self.loadTile(command.params) + elif command.name == "gsDPSetTile": + self.setTile(command.params, dlData) + elif command.name == "gsDPLoadBlock": + self.loadTile(command.params) + elif command.name == "gsDPLoadTLUTCmd": + self.loadTLUT(command.params, dlData) - # This all ignores S/T high/low values - # This is pretty bad/confusing - elif command.name.startswith("gsDPLoadTextureBlock"): - is4bit = "4b" in command.name - if is4bit: - self.loadMultiBlock( - [command.params[0]] - + [0, "G_TX_RENDERTILE"] - + [command.params[1], "G_IM_SIZ_4b"] - + command.params[2:], - dlData, - True, - ) - else: - self.loadMultiBlock( - [command.params[0]] + [0, "G_TX_RENDERTILE"] + command.params[1:], dlData, False - ) - elif command.name.startswith("gsDPLoadMultiBlock"): - is4bit = "4b" in command.name - if is4bit: - self.loadMultiBlock(command.params[:4] + ["G_IM_SIZ_4b"] + command.params[4:], dlData, True) - else: - self.loadMultiBlock(command.params, dlData, False) - elif command.name.startswith("gsDPLoadTextureTile"): - is4bit = "4b" in command.name - if is4bit: - self.loadMultiBlock( - [command.params[0]] - + [0, "G_TX_RENDERTILE"] - + [command.params[1], "G_IM_SIZ_4b"] - + command.params[2:4] - + command.params[9:], - "4b", # FIXME extra argument? - dlData, - True, - ) - else: - self.loadMultiBlock( - [command.params[0]] + [0, "G_TX_RENDERTILE"] + command.params[1:5] + command.params[9:], - "4b", # FIXME extra argument? - dlData, - False, - ) - elif command.name.startswith("gsDPLoadMultiTile"): - is4bit = "4b" in command.name - if is4bit: - self.loadMultiBlock( - command.params[:4] + ["G_IM_SIZ_4b"] + command.params[4:6] + command.params[10:], - dlData, - True, - ) - else: - self.loadMultiBlock(command.params[:7] + command.params[11:], dlData, False) + # This all ignores S/T high/low values + # This is pretty bad/confusing + elif command.name.startswith("gsDPLoadTextureBlock"): + is4bit = "4b" in command.name + if is4bit: + self.loadMultiBlock( + [command.params[0]] + + [0, "G_TX_RENDERTILE"] + + [command.params[1], "G_IM_SIZ_4b"] + + command.params[2:], + dlData, + True, + ) + else: + self.loadMultiBlock( + [command.params[0]] + [0, "G_TX_RENDERTILE"] + command.params[1:], dlData, False + ) + elif command.name.startswith("gsDPLoadMultiBlock"): + is4bit = "4b" in command.name + if is4bit: + self.loadMultiBlock(command.params[:4] + ["G_IM_SIZ_4b"] + command.params[4:], dlData, True) + else: + self.loadMultiBlock(command.params, dlData, False) + elif command.name.startswith("gsDPLoadTextureTile"): + is4bit = "4b" in command.name + if is4bit: + self.loadMultiBlock( + [command.params[0]] + + [0, "G_TX_RENDERTILE"] + + [command.params[1], "G_IM_SIZ_4b"] + + command.params[2:4] + + command.params[9:], + "4b", # FIXME extra argument? + dlData, + True, + ) + else: + self.loadMultiBlock( + [command.params[0]] + [0, "G_TX_RENDERTILE"] + command.params[1:5] + command.params[9:], + "4b", # FIXME extra argument? + dlData, + False, + ) + elif command.name.startswith("gsDPLoadMultiTile"): + is4bit = "4b" in command.name + if is4bit: + self.loadMultiBlock( + command.params[:4] + ["G_IM_SIZ_4b"] + command.params[4:6] + command.params[10:], + dlData, + True, + ) + else: + self.loadMultiBlock(command.params[:7] + command.params[11:], dlData, False) - # TODO: Only handles palettes at tmem = 256 - elif command.name == "gsDPLoadTLUT_pal16": - self.loadTLUTPal(command.params[1], dlData, 15) - elif command.name == "gsDPLoadTLUT_pal256": - self.loadTLUTPal(command.params[0], dlData, 255) - else: - pass + # TODO: Only handles palettes at tmem = 256 + elif command.name == "gsDPLoadTLUT_pal16": + self.loadTLUTPal(command.params[1], dlData, 15) + elif command.name == "gsDPLoadTLUT_pal256": + self.loadTLUTPal(command.params[0], dlData, 255) + else: + pass - except TypeError as e: - print(traceback.format_exc()) - # raise Exception(e) - # print(e) + except TypeError as e: + print(traceback.format_exc()) + # raise Exception(e) + # print(e) - # Don't use currentCommandList because some commands may change that - if len(callStack) > 0: - callStack[-1].index += 1 + # Don't use currentCommandList because some commands may change that + if len(callStack) > 0: + callStack[-1].index += 1 From dfb910bee198185631f9b9624d62c0482989f13b Mon Sep 17 00:00:00 2001 From: coco875 Date: Thu, 29 Feb 2024 17:01:01 +0100 Subject: [PATCH 09/46] ok add a mk64/README.md and add getVertexDataStart as a method of F3DContext --- fast64_internal/f3d/f3d_parser.py | 29 ++- fast64_internal/mk64/README.md | 9 + fast64_internal/mk64/f3d_course_parser.py | 284 +--------------------- 3 files changed, 25 insertions(+), 297 deletions(-) create mode 100644 fast64_internal/mk64/README.md diff --git a/fast64_internal/f3d/f3d_parser.py b/fast64_internal/f3d/f3d_parser.py index fc8231488..16fccd939 100644 --- a/fast64_internal/f3d/f3d_parser.py +++ b/fast64_internal/f3d/f3d_parser.py @@ -1527,6 +1527,19 @@ def applyTLUT(self, image, tlut): if invalidIndicesDetected: print("Invalid LUT Indices detected.") + def getVertexDataStart(self, vertexDataParam: str, f3d: F3D): + matchResult = re.search(r"\&?([A-Za-z0-9\_]*)\s*(\[([^\]]*)\])?\s*(\+(.*))?", vertexDataParam) + if matchResult is None: + raise PluginError("SPVertex param " + vertexDataParam + " is malformed.") + + offset = 0 + if matchResult.group(3): + offset += math_eval(matchResult.group(3), f3d) + if matchResult.group(5): + offset += math_eval(matchResult.group(5), f3d) + + return matchResult.group(1), offset + def processCommands(self, dlData: str, dlName: str, dlCommands: "list[ParsedMacro]"): callStack = [F3DParsedCommands(dlName, dlCommands, 0)] while len(callStack) > 0: @@ -1540,7 +1553,7 @@ def processCommands(self, dlData: str, dlName: str, dlCommands: "list[ParsedMacr # print(command.name + " " + str(command.params)) if command.name == "gsSPVertex": - vertexDataName, vertexDataOffset = getVertexDataStart(command.params[0], self.f3d) + vertexDataName, vertexDataOffset = self.getVertexDataStart(command.params[0], self.f3d) parseVertexData(dlData, vertexDataName, self) self.addVertices(command.params[1], command.params[2], vertexDataName, vertexDataOffset) elif command.name == "gsSPMatrix": @@ -1949,20 +1962,6 @@ def parseDLData(dlData: str, dlName: str): return dlCommands -def getVertexDataStart(vertexDataParam: str, f3d: F3D): - matchResult = re.search(r"\&?([A-Za-z0-9\_]*)\s*(\[([^\]]*)\])?\s*(\+(.*))?", vertexDataParam) - if matchResult is None: - raise PluginError("SPVertex param " + vertexDataParam + " is malformed.") - - offset = 0 - if matchResult.group(3): - offset += math_eval(matchResult.group(3), f3d) - if matchResult.group(5): - offset += math_eval(matchResult.group(5), f3d) - - return matchResult.group(1), offset - - def parseVertexData(dlData: str, vertexDataName: str, f3dContext: F3DContext): if vertexDataName in f3dContext.vertexData: return f3dContext.vertexData[vertexDataName] diff --git a/fast64_internal/mk64/README.md b/fast64_internal/mk64/README.md new file mode 100644 index 000000000..0a50b047f --- /dev/null +++ b/fast64_internal/mk64/README.md @@ -0,0 +1,9 @@ +# Mario Kart 64 + +## Importing Course +It's similar to F3D Importer, you select the file where you have the display list, the name of the display list you want to import and the path to the decomp. (by default course are cut as segment so it's better to use cinematic version who have all, it's in general the last display variable in course_data.inc.c). + +Example of configuration: +- d_course_wario_stadium_dl_CA78 +- path/to/mk64/courses/wario_stadium/course_data.inc.c +- path/to/mk64 \ No newline at end of file diff --git a/fast64_internal/mk64/f3d_course_parser.py b/fast64_internal/mk64/f3d_course_parser.py index 19d342522..880d922dd 100644 --- a/fast64_internal/mk64/f3d_course_parser.py +++ b/fast64_internal/mk64/f3d_course_parser.py @@ -3,7 +3,7 @@ from mathutils import Vector from ..f3d.f3d_gbi import F3D from ..f3d.f3d_material import RDPSettings -from ..f3d.f3d_parser import F3DParsedCommands, ParsedMacro, math_eval, parseDLData, parseVertexData +from ..f3d.f3d_parser import F3DContext, F3DParsedCommands, ParsedMacro, math_eval, parseDLData, parseVertexData from ..f3d.f3d_writer import F3DVert from ..utility import PluginError, float_from_u16_str, gammaInverseValue, int_from_s16_str, readFile, unpackNormal @@ -38,7 +38,7 @@ def parseCourseVtx(path: str, f3d): return vertexData -class MK64F3DContext: +class MK64F3DContext(F3DContext): def getVertexDataStart(vertexDataParam: str, f3d: F3D): matchResult = re.search(r"\&?([A-Za-z0-9\_]*)\s*(\[([^\]]*)\])?\s*(\+(.*))?", vertexDataParam) if matchResult is None: @@ -56,283 +56,3 @@ def getVertexDataStart(vertexDataParam: str, f3d: F3D): offset = (int(matchResult.group(1), 16) - 0x04000000) // 16 name = hex(0x04000000) return name, offset - - def processCommands(self, dlData: str, dlName: str, dlCommands: "list[ParsedMacro]"): - callStack = [F3DParsedCommands(dlName, dlCommands, 0)] - while len(callStack) > 0: - currentCommandList = callStack[-1] - command = currentCommandList.currentCommand() - - if currentCommandList.index >= len(currentCommandList.commands): - raise PluginError("Cannot handle unterminated static display lists: " + currentCommandList.name) - elif len(callStack) > 2**16: - raise PluginError("DL call stack larger than 2**16, assuming infinite loop: " + currentCommandList.name) - - # print(command.name + " " + str(command.params)) - if command.name == "gsSPVertex": - vertexDataName, vertexDataOffset = self.getVertexDataStart(command.params[0], self.f3d) - parseVertexData(dlData, vertexDataName, self) - self.addVertices(command.params[1], command.params[2], vertexDataName, vertexDataOffset) - elif command.name == "gsSPMatrix": - self.setCurrentTransform(command.params[0], command.params[1]) - elif command.name == "gsSPPopMatrix": - print("gsSPPopMatrix not handled.") - elif command.name == "gsSP1Triangle": - self.addTriangle(command.params[0:3], dlData) - elif command.name == "gsSP2Triangles": - self.addTriangle(command.params[0:3] + command.params[4:7], dlData) - elif command.name == "gsSPDisplayList" or command.name.startswith("gsSPBranch"): - newDLName = self.processDLName(command.params[0]) - if newDLName is not None: - newDLCommands = parseDLData(dlData, newDLName) - # Use -1 index so that it will be incremented to 0 at end of loop - parsedCommands = F3DParsedCommands(newDLName, newDLCommands, -1) - if command.name == "gsSPDisplayList": - callStack.append(parsedCommands) - elif command.name.startswith("gsSPBranch"): # TODO: Handle BranchZ? - callStack = callStack[:-1] - callStack.append(parsedCommands) - elif command.name == "gsSPEndDisplayList": - callStack = callStack[:-1] - - # Should we parse commands into f3d_gbi classes? - # No, because some parsing involves reading C files, which is separate. - - # Assumes macros use variable names instead of values - mat = self.mat() - try: - # Material Specific Commands - materialNotChanged = False - - rdp_settings: "RDPSettings" = mat.rdp_settings - - if command.name == "gsSPClipRatio": - rdp_settings.clip_ratio = math_eval(command.params[0], self.f3d) - elif command.name == "gsSPNumLights": - self.numLights = self.getLightCount(command.params[0]) - elif command.name == "gsSPLight": - self.setLight(dlData, command) - elif command.name == "gsSPLightColor": - self.setLightColor(dlData, command) - elif command.name[:13] == "gsSPSetLights": - self.setLights(dlData, command) - elif command.name == "gsSPAmbOcclusionAmb": - mat.ao_ambient = float_from_u16_str(command.params[0]) - mat.set_ao = True - elif command.name == "gsSPAmbOcclusionDir": - mat.ao_directional = float_from_u16_str(command.params[0]) - mat.set_ao = True - elif command.name == "gsSPAmbOcclusionPoint": - mat.ao_point = float_from_u16_str(command.params[0]) - mat.set_ao = True - elif command.name == "gsSPAmbOcclusionAmbDir": - mat.ao_ambient = float_from_u16_str(command.params[0]) - mat.ao_directional = float_from_u16_str(command.params[1]) - mat.set_ao = True - elif command.name == "gsSPAmbOcclusionDirPoint": - mat.ao_directional = float_from_u16_str(command.params[0]) - mat.ao_point = float_from_u16_str(command.params[1]) - mat.set_ao = True - elif command.name == "gsSPAmbOcclusion": - mat.ao_ambient = float_from_u16_str(command.params[0]) - mat.ao_directional = float_from_u16_str(command.params[1]) - mat.ao_point = float_from_u16_str(command.params[2]) - mat.set_ao = True - elif command.name == "gsSPFresnel": - scale = int_from_s16_str(command.params[0]) - offset = int_from_s16_str(command.params[1]) - dotMax = ((0x7F - offset) << 15) // scale - dotMin = ((0x00 - offset) << 15) // scale - mat.fresnel_hi = dotMax / float(0x7FFF) - mat.fresnel_lo = dotMin / float(0x7FFF) - mat.set_fresnel = True - elif command.name == "gsSPAttrOffsetST": - mat.attroffs_st = [ - int_from_s16_str(command.params[0]) / 32, - int_from_s16_str(command.params[1]) / 32, - ] - mat.set_attroffs_st = True - elif command.name == "gsSPAttrOffsetZ": - mat.attroffs_z = int_from_s16_str(command.params[0]) - mat.set_attroffs_z = True - elif command.name == "gsSPFogFactor": - pass - elif command.name == "gsSPFogPosition": - mat.fog_position = [math_eval(command.params[0], self.f3d), math_eval(command.params[1], self.f3d)] - mat.set_fog = True - elif command.name == "gsSPTexture" or command.name == "gsSPTextureL": - # scale_autoprop should always be false (set in init) - # This prevents issues with material caching where updating nodes on a material causes its key to change - if command.params[0] == 0xFFFF and command.params[1] == 0xFFFF: - mat.tex_scale = (1, 1) - else: - mat.tex_scale = [ - math_eval(command.params[0], self.f3d) / (2**16), - math_eval(command.params[1], self.f3d) / (2**16), - ] - # command.params[2] is "lod level", and for clarity we store this is the number of mipmapped textures (which is +1) - rdp_settings.num_textures_mipmapped = 1 + math_eval(command.params[2], self.f3d) - elif command.name == "gsSPSetGeometryMode": - self.setGeoFlags(command, True) - elif command.name == "gsSPClearGeometryMode": - self.setGeoFlags(command, False) - elif command.name == "gsSPLoadGeometryMode": - self.loadGeoFlags(command) - elif command.name == "gsSPSetOtherMode": - self.setOtherModeFlags(command) - elif command.name == "gsDPPipelineMode": - rdp_settings.g_mdsft_pipeline = command.params[0] - elif command.name == "gsDPSetCycleType": - rdp_settings.g_mdsft_cycletype = command.params[0] - elif command.name == "gsDPSetTexturePersp": - rdp_settings.g_mdsft_textpersp = command.params[0] - elif command.name == "gsDPSetTextureDetail": - rdp_settings.g_mdsft_textdetail = command.params[0] - elif command.name == "gsDPSetTextureLOD": - rdp_settings.g_mdsft_textlod = command.params[0] - elif command.name == "gsDPSetTextureLUT": - self.setTLUTMode(command.params[0]) - elif command.name == "gsDPSetTextureFilter": - rdp_settings.g_mdsft_text_filt = command.params[0] - elif command.name == "gsDPSetTextureConvert": - rdp_settings.g_mdsft_textconv = command.params[0] - elif command.name == "gsDPSetCombineKey": - rdp_settings.g_mdsft_combkey = command.params[0] - elif command.name == "gsDPSetColorDither": - rdp_settings.g_mdsft_color_dither = command.params[0] - elif command.name == "gsDPSetAlphaDither": - rdp_settings.g_mdsft_alpha_dither = command.params[0] - elif command.name == "gsDPSetAlphaCompare": - rdp_settings.g_mdsft_alpha_compare = command.params[0] - elif command.name == "gsDPSetDepthSource": - rdp_settings.g_mdsft_zsrcsel = command.params[0] - elif command.name == "gsDPSetRenderMode": - flags = math_eval(command.params[0] + " | " + command.params[1], self.f3d) - self.setRenderMode(flags) - elif command.name == "gsDPSetTextureImage": - # Are other params necessary? - # The params are set in SetTile commands. - self.currentTextureName = command.params[3] - elif command.name == "gsDPSetCombineMode": - self.setCombineMode(command) - elif command.name == "gsDPSetCombineLERP": - self.setCombineLerp(command.params[0:8], command.params[8:16]) - elif command.name == "gsDPSetEnvColor": - mat.env_color = self.gammaInverseParam(command.params) - mat.set_env = True - elif command.name == "gsDPSetBlendColor": - mat.blend_color = self.gammaInverseParam(command.params) - mat.set_blend = True - elif command.name == "gsDPSetFogColor": - mat.fog_color = self.gammaInverseParam(command.params) - mat.set_fog = True - elif command.name == "gsDPSetFillColor": - pass - elif command.name == "gsDPSetPrimDepth": - pass - elif command.name == "gsDPSetPrimColor": - mat.prim_lod_min = math_eval(command.params[0], self.f3d) / 255 - mat.prim_lod_frac = math_eval(command.params[1], self.f3d) / 255 - mat.prim_color = self.gammaInverseParam(command.params[2:6]) - mat.set_prim = True - elif command.name == "gsDPSetOtherMode": - print("gsDPSetOtherMode not handled.") - elif command.name == "DPSetConvert": - mat.set_k0_5 = True - for i in range(6): - setattr(mat, "k" + str(i), gammaInverseValue(math_eval(command.params[i], self.f3d) / 255)) - elif command.name == "DPSetKeyR": - mat.set_key = True - elif command.name == "DPSetKeyGB": - mat.set_key = True - else: - materialNotChanged = True - - if not materialNotChanged: - self.materialChanged = True - - # Texture Commands - # Assume file texture load - # SetTextureImage -> Load command -> Set Tile (0 or 1) - - if command.name == "gsDPSetTileSize": - self.setTileSize(command.params) - elif command.name == "gsDPLoadTile": - self.loadTile(command.params) - elif command.name == "gsDPSetTile": - self.setTile(command.params, dlData) - elif command.name == "gsDPLoadBlock": - self.loadTile(command.params) - elif command.name == "gsDPLoadTLUTCmd": - self.loadTLUT(command.params, dlData) - - # This all ignores S/T high/low values - # This is pretty bad/confusing - elif command.name.startswith("gsDPLoadTextureBlock"): - is4bit = "4b" in command.name - if is4bit: - self.loadMultiBlock( - [command.params[0]] - + [0, "G_TX_RENDERTILE"] - + [command.params[1], "G_IM_SIZ_4b"] - + command.params[2:], - dlData, - True, - ) - else: - self.loadMultiBlock( - [command.params[0]] + [0, "G_TX_RENDERTILE"] + command.params[1:], dlData, False - ) - elif command.name.startswith("gsDPLoadMultiBlock"): - is4bit = "4b" in command.name - if is4bit: - self.loadMultiBlock(command.params[:4] + ["G_IM_SIZ_4b"] + command.params[4:], dlData, True) - else: - self.loadMultiBlock(command.params, dlData, False) - elif command.name.startswith("gsDPLoadTextureTile"): - is4bit = "4b" in command.name - if is4bit: - self.loadMultiBlock( - [command.params[0]] - + [0, "G_TX_RENDERTILE"] - + [command.params[1], "G_IM_SIZ_4b"] - + command.params[2:4] - + command.params[9:], - "4b", # FIXME extra argument? - dlData, - True, - ) - else: - self.loadMultiBlock( - [command.params[0]] + [0, "G_TX_RENDERTILE"] + command.params[1:5] + command.params[9:], - "4b", # FIXME extra argument? - dlData, - False, - ) - elif command.name.startswith("gsDPLoadMultiTile"): - is4bit = "4b" in command.name - if is4bit: - self.loadMultiBlock( - command.params[:4] + ["G_IM_SIZ_4b"] + command.params[4:6] + command.params[10:], - dlData, - True, - ) - else: - self.loadMultiBlock(command.params[:7] + command.params[11:], dlData, False) - - # TODO: Only handles palettes at tmem = 256 - elif command.name == "gsDPLoadTLUT_pal16": - self.loadTLUTPal(command.params[1], dlData, 15) - elif command.name == "gsDPLoadTLUT_pal256": - self.loadTLUTPal(command.params[0], dlData, 255) - else: - pass - - except TypeError as e: - print(traceback.format_exc()) - # raise Exception(e) - # print(e) - - # Don't use currentCommandList because some commands may change that - if len(callStack) > 0: - callStack[-1].index += 1 From 955e8e12cb568f10f41c8ae4e0eddfa6cfc4ec66 Mon Sep 17 00:00:00 2001 From: coco875 <59367621+coco875@users.noreply.github.com> Date: Thu, 29 Feb 2024 17:11:34 +0100 Subject: [PATCH 10/46] Update fast64_internal/mk64/__init__.py Co-authored-by: Dragorn421 --- fast64_internal/mk64/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fast64_internal/mk64/__init__.py b/fast64_internal/mk64/__init__.py index 99588e610..176df01e3 100644 --- a/fast64_internal/mk64/__init__.py +++ b/fast64_internal/mk64/__init__.py @@ -1,5 +1,5 @@ import bpy -from bpy_types import PropertyGroup +from bpy.types import PropertyGroup from ..f3d.f3d_gbi import get_F3D_GBI from ..f3d.f3d_material import createF3DMat from ..f3d.f3d_parser import getImportData, importMeshC From 0ebed4793e4db3d8c10f90706b6df2157ac43c4d Mon Sep 17 00:00:00 2001 From: coco875 Date: Thu, 29 Feb 2024 17:17:26 +0100 Subject: [PATCH 11/46] add upgrade_changed_props --- __init__.py | 1 + fast64_internal/mk64/__init__.py | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/__init__.py b/__init__.py index 20d9e3e49..9b5dcc0b0 100644 --- a/__init__.py +++ b/__init__.py @@ -389,6 +389,7 @@ def draw(self, context): def upgrade_changed_props(): """Set scene properties after a scene loads, used for migrating old properties""" SM64_Properties.upgrade_changed_props() + MK64_Properties.upgrade_changed_props() SM64_ObjectProperties.upgrade_changed_props() OOT_ObjectProperties.upgrade_changed_props() diff --git a/fast64_internal/mk64/__init__.py b/fast64_internal/mk64/__init__.py index 99588e610..963c3cbd8 100644 --- a/fast64_internal/mk64/__init__.py +++ b/fast64_internal/mk64/__init__.py @@ -14,6 +14,12 @@ class MK64_Properties(PropertyGroup): """Global MK64 Scene Properties found under scene.fast64.mk64""" version: bpy.props.IntProperty(name="MK64_Properties Version", default=0) + cur_version = 0 + + @staticmethod + def upgrade_changed_props(): + if bpy.context.scene.fast64.mk64.version != MK64_Properties.cur_version: + bpy.context.scene.fast64.mk64.version = MK64_Properties.cur_version class MK64_ImportCourseDL(bpy.types.Operator): From ee38f20ab1cfbe460fbdf07856b5714a0b229f6e Mon Sep 17 00:00:00 2001 From: coco875 Date: Thu, 29 Feb 2024 17:21:49 +0100 Subject: [PATCH 12/46] fix poll --- fast64_internal/mk64/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fast64_internal/mk64/__init__.py b/fast64_internal/mk64/__init__.py index b2cd16cf4..1aff14f34 100644 --- a/fast64_internal/mk64/__init__.py +++ b/fast64_internal/mk64/__init__.py @@ -94,7 +94,7 @@ class MK64_ImportCourseDLPanel(MK64_Panel): @classmethod def poll(cls, context): - return True + return context.scene.gameEditorMode == "SM64" # called every frame def draw(self, context): From bd0cea7ad00134ab6973f1afc1a7f23ab4646eb8 Mon Sep 17 00:00:00 2001 From: coco875 Date: Thu, 29 Feb 2024 21:42:30 +0100 Subject: [PATCH 13/46] fix a bug and a error --- fast64_internal/mk64/__init__.py | 2 +- fast64_internal/mk64/f3d_course_parser.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fast64_internal/mk64/__init__.py b/fast64_internal/mk64/__init__.py index 1aff14f34..e54fac0e6 100644 --- a/fast64_internal/mk64/__init__.py +++ b/fast64_internal/mk64/__init__.py @@ -94,7 +94,7 @@ class MK64_ImportCourseDLPanel(MK64_Panel): @classmethod def poll(cls, context): - return context.scene.gameEditorMode == "SM64" + return context.scene.gameEditorMode == "MK64" # called every frame def draw(self, context): diff --git a/fast64_internal/mk64/f3d_course_parser.py b/fast64_internal/mk64/f3d_course_parser.py index 880d922dd..cf9f65c6c 100644 --- a/fast64_internal/mk64/f3d_course_parser.py +++ b/fast64_internal/mk64/f3d_course_parser.py @@ -39,7 +39,7 @@ def parseCourseVtx(path: str, f3d): class MK64F3DContext(F3DContext): - def getVertexDataStart(vertexDataParam: str, f3d: F3D): + def getVertexDataStart(self, vertexDataParam: str, f3d: F3D): matchResult = re.search(r"\&?([A-Za-z0-9\_]*)\s*(\[([^\]]*)\])?\s*(\+(.*))?", vertexDataParam) if matchResult is None: raise PluginError("SPVertex param " + vertexDataParam + " is malformed.") From 6d0c13b0a29aae55af7d405bbddc3eb3c01b6318 Mon Sep 17 00:00:00 2001 From: coco875 Date: Thu, 29 Feb 2024 21:57:19 +0100 Subject: [PATCH 14/46] remove poll from MK64_ImportCourseDLPanel --- fast64_internal/mk64/__init__.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/fast64_internal/mk64/__init__.py b/fast64_internal/mk64/__init__.py index e54fac0e6..86e0031a5 100644 --- a/fast64_internal/mk64/__init__.py +++ b/fast64_internal/mk64/__init__.py @@ -92,10 +92,6 @@ class MK64_ImportCourseDLPanel(MK64_Panel): bl_options = set() # default to open bl_order = 0 # force to front - @classmethod - def poll(cls, context): - return context.scene.gameEditorMode == "MK64" - # called every frame def draw(self, context): col = self.layout.column() From 4e77d46cb1dd0fa0f0e9e6d49875ea07b331b946 Mon Sep 17 00:00:00 2001 From: coco875 <59367621+coco875@users.noreply.github.com> Date: Sat, 2 Mar 2024 17:58:53 +0100 Subject: [PATCH 15/46] add the options to enable render mode for course --- fast64_internal/mk64/__init__.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/fast64_internal/mk64/__init__.py b/fast64_internal/mk64/__init__.py index 86e0031a5..54f59d83f 100644 --- a/fast64_internal/mk64/__init__.py +++ b/fast64_internal/mk64/__init__.py @@ -1,7 +1,7 @@ import bpy from bpy.types import PropertyGroup -from ..f3d.f3d_gbi import get_F3D_GBI from ..f3d.f3d_material import createF3DMat +from ..f3d.f3d_gbi import get_F3D_GBI from ..f3d.f3d_parser import getImportData, importMeshC from ..panels import MK64_Panel from ..utility import prop_split @@ -16,6 +16,9 @@ class MK64_Properties(PropertyGroup): version: bpy.props.IntProperty(name="MK64_Properties Version", default=0) cur_version = 0 + # Import Course DL + EnableRenderModeDefault: bpy.props.BoolProperty(name="Enable Render Mode by Default", default=True) + @staticmethod def upgrade_changed_props(): if bpy.context.scene.fast64.mk64.version != MK64_Properties.cur_version: @@ -58,7 +61,11 @@ def execute(self, context): data = getImportData(paths) - f3d_context = MK64F3DContext(get_F3D_GBI(), basePath, createF3DMat(None)) + material = createF3DMat(None) + + material.f3d_mat.rdp_settings.set_rendermode = context.scene.fast64.mk64.EnableRenderModeDefault + + f3d_context = MK64F3DContext(get_F3D_GBI(), basePath, material) if "course_displaylists" in importPath or "course_data" in importPath: vertexPath = importPath.replace("course_displaylists", "course_vertices").replace( "course_data", "course_vertices" @@ -106,6 +113,9 @@ def draw(self, context): col.prop(context.scene, "DLRemoveDoubles") col.prop(context.scene, "DLImportNormals") + mk64Props = context.scene.fast64.mk64 + prop_split(col, mk64Props, "EnableRenderModeDefault", "Enable Render Mode by Default") + box = col.box().column() box.label(text="All data must be contained within file.") box.label(text="The only exception are pngs converted to inc.c.") From a590c15f64718bdb0b8a77746fdaab6034cfa4e4 Mon Sep 17 00:00:00 2001 From: coco875 Date: Mon, 4 Mar 2024 17:01:41 +0100 Subject: [PATCH 16/46] fix too short argument not be parse --- fast64_internal/f3d/f3d_parser.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fast64_internal/f3d/f3d_parser.py b/fast64_internal/f3d/f3d_parser.py index 16fccd939..ca40115af 100644 --- a/fast64_internal/f3d/f3d_parser.py +++ b/fast64_internal/f3d/f3d_parser.py @@ -2222,6 +2222,9 @@ def parseMacroArgs(data: str): params.append(param) start = end + 1 + if len(data) == 1: + return [data] + return params From b3b916e596e65edbc551b145d7ba0ad78cb81eac Mon Sep 17 00:00:00 2001 From: coco875 <59367621+coco875@users.noreply.github.com> Date: Thu, 7 Mar 2024 16:25:27 +0100 Subject: [PATCH 17/46] change MK64_Properties --- fast64_internal/mk64/__init__.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/fast64_internal/mk64/__init__.py b/fast64_internal/mk64/__init__.py index 54f59d83f..0edd4cd69 100644 --- a/fast64_internal/mk64/__init__.py +++ b/fast64_internal/mk64/__init__.py @@ -12,17 +12,12 @@ class MK64_Properties(PropertyGroup): """Global MK64 Scene Properties found under scene.fast64.mk64""" - - version: bpy.props.IntProperty(name="MK64_Properties Version", default=0) - cur_version = 0 - # Import Course DL EnableRenderModeDefault: bpy.props.BoolProperty(name="Enable Render Mode by Default", default=True) @staticmethod def upgrade_changed_props(): - if bpy.context.scene.fast64.mk64.version != MK64_Properties.cur_version: - bpy.context.scene.fast64.mk64.version = MK64_Properties.cur_version + pass class MK64_ImportCourseDL(bpy.types.Operator): From bd9356196fb98a523f88b8c92f165ad3a0fb93ba Mon Sep 17 00:00:00 2001 From: coco875 <59367621+coco875@users.noreply.github.com> Date: Thu, 7 Mar 2024 16:28:22 +0100 Subject: [PATCH 18/46] Update f3d_parser.py --- fast64_internal/f3d/f3d_parser.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/fast64_internal/f3d/f3d_parser.py b/fast64_internal/f3d/f3d_parser.py index ca40115af..16fccd939 100644 --- a/fast64_internal/f3d/f3d_parser.py +++ b/fast64_internal/f3d/f3d_parser.py @@ -2222,9 +2222,6 @@ def parseMacroArgs(data: str): params.append(param) start = end + 1 - if len(data) == 1: - return [data] - return params From 0e770219119450f6f7e7720689f0b9e34bf59905 Mon Sep 17 00:00:00 2001 From: coco875 Date: Thu, 4 Apr 2024 11:08:55 +0200 Subject: [PATCH 19/46] update file who are rename in mk64 --- fast64_internal/mk64/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fast64_internal/mk64/__init__.py b/fast64_internal/mk64/__init__.py index 0edd4cd69..1f89c8125 100644 --- a/fast64_internal/mk64/__init__.py +++ b/fast64_internal/mk64/__init__.py @@ -46,10 +46,10 @@ def execute(self, context): paths = [importPath] if "course_data" in importPath: - paths += [importPath.replace("course_data", "course_displaylists")] + paths += [importPath.replace("course_data", "course_displaylists.inc")] paths += [ - importPath.replace("course_data.inc", "course_textures.linkonly").replace( + importPath.replace("course_data", "course_textures.linkonly").replace( "course_displaylists.inc", "course_textures.linkonly" ) ] @@ -62,8 +62,8 @@ def execute(self, context): f3d_context = MK64F3DContext(get_F3D_GBI(), basePath, material) if "course_displaylists" in importPath or "course_data" in importPath: - vertexPath = importPath.replace("course_displaylists", "course_vertices").replace( - "course_data", "course_vertices" + vertexPath = importPath.replace("course_displaylists.inc", "course_vertices.inc").replace( + "course_data", "course_vertices.inc" ) print(vertexPath) f3d_context.vertexData["0x4000000"] = parseCourseVtx(vertexPath, f3d_context.f3d) From 97a012398d794f67a6cdd7d08d1ca84b1ec007c8 Mon Sep 17 00:00:00 2001 From: coco875 <59367621+coco875@users.noreply.github.com> Date: Thu, 20 Jun 2024 04:15:10 +0200 Subject: [PATCH 20/46] reformat with black --- fast64_internal/mk64/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/fast64_internal/mk64/__init__.py b/fast64_internal/mk64/__init__.py index 1f89c8125..1d8ee8d7e 100644 --- a/fast64_internal/mk64/__init__.py +++ b/fast64_internal/mk64/__init__.py @@ -12,6 +12,7 @@ class MK64_Properties(PropertyGroup): """Global MK64 Scene Properties found under scene.fast64.mk64""" + # Import Course DL EnableRenderModeDefault: bpy.props.BoolProperty(name="Enable Render Mode by Default", default=True) From b4fedd2b540d45928d939f8da65e447989b1b4d3 Mon Sep 17 00:00:00 2001 From: coco875 <59367621+coco875@users.noreply.github.com> Date: Thu, 20 Jun 2024 16:58:35 +0200 Subject: [PATCH 21/46] fix an import --- fast64_internal/mk64/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fast64_internal/mk64/__init__.py b/fast64_internal/mk64/__init__.py index 1d8ee8d7e..b4666aedb 100644 --- a/fast64_internal/mk64/__init__.py +++ b/fast64_internal/mk64/__init__.py @@ -1,5 +1,5 @@ import bpy -from bpy.types import PropertyGroup +from bpy.types import PropertyGroup, Operator from ..f3d.f3d_material import createF3DMat from ..f3d.f3d_gbi import get_F3D_GBI from ..f3d.f3d_parser import getImportData, importMeshC @@ -21,7 +21,7 @@ def upgrade_changed_props(): pass -class MK64_ImportCourseDL(bpy.types.Operator): +class MK64_ImportCourseDL(Operator): # set bl_ properties bl_idname = "object.fast64_mk64_course_import_dl" bl_label = "Import Course DL" From f24435e040aa162c801e4d127c181b67f146c347 Mon Sep 17 00:00:00 2001 From: coco875 <59367621+coco875@users.noreply.github.com> Date: Thu, 20 Jun 2024 16:59:00 +0200 Subject: [PATCH 22/46] Update fast64_internal/mk64/__init__.py Co-authored-by: Lila --- fast64_internal/mk64/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fast64_internal/mk64/__init__.py b/fast64_internal/mk64/__init__.py index b4666aedb..90b6b34c2 100644 --- a/fast64_internal/mk64/__init__.py +++ b/fast64_internal/mk64/__init__.py @@ -90,8 +90,8 @@ def execute(self, context): class MK64_ImportCourseDLPanel(MK64_Panel): - bl_idname = "MK64_import_course_DL_panel_settings" - bl_label = "MK64 Import Course DL Panel Settings" + bl_idname = "MK64_PT_import_course_DL" + bl_label = "MK64 Import Course DL" bl_options = set() # default to open bl_order = 0 # force to front From a4372f39d1054d01d656f54bc835f0faf9f442b6 Mon Sep 17 00:00:00 2001 From: coco875 <59367621+coco875@users.noreply.github.com> Date: Thu, 20 Jun 2024 16:59:13 +0200 Subject: [PATCH 23/46] Update fast64_internal/mk64/f3d_course_parser.py Co-authored-by: Lila --- fast64_internal/mk64/f3d_course_parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fast64_internal/mk64/f3d_course_parser.py b/fast64_internal/mk64/f3d_course_parser.py index cf9f65c6c..5ba89a846 100644 --- a/fast64_internal/mk64/f3d_course_parser.py +++ b/fast64_internal/mk64/f3d_course_parser.py @@ -42,7 +42,7 @@ class MK64F3DContext(F3DContext): def getVertexDataStart(self, vertexDataParam: str, f3d: F3D): matchResult = re.search(r"\&?([A-Za-z0-9\_]*)\s*(\[([^\]]*)\])?\s*(\+(.*))?", vertexDataParam) if matchResult is None: - raise PluginError("SPVertex param " + vertexDataParam + " is malformed.") + raise PluginError(f"SPVertex param {vertexDataParam} is malformed.") offset = 0 if matchResult.group(3): From 97230eb56ef9aab9efe49059978d6924a9a68ad3 Mon Sep 17 00:00:00 2001 From: coco875 <59367621+coco875@users.noreply.github.com> Date: Thu, 20 Jun 2024 16:59:26 +0200 Subject: [PATCH 24/46] Update fast64_internal/mk64/__init__.py Co-authored-by: Lila --- fast64_internal/mk64/__init__.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/fast64_internal/mk64/__init__.py b/fast64_internal/mk64/__init__.py index 90b6b34c2..c9d1900e0 100644 --- a/fast64_internal/mk64/__init__.py +++ b/fast64_internal/mk64/__init__.py @@ -116,9 +116,6 @@ def draw(self, context): box.label(text="All data must be contained within file.") box.label(text="The only exception are pngs converted to inc.c.") - # col.template_list('F3D_UL_ImportDLPathList', '', context.scene, - # 'DLImportOtherFiles', context.scene, 'DLImportOtherFilesIndex') - mk64_classes = (MK64_Properties,) From 3df043dfc44598cf0a57abb5c0889673f9fdc356 Mon Sep 17 00:00:00 2001 From: coco875 <59367621+coco875@users.noreply.github.com> Date: Thu, 20 Jun 2024 17:05:26 +0200 Subject: [PATCH 25/46] Update fast64_internal/mk64/__init__.py Co-authored-by: Lila --- fast64_internal/mk64/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fast64_internal/mk64/__init__.py b/fast64_internal/mk64/__init__.py index c9d1900e0..7ff7f538e 100644 --- a/fast64_internal/mk64/__init__.py +++ b/fast64_internal/mk64/__init__.py @@ -23,7 +23,7 @@ def upgrade_changed_props(): class MK64_ImportCourseDL(Operator): # set bl_ properties - bl_idname = "object.fast64_mk64_course_import_dl" + bl_idname = "scene.fast64_mk64_course_import_dl" bl_label = "Import Course DL" bl_options = {"REGISTER", "UNDO", "PRESET"} From 8b7e2dd38e8f8564f09edb645816f473a736650a Mon Sep 17 00:00:00 2001 From: coco875 <59367621+coco875@users.noreply.github.com> Date: Thu, 20 Jun 2024 17:06:31 +0200 Subject: [PATCH 26/46] sort import --- fast64_internal/mk64/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fast64_internal/mk64/__init__.py b/fast64_internal/mk64/__init__.py index 7ff7f538e..b8734ff68 100644 --- a/fast64_internal/mk64/__init__.py +++ b/fast64_internal/mk64/__init__.py @@ -1,13 +1,13 @@ import bpy from bpy.types import PropertyGroup, Operator +from bpy.utils import register_class, unregister_class +from .f3d_course_parser import MK64F3DContext, parseCourseVtx from ..f3d.f3d_material import createF3DMat from ..f3d.f3d_gbi import get_F3D_GBI from ..f3d.f3d_parser import getImportData, importMeshC from ..panels import MK64_Panel from ..utility import prop_split -from bpy.utils import register_class, unregister_class from ..utility import raisePluginError -from .f3d_course_parser import MK64F3DContext, parseCourseVtx class MK64_Properties(PropertyGroup): From 3d4722af22d55479c7e12ed88296c16805a5525d Mon Sep 17 00:00:00 2001 From: coco875 <59367621+coco875@users.noreply.github.com> Date: Thu, 20 Jun 2024 17:23:10 +0200 Subject: [PATCH 27/46] Update README.md Co-authored-by: Lila --- fast64_internal/mk64/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fast64_internal/mk64/README.md b/fast64_internal/mk64/README.md index 0a50b047f..daa4b08c2 100644 --- a/fast64_internal/mk64/README.md +++ b/fast64_internal/mk64/README.md @@ -1,7 +1,7 @@ # Mario Kart 64 ## Importing Course -It's similar to F3D Importer, you select the file where you have the display list, the name of the display list you want to import and the path to the decomp. (by default course are cut as segment so it's better to use cinematic version who have all, it's in general the last display variable in course_data.inc.c). +It's similar to the F3D Importer, you select the file where you have the display list, set the name of the display list you want to import and the path to the decomp. (by default courses are split in segments so it's better to use the cinematic version, usually the last display list in course_data.inc.c). Example of configuration: - d_course_wario_stadium_dl_CA78 From 685da7354de11640ac176fbad48112daf116f056 Mon Sep 17 00:00:00 2001 From: coco875 <59367621+coco875@users.noreply.github.com> Date: Thu, 20 Jun 2024 17:23:15 +0200 Subject: [PATCH 28/46] Update README.md Co-authored-by: Lila --- fast64_internal/mk64/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fast64_internal/mk64/README.md b/fast64_internal/mk64/README.md index daa4b08c2..4c0b99647 100644 --- a/fast64_internal/mk64/README.md +++ b/fast64_internal/mk64/README.md @@ -1,6 +1,6 @@ # Mario Kart 64 -## Importing Course +## Importing Course Display Lists It's similar to the F3D Importer, you select the file where you have the display list, set the name of the display list you want to import and the path to the decomp. (by default courses are split in segments so it's better to use the cinematic version, usually the last display list in course_data.inc.c). Example of configuration: From 6fdf8d47b2624b07c99d3b7b8393c9ade0e2d4db Mon Sep 17 00:00:00 2001 From: coco875 <59367621+coco875@users.noreply.github.com> Date: Thu, 20 Jun 2024 17:23:25 +0200 Subject: [PATCH 29/46] Update __init__.py Co-authored-by: Lila --- fast64_internal/mk64/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fast64_internal/mk64/__init__.py b/fast64_internal/mk64/__init__.py index b8734ff68..8521bf027 100644 --- a/fast64_internal/mk64/__init__.py +++ b/fast64_internal/mk64/__init__.py @@ -14,7 +14,7 @@ class MK64_Properties(PropertyGroup): """Global MK64 Scene Properties found under scene.fast64.mk64""" # Import Course DL - EnableRenderModeDefault: bpy.props.BoolProperty(name="Enable Render Mode by Default", default=True) + EnableRenderModeDefault: bpy.props.BoolProperty(name="Set Render Mode by Default", default=True) @staticmethod def upgrade_changed_props(): From 5f520f8b7624330c73eec38f9b9af8577279e884 Mon Sep 17 00:00:00 2001 From: coco875 <59367621+coco875@users.noreply.github.com> Date: Mon, 29 Jul 2024 16:06:38 +0200 Subject: [PATCH 30/46] Update __init__.py Co-authored-by: Lila --- fast64_internal/mk64/__init__.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/fast64_internal/mk64/__init__.py b/fast64_internal/mk64/__init__.py index 8521bf027..f7d81c2b8 100644 --- a/fast64_internal/mk64/__init__.py +++ b/fast64_internal/mk64/__init__.py @@ -58,8 +58,25 @@ def execute(self, context): data = getImportData(paths) material = createF3DMat(None) - - material.f3d_mat.rdp_settings.set_rendermode = context.scene.fast64.mk64.EnableRenderModeDefault + f3d_mat = material.f3d_mat + f3d_mat.rdp_settings.set_rendermode = context.scene.fast64.mk64.EnableRenderModeDefault + f3d_mat.combiner1.A = 'TEXEL0' + f3d_mat.combiner1.B = '0' + f3d_mat.combiner1.C = 'SHADE' + f3d_mat.combiner1.D = '0' + f3d_mat.combiner1.A_alpha = 'TEXEL0' + f3d_mat.combiner1.B_alpha = '0' + f3d_mat.combiner1.C_alpha = 'SHADE' + f3d_mat.combiner1.D_alpha = '0' + f3d_mat.combiner2.name = '' + f3d_mat.combiner2.A = 'TEXEL0' + f3d_mat.combiner2.B = '0' + f3d_mat.combiner2.C = 'SHADE' + f3d_mat.combiner2.D = '0' + f3d_mat.combiner2.A_alpha = 'TEXEL0' + f3d_mat.combiner2.B_alpha = '0' + f3d_mat.combiner2.C_alpha = 'SHADE' + f3d_mat.combiner2.D_alpha = '0' f3d_context = MK64F3DContext(get_F3D_GBI(), basePath, material) if "course_displaylists" in importPath or "course_data" in importPath: From fcc6d1a6a959ef4733fd319ca8c622208940e1e4 Mon Sep 17 00:00:00 2001 From: coco875 Date: Mon, 29 Jul 2024 22:14:34 +0200 Subject: [PATCH 31/46] add properties to mk64 --- fast64_internal/mk64/__init__.py | 68 ++++++++++++-------------- fast64_internal/mk64/f3d/properties.py | 45 +++++++++++++++++ 2 files changed, 77 insertions(+), 36 deletions(-) create mode 100644 fast64_internal/mk64/f3d/properties.py diff --git a/fast64_internal/mk64/__init__.py b/fast64_internal/mk64/__init__.py index f7d81c2b8..5315f04e3 100644 --- a/fast64_internal/mk64/__init__.py +++ b/fast64_internal/mk64/__init__.py @@ -1,6 +1,7 @@ import bpy from bpy.types import PropertyGroup, Operator from bpy.utils import register_class, unregister_class +from .f3d.properties import MK64CourseDLImportSettings, f3d_props_register, f3d_props_unregister from .f3d_course_parser import MK64F3DContext, parseCourseVtx from ..f3d.f3d_material import createF3DMat from ..f3d.f3d_gbi import get_F3D_GBI @@ -14,7 +15,7 @@ class MK64_Properties(PropertyGroup): """Global MK64 Scene Properties found under scene.fast64.mk64""" # Import Course DL - EnableRenderModeDefault: bpy.props.BoolProperty(name="Set Render Mode by Default", default=True) + CourseDLImportSettings: bpy.props.PointerProperty(type=MK64CourseDLImportSettings) @staticmethod def upgrade_changed_props(): @@ -35,14 +36,15 @@ def execute(self, context): bpy.ops.object.mode_set(mode="OBJECT") try: - name = context.scene.DLImportName - importPath = bpy.path.abspath(context.scene.DLImportPath) - basePath = bpy.path.abspath(context.scene.DLImportBasePath) - scaleValue = context.scene.blenderF3DScale + importSettings: MK64CourseDLImportSettings = context.scene.fast64.mk64.CourseDLImportSettings + name = importSettings.DLImportName + importPath = bpy.path.abspath(importSettings.DLImportPath) + basePath = bpy.path.abspath(importSettings.DLImportBasePath) + scaleValue = importSettings.blenderF3DScale - removeDoubles = context.scene.DLRemoveDoubles - importNormals = context.scene.DLImportNormals - drawLayer = context.scene.DLImportDrawLayer + removeDoubles = importSettings.DLRemoveDoubles + importNormals = importSettings.DLImportNormals + drawLayer = importSettings.DLImportDrawLayer paths = [importPath] @@ -59,24 +61,24 @@ def execute(self, context): material = createF3DMat(None) f3d_mat = material.f3d_mat - f3d_mat.rdp_settings.set_rendermode = context.scene.fast64.mk64.EnableRenderModeDefault - f3d_mat.combiner1.A = 'TEXEL0' - f3d_mat.combiner1.B = '0' - f3d_mat.combiner1.C = 'SHADE' - f3d_mat.combiner1.D = '0' - f3d_mat.combiner1.A_alpha = 'TEXEL0' - f3d_mat.combiner1.B_alpha = '0' - f3d_mat.combiner1.C_alpha = 'SHADE' - f3d_mat.combiner1.D_alpha = '0' - f3d_mat.combiner2.name = '' - f3d_mat.combiner2.A = 'TEXEL0' - f3d_mat.combiner2.B = '0' - f3d_mat.combiner2.C = 'SHADE' - f3d_mat.combiner2.D = '0' - f3d_mat.combiner2.A_alpha = 'TEXEL0' - f3d_mat.combiner2.B_alpha = '0' - f3d_mat.combiner2.C_alpha = 'SHADE' - f3d_mat.combiner2.D_alpha = '0' + f3d_mat.rdp_settings.set_rendermode = importSettings.EnableRenderModeDefault + f3d_mat.combiner1.A = "TEXEL0" + f3d_mat.combiner1.B = "0" + f3d_mat.combiner1.C = "SHADE" + f3d_mat.combiner1.D = "0" + f3d_mat.combiner1.A_alpha = "TEXEL0" + f3d_mat.combiner1.B_alpha = "0" + f3d_mat.combiner1.C_alpha = "SHADE" + f3d_mat.combiner1.D_alpha = "0" + f3d_mat.combiner2.name = "" + f3d_mat.combiner2.A = "TEXEL0" + f3d_mat.combiner2.B = "0" + f3d_mat.combiner2.C = "SHADE" + f3d_mat.combiner2.D = "0" + f3d_mat.combiner2.A_alpha = "TEXEL0" + f3d_mat.combiner2.B_alpha = "0" + f3d_mat.combiner2.C_alpha = "SHADE" + f3d_mat.combiner2.D_alpha = "0" f3d_context = MK64F3DContext(get_F3D_GBI(), basePath, material) if "course_displaylists" in importPath or "course_data" in importPath: @@ -118,16 +120,8 @@ def draw(self, context): col.scale_y = 1.1 # extra padding col.operator(MK64_ImportCourseDL.bl_idname) - prop_split(col, context.scene, "DLImportName", "Name") - prop_split(col, context.scene, "DLImportPath", "File") - prop_split(col, context.scene, "DLImportBasePath", "Base Path") - prop_split(col, context.scene, "blenderF3DScale", "Scale") - prop_split(col, context.scene, "DLImportDrawLayer", "Draw Layer") - col.prop(context.scene, "DLRemoveDoubles") - col.prop(context.scene, "DLImportNormals") - - mk64Props = context.scene.fast64.mk64 - prop_split(col, mk64Props, "EnableRenderModeDefault", "Enable Render Mode by Default") + CourseDLImportSettings: MK64CourseDLImportSettings = context.scene.fast64.mk64.CourseDLImportSettings + CourseDLImportSettings.draw_props(col) box = col.box().column() box.label(text="All data must be contained within file.") @@ -153,6 +147,7 @@ def mk64_panel_unregister(): def mk64_register(registerPanels): + f3d_props_register() for cls in mk64_classes: register_class(cls) if registerPanels: @@ -164,3 +159,4 @@ def mk64_unregister(registerPanel): unregister_class(cls) if registerPanel: mk64_panel_unregister() + f3d_props_unregister() diff --git a/fast64_internal/mk64/f3d/properties.py b/fast64_internal/mk64/f3d/properties.py new file mode 100644 index 000000000..11e60d9e0 --- /dev/null +++ b/fast64_internal/mk64/f3d/properties.py @@ -0,0 +1,45 @@ +from bpy.props import StringProperty, EnumProperty, FloatProperty, BoolProperty +from bpy.types import PropertyGroup, UILayout +from bpy.utils import register_class, unregister_class +from ...utility import prop_split +from ...render_settings import ( + on_update_render_settings, +) +from ...f3d.f3d_material import ootEnumDrawLayers + + +class MK64CourseDLImportSettings(PropertyGroup): + DLImportName: StringProperty(name="Name") + DLImportPath: StringProperty(name="Directory", subtype="FILE_PATH") + DLImportBasePath: StringProperty(name="Directory", subtype="FILE_PATH") + blenderF3DScale: FloatProperty(name="F3D Blender Scale", default=100, update=on_update_render_settings) + DLImportDrawLayer: EnumProperty(name="Draw Layer", items=ootEnumDrawLayers) + DLRemoveDoubles: BoolProperty(name="Remove Doubles", default=True) + DLImportNormals: BoolProperty(name="Import Normals", default=True) + EnableRenderModeDefault: BoolProperty(name="Set Render Mode by Default", default=True) + + def draw_props(self, layout: UILayout): + prop_split(layout, self, "DLImportName", "Name") + prop_split(layout, self, "DLImportPath", "File") + prop_split(layout, self, "DLImportBasePath", "Base Path") + prop_split(layout, self, "blenderF3DScale", "Scale") + prop_split(layout, self, "DLImportDrawLayer", "Draw Layer") + layout.prop(self, "DLRemoveDoubles") + layout.prop(self, "DLImportNormals") + + prop_split(layout, self, "EnableRenderModeDefault", "Enable Render Mode by Default") + + +mk64_dl_writer_classes = [ + MK64CourseDLImportSettings, +] + + +def f3d_props_register(): + for cls in mk64_dl_writer_classes: + register_class(cls) + + +def f3d_props_unregister(): + for cls in reversed(mk64_dl_writer_classes): + unregister_class(cls) From f1119c025d81fa037472dd10ed5ee8b6159f9c63 Mon Sep 17 00:00:00 2001 From: coco875 Date: Tue, 30 Jul 2024 01:12:38 +0200 Subject: [PATCH 32/46] rename properties field --- fast64_internal/mk64/__init__.py | 16 ++++++------ fast64_internal/mk64/f3d/properties.py | 34 +++++++++++++------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/fast64_internal/mk64/__init__.py b/fast64_internal/mk64/__init__.py index 5315f04e3..840f453dc 100644 --- a/fast64_internal/mk64/__init__.py +++ b/fast64_internal/mk64/__init__.py @@ -37,14 +37,14 @@ def execute(self, context): try: importSettings: MK64CourseDLImportSettings = context.scene.fast64.mk64.CourseDLImportSettings - name = importSettings.DLImportName - importPath = bpy.path.abspath(importSettings.DLImportPath) - basePath = bpy.path.abspath(importSettings.DLImportBasePath) - scaleValue = importSettings.blenderF3DScale + name = importSettings.name + importPath = bpy.path.abspath(importSettings.path) + basePath = bpy.path.abspath(importSettings.basePath) + scaleValue = importSettings.scale - removeDoubles = importSettings.DLRemoveDoubles - importNormals = importSettings.DLImportNormals - drawLayer = importSettings.DLImportDrawLayer + removeDoubles = importSettings.removeDoubles + importNormals = importSettings.importNormals + drawLayer = importSettings.drawLayer paths = [importPath] @@ -61,7 +61,7 @@ def execute(self, context): material = createF3DMat(None) f3d_mat = material.f3d_mat - f3d_mat.rdp_settings.set_rendermode = importSettings.EnableRenderModeDefault + f3d_mat.rdp_settings.set_rendermode = importSettings.enableRenderModeDefault f3d_mat.combiner1.A = "TEXEL0" f3d_mat.combiner1.B = "0" f3d_mat.combiner1.C = "SHADE" diff --git a/fast64_internal/mk64/f3d/properties.py b/fast64_internal/mk64/f3d/properties.py index 11e60d9e0..422a2cfc8 100644 --- a/fast64_internal/mk64/f3d/properties.py +++ b/fast64_internal/mk64/f3d/properties.py @@ -9,25 +9,25 @@ class MK64CourseDLImportSettings(PropertyGroup): - DLImportName: StringProperty(name="Name") - DLImportPath: StringProperty(name="Directory", subtype="FILE_PATH") - DLImportBasePath: StringProperty(name="Directory", subtype="FILE_PATH") - blenderF3DScale: FloatProperty(name="F3D Blender Scale", default=100, update=on_update_render_settings) - DLImportDrawLayer: EnumProperty(name="Draw Layer", items=ootEnumDrawLayers) - DLRemoveDoubles: BoolProperty(name="Remove Doubles", default=True) - DLImportNormals: BoolProperty(name="Import Normals", default=True) - EnableRenderModeDefault: BoolProperty(name="Set Render Mode by Default", default=True) + name: StringProperty(name="Name") + path: StringProperty(name="Directory", subtype="FILE_PATH") + basePath: StringProperty(name="Directory", subtype="FILE_PATH") + scale: FloatProperty(name="F3D Blender Scale", default=100, update=on_update_render_settings) + drawLayer: EnumProperty(name="Draw Layer", items=ootEnumDrawLayers) + removeDoubles: BoolProperty(name="Remove Doubles", default=True) + importNormals: BoolProperty(name="Import Normals", default=True) + enableRenderModeDefault: BoolProperty(name="Set Render Mode by Default", default=True) def draw_props(self, layout: UILayout): - prop_split(layout, self, "DLImportName", "Name") - prop_split(layout, self, "DLImportPath", "File") - prop_split(layout, self, "DLImportBasePath", "Base Path") - prop_split(layout, self, "blenderF3DScale", "Scale") - prop_split(layout, self, "DLImportDrawLayer", "Draw Layer") - layout.prop(self, "DLRemoveDoubles") - layout.prop(self, "DLImportNormals") - - prop_split(layout, self, "EnableRenderModeDefault", "Enable Render Mode by Default") + prop_split(layout, self, "name", "Name") + prop_split(layout, self, "path", "File") + prop_split(layout, self, "basePath", "Base Path") + prop_split(layout, self, "scale", "Scale") + prop_split(layout, self, "drawLayer", "Draw Layer") + layout.prop(self, "removeDoubles") + layout.prop(self, "importNormals") + + prop_split(layout, self, "enableRenderModeDefault", "Enable Render Mode by Default") mk64_dl_writer_classes = [ From bd80fb12eec6effe4ccd331a8ea260877359519e Mon Sep 17 00:00:00 2001 From: coco875 Date: Tue, 30 Jul 2024 01:15:17 +0200 Subject: [PATCH 33/46] remove drawLayer --- fast64_internal/mk64/__init__.py | 2 +- fast64_internal/mk64/f3d/properties.py | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/fast64_internal/mk64/__init__.py b/fast64_internal/mk64/__init__.py index 840f453dc..4c344319a 100644 --- a/fast64_internal/mk64/__init__.py +++ b/fast64_internal/mk64/__init__.py @@ -44,7 +44,7 @@ def execute(self, context): removeDoubles = importSettings.removeDoubles importNormals = importSettings.importNormals - drawLayer = importSettings.drawLayer + drawLayer = ("Opaque", "Opaque", "Opaque") paths = [importPath] diff --git a/fast64_internal/mk64/f3d/properties.py b/fast64_internal/mk64/f3d/properties.py index 422a2cfc8..62d285188 100644 --- a/fast64_internal/mk64/f3d/properties.py +++ b/fast64_internal/mk64/f3d/properties.py @@ -13,7 +13,6 @@ class MK64CourseDLImportSettings(PropertyGroup): path: StringProperty(name="Directory", subtype="FILE_PATH") basePath: StringProperty(name="Directory", subtype="FILE_PATH") scale: FloatProperty(name="F3D Blender Scale", default=100, update=on_update_render_settings) - drawLayer: EnumProperty(name="Draw Layer", items=ootEnumDrawLayers) removeDoubles: BoolProperty(name="Remove Doubles", default=True) importNormals: BoolProperty(name="Import Normals", default=True) enableRenderModeDefault: BoolProperty(name="Set Render Mode by Default", default=True) @@ -23,7 +22,6 @@ def draw_props(self, layout: UILayout): prop_split(layout, self, "path", "File") prop_split(layout, self, "basePath", "Base Path") prop_split(layout, self, "scale", "Scale") - prop_split(layout, self, "drawLayer", "Draw Layer") layout.prop(self, "removeDoubles") layout.prop(self, "importNormals") From df47e6de872fdab79b98daeb07d27dda7fb78905 Mon Sep 17 00:00:00 2001 From: coco875 <59367621+coco875@users.noreply.github.com> Date: Tue, 30 Jul 2024 12:07:16 +0200 Subject: [PATCH 34/46] Update __init__.py Co-authored-by: Lila --- fast64_internal/mk64/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fast64_internal/mk64/__init__.py b/fast64_internal/mk64/__init__.py index 4c344319a..b334d3e02 100644 --- a/fast64_internal/mk64/__init__.py +++ b/fast64_internal/mk64/__init__.py @@ -44,7 +44,7 @@ def execute(self, context): removeDoubles = importSettings.removeDoubles importNormals = importSettings.importNormals - drawLayer = ("Opaque", "Opaque", "Opaque") + drawLayer = "Opaque" paths = [importPath] From 7541dba138be2a8a38ba68e8f220d52532098035 Mon Sep 17 00:00:00 2001 From: coco875 <59367621+coco875@users.noreply.github.com> Date: Tue, 30 Jul 2024 12:27:27 +0200 Subject: [PATCH 35/46] fix enum of game problem Co-authored-by: Lila --- __init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/__init__.py b/__init__.py index 3e51510f3..0d482259d 100644 --- a/__init__.py +++ b/__init__.py @@ -63,10 +63,10 @@ } gameEditorEnum = ( - ("SM64", "SM64", "Super Mario 64"), - ("OOT", "OOT", "Ocarina Of Time"), - ("MK64", "MK64", "Mario Kart 64"), - ("Homebrew", "Homebrew", "Homebrew"), + ("SM64", "SM64", "Super Mario 64", 0), + ("OOT", "OOT", "Ocarina Of Time", 1), + ("MK64", "MK64", "Mario Kart 64", 3), + ("Homebrew", "Homebrew", "Homebrew", 2), ) From e73a86d64c12287f3e8cf56eee4d7a88431c20a2 Mon Sep 17 00:00:00 2001 From: coco875 <59367621+coco875@users.noreply.github.com> Date: Tue, 30 Jul 2024 22:42:36 +0200 Subject: [PATCH 36/46] Update fast64_internal/mk64/f3d/properties.py Co-authored-by: Lila --- fast64_internal/mk64/f3d/properties.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fast64_internal/mk64/f3d/properties.py b/fast64_internal/mk64/f3d/properties.py index 62d285188..d12045d7d 100644 --- a/fast64_internal/mk64/f3d/properties.py +++ b/fast64_internal/mk64/f3d/properties.py @@ -25,7 +25,7 @@ def draw_props(self, layout: UILayout): layout.prop(self, "removeDoubles") layout.prop(self, "importNormals") - prop_split(layout, self, "enableRenderModeDefault", "Enable Render Mode by Default") + layout.prop(self, "enableRenderModeDefault") mk64_dl_writer_classes = [ From 5e2964ce52e742cec75269416b092b6d8f7f8650 Mon Sep 17 00:00:00 2001 From: coco875 Date: Tue, 30 Jul 2024 22:48:20 +0200 Subject: [PATCH 37/46] move MK64_ImportCourseDL to operators file --- fast64_internal/mk64/__init__.py | 96 +---------------------- fast64_internal/mk64/f3d/operators.py | 91 +++++++++++++++++++++ fast64_internal/mk64/f3d/properties.py | 2 +- fast64_internal/mk64/f3d_course_parser.py | 6 +- 4 files changed, 96 insertions(+), 99 deletions(-) create mode 100644 fast64_internal/mk64/f3d/operators.py diff --git a/fast64_internal/mk64/__init__.py b/fast64_internal/mk64/__init__.py index b334d3e02..6c912245d 100644 --- a/fast64_internal/mk64/__init__.py +++ b/fast64_internal/mk64/__init__.py @@ -1,14 +1,9 @@ import bpy -from bpy.types import PropertyGroup, Operator +from bpy.types import PropertyGroup from bpy.utils import register_class, unregister_class from .f3d.properties import MK64CourseDLImportSettings, f3d_props_register, f3d_props_unregister -from .f3d_course_parser import MK64F3DContext, parseCourseVtx -from ..f3d.f3d_material import createF3DMat -from ..f3d.f3d_gbi import get_F3D_GBI -from ..f3d.f3d_parser import getImportData, importMeshC +from .f3d.operators import MK64_ImportCourseDL from ..panels import MK64_Panel -from ..utility import prop_split -from ..utility import raisePluginError class MK64_Properties(PropertyGroup): @@ -21,93 +16,6 @@ class MK64_Properties(PropertyGroup): def upgrade_changed_props(): pass - -class MK64_ImportCourseDL(Operator): - # set bl_ properties - bl_idname = "scene.fast64_mk64_course_import_dl" - bl_label = "Import Course DL" - bl_options = {"REGISTER", "UNDO", "PRESET"} - - # Called on demand (i.e. button press, menu item) - # Can also be called from operator search menu (Spacebar) - def execute(self, context): - obj = None - if context.mode != "OBJECT": - bpy.ops.object.mode_set(mode="OBJECT") - - try: - importSettings: MK64CourseDLImportSettings = context.scene.fast64.mk64.CourseDLImportSettings - name = importSettings.name - importPath = bpy.path.abspath(importSettings.path) - basePath = bpy.path.abspath(importSettings.basePath) - scaleValue = importSettings.scale - - removeDoubles = importSettings.removeDoubles - importNormals = importSettings.importNormals - drawLayer = "Opaque" - - paths = [importPath] - - if "course_data" in importPath: - paths += [importPath.replace("course_data", "course_displaylists.inc")] - - paths += [ - importPath.replace("course_data", "course_textures.linkonly").replace( - "course_displaylists.inc", "course_textures.linkonly" - ) - ] - - data = getImportData(paths) - - material = createF3DMat(None) - f3d_mat = material.f3d_mat - f3d_mat.rdp_settings.set_rendermode = importSettings.enableRenderModeDefault - f3d_mat.combiner1.A = "TEXEL0" - f3d_mat.combiner1.B = "0" - f3d_mat.combiner1.C = "SHADE" - f3d_mat.combiner1.D = "0" - f3d_mat.combiner1.A_alpha = "TEXEL0" - f3d_mat.combiner1.B_alpha = "0" - f3d_mat.combiner1.C_alpha = "SHADE" - f3d_mat.combiner1.D_alpha = "0" - f3d_mat.combiner2.name = "" - f3d_mat.combiner2.A = "TEXEL0" - f3d_mat.combiner2.B = "0" - f3d_mat.combiner2.C = "SHADE" - f3d_mat.combiner2.D = "0" - f3d_mat.combiner2.A_alpha = "TEXEL0" - f3d_mat.combiner2.B_alpha = "0" - f3d_mat.combiner2.C_alpha = "SHADE" - f3d_mat.combiner2.D_alpha = "0" - - f3d_context = MK64F3DContext(get_F3D_GBI(), basePath, material) - if "course_displaylists" in importPath or "course_data" in importPath: - vertexPath = importPath.replace("course_displaylists.inc", "course_vertices.inc").replace( - "course_data", "course_vertices.inc" - ) - print(vertexPath) - f3d_context.vertexData["0x4000000"] = parseCourseVtx(vertexPath, f3d_context.f3d) - - importMeshC( - data, - name, - scaleValue, - removeDoubles, - importNormals, - drawLayer, - f3d_context, - ) - - self.report({"INFO"}, "Success!") - return {"FINISHED"} - - except Exception as e: - if context.mode != "OBJECT": - bpy.ops.object.mode_set(mode="OBJECT") - raisePluginError(self, e) - return {"CANCELLED"} # must return a set - - class MK64_ImportCourseDLPanel(MK64_Panel): bl_idname = "MK64_PT_import_course_DL" bl_label = "MK64 Import Course DL" diff --git a/fast64_internal/mk64/f3d/operators.py b/fast64_internal/mk64/f3d/operators.py new file mode 100644 index 000000000..f49575a1b --- /dev/null +++ b/fast64_internal/mk64/f3d/operators.py @@ -0,0 +1,91 @@ +from bpy.types import Operator +from ..f3d_course_parser import MK64F3DContext, parseCourseVtx +from ...f3d.f3d_material import createF3DMat +from ...f3d.f3d_gbi import get_F3D_GBI +from ...f3d.f3d_parser import getImportData, importMeshC +from ...utility import raisePluginError + +class MK64_ImportCourseDL(Operator): + # set bl_ properties + bl_idname = "scene.fast64_mk64_course_import_dl" + bl_label = "Import Course DL" + bl_options = {"REGISTER", "UNDO", "PRESET"} + + # Called on demand (i.e. button press, menu item) + # Can also be called from operator search menu (Spacebar) + def execute(self, context): + obj = None + if context.mode != "OBJECT": + bpy.ops.object.mode_set(mode="OBJECT") + + try: + importSettings: MK64CourseDLImportSettings = context.scene.fast64.mk64.CourseDLImportSettings + name = importSettings.name + importPath = bpy.path.abspath(importSettings.path) + basePath = bpy.path.abspath(importSettings.basePath) + scaleValue = importSettings.scale + + removeDoubles = importSettings.removeDoubles + importNormals = importSettings.importNormals + drawLayer = "Opaque" + + paths = [importPath] + + if "course_data" in importPath: + paths += [importPath.replace("course_data", "course_displaylists.inc")] + + paths += [ + importPath.replace("course_data", "course_textures.linkonly").replace( + "course_displaylists.inc", "course_textures.linkonly" + ) + ] + + data = getImportData(paths) + + material = createF3DMat(None) + f3d_mat = material.f3d_mat + f3d_mat.rdp_settings.set_rendermode = importSettings.enableRenderModeDefault + f3d_mat.combiner1.A = "TEXEL0" + f3d_mat.combiner1.B = "0" + f3d_mat.combiner1.C = "SHADE" + f3d_mat.combiner1.D = "0" + f3d_mat.combiner1.A_alpha = "TEXEL0" + f3d_mat.combiner1.B_alpha = "0" + f3d_mat.combiner1.C_alpha = "SHADE" + f3d_mat.combiner1.D_alpha = "0" + f3d_mat.combiner2.name = "" + f3d_mat.combiner2.A = "TEXEL0" + f3d_mat.combiner2.B = "0" + f3d_mat.combiner2.C = "SHADE" + f3d_mat.combiner2.D = "0" + f3d_mat.combiner2.A_alpha = "TEXEL0" + f3d_mat.combiner2.B_alpha = "0" + f3d_mat.combiner2.C_alpha = "SHADE" + f3d_mat.combiner2.D_alpha = "0" + + f3d_context = MK64F3DContext(get_F3D_GBI(), basePath, material) + if "course_displaylists" in importPath or "course_data" in importPath: + vertexPath = importPath.replace("course_displaylists.inc", "course_vertices.inc").replace( + "course_data", "course_vertices.inc" + ) + print(vertexPath) + f3d_context.vertexData["0x4000000"] = parseCourseVtx(vertexPath, f3d_context.f3d) + + importMeshC( + data, + name, + scaleValue, + removeDoubles, + importNormals, + drawLayer, + f3d_context, + ) + + self.report({"INFO"}, "Success!") + return {"FINISHED"} + + except Exception as e: + if context.mode != "OBJECT": + bpy.ops.object.mode_set(mode="OBJECT") + raisePluginError(self, e) + return {"CANCELLED"} # must return a set \ No newline at end of file diff --git a/fast64_internal/mk64/f3d/properties.py b/fast64_internal/mk64/f3d/properties.py index d12045d7d..e66b76934 100644 --- a/fast64_internal/mk64/f3d/properties.py +++ b/fast64_internal/mk64/f3d/properties.py @@ -1,4 +1,4 @@ -from bpy.props import StringProperty, EnumProperty, FloatProperty, BoolProperty +from bpy.props import StringProperty, FloatProperty, BoolProperty from bpy.types import PropertyGroup, UILayout from bpy.utils import register_class, unregister_class from ...utility import prop_split diff --git a/fast64_internal/mk64/f3d_course_parser.py b/fast64_internal/mk64/f3d_course_parser.py index 5ba89a846..ed3476bf3 100644 --- a/fast64_internal/mk64/f3d_course_parser.py +++ b/fast64_internal/mk64/f3d_course_parser.py @@ -1,11 +1,9 @@ import re -import traceback from mathutils import Vector from ..f3d.f3d_gbi import F3D -from ..f3d.f3d_material import RDPSettings -from ..f3d.f3d_parser import F3DContext, F3DParsedCommands, ParsedMacro, math_eval, parseDLData, parseVertexData +from ..f3d.f3d_parser import F3DContext, math_eval from ..f3d.f3d_writer import F3DVert -from ..utility import PluginError, float_from_u16_str, gammaInverseValue, int_from_s16_str, readFile, unpackNormal +from ..utility import PluginError, readFile, unpackNormal def courseVertexFormatPatterns(): From 30f9030c94b8d22463584b5ff5bbde6434335539 Mon Sep 17 00:00:00 2001 From: coco875 Date: Tue, 30 Jul 2024 22:49:30 +0200 Subject: [PATCH 38/46] format black --- fast64_internal/mk64/__init__.py | 1 + fast64_internal/mk64/f3d/operators.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/fast64_internal/mk64/__init__.py b/fast64_internal/mk64/__init__.py index 6c912245d..9bbff21f0 100644 --- a/fast64_internal/mk64/__init__.py +++ b/fast64_internal/mk64/__init__.py @@ -16,6 +16,7 @@ class MK64_Properties(PropertyGroup): def upgrade_changed_props(): pass + class MK64_ImportCourseDLPanel(MK64_Panel): bl_idname = "MK64_PT_import_course_DL" bl_label = "MK64 Import Course DL" diff --git a/fast64_internal/mk64/f3d/operators.py b/fast64_internal/mk64/f3d/operators.py index f49575a1b..15eade1dd 100644 --- a/fast64_internal/mk64/f3d/operators.py +++ b/fast64_internal/mk64/f3d/operators.py @@ -5,6 +5,7 @@ from ...f3d.f3d_parser import getImportData, importMeshC from ...utility import raisePluginError + class MK64_ImportCourseDL(Operator): # set bl_ properties bl_idname = "scene.fast64_mk64_course_import_dl" @@ -88,4 +89,4 @@ def execute(self, context): if context.mode != "OBJECT": bpy.ops.object.mode_set(mode="OBJECT") raisePluginError(self, e) - return {"CANCELLED"} # must return a set \ No newline at end of file + return {"CANCELLED"} # must return a set From 2a08f97678ca21ceaa836609dcc3013620b44c2f Mon Sep 17 00:00:00 2001 From: coco875 Date: Tue, 30 Jul 2024 23:05:05 +0200 Subject: [PATCH 39/46] forget an import --- fast64_internal/mk64/f3d/operators.py | 1 + 1 file changed, 1 insertion(+) diff --git a/fast64_internal/mk64/f3d/operators.py b/fast64_internal/mk64/f3d/operators.py index 15eade1dd..9426a5e05 100644 --- a/fast64_internal/mk64/f3d/operators.py +++ b/fast64_internal/mk64/f3d/operators.py @@ -1,3 +1,4 @@ +import bpy from bpy.types import Operator from ..f3d_course_parser import MK64F3DContext, parseCourseVtx from ...f3d.f3d_material import createF3DMat From edc0e7b7f9a35263e401dbedca810da09a8ba1a5 Mon Sep 17 00:00:00 2001 From: coco875 Date: Tue, 30 Jul 2024 23:05:46 +0200 Subject: [PATCH 40/46] forget another import --- fast64_internal/mk64/f3d/operators.py | 1 + 1 file changed, 1 insertion(+) diff --git a/fast64_internal/mk64/f3d/operators.py b/fast64_internal/mk64/f3d/operators.py index 9426a5e05..d8c08a08b 100644 --- a/fast64_internal/mk64/f3d/operators.py +++ b/fast64_internal/mk64/f3d/operators.py @@ -5,6 +5,7 @@ from ...f3d.f3d_gbi import get_F3D_GBI from ...f3d.f3d_parser import getImportData, importMeshC from ...utility import raisePluginError +from .properties import MK64CourseDLImportSettings class MK64_ImportCourseDL(Operator): From 77ac333a6faa708b9ee0c2f34cb62d00c56d6f8d Mon Sep 17 00:00:00 2001 From: coco875 Date: Thu, 1 Aug 2024 19:58:18 +0200 Subject: [PATCH 41/46] make some snake_case move panels and scale --- fast64_internal/mk64/__init__.py | 28 +++++------------------ fast64_internal/mk64/f3d/operators.py | 16 ++++++------- fast64_internal/mk64/f3d/panels.py | 24 +++++++++++++++++++ fast64_internal/mk64/f3d/properties.py | 23 ++++++++----------- fast64_internal/mk64/f3d_course_parser.py | 6 ++--- 5 files changed, 50 insertions(+), 47 deletions(-) create mode 100644 fast64_internal/mk64/f3d/panels.py diff --git a/fast64_internal/mk64/__init__.py b/fast64_internal/mk64/__init__.py index 9bbff21f0..228859155 100644 --- a/fast64_internal/mk64/__init__.py +++ b/fast64_internal/mk64/__init__.py @@ -1,42 +1,26 @@ import bpy +from bpy.props import FloatProperty from bpy.types import PropertyGroup from bpy.utils import register_class, unregister_class from .f3d.properties import MK64CourseDLImportSettings, f3d_props_register, f3d_props_unregister from .f3d.operators import MK64_ImportCourseDL -from ..panels import MK64_Panel +from .f3d.panels import MK64_ImportCourseDLPanel +from ..render_settings import on_update_render_settings class MK64_Properties(PropertyGroup): """Global MK64 Scene Properties found under scene.fast64.mk64""" # Import Course DL - CourseDLImportSettings: bpy.props.PointerProperty(type=MK64CourseDLImportSettings) + course_DL_import_settings: bpy.props.PointerProperty(type=MK64CourseDLImportSettings) + scale: FloatProperty(name="F3D Blender Scale", default=100, update=on_update_render_settings) + @staticmethod def upgrade_changed_props(): pass -class MK64_ImportCourseDLPanel(MK64_Panel): - bl_idname = "MK64_PT_import_course_DL" - bl_label = "MK64 Import Course DL" - bl_options = set() # default to open - bl_order = 0 # force to front - - # called every frame - def draw(self, context): - col = self.layout.column() - col.scale_y = 1.1 # extra padding - - col.operator(MK64_ImportCourseDL.bl_idname) - CourseDLImportSettings: MK64CourseDLImportSettings = context.scene.fast64.mk64.CourseDLImportSettings - CourseDLImportSettings.draw_props(col) - - box = col.box().column() - box.label(text="All data must be contained within file.") - box.label(text="The only exception are pngs converted to inc.c.") - - mk64_classes = (MK64_Properties,) mk64_panel_classes = ( diff --git a/fast64_internal/mk64/f3d/operators.py b/fast64_internal/mk64/f3d/operators.py index d8c08a08b..126e67a16 100644 --- a/fast64_internal/mk64/f3d/operators.py +++ b/fast64_internal/mk64/f3d/operators.py @@ -1,6 +1,6 @@ import bpy from bpy.types import Operator -from ..f3d_course_parser import MK64F3DContext, parseCourseVtx +from ..f3d_course_parser import MK64F3DContext, parse_course_vtx from ...f3d.f3d_material import createF3DMat from ...f3d.f3d_gbi import get_F3D_GBI from ...f3d.f3d_parser import getImportData, importMeshC @@ -22,14 +22,14 @@ def execute(self, context): bpy.ops.object.mode_set(mode="OBJECT") try: - importSettings: MK64CourseDLImportSettings = context.scene.fast64.mk64.CourseDLImportSettings + importSettings: MK64CourseDLImportSettings = context.scene.fast64.mk64.course_DL_import_settings name = importSettings.name importPath = bpy.path.abspath(importSettings.path) - basePath = bpy.path.abspath(importSettings.basePath) - scaleValue = importSettings.scale + basePath = bpy.path.abspath(importSettings.base_path) + scaleValue = context.scene.fast64.mk64.scale - removeDoubles = importSettings.removeDoubles - importNormals = importSettings.importNormals + removeDoubles = importSettings.remove_doubles + importNormals = importSettings.import_normals drawLayer = "Opaque" paths = [importPath] @@ -47,7 +47,7 @@ def execute(self, context): material = createF3DMat(None) f3d_mat = material.f3d_mat - f3d_mat.rdp_settings.set_rendermode = importSettings.enableRenderModeDefault + f3d_mat.rdp_settings.set_rendermode = importSettings.enable_render_Mode_Default f3d_mat.combiner1.A = "TEXEL0" f3d_mat.combiner1.B = "0" f3d_mat.combiner1.C = "SHADE" @@ -72,7 +72,7 @@ def execute(self, context): "course_data", "course_vertices.inc" ) print(vertexPath) - f3d_context.vertexData["0x4000000"] = parseCourseVtx(vertexPath, f3d_context.f3d) + f3d_context.vertexData["0x4000000"] = parse_course_vtx(vertexPath, f3d_context.f3d) importMeshC( data, diff --git a/fast64_internal/mk64/f3d/panels.py b/fast64_internal/mk64/f3d/panels.py new file mode 100644 index 000000000..7c1bc8c34 --- /dev/null +++ b/fast64_internal/mk64/f3d/panels.py @@ -0,0 +1,24 @@ +from .properties import MK64CourseDLImportSettings +from .operators import MK64_ImportCourseDL +from ...panels import MK64_Panel +from ...utility import prop_split + +class MK64_ImportCourseDLPanel(MK64_Panel): + bl_idname = "MK64_PT_import_course_DL" + bl_label = "MK64 Import Course DL" + bl_options = set() # default to open + bl_order = 0 # force to front + + # called every frame + def draw(self, context): + col = self.layout.column() + col.scale_y = 1.1 # extra padding + + col.operator(MK64_ImportCourseDL.bl_idname) + course_DL_import_settings: MK64CourseDLImportSettings = context.scene.fast64.mk64.course_DL_import_settings + course_DL_import_settings.draw_props(col) + prop_split(col, context.scene.fast64.mk64, "scale", "Scale") + + box = col.box().column() + box.label(text="All data must be contained within file.") + box.label(text="The only exception are pngs converted to inc.c.") \ No newline at end of file diff --git a/fast64_internal/mk64/f3d/properties.py b/fast64_internal/mk64/f3d/properties.py index e66b76934..c01700fd8 100644 --- a/fast64_internal/mk64/f3d/properties.py +++ b/fast64_internal/mk64/f3d/properties.py @@ -1,31 +1,26 @@ -from bpy.props import StringProperty, FloatProperty, BoolProperty +from bpy.props import StringProperty, BoolProperty from bpy.types import PropertyGroup, UILayout from bpy.utils import register_class, unregister_class from ...utility import prop_split -from ...render_settings import ( - on_update_render_settings, -) from ...f3d.f3d_material import ootEnumDrawLayers class MK64CourseDLImportSettings(PropertyGroup): name: StringProperty(name="Name") path: StringProperty(name="Directory", subtype="FILE_PATH") - basePath: StringProperty(name="Directory", subtype="FILE_PATH") - scale: FloatProperty(name="F3D Blender Scale", default=100, update=on_update_render_settings) - removeDoubles: BoolProperty(name="Remove Doubles", default=True) - importNormals: BoolProperty(name="Import Normals", default=True) - enableRenderModeDefault: BoolProperty(name="Set Render Mode by Default", default=True) + base_path: StringProperty(name="Directory", subtype="FILE_PATH") + remove_doubles: BoolProperty(name="Remove Doubles", default=True) + import_normals: BoolProperty(name="Import Normals", default=True) + enable_render_Mode_Default: BoolProperty(name="Set Render Mode by Default", default=True) def draw_props(self, layout: UILayout): prop_split(layout, self, "name", "Name") prop_split(layout, self, "path", "File") - prop_split(layout, self, "basePath", "Base Path") - prop_split(layout, self, "scale", "Scale") - layout.prop(self, "removeDoubles") - layout.prop(self, "importNormals") + prop_split(layout, self, "base_path", "Base Path") + layout.prop(self, "remove_doubles") + layout.prop(self, "import_normals") - layout.prop(self, "enableRenderModeDefault") + layout.prop(self, "enable_render_Mode_Default") mk64_dl_writer_classes = [ diff --git a/fast64_internal/mk64/f3d_course_parser.py b/fast64_internal/mk64/f3d_course_parser.py index ed3476bf3..721616cf4 100644 --- a/fast64_internal/mk64/f3d_course_parser.py +++ b/fast64_internal/mk64/f3d_course_parser.py @@ -6,7 +6,7 @@ from ..utility import PluginError, readFile, unpackNormal -def courseVertexFormatPatterns(): +def course_vertex_format_patterns(): # position, uv, color/normal return ( # decomp format @@ -18,9 +18,9 @@ def courseVertexFormatPatterns(): ) -def parseCourseVtx(path: str, f3d): +def parse_course_vtx(path: str, f3d): data = readFile(path) - pattern = courseVertexFormatPatterns() + pattern = course_vertex_format_patterns() vertexData = [] for values in re.findall(pattern, data, re.DOTALL): values = [math_eval(g, f3d) for g in values] From 6930776fc231c44ab74849072aed808f384e9c25 Mon Sep 17 00:00:00 2001 From: coco875 Date: Thu, 1 Aug 2024 19:59:28 +0200 Subject: [PATCH 42/46] fix black --- fast64_internal/mk64/__init__.py | 1 - fast64_internal/mk64/f3d/panels.py | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fast64_internal/mk64/__init__.py b/fast64_internal/mk64/__init__.py index 228859155..1f550761d 100644 --- a/fast64_internal/mk64/__init__.py +++ b/fast64_internal/mk64/__init__.py @@ -14,7 +14,6 @@ class MK64_Properties(PropertyGroup): # Import Course DL course_DL_import_settings: bpy.props.PointerProperty(type=MK64CourseDLImportSettings) scale: FloatProperty(name="F3D Blender Scale", default=100, update=on_update_render_settings) - @staticmethod def upgrade_changed_props(): diff --git a/fast64_internal/mk64/f3d/panels.py b/fast64_internal/mk64/f3d/panels.py index 7c1bc8c34..de8bfabe4 100644 --- a/fast64_internal/mk64/f3d/panels.py +++ b/fast64_internal/mk64/f3d/panels.py @@ -3,6 +3,7 @@ from ...panels import MK64_Panel from ...utility import prop_split + class MK64_ImportCourseDLPanel(MK64_Panel): bl_idname = "MK64_PT_import_course_DL" bl_label = "MK64 Import Course DL" @@ -21,4 +22,4 @@ def draw(self, context): box = col.box().column() box.label(text="All data must be contained within file.") - box.label(text="The only exception are pngs converted to inc.c.") \ No newline at end of file + box.label(text="The only exception are pngs converted to inc.c.") From f323083a82cc12d2a9314e99d7b858b6f9fba4bf Mon Sep 17 00:00:00 2001 From: coco875 Date: Thu, 1 Aug 2024 20:29:34 +0200 Subject: [PATCH 43/46] fix snakke_case --- fast64_internal/mk64/f3d/operators.py | 40 +++++++++++++-------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/fast64_internal/mk64/f3d/operators.py b/fast64_internal/mk64/f3d/operators.py index 126e67a16..f72b89e67 100644 --- a/fast64_internal/mk64/f3d/operators.py +++ b/fast64_internal/mk64/f3d/operators.py @@ -22,23 +22,23 @@ def execute(self, context): bpy.ops.object.mode_set(mode="OBJECT") try: - importSettings: MK64CourseDLImportSettings = context.scene.fast64.mk64.course_DL_import_settings - name = importSettings.name - importPath = bpy.path.abspath(importSettings.path) - basePath = bpy.path.abspath(importSettings.base_path) - scaleValue = context.scene.fast64.mk64.scale + import_settings: MK64CourseDLImportSettings = context.scene.fast64.mk64.course_DL_import_settings + name = import_settings.name + import_path = bpy.path.abspath(import_settings.path) + base_path = bpy.path.abspath(import_settings.base_path) + scale_value = context.scene.fast64.mk64.scale - removeDoubles = importSettings.remove_doubles - importNormals = importSettings.import_normals - drawLayer = "Opaque" + remove_doubles = import_settings.remove_doubles + import_normals = import_settings.import_normals + draw_layer = "Opaque" - paths = [importPath] + paths = [import_path] - if "course_data" in importPath: - paths += [importPath.replace("course_data", "course_displaylists.inc")] + if "course_data" in import_path: + paths += [import_path.replace("course_data", "course_displaylists.inc")] paths += [ - importPath.replace("course_data", "course_textures.linkonly").replace( + import_path.replace("course_data", "course_textures.linkonly").replace( "course_displaylists.inc", "course_textures.linkonly" ) ] @@ -47,7 +47,7 @@ def execute(self, context): material = createF3DMat(None) f3d_mat = material.f3d_mat - f3d_mat.rdp_settings.set_rendermode = importSettings.enable_render_Mode_Default + f3d_mat.rdp_settings.set_rendermode = import_settings.enable_render_Mode_Default f3d_mat.combiner1.A = "TEXEL0" f3d_mat.combiner1.B = "0" f3d_mat.combiner1.C = "SHADE" @@ -66,9 +66,9 @@ def execute(self, context): f3d_mat.combiner2.C_alpha = "SHADE" f3d_mat.combiner2.D_alpha = "0" - f3d_context = MK64F3DContext(get_F3D_GBI(), basePath, material) - if "course_displaylists" in importPath or "course_data" in importPath: - vertexPath = importPath.replace("course_displaylists.inc", "course_vertices.inc").replace( + f3d_context = MK64F3DContext(get_F3D_GBI(), base_path, material) + if "course_displaylists" in import_path or "course_data" in import_path: + vertexPath = import_path.replace("course_displaylists.inc", "course_vertices.inc").replace( "course_data", "course_vertices.inc" ) print(vertexPath) @@ -77,10 +77,10 @@ def execute(self, context): importMeshC( data, name, - scaleValue, - removeDoubles, - importNormals, - drawLayer, + scale_value, + remove_doubles, + import_normals, + draw_layer, f3d_context, ) From 76a5c6415425b291bda6eaa94db8bd8429db48fd Mon Sep 17 00:00:00 2001 From: coco875 Date: Thu, 1 Aug 2024 21:24:59 +0200 Subject: [PATCH 44/46] rename to mk64_model_classes --- .../mk64/{f3d_course_parser.py => mk64_model_classes.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename fast64_internal/mk64/{f3d_course_parser.py => mk64_model_classes.py} (100%) diff --git a/fast64_internal/mk64/f3d_course_parser.py b/fast64_internal/mk64/mk64_model_classes.py similarity index 100% rename from fast64_internal/mk64/f3d_course_parser.py rename to fast64_internal/mk64/mk64_model_classes.py From f7d9d4d86c21030241c88bbd93a68a8877cbec29 Mon Sep 17 00:00:00 2001 From: coco875 Date: Thu, 1 Aug 2024 21:25:17 +0200 Subject: [PATCH 45/46] Update operators.py --- fast64_internal/mk64/f3d/operators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fast64_internal/mk64/f3d/operators.py b/fast64_internal/mk64/f3d/operators.py index f72b89e67..7dcf2eebe 100644 --- a/fast64_internal/mk64/f3d/operators.py +++ b/fast64_internal/mk64/f3d/operators.py @@ -1,6 +1,6 @@ import bpy from bpy.types import Operator -from ..f3d_course_parser import MK64F3DContext, parse_course_vtx +from ..mk64_model_classes import MK64F3DContext, parse_course_vtx from ...f3d.f3d_material import createF3DMat from ...f3d.f3d_gbi import get_F3D_GBI from ...f3d.f3d_parser import getImportData, importMeshC From 5684b13efa3b992e164f4c506dcbe470d772149e Mon Sep 17 00:00:00 2001 From: coco875 Date: Fri, 2 Aug 2024 00:40:41 +0200 Subject: [PATCH 46/46] forget a snake_case --- fast64_internal/mk64/f3d/operators.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fast64_internal/mk64/f3d/operators.py b/fast64_internal/mk64/f3d/operators.py index 7dcf2eebe..913eac3ef 100644 --- a/fast64_internal/mk64/f3d/operators.py +++ b/fast64_internal/mk64/f3d/operators.py @@ -68,11 +68,11 @@ def execute(self, context): f3d_context = MK64F3DContext(get_F3D_GBI(), base_path, material) if "course_displaylists" in import_path or "course_data" in import_path: - vertexPath = import_path.replace("course_displaylists.inc", "course_vertices.inc").replace( + vertex_path = import_path.replace("course_displaylists.inc", "course_vertices.inc").replace( "course_data", "course_vertices.inc" ) - print(vertexPath) - f3d_context.vertexData["0x4000000"] = parse_course_vtx(vertexPath, f3d_context.f3d) + print(vertex_path) + f3d_context.vertexData["0x4000000"] = parse_course_vtx(vertex_path, f3d_context.f3d) importMeshC( data,