[Bf-blender-cvs] [b6f3db9] hair_immediate_fixes: A couple of defines to disable various influences on the cloth sim for debugging.

Lukas Tönne noreply at git.blender.org
Wed Sep 10 18:56:52 CEST 2014


Commit: b6f3db98c0ca7f5844f75a3ca60261541afaeb28
Author: Lukas Tönne
Date:   Wed Sep 10 16:59:22 2014 +0200
Branches: hair_immediate_fixes
https://developer.blender.org/rBb6f3db98c0ca7f5844f75a3ca60261541afaeb28

A couple of defines to disable various influences on the cloth sim for
debugging.

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

M	source/blender/blenkernel/intern/implicit.c
M	source/blender/blenkernel/intern/implicit.h
M	source/blender/blenkernel/intern/implicit_eigen.cpp

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

diff --git a/source/blender/blenkernel/intern/implicit.c b/source/blender/blenkernel/intern/implicit.c
index 5791b23..597b107 100644
--- a/source/blender/blenkernel/intern/implicit.c
+++ b/source/blender/blenkernel/intern/implicit.c
@@ -1437,6 +1437,7 @@ DO_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s,
 	
 	// calculate force of structural + shear springs
 	if ((s->type & CLOTH_SPRING_TYPE_STRUCTURAL) || (s->type & CLOTH_SPRING_TYPE_SHEAR) || (s->type & CLOTH_SPRING_TYPE_SEWING) ) {
+#ifdef CLOTH_FORCE_SPRING_STRUCTURAL
 		if (length > L || no_compress) {
 			s->flags |= CLOTH_SPRING_FLAG_NEEDED;
 			
@@ -1473,8 +1474,10 @@ DO_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s,
 			dfdv_damp(s->dfdv, dir, clmd->sim_parms->Cdis);
 			
 		}
+#endif
 	}
 	else if (s->type & CLOTH_SPRING_TYPE_GOAL) {
+#ifdef CLOTH_FORCE_SPRING_GOAL
 		float tvect[3];
 		
 		s->flags |= CLOTH_SPRING_FLAG_NEEDED;
@@ -1504,8 +1507,10 @@ DO_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s,
 		// HERE IS THE PROBLEM!!!!
 		// dfdx_spring(s->dfdx, dir, length, 0.0, k);
 		// dfdv_damp(s->dfdv, dir, MIN2(1.0, (clmd->sim_parms->goalfrict/100.0)));
+#endif
 	}
 	else {  /* calculate force of bending springs */
+#ifdef CLOTH_FORCE_SPRING_BEND
 		if (length < L) {
 			s->flags |= CLOTH_SPRING_FLAG_NEEDED;
 			
@@ -1519,6 +1524,7 @@ DO_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s,
 
 			dfdx_spring_type2(s->dfdx, dir, length, L, k, cb);
 		}
+#endif
 	}
 }
 
