edge rotate now keeps edge properties (like seam, crease, bevel weight.. etc)
authorCampbell Barton <ideasman42@gmail.com>
Mon, 5 Mar 2012 01:53:30 +0000 (01:53 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 5 Mar 2012 01:53:30 +0000 (01:53 +0000)
source/blender/bmesh/intern/bmesh_core.c
source/blender/bmesh/intern/bmesh_core.h
source/blender/bmesh/intern/bmesh_mods.c
source/blender/bmesh/intern/bmesh_mods.h
source/blender/bmesh/operators/bmo_dissolve.c
source/blender/bmesh/operators/bmo_join_triangles.c
source/blender/bmesh/tools/BME_bevel.c
source/blender/editors/mesh/knifetool.c
source/blender/python/bmesh/bmesh_py_utils.c

index 97a7cb41eaa12ef23263c7166ad3432ee9644c2b..c95983c43270196e5a95b0f0635a4cbaa90834fa 100644 (file)
@@ -858,6 +858,8 @@ static int disk_is_flagged(BMVert *v, int flag)
  * Joins a collected group of faces into one. Only restriction on
  * the input data is that the faces must be connected to each other.
  *
+ * \param do_clear Remove the edges and verts shared by faces when joining.
+ *
  * \return The newly created combine BMFace.
  *
  * \note If a pair of faces share multiple edges,
@@ -866,7 +868,8 @@ static int disk_is_flagged(BMVert *v, int flag)
  * \note this is a generic, flexible join faces function,
  * almost everything uses this, including #BM_faces_join_pair
  */
-BMFace *BM_faces_join(BMesh *bm, BMFace **faces, int totface)
+BMFace *BM_faces_join(BMesh *bm, BMFace **faces, int totface,
+                      const short do_del)
 {
        BMFace *f, *newf;
 #ifdef USE_BMESH_HOLES
@@ -955,7 +958,7 @@ BMFace *BM_faces_join(BMesh *bm, BMFace **faces, int totface)
 
        }
 
-       /* create region fac */
+       /* create region face */
        newf = BM_face_create_ngon(bm, v1, v2, edges, tote, FALSE);
        if (!newf || BMO_error_occurred(bm)) {
                if (!BMO_error_occurred(bm))
@@ -1020,12 +1023,14 @@ BMFace *BM_faces_join(BMesh *bm, BMFace **faces, int totface)
        }
 
        /* delete old geometr */
-       for (i = 0; i < BLI_array_count(deledges); i++) {
-               BM_edge_kill(bm, deledges[i]);
-       }
+       if (do_del) {
+               for (i = 0; i < BLI_array_count(deledges); i++) {
+                       BM_edge_kill(bm, deledges[i]);
+               }
 
-       for (i = 0; i < BLI_array_count(delverts); i++) {
-               BM_vert_kill(bm, delverts[i]);
+               for (i = 0; i < BLI_array_count(delverts); i++) {
+                       BM_vert_kill(bm, delverts[i]);
+               }
        }
        
        BLI_array_free(edges);
@@ -1034,6 +1039,7 @@ BMFace *BM_faces_join(BMesh *bm, BMFace **faces, int totface)
 
        BM_CHECK_ELEMENT(bm, newf);
        return newf;
+
 error:
        bm_elements_systag_disable(bm, faces, totface, _FLAG_JF);
        BLI_array_free(edges);
index 82731c11cf430b906f7487e2b75cb4f313c35efc..eadb588f8591fff1500be4b0aded98f7a98127ce 100644 (file)
@@ -44,7 +44,8 @@ int  BM_edge_splice(BMesh *bm, BMEdge *e, BMEdge *etarget);
 
 int  bmesh_loop_reverse(BMesh *bm, BMFace *f);
 
-BMFace *BM_faces_join(BMesh *bm, BMFace **faces, int totface);
+BMFace *BM_faces_join(BMesh *bm, BMFace **faces, int totface,
+                      const short do_del);
 
 /* EULER API - For modifying structure */
 BMFace *bmesh_sfme(BMesh *bm, BMFace *f, BMVert *v1,
index 462b0cc23697bccd45d4b29e8800424a75eabb85..1347e657a9983020b3a3d255d19db8fb72fd9cff 100644 (file)
@@ -147,7 +147,7 @@ int BM_disk_dissolve(BMesh *bm, BMVert *v)
                f = e->l->f;
                f2 = e->l->radial_next->f;
 
-               if (f != f2 && !BM_faces_join_pair(bm, f, f2, e)) {
+               if (f != f2 && !BM_faces_join_pair(bm, f, f2, e, TRUE)) {
                        return FALSE;
                }
 
@@ -164,7 +164,7 @@ int BM_disk_dissolve(BMesh *bm, BMVert *v)
                                f = NULL;
                                len = bmesh_radial_length(e->l);
                                if (len == 2 && (e != baseedge) && (e != keepedge)) {
-                                       f = BM_faces_join_pair(bm, e->l->f, e->l->radial_next->f, e);
+                                       f = BM_faces_join_pair(bm, e->l->f, e->l->radial_next->f, e, TRUE);
                                        /* return if couldn't join faces in manifold
                                         * conditions */
                                        //!disabled for testing why bad things happen
@@ -194,7 +194,7 @@ int BM_disk_dissolve(BMesh *bm, BMVert *v)
 
                if (f != f2) {
                        /* join two remaining face */
-                       if (!BM_faces_join_pair(bm, f, f2, e)) {
+                       if (!BM_faces_join_pair(bm, f, f2, e, TRUE)) {
                                return FALSE;
                        }
                }
@@ -219,7 +219,8 @@ int BM_disk_dissolve(BMesh *bm, BMVert *v)
  * \return pointer to the combined face
  */
 
-BMFace *BM_faces_join_pair(BMesh *bm, BMFace *f1, BMFace *f2, BMEdge *e)
+BMFace *BM_faces_join_pair(BMesh *bm, BMFace *f1, BMFace *f2, BMEdge *e,
+                           const short do_del)
 {
        BMLoop *l1, *l2;
        BMEdge *jed = NULL;
@@ -255,7 +256,7 @@ BMFace *BM_faces_join_pair(BMesh *bm, BMFace *f1, BMFace *f2, BMEdge *e)
                bmesh_loop_reverse(bm, f2);
        }
 
-       f1 = BM_faces_join(bm, faces, 2);
+       f1 = BM_faces_join(bm, faces, 2, do_del);
        
        return f1;
 }
@@ -448,7 +449,7 @@ BMEdge *BM_vert_collapse_faces(BMesh *bm, BMEdge *ke, BMVert *kv, float fac,
                }
 
                if (BLI_array_count(faces) >= 2) {
-                       BMFace *f2 = BM_faces_join(bm, faces, BLI_array_count(faces));
+                       BMFace *f2 = BM_faces_join(bm, faces, BLI_array_count(faces), TRUE);
                        if (f2) {
                                BMLoop *nl = NULL;
                                if (BM_face_split(bm, f2, tv, tv2, &nl, NULL)) {
@@ -961,8 +962,11 @@ BMEdge *BM_edge_rotate(BMesh *bm, BMEdge *e, const short ccw, const short check_
 
 
 
-       /* rotate the edge */
-       f = BM_faces_join_pair(bm, l1->f, l2->f, e);
+       /* --------------- */
+       /* Rotate The Edge */
+
+       /* don't delete the edge, manually remove the egde after so we can copy its attributes */
+       f = BM_faces_join_pair(bm, l1->f, l2->f, e, FALSE);
 
        if (f == NULL) {
                return NULL;
@@ -972,9 +976,12 @@ BMEdge *BM_edge_rotate(BMesh *bm, BMEdge *e, const short ccw, const short check_
         * the #BM_edge_rotate_check will ensure this, but its possibly corrupt state or future edits
         * break this */
 
-       if (!BM_face_split(bm, f, v1, v2, &nl, NULL))
+       if (!BM_face_split(bm, f, v1, v2, &nl, e))
                return NULL;
 
+       /* edge has done its job as an example, now remove */
+       BM_edge_kill(bm, e);
+
        /* replace existing edge (kill e_splice) */
        if (e_splice) {
                BM_edge_splice(bm, e_splice, nl->e);
index f3344f2d687e2bc3928d4a39f6ea66b9a1a06ca6..32faa0333bf7a1a87a92fae6c2947c5daa0c1f52 100644 (file)
@@ -33,7 +33,8 @@ int BM_vert_dissolve(BMesh *bm, BMVert *v);
 
 int BM_disk_dissolve(BMesh *bm, BMVert *v);
 
-BMFace *BM_faces_join_pair(BMesh *bm, BMFace *f1, BMFace *f2, BMEdge *e);
+BMFace *BM_faces_join_pair(BMesh *bm, BMFace *f1, BMFace *f2, BMEdge *e,
+                           const short do_del);
 
 BMEdge *BM_verts_connect(BMesh *bm, BMVert *v1, BMVert *v2, BMFace **r_f);
 
index 9e07cb177ddbe3205174e6492fe45e6a6d80a1ad..25eaab1740dfdb08b97a4ee6cffa762e6146a94a 100644 (file)
@@ -144,7 +144,7 @@ void bmo_dissolve_faces_exec(BMesh *bm, BMOperator *op)
                while (faces[tot])
                        tot++;
                
-               f = BM_faces_join(bm, faces, tot);
+               f = BM_faces_join(bm, faces, tot, TRUE);
                if (!f) {
                        BMO_error_raise(bm, op, BMERR_DISSOLVEFACES_FAILED,
                                        "Could not create merged face");
@@ -198,17 +198,16 @@ void bmo_dissolve_edgeloop_exec(BMesh *bm, BMOperator *op)
        BMVert *v, **verts = NULL;
        BLI_array_declare(verts);
        BMEdge *e;
-       /* BMFace *f; */
+       BMFace *fa, *fb;
        int i;
 
+
        BMO_ITER(e, &oiter, bm, op, "edges", BM_EDGE) {
-               if (BM_edge_face_count(e) == 2) {
+               if (BM_edge_face_pair(e, &fa, &fb)) {
                        BMO_elem_flag_enable(bm, e->v1, VERT_MARK);
                        BMO_elem_flag_enable(bm, e->v2, VERT_MARK);
 
-                       BM_faces_join_pair(bm, e->l->f,
-                                          e->l->radial_next->f,
-                                          e);
+                       BM_faces_join_pair(bm, fa, fb, e, TRUE);
                }
        }
 
@@ -256,13 +255,12 @@ void bmo_dissolve_edges_exec(BMesh *bm, BMOperator *op)
        }
 
        BMO_ITER(e, &eiter, bm, op, "edges", BM_EDGE) {
-               const int edge_face_count = BM_edge_face_count(e);
-               if (edge_face_count == 2) {
+               BMFace *fa, *fb;
+
+               if (BM_edge_face_pair(e, &fa, &fb)) {
 
                        /* join faces */
-                       BM_faces_join_pair(bm, e->l->f,
-                                          e->l->radial_next->f,
-                                          e);
+                       BM_faces_join_pair(bm, fa, fb, e, TRUE);
                }
        }
 
@@ -517,7 +515,7 @@ void bmo_dissolve_limit_exec(BMesh *bm, BMOperator *op)
                        if (BM_edge_face_angle(bm, e) < angle_limit) {
                                BMFace *nf = BM_faces_join_pair(bm, e->l->f,
                                                                e->l->radial_next->f,
-                                                               e); /* join faces */
+                                                               e, TRUE); /* join faces */
 
                                /* there may be some errors, we dont mind, just move on */
                                if (nf == NULL) {
index 76e64aee8214ea2995d66e90b521f499a6cd6470..433b91c198e145468649c09c3a08143ff3bcdd20 100644 (file)
@@ -251,14 +251,11 @@ void bmo_join_triangles_exec(BMesh *bm, BMOperator *op)
                if (!BMO_elem_flag_test(bm, e, EDGE_MARK))
                        continue;
 
-               if (BM_edge_face_count(e) != 2) {
+               if (!BM_edge_face_pair(e, &f1, &f2)) {
                        BMO_elem_flag_disable(bm, e, EDGE_MARK);
                        continue;
                }
 
-               f1 = e->l->f;
-               f2 = e->l->radial_next->f;
-
                if (f1->len != 3 || f2->len != 3) {
                        BMO_elem_flag_disable(bm, e, EDGE_MARK);
                        continue;
@@ -332,10 +329,9 @@ void bmo_join_triangles_exec(BMesh *bm, BMOperator *op)
                if (!BMO_elem_flag_test(bm, e, EDGE_CHOSEN))
                        continue;
 
-               f1 = e->l->f;
-               f2 = e->l->radial_next->f;
 
-               BM_faces_join_pair(bm, f1, f2, e);
+               BM_edge_face_pair(e, &f1, &f2); /* checked above */
+               BM_faces_join_pair(bm, f1, f2, e, TRUE);
        }
 
        BM_ITER(e, &iter, bm, BM_EDGES_OF_MESH, NULL) {
@@ -367,7 +363,7 @@ void bmo_join_triangles_exec(BMesh *bm, BMOperator *op)
                                continue;
                        }
 
-                       BM_faces_join_pair(bm, f1, f2, e);
+                       BM_faces_join_pair(bm, f1, f2, e, TRUE);
                }
        }
 
index 04cee14bf213fd51146f5caa78f73bd0e709b065..3c2d4e45342ed2c85a55138c6f1f10e1eab824ac 100644 (file)
@@ -965,7 +965,7 @@ static BMesh *BME_bevel_mesh(BMesh *bm, float value, int UNUSED(res), int option
        /* get rid of beveled edge */
        BM_ITER(e, &iter, bm, BM_EDGES_OF_MESH, NULL) {
                if(BMO_elem_flag_test(bm, e, BME_BEVEL_BEVEL) && BMO_elem_flag_test(bm, e, BME_BEVEL_ORIG)) {
-                       BM_faces_join_pair(bm, e->l->f, e->l->radial_next->f, e);
+                       BM_faces_join_pair(bm, e->l->f, e->l->radial_next->f, e, TRUE);
                }
        }
 
index 872ab5282760039c06cadcbf0a7beafac1d65ca1..c1bd0db5a8fd0a757a65e0a86370b7a3d78e6a03 100644 (file)
@@ -1671,7 +1671,7 @@ static void remerge_faces(knifetool_opdata *kcd)
                if (BLI_array_count(faces) > 0) {
                        idx = BM_elem_index_get(faces[0]);
                        
-                       f2 = BM_faces_join(bm, faces, BLI_array_count(faces));
+                       f2 = BM_faces_join(bm, faces, BLI_array_count(faces), TRUE);
                        if (f2) {
                                BMO_elem_flag_enable(bm, f2, FACE_NEW);
                                BM_elem_index_set(f2, idx); /* set_dirty! */ /* BMESH_TODO, check if this is valid or not */
index 83c75d775c15789dd7a81c754c50de6d00d66f16..351812cda1968f9087cf177dcb2755f88e4bb208 100644 (file)
@@ -406,7 +406,7 @@ static PyObject *bpy_bm_utils_face_join(PyObject *UNUSED(self), PyObject *value)
 
        /* Go ahead and join the face!
         * --------------------------- */
-       f_new = BM_faces_join(bm, face_array, (int)face_seq_len);
+       f_new = BM_faces_join(bm, face_array, (int)face_seq_len, TRUE); /* BMESH_TODO, make optional */
 
        if (f_new) {
                return BPy_BMFace_CreatePyObject(bm, f_new);