BMesh: add ability not to delete vertex when collapsing
[blender.git] / source / blender / bmesh / intern / bmesh_core.c
index 812c223dcc400bed8ef955d05d427adce7a3318b..c4dc990918587a8efe6983bc6dcd77a80efa3023 100644 (file)
@@ -1657,7 +1657,8 @@ BMVert *bmesh_semv(BMesh *bm, BMVert *tv, BMEdge *e, BMEdge **r_e)
  * faces with just 2 edges. It is up to the caller to decide what to do with
  * these faces.
  */
-BMEdge *bmesh_jekv(BMesh *bm, BMEdge *e_kill, BMVert *v_kill, const bool check_edge_double)
+BMEdge *bmesh_jekv(BMesh *bm, BMEdge *e_kill, BMVert *v_kill,
+                   const bool do_del, const bool check_edge_double)
 {
        BMEdge *e_old;
        BMVert *v_old, *tv;
@@ -1668,6 +1669,8 @@ BMEdge *bmesh_jekv(BMesh *bm, BMEdge *e_kill, BMVert *v_kill, const bool check_e
        bool edok;
 #endif
 
+       BLI_assert(BM_vert_in_edge(e_kill, v_kill));
+
        if (BM_vert_in_edge(e_kill, v_kill) == 0) {
                return NULL;
        }
@@ -1759,7 +1762,12 @@ BMEdge *bmesh_jekv(BMesh *bm, BMEdge *e_kill, BMVert *v_kill, const bool check_e
                        bm_kill_only_edge(bm, e_kill);
 
                        /* deallocate vertex */
-                       bm_kill_only_vert(bm, v_kill);
+                       if (do_del) {
+                               bm_kill_only_vert(bm, v_kill);
+                       }
+                       else {
+                               v_kill->e = NULL;
+                       }
 
 #ifndef NDEBUG
                        /* Validate disk cycle lengths of v_old, tv are unchanged */