UV: Improve UV Packing efficiency with non-square aspect ratio #105784

Merged
Chris Blackbourn merged 3 commits from Chris_Blackbourn/blender:uv-pack-aspect-ratio into main 2023-03-15 21:29:43 +01:00
1 changed files with 7 additions and 1 deletions

View File

@ -1164,6 +1164,8 @@ static void face_island_uv_rotate_fit_aabb(FaceIsland *island)
}
}
/* As the UV Packing API doesn't yet support rotation, we need
* to pre-rotate each island into the smallest AABB. */
float angle = BLI_convexhull_aabb_fit_points_2d(coords, coords_len);
/* Rotate coords by `angle` before computing bounding box. */
@ -1184,9 +1186,13 @@ static void face_island_uv_rotate_fit_aabb(FaceIsland *island)
minmax_v2v2_v2(bounds_min, bounds_max, coords[i]);
}
/* "Stand-up" islands.

What is the meaning of the squared aspect ratio here? Deserves a comment if this is correct.

What is the meaning of the squared aspect ratio here? Deserves a comment if this is correct.
* If we rotate the AABB by 90 degrees, the aspect ratio correction for the X axis will be

Don't add twitter links in Blender code, you can mention it in the pull request description instead.

Don't add twitter links in Blender code, you can mention it in the pull request description instead.
* `aspect_y` and for the Y axis will be `1.0f / aspect_y`. Applying both corrections gives
* a combined factor of `aspect_y / (1.0f / aspect_y) == aspect_y * aspect_y`. */
float size[2];
sub_v2_v2v2(size, bounds_max, bounds_min);
if (size[1] < size[0]) {
if (size[1] < size[0] * (aspect_y * aspect_y)) {
angle += DEG2RADF(90.0f);
}