main sync #3

Merged
Patrick Busch merged 318 commits from blender/blender:main into main 2023-03-17 15:52:21 +01:00
4 changed files with 47 additions and 43 deletions
Showing only changes of commit 10f06221c1 - Show all commits

View File

@ -1382,9 +1382,10 @@ static void uvedit_pack_islands_multi(const Scene *scene,
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_vector.append(pack_island);
}
BoxPack *box_array = pack_islands(pack_island_vector, *params, scale);
pack_islands(pack_island_vector, *params, scale);
float base_offset[2] = {0.0f, 0.0f};
copy_v2_v2(base_offset, params->udim_base_offset);
@ -1423,8 +1424,9 @@ static void uvedit_pack_islands_multi(const Scene *scene,
float matrix[2][2];
float matrix_inverse[2][2];
float pre_translate[2];
for (int i = 0; i < island_vector.size(); i++) {
FaceIsland *island = island_vector[box_array[i].index];
for (int64_t i : pack_island_vector.index_range()) {
blender::geometry::PackIsland *pack_island = pack_island_vector[i];
FaceIsland *island = island_vector[pack_island->caller_index];
matrix[0][0] = scale[0];
matrix[0][1] = 0.0f;
matrix[1][0] = 0.0f;
@ -1434,11 +1436,16 @@ static void uvedit_pack_islands_multi(const Scene *scene,
/* Add base_offset, post transform. */
mul_v2_m2v2(pre_translate, matrix_inverse, base_offset);
/* Translate to box_array from bounds_rect. */
blender::geometry::PackIsland *pack_island = pack_island_vector[box_array[i].index];
pre_translate[0] += box_array[i].x - pack_island->bounds_rect.xmin;
pre_translate[1] += box_array[i].y - pack_island->bounds_rect.ymin;
/* Add pre-translation from #pack_islands. */
pre_translate[0] += pack_island->pre_translate.x;
pre_translate[1] += pack_island->pre_translate.y;
/* Perform the transformation. */
island_uv_transform(island, matrix, pre_translate);
/* Cleanup memory. */
pack_island_vector[i] = nullptr;
delete pack_island;
}
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
@ -1451,14 +1458,6 @@ static void uvedit_pack_islands_multi(const Scene *scene,
MEM_freeN(island->faces);
MEM_freeN(island);
}
for (int i = 0; i < pack_island_vector.size(); i++) {
blender::geometry::PackIsland *pack_island = pack_island_vector[i];
pack_island_vector[i] = nullptr;
delete pack_island;
}
MEM_freeN(box_array);
}
/* -------------------------------------------------------------------- */

View File

@ -1,6 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
#include "BLI_boxpack_2d.h"
#include "BLI_math_matrix.hh"
#include "BLI_span.hh"
#include "DNA_vec_types.h"
@ -46,10 +46,12 @@ namespace blender::geometry {
class PackIsland {
public:
rctf bounds_rect;
float2 pre_translate; /* Output. */
int caller_index; /* Unchanged by #pack_islands, used by caller. */
};
BoxPack *pack_islands(const Span<PackIsland *> &island_vector,
const UVPackIsland_Params &params,
float r_scale[2]);
void pack_islands(const Span<PackIsland *> &islands,
const UVPackIsland_Params &params,
float r_scale[2]);
} // namespace blender::geometry

View File

@ -11,7 +11,6 @@
#include "BLI_convexhull_2d.h"
#include "BLI_listbase.h"
#include "BLI_math.h"
#include "BLI_math_matrix.hh"
#include "BLI_rect.h"
#include "BLI_vector.hh"
@ -302,9 +301,9 @@ static float calc_margin_from_aabb_length_sum(const Span<PackIsland *> &island_v
return params.margin * aabb_length_sum * 0.1f;
}
BoxPack *pack_islands(const Span<PackIsland *> &island_vector,
const UVPackIsland_Params &params,
float r_scale[2])
static BoxPack *pack_islands_box_array(const Span<PackIsland *> &island_vector,
const UVPackIsland_Params &params,
float r_scale[2])
{
BoxPack *box_array = static_cast<BoxPack *>(
MEM_mallocN(sizeof(*box_array) * island_vector.size(), __func__));
@ -351,4 +350,20 @@ BoxPack *pack_islands(const Span<PackIsland *> &island_vector,
return box_array;
}
void pack_islands(const Span<PackIsland *> &islands,
const UVPackIsland_Params &params,
float r_scale[2])
{
BoxPack *box_array = pack_islands_box_array(islands, params, r_scale);
for (int64_t i : islands.index_range()) {
BoxPack *box = box_array + i;
PackIsland *island = islands[box->index];
island->pre_translate.x = box->x - island->bounds_rect.xmin;
island->pre_translate.y = box->y - island->bounds_rect.ymin;
}
MEM_freeN(box_array);
}
} // namespace blender::geometry

View File

@ -4167,6 +4167,7 @@ void uv_parametrizer_pack(ParamHandle *handle, float margin, bool do_rotate, boo
}
geometry::PackIsland *pack_island = new geometry::PackIsland();
pack_island->caller_index = i;
pack_island_vector.append(pack_island);
float minv[2];
@ -4192,42 +4193,29 @@ void uv_parametrizer_pack(ParamHandle *handle, float margin, bool do_rotate, boo
params.udim_base_offset[1] = 0.0f;
float scale[2] = {1.0f, 1.0f};
BoxPack *box_array = pack_islands(pack_island_vector, params, scale);
pack_islands(pack_island_vector, params, scale);
for (int64_t i : pack_island_vector.index_range()) {
BoxPack *box = box_array + i;
PackIsland *pack_island = pack_island_vector[box->index];
pack_island->bounds_rect.xmin = box->x - pack_island->bounds_rect.xmin;
pack_island->bounds_rect.ymin = box->y - pack_island->bounds_rect.ymin;
}
unpacked = 0;
for (int i = 0; i < handle->ncharts; i++) {
PChart *chart = handle->charts[i];
if (ignore_pinned && chart->has_pins) {
unpacked++;
continue;
}
PackIsland *pack_island = pack_island_vector[i - unpacked];
PackIsland *pack_island = pack_island_vector[i];
PChart *chart = handle->charts[pack_island->caller_index];
/* TODO: Replace with #mul_v2_m2_add_v2v2 here soon. */
float m[2];
float b[2];
m[0] = scale[0];
m[1] = scale[1];
b[0] = pack_island->bounds_rect.xmin;
b[1] = pack_island->bounds_rect.ymin;
b[0] = pack_island->pre_translate.x;
b[1] = pack_island->pre_translate.y;
for (PVert *v = chart->verts; v; v = v->nextlink) {
/* Unusual accumulate-and-multiply here (will) reduce round-off error. */
v->uv[0] = m[0] * (v->uv[0] + b[0]);
v->uv[1] = m[1] * (v->uv[1] + b[1]);
}
pack_island_vector[i - unpacked] = nullptr;
pack_island_vector[i] = nullptr;
delete pack_island;
}
MEM_freeN(box_array);
if (handle->aspx != handle->aspy) {
uv_parametrizer_scale(handle, handle->aspx, handle->aspy);
}