Fix T60099: Inconsistent normals from spin tool
authorCampbell Barton <ideasman42@gmail.com>
Fri, 4 Jan 2019 05:23:04 +0000 (16:23 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 4 Jan 2019 06:07:19 +0000 (17:07 +1100)
source/blender/bmesh/intern/bmesh_opdefines.c
source/blender/bmesh/operators/bmo_dupe.c
source/blender/bmesh/operators/bmo_extrude.c

index 7abf050..bbd3808 100644 (file)
@@ -1040,6 +1040,7 @@ static BMOpDefine bmo_extrude_face_region_def = {
         {"edges_exclude", BMO_OP_SLOT_MAPPING, {(int)BMO_OP_SLOT_SUBTYPE_MAP_EMPTY}},
         {"use_keep_orig", BMO_OP_SLOT_BOOL},   /* keep original geometry (requires ``geom`` to include edges). */
         {"use_normal_flip", BMO_OP_SLOT_BOOL},  /* Create faces with reversed direction. */
+        {"use_normal_from_adjacent", BMO_OP_SLOT_BOOL},  /* Use winding from surrounding faces instead of this region. */
         {"use_select_history", BMO_OP_SLOT_BOOL},  /* pass to duplicate */
         {{'\0'}},
        },
index 7f13731..9dd4ede 100644 (file)
@@ -525,8 +525,9 @@ void bmo_spin_exec(BMesh *bm, BMOperator *op)
                        BMO_op_finish(bm, &dupop);
                }
                else {
-                       BMO_op_initf(bm, &extop, op->flag, "extrude_face_region geom=%S use_normal_flip=%b",
-                                    op, "geom_last.out", use_normal_flip && (a == 0));
+                       BMO_op_initf(bm, &extop, op->flag,
+                                    "extrude_face_region geom=%S use_normal_flip=%b use_normal_from_adjacent=%b",
+                                    op, "geom_last.out", use_normal_flip && (a == 0), (a != 0));
                        BMO_op_exec(bm, &extop);
                        if ((use_merge && (a == steps - 1)) == false) {
                                BMO_op_callf(bm, op->flag,
index 8c16247..a13024d 100644 (file)
@@ -339,6 +339,7 @@ void bmo_extrude_face_region_exec(BMesh *bm, BMOperator *op)
        BMOpSlot *slot_facemap_out;
        BMOpSlot *slot_edges_exclude;
        const bool use_normal_flip = BMO_slot_bool_get(op->slots_in, "use_normal_flip");
+       const bool use_normal_from_adjacent = BMO_slot_bool_get(op->slots_in, "use_normal_from_adjacent");
 
        /* initialize our sub-operators */
        BMO_op_initf(
@@ -489,13 +490,22 @@ void bmo_extrude_face_region_exec(BMesh *bm, BMOperator *op)
                        continue;
                }
 
-               /* orient loop to give same normal as a loop of newedge
-                * if it exists (will be an extruded face),
-                * else same normal as a loop of e, if it exists */
-               const bool edge_normal_flip = !(
-                       e_new->l ?
-                       (e_new->l->v == e_new->v1) :
-                       (!e->l || !(e->l->v == e->v1)));
+               bool edge_normal_flip;
+               if (use_normal_from_adjacent == false) {
+                       /* Orient loop to give same normal as a loop of 'e_new'
+                        * if it exists (will be one of the faces from the region),
+                        * else same normal as a loop of e, if it exists. */
+                       edge_normal_flip = !(
+                               e_new->l ?
+                               (e_new->l->v == e_new->v1) :
+                               (!e->l || !(e->l->v == e->v1)));
+               }
+               else {
+                       /* Special case, needed for repetitive extrusions
+                        * that use the normals from the previously created faces. */
+                       edge_normal_flip = !(e->l && e->v1 != e->l->v);
+               }
+
                if (edge_normal_flip == use_normal_flip) {
                        f_verts[0] = e->v1;
                        f_verts[1] = e->v2;