Index of every page on this site: llms.txt
All skills
impertio-studio avatar

/threejs-impl-animation

@6c190f0
Run it yourself

Use when playing animations, crossfading between animation states, or loading skeletal animations from GLTF in Three.js. Prevents the common mistake of not calling mixer.update(delta) every frame, wrong crossfade setup, or missing Clock. Covers AnimationMixer, AnimationClip, AnimationAction, KeyframeTrack, crossfade, blending. Keywords: animation, AnimationMixer, AnimationClip, AnimationAction, crossfade, skeletal, GLTF animation, keyframe, blend, Clock, camera animation, smooth camera, fly to, tween, GSAP.

Use this Skill: https://skilld.dev/gh/impertio-studio/three.js-claude-skill-package/threejs-impl-animation

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesanti-patterns.md

≈1.9k tokens on demand. Your agent reads this file only when SKILL.md points to it.

threejs-impl-animation — Anti-Patterns

What NOT to do with the Three.js Animation System. Every entry includes the mistake, why it fails, and the correct approach.


Anti-Pattern 1: Forgetting mixer.update(delta) in the Render Loop

WRONG:

const mixer = new THREE.AnimationMixer(model);
mixer.clipAction(clip).play();

function animate() {
  // Missing mixer.update(delta) -- animations will NEVER play
  renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);

WHY: The mixer does NOT advance time automatically. Without mixer.update(delta), all actions remain frozen at time 0.

CORRECT:

const clock = new THREE.Clock();
const mixer = new THREE.AnimationMixer(model);
mixer.clipAction(clip).play();

function animate() {
  const delta = clock.getDelta();
  mixer.update(delta); // ALWAYS call every frame
  renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);

Anti-Pattern 2: Using a Fixed Delta Instead of Clock

WRONG:

function animate() {
  mixer.update(1 / 60); // Assumes constant 60fps -- breaks on slow devices
  renderer.render(scene, camera);
}

WHY: Frame rates vary across devices and over time. A fixed delta causes animations to speed up or slow down unpredictably. On a 30fps device, animations play at half speed.

CORRECT:

const clock = new THREE.Clock();

function animate() {
  const delta = clock.getDelta(); // Actual time between frames
  mixer.update(delta);
  renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);

Anti-Pattern 3: Crossfading Without reset() on the Incoming Action

WRONG:

function switchToWalk() {
  walkAction.crossFadeFrom(idleAction, 0.5, true);
  walkAction.play();
  // walkAction may still have stale time/weight from a previous play
}

WHY: If the walk action was previously played and stopped, its internal state (time, weight, timeScale) retains old values. The crossfade starts from the wrong position or weight, producing jerky transitions.

CORRECT:

function switchToWalk() {
  walkAction.reset(); // ALWAYS reset before crossfading
  walkAction.setEffectiveTimeScale(1);
  walkAction.setEffectiveWeight(1);
  walkAction.crossFadeFrom(idleAction, 0.5, true);
  walkAction.play();
}

Anti-Pattern 4: Using LoopOnce Without clampWhenFinished

WRONG:

const action = mixer.clipAction(clip);
action.setLoop(THREE.LoopOnce, 1);
action.play();
// Animation snaps back to frame 0 after finishing

WHY: Without clampWhenFinished = true, the action resets to its initial state when it completes. The model visibly jumps back to the start pose, which looks broken for one-shot animations like door opens, attacks, or death animations.

CORRECT:

const action = mixer.clipAction(clip);
action.setLoop(THREE.LoopOnce, 1);
action.clampWhenFinished = true; // ALWAYS set for LoopOnce
action.play();

Anti-Pattern 5: Creating a New Mixer Every Frame

WRONG:

function animate() {
  const mixer = new THREE.AnimationMixer(model); // New mixer every frame!
  mixer.clipAction(clip).play();
  mixer.update(clock.getDelta());
  renderer.render(scene, camera);
}

WHY: Creating a new mixer every frame discards all previous action state. Animations restart from frame 0 every frame, producing a frozen first-frame appearance. It also generates massive garbage collection pressure.

CORRECT:

const mixer = new THREE.AnimationMixer(model); // Create ONCE
const action = mixer.clipAction(clip);
action.play();

function animate() {
  mixer.update(clock.getDelta());
  renderer.render(scene, camera);
}

