always select closest to pointer
This commit is contained in:
parent
3bac2bd865
commit
4a671e8019
1 changed files with 14 additions and 4 deletions
14
src/main.ts
14
src/main.ts
|
@ -1,3 +1,4 @@
|
|||
import { IncomingMessage } from 'http'
|
||||
import {
|
||||
WebGLRenderer,
|
||||
Scene,
|
||||
|
@ -60,13 +61,22 @@ function init() {
|
|||
;(star as Star).highlighted = false
|
||||
}
|
||||
|
||||
let closest: Intersection<Object3D<Event>> | null = null
|
||||
|
||||
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) {
|
||||
star.highlighted = true
|
||||
infoEl.innerText = JSON.stringify(star.starData)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
renderer.setAnimationLoop(() => {
|
||||
|
|
Loading…
Add table
Reference in a new issue