[New Port] JSBox2D! Release 2.3.1.r3

Hey there, guys.

I was pretty disappointed at the lack of a decent JS port of Box2D, so I decided to give myself a crack at it as I have a good use for it.
You can follow development & download here: https://code.google.com/p/jsbox2d

It is based off of the latest trunk version of Box2D.
Current release is JSBox2D 2.3.1.r3

-P
Hey that's really good to see! The outdated-ness of box2dweb and the Flash port are indeed a bit disappointing 🙂
Using Emscripten is easy to keep up to date but the resulting API is not so user-friendly. Looks like you have a good balance there, and keeping the files separated like that makes it a lot easier for others to come along later and add/mod stuff.
It seems a bit on the slow side though, I wonder if that's just to do with rendering.
Emscripten is nice but I find the generated code is fairly slow and hard to understand for a regular user. A native port should be faster, in theory anyways.

Rendering takes a huge percentage of the steps, yeah - canvas isn't the fastest thing in the world. The physics engine itself runs approximately 10x slower than it does in C++ (which is a lot better than I could have expected), and there are still a lot of optimization steps that can be taken to improve it more.

CCD is also broken at the moment, I am trying to figure out what is causing it to break. It seems to only be really broken with bullet bodies, but I can't for the life of me figure out where it is exactly causing issues.

The final build won't be separated into a lot of JS files but rather will be compiled into one JS file, + a minified version for production. The separate files make it easier to debug while it's being worked on.
Finally fixed CCD. Now I can push for a first release.
irresistible force wrote:Hey that's really good to see! The outdated-ness of box2dweb and the Flash port are indeed a bit disappointing 🙂
Using Emscripten is easy to keep up to date but the resulting API is not so user-friendly. Looks like you have a good balance there, and keeping the files separated like that makes it a lot easier for others to come along later and add/mod stuff.
It seems a bit on the slow side though, I wonder if that's just to do with rendering.


Hy!

I'm new here, after trying to register. It was not easy. :/
Anyway I'm here to show my new API that is a lot more user friendly than original Box2D.