Anti-Pattern 6: Calling play() Every Frame

WRONG:

const action = mixer.clipAction(clip);

function animate() {
  action.play(); // Called every frame -- unnecessary
  mixer.update(clock.getDelta());
  renderer.render(scene, camera);
}

WHY: .play() is an activation method, not an update method. While calling it on an already-playing action is harmless (it returns immediately), doing so every frame signals a fundamental misunderstanding of the API. It can also interfere with fading and crossfade transitions by re-activating an action that is being faded out.

CORRECT:

const action = mixer.clipAction(clip);
action.play(); // Call ONCE

function animate() {
  mixer.update(clock.getDelta());
  renderer.render(scene, camera);
}

Anti-Pattern 7: Instantiating AnimationAction Directly

WRONG:

const action = new THREE.AnimationAction(mixer, clip); // NEVER do this

WHY: AnimationAction is designed to be created and cached by the mixer. Direct instantiation bypasses the mixer's internal action cache, leading to duplicate actions, broken crossfades, and memory leaks.

CORRECT:

const action = mixer.clipAction(clip); // ALWAYS use mixer.clipAction()

Anti-Pattern 8: Forgetting to Dispose the Mixer on Model Removal

WRONG:

scene.remove(model);
// Mixer still holds references, continues to call update, leaks memory

WHY: The mixer retains internal references to the model and all its actions. If the model is removed from the scene but the mixer is not cleaned up, it continues to consume memory and CPU during mixer.update().

CORRECT:

mixer.stopAllAction();
mixer.uncacheRoot(model);
scene.remove(model);
mixer = null; // Allow garbage collection

Anti-Pattern 9: Using Multiple Mixers for the Same Model

WRONG:

const mixer1 = new THREE.AnimationMixer(model);
const mixer2 = new THREE.AnimationMixer(model);
mixer1.clipAction(walkClip).play();
mixer2.clipAction(idleClip).play();

WHY: Multiple mixers on the same root object cause conflicting property writes. Both mixers attempt to set the same bone transforms every frame, producing jittering, twitching, or completely broken animation. Crossfade and blending between clips on different mixers is impossible.

CORRECT:

const mixer = new THREE.AnimationMixer(model); // ONE mixer per model
mixer.clipAction(walkClip).play();
mixer.clipAction(idleClip).play();
// Use weight and crossfade to blend between them

Anti-Pattern 10: Animating material.opacity Without Setting transparent=true

WRONG:

const track = new THREE.NumberKeyframeTrack(
  'Mesh.material.opacity',
  [0, 1],
  [1, 0]
);
// Opacity changes but object remains fully visible

WHY: Three.js materials require material.transparent = true for opacity values below 1 to have any visual effect. Without this flag, the material ignores the opacity property during rendering.

CORRECT:

material.transparent = true; // MUST set before animating opacity

const track = new THREE.NumberKeyframeTrack(
  'Mesh.material.opacity',
  [0, 1],
  [1, 0]
);

Anti-Pattern 11: Using getDelta() Multiple Times per Frame

WRONG:

function animate() {
  mixer1.update(clock.getDelta()); // Returns actual delta
  mixer2.update(clock.getDelta()); // Returns ~0 (called immediately after)
  renderer.render(scene, camera);
}

WHY: clock.getDelta() returns the time since the LAST call to getDelta(). The second call within the same frame returns approximately zero, effectively freezing the second mixer.

CORRECT:

function animate() {
  const delta = clock.getDelta(); // Call ONCE per frame
  mixer1.update(delta);
  mixer2.update(delta); // Same delta for both
  renderer.render(scene, camera);
}

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts5mo3 checks · Risk SAFE
  • Gen Agent Trust Hub5mo

    The skill is a comprehensive documentation and implementation guide for Three.js animations. It includes API references, best practices, and code examples. No malicious patterns, network exfiltration, or unauthorized command executions were found.

  • Socket5mo

    No alerts

  • Snyk5mo

    Risk: LOW · No issues

Signed by skilld at 6c190f0. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 months ago.

Steadyupdated 8 months ago
compatibility
Designed for Claude Code. Requires Three.js r160+.
metadata
{
  "author": "OpenAEC-Foundation",
  "version": "1.0"
}

README badge

README badge for impertio-studio/three.js-claude-skill-package/threejs-impl-animation