Best strategy with modifiable ground

braindeadbzh
Posts: 6
Joined: Mon Apr 02, 2012 10:22 am

Best strategy with modifiable ground

Post by braindeadbzh »

Hi all,

What is the best strategy to update a mesh inside a btBvhTriangleMeshShape?

Let me explain a bit. We have a ground made of voxels. They are not rendered as cube. The ground is split into chunks (16x16x<world height>).
For each chunk we create a static rigid body with a shape in Bullet using btTriangleIndexVertexArray, btIndexedMesh and btBvhTriangleMeshShape.
One of our game's features is that the ground is modifiable in real-time (i.e. you can add or remove voxels).
At the moment, to update a chunk in Bullet, we remove the rigid body from the world, we delete the rigid body and the shape and we re-create them with the new mesh.
For us, it seems definitively not efficient. But maybe we have missed something. If there any way to update the content of a btBvhTriangleMeshShape without delete it, it would be great.

Thank you for your answer.
xexuxjy
Posts: 225
Joined: Wed Jan 07, 2009 11:43 am
Location: London

Re: Best strategy with modifiable ground

Post by xexuxjy »

I haven't tried it in this case, but BvhTriangleMesh has methods : refitTree and partialRefitTree that may do what you need without having to remove and re-create the RigidBody.
braindeadbzh
Posts: 6
Joined: Mon Apr 02, 2012 10:22 am

Re: Best strategy with modifiable ground

Post by braindeadbzh »

Thank you xexuxjy. But how do you add or remove triangles in the shape?
xexuxjy
Posts: 225
Joined: Wed Jan 07, 2009 11:43 am
Location: London

Re: Best strategy with modifiable ground

Post by xexuxjy »

Again just guessing, but you should be able to lock your underlying btTriangleIndexVertexArray object and use the getLockedVertexIndexBase method to then manipulate your dataset (add/remove vertices) then unlock them and call the recalc from earlier. You could also write your own implementation of the StridingMeshInterface as that underlies most of these calls.

If you've got any specific demo code you could post to show what you're trying to achieve I could maybe help more.
braindeadbzh
Posts: 6
Joined: Mon Apr 02, 2012 10:22 am

Re: Best strategy with modifiable ground

Post by braindeadbzh »

Thanks again xexuxjy.
I will study your solutions.
And come, eventually, with more specific questions.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Best strategy with modifiable ground

Post by Erwin Coumans »

The btBvhTriangleMeshShape can only refit existing triangles with updated vertex positions (see Bullet/Demos/ConcaveDemo), so you cannot add/remove triangles (change the topology).

If you need a concave collision shape with adding/removing triangles, you could try using btCompoundShape, with triangles as child shapes? Likely more efficient then rebuilding the BVH (btCompoundShape uses the incrementally updated btDbvt). Alternatively, some work could be done to replace the btOptimizedBVH by btDbvt, adding a btDbvtTriangleMeshShape.

Thanks,
Erwin
braindeadbzh
Posts: 6
Joined: Mon Apr 02, 2012 10:22 am

Re: Best strategy with modifiable ground

Post by braindeadbzh »

Hi Erwin,

Thank you for this details.
I will try that, and give you some feedback.