[Bf-blender-cvs] [986b1f6f327] soc-2017-normal-tools: Added 3 level weighting to modifier. Also did minor cleanup of code

Rohan Rathi noreply at git.blender.org
Mon Sep 4 05:59:30 CEST 2017


Commit: 986b1f6f32708b658fea2b77000253b37820e559
Author: Rohan Rathi
Date:   Sat Sep 2 12:13:47 2017 +0530
Branches: soc-2017-normal-tools
https://developer.blender.org/rB986b1f6f32708b658fea2b77000253b37820e559

Added 3 level weighting to modifier. Also did minor cleanup of code

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

M	release/scripts/startup/bl_ui/properties_data_modifier.py
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_modifier_types.h
M	source/blender/makesdna/DNA_scene_types.h
M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/makesrna/intern/rna_scene.c
M	source/blender/modifiers/intern/MOD_weighted_normal.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index d631e583c6b..813334b8aa3 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1543,7 +1543,7 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         row.active = has_vgroup
         row.prop(md, "invert_vertex_group", text="", icon='ARROW_LEFTRIGHT')
         layout.prop(md, "keep_sharp")
-        layout.prop(md, "binary_weights")
+        layout.prop(md, "face_influence")
 
 
 classes = (
diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index 2b3e896b950..e718a873a33 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -475,6 +475,14 @@ class VIEW3D_PT_tools_normal(View3DPanel, Panel):
 		col = layout.column(align=True)
 		col.operator("mesh.smoothen_custom_normals", text="Smoothen")
 
+		col = layout.column(align=True)
+		col.label(text="Face Strength")
+		row = col.row(align=True)
+		
+		row.prop(toolsettings, "face_strength", text="")
+		row.operator("mesh.mod_weighted_strength", text="", icon = "FACESEL").set=False
+		row.operator("mesh.mod_weighted_strength", text="", icon = "ZOOMIN").set=True	
+
 
 class VIEW3D_PT_tools_uvs(View3DPanel, Panel):
     bl_category = "Shading / UVs"
diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c
index 06dba992525..87cd0c95052 100644
--- a/source/blender/editors/mesh/editmesh_tools.c
+++ b/source/blender/editors/mesh/editmesh_tools.c
@@ -6796,7 +6796,6 @@ static EnumPropertyItem normal_vector_tool_items[] = {
 
 static int edbm_custom_normal_tools_exec(bContext *C, wmOperator *op)
 {
-
 	Object *obedit = CTX_data_edit_object(C);
 	Scene *scene = CTX_data_scene(C);
 	BMEditMesh *em = BKE_editmesh_from_object(obedit);
@@ -7101,4 +7100,70 @@ void MESH_OT_smoothen_custom_normals(struct wmOperatorType *ot)
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
 	ot->prop = RNA_def_float(ot->srna, "factor", 0.5f, 0.0f, 1.0f, "Factor", "Specifies weight of smooth vs original normal", 0.0f, 1.0f);
+}
+
+/********************** Weighted Normal Modifier Face Strength **********************/
+
+static int edbm_mod_weighted_strength_exec(bContext *C, wmOperator *op)
+{
+	Scene *scene = CTX_data_scene(C);
+	Object *obedit = CTX_data_edit_object(C);
+	BMEditMesh *em = BKE_editmesh_from_object(obedit);
+	BMesh *bm = em->bm;
+	BMFace *f;
+	BMIter fiter;
+	
+	BM_select_history_clear(bm);
+
+	int cd_prop_int_offset = CustomData_get_offset(&bm->pdata, CD_PROP_INT);
+	if (cd_prop_int_offset == -1) {
+		BM_data_layer_add(bm, &bm->pdata, CD_PROP_INT);
+		cd_prop_int_offset = CustomData_get_offset(&bm->pdata, CD_PROP_INT);
+	}
+
+	const int face_strength = scene->toolsettings->face_strength;
+	const bool set = RNA_boolean_get(op->ptr, "set");
+	BM_mesh_elem_index_ensure(bm, BM_FACE);
+
+	if (set) {
+		BM_ITER_MESH(f, &fiter, bm, BM_FACES_OF_MESH) {
+			if (BM_elem_flag_test(f, BM_ELEM_SELECT)) {
+				int *strength = BM_ELEM_CD_GET_VOID_P(f, cd_prop_int_offset);
+				*strength = face_strength;
+			}
+		}
+	}
+	else {
+		BM_ITER_MESH(f, &fiter, bm, BM_FACES_OF_MESH) {
+			int *strength = BM_ELEM_CD_GET_VOID_P(f, cd_prop_int_offset);
+			if (*strength == face_strength) {
+				BM_face_select_set(bm, f, true);
+				BM_select_history_store(bm, f);
+			}
+			else {
+				BM_face_select_set(bm, f, false);
+			}
+		}
+	}
+
+	EDBM_update_generic(em, false, false);
+	return OPERATOR_FINISHED;
+}
+
+void MESH_OT_mod_weighted_strength(struct wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Face Strength";
+	ot->description = "Set/Get strength of face. Used in Weighted Normal Modifier";
+	ot->idname = "MESH_OT_mod_weighted_strength";
+
+	/* api callbacks */
+	ot->exec = edbm_mod_weighted_strength_exec;
+	ot->poll = ED_operator_editmesh_auto_smooth;
+
+	/* flags */
+	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+	ot->prop = RNA_def_boolean(ot->srna, "set", 0, "Set value", "Set Value of faces");
+	RNA_def_property_flag(ot->prop, PROP_HIDDEN);
 }
\ No newline at end of file
diff --git a/source/blender/editors/mesh/mesh_intern.h b/source/blender/editors/mesh/mesh_intern.h
index 42788bf3d1e..a5043744f13 100644
--- a/source/blender/editors/mesh/mesh_intern.h
+++ b/source/blender/editors/mesh/mesh_intern.h
@@ -236,6 +236,7 @@ void MESH_OT_custom_normal_tools(struct wmOperatorType *ot);
 void MESH_OT_set_normals_from_faces(struct wmOperatorType *ot);
 void MESH_OT_average_loop_normals(struct wmOperatorType *ot);
 void MESH_OT_smoothen_custom_normals(struct wmOperatorType *ot);
+void MESH_OT_mod_weighted_strength(struct wmOperatorType *ot);
 
 #ifdef WITH_FREESTYLE
 void MESH_OT_mark_freestyle_edge(struct wmOperatorType *ot);
diff --git a/source/blender/editors/mesh/mesh_ops.c b/source/blender/editors/mesh/mesh_ops.c
index 80c730ca6fa..6843a761133 100644
--- a/source/blender/editors/mesh/mesh_ops.c
+++ b/source/blender/editors/mesh/mesh_ops.c
@@ -199,6 +199,7 @@ void ED_operatortypes_mesh(void)
 	WM_operatortype_append(MESH_OT_set_normals_from_faces);
 	WM_operatortype_append(MESH_OT_average_loop_normals);
 	WM_operatortype_append(MESH_OT_smoothen_custom_normals);
+	WM_operatortype_append(MESH_OT_mod_weighted_strength);
 
 #ifdef WITH_GAMEENGINE
 	WM_operatortype_append(MESH_OT_navmesh_make);
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 181ef91b109..1e683a9e9c2 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1633,7 +1633,7 @@ enum {
 enum {
 	MOD_WEIGHTEDNORMAL_KEEP_SHARP = (1 << 0),
 	MOD_WEIGHTEDNORMAL_INVERT_VGROUP = (1 << 1),
-	MOD_WEIGHTEDNORMAL_BIN_WEIGHTS = (1 << 2),
+	MOD_WEIGHTEDNORMAL_FACE_INFLUENCE = (1 << 2),
 };
 
 #define MOD_MESHSEQ_READ_ALL \
diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h
index dc1092cc0be..e050b416781 100644
--- a/source/blender/makesdna/DNA_scene_types.h
+++ b/source/blender/makesdna/DNA_scene_types.h
@@ -1606,7 +1606,7 @@ typedef struct ToolSettings {
 
 	/* Normal Editing */
 	float normal_vector[3];
-	char pad[4];
+	int face_strength;
 } ToolSettings;
 
 /* *************************************************************** */
@@ -2066,6 +2066,13 @@ enum {
 	OB_DRAW_GROUPUSER_ALL       = 2
 };
 
+/* toolsettings->face_strength */
+enum {
+	FACE_STRENGTH_WEAK = 1,
+	FACE_STRENGTH_MEDIUM = 0,
+	FACE_STRENGTH_STRONG = 2,
+};
+
 /* toolsettings->vgroupsubset */
 /* object_vgroup.c */
 typedef enum eVGroupSelect {
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index 6a06379bad9..cbd267b951b 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -4807,9 +4807,9 @@ static void rna_def_modifier_weightednormal(BlenderRNA *brna)
 	RNA_def_property_ui_text(prop, "Invert", "Invert vertex group influence");
 	RNA_def_property_update(prop, 0, "rna_Modifier_update");
 
-	prop = RNA_def_property(srna, "binary_weights", PROP_BOOLEAN, PROP_NONE);
-	RNA_def_property_boolean_sdna(prop, NULL, "flag", MOD_WEIGHTEDNORMAL_BIN_WEIGHTS);
-	RNA_def_property_ui_text(prop, "Binary Weights", "Sets weight of smooth faces to 0. Weight of flat faces remains unchanged.");
+	prop = RNA_def_property(srna, "face_influence", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "flag", MOD_WEIGHTEDNORMAL_FACE_INFLUENCE);
+	RNA_def_property_ui_text(prop, "Face Influence", "Use influence of face for weighting");
 	RNA_def_property_update(prop, 0, "rna_Modifier_update");
 }
 
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c
index 192ef03d5d1..00ddb8d582e 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -2571,6 +2571,13 @@ static void rna_def_tool_settings(BlenderRNA  *brna)
 		{0, NULL, 0, NULL, NULL}
 	};
 
+	static EnumPropertyItem mod_weighted_strength[] = {
+		{ FACE_STRENGTH_WEAK, "Weak", 0, "Weak", "Set face strength to weak" },
+		{ FACE_STRENGTH_MEDIUM, "Medium", 0, "Medium", "Set face strength to medium" },
+		{ FACE_STRENGTH_STRONG, "Strong", 0, "Strong", "Set face strength to Strong" },
+		{ 0, NULL, 0, NULL, NULL },
+	};
+
 	static EnumPropertyItem draw_groupuser_items[] = {
 		{OB_DRAW_GROUPUSER_NONE, "NONE", 0, "None", ""},
 		{OB_DRAW_GROUPUSER_ACTIVE, "ACTIVE", 0, "Active", "Show vertices with no weights in the active group"},
@@ -2964,6 +2971,11 @@ static void rna_def_tool_settings(BlenderRNA  *brna)
 	RNA_def_property_ui_text(prop, "Normal Vector", "Normal Vector used to copy, add or multiply");
 	RNA_def_property_ui_range(prop, -10000.0, 10000.0, 1, 3);
 
+	prop = RNA_def_property(srna, "face_strength", PROP_ENUM, PROP_NONE);		//Face Strength for Weighted Normal Modifier
+	RNA_def_property_enum_sdna(prop, NULL, "face_strength");
+	RNA_def_property_enum_items(prop, mod_weighted_strength);
+	RNA_def_property_ui_text(prop, "Face Strength", "Set strength of face to specified value");
+
 	/* etch-a-ton */
 	prop = RNA_def_property(srna, "use_bone_sketching", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "bone_sketching", BONE_SKETCHING);
diff --git a/source/blender/modifiers/intern/MOD_weighted_normal.c b/source/blender/modifiers/intern/MOD_weighted_normal.c
index 3e395fc41ec..78fbbd80aae 100644
--- a/source/blender/modifiers/intern/MOD_weighted_normal.c
+++ b/source/blender/modifiers/intern/MOD_weighted_normal.c
@@ -29,6 +29,7 @@
 
 #include "DNA_mesh_types.h"
 #include "DNA_object_types.h"
+#include "DNA_scene_types.h"
 
 #include "BKE_cdderivedmesh.h"
 #include "BKE_mesh.h"
@@ -76,6 +77,21 @@ static int sort_by_index(const void *p1, const void *p2)
 		return 0;
 }
 
+static bool check_strength(int strength, int *cur_strength, float *cur_val, int *vertcount, float (*custom_normal)[3])
+{
+	if ((strength == FACE_STRENGTH_STRONG && *cur_strength != FACE_STRENGTH_STRONG) ||

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list