监听事件
ThreeDom.current.addEventListener('mousemove', mousemoveFunc, false);
监听方法
const mousemoveFunc = (event) => {
event.preventDefault();
// 计算鼠标在屏幕上的位置
const mouse = new THREE.Vector2();
mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
// 将屏幕坐标转换为3D坐标
const raycaster = new THREE.Raycaster();
raycaster.setFromCamera(mouse, Three.camera);
// 获取鼠标位置对应的3D坐标
const intersects = raycaster.intersectObjects(Three.scene.children, true);
console.log(intersects);
if (intersects.length > 0) {
const position = intersects[0].point;
console.log('3D坐标: ', position);
}
};
标签:Raycaster,intersects,鼠标,坐标,const,mouse,event From: https://www.cnblogs.com/Simoon/p/18514142