Page 1 of 1

Static Collision with Trimesh Shape Objects fails.

Posted: Fri Sep 11, 2015 12:17 pm
by Amit Nagpal
Hello,
We are trying to get collision between two static objects using bullet library but we are not getting any results.
Please see the following code we have used to get the collision. We are setting up two collision objects, in this case they are cubes colliding with each other.
We are creating the btTriangleMesh using the cube face triangles. and using them to get collision but we are always getting numManifolds zero.

Please let us know if we are doing any thing wrong or we have failed to set any parameter properly.
thanks
With best regards
Amit



getTriangleMesh(btTriangleMesh*& ioTriMesh, Point& pt1, Point& pt2, Point& pt3)
{
btVector3 v0(pt1[0],pt1[1],pt1[2]);
btVector3 v1(pt2[0],pt2[1],pt2[2]);
btVector3 v2(pt3[0],pt3[1],pt3[2]);

// add the triangle to the mesh:
ioTriMesh->addTriangle(v0,v1,v2);
}

void collisionDetection(std::vector<Point>& pointArrayA, Box boundingBoxA, std::vector<Point>& pointArrayB, Box boundingBoxB)
{
btCollisionDispatcher* bt_dispatcher;
btBroadphaseInterface* bt_broadphase;
btCollisionWorld* bt_collision_world;
btCollisionConfiguration* bt_collision_configuration;

double scene_size = 500;
unsigned int max_objects = 20;

bt_collision_configuration = new btDefaultCollisionConfiguration();
bt_dispatcher = new btCollisionDispatcher(bt_collision_configuration);

btScalar sscene_size = scene_size;//(btScalar) cameraWidth;
btVector3 worldAabbMin(-sscene_size, -sscene_size, -sscene_size);
btVector3 worldAabbMax(sscene_size, sscene_size, sscene_size);

bt_broadphase = new bt32BitAxisSweep3(worldAabbMin, worldAabbMax, max_objects, 0, true); // true for disabling raycast accelerator
bt_collision_world = new btCollisionWorld(bt_dispatcher, bt_broadphase, bt_collision_configuration);

btTransform btTransform;
btTransform.setIdentity();

//Creation of collision object 1
btTriangleMesh* triMesh;

for( int i = 0 ; i < pointArrayA.size() ; ++i)
{
getTriangleMesh(triMesh, pointArrayA, pointArrayA[i+1], pointArrayA[i+2])
}

btCollisionShape *mTriMeshShape = new btBvhTriangleMeshShape(triMesh,true);
mTriMeshShape->setMargin(0.01f);

btCollisionObject* Object1 = new btCollisionObject();
Object1->setCollisionShape(mTriMeshShape);
Object1->activate(true);
Object1->setCollisionFlags(btCollisionObject::CF_STATIC_OBJECT);
Object1->setWorldTransform(btTransform);

Point center = PointUtils::subtract(boundingBoxA.ur, boundingBoxA.ll);
PointUtils::divide(center, 2);
Object1->getWorldTransform().setOrigin(btVector3((btScalar) center[0], (btScalar) center[1], (btScalar) center[2]));

bt_collision_world->addCollisionObject(Object1);

//Creation of collision object 2
btTriangleMesh* triMesh2;

for( int i = 0 ; i < pointArrayB.size() ; ++i)
{
getTriangleMesh(triMesh2, pointArrayB, pointArrayB[i+1], pointArrayB[i+2])
}

btCollisionShape *mTriMeshShape2 = new btBvhTriangleMeshShape(triMesh2,true);
mTriMeshShape2->setMargin(0.01f);

btCollisionObject* Object2 = new btCollisionObject();
Object2->setCollisionShape(mTriMeshShape2);
Object2->setCollisionFlags(btCollisionObject::CF_STATIC_OBJECT);
Object2->setWorldTransform(btTransform);

Point center = PointUtils::subtract(boundingBoxB.ur, boundingBoxB.ll);
PointUtils::divide(center, 2);
Object2->getWorldTransform().setOrigin(btVector3((btScalar) center[0], (btScalar) center[1], (btScalar) center[2]));

bt_collision_world->addCollisionObject(Object2);

//Check collision
int num = bt_collision_world->getNumCollisionObjects();
bt_collision_world->performDiscreteCollisionDetection();
int numManifolds = bt_collision_world->getDispatcher()->getNumManifolds();

}

Re: Static Collision with Trimesh Shape Objects fails.

Posted: Fri Sep 11, 2015 3:28 pm
by drleviathan
As an optimization Bullet does not generate contact manifolds between static objects. You need to make at least one of them dynamic or keyframed.

When using btBvhTriangleMeshShape the object MUST be static, so you'll have to use a different shape for any that you make keyframed. See this thread for a flow diagram showing which shapes to use.

Re: Static Collision with Trimesh Shape Objects fails.

Posted: Mon Sep 14, 2015 6:20 am
by Amit Nagpal
Hi drleviathan thanks for your reply.

Is there any other way to get only intersection of two static objects or something i get to know that they are overlapping .

Re: Static Collision with Trimesh Shape Objects fails.

Posted: Mon Sep 14, 2015 4:22 pm
by drleviathan
As per the wiki page about callbacks and triggers you should be able to use the btCollisionWorld::contactPairTest() method. I assume that path is not short circuited by the broadphase collision culling optimizations, but have not actually tried it myself.

Re: Static Collision with Trimesh Shape Objects fails.

Posted: Fri Sep 18, 2015 5:34 am
by nictosi
Have you tried using the ContactTest function? This works for me with bounding boxes