threejs-animation
Keyframe, skeletal and morph-target animation, procedural motion and clip blending, on WebGL or with WebGPU and TSL. Use when…
Three.js scene setup: scenes and fog, cameras, the renderer and tone mapping, the animation loop, object hierarchies, transforms, core math and cleanup, on WebGL or with WebGPU and TSL. Use when creating a scene from scratch, configuring a camera or renderer, handling resize, or
Claude Code
$ npx -y skills add cloudai-x/threejs-skills --skill threejs-fundamentals --agent claude-code
Codex
$ npx skills add cloudai-x/threejs-skills --skill threejs-fundamentals -a codex -y
Cursor
$ npx skills add cloudai-x/threejs-skills --skill threejs-fundamentals -a cursor -y
Gemini CLI
$ npx skills add cloudai-x/threejs-skills --skill threejs-fundamentals -a gemini-cli -y
GitHub Copilot
$ npx skills add cloudai-x/threejs-skills --skill threejs-fundamentals -a github-copilot -y
OpenCode
$ npx skills add cloudai-x/threejs-skills --skill threejs-fundamentals -a opencode -y
Windsurf
$ npx skills add cloudai-x/threejs-skills --skill threejs-fundamentals -a windsurf -y
name: threejs-fundamentals description: "Three.js scene setup: scenes and fog, cameras, the renderer and tone mapping, the animation loop, object hierarchies, transforms, core math and cleanup, on WebGL or with WebGPU and TSL. Use when creating a scene from scratch, configuring a camera or renderer, handling resize, or arranging objects."
Targets three.js r186. Examples use WebGLRenderer; the WebGPU and TSL section uses WebGPURenderer.
import * as THREE from "three";
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x111318);
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.set(0, 1.5, 5);
const cube = new THREE.Mesh(
new THREE.BoxGeometry(1, 1, 1),
new THREE.MeshStandardMaterial({ color: 0x3a86ff }),
);
scene.add(cube);
const light = new THREE.DirectionalLight(0xffffff, 2);
light.position.set(3, 4, 5); // shines from its position toward the origin
scene.add(light);
scene.add(new THREE.AmbientLight(0xffffff, 0.4));
const timer = new THREE.Timer();
timer.connect(document); // freezes the delta while the tab is hidden
function animate() {
timer.update(); // advance the timer first thing each frame
cube.rotation.y += timer.getDelta(); // seconds since the previous frame
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});Without a bundler, the browser loads three.js as ES modules through an import map; this is the map for the WebGLRenderer examples above:
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.186.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.186.0/examples/jsm/"
}
}
</script>For WebGPURenderer work, map all four keys — `three.tsl.js` imports `three/webgpu`, so the map fails without that entry:
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.186.0/build/three.webgpu.js",
"three/webgpu": "https://cdn.jsdelivr.net/npm/three@0.186.0/build/three.webgpu.js",
"three/tsl": "https://cdn.jsdelivr.net/npm/three@0.186.0/build/three.tsl.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.186.0/examples/jsm/"
}
}
</script>const scene = new THREE.Scene(); scene.background = new THREE.Color(0x111318); // solid color scene.fog = new THREE.Fog(0x111318, 1, 100); // linear fog: near, far scene.fog = new THREE.FogExp2(0x111318, 0.02); // exponential fog: density (pick one)
// PerspectiveCamera(fov in degrees, aspect, near, far) const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000); camera.position.set(0, 5, 10); camera.lookAt(0, 0, 0); // rotates the camera to face the target camera.fov = 60; camera.updateProjectionMatrix(); // required after changing fov, aspect, near or far
// OrthographicCamera(left, right, top, bottom, near, far); frustum size in world units const aspect = window.innerWidth / window.innerHeight; const frustumHeight = 10; const camera = new THREE.OrthographicCamera( (-frustumHeight * aspect) / 2, (frustumHeight * aspect) / 2, frustumHeight / 2, -frustumHeight / 2, 0.1, 1000, ); // on resize: recompute left and right from the new aspect, then call camera.updateProjectionMatrix()
// Renders the scene once per sub-camera, each into its own viewport.
// Viewport units under WebGLRenderer are drawing-buffer pixels (CSS size × pixel ratio);
// WebGPURenderer multiplies CSS pixels by the pixel ratio itself.
const width = window.innerWidth;
const height = window.innerHeight;
const dpr = renderer.getPixelRatio();
const cameras = [];
for (let i = 0; i < 4; i++) {
const subCamera = new THREE.PerspectiveCamera(75, width / height, 0.1, 100);
subCamera.viewport = new THREE.Vector4(
((i % 2) * width * dpr) / 2,
(Math.floor(i / 2) * height * dpr) / 2,
(width * dpr) / 2,
(height * dpr) / 2,
);
subCamera.position.set(-2 + (i % 2) * 4, 1.5, 6);
subCamera.lookAt(0, 0, 0);
subCamera.updateMatrixWorld(); // sub-cameras are not scene-graph children; update them when they move
cameras.push(subCamera);
}
const arrayCamera = new THREE.ArrayCamera(cameras);
arrayCamera.position.set(0, 1.5, 6); // WebGLRenderer culls every viewport with this camera's frustum (fov 50, aspect 1 by default); WebGPURenderer uses each sub-camera's frustum
renderer.render(scene, arrayCamera);const cubeRenderTarget = new THREE.WebGLCubeRenderTarget(256);
const cubeCamera = new THREE.CubeCamera(0.1, 1000, cubeRenderTarget);
scene.add(cubeCamera);
const chrome = new THREE.Mesh(
new THREE.SphereGeometry(1, 32, 16),
new THREE.MeshStandardMaterial({ color: 0xffffff, metalness: 1, roughness: 0 }),
);
chrome.material.envMap = cubeRenderTarget.texture;
scene.add(chrome);
//Skill files that give Claude Code current, verified knowledge of three.js, so the code it writes runs on the release you actually install. The skills target three.js r186 (three@0.186), React Three Fiber 9.8 with drei 10.7, and gltf-transform 4.5.
Keyframe, skeletal and morph-target animation, procedural motion and clip blending, on WebGL or with WebGPU and TSL. Use when…
Shrinking glTF assets for three.js with gltf-transform: inspect, validate and optimize commands, Draco, meshopt and quantization,…
Creating and shaping three.js geometry: built-in shapes, 3D text, vertex buffers and attributes, merging, instancing, batching,…
Picking with raycasting, camera controls, transform gizmos, drag, hover and box selection for three.js, identical under WebGL and…
Light types and physical units, shadow maps, HDR environment lighting, light probes, and lighting performance, on WebGL or with…
Loading three.js assets: glTF with Draco, meshopt and KTX2 compression, other model formats, textures, HDR and EXR environments,…
Migrates React projects and components from Radix UI to Base UI. Use when asked to migrate from radix, move to base-ui, convert…
tasteskill v2, the anti-slop frontend skill. Art direction for websites, distilled from a study of 247 curated gallery sites (One…