Soft body and anchors

psquare2
Posts: 2
Joined: Wed Aug 19, 2009 11:52 am

Soft body and anchors

Post by psquare2 »

I would like a certain vertex of a soft body to follow an exact trajectory (e.g. one vertex of a cloth) It seems if I set mass = 0 and manually move it, it causes drifts/errors in my simulation

Next, I set up a rigid kinematic body at the same position as the vertex and appended it as an anchor. I tried setting anchor hardness to 1, but the whole simulation jumps around the point even before I try to move the kinematic body. How do I solve this:

Here's the code from the demos itself:

Code: Select all

static void	Init_ClothAttach(SoftDemo* pdemo)
{
	//TRACEDEMO
	const btScalar	s=4;
	const btScalar	h=6;
	const int		r=9;
	btSoftBody*		psb=btSoftBodyHelpers::CreatePatch(pdemo->m_softBodyWorldInfo,btVector3(-s,h,-s),
		btVector3(+s,h,-s),
		btVector3(-s,h,+s),
		btVector3(+s,h,+s),r,r,4+8,true);
	psb->m_cfg.kAHR = 0.99;
	psb->m_cfg.kCHR = 0;
	psb->m_cfg.kKHR = 0;
	pdemo->getSoftDynamicsWorld()->addSoftBody(psb);

	btTransform startTransform;
	startTransform.setIdentity();
	startTransform.setOrigin(psb->m_nodes[0].m_x);

	for(unsigned int i = 1; i < psb->m_nodes.size(); ++i)
	{
		if (psb->checkLink(&psb->m_nodes[0], &psb->m_nodes[i]));
	}
	
	btRigidBody*		body=pdemo->localCreateRigidBody(0,startTransform,new btSphereShape(0.2));
	psb->appendAnchor(0,body, true);
	body1 = body;
	//pdemo->m_cutting=true;
}
adtpg
Posts: 10
Joined: Wed Aug 05, 2009 6:50 pm

Re: Soft body and anchors

Post by adtpg »

I'm looking into the same thing currently. As far as I can tell there isnt a 'hard anchor' where the point on the cloth won't get expanded upon.

Looking at the solve anchor code :

Code: Select all


void				btSoftBody::PSolve_Anchors(btSoftBody* psb,btScalar kst,btScalar ti)
{
	const btScalar	kAHR=psb->m_cfg.kAHR*kst;
	const btScalar	dt=psb->m_sst.sdt;
	for(int i=0,ni=psb->m_anchors.size();i<ni;++i)
	{
		const Anchor&		a=psb->m_anchors[i];
		const btTransform&	t=a.m_body->getInterpolationWorldTransform();
		Node&				n=*a.m_node;
		const btVector3		wa=t*a.m_local;
		const btVector3		va=a.m_body->getVelocityInLocalPoint(a.m_c1)*dt;
		const btVector3		vb=n.m_x-n.m_q;
		const btVector3		vr=(va-vb)+(wa-n.m_x)*kAHR;
		const btVector3		impulse=a.m_c0*vr;
		n.m_x+=impulse*a.m_c2;
		a.m_body->applyImpulse(-impulse,a.m_c1);
	}
}

it doesnt seem to set you node to that position, which i would think it would be cool if it did..... Maybe there's a way im not noticing in bullet to do this?

It seems if you set the kAHR to 1.0 and then the piterations to high number like 32 or so, its less noticeable, but it would be nice if it was perfectly attached to the anchor.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Soft body and anchors

Post by Erwin Coumans »

It seems if I set mass = 0 and manually move it, it causes drifts/errors in my simulation
What kind of drift/errors? The mouse picking in the soft body demo can animate both moving nodes and anchors in the corners (in Init_Cloth or Init_ClusterCollide1 demo) by setting the node position and velocity directly:

Code: Select all

	btVector3	delta=targetPosition - softDemo->m_node->m_x;
	softDemo->m_node->m_x = targetPosition;
	softDemo->m_node->m_v+=delta/timeStep;
Did you try that?
Thanks,
Erwin
psquare2
Posts: 2
Joined: Wed Aug 19, 2009 11:52 am

Re: Soft body and anchors

Post by psquare2 »

Thanks Erwin. It seems the drift was related to something on my side (I am sort of 'driving' some of nodes using a canned animation as the 'guide'). There were a minor bug related to how the canned animation is updated.

Will try this again now.