Example code to give you an idea of the API: https://github.com/kripken/ammo.js/blob/master/examples/webgl_demo/ammo.html#L14
Note: ammo.js has just been updated to a new porting approach. If you find some part of the Bullet API that is not supported that you need, please see https://github.com/kripken/ammo.js/issues/60
'ammo' stands for "Avoided Making My Own js physics engine by compiling bullet from C++" ;)
ammo.js is zlib licensed, just like Bullet.
Discussion takes place on IRC at #emscripten on Mozilla's server (irc.mozilla.org)
builds/ammo.js contains a prebuilt version of ammo.js. This is probably what you want.
You can also build ammo.js yourself, as follows:
and set it up. See
Run the build script,
which should generate builds/ammo.js.
Optionally, run the automatic tests,
ammo.js autogenerates its API from the Bullet source code, so it should be basically identical. There are however some differences and things to be aware of:
See https://github.com/kripken/emscripten/wiki/WebIDL-Binder for a description of the bindings tool we use here, which includes instructions for how to use the wrapped objects.
All ammo.js elements should be accessed through
Ammo.*. For example,
Ammo.btVector3, etc., as you can see in the example code.
Member variables of structs and classes can be accessed through setter and getter functions, that are prefixed with
|set_|. For example,
m_rayToWorldfrom say a
Functions returning or getting
btScalar&are converted to float. The reason is that
|new btVector3(5, 6, 7)|and it will work as expected. If you find a case where you need the float& method, please file an issue.
Not all classes are exposed, as only what is described in ammo.idl is wrapped. Please submit pull requests with extra stuff that you need and add.
There is experimental support for binding operator functions. The following might work:
Operator Name in JS
It's easy to forget to write |new| when creating an object, for example
var vec = Ammo.btVector3(1,2,3); // This is wrong! Need 'new'!
This can lead to error messages like the following:
Cannot read property 'a' of undefined
Cannot read property 'ptr' of undefined
If you find a bug in ammo.js and file an issue, please include a script that reproduces the problem. That way it is easier to debug, and we can then include that script in our automatic tests.
Pushing a new build in
builds/ammo.js should be done only after the
Build using python make.py which generates builds/temp.js
Make sure it passes all automatic tests using python test.py (That uses builds/temp.js by default, you can also pass a flag saying which build to use.) Note that it uses SpiderMonkey by default, and SPIDERMONKEY_ENGINE is defined in ~/.emscripten, see the script contents for details.
Make sure that the stress test benchmark did not regress compared to the old build. That number is printed out at the end of running the tests.
Run the WebGL demo in examples/webgl_demo and make sure it looks ok, using something like firefox examples/webgl_demo/ammo.html (chrome will need a webserver as it doesn't like file:// urls)
Bullet 2.82 patched with raycast fix from 2.83