Commit: 77129b399d21fdd0376efbb0daaf22dbc2abfd90
Author: Lukas Tönne
Date:   Tue Jul 29 15:44:29 2014 +0200
Branches: hair_system
https://developer.blender.org/rB77129b399d21fdd0376efbb0daaf22dbc2abfd90

Bending forces and damping for hair.

This adds some stiffness to hairs along bends, such that the hair does
no longer behave like a chain of freely rotating segments.

Note that there is no bending force on the root segment yet, which means
the hair swivels around the root point without resistance.

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

M       release/scripts/startup/bl_ui/properties_data_modifier.py
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

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

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py 
b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 9d6ebae..2f1fca4 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1235,8 +1235,10 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         row = col.row()
         col2 = row.column()
         col2.prop(params, "stretch_stiffness")
+        col2.prop(params, "bend_stiffness")
         col2 = row.column()
         col2.prop(params, "stretch_damping")
+        col2.prop(params, "bend_damping")
         
         col.separator()
         
diff --git a/source/blender/hair/intern/HAIR_solver.cpp 
b/source/blender/hair/intern/HAIR_solver.cpp
index be2c38c..433fecd 100644
--- a/source/blender/hair/intern/HAIR_solver.cpp
+++ b/source/blender/hair/intern/HAIR_solver.cpp
@@ -64,9 +64,8 @@ SolverData::~SolverData()
 
 static float3 calc_bend(const Frame &frame, const float3 &co0, const float3 
&co1)
 {
-       float3 dir;
-       normalize_v3_v3(dir, co1 - co0);
-       return float3(dot_v3_v3(dir, frame.normal), dot_v3_v3(dir, 
frame.tangent), dot_v3_v3(dir, frame.cotangent));
+       float3 edge = co1 - co0;
+       return float3(dot_v3_v3(edge, frame.normal), dot_v3_v3(edge, 
frame.tangent), dot_v3_v3(edge, frame.cotangent));
 }
 
 void SolverData::precompute_rest_bend()
@@ -150,7 +149,7 @@ float3 Solver::calc_velocity(Curve *curve, Point *point, 
float time, Point::Stat
        return state.vel;
 }
 
