Three.js Complete Reference (Vanilla)
React Three Fiber users: This reference is for vanilla Three.js. For R3F/Drei patterns,
use the r3f-best-practices skill. However, understanding Three.js concepts here
helps when working with R3F since R3F is a React renderer for Three.js.
Quick Start
import * as THREE from 'three';
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);
const geometry = new THREE.BoxGeometry(1, 1, 1);
const material = new THREE.MeshStandardMaterial({ color: 0x00ff00 });
const cube = new THREE.Mesh(geometry, material);
scene.add(cube);
scene.add(new THREE.AmbientLight(0xffffff, 0.5));
const light = new THREE.DirectionalLight(0xffffff, 1);
light.position.set(5, 5, 5);
scene.add(light);
camera.position.z = 5;
function animate() {
requestAnimationFrame(animate);
cube.rotation.x += 0.01;
cube.rotation.y += 0.01;
renderer.render(scene, camera);
}
animate();
Reference Index
Load the appropriate reference file based on task:
Core Foundation
| Reference |
Use When |
references/01-fundamentals.md |
Scene setup, renderer config, Object3D hierarchy, coordinate systems |
references/02-geometry.md |
Creating shapes, BufferGeometry, instancing, points, lines |
references/06-cameras.md |
Camera types, frustum, viewport, projection |
references/13-math.md |
Vector3, Matrix4, Quaternion, Euler, Color, MathUtils |
Visual Appearance
| Reference |
Use When |
references/03-materials.md |
PBR materials, shader materials, all material types |
references/04-textures.md |
Texture loading, UV mapping, render targets, environment maps |
references/05-lighting.md |
Light types, shadows, IBL, light probes |
references/11-shaders.md |
Custom GLSL shaders, uniforms, varyings, shader patterns |
Motion & Interaction
| Reference |
Use When |
references/08-animation.md |
Keyframe animation, skeletal, morph targets, procedural motion |
references/09-interaction.md |
Raycasting, selection, drag, coordinate conversion |
references/10-controls.md |
OrbitControls, FlyControls, PointerLockControls, etc. |
Assets
| Reference |
Use When |
references/07-loaders.md |
GLTF, FBX, textures, HDR, Draco compression, async patterns |
Effects
| Reference |
Use When |
references/12-postprocessing.md |
Bloom, DOF, SSAO, custom effects, EffectComposer |
Advanced
| Reference |
Use When |
references/14-performance.md |
Optimization, profiling, LOD, culling, batching |
references/15-node-materials.md |
TSL (Three Shading Language), node-based materials |
references/16-physics-vr.md |
Physics engines, WebXR, VR/AR integration |
references/17-webgpu.md |
WebGPU renderer, compute shaders, WGSL |
references/18-patterns.md |
Architecture patterns, asset management, cleanup, state |
Common Patterns Quick Reference
Resize Handler
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
Cleanup/Dispose
function dispose(obj) {
obj.traverse(child => {
if (child.geometry) child.geometry.dispose();
if (child.material) {
if (Array.isArray(child.material)) {
child.material.forEach(m => m.dispose());
} else {
child.material.dispose();
}
}
});
}
Animation Loop with Clock
const clock = new THREE.Clock();
function animate() {
const delta = clock.getDelta();
const elapsed = clock.getElapsedTime();
// Use delta for frame-rate independent animation
mixer?.update(delta);
requestAnimationFrame(animate);
renderer.render(scene, camera);
}
Import Patterns
// Core
import * as THREE from 'three';
// Addons (controls, loaders, effects)
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { RGBELoader } from 'three/addons/loaders/RGBELoader.js';
import { EffectComposer } from 'three/addons/postprocessing/EffectComposer.js';
// Compression support
import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';
import { KTX2Loader } from 'three/addons/loaders/KTX2Loader.js';
Version Notes
This reference targets Three.js r150+ with notes for:
- WebGPU support (r150+)
- Node materials / TSL
- Modern ES module imports
For version-specific APIs, check the Three.js migration guide.
1---2name: three-js3description: This skill should be used when the user asks to "create a 3D scene", "add a mesh", "implement OrbitControls", "load a GLTF model", "add bloom post-processing", "write a custom shader", "create particle effects", "optimize Three.js performance", "use WebGPU", "add shadows", "animate a model", or mentions Three.js, threejs, WebGL, WebGPU, GLTF, raycaster, shader material, PBR material, or post-processing effects. IMPORTANT: This skill is for VANILLA Three.js (imperative JavaScript). For React Three Fiber (@react-three/fiber, R3F, drei), check the `r3f-best-practices` skill, although three-js skills helps when working with R3F since R3F is a React renderer for Three.js. Provides complete Three.js reference for 3D web graphics including scene setup, geometry, materials, textures, lighting, cameras, loaders, animation, controls, interaction, shaders, post-processing, performance optimization, TSL/node materials, WebGPU, physics, and VR/XR integration.4---5
6# Three.js Complete Reference (Vanilla)
7
8> **React Three Fiber users**: This reference is for vanilla Three.js. For R3F/Drei patterns,
9> use the **`r3f-best-practices`** skill. However, understanding Three.js concepts here
10> helps when working with R3F since R3F is a React renderer for Three.js.
11
12## Quick Start
13
14```javascript
15import * as THREE from 'three';
16
17const scene = new THREE.Scene();
18const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
19const renderer = new THREE.WebGLRenderer({ antialias: true });
20
21renderer.setSize(window.innerWidth, window.innerHeight);
22renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
23document.body.appendChild(renderer.domElement);
24
25const geometry = new THREE.BoxGeometry(1, 1, 1);
26const material = new THREE.MeshStandardMaterial({ color: 0x00ff00 });
27const cube = new THREE.Mesh(geometry, material);
28scene.add(cube);
29
30scene.add(new THREE.AmbientLight(0xffffff, 0.5));
31const light = new THREE.DirectionalLight(0xffffff, 1);
32light.position.set(5, 5, 5);
33scene.add(light);
34
35camera.position.z = 5;
36
37function animate() {
38 requestAnimationFrame(animate);
39 cube.rotation.x += 0.01;
40 cube.rotation.y += 0.01;
41 renderer.render(scene, camera);
42}
43animate();
44```
45
46## Reference Index
47
48Load the appropriate reference file based on task:
49
50### Core Foundation
51| Reference | Use When |
52|-----------|----------|
53| `references/01-fundamentals.md` | Scene setup, renderer config, Object3D hierarchy, coordinate systems |
54| `references/02-geometry.md` | Creating shapes, BufferGeometry, instancing, points, lines |
55| `references/06-cameras.md` | Camera types, frustum, viewport, projection |
56| `references/13-math.md` | Vector3, Matrix4, Quaternion, Euler, Color, MathUtils |
57
58### Visual Appearance
59| Reference | Use When |
60|-----------|----------|
61| `references/03-materials.md` | PBR materials, shader materials, all material types |
62| `references/04-textures.md` | Texture loading, UV mapping, render targets, environment maps |
63| `references/05-lighting.md` | Light types, shadows, IBL, light probes |
64| `references/11-shaders.md` | Custom GLSL shaders, uniforms, varyings, shader patterns |
65
66### Motion & Interaction
67| Reference | Use When |
68|-----------|----------|
69| `references/08-animation.md` | Keyframe animation, skeletal, morph targets, procedural motion |
70| `references/09-interaction.md` | Raycasting, selection, drag, coordinate conversion |
71| `references/10-controls.md` | OrbitControls, FlyControls, PointerLockControls, etc. |
72
73### Assets
74| Reference | Use When |
75|-----------|----------|
76| `references/07-loaders.md` | GLTF, FBX, textures, HDR, Draco compression, async patterns |
77
78### Effects
79| Reference | Use When |
80|-----------|----------|
81| `references/12-postprocessing.md` | Bloom, DOF, SSAO, custom effects, EffectComposer |
82
83### Advanced
84| Reference | Use When |
85|-----------|----------|
86| `references/14-performance.md` | Optimization, profiling, LOD, culling, batching |
87| `references/15-node-materials.md` | TSL (Three Shading Language), node-based materials |
88| `references/16-physics-vr.md` | Physics engines, WebXR, VR/AR integration |
89| `references/17-webgpu.md` | WebGPU renderer, compute shaders, WGSL |
90| `references/18-patterns.md` | Architecture patterns, asset management, cleanup, state |
91
92## Common Patterns Quick Reference
93
94### Resize Handler
95```javascript
96window.addEventListener('resize', () => {
97 camera.aspect = window.innerWidth / window.innerHeight;
98 camera.updateProjectionMatrix();
99 renderer.setSize(window.innerWidth, window.innerHeight);
100});
101```
102
103### Cleanup/Dispose
104```javascript
105function dispose(obj) {
106 obj.traverse(child => {
107 if (child.geometry) child.geometry.dispose();
108 if (child.material) {
109 if (Array.isArray(child.material)) {
110 child.material.forEach(m => m.dispose());
111 } else {
112 child.material.dispose();
113 }
114 }
115 });
116}
117```
118
119### Animation Loop with Clock
120```javascript
121const clock = new THREE.Clock();
122
123function animate() {
124 const delta = clock.getDelta();
125 const elapsed = clock.getElapsedTime();
126
127 // Use delta for frame-rate independent animation
128 mixer?.update(delta);
129
130 requestAnimationFrame(animate);
131 renderer.render(scene, camera);
132}
133```
134
135## Import Patterns
136
137```javascript
138// Core
139import * as THREE from 'three';
140
141// Addons (controls, loaders, effects)
142import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
143import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
144import { RGBELoader } from 'three/addons/loaders/RGBELoader.js';
145import { EffectComposer } from 'three/addons/postprocessing/EffectComposer.js';
146
147// Compression support
148import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';
149import { KTX2Loader } from 'three/addons/loaders/KTX2Loader.js';
150```
151
152## Version Notes
153
154This reference targets Three.js r150+ with notes for:
155- WebGPU support (r150+)
156- Node materials / TSL
157- Modern ES module imports
158
159For version-specific APIs, check the Three.js migration guide.