From 5f389391c2acf21ec4fbd16d11d667717ba42f19 Mon Sep 17 00:00:00 2001 From: Lila Date: Tue, 10 Sep 2024 09:57:35 +0100 Subject: [PATCH 01/16] [SM64/F3D] Fix and update Ui Image Exporter Fixes #451 Missing: Load and set commands and pallets (currently relying on multitex manager, will have to be changed somehow) Updated: Tex prop is now drawn using ui_image, ui_image has been updated to optionally hide low and high props (are handled by size cmd, does not exist for texrect) materialless_setup func for TexInfo, equivelant to moreSetupFromModel for bpy material-less contexts, obviously cannot handle flipbooks ignore_tex_set bool for fromProp Use only fromProp and updated writeAll Some basic ui reordering to match other panels --- fast64_internal/f3d/f3d_material.py | 4 +- fast64_internal/f3d/f3d_texture_writer.py | 36 ++++++++++++++-- fast64_internal/sm64/sm64_f3d_writer.py | 52 ++++------------------- 3 files changed, 45 insertions(+), 47 deletions(-) diff --git a/fast64_internal/f3d/f3d_material.py b/fast64_internal/f3d/f3d_material.py index f4be233ed..71a6147f7 100644 --- a/fast64_internal/f3d/f3d_material.py +++ b/fast64_internal/f3d/f3d_material.py @@ -2919,6 +2919,7 @@ def ui_image( textureProp: TextureProperty, name: str, showCheckBox: bool, + hide_lowhigh=False, ): inputGroup = layout.box().column() @@ -3025,7 +3026,8 @@ def ui_image( shift = prop_input.row() shift.prop(textureProp.S, "shift", text="Shift S") shift.prop(textureProp.T, "shift", text="Shift T") - + if hide_lowhigh: + return low = prop_input.row() low.prop(textureProp.S, "low", text="S Low") low.prop(textureProp.T, "low", text="T Low") diff --git a/fast64_internal/f3d/f3d_texture_writer.py b/fast64_internal/f3d/f3d_texture_writer.py index d08d80ced..9d4dcb0b4 100644 --- a/fast64_internal/f3d/f3d_texture_writer.py +++ b/fast64_internal/f3d/f3d_texture_writer.py @@ -420,10 +420,10 @@ def fromMat(self, index: int, f3dMat: F3DMaterialProperty) -> bool: texProp = getattr(f3dMat, "tex" + str(index)) return self.fromProp(texProp, index) - def fromProp(self, texProp: TextureProperty, index: int) -> bool: + def fromProp(self, texProp: TextureProperty, index: int, ignore_tex_set=False) -> bool: self.indexInMat = index self.texProp = texProp - if not texProp.tex_set: + if not texProp.tex_set and not ignore_tex_set: return True self.useTex = True @@ -463,6 +463,33 @@ def fromProp(self, texProp: TextureProperty, index: int) -> bool: return True + def materialless_setup(self) -> None: + """moreSetupFromModel equivelent that does not handle material properties like OOT flipbooks""" + if not self.useTex: + return + + if self.isTexCI: + self.imDependencies, self.flipbook, self.pal = ( + [] if self.texProp.tex is None else [self.texProp.tex], + None, + None, + ) + if self.isTexRef: + self.palLen = self.texProp.pal_reference_size + else: + assert self.flipbook is None + self.pal = getColorsUsedInImage(self.texProp.tex, self.palFormat) + self.palLen = len(self.pal) + if self.palLen > (16 if self.texFormat == "CI4" else 256): + raise PluginError( + f"Error in Texture {self.indexInMat} uses too many unique colors to fit in format {self.texFormat}." + ) + else: + self.imDependencies, self.flipbook = [] if self.texProp.tex is None else [self.texProp.tex], None + + self.isPalRef = self.isTexRef and self.flipbook is None + self.palDependencies = self.imDependencies + def moreSetupFromModel( self, material: bpy.types.Material, @@ -514,7 +541,7 @@ def writeAll( return assert ( self.imDependencies is not None - ) # Must be set manually if didn't use moreSetupFromModel, e.g. ti.imDependencies = [tex] + ), "self.imDependencies is None, either moreSetupFromModel or materialless_setup must be called beforehand" # Get definitions imageKey, fImage = saveOrGetTextureDefinition( @@ -551,6 +578,9 @@ def writeAll( fModel.writeTexRefNonCITextures(self.flipbook, self.texFormat) else: if self.isTexCI: + assert ( + self.pal is not None + ), "self.pal is None, either moreSetupFromModel or materialless_setup must be called beforehand" writeCITextureData(self.texProp.tex, fImage, self.pal, self.palFormat, self.texFormat) else: writeNonCITextureData(self.texProp.tex, fImage, self.texFormat) diff --git a/fast64_internal/sm64/sm64_f3d_writer.py b/fast64_internal/sm64/sm64_f3d_writer.py index ab69b095f..555e0d918 100644 --- a/fast64_internal/sm64/sm64_f3d_writer.py +++ b/fast64_internal/sm64/sm64_f3d_writer.py @@ -8,8 +8,8 @@ from ..f3d.f3d_texture_writer import TexInfo from ..f3d.f3d_material import ( TextureProperty, - tmemUsageUI, all_combiner_uses, + ui_image, ui_procAnim, update_world_default_rendermode, ) @@ -283,18 +283,8 @@ def exportTexRectCommon(texProp, name, convertTextureData): if tex is None: raise PluginError("No texture is selected.") - texProp.S.low = 0 - texProp.S.high = texProp.tex.size[0] - 1 - texProp.S.mask = ceil(log(texProp.tex.size[0], 2) - 0.001) - texProp.S.shift = 0 - - texProp.T.low = 0 - texProp.T.high = texProp.tex.size[1] - 1 - texProp.T.mask = ceil(log(texProp.tex.size[1], 2) - 0.001) - texProp.T.shift = 0 - fTexRect = FTexRect(toAlnum(name), GfxMatWriteMethod.WriteDifferingAndRevert) - fMaterial = FMaterial(toAlnum(name) + "_mat", DLFormat.Dynamic) + fMaterial = fTexRect.addMaterial(toAlnum(name) + "_mat") # dl_hud_img_begin fTexRect.draw.commands.extend( @@ -311,21 +301,12 @@ def exportTexRectCommon(texProp, name, convertTextureData): drawEndCommands = GfxList("temp", GfxListTag.Draw, DLFormat.Dynamic) ti = TexInfo() - if not ti.fromProp(texProp, 0): - raise PluginError(f"In {name}: {texProp.errorMsg}.") - if not ti.useTex: - raise PluginError(f"In {name}: texture disabled.") - if ti.isTexCI: - raise PluginError(f"In {name}: CI textures not compatible with exportTexRectCommon (because copy mode).") - if ti.tmemSize > 512: - raise PluginError(f"In {name}: texture is too big (> 4 KiB).") - if ti.texFormat != "RGBA16": - raise PluginError(f"In {name}: texture format must be RGBA16 (because copy mode).") - ti.imDependencies = [tex] - ti.writeAll(fTexRect.draw, fMaterial, fTexRect, convertTextureData) + ti.fromProp(texProp, index=0, ignore_tex_set=True) + ti.materialless_setup() + ti.writeAll(fMaterial, fTexRect, convertTextureData) fTexRect.draw.commands.append( - SPScisTextureRectangle(0, 0, (texDimensions[0] - 1) << 2, (texDimensions[1] - 1) << 2, 0, 0, 0) + SPScisTextureRectangle(0, 0, (ti.imageDims[0] - 1) << 2, (ti.imageDims[1] - 1) << 2, 0, 0, 0) ) fTexRect.draw.commands.extend(drawEndCommands.commands) @@ -822,25 +803,7 @@ class ExportTexRectDrawPanel(SM64_Panel): # called every frame def draw(self, context): col = self.layout.column() - propsTexRectE = col.operator(ExportTexRectDraw.bl_idname) - - textureProp = context.scene.texrect - tex = textureProp.tex - col.label(text="This is for decomp only.") - col.template_ID(textureProp, "tex", new="image.new", open="image.open", unlink="image.texrect_unlink") - # col.prop(textureProp, 'tex') - - tmemUsageUI(col, textureProp) - if tex is not None and tex.size[0] > 0 and tex.size[1] > 0: - col.prop(textureProp, "tex_format", text="Format") - if textureProp.tex_format[:2] == "CI": - col.prop(textureProp, "ci_format", text="CI Format") - col.prop(textureProp.S, "clamp", text="Clamp S") - col.prop(textureProp.T, "clamp", text="Clamp T") - col.prop(textureProp.S, "mirror", text="Mirror S") - col.prop(textureProp.T, "mirror", text="Mirror T") - prop_split(col, context.scene, "TexRectName", "Name") col.prop(context.scene, "TexRectCustomExport") if context.scene.TexRectCustomExport: col.prop(context.scene, "TexRectExportPath") @@ -857,6 +820,9 @@ def draw(self, context): infoBox.label(text="After export, call your hud's draw function in ") infoBox.label(text=enumHUDPaths[context.scene.TexRectExportType][0] + ": ") infoBox.label(text=enumHUDPaths[context.scene.TexRectExportType][1] + ".") + prop_split(col, context.scene, "TexRectName", "Name") + ui_image(False, col, None, context.scene.texrect, context.scene.TexRectName, False, hide_lowhigh=True) + col.operator(ExportTexRectDraw.bl_idname) class SM64_DrawLayersPanel(bpy.types.Panel): From 0ce706ce23478e7fda85661c2dc76158a4efa93f Mon Sep 17 00:00:00 2001 From: Lila Date: Tue, 10 Sep 2024 12:00:05 +0100 Subject: [PATCH 02/16] Fix noted issues, clean up code to be consistent, add tlut mode --- fast64_internal/f3d/f3d_material.py | 13 ++++++++-- fast64_internal/f3d/f3d_texture_writer.py | 20 +++++++++++++++ fast64_internal/sm64/sm64_f3d_writer.py | 31 +++++++++++------------ 3 files changed, 46 insertions(+), 18 deletions(-) diff --git a/fast64_internal/f3d/f3d_material.py b/fast64_internal/f3d/f3d_material.py index 71a6147f7..9c1db5347 100644 --- a/fast64_internal/f3d/f3d_material.py +++ b/fast64_internal/f3d/f3d_material.py @@ -2143,9 +2143,9 @@ def get_textlut_mode(f3d_mat: "F3DMaterialProperty", inherit_from_tex: bool = Fa use_dict = all_combiner_uses(f3d_mat) textures = [f3d_mat.tex0] if use_dict["Texture 0"] and f3d_mat.tex0.tex_set else [] textures += [f3d_mat.tex1] if use_dict["Texture 1"] and f3d_mat.tex1.tex_set else [] - tlut_modes = [tex.ci_format if tex.tex_format.startswith("CI") else "NONE" for tex in textures] + tlut_modes = [tex.tlut_mode for tex in textures] if tlut_modes and tlut_modes[0] == tlut_modes[-1]: - return "G_TT_" + tlut_modes[0] + return tlut_modes[0] return None if inherit_from_tex else f3d_mat.rdp_settings.g_mdsft_textlut @@ -2858,6 +2858,15 @@ class TextureProperty(PropertyGroup): ) tile_scroll: bpy.props.PointerProperty(type=SetTileSizeScrollProperty) + @property + def is_ci(self): + self.tex_format: str + return self.tex_format.startswith("CI") + + @property + def tlut_mode(self): + return f"G_TT_{self.ci_format if self.is_ci else 'NONE'}" + def get_tex_size(self) -> list[int]: if self.tex or self.use_tex_reference: if self.tex is not None: diff --git a/fast64_internal/f3d/f3d_texture_writer.py b/fast64_internal/f3d/f3d_texture_writer.py index 9d4dcb0b4..b35e17b2c 100644 --- a/fast64_internal/f3d/f3d_texture_writer.py +++ b/fast64_internal/f3d/f3d_texture_writer.py @@ -531,6 +531,26 @@ def getPaletteName(self): return self.flipbook.name return getImageName(self.texProp.tex) + def setup_single_tex(self, is_ci: bool, use_large_tex: bool): + is_large = False + tmem_size = 256 if is_ci else 512 + if is_ci: + assert self.useTex # should this be here? + if self.useTex: + self.loadPal = True + self.palBaseName = self.getPaletteName() + if self.tmemSize >= tmem_size: + if use_large_tex: + self.doTexLoad = False + return True + elif not bpy.context.scene.ignoreTextureRestrictions: + raise PluginError( + "Textures are too big. Max TMEM size is 4k " + "bytes, ex. 2 32x32 RGBA 16 bit textures.\n" + "Note that texture width will be internally padded to 64 bit boundaries." + ) + return is_large + def writeAll( self, fMaterial: FMaterial, diff --git a/fast64_internal/sm64/sm64_f3d_writer.py b/fast64_internal/sm64/sm64_f3d_writer.py index 555e0d918..471708309 100644 --- a/fast64_internal/sm64/sm64_f3d_writer.py +++ b/fast64_internal/sm64/sm64_f3d_writer.py @@ -4,7 +4,7 @@ from mathutils import Matrix, Vector from bpy.utils import register_class, unregister_class from ..panels import SM64_Panel -from ..f3d.f3d_writer import exportF3DCommon +from ..f3d.f3d_writer import exportF3DCommon, saveModeSetting from ..f3d.f3d_texture_writer import TexInfo from ..f3d.f3d_material import ( TextureProperty, @@ -22,6 +22,7 @@ from ..f3d.f3d_bleed import BleedGraphics from ..f3d.f3d_gbi import ( + DPSetTextureLUT, get_F3D_GBI, GbiMacro, GfxTag, @@ -279,15 +280,12 @@ def modifyDLForHUD(data): def exportTexRectCommon(texProp, name, convertTextureData): - tex = texProp.tex - if tex is None: - raise PluginError("No texture is selected.") + defaults = create_or_get_world(bpy.context.scene).rdp_defaults fTexRect = FTexRect(toAlnum(name), GfxMatWriteMethod.WriteDifferingAndRevert) fMaterial = fTexRect.addMaterial(toAlnum(name) + "_mat") - # dl_hud_img_begin - fTexRect.draw.commands.extend( + fMaterial.mat_only_DL.commands.extend( # dl_hud_img_begin [ DPPipeSync(), DPSetCycleType("G_CYC_COPY"), @@ -298,21 +296,14 @@ def exportTexRectCommon(texProp, name, convertTextureData): ] ) - drawEndCommands = GfxList("temp", GfxListTag.Draw, DLFormat.Dynamic) - + saveModeSetting(fMaterial, texProp.tlut_mode, defaults.g_mdsft_textlut, DPSetTextureLUT) ti = TexInfo() ti.fromProp(texProp, index=0, ignore_tex_set=True) ti.materialless_setup() + ti.setup_single_tex(texProp.is_ci, False) ti.writeAll(fMaterial, fTexRect, convertTextureData) - fTexRect.draw.commands.append( - SPScisTextureRectangle(0, 0, (ti.imageDims[0] - 1) << 2, (ti.imageDims[1] - 1) << 2, 0, 0, 0) - ) - - fTexRect.draw.commands.extend(drawEndCommands.commands) - - # dl_hud_img_end - fTexRect.draw.commands.extend( + fMaterial.revert.commands.extend( # dl_hud_img_end [ DPPipeSync(), DPSetCycleType("G_CYC_1CYCLE"), @@ -323,6 +314,14 @@ def exportTexRectCommon(texProp, name, convertTextureData): SPEndDisplayList(), ] ) + fTexRect.materials[texProp] = (fMaterial, ti.imageDims) + + fTexRect.draw.commands.extend(fMaterial.mat_only_DL.commands) + fTexRect.draw.commands.extend(fMaterial.texture_DL.commands) + fTexRect.draw.commands.append( + SPScisTextureRectangle(0, 0, (ti.imageDims[0] - 1) << 2, (ti.imageDims[1] - 1) << 2, 0, 0, 0) + ) + fTexRect.draw.commands.extend(fMaterial.revert.commands) return fTexRect From 829970a9a3d3bf88ef1db9ad5d474a502eb8f4fd Mon Sep 17 00:00:00 2001 From: Lila Date: Tue, 10 Sep 2024 12:19:19 +0100 Subject: [PATCH 03/16] use world defaults and saveModeSetting to remove revert code, remove extra syncs --- fast64_internal/sm64/sm64_f3d_writer.py | 32 ++++++++----------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/fast64_internal/sm64/sm64_f3d_writer.py b/fast64_internal/sm64/sm64_f3d_writer.py index 471708309..cb7078aca 100644 --- a/fast64_internal/sm64/sm64_f3d_writer.py +++ b/fast64_internal/sm64/sm64_f3d_writer.py @@ -285,16 +285,14 @@ def exportTexRectCommon(texProp, name, convertTextureData): fTexRect = FTexRect(toAlnum(name), GfxMatWriteMethod.WriteDifferingAndRevert) fMaterial = fTexRect.addMaterial(toAlnum(name) + "_mat") - fMaterial.mat_only_DL.commands.extend( # dl_hud_img_begin - [ - DPPipeSync(), - DPSetCycleType("G_CYC_COPY"), - DPSetTexturePersp("G_TP_NONE"), - DPSetAlphaCompare("G_AC_THRESHOLD"), - DPSetBlendColor(0xFF, 0xFF, 0xFF, 0xFF), - DPSetRenderMode(["G_RM_AA_XLU_SURF", "G_RM_AA_XLU_SURF2"], None), - ] - ) + # dl_hud_img_begin and dl_hud_img_end + saveModeSetting(fMaterial, "G_CYC_COPY", defaults.g_mdsft_cycletype, DPSetCycleType) + saveModeSetting(fMaterial, "G_TP_NONE", defaults.g_mdsft_textpersp, DPSetTexturePersp) + saveModeSetting(fMaterial, "G_AC_THRESHOLD", defaults.g_mdsft_alpha_compare, DPSetAlphaCompare) + fMaterial.mat_only_DL.commands.append(DPSetBlendColor(0xFF, 0xFF, 0xFF, 0xFF)) + + fMaterial.mat_only_DL.commands.append(DPSetRenderMode(["G_RM_AA_XLU_SURF", "G_RM_AA_XLU_SURF2"], None)) + fMaterial.revert.commands.append(DPSetRenderMode(["G_RM_AA_ZB_OPA_SURF", "G_RM_AA_ZB_OPA_SURF2"], None)) saveModeSetting(fMaterial, texProp.tlut_mode, defaults.g_mdsft_textlut, DPSetTextureLUT) ti = TexInfo() @@ -302,18 +300,6 @@ def exportTexRectCommon(texProp, name, convertTextureData): ti.materialless_setup() ti.setup_single_tex(texProp.is_ci, False) ti.writeAll(fMaterial, fTexRect, convertTextureData) - - fMaterial.revert.commands.extend( # dl_hud_img_end - [ - DPPipeSync(), - DPSetCycleType("G_CYC_1CYCLE"), - SPTexture(0xFFFF, 0xFFFF, 0, "G_TX_RENDERTILE", "G_OFF"), - DPSetTexturePersp("G_TP_PERSP"), - DPSetAlphaCompare("G_AC_NONE"), - DPSetRenderMode(["G_RM_AA_ZB_OPA_SURF", "G_RM_AA_ZB_OPA_SURF2"], None), - SPEndDisplayList(), - ] - ) fTexRect.materials[texProp] = (fMaterial, ti.imageDims) fTexRect.draw.commands.extend(fMaterial.mat_only_DL.commands) @@ -321,7 +307,9 @@ def exportTexRectCommon(texProp, name, convertTextureData): fTexRect.draw.commands.append( SPScisTextureRectangle(0, 0, (ti.imageDims[0] - 1) << 2, (ti.imageDims[1] - 1) << 2, 0, 0, 0) ) + fTexRect.draw.commands.append(DPPipeSync()) fTexRect.draw.commands.extend(fMaterial.revert.commands) + fTexRect.draw.commands.append(SPEndDisplayList()) return fTexRect From 4659223da316f16150ce112153d7cea0c4927bda Mon Sep 17 00:00:00 2001 From: Lila Date: Tue, 10 Sep 2024 12:21:33 +0100 Subject: [PATCH 04/16] close to being finished --- fast64_internal/sm64/sm64_f3d_writer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fast64_internal/sm64/sm64_f3d_writer.py b/fast64_internal/sm64/sm64_f3d_writer.py index cb7078aca..1f2084af4 100644 --- a/fast64_internal/sm64/sm64_f3d_writer.py +++ b/fast64_internal/sm64/sm64_f3d_writer.py @@ -187,7 +187,7 @@ def exportTexRectToC(dirPath, texProp, texDir, savePNG, name, exportToProject, p checkIfPathExists(seg2TexDir) checkIfPathExists(hudPath) - fTexRect.save_textures(seg2TexDir, not savePNG) + fTexRect.save_textures(seg2TexDir) textures = [] for _, fImage in fTexRect.textures.items(): From e5851a9f23311743bbba197d6225905d59119910 Mon Sep 17 00:00:00 2001 From: Lila Date: Tue, 10 Sep 2024 12:39:03 +0100 Subject: [PATCH 05/16] refresh 13 memes --- fast64_internal/sm64/sm64_f3d_writer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fast64_internal/sm64/sm64_f3d_writer.py b/fast64_internal/sm64/sm64_f3d_writer.py index 1f2084af4..81a01a02a 100644 --- a/fast64_internal/sm64/sm64_f3d_writer.py +++ b/fast64_internal/sm64/sm64_f3d_writer.py @@ -100,7 +100,7 @@ # filepath, function to insert before enumHUDPaths = { "HUD": ("src/game/hud.c", "void render_hud(void)"), - "Menu": ("src/game/ingame_menu.c", "s16 render_menus_and_dialogs()"), + "Menu": ("src/game/ingame_menu.c", "s16 render_menus_and_dialogs("), } From 60416e783a7cee7a433d6e4972c006af66b518b5 Mon Sep 17 00:00:00 2001 From: Lila Date: Tue, 10 Sep 2024 14:10:52 +0100 Subject: [PATCH 06/16] automatically pick 1 cycle instead of copy mode --- fast64_internal/sm64/sm64_f3d_writer.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/fast64_internal/sm64/sm64_f3d_writer.py b/fast64_internal/sm64/sm64_f3d_writer.py index 81a01a02a..0134c35a0 100644 --- a/fast64_internal/sm64/sm64_f3d_writer.py +++ b/fast64_internal/sm64/sm64_f3d_writer.py @@ -22,6 +22,7 @@ from ..f3d.f3d_bleed import BleedGraphics from ..f3d.f3d_gbi import ( + DPSetCombineMode, DPSetTextureLUT, get_F3D_GBI, GbiMacro, @@ -280,13 +281,22 @@ def modifyDLForHUD(data): def exportTexRectCommon(texProp, name, convertTextureData): + use_copy_mode = texProp.tlut_mode == "G_TT_RGBA16" or texProp.tex_format == "RGBA16" + defaults = create_or_get_world(bpy.context.scene).rdp_defaults fTexRect = FTexRect(toAlnum(name), GfxMatWriteMethod.WriteDifferingAndRevert) fMaterial = fTexRect.addMaterial(toAlnum(name) + "_mat") - # dl_hud_img_begin and dl_hud_img_end - saveModeSetting(fMaterial, "G_CYC_COPY", defaults.g_mdsft_cycletype, DPSetCycleType) + # use_copy_mode is based on dl_hud_img_begin and dl_hud_img_end + if use_copy_mode: + saveModeSetting(fMaterial, "G_CYC_COPY", defaults.g_mdsft_cycletype, DPSetCycleType) + else: + saveModeSetting(fMaterial, "G_CYC_1CYCLE", defaults.g_mdsft_cycletype, DPSetCycleType) + fMaterial.mat_only_DL.commands.append( + DPSetCombineMode(*fTexRect.f3d.G_CC_DECALRGBA, *fTexRect.f3d.G_CC_DECALRGBA) + ) + fMaterial.revert.commands.append(DPSetCombineMode(*fTexRect.f3d.G_CC_SHADE, *fTexRect.f3d.G_CC_SHADE)) saveModeSetting(fMaterial, "G_TP_NONE", defaults.g_mdsft_textpersp, DPSetTexturePersp) saveModeSetting(fMaterial, "G_AC_THRESHOLD", defaults.g_mdsft_alpha_compare, DPSetAlphaCompare) fMaterial.mat_only_DL.commands.append(DPSetBlendColor(0xFF, 0xFF, 0xFF, 0xFF)) From 7fe981cc15e3a45766a2aacd21c725af8e2f708b Mon Sep 17 00:00:00 2001 From: Lila Date: Tue, 10 Sep 2024 17:16:08 +0100 Subject: [PATCH 07/16] Rasky confirmed ia16 tlut works for copy mode, cool --- fast64_internal/sm64/sm64_f3d_writer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fast64_internal/sm64/sm64_f3d_writer.py b/fast64_internal/sm64/sm64_f3d_writer.py index 0134c35a0..0e76db282 100644 --- a/fast64_internal/sm64/sm64_f3d_writer.py +++ b/fast64_internal/sm64/sm64_f3d_writer.py @@ -281,7 +281,7 @@ def modifyDLForHUD(data): def exportTexRectCommon(texProp, name, convertTextureData): - use_copy_mode = texProp.tlut_mode == "G_TT_RGBA16" or texProp.tex_format == "RGBA16" + use_copy_mode = texProp.is_ci or texProp.tex_format == "RGBA16" defaults = create_or_get_world(bpy.context.scene).rdp_defaults From d3b4e24146092e77d37ee998635de3cbd6d8df20 Mon Sep 17 00:00:00 2001 From: Lila Date: Tue, 10 Sep 2024 20:48:02 +0100 Subject: [PATCH 08/16] Revert "Rasky confirmed ia16 tlut works for copy mode, cool" This reverts commit 7fe981cc15e3a45766a2aacd21c725af8e2f708b. --- fast64_internal/sm64/sm64_f3d_writer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fast64_internal/sm64/sm64_f3d_writer.py b/fast64_internal/sm64/sm64_f3d_writer.py index 0e76db282..0134c35a0 100644 --- a/fast64_internal/sm64/sm64_f3d_writer.py +++ b/fast64_internal/sm64/sm64_f3d_writer.py @@ -281,7 +281,7 @@ def modifyDLForHUD(data): def exportTexRectCommon(texProp, name, convertTextureData): - use_copy_mode = texProp.is_ci or texProp.tex_format == "RGBA16" + use_copy_mode = texProp.tlut_mode == "G_TT_RGBA16" or texProp.tex_format == "RGBA16" defaults = create_or_get_world(bpy.context.scene).rdp_defaults From 2b8d0aba95898c83bd5f6004fd3db6fa573e6659 Mon Sep 17 00:00:00 2001 From: Lila Date: Tue, 10 Sep 2024 09:57:35 +0100 Subject: [PATCH 09/16] [SM64/F3D] Fix and update Ui Image Exporter Updated: Tex prop is now drawn using ui_image, ui_image has been updated to optionally hide low and high props (are handled by size cmd, does not exist for texture rectangles) materialless_setup func for TexInfo, equivelant to moreSetupFromModel for bpy material-less contexts, obviously cannot handle flipbooks setup_single_tex func for TexInfo, sets up a single texture without the context of the multi texture manager ignore_tex_set bool for fromProp Use only fromProp and updated writeAll Use saveModeSetting (and world defaults) instead of manullay appending each DP command (except for blend color) Removed syncs except for the sync after the texrect cmd to do the reverts Removed deprecated arg for png exporting in save_textures (assumed from fimage) Removed the ) part of the delimiter checked when exporting "Menu", refresh 13 made it (void) instead of () Some basic ui reordering to match other panels Added 1 cycle variant for non rgba16 exports Fix dynamic dls --- fast64_internal/f3d/f3d_gbi.py | 3 +- fast64_internal/f3d/f3d_material.py | 17 +++- fast64_internal/f3d/f3d_texture_writer.py | 56 ++++++++++- fast64_internal/sm64/sm64_f3d_writer.py | 117 ++++++++-------------- 4 files changed, 109 insertions(+), 84 deletions(-) diff --git a/fast64_internal/f3d/f3d_gbi.py b/fast64_internal/f3d/f3d_gbi.py index 1eb5b7d80..22a6f3a86 100644 --- a/fast64_internal/f3d/f3d_gbi.py +++ b/fast64_internal/f3d/f3d_gbi.py @@ -3399,7 +3399,8 @@ def to_c(self, static=True): if static: return f"g{'s'*static}{type(self).__name__}({', '.join( self.getargs(static) )})" else: - return f"g{'s'*static}{type(self).__name__}(glistp++, {', '.join( self.getargs(static) )})" + args = ["glistp++"] + list(self.getargs(static)) + return f"g{'s'*static}{type(self).__name__}({', '.join( args )})" def size(self, f3d): return GFX_SIZE diff --git a/fast64_internal/f3d/f3d_material.py b/fast64_internal/f3d/f3d_material.py index f4be233ed..9c1db5347 100644 --- a/fast64_internal/f3d/f3d_material.py +++ b/fast64_internal/f3d/f3d_material.py @@ -2143,9 +2143,9 @@ def get_textlut_mode(f3d_mat: "F3DMaterialProperty", inherit_from_tex: bool = Fa use_dict = all_combiner_uses(f3d_mat) textures = [f3d_mat.tex0] if use_dict["Texture 0"] and f3d_mat.tex0.tex_set else [] textures += [f3d_mat.tex1] if use_dict["Texture 1"] and f3d_mat.tex1.tex_set else [] - tlut_modes = [tex.ci_format if tex.tex_format.startswith("CI") else "NONE" for tex in textures] + tlut_modes = [tex.tlut_mode for tex in textures] if tlut_modes and tlut_modes[0] == tlut_modes[-1]: - return "G_TT_" + tlut_modes[0] + return tlut_modes[0] return None if inherit_from_tex else f3d_mat.rdp_settings.g_mdsft_textlut @@ -2858,6 +2858,15 @@ class TextureProperty(PropertyGroup): ) tile_scroll: bpy.props.PointerProperty(type=SetTileSizeScrollProperty) + @property + def is_ci(self): + self.tex_format: str + return self.tex_format.startswith("CI") + + @property + def tlut_mode(self): + return f"G_TT_{self.ci_format if self.is_ci else 'NONE'}" + def get_tex_size(self) -> list[int]: if self.tex or self.use_tex_reference: if self.tex is not None: @@ -2919,6 +2928,7 @@ def ui_image( textureProp: TextureProperty, name: str, showCheckBox: bool, + hide_lowhigh=False, ): inputGroup = layout.box().column() @@ -3025,7 +3035,8 @@ def ui_image( shift = prop_input.row() shift.prop(textureProp.S, "shift", text="Shift S") shift.prop(textureProp.T, "shift", text="Shift T") - + if hide_lowhigh: + return low = prop_input.row() low.prop(textureProp.S, "low", text="S Low") low.prop(textureProp.T, "low", text="T Low") diff --git a/fast64_internal/f3d/f3d_texture_writer.py b/fast64_internal/f3d/f3d_texture_writer.py index d08d80ced..b35e17b2c 100644 --- a/fast64_internal/f3d/f3d_texture_writer.py +++ b/fast64_internal/f3d/f3d_texture_writer.py @@ -420,10 +420,10 @@ def fromMat(self, index: int, f3dMat: F3DMaterialProperty) -> bool: texProp = getattr(f3dMat, "tex" + str(index)) return self.fromProp(texProp, index) - def fromProp(self, texProp: TextureProperty, index: int) -> bool: + def fromProp(self, texProp: TextureProperty, index: int, ignore_tex_set=False) -> bool: self.indexInMat = index self.texProp = texProp - if not texProp.tex_set: + if not texProp.tex_set and not ignore_tex_set: return True self.useTex = True @@ -463,6 +463,33 @@ def fromProp(self, texProp: TextureProperty, index: int) -> bool: return True + def materialless_setup(self) -> None: + """moreSetupFromModel equivelent that does not handle material properties like OOT flipbooks""" + if not self.useTex: + return + + if self.isTexCI: + self.imDependencies, self.flipbook, self.pal = ( + [] if self.texProp.tex is None else [self.texProp.tex], + None, + None, + ) + if self.isTexRef: + self.palLen = self.texProp.pal_reference_size + else: + assert self.flipbook is None + self.pal = getColorsUsedInImage(self.texProp.tex, self.palFormat) + self.palLen = len(self.pal) + if self.palLen > (16 if self.texFormat == "CI4" else 256): + raise PluginError( + f"Error in Texture {self.indexInMat} uses too many unique colors to fit in format {self.texFormat}." + ) + else: + self.imDependencies, self.flipbook = [] if self.texProp.tex is None else [self.texProp.tex], None + + self.isPalRef = self.isTexRef and self.flipbook is None + self.palDependencies = self.imDependencies + def moreSetupFromModel( self, material: bpy.types.Material, @@ -504,6 +531,26 @@ def getPaletteName(self): return self.flipbook.name return getImageName(self.texProp.tex) + def setup_single_tex(self, is_ci: bool, use_large_tex: bool): + is_large = False + tmem_size = 256 if is_ci else 512 + if is_ci: + assert self.useTex # should this be here? + if self.useTex: + self.loadPal = True + self.palBaseName = self.getPaletteName() + if self.tmemSize >= tmem_size: + if use_large_tex: + self.doTexLoad = False + return True + elif not bpy.context.scene.ignoreTextureRestrictions: + raise PluginError( + "Textures are too big. Max TMEM size is 4k " + "bytes, ex. 2 32x32 RGBA 16 bit textures.\n" + "Note that texture width will be internally padded to 64 bit boundaries." + ) + return is_large + def writeAll( self, fMaterial: FMaterial, @@ -514,7 +561,7 @@ def writeAll( return assert ( self.imDependencies is not None - ) # Must be set manually if didn't use moreSetupFromModel, e.g. ti.imDependencies = [tex] + ), "self.imDependencies is None, either moreSetupFromModel or materialless_setup must be called beforehand" # Get definitions imageKey, fImage = saveOrGetTextureDefinition( @@ -551,6 +598,9 @@ def writeAll( fModel.writeTexRefNonCITextures(self.flipbook, self.texFormat) else: if self.isTexCI: + assert ( + self.pal is not None + ), "self.pal is None, either moreSetupFromModel or materialless_setup must be called beforehand" writeCITextureData(self.texProp.tex, fImage, self.pal, self.palFormat, self.texFormat) else: writeNonCITextureData(self.texProp.tex, fImage, self.texFormat) diff --git a/fast64_internal/sm64/sm64_f3d_writer.py b/fast64_internal/sm64/sm64_f3d_writer.py index ab69b095f..0134c35a0 100644 --- a/fast64_internal/sm64/sm64_f3d_writer.py +++ b/fast64_internal/sm64/sm64_f3d_writer.py @@ -4,12 +4,12 @@ from mathutils import Matrix, Vector from bpy.utils import register_class, unregister_class from ..panels import SM64_Panel -from ..f3d.f3d_writer import exportF3DCommon +from ..f3d.f3d_writer import exportF3DCommon, saveModeSetting from ..f3d.f3d_texture_writer import TexInfo from ..f3d.f3d_material import ( TextureProperty, - tmemUsageUI, all_combiner_uses, + ui_image, ui_procAnim, update_world_default_rendermode, ) @@ -22,6 +22,8 @@ from ..f3d.f3d_bleed import BleedGraphics from ..f3d.f3d_gbi import ( + DPSetCombineMode, + DPSetTextureLUT, get_F3D_GBI, GbiMacro, GfxTag, @@ -99,7 +101,7 @@ # filepath, function to insert before enumHUDPaths = { "HUD": ("src/game/hud.c", "void render_hud(void)"), - "Menu": ("src/game/ingame_menu.c", "s16 render_menus_and_dialogs()"), + "Menu": ("src/game/ingame_menu.c", "s16 render_menus_and_dialogs("), } @@ -186,7 +188,7 @@ def exportTexRectToC(dirPath, texProp, texDir, savePNG, name, exportToProject, p checkIfPathExists(seg2TexDir) checkIfPathExists(hudPath) - fTexRect.save_textures(seg2TexDir, not savePNG) + fTexRect.save_textures(seg2TexDir) textures = [] for _, fImage in fTexRect.textures.items(): @@ -279,69 +281,45 @@ def modifyDLForHUD(data): def exportTexRectCommon(texProp, name, convertTextureData): - tex = texProp.tex - if tex is None: - raise PluginError("No texture is selected.") + use_copy_mode = texProp.tlut_mode == "G_TT_RGBA16" or texProp.tex_format == "RGBA16" - texProp.S.low = 0 - texProp.S.high = texProp.tex.size[0] - 1 - texProp.S.mask = ceil(log(texProp.tex.size[0], 2) - 0.001) - texProp.S.shift = 0 - - texProp.T.low = 0 - texProp.T.high = texProp.tex.size[1] - 1 - texProp.T.mask = ceil(log(texProp.tex.size[1], 2) - 0.001) - texProp.T.shift = 0 + defaults = create_or_get_world(bpy.context.scene).rdp_defaults fTexRect = FTexRect(toAlnum(name), GfxMatWriteMethod.WriteDifferingAndRevert) - fMaterial = FMaterial(toAlnum(name) + "_mat", DLFormat.Dynamic) - - # dl_hud_img_begin - fTexRect.draw.commands.extend( - [ - DPPipeSync(), - DPSetCycleType("G_CYC_COPY"), - DPSetTexturePersp("G_TP_NONE"), - DPSetAlphaCompare("G_AC_THRESHOLD"), - DPSetBlendColor(0xFF, 0xFF, 0xFF, 0xFF), - DPSetRenderMode(["G_RM_AA_XLU_SURF", "G_RM_AA_XLU_SURF2"], None), - ] - ) + fMaterial = fTexRect.addMaterial(toAlnum(name) + "_mat") - drawEndCommands = GfxList("temp", GfxListTag.Draw, DLFormat.Dynamic) + # use_copy_mode is based on dl_hud_img_begin and dl_hud_img_end + if use_copy_mode: + saveModeSetting(fMaterial, "G_CYC_COPY", defaults.g_mdsft_cycletype, DPSetCycleType) + else: + saveModeSetting(fMaterial, "G_CYC_1CYCLE", defaults.g_mdsft_cycletype, DPSetCycleType) + fMaterial.mat_only_DL.commands.append( + DPSetCombineMode(*fTexRect.f3d.G_CC_DECALRGBA, *fTexRect.f3d.G_CC_DECALRGBA) + ) + fMaterial.revert.commands.append(DPSetCombineMode(*fTexRect.f3d.G_CC_SHADE, *fTexRect.f3d.G_CC_SHADE)) + saveModeSetting(fMaterial, "G_TP_NONE", defaults.g_mdsft_textpersp, DPSetTexturePersp) + saveModeSetting(fMaterial, "G_AC_THRESHOLD", defaults.g_mdsft_alpha_compare, DPSetAlphaCompare) + fMaterial.mat_only_DL.commands.append(DPSetBlendColor(0xFF, 0xFF, 0xFF, 0xFF)) - ti = TexInfo() - if not ti.fromProp(texProp, 0): - raise PluginError(f"In {name}: {texProp.errorMsg}.") - if not ti.useTex: - raise PluginError(f"In {name}: texture disabled.") - if ti.isTexCI: - raise PluginError(f"In {name}: CI textures not compatible with exportTexRectCommon (because copy mode).") - if ti.tmemSize > 512: - raise PluginError(f"In {name}: texture is too big (> 4 KiB).") - if ti.texFormat != "RGBA16": - raise PluginError(f"In {name}: texture format must be RGBA16 (because copy mode).") - ti.imDependencies = [tex] - ti.writeAll(fTexRect.draw, fMaterial, fTexRect, convertTextureData) + fMaterial.mat_only_DL.commands.append(DPSetRenderMode(["G_RM_AA_XLU_SURF", "G_RM_AA_XLU_SURF2"], None)) + fMaterial.revert.commands.append(DPSetRenderMode(["G_RM_AA_ZB_OPA_SURF", "G_RM_AA_ZB_OPA_SURF2"], None)) + saveModeSetting(fMaterial, texProp.tlut_mode, defaults.g_mdsft_textlut, DPSetTextureLUT) + ti = TexInfo() + ti.fromProp(texProp, index=0, ignore_tex_set=True) + ti.materialless_setup() + ti.setup_single_tex(texProp.is_ci, False) + ti.writeAll(fMaterial, fTexRect, convertTextureData) + fTexRect.materials[texProp] = (fMaterial, ti.imageDims) + + fTexRect.draw.commands.extend(fMaterial.mat_only_DL.commands) + fTexRect.draw.commands.extend(fMaterial.texture_DL.commands) fTexRect.draw.commands.append( - SPScisTextureRectangle(0, 0, (texDimensions[0] - 1) << 2, (texDimensions[1] - 1) << 2, 0, 0, 0) - ) - - fTexRect.draw.commands.extend(drawEndCommands.commands) - - # dl_hud_img_end - fTexRect.draw.commands.extend( - [ - DPPipeSync(), - DPSetCycleType("G_CYC_1CYCLE"), - SPTexture(0xFFFF, 0xFFFF, 0, "G_TX_RENDERTILE", "G_OFF"), - DPSetTexturePersp("G_TP_PERSP"), - DPSetAlphaCompare("G_AC_NONE"), - DPSetRenderMode(["G_RM_AA_ZB_OPA_SURF", "G_RM_AA_ZB_OPA_SURF2"], None), - SPEndDisplayList(), - ] + SPScisTextureRectangle(0, 0, (ti.imageDims[0] - 1) << 2, (ti.imageDims[1] - 1) << 2, 0, 0, 0) ) + fTexRect.draw.commands.append(DPPipeSync()) + fTexRect.draw.commands.extend(fMaterial.revert.commands) + fTexRect.draw.commands.append(SPEndDisplayList()) return fTexRect @@ -822,25 +800,7 @@ class ExportTexRectDrawPanel(SM64_Panel): # called every frame def draw(self, context): col = self.layout.column() - propsTexRectE = col.operator(ExportTexRectDraw.bl_idname) - - textureProp = context.scene.texrect - tex = textureProp.tex - col.label(text="This is for decomp only.") - col.template_ID(textureProp, "tex", new="image.new", open="image.open", unlink="image.texrect_unlink") - # col.prop(textureProp, 'tex') - - tmemUsageUI(col, textureProp) - if tex is not None and tex.size[0] > 0 and tex.size[1] > 0: - col.prop(textureProp, "tex_format", text="Format") - if textureProp.tex_format[:2] == "CI": - col.prop(textureProp, "ci_format", text="CI Format") - col.prop(textureProp.S, "clamp", text="Clamp S") - col.prop(textureProp.T, "clamp", text="Clamp T") - col.prop(textureProp.S, "mirror", text="Mirror S") - col.prop(textureProp.T, "mirror", text="Mirror T") - prop_split(col, context.scene, "TexRectName", "Name") col.prop(context.scene, "TexRectCustomExport") if context.scene.TexRectCustomExport: col.prop(context.scene, "TexRectExportPath") @@ -857,6 +817,9 @@ def draw(self, context): infoBox.label(text="After export, call your hud's draw function in ") infoBox.label(text=enumHUDPaths[context.scene.TexRectExportType][0] + ": ") infoBox.label(text=enumHUDPaths[context.scene.TexRectExportType][1] + ".") + prop_split(col, context.scene, "TexRectName", "Name") + ui_image(False, col, None, context.scene.texrect, context.scene.TexRectName, False, hide_lowhigh=True) + col.operator(ExportTexRectDraw.bl_idname) class SM64_DrawLayersPanel(bpy.types.Panel): From 4b3f8f45f6b8207eebdcf63db4ae3ae6c52fd300 Mon Sep 17 00:00:00 2001 From: Lila Date: Mon, 16 Sep 2024 21:10:57 +0100 Subject: [PATCH 10/16] fix dsdx and dsdy --- fast64_internal/sm64/sm64_f3d_writer.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fast64_internal/sm64/sm64_f3d_writer.py b/fast64_internal/sm64/sm64_f3d_writer.py index 0134c35a0..e36be129b 100644 --- a/fast64_internal/sm64/sm64_f3d_writer.py +++ b/fast64_internal/sm64/sm64_f3d_writer.py @@ -312,10 +312,16 @@ def exportTexRectCommon(texProp, name, convertTextureData): ti.writeAll(fMaterial, fTexRect, convertTextureData) fTexRect.materials[texProp] = (fMaterial, ti.imageDims) + if use_copy_mode: + dsdx = 4 << 10 + dtdy = 1 << 10 + else: + dsdx = dtdy = 4096 // 4 + fTexRect.draw.commands.extend(fMaterial.mat_only_DL.commands) fTexRect.draw.commands.extend(fMaterial.texture_DL.commands) fTexRect.draw.commands.append( - SPScisTextureRectangle(0, 0, (ti.imageDims[0] - 1) << 2, (ti.imageDims[1] - 1) << 2, 0, 0, 0) + SPScisTextureRectangle(0, 0, (ti.imageDims[0] - 1) << 2, (ti.imageDims[1] - 1) << 2, 0, 0, 0, dsdx, dtdy) ) fTexRect.draw.commands.append(DPPipeSync()) fTexRect.draw.commands.extend(fMaterial.revert.commands) From 79a76dbb13ec0f1d5aa8a3ca7a9774c685cad73b Mon Sep 17 00:00:00 2001 From: Lila Date: Mon, 16 Sep 2024 21:57:50 +0100 Subject: [PATCH 11/16] fix overwrite data issues could not deal with aligner and palletes, now can! --- fast64_internal/f3d/f3d_gbi.py | 6 +++- fast64_internal/sm64/sm64_f3d_writer.py | 46 ++++++++++++++++++------- fast64_internal/utility.py | 5 +-- 3 files changed, 41 insertions(+), 16 deletions(-) diff --git a/fast64_internal/f3d/f3d_gbi.py b/fast64_internal/f3d/f3d_gbi.py index 22a6f3a86..d77096864 100644 --- a/fast64_internal/f3d/f3d_gbi.py +++ b/fast64_internal/f3d/f3d_gbi.py @@ -3262,6 +3262,10 @@ class FImage: isLargeTexture: bool = field(init=False, compare=False, default=False) converted: bool = field(init=False, compare=False, default=False) + @property + def aligner_name(self): + return f"{self.name}_aligner" + def size(self): return len(self.data) @@ -3280,7 +3284,7 @@ def to_c_helper(self, texData, bitsPerValue): # This is to force 8 byte alignment if bitsPerValue != 64: - code.source = f"Gfx {self.name}_aligner[] = {{gsSPEndDisplayList()}};\n" + code.source = f"Gfx {self.aligner_name}[] = {{gsSPEndDisplayList()}};\n" code.source += f"u{str(bitsPerValue)} {self.name}[] = {{\n\t" code.source += texData code.source += "\n};\n\n" diff --git a/fast64_internal/sm64/sm64_f3d_writer.py b/fast64_internal/sm64/sm64_f3d_writer.py index e36be129b..693a49700 100644 --- a/fast64_internal/sm64/sm64_f3d_writer.py +++ b/fast64_internal/sm64/sm64_f3d_writer.py @@ -1,3 +1,4 @@ +from pathlib import Path import shutil, copy, bpy, re, os from io import BytesIO from math import ceil, log, radians @@ -55,6 +56,7 @@ ) from ..utility import ( + CData, CScrollData, PluginError, raisePluginError, @@ -169,15 +171,14 @@ def exportTexRectToC(dirPath, texProp, texDir, savePNG, name, exportToProject, p if name is None or name == "": raise PluginError("Name cannot be empty.") - exportData = fTexRect.to_c(savePNG, texDir, SM64GfxFormatter(ScrollMethod.Vertex)) - staticData = exportData.staticData - dynamicData = exportData.dynamicData + formater = SM64GfxFormatter(ScrollMethod.Vertex) - declaration = staticData.header code = modifyDLForHUD(dynamicData.source) - data = staticData.source if exportToProject: + dynamicData = CData() + dynamicData.append(fTexRect.draw.to_c(fTexRect.f3d)) + seg2CPath = os.path.join(dirPath, "bin/segment2.c") seg2HPath = os.path.join(dirPath, "src/game/segment2.h") seg2TexDir = os.path.join(dirPath, "textures/segment2") @@ -188,22 +189,41 @@ def exportTexRectToC(dirPath, texProp, texDir, savePNG, name, exportToProject, p checkIfPathExists(seg2TexDir) checkIfPathExists(hudPath) - fTexRect.save_textures(seg2TexDir) + if savePNG: + fTexRect.save_textures(seg2TexDir) - textures = [] + include_dir = Path(texDir).as_posix() + "/" for _, fImage in fTexRect.textures.items(): - textures.append(fImage) - - # Append/Overwrite texture definition to segment2.c - overwriteData("const\s*u8\s*", textures[0].name, data, seg2CPath, None, False) + if savePNG: + data = fImage.to_c_tex_separate(include_dir, formater.texArrayBitSize) + else: + data = fImage.to_c(formater.texArrayBitSize) + + # Append/Overwrite texture definition to segment2.c + overwriteData( + f"(Gfx\s*{fImage.aligner_name}\[\]\s*=\s*{{gsSPEndDisplayList\(\)}};\s*)?u{str(formater.texArrayBitSize)}\s*", + fImage.name, + data.source, + seg2CPath, + None, + False, + post_regex="\s?\s?", # tex to c includes 2 newlines + ) - # Append texture declaration to segment2.h - writeIfNotFound(seg2HPath, declaration, "#endif") + # Append texture declaration to segment2.h + writeIfNotFound(seg2HPath, data.header, "#endif") # Write/Overwrite function to hud.c overwriteData("void\s*", fTexRect.name, code, hudPath, projectExportData[1], True) else: + exportData = fTexRect.to_c(savePNG, texDir, formater) + staticData = exportData.staticData + dynamicData = exportData.dynamicData + + declaration = staticData.header + data = staticData.source + singleFileData = "" singleFileData += "// Copy this function to src/game/hud.c or src/game/ingame_menu.c.\n" singleFileData += "// Call the function in render_hud() or render_menus_and_dialogs() respectively.\n" diff --git a/fast64_internal/utility.py b/fast64_internal/utility.py index 14f6aea59..f47b9dc70 100644 --- a/fast64_internal/utility.py +++ b/fast64_internal/utility.py @@ -712,7 +712,7 @@ def getExportDir(customExport, dirPath, headerType, levelName, texDir, dirName): return dirPath, texDir -def overwriteData(headerRegex, name, value, filePath, writeNewBeforeString, isFunction): +def overwriteData(headerRegex, name, value, filePath, writeNewBeforeString, isFunction, post_regex=""): if os.path.exists(filePath): dataFile = open(filePath, "r") data = dataFile.read() @@ -721,7 +721,8 @@ def overwriteData(headerRegex, name, value, filePath, writeNewBeforeString, isFu matchResult = re.search( headerRegex + re.escape(name) - + ("\s*\((((?!\)).)*)\)\s*\{(((?!\}).)*)\}" if isFunction else "\[\]\s*=\s*\{(((?!;).)*);"), + + ("\s*\((((?!\)).)*)\)\s*\{(((?!\}).)*)\}" if isFunction else "\[\]\s*=\s*\{(((?!;).)*);") + + post_regex, data, re.DOTALL, ) From 0742dfd7fce2445a1d5b5fc7f298445496929935 Mon Sep 17 00:00:00 2001 From: Lila Date: Mon, 16 Sep 2024 22:00:42 +0100 Subject: [PATCH 12/16] sauren nitpicks --- fast64_internal/f3d/f3d_texture_writer.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fast64_internal/f3d/f3d_texture_writer.py b/fast64_internal/f3d/f3d_texture_writer.py index b35e17b2c..8af1ffa0f 100644 --- a/fast64_internal/f3d/f3d_texture_writer.py +++ b/fast64_internal/f3d/f3d_texture_writer.py @@ -464,7 +464,7 @@ def fromProp(self, texProp: TextureProperty, index: int, ignore_tex_set=False) - return True def materialless_setup(self) -> None: - """moreSetupFromModel equivelent that does not handle material properties like OOT flipbooks""" + """moreSetupFromModel equivalent that does not handle material properties like OOT flipbooks""" if not self.useTex: return @@ -485,7 +485,8 @@ def materialless_setup(self) -> None: f"Error in Texture {self.indexInMat} uses too many unique colors to fit in format {self.texFormat}." ) else: - self.imDependencies, self.flipbook = [] if self.texProp.tex is None else [self.texProp.tex], None + self.imDependencies = [] if self.texProp.tex is None else [self.texProp.tex] + self.flipbook = None self.isPalRef = self.isTexRef and self.flipbook is None self.palDependencies = self.imDependencies From 7e9a909488cf7e1e7bc4fe45c27e9994cef24a24 Mon Sep 17 00:00:00 2001 From: Lila Date: Wed, 18 Sep 2024 21:02:10 +0100 Subject: [PATCH 13/16] fix first test --- fast64_internal/sm64/sm64_f3d_writer.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/fast64_internal/sm64/sm64_f3d_writer.py b/fast64_internal/sm64/sm64_f3d_writer.py index 693a49700..d61cc2f98 100644 --- a/fast64_internal/sm64/sm64_f3d_writer.py +++ b/fast64_internal/sm64/sm64_f3d_writer.py @@ -173,12 +173,11 @@ def exportTexRectToC(dirPath, texProp, texDir, savePNG, name, exportToProject, p formater = SM64GfxFormatter(ScrollMethod.Vertex) + dynamicData = CData() + dynamicData.append(fTexRect.draw.to_c(fTexRect.f3d)) code = modifyDLForHUD(dynamicData.source) if exportToProject: - dynamicData = CData() - dynamicData.append(fTexRect.draw.to_c(fTexRect.f3d)) - seg2CPath = os.path.join(dirPath, "bin/segment2.c") seg2HPath = os.path.join(dirPath, "src/game/segment2.h") seg2TexDir = os.path.join(dirPath, "textures/segment2") @@ -219,7 +218,6 @@ def exportTexRectToC(dirPath, texProp, texDir, savePNG, name, exportToProject, p else: exportData = fTexRect.to_c(savePNG, texDir, formater) staticData = exportData.staticData - dynamicData = exportData.dynamicData declaration = staticData.header data = staticData.source From 8e1c35958387495302293067fe3e1f7a2a315783 Mon Sep 17 00:00:00 2001 From: Lila Date: Wed, 18 Sep 2024 21:22:11 +0100 Subject: [PATCH 14/16] Update f3d_texture_writer.py --- fast64_internal/f3d/f3d_texture_writer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fast64_internal/f3d/f3d_texture_writer.py b/fast64_internal/f3d/f3d_texture_writer.py index 8af1ffa0f..eabafd92c 100644 --- a/fast64_internal/f3d/f3d_texture_writer.py +++ b/fast64_internal/f3d/f3d_texture_writer.py @@ -540,7 +540,7 @@ def setup_single_tex(self, is_ci: bool, use_large_tex: bool): if self.useTex: self.loadPal = True self.palBaseName = self.getPaletteName() - if self.tmemSize >= tmem_size: + if self.tmemSize > tmem_size: if use_large_tex: self.doTexLoad = False return True From 26159b6d8589b431e46f11dd1f188e25a6e2f62f Mon Sep 17 00:00:00 2001 From: Lila Date: Wed, 18 Sep 2024 21:43:56 +0100 Subject: [PATCH 15/16] make the regex allow even more whitespace --- fast64_internal/sm64/sm64_f3d_writer.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fast64_internal/sm64/sm64_f3d_writer.py b/fast64_internal/sm64/sm64_f3d_writer.py index d61cc2f98..accd504a3 100644 --- a/fast64_internal/sm64/sm64_f3d_writer.py +++ b/fast64_internal/sm64/sm64_f3d_writer.py @@ -200,7 +200,8 @@ def exportTexRectToC(dirPath, texProp, texDir, savePNG, name, exportToProject, p # Append/Overwrite texture definition to segment2.c overwriteData( - f"(Gfx\s*{fImage.aligner_name}\[\]\s*=\s*{{gsSPEndDisplayList\(\)}};\s*)?u{str(formater.texArrayBitSize)}\s*", + rf"(Gfx\s+{fImage.aligner_name}\s*\[\s*\]\s*=\s*\{{\s*gsSPEndDisplayList\s*\(\s*\)\s*\}}\s*;\s*)?" + rf"u{str(formater.texArrayBitSize)}\s*", fImage.name, data.source, seg2CPath, From 061e451bc265b6ce309fb22a287698b519bee1f6 Mon Sep 17 00:00:00 2001 From: Lila Date: Thu, 19 Sep 2024 08:51:21 +0100 Subject: [PATCH 16/16] fix extra new lines --- fast64_internal/sm64/sm64_f3d_writer.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fast64_internal/sm64/sm64_f3d_writer.py b/fast64_internal/sm64/sm64_f3d_writer.py index accd504a3..e71c3202a 100644 --- a/fast64_internal/sm64/sm64_f3d_writer.py +++ b/fast64_internal/sm64/sm64_f3d_writer.py @@ -207,14 +207,14 @@ def exportTexRectToC(dirPath, texProp, texDir, savePNG, name, exportToProject, p seg2CPath, None, False, - post_regex="\s?\s?", # tex to c includes 2 newlines + post_regex=r"\s?\s?", # tex to c includes 2 newlines ) # Append texture declaration to segment2.h writeIfNotFound(seg2HPath, data.header, "#endif") # Write/Overwrite function to hud.c - overwriteData("void\s*", fTexRect.name, code, hudPath, projectExportData[1], True) + overwriteData("void\s*", fTexRect.name, code, hudPath, projectExportData[1], True, post_regex=r"\s?") else: exportData = fTexRect.to_c(savePNG, texDir, formater) @@ -296,7 +296,7 @@ def modifyDLForHUD(data): # data = data[:matchResult.start(7)] + 'segmented_to_virtual(&' + \ # matchResult.group(7) + ")" +data[matchResult.end(7):] - return data + return data.removesuffix("\n") def exportTexRectCommon(texProp, name, convertTextureData):