Commit: e9dcb068c749bc9e73450a4feb491551ede58c07
Author: Campbell Barton
Date:   Thu Apr 30 07:22:18 2015 +1000
Branches: master
https://developer.blender.org/rBe9dcb068c749bc9e73450a4feb491551ede58c07

Fix T44484: Edge-split corrupts mesh

Splitting non-manifold edges could produce duplicate edges.

===================================================================

M       source/blender/bmesh/operators/bmo_split_edges.c
M       source/blender/bmesh/tools/bmesh_edgesplit.c
M       source/blender/bmesh/tools/bmesh_edgesplit.h
M       source/blender/bmesh/tools/bmesh_intersect.c
M       source/blender/editors/mesh/editmesh_rip.c
M       source/blender/modifiers/intern/MOD_edgesplit.c

===================================================================

diff --git a/source/blender/bmesh/operators/bmo_split_edges.c 
b/source/blender/bmesh/operators/bmo_split_edges.c
index eb7946c..ca20883 100644
--- a/source/blender/bmesh/operators/bmo_split_edges.c
+++ b/source/blender/bmesh/operators/bmo_split_edges.c
@@ -48,7 +48,7 @@ void bmo_split_edges_exec(BMesh *bm, BMOperator *op)
        }
 
        /* this is where everything happens */
-       BM_mesh_edgesplit(bm, use_verts, true, false);
+       BM_mesh_edgesplit(bm, use_verts, true, true, false);
 
        BMO_slot_buffer_from_enabled_hflag(bm, op, op->slots_out, "edges.out", 
BM_EDGE, BM_ELEM_INTERNAL_TAG);
 }
diff --git a/source/blender/bmesh/tools/bmesh_edgesplit.c 
b/source/blender/bmesh/tools/bmesh_edgesplit.c
index c01b488..30ba07c 100644
--- a/source/blender/bmesh/tools/bmesh_edgesplit.c
+++ b/source/blender/bmesh/tools/bmesh_edgesplit.c
@@ -42,7 +42,7 @@
  * un-tag edges not connected to other tagged edges,
  * unless they are on a boundary
  */
-static void bm_edgesplit_validate_seams(BMesh *bm)
+static void bm_edgesplit_validate_seams(BMesh *bm, const bool use_non_manifold)
 {
        BMIter iter;
        BMEdge *e;
@@ -72,6 +72,11 @@ static void bm_edgesplit_validate_seams(BMesh *bm)
                         * the edge its self can't be split */
                        BM_elem_flag_disable(e, BM_ELEM_TAG);
                }
+               else if ((use_non_manifold == false) &&
+                        (BM_edge_is_manifold(e) == false))
+               {
+                       BM_elem_flag_disable(e, BM_ELEM_TAG);
+               }
        }
 
        /* single marked edges unconnected to any other marked edges
@@ -98,7 +103,16 @@ static void bm_edgesplit_validate_seams(BMesh *bm)
        MEM_freeN(vtouch);
 }
 
-void BM_mesh_edgesplit(BMesh *bm, const bool use_verts, const bool tag_only, 
const bool copy_select)
+/**
+ * \param use_verts  Use flagged verts instead of edges.
+ * \param use_non_manifold  Split non-manifold edges (a little slower, must 
check for doubles).
+ * \param tag_only  Only split tagged edges.
+ * \param copy_select  Copy selection history.
+ */
+void BM_mesh_edgesplit(
+        BMesh *bm,
+        const bool use_verts, const bool use_non_manifold,
+        const bool tag_only, const bool copy_select)
 {
        BMIter iter;
        BMEdge *e;
@@ -142,7 +156,7 @@ void BM_mesh_edgesplit(BMesh *bm, const bool use_verts, 
const bool tag_only, con
                }
        }
 
-       bm_edgesplit_validate_seams(bm);
+       bm_edgesplit_validate_seams(bm, use_non_manifold);
 
        BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
                if (BM_elem_flag_test(e, BM_ELEM_TAG)) {
@@ -204,6 +218,29 @@ void BM_mesh_edgesplit(BMesh *bm, const bool use_verts, 
const bool tag_only, con
                }
        }
 
