@rr0/ufoathome 0.19.1 → 0.19.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5034,7 +5034,7 @@ void main()
5034
5034
 
5035
5035
  gl_FragColor = vec4(finalColor, max(dazzleAlpha, artifactsAlpha));
5036
5036
  }
5037
- `;let Wr;function _x(){if(Wr)return Wr;const i=256,e=document.createElement("canvas");e.width=i,e.height=i;const t=e.getContext("2d");t.fillStyle="rgba(60,60,60,1)",t.fillRect(0,0,i,i);const n=[[.3,.35,.22,.5],[.7,.6,.16,.35],[.55,.8,.3,.4],[.15,.7,.12,.3],[.85,.2,.18,.3]];for(const[s,r,a,o]of n){const l=t.createRadialGradient(s*i,r*i,0,s*i,r*i,a*i);l.addColorStop(0,`rgba(200,200,200,${o})`),l.addColorStop(1,"rgba(200,200,200,0)"),t.fillStyle=l,t.fillRect(0,0,i,i)}return Wr=new Wn(e),Wr}function vx(){const i={uTime:{value:0},uResolution:{value:new Ue(1,1)},uLensPosition:{value:new Ue(0,0)},uColorGain:{value:new Me(55,55,51)},uOpacity:{value:.5},uFlareIntensity:{value:0},uStarPoints:{value:6},uGlareSize:{value:.55},uFlareSize:{value:.0025},uFlareSpeed:{value:.4},uFlareShape:{value:1.2},uHaloScale:{value:.5},uGhostScale:{value:.3},uAnimated:{value:!1},uAnamorphic:{value:!1},uSecondaryGhosts:{value:!0},uStarBurst:{value:!0},uAdditionalStreaks:{value:!0},uLensDirtTexture:{value:_x()}},e=new Gt({uniforms:i,vertexShader:mx,fragmentShader:gx,transparent:!0,depthWrite:!1,depthTest:!1,blending:ra,fog:!1,name:"LensFlareShader"}),t=new Mt(new tr(2,2),e);return t.frustumCulled=!1,t.renderOrder=20,{mesh:t,uniforms:i}}const xx=2;function Mx(i){return i==="building"||i==="vehicle"}function Sx(i,e){const t=i.litKeyframes;if(!t||t.length===0)return i.lit??!1;let n=t[0];for(const s of t){if(s.t>e)break;n=s}return n.lit}const hu=Math.PI/180;function nn(i,e,t,n,s=!1){const r=s?new js({color:new Me(...t)}):new nr({color:new Me(...t)}),a=new Mt(e,r);return a.position.y=n,a.userData={emissive:s},a.castShadow=!s,a.receiveShadow=!s,i.add(a),a}const X0=[.32,.32,.3],q0=[1,.85,.5],Y0=[.25,.25,.25],Z0=[1,.97,.85],yx=[.55,.68,.72],vn=.03,xn=.05,$0={front:0,behind:Math.PI,left:Math.PI/2,right:-Math.PI/2,"front-left":Math.PI/2,"behind-left":Math.PI/2,"front-right":-Math.PI/2,"behind-right":-Math.PI/2};function kt(i,e){return i?.[e]}function Mn(i,e,t,n,s,r,a,o){if(o===void 0)return;const l=new nr({color:new Me(...yx),transparent:!0,opacity:o/100}),c=new Mt(new Cn(e,t,n),l);c.position.set(s,r,a),i.add(c)}const Qt=.05,vo=[.6,.58,.53],uu=[.5,.5,.48];function ls(i,e,t,n,s,r,a,o){const l=new nr({color:new Me(...o),side:It}),c=new Mt(new Cn(e,t,n),l);c.position.set(s,r,a),i.add(c)}function Ex(i,e,t,n,s,r,a,o,l){const c=(n-r)/2,h=(g,x,m,f)=>{g<=0||(e?ls(i,g,x,Qt,m,o+f,a,l):ls(i,Qt,x,g,a,o+f,m,l))};h(t,c,0,n/2-c/2),h(t,c,0,-(n/2-c/2));const d=[...s].sort((g,x)=>g.center-x.center);let u=-t/2;for(const g of d){const m=g.center-g.main/2-u;h(m,r,u+m/2,0),u=g.center+g.main/2}const p=t/2-u;h(p,r,u+p/2,0)}function K0(i,e,t,n,s,r,a,o,l,c){const h=(n+s)/2,d=s-n,u=(p,g,x,m)=>{p.length===0?g?ls(i,x,d,Qt,0,h,m,vo):ls(i,Qt,d,x,m,h,0,vo):Ex(i,g,x,d,p,r,m,h,vo)};u(a,!0,e*2,-t+Qt),u(o,!0,e*2,t-Qt),u(l,!1,t*2,-e+Qt),u(c,!1,t*2,e-Qt),ls(i,e*2,Qt,t*2,0,n+Qt,0,uu),ls(i,e*2,Qt,t*2,0,s-Qt,0,uu)}function ql(i,e,t,n){switch(i){case"front":return{x:0,z:-(t-n)};case"behind":return{x:0,z:t-n};case"left":return{x:-(e-n),z:0};case"right":return{x:e-n,z:0};case"front-left":return{x:-(e-n),z:-Sn};case"front-right":return{x:e-n,z:-Sn};case"behind-left":return{x:-(e-n),z:Sn};case"behind-right":return{x:e-n,z:Sn}}}function J0(i,e,t,n,s,r,a){const o=ed();o.scale.setScalar(n),o.rotation.y=$0[e];const{x:l,z:c}=ql(e,s,r,a);o.position.set(l,t,c),i.add(o)}const Yl=6,Zl=6,ii=3,Us=1.4,Fs=ii*.5,Q0=1.2,j0=.35,bx=.75,Tx=1.6;function Ax(i,e,t,n){const s=new Tn,r=Math.max(1,i+1),a=r*ii;nn(s,new Cn(Yl,a,Zl),[.55,.54,.5],a/2);const o=Yl/2,l=Zl/2;for(let c=0;c<r;c++){const h=c*ii+ii/2;Mn(s,Us,Fs,xn,0,h,-l-vn,kt(e,"front")),Mn(s,Us,Fs,xn,0,h,l+vn,kt(e,"behind")),Mn(s,xn,Fs,Us,-o-vn,h,0,kt(e,"left")),Mn(s,xn,Fs,Us,o+vn,h,0,kt(e,"right"))}if(t){const c=Math.min(Math.max(n??0,0),r-1);J0(s,t,c*ii,.72,o,l,Q0);const h=d=>kt(e,d)!==void 0?[{main:Us,center:0}]:[];K0(s,o,l,c*ii,(c+1)*ii,Fs,h("front"),h("behind"),h("left"),h("right"))}return s}function wx(){const i=new Tn;return nn(i,new Di(.15,.22,2,8),[.32,.22,.14],1),nn(i,new Ea(1.4,3,8),[.16,.32,.14],3.5),i}function Rx(i){const e=new Tn;return nn(e,new Di(.05,.08,5,8),[.28,.28,.3],2.5),nn(e,new ui(.25,12,8),i?q0:X0,5.1,!0),e}const Cx=[.08,.08,.08],ni=.8,ss=1,gn=1.7,xo=.6,_i=.4,Xr=1.2,ts=.7,Sn=.5,Px=gn;function Ix(i,e,t){const n=new Tn;nn(n,new Cn(1.8,1.4,4.2),[.45,.14,.14],.7),nn(n,new Cn(ni*2,xo,ss*2),[.4,.12,.12],gn);for(const r of[-1.4,1.4])for(const a of[-.95,.95]){const o=nn(n,new Di(.4,.4,.3,12),Cx,.4);o.rotation.z=Math.PI/2,o.position.x=a,o.position.z=r}const s=i?Z0:Y0;for(const r of[-.7,.7])nn(n,new ui(.15,8,6),s,.7,!0).position.set(r,.7,-2.1);if(Mn(n,Xr,_i,xn,0,gn,-ss-vn,kt(e,"front")),Mn(n,Xr,_i,xn,0,gn,ss+vn,kt(e,"behind")),Mn(n,xn,_i,ts,-ni-vn,gn,-Sn,kt(e,"front-left")),Mn(n,xn,_i,ts,-ni-vn,gn,Sn,kt(e,"behind-left")),Mn(n,xn,_i,ts,ni+vn,gn,-Sn,kt(e,"front-right")),Mn(n,xn,_i,ts,ni+vn,gn,Sn,kt(e,"behind-right")),t){J0(n,t,bx,.5,ni,ss,j0);const r=(l,c)=>{const h=[];return kt(e,l)!==void 0&&h.push({main:ts,center:-Sn}),kt(e,c)!==void 0&&h.push({main:ts,center:Sn}),h},a=kt(e,"front")!==void 0?[{main:Xr,center:0}]:[],o=kt(e,"behind")!==void 0?[{main:Xr,center:0}]:[];K0(n,ni,ss,gn-xo/2,gn+xo/2,_i,a,o,r("front-left","behind-left"),r("front-right","behind-right"))}return n}const Dx=[.95,.9,.82];function ed(){const i=new Tn;nn(i,new Di(.25,.3,1.5,10),[.3,.3,.35],.75),nn(i,new ui(.22,10,8),[.62,.52,.46],1.72);const e=nn(i,new Ea(.07,.16,8),Dx,1.72);return e.rotation.x=-Math.PI/2,e.position.z=-.2,i}class Os{static occupantView(e){const t=e.witnessSide;if(!t)throw new Error("occupantView requires object.witnessSide to be set");const{x:n,z:s}=e.kind==="vehicle"?ql(t,ni,ss,j0):ql(t,Yl/2,Zl/2,Q0),r=e.kind==="vehicle"?Px:(e.occupiedFloor??0)*ii+Tx,a=(e.headingDeg??0)-$0[t]/hu;return{x:n,z:s,eyeY:r,headingDeg:a}}static build(e,t){const n=e.kind==="building"?Ax(e.floors??xx,e.windows,e.witnessSide,e.occupiedFloor):e.kind==="tree"?wx():e.kind==="streetlight"?Rx(t):e.kind==="vehicle"?Ix(t,e.windows,e.witnessSide):ed();return e.headingDeg!==void 0&&(n.rotation.y=-e.headingDeg*hu),n}static setLit(e,t,n){const s=t==="streetlight"?n?q0:X0:n?Z0:Y0;for(const r of e.children)!(r instanceof Mt)||!r.userData.emissive||r.material.color.setRGB(...s)}static dispose(e){for(const t of e.children)t instanceof Mt&&(t.geometry.dispose(),t.material.dispose())}}function Lx(i,e){return i.cloudCover===e.cloudCover&&i.cloudDarkness===e.cloudDarkness&&i.cloudBaseM===e.cloudBaseM&&i.precipitationType===e.precipitationType&&i.precipitationIntensity===e.precipitationIntensity&&i.windDirectionDeg===e.windDirectionDeg&&i.windSpeed===e.windSpeed&&i.storm===e.storm}const Mo=900,Nx=.5,Ws=900,Ux=6371e3,Fx=3e4;function du(i){const e=Math.sqrt(2*Ux*Math.max(i,0));return Math.max(Ws,Math.min(e,Fx))}const So=.5,Ox=850,yo=850,Eo=4,Bx=1.5,zx=-1,kx=6,$l=-4,fu=$l,Gx=3,Hx=.15,Vx=.6,Wx=40,Xx=30,qx=[0,45,90,135,180,225,270,315],Yx={en:["N","NE","E","SE","S","SW","W","NW"],fr:["N","NE","E","SE","S","SO","O","NO"]},Zx=["en","fr"],$x=880,pu=40,Kx=10,Jx=1,Qx=150,bo=55,mu=.5,jx=700,e3=250/Po,t3=12,n3=.5,i3=5,To=6,ns=[.92,.92,.95],Ao=[.15,.15,.19],gu={snow:{fallSpeedMPerS:2,size:.3,color:new Me(1,1,1),driftSensitivity:1,radiusM:25,topYM:20,opacity:.75,poolSize:2400},hail:{fallSpeedMPerS:14,size:.5,color:new Me(.95,.98,1),driftSensitivity:.25,radiusM:25,topYM:10,opacity:.95,poolSize:1200}},rs=0,s3=0,_u=3e3,Bs=20,r3=15,vu=rs,a3=40,xu=1,o3=9;function l3(i){return xu+(o3-xu)*i}const c3=new Me(.75,.82,.92),h3=10,u3=.5;function d3(i){return td(i/h3,u3,1)}const is=200,Mu=.18,Su=.32,f3=.35,p3=new Me(.85,.9,.98),yu=5,Eu=.85,bu=.01;function wo(i,e){return Math.round(i*(bu+(1-bu)*e))}const Tu=230,Au=.7,wu=.05,m3=.6,g3=.7,_3=.15,Ru=.35,v3=3,x3=1/12,M3=.5,Cu=8,Pu=25,Iu=.12,S3={Venus:new Me(1,.96,.85),Mars:new Me(1,.55,.4),Jupiter:new Me(.95,.87,.72),Saturn:new Me(.92,.86,.68)};class y3{renderer;scene=new Zf;camera;celestialGroup=new Tn;skyMesh;groundMesh;terrainMesh;terrainProviders;terrainOrigin;terrainBuildToken=0;terrainAttribution;starTiers=[];bodyMeshes=new Map;hitAreas=new Map;glareSprites=new Map;decorObjects=[];decorGroups=new Map;celestialLight=new _p(16777215,0);celestialLightTarget=new St;skyLight=new fp(16777215,0,0);streetlightLights=new Map;compassSprites=[];showCompass=!1;compassHovered=!1;compassForced=!1;animationFrameId=null;raycaster=new ro;weather=Nu;observerElevationM=0;groundRadius=Ws;terrainRadius=Ws;cloudMesh;cloudMaterial;cloudUniforms;precipitationPoints;precipitationPositions;precipitationPhase;precipitationSpeedJitter;precipitationWobbleFreqJitter;precipitationWobbleAmpJitter;precipitationBounceRemaining;precipitationBounceHeight;precipitationBounceDuration;precipitationBounceVelX;precipitationBounceVelZ;precipitationUniforms;rainSystem;rainSplashSystem;rainCameraDirection=new U;rainLastVerticalFacing=-1;lightningArmed=!1;nextLightningAtS=null;lightningFlashRemainingS=0;baseFogColor=[0,0,0];lastSunPosition;lensFlare;dazzleIntensity=1;lensFlareArtifactIntensity=0;sunWorldPosition=new U;sunVisible=!1;lensFlareScratch=new U;sunOcclusionRaycaster=new ro;sunOcclusionDirectionScratch=new U;ufoOcclusionRaycaster=new ro;onLightningFlash;constructor(e,t=Z2(),n){this.renderer=new mv({canvas:e,antialias:!0}),this.renderer.setPixelRatio(Math.min(window.devicePixelRatio||1,2)),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=Xs,this.camera=new Yt(60,e.width/Math.max(e.height,1),.1,Mo*1.2),this.camera.position.set(0,1.6,0),this.terrainProviders=t,this.onLightningFlash=n,this.celestialLight.shadow.mapSize.set(1024,1024),this.celestialLight.shadow.camera.left=-120,this.celestialLight.shadow.camera.right=120,this.celestialLight.shadow.camera.top=120,this.celestialLight.shadow.camera.bottom=-120,this.celestialLight.shadow.camera.near=1,this.celestialLight.shadow.camera.far=1e3,this.celestialLight.shadow.bias=-.0015,this.celestialLight.target=this.celestialLightTarget,this.scene.add(this.celestialLight,this.celestialLightTarget,this.skyLight),this.scene.add(this.celestialGroup)}get currentTerrainAttribution(){return this.terrainAttribution}resize(e,t){this.renderer.setSize(e,t,!1),this.camera.aspect=e/Math.max(t,1),this.camera.updateProjectionMatrix(),this.render()}setObserverPose(e){e.headingDeg!==void 0?this.camera.rotation.set(e.pitchDeg*mn,-e.headingDeg*mn,0,"YXZ"):this.camera.rotation.set(e.pitchDeg*mn,this.camera.rotation.y,0,"YXZ"),e.elevationM!==this.observerElevationM&&(this.observerElevationM=e.elevationM,this.syncCloudLayer(),Math.abs(du(e.elevationM)-this.groundRadius)>1&&(this.buildGround(),this.celestialGroup.scale.setScalar(this.groundRadius/Ws),this.camera.far=Math.max(Mo*1.2,this.groundRadius*2.5),this.camera.updateProjectionMatrix())),this.camera.position.y=1.6+e.elevationM,this.celestialGroup.position.y=this.camera.position.y,this.camera.fov!==e.fovDeg&&(this.camera.fov=e.fovDeg,this.camera.updateProjectionMatrix())}setTerrainProviders(e){this.terrainProviders=e,this.disposeMesh(this.terrainMesh),this.terrainMesh=void 0,this.terrainOrigin=void 0,this.terrainAttribution=void 0,this.terrainBuildToken++}setTerrainOrigin(e,t,n){if(e===void 0||t===void 0)return;const s=this.groundRadius;if(this.terrainOrigin&&Math.abs(this.terrainRadius-s)<s*.1){const{x:a,z:o}=Ci(e,t,this.terrainOrigin.lat,this.terrainOrigin.lng);if(Math.sqrt(a*a+o*o)<Qx*(s/Ws))return}this.terrainOrigin={lat:e,lng:t},this.terrainRadius=s;const r=++this.terrainBuildToken;ex(e,t,this.terrainProviders,s).then(({mesh:a,attribution:o})=>{r===this.terrainBuildToken&&(this.disposeMesh(this.terrainMesh),a.renderOrder=Jx,this.terrainMesh=a,this.terrainAttribution=o,this.scene.add(a),this.render(),n?.())}).catch(a=>{console.warn("Terrain build failed, keeping the flat ground fallback:",a),n?.()})}setShowCompass(e){this.showCompass!==e&&(this.showCompass=e,this.disposeCompassLabels(),e&&this.buildCompassLabels(),this.render())}setDazzleIntensity(e){this.dazzleIntensity!==e&&(this.dazzleIntensity=e,this.lensFlare&&(this.lensFlare.uniforms.uOpacity.value=mu*e,this.lastSunPosition&&this.applyLensFlareTint(Ls(this.lastSunPosition.altitudeDeg))),this.render())}setLensFlareArtifactIntensity(e){this.lensFlareArtifactIntensity!==e&&(this.lensFlareArtifactIntensity=e,this.lensFlare&&(this.lensFlare.uniforms.uFlareIntensity.value=e),this.render())}applyLensFlareTint(e){this.lensFlare&&this.lensFlare.uniforms.uColorGain.value.setRGB(bo*this.dazzleIntensity*e[0],bo*this.dazzleIntensity*e[1],bo*this.dazzleIntensity*e[2])}setCompassHovered(e){this.compassHovered!==e&&(this.compassHovered=e,this.updateCompassVisibility())}setCompassForced(e){this.compassForced!==e&&(this.compassForced=e,this.updateCompassVisibility())}updateCompassVisibility(){const e=this.compassHovered||this.compassForced;for(const t of this.compassSprites)t.visible=e;this.render()}setWeather(e){Lx(this.weather,e)||(this.weather=e,this.buildClouds(),this.buildPrecipitation(),this.lightningArmed=e.storm&&e.cloudDarkness>=M3,this.lightningArmed||(this.nextLightningAtS=null,this.lightningFlashRemainingS=0,this.scene.fog&&this.scene.fog.color.setRGB(...this.baseFogColor)),this.syncAnimationLoop(),this.render())}setDecor(e){if(this.decorObjects!==e){this.decorObjects=e;for(const t of this.decorGroups.values())t.removeFromParent(),Os.dispose(t);this.decorGroups.clear(),this.streetlightLights.clear();for(const t of e){const n=Os.build(t,t.lit??!1);this.scene.add(n),this.decorGroups.set(t.id,n),t.kind==="streetlight"&&this.addStreetlightLight(t.id,n)}this.celestialLight.castShadow=this.decorGroups.size>0}}updateDecorAnchoring(e,t){const n=e?.lat!==void 0&&e.lng!==void 0&&t?.lat!==void 0&&t?.lng!==void 0?Ci(e.lat,e.lng,t.lat,t.lng):{x:0,z:0},s=this.decorObjects.find(a=>a.witnessSide!==void 0&&Mx(a.kind)),r={x:0,z:0};if(s){const a=Os.occupantView(s),o=-(s.headingDeg??0)*mn,l=a.x*Math.cos(o)+a.z*Math.sin(o),c=-a.x*Math.sin(o)+a.z*Math.cos(o),h=s.eastM+n.x,d=-s.northM+n.z;r.x=-(h+l),r.z=-(d+c),this.camera.position.y=a.eyeY,this.camera.rotation.set(this.indoorLookPitchDeg*mn,-(a.headingDeg+this.indoorLookYawDeg)*mn,0,"YXZ")}for(const a of this.decorObjects){const o=this.decorGroups.get(a.id);o&&o.position.set(a.eastM+n.x+r.x,s3,-a.northM+n.z+r.z)}}indoorLookYawDeg=0;indoorLookPitchDeg=0;setIndoorLook(e,t){this.indoorLookYawDeg=e,this.indoorLookPitchDeg=t}updateDecorLitState(e){for(const t of this.decorObjects){if(t.kind!=="streetlight"&&t.kind!=="vehicle")continue;const n=this.decorGroups.get(t.id);if(!n)continue;const s=Sx(t,e);Os.setLit(n,t.kind,s);const r=this.streetlightLights.get(t.id);r&&(r.visible=s)}}addStreetlightLight(e,t){const n=t.children.find(r=>r.userData.emissive);if(!n)return;const s=new mp(16764006,Wx,Xx);s.position.copy(n.position),s.castShadow=!0,s.shadow.mapSize.set(512,512),s.shadow.bias=-.002,t.add(s),this.streetlightLights.set(e,s)}setAstronomy(e){const t=M0(e.sun.altitudeDeg),n=t.horizon;this.baseFogColor=n,this.lastSunPosition=e.sun,this.buildSky(e.sun),this.buildGround(),this.updateCloudLighting(e.sun,n),this.updateCelestialLight(e,t.zenith,n),this.buildStars(e.stars,e.sun.altitudeDeg),this.setBodyMesh("sun",e.sun,Eo,new Me(1,.96,.88),e.sun.magnitude),this.setMoonMesh(e.moon),this.buildPlanets(e.planets),this.scene.fog=new hc(new Me(...n),this.groundRadius*.2,this.groundRadius),this.syncAnimationLoop(),this.render()}updateCelestialLight(e,t,n){this.skyLight.color.setRGB(t[0],t[1],t[2]),this.skyLight.groundColor.setRGB(n[0],n[1],n[2]),this.skyLight.intensity=Vx;const s=e.sun.altitudeDeg>=fu,r=!s&&e.moon.altitudeDeg>=fu;if(!s&&!r){this.celestialLight.intensity=0;return}const a=s?e.sun:e.moon,{x:o,y:l,z:c}=ji(a.altitudeDeg,a.azimuthDeg,yo);this.celestialLight.position.set(o,l,c);const h=Ls(a.altitudeDeg);this.celestialLight.color.setRGB(h[0],h[1],h[2]);const d=Math.max(0,Math.sin(Math.max(a.altitudeDeg,0)*mn));this.celestialLight.intensity=(s?Gx:Hx)*d,this.celestialLight.castShadow=this.decorGroups.size>0}render(){this.updateLensFlarePosition(),this.renderer.render(this.scene,this.camera)}updateLensFlarePosition(){const e=this.lensFlare;if(!e)return;if(!this.sunVisible){e.mesh.visible=!1;return}if(this.camera.updateMatrixWorld(),this.lensFlareScratch.copy(this.sunWorldPosition).applyMatrix4(this.camera.matrixWorldInverse),this.lensFlareScratch.z>0){e.mesh.visible=!1;return}if(this.isSunOccluded()){e.mesh.visible=!1;return}e.mesh.visible=!0;const t=this.lensFlareScratch.copy(this.sunWorldPosition).project(this.camera);e.uniforms.uLensPosition.value.set(t.x,t.y),e.uniforms.uResolution.value.set(this.renderer.domElement.width,this.renderer.domElement.height)}isSunOccluded(){const e=[];this.groundMesh&&e.push(this.groundMesh),this.terrainMesh&&e.push(this.terrainMesh);for(const r of this.decorGroups.values())e.push(r);if(e.length===0)return!1;const t=this.sunOcclusionDirectionScratch.copy(this.sunWorldPosition).sub(this.camera.position),n=t.length();t.normalize(),this.sunOcclusionRaycaster.set(this.camera.position,t);const s=this.sunOcclusionRaycaster.intersectObjects(e,!0)[0];return s!==void 0&&s.distance<n}isScreenPointOccluded(e,t,n,s){if(this.isBehindCloudLayer(e,t,s))return!0;const r=[];for(const a of this.decorObjects){if(!a.occludesSourceIds?.includes(n))continue;const o=this.decorGroups.get(a.id);o&&r.push(o)}return r.length===0?!1:(this.ufoOcclusionRaycaster.setFromCamera(new Ue(e,t),this.camera),this.ufoOcclusionRaycaster.near=Nx,this.ufoOcclusionRaycaster.intersectObjects(r,!0).length>0)}isBehindCloudLayer(e,t,n){if(!n||!this.cloudMesh||this.weather.cloudCover<=0)return!1;if(n.declared)return!0;const s=n.distanceM;if(s===void 0)return!1;const r=this.cloudLayerOffset();this.ufoOcclusionRaycaster.setFromCamera(new Ue(e,t),this.camera);const a=this.ufoOcclusionRaycaster.ray.direction;return Math.sign(a.y||1)!==Math.sign(r)||Math.abs(this.cloudLayerHeightM())/Math.max(Math.abs(a.y),.026)>=s?!1:yt.alphaAt(a,Math.abs(r),this.weather.cloudCover)>=n3}cloudLayerHeightM(){return(this.weather.cloudBaseM??Po)-this.observerElevationM}pickBodyAt(e,t){this.raycaster.setFromCamera(new Ue(e,t),this.camera);const n=[...this.hitAreas.entries()],s=this.raycaster.intersectObjects(n.map(([,r])=>r))[0];if(s)return n.find(([,r])=>r===s.object)?.[0]}pickDecorAt(e,t){this.raycaster.setFromCamera(new Ue(e,t),this.camera);const n=[...this.decorGroups.entries()],s=this.raycaster.intersectObjects(n.map(([,a])=>a),!0)[0];if(!s)return;let r=s.object;for(;r&&!n.some(([,a])=>a===r);)r=r.parent;return n.find(([,a])=>a===r)?.[0]}dispose(){this.stopTwinkle(),this.terrainBuildToken++,this.disposeMesh(this.skyMesh),this.disposeMesh(this.groundMesh),this.disposeMesh(this.terrainMesh),this.disposeCloudSystem(),this.disposePrecipitationPoints(),this.disposeRain(),this.disposeStarTiers();for(const e of this.bodyMeshes.values())this.disposeMesh(e);this.bodyMeshes.clear();for(const e of[...this.hitAreas.keys()])this.disposeHitArea(e);for(const e of[...this.glareSprites.keys()])this.disposeGlare(e);this.disposeCompassLabels();for(const e of this.decorGroups.values())Os.dispose(e);this.decorGroups.clear(),this.streetlightLights.clear(),this.lensFlare&&(this.lensFlare.mesh.removeFromParent(),this.lensFlare.mesh.geometry.dispose(),this.lensFlare.mesh.material.dispose(),this.lensFlare=void 0),this.renderer.dispose()}startTwinkle(){if(this.animationFrameId!==null||!this.needsAnimationLoop())return;let e;const t=n=>{const s=e===void 0?0:Math.min((n-e)/1e3,x3);e=n,this.updateTwinkle(n/1e3),this.updatePrecipitation(n/1e3,s),this.updateRain(s),this.updateLightning(n/1e3,s),this.lensFlare&&(this.lensFlare.uniforms.uTime.value=n/1e3),this.render(),this.animationFrameId=requestAnimationFrame(t)};this.animationFrameId=requestAnimationFrame(t)}stopTwinkle(){this.animationFrameId!==null&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null)}needsAnimationLoop(){return this.starTiers.length>0||this.precipitationPoints!==void 0||this.rainSystem!==void 0||this.lightningArmed||this.lensFlare!==void 0&&this.sunVisible}syncAnimationLoop(){this.needsAnimationLoop()?this.startTwinkle():this.stopTwinkle()}buildSky(e){this.disposeMesh(this.skyMesh);const t=new ui(Mo,32,16),n=t.attributes.position,s=[];for(let a=0;a<n.count;a++){const{altitudeDeg:o,azimuthDeg:l}=xv(n.getX(a),n.getY(a),n.getZ(a)),c=yv(o,l,e.azimuthDeg,e.altitudeDeg);s.push(c[0],c[1],c[2])}t.setAttribute("color",new Et(s,3));const r=new js({vertexColors:!0,side:It,fog:!1});this.skyMesh=new Mt(t,r),this.celestialGroup.add(this.skyMesh)}buildGround(){this.disposeMesh(this.groundMesh),this.groundRadius=du(this.observerElevationM);const e=new fc(this.groundRadius,48),t=new nr({color:new Me(So,So,So),fog:!0});this.groundMesh=new Mt(e,t),this.groundMesh.rotation.x=-Math.PI/2,this.groundMesh.position.y=0,this.groundMesh.receiveShadow=!0,this.scene.add(this.groundMesh)}setBodyMesh(e,t,n,s,r){if(this.disposeMesh(this.bodyMeshes.get(e)),this.disposeHitArea(e),this.disposeGlare(e),t.altitudeDeg<$l){this.bodyMeshes.delete(e),e==="sun"&&(this.sunVisible=!1);return}const{x:a,y:o,z:l}=ji(t.altitudeDeg,t.azimuthDeg,yo),c=Ls(t.altitudeDeg),h=new Me(s.r*c[0],s.g*c[1],s.b*c[2]),d=new ui(n,16,16),u=new js({color:h,fog:!1}),p=new Mt(d,u);if(p.position.set(a,o,l),this.celestialGroup.add(p),this.bodyMeshes.set(e,p),this.setHitArea(e,a,o,l,n),e!=="sun"&&this.setGlare(e,a,o,l,r,h),e==="sun"){this.sunVisible=!0;const g=this.celestialGroup.scale.x;this.sunWorldPosition.set(a*g,o*g+this.celestialGroup.position.y,l*g),this.lensFlare||(this.lensFlare=vx(),this.lensFlare.uniforms.uOpacity.value=mu*this.dazzleIntensity,this.lensFlare.uniforms.uFlareIntensity.value=this.lensFlareArtifactIntensity,this.scene.add(this.lensFlare.mesh)),this.applyLensFlareTint(c)}}setMoonMesh(e){const t="moon";if(this.disposeMesh(this.bodyMeshes.get(t)),this.disposeHitArea(t),this.disposeGlare(t),e.altitudeDeg<$l){this.bodyMeshes.delete(t);return}const{x:n,y:s,z:r}=ji(e.altitudeDeg,e.azimuthDeg,yo),a=Ls(e.altitudeDeg),o=new Me(a[0],a[1],a[2]),l=new ks({map:D3(e.phase),color:o,fog:!1}),c=new Mr(l);c.position.set(n,s,r);const h=Eo*2;c.scale.set(h,h,1),this.celestialGroup.add(c),this.bodyMeshes.set(t,c),this.setHitArea(t,n,s,r,Eo),this.setGlare(t,n,s,r,e.magnitude,o)}setHitArea(e,t,n,s,r){const a=new ks({transparent:!0,opacity:0,depthTest:!1,depthWrite:!1,fog:!1}),o=new Mr(a);o.position.set(t,n,s);const l=r*kx;o.scale.set(l,l,1),this.celestialGroup.add(o),this.hitAreas.set(e,o)}disposeHitArea(e){const t=this.hitAreas.get(e);t&&(t.removeFromParent(),t.material.dispose(),this.hitAreas.delete(e))}setGlare(e,t,n,s,r,a){this.disposeGlare(e);const o=bv(r);if(o<=0)return;const l=wv(o),c=new ks({map:I3(),color:a,transparent:!0,opacity:Pv(o),blending:ra,depthWrite:!1,fog:!1}),h=new Mr(c);h.position.set(t,n,s),h.scale.set(l*2,l*2,1),this.celestialGroup.add(h),this.glareSprites.set(e,h)}disposeGlare(e){const t=this.glareSprites.get(e);t&&(t.removeFromParent(),t.material.dispose(),this.glareSprites.delete(e))}buildPlanets(e){const t=new Set(["sun","moon"]);for(const n of e){t.add(n.body);const s=Yh(n.magnitude),r=Zh(s),a=S3[n.body]??new Me(1,1,1),o=new Me(a.r*r,a.g*r,a.b*r),l=Bx*(.5+.5*s);this.setBodyMesh(n.body,n.position,l,o,n.magnitude)}for(const n of[...this.bodyMeshes.keys()])t.has(n)||(this.disposeMesh(this.bodyMeshes.get(n)),this.bodyMeshes.delete(n),this.disposeHitArea(n),this.disposeGlare(n))}buildStars(e,t){if(this.disposeStarTiers(),!e||e.catalog.count===0){this.syncAnimationLoop();return}const{catalog:n,date:s,observer:r}=e,a=gv(t),o=Ro(1337),l=[];for(let c=0;c<n.count;c++){const h=n.mag[c];if(h>a)continue;const{altitudeDeg:d,azimuthDeg:u}=I2(n.ra[c],n.dec[c],s,r);if(d<zx)continue;const{x:p,y:g,z:x}=ji(d,u,Ox);l.push({x:p,y:g,z:x,brightness:Yh(h),phase:o()*Math.PI*2,speedFactor:.7+o()*.6})}this.starTiers=y0.map((c,h)=>{const d=l.filter(M=>Dv(M.brightness)===h),u=new Float32Array(d.length*3),p=new Float32Array(d.length),g=new Float32Array(d.length),x=new Float32Array(d.length);d.forEach((M,y)=>{u[y*3]=M.x,u[y*3+1]=M.y,u[y*3+2]=M.z,p[y]=M.brightness,g[y]=M.phase,x[y]=M.speedFactor});const m=new bt;m.setAttribute("position",new pt(u,3));const f=new pt(new Float32Array(d.length*3),3);m.setAttribute("color",f);const A=new r0({vertexColors:!0,size:c.size,sizeAttenuation:!1,fog:!1}),w=new na(m,A);return this.celestialGroup.add(w),{points:w,colorAttribute:f,brightness:p,phase:g,speedFactor:x}}),this.updateTwinkle(0),this.startTwinkle()}updateTwinkle(e){for(const t of this.starTiers){const n=t.colorAttribute.array;for(let s=0;s<t.brightness.length;s++){const r=Uv(t.brightness[s],{phase:t.phase[s],speedFactor:t.speedFactor[s]},e),a=Zh(t.brightness[s])*r;n[s*3]=a,n[s*3+1]=a,n[s*3+2]=a}t.colorAttribute.needsUpdate=!0}}buildClouds(){if(this.disposeCloudSystem(),this.weather.cloudCover<=0)return;const e=this.weather.cloudDarkness,t=new Me(ns[0]+(Ao[0]-ns[0])*e,ns[1]+(Ao[1]-ns[1])*e,ns[2]+(Ao[2]-ns[2])*e),{material:n,uniforms:s}=dx(t,this.weather.cloudCover,Math.abs(this.cloudLayerOffset()));this.cloudMaterial=n,this.cloudUniforms=s,this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor);const r=px(jx);this.cloudMesh=new Mt(r,n),this.cloudLayerOffset()<0&&(this.cloudMesh.scale.y=-1),this.cloudMesh.renderOrder=i3,this.celestialGroup.add(this.cloudMesh)}syncCloudLayer(){const e=this.cloudLayerOffset();this.cloudUniforms&&(this.cloudUniforms.layerHeight.value=Math.abs(e)),this.cloudMesh&&(this.cloudMesh.scale.y=e<0?-1:1)}cloudLayerOffset(){const t=((this.weather.cloudBaseM??Po)-this.observerElevationM)*e3;return Math.sign(t||1)*Math.max(Math.abs(t),t3)}updateCloudLighting(e,t){if(!this.cloudUniforms)return;const{x:n,y:s,z:r}=ji(e.altitudeDeg,e.azimuthDeg,1),a=Ls(e.altitudeDeg),o=Math.max(0,Math.sin(Math.max(e.altitudeDeg,0)*mn));this.cloudUniforms.sunDir.value.set(n,s,r),this.cloudUniforms.sunColor.value.setRGB(a[0]*o,.96*a[1]*o,.88*a[2]*o),this.cloudUniforms.ambientColor.value.setRGB(t[0],t[1],t[2])}disposeCloudSystem(){this.cloudMesh&&(this.cloudMesh.removeFromParent(),this.cloudMesh.geometry.dispose()),this.cloudMaterial?.dispose(),this.cloudMesh=void 0,this.cloudMaterial=void 0,this.cloudUniforms=void 0}disposePrecipitationPoints(){this.precipitationPoints&&(this.precipitationPoints.removeFromParent(),this.precipitationPoints.geometry.dispose(),this.precipitationPoints.material.dispose()),this.precipitationPoints=void 0,this.precipitationPositions=void 0,this.precipitationPhase=void 0,this.precipitationSpeedJitter=void 0,this.precipitationWobbleFreqJitter=void 0,this.precipitationWobbleAmpJitter=void 0,this.precipitationBounceRemaining=void 0,this.precipitationBounceHeight=void 0,this.precipitationBounceDuration=void 0,this.precipitationBounceVelX=void 0,this.precipitationBounceVelZ=void 0,this.precipitationUniforms=void 0}buildPrecipitation(){this.disposePrecipitationPoints(),this.disposeRain();const e=this.weather.precipitationType;if(e==="none")return;if(e==="rain"){this.buildRain();return}const t=gu[e],n=t.poolSize,s=Ro(9001),r=new Float32Array(n*3),a=new Float32Array(n),o=new Float32Array(n),l=new Float32Array(n),c=new Float32Array(n),h=new Float32Array(n),d=new Float32Array(n),u=new Float32Array(n),p=new Float32Array(n),g=new Float32Array(n);for(let w=0;w<n;w++){const M=s()*Math.PI*2,y=s()*t.radiusM;r[w*3]=Math.cos(M)*y,r[w*3+1]=rs+s()*(t.topYM-rs),r[w*3+2]=Math.sin(M)*y,a[w]=s()*Math.PI*2,o[w]=.7+s()*.6,l[w]=.6+s()*.8,c[w]=.4+s()*1.2}const x=new bt;x.setAttribute("position",new pt(r,3)),x.setDrawRange(0,wo(n,this.weather.precipitationIntensity));const m={uSize:{value:t.size},uScale:{value:.5*this.renderer.domElement.height},uOpacity:{value:t.opacity},uColor:{value:t.color},uHazeColor:{value:new Me(...this.baseFogColor)},uTexture:{value:E3(e)},uNearFocusDistance:{value:yu},uHazeDistance:{value:t.radiusM*Eu}},f=new Gt({uniforms:m,vertexShader:C3,fragmentShader:P3,transparent:!0,depthWrite:!1});this.precipitationUniforms=m;const A=new na(x,f);A.renderOrder=To,this.scene.add(A),this.precipitationPoints=A,this.precipitationPositions=r,this.precipitationPhase=a,this.precipitationSpeedJitter=o,this.precipitationWobbleFreqJitter=l,this.precipitationWobbleAmpJitter=c,this.precipitationBounceRemaining=h,this.precipitationBounceHeight=d,this.precipitationBounceDuration=u,this.precipitationBounceVelX=p,this.precipitationBounceVelZ=g}updatePrecipitation(e,t){if(!this.precipitationPoints||!this.precipitationPositions||!this.precipitationPhase||!this.precipitationSpeedJitter||(this.precipitationUniforms?.uHazeColor.value.setRGB(...this.baseFogColor),t<=0))return;const n=this.weather.precipitationType;if(n==="none"||n==="rain")return;const s=gu[n],r=this.weather.windDirectionDeg*mn,a=Math.sin(r)*this.weather.windSpeed*s.driftSensitivity,o=-Math.cos(r)*this.weather.windSpeed*s.driftSensitivity,l=this.precipitationPositions,c=this.precipitationPhase,h=this.precipitationSpeedJitter,d=this.precipitationWobbleFreqJitter,u=this.precipitationWobbleAmpJitter,p=this.precipitationBounceRemaining,g=this.precipitationBounceHeight,x=this.precipitationBounceDuration,m=this.precipitationBounceVelX,f=this.precipitationBounceVelZ,A=n==="snow"&&d&&u,w=n==="hail"&&p&&g&&x&&m&&f;for(let M=0,y=0;M<l.length;M+=3,y++){if(w&&p[y]>0){if(p[y]-=t,p[y]<=0){const v=Math.random()*Math.PI*2,E=Math.sqrt(Math.random())*s.radiusM;l[M]=Math.cos(v)*E,l[M+1]=s.topYM,l[M+2]=Math.sin(v)*E,p[y]=0}else{const v=1-p[y]/x[y];l[M+1]=rs+Math.sin(Math.PI*v)*g[y],l[M]=Yr(l[M]+(a+m[y])*t,s.radiusM),l[M+2]=Yr(l[M+2]+(o+f[y])*t,s.radiusM)}continue}let b=0,R=0;if(A){const v=m3*d[y],E=g3*u[y];b=Math.sin(e*v*Math.PI*2+c[y])*E,R=Math.sin(e*v*Math.PI*2+c[y]+Math.PI/2)*E}if(l[M]+=(a+b)*t,l[M+1]-=s.fallSpeedMPerS*h[y]*t,l[M+2]+=(o+R)*t,l[M]=Yr(l[M],s.radiusM),l[M+2]=Yr(l[M+2],s.radiusM),l[M+1]<rs){if(w){g[y]=Ru*(.2+Math.random()*1.6),x[y]=_3*(.5+Math.random()),p[y]=x[y];const P=Math.random()*Math.PI*2,C=v3*(g[y]/Ru);m[y]=Math.cos(P)*C,f[y]=Math.sin(P)*C,l[M+1]=rs;continue}const v=Math.random()*Math.PI*2,E=Math.sqrt(Math.random())*s.radiusM;l[M]=Math.cos(v)*E,l[M+1]=s.topYM,l[M+2]=Math.sin(v)*E}}this.precipitationPoints.geometry.attributes.position.needsUpdate=!0}buildRain(){const e=l3(this.weather.precipitationIntensity);this.rainSystem=cx({count:_u,radiusM:Bs,heightM:r3,bottomYM:vu,overallSpeed:a3,color:c3,opacity:.85,visibleCount:wo(_u,this.weather.precipitationIntensity),speedStreak:d3(e),pixelSize:Tu,seed:9001,nearFocusDistanceM:yu,hazeDistanceM:Bs*Eu,hazeColor:new Me(...this.baseFogColor)}),this.rainLastVerticalFacing=-1,this.rainSystem.points.renderOrder=To,this.scene.add(this.rainSystem.points),this.buildRainSplashes()}buildRainSplashes(){const e=Ro(4242),t=new Float32Array(is*3),n=new Float32Array(is),s=new Float32Array(is),r=new Float32Array(is);for(let h=0;h<is;h++){const d=e()*Math.PI*2,u=Math.sqrt(e())*Bs;t[h*3]=Math.cos(d)*u,t[h*3+1]=vu,t[h*3+2]=Math.sin(d)*u,s[h]=qr(Mu,Su),n[h]=e()*s[h],r[h]=n[h]/s[h]}const a=new bt;a.setAttribute("position",new pt(t,3));const o=new pt(r,1);a.setAttribute("aLife",o),a.setDrawRange(0,wo(is,this.weather.precipitationIntensity));const l=new Gt({uniforms:{uMaxSize:{value:f3},uScale:{value:.5*this.renderer.domElement.height},uColor:{value:p3},uTexture:{value:A3()}},vertexShader:w3,fragmentShader:R3,transparent:!0,depthWrite:!1}),c=new na(a,l);c.renderOrder=To,this.scene.add(c),this.rainSplashSystem={points:c,positions:t,life:n,duration:s,lifeAttribute:o}}disposeRain(){this.rainSystem&&(this.rainSystem.points.removeFromParent(),this.rainSystem.points.geometry.dispose(),this.rainSystem.points.material.dispose()),this.rainSystem=void 0,this.disposeRainSplashes()}disposeRainSplashes(){this.rainSplashSystem&&(this.rainSplashSystem.points.removeFromParent(),this.rainSplashSystem.points.geometry.dispose(),this.rainSplashSystem.points.material.dispose()),this.rainSplashSystem=void 0}updateRain(e){const t=this.rainSystem;if(!t)return;t.uniforms.uTime.value+=e,t.uniforms.uHazeColor.value.setRGB(...this.baseFogColor);const n=this.weather.windDirectionDeg*mn,s=Math.sin(n)*this.weather.windSpeed,r=-Math.cos(n)*this.weather.windSpeed,a=Bs,o=c=>(c%(a*2)+a*3)%(a*2)-a;t.uniforms.uWindOffset.value.set(o(t.uniforms.uWindOffset.value.x+s*e),o(t.uniforms.uWindOffset.value.y+r*e)),this.camera.getWorldDirection(this.rainCameraDirection);const l=Math.abs(this.rainCameraDirection.y);if(Math.abs(l-this.rainLastVerticalFacing)>.001){this.rainLastVerticalFacing=l;const c=Au+(1-Au)*(1-l),h=wu+(1-wu)*(1-l);t.uniforms.uUvSquash.value=h,t.uniforms.uPixelSize.value=Tu*c*(.5+.5*h)}this.updateRainSplashes(e)}updateRainSplashes(e){const t=this.rainSplashSystem;if(!t||e<=0)return;const{positions:n,life:s,duration:r,lifeAttribute:a}=t,o=a.array;for(let l=0,c=0;l<n.length;l+=3,c++){if(s[c]+=e,s[c]>=r[c]){const h=Math.random()*Math.PI*2,d=Math.sqrt(Math.random())*Bs;n[l]=Math.cos(h)*d,n[l+2]=Math.sin(h)*d,r[c]=qr(Mu,Su),s[c]=0}o[c]=s[c]/r[c]}t.points.geometry.attributes.position.needsUpdate=!0,a.needsUpdate=!0}updateLightning(e,t){if(this.lightningArmed){if(this.lightningFlashRemainingS>0){this.lightningFlashRemainingS=Math.max(0,this.lightningFlashRemainingS-t);const n=this.lightningFlashRemainingS/Iu;this.scene.fog&&this.scene.fog.color.setRGB(this.baseFogColor[0]+(1-this.baseFogColor[0])*n,this.baseFogColor[1]+(1-this.baseFogColor[1])*n,this.baseFogColor[2]+(1-this.baseFogColor[2])*n);return}if(this.nextLightningAtS===null){this.nextLightningAtS=e+qr(Cu,Pu);return}e>=this.nextLightningAtS&&(this.lightningFlashRemainingS=Iu,this.nextLightningAtS=e+qr(Cu,Pu),this.onLightningFlash?.())}}buildCompassLabels(){const e=Jl(navigator.languages,Zx),t=Yx[e];this.compassSprites=qx.map((n,s)=>{const r=t[s],a=new ks({map:L3(r),depthTest:!1,fog:!1}),o=new Mr(a),{x:l,y:c,z:h}=ji(0,n,$x);return o.position.set(l,c,h),o.scale.set(pu,pu,1),o.renderOrder=Kx,o.visible=this.compassHovered||this.compassForced,this.celestialGroup.add(o),o})}disposeCompassLabels(){for(const e of this.compassSprites)e.removeFromParent(),e.material.map?.dispose(),e.material.dispose();this.compassSprites=[]}disposeStarTiers(){for(const e of this.starTiers)this.disposeMesh(e.points);this.starTiers=[]}disposeMesh(e){if(!e)return;e.removeFromParent(),"geometry"in e&&e.geometry.dispose();const t=e.material;for(const n of Array.isArray(t)?t:[t]){const s=n.map;s&&s.dispose(),n.dispose()}}}const mn=Math.PI/180;function td(i,e,t){return Math.max(e,Math.min(t,i))}function qr(i,e){return i+Math.random()*(e-i)}function Yr(i,e){return(i%(e*2)+e*3)%(e*2)-e}let Zr,$r;function E3(i){switch(i){case"snow":return b3();case"hail":return T3()}}function b3(){if(Zr)return Zr;const i=64,e=document.createElement("canvas");e.width=i,e.height=i;const t=e.getContext("2d"),n=t.createRadialGradient(i/2,i/2,0,i/2,i/2,i/2);return n.addColorStop(0,"rgba(255,255,255,0.95)"),n.addColorStop(.5,"rgba(255,255,255,0.55)"),n.addColorStop(1,"rgba(255,255,255,0)"),t.fillStyle=n,t.fillRect(0,0,i,i),Zr=new Wn(e),Zr}function T3(){if($r)return $r;const i=64,e=document.createElement("canvas");e.width=i,e.height=i;const t=e.getContext("2d"),n=t.createRadialGradient(i/2,i/2,0,i/2,i/2,i/2);return n.addColorStop(0,"rgba(255,255,255,1)"),n.addColorStop(.55,"rgba(255,255,255,0.95)"),n.addColorStop(.8,"rgba(255,255,255,0.4)"),n.addColorStop(1,"rgba(255,255,255,0)"),t.fillStyle=n,t.fillRect(0,0,i,i),$r=new Wn(e),$r}let Kr;function A3(){if(Kr)return Kr;const i=64,e=document.createElement("canvas");e.width=i,e.height=i;const t=e.getContext("2d"),n=t.createRadialGradient(i/2,i/2,0,i/2,i/2,i/2);return n.addColorStop(0,"rgba(255,255,255,0)"),n.addColorStop(.4,"rgba(255,255,255,0)"),n.addColorStop(.6,"rgba(255,255,255,0.9)"),n.addColorStop(.8,"rgba(255,255,255,0.25)"),n.addColorStop(1,"rgba(255,255,255,0)"),t.fillStyle=n,t.fillRect(0,0,i,i),Kr=new Wn(e),Kr}const w3=`
5037
+ `;let Wr;function _x(){if(Wr)return Wr;const i=256,e=document.createElement("canvas");e.width=i,e.height=i;const t=e.getContext("2d");t.fillStyle="rgba(60,60,60,1)",t.fillRect(0,0,i,i);const n=[[.3,.35,.22,.5],[.7,.6,.16,.35],[.55,.8,.3,.4],[.15,.7,.12,.3],[.85,.2,.18,.3]];for(const[s,r,a,o]of n){const l=t.createRadialGradient(s*i,r*i,0,s*i,r*i,a*i);l.addColorStop(0,`rgba(200,200,200,${o})`),l.addColorStop(1,"rgba(200,200,200,0)"),t.fillStyle=l,t.fillRect(0,0,i,i)}return Wr=new Wn(e),Wr}function vx(){const i={uTime:{value:0},uResolution:{value:new Ue(1,1)},uLensPosition:{value:new Ue(0,0)},uColorGain:{value:new Me(55,55,51)},uOpacity:{value:.5},uFlareIntensity:{value:0},uStarPoints:{value:6},uGlareSize:{value:.55},uFlareSize:{value:.0025},uFlareSpeed:{value:.4},uFlareShape:{value:1.2},uHaloScale:{value:.5},uGhostScale:{value:.3},uAnimated:{value:!1},uAnamorphic:{value:!1},uSecondaryGhosts:{value:!0},uStarBurst:{value:!0},uAdditionalStreaks:{value:!0},uLensDirtTexture:{value:_x()}},e=new Gt({uniforms:i,vertexShader:mx,fragmentShader:gx,transparent:!0,depthWrite:!1,depthTest:!1,blending:ra,fog:!1,name:"LensFlareShader"}),t=new Mt(new tr(2,2),e);return t.frustumCulled=!1,t.renderOrder=20,{mesh:t,uniforms:i}}const xx=2;function Mx(i){return i==="building"||i==="vehicle"}function Sx(i,e){const t=i.litKeyframes;if(!t||t.length===0)return i.lit??!1;let n=t[0];for(const s of t){if(s.t>e)break;n=s}return n.lit}const hu=Math.PI/180;function nn(i,e,t,n,s=!1){const r=s?new js({color:new Me(...t)}):new nr({color:new Me(...t)}),a=new Mt(e,r);return a.position.y=n,a.userData={emissive:s},a.castShadow=!s,a.receiveShadow=!s,i.add(a),a}const X0=[.32,.32,.3],q0=[1,.85,.5],Y0=[.25,.25,.25],Z0=[1,.97,.85],yx=[.55,.68,.72],vn=.03,xn=.05,$0={front:0,behind:Math.PI,left:Math.PI/2,right:-Math.PI/2,"front-left":Math.PI/2,"behind-left":Math.PI/2,"front-right":-Math.PI/2,"behind-right":-Math.PI/2};function kt(i,e){return i?.[e]}function Mn(i,e,t,n,s,r,a,o){if(o===void 0)return;const l=new nr({color:new Me(...yx),transparent:!0,opacity:o/100}),c=new Mt(new Cn(e,t,n),l);c.position.set(s,r,a),i.add(c)}const Qt=.05,vo=[.6,.58,.53],uu=[.5,.5,.48];function ls(i,e,t,n,s,r,a,o){const l=new nr({color:new Me(...o),side:It}),c=new Mt(new Cn(e,t,n),l);c.position.set(s,r,a),i.add(c)}function Ex(i,e,t,n,s,r,a,o,l){const c=(n-r)/2,h=(g,x,m,f)=>{g<=0||(e?ls(i,g,x,Qt,m,o+f,a,l):ls(i,Qt,x,g,a,o+f,m,l))};h(t,c,0,n/2-c/2),h(t,c,0,-(n/2-c/2));const d=[...s].sort((g,x)=>g.center-x.center);let u=-t/2;for(const g of d){const m=g.center-g.main/2-u;h(m,r,u+m/2,0),u=g.center+g.main/2}const p=t/2-u;h(p,r,u+p/2,0)}function K0(i,e,t,n,s,r,a,o,l,c){const h=(n+s)/2,d=s-n,u=(p,g,x,m)=>{p.length===0?g?ls(i,x,d,Qt,0,h,m,vo):ls(i,Qt,d,x,m,h,0,vo):Ex(i,g,x,d,p,r,m,h,vo)};u(a,!0,e*2,-t+Qt),u(o,!0,e*2,t-Qt),u(l,!1,t*2,-e+Qt),u(c,!1,t*2,e-Qt),ls(i,e*2,Qt,t*2,0,n+Qt,0,uu),ls(i,e*2,Qt,t*2,0,s-Qt,0,uu)}function ql(i,e,t,n){switch(i){case"front":return{x:0,z:-(t-n)};case"behind":return{x:0,z:t-n};case"left":return{x:-(e-n),z:0};case"right":return{x:e-n,z:0};case"front-left":return{x:-(e-n),z:-Sn};case"front-right":return{x:e-n,z:-Sn};case"behind-left":return{x:-(e-n),z:Sn};case"behind-right":return{x:e-n,z:Sn}}}function J0(i,e,t,n,s,r,a){const o=ed();o.scale.setScalar(n),o.rotation.y=$0[e];const{x:l,z:c}=ql(e,s,r,a);o.position.set(l,t,c),i.add(o)}const Yl=6,Zl=6,ii=3,Us=1.4,Fs=ii*.5,Q0=1.2,j0=.35,bx=.75,Tx=1.6;function Ax(i,e,t,n){const s=new Tn,r=Math.max(1,i+1),a=r*ii;nn(s,new Cn(Yl,a,Zl),[.55,.54,.5],a/2);const o=Yl/2,l=Zl/2;for(let c=0;c<r;c++){const h=c*ii+ii/2;Mn(s,Us,Fs,xn,0,h,-l-vn,kt(e,"front")),Mn(s,Us,Fs,xn,0,h,l+vn,kt(e,"behind")),Mn(s,xn,Fs,Us,-o-vn,h,0,kt(e,"left")),Mn(s,xn,Fs,Us,o+vn,h,0,kt(e,"right"))}if(t){const c=Math.min(Math.max(n??0,0),r-1);J0(s,t,c*ii,.72,o,l,Q0);const h=d=>kt(e,d)!==void 0?[{main:Us,center:0}]:[];K0(s,o,l,c*ii,(c+1)*ii,Fs,h("front"),h("behind"),h("left"),h("right"))}return s}function wx(){const i=new Tn;return nn(i,new Di(.15,.22,2,8),[.32,.22,.14],1),nn(i,new Ea(1.4,3,8),[.16,.32,.14],3.5),i}function Rx(i){const e=new Tn;return nn(e,new Di(.05,.08,5,8),[.28,.28,.3],2.5),nn(e,new ui(.25,12,8),i?q0:X0,5.1,!0),e}const Cx=[.08,.08,.08],ni=.8,ss=1,gn=1.7,xo=.6,_i=.4,Xr=1.2,ts=.7,Sn=.5,Px=gn;function Ix(i,e,t){const n=new Tn;nn(n,new Cn(1.8,1.4,4.2),[.45,.14,.14],.7),nn(n,new Cn(ni*2,xo,ss*2),[.4,.12,.12],gn);for(const r of[-1.4,1.4])for(const a of[-.95,.95]){const o=nn(n,new Di(.4,.4,.3,12),Cx,.4);o.rotation.z=Math.PI/2,o.position.x=a,o.position.z=r}const s=i?Z0:Y0;for(const r of[-.7,.7])nn(n,new ui(.15,8,6),s,.7,!0).position.set(r,.7,-2.1);if(Mn(n,Xr,_i,xn,0,gn,-ss-vn,kt(e,"front")),Mn(n,Xr,_i,xn,0,gn,ss+vn,kt(e,"behind")),Mn(n,xn,_i,ts,-ni-vn,gn,-Sn,kt(e,"front-left")),Mn(n,xn,_i,ts,-ni-vn,gn,Sn,kt(e,"behind-left")),Mn(n,xn,_i,ts,ni+vn,gn,-Sn,kt(e,"front-right")),Mn(n,xn,_i,ts,ni+vn,gn,Sn,kt(e,"behind-right")),t){J0(n,t,bx,.5,ni,ss,j0);const r=(l,c)=>{const h=[];return kt(e,l)!==void 0&&h.push({main:ts,center:-Sn}),kt(e,c)!==void 0&&h.push({main:ts,center:Sn}),h},a=kt(e,"front")!==void 0?[{main:Xr,center:0}]:[],o=kt(e,"behind")!==void 0?[{main:Xr,center:0}]:[];K0(n,ni,ss,gn-xo/2,gn+xo/2,_i,a,o,r("front-left","behind-left"),r("front-right","behind-right"))}return n}const Dx=[.95,.9,.82];function ed(){const i=new Tn;nn(i,new Di(.25,.3,1.5,10),[.3,.3,.35],.75),nn(i,new ui(.22,10,8),[.62,.52,.46],1.72);const e=nn(i,new Ea(.07,.16,8),Dx,1.72);return e.rotation.x=-Math.PI/2,e.position.z=-.2,i}class Os{static occupantView(e){const t=e.witnessSide;if(!t)throw new Error("occupantView requires object.witnessSide to be set");const{x:n,z:s}=e.kind==="vehicle"?ql(t,ni,ss,j0):ql(t,Yl/2,Zl/2,Q0),r=e.kind==="vehicle"?Px:(e.occupiedFloor??0)*ii+Tx,a=(e.headingDeg??0)-$0[t]/hu;return{x:n,z:s,eyeY:r,headingDeg:a}}static build(e,t){const n=e.kind==="building"?Ax(e.floors??xx,e.windows,e.witnessSide,e.occupiedFloor):e.kind==="tree"?wx():e.kind==="streetlight"?Rx(t):e.kind==="vehicle"?Ix(t,e.windows,e.witnessSide):ed();return e.headingDeg!==void 0&&(n.rotation.y=-e.headingDeg*hu),n}static setLit(e,t,n){const s=t==="streetlight"?n?q0:X0:n?Z0:Y0;for(const r of e.children)!(r instanceof Mt)||!r.userData.emissive||r.material.color.setRGB(...s)}static dispose(e){for(const t of e.children)t instanceof Mt&&(t.geometry.dispose(),t.material.dispose())}}function Lx(i,e){return i.cloudCover===e.cloudCover&&i.cloudDarkness===e.cloudDarkness&&i.cloudBaseM===e.cloudBaseM&&i.precipitationType===e.precipitationType&&i.precipitationIntensity===e.precipitationIntensity&&i.windDirectionDeg===e.windDirectionDeg&&i.windSpeed===e.windSpeed&&i.storm===e.storm}const Mo=900,Nx=.5,Ws=900,Ux=6371e3,Fx=3e4;function du(i){const e=Math.sqrt(2*Ux*Math.max(i,0));return Math.max(Ws,Math.min(e,Fx))}const So=.5,Ox=850,yo=850,Eo=4,Bx=1.5,zx=-1,kx=6,$l=-4,fu=$l,Gx=3,Hx=.15,Vx=.6,Wx=40,Xx=30,qx=[0,45,90,135,180,225,270,315],Yx={en:["N","NE","E","SE","S","SW","W","NW"],fr:["N","NE","E","SE","S","SO","O","NO"]},Zx=["en","fr"],$x=880,pu=40,Kx=10,Jx=1,Qx=150,bo=55,mu=.5,jx=700,e3=250/Po,t3=12,n3=.5,i3=5,To=6,ns=[.92,.92,.95],Ao=[.15,.15,.19],gu={snow:{fallSpeedMPerS:2,size:.3,color:new Me(1,1,1),driftSensitivity:1,radiusM:25,topYM:20,opacity:.75,poolSize:2400},hail:{fallSpeedMPerS:14,size:.5,color:new Me(.95,.98,1),driftSensitivity:.25,radiusM:25,topYM:10,opacity:.95,poolSize:1200}},rs=0,s3=0,_u=3e3,Bs=20,r3=15,vu=rs,a3=40,xu=1,o3=9;function l3(i){return xu+(o3-xu)*i}const c3=new Me(.75,.82,.92),h3=10,u3=.5;function d3(i){return td(i/h3,u3,1)}const is=200,Mu=.18,Su=.32,f3=.35,p3=new Me(.85,.9,.98),yu=5,Eu=.85,bu=.01;function wo(i,e){return Math.round(i*(bu+(1-bu)*e))}const Tu=230,Au=.7,wu=.05,m3=.6,g3=.7,_3=.15,Ru=.35,v3=3,x3=1/12,M3=.5,Cu=8,Pu=25,Iu=.12,S3={Venus:new Me(1,.96,.85),Mars:new Me(1,.55,.4),Jupiter:new Me(.95,.87,.72),Saturn:new Me(.92,.86,.68)};class y3{renderer;scene=new Zf;camera;celestialGroup=new Tn;skyMesh;groundMesh;terrainMesh;terrainProviders;terrainOrigin;terrainBuildToken=0;terrainAttribution;starTiers=[];bodyMeshes=new Map;hitAreas=new Map;glareSprites=new Map;decorObjects=[];decorGroups=new Map;celestialLight=new _p(16777215,0);celestialLightTarget=new St;skyLight=new fp(16777215,0,0);streetlightLights=new Map;compassSprites=[];showCompass=!1;compassHovered=!1;compassForced=!1;animationFrameId=null;raycaster=new ro;weather=Nu;observerElevationM=0;groundRadius=Ws;terrainRadius=Ws;cloudMesh;cloudMaterial;cloudUniforms;precipitationPoints;precipitationPositions;precipitationPhase;precipitationSpeedJitter;precipitationWobbleFreqJitter;precipitationWobbleAmpJitter;precipitationBounceRemaining;precipitationBounceHeight;precipitationBounceDuration;precipitationBounceVelX;precipitationBounceVelZ;precipitationUniforms;rainSystem;rainSplashSystem;rainCameraDirection=new U;rainLastVerticalFacing=-1;lightningArmed=!1;nextLightningAtS=null;lightningFlashRemainingS=0;baseFogColor=[0,0,0];lastSunPosition;lensFlare;dazzleIntensity=1;lensFlareArtifactIntensity=0;sunWorldPosition=new U;sunVisible=!1;lensFlareScratch=new U;sunOcclusionRaycaster=new ro;sunOcclusionDirectionScratch=new U;ufoOcclusionRaycaster=new ro;onLightningFlash;constructor(e,t=Z2(),n){this.renderer=new mv({canvas:e,antialias:!0}),this.renderer.setPixelRatio(Math.min(window.devicePixelRatio||1,2)),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=Xs,this.camera=new Yt(60,e.width/Math.max(e.height,1),.1,Mo*1.2),this.camera.position.set(0,1.6,0),this.terrainProviders=t,this.onLightningFlash=n,this.celestialLight.shadow.mapSize.set(1024,1024),this.celestialLight.shadow.camera.left=-120,this.celestialLight.shadow.camera.right=120,this.celestialLight.shadow.camera.top=120,this.celestialLight.shadow.camera.bottom=-120,this.celestialLight.shadow.camera.near=1,this.celestialLight.shadow.camera.far=1e3,this.celestialLight.shadow.bias=-.0015,this.celestialLight.target=this.celestialLightTarget,this.scene.add(this.celestialLight,this.celestialLightTarget,this.skyLight),this.scene.add(this.celestialGroup)}get currentTerrainAttribution(){return this.terrainAttribution}resize(e,t){this.renderer.setSize(e,t,!1),this.camera.aspect=e/Math.max(t,1),this.camera.updateProjectionMatrix(),this.render()}setObserverPose(e){e.headingDeg!==void 0?this.camera.rotation.set(e.pitchDeg*mn,-e.headingDeg*mn,0,"YXZ"):this.camera.rotation.set(e.pitchDeg*mn,this.camera.rotation.y,0,"YXZ"),e.elevationM!==this.observerElevationM&&(this.observerElevationM=e.elevationM,this.syncCloudLayer(),Math.abs(du(e.elevationM)-this.groundRadius)>1&&(this.buildGround(),this.celestialGroup.scale.setScalar(this.groundRadius/Ws),this.camera.far=Math.max(Mo*1.2,this.groundRadius*2.5),this.camera.updateProjectionMatrix())),this.camera.position.y=1.6+e.elevationM,this.celestialGroup.position.y=this.camera.position.y,this.camera.fov!==e.fovDeg&&(this.camera.fov=e.fovDeg,this.camera.updateProjectionMatrix())}setTerrainProviders(e){this.terrainProviders=e,this.disposeMesh(this.terrainMesh),this.terrainMesh=void 0,this.terrainOrigin=void 0,this.terrainAttribution=void 0,this.terrainBuildToken++}setTerrainOrigin(e,t,n){if(e===void 0||t===void 0)return;const s=this.groundRadius;if(this.terrainOrigin&&Math.abs(this.terrainRadius-s)<s*.1){const{x:a,z:o}=Ci(e,t,this.terrainOrigin.lat,this.terrainOrigin.lng);if(Math.sqrt(a*a+o*o)<Qx*(s/Ws))return}this.terrainOrigin={lat:e,lng:t},this.terrainRadius=s;const r=++this.terrainBuildToken;ex(e,t,this.terrainProviders,s).then(({mesh:a,attribution:o})=>{r===this.terrainBuildToken&&(this.disposeMesh(this.terrainMesh),a.renderOrder=Jx,this.terrainMesh=a,this.terrainAttribution=o,this.scene.add(a),this.render(),n?.())}).catch(a=>{console.warn("Terrain build failed, keeping the flat ground fallback:",a),n?.()})}setShowCompass(e){this.showCompass!==e&&(this.showCompass=e,this.disposeCompassLabels(),e&&this.buildCompassLabels(),this.render())}setDazzleIntensity(e){this.dazzleIntensity!==e&&(this.dazzleIntensity=e,this.lensFlare&&(this.lensFlare.uniforms.uOpacity.value=mu*e,this.lastSunPosition&&this.applyLensFlareTint(Ls(this.lastSunPosition.altitudeDeg))),this.render())}setLensFlareArtifactIntensity(e){this.lensFlareArtifactIntensity!==e&&(this.lensFlareArtifactIntensity=e,this.lensFlare&&(this.lensFlare.uniforms.uFlareIntensity.value=e),this.render())}applyLensFlareTint(e){this.lensFlare&&this.lensFlare.uniforms.uColorGain.value.setRGB(bo*this.dazzleIntensity*e[0],bo*this.dazzleIntensity*e[1],bo*this.dazzleIntensity*e[2])}setCompassHovered(e){this.compassHovered!==e&&(this.compassHovered=e,this.updateCompassVisibility())}setCompassForced(e){this.compassForced!==e&&(this.compassForced=e,this.updateCompassVisibility())}updateCompassVisibility(){const e=this.compassHovered||this.compassForced;for(const t of this.compassSprites)t.visible=e;this.render()}setWeather(e){Lx(this.weather,e)||(this.weather=e,this.buildClouds(),this.buildPrecipitation(),this.lightningArmed=e.storm&&e.cloudDarkness>=M3,this.lightningArmed||(this.nextLightningAtS=null,this.lightningFlashRemainingS=0,this.restoreFogColor()),this.syncAnimationLoop(),this.render())}setDecor(e){if(this.decorObjects!==e){this.decorObjects=e;for(const t of this.decorGroups.values())t.removeFromParent(),Os.dispose(t);this.decorGroups.clear(),this.streetlightLights.clear();for(const t of e){const n=Os.build(t,t.lit??!1);this.scene.add(n),this.decorGroups.set(t.id,n),t.kind==="streetlight"&&this.addStreetlightLight(t.id,n)}this.celestialLight.castShadow=this.decorGroups.size>0}}updateDecorAnchoring(e,t){const n=e?.lat!==void 0&&e.lng!==void 0&&t?.lat!==void 0&&t?.lng!==void 0?Ci(e.lat,e.lng,t.lat,t.lng):{x:0,z:0},s=this.decorObjects.find(a=>a.witnessSide!==void 0&&Mx(a.kind)),r={x:0,z:0};if(s){const a=Os.occupantView(s),o=-(s.headingDeg??0)*mn,l=a.x*Math.cos(o)+a.z*Math.sin(o),c=-a.x*Math.sin(o)+a.z*Math.cos(o),h=s.eastM+n.x,d=-s.northM+n.z;r.x=-(h+l),r.z=-(d+c),this.camera.position.y=a.eyeY,this.camera.rotation.set(this.indoorLookPitchDeg*mn,-(a.headingDeg+this.indoorLookYawDeg)*mn,0,"YXZ")}for(const a of this.decorObjects){const o=this.decorGroups.get(a.id);o&&o.position.set(a.eastM+n.x+r.x,s3,-a.northM+n.z+r.z)}}indoorLookYawDeg=0;indoorLookPitchDeg=0;setIndoorLook(e,t){this.indoorLookYawDeg=e,this.indoorLookPitchDeg=t}updateDecorLitState(e){for(const t of this.decorObjects){if(t.kind!=="streetlight"&&t.kind!=="vehicle")continue;const n=this.decorGroups.get(t.id);if(!n)continue;const s=Sx(t,e);Os.setLit(n,t.kind,s);const r=this.streetlightLights.get(t.id);r&&(r.visible=s)}}addStreetlightLight(e,t){const n=t.children.find(r=>r.userData.emissive);if(!n)return;const s=new mp(16764006,Wx,Xx);s.position.copy(n.position),s.castShadow=!0,s.shadow.mapSize.set(512,512),s.shadow.bias=-.002,t.add(s),this.streetlightLights.set(e,s)}setAstronomy(e){const t=M0(e.sun.altitudeDeg),n=t.horizon;this.baseFogColor=n,this.lastSunPosition=e.sun,this.buildSky(e.sun),this.buildGround(),this.updateCloudLighting(e.sun,n),this.updateCelestialLight(e,t.zenith,n),this.buildStars(e.stars,e.sun.altitudeDeg),this.setBodyMesh("sun",e.sun,Eo,new Me(1,.96,.88),e.sun.magnitude),this.setMoonMesh(e.moon),this.buildPlanets(e.planets),this.scene.fog=new hc(new Me(...n),this.groundRadius*.2,this.groundRadius),this.syncAnimationLoop(),this.render()}updateCelestialLight(e,t,n){this.skyLight.color.setRGB(t[0],t[1],t[2]),this.skyLight.groundColor.setRGB(n[0],n[1],n[2]),this.skyLight.intensity=Vx;const s=e.sun.altitudeDeg>=fu,r=!s&&e.moon.altitudeDeg>=fu;if(!s&&!r){this.celestialLight.intensity=0;return}const a=s?e.sun:e.moon,{x:o,y:l,z:c}=ji(a.altitudeDeg,a.azimuthDeg,yo);this.celestialLight.position.set(o,l,c);const h=Ls(a.altitudeDeg);this.celestialLight.color.setRGB(h[0],h[1],h[2]);const d=Math.max(0,Math.sin(Math.max(a.altitudeDeg,0)*mn));this.celestialLight.intensity=(s?Gx:Hx)*d,this.celestialLight.castShadow=this.decorGroups.size>0}render(){this.updateLensFlarePosition(),this.renderer.render(this.scene,this.camera)}updateLensFlarePosition(){const e=this.lensFlare;if(!e)return;if(!this.sunVisible){e.mesh.visible=!1;return}if(this.camera.updateMatrixWorld(),this.lensFlareScratch.copy(this.sunWorldPosition).applyMatrix4(this.camera.matrixWorldInverse),this.lensFlareScratch.z>0){e.mesh.visible=!1;return}if(this.isSunOccluded()){e.mesh.visible=!1;return}e.mesh.visible=!0;const t=this.lensFlareScratch.copy(this.sunWorldPosition).project(this.camera);e.uniforms.uLensPosition.value.set(t.x,t.y),e.uniforms.uResolution.value.set(this.renderer.domElement.width,this.renderer.domElement.height)}isSunOccluded(){const e=[];this.groundMesh&&e.push(this.groundMesh),this.terrainMesh&&e.push(this.terrainMesh);for(const r of this.decorGroups.values())e.push(r);if(e.length===0)return!1;const t=this.sunOcclusionDirectionScratch.copy(this.sunWorldPosition).sub(this.camera.position),n=t.length();t.normalize(),this.sunOcclusionRaycaster.set(this.camera.position,t);const s=this.sunOcclusionRaycaster.intersectObjects(e,!0)[0];return s!==void 0&&s.distance<n}isScreenPointOccluded(e,t,n,s){if(this.isBehindCloudLayer(e,t,s))return!0;const r=[];for(const a of this.decorObjects){if(!a.occludesSourceIds?.includes(n))continue;const o=this.decorGroups.get(a.id);o&&r.push(o)}return r.length===0?!1:(this.ufoOcclusionRaycaster.setFromCamera(new Ue(e,t),this.camera),this.ufoOcclusionRaycaster.near=Nx,this.ufoOcclusionRaycaster.intersectObjects(r,!0).length>0)}isBehindCloudLayer(e,t,n){if(!n||!this.cloudMesh||this.weather.cloudCover<=0)return!1;if(n.declared)return!0;const s=n.distanceM;if(s===void 0)return!1;const r=this.cloudLayerOffset();this.ufoOcclusionRaycaster.setFromCamera(new Ue(e,t),this.camera);const a=this.ufoOcclusionRaycaster.ray.direction;return Math.sign(a.y||1)!==Math.sign(r)||Math.abs(this.cloudLayerHeightM())/Math.max(Math.abs(a.y),.026)>=s?!1:yt.alphaAt(a,Math.abs(r),this.weather.cloudCover)>=n3}cloudLayerHeightM(){return(this.weather.cloudBaseM??Po)-this.observerElevationM}pickBodyAt(e,t){this.raycaster.setFromCamera(new Ue(e,t),this.camera);const n=[...this.hitAreas.entries()],s=this.raycaster.intersectObjects(n.map(([,r])=>r))[0];if(s)return n.find(([,r])=>r===s.object)?.[0]}pickDecorAt(e,t){this.raycaster.setFromCamera(new Ue(e,t),this.camera);const n=[...this.decorGroups.entries()],s=this.raycaster.intersectObjects(n.map(([,a])=>a),!0)[0];if(!s)return;let r=s.object;for(;r&&!n.some(([,a])=>a===r);)r=r.parent;return n.find(([,a])=>a===r)?.[0]}dispose(){this.stopTwinkle(),this.terrainBuildToken++,this.disposeMesh(this.skyMesh),this.disposeMesh(this.groundMesh),this.disposeMesh(this.terrainMesh),this.disposeCloudSystem(),this.disposePrecipitationPoints(),this.disposeRain(),this.disposeStarTiers();for(const e of this.bodyMeshes.values())this.disposeMesh(e);this.bodyMeshes.clear();for(const e of[...this.hitAreas.keys()])this.disposeHitArea(e);for(const e of[...this.glareSprites.keys()])this.disposeGlare(e);this.disposeCompassLabels();for(const e of this.decorGroups.values())Os.dispose(e);this.decorGroups.clear(),this.streetlightLights.clear(),this.lensFlare&&(this.lensFlare.mesh.removeFromParent(),this.lensFlare.mesh.geometry.dispose(),this.lensFlare.mesh.material.dispose(),this.lensFlare=void 0),this.renderer.dispose()}animationsRunning=!1;startTwinkle(){if(this.animationFrameId!==null||!this.needsAnimationLoop())return;let e;const t=n=>{const s=e===void 0?0:Math.min((n-e)/1e3,x3);e=n,this.updateTwinkle(n/1e3),this.updatePrecipitation(n/1e3,s),this.updateRain(s),this.updateLightning(n/1e3,s),this.lensFlare&&(this.lensFlare.uniforms.uTime.value=n/1e3),this.render(),this.animationFrameId=requestAnimationFrame(t)};this.animationFrameId=requestAnimationFrame(t)}setAnimationsRunning(e){e!==this.animationsRunning&&(this.animationsRunning=e,e?this.nextLightningAtS=null:this.lightningFlashRemainingS>0&&(this.lightningFlashRemainingS=0,this.restoreFogColor()),this.syncAnimationLoop(),e||this.render())}stopTwinkle(){this.animationFrameId!==null&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null)}restoreFogColor(){this.scene.fog&&this.scene.fog.color.setRGB(...this.baseFogColor)}needsAnimationLoop(){return this.animationsRunning&&(this.starTiers.length>0||this.precipitationPoints!==void 0||this.rainSystem!==void 0||this.lightningArmed||this.lensFlare!==void 0&&this.sunVisible)}syncAnimationLoop(){this.needsAnimationLoop()?this.startTwinkle():this.stopTwinkle()}buildSky(e){this.disposeMesh(this.skyMesh);const t=new ui(Mo,32,16),n=t.attributes.position,s=[];for(let a=0;a<n.count;a++){const{altitudeDeg:o,azimuthDeg:l}=xv(n.getX(a),n.getY(a),n.getZ(a)),c=yv(o,l,e.azimuthDeg,e.altitudeDeg);s.push(c[0],c[1],c[2])}t.setAttribute("color",new Et(s,3));const r=new js({vertexColors:!0,side:It,fog:!1});this.skyMesh=new Mt(t,r),this.celestialGroup.add(this.skyMesh)}buildGround(){this.disposeMesh(this.groundMesh),this.groundRadius=du(this.observerElevationM);const e=new fc(this.groundRadius,48),t=new nr({color:new Me(So,So,So),fog:!0});this.groundMesh=new Mt(e,t),this.groundMesh.rotation.x=-Math.PI/2,this.groundMesh.position.y=0,this.groundMesh.receiveShadow=!0,this.scene.add(this.groundMesh)}setBodyMesh(e,t,n,s,r){if(this.disposeMesh(this.bodyMeshes.get(e)),this.disposeHitArea(e),this.disposeGlare(e),t.altitudeDeg<$l){this.bodyMeshes.delete(e),e==="sun"&&(this.sunVisible=!1);return}const{x:a,y:o,z:l}=ji(t.altitudeDeg,t.azimuthDeg,yo),c=Ls(t.altitudeDeg),h=new Me(s.r*c[0],s.g*c[1],s.b*c[2]),d=new ui(n,16,16),u=new js({color:h,fog:!1}),p=new Mt(d,u);if(p.position.set(a,o,l),this.celestialGroup.add(p),this.bodyMeshes.set(e,p),this.setHitArea(e,a,o,l,n),e!=="sun"&&this.setGlare(e,a,o,l,r,h),e==="sun"){this.sunVisible=!0;const g=this.celestialGroup.scale.x;this.sunWorldPosition.set(a*g,o*g+this.celestialGroup.position.y,l*g),this.lensFlare||(this.lensFlare=vx(),this.lensFlare.uniforms.uOpacity.value=mu*this.dazzleIntensity,this.lensFlare.uniforms.uFlareIntensity.value=this.lensFlareArtifactIntensity,this.scene.add(this.lensFlare.mesh)),this.applyLensFlareTint(c)}}setMoonMesh(e){const t="moon";if(this.disposeMesh(this.bodyMeshes.get(t)),this.disposeHitArea(t),this.disposeGlare(t),e.altitudeDeg<$l){this.bodyMeshes.delete(t);return}const{x:n,y:s,z:r}=ji(e.altitudeDeg,e.azimuthDeg,yo),a=Ls(e.altitudeDeg),o=new Me(a[0],a[1],a[2]),l=new ks({map:D3(e.phase),color:o,fog:!1}),c=new Mr(l);c.position.set(n,s,r);const h=Eo*2;c.scale.set(h,h,1),this.celestialGroup.add(c),this.bodyMeshes.set(t,c),this.setHitArea(t,n,s,r,Eo),this.setGlare(t,n,s,r,e.magnitude,o)}setHitArea(e,t,n,s,r){const a=new ks({transparent:!0,opacity:0,depthTest:!1,depthWrite:!1,fog:!1}),o=new Mr(a);o.position.set(t,n,s);const l=r*kx;o.scale.set(l,l,1),this.celestialGroup.add(o),this.hitAreas.set(e,o)}disposeHitArea(e){const t=this.hitAreas.get(e);t&&(t.removeFromParent(),t.material.dispose(),this.hitAreas.delete(e))}setGlare(e,t,n,s,r,a){this.disposeGlare(e);const o=bv(r);if(o<=0)return;const l=wv(o),c=new ks({map:I3(),color:a,transparent:!0,opacity:Pv(o),blending:ra,depthWrite:!1,fog:!1}),h=new Mr(c);h.position.set(t,n,s),h.scale.set(l*2,l*2,1),this.celestialGroup.add(h),this.glareSprites.set(e,h)}disposeGlare(e){const t=this.glareSprites.get(e);t&&(t.removeFromParent(),t.material.dispose(),this.glareSprites.delete(e))}buildPlanets(e){const t=new Set(["sun","moon"]);for(const n of e){t.add(n.body);const s=Yh(n.magnitude),r=Zh(s),a=S3[n.body]??new Me(1,1,1),o=new Me(a.r*r,a.g*r,a.b*r),l=Bx*(.5+.5*s);this.setBodyMesh(n.body,n.position,l,o,n.magnitude)}for(const n of[...this.bodyMeshes.keys()])t.has(n)||(this.disposeMesh(this.bodyMeshes.get(n)),this.bodyMeshes.delete(n),this.disposeHitArea(n),this.disposeGlare(n))}buildStars(e,t){if(this.disposeStarTiers(),!e||e.catalog.count===0){this.syncAnimationLoop();return}const{catalog:n,date:s,observer:r}=e,a=gv(t),o=Ro(1337),l=[];for(let c=0;c<n.count;c++){const h=n.mag[c];if(h>a)continue;const{altitudeDeg:d,azimuthDeg:u}=I2(n.ra[c],n.dec[c],s,r);if(d<zx)continue;const{x:p,y:g,z:x}=ji(d,u,Ox);l.push({x:p,y:g,z:x,brightness:Yh(h),phase:o()*Math.PI*2,speedFactor:.7+o()*.6})}this.starTiers=y0.map((c,h)=>{const d=l.filter(M=>Dv(M.brightness)===h),u=new Float32Array(d.length*3),p=new Float32Array(d.length),g=new Float32Array(d.length),x=new Float32Array(d.length);d.forEach((M,y)=>{u[y*3]=M.x,u[y*3+1]=M.y,u[y*3+2]=M.z,p[y]=M.brightness,g[y]=M.phase,x[y]=M.speedFactor});const m=new bt;m.setAttribute("position",new pt(u,3));const f=new pt(new Float32Array(d.length*3),3);m.setAttribute("color",f);const A=new r0({vertexColors:!0,size:c.size,sizeAttenuation:!1,fog:!1}),w=new na(m,A);return this.celestialGroup.add(w),{points:w,colorAttribute:f,brightness:p,phase:g,speedFactor:x}}),this.updateTwinkle(0),this.startTwinkle()}updateTwinkle(e){for(const t of this.starTiers){const n=t.colorAttribute.array;for(let s=0;s<t.brightness.length;s++){const r=Uv(t.brightness[s],{phase:t.phase[s],speedFactor:t.speedFactor[s]},e),a=Zh(t.brightness[s])*r;n[s*3]=a,n[s*3+1]=a,n[s*3+2]=a}t.colorAttribute.needsUpdate=!0}}buildClouds(){if(this.disposeCloudSystem(),this.weather.cloudCover<=0)return;const e=this.weather.cloudDarkness,t=new Me(ns[0]+(Ao[0]-ns[0])*e,ns[1]+(Ao[1]-ns[1])*e,ns[2]+(Ao[2]-ns[2])*e),{material:n,uniforms:s}=dx(t,this.weather.cloudCover,Math.abs(this.cloudLayerOffset()));this.cloudMaterial=n,this.cloudUniforms=s,this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor);const r=px(jx);this.cloudMesh=new Mt(r,n),this.cloudLayerOffset()<0&&(this.cloudMesh.scale.y=-1),this.cloudMesh.renderOrder=i3,this.celestialGroup.add(this.cloudMesh)}syncCloudLayer(){const e=this.cloudLayerOffset();this.cloudUniforms&&(this.cloudUniforms.layerHeight.value=Math.abs(e)),this.cloudMesh&&(this.cloudMesh.scale.y=e<0?-1:1)}cloudLayerOffset(){const t=((this.weather.cloudBaseM??Po)-this.observerElevationM)*e3;return Math.sign(t||1)*Math.max(Math.abs(t),t3)}updateCloudLighting(e,t){if(!this.cloudUniforms)return;const{x:n,y:s,z:r}=ji(e.altitudeDeg,e.azimuthDeg,1),a=Ls(e.altitudeDeg),o=Math.max(0,Math.sin(Math.max(e.altitudeDeg,0)*mn));this.cloudUniforms.sunDir.value.set(n,s,r),this.cloudUniforms.sunColor.value.setRGB(a[0]*o,.96*a[1]*o,.88*a[2]*o),this.cloudUniforms.ambientColor.value.setRGB(t[0],t[1],t[2])}disposeCloudSystem(){this.cloudMesh&&(this.cloudMesh.removeFromParent(),this.cloudMesh.geometry.dispose()),this.cloudMaterial?.dispose(),this.cloudMesh=void 0,this.cloudMaterial=void 0,this.cloudUniforms=void 0}disposePrecipitationPoints(){this.precipitationPoints&&(this.precipitationPoints.removeFromParent(),this.precipitationPoints.geometry.dispose(),this.precipitationPoints.material.dispose()),this.precipitationPoints=void 0,this.precipitationPositions=void 0,this.precipitationPhase=void 0,this.precipitationSpeedJitter=void 0,this.precipitationWobbleFreqJitter=void 0,this.precipitationWobbleAmpJitter=void 0,this.precipitationBounceRemaining=void 0,this.precipitationBounceHeight=void 0,this.precipitationBounceDuration=void 0,this.precipitationBounceVelX=void 0,this.precipitationBounceVelZ=void 0,this.precipitationUniforms=void 0}buildPrecipitation(){this.disposePrecipitationPoints(),this.disposeRain();const e=this.weather.precipitationType;if(e==="none")return;if(e==="rain"){this.buildRain();return}const t=gu[e],n=t.poolSize,s=Ro(9001),r=new Float32Array(n*3),a=new Float32Array(n),o=new Float32Array(n),l=new Float32Array(n),c=new Float32Array(n),h=new Float32Array(n),d=new Float32Array(n),u=new Float32Array(n),p=new Float32Array(n),g=new Float32Array(n);for(let w=0;w<n;w++){const M=s()*Math.PI*2,y=s()*t.radiusM;r[w*3]=Math.cos(M)*y,r[w*3+1]=rs+s()*(t.topYM-rs),r[w*3+2]=Math.sin(M)*y,a[w]=s()*Math.PI*2,o[w]=.7+s()*.6,l[w]=.6+s()*.8,c[w]=.4+s()*1.2}const x=new bt;x.setAttribute("position",new pt(r,3)),x.setDrawRange(0,wo(n,this.weather.precipitationIntensity));const m={uSize:{value:t.size},uScale:{value:.5*this.renderer.domElement.height},uOpacity:{value:t.opacity},uColor:{value:t.color},uHazeColor:{value:new Me(...this.baseFogColor)},uTexture:{value:E3(e)},uNearFocusDistance:{value:yu},uHazeDistance:{value:t.radiusM*Eu}},f=new Gt({uniforms:m,vertexShader:C3,fragmentShader:P3,transparent:!0,depthWrite:!1});this.precipitationUniforms=m;const A=new na(x,f);A.renderOrder=To,this.scene.add(A),this.precipitationPoints=A,this.precipitationPositions=r,this.precipitationPhase=a,this.precipitationSpeedJitter=o,this.precipitationWobbleFreqJitter=l,this.precipitationWobbleAmpJitter=c,this.precipitationBounceRemaining=h,this.precipitationBounceHeight=d,this.precipitationBounceDuration=u,this.precipitationBounceVelX=p,this.precipitationBounceVelZ=g}updatePrecipitation(e,t){if(!this.precipitationPoints||!this.precipitationPositions||!this.precipitationPhase||!this.precipitationSpeedJitter||(this.precipitationUniforms?.uHazeColor.value.setRGB(...this.baseFogColor),t<=0))return;const n=this.weather.precipitationType;if(n==="none"||n==="rain")return;const s=gu[n],r=this.weather.windDirectionDeg*mn,a=Math.sin(r)*this.weather.windSpeed*s.driftSensitivity,o=-Math.cos(r)*this.weather.windSpeed*s.driftSensitivity,l=this.precipitationPositions,c=this.precipitationPhase,h=this.precipitationSpeedJitter,d=this.precipitationWobbleFreqJitter,u=this.precipitationWobbleAmpJitter,p=this.precipitationBounceRemaining,g=this.precipitationBounceHeight,x=this.precipitationBounceDuration,m=this.precipitationBounceVelX,f=this.precipitationBounceVelZ,A=n==="snow"&&d&&u,w=n==="hail"&&p&&g&&x&&m&&f;for(let M=0,y=0;M<l.length;M+=3,y++){if(w&&p[y]>0){if(p[y]-=t,p[y]<=0){const v=Math.random()*Math.PI*2,E=Math.sqrt(Math.random())*s.radiusM;l[M]=Math.cos(v)*E,l[M+1]=s.topYM,l[M+2]=Math.sin(v)*E,p[y]=0}else{const v=1-p[y]/x[y];l[M+1]=rs+Math.sin(Math.PI*v)*g[y],l[M]=Yr(l[M]+(a+m[y])*t,s.radiusM),l[M+2]=Yr(l[M+2]+(o+f[y])*t,s.radiusM)}continue}let b=0,R=0;if(A){const v=m3*d[y],E=g3*u[y];b=Math.sin(e*v*Math.PI*2+c[y])*E,R=Math.sin(e*v*Math.PI*2+c[y]+Math.PI/2)*E}if(l[M]+=(a+b)*t,l[M+1]-=s.fallSpeedMPerS*h[y]*t,l[M+2]+=(o+R)*t,l[M]=Yr(l[M],s.radiusM),l[M+2]=Yr(l[M+2],s.radiusM),l[M+1]<rs){if(w){g[y]=Ru*(.2+Math.random()*1.6),x[y]=_3*(.5+Math.random()),p[y]=x[y];const P=Math.random()*Math.PI*2,C=v3*(g[y]/Ru);m[y]=Math.cos(P)*C,f[y]=Math.sin(P)*C,l[M+1]=rs;continue}const v=Math.random()*Math.PI*2,E=Math.sqrt(Math.random())*s.radiusM;l[M]=Math.cos(v)*E,l[M+1]=s.topYM,l[M+2]=Math.sin(v)*E}}this.precipitationPoints.geometry.attributes.position.needsUpdate=!0}buildRain(){const e=l3(this.weather.precipitationIntensity);this.rainSystem=cx({count:_u,radiusM:Bs,heightM:r3,bottomYM:vu,overallSpeed:a3,color:c3,opacity:.85,visibleCount:wo(_u,this.weather.precipitationIntensity),speedStreak:d3(e),pixelSize:Tu,seed:9001,nearFocusDistanceM:yu,hazeDistanceM:Bs*Eu,hazeColor:new Me(...this.baseFogColor)}),this.rainLastVerticalFacing=-1,this.rainSystem.points.renderOrder=To,this.scene.add(this.rainSystem.points),this.buildRainSplashes()}buildRainSplashes(){const e=Ro(4242),t=new Float32Array(is*3),n=new Float32Array(is),s=new Float32Array(is),r=new Float32Array(is);for(let h=0;h<is;h++){const d=e()*Math.PI*2,u=Math.sqrt(e())*Bs;t[h*3]=Math.cos(d)*u,t[h*3+1]=vu,t[h*3+2]=Math.sin(d)*u,s[h]=qr(Mu,Su),n[h]=e()*s[h],r[h]=n[h]/s[h]}const a=new bt;a.setAttribute("position",new pt(t,3));const o=new pt(r,1);a.setAttribute("aLife",o),a.setDrawRange(0,wo(is,this.weather.precipitationIntensity));const l=new Gt({uniforms:{uMaxSize:{value:f3},uScale:{value:.5*this.renderer.domElement.height},uColor:{value:p3},uTexture:{value:A3()}},vertexShader:w3,fragmentShader:R3,transparent:!0,depthWrite:!1}),c=new na(a,l);c.renderOrder=To,this.scene.add(c),this.rainSplashSystem={points:c,positions:t,life:n,duration:s,lifeAttribute:o}}disposeRain(){this.rainSystem&&(this.rainSystem.points.removeFromParent(),this.rainSystem.points.geometry.dispose(),this.rainSystem.points.material.dispose()),this.rainSystem=void 0,this.disposeRainSplashes()}disposeRainSplashes(){this.rainSplashSystem&&(this.rainSplashSystem.points.removeFromParent(),this.rainSplashSystem.points.geometry.dispose(),this.rainSplashSystem.points.material.dispose()),this.rainSplashSystem=void 0}updateRain(e){const t=this.rainSystem;if(!t)return;t.uniforms.uTime.value+=e,t.uniforms.uHazeColor.value.setRGB(...this.baseFogColor);const n=this.weather.windDirectionDeg*mn,s=Math.sin(n)*this.weather.windSpeed,r=-Math.cos(n)*this.weather.windSpeed,a=Bs,o=c=>(c%(a*2)+a*3)%(a*2)-a;t.uniforms.uWindOffset.value.set(o(t.uniforms.uWindOffset.value.x+s*e),o(t.uniforms.uWindOffset.value.y+r*e)),this.camera.getWorldDirection(this.rainCameraDirection);const l=Math.abs(this.rainCameraDirection.y);if(Math.abs(l-this.rainLastVerticalFacing)>.001){this.rainLastVerticalFacing=l;const c=Au+(1-Au)*(1-l),h=wu+(1-wu)*(1-l);t.uniforms.uUvSquash.value=h,t.uniforms.uPixelSize.value=Tu*c*(.5+.5*h)}this.updateRainSplashes(e)}updateRainSplashes(e){const t=this.rainSplashSystem;if(!t||e<=0)return;const{positions:n,life:s,duration:r,lifeAttribute:a}=t,o=a.array;for(let l=0,c=0;l<n.length;l+=3,c++){if(s[c]+=e,s[c]>=r[c]){const h=Math.random()*Math.PI*2,d=Math.sqrt(Math.random())*Bs;n[l]=Math.cos(h)*d,n[l+2]=Math.sin(h)*d,r[c]=qr(Mu,Su),s[c]=0}o[c]=s[c]/r[c]}t.points.geometry.attributes.position.needsUpdate=!0,a.needsUpdate=!0}updateLightning(e,t){if(this.lightningArmed){if(this.lightningFlashRemainingS>0){this.lightningFlashRemainingS=Math.max(0,this.lightningFlashRemainingS-t);const n=this.lightningFlashRemainingS/Iu;this.scene.fog&&this.scene.fog.color.setRGB(this.baseFogColor[0]+(1-this.baseFogColor[0])*n,this.baseFogColor[1]+(1-this.baseFogColor[1])*n,this.baseFogColor[2]+(1-this.baseFogColor[2])*n);return}if(this.nextLightningAtS===null){this.nextLightningAtS=e+qr(Cu,Pu);return}e>=this.nextLightningAtS&&(this.lightningFlashRemainingS=Iu,this.nextLightningAtS=e+qr(Cu,Pu),this.onLightningFlash?.())}}buildCompassLabels(){const e=Jl(navigator.languages,Zx),t=Yx[e];this.compassSprites=qx.map((n,s)=>{const r=t[s],a=new ks({map:L3(r),depthTest:!1,fog:!1}),o=new Mr(a),{x:l,y:c,z:h}=ji(0,n,$x);return o.position.set(l,c,h),o.scale.set(pu,pu,1),o.renderOrder=Kx,o.visible=this.compassHovered||this.compassForced,this.celestialGroup.add(o),o})}disposeCompassLabels(){for(const e of this.compassSprites)e.removeFromParent(),e.material.map?.dispose(),e.material.dispose();this.compassSprites=[]}disposeStarTiers(){for(const e of this.starTiers)this.disposeMesh(e.points);this.starTiers=[]}disposeMesh(e){if(!e)return;e.removeFromParent(),"geometry"in e&&e.geometry.dispose();const t=e.material;for(const n of Array.isArray(t)?t:[t]){const s=n.map;s&&s.dispose(),n.dispose()}}}const mn=Math.PI/180;function td(i,e,t){return Math.max(e,Math.min(t,i))}function qr(i,e){return i+Math.random()*(e-i)}function Yr(i,e){return(i%(e*2)+e*3)%(e*2)-e}let Zr,$r;function E3(i){switch(i){case"snow":return b3();case"hail":return T3()}}function b3(){if(Zr)return Zr;const i=64,e=document.createElement("canvas");e.width=i,e.height=i;const t=e.getContext("2d"),n=t.createRadialGradient(i/2,i/2,0,i/2,i/2,i/2);return n.addColorStop(0,"rgba(255,255,255,0.95)"),n.addColorStop(.5,"rgba(255,255,255,0.55)"),n.addColorStop(1,"rgba(255,255,255,0)"),t.fillStyle=n,t.fillRect(0,0,i,i),Zr=new Wn(e),Zr}function T3(){if($r)return $r;const i=64,e=document.createElement("canvas");e.width=i,e.height=i;const t=e.getContext("2d"),n=t.createRadialGradient(i/2,i/2,0,i/2,i/2,i/2);return n.addColorStop(0,"rgba(255,255,255,1)"),n.addColorStop(.55,"rgba(255,255,255,0.95)"),n.addColorStop(.8,"rgba(255,255,255,0.4)"),n.addColorStop(1,"rgba(255,255,255,0)"),t.fillStyle=n,t.fillRect(0,0,i,i),$r=new Wn(e),$r}let Kr;function A3(){if(Kr)return Kr;const i=64,e=document.createElement("canvas");e.width=i,e.height=i;const t=e.getContext("2d"),n=t.createRadialGradient(i/2,i/2,0,i/2,i/2,i/2);return n.addColorStop(0,"rgba(255,255,255,0)"),n.addColorStop(.4,"rgba(255,255,255,0)"),n.addColorStop(.6,"rgba(255,255,255,0.9)"),n.addColorStop(.8,"rgba(255,255,255,0.25)"),n.addColorStop(1,"rgba(255,255,255,0)"),t.fillStyle=n,t.fillRect(0,0,i,i),Kr=new Wn(e),Kr}const w3=`
5038
5038
  uniform float uMaxSize;
