Commit: ed84388e7d46214bbc5c4f8a28420f56e44cfa4d
Author: Howard Trickey
Date:   Wed Jun 7 08:53:10 2017 -0400
Branches: master
https://developer.blender.org/rBed84388e7d46214bbc5c4f8a28420f56e44cfa4d

Bevel Op (internal and API) now returns new edges and verts as well as
faces.

This was requested by script writers. Especially needed if beveling
wire edges with vertex_only.
Should be backward compatible as just adds two new keys to returned
dict in python ('edges' and 'verts').

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

M       source/blender/bmesh/intern/bmesh_opdefines.c
M       source/blender/bmesh/operators/bmo_bevel.c
M       source/blender/bmesh/tools/bmesh_bevel.c

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

diff --git a/source/blender/bmesh/intern/bmesh_opdefines.c 
b/source/blender/bmesh/intern/bmesh_opdefines.c
index d2f0fc1721c..200a31b1a57 100644
--- a/source/blender/bmesh/intern/bmesh_opdefines.c
+++ b/source/blender/bmesh/intern/bmesh_opdefines.c
@@ -1741,6 +1741,8 @@ static BMOpDefine bmo_bevel_def = {
        },
        /* slots_out */
        {{"faces.out", BMO_OP_SLOT_ELEMENT_BUF, {BM_FACE}}, /* output faces */
+        {"edges.out", BMO_OP_SLOT_ELEMENT_BUF, {BM_EDGE}}, /* output edges */
+        {"verts.out", BMO_OP_SLOT_ELEMENT_BUF, {BM_VERT}}, /* output verts */
         {{'\0'}},
        },
 
diff --git a/source/blender/bmesh/operators/bmo_bevel.c 
b/source/blender/bmesh/operators/bmo_bevel.c
index d5afb39d7b7..2ae87b64286 100644
--- a/source/blender/bmesh/operators/bmo_bevel.c
+++ b/source/blender/bmesh/operators/bmo_bevel.c
@@ -66,5 +66,7 @@ void bmo_bevel_exec(BMesh *bm, BMOperator *op)
                BM_mesh_bevel(bm, offset, offset_type, seg, profile, vonly, 
false, clamp_overlap, NULL, -1, material, loop_slide);
 
                BMO_slot_buffer_from_enabled_hflag(bm, op, op->slots_out, 
"faces.out", BM_FACE, BM_ELEM_TAG);
+               BMO_slot_buffer_from_enabled_hflag(bm, op, op->slots_out, 
"edges.out", BM_EDGE, BM_ELEM_TAG);
+               BMO_slot_buffer_from_enabled_hflag(bm, op, op->slots_out, 
"verts.out", BM_VERT, BM_ELEM_TAG);
        }
 }
diff --git a/source/blender/bmesh/tools/bmesh_bevel.c 
b/source/blender/bmesh/tools/bmesh_bevel.c
index 74841dc2756..6673c5d25cf 100644
--- a/source/blender/bmesh/tools/bmesh_bevel.c
+++ b/source/blender/bmesh/tools/bmesh_bevel.c
@@ -205,6 +205,29 @@ static int bev_debug_flags = 0;
 #define DEBUG_OLD_PROJ_TO_PERP_PLANE (bev_debug_flags & 2)
 #define DEBUG_OLD_FLAT_MID (bev_debug_flags & 4)
 
