[Bf-blender-cvs] [33ed8b9] temp_custom_loop_normals: SetSplitNormals: add 'from current clnors' options to 'set clnors from vertices' code too.

Bastien Montagne noreply at git.blender.org
Sun Aug 24 16:40:38 CEST 2014


Commit: 33ed8b932596e1f8fdb92b3a588a5cff3a43ccb1
Author: Bastien Montagne
Date:   Sun Aug 24 15:58:15 2014 +0200
Branches: temp_custom_loop_normals
https://developer.blender.org/rB33ed8b932596e1f8fdb92b3a588a5cff3a43ccb1

SetSplitNormals: add 'from current clnors' options to 'set clnors from vertices' code too.

Did not do it at first because this could give strange/unexpected results with non-full
weights, but in the end it turns out to be a really needed and 'most expected'
behavior, so add it in all case, and make it default behavior in modifier.

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

M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/blenkernel/BKE_mesh.h
M	source/blender/blenkernel/intern/mesh_evaluate.c
M	source/blender/makesrna/intern/rna_mesh_api.c
M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/modifiers/intern/MOD_setsplitnormal.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index cda5eaa..ba6bb17 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1228,7 +1228,6 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
     def SET_SPLIT_NORMAL(self, layout, ob, md):
         has_vgroup = bool(md.vertex_group)
         needs_object_bbox_center = (md.mode == 'ELLIPSOID') and not md.target
-        needs_use_current_clnors = (md.mode == 'SPLIT_NORMALS')
 
         row = layout.row()
         row.prop(md, "mode", expand=True)
@@ -1247,9 +1246,7 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         sub = row.row(align=True)
         sub.active = has_vgroup
         sub.prop(md, "use_invert_vertex_group", text="", icon='ARROW_LEFTRIGHT')
