How can i detect that an object is inside another ?
Knowing that if the both mesh intersect every thing is ok my btCollisionObject intersect with the other btCollisionObject.
Ex. I have Two sphere :S1 : R1 < S2 : R2
if both shperes are at O(0,0,0) no collision is detected ? why ? how to tell bullet the mesh that i gave him is a filled mesh ?
I am not using the bounding box : cause my objects can be concave
Object inside Object Collision
Re: Object inside Object Collision
Hello,
How do you know that there is no collision detected? Just because it does not resolve the collision? Are your two spheres constrained and you turned off collision?
Check if really no collision happens using a callback:
http://www.bulletphysics.org/mediawiki- ... d_Triggers
Furthermore, you do know that your concave objects are colliding as if they were convex? You need some convex decomposition in order to get a concave object.
How do you know that there is no collision detected? Just because it does not resolve the collision? Are your two spheres constrained and you turned off collision?
Check if really no collision happens using a callback:
http://www.bulletphysics.org/mediawiki- ... d_Triggers
Furthermore, you do know that your concave objects are colliding as if they were convex? You need some convex decomposition in order to get a concave object.
Re: Object inside Object Collision
Hello, Thanks for response.
PS : I am new to bullet i am just discovering the Bullet World.
I am using GimpactTriangleMesh for concave objects, i don't knwo what is my mesh. My meshes are user input meshes using STL or 3mf Files. And by this way I am not using convex decomposition.
And the code that i am using for collision is :
I am using OSG for 3D, in my scene i have to types of objects :
The out of Build Zone, and my Nodes that i call PI or PartInstances
the line :
cw->getDispatcher()->getNumManifolds();
detectes nothing when the objects are inside each other.
PS : I am new to bullet i am just discovering the Bullet World.
I am using GimpactTriangleMesh for concave objects, i don't knwo what is my mesh. My meshes are user input meshes using STL or 3mf Files. And by this way I am not using convex decomposition.
And the code that i am using for collision is :
I am using OSG for 3D, in my scene i have to types of objects :
The out of Build Zone, and my Nodes that i call PI or PartInstances
Code: Select all
void BulletManager::detectCollision(bool & lastColState, btCollisionWorld * cw)
{
// Disable all collision before starting
for (auto& pair : mBuildInstancesNodeMap)
pair.second->setCollision(false);
// Check if there is Manifolds : if yes : so there are some collision
unsigned int numManifolds = cw->getDispatcher()->getNumManifolds();
if ((numManifolds == 0) && (lastColState == true))
{
lastColState = false; // No Collision
}
else // Collision happend with some elements
{
lastColState = false; // Start with No Collision
for (unsigned int i = 0; i < numManifolds; i++)
{
// Getting each Manifold : Contains the two Bodies that has collisioned
btPersistentManifold* contactManifold = cw->getDispatcher()->getManifoldByIndexInternal(i);
bool outOfBuildDetected = false;
bool piCollisionDetected = false;
osg::ref_ptr<nodes::PartInstanceGroup> firstPI;
osg::ref_ptr<nodes::PartInstanceGroup> secondPI;
/**
* We are using UserIndex to check what type of ogject has been detected
@see bt::BulletObjectUserData enum for different types
be careful a wrong cast could crashes the application
* if the first body is a PI and the second BuildOutOfBoundsTransform or
if the second body is a PI and the first BuildOutOfBoundsTransform
so the Part instance has collided with the out of build geometry
*/
if ((contactManifold->getBody0()->getUserIndex() == bt::BulletObjectUserData::PartInstanceGroup) &&
(contactManifold->getBody1()->getUserIndex() == bt::BulletObjectUserData::BuildOutOfBoundsTransform))
{
firstPI = static_cast<nodes::PartInstanceGroup*>(contactManifold->getBody0()->getUserPointer());
outOfBuildDetected = true;
}
else if ((contactManifold->getBody1()->getUserIndex() == bt::BulletObjectUserData::PartInstanceGroup) &&
(contactManifold->getBody0()->getUserIndex() == bt::BulletObjectUserData::BuildOutOfBoundsTransform))
{
firstPI = static_cast<nodes::PartInstanceGroup*>(contactManifold->getBody1()->getUserPointer());
outOfBuildDetected = true;
}
/*if the both bodies are pi so both of the PIs are collisend each other*/
else if ((contactManifold->getBody0()->getUserIndex() == bt::BulletObjectUserData::PartInstanceGroup) &&
(contactManifold->getBody1()->getUserIndex() == bt::BulletObjectUserData::PartInstanceGroup))
{
firstPI = static_cast<nodes::PartInstanceGroup*>(contactManifold->getBody0()->getUserPointer());
secondPI = static_cast<nodes::PartInstanceGroup*>(contactManifold->getBody1()->getUserPointer());
piCollisionDetected = true;
}
/* Out of build detected */
if (outOfBuildDetected)
{
firstPI->setCollision(true);
lastColState = true;
}
/* PIs are colliding */
else if (piCollisionDetected)
{
if (firstPI != secondPI)
{
firstPI->setCollision(true);
secondPI->setCollision(true);
lastColState = true;
}
}
}
}
#if (defined _DEBUG && defined _BULLET_DEBUG)
{
// Lock before Drawing
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(*mMutex);
if (mDbgDraw)
{
mDbgDraw->BeginDraw();
mBtCollisionWorld->debugDrawWorld();
mDbgDraw->EndDraw();
}
}
#endif // _DEBUG && _BULLET_DEBUG
}
cw->getDispatcher()->getNumManifolds();
detectes nothing when the objects are inside each other.
Re: Object inside Object Collision
I think that is precisely the problem. From an older post, it seems collisions between GImpactTriangleMeshes seem to be unstable (http://www.bulletphysics.org/Bullet/php ... w=previous). Try using HACD for the convex decomposition and use a compoundshape. That should resolve the collision issues. At least that is all I know.
- Erwin Coumans
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
- Contact:
Re: Object inside Object Collision
Indeed, try using the V-HACD to create a convex decomposition, it should work well. Don't waste your time using btGImpactShape.