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

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(); 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])
// // // 绿
// selectedObject.material = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
// nearCamera(intersects); // 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

View File

@ -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: {