Commit: 96e76ea4a3e0d988389ed3ba5464696e02028628
Author: Rohan Rathi
Date:   Fri Aug 18 20:44:15 2017 +0530
Branches: soc-2017-normal-tools
https://developer.blender.org/rB96e76ea4a3e0d988389ed3ba5464696e02028628

Made workflow changes to copy, paste. Added add and multiply.

Did a cleanup of point_normals and split. Added ability to spherize in 
point_normals. Added reset. Added normal smoothing based on adjacent vertices. 
Did a cleanup of UI.
The set of normal tools now share the normal vector in UI. The copy/paste 
operator now contains all these methods and has been renamed.

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

M       release/scripts/startup/bl_ui/space_view3d_toolbar.py
M       source/blender/editors/mesh/editmesh_tools.c
M       source/blender/editors/mesh/mesh_intern.h
M       source/blender/editors/mesh/mesh_ops.c
M       source/blender/makesdna/DNA_scene_types.h
M       source/blender/makesrna/intern/rna_scene.c

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

diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py 
b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index 82766ac7ad0..a86585a0ece 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -442,6 +442,7 @@ class VIEW3D_PT_tools_normal(View3DPanel, Panel):
 
        def draw(self, context):
                layout = self.layout
+               toolsettings = context.tool_settings
 
                col = layout.column(align=True)
                col.operator("transform.rotate_normal", text = "Rotate Normal")
@@ -459,10 +460,20 @@ class VIEW3D_PT_tools_normal(View3DPanel, Panel):
                col.operator_menu_enum("mesh.average_loop_normals", 
"average_type")
                
                col = layout.column(align=True)
-               col.label(text="Copy/Paste Normal")
+               col.label(text="Normal Vector: ")
+               col.operator("mesh.custom_normal_tools", text="Reset").mode = 
"Reset"
+               col.prop(toolsettings, "normal_vector", text = '')
+
+               row = col.row(align=True)
+               row.operator("mesh.custom_normal_tools", text="Copy").mode = 
"Copy"
+               row.operator("mesh.custom_normal_tools", text="Paste").mode = 
"Paste"
+
                row = col.row(align=True)
-               row.operator("mesh.copy_normal", text="Copy").copy = True
-               row.operator("mesh.copy_normal", text="Paste").copy = False
+               row.operator("mesh.custom_normal_tools", text = 
"Multiply").mode = "Multiply"
+               row.operator("mesh.custom_normal_tools", text="Add").mode = 
"Add"
+
+               col = layout.column(align=True)
+               col.operator("mesh.smoothen_custom_normals", text="Smoothen")
 
 
 class VIEW3D_PT_tools_uvs(View3DPanel, Panel):
