Home / All Skills / Design & Motion / threejs-animation
Design & Motion · iart-ai/webgl-animation-skills

threejs-animation

This skill should be used when the user asks to "build a 3D hero section or WebGL background", "animate a Three.js scene", "play or crossfade GLTF animation clips", "move/lerp the camera or link it to scroll", "render thousands of objects with InstancedMesh", "set up React Three Fiber (R3F) motion", "add bloom/DOF post-processing", or "keep a Three.js/R3F animation smooth and leak-free (dispose geometries/materials/textures, free GPU memory on unmount)". Covers scenes, render loops, camera moves, GLTF AnimationMixer, instancing, scroll-linked 3D, R3F, and animation performance/disposal.

L4 High-Privilege · Graded auth & full auditV1 Commit-PinnedExecute CommandNetwork AccessWrite FileDual-pass Audit
Author iart-aiGitHub iart-ai/webgl-animation-skills ↗Stars 14License MIT(仓库根 LICENSE 为 MIT License / Copyright (c) 2026 iart.ai;.claude-plugin/plugin.json 亦声明 "license": "MIT")Commit 50697d659f
Control levels describe skill capabilities and suggested control measures; they do not represent quality or safety certifications, nor do they dictate usability. Usage decisions rest entirely with users and administrators. Different agent hosts apply varying constraints; do not assume hosts provide automatic protection. Third-party skill copyrights belong to their original authors. Use at your own risk.

1How It Works & Mechanism

The implementation principle consists of three API discipline sets plus one VRAM garbage collection discipline: frame-rate independence (multiply by dt), using setAnimationLoop instead of bare rAF, and treating the GPU resource lifecycle as a first-class citizen.

skills/threejs-animation/SKILL.md
Use `clock.getDelta()` to make motion frame-rate independent (multiply rates by `dt`), and `setAnimationLoop` (works with WebXR and pauses on tab blur) instead of raw `requestAnimationFrame`.
What is being done here: Clarifying "why not bare rAF" and "why multiply by dt"—these two rules determine the structure of all subsequent animation code.

GLTF playback relies on AnimationMixer, where the key is "updating the mixer with delta"; crossfading uses crossFadeTo (warping=false for linear weighting), and one-shot actions use LoopOnce + clampWhenFinished + finished event.

skills/threejs-animation/SKILL.md
Load a model, play clips through an `AnimationMixer`, and **update the mixer with delta time** every frame.
What is being done here: Providing the complete lifecycle of clip playback (load → clipAction → crossFade / one-shot), which is the most error-prone section in Three.js.

Camera motion employs exponential decay interpolation lerp(goal, 1 - exp(-lambda*dt)) rather than a fixed coefficient, ensuring consistent damping feel across arbitrary frame rates; scroll only alters the target position smoothed by damping, and curve fly-throughs follow CatmullRomCurve3 + getPointAt.

skills/threejs-animation/SKILL.md
Smooth camera follow uses exponential interpolation toward a target. Frame-rate-correct damping:
What is being done here: Turning "frame-rate correctness" from a slogan into a concrete formula, accompanied by the implementation entry point for curved paths.

Massive object counts leverage InstancedMesh to consolidate into a single draw call, with per-instance matrices set via setMatrixAt; per-frame updates require switching to DynamicDrawUsage, and color changes use setColorAt combined with setting needsUpdate.

skills/threejs-animation/SKILL.md
One draw call for thousands of identical meshes. Set per-instance matrices (and optional colors).
What is being done here: Pinning down the performance path for "thousands of objects" into a standardized API combination, detailing the necessary switches for per-frame updates.

The R3F branch is driven by useFrame(state, delta) and caps the DPR inside <Canvas dpr={[1, 2]}>; models and animations delegate to useGLTF and useAnimations, while springs and scrolling pull in @react-spring/three and drei ScrollControls as needed.

skills/threejs-animation/SKILL.md
Drive animation with `useFrame`; it receives `state` and `delta`.
What is being done here: Demonstrating the corresponding syntax for the same discipline set within a declarative renderer (useFrame + DPR cap).

VRAM disposal is the core of the documentation: explaining why standard GC cannot release GPU buffers/textures, providing criteria for "what to dispose and what not to", and supplying a full traversal routine handling material arrays and all texture slots.

