Best Way to Use Changing Meshes

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Wabafet
Posts: 3
Joined: Wed Feb 18, 2015 12:29 am

Best Way to Use Changing Meshes

Post by Wabafet »

Hello,

In my game I have a lot of procedurally generated obstacles that are composed of a mesh and a material but remain static in the environment so I assume StaticMesh collidables are best for them. However, because of the huge number of obstacles I can't retain a collidable for each obstacle. I am able to quickly determine which obstacles are near a player so I only need to check for collisions with them. I would assume that creating and destroying new StaticMesh objects as the player moves would create a lot of garbage. Is there an efficient way to change the shape of a StaticMesh object?

The closest other topic about this that I found is:
viewtopic.php?f=4&t=1402
Which describes what I had been looking into myself, changing the Vertices and Indices of the shape then using Reconstruct but it sounds like it may be inefficient.

The obstacles are small, relatively simple unique meshes of about 50 triangles each and the player may be touching multiple obstacles at once, up to 10 or so. Is there a better way to manage this than using Reconstruct? Is there maybe a different collidable that would work better?

Thank you.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Best Way to Use Changing Meshes

Post by Norbo »

If the obstacles tend to be a lot of the same shapes with different transforms, InstancedMeshes might offer some more pooling opportunities. The acceleration hierarchy is local to the shared InstancedMeshShape, so the memory overhead for tons of InstancedMeshes is very low.

If the changes do not change topology, refits can be used (as mentioned in that link). For fully arbitrary unpoolable shapes without shared topology, there is no good way to fully avoid some sort of construction, and at the moment, there is no good way to avoid some allocations with mesh reconstructions.

Also, if for some reason having thousands of collidables active at once would help but you've measured excessive broadphase cost, the StaticGroupShape now supports Adds and Removes. This is a bit of a stopgap measure- the tree will not try to do any maintenance, so the quality of the tree depends partially on the order of adds and removes. If they're spatially randomized, the quality of the tree will be better than otherwise.

(A longstanding item on the to do list is to rewrite all of these involved acceleration structures to both make them faster and more memory efficient. I'm still not sure when this is going to happen, but it will happen eventually!)
Wabafet
Posts: 3
Joined: Wed Feb 18, 2015 12:29 am

Re: Best Way to Use Changing Meshes

Post by Wabafet »

Thanks for your reply. The meshes I am using are generated through noise so they are all different so it seems I'll have to use Reconstruct for now. It shouldn't have much impact though, I will have to test it. If it does I'm sure I can think of a different way to manage it to better work with the physics engine.

Thanks.
Post Reply