// 监听鼠标点击事件
document.addEventListener('click', function (event) {
// 创建一个射线投射器
var raycaster = new THREE.Raycaster();
// 鼠标位置
var mouse = new THREE.Vector2();
//event.preventDefault();
// 将鼠标位置转换为有意义的数据
mouse.x = (event.clientX / renderer.domElement.clientWidth) * 2 - 1;
mouse.y = - (event.clientY / renderer.domElement.clientHeight) * 2 + 1;
// 使用鼠标位置更新射线投射器
raycaster.setFromCamera(mouse, camera);
// 计算物体和射线的交点
var intersects = raycaster.intersectObjects(scene.children, true);
// 如果存在交点
debugger
if (intersects.length > 0) {
// 获取第一个交点的3D坐标
var point = intersects[0].point;
console.log('3D Coordinates of the clicked point:', point.x, point.y, point.z);
}
}, false);
标签:raycaster,鼠标,point,three,js,点击,var,mouse,event
From: https://www.cnblogs.com/duixue/p/18556747