LoadThreeModelImage.vue
1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<template>
<div class="go-content-box">
<div>
<vue3dLoader
ref="vue3dLoaderRef"
:requestHeader="headers"
:webGLRendererOptions="webGLRendererOptions"
:height="200"
:width="400"
:filePath="threeModelPath"
@process="onProcess"
@load="onLoad"
:intersectRecursive="true"
/>
<div v-show="show" class="process">
<span> 拼命加载中... </span>
<n-progress type="line" :color="themeColor" :percentage="process" :indicator-placement="'inside'" processing />
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { ref, nextTick, computed } from 'vue'
import { vue3dLoader } from 'vue-3d-loader'
import { useDesignStore } from '@/store/modules/designStore/designStore'
import { getJwtToken } from '@/utils/external/auth'
const designStore = useDesignStore()
defineProps({
threeModelPath: {
type: String,
default: ''
}
})
const themeColor = computed(() => {
return designStore.getAppTheme
})
const vue3dLoaderRef = ref(null)
const headers = {
'x-authorization': `Bearer ${getJwtToken()}`
}
const webGLRendererOptions = {
alpha: true, // 透明
antialias: true, // 抗锯齿
// fix: 预览三维图像需加上preserveDrawingBuffer: true
preserveDrawingBuffer: true //缩略图生效需开启
}
//三维模型加载
const show = ref(false)
const onLoad = async () => {
//加载完成
await nextTick()
show.value = false
}
//三维模型进度条
const process = ref(0)
const onProcess = (event: Recordable) => {
process.value = Math.floor((event.loaded / event.total) * 100)
}
</script>
<style lang="scss" scoped>
.go-content-box {
height: 100%;
.process {
position: absolute;
top: 50%;
left: 50%;
width: 50%;
transform: translate(-50%, -50%);
}
}
</style>