UV: Improve layout when alpaca is tighter than slow packers

When packing the largest islands, if the alpaca turns out to be tighter
than all of the other packers, then use alpaca on the large islands
and small islands together in one pass instead of two.
This commit is contained in:
Chris Blackbourn
2023-06-14 19:24:04 +12:00
parent a783fe8198
commit b8d263ee5a

View File

@@ -1829,6 +1829,7 @@ static float pack_islands_scale_margin(const Span<PackIsland *> islands,
params.target_aspect_y,
r_phis,
&extent);
rctf fast_extent = extent; /* Remember how large the "fast" packer was. */
/* Call the "optimal" packer. */
if (locked_island_count == 0) {
@@ -1847,13 +1848,19 @@ static float pack_islands_scale_margin(const Span<PackIsland *> islands,
slow_aabbs = aabbs.as_span().take_front(max_xatlas);
}
/* At this stage, `extent` contains the optimal/box_pack/xatlas UVs. */
/* At this stage, `extent` contains the fast/optimal/box_pack/xatlas UVs. */
if (all_can_rotate) {
/* Attempt to improve the layout even further by finding the minimal-bounding-square. */
rotate_inside_square(slow_aabbs, islands, params, scale, margin, r_phis, &extent);
}
if (!memcmp(&extent, &fast_extent, sizeof(rctf))) {
/* The fast packer was the best so far. Lets just use the fast packer for everything. */
slow_aabbs = slow_aabbs.take_front(locked_island_count);
extent = locked_bounds;
}
/* Call fast packer for remaining islands, excluding everything already placed. */
rctf final_extent = {0.0f, 1e30f, 0.0f, 1e30f};
pack_islands_fast(slow_aabbs.size(),