Terrain mesh and collision

kend
Posts: 11
Joined: Thu May 04, 2006 8:36 pm

Terrain mesh and collision

Post by kend »

Hi,

First let me say that I'm no physics expert, just normal game and college math.

I've decided to use Bullet in my game engine and I have a terrain mesh that is split up in many parts. I have taken the base set up from the Concave demo since it also uses a "terrain" mesh.

I have created a separate collision shape, motion state and physics controller for each terrain part and added the controllers to the physics environment. Is this the correct way of doing it?

The mesh parts have a mass of zero and are thus static. No other objects added yet. When I run it, it's very very slow. The time is being used in the collision detection (SimpleBroadphase::FindPair). It seems there are a lot of collisions since the AABB of the mesh parts overlap so I get a lot of collision pairs. What can I do about this? Is there a way to avoid processing these mesh parts since terrain does not collide with itself?

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

Post by Erwin Coumans »

you can add all parts to 1 static shape.
kend
Posts: 11
Joined: Thu May 04, 2006 8:36 pm

Post by kend »

Erwin, can you explain how to add more meshes to a shape? If the vertices of the shapes were in one big array it could be done but they are of course separated into their own structures and objects.
I can't see a way to add more triangle arrays after the BvhTriangleMeshShape object is created. I'm new to bullet so I may very well have missed something.

Ken
Proctoid
Posts: 18
Joined: Fri Apr 21, 2006 3:04 pm
Location: uk

Post by Proctoid »

kend, I'm new to all this too - but have recently done something similiar to what you want to do - lots of individual objects in one hit mesh...

These are the steps i take...

1. create new index and vertex buffers large enough to contain the collision shapes you need in the collision mesh
2. manually fill these buffers with the individual objects you have
(ie. you write functions that append your different individual object types to the new index and vertex buffers)
3. create a new TriangleIndexVertexArray from the newly filled buffers
4. create a new collision object using BvhTriangleMeshShape
5. release unused old collision object

This works so far for me... i would not suggest using this method often as alloc and dealloc of vertex and index buffers will be slow - it maybe an awful method - but at least it's a start!
kend
Posts: 11
Joined: Thu May 04, 2006 8:36 pm

Post by kend »

Yes, that approach would work but it means having an extra copy of the vertex data and I don't want to do that. It could be quite a lot in my case.
Erwin will have a demo later showing how to do it so I'll wait for that.

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

Post by Erwin Coumans »

I've been busy with Bullet Collada 1.4 Physics import, Blender-Bullet integration, ConvexDecomposition demo and other things.

Adding new parts to an existing TriangleMeshSHape requires to either add a new BVH tree, or extending the existing BVH tree. Both are better not done during the simulation, only at startup / preprocessing.

Are all the shapes not available at the start? Do you want to support streaming worlds? It would still be best to create large static meshes each in their own TriangleMeshShape.

Can you provide a bit more info?
Thanks,
Erwin
kend
Posts: 11
Joined: Thu May 04, 2006 8:36 pm

Post by kend »

The static terrain meshes are all loaded and available when bullet is initialized. The problem is that when each mesh is in its own TriangleIndexVertexArray there are a lot of collisions between these static meshes and this slows it down.
Basically what I'd like to see is a way to avoid processing these static meshes against each other. The terrain does not move so there can't be any real collision between the terrain parts. They should all be sleeping but right now they are all marked as "wants deactivating" and they remain in that state.

I'd be happy to clarify ths more if needed.

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

Post by Erwin Coumans »

kend wrote:The static terrain meshes are all loaded and available when bullet is initialized. The problem is that when each mesh is in its own TriangleIndexVertexArray there are a lot of collisions between these static meshes and this slows it down.
Basically what I'd like to see is a way to avoid processing these static meshes against each other. The terrain does not move so there can't be any real collision between the terrain parts. They should all be sleeping but right now they are all marked as "wants deactivating" and they remain in that state.

I'd be happy to clarify ths more if needed.

Ken
I suppose you mean collision time spend in the broadphase? There is no static trimesh versus static trimesh narrowphase.

Do you use 3d axis sweep and prune (AxisSweep3) ?

I'll check what we can do about this extra overhead indeed.

Thanks,
Erwin
kend
Posts: 11
Joined: Thu May 04, 2006 8:36 pm

Post by kend »

Erwin Coumans wrote: I suppose you mean collision time spend in the broadphase? There is no static trimesh versus static trimesh narrowphase.

Do you use 3d axis sweep and prune (AxisSweep3) ?

I'll check what we can do about this extra overhead indeed.

Thanks,
Erwin
Yes, broadphase and I use AxisSweep3. If you can find a way to eliminate the extra overhead that would be really great.

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

Post by Erwin Coumans »

There is new support for both collision filtering in the broadphase (to avoid static-static collision processing, see CcdPhysicsDemo how to use this), and also option to add multiple static meshes using TriangleIndexVertexArray::AddIndexedMesh:

1) First create a TriangleIndexVertexArray
2)Then add each mesh using AddIndexedMesh. notice this is indexing into existing vertex/index arrays, don't delete those original arrays, no internal copy is made.
3) Create a TriangleMeshShape, passing this TriangleIndexVertexArray.

Visit http://www.continuousphysics.com/mediaw ... e=Download

Let me know if there is problems using it.
Erwin