/vibedgames:threejsfrom vibedgames
Build and debug 3D browser apps and games with Three.js or React Three Fiber: scene setup, materials, lighting, GLTF models, physics, character controllers, cameras, and post-processing.
Ships in vibedgames. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Build performant 3D browser apps and games with Three.js using modern ES module patterns (r150+). This file covers scene setup inline; physics, controllers, gameplay architecture, and deep topics live in references/.
Core principles:
scene renders. Use Group for hierarchical transforms (parent transforms affect children).renderer.setAnimationLoop.modules/ holds a small set of TypeScript files for the parts of a 3D game that are hard to get right and the same across games: framerate-independent smoothing + a deterministic PRNG (math.ts), Y-up orientation-frame helpers + a grounded character controller (character-movement.ts), and a Rapier kinematic character-collision resolver (kinematic-resolver.ts). Copy these into the project rather than re-deriving them — inverted axes, framerate-dependent smoothing, and mis-wired Rapier controllers are the classic ways this goes wrong.
Everything else — camera rigs, enemy waves, pathfinding, steering, minimaps, input schemes — is not prebuilt on purpose: it differs per game and is cheap to write, so generate it live against the references below. Read modules/summary.md before pulling anything in.
Scene setup is inline below. Read the relevant reference before working on that area:
| When you're working on... | Read first |
|---|---|
| Character locomotion / Rapier character collision / smoothing / seeded RNG | modules/summary.md |
| Turning a scene into a playable game (fixed-timestep loop, structure) | references/gameplay-systems.md |
| Physics or collision (Rapier / cannon-es / arcade overlap) | references/physics.md |
| Movement controllers, vehicles + follow/third-person camera | references/controllers-and-camera.md |
| Loading/caching/normalizing GLTF/GLB models | references/gltf-loading-guide.md |
| Game loop, state machine, object pooling, screen effects, attack timing, weapon trails | references/game-patterns.md |
| Dropping generated GLB models / SFX into a running scene | references/generated-assets.md |
| Post-processing, shaders, instancing, env maps, color management | references/advanced-topics.md |
| Material values, shader injection (onBeforeCompile), sky, cheap tricks, pixel-look post, z-fighting, shadows | references/graphics-recipes.md |
| Black screen, low FPS, mobile issues, memory leaks, physics debugging | references/debugging-and-profiling.md |
| Auditing a scene you didn't write, visual-defect sweeps, React Three Fiber (R3F) | references/debugging-and-profiling.md |
Verify it actually renders. scripts/check-canvas.mjs loads a build in headless Chromium and fails on a blank canvas or uncaught page error — run it in CI / before vg deploy (details in references/debugging-and-profiling.md).
| Approach | Use when |
|---|---|
| Arcade / custom | Pickups, triggers, hand-tuned jumps — overlap checks, no dependency |
| cannon-es | A few dozen dynamic rigid bodies, pure-JS simplicity |
| Rapier | Serious games: stable stacking, many bodies, a real character controller |
| None | Showcases, product viewers, data viz, background effects |
Recipes for all three are in references/physics.md; don't simulate things that want authored feel.
Scaffold with vg new <slug> --engine threejs (Vite + TypeScript, three from npm), or npm install three in any Vite project. Import Three.js and its addons (three/addons/...) from the package — never from a CDN URL or an import map: a deployed game would then depend on a third-party origin at runtime, and the URL pins a version that silently drifts from the one your types and tools assume.
<!-- index.html -->
<!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" src="/src/main.ts"></script>
</body>
</html>
// src/main.ts
import * as THREE from "three";
// 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);
});
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
}
Concrete per-surface values (painted metal, rubber, ceramic, glass, cloth, emissive) are in references/graphics-recipes.md. Two rules that matter more than the numbers: metals/glossy surfaces need an environment map or they render flat gray (see references/advanced-topics.md), and objects should differ by roughness/metalness contrast, not hue alone.
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);
In a game, add a rim/back light behind the player (opposite the camera) — it separates the character's silhouette from a busy background, which matters more than a prettier key light.
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:
import * as THREE from "three";
import { OrbitControls } from "three/addons/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);
});
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: 0xff0088THREE.OrbitControls is undefined in modern Three.js. Import from three/addons/controls/OrbitControls.js.three your types assume. Install from npm and let Vite bundle it.scene.add(object) → object won't render, silent failure.requestAnimationFrame instead of setAnimationLoop → more verbose, doesn't handle WebXR. Use renderer.setAnimationLoop((time) => { ... }).SphereGeometry(1, 32, 16), not (1, 128, 64).Math.min(window.devicePixelRatio, 2).createScene()/createLights()/createMeshes(); hoist constants into a CONFIG object.localStorage → throws in a sandboxed iframe (games run embedded in the web app) and the game boot-dies. Wrap every read/write in try/catch.Each app should feel context-appropriate, not templated. Vary by scenario:
Vary geometry (not always a cube), material style, color palette, and animation style. Avoid converging on the default green cube at z=5 with a directional light at (1,1,1).
Use ES modules from the three package or CDN — CommonJS and the global THREE are legacy.
See the Reference Files table near the top for the full map of references/ (gameplay systems, physics, controllers/camera, GLTF loading, game patterns, generated assets, advanced topics, debugging) and scripts/check-canvas.mjs. For 2D games use the phaser skill; for engine-agnostic feel/balance/level/onboarding craft use the game-craft skills.
modules/character-movement.ts (opens in a new tab)modules/kinematic-resolver.ts (opens in a new tab)modules/math.ts (opens in a new tab)modules/summary.md (opens in a new tab)references/advanced-topics.md (opens in a new tab)references/controllers-and-camera.md (opens in a new tab)references/debugging-and-profiling.md (opens in a new tab)references/game-patterns.md (opens in a new tab)references/gameplay-systems.md (opens in a new tab)references/generated-assets.md (opens in a new tab)references/gltf-loading-guide.md (opens in a new tab)references/graphics-recipes.md (opens in a new tab)references/physics.md (opens in a new tab)scripts/check-canvas.mjs (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
threejs, 3d-graphics, webgl, game-development, react-three-fiber
npx claudepluginhub kyh/vibedgames --plugin vibedgames35 skills in this plugin
/animated-spritesheetsGenerate a character's animation frames (idle, run, attack, death…) as one labeled pose board, then slice, key and pack them into an engine-ready spritesheet./animationMake 2D sprite animation read well: frame budgets per clip, timing and spacing, cancel windows, smears, secondary motion, wiring clips in Phaser. Generating frames is pixel-art / animated-spritesheets./asepriteParse Aseprite files (.ase/.aseprite) — layers, cels, tags, slices, palettes, tilesets — into JSON, durations and bounds for engines and tools./ask-meInterview the user about a fuzzy game idea, one question at a time, until it is build-ready. Skip when they already know what to build./asset-pipelineAudit 2D game art on disk: validate an asset manifest against PNGs, probe sprite sheets and tilesets for occupied frames, report sizes, fix sprite baselines./capacitor-iosShip a Three.js + Vite app on Capacitor iOS: GLTF loading, animation UI, OrbitControls touch mapping, Swift Package Manager, iOS sync and run troubleshooting.Other plugins' skills for the same job