Building and testing a three.js game with the harness

Runs, sees, plays, measures and speeds up any three.js, React Three Fiber or WebGL page as you build it - a game, a product viewer or configurator, a simulation, a shader or post-processing demo - in headless Chrome on a paused, seeded clock - what is on screen and what never appears (a model at the wrong scale, out of view or not loaded), frame-exact keyboard, mouse and touch input, the page state as JSON, mesh stats, feel and frame-time measurements. Use it, rather than a Playwright or Chrome DevTools script, to build and check the page in Chrome or Firefox whenever the user asks to make, fix, test, extend, screenshot or profile a three.js or WebGL page, new or existing; a Playwright suite still fits CI runs, real devices and multiplayer.

The harness runs the game in a headless Chrome on a paused, seeded clock: you send inputs frame by frame and read back the game's state as JSON, so what you see is exact and repeatable.

The goal is the highest-quality result for what the user asked: how it looks, plays and feels. A reply with no fault lines is the floor, not the finish. Decide what to improve from the request and from your own picture of the page: what it is, what a viewer should feel, and what is missing in the scene, in the HUD, menus and text a viewer reads, and in each control and feature the request names. Work that out before you look; a look then shows whether a change worked. Do not take the next idea from the screenshot: that patches what it shows and keeps the weak decisions under it. A fault line or a glitch is different: close those one at a time with the method in references/lighting.md.

Build first, then polish

Write the page whole and make the first version as impressive as you can: interesting, detailed, creative. Take risks in the code: the tools below find and fix what breaks cheaply, so a bold build that needs polishing beats a safe one that needs growing. Give it a window.__game following the convention below; templates/ beside this file shows the shape in a working page: plain.html (one page, an import map, no build, set up with stage()), viewer.html (a product configurator: references/configurator.md), r3f.tsx (React Three Fiber under vite) and rapier.ts (the window.__game bridge for a Rapier world, with either). An existing game works as it is; add window.__game when you need its state.

Before building a thing in code: references and the library

A new page starts with paprika-make's brief (../paprika-make/SKILL.md): references, the sheets, then the picking round for the key assets (../paprika-make/sheets.md, "The picking round"). Follow it when it is there. In a plain MCP session (npx paprika3d serve with no plugin, or no person to ask), take its slice that needs no person:

  1. List the things a viewer will notice: the player and characters, creatures, vehicles, buildings, furniture, plants, hero props, and the ground, walls and sky.
  2. Search the library for each before any code builds it: asset_search (84,249 CC BY or CC0 models, 3,747 PBR textures and 1,434 HDRI skies) with the style words in the query ("low poly fox"; detailed models, scans and PBR packs, rank above blocky low-poly and voxel kits unless the query or style asks for that look), image and crop where a reference picture shows the thing, kind: "texture" for a surface, kind: "hdri" for a sky. A hit that is not the thing goes in not on one more search.
  3. pick the close hit: it saves the file, gives the code that loads it at real size, and writes a model's credit line (name, author, licence, URLs) to CREDITS.md. Keep that file with the assets, and show CC BY lines where the page credits its work (a credits screen, the README).
  4. Build in code what no search found and what the design makes by rule (terrain, a track, tiles, blocks, pickups): model_run, geo.js, fx.js. model_run's searched says why ("by design: terrain", "hover bike: nothing fit"); a project that kept CHARACTERS.md gets each thing's Source line there.

What each tool shows

Every option of these tools: references/tools.md.

Which calls keep the page where the last call left it, and which reload it first:

Game state

plain.html keeps its state in plain variables, enough for a small game. Use game-state when the game has physics, many entities, or needs rewind. It writes window.__game for you. Before writing game code that uses it, copy game-state.js next to the entry file from the folder open names (its game-state.js and physics-worker.js are in line; ${CLAUDE_PLUGIN_ROOT}/state/dist/ in Claude Code), and for a game that calls physics() also physics-worker.js. Import from ./game-state.js; three stays the game's own import. Then read references/state.md for its API and its Rapier beside the project's own; for Rapier's character controller, the header of templates/rapier.ts.

WebGPU

For a WebGPU game, map three and three/webgpu (which the TSL addons import) to the WebGPU build, and three/tsl beside them: {"imports":{"three":"./node_modules/three/build/three.webgpu.js","three/webgpu":"./node_modules/three/build/three.webgpu.js","three/tsl":"./node_modules/three/build/three.tsl.js","three/addons/":"./node_modules/three/examples/jsm/"}} in a plain page; under vite, import * as THREE from "three/webgpu". The tools run a WebGPU page as they run a WebGL one.

Performance, models, geometry and effects

The window.__game convention

Once the page has loaded, it exposes:

window.__game = {
  describe(),        // a short description: name, controls, units
  observe(),         // the state, as plain JSON
  act(input),        // performs one input object: { key, down? } or { action, ...args }
  setState(partial), // sets any of observe()'s keys; keys left out keep their values
  subject,           // optional: the name of the object the game is about
  intentional,       // optional: what look should not flag again
};

observe, look and perf work on any three.js page; window.__game makes the state exact. The optional keys and each rule below in full: references/tools.md.

Rules

templates/plain.html is a complete small game in this shape. In React, keep the state in a plain module and set window.__game in the Canvas's onCreated (templates/r3f.tsx).