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