案例展示
模型淡入效果
<template>
<div style="position: relative">
<div id="TO"></div>
<el-button type="primary" @click="animateIn()" size="small" class="btn btnIn">淡入</el-button>
<el-button type="primary" @click="animateOut()" size="small" class="btn btnOut">淡出</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: 3,
y: 3,
z: 3,
},
rotation: {
x: 0,
y: 0,
z: 0,
}
}
).then((model) => {
originModel = model.scene;
TO.scene.add(originModel);
animateIn();
//间隔 5s
setTimeout(() => {
animateOut();
}, 5000);
});
});
function animateIn() {
//淡入
TO.animate.modelFadeIn(originModel, 2000);
}
function animateOut() {
//淡出
TO.animate.modelFadeOut(originModel, 2000);
}
</script>
<style scoped>
#TO {
width: 100%;
height: 400px;
position: relative;
}
.btn {
position: absolute;
top: 10px;
right: 70px;
}
.btnOut {
position: absolute;
top: 10px;
right: 10px;
}
</style>
API 介绍
animate.modelFadeIn
方法签名 | 返回值 | 描述 |
---|---|---|
modelFadeIn(model: Object3D, time: number) | void | 模型淡入效果 |
参数说明:
参数名 | 类型 | 是否必选 | 描述 |
---|---|---|---|
model | Object3D | 是 | 模型 |
time | number | 是 | 完成时间(毫秒) |
animate.modelFadeOut
方法签名 | 返回值 | 描述 |
---|---|---|
modelFadeOut(model: Object3D, time: number) | void | 模型淡出效果 |
参数说明:
参数名 | 类型 | 是否必选 | 描述 |
---|---|---|---|
model | Object3D | 是 | 模型 |
time | number | 是 | 完成时间(毫秒) |