Three Vue3Three Vue3
指南
  • English
  • 简体中文
GitHub
指南
  • English
  • 简体中文
GitHub
    • 快速开始
    • 场景
    • 天空盒
    • 模型加载器

      • 组件加载器
      • 函数加载器
    • 弹出窗口
    • 动态元素
    • 动画
      • 默认用法
      • 方法
    • 网格模型

      • 波动圆
    • 效果

      • 泛光

type

类

默认用法

点击我查看代码
<template>
  <tv-scene class="scene" bg-color="#FAEBD7" @created="created"></tv-scene>
</template>

<script lang="ts" setup>
import { GLTFLoader, Animation } from 'three-vue3'

const created = async (scene, { camera }) => {
  scene.position.set(0, -0.5, 0)
  camera.position.set(0, 1.5, 3)

  // 加载模型到场景中。
  const model = await GLTFLoader('/models/perseverance.glb')
  scene.add(model)

  // 播放动画。
  const animation = new Animation(model)
  animation.playAll()
}
</script>

<style>
.scene {
  margin-top: 10px;
  width: 100%;
  height: 300px;
}
</style>

方法

名称参数描述
constructor(mesh: THREE.Mesh) => voidmesh 传THREE.Mesh 对象。
set(index: number) => thisindex 当前播放的动画索引。
setByName(name: string) => thisname 当前动画的名称。
setLoop(loop: typeof THREE.LoopOnce | typeof THREE.LoopRepeat | typeof THREE.LoopPingPong) => thisloop 当前动画播放循环方式。
setTimeScale(timeScale: number) => thistimeScale 当前动画播放速度。
setClampWhenFinished(clampWhenFinished: boolean) => thisclampWhenFinished 当前动画是否在播放完成时停止。
play() => void播放动画。默认播放mesh中第一个动画。如果要播放特定的动画,需要先调用set或setByName方法。
playAll() => void播放模型中的所有动画。
stop() => void停止动画,只能停止使用play方法播放的动画。
stopAll() => void停止所有动画。只能停止使用playAll方法播放的动画。
pause() => void暂停动画,只能暂停使用play方法播放的动画。
pauseAll() => void暂停所有动画。只能暂停使用playAll方法播放的动画。
在 GitHub 上编辑此页
Last Updated:
Contributors: Shing Rui
Prev
动态元素