Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed large uv wrapping #249

Merged
merged 6 commits into from
Feb 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions fast64_internal/f3d/f3d_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,29 @@ def getInfoDict(obj):
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 @@ -168,12 +191,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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To reiterate on my previous comments why "highest"? There must be a piece of code elsewhere on exporting that handles this similarly? Where

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There isn´t because this is doing something else, we don´t need to account for texture resolutions and what not, so there is no function which does this behavior specifically.

UVinterval = getUVInterval(material.f3d_mat)

size = texSizeDict[material]
if size[0] == 0 or size[1] == 0:
Expand Down