diff --git a/source/blender/editors/mesh/editmesh_tools.c 
b/source/blender/editors/mesh/editmesh_tools.c
index 9868674815c..9ef463db893 100644
--- a/source/blender/editors/mesh/editmesh_tools.c
+++ b/source/blender/editors/mesh/editmesh_tools.c
@@ -6006,16 +6006,39 @@ static void apply_point_normals(bContext *C, wmOperator 
*op, const wmEvent *even
        LoopNormalData *ld = op->customdata;
        TransDataLoopNormal *tld = ld->normal;
 
-       const bool point_away = RNA_boolean_get(op->ptr, "point_away");
+       const bool point_away = RNA_boolean_get(op->ptr, "point_away"), 
spherize = RNA_boolean_get(op->ptr, "spherize");
+       float zero[3] = { 0 };
+
+       PropertyRNA *prop = RNA_struct_find_property(op->ptr, "strength");
+       if (spherize) {
+               RNA_def_property_clear_flag(prop, PROP_HIDDEN);
+       }
+       else {
+               RNA_def_property_flag(prop, PROP_HIDDEN);
+       }
 
        for (int i = 0; i < ld->totloop; i++, tld++) {
-               sub_v3_v3v3(tld->nloc, target, tld->loc);
-               normalize_v3(tld->nloc);
+
+               if (spherize) {
+                       float strength = RNA_float_get(op->ptr, "strength");
+                       float spherized_normal[3] = { 0 };
+
+                       sub_v3_v3v3(spherized_normal, target, tld->loc);
+                       sub_v3_v3(spherized_normal, obedit->loc);
+                       mul_v3_fl(spherized_normal, strength);
+                       mul_v3_fl(tld->nloc, 1.0f - strength);
+                       sub_v3_v3(tld->nloc, spherized_normal);
+               }
+               else {
+                       sub_v3_v3v3(tld->nloc, target, tld->loc);
+                       sub_v3_v3(tld->nloc, obedit->loc);
+               }
 
                if (point_away) {
                        negate_v3(tld->nloc);
                }
-               if (tld->loop_index != -1 && !is_zero_v3(tld->nloc)) {
+               if (tld->loop_index != -1 && !compare_v3v3(tld->nloc, zero, 
1e-4f)) {
+                       normalize_v3(tld->nloc);
                        
BKE_lnor_space_custom_normal_to_data(bm->lnor_spacearr->lspacearr[tld->loop_index],
 tld->nloc, tld->clnors_data);
                }
        }
@@ -6053,16 +6076,13 @@ static int point_normals_mouse(bContext *C, wmOperator 
*op, const wmEvent *event
        BM_ITER_MESH(v, &viter, bm, BM_VERTS_OF_MESH) {
                if (BM_elem_flag_test(v, BM_ELEM_SELECT)) {
                        add_v3_v3(center, v->co);
+                       add_v3_v3(center, obedit->loc);
                        i++;
                }
        }
        mul_v3_fl(center, 1.0f / (float)i);
 
        ED_view3d_win_to_3d_int(v3d, ar, center, event->mval, target);
-       sub_v3_v3(target, obedit->loc);
-
-       PropertyRNA *prop = RNA_struct_find_property(op->ptr, "align");
-       RNA_def_property_clear_flag(prop, PROP_HIDDEN);
 
        const bool align = RNA_boolean_get(op->ptr, "align");
 
@@ -6115,7 +6135,6 @@ static int edbm_point_normals_modal(bContext *C, 
wmOperator *op, const wmEvent *
                if (event->type == LEFTMOUSE) {
                        ED_view3d_cursor3d_update(C, event->mval);
                        copy_v3_v3(target, ED_view3d_cursor3d_get(scene, v3d));
-                       sub_v3_v3(target, obedit->loc);
                        RNA_property_float_set_array(op->ptr, prop, target);
 
                        handled = true;
@@ -6129,6 +6148,7 @@ static int edbm_point_normals_modal(bContext *C, 
wmOperator *op, const wmEvent *
                                return OPERATOR_CANCELLED;
                        }
                        ED_object_editmode_calc_active_center(obedit, false, 
target);
+                       add_v3_v3(target, obedit->loc);
                        RNA_property_float_set_array(op->ptr, prop, target);
                        handled = true;
                }
@@ -6152,6 +6172,7 @@ static int edbm_point_normals_modal(bContext *C, 
wmOperator *op, const wmEvent *
                                        }
                                }
                                mid_v3_v3v3(target, min, max);
+                               add_v3_v3(target, obedit->loc);
                                RNA_property_float_set_array(op->ptr, prop, 
target);
                        }
                        break;
@@ -6162,6 +6183,7 @@ static int edbm_point_normals_modal(bContext *C, 
wmOperator *op, const wmEvent *
                                BM_ITER_MESH(v, &viter, bm, BM_VERTS_OF_MESH) {
                                        if (BM_elem_flag_test(v, 
BM_ELEM_SELECT)) {
                                                add_v3_v3(target, v->co);
+                                               add_v3_v3(target, obedit->loc);
                                                i++;
                                        }
                                }
@@ -6171,14 +6193,15 @@ static int edbm_point_normals_modal(bContext *C, 
wmOperator *op, const wmEvent *
 
                        case V3D_AROUND_CURSOR:
                                copy_v3_v3(target, 
ED_view3d_cursor3d_get(scene, v3d));
-                               sub_v3_v3(target, obedit->loc);
                                RNA_property_float_set_array(op->ptr, prop, 
target);
                                break;
 
                        case V3D_AROUND_ACTIVE:
                                if 
(!ED_object_editmode_calc_active_center(obedit, false, target)) {
+                                       point_normals_free(C, op, false);
                                        return OPERATOR_CANCELLED;
                                }
+                               add_v3_v3(target, obedit->loc);
                                RNA_property_float_set_array(op->ptr, prop, 
target);
                                break;
 
@@ -6226,7 +6249,6 @@ static int edbm_point_normals_modal(bContext *C, 
wmOperator *op, const wmEvent *
                else if (ISKEYBOARD(event->type) && event->type != RIGHTALTKEY) 
{
                        prop = RNA_struct_find_property(op->ptr, "align");
                        RNA_property_boolean_set(op->ptr, prop, false);
-                       RNA_def_property_flag(prop, PROP_HIDDEN);
 
                        point_normals_free(C, op, false);
                        return OPERATOR_CANCELLED;
@@ -6236,7 +6258,6 @@ static int edbm_point_normals_modal(bContext *C, 
wmOperator *op, const wmEvent *
        if (handled || event->type == RIGHTMOUSE) {
                prop = RNA_struct_find_property(op->ptr, "align");
                RNA_property_boolean_set(op->ptr, prop, false);
-               RNA_def_property_flag(prop, PROP_HIDDEN);
        }
 
        if (handled) {
@@ -6294,8 +6315,18 @@ static int edbm_point_normals_exec(bContext *C, 
wmOperator *op)
                LoopNormalData *ld = op->customdata;
                TransDataLoopNormal *t = ld->normal;
                int i = 0;
+               BMVert *v;
+               BMIter viter;
+
+               zero_v3(center);
+               BM_ITER_MESH(v, &viter, bm, BM_VERTS_OF_MESH) {
+                       if (BM_elem_flag_test(v, BM_ELEM_SELECT)) {
+                               add_v3_v3(center, v->co);
+                               i++;
+                       }
+               }
+               mul_v3_fl(center, 1.0f / (float)i);
 
-               copy_v3_v3(center, obedit->loc);
                for (i = 0; i < ld->totloop; i++, t++) {
                        t->loc = center;
                }
@@ -6311,31 +6342,6 @@ static int edbm_point_normals_exec(bContext *C, 
wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-static void edbm_point_normals_ui(bContext *UNUSED(C), wmOperator *op)
-{
-       uiLayout *layout = op->layout, *row, *col;
-       PointerRNA ptr;
-
-       const bool align = RNA_boolean_get(op->ptr, "align");
-
-       RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr);
-
-       uiItemR(layout, &ptr, "point_away", 0, NULL, ICON_NONE);
-
-       uiItemR(layout, &ptr, "align", 0, NULL, ICON_NONE);
-       row = uiLayoutRow(layout, false);
-
-       if (align) {
-               col = uiLayoutColumn(row, false);
-               uiItemR(col, &ptr, "target_location", UI_ITEM_R_EXPAND, "", 
ICON_NONE);
-               uiItemR(row, &ptr, "target_location", 0, "", ICON_NONE);
-       }
-       else {
-               col = uiLayoutColumn(layout, false);
-               uiItemR(col, &ptr, "target_location", UI_ITEM_R_EXPAND, "", 
ICON_NONE);
-       }
-}
-
 void MESH_OT_point_normals(struct wmOperatorType *ot)
 {
        /* identifiers */
@@ -6347,23 +6353,24 @@ void MESH_OT_point_normals(struct wmOperatorType *ot)
        ot->exec = edbm_point_normals_exec;
        ot->invoke = edbm_point_normals_invoke;
        ot->modal = edbm_point_normals_modal;
-       ot->ui = edbm_point_normals_ui;
        ot->poll = ED_operator_editmesh_auto_smooth;
 
        /* flags */
        ot->flag = OPTYPE_BLOCKING | OPTYPE_REGISTER | OPTYPE_UNDO;
 
        ot->prop = RNA_def_boolean(ot->srna, "point_away", false, "Point Away", 
"Point Away from target");
+       
+       ot->prop = RNA_def_boolean(ot->srna, "align", false, "Align", "Align 
normal with mouse location");
 
        PropertyRNA *prop;
 
-       prop = RNA_def_boolean(ot->srna, "align", false, "Align", "Align normal 
with mouse location");
-       RNA_def_property_flag(prop, PROP_HIDDEN);
-
-       prop = RNA_def_property(ot->srna, "target_location", PROP_FLOAT, 
PROP_DIRECTION);
+       prop = RNA_def_property(ot->srna, "target_location", PROP_FLOAT, 
PROP_XYZ);
        RNA_def_property_array(prop, 3);
-       RNA_def_property_flag(prop, PROP_ANIMATABLE);
        RNA_def_property_ui_text(prop, "Target", "Target location where normals 
will point");
+
+       prop = RNA_def_boolean(ot->srna, "spherize", false, "Spherize Normal", 
"Add normal vector of target to custom normal with given proportion");
+
+       prop = RNA_def_float(ot->srna, "strength", 0.1, 0.0f, 1.0f, "Strength", 
"Ratio of spherized normal to original normal", 0.0f, 1.0f);
 }
 
 /********************** Split/Merge Loop Normals **********************/
@@ -6429,19 +6436,17 @@ static bool split_loop(bContext *C, wmOperator *op, 
LoopNormalData *ld)
        BMIter fiter, liter;
 
        TransDataLoopNormal *tld = ld->normal;
-       void **loops;
-
-       loops = MEM_mallocN(sizeof(void *) * bm->totloop, "__func__");          
/* temp loop index table */
+       BMLoop **loop_at_index = MEM_mallocN(sizeof(void *) * bm->totloop, 
"__func__");         /* temp loop index table */
        BM_ITER_MESH(f, &fiter, bm, BM_FACES_OF_MESH) {
                BM_ITER_ELEM(l, &liter, f, BM_LOOPS_OF_FACE) {
-                       loops[BM_elem_index_get(l)] = l;
+                       loop_at_index[BM_elem_index_get(l)] = l;
                }
        }
        for (int i = 0; i < ld->totloop; i++, tld++) {
-               BMLoop *loop_at_index = loops[tld->loop_index];
-               
BKE_lnor_space_custom_normal_to_data(bm->lnor_spacearr->lspacearr[tld->loop_index],
 loop_at_index->f->no, tld->clnors_data);
+               BMLoop *l_curr = loop_at_index[tld-

@@ 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