Collision between rope and soft body mesh

tbreina

31-01-2013 19:07:07

I'm trying to do a needle and thread object that can "sew" into the cloth soft body mesh.

I'm modifying SoftBody Demo #4 (Demos/SoftDemos/SoftDemo.cpp). I've added the soft body mesh from one of the other soft body demos. Then, I changed the box that was hanging from the two ropes to a cone that hangs from one rope. My idea is that the rigid cone would be a first attempt at a needle and it's connected to a rope thread which makes it a good approximation of needle and thread.

The cone seems to collide with the cloth soft body mesh correctly, but the rope just passes straight through the cloth mesh. I've seen other threads suggesting that I need to create a rope of rigid spheres to handle the collision between the rope and the cloth. Does anyone have some code that shows how to do this? Is there any way of making the standard rope from SoftDemo #4 collide correctly with the cloth soft body?

Here's my first attempt at making a rope built with rigid spheres. The problem I have (other than being a newbie to Ogre and Bullet), is that the spheres don't seem to rotate like a rope (maybe I need a 6DOF constraint??) and the whole compound bullet shape doesn't collide with the cloth soft body.

If anyone can provide any help at all, I'd greatly appreciate it.

Thanks.
-Tony


//
// Rope attach
//
static void Init_RopeAttach(SoftDemo* pdemo) // Demo #4
{
//TRACEDEMO
pdemo->m_softBodyWorldInfo.m_sparsesdf.RemoveReferences(0);
struct Functors
{
static btSoftBody* CtorRope(SoftDemo* pdemo,const btVector3& p)
{
btSoftBody* psb=btSoftBodyHelpers::CreateRope(pdemo->m_softBodyWorldInfo,p,p+btVector3(10,0,0),8,1);
psb->setTotalMass(50);
pdemo->getSoftDynamicsWorld()->addSoftBody(psb);
return(psb);
}

static btCompoundShape* CtorRigidRopeShape(const int nSegments, const btScalar width)
{
int i;
btScalar spacing = 0.5, length = 0;

btTransform startTransform;
startTransform.setIdentity();
startTransform.setOrigin(btVector3(0,0,0));

btCompoundShape* ropeShape=new btCompoundShape();

for (i = 0; i < nSegments; i++) {
ropeShape->addChildShape(startTransform,new btSphereShape(width));
startTransform.setOrigin(btVector3(length,0,0));
length += spacing;
}

return(ropeShape);
}

};

btTransform startTransform;
startTransform.setIdentity();
startTransform.setOrigin(btVector3(0,0,0));

//btRigidBody* body=pdemo->localCreateRigidBody(50,startTransform,new btConeShape(0.2, 4));

// Regular ropes
//btSoftBody* psb0=Functors::CtorRope(pdemo,btVector3(0,10,-1));
//btSoftBody* psb1=Functors::CtorRope(pdemo,btVector3(0,10,+1));


//psb0->appendAnchor(psb0->m_nodes.size()-1,body);
//psb1->appendAnchor(psb1->m_nodes.size()-1,body);

// Custom rigid rope of rigid spheres
btCompoundShape* ropeShape= Functors::CtorRigidRopeShape(3, 0.5);

btRigidBody* body=pdemo->localCreateRigidBody(0.1,startTransform,ropeShape);

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),
20,40,
1+2+4+8,
true);

btSoftBody::Material* pm=psb->appendMaterial();
pm->m_kLST = 0.9;
pm->m_flags += btSoftBody::fMaterial::DebugDraw;
psb->m_cfg.kDF = 1;
psb->m_cfg.kSRHR_CL = 1;
psb->m_cfg.kSR_SPLT_CL = 0.5;
psb->m_cfg.collisions = btSoftBody::fCollision::CL_SS + btSoftBody::fCollision::CL_RS;
psb->generateBendingConstraints(2,pm);

psb->getCollisionShape()->setMargin(0.05);
psb->setTotalMass(20);

///pass zero in generateClusters to create cluster for each tetrahedron or triangle
psb->generateClusters(0);

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

}