c45e617dd39045d44a6801eae7dc7fa794a5cce8
[blender.git] / source / blender / bmesh / tools / bmesh_wireframe.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * Contributor(s): Campbell Barton
19  *
20  * ***** END GPL LICENSE BLOCK *****
21  */
22
23 /** \file blender/bmesh/tools/bmesh_wireframe.c
24  *  \ingroup bmesh
25  *
26  * Creates a solid wireframe from connected faces.
27  */
28
29 #include "MEM_guardedalloc.h"
30
31 #include "DNA_object_types.h"
32 #include "DNA_meshdata_types.h"
33
34 #include "BLI_math.h"
35
36 #include "bmesh.h"
37
38 #include "BKE_deform.h"
39 #include "BKE_customdata.h"
40
41 #include "bmesh_wireframe.h"
42
43 static BMLoop *bm_edge_tag_faceloop(BMEdge *e)
44 {
45         BMLoop *l, *l_first;
46
47         l = l_first = e->l;
48         do {
49                 if (BM_elem_flag_test(l->f, BM_ELEM_TAG)) {
50                         return l;
51                 }
52         } while ((l = l->radial_next) != l_first);
53
54         /* in the case this is used, we know this will never happen */
55         return NULL;
56 }
57
58 static void bm_vert_boundary_tangent(
59         BMVert *v, float r_no[3], float r_no_face[3],
60         BMVert **r_va_other, BMVert **r_vb_other)
61 {
62         BMIter iter;
63         BMEdge *e_iter;
64
65         BMEdge *e_a = NULL, *e_b = NULL;
66         BMVert *v_a, *v_b;
67
68         BMLoop *l_a, *l_b;
69
70         float no_face[3], no_edge[3];
71         float tvec_a[3], tvec_b[3];
72
73         /* get 2 boundary edges, there should only _be_ 2,
74          * in case there are more - results wont be valid of course */
75         BM_ITER_ELEM (e_iter, &iter, v, BM_EDGES_OF_VERT) {
76                 if (BM_elem_flag_test(e_iter, BM_ELEM_TAG)) {
77                         if (e_a == NULL) {
78                                 e_a = e_iter;
79                         }
80                         else {
81                                 e_b = e_iter;
82                                 break;
83                         }
84                 }
85         }
86
87         if (e_a && e_b) {
88                 /* note, with an incorrectly flushed selection this can crash */
89                 l_a = bm_edge_tag_faceloop(e_a);
90                 l_b = bm_edge_tag_faceloop(e_b);
91
92                 /* average edge face normal */
93                 add_v3_v3v3(no_face, l_a->f->no, l_b->f->no);
94                 normalize_v3(no_face);
95
96                 /* average edge direction */
97                 v_a = BM_edge_other_vert(e_a, v);
98                 v_b = BM_edge_other_vert(e_b, v);
99
100                 sub_v3_v3v3(tvec_a, v->co, v_a->co);
101                 sub_v3_v3v3(tvec_b, v_b->co, v->co);
102                 normalize_v3(tvec_a);
103                 normalize_v3(tvec_b);
104                 add_v3_v3v3(no_edge, tvec_a, tvec_b); /* not unit length but this is ok */
105
106                 /* check are we flipped the right way */
107                 BM_edge_calc_face_tangent(e_a, l_a, tvec_a);
108                 BM_edge_calc_face_tangent(e_b, l_b, tvec_b);
109                 add_v3_v3(tvec_a, tvec_b);
110
111                 *r_va_other = v_a;
112                 *r_vb_other = v_b;
113         }
114         else {
115                 /* degenerate case - vertex connects a boundary edged face to other faces,
116                  * so we have only one boundary face - only use it for calculations */
117                 l_a = bm_edge_tag_faceloop(e_a);
118
119                 copy_v3_v3(no_face, l_a->f->no);
120
121                 /* edge direction */
122                 v_a = BM_edge_other_vert(e_a, v);
123                 v_b = NULL;
124
125                 sub_v3_v3v3(no_edge, v->co, v_a->co);
126
127                 /* check are we flipped the right way */
128                 BM_edge_calc_face_tangent(e_a, l_a, tvec_a);
129
130                 *r_va_other = NULL;
131                 *r_vb_other = NULL;
132         }
133
134         /* find the normal */
135         cross_v3_v3v3(r_no, no_edge, no_face);
136         normalize_v3(r_no);
137
138         if (dot_v3v3(r_no, tvec_a) > 0.0f) {
139                 negate_v3(r_no);
140         }
141
142         copy_v3_v3(r_no_face, no_face);
143 }
144
145 /* check if we are the only tagged loop-face around this edge */
146 static bool bm_loop_is_radial_boundary(BMLoop *l_first)
147 {
148         BMLoop *l = l_first->radial_next;
149
150         if (l == l_first) {
151                 return true; /* a real boundary */
152         }
153         else {
154                 do {
155                         if (BM_elem_flag_test(l->f, BM_ELEM_TAG)) {
156                                 return false;
157                         }
158                 } while ((l = l->radial_next) != l_first);
159         }
160         return true;
161 }
162
163 /**
164  * \param defgrp_index: Vertex group index, -1 for no vertex groups.
165  *
166  * \note All edge tags must be cleared.
167  * \note Behavior matches MOD_solidify.c
168  */
169 void BM_mesh_wireframe(
170         BMesh *bm,
171         const float offset,
172         const float offset_fac,
173         const float offset_fac_vg,
174         const bool use_replace,
175         const bool use_boundary,
176         const bool use_even_offset,
177         const bool use_relative_offset,
178         const bool use_crease,
179         const float crease_weight,
180         const int defgrp_index,
181         const bool defgrp_invert,
182         const short mat_offset,
183         const short mat_max,
184         /* for operators */
185         const bool use_tag
186         )
187 {
188         const float ofs_orig = -(((-offset_fac + 1.0f) * 0.5f) * offset);
189         const float ofs_new  = offset + ofs_orig;
190         const float ofs_mid  = (ofs_orig + ofs_new) / 2.0f;
191         const float inset = offset / 2.0f;
192         int cd_edge_crease_offset = use_crease ? CustomData_get_offset(&bm->edata, CD_CREASE) : -1;
193         const int cd_dvert_offset = (defgrp_index != -1) ? CustomData_get_offset(&bm->vdata, CD_MDEFORMVERT) : -1;
194         const float offset_fac_vg_inv = 1.0f - offset_fac_vg;
195
196         const int totvert_orig = bm->totvert;
197
198         BMIter iter;
199         BMIter itersub;
200
201         /* filled only with boundary verts */
202         BMVert **verts_src      = MEM_mallocN(sizeof(BMVert *) * totvert_orig, __func__);
203         BMVert **verts_neg      = MEM_mallocN(sizeof(BMVert *) * totvert_orig, __func__);
204         BMVert **verts_pos      = MEM_mallocN(sizeof(BMVert *) * totvert_orig, __func__);
205
206         /* will over-alloc, but makes for easy lookups by index to keep aligned  */
207         BMVert **verts_boundary = use_boundary ?
208                                   MEM_mallocN(sizeof(BMVert *) * totvert_orig, __func__) : NULL;
209
210         float  *verts_relfac    = (use_relative_offset || (cd_dvert_offset != -1)) ?
211                                   MEM_mallocN(sizeof(float) * totvert_orig, __func__) : NULL;
212
213         /* may over-alloc if not all faces have wire */
214         BMVert **verts_loop;
215         int verts_loop_tot = 0;
216
217         BMVert *v_src;
218
219         BMFace *f_src;
220         BMLoop *l;
221
222         float tvec[3];
223         float fac, fac_shell;
224
225         int i;
226
227         if (use_crease && cd_edge_crease_offset == -1) {
228                 BM_data_layer_add(bm, &bm->edata, CD_CREASE);
229                 cd_edge_crease_offset = CustomData_get_offset(&bm->edata, CD_CREASE);
230         }
231
232         BM_ITER_MESH_INDEX (v_src, &iter, bm, BM_VERTS_OF_MESH, i) {
233                 BM_elem_index_set(v_src, i); /* set_inline */
234
235                 verts_src[i] = v_src;
236                 BM_elem_flag_disable(v_src, BM_ELEM_TAG);
237         }
238         bm->elem_index_dirty &= ~BM_VERT;
239
240         /* setup tags, all faces and verts will be tagged which will be duplicated */
241
242         BM_ITER_MESH_INDEX (f_src, &iter, bm, BM_FACES_OF_MESH, i) {
243                 BM_elem_index_set(f_src, i); /* set_inline */
244
245                 if (use_tag) {
246                         if (!BM_elem_flag_test(f_src, BM_ELEM_TAG)) {
247                                 continue;
248                         }
249                 }
250                 else {
251                         BM_elem_flag_enable(f_src, BM_ELEM_TAG);
252                 }
253
254
255                 verts_loop_tot += f_src->len;
256                 BM_ITER_ELEM (l, &itersub, f_src, BM_LOOPS_OF_FACE) {
257                         BM_elem_flag_enable(l->v, BM_ELEM_TAG);
258
259                         /* also tag boundary edges */
260                         BM_elem_flag_set(l->e, BM_ELEM_TAG, bm_loop_is_radial_boundary(l));
261                 }
262         }
263         bm->elem_index_dirty &= ~BM_FACE;
264
265         /* duplicate tagged verts */
266         for (i = 0; i < totvert_orig; i++) {
267                 v_src = verts_src[i];
268                 if (BM_elem_flag_test(v_src, BM_ELEM_TAG)) {
269                         fac = 1.0f;
270
271                         if (verts_relfac) {
272                                 if (use_relative_offset) {
273                                         verts_relfac[i] = BM_vert_calc_mean_tagged_edge_length(v_src);
274                                 }
275                                 else {
276                                         verts_relfac[i] = 1.0f;
277                                 }
278
279
280                                 if (cd_dvert_offset != -1) {
281                                         MDeformVert *dvert = BM_ELEM_CD_GET_VOID_P(v_src, cd_dvert_offset);
282                                         float defgrp_fac = defvert_find_weight(dvert, defgrp_index);
283
284                                         if (defgrp_invert) {
285                                                 defgrp_fac = 1.0f - defgrp_fac;
286                                         }
287
288                                         if (offset_fac_vg > 0.0f) {
289                                                 defgrp_fac = (offset_fac_vg + (defgrp_fac * offset_fac_vg_inv));
290                                         }
291
292                                         verts_relfac[i] *= defgrp_fac;
293                                 }
294
295                                 fac *= verts_relfac[i];
296                         }
297
298
299                         verts_neg[i] = BM_vert_create(bm, NULL, v_src, BM_CREATE_NOP);
300                         verts_pos[i] = BM_vert_create(bm, NULL, v_src, BM_CREATE_NOP);
301
302                         if (offset == 0.0f) {
303                                 madd_v3_v3v3fl(verts_neg[i]->co, v_src->co, v_src->no, ofs_orig * fac);
304                                 madd_v3_v3v3fl(verts_pos[i]->co, v_src->co, v_src->no,  ofs_new * fac);
305                         }
306                         else {
307                                 madd_v3_v3v3fl(tvec, v_src->co, v_src->no, ofs_mid * fac);
308
309                                 madd_v3_v3v3fl(verts_neg[i]->co, tvec, v_src->no, (ofs_orig - ofs_mid) * fac);
310                                 madd_v3_v3v3fl(verts_pos[i]->co, tvec, v_src->no,  (ofs_new - ofs_mid) * fac);
311                         }
312                 }
313                 else {
314                         /* could skip this */
315                         verts_neg[i] = NULL;
316                         verts_pos[i] = NULL;
317                 }
318
319                 /* conflicts with BM_vert_calc_mean_tagged_edge_length */
320                 if (use_relative_offset == false) {
321                         BM_elem_flag_disable(v_src, BM_ELEM_TAG);
322                 }
323         }
324
325         if (use_relative_offset) {
326                 BM_mesh_elem_hflag_disable_all(bm, BM_VERT, BM_ELEM_TAG, false);
327         }
328
329         verts_loop = MEM_mallocN(sizeof(BMVert *) * verts_loop_tot, __func__);
330         verts_loop_tot = 0; /* count up again */
331
332         BM_ITER_MESH (f_src, &iter, bm, BM_FACES_OF_MESH) {
333
334                 if (use_tag && !BM_elem_flag_test(f_src, BM_ELEM_TAG)) {
335                         continue;
336                 }
337
338                 BM_ITER_ELEM (l, &itersub, f_src, BM_LOOPS_OF_FACE) {
339                         BM_elem_index_set(l, verts_loop_tot); /* set_dirty */  /* Because some faces might be skipped! */
340
341                         BM_loop_calc_face_tangent(l, tvec);
342
343                         /* create offset vert */
344                         fac = 1.0f;
345
346                         if (verts_relfac) {
347                                 fac *= verts_relfac[BM_elem_index_get(l->v)];
348                         }
349
350                         fac_shell = fac;
351                         if (use_even_offset) {
352                                 fac_shell *= shell_angle_to_dist(((float)M_PI - BM_loop_calc_face_angle(l)) * 0.5f);
353                         }
354
355
356                         madd_v3_v3v3fl(tvec, l->v->co, tvec, inset * fac_shell);
357                         if (offset != 0.0f) {
358                                 madd_v3_v3fl(tvec, l->v->no, ofs_mid * fac);
359                         }
360                         verts_loop[verts_loop_tot] = BM_vert_create(bm, tvec, l->v, BM_CREATE_NOP);
361
362
363                         if (use_boundary) {
364                                 if (BM_elem_flag_test(l->e, BM_ELEM_TAG)) {  /* is this a boundary? */
365                                         BMVert *v_pair[2] = {l->v, l->next->v};
366
367                                         for (i = 0; i < 2; i++) {
368                                                 BMVert *v_boundary = v_pair[i];
369                                                 if (!BM_elem_flag_test(v_boundary, BM_ELEM_TAG)) {
370                                                         const int v_boundary_index = BM_elem_index_get(v_boundary);
371                                                         float no_face[3];
372                                                         BMVert *va_other;
373                                                         BMVert *vb_other;
374
375                                                         BM_elem_flag_enable(v_boundary, BM_ELEM_TAG);
376
377                                                         bm_vert_boundary_tangent(v_boundary, tvec, no_face, &va_other, &vb_other);
378
379                                                         /* create offset vert */
380                                                         /* similar to code above but different angle calc */
381                                                         fac = 1.0f;
382
383                                                         if (verts_relfac) {
384                                                                 fac *= verts_relfac[v_boundary_index];
385                                                         }
386
387                                                         fac_shell = fac;
388                                                         if (use_even_offset) {
389                                                                 if (va_other) {  /* for verts with only one boundary edge - this will be NULL */
390                                                                         fac_shell *= shell_angle_to_dist(((float)M_PI -
391                                                                                                           angle_on_axis_v3v3v3_v3(va_other->co,
392                                                                                                                                   v_boundary->co,
393                                                                                                                                   vb_other->co,
394                                                                                                                                   no_face)) * 0.5f);
395                                                                 }
396                                                         }
397
398
399                                                         madd_v3_v3v3fl(tvec, v_boundary->co, tvec, inset * fac_shell);
400                                                         if (offset != 0.0f) {
401                                                                 madd_v3_v3fl(tvec, v_boundary->no, ofs_mid * fac);
402                                                         }
403                                                         verts_boundary[v_boundary_index] = BM_vert_create(bm, tvec, v_boundary, BM_CREATE_NOP);
404                                                 }
405                                         }
406                                 }
407                         }
408
409                         verts_loop_tot++;
410                 }
411         }
412         bm->elem_index_dirty |= BM_LOOP;
413
414         BM_ITER_MESH (f_src, &iter, bm, BM_FACES_OF_MESH) {
415
416                 /* skip recently added faces */
417                 if (BM_elem_index_get(f_src) == -1) {
418                         continue;
419                 }
420
421                 if (use_tag && !BM_elem_flag_test(f_src, BM_ELEM_TAG)) {
422                         continue;
423                 }
424
425                 BM_elem_flag_disable(f_src, BM_ELEM_TAG);
426
427                 BM_ITER_ELEM (l, &itersub, f_src, BM_LOOPS_OF_FACE) {
428                         BMFace *f_new;
429                         BMLoop *l_new;
430                         BMLoop *l_next = l->next;
431                         BMVert *v_l1 = verts_loop[BM_elem_index_get(l)];
432                         BMVert *v_l2 = verts_loop[BM_elem_index_get(l_next)];
433
434                         BMVert *v_src_l1 = l->v;
435                         BMVert *v_src_l2 = l_next->v;
436
437                         const int i_1 = BM_elem_index_get(v_src_l1);
438                         const int i_2 = BM_elem_index_get(v_src_l2);
439
440                         BMVert *v_neg1 = verts_neg[i_1];
441                         BMVert *v_neg2 = verts_neg[i_2];
442
443                         BMVert *v_pos1 = verts_pos[i_1];
444                         BMVert *v_pos2 = verts_pos[i_2];
445
446                         f_new = BM_face_create_quad_tri(bm, v_l1, v_l2, v_neg2, v_neg1, f_src, BM_CREATE_NOP);
447                         if (mat_offset) f_new->mat_nr = CLAMPIS(f_new->mat_nr + mat_offset, 0, mat_max);
448                         BM_elem_flag_enable(f_new, BM_ELEM_TAG);
449                         l_new = BM_FACE_FIRST_LOOP(f_new);
450
451                         BM_elem_attrs_copy(bm, bm, l,      l_new);
452                         BM_elem_attrs_copy(bm, bm, l,      l_new->prev);
453                         BM_elem_attrs_copy(bm, bm, l_next, l_new->next);
454                         BM_elem_attrs_copy(bm, bm, l_next, l_new->next->next);
455
456                         f_new = BM_face_create_quad_tri(bm, v_l2, v_l1, v_pos1, v_pos2, f_src, BM_CREATE_NOP);
457
458                         if (mat_offset) f_new->mat_nr = CLAMPIS(f_new->mat_nr + mat_offset, 0, mat_max);
459                         BM_elem_flag_enable(f_new, BM_ELEM_TAG);
460                         l_new = BM_FACE_FIRST_LOOP(f_new);
461
462                         BM_elem_attrs_copy(bm, bm, l_next, l_new);
463                         BM_elem_attrs_copy(bm, bm, l_next, l_new->prev);
464                         BM_elem_attrs_copy(bm, bm, l,      l_new->next);
465                         BM_elem_attrs_copy(bm, bm, l,      l_new->next->next);
466
467                         if (use_boundary) {
468                                 if (BM_elem_flag_test(l->e, BM_ELEM_TAG)) {
469                                         /* we know its a boundary and this is the only face user (which is being wire'd) */
470                                         /* we know we only touch this edge/face once */
471                                         BMVert *v_b1 = verts_boundary[i_1];
472                                         BMVert *v_b2 = verts_boundary[i_2];
473
474                                         f_new = BM_face_create_quad_tri(bm, v_b2, v_b1, v_neg1, v_neg2, f_src, BM_CREATE_NOP);
475                                         if (mat_offset) f_new->mat_nr = CLAMPIS(f_new->mat_nr + mat_offset, 0, mat_max);
476                                         BM_elem_flag_enable(f_new, BM_ELEM_TAG);
477                                         l_new = BM_FACE_FIRST_LOOP(f_new);
478
479                                         BM_elem_attrs_copy(bm, bm, l_next, l_new);
480                                         BM_elem_attrs_copy(bm, bm, l_next, l_new->prev);
481                                         BM_elem_attrs_copy(bm, bm, l,      l_new->next);
482                                         BM_elem_attrs_copy(bm, bm, l,      l_new->next->next);
483
484                                         f_new = BM_face_create_quad_tri(bm, v_b1, v_b2, v_pos2, v_pos1, f_src, BM_CREATE_NOP);
485                                         if (mat_offset) f_new->mat_nr = CLAMPIS(f_new->mat_nr + mat_offset, 0, mat_max);
486                                         BM_elem_flag_enable(f_new, BM_ELEM_TAG);
487                                         l_new = BM_FACE_FIRST_LOOP(f_new);
488
489                                         BM_elem_attrs_copy(bm, bm, l,      l_new);
490                                         BM_elem_attrs_copy(bm, bm, l,      l_new->prev);
491                                         BM_elem_attrs_copy(bm, bm, l_next, l_new->next);
492                                         BM_elem_attrs_copy(bm, bm, l_next, l_new->next->next);
493
494                                         if (use_crease) {
495                                                 BMEdge *e_new;
496                                                 e_new = BM_edge_exists(v_pos1, v_b1);
497                                                 BM_ELEM_CD_SET_FLOAT(e_new, cd_edge_crease_offset, crease_weight);
498
499                                                 e_new = BM_edge_exists(v_pos2, v_b2);
500                                                 BM_ELEM_CD_SET_FLOAT(e_new, cd_edge_crease_offset, crease_weight);
501
502                                                 e_new = BM_edge_exists(v_neg1, v_b1);
503                                                 BM_ELEM_CD_SET_FLOAT(e_new, cd_edge_crease_offset, crease_weight);
504
505                                                 e_new = BM_edge_exists(v_neg2, v_b2);
506                                                 BM_ELEM_CD_SET_FLOAT(e_new, cd_edge_crease_offset, crease_weight);
507                                         }
508                                 }
509                         }
510
511                         if (use_crease) {
512                                 BMEdge *e_new;
513                                 e_new = BM_edge_exists(v_pos1, v_l1);
514                                 BM_ELEM_CD_SET_FLOAT(e_new, cd_edge_crease_offset, crease_weight);
515
516                                 e_new = BM_edge_exists(v_pos2, v_l2);
517                                 BM_ELEM_CD_SET_FLOAT(e_new, cd_edge_crease_offset, crease_weight);
518
519                                 e_new = BM_edge_exists(v_neg1, v_l1);
520                                 BM_ELEM_CD_SET_FLOAT(e_new, cd_edge_crease_offset, crease_weight);
521
522                                 e_new = BM_edge_exists(v_neg2, v_l2);
523                                 BM_ELEM_CD_SET_FLOAT(e_new, cd_edge_crease_offset, crease_weight);
524                         }
525
526                 }
527         }
528
529         if (use_boundary) {
530                 MEM_freeN(verts_boundary);
531         }
532
533         if (verts_relfac) {
534                 MEM_freeN(verts_relfac);
535         }
536
537         if (use_replace) {
538
539                 if (use_tag) {
540                         /* only remove faces which are original and used to make wire,
541                          * use 'verts_pos' and 'verts_neg' to avoid a feedback loop. */
542
543                         /* vertex must be from 'verts_src' */
544 #define VERT_DUPE_TEST_ORIG(v)  (verts_neg[BM_elem_index_get(v)] != NULL)
545 #define VERT_DUPE_TEST(v)       (verts_pos[BM_elem_index_get(v)] != NULL)
546 #define VERT_DUPE_CLEAR(v)     { verts_pos[BM_elem_index_get(v)]  = NULL; } (void)0
547
548                         /* first ensure we keep all verts which are used in faces that weren't
549                          * entirely made into wire. */
550                         BM_ITER_MESH (f_src, &iter, bm, BM_FACES_OF_MESH) {
551                                 int mix_flag = 0;
552                                 BMLoop *l_iter, *l_first;
553
554                                 /* skip new faces */
555                                 if (BM_elem_index_get(f_src) == -1) {
556                                         continue;
557                                 }
558
559                                 l_iter = l_first = BM_FACE_FIRST_LOOP(f_src);
560                                 do {
561                                         mix_flag |= (VERT_DUPE_TEST_ORIG(l_iter->v) ? 1 : 2);
562                                         if (mix_flag == (1 | 2)) {
563                                                 break;
564                                         }
565                                 } while ((l_iter = l_iter->next) != l_first);
566
567                                 if (mix_flag == (1 | 2)) {
568                                         l_iter = l_first = BM_FACE_FIRST_LOOP(f_src);
569                                         do {
570                                                 VERT_DUPE_CLEAR(l_iter->v);
571                                         } while ((l_iter = l_iter->next) != l_first);
572                                 }
573                         }
574
575                         /* now remove any verts which were made into wire by all faces */
576                         for (i = 0; i < totvert_orig; i++) {
577                                 v_src = verts_src[i];
578                                 BLI_assert(i == BM_elem_index_get(v_src));
579                                 if (VERT_DUPE_TEST(v_src)) {
580                                         BM_vert_kill(bm, v_src);
581                                 }
582                         }
583
584 #undef VERT_DUPE_TEST_ORIG
585 #undef VERT_DUPE_TEST
586 #undef VERT_DUPE_CLEAR
587
588                 }
589                 else {
590                         /* simple case, no tags - replace all */
591                         for (i = 0; i < totvert_orig; i++) {
592                                 BM_vert_kill(bm, verts_src[i]);
593                         }
594                 }
595         }
596
597         MEM_freeN(verts_src);
598         MEM_freeN(verts_neg);
599         MEM_freeN(verts_pos);
600         MEM_freeN(verts_loop);
601 }