-float3 Solver::calc_stretch(Curve *curve, Point *point0, Point *point1, float 
time) const
+float3 Solver::calc_stretch_force(Curve *curve, Point *point0, Point *point1, 
float time) const
 {
        /* XXX this could be cached in SolverData */
        float3 dir;
@@ -164,14 +163,34 @@ float3 Solver::calc_stretch(Curve *curve, Point *point0, 
Point *point1, float ti
        return stretch_force + stretch_damp;
 }
 
-float3 Solver::calc_acceleration(Curve *curve, Point *point, float time, 
float3 prev_stretch, float3 stretch, Point::State &state) const
+#if 0
+float3 Solver::calc_bend_force(Curve *curve, const Frame &frame, Point 
*point0, Point *point1, float time) const
+{
+       float3 bend = calc_bend(frame, point0->cur.co, point1->cur.co);
+       
+       
+}
+#endif
+
+float3 Solver::calc_bend_force(Curve *curve, Point *point0, Point *point1, 
float time) const
+{
+       float3 dir;
+       float3 edge = point1->cur.co - point0->cur.co;
+       normalize_v3_v3(dir, edge);
+       float3 dvel = point1->cur.vel - point0->cur.vel;
+       
+       float3 bend_force = m_params.bend_stiffness * (edge - 
point0->rest_bend);
+       float3 bend_damp = m_params.bend_damping * (dvel - dot_v3_v3(dvel, dir) 
* dir);
+       
+       return bend_force + bend_damp;
+}
+
+float3 Solver::calc_acceleration(Curve *curve, Point *point, float time, 
Point::State &state) const
 {
        float3 acc = float3(0.0f, 0.0f, 0.0f);
        
        acc = acc + m_forces.gravity;
        
-       acc = acc - prev_stretch + stretch;
-       
        return acc;
 }
 
@@ -187,7 +206,7 @@ void Solver::step(float timestep)
        
        for (i = 0, curve = m_data->curves; i < totcurve; ++i, ++curve) {
                int numpoints = curve->totpoints;
-               float3 prev_stretch;
+               float3 stretch, prev_stretch, bend, prev_bend;
                
                /* Root point animation */
                k = 0;
@@ -197,20 +216,37 @@ void Solver::step(float timestep)
                point->next.co = point->cur.co;
                point->next.vel = float3(0.0f, 0.0f, 0.0f);
                
-               float3 stretch = k < numpoints-1 ? calc_stretch(curve, point, 
point+1, time) : float3(0.0f, 0.0f, 0.0f);
+               if (k < numpoints-1) {
+                       stretch = calc_stretch_force(curve, point, point+1, 
time);
+                       bend = calc_bend_force(curve, point, point+1, time);
+               }
+               else {
+                       stretch = float3(0.0f, 0.0f, 0.0f);
+                       bend = float3(0.0f, 0.0f, 0.0f);
+               }
                prev_stretch = stretch;
+               prev_bend = bend;
                
                /* Integrate the remaining free points */
                for (++k, ++point; k < numpoints; ++k, ++point) {
-                       float3 stretch = k < numpoints-1 ? calc_stretch(curve, 
point, point+1, time) : float3(0.0f, 0.0f, 0.0f);
+                       if (k < numpoints-1) {
+                               stretch = calc_stretch_force(curve, point, 
point+1, time);
+                               bend = calc_bend_force(curve, point, point+1, 
time);
+                       }
+                       else {
+                               stretch = float3(0.0f, 0.0f, 0.0f);
+                               bend = float3(0.0f, 0.0f, 0.0f);
+                       }
                        
-                       float3 acc = calc_acceleration(curve, point, time, 
prev_stretch, stretch, point->cur);
+                       float3 acc = calc_acceleration(curve, point, time, 
point->cur);
+                       acc = acc - prev_stretch + stretch - prev_bend + bend;
                        point->next.vel = point->cur.vel + acc * timestep;
                        
                        float3 vel = calc_velocity(curve, point, time, 
point->next);
                        point->next.co = point->cur.co + vel * timestep;
                        
                        prev_stretch = stretch;
+                       prev_bend = bend;
                }
        }
        
diff --git a/source/blender/hair/intern/HAIR_solver.h 
b/source/blender/hair/intern/HAIR_solver.h
index 940d661..8ff5f11 100644
--- a/source/blender/hair/intern/HAIR_solver.h
+++ b/source/blender/hair/intern/HAIR_solver.h
@@ -77,8 +77,9 @@ public:
        
 protected:
        float3 calc_velocity(Curve *curve, Point *point, float time, 
Point::State &state) const;
-       float3 calc_acceleration(Curve *curve, Point *point, float time, float3 
prev_stretch, float3 stretch, Point::State &state) const;
-       float3 calc_stretch(Curve *curve, Point *point0, Point *point1, float 
time) const;
+       float3 calc_acceleration(Curve *curve, Point *point, float time, 
Point::State &state) const;
+       float3 calc_stretch_force(Curve *curve, Point *point0, Point *point1, 
float time) const;
+       float3 calc_bend_force(Curve *curve, Point *point0, Point *point1, 
float time) const;
        
 private:
        HairParams m_params;
diff --git a/source/blender/makesdna/DNA_hair_types.h 
b/source/blender/makesdna/DNA_hair_types.h
index e5433e3..1f93807 100644
--- a/source/blender/makesdna/DNA_hair_types.h
+++ b/source/blender/makesdna/DNA_hair_types.h
@@ -49,7 +49,8 @@ typedef struct HairCurve {
 typedef struct HairParams {
        float stretch_stiffness;
        float stretch_damping;
-       int pad[2];
+       float bend_stiffness;
+       float bend_damping;
 } HairParams;
 
 typedef struct HairSystem {
diff --git a/source/blender/makesrna/intern/rna_hair.c 
b/source/blender/makesrna/intern/rna_hair.c
index 64ee0d0..e5aab41 100644
--- a/source/blender/makesrna/intern/rna_hair.c
+++ b/source/blender/makesrna/intern/rna_hair.c
@@ -71,6 +71,18 @@ static void rna_def_hair_params(BlenderRNA *brna)
        RNA_def_property_range(prop, 0.0f, 1.0e6f);
        RNA_def_property_ui_range(prop, 0.0f, 1.0e5f, 0.1, 2);
        RNA_def_property_ui_text(prop, "Stretch Damping", "");
+
+       prop = RNA_def_property(srna, "bend_stiffness", PROP_FLOAT, 
PROP_FACTOR);
+       RNA_def_property_float_sdna(prop, NULL, "bend_stiffness");
+       RNA_def_property_range(prop, 0.0f, 1.0e9f);
+       RNA_def_property_ui_range(prop, 0.0f, 1.0e8f, 0.1, 2);
+       RNA_def_property_ui_text(prop, "Bend Stiffness", "");
+
+       prop = RNA_def_property(srna, "bend_damping", PROP_FLOAT, PROP_FACTOR);
+       RNA_def_property_float_sdna(prop, NULL, "bend_damping");
+       RNA_def_property_range(prop, 0.0f, 1.0e6f);
+       RNA_def_property_ui_range(prop, 0.0f, 1.0e5f, 0.1, 2);
+       RNA_def_property_ui_text(prop, "Bend Damping", "");
 }
 
 static void rna_def_hair_system(BlenderRNA *brna)

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to