修改了选中的逻辑,更容易点击了
parent
59bbb8358c
commit
04e51bbcbf
|
@ -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 });
|
||||
// 更新射线的起点和方向
|
||||
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
|
||||
|
|
|
@ -25,7 +25,7 @@ export default defineConfig(({ mode, command }) => {
|
|||
},
|
||||
// vite 相关配置
|
||||
server: {
|
||||
port: 80,
|
||||
port: 8080,
|
||||
host: true,
|
||||
open: true,
|
||||
proxy: {
|
||||
|
|
Loading…
Reference in New Issue