For AI agents: the complete documentation index is available at /vue-vrm/zh/llms.txt, the full documentation bundle is available at /vue-vrm/zh/llms-full.txt, and this page is available as Markdown at /vue-vrm/zh/api/instance.md.
  • 简体中文
  • 实例 API

    通过模板引用访问实例。类型检查请使用 VrmCanvasExposed 类型。

    <script setup lang="ts">
      import { ref } from 'vue';
      import { VrmCanvas, type VrmCanvasExposed } from 'vue-vrm';
    
      const canvas = ref<VrmCanvasExposed>();
    
      function logBones(): void {
        const humanoid = canvas.value?.getVrm()?.humanoid;
        console.log(humanoid?.getNormalizedBoneNode('head'));
      }
    </script>
    
    <template>
      <VrmCanvas ref="canvas" :model-data="modelData" />
      <button type="button" @click="logBones">Log head bone</button>
    </template>
    Info

    渲染器在挂载后创建,模型在加载完成后创建。在此之前,获取类方法会返回 undefined。

    播放

    方法返回值说明
    playAnimation(data, weights?)Promise<void>加载并播放动画,替换当前动画。
    pauseAnimation()void在当前帧暂停。
    resumeAnimation()void继续播放已暂停的动画。
    stopAnimation()void停止并回到开头。

    表情

    方法返回值说明
    getExpressionNames()VrmExpressionNames模型定义的预设和自定义表情名称。未加载模型时为空。
    setExpression(name, weight)void不经过 Vue 响应式系统设置权重,在下一帧应用。适用于口型同步。
    resetExpressions()void清除通过 setExpression() 设置的值,这些表情恢复为 0。

    相机和输出

    方法返回值说明
    resetCamera()void把相机恢复到能完整显示模型的位置。
    captureScreenshot(format?)string渲染当前帧并返回 data URL。format 默认为 'image/png'。渲染器就绪前调用会抛出异常。

    three.js 对象

    方法返回值说明
    getVrm()VRM | undefined已加载的 VRM。
    getScene()Scene | undefined场景。
    getCamera()PerspectiveCamera | undefined相机。
    getRenderer()WebGLRenderer | undefined渲染器。
    getMixer()AnimationMixer | undefined加载动画期间的动画混合器。
    getCanvas()HTMLCanvasElement | undefined<canvas> 元素。
    Warning

    这些方法返回的对象由组件管理。更换模型或组件卸载时它们会被释放,因此请不要长期持有其引用。

    已弃用

    方法替代方法
    resetCameraPose()resetCamera()