[Bf-blender-cvs] [d0c25f82966] soc-2017-normal-tools: Added the following to weighted modifier:

Rohan Rathi noreply at git.blender.org
Sun Jul 30 18:08:52 CEST 2017


Commit: d0c25f82966f9bc9b4528814b3bdd074b98edee6
Author: Rohan Rathi
Date:   Sun Jul 30 21:38:33 2017 +0530
Branches: soc-2017-normal-tools
https://developer.blender.org/rBd0c25f82966f9bc9b4528814b3bdd074b98edee6

Added the following to weighted modifier:

1) Modifier now respects sharp edges, requires bool value to be checked.
2) Can now use vertex groups to apply modifier to only selected vgroup
3) Added boolean (0-1) weights in the form of Smooth/Sharp flags. Smooth flag means the face will hold 0 weight.

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

M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesrna/intern/rna_modifier.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 ef7f46e0954..749d3efc58d 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1530,12 +1530,19 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
             layout.operator("object.correctivesmooth_bind", text="Unbind" if is_bind else "Bind")
 
     def WEIGHTED_NORMAL(self, layout, ob, md):
+        has_vgroup = bool(md.vertex_group)
+
         col = layout.column()
         col.label("Weighting Mode:")
         col.prop(md, "mode", text="")
 
         layout.prop(md, "weight", text="Weight")
         layout.prop(md, "thresh", text="Threshold")
