(event)
| 73 | const raycaster = new THREE.Raycaster(); |
| 74 | |
| 75 | const onMouseMove = (event) => { |
| 76 | // calculate pointer position in normalized device coordinates |
| 77 | // (-1 to +1) for both components |
| 78 | pointer.x = (event.clientX / window.innerWidth) * 2 - 1; |
| 79 | pointer.y = -(event.clientY / window.innerHeight) * 2 + 1; |
| 80 | |
| 81 | raycaster.setFromCamera(pointer, test.camera); |
| 82 | const intersects = raycaster.intersectObjects(test.scene.children); |
| 83 | |
| 84 | // for (let i = 0; i < intersects.length; i++) { |
| 85 | // console.log(intersects); |
| 86 | // } |
| 87 | |
| 88 | // change color of objects intersecting the raycaster |
| 89 | // for (let i = 0; i < intersects.length; i++) { |
| 90 | // intersects[i].object.material.color.set(0xff0000); |
| 91 | // } |
| 92 | |
| 93 | // change color of the closest object intersecting the raycaster |
| 94 | if (intersects.length > 0) { |
| 95 | intersects[0].object.material.color.set(0xff0000); |
| 96 | } |
| 97 | }; |
| 98 | |
| 99 | window.addEventListener('mousemove', onMouseMove); |
| 100 | }, []); |
nothing calls this directly
no outgoing calls
no test coverage detected