1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
|
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributor(s): Joseph Eagar.
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file blender/bmesh/operators/bmo_removedoubles.c
* \ingroup bmesh
*
* Welding and merging functionality.
*/
#include "MEM_guardedalloc.h"
#include "BLI_math.h"
#include "BLI_alloca.h"
#include "BLI_stackdefines.h"
#include "BLI_stack.h"
#include "BKE_customdata.h"
#include "bmesh.h"
#include "intern/bmesh_operators_private.h"
static void remdoubles_splitface(BMFace *f, BMesh *bm, BMOperator *op, BMOpSlot *slot_targetmap)
{
BMIter liter;
BMLoop *l, *l_tar, *l_double;
bool split = false;
BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) {
BMVert *v_tar = BMO_slot_map_elem_get(slot_targetmap, l->v);
/* ok: if v_tar is NULL (e.g. not in the map) then it's
* a target vert, otherwise it's a double */
if (v_tar) {
l_tar = BM_face_vert_share_loop(f, v_tar);
if (l_tar && (l_tar != l) && !BM_loop_is_adjacent(l_tar, l)) {
l_double = l;
split = true;
break;
}
}
}
if (split) {
BMLoop *l_new;
BMFace *f_new;
f_new = BM_face_split(bm, f, l_double, l_tar, &l_new, NULL, false);
remdoubles_splitface(f, bm, op, slot_targetmap);
remdoubles_splitface(f_new, bm, op, slot_targetmap);
}
}
#define ELE_DEL 1
#define EDGE_COL 2
#define FACE_MARK 2
/**
* helper function for bmo_weld_verts_exec so we can use stack memory
*/
static void remdoubles_createface(BMesh *bm, BMFace *f, BMOpSlot *slot_targetmap)
{
BMIter liter;
BMFace *f_new;
BMEdge *e_new;
BMLoop *l;
BMEdge **edges = BLI_array_alloca(edges, f->len);
BMLoop **loops = BLI_array_alloca(loops, f->len);
STACK_DECLARE(edges);
STACK_DECLARE(loops);
STACK_INIT(edges, f->len);
STACK_INIT(loops, f->len);
BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) {
BMVert *v1 = l->v;
BMVert *v2 = l->next->v;
const bool is_del_v1 = BMO_elem_flag_test_bool(bm, v1, ELE_DEL);
const bool is_del_v2 = BMO_elem_flag_test_bool(bm, v2, ELE_DEL);
/* only search for a new edge if one of the verts is mapped */
if (is_del_v1 || is_del_v2) {
if (is_del_v1)
v1 = BMO_slot_map_elem_get(slot_targetmap, v1);
if (is_del_v2)
v2 = BMO_slot_map_elem_get(slot_targetmap, v2);
e_new = (v1 != v2) ? BM_edge_exists(v1, v2) : NULL;
}
else {
e_new = l->e;
}
if (e_new) {
unsigned int i;
for (i = 0; i < STACK_SIZE(edges); i++) {
if (edges[i] == e_new) {
break;
}
}
if (UNLIKELY(i != STACK_SIZE(edges))) {
continue;
}
/* low level selection, not essential but means we can keep
* edge selection valid on auto-merge for example. */
if ((BM_elem_flag_test(l->e, BM_ELEM_SELECT) == true) &&
(BM_elem_flag_test(e_new, BM_ELEM_SELECT) == false))
{
BM_elem_flag_disable(l->e, BM_ELEM_SELECT);
BM_elem_flag_merge_into(e_new, e_new, l->e);
BM_elem_flag_enable(e_new, BM_ELEM_SELECT);
/* bm->totedgesel remains valid */
}
else {
BM_elem_flag_merge_into(e_new, e_new, l->e);
}
STACK_PUSH(edges, e_new);
STACK_PUSH(loops, l);
}
}
if (STACK_SIZE(edges) >= 3) {
BMVert *v1 = loops[0]->v;
BMVert *v2 = loops[1]->v;
if (BMO_elem_flag_test(bm, v1, ELE_DEL)) {
v1 = BMO_slot_map_elem_get(slot_targetmap, v1);
}
if (BMO_elem_flag_test(bm, v2, ELE_DEL)) {
v2 = BMO_slot_map_elem_get(slot_targetmap, v2);
}
f_new = BM_face_create_ngon(bm, v1, v2, edges, STACK_SIZE(edges), f, BM_CREATE_NO_DOUBLE);
BLI_assert(f_new != f);
if (f_new) {
unsigned int i;
BM_ITER_ELEM_INDEX (l, &liter, f_new, BM_LOOPS_OF_FACE, i) {
BM_elem_attrs_copy(bm, bm, loops[i], l);
}
}
}
}
/**
* \note with 'targetmap', multiple 'keys' are currently supported, though no callers should be using.
* (because slot maps currently use GHash without the GHASH_FLAG_ALLOW_DUPES flag set)
*
*/
void bmo_weld_verts_exec(BMesh *bm, BMOperator *op)
{
BMIter iter, liter;
BMVert *v1, *v2;
BMEdge *e;
BMLoop *l;
BMFace *f;
BMOpSlot *slot_targetmap = BMO_slot_get(op->slots_in, "targetmap");
/* mark merge verts for deletion */
BM_ITER_MESH (v1, &iter, bm, BM_VERTS_OF_MESH) {
if ((v2 = BMO_slot_map_elem_get(slot_targetmap, v1))) {
BMO_elem_flag_enable(bm, v1, ELE_DEL);
/* merge the vertex flags, else we get randomly selected/unselected verts */
BM_elem_flag_merge(v1, v2);
}
}
/* check if any faces are getting their own corners merged
* together, split face if so */
BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
remdoubles_splitface(f, bm, op, slot_targetmap);
}
BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
const bool is_del_v1 = BMO_elem_flag_test_bool(bm, (v1 = e->v1), ELE_DEL);
const bool is_del_v2 = BMO_elem_flag_test_bool(bm, (v2 = e->v2), ELE_DEL);
if (is_del_v1 || is_del_v2) {
if (is_del_v1)
v1 = BMO_slot_map_elem_get(slot_targetmap, v1);
if (is_del_v2)
v2 = BMO_slot_map_elem_get(slot_targetmap, v2);
if (v1 == v2) {
BMO_elem_flag_enable(bm, e, EDGE_COL);
}
else if (!BM_edge_exists(v1, v2)) {
BM_edge_create(bm, v1, v2, e, BM_CREATE_NOP);
}
BMO_elem_flag_enable(bm, e, ELE_DEL);
}
}
/* BMESH_TODO, stop abusing face index here */
BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
BM_elem_index_set(f, 0); /* set_dirty! */
BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) {
if (BMO_elem_flag_test(bm, l->v, ELE_DEL)) {
BMO_elem_flag_enable(bm, f, FACE_MARK | ELE_DEL);
}
if (BMO_elem_flag_test(bm, l->e, EDGE_COL)) {
BM_elem_index_set(f, BM_elem_index_get(f) + 1); /* set_dirty! */
}
}
}
bm->elem_index_dirty |= BM_FACE | BM_LOOP;
/* faces get "modified" by creating new faces here, then at the
* end the old faces are deleted */
BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
if (!BMO_elem_flag_test(bm, f, FACE_MARK))
continue;
if (f->len - BM_elem_index_get(f) < 3) {
BMO_elem_flag_enable(bm, f, ELE_DEL);
continue;
}
remdoubles_createface(bm, f, slot_targetmap);
}
BMO_mesh_delete_oflag_context(bm, ELE_DEL, DEL_ONLYTAGGED);
}
static int vergaverco(const void *e1, const void *e2)
{
const BMVert *v1 = *(const void **)e1, *v2 = *(const void **)e2;
float x1 = v1->co[0] + v1->co[1] + v1->co[2];
float x2 = v2->co[0] + v2->co[1] + v2->co[2];
if (x1 > x2) return 1;
else if (x1 < x2) return -1;
else return 0;
}
// #define VERT_TESTED 1 // UNUSED
#define VERT_DOUBLE 2
#define VERT_TARGET 4
#define VERT_KEEP 8
// #define VERT_MARK 16 // UNUSED
#define VERT_IN 32
#define EDGE_MARK 1
void bmo_pointmerge_facedata_exec(BMesh *bm, BMOperator *op)
{
BMOIter siter;
BMIter iter;
BMVert *v, *vert_snap;
BMLoop *l, *l_first = NULL;
float fac;
int i, tot;
vert_snap = BMO_slot_buffer_get_single(BMO_slot_get(op->slots_in, "vert_snap"));
tot = BM_vert_face_count(vert_snap);
if (!tot)
return;
fac = 1.0f / tot;
BM_ITER_ELEM (l, &iter, vert_snap, BM_LOOPS_OF_VERT) {
if (l_first == NULL) {
l_first = l;
}
for (i = 0; i < bm->ldata.totlayer; i++) {
if (CustomData_layer_has_math(&bm->ldata, i)) {
const int type = bm->ldata.layers[i].type;
const int offset = bm->ldata.layers[i].offset;
void *e1, *e2;
e1 = BM_ELEM_CD_GET_VOID_P(l_first, offset);
e2 = BM_ELEM_CD_GET_VOID_P(l, offset);
CustomData_data_multiply(type, e2, fac);
if (l != l_first) {
CustomData_data_add(type, e1, e2);
}
}
}
}
BMO_ITER (v, &siter, op->slots_in, "verts", BM_VERT) {
BM_ITER_ELEM (l, &iter, v, BM_LOOPS_OF_VERT) {
if (l == l_first) {
continue;
}
CustomData_bmesh_copy_data(&bm->ldata, &bm->ldata, l_first->head.data, &l->head.data);
}
}
}
void bmo_average_vert_facedata_exec(BMesh *bm, BMOperator *op)
{
BMOIter siter;
BMIter iter;
BMVert *v;
BMLoop *l /* , *firstl = NULL */;
CDBlockBytes min, max;
int i;
for (i = 0; i < bm->ldata.totlayer; i++) {
const int type = bm->ldata.layers[i].type;
const int offset = bm->ldata.layers[i].offset;
if (!CustomData_layer_has_math(&bm->ldata, i))
continue;
CustomData_data_initminmax(type, &min, &max);
BMO_ITER (v, &siter, op->slots_in, "verts", BM_VERT) {
BM_ITER_ELEM (l, &iter, v, BM_LOOPS_OF_VERT) {
void *block = BM_ELEM_CD_GET_VOID_P(l, offset);
CustomData_data_dominmax(type, block, &min, &max);
}
}
CustomData_data_multiply(type, &min, 0.5f);
CustomData_data_multiply(type, &max, 0.5f);
CustomData_data_add(type, &min, &max);
BMO_ITER (v, &siter, op->slots_in, "verts", BM_VERT) {
BM_ITER_ELEM (l, &iter, v, BM_LOOPS_OF_VERT) {
void *block = BM_ELEM_CD_GET_VOID_P(l, offset);
CustomData_data_copy_value(type, &min, block);
}
}
}
}
void bmo_pointmerge_exec(BMesh *bm, BMOperator *op)
{
BMOperator weldop;
BMOIter siter;
BMVert *v, *vert_snap = NULL;
float vec[3];
BMOpSlot *slot_targetmap;
BMO_slot_vec_get(op->slots_in, "merge_co", vec);
//BMO_op_callf(bm, op->flag, "collapse_uvs edges=%s", op, "edges");
BMO_op_init(bm, &weldop, op->flag, "weld_verts");
slot_targetmap = BMO_slot_get(weldop.slots_in, "targetmap");
BMO_ITER (v, &siter, op->slots_in, "verts", BM_VERT) {
if (!vert_snap) {
vert_snap = v;
copy_v3_v3(vert_snap->co, vec);
}
else {
BMO_slot_map_elem_insert(&weldop, slot_targetmap, v, vert_snap);
}
}
BMO_op_exec(bm, &weldop);
BMO_op_finish(bm, &weldop);
}
void bmo_collapse_exec(BMesh *bm, BMOperator *op)
{
BMOperator weldop;
BMWalker walker;
BMIter iter;
BMEdge *e;
BLI_Stack *edge_stack;
BMOpSlot *slot_targetmap;
if (BMO_slot_bool_get(op->slots_in, "uvs")) {
BMO_op_callf(bm, op->flag, "collapse_uvs edges=%s", op, "edges");
}
BMO_op_init(bm, &weldop, op->flag, "weld_verts");
slot_targetmap = BMO_slot_get(weldop.slots_in, "targetmap");
BMO_slot_buffer_flag_enable(bm, op->slots_in, "edges", BM_EDGE, EDGE_MARK);
BMW_init(&walker, bm, BMW_VERT_SHELL,
BMW_MASK_NOP, EDGE_MARK, BMW_MASK_NOP,
BMW_FLAG_NOP, /* no need to use BMW_FLAG_TEST_HIDDEN, already marked data */
BMW_NIL_LAY);
edge_stack = BLI_stack_new(sizeof(BMEdge *), __func__);
BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
float min[3], max[3], center[3];
BMVert *v_tar;
if (!BMO_elem_flag_test(bm, e, EDGE_MARK))
continue;
BLI_assert(BLI_stack_is_empty(edge_stack));
INIT_MINMAX(min, max);
for (e = BMW_begin(&walker, e->v1); e; e = BMW_step(&walker)) {
BLI_stack_push(edge_stack, &e);
minmax_v3v3_v3(min, max, e->v1->co);
minmax_v3v3_v3(min, max, e->v2->co);
/* prevent adding to slot_targetmap multiple times */
BM_elem_flag_disable(e->v1, BM_ELEM_TAG);
BM_elem_flag_disable(e->v2, BM_ELEM_TAG);
}
if (!BLI_stack_is_empty(edge_stack)) {
mid_v3_v3v3(center, min, max);
/* snap edges to a point. for initial testing purposes anyway */
e = *(BMEdge **)BLI_stack_peek(edge_stack);
v_tar = e->v1;
while (!BLI_stack_is_empty(edge_stack)) {
unsigned int j;
BLI_stack_pop(edge_stack, &e);
for (j = 0; j < 2; j++) {
BMVert *v_src = *((&e->v1) + j);
copy_v3_v3(v_src->co, center);
if ((v_src != v_tar) && !BM_elem_flag_test(v_src, BM_ELEM_TAG)) {
BM_elem_flag_enable(v_src, BM_ELEM_TAG);
BMO_slot_map_elem_insert(&weldop, slot_targetmap, v_src, v_tar);
}
}
}
}
}
BLI_stack_free(edge_stack);
BMO_op_exec(bm, &weldop);
BMO_op_finish(bm, &weldop);
BMW_end(&walker);
}
/* uv collapse function */
static void bmo_collapsecon_do_layer(BMesh *bm, const int layer, const short oflag)
{
const int type = bm->ldata.layers[layer].type;
const int offset = bm->ldata.layers[layer].offset;
BMIter iter, liter;
BMFace *f;
BMLoop *l, *l2;
BMWalker walker;
BLI_Stack *block_stack;
CDBlockBytes min, max;
BMW_init(&walker, bm, BMW_LOOPDATA_ISLAND,
BMW_MASK_NOP, oflag, BMW_MASK_NOP,
BMW_FLAG_NOP, /* no need to use BMW_FLAG_TEST_HIDDEN, already marked data */
layer);
block_stack = BLI_stack_new(sizeof(void *), __func__);
BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) {
if (BMO_elem_flag_test(bm, l->e, oflag)) {
/* walk */
BLI_assert(BLI_stack_is_empty(block_stack));
CustomData_data_initminmax(type, &min, &max);
for (l2 = BMW_begin(&walker, l); l2; l2 = BMW_step(&walker)) {
void *block = BM_ELEM_CD_GET_VOID_P(l2, offset);
CustomData_data_dominmax(type, block, &min, &max);
BLI_stack_push(block_stack, &block);
}
if (!BLI_stack_is_empty(block_stack)) {
CustomData_data_multiply(type, &min, 0.5f);
CustomData_data_multiply(type, &max, 0.5f);
CustomData_data_add(type, &min, &max);
/* snap CD (uv, vcol) points to their centroid */
while (!BLI_stack_is_empty(block_stack)) {
void *block;
BLI_stack_pop(block_stack, &block);
CustomData_data_copy_value(type, &min, block);
}
}
}
}
}
BLI_stack_free(block_stack);
BMW_end(&walker);
}
void bmo_collapse_uvs_exec(BMesh *bm, BMOperator *op)
{
const short oflag = EDGE_MARK;
int i;
/* check flags dont change once set */
#ifndef NDEBUG
int tot_test;
#endif
if (!CustomData_has_math(&bm->ldata)) {
return;
}
BMO_slot_buffer_flag_enable(bm, op->slots_in, "edges", BM_EDGE, oflag);
#ifndef NDEBUG
tot_test = BM_iter_mesh_count_flag(BM_EDGES_OF_MESH, bm, oflag, true);
#endif
for (i = 0; i < bm->ldata.totlayer; i++) {
if (CustomData_layer_has_math(&bm->ldata, i))
bmo_collapsecon_do_layer(bm, i, oflag);
}
#ifndef NDEBUG
BLI_assert(tot_test == BM_iter_mesh_count_flag(BM_EDGES_OF_MESH, bm, EDGE_MARK, true));
#endif
}
static void bmesh_find_doubles_common(
BMesh *bm, BMOperator *op,
BMOperator *optarget, BMOpSlot *optarget_slot)
{
BMVert **verts;
int verts_len;
int i, j, keepvert = 0;
const float dist = BMO_slot_float_get(op->slots_in, "dist");
const float dist_sq = dist * dist;
const float dist3 = ((float)M_SQRT3 + 0.00005f) * dist; /* Just above sqrt(3) */
/* Test whether keep_verts arg exists and is non-empty */
if (BMO_slot_exists(op->slots_in, "keep_verts")) {
BMOIter oiter;
keepvert = BMO_iter_new(&oiter, op->slots_in, "keep_verts", BM_VERT) != NULL;
}
/* get the verts as an array we can sort */
verts = BMO_slot_as_arrayN(op->slots_in, "verts", &verts_len);
/* sort by vertex coordinates added together */
qsort(verts, verts_len, sizeof(BMVert *), vergaverco);
/* Flag keep_verts */
if (keepvert) {
BMO_slot_buffer_flag_enable(bm, op->slots_in, "keep_verts", BM_VERT, VERT_KEEP);
}
for (i = 0; i < verts_len; i++) {
BMVert *v_check = verts[i];
if (BMO_elem_flag_test(bm, v_check, VERT_DOUBLE | VERT_TARGET)) {
continue;
}
for (j = i + 1; j < verts_len; j++) {
BMVert *v_other = verts[j];
/* a match has already been found, (we could check which is best, for now don't) */
if (BMO_elem_flag_test(bm, v_other, VERT_DOUBLE | VERT_TARGET)) {
continue;
}
/* Compare sort values of the verts using 3x tolerance (allowing for the tolerance
* on each of the three axes). This avoids the more expensive length comparison
* for most vertex pairs. */
if ((v_other->co[0] + v_other->co[1] + v_other->co[2]) -
(v_check->co[0] + v_check->co[1] + v_check->co[2]) > dist3)
{
break;
}
if (keepvert) {
if (BMO_elem_flag_test(bm, v_other, VERT_KEEP) == BMO_elem_flag_test(bm, v_check, VERT_KEEP))
continue;
}
if (compare_len_squared_v3v3(v_check->co, v_other->co, dist_sq)) {
/* If one vert is marked as keep, make sure it will be the target */
if (BMO_elem_flag_test(bm, v_other, VERT_KEEP)) {
SWAP(BMVert *, v_check, v_other);
}
BMO_elem_flag_enable(bm, v_other, VERT_DOUBLE);
BMO_elem_flag_enable(bm, v_check, VERT_TARGET);
BMO_slot_map_elem_insert(optarget, optarget_slot, v_other, v_check);
}
}
}
MEM_freeN(verts);
}
void bmo_remove_doubles_exec(BMesh *bm, BMOperator *op)
{
BMOperator weldop;
BMOpSlot *slot_targetmap;
BMO_op_init(bm, &weldop, op->flag, "weld_verts");
slot_targetmap = BMO_slot_get(weldop.slots_in, "targetmap");
bmesh_find_doubles_common(bm, op,
&weldop, slot_targetmap);
BMO_op_exec(bm, &weldop);
BMO_op_finish(bm, &weldop);
}
void bmo_find_doubles_exec(BMesh *bm, BMOperator *op)
{
BMOpSlot *slot_targetmap_out;
slot_targetmap_out = BMO_slot_get(op->slots_out, "targetmap.out");
bmesh_find_doubles_common(bm, op,
op, slot_targetmap_out);
}
void bmo_automerge_exec(BMesh *bm, BMOperator *op)
{
BMOperator findop, weldop;
BMIter viter;
BMVert *v;
/* The "verts" input sent to this op is the set of verts that
* can be merged away into any other verts. Mark all other verts
* as VERT_KEEP. */
BMO_slot_buffer_flag_enable(bm, op->slots_in, "verts", BM_VERT, VERT_IN);
BM_ITER_MESH (v, &viter, bm, BM_VERTS_OF_MESH) {
if (!BMO_elem_flag_test(bm, v, VERT_IN)) {
BMO_elem_flag_enable(bm, v, VERT_KEEP);
}
}
/* Search for doubles among all vertices, but only merge non-VERT_KEEP
* vertices into VERT_KEEP vertices. */
BMO_op_initf(bm, &findop, op->flag, "find_doubles verts=%av keep_verts=%fv", VERT_KEEP);
BMO_slot_copy(op, slots_in, "dist",
&findop, slots_in, "dist");
BMO_op_exec(bm, &findop);
/* weld the vertices */
BMO_op_init(bm, &weldop, op->flag, "weld_verts");
BMO_slot_copy(&findop, slots_out, "targetmap.out",
&weldop, slots_in, "targetmap");
BMO_op_exec(bm, &weldop);
BMO_op_finish(bm, &findop);
BMO_op_finish(bm, &weldop);
}
|