Commit: 0c6410ec0cffdcb0641fa85d8394f7c682c44143
Author: Rohan Rathi
Date:   Mon Jun 11 11:58:26 2018 +0530
Branches: soc-2018-bevel
https://developer.blender.org/rB0c6410ec0cffdcb0641fa85d8394f7c682c44143

Added ability to harden normals.

Uses 2 different params: mode and strength. There are still some
hiccups with how 2.8 interacts with normals. Will resolve as
support gets better

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

M       source/blender/bmesh/intern/bmesh_mesh.c
M       source/blender/bmesh/intern/bmesh_mesh.h
M       source/blender/bmesh/intern/bmesh_opdefines.c
M       source/blender/bmesh/intern/bmesh_operators.h
M       source/blender/bmesh/operators/bmo_bevel.c
M       source/blender/bmesh/tools/bmesh_bevel.c
M       source/blender/bmesh/tools/bmesh_bevel.h
M       source/blender/editors/mesh/editmesh_bevel.c
M       source/blender/editors/mesh/editmesh_tools.c
M       source/blender/makesdna/DNA_modifier_types.h
M       source/blender/makesrna/intern/rna_modifier.c
M       source/blender/modifiers/intern/MOD_bevel.c

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

diff --git a/source/blender/bmesh/intern/bmesh_mesh.c 
b/source/blender/bmesh/intern/bmesh_mesh.c
index 79c835cca11..3a4aec8cc69 100644
--- a/source/blender/bmesh/intern/bmesh_mesh.c
+++ b/source/blender/bmesh/intern/bmesh_mesh.c
@@ -1225,6 +1225,41 @@ void BM_lnorspace_update(BMesh *bm)
        }
 }
 
+void BM_normals_loops_edges_tag(BMesh *bm, const bool do_edges)
+{
+       BMFace *f;
+       BMEdge *e;
+       BMIter fiter, eiter;
+       BMLoop *l_curr, *l_first;
+
+       if (do_edges) {
+               int index_edge;
+               BM_ITER_MESH_INDEX(e, &eiter, bm, BM_EDGES_OF_MESH, index_edge) 
{
+                       BMLoop *l_a, *l_b;
+
+                       BM_elem_index_set(e, index_edge);  /* set_inline */
+                       BM_elem_flag_disable(e, BM_ELEM_TAG);
+                       if (BM_edge_loop_pair(e, &l_a, &l_b)) {
+                               if (BM_elem_flag_test(e, BM_ELEM_SMOOTH) && 
l_a->v != l_b->v) {
+                                       BM_elem_flag_enable(e, BM_ELEM_TAG);
+                               }
+                       }
+               }
+               bm->elem_index_dirty &= ~BM_EDGE;
+       }
+
+       int index_face, index_loop = 0;
+       BM_ITER_MESH_INDEX(f, &fiter, bm, BM_FACES_OF_MESH, index_face) {
+               BM_elem_index_set(f, index_face);  /* set_inline */
+               l_curr = l_first = BM_FACE_FIRST_LOOP(f);
+               do {
+                       BM_elem_index_set(l_curr, index_loop++);  /* set_inline 
*/
+                       BM_elem_flag_disable(l_curr, BM_ELEM_TAG);
+               } while ((l_curr = l_curr->next) != l_first);
+       }
+       bm->elem_index_dirty &= ~(BM_FACE | BM_LOOP);
+}
+
 /**
 * Auxillary function only used by rebuild to detect if any spaces were not 
marked as invalid.
 * Reports error if any of the lnor spaces change after rebuilding, meaning 
that all the possible
diff --git a/source/blender/bmesh/intern/bmesh_mesh.h 
b/source/blender/bmesh/intern/bmesh_mesh.h
index 44887e81157..43029e370c6 100644
--- a/source/blender/bmesh/intern/bmesh_mesh.h
+++ b/source/blender/bmesh/intern/bmesh_mesh.h
@@ -59,6 +59,7 @@ void BM_lnorspacearr_store(BMesh *bm, float(*r_lnors)[3]);
 void BM_lnorspace_invalidate(BMesh *bm, const bool do_invalidate_all);
 void BM_lnorspace_rebuild(BMesh *bm, bool preserve_clnor);
 void BM_lnorspace_update(BMesh *bm);
+void BM_normals_loops_edges_tag(BMesh *bm, const bool do_edges);
 #ifndef NDEBUG
 void BM_lnorspace_err(BMesh *bm);
 #endif
diff --git a/source/blender/bmesh/intern/bmesh_opdefines.c 
b/source/blender/bmesh/intern/bmesh_opdefines.c
index e6a66372274..49d160f5d4a 100644
--- a/source/blender/bmesh/intern/bmesh_opdefines.c
+++ b/source/blender/bmesh/intern/bmesh_opdefines.c
@@ -1738,12 +1738,15 @@ static BMOpDefine bmo_bevel_def = {
         {"loop_slide", BMO_OP_SLOT_BOOL},      /* prefer to slide along edges 
to having even widths */
         {"mark_seam", BMO_OP_SLOT_BOOL},
         {"mark_sharp", BMO_OP_SLOT_BOOL},
