For AI agents: the complete documentation index is available at /vue-vrm/ja/llms.txt, the full documentation bundle is available at /vue-vrm/ja/llms-full.txt, and this page is available as Markdown at /vue-vrm/ja/guide/animation.md.
  • 日本語
  • アニメーション

    vue-vrmは、VRM用のアニメーション形式であるVRMAファイルを再生できます。モデルと同じく、アニメーションもArrayBufferで渡します。

    VRMAファイルを再生する

    model-dataの後に(または同時に)animation-dataを指定します。

    <script setup lang="ts">
      import { ref } from 'vue';
      import { VrmCanvas } from 'vue-vrm';
    
      const modelData = ref<ArrayBuffer>();
      const animationData = ref<ArrayBuffer>();
    
      async function onAnimationFile(event: Event): Promise<void> {
        const file = (event.target as HTMLInputElement).files?.[0];
        if (file) animationData.value = await file.arrayBuffer();
      }
    </script>
    
    <template>
      <input type="file" accept=".vrma" @change="onAnimationFile" />
      <VrmCanvas :model-data="modelData" :animation-data="animationData" />
    </template>

    アニメーションは読み込みが終わるとすぐに再生されます。モデルを差し替えた場合は、再生中のアニメーションが新しいモデルにも適用されます。

    Info

    無料のVRMAファイルはBOOTHのVRoidプロジェクトで配布されています。再配布する場合は、ファイルごとのライセンスを確認してください。

    複数のクリップをブレンドする

    バッファーの配列を渡すと、複数のクリップを同時に再生します。各クリップの重みはanimation-weightsで指定します。

    <template>
      <VrmCanvas
        :model-data="modelData"
        :animation-data="[idle, wave]"
        :animation-weights="[0.7, 0.3]"
      />
    </template>
    • animation-weightsを省略した場合や、要素数がクリップの数と合わない場合は、すべてのクリップが同じ重みになります。
    • 重みの合計は1.0以下にしてください。超えるとanimation:errorが発生します。

    ループ

    アニメーションは既定でループします。1回だけ再生するにはloopをfalseにします。最後のフレームで止まり、再生が終わるとanimation:endが発生します。

    <template>
      <VrmCanvas
        :model-data="modelData"
        :animation-data="animationData"
        :loop="false"
        @animation:end="onEnd"
      />
    </template>

    再生の制御

    再生はインスタンスAPIで制御します。

    メソッド効果
    playAnimation(data, weights?)新しいアニメーションを読み込んで再生します。再生中のものは置き換えます。
    pauseAnimation()現在のフレームで一時停止します。
    resumeAnimation()一時停止したアニメーションを再開します。
    stopAnimation()アニメーションを止め、先頭に戻します。
    <script setup lang="ts">
      import { ref } from 'vue';
      import { VrmCanvas, type VrmCanvasExposed } from 'vue-vrm';
    
      const canvas = ref<VrmCanvasExposed>();
    </script>
    
    <template>
      <VrmCanvas ref="canvas" :model-data="modelData" :animation-data="animationData" />
      <button type="button" @click="canvas?.pauseAnimation()">Pause</button>
      <button type="button" @click="canvas?.resumeAnimation()">Resume</button>
      <button type="button" @click="canvas?.stopAnimation()">Stop</button>
    </template>

    それぞれのメソッドは、対応するイベント(animation:pause、animation:resume、animation:stop)を発生させます。