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