Skip to content

Commit 8a0629c

Browse files
committed
- Minor edge case cleanup on UV quadrant forcing.
1 parent aaf1398 commit 8a0629c

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

xivModdingFramework/Models/Helpers/ModelModifiers.cs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -738,18 +738,41 @@ public static void ForceUVQuadrant(TTModel model, Action<bool, string> loggingFu
738738
{
739739
foreach(var p in m.Parts)
740740
{
741-
foreach(var v in p.Vertices)
741+
bool anyNegativeX = p.Vertices.Any(x => x.UV1.X < 0);
742+
bool anyPositiveY = p.Vertices.Any(x => x.UV1.Y > 0);
743+
foreach (var v in p.Vertices)
742744
{
743745

744-
v.UV1.X = (v.UV1.X % 1);
745-
v.UV1.Y = (v.UV1.Y % 1);
746+
// Edge case to prevent shoving things at exactly 1.0 to 0.0
747+
if (Math.Abs(v.UV1.X) != 1)
748+
{
749+
v.UV1.X = (v.UV1.X % 1);
750+
}
751+
752+
if (Math.Abs(v.UV1.Y) != 1)
753+
{
754+
v.UV1.Y = (v.UV1.Y % 1);
755+
}
756+
757+
// The extra [anyPositive/negative] values check is to avoid potentially
758+
// shifting values at exactly 0 if 0 is effectively the "top" of the
759+
// used UV space.
760+
761+
// The goal here is to allow the user to have used any exact quadrant in the [-1 - 1, -1 - 1] range
762+
// and maintain the UV correctly, even if they used exactly [1,1] as a coordinate, for example.
763+
764+
// If the user has the UV's arbitrarily split over multiple quadrants, though, then
765+
// the exact points [1,1] for example, become unstable, and end up forced to [0,0]
766+
// No particularly sane way around that though without doing really invasive math to compare connected UVs, etc.
746767

747-
if (v.UV1.X < 0)
768+
// Shove things over into positive quadrant.
769+
if (v.UV1.X <= 0 && anyNegativeX)
748770
{
749771
v.UV1.X += 1;
750772
}
751773

752-
if (v.UV1.Y > 0)
774+
// Shove things over into negative quadrant.
775+
if (v.UV1.Y >= 0 && anyPositiveY)
753776
{
754777
v.UV1.Y -= 1;
755778
}

0 commit comments

Comments
 (0)