# Physics Simulation Forum

 Page 1 of 1 [ 5 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Rigid bodies not colliding with soft bodiesPosted: Thu Dec 08, 2011 7:45 pm

Joined: Sun Nov 13, 2011 10:41 pm
Posts: 5
Hello all,

I'm currently adding Bullet soft bodies to Dynamica as a personal learning exercise (I'll release the code when it's done, along with any documentation that comes out of it). I've made good progress but I'm currently blocked by the fact that soft bodies do not seem to interact with rigid bodies at all inside the plugin. Soft bodies do collide with each other, but not rigid bodies. I was wondering if anyone more familiar with the code might know any "obvious" reasons why this would happen. My soft body object (class bt_soft_body) construction code looks something like this:
Code:
bt_soft_body::bt_soft_body(btSoftBodyWorldInfo &worldInfo, const std::vector<float> &triVertexCoords,
const std::vector<int> &triVertexIndices  )
{
this->numTriangles = triVertexIndices.size() / 3;
this->numVertices = triVertexCoords.size() / 3;
this->triVertCoords = new btScalar[triVertexCoords.size()];
this->triVertIndices = new int[triVertexIndices.size()];

for(int i = 0; i < triVertexCoords.size(); i ++)
{
this->triVertCoords[i] = static_cast<btScalar>(triVertexCoords[i]);

}

for(int i = 0; i < triVertexIndices.size(); i ++)
{
this->triVertIndices[i] = triVertexIndices[i];
}
this->m_body.reset( btSoftBodyHelpers::CreateFromTriMesh(worldInfo, this->triVertCoords, this->triVertIndices, this->numTriangles ));

btSoftBody::Material* pm = this->m_body->appendMaterial();
pm->m_kLST = 0.5;

this->m_body->scale(btVector3(1,1,1));
this->m_body->setTotalMass(50);
this->m_body->generateBendingConstraints(2, pm);
this->m_body->m_cfg.piterations=2;
this->m_body->m_cfg.kDF = 0.5;
this->m_body->generateClusters(50);
this->m_body->m_cfg.collisions += btSoftBody::fCollision::CL_RS;
this->m_body->m_cfg.collisions += btSoftBody::fCollision::CL_SS;
this->m_body->randomizeConstraints();

}

I've modified the bt_solver_t constructor code to this:

Code:
bt_solver_t::bt_solver_t():
m_solver(new btSequentialImpulseConstraintSolver),
m_collisionConfiguration(new btSoftBodyRigidBodyCollisionConfiguration()),
m_dispatcher(new btCollisionDispatcher(m_collisionConfiguration.get())),
m_dynamicsWorld(new btSoftRigidDynamicsWorld(m_dispatcher.get(),
m_solver.get(),
m_collisionConfiguration.get())

),
m_worldInfo()
{

//register algorithm for concave meshes
btGImpactCollisionAlgorithm::registerAlgorithm(m_dispatcher.get());

m_dynamicsWorld->setGravity(btVector3(0, -9.81f, 0));

m_dynamicsWorld->getDispatchInfo().m_enableSPU = true;

bt_debug_draw* dbgDraw = new bt_debug_draw();
m_dynamicsWorld->setDebugDrawer(dbgDraw);

m_worldInfo.m_dispatcher = m_dispatcher.get();
m_worldInfo.m_gravity = m_dynamicsWorld->getGravity();
m_worldInfo.m_sparsesdf.Initialize();

}

m_worldInfo is passed in to the bt_soft_body constructor when adding new soft bodies to the solver.

Thanks in advance for any help.

Top

 Post subject: Re: Rigid bodies not colliding with soft bodiesPosted: Fri Dec 09, 2011 6:54 pm

Joined: Sun Nov 13, 2011 10:41 pm
Posts: 5
I've run a few more searches on this topic in the forum archives and it has come up a few times in the past. See the following for example:

http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?f=9&t=5523&hilit=soft+rigid+collision
http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=23169#p23169

I've played with some of the ideas in the second URL to no avail (but have not tried changing the collision margins yet). Other posts suggest that a problem may arise if a rigid body's position is set either at constructor time or if it is updated later - but which one of these is "correct" is not clear to me. I will try playing with the way object positions are set but there's no cause for optimism so far - hopefully I won't have to halt development .

Top

 Post subject: Re: Rigid bodies not colliding with soft bodiesPosted: Sat Dec 10, 2011 2:34 pm

Joined: Sun Nov 13, 2011 10:41 pm
Posts: 5
It looks like I've managed to fix this. I changed the soft-body creation code to match that in the demo bunny constructor exactly. It now looks like this:

Code:
bt_soft_body::bt_soft_body(btSoftBodyWorldInfo &worldInfo, const std::vector<float> &triVertexCoords,
const std::vector<int> &triVertexIndices  )
{
this->numTriangles = triVertexIndices.size() / 3;
this->numVertices = triVertexCoords.size() / 3;
this->triVertCoords = new btScalar[triVertexCoords.size()];
this->triVertIndices = new int[triVertexIndices.size()];

for(int i = 0; i < triVertexCoords.size(); i ++)
{
this->triVertCoords[i] = static_cast<btScalar>(triVertexCoords[i]);

}

for(int i = 0; i < triVertexIndices.size(); i ++)
{
this->triVertIndices[i] = triVertexIndices[i];
}
this->m_body.reset( btSoftBodyHelpers::CreateFromTriMesh(worldInfo, this->triVertCoords, this->triVertIndices, this->numTriangles));

btSoftBody::Material*   pm=this->m_body->appendMaterial();
pm->m_kLST            =   0.5;
pm->m_flags            -=   btSoftBody::fMaterial::DebugDraw;
this->m_body->generateBendingConstraints(2,pm);
this->m_body->m_cfg.piterations   =   3;
this->m_body->m_cfg.kDF         =   0.5;
this->m_body->scale(btVector3(1,1,1));
this->m_body->setTotalMass(100, true);
this->m_body->randomizeConstraints();

}

I've also updated to the latest Bullet source (as of yesterday). Soft bodies, passive rigid bodies, and active rigid bodies now all seem to be interacting correctly .

Top

 Post subject: Re: Rigid bodies not colliding with soft bodiesPosted: Wed Dec 14, 2011 10:34 pm

Joined: Sun Nov 13, 2011 10:41 pm
Posts: 5
Final word on this :

The "fix" I posted before does not allow soft bodies to interact with each other. After further experimentation I found that the original cause of my problems was the btSoftBody::fCollision::CL_RS flag. When this is added soft bodies actually stop interacting with rigid bodies entirely (I'm guessing that this interacts badly with some other setting somewhere else), and as a result I cannot seem to use soft body - rigid body cluster collisions, though other collision detection methods do work (albeit imperfectly). So I added the cluster generation code along with the btSoftBody::fCollision::CL_SS flag back in. Things seem fine now except that soft-bodies tend to pass through planes after prolonged contact.

Top

 Post subject: Re: Rigid bodies not colliding with soft bodiesPosted: Wed Dec 21, 2011 9:09 am

Joined: Sun Jun 26, 2005 6:43 pm
Posts: 3825
Location: California, USA
The Bullet soft body implementation has several collision options, and not all combinations are compatible/fully implemented.

Generally it is best to check out the demos in Bullet/Demos/SoftDemo.

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 5 posts ]

#### Who is online

Users browsing this forum: No registered users and 3 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ BULLET PHYSICS LIBRARY USERS    General Bullet Physics Support and Feedback    Release Announcements    Applications, Games, Demos or Movies using Bullet PHYSICS AUTHORING TOOLS, SERIALIZATION AND STANDARDS    Physics authoring tools, serialization, standards and related topics RESEARCH AND DEVELOPMENT IN COLLISION DETECTION & PHYSICS. Don't post Bullet support questions here!    Research and development discussion about Collision Detection and Physics Simulation    Links, Papers, Libraries, Demos, Movies, Comparisons       Non-technical forum and license/patent discussion    Career Opportunities