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/guide/camera-and-lighting.md.
  • 简体中文
  • 相机与灯光

    自动取景

    加载模型后,相机距离会被调整到能完整显示模型的位置。用户移动相机之后,可以调用 resetCamera() 回到这个位置。

    相机 props

    Prop默认值作用
    camera-options{ fov: 30, near: 0.1, far: 100 }视野角(度)和裁剪面。省略的字段使用默认值。
    camera-look-at[0, 0.9, 0]相机朝向的点(米)。启用轨道控制时会被忽略。
    camera-distance根据模型计算到目标点的距离。优先于自动取景。
    camera-euler[0, 0, 0]绕目标点的旋转,以弧度表示的欧拉角(X、Y、Z)。
    camera-offset[0, 0, 0]移动相机所围绕的目标点(模型中心)。

    相机位于距目标点 camera-distance 的位置,并按 camera-euler 旋转。目标点是模型中心加上 camera-offset。例如,要从稍偏左的位置拍摄面部:

    <template>
      <VrmCanvas
        :model-data="modelData"
        :camera-offset="[0, 0.6, 0]"
        :camera-look-at="[0, 1.4, 0]"
        :camera-distance="1.2"
        :camera-euler="[0, -0.4, 0]"
      />
    </template>

    相机位置或目标点变化时会触发 camera:change,camera-options 变化时会触发 camera:options-change。

    轨道控制

    设置 camera-interaction 后,用户可以用鼠标或触摸移动相机。默认关闭。

    <script setup lang="ts">
      import { VrmCanvas, type CameraInteractionOptions } from 'vue-vrm';
    
      const interaction: CameraInteractionOptions = {
        enabled: true,
        roll: true,
        minDistance: 0.5,
        maxDistance: 20
      };
    </script>
    
    <template>
      <VrmCanvas :model-data="modelData" :camera-interaction="interaction" />
    </template>
    选项默认值作用
    enabled—启用控制。必填。
    rotatetrue拖动以绕目标点旋转。
    pantrue右键拖动或 Ctrl + 拖动以平移。
    zoomtrue使用鼠标滚轮或双指缩放。
    rollfalse画布获得焦点时,用 Q/E 键使相机翻滚。
    rotateSpeed1旋转速度。
    panSpeed1平移速度。
    zoomSpeed1缩放速度。
    dampingtrue松开指针后让运动平滑减速。
    dampingFactor0.08阻尼强度。
    minDistance0.1到目标点的最近距离。
    maxDistanceInfinity到目标点的最远距离。
    rollSpeed0.03每次按键翻滚的角度(弧度)。
    Tip

    启用 roll 后,画布可以获得焦点。按 Q/E 之前,请先点击画布,或用 Tab 键把焦点移到画布上。

    灯光

    场景中有一个环境光和一个平行光。

    Prop默认值作用
    ambient-light{ color: '#ffffff', intensity: 0.5 }均匀照亮所有表面的光。
    directional-light{ color: '#ffffff', intensity: 1, position: [1, 1, 1] }像阳光一样从一个方向照射的光。
    <template>
      <VrmCanvas
        :model-data="modelData"
        :ambient-light="{ color: '#ffe8d0', intensity: 0.6 }"
        :directional-light="{ color: '#ffffff', intensity: 1.2, position: [-1, 2, 1] }"
      />
    </template>

    更改会立即生效,并通过 light:ambient-change 和 light:directional-change 通知。