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/abb.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() { 
  let rotateModel = TO.scene.getObjectByProperty("name", "WS30-1") //找到模型对象
  TO.animate.rotateAngle(rotateModel, 'y', 0, 180, 2000);
}


</script>

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

API 介绍

animate.rotateAngle

方法签名返回值描述
rotateAngle(model: Object3D, axis: string, from: number, to: number, time: number)Tween<any>间补旋转动画(旋转角度)

参数说明:

参数名类型是否必选描述
modelObject3D模型
axisstring方向,可传入字符串 'x'/'y'/'z'
fromnumber起始角度
tonumber目标角度
timenumber动画时间(毫秒)
modestring运动模式 linear:匀速 bounceOut:弹开