.claude/skills/threejs-builder/SKILL.md
Creates simple Three.js web apps with scene setup, lighting, geometries, materials, animations, and responsive rendering. Use for: "Create a threejs scene/app/showcase" or when user wants 3D web content. Supports ES modules, modern Three.js r150+ APIs.
npx skillsauth add dschonholtz/MultiMagicDungeonWeb threejs-builderInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
A focused skill for creating simple, performant Three.js web applications using modern ES module patterns.
Important: Read the appropriate reference file when working on specific topics.
| Topic | File | Use When | |-------|------|----------| | GLTF Models | gltf-loading-guide.md | Loading, caching, cloning 3D models, SkeletonUtils | | Reference Frames | reference-frame-contract.md | Calibration, anchoring, axis correctness, debugging | | Game Development | game-patterns.md | State machines, animation switching, parallax, object pooling | | Advanced Topics | advanced-topics.md | Post-processing, shaders, physics, instancing | | Calibration Helpers | scripts/README.md | GLTF calibration helper installation and usage |
Three.js is built on the scene graph—a hierarchical tree of objects where parent transformations affect children. Understanding this mental model is key to effective 3D web development.
Before creating a Three.js app, ask:
Core principles:
scene renders. Use Group for hierarchical transforms.requestAnimationFrame or renderer.setAnimationLoop.Understanding Three.js's right-handed coordinate system is essential to avoid inverted movement, wrong-facing models, and broken collision detection.
+Y (up)
|
|
|_______ +X (right)
/
/
+Z (toward camera/viewer)
Memory aid: Point your thumb (+X), index finger (+Y), middle finger (+Z) - that's right-handed coordinates.
| Axis | Direction | Common Usage | |------|-----------|--------------| | +X | Right | Strafe right, spawn right | | -X | Left | Strafe left, spawn left | | +Y | Up | Jump, height | | -Y | Down | Fall, gravity | | +Z | Toward camera | Approach viewer, "forward" in many setups | | -Z | Away from camera | Retreat, GLTF models face -Z by default |
CRITICAL: GLTF models exported from Blender/Maya face -Z (into the screen) by default.
// GLTF model faces -Z. To face +Z (toward camera):
model.rotation.y = Math.PI; // 180° rotation
// To face +X (right):
model.rotation.y = -Math.PI / 2; // -90°
// To face -X (left):
model.rotation.y = Math.PI / 2; // +90°
PROBLEM: When camera is at an angle (e.g., isometric view), raw WASD input moves wrong!
// ❌ WRONG - Input is world-axis relative, not camera-relative
if (keyW) player.position.z -= speed; // Moves toward -Z, not "forward" from player's view
if (keyD) player.position.x += speed; // Moves +X, not "right" from camera's view
// ✓ CORRECT - Calculate camera-relative directions
function updateMovement(deltaTime) {
// Get camera's forward direction, projected onto ground (XZ plane)
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
// Calculate right vector (cross product of forward and world up)
const right = new THREE.Vector3();
right.crossVectors(forward, new THREE.Vector3(0, 1, 0)).normalize();
// Apply input relative to camera orientation
const velocity = new THREE.Vector3();
if (inputState.up) velocity.add(forward);
if (inputState.down) velocity.sub(forward);
if (inputState.right) velocity.add(right);
if (inputState.left) velocity.sub(right);
if (velocity.length() > 0) {
velocity.normalize().multiplyScalar(speed * deltaTime);
player.position.add(velocity);
// Face movement direction
player.rotation.y = Math.atan2(velocity.x, velocity.z);
}
}
Why this matters: With camera at (8, 11, -6) looking at (0, 1, 3):
-Z, it's roughly +Z+X, it's roughly -X + Z<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Three.js App</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { overflow: hidden; background: #000; }
canvas { display: block; }
</style>
</head>
<body>
<script type="module">
import * as THREE from 'https://unpkg.com/[email protected]/build/three.module.js';
// Scene setup
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
document.body.appendChild(renderer.domElement);
// Your 3D content here
// ...
camera.position.z = 5;
// Animation loop
renderer.setAnimationLoop((time) => {
renderer.render(scene, camera);
});
// Handle resize
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
</script>
</body>
</html>
Built-in primitives cover most simple app needs. Use BufferGeometry only for custom shapes.
Common primitives:
BoxGeometry(width, height, depth) - cubes, boxesSphereGeometry(radius, widthSegments, heightSegments) - balls, planetsCylinderGeometry(radiusTop, radiusBottom, height) - tubes, cylindersTorusGeometry(radius, tube) - donuts, ringsPlaneGeometry(width, height) - floors, walls, backgroundsConeGeometry(radius, height) - spikes, conesIcosahedronGeometry(radius, detail) - low-poly spheres (detail=0)Usage:
const geometry = new THREE.BoxGeometry(1, 1, 1);
const material = new THREE.MeshStandardMaterial({ color: 0x44aa88 });
const mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);
Choose material based on lighting needs and visual style.
Material selection guide:
MeshBasicMaterial - No lighting, flat colors. Use for: UI, wireframes, unlit effectsMeshStandardMaterial - PBR lighting. Default for realistic surfacesMeshPhysicalMaterial - Advanced PBR with clearcoat, transmission. Glass, waterMeshNormalMaterial - Debug, rainbow colors based on normalsMeshPhongMaterial - Legacy, shininess control. Faster than StandardCommon material properties:
{
color: 0x44aa88, // Hex color
roughness: 0.5, // 0=glossy, 1=matte (Standard/Physical)
metalness: 0.0, // 0=non-metal, 1=metal (Standard/Physical)
emissive: 0x000000, // Self-illumination color
wireframe: false, // Show edges only
transparent: false, // Enable transparency
opacity: 1.0, // 0=invisible, 1=opaque (needs transparent:true)
side: THREE.FrontSide // FrontSide, BackSide, DoubleSide
}
No light = black screen (except BasicMaterial/NormalMaterial).
Light types:
AmbientLight(intensity) - Base illumination everywhere. Use 0.3-0.5DirectionalLight(color, intensity) - Sun-like, parallel rays. Cast shadowsPointLight(color, intensity, distance) - Light bulb, emits in all directionsSpotLight(color, intensity, angle, penumbra) - Flashlight, cone of lightTypical lighting setup:
const ambientLight = new THREE.AmbientLight(0xffffff, 0.4);
scene.add(ambientLight);
const mainLight = new THREE.DirectionalLight(0xffffff, 1);
mainLight.position.set(5, 10, 7);
scene.add(mainLight);
const fillLight = new THREE.DirectionalLight(0x88ccff, 0.5);
fillLight.position.set(-5, 0, -5);
scene.add(fillLight);
Shadows (advanced, use when needed):
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
mainLight.castShadow = true;
mainLight.shadow.mapSize.width = 2048;
mainLight.shadow.mapSize.height = 2048;
mesh.castShadow = true;
mesh.receiveShadow = true;
Transform objects over time using the animation loop.
Animation patterns:
renderer.setAnimationLoop((time) => {
mesh.rotation.x = time * 0.001;
mesh.rotation.y = time * 0.0005;
renderer.render(scene, camera);
});
renderer.setAnimationLoop((time) => {
mesh.position.y = Math.sin(time * 0.002) * 0.5;
renderer.render(scene, camera);
});
const mouse = new THREE.Vector2();
window.addEventListener('mousemove', (event) => {
mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
});
renderer.setAnimationLoop(() => {
mesh.rotation.x = mouse.y * 0.5;
mesh.rotation.y = mouse.x * 0.5;
renderer.render(scene, camera);
});
Import OrbitControls from examples for interactive camera movement:
<script type="module">
import * as THREE from 'https://unpkg.com/[email protected]/build/three.module.js';
import { OrbitControls } from 'https://unpkg.com/[email protected]/examples/jsm/controls/OrbitControls.js';
// ... scene setup ...
const controls = new OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
controls.dampingFactor = 0.05;
renderer.setAnimationLoop(() => {
controls.update();
renderer.render(scene, camera);
});
</script>
const geometry = new THREE.BoxGeometry(1, 1, 1);
const material = new THREE.MeshStandardMaterial({ color: 0x00ff88 });
const cube = new THREE.Mesh(geometry, material);
scene.add(cube);
renderer.setAnimationLoop((time) => {
cube.rotation.x = time * 0.001;
cube.rotation.y = time * 0.001;
renderer.render(scene, camera);
});
const particleCount = 1000;
const geometry = new THREE.BufferGeometry();
const positions = new Float32Array(particleCount * 3);
for (let i = 0; i < particleCount * 3; i += 3) {
positions[i] = (Math.random() - 0.5) * 50;
positions[i + 1] = (Math.random() - 0.5) * 50;
positions[i + 2] = (Math.random() - 0.5) * 50;
}
geometry.setAttribute('position', new THREE.BufferAttribute(positions, 3));
const material = new THREE.PointsMaterial({ color: 0xffffff, size: 0.1 });
const particles = new THREE.Points(geometry, material);
scene.add(particles);
// Background grid
const gridHelper = new THREE.GridHelper(50, 50, 0x444444, 0x222222);
scene.add(gridHelper);
// Foreground object
const mainGeometry = new THREE.IcosahedronGeometry(1, 0);
const mainMaterial = new THREE.MeshStandardMaterial({
color: 0xff6600,
flatShading: true
});
const mainMesh = new THREE.Mesh(mainGeometry, mainMaterial);
scene.add(mainMesh);
Three.js uses hexadecimal color format: 0xRRGGBB
Common hex colors:
0x000000, White: 0xffffff0xff0000, Green: 0x00ff00, Blue: 0x0000ff0x00ffff, Magenta: 0xff00ff, Yellow: 0xffff000xff8800, Purple: 0x8800ff, Pink: 0xff0088❌ Not importing OrbitControls from correct path
Why bad: Controls won't load, THREE.OrbitControls is undefined in modern Three.js
Better: Use import { OrbitControls } from 'three/addons/controls/OrbitControls.js' or unpkg examples/jsm path
❌ Forgetting to add object to scene
Why bad: Object won't render, silent failure
Better: Always call scene.add(object) after creating meshes/lights
❌ Using old requestAnimationFrame pattern instead of setAnimationLoop
Why bad: More verbose, doesn't handle XR/WebXR automatically
Better: renderer.setAnimationLoop((time) => { ... })
❌ Creating new geometries in animation loop Why bad: Massive memory allocation, frame rate collapse Better: Create geometry once, reuse it. Transform only position/rotation/scale
❌ Using too many segments on primitives
Why bad: Unnecessary vertices, GPU overhead
Better: Default segments are usually fine. SphereGeometry(1, 32, 16) not SphereGeometry(1, 128, 64)
❌ Not setting pixelRatio cap
Why bad: 4K/5K displays run at full resolution, poor performance
Better: Math.min(window.devicePixelRatio, 2)
❌ Everything in one giant function
Why bad: Hard to modify, hard to debug
Better: Separate setup into functions: createScene(), createLights(), createMeshes()
❌ Hardcoding all values
Why bad: Difficult to tweak and experiment
Better: Define constants at top: const CONFIG = { color: 0x00ff88, speed: 0.001 }
IMPORTANT: Each Three.js app should feel unique and context-appropriate.
Vary by scenario:
Vary visual elements:
Avoid converging on:
Three.js is a tool for interactive 3D on the web.
Effective Three.js apps:
Modern Three.js (r150+) uses ES modules from three package or CDN. CommonJS patterns and global THREE variable are legacy.
Claude is capable of creating elegant, performant 3D web experiences. These patterns guide the way—they don't limit the result.
For specific topics, see the Reference Files table at the top of this document.
tools
# Skill: Extend the WebSocket Protocol Use this when adding a new message type. Both client and server must be updated together. ## Message flow ``` Client → Server: join, move, spell_cast, rename, [new type] Server → Client: welcome, player_join, player_leave, player_move, spell_cast, player_rename, [new type] ``` ## Step 1: Define the message before coding Document these before touching any file: - **Name**: snake_case - **Direction**: client→server, server→client, or
development
# Skill: Add a Three.js Feature to MultiMagicDungeonWeb This game is a **single monolithic `index.html`** — no build step, no bundler. Everything lives in one file. ## File structure inside index.html ``` <html> <head> ... styles ... </head> <body> <!-- HUD overlay divs: #hud, #rename-panel, etc. --> <canvas id="c"></canvas> <script type="module"> // === CONSTANTS (WS_URL, PLAYER_SPEED, HP_MAX, etc.) === // === GLOBALS (scene, camera, renderer, clock) === //
tools
# Skill: Test Multiplayer Locally Use this skill any time you need to verify multiplayer behavior in MultiMagicDungeonWeb. ## Stack - Game: `index.html` (open as `file://` — no HTTP server needed) - WS server: `server/index.js` on port 8080 - Node binary: `~/.nvm/versions/node/v22.22.0/bin/node` (shell aliases don't apply in Bash tool) ## Step 1: Start the WS server ```bash export PATH="$HOME/.nvm/versions/node/v22.22.0/bin:$PATH" cd /Users/douglasschonholtz/repos/MultiMagicDungeonWeb/server
development
# Skill: Task Workflow Use this checklist for every non-trivial piece of work. Four steps, always in order. Never skip or merge steps. --- ## Step 1 — Plan _(requires user approval before any code is written)_ - [ ] Create `tasks/active/NNN-short-title.md` from `tasks/TEMPLATE.md` - [ ] Document 2–3 options with pros/cons - [ ] Pick the best option and explain why, clearly - [ ] Write numbered, measurable **success criteria** (not "looks better" — testable outcomes) - [ ] Write a **testing s