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 2 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
36 changes: 28 additions & 8 deletions fast64_internal/f3d/f3d_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,29 @@ def getInfoDict(obj):
return infoDict


def getSTUVRepeats(tex_prop: "TextureProperty") :
jesusyoshi54 marked this conversation as resolved.
Show resolved Hide resolved
SShift, TShift = 2 ** tex_prop.S.shift, 2 ** tex_prop.T.shift
jesusyoshi54 marked this conversation as resolved.
Show resolved Hide resolved
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]:
Lilaa3 marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this behaves as expected if e.g. tex0 has shift=0 mirror=True and tex1 has shift=1 mirror=False

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

When shift is 0, SShift will be 1, because 2^0 is 1. What´s wrong here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The result of your case should be 2.

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:
Expand Down Expand Up @@ -169,12 +192,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 Expand Up @@ -320,7 +340,7 @@ def saveMeshWithLargeTexturesByFaces(
firstFace = False

triGroup.triList.commands.append(SPEndDisplayList())

if fMaterial.revert is not None:
fMesh.draw.commands.append(SPDisplayList(fMaterial.revert))

Expand Down Expand Up @@ -1359,7 +1379,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)
Expand Down