Well, after many moons of delay, BoxCAD now generates pristine AS3 code. Only for fundamental objects and constraints (none of the fancy stuff yet, like particle engines/controllers/etc), but still a very useful subset of Box2D’s functionality.
Here’s a clip of the code output from the MoonTank file:
// New Polygon Shape & Body.
polygonDef = new b2PolygonDef();
polygonDef.vertexCount = 4;
polygonDef.vertices[0].Set(0.6000000000000005, -0.19999999999999996);
polygonDef.vertices[1].Set(0.6000000000000005, 0.19999999999999996);
polygonDef.vertices[2].Set(-0.6000000000000005, 0.19999999999999996);
polygonDef.vertices[3].Set(-0.6000000000000005, -0.19999999999999996);
polygonDef.friction = 0.2;
polygonDef.restitution = 0.4;
polygonDef.density = 1;
polygonDef.filter.groupIndex = -1;
bodyDef = new b2BodyDef();
bodyDef.position = new b2Vec2(4.056582535099032, 18.045220905705396);
bodyDef.angle = 0.41509286801864664;
newBody = m_world.CreateBody(bodyDef);
newBody.CreateShape(polygonDef);
newBody.SetMassFromShapes();
arrBodyList["30075"] = newBody;
// New Polygon Shape & Body.
polygonDef = new b2PolygonDef();
polygonDef.vertexCount = 4;
polygonDef.vertices[0].Set(0.6000000000000005, -0.19999999999999996);
polygonDef.vertices[1].Set(0.6000000000000005, 0.19999999999999996);
polygonDef.vertices[2].Set(-0.6000000000000005, 0.19999999999999996);
polygonDef.vertices[3].Set(-0.6000000000000005, -0.19999999999999996);
polygonDef.friction = 0.2;
polygonDef.restitution = 0.4;
polygonDef.density = 1;
polygonDef.filter.groupIndex = -1;
bodyDef = new b2BodyDef();
bodyDef.position = new b2Vec2(3.08373731317662, 17.90830170541888);
bodyDef.angle = -0.1395542297981954;
newBody = m_world.CreateBody(bodyDef);
newBody.CreateShape(polygonDef);
newBody.SetMassFromShapes();
arrBodyList["29906"] = newBody;
// New Revolute Joint.
rJointDef = new b2RevoluteJointDef();
rJointDef.Initialize(arrBodyList['30118'], arrBodyList['30120'], new b2Vec2(9.062264928353713, 20.28247519314447));
rJointDef.enableLimit = true;
rJointDef.lowerAngle = 0;
rJointDef.upperAngle = 0;
m_world.CreateJoint(rJointDef);
// New Revolute Joint.
rJointDef = new b2RevoluteJointDef();
rJointDef.Initialize(arrBodyList['30114'], arrBodyList['30118'], new b2Vec2(3.3360183210518954, 19.479990925312997));
rJointDef.enableLimit = false;
rJointDef.lowerAngle = 0;
rJointDef.upperAngle = 0;
m_world.CreateJoint(rJointDef);
That is two tread segments and two revolute joints. Imagine doing 20 tread segments by hand….
To make the development of flash physics apps even easier – here is a basic application skeleton. It supplies a convenient home, with basic mouse interaction, for BoxCAD’s output.
BoxCAD, of course, can be found on the main BoxCAD page.







