You're definitely targeting a gaping niche IMO though (same one I'm trying to fill through a side project). Using Box2D in JavaScript feels like programming in assembly sometimes.
[1]: https://github.com/davidgomes/pentagine/blob/master/tools/me...
EDIT: Already filled in a pull request, the code looks quite good.
You should seriously consider employing techniques such as LLJS[1] to avoid thrashing the GC.
At the very least use typed arrays à la glMatrix[2] rather than a Vector prototype.
Typed arrays have the added benefit of interoperability with WebGL and Canvas2D via Function::apply.
---
I did some quick benchmarks using emscripten recently and performance absolutely blew away my hand-tweaked chipmunk code[3]. Hand optimized, ChipmunkJS takes 2.8x as long to run the tests. Emscripten compiled chipmunk is 1.4x, so twice as fast.
That said, the generated code is huge and awful, and the API is terrible. I've been playing around with porting my library to LLJS recently, but when I looked at LLJS it hadn't been updated in over a year. Its nice to see that there were some commits a few months ago, but LLJS needs a lot of work before its generally usable. I've been doing some stuff manually as a toy - still not sure where to go with all of this. Bridging from ASMJS to regular javascript makes your API really hard to use.
---
[1] https://github.com/josephg/Chipmunk-js
[2] https://docs.google.com/spreadsheet/ccc?key=0Ap2hDnCZnXiVdDV... , though this is somewhat hard to read.
On the other hand, the vec2 class of glMatrix looks fantastic and this is something to consider. Thanks!
This is exactly how I felt using the Box2D port for our swarm project--itself a port of an ActionScript port of a C++ library.
Here are a few points for comparison:
- p2.js is significantly more complete than newton
- p2.js uses a rigid body simulation closer in principle to box2d, while newton uses a particle-and-constraint based verlet integration
- newton provides a game loop with separate render/simulate time tracking (something I feel is missing from existing libs)