Communitygithub.com

Desesbraker/agentes-vip

Three.jsアニメーション - キーフレームアニメーション、スケルタルアニメーション、モーフターゲット、アニメーションブレンド。オブジェクトのアニメーション、GLTFアニメーションの再生、プロシージャルモーションの作成、アニメーションブレンドを行う際に使用します。

agentes-vip とは?

このスキルは、Three.jsアニメーションシステムの包括的なリファレンスを提供します。キーフレームアニメーション(AnimationClip)、アニメーションミキサー(AnimationMixer)、再生制御(AnimationAction)の3つの主要コンポーネントをカバーし、GLTFファイルからのスケルタルアニメーション読み込み、モーフターゲットによる形状ブレンド、複数アニメーションのブレンド(加算ブレンド含む)を解説します。また、スムーズダンピングやスプリング物理、正弦波振動などのプロシージャルアニメーションパターンも提供。パフォーマンス最適化のヒント(クリップ共有、オフスクリーン時の更新停止)も含まれ、`THREE.Timer`(r183推奨)の使用法も説明しています。任意のThree.jsプロジェクトで動作し、特にアニメーションの実装・デバッグ時に役立ちます。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Desesbraker/agentes-vip/tree/HEAD/full%20skill/plugins/antigravity-awesome-skills-claude/skills/threejs-animation

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

Three.js アニメーション

クイックスタート

import * as THREE from "three";

// Timerを使ったシンプルなプロシージャルアニメーション (r183推奨)
const timer = new THREE.Timer();

renderer.setAnimationLoop(() => {
  timer.update();
  const delta = timer.getDelta();
  const elapsed = timer.getElapsed();

  mesh.rotation.y += delta;
  mesh.position.y = Math.sin(elapsed) * 0.5;

  renderer.render(scene, camera);
});

注: r183以降、THREE.Timer は THREE.Clock よりも推奨されます。Timerはページが非表示のときに一時停止し、よりクリーンなAPIを提供します。THREE.Clock も引き続き動作しますが、レガシーと見なされます。

アニメーションシステムの概要

Three.jsアニメーションシステムには、3つの主要コンポーネントがあります:

  1. AnimationClip - キーフレームデータのコンテナ
  2. AnimationMixer - ルートオブジェクト上でアニメーションを再生
  3. AnimationAction - クリップの再生を制御

AnimationClip

キーフレームアニメーションデータを保存します。

// アニメーションクリップの作成
const times = [0, 1, 2]; // キーフレーム時間 (秒)
const values = [0, 1, 0]; // 各キーフレームの値

const track = new THREE.NumberKeyframeTrack(
  ".position[y]", // プロパティパス
  times,
  values,
);

const clip = new THREE.AnimationClip("bounce", 2, [track]);

KeyframeTrackの種類

// 数値トラック (単一値)
new THREE.NumberKeyframeTrack(".opacity", times, [1, 0]);
new THREE.NumberKeyframeTrack(".material.opacity", times, [1, 0]);

// ベクトルトラック (位置、スケール)
new THREE.VectorKeyframeTrack(".position", times, [
  0,
  0,
  0, // t=0
  1,
  2,
  0, // t=1
  0,
  0,
  0, // t=2
]);

// クォータニオントラック (回転)
const q1 = new THREE.Quaternion().setFromEuler(new THREE.Euler(0, 0, 0));
const q2 = new THREE.Quaternion().setFromEuler(new THREE.Euler(0, Math.PI, 0));
new THREE.QuaternionKeyframeTrack(
  ".quaternion",
  [0, 1],
  [q1.x, q1.y, q1.z, q1.w, q2.x, q2.y, q2.z, q2.w],
);

// カラートラック
new THREE.ColorKeyframeTrack(".material.color", times, [
  1,
  0,
  0, // 赤
  0,
  1,
  0, // 緑
  0,
  0,
  1, // 青
]);

// 真偽値トラック
new THREE.BooleanKeyframeTrack(".visible", [0, 0.5, 1], [true, false, true]);

// 文字列トラック (モーフターゲット用)
new THREE.StringKeyframeTrack(
  ".morphTargetInfluences[smile]",
  [0, 1],
  ["0", "1"],
);

補間モード

const track = new THREE.VectorKeyframeTrack(".position", times, values);

// 補間
track.setInterpolation(THREE.InterpolateLinear); // デフォルト
track.setInterpolation(THREE.InterpolateSmooth); // 3次スプライン
track.setInterpolation(THREE.InterpolateDiscrete); // ステップ関数

BezierInterpolant (r183)

Three.js r183では、キーフレームトラックにベジェ曲線補間のための THREE.BezierInterpolant が追加され、接線制御によるより滑らかなアニメーションカーブが可能になりました。

AnimationMixer

