[Bf-blender-cvs] [0aa1071] hair_system: Added a HairParams struct to collect all the physical parameters of hair simulation in one place.

Lukas Tönne noreply at git.blender.org
Sun Jul 27 19:59:45 CEST 2014


Commit: 0aa1071697e8af3b9374a4a140f7bbec455ab663
Author: Lukas Tönne
Date:   Sun Jul 27 19:53:17 2014 +0200
Branches: hair_system
https://developer.blender.org/rB0aa1071697e8af3b9374a4a140f7bbec455ab663

Added a HairParams struct to collect all the physical parameters of
hair simulation in one place.

This defines user-settable parameters for controlling things like
stretch stiffness, damping, etc. The defaults of these parameters
should give usable results right from the start (possibly with presets),
but tweaking may still be necessary.

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

M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/blenkernel/intern/hair.c
M	source/blender/hair/HAIR_capi.cpp
M	source/blender/hair/HAIR_capi.h
M	source/blender/hair/intern/HAIR_solver.cpp
M	source/blender/hair/intern/HAIR_solver.h
M	source/blender/makesdna/DNA_hair_types.h
M	source/blender/makesrna/intern/rna_hair.c
M	source/blender/modifiers/intern/MOD_hair.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 2e6f884..a5cc30c 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1224,12 +1224,22 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
 
     def HAIR(self, layout, ob, md):
         hsys = md.hair_system
+        params = hsys.params
         col = layout.column()
-
-        col.prop(md, "steps_per_second")
-        col.separator()
+        
         col.prop(hsys, "smooth")
+        
+        col.separator()
+        
+        col.prop(md, "steps_per_second")
+        row = col.row()
+        col2 = row.column()
+        col2.prop(params, "stretch_stiffness")
+        col2 = row.column()
+        col2.prop(params, "stretch_damping")
+        
         col.separator()
+        
         col.operator("hair.copy_from_particles")
 
 
diff --git a/source/blender/blenkernel/intern/hair.c b/source/blender/blenkernel/intern/hair.c
index e9bcdf7..99c764a 100644
--- a/source/blender/blenkernel/intern/hair.c
+++ b/source/blender/blenkernel/intern/hair.c
@@ -42,6 +42,10 @@
 HairSystem *BKE_hairsys_new(void)
 {
 	HairSystem *hsys = MEM_callocN(sizeof(HairSystem), "hair system");
+	
+	hsys->params.stretch_stiffness = 7e6;
+	hsys->params.stretch_damping = 4500;
+	
 	return hsys;
 }
 
diff --git a/source/blender/hair/HAIR_capi.cpp b/source/blender/hair/HAIR_capi.cpp
index 8d8210c..8031f42 100644
--- a/source/blender/hair/HAIR_capi.cpp
+++ b/source/blender/hair/HAIR_capi.cpp
@@ -38,9 +38,9 @@ extern "C" {
 
 using namespace HAIR_NAMESPACE;
 
-struct HAIR_Solver *HAIR_solver_new(void)
+struct HAIR_Solver *HAIR_solver_new(const struct HairParams *params)
 {
-	Solver *solver = new Solver();
+	Solver *solver = new Solver(*params);
 	
 	return (HAIR_Solver *)solver;
 }
diff --git a/source/blender/hair/HAIR_capi.h b/source/blender/hair/HAIR_capi.h
index 64d3764..69536a9 100644
--- a/source/blender/hair/HAIR_capi.h
+++ b/source/blender/hair/HAIR_capi.h
@@ -34,7 +34,7 @@ struct HairSystem;
 struct HAIR_Solver;
 struct HAIR_SmoothingIteratorFloat3;
 
-struct HAIR_Solver *HAIR_solver_new(void);
+struct HAIR_Solver *HAIR_solver_new(const struct HairParams *params);
 void HAIR_solver_free(struct HAIR_Solver *solver);
 void HAIR_solver_init(struct HAIR_Solver *solver, struct HairSystem *hsys);
 void HAIR_solver_step(struct HAIR_Solver *solver, float timestep);
diff --git a/source/blender/hair/intern/HAIR_solver.cpp b/source/blender/hair/intern/HAIR_solver.cpp
index fc76963..9d97cca 100644
--- a/source/blender/hair/intern/HAIR_solver.cpp
+++ b/source/blender/hair/intern/HAIR_solver.cpp
@@ -60,7 +60,8 @@ SolverData::~SolverData()
 		delete[] points;
 }
 
-Solver::Solver() :
+Solver::Solver(const HairParams &params) :
+    m_params(params),
     m_data(NULL)
 {
 }
diff --git a/source/blender/hair/intern/HAIR_solver.h b/source/blender/hair/intern/HAIR_solver.h
index fb222ad..219d6a1 100644
--- a/source/blender/hair/intern/HAIR_solver.h
+++ b/source/blender/hair/intern/HAIR_solver.h
@@ -27,6 +27,10 @@
 #ifndef __HAIR_SOLVER_H__
 #define __HAIR_SOLVER_H__
 
