Best shape for large and detailed world?

User avatar
Carsten
Posts: 14
Joined: Thu Sep 25, 2008 1:36 pm
Location: Germany

Best shape for large and detailed world?

Post by Carsten »

Hello all,

we're currently integrating Bullet (currently using version 2.71) into our Ca3D-Engine. Bullet is awesome and it works very well so that we're making good progress, but as we're not (yet) familiar with all the Bullet implementation details, there is now the question which shapes are best to represent the static part of large and detailed worlds.

More precisely, our static parts are composed of:
  • Heightfields (e.g. 1025*1025 points with a point spacing of 1m, so that the entire size is roughly 1 square kilometer),
  • convex polyhedra ("brushes"), usually several thousand per level,
  • triangle meshes computed from Bezier patches, used for anything curved, can be very big or small, e.g. pipes, handrails, etc., also usually used in hundreds or thousands per level,
  • arbitrary triangle meshes e.g. for detail objects, currently used only rarely.
You can see example screenshots of such a world at http://www.ca3d-engine.de/gallery/20-techdemo - note that all images on this page were taken in the same big world.

We have begun by adding all convex polyhedra as btConvexHullShapes to the dynamics world, relying on the worlds broadphase for spatial hierarchy.
Normally our next step had been to create one instance of btBvhTriangleMeshShape for each triangle mesh in our world, and add that to the collision/dynamics world as well.

To our understanding the broadphase should take care of organizing all these shapes well, for good performance.
However, some posts in this forum mention that one should better add the triangles of all objects of the static world into a single big btBvhTriangleMeshShape.

So our real question is:
Can we keep separate components of the static world in separate shapes (and rely on the broadphase to give optimal performance),
- or -
should we actually put all triangles of all static objects into a single big btBvhTriangleMeshShape (or rather btMultimaterialTriangleMeshShape) instance?

(Or should we employ a completely different strategy for the task? Which approach works best with Bullet?)

We'd be very grateful for your advice!! :-D
rusty
Posts: 25
Joined: Fri Sep 19, 2008 10:23 am

Re: Best shape for large and detailed world?

Post by rusty »

Hi Carsten.

I think you should probably invest a few days in profiling the best method for your static collision. Using either seperate triangle shapes or a multimaterial triangle shape are valid solutions, but the suitabilaty of each one depends on a typical scene.

And this is the sort of thing that's hard to profile in your head! Thinking about it, I can see pros and cons of both methods. I'll list them for you;

btMultimaterialTriangleMeshShape Pros and Cons
  • Pros
  • Possibly smaller memory footprint as memory for containers is in one place
  • Only has to walk the triangle tree one for each moving object
  • Cons
  • In dense scenes, it could be very slow as it may have to reject lots of triangles in the narrow phase.
Multiple btBvhTriangleMeshShape pros and cons
  • Pros
  • Relatively small number of narrow phase checks
  • Good for spare or densely populated scenes
  • Cons
  • Memory footprint could become a problem with a densely populated scene as you create a new container for every triangle mesh
It really depends how big an impact each of the pros and cons has in a typical scene in your engine. So really...I think you should try using both implementations and perform some memory and performance profiling to see which performs better in the worst case scenario.

I hope this helps a little.

lg
rusty
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Best shape for large and detailed world?

Post by Erwin Coumans »

Using fewer large btBvhTriangleMeshShape is best, but there is no problem having a few hundred to a thousand (1000) static triangle meshes. Typically each single btBvhTriangleMeshShape triangle mesh can contain from 1000 to millions of triangles. But there is no reason to merge _every_ static triangle mesh.

In general, the Bullet broadphases should have no problem dealing with 10.000 static+dynamic objects.

The number of vertices in a btConvexHullShape should preferably be reduced to below say 100 vertices. You can automatically perform this reduction using the btShapeHull utility. See Demos\ConvexDecompositionDemo\ConvexDecompositionDemo.cpp for a sample implementation.

Last but not least: consider using the btHeightfieldTerrainShape for heighfields.
Hope this helps,
Erwin
User avatar
Carsten
Posts: 14
Joined: Thu Sep 25, 2008 1:36 pm
Location: Germany

Re: Best shape for large and detailed world?

Post by Carsten »

Hi rusty,

thank you very much for your feedback!
rusty wrote:I think you should probably invest a few days in profiling the best method for your static collision. [...]
Yes, this is what I'll do. I had hoped to reduce the number of test cases beforehand depending on your answers to my questions, but eventually profiling will provide the most definitive insights. :mrgreen:
User avatar
Carsten
Posts: 14
Joined: Thu Sep 25, 2008 1:36 pm
Location: Germany

Re: Best shape for large and detailed world?

Post by Carsten »

Hi Erwin,

thank you very much for your reply!
Erwin Coumans wrote:Using fewer large btBvhTriangleMeshShape is best, but there is no problem having a few hundred to a thousand (1000) static triangle meshes. Typically each single btBvhTriangleMeshShape triangle mesh can contain from 1000 to millions of triangles. But there is no reason to merge _every_ static triangle mesh.

In general, the Bullet broadphases should have no problem dealing with 10.000 static+dynamic objects.
Ok, thanks for clarifying this.
I understand that combining individual triangle shapes in a common btBvhTriangleMeshShape is (much) better than adding the individual triangles to the broadphase, but from some posts we got the impression that the broadphase worked "worse" than the bvh in the btBvhTriangleMeshShape when they recommended to reduce their number as much as possible - thus my initial post.

So unless the number "thousand (1000)" you mentioned above is an absolute limit (probably not), we'll first try to organize things "naturally", that is, adding to the broadphase a "lot" of btBvhTriangleMeshShape, each with "a lot of" triangles. We will also try other setups and profile as suggested by rusty.
Last but not least: consider using the btHeightfieldTerrainShape for heighfields.
We will, but it seems the VehicleDemo prefers using a btBvhTriangleMeshShape over a btHeightfieldTerrainShape even for the terrain? At least the preprocessor #if ... statements are setup to create a btBvhTriangleMeshShape by default.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Best shape for large and detailed world?

Post by Erwin Coumans »

Carsten wrote:So unless the number "thousand (1000)" you mentioned above is an absolute limit (probably not),
There is no lower limit, technically you can create a btBvhTriangleMeshShape consisting of 1 single triangle, but that would be a waste of memory and performance. It is better to use at least 100, or preferably 1000 or more triangles in each btBvhTriangleMeshShape.
Last but not least: consider using the btHeightfieldTerrainShape for heighfields.
We will, but it seems the VehicleDemo prefers using a btBvhTriangleMeshShape over a btHeightfieldTerrainShape even for the terrain? At least the preprocessor #if ... statements are setup to create a btBvhTriangleMeshShape by default.
It was an arbitrary choice, and some releases have the btHeightfieldTerrainShape enabled,so there is no preference intended. Just experiment and find out what works best for you,

Enjoy,
Erwin