[v1]Accelerating StaticMesh creation

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
KakCAT
Posts: 32
Joined: Mon Apr 14, 2014 2:08 pm

[v1]Accelerating StaticMesh creation

Post by KakCAT »

Hi Norbo!

Lately I've been abusing a bit of StaticMesh in bepu v1. It has accelerated a lot the execution in runtime while making the load slower. I had no problem with it, until I've recently realized that sometimes I need a very fast StaticMesh creation. The game is a JRPG and I want the transitions to battle to be as fast as possible.

I've been profiling and I've found that most of the time is lost when calling Reconstruct at MeshBoundingBoxTree when creating the StaticMesh. If I'm not wrong, it is a tree created to accelerate collision detections.

What I'd like to do is to avoid creating the StaticMesh acceleration tree every time, taking advantage of the fact that the maps that are reloaded very often are usually the same map for a long period of time. I'd like to save somehow that tree and reuse when creating the mesh again.

My question is if it's possible, and which would be the safest/easiest way to acomplish that.

What I've thought so far is getting a reference the MeshBoundingBoxTree once it's constructed the first time, save that reference and reuse it later by passing it as a new parameters for a new constructor of a StaticMesh. As I'm holding that reference, it's supposed not to be collected thus, as long as the mesh is the same, the acceleration tree would be also the same, despite the fact that the physics Space will be destroyed once the battle is over, isn't it?
However I don't know if this is possible, or if there is a better solution.

Thanks!
Kak
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: [v1]Accelerating StaticMesh creation

Post by Norbo »

The easiest thing to do would be to keep a reference to the whole StaticMesh for later use. You can remove it from the Space and re-add it later.

There's also the InstancedMesh, which is very similar to the StaticMesh but doesn't bake the world transform into the underlying tree so the shape it uses can be more efficiently reused.

If you wanted to minimize the load times as much as possible, you could do something like v2's tree serialization. The tree can be stored on disk as a build step. More work, but it does the job.
KakCAT
Posts: 32
Joined: Mon Apr 14, 2014 2:08 pm

Re: [v1]Accelerating StaticMesh creation

Post by KakCAT »

Thanks for the tips!

I realized I couldn't insert/remove the StaticMeshes (because 2 same maps can be loaded at the same time) and went for the serialization method.
Post Reply