+        {"strength", BMO_OP_SLOT_FLT},
+        {"hnmode", BMO_OP_SLOT_INT},
         {{'\0'}},
        },
        /* 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 */
+        {"normals.out", BMO_OP_SLOT_MAPPING},
         {{'\0'}},
        },
 
diff --git a/source/blender/bmesh/intern/bmesh_operators.h 
b/source/blender/bmesh/intern/bmesh_operators.h
index 80b57eb3565..3ae9a77a761 100644
--- a/source/blender/bmesh/intern/bmesh_operators.h
+++ b/source/blender/bmesh/intern/bmesh_operators.h
@@ -127,6 +127,11 @@ enum {
        BEVEL_AMT_PERCENT
 };
 
+enum {
+       BEVEL_HN_FACE,
+       BEVEL_HN_ADJ,
+};
+
 extern const BMOpDefine *bmo_opdefines[];
 extern const int         bmo_opdefines_total;
 
diff --git a/source/blender/bmesh/operators/bmo_bevel.c 
b/source/blender/bmesh/operators/bmo_bevel.c
index cf063f7b0a8..cd27b486929 100644
--- a/source/blender/bmesh/operators/bmo_bevel.c
+++ b/source/blender/bmesh/operators/bmo_bevel.c
@@ -45,6 +45,7 @@ void bmo_bevel_exec(BMesh *bm, BMOperator *op)
        const bool  loop_slide    = BMO_slot_bool_get(op->slots_in,  
"loop_slide");
        const bool      mark_seam         = BMO_slot_bool_get(op->slots_in, 
"mark_seam");
        const bool      mark_sharp        = BMO_slot_bool_get(op->slots_in, 
"mark_sharp");
+       const int hnmode                  = BMO_slot_int_get(op->slots_in, 
"hnmode");
 
        if (offset > 0) {
                BMOIter siter;
@@ -65,7 +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, mark_seam, mark_sharp);
+               BM_mesh_bevel(bm, offset, offset_type, seg, profile, vonly, 
false, clamp_overlap, NULL, -1, material, loop_slide, mark_seam, mark_sharp, 
0/*hnmode*/, op);
 
                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);
diff --git a/source/blender/bmesh/tools/bmesh_bevel.c 
b/source/blender/bmesh/tools/bmesh_bevel.c
index 8a2a022852d..18039261735 100644
--- a/source/blender/bmesh/tools/bmesh_bevel.c
+++ b/source/blender/bmesh/tools/bmesh_bevel.c
@@ -37,6 +37,7 @@
 
 #include "BLI_array.h"
 #include "BLI_alloca.h"
