wangqiujuan0808 2023-12-11 08:31:27 +08:00
parent 579be74275
commit ce7e6cc9b8
4 changed files with 153 additions and 14 deletions

View File

@ -185,3 +185,6 @@ aside {
margin-bottom: 10px; margin-bottom: 10px;
} }
} }
.el-tree--highlight-current .el-tree-node.is-current>.el-tree-node__content {
background-color: #033b73 !important;
}

View File

@ -206,7 +206,7 @@ const handleNodeClick = (value) => {
width: 224px; width: 224px;
margin: 0 10px; margin: 0 10px;
background: transparent; background: transparent;
color: #3cbfdf; color: #fff;
} }
.el-select { .el-select {
@ -218,7 +218,7 @@ const handleNodeClick = (value) => {
} }
:deep(.el-input__inner) { :deep(.el-input__inner) {
color: #3cbfdf; color: #fff;
} }
} }
</style> </style>

View File

@ -124,7 +124,7 @@ const handleNodeClick = (value) => {
width: 224px; width: 224px;
margin: 0 10px; margin: 0 10px;
background: transparent; background: transparent;
color: #3cbfdf; color: #fff;
} }
.el-select { .el-select {

View File

@ -1,7 +1,14 @@
<template> <template>
<div> <div>
<div id="gltf"></div> <div id="gltf"></div>
<div id="dom"></div>
<div class="btnGroup"> <div class="btnGroup">
<div class="button" @click="toHomeView">
主视角
</div>
<div class="button" @click="setLabel">
{{ isAddLabel ? '添加标签' : '移除标签' }}
</div>
<div class="button" @click="walk"> <div class="button" @click="walk">
漫游 漫游
</div> </div>
@ -15,7 +22,13 @@ import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
import { RoomEnvironment } from "three/examples/jsm/environments/RoomEnvironment.js"; import { RoomEnvironment } from "three/examples/jsm/environments/RoomEnvironment.js";
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js"; import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
import TWEEN from "@tweenjs/tween.js"; import TWEEN from "@tweenjs/tween.js";
import {
CSS2DObject,
CSS2DRenderer,
} from "three/examples/jsm/renderers/CSS2DRenderer";
import Bus from '@/utils/bus.js'
import bimStore from '@/store/modules/bim';
import gsap from "gsap";
onMounted(() => { onMounted(() => {
init(); init();
loadSence(); loadSence();
@ -23,14 +36,45 @@ onMounted(() => {
document.addEventListener("click", onMouseDown); document.addEventListener("click", onMouseDown);
// document.addEventListener("mousemove", onMouseMove); // document.addEventListener("mousemove", onMouseMove);
}); });
let scene, renderer, camera, controls; let scene, renderer, camera, controls, isAddLabel = true;
let mouse = new THREE.Vector2();
let labelRenderer = new CSS2DRenderer(); //CSS2DRenderer
//
Bus.on('clickBuild', (isParent) => {
// Todo
console.log('clickBuild', isParent);
if (!isParent) {//
var clickName = bimStore().activateTree.clickName;
var Floor = scene.getObjectByName(clickName);
//
// nearCamera(Floor);
centerSelectedGroup(Floor);
return;
}
})
//
Bus.on('clickDevice', (isParent) => {
if (!isParent) {//
var clickName = bimStore().activateDevice.clickName;
var Floor = scene.getObjectByName(clickName);
//
nearCamera(Floor);
return;
}
})
//
Bus.on('clickApplication', e => {
// Todo
console.log('clickApplication');
})
const init = () => { const init = () => {
// //
scene = new THREE.Scene(); scene = new THREE.Scene();
// //
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;
camera.position.set(-46.650, 67.456, 38.088); camera.position.set(-20.650, 5.456, 30.088);
// //
renderer = new THREE.WebGLRenderer({ antialias: true }); renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(window.devicePixelRatio); renderer.setPixelRatio(window.devicePixelRatio);
@ -93,7 +137,7 @@ const isSelent = (obj) => {
} }
} }
} }
let mouse = new THREE.Vector2();
let selectedObjects = ref([]); let selectedObjects = ref([]);
let selectBoxByClick, selectBoxByMouseon; let selectBoxByClick, selectBoxByMouseon;
var marginLeft = 0; var marginLeft = 0;
@ -150,10 +194,6 @@ const centerSelectedGroup = (obj) => {
tween.start(); tween.start();
// let distance = 100 // let distance = 100
// let angel = Math.PI / 5 // let angel = Math.PI / 5
@ -189,10 +229,66 @@ const roam = (obj) => {
tween.start(); tween.start();
} }
let roamdObjects = ref([]); let roamdObjects = ref([]);
const walk = () => { //
const toHomeView = () => {
controls.reset();
} }
//
const nearCamera = (floor) => {
controls.reset();
gsap.to(camera.position, {
x: floor.position.x,
y: floor.position.y,
z: floor.position.z,
duration: 2,
ease: "power1.inOut",
onComplete: () => {
},
});
}
//
const setLabel = () => {
if(isAddLabel) {
addLabel();
} else {
removeLabel();
}
isAddLabel = !isAddLabel;
}
//
const addLabel = () => {
let obj = scene.getObjectByName('set2');
console.log(123, obj);
let text = "设备二";
let pointLabel = createLableObj(text);
obj.add(pointLabel);
labelRenderer.setSize(window.innerWidth, window.innerHeight);
labelRenderer.domElement.style.position = "absolute";
labelRenderer.domElement.style.top = 0;
labelRenderer.domElement.style.pointerEvents = 'none';//
document.body.appendChild(labelRenderer.domElement);
// HTML
document.getElementById("dom").appendChild(renderer.domElement);
};
const createLableObj = (text) => {
let laberDiv = document.createElement("div"); //div
laberDiv.className = "laber_name";
laberDiv.innerHTML = `<div class="arrow_outer"></div><span>设备名称:${text}</span><span>状态:启用</span><span>压力50 Pa</span>`
let pointLabel = new CSS2DObject(laberDiv);
return pointLabel;
};
const removeLabel = () => {
document.body.removeChild(labelRenderer.domElement);
}
</script> </script>
<style scoped> <style lang='scss'>
#gltf {
height: 100%;
width: 100%;
}
.btnGroup { .btnGroup {
width: 180px; width: 180px;
position: absolute; position: absolute;
@ -215,4 +311,44 @@ const walk = () => {
margin-top: 10px; margin-top: 10px;
} }
} }
.laber_name {
width: 120px;
height: 90px;
padding: 5px 10px;
white-space: nowrap;
background-color: #ffffffb3;
border-top-right-radius: 12px;
border-bottom-right-radius: 12px;
font-size: 12px;
display: flex;
flex-direction: column;
&::before {
// content: "";
// display: inline-block;
// width: 0;
// height: 0;
// border: 12px solid transparent;
// border-right-color: #ffffffb3;
// position: absolute;
// left: -23px;
// top: 0;
}
.arrow_outer {
// position: absolute;
// left: -22px;
// top: 6px;
// margin: 0;
// width: 12px;
// height: 12px;
// background-color: #eb6852;
// border-radius: 100%;
// border: 1px solid #fff;
}
span {
line-height: 24px;
}
}
</style> </style>