The only engines I know of in JS are ports of either Box2D or Bullet. My thoughts about them so far:
- Box2D also has two ports (Box2dJS and ). I just don't like the Box2D API, that's pretty much all. Box2dJS also is outdated and requires Prototype (for whatever reason).
The last point is especially important to me, because that means they will most certainly clutter the global namespace. I started using AMD script loaders for almost all of my projects in the last months and I really don't want to go back to this global mess.. (: So I decided to take a shot at doing a physics engine port that's AMD compatible and has a nice API.
The Chipmunk engine has a really nice API, so I chose to port that. After about two months of work besides work and exams I finally reached a point where most parts work and I feel comfortable to put it out.
I still consider it to be an early alpha version, so it's probably not recommend to use it in any serious project yet. Nevertheless, you can check out the code on Github.
It's not a 1:1 port, since Chipmunk is written in C and I wanted an object oriented library. But it's a really close port when it comes to naming things. For instance cpSpaceAddShape(space, shape) in Chipmunk became space.addShape(shape) (space being an instance of cp/Space) in Chipmunk.js. I think I managed to stay as close as possible to the method signatures of Chipmunk.
Alright, here's the current state:
- Collision primitives for segments, circles and convex polygons
- Uses fast contact persistence algorithm by Erin Catto (of Box2D fame)
- Neat constraints like damped springs or motors.
- Almost no dependencies. Chipmunk.js only requires (he he he) an AMD script loader.
- No global namespace pollution. I'm not in your global, polluting your windowz. (o:
- Sleeping bodies not supported. The code is already ported, but contains a crucial bug that leads to a freezing browser. More in this issue on Github.
- Write some unit tests for all classes.
- Find a tool for JS code documentation that does not suck that bad and make some nice API docs.
I made a page where I will put a few demos (two until now) here and other stuff such as API docs.
TLDR;blog comments powered by Disqus