Commit 6ee8698affb89e3b437b15fcf4c1a443b5488a7a
1 parent
a12252bc
perf(external/Composes): 组合下新增三维模型展示,目前支持.dae/.fbx/.gltf/.glb/.obj/.ply/.stl/.json
Showing
7 changed files
with
129 additions
and
1 deletions
@@ -45,6 +45,7 @@ | @@ -45,6 +45,7 @@ | ||
45 | "three": "^0.145.0", | 45 | "three": "^0.145.0", |
46 | "video.js": "^7.20.3", | 46 | "video.js": "^7.20.3", |
47 | "vue": "^3.2.31", | 47 | "vue": "^3.2.31", |
48 | + "vue-3d-loader": "^2.1.7", | ||
48 | "vue-demi": "^0.13.1", | 49 | "vue-demi": "^0.13.1", |
49 | "vue-i18n": "^9.2.2", | 50 | "vue-i18n": "^9.2.2", |
50 | "vue-router": "4.0.12", | 51 | "vue-router": "4.0.12", |
No preview for this file type
1 | +import { PublicConfigClass } from '@/packages/public' | ||
2 | +import { CreateComponentType } from '@/packages/index.d' | ||
3 | +import { ThreeDimensional1Config } from './index' | ||
4 | +import cloneDeep from 'lodash/cloneDeep' | ||
5 | +import { chartInitConfig } from '@/settings/designSetting' | ||
6 | + | ||
7 | +export const option = { | ||
8 | + | ||
9 | +} | ||
10 | + | ||
11 | +export default class Config extends PublicConfigClass implements CreateComponentType { | ||
12 | + public key = ThreeDimensional1Config.key | ||
13 | + public attr = { ...chartInitConfig, zIndex: 1, w: 600, h: 500 } | ||
14 | + public chartConfig = cloneDeep(ThreeDimensional1Config) | ||
15 | + public option = cloneDeep(option) | ||
16 | +} |
1 | +<template> | ||
2 | + | ||
3 | +</template> | ||
4 | + | ||
5 | +<script setup lang="ts"> | ||
6 | +import { PropType } from 'vue' | ||
7 | +import { option } from './config' | ||
8 | +import { CollapseItem, SettingItemBox, SettingItem } from '@/components/Pages/ChartItemSetting' | ||
9 | + | ||
10 | +defineProps({ | ||
11 | + optionData: { | ||
12 | + type: Object as PropType<typeof option>, | ||
13 | + required: true | ||
14 | + } | ||
15 | +}) | ||
16 | +</script> |
1 | +import { ChartFrameEnum, ConfigType } from '@/packages/index.d' | ||
2 | +import { EPackagesCategoryEnum } from '@/packages/components/external/types' | ||
3 | +import { ChatCategoryEnum, ChatCategoryEnumName } from '../../index.d' | ||
4 | +import { useWidgetKey } from '@/packages/external/useWidgetKey' | ||
5 | + | ||
6 | +const { key, chartKey, conKey } = useWidgetKey('ThreeDimensional1') | ||
7 | +export const ThreeDimensional1Config: ConfigType = { | ||
8 | + key, | ||
9 | + chartKey, | ||
10 | + conKey, | ||
11 | + title: '三维模型1', | ||
12 | + category: ChatCategoryEnum.MORE, | ||
13 | + categoryName: ChatCategoryEnumName.MORE, | ||
14 | + package: EPackagesCategoryEnum.COMPOSES, | ||
15 | + chartFrame: ChartFrameEnum.NAIVE_UI, | ||
16 | + image: 'title1.png' | ||
17 | +} |
1 | +<template> | ||
2 | + <div class="go-content-box"> | ||
3 | + <vue3dLoader | ||
4 | + :backgroundColor="''" | ||
5 | + :backgroundAlpha="0" | ||
6 | + :height="h" | ||
7 | + :width="w" | ||
8 | + :filePath="filePath" | ||
9 | + @process="onProcess" | ||
10 | + /> | ||
11 | + <div v-show="show" class="process"> | ||
12 | + <n-space vertical> | ||
13 | + <n-spin :show="false"> | ||
14 | + <template #description> 三维模型加载中:进度{{ process + '%' }} </template> | ||
15 | + </n-spin> | ||
16 | + </n-space> | ||
17 | + </div> | ||
18 | + </div> | ||
19 | +</template> | ||
20 | +<script setup lang="ts"> | ||
21 | +import { PropType, toRefs, ref } from 'vue' | ||
22 | +import { CreateComponentType } from '@/packages/index.d' | ||
23 | +import { vue3dLoader } from 'vue-3d-loader' | ||
24 | + | ||
25 | +const props = defineProps({ | ||
26 | + chartConfig: { | ||
27 | + type: Object as PropType<CreateComponentType>, | ||
28 | + required: true | ||
29 | + } | ||
30 | +}) | ||
31 | + | ||
32 | +//三维静态文件 | ||
33 | +const filePath = ref() | ||
34 | + | ||
35 | +filePath.value = ['src/assets/external/models/fbx/Samba Dancing.fbx'] | ||
36 | + | ||
37 | +//三维加载事件相关 | ||
38 | +const show = ref(false) | ||
39 | + | ||
40 | +const currentModelIndex = ref() | ||
41 | + | ||
42 | +const process = ref(0) | ||
43 | + | ||
44 | +const onProcess = (event: any, index: number) => { | ||
45 | + // show.value = true | ||
46 | + try { | ||
47 | + process.value = Math.floor((event.loaded / event.total) * 100) | ||
48 | + if (process.value > 50) show.value = false | ||
49 | + if (index != 0) { | ||
50 | + currentModelIndex.value = index | ||
51 | + } | ||
52 | + } catch (e) { | ||
53 | + console.log(`三维模型加载失败原因:${e}`) | ||
54 | + } finally { | ||
55 | + show.value = false | ||
56 | + } | ||
57 | +} | ||
58 | +//三维加载事件 | ||
59 | + | ||
60 | +const { w, h } = toRefs(props.chartConfig.attr) | ||
61 | +</script> | ||
62 | + | ||
63 | +<style lang="scss" scoped> | ||
64 | +.go-content-box { | ||
65 | + width: v-bind('w+"px"'); | ||
66 | + height: v-bind('h+"px"'); | ||
67 | + display: flex; | ||
68 | + align-items: center; | ||
69 | + justify-content: center; | ||
70 | + .process { | ||
71 | + position: absolute; | ||
72 | + top: 50%; | ||
73 | + left: 50%; | ||
74 | + transform: translateX(-50%, -50%); | ||
75 | + } | ||
76 | +} | ||
77 | +</style> |
@@ -2,5 +2,6 @@ import { Title1Config } from './Title1/index' | @@ -2,5 +2,6 @@ import { Title1Config } from './Title1/index' | ||
2 | import { Title2Config } from './Title2/index' | 2 | import { Title2Config } from './Title2/index' |
3 | import { Title3Config } from './Title3/index' | 3 | import { Title3Config } from './Title3/index' |
4 | import { CameraConfig } from './Camera/index' | 4 | import { CameraConfig } from './Camera/index' |
5 | +import { ThreeDimensional1Config } from './ThreeDimensional1/index' | ||
5 | 6 | ||
6 | -export default [Title1Config, Title2Config, Title3Config, CameraConfig] | 7 | +export default [Title1Config, Title2Config, Title3Config, CameraConfig, ThreeDimensional1Config] |