geo6
Posts: 4 Joined: Fri Mar 22, 2019 9:06 pm
Post
by geo6 » Wed Apr 10, 2019 9:20 pm
Was wondering if anyone might have some insight into how one would implement a cloth self collision feature into Bullet's softbody code. After Looking around a bit it looks like I need to implement vertex-face collision tests somewhere in the following function:
Code: Select all
void btSoftBody::defaultCollisionHandler(btSoftBody* psb)
{
const int cf=m_cfg.collisions&psb->m_cfg.collisions;
switch(cf&fCollision::SVSmask)
{
case fCollision::CL_SS:
{
//support self-collision if CL_SELF flag set
if (this!=psb || psb->m_cfg.collisions&fCollision::CL_SELF)
{
btSoftColliders::CollideCL_SS docollide;
docollide.ProcessSoftSoft(this,psb);
}
}
break;
case fCollision::VF_SS:
{
//only self-collision for Cluster, not Vertex-Face yet
if (this!=psb)
{
btSoftColliders::CollideVF_SS docollide;
/* common */
docollide.mrg= getCollisionShape()->getMargin()+
psb->getCollisionShape()->getMargin();
/* psb0 nodes vs psb1 faces */
docollide.psb[0]=this;
docollide.psb[1]=psb;
docollide.psb[0]->m_ndbvt.collideTT( docollide.psb[0]->m_ndbvt.m_root,
docollide.psb[1]->m_fdbvt.m_root,
docollide);
/* psb1 nodes vs psb0 faces */
docollide.psb[0]=psb;
docollide.psb[1]=this;
docollide.psb[0]->m_ndbvt.collideTT( docollide.psb[0]->m_ndbvt.m_root,
docollide.psb[1]->m_fdbvt.m_root,
docollide);
}
}
break;
default:
{
}
}
}
Am I on the right track?
steven
Posts: 83 Joined: Mon Nov 05, 2018 8:16 am
Location: China
Post
by steven » Thu Apr 11, 2019 7:44 am
i find this code below in the function btSoftRigidDynamicsWorld::internalSingleStepSimulation(btScalar timeStep) which seems to process self-collision.
Code: Select all
//self collisions
for (int i = 0; i < m_softBodies.size(); i++)
{
btSoftBody* psb = (btSoftBody*)m_softBodies[i];
psb->defaultCollisionHandler(psb);
}
geo6
Posts: 4 Joined: Fri Mar 22, 2019 9:06 pm
Post
by geo6 » Sat Apr 20, 2019 12:42 am
Yes, these are the outer most functions. Then I traced through the code and found out that after those functions we go through broadphase bounding volume tree and end up doing vertex face collision detection in btSoftBodyInternals.h in this function:
struct CollideVF_SS : btDbvt::ICollide
{
void Process(const btDbvtNode* lnode,
const btDbvtNode* lface)
Just thought I would post this in case anyone else is also working on cloth to cloth collision
steven
Posts: 83 Joined: Mon Nov 05, 2018 8:16 am
Location: China
Post
by steven » Sat Apr 20, 2019 9:05 am
Code: Select all
//only self-collision for Cluster, not Vertex-Face yet
from the comment, it seems that it only support self-collision for Cluster.
Could you try these interfaces to enable the cluster?
Code: Select all
pSoftBody->m_cfg.collisions = btSoftBody::fCollision::CL_SS | btSoftBody::fCollision::CL_RS | btSoftBody::fCollision::CL_SELF;;
btSoftBody::generateClusters(int k,int maxiterations)