You give it the original Box2D and it changes to the new Box2D:
- Hierarchy removed (if you don't want);
- No b2 prefix;
- Look at Joint definitions;

I've also created Rect, Circle and Shape (+ non-convex support) wrappers that are not shown here;
But hit is for 2.1 version, now I will upgrade to 2.3. Github repo is not yet available.


var _Box2D = {
b2Color : Box2D.Common.b2Color,
b2internal : Box2D.Common.b2internal,
b2Settings : Box2D.Common.b2Settings,
b2CircleShape : Box2D.Collision.Shapes.b2CircleShape,
b2EdgeChainDef : Box2D.Collision.Shapes.b2EdgeChainDef,
b2EdgeShape : Box2D.Collision.Shapes.b2EdgeShape,
b2MassData : Box2D.Collision.Shapes.b2MassData,
b2PolygonShape : Box2D.Collision.Shapes.b2PolygonShape,
b2Shape : Box2D.Collision.Shapes.b2Shape,
b2Mat22 : Box2D.Common.Math.b2Mat22,
b2Mat33 : Box2D.Common.Math.b2Mat33,
b2Math : Box2D.Common.Math.b2Math,
b2Sweep : Box2D.Common.Math.b2Sweep,
b2Transform : Box2D.Common.Math.b2Transform,
b2Vec2 : Box2D.Common.Math.b2Vec2,
b2Vec3 : Box2D.Common.Math.b2Vec3,
b2Body : Box2D.Dynamics.b2Body,
b2BodyDef : Box2D.Dynamics.b2BodyDef,
b2ContactFilter : Box2D.Dynamics.b2ContactFilter,
b2ContactImpulse : Box2D.Dynamics.b2ContactImpulse,
b2ContactListener : Box2D.Dynamics.b2ContactListener,
b2ContactManager : Box2D.Dynamics.b2ContactManager,
b2DebugDraw : Box2D.Dynamics.b2DebugDraw,
b2DestructionListener : Box2D.Dynamics.b2DestructionListener,
b2FilterData : Box2D.Dynamics.b2FilterData,
b2Fixture : Box2D.Dynamics.b2Fixture,
b2FixtureDef : Box2D.Dynamics.b2FixtureDef,
b2Island : Box2D.Dynamics.b2Island,
b2TimeStep : Box2D.Dynamics.b2TimeStep,
b2World : Box2D.Dynamics.b2World,
b2AABB : Box2D.Collision.b2AABB,
b2Bound : Box2D.Collision.b2Bound,
b2BoundValues : Box2D.Collision.b2BoundValues,
b2Collision : Box2D.Collision.b2Collision,
b2ContactID : Box2D.Collision.b2ContactID,
b2ContactPoint : Box2D.Collision.b2ContactPoint,
b2Distance : Box2D.Collision.b2Distance,
b2DistanceInput : Box2D.Collision.b2DistanceInput,
b2DistanceOutput : Box2D.Collision.b2DistanceOutput,
b2DistanceProxy : Box2D.Collision.b2DistanceProxy,
b2DynamicTree : Box2D.Collision.b2DynamicTree,
b2DynamicTreeBroadPhase : Box2D.Collision.b2DynamicTreeBroadPhase,
b2DynamicTreeNode : Box2D.Collision.b2DynamicTreeNode,
b2DynamicTreePair : Box2D.Collision.b2DynamicTreePair,
b2Manifold : Box2D.Collision.b2Manifold,
b2ManifoldPoint : Box2D.Collision.b2ManifoldPoint,
b2Point : Box2D.Collision.b2Point,
b2RayCastInput : Box2D.Collision.b2RayCastInput,
b2RayCastOutput : Box2D.Collision.b2RayCastOutput,
b2Segment : Box2D.Collision.b2Segment,
b2SeparationFunction : Box2D.Collision.b2SeparationFunction,
b2Simplex : Box2D.Collision.b2Simplex,
b2SimplexCache : Box2D.Collision.b2SimplexCache,
b2SimplexVertex : Box2D.Collision.b2SimplexVertex,
b2TimeOfImpact : Box2D.Collision.b2TimeOfImpact,
b2TOIInput : Box2D.Collision.b2TOIInput,
b2WorldManifold : Box2D.Collision.b2WorldManifold,
ClipVertex : Box2D.Collision.ClipVertex,
Features : Box2D.Collision.Features,
IBroadPhase : Box2D.Collision.IBroadPhase,



b2ControllerEdge : Box2D.Dynamics.Controllers.b2ControllerEdge,
b2Mat22 : Box2D.Common.Math.b2Mat22,
b2Mat33 : Box2D.Common.Math.b2Mat33,
b2Math : Box2D.Common.Math.b2Math,
b2Sweep : Box2D.Common.Math.b2Sweep,
b2Transform : Box2D.Common.Math.b2Transform,
b2Vec2 : Box2D.Common.Math.b2Vec2,
b2Vec3 : Box2D.Common.Math.b2Vec3,
b2Color : Box2D.Common.b2Color,
b2internal : Box2D.Common.b2internal,
b2Settings : Box2D.Common.b2Settings,
b2AABB : Box2D.Collision.b2AABB,
b2Bound : Box2D.Collision.b2Bound,
b2BoundValues : Box2D.Collision.b2BoundValues,
b2Collision : Box2D.Collision.b2Collision,
b2ContactID : Box2D.Collision.b2ContactID,
b2ContactPoint : Box2D.Collision.b2ContactPoint,
b2Distance : Box2D.Collision.b2Distance,
b2DistanceInput : Box2D.Collision.b2DistanceInput,
b2DistanceOutput : Box2D.Collision.b2DistanceOutput,
b2DistanceProxy : Box2D.Collision.b2DistanceProxy,
b2DynamicTree : Box2D.Collision.b2DynamicTree,
b2DynamicTreeBroadPhase : Box2D.Collision.b2DynamicTreeBroadPhase,
b2DynamicTreeNode : Box2D.Collision.b2DynamicTreeNode,
b2DynamicTreePair : Box2D.Collision.b2DynamicTreePair,
b2Manifold : Box2D.Collision.b2Manifold,
b2ManifoldPoint : Box2D.Collision.b2ManifoldPoint,
b2Point : Box2D.Collision.b2Point,
b2RayCastInput : Box2D.Collision.b2RayCastInput,
b2RayCastOutput : Box2D.Collision.b2RayCastOutput,
b2Segment : Box2D.Collision.b2Segment,
b2SeparationFunction : Box2D.Collision.b2SeparationFunction,
b2Simplex : Box2D.Collision.b2Simplex,
b2SimplexCache : Box2D.Collision.b2SimplexCache,
b2SimplexVertex : Box2D.Collision.b2SimplexVertex,
b2TimeOfImpact : Box2D.Collision.b2TimeOfImpact,
b2TOIInput : Box2D.Collision.b2TOIInput,
b2WorldManifold : Box2D.Collision.b2WorldManifold,
ClipVertex : Box2D.Collision.ClipVertex,
Features : Box2D.Collision.Features,
IBroadPhase : Box2D.Collision.IBroadPhase,
b2CircleShape : Box2D.Collision.Shapes.b2CircleShape,
b2EdgeChainDef : Box2D.Collision.Shapes.b2EdgeChainDef,
b2EdgeShape : Box2D.Collision.Shapes.b2EdgeShape,
b2MassData : Box2D.Collision.Shapes.b2MassData,
b2PolygonShape : Box2D.Collision.Shapes.b2PolygonShape,
b2Shape : Box2D.Collision.Shapes.b2Shape,
b2Body : Box2D.Dynamics.b2Body,
b2BodyDef : Box2D.Dynamics.b2BodyDef,
b2ContactFilter : Box2D.Dynamics.b2ContactFilter,
b2ContactImpulse : Box2D.Dynamics.b2ContactImpulse,
b2ContactListener : Box2D.Dynamics.b2ContactListener,
b2ContactManager : Box2D.Dynamics.b2ContactManager,
b2DebugDraw : Box2D.Dynamics.b2DebugDraw,
b2DestructionListener : Box2D.Dynamics.b2DestructionListener,
b2FilterData : Box2D.Dynamics.b2FilterData,
b2Fixture : Box2D.Dynamics.b2Fixture,
b2FixtureDef : Box2D.Dynamics.b2FixtureDef,
b2Island : Box2D.Dynamics.b2Island,
b2TimeStep : Box2D.Dynamics.b2TimeStep,
b2World : Box2D.Dynamics.b2World,
b2CircleContact : Box2D.Dynamics.Contacts.b2CircleContact,
b2Contact : Box2D.Dynamics.Contacts.b2Contact,
b2ContactConstraint : Box2D.Dynamics.Contacts.b2ContactConstraint,
b2ContactConstraintPoint : Box2D.Dynamics.Contacts.b2ContactConstraintPoint,
b2ContactEdge : Box2D.Dynamics.Contacts.b2ContactEdge,
b2ContactFactory : Box2D.Dynamics.Contacts.b2ContactFactory,
b2ContactRegister : Box2D.Dynamics.Contacts.b2ContactRegister,
b2ContactResult : Box2D.Dynamics.Contacts.b2ContactResult,
b2ContactSolver : Box2D.Dynamics.Contacts.b2ContactSolver,
b2EdgeAndCircleContact : Box2D.Dynamics.Contacts.b2EdgeAndCircleContact,
b2NullContact : Box2D.Dynamics.Contacts.b2NullContact,
b2PolyAndCircleContact : Box2D.Dynamics.Contacts.b2PolyAndCircleContact,
b2PolyAndEdgeContact : Box2D.Dynamics.Contacts.b2PolyAndEdgeContact,
b2PolygonContact : Box2D.Dynamics.Contacts.b2PolygonContact,
b2PositionSolverManifold : Box2D.Dynamics.Contacts.b2PositionSolverManifold,
b2Controller : Box2D.Dynamics.Controllers.b2Controller,
b2DistanceJoint : Box2D.Dynamics.Joints.b2DistanceJoint,
b2DistanceJointDef : Box2D.Dynamics.Joints.b2DistanceJointDef,
b2FrictionJoint : Box2D.Dynamics.Joints.b2FrictionJoint,
b2FrictionJointDef : Box2D.Dynamics.Joints.b2FrictionJointDef,
b2GearJoint : Box2D.Dynamics.Joints.b2GearJoint,
b2GearJointDef : Box2D.Dynamics.Joints.b2GearJointDef,
b2Jacobian : Box2D.Dynamics.Joints.b2Jacobian,
b2Joint : Box2D.Dynamics.Joints.b2Joint,
b2JointDef : Box2D.Dynamics.Joints.b2JointDef,
b2JointEdge : Box2D.Dynamics.Joints.b2JointEdge,
b2LineJoint : Box2D.Dynamics.Joints.b2LineJoint,
b2LineJointDef : Box2D.Dynamics.Joints.b2LineJointDef,
b2MouseJoint : Box2D.Dynamics.Joints.b2MouseJoint,
b2MouseJointDef : Box2D.Dynamics.Joints.b2MouseJointDef,
b2PrismaticJoint : Box2D.Dynamics.Joints.b2PrismaticJoint,
b2PrismaticJointDef : Box2D.Dynamics.Joints.b2PrismaticJointDef,
b2PulleyJoint : Box2D.Dynamics.Joints.b2PulleyJoint,
b2PulleyJointDef : Box2D.Dynamics.Joints.b2PulleyJointDef,
b2RevoluteJoint : Box2D.Dynamics.Joints.b2RevoluteJoint,
b2RevoluteJointDef : Box2D.Dynamics.Joints.b2RevoluteJointDef,
b2WeldJoint : Box2D.Dynamics.Joints.b2WeldJoint,
b2WeldJointDef : Box2D.Dynamics.Joints.b2WeldJointDef
}
// remove the b2 before all the names
var temp;
for(var k in _Box2D){
if(k.substr(0, 2) === 'b2'){
temp = _Box2D[k];
delete _Box2D[k];
_Box2D[k.substr(2, 100)] = temp;
}
}

// make definitions to accept an object instead of changing properties after instanced
_Box2D.RevoluteJointDef.prototype.b2RevoluteJointDef = function (options) {
this.__super.b2JointDef.call(this, options);
options = _.extend({
localAnchorA : new _Box2D.Vec2(0, 0),
localAnchorB : new _Box2D.Vec2(0, 0),
referenceAngle : 0,
lowerAngle : 0,
upperAngle : 0,
maxMotorTorque : 0,
motorSpeed : 0,
enableLimit : false,
enableMotor : false,
}, options)
this.type = _Box2D.Joint.e_revoluteJoint;
this.localAnchorA = options.localAnchorA;
this.localAnchorB = options.localAnchorB;
this.referenceAngle = options.referenceAngle;
this.lowerAngle = options.lowerAngle;
this.upperAngle = options.upperAngle;
this.maxMotorTorque = options.maxMotorTorque;
this.motorSpeed = options.motorSpeed;
this.enableLimit = options.enableLimit;
this.enableMotor = options.enableMotor;
}

_Box2D.DistanceJointDef.prototype.b2DistanceJointDef = function (options) {
this.__super.b2JointDef.call(this, options);
options = _.extend({
bodyA : null,
bodyB : null,
length : 1,
frequencyHz : 0,
dampingRatio : 0,
localAnchorA : new _Box2D.Vec2(0, 0),
localAnchorB : new _Box2D.Vec2(0, 0),
userData : null,
collideConnected : true,
}, options);
this.type = _Box2D.Joint.e_distanceJoint;
this.length = options.length;
this.frequencyHz = options.frequencyHz;
this.dampingRatio = options.dampingRatio;
this.localAnchorA = options.localAnchorA;
this.localAnchorB = options.localAnchorB;
this.collideConnected = options.collideConnected;
}
_Box2D.MouseJointDef.prototype.b2MouseJointDef = function (options) {
this.__super.b2JointDef.call(this, options);
options = _.extend({
maxForce : 0.0,
frequencyHz : 5.0,
dampingRatio : 0.7,
target : new _Box2D.Vec2(0, 0),
}, options);
this.type = _Box2D.Joint.e_mouseJoint;
this.maxForce = options.maxForce;
this.frequencyHz = options.frequencyHz;
this.dampingRatio = options.dampingRatio;
this.target = options.target;
}
_Box2D.PrismaticJointDef.prototype.b2PrismaticJointDef = function(options){
this.__super.b2JointDef.call(this, options);
options = _.extend({
localAxisA : [1.0, 0.0],
referenceAngle : 0.0,
enableLimit : false,
lowerTranslation : 0.0,
upperTranslation : 0.0,
enableMotor : false,
maxMotorForce : 0.0,
motorSpeed : 0.0,
localAnchorA : new _Box2D.Vec2(0, 0),
localAnchorB : new _Box2D.Vec2(0, 0),
}, options);
var o = options;
this.type = _Box2D.Joint.e_prismaticJoint;
this.localAxisA.Set.apply(this.localAxisA, o.localAxisA);
this.referenceAngle = o.referenceAngle;
this.enableLimit = o.enableLimit;
this.lowerTranslation = o.lowerTranslation;
this.upperTranslation = o.upperTranslation;
this.enableMotor = o.enableMotor;
this.maxMotorForce = o.maxMotorForce;
this.motorSpeed = o.motorSpeed;
this.localAnchorA = o.localAnchorA;
this.localAnchorB = o.localAnchorB;
}
_Box2D.JointDef.prototype.b2JointDef = function (options) {
this.type = _Box2D.Joint.e_unknownJoint;
options = _.extend({
userData : null,
bodyA : null,
bodyB : null,
}, options)
this.userData = options.userData;
this.bodyA = options.bodyA;
this.bodyB = options.bodyB;
if(!this.bodyA || !this.bodyB){
debugger;
throw new Error('bodyA or bodyB is missing')
}
this.collideConnected = false;
}
_Box2D.BodyDef.prototype.b2BodyDef = function (options) {
this.userData = options && typeof options.userData !== 'undefined' ? options.userData : null;
// this.position.Set(0.0, 0.0);
if(options){
this.position.x = typeof options.x !== 'undefined' ? options.x : 0;
this.position.y = typeof options.y !== 'undefined' ? options.y : 0;
}
this.linearVelocity.Set(0 , 0);
this.angle = 0.0;
this.angularVelocity = 0.0;
this.linearDamping = 0.0;
this.angularDamping = 0.0;
this.allowSleep = true;
this.awake = true;
this.fixedRotation = false;
this.bullet = false;
this.type = options && options.type ? options.type : _Box2D.Body.b2_staticBody;
this.active = true;
this.inertiaScale = 1.0;
}

// open plugins
_Box2D.original = Box2D;
_Box2D.Separator = b2Separator(_Box2D.original);

// @todo1:
// camel case methods
// for example we don't want a.CreateWorld
// but a.createWorld, as it's standard

// @todo2: event listeners for world instead of class
return _Box2D;
Paril wrote:Hey there, guys.

I was pretty disappointed at the lack of a decent JS port of Box2D, so I decided to give myself a crack at it as I have a good use for it.
You can follow development & download here: https://code.google.com/p/jsbox2d

It is based off of the latest trunk version of Box2D.
Current release is JSBox2D 2.3.1.r1

-P


Hy!

First of all thanks for you port! (:
My I ask you why you attach it to the window object? It might be more modular using a Box2D object.
Anyway, that is not a problem. But there is no DebugDraw class?
Hi.

Your first post above is not for this port, it need not be here. My port uses global names like the C++ version does (b2Color, etc).
b2DebugDraw is called b2Draw in the latest C++ trunk version. That's what this version is based off of.

I attach it to window at the moment as it's meant to be a browser-based system. I will mess with possible alternatives later on. The build system is still very early.
I originally messed with the idea of using a separator, such as "b2.CircleShape". I might return to that idea as it allows some nice documentation for the objects contained within the scope. Might also provide a static variable for re-integrating them into the window object for compatibility purposes.

I also do like the idea of constructors, but I am trying to provide as close to a 1:1 parity with the C++ version as I can. The further I stray from it will cause issues when I have to merge newer commits.

-P
Paril wrote:Hi.

Your first post above is not for this port, it need not be here. My port uses global names like the C++ version does (b2Color, etc).
b2DebugDraw is called b2Draw in the latest C++ trunk version. That's what this version is based off of.

I attach it to window at the moment as it's meant to be a browser-based system. I will mess with possible alternatives later on. The build system is still very early.
I originally messed with the idea of using a separator, such as "b2.CircleShape". I might return to that idea as it allows some nice documentation for the objects contained within the scope. Might also provide a static variable for re-integrating them into the window object for compatibility purposes.

I also do like the idea of constructors, but I am trying to provide as close to a 1:1 parity with the C++ version as I can. The further I stray from it will cause issues when I have to merge newer commits.

-P

Well I've already "played" with your port but the Draw doesn't work neither, I will try later.
About the constructors, is not so dangerous because you still maintain the original port in a file. Then in another you import the original port and change the constructors, so in the new port, you just change the original port file. If anything is needed to be changed in the contructor api, you can easily change the second file.

This is the approach I'm doing right now.

Here is my "mod" for your port:
After that run:
// remove the b2 prefix
var temp;
for(var k in Box2D){
if(k.substr(0, 2) === 'b2'){
temp = _Box2D[k];
delete _Box2D[k];
Box2D[k.substr(2, 100)] = temp;
}
}

// mod:
Box2D["b2_version"] = b2_version;
Box2D["b2Vec2"] = b2Vec2;
Box2D["b2Vec3"] = b2Vec3;
Box2D["b2Mat22"] = b2Mat22;
Box2D["b2Mat33"] = b2Mat33;
Box2D["b2Rot"] = b2Rot;
Box2D["b2Transform"] = b2Transform;
Box2D["b2Sweep"] = b2Sweep;
Box2D["b2Dot_v2_v2"] = b2Dot_v2_v2;
Box2D["b2Cross_v2_v2"] = b2Cross_v2_v2;
Box2D["b2Cross_v2_f"] = b2Cross_v2_f;
Box2D["b2Cross_f_v2"] = b2Cross_f_v2;
Box2D["b2Mul_m22_v2"] = b2Mul_m22_v2;
Box2D["b2MulT_m22_v2"] = b2MulT_m22_v2;
Box2D["b2Distance"] = b2Distance;
Box2D["b2DistanceSquared"] = b2DistanceSquared;
Box2D["b2Dot_v3_v3"] = b2Dot_v3_v3;
Box2D["b2Cross_v3_v3"] = b2Cross_v3_v3;
Box2D["b2Mul_m22_m22"] = b2Mul_m22_m22;
Box2D["b2MulT_m22_m22"] = b2MulT_m22_m22;
Box2D["b2Mul_m33_v3"] = b2Mul_m33_v3;
Box2D["b2Mul22_m33_v2"] = b2Mul22_m33_v2;
Box2D["b2Mul_r_r"] = b2Mul_r_r;
Box2D["b2MulT_r_r"] = b2MulT_r_r;
Box2D["b2Mul_r_v2"] = b2Mul_r_v2;
Box2D["b2MulT_r_v2"] = b2MulT_r_v2;
Box2D["b2Mul_t_v2"] = b2Mul_t_v2;
Box2D["b2Min_v2"] = b2Min_v2;
Box2D["b2Max_v2"] = b2Max_v2;
Box2D["b2Clamp"] = b2Clamp;
Box2D["b2MulT_t_v2"] = b2MulT_t_v2;
Box2D["b2Mul_t_t"] = b2Mul_t_t;
Box2D["b2MulT_t_t"] = b2MulT_t_t;
Box2D["b2Clamp_v2"] = b2Clamp_v2;
Box2D["b2NextPowerOfTwo"] = b2NextPowerOfTwo;
Box2D["b2Abs_v2"] = b2Abs_v2;
Box2D["b2Abs_m22"] = b2Abs_m22;
Box2D["b2IsPowerOfTwo"] = b2IsPowerOfTwo;
Box2D["b2RandomFloat"] = b2RandomFloat;
Box2D["b2Timer"] = b2Timer;
Box2D["b2Color"] = b2Color;
Box2D["b2Draw"] = b2Draw;
Box2D["b2ContactID"] = b2ContactID;
Box2D["b2ManifoldPoint"] = b2ManifoldPoint;
Box2D["b2Manifold"] = b2Manifold;
Box2D["b2WorldManifold"] = b2WorldManifold;
Box2D["b2GetPointStates"] = b2GetPointStates;
Box2D["b2ClipVertex"] = b2ClipVertex;
Box2D["b2RayCastInput"] = b2RayCastInput;
Box2D["b2RayCastOutput"] = b2RayCastOutput;
Box2D["b2AABB"] = b2AABB;
Box2D["b2CollideCircles"] = b2CollideCircles;
Box2D["b2CollidePolygonAndCircle"] = b2CollidePolygonAndCircle;
Box2D["b2FindMaxSeparation"] = b2FindMaxSeparation;
Box2D["b2FindIncidentEdge"] = b2FindIncidentEdge;
Box2D["b2CollidePolygons"] = b2CollidePolygons;
Box2D["b2CollideEdgeAndCircle"] = b2CollideEdgeAndCircle;
Box2D["b2EPAxis"] = b2EPAxis;
Box2D["b2TempPolygon"] = b2TempPolygon;
Box2D["b2ReferenceFace"] = b2ReferenceFace;
Box2D["b2EPCollider"] = b2EPCollider;
Box2D["b2CollideEdgeAndPolygon"] = b2CollideEdgeAndPolygon;
Box2D["b2ClipSegmentToLine"] = b2ClipSegmentToLine;
Box2D["b2TestShapeOverlap"] = b2TestShapeOverlap;
Box2D["b2TestOverlap"] = b2TestOverlap;
Box2D["b2Shape"] = b2Shape;
Box2D["b2CircleShape"] = b2CircleShape;
Box2D["b2EdgeShape"] = b2EdgeShape;
Box2D["b2ChainShape"] = b2ChainShape;
Box2D["b2PolygonShape"] = b2PolygonShape;
Box2D["b2Pair"] = b2Pair;
Box2D["b2PairLessThan"] = b2PairLessThan;
Box2D["b2BroadPhase"] = b2BroadPhase;
Box2D["b2DistanceProxy"] = b2DistanceProxy;
Box2D["b2SimplexCache"] = b2SimplexCache;
Box2D["b2DistanceInput"] = b2DistanceInput;
Box2D["b2DistanceOutput"] = b2DistanceOutput;
Box2D["b2SimplexVertex"] = b2SimplexVertex;
Box2D["b2Simplex"] = b2Simplex;
Box2D["b2DistanceFunc"] = b2DistanceFunc;
Box2D["b2TreeNode"] = b2TreeNode;
Box2D["b2DynamicTree"] = b2DynamicTree;
Box2D["b2TOIInput"] = b2TOIInput;
Box2D["b2TOIOutput"] = b2TOIOutput;
Box2D["b2SeparationFunction"] = b2SeparationFunction;
Box2D["b2TimeOfImpact"] = b2TimeOfImpact;
Box2D["b2BodyDef"] = b2BodyDef;
Box2D["b2Body"] = b2Body;
Box2D["b2Filter"] = b2Filter;
Box2D["b2FixtureDef"] = b2FixtureDef;
Box2D["b2Fixture"] = b2Fixture;
Box2D["b2DestructionListener"] = b2DestructionListener;
Box2D["b2ContactFilter"] = b2ContactFilter;
Box2D["b2ContactImpulse"] = b2ContactImpulse;
Box2D["b2ContactListener"] = b2ContactListener;
Box2D["b2QueryCallback"] = b2QueryCallback;
Box2D["b2RayCastCallback"] = b2RayCastCallback;
Box2D["b2TimeStep"] = b2TimeStep;
Box2D["b2Position"] = b2Position;
Box2D["b2Velocity"] = b2Velocity;
Box2D["b2SolverData"] = b2SolverData;
Box2D["b2World"] = b2World;
Box2D["b2MixFriction"] = b2MixFriction;
Box2D["b2MixRestitution"] = b2MixRestitution;
Box2D["b2ContactRegister"] = b2ContactRegister;
Box2D["b2ContactEdge"] = b2ContactEdge;
Box2D["b2Contact"] = b2Contact;
Box2D["b2CircleContact"] = b2CircleContact;
Box2D["b2PolygonContact"] = b2PolygonContact;
Box2D["b2ChainAndCircleContact"] = b2ChainAndCircleContact;
Box2D["b2ChainAndPolygonContact"] = b2ChainAndPolygonContact;
Box2D["b2EdgeAndCircleContact"] = b2EdgeAndCircleContact;
Box2D["b2EdgeAndPolygonContact"] = b2EdgeAndPolygonContact;
Box2D["b2PolygonAndCircleContact"] = b2PolygonAndCircleContact;
Box2D["b2_defaultFilter"] = b2_defaultFilter;
Box2D["b2_defaultListener"] = b2_defaultListener;
Box2D["b2ContactManager"] = b2ContactManager;
Box2D["b2VelocityConstraintPoint"] = b2VelocityConstraintPoint;
Box2D["b2ContactPositionConstraint"] = b2ContactPositionConstraint;
Box2D["b2ContactVelocityConstraint"] = b2ContactVelocityConstraint;
Box2D["b2PositionSolverManifold"] = b2PositionSolverManifold;
Box2D["b2ContactSolverDef"] = b2ContactSolverDef;
Box2D["b2ContactSolver"] = b2ContactSolver;
Box2D["b2Island"] = b2Island;
Box2D["b2Jacobian"] = b2Jacobian;
Box2D["b2JointEdge"] = b2JointEdge;
Box2D["b2JointDef"] = b2JointDef;
Box2D["b2Joint"] = b2Joint;
Box2D["b2RevoluteJointDef"] = b2RevoluteJointDef;
Box2D["b2RevoluteJoint"] = b2RevoluteJoint;
Box2D["b2MouseJointDef"] = b2MouseJointDef;
Box2D["b2MouseJoint"] = b2MouseJoint;
Box2D["b2DistanceJointDef"] = b2DistanceJointDef;
Box2D["b2DistanceJoint"] = b2DistanceJoint;
Box2D["b2PrismaticJointDef"] = b2PrismaticJointDef;
Box2D["b2PrismaticJoint"] = b2PrismaticJoint;
Box2D["b2FrictionJointDef"] = b2FrictionJointDef;
Box2D["b2FrictionJoint"] = b2FrictionJoint;
Box2D["b2WeldJointDef"] = b2WeldJointDef;
Box2D["b2WeldJoint"] = b2WeldJoint;
Box2D["b2WheelJointDef"] = b2WheelJointDef;
Box2D["b2WheelJoint"] = b2WheelJoint;
Box2D["b2GearJointDef"] = b2GearJointDef;
Box2D["b2GearJoint"] = b2GearJoint;
Box2D["b2MotorJointDef"] = b2MotorJointDef;
Box2D["b2MotorJoint"] = b2MotorJoint;
Box2D["b2PulleyJointDef"] = b2PulleyJointDef;
Box2D["b2PulleyJoint"] = b2PulleyJoint;
Box2D["b2RopeJointDef"] = b2RopeJointDef;
Box2D["b2RopeJoint"] = b2RopeJoint;
Box2D["b2RopeDef"] = b2RopeDef;
Box2D["b2Rope"] = b2Rope;
Box2D["b2_maxManifoldPoints"] = b2_maxManifoldPoints;
Box2D["b2_maxPolygonVertices"] = b2_maxPolygonVertices;
Box2D["b2_aabbExtension"] = b2_aabbExtension;
Box2D["b2_aabbMultiplier"] = b2_aabbMultiplier;
Box2D["b2_linearSlop"] = b2_linearSlop;
Box2D["b2_angularSlop"] = b2_angularSlop;
Box2D["b2_polygonRadius"] = b2_polygonRadius;
Box2D["b2_maxSubSteps"] = b2_maxSubSteps;
Box2D["b2_maxTOIContacts"] = b2_maxTOIContacts;
Box2D["b2_velocityThreshold"] = b2_velocityThreshold;
Box2D["b2_maxLinearCorrection"] = b2_maxLinearCorrection;
Box2D["b2_maxAngularCorrection"] = b2_maxAngularCorrection;
Box2D["b2_maxTranslation"] = b2_maxTranslation;
Box2D["b2_maxTranslationSquared"] = b2_maxTranslationSquared;
Box2D["b2_maxRotation"] = b2_maxRotation;
Box2D["b2_maxRotationSquared"] = b2_maxRotationSquared;
Box2D["b2_baumgarte"] = b2_baumgarte;
Box2D["b2_toiBaugarte"] = b2_toiBaugarte;
Box2D["b2_timeToSleep"] = b2_timeToSleep;
Box2D["b2_linearSleepTolerance"] = b2_linearSleepTolerance;
Box2D["b2_angularSleepTolerance"] = b2_angularSleepTolerance;
Box2D["b2_epsilon"] = b2_epsilon;
Box2D["b2JsonSerializer"] = b2JsonSerializer;
Box2D["b2RUBELoader"] = b2RUBELoader;
Box2D["b2Profiler"] = b2Profiler;
ttt wrote:
Paril wrote:Hi.

Your first post above is not for this port, it need not be here. My port uses global names like the C++ version does (b2Color, etc).
b2DebugDraw is called b2Draw in the latest C++ trunk version. That's what this version is based off of.

I attach it to window at the moment as it's meant to be a browser-based system. I will mess with possible alternatives later on. The build system is still very early.
I originally messed with the idea of using a separator, such as "b2.CircleShape". I might return to that idea as it allows some nice documentation for the objects contained within the scope. Might also provide a static variable for re-integrating them into the window object for compatibility purposes.

I also do like the idea of constructors, but I am trying to provide as close to a 1:1 parity with the C++ version as I can. The further I stray from it will cause issues when I have to merge newer commits.

-P

Well I've already "played" with your port but the Draw doesn't work neither, I will try later.
About the constructors, is not so dangerous because you still maintain the original port in a file. Then in another you import the original port and change the constructors, so in the new port, you just change the original port file. If anything is needed to be changed in the contructor api, you can easily change the second file.

This is the approach I'm doing right now.

Here is my "mod" for your port:
After that run:
// remove the b2 prefix
var temp;
for(var k in Box2D){
if(k.substr(0, 2) === 'b2'){
temp = _Box2D[k];
delete _Box2D[k];
Box2D[k.substr(2, 100)] = temp;
}
}

// mod:
Box2D["b2_version"] = b2_version;
Box2D["b2Vec2"] = b2Vec2;
Box2D["b2Vec3"] = b2Vec3;
Box2D["b2Mat22"] = b2Mat22;
Box2D["b2Mat33"] = b2Mat33;
Box2D["b2Rot"] = b2Rot;
Box2D["b2Transform"] = b2Transform;
Box2D["b2Sweep"] = b2Sweep;
Box2D["b2Dot_v2_v2"] = b2Dot_v2_v2;
Box2D["b2Cross_v2_v2"] = b2Cross_v2_v2;
Box2D["b2Cross_v2_f"] = b2Cross_v2_f;
Box2D["b2Cross_f_v2"] = b2Cross_f_v2;
Box2D["b2Mul_m22_v2"] = b2Mul_m22_v2;
Box2D["b2MulT_m22_v2"] = b2MulT_m22_v2;
Box2D["b2Distance"] = b2Distance;
Box2D["b2DistanceSquared"] = b2DistanceSquared;
Box2D["b2Dot_v3_v3"] = b2Dot_v3_v3;
Box2D["b2Cross_v3_v3"] = b2Cross_v3_v3;
Box2D["b2Mul_m22_m22"] = b2Mul_m22_m22;
Box2D["b2MulT_m22_m22"] = b2MulT_m22_m22;
Box2D["b2Mul_m33_v3"] = b2Mul_m33_v3;
Box2D["b2Mul22_m33_v2"] = b2Mul22_m33_v2;
Box2D["b2Mul_r_r"] = b2Mul_r_r;
Box2D["b2MulT_r_r"] = b2MulT_r_r;
Box2D["b2Mul_r_v2"] = b2Mul_r_v2;
Box2D["b2MulT_r_v2"] = b2MulT_r_v2;
Box2D["b2Mul_t_v2"] = b2Mul_t_v2;
Box2D["b2Min_v2"] = b2Min_v2;
Box2D["b2Max_v2"] = b2Max_v2;
Box2D["b2Clamp"] = b2Clamp;
Box2D["b2MulT_t_v2"] = b2MulT_t_v2;
Box2D["b2Mul_t_t"] = b2Mul_t_t;
Box2D["b2MulT_t_t"] = b2MulT_t_t;
Box2D["b2Clamp_v2"] = b2Clamp_v2;
Box2D["b2NextPowerOfTwo"] = b2NextPowerOfTwo;
Box2D["b2Abs_v2"] = b2Abs_v2;
Box2D["b2Abs_m22"] = b2Abs_m22;
Box2D["b2IsPowerOfTwo"] = b2IsPowerOfTwo;
Box2D["b2RandomFloat"] = b2RandomFloat;
Box2D["b2Timer"] = b2Timer;
Box2D["b2Color"] = b2Color;
Box2D["b2Draw"] = b2Draw;
Box2D["b2ContactID"] = b2ContactID;
Box2D["b2ManifoldPoint"] = b2ManifoldPoint;
Box2D["b2Manifold"] = b2Manifold;
Box2D["b2WorldManifold"] = b2WorldManifold;
Box2D["b2GetPointStates"] = b2GetPointStates;
Box2D["b2ClipVertex"] = b2ClipVertex;
Box2D["b2RayCastInput"] = b2RayCastInput;
Box2D["b2RayCastOutput"] = b2RayCastOutput;
Box2D["b2AABB"] = b2AABB;
Box2D["b2CollideCircles"] = b2CollideCircles;
Box2D["b2CollidePolygonAndCircle"] = b2CollidePolygonAndCircle;
Box2D["b2FindMaxSeparation"] = b2FindMaxSeparation;
Box2D["b2FindIncidentEdge"] = b2FindIncidentEdge;
Box2D["b2CollidePolygons"] = b2CollidePolygons;
Box2D["b2CollideEdgeAndCircle"] = b2CollideEdgeAndCircle;
Box2D["b2EPAxis"] = b2EPAxis;
Box2D["b2TempPolygon"] = b2TempPolygon;
Box2D["b2ReferenceFace"] = b2ReferenceFace;
Box2D["b2EPCollider"] = b2EPCollider;
Box2D["b2CollideEdgeAndPolygon"] = b2CollideEdgeAndPolygon;
Box2D["b2ClipSegmentToLine"] = b2ClipSegmentToLine;
Box2D["b2TestShapeOverlap"] = b2TestShapeOverlap;
Box2D["b2TestOverlap"] = b2TestOverlap;
Box2D["b2Shape"] = b2Shape;
Box2D["b2CircleShape"] = b2CircleShape;
Box2D["b2EdgeShape"] = b2EdgeShape;
Box2D["b2ChainShape"] = b2ChainShape;
Box2D["b2PolygonShape"] = b2PolygonShape;
Box2D["b2Pair"] = b2Pair;
Box2D["b2PairLessThan"] = b2PairLessThan;
Box2D["b2BroadPhase"] = b2BroadPhase;
Box2D["b2DistanceProxy"] = b2DistanceProxy;
Box2D["b2SimplexCache"] = b2SimplexCache;
Box2D["b2DistanceInput"] = b2DistanceInput;
Box2D["b2DistanceOutput"] = b2DistanceOutput;
Box2D["b2SimplexVertex"] = b2SimplexVertex;
Box2D["b2Simplex"] = b2Simplex;
Box2D["b2DistanceFunc"] = b2DistanceFunc;
Box2D["b2TreeNode"] = b2TreeNode;
Box2D["b2DynamicTree"] = b2DynamicTree;
Box2D["b2TOIInput"] = b2TOIInput;
Box2D["b2TOIOutput"] = b2TOIOutput;
Box2D["b2SeparationFunction"] = b2SeparationFunction;
Box2D["b2TimeOfImpact"] = b2TimeOfImpact;
Box2D["b2BodyDef"] = b2BodyDef;
Box2D["b2Body"] = b2Body;
Box2D["b2Filter"] = b2Filter;
Box2D["b2FixtureDef"] = b2FixtureDef;
Box2D["b2Fixture"] = b2Fixture;
Box2D["b2DestructionListener"] = b2DestructionListener;
Box2D["b2ContactFilter"] = b2ContactFilter;
Box2D["b2ContactImpulse"] = b2ContactImpulse;
Box2D["b2ContactListener"] = b2ContactListener;
Box2D["b2QueryCallback"] = b2QueryCallback;
Box2D["b2RayCastCallback"] = b2RayCastCallback;
Box2D["b2TimeStep"] = b2TimeStep;
Box2D["b2Position"] = b2Position;
Box2D["b2Velocity"] = b2Velocity;
Box2D["b2SolverData"] = b2SolverData;
Box2D["b2World"] = b2World;
Box2D["b2MixFriction"] = b2MixFriction;
Box2D["b2MixRestitution"] = b2MixRestitution;
Box2D["b2ContactRegister"] = b2ContactRegister;
Box2D["b2ContactEdge"] = b2ContactEdge;
Box2D["b2Contact"] = b2Contact;
Box2D["b2CircleContact"] = b2CircleContact;
Box2D["b2PolygonContact"] = b2PolygonContact;
Box2D["b2ChainAndCircleContact"] = b2ChainAndCircleContact;
Box2D["b2ChainAndPolygonContact"] = b2ChainAndPolygonContact;
Box2D["b2EdgeAndCircleContact"] = b2EdgeAndCircleContact;
Box2D["b2EdgeAndPolygonContact"] = b2EdgeAndPolygonContact;
Box2D["b2PolygonAndCircleContact"] = b2PolygonAndCircleContact;
Box2D["b2_defaultFilter"] = b2_defaultFilter;
Box2D["b2_defaultListener"] = b2_defaultListener;
Box2D["b2ContactManager"] = b2ContactManager;
Box2D["b2VelocityConstraintPoint"] = b2VelocityConstraintPoint;
Box2D["b2ContactPositionConstraint"] = b2ContactPositionConstraint;
Box2D["b2ContactVelocityConstraint"] = b2ContactVelocityConstraint;
Box2D["b2PositionSolverManifold"] = b2PositionSolverManifold;
Box2D["b2ContactSolverDef"] = b2ContactSolverDef;
Box2D["b2ContactSolver"] = b2ContactSolver;
Box2D["b2Island"] = b2Island;
Box2D["b2Jacobian"] = b2Jacobian;
Box2D["b2JointEdge"] = b2JointEdge;
Box2D["b2JointDef"] = b2JointDef;
Box2D["b2Joint"] = b2Joint;
Box2D["b2RevoluteJointDef"] = b2RevoluteJointDef;
Box2D["b2RevoluteJoint"] = b2RevoluteJoint;
Box2D["b2MouseJointDef"] = b2MouseJointDef;
Box2D["b2MouseJoint"] = b2MouseJoint;
Box2D["b2DistanceJointDef"] = b2DistanceJointDef;
Box2D["b2DistanceJoint"] = b2DistanceJoint;
Box2D["b2PrismaticJointDef"] = b2PrismaticJointDef;
Box2D["b2PrismaticJoint"] = b2PrismaticJoint;
Box2D["b2FrictionJointDef"] = b2FrictionJointDef;
Box2D["b2FrictionJoint"] = b2FrictionJoint;
Box2D["b2WeldJointDef"] = b2WeldJointDef;
Box2D["b2WeldJoint"] = b2WeldJoint;
Box2D["b2WheelJointDef"] = b2WheelJointDef;
Box2D["b2WheelJoint"] = b2WheelJoint;
Box2D["b2GearJointDef"] = b2GearJointDef;
Box2D["b2GearJoint"] = b2GearJoint;
Box2D["b2MotorJointDef"] = b2MotorJointDef;
Box2D["b2MotorJoint"] = b2MotorJoint;
Box2D["b2PulleyJointDef"] = b2PulleyJointDef;
Box2D["b2PulleyJoint"] = b2PulleyJoint;
Box2D["b2RopeJointDef"] = b2RopeJointDef;
Box2D["b2RopeJoint"] = b2RopeJoint;
Box2D["b2RopeDef"] = b2RopeDef;
Box2D["b2Rope"] = b2Rope;
Box2D["b2_maxManifoldPoints"] = b2_maxManifoldPoints;
Box2D["b2_maxPolygonVertices"] = b2_maxPolygonVertices;
Box2D["b2_aabbExtension"] = b2_aabbExtension;
Box2D["b2_aabbMultiplier"] = b2_aabbMultiplier;
Box2D["b2_linearSlop"] = b2_linearSlop;
Box2D["b2_angularSlop"] = b2_angularSlop;
Box2D["b2_polygonRadius"] = b2_polygonRadius;
Box2D["b2_maxSubSteps"] = b2_maxSubSteps;
Box2D["b2_maxTOIContacts"] = b2_maxTOIContacts;
Box2D["b2_velocityThreshold"] = b2_velocityThreshold;
Box2D["b2_maxLinearCorrection"] = b2_maxLinearCorrection;
Box2D["b2_maxAngularCorrection"] = b2_maxAngularCorrection;
Box2D["b2_maxTranslation"] = b2_maxTranslation;
Box2D["b2_maxTranslationSquared"] = b2_maxTranslationSquared;
Box2D["b2_maxRotation"] = b2_maxRotation;
Box2D["b2_maxRotationSquared"] = b2_maxRotationSquared;
Box2D["b2_baumgarte"] = b2_baumgarte;
Box2D["b2_toiBaugarte"] = b2_toiBaugarte;
Box2D["b2_timeToSleep"] = b2_timeToSleep;
Box2D["b2_linearSleepTolerance"] = b2_linearSleepTolerance;
Box2D["b2_angularSleepTolerance"] = b2_angularSleepTolerance;
Box2D["b2_epsilon"] = b2_epsilon;
Box2D["b2JsonSerializer"] = b2JsonSerializer;
Box2D["b2RUBELoader"] = b2RUBELoader;
Box2D["b2Profiler"] = b2Profiler;



Well, you were right it works with the b2Draw but it's missing some methods. Anyway I can't use right now because my game depends on b2Separator plugin that needs a Box2D with hierarchy :/. That is not a problem neither because I have the hierarchy from the previous Box2D version and I can match. There will be some problems as the b2Draw but not a lot more, I think.
I provide a Canvas-based draw in the root of the trunk you can look at.
r3 now provides a module-based build; by default, if 'window' is there, it will define window.b2 to be the Box2D namespace (ie, b2.Vec2, b2.World, etc). If you create a global var named "b2_compatibility", it will instead use the old global method.

Which methods are missing?

-P

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