オブジェクトとその子孫に対してアニメーションを再生します。

const mixer = new THREE.AnimationMixer(model);

// クリップからアクションを作成
const action = mixer.clipAction(clip);
action.play();

// アニメーションループで更新
function animate() {
  const delta = clock.getDelta();
  mixer.update(delta); // 必須!

  requestAnimationFrame(animate);
  renderer.render(scene, camera);
}

ミキサーイベント

mixer.addEventListener("finished", (e) => {
  console.log("アニメーション終了:", e.action.getClip().name);
});

mixer.addEventListener("loop", (e) => {
  console.log("アニメーションループ:", e.action.getClip().name);
});

AnimationAction

アニメーションクリップの再生を制御します。

const action = mixer.clipAction(clip);

// 再生制御
action.play();
action.stop();
action.reset();
action.halt(fadeOutDuration);

// 再生状態
action.isRunning();
action.isScheduled();

// 時間制御
action.time = 0.5; // 現在の時間
action.timeScale = 1; // 再生速度 (負の値=逆再生)
action.paused = false;

// 重み (ブレンド用)
action.weight = 1; // 0-1、最終ポーズへの寄与度
action.setEffectiveWeight(1);

// ループモード
action.loop = THREE.LoopRepeat; // デフォルト: 無限ループ
action.loop = THREE.LoopOnce; // 一度だけ再生して停止
action.loop = THREE.LoopPingPong; // 順方向/逆方向を交互に繰り返す
action.repetitions = 3; // ループ回数 (デフォルトは無限)

// クランプ
action.clampWhenFinished = true; // 終了時に最後のフレームを保持

// ブレンド
action.blendMode = THREE.NormalAnimationBlendMode;
action.blendMode = THREE.AdditiveAnimationBlendMode;

フェードイン/フェードアウト

// フェードイン
action.reset().fadeIn(0.5).play();

// フェードアウト
action.fadeOut(0.5);

// アニメーション間のクロスフェード
const action1 = mixer.clipAction(clip1);
const action2 = mixer.clipAction(clip2);

action1.play();

// 後で、action2にクロスフェード
action1.crossFadeTo(action2, 0.5, true);
action2.play();

GLTFアニメーションの読み込み

スケルタルアニメーションの最も一般的なソースです。

import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";

const loader = new GLTFLoader();
loader.load("model.glb", (gltf) => {
  const model = gltf.scene;
  scene.add(model);

  // ミキサーを作成
  const mixer = new THREE.AnimationMixer(model);

  // すべてのクリップを取得
  const clips = gltf.animations;
  console.log(
    "利用可能なアニメーション:",
    clips.map((c) => c.name),
  );

  // 最初のアニメーションを再生
  if (clips.length > 0) {
    const action = mixer.clipAction(clips[0]);
    action.play();
  }

  // 名前で特定のアニメーションを再生
  const walkClip = THREE.AnimationClip.findByName(clips, "Walk");
  if (walkClip) {
    mixer.clipAction(walkClip).play();
  }

  // 更新ループのためにミキサーを保存
  window.mixer = mixer;
});

// アニメーションループ
function animate() {
  const delta = clock.getDelta();
  if (window.mixer) window.mixer.update(delta);

  requestAnimationFrame(animate);
  renderer.render(scene, camera);
}

スケルタルアニメーション

スケルトンとボーン

// スキンメッシュからスケルトンにアクセス
const skinnedMesh = model.getObjectByProperty("type", "SkinnedMesh");
const skeleton = skinnedMesh.skeleton;

// ボーンにアクセス
skeleton.bones.forEach((bone) => {
  console.log(bone.name, bone.position, bone.rotation);
});

// 名前で特定のボーンを見つける
const headBone = skeleton.bones.find((b) => b.name === "Head");
if (headBone) headBone.rotation.y = Math.PI / 4; // 頭を回す

// スケルトンヘルパー
const helper = new THREE.SkeletonHelper(model);
scene.add(helper);

プログラムによるボーンアニメーション

function animate() {
  const time = clock.getElapsedTime();

  // ボーンをアニメーション
  const headBone = skeleton.bones.find((b) => b.name === "Head");
  if (headBone) {
    headBone.rotation.y = Math.sin(time) * 0.3;
  }

  // クリップも再生している場合はミキサーも更新
  mixer.update(clock.getDelta());
}

ボーンへのアタッチメント

// オブジェクトをボーンにアタッチ
const weapon = new THREE.Mesh(weaponGeometry, weaponMaterial);
const handBone = skeleton.bones.find((b) => b.name === "RightHand");
if (handBone) handBone.add(weapon);

// アタッチメントのオフセット
weapon.position.set(0, 0, 0.5);
weapon.rotation.set(0, Math.PI / 2, 0);

モーフターゲット

