更换模型背景

main
wangqiujuan0808 2023-12-14 11:55:51 +08:00
parent a78535f6a7
commit 2a4b42ba0b
5 changed files with 35 additions and 10 deletions

View File

@ -5,7 +5,7 @@
"author": "若依", "author": "若依",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite --host=0.0.0.0",
"build:prod": "vite build", "build:prod": "vite build",
"build:stage": "vite build --mode staging", "build:stage": "vite build --mode staging",
"preview": "vite preview" "preview": "vite preview"

View File

@ -6,13 +6,21 @@ const bimStore = defineStore(
activateTree: {}, activateTree: {},
activateDevice: {}, activateDevice: {},
activateApplication: {}, activateApplication: {},
deviceNum: '' deviceNum: '',
activateMenu: {
name: '建筑信息',
background: '#202a60'
}
}), }),
actions: { actions: {
// 菜单 // 菜单
setActivateIndex(index) { setActivateIndex(index) {
this.activateIndex = index; this.activateIndex = index;
}, },
setActivateMenu(item) {
this.activateMenu = item;
},
// 建筑树选中 // 建筑树选中
setActivateTree(item) { setActivateTree(item) {
this.activateTree = item; this.activateTree = item;

View File

@ -1,21 +1,25 @@
<template> <template>
<div class="menuDiv"> <div class="menuDiv">
<div v-for="(item, index) of menuList" :key="index" @click="changeMenu(index)" <div v-for="(item, index) of menuList" :key="index" @click="changeMenu(index, item)"
:class="{ 'activateTab': index == activateIndex }">{{ item.name }}</div> :class="{ 'activateTab': index == activateIndex }">{{ item.name }}</div>
</div> </div>
</template> </template>
<script setup> <script setup>
import bimStore from '@/store/modules/bim'; import bimStore from '@/store/modules/bim';
import { onMounted } from 'vue';
const menuList = [ const menuList = [
{ {
name: '建筑信息' name: '建筑信息',
background: '#000000'
}, },
{ {
name: '资产信息' name: '资产信息',
background: '#2b2f48'
}, },
{ {
name: 'BIM应用' name: 'BIM应用',
background: '#212b5f'
} }
] ]
@ -23,11 +27,16 @@ const data = reactive({
activateIndex: 0 activateIndex: 0
}); });
onMounted(() => {
changeMenu(0, menuList[0]);
})
const { activateIndex } = toRefs(data); const { activateIndex } = toRefs(data);
const emit = defineEmits(['changeMenu']) const emit = defineEmits(['changeMenu'])
const changeMenu = (index) => { const changeMenu = (index, item) => {
activateIndex.value = index; activateIndex.value = index;
bimStore().setActivateIndex(index); bimStore().setActivateIndex(index);
bimStore().setActivateMenu(item);
emit('changeMenu', index) emit('changeMenu', index)
} }
</script> </script>

View File

@ -16,7 +16,7 @@
</div> </div>
</template> </template>
<script setup> <script setup>
import { onMounted, ref } from 'vue'; import { onMounted, ref,watch } from 'vue';
import * as THREE from 'three'; import * as THREE from 'three';
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js"; import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
import { DRACOLoader} from "three/examples/jsm/loaders/DRACOLoader.js"; import { DRACOLoader} from "three/examples/jsm/loaders/DRACOLoader.js";
@ -80,9 +80,17 @@ Bus.on('clickApplication', e => {
console.log('clickApplication'); console.log('clickApplication');
}) })
watch(() => bimStore().activateMenu, value => {
console.log(1,scene);
//
scene.background = new THREE.Color(value.background);
toHomeView();
},{ deep: true });
const init = () => { const init = () => {
// //
scene = new THREE.Scene(); scene = new THREE.Scene();
scene.background = new THREE.Color(bimStore().activateMenu.background);
// //
camera = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 0.1, 1000); camera = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 0.1, 1000);
// camera.position.z = 5; // camera.position.z = 5;

View File

@ -1,7 +1,7 @@
<template> <template>
<div class="app-container"> <div class="app-container">
<!-- 场景模型 --> <!-- 场景模型 -->
<ThreeView background="#202a60" light="0xfffafa" :sceneUrl="sceneUrl" v-if="sceneUrl !== ''"></ThreeView> <ThreeView light="0xfffafa" :sceneUrl="sceneUrl" v-if="sceneUrl !== ''"></ThreeView>
<!-- <ThreeModel /> --> <!-- <ThreeModel /> -->
<!-- 底部菜单 --> <!-- 底部菜单 -->
<MenuTab @changeMenu="changeMenu"></MenuTab> <MenuTab @changeMenu="changeMenu"></MenuTab>
@ -55,7 +55,7 @@ import DeviceDetial from './components/DeviceDetial.vue';
import bimStore from '@/store/modules/bim'; import bimStore from '@/store/modules/bim';
import { computed } from 'vue'; import { computed } from 'vue';
const data = reactive({ const data = reactive({
sceneUrl: '', sceneUrl: '/jz/glb/scene.gltf',
equimentInfo: {}, equimentInfo: {},
}); });