Page 1 of 1

btBvhTriangleMeshShape + instances

Posted: Mon May 29, 2017 3:34 pm
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

Re: btBvhTriangleMeshShape + instances

Posted: Tue May 30, 2017 11:14 pm
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.

Re: btBvhTriangleMeshShape + instances

Posted: Wed May 31, 2017 7:15 am
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 !