always select closest to pointer

This commit is contained in:
Norman Köhring 2023-01-22 22:50:27 +01:00
parent 3bac2bd865
commit 4a671e8019

View file

@ -1,3 +1,4 @@
import { IncomingMessage } from 'http'
import { import {
WebGLRenderer, WebGLRenderer,
Scene, Scene,
@ -60,13 +61,22 @@ function init() {
;(star as Star).highlighted = false ;(star as Star).highlighted = false
} }
let closest: Intersection<Object3D<Event>> | null = null
for (let i of intersections) { for (let i of intersections) {
const star = i.object.parent as Star if (i.distanceToRay === undefined) continue
if (closest === null || i.distanceToRay < (closest.distanceToRay ?? 0)) {
closest = i
}
}
if (closest === null) return
const star = closest.object.parent as Star
if (star.isStar) { if (star.isStar) {
star.highlighted = true star.highlighted = true
infoEl.innerText = JSON.stringify(star.starData) infoEl.innerText = JSON.stringify(star.starData)
} }
}
}) })
renderer.setAnimationLoop(() => { renderer.setAnimationLoop(() => {