@@ -738,18 +738,41 @@ public static void ForceUVQuadrant(TTModel model, Action<bool, string> loggingFu
738
738
{
739
739
foreach ( var p in m . Parts )
740
740
{
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 )
742
744
{
743
745
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.
746
767
747
- if ( v . UV1 . X < 0 )
768
+ // Shove things over into positive quadrant.
769
+ if ( v . UV1 . X <= 0 && anyNegativeX )
748
770
{
749
771
v . UV1 . X += 1 ;
750
772
}
751
773
752
- if ( v . UV1 . Y > 0 )
774
+ // Shove things over into negative quadrant.
775
+ if ( v . UV1 . Y >= 0 && anyPositiveY )
753
776
{
754
777
v . UV1 . Y -= 1 ;
755
778
}
0 commit comments