Skip to content

Commit d2db4fe

Browse files
committed
Correct UV Force Math. (Math.Abs was wrong)
1 parent 53f2f6e commit d2db4fe

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

xivModdingFramework/Models/Helpers/ModelModifiers.cs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -570,14 +570,16 @@ public static void ClearShapeData(TTModel ttModel, Action<bool, string> loggingF
570570
ttModel.MeshGroups.ForEach(x => x.ShapeParts.Clear());
571571
}
572572

573-
// Forces all UV Coordinates in UV1 Layer to [1,-1] Quadrant.
573+
// Forces all UV Coordinates in UV1 Layer to [1,1] (pre-flip) Quadrant.
574574
public static void ForceUVQuadrant(TTModel model, Action<bool, string> loggingFunction = null)
575575
{
576576
if (loggingFunction == null)
577577
{
578578
loggingFunction = NoOp;
579579
}
580580

581+
MakeExportReady(model, loggingFunction);
582+
581583
loggingFunction(false, "Forcing UV1 to [1,-1]...");
582584
foreach(var m in model.MeshGroups)
583585
{
@@ -586,11 +588,37 @@ public static void ForceUVQuadrant(TTModel model, Action<bool, string> loggingFu
586588
foreach(var v in p.Vertices)
587589
{
588590

589-
v.UV1.X = Math.Abs((v.UV1.X % 1));
590-
v.UV1.Y = Math.Abs((v.UV1.Y % 1));
591+
v.UV1.X = (v.UV1.X % 1);
592+
v.UV1.Y = (v.UV1.Y % 1);
593+
594+
if (v.UV1.X < 0)
595+
{
596+
v.UV1.X += 1;
597+
}
598+
599+
if (v.UV1.Y > 0)
600+
{
601+
v.UV1.Y -= 1;
602+
}
603+
}
604+
}
605+
}
606+
607+
// Tangents have to be recalculated because we moved the UVs.
608+
foreach (var m in model.MeshGroups)
609+
{
610+
foreach (var p in m.Parts)
611+
{
612+
foreach (var v in p.Vertices)
613+
{
614+
v.Tangent = Vector3.Zero;
615+
v.Binormal = Vector3.Zero;
616+
v.Handedness = false;
591617
}
592618
}
593619
}
620+
MakeImportReady(model, loggingFunction);
621+
594622
}
595623

596624
// Resets UV2 to [0,0]

0 commit comments

Comments
 (0)