異なるメッシュ形状間をブレンドします。

// モーフターゲットはジオメトリに格納される
const geometry = mesh.geometry;
console.log("モーフ属性:", Object.keys(geometry.morphAttributes));

// モーフターゲットの影響度にアクセス
mesh.morphTargetInfluences; // 重みの配列
mesh.morphTargetDictionary; // 名前 -> インデックスのマッピング

// インデックスでモーフターゲットを設定
mesh.morphTargetInfluences[0] = 0.5;

// 名前で設定
const smileIndex = mesh.morphTargetDictionary["smile"];
mesh.morphTargetInfluences[smileIndex] = 1;

モーフターゲットのアニメーション

// プロシージャル
function animate() {
  const t = clock.getElapsedTime();
  mesh.morphTargetInfluences[0] = (Math.sin(t) + 1) / 2;
}

// キーフレームアニメーションで
const track = new THREE.NumberKeyframeTrack(
  ".morphTargetInfluences[smile]",
  [0, 0.5, 1],
  [0, 1, 0],
);
const clip = new THREE.AnimationClip("smile", 1, [track]);
mixer.clipAction(clip).play();

アニメーションブレンド

複数のアニメーションを混ぜ合わせます。

// アクションのセットアップ
const idleAction = mixer.clipAction(idleClip);
const walkAction = mixer.clipAction(walkClip);
const runAction = mixer.clipAction(runClip);

// 異なる重みですべてを再生
idleAction.play();
walkAction.play();
runAction.play();

// 初期重みを設定
idleAction.setEffectiveWeight(1);
walkAction.setEffectiveWeight(0);
runAction.setEffectiveWeight(0);

// 速度に基づいてブレンド
function updateAnimations(speed) {
  if (speed < 0.1) {
    idleAction.setEffectiveWeight(1);
    walkAction.setEffectiveWeight(0);
    runAction.setEffectiveWeight(0);
  } else if (speed < 5) {
    const t = speed / 5;
    idleAction.setEffectiveWeight(1 - t);
    walkAction.setEffectiveWeight(t);
    runAction.setEffectiveWeight(0);
  } else {
    const t = Math.min((speed - 5) / 5, 1);
    idleAction.setEffectiveWeight(0);
    walkAction.setEffectiveWeight(1 - t);
    runAction.setEffectiveWeight(t);
  }
}

加算ブレンド

// ベースポーズ
const baseAction = mixer.clipAction(baseClip);
baseAction.play();

// 加算レイヤー (例: 呼吸)
const additiveAction = mixer.clipAction(additiveClip);
additiveAction.blendMode = THREE.AdditiveAnimationBlendMode;
additiveAction.play();

// クリップを加算に変換
THREE.AnimationUtils.makeClipAdditive(additiveClip);

アニメーションユーティリティ

import * as THREE from "three";

// 名前でクリップを検索
const clip = THREE.AnimationClip.findByName(clips, "Walk");

// サブクリップを作成
const subclip = THREE.AnimationUtils.subclip(clip, "subclip", 0, 30, 30);

// 加算に変換
THREE.AnimationUtils.makeClipAdditive(clip);
THREE.AnimationUtils.makeClipAdditive(clip, 0, referenceClip);

// クリップをクローン
const clone = clip.clone();

// クリップの長さを取得
clip.duration;

// クリップを最適化 (冗長なキーフレームを削除)
clip.optimize();

// クリップを最初のフレームにリセット
clip.resetDuration();

プロシージャルアニメーションパターン

スムーズダンピング

// スムーズフォロー/線形補間
const target = new THREE.Vector3();
const current = new THREE.Vector3();
const velocity = new THREE.Vector3();

function smoothDamp(current, target, velocity, smoothTime, deltaTime) {
  const omega = 2 / smoothTime;
  const x = omega * deltaTime;
  const exp = 1 / (1 + x + 0.48 * x * x + 0.235 * x * x * x);
  const change = current.clone().sub(target);
  const temp = velocity
    .clone()
    .add(change.clone().multiplyScalar(omega))
    .multiplyScalar(deltaTime);
  velocity.sub(temp.clone().multiplyScalar(omega)).multiplyScalar(exp);
  return target.clone().add(change.add(temp).multiplyScalar(exp));
}

function animate() {
  current.copy(smoothDamp(current, target, velocity, 0.3, delta));
  mesh.position.copy(current);
}

スプリング物理

class Spring {
  constructor(stiffness = 100, damping = 10) {
    this.stiffness = stiffness;
    this.damping = damping;
    this.position = 0;
    this.velocity = 0;
    this.target = 0;
  }

  update(dt) {
    const force = -this.stiffness * (this.position - this.target);
    const dampingForce = -this.damping * this.velocity;
    this.velocity += (force + dampingForce) * dt;
    this.position += this.velocity * dt;
    return this.position;
  }
}