+extern "C" {
+#include "DNA_hair_types.h"
+}
+
 #include "HAIR_curve.h"
 #include "HAIR_memalloc.h"
 
@@ -49,9 +53,11 @@ struct SolverData {
 class Solver
 {
 public:
-	Solver();
+	Solver(const HairParams &params);
 	~Solver();
 	
+	const HairParams &params() const { return m_params; }
+	
 	void init_data(int totcurves, int totpoints);
 	void free_data();
 	SolverData *data() const { return m_data; }
@@ -63,6 +69,7 @@ protected:
 	float3 calc_acceleration(Curve *curve, Point *point, float time, Point::State &state) const;
 	
 private:
+	HairParams m_params;
 	SolverData *m_data;
 
 	HAIR_CXX_CLASS_ALLOC(Solver)
diff --git a/source/blender/makesdna/DNA_hair_types.h b/source/blender/makesdna/DNA_hair_types.h
index ad78787..e5433e3 100644
--- a/source/blender/makesdna/DNA_hair_types.h
+++ b/source/blender/makesdna/DNA_hair_types.h
@@ -46,12 +46,22 @@ typedef struct HairCurve {
 	int pad;
 } HairCurve;
 
+typedef struct HairParams {
+	float stretch_stiffness;
+	float stretch_damping;
+	int pad[2];
+} HairParams;
+
 typedef struct HairSystem {
 	HairCurve *curves;          /* curve data */
 	int totcurves;              /* number of curves */
+	int pad;
+	
+	HairParams params;
 	
 	/* testing */
 	float smooth;
+	int pad2;
 } HairSystem;
 
 #endif
diff --git a/source/blender/makesrna/intern/rna_hair.c b/source/blender/makesrna/intern/rna_hair.c
index e5dfb63..81a5eb3 100644
--- a/source/blender/makesrna/intern/rna_hair.c
+++ b/source/blender/makesrna/intern/rna_hair.c
@@ -52,6 +52,25 @@ static void rna_HairSystem_update(Main *UNUSED(bmain), Scene *UNUSED(scene), Poi
 
 #else
 
+static void rna_def_hair_params(BlenderRNA *brna)
+{
+	StructRNA *srna;
+	PropertyRNA *prop;
+
+	srna = RNA_def_struct(brna, "HairParams", NULL);
+	RNA_def_struct_ui_text(srna, "Hair Parameters", "Hair simulation parameters");
+
+	prop = RNA_def_property(srna, "stretch_stiffness", PROP_FLOAT, PROP_FACTOR);
+	RNA_def_property_float_sdna(prop, NULL, "stretch_stiffness");
+	RNA_def_property_ui_range(prop, 0.0f, 10.0f, 0.1, 2);
+	RNA_def_property_ui_text(prop, "Stretch Stiffness", "");
+
+	prop = RNA_def_property(srna, "stretch_damping", PROP_FLOAT, PROP_FACTOR);
+	RNA_def_property_float_sdna(prop, NULL, "stretch_damping");
+	RNA_def_property_ui_range(prop, 0.0f, 1.0f, 0.05, 3);
+	RNA_def_property_ui_text(prop, "Stretch Damping", "");
+}
+
 static void rna_def_hair_system(BlenderRNA *brna)
 {
 	StructRNA *srna;
@@ -65,10 +84,16 @@ static void rna_def_hair_system(BlenderRNA *brna)
 	RNA_def_property_ui_range(prop, 0.0f, 10.0f, 0.1, 2);
 	RNA_def_property_ui_text(prop, "Smoothing", "Amount of smoothing");
 	RNA_def_property_update(prop, 0, "rna_HairSystem_update");
+
+	prop = RNA_def_property(srna, "params", PROP_POINTER, PROP_NONE);
+	RNA_def_property_pointer_sdna(prop, NULL, "params");
+	RNA_def_property_struct_type(prop, "HairParams");
+	RNA_def_property_ui_text(prop, "Parameters", "Parameters for the hair simulation");
 }
 
 void RNA_def_hair(BlenderRNA *brna)
 {
+	rna_def_hair_params(brna);
 	rna_def_hair_system(brna);
 }
 
diff --git a/source/blender/modifiers/intern/MOD_hair.c b/source/blender/modifiers/intern/MOD_hair.c
index 1394c81..95c8af1 100644
--- a/source/blender/modifiers/intern/MOD_hair.c
+++ b/source/blender/modifiers/intern/MOD_hair.c
@@ -92,7 +92,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob),
 		float dt = 1.0f / (float)hmd->steps_per_second;
 		int s;
 		
-		solver = HAIR_solver_new();
+		solver = HAIR_solver_new(&hsys->params);
 		HAIR_solver_init(solver, hsys);
 		
 		if (num_steps < 10000) {




More information about the Bf-blender-cvs mailing list