+#include "BLI_bitmap.h"
 #include "BLI_gsqueue.h"
 #include "BLI_math.h"
 #include "BLI_memarena.h"
@@ -207,6 +208,7 @@ typedef struct BevelParams {
        const struct MDeformVert *dvert; /* vertex group array, maybe set if 
vertex_only */
        int vertex_group;       /* vertex group index, maybe set if vertex_only 
*/
        int mat_nr;             /* if >= 0, material number for bevel; else 
material comes from adjacent faces */
+       int hnmode;
 } BevelParams;
 
 // #pragma GCC diagnostic ignored "-Wpadded"
@@ -1648,6 +1650,76 @@ static void bevel_extend_edge_data(BevVert *bv)
        } while (bcur != start);
 }
 
+static void bevel_harden_normals_mode(BMesh *bm, BevelParams *bp, BevVert *bv, 
BMOperator *op)
+{
+       int mode = 1;
+
+       VMesh *vm = bv->vmesh;
+       BoundVert *bcur = vm->boundstart, *bstart = bcur;
+       int ns = vm->seg, ns2 = ns / 2;
+
+       BMEdge *e;
+       BMIter eiter;
+
+       BMOpSlot *nslot = BMO_slot_get(op->slots_out, "normals.out");
+       float n_final[3] = { 0.0f, 0.0f, 0.0f };
+
+       if (bp->hnmode == BEVEL_HN_FACE) {
+               BLI_bitmap *faces = BLI_BITMAP_NEW(bm->totface, __func__);
+               BM_ITER_ELEM(e, &eiter, bv->v, BM_EDGES_OF_VERT) {
+                       if (BM_elem_flag_test(e, BM_ELEM_TAG)) {
+
+                               BMFace *f_a, *f_b;
+                               BM_edge_face_pair(e, &f_a, &f_b);
+
+                               if (f_a && !BLI_BITMAP_TEST(faces, 
BM_elem_index_get(f_a))) {
+                                       int f_area = BM_face_calc_area(f_a);
+                                       float f_no[3];
+                                       copy_v3_v3(f_no, f_a->no);
+                                       mul_v3_fl(f_no, f_area);
+                                       add_v3_v3(n_final, f_no);
+                                       BLI_BITMAP_ENABLE(faces, 
BM_elem_index_get(f_a));
+                               }
+                               if (f_b && !BLI_BITMAP_TEST(faces, 
BM_elem_index_get(f_b))) {
+                                       int f_area = BM_face_calc_area(f_b);
+                                       float f_no[3];
+                                       copy_v3_v3(f_no, f_b->no);
+                                       mul_v3_fl(f_no, f_area);
+                                       add_v3_v3(n_final, f_no);
+                                       BLI_BITMAP_ENABLE(faces, 
BM_elem_index_get(f_b));
+                               }
+                       }
+               }
+               MEM_freeN(faces);
+               normalize_v3(n_final);
+       }
+       else if (bp->hnmode == BEVEL_HN_ADJ) {
+               BM_ITER_ELEM(e, &eiter, bv->v, BM_EDGES_OF_VERT) {
+                       if (BM_elem_flag_test(e, BM_ELEM_TAG)) {
+                               if (e->v1 == bv->v) {
+                                       add_v3_v3(n_final, e->v2->no);
+                               }
+                               else {
+                                       add_v3_v3(n_final, e->v1->no);
+                               }
+                       }
+               }
+               normalize_v3(n_final);
+       }
+
+       do {
+               if (BMO_slot_map_contains(nslot, bcur->nv.v) != true) {
+
+                       float(*custom_normal) = 
MEM_callocN(sizeof(*custom_normal) * 3, __func__);
+                       add_v3_v3(custom_normal, n_final);
+                       normalize_v3(custom_normal);
+
+                       BMO_slot_map_insert(op, nslot, bcur->nv.v, 
custom_normal);
+               }
+               bcur = bcur->next;
+       } while (bcur != bstart);
+}
+
 /* Set the any_seam property for a BevVert and all its BoundVerts */
 static void set_bound_vert_seams(BevVert *bv, bool mark_seam, bool mark_sharp)
 {
@@ -5482,7 +5554,8 @@ void BM_mesh_bevel(
         const float segments, const float profile,
         const bool vertex_only, const bool use_weights, const bool 
limit_offset,
         const struct MDeformVert *dvert, const int vertex_group, const int mat,
-        const bool loop_slide, const bool mark_seam, const bool mark_sharp)
+        const bool loop_slide, const bool mark_seam, const bool mark_sharp,
+               const int hnmode, BMOperator *op)
 {
        BMIter iter;
        BMVert *v, *v_next;
@@ -5505,6 +5578,7 @@ void BM_mesh_bevel(
        bp.mat_nr = mat;
        bp.mark_seam = mark_seam;
        bp.mark_sharp = mark_sharp;
+       bp.hnmode = hnmode;
 
        if (profile >= 0.999f) {  /* r ~ 692, so PRO_SQUARE_R is 1e4 */
                bp.pro_super_r = PRO_SQUARE_R;
@@ -5561,6 +5635,13 @@ void BM_mesh_bevel(
                        }
                }
 
+               GHASH_ITER(giter, bp.vert_hash) {
+                       bv = BLI_ghashIterator_getValue(&giter);
+                       bevel_extend_edge_data(bv);
+                       if(bm->use_toolflags)
+                               bevel_harden_normals_mode(bm, &bp, bv, op);
+               }
+
                /* Rebuild face polygons around affected vertices */
                BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
                        if (BM_elem_flag_test(v, BM_ELEM_TAG)) {
@@ -5571,9 +5652,7 @@ void BM_mesh_bevel(
 
                BM_ITER_MESH_MUTABLE (v, v_next, &iter, bm, BM_VERTS_OF_MESH) {
                        if (BM_elem_flag_test(v, BM_ELEM_TAG)) {
-                               BevVert *bv = find_bevvert(&bp, v);
-                               BLI_assert(bv != NULL);
-                               bevel_extend_edge_data(bv);
+                               BLI_assert(find_bevvert(&bp, v) != NULL);
                                BM_vert_kill(bm, v);
                        }
                }
diff --git a/source/blender/bmesh/tools/bmesh_bevel.h 
b/source/blender/bmesh/tools/bmesh_bevel.h
index d932ac381a6..f43289aac27 100644
--- a/source/blender/bmesh/tools/bmesh_bevel.h
+++ b/source/blender/bmesh/tools/bmesh_bevel.h
@@ -33,6 +33,7 @@ void BM_mesh_bevel(
         BMesh *bm, const float offset, const int offset_type, const float 
segments,
         const float profile, const bool vertex_only, const bool use_weights,
         const bool limit_offset, const struct MDeformVert *dvert, const int 
vertex_group,
-        const int mat, const bool loop_slide, const bool mark_seam, const bool 
mark_sharp);
+        const int mat, const bool loop_slide, const bool mark_seam, const bool 
mark_sharp,
+               const int hnmode, BMOperator *op);
 
 #endif /* __BMESH_BEVEL_H__ */
diff --git a/source/blender/editors/mesh/editmesh_bevel.c 
b/source/blender/editors/mesh/editmesh_bevel.c
index 86aff48615c..859b0942e55 100644
--- a/source/blender/editors/mesh/editmesh_bevel.c
+++ b/source/blender/editors/mesh/editmesh_bevel.c
@@ -30,6 +30,7 @@
 
 #include "BLI_string.h"
 #include "BLI_math.h"
+#include "BLI_linklist_stack.h"
 
 #include "BLT_translation

@@ Diff output truncated at 10240 characters. @@

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

Reply via email to