+/* this flag values will get set on geom we want to return in 'out' slots for 
edges and verts */
+#define EDGE_OUT 4
+#define VERT_OUT 8
+
+/* If we're called from the modifier, tool flags aren't available, but don't 
need output geometry */
+static void flag_out_edge(BMesh *bm, BMEdge *bme)
+{
+       if (bm->use_toolflags)
+               BMO_edge_flag_enable(bm, bme, EDGE_OUT);
+}
+
+static void flag_out_vert(BMesh *bm, BMVert *bmv)
+{
+       if (bm->use_toolflags)
+               BMO_vert_flag_enable(bm, bmv, VERT_OUT);
+}
+
+static void disable_flag_out_edge(BMesh *bm, BMEdge *bme)
+{
+       if (bm->use_toolflags)
+               BMO_edge_flag_disable(bm, bme, EDGE_OUT);
+}
+
 /* Are d1 and d2 parallel or nearly so? */
 static bool nearly_parallel(const float d1[3], const float d2[3])
 {
@@ -262,6 +285,7 @@ static void create_mesh_bmvert(BMesh *bm, VMesh *vm, int i, 
int j, int k, BMVert
        NewVert *nv = mesh_vert(vm, i, j, k);
        nv->v = BM_vert_create(bm, nv->co, eg, BM_CREATE_NOP);
        BM_elem_flag_disable(nv->v, BM_ELEM_TAG);
+       flag_out_vert(bm, nv->v);
 }
 
 static void copy_mesh_vert(
@@ -504,9 +528,12 @@ static BMFace *bev_create_ngon(
        }
 
        /* not essential for bevels own internal logic,
-        * this is done so the operator can select newly created faces */
+        * this is done so the operator can select newly created geometry */
        if (f) {
                BM_elem_flag_enable(f, BM_ELEM_TAG);
+               BM_ITER_ELEM(bme, &iter, f, BM_EDGES_OF_FACE) {
+                       flag_out_edge(bm, bme);
+               }
        }
 
        if (mat_nr >= 0)
@@ -3213,6 +3240,7 @@ static void bevel_build_trifan(BevelParams *bp, BMesh 
*bm, BevVert *bv)
                        BMFace *f_new;
                        BLI_assert(v_fan == l_fan->v);
                        f_new = BM_face_split(bm, f, l_fan, l_fan->next->next, 
&l_new, NULL, false);
+                       flag_out_edge(bm, l_new->e);
 
                        if (f_new->len > f->len) {
                                f = f_new;
@@ -3259,6 +3287,7 @@ static void bevel_build_quadstrip(BevelParams *bp, BMesh 
*bm, BevVert *bv)
                        else {
                                BM_face_split(bm, f, l_a, l_b, &l_new, NULL, 
false);
                                f = l_new->f;
+                               flag_out_edge(bm, l_new->e);
 
                                /* walk around the new face to get the next 
verts to split */
                                l_a = l_new->prev;
@@ -3278,7 +3307,7 @@ static void bevel_vert_two_edges(BevelParams *bp, BMesh 
*bm, BevVert *bv)
 {
        VMesh *vm = bv->vmesh;
        BMVert *v1, *v2;
-       BMEdge *e_eg;
+       BMEdge *e_eg, *bme;
        Profile *pro;
        float co[3];
        BoundVert *bndv;
@@ -3320,7 +3349,9 @@ static void bevel_vert_two_edges(BevelParams *bp, BMesh 
*bm, BevVert *bv)
                        v1 = mesh_vert(vm, 0, 0, k)->v;
                        v2 = mesh_vert(vm, 0, 0, k + 1)->v;
                        BLI_assert(v1 != NULL && v2 != NULL);
-                       BM_edge_create(bm, v1, v2, e_eg, BM_CREATE_NO_DOUBLE);
+                       bme = BM_edge_create(bm, v1, v2, e_eg, 
BM_CREATE_NO_DOUBLE);
+                       if (bme)
+                               flag_out_edge(bm, bme);
                }
        }
 }
@@ -3901,7 +3932,7 @@ static BevVert *bevel_vert_construct(BMesh *bm, 
BevelParams *bp, BMVert *v)
 /* Face f has at least one beveled vertex.  Rebuild f */
 static bool bev_rebuild_polygon(BMesh *bm, BevelParams *bp, BMFace *f)
 {
-       BMIter liter;
+       BMIter liter, eiter, fiter;
        BMLoop *l, *lprev;
        BevVert *bv;
        BoundVert *v, *vstart, *vend;
@@ -3909,10 +3940,10 @@ static bool bev_rebuild_polygon(BMesh *bm, BevelParams 
*bp, BMFace *f)
        VMesh *vm;
        int i, k, n;
        bool do_rebuild = false;
-       bool go_ccw, corner3special;
+       bool go_ccw, corner3special, keep;
        BMVert *bmv;
        BMEdge *bme, *bme_new, *bme_prev;
-       BMFace *f_new;
+       BMFace *f_new, *f_other;
        BMVert **vv = NULL;
        BMVert **vv_fix = NULL;
        BMEdge **ee = NULL;
@@ -4050,9 +4081,21 @@ static bool bev_rebuild_polygon(BMesh *bm, BevelParams 
*bp, BMFace *f)
                        }
                }
 
-               /* don't select newly created boundary faces... */
+               /* don't select newly or return created boundary faces... */
                if (f_new) {
                        BM_elem_flag_disable(f_new, BM_ELEM_TAG);
+                       /* Also don't want new edges that aren't part of a new 
bevel face */
+                       BM_ITER_ELEM(bme, &eiter, f_new, BM_EDGES_OF_FACE) {
+                               keep = false;
+                               BM_ITER_ELEM(f_other, &fiter, bme, 
BM_FACES_OF_EDGE) {
+                                       if (BM_elem_flag_test(f_other, 
BM_ELEM_TAG)) {
+                                               keep = true;
+                                               break;
+                                       }
+                               }
+                               if (!keep)
+                                       disable_flag_out_edge(bm, bme);
+                       }
                }
        }
 
@@ -4134,8 +4177,9 @@ static void bevel_reattach_wires(BMesh *bm, BevelParams 
*bp, BMVert *v)
                                }
                        }
                } while ((bndv = bndv->next) != bv->vmesh->boundstart);
-               if (vclosest)
+               if (vclosest) {
                        BM_edge_create(bm, vclosest, votherclosest, e, 
BM_CREATE_NO_DOUBLE);
+               }
        }
 }
 
@@ -4539,9 +4583,9 @@ static float bevel_limit_offset(BMesh *bm, BevelParams 
*bp)
 /**
  * - Currently only bevels BM_ELEM_TAG'd verts and edges.
  *
- * - Newly created faces are BM_ELEM_TAG'd too,
- *   the caller needs to ensure this is cleared before calling
- *   if its going to use this face tag.
+ * - Newly created faces, edges, and verts are BM_ELEM_TAG'd too,
+ *   the caller needs to ensure these are cleared before calling
+ *   if its going to use this tag.
  *
  * - If limit_offset is set, adjusts offset down if necessary
  *   to avoid geometry collisions.
@@ -4633,6 +4677,20 @@ void BM_mesh_bevel(
                        }
                }
 
+               /* When called from operator (as opposed to modifier), 
bm->use_toolflags
+                * will be set, and we to transfer the oflags to BM_ELEM_TAGs */
+               if (bm->use_toolflags) {
+                       BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
+                               if (BMO_vert_flag_test(bm, v, VERT_OUT))
+                                       BM_elem_flag_enable(v, BM_ELEM_TAG);
+                       }
+                       BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
+                               if (BMO_edge_flag_test(bm, e, EDGE_OUT)) {
+                                       BM_elem_flag_enable(e, BM_ELEM_TAG);
+                               }
+                       }
+               }
+
                /* primary free */
                BLI_ghash_free(bp.vert_hash, NULL, NULL);
                BLI_memarena_free(bp.mem_arena);

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

Reply via email to