Fix weld edges into faces splicing verts that shared a face
authorCampbell Barton <ideasman42@gmail.com>
Wed, 23 Dec 2015 16:28:35 +0000 (03:28 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 23 Dec 2015 16:36:06 +0000 (03:36 +1100)
This could happen with degenerate faces.

source/blender/editors/mesh/editmesh_intersect.c

index d61e32794916a8f60c77b3963b935631da14c0f0..2c173a20eac141e11f9696e8f4716701f9de277c 100644 (file)
@@ -373,6 +373,26 @@ static void bm_face_split_by_edges(
        }
 }
 
+/**
+ * Check if a vert is in any of the faces connected to the edge,
+ * \a f_ignore is a face we happen to know isn't shared by the vertex.
+ */
+static bool bm_vert_in_faces_radial(BMVert *v, BMEdge *e_radial, BMFace *f_ignore)
+{
+       BLI_assert(BM_vert_in_face(v, f_ignore) == false);
+       if (e_radial->l) {
+               BMLoop *l_iter = e_radial->l;
+               do {
+                       if (l_iter->f != f_ignore) {
+                               if (BM_vert_in_face(v, l_iter->f)) {
+                                       return true;
+                               }
+                       }
+               } while ((l_iter = l_iter->radial_next) != e_radial->l);
+       }
+       return false;
+}
+
 #ifdef USE_NET_ISLAND_CONNECT
 
 struct LinkBase {
@@ -791,12 +811,15 @@ static int edbm_face_split_by_edges_exec(bContext *C, wmOperator *UNUSED(op))
                                                                v_pivot_co, &v_pivot_fac);
 
                                                        if (e_split) {
-                                                               BMEdge *e_new;
-                                                               BMVert *v_new = BM_edge_split(bm, e_split, e_split->v1, &e_new, v_pivot_fac);
-                                                               if (v_new) {
-                                                                       /* we _know_ these don't share an edge */
-                                                                       BM_vert_splice(bm, v_pivot, v_new);
-                                                                       BM_elem_index_set(e_new, BM_elem_index_get(e_split));
+                                                               /* for degenerate cases this vertex may be in one of this edges radial faces */
+                                                               if (!bm_vert_in_faces_radial(v_pivot, e_split, f)) {
+                                                                       BMEdge *e_new;
+                                                                       BMVert *v_new = BM_edge_split(bm, e_split, e_split->v1, &e_new, v_pivot_fac);
+                                                                       if (v_new) {
+                                                                               /* we _know_ these don't share an edge */
+                                                                               BM_vert_splice(bm, v_pivot, v_new);
+                                                                               BM_elem_index_set(e_new, BM_elem_index_get(e_split));
+                                                                       }
                                                                }
                                                        }
                                                }