From 117ac4241231c9f4fdf19c7f10a4d201e8facbb9 Mon Sep 17 00:00:00 2001 From: Lilaa3 <87947656+Lilaa3@users.noreply.github.com> Date: Thu, 7 Sep 2023 18:08:51 +0100 Subject: [PATCH 1/5] Fixed large UV valid bounds wrapping Arthur suggested this a solution. --- fast64_internal/f3d/f3d_writer.py | 37 ++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/fast64_internal/f3d/f3d_writer.py b/fast64_internal/f3d/f3d_writer.py index d0d952901..4f3edabff 100644 --- a/fast64_internal/f3d/f3d_writer.py +++ b/fast64_internal/f3d/f3d_writer.py @@ -12,6 +12,7 @@ isTexturePointSampled, isLightingDisabled, checkIfFlatShaded, + shift_num, ) from .f3d_texture_writer import MultitexManager, TileLoad, maybeSaveSingleLargeTextureSetup from .f3d_gbi import * @@ -140,6 +141,29 @@ def getInfoDict(obj): return infoDict +def getSTUVRepeats(tex_prop: "TextureProperty") : + SShift, TShift = 2 ** tex_prop.S.shift, 2 ** tex_prop.T.shift + sMirrorScale = 2 if tex_prop.S.mirror else 1 + tMirrorScale = 2 if tex_prop.T.mirror else 1 + return (SShift * sMirrorScale, TShift * tMirrorScale) + + +def getUVInterval(f3dMat) -> tuple[int, int]: + useDict = all_combiner_uses(f3dMat) + + if useDict["Texture 0"] and f3dMat.tex0.tex_set: + tex0UVInterval = getSTUVRepeats(f3dMat.tex0) + else: + tex0UVInterval = (1, 1) + + if useDict["Texture 1"] and f3dMat.tex1.tex_set: + tex1UVInterval = getSTUVRepeats(f3dMat.tex1) + else: + tex1UVInterval = (1, 1) + + return (max(tex0UVInterval[0], tex1UVInterval[0]), max(tex0UVInterval[1], tex1UVInterval[1])) + + def fixLargeUVs(obj): mesh = obj.data if len(obj.data.uv_layers) == 0: @@ -169,12 +193,9 @@ def fixLargeUVs(obj): if material.f3d_mat.use_large_textures: continue - f3dMat = material.f3d_mat - - UVinterval = [ - 2 if f3dMat.tex0.S.mirror or f3dMat.tex1.S.mirror else 1, - 2 if f3dMat.tex0.T.mirror or f3dMat.tex1.T.mirror else 1, - ] + # To prevent wrong UVs when wrapping UVs into valid bounds, + # we need to account for the highest texture shift and if mirroring is active. + UVinterval = getUVInterval(material.f3d_mat) size = texSizeDict[material] if size[0] == 0 or size[1] == 0: @@ -320,7 +341,7 @@ def saveMeshWithLargeTexturesByFaces( firstFace = False triGroup.triList.commands.append(SPEndDisplayList()) - + if fMaterial.revert is not None: fMesh.draw.commands.append(SPDisplayList(fMaterial.revert)) @@ -1359,7 +1380,7 @@ def saveOrGetF3DMaterial(material, fModel, obj, drawLayer, convertTextureData): defaults, fModel.f3d._HW_VERSION_1, fModel.matWriteMethod, - fModel.f3d + fModel.f3d, ) saveOtherModeLDefinition(fMaterial, f3dMat.rdp_settings, defaults, defaultRM, fModel.matWriteMethod, fModel.f3d) saveOtherDefinition(fMaterial, f3dMat, defaults) From 638e1d10d9773522799f17563dfbb1cc14409851 Mon Sep 17 00:00:00 2001 From: Lilaa3 <87947656+Lilaa3@users.noreply.github.com> Date: Fri, 8 Sep 2023 20:58:16 +0100 Subject: [PATCH 2/5] Unused import --- fast64_internal/f3d/f3d_writer.py | 1 - 1 file changed, 1 deletion(-) diff --git a/fast64_internal/f3d/f3d_writer.py b/fast64_internal/f3d/f3d_writer.py index 4f3edabff..41d6536c3 100644 --- a/fast64_internal/f3d/f3d_writer.py +++ b/fast64_internal/f3d/f3d_writer.py @@ -12,7 +12,6 @@ isTexturePointSampled, isLightingDisabled, checkIfFlatShaded, - shift_num, ) from .f3d_texture_writer import MultitexManager, TileLoad, maybeSaveSingleLargeTextureSetup from .f3d_gbi import * From 6e56d0776ef7f1154f423be04a157a715654b1ae Mon Sep 17 00:00:00 2001 From: Lilaa3 <87947656+Lilaa3@users.noreply.github.com> Date: Sat, 9 Sep 2023 01:12:20 +0100 Subject: [PATCH 3/5] Small explicit type correction --- fast64_internal/f3d/f3d_writer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fast64_internal/f3d/f3d_writer.py b/fast64_internal/f3d/f3d_writer.py index 41d6536c3..36ed74ccb 100644 --- a/fast64_internal/f3d/f3d_writer.py +++ b/fast64_internal/f3d/f3d_writer.py @@ -147,7 +147,7 @@ def getSTUVRepeats(tex_prop: "TextureProperty") : return (SShift * sMirrorScale, TShift * tMirrorScale) -def getUVInterval(f3dMat) -> tuple[int, int]: +def getUVInterval(f3dMat) -> tuple[float, float]: useDict = all_combiner_uses(f3dMat) if useDict["Texture 0"] and f3dMat.tex0.tex_set: From 24cb921703d82d259ffd179882378d8fa1346dd0 Mon Sep 17 00:00:00 2001 From: Lilaa3 <87947656+Lilaa3@users.noreply.github.com> Date: Thu, 18 Jan 2024 14:27:48 +0000 Subject: [PATCH 4/5] Fixed formatting --- fast64_internal/f3d/f3d_writer.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/fast64_internal/f3d/f3d_writer.py b/fast64_internal/f3d/f3d_writer.py index 36ed74ccb..21dc55db3 100644 --- a/fast64_internal/f3d/f3d_writer.py +++ b/fast64_internal/f3d/f3d_writer.py @@ -140,8 +140,8 @@ def getInfoDict(obj): return infoDict -def getSTUVRepeats(tex_prop: "TextureProperty") : - SShift, TShift = 2 ** tex_prop.S.shift, 2 ** tex_prop.T.shift +def getSTUVRepeats(tex_prop: "TextureProperty"): + SShift, TShift = 2**tex_prop.S.shift, 2**tex_prop.T.shift sMirrorScale = 2 if tex_prop.S.mirror else 1 tMirrorScale = 2 if tex_prop.T.mirror else 1 return (SShift * sMirrorScale, TShift * tMirrorScale) @@ -149,7 +149,7 @@ def getSTUVRepeats(tex_prop: "TextureProperty") : def getUVInterval(f3dMat) -> tuple[float, float]: useDict = all_combiner_uses(f3dMat) - + if useDict["Texture 0"] and f3dMat.tex0.tex_set: tex0UVInterval = getSTUVRepeats(f3dMat.tex0) else: @@ -204,7 +204,6 @@ def fixLargeUVs(obj): uvOffset = [0, 0] for i in range(2): - # Move any UVs close to or straddling edge minDiff = (-cellSize[i] + 2) - minUV[i] if minDiff > 0: @@ -1144,7 +1143,6 @@ def is3_2_or_above(): def getLoopColor(loop: bpy.types.MeshLoop, mesh, mat_ver): - color_layer = getColorLayer(mesh, layer="Col") alpha_layer = getColorLayer(mesh, layer="Alpha") @@ -1840,7 +1838,6 @@ def getWriteMethodFromEnum(enumVal): def exportF3DtoC( dirPath, obj, DLFormat, transformMatrix, f3dType, isHWv1, texDir, savePNG, texSeparate, name, matWriteMethod ): - inline = bpy.context.scene.exportInlineF3D fModel = FModel(f3dType, isHWv1, name, DLFormat, matWriteMethod if not inline else GfxMatWriteMethod.WriteAll) fMeshes = exportF3DCommon(obj, fModel, transformMatrix, True, name, DLFormat, not savePNG) From f2b1d3d948758ef8c49aa3c28dcd5de6976d517c Mon Sep 17 00:00:00 2001 From: Lilaa3 <87947656+Lilaa3@users.noreply.github.com> Date: Thu, 18 Jan 2024 14:39:49 +0000 Subject: [PATCH 5/5] Type hints MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit getSTUVRepeats couldnĀ“t auto type hint, getUVInverval can. Use 1.0 instead of 1 --- fast64_internal/f3d/f3d_writer.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fast64_internal/f3d/f3d_writer.py b/fast64_internal/f3d/f3d_writer.py index 21dc55db3..b44baadb2 100644 --- a/fast64_internal/f3d/f3d_writer.py +++ b/fast64_internal/f3d/f3d_writer.py @@ -140,25 +140,25 @@ def getInfoDict(obj): return infoDict -def getSTUVRepeats(tex_prop: "TextureProperty"): +def getSTUVRepeats(tex_prop: "TextureProperty") -> tuple[float, float]: SShift, TShift = 2**tex_prop.S.shift, 2**tex_prop.T.shift sMirrorScale = 2 if tex_prop.S.mirror else 1 tMirrorScale = 2 if tex_prop.T.mirror else 1 return (SShift * sMirrorScale, TShift * tMirrorScale) -def getUVInterval(f3dMat) -> tuple[float, float]: +def getUVInterval(f3dMat): useDict = all_combiner_uses(f3dMat) if useDict["Texture 0"] and f3dMat.tex0.tex_set: tex0UVInterval = getSTUVRepeats(f3dMat.tex0) else: - tex0UVInterval = (1, 1) + tex0UVInterval = (1.0, 1.0) if useDict["Texture 1"] and f3dMat.tex1.tex_set: tex1UVInterval = getSTUVRepeats(f3dMat.tex1) else: - tex1UVInterval = (1, 1) + tex1UVInterval = (1.0, 1.0) return (max(tex0UVInterval[0], tex1UVInterval[0]), max(tex0UVInterval[1], tex1UVInterval[1]))