38
38
#include "intern/bmesh_operators_private.h" /* own include */
44
41
#define FACE_MARK 2
45
42
#define EDGE_MARK 4
47
44
void bmo_triangulate_exec(BMesh *bm, BMOperator *op)
50
BMFace *face, **newfaces = NULL;
51
BLI_array_declare(newfaces);
52
float (*projectverts)[3] = NULL;
53
BLI_array_declare(projectverts);
55
const int use_beauty = BMO_slot_bool_get(op, "use_beauty");
57
for (face = BMO_iter_new(&siter, bm, op, "faces", BM_FACE); face; face = BMO_iter_step(&siter)) {
59
BLI_array_empty(projectverts);
60
BLI_array_empty(newfaces);
62
BLI_array_growitems(projectverts, face->len * 3);
63
BLI_array_growitems(newfaces, face->len);
65
BM_face_triangulate(bm, face, projectverts, EDGE_NEW, FACE_NEW, newfaces, use_beauty);
67
BMO_slot_map_ptr_insert(bm, op, "facemap", face, face);
68
for (i = 0; newfaces[i]; i++) {
69
BMO_slot_map_ptr_insert(bm, op, "facemap",
75
BMO_slot_buffer_from_enabled_flag(bm, op, "edgeout", BM_EDGE, EDGE_NEW);
76
BMO_slot_buffer_from_enabled_flag(bm, op, "faceout", BM_FACE, FACE_NEW);
78
BLI_array_free(projectverts);
79
BLI_array_free(newfaces);
46
const bool use_beauty = BMO_slot_bool_get(op->slots_in, "use_beauty");
47
BMOpSlot *slot_facemap_out = BMO_slot_get(op->slots_out, "face_map.out");
49
BM_mesh_elem_hflag_disable_all(bm, BM_FACE | BM_EDGE, BM_ELEM_TAG, false);
50
BMO_slot_buffer_hflag_enable(bm, op->slots_in, "faces", BM_FACE, BM_ELEM_TAG, false);
52
BM_mesh_triangulate(bm, use_beauty, true, op, slot_facemap_out);
54
BMO_slot_buffer_from_enabled_hflag(bm, op, op->slots_out, "edges.out", BM_EDGE, BM_ELEM_TAG);
55
BMO_slot_buffer_from_enabled_hflag(bm, op, op->slots_out, "faces.out", BM_FACE, BM_ELEM_TAG);
82
58
void bmo_beautify_fill_exec(BMesh *bm, BMOperator *op)
90
BMO_slot_buffer_flag_enable(bm, op, "constrain_edges", BM_EDGE, EDGE_MARK);
66
BMO_slot_buffer_flag_enable(bm, op->slots_in, "edges", BM_EDGE, EDGE_MARK);
92
BMO_ITER (f, &siter, bm, op, "faces", BM_FACE) {
68
BMO_ITER (f, &siter, op->slots_in, "faces", BM_FACE) {
94
70
BMO_elem_flag_enable(bm, f, FACE_MARK);
139
115
fac2 = opp1 / (len2 + len3 + len6) + opp2 / (len4 + len1 + len6);
141
117
if (fac1 > fac2) {
142
e = BM_edge_rotate(bm, e, FALSE, BM_EDGEROT_CHECK_EXISTS);
118
e = BM_edge_rotate(bm, e, false, BM_EDGEROT_CHECK_EXISTS);
144
BMO_elem_flag_enable(bm, e, ELE_NEW);
120
BMO_elem_flag_enable(bm, e, ELE_NEW | EDGE_MARK);
146
BMO_elem_flag_enable(bm, e->l->f, FACE_MARK|ELE_NEW);
147
BMO_elem_flag_enable(bm, e->l->radial_next->f, FACE_MARK|ELE_NEW);
122
BMO_elem_flag_enable(bm, e->l->f, FACE_MARK | ELE_NEW);
123
BMO_elem_flag_enable(bm, e->l->radial_next->f, FACE_MARK | ELE_NEW);
155
BMO_slot_buffer_from_enabled_flag(bm, op, "geomout", BM_EDGE|BM_FACE, ELE_NEW);
131
BMO_slot_buffer_from_enabled_flag(bm, op, op->slots_out, "geom.out", BM_EDGE | BM_FACE, ELE_NEW);
158
134
void bmo_triangle_fill_exec(BMesh *bm, BMOperator *op)
136
const bool use_beauty = BMO_slot_bool_get(op->slots_in, "use_beauty");
163
139
ScanFillContext sf_ctx;
164
/* ScanFillEdge *eed; */ /* UNUSED */
165
ScanFillVert *eve, *v1, *v2;
140
/* ScanFillEdge *sf_edge; */ /* UNUSED */
141
ScanFillVert *sf_vert, *sf_vert_1, *sf_vert_2;
142
ScanFillFace *sf_tri;
169
145
BLI_smallhash_init(&hash);
171
BLI_begin_edgefill(&sf_ctx);
147
BLI_scanfill_begin(&sf_ctx);
173
BMO_ITER (e, &siter, bm, op, "edges", BM_EDGE) {
149
BMO_ITER (e, &siter, op->slots_in, "edges", BM_EDGE) {
174
150
BMO_elem_flag_enable(bm, e, EDGE_MARK);
176
152
if (!BLI_smallhash_haskey(&hash, (uintptr_t)e->v1)) {
177
eve = BLI_addfillvert(&sf_ctx, e->v1->co);
179
BLI_smallhash_insert(&hash, (uintptr_t)e->v1, eve);
153
sf_vert = BLI_scanfill_vert_add(&sf_ctx, e->v1->co);
154
sf_vert->tmp.p = e->v1;
155
BLI_smallhash_insert(&hash, (uintptr_t)e->v1, sf_vert);
182
158
if (!BLI_smallhash_haskey(&hash, (uintptr_t)e->v2)) {
183
eve = BLI_addfillvert(&sf_ctx, e->v2->co);
185
BLI_smallhash_insert(&hash, (uintptr_t)e->v2, eve);
159
sf_vert = BLI_scanfill_vert_add(&sf_ctx, e->v2->co);
160
sf_vert->tmp.p = e->v2;
161
BLI_smallhash_insert(&hash, (uintptr_t)e->v2, sf_vert);
188
v1 = BLI_smallhash_lookup(&hash, (uintptr_t)e->v1);
189
v2 = BLI_smallhash_lookup(&hash, (uintptr_t)e->v2);
190
/* eed = */ BLI_addfilledge(&sf_ctx, v1, v2);
191
/* eed->tmp.p = e; */ /* UNUSED */
164
sf_vert_1 = BLI_smallhash_lookup(&hash, (uintptr_t)e->v1);
165
sf_vert_2 = BLI_smallhash_lookup(&hash, (uintptr_t)e->v2);
166
/* sf_edge = */ BLI_scanfill_edge_add(&sf_ctx, sf_vert_1, sf_vert_2);
167
/* sf_edge->tmp.p = e; */ /* UNUSED */
194
BLI_edgefill(&sf_ctx, FALSE);
170
BLI_scanfill_calc(&sf_ctx, BLI_SCANFILL_CALC_HOLES);
196
for (efa = sf_ctx.fillfacebase.first; efa; efa = efa->next) {
172
for (sf_tri = sf_ctx.fillfacebase.first; sf_tri; sf_tri = sf_tri->next) {
197
173
BMFace *f = BM_face_create_quad_tri(bm,
198
efa->v1->tmp.p, efa->v2->tmp.p, efa->v3->tmp.p, NULL,
174
sf_tri->v1->tmp.p, sf_tri->v2->tmp.p, sf_tri->v3->tmp.p, NULL,
211
BLI_end_edgefill(&sf_ctx);
187
BLI_scanfill_end(&sf_ctx);
212
188
BLI_smallhash_release(&hash);
215
BMO_op_initf(bm, &bmop, "beautify_fill faces=%ff constrain_edges=%fe", ELE_NEW, EDGE_MARK);
216
BMO_op_exec(bm, &bmop);
217
BMO_slot_buffer_flag_enable(bm, &bmop, "geomout", BM_FACE|BM_EDGE, ELE_NEW);
218
BMO_op_finish(bm, &bmop);
193
BMO_op_initf(bm, &bmop, op->flag, "beautify_fill faces=%ff edges=%Fe", ELE_NEW, EDGE_MARK);
194
BMO_op_exec(bm, &bmop);
195
BMO_slot_buffer_flag_enable(bm, bmop.slots_out, "geom.out", BM_FACE | BM_EDGE, ELE_NEW);
196
BMO_op_finish(bm, &bmop);
220
BMO_slot_buffer_from_enabled_flag(bm, op, "geomout", BM_EDGE|BM_FACE, ELE_NEW);
199
BMO_slot_buffer_from_enabled_flag(bm, op, op->slots_out, "geom.out", BM_EDGE | BM_FACE, ELE_NEW);