MAX Performance

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
galodoido794
Posts: 12
Joined: Tue Jan 17, 2012 10:50 am

MAX Performance

Post by galodoido794 »

First, praising the project. I'm learning a lot from him.

I have a question, want to build a scenario where I can have 10 to 30 thousand boxes or other shape (no physical).

I set an example by using:

space.Solver.IterationLimit = 2;

var = new StaticMesh mesh (staticTriangleVertices, staticTriangleIndices, new AffineTransform (
new Vector3 (boxSize, boxSize, boxSize)
box.Orientation,
box.Position));
mesh.Sidedness = TriangleSidedness.Counterclockwise;
mesh.IgnoreShapeChanges = true;

And also rode another example using:

space.Solver.IterationLimit = 2;

var = new meshShape InstancedMeshShape (staticTriangleVertices, staticTriangleIndices);
var = new InstancedMesh mesh (meshShape, new AffineTransform (
new Vector3 (boxSize, boxSize, boxSize)
box.Orientation,
box.Position));
mesh.Sidedness = TriangleSidedness.Counterclockwise;
mesh.IgnoreShapeChanges = true;

Space.Add (mesh);
game.ModelDrawer.Add (mesh);

In both cases the FPS varies from 30 to 45 and Physics Time varies from 12 to 30.

I wonder what techniques I use to increase FPS and reduce the Physics Time? There could be an example or documentation on how to make a game with a great performance =)

Sorry for my bad english = (
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: MAX Performance

Post by Norbo »

If I'm understanding correctly, there are 10,000 to 30,000 StaticMeshes or InstancedMeshes in the simulation, each representing one shape. If that's correct, then you'll be able to get a massive performance boost by combining all of those meshes into a single mesh.

Having a bunch of separate objects in the space causes pollution in the BroadPhase. A StaticMesh has an internal acceleration structure which has certain guarantees that the BroadPhase does not, so it can ignore the vast majority of collision possibilities with no effort. A StaticMesh can easily handle many thousands of triangles.

If you'd prefer to have actual shapes composing the environment, like BoxShapes, SphereShapes and so on as opposed to a triangulated mesh, you can do so using a kinematic CompoundBody. It has an internal acceleration structure similar to the StaticMesh, but can include any combination of EntityShapes.
galodoido794
Posts: 12
Joined: Tue Jan 17, 2012 10:50 am

Re: MAX Performance

Post by galodoido794 »

His suggestion is a measure creating an object that I join others in such a way to stay only a StaticMesh??

For example, I created three staticmesh somehow combines them into one? How?

Thanks for the reply =D
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: MAX Performance

Post by Norbo »

A mesh is a list of vertices and indices. To combine multiple meshes, go through each mesh, append its vertices to the combined vertices list, and then append its modified indices to the index list. The indices must be modified because the vertices were appended to the end of a vertex list and no longer inhabit the same location in the vertex list.

To get a feel for the process, try doing it with a simplified case at first. Consider two meshes, each with three vertices and three indices. Combining the two results in a mesh with six vertices. However, the second mesh's indices must be offset before appending them; their targeted vertices are 3 slots off where they used to be. So, add 3 to all the second mesh's indices. For more complicated situations, the process generalizes to adding the count of vertices (as counted prior to adding the latest new mesh vertices) to each new index.
galodoido794
Posts: 12
Joined: Tue Jan 17, 2012 10:50 am

Re: MAX Performance

Post by galodoido794 »

I'm trying to make your solution and so far not been successful =(

I was wondering if I have two objects, separately and in different positions.
Assuming that the first object is the vertex (1,1,1), index 0 and position (5,5,5).
The second object vertex (1,1,1), index 0 and position (9,9,9).

Joining the two into a single object (as per your suggestion) I have two vertices in the list {(1,1,1) and (1,1,1)} and two indices in the list {0, 1 (increment)},
but how can I address the issue of position in a single object?

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

Re: MAX Performance

Post by Norbo »

Apply the transforms needed to bring the meshes into a common transform space. So, if a vertex is at (1,1,1) in local space of its current mesh, but it has a mesh space transform of 'offset by (9,9,9)', apply the transform to get (10,10,10) before putting it into the mesh.
galodoido794
Posts: 12
Joined: Tue Jan 17, 2012 10:50 am

Re: MAX Performance

Post by galodoido794 »

I understand, but when applying this formula the result was not expected.

Example:
...
staticTriangleVertex[v].X += newPosition.X;
staticTriangleVertex[v].Y += newPosition.Y;
staticTriangleVertex[v].Z += newPosition.Z;
...
vertex.add(staticTriangleVertex);

Is there any function in the framework that does this transformation?

Thanks
Last edited by galodoido794 on Sat Jan 21, 2012 12:42 am, edited 1 time in total.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: MAX Performance

Post by Norbo »

TriangleMesh.AddMesh does something somewhat similar.
galodoido794
Posts: 12
Joined: Tue Jan 17, 2012 10:50 am

Re: MAX Performance

Post by galodoido794 »

Ok ... I will test ... Thank you ..
galodoido794
Posts: 12
Joined: Tue Jan 17, 2012 10:50 am

Re: MAX Performance

Post by galodoido794 »

I'm guessing this engine and fantastic support.
One question, how can I draw with StaticMesh 9999999 vertex and 29999999 indices? That is, I have a StaticMesh with many vertices and indices (from the millions) ...

I made this example, but is designed StaticMesh half.
I'm looking into this class:
ModelDisplayObjectBatch
{
public static int MaximumPrimitiveCountPerBatch = 9999999;
public const int MaximumObjectsPerBatch = 61;
}
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: MAX Performance

Post by Norbo »

The BEPUphysicsDrawer can't draw something that large. It's designed for debug visualization (to make sure collision shapes match and such) and for the demos. It should not be used for the primary rendering system of a game.

There's a couple of general problems with objects with that many triangles:
-Graphics cards have limits on the number of triangles they can draw in a single draw call. For example, if I remember correctly, mine is around 1.4 million triangles. Attempting to draw more than that at once will throw an exception. 30,000,000 indices is 10,000,000 triangles. I don't know if any graphics card will accept that many off the top of my head.
-That mesh would likely be excessively large for other systems in many ways. There would be numerical issues at the extremes, it would use large amounts of memory, it would have bad performance, etc.

For immense meshes, such as a big MMO environment or Minecraft-like procedural worlds, the usual strategy is to split it up and only manage a smaller bit of it at once.
galodoido794
Posts: 12
Joined: Tue Jan 17, 2012 10:50 am

Re: MAX Performance

Post by galodoido794 »

I'm making a big MMO =D

I'll search what are the strategies that can take ...

As always thank you ...
galodoido794
Posts: 12
Joined: Tue Jan 17, 2012 10:50 am

Re: MAX Performance

Post by galodoido794 »

Just kidding, but I found the engine very good and wanted to use it as the main engine.

You indicate a graphics engine? Xen? SlimDX? Other?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: MAX Performance

Post by Norbo »

I've seen a lot of people using Sunburn with BEPUphysics. Xen is an option too, though I think the development stopped last year. SlimDX and similar projects like SharpDX are DirectX wrappers, not engines, so they wouldn't provide what you expect from an engine. I'm not very familiar with all the options available so I'm probably not the best person to ask :)
Post Reply