35#define BM_EDGELOOP_IS_CLOSED (1 << 0)
40#define BM_EDGELOOP_IS_CLOSED_JUNCTION (1 << 1)
43#define EDGELOOP_EPS 1e-10f
57 if (v_other != v_prev) {
118 if (vert_junctions) {
131 if (v_next == v_first) [[unlikely]] {
136 else if (count == 0) {
153 ListBaseT<BMEdgeLoopStore> *r_eloops,
190 if (use_vert_junction) {
192 for (
BMVert *v_end : {
e->v1,
e->v2}) {
194 vert_junction_set.
add(v_end);
200 use_vert_junction =
false;
202 const Set<BMVert *> *vert_junctions = use_vert_junction ? &vert_junction_set :
nullptr;
209 const bool built =
bm_loop_build(el_store,
e->v1,
e->v2, 1, vert_junctions) &&
212 if (use_vert_junction) {
216 if (built && el_store->
len >= 2) {
219 if (node_first->
data == node_last->
data) {
221 MEM_delete(node_last);
228 if (built && el_store->
len > 1) {
279 ListBaseT<VertStep> *lb,
283 ListBaseT<VertStep> lb_tmp = {
nullptr,
nullptr};
287 for (vs = lb->first(); vs; vs = vs_next) {
292 const int vs_iter_next = vs_iter_tot + dir;
302 if (v_next_index == 0) {
303 vs_add(vs_pool, &lb_tmp, v_next,
e, vs_iter_next);
305 else if ((dir < 0) == (v_next_index < 0)) {
334 return (lb->is_empty() ==
false);
338 ListBaseT<BMEdgeLoopStore> *r_eloops,
395 BMVert *v_match[2] = {
nullptr,
nullptr};
396 ListBaseT<VertStep> lb_src = {
nullptr,
nullptr};
397 ListBaseT<VertStep> lb_dst = {
nullptr,
nullptr};
401 vs_add(vs_pool, &lb_src, v_src, v_src->
e, 1);
402 vs_add(vs_pool, &lb_dst, v_dst, v_dst->
e, -1);
486 ListBaseT<BMEdgeLoopStore> *eloops,
487 const float no_align[3])
495 ListBaseT<BMEdgeLoopStore> *eloops,
496 const bool use_normals)
498 ListBaseT<BMEdgeLoopStore> eloops_ordered = {
nullptr};
520 float len_best_sq = -1.0f;
524 if ((len_sq > len_best_sq) || (el_store_best ==
nullptr)) {
525 len_best_sq = len_sq;
526 el_store_best = &el_store;
535 while (eloops->first()) {
537 const float *co = (eloops_ordered.last())->
co;
538 const float *no = (eloops_ordered.last())->no;
560 if ((len_sq < len_best_sq) || (el_store_best ==
nullptr)) {
561 len_best_sq = len_sq;
562 el_store_best = &el_store;
570 *eloops = eloops_ordered;
579 *el_store_copy = *el_store;
581 return el_store_copy;
588 for (i = 0; i < v_arr_tot; i++) {
590 node->data = v_arr[i];
593 el_store->
len = v_arr_tot;
602 el_store->
verts.free_no_destruct();
603 MEM_delete(el_store);
618 return &el_store->
verts;
623 return el_store->
len;
636#define NODE_AS_V(n) ((BMVert *)((LinkData *)n)->data)
637#define NODE_AS_CO(n) ((BMVert *)((LinkData *)n)->data)->co
674 const float w_curr =
len_v3v3(v_curr, v_next);
675 const float w = (w_curr + w_prev);
680 node_prev = node_curr;
681 node_curr = node_next;
682 node_next = node_next->
next;
684 if (node_next ==
nullptr) {
709 if ((node_curr = node_curr->
next)) {
719 el_store->
no[2] = 1.0f;
727 const float no_align[3])
737 float cross[3], no[3], dir[3];
743 if ((node_curr = node_curr->
next)) {
753 el_store->
no[2] = 1.0f;
768 bool split_swap =
true;
770#define EDGE_SPLIT(node_copy, node_other) \
772 BMVert *v_split, *v_other = static_cast<BMVert *>((node_other)->data); \
774 *e_other = BM_edge_exists(static_cast<BMVert *>((node_copy)->data), v_other); \
775 v_split = BM_edge_split(bm, \
777 static_cast<BMVert *>(split_swap ? (node_copy)->data : v_other), \
780 v_split->e = e_split; \
781 BLI_assert(v_split == e_split->v2); \
782 split_edges->add(e_split); \
783 (node_copy)->data = v_split; \
788 while ((el_store->
len * 2) < el_store_len) {
791 LinkData *node_curr_copy = MEM_dupalloc(node_curr);
792 if (
split ==
false) {
794 node_curr = node_curr_copy->
next;
801 node_curr = node_curr_copy->
next;
806 node_curr = node_curr->
next;
808 split_swap = !split_swap;
812 split_swap = !split_swap;
815 if (el_store->
len < el_store_len) {
820 while (iter_prev < iter) {
821 node_curr = node_curr->
next;
826 node_curr_copy = MEM_dupalloc(node_curr);
827 if (
split ==
false) {
829 node_curr = node_curr_copy->
next;
836 node_curr = node_curr_copy->
next;
841 node_curr = node_curr->
next;
843 split_swap = !split_swap;
850#undef BKE_FOREACH_SUBSET_OF_RANGE
859 if (el_store_a->
len > el_store_b->
len) {
860 std::swap(el_store_a, el_store_b);
876 while ((remaining_node = remaining_node->
next)) {
#define BLI_ASSERT_UNIT_V3(v)
#define BLI_FOREACH_SPARSE_RANGE(src, dst, i)
Read Blender memory allocation and freeing.
#define BM_EDGELOOP_IS_CLOSED
#define BM_EDGELOOP_IS_CLOSED_JUNCTION
#define EDGE_SPLIT(node_copy, node_other)
#define BM_elem_index_get(ele)
#define BM_elem_flag_disable(ele, hflag)
#define BM_elem_index_set(ele, index)
#define BM_elem_flag_test(ele, hflag)
#define BM_elem_flag_enable(ele, hflag)
#define BM_ITER_ELEM(ele, iter, data, itype)
#define BM_ITER_MESH(ele, iter, bm, itype)
#define BM_ITER_MESH_INDEX(ele, iter, bm, itype, indexvar)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
bool contains(const Key &key) const
VecBase< float, 3 > cross(VecOp< float, 3 >, VecOp< float, 3 >) RET
void split(const std::string &s, const char delim, std::vector< std::string > &tokens)
bool BM_edgeloop_calc_normal_aligned(BMesh *, BMEdgeLoopStore *el_store, const float no_align[3])
BMEdgeLoopStore * BM_edgeloop_from_verts(BMVert **v_arr, const int v_arr_tot, bool is_closed)
void * MEM_new_uninitialized(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
MINLINE float len_squared_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
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)
bool BM_edgeloop_is_closed_junction(BMEdgeLoopStore *el_store)
MINLINE bool is_finite_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
void BM_mesh_edgeloops_calc_center(BMesh *bm, ListBaseT< BMEdgeLoopStore > *eloops)
void BM_edgeloop_flip(BMesh *, BMEdgeLoopStore *el_store)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void BM_edgeloop_expand(BMesh *bm, BMEdgeLoopStore *el_store, int el_store_len, bool split, Set< BMEdge * > *split_edges)
void BLI_addhead(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void BLI_stack_free(BLI_Stack *stack) ATTR_NONNULL()
void BM_mesh_edgeloops_free(ListBaseT< BMEdgeLoopStore > *eloops)
void BM_edgeloop_free(BMEdgeLoopStore *el_store)
void void void void void void BLI_duplicatelist(ListBase *dst, const ListBase *src) ATTR_NONNULL(1
void BM_mesh_edgeloops_calc_normal(BMesh *bm, ListBaseT< BMEdgeLoopStore > *eloops)
static int bm_vert_other_tag(BMVert *v, BMVert *v_prev, BMEdge **r_e)
const float * BM_edgeloop_normal_get(BMEdgeLoopStore *el_store)
bool BM_mesh_edgeloops_find_path(BMesh *bm, ListBaseT< BMEdgeLoopStore > *r_eloops, FunctionRef< bool(BMEdge *)> test_fn, BMVert *v_src, BMVert *v_dst)
ATTR_WARN_UNUSED_RESULT const BMVert * v
BLI_INLINE bool BM_vert_in_edge(const BMEdge *e, const BMVert *v) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
BLI_INLINE BMVert * BM_edge_other_vert(BMEdge *e, const BMVert *v) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
MINLINE void mul_v3_fl(float r[3], float f)
bool BM_edgeloop_is_closed(BMEdgeLoopStore *el_store)
static bool bm_loop_path_build_step(BLI_mempool *vs_pool, ListBaseT< VertStep > *lb, const int dir, BMVert *v_match[2])
void BLI_mempool_free(BLI_mempool *pool, void *addr) ATTR_NONNULL(1
void * BLI_pophead(ListBase *listbase) ATTR_NONNULL(1)
void BM_mesh_edgeloops_calc_normal_aligned(BMesh *bm, ListBaseT< BMEdgeLoopStore > *eloops, const float no_align[3])
int BM_edgeloop_length_get(BMEdgeLoopStore *el_store)
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
const float * BM_edgeloop_center_get(BMEdgeLoopStore *el_store)
void BLI_mempool_destroy(BLI_mempool *pool) ATTR_NONNULL(1)
void BM_edgeloop_edges_get(BMEdgeLoopStore *el_store, BMEdge **e_arr)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
size_t BLI_stack_count(const BLI_Stack *stack) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void BLI_insertlinkafter(ListBase *listbase, void *vprevlink, void *vnewlink) ATTR_NONNULL(1)
BLI_mempool * BLI_mempool_create(unsigned int esize, unsigned int elem_num, unsigned int pchunk, unsigned int flag) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL
void BM_edgeloop_calc_center(BMesh *, BMEdgeLoopStore *el_store)
MINLINE void negate_v3(float r[3])
void void void void void void void BLI_listbase_reverse(ListBase *lb) ATTR_NONNULL(1)
static void vs_add(BLI_mempool *vs_pool, ListBaseT< VertStep > *lb, BMVert *v, BMEdge *e_prev, const int iter_tot)
BMEdgeLoopStore * BM_edgeloop_copy(BMEdgeLoopStore *el_store)
MINLINE void zero_v3(float r[3])
void BLI_insertlinkbefore(ListBase *listbase, void *vnextlink, void *vnewlink) ATTR_NONNULL(1)
BMEdge * BM_edge_exists(BMVert *v_a, BMVert *v_b)
MINLINE float normalize_v3(float n[3])
MINLINE void add_v3_v3(float r[3], const float a[3])
static bool bm_vert_is_junction(BMVert *v)
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
bool BM_edgeloop_overlap_check(BMEdgeLoopStore *el_store_a, BMEdgeLoopStore *el_store_b)
void BLI_stack_pop_n_reverse(BLI_Stack *stack, void *dst, unsigned int n) ATTR_NONNULL()
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
MINLINE void add_newell_cross_v3_v3v3(float n[3], const float v_prev[3], const float v_curr[3])
void BLI_stack_push(BLI_Stack *stack, const void *src) ATTR_NONNULL()
static bool bm_loop_build(BMEdgeLoopStore *el_store, BMVert *v_prev, BMVert *v, int dir, const Set< BMVert * > *vert_junctions)
void * BLI_mempool_alloc(BLI_mempool *pool) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(1)
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
BLI_Stack * BLI_stack_new(size_t elem_size, const char *description) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
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
void BM_mesh_edgeloops_calc_order(BMesh *, ListBaseT< BMEdgeLoopStore > *eloops, const bool use_normals)
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
ListBaseT< LinkData > verts