5039
5039
  uniform float uScale;
5040
5040
  attribute float aLife;
@@ -5099,4 +5099,4 @@ void main() {
5099
5099
  float blur = max(vNearBlur, vHaze);
5100
5100
  gl_FragColor = vec4(color, tex.a * uOpacity * (1.0 - blur * 0.5));
5101
5101
  }
5102
- `;let Jr;function I3(){if(Jr)return Jr;const i=128,e=document.createElement("canvas");e.width=i,e.height=i;const t=e.getContext("2d"),n=t.createRadialGradient(i/2,i/2,0,i/2,i/2,i/2);return n.addColorStop(0,"rgba(255,255,255,1)"),n.addColorStop(.4,"rgba(255,255,255,0.35)"),n.addColorStop(1,"rgba(255,255,255,0)"),t.fillStyle=n,t.fillRect(0,0,i,i),Jr=new Wn(e),Jr}function D3(i){const t=document.createElement("canvas");t.width=128,t.height=128;const n=t.getContext("2d"),s=128/2-2,r=128/2,a=128/2,o="#2e2b26",l="#f4f1e2";n.fillStyle=o,n.beginPath(),n.arc(r,a,s,0,Math.PI*2),n.fill();const c=td(i.illuminatedFraction,0,1),h=i.phaseFraction<.5,d=s*Math.abs(1-2*c),u=c<.5;return n.save(),n.beginPath(),n.arc(r,a,s,0,Math.PI*2),n.clip(),n.fillStyle=l,n.beginPath(),h?(n.arc(r,a,s,-Math.PI/2,Math.PI/2,!1),n.ellipse(r,a,d,s,0,Math.PI/2,-Math.PI/2,u)):(n.arc(r,a,s,Math.PI/2,-Math.PI/2,!1),n.ellipse(r,a,d,s,0,-Math.PI/2,Math.PI/2,u)),n.fill(),n.restore(),new Wn(t)}function L3(i){const e=document.createElement("canvas");e.width=128,e.height=128;const t=e.getContext("2d");return t.fillStyle="rgba(0, 0, 0, 0.55)",t.beginPath(),t.arc(64,64,60,0,Math.PI*2),t.fill(),t.fillStyle="#ffffff",t.font="bold 52px sans-serif",t.textAlign="center",t.textBaseline="middle",t.fillText(i,64,68),new Wn(e)}function Ro(i){let e=i;return function(){e|=0,e=e+1831565813|0;let n=Math.imul(e^e>>>15,1|e);return n=n+Math.imul(n^n>>>7,61|n)^n,((n^n>>>14)>>>0)/4294967296}}const Du=new Map;function N3(i){const e=i.byteLength/(4*Float32Array.BYTES_PER_ELEMENT),t=e,n=t*Float32Array.BYTES_PER_ELEMENT;return{count:e,ra:new Float32Array(i,0*n,t),dec:new Float32Array(i,1*n,t),mag:new Float32Array(i,2*n,t),ci:new Float32Array(i,3*n,t)}}function U3(i){let e=Du.get(i);return e||(e=fetch(i).then(t=>t.arrayBuffer()).then(N3),Du.set(i,e)),e}const F3=new URL(""+new URL("rain-BvWZrB9h.ogg",import.meta.url).href,import.meta.url).href,O3=new URL(""+new URL("wind-BjklexY7.ogg",import.meta.url).href,import.meta.url).href,B3=new URL(""+new URL("thunder-DA48qs_v.wav",import.meta.url).href,import.meta.url).href,z3=20,k3=1;class G3{context;buffers=new Map;ambientSource;ambientGain;ambientKey="none";ambientToken=0;ambientVolume=0;windSource;windGain;windActive=!1;windToken=0;windVolume=0;resume(){if(!this.context){if(typeof AudioContext>"u")return;try{this.context=new AudioContext}catch(e){console.warn("WeatherAudio: Web Audio unavailable, weather sounds disabled:",e);return}}this.context.state==="suspended"&&this.context.resume()}setAmbient(e,t,n){if(!this.context)return;const s=e==="rain"||e==="hail"?e:"none";if(this.ambientVolume=s==="hail"?Math.min(1,t*1.3+.2):s==="rain"?t:0,s!==this.ambientKey){this.ambientKey=s;const a=++this.ambientToken;this.stopSource(this.ambientSource,this.ambientGain),this.ambientSource=void 0,this.ambientGain=void 0,s!=="none"&&this.startLoop(F3,this.ambientVolume).then(o=>this.applyIfCurrent(o,a,()=>this.ambientToken,l=>{this.ambientSource=l?.source,this.ambientGain=l?.gain,l&&(l.gain.gain.value=this.ambientVolume)}))}else this.ambientGain&&(this.ambientGain.gain.value=this.ambientVolume);this.windVolume=Math.min(n/z3,1);const r=n>k3;if(r!==this.windActive){this.windActive=r;const a=++this.windToken;this.stopSource(this.windSource,this.windGain),this.windSource=void 0,this.windGain=void 0,r&&this.startLoop(O3,this.windVolume).then(o=>this.applyIfCurrent(o,a,()=>this.windToken,l=>{this.windSource=l?.source,this.windGain=l?.gain,l&&(l.gain.gain.value=this.windVolume)}))}else this.windGain&&(this.windGain.gain.value=this.windVolume)}playThunder(){this.context&&this.playOneShot(B3,.9)}dispose(){this.ambientToken++,this.windToken++,this.stopSource(this.ambientSource,this.ambientGain),this.stopSource(this.windSource,this.windGain),this.ambientSource=void 0,this.ambientGain=void 0,this.windSource=void 0,this.windGain=void 0,this.context?.close(),this.context=void 0,this.buffers.clear()}applyIfCurrent(e,t,n,s){if(t!==n()){e?.source.stop();return}s(e)}async startLoop(e,t){const n=this.context;if(n)try{const s=await this.getBuffer(e),r=n.createBufferSource();r.buffer=s,r.loop=!0;const a=n.createGain();return a.gain.value=t,r.connect(a).connect(n.destination),r.start(),{source:r,gain:a}}catch(s){console.warn("Weather ambient sound failed to load, staying silent:",s);return}}async playOneShot(e,t){const n=this.context;if(n)try{const s=await this.getBuffer(e),r=n.createBufferSource();r.buffer=s;const a=n.createGain();a.gain.value=t,r.connect(a).connect(n.destination),r.start()}catch(s){console.warn("Thunder sound failed to load:",s)}}async getBuffer(e){const t=this.context;if(!t)throw new Error("WeatherAudio: AudioContext not ready — resume() must be called first");let n=this.buffers.get(e);return n||(n=fetch(e).then(s=>{if(!s.ok)throw new Error(`Audio fetch failed (${s.status}): ${e}`);return s.arrayBuffer()}).then(s=>t.decodeAudioData(s)),this.buffers.set(e,n)),n}stopSource(e,t){try{e?.stop()}catch{}e?.disconnect(),t?.disconnect()}}Ou();const H3={sun:{en:"Sun",fr:"Soleil"},moon:{en:"Moon",fr:"Lune"},Venus:{en:"Venus",fr:"Vénus"},Mars:{en:"Mars",fr:"Mars"},Jupiter:{en:"Jupiter",fr:"Jupiter"},Saturn:{en:"Saturn",fr:"Saturne"}},V3=["en","fr"],W3={building:{en:"Building",fr:"Bâtiment"},tree:{en:"Tree",fr:"Arbre"},streetlight:{en:"Streetlight",fr:"Lampadaire"},vehicle:{en:"Vehicle",fr:"Véhicule"},witness:{en:"Witness",fr:"Témoin"}},X3=new URL(""+new URL("stars-mag7.5-DDr9QasD.bin",import.meta.url).href,import.meta.url).href,q3={sun:{altitudeDeg:-3,azimuthDeg:180,magnitude:-26.7},moon:{altitudeDeg:-90,azimuthDeg:0,phase:{phaseFraction:0,illuminatedFraction:0},magnitude:-12.7},planets:[]},Co={lat:0,lng:0,elevationM:0,headingDeg:void 0,pitchDeg:0,fovDeg:60};class Y3 extends HTMLElement{static get observedAttributes(){return["src","star-catalog-src","show-compass","lens-flare-intensity","lens-flare-brightness"]}shadow;stageElement;frameElement;sceneCanvas;ufoElement;sceneRenderer;hoverTooltip;resizeObserver;lastTimeMs=0;starCatalog;weatherAudio=new G3;thunderTimeoutId;handleFullscreenChange=()=>this.resizeToStage();handlePointerMove=e=>{this.sceneRenderer.setCompassHovered(!0);const t=this.ufoElement.canvasElement,n=t.getBoundingClientRect();if(n.width===0||n.height===0)return;const s=(e.clientX-n.left)/n.width*t.width,r=(e.clientY-n.top)/n.height*t.height;if(this.ufoElement.hasVisibleShapeAt(s,r)){this.hoverTooltip.hidden=!0;return}const a=(e.clientX-n.left)/n.width*2-1,o=-((e.clientY-n.top)/n.height*2-1),l=Jl(navigator.languages,V3),c=this.sceneRenderer.pickBodyAt(a,o);if(c){this.showHoverTooltip(e,H3[c]?.[l]??c);return}const h=this.sceneRenderer.pickDecorAt(a,o),d=h?this.ufoElement.sighting.decor.find(u=>u.id===h):void 0;if(d){this.showHoverTooltip(e,d.title||W3[d.kind][l]);return}this.hoverTooltip.hidden=!0};showHoverTooltip(e,t){this.hoverTooltip.textContent=t,this.hoverTooltip.hidden=!1;const n=this.stageElement.getBoundingClientRect();this.hoverTooltip.style.left=`${e.clientX-n.left+12}px`,this.hoverTooltip.style.top=`${e.clientY-n.top+12}px`}handlePointerLeave=()=>{this.hoverTooltip.hidden=!0,this.sceneRenderer.setCompassHovered(!1)};handleLightningFlash=()=>{clearTimeout(this.thunderTimeoutId);const e=(.5+Math.random()*3.5)*1e3;this.thunderTimeoutId=window.setTimeout(()=>this.weatherAudio.playThunder(),e)};handleFirstInteraction=()=>{this.weatherAudio.resume(),this.setWeather(Lc(this.ufoElement.sighting,this.lastTimeMs))};handleTimeUpdate=e=>{this.lastTimeMs=e.detail.time,this.updateAstronomy(this.lastTimeMs),this.updateUfoOcclusion(this.lastTimeMs)};constructor(){super(),this.shadow=this.attachShadow({mode:"open"});const e=document.createElement("template");e.innerHTML=`<style>${hd}</style>${cd}`,this.shadow.appendChild(e.content.cloneNode(!0)),this.stageElement=this.shadow.getElementById("stage"),this.frameElement=this.shadow.getElementById("frame"),this.sceneCanvas=this.shadow.getElementById("scene-canvas"),this.sceneRenderer=new y3(this.sceneCanvas,void 0,this.handleLightningFlash),this.hoverTooltip=this.shadow.getElementById("hover-tooltip"),this.ufoElement=document.createElement(Lo),this.ufoElement.classList.add("ufo-overlay"),this.ufoElement.style.setProperty("--ufo-canvas-background","transparent"),this.ufoElement.style.setProperty("--ufo-canvas-border","none"),this.ufoElement.fullscreenTarget=this.stageElement,this.shadow.getElementById("ufo-slot").replaceWith(this.ufoElement),this.ufoElement.addEventListener("timeupdate",this.handleTimeUpdate),this.ufoElement.canvasElement.addEventListener("pointermove",this.handlePointerMove),this.ufoElement.canvasElement.addEventListener("pointerleave",this.handlePointerLeave),this.ufoElement.canvasElement.addEventListener("pointerdown",this.handleFirstInteraction,{once:!0})}connectedCallback(){this.resizeToStage(),this.updateAstronomy(this.lastTimeMs),this.loadStars(),this.resizeObserver=new ResizeObserver(()=>this.resizeToStage()),this.resizeObserver.observe(this.frameElement),document.addEventListener("fullscreenchange",this.handleFullscreenChange);const e=this.getAttribute("src");e&&this.loadFromSrc(e)}disconnectedCallback(){this.resizeObserver?.disconnect(),document.removeEventListener("fullscreenchange",this.handleFullscreenChange),this.sceneRenderer.stopTwinkle(),clearTimeout(this.thunderTimeoutId),this.weatherAudio.dispose()}attributeChangedCallback(e,t,n){if(e==="src"&&n&&n!==t&&this.isConnected&&this.loadFromSrc(n),e==="star-catalog-src"&&n!==t&&this.isConnected&&this.loadStars(),e==="show-compass"&&n!==t&&this.sceneRenderer.setShowCompass(this.hasAttribute("show-compass")),e==="lens-flare-intensity"&&n!==t){const s=n===null?NaN:parseFloat(n);this.sceneRenderer.setLensFlareArtifactIntensity(Number.isFinite(s)?s:0)}if(e==="lens-flare-brightness"&&n!==t){const s=n===null?NaN:parseFloat(n);this.sceneRenderer.setDazzleIntensity(Number.isFinite(s)?s:1)}}setCompassForced(e){this.sceneRenderer.setCompassForced(e)}setIndoorLook(e,t){this.sceneRenderer.setIndoorLook(e,t)}setWeather(e){this.sceneRenderer.setWeather(e),this.weatherAudio.setAmbient(e.precipitationType,e.precipitationIntensity,e.windSpeed)}pickDecorAt(e,t){return this.sceneRenderer.pickDecorAt(e,t)}resumeWeatherAudio(){this.weatherAudio.resume()}async loadFromSrc(e){const t=await fetch(e);this.sightingData=await t.json()}get sightingData(){return this.ufoElement.sightingData}set sightingData(e){this.ufoElement.sightingData=e,this.lastTimeMs=0,this.updateAstronomy(0)}get currentTerrainAttribution(){return this.sceneRenderer.currentTerrainAttribution}setTerrainProviders(e){this.sceneRenderer.setTerrainProviders(e)}resizeToStage(){const e=this.frameElement.getBoundingClientRect(),t=Math.max(1,Math.round(e.width)),n=Math.max(1,Math.round(e.height));this.sceneCanvas.width=t,this.sceneCanvas.height=n,this.sceneRenderer.resize(t,n)}async loadStars(){const e=this.getAttribute("star-catalog-src")??X3;this.starCatalog=await U3(e),this.updateAstronomy(this.lastTimeMs)}updateAstronomy(e){const t=this.ufoElement.sighting;this.setWeather(Lc(t,e)),this.sceneRenderer.setDecor(t.decor);const n=Dc(t,e);this.sceneRenderer.setObserverPose(n??Co),this.sceneRenderer.updateDecorAnchoring(Dc(t,0),n),this.sceneRenderer.updateDecorLitState(e),this.sceneRenderer.setTerrainOrigin(n?.lat,n?.lng);const s=n?.lat??Co.lat,r=n?.lng??Co.lng,a=F2(t.event.time??{},r,t.event.utcOffsetHours);if(!a){this.sceneRenderer.setAstronomy(q3);return}const o=new Date(a.getTime()+e),l={lat:s,lng:r,elevationM:n?.elevationM??0},c={...mo("Sun",o,l),magnitude:go("Sun",o)},h={...mo("Moon",o,l),phase:D2(o),magnitude:go("Moon",o)},d=P2.map(u=>({body:u,position:mo(u,o,l),magnitude:go(u,o)}));this.sceneRenderer.setAstronomy({sun:c,moon:h,planets:d,stars:this.starCatalog?{catalog:this.starCatalog,date:o,observer:l}:void 0})}updateUfoOcclusion(e){const t=this.ufoElement.sighting.timeline,n=this.ufoElement.canvasElement,s=new Set;for(const r of t.sourceIds){const a=t.getInterpolatedShapeAt(e,r);if(!a)continue;const o=(a.bounds.x+a.bounds.width/2)/n.width*2-1,l=-((a.bounds.y+a.bounds.height/2)/n.height*2-1),c={declared:a.behindCloud,distanceM:a.physical?.distanceM};this.sceneRenderer.isScreenPointOccluded(o,l,r,c)&&s.add(r)}this.ufoElement.setOccludedSourceIds(s)}}const Lu="rr0-scene";function Z3(){Ou(),customElements.get(Lu)||customElements.define(Lu,Y3)}Z3();
5102
+ `;let Jr;function I3(){if(Jr)return Jr;const i=128,e=document.createElement("canvas");e.width=i,e.height=i;const t=e.getContext("2d"),n=t.createRadialGradient(i/2,i/2,0,i/2,i/2,i/2);return n.addColorStop(0,"rgba(255,255,255,1)"),n.addColorStop(.4,"rgba(255,255,255,0.35)"),n.addColorStop(1,"rgba(255,255,255,0)"),t.fillStyle=n,t.fillRect(0,0,i,i),Jr=new Wn(e),Jr}function D3(i){const t=document.createElement("canvas");t.width=128,t.height=128;const n=t.getContext("2d"),s=128/2-2,r=128/2,a=128/2,o="#2e2b26",l="#f4f1e2";n.fillStyle=o,n.beginPath(),n.arc(r,a,s,0,Math.PI*2),n.fill();const c=td(i.illuminatedFraction,0,1),h=i.phaseFraction<.5,d=s*Math.abs(1-2*c),u=c<.5;return n.save(),n.beginPath(),n.arc(r,a,s,0,Math.PI*2),n.clip(),n.fillStyle=l,n.beginPath(),h?(n.arc(r,a,s,-Math.PI/2,Math.PI/2,!1),n.ellipse(r,a,d,s,0,Math.PI/2,-Math.PI/2,u)):(n.arc(r,a,s,Math.PI/2,-Math.PI/2,!1),n.ellipse(r,a,d,s,0,-Math.PI/2,Math.PI/2,u)),n.fill(),n.restore(),new Wn(t)}function L3(i){const e=document.createElement("canvas");e.width=128,e.height=128;const t=e.getContext("2d");return t.fillStyle="rgba(0, 0, 0, 0.55)",t.beginPath(),t.arc(64,64,60,0,Math.PI*2),t.fill(),t.fillStyle="#ffffff",t.font="bold 52px sans-serif",t.textAlign="center",t.textBaseline="middle",t.fillText(i,64,68),new Wn(e)}function Ro(i){let e=i;return function(){e|=0,e=e+1831565813|0;let n=Math.imul(e^e>>>15,1|e);return n=n+Math.imul(n^n>>>7,61|n)^n,((n^n>>>14)>>>0)/4294967296}}const Du=new Map;function N3(i){const e=i.byteLength/(4*Float32Array.BYTES_PER_ELEMENT),t=e,n=t*Float32Array.BYTES_PER_ELEMENT;return{count:e,ra:new Float32Array(i,0*n,t),dec:new Float32Array(i,1*n,t),mag:new Float32Array(i,2*n,t),ci:new Float32Array(i,3*n,t)}}function U3(i){let e=Du.get(i);return e||(e=fetch(i).then(t=>t.arrayBuffer()).then(N3),Du.set(i,e)),e}const F3=new URL(""+new URL("rain-BvWZrB9h.ogg",import.meta.url).href,import.meta.url).href,O3=new URL(""+new URL("wind-BjklexY7.ogg",import.meta.url).href,import.meta.url).href,B3=new URL(""+new URL("thunder-DA48qs_v.wav",import.meta.url).href,import.meta.url).href,z3=20,k3=1;class G3{context;buffers=new Map;ambientSource;ambientGain;ambientKey="none";ambientToken=0;ambientVolume=0;windSource;windGain;windActive=!1;windToken=0;windVolume=0;paused=!0;requested={type:"none",intensity:0,windSpeed:0};resume(){if(!this.context){if(typeof AudioContext>"u")return;try{this.context=new AudioContext}catch(e){console.warn("WeatherAudio: Web Audio unavailable, weather sounds disabled:",e);return}}this.context.state==="suspended"&&this.context.resume()}setAmbient(e,t,n){if(this.requested={type:e,intensity:t,windSpeed:n},!this.context)return;this.paused&&(e="none",t=0,n=0);const s=e==="rain"||e==="hail"?e:"none";if(this.ambientVolume=s==="hail"?Math.min(1,t*1.3+.2):s==="rain"?t:0,s!==this.ambientKey){this.ambientKey=s;const a=++this.ambientToken;this.stopSource(this.ambientSource,this.ambientGain),this.ambientSource=void 0,this.ambientGain=void 0,s!=="none"&&this.startLoop(F3,this.ambientVolume).then(o=>this.applyIfCurrent(o,a,()=>this.ambientToken,l=>{this.ambientSource=l?.source,this.ambientGain=l?.gain,l&&(l.gain.gain.value=this.ambientVolume)}))}else this.ambientGain&&(this.ambientGain.gain.value=this.ambientVolume);this.windVolume=Math.min(n/z3,1);const r=n>k3;if(r!==this.windActive){this.windActive=r;const a=++this.windToken;this.stopSource(this.windSource,this.windGain),this.windSource=void 0,this.windGain=void 0,r&&this.startLoop(O3,this.windVolume).then(o=>this.applyIfCurrent(o,a,()=>this.windToken,l=>{this.windSource=l?.source,this.windGain=l?.gain,l&&(l.gain.gain.value=this.windVolume)}))}else this.windGain&&(this.windGain.gain.value=this.windVolume)}setPaused(e){if(e===this.paused)return;this.paused=e;const{type:t,intensity:n,windSpeed:s}=this.requested;this.setAmbient(t,n,s)}playThunder(){!this.context||this.paused||this.playOneShot(B3,.9)}dispose(){this.ambientToken++,this.windToken++,this.stopSource(this.ambientSource,this.ambientGain),this.stopSource(this.windSource,this.windGain),this.ambientSource=void 0,this.ambientGain=void 0,this.windSource=void 0,this.windGain=void 0,this.context?.close(),this.context=void 0,this.buffers.clear()}applyIfCurrent(e,t,n,s){if(t!==n()){e?.source.stop();return}s(e)}async startLoop(e,t){const n=this.context;if(n)try{const s=await this.getBuffer(e),r=n.createBufferSource();r.buffer=s,r.loop=!0;const a=n.createGain();return a.gain.value=t,r.connect(a).connect(n.destination),r.start(),{source:r,gain:a}}catch(s){console.warn("Weather ambient sound failed to load, staying silent:",s);return}}async playOneShot(e,t){const n=this.context;if(n)try{const s=await this.getBuffer(e),r=n.createBufferSource();r.buffer=s;const a=n.createGain();a.gain.value=t,r.connect(a).connect(n.destination),r.start()}catch(s){console.warn("Thunder sound failed to load:",s)}}async getBuffer(e){const t=this.context;if(!t)throw new Error("WeatherAudio: AudioContext not ready — resume() must be called first");let n=this.buffers.get(e);return n||(n=fetch(e).then(s=>{if(!s.ok)throw new Error(`Audio fetch failed (${s.status}): ${e}`);return s.arrayBuffer()}).then(s=>t.decodeAudioData(s)),this.buffers.set(e,n)),n}stopSource(e,t){try{e?.stop()}catch{}e?.disconnect(),t?.disconnect()}}Ou();const H3={sun:{en:"Sun",fr:"Soleil"},moon:{en:"Moon",fr:"Lune"},Venus:{en:"Venus",fr:"Vénus"},Mars:{en:"Mars",fr:"Mars"},Jupiter:{en:"Jupiter",fr:"Jupiter"},Saturn:{en:"Saturn",fr:"Saturne"}},V3=["en","fr"],W3={building:{en:"Building",fr:"Bâtiment"},tree:{en:"Tree",fr:"Arbre"},streetlight:{en:"Streetlight",fr:"Lampadaire"},vehicle:{en:"Vehicle",fr:"Véhicule"},witness:{en:"Witness",fr:"Témoin"}},X3=new URL(""+new URL("stars-mag7.5-DDr9QasD.bin",import.meta.url).href,import.meta.url).href,q3={sun:{altitudeDeg:-3,azimuthDeg:180,magnitude:-26.7},moon:{altitudeDeg:-90,azimuthDeg:0,phase:{phaseFraction:0,illuminatedFraction:0},magnitude:-12.7},planets:[]},Co={lat:0,lng:0,elevationM:0,headingDeg:void 0,pitchDeg:0,fovDeg:60};class Y3 extends HTMLElement{static get observedAttributes(){return["src","star-catalog-src","show-compass","lens-flare-intensity","lens-flare-brightness"]}shadow;stageElement;frameElement;sceneCanvas;ufoElement;sceneRenderer;hoverTooltip;resizeObserver;lastTimeMs=0;starCatalog;weatherAudio=new G3;thunderTimeoutId;handleFullscreenChange=()=>this.resizeToStage();handlePointerMove=e=>{this.sceneRenderer.setCompassHovered(!0);const t=this.ufoElement.canvasElement,n=t.getBoundingClientRect();if(n.width===0||n.height===0)return;const s=(e.clientX-n.left)/n.width*t.width,r=(e.clientY-n.top)/n.height*t.height;if(this.ufoElement.hasVisibleShapeAt(s,r)){this.hoverTooltip.hidden=!0;return}const a=(e.clientX-n.left)/n.width*2-1,o=-((e.clientY-n.top)/n.height*2-1),l=Jl(navigator.languages,V3),c=this.sceneRenderer.pickBodyAt(a,o);if(c){this.showHoverTooltip(e,H3[c]?.[l]??c);return}const h=this.sceneRenderer.pickDecorAt(a,o),d=h?this.ufoElement.sighting.decor.find(u=>u.id===h):void 0;if(d){this.showHoverTooltip(e,d.title||W3[d.kind][l]);return}this.hoverTooltip.hidden=!0};showHoverTooltip(e,t){this.hoverTooltip.textContent=t,this.hoverTooltip.hidden=!1;const n=this.stageElement.getBoundingClientRect();this.hoverTooltip.style.left=`${e.clientX-n.left+12}px`,this.hoverTooltip.style.top=`${e.clientY-n.top+12}px`}handlePointerLeave=()=>{this.hoverTooltip.hidden=!0,this.sceneRenderer.setCompassHovered(!1)};handleLightningFlash=()=>{clearTimeout(this.thunderTimeoutId);const e=(.5+Math.random()*3.5)*1e3;this.thunderTimeoutId=window.setTimeout(()=>this.weatherAudio.playThunder(),e)};handleFirstInteraction=()=>{this.weatherAudio.resume(),this.setWeather(Lc(this.ufoElement.sighting,this.lastTimeMs))};handleTimeUpdate=e=>{this.lastTimeMs=e.detail.time,this.syncAnimationsToPlayback(),this.updateAstronomy(this.lastTimeMs),this.updateUfoOcclusion(this.lastTimeMs)};syncAnimationsToPlayback(){const e=this.ufoElement.playbackState==="playing";this.sceneRenderer.setAnimationsRunning(e),this.weatherAudio.setPaused(!e),e||clearTimeout(this.thunderTimeoutId)}constructor(){super(),this.shadow=this.attachShadow({mode:"open"});const e=document.createElement("template");e.innerHTML=`<style>${hd}</style>${cd}`,this.shadow.appendChild(e.content.cloneNode(!0)),this.stageElement=this.shadow.getElementById("stage"),this.frameElement=this.shadow.getElementById("frame"),this.sceneCanvas=this.shadow.getElementById("scene-canvas"),this.sceneRenderer=new y3(this.sceneCanvas,void 0,this.handleLightningFlash),this.hoverTooltip=this.shadow.getElementById("hover-tooltip"),this.ufoElement=document.createElement(Lo),this.ufoElement.classList.add("ufo-overlay"),this.ufoElement.style.setProperty("--ufo-canvas-background","transparent"),this.ufoElement.style.setProperty("--ufo-canvas-border","none"),this.ufoElement.fullscreenTarget=this.stageElement,this.shadow.getElementById("ufo-slot").replaceWith(this.ufoElement),this.ufoElement.addEventListener("timeupdate",this.handleTimeUpdate),this.ufoElement.canvasElement.addEventListener("pointermove",this.handlePointerMove),this.ufoElement.canvasElement.addEventListener("pointerleave",this.handlePointerLeave),this.ufoElement.canvasElement.addEventListener("pointerdown",this.handleFirstInteraction,{once:!0})}connectedCallback(){this.resizeToStage(),this.updateAstronomy(this.lastTimeMs),this.loadStars(),this.resizeObserver=new ResizeObserver(()=>this.resizeToStage()),this.resizeObserver.observe(this.frameElement),document.addEventListener("fullscreenchange",this.handleFullscreenChange);const e=this.getAttribute("src");e&&this.loadFromSrc(e)}disconnectedCallback(){this.resizeObserver?.disconnect(),document.removeEventListener("fullscreenchange",this.handleFullscreenChange),this.sceneRenderer.stopTwinkle(),clearTimeout(this.thunderTimeoutId),this.weatherAudio.dispose()}attributeChangedCallback(e,t,n){if(e==="src"&&n&&n!==t&&this.isConnected&&this.loadFromSrc(n),e==="star-catalog-src"&&n!==t&&this.isConnected&&this.loadStars(),e==="show-compass"&&n!==t&&this.sceneRenderer.setShowCompass(this.hasAttribute("show-compass")),e==="lens-flare-intensity"&&n!==t){const s=n===null?NaN:parseFloat(n);this.sceneRenderer.setLensFlareArtifactIntensity(Number.isFinite(s)?s:0)}if(e==="lens-flare-brightness"&&n!==t){const s=n===null?NaN:parseFloat(n);this.sceneRenderer.setDazzleIntensity(Number.isFinite(s)?s:1)}}setCompassForced(e){this.sceneRenderer.setCompassForced(e)}setIndoorLook(e,t){this.sceneRenderer.setIndoorLook(e,t)}setWeather(e){this.sceneRenderer.setWeather(e),this.weatherAudio.setAmbient(e.precipitationType,e.precipitationIntensity,e.windSpeed)}pickDecorAt(e,t){return this.sceneRenderer.pickDecorAt(e,t)}resumeWeatherAudio(){this.weatherAudio.resume()}async loadFromSrc(e){const t=await fetch(e);this.sightingData=await t.json()}get sightingData(){return this.ufoElement.sightingData}set sightingData(e){this.ufoElement.sightingData=e,this.lastTimeMs=0,this.updateAstronomy(0)}get currentTerrainAttribution(){return this.sceneRenderer.currentTerrainAttribution}setTerrainProviders(e){this.sceneRenderer.setTerrainProviders(e)}resizeToStage(){const e=this.frameElement.getBoundingClientRect(),t=Math.max(1,Math.round(e.width)),n=Math.max(1,Math.round(e.height));this.sceneCanvas.width=t,this.sceneCanvas.height=n,this.sceneRenderer.resize(t,n)}async loadStars(){const e=this.getAttribute("star-catalog-src")??X3;this.starCatalog=await U3(e),this.updateAstronomy(this.lastTimeMs)}updateAstronomy(e){const t=this.ufoElement.sighting;this.setWeather(Lc(t,e)),this.sceneRenderer.setDecor(t.decor);const n=Dc(t,e);this.sceneRenderer.setObserverPose(n??Co),this.sceneRenderer.updateDecorAnchoring(Dc(t,0),n),this.sceneRenderer.updateDecorLitState(e),this.sceneRenderer.setTerrainOrigin(n?.lat,n?.lng);const s=n?.lat??Co.lat,r=n?.lng??Co.lng,a=F2(t.event.time??{},r,t.event.utcOffsetHours);if(!a){this.sceneRenderer.setAstronomy(q3);return}const o=new Date(a.getTime()+e),l={lat:s,lng:r,elevationM:n?.elevationM??0},c={...mo("Sun",o,l),magnitude:go("Sun",o)},h={...mo("Moon",o,l),phase:D2(o),magnitude:go("Moon",o)},d=P2.map(u=>({body:u,position:mo(u,o,l),magnitude:go(u,o)}));this.sceneRenderer.setAstronomy({sun:c,moon:h,planets:d,stars:this.starCatalog?{catalog:this.starCatalog,date:o,observer:l}:void 0})}updateUfoOcclusion(e){const t=this.ufoElement.sighting.timeline,n=this.ufoElement.canvasElement,s=new Set;for(const r of t.sourceIds){const a=t.getInterpolatedShapeAt(e,r);if(!a)continue;const o=(a.bounds.x+a.bounds.width/2)/n.width*2-1,l=-((a.bounds.y+a.bounds.height/2)/n.height*2-1),c={declared:a.behindCloud,distanceM:a.physical?.distanceM};this.sceneRenderer.isScreenPointOccluded(o,l,r,c)&&s.add(r)}this.ufoElement.setOccludedSourceIds(s)}}const Lu="rr0-scene";function Z3(){Ou(),customElements.get(Lu)||customElements.define(Lu,Y3)}Z3();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rr0/ufoathome",
3
3
  "type": "module",
4
- "version": "0.19.1",
4
+ "version": "0.19.2",
5
5
  "description": "UFO@home — record and replay a UFO sighting's shape, movement and appearance",
6
6
  "author": "Jérôme Beau <rr0@rr0.org> (https://rr0.org)",
7
7
  "license": "MIT",