Bullet Physics - Collision issue when moving triangle mesh

Post Reply
tame
Posts: 3
Joined: Wed May 06, 2015 10:56 am

Bullet Physics - Collision issue when moving triangle mesh

Post by tame »

Hey guys,

I have a robot (btTriangleMeshShape for each component) and a chain of boxes used as a cable, which is anchored on two components of the robot. I want to rotate a robot component and when this happens, I want to twist/ roll the cable on that component. The problem is - when i rotate a robot component, collision does not work anymore with that component.
I cannot use btHullShape because of the lack of accuracy, neither btGimpact because of the complexity of computations (which gives a really unsatisfying performance). I couldn't improve enough any of these two shapes, so that is why I use btTriangleMeshShape and rotate it by code.
Also, I have replaced the btTriangleMeshShape of the rotating component with a simple static box and rotate the box. Using the box shape, collision is working with that box.
So the problem of collision not working is only when trying to rotate a (static) btTriangleMeshShape.
Here is the code I use to rotate the static body, although I don't think it's necessary (it works for box shape, not for triangle mesh shape):

Code: Select all

  btTransform tr = m_dynamicsWorld->getCollisionObjectArray()[7]->getWorldTransform();
	   static float angle = 0.f;
	   angle += 0.1f;
	   tr.setRotation(btQuaternion(btVector3(1, 0, 0), -angle));
	   m_dynamicsWorld->getCollisionObjectArray()[7]->setWorldTransform(tr);

	   m_dynamicsWorld->updateAabbs();
	   m_dynamicsWorld->computeOverlappingPairs();
I have to mention that I've searched the web before and couldn't find any solution and also I'm a newbie on Bullet Physics and any graphic libraries.
Any help would by really apreciated : )
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Bullet Physics - Collision issue when moving triangle me

Post by Erwin Coumans »

You cannot use a btTriangleMeshShape for this purpose. You will have to use some convex decomposition for example using HACD, that generates a btCompoundShape with btConvexHullShape, or btGimpactShape.
tame
Posts: 3
Joined: Wed May 06, 2015 10:56 am

Re: Bullet Physics - Collision issue when moving triangle me

Post by tame »

Hello Erwin,

Thank you for your reply. You have all my consideration for the library you have developed:)
I've already tried those types of shapes you have mentioned. I use Bullet Physics for an offline programming application for industrial robots, so the accuracy and also performance are important. btConvexHullShape is not enough accurate in my case. Gimpact is what I really need, but the problem is that Gimpact has a very slow performance in my project. Can I improve its performance somehow? I couldn't find any related topic, too.

Here is the code I have used for btGimpactShape:

Code: Select all

       btGImpactMeshShape* gimpactShape = new btGImpactMeshShape(testMesh);
		gimpactShape->updateBound();

		btCollisionDispatcher * dispatcher = static_cast<btCollisionDispatcher *>(m_dynamicsWorld->getDispatcher());
		btGImpactCollisionAlgorithm::registerAlgorithm(dispatcher);
If there are any settings that can be made to improve the performance of a btGimpactShape, please, let me now.

Kind regards,
Ramona
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Bullet Physics - Collision issue when moving triangle me

Post by Erwin Coumans »

No, you should not use btGImpactShape, and don't use a single btConvexHullShape.

You can get a very accurate approximation using convex decomposition, using HACD.
This will create multiple convex hulls, gathered in a btCompoundShape.

That is the way to go when using Bullet. Don't waste your time with btGimpactShape.
vipinjs
Posts: 13
Joined: Wed Nov 26, 2014 9:48 am

Re: Bullet Physics - Collision issue when moving triangle me

Post by vipinjs »

Hello Erwin,

Is it possible to get btCompoundShape from a triangle mesh in real time, I meant on the fly.
Right now I am using the following code

Code: Select all

btTriangleIndexVertexArray *indexvertsarrayhuman = new btTriangleIndexVertexArray(AvatarNode.ObjNumInd, indexhuman, 3 * sizeof(int), AvatarNode.ObjNumVerts, vertshuman, sizeof(btScalar)* 3);

TriCollShape = new btGImpactMeshShape(indexvertsarrayhuman);
TriCollShape->updateBound();
btCompoundShape *compshape = new btCompoundShape(false);
compshape = btCreateCompoundFromGimpactShape(TriCollShape, 0.05);
Is this the correct method to create compound shape coz now to create compound shape it is taking more time.

Regards,
vipin
tame
Posts: 3
Joined: Wed May 06, 2015 10:56 am

Re: Bullet Physics - Collision issue when moving triangle me

Post by tame »

Ok, Thank you, Erwin:)
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Bullet Physics - Collision issue when moving triangle me

Post by Erwin Coumans »

Is this the correct method to create compound shape coz now to create compound shape it is taking more time.
No, I suggest not using btGimpactShape at all. It is better to use HACD, see Bullet/Extras/HACD and
this demo (I need to convert it to the new example browser)
https://github.com/bulletphysics/bullet ... onDemo.cpp

or any other convex decomposition, either automatic or manually generated.
vipinjs
Posts: 13
Joined: Wed Nov 26, 2014 9:48 am

Re: Bullet Physics - Collision issue when moving triangle me

Post by vipinjs »

Thanks Erwin :)
Post Reply