Skip to content

案例展示

间补平移动画

<template>
   <div style="position: relative">
    <div id="TO"></div>
    <el-button type="primary" @click="startTween()" size="small" class="btn">开始移动</el-button>
  </div>
</template>

<script setup>
import { onMounted } from 'vue';
let TO = null, originModel = null;
onMounted(() => {
  TO = new ThingOrigin("fileModel", document.getElementById("TO"), {
    helper: {
      axes: {
        active: false,
      },
      grid: {
        active: false,
      },
    }
  })
 
 
  TO.model.initFileModel(
    {
      modelName: "fileModel-" + new Date().getTime(),
      base: {
        modelUrl: `${import.meta.env.BASE_URL}models/agv.gltf`
      },
      modelType: "gltf",
      position: {
        x: 0,
        y: 0,
        z: 0,
      },
      scale: {
        x: 2,
        y: 2,
        z: 2,
      },
      rotation: {
        x: 0,
        y: 0,
        z: 0,
      }
    }
  ).then((model) => {
    originModel = model.scene;
    TO.scene.add(originModel);
    startTween();
  });

});

//开始动画
function startTween() { 
  TO.animate.move(originModel, 'z', -100, 100, 2000);
}



</script>

<style scoped>
#TO {
  width: 100%;
  height: 400px;
  position: relative;
}
.btn {
  position: absolute;
  top: 10px;
  right: 10px;
}
</style>

API 介绍

animate.move

方法签名返回值描述
move(model: Object3D, axis: string, from: number, to: number, time: number)Tween<any>间补平移动画

参数说明:

参数名类型是否必选描述
modelObject3D模型
axisstring方向,可传入字符串 'x'/'y'/'z'
fromnumber起始位置
tonumber终止位置
timenumber完成时间(毫秒)