修改了选中的逻辑,更容易点击了
parent
59bbb8358c
commit
04e51bbcbf
|
@ -125,7 +125,7 @@ onMounted(() => {
|
||||||
// 启动动画
|
// 启动动画
|
||||||
renderScene();
|
renderScene();
|
||||||
document.addEventListener("click", onMouseDown);
|
document.addEventListener("click", onMouseDown);
|
||||||
document.addEventListener("mousemove", onMouseDown);
|
document.addEventListener("mousemove", onMouseMove);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -291,28 +291,31 @@ const enableGroup = [
|
||||||
'tanghua_room',
|
'tanghua_room',
|
||||||
'touliao_room',
|
'touliao_room',
|
||||||
]
|
]
|
||||||
// const onMouseDown = (event) => {
|
const onMouseMove = (event) => {
|
||||||
// // 计算鼠标点击位置的归一化设备坐标
|
var raycaster = new THREE.Raycaster()
|
||||||
// mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
|
// 计算鼠标点击位置的归一化设备坐标
|
||||||
// mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
|
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);
|
||||||
// // 更新射线的起点和方向
|
// 计算射线和场景中所有可点击物体的相交情况
|
||||||
// raycaster.setFromCamera(mouse, camera);
|
const intersects = raycaster.intersectObjects(scene.children, true);
|
||||||
// // 计算射线和场景中所有可点击物体的相交情况
|
// 如果找到了模型,将其材质修改为绿色
|
||||||
// const intersects = raycaster.intersectObjects(scene.children, true);
|
if (intersects.length > 0) {
|
||||||
// // 如果找到了模型,将其材质修改为绿色
|
const clickedObject = intersects[0].object;
|
||||||
// if (intersects.length > 0) {
|
// 储存被选中的模型和材质
|
||||||
// const clickedObject = intersects[0].object;
|
selectedObject = clickedObject;
|
||||||
// // 储存被选中的模型和材质
|
if (enableGroup.indexOf(selectedObject.name) != -1) {
|
||||||
// selectedObject = clickedObject;
|
outlineObj([selectedObject])
|
||||||
// // // 修改材质为绿色
|
// nearCamera(intersects);
|
||||||
// selectedObject.material = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
|
}
|
||||||
// nearCamera(intersects);
|
if (enableGroup.indexOf(selectedObject.parent.name) != -1) {
|
||||||
// }
|
outlineObj([selectedObject.parent])
|
||||||
|
// nearCamera(intersects);
|
||||||
// }
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
const onMouseDown = (event) => {
|
const onMouseDown = (event) => {
|
||||||
var raycaster = new THREE.Raycaster()
|
var raycaster = new THREE.Raycaster()
|
||||||
// 计算鼠标点击位置的归一化设备坐标
|
// 计算鼠标点击位置的归一化设备坐标
|
||||||
|
@ -327,13 +330,18 @@ const onMouseDown = (event) => {
|
||||||
if (intersects.length > 0) {
|
if (intersects.length > 0) {
|
||||||
const clickedObject = intersects[0].object;
|
const clickedObject = intersects[0].object;
|
||||||
// 储存被选中的模型和材质
|
// 储存被选中的模型和材质
|
||||||
selectedObject = clickedObject.parent;
|
selectedObject = clickedObject;
|
||||||
if (enableGroup.indexOf(selectedObject.name) != -1) {
|
if (enableGroup.indexOf(selectedObject.name) != -1) {
|
||||||
outlineObj([selectedObject])
|
outlineObj([selectedObject])
|
||||||
|
alert("点击了",selectedObject.name)
|
||||||
|
// nearCamera(intersects);
|
||||||
|
}
|
||||||
|
if (enableGroup.indexOf(selectedObject.parent.name) != -1) {
|
||||||
|
outlineObj([selectedObject.parent])
|
||||||
|
alert("点击了",selectedObject.parent.name)
|
||||||
// nearCamera(intersects);
|
// nearCamera(intersects);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let composer = null
|
let composer = null
|
||||||
|
|
|
@ -25,7 +25,7 @@ export default defineConfig(({ mode, command }) => {
|
||||||
},
|
},
|
||||||
// vite 相关配置
|
// vite 相关配置
|
||||||
server: {
|
server: {
|
||||||
port: 80,
|
port: 8080,
|
||||||
host: true,
|
host: true,
|
||||||
open: true,
|
open: true,
|
||||||
proxy: {
|
proxy: {
|
||||||
|
|
Loading…
Reference in New Issue