123
commit
dc63189d44
Binary file not shown.
After Width: | Height: | Size: 3.2 KiB |
Binary file not shown.
After Width: | Height: | Size: 8.8 KiB |
Binary file not shown.
After Width: | Height: | Size: 31 MiB |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Binary file not shown.
After Width: | Height: | Size: 69 KiB |
Binary file not shown.
After Width: | Height: | Size: 194 KiB |
|
@ -247,28 +247,31 @@ const enableGroup = [
|
|||
'tanghua_room',
|
||||
'touliao_room',
|
||||
]
|
||||
// const onMouseDown = (event) => {
|
||||
// // 计算鼠标点击位置的归一化设备坐标
|
||||
// mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
|
||||
// mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
|
||||
const onMouseMove = (event) => {
|
||||
var raycaster = new THREE.Raycaster()
|
||||
// 计算鼠标点击位置的归一化设备坐标
|
||||
mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
|
||||
mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
|
||||
|
||||
// var raycaster = new THREE.Raycaster()
|
||||
// cleanColor();
|
||||
// // 更新射线的起点和方向
|
||||
// raycaster.setFromCamera(mouse, camera);
|
||||
// // 计算射线和场景中所有可点击物体的相交情况
|
||||
// const intersects = raycaster.intersectObjects(scene.children, true);
|
||||
// // 如果找到了模型,将其材质修改为绿色
|
||||
// if (intersects.length > 0) {
|
||||
// const clickedObject = intersects[0].object;
|
||||
// // 储存被选中的模型和材质
|
||||
// selectedObject = clickedObject;
|
||||
// // // 修改材质为绿色
|
||||
// selectedObject.material = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
|
||||
// 更新射线的起点和方向
|
||||
raycaster.setFromCamera(mouse, camera);
|
||||
// 计算射线和场景中所有可点击物体的相交情况
|
||||
const intersects = raycaster.intersectObjects(scene.children, true);
|
||||
// 如果找到了模型,将其材质修改为绿色
|
||||
if (intersects.length > 0) {
|
||||
const clickedObject = intersects[0].object;
|
||||
// 储存被选中的模型和材质
|
||||
selectedObject = clickedObject;
|
||||
if (enableGroup.indexOf(selectedObject.name) != -1) {
|
||||
outlineObj([selectedObject])
|
||||
// nearCamera(intersects);
|
||||
// }
|
||||
|
||||
// }
|
||||
}
|
||||
if (enableGroup.indexOf(selectedObject.parent.name) != -1) {
|
||||
outlineObj([selectedObject.parent])
|
||||
// nearCamera(intersects);
|
||||
}
|
||||
}
|
||||
}
|
||||
const onMouseDown = (event) => {
|
||||
var raycaster = new THREE.Raycaster()
|
||||
// 计算鼠标点击位置的归一化设备坐标
|
||||
|
@ -283,13 +286,18 @@ const onMouseDown = (event) => {
|
|||
if (intersects.length > 0) {
|
||||
const clickedObject = intersects[0].object;
|
||||
// 储存被选中的模型和材质
|
||||
selectedObject = clickedObject.parent;
|
||||
selectedObject = clickedObject;
|
||||
if (enableGroup.indexOf(selectedObject.name) != -1) {
|
||||
outlineObj([selectedObject])
|
||||
alert("点击了",selectedObject.name)
|
||||
// nearCamera(intersects);
|
||||
}
|
||||
if (enableGroup.indexOf(selectedObject.parent.name) != -1) {
|
||||
outlineObj([selectedObject.parent])
|
||||
alert("点击了",selectedObject.parent.name)
|
||||
// nearCamera(intersects);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
let composer = null
|
||||
|
|
|
@ -0,0 +1,122 @@
|
|||
<template>
|
||||
<div>
|
||||
<div id="gltf"></div>
|
||||
</div>
|
||||
</template>
|
||||
<script setup>
|
||||
import { onMounted, ref } from 'vue';
|
||||
import * as THREE from 'three';
|
||||
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
|
||||
import { RoomEnvironment } from "three/examples/jsm/environments/RoomEnvironment.js";
|
||||
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
|
||||
|
||||
import { EffectComposer } from "three/examples/jsm/postprocessing/EffectComposer.js";
|
||||
import { RenderPass } from "three/examples/jsm/postprocessing/RenderPass.js";
|
||||
import { OutlinePass } from "three/examples/jsm/postprocessing/OutlinePass.js";
|
||||
import { ShaderPass } from "three/examples/jsm/postprocessing/ShaderPass.js";
|
||||
import { FXAAShader } from "three/examples/jsm/shaders/FXAAShader.js";
|
||||
|
||||
onMounted(() => {
|
||||
init();
|
||||
loadSence();
|
||||
renderScene();
|
||||
document.addEventListener("click", onMouseDown);
|
||||
// document.addEventListener("mousemove", onMouseMove);
|
||||
});
|
||||
let scene, renderer, camera;
|
||||
const init = () => {
|
||||
// 场景
|
||||
scene = new THREE.Scene();
|
||||
// 相机
|
||||
camera = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 0.1, 1000);
|
||||
// camera.position.z = 5;
|
||||
camera.position.set(-46.650, 67.456, 38.088);
|
||||
//渲染器
|
||||
renderer = new THREE.WebGLRenderer({ antialias: true });
|
||||
renderer.setPixelRatio(window.devicePixelRatio);
|
||||
renderer.setSize(window.innerWidth, window.innerHeight);
|
||||
renderer.outputEncoding = THREE.sRGBEncoding;
|
||||
document.getElementById('gltf').appendChild(renderer.domElement);
|
||||
|
||||
const controls = new OrbitControls(camera, renderer.domElement);
|
||||
const pmremGenerator = new THREE.PMREMGenerator(renderer);
|
||||
scene.environment = pmremGenerator.fromScene(new RoomEnvironment()).texture;
|
||||
}
|
||||
const loadSence = () => {
|
||||
const gltfLoader = new GLTFLoader();
|
||||
gltfLoader.load('/jzc/scene.gltf', (gltf) => {
|
||||
var model = gltf.scene;
|
||||
scene.add(model);
|
||||
});
|
||||
};
|
||||
const renderScene = () => {
|
||||
requestAnimationFrame(renderScene);
|
||||
renderer.render(scene, camera);
|
||||
};
|
||||
|
||||
// 能选中的组
|
||||
const enableGroup = [
|
||||
'set1',
|
||||
'set2',
|
||||
'set3',
|
||||
'set4',
|
||||
'set5',
|
||||
'set6',
|
||||
'set7',
|
||||
'set8',
|
||||
'yuanliao_room',
|
||||
'tanghua_room',
|
||||
'touliao_room',
|
||||
]
|
||||
let mouse = new THREE.Vector2();
|
||||
let selectedObjects = ref([]);
|
||||
let selectBoxByClick, selectBoxByMouseon;
|
||||
// 鼠标移动效果
|
||||
const onMouseMove = (event) => {
|
||||
var raycaster = new THREE.Raycaster()
|
||||
mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
|
||||
mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
|
||||
raycaster.setFromCamera(mouse, camera);
|
||||
const intersects = raycaster.intersectObjects(scene.children, true);
|
||||
if (intersects.length > 0) {
|
||||
const clickedObject = intersects[0].object;
|
||||
var selectedObject = clickedObject;
|
||||
if (enableGroup.indexOf(selectedObject.name) != -1) {
|
||||
selectedObjects[0] = selectedObject
|
||||
}
|
||||
if (enableGroup.indexOf(selectedObject.parent.name) != -1) {
|
||||
selectedObjects[0] = selectedObject.parent
|
||||
}
|
||||
if (selectBoxByMouseon) {
|
||||
scene.remove(selectBoxByMouseon);
|
||||
}
|
||||
selectBoxByMouseon = new THREE.BoxHelper(selectedObjects[0], '#ffffff');
|
||||
scene.add(selectBoxByMouseon);
|
||||
}
|
||||
}
|
||||
// 鼠标点击效果
|
||||
const onMouseDown = (event) => {
|
||||
var raycaster = new THREE.Raycaster()
|
||||
mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
|
||||
mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
|
||||
raycaster.setFromCamera(mouse, camera);
|
||||
const intersects = raycaster.intersectObjects(scene.children, true);
|
||||
if (intersects.length > 0) {
|
||||
const clickedObject = intersects[0].object;
|
||||
var selectedObject = clickedObject;
|
||||
console.log(selectedObject);
|
||||
if (enableGroup.indexOf(selectedObject.name) != -1) {
|
||||
selectedObjects[0] = selectedObject
|
||||
}
|
||||
if (enableGroup.indexOf(selectedObject.parent.name) != -1) {
|
||||
selectedObjects[0] = selectedObject.parent
|
||||
}
|
||||
if (selectBoxByClick) {
|
||||
scene.remove(selectBoxByClick);
|
||||
}
|
||||
selectBoxByClick = new THREE.BoxHelper(selectedObjects[0], '#00ffff');
|
||||
scene.add(selectBoxByClick);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<style scoped></style>
|
|
@ -48,7 +48,7 @@ import DeviceEvent from './components/DeviceEvent.vue';
|
|||
import ApplicationTree from './components/ApplicationTree.vue';
|
||||
import EquipmentInfo from './components/EquipmentInfo.vue';
|
||||
import RealData from './components/RealData.vue';
|
||||
import ThreeView from './components/ThreeView.vue';
|
||||
import ThreeView from './components/ThreeView2.vue';
|
||||
// import ThreeModel from './components/ThreeModel.vue';
|
||||
import DeviceInfoDialog from './components/DeviceInfoDialog.vue';
|
||||
import RealInfoDialog from './components/RealInfoDialog.vue';
|
||||
|
|
|
@ -25,7 +25,7 @@ export default defineConfig(({ mode, command }) => {
|
|||
},
|
||||
// vite 相关配置
|
||||
server: {
|
||||
port: 80,
|
||||
port: 8080,
|
||||
host: true,
|
||||
open: true,
|
||||
proxy: {
|
||||
|
|
Loading…
Reference in New Issue