修改了选中的逻辑,更容易点击了

main
cc 2023-12-10 02:11:35 +00:00
parent 59bbb8358c
commit 04e51bbcbf
2 changed files with 33 additions and 25 deletions

View File

@ -125,7 +125,7 @@ onMounted(() => {
//
renderScene();
document.addEventListener("click", onMouseDown);
document.addEventListener("mousemove", onMouseDown);
document.addEventListener("mousemove", onMouseMove);
});
@ -291,28 +291,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 });
// nearCamera(intersects);
// }
// }
// 线
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()
//
@ -327,13 +330,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

View File

@ -25,7 +25,7 @@ export default defineConfig(({ mode, command }) => {
},
// vite 相关配置
server: {
port: 80,
port: 8080,
host: true,
open: true,
proxy: {