Threejs:捕获鼠标位置
// 获取鼠标坐标 function onPointerMove(event) { //将鼠标点击位置的屏幕坐标转换成threejs中的标准坐标 mouse.x = (event.clientX / window.innerWidth) * 2 - 1 mouse.y = 1 - (event.clientY / window.innerHeight) * 2 // console.log(mouse); } // 渲染函数 function render() { // 通过摄像机和鼠标位置更新射线 raycaster.setFromCamera(mouse, camera); // 计算物体和射线的焦点 const intersects = raycaster.intersectObjects(scene.children); // for ( let i = 0; i < intersects.length; i ++ ) { // intersects[ i ].object.material.color.set( 0xff0000 ); // } renderer.render(scene, camera); } window.addEventListener('pointermove', onPointerMove); window.requestAnimationFrame(render);