[Bf-blender-cvs] [a04e5ab] temp_merge_gooseberry_hair: Cleanup: Removed the unnecessary cloth solver abstraction (there is only one solver anyway), and split some particle cloth functions for clarity.

Lukas Tönne noreply at git.blender.org
Mon Jan 19 20:50:00 CET 2015


Commit: a04e5abbacaac965df7f91f925faf4dcfd400e09
Author: Lukas Tönne
Date:   Mon Jan 19 18:39:41 2015 +0100
Branches: temp_merge_gooseberry_hair
https://developer.blender.org/rBa04e5abbacaac965df7f91f925faf4dcfd400e09

Cleanup: Removed the unnecessary cloth solver abstraction (there is only
one solver anyway), and split some particle cloth functions for clarity.

Conflicts:
	source/blender/blenkernel/BKE_particle.h
	source/blender/blenkernel/intern/particle_system.c
	source/blender/blenloader/intern/versioning_270.c
	source/blender/makesdna/DNA_particle_types.h
	source/blender/makesrna/intern/rna_particle.c

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

M	source/blender/blenkernel/BKE_cloth.h
M	source/blender/blenkernel/intern/cloth.c
M	source/blender/blenkernel/intern/particle_system.c

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

diff --git a/source/blender/blenkernel/BKE_cloth.h b/source/blender/blenkernel/BKE_cloth.h
index 940d8ea..3a9bb9c 100644
--- a/source/blender/blenkernel/BKE_cloth.h
+++ b/source/blender/blenkernel/BKE_cloth.h
@@ -249,25 +249,5 @@ void cloth_parallel_transport_hair_frame(float mat[3][3], const float dir_old[3]
 
 ////////////////////////////////////////////////
 
-
-/* This enum provides the IDs for our solvers. */
-// only one available in the moment
-typedef enum {
-	CM_IMPLICIT = 0,
-} CM_SOLVER_ID;
-
-
-/* This structure defines how to call the solver.
- */
-typedef struct {
-	const char		*name;
-	CM_SOLVER_ID	id;
-	int ( *init ) (struct Object *ob, struct ClothModifierData *clmd );
-	int ( *solver ) (struct Object *ob, float framenr, struct ClothModifierData *clmd, struct ListBase *effectors );
-	void ( *free ) (struct ClothModifierData *clmd );
-}
-CM_SOLVER_DEF;
-
-
 #endif
 
diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c
index a77357f..a8d7d0a 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -51,15 +51,6 @@
 
 // #include "PIL_time.h"  /* timing for debug prints */
 
-/* Our available solvers. */
-// 255 is the magic reserved number, so NEVER try to put 255 solvers in here!
-// 254 = MAX!
-static CM_SOLVER_DEF	solvers [] =
-{
-	{ "Implicit", CM_IMPLICIT, BPH_cloth_solver_init, BPH_cloth_solve, BPH_cloth_solver_free },
-	// { "Implicit C++", CM_IMPLICITCPP, implicitcpp_init, implicitcpp_solver, implicitcpp_free },
-};
-
 /* ********** cloth engine ******* */
 /* Prototypes for internal functions.
  */
@@ -419,8 +410,7 @@ static int do_step_cloth(Object *ob, ClothModifierData *clmd, DerivedMesh *resul
 	// TIMEIT_START(cloth_step)
 
 	/* call the solver. */
-	if (solvers [clmd->sim_parms->solver_type].solver)
-		ret = solvers[clmd->sim_parms->solver_type].solver(ob, framenr, clmd, effectors);
+	ret = BPH_cloth_solve(ob, framenr, clmd, effectors);
 
 	// TIMEIT_END(cloth_step)
 
@@ -615,10 +605,7 @@ void cloth_free_modifier(ClothModifierData *clmd )
 
 	
 	if ( cloth ) {
-		// If our solver provides a free function, call it
-		if ( solvers [clmd->sim_parms->solver_type].free ) {
-			solvers [clmd->sim_parms->solver_type].free ( clmd );
-		}
+		BPH_cloth_solver_free(clmd);
 
 		// Free the verts.
 		if ( cloth->verts != NULL )
@@ -684,10 +671,7 @@ void cloth_free_modifier_extern(ClothModifierData *clmd )
 		if (G.debug_value > 0)
 			printf("cloth_free_modifier_extern in\n");
 
-		// If our solver provides a free function, call it
-		if ( solvers [clmd->sim_parms->solver_type].free ) {
-			solvers [clmd->sim_parms->solver_type].free ( clmd );
-		}
+		BPH_cloth_solver_free(clmd);
 
 		// Free the verts.
 		if ( cloth->verts != NULL )
@@ -965,9 +949,7 @@ static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *d
 	}
 	
 	// init our solver
-	if ( solvers [clmd->sim_parms->solver_type].init ) {
-		solvers [clmd->sim_parms->solver_type].init ( ob, clmd );
-	}
+	BPH_cloth_solver_init(ob, clmd);
 	
 	if (!first)
 		BKE_cloth_solver_set_positions(clmd);
diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c
index 6ebf92e..88df5d3 100644
--- a/source/blender/blenkernel/intern/particle_system.c
+++ b/source/blender/blenkernel/intern/particle_system.c
@@ -4040,32 +4040,34 @@ static MDeformVert *hair_set_pinning(MDeformVert *dvert, float weight)
 	return dvert;
 }
 
-static void do_hair_dynamics(ParticleSimulationData *sim)
+static void hair_create_input_dm(ParticleSimulationData *sim, int totpoint, int totedge, DerivedMesh **r_dm, ClothHairRoot **r_roots)
 {
 	ParticleSystem *psys = sim->psys;
-	DerivedMesh *dm = psys->hair_in_dm;
-	MVert *mvert = NULL;
-	MEdge *medge = NULL;
-	MDeformVert *dvert = NULL;
+	DerivedMesh *dm;
+	ClothHairRoot *roots;
+	MVert *mvert;
+	MEdge *medge;
+	MDeformVert *dvert;
 	HairKey *key;
 	PARTICLE_P;
-	int totpoint = 0;
-	int totedge;
-	int k;
+	int k, hair_index;
 	float hairmat[4][4];
-	float (*deformedVerts)[3];
 	float max_length;
-	bool realloc_roots;
-
-	if (!psys->clmd) {
-		psys->clmd = (ClothModifierData*)modifier_new(eModifierType_Cloth);
-		psys->clmd->sim_parms->goalspring = 0.0f;
-		psys->clmd->sim_parms->vel_damping = 1.0f;
-		psys->clmd->sim_parms->flags |= CLOTH_SIMSETTINGS_FLAG_GOAL|CLOTH_SIMSETTINGS_FLAG_NO_SPRING_COMPRESS;
-		psys->clmd->coll_parms->flags &= ~CLOTH_COLLSETTINGS_FLAG_SELF;
-		psys->clmd->coll_parms->flags |= CLOTH_COLLSETTINGS_FLAG_POINTS;
+	
+	dm = *r_dm;
+	if (!dm) {
+		*r_dm = dm = CDDM_new(totpoint, totedge, 0, 0, 0);
+		DM_add_vert_layer(dm, CD_MDEFORMVERT, CD_CALLOC, NULL);
 	}
-
+	mvert = CDDM_get_verts(dm);
+	medge = CDDM_get_edges(dm);
+	dvert = DM_get_vert_data_layer(dm, CD_MDEFORMVERT);
+	
+	roots = *r_roots;
+	if (!roots) {
+		*r_roots = roots = MEM_mallocN(sizeof(ClothHairRoot) * totpoint, "hair roots");
+	}
+	
 	/* calculate maximum segment length */
 	max_length = 0.0f;
 	LOOP_PARTICLES {
@@ -4075,117 +4077,138 @@ static void do_hair_dynamics(ParticleSimulationData *sim)
 				max_length = length;
 		}
 	}
-
-	/* create a dm from hair vertices */
-	LOOP_PARTICLES
-		totpoint += pa->totkey;
-
-	totedge = totpoint;
-	totpoint += psys->totpart;
-
-	realloc_roots = false; /* whether hair root info array has to be reallocated */
-	if (dm && (totpoint != dm->getNumVerts(dm) || totedge != dm->getNumEdges(dm))) {
-		dm->release(dm);
-		dm = psys->hair_in_dm = NULL;
-		
-		realloc_roots = true;
-	}
-
-	if (!dm) {
-		dm = psys->hair_in_dm = CDDM_new(totpoint, totedge, 0, 0, 0);
-		DM_add_vert_layer(dm, CD_MDEFORMVERT, CD_CALLOC, NULL);
-		
-		realloc_roots = true;
-	}
 	
-	if (!psys->clmd->roots || realloc_roots) {
-		if (psys->clmd->roots)
-			MEM_freeN(psys->clmd->roots);
-		psys->clmd->roots = MEM_mallocN(sizeof(ClothHairRoot) * totpoint, "hair roots");
-	}
-
-	mvert = CDDM_get_verts(dm);
-	medge = CDDM_get_edges(dm);
-	dvert = DM_get_vert_data_layer(dm, CD_MDEFORMVERT);
-
 	psys->clmd->sim_parms->vgroup_mass = 1;
-
+	
 	/* make vgroup for pin roots etc.. */
-	psys->particles->hair_index = 1;
+	hair_index = 1;
 	LOOP_PARTICLES {
 		float root_mat[4][4];
-		bool use_hair = psys_hair_use_simulation(pa, max_length);
-
-		if (p)
-			pa->hair_index = (pa-1)->hair_index + (pa-1)->totkey + 1;
-
+		bool use_hair;
+		
+		pa->hair_index = hair_index;
+		use_hair = psys_hair_use_simulation(pa, max_length);
+		
 		psys_mat_hair_to_object(sim->ob, sim->psmd->dm, psys->part->from, pa, hairmat);
 		mul_m4_m4m4(root_mat, sim->ob->obmat, hairmat);
 		normalize_m4(root_mat);
-
+		
 		for (k=0, key=pa->hair; k<pa->totkey; k++,key++) {
 			ClothHairRoot *root;
+			float *co, *co_next;
+			
+			co = key->co;
+			co_next = (key+1)->co;
 			
 			/* create fake root before actual root to resist bending */
 			if (k==0) {
-				float temp[3];
-				
 				root = &psys->clmd->roots[pa->hair_index - 1];
 				copy_v3_v3(root->loc, root_mat[3]);
 				copy_m3_m4(root->rot, root_mat);
 				
-				sub_v3_v3v3(temp, key->co, (key+1)->co);
-				copy_v3_v3(mvert->co, key->co);
-				add_v3_v3v3(mvert->co, mvert->co, temp);
+				add_v3_v3v3(mvert->co, co, co);
+				sub_v3_v3(mvert->co, co_next);
 				mul_m4_v3(hairmat, mvert->co);
-				mvert++;
-
+				
 				medge->v1 = pa->hair_index - 1;
 				medge->v2 = pa->hair_index;
-				medge++;
-
+				
 				dvert = hair_set_pinning(dvert, 1.0f);
+				
+				mvert++;
+				medge++;
 			}
-
+			
 			/* store root transform in cloth data */
 			root = &psys->clmd->roots[pa->hair_index + k];
 			copy_v3_v3(root->loc, root_mat[3]);
 			copy_m3_m4(root->rot, root_mat);
-
-			copy_v3_v3(mvert->co, key->co);
+			
+			copy_v3_v3(mvert->co, co);
 			mul_m4_v3(hairmat, mvert->co);
-			mvert++;
 			
 			if (k) {
 				medge->v1 = pa->hair_index + k - 1;
 				medge->v2 = pa->hair_index + k;
-				medge++;
 			}
-
+			
 			/* roots and disabled hairs should be 1.0, the rest can be anything from 0.0 to 1.0 */
 			if (use_hair)
 				dvert = hair_set_pinning(dvert, key->weight);
 			else
 				dvert = hair_set_pinning(dvert, 1.0f);
+			
+			mvert++;
+			if (k)
+				medge++;
 		}
+		
+		hair_index += pa->totkey + 1;
 	}
+}
 
+static void do_hair_dynamics(ParticleSimulationData *sim)
+{
+	ParticleSystem *psys = sim->psys;
+	PARTICLE_P;
+	int totpoint;
+	int totedge;
+	float (*deformedVerts)[3];
+	bool realloc_roots;
+	
+	if (!psys->clmd) {
+		psys->clmd = (ClothModifierData*)modifier_new(eModifierType_Cloth);
+		psys->clmd->sim_parms->goalspring = 0.0f;
+		psys->clmd->sim_parms->vel_damping = 1.0f;
+		psys->clmd->sim_parms->flags |= CLOTH_SIMSETTINGS_FLAG_GOAL|CLOTH_SIMSETTINGS_FLAG_NO_SPRING_COMPRESS;
+		psys->clmd->coll_parms->flags &= ~CLOTH_COLLSETTINGS_FLAG_SELF;
+		psys->clmd->coll_parms->flags |= CLOTH_COLLSETTINGS_FLAG_POINTS;
+	}
+	
+	/* count simulated points */
+	totpoint = 0;
+	totedge = 0;
+	LOOP_PARTICLES {
+		/* "out" dm contains all hairs */
+		totedge += pa->totkey;
+		totpoint += pa->totkey + 1; /* +1 for virtual root point */
+	}
+	
+	realloc_roots = false; /* whether hair root info array has to be reallocated */
+	if (psys->hair_in_dm) {
+		DerivedMesh *dm = psys->hair_in_dm;
+		if (totpoint != dm->getNumVerts(dm) || totedge != dm->getNumEdges(dm)) {
+			dm->release(dm);
+			psys->hair_in_dm = NULL;
+			realloc_roots = true;
+		}
+	}
+	
+	if (psys->hair_in_dm || !psys->clmd->roots || realloc_roots) {
+		if (psys->clmd->roots) {
+			MEM_freeN(psys->clmd->roots);
+			psys->clmd->roots = NULL;
+		}
+	}
+	
+	hair_create_input_dm(sim, totpoint, totedge, &psys->hair_in_dm, &psys->clmd->roots);
+	
 	if (psys->hair_out_dm)
 		psys->hair_out_dm->release(psys->hair_out_dm);
-
+	
 	psys->clmd->point_cache = psys->pointcache;
 	psys->clmd->sim_parms->effector_weights = psys->part->effector_weights;
-
-	deformedVerts = MEM_mallocN(sizeof(*deformedVerts) * dm->getNumVerts(dm), "do_hair_dynamics vertexCos");
-	psys->hair_out_dm = CDDM_copy(dm);
+	
+	deformedVerts = MEM_mallocN(sizeof(*deformedVerts) * psys->hair_in_dm->getNumVerts(psys->hair_in_dm), "do_hair_dynamics vertexCos");
+	psys->hair_out_dm = CDDM_copy(psys->hair_in_dm);
 	psys->hair_out_dm->getVertCos(psys->hair_out_dm, deformedVerts);
-
-	clothModifier_d

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list