@@ -2095,30 +2101,23 @@ static void cloth_calc_force(ClothModifierData *clmd, float UNUSED(frame), lfVec
 	unsigned int i	= 0;
 	float 		spring_air 	= clmd->sim_parms->Cvi * 0.01f; /* viscosity of air scaled in percent */
 	float 		gravity[3] = {0.0f, 0.0f, 0.0f};
-	float 		tm2[3][3] 	= {{0}};
 	MFace 		*mfaces 	= cloth->mfaces;
 	unsigned int numverts = cloth->numverts;
 	LinkNode *search;
 	lfVector *winvec;
 	EffectedPoint epoint;
-
-	tm2[0][0] = tm2[1][1] = tm2[2][2] = -spring_air;
 	
+	/* set dFdX jacobi matrix to zero */
+	init_bfmatrix(dFdX, ZERO);
+	init_bfmatrix(dFdV, ZERO);
+
+#ifdef CLOTH_FORCE_GRAVITY
 	/* global acceleration (gravitation) */
 	if (clmd->scene->physics_settings.flag & PHYS_GLOBAL_GRAVITY) {
 		copy_v3_v3(gravity, clmd->scene->physics_settings.gravity);
 		mul_fvector_S(gravity, gravity, 0.001f * clmd->sim_parms->effector_weights->global_gravity); /* scale gravity force */
 	}
-
-	/* set dFdX jacobi matrix to zero */
-	init_bfmatrix(dFdX, ZERO);
-	/* set dFdX jacobi matrix diagonal entries to -spring_air */ 
-	initdiag_bfmatrix(dFdV, tm2);
-
 	init_lfvector(lF, gravity, numverts);
-	
-	hair_volume_forces(clmd, lF, lX, lV, numverts);
-
 	/* multiply lF with mass matrix
 	 * force = mass * acceleration (in this case: gravity)
 	 */
@@ -2127,8 +2126,21 @@ static void cloth_calc_force(ClothModifierData *clmd, float UNUSED(frame), lfVec
 		copy_v3_v3(temp, lF[i]);
 		mul_fmatrix_fvector(lF[i], M[i].m, temp);
 	}
+#else
+	zero_lfvector(lF, numverts);
+#endif
 
+	hair_volume_forces(clmd, lF, lX, lV, numverts);
+
+#ifdef CLOTH_FORCE_DRAG
+	/* set dFdX jacobi matrix diagonal entries to -spring_air */ 
+	for (i = 0; i < numverts; i++) {
+		dFdV[i].m[0][0] -= spring_air;
+		dFdV[i].m[1][1] -= spring_air;
+		dFdV[i].m[2][2] -= spring_air;
+	}
 	submul_lfvectorS(lF, lV, spring_air, numverts);
+#endif
 	
 	/* handle external forces like wind */
 	if (effectors) {
diff --git a/source/blender/blenkernel/intern/implicit.h b/source/blender/blenkernel/intern/implicit.h
index 91c4ebb..4124e52 100644
--- a/source/blender/blenkernel/intern/implicit.h
+++ b/source/blender/blenkernel/intern/implicit.h
@@ -37,6 +37,12 @@
 #define IMPLICIT_SOLVER_EIGEN
 //#define IMPLICIT_SOLVER_BLENDER
 
+#define CLOTH_FORCE_GRAVITY
+#define CLOTH_FORCE_DRAG
+#define CLOTH_FORCE_SPRING_STRUCTURAL
+#define CLOTH_FORCE_SPRING_BEND
+#define CLOTH_FORCE_SPRING_GOAL
+
 #define IMPLICIT_PRINT_SOLVER_INPUT_OUTPUT
 
 BLI_INLINE void implicit_print_matrix_elem(float v)
diff --git a/source/blender/blenkernel/intern/implicit_eigen.cpp b/source/blender/blenkernel/intern/implicit_eigen.cpp
index 03d69a8..4f44df9 100644
--- a/source/blender/blenkernel/intern/implicit_eigen.cpp
+++ b/source/blender/blenkernel/intern/implicit_eigen.cpp
@@ -420,6 +420,7 @@ static void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s, con
 	
 	// calculate force of structural + shear springs
 	if (ELEM(s->type, CLOTH_SPRING_TYPE_STRUCTURAL, CLOTH_SPRING_TYPE_SHEAR, CLOTH_SPRING_TYPE_SEWING)) {
+#ifdef CLOTH_FORCE_SPRING_STRUCTURAL
 		if (length > L || no_compress) {
 			s->flags |= CLOTH_SPRING_FLAG_NEEDED;
 			
@@ -452,8 +453,10 @@ static void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s, con
 			/* VERIFIED */
 			dfdv_damp(s->dfdv, dir, clmd->sim_parms->Cdis * structural_scale);
 		}
+#endif
 	}
 	else if (s->type & CLOTH_SPRING_TYPE_GOAL) {
+#ifdef CLOTH_FORCE_SPRING_GOAL
 		float target[3];
 		
 		s->flags |= CLOTH_SPRING_FLAG_NEEDED;
@@ -480,9 +483,11 @@ static void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s, con
 		// HERE IS THE PROBLEM!!!!
 		// dfdx_spring(s->dfdx, dir, length, 0.0, k);
 		// dfdv_damp(s->dfdv, dir, MIN2(1.0, (clmd->sim_parms->goalfrict/100.0)));
+#endif
 	}
 #if 0
 	else {  /* calculate force of bending springs */
+#ifdef CLOTH_FORCE_SPRING_BEND
 		if (length < L) {
 			s->flags |= CLOTH_SPRING_FLAG_NEEDED;
 			
@@ -496,6 +501,7 @@ static void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s, con
 
 			dfdx_spring_type2(s->dfdx, dir, length, L, k, cb);
 		}
+#endif
 	}
 #endif
 }
@@ -533,13 +539,7 @@ static void cloth_calc_force(ClothModifierData *clmd, lVector &F, lMatrix &dFdX,
 	dFdX.setZero();
 	dFdV.setZero();
 	
-	/* air drag */
-	lMatrix_reserve_elems(dFdV, 1);
-	for (int i = 0; i < numverts; ++i) {
-		madd_v3_v3fl(lVector_v3(F, i), lVector_v3(V, i), -drag);
-		lMatrix_madd_m3(dFdV, I, -drag, i, i);
-	}
-	
+#ifdef CLOTH_FORCE_GRAVITY
 	/* global acceleration (gravitation) */
 	if (clmd->scene->physics_settings.flag & PHYS_GLOBAL_GRAVITY) {
 		/* scale gravity force
@@ -547,12 +547,20 @@ static void cloth_calc_force(ClothModifierData *clmd, lVector &F, lMatrix &dFdX,
 		 */
 		mul_v3_v3fl(gravity, clmd->scene->physics_settings.gravity, 0.001f * clmd->sim_parms->effector_weights->global_gravity);
 	}
-	
-	/* initialize force with gravity */
 	for (int i = 0; i < numverts; ++i) {
 		/* gravitational mass same as inertial mass */
-		mul_v3_v3fl(lVector_v3(F, i), gravity, verts[i].mass);
+		madd_v3_v3fl(lVector_v3(F, i), gravity, verts[i].mass);
+	}
+#endif
+	
+#ifdef CLOTH_FORCE_DRAG
+	/* air drag */
+	lMatrix_reserve_elems(dFdV, 1);
+	for (int i = 0; i < numverts; ++i) {
+		madd_v3_v3fl(lVector_v3(F, i), lVector_v3(V, i), -drag);
+		lMatrix_madd_m3(dFdV, I, -drag, i, i);
 	}
+#endif
 
 #if 0
 	/* Collect forces and derivatives:  F, dFdX, dFdV */




More information about the Bf-blender-cvs mailing list