From 69d52c5f1c302a710ca2ceada9bbf705dc228411 Mon Sep 17 00:00:00 2001 From: Chris Blackbourn Date: Sat, 29 Apr 2023 10:24:23 +1200 Subject: [PATCH] UV: Fix uv packing overflow with fraction margin method When UV Packing with the `fraction` margin method, if the UVs overflowed the unit square, the UVs could sometimes overlap. (island_index was incorrect.) --- source/blender/geometry/intern/uv_pack.cc | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/source/blender/geometry/intern/uv_pack.cc b/source/blender/geometry/intern/uv_pack.cc index df46dc0db04..a159de1ccca 100644 --- a/source/blender/geometry/intern/uv_pack.cc +++ b/source/blender/geometry/intern/uv_pack.cc @@ -884,7 +884,8 @@ static void pack_island_xatlas(const Span island_indices, float max_u = 0.0f; float max_v = 0.0f; - int scan_line = 0; + int scan_line = 0; /* Current "scan_line" of occupancy bitmap. */ + int traced_islands = 0; /* Which islands are currently traced in `occupancy`. */ int i = 0; /* The following `while` loop is setting up a three-way race: @@ -894,6 +895,14 @@ static void pack_island_xatlas(const Span island_indices, */ while (i < island_indices.size()) { + + while (traced_islands < i) { + /* Trace an island that's been solved. (Greedy.) */ + const int64_t island_index = island_indices[traced_islands]->index; + occupancy.trace_island(islands[island_index], r_phis[island_index], scale, margin, true); + traced_islands++; + } + PackIsland *island = islands[island_indices[i]->index]; uv_phi phi; @@ -930,17 +939,12 @@ static void pack_island_xatlas(const Span island_indices, /* Enlarge search parameters. */ scan_line = 0; occupancy.increase_scale(); - - /* Redraw already placed islands. (Greedy.) */ - for (int j = 0; j < i; j++) { - occupancy.trace_island(islands[island_indices[j]->index], r_phis[j], scale, margin, true); - } + traced_islands = 0; /* Will trigger a re-trace of previously solved islands. */ continue; } /* Place island. */ r_phis[island_indices[i]->index] = phi; - occupancy.trace_island(island, phi, scale, margin, true); i++; /* Next island. */ /* Update top-right corner. */