btConvexHullShape not detecting collisions

Post Reply
jdoriang
Posts: 5
Joined: Fri Jun 16, 2017 2:20 pm

btConvexHullShape not detecting collisions

Post by jdoriang »

Hi

I am experiencing a problem that colliding with certain btConvexHullShapes does not trigger a contact.
The famous suzanne and teapot objects work when using below method. When using a plane with a hole inside it does not work. If that cannot work please let me know. What I want to achieve is flying a spaceship through a hole in a plane and detecting whether it has collided with the edges of the hole in the plane.

Thanks!

Rupert

I am using the following code:

Code: Select all

btConvexHullShape* shape = new btConvexHullShape();
	//btVector3 v;
	for (int i = 0; i < m_Entries[0].vertices.size(); i++) {
		btVector3 v(m_Entries[0].vertices[i].x, m_Entries[0].vertices[i].y, m_Entries[0].vertices[i].z);
		shape->addPoint(v);
	}

	shape->optimizeConvexHull();
	shape->initializePolyhedralFeatures();
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: btConvexHullShape not detecting collisions

Post by drleviathan »

You are using a btConvexHullShape which creates a convex hull around the points that you give it. You can feed a teapot to a convex hull but the result won't collide quite like what the teapot looks like. Search for "teapot convex hull" on images.google.com and you'll see some example images of what is going on.

Once you understand what a "convex hull" is, it should be clear why you can't use btConvexHullShape for a plane with a hole inside. You need to use a different shape type, maybe btBvhTriangleMeshShape or you could break the plane+hole into pieces and use btCompoundShape around several btConvexHullShapes.
jdoriang
Posts: 5
Joined: Fri Jun 16, 2017 2:20 pm

Re: btConvexHullShape not detecting collisions

Post by jdoriang »

Thank you so much. It looks fine in debugdrawer.

Does it still not work if I am using shape->initializePolyhedralFeatures(); ?

Which approach would you recommend as alternative in terms of speed/ease of use ? btBvhTriangleMeshShape or btCompoundShape ?

Thanks

Greetings, Rupert
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: btConvexHullShape not detecting collisions

Post by drleviathan »

The btBvhTriangleMeshShape works surprisingly well in my experience. However, a body that uses such a shape MUST be static (it can't be dynamic or kinematic). Also, that shape works ok if the mesh doesn't have a high triangle density. That is, a small object with all 10k triangles packed into a small space would be a problem, but 10k triangles spread out over a whole terrain might be ok... where "small" means "small relative to the things that are colliding against it".

If the object must be dynamic I recommend building a btCompoundShape however if you're on a tight time budget I'd say avoid that complexity if possible... unless you are good at 3DStudioMax or Blender and know how to convexify the geometry using those tools.
Post Reply