Bullet Physics Collision Margins and Shapes

Show what you made with Bullet Physics SDK: Games, Demos, Integrations with a graphics engine, modeler or any other application
Post Reply
RBD
Posts: 141
Joined: Tue Sep 16, 2008 11:31 am

Bullet Physics Collision Margins and Shapes

Post by RBD »

A different way to look at collision margins and understanding collision shapes, for everyone using Bullet physics engine (in any form on any platform)...
Hopefully this is also a useful tutorial and visual explanation of Bullet's collision margins. I also cover compound rigid bodies in this video and consider ways to really exploit collision margins.

YouTube: Bullet Physics Collision Margins and Shapes

UPDATE: I've posted some code below that contains a utility function to generate convex hull meshes extruded by a specified collision margin (and specified margin curve resolution).
Last edited by RBD on Thu Jul 04, 2013 2:28 pm, edited 1 time in total.
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: Bullet Physics Collision Margins and Shapes

Post by Flix »

Really amazing video :D
Thanks for sharing it :D

I'm not an expert Blender user at all, and it took me a while to understand that the .blend file works (and with runtime rendering!) on a plain Blender 2.66 version (and the performance is not at all bad even of my old graphic card!).

About the topic: it is really interesting (and it's impressive how quickly you can create meshes that match each Bullet collision shapes with arbitrary margin...).

I remember that by using the btMultiSphereShape, some time ago I was able to produce similiar results (I don't know if this shape is available in Blender, but it's basically a convex hull shape with a radius associated to each vertex: it's an underestimated collision shape IMO, but it's very powerful and can be further scaled in each direction).

However many things like rounded cylinders, cones and compund shapes can't be built using a btMultiSphereShape and the "collision margin tuning technique" you propose is extremely interesting indeed :) .
RBD
Posts: 141
Joined: Tue Sep 16, 2008 11:31 am

Re: Bullet Physics Collision Margins and Shapes

Post by RBD »

Thank you Flix.

Yes btMultiSphereShape does indeed seem to have a lot of potential uses (not exposed in Blender at this time).

I've had this feeling there might be a way to exploit (compound) btMultiSphereShape to do automated convex decomposition of high resolution subdivision surface / rounded / bevelled objects using a sphere packing algorithm (only using the outer spheres of convex spaces). Haven't tried attacking this problem.
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: Bullet Physics Collision Margins and Shapes

Post by Flix »

Intersesting...

I hope Blender developers will add that shape in the future (even if they should probably find some spot to add the "radii" of the vertices).

And I hope that in the future they will add some way (or some addon) to create meshes that match the Bullet collision shapes (with arbitrary margins) automatically too.

Blender seems to be a great tool for Bullet users.
RBD
Posts: 141
Joined: Tue Sep 16, 2008 11:31 am

Re: Bullet Physics Collision Margins and Shapes

Post by RBD »

Flix wrote:And I hope that in the future they will add some way (or some addon) to create meshes that match the Bullet collision shapes (with arbitrary margins) automatically too.
:P I guess I could do that at some point in the future... (with spring here, this indoor hobby will probably take a back seat. :) )

But yes, just needs a few more exposed tools... e.g.: Blender already has a convex hull mesh operator, and it actually calls Bullet's btConvexHullComputer, but unfortunately the margin shrink parameter was simply ignored. All that's needed is a simple call to Ole's btConvexHullComputer possibly followed by Erwin's GrahamScanConvexHull2D to consolidate left over co-planar faces (for Bmesh); these little things would be fairly straightforward to implement, but it still takes time and effort; I'll leave it to people making an income related to this to work it out.
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: Bullet Physics Collision Margins and Shapes

Post by Flix »

RBD wrote::P I guess I could do that at some point in the future... (with spring here, this indoor hobby will probably take a back seat. :) )
:lol: (computer activity in the open air might help, but it's definitely not the ideal outdoor hobby one can have :) ).

I agree with you about the rest of your post (I was simply making some general considerations in my previous post, I was obviously not expecting anything by your side: you're already doing a lot :D).
RBD
Posts: 141
Joined: Tue Sep 16, 2008 11:31 am

Re: Bullet Physics Collision Margins and Shapes

Post by RBD »

I've received some inquiries about how I produced the extruded collision margin meshes for this video. So I'm posting some example code to produce these here.

The function I'm providing takes mesh vertices as input and will generate a convex hull mesh extruded by the specified collision margin (with specified margin curve resolution).
You can supply any convex hull vertices to this function, and just like in the video: if you supply one vertex you will get a sphere, if you supply two vertices you will get a capsule, etc..
For a cone primitive, of course, you would supply a circle of vertices at the base and one vertex at the tip; two circles for a cylinder, etc..
If you want a single compound non-convex mesh, you'll need to resort to your favourite CSG mesh tool to create a union of these.

See convexMarginMesh.h for instructions.
Attachments
convexMarginMesh.zip
Code for convexHullMarginMesh function.
(2.18 KiB) Downloaded 925 times
RBD
Posts: 141
Joined: Tue Sep 16, 2008 11:31 am

Re: Bullet Physics Collision Margins and Shapes

Post by RBD »

Convex Hull Margin Blender add-on posted on Blender Artists forum in this thread: Round Cube: real Quadsphere, Capsule, Rounded Cuboid, 3D Grid + Convex Hull Margin
RBD
Posts: 141
Joined: Tue Sep 16, 2008 11:31 am

Re: Bullet Physics Collision Margins and Shapes

Post by RBD »

Convex Hull Margin Blender add-on updated for the latest Blender version (2.74) and attached here (for now).

This Blender add-on allows users to create an approximate convex hull mesh from any Blender object with an optional margin value used to shrink or expand the convex hull.
- Use a margin of 0 to get an approximate convex hull
- Use a negative margin to generate an approximate convex hull of the object less this collision margin: this convex hull can be used with the specified collision margin as a proxy for physics of the object.
- Use a positive margin to generate an approximate convex hull of the object plus a collision margin: this convex hull is an approximate visual representation the object plus a collision margin.
Attachments
object_convex_hull_margin_v0_2.zip
Convex Hull Margin Blender add-on v0.2
(2.64 KiB) Downloaded 895 times
Post Reply