skills/threejs-animation/SKILL.md
GPU resources (geometries, materials, textures, render targets) live on the *GPU*, not the JS heap. The garbage collector frees the JS objects but **cannot free the WebGL buffers/textures they uploaded**.
What is being done here: Addressing "why black canvas / CONTEXT_LOST_WEBGL occurs" and debunking the common misconception that scene.remove frees GPU resources.

The R3F leak boundary is clearly bifurcated: resources declaratively created via JSX are automatically disposed upon unmount, whereas imperative ones (instantiated via new in useMemo/ref/loaders) are not and must be manually disposed in useEffect cleanups; this is validated using renderer.info.memory across a 10-cycle mount/unmount baseline regression.

skills/threejs-animation/SKILL.md
Verify with `renderer.info.memory` (R3F: `useThree().gl.info.memory`): mount/unmount 10x; if `geometries`/`textures` does not return to baseline, something leaked.
What is being done here: Turning "whether it leaks" into a runnable, quantitative check rather than guesswork.

2Core Capabilities

01Minimal scene + render loop scaffold (camera parameters, DPR cap, resize, setAnimationLoop, dt-driven rotation)
02GLTF animations: AnimationMixer playback, crossFadeTo blending, LoopOnce + finished event handling
03Camera damped following and scroll-driven 3D (including CatmullRomCurve3 path fly-throughs)
04InstancedMesh batch rendering (per-instance matrix + per-instance color + per-frame needsUpdate performance switches)
05React Three Fiber motion: useFrame, DPR cap, useGLTF/useAnimations, drei ScrollControls and springs
06Performance checklist: DPR caps, geometry/material reuse and static geometry merging, minimizing real-time lights/shadows, favoring material animations over geometry transformations
07GPU VRAM disposal: disposeObject traversal (material arrays + all texture slots), renderer.dispose + forceContextLoss, R3F useMemo+cleanup, shared resource dispose={null}
08Deterministic screenshot harness (?t=N pinning elapsed time, mixer driven by absolute setTime) and pre-completion checklist

3External Dependencies

