Skip to content

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.

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.

Bullet physics in WebAssembly

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

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.

Voxel terrain

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

HUD without a framework

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

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, compiled to WebAssembly ​

Bullet is the C++ physics engine; ammo.js compiles it to WebAssembly with Emscripten. Marble3 gets it through bullet-ts, its companion project, maintained by the same author: the ammo.js WASM build packaged as one typed ESM namespace that boots its WASM with a top-level await, so it is ready before any importer runs. Marble3 ships a copy of it 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-ts is a fork of giniedp/ammojs-typed (MIT); Bullet and ammo.js are under the zlib license. Marble3 itself is MIT.