const spring = new Spring(100, 10);
spring.target = 1;

function animate() {
  mesh.position.y = spring.update(delta);
}

振動

function animate() {
  const t = clock.getElapsedTime();

  // 正弦波
  mesh.position.y = Math.sin(t * 2) * 0.5;

  // バウンド
  mesh.position.y = Math.abs(Math.sin(t * 3)) * 2;

  // 円運動
  mesh.position.x = Math.cos(t) * 2;
  mesh.position.z = Math.sin(t) * 2;

  // 8の字
  mesh.position.x = Math.sin(t) * 2;
  mesh.position.z = Math.sin(t * 2) * 1;
}

パフォーマンスのヒント

  1. クリップを共有する: 同じAnimationClipを複数のミキサーで使用できます
  2. クリップを最適化する: clip.optimize() を呼び出して冗長なキーフレームを削除
  3. オフスクリーン時は無効にする: 非表示オブジェクトのミキサー更新を停止
  4. アニメーションにLODを使用する: 遠くのキャラクターにはよりシンプルなリグを使用
  5. アクティブなミキサーを制限する: 各 mixer.update() にはコストがかかります
// 非表示時にアニメーションを一時停止
mesh.onBeforeRender = () => {
  action.paused = false;
};

mesh.onAfterRender = () => {
  // 次のフレームで表示されるか確認
  if (!isInFrustum(mesh)) {
    action.paused = true;
  }
};

// クリップをキャッシュ
const clipCache = new Map();
function getClip(name) {
  if (!clipCache.has(name)) {
    clipCache.set(name, loadClip(name));
  }
  return clipCache.get(name);
}

関連項目

  • threejs-loaders - アニメーション付きGLTFモデルの読み込み
  • threejs-fundamentals - Clockとアニメーションループ
  • threejs-shaders - シェーダー内の頂点アニメーション

Individual skills in this repo

This repo contains 16 individual skills — each has its own dedicated page.

Desesbraker/agentes-vip

Skill for discovering and researching autonomous AI agents, tools, and ecosystems using the AgentFolio directory.

Desesbraker/agentes-vip

Advanced JavaScript animation library skill for creating complex, high-performance web animations.

Desesbraker/agentes-vip

Audit and fix animation performance issues including layout thrashing, compositor properties, scroll-linked motion, and blur effects. Use when animations stutter, transitions jank, or reviewing CSS/JS animation performance.

Desesbraker/agentes-vip

Internationalization and localization patterns. Detecting hardcoded strings, managing translations, locale files, RTL support.

Desesbraker/agentes-vip

AI-powered animation tool for creating motion in logos, UI, icons, and social media assets.

Desesbraker/agentes-vip

CRITICAL: Use for Makepad animation system. Triggers on: makepad animation, makepad animator, makepad hover, makepad state, makepad transition, "from: { all: Forward", makepad pressed, makepad 动画, makepad 状态, makepad 过渡, makepad 悬停效果

Desesbraker/agentes-vip

Best practices for Remotion - Video creation in React

Desesbraker/agentes-vip

Generate walkthrough videos from Stitch projects using Remotion with smooth transitions, zooming, and text overlays

Desesbraker/agentes-vip

Seek and analyze video content using Memories.ai Large Visual Memory Model for persistent video intelligence

Desesbraker/agentes-vip

Automate TikTok tasks via Rube MCP (Composio): upload/publish videos, post photos, manage content, and view user profiles/stats. Always search tools first for current schemas.

Desesbraker/agentes-vip

Video and audio perception, indexing, and editing. Ingest files/URLs/live streams, build visual/spoken indexes, search with timestamps, edit timelines, add overlays/subtitles, generate media, and create real-time alerts.

Desesbraker/agentes-vip

Upload, stream, search, edit, transcribe, and generate AI video and audio using the VideoDB SDK.

Desesbraker/agentes-vip

Automate YouTube tasks via Rube MCP (Composio): upload videos, manage playlists, search content, get analytics, and handle comments. Always search tools first for current schemas.

Desesbraker/agentes-vip

Extract transcripts from YouTube videos and generate comprehensive, detailed summaries using intelligent analysis frameworks

Desesbraker/agentes-vip

Generates high-converting Next.js/React landing pages with Tailwind CSS. Uses PAS, AIDA, and BAB frameworks for optimized copy/components (Heroes, Features, Pricing). Focuses on Core Web Vitals/SEO.

Desesbraker/agentes-vip

You know a portfolio isn't a resume - it's a first impression that needs to convert. You balance creativity with usability. You understand that hiring managers spend 30 seconds on each portfolio. You make those 30 seconds count. You help people stand out without being gimmicky.

関連スキル