Does softbody friction work

Post Reply
User avatar
SynapticBytes
Posts: 74
Joined: Thu Feb 10, 2011 8:27 pm

Does softbody friction work

Post by SynapticBytes »

I'm still struglling with drift when softbodies ashould ahve come to rest. I can almost remove it with a lot of parameter tweaking, but different shapes need vastly different tweaks,

I'm thinking it's maybe just that friction isn't being applies. I've tried searching for kDF parameter references, and it doesn't seem to be used. There are some m_friction values used, but I can't find where they are set. Is this from the collision object attached to the soft body friction setting?

Can anyone verify that friction is used somehow with softbodies, and where it is set?

Thanks.
User avatar
SynapticBytes
Posts: 74
Joined: Thu Feb 10, 2011 8:27 pm

Re: Does softbody friction work

Post by SynapticBytes »

So no one has used friction with softbodies?

Here's the places I can find m_friction referenced in the softbody code, but m_friction is not set from kDF. Can anyone help identify where it comes from? When I debug this code and check these values, they are always 0.

Code: Select all

void				btSoftBody::CJoint::Solve(btScalar dt,btScalar sor)
{
	const btVector3		va=m_bodies[0].velocity(m_rpos[0]);
	const btVector3		vb=m_bodies[1].velocity(m_rpos[1]);
	const btVector3		vrel=va-vb;
	const btScalar		rvac=btDot(vrel,m_normal);
	btSoftBody::Impulse	impulse;
	impulse.m_asVelocity	=	1;
	impulse.m_velocity		=	m_drift;
	if(rvac<0)
	{
		const btVector3	iv=m_normal*rvac;
		const btVector3	fv=vrel-iv;
		impulse.m_velocity	+=	iv+fv*m_friction;
	}
	impulse.m_velocity=m_massmatrix*impulse.m_velocity*sor;
	
	if (m_bodies[0].m_soft==m_bodies[1].m_soft)
	{
		if ((impulse.m_velocity.getX() ==impulse.m_velocity.getX())&&(impulse.m_velocity.getY() ==impulse.m_velocity.getY())&&
			(impulse.m_velocity.getZ() ==impulse.m_velocity.getZ()))
		{
			if (impulse.m_asVelocity)
			{
				if (impulse.m_velocity.length() <m_bodies[0].m_soft->m_maxSelfCollisionImpulse)
				{
					
				} else
				{
					m_bodies[0].applyImpulse(-impulse*m_bodies[0].m_soft->m_selfCollisionImpulseFactor,m_rpos[0]);
					m_bodies[1].applyImpulse( impulse*m_bodies[0].m_soft->m_selfCollisionImpulseFactor,m_rpos[1]);
				}
			}
		}
	} else
	{
		m_bodies[0].applyImpulse(-impulse,m_rpos[0]);
		m_bodies[1].applyImpulse( impulse,m_rpos[1]);
	}
}

Code: Select all

void				btSoftBody::PSolve_SContacts(btSoftBody* psb,btScalar,btScalar ti)
{
	for(int i=0,ni=psb->m_scontacts.size();i<ni;++i)
	{
		const SContact&		c=psb->m_scontacts[i];
		const btVector3&	nr=c.m_normal;
		Node&				n=*c.m_node;
		Face&				f=*c.m_face;
		const btVector3		p=BaryEval(	f.m_n[0]->m_x,
			f.m_n[1]->m_x,
			f.m_n[2]->m_x,
			c.m_weights);
		const btVector3		q=BaryEval(	f.m_n[0]->m_q,
			f.m_n[1]->m_q,
			f.m_n[2]->m_q,
			c.m_weights);											
		const btVector3		vr=(n.m_x-n.m_q)-(p-q);
		btVector3			corr(0,0,0);
		btScalar dot = btDot(vr,nr);
		if(dot<0)
		{
			const btScalar	j=c.m_margin-(btDot(nr,n.m_x)-btDot(nr,p));
			corr+=c.m_normal*j;
		}
		corr			-=	ProjectOnPlane(vr,nr)*c.m_friction;
		n.m_x			+=	corr*c.m_cfm[0];
		f.m_n[0]->m_x	-=	corr*(c.m_cfm[1]*c.m_weights.x());
		f.m_n[1]->m_x	-=	corr*(c.m_cfm[1]*c.m_weights.y());
		f.m_n[2]->m_x	-=	corr*(c.m_cfm[1]*c.m_weights.z());
	}
}
User avatar
SynapticBytes
Posts: 74
Joined: Thu Feb 10, 2011 8:27 pm

Re: Does softbody friction work

Post by SynapticBytes »

This is funny. A year to the day I'm still looking at the same problem, and googling for an answer, I come across my original issue :)

Anyone got any updates? Does kDF do anything, or not?
Post Reply