26#define USE_DUPLICATE_FACE_VERT_CHECK
36 const float merge_factor)
51 }
while ((
void)(el_b = el_b->
next), (el_a = el_a->
next));
93 }
while ((
void)(el_b = el_b->
next ? el_b->
next : el_b_first),
94 (el_a = el_a->
next) && (
len < len_max));
109 for (; el_b; el_b = el_b->
next) {
111 if (
len < len_best) {
128 }
while ((l_iter = l_iter->
next) != l_first);
134 const bool use_merge,
135 const float merge_factor,
136 const int twist_offset)
138 const float eps = 0.00001f;
141 int el_store_a_len, el_store_b_len;
142 bool el_store_b_free =
false;
145 const bool use_edgeout =
true;
150 if (el_store_a_len < el_store_b_len) {
151 std::swap(el_store_a_len, el_store_b_len);
152 std::swap(el_store_a, el_store_b);
159 if (el_store_a_len != el_store_b_len) {
176 float dir_a_orig[3], dir_b_orig[3];
177 float dir_a[3], dir_b[3];
178 const float *test_a, *test_b;
181 (
static_cast<BMVert *
>(lb_a->first()->data))->co,
182 (
static_cast<BMVert *
>(lb_a->last()->data))->co);
184 (
static_cast<BMVert *
>(lb_b->first()->data))->co,
185 (
static_cast<BMVert *
>(lb_b->last()->data))->co);
216 if (
dot_v3v3(test_a, test_b) < 0.0f) {
238 else if ((dot_a < 0.0f) != (dot_b < 0.0f)) {
243 if (use_merge ==
false) {
257 int winding_votes[2] = {0, 0};
259 for (i = 0; i < 2; i++, winding_dir = -winding_dir) {
266 winding_votes[i] += ((
e->l->v == el.data) ? winding_dir : -winding_dir);
272 if (winding_votes[0] || winding_votes[1]) {
273 bool flip[2] = {
false,
false};
278 if (winding_votes[0] < 0) {
280 winding_votes[0] *= -1;
284 if (winding_votes[1] < 0) {
286 winding_votes[1] *= -1;
291 if ((winding_votes[0] + winding_votes[1]) < 0) {
297 winding_votes[0] *= -1;
298 winding_votes[1] *= -1;
312 if (el_store_a_len > el_store_b_len) {
315 el_store_b_free =
true;
322 if (twist_offset != 0) {
347 BMVert *v_a, *v_b, *v_a_next, *v_b_next;
351 BMLoop *l_a_next =
nullptr;
352 BMLoop *l_b_next =
nullptr;
359 el_a_next = el_a->
next;
360 el_b_next = el_b->
next;
361 if (
ELEM(
nullptr, el_a_next, el_b_next)) {
368 v_a_next =
static_cast<BMVert *
>(el_a_next->
data);
369 v_b_next =
static_cast<BMVert *
>(el_b_next->
data);
372 if (v_b != v_b_next) {
382 if (l_a && l_a_next ==
nullptr) {
385 if (l_a_next && l_a ==
nullptr) {
388 if (
l_b && l_b_next ==
nullptr) {
391 if (l_b_next &&
l_b ==
nullptr) {
394 f_example = l_a ? l_a->
f : (
l_b ?
l_b->
f :
nullptr);
396 if (v_b != v_b_next) {
397#ifdef USE_DUPLICATE_FACE_VERT_CHECK
398 BLI_assert((v_b != v_b_next) && (v_a_next != v_a));
399 if (
ELEM(v_b, v_a_next, v_a) ||
ELEM(v_b_next, v_a_next, v_a)) [[unlikely]] {
405 BMVert *v_arr[4] = {v_b, v_b_next, v_a_next, v_a};
415 l_iter = l_iter->
next;
419 l_iter = l_iter->
next;
423 l_iter = l_iter->
next;
431#ifdef USE_DUPLICATE_FACE_VERT_CHECK
433 if (
ELEM(v_b, v_a_next, v_a)) [[unlikely]] {
439 BMVert *v_arr[3] = {v_b, v_a_next, v_a};
449 l_iter = l_iter->
next;
453 l_iter = l_iter->
next;
461#ifdef USE_DUPLICATE_FACE_VERT_CHECK
465 if (f_example && (f_example != f)) {
477 if (el_a_next == el_a_first) {
486 if (el_store_a_len != el_store_b_len) {
510 for (i = 0; i < 2; i++) {
519 "beautify_fill faces=%hf edges=ae use_restrict_tag=%b method=%i",
551 if (use_edgeout && use_merge ==
false) {
555 for (i = 0; i < 2; i++) {
559 if (el.data != el_next->
data) {
569 if (el_store_b_free) {
576 ListBaseT<BMEdgeLoopStore> eloops = {
nullptr};
585 bool changed =
false;
599 if (use_pairs && (count % 2)) {
627 for (
const Link *el_store = eloops.first_as<
Link>(); el_store; el_store = el_store->
next) {
628 Link *el_store_next = el_store->
next;
630 if (el_store_next ==
nullptr) {
631 if (use_cyclic && (count > 2)) {
632 el_store_next = eloops.first_as<
Link>();
646 el_store = el_store->next;
655 if (use_merge ==
false) {
#define BM_FACE_FIRST_LOOP(p)
#define BM_EDGELINK_NEXT(el_store, elink)
#define BM_elem_flag_set(ele, hflag, val)
#define BM_elem_flag_enable(ele, hflag)
#define BMO_edge_flag_test(bm, e, oflag)
#define BMO_edge_flag_enable(bm, e, oflag)
#define BMO_face_flag_enable(bm, e, oflag)
#define BMO_ITER(ele, iter, slot_args, slot_name, restrict_flag)
#define BMO_edge_flag_disable(bm, e, oflag)
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
bool BM_edgeloop_calc_normal_aligned(BMesh *, BMEdgeLoopStore *el_store, const float no_align[3])
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
BMFace * BM_face_create_verts(BMesh *bm, BMVert **vert_arr, const int len, const BMFace *f_example, const eBMCreateFlag create_flag, const bool create_edges)
ListBaseT< LinkData > * BM_edgeloop_verts_get(BMEdgeLoopStore *el_store)
int BM_mesh_edgeloops_find(BMesh *bm, ListBaseT< BMEdgeLoopStore > *r_eloops, FunctionRef< bool(BMEdge *)> test_fn, const BMEdgeLoopFind_Params *params)
int BMO_slot_int_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name)
MINLINE int mod_i(int i, int n)
void * BLI_rfindlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
static double op_sub(double a, double b)
void BM_mesh_edgeloops_calc_center(BMesh *bm, ListBaseT< BMEdgeLoopStore > *eloops)
void BM_edgeloop_flip(BMesh *, BMEdgeLoopStore *el_store)
void BM_edgeloop_expand(BMesh *bm, BMEdgeLoopStore *el_store, int el_store_len, bool split, Set< BMEdge * > *split_edges)
void BMO_slot_buffer_hflag_enable(BMesh *bm, BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name, char htype, char hflag, bool do_flush)
BMO_FLAG_BUFFER.
static float bm_edgeloop_offset_length(LinkData *el_a, LinkData *el_b, LinkData *el_b_first, const float len_max)
ATTR_WARN_UNUSED_RESULT const BMLoop * l
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
void BM_mesh_edgeloops_free(ListBaseT< BMEdgeLoopStore > *eloops)
void BM_edgeloop_free(BMEdgeLoopStore *el_store)
float BMO_slot_float_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name)
void BM_mesh_edgeloops_calc_normal(BMesh *bm, ListBaseT< BMEdgeLoopStore > *eloops)
void BMO_slot_buffer_flag_enable(BMesh *bm, BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name, char htype, short oflag)
BMO_FLAG_BUFFER.
bool BMO_op_initf(BMesh *bm, BMOperator *op, int flag, const char *fmt,...)
static void bm_face_edges_tag_out(BMesh *bm, BMFace *f)
const float * BM_edgeloop_normal_get(BMEdgeLoopStore *el_store)
void BM_mesh_elem_hflag_disable_all(BMesh *bm, const char htype, const char hflag, const bool respecthide)
void BMO_op_exec(BMesh *bm, BMOperator *op)
BMESH OPSTACK EXEC OP.
bool BM_edgeloop_is_closed(BMEdgeLoopStore *el_store)
void * BM_iter_at_index(BMesh *bm, const char itype, void *data, int index)
static void bm_bridge_splice_loops(BMesh *bm, LinkData *el_a, LinkData *el_b, const float merge_factor)
int BM_edgeloop_length_get(BMEdgeLoopStore *el_store)
const float * BM_edgeloop_center_get(BMEdgeLoopStore *el_store)
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
void BM_face_normal_update(BMFace *f)
void BMO_slot_buffer_from_enabled_flag(BMesh *bm, BMOperator *op, BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name, char htype, short oflag)
static void bm_bridge_best_rotation(BMEdgeLoopStore *el_store_a, BMEdgeLoopStore *el_store_b)
ATTR_WARN_UNUSED_RESULT const BMLoop * l_b
void BLI_listbase_rotate_first(ListBase *lb, void *vlink) ATTR_NONNULL(1
BLI_INLINE bool BM_edge_is_boundary(const BMEdge *e) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], float t)
BMEdgeLoopStore * BM_edgeloop_copy(BMEdgeLoopStore *el_store)
void bmo_bridge_loops_exec(BMesh *bm, BMOperator *op)
static void bridge_loop_pair(BMesh *bm, BMEdgeLoopStore *el_store_a, BMEdgeLoopStore *el_store_b, const bool use_merge, const float merge_factor, const int twist_offset)
BMFace * BM_face_exists(BMVert *const *varr, int len)
MINLINE float normalize_v3_v3(float r[3], const float a[3])
BMOpSlot * BMO_slot_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *identifier)
BMESH OPSTACK GET SLOT.
BMEdge * BM_edge_exists(BMVert *v_a, BMVert *v_b)
bool BMO_slot_bool_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name)
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
ATTR_WARN_UNUSED_RESULT const BMVert * v2
MINLINE float len_squared_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
void BMO_error_raise(BMesh *bm, BMOperator *owner, eBMOpErrorLevel level, const char *msg) ATTR_NONNULL(1
void BMO_op_init(BMesh *bm, BMOperator *op, int flag, const char *opname)
BMESH OPSTACK INIT OP.
void BM_data_interp_from_verts(BMesh *bm, const BMVert *v_src_1, const BMVert *v_src_2, BMVert *v_dst, const float fac)
Data, Interpolate From Verts.
void BM_elem_attrs_copy(BMesh *bm, const BMCustomDataCopyMap &map, const BMVert *src, BMVert *dst)
void BMO_op_finish(BMesh *bm, BMOperator *op)
BMESH OPSTACK FINISH OP.
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
BLI_INLINE void BMO_slot_map_elem_insert(BMOperator *op, BMOpSlot *slot, const void *element, void *val)
static void bm_vert_loop_pair(BMesh *bm, BMVert *v1, BMVert *v2, BMLoop **l1, BMLoop **l2)
bool BM_edgeloop_calc_normal(BMesh *, BMEdgeLoopStore *el_store)
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE bool is_zero_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
void BM_mesh_edgeloops_calc_order(BMesh *, ListBaseT< BMEdgeLoopStore > *eloops, const bool use_normals)
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
struct BMOpSlot slots_in[BMO_OP_MAX_SLOTS]
struct BMOpSlot slots_out[BMO_OP_MAX_SLOTS]