From d31b719eb160f4dfb1ec86e536266b991e0c5cc3 Mon Sep 17 00:00:00 2001 From: ajmas Date: Thu, 21 Dec 2023 05:27:33 +0000 Subject: [PATCH] deploy: e3c355a4fc67f10b4524d726be9fabba63375729 --- assets/index-98167e89.js | 4 ++++ assets/index-a58a40e6.js | 4 ---- index.html | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) create mode 100644 assets/index-98167e89.js delete mode 100644 assets/index-a58a40e6.js diff --git a/assets/index-98167e89.js b/assets/index-98167e89.js new file mode 100644 index 0000000..0723b14 --- /dev/null +++ b/assets/index-98167e89.js @@ -0,0 +1,4 @@ +var re=Object.defineProperty;var oe=(r,e,t)=>e in r?re(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var o=(r,e,t)=>(oe(r,typeof e!="symbol"?e+"":e,t),t);import{T as w,S as E,M as j,a as G,U as ae,b as V,B as ne,A as le,G as B,C as $,D as he,P as ce,F as g,c as J,d as de,e as ue,O as fe,f as ge,L as pe,g as me,h as Se,i as z,V as we,j as ye,k as ve,l as be,W as xe,m as Le,R as De}from"./vendor-e5c7e806.js";(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))s(i);new MutationObserver(i=>{for(const a of i)if(a.type==="childList")for(const n of a.addedNodes)n.tagName==="LINK"&&n.rel==="modulepreload"&&s(n)}).observe(document,{childList:!0,subtree:!0});function t(i){const a={};return i.integrity&&(a.integrity=i.integrity),i.referrerPolicy&&(a.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?a.credentials="include":i.crossOrigin==="anonymous"?a.credentials="omit":a.credentials="same-origin",a}function s(i){if(i.ep)return;i.ep=!0;const a=t(i);fetch(i.href,a)}})();class Ee{constructor(){o(this,"baseUrl","");o(this,"basePath","/StuffInSpace/images");o(this,"radiusInKm",6371);o(this,"pxToRadius",3185.5);o(this,"addAtmosphere",!1);o(this,"addClouds",!0);o(this,"sphere");o(this,"group")}initClouds(e,t){const s=new w().load(`${this.basePath}/Earth_Cloud.jpg`),i=e.km2pixels(this.radiusInKm+.02),a=new E(i,32,32),n=new j({map:s,opacity:.3,transparent:!0}),l=new G(a,n),h=1.01;l.scale.set(h,h,h),t.add(l)}initAtmosphere(e,t){const s=["varying vec3 vNormal;","varying vec3 vPosition;","void main() {","vNormal = normalize( normalMatrix * normal );","gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );","vPosition = gl_Position.xyz;","}"].join(` +`),i=["varying vec3 vNormal;","varying vec3 vPosition;","void main() {"," float intensity = pow( 0.8 + dot( vNormal, vec3( 0, 0, 1.0 ) ), 12.0 );"," intensity = min(intensity, 1.7);"," gl_FragColor = vec4( 0.37, 0.71, 0.93, 0.6 ) * intensity;","}"].join(` +`),a=ae.clone({}),n=new V({uniforms:a,vertexShader:s,fragmentShader:i,side:ne,blending:le,transparent:!0}),l=e.km2pixels(this.radiusInKm+.1),h=new E(l,32,32),c=new G(h,n),f=1.019;c.scale.set(f,f,f),t.add(c)}init(e,t){t.config&&(this.baseUrl=t.config.baseUrl),this.group=new B;const s=`${this.baseUrl}/images`,i=new w().load(`${s}/earth-blue-marble.jpg`),a=new w().load(`${s}/nightearth-4096.png`),n=new w().load(`${s}/8081_earthbump4k.jpg`),l=new w().load(`${s}/earth-water.png`),h=new j({map:i,bumpMap:n,emissiveMap:a,emissive:new $(8947848),emissiveIntensity:5,specularMap:l,specular:1,shininess:15,bumpScale:1}),c=e.km2pixels(this.radiusInKm),f=new E(c,32,32);this.sphere=new G(f,h),this.group.add(this.sphere),this.addClouds&&this.initClouds(e,this.group),this.addAtmosphere&&this.initAtmosphere(e,this.group),e.add(this.group),this.sphere.geometry.computeBoundingBox(),this.sphere.geometry.computeBoundingSphere()}update(){}getMesh(){return this.sphere}}const T=class T{constructor(){o(this,"fastTime",!1);o(this,"showGeometry",!1);o(this,"lightSouce");o(this,"lightSourceGeometery");o(this,"hour",0);o(this,"objectGroup");o(this,"scene");o(this,"visible",!0)}degreesToReadians(e){return e*T.deg2RadMult}calculateSunLoc(){let t=this.hour;(t===void 0||t===-1)&&(t=he.utc().hour);const s=t/24*360+180;return{x:25*Math.cos(this.degreesToReadians(s)),z:25*Math.sin(this.degreesToReadians(s))}}init(e){this.fastTime?setInterval(()=>{this.hour+=.05},100):this.hour=-1,this.calculateSunLoc();const t=this.calculateSunLoc(),s={x:t.x,y:0,z:t.z};if(this.scene=e,this.objectGroup=new B,this.lightSouce=new ce(16777215,2e3),this.lightSouce.position.set(s.x,s.y,s.z),this.objectGroup.add(this.lightSouce),this.showGeometry){const i=new E(.1,32,32);this.lightSourceGeometery=new G(i),this.lightSourceGeometery.position.set(s.x,s.y,s.z),this.objectGroup.add(this.lightSourceGeometery)}e.add(this.objectGroup)}update(){}setVisible(e){var t,s;e?this.visible||(t=this.scene)==null||t.add(this.objectGroup):this.visible&&((s=this.scene)==null||s.remove(this.objectGroup)),this.visible=e}};o(T,"deg2RadMult",Math.PI/180);let M=T;class Ge{init(e){const t=new w().load("textures/example_render.jpg");e.background=t}update(){}}function Te(){return new Worker("/StuffInSpace/assets/SatCruncherWorker-37c21408.js")}const Ce="debug",x=["error","warn","info","debug"];let v={},L=new Proxy({logLevel:Ce,enabledOutputs:{},error:v.error,warn:v.warn,info:v.info,debug:v.debug,setLogLevel:_},{});function D(r,e,t,...s){r.enabledOutputs[e]&&t(e.toUpperCase(),...s)}function _(r){const e=x.indexOf(r.toLowerCase());if(e<0)throw new Error("Unknown log level");for(let t=0;t{let t=[1,1,0,1],s=!1;return e&&(s=!0,e.OBJECT_TYPE==="PAYLOAD"?t=[1,.2,0,1]:e.OBJECT_TYPE==="ROCKET BODY"?t=[.2,.5,1,.85]:e.OBJECT_TYPE==="DEBRIS"&&(t=[.5,.5,.5,.85])),{color:t,pickable:s}})}}class Me extends Y{constructor(){super("Group color scheme",(e,t)=>e&&t&&t.hasSat(e.id)?{color:[1,.2,0,1],pickable:!0}:{color:[1,1,1,.2],pickable:!0})}}class ke{constructor(){o(this,"baseUrl","");o(this,"worker");o(this,"currentColorScheme",new F);o(this,"numSats",1);o(this,"maxSize",0);o(this,"satPos",new Float32Array);o(this,"satVel",new Float32Array);o(this,"satAlt",new Float32Array);o(this,"satelliteColors",[]);o(this,"cruncherReady",!1);o(this,"scene");o(this,"particles");o(this,"geometry");o(this,"satelliteStore");o(this,"shaderStore");o(this,"selectedSatelliteIndexes",[]);o(this,"satelliteGroup");o(this,"hoverSatelliteIdx",-1)}setColorScheme(e){this.currentColorScheme=e}debugRaycastSelection(){if(this.satelliteStore&&(this.satelliteColors.length===0&&this.satelliteStore.satData.length>0&&(this.satelliteColors=new Array(this.satelliteStore.satData.length*4),this.satelliteColors.fill(1,0,this.satelliteColors.length),this.geometry&&this.geometry.setAttribute("color",new g(this.satelliteColors,4))),this.selectedSatelliteIndexes.length>0&&this.geometry)){for(let e=0;e0&&(e=this.geometry)!=null&&e.attributes){const t=this.satelliteStore.satData,s=t.length;this.updateSatellitesGeometry(),this.updateSatellitesMaterial(s,t)}this.debugRaycastSelection()}}updateSatellitesMaterial(e,t){var s,i,a;if((s=this.geometry)!=null&&s.attributes.color&&this.currentColorScheme&&this.satelliteStore){(this.satelliteColors.length===0||e*4!==this.satelliteColors.length)&&(this.satelliteColors=new Array(this.satelliteStore.satData.length*4),this.satelliteColors.fill(1,0,this.satelliteColors.length));for(let n=0;n{var c;(c=this.worker)==null||c.postMessage(JSON.stringify({state:{running:document.visibilityState==="visible"}}))})}getObject3D(){return this.particles}initSatWorker(e={}){u.info("Kicking off sat-cruncher-worker"),this.worker=new Te,this.worker.onmessage=this.onMessage.bind(this),this.worker.postMessage(JSON.stringify({config:e}))}async init(e,t){this.satelliteStore=t.satelliteStore,this.shaderStore=t.shaderStore,this.scene=e;const s=t.config||{};let i={};s.satWorker&&(i={...s.satWorker,logLevel:s.logLevel}),this.initSatWorker(i),t!=null&&t.config&&(this.baseUrl=t.config.baseUrl),this.satelliteStore&&(this.satelliteStore.addEventListener("satdataloaded",this.onSatDataLoaded.bind(this)),await this.satelliteStore.loadSatelliteData(),this.initGeometry(),this.satelliteStore.gotExtraData&&this.updateSatellites())}update(){}}function Ie(){return new Worker("/StuffInSpace/assets/OrbitCalculationWorker-dff8774f.js")}class Pe{constructor(){o(this,"config",{});o(this,"segmentCount",255);o(this,"orbitWorker");o(this,"selectedSatellites",[]);o(this,"hoverSatelliteIdx",-1);o(this,"satelliteGroups");o(this,"satelliteGroup");o(this,"inProgress",[]);o(this,"scene");o(this,"selectColor",[0,1,0,1]);o(this,"hoverColor",[1,.92,.23,1]);o(this,"groupColor",[.3,.5,1,.4]);o(this,"orbitTracks",[]);o(this,"satelliteStore");o(this,"satelliteOrbitGroup")}calculateOrbits(e){e=e.filter(t=>!this.inProgress[t]),this.orbitWorker?this.orbitWorker.postMessage(JSON.stringify({isInit:!1,satId:e})):u.error("Orbit worker is undefined"),e.forEach(t=>this.inProgress[t]=!0)}onSatellitesLoaded(){this.satelliteStore&&(this.inProgress=new Array(this.satelliteStore.size()),this.orbitTracks=new Array(this.satelliteStore.size()),this.orbitWorker&&this.orbitWorker.postMessage(JSON.stringify({isInit:!0,satData:this.satelliteStore.satData,numSegs:this.segmentCount})))}isTrackVisible(e){return this.selectedSatellites.indexOf(e)>-1||e===this.hoverSatelliteIdx||this.satelliteGroup&&this.satelliteGroup.hasSat(e)}getTrackColor(e){let t=[1,1,0];return e===this.hoverSatelliteIdx?t=this.hoverColor:this.selectedSatellites.indexOf(e)>-1?t=this.selectColor:this.satelliteGroup&&this.satelliteGroup.hasSat(e)&&(t=this.groupColor),new $(t[0],t[1],t[2])}addOrbitTrack(e,t){const s=this.getTrackColor(e),i=new pe({color:s,linewidth:10}),a=new J;a.setAttribute("position",new g(t,3));const n=new me(a,i);n.name=`${e}`,this.satelliteOrbitGroup&&this.satelliteOrbitGroup.add(n),this.orbitTracks[e]=n}updateOrbitTrack(e,t){const s=this.orbitTracks[e];if(s){const i=s.material;i.color=this.getTrackColor(e),i.needsUpdate=!0,t&&(s.geometry.setAttribute("position",new g(t,3)),s.geometry.computeBoundingBox(),s.geometry.computeBoundingSphere())}}removeOrbitTrack(e){var t;if(this.orbitTracks[e]){const s=this.orbitTracks[e];(t=this.satelliteOrbitGroup)==null||t.remove(s),s.geometry&&s.geometry.dispose(),this.orbitTracks[e]=void 0}}onMessage(e){const{satId:t}=e.data;this.scene&&(this.orbitTracks[t]?this.updateOrbitTrack(t,e.data.pointsOut):this.isTrackVisible(t)&&this.addOrbitTrack(t,e.data.pointsOut)),this.inProgress[t]=!1}isHoverSatellite(e){return this.hoverSatelliteIdx!==void 0&&e!==-1&&this.hoverSatelliteIdx===e}isSelectedSatellite(e){return this.selectedSatellites.length>0?this.selectedSatellites.indexOf(e)>-1:!1}refreshOrbits(){if(this.satelliteGroup){const e=this.satelliteGroup.sats;for(let t=0;t0)for(let t=0;t-1&&(t=this.selectedSatellites.indexOf(this.hoverSatelliteIdx)<0,t=t&&(!this.satelliteGroup||!this.satelliteGroup.hasSat(this.hoverSatelliteIdx))),this.hoverSatelliteIdx=e,t?this.removeOrbitTrack(s):this.updateOrbitTrack(s),this.calculateOrbits([e]),this.refreshOrbits()}setSatelliteGroup(e){if(this.satelliteGroup){this.setSelectedSatellites([]),this.setHoverSatellite(-1);for(let t=0;ti.satId);this.calculateOrbits(s)}}init(e,t){this.config=t.config,this.scene=e,this.orbitWorker=new Ie,this.orbitWorker.onmessage=this.onMessage.bind(this),this.satelliteStore=t.satelliteStore,this.orbitWorker.postMessage(JSON.stringify({config:{logLevel:this.config.logLevel}})),this.satelliteStore&&(this.satelliteStore.addEventListener("satdataloaded",this.onSatellitesLoaded.bind(this)),this.satelliteStore.size()>0&&(this.inProgress=new Array(this.satelliteStore.size()),this.onSatellitesLoaded())),t.satelliteGroups&&(this.satelliteGroups=t.satelliteGroups),this.satelliteOrbitGroup=new B,this.scene.add(this.satelliteOrbitGroup)}update(){}}const C=class C extends Se{constructor(){super();o(this,"pxToRadius",3185.5)}setPixels2Radius(t){this.pxToRadius=t}getPixels2Radius(){return this.pxToRadius}km2pixels(t){return t/this.pxToRadius}alitudeToPixels(t){return(C.earthRadiusInKm+t)/this.pxToRadius}};o(C,"earthRadiusInKm",6371);let k=C;class K{constructor(e,t,s,i,a){o(this,"sats",[]);o(this,"id");o(this,"name");o(this,"groupType");o(this,"data");o(this,"satelliteStore");if(this.id=e,this.name=t,this.groupType=s,this.data=i,this.satelliteStore=a,!this.satelliteStore)throw new Error("satelliteStore is required")}reload(){if(this.sats=[],this.groupType==="intlDes")for(let e=0;et.id===e)}hasSat(e){const t=this.sats.length;for(let s=0;s{i(t)})}}const We={baseUrl:"/StuffInSpace"};class Be{constructor(e={}){o(this,"tleUrl",`${We.baseUrl}/data/attributed-TLE.json`);o(this,"eventManager");o(this,"satData",[]);o(this,"attribution");o(this,"updateDate");o(this,"satelliteVelocities",new Float32Array);o(this,"satellitePositions",new Float32Array);o(this,"satelliteAltitudes",new Float32Array);o(this,"gotExtraData",!1);o(this,"gotPositionalData",!1);o(this,"loaded",!1);this.eventManager=new Z,e.tleUrl&&(this.tleUrl=e.tleUrl)}async loadSatelliteData(){try{const e=await z.get(this.tleUrl,{params:{t:Date.now()}});if(e.data){Array.isArray(e.data)?this.satData=e.data:(this.satData=e.data.data,this.attribution=e.data.source,this.updateDate=e.data.date);for(let t=0;t50?"19":"20")+s;const a=this.satData[t].INTLDES.substring(2);this.satData[t].intlDes=`${s}-${a}`}else this.satData[t].intlDes="unknown";this.satData[t].id=t}}this.eventManager.fireEvent("satdataloaded",this.satData),this.loaded=!0}catch(e){u.error("error loading TLE data",e)}}getAttribution(){return this.attribution}getUpdatedDate(){return this.updateDate}setSatelliteData(e,t=!1){this.satData=e,this.gotExtraData=t,t&&this.eventManager.fireEvent("satextradataloaded",this.satData)}setPositionalData(e,t,s){this.satelliteVelocities=e,this.satellitePositions=t,this.satelliteAltitudes=s,this.gotPositionalData=!0}getSatellitePosition(e){const t=e*3;if(this.satellitePositions&&tn[a]===e[a])}return s}searchName(e){const t=[];for(let s=0;s0){a.sort((h,c)=>h.object.type==="Line"&&c.object.type==="Points"?1:h.object.type==="Points"&&c.object.type==="Line"?-1:0);let l=a.map(h=>h.object.type==="Points"?h.index:h.object.type==="Line"?parseInt(h.object.name):-1).filter(h=>h!==-1);if(l.length>0){const h=[];for(let c=0;c0&&(i=s[0],a=(l=this.satelliteStore)==null?void 0:l.getSatellite(i)),(h=this.satellites)==null||h.setSelectedSatellite(i),(c=this.orbits)==null||c.setSelectedSatellite(i),this.eventManager.fireEvent("selectedSatChange",a)}onMouseMove(){this.mouseMoved=!0}onMouseDown(){this.mouseMoved=!1,window.addEventListener("mousemove",this.onMouseMove.bind(this))}onMouseUp(e){this.mouseMoved||this.onClick(e),this.mouseMoved=!1,window.removeEventListener("mousemove",this.onMouseMove.bind(this))}onHover(e){var n,l,h,c;const t=(n=this.renderer)==null?void 0:n.domElement;if(!this.raycaster||!this.scene||!this.camera||!t)return;const s=this.findSatellitesAtMouse({x:e.clientX,y:e.clientY});let i=-1,a;s&&s.length>0&&(i=s[0],a=(l=this.satelliteStore)==null?void 0:l.getSatellite(i)),(h=this.satellites)==null||h.setHoverSatellite(i),(c=this.orbits)==null||c.setHoverSatellite(i),this.eventManager.fireEvent("sathoverChange",a),this.mouseMoved=!0}async init(){var e;try{this.scene=new k,this.camera=new be(45,window.innerWidth/window.innerHeight,.1,1e3),this.renderer=new xe({antialias:!0}),this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.setSize(window.innerWidth,window.innerHeight),(e=document.querySelector(this.config.canvasSelector))==null||e.appendChild(this.renderer.domElement),this.controls=new Le(this.camera,this.renderer.domElement),this.camera.position.set(15,0,-100),this.controls.update(),this.camera.position.y=5,this.camera.zoom=5,this.raycaster=new De,this.satelliteStore=new Be(this.config),this.satelliteGroups=new Re(this.config.satelliteGroups,this.satelliteStore),this.shaderStore=new $e(this.config.baseUrl),u.debug("loading shaders"),await this.shaderStore.load(),this.context.satelliteGroups=this.satelliteGroups,this.context.config=this.config,this.context.satelliteStore=this.satelliteStore,this.context.shaderStore=this.shaderStore,this.satelliteStore.addEventListener("satdataloaded",this.onSatDataLoaded.bind(this)),this.earth=new Ee,await this.registerSceneComponent("earth",this.earth),await this.registerSceneComponent("sun",new M),await this.registerSceneComponent("universe",new Ge),this.satellites=new ke,await this.registerSceneComponent("satellites",this.satellites),this.orbits=new Pe,await this.registerSceneComponent("orbits",this.orbits);const t=this.getCenterPoint(this.earth.getMesh());t&&(this.controls.target=t),this.camera.position.y=42,this.controls.minDistance=this.minZoom,this.controls.maxDistance=this.maxZoom,this.controls.enablePan=!1,this.controls.zoomSpeed=.5,this.camera.updateProjectionMatrix(),window.addEventListener("resize",this.onWindowResize.bind(this));const s=this.renderer.domElement;s.addEventListener("mousedown",this.onMouseDown.bind(this)),s.addEventListener("mouseup",this.onMouseUp.bind(this)),s.addEventListener("mousemove",this.onHover.bind(this))}catch(t){u.error("Error while initialising scene",t)}}animate(){requestAnimationFrame(this.animate.bind(this));for(let e=0;e{this.camera&&(this.camera.zoom>this.maxZoom||this.camera.zoom{this.camera&&(this.camera.zoome&&(this.camera.zoom=this.camera.zoom+-.08,this.camera.zoom<0&&(this.camera.zoom=0),this.camera.updateProjectionMatrix(),setTimeout(s,t)))};setTimeout(s,t)}}setHoverSatellite(e){var t,s;(t=this.satellites)==null||t.setHoverSatellite(e),(s=this.orbits)==null||s.setHoverSatellite(e)}setSelectedSatellite(e){var t,s;(t=this.satellites)==null||t.setSelectedSatellite(e),(s=this.orbits)==null||s.setSelectedSatellite(e)}setSelectedSatelliteGroup(e){var t,s,i;this.setSelectedSatellite(-1),(t=this.satelliteGroups)==null||t.selectGroup(e),(s=this.orbits)==null||s.setSatelliteGroup(e),(i=this.satellites)==null||i.setSatelliteGroup(e)}getSelectedSatellite(){if(this.satelliteStore)return this.satelliteStore.getSatellite(this.selectedSatelliteIdx)}getSelectedSatelliteIdx(){return this.selectedSatelliteIdx}addEventListener(e,t){this.eventManager.addEventListener(e,t)}}function je(r){return new ze(r)}const Fe="/StuffInSpace",U={appName:"Stuff in Space",baseUrl:Fe,propergateInterval:1e3,pushHistory:!1,logLevel:"debug",satWorker:{runOnce:!0},satelliteGroups:[{id:"GPSGroup",name:"GPS",groupType:"intlDes",data:["90103A","93068A","96041A","97035A","99055A","00025A","00040A","00071A","01004A","03005A","03010A","03058A","04009A","04023A","04045A","05038A","06042A","06052A","07047A","07062A","08012A","09043A","10022A","11036A","12053A","13023A","14008A","14026A","14045A","14068A","15013A"]},{id:"IridiumGroup",name:"Iridium Debris",groupType:"nameRegex",data:/IRIDIUM(?!.*DEB)/},{id:"Iridium33DebrisGroup",name:"Iridium 33 Debris",groupType:"nameRegex",data:/(COSMOS 2251|IRIDIUM 33) DEB/},{id:"GlonassGroup",name:"Glonass",groupType:"nameRegex",data:/GLONASS/},{id:"GalileoGroup",name:"Galileo",groupType:"nameRegex",data:/GALILEO/},{id:"FunGroup",name:"Fun",groupType:"nameRegex",data:/SYLDA/},{id:"WestfordNeedlesGroup",name:"Westford Needles",groupType:"nameRegex",data:/WESTFORD NEEDLES/},{id:"SpaceXGroup",name:"Space X",groupType:"nameRegex",data:/FALCON [19]/},{id:"DebrisGroup",name:"Debris",groupType:"objectType",data:"DEBRIS"},{id:"Starlink",name:"Starlink",groupType:"nameRegex",data:/STARLINK/},{id:"Unknown",name:"Unknown Objects",groupType:"objectType",data:"UNKNOWN"}]},Ue=80/Math.PI,I={satMovementChange:"satMovementChange",selectedSatChange:"selectedSatChange",satHover:"sathoverChange",satDataLoaded:"satdataloaded",closeWindow:"closeWindow",cruncherReady:"cruncherReady"};class qe{constructor(e,t={}){o(this,"element");o(this,"id");o(this,"options");o(this,"listeners",{});o(this,"firstOpen",!0);o(this,"windowManager");this.element=document.querySelector(`#${e}`),this.id=e,this.options=t,this.listeners={},this.firstOpen=!0,this.initEvents()}setWindowManager(e){this.windowManager=e}open(){this.element&&(this.firstOpen=!1,this.element.classList.add("active"),this.element.classList.add("visible"),this.element.classList.remove("hidden"),this.windowManager.bringWindowToFront(this))}close(){this.element&&(this.element.classList.remove("active"),this.element.classList.remove("visible"),this.element.classList.add("hidden"))}isOpen(){return this.element?this.element.classList.contains("visible"):!1}initEvents(){if(!this.element)return;const e=this.element.querySelector(".window-close");e&&e.addEventListener("click",()=>{this.close()})}moveTo(e,t){this.element&&(this.element.style.top=`${t}px`,this.element.style.left=`${e}px`)}getLocation(){if(!this.element)return{x:0,y:0};const e=this.element.style;return e.x?{x:e.x,y:e.y}:{x:this.element.offsetLeft,y:this.element.offsetTop}}addEventListener(e,t){if(this.listeners[e]||(this.listeners[e]=new Set),this.listeners[e])this.listeners[e].add(t);else throw new Error("unknown event")}fireEvent(e,t){this.listeners[e]&&this.listeners[e].forEach(i=>{i(t)})}}const He=100;class Ne{constructor(){o(this,"windows",[]);o(this,"windowsById",{});o(this,"initialOpen",!1)}bringWindowToFront(e){const t=e.element;let s=-1;for(let i=0;i-1&&(this.windows.splice(s,1),this.windows.push(e));for(let i=0;i=0;e--)if(this.windows[e].isOpen())return this.windows[e]}openWindow(e){const s={x:100,y:100},i=this.windowsById[e],a=this.getTopWindow();let n=!1;if(i){let{x:l,y:h}=i.getLocation();if(a||(l=s.x,h=s.y,this.initialOpen=!1),n=i.firstOpen,n&&a){const c=a.getLocation();c&&(l=c.x+42,h=c.y+42)}if(i.open(),!this.initialOpen&&!n){const c=i.getLocation();c&&(l=c.x,h=c.y)}(l>window.innerWidth||l<0)&&(l=s.x),(h>window.innerHeight||h<0)&&(h=s.y),this.bringWindowToFront(i),i.moveTo(l,h),this.initialOpen=!1}}closeWindow(e){const t=this.windowsById[e];t&&t.close()}makeDraggable(e){let t=0,s=0,i=0,a=0;const n=e.element;if(!n)return;const l=n.querySelector(".drag-zone")||n;function h(c){const f=`${t-(a-c.clientY)}px`,b=`${s-(i-c.clientX)}px`;n&&n.style&&(n.style.top=f,n.style.left=b)}n.classList.add("draggable"),n.addEventListener("click",()=>{this.bringWindowToFront(e)}),l.addEventListener("mousedown",c=>{c.preventDefault(),s=n.offsetLeft,t=n.offsetTop,i=c.clientX,a=c.clientY,this.bringWindowToFront(e),n.style.right="unset",n.style.bottom="unset",n.style.left=`${s}px`,n.style.top=`${t}px`,n.classList.add("dragging"),l.addEventListener("mousemove",h)}),n.addEventListener("mouseup",c=>{c.preventDefault(),l.removeEventListener("mousemove",h),n.classList.remove("dragging")}),n.addEventListener("mouseout",c=>{c.preventDefault(),l.removeEventListener("mousemove",h),n.classList.remove("dragging")})}}const q=200;let m,P,X=!1,R=-1,A=!1,Q;function ee(){return A}function Ve(){return Q}function Je(){return A?document.querySelector("#search").value:null}function _e(){return X}function Ye(){return R}function Ke(){X=!1,R=-1,m.setHoverSatellite(R)}function O(r){const e=document.querySelector("#search-results");e&&(r?e.style.display="block":e.style.display="none",A=r)}function Ze(){O(!ee())}function Xe(){O(!0)}function te(){O(!1);const r=m.getSatelliteGroups();r&&r.clearSelect()}function se(r,e){const t=document.querySelector("#search-results"),s=m.getSatelliteStore();if(!s)return;let i="";for(let a=0;a`,r[a].isIntlDes?i+=n.OBJECT_NAME:(i+=n.OBJECT_NAME.substring(0,r[a].strIndex),i+='',i+=n.OBJECT_NAME.substring(r[a].strIndex,r[a].strIndex+e.length),i+="",i+=n.OBJECT_NAME.substring(r[a].strIndex+e.length)),i+='
',r[a].isIntlDes?(i+=n.intlDes.substring(0,r[a].strIndex),i+='',i+=n.intlDes.substring(r[a].strIndex,r[a].strIndex+e.length),i+="",i+=n.intlDes.substring(r[a].strIndex+e.length)):i+=n.intlDes,i+="
"}t.innerHTML=i,t.style.display="block",A=!0}function Qe(){const r=document.querySelector("#search-results");r&&(r.innerHTML="")}function W(r){var l;const e=m.getSatelliteStore();if(!e)return;const t=e.getSatData();if(m.setSelectedSatellite(-1),r.length===0){te();return}r=r.toUpperCase();const s=[];for(let h=0;hq&&(s.length=q);const i=[];for(let h=0;h{const a=s.target.dataset.satId;Ke(),m.setSelectedSatellite(a)}),(e=document.querySelector("#search"))==null||e.addEventListener("input",()=>{var i;const s=(i=document.querySelector("#search"))==null?void 0:i.value;W(s)}),(t=document.querySelector("#all-objects-link"))==null||t.addEventListener("click",()=>{const s=m.getSelectedSatellite();if(s){const a=s.intlDes.slice(0,8);W(a),document.querySelector("#search").value=a,P&&P.openWindow("search-window")}}))}function tt(r,e){m=r,P=e,et()}const y={init:tt,clearResults:Qe,getHoverSat:Ye,isHovering:_e,showResults:Xe,hideResults:te,doSearch:W,getCurrentSearch:Je,getLastResultGroup:Ve,fillResultBox:se,isResultBoxOpen:ee,setResultsVisible:O,toggleResultsVisible:Ze},st=[],S=new Ne,it=[];let H=!1,d;function rt(r){var t;let e=document.querySelector(".attribution");if(e||(e=document.createElement("div"),e.className="attribution",(t=document.querySelector("body"))==null||t.appendChild(e)),e)if(r){const s=d.getSatelliteStore();if(s&&s.getAttribution()){const i=s.getAttribution()||{},a=s.getUpdatedDate();e.innerHTML=`Orbital object data from ${i.name} (updated ${a})`}e.classList.remove("hidden")}else e.classList.add("hidden")}function ie(r){var e,t;r?(e=document.querySelector("body"))==null||e.classList.add("loading"):(t=document.querySelector("body"))==null||t.classList.remove("loading")}function ot(){const r=document.querySelector("#groups-display"),e=d.getSatelliteGroups();let t=[];e&&(t=e.asArray().sort((i,a)=>i.name.localeCompare(a.name)));let s="";for(let i=0;i${t[i].name} +`;r.innerHTML=s}function p(r,e){const t=document.querySelector(r);t&&(t.innerHTML=e)}function at(r){var e,t,s,i,a;r?((e=document.querySelector("#sat-infobox"))==null||e.classList.add("visible"),p("#sat-info-title",r.OBJECT_NAME),p("#sat-intl-des",r.intlDes),p("#sat-type",r.OBJECT_TYPE),p("#sat-apogee",`${(t=r.apogee)==null?void 0:t.toFixed(0)} km`),p("#sat-perigee",`${(s=r.perigee)==null?void 0:s.toFixed(0)} km`),p("#sat-inclination",`${(r.inclination*Ue).toFixed(2)}°`),p("#sat-period",`${(i=r.period)==null?void 0:i.toFixed(2)} min`)):(a=document.querySelector("#sat-infobox"))==null||a.classList.remove("visible")}function nt(){var e;(e=document.querySelector("#groups-display"))==null||e.addEventListener("mouseout",()=>{if(!H){const t=d.getSatelliteGroups();t&&(y.isResultBoxOpen()?t.selectGroup(y.getLastResultGroup()):t.clearSelect())}});const r=document.querySelectorAll("#groups-display>li");for(let t=0;t{const n=i.currentTarget.dataset.group,l=d.getSatelliteGroups();l&&l.selectGroup(l.getGroupById(n))}),s.addEventListener("mouseout",()=>{const i=d.getSatelliteGroups();if(i){const a=document.querySelector("#groups-display>li.selected");a?i.selectGroup(i.getGroupById(a.dataset.group)):i.selectGroup(void 0)}}),s.addEventListener("click",i=>{i.preventDefault();const a=i.currentTarget;H=!0;const n=document.querySelector("#groups-display>li.selected");let l;n&&(l=n.dataset.group);for(let b=0;b{s.preventDefault(),d.zoomIn()}),(t=document.querySelector("#zoom-out"))==null||t.addEventListener("click",s=>{s.preventDefault(),d.zoomOut()}),window.addEventListener("resize",()=>{it.forEach(s=>{window.visualViewport&&(s.offsetLeft+s.offsetWidth>window.visualViewport.width&&(s.style.right="unset",s.style.left=`${window.visualViewport.width-s.offsetWidth}px`),s.offsetTop+s.offsetHeight>window.visualViewport.height&&(s.style.bottom="unset",s.style.offsetTop=`${window.visualViewport.height-s.offsetHeight}px`))})}),ie(!1)}function ht(r){r.satId&&(p("#sat-altitude",`${r.altitude.toFixed(2)} km`),p("#sat-velocity",`${r.velocity.toFixed(2)} km/s`))}function N(){lt(),ot(),setTimeout(()=>nt(),0);const r=document.querySelector("#load-cover");r&&r.classList.add("hidden"),rt(!0)}function ct(){return st}function dt(){const r=document.querySelectorAll(".menu-item");for(let e=0;e{const s=t.dataset.action;if(s&&s.startsWith("open:")){const i=s.split(":");S.openWindow(i[1])}})}}function ut(){return y.getCurrentSearch()}function ft(r){d=r,S.registerWindow("sat-infobox"),S.registerWindow("about-window"),S.registerWindow("help-window"),S.registerWindow("groups-window"),S.registerWindow("search-window"),y.init(d,S),dt(),d.addEventListener(I.satMovementChange,ht),d.ready?N():d.addEventListener(I.satDataLoaded,N)}const gt={setLoading:ie,init:ft,getSupportedEvents:ct,getCurrentSearch:ut};async function pt(){const r=await z.get("config.json");let e=U;return r.data&&(e={...U,...r.data}),e}async function mt(){const r=await pt();_(r.logLevel);const e=je(r);await e.init(),e.animate(),gt.init(e)}document.addEventListener("DOMContentLoaded",()=>{mt().catch(r=>console.error(r))}); diff --git a/assets/index-a58a40e6.js b/assets/index-a58a40e6.js deleted file mode 100644 index f283bfe..0000000 --- a/assets/index-a58a40e6.js +++ /dev/null @@ -1,4 +0,0 @@ -var re=Object.defineProperty;var oe=(r,e,t)=>e in r?re(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var o=(r,e,t)=>(oe(r,typeof e!="symbol"?e+"":e,t),t);import{T as w,S as E,M as F,a as G,U as ae,b as V,B as ne,A as le,G as B,C as $,D as he,P as ce,F as f,c as J,d as de,e as ue,O as ge,f as fe,L as pe,g as me,h as Se,i as z,V as we,j as ye,k as ve,l as be,W as xe,m as Le,R as De}from"./vendor-e5c7e806.js";(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))s(i);new MutationObserver(i=>{for(const a of i)if(a.type==="childList")for(const n of a.addedNodes)n.tagName==="LINK"&&n.rel==="modulepreload"&&s(n)}).observe(document,{childList:!0,subtree:!0});function t(i){const a={};return i.integrity&&(a.integrity=i.integrity),i.referrerPolicy&&(a.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?a.credentials="include":i.crossOrigin==="anonymous"?a.credentials="omit":a.credentials="same-origin",a}function s(i){if(i.ep)return;i.ep=!0;const a=t(i);fetch(i.href,a)}})();class Ee{constructor(){o(this,"baseUrl","");o(this,"basePath","/StuffInSpace/images");o(this,"radiusInKm",6371);o(this,"pxToRadius",3185.5);o(this,"addAtmosphere",!1);o(this,"addClouds",!0);o(this,"sphere");o(this,"group")}initClouds(e,t){const s=new w().load(`${this.basePath}/Earth_Cloud.jpg`),i=e.km2pixels(this.radiusInKm+.02),a=new E(i,32,32),n=new F({map:s,opacity:.3,transparent:!0}),l=new G(a,n),h=1.01;l.scale.set(h,h,h),t.add(l)}initAtmosphere(e,t){const s=["varying vec3 vNormal;","varying vec3 vPosition;","void main() {","vNormal = normalize( normalMatrix * normal );","gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );","vPosition = gl_Position.xyz;","}"].join(` -`),i=["varying vec3 vNormal;","varying vec3 vPosition;","void main() {"," float intensity = pow( 0.8 + dot( vNormal, vec3( 0, 0, 1.0 ) ), 12.0 );"," intensity = min(intensity, 1.7);"," gl_FragColor = vec4( 0.37, 0.71, 0.93, 0.6 ) * intensity;","}"].join(` -`),a=ae.clone({}),n=new V({uniforms:a,vertexShader:s,fragmentShader:i,side:ne,blending:le,transparent:!0}),l=e.km2pixels(this.radiusInKm+.1),h=new E(l,32,32),c=new G(h,n),g=1.019;c.scale.set(g,g,g),t.add(c)}init(e,t){t.config&&(this.baseUrl=t.config.baseUrl),this.group=new B;const s=`${this.baseUrl}/images`,i=new w().load(`${s}/earth-blue-marble.jpg`),a=new w().load(`${s}/nightearth-4096.png`),n=new w().load(`${s}/8081_earthbump4k.jpg`),l=new w().load(`${s}/earth-water.png`),h=new F({map:i,bumpMap:n,emissiveMap:a,emissive:new $(8947848),emissiveIntensity:5,specularMap:l,specular:1,shininess:15,bumpScale:1}),c=e.km2pixels(this.radiusInKm),g=new E(c,32,32);this.sphere=new G(g,h),this.group.add(this.sphere),this.addClouds&&this.initClouds(e,this.group),this.addAtmosphere&&this.initAtmosphere(e,this.group),e.add(this.group),this.sphere.geometry.computeBoundingBox(),this.sphere.geometry.computeBoundingSphere()}update(){}getMesh(){return this.sphere}}const T=class T{constructor(){o(this,"fastTime",!1);o(this,"showGeometry",!1);o(this,"lightSouce");o(this,"lightSourceGeometery");o(this,"hour",0);o(this,"objectGroup");o(this,"scene");o(this,"visible",!0)}degreesToReadians(e){return e*T.deg2RadMult}calculateSunLoc(){let t=this.hour;(t===void 0||t===-1)&&(t=he.utc().hour);const s=t/24*360+180;return{x:25*Math.cos(this.degreesToReadians(s)),z:25*Math.sin(this.degreesToReadians(s))}}init(e){this.fastTime?setInterval(()=>{this.hour+=.05},100):this.hour=-1,this.calculateSunLoc();const t=this.calculateSunLoc(),s={x:t.x,y:0,z:t.z};if(this.scene=e,this.objectGroup=new B,this.lightSouce=new ce(16777215,2e3),this.lightSouce.position.set(s.x,s.y,s.z),this.objectGroup.add(this.lightSouce),this.showGeometry){const i=new E(.1,32,32);this.lightSourceGeometery=new G(i),this.lightSourceGeometery.position.set(s.x,s.y,s.z),this.objectGroup.add(this.lightSourceGeometery)}e.add(this.objectGroup)}update(){}setVisible(e){var t,s;e?this.visible||(t=this.scene)==null||t.add(this.objectGroup):this.visible&&((s=this.scene)==null||s.remove(this.objectGroup)),this.visible=e}};o(T,"deg2RadMult",Math.PI/180);let M=T;class Ge{init(e){const t=new w().load("textures/example_render.jpg");e.background=t}update(){}}function Te(){return new Worker("/StuffInSpace/assets/SatCruncherWorker-37c21408.js")}const Ce="debug",x=["error","warn","info","debug"];let v={},L=new Proxy({logLevel:Ce,enabledOutputs:{},error:v.error,warn:v.warn,info:v.info,debug:v.debug,setLogLevel:_},{});function D(r,e,t,...s){r.enabledOutputs[e]&&t(e.toUpperCase(),...s)}function _(r){const e=x.indexOf(r.toLowerCase());if(e<0)throw new Error("Unknown log level");for(let t=0;t{let t=[1,1,0,1],s=!1;return e&&(s=!0,e.OBJECT_TYPE==="PAYLOAD"?t=[1,.2,0,1]:e.OBJECT_TYPE==="ROCKET BODY"?t=[.2,.5,1,.85]:e.OBJECT_TYPE==="DEBRIS"&&(t=[.5,.5,.5,.85])),{color:t,pickable:s}})}}class Me extends Y{constructor(){super("Group color scheme",(e,t)=>e&&t&&t.hasSat(e.id)?{color:[1,.2,0,1],pickable:!0}:{color:[1,1,1,.2],pickable:!0})}}class ke{constructor(){o(this,"baseUrl","");o(this,"worker");o(this,"currentColorScheme",new j);o(this,"numSats",1);o(this,"maxSize",0);o(this,"satPos",new Float32Array);o(this,"satVel",new Float32Array);o(this,"satAlt",new Float32Array);o(this,"satelliteColors",[]);o(this,"cruncherReady",!1);o(this,"scene");o(this,"particles");o(this,"geometry");o(this,"satelliteStore");o(this,"shaderStore");o(this,"selectedSatelliteIndexes",[]);o(this,"satelliteGroup");o(this,"hoverSatelliteIdx",-1)}setColorScheme(e){this.currentColorScheme=e}debugRaycastSelection(){if(this.satelliteStore&&(this.satelliteColors.length===0&&this.satelliteStore.satData.length>0&&(this.satelliteColors=new Array(this.satelliteStore.satData.length*4),this.satelliteColors.fill(1,0,this.satelliteColors.length),this.geometry&&this.geometry.setAttribute("color",new f(this.satelliteColors,4))),this.selectedSatelliteIndexes.length>0&&this.geometry)){for(let e=0;e0&&(e=this.geometry)!=null&&e.attributes){const t=this.satelliteStore.satData,s=t.length;this.updateSatellitesGeometry(),this.updateSatellitesMaterial(s,t)}this.debugRaycastSelection()}}updateSatellitesMaterial(e,t){var s,i,a;if((s=this.geometry)!=null&&s.attributes.color&&this.currentColorScheme&&this.satelliteStore){(this.satelliteColors.length===0||e*4!==this.satelliteColors.length)&&(this.satelliteColors=new Array(this.satelliteStore.satData.length*4),this.satelliteColors.fill(1,0,this.satelliteColors.length));for(let n=0;n{var c;(c=this.worker)==null||c.postMessage(JSON.stringify({state:{running:document.visibilityState==="visible"}}))})}getObject3D(){return this.particles}initSatWorker(e={}){u.info("Kicking off sat-cruncher-worker"),this.worker=new Te,this.worker.onmessage=this.onMessage.bind(this),this.worker.postMessage(JSON.stringify({config:e}))}async init(e,t){this.satelliteStore=t.satelliteStore,this.shaderStore=t.shaderStore,this.scene=e;const s=t.config||{};let i={};s.satWorker&&(i={...s.satWorker,logLevel:s.logLevel}),this.initSatWorker(i),t!=null&&t.config&&(this.baseUrl=t.config.baseUrl),this.satelliteStore&&(this.satelliteStore.addEventListener("satdataloaded",this.onSatDataLoaded.bind(this)),await this.satelliteStore.loadSatelliteData(),this.initGeometry(),this.satelliteStore.gotExtraData&&this.updateSatellites())}update(){}}function Ie(){return new Worker("/StuffInSpace/assets/OrbitCalculationWorker-dff8774f.js")}class Pe{constructor(){o(this,"config",{});o(this,"segmentCount",255);o(this,"orbitWorker");o(this,"selectedSatellites",[]);o(this,"hoverSatelliteIdx",-1);o(this,"satelliteGroups");o(this,"satelliteGroup");o(this,"inProgress",[]);o(this,"scene");o(this,"selectColor",[0,1,0,1]);o(this,"hoverColor",[1,.92,.23,1]);o(this,"groupColor",[.3,.5,1,.4]);o(this,"orbitTracks",[]);o(this,"satelliteStore");o(this,"satelliteOrbitGroup")}calculateOrbits(e){e=e.filter(t=>!this.inProgress[t]),this.orbitWorker?this.orbitWorker.postMessage(JSON.stringify({isInit:!1,satId:e})):u.error("Orbit worker is undefined"),e.forEach(t=>this.inProgress[t]=!0)}onSatellitesLoaded(){this.satelliteStore&&(this.inProgress=new Array(this.satelliteStore.size()),this.orbitTracks=new Array(this.satelliteStore.size()),this.orbitWorker&&this.orbitWorker.postMessage(JSON.stringify({isInit:!0,satData:this.satelliteStore.satData,numSegs:this.segmentCount})))}isTrackVisible(e){return this.selectedSatellites.indexOf(e)>-1||e===this.hoverSatelliteIdx||this.satelliteGroup&&this.satelliteGroup.hasSat(e)}getTrackColor(e){let t=[1,1,0];return e===this.hoverSatelliteIdx?t=this.hoverColor:this.selectedSatellites.indexOf(e)>-1?t=this.selectColor:this.satelliteGroup&&this.satelliteGroup.hasSat(e)&&(t=this.groupColor),new $(t[0],t[1],t[2])}addOrbitTrack(e,t){const s=this.getTrackColor(e),i=new pe({color:s,linewidth:10}),a=new J;a.setAttribute("position",new f(t,3));const n=new me(a,i);this.satelliteOrbitGroup&&this.satelliteOrbitGroup.add(n),this.orbitTracks[e]=n}updateOrbitTrack(e,t){const s=this.orbitTracks[e];if(s){const i=s.material;i.color=this.getTrackColor(e),i.needsUpdate=!0,t&&(s.geometry.setAttribute("position",new f(t,3)),s.geometry.computeBoundingBox(),s.geometry.computeBoundingSphere())}}removeOrbitTrack(e){var t;if(this.orbitTracks[e]){const s=this.orbitTracks[e];(t=this.satelliteOrbitGroup)==null||t.remove(s),s.geometry&&s.geometry.dispose(),this.orbitTracks[e]=void 0}}onMessage(e){const{satId:t}=e.data;this.scene&&(this.orbitTracks[t]?this.updateOrbitTrack(t,e.data.pointsOut):this.isTrackVisible(t)&&this.addOrbitTrack(t,e.data.pointsOut)),this.inProgress[t]=!1}isHoverSatellite(e){return this.hoverSatelliteIdx!==void 0&&e!==-1&&this.hoverSatelliteIdx===e}isSelectedSatellite(e){return this.selectedSatellites.length>0?this.selectedSatellites.indexOf(e)>-1:!1}refreshOrbits(){if(this.satelliteGroup){const e=this.satelliteGroup.sats;for(let t=0;t0)for(let t=0;t-1&&(t=this.selectedSatellites.indexOf(this.hoverSatelliteIdx)<0,t=t&&(!this.satelliteGroup||!this.satelliteGroup.hasSat(this.hoverSatelliteIdx))),this.hoverSatelliteIdx=e,t?this.removeOrbitTrack(s):this.updateOrbitTrack(s),this.calculateOrbits([e]),this.refreshOrbits()}setSatelliteGroup(e){if(this.satelliteGroup){this.setSelectedSatellites([]),this.setHoverSatellite(-1);for(let t=0;ti.satId);this.calculateOrbits(s)}}init(e,t){this.config=t.config,this.scene=e,this.orbitWorker=new Ie,this.orbitWorker.onmessage=this.onMessage.bind(this),this.satelliteStore=t.satelliteStore,this.orbitWorker.postMessage(JSON.stringify({config:{logLevel:this.config.logLevel}})),this.satelliteStore&&(this.satelliteStore.addEventListener("satdataloaded",this.onSatellitesLoaded.bind(this)),this.satelliteStore.size()>0&&(this.inProgress=new Array(this.satelliteStore.size()),this.onSatellitesLoaded())),t.satelliteGroups&&(this.satelliteGroups=t.satelliteGroups),this.satelliteOrbitGroup=new B,this.scene.add(this.satelliteOrbitGroup)}update(){}}const C=class C extends Se{constructor(){super();o(this,"pxToRadius",3185.5)}setPixels2Radius(t){this.pxToRadius=t}getPixels2Radius(){return this.pxToRadius}km2pixels(t){return t/this.pxToRadius}alitudeToPixels(t){return(C.earthRadiusInKm+t)/this.pxToRadius}};o(C,"earthRadiusInKm",6371);let k=C;class K{constructor(e,t,s,i,a){o(this,"sats",[]);o(this,"id");o(this,"name");o(this,"groupType");o(this,"data");o(this,"satelliteStore");if(this.id=e,this.name=t,this.groupType=s,this.data=i,this.satelliteStore=a,!this.satelliteStore)throw new Error("satelliteStore is required")}reload(){if(this.sats=[],this.groupType==="intlDes")for(let e=0;et.id===e)}hasSat(e){const t=this.sats.length;for(let s=0;s{i(t)})}}const We={baseUrl:"/StuffInSpace"};class Be{constructor(e={}){o(this,"tleUrl",`${We.baseUrl}/data/attributed-TLE.json`);o(this,"eventManager");o(this,"satData",[]);o(this,"attribution");o(this,"updateDate");o(this,"satelliteVelocities",new Float32Array);o(this,"satellitePositions",new Float32Array);o(this,"satelliteAltitudes",new Float32Array);o(this,"gotExtraData",!1);o(this,"gotPositionalData",!1);o(this,"loaded",!1);this.eventManager=new Z,e.tleUrl&&(this.tleUrl=e.tleUrl)}async loadSatelliteData(){try{const e=await z.get(this.tleUrl,{params:{t:Date.now()}});if(e.data){Array.isArray(e.data)?this.satData=e.data:(this.satData=e.data.data,this.attribution=e.data.source,this.updateDate=e.data.date);for(let t=0;t50?"19":"20")+s;const a=this.satData[t].INTLDES.substring(2);this.satData[t].intlDes=`${s}-${a}`}else this.satData[t].intlDes="unknown";this.satData[t].id=t}}this.eventManager.fireEvent("satdataloaded",this.satData),this.loaded=!0}catch(e){u.error("error loading TLE data",e)}}getAttribution(){return this.attribution}getUpdatedDate(){return this.updateDate}setSatelliteData(e,t=!1){this.satData=e,this.gotExtraData=t,t&&this.eventManager.fireEvent("satextradataloaded",this.satData)}setPositionalData(e,t,s){this.satelliteVelocities=e,this.satellitePositions=t,this.satelliteAltitudes=s,this.gotPositionalData=!0}getSatellitePosition(e){const t=e*3;if(this.satellitePositions&&tn[a]===e[a])}return s}searchName(e){const t=[];for(let s=0;s0){let l=a.filter(h=>h.object.type==="Points").map(h=>h.index);if(l.length>0){const h=[];for(let c=0;c0&&(i=s[0],a=(l=this.satelliteStore)==null?void 0:l.getSatellite(i)),(h=this.satellites)==null||h.setSelectedSatellite(i),(c=this.orbits)==null||c.setSelectedSatellite(i),this.eventManager.fireEvent("selectedSatChange",a)}onMouseMove(){this.mouseMoved=!0}onMouseDown(){this.mouseMoved=!1,window.addEventListener("mousemove",this.onMouseMove.bind(this))}onMouseUp(e){this.mouseMoved||this.onClick(e),this.mouseMoved=!1,window.removeEventListener("mousemove",this.onMouseMove.bind(this))}onHover(e){var n,l,h,c;const t=(n=this.renderer)==null?void 0:n.domElement;if(!this.raycaster||!this.scene||!this.camera||!t)return;const s=this.findSatellitesAtMouse({x:e.clientX,y:e.clientY});let i=-1,a;s&&s.length>0&&(i=s[0],a=(l=this.satelliteStore)==null?void 0:l.getSatellite(i)),(h=this.satellites)==null||h.setHoverSatellite(i),(c=this.orbits)==null||c.setHoverSatellite(i),this.eventManager.fireEvent("sathoverChange",a)}async init(){var e;try{this.scene=new k,this.camera=new be(45,window.innerWidth/window.innerHeight,.1,1e3),this.renderer=new xe({antialias:!0}),this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.setSize(window.innerWidth,window.innerHeight),(e=document.querySelector(this.config.canvasSelector))==null||e.appendChild(this.renderer.domElement),this.controls=new Le(this.camera,this.renderer.domElement),this.camera.position.set(15,0,-100),this.controls.update(),this.camera.position.y=5,this.camera.zoom=5,this.raycaster=new De,this.satelliteStore=new Be(this.config),this.satelliteGroups=new Re(this.config.satelliteGroups,this.satelliteStore),this.shaderStore=new $e(this.config.baseUrl),u.debug("loading shaders"),await this.shaderStore.load(),this.context.satelliteGroups=this.satelliteGroups,this.context.config=this.config,this.context.satelliteStore=this.satelliteStore,this.context.shaderStore=this.shaderStore,this.satelliteStore.addEventListener("satdataloaded",this.onSatDataLoaded.bind(this)),this.earth=new Ee,await this.registerSceneComponent("earth",this.earth),await this.registerSceneComponent("sun",new M),await this.registerSceneComponent("universe",new Ge),this.satellites=new ke,await this.registerSceneComponent("satellites",this.satellites),this.orbits=new Pe,await this.registerSceneComponent("orbits",this.orbits);const t=this.getCenterPoint(this.earth.getMesh());t&&(this.controls.target=t),this.camera.position.y=42,this.controls.minDistance=this.minZoom,this.controls.maxDistance=this.maxZoom,this.controls.enablePan=!1,this.controls.zoomSpeed=.5,this.camera.updateProjectionMatrix(),window.addEventListener("resize",this.onWindowResize.bind(this));const s=this.renderer.domElement;s.addEventListener("mousedown",this.onMouseDown.bind(this)),s.addEventListener("mouseup",this.onMouseUp.bind(this)),s.addEventListener("mousemove",this.onHover.bind(this))}catch(t){u.error("Error while initialising scene",t)}}animate(){requestAnimationFrame(this.animate.bind(this));for(let e=0;e{this.camera&&(this.camera.zoom>this.maxZoom||this.camera.zoom{this.camera&&(this.camera.zoome&&(this.camera.zoom=this.camera.zoom+-.08,this.camera.zoom<0&&(this.camera.zoom=0),this.camera.updateProjectionMatrix(),setTimeout(s,t)))};setTimeout(s,t)}}setHoverSatellite(e){var t,s;(t=this.satellites)==null||t.setHoverSatellite(e),(s=this.orbits)==null||s.setHoverSatellite(e)}setSelectedSatellite(e){var t,s;(t=this.satellites)==null||t.setSelectedSatellite(e),(s=this.orbits)==null||s.setSelectedSatellite(e)}setSelectedSatelliteGroup(e){var t,s,i;this.setSelectedSatellite(-1),(t=this.satelliteGroups)==null||t.selectGroup(e),(s=this.orbits)==null||s.setSatelliteGroup(e),(i=this.satellites)==null||i.setSatelliteGroup(e)}getSelectedSatellite(){if(this.satelliteStore)return this.satelliteStore.getSatellite(this.selectedSatelliteIdx)}getSelectedSatelliteIdx(){return this.selectedSatelliteIdx}addEventListener(e,t){this.eventManager.addEventListener(e,t)}}function Fe(r){return new ze(r)}const je="/StuffInSpace",U={appName:"Stuff in Space",baseUrl:je,propergateInterval:1e3,pushHistory:!1,logLevel:"debug",satWorker:{runOnce:!0},satelliteGroups:[{id:"GPSGroup",name:"GPS",groupType:"intlDes",data:["90103A","93068A","96041A","97035A","99055A","00025A","00040A","00071A","01004A","03005A","03010A","03058A","04009A","04023A","04045A","05038A","06042A","06052A","07047A","07062A","08012A","09043A","10022A","11036A","12053A","13023A","14008A","14026A","14045A","14068A","15013A"]},{id:"IridiumGroup",name:"Iridium Debris",groupType:"nameRegex",data:/IRIDIUM(?!.*DEB)/},{id:"Iridium33DebrisGroup",name:"Iridium 33 Debris",groupType:"nameRegex",data:/(COSMOS 2251|IRIDIUM 33) DEB/},{id:"GlonassGroup",name:"Glonass",groupType:"nameRegex",data:/GLONASS/},{id:"GalileoGroup",name:"Galileo",groupType:"nameRegex",data:/GALILEO/},{id:"FunGroup",name:"Fun",groupType:"nameRegex",data:/SYLDA/},{id:"WestfordNeedlesGroup",name:"Westford Needles",groupType:"nameRegex",data:/WESTFORD NEEDLES/},{id:"SpaceXGroup",name:"Space X",groupType:"nameRegex",data:/FALCON [19]/},{id:"DebrisGroup",name:"Debris",groupType:"objectType",data:"DEBRIS"},{id:"Starlink",name:"Starlink",groupType:"nameRegex",data:/STARLINK/},{id:"Unknown",name:"Unknown Objects",groupType:"objectType",data:"UNKNOWN"}]},Ue=80/Math.PI,I={satMovementChange:"satMovementChange",selectedSatChange:"selectedSatChange",satHover:"sathoverChange",satDataLoaded:"satdataloaded",closeWindow:"closeWindow",cruncherReady:"cruncherReady"};class qe{constructor(e,t={}){o(this,"element");o(this,"id");o(this,"options");o(this,"listeners",{});o(this,"firstOpen",!0);o(this,"windowManager");this.element=document.querySelector(`#${e}`),this.id=e,this.options=t,this.listeners={},this.firstOpen=!0,this.initEvents()}setWindowManager(e){this.windowManager=e}open(){this.element&&(this.firstOpen=!1,this.element.classList.add("active"),this.element.classList.add("visible"),this.element.classList.remove("hidden"),this.windowManager.bringWindowToFront(this))}close(){this.element&&(this.element.classList.remove("active"),this.element.classList.remove("visible"),this.element.classList.add("hidden"))}isOpen(){return this.element?this.element.classList.contains("visible"):!1}initEvents(){if(!this.element)return;const e=this.element.querySelector(".window-close");e&&e.addEventListener("click",()=>{this.close()})}moveTo(e,t){this.element&&(this.element.style.top=`${t}px`,this.element.style.left=`${e}px`)}getLocation(){if(!this.element)return{x:0,y:0};const e=this.element.style;return e.x?{x:e.x,y:e.y}:{x:this.element.offsetLeft,y:this.element.offsetTop}}addEventListener(e,t){if(this.listeners[e]||(this.listeners[e]=new Set),this.listeners[e])this.listeners[e].add(t);else throw new Error("unknown event")}fireEvent(e,t){this.listeners[e]&&this.listeners[e].forEach(i=>{i(t)})}}const He=100;class Ne{constructor(){o(this,"windows",[]);o(this,"windowsById",{});o(this,"initialOpen",!1)}bringWindowToFront(e){const t=e.element;let s=-1;for(let i=0;i-1&&(this.windows.splice(s,1),this.windows.push(e));for(let i=0;i=0;e--)if(this.windows[e].isOpen())return this.windows[e]}openWindow(e){const s={x:100,y:100},i=this.windowsById[e],a=this.getTopWindow();let n=!1;if(i){let{x:l,y:h}=i.getLocation();if(a||(l=s.x,h=s.y,this.initialOpen=!1),n=i.firstOpen,n&&a){const c=a.getLocation();c&&(l=c.x+42,h=c.y+42)}if(i.open(),!this.initialOpen&&!n){const c=i.getLocation();c&&(l=c.x,h=c.y)}(l>window.innerWidth||l<0)&&(l=s.x),(h>window.innerHeight||h<0)&&(h=s.y),this.bringWindowToFront(i),i.moveTo(l,h),this.initialOpen=!1}}closeWindow(e){const t=this.windowsById[e];t&&t.close()}makeDraggable(e){let t=0,s=0,i=0,a=0;const n=e.element;if(!n)return;const l=n.querySelector(".drag-zone")||n;function h(c){const g=`${t-(a-c.clientY)}px`,b=`${s-(i-c.clientX)}px`;n&&n.style&&(n.style.top=g,n.style.left=b)}n.classList.add("draggable"),n.addEventListener("click",()=>{this.bringWindowToFront(e)}),l.addEventListener("mousedown",c=>{c.preventDefault(),s=n.offsetLeft,t=n.offsetTop,i=c.clientX,a=c.clientY,this.bringWindowToFront(e),n.style.right="unset",n.style.bottom="unset",n.style.left=`${s}px`,n.style.top=`${t}px`,n.classList.add("dragging"),l.addEventListener("mousemove",h)}),n.addEventListener("mouseup",c=>{c.preventDefault(),l.removeEventListener("mousemove",h),n.classList.remove("dragging")}),n.addEventListener("mouseout",c=>{c.preventDefault(),l.removeEventListener("mousemove",h),n.classList.remove("dragging")})}}const q=200;let m,P,X=!1,R=-1,A=!1,Q;function ee(){return A}function Ve(){return Q}function Je(){return A?document.querySelector("#search").value:null}function _e(){return X}function Ye(){return R}function Ke(){X=!1,R=-1,m.setHoverSatellite(R)}function O(r){const e=document.querySelector("#search-results");e&&(r?e.style.display="block":e.style.display="none",A=r)}function Ze(){O(!ee())}function Xe(){O(!0)}function te(){O(!1);const r=m.getSatelliteGroups();r&&r.clearSelect()}function se(r,e){const t=document.querySelector("#search-results"),s=m.getSatelliteStore();if(!s)return;let i="";for(let a=0;a`,r[a].isIntlDes?i+=n.OBJECT_NAME:(i+=n.OBJECT_NAME.substring(0,r[a].strIndex),i+='',i+=n.OBJECT_NAME.substring(r[a].strIndex,r[a].strIndex+e.length),i+="",i+=n.OBJECT_NAME.substring(r[a].strIndex+e.length)),i+='
',r[a].isIntlDes?(i+=n.intlDes.substring(0,r[a].strIndex),i+='',i+=n.intlDes.substring(r[a].strIndex,r[a].strIndex+e.length),i+="",i+=n.intlDes.substring(r[a].strIndex+e.length)):i+=n.intlDes,i+="
"}t.innerHTML=i,t.style.display="block",A=!0}function Qe(){const r=document.querySelector("#search-results");r&&(r.innerHTML="")}function W(r){var l;const e=m.getSatelliteStore();if(!e)return;const t=e.getSatData();if(m.setSelectedSatellite(-1),r.length===0){te();return}r=r.toUpperCase();const s=[];for(let h=0;hq&&(s.length=q);const i=[];for(let h=0;h{const a=s.target.dataset.satId;Ke(),m.setSelectedSatellite(a)}),(e=document.querySelector("#search"))==null||e.addEventListener("input",()=>{var i;const s=(i=document.querySelector("#search"))==null?void 0:i.value;W(s)}),(t=document.querySelector("#all-objects-link"))==null||t.addEventListener("click",()=>{const s=m.getSelectedSatellite();if(s){const a=s.intlDes.slice(0,8);W(a),document.querySelector("#search").value=a,P&&P.openWindow("search-window")}}))}function tt(r,e){m=r,P=e,et()}const y={init:tt,clearResults:Qe,getHoverSat:Ye,isHovering:_e,showResults:Xe,hideResults:te,doSearch:W,getCurrentSearch:Je,getLastResultGroup:Ve,fillResultBox:se,isResultBoxOpen:ee,setResultsVisible:O,toggleResultsVisible:Ze},st=[],S=new Ne,it=[];let H=!1,d;function rt(r){var t;let e=document.querySelector(".attribution");if(e||(e=document.createElement("div"),e.className="attribution",(t=document.querySelector("body"))==null||t.appendChild(e)),e)if(r){const s=d.getSatelliteStore();if(s&&s.getAttribution()){const i=s.getAttribution()||{},a=s.getUpdatedDate();e.innerHTML=`Orbital object data from ${i.name} (updated ${a})`}e.classList.remove("hidden")}else e.classList.add("hidden")}function ie(r){var e,t;r?(e=document.querySelector("body"))==null||e.classList.add("loading"):(t=document.querySelector("body"))==null||t.classList.remove("loading")}function ot(){const r=document.querySelector("#groups-display"),e=d.getSatelliteGroups();let t=[];e&&(t=e.asArray().sort((i,a)=>i.name.localeCompare(a.name)));let s="";for(let i=0;i${t[i].name} -`;r.innerHTML=s}function p(r,e){const t=document.querySelector(r);t&&(t.innerHTML=e)}function at(r){var e,t,s,i,a;r?((e=document.querySelector("#sat-infobox"))==null||e.classList.add("visible"),p("#sat-info-title",r.OBJECT_NAME),p("#sat-intl-des",r.intlDes),p("#sat-type",r.OBJECT_TYPE),p("#sat-apogee",`${(t=r.apogee)==null?void 0:t.toFixed(0)} km`),p("#sat-perigee",`${(s=r.perigee)==null?void 0:s.toFixed(0)} km`),p("#sat-inclination",`${(r.inclination*Ue).toFixed(2)}°`),p("#sat-period",`${(i=r.period)==null?void 0:i.toFixed(2)} min`)):(a=document.querySelector("#sat-infobox"))==null||a.classList.remove("visible")}function nt(){var e;(e=document.querySelector("#groups-display"))==null||e.addEventListener("mouseout",()=>{if(!H){const t=d.getSatelliteGroups();t&&(y.isResultBoxOpen()?t.selectGroup(y.getLastResultGroup()):t.clearSelect())}});const r=document.querySelectorAll("#groups-display>li");for(let t=0;t{const n=i.currentTarget.dataset.group,l=d.getSatelliteGroups();l&&l.selectGroup(l.getGroupById(n))}),s.addEventListener("mouseout",()=>{const i=d.getSatelliteGroups();if(i){const a=document.querySelector("#groups-display>li.selected");a?i.selectGroup(i.getGroupById(a.dataset.group)):i.selectGroup(void 0)}}),s.addEventListener("click",i=>{i.preventDefault();const a=i.currentTarget;H=!0;const n=document.querySelector("#groups-display>li.selected");let l;n&&(l=n.dataset.group),console.dir(i.target);for(let b=0;b{s.preventDefault(),d.zoomIn()}),(t=document.querySelector("#zoom-out"))==null||t.addEventListener("click",s=>{s.preventDefault(),d.zoomOut()}),window.addEventListener("resize",()=>{it.forEach(s=>{window.visualViewport&&(s.offsetLeft+s.offsetWidth>window.visualViewport.width&&(s.style.right="unset",s.style.left=`${window.visualViewport.width-s.offsetWidth}px`),s.offsetTop+s.offsetHeight>window.visualViewport.height&&(s.style.bottom="unset",s.style.offsetTop=`${window.visualViewport.height-s.offsetHeight}px`))})}),ie(!1)}function ht(r){r.satId&&(p("#sat-altitude",`${r.altitude.toFixed(2)} km`),p("#sat-velocity",`${r.velocity.toFixed(2)} km/s`))}function N(){lt(),ot(),setTimeout(()=>nt(),0);const r=document.querySelector("#load-cover");r&&r.classList.add("hidden"),rt(!0)}function ct(){return st}function dt(){const r=document.querySelectorAll(".menu-item");for(let e=0;e{const s=t.dataset.action;if(s&&s.startsWith("open:")){const i=s.split(":");S.openWindow(i[1])}})}}function ut(){return y.getCurrentSearch()}function gt(r){d=r,S.registerWindow("sat-infobox"),S.registerWindow("about-window"),S.registerWindow("help-window"),S.registerWindow("groups-window"),S.registerWindow("search-window"),y.init(d,S),dt(),d.addEventListener(I.satMovementChange,ht),d.ready?N():d.addEventListener(I.satDataLoaded,N)}const ft={setLoading:ie,init:gt,getSupportedEvents:ct,getCurrentSearch:ut};async function pt(){const r=await z.get("config.json");let e=U;return r.data&&(e={...U,...r.data}),e}async function mt(){const r=await pt();_(r.logLevel);const e=Fe(r);await e.init(),e.animate(),ft.init(e)}document.addEventListener("DOMContentLoaded",()=>{mt().catch(r=>console.error(r))}); diff --git a/index.html b/index.html index 9278d5e..705f599 100644 --- a/index.html +++ b/index.html @@ -28,7 +28,7 @@ Stuff in Space - +