1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| const raycaster = new THREE.Raycaster()
const mouse = new THREE.Vector2()
window.addEventListener("click", (event) => { mouse.x = (event.clientX / window.innerWidth) *2 -1 mouse.y = -((event.clientY / window.innerHeight) *2 -1) raycaster.setFromCamera(mouse, camera) const intersects = raycaster.intersectObjects([sphere1, sphere2, sphere3]) if(intersects.length > 0) { if(intersects[0].object._isSelect) { intersects[0].object.material.color.set(intersects[0].object._originColor) intersects[0].object._isSelect = false return } intersects[0].object._isSelect = true intersects[0].object._originColor = intersects[0].object.material.color.getHex() intersects[0].object.material.color.set(0xff00ff) } })
|