Question about cluster collision algorithm for cloth

Eaglegor
Posts: 9
Joined: Tue Jun 18, 2013 2:20 pm
Location: Russia, Samara

Question about cluster collision algorithm for cloth

Post by Eaglegor »

Hi everybody!
Hopefully you are not yet much annoyed with my posts )

I'm a bit confused by a behaviour of cloth lying on the box-shaped ground. I could be seen in bullet soft body demos. I modified code of Init_ClusterCollide1 in this manner:

Code: Select all

static void	Init_ClusterCollide1(SoftDemo* pdemo)
{
	const btScalar	s=8;
	btSoftBody*		psb=btSoftBodyHelpers::CreatePatch(	pdemo->m_softBodyWorldInfo,btVector3(-s,0,-s),
		btVector3(+s,0,-s),
		btVector3(-s,0,+s),
		btVector3(+s,0,+s),
		17,17,//9,9,//31,31,
		0,
		true);

	btSoftBody::Material* pm=psb->appendMaterial();


	pm->m_kLST		=	1.0;
	pm->m_flags		-=	btSoftBody::fMaterial::DebugDraw;
	psb->m_cfg.kDF	=	1;
	psb->m_cfg.kSRHR_CL		=	1;
	psb->m_cfg.kSR_SPLT_CL	=	1;
	psb->m_cfg.kSKHR_CL		=	1;
	psb->m_cfg.kSK_SPLT_CL	=	1;

	psb->m_cfg.collisions	=	btSoftBody::fCollision::CL_SS | btSoftBody::fCollision::CL_RS;
	psb->generateBendingConstraints(4,pm);

	psb->randomizeConstraints();

	psb->getCollisionShape()->setMargin(2);
	psb->setTotalMass(1, true);
	
	///pass zero in generateClusters to create  cluster for each tetrahedron or triangle
	//psb->generateClusters(0);
	psb->generateClusters(64);

	pdemo->getSoftDynamicsWorld()->addSoftBody(psb);

	//Ctor_RbUpStack(pdemo,10);
}
When the number of clusters is 64, the behavior is so:
http://youtu.be/qqz9Bzn4TmI

When there are only 3 clusters, I see this:
http://youtu.be/GOPkskRQAm0

I was a bit confused by jerking in 3-clusters case. I want to ask if my understanding of reasons of these jerks is correct.

Let's have a part of cloth with cluster:
Image

It falls on the ground affected by the gravity force. The cluster then gets an impulse to move away from the ground. The impulse, the gravity force and mass-spring forces are applied to vertices of cluster like this:
Image

Then vertices are above the ground and convex cluster shape doesn't collide with ground:
Image

A bit later the lowest vertices hit the ground causing the bottom border of cluster collide with ground:
Image

The cluster gets a new impulse from this collision and applies it to all own vertices (including the ones which are already in air):
Image

Then collided vertices jump in air again, and the next ones hit the ground:
Image

The new impulses are applied to all vertices again:
Image

This process repeats endless for different groups of colliding vertices. This could explain why the corners of cloth are flying in air in the 3-clusters case.

I want to know, if I'm understanding the process correct.

If I don't make a mistake, the solution could be to generate much more clusters but it slows the simulation. And even with generateClusters(0) I see the jerking with smaller amplitude and higher frequency. Is there any way to avoid it?