KindDependency / Endpoint
clinpx playwright screenshot(验证回路:截 file:// 页面冻结帧)
cli仓库根共享脚本 scripts/seek-shot.sh、scripts/contact-sheet.sh(不在 skill 目录内)
cliffmpeg / ffprobe(contact-sheet.sh / probe-mp4.sh)
packagethree + three/addons(GLTFLoader 等),产物期经 importmap 从 CDN 取
packageReact Three Fiber 生态(@react-three/fiber、drei 的 useGLTF/ScrollControls、@react-spring/three,以及 postprocessing 的 UnrealBloom / DepthOfField)

4Recommended Governance & Evidence

Suggested Controls for Safe Operation
For Agent Runtime
Graded/per-use authorization, sandbox recommended
For Administrators
Approval workflow, rollback support, full audit
Evidence & Triggers (File Paths & Excerpts)
  • scripts/: Executes local scripts or commands: (SKILL.md instruction) npx playwright screenshot --wait-for-timeout=600 "file://$PWD/
  • 网络端点: Declares external network access: No network call code inside skill directory; runtime network surface only stems from `npx playwright` tool acquisition (npm registry + Chromium binary download)
  • 本地工作目录: File read/write and artifact output: Artifact itself: single scene.html (created by agent per output contract)
Audit Notes: Evaluation target = the skill's own directory, containing only SKILL.md and two markdown references (plus a 0-byte README.md): no built-in scripts, no credential access, no endpoint calls, no exfiltration of user assets; deliverables are local single-file HTMLs (or the user's own R3F project). Runtime only involves local tools (`npx playwright screenshot` capturing file:// local pages, ffmpeg stitching images); artifact-phase HTML fetching three / three/addons from CDN via importmap represents browser-side retrieval (classified under the paradigm "artifact-phase references are not graded", noted in reason). Caveats: 1) `npx playwright` fetches remote packages and downloads Chromium on first run (supply chain exposure, unpinned versions); 2) scripts/seek-shot.sh and scripts/contact-sheet.sh reside in the repo root; installing the skill directory alone causes dangling references; 3) WebGL/GPU prerequisite: under headless SwiftShader software rendering, frame times deviate noticeably from real hardware; leak regressions should be rerun on a host GPU; 4) The R3F branch declares several third-party packages (fiber/drei/react-spring/postprocessing), which must be installed and version-pinned by the user's project. None meet yellow (no routine external network exfiltration) or orange criteria; full repo scan confirms no red-flag behaviors such as disabling sandboxes, disabling TLS, or bypassing automated detection.

5Second-Pass Verification

  • [ok] 「skill 目录内无脚本、无 3D 资产」是否成立 — 文件清单实证:目录内只有 SKILL.md、README.md(0 B) 与两份 markdown reference;无 .glb/.gltf/.hdr/贴图,也无 package.json 或构建配置。引用到的 scripts/*.sh 属仓库根资产。
  • [ok] 凭证/环境变量读取是否存在 — 本仓全仓正则 `process.env|API_KEY|TOKEN|SECRET|Authorization` 零命中;credential_reads 为空成立。
  • [ok] 是否有更高的触发条件被漏掉(红档特征) — `sandbox|automationcontrolled|no-verify|stealth|bypass|ignoreHTTPSErrors|dangerously` 全仓零命中;无任意代码执行面(交付物在浏览器沙箱内运行用户自己的场景代码)。
  • [ok] 「显存 GC 释放不了」的解释与处置是否自洽 — 文档先讲机制(GC 释放 JS 对象但释放不了上传的 WebGL buffer/texture),再给「该 dispose / 不用 dispose」清单,再给 disposeObject 遍历(含材质数组与 for…in 贴图槽),三者互证;scene.remove 的误解也单独点破:'it frees **nothing** on the GPU'。
  • [ok] R3F 自动 dispose 的边界声明是否有可验证手段 — 声明式自动 dispose vs imperative 泄漏的分界写得很具体,并要求 renderer.info.memory 挂载/卸载 10 次回归;references/resource-disposal.md 另附完整泄漏案例与 <DisposeOnUnmount> 方案,属可执行而非口号。
  • [ok] 冻结 harness 与 mixer 的配合是否写对(易错点) — harness 段用 `mixer.setTime(elapsed)` 并注释 'setTime is absolute, not delta',与循环里 `mixer.update(dt)` 的增量语义区分开,说明作者意识到差异,声明可信。

6Verdict & Scenarios

  • Treats VRAM disposal as the main storyline: mechanism → criteria → traversal code → quantitative regression, directly addressing symptoms like black canvas and CONTEXT_LOST
  • Pairs key APIs with explicit anti-pattern caveats (bare rAF, scene.remove, R3F only auto-disposing declarative resources)
  • Formalizes frame-rate correctness with a mathematical formula (exponential damping 1 - exp(-lambda*dt)), moving beyond the vague slogan of "just multiply by dt"
  • Covers the full GLTF lifecycle down to crossfading and single-shot wrap-up events, ready for direct copy-paste
  • Decoupled into two targeted reference guides; the disposal guide details texture slots, render targets, and HMR safety
  • Provides performance priorities and trade-offs (DPR capping yields the highest ROI; material animations are often much cheaper than moving geometry)
  • Best for: Ideal for 3D hero sections, WebGL backgrounds, product viewers, scroll-linked 3D, GLTF character playback, instancing thousands of objects, and handling motion/performance governance in R3F projects. Especially suitable for troubleshooting legacy issues like "animations run smoothly but VRAM usage keeps creeping up" or "black canvas appearing after route changes" (leak regression tests and disposal utilities are directly usable). The output is a self-contained, directly openable single-file HTML, also suitable as an internal team reference standard for Three.js performance and disposal.
    Not for: Not suitable for: 1) Video production requiring offline rendering or cinematic fidelity (this skill focuses on real-time WebGL); 2) Acceptance environments completely devoid of a GPU requiring near-bare-metal performance (software rendering will distort results); 3) Projects expecting bundled 3D assets and models (this skill provides code methodologies and references only, no models/textures); 4) Strict supply chain environments where CDN versions and third-party packages are unacceptable risks (must self-host and pin versions); 5) Standalone skill directory installations that expect repository-root scripts/ to be present.
    Install Agent-Ready
    ① Verified Mirror 2026-09-28
    Option A · Direct DownloadDownload threejs-animation.tar.gz
    sha256: de5e7ad51ab285c7…
    Option B · Copy Guide for Agent
    install.json
    Agents automatically download and verify mirrors from this JSON guide.
    ② Upstream GitHub
    GitHub Repo ↗
    Pinned to commit 50697d659f.