Deformable and breakable body - sample

a small TestBed example for deformable and breakable bodies using the updated b2DistanceJoint in Box2D version 2
Image
add in TestEntries.cpp
#include "BreakableBody.h"
and in TestEntry g_testEntries[] =
...
{"BreakableBody", BreakableBody::Create},
...

Put the 2 files TriangleMesh.cpp/h into the same directory.
Or use a mesher - supporting holes - of your choice, its quite easy to connect.

Use '+'' and '-' key to increase/decrease the max. allowable reaction forces of joints

cheers - nimodo
a short description
BreakableBody -> ExampleData('b');
Image

Code: Select all

/// 'b' a box with a rectangular hole
     static tmVertex b_nodes[] = {
       { 0.00f, 0.00f},  //V1
       { 10.00f, 0.00f}, //V2
       { 10.00f, 10.00f},//V3
       { 0.00f, 10.00f}, //V4
       { 2.00f, 2.00f},  //V5
       { 8.00f, 2.00f},  //V6
       { 8.00f, 8.00f},  //V7
       { 2.00f, 8.00f}   //V8
     };

     static tmVertex b_holes[] = {
       { 5.0f, 5.0f}   // H1: hole must be inside below segments
     };
     static tmSegmentId b_segments[] = {
       { 5, 6 }, // V5 --- V6
       { 6, 7 }, // V6 --- V7
       { 7, 8 }, // V7 --- V8
       { 8, 5 }  // V8 --- V5
     };

V1 - V8 are the input vertices - counterclock!
H1 is a hole point - must be inside the declared segments below
Segments are defined by the V? vertices id
The dashed lines are actually the b2DistanceJoints

To refine the mesh, set the meshDensity (=maxVertexCount) parameter in CreateSoftBody() (attention with Box2D's constant's, eg Pairs,... 😉
some more examples

Code: Select all

tmVertex V[] = {
 { 0.00f, 0.00f},   {10.00f, 0.00f},
 { 8.00f, 2.00f},   { 4.00f, 1.00f},
 { 2.00f, 4.00f},   { 5.00f, 5.00f},
 { 0.00f, 7.00f},   { 1.00f, 5.00f},
 { 0.00f, 3.00f},
};
TriangleMesh md;
... set options
md.Mesh( V, 9 );

//Default: md.SetOption(tmO_MINIMALGRID|tmO_CONVEXHULL);
Image
time: ~0 ms

md.SetOption(tmO_SEGMENTBOUNDARY);
Image
time: ~0 ms

md.SetOption(tmO_SEGMENTBOUNDARY);
md.SetMaxVertexCount(1000); // mesh density
Image
time: ~16 ms

Used:WinXP, Intel Core 2Duo CPU, 2.2GHz, MSVC2005 compiler
Hrm... no one's commented on this. Is Box2D dying? I sure hope not.

Just wanted to say that this looks super cool. Thanks for posting 🙂
Yeah, the example animation is amazing. But I didn't realize that the source here includes a full constrained Delauney triangulator too. Now that is awesome.
Thanks nimodo. I added this to SVN.
We are just speechless, that's why there are no comments... and sure it's not dying!
BorisTheBrave wrote:Yeah, the example animation is amazing. But I didn't realize that the source here includes a full constrained Delauney triangulator too. Now that is awesome.

Wow - I can't believe I didn't catch that, we've been discussing constrained Delaunay triangulation implementations on the convex decomposition thread for a long while now. I'll definitely be putting this to use, great work!
Great work! Just ported it to Python and have been playing around with it for a while now. 🙂
Excellent work!!! I will be fudging around with this for some time...

The licence on TriangleMesh.cpp is a bit ambiguous about using this in a commercial product... there might be issues here. In the meantime I'm more excited about the awesomeness that will result from this than the potential legal issues that might arise from me trying to sell said awesomeness.

Original thread: https://box2d.org/forum/viewtopic.php?t=836