Loading...
Loading...
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.
npx skill4agent add noklip-io/agent-skills three-jsReact Three Fiber users: This reference is for vanilla Three.js. For R3F/Drei patterns, use theskill. However, understanding Three.js concepts here helps when working with R3F since R3F is a React renderer for Three.js.r3f-best-practices
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 | Use When |
|---|---|
| Scene setup, renderer config, Object3D hierarchy, coordinate systems |
| Creating shapes, BufferGeometry, instancing, points, lines |
| Camera types, frustum, viewport, projection |
| Vector3, Matrix4, Quaternion, Euler, Color, MathUtils |
| Reference | Use When |
|---|---|
| PBR materials, shader materials, all material types |
| Texture loading, UV mapping, render targets, environment maps |
| Light types, shadows, IBL, light probes |
| Custom GLSL shaders, uniforms, varyings, shader patterns |
| Reference | Use When |
|---|---|
| Keyframe animation, skeletal, morph targets, procedural motion |
| Raycasting, selection, drag, coordinate conversion |
| OrbitControls, FlyControls, PointerLockControls, etc. |
| Reference | Use When |
|---|---|
| GLTF, FBX, textures, HDR, Draco compression, async patterns |
| Reference | Use When |
|---|---|
| Bloom, DOF, SSAO, custom effects, EffectComposer |
| Reference | Use When |
|---|---|
| Optimization, profiling, LOD, culling, batching |
| TSL (Three Shading Language), node-based materials |
| Physics engines, WebXR, VR/AR integration |
| WebGPU renderer, compute shaders, WGSL |
| Architecture patterns, asset management, cleanup, state |
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});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();
}
}
});
}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);
}// 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';