Correct shape to use?

riptide
Posts: 6
Joined: Sat Nov 08, 2008 12:50 am

Correct shape to use?

Post by riptide »

I'm writing a game for the iPhone, so memory and CPU usage are very limited resources. My current issue is with the CPU.

I have a set of dice set to fall into a "cup" which is actually a model of a barrel. The dice I have represented as the primitive cube shape even though my models have curved edges. However, the cup is not as simple. As far as I understand it, it must be represented as a concave shape in order for the dice to be able to fall into it.

When I represent it as a concave shape (using btBvhTriangleMeshShape), the simulation runs slowly (not as bad as I would have thought, but obviously skipping steps in the simulation). When I load the mesh into a btConvexTriangleMeshShape and use btShapeHull to simplify it to get a btConvexHullShape, the simulation runs smooth as butter on the iPhone, but the dice just impact the top of the cup as if there were a side across the opening and bounce and skip across that surface and fall away outside the cup.

Is there another shape I can try that would be faster than a btBvhTriangleMeshShape or a way to construct my concave cup shape out of multiple convex ones or something similar to get the effect I want with less computation?

Thanks
- Marcus
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Correct shape to use?

Post by Erwin Coumans »

It is best to use a btCompoundShape with several btConvexHullShapes. Note you can automatically simplify individual btConvexHullShapes using the btHullShape utility.

Does the cup need to move? The btBvhTriangleMeshShape can only be used for static/non-moving objects. An alternative is using the btGimpactShape (see Bullet/Demos/MovingConcaveDemo and Bullet/Demos/GimpactTestDemo), which has automatic convex decomposition as one of the options. The Bullet btSoftBody has also some convex cluster decomposition, but this feature is not available for rigid bodies yet.

You can see some example of btCompoundShape in Bullet/Demos/ConvexDecompositionDemo. Obviously, you can do the convex decomposition by hand, instead of using the Bullet/Extras/ConvexDecomposition utility.
Hope this helps,
Erwin
riptide
Posts: 6
Joined: Sat Nov 08, 2008 12:50 am

Re: Correct shape to use?

Post by riptide »

I'm not really sure how to answer your question about whether the cup has to move -- it does have to move in the game, but it can be considered static in the physics world.

Basically, the cup doesn't need to react to collisions with the dice, but the dice do need to react to collisions with the cup. The cup will be moved by the program, and the dice need to collide with it as it moves. The cup will be shaken to mix up the dice (input for shaking the cup coming from the accelerometer on the iPhone), and then the cup will be flipped onto a surface (trapping the dice underneath) to cast the roll of the dice.

Thanks for the help. Taking a look at those demos now.

- Marcus
riptide
Posts: 6
Joined: Sat Nov 08, 2008 12:50 am

Re: Correct shape to use?

Post by riptide »

I went back and decomposed my object into a set of convex shapes and loaded them as a compound shape. I converted my model to an obj, then used the demo to decompose it and converted the result back to Collada for my application (I only have a collada loader in my project).

I use a btConvexTriangleMeshShape to load a decomposed piece, create a btShapeHull from that, call buildHull, then convert the result into a btConvexHullShape which I add to a btCompoundShape rinse and repeat for each decomposed piece.

The end result on the iPhone runs about the same as far as performance goes between this method and the concave shape (btBvhTriangleMeshShape).
riptide
Posts: 6
Joined: Sat Nov 08, 2008 12:50 am

Re: Correct shape to use?

Post by riptide »

Since my cup object does not need to react to the impact with the dice, am I ok with a static object? I do need to move it and have its movement affect other objects, but I don't need any other objects to affect it in the physics world.

In either case, I ran some performance tests without the cup, and I think further optimizations are needed before Bullet is fast enough for what I want to do on the iPhone. I was reading on the Oolong list about a VFP math library which apparently has work already begun at http://code.google.com/p/vfpmathlibrary/. Will there be work done to integrate the VFP library with Bullet?

For those reading that would have to do like me and look up what VFP is, it stands for Vector Floating Point and it's apparently a piece of hardware integrated with the iPhone that provides faster floating point math.