How do I create a shape for a triangle mesh?

shchhan
Posts: 8
Joined: Sat Nov 09, 2013 10:16 pm

How do I create a shape for a triangle mesh?

Post by shchhan »

I'm new to Bullet and have some issues using it. I need a collision shape for a triangle mesh with about 50000 vertices. I searched everywhere and couldn't find any answer. Currently I'm using btTriangleIndexVertexArray for the triangle mesh and btGImpactMeshShape for the collision shape. The rigid body construction is following the "moving concave demo". The physics seems to be working OK when the program starts. But when I shoot a ball at the model, the getOpenGLMatrix function will return me a lot of invalid values. My questions are:
(1) Do I use btTriangleIndexVertexArray and btGImpactMeshShape for the triangle mesh collision? I need accurate collision information for each time step. Is the collision shape a simplified convex hull or anything else? If I should use any other collision shape, what is it?
(2) Do I need to update any information at every time step?

Update: I used btTriangleMesh and it works fine. But the physics is not right. When the object is at rest, it was in a very weired pose. When using btTriangleIndexVertexArray, the resting pose looks right. But when collision with new objects, the simulation totally crushed. I checked the localInertia of the collision shape using both the triangle mesh format, and the results are the same. The simulation is getting more and more confused to me... Can anyone help me with this?
Ateocinico
Posts: 12
Joined: Sat Jun 29, 2013 5:55 pm

Re: How do I create a shape for a triangle mesh?

Post by Ateocinico »

Rendering detail is different from physical detail. Try to simplify as much as possible the physical object.
shchhan
Posts: 8
Joined: Sat Nov 09, 2013 10:16 pm

Re: How do I create a shape for a triangle mesh?

Post by shchhan »

Can you be a little more specific? I do need accurate collision information of a mesh. I don't think I can simply anything. Also, are the classes I used right for meshes? Thanks
c6burns
Posts: 149
Joined: Fri May 24, 2013 6:08 am

Re: How do I create a shape for a triangle mesh?

Post by c6burns »

I think what he means is that generally in a real time application, you don't want to use the render geometry in the physics system unless you have to. If you have an animated character with 50k verts, you don't use that geometry in the physics system. For example, in CryEngine3 by default the engine will skip the generation of physics proxies with > 10k verts. (I know CE3 doesn't use bullet ... I just used it a great deal before moving on to my own framework which does :))

That being said, if you absolutely have to use a complex collision shape, then it is what it is. For my terrain pages, I use a btBvhTriangleMeshShape. But for animated characters, I use primitives aligned to the bones of the skeleton.
shchhan
Posts: 8
Joined: Sat Nov 09, 2013 10:16 pm

Re: How do I create a shape for a triangle mesh?

Post by shchhan »

Then is btGImpactMeshShape the right collision shape to use for triangular mesh? And still can you help me with the questions I posted? I'm still having trouble using the collision shape.
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: How do I create a shape for a triangle mesh?

Post by Flix »

As far as I know, for concave meshes, in general it's better to use btBvhTriangleMeshShape for static meshes and btGImpactMeshShape for moving meshes.
Everybody should know that, as it's clearly written in the Bullet manual and there are tons of forum posts about it.

As usual, some user may have some problem with some (usually big) mesh that's not working, or with performance issues.

These are my suggestions (in random order):
1) Try using the mesh as static (btBvhTriangleMeshShape) and see if the problems disappear (and ensure that the vertices/indices are passed correctly).
2) Purge the mesh from duplicated vertices and/or decimate it. The physic model is usually different from the rendering model, and modelling programs easilly duplicate vertex positions without asking (for example when one vertex is shared by more than one texture or normal).
3) Use convex decomposition for moving shapes (there are a lot of tools available: there's also a btGImpactConvexDecompositionShape that is used in the Bullet GImpact demo AFAIR): decomposed moving compound shapes are usually MUCH faster. (As far as I remember there should be a recent addition somewhere in some Bullet class that can turn a mesh shape into a btCompoundShape with one child shape per triangle: I've never tried it, but it should probably be too slow in your case).
4) Experiment with a tiny mesh first.

For further info, try searching the forum about it.

[Edit]:
5) Ensure that the btStridingMeshInterface instance (or the classes that own/inherit from it like btTriangleIndexVertexArray, btTriangleMesh, and any other custom 'mesh' classes), that is needed by btBvhTriangleMeshShape and btGImpactMeshShape, has the same lifetime as the collision shape (this is a common source of crashes for newbies). Other shape types don't need this requirement.