+       if (use_non_manifold) {
+               /* if we split non-manifold, double edge may remain */
+               BMEdge *e_next;
+               BM_ITER_MESH_MUTABLE (e, e_next, &iter, bm, BM_EDGES_OF_MESH) {
+                       if (BM_elem_flag_test(e, BM_ELEM_TAG)) {
+                               BMEdge *e_other;
+                               if ((e_other = BM_edge_find_double(e))) {
+                                       BM_edge_splice(bm, e, e_other);
+                               }
+                       }
+               }
+       }
+       else {
+#ifndef NDEBUG
+               /* ensure we don't have any double edges! */
+               BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
+                       if (BM_elem_flag_test(e, BM_ELEM_TAG)) {
+                               BLI_assert(BM_edge_find_double(e) == NULL);
+                       }
+               }
+#endif
+       }
+
        if (use_ese) {
                BLI_ghash_free(ese_gh, NULL, NULL);
        }
diff --git a/source/blender/bmesh/tools/bmesh_edgesplit.h 
b/source/blender/bmesh/tools/bmesh_edgesplit.h
index bd66f6a..531af96 100644
--- a/source/blender/bmesh/tools/bmesh_edgesplit.h
+++ b/source/blender/bmesh/tools/bmesh_edgesplit.h
@@ -27,6 +27,9 @@
  *  \ingroup bmesh
  */
 
-void BM_mesh_edgesplit(BMesh *bm, const bool use_verts, const bool tag_only, 
const bool copy_select);
+void BM_mesh_edgesplit(
+        BMesh *bm,
+        const bool use_verts, const bool use_non_manifold,
+        const bool tag_only, const bool copy_select);
 
 #endif /* __BMESH_EDGESPLIT_H__ */
diff --git a/source/blender/bmesh/tools/bmesh_intersect.c 
b/source/blender/bmesh/tools/bmesh_intersect.c
index ceb6ded..76a289f 100644
--- a/source/blender/bmesh/tools/bmesh_intersect.c
+++ b/source/blender/bmesh/tools/bmesh_intersect.c
@@ -1283,7 +1283,7 @@ bool BM_mesh_intersect(
                        BM_elem_flag_enable(e, BM_ELEM_TAG);
                }
 
-               BM_mesh_edgesplit(bm, false, true, false);
+               BM_mesh_edgesplit(bm, false, false, true, false);
        }
 #else
        (void)use_separate;
diff --git a/source/blender/editors/mesh/editmesh_rip.c 
b/source/blender/editors/mesh/editmesh_rip.c
index f5d22ea..7bd072a 100644
--- a/source/blender/editors/mesh/editmesh_rip.c
+++ b/source/blender/editors/mesh/editmesh_rip.c
@@ -941,7 +941,7 @@ static int edbm_rip_invoke__edge(bContext *C, wmOperator 
*op, const wmEvent *eve
                fill_uloop_pairs = edbm_tagged_loop_pairs_to_fill(bm);
        }
 
-       BM_mesh_edgesplit(em->bm, true, true, true);
+       BM_mesh_edgesplit(em->bm, true, true, true, true);
 
        /* note: the output of the bmesh operator is ignored, since we built
         * the contiguous loop pairs to split already, its possible that some
diff --git a/source/blender/modifiers/intern/MOD_edgesplit.c 
b/source/blender/modifiers/intern/MOD_edgesplit.c
index fa29921..2e6360c 100644
--- a/source/blender/modifiers/intern/MOD_edgesplit.c
+++ b/source/blender/modifiers/intern/MOD_edgesplit.c
@@ -91,7 +91,7 @@ static DerivedMesh *doEdgeSplit(DerivedMesh *dm, 
EdgeSplitModifierData *emd)
                }
        }
        
-       BM_mesh_edgesplit(bm, false, true, false);
+       BM_mesh_edgesplit(bm, false, false, true, false);
 
        /* BM_mesh_validate(bm); */ /* for troubleshooting */

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to