Skip to content

The break. Glass marbles at half speed. Click to break again.debug draw, live. What the physics engine sees.Chain reaction. Dominoes, printed live in two inks.Three steps. Flat colour, real gravity.Move the pointer to tilt the board. Collect the coins.

A lightweight 3D game engine

Marble3Small 3D games for the web

A lightweight 3D game engine for people making small browser games. Write TypeScript on Three.js; Bullet physics runs as WebAssembly. An FPS player with desktop and touch controls, voxel terrain and a DOM HUD come in the box.

npm install marble3

Language
TypeScript
Rendering
Three.js
Physics
Bullet via Bullet TS
Licence
MIT

In the box

  1. A game is () => HTMLElement

    new FPS(), add entities, start(player) — you get back a container element. Mount it anywhere; disposeGame(el) tears everything down, physics included.

  2. Bullet physics in WebAssembly

    Dynamic bodies, a velocity-based character controller, raycasts and collision callbacks, on the Bullet engine, compiled to WASM and typed by Bullet TS. Box, Sphere, convex hulls and static meshes.

  3. Desktop and touch, same game

    Pointer-lock WASD on desktop; a stick, swipe-look and jump button on phones. The Player picks the right controller by itself.

  4. Voxel terrain

    Simplex-noise heightmaps with greedy block merging, and physics that streams in around moving entities instead of materializing the whole map.

  5. HUD without a framework

    Slot-based screen chrome — score lines, bars, hints, banners, buttons, dialogs — plain DOM, styled inline, disposed with the game.

  6. Small on purpose

    About 4k lines of TypeScript and one npm package — Three.js installs with it and the Bullet WebAssembly ships inside it. No CSS files, no assets to copy.

A game in one function ​

ts
import * as THREE from 'three';
import { FPS } from 'marble3';
import { Player } from 'marble3/player';
import { Box } from 'marble3/object';
import { Grid } from 'marble3/terrain/grid';
import { defaultLights } from 'marble3/lights';

export const createGame = (): HTMLElement => {
  const camera = new THREE.PerspectiveCamera(70, innerWidth / innerHeight, 0.1, 4000);
  const fps = new FPS();
  fps.scene.add(defaultLights());
  fps.add(new Grid(100));
  const crate = new Box();
  crate.position = new THREE.Vector3(0, 5, -4);
  fps.add(crate);
  const player = new Player({ camera });
  fps.add(player);
  return fps.start(player);
};

Install it with npm install marble3 (or yarn add marble3); the getting-started guide covers the setup, including the two Vite settings that projects on Vite 7 or older need.

Live, in this page ​

The Asteroid world example, running on the engine right here. Press Play for the full game, or see all the examples.

Building the world…
Milky Way sky: ESO/S. Brunier

Asteroid world · Credits

All credits and licences

Physics: Bullet, through Bullet TS ​

Marble3's physics engine is Bullet, the C++ engine. It reaches the browser and TypeScript through Bullet TS, its companion project by the same author: Bullet's own source compiled to WebAssembly with Emscripten, with bindings and TypeScript declarations generated from Bullet's headers, packaged as one typed ESM namespace that boots the WASM with a top-level await, so it is ready before any importer runs. Marble3 ships a copy of Bullet TS inside the package, as marble3/bullet — there is nothing else to install or initialise.

On top of that, Marble3 builds and frees the dynamics world, turns entities into rigid bodies, and adds the character controller, raycasts and collision callbacks — while fps.world stays the real btDiscreteDynamicsWorld for anything the wrappers don't cover. See Physics.

Bullet is under the zlib license; Bullet TS and Marble3 are MIT.