btBvhTriangleMeshShape + instances

Post Reply
gjaegy
Posts: 178
Joined: Fri Apr 18, 2008 2:20 pm

btBvhTriangleMeshShape + instances

Post by gjaegy »

Hi,

imagine the following case: HW instancing is being used in order to render 10 instances of the same street light 3D model (i.e. one mesh being rendered 10 times).

Is there a way to create one single btBvhTriangleMeshShape object, and reuse it across the different instances (of course with a different position for each instance) ?

If not, what would be the best way of doing thing, while trying to avoid having to create 10 btBvhTriangleMeshShape objects, or creating on single btBvhTriangleMeshShape built using the merged geometry of the 10 instances (i.e. duplicating vertices 10x to create one single mesh containing duplicated geometry) ?

Is that achievable in one way or another ?

Thanks a lot
Greg
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: btBvhTriangleMeshShape + instances

Post by drleviathan »

Yes, you can share one shape instance across many RigidBodies. Getting it done is simple enough: just pass the shape pointer to each RigidBody as normal, however the tricky bit comes down to keeping track of how many bodies are using each shape and when to delete the shape, if ever.

Depending on what kind of simulation/game you're running I can think of two ways to do it:

(1) Never ever bother to clean up the shapes you create. This would be a memory leak but might work for some special cases where the number/variety of shapes you'll ever need is known to be finite and reasonable.
(2) Implement a ShapeManager/Factory to build the shapes you need and to supply ref-counted pointers to them.
gjaegy
Posts: 178
Joined: Fri Apr 18, 2008 2:20 pm

Re: btBvhTriangleMeshShape + instances

Post by gjaegy »

OK great, I also discover the scaled bvh, which perfectly suits our needs since we have some random scaling variation of instances.

Thanks for your answer !
Post Reply