spaSHıal

3D games, real physics, in the browser

Make 3D games with real physics.

A small JavaScript engine for the web. A few lines of code, and things fall, bounce and swing.

This is the engine running, not a video. Open this scene in the sandbox

the whole idea

Short enough to read in one go

There is no loop to write and nothing to import. You write the functions the engine calls, and use a few globals.

  • setup()Runs once. Make your starting scene here.
  • update()Runs 60 times a second. Read the keyboard and the mouse, push things around.
  • Cube, Sphere, Floor and friendsEvery one is a Solid: it can be seen, it can fall, and it can be touched.
function setup() {
  world.gravity.y = -10;          // gravity starts off. Turn it on.
  new Floor();
  const box = new Cube(0, 4, 0);
  box.color = 'tomato';
  box.bounciness = 0.6;
}

function update() {
  // Space blows everything away from the middle
  if (kb.presses('space')) world.explodeAt(0, 0, 0, 6, 8);
}

docs & sandbox

What is in the box

Six shapes, your own hulls and meshes, textures, glTF models, joints, forces, ray casts, cameras, lights, sound, saving, a level built from text, and online play between two tabs. Each page of the docs has demos you can run.

embedding

Put it in your own page

spaSHial runs in a sandboxed iframe, so the sketch cannot touch your page. Hand it the code with one message. It is plain static files: GitHub Pages, Cloudflare Pages, or any folder you can serve.

<iframe id="frame" sandbox="allow-scripts allow-downloads allow-modals"
        src="https://spashial.lefthanddev.com/runner.html"></iframe>
<script>
  addEventListener('message', (e) => {
    if (e.data?.source === 'preview-storage-request')
      frame.contentWindow.postMessage({ source: 'preview-storage-init', code: mySketch }, '*');
  });
</script>

The whole embedding guide

honest limits

What it cannot do yet

spaSHial is young. These are not built, and the docs say so in one place.

  • Online play between two computers
  • Vehicles and ragdolls
  • Terrain from a height map
  • Animated models
  • Motorised and 6-axis joints

The planned list, with what to do instead