Blender V5.3
bmo_fill_attribute.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include "BLI_linklist_stack.hh"
12
13#include "bmesh.hh"
14
15#include "intern/bmesh_operators_private.hh" /* own include */
16
17namespace blender {
18
23{
24 BMLoop *l_iter;
25 l_iter = l->radial_next;
26 do {
27 if (BM_elem_flag_test(l_iter->f, BM_ELEM_TAG) == 0) {
28 return false;
29 }
30 } while ((l_iter = l_iter->radial_next) != l);
31
32 return true;
33}
34
38static bool bm_loop_is_face_untag(const BMLoop *l, void * /*user_data*/)
39{
40 return (BM_elem_flag_test(l->f, BM_ELEM_TAG) == 0);
41}
42
47 BMLoop *l,
48 const bool use_normals,
49 const bool use_data)
50{
51 BMLoop *l_other = l->radial_next;
52 BMFace *f = l->f, *f_other;
53 while (BM_elem_flag_test(l_other->f, BM_ELEM_TAG)) {
54 l_other = l_other->radial_next;
55 }
56 f_other = l_other->f;
57
58 if (use_data) {
59 /* copy face-attrs */
60 BM_elem_attrs_copy(bm, f_other, f);
61
62 /* copy loop-attrs */
64 }
65
66 if (use_normals) {
67 /* copy winding (flipping) */
68 if (l->v == l_other->v) {
70 }
71 }
72}
73
77static uint bmesh_face_attribute_fill(BMesh *bm, const bool use_normals, const bool use_data)
78{
79 BLI_LINKSTACK_DECLARE(loop_queue_prev, BMLoop *);
80 BLI_LINKSTACK_DECLARE(loop_queue_next, BMLoop *);
81
82 BMFace *f;
83 BMIter iter;
84 BMLoop *l;
85
86 uint face_tot = 0;
87
88 BLI_LINKSTACK_INIT(loop_queue_prev);
89 BLI_LINKSTACK_INIT(loop_queue_next);
90
91 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
93 BMLoop *l_iter, *l_first;
94 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
95 do {
96 if (bm_loop_is_all_radial_tag(l_iter) == false) {
97 BLI_LINKSTACK_PUSH(loop_queue_prev, l_iter);
98 }
99 } while ((l_iter = l_iter->next) != l_first);
100 }
101 }
102
103 while (BLI_LINKSTACK_SIZE(loop_queue_prev)) {
104 while ((l = BLI_LINKSTACK_POP(loop_queue_prev))) {
105 /* check we're still un-assigned */
107 BMLoop *l_iter;
108
110
111 l_iter = l->next;
112 do {
113 BMLoop *l_radial_iter = l_iter->radial_next;
114 if (l_radial_iter != l_iter) {
115 do {
116 if (BM_elem_flag_test(l_radial_iter->f, BM_ELEM_TAG)) {
117 BLI_LINKSTACK_PUSH(loop_queue_next, l_radial_iter);
118 }
119 } while ((l_radial_iter = l_radial_iter->radial_next) != l_iter);
120 }
121 } while ((l_iter = l_iter->next) != l);
122
123 /* do last because of face flipping */
124 bm_face_copy_shared_all(bm, l, use_normals, use_data);
125 face_tot += 1;
126 }
127 }
128
129 BLI_LINKSTACK_SWAP(loop_queue_prev, loop_queue_next);
130 }
131
132 BLI_LINKSTACK_FREE(loop_queue_prev);
133 BLI_LINKSTACK_FREE(loop_queue_next);
134
135 return face_tot;
136}
137
139{
140 const bool use_normals = BMO_slot_bool_get(op->slots_in, "use_normals");
141 const bool use_data = BMO_slot_bool_get(op->slots_in, "use_data");
142
143 int face_tot;
144
146
147 /* do inline */
149
150 /* now we can copy adjacent data */
151 face_tot = bmesh_face_attribute_fill(bm, use_normals, use_data);
152
153 if (face_tot != BMO_slot_buffer_len(op->slots_in, "faces")) {
154 /* any remaining tags will be skipped */
156 bm, op, op->slots_out, "faces_fail.out", BM_FACE, BM_ELEM_TAG);
157 }
158}
159
160} // namespace blender
#define BM_FACE_FIRST_LOOP(p)
#define BM_elem_flag_disable(ele, hflag)
#define BM_elem_flag_test(ele, hflag)
#define BM_ITER_MESH(ele, iter, bm, itype)
BMesh Iterators.
static bool bm_loop_is_all_radial_tag(BMLoop *l)
int BMO_slot_buffer_len(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name)
void BM_face_normal_flip(BMesh *bm, BMFace *f)
unsigned int uint
Definition BKE_text.h:55
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.
ATTR_WARN_UNUSED_RESULT const BMLoop * l
static void bm_face_copy_shared_all(BMesh *bm, BMLoop *l, const bool use_normals, const bool use_data)
static bool bm_loop_is_face_untag(const BMLoop *l, void *)
void bmo_face_attribute_fill_exec(BMesh *bm, BMOperator *op)
void BM_mesh_elem_hflag_disable_all(BMesh *bm, const char htype, const char hflag, const bool respecthide)
static uint bmesh_face_attribute_fill(BMesh *bm, const bool use_normals, const bool use_data)
void BM_face_copy_shared(BMesh *bm, BMFace *f, BMLoopFilterFunc filter_fn, void *user_data)
copies face loop data from shared adjacent faces.
bool BMO_slot_bool_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name)
void BM_elem_attrs_copy(BMesh *bm, const BMCustomDataCopyMap &map, const BMVert *src, BMVert *dst)
void BMO_slot_buffer_from_enabled_hflag(BMesh *bm, BMOperator *op, BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name, char htype, char hflag)
struct BMLoop * next
struct BMVert * v
struct BMLoop * radial_next
struct BMFace * f
struct BMOpSlot slots_in[BMO_OP_MAX_SLOTS]
struct BMOpSlot slots_out[BMO_OP_MAX_SLOTS]
struct BMLoop * radial_next