[Bf-blender-cvs] [db2ac79] master: Radical simplification of the wind effect on hair, since the previous approach does not work very well.

Lukas Tönne noreply at git.blender.org
Tue Jan 20 09:53:14 CET 2015

Commit: db2ac79fc7ca7d65a3e2912b4b6b5f1ec3b911fd
Author: Lukas Tönne
Date:   Thu Dec 18 13:52:31 2014 +0100
Branches: master

Radical simplification of the wind effect on hair, since the previous
approach does not work very well.

Using a cross section estimate still causes large oscillations due to
varying hair force based on angles. It also requires a sensible hair
thickness value (particle radius) which is difficult to control and
visualize at this point.

The new model is based purely on per-vertex forces, which seems to be
much more stable. It's also somewhat justified by the fact that each
hair vertex represents a certain mass.



M	source/blender/physics/intern/BPH_mass_spring.cpp
M	source/blender/physics/intern/implicit.h
M	source/blender/physics/intern/implicit_blender.c


diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp
index e9bf376..9e58a13 100644
--- a/source/blender/physics/intern/BPH_mass_spring.cpp
+++ b/source/blender/physics/intern/BPH_mass_spring.cpp
@@ -497,6 +497,7 @@ static void cloth_calc_force(ClothModifierData *clmd, float UNUSED(frame), ListB
 		/* Hair has only edges */
 		if (cloth->numfaces == 0) {
+#if 0
 			ClothHairData *hairdata = clmd->hairdata;
 			ClothHairData *hair_ij, *hair_kl;
@@ -508,6 +509,16 @@ static void cloth_calc_force(ClothModifierData *clmd, float UNUSED(frame), ListB
 					BPH_mass_spring_force_edge_wind(data, spring->ij, spring->kl, hair_ij->radius, hair_kl->radius, winvec);
+			ClothHairData *hairdata = clmd->hairdata;
+			vert = cloth->verts;
+			for (i = 0; i < cloth->numverts; i++, vert++) {
+				ClothHairData *hair = &hairdata[i];
+				BPH_mass_spring_force_vertex_wind(data, i, hair->radius, winvec);
+			}
diff --git a/source/blender/physics/intern/implicit.h b/source/blender/physics/intern/implicit.h
index 1c9dccb..0e2d12b 100644
--- a/source/blender/physics/intern/implicit.h
+++ b/source/blender/physics/intern/implicit.h
@@ -112,6 +112,8 @@ void BPH_mass_spring_force_extern(struct Implicit_Data *data, int i, const float
 void BPH_mass_spring_force_face_wind(struct Implicit_Data *data, int v1, int v2, int v3, int v4, const float (*winvec)[3]);
 /* Wind force, acting on an edge */
 void BPH_mass_spring_force_edge_wind(struct Implicit_Data *data, int v1, int v2, float radius1, float radius2, const float (*winvec)[3]);
+/* Wind force, acting on a vertex */
+void BPH_mass_spring_force_vertex_wind(struct Implicit_Data *data, int v, float radius, const float (*winvec)[3]);
 /* Linear spring force between two points */
 bool BPH_mass_spring_force_spring_linear(struct Implicit_Data *data, int i, int j, float restlen,
                                          float stiffness, float damping, bool no_compress, float clamp_force,
diff --git a/source/blender/physics/intern/implicit_blender.c b/source/blender/physics/intern/implicit_blender.c
index e632050..9f43e79 100644
--- a/source/blender/physics/intern/implicit_blender.c
+++ b/source/blender/physics/intern/implicit_blender.c
@@ -1493,11 +1493,22 @@ void BPH_mass_spring_force_edge_wind(Implicit_Data *data, int v1, int v2, float
 	add_v3_v3(data->F[v1], f);
 	world_to_root_v3(data, v2, win, winvec[v2]);
-	/* use -length to invert edge direction */
 	edge_wind_vertex(dir, length, radius2, win, f, dfdx, dfdv);
 	add_v3_v3(data->F[v2], f);
+void BPH_mass_spring_force_vertex_wind(Implicit_Data *data, int v, float UNUSED(radius), const float (*winvec)[3])
+	const float density = 0.01f; /* XXX arbitrary value, corresponds to effect of air density */
+	float wind[3];
+	float f[3];
+	world_to_root_v3(data, v, wind, winvec[v]);
+	mul_v3_v3fl(f, wind, density);
+	add_v3_v3(data->F[v], f);
 BLI_INLINE void dfdx_spring(float to[3][3], const float dir[3], float length, float L, float k)
 	// dir is unit length direction, rest is spring's restlength, k is spring constant.

More information about the Bf-blender-cvs mailing list