How to detect collisions between concave meshes with GImpact?

Post Reply
CesD
Posts: 6
Joined: Sun Jun 10, 2018 4:59 pm

How to detect collisions between concave meshes with GImpact?

Post by CesD »

Hi there!

My setup: Debian 8.8, compiling with g++, using Bullet 2.87. I use the ExampleBrowser app to debug draw everything and therefore use a CommonExampleInterface (CommonMultiBodyBase) to setup and simulate my bodies and world.

I am desperately writing this post after a long time spent looking for answers... Basically, my project is very similar to this: https://pybullet.org/Bullet/phpBB3/viewtopic.php?t=6108. I am modelling a robot (with a btMultyBody instance) and try to study possible collision between its parts. I first tried to represent the different collision shapes (loaded from STL files) with btBvhTriangleMeshShapes, but of course it did'nt work since this representation is made for static objects.

After my research, I basically found to answers :
--> Use btGImpactMeshShapes
--> Use convex decomposition in order to build btCompoundShape

I tried using btGImpactMeshShape:

Code: Select all

#include "../Importers/ImportSTLDemo/LoadMeshFromSTL.h"
#include "../OpenGLWindow/GLInstanceGraphicsShape.h"
...

void MyRobotSim::initPhysics(){
...
	GLInstanceGraphicsShape* glmesh = LoadMeshFromSTL(myStLFilePath);

	if (!glmesh){
		throw BCImportError(component->getFileName());
	}
	
	const GLInstanceVertex& v = glmesh->m_vertices->at(0);
	btAlignedObjectArray<btVector3> convertedVerts;
	convertedVerts.reserve(glmesh->m_numvertices);
	for (int i=0; i<glmesh->m_numvertices; i++)
	{
		convertedVerts.push_back(btVector3(
				glmesh->m_vertices->at(i).xyzw[0],
				glmesh->m_vertices->at(i).xyzw[1],
				glmesh->m_vertices->at(i).xyzw[2]));
	}
	
	btTriangleMesh* meshInterface = new btTriangleMesh();
	for (int i=0; i<glmesh->m_numIndices/3; i++)
	{
		const btVector3& v0 = convertedVerts[glmesh->m_indices->at(i*3)];
		const btVector3& v1 = convertedVerts[glmesh->m_indices->at(i*3+1)];
		const btVector3& v2 = convertedVerts[glmesh->m_indices->at(i*3+2)];
		meshInterface->addTriangle(v0,v1,v2);
	}
	btCollisionShape* shape = new btGImpactMeshShape(meshInterface);
I also added these lines in my initPhysics :

Code: Select all

btCollisionDispatcher *dispatcher = static_cast<btCollisionDispatcher *>(m_dynamicsWorld->getDispatcher());
btGImpactCollisionAlgorithm::registerAlgorithm(dispatcher);
, without any success: Nothing is drawn in the debug drawer and the number of manifolds of my collision dispatcher is always at 0 (though it shouldn't be).

I'm quiet sure that the meshInterface built here is accurate, since when I replace

Code: Select all

btCollisionShape* shape = new btGImpactMeshShape(meshInterface);
by

Code: Select all

btCollisionShape* shape = new btBvhTriangleMesh(meshInterface, true, true);
, the robot is perfectly drawn.

Should there be a difference in the btStridingMeshInterface* that both constructor get in argument? Which one?
I also tried to build directly a btTriangleIndexVertexArray instead of a btTriangleMesh, without success.
Did anyone already face these issue? Does anyone has a working demo using btGImpactMeshShapes? (since there are none in Bullet 2.87)

Regarding the convex decomposition, does anyone have an approach / demo that would help me getting started?

Thank you in advance for your answers!
Last edited by CesD on Mon Jul 23, 2018 11:28 am, edited 2 times in total.
User avatar
godlike
Posts: 20
Joined: Fri Feb 19, 2010 7:09 pm
Contact:

Re: How to detect collisions between concave meshes with GImpact? Help :'(

Post by godlike »

I think you need to call updateBound() on the btGImpactMeshShape just after initialization.
StabInTheDark
Posts: 29
Joined: Sat May 18, 2013 1:36 am
Location: NY
Contact:

Re: How to detect collisions between concave meshes with GImpact? Help :'(

Post by StabInTheDark »

Regarding the convex decomposition, does anyone have an approach / demo that would help me getting started?
I used the VHACD algorithm and a compound collision shape.

http://kmamou.blogspot.com/2014/11/v-ha ... -here.html

Here are my results.

https://www.youtube.com/watch?v=iDQCtVCvzWs
CesD
Posts: 6
Joined: Sun Jun 10, 2018 4:59 pm

Re: How to detect collisions between concave meshes with GImpact? Help :'(

Post by CesD »

godlike wrote: Fri Jul 20, 2018 6:31 am I think you need to call updateBound() on the btGImpactMeshShape just after initialization.
Hi godlike! Thank you for your answer, I called updateBound on my shapes and there is indeed a change in the number of manifolds of the dispatcher so that's a step! Unfortunately, shapes still aren't drawn on my debug drawer... Do you know where this could come from?
StabInTheDark wrote: Sat Jul 21, 2018 3:23 pm I used the VHACD algorithm and a compound collision shape.

http://kmamou.blogspot.com/2014/11/v-ha ... -here.html

Here are my results.

https://www.youtube.com/watch?v=iDQCtVCvzWs
Thank you StabInTheDark, I'll take close look at this!
CesD
Posts: 6
Joined: Sun Jun 10, 2018 4:59 pm

Re: How to detect collisions between concave meshes with GImpact? Help :'(

Post by CesD »

EDIT: The GImpactShapes actually work when calling updateBound; the only thing is that the shapes aren't drawn with default rendering, I don't know why. I used wireframes instead and now I can see my shapes colliding.
Post Reply