Precomputed ConvexHulls?

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
ryantrem
Posts: 5
Joined: Sun Nov 14, 2010 11:12 pm

Precomputed ConvexHulls?

Post by ryantrem »

I'm creating a ConvexHull from a list of 720 vertices. Once the ConvexHull is created, performance seems fine, but it takes about 15 seconds to instantiate the ConvexHull. Are there any recommendations on precomputing the ConvexHull? It'd be nice if I could either do this at build time, or even just serialize the ConvexHull manually and then deserialize it at runtime. Suggestions?

Also, the ConvexHull has 720 vertices because I'm trying to simulate a polyhedron with rounded edges. I noticed a MinkowskiSum entity class - would it be possible/performant to create a Minkowski sum of the polyhedron and a sphere to get the rounded edges rather than the more complex polyhedron with approximately round edges (which is what I'm doing now)?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Precomputed ConvexHulls?

Post by Norbo »

It'd be nice if I could either do this at build time, or even just serialize the ConvexHull manually and then deserialize it at runtime. Suggestions?
The convex hull pointset could be reduced using the Toolbox.GetConvexHull method at build time, or just a single time at initialization. The reduced list could then be passed to the ConvexHull instances, although if most of the convex hull pointset is still around, there will still be some slowdown. 15 seconds also seems pretty long- is that on a phone?

Edit: By the way, in v0.15.0, it will be possible to re-use collision shapes and other parts of entity data across multiple entities, allowing for quicker initialization.
I noticed a MinkowskiSum entity class - would it be possible/performant to create a Minkowski sum of the polyhedron and a sphere to get the rounded edges
Yes, that would be much better overall. However, you don't have to use the MinkowskiSum class itself. General convex objects are expanded by a spherical collision margin which is equivalent to taking the minkowski sum of the shape and a sphere. The CollisionMargin property is on all entities. By default, it is 0.04, but you could increase that to higher values to make it more noticeable.

The reason for the collision margin in general is explained here if you are curious:
http://www.bepu-games.com/forums/viewto ... ?f=4&t=409
ryantrem
Posts: 5
Joined: Sun Nov 14, 2010 11:12 pm

Re: Precomputed ConvexHulls?

Post by ryantrem »

Thanks for the info! I'd like to try out the implicit Minkowski sum approach, but I have a few follow up questions:

1. Given my more complex rounded edge polyhedron mesh, can you suggest a method of getting the points of a convex hull that is roughly equivalent to the polyhedron without rounded edges? For example, my mesh that results in a 720 point convex hull represents a polyhedron with maybe 40 or 50 vertices. Toolbox.GetConvexHull doesn't seem to have any parameters to determine which vertices get removed, and ends up returning 660 points, so it doesn't help much. Perhaps I should be using a mesh with a minimal number of vertices and faking the rounded edges in the shader...

2. Is the CollisionMargin in absolute units, or is it a scale factor?

3. If I increase the CollisionMargin to effectively create the Minkowski sum, I'll need to shrink the ConvexHull to not overly expand the object. Is the best way to do this to simply scale all the individual points of the ConvexHull?

And yes, this is in the WP7 emulator.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Precomputed ConvexHulls?

Post by Norbo »

Given my more complex rounded edge polyhedron mesh, can you suggest a method of getting the points of a convex hull that is roughly equivalent to the polyhedron without rounded edges?
The best way would probably be to have a separate mesh/pointset created for the collision, as culling out the extra points could get complicated. There might be some mesh simplification algorithm that could get something close to what you're looking for, but it would probably take more time to get working than just creating some extra content files.
2. Is the CollisionMargin in absolute units, or is it a scale factor?
Absolute units.
3. If I increase the CollisionMargin to effectively create the Minkowski sum, I'll need to shrink the ConvexHull to not overly expand the object. Is the best way to do this to simply scale all the individual points of the ConvexHull?
That's certainly an option that will probably produce 'good enough' results. There are also some other approaches that are a little more intensive algorithmically (I believe I've seen some discussions about it over on the bulletphysics.org forums). If you have a separate source content for the collision data though, you can construct it such that it matches to begin with.
Danthekilla
Posts: 136
Joined: Sun Jan 17, 2010 11:35 am

Re: Precomputed ConvexHulls?

Post by Danthekilla »

ryantrem wrote:And yes, this is in the WP7 emulator.
Just thought i should let you know we have 2 different actual devices and they are both an order of magnitude slower than the emulator even running on a crappy pc.

In my naive tests i have found that it is around 25-40 times slower than the emulator for gpu stuff (running on a geforce 260 on my pc)
and about 15-20 times slower than one core of a 2.4ghz core 2 duo.

The emulator is slower than running normally on pc but it is far slower again on the phone...

Just be sure to run this on a real device as soon as possible. And with luck you will be fine.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Precomputed ConvexHulls?

Post by Norbo »

In a few quick tests on the phone, it appears that on my Q6600@2.4ghz, the emulator is around 1.7x as fast as the device with regards to physics updates. If yours is running an order of magnitude slower, there are probably some other issues; that mesh problem could be doing it (http://www.bepu-games.com/forums/viewto ... f=4&t=1017).
Danthekilla
Posts: 136
Joined: Sun Jan 17, 2010 11:35 am

Re: Precomputed ConvexHulls?

Post by Danthekilla »

Norbo wrote:In a few quick tests on the phone, it appears that on my Q6600@2.4ghz, the emulator is around 1.7x as fast as the device with regards to physics updates. If yours is running an order of magnitude slower, there are probably some other issues; that mesh problem could be doing it (http://www.bepu-games.com/forums/viewto ... f=4&t=1017).
I forgot that i upgraded my cpu and am now using a 3.6ghz i7 which when running one core runs at 4.0ghz and an i7 is much faster than a core 2 duo per clock.

If i remember rightly my results were 79ms on the real phone and 7.2ms on the emulator just using the default sample you provided with the amounts changed a bit and the rendering commented out.

Also many people have said that the emulator runs slowly on their systems where for some people it runs at crazy speeds, it is thought that it has something to do with the gpu and its drivers that you use. Some people have found the emulator to be a little slower than the device on a fairly modern computer, others have found it to be out by massive amounts...

For instance a 3d particle system i made can get around 4,000 particles rendering on the actual phone but on the emulator it gets about 270,000 with the exact same framerate (23)
Last edited by Danthekilla on Wed Nov 17, 2010 7:38 am, edited 1 time in total.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Precomputed ConvexHulls?

Post by Norbo »

That would explain it :)
Post Reply