[Bf-blender-cvs] [3cbdb31] alembic: Added the major parameters for the hair simulation.

Lukas Tönne noreply at git.blender.org
Fri Apr 3 15:21:57 CEST 2015


Commit: 3cbdb312559684d4c69a1249e2678c817e122d45
Author: Lukas Tönne
Date:   Fri Apr 3 15:18:52 2015 +0200
Branches: alembic
https://developer.blender.org/rB3cbdb312559684d4c69a1249e2678c817e122d45

Added the major parameters for the hair simulation.

This is basically copied from existing cloth sim settings, with a good
deal of cleanup and sanitization.

Unlike cloth parameters, the damping values are described as relative
to their associated stiffness values for springs. This is much easier
to use in practice and less prone to lead to unstable simulations.
Damping simply works best when the force is in the same order of
magnitude as the stiffness, so having a relative factor requires much
less adjustment on the user side.

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

M	release/scripts/startup/bl_ui/properties_object.py
M	source/blender/blenkernel/intern/cache_library.c
M	source/blender/makesdna/DNA_cache_library_types.h
M	source/blender/makesrna/intern/rna_cache_library.c
M	source/blender/physics/intern/BPH_mass_spring.cpp

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

diff --git a/release/scripts/startup/bl_ui/properties_object.py b/release/scripts/startup/bl_ui/properties_object.py
index 0aa7569..03d9eab 100644
--- a/release/scripts/startup/bl_ui/properties_object.py
+++ b/release/scripts/startup/bl_ui/properties_object.py
@@ -321,7 +321,7 @@ class OBJECT_PT_duplication(ObjectButtonsPanel, Panel):
         row.operator("cachelibrary.remove_modifier", icon='X', text="", emboss=False)
 
         # match enum type to our functions, avoids a lookup table.
-        getattr(self, md.type)(layout, context, cachelib, md)
+        getattr(self, md.type)(context, layout, cachelib, md)
 
     def draw_cachelib(self, context, layout, ob, cachelib, objects):
         col = layout.column()
@@ -421,6 +421,27 @@ class OBJECT_PT_duplication(ObjectButtonsPanel, Panel):
 
     def HAIR_SIMULATION(self, context, layout, cachelib, md):
         params = md.parameters
+
+        col = layout.column()
+        col.prop(params, "substeps")
+        col.prop(params, "timescale")
+        col.prop(params, "mass")
+        col.prop(params, "drag")
+
+        row = col.row(align=True)
+        row.prop(params, "stretch_stiffness")
+        row.prop(params, "stretch_damping")
+
+        row = col.row(align=True)
+        row.prop(params, "bend_stiffness")
+        row.prop(params, "bend_damping")
+
+        row = col.row(align=True)
+        row.prop(params, "goal_stiffness")
+        row.prop(params, "goal_damping")
+
+        layout.separator()
+
         effector_weights_ui(self, context, params.effector_weights, 'HAIR')
 
 
diff --git a/source/blender/blenkernel/intern/cache_library.c b/source/blender/blenkernel/intern/cache_library.c
index 5de4968..5d57d45 100644
--- a/source/blender/blenkernel/intern/cache_library.c
+++ b/source/blender/blenkernel/intern/cache_library.c
@@ -563,6 +563,16 @@ static void hairsim_params_init(HairSimParams *params)
 	params->timescale = 1.0f;
 	params->substeps = 5;
 	
+	params->mass = 0.3f;
+	params->drag = 0.1f;
+	
+	params->stretch_stiffness = 1000.0f;
+	params->stretch_damping = 1.0f;
+	params->bend_stiffness = 100.0f;
+	params->bend_damping = 1.0f;
+	params->goal_stiffness = 0.0f;
+	params->goal_damping = 1.0f;
+	
 	params->effector_weights = BKE_add_effector_weights(NULL);
 }
 
