wangqiujuan0808 2023-12-14 11:57:13 +08:00
commit 41e2b90ea8
4 changed files with 205 additions and 47 deletions

BIN
dist.7z

Binary file not shown.

View File

@ -9,7 +9,7 @@
<div class="button" @click="setLabel">
{{ isAddLabel ? '添加标签' : '移除标签' }}
</div>
<div class="button" @click="roam({x: -1.6464157104492188, y: 2.9064807891845703, z: -11.564851760864258})">
<div class="button" @click="roam()">
漫游
</div>
</div>
@ -19,7 +19,7 @@
import { onMounted, ref,watch } from 'vue';
import * as THREE from 'three';
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";
import { RoomEnvironment } from "three/examples/jsm/environments/RoomEnvironment.js";
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
import TWEEN from "@tweenjs/tween.js";
@ -37,7 +37,8 @@ onMounted(() => {
document.addEventListener("click", onMouseDown);
// document.addEventListener("mousemove", onMouseMove);
});
let scene, renderer, camera, controls = true;
let scene, renderer, camera, controls, pointsArr = true;
let i = 1;
let mouse = new THREE.Vector2();
let labelRenderer = new CSS2DRenderer(); //CSS2DRenderer
const data = reactive({
@ -51,7 +52,7 @@ Bus.on('clickBuild', (isParent) => {
if (!isParent) {//
var clickName = bimStore().activateTree.clickName;
var Floor = scene.getObjectByName(clickName);
console.log(123, Floor.position);
// x: 42.6454163 y: 5.36651754 z: -95.03277
// x: 27.127655 y: 8.55 z: -6.132766
// x: 27.6954441 y: 10.7530384 z: -37.73485
@ -204,12 +205,10 @@ const onMouseDown = (event) => {
if (intersects.length > 0) {
const clickedObject = intersects[0].object;
// {x: -1.6464157104492188, y: 2.9064807891845703, z: -11.564851760864258}
// {x: -1.7519302368164062, y: 6.542750358581543, z: 11.509664535522461}
var selectedObject = isSelent(clickedObject);
console.log(selectedObject);
// boxLight(selectedObject);
nearCamera(selectedObject)
console.log(123, selectedObject);
boxLight(selectedObject);
// nearCamera(selectedObject)
}
}
@ -252,24 +251,68 @@ const centerSelectedGroup = (obj) => {
// tween1.start()
}
//
const i = 0;
const roam = (obj) => {
gsap.to(camera.position, {
x: obj.x,
y: obj.y,
z: obj.z,
duration: 2,
ease: "power1.inOut",
onComplete: () => {
// if (i < 1) {
// //
// roam( {x: -1.7519302368164062, y: 6.542750358581543, z: 11.509664535522461})
// }
// i++;
},
});
const roam = () => {
//
controls.enableDamping = false; //
controls.dampingFactor = 0.05; // 0 1 default = 0.25
controls.screenSpacePanning = false; // 使default = false
controls.minDistance = 100;
controls.maxDistance = 200;
controls.maxPolarAngle = Math.PI / 2; // atorbit
//
controls.enablePan = false; // pan
controls.enableKeys = true;
controls.keyPanSpeed = 30; // 7 WSAD
controls.enableZoom = false; //
controls.keyRotateSpeed = 90; // 30QE
controls.spaceingFactor = 0.4; //0.4
//
const path = new THREE.CatmullRomCurve3([
new THREE.Vector3(-50, 20, 90), //
new THREE.Vector3(-10, 40, 40), //
new THREE.Vector3(0, 0, 0), //
new THREE.Vector3(60, -60, 0), //
new THREE.Vector3(90, -40, 60), //
new THREE.Vector3(120, 30, 30), //
// //
// new THREE.Vector3(-10, 0, 10),
// //
// new THREE.Vector3(-5,10,-10),
// new THREE.Vector3(2, 5, -5),
// //
// new THREE.Vector3(10, 0, 10),
]);
pointsArr = path.getSpacedPoints(500);
// console.log(pointsArr);
i = 100;
// 线pointsArr[i]
camera.position.copy(pointsArr[i]);
// pointsArr[i + 1]
camera.lookAt(pointsArr[i + 1]);
renders();
}
let num = 0;
const renders = () => {
/* angle += 0.01;
// yXOZ
camera.position.x = R * Math.sin(angle);
camera.lookAt(0, 0, 0); */
if (num < pointsArr.length - 1) {
//
camera.position.copy(pointsArr[num]);
// 线pointsArr[num]pointsArr[num+1]线线
// 线线线
camera.lookAt(pointsArr[num + 1]);
num += 1; //
} else {
num = 0
}
requestAnimationFrame(renders);
};
let roamdObjects = ref([]);
//
const toHomeView = () => {
@ -279,20 +322,20 @@ const toHomeView = () => {
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: () => {
// },
// });
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.value) {
if (isAddLabel.value) {
addLabel();
} else {
removeLabel();
@ -334,6 +377,7 @@ const removeLabel = () => {
height: 100%;
width: 100%;
}
.btnGroup {
width: 180px;
position: absolute;
@ -356,6 +400,7 @@ const removeLabel = () => {
margin-top: 10px;
}
}
.laber_name {
width: 120px;
height: 90px;

View File

@ -0,0 +1,112 @@
<template>
<div class="box4"></div>
</template>
<script>
import * as THREE from 'three';
import Stats from 'three/examples/jsm/libs/stats.module';
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls';
export default{
data(){
return{
scene:null,
camera:null,
renderer:null,
stats:null,
pointLight:null,
pos:0,
curve:null,
sphereLightMesh:null,
}
},
methods:{
init(){
this.scene=new THREE.Scene();//
this.camera=new THREE.PerspectiveCamera(40,window.innerWidth/window.innerHeight,1,1000);//
this.camera.position.set(0,70,70);//
this.camera.lookAt(new THREE.Vector3(0,0,0));//
this.scene.add(new THREE.AxesHelper(20));//
this.pointLight=new THREE.PointLight(0xffffff);
this.pointLight.position.set(0,5,5);
this.pointLight.name="pointLight";//
this.scene.add(this.pointLight);
//
let sphereLight=new THREE.SphereGeometry(0.5,50,50);
let spLightMaterial=new THREE.MeshLambertMaterial({
color:0xffffff,
emissive:0xffffff
})
this.sphereLightMesh=new THREE.Mesh(sphereLight,spLightMaterial);
this.sphereLightMesh.position.copy(this.pointLight.position);
this.scene.add(this.sphereLightMesh);
//
let spheregeo=new THREE.SphereGeometry(5,100,100);
let sphereMaterial=new THREE.MeshLambertMaterial({
color:new THREE.Color().setHSL(Math.random(),0.5,0.5),
})
this.scene.add(new THREE.Mesh(spheregeo,sphereMaterial));
this.curve = new THREE.CatmullRomCurve3( [
//
new THREE.Vector3(-10, 0, 10),
//
new THREE.Vector3(-5,10,-10),
new THREE.Vector3(2, 5, -5),
//
new THREE.Vector3(10, 0, 10),
],
true,
);
console.log(this.curve.getPoint( 0.1 ));
// 线
let geometry = new THREE.Geometry();
// 线()
geometry.vertices = this.curve.getSpacedPoints(100);
let material = new THREE.LineBasicMaterial({ color:new THREE.Color().setHSL(Math.random(),0.5,0.5) });
let curveObject = new THREE.Line(geometry, material);
this.scene.add(curveObject);
this.renderer=new THREE.WebGLRenderer({antialias:true});//,齿
this.renderer.setSize(window.innerWidth,window.innerHeight);//
this.renderer.setClearColor(0x000000);//
this.renderer.setPixelRatio(window.devicePixelRatio);
this.stats=new Stats();
let control=new OrbitControls(this.camera,this.renderer.domElement);
//
document.getElementsByClassName("box4")[0].appendChild(this.stats.domElement);
document.getElementsByClassName("box4")[0].appendChild(this.renderer.domElement);
window.addEventListener("resize",this.onSize,false);//
},
run(){
requestAnimationFrame(this.run);
let pointLight=this.scene.getObjectByName("pointLight");
if(this.pos<1){
pointLight.position=this.curve.getPointAt(this.pos);//
this.sphereLightMesh.position.copy(pointLight.position);//
this.pos+=0.001;
}else{
this.pos=0;
}
this.renderer.render(this.scene,this.camera);
this.stats.update();
},
onSize(){
this.camera.aspect=window.innerWidth/window.innerHeight;
this.renderer.setSize(window.innerWidth,window.innerHeight);
this.camera.updateProjectionMatrix();
}
},
mounted() {
this.init();
this.run();
}
}
</script>
<style>
</style>

View File

@ -49,6 +49,7 @@ import ApplicationTree from './components/ApplicationTree.vue';
import EquipmentInfo from './components/EquipmentInfo.vue';
import RealData from './components/RealData.vue';
import ThreeView from './components/ThreeView2.vue';
// import ThreeView from './components/qqq.vue';
import DeviceInfoDialog from './components/DeviceInfoDialog.vue';
import RealInfoDialog from './components/RealInfoDialog.vue';
import DeviceDetial from './components/DeviceDetial.vue';