Skip to content

Commit

Permalink
Fixed large uv wrapping (#249)
Browse files Browse the repository at this point in the history
* Fixed large UV valid bounds wrapping

Arthur suggested this a solution.

* Unused import

* Small explicit type correction

* Fixed formatting

* Type hints

getSTUVRepeats couldn´t auto type hint, getUVInverval can.
Use 1.0 instead of 1
  • Loading branch information
Lilaa3 authored Feb 14, 2024
1 parent c7ee1fb commit 4f621f4
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions fast64_internal/f3d/f3d_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,29 @@ def getInfoDict_impl(obj: bpy.types.Object):
return infoDict


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):
useDict = all_combiner_uses(f3dMat)

if useDict["Texture 0"] and f3dMat.tex0.tex_set:
tex0UVInterval = getSTUVRepeats(f3dMat.tex0)
else:
tex0UVInterval = (1.0, 1.0)

if useDict["Texture 1"] and f3dMat.tex1.tex_set:
tex1UVInterval = getSTUVRepeats(f3dMat.tex1)
else:
tex1UVInterval = (1.0, 1.0)

return (max(tex0UVInterval[0], tex1UVInterval[0]), max(tex0UVInterval[1], tex1UVInterval[1]))


def fixLargeUVs(obj):
mesh = obj.data
if len(obj.data.uv_layers) == 0:
Expand Down Expand Up @@ -232,12 +255,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:
Expand Down

0 comments on commit 4f621f4

Please sign in to comment.