Giter VIP home page Giter VIP logo

sondro / ammo.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kripken/ammo.js

0.0 2.0 0.0 35.65 MB

Direct port of the Bullet physics engine to JavaScript using Emscripten

License: Other

CMake 1.04% C++ 71.07% Makefile 0.24% Lua 0.07% C 16.87% RPC 8.39% HLSL 0.07% JavaScript 0.25% Batchfile 0.01% Python 0.09% HTML 0.01% GLSL 0.01% Objective-C 0.40% Objective-C++ 0.04% Cuda 0.51% Shell 0.06% M4 0.82% TeX 0.07%

ammo.js's Introduction

ammo.js

Demos

Overview

Example code to give you an idea of the API:

ammo.js is a direct port of the Bullet physics engine to JavaScript, using Emscripten. The source code is translated directly to JavaScript, without human rewriting, so functionality should be identical to the original Bullet.

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 kripken#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)

Instructions

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:

Usage

The most straightforward thing is if you want to write your code in C++, and run that on the web. If so, then compile your code into LLVM, link it with bullet, and compile that to JavaScript using emscripten. (The easiest way to link it is to add your .bc file to the llvm-link command in make.py.)

If, on the other hand, you want to write code in JavaScript, you can use the autogenerated binding code. A complete example appears in

examples/hello_world.js

That is HelloWorld.cpp from Bullet, translated to JavaScript. Other examples in that directory might be useful as well. In particular see the WebGL demo code in

examples/webgl_demo/ammo.html

Bindings API

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 |get_| or |set_|. For example,

    rayCallback.get_m_rayToWorld()

    will get m_rayToWorld from say a ClosestRayResultCallback. Native JavaScript getters and setters could give a slightly nicer API here, however their performance is potentially problematic.

  • Functions returning or getting float& or btScalar& are converted to float. The reason is that float& is basically float* with nicer syntax in C++, but from JavaScript you would need to write to the heap every time you call such a function, making usage very ugly. With this change, you can do |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
    = op_set
    + op_add
    - op_sub
    * op_mul
    / op_div
    [] op_get
    == op_eq

Reducing Build Size

The size of the ammo.js builds can be reduced in several ways:

  • Removing uneeded interfaces from ammo.idl. Some good examples of this are btIDebugDraw and DebugDrawer, which are both only needed if visual debug rendering is desired.

  • Removing methods from the -s EXPORTED_RUNTIME_METHODS=[] argument in make.py. For example, Pointer_stringify is only needed if printable error messages are desired from DebugDrawer.

Troubleshooting

  • 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

    This is an annoying aspect of JavaScript, sadly.

Reporting Issues

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.

Release Process

Pushing a new build in builds/ammo.js should be done only after the following steps:

  • Build using python make.py closure which generates the asm.js build, and python make.py closure wasm which generates the wasm build.

  • Make sure it passes all automatic tests using python test.py (build-name) Note that it uses SpiderMonkey by default, and SPIDERMONKEY_ENGINE is defined in ~/.emscripten, see the script contents for details.

  • 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)

Upstream Version

Bullet 2.82 patched with raycast fix from 2.83

ammo.js's People

Contributors

kripken avatar yomboprime avatar richtrr avatar bunzaga avatar willeastcott avatar infinitelee avatar nickpepper avatar silverweed avatar donalffons avatar guzzard avatar juj avatar jazzzz avatar swift502 avatar beiller avatar yaustar avatar sbc100 avatar dvlp avatar mrdoob avatar saldivarcher avatar luboslenco avatar jordan-woyak avatar steve384 avatar jackdalton avatar me97esn avatar dweis avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.