Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ajmas/StuffInSpace
Browse files Browse the repository at this point in the history
  • Loading branch information
ajmas committed Dec 20, 2023
2 parents 71cf2b8 + d69a509 commit 4e28b96
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 18 deletions.
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

0 comments on commit 4e28b96

Please sign in to comment.