Cleanup: simplify uv packing api
This commit is contained in:
@@ -1388,7 +1388,6 @@ static void uvedit_pack_islands_multi(const Scene *scene,
|
||||
for (int i = 0; i < island_vector.size(); i++) {
|
||||
FaceIsland *face_island = island_vector[i];
|
||||
blender::geometry::PackIsland *pack_island = new blender::geometry::PackIsland();
|
||||
pack_island->bounds_rect = face_island->bounds_rect;
|
||||
pack_island->caller_index = i;
|
||||
pack_island->aspect_y = face_island->aspect_y;
|
||||
pack_island->angle = 0.0f;
|
||||
|
@@ -72,7 +72,7 @@ class UVPackIsland_Params {
|
||||
|
||||
class PackIsland {
|
||||
public:
|
||||
/** Bounding rectangle of input. Will be calculated automatically in a future update. */
|
||||
/** Calculated automatically. */
|
||||
rctf bounds_rect;
|
||||
/** Aspect ratio, required for rotation. */
|
||||
float aspect_y;
|
||||
|
@@ -7,6 +7,7 @@
|
||||
#include "GEO_uv_pack.hh"
|
||||
|
||||
#include "BLI_array.hh"
|
||||
#include "BLI_bounds.hh"
|
||||
#include "BLI_boxpack_2d.h"
|
||||
#include "BLI_convexhull_2d.h"
|
||||
#include "BLI_listbase.h"
|
||||
@@ -125,6 +126,7 @@ void PackIsland::add_polygon(const blender::Span<float2> uvs, MemArena *arena, H
|
||||
void PackIsland::finalize_geometry(const UVPackIsland_Params ¶ms, MemArena *arena, Heap *heap)
|
||||
{
|
||||
BLI_assert(triangle_vertices_.size() >= 3);
|
||||
|
||||
const eUVPackIsland_ShapeMethod shape_method = params.shape_method;
|
||||
if (shape_method == ED_UVPACK_SHAPE_CONVEX) {
|
||||
/* Compute convex hull of existing triangles. */
|
||||
@@ -154,6 +156,17 @@ void PackIsland::finalize_geometry(const UVPackIsland_Params ¶ms, MemArena *
|
||||
|
||||
BLI_heap_clear(heap, nullptr);
|
||||
}
|
||||
|
||||
Bounds<float2> triangle_bounds = *bounds::min_max(triangle_vertices_.as_span());
|
||||
float2 aabb_min = triangle_bounds.min;
|
||||
float2 aabb_max = triangle_bounds.max;
|
||||
float2 pivot = (aabb_min + aabb_max) * 0.5f;
|
||||
float2 half_diagonal = (aabb_max - aabb_min) * 0.5f;
|
||||
|
||||
bounds_rect.xmin = pivot.x - half_diagonal.x;
|
||||
bounds_rect.ymin = pivot.y - half_diagonal.y;
|
||||
bounds_rect.xmax = pivot.x + half_diagonal.x;
|
||||
bounds_rect.ymax = pivot.y + half_diagonal.y;
|
||||
}
|
||||
|
||||
UVPackIsland_Params::UVPackIsland_Params()
|
||||
@@ -944,7 +957,7 @@ static float pack_islands_margin_fraction(const Span<PackIsland *> &island_vecto
|
||||
/* TODO (?): `if (max_uv < 1.0f) { scale_last /= max_uv; }` */
|
||||
}
|
||||
|
||||
/* Then expand FaceIslands by the correct amount. */
|
||||
/* Then expand PackIslands by the correct amount. */
|
||||
for (const int64_t index : island_vector.index_range()) {
|
||||
BoxPack *box = &box_array[index];
|
||||
box->x /= scale_last;
|
||||
@@ -998,7 +1011,7 @@ static BoxPack *pack_islands_box_array(const Span<PackIsland *> &islands,
|
||||
const float scale = pack_islands_margin_fraction(islands, box_array, params.margin, params);
|
||||
r_scale[0] = scale;
|
||||
r_scale[1] = scale;
|
||||
/* pack_islands_margin_fraction will pad FaceIslands, return early. */
|
||||
/* pack_islands_margin_fraction will pad PackIslands, return early. */
|
||||
return box_array;
|
||||
}
|
||||
|
||||
|
@@ -4144,7 +4144,17 @@ void uv_parametrizer_pack(ParamHandle *handle, float margin, bool do_rotate, boo
|
||||
}
|
||||
|
||||
uv_parametrizer_scale_x(handle, 1.0f / handle->aspect_y);
|
||||
|
||||
Vector<PackIsland *> pack_island_vector;
|
||||
|
||||
UVPackIsland_Params params;
|
||||
params.rotate = do_rotate;
|
||||
params.margin = margin;
|
||||
params.margin_method = ED_UVPACK_MARGIN_SCALED;
|
||||
|
||||
MemArena *arena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__);
|
||||
Heap *heap = BLI_heap_new();
|
||||
|
||||
int unpacked = 0;
|
||||
for (int i = 0; i < handle->ncharts; i++) {
|
||||
PChart *chart = handle->charts[i];
|
||||
@@ -4159,21 +4169,19 @@ void uv_parametrizer_pack(ParamHandle *handle, float margin, bool do_rotate, boo
|
||||
pack_island->caller_index = i;
|
||||
pack_island->aspect_y = handle->aspect_y;
|
||||
pack_island->angle = 0.0f;
|
||||
|
||||
for (PFace *f = chart->faces; f; f = f->nextlink) {
|
||||
PVert *v0 = f->edge->vert;
|
||||
PVert *v1 = f->edge->next->vert;
|
||||
PVert *v2 = f->edge->next->next->vert;
|
||||
pack_island->add_triangle(v0->uv, v1->uv, v2->uv);
|
||||
}
|
||||
pack_island->finalize_geometry(params, arena, heap);
|
||||
|
||||
pack_island_vector.append(pack_island);
|
||||
|
||||
float minv[2];
|
||||
float maxv[2];
|
||||
p_chart_uv_bbox(chart, minv, maxv);
|
||||
pack_island->bounds_rect.xmin = minv[0];
|
||||
pack_island->bounds_rect.ymin = minv[1];
|
||||
pack_island->bounds_rect.xmax = maxv[0];
|
||||
pack_island->bounds_rect.ymax = maxv[1];
|
||||
}
|
||||
|
||||
UVPackIsland_Params params;
|
||||
params.rotate = do_rotate;
|
||||
params.margin = margin;
|
||||
params.margin_method = ED_UVPACK_MARGIN_SCALED;
|
||||
BLI_heap_free(heap, nullptr);
|
||||
BLI_memarena_free(arena);
|
||||
|
||||
float scale[2] = {1.0f, 1.0f};
|
||||
pack_islands(pack_island_vector, params, scale);
|
||||
|
Reference in New Issue
Block a user