Monday, July 19, 2010

Bullet SoC - A Guide to choosing Collision Shapes

As promised in my commit log for Triangle-Mesh Collision Shapes, here is a brief guide (with demonstrative videos) on choosing collision shapes when working with Rigid Body simulations.

A few bugs showed up (and most but not all were fixed) during the course of the video recording process, so the initial commit of this functionality may not be sufficient to reproduce these videos.

By default, all newly added Rigid Bodies have their collision shape type set to 'Convex Hull'. Most of the time, this allows you to quickly and easily setup up simulations and have them work as you expect. However, in some cases, this may not be the case, as we'll see...

Example 1: Ski Ramp

This example shows one of the situations where the default "Convex Hull" is inappropriate. As illustrated using Grease Pencil and seen from the motion of the sphere, the convex hull used as the collision shape provides a very crude approximation of the true shape of the ramp. Convex hulls are like forming a surface/envelope over the outside of a shape with shrinkwrap, which means that bowl-like areas (concave regions) are not accurately represented for collision detection. Here the ramp exhibits concave-tendencies, so in this case, you need to change the collision shape to mesh instead of the default convex hulls.

Example 2: Chains

This example shows another one of the situations where the default "Convex Hull" is inappropriate. Once again, the convex hull makes an envelope which is too crude of an approximation to the actual collision surface. However, in this case, this is because the convex hulls only consider the outer (extremes of the) surfaces. This means that the holes in the middle get ignored or are non-existent from Bullet's POV. Consequently, the shapes will appear to have illegally collided, and strong repulsion forces will be assigned to all parts of the chain to force them apart, causing the explosion result.

In general, this is not the desired result (though you now also know how to create the "Houdini's Rings" effect), so we need to use Mesh collision shapes here once again.

Example 3: Why not always 'Mesh'?

This demonstration examines the question: Why don't we just use 'Mesh' all the time instead?

As seen in the video, when we do this, collision detection will appear to 'fail' when all participants use Mesh shapes. But, if we used Convex Hull for both (i.e. default settings), collision detection will also not be correct, as the convex hull masks over some of the gullies (as per Example 1).

Therefore, the recommended/only solution is to make the plane a Mesh, and the object a convex hull.

Other Things You Should Consider:
Hopefully now that it's clear when to use Convex Hulls and when to use Meshes, let's consider the remaining cases of when you might consider using other collision shapes at all. After all, left to its own devices, Blender will give you a good default of Convex Hulls, which takes care of most situations.

The main reason you may want to consider using the other types is if your objects can be very well approximated by one of the existing primitives. For example, for roughly spherical bodies, Sphere would be more efficient than a Convex Hull sphere mesh. The same goes for floor planes or boxes or bricks, by using the Box shape.

This is really handy to keep in mind when dealing with larger sims that are starting to bog down your computer.

Hopefully this has been an informative post. Until next time,


  1. Hey Ali, this is a great update!

    Should we report bugs/crashes/etc for this branch? If so, where? Right now I get a crash just trying to move something to another layer without changing any settings. Are there any special building instructions for this branch? I'm using scons on a Mac.

    Also one setup I've been trying to create is several boxes sitting on top of each other. The problem is that as soon as the sim starts the boxes kind of bounce away from each other, which I assume is do to the bounding margin taking effect or something. Is there anyway to create this sort of set up without some sort of preroll? I tried setting the margin really low, but didn't seem to help. Boxes aside I'm much more interested in how this can be used with pre-fractured objects, like smashing through a wall, which is something you can't really preroll to a rest position on.

    Thanks for all the hard work!

    24" iMac 2.8GHz core 2 duo
    ATI RadeonHD2600
    4GB Ram

  2. Further investigation.
    I realized that by changing the container type to box instead of leaving it as convex hull (as in the previous example I provided) the gap seems to disappear. Is there a reason the convex hull type creates a margin? Also can you set a negative margin so that the collision bounds would actually be slightly smaller than the shape? I didn't seem to see any difference when playing with the margin setting. I also never seem to notice any difference when adjusting the bounciness amount.

    The next thing I noticed is that the chain demo doesn't really end up giving the desired effect, because while the chains no longer explode (houdini effect), neither do they see each other. So you can't actually create a swinging chain setup, they just fall through each other.

    FYI, I understand these problems may be well beyond your SOC project, but I just wanted you to be aware.

    I created a simple chain setup blend for your convenience incase you'd like to pursue this. There are no rigid bodies applied, it is just a pole and chain set up.

    This is a link to a very similar setup done in cinema4D (similar collision problems with work arounds included).

  3. Hey Aligorith!
    Just wanted to say, that you are doing a great job!!! I am really looking forward for your finished soc project! Will this be included in 2.6 already?
    It is a lot of fun to play around with your branch!!
    Keep on going!!

  4. Ichabodcole:
    Thanks for all the great feedback. The video you linked to mentions some interesting ideas to investigate indeed.

    You can add bugreports to

    Compiling with scons should work. Just make sure you've got WITH_BF_BULLET = True in your, otherwise you'll currently run into some strife trying to get everything compiling/linking.

    Also, I've fixed that crash you mentioned. Thanks :)

  5. actually I believe MoDynamics (c4d) is build among Bullet :)

  6. Thanks Ali! I assure you I will now pester you to no end with tweaks and bug fixes :). Fortunately, like a vampire you can just uninvited me and I will retreat to my coffin.

    @francois - indeed it is.

  7. Thanks for the latest bug fix Ali!