2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup bmesh
|
2013-03-30 08:54:50 +00:00
|
|
|
*
|
|
|
|
|
* Convert triangle to quads.
|
|
|
|
|
*
|
|
|
|
|
* TODO
|
|
|
|
|
* - convert triangles to any sided faces, not just quads.
|
2012-04-06 09:21:19 +00:00
|
|
|
*/
|
|
|
|
|
|
2012-02-19 18:31:04 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
|
|
#include "DNA_meshdata_types.h"
|
|
|
|
|
|
Cleanup: reduce amount of math-related includes
Using ClangBuildAnalyzer on the whole Blender build, it was pointing
out that BLI_math.h is the heaviest "header hub" (i.e. non tiny file
that is included a lot).
However, there's very little (actually zero) source files in Blender
that need "all the math" (base, colors, vectors, matrices,
quaternions, intersection, interpolation, statistics, solvers and
time). A common use case is source files needing just vectors, or
just vectors & matrices, or just colors etc. Actually, 181 files
were including the whole math thing without needing it at all.
This change removes BLI_math.h completely, and instead in all the
places that need it, includes BLI_math_vector.h or BLI_math_color.h
and so on.
Change from that:
- BLI_math_color.h was included 1399 times -> now 408 (took 114.0sec
to parse -> now 36.3sec)
- BLI_simd.h 1403 -> 418 (109.7sec -> 34.9sec).
Full rebuild of Blender (Apple M1, Xcode, RelWithDebInfo) is not
affected much (342sec -> 334sec). Most of benefit would be when
someone's changing BLI_simd.h or BLI_math_color.h or similar files,
that now there's 3x fewer files result in a recompile.
Pull Request #110944
2023-08-09 11:39:20 +03:00
|
|
|
#include "BLI_math_geom.h"
|
|
|
|
|
#include "BLI_math_rotation.h"
|
|
|
|
|
#include "BLI_math_vector.h"
|
2013-09-05 22:24:12 +00:00
|
|
|
#include "BLI_sort_utils.h"
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2013-04-05 17:56:54 +00:00
|
|
|
#include "BKE_customdata.h"
|
|
|
|
|
|
2012-02-19 18:31:04 +00:00
|
|
|
#include "bmesh.h"
|
|
|
|
|
|
2012-03-08 03:25:53 +00:00
|
|
|
#include "intern/bmesh_operators_private.h" /* own include */
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2022-09-17 14:46:50 +10:00
|
|
|
/**
|
|
|
|
|
* \note Assumes edges are validated before reaching this point.
|
|
|
|
|
*/
|
2015-05-26 13:39:07 +10:00
|
|
|
static float quad_calc_error(const float v1[3],
|
2015-05-05 15:59:26 +10:00
|
|
|
const float v2[3],
|
2015-05-26 13:39:07 +10:00
|
|
|
const float v3[3],
|
|
|
|
|
const float v4[3])
|
2012-02-19 18:31:04 +00:00
|
|
|
{
|
2019-04-29 22:04:24 +10:00
|
|
|
/* Gives a 'weight' to a pair of triangles that join an edge
|
|
|
|
|
* to decide how good a join they would make. */
|
2021-07-03 23:08:40 +10:00
|
|
|
/* NOTE: this is more complicated than it needs to be and should be cleaned up. */
|
2015-05-26 13:39:07 +10:00
|
|
|
float error = 0.0f;
|
|
|
|
|
|
|
|
|
|
/* Normal difference */
|
|
|
|
|
{
|
|
|
|
|
float n1[3], n2[3];
|
|
|
|
|
float angle_a, angle_b;
|
|
|
|
|
float diff;
|
|
|
|
|
|
|
|
|
|
normal_tri_v3(n1, v1, v2, v3);
|
|
|
|
|
normal_tri_v3(n2, v1, v3, v4);
|
2022-10-07 22:52:53 +11:00
|
|
|
angle_a = compare_v3v3(n1, n2, FLT_EPSILON) ? 0.0f : angle_normalized_v3v3(n1, n2);
|
2015-05-26 13:39:07 +10:00
|
|
|
|
|
|
|
|
normal_tri_v3(n1, v2, v3, v4);
|
|
|
|
|
normal_tri_v3(n2, v4, v1, v2);
|
2022-10-07 22:52:53 +11:00
|
|
|
angle_b = compare_v3v3(n1, n2, FLT_EPSILON) ? 0.0f : angle_normalized_v3v3(n1, n2);
|
2015-05-26 13:39:07 +10:00
|
|
|
|
2023-07-27 11:23:35 +10:00
|
|
|
diff = (angle_a + angle_b) / float(M_PI * 2);
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2015-05-26 13:39:07 +10:00
|
|
|
error += diff;
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
|
|
2021-02-05 16:23:34 +11:00
|
|
|
/* Co-linearity */
|
2015-05-26 13:39:07 +10:00
|
|
|
{
|
|
|
|
|
float edge_vecs[4][3];
|
|
|
|
|
float diff;
|
|
|
|
|
|
|
|
|
|
sub_v3_v3v3(edge_vecs[0], v1, v2);
|
|
|
|
|
sub_v3_v3v3(edge_vecs[1], v2, v3);
|
|
|
|
|
sub_v3_v3v3(edge_vecs[2], v3, v4);
|
|
|
|
|
sub_v3_v3v3(edge_vecs[3], v4, v1);
|
|
|
|
|
|
|
|
|
|
normalize_v3(edge_vecs[0]);
|
|
|
|
|
normalize_v3(edge_vecs[1]);
|
|
|
|
|
normalize_v3(edge_vecs[2]);
|
|
|
|
|
normalize_v3(edge_vecs[3]);
|
|
|
|
|
|
|
|
|
|
/* a completely skinny face is 'pi' after halving */
|
2023-07-27 11:23:35 +10:00
|
|
|
diff = (fabsf(angle_normalized_v3v3(edge_vecs[0], edge_vecs[1]) - float(M_PI_2)) +
|
|
|
|
|
fabsf(angle_normalized_v3v3(edge_vecs[1], edge_vecs[2]) - float(M_PI_2)) +
|
|
|
|
|
fabsf(angle_normalized_v3v3(edge_vecs[2], edge_vecs[3]) - float(M_PI_2)) +
|
|
|
|
|
fabsf(angle_normalized_v3v3(edge_vecs[3], edge_vecs[0]) - float(M_PI_2))) /
|
|
|
|
|
float(M_PI * 2);
|
2015-05-26 13:39:07 +10:00
|
|
|
|
|
|
|
|
error += diff;
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-26 13:39:07 +10:00
|
|
|
/* Concavity */
|
|
|
|
|
{
|
|
|
|
|
float area_min, area_max, area_a, area_b;
|
|
|
|
|
float diff;
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2015-05-26 13:39:07 +10:00
|
|
|
area_a = area_tri_v3(v1, v2, v3) + area_tri_v3(v1, v3, v4);
|
|
|
|
|
area_b = area_tri_v3(v2, v3, v4) + area_tri_v3(v4, v1, v2);
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2015-05-26 13:39:07 +10:00
|
|
|
area_min = min_ff(area_a, area_b);
|
|
|
|
|
area_max = max_ff(area_a, area_b);
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2015-07-25 13:26:20 +10:00
|
|
|
diff = area_max ? (1.0f - (area_min / area_max)) : 1.0f;
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2015-05-26 13:39:07 +10:00
|
|
|
error += diff;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return error;
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-26 13:39:07 +10:00
|
|
|
static void bm_edge_to_quad_verts(const BMEdge *e, const BMVert *r_v_quad[4])
|
|
|
|
|
{
|
|
|
|
|
BLI_assert(e->l->f->len == 3 && e->l->radial_next->f->len == 3);
|
|
|
|
|
BLI_assert(BM_edge_is_manifold(e));
|
|
|
|
|
r_v_quad[0] = e->l->v;
|
|
|
|
|
r_v_quad[1] = e->l->prev->v;
|
|
|
|
|
r_v_quad[2] = e->l->next->v;
|
|
|
|
|
r_v_quad[3] = e->l->radial_next->prev->v;
|
|
|
|
|
}
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2015-05-26 13:39:07 +10:00
|
|
|
/* cache customdata delimiters */
|
|
|
|
|
struct DelimitData_CD {
|
|
|
|
|
int cd_type;
|
|
|
|
|
int cd_size;
|
|
|
|
|
int cd_offset;
|
|
|
|
|
int cd_offset_end;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct DelimitData {
|
2017-05-06 14:18:31 +10:00
|
|
|
uint do_seam : 1;
|
|
|
|
|
uint do_sharp : 1;
|
|
|
|
|
uint do_mat : 1;
|
|
|
|
|
uint do_angle_face : 1;
|
|
|
|
|
uint do_angle_shape : 1;
|
2015-05-26 13:39:07 +10:00
|
|
|
|
2015-05-26 14:27:38 +10:00
|
|
|
float angle_face;
|
|
|
|
|
float angle_face__cos;
|
|
|
|
|
|
|
|
|
|
float angle_shape;
|
2015-05-26 13:39:07 +10:00
|
|
|
|
2023-07-27 11:23:35 +10:00
|
|
|
DelimitData_CD cdata[4];
|
2015-05-26 13:39:07 +10:00
|
|
|
int cdata_len;
|
|
|
|
|
};
|
|
|
|
|
|
2023-07-27 11:23:35 +10:00
|
|
|
static bool bm_edge_is_contiguous_loop_cd_all(const BMEdge *e, const DelimitData_CD *delimit_data)
|
2012-02-19 18:31:04 +00:00
|
|
|
{
|
2015-05-26 13:39:07 +10:00
|
|
|
int cd_offset;
|
|
|
|
|
for (cd_offset = delimit_data->cd_offset; cd_offset < delimit_data->cd_offset_end;
|
|
|
|
|
cd_offset += delimit_data->cd_size)
|
|
|
|
|
{
|
|
|
|
|
if (BM_edge_is_contiguous_loop_cd(e, delimit_data->cd_type, cd_offset) == false) {
|
|
|
|
|
return false;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2015-05-26 13:39:07 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-05-26 13:39:07 +10:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool bm_edge_delimit_cdata(CustomData *ldata,
|
2022-06-01 14:38:06 +10:00
|
|
|
eCustomDataType type,
|
2023-07-27 11:23:35 +10:00
|
|
|
DelimitData_CD *r_delim_cd)
|
2015-05-26 13:39:07 +10:00
|
|
|
{
|
|
|
|
|
const int layer_len = CustomData_number_of_layers(ldata, type);
|
|
|
|
|
r_delim_cd->cd_type = type;
|
2023-07-26 16:12:55 +02:00
|
|
|
r_delim_cd->cd_size = CustomData_sizeof(eCustomDataType(r_delim_cd->cd_type));
|
2015-05-26 13:39:07 +10:00
|
|
|
r_delim_cd->cd_offset = CustomData_get_n_offset(ldata, type, 0);
|
2020-09-21 15:01:46 +10:00
|
|
|
r_delim_cd->cd_offset_end = r_delim_cd->cd_offset + (r_delim_cd->cd_size * layer_len);
|
2015-05-26 13:39:07 +10:00
|
|
|
return (r_delim_cd->cd_offset != -1);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-27 11:23:35 +10:00
|
|
|
static float bm_edge_is_delimit(const BMEdge *e, const DelimitData *delimit_data)
|
2015-05-26 13:39:07 +10:00
|
|
|
{
|
|
|
|
|
BMFace *f_a = e->l->f, *f_b = e->l->radial_next->f;
|
|
|
|
|
#if 0
|
|
|
|
|
const bool is_contig = BM_edge_is_contiguous(e);
|
|
|
|
|
float angle;
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-10-07 22:52:53 +11:00
|
|
|
if (delimit_data->do_seam && BM_elem_flag_test(e, BM_ELEM_SEAM)) {
|
2015-05-26 13:39:07 +10:00
|
|
|
goto fail;
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-10-07 22:52:53 +11:00
|
|
|
if (delimit_data->do_sharp && (BM_elem_flag_test(e, BM_ELEM_SMOOTH) == 0)) {
|
2015-05-26 13:39:07 +10:00
|
|
|
goto fail;
|
2012-09-19 04:48:34 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-10-07 22:52:53 +11:00
|
|
|
if (delimit_data->do_mat && (f_a->mat_nr != f_b->mat_nr)) {
|
2015-05-26 13:39:07 +10:00
|
|
|
goto fail;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-05-26 14:27:38 +10:00
|
|
|
if (delimit_data->do_angle_face) {
|
|
|
|
|
if (dot_v3v3(f_a->no, f_b->no) < delimit_data->angle_face__cos) {
|
|
|
|
|
goto fail;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2015-05-26 14:27:38 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-05-26 14:27:38 +10:00
|
|
|
if (delimit_data->do_angle_shape) {
|
|
|
|
|
const BMVert *verts[4];
|
|
|
|
|
bm_edge_to_quad_verts(e, verts);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-05-26 14:27:38 +10:00
|
|
|
/* if we're checking the shape at all, a flipped face is out of the question */
|
|
|
|
|
if (is_quad_flip_v3(verts[0]->co, verts[1]->co, verts[2]->co, verts[3]->co)) {
|
2015-05-26 13:39:07 +10:00
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
float edge_vecs[4][3];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-05-26 13:39:07 +10:00
|
|
|
sub_v3_v3v3(edge_vecs[0], verts[0]->co, verts[1]->co);
|
|
|
|
|
sub_v3_v3v3(edge_vecs[1], verts[1]->co, verts[2]->co);
|
|
|
|
|
sub_v3_v3v3(edge_vecs[2], verts[2]->co, verts[3]->co);
|
|
|
|
|
sub_v3_v3v3(edge_vecs[3], verts[3]->co, verts[0]->co);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-05-26 13:39:07 +10:00
|
|
|
normalize_v3(edge_vecs[0]);
|
|
|
|
|
normalize_v3(edge_vecs[1]);
|
|
|
|
|
normalize_v3(edge_vecs[2]);
|
|
|
|
|
normalize_v3(edge_vecs[3]);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-27 11:23:35 +10:00
|
|
|
if ((fabsf(angle_normalized_v3v3(edge_vecs[0], edge_vecs[1]) - float(M_PI_2)) >
|
2015-05-26 14:27:38 +10:00
|
|
|
delimit_data->angle_shape) ||
|
2023-07-27 11:23:35 +10:00
|
|
|
(fabsf(angle_normalized_v3v3(edge_vecs[1], edge_vecs[2]) - float(M_PI_2)) >
|
2015-05-26 14:27:38 +10:00
|
|
|
delimit_data->angle_shape) ||
|
2023-07-27 11:23:35 +10:00
|
|
|
(fabsf(angle_normalized_v3v3(edge_vecs[2], edge_vecs[3]) - float(M_PI_2)) >
|
2015-05-26 14:27:38 +10:00
|
|
|
delimit_data->angle_shape) ||
|
2023-07-27 11:23:35 +10:00
|
|
|
(fabsf(angle_normalized_v3v3(edge_vecs[3], edge_vecs[0]) - float(M_PI_2)) >
|
2015-05-26 14:27:38 +10:00
|
|
|
delimit_data->angle_shape))
|
|
|
|
|
{
|
2015-05-26 13:39:07 +10:00
|
|
|
goto fail;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2015-05-26 13:39:07 +10:00
|
|
|
}
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-05-26 13:39:07 +10:00
|
|
|
if (delimit_data->cdata_len) {
|
|
|
|
|
int i;
|
|
|
|
|
for (i = 0; i < delimit_data->cdata_len; i++) {
|
|
|
|
|
if (!bm_edge_is_contiguous_loop_cd_all(e, &delimit_data->cdata[i])) {
|
|
|
|
|
goto fail;
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-05-26 13:39:07 +10:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
fail:
|
2013-01-14 16:42:43 +00:00
|
|
|
return true;
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-26 13:39:07 +10:00
|
|
|
#define EDGE_MARK (1 << 0)
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2015-05-26 13:39:07 +10:00
|
|
|
#define FACE_OUT (1 << 0)
|
|
|
|
|
#define FACE_INPUT (1 << 2)
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2012-02-28 09:48:00 +00:00
|
|
|
void bmo_join_triangles_exec(BMesh *bm, BMOperator *op)
|
2012-02-19 18:31:04 +00:00
|
|
|
{
|
2015-05-26 14:27:38 +10:00
|
|
|
float angle_face, angle_shape;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-07-27 06:45:11 +00:00
|
|
|
BMIter iter;
|
2012-02-19 18:31:04 +00:00
|
|
|
BMOIter siter;
|
2013-07-27 06:45:11 +00:00
|
|
|
BMFace *f;
|
2015-06-20 16:48:59 +10:00
|
|
|
BMEdge *e;
|
2013-09-05 22:24:12 +00:00
|
|
|
/* data: edge-to-join, sort_value: error weight */
|
2023-07-27 11:23:35 +10:00
|
|
|
SortPtrByFloat *jedges;
|
2020-02-08 01:02:18 +11:00
|
|
|
uint i, totedge;
|
2017-05-06 14:18:31 +10:00
|
|
|
uint totedge_tag = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-27 11:23:35 +10:00
|
|
|
DelimitData delimit_data = {0};
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-05-26 13:39:07 +10:00
|
|
|
delimit_data.do_seam = BMO_slot_bool_get(op->slots_in, "cmp_seam");
|
|
|
|
|
delimit_data.do_sharp = BMO_slot_bool_get(op->slots_in, "cmp_sharp");
|
|
|
|
|
delimit_data.do_mat = BMO_slot_bool_get(op->slots_in, "cmp_materials");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-05-26 14:27:38 +10:00
|
|
|
angle_face = BMO_slot_float_get(op->slots_in, "angle_face_threshold");
|
|
|
|
|
if (angle_face < DEG2RADF(180.0f)) {
|
|
|
|
|
delimit_data.angle_face = angle_face;
|
|
|
|
|
delimit_data.angle_face__cos = cosf(angle_face);
|
|
|
|
|
delimit_data.do_angle_face = true;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
delimit_data.do_angle_face = false;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-05-26 14:27:38 +10:00
|
|
|
angle_shape = BMO_slot_float_get(op->slots_in, "angle_shape_threshold");
|
|
|
|
|
if (angle_shape < DEG2RADF(180.0f)) {
|
|
|
|
|
delimit_data.angle_shape = angle_shape;
|
|
|
|
|
delimit_data.do_angle_shape = true;
|
2015-05-26 13:39:07 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2015-05-26 14:27:38 +10:00
|
|
|
delimit_data.do_angle_shape = false;
|
2015-05-26 13:39:07 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-05-26 13:39:07 +10:00
|
|
|
if (BMO_slot_bool_get(op->slots_in, "cmp_uvs") &&
|
Mesh: Move UV layers to generic attributes
Currently the `MLoopUV` struct stores UV coordinates and flags related
to editing UV maps in the UV editor. This patch changes the coordinates
to use the generic 2D vector type, and moves the flags into three
separate boolean attributes. This follows the design in T95965, with
the ultimate intention of simplifying code and improving performance.
Importantly, the change allows exporters and renderers to use UVs
"touched" by geometry nodes, which only creates generic attributes.
It also allows geometry nodes to create "proper" UV maps from scratch,
though only with the Store Named Attribute node for now.
The new design considers any 2D vector attribute on the corner domain
to be a UV map. In the future, they might be distinguished from regular
2D vectors with attribute metadata, which may be helpful because they
are often interpolated differently.
Most of the code changes deal with passing around UV BMesh custom data
offsets and tracking the boolean "sublayers". The boolean layers are
use the following prefixes for attribute names: vert selection: `.vs.`,
edge selection: `.es.`, pinning: `.pn.`. Currently these are short to
avoid using up the maximum length of attribute names. To accommodate
for these 4 extra characters, the name length limit is enlarged to 68
bytes, while the maximum user settable name length is still 64 bytes.
Unfortunately Python/RNA API access to the UV flag data becomes slower.
Accessing the boolean layers directly is be better for performance in
general.
Like the other mesh SoA refactors, backward and forward compatibility
aren't affected, and won't be changed until 4.0. We pay for that by
making mesh reading and writing more expensive with conversions.
Resolves T85962
Differential Revision: https://developer.blender.org/D14365
2023-01-10 00:47:04 -05:00
|
|
|
bm_edge_delimit_cdata(
|
|
|
|
|
&bm->ldata, CD_PROP_FLOAT2, &delimit_data.cdata[delimit_data.cdata_len]))
|
|
|
|
|
{
|
2015-05-26 13:39:07 +10:00
|
|
|
delimit_data.cdata_len += 1;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-05-26 13:39:07 +10:00
|
|
|
delimit_data.cdata[delimit_data.cdata_len].cd_offset = -1;
|
|
|
|
|
if (BMO_slot_bool_get(op->slots_in, "cmp_vcols") &&
|
|
|
|
|
bm_edge_delimit_cdata(
|
2022-04-20 09:10:10 -05:00
|
|
|
&bm->ldata, CD_PROP_BYTE_COLOR, &delimit_data.cdata[delimit_data.cdata_len]))
|
|
|
|
|
{
|
2015-05-26 13:39:07 +10:00
|
|
|
delimit_data.cdata_len += 1;
|
2015-05-22 18:12:54 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-02-19 18:31:04 +00:00
|
|
|
/* flag all edges of all input face */
|
2012-11-19 14:58:31 +00:00
|
|
|
BMO_ITER (f, &siter, op->slots_in, "faces", BM_FACE) {
|
2013-08-02 13:35:04 +00:00
|
|
|
if (f->len == 3) {
|
2016-07-01 19:07:11 +10:00
|
|
|
BMO_face_flag_enable(bm, f, FACE_INPUT);
|
2013-08-02 13:35:04 +00:00
|
|
|
}
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-07-27 06:45:11 +00:00
|
|
|
/* flag edges surrounded by 2 flagged triangles */
|
2012-04-19 13:47:58 +00:00
|
|
|
BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
|
2013-07-27 06:45:11 +00:00
|
|
|
BMFace *f_a, *f_b;
|
|
|
|
|
if (BM_edge_face_pair(e, &f_a, &f_b) &&
|
2016-07-01 19:07:11 +10:00
|
|
|
(BMO_face_flag_test(bm, f_a, FACE_INPUT) && BMO_face_flag_test(bm, f_b, FACE_INPUT)))
|
|
|
|
|
{
|
2015-05-26 13:39:07 +10:00
|
|
|
if (!bm_edge_is_delimit(e, &delimit_data)) {
|
2016-07-01 19:07:11 +10:00
|
|
|
BMO_edge_flag_enable(bm, e, EDGE_MARK);
|
2015-05-26 13:39:07 +10:00
|
|
|
totedge_tag++;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2015-05-26 13:39:07 +10:00
|
|
|
}
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-07-27 06:45:11 +00:00
|
|
|
if (totedge_tag == 0) {
|
|
|
|
|
return;
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-07-27 06:45:11 +00:00
|
|
|
/* over alloc, some of the edges will be delimited */
|
2023-07-26 16:12:55 +02:00
|
|
|
jedges = static_cast<SortPtrByFloat *>(MEM_mallocN(sizeof(*jedges) * totedge_tag, __func__));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-02-19 18:31:04 +00:00
|
|
|
i = 0;
|
2012-04-19 13:47:58 +00:00
|
|
|
BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
|
2015-05-26 13:39:07 +10:00
|
|
|
const BMVert *verts[4];
|
|
|
|
|
float error;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-27 17:14:36 +11:00
|
|
|
if (!BMO_edge_flag_test(bm, e, EDGE_MARK)) {
|
2012-02-19 18:31:04 +00:00
|
|
|
continue;
|
2019-03-27 17:14:36 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-05-26 13:39:07 +10:00
|
|
|
bm_edge_to_quad_verts(e, verts);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-05-26 13:39:07 +10:00
|
|
|
error = quad_calc_error(verts[0]->co, verts[1]->co, verts[2]->co, verts[3]->co);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-05-26 13:39:07 +10:00
|
|
|
jedges[i].data = e;
|
|
|
|
|
jedges[i].sort_value = error;
|
|
|
|
|
i++;
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-07-27 06:45:11 +00:00
|
|
|
totedge = i;
|
2013-09-05 22:24:12 +00:00
|
|
|
qsort(jedges, totedge, sizeof(*jedges), BLI_sortutil_cmp_float);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-02-19 18:31:04 +00:00
|
|
|
for (i = 0; i < totedge; i++) {
|
2016-11-12 10:06:53 +11:00
|
|
|
BMLoop *l_a, *l_b;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-26 16:12:55 +02:00
|
|
|
e = static_cast<BMEdge *>(jedges[i].data);
|
2016-11-12 10:06:53 +11:00
|
|
|
l_a = e->l;
|
|
|
|
|
l_b = e->l->radial_next;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-07-27 06:45:11 +00:00
|
|
|
/* check if another edge already claimed this face */
|
2016-11-12 10:06:53 +11:00
|
|
|
if ((l_a->f->len == 3) && (l_b->f->len == 3)) {
|
2015-06-20 16:48:59 +10:00
|
|
|
BMFace *f_new;
|
2016-11-12 10:06:53 +11:00
|
|
|
f_new = BM_faces_join_pair(bm, l_a, l_b, true);
|
2013-08-02 13:35:04 +00:00
|
|
|
if (f_new) {
|
2016-07-01 19:07:11 +10:00
|
|
|
BMO_face_flag_enable(bm, f_new, FACE_OUT);
|
2013-08-02 13:35:04 +00:00
|
|
|
}
|
2013-07-27 06:11:54 +00:00
|
|
|
}
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-06-20 16:48:59 +10:00
|
|
|
MEM_freeN(jedges);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-07-27 06:11:54 +00:00
|
|
|
BMO_slot_buffer_from_enabled_flag(bm, op, op->slots_out, "faces.out", BM_FACE, FACE_OUT);
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|