spaSHial

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

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);
}

What is in the box

Six shapes, your own hulls and meshes, joints, forces, ray casts, cameras, lights and a flat layer for scores. Each page of the docs has demos you can run.

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

What it cannot do yet

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

  • Textures and sounds
  • Models from files (glTF)
  • Online multiplayer
  • Saving a game's data
  • Vehicles and ragdolls
  • Terrain from a height map

The planned list, with what to do instead