This skill gives a coding agent the base every three.js game needs: module loading through an import map or bundler, a scene, camera and renderer, one render loop driven by setAnimationLoop with a clamped Timer delta, and resize handling. It proves the pipeline with an unlit mesh before any lighting is added.
It targets three.js r187 and reads the installed version first. It also covers a pixel ratio budget for phones and HiDPI screens, a switch to WebGPURenderer when node materials are needed, and a headless smoke test that checks draw calls and survives a lost WebGL context.
What You Get
- Six code patterns: an import map without a bundler, scene camera and renderer, a Timer render loop, resize, OrbitControls and a WebGPURenderer start
- A smoke.mjs script that fails on page errors, checks draw calls, saves screenshots and tests a lost and restored WebGL context
- A gotcha list for module resolution errors, black canvases, stretched views after resize, frozen simulations after a hidden tab and OrbitControls damping
- A reference on coordinates, Group parenting, orthographic cameras, disposing GPU resources, render on demand and adaptive resolution
Common Use Cases
- Starting a new three.js game with a clean loop and resize handling
- Fixing the error that three cannot be resolved as a module specifier
- Finding why a canvas stays black with no console errors
- Capping pixel ratio so a scene runs cool on phones
What Makes It Unique
The skill keeps game state in ordinary objects and copies it onto meshes each frame, so state can be saved and tested without a GPU. It documents a Timer quirk in r186 and r187 where a loop timestamp passed to update can give a negative delta, and its smoke test forces a WebGL context loss and restore to catch code that holds raw GPU objects.
Under The Hood
The agent loads the SKILL.md and reads the scene graph reference only when it needs depth. It edits your source and html, runs the project build or type check, and writes a smoke.mjs script. That script needs the Playwright package and a downloaded Chromium browser, installed through npm and npx commands; it opens your local dev server page in a headless browser and writes screenshot files. The example import map loads three.js from a public CDN, and the skill makes no other outside calls.