Dynamic model

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
vendetta
Posts: 18
Joined: Sat Dec 31, 2011 7:49 pm

Dynamic model

Post by vendetta »

Hi,
What is the best way to allow a model to be dynamic?

Is the ConvexHull class the most efficient way?

I currently have about 10 dynamic models using ConvexHull and the FPS drops significantly as opposed to when they are just StaticMeshes.

Is there a more efficient physics class for this type of thing?

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

Re: Dynamic model

Post by Norbo »

Convex hull collision detection cost is linear with the number of vertices in the hull. If there are hundreds or thousands of vertices, performance will take a hit. It's best to build the convex hulls from a simplified representation. Try to stay below ~30 vertices if possible.

If possible, using simpler primitives like Boxes would be a bit faster too.

That said, to get a significant drop from 10 convex hulls on the PC would require a huge number of vertices and many collisions. If there aren't enough vertices or collisions to explain the drop, there might be some other shenanigans going on. What kind of interactions are going on and how many milliseconds does the update take?
vendetta
Posts: 18
Joined: Sat Dec 31, 2011 7:49 pm

Re: Dynamic model

Post by vendetta »

Thanks for the fast reply!

I'm using this method for constructing the ConvexHull:
Vector3[] staticTriangleVertices;
int[] staticTriangleIndices;
TriangleMesh.GetVerticesAndIndicesFromModel(model, out staticTriangleVertices, out staticTriangleIndices);
var convex = new ConvexHull(position, staticTriangleVertices, 1);

The vector3 array's length for the models I'd like to be dynamic are:
Barrel_Top: 84
SmallStool: 230
OldKey: 861
RowOfBooks: 168

For things like the Barrel_Top and Books I can use a simple box, but for more complex shapes like a stool or barrel, what would be a good method to use? Is there a way I can reduce the number of vertices in the array or perhaps construct simple box / sphere shapes from the vertex array?

Also, the FPS starts out at 10-15, but as I go around and collide with the dynamic models and pick them up, the FPS rises to 100-150 (which is the same FPS that I get if I don't submit the convex hulls to the physics space). Is there a property I can set on the convex hulls so this occurs from the start?

Thanks for your help, it's greatly appreciated :)
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Dynamic model

Post by Norbo »

for more complex shapes like a stool or barrel, what would be a good method to use?
Depending on how they're shaped, a simple cylinder might do the trick. Or perhaps a minkowski sum of a cone and a short cylinder, or a wrapped shape of a cylinder representing the top of the stool and a box representing the bottom area of the stool.
Is there a way I can reduce the number of vertices in the array
The easiest way to do it is create a simplified version in a model editor. It's also technically possible to perform a simplification operation on a convex hull, but there's no built in method to do it and it's not trivial.
or perhaps construct simple box / sphere shapes from the vertex array?
This would also be possible, but there is no built in support and it could end up being harder than convex hull simplification (unless it just picked singular 'dumb' unfit bounding volumes).
Also, the FPS starts out at 10-15, but as I go around and collide with the dynamic models and pick them up, the FPS rises to 100-150 (which is the same FPS that I get if I don't submit the convex hulls to the physics space). Is there a property I can set on the convex hulls so this occurs from the start?
Something sounds a bit off here.

If the sequence of events is:
1) Objects are sitting on the ground, but still active, and the fps is 10-15.
2) Objects are picked up and no longer touch the environment, the FPS rises to 100-150.
3) Objects are back on the ground and still active, the fps drops to 10-15 again.

then that could be explained by collision complexity which can be solved by more efficient shapes. However, I would expect the objects on the ground to quickly go to sleep which would raise FPS back to at least 100-150 again.

However, if the sequence was more like this:
1) The objects are just sitting on the ground and the fps is around 10-15.
2) Objects are pushed around, picked up, and tossed about.
3) Objects are sitting on the ground once again, but the FPS is now 100-150.

then something strange is happening.

One explanation for this second sequence could be that the objects start in some very expensive locations. For example, if there was some odd, extremely dense geometry that caused a few hundred/thousand collision pairs in one part of the environment and the object was moved out of that, performance would increase quite a bit.

There is no expected behavior intrinsic to convex hulls or 'pre-interaction' time that would cause that to happen, so if the second sequence is what you're seeing and there are no oddities in the environment or collisions, there are indeed some shenanigans afoot.
vendetta
Posts: 18
Joined: Sat Dec 31, 2011 7:49 pm

Re: Dynamic model

Post by vendetta »

I found one problem for my Low FPS: The book objects were stuck in the shelves of my bookcase (which was a static mesh object). Moving them off of the shelf raised my fps to its normal standard.
I'm going to optimize as many models as I can by using basic shapes, and for more complex objects I'll use the convex hull.

Thanks for the help :mrgreen:
Post Reply