Deformable and breakable body - sample

Here's the place to get help and discuss features. The focus is on the C++ version, but generic questions are welcome.
nimodo
Posts: 75
Joined: Sat Feb 09, 2008 4:00 pm

Deformable and breakable body - sample

Postby nimodo » Fri May 09, 2008 5:15 am

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
Attachments
BreakableBody.h
Updated 26.09.2008-100
(22.12 KiB) Downloaded 693 times
TriangleMesh.cpp
Updated 08.08.2008-103
(38.47 KiB) Downloaded 678 times
TriangleMesh.h
Updated 17.07.2008-72
(7.79 KiB) Downloaded 615 times
Last edited by nimodo on Fri Sep 26, 2008 2:58 am, edited 16 times in total.

nimodo
Posts: 75
Joined: Sat Feb 09, 2008 4:00 pm

Re: Deformable and breakable body - sample

Postby nimodo » Fri May 09, 2008 5:15 am

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,... ;)

nimodo
Posts: 75
Joined: Sat Feb 09, 2008 4:00 pm

Re: Deformable and breakable body - sample

Postby nimodo » Sat May 31, 2008 3:37 pm

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

darkzerox
Posts: 241
Joined: Fri Dec 07, 2007 3:09 pm

Re: Deformable and breakable body - sample

Postby darkzerox » Sun Jun 01, 2008 12:30 pm

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 :)

BorisTheBrave
Posts: 1911
Joined: Mon Jan 07, 2008 10:51 am
Contact:

Re: Deformable and breakable body - sample

Postby BorisTheBrave » Sun Jun 01, 2008 1:12 pm

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.

Erin Catto
Site Admin
Posts: 2948
Joined: Thu Sep 06, 2007 12:34 am

Re: Deformable and breakable body - sample

Postby Erin Catto » Sun Jun 01, 2008 1:29 pm

Thanks nimodo. I added this to SVN.

ivailo91
Posts: 25
Joined: Thu May 08, 2008 12:33 pm

Re: Deformable and breakable body - sample

Postby ivailo91 » Sun Jun 01, 2008 2:02 pm

We are just speechless, that's why there are no comments... and sure it's not dying!

ewjordan
Posts: 803
Joined: Sun Sep 23, 2007 2:35 pm

Re: Deformable and breakable body - sample

Postby ewjordan » Sun Jun 01, 2008 5:50 pm

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!

kne
Posts: 88
Joined: Mon Feb 18, 2008 12:30 am

Re: Deformable and breakable body - sample

Postby kne » Tue Jun 03, 2008 2:23 am

Great work! Just ported it to Python and have been playing around with it for a while now. :)

dc443
Posts: 341
Joined: Fri May 16, 2008 10:09 am

Re: Deformable and breakable body - sample

Postby dc443 » Tue Jun 03, 2008 11:56 am

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.


Return to “General Discussion”



Who is online

Users browsing this forum: No registered users and 3 guests