From 655160a1c9296ff3456d7583b94c2abdb6bdf567 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Sat, 7 Dec 2024 17:21:52 +0900 Subject: [PATCH] fix: error with UV at very edge --- Editor/Processors/TraceAndOptimize/OptimizeTexture.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Editor/Processors/TraceAndOptimize/OptimizeTexture.cs b/Editor/Processors/TraceAndOptimize/OptimizeTexture.cs index 1877d081..c1b8a4ea 100644 --- a/Editor/Processors/TraceAndOptimize/OptimizeTexture.cs +++ b/Editor/Processors/TraceAndOptimize/OptimizeTexture.cs @@ -740,10 +740,11 @@ private void FitToBlockSizeAndAddPadding(List islands, float blockS ref var max = ref island.MaxPos; // fit to block size - min.x = Mathf.Floor(min.x / blockSizeRatioX - paddingRatio) * blockSizeRatioX; - min.y = Mathf.Floor(min.y / blockSizeRatioY - paddingRatio) * blockSizeRatioY; - max.x = Mathf.Ceil(max.x / blockSizeRatioX + paddingRatio) * blockSizeRatioX; - max.y = Mathf.Ceil(max.y / blockSizeRatioY + paddingRatio) * blockSizeRatioY; + // if rest texture size is less than padding, fit to the UV coordinate + min.x = Mathf.Max(Mathf.Floor(min.x / blockSizeRatioX - paddingRatio) * blockSizeRatioX, 0); + min.y = Mathf.Max(Mathf.Floor(min.y / blockSizeRatioY - paddingRatio) * blockSizeRatioY, 0); + max.x = Mathf.Min(Mathf.Ceil(max.x / blockSizeRatioX + paddingRatio) * blockSizeRatioX, 1); + max.y = Mathf.Min(Mathf.Ceil(max.y / blockSizeRatioY + paddingRatio) * blockSizeRatioY, 1); } }