Monday, August 8, 2011

ammo.js - Ready for Testing!

After months of work, ammo.js (the Bullet physics engine compiled to JavaScript using Emscripten) is now ready for testing. To do that, grab builds/ammo.js, and look at examples/hello_world.js for a code example.

examples/hello_world.js is almost a 1 to 1 manual translation of HelloWorld.cpp (which you can find in bullet/Demos/HelloWorld/HelloWorld.cpp). That is possible since the ammo.js bindings let you write very natural JavaScript, for example this C++ code
btTransform groundTransform;
becomes this JavaScript code
var groundTransform = new btTransform();
There are some limitations to the automatically generated bindings code (see the ammo.js README for more details), but overall it basically works.

This is the result of a lot of hard work by bretthart on CppHeaderParser and by me on the bindings generator in Emscripten that uses it. Turns out it's pretty hard to automatically generate bindings from C++ to JavaScript, who would have thought ;) In any case we appear to have things in good shape now. I will probably write a separate blogpost about the bindings methodology later on.

The speed of ammo.js should be fairly decent, most optimizations are applied to the underlying Bullet code except for the LLVM ones and for typed arrays. However the binding code itself is not optimized at all yet. Overall things should be fast enough for testing, with some additional speedups still possible later on.

Please test ammo.js and file issues on github :)

No comments:

Post a Comment