Keyframe, skeletal and morph-target animation, procedural motion and clip blending, on WebGL or with WebGPU and TSL. Use when animating objects, playing glTF animations, posing bones, driving morph targets, or mixing and crossfading clips.
Read from this skill's files on GitHub on 2026-11-09. These are facts about the files, not a review of how well the skill works.
Files
1 file, 0 scripts, SKILL.md is 2624 words
Needs on your machine
Nothing beyond the agent: no scripts or install commands found
Web addresses in its scripts
No URLs in its scripts
Worth a look before running
No sudo, rm -rf, curl | sh or shell=True in its scripts
Agent Skills spec
name and description present, name matches the folder
Last upstream change
2026-10-18
We ran this skill ourselves. Here is what went in and what came out.
Field noteRan on 2026-11-22
Claude Code 2.1.329, claude-opus-5-5, headless, 61s. Claude picked the skill on its own from a plain prompt. How we test skills
Terminal log of the run, rendered from Claude Code's stream-json output. Long steps are trimmed.
Input
Empty folder. Prompt: index.html with three.js from a CDN via import map, a cube bouncing with squash and stretch, a sphere orbiting it, a proper delta-time loop.
Output
three.js r186 from jsDelivr, renderer.setAnimationLoop with THREE.Timer and delta capped at 0.1s, a cube scaled from its base so it keeps volume, a quarter turn per jump, and an orbiting sphere.
What happened
The squash-and-stretch math is careful, including stretching most near the ground where it moves fastest. Claude checked the CDN file exists but did not open the page. We loaded it in headless Chrome and the scene rendered without errors.
Use it when
Procedural or keyframe motion in a three.js scene where frame-rate independence matters.
Skip it when
Loading from file://. Import maps need a local server.
Three.js Animation
Targets three.js r186. Examples use WebGLRenderer; the WebGPU and TSL section uses WebGPURenderer.
Quick Start
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();const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 100);camera.position.set(0, 0.5, 3);const mesh = new THREE.Mesh(new THREE.BoxGeometry(1, 1, 1), new THREE.MeshNormalMaterial());scene.add(mesh);const timer = new THREE.Timer();timer.connect(document); // also keeps deltas small after the tab was hiddenfunction animate() { timer.update(); // first thing each frame: fixes getDelta()/getElapsed() for this frame const delta = timer.getDelta(); const elapsed = timer.getElapsed(); mesh.rotation.y += delta; // frame-rate-independent spin mesh.position.y = Math.sin(elapsed * 2) * 0.25; // bob on absolute time renderer.render(scene, camera);}renderer.setAnimationLoop(animate);
How the System Fits Together
AnimationClip: keyframe data — tracks of times and values, no playback state.
AnimationMixer: plays clips on one root object and all its descendants.
AnimationAction: playback control for one clip on one mixer.
Each frame, mixer.update(delta) samples the active clips and writes the values into ordinary object properties. The system runs on the CPU and never touches the renderer, so it drives models the same way under either renderer.
AnimationClip and Keyframe Tracks
// One track per animated property. values.length must be times.length * valueSize.const times = [0, 1, 2]; // keyframe times in secondsconst values = [0, 1, 0]; // one scalar per keyframe for a Number trackconst track = new THREE.
Track names follow nodeName.objectName[objectIndex].propertyName[propertyIndex]; all parts except the property are optional. .position binds the root's position, .material.opacity a material property, .position[y] one component, .morphTargetInfluences[smile] one morph target, Hips.position a named descendant — that is how bones are addressed in a skinned model. Object names may be material, materials, bones or map.
// Number track (value size 1); create the material with transparent: true, or opacity is ignorednew THREE.NumberKeyframeTrack(".material.opacity", [0, 1], [1, 0]);// Vector track (value size 3: x, y, z per keyframe)new THREE.VectorKeyframeTrack(".position"
const track = new THREE.NumberKeyframeTrack(".rotation[y]", [0, 2], [0, Math.PI * 2]);const clip = new THREE
AnimationAction
const mixer = new THREE.AnimationMixer(mesh);const clip = new THREE.AnimationClip("spin", 2, [ new THREE.NumberKeyframeTrack(
Fades and Crossfades
const mixer = new THREE.AnimationMixer(mesh);const idleClip = new THREE.AnimationClip("idle", 2, [ new THREE.NumberKeyframeTrack(".position[y]"
Playing glTF Animations
import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js";import * as SkeletonUtils from "three/addons/utils/SkeletonUtils.js";const gltf = await new GLTFLoader
Skeletal Animation
// mesh is the loaded model root; find its first SkinnedMeshconst skinnedMesh = mesh.getObjectByProperty("type", "SkinnedMesh");const skeleton = skinnedMesh.skeleton;console.log(skeleton.bones.map((b) => b.name));// Grab a bone to pose or attach toconst handBone =
Procedural bone control runs aftermixer.update(), or a clip that animates the same bone overwrites it:
const skinnedMesh = mesh.getObjectByProperty("type", "SkinnedMesh");const headBone = skinnedMesh.skeleton.bones.find((b) => b.name === "Head");const mixer = new THREE
Bones are Object3Ds, so attaching means parenting:
// mesh carries morph targets (loaded, or added by hand below)const names = Object.keys(mesh.morphTargetDictionary); // name -> indexconsole.log(names, mesh.morphTargetInfluences); // one weight per target// Blend a target by index or by name; 0 = base shape, 1 = full targetmesh.morphTargetInfluences[0] = 0.5;const smileIndex = mesh.morphTargetDictionary["Mouth_Smile"];
Adding a morph target by hand:
const geometry = mesh.geometry;// A morph target is a full-size position (or normal) attribute beside the base oneconst raised = geometry.attributes.position.array.slice(); // same vertex countfor (let i = 1; i < raised.length; i += 3) {
Driving morph targets:
// Procedural, inside the render loop after timer.update():// mesh.morphTargetInfluences[0] = (Math.sin(timer.getElapsed() * 2) + 1) / 2;// Keyframed: a Number track drives one target by name — never a String trackconst track = new THREE.NumberKeyframeTrack( ".morphTargetInfluences[raised]", [0, 0.5, 1], [0, 1, 0
Blending Clips by Weight
const mixer = new THREE.AnimationMixer(mesh);const idleClip = new THREE.AnimationClip("idle", 2, [ new THREE.NumberKeyframeTrack(".position[y]", [0
Additive Animation
const mixer = new THREE.AnimationMixer(mesh);const walkClip = new THREE.AnimationClip("walk", 1, [ new THREE.NumberKeyframeTrack(".rotation[y]", [0,
Clip Utilities
const clip = new THREE.AnimationClip("walk", 2, [ new THREE.NumberKeyframeTrack(".rotation[y]", [0, 1, 2], [0, Math.
Procedural Motion
const timer = new THREE.Timer();timer.connect(document);// Exponential approach; a higher lambda snaps faster. Frame-rate independent.// The same shape drives positions, rotations or any scalar each frame.let scale = 0;function animate() { timer.update(); scale =
Performance
The same AnimationClip can feed any number of mixers — share one clip set across characters instead of copying it.
Call mixer.update() only for characters that are visible or about to be; an un-updated mixer simply leaves the last pose in place.
A SkinnedMesh computes its bounding sphere once, the first time culling or raycasting needs it, so a clip that moves it far from that pose can get it culled at the screen edge: after mixer.update() call mixer.getRoot().updateMatrixWorld() then skinnedMesh.computeBoundingSphere() (a CPU pass over every vertex) or set skinnedMesh.frustumCulled = false.
// Free a mixer and its cached bindings when its model leaves for goodconst mixer = new THREE.AnimationMixer(mesh);mixer.stopAllAction();mixer.uncacheRoot(mesh); // releases the property bindings created for the model
WebGPU and TSL
Everything above — mixer, actions, bone transforms, morph weights — is computed on the CPU and drives a model under WebGPURenderer unchanged. TSL adds animation on the GPU: time (elapsed seconds) and deltaTime (seconds since the previous frame) are float uniforms the renderer refreshes every frame, and the oscillators oscSine, oscSquare, oscTriangle and oscSawtooth return 0-to-1 waves with a one-second period from a time node, defaulting to time (oscSine(time.mul(0.5)) takes two seconds). Per-vertex motion needs a node material and a subdivided mesh.
import * as THREE from "three/webgpu";import { positionLocal, time, vec3 } from "three/tsl";const renderer = new THREE.WebGPURenderer({ antialias:
On a skinned mesh, build displacement on positionLocal: skinning, morph targets, batching and instancing are applied to it before positionNode runs, so the mixer-driven pose survives. positionGeometry is the raw rest-pose attribute — never the base for displacement on an animated mesh.
import * as THREE from "three/webgpu";import { color, mix, oscSine, positionLocal, vec3 } from "three/tsl";// The pulse rides on top of the skinned pose: positionLocal already carries itconst material = new THREE.MeshBasicNodeMaterial();material.positionNode = positionLocal.add
Common Mistakes
const clock = new THREE.Clock(); → const timer = new THREE.Timer(); timer.connect(document);: the Clock class is deprecated in r183 and Timer is its replacement.
const elapsed = clock.getElapsedTime(); const delta = clock.getDelta(); → timer.update(); const delta = timer.getDelta(); const elapsed = timer.getElapsed();: getElapsedTime() calls getDelta() internally, so the following delta read is about zero and the mixer stalls.
requestAnimationFrame(animate); → renderer.setAnimationLoop(animate);: both renderers' docs advise it over a manual loop, and it hands frames to the WebXR session when one starts.
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js"; → import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js";: the examples/jsm specifier does not resolve under the standard import map.
new THREE.NumberKeyframeTrack(".material.opacity", [0, 1, 2], [1, 0]) → new THREE.NumberKeyframeTrack(".material.opacity", [0, 1], [1, 0]): values must hold times.length × valueSize entries; with a fractional ratio play() never returns, and any other mismatch samples wrong values.
new THREE.StringKeyframeTrack(".morphTargetInfluences[smile]", [0, 1], ["0", "1"]) → new THREE.NumberKeyframeTrack(".morphTargetInfluences[smile]", [0, 1], [0, 1]): morph influences are numbers, and a string track writes "0"/"1" strings into the array.
See Also
threejs-fundamentals — render loop, Timer, renderer and scene setup
threejs-loaders — loading glTF models and their animation clips
threejs-shaders — GPU vertex displacement with TSL or ShaderMaterial
NumberKeyframeTrack
(
".position[y]"
, times, values);
// the root's position.y
const clip = new THREE.AnimationClip("bounce", 2, [track]); // duration in seconds
// pass -1 as the duration to derive it from the tracks
, [
0
,
1
,
2
], [
0
,
0
,
0
,
1
,
2
,
0
,
0
,
0
,
0
]);
// Rotation track (value size 4): quaternion x, y, z, w per keyframe, not Euler angles
const q2 = new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0, 1, 0), Math.PI);
const skinnedMesh = scene.getObjectByProperty("type", "SkinnedMesh"); // a loaded animated model
if (skinnedMesh) skinnedMesh.material = material;
headBone.rotation.y = Math.sin(t) * 0.3; mixer.update(delta); → mixer.update(delta); headBone.rotation.y = Math.sin(t) * 0.3;: update() writes the clip's pose over any value set before it.
clip.resetDuration() → action.reset(): resetDuration() only recomputes the clip's duration from its longest track, while reset() rewinds the action to time 0 and re-enables it after a one-shot finished.
material.positionNode = positionGeometry.add(offset) → material.positionNode = positionLocal.add(offset): positionGeometry is the raw attribute, so building on it drops skinning, morph targets, batching and instancing.
const uTime = uniform(0); uTime.value = timer.getElapsed(); const wave = uTime.mul(2).sin(); → const wave = time.mul(2).sin();: the renderer already advances the TSL time node every frame, so a Timer-fed uniform is redundant per-frame JavaScript.
const model2 = model.clone(); → const model2 = SkeletonUtils.clone(model);: cloning a skinned model shares its skeleton between the copies; each copy needs its own.
import { clone } from "three/addons/utils/SkeletonUtils.js"; → import * as SkeletonUtils from "three/addons/utils/SkeletonUtils.js";: the namespace keeps the call as SkeletonUtils.clone(model), which cannot be mistaken for the skeleton-sharing model.clone().
new Promise((resolve, reject) => loader.load(url, resolve, undefined, reject)) → await loader.loadAsync(url): loaders already expose the promise form, and loadAsync takes the progress callback as its second argument.