+        row = layout.row(align=True)
+        row.prop_search(md, "vertex_group", ob, "vertex_groups", text="")
+        row.active = has_vgroup
+        row.prop(md, "invert_vertex_group", text="", icon='ARROW_LEFTRIGHT')
+        layout.prop(md, "keep_sharp")
 
 
 classes = (
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 47950ced88d..67ae41f0300 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1616,7 +1616,9 @@ enum {
 typedef struct WeightedNormalModifierData {
 	ModifierData modifier;
 
-	short weight, mode;
+	char defgrp_name[64];
+	char mode, flag;
+	short weight;
 	float thresh;
 } WeightedNormalModifierData;
 
@@ -1627,6 +1629,12 @@ enum {
 	MOD_WEIGHTEDNORMAL_MODE_FACE_ANGLE = 2,
 };
 
+/* WeightedNormalModifierData.flag */
+enum {
+	MOD_WEIGHTEDNORMAL_KEEP_SHARP = (1 << 0),
+	MOD_WEIGHTEDNORMAL_INVERT_VGROUP = (1 << 1),
+};
+
 #define MOD_MESHSEQ_READ_ALL \
 	(MOD_MESHSEQ_READ_VERT | MOD_MESHSEQ_READ_POLY | MOD_MESHSEQ_READ_UV | MOD_MESHSEQ_READ_COLOR)
 
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index 81121bc88b0..a69809308c6 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -504,6 +504,7 @@ RNA_MOD_VGROUP_NAME_SET(WeightVGMix, defgrp_name_b);
 RNA_MOD_VGROUP_NAME_SET(WeightVGMix, mask_defgrp_name);
 RNA_MOD_VGROUP_NAME_SET(WeightVGProximity, defgrp_name);
 RNA_MOD_VGROUP_NAME_SET(WeightVGProximity, mask_defgrp_name);
+RNA_MOD_VGROUP_NAME_SET(WeightedNormal, defgrp_name);
 RNA_MOD_VGROUP_NAME_SET(Wireframe, defgrp_name);
 
 static void rna_ExplodeModifier_vgroup_get(PointerRNA *ptr, char *value)
@@ -4789,6 +4790,22 @@ static void rna_def_modifier_weightednormal(BlenderRNA *brna)
 	RNA_def_property_ui_range(prop, 0, 5, 1, 2);
 	RNA_def_property_ui_text(prop, "Thresh", "Threshold value for different weights to be considered equal");
 	RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+	prop = RNA_def_property(srna, "keep_sharp", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "flag", MOD_WEIGHTEDNORMAL_KEEP_SHARP);
+	RNA_def_property_ui_text(prop, "Keep Sharp Edges", "Do not edit normals of sharp edges");
+	RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+	prop = RNA_def_property(srna, "vertex_group", PROP_STRING, PROP_NONE);
+	RNA_def_property_string_sdna(prop, NULL, "defgrp_name");
+	RNA_def_property_ui_text(prop, "Vertex Group", "Vertex group name for modifying the selected areas");
+	RNA_def_property_string_funcs(prop, NULL, NULL, "rna_WeightedNormalModifier_defgrp_name_set");
+	RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+	prop = RNA_def_property(srna, "invert_vertex_group", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "flag", MOD_WEIGHTEDNORMAL_INVERT_VGROUP);
+	RNA_def_property_ui_text(prop, "Invert", "Invert vertex group influence");
+	RNA_def_property_update(prop, 0, "rna_Modifier_update");
 }
 
 void RNA_def_modifier(BlenderRNA *brna)
diff --git a/source/blender/modifiers/intern/MOD_weighted_normal.c b/source/blender/modifiers/intern/MOD_weighted_normal.c
index e0cd81abc79..d0fa31ee22c 100644
--- a/source/blender/modifiers/intern/MOD_weighted_normal.c
+++ b/source/blender/modifiers/intern/MOD_weighted_normal.c
@@ -29,11 +29,15 @@
 #include "DNA_object_types.h"
 
 #include "BKE_cdderivedmesh.h"
+#include "BKE_deform.h"
 #include "BKE_mesh.h"
 
 #include "BLI_math.h"
 
+#include "bmesh_class.h"
+
 #include "MOD_modifiertypes.h"
+#include "MOD_util.h"
 
 typedef struct pair {
 	float val;		/* contains mode based value (face area/ corner angle) */
@@ -56,33 +60,41 @@ static int sort_by_val(const void *p1, const void *p2)
 static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd, Object *ob, DerivedMesh *dm,
 	short(*clnors)[2], MVert *mvert, const int numVerts, MEdge *medge,
 	const int numEdges, MLoop *mloop, const int numLoops, MPoly *mpoly,
-	const int numPoly, float(*polynors)[3], const float weight, short mode, pair *mode_pair, float *index_angle)
+	const int numPoly, float(*polynors)[3], MDeformVert *dvert, int defgrp_index,
+	const bool use_invert_vgroup, const float weight, short mode, pair *mode_pair, float *index_angle)
 {
 	float(*custom_normal)[3] = MEM_callocN(sizeof(*custom_normal) * numVerts, "__func__");
 	int *vertcount = MEM_callocN(sizeof(*vertcount) * numVerts, "__func__");	/* count number of loops using this vertex so far */
 	float *cur_val = MEM_callocN(sizeof(*cur_val) * numVerts, "__func__");		/* current max val for this vertex */
 
+	const bool keep_sharp = (wnmd->flag & MOD_WEIGHTEDNORMAL_KEEP_SHARP) != 0,
+		 has_vgroup = dvert != NULL;
+
 	if (mode == MOD_WEIGHTEDNORMAL_MODE_FACE) {
 		for (int i = 0; i < numPoly; i++) {			/* iterate through each pair in descending order */
 			int ml_index = mpoly[mode_pair[i].index].loopstart;
 			const int ml_index_end = ml_index + mpoly[mode_pair[i].index].totloop;
 
 			for (; ml_index < ml_index_end; ml_index++) {
-				float wnor[3];
+
 				int mv_index = mloop[ml_index].v;
 
-				if (!cur_val[mv_index]) {			/* if cur_val is 0 init it to present value */
-					cur_val[mv_index] = mode_pair[i].val;
-				}
-				if (!compare_ff(cur_val[mv_index], mode_pair[i].val, wnmd->thresh)) {
-					vertcount[mv_index]++;			/* cur_val and present value differ more than threshold, update  */
-					cur_val[mv_index] = mode_pair[i].val;
+				if ( ((dvert && dvert[mv_index].dw) ^ use_invert_vgroup) || !dvert/* && keep_sharp)*/) {
+					float wnor[3];
+
+					if (!cur_val[mv_index]) {			/* if cur_val is 0 init it to present value */
+						cur_val[mv_index] = mode_pair[i].val;
+					}
+					if (!compare_ff(cur_val[mv_index], mode_pair[i].val, wnmd->thresh)) {
+						vertcount[mv_index]++;			/* cur_val and present value differ more than threshold, update  */
+						cur_val[mv_index] = mode_pair[i].val;
+					}
+					float n_weight = pow(weight, vertcount[mv_index]);		/* exponentially divided weight for each normal */
+
+					copy_v3_v3(wnor, polynors[mode_pair[i].index]);
+					mul_v3_fl(wnor, mode_pair[i].val * (1.0f / n_weight));
+					add_v3_v3(custom_normal[mv_index], wnor);
 				}
-				float n_weight = pow(weight, vertcount[mv_index]);		/* exponentially divided weight for each normal */
-
-				copy_v3_v3(wnor, polynors[mode_pair[i].index]);
-				mul_v3_fl(wnor, mode_pair[i].val * (1.0f / n_weight));
-				add_v3_v3(custom_normal[mv_index], wnor);
 			}
 		}
 	}
@@ -92,18 +104,20 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd, Object
 			int ml_index = mode_pair[i].index;
 			int mv_index = mloop[ml_index].v;
 
-			if (!cur_val[mv_index]) {
-				cur_val[mv_index] = mode_pair[i].val;
-			}
-			if (!compare_ff(cur_val[mv_index], mode_pair[i].val, wnmd->thresh)) {
-				vertcount[mv_index]++;
-				cur_val[mv_index] = mode_pair[i].val;
-			}
-			float n_weight = pow(weight, vertcount[mv_index]);
+			if (((dvert && dvert[mv_index].dw) ^ use_invert_vgroup) || (!dvert && keep_sharp)) {
+				if (!cur_val[mv_index]) {
+					cur_val[mv_index] = mode_pair[i].val;
+				}
+				if (!compare_ff(cur_val[mv_index], mode_pair[i].val, wnmd->thresh)) {
+					vertcount[mv_index]++;
+					cur_val[mv_index] = mode_pair[i].val;
+				}
+				float n_weight = pow(weight, vertcount[mv_index]);
 
-			copy_v3_v3(wnor, polynors[(int)index_angle[ml_index]]);
-			mul_v3_fl(wnor, mode_pair[i].val * (1.0f / n_weight));
-			add_v3_v3(custom_normal[mv_index], wnor);
+				copy_v3_v3(wnor, polynors[(int)index_angle[ml_index]]);
+				mul_v3_fl(wnor, mode_pair[i].val * (1.0f / n_weight));
+				add_v3_v3(custom_normal[mv_index], wnor);
+			}
 		}
 	}
 	MEM_freeN(vertcount);
