[Bf-blender-cvs] [702ae54] alembic: External forces in strand hair simulation.

Lukas Tönne noreply at git.blender.org
Fri Apr 10 10:04:46 CEST 2015


Commit: 702ae54436a5bedd441170806840b1181fb80245
Author: Lukas Tönne
Date:   Fri Apr 10 10:03:48 2015 +0200
Branches: alembic
https://developer.blender.org/rB702ae54436a5bedd441170806840b1181fb80245

External forces in strand hair simulation.

Arbitrary wind force "density" factor has been moved out of the force
function now, so cloth simulation can do this on it's own without
affecting the strand sim.

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

M	source/blender/blenkernel/intern/cache_library.c
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/blenkernel/intern/cache_library.c b/source/blender/blenkernel/intern/cache_library.c
index 4c9446c..f8bf982 100644
--- a/source/blender/blenkernel/intern/cache_library.c
+++ b/source/blender/blenkernel/intern/cache_library.c
@@ -631,6 +631,7 @@ static void hairsim_process(HairSimCacheModifier *hsmd, CacheProcessContext *ctx
 		
 		for (link = dobdata->strands.first; link; link = link->next) {
 			Strands *strands = link->strands;
+			ListBase *effectors;
 			
 			struct Implicit_Data *solver_data;
 			
@@ -638,7 +639,11 @@ static void hairsim_process(HairSimCacheModifier *hsmd, CacheProcessContext *ctx
 			
 			solver_data = BPH_strands_solver_create(strands, &hsmd->sim_params);
 			
-			BPH_strands_solve(strands, mat, solver_data, &hsmd->sim_params, (float)frame, (float)frame_prev, ctx->scene, NULL);
+			effectors = pdInitEffectors(ctx->scene, dobdata->ob, NULL, hsmd->sim_params.effector_weights, true);
+			
+			BPH_strands_solve(strands, mat, solver_data, &hsmd->sim_params, (float)frame, (float)frame_prev, ctx->scene, effectors);
+			
+			pdEndEffectors(&effectors);
 			
 			BPH_mass_spring_solver_free(solver_data);
 		}
diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp
index 84ab4c6..e0ec2c4 100644
--- a/source/blender/physics/intern/BPH_mass_spring.cpp
+++ b/source/blender/physics/intern/BPH_mass_spring.cpp
@@ -508,6 +508,7 @@ static void cloth_calc_force(ClothModifierData *clmd, float UNUSED(frame), ListB
 
 		/* Hair has only edges */
 		if (cloth->numfaces == 0) {
+			const float density = 0.01f; /* XXX arbitrary value, corresponds to effect of air density */
 #if 0
 			ClothHairData *hairdata = clmd->hairdata;
 			ClothHairData *hair_ij, *hair_kl;
@@ -531,10 +532,10 @@ static void cloth_calc_force(ClothModifierData *clmd, float UNUSED(frame), ListB
 			for (i = 0; i < cloth->numverts; i++, vert++) {
 				if (hairdata) {
 					ClothHairData *hair = &hairdata[i];
-					BPH_mass_spring_force_vertex_wind(data, i, hair->radius, winvec);
+					BPH_mass_spring_force_vertex_wind(data, i, hair->radius * density, winvec);
 				}
 				else
-					BPH_mass_spring_force_vertex_wind(data, i, 1.0f, winvec);
+					BPH_mass_spring_force_vertex_wind(data, i, density, winvec);
 			}
 		}
 #endif
@@ -1427,40 +1428,25 @@ static void strands_calc_force(Strands *strands, float space[4][4], HairSimParam
 	BPH_mass_spring_force_drag(data, drag);
 #endif
 	
-#if 0
 	/* handle external forces like wind */
 	if (effectors) {
 		/* cache per-vertex forces to avoid redundant calculation */
-		float (*winvec)[3] = (float (*)[3])MEM_callocN(sizeof(float) * 3 * numverts, "effector forces");
-		for (i = 0; i < cloth->numverts; i++) {
+		float (*ext_forces)[3] = (float (*)[3])MEM_callocN(sizeof(float) * 3 * numverts, "effector forces");
+		for (i = 0; i < numverts; ++i) {
 			float x[3], v[3];
 			EffectedPoint epoint;
 			
 			BPH_mass_spring_get_motion_state(data, i, x, v);
-			pd_point_from_loc(clmd->scene, x, v, i, &epoint);
-			pdDoEffectors(effectors, NULL, clmd->sim_parms->effector_weights, &epoint, winvec[i], NULL);
+			pd_point_from_loc(scene, x, v, i, &epoint);
+			pdDoEffectors(effectors, NULL, params->effector_weights, &epoint, ext_forces[i], NULL);
 		}
 		
-		for (i = 0; i < cloth->numfaces; i++) {
-			MFace *mf = &mfaces[i];
-			BPH_mass_spring_force_face_wind(data, mf->v1, mf->v2, mf->v3, mf->v4, winvec);
+		for (i = 0; i < numverts; ++i) {
+			BPH_mass_spring_force_vertex_wind(data, i, 1.0f, ext_forces);
 		}
 
-		ClothHairData *hairdata = clmd->hairdata;
-		
-		vert = cloth->verts;
-		for (i = 0; i < cloth->numverts; i++, vert++) {
-			if (hairdata) {
-				ClothHairData *hair = &hairdata[i];
-				BPH_mass_spring_force_vertex_wind(data, i, hair->radius, winvec);
-			}
-			else
-				BPH_mass_spring_force_vertex_wind(data, i, 1.0f, winvec);
-		}
-
-		MEM_freeN(winvec);
+		MEM_freeN(ext_forces);
 	}
-#endif
 	
 	/* spring forces */
 	StrandIterator it_strand;
diff --git a/source/blender/physics/intern/implicit.h b/source/blender/physics/intern/implicit.h
index c8e0ed9..fa3b642 100644
--- a/source/blender/physics/intern/implicit.h
+++ b/source/blender/physics/intern/implicit.h
@@ -112,7 +112,7 @@ void BPH_mass_spring_force_face_wind(struct Implicit_Data *data, int v1, int v2,
 /* 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]);
+void BPH_mass_spring_force_vertex_wind(struct Implicit_Data *data, int v, float factor, 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 69666c0..76adfe6 100644
--- a/source/blender/physics/intern/implicit_blender.c
+++ b/source/blender/physics/intern/implicit_blender.c
@@ -1508,15 +1508,13 @@ void BPH_mass_spring_force_edge_wind(Implicit_Data *data, int v1, int v2, float
 	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])
+void BPH_mass_spring_force_vertex_wind(Implicit_Data *data, int v, float factor, 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);
+	mul_v3_v3fl(f, wind, factor);
 	add_v3_v3(data->F[v], f);
 }




More information about the Bf-blender-cvs mailing list