explaingit

kripken/ammo.js

4,511C++Audience · developerComplexity · 3/5LicenseSetup · easy

TLDR

The Bullet physics engine ported to JavaScript and WebAssembly so web developers can add realistic physics, falling, colliding, bouncing objects, to browser-based 3D games and simulations without writing a physics engine.

Mindmap

mindmap
  root((ammo.js))
    What it does
      Browser physics
      Bullet port
    Output formats
      JavaScript build
      WebAssembly build
    Demos included
      Rigid body stack
      Cloth and rope
      Vehicle sim
      Heightmap terrain
    Tech stack
      C++
      Emscripten
      WebAssembly
    Use cases
      Browser games
      3D simulations
      Physics prototypes
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Add realistic rigid-body physics to a browser-based 3D game so objects fall, collide, and bounce under gravity.

USE CASE 2

Run cloth, rope, or soft-body simulations in a web browser without a server-side physics engine.

USE CASE 3

Prototype a vehicle simulation with suspension and wheel friction that runs entirely in the browser.

USE CASE 4

Use ammo.js with Three.js or Babylon.js to synchronize visual objects with physics simulation positions.

Tech stack

C++JavaScriptWebAssemblyEmscripten

Getting it running

Difficulty · easy Time to first run · 30min

A prebuilt ammo.js file is included in the repo under builds/ so most users don't need to compile anything, building from source requires Emscripten and cmake.

Use freely for any purpose including commercial, the zlib license only asks that you don't misrepresent the origin of the software.

In plain English

Ammo.js is a version of the Bullet physics engine that runs inside a web browser. Bullet is a well-established physics simulation library written in C++, used in games and 3D applications to simulate how objects fall, collide, bounce, and interact with forces. Normally Bullet runs as native compiled code on a desktop or console. Ammo.js makes the same physics engine available to JavaScript developers by translating the C++ source code into JavaScript automatically using a tool called Emscripten, rather than rewriting it by hand. The name is an acronym: Avoided Making My Own js physics engine by compiling bullet from C++. Because the translation is automated rather than hand-written, the API closely mirrors the original Bullet API. JavaScript developers access physics objects through an Ammo namespace: for example, creating a vector is done with new Ammo.btVector3(x, y, z). Struct member variables that would be directly readable in C++ are accessed through getter and setter functions in the JavaScript version. The library ships with both a standard JavaScript build and a WebAssembly build, which is a more compact binary format that browsers can load and execute faster. The project includes several live browser demos covering common physics scenarios: a stack of cubes colliding under gravity, a rope, cloth, a soft volume, a height-mapped terrain, and a vehicle simulation. These demonstrate what Bullet can do and give developers concrete examples to reference. A prebuilt version of ammo.js is included in the repository under the builds directory, so most developers can start using it without compiling anything themselves. For those who want to build from source, the process requires Emscripten and cmake. A Docker-based build path is also available. Build size can be reduced by removing unused interfaces from the interface definition file. Ammo.js is licensed under the zlib license, the same license as Bullet. It is used most often by developers building 3D games or simulations that run in the browser and need realistic physics without writing a physics engine themselves.

Copy-paste prompts

Prompt 1
Show me how to set up ammo.js with Three.js to create a stack of boxes that falls under gravity, using the WebAssembly build for better performance.
Prompt 2
How do I create a rigid-body ground plane and a falling sphere in ammo.js, then read back the sphere's position each frame to update a Three.js mesh?
Prompt 3
Walk me through using ammo.js to simulate a rope between two anchor points and render it in the browser using line geometry.
Prompt 4
How do I build ammo.js from source using Emscripten and reduce the output file size by removing physics interfaces I don't need?
Prompt 5
What is the ammo.js equivalent of the Bullet btVector3 and btTransform C++ types, and how do I create and free them correctly in JavaScript to avoid memory leaks?
Open on GitHub → Explain another repo

← kripken on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.