[Bf-blender-cvs] [57974dd] temp_custom_loop_normals: Custom Split Normals current state

Bastien Montagne noreply at git.blender.org
Wed Aug 6 21:36:51 CEST 2014


Commit: 57974ddd554941d5227ad3cb5b75e1cdef46e139
Author: Bastien Montagne
Date:   Sun Mar 2 17:27:11 2014 +0100
Branches: temp_custom_loop_normals
https://developer.blender.org/rB57974ddd554941d5227ad3cb5b75e1cdef46e139

Custom Split Normals current state

This is not yet ready for a detailed review, requesting more a skim one to see whether there are some big/key issues in current patch code/design.

Further info on concepts used for custom lnors storage can be found [here](http://wiki.blender.org/index.php/User:Mont29/Foundation/Split_Vertex_Normals#Loop_normal_edition), but to summarize, it defines for each smooth fan (i.e. group of neighbor loops sharing a same normal) an orthonormal system which one axis is the auto lnor, and another one is aligned with a 'reference' edge which defines the start of the smooth fan. In addition, we store two angles, alhpa being the average angle bet [...]

We then store custom lnors as a set of two factors, one applied to alpha angle (to get how much 'far away' from auto lnor custom one is), the other applied to beta angle (to get where around auto lnor custom one is).

Since we need those data as well (like auto lnors), nearly all this adds to existing `BKE_mesh_normals_loop_split()` (and its BMesh version), with a small API to define lnor spaces, and convert raw custom normals to/from clnor data format (the two angle factors). Note lnor spaces also embed a representation of smoothfans (as a linklist of relevant loop's indices).

Also note than all this overhead only takes effect when computing lnor spaces and/or using custom lnors, else current split lnors code is nearly unchanged.

Would also like some advice on performances topic - right now, custom split normals can be up to 50 (or more) times slower than mare autosmooth in worst 'grid/sphere' cases, mostly because we can't skip anymore fanning around fully smooth vertices (since we have to generate lnor spaces for those too). In a more average case, it's something like three, four times slower (really depends on the topology!).

I have two different tracks for optimization currently:

* Use real threading (BLI_thread, could probably gives three or four times speedup with modern CPUs). Not really considering OMP, it’s practically unusable on OSX and Win platforms currently (and not that perfomant compared to real threading anyway, afaik). Thinks the main loop of `BKE_mesh_normals_loop_split` (and it’s BMesh equivalent) would be a good candidate for that, afaics each loop processing can be operated in parallel (this is a bit tricky to analyze, so not yet 100% sure about  [...]

* Cache lnor spaces, using a similar system to current skey gsoc to detect changes in geometry or topology that would need to recompute them. Since computing those lnor spaces takes a huge part of the added processing time, this should lead to a nice gain too. But that would mean caching quite a bit of data in BMesh, Mesh and DerivedMesh...

Reviewers: campbellbarton

Differential Revision: https://developer.blender.org/D703

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

M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/editors/space_outliner/outliner_draw.c
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesrna/RNA_access.h
M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/modifiers/CMakeLists.txt
M	source/blender/modifiers/MOD_modifiertypes.h
A	source/blender/modifiers/intern/MOD_setsplitnormal.c
M	source/blender/modifiers/intern/MOD_util.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 5769db5..372d22e 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1222,6 +1222,35 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
 
         col.prop(md, "material_offset", text="Material Offset")
 
+    def SET_SPLIT_NORMAL(self, layout, ob, md):
+        has_vgroup = bool(md.vertex_group)
+        needs_object_geom = (md.mode == 'OBJECT')
+        needs_object_center = (md.mode == 'ELLIPSOID')
+        has_object_center = bool(md.object_center)
+
+        row = layout.row(align=True)
+        row.prop(md, "mode", expand=True)
+
+        split = layout.split()
+
+        col = split.column()
+        col.active = needs_object_center
+        col.prop(md, "object_center", text="")
+        row = col.row()
+        row.active = not has_object_center
+        row.prop(md, "use_bbox_center")
+
+        col = split.column()
+        row = col.row()
+        row.active = needs_object_geom
+        row.prop(md, "object_geometry", text="")
+
+        row = col.row(align=True)
+        row.prop_search(md, "vertex_group", ob, "vertex_groups", text="")
+        sub = row.row(align=True)
+        sub.active = has_vgroup
+        sub.prop(md, "use_invert_vertex_group", text="", icon='ARROW_LEFTRIGHT')
+
 
 if __name__ == "__main__":  # only for live edit.
     bpy.utils.register_module(__name__)
diff --git a/source/blender/editors/space_outliner/outliner_draw.c b/source/blender/editors/space_outliner/outliner_draw.c
index 7eb9095..d370ec0 100644
--- a/source/blender/editors/space_outliner/outliner_draw.c
+++ b/source/blender/editors/space_outliner/outliner_draw.c
@@ -990,6 +990,8 @@ static void tselem_draw_icon(uiBlock *block, int xmax, float x, float y, TreeSto
 						UI_icon_draw(x, y, ICON_MOD_WIREFRAME); break;
 					case eModifierType_LaplacianDeform:
 						UI_icon_draw(x, y, ICON_MOD_MESHDEFORM); break;  /* XXX, needs own icon */
+					case eModifierType_SetSplitNormal:
+						UI_icon_draw(x, y, ICON_MOD_VERTEX_WEIGHT); break;  /* XXX, needs own icon */
 					/* Default */
 					case eModifierType_None:
 					case eModifierType_ShapeKey:
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 2bd33ae..afa6582 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -82,6 +82,7 @@ typedef enum ModifierType {
 	eModifierType_MeshCache         = 46,
 	eModifierType_LaplacianDeform   = 47,
 	eModifierType_Wireframe         = 48,
+	eModifierType_SetSplitNormal    = 49,
 	NUM_MODIFIER_TYPES
 } ModifierType;
 
@@ -1365,6 +1366,28 @@ enum {
 	MOD_WIREFRAME_CREASE        = (1 << 5),
 };
 
+/* Set Split Normals modifier */
+typedef struct SetSplitNormalModifierData {
+	ModifierData modifier;
+	char defgrp_name[64];  /* MAX_VGROUP_NAME */
+	struct Object *object_geometry;  /* Source of normals. */
+	struct Object *object_center;    /* Center of box or ellipsoid. */
+	short flags;
+	short mode;
+	short pad[2];
+} SetSplitNormalModifierData;
+
+/* SetSplitNormalModifierData.flags */
+enum {
+	MOD_SETSPLITNORMAL_INVERT_VGROUP = (1 << 0),
+	MOD_SETSPLITNORMAL_CENTER_BBOX   = (1 << 1),
+};
+
+/* SetSplitNormalModifierData.mode */
+enum {
+	MOD_SETSPLITNORMAL_ELLIPSOID    = 0,
+	MOD_SETSPLITNORMAL_OBJECT       = 1,
+};
 
 
 #endif  /* __DNA_MODIFIER_TYPES_H__ */
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index ba2dd8b..9138dc1 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -490,6 +490,7 @@ extern StructRNA RNA_SequenceEditor;
 extern StructRNA RNA_SequenceElement;
 extern StructRNA RNA_SequenceProxy;
 extern StructRNA RNA_SequenceTransform;
+extern StructRNA RNA_SetSplitNormalModifier;
 extern StructRNA RNA_ShaderNode;
 extern StructRNA RNA_ShaderNodeCameraData;
 extern StructRNA RNA_ShaderNodeCombineRGB;
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index fb76010..32c8f80 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -64,6 +64,7 @@ EnumPropertyItem modifier_type_items[] = {
 	{eModifierType_WeightVGMix, "VERTEX_WEIGHT_MIX", ICON_MOD_VERTEX_WEIGHT, "Vertex Weight Mix", ""},
 	{eModifierType_WeightVGProximity, "VERTEX_WEIGHT_PROXIMITY", ICON_MOD_VERTEX_WEIGHT,
 	                                  "Vertex Weight Proximity", ""},
+	{eModifierType_SetSplitNormal, "SET_SPLIT_NORMAL", ICON_MOD_VERTEX_WEIGHT, "Set Split Normals", ""},
 	{0, "", 0, N_("Generate"), ""},
 	{eModifierType_Array, "ARRAY", ICON_MOD_ARRAY, "Array", ""},
 	{eModifierType_Bevel, "BEVEL", ICON_MOD_BEVEL, "Bevel", ""},
@@ -244,6 +245,8 @@ static StructRNA *rna_Modifier_refine(struct PointerRNA *ptr)
 			return &RNA_LaplacianDeformModifier;
 		case eModifierType_Wireframe:
 			return &RNA_WireframeModifier;
+		case eModifierType_SetSplitNormal:
+			return &RNA_SetSplitNormalModifier;
 		/* Default */
 		case eModifierType_None:
 		case eModifierType_ShapeKey:
@@ -317,6 +320,7 @@ RNA_MOD_VGROUP_NAME_SET(LaplacianSmooth, defgrp_name);
 RNA_MOD_VGROUP_NAME_SET(Lattice, name);
 RNA_MOD_VGROUP_NAME_SET(Mask, vgroup);
 RNA_MOD_VGROUP_NAME_SET(MeshDeform, defgrp_name);
+RNA_MOD_VGROUP_NAME_SET(SetSplitNormal, defgrp_name);
 RNA_MOD_VGROUP_NAME_SET(Shrinkwrap, vgroup_name);
 RNA_MOD_VGROUP_NAME_SET(SimpleDeform, vgroup_name);
 RNA_MOD_VGROUP_NAME_SET(Smooth, defgrp_name);
@@ -402,6 +406,8 @@ RNA_MOD_OBJECT_SET(Curve, object, OB_CURVE);
 RNA_MOD_OBJECT_SET(Lattice, object, OB_LATTICE);
 RNA_MOD_OBJECT_SET(Mask, ob_arm, OB_ARMATURE);
 RNA_MOD_OBJECT_SET(MeshDeform, object, OB_MESH);
+RNA_MOD_OBJECT_SET(SetSplitNormal, object_geometry, OB_MESH);
+RNA_MOD_OBJECT_SET(SetSplitNormal, object_center, OB_EMPTY);
 RNA_MOD_OBJECT_SET(Shrinkwrap, target, OB_MESH);
 RNA_MOD_OBJECT_SET(Shrinkwrap, auxTarget, OB_MESH);
 
@@ -3659,6 +3665,59 @@ static void rna_def_modifier_wireframe(BlenderRNA *brna)
 	RNA_def_property_update(prop, 0, "rna_Modifier_update");
 }
 
+static void rna_def_modifier_setsplitnormal(BlenderRNA *brna)
+{
+	StructRNA *srna;
+	PropertyRNA *prop;
+
+	static EnumPropertyItem prop_mode_items[] = {
+		{MOD_SETSPLITNORMAL_ELLIPSOID, "ELLIPSOID", 0, "Ellipsoid",
+		                               "From an ellipsoid (shape defined by the boundbox's dimensions)"},
+		{MOD_SETSPLITNORMAL_OBJECT, "OBJECT", 0, "Object", "From a mesh object"},
+		{0, NULL, 0, NULL, NULL}
+	};
+
+	srna = RNA_def_struct(brna, "SetSplitNormalModifier", "Modifier");
+	RNA_def_struct_ui_text(srna, "Set Split Normal Modifier", "Modifier affecting split normals");
+	RNA_def_struct_sdna(srna, "SetSplitNormalModifierData");
+	RNA_def_struct_ui_icon(srna, ICON_MOD_WIREFRAME);
+
+	prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
+	RNA_def_property_enum_items(prop, prop_mode_items);
+	RNA_def_property_ui_text(prop, "Mode", "How to get our normals");
+	RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+	prop = RNA_def_property(srna, "object_geometry", PROP_POINTER, PROP_NONE);
+	RNA_def_property_ui_text(prop, "Object", "Mesh object to take normals from (use nearest face's normal)");
+	RNA_def_property_pointer_funcs(prop, NULL, "rna_SetSplitNormalModifier_object_geometry_set", NULL, NULL);
+	RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_SELF_CHECK);
+	RNA_def_property_update(prop, 0, "rna_Modifier_dependency_update");
+
+	prop = RNA_def_property(srna, "use_bbox_center", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "flags", MOD_SETSPLITNORMAL_CENTER_BBOX);
+	RNA_def_property_ui_text(prop, "BoundingBox Center",
+	                         "Center ellipsoid on bounding box center instead of own object center");
+	RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+	prop = RNA_def_property(srna, "object_center", PROP_POINTER, PROP_NONE);
+	RNA_def_property_ui_text(prop, "Object Center",
+	                         "Center ellipsoid on this object center (overrides BoundingBox Center when set)");
+	RNA_def_property_pointer_funcs(prop, NULL, "rna_SetSplitNormalModifier_object_center_set", NULL, NULL);
+	RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_SELF_CHECK);
+	RNA_def_property_update(prop, 0, "rna_Modifier_dependency_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 selecting the affected areas");
+	RNA_def_property_string_funcs(prop, NULL, NULL, "rna_SetSplitNormalModifier_defgrp_name_set");
+	RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+	prop = RNA_def_property(srna, "use_invert_vertex_group", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "flags", MOD_SETSPLITNORMAL_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)
 {
 	StructRNA *srna;
@@ -3771,6 +3830,7 @@ void RNA_def_modifier(BlenderRNA *brna)
 	rna_def_modifier_meshcache(brna);
 	rna_def_modifier_laplaciandeform(brna);
 	rna_def_modifier_wireframe(brna);
+	rna_def_modifier_setsplitnormal(brna);
 }
 
 #endif
diff --git a/source/blender/modifiers/CMakeLists.txt b/source/blender/modifiers/CMakeLists.txt
index b841356..c6d1266 100644
--- a/source/blender/modifiers/CMakeLists.txt
+++ b/source/blender/modifiers/CMakeLists.txt
@@ -78,6 +78,7 @@ set(SRC
 	intern/MOD_particlesystem.c
 	intern/MOD_remesh.c
 	intern/MOD_screw.c
+	intern/MOD_setsplitnormal.c
 	intern/MOD_shapekey.c
 	intern/MOD_shrinkwrap.c
 	intern/MOD_simpledeform.c
diff --git a/source/blender/modifiers/MOD_modifiertypes.h b/source/blender/modifiers/MOD_modifiertypes.h
index 9c7c21c..5261afe 100644
--- a/source/blender/modifiers/MOD_modifiertypes.h
+++ b/source/blender/modifiers/MOD_modifiertypes.h
@@ -81,6 +81,7 @@ extern ModifierTypeInfo modifierType_UVWarp;
 extern 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list