-        sub = col.row()
-        sub.active = needs_use_current_clnors
-        sub.prop(md, "use_current_custom_split_normals")
+        col.prop(md, "use_current_custom_split_normals")
 
 
 if __name__ == "__main__":  # only for live edit.
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index d616021..114d224 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -227,7 +227,8 @@ void BKE_mesh_normals_loop_custom_set(
 void BKE_mesh_normals_loop_custom_from_vertices_set(
         struct MVert *mverts, float (*custom_vertnors)[3], const float *custom_vertnors_facs, const int numVerts,
         struct MEdge *medges, const int numEdges, struct MLoop *mloops, const int numLoops,
-        struct MPoly *mpolys, const float (*polynors)[3], const int numPolys, short (*r_clnors_data)[2]);
+        struct MPoly *mpolys, const float (*polynors)[3], const int numPolys,
+        short (*r_clnors_data)[2], const bool use_clnors_data);
 
 void BKE_mesh_calc_poly_normal(
         struct MPoly *mpoly, struct MLoop *loopstart,
diff --git a/source/blender/blenkernel/intern/mesh_evaluate.c b/source/blender/blenkernel/intern/mesh_evaluate.c
index 875127b..2a35987 100644
--- a/source/blender/blenkernel/intern/mesh_evaluate.c
+++ b/source/blender/blenkernel/intern/mesh_evaluate.c
@@ -1215,8 +1215,8 @@ void BKE_mesh_normals_loop_split(MVert *mverts, const int numVerts, MEdge *medge
  * same custom lnor for all loops sharing a same smooth fan.
  * If use_vertices if true, custom_loopnors and custom_loopnors_facs are assumed to be per-vertex, not per-loop
  * (this allows to set whole vert's normals at once, useful in some cases).
- * If use_vertices is false and use_clnors_data is true, auto lnors will be computed using data available in given
- * r_clnors_data. Useful to edit custom normals instead of simply overwriting them!
+ * If use_clnors_data is true, auto lnors will be computed using data available in given r_clnors_data. Useful to edit
+ * custom normals instead of simply overwriting them!
  */
 static void mesh_normals_loop_custom_set(MVert *mverts, const int numVerts, MEdge *medges, const int numEdges,
                                          MLoop *mloops, float (*custom_loopnors)[3],
@@ -1418,11 +1418,11 @@ void BKE_mesh_normals_loop_custom_from_vertices_set(MVert *mverts, float (*custo
                                                     MEdge *medges, const int numEdges,
                                                     MLoop *mloops, const int numLoops,
                                                     MPoly *mpolys, const float (*polynors)[3], const int numPolys,
-                                                    short (*r_clnors_data)[2])
+                                                    short (*r_clnors_data)[2], const bool use_clnors_data)
 {
 	mesh_normals_loop_custom_set(mverts, numVerts, medges, numEdges, mloops, custom_vertnors,
 	                             custom_vertnors_facs, numLoops, mpolys, polynors, numPolys,
-	                             r_clnors_data, false, true);
+	                             r_clnors_data, use_clnors_data, true);
 }
 
 /** \} */
diff --git a/source/blender/makesrna/intern/rna_mesh_api.c b/source/blender/makesrna/intern/rna_mesh_api.c
index 15504cc..a013a40 100644
--- a/source/blender/makesrna/intern/rna_mesh_api.c
+++ b/source/blender/makesrna/intern/rna_mesh_api.c
@@ -185,7 +185,8 @@ static void rna_Mesh_define_normals_split_custom_do(Mesh *mesh, float (*custom_l
 		BKE_mesh_normals_loop_custom_from_vertices_set(mesh->mvert, custom_loopnors, custom_loopnors_factors,
 		                                               mesh->totvert, mesh->medge, mesh->totedge,
 		                                               mesh->mloop, mesh->totloop, mesh->mpoly,
-		                                               (const float (*)[3])polynors, mesh->totpoly, clnors);
+		                                               (const float (*)[3])polynors, mesh->totpoly,
+		                                               clnors, use_current_clnors);
 	}
 	else {
 		BKE_mesh_normals_loop_custom_set(mesh->mvert, mesh->totvert, mesh->medge, mesh->totedge,
@@ -224,7 +225,8 @@ static void rna_Mesh_define_normals_split_custom(Mesh *mesh, ReportList *reports
 
 static void rna_Mesh_define_normals_split_custom_from_vertices(Mesh *mesh, ReportList *reports,
                                                                int normals_len, float *normals,
-                                                               int factors_len, float *factors)
+                                                               int factors_len, float *factors,
+                                                               int use_current_custom_normals)
 {
 	float (*vertnors)[3] = (float (*)[3])normals;
 	const float *vertnors_factors = (const float *)factors;
@@ -245,7 +247,7 @@ static void rna_Mesh_define_normals_split_custom_from_vertices(Mesh *mesh, Repor
 		return;
 	}
 
-	rna_Mesh_define_normals_split_custom_do(mesh, vertnors, vertnors_factors, false, true);
+	rna_Mesh_define_normals_split_custom_do(mesh, vertnors, vertnors_factors, (bool)use_current_custom_normals, true);
 }
 
 static void rna_Mesh_transform(Mesh *mesh, float *mat)
@@ -335,6 +337,8 @@ void RNA_api_mesh(StructRNA *srna)
 	                           "Interpolation factors (0.0 to use full auto normal, 1.0 to use full custom given one)",
 	                           0.0f, 0.0f);
 	RNA_def_property_flag(parm, PROP_DYNAMIC);
+	RNA_def_boolean(func, "use_current_custom_normals", false, "",
+	                "Try to use current custom split normals data as basis (if available), instead of plain auto ones");
 
 	func = RNA_def_function(srna, "update", "ED_mesh_update");
 	RNA_def_boolean(func, "calc_edges", 0, "Calculate Edges", "Force recalculation of edges");
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index c14de99..a66736f 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -3718,6 +3718,7 @@ static void rna_def_modifier_setsplitnormal(BlenderRNA *brna)
 
 	prop = RNA_def_property(srna, "use_current_custom_split_normals", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "flags", MOD_SETSPLITNORMAL_USE_CURCLNORS);
+	RNA_def_property_boolean_default(prop, true);
 	RNA_def_property_ui_text(prop, "Use Custom Split Normals",
 	                         "Use current custom split normals as basis, instead of auto-computed ones, if available "
 	                         "(Split Normals mode only)");
diff --git a/source/blender/modifiers/intern/MOD_setsplitnormal.c b/source/blender/modifiers/intern/MOD_setsplitnormal.c
index 853848a..bd385d7 100644
--- a/source/blender/modifiers/intern/MOD_setsplitnormal.c
+++ b/source/blender/modifiers/intern/MOD_setsplitnormal.c
@@ -178,6 +178,7 @@ static void setSplitNormalModifier_do_ellipsoid(
         MLoop *mloop, const int num_loops, MPoly *mpoly, const int num_polys)
 {
 	const bool use_bbox_center = ((smd->flags & MOD_SETSPLITNORMAL_CENTER_BBOX) != 0) && (smd->target == NULL);
+	const bool use_current_clnors = ((smd->flags & MOD_SETSPLITNORMAL_USE_CURCLNORS) != 0);
 
 	float (*cos)[3] = MEM_mallocN(sizeof(*cos) * num_verts, __func__);
 	float *facs = MEM_mallocN(sizeof(*facs) * num_verts, __func__);
@@ -238,7 +239,8 @@ static void setSplitNormalModifier_do_ellipsoid(
 	}
 
 	BKE_mesh_normals_loop_custom_from_vertices_set(mvert, cos, facs, num_verts, medge, num_edges, mloop, num_loops,
-	                                               mpoly, (const float(*)[3])polynors, num_polys, clnors);
+	                                               mpoly, (const float(*)[3])polynors, num_polys,
+	                                               clnors, use_current_clnors);
 
 	MEM_freeN(cos);
 	MEM_freeN(facs);
@@ -256,6 +258,8 @@ static void setSplitNormalModifier_do_facenormal(
 	const bool free_target_dm = ensure_target_dm(target_ob, &target_dm);
 	BVHTreeFromMesh treeData = {0};
 
+	const bool use_current_clnors = ((smd->flags & MOD_SETSPLITNORMAL_USE_CURCLNORS) != 0);
+
 	float (*cos)[3] = MEM_mallocN(sizeof(*cos) * num_verts, __func__);
 	float *facs = MEM_mallocN(sizeof(*facs) * num_verts, __func__);
 
@@ -332,7 +336,8 @@ static void setSplitNormalModifier_do_facenormal(
 		}
 
 		BKE_mesh_normals_loop_custom_from_vertices_set(mvert, cos, facs, num_verts, medge, num_edges, mloop, num_loops,
-		                                               mpoly, (const float(*)[3])polynors, num_polys, clnors);
+		                                               mpoly, (const float(*)[3])polynors, num_polys,
+		                                               clnors, use_current_clnors);
 	}
 
 	MEM_freeN(cos);
@@ -597,9 +602,10 @@ static void setSplitNormalModifier_do(SetSplitNormalModifierData *smd, Object *o
 
 static void initData(ModifierData *md)
 {
-	SetSplitNormalModifierData *smd = (SetSplitNormalModifierData *) md;
+	SetSplitNormalModifierData *smd = (SetSplitNormalModifierData *)md;
 
 	smd->mode = MOD_SETSPLITNORMAL_MODE_ELLIPSOID;
+	smd->flags = MOD_SETSPLITNORMAL_USE_CURCLNORS;
 }
 
 static void copyData(ModifierData *md, ModifierData *target)




More information about the Bf-blender-cvs mailing list