always select closest to pointer
This commit is contained in:
parent
3bac2bd865
commit
4a671e8019
1 changed files with 14 additions and 4 deletions
18
src/main.ts
18
src/main.ts
|
@ -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 (star.isStar) {
|
if (closest === null || i.distanceToRay < (closest.distanceToRay ?? 0)) {
|
||||||
star.highlighted = true
|
closest = i
|
||||||
infoEl.innerText = JSON.stringify(star.starData)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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(() => {
|
renderer.setAnimationLoop(() => {
|
||||||
|
|
Loading…
Add table
Reference in a new issue