Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue #27 Limit sat selection to active group #33

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/viewer/Satellites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down
54 changes: 38 additions & 16 deletions src/viewer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Viewer {
eventManager = new EventManager();
ready = false;
raycaster?: Raycaster;
showRaycastArrow = true;
showRaycastArrow = false;
raycastArrow?: ArrowHelper;
satellites?: Satellites;
orbits?: Orbits;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down