[Bf-blender-cvs] [0f26b5d] gooseberry: Removed the solver_index from cloth vertices.

Lukas Tönne noreply at git.blender.org
Wed Jan 21 10:42:05 CET 2015


Commit: 0f26b5d2f591945e3861a2b6941fc2e3a41b45a4
Author: Lukas Tönne
Date:   Wed Jan 21 10:38:54 2015 +0100
Branches: gooseberry
https://developer.blender.org/rB0f26b5d2f591945e3861a2b6941fc2e3a41b45a4

Removed the solver_index from cloth vertices.

This was used as part of the "sim preview" feature, where some amount of
vertices were tagged as disabled in the particle system. Due to the
mind twisting complexity of using the nested cloth modifier to simulate
hair strands indirectly it became necessary to still store all the
vertices, but then disable them again on the solver level ... If this
ever gets reimplemented it must be done in a sane way, avoiding the
cloth step altogether.

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

M	source/blender/blenkernel/BKE_cloth.h
M	source/blender/blenkernel/intern/cloth.c
M	source/blender/blenkernel/intern/collision.c
M	source/blender/blenkernel/intern/particle_system.c
M	source/blender/physics/intern/BPH_mass_spring.cpp

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

diff --git a/source/blender/blenkernel/BKE_cloth.h b/source/blender/blenkernel/BKE_cloth.h
index 534747e..beb4f22 100644
--- a/source/blender/blenkernel/BKE_cloth.h
+++ b/source/blender/blenkernel/BKE_cloth.h
@@ -59,7 +59,6 @@ struct PartDeflect;
 typedef enum eClothVertexFlag {
 	CLOTH_VERT_FLAG_PINNED      = 1,
 	CLOTH_VERT_FLAG_NOSELFCOLL  = 2, /* vertex NOT used for self collisions */
-	CLOTH_VERT_FLAG_EXCLUDE     = 4, /* exclude vertex from the simulation */
 } eClothVertexFlag;
 
 typedef struct ClothHairData {
@@ -110,7 +109,6 @@ typedef struct Cloth {
  */
 typedef struct ClothVertex {
 	int	flags;		/* General flags per vertex.		*/
-	int solver_index;	/* index in internal solver data */
 	float	v[3];		/* The velocity of the point.		*/
 	float	xconst[3];	/* constrained position			*/
 	float	x[3];		/* The current position of this vertex.	*/
diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c
index 72a3587..0b9833e 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -739,7 +739,6 @@ static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm )
 {
 	int i = 0;
 	int j = 0;
-	MVert *mvert;
 	MDeformVert *dvert = NULL;
 	Cloth *clothObj = NULL;
 	int numverts;
@@ -751,7 +750,6 @@ static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm )
 	clothObj = clmd->clothObject;
 
 	numverts = dm->getNumVerts(dm);
-	mvert = dm->getVertArray(dm);
 
 	if (cloth_uses_vgroup(clmd)) {
 		verts = clothObj->verts;
@@ -766,7 +764,6 @@ static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm )
 			/* Reset vertex flags */
 			verts->flags &= ~CLOTH_VERT_FLAG_PINNED;
 			verts->flags &= ~CLOTH_VERT_FLAG_NOSELFCOLL;
-			verts->flags &= ~CLOTH_VERT_FLAG_EXCLUDE;
 
 			dvert = dm->getVertData ( dm, i, CD_MDEFORMVERT );
 			if ( dvert ) {
@@ -820,10 +817,13 @@ static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm )
 	}
 	
 #ifdef USE_PARTICLE_PREVIEW
-	verts = clothObj->verts;
-	for ( i = 0; i < numverts; i++, verts++ ) {
-		if (mvert[i].flag & ME_VERT_TMP_TAG)
-			verts->flags |= CLOTH_VERT_FLAG_EXCLUDE;
+	{
+		MVert *mvert = dm->getVertArray(dm);
+		verts = clothObj->verts;
+		for ( i = 0; i < numverts; i++, verts++ ) {
+			if (mvert[i].flag & ME_VERT_TMP_TAG)
+				verts->flags |= CLOTH_VERT_FLAG_EXCLUDE;
+		}
 	}
 #endif
 }
diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c
index d710493..2633152 100644
--- a/source/blender/blenkernel/intern/collision.c
+++ b/source/blender/blenkernel/intern/collision.c
@@ -1352,14 +1352,7 @@ void cloth_find_point_contacts(Object *ob, ClothModifierData *clmd, float step,
 	unsigned int numcollobj = 0;
 	
 	verts = cloth->verts;
-	
-	numverts = 0;
-	for (i = 0; i < cloth->numverts; ++i) {
-		/* avoid costly collision detection for points that are excluded anyway */
-		if (verts[i].flags & CLOTH_VERT_FLAG_EXCLUDE)
-			continue;
-		++numverts;
-	}
+	numverts = cloth->numverts;
 	
 	////////////////////////////////////////////////////////////
 	// static collisions
@@ -1370,9 +1363,6 @@ void cloth_find_point_contacts(Object *ob, ClothModifierData *clmd, float step,
 	/* fill tree */
 	for (i = 0; i < cloth->numverts; i++) {
 		float co[6];
-		/* avoid costly collision detection for points that are excluded anyway */
-		if (verts[i].flags & CLOTH_VERT_FLAG_EXCLUDE)
-			continue;
 		
 		copy_v3_v3(&co[0*3], verts[i].x);
 		copy_v3_v3(&co[1*3], verts[i].tx);
diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c
index ccb6876..83984e8 100644
--- a/source/blender/blenkernel/intern/particle_system.c
+++ b/source/blender/blenkernel/intern/particle_system.c
@@ -3206,11 +3206,13 @@ static void hair_create_input_dm(ParticleSimulationData *sim, int totpoint, int
 				
 				dvert = hair_set_pinning(dvert, 1.0f);
 				
+#ifdef USE_PARTICLE_PREVIEW
 				/* tag vert if hair is not simulated */
 				if (pa->flag & PARS_HAIR_BLEND)
 					mvert->flag |= ME_VERT_TMP_TAG;
 				else
 					mvert->flag &= ~ME_VERT_TMP_TAG;
+#endif
 				
 				mvert++;
 				medge++;
@@ -3238,11 +3240,13 @@ static void hair_create_input_dm(ParticleSimulationData *sim, int totpoint, int
 			else
 				dvert = hair_set_pinning(dvert, 1.0f);
 			
+#ifdef USE_PARTICLE_PREVIEW
 			/* tag vert if hair is not simulated */
 			if (pa->flag & PARS_HAIR_BLEND)
 				mvert->flag |= ME_VERT_TMP_TAG;
 			else
 				mvert->flag &= ~ME_VERT_TMP_TAG;
+#endif
 			
 			mvert++;
 			if (k)
diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp
index 6c70018..79c3779 100644
--- a/source/blender/physics/intern/BPH_mass_spring.cpp
+++ b/source/blender/physics/intern/BPH_mass_spring.cpp
@@ -53,51 +53,6 @@ extern "C" {
 
 static float I3[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}};
 
-BLI_INLINE bool exclude_vertex(Cloth *cloth, int index)
-{
-	return cloth->verts[index].flags & CLOTH_VERT_FLAG_EXCLUDE;
-}
-
-BLI_INLINE bool exclude_spring(Cloth *cloth, ClothSpring *spring)
-{
-	switch (spring->type) {
-		case CLOTH_SPRING_TYPE_BENDING_ANG:
-			return exclude_vertex(cloth, spring->ij) || exclude_vertex(cloth, spring->kl) || exclude_vertex(cloth, spring->mn);
-			
-		default:
-			return exclude_vertex(cloth, spring->ij) || exclude_vertex(cloth, spring->kl);
-	}
-}
-
-/* Assign a running index to each cloth vertex for mapping to solver data,
- * or -1 if the vertex is to be ignored.
- * Returns the number of solver vertices required.
- */
-static int assign_solver_indices(Cloth *cloth)
-{
-	ClothVertex *vert;
-	int i, si;
-	
-	si = 0;
-	vert = cloth->verts;
-	for (i = 0; i < cloth->numverts; ++i, ++vert) {
-		if (exclude_vertex(cloth, i))
-			vert->solver_index = -1;
-		else {
-			vert->solver_index = si;
-			++si;
-		}
-	}
-	
-	/* first element of solver data matrices is used to store numbers ...
-	 * have to keep at least one
-	 */
-	if (si == 0)
-		si = 1;
-	
-	return si;
-}
-
 /* Number of off-diagonal non-zero matrix blocks.
  * Basically there is one of these for each vertex-vertex interaction.
  */
@@ -108,8 +63,6 @@ static int cloth_count_nondiag_blocks(Cloth *cloth)
 	
 	for (link = cloth->springs; link; link = link->next) {
 		ClothSpring *spring = (ClothSpring *)link->link;
-		if (exclude_spring(cloth, spring))
-			continue;
 		
 		switch (spring->type) {
 			case CLOTH_SPRING_TYPE_BENDING_ANG:
@@ -129,7 +82,7 @@ static int cloth_count_nondiag_blocks(Cloth *cloth)
 
 static struct Implicit_Data *cloth_solver_init_data(Cloth *cloth)
 {
-	int totvert = assign_solver_indices(cloth);
+	int totvert = cloth->numverts;
 	
 	if (cloth->implicit && totvert != BPH_mass_spring_solver_numvert(cloth->implicit)) {
 		BPH_mass_spring_solver_free(cloth->implicit);
@@ -154,10 +107,8 @@ int BPH_cloth_solver_init(Object *UNUSED(ob), ClothModifierData *clmd)
 	
 	vert = cloth->verts;
 	for (i = 0; i < cloth->numverts; ++i, ++vert) {
-		if (vert->solver_index < 0)
-			continue;
-		BPH_mass_spring_set_vertex_mass(id, vert->solver_index, vert->mass);
-		BPH_mass_spring_set_motion_state(id, vert->solver_index, vert->x, ZERO);
+		BPH_mass_spring_set_vertex_mass(id, i, vert->mass);
+		BPH_mass_spring_set_motion_state(id, i, vert->x, ZERO);
 	}
 	
 	return 1;
@@ -183,17 +134,14 @@ void BPH_cloth_solver_set_positions(ClothModifierData *clmd)
 	
 	vert = cloth->verts;
 	for (i = 0; i < numverts; ++i, ++vert) {
-		if (vert->solver_index < 0)
-			continue;
-		
 		if (cloth_hairdata) {
 			ClothHairData *root = &cloth_hairdata[i];
-			BPH_mass_spring_set_rest_transform(id, vert->solver_index, root->rot);
+			BPH_mass_spring_set_rest_transform(id, i, root->rot);
 		}
 		else
-			BPH_mass_spring_set_rest_transform(id, vert->solver_index, I3);
+			BPH_mass_spring_set_rest_transform(id, i, I3);
 		
-		BPH_mass_spring_set_motion_state(id, vert->solver_index, vert->x, vert->v);
+		BPH_mass_spring_set_motion_state(id, i, vert->x, vert->v);
 	}
 }
 
@@ -282,11 +230,9 @@ static void cloth_setup_constraints(ClothModifierData *clmd, ColliderContacts *c
 	
 	vert = cloth->verts;
 	for (v = 0; v < numverts; ++v, ++vert) {
-		if (vert->solver_index < 0)
-			continue;
 		if (vert->flags & CLOTH_VERT_FLAG_PINNED) {
 			/* pinned vertex constraints */
-			BPH_mass_spring_add_constraint_ndof0(data, vert->solver_index, ZERO); /* velocity is defined externally */
+			BPH_mass_spring_add_constraint_ndof0(data, v, ZERO); /* velocity is defined externally */
 		}
 		
 		vert->impulse_count = 0;
@@ -303,8 +249,6 @@ static void cloth_setup_constraints(ClothModifierData *clmd, ColliderContacts *c
 			float restitution = 0.0f;
 			
 			vert = &cloth->verts[v];
-			if (vert->solver_index < 0)
-				continue;
 			/* pinned verts handled separately */
 			if (vert->flags & CLOTH_VERT_FLAG_PINNED)
 				continue;
@@ -319,7 +263,7 @@ static void cloth_setup_constraints(ClothModifierData *clmd, ColliderContacts *c
 			if (!collision_response(clmd, ct->collmd, collpair, dt, restitution, impulse))
 				continue;
 			
-			BPH_mass_spring_add_constraint_ndof2(data, vert->solver_index, collpair->normal, impulse);
+			BPH_mass_spring_add_constraint_ndof2(data, i, collpair->normal, impulse);
 			++vert->impulse_count;
 		}
 	}
@@ -341,9 +285,6 @@ static int UNUSED_FUNCTION(cloth_calc_helper_forces)(Object *UNUSED(ob), ClothMo
 	
 	vert = cloth->verts;
 	for (i=0; i<cloth->numverts; i++, vert++) {
-		if (vert->solver_index < 0)
-			continue;
-		
 		copy_v3_v3(cos[i], vert->tx);
 		
 		if (vert->goal == 1.0f || len_squared_v3v3(initial_cos[i], vert->tx) != 0.0f) {
@@ -362,8 +303,6 @@ static int UNUSED_FUNCTION(cloth_calc_helper_forces)(Object *UNUSED(ob), ClothMo
 			float len, c, l, vec[3];
 			
 			spring = (ClothSpring *)node->link;
-			if (exclude_spring(cloth, spring))
-				continue;
 			if (spring->type != CLOTH_SPRING_TYPE_STRUCTURAL && spring->type != CLOTH_SPRING_TYPE_SHEAR) 
 				continue;
 			
@@ -396,9 +335,6 @@ static int UNUSED_FUNCTION(cloth_calc_helper_forces)(Object *UNUSED(ob), ClothMo
 	for (i=0; i<cloth->numverts; i++, vert++) {
 		float vec[3];
 		
-		if (vert->solver_index < 0)
-			continue;
-		

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list