@@ -113,9 +127,44 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd, Object
 		normalize_v3(custom_normal[mv_index]);
 	}
 
-	BKE_mesh_normals_loop_custom_from_vertices_set(mvert, custom_normal, numVerts, medge, numEdges,
-		mloop, numLoops, mpoly, polynors, numPoly, clnors);
+	if (!keep_sharp && !has_vgroup) {
+		BKE_mesh_normals_loop_custom_from_vertices_set(mvert, custom_normal, numVerts, medge, numEdges,
+			mloop, numLoops, mpoly, polynors, numPoly, clnors);
+	}
+	else {
+		float(*loop_normal)[3] = MEM_callocN(sizeof(*loop_normal) * numLoops, "__func__");
 
+		for (int mp_index = 0; mp_index < numPoly; mp_index++) {
+			int ml_index = mpoly[mp_index].loopstart;
+			const int ml_index_end = ml_index + mpoly[mp_index].totloop;
+
+			for (int i = ml_index; i < ml_index_end; i++) {
+				copy_v3_v3(loop_normal[i], custom_normal[mloop[i].v]);
+			}
+		}
+
+		if (keep_sharp) {
+			for (int mp_index = 0; mp_index < numPoly; mp_index++) {
+				int ml_index = mpoly[mp_index].loopstart;
+				const int ml_index_end = ml_index + mpoly[mp_index].totloop;
+
+				for (int i = ml_index; i < ml_index_end; i++) {
+					if (medge[mloop[i].e].flag & ME_SHARP) {
+						int other_v = BKE_mesh_edge_other_vert(&medge[mloop[i].e], mloop[i].v);
+
+						int other_loop_index = poly_find_loop_from_vert(&mpoly[mp_index], &mloop[ml_index], other_v);
+						if (other_loop_index != -1) {
+							zero_v3(loop_normal[i]);
+							zero_v3(loop_normal[ml_index + other_loop_index]);
+						}
+					}
+				}
+			}
+		}
+		BKE_mesh_normals_loop_custom_set(mvert, numVerts, medge, numEdges,
+			mloop, loop_normal, numLo

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list