diff --git a/source/blender/makesdna/DNA_cache_library_types.h b/source/blender/makesdna/DNA_cache_library_types.h
index 600175a..dee7032 100644
--- a/source/blender/makesdna/DNA_cache_library_types.h
+++ b/source/blender/makesdna/DNA_cache_library_types.h
@@ -118,6 +118,12 @@ typedef struct HairSimParams {
 	int substeps;
 	
 	struct EffectorWeights *effector_weights;
+	
+	float mass;
+	float drag;
+	float goal_stiffness, goal_damping;
+	float stretch_stiffness, stretch_damping;
+	float bend_stiffness, bend_damping;
 } HairSimParams;
 
 typedef struct HairSimCacheModifier {
diff --git a/source/blender/makesrna/intern/rna_cache_library.c b/source/blender/makesrna/intern/rna_cache_library.c
index aa18e4c..4de85f5 100644
--- a/source/blender/makesrna/intern/rna_cache_library.c
+++ b/source/blender/makesrna/intern/rna_cache_library.c
@@ -176,10 +176,71 @@ static void rna_def_hair_sim_params(BlenderRNA *brna)
 	RNA_def_struct_ui_text(srna, "Hair Simulation Parameters", "Simulation parameters for hair simulation");
 	RNA_def_struct_ui_icon(srna, ICON_HAIR);
 	
+	prop = RNA_def_property(srna, "timescale", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_range(prop, 0.0f, FLT_MAX);
+	RNA_def_property_ui_range(prop, 0.0f, 10.0f, 0.1f, 3);
+	RNA_def_property_ui_text(prop, "Time Scale", "Simulation time scale relative to scene time");
+	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
+	
+	prop = RNA_def_property(srna, "substeps", PROP_INT, PROP_NONE);
+	RNA_def_property_range(prop, 1, 80);
+	RNA_def_property_ui_text(prop, "Substeps", "Simulation steps per frame");
+	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
+	
 	prop = RNA_def_property(srna, "effector_weights", PROP_POINTER, PROP_NONE);
 	RNA_def_property_struct_type(prop, "EffectorWeights");
 	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
 	RNA_def_property_ui_text(prop, "Effector Weights", "");
+	
+	prop = RNA_def_property(srna, "mass", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_range(prop, 0.0f, 10.0f);
+	RNA_def_property_ui_text(prop, "Mass", "Mass of hair vertices");
+	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
+	
+	prop = RNA_def_property(srna, "drag", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_range(prop, 0.0f, FLT_MAX);
+	RNA_def_property_ui_range(prop, 0.0f, 10.0f, 0.1f, 3);
+	RNA_def_property_ui_text(prop, "Drag", "Drag simulating friction with surrounding air");
+	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
+	
+	prop = RNA_def_property(srna, "goal_stiffness", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_range(prop, 0.0f, FLT_MAX);
+	RNA_def_property_ui_range(prop, 0.0f, 10.0f, 0.1f, 3);
+	RNA_def_property_ui_text(prop, "Goal Strength", "Goal spring, pulling vertices toward their rest position");
+	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
+	
+	prop = RNA_def_property(srna, "goal_damping", PROP_FLOAT, PROP_FACTOR);
+	RNA_def_property_range(prop, 0.0f, FLT_MAX);
+	RNA_def_property_ui_range(prop, 0.0f, 1.0f, 0.1f, 3);
+	RNA_def_property_float_default(prop, 1.0f);
+	RNA_def_property_ui_text(prop, "Goal Damping", "Damping factor of goal springs");
+	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
+	
+	prop = RNA_def_property(srna, "stretch_stiffness", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_range(prop, 0.0f, FLT_MAX);
+	RNA_def_property_ui_range(prop, 0.0f, 1000.0f, 0.1f, 3);
+	RNA_def_property_ui_text(prop, "Stretch Stiffness", "Resistence to stretching");
+	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
+	
+	prop = RNA_def_property(srna, "stretch_damping", PROP_FLOAT, PROP_FACTOR);
+	RNA_def_property_range(prop, 0.0f, FLT_MAX);
+	RNA_def_property_ui_range(prop, 0.0f, 1.0f, 0.1f, 3);
+	RNA_def_property_float_default(prop, 1.0f);
+	RNA_def_property_ui_text(prop, "Stretch Damping", "Damping factor of stretch springs");
+	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
+	
+	prop = RNA_def_property(srna, "bend_stiffness", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_range(prop, 0.0f, FLT_MAX);
+	RNA_def_property_ui_range(prop, 0.0f, 1000.0f, 0.1f, 3);
+	RNA_def_property_ui_text(prop, "Bend Stiffness", "Resistance to bending of the rest shape");
+	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
+	
+	prop = RNA_def_property(srna, "bend_damping", PROP_FLOAT, PROP_FACTOR);
+	RNA_def_property_range(prop, 0.0f, FLT_MAX);
+	RNA_def_property_ui_range(prop, 0.0f, 1.0f, 0.1f, 3);
+	RNA_def_property_float_default(prop, 1.0f);
+	RNA_def_property_ui_text(prop, "Bend Damping", "Damping factor of bending springs");
+	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
 }
 
 static void rna_def_cache_modifier_hair_simulation(BlenderRNA *brna)
diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp
index 0bb0b63..6e7fb24 100644
--- a/source/blender/physics/intern/BPH_mass_spring.cpp
+++ b/source/blender/physics/intern/BPH_mass_spring.cpp
@@ -1211,8 +1211,7 @@ static void strands_calc_force(Strands *strands, HairSimParams *params, Implicit
 	/* global acceleration (gravitation) */
 	if (scene->physics_settings.flag & PHYS_GLOBAL_GRAVITY) {
 		/* scale gravity force */
-//		mul_v3_v3fl(gravity, scene->physics_settings.gravity, 0.001f * params->effector_weights->global_gravity);
-		copy_v3_v3(gravity, scene->physics_settings.gravity);
+		mul_v3_v3fl(gravity, scene->physics_settings.gravity, params->effector_weights->global_gravity);
 	}
 	for (i = 0; i < numverts; i++) {
 		float mass = 1.0f; // TODO
@@ -1272,7 +1271,9 @@ static void strands_calc_force(Strands *strands, HairSimParams *params, Implicit
 				int vj = BKE_strand_vertex_iter_vertex_offset(strands, &it_vert_prev);
 				float restlen = len_v3v3(it_vert.vertex->co, it_vert_prev.vertex->co);
 				
-				BPH_mass_spring_force_spring_linear(data, vi, vj, restlen, 1000.0f, 1000.0f, true, 0.0f, NULL, NULL, NULL);
+				float stiffness = params->stretch_stiffness;
+				float damping = stiffness * params->stretch_damping;
+				BPH_mass_spring_force_spring_linear(data, vi, vj, restlen, stiffness, damping, true, 0.0f, NULL, NULL, NULL);
 			}
 		}




More information about the Bf-blender-cvs mailing list