From 4c851a7261e6da218c3a007e5f290ef7daa508ad Mon Sep 17 00:00:00 2001 From: Andre-John Mas Date: Wed, 20 Dec 2023 16:05:29 -0500 Subject: [PATCH] issue #27 Limit sat selection to active group --- src/viewer/Satellites.ts | 7 ++++-- src/viewer/index.ts | 54 ++++++++++++++++++++++++++++------------ 2 files changed, 43 insertions(+), 18 deletions(-) diff --git a/src/viewer/Satellites.ts b/src/viewer/Satellites.ts index 1e82d77..c6336b2 100644 --- a/src/viewer/Satellites.ts +++ b/src/viewer/Satellites.ts @@ -105,7 +105,6 @@ class Satellites implements SceneComponent, SelectableSatellite { for (let i = 0; i < satellites.length; i++) { let color = this.currentColorScheme?.getSatelliteColor(satellites[i], this.satelliteGroup)?.color; // || [0, 0, 0]; if (!color) { - console.log('no color', satellites[i].id); color = [0, 0, 0]; } const idx = i * 4; @@ -219,7 +218,7 @@ class Satellites implements SceneComponent, SelectableSatellite { } } - setSatelliteGroup (satelliteGroup: SatelliteGroup) { + setSatelliteGroup (satelliteGroup?: SatelliteGroup) { this.satelliteGroup = satelliteGroup; if (this.satelliteGroup) { this.currentColorScheme = new GroupColorScheme(); @@ -228,6 +227,10 @@ class Satellites implements SceneComponent, SelectableSatellite { } } + getSatellitegroup (): SatelliteGroup | undefined { + return this.satelliteGroup; + } + setSelectedSatellites (satelliteIndexes: number[]) { logger.debug('Updated selected satellites', satelliteIndexes); this.selectedSatelliteIndexes = satelliteIndexes; diff --git a/src/viewer/index.ts b/src/viewer/index.ts index bd5552e..cb16862 100644 --- a/src/viewer/index.ts +++ b/src/viewer/index.ts @@ -37,7 +37,7 @@ class Viewer { eventManager = new EventManager(); ready = false; raycaster?: Raycaster; - showRaycastArrow = true; + showRaycastArrow = false; raycastArrow?: ArrowHelper; satellites?: Satellites; orbits?: Orbits; @@ -101,29 +101,45 @@ class Viewer { this.raycaster.setFromCamera( mouse, this.camera); - if (this.raycastArrow) { - this.scene.remove(this.raycastArrow); - this.raycastArrow.dispose(); - this.raycastArrow = undefined; + if (this.showRaycastArrow) { + if (this.raycastArrow) { + this.scene.remove(this.raycastArrow); + this.raycastArrow.dispose(); + this.raycastArrow = undefined; + } + this.raycastArrow = new ArrowHelper(this.raycaster.ray.direction, this.raycaster.ray.origin, 300, 0xffff00, undefined, 1) ; + this.scene.add(this.raycastArrow); } - this.raycastArrow = new ArrowHelper(this.raycaster.ray.direction, this.raycaster.ray.origin, 300, 0xffff00, undefined, 1) ; - this.scene.add(this.raycastArrow); const intersects = this.raycaster.intersectObjects(this.scene.children, true); if (intersects.length > 0) { - return intersects.map(intersect => intersect.index) as number[]; + // TODO deal with lines + let satIndexes = intersects.filter(intersect => intersect.object.type === 'Points').map(intersect => intersect.index) as number[]; + + if (satIndexes.length > 0) { + const filteredSatIndexes: number[] = []; + for (let i = 0; i < satIndexes.length; i++) { + if (this.isValidTarget(satIndexes[i])) { + filteredSatIndexes.push(satIndexes[i]); + } + } + satIndexes = filteredSatIndexes; + } + return satIndexes; + } - // intersects.sort((intersectA, intersectB) => intersectA.distance - intersectB.distance); - // const intersctZero = intersects[0]; + return []; + } - // const satellite = this.satelliteStore?.getSatellite(intersctZero.index as number); - // this.satellites?.setSelectedSatellite(intersctZero.index as number); - // this.orbits?.setSelectedSatellite(intersctZero.index as number); - // this.eventManager.fireEvent('selectedSatChange', satellite); + isValidTarget (satelliteIdx: number): boolean { + const satelliteGroup = this.satellites?.getSatellitegroup(); + + if (satelliteGroup) { + return satelliteGroup.hasSat(satelliteIdx); } - return []; + return true; } onClick (event: MouseEvent) { @@ -326,8 +342,14 @@ class Viewer { this.orbits?.setSelectedSatellite(satelliteIdx); } + /** + * Sets the active satellite group, or if `undefined`, + * then it unsets the active satellite group. + * + * @param satelliteGroup + */ setSelectedSatelliteGroup (satelliteGroup?: SatelliteGroup) { - if (!satelliteGroup) return; + this.setSelectedSatellite(-1); this.satelliteGroups?.selectGroup(satelliteGroup); this.orbits?.setSatelliteGroup(satelliteGroup);