|
|
|
@ -1,6 +1,11 @@
|
|
|
|
|
<template>
|
|
|
|
|
<div>
|
|
|
|
|
<div ref="threeJs" class="app-container">
|
|
|
|
|
</div>
|
|
|
|
|
<div ref="demo">
|
|
|
|
|
<Demo/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
@ -9,6 +14,7 @@ import {OBJLoader} from 'three/examples/jsm/loaders/OBJLoader.js';
|
|
|
|
|
import {MTLLoader} from 'three/examples/jsm/loaders/MTLLoader.js';
|
|
|
|
|
import {OrbitControls} from 'three/examples/jsm/controls/OrbitControls.js';
|
|
|
|
|
import {CSS2DObject, CSS2DRenderer} from "three/examples/jsm/renderers/CSS2DRenderer";
|
|
|
|
|
import Demo from '@/components/model/demo.vue'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const vw = (document.documentElement.clientWidth || document.body.clientWidth) / 100
|
|
|
|
@ -16,7 +22,7 @@ let a = 0
|
|
|
|
|
let lastModel = null
|
|
|
|
|
export default {
|
|
|
|
|
name: 'Model',
|
|
|
|
|
components: {},
|
|
|
|
|
components: {Demo},
|
|
|
|
|
data() {
|
|
|
|
|
return {}
|
|
|
|
|
},
|
|
|
|
@ -26,9 +32,10 @@ export default {
|
|
|
|
|
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000000000);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// camera.position.set(1, 1, 1);
|
|
|
|
|
camera.position.set(289, 1559, 1298);
|
|
|
|
|
camera.lookAt(285, -66, -15);
|
|
|
|
|
camera.position.set(1, 1, 1);
|
|
|
|
|
// camera.position.set(-21325, 588, -56323);
|
|
|
|
|
// camera.lookAt(285, -66, -15);
|
|
|
|
|
camera.lookAt(1, 1, -1);
|
|
|
|
|
camera.updateProjectionMatrix();
|
|
|
|
|
|
|
|
|
|
const renderer = new THREE.WebGLRenderer({
|
|
|
|
@ -53,7 +60,6 @@ export default {
|
|
|
|
|
light.target.position.set(0, 0, 0);
|
|
|
|
|
scene.add(light)
|
|
|
|
|
|
|
|
|
|
// camera.position.z = 5;
|
|
|
|
|
const loadF = (e) => {
|
|
|
|
|
let str = '/1'
|
|
|
|
|
e.forEach(v => {
|
|
|
|
@ -97,16 +103,14 @@ export default {
|
|
|
|
|
const labelRenderer = new CSS2DRenderer();
|
|
|
|
|
labelRenderer.setSize(window.innerWidth, window.innerHeight);
|
|
|
|
|
labelRenderer.domElement.style.position = 'absolute';
|
|
|
|
|
labelRenderer.domElement.style.top = 0;
|
|
|
|
|
labelRenderer.domElement.style.top = '0';
|
|
|
|
|
labelRenderer.domElement.style.pointerEvents = 'none';
|
|
|
|
|
document.body.appendChild(labelRenderer.domElement);
|
|
|
|
|
|
|
|
|
|
// 创建CSS2DObject
|
|
|
|
|
const label = document.createElement('div');
|
|
|
|
|
label.style.color = '#fff';
|
|
|
|
|
label.innerHTML = '这是提示窗口';
|
|
|
|
|
const label = this.$refs.demo
|
|
|
|
|
const labelObject = new CSS2DObject(label);
|
|
|
|
|
labelObject.position.set(289, 1559, 1298); // 根据需要调整位置
|
|
|
|
|
labelObject.position.set(-21325, 550, -56323); // 根据需要调整位置
|
|
|
|
|
scene.add(labelObject);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -116,6 +120,18 @@ export default {
|
|
|
|
|
// 创建一个二维空间的向量用于存储鼠标点击的屏幕位置
|
|
|
|
|
var mouse = new THREE.Vector2();
|
|
|
|
|
|
|
|
|
|
function getModelById(id) {
|
|
|
|
|
// 遍历场景中的所有对象
|
|
|
|
|
const objects = scene.children.filter(obj => obj.type === 'Group' || obj.type === 'Object3D');
|
|
|
|
|
for (const obj of objects) {
|
|
|
|
|
if (obj.id === id) {
|
|
|
|
|
// 返回匹配ID的模型
|
|
|
|
|
return obj;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 监听鼠标点击事件
|
|
|
|
|
document.addEventListener('dblclick', function (event) {
|
|
|
|
|
// 将鼠标位置转换为二维向量
|
|
|
|
@ -130,16 +146,13 @@ export default {
|
|
|
|
|
|
|
|
|
|
// 如果有交点
|
|
|
|
|
if (intersects.length > 0) {
|
|
|
|
|
// 获取第一个交点的对象
|
|
|
|
|
var obj = intersects[0].object;
|
|
|
|
|
console.log('Clicked object:', obj);
|
|
|
|
|
outlineObj(obj.parent)
|
|
|
|
|
// obj.parent.children.forEach(e => {
|
|
|
|
|
// e.material.color.set(0xff0000);
|
|
|
|
|
// })
|
|
|
|
|
// obj.material.color.set(0xff0000);
|
|
|
|
|
alert(obj.parent?.name || obj.name)
|
|
|
|
|
// 你可以在这里添加你想要的逻辑,比如高亮被点击的模型等
|
|
|
|
|
camera.position.set((intersects[0].point.x + 5000), (intersects[0].point.y + 5000), (intersects[0].point.z - 1000));
|
|
|
|
|
camera.updateProjectionMatrix();
|
|
|
|
|
controls.target = new THREE.Vector3(intersects[0].point.x, intersects[0].point.y, intersects[0].point.z)
|
|
|
|
|
controls.update();
|
|
|
|
|
|
|
|
|
|
renderer.render(scene, camera);
|
|
|
|
|
}
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
@ -152,8 +165,8 @@ export default {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setInterval(() => {
|
|
|
|
|
// console.log(camera)
|
|
|
|
|
}, 1000)
|
|
|
|
|
console.log(camera)
|
|
|
|
|
}, 1000 * 10)
|
|
|
|
|
|
|
|
|
|
animate();
|
|
|
|
|
|
|
|
|
|