@rr0/ufoathome 0.115.3 → 0.115.4

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.
@@ -2833,7 +2833,7 @@ canvas[data-cursor="rotate"] {
2833
2833
  `;class Ul{constructor(e){this.points=e}static STATIONARY_M=5;static of(e){const t=[];for(const i of e.observerTrack.allKeyframes){const{lat:n,lng:s,headingDeg:r}=i.pose;n===void 0||s===void 0||t.push({t:i.t,lat:n,lng:s,headingDeg:r})}if(t.length===0){const i=e.event.place?.[0];if(!i)return;t.push({t:0,lat:i.lat,lng:i.lng})}return new Ul(t)}static TRAVEL_M=50;get travels(){return this.spanM>Ul.TRAVEL_M}get moved(){return this.spanM>Ul.STATIONARY_M}get spanM(){const e=this.box,t=(e.south+e.north)/2,i=(e.west+e.east)/2;return Math.max(Math.abs(vt(t,e.east,t,e.west).x),Math.abs(vt(e.north,i,e.south,i).z))}get center(){const e=this.box;return{lat:(e.south+e.north)/2,lng:(e.west+e.east)/2}}boundsAround(e,t){const{lat:i,lng:n}=this.center,s=Math.max(this.spanM*(1+t),e)/2;return{north:us(0,-s,i,n).lat,south:us(0,s,i,n).lat,east:us(s,0,i,n).lng,west:us(-s,0,i,n).lng}}get box(){const e=this.points.map(i=>i.lat),t=this.points.map(i=>i.lng);return{south:Math.min(...e),north:Math.max(...e),west:Math.min(...t),east:Math.max(...t)}}}class bs{constructor(e,t){this.rotationPassed=e,this.scale=t}static SWAY_M=.012;static BREATH_M=.003;static DRIFT_YAW_DEG=.5;static DRIFT_PITCH_DEG=.4;static DRIFT_ROLL_DEG=.3;static GAZE_DRIFT_SHARE=.35;static HAND_HELD_S=.5;static HZ=[.11,.23,.17,.29,.37,.07];static of(e){const t=e.event.tags?.includes("paralysis")||(e.exposure??0)>bs.HAND_HELD_S,i=e.sway??(t?0:1);if(i>0)return new bs(Math.max(1-(e.instrument.stabilization??0),bs.GAZE_DRIFT_SHARE),i)}offsetAt(e){const t=e/1e3,i=this.scale,n=(d,u)=>Math.sin(2*Math.PI*d*t+u),[s,r,a,l,c,h]=bs.HZ;return{eastM:i*bs.SWAY_M*(.7*n(s,.3)+.3*n(l,1.9)),northM:i*bs.SWAY_M*(.6*n(a,2.2)+.4*n(c,.8)),upM:i*bs.BREATH_M*n(r,0),yawDeg:i*this.rotationPassed*bs.DRIFT_YAW_DEG*(.6*n(h,1.1)+.4*n(l,2.7)),pitchDeg:i*this.rotationPassed*bs.DRIFT_PITCH_DEG*(.5*n(r,1.6)+.5*n(a,.4)),rollDeg:i*this.rotationPassed*bs.DRIFT_ROLL_DEG*n(s,2.9)}}}class $t{constructor(e,t){this.stretches=e,this.rotationPassed=t}static REFERENCE_SPEED_M_PER_S=1.4;static REFERENCE_STEP_HZ=1.9;static CADENCE_EXPONENT=.43;static RISE_M_PER_M_PER_S=.0175;static SWAY_M=.0175;static SLOWEST_WALK_M_PER_S=.2;static FASTEST_WALK_M_PER_S=2.2;static HEAD_ROLL_DEG=1.5;static HEAD_PITCH_DEG=1.25;static HEAD_YAW_DEG=1;static STOP_LURCH_M=.035;static STOP_PITCH_DEG=3;static START_LURCH_M=.015;static START_PITCH_DEG=1.2;static JOLT_HZ=1.4;static JOLT_DECAY_S=.35;static JOLT_LASTS_MS=1500;static STILL=Object.freeze({eastM:0,northM:0,upM:0,rollDeg:0,pitchDeg:0,yawDeg:0});static of(e){const t=Ul.of(e);if(!t||t.points.length<2)return;const i=[];let n=0;for(let s=1;s<t.points.length;s++){const r=t.points[s-1],a=t.points[s],l=(a.t-r.t)/1e3;if(l<=0)continue;const c=vt(a.lat,a.lng,r.lat,r.lng),h=c.x,d=-c.z,u=Math.hypot(h,d),f=u/l,p=$t.stepHzFor(f);i.push({startMs:r.t,endMs:a.t,speedMPerS:f,eastUnit:u>0?h/u:0,northUnit:u>0?d/u:0,stepHz:p,stepsBefore:n,rampsIn:!0,rampsOut:!0}),n+=p*l}for(let s=0;s<i.length;s++){const r=i[s-1],a=i[s+1];i[s].rampsIn=r===void 0||r.stepHz===0,i[s].rampsOut=a===void 0||a.stepHz===0}if(i.some(s=>s.stepHz>0))return new $t(i,1-(e.instrument.stabilization??0))}static bodyAt(e,t,i=!1){const n=$t.of(e)?.offsetAt(t)??$t.STILL;return i?n:$t.add(n,bs.of(e)?.offsetAt(t))}static stepHzFor(e){return e<$t.SLOWEST_WALK_M_PER_S||e>$t.FASTEST_WALK_M_PER_S?0:$t.REFERENCE_STEP_HZ*Math.pow(e/$t.REFERENCE_SPEED_M_PER_S,$t.CADENCE_EXPONENT)}offsetAt(e){return $t.add(this.cycleAt(e),this.joltAt(e))}joltAt(e){for(const t of this.stretches){if(t.stepHz===0)continue;const i=t.speedMPerS/$t.REFERENCE_SPEED_M_PER_S,n=(a,l,c,h)=>{if(a<0||a>$t.JOLT_LASTS_MS)return;const d=a/1e3,u=Math.exp(-d/$t.JOLT_DECAY_S)*Math.sin(2*Math.PI*$t.JOLT_HZ*d),f=h*l*i*u;return{eastM:f*t.eastUnit,northM:f*t.northUnit,upM:-Math.abs(f)*.3,rollDeg:0,pitchDeg:-h*c*i*u*this.rotationPassed,yawDeg:0}},s=t.rampsOut?n(e-t.endMs,$t.STOP_LURCH_M,$t.STOP_PITCH_DEG,1):void 0;if(s)return s;const r=t.rampsIn?n(e-t.startMs,$t.START_LURCH_M,$t.START_PITCH_DEG,-1):void 0;if(r)return r}}static add(e,t){return t?{eastM:e.eastM+t.eastM,northM:e.northM+t.northM,upM:e.upM+t.upM,rollDeg:e.rollDeg+t.rollDeg,pitchDeg:e.pitchDeg+t.pitchDeg,yawDeg:e.yawDeg+t.yawDeg}:e}cycleAt(e){const t=this.stretches.find(l=>e>=l.startMs&&e<=l.endMs);if(!t||t.stepHz===0)return $t.STILL;const i=t.stepsBefore+t.stepHz*(e-t.startMs)/1e3,n=2*Math.PI*i,s=this.amplitudeAt(t,e),r=$t.SWAY_M*s*Math.cos(n/2),a=s*this.rotationPassed*t.speedMPerS/$t.REFERENCE_SPEED_M_PER_S;return{eastM:r*t.northUnit,northM:-r*t.eastUnit,upM:$t.RISE_M_PER_M_PER_S*t.speedMPerS*s*Math.cos(n),rollDeg:$t.HEAD_ROLL_DEG*a*Math.cos(n/2),pitchDeg:-1.25*a*Math.cos(n),yawDeg:$t.HEAD_YAW_DEG*a*Math.cos(n/2)}}amplitudeAt(e,t){const i=1e3/e.stepHz,n=Math.min(i,(e.endMs-e.startMs)/2);if(n<=0)return 1;const s=t-e.startMs,r=e.endMs-t,a=Math.min(e.rampsIn?s/n:1,e.rampsOut?r/n:1,1);return(1-Math.cos(Math.PI*Math.max(a,0)))/2}}class CS{constructor(e,t){this.timeline=e,this.onFrame=t}rafId=null;state="stopped";currentT=0;lastWallTime=0;playbackRate=1;loop=!1;onEnded;durationOverrideMs=0;get seekableDuration(){return Math.max(this.timeline.duration,this.durationOverrideMs)}play(){if(this.state==="playing")return;this.currentT>=this.seekableDuration&&(this.currentT=0,this.resolveFrame(0)),this.state="playing",this.lastWallTime=performance.now();const e=()=>{if(this.state!=="playing")return;const t=performance.now();if(this.currentT+=(t-this.lastWallTime)*this.playbackRate,this.lastWallTime=t,this.currentT>=this.seekableDuration){if(this.loop&&this.seekableDuration>0){this.currentT%=this.seekableDuration,this.resolveFrame(this.currentT),this.rafId=requestAnimationFrame(e);return}this.currentT=this.seekableDuration,this.stop(),this.resolveFrame(this.currentT),this.onEnded?.();return}this.resolveFrame(this.currentT),this.rafId=requestAnimationFrame(e)};this.rafId=requestAnimationFrame(e)}pause(){this.state==="playing"&&(this.state="paused",this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null))}stop(){this.state="stopped",this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null)}seek(e){this.currentT=Math.max(0,Math.min(e,this.seekableDuration)),this.resolveFrame(this.currentT)}get playbackState(){return this.state}get time(){return this.currentT}resolveFrame(e){const t=new Map;for(const i of this.timeline.sourceIds){const n=this.timeline.getInterpolatedShapeAt(e,i);n&&t.set(i,n)}this.onFrame(e,t)}}class To{static sessionDeclared=!1;static unlock(e){if(To.declarePlayback(),e.state!=="running")try{Promise.resolve(e.resume()).catch(()=>{});const t=e.createBufferSource();t.buffer=e.createBuffer(1,1,22050),t.connect(e.destination),t.start(0)}catch{}}static declarePlayback(){if(!(To.sessionDeclared||typeof navigator>"u")){To.sessionDeclared=!0;try{const e=navigator.audioSession;e&&(e.type="playback")}catch{}}}}const Gv=.05,Vv=.08,Wv=2,Xv=3,kS=14,PS=.02;class LS{context;voice;voiceToken=0;buffers=new Map;noiseBuffer;crackleBuffer;requested;level=1;master;output(e){return this.master||(this.master=e.createGain(),this.master.gain.value=this.level,this.master.connect(e.destination)),this.master}setLevel(e){this.level=e,this.master&&(this.master.gain.value=e)}resume(){if(!this.context){if(typeof AudioContext>"u")return;try{this.context=new AudioContext}catch(e){console.warn("SightingAudio: Web Audio unavailable, the sighting stays silent:",e);return}}To.unlock(this.context)}setSound(e){if(this.requested=e,!this.context)return;const t=this.keyFor(e);if(!t){this.silence();return}if(this.voice?.key!==t){this.stopVoice();const i=++this.voiceToken;t.startsWith("src:")?this.buildRecordedVoice(e.src,t,i):this.voice=this.buildSynthesizedVoice(e,t)}this.applyTo(this.voice,e)}silence(){this.voiceToken++,this.stopVoice()}dispose(){this.silence(),this.context?.close(),this.context=void 0,this.master=void 0,this.buffers.clear(),this.noiseBuffer=void 0,this.crackleBuffer=void 0}keyFor(e){if(!(e.volume<=0))return e.src?`src:${e.src}`:e.kind==="none"?void 0:e.kind}applyTo(e,t){const i=this.context;if(!e||!i)return;const n=i.currentTime;e.volumeParam.setTargetAtTime(Math.max(0,Math.min(1,t.volume))*e.gainScale,n,Gv);for(const{param:s,ratio:r}of e.pitch)s.setTargetAtTime(Math.min(t.pitchHz*r,i.sampleRate/2-1),n,Gv)}buildSynthesizedVoice(e,t){const i=this.context;if(i)switch(e.kind){case"hum":return this.buildHum(i,t);case"whistle":return this.buildWhistle(i,t);case"rumble":return this.buildRumble(i,t);case"crackle":return this.buildCrackle(i,t);default:return}}buildHum(e,t){const i=e.createOscillator();i.type="sawtooth";const n=e.createOscillator();n.type="sawtooth";const s=e.createBiquadFilter();s.type="lowpass",s.Q.value=1;const r=e.createGain();return r.gain.value=0,i.connect(s),n.connect(s),s.connect(r).connect(this.output(e)),i.start(),n.start(),{key:t,nodes:[s,r],sources:[i,n],volumeParam:r.gain,gainScale:.16,pitch:[{param:i.frequency,ratio:1},{param:n.frequency,ratio:1.006},{param:s.frequency,ratio:6}]}}buildWhistle(e,t){const i=e.createOscillator();i.type="sine";const n=e.createOscillator();n.type="sine",n.frequency.value=5;const s=e.createGain(),r=e.createGain();return r.gain.value=0,n.connect(s).connect(i.frequency),i.connect(r).connect(this.output(e)),i.start(),n.start(),{key:t,nodes:[s,r],sources:[i,n],volumeParam:r.gain,gainScale:.22,pitch:[{param:i.frequency,ratio:1},{param:s.gain,ratio:.012}]}}buildRumble(e,t){const i=e.createBufferSource();i.buffer=this.brownNoise(e),i.loop=!0;const n=e.createBiquadFilter();n.type="lowpass",n.Q.value=.8;const s=e.createGain();return s.gain.value=0,i.connect(n).connect(s).connect(this.output(e)),i.start(),{key:t,nodes:[n,s],sources:[i],volumeParam:s.gain,gainScale:1.4,pitch:[{param:n.frequency,ratio:1}]}}buildCrackle(e,t){const i=e.createBufferSource();i.buffer=this.whiteNoise(e),i.loop=!0;const n=e.createBiquadFilter();n.type="bandpass",n.Q.value=1.2;const s=e.createGain();s.gain.value=0;const r=e.createBufferSource();r.buffer=this.crackleEnvelope(e),r.loop=!0;const a=e.createGain();return a.gain.value=0,r.connect(a).connect(s.gain),i.connect(n).connect(s).connect(this.output(e)),i.start(),r.start(),{key:t,nodes:[n,s,a],sources:[i,r],volumeParam:a.gain,gainScale:.9,pitch:[{param:n.frequency,ratio:4}]}}async buildRecordedVoice(e,t,i){const n=this.context;if(!n)return;let s;try{s=await this.getBuffer(e)}catch(l){console.warn("SightingAudio: the recorded sound failed to load, staying silent:",l);return}if(i!==this.voiceToken||!this.context)return;const r=n.createBufferSource();r.buffer=s,r.loop=!0;const a=n.createGain();a.gain.value=0,r.connect(a).connect(this.output(n)),r.start(),this.voice={key:t,nodes:[a],sources:[r],volumeParam:a.gain,gainScale:1,pitch:[]},this.requested&&this.applyTo(this.voice,this.requested)}async getBuffer(e){const t=this.context;if(!t)throw new Error("SightingAudio: AudioContext not ready — resume() must be called first");let i=this.buffers.get(e);return i||(i=fetch(e).then(n=>{if(!n.ok)throw new Error(`Audio fetch failed (${n.status}): ${e}`);return n.arrayBuffer()}).then(n=>t.decodeAudioData(n)),this.buffers.set(e,i)),i}whiteNoise(e){if(!this.noiseBuffer){const t=e.createBuffer(1,Math.floor(e.sampleRate*Wv),e.sampleRate),i=t.getChannelData(0);for(let n=0;n<i.length;n++)i[n]=Math.random()*2-1;this.noiseBuffer=t}return this.noiseBuffer}brownNoise(e){const t=e.createBuffer(1,Math.floor(e.sampleRate*Wv),e.sampleRate),i=t.getChannelData(0);let n=0,s=0;for(let r=0;r<i.length;r++)n=(n+.02*(Math.random()*2-1))/1.02,i[r]=n,s=Math.max(s,Math.abs(n));if(s>0)for(let r=0;r<i.length;r++)i[r]/=s;return t}crackleEnvelope(e){if(!this.crackleBuffer){const t=e.createBuffer(1,Math.floor(e.sampleRate*Xv),e.sampleRate),i=t.getChannelData(0),n=Math.max(1,Math.floor(PS*e.sampleRate)),s=Math.round(Xv*kS);for(let r=0;r<s;r++){const a=Math.floor(Math.random()*i.length),l=.4+Math.random()*.6;for(let c=0;c<n&&a+c<i.length;c++)i[a+c]=Math.max(i[a+c],l*(1-c/n))}this.crackleBuffer=t}return this.crackleBuffer}stopVoice(){const e=this.voice,t=this.context;if(this.voice=void 0,!e||!t)return;const i=t.currentTime;e.volumeParam.cancelScheduledValues(i),e.volumeParam.setTargetAtTime(0,i,Vv/3);const n=i+Vv;for(const s of e.sources){s.onended=()=>{s.disconnect();for(const r of e.nodes)r.disconnect()};try{s.stop(n)}catch{s.disconnect();for(const r of e.nodes)r.disconnect()}}}}class qe{static svg(e){return`<svg viewBox="0 0 24 24" width="1.5em" height="1.5em" aria-hidden="true" focusable="false"><path d="${e}" fill="currentColor"/></svg>`}static outline(e){return`<svg viewBox="0 0 24 24" width="1.5em" height="1.5em" aria-hidden="true" focusable="false"><path d="${e}" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linejoin="round" stroke-linecap="round"/></svg>`}static solid(e){return`<svg viewBox="0 0 24 24" width="1.5em" height="1.5em" aria-hidden="true" focusable="false"><path d="${e}" fill="currentColor" fill-rule="evenodd"/></svg>`}static BOOKMARK="M6 3.5h12a.5.5 0 0 1 .5.5v16.5L12 16.8l-6.5 3.7V4a.5.5 0 0 1 .5-.5z";static PICTURE="M5 4h14a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2z";static PICTURE_HILLS="M4.5 17.5l4.5-6 3 4 2.5-3 5 5z";static PIN="M12 21.5s-6.5-5.7-6.5-10.8a6.5 6.5 0 0 1 13 0c0 5.1-6.5 10.8-6.5 10.8z";static PIN_HOLE="M12 8.4a2.4 2.4 0 1 0 0 4.8 2.4 2.4 0 0 0 0-4.8z";static MILESTONES_OFF=qe.outline(qe.BOOKMARK);static MILESTONES_ON=qe.solid(qe.BOOKMARK);static PICTURES_OFF=qe.outline(`${qe.PICTURE}${qe.PICTURE_HILLS}`);static PICTURES_ON=qe.solid(`${qe.PICTURE}${qe.PICTURE_HILLS}`);static TRACE_LINE="M3 19.5l2.2-2.2 1.4 1.4L4.4 20.9zM8 14.5l2.2-2.2 1.4 1.4-2.2 2.2zM13 9.5l2.2-2.2 1.4 1.4-2.2 2.2z";static TRACE_MARK="M18.5 2.5l3.5 3.5-3.5 3.5-3.5-3.5z";static TRACES_OFF=qe.outline(`${qe.TRACE_LINE}${qe.TRACE_MARK}`);static TRACES_ON=qe.solid(`${qe.TRACE_LINE}${qe.TRACE_MARK}`);static MAP_OFF=qe.outline(`${qe.PIN}${qe.PIN_HOLE}`);static MAP_ON=qe.solid(`${qe.PIN}${qe.PIN_HOLE}`);static SHARE=qe.outline("M14 4l7 7-7 7v-4.2C8.6 13.8 5.4 15.6 3.5 19c.6-5.6 3.4-9.6 10.5-10.8V4z");static FOLDED=qe.svg("M15.4 7.4 14 6l-6 6 6 6 1.4-1.4L10.8 12z");static UNFOLDED=qe.svg("M8.6 16.6 10 18l6-6-6-6-1.4 1.4 4.6 4.6z");static PLAY=qe.svg("M7.4 5v14l11-7z");static PAUSE=qe.svg("M6 5h4v14H6zM14 5h4v14h-4z");static VOLUME=qe.svg("M2 9.5v5h3.5l4.5 4.5V5L5.5 9.5H2zm12.5 2.5A4 4 0 0 0 12.5 8.5v7A4 4 0 0 0 14.5 12zM12.5 4.2v2.1a6.5 6.5 0 0 1 0 11.4v2.1a8.6 8.6 0 0 0 0-15.6z");static MUTED=qe.svg("M2 9.5v5h3.5l4.5 4.5V5L5.5 9.5H2zM15 9.8l1.4-1.4 2.6 2.6 2.6-2.6 1.4 1.4-2.6 2.6 2.6 2.6-1.4 1.4-2.6-2.6-2.6 2.6-1.4-1.4 2.6-2.6z");static ENTER_FULLSCREEN=qe.svg("M5 5h5v2H7v3H5V5zm9 0h5v5h-2V7h-3V5zM5 14h2v3h3v2H5v-5zm12 0h2v5h-5v-2h3v-3z");static EXIT_FULLSCREEN=qe.svg("M8 5h2v5H5V8h3V5zm6 0h2v3h3v2h-5V5zM5 14h5v5H8v-3H5v-2zm9 0h5v2h-3v3h-2v-5z")}function Io(o){return[...o].sort((e,t)=>e.t-t.t)}function zf(o,e){let t;for(const i of Io(o)){if(i.t>e)break;t=i}return t}const Hf=Math.PI/180,Vh=180/Math.PI;class Vs{constructor(e,t,i){this.kind=e,this.canvasHeightPx=t,this.fovDeg=i;const n=i*Hf/2;this.focalPx=e==="equidistant"?t/2/n:t/2/Math.tan(n)}focalPx;static of(e,t,i){return new Vs(e.projection,t,i)}degToPx(e){const t=e*Hf;return this.kind==="equidistant"?this.focalPx*t:2*this.focalPx*Math.tan(t/2)}pxToDeg(e){return this.kind==="equidistant"?e/this.focalPx*Vh:2*Math.atan(e/(2*this.focalPx))*Vh}angleDegToRadiusPx(e){const t=e*Hf;return this.kind==="equidistant"?this.focalPx*t:this.focalPx*Math.tan(t)}halfWidthAngleDeg(e){return this.radiusPxToAngleDeg(this.canvasHeightPx*e/2)}radiusPxToAngleDeg(e){return this.kind==="equidistant"?e/this.focalPx*Vh:Math.atan(e/this.focalPx)*Vh}ofBounds(e){return{widthDeg:this.pxToDeg(e.width),heightDeg:this.pxToDeg(e.height)}}toBoundsSize(e){return{width:this.degToPx(e.widthDeg),height:this.degToPx(e.heightDeg)}}widthPx(e){return this.degToPx(pt.angularWidthDeg(e))}}class ji{static fovOf(e,t){return at(e,t)?.fovDeg??Bt.fieldOfViewDeg(e.instrument)}static toAngular(e){this.eachKeyframe(e,(t,i)=>({...t,angular:i.ofBounds(t.bounds)}))}static toBounds(e){this.eachKeyframe(e,(t,i)=>{if(!t.angular)return t;const{width:n,height:s}=i.toBoundsSize(t.angular),r={x:t.bounds.x+(t.bounds.width-n)/2,y:t.bounds.y+(t.bounds.height-s)/2,width:n,height:s};if(t.kind!=="polygon")return{...t,bounds:r};const a=t.bounds.width===0?1:n/t.bounds.width,l=t.bounds.height===0?1:s/t.bounds.height;return{...t,bounds:r,points:t.points.map(c=>({x:c.x*a,y:c.y*l}))}})}static toAim(e){this.eachKeyframe(e,(t,i,n)=>{const s=t.aim&&this.positionOf(e,t.aim,t.bounds,i,n);if(s&&Math.abs(s.x-t.bounds.x)<ji.UNMOVED_PX&&Math.abs(s.y-t.bounds.y)<ji.UNMOVED_PX)return t;const r=this.aimFrom(e,i,n,t.bounds);return r?{...t,aim:r}:t})}static UNMOVED_PX=.01;static aimOf(e,t,i){const n=Vs.of(e.instrument,pt.CANVAS_HEIGHT_PX,this.fovOf(e,t));return this.aimFrom(e,n,at(e,t),i)}static aimFrom(e,t,i,n){if(i?.headingDeg===void 0)return;const s=this.frameCentre(e),r=t.radiusPxToAngleDeg(n.x+n.width/2-s.x),a=t.radiusPxToAngleDeg(s.y-(n.y+n.height/2));return{azimuthDeg:((i.headingDeg+r)%360+360)%360,altitudeDeg:i.pitchDeg+a}}static toPosition(e){this.eachKeyframe(e,(t,i,n)=>{const s=t.aim&&this.positionOf(e,t.aim,t.bounds,i,n);return s?{...t,bounds:{...t.bounds,...s}}:t})}static positionOf(e,t,i,n,s){if(s?.headingDeg===void 0)return;const r=this.frameCentre(e),a=this.shortestArc(t.azimuthDeg-s.headingDeg),l=t.altitudeDeg-s.pitchDeg;return{x:r.x+this.offAxisPx(n,a)-i.width/2,y:r.y-this.offAxisPx(n,l)-i.height/2}}static frameCentre(e){return{x:Bt.frameWidthPx(e.instrument,pt.CANVAS_HEIGHT_PX)/2,y:pt.CANVAS_HEIGHT_PX/2}}static shortestArc(e){return(e%360+540)%360-180}static offAxisPx(e,t){return Math.abs(t)>=ji.OFF_CANVAS_DEG?Math.sign(t)*ji.OFF_CANVAS_PX:e.angleDegToRadiusPx(t)}static OFF_CANVAS_DEG=89;static OFF_CANVAS_PX=1e5;static reproject(e,t,i){const n=Bt.frameWidthPx(t,pt.CANVAS_HEIGHT_PX)/2,s=Bt.frameWidthPx(e.instrument,pt.CANVAS_HEIGHT_PX)/2,r=pt.CANVAS_HEIGHT_PX/2;for(const a of[...e.timeline.allKeyframes]){const l=this.fovOf(e,a.t),c=i?.get(a.t)??l,h=Vs.of(t,pt.CANVAS_HEIGHT_PX,c),d=Vs.of(e.instrument,pt.CANVAS_HEIGHT_PX,l);e.timeline.addKeyframe(a.t,a.shapes.map(u=>{const{bounds:f}=u.shape,p=f.x+f.width/2-n,g=f.y+f.height/2-r,m=Math.hypot(p,g),v=m===0?1:d.angleDegToRadiusPx(h.radiusPxToAngleDeg(m))/m,b={...f,x:s+p*v-f.width/2,y:r+g*v-f.height/2};return{...u,shape:{...u.shape,bounds:b}}}))}this.toBounds(e)}static eachKeyframe(e,t){const{timeline:i}=e;for(const n of[...i.allKeyframes]){const s=at(e,n.t),r=this.fovOf(e,n.t),a=Vs.of(e.instrument,pt.CANVAS_HEIGHT_PX,r);i.addKeyframe(n.t,n.shapes.map(l=>({...l,shape:t(l.shape,a,s)})))}}}function OS(o){return On.restore(S0(o),o.provenance)}function S0(o){return ji.toAngular(o),ji.toAim(o),{version:1,id:o.id,time:o.event.time,endTime:o.event.endTime,durationSeconds:o.event.durationSeconds,durationText:o.event.durationText,utcOffsetHours:o.event.utcOffsetHours,timeZone:o.event.timeZone,place:o.event.place,observer:o.observer,account:o.account,sources:o.sources?.length?o.sources:void 0,sway:o.sway,vehicle:o.vehicle,description:o.event.description,image:o.event.image,summary:o.event.summary,summaryTime:o.event.summaryTime,tags:o.event.tags,timeline:o.timeline.toJSON(),observerTrack:o.observerTrack.toJSON(),weatherTrack:o.weatherTrack.toJSON(),soundTrack:o.soundTrack.toJSON(),weather:o.weather,decor:o.decor,milestones:o.milestones.length>0?o.milestones:void 0,references:o.references.length>0?o.references:void 0,roads:o.roads.length>0?o.roads:void 0,traces:o.traces.length>0?o.traces:void 0,weatherSource:o.weatherSource,instrument:o.instrumentId,exposureSeconds:o.exposureSeconds,iso:o.iso,lightPollution:o.lightPollution,observerMap:o.observerMap,interpretation:o.interpretation}}function NS(o){const{recording:e,provenance:t}=On.strip(o),i=FS(e);return i.provenance=t,i}function FS(o){const e=[],t=new yf({eventType:"sighting",time:o.time,endTime:o.endTime,durationSeconds:o.durationSeconds,durationText:o.durationText,utcOffsetHours:o.utcOffsetHours,timeZone:o.timeZone,place:o.place,description:o.description,image:o.image,summary:o.summary,summaryTime:o.summaryTime,tags:o.tags},ff.fromJSON(o.timeline,e),o.observerTrack?hh.fromJSON(o.observerTrack):new hh,o.weatherTrack?dh.fromJSON(o.weatherTrack):new dh,o.soundTrack?uh.fromJSON(o.soundTrack):new uh,o.observer&&{id:o.observer.id,title:o.observer.title,lastName:o.observer.lastName,firstNames:o.observer.firstNames},o.id,o.weather,o.decor??[],o.weatherSource,o.instrument,o.exposureSeconds??o.observerTrack?.keyframes.map(i=>i.pose.exposureSeconds).find(i=>i!==void 0),Io(o.milestones??[]),o.references??[],o.roads??[],o.traces??[]);return t.account=o.account,t.sources=o.sources,t.sway=o.sway,t.iso=o.iso,t.lightPollution=o.lightPollution,t.observerMap=o.observerMap,t.vehicle=o.vehicle,t.interpretation=o.interpretation,t.loadIssues=e,ji.toBounds(t),ji.toPosition(t),t}class nc{static EN={"unknown-key":"{path}: unknown key, ignored","wrong-type":"{path}: expected {expected}, found {found}","not-in-list":"{path}: {found} is not one of {expected}",defaulted:"{path}: missing, {expected} used",unplaced:"{path}: no aim (and no bounds), drawn at the middle of the view",unsized:"{path}: no angular size (and no bounds), drawn one pixel wide","pixels-over-angles":"{path}: bounds restated without aim or angular, so the shape follows the pixels"};static text(e,t=nc.EN){return t[e.kind].replace("{path}",e.path).replace("{expected}",e.expected??"").replace("{found}",e.found??"")}static warn(e,t){if(e.length===0)return;const i=e.map(n=>` ${nc.text(n)}`);console.warn(`UFO@home: ${e.length} problem(s) in ${t??"this recording"}:
2834
2834
  ${i.join(`
2835
2835
  `)}`)}}class Cs{constructor(e){this.format=e}issues(e){const t=[];return this.object(e,this.format,"",t),t}object(e,t,i,n){if(!Cs.isObject(e)){n.push({kind:"wrong-type",path:i||"(the file)",expected:"object",found:Cs.typeOf(e)});return}for(const[s,r]of Object.entries(e)){const a=i?`${i}.${s}`:s,l=t[s];l?this.field(r,l,a,n):n.push({kind:"unknown-key",path:a})}}field(e,t,i,n){if(Cs.isStated(e)){this.field(e.value,t,i,n);return}if(!(t.loose||e===void 0||e===null))switch(t.type){case"enum":(typeof e!="string"||!t.values?.includes(e))&&n.push({kind:"not-in-list",path:i,expected:(t.values??[]).map(s=>`"${s}"`).join(", "),found:JSON.stringify(e)});return;case"object":t.fields?this.object(e,t.fields,i,n):Cs.isObject(e)||n.push({kind:"wrong-type",path:i,expected:"object",found:Cs.typeOf(e)});return;case"array":Array.isArray(e)?t.fields&&e.forEach((s,r)=>{const a=Cs.isStated(s)?s.value:s;this.object(a,t.fields,`${i}.${r}`,n)}):n.push({kind:"wrong-type",path:i,expected:"array",found:Cs.typeOf(e)});return;default:typeof e!==t.type&&n.push({kind:"wrong-type",path:i,expected:t.type,found:Cs.typeOf(e)})}}static isObject(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}static isStated(e){return Cs.isObject(e)&&"value"in e&&Object.keys(e).every(t=>t==="value"||t==="basis"||t==="rationale")}static typeOf(e){return Array.isArray(e)?"array":e===null?"null":typeof e}}class Fs{static PIXELS_PER_INSTANT=2;static INSTANTS_PER_FLASH=2;static MAX_INSTANTS=512;static windowEndingAt(e,t){const i=Number.isFinite(t)?Math.max(0,t):0,n=Math.max(0,e-i*1e3),s=Math.max(0,e-n);return{fromMs:n,toMs:e,ms:s,seconds:s/1e3}}static instants(e,t,i,n,s){if(!(n>0))return 1;const r=s>0?Fs.travelDegOver(e,t,i,i+n*1e3)/s/Fs.PIXELS_PER_INSTANT:0,a=Fs.flashesOver(e,n)*Fs.INSTANTS_PER_FLASH,l=Math.ceil(Math.max(r,a));return l<2?1:Math.min(Fs.MAX_INSTANTS,l)}static travelDegOver(e,t,i,n){let s=0;for(const r of e){if(!r.track||r.track.length<2)continue;const a=Fs.directionAt(r,t,i),l=Fs.directionAt(r,t,n),c=Math.min(1,Math.max(-1,a.x*l.x+a.y*l.y+a.z*l.z));s=Math.max(s,Math.acos(c)*180/Math.PI)}return s}static flashesOver(e,t){let i=0;for(const n of e)for(const s of n.lights??[])s.pattern.kind==="flash"&&(i=Math.max(i,s.pattern.perMinute));return i/60*t}static directionAt(e,t,i){const n=Gs(e,i),s=n.eastM,r=n.altitudeM-t,a=n.northM,l=Math.hypot(s,r,a);return l===0?{x:0,y:1,z:0}:{x:s/l,y:r/l,z:a/l}}}const CM={play:"Play",pause:"Pause",noDuration:"No observation duration",currentPosition:"Current position",duration:"Duration",switchToElapsed:"click to show elapsed time",switchToClockTime:"click to show the time of day",fullscreen:"Fullscreen",exitFullscreen:"Exit fullscreen",mute:"Mute",unmute:"Unmute",noSound:"No sound recorded",moments:"Moments",moreControls:"More controls",fewerControls:"Fewer controls",showObserverMap:"Show where the observer was",hideObserverMap:"Hide where the observer was",mapImageryUnavailable:"Aerial imagery unavailable",zoomMapIn:"Zoom in",zoomMapOut:"Zoom out",fitMap:"Back to the whole path",placeObserverHere:"Put the observer here",showReferences:"Show the pictures of the place",hideReferences:"Hide the pictures of the place",showTraces:"Show the investigator's lines",hideTraces:"Hide the investigator's lines",referenceOpacity:"Picture opacity",referencesMenu:"Pictures of the place",showMilestones:"Show the account's moments",hideMilestones:"Hide the account's moments",observerHere:"The observer, here",decorHere:"Scenery",recordingIssues:"{count} problem(s) in this recording: it may not play as its author meant",issueTemplates:nc.EN},US=Object.freeze(Object.defineProperty({__proto__:null,ufoMessages_en:CM},Symbol.toStringTag,{value:"Module"})),kM=Math.PI/180,BS=180/Math.PI,zS=256,PM=19,HS=1.25;function LM(o,e){return 156543.03392*Math.cos(o*kM)/2**e}function OM(o,e){return LM(o,e)*zS}function GS(o,e){let t=0;for(;t<PM&&OM(o,t+1)>=e;)t++;return t}function NM(o,e){return OM(o,e)}function VS(o,e){const t=e*HS;let i=0;for(;i<PM&&LM(o,i)>t;)i++;return i}function qd(o){const e=o*kM;return(1-Math.log(Math.tan(e)+1/Math.cos(e))/Math.PI)/2}function FM(o,e,t){const i=2**t;return{x:(o+180)/360*i,y:qd(e)*i}}function UM(o,e,t){const i=qd(o.north),n=qd(o.south);return{x:(e-o.west)/(o.east-o.west),y:(qd(t)-i)/(n-i)}}function WS(o,e,t){const{x:i,y:n}=FM(o,e,t);return{x:Math.floor(i),y:Math.floor(n),z:t}}function XS(o){const e=2**o.z,t=o.x/e*360-180,i=(o.x+1)/e*360-180,n=$v(o.y,e);return{south:$v(o.y+1,e),north:n,west:t,east:i}}function $v(o,e){const t=o/e;return Math.atan(Math.sinh(Math.PI*(1-2*t)))*BS}function BM(o,e,t,i){const n=WS(o,e,t),s=Math.floor(i/2),r=[];for(let c=-s;c<=s;c++)for(let h=-s;h<=s;h++)r.push({x:n.x+h,y:n.y+c,z:t});const a=r.map(XS),l={south:Math.min(...a.map(c=>c.south)),north:Math.max(...a.map(c=>c.north)),west:Math.min(...a.map(c=>c.west)),east:Math.max(...a.map(c=>c.east))};return{tiles:r,bounds:l}}const $S="#2ec4ff";class Qa{constructor(e){this.ctx=e}static SCALE_STEPS_M=[5e3,2e3,1e3,500,200,100,50,20,10,5];static MARKER_RADIUS_PX=8.5;static ON_MARKER_M=3;targets=[];hitTest(e,t){let i,n=1/0;for(const s of this.targets){const r=Math.hypot(s.x-e,s.y-t);r>s.radius||r>n||(i=s,n=r)}return i}get width(){return this.ctx.canvas.width}get height(){return this.ctx.canvas.height}paint(e){const{ctx:t}=this;t.save(),this.targets=[],t.clearRect(0,0,this.width,this.height),this.paintGround(e),this.paintNight(e.nightFraction),this.paintPath(e),this.paintTraces(e),e.position?(this.paintCone(e,e.position),this.paintDecor(e),this.paintMarkers(e),this.paintObserver(e,e.position)):(this.paintDecor(e),this.paintMarkers(e)),this.paintNorth(),this.paintFooter(e.bounds,e.attribution),t.restore()}toCanvas(e,t,i){const n=UM(e,i,t);return{x:n.x*this.width,y:n.y*this.height}}paintGround(e){const{ctx:t}=this;t.fillStyle="#1d2321",t.fillRect(0,0,this.width,this.height);const i=e.imagery;if(!i)return;const n=this.toCanvas(e.bounds,i.bounds.north,i.bounds.west),s=this.toCanvas(e.bounds,i.bounds.south,i.bounds.east);t.drawImage(i.source,n.x,n.y,s.x-n.x,s.y-n.y)}paintNight(e=0){if(e<=0)return;const{ctx:t}=this;t.save(),t.fillStyle=`rgba(6, 12, 30, ${Math.min(e,1)*.78})`,t.fillRect(0,0,this.width,this.height),t.restore()}paintDecor(e){const{ctx:t}=this;for(const i of e.decor){const n=this.toCanvas(e.bounds,i.lat,i.lng);if(i.label&&this.targets.push({kind:"decor",label:i.label,lat:i.lat,lng:i.lng,x:n.x,y:n.y,radius:7}),t.beginPath(),t.rect(n.x-3.5,n.y-3.5,7,7),t.fillStyle="rgba(120, 220, 255, 0.85)",t.fill(),t.lineWidth=1.5,t.strokeStyle="rgba(0, 0, 0, 0.7)",t.stroke(),i.headingDeg===void 0)continue;const s=(i.headingDeg-90)*Math.PI/180;t.beginPath(),t.moveTo(n.x,n.y),t.lineTo(n.x+Math.cos(s)*10,n.y+Math.sin(s)*10),t.lineWidth=3,t.strokeStyle="rgba(0, 0, 0, 0.6)",t.stroke(),t.lineWidth=1.5,t.strokeStyle="rgba(120, 220, 255, 0.9)",t.stroke()}}paintPath(e){if(!e.path.moved)return;const{ctx:t}=this,i=e.path.points.map(n=>this.toCanvas(e.bounds,n.lat,n.lng));t.beginPath(),t.moveTo(i[0].x,i[0].y);for(const n of i.slice(1))t.lineTo(n.x,n.y);t.lineJoin="round",t.lineCap="round",t.strokeStyle="rgba(0, 0, 0, 0.65)",t.lineWidth=5,t.stroke(),t.strokeStyle="rgba(255, 255, 255, 0.9)",t.lineWidth=2,t.stroke()}paintTraces(e){const{ctx:t}=this;for(const i of e.traces??[]){const n=i.points.map(r=>this.toCanvas(e.bounds,r.lat,r.lng));if(n.length===0)continue;const s=i.color??$S;if(i.kind==="point")t.beginPath(),t.moveTo(n[0].x,n[0].y-6),t.lineTo(n[0].x+6,n[0].y),t.lineTo(n[0].x,n[0].y+6),t.lineTo(n[0].x-6,n[0].y),t.closePath(),t.fillStyle=s,t.fill(),t.lineWidth=1.5,t.strokeStyle="rgba(0, 0, 0, 0.8)",t.stroke();else{t.beginPath(),t.moveTo(n[0].x,n[0].y);for(const r of n.slice(1))t.lineTo(r.x,r.y);i.kind==="polygon"&&t.closePath(),t.lineJoin="round",t.setLineDash([]),t.strokeStyle="rgba(0, 0, 0, 0.65)",t.lineWidth=4.5,t.stroke(),t.setLineDash([9,5]),t.strokeStyle=s,t.lineWidth=2.5,t.stroke(),t.setLineDash([])}if(i.label){t.font="11px sans-serif",t.textAlign="left",t.textBaseline="middle";let r=n[0];if(i.kind==="line"&&e.position){const a=this.toCanvas(e.bounds,e.position.lat,e.position.lng);r=n.reduce((l,c)=>Math.hypot(c.x-a.x,c.y-a.y)>Math.hypot(l.x-a.x,l.y-a.y)?c:l)}this.paintOutlinedText(i.label,r.x+9,r.y-9)}}}paintCone(e,t){const{headingDeg:i,coneHalfAngleDeg:n}=e;if(i===void 0||n===void 0)return;const{ctx:s}=this,r=this.toCanvas(e.bounds,t.lat,t.lng),a=Math.hypot(this.width,this.height),l=(i-90)*Math.PI/180,c=n*Math.PI/180;s.save(),s.beginPath(),s.moveTo(r.x,r.y),s.arc(r.x,r.y,a,l-c,l+c),s.closePath();const h=s.createRadialGradient(r.x,r.y,0,r.x,r.y,a);h.addColorStop(0,"rgba(255, 224, 130, 0.55)"),h.addColorStop(.35,"rgba(255, 224, 130, 0.22)"),h.addColorStop(1,"rgba(255, 224, 130, 0)"),s.fillStyle=h,s.fill(),s.restore()}paintMarkers(e){const{ctx:t}=this;t.textAlign="center",t.textBaseline="middle",t.font="bold 10px sans-serif";for(const i of[...e.markers].sort((n,s)=>Number(n.current)-Number(s.current))){const n=this.toCanvas(e.bounds,i.lat,i.lng);this.targets.push({kind:"milestone",label:i.note?`${i.label} — ${i.note}`:i.label,lat:i.lat,lng:i.lng,t:i.t,x:n.x,y:n.y,radius:Qa.MARKER_RADIUS_PX}),t.beginPath(),t.arc(n.x,n.y,Qa.MARKER_RADIUS_PX,0,Math.PI*2),t.fillStyle=i.current?"rgba(255, 224, 130, 0.95)":"rgba(0, 0, 0, 0.55)",t.fill(),t.lineWidth=2,t.strokeStyle="rgba(255, 255, 255, 0.9)",t.stroke(),t.fillStyle=i.current?"#1d2321":"#fff",t.fillText(i.label,n.x,n.y)}}paintObserver(e,t){const{ctx:i}=this,n=this.toCanvas(e.bounds,t.lat,t.lng);e.observerLabel&&this.targets.push({kind:"observer",label:e.observerLabel,lat:t.lat,lng:t.lng,x:n.x,y:n.y,radius:8});const s=e.markers.some(r=>{if(!r.current)return!1;const a=vt(r.lat,r.lng,t.lat,t.lng);return Math.hypot(a.x,a.z)<=Qa.ON_MARKER_M});i.beginPath(),i.arc(n.x,n.y,s?Qa.MARKER_RADIUS_PX+2.5:5.5,0,Math.PI*2),s||(i.fillStyle="#ff5a3c",i.fill()),i.lineWidth=4,i.strokeStyle="rgba(0, 0, 0, 0.5)",i.stroke(),i.lineWidth=s?3:2.5,i.strokeStyle=s?"#ff5a3c":"#fff",i.stroke()}paintNorth(){const{ctx:e}=this,t=this.width-14,i=16;e.beginPath(),e.moveTo(t,i-9),e.lineTo(t-4.5,i+5),e.lineTo(t,i+2),e.lineTo(t+4.5,i+5),e.closePath(),e.fillStyle="rgba(255, 255, 255, 0.92)",e.strokeStyle="rgba(0, 0, 0, 0.6)",e.lineWidth=1,e.fill(),e.stroke(),e.font="bold 9px sans-serif",e.textAlign="center",e.textBaseline="top",e.strokeText("N",t,i+6),e.fillText("N",t,i+6)}paintFooter(e,t){const{ctx:i}=this;i.font="9px sans-serif",i.textBaseline="bottom";const n=t?this.wrap(t,this.width-20):[];let s=this.height-4;i.textAlign="right";for(const f of n.slice().reverse())this.paintOutlinedText(f,this.width-6,s),s-=11;const r=(e.south+e.north)/2,l=Math.abs(vt(r,e.east,r,e.west).x)/this.width,c=Qa.SCALE_STEPS_M.find(f=>f/l<=this.width/3);if(c===void 0)return;const h=c/l,d=8,u=s-3;i.lineWidth=3,i.strokeStyle="rgba(0, 0, 0, 0.6)",i.beginPath(),i.moveTo(d,u),i.lineTo(d+h,u),i.stroke(),i.lineWidth=1.5,i.strokeStyle="rgba(255, 255, 255, 0.95)",i.stroke(),i.textAlign="left",this.paintOutlinedText(c>=1e3?`${c/1e3} km`:`${c} m`,d,u-3)}paintOutlinedText(e,t,i){const{ctx:n}=this;n.lineWidth=3,n.strokeStyle="rgba(0, 0, 0, 0.75)",n.strokeText(e,t,i),n.fillStyle="#fff",n.fillText(e,t,i)}wrap(e,t){const i=[];let n="";for(const s of e.split(" ")){const r=n?`${n} ${s}`:s;n&&this.ctx.measureText(r).width>t?(i.push(n),n=s):n=r}return n&&i.push(n),i}}class yi{static MIN_ZOOM=.25;static MAX_ZOOM=64;zoom=1;centerX=.5;centerY=.5;get changed(){return this.zoom!==1||this.centerX!==.5||this.centerY!==.5}get zoomFactor(){return this.zoom}reset(){this.zoom=1,this.centerX=.5,this.centerY=.5}zoomAt(e,t,i){const n=Math.min(yi.MAX_ZOOM,Math.max(yi.MIN_ZOOM,this.zoom*i)),s=this.centerX+(e-.5)/this.zoom,r=this.centerY+(t-.5)/this.zoom;this.centerX=s-(e-.5)/n,this.centerY=r-(t-.5)/n,this.zoom=n}panBy(e,t){this.centerX-=e/this.zoom,this.centerY-=t/this.zoom}refit(e,t){if(!this.changed)return;const i=this.boundsWithin(e),n=yi.mercatorY01(t.north),s=yi.mercatorY01(t.south),r=yi.mercatorY01(i.north),a=yi.mercatorY01(i.south);this.zoom=(t.east-t.west)/(i.east-i.west),this.centerX=((i.west+i.east)/2-t.west)/(t.east-t.west),this.centerY=((r+a)/2-n)/(s-n)}keepInView(e,t,i){if(!this.changed)return!1;const n=this.boundsWithin(e),s=yi.mercatorY01(n.north),r=yi.mercatorY01(n.south),a=(t.lng-n.west)/(n.east-n.west),l=(yi.mercatorY01(t.lat)-s)/(r-s);return a>=i&&a<=1-i&&l>=i&&l<=1-i?!1:(this.panBy(.5-a,.5-l),!0)}boundsWithin(e){if(!this.changed)return e;const t=.5/this.zoom,i=yi.mercatorY01(e.north),n=yi.mercatorY01(e.south),s=e.east-e.west;return{west:e.west+(this.centerX-t)*s,east:e.west+(this.centerX+t)*s,north:yi.latitudeAt(i+(this.centerY-t)*(n-i)),south:yi.latitudeAt(i+(this.centerY+t)*(n-i))}}static including(e,t,i=3){const n=(e.north+e.south)/2,s=(e.east+e.west)/2,r=vt(n,e.east,n,s).x;let a=r;for(const l of t){const{x:c,z:h}=vt(l.lat,l.lng,n,s),d=Math.max(Math.abs(c),Math.abs(h));d<=r*i&&(a=Math.max(a,d*1.15))}return a<=r?e:{north:us(0,-a,n,s).lat,south:us(0,a,n,s).lat,east:us(a,0,n,s).lng,west:us(-a,0,n,s).lng}}static expand(e,t){const i=e.east-e.west,n=e.north-e.south;return{west:e.west-i*t,east:e.east+i*t,south:e.south-n*t,north:e.north+n*t}}static pointAt(e,t,i){const n=yi.mercatorY01(e.north),s=yi.mercatorY01(e.south);return{lat:yi.latitudeAt(n+i*(s-n)),lng:e.west+t*(e.east-e.west)}}static mercatorY01(e){const t=e*Math.PI/180;return(1-Math.log(Math.tan(t)+1/Math.cos(t))/Math.PI)/2}static latitudeAt(e){return Math.atan(Math.sinh(Math.PI*(1-2*e)))*180/Math.PI}}const vs=256,Yv=3,YS=32768;class zM{fetchImpl;tileUrlTemplate;constructor(e={}){this.fetchImpl=e.fetchImpl??fetch.bind(globalThis),this.tileUrlTemplate=e.tileUrlTemplate??"https://s3.amazonaws.com/elevation-tiles-prod/terrarium/{z}/{x}/{y}.png"}async getElevationGrid(e,t){const i=(e.south+e.north)/2,n=(e.west+e.east)/2,s=Math.abs(vt(i,e.east,i,e.west).x),r=Math.abs(vt(e.north,n,e.south,n).z),a=GS(i,Math.max(s,r)),{tiles:l}=BM(n,i,a,Yv),c=Yv*vs,h=new Float32Array(c*c),d=l[0];await Promise.all(l.map(f=>this.decodeTileInto(f,d,h,c)));const u=new Float32Array(t.width*t.height);for(let f=0;f<t.height;f++){const p=e.north+(e.south-e.north)*(f/(t.height-1));for(let g=0;g<t.width;g++){const m=e.west+(e.east-e.west)*(g/(t.width-1));u[f*t.width+g]=this.sampleAt(p,m,a,d,h,c)}}return{heights:u,width:t.width,height:t.height,bounds:e}}async decodeTileInto(e,t,i,n){const s=this.tileUrlTemplate.replace("{z}",String(e.z)).replace("{x}",String(e.x)).replace("{y}",String(e.y)),r=await this.fetchImpl(s);if(!r.ok)throw new Error(`Elevation tile fetch failed (${r.status}): ${s}`);const a=await createImageBitmap(await r.blob()),l=document.createElement("canvas");l.width=vs,l.height=vs;const c=l.getContext("2d");if(!c)throw new Error("2D canvas context unavailable");c.drawImage(a,0,0);const{data:h}=c.getImageData(0,0,vs,vs),d=(e.x-t.x)*vs,u=(e.y-t.y)*vs;for(let f=0;f<vs;f++)for(let p=0;p<vs;p++){const g=(f*vs+p)*4,m=h[g]*256+h[g+1]+h[g+2]/256-YS,v=d+p,b=u+f;i[b*n+v]=m}}sampleAt(e,t,i,n,s,r){const{x:a,y:l}=FM(t,e,i),c=(a-n.x)*vs,h=(l-n.y)*vs,d=Math.max(0,Math.min(r-1,Math.floor(c))),u=Math.max(0,Math.min(r-1,Math.floor(h))),f=Math.min(r-1,d+1),p=Math.min(r-1,u+1),g=c-d,m=h-u,v=s[u*r+d],b=s[u*r+f],x=s[p*r+d],y=s[p*r+f],w=v+(b-v)*g,S=x+(y-x)*g;return w+(S-w)*m}}class wf{constructor(e,t,i,n){this.width=e,this.height=t,this.samples=i,this.values=n}at(e,t,i=0){return this.values[(t*this.width+e)*this.samples+i]}static parse(e){const t=new DataView(e);if(e.byteLength<8||t.getUint16(0)!==18761||t.getUint16(2,!0)!==42)throw new Error("Not a little-endian TIFF");const i=t.getUint32(4,!0),n=t.getUint16(i,!0),s=new Map;for(let v=0;v<n;v++){const b=i+2+v*12;s.set(t.getUint16(b,!0),{type:t.getUint16(b+2,!0),count:t.getUint32(b+4,!0),value:t.getUint32(b+8,!0)})}const r=(v,b)=>{const x=s.get(v);if(x===void 0){if(b===void 0)throw new Error(`TIFF without tag ${v}`);return b}return x.type===3?x.value&65535:x.value},a=v=>{const b=s.get(v);if(b===void 0)throw new Error(`TIFF without tag ${v}`);const x=b.type===3?2:4,y=[];if(b.count*x<=4){const w=new DataView(new ArrayBuffer(4));w.setUint32(0,b.value,!0);for(let S=0;S<b.count;S++)y.push(x===2?w.getUint16(S*2,!0):w.getUint32(0,!0))}else for(let w=0;w<b.count;w++)y.push(x===2?t.getUint16(b.value+w*2,!0):t.getUint32(b.value+w*4,!0));return y};if(r(259,1)!==1)throw new Error("Compressed TIFF");if(s.has(322))throw new Error("Tiled TIFF");const l=r(256),c=r(257),h=r(277,1),d=a(258)[0],u=r(339,1)===3;if(!(u&&d===32||!u&&d===8))throw new Error(`Unsupported TIFF samples: ${d} bits`);const f=a(273),p=a(279),g=new Uint8Array(l*c*h*(d/8));let m=0;for(let v=0;v<f.length&&m<g.length;v++){const b=Math.min(p[v],g.length-m);g.set(new Uint8Array(e,f[v],b),m),m+=b}if(m<g.length)throw new Error("Truncated TIFF");return new wf(l,c,h,u?new Float32Array(g.buffer):g)}}class qS{constructor(e,t,i,n,s){this.heights=e,this.plants=t,this.buildings=i,this.size=n,this.metresPerPixel=s}structureAt(e,t){const i=Math.floor(e/this.metresPerPixel+this.size/2),n=Math.floor(this.size/2-t/this.metresPerPixel);if(i<0||n<0||i>=this.size||n>=this.size)return;const s=n*this.size+i;if(!(this.plants[s]||this.buildings[s]))return this.heights[s]}tallestStructureNear(e,t,i){let n;const s=Math.ceil(i/this.metresPerPixel);for(let r=-s;r<=s;r++)for(let a=-s;a<=s;a++){if(Math.hypot(a,r)*this.metresPerPixel>i)continue;const l=this.structureAt(e+a*this.metresPerPixel,t+r*this.metresPerPixel);l!==void 0&&(n===void 0||l>n)&&(n=l)}return n}}class rt{static METRES_PER_DEGREE=111320;static MIN_BRIDGE_M=4;static DEFAULT_DECK_M=6;static FOOTBRIDGE_DECK_M=2.5;static DECK_MARGIN_M=2.4;static ROAD_MATCH_M=12;static DEFAULT_DECK_HEIGHT_M=4;static MIN_POLE_M=6;static MAX_POLE_M=70;static MAX_SPAN_M=800;static MAX_LINES=16;static BY_VOLTAGE=[{upToKv:25,poleM:11,dropM:1.2,spreadM:.8},{upToKv:70,poleM:20,dropM:3,spreadM:3},{upToKv:100,poleM:22,dropM:3.5,spreadM:3.5},{upToKv:170,poleM:27,dropM:4.5,spreadM:4.5},{upToKv:250,poleM:32,dropM:5.5,spreadM:5.5},{upToKv:1e3,poleM:42,dropM:7,spreadM:7.5}];static toMetres(e,t){const[i,n]=e;return{east:(i-t.lng)*rt.METRES_PER_DEGREE*Math.cos(t.lat*Math.PI/180),north:(n-t.lat)*rt.METRES_PER_DEGREE}}static path(e,t){return e.geometry.type!=="LineString"?[]:e.geometry.coordinates.map(i=>rt.toMetres(i,t))}static bearing(e,t){return(Math.atan2(t.east-e.east,t.north-e.north)*180/Math.PI+360)%360}static distanceToSegment(e,t,i){const n=i.east-t.east,s=i.north-t.north,r=n*n+s*s,a=r===0?0:Math.max(0,Math.min(1,((e.east-t.east)*n+(e.north-t.north)*s)/r));return Math.hypot(e.east-(t.east+a*n),e.north-(t.north+a*s))}static bridges(e,t,i,n){const s=e.elevatedRoads.map(a=>({path:rt.path(a,t),properties:a.properties})),r=[];for(const a of e.bridges){const l=rt.path(a,t);if(l.length<2)continue;const c=l[0],h=l[l.length-1],d=Math.hypot(h.east-c.east,h.north-c.north);if(d<rt.MIN_BRIDGE_M)continue;const u={east:(c.east+h.east)/2,north:(c.north+h.north)/2};Math.hypot(u.east,u.north)>i+d/2||r.push({eastM:rt.tenth(u.east),northM:rt.tenth(u.north),lengthM:rt.tenth(d),widthM:rt.roadOf(u,s).width,heightM:rt.tenth(rt.deckHeight(c,h,n)),headingDeg:rt.tenth(rt.bearing(c,h)%180),...rt.roadOf(u,s).name?{name:rt.roadOf(u,s).name}:{}})}return r.sort((a,l)=>Math.hypot(a.eastM,a.northM)-Math.hypot(l.eastM,l.northM)),r}static roadOf(e,t){let i;for(const a of t)for(let l=0;l+1<a.path.length;l++){const c=rt.distanceToSegment(e,a.path[l],a.path[l+1]);(i===void 0||c<i.distance)&&(i={distance:c,properties:a.properties})}if(i===void 0||i.distance>rt.ROAD_MATCH_M)return{width:rt.DEFAULT_DECK_M};const n=[i.properties.nom_voie_ban_gauche,i.properties.nom_voie_ban_droite,i.properties.cpx_toponyme_route_nommee].find(a=>typeof a=="string"&&a.length>0),s=Number(i.properties.largeur_de_chaussee),r=Number.isFinite(s)&&s>0?rt.tenth(s+rt.DECK_MARGIN_M):i.properties.nature==="Sentier"?rt.FOOTBRIDGE_DECK_M:rt.DEFAULT_DECK_M;return n?{width:r,name:n}:{width:r}}static deckHeight(e,t,i){if(i===void 0)return rt.DEFAULT_DECK_HEIGHT_M;const n=[],s=20;for(let r=4;r<=s-4;r++){const a=i.structureAt(e.east+(t.east-e.east)*r/s,e.north+(t.north-e.north)*r/s);a!==void 0&&a>=1.5&&n.push(a)}return n.length===0?rt.DEFAULT_DECK_HEIGHT_M:(n.sort((r,a)=>r-a),n[Math.floor(n.length/2)])}static lines(e,t,i,n){const s=[];for(const r of e.lines){const a=String(r.properties.voltage??""),l=rt.kilovolts(a);if(l===void 0)continue;const c=rt.BY_VOLTAGE.find(d=>l<=d.upToKv)??rt.BY_VOLTAGE[rt.BY_VOLTAGE.length-1],h=rt.path(r,t);for(let d=0;d+1<h.length;d++){const u=h[d],f=h[d+1],p=Math.hypot(f.east-u.east,f.north-u.north);if(p<5||p>rt.MAX_SPAN_M||rt.distanceToSegment({east:0,north:0},u,f)>i)continue;const g=rt.poleHeight(u,f,n)??c.poleM;s.push({eastM:rt.tenth((u.east+f.east)/2),northM:rt.tenth((u.north+f.north)/2),lengthM:rt.tenth(p),headingDeg:rt.tenth(rt.bearing(u,f)),heightM:rt.tenth(Math.max(4,g-c.dropM)),poleHeightM:rt.tenth(g),acrossM:[-c.spreadM,0,c.spreadM],voltage:a})}}return s.sort((r,a)=>Math.hypot(r.eastM,r.northM)-Math.hypot(a.eastM,a.northM)),s.slice(0,rt.MAX_LINES)}static kilovolts(e){const t=/([\d.,]+)\s*kV/i.exec(e);if(t===null)return;const i=Number(t[1].replace(",","."));return Number.isFinite(i)&&i>0?i:void 0}static poleHeight(e,t,i){if(i===void 0)return;const n=[e,t].map(s=>i.tallestStructureNear(s.east,s.north,3)).filter(s=>s!==void 0&&s>=rt.MIN_POLE_M&&s<=rt.MAX_POLE_M);return n.length===0?void 0:n.reduce((s,r)=>s+r,0)/n.length}static tenth(e){return Math.round(e*10)/10}}class li{static covers(e,t){return e>=41.2&&e<=51.3&&t>=-5.4&&t<=9.8}static WMS="https://data.geopf.fr/wms-r/wms";static WFS="https://data.geopf.fr/wfs/ows";static HEIGHT_LAYER="IGNF_LIDAR-HD_MNH_ELEVATION.ELEVATIONGRIDCOVERAGE.LAMB93";static CLASS_LAYER="IGNF_LIDAR-HD_CLASS";static PHOTO_LAYER="ORTHOIMAGERY.ORTHOPHOTOS";static MAX_PHOTO_PIXELS=1e3;static METRES_PER_PIXEL=.5;static MAX_RADIUS_M=3e3;static MAX_LIDAR_RADIUS_M=150;static NO_DATA=-9999;static METRES_PER_DEGREE=111320;fetchImpl;wms;wfs;constructor(e={}){this.fetchImpl=e.fetchImpl??fetch.bind(globalThis),this.wms=e.wmsEndpoint??li.WMS,this.wfs=e.wfsEndpoint??li.WFS}static radius(e){return Math.min(e,li.MAX_RADIUS_M)}static lidarRadius(e){return Math.min(e,li.MAX_LIDAR_RADIUS_M)}async lidar(e,t){const i=li.lidarRadius(t),n=Math.ceil(2*i/li.METRES_PER_PIXEL),[s,r]=await Promise.all([this.raster(e,i,n,li.HEIGHT_LAYER),this.raster(e,i,n,li.CLASS_LAYER)]);if(s.samples!==1||r.samples<3)throw new Ps("unreachable","The survey answered in a layout this does not read");const a=s.values;if(a.every(d=>d===li.NO_DATA))throw new Ps("no-coverage","No LiDAR HD survey here yet");const l=new Uint8Array(n*n),c=new Uint8Array(n*n);for(let d=0;d<n*n;d++){const u=r.values[d*r.samples],f=r.values[d*r.samples+1],p=r.values[d*r.samples+2];l[d]=f>u&&f>p?1:0,c[d]=u>120&&f<90&&p<90?1:0}const h=2*i/n;return{size:n,metresPerPixel:h,heights:a,vegetation:l,building:c,structures:new qS(a,l,c,n,h)}}async laserDate(e){return li.latest(await this.dated("IGNF_LIDAR-HD_METADONNEE:metadata","geom","date_fin_acquisition",e))}async photoDate(e){return li.latest(await this.dated("ORTHOIMAGERY.ORTHOPHOTOS.GRAPHE-MOSAIQUAGE:graphe_bdortho","geom","date_vol",e))}static latest(e){return e.map(i=>/^\d{4}-\d{2}-\d{2}/.exec(String(i??""))?.[0]).filter(i=>i!==void 0).sort().at(-1)}async dated(e,t,i,n){const r=[n.lng-1e-4,n.lat-1e-4,n.lng+1e-4,n.lat+1e-4].map(a=>a.toFixed(6)).join(",");try{return(await this.features(e,`BBOX(${t},${r},'EPSG:4326')`,i,20)).map(a=>a.properties[i])}catch{return[]}}async photo(e,t){const i=li.radius(t),n=Math.min(li.MAX_PHOTO_PIXELS,Math.ceil(2*i/li.METRES_PER_PIXEL)),s=await this.raster(e,i,n,li.PHOTO_LAYER);if(s.samples<3)throw new Ps("unreachable","The photograph came in a layout this does not read");return{size:n,metresPerPixel:2*i/n,samples:s.samples,values:s.values}}async vectors(e,t,i){const n=li.radius(t),s=n/li.METRES_PER_DEGREE,r=n/(li.METRES_PER_DEGREE*Math.cos(e.lat*Math.PI/180)),l=`BBOX(geometrie,${[e.lng-r,e.lat-s,e.lng+r,e.lat+s].map(p=>p.toFixed(6)).join(",")},'EPSG:4326')`,[c,h,d,u,f]=await Promise.all([this.features("construction_lineaire",`${l} AND nature='Pont'`,"nature,geometrie"),this.features("troncon_de_route",`${l} AND position_par_rapport_au_sol<>'0'`,"nature,largeur_de_chaussee,position_par_rapport_au_sol,nom_voie_ban_gauche,nom_voie_ban_droite,cpx_toponyme_route_nommee,geometrie"),this.features("ligne_electrique",l,"voltage,geometrie"),i?this.features("batiment",l,"nature,hauteur,nombre_d_etages,materiaux_des_murs,materiaux_de_la_toiture,date_modification,geometrie",5e3):Promise.resolve([]),i?this.features("zone_d_activite_ou_d_interet",l,"toponyme,geometrie",100).catch(()=>[]):Promise.resolve([])]);return{bridges:c,elevatedRoads:h,lines:d,buildings:u,zones:f,mapDate:li.latest(u.map(p=>p.properties.date_modification))}}async elevatedRoadLines(e){const t=`BBOX(geometrie,${[e.west,e.south,e.east,e.north].map(s=>s.toFixed(6)).join(",")},'EPSG:4326')`,i=await this.features("troncon_de_route",`${t} AND position_par_rapport_au_sol>'0'`,"geometrie",300),n=[];for(const s of i){const{type:r,coordinates:a}=s.geometry,l=r==="LineString"?[a]:r==="MultiLineString"?a:[];for(const c of l)n.push(c.map(h=>({lat:h[1],lng:h[0]})))}return n}async roads(e){const t=`BBOX(geometrie,${[e.west,e.south,e.east,e.north].map(i=>i.toFixed(6)).join(",")},'EPSG:4326')`;return this.features("troncon_de_route",`${t} AND nature<>'Sentier' AND nature<>'Escalier' AND position_par_rapport_au_sol>='0'`,"cleabs,nature,largeur_de_chaussee,nombre_de_voies,sens_de_circulation,vitesse_moyenne_vl,urbain,nom_voie_ban_gauche,nom_voie_ban_droite,cpx_toponyme_route_nommee,geometrie",3e3)}async raster(e,t,i,n){const s=t/li.METRES_PER_DEGREE,r=t/(li.METRES_PER_DEGREE*Math.cos(e.lat*Math.PI/180)),a=new URLSearchParams({SERVICE:"WMS",VERSION:"1.3.0",REQUEST:"GetMap",LAYERS:n,STYLES:"",CRS:"EPSG:4326",BBOX:[e.lat-s,e.lng-r,e.lat+s,e.lng+r].map(c=>c.toFixed(6)).join(","),WIDTH:String(i),HEIGHT:String(i),FORMAT:"image/geotiff"});let l;try{l=await this.fetchImpl(`${this.wms}?${a}`)}catch(c){throw new Ps("unreachable",c instanceof Error?c.message:String(c))}if(!l.ok)throw new Ps("unreachable",`The survey answered ${l.status}`);try{return wf.parse(await l.arrayBuffer())}catch(c){throw new Ps("unreachable",c instanceof Error?c.message:String(c))}}async features(e,t,i,n=200){const s=new URLSearchParams({SERVICE:"WFS",VERSION:"2.0.0",REQUEST:"GetFeature",TYPENAMES:e.includes(":")?e:`BDTOPO_V3:${e}`,SRSNAME:"EPSG:4326",OUTPUTFORMAT:"application/json",COUNT:String(n),CQL_FILTER:t,PROPERTYNAME:i});let r;try{r=await this.fetchImpl(`${this.wfs}?${s}`)}catch(l){throw new Ps("unreachable",l instanceof Error?l.message:String(l))}if(!r.ok)throw new Ps("unreachable",`The map answered ${r.status}`);return(await r.json()).features??[]}}class fa{static NEAR_M=15;static ALIGNED_DEG=30;static LONG_ENOUGH_M=15;static SAMPLE_M=5;static follows(e,t){if(e.length<2||t.length<2)return!1;const i=t[0],n=t.map(a=>vt(a.lat,a.lng,i.lat,i.lng)),s=e.map(a=>vt(a.lat,a.lng,i.lat,i.lng));let r=0;for(let a=0;a<s.length-1;a++){const l=s[a],c=s[a+1],h=Math.hypot(c.x-l.x,c.z-l.z);if(h<1e-6)continue;const d=Math.max(1,Math.ceil(h/fa.SAMPLE_M)),u=Math.atan2(c.x-l.x,-(c.z-l.z));for(let f=0;f<=d;f++){const p=f/d,g=fa.nearest(n,l.x+(c.x-l.x)*p,l.z+(c.z-l.z)*p);g.distanceM>fa.NEAR_M||fa.angleBetween(u,g.heading)<=fa.ALIGNED_DEG&&(r+=h/d)}}return r>=fa.LONG_ENOUGH_M}static nearest(e,t,i){let n={distanceM:1/0,heading:0};for(let s=0;s<e.length-1;s++){const r=e[s],a=e[s+1],l=a.x-r.x,c=a.z-r.z,h=l*l+c*c,d=h<1e-9?0:Math.max(0,Math.min(1,((t-r.x)*l+(i-r.z)*c)/h)),u=Math.hypot(t-(r.x+l*d),i-(r.z+c*d));u<n.distanceM&&(n={distanceM:u,heading:Math.atan2(l,-c)})}return n}static angleBetween(e,t){const i=Math.abs((e-t)*180/Math.PI%180);return Math.min(i,180-i)}}class Jt{static WMS="https://data.geopf.fr/wms-r/wms";static LAYERS=["IGNF_LIDAR-HD_MNT_ELEVATION.ELEVATIONGRIDCOVERAGE.LAMB93","ELEVATION.ELEVATIONGRIDCOVERAGE.HIGHRES"];static METRES_PER_PIXEL=4;static METRES_PER_DEGREE=111320;static CLASS_LAYER="IGNF_LIDAR-HD_CLASS";static SURFACE_LAYER="IGNF_LIDAR-HD_MNS_ELEVATION.ELEVATIONGRIDCOVERAGE.LAMB93";static DECK=[240,240,0];static NO_CLASS=[0,0,0];static DECK_END_PIXELS=3;static MIN_PIXELS=8;static MAX_PIXELS=700;static NO_DATA_BELOW=-9e3;static MESH_FROM_VERTICES=33;static FINE_SPACING_M=7;static MAX_SEGMENTS=256;static MAX_HOLE_SHARE=.05;static DEFAULT_TIMEOUT_MS=12e3;static MAX_WINDOW_M=50;fetchImpl;wms;timeoutMs;maxWindowM;geoplatform;constructor(e={}){this.fetchImpl=e.fetchImpl??fetch.bind(globalThis),this.wms=e.wmsEndpoint??Jt.WMS,this.timeoutMs=e.timeoutMs??Jt.DEFAULT_TIMEOUT_MS,this.maxWindowM=e.maxWindowM??Jt.MAX_WINDOW_M,this.geoplatform=new li({fetchImpl:this.fetchImpl,wmsEndpoint:this.wms,wfsEndpoint:e.wfsEndpoint})}async getElevationGrid(e,t,i){const n={lat:(e.south+e.north)/2,lng:(e.west+e.east)/2};if(!li.covers(n.lat,n.lng))throw new Error("The IGN's relief covers France only");const s=Math.abs(vt(n.lat,e.east,n.lat,e.west).x),r=Math.abs(vt(e.north,n.lng,e.south,n.lng).z);t=this.finer(t,s,r);const a={x:s/Math.max(1,t.width-1),y:r/Math.max(1,t.height-1)},l={x:Math.min(a.x,this.maxWindowM),y:Math.min(a.y,this.maxWindowM)},c={south:e.south-l.y/Jt.METRES_PER_DEGREE,north:e.north+l.y/Jt.METRES_PER_DEGREE,west:e.west-l.x/(Jt.METRES_PER_DEGREE*Math.cos(n.lat*Math.PI/180)),east:e.east+l.x/(Jt.METRES_PER_DEGREE*Math.cos(n.lat*Math.PI/180))},h=p=>Math.min(Jt.MAX_PIXELS,Math.max(Jt.MIN_PIXELS,Math.ceil(p/Jt.METRES_PER_PIXEL))),d={width:h(s+2*l.x),height:h(r+2*l.y)},u={x:(s+2*l.x)/d.width,y:(r+2*l.y)/d.height};let f=new Error("No layer of the IGN's relief answered");for(const p of Jt.LAYERS)try{const g=await this.heights(c,d,p);p===Jt.LAYERS[0]&&await this.layBridgeDecks(g,c,d,i?.route);const m=this.sample(g,t,e,c,u,a);if(m)return{heights:m,width:t.width,height:t.height,bounds:e};f=new Error(`${p} does not cover this place`)}catch(g){f=g}throw f}finer(e,t,i){if(e.width<Jt.MESH_FROM_VERTICES||e.height<Jt.MESH_FROM_VERTICES)return e;const n=(s,r)=>{const a=Math.ceil(s/Jt.FINE_SPACING_M),l=Math.max(r-1,Math.min(Jt.MAX_SEGMENTS,a));return l%2===0?l:l+1};return{width:n(t,e.width)+1,height:n(i,e.height)+1}}async raster(e,t,i){const n=new URLSearchParams({SERVICE:"WMS",VERSION:"1.3.0",REQUEST:"GetMap",LAYERS:i,STYLES:"",CRS:"EPSG:4326",BBOX:[e.south,e.west,e.north,e.east].map(r=>r.toFixed(6)).join(","),WIDTH:String(t.width),HEIGHT:String(t.height),FORMAT:"image/geotiff"}),s=await this.fetchImpl(`${this.wms}?${n}`,{signal:AbortSignal.timeout(this.timeoutMs)});if(!s.ok)throw new Error(`The IGN's relief answered ${s.status}`);return wf.parse(await s.arrayBuffer())}async heights(e,t,i){const n=await this.raster(e,t,i);if(n.samples!==1||!(n.values instanceof Float32Array))throw new Error("The IGN's relief came in a layout this does not read");return n}async layBridgeDecks(e,t,i,n){if(!(!n||n.length<2)&&!(!(e.values instanceof Float32Array)||!e.values.some(s=>s>Jt.NO_DATA_BELOW)))try{const s=(await this.geoplatform.elevatedRoadLines({west:t.west,south:t.south,east:t.east,north:t.north})).filter(v=>fa.follows(n,v));if(s.length===0)return;const r=await this.raster(t,i,Jt.CLASS_LAYER);if(r.samples<3||r.width!==e.width||r.height!==e.height)return;const a=(v,[b,x,y])=>r.values[v*r.samples]===b&&r.values[v*r.samples+1]===x&&r.values[v*r.samples+2]===y,l=e.width,c=e.height,h=new Uint8Array(l*c);let d=!1;for(let v=0;v<h.length;v++)a(v,Jt.DECK)&&(h[v]=1,d=!0);if(!d)return;const u=Jt.DECK_END_PIXELS,f=[];for(let v=0;v<h.length;v++){if(h[v]!==1)continue;const b=v%l,x=(v-b)/l;for(let y=-u;y<=u;y++)for(let w=-u;w<=u;w++){const S=b+w,A=x+y;if(S<0||A<0||S>=l||A>=c)continue;const M=A*l+S;h[M]===0&&a(M,Jt.NO_CLASS)&&f.push(M)}}for(const v of f)h[v]=1;const p=this.paint(s,t,l,c),g=this.touching(h,p,l,c);if(g.every(v=>v===0))return;const m=await this.heights(t,i,Jt.SURFACE_LAYER);if(m.width!==l||m.height!==c)return;for(let v=0;v<g.length;v++){if(g[v]===0)continue;const b=m.values[v];Number.isFinite(b)&&b>Jt.NO_DATA_BELOW&&b>e.values[v]&&(e.values[v]=b)}}catch{}}paint(e,t,i,n){const s=new Uint8Array(i*n),r=l=>(l-t.west)/(t.east-t.west)*i,a=l=>(t.north-l)/(t.north-t.south)*n;for(const l of e)for(let c=0;c<l.length-1;c++){const h=r(l[c].lng),d=a(l[c].lat),u=r(l[c+1].lng),f=a(l[c+1].lat),p=Math.max(1,Math.ceil(Math.hypot(u-h,f-d)*2));for(let g=0;g<=p;g++){const m=Math.floor(h+(u-h)*g/p),v=Math.floor(d+(f-d)*g/p);for(let b=-1;b<=1;b++)for(let x=-1;x<=1;x++){const y=m+x,w=v+b;y>=0&&w>=0&&y<i&&w<n&&(s[w*i+y]=1)}}}return s}touching(e,t,i,n){const s=new Uint8Array(e.length),r=new Uint8Array(e.length);for(let a=0;a<e.length;a++){if(e[a]===0||r[a]===1)continue;const l=[],c=[a];r[a]=1;let h=!1;for(;c.length>0;){const d=c.pop();l.push(d),t[d]===1&&(h=!0);const u=d%i,f=(d-u)/i;for(let p=-1;p<=1;p++)for(let g=-1;g<=1;g++){const m=u+g,v=f+p;if(m<0||v<0||m>=i||v>=n)continue;const b=v*i+m;e[b]===1&&r[b]===0&&(r[b]=1,c.push(b))}}if(h)for(const d of l)s[d]=1}return s}sample(e,t,i,n,s,r){const{width:a,height:l}=t,c=new Float32Array(a*l),h=new Uint8Array(a*l),d=Math.min(r.x,this.maxWindowM)/s.x,u=Math.min(r.y,this.maxWindowM)/s.y;let f=0;for(let p=0;p<l;p++){const g=i.north+(i.south-i.north)*(l===1?.5:p/(l-1)),m=(n.north-g)/(n.north-n.south)*e.height-.5;for(let v=0;v<a;v++){const x=(i.west+(i.east-i.west)*(a===1?.5:v/(a-1))-n.west)/(n.east-n.west)*e.width-.5,y=d>1||u>1?this.tent(e,x,m,Math.max(1,d),Math.max(1,u)):this.bilinear(e,x,m),w=p*a+v;y===void 0?f++:(c[w]=y,h[w]=1)}}if(!(f===a*l||f/(a*l)>Jt.MAX_HOLE_SHARE))return this.fill(c,h,a,l),c}tent(e,t,i,n,s){let r=0,a=0,l=0;const c=Math.max(0,Math.ceil(i-s)),h=Math.min(e.height-1,Math.floor(i+s)),d=Math.max(0,Math.ceil(t-n)),u=Math.min(e.width-1,Math.floor(t+n));for(let f=c;f<=h;f++){const p=1-Math.abs(f-i)/s;if(!(p<=0))for(let g=d;g<=u;g++){const m=p*(1-Math.abs(g-t)/n);if(m<=0)continue;l+=m;const v=e.at(g,f);!Number.isFinite(v)||v<Jt.NO_DATA_BELOW||(r+=m*v,a+=m)}}return l>0&&a>=l*.5?r/a:void 0}bilinear(e,t,i){const n=Math.max(0,Math.min(e.width-1,Math.floor(t))),s=Math.max(0,Math.min(e.height-1,Math.floor(i))),r=Math.min(e.width-1,n+1),a=Math.min(e.height-1,s+1),l=Math.max(0,Math.min(1,t-n)),c=Math.max(0,Math.min(1,i-s)),h=e.at(n,s),d=e.at(r,s),u=e.at(n,a),f=e.at(r,a);for(const m of[h,d,u,f])if(!Number.isFinite(m)||m<Jt.NO_DATA_BELOW)return;const p=h+(d-h)*l,g=u+(f-u)*l;return p+(g-p)*c}fill(e,t,i,n){let s=t.reduce((r,a)=>r+(a?0:1),0);for(;s>0;){const r=[];for(let a=0;a<n;a++)for(let l=0;l<i;l++){const c=a*i+l;if(t[c])continue;let h=0,d=0;for(let u=-1;u<=1;u++)for(let f=-1;f<=1;f++){const p=a+u,g=l+f;p<0||g<0||p>=n||g>=i||!t[p*i+g]||(h+=e[p*i+g],d++)}d>0&&r.push([c,h/d])}if(r.length===0)return;for(const[a,l]of r)e[a]=l,t[a]=1;s-=r.length}}}class KS{providers;constructor(...e){this.providers=e}async getElevationGrid(e,t,i){let n=new Error("No source of relief to ask");for(const s of this.providers)try{return await s.getElevationGrid(e,t,i)}catch(r){n=r}throw n}}const Kd=256,ZS=5;async function HM(o,e,t,i){const n=(o.south+o.north)/2,s=(o.west+o.east)/2,r=Math.abs(vt(n,o.east,n,o.west).x),a=Math.abs(vt(o.north,s,o.south,s).z),l=Math.max(r,a),{zoom:c,gridSize:h}=jS(n,l,Math.max(e.width,e.height)),{tiles:d,bounds:u}=BM(s,n,c,h),f=h*Kd,p=document.createElement("canvas");p.width=f,p.height=f;const g=p.getContext("2d");if(!g)throw new Error("2D canvas context unavailable");const m=d[0];await Promise.all(d.map(async y=>{const w=t(y),S=await i(w);if(!S.ok)throw new Error(`Imagery tile fetch failed (${S.status}): ${w}`);const A=await createImageBitmap(await S.blob());g.drawImage(A,(y.x-m.x)*Kd,(y.y-m.y)*Kd)}));const v=Math.min(Math.max(e.width,e.height),f);if(v===f)return{source:p,width:f,height:f,bounds:u};const b=document.createElement("canvas");b.width=v,b.height=v;const x=b.getContext("2d");if(!x)throw new Error("2D canvas context unavailable");return x.drawImage(p,0,0,f,f,0,0,v,v),{source:b,width:v,height:v,bounds:u}}function jS(o,e,t){let i=VS(o,e/Math.max(1,t)),n=qv(o,i,e);for(;n>ZS&&i>0;)i--,n=qv(o,i,e);return{zoom:i,gridSize:n,mPerPixel:NM(o,i)/Kd}}function qv(o,e,t){const i=Math.ceil(t/2/NM(o,e));return Math.max(3,2*i+1)}class GM{attribution="Imagery © Esri, Maxar, Earthstar Geographics, and the GIS User Community";fetchImpl;tileUrlTemplate;constructor(e={}){this.fetchImpl=e.fetchImpl??fetch.bind(globalThis),this.tileUrlTemplate=e.tileUrlTemplate??"https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"}async getImageryTexture(e,t){return HM(e,t,i=>this.tileUrlTemplate.replace("{z}",String(i.z)).replace("{y}",String(i.y)).replace("{x}",String(i.x)),this.fetchImpl)}}class El{static ENDPOINTS=["https://overpass-api.de/api/interpreter","https://overpass.kumi.systems/api/interpreter","https://overpass.private.coffee/api/interpreter"];fetchImpl;endpoints;constructor(e={}){this.fetchImpl=e.fetchImpl??fetch.bind(globalThis),this.endpoints=e.endpoints??El.ENDPOINTS}static queue=Promise.resolve();static RETRY_MS=4e3;query(e){return this.queued(()=>this.ask(e))}queued(e){const t=El.queue.then(e,e);return El.queue=t.catch(()=>{}),t}async ask(e){let t;for(const i of this.endpoints)for(let n=0;n<2;n++){try{const s=await this.fetchImpl(`${i}?data=${encodeURIComponent(e)}`);if(s.ok)return await s.json();if(t=new Error(`${new URL(i).host} refused (${s.status})`),s.status!==429&&s.status!==504)break}catch(s){t=new Error(`${new URL(i).host} unreachable (${String(s)})`);break}await new Promise(s=>setTimeout(s,El.RETRY_MS))}throw t??new Error("No Overpass instance answered")}}class pa{attribution="Roads © OpenStreetMap contributors, as surveyed today";contemporary=!0;static DRIVABLE=["motorway","trunk","primary","secondary","tertiary","unclassified","residential","service","track","motorway_link","trunk_link","primary_link","secondary_link","tertiary_link"];static WIDTH_M={motorway:11,trunk:9,primary:8,secondary:7,tertiary:6.5,unclassified:5.5,residential:5.5,service:4,track:3.5};static DEFAULT_WIDTH_M=5;client;constructor(e={}){this.client=new El(e)}async getRoads(e){const t=`${e.south},${e.west},${e.north},${e.east}`,i=`[out:json][timeout:30];way["highway"~"^(${pa.DRIVABLE.join("|")})$"](${t});out geom;`;return this.waysFrom(await this.client.query(i))}waysFrom(e){const t=[];for(const i of e.elements??[]){const n=i.geometry,s=i.tags;!s||!n||n.length<2||t.push({id:`osm-${i.id??t.length}`,name:s.name,surface:pa.surfaceOf(s),widthM:pa.widthOf(s),...pa.paintOf(s),points:n.map(r=>({lat:r.lat,lng:r.lon}))})}return t}static paintOf(e){const t=e.highway??"",i=e.junction==="roundabout"||e.junction==="circular",n=e.oneway,s=n==="yes"||n==="1"||n==="true"||n===void 0&&(t==="motorway"||i),r=n==="-1"||n==="reverse",a=Number.parseInt(e.lanes??"",10),l=Number.parseInt(e.maxspeed??"",10),c=i?"roundabout":t==="motorway"?"motorway":t.endsWith("_link")?"slip":(t==="trunk"||t==="primary")&&(s||r)?"dual":t?"road":void 0;return{...c?{kind:c}:{},...Number.isFinite(a)&&a>0?{lanes:a}:{},...n!==void 0||t==="motorway"||i?{direction:r?"backward":s?"forward":"both"}:{},...Number.isFinite(l)&&l>0?{speedKmh:l}:{}}}static widthOf(e){const t=Number.parseFloat(e.width??e.est_width??"");if(Number.isFinite(t)&&t>0)return t;const i=Number.parseInt(e.lanes??"",10);return Number.isFinite(i)&&i>0?i*3.5:pa.WIDTH_M[e.highway]??pa.DEFAULT_WIDTH_M}static surfaceOf(e){const t=e.surface;return t==="dirt"||t==="earth"||t==="mud"?"dirt":t==="gravel"||t==="fine_gravel"||t==="compacted"||t==="ground"||t==="sand"||t==="unpaved"?"gravel":t?"paved":e.highway==="track"?"gravel":"paved"}}const Gf="https://ufoathome.org/roads/index.json";class Al{attributionRead;contemporaryRead;fetchImpl;indexUrls;fallback;index;static shared=new Map;sharing;constructor(e={}){this.sharing=!e.fetchImpl,this.fetchImpl=e.fetchImpl??fetch.bind(globalThis),this.indexUrls=e.indexUrls??Al.defaultIndexUrls(),this.fallback=e.fallback}get attribution(){return this.attributionRead??this.fallback?.attribution??"Roads © OpenStreetMap contributors"}get contemporary(){return this.contemporaryRead??this.fallback?.contemporary??!0}async getRoads(e){const t=await this.held(e);if(t)return t;if(!this.fallback)return[];const i=await this.fallback.getRoads(e);return this.attributionRead=this.fallback.attribution,this.contemporaryRead=this.fallback.contemporary,i}async held(e){let t;try{t=await this.load()}catch{return}const i=t.find(({entry:n})=>n.north>=e.north&&n.south<=e.south&&n.east>=e.east&&n.west<=e.west);if(i)try{const n=await this.fetchImpl(new URL(i.entry.file,i.indexUrl).href);if(!n.ok)return;const s=await n.json();return Array.isArray(s?.ways)?(this.attributionRead=s.attribution,this.contemporaryRead=s.contemporary,s.ways):void 0}catch{return}}load(){if(this.index)return this.index;if(!this.sharing)return this.index=this.fetchFirstAvailable();const e=this.indexUrls.join(`
2836
- `);let t=Al.shared.get(e);return t||(t=this.fetchFirstAvailable(),Al.shared.set(e,t),t.then(i=>{i.length===0&&Al.shared.delete(e)})),this.index=t}async fetchFirstAvailable(){for(const e of this.indexUrls)try{const t=await this.fetchImpl(e);if(!t.ok)continue;const i=await t.json();if(Array.isArray(i?.entries))return i.entries.map(n=>({entry:n,indexUrl:e}))}catch{}return[]}static defaultIndexUrls(){const e=`?v=${encodeURIComponent("0.115.3")}`,t=typeof location>"u"?void 0:new URL("/roads/index.json",location.href).href;return(t&&t!==Gf?[t,Gf]:[Gf]).map(i=>i+e)}}class ya{attribution="Roads © IGN, BD TOPO (Licence Ouverte 2.0), as drawn today";contemporary=!0;static BY_NATURE={"Type autoroutier":{surface:"paved",widthM:11},"Route à 2 chaussées":{surface:"paved",widthM:7},"Route à 1 chaussée":{surface:"paved",widthM:5.5},"Rond-point":{surface:"paved",widthM:6},Bretelle:{surface:"paved",widthM:5},"Route empierrée":{surface:"gravel",widthM:3.5},Chemin:{surface:"dirt",widthM:3},"Piste cyclable":{surface:"paved",widthM:2.5}};static DEFAULT={surface:"paved",widthM:5};static KINDS={"Type autoroutier":"motorway","Route à 2 chaussées":"dual","Route à 1 chaussée":"road","Rond-point":"roundabout",Bretelle:"slip"};static DIRECTIONS={"Double sens":"both","Sens direct":"forward","Sens inverse":"backward"};platform;constructor(e={}){this.platform=new li(e)}static covers(e){return li.covers((e.south+e.north)/2,(e.west+e.east)/2)}async getRoads(e){return(await this.platform.roads(e)).flatMap((i,n)=>ya.wayOf(i,n))}static wayOf(e,t){if(e.geometry.type!=="LineString")return[];const i=e.geometry.coordinates.map(([u,f])=>({lat:f,lng:u}));if(i.length<2)return[];const n=String(e.properties.nature??""),s=ya.BY_NATURE[n]??ya.DEFAULT,r=Number(e.properties.largeur_de_chaussee),a=Number(e.properties.nombre_de_voies),l=Number(e.properties.vitesse_moyenne_vl),c=ya.DIRECTIONS[String(e.properties.sens_de_circulation??"")],h=ya.KINDS[n],d=[e.properties.cpx_toponyme_route_nommee,e.properties.nom_voie_ban_gauche,e.properties.nom_voie_ban_droite].find(u=>typeof u=="string"&&u.length>0);return[{id:String(e.properties.cleabs??`ign-${t}`),...d?{name:d}:{},surface:s.surface,widthM:Number.isFinite(r)&&r>0?r:s.widthM,...e.properties.urbain===!0?{urban:!0}:{},...h?{kind:h}:{},...Number.isInteger(a)&&a>0?{lanes:a}:{},...c?{direction:c}:{},...Number.isFinite(l)&&l>0?{speedKmh:l}:{},points:i}]}}class JS{constructor(e,t){this.regional=e,this.worldwide=t}attribution="Roads © IGN, BD TOPO, in France; © OpenStreetMap contributors elsewhere, as drawn today";contemporary=!0;async getRoads(e){if(ya.covers(e))try{const t=await this.regional.getRoads(e);if(t.length>0)return t}catch{}return this.worldwide.getRoads(e)}}function QS(){return{elevation:VM(),imagery:WM(),roads:eE()}}function VM(){return new KS(new Jt,new zM)}function WM(){return new GM}function eE(){return new Al({fallback:new JS(new ya,new pa)})}const tE=new Set,Bl="show-observer-map",zl="hide-milestones";class Et extends HTMLElement{static get observedAttributes(){return["src",Bl,zl]}shadow;stageElement;canvas;canvasRenderer;chromeCanvas;chromeRenderer;chromeResizeObserver=typeof ResizeObserver>"u"?void 0:new ResizeObserver(()=>{this.chromeDirty&&this.refresh()});chromeDirty=!1;tooltip;toolbar;issuesBox;issuesButton;issuesPanel;playPauseButton;static OBSERVER_MAP_MIN_SPAN_M=400;static OBSERVER_MAP_MARGIN=.6;static OBSERVER_MAP_IMAGERY_PX=768;fullscreenButton;cornerButtons;observerMapButton;referencesButton;tracesButton;tracesShownState=!0;referenceOpacityInput;referencesShownState=!0;accountHidden=!1;referenceViews=new Map;referencesMenu;referenceOpacityTouched=!1;milestonesButton;observerMapPanel;observerMapCanvas;observerMapRenderer;mapZoomInButton;mapZoomOutButton;mapFitButton;observerMapView=new yi;observerMapDrag;suppressObserverMapClick=!1;observerMapImageryTimer;observerPlacing=!1;seekInput;playbackFlash;milestoneMarks;milestoneCaption;timeStartLabel;timeEndLabel;timePill;muteButton;volumeInput;controlsRow;momentsBox;momentsButton;momentsCurrent;momentsMenu;moreButton;controlsRight;seekSegments;seekDot;playerTitleBox;seekPreview;seekPreviewCanvas;seekPreviewTitle;seekPreviewTime;observerPath;observerMapBounds;observerMapImagery;observerMapImageryBounds;observerMapImageryViewWidth=0;observerMapImageryLoading=!1;observerMapImageryCredit;observerMapImageryFailed=!1;creditShownExternally=!1;lookYawDeg=0;lookPitchDeg=0;milestonesShown=!0;currentSighting=yf.create();issues=[];issueCheck=0;sightingAudio=new LS;soundPreview;player;loopEnabled=!1;playbackBeforeClick;highlightedSourceIds=new Set;paintsShapes=!0;steadyObserver=!1;static LIVE_BODY_MAX_RATE=2;get steadyBody(){return this.steadyObserver||this.player.playbackState!=="playing"||this.player.playbackRate>Et.LIVE_BODY_MAX_RATE}selectionShown=!0;overlayPainter;enableClickToPlay=!0;fullscreenTarget;messages=CM;realDurationMs;realStartMs;showClockTime=!0;handleFullscreenChange=()=>{this.updateFullscreenButton(),this.updateMuteButton(),this.resizeObserverMap()};controlsFitObserver=typeof ResizeObserver>"u"?void 0:new ResizeObserver(()=>this.fitControls());controlsMutations;fitControls(){const e=this.controlsRow,t=e.classList.contains("more-open"),i=()=>e.scrollWidth>e.clientWidth+1,n=!this.momentsMenu.hidden;if(this.momentsMenu.hidden=!0,e.classList.remove("narrow","more-open","nomoments","compact","tiny"),e.clientWidth>0&&i()){e.classList.add("narrow");for(const s of["nomoments","compact","tiny"]){if(!i())break;e.classList.add(s)}t&&e.classList.add("more-open")}this.momentsMenu.hidden=!n,this.updateMoreButton()}setControlsFolded(e){this.controlsRow.classList.toggle("more-open",!e),this.updateMoreButton()}updateMoreButton(){const e=this.controlsRow.classList.contains("more-open");Et.setIcon(this.moreButton,e?qe.UNFOLDED:qe.FOLDED);const t=e?this.messages.fewerControls:this.messages.moreControls;this.moreButton.title=t,this.moreButton.setAttribute("aria-label",t),this.moreButton.setAttribute("aria-expanded",String(e))}addControl(e){this.controlsRight.insertBefore(e,this.fullscreenButton.parentElement===this.controlsRight?this.fullscreenButton:null),this.fitControls()}observerMapResizeObserver=typeof ResizeObserver>"u"?void 0:new ResizeObserver(()=>this.resizeObserverMap());resizeObserverMap(){this.observerMapPanel.hidden||(this.sizeObserverMapCanvas(),this.paintObserverMap(this.currentTime))}simulatedFullscreen=!1;styleBeforeSimulatedFullscreen;bodyOverflowBeforeSimulatedFullscreen;handleSimulatedFullscreenKey=e=>{e.key==="Escape"&&this.exitSimulatedFullscreen()};handlePointerMove=e=>{const t=this.canvasPointFromEvent(e),i=t&&this.shapeAt(t.x,t.y),n=this.said.read(i?.shape.title);if(!n){this.tooltip.hidden=!0;return}this.tooltip.textContent=n,this.tooltip.hidden=!1;const s=this.stageElement.getBoundingClientRect();this.tooltip.style.left=`${e.clientX-s.left+12}px`,this.tooltip.style.top=`${e.clientY-s.top+12}px`};handleObserverMapPointerMove=e=>{if(this.dragObserverMap(e))return;const t=this.observerMapTargetFrom(e);if(!t){if(!this.observerPlacing){this.tooltip.hidden=!0,this.observerMapCanvas.style.cursor="grab";return}this.observerMapCanvas.style.cursor="crosshair",this.showObserverMapTooltip(e,this.messages.placeObserverHere);return}this.observerMapCanvas.style.cursor="pointer",this.showObserverMapTooltip(e,t.label)};showObserverMapTooltip(e,t){this.tooltip.textContent=t,this.tooltip.hidden=!1;const i=this.stageElement.getBoundingClientRect();this.tooltip.style.left=`${e.clientX-i.left+12}px`,this.tooltip.style.top=`${e.clientY-i.top+12}px`}handleObserverMapClick=e=>{if(this.suppressObserverMapClick){this.suppressObserverMapClick=!1;return}const t=this.observerMapTargetFrom(e);if(!t){this.observerPlacing&&this.placeObserverFrom(e);return}if(t.kind==="milestone"&&t.t!==void 0){this.player.seek(t.t);return}this.dispatchEvent(new CustomEvent("lookat",{detail:{lat:t.lat,lng:t.lng,kind:t.kind},bubbles:!0,composed:!0}))};observerMapTargetFrom(e){const t=this.observerMapCanvas.getBoundingClientRect();if(!(t.width===0||t.height===0))return this.observerMapRenderer.hitTest((e.clientX-t.left)/t.width*this.observerMapCanvas.width,(e.clientY-t.top)/t.height*this.observerMapCanvas.height)}handlePointerLeave=()=>{this.tooltip.hidden=!0};handleObserverMapPointerDown=e=>{e.button===0&&(this.suppressObserverMapClick=!1,this.observerMapDrag={pointerId:e.pointerId,startX:e.clientX,startY:e.clientY,lastX:e.clientX,lastY:e.clientY,moved:!1})};handleObserverMapPointerUp=e=>{const t=this.observerMapDrag;!t||t.pointerId!==e.pointerId||(this.observerMapDrag=void 0,this.observerMapCanvas.classList.remove("dragging"),t.moved&&(this.suppressObserverMapClick=!0,this.paintObserverMap(this.currentTime),this.observerMapCanvas.hasPointerCapture?.(e.pointerId)&&this.observerMapCanvas.releasePointerCapture(e.pointerId)))};dragObserverMap(e){const t=this.observerMapDrag;if(!t||t.pointerId!==e.pointerId)return!1;if(!t.moved){if(Math.hypot(e.clientX-t.startX,e.clientY-t.startY)<Et.OBSERVER_MAP_DRAG_PX)return!1;t.moved=!0,this.tooltip.hidden=!0,this.observerMapCanvas.classList.add("dragging"),this.observerMapCanvas.setPointerCapture?.(e.pointerId)}const i=this.observerMapCanvas.getBoundingClientRect();return i.width>0&&i.height>0&&(this.observerMapView.panBy((e.clientX-t.lastX)/i.width,(e.clientY-t.lastY)/i.height),this.observerMapViewChanged()),t.lastX=e.clientX,t.lastY=e.clientY,!0}static OBSERVER_MAP_DRAG_PX=4;handleObserverMapWheel=e=>{e.preventDefault();const t=this.observerMapCanvas.getBoundingClientRect();if(t.width===0||t.height===0)return;const i=e.deltaMode===0?e.deltaY:e.deltaY*40;this.zoomObserverMap((e.clientX-t.left)/t.width,(e.clientY-t.top)/t.height,Math.exp(-i*.002))};zoomObserverMap(e,t,i){this.observerMapView.zoomAt(e,t,i),this.observerMapViewChanged()}observerMapViewChanged(){this.mapFitButton.hidden=!this.observerMapView.changed,this.mapZoomInButton.disabled=this.observerMapView.zoomFactor>=yi.MAX_ZOOM,this.mapZoomOutButton.disabled=this.observerMapView.zoomFactor<=yi.MIN_ZOOM,this.paintObserverMap(this.currentTime),this.scheduleObserverMapImagery()}scheduleObserverMapImagery(){this.observerMapImageryTimer===void 0&&(this.observerMapImageryTimer=setTimeout(()=>{this.observerMapImageryTimer=void 0,this.loadObserverMapImagery()},Et.OBSERVER_MAP_IMAGERY_DELAY_MS))}static OBSERVER_MAP_FOLLOW_MARGIN=.1;static OBSERVER_MAP_IMAGERY_DELAY_MS=300;get observerMapViewBounds(){return this.observerMapBounds&&this.observerMapView.boundsWithin(this.observerMapBounds)}placeObserverFrom(e){const t=this.observerMapViewBounds,i=this.observerMapCanvas.getBoundingClientRect();if(!t||i.width===0||i.height===0)return;const n=yi.pointAt(t,(e.clientX-i.left)/i.width,(e.clientY-i.top)/i.height);this.dispatchEvent(new CustomEvent("observerplace",{detail:n,bubbles:!0,composed:!0}))}constructor(){super(),this.shadow=this.attachShadow({mode:"open"});const e=document.createElement("template");e.innerHTML=`<style>${RS}</style>${DS}`,this.shadow.appendChild(e.content.cloneNode(!0)),this.stageElement=this.shadow.getElementById("stage"),this.canvas=this.shadow.getElementById("canvas"),this.canvasRenderer=new ic(this.canvas.getContext("2d")),this.chromeCanvas=this.shadow.getElementById("chrome"),this.tooltip=this.shadow.getElementById("tooltip"),this.toolbar=this.shadow.getElementById("toolbar"),this.issuesBox=this.shadow.getElementById("issues"),this.issuesButton=this.shadow.getElementById("issues-button"),this.issuesPanel=this.shadow.getElementById("issues-panel"),this.issuesButton.addEventListener("click",t=>{t.stopPropagation(),this.issuesPanel.hidden=!this.issuesPanel.hidden,this.issuesButton.setAttribute("aria-expanded",String(!this.issuesPanel.hidden))}),this.playPauseButton=this.shadow.getElementById("play-pause"),this.fullscreenButton=this.shadow.getElementById("fullscreen"),this.cornerButtons=this.shadow.getElementById("corner-buttons"),this.observerMapButton=this.shadow.getElementById("observer-map"),this.referencesButton=this.shadow.getElementById("references"),this.tracesButton=this.shadow.getElementById("traces"),this.referenceOpacityInput=this.shadow.getElementById("reference-opacity"),this.referencesMenu=this.shadow.getElementById("references-menu"),this.milestonesButton=this.shadow.getElementById("milestones"),this.observerMapPanel=this.shadow.getElementById("observer-map-panel"),this.observerMapCanvas=this.shadow.getElementById("observer-map-canvas"),this.observerMapRenderer=new Qa(this.observerMapCanvas.getContext("2d")),this.mapZoomInButton=this.shadow.getElementById("map-zoom-in"),this.mapZoomOutButton=this.shadow.getElementById("map-zoom-out"),this.mapFitButton=this.shadow.getElementById("map-fit"),this.seekInput=this.shadow.getElementById("seek"),this.playbackFlash=this.shadow.getElementById("playback-flash"),this.milestoneMarks=this.shadow.getElementById("milestone-marks"),this.milestoneCaption=this.shadow.getElementById("milestone-caption"),this.timeStartLabel=this.shadow.getElementById("time-start"),this.timeEndLabel=this.shadow.getElementById("time-end"),this.timePill=this.shadow.getElementById("time"),this.muteButton=this.shadow.getElementById("mute"),this.controlsRight=this.shadow.getElementById("controls-right"),this.seekSegments=this.shadow.getElementById("seek-segments"),this.seekDot=this.shadow.getElementById("seek-dot"),this.playerTitleBox=this.shadow.getElementById("player-title"),this.seekPreview=this.shadow.getElementById("seek-preview"),this.seekPreviewCanvas=this.shadow.getElementById("seek-preview-canvas"),this.seekPreviewTitle=this.shadow.getElementById("seek-preview-title"),this.seekPreviewTime=this.shadow.getElementById("seek-preview-time"),this.timePill.addEventListener("click",()=>this.toggleTimeDisplay()),this.timePill.addEventListener("keydown",t=>{t.key!=="Enter"&&t.key!==" "||(t.preventDefault(),this.toggleTimeDisplay())}),this.volumeInput=this.shadow.getElementById("volume"),this.controlsRow=this.shadow.querySelector(".controls"),this.momentsBox=this.shadow.getElementById("moments"),this.momentsButton=this.shadow.getElementById("moments-button"),this.momentsCurrent=this.shadow.getElementById("moments-current"),this.momentsMenu=this.shadow.getElementById("moments-menu"),this.momentsButton.addEventListener("click",()=>this.toggleMomentsMenu()),this.moreButton=this.shadow.getElementById("controls-more"),this.moreButton.addEventListener("click",()=>this.setControlsFolded(this.controlsRow.classList.contains("more-open"))),this.muteButton.addEventListener("click",()=>this.toggleMuted()),this.volumeInput.addEventListener("input",()=>{this.setVolume(Number(this.volumeInput.value))}),this.fullscreenTarget=this.stageElement,this.playPauseButton.addEventListener("click",()=>this.togglePlayPause()),this.fullscreenButton.addEventListener("click",()=>this.toggleFullscreen()),this.addEventListener("keydown",this.handleFullscreenKey),this.observerMapButton.addEventListener("click",()=>this.toggleObserverMap()),this.referencesButton.addEventListener("click",()=>this.toggleReferences()),this.tracesButton.addEventListener("click",()=>this.toggleTraces()),this.referenceOpacityInput.addEventListener("input",()=>{this.referenceOpacityTouched=!0,this.dispatchReferenceView()}),this.milestonesButton.addEventListener("click",()=>this.toggleMilestones()),this.observerMapCanvas.addEventListener("pointermove",this.handleObserverMapPointerMove),this.observerMapCanvas.addEventListener("pointerleave",this.handlePointerLeave),this.observerMapCanvas.addEventListener("click",this.handleObserverMapClick),this.observerMapCanvas.addEventListener("pointerdown",this.handleObserverMapPointerDown),this.observerMapCanvas.addEventListener("pointerup",this.handleObserverMapPointerUp),this.observerMapCanvas.addEventListener("pointercancel",this.handleObserverMapPointerUp),this.observerMapCanvas.addEventListener("wheel",this.handleObserverMapWheel,{passive:!1}),this.mapZoomInButton.addEventListener("click",()=>this.zoomObserverMap(.5,.5,2)),this.mapZoomOutButton.addEventListener("click",()=>this.zoomObserverMap(.5,.5,.5)),this.mapFitButton.addEventListener("click",()=>{this.observerMapView.reset(),this.observerMapViewChanged()}),this.seekInput.addEventListener("input",()=>this.player.seek(this.snapSeekToMark(Number(this.seekInput.value)))),this.seekInput.addEventListener("pointerdown",t=>{this.suspendForScrub(),this.seekSnapArmed=!0,this.nameMarkUnder(t),this.beginTouchScrub(t)}),this.seekInput.addEventListener("pointerup",t=>{this.seekSnapArmed=!1,this.endTouchScrub(t)}),this.seekInput.addEventListener("pointercancel",t=>this.endTouchScrub(t)),this.seekInput.addEventListener("pointermove",t=>{this.nameMarkUnder(t),this.hoverSeek(t),this.touchScrub(t)}),this.seekInput.addEventListener("pointerleave",()=>{this.seekInput.removeAttribute("title"),this.leaveSeek()}),this.seekInput.addEventListener("keydown",this.handleSeekKey),this.stageElement.addEventListener("pointerdown",()=>{this.handlePointerDown(),this.touchedStage()},!0);for(const t of["touchend","click"])this.stageElement.addEventListener(t,()=>this.sightingAudio.resume(),!0);this.stageElement.addEventListener("pointermove",()=>this.touchedStage()),this.canvas.addEventListener("click",t=>{if(this.enableClickToPlay){if(this.tapRevealedOnly){this.tapRevealedOnly=!1;return}t.detail<=1&&(this.playbackBeforeClick={state:this.playbackState,time:this.currentTime}),this.togglePlayPause()}}),this.canvas.addEventListener("dblclick",t=>{this.enableClickToPlay&&(t.preventDefault(),this.restorePlayback(),this.toggleFullscreen())}),this.canvas.addEventListener("pointermove",this.handlePointerMove),this.canvas.addEventListener("pointerleave",this.handlePointerLeave),document.addEventListener("fullscreenchange",this.handleFullscreenChange),document.addEventListener("pointerdown",this.handleMomentsDismiss,!0),document.addEventListener("keydown",this.handleMomentsDismiss,!0),document.addEventListener("visibilitychange",this.handleVisibility),window.addEventListener("pagehide",this.handleHidden),document.addEventListener("pointerup",this.handlePointerRelease,!0),document.addEventListener("pointercancel",this.handlePointerRelease,!0),this.observerMapResizeObserver?.observe(this.observerMapPanel),this.chromeResizeObserver?.observe(this.chromeCanvas),this.controlsFitObserver?.observe(this.controlsRow),this.controlsFitObserver?.observe(this.controlsRow.querySelector(".controls-left")),typeof MutationObserver<"u"&&(this.controlsMutations=new MutationObserver(()=>this.fitControls()),this.controlsMutations.observe(this.controlsRight,{attributes:!0,attributeFilter:["hidden"],childList:!0,subtree:!0})),this.hostControls(void 0),this.player=this.createPlayer(),this.updateTimeLabels(),this.updatePlayPauseButton(),this.updateFullscreenButton(),this.updateMuteButton(),this.updateObserverMapButton(),this.updateReferencesButton(),this.updateTracesButton(),this.updateMilestonesButton(),this.refresh()}connectedCallback(){this.saidTexts=void 0,this.loadLocaleMessages();const e=this.getAttribute("src");e&&this.loadFromSrc(e)}disconnectedCallback(){document.removeEventListener("fullscreenchange",this.handleFullscreenChange),document.removeEventListener("pointerdown",this.handleMomentsDismiss,!0),document.removeEventListener("keydown",this.handleMomentsDismiss,!0),document.removeEventListener("visibilitychange",this.handleVisibility),window.removeEventListener("pagehide",this.handleHidden),document.removeEventListener("pointerup",this.handlePointerRelease,!0),document.removeEventListener("pointercancel",this.handlePointerRelease,!0),window.clearTimeout(this.controlsIdleTimer),this.observerMapResizeObserver?.disconnect(),this.chromeResizeObserver?.disconnect(),this.controlsFitObserver?.disconnect(),this.controlsMutations?.disconnect(),this.exitSimulatedFullscreen(),this.sightingAudio.dispose()}attributeChangedCallback(e,t,i){e==="src"&&i&&i!==t&&this.isConnected&&this.loadFromSrc(i),e===Bl&&this.applyObserverMapDefault(),e===zl&&this.setMilestonesShown(!this.hasAttribute(zl))}async loadFromSrc(e){this.sightingData=await lh.json(e)}get sightingData(){return OS(this.currentSighting)}set sightingData(e){this.player.stop(),this.soundPreview=void 0,this.sightingAudio.silence(),this.currentSighting=NS(e),this.issuesPanel.hidden=!0,this.issuesButton.setAttribute("aria-expanded","false"),this.reportIssues(e,this.currentSighting),this.observerMapView.reset(),this.mapFitButton.hidden=!0,this.observerMapAsked=!1,this.player=this.createPlayer(),this.syncPlayerTitle(),this.updateTimeLabels(),this.updatePlayPauseButton(),this.refresh(),this.applyObserverMapDefault()}set playerTitle(e){this.titleOverride=e,this.syncPlayerTitle()}titleOverride;syncPlayerTitle(){const e=this.said.read(this.titleOverride)??this.currentSighting.observer?.title??"";this.playerTitleBox.textContent=e,this.playerTitleBox.hidden=e===""}get recordingIssues(){return this.issues}async reportIssues(e,t){const i=++this.issueCheck;let n=[];try{const{default:s}=await Ue(async()=>{const{default:r}=await import("./sightingSchema-CNx1-oWD.js");return{default:r}},[],import.meta.url);n=new Cs(s).issues(e)}catch{}i===this.issueCheck&&(this.issues=[...n,...t.loadIssues],nc.warn(this.issues,t.id),this.renderIssues(),this.dispatchEvent(new CustomEvent(iE,{detail:{issues:this.issues},bubbles:!0,composed:!0})))}renderIssues(){const e=this.issues.length;this.issuesBox.hidden=e===0,this.shadow.getElementById("issues-count").textContent=String(e);const t=this.messages.recordingIssues.replace("{count}",String(e));this.issuesButton.title=t,this.issuesButton.setAttribute("aria-label",t),this.shadow.getElementById("issues-title").textContent=t,this.shadow.getElementById("issues-list").replaceChildren(...this.issues.map(i=>{const n=document.createElement("li");return n.textContent=nc.text(i,this.messages.issueTemplates),n}))}get sighting(){return this.currentSighting}previewSound(e){this.soundPreview=e,this.sightingAudio.resume(),this.sightingAudio.setSound(e)}stopSoundPreview(){this.soundPreview=void 0,this.sightingAudio.silence()}get canvasElement(){return this.canvas}get renderer(){return this.canvasRenderer}get currentTime(){return this.player.time}set currentTime(e){this.player.seek(e)}get seekableDuration(){return this.player.seekableDuration}get autoReplayEnabled(){return this.loopEnabled}set autoReplayEnabled(e){e!==this.loopEnabled&&this.toggleLoop()}play(){if(!(this.player.seekableDuration<=0||this.playbackState==="playing")){if(this.clockHeld){this.playAfterHold=!0;return}this.togglePlayPause()}}clockHeld=!1;playAfterHold=!1;holdClock(e){if(e!==this.clockHeld){if(this.clockHeld=e,e){if(this.playbackState!=="playing")return;this.playAfterHold=!0,this.player.pause(),this.soundPreview=void 0,this.sightingAudio.silence(),this.refresh(),this.updatePlayPauseButton();return}this.playAfterHold&&(this.playAfterHold=!1,!(this.player.seekableDuration<=0||this.playbackState==="playing")&&(this.sightingAudio.resume(),this.player.play(),this.updatePlayPauseButton()))}}pause(){this.playAfterHold=!1,this.playbackState==="playing"&&this.togglePlayPause()}get positionLabel(){return this.timeStartLabel.textContent??""}get durationLabel(){return this.timeEndLabel.textContent??""}get showingClockTime(){return this.canShowClockTime}get canSwitchTimeDisplay(){return this.realStartMs!==void 0}toggleTimeDisplay(){this.canSwitchTimeDisplay&&(this.showClockTime=!this.showClockTime,this.updateTimeLabels(),this.updateTimeLabelTitles(),this.dispatchEvent(new CustomEvent("timedisplaychange",{bubbles:!0,composed:!0})))}get canShowClockTime(){return this.realStartMs!==void 0&&this.showClockTime}set showToolbar(e){this.toolbar.classList.toggle("hidden",!e),e?this.controlsRight.appendChild(this.fullscreenButton):this.cornerButtons.appendChild(this.fullscreenButton)}get playbackState(){return this.player.playbackState}get selectedSourceIds(){return this.highlightedSourceIds}get durationSeconds(){return this.currentSighting.event.durationSeconds}set durationSeconds(e){this.currentSighting.event.durationSeconds=e,this.updateTimeLabels(),this.refresh(),this.updatePlayPauseButton()}set selectedSourceIds(e){const t=new Set(e);t.size===this.highlightedSourceIds.size&&[...t].every(n=>this.highlightedSourceIds.has(n))||(this.highlightedSourceIds=t,this.refresh())}hasVisibleShapeAt(e,t){return this.shapeAt(e,t)!==void 0}refresh(){this.applyFrameFormat(),this.updateMuteButton(),this.updateTimeLabels(),this.seekInput.max=String(this.player.seekableDuration),this.refreshMilestoneMarks(),this.updateMilestonesButton(),this.updateObserverMap(),this.updateReferences(),this.updateTracesButton(),this.player.seek(this.player.time)}hostControls(e){const t=[this.milestonesButton,this.referencesButton,this.referenceOpacityInput,this.tracesButton,this.observerMapButton];if(e)for(const i of t)e.appendChild(i);else{const i=this.fullscreenButton.parentElement===this.controlsRight?this.fullscreenButton:null;for(const n of t)this.controlsRight.insertBefore(n,i)}}get referencesShown(){return this.referencesShownState}get referenceOpacity(){return Number(this.referenceOpacityInput.value)}get severalReferences(){return this.currentSighting.references.length>1}toggleReferences(){if(this.severalReferences){this.toggleReferencesMenu();return}this.referencesShownState=!this.referencesShownState,this.updateReferencesButton(),this.dispatchReferenceView()}updateReferences(){const e=this.currentSighting.references;!this.referenceOpacityTouched&&e.length>0&&(this.referenceOpacityInput.value=String(e[0].opacity));for(const t of[...this.referenceViews.keys()])e.some(i=>i.id===t)||this.referenceViews.delete(t);this.severalReferences?this.referencesMenu.hidden||this.renderReferencesMenu():this.closeReferencesMenu(),this.updateReferencesButton(),this.severalReferences&&this.dispatchReferenceView()}viewOfReference(e){let t=this.referenceViews.get(e.id);return t||(t={shown:!0,opacity:e.opacity},this.referenceViews.set(e.id,t)),t}toggleReferencesMenu(){this.referencesMenu.hidden?this.openReferencesMenu():this.closeReferencesMenu()}openReferencesMenu(){this.renderReferencesMenu(),this.referencesMenu.hidden=!1,this.placeReferencesMenu(),this.referencesButton.setAttribute("aria-expanded","true"),document.addEventListener("pointerdown",this.handleReferencesMenuOutside,!0),document.addEventListener("keydown",this.handleReferencesMenuKey,!0)}closeReferencesMenu(){this.referencesMenu.hidden||(this.referencesMenu.hidden=!0,this.referencesButton.setAttribute("aria-expanded","false"),document.removeEventListener("pointerdown",this.handleReferencesMenuOutside,!0),document.removeEventListener("keydown",this.handleReferencesMenuKey,!0))}handleReferencesMenuOutside=e=>{const t=e.composedPath();t.includes(this.referencesMenu)||t.includes(this.referencesButton)||this.closeReferencesMenu()};handleReferencesMenuKey=e=>{e.key==="Escape"&&(this.closeReferencesMenu(),this.referencesButton.focus())};placeReferencesMenu(){const e=this.referencesButton.getBoundingClientRect(),t=this.referencesMenu,i=4;t.style.bottom=`${Math.max(i,window.innerHeight-e.top+i)}px`,t.style.top="auto";const n=t.getBoundingClientRect().width;t.style.left=`${Math.max(i,Math.min(e.left,window.innerWidth-n-i))}px`}renderReferencesMenu(){const e=this.currentSighting.references.map(t=>{const i=this.viewOfReference(t),n=this.said.read(t.title)??t.id,s=document.createElement("div");s.className="reference-row";const r=document.createElement("label"),a=document.createElement("input");a.type="checkbox",a.checked=i.shown;const l=document.createElement("span");l.textContent=n,l.title=n,r.append(a,l);const c=document.createElement("input");return c.type="range",c.min="0",c.max="1",c.step="0.05",c.value=String(i.opacity),c.title=this.messages.referenceOpacity,c.setAttribute("aria-label",`${this.messages.referenceOpacity}: ${n}`),c.disabled=!i.shown,a.addEventListener("change",()=>{i.shown=a.checked,c.disabled=!i.shown,this.updateReferencesButton(),this.dispatchReferenceView()}),c.addEventListener("input",()=>{i.opacity=Number(c.value),this.dispatchReferenceView()}),s.append(r,c),s});this.referencesMenu.setAttribute("aria-label",this.messages.referencesMenu),this.referencesMenu.replaceChildren(...e)}updateReferencesButton(){const e=this.currentSighting.references.length>0,t=this.severalReferences,i=t?this.currentSighting.references.some(s=>this.viewOfReference(s).shown):this.referencesShownState;this.referencesButton.hidden=!e,this.referenceOpacityInput.hidden=!e||!this.referencesShownState||t,this.referencesButton.setAttribute("aria-pressed",String(i)),t?this.referencesButton.setAttribute("aria-haspopup","true"):this.referencesButton.removeAttribute("aria-haspopup"),Et.setIcon(this.referencesButton,i?qe.PICTURES_ON:qe.PICTURES_OFF);const n=t?this.messages.referencesMenu:this.referencesShownState?this.messages.hideReferences:this.messages.showReferences;this.referencesButton.title=n,this.referencesButton.setAttribute("aria-label",n),this.referenceOpacityInput.title=this.messages.referenceOpacity,this.referenceOpacityInput.setAttribute("aria-label",this.messages.referenceOpacity)}get tracesShown(){return this.tracesShownState}toggleTraces(){this.tracesShownState=!this.tracesShownState,this.updateTracesButton(),this.updateObserverMap(),this.dispatchEvent(new CustomEvent("traceview",{detail:{shown:this.tracesShown}}))}updateTracesButton(){this.tracesButton.hidden=this.currentSighting.traces.length===0,this.tracesButton.setAttribute("aria-pressed",String(this.tracesShownState)),Et.setIcon(this.tracesButton,this.tracesShownState?qe.TRACES_ON:qe.TRACES_OFF);const e=this.tracesShownState?this.messages.hideTraces:this.messages.showTraces;this.tracesButton.title=e,this.tracesButton.setAttribute("aria-label",e)}dispatchReferenceView(){const e=this.severalReferences?Object.fromEntries(this.currentSighting.references.map(t=>[t.id,{...this.viewOfReference(t)}])):void 0;this.dispatchEvent(new CustomEvent("referenceview",{detail:{shown:this.referencesShown,opacity:this.referenceOpacity,views:e}}))}refreshMilestoneMarks(){const e=this.player.seekableDuration,t=e>0?Io(this.sighting.milestones):[];this.milestoneMarks.replaceChildren(...t.map(i=>{const n=document.createElement("button");n.type="button",n.className="milestone-mark",n.style.left=`${Math.min(Math.max(i.t/e,0),1)*100}%`;const s=this.said.read(i.label)??"",r=this.said.read(i.note),a=r?`${s} — ${r}`:s;return n.title=a,n.setAttribute("aria-label",a),n.dataset.t=String(i.t),n.addEventListener("click",()=>this.player.seek(i.t)),n})),this.refreshSeekSegments(e,t.map(i=>i.t)),this.refreshMomentsPicker(t)}refreshMomentsPicker(e){const t=this.milestonesShown&&e.length>0;this.momentsBox.hidden=!t,this.closeMomentsMenu(),this.momentsMenu.replaceChildren(...e.map(i=>{const n=document.createElement("li"),s=document.createElement("button");s.type="button",s.dataset.t=String(i.t);const r=this.said.read(i.label)??"",a=this.said.read(i.note);return s.textContent=a?`${r} — ${a}`:r,s.addEventListener("click",()=>{this.player.seek(i.t),this.closeMomentsMenu()}),n.appendChild(s),n})),this.momentsButton.title=this.messages.moments,this.showCurrentMoment(void 0)}showCurrentMoment(e){const i=(e?this.said.read(e.label)??"":"")||this.messages.moments;this.momentsCurrent.textContent!==i&&(this.momentsCurrent.textContent=i);for(const n of this.momentsMenu.querySelectorAll("button")){const s=e!==void 0&&Number(n.dataset.t)===e.t;n.getAttribute("aria-current")==="true"!==s&&n.setAttribute("aria-current",String(s))}}toggleMomentsMenu(){this.momentsMenu.hidden?(this.momentsMenu.hidden=!1,this.momentsButton.setAttribute("aria-expanded","true")):this.closeMomentsMenu()}closeMomentsMenu(){this.momentsMenu.hidden=!0,this.momentsButton.setAttribute("aria-expanded","false")}handleMomentsDismiss=e=>{if(!this.momentsMenu.hidden){if(e instanceof KeyboardEvent){e.key==="Escape"&&this.closeMomentsMenu();return}e.composedPath().some(t=>t===this.momentsMenu||t===this.momentsButton)||this.closeMomentsMenu()}};seekSegmentList=[];refreshSeekSegments(e,t){const n=[0,...this.milestonesShown&&e>0?[...new Set(t.filter(r=>r>0&&r<e))].sort((r,a)=>r-a):[],Math.max(e,0)];this.seekSegmentList=[];const s=[];for(let r=0;r<n.length-1;r++){const a=document.createElement("div");a.className="seek-segment",a.style.flexGrow=String(Math.max(n[r+1]-n[r],1));const l=document.createElement("i");l.className="seek-hover";const c=document.createElement("i");c.className="seek-played",a.append(l,c),s.push(a),this.seekSegmentList.push({start:n[r],end:n[r+1],element:a,played:c,hover:l})}this.seekSegments.replaceChildren(...s),this.paintSeekProgress(this.player.time)}static fillOf(e,t){const i=e.end-e.start,n=i>0?(t-e.start)/i:t>=e.end?1:0;return`${Math.min(Math.max(n,0),1)*100}%`}paintSeekProgress(e){for(const i of this.seekSegmentList)i.played.style.width=Et.fillOf(i,e);const t=this.player.seekableDuration;this.seekDot.style.left=`${t>0?Math.min(Math.max(e/t,0),1)*100:0}%`}hoverSeek(e){const t=this.seekInput.getBoundingClientRect(),i=this.player.seekableDuration;if(t.width<=0||i<=0)return;const n=Math.min(Math.max((e.clientX-t.left)/t.width,0),1),s=n*i,r=this.seekSegmentList.length-1;this.seekSegmentList.forEach((f,p)=>{f.hover.style.width=Et.fillOf(f,s),f.element.classList.toggle("hovered",s>=f.start&&(s<f.end||p===r))});const a=this.milestonesShown?this.sighting.milestones:[],l=a.length>0?zf(a,s):void 0,c=l?this.said.read(l.label)??"":"",h=l?this.said.read(l.note):void 0,d=h?`${c} — ${h}`:c;this.seekPreviewTitle.textContent=d,this.seekPreviewTime.textContent=this.formatPosition(s),this.seekPreview.hidden=!1;const u=this.seekPreview.offsetWidth;this.seekPreview.style.left=`${Math.min(Math.max(n*t.width-u/2,0),Math.max(t.width-u,0))}px`,this.paintSeekPreview(s)}leaveSeek(){for(const e of this.seekSegmentList)e.hover.style.width="0",e.element.classList.remove("hovered");this.seekPreview.hidden=!0}seekPreviewPainter;paintSeekPreview(e){const t=this.seekPreviewPainter;this.seekPreviewCanvas.hidden=t===void 0,t?.(e,this.seekPreviewCanvas)}paintChrome(e){const t=this.chromeCanvas.getContext("2d"),i=this.overlayPainter!==void 0||this.selectionShown;if(!i&&!this.chromeDirty)return;const n=this.chromeCanvas.clientWidth,s=this.chromeCanvas.clientHeight;if(!t||typeof t.setTransform!="function"||n===0||s===0){e(this.canvasRenderer);return}const r=window.devicePixelRatio||1,a=Math.max(1,Math.round(n*r)),l=Math.max(1,Math.round(s*r));this.chromeCanvas.width!==a&&(this.chromeCanvas.width=a),this.chromeCanvas.height!==l&&(this.chromeCanvas.height=l),t.setTransform(1,0,0,1,0,0),t.clearRect(0,0,a,l),this.chromeDirty=!1,i&&(t.setTransform(a/this.canvas.width,0,0,l/this.canvas.height,0,0),this.chromeRenderer??=new ic(t),this.chromeDirty=!0,e(this.chromeRenderer))}chromeDraw;repaintChrome(){this.chromeDraw&&this.overlayPainter&&this.paintChrome(this.chromeDraw)}scrubbingPointer;beginTouchScrub(e){if(e.pointerType!=="mouse"){this.scrubbingPointer=e.pointerId;try{this.seekInput.setPointerCapture(e.pointerId)}catch{}this.seekToPointer(e)}}touchScrub(e){e.pointerId===this.scrubbingPointer&&this.seekToPointer(e)}endTouchScrub(e){e.pointerId===this.scrubbingPointer&&(this.scrubbingPointer=void 0,this.seekToPointer(e))}seekToPointer(e){const t=this.seekInput.getBoundingClientRect(),i=this.player.seekableDuration;if(t.width<=0||i<=0)return;const n=Math.min(Math.max((e.clientX-t.left)/t.width,0),1);this.player.seek(this.snapSeekToMark(n*i))}seekSnapArmed=!1;static MARK_SNAP_PX=6;markNear(e){const t=this.player.seekableDuration,i=this.seekInput.getBoundingClientRect().width;if(t<=0||i<=0)return;const n=Et.MARK_SNAP_PX/i*t;let s;for(const r of this.milestoneMarks.children){const a=Number(r.dataset.t);Math.abs(a-e)>n||(!s||Math.abs(a-e)<Math.abs(s.t-e))&&(s={t:a,name:r.title})}return s}snapSeekToMark(e){return this.seekSnapArmed?(this.seekSnapArmed=!1,this.markNear(e)?.t??e):e}nameMarkUnder(e){const t=this.seekInput.getBoundingClientRect(),i=this.player.seekableDuration;if(t.width<=0||i<=0)return;const n=(e.clientX-t.left)/t.width*i,s=this.markNear(n);s?this.seekInput.title=s.name:this.seekInput.removeAttribute("title")}showMilestoneAt(e){const t=this.milestonesShown&&this.sighting.milestones.length>0?zf(this.sighting.milestones,e):void 0;if(this.milestoneCaption.hidden=t===void 0,this.showCurrentMoment(t),!t)return;const i=document.createElement("b");i.textContent=this.said.read(t.label)??"";const n=this.said.read(t.note),s=n?` — ${n}`:"";this.milestoneCaption.replaceChildren(i,document.createTextNode(s))}exposureInstants(e){const t=this.exposureTimes(e),i=1/t.length;return t.map(n=>({shapes:this.shapesAt(n),share:i}))}exposureTimes(e=this.currentTime){const t=Fs.windowEndingAt(e,this.currentSighting.exposure??0);if(t.ms<Et.SHORTEST_VISIBLE_EXPOSURE_MS)return[e];const i=Math.min(Et.MAX_EXPOSURE_STEPS,Math.max(2,Math.round(t.ms/Et.SHORTEST_VISIBLE_EXPOSURE_MS))),n=Math.ceil(this.travelPxOver(t.fromMs,t.ms)/Et.EXPOSURE_STEP_PX),s=Math.min(Et.MAX_TRAVEL_STEPS,Math.max(i,n)),r=[];for(let a=0;a<s;a++)r.push(t.fromMs+t.ms*a/(s-1));return r}travelPxOver(e,t){const i=this.shapesAt(e),n=this.shapesAt(e+t);let s=0;for(const[r,a]of i){const l=n.get(r);if(!l)continue;const c=l.bounds.x+l.bounds.width/2-(a.bounds.x+a.bounds.width/2),h=l.bounds.y+l.bounds.height/2-(a.bounds.y+a.bounds.height/2);s=Math.max(s,Math.hypot(c,h))}return s}shapeAt(e,t,i){if(!this.accountHidden)for(const n of this.exposureTimes()){const s=this.currentSighting.timeline.hitTest(n,e,t,i);if(s)return s}}shapesAt(e){const t=new Map;for(const i of this.currentSighting.timeline.sourceIds){const n=this.currentSighting.timeline.getInterpolatedShapeAt(e,i);n&&t.set(i,n)}return t}static SHORTEST_VISIBLE_EXPOSURE_MS=20;static MAX_EXPOSURE_STEPS=48;static EXPOSURE_STEP_PX=2;static MAX_TRAVEL_STEPS=320;applyFrameFormat(){const e=Bt.frameWidthPx(this.currentSighting.instrument,this.canvas.height);if(this.canvas.width===e)return;this.canvas.width=e,this.canvas.parentElement?.style.setProperty("--frame-aspect",`${e} / ${this.canvas.height}`)}canvasPointFromEvent(e){const t=this.canvas.getBoundingClientRect();if(!(t.width===0||t.height===0))return{x:(e.clientX-t.left)/t.width*this.canvas.width,y:(e.clientY-t.top)/t.height*this.canvas.height}}onFrame(e,t){this.canvasRenderer.clear(this.canvas.width,this.canvas.height);const i=this.playbackState!=="playing"?this.highlightedSourceIds:tE;this.canvasRenderer.setStarPoints(Bt.starPointsOf(this.sighting.instrument));const n=(at(this.sighting,e)?.rollDeg??0)+this.gaitAt(e).rollDeg;this.canvasRenderer.setRoll(n*Math.PI/180);const s=this.exposureInstants(e),r=this.frameShift;if(this.paintsShapes)for(const l of s)for(const[,c]of l.shapes){const h=l.share,d=h===1?c:{...c,transparency:1-(1-c.transparency)*h};this.canvasRenderer.paintShape(this.shifted(d,r))}for(const[l,c]of s[0].shapes)!this.selectionShown||!i.has(l)||(this.paintsShapes?i.size===1?this.canvasRenderer.paintShape({...c,selected:!0}):this.canvasRenderer.paintMemberOutline(c):this.canvasRenderer.paintSelectionOnly(this.shifted(c,r)));const a=this.selectionShown&&i.size>1?kt.groupBoundsFor([...t].filter(([l])=>i.has(l)).map(([,l])=>l.bounds)):void 0;this.chromeDraw=l=>{a&&l.paintGroupHandles(a),this.overlayPainter?.(l)},this.paintChrome(this.chromeDraw),this.mapShapeBounds=s.flatMap(l=>[...l.shapes.values()].filter(c=>c.transparency<1).map(c=>this.shifted(c,r).bounds)),this.keepObserverMapClear(),this.seekInput.value=String(e),this.paintSeekProgress(e),this.timeStartLabel.textContent=this.formatPosition(e),this.showMilestoneAt(e),this.paintObserverMap(e),this.playbackState==="playing"?(this.soundPreview=void 0,this.sightingAudio.setSound(ng(this.currentSighting,e))):this.soundPreview?this.sightingAudio.setSound(this.soundPreview):this.sightingAudio.silence(),this.updatePlayPauseButton(),this.dispatchEvent(new CustomEvent("timeupdate",{detail:{time:e}}))}shifted(e,t){return t.x===0&&t.y===0?e:{...e,bounds:{...e.bounds,x:e.bounds.x+t.x,y:e.bounds.y+t.y}}}createPlayer(){const e=new CS(this.currentSighting.timeline,(t,i)=>this.onFrame(t,i));return e.loop=this.loopEnabled,e.onEnded=()=>{this.updatePlayPauseButton(),this.dispatchEvent(new CustomEvent("ended",{bubbles:!0,composed:!0}))},e}static SEEK_KEY_STEP_MS=5e3;handleFullscreenKey=e=>{e.key.toLowerCase()!=="f"||e.altKey||e.ctrlKey||e.metaKey||!this.enableClickToPlay||e.composedPath().some(i=>i instanceof HTMLElement&&(i.isContentEditable||["INPUT","TEXTAREA","SELECT"].includes(i.tagName)&&i.type!=="range"))||(e.preventDefault(),this.toggleFullscreen())};handleSeekKey=e=>{if(e.altKey||e.ctrlKey||e.metaKey)return;const t=e.key==="ArrowLeft"?-1:e.key==="ArrowRight"?1:0;if(t){e.preventDefault();const i=this.player.seekableDuration;this.player.seek(Math.min(i,Math.max(0,this.player.time+t*Et.SEEK_KEY_STEP_MS)))}else e.key===" "&&(e.preventDefault(),this.togglePlayPause())};togglePlayPause(){if(!(this.player.seekableDuration<=0)){if(this.player.playbackState==="playing")this.player.pause(),this.soundPreview=void 0,this.sightingAudio.silence(),this.refresh();else if(this.clockHeld){this.playAfterHold=!this.playAfterHold;return}else this.sightingAudio.resume(),this.player.play();this.updatePlayPauseButton(),this.flashPlayback()}}flashPlayback(){const e=this.playbackFlash;e.innerHTML=this.player.playbackState==="playing"?qe.PLAY:qe.PAUSE,e.classList.remove("flashing"),e.offsetWidth,e.classList.add("flashing")}static icons=new WeakMap;static setIcon(e,t){Et.icons.get(e)!==t&&(Et.icons.set(e,t),e.innerHTML=t)}set captionHeld(e){this.stageElement.classList.toggle("caption-held",e)}static CONTROLS_IDLE_MS=3e3;controlsIdleTimer;wasPlaying=!1;quietControlsValue=!1;get quietControls(){return this.quietControlsValue}set quietControls(e){this.quietControlsValue=e,this.stageElement.classList.toggle("quiet",e)}tapRevealedOnly=!1;get hoverless(){return typeof matchMedia=="function"&&matchMedia("(hover: none)").matches}touchedStage(){if(!this.hoverless)return;this.player.playbackState==="playing"&&!this.stageElement.classList.contains("touched")&&(this.tapRevealedOnly=!0),this.revealControls()}pointerHeld=!1;handlePointerDown=()=>{this.pointerHeld=!0};resumeAfterScrub=!1;suspendForScrub(){this.player.playbackState==="playing"&&(this.resumeAfterScrub=!0,this.stopPlaying())}stopPlaying(){this.player.pause(),this.soundPreview=void 0,this.sightingAudio.silence(),this.refresh(),this.updatePlayPauseButton()}resumeFromScrub(){this.resumeAfterScrub&&(this.resumeAfterScrub=!1,this.sightingAudio.resume(),this.player.play(),this.updatePlayPauseButton())}handleHidden=()=>{this.player.playbackState==="playing"&&this.stopPlaying(),this.resumeAfterScrub=!1};handleVisibility=()=>{document.visibilityState==="hidden"&&this.handleHidden()};handlePointerRelease=()=>{this.resumeAfterScrub&&window.setTimeout(()=>this.resumeFromScrub(),0),this.pointerHeld&&(this.pointerHeld=!1,this.hoverless&&this.stageElement.classList.contains("touched")&&this.revealControls())};revealControls(){this.stageElement.classList.add("touched"),window.clearTimeout(this.controlsIdleTimer),this.player.playbackState==="playing"&&(this.pointerHeld||!this.momentsMenu.hidden||(this.controlsIdleTimer=window.setTimeout(()=>{this.stageElement.classList.remove("touched"),this.tapRevealedOnly=!1},Et.CONTROLS_IDLE_MS)))}updatePlayPauseButton(){const e=this.player.playbackState==="playing";this.stageElement.classList.toggle("paused",!e),e!==this.wasPlaying&&e&&this.hoverless&&(!this.quietControlsValue||this.stageElement.classList.contains("touched"))&&this.revealControls(),this.wasPlaying=e,Et.setIcon(this.playPauseButton,e?qe.PAUSE:qe.PLAY);const t=this.player.seekableDuration>0;this.playPauseButton.disabled=!t;const i=t?e?this.messages.pause:this.messages.play:this.messages.noDuration;this.playPauseButton.title=i,this.playPauseButton.setAttribute("aria-label",i)}toggleLoop(){this.loopEnabled=!this.loopEnabled,this.player.loop=this.loopEnabled}restorePlayback(){const e=this.playbackBeforeClick;e&&(this.currentTime=e.time,e.state==="playing"?this.play():this.pause())}get canUseNativeFullscreen(){return typeof this.fullscreenTarget.requestFullscreen=="function"&&document.fullscreenEnabled}toggleFullscreen(){if(!this.canUseNativeFullscreen){this.simulatedFullscreen?this.exitSimulatedFullscreen():this.enterSimulatedFullscreen();return}document.fullscreenElement?document.exitFullscreen():this.fullscreenTarget.requestFullscreen().catch(e=>{console.error("<rr0-ufo>: requestFullscreen() failed —",e)})}enterSimulatedFullscreen(){const e=this.fullscreenTarget;this.styleBeforeSimulatedFullscreen=e.getAttribute("style")??"",this.bodyOverflowBeforeSimulatedFullscreen=document.body.style.overflow;const t=e.style;t.setProperty("position","fixed"),t.setProperty("inset","0"),t.setProperty("margin","0"),t.setProperty("max-width","none"),t.setProperty("max-height","none"),t.setProperty("aspect-ratio","auto"),t.setProperty("z-index","2147483647"),t.setProperty("background","#000"),t.setProperty("width","100vw"),t.setProperty("width","100dvw"),t.setProperty("height","100vh"),t.setProperty("height","100dvh"),document.body.style.overflow="hidden",this.simulatedFullscreen=!0,document.addEventListener("keydown",this.handleSimulatedFullscreenKey),this.updateFullscreenButton(),this.updateMuteButton()}exitSimulatedFullscreen(){if(!this.simulatedFullscreen)return;const e=this.fullscreenTarget;this.styleBeforeSimulatedFullscreen?e.setAttribute("style",this.styleBeforeSimulatedFullscreen):e.removeAttribute("style"),document.body.style.overflow=this.bodyOverflowBeforeSimulatedFullscreen??"",this.simulatedFullscreen=!1,document.removeEventListener("keydown",this.handleSimulatedFullscreenKey),this.updateFullscreenButton(),this.updateMuteButton()}toggleObserverMap(){const e=this.observerMapPanel.hidden;this.observerMapAsked=e,this.setObserverMapOpen(e),this.keepObserverMapClear(),this.dispatchEvent(new CustomEvent("observermapchange",{bubbles:!0,composed:!0,detail:{open:e}}))}get observerMapOpen(){return!this.observerMapPanel.hidden}get milestonesVisible(){return this.milestonesShown}observerMapAsked=!1;applyObserverMapDefault(){const e=this.getAttribute(Bl),t=e===null?this.sighting.observerMap??this.observerPath?.travels===!0:e!=="false";this.setObserverMapOpen(t&&this.observerPath!==void 0)}setObserverMapOpen(e){this.observerMapPanel.hidden=!e,this.observerMapPanel.removeAttribute("title"),this.observerMapButton.setAttribute("aria-pressed",String(e)),this.updateObserverMapButton(),e&&(this.sizeObserverMapCanvas(),this.loadObserverMapImagery(),this.paintObserverMap(this.currentTime))}updateObserverMapButton(){const e=!this.observerMapPanel.hidden;Et.setIcon(this.observerMapButton,e?qe.MAP_ON:qe.MAP_OFF);const t=e?this.messages.hideObserverMap:this.messages.showObserverMap;this.observerMapButton.title=t,this.observerMapButton.setAttribute("aria-label",t);const i=[[this.mapZoomInButton,this.messages.zoomMapIn],[this.mapZoomOutButton,this.messages.zoomMapOut],[this.mapFitButton,this.messages.fitMap]];for(const[n,s]of i)n.title=s,n.setAttribute("aria-label",s)}updateObserverMap(){const e=this.observerPath!==void 0;if(this.observerPath=Ul.of(this.currentSighting),this.observerMapButton.hidden=this.observerPath===void 0,!e&&this.observerPath&&this.applyObserverMapDefault(),!this.observerPath){this.setObserverMapOpen(!1),this.observerMapBounds=void 0;return}const t=this.tracesShownState?this.currentSighting.traces.flatMap(n=>n.points):[],i=yi.including(this.observerPath.boundsAround(Et.OBSERVER_MAP_MIN_SPAN_M,Et.OBSERVER_MAP_MARGIN),t);(!this.observerMapBounds||!this.sameGround(this.observerMapBounds,i))&&(this.observerMapBounds&&this.observerMapView.refit(this.observerMapBounds,i),this.observerMapBounds=i,this.observerMapImagery=void 0,this.observerMapImageryCredit=void 0,this.observerMapImageryFailed=!1,this.observerMapImageryBounds=void 0,this.observerMapImageryLoading=!1,this.observerMapPanel.hidden||this.loadObserverMapImagery())}sameGround(e,t){const i=Math.abs(e.east-e.west)/20;return Math.abs(e.north-t.north)<i&&Math.abs(e.south-t.south)<i&&Math.abs(e.west-t.west)<i&&Math.abs(e.east-t.east)<i}async loadObserverMapImagery(){const e=this.observerMapViewBounds;if(!e||this.observerMapPanel.hidden||this.observerMapImageryLoading||!this.observerMapImageryNeededFor(e))return;const t=this.observerMapView.changed,i=t?yi.expand(e,Et.OBSERVER_MAP_IMAGERY_AHEAD):e,n=Et.OBSERVER_MAP_IMAGERY_PX*(t?1+2*Et.OBSERVER_MAP_IMAGERY_AHEAD:1);this.observerMapImageryBounds=i,this.observerMapImageryViewWidth=e.east-e.west,this.observerMapImageryLoading=!0;const s=WM();try{const r=await s.getImageryTexture(i,{width:n,height:n});if(this.observerMapImageryBounds!==i)return;this.observerMapImagery=r,this.observerMapImageryCredit=s.attribution,this.observerMapImageryFailed=!1}catch{if(this.observerMapImageryBounds!==i)return;this.observerMapImageryFailed=this.observerMapImagery===void 0}finally{this.observerMapImageryBounds===i&&(this.observerMapImageryLoading=!1)}this.paintObserverMap(this.currentTime),this.scheduleObserverMapImagery()}static OBSERVER_MAP_IMAGERY_AHEAD=.5;static OBSERVER_MAP_IMAGERY_LOOKAHEAD=.25;observerMapImageryNeededFor(e){const t=this.observerMapImageryBounds;if(!t)return!0;const i=this.observerMapImagery?.bounds??t,n=this.observerMapView.changed?yi.expand(e,Et.OBSERVER_MAP_IMAGERY_LOOKAHEAD):e,s=n.west>=i.west&&n.east<=i.east&&n.south>=i.south&&n.north<=i.north,r=e.east-e.west>this.observerMapImageryViewWidth/2;return!s||!r}get observerMapCredit(){return this.observerMapImageryCredit}get observerMapFooterLine(){return this.observerMapImageryFailed?this.messages.mapImageryUnavailable:this.creditShownExternally?void 0:this.observerMapImageryCredit}mapShapeBounds=[];mapSceneBounds=[];setMapSubjectBounds(e){this.mapSceneBounds=e.map(t=>({x:t.x*this.canvas.width,y:t.y*this.canvas.height,width:t.width*this.canvas.width,height:t.height*this.canvas.height})),this.keepObserverMapClear()}keepObserverMapClear(){if(this.observerMapPanel.hidden)return;const e=this.observerMapBoxPx;if(!e)return;const t=[...this.mapShapeBounds,...this.mapSceneBounds],i=(c,h,d)=>{for(const u of t)if(!(u.x+u.width<c-d||u.x>h+d)&&!(u.y>e.bottom+d||u.y+u.height<e.top-d))return!0;return!1},n=[this.canvas.width-e.width,this.canvas.width],s=[0,e.width],r=Et.OBSERVER_MAP_CLEARANCE_PX,a=i(...n,0),l=i(...s,0);if(this.observerMapPanel.classList.toggle("subject-overlap",a&&l&&!this.observerMapAsked),this.observerMapPanel.classList.contains("on-the-left")){!a&&(l||!i(n[0],n[1],r))&&this.observerMapPanel.classList.remove("on-the-left");return}i(n[0],n[1],0)&&!i(s[0],s[1],0)&&this.observerMapPanel.classList.add("on-the-left")}observerMapBoxPx;static OBSERVER_MAP_CLEARANCE_PX=24;sizeObserverMapCanvas(){const e=this.observerMapPanel.clientWidth;if(e===0)return;const t=Math.round(e*(globalThis.devicePixelRatio??1));this.measureObserverMapBox(),this.observerMapCanvas.width!==t&&(this.observerMapCanvas.width=t,this.observerMapCanvas.height=t)}measureObserverMapBox(){const e=this.observerMapPanel.getBoundingClientRect(),t=this.canvas.getBoundingClientRect();if(t.width===0||t.height===0)return;const i=this.canvas.width/t.width,n=this.canvas.height/t.height;this.observerMapBoxPx={width:e.width*i,top:(e.top-t.top)*n,bottom:(e.bottom-t.top)*n}}paintObserverMap(e){if(this.observerMapPanel.hidden||!this.observerPath||!this.observerMapBounds)return;const t=at(this.currentSighting,e);t?.lat!==void 0&&t.lng!==void 0&&!this.observerMapDrag?.moved&&this.observerMapView.keepInView(this.observerMapBounds,{lat:t.lat,lng:t.lng},Et.OBSERVER_MAP_FOLLOW_MARGIN)&&this.scheduleObserverMapImagery();const i=this.currentSighting.instrument,n=[],s=this.currentSighting.milestones.length>0?zf(this.currentSighting.milestones,e):void 0;for(const r of this.milestonesShown?Io(this.currentSighting.milestones):[]){const a=at(this.currentSighting,r.t);a?.lat===void 0||a.lng===void 0||n.push({label:this.said.read(r.label)??"",note:this.said.read(r.note),t:r.t,lat:a.lat,lng:a.lng,current:r===s})}this.observerMapRenderer.paint({bounds:this.observerMapViewBounds,imagery:this.observerMapImagery,path:this.observerPath,position:t?.lat!==void 0&&t.lng!==void 0?{lat:t.lat,lng:t.lng}:void 0,headingDeg:t?.headingDeg===void 0?void 0:t.headingDeg+this.lookYawDeg,coneHalfAngleDeg:t?Vs.of(i,this.canvas.height,t.fovDeg).halfWidthAngleDeg(Bt.aspectOf(i)):void 0,markers:n,traces:(this.tracesShownState?this.currentSighting.traces:[]).map(r=>({kind:r.kind,points:r.points,color:r.color,label:this.said.read(r.title)})),decor:this.observerMapDecorAt(e),observerLabel:this.said.read(this.currentSighting.observer?.title)??this.messages.observerHere,nightFraction:this.observerMapNightFraction,attribution:this.observerMapFooterLine})}toggleMilestones(){this.setMilestonesShown(!this.milestonesShown)}setMilestonesShown(e){this.milestonesShown=e,this.milestoneMarks.hidden=!e,this.momentsBox.hidden=!e||this.sighting.milestones.length===0,this.refreshSeekSegments(this.player.seekableDuration,Io(this.sighting.milestones).map(t=>t.t)),this.milestonesButton.setAttribute("aria-pressed",String(e)),this.updateMilestonesButton(),this.showMilestoneAt(this.currentTime),this.paintObserverMap(this.currentTime)}updateMilestonesButton(){this.milestonesButton.hidden=this.currentSighting.milestones.length===0,this.momentsButton.title=this.messages.moments,Et.setIcon(this.milestonesButton,this.milestonesShown?qe.MILESTONES_ON:qe.MILESTONES_OFF);const e=this.milestonesShown?this.messages.hideMilestones:this.messages.showMilestones;this.milestonesButton.title=e,this.milestonesButton.setAttribute("aria-label",e)}observerMapDecorAt(e){const t=at(this.currentSighting,0);return t?.lat===void 0||t.lng===void 0?[]:this.currentSighting.decor.filter(i=>i.kind!=="crop").map(i=>{const n=Gs(i,e),{lat:s,lng:r}=us(n.eastM,-n.northM,t.lat,t.lng);return{lat:s,lng:r,headingDeg:n.headingDeg,label:this.said.read(i.title)??this.messages.decorHere}})}observerMapNightFraction;setSunAltitude(e){const t=e===void 0?void 0:Math.max(0,Math.min(1,-e/12));t!==this.observerMapNightFraction&&(this.observerMapNightFraction=t,this.paintObserverMap(this.currentTime))}setLookOffset(e,t){e===this.lookYawDeg&&t===this.lookPitchDeg||(this.lookYawDeg=e,this.lookPitchDeg=t,this.refresh())}get frameShiftPx(){return this.frameShift}get frameShift(){const e=this.gaitAt(this.currentTime),t=this.lookYawDeg+e.yawDeg,i=this.lookPitchDeg+e.pitchDeg;if(t===0&&i===0)return{x:0,y:0};const n=at(this.currentSighting,this.currentTime),s=Vs.of(this.currentSighting.instrument,this.canvas.height,n?.fovDeg??60);return{x:-s.angleDegToRadiusPx(t),y:s.angleDegToRadiusPx(i)}}gaitAt(e){return $t.bodyAt(this.currentSighting,e,this.steadyBody)}mutedState=!1;get muted(){return this.mutedState}set muted(e){e!==this.mutedState&&(this.mutedState=e,!e&&this.volumeState===0&&(this.volumeState=Et.RESTORED_VOLUME),this.applyLevel())}volumeState=1;static RESTORED_VOLUME=.5;get volume(){return this.volumeState}set volume(e){this.setVolume(e)}setVolume(e){this.volumeState=Math.min(Math.max(e,0),1),this.mutedState=this.volumeState===0,this.applyLevel()}get level(){return this.mutedState?0:this.volumeState}applyLevel(){this.sightingAudio.setLevel(this.level),this.updateMuteButton(),this.dispatchEvent(new CustomEvent("mutedchange",{bubbles:!0,composed:!0,detail:{muted:this.mutedState,volume:this.volumeState}}))}toggleMuted(){this.hasSound&&(this.muted=!this.mutedState)}ambientSound;get hasSound(){return this.currentSighting.soundTrack.allKeyframes.length>0||this.ambientSound?.(this.currentSighting)===!0}updateMuteButton(){const e=!this.hasSound;if(this.muteButton.disabled=e,this.volumeInput.hidden=e,e){Et.setIcon(this.muteButton,qe.MUTED),this.muteButton.title=this.messages.noSound,this.muteButton.setAttribute("aria-label",this.messages.noSound),this.muteButton.setAttribute("aria-pressed","true");return}Et.setIcon(this.muteButton,this.mutedState?qe.MUTED:qe.VOLUME);const t=this.mutedState?this.messages.unmute:this.messages.mute;this.muteButton.title=t,this.muteButton.setAttribute("aria-label",t),this.muteButton.setAttribute("aria-pressed",String(this.mutedState)),this.volumeInput.value=String(this.level)}updateFullscreenButton(){const e=this.simulatedFullscreen||document.fullscreenElement===this.fullscreenTarget;Et.setIcon(this.fullscreenButton,e?qe.EXIT_FULLSCREEN:qe.ENTER_FULLSCREEN),this.fullscreenButton.title=e?this.messages.exitFullscreen:this.messages.fullscreen,this.fullscreenButton.setAttribute("aria-label",this.fullscreenButton.title)}get said(){return this.saidTexts??=new Un(_s.preferencesFor(this))}saidTexts;async loadLocaleMessages(){const e=ch(_s.preferencesFor(this),ph);if(e===this.messagesLanguage||e==="en"&&this.messagesLanguage===void 0)return;this.messagesLanguage=e;const t=await rS(e);this.messagesLanguage===e&&this.applyMessages(t)}messagesLanguage;updateTimeLabelTitles(){const e=this.showClockTime?this.messages.switchToElapsed:this.messages.switchToClockTime,t=this.canSwitchTimeDisplay?` — ${e}`:"";this.timeStartLabel.title=this.messages.currentPosition+t,this.timeEndLabel.title=this.messages.duration+t,this.timePill.classList.toggle("switchable",this.canSwitchTimeDisplay),this.canSwitchTimeDisplay?(this.timePill.setAttribute("role","button"),this.timePill.setAttribute("tabindex","0")):(this.timePill.removeAttribute("role"),this.timePill.removeAttribute("tabindex"))}applyMessages(e){this.messages=e,this.updateTimeLabelTitles(),this.updatePlayPauseButton(),this.updateFullscreenButton(),this.updateMuteButton(),this.updateObserverMapButton(),this.updateReferencesButton(),this.updateTracesButton(),this.updateMilestonesButton(),this.renderIssues()}updateTimeLabels(){const e=this.currentSighting.event,t=ec(e);this.realDurationMs=t!==void 0&&t>0?t:void 0,this.realStartMs=e.time?v0(e.time):void 0;const i=this.currentSighting.timeline.duration;this.player.playbackRate=this.realDurationMs!==void 0&&i>0?i/this.realDurationMs:1,this.player.durationOverrideMs=i>0?0:this.realDurationMs??0,this.timeEndLabel.textContent=this.formatEndOfTimeline(),this.timeStartLabel.textContent=this.formatPosition(this.player.time),this.updateTimeLabelTitles()}formatPosition(e){if(this.realDurationMs===void 0)return Wh(e);const t=this.currentSighting.timeline.duration,i=t>0&&e<=t?e/t*this.realDurationMs:e;return this.canShowClockTime?Zv(Kv(this.realStartMs+i)):Wh(i)}formatEndOfTimeline(){return this.realDurationMs===void 0?Wh(this.currentSighting.timeline.duration):this.canShowClockTime?Zv(Kv(this.realStartMs+this.realDurationMs)):Wh(this.realDurationMs)}}function Kv(o){const e=new Date(o);return{hour:e.getUTCHours(),minute:e.getUTCMinutes(),second:e.getUTCSeconds()}}function Zv(o){if(o.hour===void 0)return"0:00";const e=t=>String(t).padStart(2,"0");return o.second?`${e(o.hour)}:${e(o.minute??0)}:${e(o.second)}`:`${e(o.hour)}:${e(o.minute??0)}`}function Wh(o){const e=Math.round(o/1e3),t=Math.floor(e/60),i=e%60;return`${t}:${String(i).padStart(2,"0")}`}const E0="rr0-ufo";function xf(){customElements.get(E0)||customElements.define(E0,Et)}const iE="recordingissues";class Kc{constructor(e,t){this.seekInput=e,this.layer=t,e.addEventListener("pointerdown",i=>{this.snapArmed=!0,this.nameMarkUnder(i)}),e.addEventListener("pointerup",()=>this.snapArmed=!1),e.addEventListener("pointermove",i=>this.nameMarkUnder(i)),e.addEventListener("pointerleave",()=>e.removeAttribute("title"))}static SNAP_PX=6;marks=[];duration=0;drawn="";snapArmed=!1;show(e,t){const i=t>0?[...e].sort((s,r)=>s.t-r.t):[],n=`${t}|${i.map(s=>`${s.kind}:${s.t}:${s.label}`).join("|")}`;n!==this.drawn&&(this.drawn=n,this.marks=i,this.duration=t,this.layer.replaceChildren(...i.map(s=>{const r=document.createElement("span");return r.className=`timeline-mark ${s.kind}`,r.style.left=`${Math.min(Math.max(s.t/t,0),1)*100}%`,r})))}snap(e){return this.snapArmed?(this.snapArmed=!1,this.markNear(e)?.t??e):e}next(e){return this.marks.find(t=>t.t>e+Kc.SAME_INSTANT)?.t}previous(e){return[...this.marks].reverse().find(t=>t.t<e-Kc.SAME_INSTANT)?.t}static SAME_INSTANT=.5;markNear(e){const t=this.seekInput.getBoundingClientRect().width;if(this.duration<=0||t<=0)return;const i=Kc.SNAP_PX/t*this.duration;let n;for(const s of this.marks)Math.abs(s.t-e)>i||(!n||Math.abs(s.t-e)<Math.abs(n.t-e)||s.t===n.t&&s.kind==="milestone")&&(n=s);return n}nameMarkUnder(e){const t=this.seekInput.getBoundingClientRect();if(t.width<=0||this.duration<=0)return;const i=this.marksNear((e.clientX-t.left)/t.width*this.duration);i?this.seekInput.title=i:this.seekInput.removeAttribute("title")}marksNear(e){const t=this.markNear(e);if(t)return[...new Set(this.marks.filter(i=>i.t===t.t).map(i=>i.label))].join(" · ")}}class _l{static HALF_SPAN_MS=2e3;static MIN_SPEED_MS=1;static at(e,t,i){const n=e.event.place?.[0],s=e.observerTrack;if(!n)return 0;const r=g=>{const m=s.getInterpolatedPoseAt(Math.max(0,g));if(!m||m.lat===void 0||m.lng===void 0)return;const v=vt(m.lat,m.lng,n.lat,n.lng);return{eastM:v.x,northM:-v.z,heading:m.headingDeg}},a=r(t-_l.HALF_SPAN_MS),l=r(t+_l.HALF_SPAN_MS),c=r(t);if(!a||!l||!c)return 0;const h=Math.hypot(l.eastM-a.eastM,l.northM-a.northM),d=2*_l.HALF_SPAN_MS/1e3;if(h/d<_l.MIN_SPEED_MS)return 0;const u=i.heightAt(l.eastM,l.northM)-i.heightAt(a.eastM,a.northM),f=Math.atan2(u,h)*180/Math.PI;if(c.heading===void 0)return f;const p=Math.atan2(l.eastM-a.eastM,l.northM-a.northM)*180/Math.PI;return f*Math.max(0,Math.cos((c.heading-p)*Math.PI/180))}}const nE=.08,jv=.15,Jv=2,sE=2e3;class rE{context;noiseBuffer;voices=new Map;level=1;master;paused=!0;requested=[];resume(){if(!this.context){if(typeof AudioContext>"u")return;try{this.context=new AudioContext}catch(e){console.warn("VehicleAudio: Web Audio unavailable, vehicles stay silent:",e);return}}To.unlock(this.context),this.apply()}setLevel(e){this.level=e,this.master&&(this.master.gain.value=e)}setPaused(e){e!==this.paused&&(this.paused=e,this.apply())}setVoices(e){this.requested=e,this.apply()}dispose(){for(const e of[...this.voices.keys()])this.release(e);this.context?.close(),this.context=void 0,this.master=void 0}masterOf(e){return this.master||(this.master=e.createGain(),this.master.gain.value=this.level,this.master.connect(e.destination)),this.master}apply(){const e=this.context;if(!e)return;const t=this.paused?[]:this.requested.filter(n=>n.inside||n.distanceM<sE),i=new Set(t.map(n=>n.id));for(const n of[...this.voices.keys()])i.has(n)||this.release(n);for(const n of t){const s=this.voices.get(n.id)??this.build(e,n.id);this.retarget(e,s,n)}}build(e,t){const i=e.createGain();i.gain.value=0;const n=e.createBiquadFilter();n.type="lowpass",n.connect(i).connect(this.masterOf(e));const s=e.createOscillator();s.type="sawtooth";const r=e.createOscillator();r.type="sine";const a=e.createGain(),l=e.createBiquadFilter();l.type="lowpass",l.frequency.value=900,s.connect(l),r.connect(l),l.connect(a).connect(n);const c=()=>{const w=e.createBufferSource();return w.buffer=this.noise(e),w.loop=!0,w.loopStart=Math.random()*Jv*.5,w},h=c(),d=e.createBiquadFilter();d.type="bandpass",d.Q.value=4;const u=e.createGain();h.connect(d).connect(u).connect(n);const f=c(),p=e.createBiquadFilter();p.type="lowpass",p.frequency.value=600;const g=e.createGain();f.connect(p).connect(g).connect(n);const m=c(),v=e.createBiquadFilter();v.type="bandpass",v.frequency.value=1400,v.Q.value=.7;const b=e.createGain();m.connect(v).connect(b).connect(n);const x=[s,r,h,f,m];for(const w of x)w.start();const y={nodes:[i,n,a,l,d,u,p,g,v,b,...x],sources:x,firing:s,crank:r,knock:d,engineGain:a,knockGain:u,roadGain:g,windGain:b,cabin:n,output:i};return this.voices.set(t,y),y}retarget(e,t,{profile:i,state:n,noise:s,inside:r,windowsOpen:a,distanceM:l}){const c=e.currentTime,h=(b,x)=>b.setTargetAtTime(x,c,nE),d=n.rpm/60,u=d*i.cylinders/2,f=Math.min(1,n.rpm/i.shiftUpRpm),p=Math.min(1.5,n.speedMps/30);h(t.firing.frequency,u),h(t.crank.frequency,d),h(t.knock.frequency,u*3),h(t.engineGain.gain,i.engineGain*(.25+.75*n.load)*(.5+.5*f)*.3),h(t.knockGain.gain,i.roughness*(.2+.8*n.load)*.4),h(t.roadGain.gain,i.roadGain*p**1.5*.8);const g=!r||a;h(t.windGain.gain,p**2*(g?.5:.06));const m=r?a?3500:700:8e3/(1+l/60);h(t.cabin.frequency,m);const v=r?.5:Math.min(1,8/Math.max(l,1));h(t.output.gain,v*s)}release(e){const t=this.voices.get(e);if(!t)return;this.voices.delete(e);const i=this.context;i&&(t.output.gain.setTargetAtTime(0,i.currentTime,jv/3),setTimeout(()=>{for(const n of t.sources)try{n.stop()}catch{}for(const n of t.nodes)n.disconnect()},jv*1e3*3))}noise(e){if(this.noiseBuffer)return this.noiseBuffer;const t=e.createBuffer(1,e.sampleRate*Jv,e.sampleRate),i=t.getChannelData(0);for(let n=0;n<i.length;n++)i[n]=Math.random()*2-1;return this.noiseBuffer=t,t}}class vh{static BY_KIND={car:{cylinders:4,idleRpm:800,kmhPer1000Rpm:[8,14,21,29,37,45],shiftUpRpm:3e3,shiftDownRpm:1300,engineGain:.6,roadGain:.5,roughness:.15},generic:{cylinders:4,idleRpm:800,kmhPer1000Rpm:[8,14,21,29,37,45],shiftUpRpm:3e3,shiftDownRpm:1300,engineGain:.6,roadGain:.5,roughness:.15},van:{cylinders:4,idleRpm:750,kmhPer1000Rpm:[7,12,19,27,35,42],shiftUpRpm:2600,shiftDownRpm:1200,engineGain:.8,roadGain:.7,roughness:.45},truck:{cylinders:6,idleRpm:600,kmhPer1000Rpm:[5,8,12,17,23,30,38,48],shiftUpRpm:1900,shiftDownRpm:1e3,engineGain:1,roadGain:.9,roughness:.55},motorcycle:{cylinders:2,idleRpm:1100,kmhPer1000Rpm:[12,18,24,30,35,40],shiftUpRpm:6e3,shiftDownRpm:2500,engineGain:.9,roadGain:.3,roughness:.3}};static of(e){return vh.BY_KIND[e??"generic"]??vh.BY_KIND.generic}}class yo{constructor(e,t){this.samples=e,this.startMs=t}static SAMPLE_MS=100;static STANDING_MPS=.3;static of(e,t,i,n){const s=yo.SAMPLE_MS,r=[];for(let c=i;c<=n+s/2;c+=s){const h=t(c-s/2),d=t(c+s/2);if(!h||!d)return;r.push(Math.hypot(d.eastM-h.eastM,d.northM-h.northM)/(s/1e3))}const a=[];let l=1;for(let c=0;c<r.length;c++){const h=r[c],d=(r[Math.min(c+1,r.length-1)]-r[Math.max(c-1,0)])/(2*s/1e3);if(h<yo.STANDING_MPS){l=1,a.push({speedMps:h,rpm:e.idleRpm,load:.1,gear:0});continue}const u=h*3.6,f=v=>u/e.kmhPer1000Rpm[v-1]*1e3;for(;l<e.kmhPer1000Rpm.length&&f(l)>e.shiftUpRpm;)l++;for(;l>1&&f(l)<e.shiftDownRpm;)l--;const p=Math.max(f(l),e.idleRpm*(1+.3*Math.min(1,h/3))),g=.15+.5*Math.min(1,(h/35)**2),m=d>.15?Math.min(1,g+d/2.5):d<-.3?.05:g;a.push({speedMps:h,rpm:p,load:m,gear:l})}return new yo(a,i)}at(e){const t=(e-this.startMs)/yo.SAMPLE_MS,i=Math.min(Math.max(Math.floor(t),0),this.samples.length-1),n=this.samples[i],s=this.samples[Math.min(i+1,this.samples.length-1)],r=Math.min(Math.max(t-i,0),1);return{speedMps:n.speedMps+(s.speedMps-n.speedMps)*r,rpm:n.rpm+(s.rpm-n.rpm)*r,load:n.load+(s.load-n.load)*r,gear:r<.5?n.gear:s.gear}}}class Nu{drives=new Map;at(e,t){const i=[],n=e.event.place?.[0],s=c=>{const h=e.observerTrack.getInterpolatedPoseAt(c),d=h?.lat??n?.lat,u=h?.lng??n?.lng;if(d===void 0||u===void 0||!n)return;const f=vt(d,u,n.lat,n.lng);return{eastM:f.x,northM:-f.z}},r=Math.max(e.observerTrack.duration,(e.event.durationSeconds??0)*1e3),a=e.vehicle;if(a){const c=vh.of(a.kind),h=this.drive(`observer:${a.kind}`,Nu.trackKey(e),()=>yo.of(c,s,0,r));h&&i.push({id:"observer",profile:c,state:h.at(t),noise:a.noise??1,inside:!0,windowsOpen:a.windowsOpen===!0,distanceM:0})}const l=s(t);for(const c of e.decor){if(!c.engine||!l)continue;const h=vh.of(c.engine.kind),d=g=>{const m=Gs(c,g);return{eastM:m.eastM,northM:m.northM}},u=this.drive(`decor:${c.id}`,Nu.decorKey(c,r),()=>yo.of(h,d,0,r));if(!u)continue;const f=Gs(c,t),p=Math.hypot(f.eastM-l.eastM,f.northM-l.northM,f.altitudeM);i.push({id:`decor:${c.id}`,profile:h,state:u.at(t),noise:c.engine.noise??1,inside:!1,windowsOpen:!0,distanceM:p})}return i}drive(e,t,i){const n=this.drives.get(e);if(n&&n.key===t)return n.drive;const s=i();return this.drives.set(e,{key:t,drive:s}),s}static trackKey(e){return e.observerTrack.allKeyframes.map(i=>`${i.t}:${i.pose.lat}:${i.pose.lng}`).join(";")}static decorKey(e,t){return`${t}|${e.eastM},${e.northM}|`+(e.track??[]).map(i=>`${i.t}:${i.eastM}:${i.northM}`).join(";")}}const aE="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAMAAADVRocKAAAARVBMVEX9sST/uyTfoCjNlSikfCqRcCx8Yy21hipTSi4TITEMHTEuMzBqWC3/wSRUX207SFj8/PyaoakmNUd5gYxBPy90fIfMz9RsB4kZAAACEUlEQVRo3u2XyXbDIAxFLeapjts6/f9PrQA3JymT25Cd3iY5xtYVIB6wLCQSiUQikUgk0nzBoVdFZ1xIpaTQbJnPACaNdYeskWwuAhaZoltnUemfnNkL4N49KEI8n0YAEXMvEWISAWQZPw2Xk1MIoF1dSNAzCMy6JsGyCR0wrkMwT3cBeDt+FH8aEHoA68LbM8HRHXQ3f0RE3/jXOOFX+s4djrKpIbzS7K+MmLrxlWCNR8mczjMw92Ar4dZLDXG4kzXinAECcOUPL3jMdN2294/GQGVG4EMHxORNJXoCfG6oT1trvDGM7iIA9N6aTOuuEbB9ra6FyCYr2gjge+fjA4CIi2uujYRoOBSw0A5/D0hT0X4PW0xtuotNpQPYtkt/fdtyM0LP6ZvOI2DtvoxtJWHvx38AxIkevLwXQ2TOA66DziYfLwC4r5wbIlwJo1ys8+VOBMy7/sxdjwIap49lVC3UePZp1mmyit4SuGUf11pjoTHVRVzXUaXFVt87kuEBsWZ055Q+2sXA76LbZYsvKR1ubvJqbKd5swl+GPI31p6L/sNYuDTe3jo+GBdr1J+P9PGawbRUw9VhleD/3ffT9uZ7DhtX1JNHL2CmNRXxYZhwSwBd3aJTyU85/GKOwhxBf5RnVk+75OSiuu+Ax4PQ3Jsg1hTeMUMwJgQp+PKCe2a+JuefFwQnkUgkEolEIpFerW8TL0hlNl2QVAAAAABJRU5ErkJggg==",oE=`
2836
+ `);let t=Al.shared.get(e);return t||(t=this.fetchFirstAvailable(),Al.shared.set(e,t),t.then(i=>{i.length===0&&Al.shared.delete(e)})),this.index=t}async fetchFirstAvailable(){for(const e of this.indexUrls)try{const t=await this.fetchImpl(e);if(!t.ok)continue;const i=await t.json();if(Array.isArray(i?.entries))return i.entries.map(n=>({entry:n,indexUrl:e}))}catch{}return[]}static defaultIndexUrls(){const e=`?v=${encodeURIComponent("0.115.4")}`,t=typeof location>"u"?void 0:new URL("/roads/index.json",location.href).href;return(t&&t!==Gf?[t,Gf]:[Gf]).map(i=>i+e)}}class ya{attribution="Roads © IGN, BD TOPO (Licence Ouverte 2.0), as drawn today";contemporary=!0;static BY_NATURE={"Type autoroutier":{surface:"paved",widthM:11},"Route à 2 chaussées":{surface:"paved",widthM:7},"Route à 1 chaussée":{surface:"paved",widthM:5.5},"Rond-point":{surface:"paved",widthM:6},Bretelle:{surface:"paved",widthM:5},"Route empierrée":{surface:"gravel",widthM:3.5},Chemin:{surface:"dirt",widthM:3},"Piste cyclable":{surface:"paved",widthM:2.5}};static DEFAULT={surface:"paved",widthM:5};static KINDS={"Type autoroutier":"motorway","Route à 2 chaussées":"dual","Route à 1 chaussée":"road","Rond-point":"roundabout",Bretelle:"slip"};static DIRECTIONS={"Double sens":"both","Sens direct":"forward","Sens inverse":"backward"};platform;constructor(e={}){this.platform=new li(e)}static covers(e){return li.covers((e.south+e.north)/2,(e.west+e.east)/2)}async getRoads(e){return(await this.platform.roads(e)).flatMap((i,n)=>ya.wayOf(i,n))}static wayOf(e,t){if(e.geometry.type!=="LineString")return[];const i=e.geometry.coordinates.map(([u,f])=>({lat:f,lng:u}));if(i.length<2)return[];const n=String(e.properties.nature??""),s=ya.BY_NATURE[n]??ya.DEFAULT,r=Number(e.properties.largeur_de_chaussee),a=Number(e.properties.nombre_de_voies),l=Number(e.properties.vitesse_moyenne_vl),c=ya.DIRECTIONS[String(e.properties.sens_de_circulation??"")],h=ya.KINDS[n],d=[e.properties.cpx_toponyme_route_nommee,e.properties.nom_voie_ban_gauche,e.properties.nom_voie_ban_droite].find(u=>typeof u=="string"&&u.length>0);return[{id:String(e.properties.cleabs??`ign-${t}`),...d?{name:d}:{},surface:s.surface,widthM:Number.isFinite(r)&&r>0?r:s.widthM,...e.properties.urbain===!0?{urban:!0}:{},...h?{kind:h}:{},...Number.isInteger(a)&&a>0?{lanes:a}:{},...c?{direction:c}:{},...Number.isFinite(l)&&l>0?{speedKmh:l}:{},points:i}]}}class JS{constructor(e,t){this.regional=e,this.worldwide=t}attribution="Roads © IGN, BD TOPO, in France; © OpenStreetMap contributors elsewhere, as drawn today";contemporary=!0;async getRoads(e){if(ya.covers(e))try{const t=await this.regional.getRoads(e);if(t.length>0)return t}catch{}return this.worldwide.getRoads(e)}}function QS(){return{elevation:VM(),imagery:WM(),roads:eE()}}function VM(){return new KS(new Jt,new zM)}function WM(){return new GM}function eE(){return new Al({fallback:new JS(new ya,new pa)})}const tE=new Set,Bl="show-observer-map",zl="hide-milestones";class Et extends HTMLElement{static get observedAttributes(){return["src",Bl,zl]}shadow;stageElement;canvas;canvasRenderer;chromeCanvas;chromeRenderer;chromeResizeObserver=typeof ResizeObserver>"u"?void 0:new ResizeObserver(()=>{this.chromeDirty&&this.refresh()});chromeDirty=!1;tooltip;toolbar;issuesBox;issuesButton;issuesPanel;playPauseButton;static OBSERVER_MAP_MIN_SPAN_M=400;static OBSERVER_MAP_MARGIN=.6;static OBSERVER_MAP_IMAGERY_PX=768;fullscreenButton;cornerButtons;observerMapButton;referencesButton;tracesButton;tracesShownState=!0;referenceOpacityInput;referencesShownState=!0;accountHidden=!1;referenceViews=new Map;referencesMenu;referenceOpacityTouched=!1;milestonesButton;observerMapPanel;observerMapCanvas;observerMapRenderer;mapZoomInButton;mapZoomOutButton;mapFitButton;observerMapView=new yi;observerMapDrag;suppressObserverMapClick=!1;observerMapImageryTimer;observerPlacing=!1;seekInput;playbackFlash;milestoneMarks;milestoneCaption;timeStartLabel;timeEndLabel;timePill;muteButton;volumeInput;controlsRow;momentsBox;momentsButton;momentsCurrent;momentsMenu;moreButton;controlsRight;seekSegments;seekDot;playerTitleBox;seekPreview;seekPreviewCanvas;seekPreviewTitle;seekPreviewTime;observerPath;observerMapBounds;observerMapImagery;observerMapImageryBounds;observerMapImageryViewWidth=0;observerMapImageryLoading=!1;observerMapImageryCredit;observerMapImageryFailed=!1;creditShownExternally=!1;lookYawDeg=0;lookPitchDeg=0;milestonesShown=!0;currentSighting=yf.create();issues=[];issueCheck=0;sightingAudio=new LS;soundPreview;player;loopEnabled=!1;playbackBeforeClick;highlightedSourceIds=new Set;paintsShapes=!0;steadyObserver=!1;static LIVE_BODY_MAX_RATE=2;get steadyBody(){return this.steadyObserver||this.player.playbackState!=="playing"||this.player.playbackRate>Et.LIVE_BODY_MAX_RATE}selectionShown=!0;overlayPainter;enableClickToPlay=!0;fullscreenTarget;messages=CM;realDurationMs;realStartMs;showClockTime=!0;handleFullscreenChange=()=>{this.updateFullscreenButton(),this.updateMuteButton(),this.resizeObserverMap()};controlsFitObserver=typeof ResizeObserver>"u"?void 0:new ResizeObserver(()=>this.fitControls());controlsMutations;fitControls(){const e=this.controlsRow,t=e.classList.contains("more-open"),i=()=>e.scrollWidth>e.clientWidth+1,n=!this.momentsMenu.hidden;if(this.momentsMenu.hidden=!0,e.classList.remove("narrow","more-open","nomoments","compact","tiny"),e.clientWidth>0&&i()){e.classList.add("narrow");for(const s of["nomoments","compact","tiny"]){if(!i())break;e.classList.add(s)}t&&e.classList.add("more-open")}this.momentsMenu.hidden=!n,this.updateMoreButton()}setControlsFolded(e){this.controlsRow.classList.toggle("more-open",!e),this.updateMoreButton()}updateMoreButton(){const e=this.controlsRow.classList.contains("more-open");Et.setIcon(this.moreButton,e?qe.UNFOLDED:qe.FOLDED);const t=e?this.messages.fewerControls:this.messages.moreControls;this.moreButton.title=t,this.moreButton.setAttribute("aria-label",t),this.moreButton.setAttribute("aria-expanded",String(e))}addControl(e){this.controlsRight.insertBefore(e,this.fullscreenButton.parentElement===this.controlsRight?this.fullscreenButton:null),this.fitControls()}observerMapResizeObserver=typeof ResizeObserver>"u"?void 0:new ResizeObserver(()=>this.resizeObserverMap());resizeObserverMap(){this.observerMapPanel.hidden||(this.sizeObserverMapCanvas(),this.paintObserverMap(this.currentTime))}simulatedFullscreen=!1;styleBeforeSimulatedFullscreen;bodyOverflowBeforeSimulatedFullscreen;handleSimulatedFullscreenKey=e=>{e.key==="Escape"&&this.exitSimulatedFullscreen()};handlePointerMove=e=>{const t=this.canvasPointFromEvent(e),i=t&&this.shapeAt(t.x,t.y),n=this.said.read(i?.shape.title);if(!n){this.tooltip.hidden=!0;return}this.tooltip.textContent=n,this.tooltip.hidden=!1;const s=this.stageElement.getBoundingClientRect();this.tooltip.style.left=`${e.clientX-s.left+12}px`,this.tooltip.style.top=`${e.clientY-s.top+12}px`};handleObserverMapPointerMove=e=>{if(this.dragObserverMap(e))return;const t=this.observerMapTargetFrom(e);if(!t){if(!this.observerPlacing){this.tooltip.hidden=!0,this.observerMapCanvas.style.cursor="grab";return}this.observerMapCanvas.style.cursor="crosshair",this.showObserverMapTooltip(e,this.messages.placeObserverHere);return}this.observerMapCanvas.style.cursor="pointer",this.showObserverMapTooltip(e,t.label)};showObserverMapTooltip(e,t){this.tooltip.textContent=t,this.tooltip.hidden=!1;const i=this.stageElement.getBoundingClientRect();this.tooltip.style.left=`${e.clientX-i.left+12}px`,this.tooltip.style.top=`${e.clientY-i.top+12}px`}handleObserverMapClick=e=>{if(this.suppressObserverMapClick){this.suppressObserverMapClick=!1;return}const t=this.observerMapTargetFrom(e);if(!t){this.observerPlacing&&this.placeObserverFrom(e);return}if(t.kind==="milestone"&&t.t!==void 0){this.player.seek(t.t);return}this.dispatchEvent(new CustomEvent("lookat",{detail:{lat:t.lat,lng:t.lng,kind:t.kind},bubbles:!0,composed:!0}))};observerMapTargetFrom(e){const t=this.observerMapCanvas.getBoundingClientRect();if(!(t.width===0||t.height===0))return this.observerMapRenderer.hitTest((e.clientX-t.left)/t.width*this.observerMapCanvas.width,(e.clientY-t.top)/t.height*this.observerMapCanvas.height)}handlePointerLeave=()=>{this.tooltip.hidden=!0};handleObserverMapPointerDown=e=>{e.button===0&&(this.suppressObserverMapClick=!1,this.observerMapDrag={pointerId:e.pointerId,startX:e.clientX,startY:e.clientY,lastX:e.clientX,lastY:e.clientY,moved:!1})};handleObserverMapPointerUp=e=>{const t=this.observerMapDrag;!t||t.pointerId!==e.pointerId||(this.observerMapDrag=void 0,this.observerMapCanvas.classList.remove("dragging"),t.moved&&(this.suppressObserverMapClick=!0,this.paintObserverMap(this.currentTime),this.observerMapCanvas.hasPointerCapture?.(e.pointerId)&&this.observerMapCanvas.releasePointerCapture(e.pointerId)))};dragObserverMap(e){const t=this.observerMapDrag;if(!t||t.pointerId!==e.pointerId)return!1;if(!t.moved){if(Math.hypot(e.clientX-t.startX,e.clientY-t.startY)<Et.OBSERVER_MAP_DRAG_PX)return!1;t.moved=!0,this.tooltip.hidden=!0,this.observerMapCanvas.classList.add("dragging"),this.observerMapCanvas.setPointerCapture?.(e.pointerId)}const i=this.observerMapCanvas.getBoundingClientRect();return i.width>0&&i.height>0&&(this.observerMapView.panBy((e.clientX-t.lastX)/i.width,(e.clientY-t.lastY)/i.height),this.observerMapViewChanged()),t.lastX=e.clientX,t.lastY=e.clientY,!0}static OBSERVER_MAP_DRAG_PX=4;handleObserverMapWheel=e=>{e.preventDefault();const t=this.observerMapCanvas.getBoundingClientRect();if(t.width===0||t.height===0)return;const i=e.deltaMode===0?e.deltaY:e.deltaY*40;this.zoomObserverMap((e.clientX-t.left)/t.width,(e.clientY-t.top)/t.height,Math.exp(-i*.002))};zoomObserverMap(e,t,i){this.observerMapView.zoomAt(e,t,i),this.observerMapViewChanged()}observerMapViewChanged(){this.mapFitButton.hidden=!this.observerMapView.changed,this.mapZoomInButton.disabled=this.observerMapView.zoomFactor>=yi.MAX_ZOOM,this.mapZoomOutButton.disabled=this.observerMapView.zoomFactor<=yi.MIN_ZOOM,this.paintObserverMap(this.currentTime),this.scheduleObserverMapImagery()}scheduleObserverMapImagery(){this.observerMapImageryTimer===void 0&&(this.observerMapImageryTimer=setTimeout(()=>{this.observerMapImageryTimer=void 0,this.loadObserverMapImagery()},Et.OBSERVER_MAP_IMAGERY_DELAY_MS))}static OBSERVER_MAP_FOLLOW_MARGIN=.1;static OBSERVER_MAP_IMAGERY_DELAY_MS=300;get observerMapViewBounds(){return this.observerMapBounds&&this.observerMapView.boundsWithin(this.observerMapBounds)}placeObserverFrom(e){const t=this.observerMapViewBounds,i=this.observerMapCanvas.getBoundingClientRect();if(!t||i.width===0||i.height===0)return;const n=yi.pointAt(t,(e.clientX-i.left)/i.width,(e.clientY-i.top)/i.height);this.dispatchEvent(new CustomEvent("observerplace",{detail:n,bubbles:!0,composed:!0}))}constructor(){super(),this.shadow=this.attachShadow({mode:"open"});const e=document.createElement("template");e.innerHTML=`<style>${RS}</style>${DS}`,this.shadow.appendChild(e.content.cloneNode(!0)),this.stageElement=this.shadow.getElementById("stage"),this.canvas=this.shadow.getElementById("canvas"),this.canvasRenderer=new ic(this.canvas.getContext("2d")),this.chromeCanvas=this.shadow.getElementById("chrome"),this.tooltip=this.shadow.getElementById("tooltip"),this.toolbar=this.shadow.getElementById("toolbar"),this.issuesBox=this.shadow.getElementById("issues"),this.issuesButton=this.shadow.getElementById("issues-button"),this.issuesPanel=this.shadow.getElementById("issues-panel"),this.issuesButton.addEventListener("click",t=>{t.stopPropagation(),this.issuesPanel.hidden=!this.issuesPanel.hidden,this.issuesButton.setAttribute("aria-expanded",String(!this.issuesPanel.hidden))}),this.playPauseButton=this.shadow.getElementById("play-pause"),this.fullscreenButton=this.shadow.getElementById("fullscreen"),this.cornerButtons=this.shadow.getElementById("corner-buttons"),this.observerMapButton=this.shadow.getElementById("observer-map"),this.referencesButton=this.shadow.getElementById("references"),this.tracesButton=this.shadow.getElementById("traces"),this.referenceOpacityInput=this.shadow.getElementById("reference-opacity"),this.referencesMenu=this.shadow.getElementById("references-menu"),this.milestonesButton=this.shadow.getElementById("milestones"),this.observerMapPanel=this.shadow.getElementById("observer-map-panel"),this.observerMapCanvas=this.shadow.getElementById("observer-map-canvas"),this.observerMapRenderer=new Qa(this.observerMapCanvas.getContext("2d")),this.mapZoomInButton=this.shadow.getElementById("map-zoom-in"),this.mapZoomOutButton=this.shadow.getElementById("map-zoom-out"),this.mapFitButton=this.shadow.getElementById("map-fit"),this.seekInput=this.shadow.getElementById("seek"),this.playbackFlash=this.shadow.getElementById("playback-flash"),this.milestoneMarks=this.shadow.getElementById("milestone-marks"),this.milestoneCaption=this.shadow.getElementById("milestone-caption"),this.timeStartLabel=this.shadow.getElementById("time-start"),this.timeEndLabel=this.shadow.getElementById("time-end"),this.timePill=this.shadow.getElementById("time"),this.muteButton=this.shadow.getElementById("mute"),this.controlsRight=this.shadow.getElementById("controls-right"),this.seekSegments=this.shadow.getElementById("seek-segments"),this.seekDot=this.shadow.getElementById("seek-dot"),this.playerTitleBox=this.shadow.getElementById("player-title"),this.seekPreview=this.shadow.getElementById("seek-preview"),this.seekPreviewCanvas=this.shadow.getElementById("seek-preview-canvas"),this.seekPreviewTitle=this.shadow.getElementById("seek-preview-title"),this.seekPreviewTime=this.shadow.getElementById("seek-preview-time"),this.timePill.addEventListener("click",()=>this.toggleTimeDisplay()),this.timePill.addEventListener("keydown",t=>{t.key!=="Enter"&&t.key!==" "||(t.preventDefault(),this.toggleTimeDisplay())}),this.volumeInput=this.shadow.getElementById("volume"),this.controlsRow=this.shadow.querySelector(".controls"),this.momentsBox=this.shadow.getElementById("moments"),this.momentsButton=this.shadow.getElementById("moments-button"),this.momentsCurrent=this.shadow.getElementById("moments-current"),this.momentsMenu=this.shadow.getElementById("moments-menu"),this.momentsButton.addEventListener("click",()=>this.toggleMomentsMenu()),this.moreButton=this.shadow.getElementById("controls-more"),this.moreButton.addEventListener("click",()=>this.setControlsFolded(this.controlsRow.classList.contains("more-open"))),this.muteButton.addEventListener("click",()=>this.toggleMuted()),this.volumeInput.addEventListener("input",()=>{this.setVolume(Number(this.volumeInput.value))}),this.fullscreenTarget=this.stageElement,this.playPauseButton.addEventListener("click",()=>this.togglePlayPause()),this.fullscreenButton.addEventListener("click",()=>this.toggleFullscreen()),this.addEventListener("keydown",this.handleFullscreenKey),this.observerMapButton.addEventListener("click",()=>this.toggleObserverMap()),this.referencesButton.addEventListener("click",()=>this.toggleReferences()),this.tracesButton.addEventListener("click",()=>this.toggleTraces()),this.referenceOpacityInput.addEventListener("input",()=>{this.referenceOpacityTouched=!0,this.dispatchReferenceView()}),this.milestonesButton.addEventListener("click",()=>this.toggleMilestones()),this.observerMapCanvas.addEventListener("pointermove",this.handleObserverMapPointerMove),this.observerMapCanvas.addEventListener("pointerleave",this.handlePointerLeave),this.observerMapCanvas.addEventListener("click",this.handleObserverMapClick),this.observerMapCanvas.addEventListener("pointerdown",this.handleObserverMapPointerDown),this.observerMapCanvas.addEventListener("pointerup",this.handleObserverMapPointerUp),this.observerMapCanvas.addEventListener("pointercancel",this.handleObserverMapPointerUp),this.observerMapCanvas.addEventListener("wheel",this.handleObserverMapWheel,{passive:!1}),this.mapZoomInButton.addEventListener("click",()=>this.zoomObserverMap(.5,.5,2)),this.mapZoomOutButton.addEventListener("click",()=>this.zoomObserverMap(.5,.5,.5)),this.mapFitButton.addEventListener("click",()=>{this.observerMapView.reset(),this.observerMapViewChanged()}),this.seekInput.addEventListener("input",()=>this.player.seek(this.snapSeekToMark(Number(this.seekInput.value)))),this.seekInput.addEventListener("pointerdown",t=>{this.suspendForScrub(),this.seekSnapArmed=!0,this.nameMarkUnder(t),this.beginTouchScrub(t)}),this.seekInput.addEventListener("pointerup",t=>{this.seekSnapArmed=!1,this.endTouchScrub(t)}),this.seekInput.addEventListener("pointercancel",t=>this.endTouchScrub(t)),this.seekInput.addEventListener("pointermove",t=>{this.nameMarkUnder(t),this.hoverSeek(t),this.touchScrub(t)}),this.seekInput.addEventListener("pointerleave",()=>{this.seekInput.removeAttribute("title"),this.leaveSeek()}),this.seekInput.addEventListener("keydown",this.handleSeekKey),this.stageElement.addEventListener("pointerdown",()=>{this.handlePointerDown(),this.touchedStage()},!0);for(const t of["touchend","click"])this.stageElement.addEventListener(t,()=>this.sightingAudio.resume(),!0);this.stageElement.addEventListener("pointermove",()=>this.touchedStage()),this.canvas.addEventListener("click",t=>{if(this.enableClickToPlay){if(this.tapRevealedOnly){this.tapRevealedOnly=!1;return}t.detail<=1&&(this.playbackBeforeClick={state:this.playbackState,time:this.currentTime}),this.togglePlayPause()}}),this.canvas.addEventListener("dblclick",t=>{this.enableClickToPlay&&(t.preventDefault(),this.restorePlayback(),this.toggleFullscreen())}),this.canvas.addEventListener("pointermove",this.handlePointerMove),this.canvas.addEventListener("pointerleave",this.handlePointerLeave),document.addEventListener("fullscreenchange",this.handleFullscreenChange),document.addEventListener("pointerdown",this.handleMomentsDismiss,!0),document.addEventListener("keydown",this.handleMomentsDismiss,!0),document.addEventListener("visibilitychange",this.handleVisibility),window.addEventListener("pagehide",this.handleHidden),document.addEventListener("pointerup",this.handlePointerRelease,!0),document.addEventListener("pointercancel",this.handlePointerRelease,!0),this.observerMapResizeObserver?.observe(this.observerMapPanel),this.chromeResizeObserver?.observe(this.chromeCanvas),this.controlsFitObserver?.observe(this.controlsRow),this.controlsFitObserver?.observe(this.controlsRow.querySelector(".controls-left")),typeof MutationObserver<"u"&&(this.controlsMutations=new MutationObserver(()=>this.fitControls()),this.controlsMutations.observe(this.controlsRight,{attributes:!0,attributeFilter:["hidden"],childList:!0,subtree:!0})),this.hostControls(void 0),this.player=this.createPlayer(),this.updateTimeLabels(),this.updatePlayPauseButton(),this.updateFullscreenButton(),this.updateMuteButton(),this.updateObserverMapButton(),this.updateReferencesButton(),this.updateTracesButton(),this.updateMilestonesButton(),this.refresh()}connectedCallback(){this.saidTexts=void 0,this.loadLocaleMessages();const e=this.getAttribute("src");e&&this.loadFromSrc(e)}disconnectedCallback(){document.removeEventListener("fullscreenchange",this.handleFullscreenChange),document.removeEventListener("pointerdown",this.handleMomentsDismiss,!0),document.removeEventListener("keydown",this.handleMomentsDismiss,!0),document.removeEventListener("visibilitychange",this.handleVisibility),window.removeEventListener("pagehide",this.handleHidden),document.removeEventListener("pointerup",this.handlePointerRelease,!0),document.removeEventListener("pointercancel",this.handlePointerRelease,!0),window.clearTimeout(this.controlsIdleTimer),this.observerMapResizeObserver?.disconnect(),this.chromeResizeObserver?.disconnect(),this.controlsFitObserver?.disconnect(),this.controlsMutations?.disconnect(),this.exitSimulatedFullscreen(),this.sightingAudio.dispose()}attributeChangedCallback(e,t,i){e==="src"&&i&&i!==t&&this.isConnected&&this.loadFromSrc(i),e===Bl&&this.applyObserverMapDefault(),e===zl&&this.setMilestonesShown(!this.hasAttribute(zl))}async loadFromSrc(e){this.sightingData=await lh.json(e)}get sightingData(){return OS(this.currentSighting)}set sightingData(e){this.player.stop(),this.soundPreview=void 0,this.sightingAudio.silence(),this.currentSighting=NS(e),this.issuesPanel.hidden=!0,this.issuesButton.setAttribute("aria-expanded","false"),this.reportIssues(e,this.currentSighting),this.observerMapView.reset(),this.mapFitButton.hidden=!0,this.observerMapAsked=!1,this.player=this.createPlayer(),this.syncPlayerTitle(),this.updateTimeLabels(),this.updatePlayPauseButton(),this.refresh(),this.applyObserverMapDefault()}set playerTitle(e){this.titleOverride=e,this.syncPlayerTitle()}titleOverride;syncPlayerTitle(){const e=this.said.read(this.titleOverride)??this.currentSighting.observer?.title??"";this.playerTitleBox.textContent=e,this.playerTitleBox.hidden=e===""}get recordingIssues(){return this.issues}async reportIssues(e,t){const i=++this.issueCheck;let n=[];try{const{default:s}=await Ue(async()=>{const{default:r}=await import("./sightingSchema-CNx1-oWD.js");return{default:r}},[],import.meta.url);n=new Cs(s).issues(e)}catch{}i===this.issueCheck&&(this.issues=[...n,...t.loadIssues],nc.warn(this.issues,t.id),this.renderIssues(),this.dispatchEvent(new CustomEvent(iE,{detail:{issues:this.issues},bubbles:!0,composed:!0})))}renderIssues(){const e=this.issues.length;this.issuesBox.hidden=e===0,this.shadow.getElementById("issues-count").textContent=String(e);const t=this.messages.recordingIssues.replace("{count}",String(e));this.issuesButton.title=t,this.issuesButton.setAttribute("aria-label",t),this.shadow.getElementById("issues-title").textContent=t,this.shadow.getElementById("issues-list").replaceChildren(...this.issues.map(i=>{const n=document.createElement("li");return n.textContent=nc.text(i,this.messages.issueTemplates),n}))}get sighting(){return this.currentSighting}previewSound(e){this.soundPreview=e,this.sightingAudio.resume(),this.sightingAudio.setSound(e)}stopSoundPreview(){this.soundPreview=void 0,this.sightingAudio.silence()}get canvasElement(){return this.canvas}get renderer(){return this.canvasRenderer}get currentTime(){return this.player.time}set currentTime(e){this.player.seek(e)}get seekableDuration(){return this.player.seekableDuration}get autoReplayEnabled(){return this.loopEnabled}set autoReplayEnabled(e){e!==this.loopEnabled&&this.toggleLoop()}play(){if(!(this.player.seekableDuration<=0||this.playbackState==="playing")){if(this.clockHeld){this.playAfterHold=!0;return}this.togglePlayPause()}}clockHeld=!1;playAfterHold=!1;holdClock(e){if(e!==this.clockHeld){if(this.clockHeld=e,e){if(this.playbackState!=="playing")return;this.playAfterHold=!0,this.player.pause(),this.soundPreview=void 0,this.sightingAudio.silence(),this.refresh(),this.updatePlayPauseButton();return}this.playAfterHold&&(this.playAfterHold=!1,!(this.player.seekableDuration<=0||this.playbackState==="playing")&&(this.sightingAudio.resume(),this.player.play(),this.updatePlayPauseButton()))}}pause(){this.playAfterHold=!1,this.playbackState==="playing"&&this.togglePlayPause()}get positionLabel(){return this.timeStartLabel.textContent??""}get durationLabel(){return this.timeEndLabel.textContent??""}get showingClockTime(){return this.canShowClockTime}get canSwitchTimeDisplay(){return this.realStartMs!==void 0}toggleTimeDisplay(){this.canSwitchTimeDisplay&&(this.showClockTime=!this.showClockTime,this.updateTimeLabels(),this.updateTimeLabelTitles(),this.dispatchEvent(new CustomEvent("timedisplaychange",{bubbles:!0,composed:!0})))}get canShowClockTime(){return this.realStartMs!==void 0&&this.showClockTime}set showToolbar(e){this.toolbar.classList.toggle("hidden",!e),e?this.controlsRight.appendChild(this.fullscreenButton):this.cornerButtons.appendChild(this.fullscreenButton)}get playbackState(){return this.player.playbackState}get selectedSourceIds(){return this.highlightedSourceIds}get durationSeconds(){return this.currentSighting.event.durationSeconds}set durationSeconds(e){this.currentSighting.event.durationSeconds=e,this.updateTimeLabels(),this.refresh(),this.updatePlayPauseButton()}set selectedSourceIds(e){const t=new Set(e);t.size===this.highlightedSourceIds.size&&[...t].every(n=>this.highlightedSourceIds.has(n))||(this.highlightedSourceIds=t,this.refresh())}hasVisibleShapeAt(e,t){return this.shapeAt(e,t)!==void 0}refresh(){this.applyFrameFormat(),this.updateMuteButton(),this.updateTimeLabels(),this.seekInput.max=String(this.player.seekableDuration),this.refreshMilestoneMarks(),this.updateMilestonesButton(),this.updateObserverMap(),this.updateReferences(),this.updateTracesButton(),this.player.seek(this.player.time)}hostControls(e){const t=[this.milestonesButton,this.referencesButton,this.referenceOpacityInput,this.tracesButton,this.observerMapButton];if(e)for(const i of t)e.appendChild(i);else{const i=this.fullscreenButton.parentElement===this.controlsRight?this.fullscreenButton:null;for(const n of t)this.controlsRight.insertBefore(n,i)}}get referencesShown(){return this.referencesShownState}get referenceOpacity(){return Number(this.referenceOpacityInput.value)}get severalReferences(){return this.currentSighting.references.length>1}toggleReferences(){if(this.severalReferences){this.toggleReferencesMenu();return}this.referencesShownState=!this.referencesShownState,this.updateReferencesButton(),this.dispatchReferenceView()}updateReferences(){const e=this.currentSighting.references;!this.referenceOpacityTouched&&e.length>0&&(this.referenceOpacityInput.value=String(e[0].opacity));for(const t of[...this.referenceViews.keys()])e.some(i=>i.id===t)||this.referenceViews.delete(t);this.severalReferences?this.referencesMenu.hidden||this.renderReferencesMenu():this.closeReferencesMenu(),this.updateReferencesButton(),this.severalReferences&&this.dispatchReferenceView()}viewOfReference(e){let t=this.referenceViews.get(e.id);return t||(t={shown:!0,opacity:e.opacity},this.referenceViews.set(e.id,t)),t}toggleReferencesMenu(){this.referencesMenu.hidden?this.openReferencesMenu():this.closeReferencesMenu()}openReferencesMenu(){this.renderReferencesMenu(),this.referencesMenu.hidden=!1,this.placeReferencesMenu(),this.referencesButton.setAttribute("aria-expanded","true"),document.addEventListener("pointerdown",this.handleReferencesMenuOutside,!0),document.addEventListener("keydown",this.handleReferencesMenuKey,!0)}closeReferencesMenu(){this.referencesMenu.hidden||(this.referencesMenu.hidden=!0,this.referencesButton.setAttribute("aria-expanded","false"),document.removeEventListener("pointerdown",this.handleReferencesMenuOutside,!0),document.removeEventListener("keydown",this.handleReferencesMenuKey,!0))}handleReferencesMenuOutside=e=>{const t=e.composedPath();t.includes(this.referencesMenu)||t.includes(this.referencesButton)||this.closeReferencesMenu()};handleReferencesMenuKey=e=>{e.key==="Escape"&&(this.closeReferencesMenu(),this.referencesButton.focus())};placeReferencesMenu(){const e=this.referencesButton.getBoundingClientRect(),t=this.referencesMenu,i=4;t.style.bottom=`${Math.max(i,window.innerHeight-e.top+i)}px`,t.style.top="auto";const n=t.getBoundingClientRect().width;t.style.left=`${Math.max(i,Math.min(e.left,window.innerWidth-n-i))}px`}renderReferencesMenu(){const e=this.currentSighting.references.map(t=>{const i=this.viewOfReference(t),n=this.said.read(t.title)??t.id,s=document.createElement("div");s.className="reference-row";const r=document.createElement("label"),a=document.createElement("input");a.type="checkbox",a.checked=i.shown;const l=document.createElement("span");l.textContent=n,l.title=n,r.append(a,l);const c=document.createElement("input");return c.type="range",c.min="0",c.max="1",c.step="0.05",c.value=String(i.opacity),c.title=this.messages.referenceOpacity,c.setAttribute("aria-label",`${this.messages.referenceOpacity}: ${n}`),c.disabled=!i.shown,a.addEventListener("change",()=>{i.shown=a.checked,c.disabled=!i.shown,this.updateReferencesButton(),this.dispatchReferenceView()}),c.addEventListener("input",()=>{i.opacity=Number(c.value),this.dispatchReferenceView()}),s.append(r,c),s});this.referencesMenu.setAttribute("aria-label",this.messages.referencesMenu),this.referencesMenu.replaceChildren(...e)}updateReferencesButton(){const e=this.currentSighting.references.length>0,t=this.severalReferences,i=t?this.currentSighting.references.some(s=>this.viewOfReference(s).shown):this.referencesShownState;this.referencesButton.hidden=!e,this.referenceOpacityInput.hidden=!e||!this.referencesShownState||t,this.referencesButton.setAttribute("aria-pressed",String(i)),t?this.referencesButton.setAttribute("aria-haspopup","true"):this.referencesButton.removeAttribute("aria-haspopup"),Et.setIcon(this.referencesButton,i?qe.PICTURES_ON:qe.PICTURES_OFF);const n=t?this.messages.referencesMenu:this.referencesShownState?this.messages.hideReferences:this.messages.showReferences;this.referencesButton.title=n,this.referencesButton.setAttribute("aria-label",n),this.referenceOpacityInput.title=this.messages.referenceOpacity,this.referenceOpacityInput.setAttribute("aria-label",this.messages.referenceOpacity)}get tracesShown(){return this.tracesShownState}toggleTraces(){this.tracesShownState=!this.tracesShownState,this.updateTracesButton(),this.updateObserverMap(),this.dispatchEvent(new CustomEvent("traceview",{detail:{shown:this.tracesShown}}))}updateTracesButton(){this.tracesButton.hidden=this.currentSighting.traces.length===0,this.tracesButton.setAttribute("aria-pressed",String(this.tracesShownState)),Et.setIcon(this.tracesButton,this.tracesShownState?qe.TRACES_ON:qe.TRACES_OFF);const e=this.tracesShownState?this.messages.hideTraces:this.messages.showTraces;this.tracesButton.title=e,this.tracesButton.setAttribute("aria-label",e)}dispatchReferenceView(){const e=this.severalReferences?Object.fromEntries(this.currentSighting.references.map(t=>[t.id,{...this.viewOfReference(t)}])):void 0;this.dispatchEvent(new CustomEvent("referenceview",{detail:{shown:this.referencesShown,opacity:this.referenceOpacity,views:e}}))}refreshMilestoneMarks(){const e=this.player.seekableDuration,t=e>0?Io(this.sighting.milestones):[];this.milestoneMarks.replaceChildren(...t.map(i=>{const n=document.createElement("button");n.type="button",n.className="milestone-mark",n.style.left=`${Math.min(Math.max(i.t/e,0),1)*100}%`;const s=this.said.read(i.label)??"",r=this.said.read(i.note),a=r?`${s} — ${r}`:s;return n.title=a,n.setAttribute("aria-label",a),n.dataset.t=String(i.t),n.addEventListener("click",()=>this.player.seek(i.t)),n})),this.refreshSeekSegments(e,t.map(i=>i.t)),this.refreshMomentsPicker(t)}refreshMomentsPicker(e){const t=this.milestonesShown&&e.length>0;this.momentsBox.hidden=!t,this.closeMomentsMenu(),this.momentsMenu.replaceChildren(...e.map(i=>{const n=document.createElement("li"),s=document.createElement("button");s.type="button",s.dataset.t=String(i.t);const r=this.said.read(i.label)??"",a=this.said.read(i.note);return s.textContent=a?`${r} — ${a}`:r,s.addEventListener("click",()=>{this.player.seek(i.t),this.closeMomentsMenu()}),n.appendChild(s),n})),this.momentsButton.title=this.messages.moments,this.showCurrentMoment(void 0)}showCurrentMoment(e){const i=(e?this.said.read(e.label)??"":"")||this.messages.moments;this.momentsCurrent.textContent!==i&&(this.momentsCurrent.textContent=i);for(const n of this.momentsMenu.querySelectorAll("button")){const s=e!==void 0&&Number(n.dataset.t)===e.t;n.getAttribute("aria-current")==="true"!==s&&n.setAttribute("aria-current",String(s))}}toggleMomentsMenu(){this.momentsMenu.hidden?(this.momentsMenu.hidden=!1,this.momentsButton.setAttribute("aria-expanded","true")):this.closeMomentsMenu()}closeMomentsMenu(){this.momentsMenu.hidden=!0,this.momentsButton.setAttribute("aria-expanded","false")}handleMomentsDismiss=e=>{if(!this.momentsMenu.hidden){if(e instanceof KeyboardEvent){e.key==="Escape"&&this.closeMomentsMenu();return}e.composedPath().some(t=>t===this.momentsMenu||t===this.momentsButton)||this.closeMomentsMenu()}};seekSegmentList=[];refreshSeekSegments(e,t){const n=[0,...this.milestonesShown&&e>0?[...new Set(t.filter(r=>r>0&&r<e))].sort((r,a)=>r-a):[],Math.max(e,0)];this.seekSegmentList=[];const s=[];for(let r=0;r<n.length-1;r++){const a=document.createElement("div");a.className="seek-segment",a.style.flexGrow=String(Math.max(n[r+1]-n[r],1));const l=document.createElement("i");l.className="seek-hover";const c=document.createElement("i");c.className="seek-played",a.append(l,c),s.push(a),this.seekSegmentList.push({start:n[r],end:n[r+1],element:a,played:c,hover:l})}this.seekSegments.replaceChildren(...s),this.paintSeekProgress(this.player.time)}static fillOf(e,t){const i=e.end-e.start,n=i>0?(t-e.start)/i:t>=e.end?1:0;return`${Math.min(Math.max(n,0),1)*100}%`}paintSeekProgress(e){for(const i of this.seekSegmentList)i.played.style.width=Et.fillOf(i,e);const t=this.player.seekableDuration;this.seekDot.style.left=`${t>0?Math.min(Math.max(e/t,0),1)*100:0}%`}hoverSeek(e){const t=this.seekInput.getBoundingClientRect(),i=this.player.seekableDuration;if(t.width<=0||i<=0)return;const n=Math.min(Math.max((e.clientX-t.left)/t.width,0),1),s=n*i,r=this.seekSegmentList.length-1;this.seekSegmentList.forEach((f,p)=>{f.hover.style.width=Et.fillOf(f,s),f.element.classList.toggle("hovered",s>=f.start&&(s<f.end||p===r))});const a=this.milestonesShown?this.sighting.milestones:[],l=a.length>0?zf(a,s):void 0,c=l?this.said.read(l.label)??"":"",h=l?this.said.read(l.note):void 0,d=h?`${c} — ${h}`:c;this.seekPreviewTitle.textContent=d,this.seekPreviewTime.textContent=this.formatPosition(s),this.seekPreview.hidden=!1;const u=this.seekPreview.offsetWidth;this.seekPreview.style.left=`${Math.min(Math.max(n*t.width-u/2,0),Math.max(t.width-u,0))}px`,this.paintSeekPreview(s)}leaveSeek(){for(const e of this.seekSegmentList)e.hover.style.width="0",e.element.classList.remove("hovered");this.seekPreview.hidden=!0}seekPreviewPainter;paintSeekPreview(e){const t=this.seekPreviewPainter;this.seekPreviewCanvas.hidden=t===void 0,t?.(e,this.seekPreviewCanvas)}paintChrome(e){const t=this.chromeCanvas.getContext("2d"),i=this.overlayPainter!==void 0||this.selectionShown;if(!i&&!this.chromeDirty)return;const n=this.chromeCanvas.clientWidth,s=this.chromeCanvas.clientHeight;if(!t||typeof t.setTransform!="function"||n===0||s===0){e(this.canvasRenderer);return}const r=window.devicePixelRatio||1,a=Math.max(1,Math.round(n*r)),l=Math.max(1,Math.round(s*r));this.chromeCanvas.width!==a&&(this.chromeCanvas.width=a),this.chromeCanvas.height!==l&&(this.chromeCanvas.height=l),t.setTransform(1,0,0,1,0,0),t.clearRect(0,0,a,l),this.chromeDirty=!1,i&&(t.setTransform(a/this.canvas.width,0,0,l/this.canvas.height,0,0),this.chromeRenderer??=new ic(t),this.chromeDirty=!0,e(this.chromeRenderer))}chromeDraw;repaintChrome(){this.chromeDraw&&this.overlayPainter&&this.paintChrome(this.chromeDraw)}scrubbingPointer;beginTouchScrub(e){if(e.pointerType!=="mouse"){this.scrubbingPointer=e.pointerId;try{this.seekInput.setPointerCapture(e.pointerId)}catch{}this.seekToPointer(e)}}touchScrub(e){e.pointerId===this.scrubbingPointer&&this.seekToPointer(e)}endTouchScrub(e){e.pointerId===this.scrubbingPointer&&(this.scrubbingPointer=void 0,this.seekToPointer(e))}seekToPointer(e){const t=this.seekInput.getBoundingClientRect(),i=this.player.seekableDuration;if(t.width<=0||i<=0)return;const n=Math.min(Math.max((e.clientX-t.left)/t.width,0),1);this.player.seek(this.snapSeekToMark(n*i))}seekSnapArmed=!1;static MARK_SNAP_PX=6;markNear(e){const t=this.player.seekableDuration,i=this.seekInput.getBoundingClientRect().width;if(t<=0||i<=0)return;const n=Et.MARK_SNAP_PX/i*t;let s;for(const r of this.milestoneMarks.children){const a=Number(r.dataset.t);Math.abs(a-e)>n||(!s||Math.abs(a-e)<Math.abs(s.t-e))&&(s={t:a,name:r.title})}return s}snapSeekToMark(e){return this.seekSnapArmed?(this.seekSnapArmed=!1,this.markNear(e)?.t??e):e}nameMarkUnder(e){const t=this.seekInput.getBoundingClientRect(),i=this.player.seekableDuration;if(t.width<=0||i<=0)return;const n=(e.clientX-t.left)/t.width*i,s=this.markNear(n);s?this.seekInput.title=s.name:this.seekInput.removeAttribute("title")}showMilestoneAt(e){const t=this.milestonesShown&&this.sighting.milestones.length>0?zf(this.sighting.milestones,e):void 0;if(this.milestoneCaption.hidden=t===void 0,this.showCurrentMoment(t),!t)return;const i=document.createElement("b");i.textContent=this.said.read(t.label)??"";const n=this.said.read(t.note),s=n?` — ${n}`:"";this.milestoneCaption.replaceChildren(i,document.createTextNode(s))}exposureInstants(e){const t=this.exposureTimes(e),i=1/t.length;return t.map(n=>({shapes:this.shapesAt(n),share:i}))}exposureTimes(e=this.currentTime){const t=Fs.windowEndingAt(e,this.currentSighting.exposure??0);if(t.ms<Et.SHORTEST_VISIBLE_EXPOSURE_MS)return[e];const i=Math.min(Et.MAX_EXPOSURE_STEPS,Math.max(2,Math.round(t.ms/Et.SHORTEST_VISIBLE_EXPOSURE_MS))),n=Math.ceil(this.travelPxOver(t.fromMs,t.ms)/Et.EXPOSURE_STEP_PX),s=Math.min(Et.MAX_TRAVEL_STEPS,Math.max(i,n)),r=[];for(let a=0;a<s;a++)r.push(t.fromMs+t.ms*a/(s-1));return r}travelPxOver(e,t){const i=this.shapesAt(e),n=this.shapesAt(e+t);let s=0;for(const[r,a]of i){const l=n.get(r);if(!l)continue;const c=l.bounds.x+l.bounds.width/2-(a.bounds.x+a.bounds.width/2),h=l.bounds.y+l.bounds.height/2-(a.bounds.y+a.bounds.height/2);s=Math.max(s,Math.hypot(c,h))}return s}shapeAt(e,t,i){if(!this.accountHidden)for(const n of this.exposureTimes()){const s=this.currentSighting.timeline.hitTest(n,e,t,i);if(s)return s}}shapesAt(e){const t=new Map;for(const i of this.currentSighting.timeline.sourceIds){const n=this.currentSighting.timeline.getInterpolatedShapeAt(e,i);n&&t.set(i,n)}return t}static SHORTEST_VISIBLE_EXPOSURE_MS=20;static MAX_EXPOSURE_STEPS=48;static EXPOSURE_STEP_PX=2;static MAX_TRAVEL_STEPS=320;applyFrameFormat(){const e=Bt.frameWidthPx(this.currentSighting.instrument,this.canvas.height);if(this.canvas.width===e)return;this.canvas.width=e,this.canvas.parentElement?.style.setProperty("--frame-aspect",`${e} / ${this.canvas.height}`)}canvasPointFromEvent(e){const t=this.canvas.getBoundingClientRect();if(!(t.width===0||t.height===0))return{x:(e.clientX-t.left)/t.width*this.canvas.width,y:(e.clientY-t.top)/t.height*this.canvas.height}}onFrame(e,t){this.canvasRenderer.clear(this.canvas.width,this.canvas.height);const i=this.playbackState!=="playing"?this.highlightedSourceIds:tE;this.canvasRenderer.setStarPoints(Bt.starPointsOf(this.sighting.instrument));const n=(at(this.sighting,e)?.rollDeg??0)+this.gaitAt(e).rollDeg;this.canvasRenderer.setRoll(n*Math.PI/180);const s=this.exposureInstants(e),r=this.frameShift;if(this.paintsShapes)for(const l of s)for(const[,c]of l.shapes){const h=l.share,d=h===1?c:{...c,transparency:1-(1-c.transparency)*h};this.canvasRenderer.paintShape(this.shifted(d,r))}for(const[l,c]of s[0].shapes)!this.selectionShown||!i.has(l)||(this.paintsShapes?i.size===1?this.canvasRenderer.paintShape({...c,selected:!0}):this.canvasRenderer.paintMemberOutline(c):this.canvasRenderer.paintSelectionOnly(this.shifted(c,r)));const a=this.selectionShown&&i.size>1?kt.groupBoundsFor([...t].filter(([l])=>i.has(l)).map(([,l])=>l.bounds)):void 0;this.chromeDraw=l=>{a&&l.paintGroupHandles(a),this.overlayPainter?.(l)},this.paintChrome(this.chromeDraw),this.mapShapeBounds=s.flatMap(l=>[...l.shapes.values()].filter(c=>c.transparency<1).map(c=>this.shifted(c,r).bounds)),this.keepObserverMapClear(),this.seekInput.value=String(e),this.paintSeekProgress(e),this.timeStartLabel.textContent=this.formatPosition(e),this.showMilestoneAt(e),this.paintObserverMap(e),this.playbackState==="playing"?(this.soundPreview=void 0,this.sightingAudio.setSound(ng(this.currentSighting,e))):this.soundPreview?this.sightingAudio.setSound(this.soundPreview):this.sightingAudio.silence(),this.updatePlayPauseButton(),this.dispatchEvent(new CustomEvent("timeupdate",{detail:{time:e}}))}shifted(e,t){return t.x===0&&t.y===0?e:{...e,bounds:{...e.bounds,x:e.bounds.x+t.x,y:e.bounds.y+t.y}}}createPlayer(){const e=new CS(this.currentSighting.timeline,(t,i)=>this.onFrame(t,i));return e.loop=this.loopEnabled,e.onEnded=()=>{this.updatePlayPauseButton(),this.dispatchEvent(new CustomEvent("ended",{bubbles:!0,composed:!0}))},e}static SEEK_KEY_STEP_MS=5e3;handleFullscreenKey=e=>{e.key.toLowerCase()!=="f"||e.altKey||e.ctrlKey||e.metaKey||!this.enableClickToPlay||e.composedPath().some(i=>i instanceof HTMLElement&&(i.isContentEditable||["INPUT","TEXTAREA","SELECT"].includes(i.tagName)&&i.type!=="range"))||(e.preventDefault(),this.toggleFullscreen())};handleSeekKey=e=>{if(e.altKey||e.ctrlKey||e.metaKey)return;const t=e.key==="ArrowLeft"?-1:e.key==="ArrowRight"?1:0;if(t){e.preventDefault();const i=this.player.seekableDuration;this.player.seek(Math.min(i,Math.max(0,this.player.time+t*Et.SEEK_KEY_STEP_MS)))}else e.key===" "&&(e.preventDefault(),this.togglePlayPause())};togglePlayPause(){if(!(this.player.seekableDuration<=0)){if(this.player.playbackState==="playing")this.player.pause(),this.soundPreview=void 0,this.sightingAudio.silence(),this.refresh();else if(this.clockHeld){this.playAfterHold=!this.playAfterHold;return}else this.sightingAudio.resume(),this.player.play();this.updatePlayPauseButton(),this.flashPlayback()}}flashPlayback(){const e=this.playbackFlash;e.innerHTML=this.player.playbackState==="playing"?qe.PLAY:qe.PAUSE,e.classList.remove("flashing"),e.offsetWidth,e.classList.add("flashing")}static icons=new WeakMap;static setIcon(e,t){Et.icons.get(e)!==t&&(Et.icons.set(e,t),e.innerHTML=t)}set captionHeld(e){this.stageElement.classList.toggle("caption-held",e)}static CONTROLS_IDLE_MS=3e3;controlsIdleTimer;wasPlaying=!1;quietControlsValue=!1;get quietControls(){return this.quietControlsValue}set quietControls(e){this.quietControlsValue=e,this.stageElement.classList.toggle("quiet",e)}tapRevealedOnly=!1;get hoverless(){return typeof matchMedia=="function"&&matchMedia("(hover: none)").matches}touchedStage(){if(!this.hoverless)return;this.player.playbackState==="playing"&&!this.stageElement.classList.contains("touched")&&(this.tapRevealedOnly=!0),this.revealControls()}pointerHeld=!1;handlePointerDown=()=>{this.pointerHeld=!0};resumeAfterScrub=!1;suspendForScrub(){this.player.playbackState==="playing"&&(this.resumeAfterScrub=!0,this.stopPlaying())}stopPlaying(){this.player.pause(),this.soundPreview=void 0,this.sightingAudio.silence(),this.refresh(),this.updatePlayPauseButton()}resumeFromScrub(){this.resumeAfterScrub&&(this.resumeAfterScrub=!1,this.sightingAudio.resume(),this.player.play(),this.updatePlayPauseButton())}handleHidden=()=>{this.player.playbackState==="playing"&&this.stopPlaying(),this.resumeAfterScrub=!1};handleVisibility=()=>{document.visibilityState==="hidden"&&this.handleHidden()};handlePointerRelease=()=>{this.resumeAfterScrub&&window.setTimeout(()=>this.resumeFromScrub(),0),this.pointerHeld&&(this.pointerHeld=!1,this.hoverless&&this.stageElement.classList.contains("touched")&&this.revealControls())};revealControls(){this.stageElement.classList.add("touched"),window.clearTimeout(this.controlsIdleTimer),this.player.playbackState==="playing"&&(this.pointerHeld||!this.momentsMenu.hidden||(this.controlsIdleTimer=window.setTimeout(()=>{this.stageElement.classList.remove("touched"),this.tapRevealedOnly=!1},Et.CONTROLS_IDLE_MS)))}updatePlayPauseButton(){const e=this.player.playbackState==="playing";this.stageElement.classList.toggle("paused",!e),e!==this.wasPlaying&&e&&this.hoverless&&(!this.quietControlsValue||this.stageElement.classList.contains("touched"))&&this.revealControls(),this.wasPlaying=e,Et.setIcon(this.playPauseButton,e?qe.PAUSE:qe.PLAY);const t=this.player.seekableDuration>0;this.playPauseButton.disabled=!t;const i=t?e?this.messages.pause:this.messages.play:this.messages.noDuration;this.playPauseButton.title=i,this.playPauseButton.setAttribute("aria-label",i)}toggleLoop(){this.loopEnabled=!this.loopEnabled,this.player.loop=this.loopEnabled}restorePlayback(){const e=this.playbackBeforeClick;e&&(this.currentTime=e.time,e.state==="playing"?this.play():this.pause())}get canUseNativeFullscreen(){return typeof this.fullscreenTarget.requestFullscreen=="function"&&document.fullscreenEnabled}toggleFullscreen(){if(!this.canUseNativeFullscreen){this.simulatedFullscreen?this.exitSimulatedFullscreen():this.enterSimulatedFullscreen();return}document.fullscreenElement?document.exitFullscreen():this.fullscreenTarget.requestFullscreen().catch(e=>{console.error("<rr0-ufo>: requestFullscreen() failed —",e)})}enterSimulatedFullscreen(){const e=this.fullscreenTarget;this.styleBeforeSimulatedFullscreen=e.getAttribute("style")??"",this.bodyOverflowBeforeSimulatedFullscreen=document.body.style.overflow;const t=e.style;t.setProperty("position","fixed"),t.setProperty("inset","0"),t.setProperty("margin","0"),t.setProperty("max-width","none"),t.setProperty("max-height","none"),t.setProperty("aspect-ratio","auto"),t.setProperty("z-index","2147483647"),t.setProperty("background","#000"),t.setProperty("width","100vw"),t.setProperty("width","100dvw"),t.setProperty("height","100vh"),t.setProperty("height","100dvh"),document.body.style.overflow="hidden",this.simulatedFullscreen=!0,document.addEventListener("keydown",this.handleSimulatedFullscreenKey),this.updateFullscreenButton(),this.updateMuteButton()}exitSimulatedFullscreen(){if(!this.simulatedFullscreen)return;const e=this.fullscreenTarget;this.styleBeforeSimulatedFullscreen?e.setAttribute("style",this.styleBeforeSimulatedFullscreen):e.removeAttribute("style"),document.body.style.overflow=this.bodyOverflowBeforeSimulatedFullscreen??"",this.simulatedFullscreen=!1,document.removeEventListener("keydown",this.handleSimulatedFullscreenKey),this.updateFullscreenButton(),this.updateMuteButton()}toggleObserverMap(){const e=this.observerMapPanel.hidden;this.observerMapAsked=e,this.setObserverMapOpen(e),this.keepObserverMapClear(),this.dispatchEvent(new CustomEvent("observermapchange",{bubbles:!0,composed:!0,detail:{open:e}}))}get observerMapOpen(){return!this.observerMapPanel.hidden}get milestonesVisible(){return this.milestonesShown}observerMapAsked=!1;applyObserverMapDefault(){const e=this.getAttribute(Bl),t=e===null?this.sighting.observerMap??this.observerPath?.travels===!0:e!=="false";this.setObserverMapOpen(t&&this.observerPath!==void 0)}setObserverMapOpen(e){this.observerMapPanel.hidden=!e,this.observerMapPanel.removeAttribute("title"),this.observerMapButton.setAttribute("aria-pressed",String(e)),this.updateObserverMapButton(),e&&(this.sizeObserverMapCanvas(),this.loadObserverMapImagery(),this.paintObserverMap(this.currentTime))}updateObserverMapButton(){const e=!this.observerMapPanel.hidden;Et.setIcon(this.observerMapButton,e?qe.MAP_ON:qe.MAP_OFF);const t=e?this.messages.hideObserverMap:this.messages.showObserverMap;this.observerMapButton.title=t,this.observerMapButton.setAttribute("aria-label",t);const i=[[this.mapZoomInButton,this.messages.zoomMapIn],[this.mapZoomOutButton,this.messages.zoomMapOut],[this.mapFitButton,this.messages.fitMap]];for(const[n,s]of i)n.title=s,n.setAttribute("aria-label",s)}updateObserverMap(){const e=this.observerPath!==void 0;if(this.observerPath=Ul.of(this.currentSighting),this.observerMapButton.hidden=this.observerPath===void 0,!e&&this.observerPath&&this.applyObserverMapDefault(),!this.observerPath){this.setObserverMapOpen(!1),this.observerMapBounds=void 0;return}const t=this.tracesShownState?this.currentSighting.traces.flatMap(n=>n.points):[],i=yi.including(this.observerPath.boundsAround(Et.OBSERVER_MAP_MIN_SPAN_M,Et.OBSERVER_MAP_MARGIN),t);(!this.observerMapBounds||!this.sameGround(this.observerMapBounds,i))&&(this.observerMapBounds&&this.observerMapView.refit(this.observerMapBounds,i),this.observerMapBounds=i,this.observerMapImagery=void 0,this.observerMapImageryCredit=void 0,this.observerMapImageryFailed=!1,this.observerMapImageryBounds=void 0,this.observerMapImageryLoading=!1,this.observerMapPanel.hidden||this.loadObserverMapImagery())}sameGround(e,t){const i=Math.abs(e.east-e.west)/20;return Math.abs(e.north-t.north)<i&&Math.abs(e.south-t.south)<i&&Math.abs(e.west-t.west)<i&&Math.abs(e.east-t.east)<i}async loadObserverMapImagery(){const e=this.observerMapViewBounds;if(!e||this.observerMapPanel.hidden||this.observerMapImageryLoading||!this.observerMapImageryNeededFor(e))return;const t=this.observerMapView.changed,i=t?yi.expand(e,Et.OBSERVER_MAP_IMAGERY_AHEAD):e,n=Et.OBSERVER_MAP_IMAGERY_PX*(t?1+2*Et.OBSERVER_MAP_IMAGERY_AHEAD:1);this.observerMapImageryBounds=i,this.observerMapImageryViewWidth=e.east-e.west,this.observerMapImageryLoading=!0;const s=WM();try{const r=await s.getImageryTexture(i,{width:n,height:n});if(this.observerMapImageryBounds!==i)return;this.observerMapImagery=r,this.observerMapImageryCredit=s.attribution,this.observerMapImageryFailed=!1}catch{if(this.observerMapImageryBounds!==i)return;this.observerMapImageryFailed=this.observerMapImagery===void 0}finally{this.observerMapImageryBounds===i&&(this.observerMapImageryLoading=!1)}this.paintObserverMap(this.currentTime),this.scheduleObserverMapImagery()}static OBSERVER_MAP_IMAGERY_AHEAD=.5;static OBSERVER_MAP_IMAGERY_LOOKAHEAD=.25;observerMapImageryNeededFor(e){const t=this.observerMapImageryBounds;if(!t)return!0;const i=this.observerMapImagery?.bounds??t,n=this.observerMapView.changed?yi.expand(e,Et.OBSERVER_MAP_IMAGERY_LOOKAHEAD):e,s=n.west>=i.west&&n.east<=i.east&&n.south>=i.south&&n.north<=i.north,r=e.east-e.west>this.observerMapImageryViewWidth/2;return!s||!r}get observerMapCredit(){return this.observerMapImageryCredit}get observerMapFooterLine(){return this.observerMapImageryFailed?this.messages.mapImageryUnavailable:this.creditShownExternally?void 0:this.observerMapImageryCredit}mapShapeBounds=[];mapSceneBounds=[];setMapSubjectBounds(e){this.mapSceneBounds=e.map(t=>({x:t.x*this.canvas.width,y:t.y*this.canvas.height,width:t.width*this.canvas.width,height:t.height*this.canvas.height})),this.keepObserverMapClear()}keepObserverMapClear(){if(this.observerMapPanel.hidden)return;const e=this.observerMapBoxPx;if(!e)return;const t=[...this.mapShapeBounds,...this.mapSceneBounds],i=(c,h,d)=>{for(const u of t)if(!(u.x+u.width<c-d||u.x>h+d)&&!(u.y>e.bottom+d||u.y+u.height<e.top-d))return!0;return!1},n=[this.canvas.width-e.width,this.canvas.width],s=[0,e.width],r=Et.OBSERVER_MAP_CLEARANCE_PX,a=i(...n,0),l=i(...s,0);if(this.observerMapPanel.classList.toggle("subject-overlap",a&&l&&!this.observerMapAsked),this.observerMapPanel.classList.contains("on-the-left")){!a&&(l||!i(n[0],n[1],r))&&this.observerMapPanel.classList.remove("on-the-left");return}i(n[0],n[1],0)&&!i(s[0],s[1],0)&&this.observerMapPanel.classList.add("on-the-left")}observerMapBoxPx;static OBSERVER_MAP_CLEARANCE_PX=24;sizeObserverMapCanvas(){const e=this.observerMapPanel.clientWidth;if(e===0)return;const t=Math.round(e*(globalThis.devicePixelRatio??1));this.measureObserverMapBox(),this.observerMapCanvas.width!==t&&(this.observerMapCanvas.width=t,this.observerMapCanvas.height=t)}measureObserverMapBox(){const e=this.observerMapPanel.getBoundingClientRect(),t=this.canvas.getBoundingClientRect();if(t.width===0||t.height===0)return;const i=this.canvas.width/t.width,n=this.canvas.height/t.height;this.observerMapBoxPx={width:e.width*i,top:(e.top-t.top)*n,bottom:(e.bottom-t.top)*n}}paintObserverMap(e){if(this.observerMapPanel.hidden||!this.observerPath||!this.observerMapBounds)return;const t=at(this.currentSighting,e);t?.lat!==void 0&&t.lng!==void 0&&!this.observerMapDrag?.moved&&this.observerMapView.keepInView(this.observerMapBounds,{lat:t.lat,lng:t.lng},Et.OBSERVER_MAP_FOLLOW_MARGIN)&&this.scheduleObserverMapImagery();const i=this.currentSighting.instrument,n=[],s=this.currentSighting.milestones.length>0?zf(this.currentSighting.milestones,e):void 0;for(const r of this.milestonesShown?Io(this.currentSighting.milestones):[]){const a=at(this.currentSighting,r.t);a?.lat===void 0||a.lng===void 0||n.push({label:this.said.read(r.label)??"",note:this.said.read(r.note),t:r.t,lat:a.lat,lng:a.lng,current:r===s})}this.observerMapRenderer.paint({bounds:this.observerMapViewBounds,imagery:this.observerMapImagery,path:this.observerPath,position:t?.lat!==void 0&&t.lng!==void 0?{lat:t.lat,lng:t.lng}:void 0,headingDeg:t?.headingDeg===void 0?void 0:t.headingDeg+this.lookYawDeg,coneHalfAngleDeg:t?Vs.of(i,this.canvas.height,t.fovDeg).halfWidthAngleDeg(Bt.aspectOf(i)):void 0,markers:n,traces:(this.tracesShownState?this.currentSighting.traces:[]).map(r=>({kind:r.kind,points:r.points,color:r.color,label:this.said.read(r.title)})),decor:this.observerMapDecorAt(e),observerLabel:this.said.read(this.currentSighting.observer?.title)??this.messages.observerHere,nightFraction:this.observerMapNightFraction,attribution:this.observerMapFooterLine})}toggleMilestones(){this.setMilestonesShown(!this.milestonesShown)}setMilestonesShown(e){this.milestonesShown=e,this.milestoneMarks.hidden=!e,this.momentsBox.hidden=!e||this.sighting.milestones.length===0,this.refreshSeekSegments(this.player.seekableDuration,Io(this.sighting.milestones).map(t=>t.t)),this.milestonesButton.setAttribute("aria-pressed",String(e)),this.updateMilestonesButton(),this.showMilestoneAt(this.currentTime),this.paintObserverMap(this.currentTime)}updateMilestonesButton(){this.milestonesButton.hidden=this.currentSighting.milestones.length===0,this.momentsButton.title=this.messages.moments,Et.setIcon(this.milestonesButton,this.milestonesShown?qe.MILESTONES_ON:qe.MILESTONES_OFF);const e=this.milestonesShown?this.messages.hideMilestones:this.messages.showMilestones;this.milestonesButton.title=e,this.milestonesButton.setAttribute("aria-label",e)}observerMapDecorAt(e){const t=at(this.currentSighting,0);return t?.lat===void 0||t.lng===void 0?[]:this.currentSighting.decor.filter(i=>i.kind!=="crop").map(i=>{const n=Gs(i,e),{lat:s,lng:r}=us(n.eastM,-n.northM,t.lat,t.lng);return{lat:s,lng:r,headingDeg:n.headingDeg,label:this.said.read(i.title)??this.messages.decorHere}})}observerMapNightFraction;setSunAltitude(e){const t=e===void 0?void 0:Math.max(0,Math.min(1,-e/12));t!==this.observerMapNightFraction&&(this.observerMapNightFraction=t,this.paintObserverMap(this.currentTime))}setLookOffset(e,t){e===this.lookYawDeg&&t===this.lookPitchDeg||(this.lookYawDeg=e,this.lookPitchDeg=t,this.refresh())}get frameShiftPx(){return this.frameShift}get frameShift(){const e=this.gaitAt(this.currentTime),t=this.lookYawDeg+e.yawDeg,i=this.lookPitchDeg+e.pitchDeg;if(t===0&&i===0)return{x:0,y:0};const n=at(this.currentSighting,this.currentTime),s=Vs.of(this.currentSighting.instrument,this.canvas.height,n?.fovDeg??60);return{x:-s.angleDegToRadiusPx(t),y:s.angleDegToRadiusPx(i)}}gaitAt(e){return $t.bodyAt(this.currentSighting,e,this.steadyBody)}mutedState=!1;get muted(){return this.mutedState}set muted(e){e!==this.mutedState&&(this.mutedState=e,!e&&this.volumeState===0&&(this.volumeState=Et.RESTORED_VOLUME),this.applyLevel())}volumeState=1;static RESTORED_VOLUME=.5;get volume(){return this.volumeState}set volume(e){this.setVolume(e)}setVolume(e){this.volumeState=Math.min(Math.max(e,0),1),this.mutedState=this.volumeState===0,this.applyLevel()}get level(){return this.mutedState?0:this.volumeState}applyLevel(){this.sightingAudio.setLevel(this.level),this.updateMuteButton(),this.dispatchEvent(new CustomEvent("mutedchange",{bubbles:!0,composed:!0,detail:{muted:this.mutedState,volume:this.volumeState}}))}toggleMuted(){this.hasSound&&(this.muted=!this.mutedState)}ambientSound;get hasSound(){return this.currentSighting.soundTrack.allKeyframes.length>0||this.ambientSound?.(this.currentSighting)===!0}updateMuteButton(){const e=!this.hasSound;if(this.muteButton.disabled=e,this.volumeInput.hidden=e,e){Et.setIcon(this.muteButton,qe.MUTED),this.muteButton.title=this.messages.noSound,this.muteButton.setAttribute("aria-label",this.messages.noSound),this.muteButton.setAttribute("aria-pressed","true");return}Et.setIcon(this.muteButton,this.mutedState?qe.MUTED:qe.VOLUME);const t=this.mutedState?this.messages.unmute:this.messages.mute;this.muteButton.title=t,this.muteButton.setAttribute("aria-label",t),this.muteButton.setAttribute("aria-pressed",String(this.mutedState)),this.volumeInput.value=String(this.level)}updateFullscreenButton(){const e=this.simulatedFullscreen||document.fullscreenElement===this.fullscreenTarget;Et.setIcon(this.fullscreenButton,e?qe.EXIT_FULLSCREEN:qe.ENTER_FULLSCREEN),this.fullscreenButton.title=e?this.messages.exitFullscreen:this.messages.fullscreen,this.fullscreenButton.setAttribute("aria-label",this.fullscreenButton.title)}get said(){return this.saidTexts??=new Un(_s.preferencesFor(this))}saidTexts;async loadLocaleMessages(){const e=ch(_s.preferencesFor(this),ph);if(e===this.messagesLanguage||e==="en"&&this.messagesLanguage===void 0)return;this.messagesLanguage=e;const t=await rS(e);this.messagesLanguage===e&&this.applyMessages(t)}messagesLanguage;updateTimeLabelTitles(){const e=this.showClockTime?this.messages.switchToElapsed:this.messages.switchToClockTime,t=this.canSwitchTimeDisplay?` — ${e}`:"";this.timeStartLabel.title=this.messages.currentPosition+t,this.timeEndLabel.title=this.messages.duration+t,this.timePill.classList.toggle("switchable",this.canSwitchTimeDisplay),this.canSwitchTimeDisplay?(this.timePill.setAttribute("role","button"),this.timePill.setAttribute("tabindex","0")):(this.timePill.removeAttribute("role"),this.timePill.removeAttribute("tabindex"))}applyMessages(e){this.messages=e,this.updateTimeLabelTitles(),this.updatePlayPauseButton(),this.updateFullscreenButton(),this.updateMuteButton(),this.updateObserverMapButton(),this.updateReferencesButton(),this.updateTracesButton(),this.updateMilestonesButton(),this.renderIssues()}updateTimeLabels(){const e=this.currentSighting.event,t=ec(e);this.realDurationMs=t!==void 0&&t>0?t:void 0,this.realStartMs=e.time?v0(e.time):void 0;const i=this.currentSighting.timeline.duration;this.player.playbackRate=this.realDurationMs!==void 0&&i>0?i/this.realDurationMs:1,this.player.durationOverrideMs=i>0?0:this.realDurationMs??0,this.timeEndLabel.textContent=this.formatEndOfTimeline(),this.timeStartLabel.textContent=this.formatPosition(this.player.time),this.updateTimeLabelTitles()}formatPosition(e){if(this.realDurationMs===void 0)return Wh(e);const t=this.currentSighting.timeline.duration,i=t>0&&e<=t?e/t*this.realDurationMs:e;return this.canShowClockTime?Zv(Kv(this.realStartMs+i)):Wh(i)}formatEndOfTimeline(){return this.realDurationMs===void 0?Wh(this.currentSighting.timeline.duration):this.canShowClockTime?Zv(Kv(this.realStartMs+this.realDurationMs)):Wh(this.realDurationMs)}}function Kv(o){const e=new Date(o);return{hour:e.getUTCHours(),minute:e.getUTCMinutes(),second:e.getUTCSeconds()}}function Zv(o){if(o.hour===void 0)return"0:00";const e=t=>String(t).padStart(2,"0");return o.second?`${e(o.hour)}:${e(o.minute??0)}:${e(o.second)}`:`${e(o.hour)}:${e(o.minute??0)}`}function Wh(o){const e=Math.round(o/1e3),t=Math.floor(e/60),i=e%60;return`${t}:${String(i).padStart(2,"0")}`}const E0="rr0-ufo";function xf(){customElements.get(E0)||customElements.define(E0,Et)}const iE="recordingissues";class Kc{constructor(e,t){this.seekInput=e,this.layer=t,e.addEventListener("pointerdown",i=>{this.snapArmed=!0,this.nameMarkUnder(i)}),e.addEventListener("pointerup",()=>this.snapArmed=!1),e.addEventListener("pointermove",i=>this.nameMarkUnder(i)),e.addEventListener("pointerleave",()=>e.removeAttribute("title"))}static SNAP_PX=6;marks=[];duration=0;drawn="";snapArmed=!1;show(e,t){const i=t>0?[...e].sort((s,r)=>s.t-r.t):[],n=`${t}|${i.map(s=>`${s.kind}:${s.t}:${s.label}`).join("|")}`;n!==this.drawn&&(this.drawn=n,this.marks=i,this.duration=t,this.layer.replaceChildren(...i.map(s=>{const r=document.createElement("span");return r.className=`timeline-mark ${s.kind}`,r.style.left=`${Math.min(Math.max(s.t/t,0),1)*100}%`,r})))}snap(e){return this.snapArmed?(this.snapArmed=!1,this.markNear(e)?.t??e):e}next(e){return this.marks.find(t=>t.t>e+Kc.SAME_INSTANT)?.t}previous(e){return[...this.marks].reverse().find(t=>t.t<e-Kc.SAME_INSTANT)?.t}static SAME_INSTANT=.5;markNear(e){const t=this.seekInput.getBoundingClientRect().width;if(this.duration<=0||t<=0)return;const i=Kc.SNAP_PX/t*this.duration;let n;for(const s of this.marks)Math.abs(s.t-e)>i||(!n||Math.abs(s.t-e)<Math.abs(n.t-e)||s.t===n.t&&s.kind==="milestone")&&(n=s);return n}nameMarkUnder(e){const t=this.seekInput.getBoundingClientRect();if(t.width<=0||this.duration<=0)return;const i=this.marksNear((e.clientX-t.left)/t.width*this.duration);i?this.seekInput.title=i:this.seekInput.removeAttribute("title")}marksNear(e){const t=this.markNear(e);if(t)return[...new Set(this.marks.filter(i=>i.t===t.t).map(i=>i.label))].join(" · ")}}class _l{static HALF_SPAN_MS=2e3;static MIN_SPEED_MS=1;static at(e,t,i){const n=e.event.place?.[0],s=e.observerTrack;if(!n)return 0;const r=g=>{const m=s.getInterpolatedPoseAt(Math.max(0,g));if(!m||m.lat===void 0||m.lng===void 0)return;const v=vt(m.lat,m.lng,n.lat,n.lng);return{eastM:v.x,northM:-v.z,heading:m.headingDeg}},a=r(t-_l.HALF_SPAN_MS),l=r(t+_l.HALF_SPAN_MS),c=r(t);if(!a||!l||!c)return 0;const h=Math.hypot(l.eastM-a.eastM,l.northM-a.northM),d=2*_l.HALF_SPAN_MS/1e3;if(h/d<_l.MIN_SPEED_MS)return 0;const u=i.heightAt(l.eastM,l.northM)-i.heightAt(a.eastM,a.northM),f=Math.atan2(u,h)*180/Math.PI;if(c.heading===void 0)return f;const p=Math.atan2(l.eastM-a.eastM,l.northM-a.northM)*180/Math.PI;return f*Math.max(0,Math.cos((c.heading-p)*Math.PI/180))}}const nE=.08,jv=.15,Jv=2,sE=2e3;class rE{context;noiseBuffer;voices=new Map;level=1;master;paused=!0;requested=[];resume(){if(!this.context){if(typeof AudioContext>"u")return;try{this.context=new AudioContext}catch(e){console.warn("VehicleAudio: Web Audio unavailable, vehicles stay silent:",e);return}}To.unlock(this.context),this.apply()}setLevel(e){this.level=e,this.master&&(this.master.gain.value=e)}setPaused(e){e!==this.paused&&(this.paused=e,this.apply())}setVoices(e){this.requested=e,this.apply()}dispose(){for(const e of[...this.voices.keys()])this.release(e);this.context?.close(),this.context=void 0,this.master=void 0}masterOf(e){return this.master||(this.master=e.createGain(),this.master.gain.value=this.level,this.master.connect(e.destination)),this.master}apply(){const e=this.context;if(!e)return;const t=this.paused?[]:this.requested.filter(n=>n.inside||n.distanceM<sE),i=new Set(t.map(n=>n.id));for(const n of[...this.voices.keys()])i.has(n)||this.release(n);for(const n of t){const s=this.voices.get(n.id)??this.build(e,n.id);this.retarget(e,s,n)}}build(e,t){const i=e.createGain();i.gain.value=0;const n=e.createBiquadFilter();n.type="lowpass",n.connect(i).connect(this.masterOf(e));const s=e.createOscillator();s.type="sawtooth";const r=e.createOscillator();r.type="sine";const a=e.createGain(),l=e.createBiquadFilter();l.type="lowpass",l.frequency.value=900,s.connect(l),r.connect(l),l.connect(a).connect(n);const c=()=>{const w=e.createBufferSource();return w.buffer=this.noise(e),w.loop=!0,w.loopStart=Math.random()*Jv*.5,w},h=c(),d=e.createBiquadFilter();d.type="bandpass",d.Q.value=4;const u=e.createGain();h.connect(d).connect(u).connect(n);const f=c(),p=e.createBiquadFilter();p.type="lowpass",p.frequency.value=600;const g=e.createGain();f.connect(p).connect(g).connect(n);const m=c(),v=e.createBiquadFilter();v.type="bandpass",v.frequency.value=1400,v.Q.value=.7;const b=e.createGain();m.connect(v).connect(b).connect(n);const x=[s,r,h,f,m];for(const w of x)w.start();const y={nodes:[i,n,a,l,d,u,p,g,v,b,...x],sources:x,firing:s,crank:r,knock:d,engineGain:a,knockGain:u,roadGain:g,windGain:b,cabin:n,output:i};return this.voices.set(t,y),y}retarget(e,t,{profile:i,state:n,noise:s,inside:r,windowsOpen:a,distanceM:l}){const c=e.currentTime,h=(b,x)=>b.setTargetAtTime(x,c,nE),d=n.rpm/60,u=d*i.cylinders/2,f=Math.min(1,n.rpm/i.shiftUpRpm),p=Math.min(1.5,n.speedMps/30);h(t.firing.frequency,u),h(t.crank.frequency,d),h(t.knock.frequency,u*3),h(t.engineGain.gain,i.engineGain*(.25+.75*n.load)*(.5+.5*f)*.3),h(t.knockGain.gain,i.roughness*(.2+.8*n.load)*.4),h(t.roadGain.gain,i.roadGain*p**1.5*.8);const g=!r||a;h(t.windGain.gain,p**2*(g?.5:.06));const m=r?a?3500:700:8e3/(1+l/60);h(t.cabin.frequency,m);const v=r?.5:Math.min(1,8/Math.max(l,1));h(t.output.gain,v*s)}release(e){const t=this.voices.get(e);if(!t)return;this.voices.delete(e);const i=this.context;i&&(t.output.gain.setTargetAtTime(0,i.currentTime,jv/3),setTimeout(()=>{for(const n of t.sources)try{n.stop()}catch{}for(const n of t.nodes)n.disconnect()},jv*1e3*3))}noise(e){if(this.noiseBuffer)return this.noiseBuffer;const t=e.createBuffer(1,e.sampleRate*Jv,e.sampleRate),i=t.getChannelData(0);for(let n=0;n<i.length;n++)i[n]=Math.random()*2-1;return this.noiseBuffer=t,t}}class vh{static BY_KIND={car:{cylinders:4,idleRpm:800,kmhPer1000Rpm:[8,14,21,29,37,45],shiftUpRpm:3e3,shiftDownRpm:1300,engineGain:.6,roadGain:.5,roughness:.15},generic:{cylinders:4,idleRpm:800,kmhPer1000Rpm:[8,14,21,29,37,45],shiftUpRpm:3e3,shiftDownRpm:1300,engineGain:.6,roadGain:.5,roughness:.15},van:{cylinders:4,idleRpm:750,kmhPer1000Rpm:[7,12,19,27,35,42],shiftUpRpm:2600,shiftDownRpm:1200,engineGain:.8,roadGain:.7,roughness:.45},truck:{cylinders:6,idleRpm:600,kmhPer1000Rpm:[5,8,12,17,23,30,38,48],shiftUpRpm:1900,shiftDownRpm:1e3,engineGain:1,roadGain:.9,roughness:.55},motorcycle:{cylinders:2,idleRpm:1100,kmhPer1000Rpm:[12,18,24,30,35,40],shiftUpRpm:6e3,shiftDownRpm:2500,engineGain:.9,roadGain:.3,roughness:.3}};static of(e){return vh.BY_KIND[e??"generic"]??vh.BY_KIND.generic}}class yo{constructor(e,t){this.samples=e,this.startMs=t}static SAMPLE_MS=100;static STANDING_MPS=.3;static of(e,t,i,n){const s=yo.SAMPLE_MS,r=[];for(let c=i;c<=n+s/2;c+=s){const h=t(c-s/2),d=t(c+s/2);if(!h||!d)return;r.push(Math.hypot(d.eastM-h.eastM,d.northM-h.northM)/(s/1e3))}const a=[];let l=1;for(let c=0;c<r.length;c++){const h=r[c],d=(r[Math.min(c+1,r.length-1)]-r[Math.max(c-1,0)])/(2*s/1e3);if(h<yo.STANDING_MPS){l=1,a.push({speedMps:h,rpm:e.idleRpm,load:.1,gear:0});continue}const u=h*3.6,f=v=>u/e.kmhPer1000Rpm[v-1]*1e3;for(;l<e.kmhPer1000Rpm.length&&f(l)>e.shiftUpRpm;)l++;for(;l>1&&f(l)<e.shiftDownRpm;)l--;const p=Math.max(f(l),e.idleRpm*(1+.3*Math.min(1,h/3))),g=.15+.5*Math.min(1,(h/35)**2),m=d>.15?Math.min(1,g+d/2.5):d<-.3?.05:g;a.push({speedMps:h,rpm:p,load:m,gear:l})}return new yo(a,i)}at(e){const t=(e-this.startMs)/yo.SAMPLE_MS,i=Math.min(Math.max(Math.floor(t),0),this.samples.length-1),n=this.samples[i],s=this.samples[Math.min(i+1,this.samples.length-1)],r=Math.min(Math.max(t-i,0),1);return{speedMps:n.speedMps+(s.speedMps-n.speedMps)*r,rpm:n.rpm+(s.rpm-n.rpm)*r,load:n.load+(s.load-n.load)*r,gear:r<.5?n.gear:s.gear}}}class Nu{drives=new Map;at(e,t){const i=[],n=e.event.place?.[0],s=c=>{const h=e.observerTrack.getInterpolatedPoseAt(c),d=h?.lat??n?.lat,u=h?.lng??n?.lng;if(d===void 0||u===void 0||!n)return;const f=vt(d,u,n.lat,n.lng);return{eastM:f.x,northM:-f.z}},r=Math.max(e.observerTrack.duration,(e.event.durationSeconds??0)*1e3),a=e.vehicle;if(a){const c=vh.of(a.kind),h=this.drive(`observer:${a.kind}`,Nu.trackKey(e),()=>yo.of(c,s,0,r));h&&i.push({id:"observer",profile:c,state:h.at(t),noise:a.noise??1,inside:!0,windowsOpen:a.windowsOpen===!0,distanceM:0})}const l=s(t);for(const c of e.decor){if(!c.engine||!l)continue;const h=vh.of(c.engine.kind),d=g=>{const m=Gs(c,g);return{eastM:m.eastM,northM:m.northM}},u=this.drive(`decor:${c.id}`,Nu.decorKey(c,r),()=>yo.of(h,d,0,r));if(!u)continue;const f=Gs(c,t),p=Math.hypot(f.eastM-l.eastM,f.northM-l.northM,f.altitudeM);i.push({id:`decor:${c.id}`,profile:h,state:u.at(t),noise:c.engine.noise??1,inside:!1,windowsOpen:!0,distanceM:p})}return i}drive(e,t,i){const n=this.drives.get(e);if(n&&n.key===t)return n.drive;const s=i();return this.drives.set(e,{key:t,drive:s}),s}static trackKey(e){return e.observerTrack.allKeyframes.map(i=>`${i.t}:${i.pose.lat}:${i.pose.lng}`).join(";")}static decorKey(e,t){return`${t}|${e.eastM},${e.northM}|`+(e.track??[]).map(i=>`${i.t}:${i.eastM}:${i.northM}`).join(";")}}const aE="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAMAAADVRocKAAAARVBMVEX9sST/uyTfoCjNlSikfCqRcCx8Yy21hipTSi4TITEMHTEuMzBqWC3/wSRUX207SFj8/PyaoakmNUd5gYxBPy90fIfMz9RsB4kZAAACEUlEQVRo3u2XyXbDIAxFLeapjts6/f9PrQA3JymT25Cd3iY5xtYVIB6wLCQSiUQikUgk0nzBoVdFZ1xIpaTQbJnPACaNdYeskWwuAhaZoltnUemfnNkL4N49KEI8n0YAEXMvEWISAWQZPw2Xk1MIoF1dSNAzCMy6JsGyCR0wrkMwT3cBeDt+FH8aEHoA68LbM8HRHXQ3f0RE3/jXOOFX+s4djrKpIbzS7K+MmLrxlWCNR8mczjMw92Ar4dZLDXG4kzXinAECcOUPL3jMdN2294/GQGVG4EMHxORNJXoCfG6oT1trvDGM7iIA9N6aTOuuEbB9ra6FyCYr2gjge+fjA4CIi2uujYRoOBSw0A5/D0hT0X4PW0xtuotNpQPYtkt/fdtyM0LP6ZvOI2DtvoxtJWHvx38AxIkevLwXQ2TOA66DziYfLwC4r5wbIlwJo1ys8+VOBMy7/sxdjwIap49lVC3UePZp1mmyit4SuGUf11pjoTHVRVzXUaXFVt87kuEBsWZ055Q+2sXA76LbZYsvKR1ubvJqbKd5swl+GPI31p6L/sNYuDTe3jo+GBdr1J+P9PGawbRUw9VhleD/3ffT9uZ7DhtX1JNHL2CmNRXxYZhwSwBd3aJTyU85/GKOwhxBf5RnVk+75OSiuu+Ax4PQ3Jsg1hTeMUMwJgQp+PKCe2a+JuefFwQnkUgkEolEIpFerW8TL0hlNl2QVAAAAABJRU5ErkJggg==",oE=`
2837
2837
  <div class="stage" id="stage">
2838
2838
  <div class="frame" id="frame">
2839
2839
  <canvas id="scene-canvas"></canvas>
@@ -3156,11 +3156,11 @@ ${i.join(`
3156
3156
  * @license
3157
3157
  * Copyright 2010-2026 Three.js Authors
3158
3158
  * SPDX-License-Identifier: MIT
3159
- */const ag="185",cE=0,Qv=1,hE=2,Zc=1,dE=2,Wc=3,Pa=0,fi=1,Bn=2,br=0,Ia=1,Wi=2,e1=3,t1=4,Rh=5,eo=100,uE=101,fE=102,pE=103,mE=104,Xc=200,yh=201,gE=202,vE=203,A0=204,bh=205,yE=206,bE=207,ME=208,wE=209,xE=210,SE=211,EE=212,AE=213,_E=214,_0=0,T0=1,I0=2,sc=3,D0=4,R0=5,C0=6,k0=7,og=0,TE=1,IE=2,Mr=0,XM=1,$M=2,YM=3,qM=4,KM=5,ZM=6,jM=7,i1="attached",DE="detached",JM=300,Oo=301,rc=302,Vf=303,Wf=304,Sf=306,No=1e3,Ti=1001,P0=1002,Qt=1003,RE=1004,Xh=1005,mt=1006,Xf=1007,gr=1008,zn=1009,QM=1010,ew=1011,Mh=1012,lg=1013,Ts=1014,En=1015,ci=1016,cg=1017,hg=1018,wh=1020,tw=35902,iw=35899,nw=1021,sw=1022,Vi=1023,Wr=1026,bo=1027,ac=1028,dg=1029,Fo=1030,ug=1031,fg=1033,Zd=33776,jd=33777,Jd=33778,Qd=33779,L0=35840,O0=35841,N0=35842,F0=35843,U0=36196,B0=37492,z0=37496,H0=37488,G0=37489,Fu=37490,V0=37491,W0=37808,X0=37809,$0=37810,Y0=37811,q0=37812,K0=37813,Z0=37814,j0=37815,J0=37816,Q0=37817,em=37818,tm=37819,im=37820,nm=37821,sm=36492,rm=36494,am=36495,om=36283,lm=36284,Uu=36285,cm=36286,rw=2200,CE=2201,kE=2202,Bu=2300,hm=2301,$f=2302,n1=2303,Tl=2400,Il=2401,zu=2402,pg=2500,PE=2501,Bk=0,zk=1,Hk=2,LE=3200,Hu=0,OE=1,ba="",an="srgb",Gu="srgb-linear",Vu="linear",Yt="srgb",Yo=7680,s1=519,NE=512,FE=513,UE=514,mg=515,BE=516,zE=517,gg=518,HE=519,dm=35044,Wu="300 es",vr=2e3,xh=2001;function GE(o){for(let e=o.length-1;e>=0;--e)if(o[e]>=65535)return!0;return!1}function VE(o){return ArrayBuffer.isView(o)&&!(o instanceof DataView)}function Sh(o){return document.createElementNS("http://www.w3.org/1999/xhtml",o)}function WE(){const o=Sh("canvas");return o.style.display="block",o}const r1={};function Xu(...o){const e="THREE."+o.shift();console.log(e,...o)}function aw(o){const e=o[0];if(typeof e=="string"&&e.startsWith("TSL:")){const t=o[1];t&&t.isStackTrace?o[0]+=" "+t.getLocation():o[1]='Stack trace not available. Enable "THREE.Node.captureStackTrace" to capture stack traces.'}return o}function ke(...o){o=aw(o);const e="THREE."+o.shift();{const t=o[0];t&&t.isStackTrace?console.warn(t.getError(e)):console.warn(e,...o)}}function Ze(...o){o=aw(o);const e="THREE."+o.shift();{const t=o[0];t&&t.isStackTrace?console.error(t.getError(e)):console.error(e,...o)}}function Hl(...o){const e=o.join(" ");e in r1||(r1[e]=!0,ke(...o))}function XE(o,e,t){return new Promise(function(i,n){function s(){switch(o.clientWaitSync(e,o.SYNC_FLUSH_COMMANDS_BIT,0)){case o.WAIT_FAILED:n();break;case o.TIMEOUT_EXPIRED:setTimeout(s,t);break;default:i()}}setTimeout(s,t)})}const $E={[_0]:T0,[I0]:C0,[D0]:k0,[sc]:R0,[T0]:_0,[C0]:I0,[k0]:D0,[R0]:sc};class Na{addEventListener(e,t){this._listeners===void 0&&(this._listeners={});const i=this._listeners;i[e]===void 0&&(i[e]=[]),i[e].indexOf(t)===-1&&i[e].push(t)}hasEventListener(e,t){const i=this._listeners;return i===void 0?!1:i[e]!==void 0&&i[e].indexOf(t)!==-1}removeEventListener(e,t){const i=this._listeners;if(i===void 0)return;const n=i[e];if(n!==void 0){const s=n.indexOf(t);s!==-1&&n.splice(s,1)}}dispatchEvent(e){const t=this._listeners;if(t===void 0)return;const i=t[e.type];if(i!==void 0){e.target=this;const n=i.slice(0);for(let s=0,r=n.length;s<r;s++)n[s].call(this,e);e.target=null}}}const fn=["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"];let a1=1234567;const jc=Math.PI/180,oc=180/Math.PI;function Ws(){const o=Math.random()*4294967295|0,e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,i=Math.random()*4294967295|0;return(fn[o&255]+fn[o>>8&255]+fn[o>>16&255]+fn[o>>24&255]+"-"+fn[e&255]+fn[e>>8&255]+"-"+fn[e>>16&15|64]+fn[e>>24&255]+"-"+fn[t&63|128]+fn[t>>8&255]+"-"+fn[t>>16&255]+fn[t>>24&255]+fn[i&255]+fn[i>>8&255]+fn[i>>16&255]+fn[i>>24&255]).toLowerCase()}function nt(o,e,t){return Math.max(e,Math.min(t,o))}function vg(o,e){return(o%e+e)%e}function YE(o,e,t,i,n){return i+(o-e)*(n-i)/(t-e)}function qE(o,e,t){return o!==e?(t-o)/(e-o):0}function Jc(o,e,t){return(1-t)*o+t*e}function KE(o,e,t,i){return Jc(o,e,1-Math.exp(-t*i))}function ZE(o,e=1){return e-Math.abs(vg(o,e*2)-e)}function jE(o,e,t){return o<=e?0:o>=t?1:(o=(o-e)/(t-e),o*o*(3-2*o))}function JE(o,e,t){return o<=e?0:o>=t?1:(o=(o-e)/(t-e),o*o*o*(o*(o*6-15)+10))}function QE(o,e){return o+Math.floor(Math.random()*(e-o+1))}function e3(o,e){return o+Math.random()*(e-o)}function t3(o){return o*(.5-Math.random())}function i3(o){o!==void 0&&(a1=o);let e=a1+=1831565813;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}function n3(o){return o*jc}function s3(o){return o*oc}function r3(o){return(o&o-1)===0&&o!==0}function a3(o){return Math.pow(2,Math.ceil(Math.log(o)/Math.LN2))}function o3(o){return Math.pow(2,Math.floor(Math.log(o)/Math.LN2))}function l3(o,e,t,i,n){const s=Math.cos,r=Math.sin,a=s(t/2),l=r(t/2),c=s((e+i)/2),h=r((e+i)/2),d=s((e-i)/2),u=r((e-i)/2),f=s((i-e)/2),p=r((i-e)/2);switch(n){case"XYX":o.set(a*h,l*d,l*u,a*c);break;case"YZY":o.set(l*u,a*h,l*d,a*c);break;case"ZXZ":o.set(l*d,l*u,a*h,a*c);break;case"XZX":o.set(a*h,l*p,l*f,a*c);break;case"YXY":o.set(l*f,a*h,l*p,a*c);break;case"ZYZ":o.set(l*p,l*f,a*h,a*c);break;default:ke("MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+n)}}function zs(o,e){switch(e.constructor){case Float32Array:return o;case Uint32Array:return o/4294967295;case Uint16Array:return o/65535;case Uint8Array:return o/255;case Int32Array:return Math.max(o/2147483647,-1);case Int16Array:return Math.max(o/32767,-1);case Int8Array:return Math.max(o/127,-1);default:throw new Error("THREE.MathUtils: Invalid component type.")}}function qt(o,e){switch(e.constructor){case Float32Array:return o;case Uint32Array:return Math.round(o*4294967295);case Uint16Array:return Math.round(o*65535);case Uint8Array:return Math.round(o*255);case Int32Array:return Math.round(o*2147483647);case Int16Array:return Math.round(o*32767);case Int8Array:return Math.round(o*127);default:throw new Error("THREE.MathUtils: Invalid component type.")}}const Gk={DEG2RAD:jc,RAD2DEG:oc,generateUUID:Ws,clamp:nt,euclideanModulo:vg,mapLinear:YE,inverseLerp:qE,lerp:Jc,damp:KE,pingpong:ZE,smoothstep:jE,smootherstep:JE,randInt:QE,randFloat:e3,randFloatSpread:t3,seededRandom:i3,degToRad:n3,radToDeg:s3,isPowerOfTwo:r3,ceilPowerOfTwo:a3,floorPowerOfTwo:o3,setQuaternionFromProperEuler:l3,normalize:qt,denormalize:zs};class we{static{we.prototype.isVector2=!0}constructor(e=0,t=0){this.x=e,this.y=t}get width(){return this.x}set width(e){this.x=e}get height(){return this.y}set height(e){this.y=e}set(e,t){return this.x=e,this.y=t,this}setScalar(e){return this.x=e,this.y=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;default:throw new Error("THREE.Vector2: index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;default:throw new Error("THREE.Vector2: index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}addScalar(e){return this.x+=e,this.y+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this}subScalar(e){return this.x-=e,this.y-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this}multiply(e){return this.x*=e.x,this.y*=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}divide(e){return this.x/=e.x,this.y/=e.y,this}divideScalar(e){return this.multiplyScalar(1/e)}applyMatrix3(e){const t=this.x,i=this.y,n=e.elements;return this.x=n[0]*t+n[3]*i+n[6],this.y=n[1]*t+n[4]*i+n[7],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this}clamp(e,t){return this.x=nt(this.x,e.x,t.x),this.y=nt(this.y,e.y,t.y),this}clampScalar(e,t){return this.x=nt(this.x,e,t),this.y=nt(this.y,e,t),this}clampLength(e,t){const i=this.length();return this.divideScalar(i||1).multiplyScalar(nt(i,e,t))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(e){return this.x*e.x+this.y*e.y}cross(e){return this.x*e.y-this.y*e.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(e){const t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;const i=this.dot(e)/t;return Math.acos(nt(i,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,i=this.y-e.y;return t*t+i*i}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this}lerpVectors(e,t,i){return this.x=e.x+(t.x-e.x)*i,this.y=e.y+(t.y-e.y)*i,this}equals(e){return e.x===this.x&&e.y===this.y}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this}rotateAround(e,t){const i=Math.cos(t),n=Math.sin(t),s=this.x-e.x,r=this.y-e.y;return this.x=s*i-r*n+e.x,this.y=s*n+r*i+e.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class An{constructor(e=0,t=0,i=0,n=1){this.isQuaternion=!0,this._x=e,this._y=t,this._z=i,this._w=n}static slerpFlat(e,t,i,n,s,r,a){let l=i[n+0],c=i[n+1],h=i[n+2],d=i[n+3],u=s[r+0],f=s[r+1],p=s[r+2],g=s[r+3];if(d!==g||l!==u||c!==f||h!==p){let m=l*u+c*f+h*p+d*g;m<0&&(u=-u,f=-f,p=-p,g=-g,m=-m);let v=1-a;if(m<.9995){const b=Math.acos(m),x=Math.sin(b);v=Math.sin(v*b)/x,a=Math.sin(a*b)/x,l=l*v+u*a,c=c*v+f*a,h=h*v+p*a,d=d*v+g*a}else{l=l*v+u*a,c=c*v+f*a,h=h*v+p*a,d=d*v+g*a;const b=1/Math.sqrt(l*l+c*c+h*h+d*d);l*=b,c*=b,h*=b,d*=b}}e[t]=l,e[t+1]=c,e[t+2]=h,e[t+3]=d}static multiplyQuaternionsFlat(e,t,i,n,s,r){const a=i[n],l=i[n+1],c=i[n+2],h=i[n+3],d=s[r],u=s[r+1],f=s[r+2],p=s[r+3];return e[t]=a*p+h*d+l*f-c*u,e[t+1]=l*p+h*u+c*d-a*f,e[t+2]=c*p+h*f+a*u-l*d,e[t+3]=h*p-a*d-l*u-c*f,e}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get w(){return this._w}set w(e){this._w=e,this._onChangeCallback()}set(e,t,i,n){return this._x=e,this._y=t,this._z=i,this._w=n,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback(),this}setFromEuler(e,t=!0){const i=e._x,n=e._y,s=e._z,r=e._order,a=Math.cos,l=Math.sin,c=a(i/2),h=a(n/2),d=a(s/2),u=l(i/2),f=l(n/2),p=l(s/2);switch(r){case"XYZ":this._x=u*h*d+c*f*p,this._y=c*f*d-u*h*p,this._z=c*h*p+u*f*d,this._w=c*h*d-u*f*p;break;case"YXZ":this._x=u*h*d+c*f*p,this._y=c*f*d-u*h*p,this._z=c*h*p-u*f*d,this._w=c*h*d+u*f*p;break;case"ZXY":this._x=u*h*d-c*f*p,this._y=c*f*d+u*h*p,this._z=c*h*p+u*f*d,this._w=c*h*d-u*f*p;break;case"ZYX":this._x=u*h*d-c*f*p,this._y=c*f*d+u*h*p,this._z=c*h*p-u*f*d,this._w=c*h*d+u*f*p;break;case"YZX":this._x=u*h*d+c*f*p,this._y=c*f*d+u*h*p,this._z=c*h*p-u*f*d,this._w=c*h*d-u*f*p;break;case"XZY":this._x=u*h*d-c*f*p,this._y=c*f*d-u*h*p,this._z=c*h*p+u*f*d,this._w=c*h*d+u*f*p;break;default:ke("Quaternion: .setFromEuler() encountered an unknown order: "+r)}return t===!0&&this._onChangeCallback(),this}setFromAxisAngle(e,t){const i=t/2,n=Math.sin(i);return this._x=e.x*n,this._y=e.y*n,this._z=e.z*n,this._w=Math.cos(i),this._onChangeCallback(),this}setFromRotationMatrix(e){const t=e.elements,i=t[0],n=t[4],s=t[8],r=t[1],a=t[5],l=t[9],c=t[2],h=t[6],d=t[10],u=i+a+d;if(u>0){const f=.5/Math.sqrt(u+1);this._w=.25/f,this._x=(h-l)*f,this._y=(s-c)*f,this._z=(r-n)*f}else if(i>a&&i>d){const f=2*Math.sqrt(1+i-a-d);this._w=(h-l)/f,this._x=.25*f,this._y=(n+r)/f,this._z=(s+c)/f}else if(a>d){const f=2*Math.sqrt(1+a-i-d);this._w=(s-c)/f,this._x=(n+r)/f,this._y=.25*f,this._z=(l+h)/f}else{const f=2*Math.sqrt(1+d-i-a);this._w=(r-n)/f,this._x=(s+c)/f,this._y=(l+h)/f,this._z=.25*f}return this._onChangeCallback(),this}setFromUnitVectors(e,t){let i=e.dot(t)+1;return i<1e-8?(i=0,Math.abs(e.x)>Math.abs(e.z)?(this._x=-e.y,this._y=e.x,this._z=0,this._w=i):(this._x=0,this._y=-e.z,this._z=e.y,this._w=i)):(this._x=e.y*t.z-e.z*t.y,this._y=e.z*t.x-e.x*t.z,this._z=e.x*t.y-e.y*t.x,this._w=i),this.normalize()}angleTo(e){return 2*Math.acos(Math.abs(nt(this.dot(e),-1,1)))}rotateTowards(e,t){const i=this.angleTo(e);if(i===0)return this;const n=Math.min(1,t/i);return this.slerp(e,n),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(e){return this._x*e._x+this._y*e._y+this._z*e._z+this._w*e._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let e=this.length();return e===0?(this._x=0,this._y=0,this._z=0,this._w=1):(e=1/e,this._x=this._x*e,this._y=this._y*e,this._z=this._z*e,this._w=this._w*e),this._onChangeCallback(),this}multiply(e){return this.multiplyQuaternions(this,e)}premultiply(e){return this.multiplyQuaternions(e,this)}multiplyQuaternions(e,t){const i=e._x,n=e._y,s=e._z,r=e._w,a=t._x,l=t._y,c=t._z,h=t._w;return this._x=i*h+r*a+n*c-s*l,this._y=n*h+r*l+s*a-i*c,this._z=s*h+r*c+i*l-n*a,this._w=r*h-i*a-n*l-s*c,this._onChangeCallback(),this}slerp(e,t){let i=e._x,n=e._y,s=e._z,r=e._w,a=this.dot(e);a<0&&(i=-i,n=-n,s=-s,r=-r,a=-a);let l=1-t;if(a<.9995){const c=Math.acos(a),h=Math.sin(c);l=Math.sin(l*c)/h,t=Math.sin(t*c)/h,this._x=this._x*l+i*t,this._y=this._y*l+n*t,this._z=this._z*l+s*t,this._w=this._w*l+r*t,this._onChangeCallback()}else this._x=this._x*l+i*t,this._y=this._y*l+n*t,this._z=this._z*l+s*t,this._w=this._w*l+r*t,this.normalize();return this}slerpQuaternions(e,t,i){return this.copy(e).slerp(t,i)}random(){const e=2*Math.PI*Math.random(),t=2*Math.PI*Math.random(),i=Math.random(),n=Math.sqrt(1-i),s=Math.sqrt(i);return this.set(n*Math.sin(e),n*Math.cos(e),s*Math.sin(t),s*Math.cos(t))}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._w===this._w}fromArray(e,t=0){return this._x=e[t],this._y=e[t+1],this._z=e[t+2],this._w=e[t+3],this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._w,e}fromBufferAttribute(e,t){return this._x=e.getX(t),this._y=e.getY(t),this._z=e.getZ(t),this._w=e.getW(t),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class D{static{D.prototype.isVector3=!0}constructor(e=0,t=0,i=0){this.x=e,this.y=t,this.z=i}set(e,t,i){return i===void 0&&(i=this.z),this.x=e,this.y=t,this.z=i,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;default:throw new Error("THREE.Vector3: index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("THREE.Vector3: index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}multiplyVectors(e,t){return this.x=e.x*t.x,this.y=e.y*t.y,this.z=e.z*t.z,this}applyEuler(e){return this.applyQuaternion(o1.setFromEuler(e))}applyAxisAngle(e,t){return this.applyQuaternion(o1.setFromAxisAngle(e,t))}applyMatrix3(e){const t=this.x,i=this.y,n=this.z,s=e.elements;return this.x=s[0]*t+s[3]*i+s[6]*n,this.y=s[1]*t+s[4]*i+s[7]*n,this.z=s[2]*t+s[5]*i+s[8]*n,this}applyNormalMatrix(e){return this.applyMatrix3(e).normalize()}applyMatrix4(e){const t=this.x,i=this.y,n=this.z,s=e.elements,r=1/(s[3]*t+s[7]*i+s[11]*n+s[15]);return this.x=(s[0]*t+s[4]*i+s[8]*n+s[12])*r,this.y=(s[1]*t+s[5]*i+s[9]*n+s[13])*r,this.z=(s[2]*t+s[6]*i+s[10]*n+s[14])*r,this}applyQuaternion(e){const t=this.x,i=this.y,n=this.z,s=e.x,r=e.y,a=e.z,l=e.w,c=2*(r*n-a*i),h=2*(a*t-s*n),d=2*(s*i-r*t);return this.x=t+l*c+r*d-a*h,this.y=i+l*h+a*c-s*d,this.z=n+l*d+s*h-r*c,this}project(e){return this.applyMatrix4(e.matrixWorldInverse).applyMatrix4(e.projectionMatrix)}unproject(e){return this.applyMatrix4(e.projectionMatrixInverse).applyMatrix4(e.matrixWorld)}transformDirection(e){const t=this.x,i=this.y,n=this.z,s=e.elements;return this.x=s[0]*t+s[4]*i+s[8]*n,this.y=s[1]*t+s[5]*i+s[9]*n,this.z=s[2]*t+s[6]*i+s[10]*n,this.normalize()}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this}divideScalar(e){return this.multiplyScalar(1/e)}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this}clamp(e,t){return this.x=nt(this.x,e.x,t.x),this.y=nt(this.y,e.y,t.y),this.z=nt(this.z,e.z,t.z),this}clampScalar(e,t){return this.x=nt(this.x,e,t),this.y=nt(this.y,e,t),this.z=nt(this.z,e,t),this}clampLength(e,t){const i=this.length();return this.divideScalar(i||1).multiplyScalar(nt(i,e,t))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this}lerpVectors(e,t,i){return this.x=e.x+(t.x-e.x)*i,this.y=e.y+(t.y-e.y)*i,this.z=e.z+(t.z-e.z)*i,this}cross(e){return this.crossVectors(this,e)}crossVectors(e,t){const i=e.x,n=e.y,s=e.z,r=t.x,a=t.y,l=t.z;return this.x=n*l-s*a,this.y=s*r-i*l,this.z=i*a-n*r,this}projectOnVector(e){const t=e.lengthSq();if(t===0)return this.set(0,0,0);const i=e.dot(this)/t;return this.copy(e).multiplyScalar(i)}projectOnPlane(e){return Yf.copy(this).projectOnVector(e),this.sub(Yf)}reflect(e){return this.sub(Yf.copy(e).multiplyScalar(2*this.dot(e)))}angleTo(e){const t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;const i=this.dot(e)/t;return Math.acos(nt(i,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,i=this.y-e.y,n=this.z-e.z;return t*t+i*i+n*n}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)+Math.abs(this.z-e.z)}setFromSpherical(e){return this.setFromSphericalCoords(e.radius,e.phi,e.theta)}setFromSphericalCoords(e,t,i){const n=Math.sin(t)*e;return this.x=n*Math.sin(i),this.y=Math.cos(t)*e,this.z=n*Math.cos(i),this}setFromCylindrical(e){return this.setFromCylindricalCoords(e.radius,e.theta,e.y)}setFromCylindricalCoords(e,t,i){return this.x=e*Math.sin(t),this.y=i,this.z=e*Math.cos(t),this}setFromMatrixPosition(e){const t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this}setFromMatrixScale(e){const t=this.setFromMatrixColumn(e,0).length(),i=this.setFromMatrixColumn(e,1).length(),n=this.setFromMatrixColumn(e,2).length();return this.x=t,this.y=i,this.z=n,this}setFromMatrixColumn(e,t){return this.fromArray(e.elements,t*4)}setFromMatrix3Column(e,t){return this.fromArray(e.elements,t*3)}setFromEuler(e){return this.x=e._x,this.y=e._y,this.z=e._z,this}setFromColor(e){return this.x=e.r,this.y=e.g,this.z=e.b,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const e=Math.random()*Math.PI*2,t=Math.random()*2-1,i=Math.sqrt(1-t*t);return this.x=i*Math.cos(e),this.y=t,this.z=i*Math.sin(e),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const Yf=new D,o1=new An;class je{static{je.prototype.isMatrix3=!0}constructor(e,t,i,n,s,r,a,l,c){this.elements=[1,0,0,0,1,0,0,0,1],e!==void 0&&this.set(e,t,i,n,s,r,a,l,c)}set(e,t,i,n,s,r,a,l,c){const h=this.elements;return h[0]=e,h[1]=n,h[2]=a,h[3]=t,h[4]=s,h[5]=l,h[6]=i,h[7]=r,h[8]=c,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(e){const t=this.elements,i=e.elements;return t[0]=i[0],t[1]=i[1],t[2]=i[2],t[3]=i[3],t[4]=i[4],t[5]=i[5],t[6]=i[6],t[7]=i[7],t[8]=i[8],this}extractBasis(e,t,i){return e.setFromMatrix3Column(this,0),t.setFromMatrix3Column(this,1),i.setFromMatrix3Column(this,2),this}setFromMatrix4(e){const t=e.elements;return this.set(t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]),this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){const i=e.elements,n=t.elements,s=this.elements,r=i[0],a=i[3],l=i[6],c=i[1],h=i[4],d=i[7],u=i[2],f=i[5],p=i[8],g=n[0],m=n[3],v=n[6],b=n[1],x=n[4],y=n[7],w=n[2],S=n[5],A=n[8];return s[0]=r*g+a*b+l*w,s[3]=r*m+a*x+l*S,s[6]=r*v+a*y+l*A,s[1]=c*g+h*b+d*w,s[4]=c*m+h*x+d*S,s[7]=c*v+h*y+d*A,s[2]=u*g+f*b+p*w,s[5]=u*m+f*x+p*S,s[8]=u*v+f*y+p*A,this}multiplyScalar(e){const t=this.elements;return t[0]*=e,t[3]*=e,t[6]*=e,t[1]*=e,t[4]*=e,t[7]*=e,t[2]*=e,t[5]*=e,t[8]*=e,this}determinant(){const e=this.elements,t=e[0],i=e[1],n=e[2],s=e[3],r=e[4],a=e[5],l=e[6],c=e[7],h=e[8];return t*r*h-t*a*c-i*s*h+i*a*l+n*s*c-n*r*l}invert(){const e=this.elements,t=e[0],i=e[1],n=e[2],s=e[3],r=e[4],a=e[5],l=e[6],c=e[7],h=e[8],d=h*r-a*c,u=a*l-h*s,f=c*s-r*l,p=t*d+i*u+n*f;if(p===0)return this.set(0,0,0,0,0,0,0,0,0);const g=1/p;return e[0]=d*g,e[1]=(n*c-h*i)*g,e[2]=(a*i-n*r)*g,e[3]=u*g,e[4]=(h*t-n*l)*g,e[5]=(n*s-a*t)*g,e[6]=f*g,e[7]=(i*l-c*t)*g,e[8]=(r*t-i*s)*g,this}transpose(){let e;const t=this.elements;return e=t[1],t[1]=t[3],t[3]=e,e=t[2],t[2]=t[6],t[6]=e,e=t[5],t[5]=t[7],t[7]=e,this}getNormalMatrix(e){return this.setFromMatrix4(e).invert().transpose()}transposeIntoArray(e){const t=this.elements;return e[0]=t[0],e[1]=t[3],e[2]=t[6],e[3]=t[1],e[4]=t[4],e[5]=t[7],e[6]=t[2],e[7]=t[5],e[8]=t[8],this}setUvTransform(e,t,i,n,s,r,a){const l=Math.cos(s),c=Math.sin(s);return this.set(i*l,i*c,-i*(l*r+c*a)+r+e,-n*c,n*l,-n*(-c*r+l*a)+a+t,0,0,1),this}scale(e,t){return Hl("Matrix3: .scale() is deprecated. Use .makeScale() instead."),this.premultiply(qf.makeScale(e,t)),this}rotate(e){return Hl("Matrix3: .rotate() is deprecated. Use .makeRotation() instead."),this.premultiply(qf.makeRotation(-e)),this}translate(e,t){return Hl("Matrix3: .translate() is deprecated. Use .makeTranslation() instead."),this.premultiply(qf.makeTranslation(e,t)),this}makeTranslation(e,t){return e.isVector2?this.set(1,0,e.x,0,1,e.y,0,0,1):this.set(1,0,e,0,1,t,0,0,1),this}makeRotation(e){const t=Math.cos(e),i=Math.sin(e);return this.set(t,-i,0,i,t,0,0,0,1),this}makeScale(e,t){return this.set(e,0,0,0,t,0,0,0,1),this}equals(e){const t=this.elements,i=e.elements;for(let n=0;n<9;n++)if(t[n]!==i[n])return!1;return!0}fromArray(e,t=0){for(let i=0;i<9;i++)this.elements[i]=e[i+t];return this}toArray(e=[],t=0){const i=this.elements;return e[t]=i[0],e[t+1]=i[1],e[t+2]=i[2],e[t+3]=i[3],e[t+4]=i[4],e[t+5]=i[5],e[t+6]=i[6],e[t+7]=i[7],e[t+8]=i[8],e}clone(){return new this.constructor().fromArray(this.elements)}}const qf=new je,l1=new je().set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),c1=new je().set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);function c3(){const o={enabled:!0,workingColorSpace:Gu,spaces:{},convert:function(n,s,r){return this.enabled===!1||s===r||!s||!r||(this.spaces[s].transfer===Yt&&(n.r=Gr(n.r),n.g=Gr(n.g),n.b=Gr(n.b)),this.spaces[s].primaries!==this.spaces[r].primaries&&(n.applyMatrix3(this.spaces[s].toXYZ),n.applyMatrix3(this.spaces[r].fromXYZ)),this.spaces[r].transfer===Yt&&(n.r=Gl(n.r),n.g=Gl(n.g),n.b=Gl(n.b))),n},workingToColorSpace:function(n,s){return this.convert(n,this.workingColorSpace,s)},colorSpaceToWorking:function(n,s){return this.convert(n,s,this.workingColorSpace)},getPrimaries:function(n){return this.spaces[n].primaries},getTransfer:function(n){return n===ba?Vu:this.spaces[n].transfer},getToneMappingMode:function(n){return this.spaces[n].outputColorSpaceConfig.toneMappingMode||"standard"},getLuminanceCoefficients:function(n,s=this.workingColorSpace){return n.fromArray(this.spaces[s].luminanceCoefficients)},define:function(n){Object.assign(this.spaces,n)},_getMatrix:function(n,s,r){return n.copy(this.spaces[s].toXYZ).multiply(this.spaces[r].fromXYZ)},_getDrawingBufferColorSpace:function(n){return this.spaces[n].outputColorSpaceConfig.drawingBufferColorSpace},_getUnpackColorSpace:function(n=this.workingColorSpace){return this.spaces[n].workingColorSpaceConfig.unpackColorSpace},fromWorkingColorSpace:function(n,s){return Hl("ColorManagement: .fromWorkingColorSpace() has been renamed to .workingToColorSpace()."),o.workingToColorSpace(n,s)},toWorkingColorSpace:function(n,s){return Hl("ColorManagement: .toWorkingColorSpace() has been renamed to .colorSpaceToWorking()."),o.colorSpaceToWorking(n,s)}},e=[.64,.33,.3,.6,.15,.06],t=[.2126,.7152,.0722],i=[.3127,.329];return o.define({[Gu]:{primaries:e,whitePoint:i,transfer:Vu,toXYZ:l1,fromXYZ:c1,luminanceCoefficients:t,workingColorSpaceConfig:{unpackColorSpace:an},outputColorSpaceConfig:{drawingBufferColorSpace:an}},[an]:{primaries:e,whitePoint:i,transfer:Yt,toXYZ:l1,fromXYZ:c1,luminanceCoefficients:t,outputColorSpaceConfig:{drawingBufferColorSpace:an}}}),o}const Tt=c3();function Gr(o){return o<.04045?o*.0773993808:Math.pow(o*.9478672986+.0521327014,2.4)}function Gl(o){return o<.0031308?o*12.92:1.055*Math.pow(o,.41666)-.055}let qo;class h3{static getDataURL(e,t="image/png"){if(/^data:/i.test(e.src)||typeof HTMLCanvasElement>"u")return e.src;let i;if(e instanceof HTMLCanvasElement)i=e;else{qo===void 0&&(qo=Sh("canvas")),qo.width=e.width,qo.height=e.height;const n=qo.getContext("2d");e instanceof ImageData?n.putImageData(e,0,0):n.drawImage(e,0,0,e.width,e.height),i=qo}return i.toDataURL(t)}static sRGBToLinear(e){if(typeof HTMLImageElement<"u"&&e instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&e instanceof ImageBitmap){const t=Sh("canvas");t.width=e.width,t.height=e.height;const i=t.getContext("2d");i.drawImage(e,0,0,e.width,e.height);const n=i.getImageData(0,0,e.width,e.height),s=n.data;for(let r=0;r<s.length;r++)s[r]=Gr(s[r]/255)*255;return i.putImageData(n,0,0),t}else if(e.data){const t=e.data.slice(0);for(let i=0;i<t.length;i++)t instanceof Uint8Array||t instanceof Uint8ClampedArray?t[i]=Math.floor(Gr(t[i]/255)*255):t[i]=Gr(t[i]);return{data:t,width:e.width,height:e.height}}else return ke("ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."),e}}let d3=0;class yg{constructor(e=null){this.isSource=!0,Object.defineProperty(this,"id",{value:d3++}),this.uuid=Ws(),this.data=e,this.dataReady=!0,this.version=0}getSize(e){const t=this.data;return typeof HTMLVideoElement<"u"&&t instanceof HTMLVideoElement?e.set(t.videoWidth,t.videoHeight,0):typeof VideoFrame<"u"&&t instanceof VideoFrame?e.set(t.displayWidth,t.displayHeight,0):t!==null?e.set(t.width,t.height,t.depth||0):e.set(0,0,0),e}set needsUpdate(e){e===!0&&this.version++}toJSON(e){const t=e===void 0||typeof e=="string";if(!t&&e.images[this.uuid]!==void 0)return e.images[this.uuid];const i={uuid:this.uuid,url:""},n=this.data;if(n!==null){let s;if(Array.isArray(n)){s=[];for(let r=0,a=n.length;r<a;r++)n[r].isDataTexture?s.push(Kf(n[r].image)):s.push(Kf(n[r]))}else s=Kf(n);i.url=s}return t||(e.images[this.uuid]=i),i}}function Kf(o){return typeof HTMLImageElement<"u"&&o instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&o instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&o instanceof ImageBitmap?h3.getDataURL(o):o.data?{data:Array.from(o.data),width:o.width,height:o.height,type:o.data.constructor.name}:(ke("Texture: Unable to serialize Texture."),{})}let u3=0;const Zf=new D;class ln extends Na{constructor(e=ln.DEFAULT_IMAGE,t=ln.DEFAULT_MAPPING,i=Ti,n=Ti,s=mt,r=gr,a=Vi,l=zn,c=ln.DEFAULT_ANISOTROPY,h=ba){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:u3++}),this.uuid=Ws(),this.name="",this.source=new yg(e),this.mipmaps=[],this.mapping=t,this.channel=0,this.wrapS=i,this.wrapT=n,this.magFilter=s,this.minFilter=r,this.anisotropy=c,this.format=a,this.internalFormat=null,this.type=l,this.offset=new we(0,0),this.repeat=new we(1,1),this.center=new we(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new je,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.colorSpace=h,this.userData={},this.updateRanges=[],this.version=0,this.onUpdate=null,this.renderTarget=null,this.isRenderTargetTexture=!1,this.isArrayTexture=!!(e&&e.depth&&e.depth>1),this.pmremVersion=0,this.normalized=!1}get width(){return this.source.getSize(Zf).x}get height(){return this.source.getSize(Zf).y}get depth(){return this.source.getSize(Zf).z}get image(){return this.source.data}set image(e){this.source.data=e}updateMatrix(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y)}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}clone(){return new this.constructor().copy(this)}copy(e){return this.name=e.name,this.source=e.source,this.mipmaps=e.mipmaps.slice(0),this.mapping=e.mapping,this.channel=e.channel,this.wrapS=e.wrapS,this.wrapT=e.wrapT,this.magFilter=e.magFilter,this.minFilter=e.minFilter,this.anisotropy=e.anisotropy,this.format=e.format,this.internalFormat=e.internalFormat,this.type=e.type,this.normalized=e.normalized,this.offset.copy(e.offset),this.repeat.copy(e.repeat),this.center.copy(e.center),this.rotation=e.rotation,this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrix.copy(e.matrix),this.generateMipmaps=e.generateMipmaps,this.premultiplyAlpha=e.premultiplyAlpha,this.flipY=e.flipY,this.unpackAlignment=e.unpackAlignment,this.colorSpace=e.colorSpace,this.renderTarget=e.renderTarget,this.isRenderTargetTexture=e.isRenderTargetTexture,this.isArrayTexture=e.isArrayTexture,this.userData=JSON.parse(JSON.stringify(e.userData)),this.needsUpdate=!0,this}setValues(e){for(const t in e){const i=e[t];if(i===void 0){ke(`Texture.setValues(): parameter '${t}' has value of undefined.`);continue}const n=this[t];if(n===void 0){ke(`Texture.setValues(): property '${t}' does not exist.`);continue}n&&i&&n.isVector2&&i.isVector2||n&&i&&n.isVector3&&i.isVector3||n&&i&&n.isMatrix3&&i.isMatrix3?n.copy(i):this[t]=i}}toJSON(e){const t=e===void 0||typeof e=="string";if(!t&&e.textures[this.uuid]!==void 0)return e.textures[this.uuid];const i={metadata:{version:4.7,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,image:this.source.toJSON(e).uuid,mapping:this.mapping,channel:this.channel,repeat:[this.repeat.x,this.repeat.y],offset:[this.offset.x,this.offset.y],center:[this.center.x,this.center.y],rotation:this.rotation,wrap:[this.wrapS,this.wrapT],format:this.format,internalFormat:this.internalFormat,type:this.type,normalized:this.normalized,colorSpace:this.colorSpace,minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy,flipY:this.flipY,generateMipmaps:this.generateMipmaps,premultiplyAlpha:this.premultiplyAlpha,unpackAlignment:this.unpackAlignment};return Object.keys(this.userData).length>0&&(i.userData=this.userData),t||(e.textures[this.uuid]=i),i}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(e){if(this.mapping!==JM)return e;if(e.applyMatrix3(this.matrix),e.x<0||e.x>1)switch(this.wrapS){case No:e.x=e.x-Math.floor(e.x);break;case Ti:e.x=e.x<0?0:1;break;case P0:Math.abs(Math.floor(e.x)%2)===1?e.x=Math.ceil(e.x)-e.x:e.x=e.x-Math.floor(e.x);break}if(e.y<0||e.y>1)switch(this.wrapT){case No:e.y=e.y-Math.floor(e.y);break;case Ti:e.y=e.y<0?0:1;break;case P0:Math.abs(Math.floor(e.y)%2)===1?e.y=Math.ceil(e.y)-e.y:e.y=e.y-Math.floor(e.y);break}return this.flipY&&(e.y=1-e.y),e}set needsUpdate(e){e===!0&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(e){e===!0&&this.pmremVersion++}}ln.DEFAULT_IMAGE=null;ln.DEFAULT_MAPPING=JM;ln.DEFAULT_ANISOTROPY=1;class wt{static{wt.prototype.isVector4=!0}constructor(e=0,t=0,i=0,n=1){this.x=e,this.y=t,this.z=i,this.w=n}get width(){return this.z}set width(e){this.z=e}get height(){return this.w}set height(e){this.w=e}set(e,t,i,n){return this.x=e,this.y=t,this.z=i,this.w=n,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this.w=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setW(e){return this.w=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;case 3:this.w=t;break;default:throw new Error("THREE.Vector4: index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("THREE.Vector4: index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w!==void 0?e.w:1,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this.w+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this.w=e.w+t.w,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this.w+=e.w*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this.w-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this.w=e.w-t.w,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this.w*=e.w,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}applyMatrix4(e){const t=this.x,i=this.y,n=this.z,s=this.w,r=e.elements;return this.x=r[0]*t+r[4]*i+r[8]*n+r[12]*s,this.y=r[1]*t+r[5]*i+r[9]*n+r[13]*s,this.z=r[2]*t+r[6]*i+r[10]*n+r[14]*s,this.w=r[3]*t+r[7]*i+r[11]*n+r[15]*s,this}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this.w/=e.w,this}divideScalar(e){return this.multiplyScalar(1/e)}setAxisAngleFromQuaternion(e){this.w=2*Math.acos(e.w);const t=Math.sqrt(1-e.w*e.w);return t<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=e.x/t,this.y=e.y/t,this.z=e.z/t),this}setAxisAngleFromRotationMatrix(e){let t,i,n,s;const l=e.elements,c=l[0],h=l[4],d=l[8],u=l[1],f=l[5],p=l[9],g=l[2],m=l[6],v=l[10];if(Math.abs(h-u)<.01&&Math.abs(d-g)<.01&&Math.abs(p-m)<.01){if(Math.abs(h+u)<.1&&Math.abs(d+g)<.1&&Math.abs(p+m)<.1&&Math.abs(c+f+v-3)<.1)return this.set(1,0,0,0),this;t=Math.PI;const x=(c+1)/2,y=(f+1)/2,w=(v+1)/2,S=(h+u)/4,A=(d+g)/4,M=(p+m)/4;return x>y&&x>w?x<.01?(i=0,n=.707106781,s=.707106781):(i=Math.sqrt(x),n=S/i,s=A/i):y>w?y<.01?(i=.707106781,n=0,s=.707106781):(n=Math.sqrt(y),i=S/n,s=M/n):w<.01?(i=.707106781,n=.707106781,s=0):(s=Math.sqrt(w),i=A/s,n=M/s),this.set(i,n,s,t),this}let b=Math.sqrt((m-p)*(m-p)+(d-g)*(d-g)+(u-h)*(u-h));return Math.abs(b)<.001&&(b=1),this.x=(m-p)/b,this.y=(d-g)/b,this.z=(u-h)/b,this.w=Math.acos((c+f+v-1)/2),this}setFromMatrixPosition(e){const t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this.w=t[15],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this.w=Math.min(this.w,e.w),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this.w=Math.max(this.w,e.w),this}clamp(e,t){return this.x=nt(this.x,e.x,t.x),this.y=nt(this.y,e.y,t.y),this.z=nt(this.z,e.z,t.z),this.w=nt(this.w,e.w,t.w),this}clampScalar(e,t){return this.x=nt(this.x,e,t),this.y=nt(this.y,e,t),this.z=nt(this.z,e,t),this.w=nt(this.w,e,t),this}clampLength(e,t){const i=this.length();return this.divideScalar(i||1).multiplyScalar(nt(i,e,t))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z+this.w*e.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this.w+=(e.w-this.w)*t,this}lerpVectors(e,t,i){return this.x=e.x+(t.x-e.x)*i,this.y=e.y+(t.y-e.y)*i,this.z=e.z+(t.z-e.z)*i,this.w=e.w+(t.w-e.w)*i,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z&&e.w===this.w}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this.w=e[t+3],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e[t+3]=this.w,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this.w=e.getW(t),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}}class f3 extends Na{constructor(e=1,t=1,i={}){super(),i=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:mt,depthBuffer:!0,stencilBuffer:!1,resolveDepthBuffer:!0,resolveStencilBuffer:!0,depthTexture:null,samples:0,count:1,depth:1,multiview:!1,useArrayDepthTexture:!1},i),this.isRenderTarget=!0,this.width=e,this.height=t,this.depth=i.depth,this.scissor=new wt(0,0,e,t),this.scissorTest=!1,this.viewport=new wt(0,0,e,t),this.textures=[];const n={width:e,height:t,depth:i.depth},s=new ln(n),r=i.count;for(let a=0;a<r;a++)this.textures[a]=s.clone(),this.textures[a].isRenderTargetTexture=!0,this.textures[a].renderTarget=this;this._setTextureOptions(i),this.depthBuffer=i.depthBuffer,this.stencilBuffer=i.stencilBuffer,this.resolveDepthBuffer=i.resolveDepthBuffer,this.resolveStencilBuffer=i.resolveStencilBuffer,this._depthTexture=null,this.depthTexture=i.depthTexture,this.samples=i.samples,this.multiview=i.multiview,this.useArrayDepthTexture=i.useArrayDepthTexture}_setTextureOptions(e={}){const t={minFilter:mt,generateMipmaps:!1,flipY:!1,internalFormat:null};e.mapping!==void 0&&(t.mapping=e.mapping),e.wrapS!==void 0&&(t.wrapS=e.wrapS),e.wrapT!==void 0&&(t.wrapT=e.wrapT),e.wrapR!==void 0&&(t.wrapR=e.wrapR),e.magFilter!==void 0&&(t.magFilter=e.magFilter),e.minFilter!==void 0&&(t.minFilter=e.minFilter),e.format!==void 0&&(t.format=e.format),e.type!==void 0&&(t.type=e.type),e.anisotropy!==void 0&&(t.anisotropy=e.anisotropy),e.colorSpace!==void 0&&(t.colorSpace=e.colorSpace),e.flipY!==void 0&&(t.flipY=e.flipY),e.generateMipmaps!==void 0&&(t.generateMipmaps=e.generateMipmaps),e.internalFormat!==void 0&&(t.internalFormat=e.internalFormat);for(let i=0;i<this.textures.length;i++)this.textures[i].setValues(t)}get texture(){return this.textures[0]}set texture(e){this.textures[0]=e}set depthTexture(e){this._depthTexture!==null&&(this._depthTexture.renderTarget=null),e!==null&&(e.renderTarget=this),this._depthTexture=e}get depthTexture(){return this._depthTexture}setSize(e,t,i=1){if(this.width!==e||this.height!==t||this.depth!==i){this.width=e,this.height=t,this.depth=i;for(let n=0,s=this.textures.length;n<s;n++)this.textures[n].image.width=e,this.textures[n].image.height=t,this.textures[n].image.depth=i,this.textures[n].isData3DTexture!==!0&&(this.textures[n].isArrayTexture=this.textures[n].image.depth>1);this.dispose()}this.viewport.set(0,0,e,t),this.scissor.set(0,0,e,t)}clone(){return new this.constructor().copy(this)}copy(e){this.width=e.width,this.height=e.height,this.depth=e.depth,this.scissor.copy(e.scissor),this.scissorTest=e.scissorTest,this.viewport.copy(e.viewport),this.textures.length=0;for(let t=0,i=e.textures.length;t<i;t++){this.textures[t]=e.textures[t].clone(),this.textures[t].isRenderTargetTexture=!0,this.textures[t].renderTarget=this;const n=Object.assign({},e.textures[t].image);this.textures[t].source=new yg(n)}return this.depthBuffer=e.depthBuffer,this.stencilBuffer=e.stencilBuffer,this.resolveDepthBuffer=e.resolveDepthBuffer,this.resolveStencilBuffer=e.resolveStencilBuffer,e.depthTexture!==null&&(this.depthTexture=e.depthTexture.clone()),this.samples=e.samples,this.multiview=e.multiview,this.useArrayDepthTexture=e.useArrayDepthTexture,this}dispose(){this.dispatchEvent({type:"dispose"})}}class Mi extends f3{constructor(e=1,t=1,i={}){super(e,t,i),this.isWebGLRenderTarget=!0}}class ow extends ln{constructor(e=null,t=1,i=1,n=1){super(null),this.isDataArrayTexture=!0,this.image={data:e,width:t,height:i,depth:n},this.magFilter=Qt,this.minFilter=Qt,this.wrapR=Ti,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1,this.layerUpdates=new Set}addLayerUpdate(e){this.layerUpdates.add(e)}clearLayerUpdates(){this.layerUpdates.clear()}}class lw extends ln{constructor(e=null,t=1,i=1,n=1){super(null),this.isData3DTexture=!0,this.image={data:e,width:t,height:i,depth:n},this.magFilter=Qt,this.minFilter=Qt,this.wrapR=Ti,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}class lt{static{lt.prototype.isMatrix4=!0}constructor(e,t,i,n,s,r,a,l,c,h,d,u,f,p,g,m){this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],e!==void 0&&this.set(e,t,i,n,s,r,a,l,c,h,d,u,f,p,g,m)}set(e,t,i,n,s,r,a,l,c,h,d,u,f,p,g,m){const v=this.elements;return v[0]=e,v[4]=t,v[8]=i,v[12]=n,v[1]=s,v[5]=r,v[9]=a,v[13]=l,v[2]=c,v[6]=h,v[10]=d,v[14]=u,v[3]=f,v[7]=p,v[11]=g,v[15]=m,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return new lt().fromArray(this.elements)}copy(e){const t=this.elements,i=e.elements;return t[0]=i[0],t[1]=i[1],t[2]=i[2],t[3]=i[3],t[4]=i[4],t[5]=i[5],t[6]=i[6],t[7]=i[7],t[8]=i[8],t[9]=i[9],t[10]=i[10],t[11]=i[11],t[12]=i[12],t[13]=i[13],t[14]=i[14],t[15]=i[15],this}copyPosition(e){const t=this.elements,i=e.elements;return t[12]=i[12],t[13]=i[13],t[14]=i[14],this}setFromMatrix3(e){const t=e.elements;return this.set(t[0],t[3],t[6],0,t[1],t[4],t[7],0,t[2],t[5],t[8],0,0,0,0,1),this}extractBasis(e,t,i){return this.determinantAffine()===0?(e.set(1,0,0),t.set(0,1,0),i.set(0,0,1),this):(e.setFromMatrixColumn(this,0),t.setFromMatrixColumn(this,1),i.setFromMatrixColumn(this,2),this)}makeBasis(e,t,i){return this.set(e.x,t.x,i.x,0,e.y,t.y,i.y,0,e.z,t.z,i.z,0,0,0,0,1),this}extractRotation(e){if(e.determinantAffine()===0)return this.identity();const t=this.elements,i=e.elements,n=1/Ko.setFromMatrixColumn(e,0).length(),s=1/Ko.setFromMatrixColumn(e,1).length(),r=1/Ko.setFromMatrixColumn(e,2).length();return t[0]=i[0]*n,t[1]=i[1]*n,t[2]=i[2]*n,t[3]=0,t[4]=i[4]*s,t[5]=i[5]*s,t[6]=i[6]*s,t[7]=0,t[8]=i[8]*r,t[9]=i[9]*r,t[10]=i[10]*r,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromEuler(e){const t=this.elements,i=e.x,n=e.y,s=e.z,r=Math.cos(i),a=Math.sin(i),l=Math.cos(n),c=Math.sin(n),h=Math.cos(s),d=Math.sin(s);if(e.order==="XYZ"){const u=r*h,f=r*d,p=a*h,g=a*d;t[0]=l*h,t[4]=-l*d,t[8]=c,t[1]=f+p*c,t[5]=u-g*c,t[9]=-a*l,t[2]=g-u*c,t[6]=p+f*c,t[10]=r*l}else if(e.order==="YXZ"){const u=l*h,f=l*d,p=c*h,g=c*d;t[0]=u+g*a,t[4]=p*a-f,t[8]=r*c,t[1]=r*d,t[5]=r*h,t[9]=-a,t[2]=f*a-p,t[6]=g+u*a,t[10]=r*l}else if(e.order==="ZXY"){const u=l*h,f=l*d,p=c*h,g=c*d;t[0]=u-g*a,t[4]=-r*d,t[8]=p+f*a,t[1]=f+p*a,t[5]=r*h,t[9]=g-u*a,t[2]=-r*c,t[6]=a,t[10]=r*l}else if(e.order==="ZYX"){const u=r*h,f=r*d,p=a*h,g=a*d;t[0]=l*h,t[4]=p*c-f,t[8]=u*c+g,t[1]=l*d,t[5]=g*c+u,t[9]=f*c-p,t[2]=-c,t[6]=a*l,t[10]=r*l}else if(e.order==="YZX"){const u=r*l,f=r*c,p=a*l,g=a*c;t[0]=l*h,t[4]=g-u*d,t[8]=p*d+f,t[1]=d,t[5]=r*h,t[9]=-a*h,t[2]=-c*h,t[6]=f*d+p,t[10]=u-g*d}else if(e.order==="XZY"){const u=r*l,f=r*c,p=a*l,g=a*c;t[0]=l*h,t[4]=-d,t[8]=c*h,t[1]=u*d+g,t[5]=r*h,t[9]=f*d-p,t[2]=p*d-f,t[6]=a*h,t[10]=g*d+u}return t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromQuaternion(e){return this.compose(p3,e,m3)}lookAt(e,t,i){const n=this.elements;return is.subVectors(e,t),is.lengthSq()===0&&(is.z=1),is.normalize(),Qr.crossVectors(i,is),Qr.lengthSq()===0&&(Math.abs(i.z)===1?is.x+=1e-4:is.z+=1e-4,is.normalize(),Qr.crossVectors(i,is)),Qr.normalize(),$h.crossVectors(is,Qr),n[0]=Qr.x,n[4]=$h.x,n[8]=is.x,n[1]=Qr.y,n[5]=$h.y,n[9]=is.y,n[2]=Qr.z,n[6]=$h.z,n[10]=is.z,this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){const i=e.elements,n=t.elements,s=this.elements,r=i[0],a=i[4],l=i[8],c=i[12],h=i[1],d=i[5],u=i[9],f=i[13],p=i[2],g=i[6],m=i[10],v=i[14],b=i[3],x=i[7],y=i[11],w=i[15],S=n[0],A=n[4],M=n[8],_=n[12],I=n[1],R=n[5],L=n[9],P=n[13],O=n[2],k=n[6],F=n[10],z=n[14],V=n[3],K=n[7],q=n[11],te=n[15];return s[0]=r*S+a*I+l*O+c*V,s[4]=r*A+a*R+l*k+c*K,s[8]=r*M+a*L+l*F+c*q,s[12]=r*_+a*P+l*z+c*te,s[1]=h*S+d*I+u*O+f*V,s[5]=h*A+d*R+u*k+f*K,s[9]=h*M+d*L+u*F+f*q,s[13]=h*_+d*P+u*z+f*te,s[2]=p*S+g*I+m*O+v*V,s[6]=p*A+g*R+m*k+v*K,s[10]=p*M+g*L+m*F+v*q,s[14]=p*_+g*P+m*z+v*te,s[3]=b*S+x*I+y*O+w*V,s[7]=b*A+x*R+y*k+w*K,s[11]=b*M+x*L+y*F+w*q,s[15]=b*_+x*P+y*z+w*te,this}multiplyScalar(e){const t=this.elements;return t[0]*=e,t[4]*=e,t[8]*=e,t[12]*=e,t[1]*=e,t[5]*=e,t[9]*=e,t[13]*=e,t[2]*=e,t[6]*=e,t[10]*=e,t[14]*=e,t[3]*=e,t[7]*=e,t[11]*=e,t[15]*=e,this}determinant(){const e=this.elements,t=e[0],i=e[4],n=e[8],s=e[12],r=e[1],a=e[5],l=e[9],c=e[13],h=e[2],d=e[6],u=e[10],f=e[14],p=e[3],g=e[7],m=e[11],v=e[15],b=l*f-c*u,x=a*f-c*d,y=a*u-l*d,w=r*f-c*h,S=r*u-l*h,A=r*d-a*h;return t*(g*b-m*x+v*y)-i*(p*b-m*w+v*S)+n*(p*x-g*w+v*A)-s*(p*y-g*S+m*A)}determinantAffine(){const e=this.elements,t=e[0],i=e[4],n=e[8],s=e[1],r=e[5],a=e[9],l=e[2],c=e[6],h=e[10];return t*(r*h-a*c)-i*(s*h-a*l)+n*(s*c-r*l)}transpose(){const e=this.elements;let t;return t=e[1],e[1]=e[4],e[4]=t,t=e[2],e[2]=e[8],e[8]=t,t=e[6],e[6]=e[9],e[9]=t,t=e[3],e[3]=e[12],e[12]=t,t=e[7],e[7]=e[13],e[13]=t,t=e[11],e[11]=e[14],e[14]=t,this}setPosition(e,t,i){const n=this.elements;return e.isVector3?(n[12]=e.x,n[13]=e.y,n[14]=e.z):(n[12]=e,n[13]=t,n[14]=i),this}invert(){const e=this.elements,t=e[0],i=e[1],n=e[2],s=e[3],r=e[4],a=e[5],l=e[6],c=e[7],h=e[8],d=e[9],u=e[10],f=e[11],p=e[12],g=e[13],m=e[14],v=e[15],b=t*a-i*r,x=t*l-n*r,y=t*c-s*r,w=i*l-n*a,S=i*c-s*a,A=n*c-s*l,M=h*g-d*p,_=h*m-u*p,I=h*v-f*p,R=d*m-u*g,L=d*v-f*g,P=u*v-f*m,O=b*P-x*L+y*R+w*I-S*_+A*M;if(O===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const k=1/O;return e[0]=(a*P-l*L+c*R)*k,e[1]=(n*L-i*P-s*R)*k,e[2]=(g*A-m*S+v*w)*k,e[3]=(u*S-d*A-f*w)*k,e[4]=(l*I-r*P-c*_)*k,e[5]=(t*P-n*I+s*_)*k,e[6]=(m*y-p*A-v*x)*k,e[7]=(h*A-u*y+f*x)*k,e[8]=(r*L-a*I+c*M)*k,e[9]=(i*I-t*L-s*M)*k,e[10]=(p*S-g*y+v*b)*k,e[11]=(d*y-h*S-f*b)*k,e[12]=(a*_-r*R-l*M)*k,e[13]=(t*R-i*_+n*M)*k,e[14]=(g*x-p*w-m*b)*k,e[15]=(h*w-d*x+u*b)*k,this}scale(e){const t=this.elements,i=e.x,n=e.y,s=e.z;return t[0]*=i,t[4]*=n,t[8]*=s,t[1]*=i,t[5]*=n,t[9]*=s,t[2]*=i,t[6]*=n,t[10]*=s,t[3]*=i,t[7]*=n,t[11]*=s,this}getMaxScaleOnAxis(){const e=this.elements,t=e[0]*e[0]+e[1]*e[1]+e[2]*e[2],i=e[4]*e[4]+e[5]*e[5]+e[6]*e[6],n=e[8]*e[8]+e[9]*e[9]+e[10]*e[10];return Math.sqrt(Math.max(t,i,n))}makeTranslation(e,t,i){return e.isVector3?this.set(1,0,0,e.x,0,1,0,e.y,0,0,1,e.z,0,0,0,1):this.set(1,0,0,e,0,1,0,t,0,0,1,i,0,0,0,1),this}makeRotationX(e){const t=Math.cos(e),i=Math.sin(e);return this.set(1,0,0,0,0,t,-i,0,0,i,t,0,0,0,0,1),this}makeRotationY(e){const t=Math.cos(e),i=Math.sin(e);return this.set(t,0,i,0,0,1,0,0,-i,0,t,0,0,0,0,1),this}makeRotationZ(e){const t=Math.cos(e),i=Math.sin(e);return this.set(t,-i,0,0,i,t,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(e,t){const i=Math.cos(t),n=Math.sin(t),s=1-i,r=e.x,a=e.y,l=e.z,c=s*r,h=s*a;return this.set(c*r+i,c*a-n*l,c*l+n*a,0,c*a+n*l,h*a+i,h*l-n*r,0,c*l-n*a,h*l+n*r,s*l*l+i,0,0,0,0,1),this}makeScale(e,t,i){return this.set(e,0,0,0,0,t,0,0,0,0,i,0,0,0,0,1),this}makeShear(e,t,i,n,s,r){return this.set(1,i,s,0,e,1,r,0,t,n,1,0,0,0,0,1),this}compose(e,t,i){const n=this.elements,s=t._x,r=t._y,a=t._z,l=t._w,c=s+s,h=r+r,d=a+a,u=s*c,f=s*h,p=s*d,g=r*h,m=r*d,v=a*d,b=l*c,x=l*h,y=l*d,w=i.x,S=i.y,A=i.z;return n[0]=(1-(g+v))*w,n[1]=(f+y)*w,n[2]=(p-x)*w,n[3]=0,n[4]=(f-y)*S,n[5]=(1-(u+v))*S,n[6]=(m+b)*S,n[7]=0,n[8]=(p+x)*A,n[9]=(m-b)*A,n[10]=(1-(u+g))*A,n[11]=0,n[12]=e.x,n[13]=e.y,n[14]=e.z,n[15]=1,this}decompose(e,t,i){const n=this.elements;e.x=n[12],e.y=n[13],e.z=n[14];const s=this.determinantAffine();if(s===0)return i.set(1,1,1),t.identity(),this;let r=Ko.set(n[0],n[1],n[2]).length();const a=Ko.set(n[4],n[5],n[6]).length(),l=Ko.set(n[8],n[9],n[10]).length();s<0&&(r=-r),Is.copy(this);const c=1/r,h=1/a,d=1/l;return Is.elements[0]*=c,Is.elements[1]*=c,Is.elements[2]*=c,Is.elements[4]*=h,Is.elements[5]*=h,Is.elements[6]*=h,Is.elements[8]*=d,Is.elements[9]*=d,Is.elements[10]*=d,t.setFromRotationMatrix(Is),i.x=r,i.y=a,i.z=l,this}makePerspective(e,t,i,n,s,r,a=vr,l=!1){const c=this.elements,h=2*s/(t-e),d=2*s/(i-n),u=(t+e)/(t-e),f=(i+n)/(i-n);let p,g;if(l)p=s/(r-s),g=r*s/(r-s);else if(a===vr)p=-(r+s)/(r-s),g=-2*r*s/(r-s);else if(a===xh)p=-r/(r-s),g=-r*s/(r-s);else throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+a);return c[0]=h,c[4]=0,c[8]=u,c[12]=0,c[1]=0,c[5]=d,c[9]=f,c[13]=0,c[2]=0,c[6]=0,c[10]=p,c[14]=g,c[3]=0,c[7]=0,c[11]=-1,c[15]=0,this}makeOrthographic(e,t,i,n,s,r,a=vr,l=!1){const c=this.elements,h=2/(t-e),d=2/(i-n),u=-(t+e)/(t-e),f=-(i+n)/(i-n);let p,g;if(l)p=1/(r-s),g=r/(r-s);else if(a===vr)p=-2/(r-s),g=-(r+s)/(r-s);else if(a===xh)p=-1/(r-s),g=-s/(r-s);else throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+a);return c[0]=h,c[4]=0,c[8]=0,c[12]=u,c[1]=0,c[5]=d,c[9]=0,c[13]=f,c[2]=0,c[6]=0,c[10]=p,c[14]=g,c[3]=0,c[7]=0,c[11]=0,c[15]=1,this}equals(e){const t=this.elements,i=e.elements;for(let n=0;n<16;n++)if(t[n]!==i[n])return!1;return!0}fromArray(e,t=0){for(let i=0;i<16;i++)this.elements[i]=e[i+t];return this}toArray(e=[],t=0){const i=this.elements;return e[t]=i[0],e[t+1]=i[1],e[t+2]=i[2],e[t+3]=i[3],e[t+4]=i[4],e[t+5]=i[5],e[t+6]=i[6],e[t+7]=i[7],e[t+8]=i[8],e[t+9]=i[9],e[t+10]=i[10],e[t+11]=i[11],e[t+12]=i[12],e[t+13]=i[13],e[t+14]=i[14],e[t+15]=i[15],e}}const Ko=new D,Is=new lt,p3=new D(0,0,0),m3=new D(1,1,1),Qr=new D,$h=new D,is=new D,h1=new lt,d1=new An;class wr{constructor(e=0,t=0,i=0,n=wr.DEFAULT_ORDER){this.isEuler=!0,this._x=e,this._y=t,this._z=i,this._order=n}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get order(){return this._order}set order(e){this._order=e,this._onChangeCallback()}set(e,t,i,n=this._order){return this._x=e,this._y=t,this._z=i,this._order=n,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(e){return this._x=e._x,this._y=e._y,this._z=e._z,this._order=e._order,this._onChangeCallback(),this}setFromRotationMatrix(e,t=this._order,i=!0){const n=e.elements,s=n[0],r=n[4],a=n[8],l=n[1],c=n[5],h=n[9],d=n[2],u=n[6],f=n[10];switch(t){case"XYZ":this._y=Math.asin(nt(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-h,f),this._z=Math.atan2(-r,s)):(this._x=Math.atan2(u,c),this._z=0);break;case"YXZ":this._x=Math.asin(-nt(h,-1,1)),Math.abs(h)<.9999999?(this._y=Math.atan2(a,f),this._z=Math.atan2(l,c)):(this._y=Math.atan2(-d,s),this._z=0);break;case"ZXY":this._x=Math.asin(nt(u,-1,1)),Math.abs(u)<.9999999?(this._y=Math.atan2(-d,f),this._z=Math.atan2(-r,c)):(this._y=0,this._z=Math.atan2(l,s));break;case"ZYX":this._y=Math.asin(-nt(d,-1,1)),Math.abs(d)<.9999999?(this._x=Math.atan2(u,f),this._z=Math.atan2(l,s)):(this._x=0,this._z=Math.atan2(-r,c));break;case"YZX":this._z=Math.asin(nt(l,-1,1)),Math.abs(l)<.9999999?(this._x=Math.atan2(-h,c),this._y=Math.atan2(-d,s)):(this._x=0,this._y=Math.atan2(a,f));break;case"XZY":this._z=Math.asin(-nt(r,-1,1)),Math.abs(r)<.9999999?(this._x=Math.atan2(u,c),this._y=Math.atan2(a,s)):(this._x=Math.atan2(-h,f),this._y=0);break;default:ke("Euler: .setFromRotationMatrix() encountered an unknown order: "+t)}return this._order=t,i===!0&&this._onChangeCallback(),this}setFromQuaternion(e,t,i){return h1.makeRotationFromQuaternion(e),this.setFromRotationMatrix(h1,t,i)}setFromVector3(e,t=this._order){return this.set(e.x,e.y,e.z,t)}reorder(e){return d1.setFromEuler(this),this.setFromQuaternion(d1,e)}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._order===this._order}fromArray(e){return this._x=e[0],this._y=e[1],this._z=e[2],e[3]!==void 0&&(this._order=e[3]),this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._order,e}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}wr.DEFAULT_ORDER="XYZ";class bg{constructor(){this.mask=1}set(e){this.mask=(1<<e|0)>>>0}enable(e){this.mask|=1<<e|0}enableAll(){this.mask=-1}toggle(e){this.mask^=1<<e|0}disable(e){this.mask&=~(1<<e|0)}disableAll(){this.mask=0}test(e){return(this.mask&e.mask)!==0}isEnabled(e){return(this.mask&(1<<e|0))!==0}}let g3=0;const u1=new D,Zo=new An,_r=new lt,Yh=new D,vc=new D,v3=new D,y3=new An,f1=new D(1,0,0),p1=new D(0,1,0),m1=new D(0,0,1),g1={type:"added"},b3={type:"removed"},jo={type:"childadded",child:null},jf={type:"childremoved",child:null};class hi extends Na{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:g3++}),this.uuid=Ws(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=hi.DEFAULT_UP.clone();const e=new D,t=new wr,i=new An,n=new D(1,1,1);function s(){i.setFromEuler(t,!1)}function r(){t.setFromQuaternion(i,void 0,!1)}t._onChange(s),i._onChange(r),Object.defineProperties(this,{position:{configurable:!0,enumerable:!0,value:e},rotation:{configurable:!0,enumerable:!0,value:t},quaternion:{configurable:!0,enumerable:!0,value:i},scale:{configurable:!0,enumerable:!0,value:n},modelViewMatrix:{value:new lt},normalMatrix:{value:new je}}),this.matrix=new lt,this.matrixWorld=new lt,this.matrixAutoUpdate=hi.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=hi.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new bg,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.renderOrder=0,this.animations=[],this.customDepthMaterial=void 0,this.customDistanceMaterial=void 0,this.static=!1,this.userData={},this.pivot=null}onBeforeShadow(){}onAfterShadow(){}onBeforeRender(){}onAfterRender(){}applyMatrix4(e){this.matrixAutoUpdate&&this.updateMatrix(),this.matrix.premultiply(e),this.matrix.decompose(this.position,this.quaternion,this.scale)}applyQuaternion(e){return this.quaternion.premultiply(e),this}setRotationFromAxisAngle(e,t){this.quaternion.setFromAxisAngle(e,t)}setRotationFromEuler(e){this.quaternion.setFromEuler(e,!0)}setRotationFromMatrix(e){this.quaternion.setFromRotationMatrix(e)}setRotationFromQuaternion(e){this.quaternion.copy(e)}rotateOnAxis(e,t){return Zo.setFromAxisAngle(e,t),this.quaternion.multiply(Zo),this}rotateOnWorldAxis(e,t){return Zo.setFromAxisAngle(e,t),this.quaternion.premultiply(Zo),this}rotateX(e){return this.rotateOnAxis(f1,e)}rotateY(e){return this.rotateOnAxis(p1,e)}rotateZ(e){return this.rotateOnAxis(m1,e)}translateOnAxis(e,t){return u1.copy(e).applyQuaternion(this.quaternion),this.position.add(u1.multiplyScalar(t)),this}translateX(e){return this.translateOnAxis(f1,e)}translateY(e){return this.translateOnAxis(p1,e)}translateZ(e){return this.translateOnAxis(m1,e)}localToWorld(e){return this.updateWorldMatrix(!0,!1),e.applyMatrix4(this.matrixWorld)}worldToLocal(e){return this.updateWorldMatrix(!0,!1),e.applyMatrix4(_r.copy(this.matrixWorld).invert())}lookAt(e,t,i){e.isVector3?Yh.copy(e):Yh.set(e,t,i);const n=this.parent;this.updateWorldMatrix(!0,!1),vc.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?_r.lookAt(vc,Yh,this.up):_r.lookAt(Yh,vc,this.up),this.quaternion.setFromRotationMatrix(_r),n&&(_r.extractRotation(n.matrixWorld),Zo.setFromRotationMatrix(_r),this.quaternion.premultiply(Zo.invert()))}add(e){if(arguments.length>1){for(let t=0;t<arguments.length;t++)this.add(arguments[t]);return this}return e===this?(Ze("Object3D.add: object can't be added as a child of itself.",e),this):(e&&e.isObject3D?(e.removeFromParent(),e.parent=this,this.children.push(e),e.dispatchEvent(g1),jo.child=e,this.dispatchEvent(jo),jo.child=null):Ze("Object3D.add: object not an instance of THREE.Object3D.",e),this)}remove(e){if(arguments.length>1){for(let i=0;i<arguments.length;i++)this.remove(arguments[i]);return this}const t=this.children.indexOf(e);return t!==-1&&(e.parent=null,this.children.splice(t,1),e.dispatchEvent(b3),jf.child=e,this.dispatchEvent(jf),jf.child=null),this}removeFromParent(){const e=this.parent;return e!==null&&e.remove(this),this}clear(){return this.remove(...this.children)}attach(e){return this.updateWorldMatrix(!0,!1),_r.copy(this.matrixWorld).invert(),e.parent!==null&&(e.parent.updateWorldMatrix(!0,!1),_r.multiply(e.parent.matrixWorld)),e.applyMatrix4(_r),e.removeFromParent(),e.parent=this,this.children.push(e),e.updateWorldMatrix(!1,!0),e.dispatchEvent(g1),jo.child=e,this.dispatchEvent(jo),jo.child=null,this}getObjectById(e){return this.getObjectByProperty("id",e)}getObjectByName(e){return this.getObjectByProperty("name",e)}getObjectByProperty(e,t){if(this[e]===t)return this;for(let i=0,n=this.children.length;i<n;i++){const r=this.children[i].getObjectByProperty(e,t);if(r!==void 0)return r}}getObjectsByProperty(e,t,i=[]){this[e]===t&&i.push(this);const n=this.children;for(let s=0,r=n.length;s<r;s++)n[s].getObjectsByProperty(e,t,i);return i}getWorldPosition(e){return this.updateWorldMatrix(!0,!1),e.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(e){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(vc,e,v3),e}getWorldScale(e){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(vc,y3,e),e}getWorldDirection(e){this.updateWorldMatrix(!0,!1);const t=this.matrixWorld.elements;return e.set(t[8],t[9],t[10]).normalize()}raycast(){}traverse(e){e(this);const t=this.children;for(let i=0,n=t.length;i<n;i++)t[i].traverse(e)}traverseVisible(e){if(this.visible===!1)return;e(this);const t=this.children;for(let i=0,n=t.length;i<n;i++)t[i].traverseVisible(e)}traverseAncestors(e){const t=this.parent;t!==null&&(e(t),t.traverseAncestors(e))}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale);const e=this.pivot;if(e!==null){const t=e.x,i=e.y,n=e.z,s=this.matrix.elements;s[12]+=t-s[0]*t-s[4]*i-s[8]*n,s[13]+=i-s[1]*t-s[5]*i-s[9]*n,s[14]+=n-s[2]*t-s[6]*i-s[10]*n}this.matrixWorldNeedsUpdate=!0}updateMatrixWorld(e){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||e)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,e=!0);const t=this.children;for(let i=0,n=t.length;i<n;i++)t[i].updateMatrixWorld(e)}updateWorldMatrix(e,t,i=!1){const n=this.parent;if(e===!0&&n!==null&&n.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||i)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,i=!0),t===!0){const s=this.children;for(let r=0,a=s.length;r<a;r++)s[r].updateWorldMatrix(!1,!0,i)}}toJSON(e){const t=e===void 0||typeof e=="string",i={};t&&(e={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},i.metadata={version:4.7,type:"Object",generator:"Object3D.toJSON"});const n={};n.uuid=this.uuid,n.type=this.type,this.name!==""&&(n.name=this.name),this.castShadow===!0&&(n.castShadow=!0),this.receiveShadow===!0&&(n.receiveShadow=!0),this.visible===!1&&(n.visible=!1),this.frustumCulled===!1&&(n.frustumCulled=!1),this.renderOrder!==0&&(n.renderOrder=this.renderOrder),this.static!==!1&&(n.static=this.static),Object.keys(this.userData).length>0&&(n.userData=this.userData),n.layers=this.layers.mask,n.matrix=this.matrix.toArray(),n.up=this.up.toArray(),this.pivot!==null&&(n.pivot=this.pivot.toArray()),this.matrixAutoUpdate===!1&&(n.matrixAutoUpdate=!1),this.morphTargetDictionary!==void 0&&(n.morphTargetDictionary=Object.assign({},this.morphTargetDictionary)),this.morphTargetInfluences!==void 0&&(n.morphTargetInfluences=this.morphTargetInfluences.slice()),this.isInstancedMesh&&(n.type="InstancedMesh",n.count=this.count,n.instanceMatrix=this.instanceMatrix.toJSON(),this.instanceColor!==null&&(n.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(n.type="BatchedMesh",n.perObjectFrustumCulled=this.perObjectFrustumCulled,n.sortObjects=this.sortObjects,n.drawRanges=this._drawRanges,n.reservedRanges=this._reservedRanges,n.geometryInfo=this._geometryInfo.map(a=>({...a,boundingBox:a.boundingBox?a.boundingBox.toJSON():void 0,boundingSphere:a.boundingSphere?a.boundingSphere.toJSON():void 0})),n.instanceInfo=this._instanceInfo.map(a=>({...a})),n.availableInstanceIds=this._availableInstanceIds.slice(),n.availableGeometryIds=this._availableGeometryIds.slice(),n.nextIndexStart=this._nextIndexStart,n.nextVertexStart=this._nextVertexStart,n.geometryCount=this._geometryCount,n.maxInstanceCount=this._maxInstanceCount,n.maxVertexCount=this._maxVertexCount,n.maxIndexCount=this._maxIndexCount,n.geometryInitialized=this._geometryInitialized,n.matricesTexture=this._matricesTexture.toJSON(e),n.indirectTexture=this._indirectTexture.toJSON(e),this._colorsTexture!==null&&(n.colorsTexture=this._colorsTexture.toJSON(e)),this.boundingSphere!==null&&(n.boundingSphere=this.boundingSphere.toJSON()),this.boundingBox!==null&&(n.boundingBox=this.boundingBox.toJSON()));function s(a,l){return a[l.uuid]===void 0&&(a[l.uuid]=l.toJSON(e)),l.uuid}if(this.isScene)this.background&&(this.background.isColor?n.background=this.background.toJSON():this.background.isTexture&&(n.background=this.background.toJSON(e).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(n.environment=this.environment.toJSON(e).uuid);else if(this.isMesh||this.isLine||this.isPoints){n.geometry=s(e.geometries,this.geometry);const a=this.geometry.parameters;if(a!==void 0&&a.shapes!==void 0){const l=a.shapes;if(Array.isArray(l))for(let c=0,h=l.length;c<h;c++){const d=l[c];s(e.shapes,d)}else s(e.shapes,l)}}if(this.isSkinnedMesh&&(n.bindMode=this.bindMode,n.bindMatrix=this.bindMatrix.toArray(),this.skeleton!==void 0&&(s(e.skeletons,this.skeleton),n.skeleton=this.skeleton.uuid)),this.material!==void 0)if(Array.isArray(this.material)){const a=[];for(let l=0,c=this.material.length;l<c;l++)a.push(s(e.materials,this.material[l]));n.material=a}else n.material=s(e.materials,this.material);if(this.children.length>0){n.children=[];for(let a=0;a<this.children.length;a++)n.children.push(this.children[a].toJSON(e).object)}if(this.animations.length>0){n.animations=[];for(let a=0;a<this.animations.length;a++){const l=this.animations[a];n.animations.push(s(e.animations,l))}}if(t){const a=r(e.geometries),l=r(e.materials),c=r(e.textures),h=r(e.images),d=r(e.shapes),u=r(e.skeletons),f=r(e.animations),p=r(e.nodes);a.length>0&&(i.geometries=a),l.length>0&&(i.materials=l),c.length>0&&(i.textures=c),h.length>0&&(i.images=h),d.length>0&&(i.shapes=d),u.length>0&&(i.skeletons=u),f.length>0&&(i.animations=f),p.length>0&&(i.nodes=p)}return i.object=n,i;function r(a){const l=[];for(const c in a){const h=a[c];delete h.metadata,l.push(h)}return l}}clone(e){return new this.constructor().copy(this,e)}copy(e,t=!0){if(this.name=e.name,this.up.copy(e.up),this.position.copy(e.position),this.rotation.order=e.rotation.order,this.quaternion.copy(e.quaternion),this.scale.copy(e.scale),this.pivot=e.pivot!==null?e.pivot.clone():null,this.matrix.copy(e.matrix),this.matrixWorld.copy(e.matrixWorld),this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrixWorldAutoUpdate=e.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=e.matrixWorldNeedsUpdate,this.layers.mask=e.layers.mask,this.visible=e.visible,this.castShadow=e.castShadow,this.receiveShadow=e.receiveShadow,this.frustumCulled=e.frustumCulled,this.renderOrder=e.renderOrder,this.static=e.static,this.animations=e.animations.slice(),this.userData=JSON.parse(JSON.stringify(e.userData)),t===!0)for(let i=0;i<e.children.length;i++){const n=e.children[i];this.add(n.clone())}return this}}hi.DEFAULT_UP=new D(0,1,0);hi.DEFAULT_MATRIX_AUTO_UPDATE=!0;hi.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;class Pt extends hi{constructor(){super(),this.isGroup=!0,this.type="Group"}}const M3={type:"move"};class Jf{constructor(){this._targetRay=null,this._grip=null,this._hand=null}getHandSpace(){return this._hand===null&&(this._hand=new Pt,this._hand.matrixAutoUpdate=!1,this._hand.visible=!1,this._hand.joints={},this._hand.inputState={pinching:!1}),this._hand}getTargetRaySpace(){return this._targetRay===null&&(this._targetRay=new Pt,this._targetRay.matrixAutoUpdate=!1,this._targetRay.visible=!1,this._targetRay.hasLinearVelocity=!1,this._targetRay.linearVelocity=new D,this._targetRay.hasAngularVelocity=!1,this._targetRay.angularVelocity=new D),this._targetRay}getGripSpace(){return this._grip===null&&(this._grip=new Pt,this._grip.matrixAutoUpdate=!1,this._grip.visible=!1,this._grip.hasLinearVelocity=!1,this._grip.linearVelocity=new D,this._grip.hasAngularVelocity=!1,this._grip.angularVelocity=new D,this._grip.eventsEnabled=!1),this._grip}dispatchEvent(e){return this._targetRay!==null&&this._targetRay.dispatchEvent(e),this._grip!==null&&this._grip.dispatchEvent(e),this._hand!==null&&this._hand.dispatchEvent(e),this}connect(e){if(e&&e.hand){const t=this._hand;if(t)for(const i of e.hand.values())this._getHandJoint(t,i)}return this.dispatchEvent({type:"connected",data:e}),this}disconnect(e){return this.dispatchEvent({type:"disconnected",data:e}),this._targetRay!==null&&(this._targetRay.visible=!1),this._grip!==null&&(this._grip.visible=!1),this._hand!==null&&(this._hand.visible=!1),this}update(e,t,i){let n=null,s=null,r=null;const a=this._targetRay,l=this._grip,c=this._hand;if(e&&t.session.visibilityState!=="visible-blurred"){if(c&&e.hand){r=!0;for(const g of e.hand.values()){const m=t.getJointPose(g,i),v=this._getHandJoint(c,g);m!==null&&(v.matrix.fromArray(m.transform.matrix),v.matrix.decompose(v.position,v.rotation,v.scale),v.matrixWorldNeedsUpdate=!0,v.jointRadius=m.radius),v.visible=m!==null}const h=c.joints["index-finger-tip"],d=c.joints["thumb-tip"],u=h.position.distanceTo(d.position),f=.02,p=.005;c.inputState.pinching&&u>f+p?(c.inputState.pinching=!1,this.dispatchEvent({type:"pinchend",handedness:e.handedness,target:this})):!c.inputState.pinching&&u<=f-p&&(c.inputState.pinching=!0,this.dispatchEvent({type:"pinchstart",handedness:e.handedness,target:this}))}else l!==null&&e.gripSpace&&(s=t.getPose(e.gripSpace,i),s!==null&&(l.matrix.fromArray(s.transform.matrix),l.matrix.decompose(l.position,l.rotation,l.scale),l.matrixWorldNeedsUpdate=!0,s.linearVelocity?(l.hasLinearVelocity=!0,l.linearVelocity.copy(s.linearVelocity)):l.hasLinearVelocity=!1,s.angularVelocity?(l.hasAngularVelocity=!0,l.angularVelocity.copy(s.angularVelocity)):l.hasAngularVelocity=!1,l.eventsEnabled&&l.dispatchEvent({type:"gripUpdated",data:e,target:this})));a!==null&&(n=t.getPose(e.targetRaySpace,i),n===null&&s!==null&&(n=s),n!==null&&(a.matrix.fromArray(n.transform.matrix),a.matrix.decompose(a.position,a.rotation,a.scale),a.matrixWorldNeedsUpdate=!0,n.linearVelocity?(a.hasLinearVelocity=!0,a.linearVelocity.copy(n.linearVelocity)):a.hasLinearVelocity=!1,n.angularVelocity?(a.hasAngularVelocity=!0,a.angularVelocity.copy(n.angularVelocity)):a.hasAngularVelocity=!1,this.dispatchEvent(M3)))}return a!==null&&(a.visible=n!==null),l!==null&&(l.visible=s!==null),c!==null&&(c.visible=r!==null),this}_getHandJoint(e,t){if(e.joints[t.jointName]===void 0){const i=new Pt;i.matrixAutoUpdate=!1,i.visible=!1,e.joints[t.jointName]=i,e.add(i)}return e.joints[t.jointName]}}const cw={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074},ea={h:0,s:0,l:0},qh={h:0,s:0,l:0};function Qf(o,e,t){return t<0&&(t+=1),t>1&&(t-=1),t<1/6?o+(e-o)*6*t:t<1/2?e:t<2/3?o+(e-o)*6*(2/3-t):o}class ne{constructor(e,t,i){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(e,t,i)}set(e,t,i){if(t===void 0&&i===void 0){const n=e;n&&n.isColor?this.copy(n):typeof n=="number"?this.setHex(n):typeof n=="string"&&this.setStyle(n)}else this.setRGB(e,t,i);return this}setScalar(e){return this.r=e,this.g=e,this.b=e,this}setHex(e,t=an){return e=Math.floor(e),this.r=(e>>16&255)/255,this.g=(e>>8&255)/255,this.b=(e&255)/255,Tt.colorSpaceToWorking(this,t),this}setRGB(e,t,i,n=Tt.workingColorSpace){return this.r=e,this.g=t,this.b=i,Tt.colorSpaceToWorking(this,n),this}setHSL(e,t,i,n=Tt.workingColorSpace){if(e=vg(e,1),t=nt(t,0,1),i=nt(i,0,1),t===0)this.r=this.g=this.b=i;else{const s=i<=.5?i*(1+t):i+t-i*t,r=2*i-s;this.r=Qf(r,s,e+1/3),this.g=Qf(r,s,e),this.b=Qf(r,s,e-1/3)}return Tt.colorSpaceToWorking(this,n),this}setStyle(e,t=an){function i(s){s!==void 0&&parseFloat(s)<1&&ke("Color: Alpha component of "+e+" will be ignored.")}let n;if(n=/^(\w+)\(([^\)]*)\)/.exec(e)){let s;const r=n[1],a=n[2];switch(r){case"rgb":case"rgba":if(s=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return i(s[4]),this.setRGB(Math.min(255,parseInt(s[1],10))/255,Math.min(255,parseInt(s[2],10))/255,Math.min(255,parseInt(s[3],10))/255,t);if(s=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return i(s[4]),this.setRGB(Math.min(100,parseInt(s[1],10))/100,Math.min(100,parseInt(s[2],10))/100,Math.min(100,parseInt(s[3],10))/100,t);break;case"hsl":case"hsla":if(s=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return i(s[4]),this.setHSL(parseFloat(s[1])/360,parseFloat(s[2])/100,parseFloat(s[3])/100,t);break;default:ke("Color: Unknown color model "+e)}}else if(n=/^\#([A-Fa-f\d]+)$/.exec(e)){const s=n[1],r=s.length;if(r===3)return this.setRGB(parseInt(s.charAt(0),16)/15,parseInt(s.charAt(1),16)/15,parseInt(s.charAt(2),16)/15,t);if(r===6)return this.setHex(parseInt(s,16),t);ke("Color: Invalid hex color "+e)}else if(e&&e.length>0)return this.setColorName(e,t);return this}setColorName(e,t=an){const i=cw[e.toLowerCase()];return i!==void 0?this.setHex(i,t):ke("Color: Unknown color "+e),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(e){return this.r=e.r,this.g=e.g,this.b=e.b,this}copySRGBToLinear(e){return this.r=Gr(e.r),this.g=Gr(e.g),this.b=Gr(e.b),this}copyLinearToSRGB(e){return this.r=Gl(e.r),this.g=Gl(e.g),this.b=Gl(e.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(e=an){return Tt.workingToColorSpace(pn.copy(this),e),Math.round(nt(pn.r*255,0,255))*65536+Math.round(nt(pn.g*255,0,255))*256+Math.round(nt(pn.b*255,0,255))}getHexString(e=an){return("000000"+this.getHex(e).toString(16)).slice(-6)}getHSL(e,t=Tt.workingColorSpace){Tt.workingToColorSpace(pn.copy(this),t);const i=pn.r,n=pn.g,s=pn.b,r=Math.max(i,n,s),a=Math.min(i,n,s);let l,c;const h=(a+r)/2;if(a===r)l=0,c=0;else{const d=r-a;switch(c=h<=.5?d/(r+a):d/(2-r-a),r){case i:l=(n-s)/d+(n<s?6:0);break;case n:l=(s-i)/d+2;break;case s:l=(i-n)/d+4;break}l/=6}return e.h=l,e.s=c,e.l=h,e}getRGB(e,t=Tt.workingColorSpace){return Tt.workingToColorSpace(pn.copy(this),t),e.r=pn.r,e.g=pn.g,e.b=pn.b,e}getStyle(e=an){Tt.workingToColorSpace(pn.copy(this),e);const t=pn.r,i=pn.g,n=pn.b;return e!==an?`color(${e} ${t.toFixed(3)} ${i.toFixed(3)} ${n.toFixed(3)})`:`rgb(${Math.round(t*255)},${Math.round(i*255)},${Math.round(n*255)})`}offsetHSL(e,t,i){return this.getHSL(ea),this.setHSL(ea.h+e,ea.s+t,ea.l+i)}add(e){return this.r+=e.r,this.g+=e.g,this.b+=e.b,this}addColors(e,t){return this.r=e.r+t.r,this.g=e.g+t.g,this.b=e.b+t.b,this}addScalar(e){return this.r+=e,this.g+=e,this.b+=e,this}sub(e){return this.r=Math.max(0,this.r-e.r),this.g=Math.max(0,this.g-e.g),this.b=Math.max(0,this.b-e.b),this}multiply(e){return this.r*=e.r,this.g*=e.g,this.b*=e.b,this}multiplyScalar(e){return this.r*=e,this.g*=e,this.b*=e,this}lerp(e,t){return this.r+=(e.r-this.r)*t,this.g+=(e.g-this.g)*t,this.b+=(e.b-this.b)*t,this}lerpColors(e,t,i){return this.r=e.r+(t.r-e.r)*i,this.g=e.g+(t.g-e.g)*i,this.b=e.b+(t.b-e.b)*i,this}lerpHSL(e,t){this.getHSL(ea),e.getHSL(qh);const i=Jc(ea.h,qh.h,t),n=Jc(ea.s,qh.s,t),s=Jc(ea.l,qh.l,t);return this.setHSL(i,n,s),this}setFromVector3(e){return this.r=e.x,this.g=e.y,this.b=e.z,this}applyMatrix3(e){const t=this.r,i=this.g,n=this.b,s=e.elements;return this.r=s[0]*t+s[3]*i+s[6]*n,this.g=s[1]*t+s[4]*i+s[7]*n,this.b=s[2]*t+s[5]*i+s[8]*n,this}equals(e){return e.r===this.r&&e.g===this.g&&e.b===this.b}fromArray(e,t=0){return this.r=e[t],this.g=e[t+1],this.b=e[t+2],this}toArray(e=[],t=0){return e[t]=this.r,e[t+1]=this.g,e[t+2]=this.b,e}fromBufferAttribute(e,t){return this.r=e.getX(t),this.g=e.getY(t),this.b=e.getZ(t),this}toJSON(){return this.getHex()}*[Symbol.iterator](){yield this.r,yield this.g,yield this.b}}const pn=new ne;ne.NAMES=cw;class Mg{constructor(e,t=1,i=1e3){this.isFog=!0,this.name="",this.color=new ne(e),this.near=t,this.far=i}clone(){return new Mg(this.color,this.near,this.far)}toJSON(){return{type:"Fog",name:this.name,color:this.color.getHex(),near:this.near,far:this.far}}}class xr extends hi{constructor(){super(),this.isScene=!0,this.type="Scene",this.background=null,this.environment=null,this.fog=null,this.backgroundBlurriness=0,this.backgroundIntensity=1,this.backgroundRotation=new wr,this.environmentIntensity=1,this.environmentRotation=new wr,this.overrideMaterial=null,typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}copy(e,t){return super.copy(e,t),e.background!==null&&(this.background=e.background.clone()),e.environment!==null&&(this.environment=e.environment.clone()),e.fog!==null&&(this.fog=e.fog.clone()),this.backgroundBlurriness=e.backgroundBlurriness,this.backgroundIntensity=e.backgroundIntensity,this.backgroundRotation.copy(e.backgroundRotation),this.environmentIntensity=e.environmentIntensity,this.environmentRotation.copy(e.environmentRotation),e.overrideMaterial!==null&&(this.overrideMaterial=e.overrideMaterial.clone()),this.matrixAutoUpdate=e.matrixAutoUpdate,this}toJSON(e){const t=super.toJSON(e);return this.fog!==null&&(t.object.fog=this.fog.toJSON()),this.backgroundBlurriness>0&&(t.object.backgroundBlurriness=this.backgroundBlurriness),this.backgroundIntensity!==1&&(t.object.backgroundIntensity=this.backgroundIntensity),t.object.backgroundRotation=this.backgroundRotation.toArray(),this.environmentIntensity!==1&&(t.object.environmentIntensity=this.environmentIntensity),t.object.environmentRotation=this.environmentRotation.toArray(),t}}const Ds=new D,Tr=new D,ep=new D,Ir=new D,Jo=new D,Qo=new D,v1=new D,tp=new D,ip=new D,np=new D,sp=new wt,rp=new wt,ap=new wt;class As{constructor(e=new D,t=new D,i=new D){this.a=e,this.b=t,this.c=i}static getNormal(e,t,i,n){n.subVectors(i,t),Ds.subVectors(e,t),n.cross(Ds);const s=n.lengthSq();return s>0?n.multiplyScalar(1/Math.sqrt(s)):n.set(0,0,0)}static getBarycoord(e,t,i,n,s){Ds.subVectors(n,t),Tr.subVectors(i,t),ep.subVectors(e,t);const r=Ds.dot(Ds),a=Ds.dot(Tr),l=Ds.dot(ep),c=Tr.dot(Tr),h=Tr.dot(ep),d=r*c-a*a;if(d===0)return s.set(0,0,0),null;const u=1/d,f=(c*l-a*h)*u,p=(r*h-a*l)*u;return s.set(1-f-p,p,f)}static containsPoint(e,t,i,n){return this.getBarycoord(e,t,i,n,Ir)===null?!1:Ir.x>=0&&Ir.y>=0&&Ir.x+Ir.y<=1}static getInterpolation(e,t,i,n,s,r,a,l){return this.getBarycoord(e,t,i,n,Ir)===null?(l.x=0,l.y=0,"z"in l&&(l.z=0),"w"in l&&(l.w=0),null):(l.setScalar(0),l.addScaledVector(s,Ir.x),l.addScaledVector(r,Ir.y),l.addScaledVector(a,Ir.z),l)}static getInterpolatedAttribute(e,t,i,n,s,r){return sp.setScalar(0),rp.setScalar(0),ap.setScalar(0),sp.fromBufferAttribute(e,t),rp.fromBufferAttribute(e,i),ap.fromBufferAttribute(e,n),r.setScalar(0),r.addScaledVector(sp,s.x),r.addScaledVector(rp,s.y),r.addScaledVector(ap,s.z),r}static isFrontFacing(e,t,i,n){return Ds.subVectors(i,t),Tr.subVectors(e,t),Ds.cross(Tr).dot(n)<0}set(e,t,i){return this.a.copy(e),this.b.copy(t),this.c.copy(i),this}setFromPointsAndIndices(e,t,i,n){return this.a.copy(e[t]),this.b.copy(e[i]),this.c.copy(e[n]),this}setFromAttributeAndIndices(e,t,i,n){return this.a.fromBufferAttribute(e,t),this.b.fromBufferAttribute(e,i),this.c.fromBufferAttribute(e,n),this}clone(){return new this.constructor().copy(this)}copy(e){return this.a.copy(e.a),this.b.copy(e.b),this.c.copy(e.c),this}getArea(){return Ds.subVectors(this.c,this.b),Tr.subVectors(this.a,this.b),Ds.cross(Tr).length()*.5}getMidpoint(e){return e.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(e){return As.getNormal(this.a,this.b,this.c,e)}getPlane(e){return e.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(e,t){return As.getBarycoord(e,this.a,this.b,this.c,t)}getInterpolation(e,t,i,n,s){return As.getInterpolation(e,this.a,this.b,this.c,t,i,n,s)}containsPoint(e){return As.containsPoint(e,this.a,this.b,this.c)}isFrontFacing(e){return As.isFrontFacing(this.a,this.b,this.c,e)}intersectsBox(e){return e.intersectsTriangle(this)}closestPointToPoint(e,t){const i=this.a,n=this.b,s=this.c;let r,a;Jo.subVectors(n,i),Qo.subVectors(s,i),tp.subVectors(e,i);const l=Jo.dot(tp),c=Qo.dot(tp);if(l<=0&&c<=0)return t.copy(i);ip.subVectors(e,n);const h=Jo.dot(ip),d=Qo.dot(ip);if(h>=0&&d<=h)return t.copy(n);const u=l*d-h*c;if(u<=0&&l>=0&&h<=0)return r=l/(l-h),t.copy(i).addScaledVector(Jo,r);np.subVectors(e,s);const f=Jo.dot(np),p=Qo.dot(np);if(p>=0&&f<=p)return t.copy(s);const g=f*c-l*p;if(g<=0&&c>=0&&p<=0)return a=c/(c-p),t.copy(i).addScaledVector(Qo,a);const m=h*p-f*d;if(m<=0&&d-h>=0&&f-p>=0)return v1.subVectors(s,n),a=(d-h)/(d-h+(f-p)),t.copy(n).addScaledVector(v1,a);const v=1/(m+g+u);return r=g*v,a=u*v,t.copy(i).addScaledVector(Jo,r).addScaledVector(Qo,a)}equals(e){return e.a.equals(this.a)&&e.b.equals(this.b)&&e.c.equals(this.c)}}class on{constructor(e=new D(1/0,1/0,1/0),t=new D(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=e,this.max=t}set(e,t){return this.min.copy(e),this.max.copy(t),this}setFromArray(e){this.makeEmpty();for(let t=0,i=e.length;t<i;t+=3)this.expandByPoint(Rs.fromArray(e,t));return this}setFromBufferAttribute(e){this.makeEmpty();for(let t=0,i=e.count;t<i;t++)this.expandByPoint(Rs.fromBufferAttribute(e,t));return this}setFromPoints(e){this.makeEmpty();for(let t=0,i=e.length;t<i;t++)this.expandByPoint(e[t]);return this}setFromCenterAndSize(e,t){const i=Rs.copy(t).multiplyScalar(.5);return this.min.copy(e).sub(i),this.max.copy(e).add(i),this}setFromObject(e,t=!1){return this.makeEmpty(),this.expandByObject(e,t)}clone(){return new this.constructor().copy(this)}copy(e){return this.min.copy(e.min),this.max.copy(e.max),this}makeEmpty(){return this.min.x=this.min.y=this.min.z=1/0,this.max.x=this.max.y=this.max.z=-1/0,this}isEmpty(){return this.max.x<this.min.x||this.max.y<this.min.y||this.max.z<this.min.z}getCenter(e){return this.isEmpty()?e.set(0,0,0):e.addVectors(this.min,this.max).multiplyScalar(.5)}getSize(e){return this.isEmpty()?e.set(0,0,0):e.subVectors(this.max,this.min)}expandByPoint(e){return this.min.min(e),this.max.max(e),this}expandByVector(e){return this.min.sub(e),this.max.add(e),this}expandByScalar(e){return this.min.addScalar(-e),this.max.addScalar(e),this}expandByObject(e,t=!1){e.updateWorldMatrix(!1,!1);const i=e.geometry;if(i!==void 0){const s=i.getAttribute("position");if(t===!0&&s!==void 0&&e.isInstancedMesh!==!0)for(let r=0,a=s.count;r<a;r++)e.isMesh===!0?e.getVertexPosition(r,Rs):Rs.fromBufferAttribute(s,r),Rs.applyMatrix4(e.matrixWorld),this.expandByPoint(Rs);else e.boundingBox!==void 0?(e.boundingBox===null&&e.computeBoundingBox(),Kh.copy(e.boundingBox)):(i.boundingBox===null&&i.computeBoundingBox(),Kh.copy(i.boundingBox)),Kh.applyMatrix4(e.matrixWorld),this.union(Kh)}const n=e.children;for(let s=0,r=n.length;s<r;s++)this.expandByObject(n[s],t);return this}containsPoint(e){return e.x>=this.min.x&&e.x<=this.max.x&&e.y>=this.min.y&&e.y<=this.max.y&&e.z>=this.min.z&&e.z<=this.max.z}containsBox(e){return this.min.x<=e.min.x&&e.max.x<=this.max.x&&this.min.y<=e.min.y&&e.max.y<=this.max.y&&this.min.z<=e.min.z&&e.max.z<=this.max.z}getParameter(e,t){return t.set((e.x-this.min.x)/(this.max.x-this.min.x),(e.y-this.min.y)/(this.max.y-this.min.y),(e.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(e){return e.max.x>=this.min.x&&e.min.x<=this.max.x&&e.max.y>=this.min.y&&e.min.y<=this.max.y&&e.max.z>=this.min.z&&e.min.z<=this.max.z}intersectsSphere(e){return this.clampPoint(e.center,Rs),Rs.distanceToSquared(e.center)<=e.radius*e.radius}intersectsPlane(e){let t,i;return e.normal.x>0?(t=e.normal.x*this.min.x,i=e.normal.x*this.max.x):(t=e.normal.x*this.max.x,i=e.normal.x*this.min.x),e.normal.y>0?(t+=e.normal.y*this.min.y,i+=e.normal.y*this.max.y):(t+=e.normal.y*this.max.y,i+=e.normal.y*this.min.y),e.normal.z>0?(t+=e.normal.z*this.min.z,i+=e.normal.z*this.max.z):(t+=e.normal.z*this.max.z,i+=e.normal.z*this.min.z),t<=-e.constant&&i>=-e.constant}intersectsTriangle(e){if(this.isEmpty())return!1;this.getCenter(yc),Zh.subVectors(this.max,yc),el.subVectors(e.a,yc),tl.subVectors(e.b,yc),il.subVectors(e.c,yc),ta.subVectors(tl,el),ia.subVectors(il,tl),Ba.subVectors(el,il);let t=[0,-ta.z,ta.y,0,-ia.z,ia.y,0,-Ba.z,Ba.y,ta.z,0,-ta.x,ia.z,0,-ia.x,Ba.z,0,-Ba.x,-ta.y,ta.x,0,-ia.y,ia.x,0,-Ba.y,Ba.x,0];return!op(t,el,tl,il,Zh)||(t=[1,0,0,0,1,0,0,0,1],!op(t,el,tl,il,Zh))?!1:(jh.crossVectors(ta,ia),t=[jh.x,jh.y,jh.z],op(t,el,tl,il,Zh))}clampPoint(e,t){return t.copy(e).clamp(this.min,this.max)}distanceToPoint(e){return this.clampPoint(e,Rs).distanceTo(e)}getBoundingSphere(e){return this.isEmpty()?e.makeEmpty():(this.getCenter(e.center),e.radius=this.getSize(Rs).length()*.5),e}intersect(e){return this.min.max(e.min),this.max.min(e.max),this.isEmpty()&&this.makeEmpty(),this}union(e){return this.min.min(e.min),this.max.max(e.max),this}applyMatrix4(e){return this.isEmpty()?this:(Dr[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(e),Dr[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(e),Dr[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(e),Dr[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(e),Dr[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(e),Dr[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(e),Dr[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(e),Dr[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(e),this.setFromPoints(Dr),this)}translate(e){return this.min.add(e),this.max.add(e),this}equals(e){return e.min.equals(this.min)&&e.max.equals(this.max)}toJSON(){return{min:this.min.toArray(),max:this.max.toArray()}}fromJSON(e){return this.min.fromArray(e.min),this.max.fromArray(e.max),this}}const Dr=[new D,new D,new D,new D,new D,new D,new D,new D],Rs=new D,Kh=new on,el=new D,tl=new D,il=new D,ta=new D,ia=new D,Ba=new D,yc=new D,Zh=new D,jh=new D,za=new D;function op(o,e,t,i,n){for(let s=0,r=o.length-3;s<=r;s+=3){za.fromArray(o,s);const a=n.x*Math.abs(za.x)+n.y*Math.abs(za.y)+n.z*Math.abs(za.z),l=e.dot(za),c=t.dot(za),h=i.dot(za);if(Math.max(-Math.max(l,c,h),Math.min(l,c,h))>a)return!1}return!0}const Br=w3();function w3(){const o=new ArrayBuffer(4),e=new Float32Array(o),t=new Uint32Array(o),i=new Uint32Array(512),n=new Uint32Array(512);for(let l=0;l<256;++l){const c=l-127;c<-27?(i[l]=0,i[l|256]=32768,n[l]=24,n[l|256]=24):c<-14?(i[l]=1024>>-c-14,i[l|256]=1024>>-c-14|32768,n[l]=-c-1,n[l|256]=-c-1):c<=15?(i[l]=c+15<<10,i[l|256]=c+15<<10|32768,n[l]=13,n[l|256]=13):c<128?(i[l]=31744,i[l|256]=64512,n[l]=24,n[l|256]=24):(i[l]=31744,i[l|256]=64512,n[l]=13,n[l|256]=13)}const s=new Uint32Array(2048),r=new Uint32Array(64),a=new Uint32Array(64);for(let l=1;l<1024;++l){let c=l<<13,h=0;for(;(c&8388608)===0;)c<<=1,h-=8388608;c&=-8388609,h+=947912704,s[l]=c|h}for(let l=1024;l<2048;++l)s[l]=939524096+(l-1024<<13);for(let l=1;l<31;++l)r[l]=l<<23;r[31]=1199570944,r[32]=2147483648;for(let l=33;l<63;++l)r[l]=2147483648+(l-32<<23);r[63]=3347054592;for(let l=1;l<64;++l)l!==32&&(a[l]=1024);return{floatView:e,uint32View:t,baseTable:i,shiftTable:n,mantissaTable:s,exponentTable:r,offsetTable:a}}function x3(o){Math.abs(o)>65504&&ke("DataUtils.toHalfFloat(): Value out of range."),o=nt(o,-65504,65504),Br.floatView[0]=o;const e=Br.uint32View[0],t=e>>23&511;return Br.baseTable[t]+((e&8388607)>>Br.shiftTable[t])}function S3(o){const e=o>>10;return Br.uint32View[0]=Br.mantissaTable[Br.offsetTable[e]+(o&1023)]+Br.exponentTable[e],Br.floatView[0]}class fs{static toHalfFloat(e){return x3(e)}static fromHalfFloat(e){return S3(e)}}const Bi=new D,Jh=new we;let E3=0;class st extends Na{constructor(e,t,i=!1){if(super(),Array.isArray(e))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,Object.defineProperty(this,"id",{value:E3++}),this.name="",this.array=e,this.itemSize=t,this.count=e!==void 0?e.length/t:0,this.normalized=i,this.usage=dm,this.updateRanges=[],this.gpuType=En,this.version=0}onUploadCallback(){}set needsUpdate(e){e===!0&&this.version++}setUsage(e){return this.usage=e,this}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}copy(e){return this.name=e.name,this.array=new e.array.constructor(e.array),this.itemSize=e.itemSize,this.count=e.count,this.normalized=e.normalized,this.usage=e.usage,this.gpuType=e.gpuType,this}copyAt(e,t,i){e*=this.itemSize,i*=t.itemSize;for(let n=0,s=this.itemSize;n<s;n++)this.array[e+n]=t.array[i+n];return this}copyArray(e){return this.array.set(e),this}applyMatrix3(e){if(this.itemSize===2)for(let t=0,i=this.count;t<i;t++)Jh.fromBufferAttribute(this,t),Jh.applyMatrix3(e),this.setXY(t,Jh.x,Jh.y);else if(this.itemSize===3)for(let t=0,i=this.count;t<i;t++)Bi.fromBufferAttribute(this,t),Bi.applyMatrix3(e),this.setXYZ(t,Bi.x,Bi.y,Bi.z);return this}applyMatrix4(e){for(let t=0,i=this.count;t<i;t++)Bi.fromBufferAttribute(this,t),Bi.applyMatrix4(e),this.setXYZ(t,Bi.x,Bi.y,Bi.z);return this}applyNormalMatrix(e){for(let t=0,i=this.count;t<i;t++)Bi.fromBufferAttribute(this,t),Bi.applyNormalMatrix(e),this.setXYZ(t,Bi.x,Bi.y,Bi.z);return this}transformDirection(e){for(let t=0,i=this.count;t<i;t++)Bi.fromBufferAttribute(this,t),Bi.transformDirection(e),this.setXYZ(t,Bi.x,Bi.y,Bi.z);return this}set(e,t=0){return this.array.set(e,t),this}getComponent(e,t){let i=this.array[e*this.itemSize+t];return this.normalized&&(i=zs(i,this.array)),i}setComponent(e,t,i){return this.normalized&&(i=qt(i,this.array)),this.array[e*this.itemSize+t]=i,this}getX(e){let t=this.array[e*this.itemSize];return this.normalized&&(t=zs(t,this.array)),t}setX(e,t){return this.normalized&&(t=qt(t,this.array)),this.array[e*this.itemSize]=t,this}getY(e){let t=this.array[e*this.itemSize+1];return this.normalized&&(t=zs(t,this.array)),t}setY(e,t){return this.normalized&&(t=qt(t,this.array)),this.array[e*this.itemSize+1]=t,this}getZ(e){let t=this.array[e*this.itemSize+2];return this.normalized&&(t=zs(t,this.array)),t}setZ(e,t){return this.normalized&&(t=qt(t,this.array)),this.array[e*this.itemSize+2]=t,this}getW(e){let t=this.array[e*this.itemSize+3];return this.normalized&&(t=zs(t,this.array)),t}setW(e,t){return this.normalized&&(t=qt(t,this.array)),this.array[e*this.itemSize+3]=t,this}setXY(e,t,i){return e*=this.itemSize,this.normalized&&(t=qt(t,this.array),i=qt(i,this.array)),this.array[e+0]=t,this.array[e+1]=i,this}setXYZ(e,t,i,n){return e*=this.itemSize,this.normalized&&(t=qt(t,this.array),i=qt(i,this.array),n=qt(n,this.array)),this.array[e+0]=t,this.array[e+1]=i,this.array[e+2]=n,this}setXYZW(e,t,i,n,s){return e*=this.itemSize,this.normalized&&(t=qt(t,this.array),i=qt(i,this.array),n=qt(n,this.array),s=qt(s,this.array)),this.array[e+0]=t,this.array[e+1]=i,this.array[e+2]=n,this.array[e+3]=s,this}onUpload(e){return this.onUploadCallback=e,this}clone(){return new this.constructor(this.array,this.itemSize).copy(this)}toJSON(){const e={itemSize:this.itemSize,type:this.array.constructor.name,array:Array.from(this.array),normalized:this.normalized};return this.name!==""&&(e.name=this.name),this.usage!==dm&&(e.usage=this.usage),e}dispose(){this.dispatchEvent({type:"dispose"})}}class hw extends st{constructor(e,t,i){super(new Uint16Array(e),t,i)}}class wg extends st{constructor(e,t,i){super(new Uint32Array(e),t,i)}}class yt extends st{constructor(e,t,i){super(new Float32Array(e),t,i)}}const A3=new on,bc=new D,lp=new D;class qr{constructor(e=new D,t=-1){this.isSphere=!0,this.center=e,this.radius=t}set(e,t){return this.center.copy(e),this.radius=t,this}setFromPoints(e,t){const i=this.center;t!==void 0?i.copy(t):A3.setFromPoints(e).getCenter(i);let n=0;for(let s=0,r=e.length;s<r;s++)n=Math.max(n,i.distanceToSquared(e[s]));return this.radius=Math.sqrt(n),this}copy(e){return this.center.copy(e.center),this.radius=e.radius,this}isEmpty(){return this.radius<0}makeEmpty(){return this.center.set(0,0,0),this.radius=-1,this}containsPoint(e){return e.distanceToSquared(this.center)<=this.radius*this.radius}distanceToPoint(e){return e.distanceTo(this.center)-this.radius}intersectsSphere(e){const t=this.radius+e.radius;return e.center.distanceToSquared(this.center)<=t*t}intersectsBox(e){return e.intersectsSphere(this)}intersectsPlane(e){return Math.abs(e.distanceToPoint(this.center))<=this.radius}clampPoint(e,t){const i=this.center.distanceToSquared(e);return t.copy(e),i>this.radius*this.radius&&(t.sub(this.center).normalize(),t.multiplyScalar(this.radius).add(this.center)),t}getBoundingBox(e){return this.isEmpty()?(e.makeEmpty(),e):(e.set(this.center,this.center),e.expandByScalar(this.radius),e)}applyMatrix4(e){return this.center.applyMatrix4(e),this.radius=this.radius*e.getMaxScaleOnAxis(),this}translate(e){return this.center.add(e),this}expandByPoint(e){if(this.isEmpty())return this.center.copy(e),this.radius=0,this;bc.subVectors(e,this.center);const t=bc.lengthSq();if(t>this.radius*this.radius){const i=Math.sqrt(t),n=(i-this.radius)*.5;this.center.addScaledVector(bc,n/i),this.radius+=n}return this}union(e){return e.isEmpty()?this:this.isEmpty()?(this.copy(e),this):(this.center.equals(e.center)===!0?this.radius=Math.max(this.radius,e.radius):(lp.subVectors(e.center,this.center).setLength(e.radius),this.expandByPoint(bc.copy(e.center).add(lp)),this.expandByPoint(bc.copy(e.center).sub(lp))),this)}equals(e){return e.center.equals(this.center)&&e.radius===this.radius}clone(){return new this.constructor().copy(this)}toJSON(){return{radius:this.radius,center:this.center.toArray()}}fromJSON(e){return this.radius=e.radius,this.center.fromArray(e.center),this}}let _3=0;const ys=new lt,cp=new hi,nl=new D,ns=new on,Mc=new on,en=new D;class ot extends Na{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:_3++}),this.uuid=Ws(),this.name="",this.type="BufferGeometry",this.index=null,this.indirect=null,this.indirectOffset=0,this.attributes={},this.morphAttributes={},this.morphTargetsRelative=!1,this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.drawRange={start:0,count:1/0},this.userData={},this._transformed=!1}getIndex(){return this.index}setIndex(e){return Array.isArray(e)?this.index=new(GE(e)?wg:hw)(e,1):this.index=e,this}setIndirect(e,t=0){return this.indirect=e,this.indirectOffset=t,this}getIndirect(){return this.indirect}getAttribute(e){return this.attributes[e]}setAttribute(e,t){return this.attributes[e]=t,this}deleteAttribute(e){return delete this.attributes[e],this}hasAttribute(e){return this.attributes[e]!==void 0}addGroup(e,t,i=0){this.groups.push({start:e,count:t,materialIndex:i})}clearGroups(){this.groups=[]}setDrawRange(e,t){this.drawRange.start=e,this.drawRange.count=t}applyMatrix4(e){const t=this.attributes.position;t!==void 0&&(t.applyMatrix4(e),t.needsUpdate=!0);const i=this.attributes.normal;if(i!==void 0){const s=new je().getNormalMatrix(e);i.applyNormalMatrix(s),i.needsUpdate=!0}const n=this.attributes.tangent;return n!==void 0&&(n.transformDirection(e),n.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this._transformed=!0,this}applyQuaternion(e){return ys.makeRotationFromQuaternion(e),this.applyMatrix4(ys),this}rotateX(e){return ys.makeRotationX(e),this.applyMatrix4(ys),this}rotateY(e){return ys.makeRotationY(e),this.applyMatrix4(ys),this}rotateZ(e){return ys.makeRotationZ(e),this.applyMatrix4(ys),this}translate(e,t,i){return ys.makeTranslation(e,t,i),this.applyMatrix4(ys),this}scale(e,t,i){return ys.makeScale(e,t,i),this.applyMatrix4(ys),this}lookAt(e){return cp.lookAt(e),cp.updateMatrix(),this.applyMatrix4(cp.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(nl).negate(),this.translate(nl.x,nl.y,nl.z),this}setFromPoints(e){const t=this.getAttribute("position");if(t===void 0){const i=[];for(let n=0,s=e.length;n<s;n++){const r=e[n];i.push(r.x,r.y,r.z||0)}this.setAttribute("position",new yt(i,3))}else{const i=Math.min(e.length,t.count);for(let n=0;n<i;n++){const s=e[n];t.setXYZ(n,s.x,s.y,s.z||0)}e.length>t.count&&ke("BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry."),t.needsUpdate=!0}return this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new on);const e=this.attributes.position,t=this.morphAttributes.position;if(e&&e.isGLBufferAttribute){Ze("BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),this.boundingBox.set(new D(-1/0,-1/0,-1/0),new D(1/0,1/0,1/0));return}if(e!==void 0){if(this.boundingBox.setFromBufferAttribute(e),t)for(let i=0,n=t.length;i<n;i++){const s=t[i];ns.setFromBufferAttribute(s),this.morphTargetsRelative?(en.addVectors(this.boundingBox.min,ns.min),this.boundingBox.expandByPoint(en),en.addVectors(this.boundingBox.max,ns.max),this.boundingBox.expandByPoint(en)):(this.boundingBox.expandByPoint(ns.min),this.boundingBox.expandByPoint(ns.max))}}else this.boundingBox.makeEmpty();(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z))&&Ze('BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.',this)}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new qr);const e=this.attributes.position,t=this.morphAttributes.position;if(e&&e.isGLBufferAttribute){Ze("BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.",this),this.boundingSphere.set(new D,1/0);return}if(e){const i=this.boundingSphere.center;if(ns.setFromBufferAttribute(e),t)for(let s=0,r=t.length;s<r;s++){const a=t[s];Mc.setFromBufferAttribute(a),this.morphTargetsRelative?(en.addVectors(ns.min,Mc.min),ns.expandByPoint(en),en.addVectors(ns.max,Mc.max),ns.expandByPoint(en)):(ns.expandByPoint(Mc.min),ns.expandByPoint(Mc.max))}ns.getCenter(i);let n=0;for(let s=0,r=e.count;s<r;s++)en.fromBufferAttribute(e,s),n=Math.max(n,i.distanceToSquared(en));if(t)for(let s=0,r=t.length;s<r;s++){const a=t[s],l=this.morphTargetsRelative;for(let c=0,h=a.count;c<h;c++)en.fromBufferAttribute(a,c),l&&(nl.fromBufferAttribute(e,c),en.add(nl)),n=Math.max(n,i.distanceToSquared(en))}this.boundingSphere.radius=Math.sqrt(n),isNaN(this.boundingSphere.radius)&&Ze('BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',this)}}computeTangents(){const e=this.index,t=this.attributes;if(e===null||t.position===void 0||t.normal===void 0||t.uv===void 0){Ze("BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)");return}const i=t.position,n=t.normal,s=t.uv;let r=this.getAttribute("tangent");(r===void 0||r.count!==i.count)&&(r=new st(new Float32Array(4*i.count),4),this.setAttribute("tangent",r));const a=[],l=[];for(let M=0;M<i.count;M++)a[M]=new D,l[M]=new D;const c=new D,h=new D,d=new D,u=new we,f=new we,p=new we,g=new D,m=new D;function v(M,_,I){c.fromBufferAttribute(i,M),h.fromBufferAttribute(i,_),d.fromBufferAttribute(i,I),u.fromBufferAttribute(s,M),f.fromBufferAttribute(s,_),p.fromBufferAttribute(s,I),h.sub(c),d.sub(c),f.sub(u),p.sub(u);const R=1/(f.x*p.y-p.x*f.y);isFinite(R)&&(g.copy(h).multiplyScalar(p.y).addScaledVector(d,-f.y).multiplyScalar(R),m.copy(d).multiplyScalar(f.x).addScaledVector(h,-p.x).multiplyScalar(R),a[M].add(g),a[_].add(g),a[I].add(g),l[M].add(m),l[_].add(m),l[I].add(m))}let b=this.groups;b.length===0&&(b=[{start:0,count:e.count}]);for(let M=0,_=b.length;M<_;++M){const I=b[M],R=I.start,L=I.count;for(let P=R,O=R+L;P<O;P+=3)v(e.getX(P+0),e.getX(P+1),e.getX(P+2))}const x=new D,y=new D,w=new D,S=new D;function A(M){w.fromBufferAttribute(n,M),S.copy(w);const _=a[M];x.copy(_),x.sub(w.multiplyScalar(w.dot(_))).normalize(),y.crossVectors(S,_);const R=y.dot(l[M])<0?-1:1;r.setXYZW(M,x.x,x.y,x.z,R)}for(let M=0,_=b.length;M<_;++M){const I=b[M],R=I.start,L=I.count;for(let P=R,O=R+L;P<O;P+=3)A(e.getX(P+0)),A(e.getX(P+1)),A(e.getX(P+2))}this._transformed=!0}computeVertexNormals(){const e=this.index,t=this.getAttribute("position");if(t!==void 0){let i=this.getAttribute("normal");if(i===void 0||i.count!==t.count)i=new st(new Float32Array(t.count*3),3),this.setAttribute("normal",i);else for(let u=0,f=i.count;u<f;u++)i.setXYZ(u,0,0,0);const n=new D,s=new D,r=new D,a=new D,l=new D,c=new D,h=new D,d=new D;if(e)for(let u=0,f=e.count;u<f;u+=3){const p=e.getX(u+0),g=e.getX(u+1),m=e.getX(u+2);n.fromBufferAttribute(t,p),s.fromBufferAttribute(t,g),r.fromBufferAttribute(t,m),h.subVectors(r,s),d.subVectors(n,s),h.cross(d),a.fromBufferAttribute(i,p),l.fromBufferAttribute(i,g),c.fromBufferAttribute(i,m),a.add(h),l.add(h),c.add(h),i.setXYZ(p,a.x,a.y,a.z),i.setXYZ(g,l.x,l.y,l.z),i.setXYZ(m,c.x,c.y,c.z)}else for(let u=0,f=t.count;u<f;u+=3)n.fromBufferAttribute(t,u+0),s.fromBufferAttribute(t,u+1),r.fromBufferAttribute(t,u+2),h.subVectors(r,s),d.subVectors(n,s),h.cross(d),i.setXYZ(u+0,h.x,h.y,h.z),i.setXYZ(u+1,h.x,h.y,h.z),i.setXYZ(u+2,h.x,h.y,h.z);this.normalizeNormals(),i.needsUpdate=!0}}normalizeNormals(){const e=this.attributes.normal;for(let t=0,i=e.count;t<i;t++)en.fromBufferAttribute(e,t),en.normalize(),e.setXYZ(t,en.x,en.y,en.z)}toNonIndexed(){function e(a,l){const c=a.array,h=a.itemSize,d=a.normalized,u=new c.constructor(l.length*h);let f=0,p=0;for(let g=0,m=l.length;g<m;g++){a.isInterleavedBufferAttribute?f=l[g]*a.data.stride+a.offset:f=l[g]*h;for(let v=0;v<h;v++)u[p++]=c[f++]}return new st(u,h,d)}if(this.index===null)return ke("BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."),this;const t=new ot,i=this.index.array,n=this.attributes;for(const a in n){const l=n[a],c=e(l,i);t.setAttribute(a,c)}const s=this.morphAttributes;for(const a in s){const l=[],c=s[a];for(let h=0,d=c.length;h<d;h++){const u=c[h],f=e(u,i);l.push(f)}t.morphAttributes[a]=l}t.morphTargetsRelative=this.morphTargetsRelative;const r=this.groups;for(let a=0,l=r.length;a<l;a++){const c=r[a];t.addGroup(c.start,c.count,c.materialIndex)}return t}toJSON(){const e={metadata:{version:4.7,type:"BufferGeometry",generator:"BufferGeometry.toJSON"}};if(e.uuid=this.uuid,e.type=this.parameters!==void 0&&this._transformed===!0?"BufferGeometry":this.type,this.name!==""&&(e.name=this.name),Object.keys(this.userData).length>0&&(e.userData=this.userData),this.parameters!==void 0&&this._transformed!==!0){const l=this.parameters;for(const c in l)l[c]!==void 0&&(e[c]=l[c]);return e}e.data={attributes:{}};const t=this.index;t!==null&&(e.data.index={type:t.array.constructor.name,array:Array.prototype.slice.call(t.array)});const i=this.attributes;for(const l in i){const c=i[l];e.data.attributes[l]=c.toJSON(e.data)}const n={};let s=!1;for(const l in this.morphAttributes){const c=this.morphAttributes[l],h=[];for(let d=0,u=c.length;d<u;d++){const f=c[d];h.push(f.toJSON(e.data))}h.length>0&&(n[l]=h,s=!0)}s&&(e.data.morphAttributes=n,e.data.morphTargetsRelative=this.morphTargetsRelative);const r=this.groups;r.length>0&&(e.data.groups=JSON.parse(JSON.stringify(r)));const a=this.boundingSphere;return a!==null&&(e.data.boundingSphere=a.toJSON()),e}clone(){return new this.constructor().copy(this)}copy(e){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const t={};this.name=e.name;const i=e.index;i!==null&&this.setIndex(i.clone());const n=e.attributes;for(const c in n){const h=n[c];this.setAttribute(c,h.clone(t))}const s=e.morphAttributes;for(const c in s){const h=[],d=s[c];for(let u=0,f=d.length;u<f;u++)h.push(d[u].clone(t));this.morphAttributes[c]=h}this.morphTargetsRelative=e.morphTargetsRelative;const r=e.groups;for(let c=0,h=r.length;c<h;c++){const d=r[c];this.addGroup(d.start,d.count,d.materialIndex)}const a=e.boundingBox;a!==null&&(this.boundingBox=a.clone());const l=e.boundingSphere;return l!==null&&(this.boundingSphere=l.clone()),this.drawRange.start=e.drawRange.start,this.drawRange.count=e.drawRange.count,this.userData=e.userData,this._transformed=e._transformed,this}dispose(){this.dispatchEvent({type:"dispose"})}}class dw{constructor(e,t){this.isInterleavedBuffer=!0,this.array=e,this.stride=t,this.count=e!==void 0?e.length/t:0,this.usage=dm,this.updateRanges=[],this.version=0,this.uuid=Ws()}onUploadCallback(){}set needsUpdate(e){e===!0&&this.version++}setUsage(e){return this.usage=e,this}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}copy(e){return this.array=new e.array.constructor(e.array),this.count=e.count,this.stride=e.stride,this.usage=e.usage,this}copyAt(e,t,i){e*=this.stride,i*=t.stride;for(let n=0,s=this.stride;n<s;n++)this.array[e+n]=t.array[i+n];return this}set(e,t=0){return this.array.set(e,t),this}clone(e){e.arrayBuffers===void 0&&(e.arrayBuffers={}),this.array.buffer._uuid===void 0&&(this.array.buffer._uuid=Ws()),e.arrayBuffers[this.array.buffer._uuid]===void 0&&(e.arrayBuffers[this.array.buffer._uuid]=this.array.slice(0).buffer);const t=new this.array.constructor(e.arrayBuffers[this.array.buffer._uuid]),i=new this.constructor(t,this.stride);return i.setUsage(this.usage),i}onUpload(e){return this.onUploadCallback=e,this}toJSON(e){return e.arrayBuffers===void 0&&(e.arrayBuffers={}),this.array.buffer._uuid===void 0&&(this.array.buffer._uuid=Ws()),e.arrayBuffers[this.array.buffer._uuid]===void 0&&(e.arrayBuffers[this.array.buffer._uuid]=Array.from(new Uint32Array(this.array.buffer))),{uuid:this.uuid,buffer:this.array.buffer._uuid,type:this.array.constructor.name,stride:this.stride}}}const _n=new D;class $u{constructor(e,t,i,n=!1){this.isInterleavedBufferAttribute=!0,this.name="",this.data=e,this.itemSize=t,this.offset=i,this.normalized=n}get count(){return this.data.count}get array(){return this.data.array}set needsUpdate(e){this.data.needsUpdate=e}applyMatrix4(e){for(let t=0,i=this.data.count;t<i;t++)_n.fromBufferAttribute(this,t),_n.applyMatrix4(e),this.setXYZ(t,_n.x,_n.y,_n.z);return this}applyNormalMatrix(e){for(let t=0,i=this.count;t<i;t++)_n.fromBufferAttribute(this,t),_n.applyNormalMatrix(e),this.setXYZ(t,_n.x,_n.y,_n.z);return this}transformDirection(e){for(let t=0,i=this.count;t<i;t++)_n.fromBufferAttribute(this,t),_n.transformDirection(e),this.setXYZ(t,_n.x,_n.y,_n.z);return this}getComponent(e,t){let i=this.array[e*this.data.stride+this.offset+t];return this.normalized&&(i=zs(i,this.array)),i}setComponent(e,t,i){return this.normalized&&(i=qt(i,this.array)),this.data.array[e*this.data.stride+this.offset+t]=i,this}setX(e,t){return this.normalized&&(t=qt(t,this.array)),this.data.array[e*this.data.stride+this.offset]=t,this}setY(e,t){return this.normalized&&(t=qt(t,this.array)),this.data.array[e*this.data.stride+this.offset+1]=t,this}setZ(e,t){return this.normalized&&(t=qt(t,this.array)),this.data.array[e*this.data.stride+this.offset+2]=t,this}setW(e,t){return this.normalized&&(t=qt(t,this.array)),this.data.array[e*this.data.stride+this.offset+3]=t,this}getX(e){let t=this.data.array[e*this.data.stride+this.offset];return this.normalized&&(t=zs(t,this.array)),t}getY(e){let t=this.data.array[e*this.data.stride+this.offset+1];return this.normalized&&(t=zs(t,this.array)),t}getZ(e){let t=this.data.array[e*this.data.stride+this.offset+2];return this.normalized&&(t=zs(t,this.array)),t}getW(e){let t=this.data.array[e*this.data.stride+this.offset+3];return this.normalized&&(t=zs(t,this.array)),t}setXY(e,t,i){return e=e*this.data.stride+this.offset,this.normalized&&(t=qt(t,this.array),i=qt(i,this.array)),this.data.array[e+0]=t,this.data.array[e+1]=i,this}setXYZ(e,t,i,n){return e=e*this.data.stride+this.offset,this.normalized&&(t=qt(t,this.array),i=qt(i,this.array),n=qt(n,this.array)),this.data.array[e+0]=t,this.data.array[e+1]=i,this.data.array[e+2]=n,this}setXYZW(e,t,i,n,s){return e=e*this.data.stride+this.offset,this.normalized&&(t=qt(t,this.array),i=qt(i,this.array),n=qt(n,this.array),s=qt(s,this.array)),this.data.array[e+0]=t,this.data.array[e+1]=i,this.data.array[e+2]=n,this.data.array[e+3]=s,this}clone(e){if(e===void 0){Xu("InterleavedBufferAttribute.clone(): Cloning an interleaved buffer attribute will de-interleave buffer data.");const t=[];for(let i=0;i<this.count;i++){const n=i*this.data.stride+this.offset;for(let s=0;s<this.itemSize;s++)t.push(this.data.array[n+s])}return new st(new this.array.constructor(t),this.itemSize,this.normalized)}else return e.interleavedBuffers===void 0&&(e.interleavedBuffers={}),e.interleavedBuffers[this.data.uuid]===void 0&&(e.interleavedBuffers[this.data.uuid]=this.data.clone(e)),new $u(e.interleavedBuffers[this.data.uuid],this.itemSize,this.offset,this.normalized)}toJSON(e){if(e===void 0){Xu("InterleavedBufferAttribute.toJSON(): Serializing an interleaved buffer attribute will de-interleave buffer data.");const t=[];for(let i=0;i<this.count;i++){const n=i*this.data.stride+this.offset;for(let s=0;s<this.itemSize;s++)t.push(this.data.array[n+s])}return{itemSize:this.itemSize,type:this.array.constructor.name,array:t,normalized:this.normalized}}else return e.interleavedBuffers===void 0&&(e.interleavedBuffers={}),e.interleavedBuffers[this.data.uuid]===void 0&&(e.interleavedBuffers[this.data.uuid]=this.data.toJSON(e)),{isInterleavedBufferAttribute:!0,itemSize:this.itemSize,data:this.data.uuid,offset:this.offset,normalized:this.normalized}}}let T3=0;class Ar extends Na{constructor(){super(),this.isMaterial=!0,Object.defineProperty(this,"id",{value:T3++}),this.uuid=Ws(),this.name="",this.type="Material",this.blending=Ia,this.side=Pa,this.vertexColors=!1,this.opacity=1,this.transparent=!1,this.alphaHash=!1,this.blendSrc=A0,this.blendDst=bh,this.blendEquation=eo,this.blendSrcAlpha=null,this.blendDstAlpha=null,this.blendEquationAlpha=null,this.blendColor=new ne(0,0,0),this.blendAlpha=0,this.depthFunc=sc,this.depthTest=!0,this.depthWrite=!0,this.stencilWriteMask=255,this.stencilFunc=s1,this.stencilRef=0,this.stencilFuncMask=255,this.stencilFail=Yo,this.stencilZFail=Yo,this.stencilZPass=Yo,this.stencilWrite=!1,this.clippingPlanes=null,this.clipIntersection=!1,this.clipShadows=!1,this.shadowSide=null,this.colorWrite=!0,this.precision=null,this.polygonOffset=!1,this.polygonOffsetFactor=0,this.polygonOffsetUnits=0,this.dithering=!1,this.alphaToCoverage=!1,this.premultipliedAlpha=!1,this.forceSinglePass=!1,this.allowOverride=!0,this.visible=!0,this.toneMapped=!0,this.userData={},this.version=0,this._alphaTest=0}get alphaTest(){return this._alphaTest}set alphaTest(e){this._alphaTest>0!=e>0&&this.version++,this._alphaTest=e}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(e){if(e!==void 0)for(const t in e){const i=e[t];if(i===void 0){ke(`Material: parameter '${t}' has value of undefined.`);continue}const n=this[t];if(n===void 0){ke(`Material: '${t}' is not a property of THREE.${this.type}.`);continue}n&&n.isColor?n.set(i):n&&n.isVector2&&i&&i.isVector2||n&&n.isEuler&&i&&i.isEuler||n&&n.isVector3&&i&&i.isVector3?n.copy(i):this[t]=i}}toJSON(e){const t=e===void 0||typeof e=="string";t&&(e={textures:{},images:{}});const i={metadata:{version:4.7,type:"Material",generator:"Material.toJSON"}};i.uuid=this.uuid,i.type=this.type,this.name!==""&&(i.name=this.name),this.color&&this.color.isColor&&(i.color=this.color.getHex()),this.roughness!==void 0&&(i.roughness=this.roughness),this.metalness!==void 0&&(i.metalness=this.metalness),this.sheen!==void 0&&(i.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(i.sheenColor=this.sheenColor.getHex()),this.sheenRoughness!==void 0&&(i.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(i.emissive=this.emissive.getHex()),this.emissiveIntensity!==void 0&&this.emissiveIntensity!==1&&(i.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(i.specular=this.specular.getHex()),this.specularIntensity!==void 0&&(i.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(i.specularColor=this.specularColor.getHex()),this.shininess!==void 0&&(i.shininess=this.shininess),this.clearcoat!==void 0&&(i.clearcoat=this.clearcoat),this.clearcoatRoughness!==void 0&&(i.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(i.clearcoatMap=this.clearcoatMap.toJSON(e).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(i.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(e).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(i.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(e).uuid,i.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),this.sheenColorMap&&this.sheenColorMap.isTexture&&(i.sheenColorMap=this.sheenColorMap.toJSON(e).uuid),this.sheenRoughnessMap&&this.sheenRoughnessMap.isTexture&&(i.sheenRoughnessMap=this.sheenRoughnessMap.toJSON(e).uuid),this.dispersion!==void 0&&(i.dispersion=this.dispersion),this.iridescence!==void 0&&(i.iridescence=this.iridescence),this.iridescenceIOR!==void 0&&(i.iridescenceIOR=this.iridescenceIOR),this.iridescenceThicknessRange!==void 0&&(i.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(i.iridescenceMap=this.iridescenceMap.toJSON(e).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(i.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(e).uuid),this.anisotropy!==void 0&&(i.anisotropy=this.anisotropy),this.anisotropyRotation!==void 0&&(i.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(i.anisotropyMap=this.anisotropyMap.toJSON(e).uuid),this.map&&this.map.isTexture&&(i.map=this.map.toJSON(e).uuid),this.matcap&&this.matcap.isTexture&&(i.matcap=this.matcap.toJSON(e).uuid),this.alphaMap&&this.alphaMap.isTexture&&(i.alphaMap=this.alphaMap.toJSON(e).uuid),this.lightMap&&this.lightMap.isTexture&&(i.lightMap=this.lightMap.toJSON(e).uuid,i.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(i.aoMap=this.aoMap.toJSON(e).uuid,i.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(i.bumpMap=this.bumpMap.toJSON(e).uuid,i.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(i.normalMap=this.normalMap.toJSON(e).uuid,i.normalMapType=this.normalMapType,i.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(i.displacementMap=this.displacementMap.toJSON(e).uuid,i.displacementScale=this.displacementScale,i.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(i.roughnessMap=this.roughnessMap.toJSON(e).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(i.metalnessMap=this.metalnessMap.toJSON(e).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(i.emissiveMap=this.emissiveMap.toJSON(e).uuid),this.specularMap&&this.specularMap.isTexture&&(i.specularMap=this.specularMap.toJSON(e).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(i.specularIntensityMap=this.specularIntensityMap.toJSON(e).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(i.specularColorMap=this.specularColorMap.toJSON(e).uuid),this.envMap&&this.envMap.isTexture&&(i.envMap=this.envMap.toJSON(e).uuid,this.combine!==void 0&&(i.combine=this.combine)),this.envMapRotation!==void 0&&(i.envMapRotation=this.envMapRotation.toArray()),this.envMapIntensity!==void 0&&(i.envMapIntensity=this.envMapIntensity),this.reflectivity!==void 0&&(i.reflectivity=this.reflectivity),this.refractionRatio!==void 0&&(i.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(i.gradientMap=this.gradientMap.toJSON(e).uuid),this.transmission!==void 0&&(i.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(i.transmissionMap=this.transmissionMap.toJSON(e).uuid),this.thickness!==void 0&&(i.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(i.thicknessMap=this.thicknessMap.toJSON(e).uuid),this.attenuationDistance!==void 0&&this.attenuationDistance!==1/0&&(i.attenuationDistance=this.attenuationDistance),this.attenuationColor!==void 0&&(i.attenuationColor=this.attenuationColor.getHex()),this.size!==void 0&&(i.size=this.size),this.shadowSide!==null&&(i.shadowSide=this.shadowSide),this.sizeAttenuation!==void 0&&(i.sizeAttenuation=this.sizeAttenuation),this.blending!==Ia&&(i.blending=this.blending),this.side!==Pa&&(i.side=this.side),this.vertexColors===!0&&(i.vertexColors=!0),this.opacity<1&&(i.opacity=this.opacity),this.transparent===!0&&(i.transparent=!0),this.blendSrc!==A0&&(i.blendSrc=this.blendSrc),this.blendDst!==bh&&(i.blendDst=this.blendDst),this.blendEquation!==eo&&(i.blendEquation=this.blendEquation),this.blendSrcAlpha!==null&&(i.blendSrcAlpha=this.blendSrcAlpha),this.blendDstAlpha!==null&&(i.blendDstAlpha=this.blendDstAlpha),this.blendEquationAlpha!==null&&(i.blendEquationAlpha=this.blendEquationAlpha),this.blendColor&&this.blendColor.isColor&&(i.blendColor=this.blendColor.getHex()),this.blendAlpha!==0&&(i.blendAlpha=this.blendAlpha),this.depthFunc!==sc&&(i.depthFunc=this.depthFunc),this.depthTest===!1&&(i.depthTest=this.depthTest),this.depthWrite===!1&&(i.depthWrite=this.depthWrite),this.colorWrite===!1&&(i.colorWrite=this.colorWrite),this.stencilWriteMask!==255&&(i.stencilWriteMask=this.stencilWriteMask),this.stencilFunc!==s1&&(i.stencilFunc=this.stencilFunc),this.stencilRef!==0&&(i.stencilRef=this.stencilRef),this.stencilFuncMask!==255&&(i.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==Yo&&(i.stencilFail=this.stencilFail),this.stencilZFail!==Yo&&(i.stencilZFail=this.stencilZFail),this.stencilZPass!==Yo&&(i.stencilZPass=this.stencilZPass),this.stencilWrite===!0&&(i.stencilWrite=this.stencilWrite),this.rotation!==void 0&&this.rotation!==0&&(i.rotation=this.rotation),this.polygonOffset===!0&&(i.polygonOffset=!0),this.polygonOffsetFactor!==0&&(i.polygonOffsetFactor=this.polygonOffsetFactor),this.polygonOffsetUnits!==0&&(i.polygonOffsetUnits=this.polygonOffsetUnits),this.linewidth!==void 0&&this.linewidth!==1&&(i.linewidth=this.linewidth),this.dashSize!==void 0&&(i.dashSize=this.dashSize),this.gapSize!==void 0&&(i.gapSize=this.gapSize),this.scale!==void 0&&(i.scale=this.scale),this.dithering===!0&&(i.dithering=!0),this.alphaTest>0&&(i.alphaTest=this.alphaTest),this.alphaHash===!0&&(i.alphaHash=!0),this.alphaToCoverage===!0&&(i.alphaToCoverage=!0),this.premultipliedAlpha===!0&&(i.premultipliedAlpha=!0),this.forceSinglePass===!0&&(i.forceSinglePass=!0),this.allowOverride===!1&&(i.allowOverride=!1),this.wireframe===!0&&(i.wireframe=!0),this.wireframeLinewidth>1&&(i.wireframeLinewidth=this.wireframeLinewidth),this.wireframeLinecap!=="round"&&(i.wireframeLinecap=this.wireframeLinecap),this.wireframeLinejoin!=="round"&&(i.wireframeLinejoin=this.wireframeLinejoin),this.flatShading===!0&&(i.flatShading=!0),this.visible===!1&&(i.visible=!1),this.toneMapped===!1&&(i.toneMapped=!1),this.fog===!1&&(i.fog=!1),Object.keys(this.userData).length>0&&(i.userData=this.userData);function n(s){const r=[];for(const a in s){const l=s[a];delete l.metadata,r.push(l)}return r}if(t){const s=n(e.textures),r=n(e.images);s.length>0&&(i.textures=s),r.length>0&&(i.images=r)}return i}fromJSON(e,t){if(e.uuid!==void 0&&(this.uuid=e.uuid),e.name!==void 0&&(this.name=e.name),e.color!==void 0&&this.color!==void 0&&this.color.setHex(e.color),e.roughness!==void 0&&(this.roughness=e.roughness),e.metalness!==void 0&&(this.metalness=e.metalness),e.sheen!==void 0&&(this.sheen=e.sheen),e.sheenColor!==void 0&&(this.sheenColor=new ne().setHex(e.sheenColor)),e.sheenRoughness!==void 0&&(this.sheenRoughness=e.sheenRoughness),e.emissive!==void 0&&this.emissive!==void 0&&this.emissive.setHex(e.emissive),e.specular!==void 0&&this.specular!==void 0&&this.specular.setHex(e.specular),e.specularIntensity!==void 0&&(this.specularIntensity=e.specularIntensity),e.specularColor!==void 0&&this.specularColor!==void 0&&this.specularColor.setHex(e.specularColor),e.shininess!==void 0&&(this.shininess=e.shininess),e.clearcoat!==void 0&&(this.clearcoat=e.clearcoat),e.clearcoatRoughness!==void 0&&(this.clearcoatRoughness=e.clearcoatRoughness),e.dispersion!==void 0&&(this.dispersion=e.dispersion),e.iridescence!==void 0&&(this.iridescence=e.iridescence),e.iridescenceIOR!==void 0&&(this.iridescenceIOR=e.iridescenceIOR),e.iridescenceThicknessRange!==void 0&&(this.iridescenceThicknessRange=e.iridescenceThicknessRange),e.transmission!==void 0&&(this.transmission=e.transmission),e.thickness!==void 0&&(this.thickness=e.thickness),e.attenuationDistance!==void 0&&(this.attenuationDistance=e.attenuationDistance),e.attenuationColor!==void 0&&this.attenuationColor!==void 0&&this.attenuationColor.setHex(e.attenuationColor),e.anisotropy!==void 0&&(this.anisotropy=e.anisotropy),e.anisotropyRotation!==void 0&&(this.anisotropyRotation=e.anisotropyRotation),e.fog!==void 0&&(this.fog=e.fog),e.flatShading!==void 0&&(this.flatShading=e.flatShading),e.blending!==void 0&&(this.blending=e.blending),e.combine!==void 0&&(this.combine=e.combine),e.side!==void 0&&(this.side=e.side),e.shadowSide!==void 0&&(this.shadowSide=e.shadowSide),e.opacity!==void 0&&(this.opacity=e.opacity),e.transparent!==void 0&&(this.transparent=e.transparent),e.alphaTest!==void 0&&(this.alphaTest=e.alphaTest),e.alphaHash!==void 0&&(this.alphaHash=e.alphaHash),e.depthFunc!==void 0&&(this.depthFunc=e.depthFunc),e.depthTest!==void 0&&(this.depthTest=e.depthTest),e.depthWrite!==void 0&&(this.depthWrite=e.depthWrite),e.colorWrite!==void 0&&(this.colorWrite=e.colorWrite),e.blendSrc!==void 0&&(this.blendSrc=e.blendSrc),e.blendDst!==void 0&&(this.blendDst=e.blendDst),e.blendEquation!==void 0&&(this.blendEquation=e.blendEquation),e.blendSrcAlpha!==void 0&&(this.blendSrcAlpha=e.blendSrcAlpha),e.blendDstAlpha!==void 0&&(this.blendDstAlpha=e.blendDstAlpha),e.blendEquationAlpha!==void 0&&(this.blendEquationAlpha=e.blendEquationAlpha),e.blendColor!==void 0&&this.blendColor!==void 0&&this.blendColor.setHex(e.blendColor),e.blendAlpha!==void 0&&(this.blendAlpha=e.blendAlpha),e.stencilWriteMask!==void 0&&(this.stencilWriteMask=e.stencilWriteMask),e.stencilFunc!==void 0&&(this.stencilFunc=e.stencilFunc),e.stencilRef!==void 0&&(this.stencilRef=e.stencilRef),e.stencilFuncMask!==void 0&&(this.stencilFuncMask=e.stencilFuncMask),e.stencilFail!==void 0&&(this.stencilFail=e.stencilFail),e.stencilZFail!==void 0&&(this.stencilZFail=e.stencilZFail),e.stencilZPass!==void 0&&(this.stencilZPass=e.stencilZPass),e.stencilWrite!==void 0&&(this.stencilWrite=e.stencilWrite),e.wireframe!==void 0&&(this.wireframe=e.wireframe),e.wireframeLinewidth!==void 0&&(this.wireframeLinewidth=e.wireframeLinewidth),e.wireframeLinecap!==void 0&&(this.wireframeLinecap=e.wireframeLinecap),e.wireframeLinejoin!==void 0&&(this.wireframeLinejoin=e.wireframeLinejoin),e.rotation!==void 0&&(this.rotation=e.rotation),e.linewidth!==void 0&&(this.linewidth=e.linewidth),e.dashSize!==void 0&&(this.dashSize=e.dashSize),e.gapSize!==void 0&&(this.gapSize=e.gapSize),e.scale!==void 0&&(this.scale=e.scale),e.polygonOffset!==void 0&&(this.polygonOffset=e.polygonOffset),e.polygonOffsetFactor!==void 0&&(this.polygonOffsetFactor=e.polygonOffsetFactor),e.polygonOffsetUnits!==void 0&&(this.polygonOffsetUnits=e.polygonOffsetUnits),e.dithering!==void 0&&(this.dithering=e.dithering),e.alphaToCoverage!==void 0&&(this.alphaToCoverage=e.alphaToCoverage),e.premultipliedAlpha!==void 0&&(this.premultipliedAlpha=e.premultipliedAlpha),e.forceSinglePass!==void 0&&(this.forceSinglePass=e.forceSinglePass),e.allowOverride!==void 0&&(this.allowOverride=e.allowOverride),e.visible!==void 0&&(this.visible=e.visible),e.toneMapped!==void 0&&(this.toneMapped=e.toneMapped),e.userData!==void 0&&(this.userData=e.userData),e.vertexColors!==void 0&&(typeof e.vertexColors=="number"?this.vertexColors=e.vertexColors>0:this.vertexColors=e.vertexColors),e.size!==void 0&&(this.size=e.size),e.sizeAttenuation!==void 0&&(this.sizeAttenuation=e.sizeAttenuation),e.map!==void 0&&(this.map=t[e.map]||null),e.matcap!==void 0&&(this.matcap=t[e.matcap]||null),e.alphaMap!==void 0&&(this.alphaMap=t[e.alphaMap]||null),e.bumpMap!==void 0&&(this.bumpMap=t[e.bumpMap]||null),e.bumpScale!==void 0&&(this.bumpScale=e.bumpScale),e.normalMap!==void 0&&(this.normalMap=t[e.normalMap]||null),e.normalMapType!==void 0&&(this.normalMapType=e.normalMapType),e.normalScale!==void 0){let i=e.normalScale;Array.isArray(i)===!1&&(i=[i,i]),this.normalScale=new we().fromArray(i)}return e.displacementMap!==void 0&&(this.displacementMap=t[e.displacementMap]||null),e.displacementScale!==void 0&&(this.displacementScale=e.displacementScale),e.displacementBias!==void 0&&(this.displacementBias=e.displacementBias),e.roughnessMap!==void 0&&(this.roughnessMap=t[e.roughnessMap]||null),e.metalnessMap!==void 0&&(this.metalnessMap=t[e.metalnessMap]||null),e.emissiveMap!==void 0&&(this.emissiveMap=t[e.emissiveMap]||null),e.emissiveIntensity!==void 0&&(this.emissiveIntensity=e.emissiveIntensity),e.specularMap!==void 0&&(this.specularMap=t[e.specularMap]||null),e.specularIntensityMap!==void 0&&(this.specularIntensityMap=t[e.specularIntensityMap]||null),e.specularColorMap!==void 0&&(this.specularColorMap=t[e.specularColorMap]||null),e.envMap!==void 0&&(this.envMap=t[e.envMap]||null),e.envMapRotation!==void 0&&this.envMapRotation.fromArray(e.envMapRotation),e.envMapIntensity!==void 0&&(this.envMapIntensity=e.envMapIntensity),e.reflectivity!==void 0&&(this.reflectivity=e.reflectivity),e.refractionRatio!==void 0&&(this.refractionRatio=e.refractionRatio),e.lightMap!==void 0&&(this.lightMap=t[e.lightMap]||null),e.lightMapIntensity!==void 0&&(this.lightMapIntensity=e.lightMapIntensity),e.aoMap!==void 0&&(this.aoMap=t[e.aoMap]||null),e.aoMapIntensity!==void 0&&(this.aoMapIntensity=e.aoMapIntensity),e.gradientMap!==void 0&&(this.gradientMap=t[e.gradientMap]||null),e.clearcoatMap!==void 0&&(this.clearcoatMap=t[e.clearcoatMap]||null),e.clearcoatRoughnessMap!==void 0&&(this.clearcoatRoughnessMap=t[e.clearcoatRoughnessMap]||null),e.clearcoatNormalMap!==void 0&&(this.clearcoatNormalMap=t[e.clearcoatNormalMap]||null),e.clearcoatNormalScale!==void 0&&(this.clearcoatNormalScale=new we().fromArray(e.clearcoatNormalScale)),e.iridescenceMap!==void 0&&(this.iridescenceMap=t[e.iridescenceMap]||null),e.iridescenceThicknessMap!==void 0&&(this.iridescenceThicknessMap=t[e.iridescenceThicknessMap]||null),e.transmissionMap!==void 0&&(this.transmissionMap=t[e.transmissionMap]||null),e.thicknessMap!==void 0&&(this.thicknessMap=t[e.thicknessMap]||null),e.anisotropyMap!==void 0&&(this.anisotropyMap=t[e.anisotropyMap]||null),e.sheenColorMap!==void 0&&(this.sheenColorMap=t[e.sheenColorMap]||null),e.sheenRoughnessMap!==void 0&&(this.sheenRoughnessMap=t[e.sheenRoughnessMap]||null),this}clone(){return new this.constructor().copy(this)}copy(e){this.name=e.name,this.blending=e.blending,this.side=e.side,this.vertexColors=e.vertexColors,this.opacity=e.opacity,this.transparent=e.transparent,this.blendSrc=e.blendSrc,this.blendDst=e.blendDst,this.blendEquation=e.blendEquation,this.blendSrcAlpha=e.blendSrcAlpha,this.blendDstAlpha=e.blendDstAlpha,this.blendEquationAlpha=e.blendEquationAlpha,this.blendColor.copy(e.blendColor),this.blendAlpha=e.blendAlpha,this.depthFunc=e.depthFunc,this.depthTest=e.depthTest,this.depthWrite=e.depthWrite,this.stencilWriteMask=e.stencilWriteMask,this.stencilFunc=e.stencilFunc,this.stencilRef=e.stencilRef,this.stencilFuncMask=e.stencilFuncMask,this.stencilFail=e.stencilFail,this.stencilZFail=e.stencilZFail,this.stencilZPass=e.stencilZPass,this.stencilWrite=e.stencilWrite;const t=e.clippingPlanes;let i=null;if(t!==null){const n=t.length;i=new Array(n);for(let s=0;s!==n;++s)i[s]=t[s].clone()}return this.clippingPlanes=i,this.clipIntersection=e.clipIntersection,this.clipShadows=e.clipShadows,this.shadowSide=e.shadowSide,this.colorWrite=e.colorWrite,this.precision=e.precision,this.polygonOffset=e.polygonOffset,this.polygonOffsetFactor=e.polygonOffsetFactor,this.polygonOffsetUnits=e.polygonOffsetUnits,this.dithering=e.dithering,this.alphaTest=e.alphaTest,this.alphaHash=e.alphaHash,this.alphaToCoverage=e.alphaToCoverage,this.premultipliedAlpha=e.premultipliedAlpha,this.forceSinglePass=e.forceSinglePass,this.allowOverride=e.allowOverride,this.visible=e.visible,this.toneMapped=e.toneMapped,this.userData=JSON.parse(JSON.stringify(e.userData)),this}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(e){e===!0&&this.version++}}class eu extends Ar{constructor(e){super(),this.isSpriteMaterial=!0,this.type="SpriteMaterial",this.color=new ne(16777215),this.map=null,this.alphaMap=null,this.rotation=0,this.sizeAttenuation=!0,this.transparent=!0,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.alphaMap=e.alphaMap,this.rotation=e.rotation,this.sizeAttenuation=e.sizeAttenuation,this.fog=e.fog,this}}let sl;const wc=new D,rl=new D,al=new D,ol=new we,xc=new we,uw=new lt,Qh=new D,Sc=new D,ed=new D,y1=new we,hp=new we,b1=new we;class Ec extends hi{constructor(e=new eu){if(super(),this.isSprite=!0,this.type="Sprite",sl===void 0){sl=new ot;const t=new Float32Array([-.5,-.5,0,0,0,.5,-.5,0,1,0,.5,.5,0,1,1,-.5,.5,0,0,1]),i=new dw(t,5);sl.setIndex([0,1,2,0,2,3]),sl.setAttribute("position",new $u(i,3,0,!1)),sl.setAttribute("uv",new $u(i,2,3,!1))}this.geometry=sl,this.material=e,this.center=new we(.5,.5),this.count=1}raycast(e,t){e.camera===null&&Ze('Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.'),rl.setFromMatrixScale(this.matrixWorld),uw.copy(e.camera.matrixWorld),this.modelViewMatrix.multiplyMatrices(e.camera.matrixWorldInverse,this.matrixWorld),al.setFromMatrixPosition(this.modelViewMatrix),e.camera.isPerspectiveCamera&&this.material.sizeAttenuation===!1&&rl.multiplyScalar(-al.z);const i=this.material.rotation;let n,s;i!==0&&(s=Math.cos(i),n=Math.sin(i));const r=this.center;td(Qh.set(-.5,-.5,0),al,r,rl,n,s),td(Sc.set(.5,-.5,0),al,r,rl,n,s),td(ed.set(.5,.5,0),al,r,rl,n,s),y1.set(0,0),hp.set(1,0),b1.set(1,1);let a=e.ray.intersectTriangle(Qh,Sc,ed,!1,wc);if(a===null&&(td(Sc.set(-.5,.5,0),al,r,rl,n,s),hp.set(0,1),a=e.ray.intersectTriangle(Qh,ed,Sc,!1,wc),a===null))return;const l=e.ray.origin.distanceTo(wc);l<e.near||l>e.far||t.push({distance:l,point:wc.clone(),uv:As.getInterpolation(wc,Qh,Sc,ed,y1,hp,b1,new we),face:null,object:this})}copy(e,t){return super.copy(e,t),e.center!==void 0&&this.center.copy(e.center),this.material=e.material,this}}function td(o,e,t,i,n,s){ol.subVectors(o,t).addScalar(.5).multiply(i),n!==void 0?(xc.x=s*ol.x-n*ol.y,xc.y=n*ol.x+s*ol.y):xc.copy(ol),o.copy(e),o.x+=xc.x,o.y+=xc.y,o.applyMatrix4(uw)}const Rr=new D,dp=new D,id=new D,na=new D,up=new D,nd=new D,fp=new D;class Ch{constructor(e=new D,t=new D(0,0,-1)){this.origin=e,this.direction=t}set(e,t){return this.origin.copy(e),this.direction.copy(t),this}copy(e){return this.origin.copy(e.origin),this.direction.copy(e.direction),this}at(e,t){return t.copy(this.origin).addScaledVector(this.direction,e)}lookAt(e){return this.direction.copy(e).sub(this.origin).normalize(),this}recast(e){return this.origin.copy(this.at(e,Rr)),this}closestPointToPoint(e,t){t.subVectors(e,this.origin);const i=t.dot(this.direction);return i<0?t.copy(this.origin):t.copy(this.origin).addScaledVector(this.direction,i)}distanceToPoint(e){return Math.sqrt(this.distanceSqToPoint(e))}distanceSqToPoint(e){const t=Rr.subVectors(e,this.origin).dot(this.direction);return t<0?this.origin.distanceToSquared(e):(Rr.copy(this.origin).addScaledVector(this.direction,t),Rr.distanceToSquared(e))}distanceSqToSegment(e,t,i,n){dp.copy(e).add(t).multiplyScalar(.5),id.copy(t).sub(e).normalize(),na.copy(this.origin).sub(dp);const s=e.distanceTo(t)*.5,r=-this.direction.dot(id),a=na.dot(this.direction),l=-na.dot(id),c=na.lengthSq(),h=Math.abs(1-r*r);let d,u,f,p;if(h>0)if(d=r*l-a,u=r*a-l,p=s*h,d>=0)if(u>=-p)if(u<=p){const g=1/h;d*=g,u*=g,f=d*(d+r*u+2*a)+u*(r*d+u+2*l)+c}else u=s,d=Math.max(0,-(r*u+a)),f=-d*d+u*(u+2*l)+c;else u=-s,d=Math.max(0,-(r*u+a)),f=-d*d+u*(u+2*l)+c;else u<=-p?(d=Math.max(0,-(-r*s+a)),u=d>0?-s:Math.min(Math.max(-s,-l),s),f=-d*d+u*(u+2*l)+c):u<=p?(d=0,u=Math.min(Math.max(-s,-l),s),f=u*(u+2*l)+c):(d=Math.max(0,-(r*s+a)),u=d>0?s:Math.min(Math.max(-s,-l),s),f=-d*d+u*(u+2*l)+c);else u=r>0?-s:s,d=Math.max(0,-(r*u+a)),f=-d*d+u*(u+2*l)+c;return i&&i.copy(this.origin).addScaledVector(this.direction,d),n&&n.copy(dp).addScaledVector(id,u),f}intersectSphere(e,t){Rr.subVectors(e.center,this.origin);const i=Rr.dot(this.direction),n=Rr.dot(Rr)-i*i,s=e.radius*e.radius;if(n>s)return null;const r=Math.sqrt(s-n),a=i-r,l=i+r;return l<0?null:a<0?this.at(l,t):this.at(a,t)}intersectsSphere(e){return e.radius<0?!1:this.distanceSqToPoint(e.center)<=e.radius*e.radius}distanceToPlane(e){const t=e.normal.dot(this.direction);if(t===0)return e.distanceToPoint(this.origin)===0?0:null;const i=-(this.origin.dot(e.normal)+e.constant)/t;return i>=0?i:null}intersectPlane(e,t){const i=this.distanceToPlane(e);return i===null?null:this.at(i,t)}intersectsPlane(e){const t=e.distanceToPoint(this.origin);return t===0||e.normal.dot(this.direction)*t<0}intersectBox(e,t){let i,n,s,r,a,l;const c=1/this.direction.x,h=1/this.direction.y,d=1/this.direction.z,u=this.origin;return c>=0?(i=(e.min.x-u.x)*c,n=(e.max.x-u.x)*c):(i=(e.max.x-u.x)*c,n=(e.min.x-u.x)*c),h>=0?(s=(e.min.y-u.y)*h,r=(e.max.y-u.y)*h):(s=(e.max.y-u.y)*h,r=(e.min.y-u.y)*h),i>r||s>n||((s>i||isNaN(i))&&(i=s),(r<n||isNaN(n))&&(n=r),d>=0?(a=(e.min.z-u.z)*d,l=(e.max.z-u.z)*d):(a=(e.max.z-u.z)*d,l=(e.min.z-u.z)*d),i>l||a>n)||((a>i||i!==i)&&(i=a),(l<n||n!==n)&&(n=l),n<0)?null:this.at(i>=0?i:n,t)}intersectsBox(e){return this.intersectBox(e,Rr)!==null}intersectTriangle(e,t,i,n,s){up.subVectors(t,e),nd.subVectors(i,e),fp.crossVectors(up,nd);let r=this.direction.dot(fp),a;if(r>0){if(n)return null;a=1}else if(r<0)a=-1,r=-r;else return null;na.subVectors(this.origin,e);const l=a*this.direction.dot(nd.crossVectors(na,nd));if(l<0)return null;const c=a*this.direction.dot(up.cross(na));if(c<0||l+c>r)return null;const h=-a*na.dot(fp);return h<0?null:this.at(h/r,s)}applyMatrix4(e){return this.origin.applyMatrix4(e),this.direction.transformDirection(e),this}equals(e){return e.origin.equals(this.origin)&&e.direction.equals(this.direction)}clone(){return new this.constructor().copy(this)}}class Hn extends Ar{constructor(e){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new ne(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new wr,this.combine=og,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.specularMap=e.specularMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.combine=e.combine,this.reflectivity=e.reflectivity,this.refractionRatio=e.refractionRatio,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.fog=e.fog,this}}const M1=new lt,Ha=new Ch,sd=new qr,w1=new D,rd=new D,ad=new D,od=new D,pp=new D,ld=new D,x1=new D,cd=new D;class Se extends hi{constructor(e=new ot,t=new Hn){super(),this.isMesh=!0,this.type="Mesh",this.geometry=e,this.material=t,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.count=1,this.updateMorphTargets()}copy(e,t){return super.copy(e,t),e.morphTargetInfluences!==void 0&&(this.morphTargetInfluences=e.morphTargetInfluences.slice()),e.morphTargetDictionary!==void 0&&(this.morphTargetDictionary=Object.assign({},e.morphTargetDictionary)),this.material=Array.isArray(e.material)?e.material.slice():e.material,this.geometry=e.geometry,this}updateMorphTargets(){const t=this.geometry.morphAttributes,i=Object.keys(t);if(i.length>0){const n=t[i[0]];if(n!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let s=0,r=n.length;s<r;s++){const a=n[s].name||String(s);this.morphTargetInfluences.push(0),this.morphTargetDictionary[a]=s}}}}getVertexPosition(e,t){const i=this.geometry,n=i.attributes.position,s=i.morphAttributes.position,r=i.morphTargetsRelative;t.fromBufferAttribute(n,e);const a=this.morphTargetInfluences;if(s&&a){ld.set(0,0,0);for(let l=0,c=s.length;l<c;l++){const h=a[l],d=s[l];h!==0&&(pp.fromBufferAttribute(d,e),r?ld.addScaledVector(pp,h):ld.addScaledVector(pp.sub(t),h))}t.add(ld)}return t}raycast(e,t){const i=this.geometry,n=this.material,s=this.matrixWorld;n!==void 0&&(i.boundingSphere===null&&i.computeBoundingSphere(),sd.copy(i.boundingSphere),sd.applyMatrix4(s),Ha.copy(e.ray).recast(e.near),!(sd.containsPoint(Ha.origin)===!1&&(Ha.intersectSphere(sd,w1)===null||Ha.origin.distanceToSquared(w1)>(e.far-e.near)**2))&&(M1.copy(s).invert(),Ha.copy(e.ray).applyMatrix4(M1),!(i.boundingBox!==null&&Ha.intersectsBox(i.boundingBox)===!1)&&this._computeIntersections(e,t,Ha)))}_computeIntersections(e,t,i){let n;const s=this.geometry,r=this.material,a=s.index,l=s.attributes.position,c=s.attributes.uv,h=s.attributes.uv1,d=s.attributes.normal,u=s.groups,f=s.drawRange;if(a!==null)if(Array.isArray(r))for(let p=0,g=u.length;p<g;p++){const m=u[p],v=r[m.materialIndex],b=Math.max(m.start,f.start),x=Math.min(a.count,Math.min(m.start+m.count,f.start+f.count));for(let y=b,w=x;y<w;y+=3){const S=a.getX(y),A=a.getX(y+1),M=a.getX(y+2);n=hd(this,v,e,i,c,h,d,S,A,M),n&&(n.faceIndex=Math.floor(y/3),n.face.materialIndex=m.materialIndex,t.push(n))}}else{const p=Math.max(0,f.start),g=Math.min(a.count,f.start+f.count);for(let m=p,v=g;m<v;m+=3){const b=a.getX(m),x=a.getX(m+1),y=a.getX(m+2);n=hd(this,r,e,i,c,h,d,b,x,y),n&&(n.faceIndex=Math.floor(m/3),t.push(n))}}else if(l!==void 0)if(Array.isArray(r))for(let p=0,g=u.length;p<g;p++){const m=u[p],v=r[m.materialIndex],b=Math.max(m.start,f.start),x=Math.min(l.count,Math.min(m.start+m.count,f.start+f.count));for(let y=b,w=x;y<w;y+=3){const S=y,A=y+1,M=y+2;n=hd(this,v,e,i,c,h,d,S,A,M),n&&(n.faceIndex=Math.floor(y/3),n.face.materialIndex=m.materialIndex,t.push(n))}}else{const p=Math.max(0,f.start),g=Math.min(l.count,f.start+f.count);for(let m=p,v=g;m<v;m+=3){const b=m,x=m+1,y=m+2;n=hd(this,r,e,i,c,h,d,b,x,y),n&&(n.faceIndex=Math.floor(m/3),t.push(n))}}}}function I3(o,e,t,i,n,s,r,a){let l;if(e.side===fi?l=i.intersectTriangle(r,s,n,!0,a):l=i.intersectTriangle(n,s,r,e.side===Pa,a),l===null)return null;cd.copy(a),cd.applyMatrix4(o.matrixWorld);const c=t.ray.origin.distanceTo(cd);return c<t.near||c>t.far?null:{distance:c,point:cd.clone(),object:o}}function hd(o,e,t,i,n,s,r,a,l,c){o.getVertexPosition(a,rd),o.getVertexPosition(l,ad),o.getVertexPosition(c,od);const h=I3(o,e,t,i,rd,ad,od,x1);if(h){const d=new D;As.getBarycoord(x1,rd,ad,od,d),n&&(h.uv=As.getInterpolatedAttribute(n,a,l,c,d,new we)),s&&(h.uv1=As.getInterpolatedAttribute(s,a,l,c,d,new we)),r&&(h.normal=As.getInterpolatedAttribute(r,a,l,c,d,new D),h.normal.dot(i.direction)>0&&h.normal.multiplyScalar(-1));const u={a,b:l,c,normal:new D,materialIndex:0};As.getNormal(rd,ad,od,u.normal),h.face=u,h.barycoord=d}return h}const Ac=new wt,S1=new wt,E1=new wt,D3=new wt,A1=new lt,dd=new D,mp=new qr,_1=new lt,gp=new Ch;class Vk extends Se{constructor(e,t){super(e,t),this.isSkinnedMesh=!0,this.type="SkinnedMesh",this.bindMode=i1,this.bindMatrix=new lt,this.bindMatrixInverse=new lt,this.boundingBox=null,this.boundingSphere=null}computeBoundingBox(){const e=this.geometry;this.boundingBox===null&&(this.boundingBox=new on),this.boundingBox.makeEmpty();const t=e.getAttribute("position");for(let i=0;i<t.count;i++)this.getVertexPosition(i,dd),this.boundingBox.expandByPoint(dd)}computeBoundingSphere(){const e=this.geometry;this.boundingSphere===null&&(this.boundingSphere=new qr),this.boundingSphere.makeEmpty();const t=e.getAttribute("position");for(let i=0;i<t.count;i++)this.getVertexPosition(i,dd),this.boundingSphere.expandByPoint(dd)}copy(e,t){return super.copy(e,t),this.bindMode=e.bindMode,this.bindMatrix.copy(e.bindMatrix),this.bindMatrixInverse.copy(e.bindMatrixInverse),this.skeleton=e.skeleton,e.boundingBox!==null&&(this.boundingBox=e.boundingBox.clone()),e.boundingSphere!==null&&(this.boundingSphere=e.boundingSphere.clone()),this}raycast(e,t){const i=this.material,n=this.matrixWorld;i!==void 0&&(this.boundingSphere===null&&this.computeBoundingSphere(),mp.copy(this.boundingSphere),mp.applyMatrix4(n),e.ray.intersectsSphere(mp)!==!1&&(_1.copy(n).invert(),gp.copy(e.ray).applyMatrix4(_1),!(this.boundingBox!==null&&gp.intersectsBox(this.boundingBox)===!1)&&this._computeIntersections(e,t,gp)))}getVertexPosition(e,t){return super.getVertexPosition(e,t),this.applyBoneTransform(e,t),t}bind(e,t){this.skeleton=e,t===void 0&&(this.updateMatrixWorld(!0),this.skeleton.calculateInverses(),t=this.matrixWorld),this.bindMatrix.copy(t),this.bindMatrixInverse.copy(t).invert()}pose(){this.skeleton.pose()}normalizeSkinWeights(){const e=new wt,t=this.geometry.attributes.skinWeight;for(let i=0,n=t.count;i<n;i++){e.fromBufferAttribute(t,i);const s=1/e.manhattanLength();s!==1/0?e.multiplyScalar(s):e.set(1,0,0,0),t.setXYZW(i,e.x,e.y,e.z,e.w)}}updateMatrixWorld(e){super.updateMatrixWorld(e),this.bindMode===i1?this.bindMatrixInverse.copy(this.matrixWorld).invert():this.bindMode===DE?this.bindMatrixInverse.copy(this.bindMatrix).invert():ke("SkinnedMesh: Unrecognized bindMode: "+this.bindMode)}applyBoneTransform(e,t){const i=this.skeleton,n=this.geometry;S1.fromBufferAttribute(n.attributes.skinIndex,e),E1.fromBufferAttribute(n.attributes.skinWeight,e),t.isVector4?(Ac.copy(t),t.set(0,0,0,0)):(Ac.set(...t,1),t.set(0,0,0)),Ac.applyMatrix4(this.bindMatrix);for(let s=0;s<4;s++){const r=E1.getComponent(s);if(r!==0){const a=S1.getComponent(s);A1.multiplyMatrices(i.bones[a].matrixWorld,i.boneInverses[a]),t.addScaledVector(D3.copy(Ac).applyMatrix4(A1),r)}}return t.isVector4&&(t.w=Ac.w),t.applyMatrix4(this.bindMatrixInverse)}}class R3 extends hi{constructor(){super(),this.isBone=!0,this.type="Bone"}}class ps extends ln{constructor(e=null,t=1,i=1,n,s,r,a,l,c=Qt,h=Qt,d,u){super(null,r,a,l,c,h,n,s,d,u),this.isDataTexture=!0,this.image={data:e,width:t,height:i},this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}const T1=new lt,C3=new lt;class fw{constructor(e=[],t=[]){this.uuid=Ws(),this.bones=e.slice(0),this.boneInverses=t,this.boneMatrices=null,this.boneTexture=null,this.init()}init(){const e=this.bones,t=this.boneInverses;if(this.boneMatrices=new Float32Array(e.length*16),t.length===0)this.calculateInverses();else if(e.length!==t.length){ke("Skeleton: Number of inverse bone matrices does not match amount of bones."),this.boneInverses=[];for(let i=0,n=this.bones.length;i<n;i++)this.boneInverses.push(new lt)}}calculateInverses(){this.boneInverses.length=0;for(let e=0,t=this.bones.length;e<t;e++){const i=new lt;this.bones[e]&&i.copy(this.bones[e].matrixWorld).invert(),this.boneInverses.push(i)}}pose(){for(let e=0,t=this.bones.length;e<t;e++){const i=this.bones[e];i&&i.matrixWorld.copy(this.boneInverses[e]).invert()}for(let e=0,t=this.bones.length;e<t;e++){const i=this.bones[e];i&&(i.parent&&i.parent.isBone?(i.matrix.copy(i.parent.matrixWorld).invert(),i.matrix.multiply(i.matrixWorld)):i.matrix.copy(i.matrixWorld),i.matrix.decompose(i.position,i.quaternion,i.scale))}}update(){const e=this.bones,t=this.boneInverses,i=this.boneMatrices,n=this.boneTexture;for(let s=0,r=e.length;s<r;s++){const a=e[s]?e[s].matrixWorld:C3;T1.multiplyMatrices(a,t[s]),T1.toArray(i,s*16)}n!==null&&(n.needsUpdate=!0)}clone(){return new fw(this.bones,this.boneInverses)}computeBoneTexture(){let e=Math.sqrt(this.bones.length*4);e=Math.ceil(e/4)*4,e=Math.max(e,4);const t=new Float32Array(e*e*4);t.set(this.boneMatrices);const i=new ps(t,e,e,Vi,En);return i.needsUpdate=!0,this.boneMatrices=t,this.boneTexture=i,this}getBoneByName(e){for(let t=0,i=this.bones.length;t<i;t++){const n=this.bones[t];if(n.name===e)return n}}dispose(){this.boneTexture!==null&&(this.boneTexture.dispose(),this.boneTexture=null)}fromJSON(e,t){this.uuid=e.uuid;for(let i=0,n=e.bones.length;i<n;i++){const s=e.bones[i];let r=t[s];r===void 0&&(ke("Skeleton: No bone found with UUID:",s),r=new R3),this.bones.push(r),this.boneInverses.push(new lt().fromArray(e.boneInverses[i]))}return this.init(),this}toJSON(){const e={metadata:{version:4.7,type:"Skeleton",generator:"Skeleton.toJSON"},bones:[],boneInverses:[]};e.uuid=this.uuid;const t=this.bones,i=this.boneInverses;for(let n=0,s=t.length;n<s;n++){const r=t[n];e.bones.push(r.uuid);const a=i[n];e.boneInverses.push(a.toArray())}return e}}class I1 extends st{constructor(e,t,i,n=1){super(e,t,i),this.isInstancedBufferAttribute=!0,this.meshPerAttribute=n}copy(e){return super.copy(e),this.meshPerAttribute=e.meshPerAttribute,this}toJSON(){const e=super.toJSON();return e.meshPerAttribute=this.meshPerAttribute,e.isInstancedBufferAttribute=!0,e}}const ll=new lt,D1=new lt,ud=[],R1=new on,k3=new lt,_c=new Se,Tc=new qr;class Wk extends Se{constructor(e,t,i){super(e,t),this.isInstancedMesh=!0,this.instanceMatrix=new I1(new Float32Array(i*16),16),this.instanceColor=null,this.morphTexture=null,this.count=i,this.boundingBox=null,this.boundingSphere=null;for(let n=0;n<i;n++)this.setMatrixAt(n,k3)}computeBoundingBox(){const e=this.geometry,t=this.count;this.boundingBox===null&&(this.boundingBox=new on),e.boundingBox===null&&e.computeBoundingBox(),this.boundingBox.makeEmpty();for(let i=0;i<t;i++)this.getMatrixAt(i,ll),R1.copy(e.boundingBox).applyMatrix4(ll),this.boundingBox.union(R1)}computeBoundingSphere(){const e=this.geometry,t=this.count;this.boundingSphere===null&&(this.boundingSphere=new qr),e.boundingSphere===null&&e.computeBoundingSphere(),this.boundingSphere.makeEmpty();for(let i=0;i<t;i++)this.getMatrixAt(i,ll),Tc.copy(e.boundingSphere).applyMatrix4(ll),this.boundingSphere.union(Tc)}copy(e,t){return super.copy(e,t),this.instanceMatrix.copy(e.instanceMatrix),e.morphTexture!==null&&(this.morphTexture=e.morphTexture.clone()),e.instanceColor!==null&&(this.instanceColor=e.instanceColor.clone()),this.count=e.count,e.boundingBox!==null&&(this.boundingBox=e.boundingBox.clone()),e.boundingSphere!==null&&(this.boundingSphere=e.boundingSphere.clone()),this}getColorAt(e,t){return this.instanceColor===null?t.setRGB(1,1,1):t.fromArray(this.instanceColor.array,e*3)}getMatrixAt(e,t){return t.fromArray(this.instanceMatrix.array,e*16)}getMorphAt(e,t){const i=t.morphTargetInfluences,n=this.morphTexture.source.data.data,s=i.length+1,r=e*s+1;for(let a=0;a<i.length;a++)i[a]=n[r+a]}raycast(e,t){const i=this.matrixWorld,n=this.count;if(_c.geometry=this.geometry,_c.material=this.material,_c.material!==void 0&&(this.boundingSphere===null&&this.computeBoundingSphere(),Tc.copy(this.boundingSphere),Tc.applyMatrix4(i),e.ray.intersectsSphere(Tc)!==!1))for(let s=0;s<n;s++){this.getMatrixAt(s,ll),D1.multiplyMatrices(i,ll),_c.matrixWorld=D1,_c.raycast(e,ud);for(let r=0,a=ud.length;r<a;r++){const l=ud[r];l.instanceId=s,l.object=this,t.push(l)}ud.length=0}}setColorAt(e,t){return this.instanceColor===null&&(this.instanceColor=new I1(new Float32Array(this.instanceMatrix.count*3).fill(1),3)),t.toArray(this.instanceColor.array,e*3),this}setMatrixAt(e,t){return t.toArray(this.instanceMatrix.array,e*16),this}setMorphAt(e,t){const i=t.morphTargetInfluences,n=i.length+1;this.morphTexture===null&&(this.morphTexture=new ps(new Float32Array(n*this.count),n,this.count,ac,En));const s=this.morphTexture.source.data.data;let r=0;for(let c=0;c<i.length;c++)r+=i[c];const a=this.geometry.morphTargetsRelative?1:1-r,l=n*e;return s[l]=a,s.set(i,l+1),this}updateMorphTargets(){}dispose(){this.dispatchEvent({type:"dispose"}),this.morphTexture!==null&&(this.morphTexture.dispose(),this.morphTexture=null)}}const vp=new D,P3=new D,L3=new je;class ma{constructor(e=new D(1,0,0),t=0){this.isPlane=!0,this.normal=e,this.constant=t}set(e,t){return this.normal.copy(e),this.constant=t,this}setComponents(e,t,i,n){return this.normal.set(e,t,i),this.constant=n,this}setFromNormalAndCoplanarPoint(e,t){return this.normal.copy(e),this.constant=-t.dot(this.normal),this}setFromCoplanarPoints(e,t,i){const n=vp.subVectors(i,t).cross(P3.subVectors(e,t)).normalize();return this.setFromNormalAndCoplanarPoint(n,e),this}copy(e){return this.normal.copy(e.normal),this.constant=e.constant,this}normalize(){const e=1/this.normal.length();return this.normal.multiplyScalar(e),this.constant*=e,this}negate(){return this.constant*=-1,this.normal.negate(),this}distanceToPoint(e){return this.normal.dot(e)+this.constant}distanceToSphere(e){return this.distanceToPoint(e.center)-e.radius}projectPoint(e,t){return t.copy(e).addScaledVector(this.normal,-this.distanceToPoint(e))}intersectLine(e,t,i=!0){const n=e.delta(vp),s=this.normal.dot(n);if(s===0)return this.distanceToPoint(e.start)===0?t.copy(e.start):null;const r=-(e.start.dot(this.normal)+this.constant)/s;return i===!0&&(r<0||r>1)?null:t.copy(e.start).addScaledVector(n,r)}intersectsLine(e){const t=this.distanceToPoint(e.start),i=this.distanceToPoint(e.end);return t<0&&i>0||i<0&&t>0}intersectsBox(e){return e.intersectsPlane(this)}intersectsSphere(e){return e.intersectsPlane(this)}coplanarPoint(e){return e.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(e,t){const i=t||L3.getNormalMatrix(e),n=this.coplanarPoint(vp).applyMatrix4(e),s=this.normal.applyMatrix3(i).normalize();return this.constant=-n.dot(s),this}translate(e){return this.constant-=e.dot(this.normal),this}equals(e){return e.normal.equals(this.normal)&&e.constant===this.constant}clone(){return new this.constructor().copy(this)}}const Ga=new qr,O3=new we(.5,.5),fd=new D;class xg{constructor(e=new ma,t=new ma,i=new ma,n=new ma,s=new ma,r=new ma){this.planes=[e,t,i,n,s,r]}set(e,t,i,n,s,r){const a=this.planes;return a[0].copy(e),a[1].copy(t),a[2].copy(i),a[3].copy(n),a[4].copy(s),a[5].copy(r),this}copy(e){const t=this.planes;for(let i=0;i<6;i++)t[i].copy(e.planes[i]);return this}setFromProjectionMatrix(e,t=vr,i=!1){const n=this.planes,s=e.elements,r=s[0],a=s[1],l=s[2],c=s[3],h=s[4],d=s[5],u=s[6],f=s[7],p=s[8],g=s[9],m=s[10],v=s[11],b=s[12],x=s[13],y=s[14],w=s[15];if(n[0].setComponents(c-r,f-h,v-p,w-b).normalize(),n[1].setComponents(c+r,f+h,v+p,w+b).normalize(),n[2].setComponents(c+a,f+d,v+g,w+x).normalize(),n[3].setComponents(c-a,f-d,v-g,w-x).normalize(),i)n[4].setComponents(l,u,m,y).normalize(),n[5].setComponents(c-l,f-u,v-m,w-y).normalize();else if(n[4].setComponents(c-l,f-u,v-m,w-y).normalize(),t===vr)n[5].setComponents(c+l,f+u,v+m,w+y).normalize();else if(t===xh)n[5].setComponents(l,u,m,y).normalize();else throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: "+t);return this}intersectsObject(e){if(e.boundingSphere!==void 0)e.boundingSphere===null&&e.computeBoundingSphere(),Ga.copy(e.boundingSphere).applyMatrix4(e.matrixWorld);else{const t=e.geometry;t.boundingSphere===null&&t.computeBoundingSphere(),Ga.copy(t.boundingSphere).applyMatrix4(e.matrixWorld)}return this.intersectsSphere(Ga)}intersectsSprite(e){Ga.center.set(0,0,0);const t=O3.distanceTo(e.center);return Ga.radius=.7071067811865476+t,Ga.applyMatrix4(e.matrixWorld),this.intersectsSphere(Ga)}intersectsSphere(e){const t=this.planes,i=e.center,n=-e.radius;for(let s=0;s<6;s++)if(t[s].distanceToPoint(i)<n)return!1;return!0}intersectsBox(e){const t=this.planes;for(let i=0;i<6;i++){const n=t[i];if(fd.x=n.normal.x>0?e.max.x:e.min.x,fd.y=n.normal.y>0?e.max.y:e.min.y,fd.z=n.normal.z>0?e.max.z:e.min.z,n.distanceToPoint(fd)<0)return!1}return!0}containsPoint(e){const t=this.planes;for(let i=0;i<6;i++)if(t[i].distanceToPoint(e)<0)return!1;return!0}clone(){return new this.constructor().copy(this)}}class N3 extends Ar{constructor(e){super(),this.isLineBasicMaterial=!0,this.type="LineBasicMaterial",this.color=new ne(16777215),this.map=null,this.linewidth=1,this.linecap="round",this.linejoin="round",this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.linewidth=e.linewidth,this.linecap=e.linecap,this.linejoin=e.linejoin,this.fog=e.fog,this}}const Yu=new D,qu=new D,C1=new lt,Ic=new Ch,pd=new qr,yp=new D,k1=new D;class pw extends hi{constructor(e=new ot,t=new N3){super(),this.isLine=!0,this.type="Line",this.geometry=e,this.material=t,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.updateMorphTargets()}copy(e,t){return super.copy(e,t),this.material=Array.isArray(e.material)?e.material.slice():e.material,this.geometry=e.geometry,this}computeLineDistances(){const e=this.geometry;if(e.index===null){const t=e.attributes.position,i=[0];for(let n=1,s=t.count;n<s;n++)Yu.fromBufferAttribute(t,n-1),qu.fromBufferAttribute(t,n),i[n]=i[n-1],i[n]+=Yu.distanceTo(qu);e.setAttribute("lineDistance",new yt(i,1))}else ke("Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.");return this}raycast(e,t){const i=this.geometry,n=this.matrixWorld,s=e.params.Line.threshold,r=i.drawRange;if(i.boundingSphere===null&&i.computeBoundingSphere(),pd.copy(i.boundingSphere),pd.applyMatrix4(n),pd.radius+=s,e.ray.intersectsSphere(pd)===!1)return;C1.copy(n).invert(),Ic.copy(e.ray).applyMatrix4(C1);const a=s/((this.scale.x+this.scale.y+this.scale.z)/3),l=a*a,c=this.isLineSegments?2:1,h=i.index,u=i.attributes.position;if(h!==null){const f=Math.max(0,r.start),p=Math.min(h.count,r.start+r.count);for(let g=f,m=p-1;g<m;g+=c){const v=h.getX(g),b=h.getX(g+1),x=md(this,e,Ic,l,v,b,g);x&&t.push(x)}if(this.isLineLoop){const g=h.getX(p-1),m=h.getX(f),v=md(this,e,Ic,l,g,m,p-1);v&&t.push(v)}}else{const f=Math.max(0,r.start),p=Math.min(u.count,r.start+r.count);for(let g=f,m=p-1;g<m;g+=c){const v=md(this,e,Ic,l,g,g+1,g);v&&t.push(v)}if(this.isLineLoop){const g=md(this,e,Ic,l,p-1,f,p-1);g&&t.push(g)}}}updateMorphTargets(){const t=this.geometry.morphAttributes,i=Object.keys(t);if(i.length>0){const n=t[i[0]];if(n!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let s=0,r=n.length;s<r;s++){const a=n[s].name||String(s);this.morphTargetInfluences.push(0),this.morphTargetDictionary[a]=s}}}}}function md(o,e,t,i,n,s,r){const a=o.geometry.attributes.position;if(Yu.fromBufferAttribute(a,n),qu.fromBufferAttribute(a,s),t.distanceSqToSegment(Yu,qu,yp,k1)>i)return;yp.applyMatrix4(o.matrixWorld);const c=e.ray.origin.distanceTo(yp);if(!(c<e.near||c>e.far))return{distance:c,point:k1.clone().applyMatrix4(o.matrixWorld),index:r,face:null,faceIndex:null,barycoord:null,object:o}}const P1=new D,L1=new D;class Xk extends pw{constructor(e,t){super(e,t),this.isLineSegments=!0,this.type="LineSegments"}computeLineDistances(){const e=this.geometry;if(e.index===null){const t=e.attributes.position,i=[];for(let n=0,s=t.count;n<s;n+=2)P1.fromBufferAttribute(t,n),L1.fromBufferAttribute(t,n+1),i[n]=n===0?0:i[n-1],i[n+1]=i[n]+P1.distanceTo(L1);e.setAttribute("lineDistance",new yt(i,1))}else ke("LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.");return this}}class $k extends pw{constructor(e,t){super(e,t),this.isLineLoop=!0,this.type="LineLoop"}}class um extends Ar{constructor(e){super(),this.isPointsMaterial=!0,this.type="PointsMaterial",this.color=new ne(16777215),this.map=null,this.alphaMap=null,this.size=1,this.sizeAttenuation=!0,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.alphaMap=e.alphaMap,this.size=e.size,this.sizeAttenuation=e.sizeAttenuation,this.fog=e.fog,this}}const O1=new lt,fm=new Ch,gd=new qr,vd=new D;class ls extends hi{constructor(e=new ot,t=new um){super(),this.isPoints=!0,this.type="Points",this.geometry=e,this.material=t,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.updateMorphTargets()}copy(e,t){return super.copy(e,t),this.material=Array.isArray(e.material)?e.material.slice():e.material,this.geometry=e.geometry,this}raycast(e,t){const i=this.geometry,n=this.matrixWorld,s=e.params.Points.threshold,r=i.drawRange;if(i.boundingSphere===null&&i.computeBoundingSphere(),gd.copy(i.boundingSphere),gd.applyMatrix4(n),gd.radius+=s,e.ray.intersectsSphere(gd)===!1)return;O1.copy(n).invert(),fm.copy(e.ray).applyMatrix4(O1);const a=s/((this.scale.x+this.scale.y+this.scale.z)/3),l=a*a,c=i.index,d=i.attributes.position;if(c!==null){const u=Math.max(0,r.start),f=Math.min(c.count,r.start+r.count);for(let p=u,g=f;p<g;p++){const m=c.getX(p);vd.fromBufferAttribute(d,m),N1(vd,m,l,n,e,t,this)}}else{const u=Math.max(0,r.start),f=Math.min(d.count,r.start+r.count);for(let p=u,g=f;p<g;p++)vd.fromBufferAttribute(d,p),N1(vd,p,l,n,e,t,this)}}updateMorphTargets(){const t=this.geometry.morphAttributes,i=Object.keys(t);if(i.length>0){const n=t[i[0]];if(n!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let s=0,r=n.length;s<r;s++){const a=n[s].name||String(s);this.morphTargetInfluences.push(0),this.morphTargetDictionary[a]=s}}}}}function N1(o,e,t,i,n,s,r){const a=fm.distanceSqToPoint(o);if(a<t){const l=new D;fm.closestPointToPoint(o,l),l.applyMatrix4(i);const c=n.ray.origin.distanceTo(l);if(c<n.near||c>n.far)return;s.push({distance:c,distanceToRay:Math.sqrt(a),point:l,index:e,face:null,faceIndex:null,barycoord:null,object:r})}}class mw extends ln{constructor(e=[],t=Oo,i,n,s,r,a,l,c,h){super(e,t,i,n,s,r,a,l,c,h),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(e){this.image=e}}class Kr extends ln{constructor(e,t,i,n,s,r,a,l,c){super(e,t,i,n,s,r,a,l,c),this.isCanvasTexture=!0,this.needsUpdate=!0}}class La extends ln{constructor(e,t,i=Ts,n,s,r,a=Qt,l=Qt,c,h=Wr,d=1){if(h!==Wr&&h!==bo)throw new Error("THREE.DepthTexture: format must be either THREE.DepthFormat or THREE.DepthStencilFormat");const u={width:e,height:t,depth:d};super(u,n,s,r,a,l,h,i,c),this.isDepthTexture=!0,this.flipY=!1,this.generateMipmaps=!1,this.compareFunction=null}copy(e){return super.copy(e),this.source=new yg(Object.assign({},e.image)),this.compareFunction=e.compareFunction,this}toJSON(e){const t=super.toJSON(e);return this.compareFunction!==null&&(t.compareFunction=this.compareFunction),t}}class F3 extends La{constructor(e,t=Ts,i=Oo,n,s,r=Qt,a=Qt,l,c=Wr){const h={width:e,height:e,depth:1},d=[h,h,h,h,h,h];super(e,e,t,i,n,s,r,a,l,c),this.image=d,this.isCubeDepthTexture=!0,this.isCubeTexture=!0}get images(){return this.image}set images(e){this.image=e}}class gw extends ln{constructor(e=null){super(),this.sourceTexture=e,this.isExternalTexture=!0}copy(e){return super.copy(e),this.sourceTexture=e.sourceTexture,this}}class cn extends ot{constructor(e=1,t=1,i=1,n=1,s=1,r=1){super(),this.type="BoxGeometry",this.parameters={width:e,height:t,depth:i,widthSegments:n,heightSegments:s,depthSegments:r};const a=this;n=Math.floor(n),s=Math.floor(s),r=Math.floor(r);const l=[],c=[],h=[],d=[];let u=0,f=0;p("z","y","x",-1,-1,i,t,e,r,s,0),p("z","y","x",1,-1,i,t,-e,r,s,1),p("x","z","y",1,1,e,i,t,n,r,2),p("x","z","y",1,-1,e,i,-t,n,r,3),p("x","y","z",1,-1,e,t,i,n,s,4),p("x","y","z",-1,-1,e,t,-i,n,s,5),this.setIndex(l),this.setAttribute("position",new yt(c,3)),this.setAttribute("normal",new yt(h,3)),this.setAttribute("uv",new yt(d,2));function p(g,m,v,b,x,y,w,S,A,M,_){const I=y/A,R=w/M,L=y/2,P=w/2,O=S/2,k=A+1,F=M+1;let z=0,V=0;const K=new D;for(let q=0;q<F;q++){const te=q*R-P;for(let re=0;re<k;re++){const Ge=re*I-L;K[g]=Ge*b,K[m]=te*x,K[v]=O,c.push(K.x,K.y,K.z),K[g]=0,K[m]=0,K[v]=S>0?1:-1,h.push(K.x,K.y,K.z),d.push(re/A),d.push(1-q/M),z+=1}}for(let q=0;q<M;q++)for(let te=0;te<A;te++){const re=u+te+k*q,Ge=u+te+k*(q+1),ft=u+(te+1)+k*(q+1),it=u+(te+1)+k*q;l.push(re,Ge,it),l.push(Ge,ft,it),V+=6}a.addGroup(f,V,_),f+=V,u+=z}}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new cn(e.width,e.height,e.depth,e.widthSegments,e.heightSegments,e.depthSegments)}}class Sg extends ot{constructor(e=1,t=32,i=0,n=Math.PI*2){super(),this.type="CircleGeometry",this.parameters={radius:e,segments:t,thetaStart:i,thetaLength:n},t=Math.max(3,t);const s=[],r=[],a=[],l=[],c=new D,h=new we;r.push(0,0,0),a.push(0,0,1),l.push(.5,.5);for(let d=0,u=3;d<=t;d++,u+=3){const f=i+d/t*n;c.x=e*Math.cos(f),c.y=e*Math.sin(f),r.push(c.x,c.y,c.z),a.push(0,0,1),h.x=(r[u]/e+1)/2,h.y=(r[u+1]/e+1)/2,l.push(h.x,h.y)}for(let d=1;d<=t;d++)s.push(d,d+1,0);this.setIndex(s),this.setAttribute("position",new yt(r,3)),this.setAttribute("normal",new yt(a,3)),this.setAttribute("uv",new yt(l,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new Sg(e.radius,e.segments,e.thetaStart,e.thetaLength)}}class ms extends ot{constructor(e=1,t=1,i=1,n=32,s=1,r=!1,a=0,l=Math.PI*2){super(),this.type="CylinderGeometry",this.parameters={radiusTop:e,radiusBottom:t,height:i,radialSegments:n,heightSegments:s,openEnded:r,thetaStart:a,thetaLength:l};const c=this;n=Math.floor(n),s=Math.floor(s);const h=[],d=[],u=[],f=[];let p=0;const g=[],m=i/2;let v=0;b(),r===!1&&(e>0&&x(!0),t>0&&x(!1)),this.setIndex(h),this.setAttribute("position",new yt(d,3)),this.setAttribute("normal",new yt(u,3)),this.setAttribute("uv",new yt(f,2));function b(){const y=new D,w=new D;let S=0;const A=(t-e)/i;for(let M=0;M<=s;M++){const _=[],I=M/s,R=I*(t-e)+e;for(let L=0;L<=n;L++){const P=L/n,O=P*l+a,k=Math.sin(O),F=Math.cos(O);w.x=R*k,w.y=-I*i+m,w.z=R*F,d.push(w.x,w.y,w.z),y.set(k,A,F).normalize(),u.push(y.x,y.y,y.z),f.push(P,1-I),_.push(p++)}g.push(_)}for(let M=0;M<n;M++)for(let _=0;_<s;_++){const I=g[_][M],R=g[_+1][M],L=g[_+1][M+1],P=g[_][M+1];(e>0||_!==0)&&(h.push(I,R,P),S+=3),(t>0||_!==s-1)&&(h.push(R,L,P),S+=3)}c.addGroup(v,S,0),v+=S}function x(y){const w=p,S=new we,A=new D;let M=0;const _=y===!0?e:t,I=y===!0?1:-1;for(let L=1;L<=n;L++)d.push(0,m*I,0),u.push(0,I,0),f.push(.5,.5),p++;const R=p;for(let L=0;L<=n;L++){const O=L/n*l+a,k=Math.cos(O),F=Math.sin(O);A.x=_*F,A.y=m*I,A.z=_*k,d.push(A.x,A.y,A.z),u.push(0,I,0),S.x=k*.5+.5,S.y=F*.5*I+.5,f.push(S.x,S.y),p++}for(let L=0;L<n;L++){const P=w+L,O=R+L;y===!0?h.push(O,O+1,P):h.push(O+1,O,P),M+=3}c.addGroup(v,M,y===!0?1:2),v+=M}}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new ms(e.radiusTop,e.radiusBottom,e.height,e.radialSegments,e.heightSegments,e.openEnded,e.thetaStart,e.thetaLength)}}class uc extends ms{constructor(e=1,t=1,i=32,n=1,s=!1,r=0,a=Math.PI*2){super(0,e,t,i,n,s,r,a),this.type="ConeGeometry",this.parameters={radius:e,height:t,radialSegments:i,heightSegments:n,openEnded:s,thetaStart:r,thetaLength:a}}static fromJSON(e){return new uc(e.radius,e.height,e.radialSegments,e.heightSegments,e.openEnded,e.thetaStart,e.thetaLength)}}class Ef extends ot{constructor(e=[new we(0,-.5),new we(.5,0),new we(0,.5)],t=12,i=0,n=Math.PI*2){super(),this.type="LatheGeometry",this.parameters={points:e,segments:t,phiStart:i,phiLength:n},t=Math.floor(t),n=nt(n,0,Math.PI*2);const s=[],r=[],a=[],l=[],c=[],h=1/t,d=new D,u=new we,f=new D,p=new D,g=new D;let m=0,v=0;for(let b=0;b<=e.length-1;b++)switch(b){case 0:m=e[b+1].x-e[b].x,v=e[b+1].y-e[b].y,f.x=v*1,f.y=-m,f.z=v*0,g.copy(f),f.normalize(),l.push(f.x,f.y,f.z);break;case e.length-1:l.push(g.x,g.y,g.z);break;default:m=e[b+1].x-e[b].x,v=e[b+1].y-e[b].y,f.x=v*1,f.y=-m,f.z=v*0,p.copy(f),f.x+=g.x,f.y+=g.y,f.z+=g.z,f.normalize(),l.push(f.x,f.y,f.z),g.copy(p)}for(let b=0;b<=t;b++){const x=i+b*h*n,y=Math.sin(x),w=Math.cos(x);for(let S=0;S<=e.length-1;S++){d.x=e[S].x*y,d.y=e[S].y,d.z=e[S].x*w,r.push(d.x,d.y,d.z),u.x=b/t,u.y=S/(e.length-1),a.push(u.x,u.y);const A=l[3*S+0]*y,M=l[3*S+1],_=l[3*S+0]*w;c.push(A,M,_)}}for(let b=0;b<t;b++)for(let x=0;x<e.length-1;x++){const y=x+b*e.length,w=y,S=y+e.length,A=y+e.length+1,M=y+1;s.push(w,S,M),s.push(A,M,S)}this.setIndex(s),this.setAttribute("position",new yt(r,3)),this.setAttribute("uv",new yt(a,2)),this.setAttribute("normal",new yt(c,3))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new Ef(e.points,e.segments,e.phiStart,e.phiLength)}}class Gn extends ot{constructor(e=1,t=1,i=1,n=1){super(),this.type="PlaneGeometry",this.parameters={width:e,height:t,widthSegments:i,heightSegments:n};const s=e/2,r=t/2,a=Math.floor(i),l=Math.floor(n),c=a+1,h=l+1,d=e/a,u=t/l,f=[],p=[],g=[],m=[];for(let v=0;v<h;v++){const b=v*u-r;for(let x=0;x<c;x++){const y=x*d-s;p.push(y,-b,0),g.push(0,0,1),m.push(x/a),m.push(1-v/l)}}for(let v=0;v<l;v++)for(let b=0;b<a;b++){const x=b+c*v,y=b+c*(v+1),w=b+1+c*(v+1),S=b+1+c*v;f.push(x,y,S),f.push(y,w,S)}this.setIndex(f),this.setAttribute("position",new yt(p,3)),this.setAttribute("normal",new yt(g,3)),this.setAttribute("uv",new yt(m,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new Gn(e.width,e.height,e.widthSegments,e.heightSegments)}}class Ii extends ot{constructor(e=1,t=32,i=16,n=0,s=Math.PI*2,r=0,a=Math.PI){super(),this.type="SphereGeometry",this.parameters={radius:e,widthSegments:t,heightSegments:i,phiStart:n,phiLength:s,thetaStart:r,thetaLength:a},t=Math.max(3,Math.floor(t)),i=Math.max(2,Math.floor(i));const l=Math.min(r+a,Math.PI);let c=0;const h=[],d=new D,u=new D,f=[],p=[],g=[],m=[];for(let v=0;v<=i;v++){const b=[],x=v/i,y=r+x*a,w=e*Math.cos(y),S=Math.sqrt(e*e-w*w);let A=0;v===0&&r===0?A=.5/t:v===i&&l===Math.PI&&(A=-.5/t);for(let M=0;M<=t;M++){const _=M/t,I=n+_*s;d.x=-S*Math.cos(I),d.y=w,d.z=S*Math.sin(I),p.push(d.x,d.y,d.z),u.copy(d).normalize(),g.push(u.x,u.y,u.z),m.push(_+A,1-x),b.push(c++)}h.push(b)}for(let v=0;v<i;v++)for(let b=0;b<t;b++){const x=h[v][b+1],y=h[v][b],w=h[v+1][b],S=h[v+1][b+1];(v!==0||r>0)&&f.push(x,y,S),(v!==i-1||l<Math.PI)&&f.push(y,w,S)}this.setIndex(f),this.setAttribute("position",new yt(p,3)),this.setAttribute("normal",new yt(g,3)),this.setAttribute("uv",new yt(m,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new Ii(e.radius,e.widthSegments,e.heightSegments,e.phiStart,e.phiLength,e.thetaStart,e.thetaLength)}}class Eg extends ot{constructor(e=1,t=.4,i=12,n=48,s=Math.PI*2,r=0,a=Math.PI*2){super(),this.type="TorusGeometry",this.parameters={radius:e,tube:t,radialSegments:i,tubularSegments:n,arc:s,thetaStart:r,thetaLength:a},i=Math.floor(i),n=Math.floor(n);const l=[],c=[],h=[],d=[],u=new D,f=new D,p=new D;for(let g=0;g<=i;g++){const m=r+g/i*a;for(let v=0;v<=n;v++){const b=v/n*s;f.x=(e+t*Math.cos(m))*Math.cos(b),f.y=(e+t*Math.cos(m))*Math.sin(b),f.z=t*Math.sin(m),c.push(f.x,f.y,f.z),u.x=e*Math.cos(b),u.y=e*Math.sin(b),p.subVectors(f,u).normalize(),h.push(p.x,p.y,p.z),d.push(v/n),d.push(g/i)}}for(let g=1;g<=i;g++)for(let m=1;m<=n;m++){const v=(n+1)*g+m-1,b=(n+1)*(g-1)+m-1,x=(n+1)*(g-1)+m,y=(n+1)*g+m;l.push(v,b,y),l.push(b,x,y)}this.setIndex(l),this.setAttribute("position",new yt(c,3)),this.setAttribute("normal",new yt(h,3)),this.setAttribute("uv",new yt(d,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new Eg(e.radius,e.tube,e.radialSegments,e.tubularSegments,e.arc)}}class Yk extends ot{constructor(e=null){if(super(),this.type="WireframeGeometry",this.parameters={geometry:e},e!==null){const t=[],i=new Set,n=new D,s=new D;if(e.index!==null){const r=e.attributes.position,a=e.index;let l=e.groups;l.length===0&&(l=[{start:0,count:a.count,materialIndex:0}]);for(let c=0,h=l.length;c<h;++c){const d=l[c],u=d.start,f=d.count;for(let p=u,g=u+f;p<g;p+=3)for(let m=0;m<3;m++){const v=a.getX(p+m),b=a.getX(p+(m+1)%3);n.fromBufferAttribute(r,v),s.fromBufferAttribute(r,b),F1(n,s,i)===!0&&(t.push(n.x,n.y,n.z),t.push(s.x,s.y,s.z))}}}else{const r=e.attributes.position;for(let a=0,l=r.count/3;a<l;a++)for(let c=0;c<3;c++){const h=3*a+c,d=3*a+(c+1)%3;n.fromBufferAttribute(r,h),s.fromBufferAttribute(r,d),F1(n,s,i)===!0&&(t.push(n.x,n.y,n.z),t.push(s.x,s.y,s.z))}}this.setAttribute("position",new yt(t,3))}}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}}function F1(o,e,t){const i=`${o.x},${o.y},${o.z}-${e.x},${e.y},${e.z}`,n=`${e.x},${e.y},${e.z}-${o.x},${o.y},${o.z}`;return t.has(i)===!0||t.has(n)===!0?!1:(t.add(i),t.add(n),!0)}function lc(o){const e={};for(const t in o){e[t]={};for(const i in o[t]){const n=o[t][i];if(U1(n))n.isRenderTargetTexture?(ke("UniformsUtils: Textures of render targets cannot be cloned via cloneUniforms() or mergeUniforms()."),e[t][i]=null):e[t][i]=n.clone();else if(Array.isArray(n))if(U1(n[0])){const s=[];for(let r=0,a=n.length;r<a;r++)s[r]=n[r].clone();e[t][i]=s}else e[t][i]=n.slice();else e[t][i]=n}}return e}function Tn(o){const e={};for(let t=0;t<o.length;t++){const i=lc(o[t]);for(const n in i)e[n]=i[n]}return e}function U1(o){return o&&(o.isColor||o.isMatrix3||o.isMatrix4||o.isVector2||o.isVector3||o.isVector4||o.isTexture||o.isQuaternion)}function U3(o){const e=[];for(let t=0;t<o.length;t++)e.push(o[t].clone());return e}function vw(o){const e=o.getRenderTarget();return e===null?o.outputColorSpace:e.isXRRenderTarget===!0?e.texture.colorSpace:Tt.workingColorSpace}const B3={clone:lc,merge:Tn};var z3=`void main() {
3159
+ */const ag="185",cE=0,Qv=1,hE=2,Zc=1,dE=2,Wc=3,Pa=0,fi=1,Bn=2,br=0,Ia=1,Wi=2,e1=3,t1=4,Rh=5,eo=100,uE=101,fE=102,pE=103,mE=104,Xc=200,yh=201,gE=202,vE=203,A0=204,bh=205,yE=206,bE=207,ME=208,wE=209,xE=210,SE=211,EE=212,AE=213,_E=214,_0=0,T0=1,I0=2,sc=3,D0=4,R0=5,C0=6,k0=7,og=0,TE=1,IE=2,Mr=0,XM=1,$M=2,YM=3,qM=4,KM=5,ZM=6,jM=7,i1="attached",DE="detached",JM=300,Oo=301,rc=302,Vf=303,Wf=304,Sf=306,No=1e3,Ti=1001,P0=1002,Qt=1003,RE=1004,Xh=1005,mt=1006,Xf=1007,gr=1008,zn=1009,QM=1010,ew=1011,Mh=1012,lg=1013,Ts=1014,En=1015,ci=1016,cg=1017,hg=1018,wh=1020,tw=35902,iw=35899,nw=1021,sw=1022,Vi=1023,Wr=1026,bo=1027,ac=1028,dg=1029,Fo=1030,ug=1031,fg=1033,Zd=33776,jd=33777,Jd=33778,Qd=33779,L0=35840,O0=35841,N0=35842,F0=35843,U0=36196,B0=37492,z0=37496,H0=37488,G0=37489,Fu=37490,V0=37491,W0=37808,X0=37809,$0=37810,Y0=37811,q0=37812,K0=37813,Z0=37814,j0=37815,J0=37816,Q0=37817,em=37818,tm=37819,im=37820,nm=37821,sm=36492,rm=36494,am=36495,om=36283,lm=36284,Uu=36285,cm=36286,rw=2200,CE=2201,kE=2202,Bu=2300,hm=2301,$f=2302,n1=2303,Tl=2400,Il=2401,zu=2402,pg=2500,PE=2501,Bk=0,zk=1,Hk=2,LE=3200,Hu=0,OE=1,ba="",an="srgb",Gu="srgb-linear",Vu="linear",Yt="srgb",Yo=7680,s1=519,NE=512,FE=513,UE=514,mg=515,BE=516,zE=517,gg=518,HE=519,dm=35044,Wu="300 es",vr=2e3,xh=2001;function GE(o){for(let e=o.length-1;e>=0;--e)if(o[e]>=65535)return!0;return!1}function VE(o){return ArrayBuffer.isView(o)&&!(o instanceof DataView)}function Sh(o){return document.createElementNS("http://www.w3.org/1999/xhtml",o)}function WE(){const o=Sh("canvas");return o.style.display="block",o}const r1={};function Xu(...o){const e="THREE."+o.shift();console.log(e,...o)}function aw(o){const e=o[0];if(typeof e=="string"&&e.startsWith("TSL:")){const t=o[1];t&&t.isStackTrace?o[0]+=" "+t.getLocation():o[1]='Stack trace not available. Enable "THREE.Node.captureStackTrace" to capture stack traces.'}return o}function ke(...o){o=aw(o);const e="THREE."+o.shift();{const t=o[0];t&&t.isStackTrace?console.warn(t.getError(e)):console.warn(e,...o)}}function je(...o){o=aw(o);const e="THREE."+o.shift();{const t=o[0];t&&t.isStackTrace?console.error(t.getError(e)):console.error(e,...o)}}function Hl(...o){const e=o.join(" ");e in r1||(r1[e]=!0,ke(...o))}function XE(o,e,t){return new Promise(function(i,n){function s(){switch(o.clientWaitSync(e,o.SYNC_FLUSH_COMMANDS_BIT,0)){case o.WAIT_FAILED:n();break;case o.TIMEOUT_EXPIRED:setTimeout(s,t);break;default:i()}}setTimeout(s,t)})}const $E={[_0]:T0,[I0]:C0,[D0]:k0,[sc]:R0,[T0]:_0,[C0]:I0,[k0]:D0,[R0]:sc};class Na{addEventListener(e,t){this._listeners===void 0&&(this._listeners={});const i=this._listeners;i[e]===void 0&&(i[e]=[]),i[e].indexOf(t)===-1&&i[e].push(t)}hasEventListener(e,t){const i=this._listeners;return i===void 0?!1:i[e]!==void 0&&i[e].indexOf(t)!==-1}removeEventListener(e,t){const i=this._listeners;if(i===void 0)return;const n=i[e];if(n!==void 0){const s=n.indexOf(t);s!==-1&&n.splice(s,1)}}dispatchEvent(e){const t=this._listeners;if(t===void 0)return;const i=t[e.type];if(i!==void 0){e.target=this;const n=i.slice(0);for(let s=0,r=n.length;s<r;s++)n[s].call(this,e);e.target=null}}}const fn=["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"];let a1=1234567;const jc=Math.PI/180,oc=180/Math.PI;function Ws(){const o=Math.random()*4294967295|0,e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,i=Math.random()*4294967295|0;return(fn[o&255]+fn[o>>8&255]+fn[o>>16&255]+fn[o>>24&255]+"-"+fn[e&255]+fn[e>>8&255]+"-"+fn[e>>16&15|64]+fn[e>>24&255]+"-"+fn[t&63|128]+fn[t>>8&255]+"-"+fn[t>>16&255]+fn[t>>24&255]+fn[i&255]+fn[i>>8&255]+fn[i>>16&255]+fn[i>>24&255]).toLowerCase()}function nt(o,e,t){return Math.max(e,Math.min(t,o))}function vg(o,e){return(o%e+e)%e}function YE(o,e,t,i,n){return i+(o-e)*(n-i)/(t-e)}function qE(o,e,t){return o!==e?(t-o)/(e-o):0}function Jc(o,e,t){return(1-t)*o+t*e}function KE(o,e,t,i){return Jc(o,e,1-Math.exp(-t*i))}function ZE(o,e=1){return e-Math.abs(vg(o,e*2)-e)}function jE(o,e,t){return o<=e?0:o>=t?1:(o=(o-e)/(t-e),o*o*(3-2*o))}function JE(o,e,t){return o<=e?0:o>=t?1:(o=(o-e)/(t-e),o*o*o*(o*(o*6-15)+10))}function QE(o,e){return o+Math.floor(Math.random()*(e-o+1))}function e3(o,e){return o+Math.random()*(e-o)}function t3(o){return o*(.5-Math.random())}function i3(o){o!==void 0&&(a1=o);let e=a1+=1831565813;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}function n3(o){return o*jc}function s3(o){return o*oc}function r3(o){return(o&o-1)===0&&o!==0}function a3(o){return Math.pow(2,Math.ceil(Math.log(o)/Math.LN2))}function o3(o){return Math.pow(2,Math.floor(Math.log(o)/Math.LN2))}function l3(o,e,t,i,n){const s=Math.cos,r=Math.sin,a=s(t/2),l=r(t/2),c=s((e+i)/2),h=r((e+i)/2),d=s((e-i)/2),u=r((e-i)/2),f=s((i-e)/2),p=r((i-e)/2);switch(n){case"XYX":o.set(a*h,l*d,l*u,a*c);break;case"YZY":o.set(l*u,a*h,l*d,a*c);break;case"ZXZ":o.set(l*d,l*u,a*h,a*c);break;case"XZX":o.set(a*h,l*p,l*f,a*c);break;case"YXY":o.set(l*f,a*h,l*p,a*c);break;case"ZYZ":o.set(l*p,l*f,a*h,a*c);break;default:ke("MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+n)}}function zs(o,e){switch(e.constructor){case Float32Array:return o;case Uint32Array:return o/4294967295;case Uint16Array:return o/65535;case Uint8Array:return o/255;case Int32Array:return Math.max(o/2147483647,-1);case Int16Array:return Math.max(o/32767,-1);case Int8Array:return Math.max(o/127,-1);default:throw new Error("THREE.MathUtils: Invalid component type.")}}function qt(o,e){switch(e.constructor){case Float32Array:return o;case Uint32Array:return Math.round(o*4294967295);case Uint16Array:return Math.round(o*65535);case Uint8Array:return Math.round(o*255);case Int32Array:return Math.round(o*2147483647);case Int16Array:return Math.round(o*32767);case Int8Array:return Math.round(o*127);default:throw new Error("THREE.MathUtils: Invalid component type.")}}const Gk={DEG2RAD:jc,RAD2DEG:oc,generateUUID:Ws,clamp:nt,euclideanModulo:vg,mapLinear:YE,inverseLerp:qE,lerp:Jc,damp:KE,pingpong:ZE,smoothstep:jE,smootherstep:JE,randInt:QE,randFloat:e3,randFloatSpread:t3,seededRandom:i3,degToRad:n3,radToDeg:s3,isPowerOfTwo:r3,ceilPowerOfTwo:a3,floorPowerOfTwo:o3,setQuaternionFromProperEuler:l3,normalize:qt,denormalize:zs};class we{static{we.prototype.isVector2=!0}constructor(e=0,t=0){this.x=e,this.y=t}get width(){return this.x}set width(e){this.x=e}get height(){return this.y}set height(e){this.y=e}set(e,t){return this.x=e,this.y=t,this}setScalar(e){return this.x=e,this.y=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;default:throw new Error("THREE.Vector2: index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;default:throw new Error("THREE.Vector2: index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}addScalar(e){return this.x+=e,this.y+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this}subScalar(e){return this.x-=e,this.y-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this}multiply(e){return this.x*=e.x,this.y*=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}divide(e){return this.x/=e.x,this.y/=e.y,this}divideScalar(e){return this.multiplyScalar(1/e)}applyMatrix3(e){const t=this.x,i=this.y,n=e.elements;return this.x=n[0]*t+n[3]*i+n[6],this.y=n[1]*t+n[4]*i+n[7],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this}clamp(e,t){return this.x=nt(this.x,e.x,t.x),this.y=nt(this.y,e.y,t.y),this}clampScalar(e,t){return this.x=nt(this.x,e,t),this.y=nt(this.y,e,t),this}clampLength(e,t){const i=this.length();return this.divideScalar(i||1).multiplyScalar(nt(i,e,t))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(e){return this.x*e.x+this.y*e.y}cross(e){return this.x*e.y-this.y*e.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(e){const t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;const i=this.dot(e)/t;return Math.acos(nt(i,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,i=this.y-e.y;return t*t+i*i}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this}lerpVectors(e,t,i){return this.x=e.x+(t.x-e.x)*i,this.y=e.y+(t.y-e.y)*i,this}equals(e){return e.x===this.x&&e.y===this.y}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this}rotateAround(e,t){const i=Math.cos(t),n=Math.sin(t),s=this.x-e.x,r=this.y-e.y;return this.x=s*i-r*n+e.x,this.y=s*n+r*i+e.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class An{constructor(e=0,t=0,i=0,n=1){this.isQuaternion=!0,this._x=e,this._y=t,this._z=i,this._w=n}static slerpFlat(e,t,i,n,s,r,a){let l=i[n+0],c=i[n+1],h=i[n+2],d=i[n+3],u=s[r+0],f=s[r+1],p=s[r+2],g=s[r+3];if(d!==g||l!==u||c!==f||h!==p){let m=l*u+c*f+h*p+d*g;m<0&&(u=-u,f=-f,p=-p,g=-g,m=-m);let v=1-a;if(m<.9995){const b=Math.acos(m),x=Math.sin(b);v=Math.sin(v*b)/x,a=Math.sin(a*b)/x,l=l*v+u*a,c=c*v+f*a,h=h*v+p*a,d=d*v+g*a}else{l=l*v+u*a,c=c*v+f*a,h=h*v+p*a,d=d*v+g*a;const b=1/Math.sqrt(l*l+c*c+h*h+d*d);l*=b,c*=b,h*=b,d*=b}}e[t]=l,e[t+1]=c,e[t+2]=h,e[t+3]=d}static multiplyQuaternionsFlat(e,t,i,n,s,r){const a=i[n],l=i[n+1],c=i[n+2],h=i[n+3],d=s[r],u=s[r+1],f=s[r+2],p=s[r+3];return e[t]=a*p+h*d+l*f-c*u,e[t+1]=l*p+h*u+c*d-a*f,e[t+2]=c*p+h*f+a*u-l*d,e[t+3]=h*p-a*d-l*u-c*f,e}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get w(){return this._w}set w(e){this._w=e,this._onChangeCallback()}set(e,t,i,n){return this._x=e,this._y=t,this._z=i,this._w=n,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback(),this}setFromEuler(e,t=!0){const i=e._x,n=e._y,s=e._z,r=e._order,a=Math.cos,l=Math.sin,c=a(i/2),h=a(n/2),d=a(s/2),u=l(i/2),f=l(n/2),p=l(s/2);switch(r){case"XYZ":this._x=u*h*d+c*f*p,this._y=c*f*d-u*h*p,this._z=c*h*p+u*f*d,this._w=c*h*d-u*f*p;break;case"YXZ":this._x=u*h*d+c*f*p,this._y=c*f*d-u*h*p,this._z=c*h*p-u*f*d,this._w=c*h*d+u*f*p;break;case"ZXY":this._x=u*h*d-c*f*p,this._y=c*f*d+u*h*p,this._z=c*h*p+u*f*d,this._w=c*h*d-u*f*p;break;case"ZYX":this._x=u*h*d-c*f*p,this._y=c*f*d+u*h*p,this._z=c*h*p-u*f*d,this._w=c*h*d+u*f*p;break;case"YZX":this._x=u*h*d+c*f*p,this._y=c*f*d+u*h*p,this._z=c*h*p-u*f*d,this._w=c*h*d-u*f*p;break;case"XZY":this._x=u*h*d-c*f*p,this._y=c*f*d-u*h*p,this._z=c*h*p+u*f*d,this._w=c*h*d+u*f*p;break;default:ke("Quaternion: .setFromEuler() encountered an unknown order: "+r)}return t===!0&&this._onChangeCallback(),this}setFromAxisAngle(e,t){const i=t/2,n=Math.sin(i);return this._x=e.x*n,this._y=e.y*n,this._z=e.z*n,this._w=Math.cos(i),this._onChangeCallback(),this}setFromRotationMatrix(e){const t=e.elements,i=t[0],n=t[4],s=t[8],r=t[1],a=t[5],l=t[9],c=t[2],h=t[6],d=t[10],u=i+a+d;if(u>0){const f=.5/Math.sqrt(u+1);this._w=.25/f,this._x=(h-l)*f,this._y=(s-c)*f,this._z=(r-n)*f}else if(i>a&&i>d){const f=2*Math.sqrt(1+i-a-d);this._w=(h-l)/f,this._x=.25*f,this._y=(n+r)/f,this._z=(s+c)/f}else if(a>d){const f=2*Math.sqrt(1+a-i-d);this._w=(s-c)/f,this._x=(n+r)/f,this._y=.25*f,this._z=(l+h)/f}else{const f=2*Math.sqrt(1+d-i-a);this._w=(r-n)/f,this._x=(s+c)/f,this._y=(l+h)/f,this._z=.25*f}return this._onChangeCallback(),this}setFromUnitVectors(e,t){let i=e.dot(t)+1;return i<1e-8?(i=0,Math.abs(e.x)>Math.abs(e.z)?(this._x=-e.y,this._y=e.x,this._z=0,this._w=i):(this._x=0,this._y=-e.z,this._z=e.y,this._w=i)):(this._x=e.y*t.z-e.z*t.y,this._y=e.z*t.x-e.x*t.z,this._z=e.x*t.y-e.y*t.x,this._w=i),this.normalize()}angleTo(e){return 2*Math.acos(Math.abs(nt(this.dot(e),-1,1)))}rotateTowards(e,t){const i=this.angleTo(e);if(i===0)return this;const n=Math.min(1,t/i);return this.slerp(e,n),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(e){return this._x*e._x+this._y*e._y+this._z*e._z+this._w*e._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let e=this.length();return e===0?(this._x=0,this._y=0,this._z=0,this._w=1):(e=1/e,this._x=this._x*e,this._y=this._y*e,this._z=this._z*e,this._w=this._w*e),this._onChangeCallback(),this}multiply(e){return this.multiplyQuaternions(this,e)}premultiply(e){return this.multiplyQuaternions(e,this)}multiplyQuaternions(e,t){const i=e._x,n=e._y,s=e._z,r=e._w,a=t._x,l=t._y,c=t._z,h=t._w;return this._x=i*h+r*a+n*c-s*l,this._y=n*h+r*l+s*a-i*c,this._z=s*h+r*c+i*l-n*a,this._w=r*h-i*a-n*l-s*c,this._onChangeCallback(),this}slerp(e,t){let i=e._x,n=e._y,s=e._z,r=e._w,a=this.dot(e);a<0&&(i=-i,n=-n,s=-s,r=-r,a=-a);let l=1-t;if(a<.9995){const c=Math.acos(a),h=Math.sin(c);l=Math.sin(l*c)/h,t=Math.sin(t*c)/h,this._x=this._x*l+i*t,this._y=this._y*l+n*t,this._z=this._z*l+s*t,this._w=this._w*l+r*t,this._onChangeCallback()}else this._x=this._x*l+i*t,this._y=this._y*l+n*t,this._z=this._z*l+s*t,this._w=this._w*l+r*t,this.normalize();return this}slerpQuaternions(e,t,i){return this.copy(e).slerp(t,i)}random(){const e=2*Math.PI*Math.random(),t=2*Math.PI*Math.random(),i=Math.random(),n=Math.sqrt(1-i),s=Math.sqrt(i);return this.set(n*Math.sin(e),n*Math.cos(e),s*Math.sin(t),s*Math.cos(t))}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._w===this._w}fromArray(e,t=0){return this._x=e[t],this._y=e[t+1],this._z=e[t+2],this._w=e[t+3],this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._w,e}fromBufferAttribute(e,t){return this._x=e.getX(t),this._y=e.getY(t),this._z=e.getZ(t),this._w=e.getW(t),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class D{static{D.prototype.isVector3=!0}constructor(e=0,t=0,i=0){this.x=e,this.y=t,this.z=i}set(e,t,i){return i===void 0&&(i=this.z),this.x=e,this.y=t,this.z=i,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;default:throw new Error("THREE.Vector3: index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("THREE.Vector3: index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}multiplyVectors(e,t){return this.x=e.x*t.x,this.y=e.y*t.y,this.z=e.z*t.z,this}applyEuler(e){return this.applyQuaternion(o1.setFromEuler(e))}applyAxisAngle(e,t){return this.applyQuaternion(o1.setFromAxisAngle(e,t))}applyMatrix3(e){const t=this.x,i=this.y,n=this.z,s=e.elements;return this.x=s[0]*t+s[3]*i+s[6]*n,this.y=s[1]*t+s[4]*i+s[7]*n,this.z=s[2]*t+s[5]*i+s[8]*n,this}applyNormalMatrix(e){return this.applyMatrix3(e).normalize()}applyMatrix4(e){const t=this.x,i=this.y,n=this.z,s=e.elements,r=1/(s[3]*t+s[7]*i+s[11]*n+s[15]);return this.x=(s[0]*t+s[4]*i+s[8]*n+s[12])*r,this.y=(s[1]*t+s[5]*i+s[9]*n+s[13])*r,this.z=(s[2]*t+s[6]*i+s[10]*n+s[14])*r,this}applyQuaternion(e){const t=this.x,i=this.y,n=this.z,s=e.x,r=e.y,a=e.z,l=e.w,c=2*(r*n-a*i),h=2*(a*t-s*n),d=2*(s*i-r*t);return this.x=t+l*c+r*d-a*h,this.y=i+l*h+a*c-s*d,this.z=n+l*d+s*h-r*c,this}project(e){return this.applyMatrix4(e.matrixWorldInverse).applyMatrix4(e.projectionMatrix)}unproject(e){return this.applyMatrix4(e.projectionMatrixInverse).applyMatrix4(e.matrixWorld)}transformDirection(e){const t=this.x,i=this.y,n=this.z,s=e.elements;return this.x=s[0]*t+s[4]*i+s[8]*n,this.y=s[1]*t+s[5]*i+s[9]*n,this.z=s[2]*t+s[6]*i+s[10]*n,this.normalize()}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this}divideScalar(e){return this.multiplyScalar(1/e)}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this}clamp(e,t){return this.x=nt(this.x,e.x,t.x),this.y=nt(this.y,e.y,t.y),this.z=nt(this.z,e.z,t.z),this}clampScalar(e,t){return this.x=nt(this.x,e,t),this.y=nt(this.y,e,t),this.z=nt(this.z,e,t),this}clampLength(e,t){const i=this.length();return this.divideScalar(i||1).multiplyScalar(nt(i,e,t))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this}lerpVectors(e,t,i){return this.x=e.x+(t.x-e.x)*i,this.y=e.y+(t.y-e.y)*i,this.z=e.z+(t.z-e.z)*i,this}cross(e){return this.crossVectors(this,e)}crossVectors(e,t){const i=e.x,n=e.y,s=e.z,r=t.x,a=t.y,l=t.z;return this.x=n*l-s*a,this.y=s*r-i*l,this.z=i*a-n*r,this}projectOnVector(e){const t=e.lengthSq();if(t===0)return this.set(0,0,0);const i=e.dot(this)/t;return this.copy(e).multiplyScalar(i)}projectOnPlane(e){return Yf.copy(this).projectOnVector(e),this.sub(Yf)}reflect(e){return this.sub(Yf.copy(e).multiplyScalar(2*this.dot(e)))}angleTo(e){const t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;const i=this.dot(e)/t;return Math.acos(nt(i,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,i=this.y-e.y,n=this.z-e.z;return t*t+i*i+n*n}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)+Math.abs(this.z-e.z)}setFromSpherical(e){return this.setFromSphericalCoords(e.radius,e.phi,e.theta)}setFromSphericalCoords(e,t,i){const n=Math.sin(t)*e;return this.x=n*Math.sin(i),this.y=Math.cos(t)*e,this.z=n*Math.cos(i),this}setFromCylindrical(e){return this.setFromCylindricalCoords(e.radius,e.theta,e.y)}setFromCylindricalCoords(e,t,i){return this.x=e*Math.sin(t),this.y=i,this.z=e*Math.cos(t),this}setFromMatrixPosition(e){const t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this}setFromMatrixScale(e){const t=this.setFromMatrixColumn(e,0).length(),i=this.setFromMatrixColumn(e,1).length(),n=this.setFromMatrixColumn(e,2).length();return this.x=t,this.y=i,this.z=n,this}setFromMatrixColumn(e,t){return this.fromArray(e.elements,t*4)}setFromMatrix3Column(e,t){return this.fromArray(e.elements,t*3)}setFromEuler(e){return this.x=e._x,this.y=e._y,this.z=e._z,this}setFromColor(e){return this.x=e.r,this.y=e.g,this.z=e.b,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const e=Math.random()*Math.PI*2,t=Math.random()*2-1,i=Math.sqrt(1-t*t);return this.x=i*Math.cos(e),this.y=t,this.z=i*Math.sin(e),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const Yf=new D,o1=new An;class Je{static{Je.prototype.isMatrix3=!0}constructor(e,t,i,n,s,r,a,l,c){this.elements=[1,0,0,0,1,0,0,0,1],e!==void 0&&this.set(e,t,i,n,s,r,a,l,c)}set(e,t,i,n,s,r,a,l,c){const h=this.elements;return h[0]=e,h[1]=n,h[2]=a,h[3]=t,h[4]=s,h[5]=l,h[6]=i,h[7]=r,h[8]=c,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(e){const t=this.elements,i=e.elements;return t[0]=i[0],t[1]=i[1],t[2]=i[2],t[3]=i[3],t[4]=i[4],t[5]=i[5],t[6]=i[6],t[7]=i[7],t[8]=i[8],this}extractBasis(e,t,i){return e.setFromMatrix3Column(this,0),t.setFromMatrix3Column(this,1),i.setFromMatrix3Column(this,2),this}setFromMatrix4(e){const t=e.elements;return this.set(t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]),this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){const i=e.elements,n=t.elements,s=this.elements,r=i[0],a=i[3],l=i[6],c=i[1],h=i[4],d=i[7],u=i[2],f=i[5],p=i[8],g=n[0],m=n[3],v=n[6],b=n[1],x=n[4],y=n[7],w=n[2],S=n[5],A=n[8];return s[0]=r*g+a*b+l*w,s[3]=r*m+a*x+l*S,s[6]=r*v+a*y+l*A,s[1]=c*g+h*b+d*w,s[4]=c*m+h*x+d*S,s[7]=c*v+h*y+d*A,s[2]=u*g+f*b+p*w,s[5]=u*m+f*x+p*S,s[8]=u*v+f*y+p*A,this}multiplyScalar(e){const t=this.elements;return t[0]*=e,t[3]*=e,t[6]*=e,t[1]*=e,t[4]*=e,t[7]*=e,t[2]*=e,t[5]*=e,t[8]*=e,this}determinant(){const e=this.elements,t=e[0],i=e[1],n=e[2],s=e[3],r=e[4],a=e[5],l=e[6],c=e[7],h=e[8];return t*r*h-t*a*c-i*s*h+i*a*l+n*s*c-n*r*l}invert(){const e=this.elements,t=e[0],i=e[1],n=e[2],s=e[3],r=e[4],a=e[5],l=e[6],c=e[7],h=e[8],d=h*r-a*c,u=a*l-h*s,f=c*s-r*l,p=t*d+i*u+n*f;if(p===0)return this.set(0,0,0,0,0,0,0,0,0);const g=1/p;return e[0]=d*g,e[1]=(n*c-h*i)*g,e[2]=(a*i-n*r)*g,e[3]=u*g,e[4]=(h*t-n*l)*g,e[5]=(n*s-a*t)*g,e[6]=f*g,e[7]=(i*l-c*t)*g,e[8]=(r*t-i*s)*g,this}transpose(){let e;const t=this.elements;return e=t[1],t[1]=t[3],t[3]=e,e=t[2],t[2]=t[6],t[6]=e,e=t[5],t[5]=t[7],t[7]=e,this}getNormalMatrix(e){return this.setFromMatrix4(e).invert().transpose()}transposeIntoArray(e){const t=this.elements;return e[0]=t[0],e[1]=t[3],e[2]=t[6],e[3]=t[1],e[4]=t[4],e[5]=t[7],e[6]=t[2],e[7]=t[5],e[8]=t[8],this}setUvTransform(e,t,i,n,s,r,a){const l=Math.cos(s),c=Math.sin(s);return this.set(i*l,i*c,-i*(l*r+c*a)+r+e,-n*c,n*l,-n*(-c*r+l*a)+a+t,0,0,1),this}scale(e,t){return Hl("Matrix3: .scale() is deprecated. Use .makeScale() instead."),this.premultiply(qf.makeScale(e,t)),this}rotate(e){return Hl("Matrix3: .rotate() is deprecated. Use .makeRotation() instead."),this.premultiply(qf.makeRotation(-e)),this}translate(e,t){return Hl("Matrix3: .translate() is deprecated. Use .makeTranslation() instead."),this.premultiply(qf.makeTranslation(e,t)),this}makeTranslation(e,t){return e.isVector2?this.set(1,0,e.x,0,1,e.y,0,0,1):this.set(1,0,e,0,1,t,0,0,1),this}makeRotation(e){const t=Math.cos(e),i=Math.sin(e);return this.set(t,-i,0,i,t,0,0,0,1),this}makeScale(e,t){return this.set(e,0,0,0,t,0,0,0,1),this}equals(e){const t=this.elements,i=e.elements;for(let n=0;n<9;n++)if(t[n]!==i[n])return!1;return!0}fromArray(e,t=0){for(let i=0;i<9;i++)this.elements[i]=e[i+t];return this}toArray(e=[],t=0){const i=this.elements;return e[t]=i[0],e[t+1]=i[1],e[t+2]=i[2],e[t+3]=i[3],e[t+4]=i[4],e[t+5]=i[5],e[t+6]=i[6],e[t+7]=i[7],e[t+8]=i[8],e}clone(){return new this.constructor().fromArray(this.elements)}}const qf=new Je,l1=new Je().set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),c1=new Je().set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);function c3(){const o={enabled:!0,workingColorSpace:Gu,spaces:{},convert:function(n,s,r){return this.enabled===!1||s===r||!s||!r||(this.spaces[s].transfer===Yt&&(n.r=Gr(n.r),n.g=Gr(n.g),n.b=Gr(n.b)),this.spaces[s].primaries!==this.spaces[r].primaries&&(n.applyMatrix3(this.spaces[s].toXYZ),n.applyMatrix3(this.spaces[r].fromXYZ)),this.spaces[r].transfer===Yt&&(n.r=Gl(n.r),n.g=Gl(n.g),n.b=Gl(n.b))),n},workingToColorSpace:function(n,s){return this.convert(n,this.workingColorSpace,s)},colorSpaceToWorking:function(n,s){return this.convert(n,s,this.workingColorSpace)},getPrimaries:function(n){return this.spaces[n].primaries},getTransfer:function(n){return n===ba?Vu:this.spaces[n].transfer},getToneMappingMode:function(n){return this.spaces[n].outputColorSpaceConfig.toneMappingMode||"standard"},getLuminanceCoefficients:function(n,s=this.workingColorSpace){return n.fromArray(this.spaces[s].luminanceCoefficients)},define:function(n){Object.assign(this.spaces,n)},_getMatrix:function(n,s,r){return n.copy(this.spaces[s].toXYZ).multiply(this.spaces[r].fromXYZ)},_getDrawingBufferColorSpace:function(n){return this.spaces[n].outputColorSpaceConfig.drawingBufferColorSpace},_getUnpackColorSpace:function(n=this.workingColorSpace){return this.spaces[n].workingColorSpaceConfig.unpackColorSpace},fromWorkingColorSpace:function(n,s){return Hl("ColorManagement: .fromWorkingColorSpace() has been renamed to .workingToColorSpace()."),o.workingToColorSpace(n,s)},toWorkingColorSpace:function(n,s){return Hl("ColorManagement: .toWorkingColorSpace() has been renamed to .colorSpaceToWorking()."),o.colorSpaceToWorking(n,s)}},e=[.64,.33,.3,.6,.15,.06],t=[.2126,.7152,.0722],i=[.3127,.329];return o.define({[Gu]:{primaries:e,whitePoint:i,transfer:Vu,toXYZ:l1,fromXYZ:c1,luminanceCoefficients:t,workingColorSpaceConfig:{unpackColorSpace:an},outputColorSpaceConfig:{drawingBufferColorSpace:an}},[an]:{primaries:e,whitePoint:i,transfer:Yt,toXYZ:l1,fromXYZ:c1,luminanceCoefficients:t,outputColorSpaceConfig:{drawingBufferColorSpace:an}}}),o}const Tt=c3();function Gr(o){return o<.04045?o*.0773993808:Math.pow(o*.9478672986+.0521327014,2.4)}function Gl(o){return o<.0031308?o*12.92:1.055*Math.pow(o,.41666)-.055}let qo;class h3{static getDataURL(e,t="image/png"){if(/^data:/i.test(e.src)||typeof HTMLCanvasElement>"u")return e.src;let i;if(e instanceof HTMLCanvasElement)i=e;else{qo===void 0&&(qo=Sh("canvas")),qo.width=e.width,qo.height=e.height;const n=qo.getContext("2d");e instanceof ImageData?n.putImageData(e,0,0):n.drawImage(e,0,0,e.width,e.height),i=qo}return i.toDataURL(t)}static sRGBToLinear(e){if(typeof HTMLImageElement<"u"&&e instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&e instanceof ImageBitmap){const t=Sh("canvas");t.width=e.width,t.height=e.height;const i=t.getContext("2d");i.drawImage(e,0,0,e.width,e.height);const n=i.getImageData(0,0,e.width,e.height),s=n.data;for(let r=0;r<s.length;r++)s[r]=Gr(s[r]/255)*255;return i.putImageData(n,0,0),t}else if(e.data){const t=e.data.slice(0);for(let i=0;i<t.length;i++)t instanceof Uint8Array||t instanceof Uint8ClampedArray?t[i]=Math.floor(Gr(t[i]/255)*255):t[i]=Gr(t[i]);return{data:t,width:e.width,height:e.height}}else return ke("ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."),e}}let d3=0;class yg{constructor(e=null){this.isSource=!0,Object.defineProperty(this,"id",{value:d3++}),this.uuid=Ws(),this.data=e,this.dataReady=!0,this.version=0}getSize(e){const t=this.data;return typeof HTMLVideoElement<"u"&&t instanceof HTMLVideoElement?e.set(t.videoWidth,t.videoHeight,0):typeof VideoFrame<"u"&&t instanceof VideoFrame?e.set(t.displayWidth,t.displayHeight,0):t!==null?e.set(t.width,t.height,t.depth||0):e.set(0,0,0),e}set needsUpdate(e){e===!0&&this.version++}toJSON(e){const t=e===void 0||typeof e=="string";if(!t&&e.images[this.uuid]!==void 0)return e.images[this.uuid];const i={uuid:this.uuid,url:""},n=this.data;if(n!==null){let s;if(Array.isArray(n)){s=[];for(let r=0,a=n.length;r<a;r++)n[r].isDataTexture?s.push(Kf(n[r].image)):s.push(Kf(n[r]))}else s=Kf(n);i.url=s}return t||(e.images[this.uuid]=i),i}}function Kf(o){return typeof HTMLImageElement<"u"&&o instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&o instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&o instanceof ImageBitmap?h3.getDataURL(o):o.data?{data:Array.from(o.data),width:o.width,height:o.height,type:o.data.constructor.name}:(ke("Texture: Unable to serialize Texture."),{})}let u3=0;const Zf=new D;class ln extends Na{constructor(e=ln.DEFAULT_IMAGE,t=ln.DEFAULT_MAPPING,i=Ti,n=Ti,s=mt,r=gr,a=Vi,l=zn,c=ln.DEFAULT_ANISOTROPY,h=ba){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:u3++}),this.uuid=Ws(),this.name="",this.source=new yg(e),this.mipmaps=[],this.mapping=t,this.channel=0,this.wrapS=i,this.wrapT=n,this.magFilter=s,this.minFilter=r,this.anisotropy=c,this.format=a,this.internalFormat=null,this.type=l,this.offset=new we(0,0),this.repeat=new we(1,1),this.center=new we(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new Je,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.colorSpace=h,this.userData={},this.updateRanges=[],this.version=0,this.onUpdate=null,this.renderTarget=null,this.isRenderTargetTexture=!1,this.isArrayTexture=!!(e&&e.depth&&e.depth>1),this.pmremVersion=0,this.normalized=!1}get width(){return this.source.getSize(Zf).x}get height(){return this.source.getSize(Zf).y}get depth(){return this.source.getSize(Zf).z}get image(){return this.source.data}set image(e){this.source.data=e}updateMatrix(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y)}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}clone(){return new this.constructor().copy(this)}copy(e){return this.name=e.name,this.source=e.source,this.mipmaps=e.mipmaps.slice(0),this.mapping=e.mapping,this.channel=e.channel,this.wrapS=e.wrapS,this.wrapT=e.wrapT,this.magFilter=e.magFilter,this.minFilter=e.minFilter,this.anisotropy=e.anisotropy,this.format=e.format,this.internalFormat=e.internalFormat,this.type=e.type,this.normalized=e.normalized,this.offset.copy(e.offset),this.repeat.copy(e.repeat),this.center.copy(e.center),this.rotation=e.rotation,this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrix.copy(e.matrix),this.generateMipmaps=e.generateMipmaps,this.premultiplyAlpha=e.premultiplyAlpha,this.flipY=e.flipY,this.unpackAlignment=e.unpackAlignment,this.colorSpace=e.colorSpace,this.renderTarget=e.renderTarget,this.isRenderTargetTexture=e.isRenderTargetTexture,this.isArrayTexture=e.isArrayTexture,this.userData=JSON.parse(JSON.stringify(e.userData)),this.needsUpdate=!0,this}setValues(e){for(const t in e){const i=e[t];if(i===void 0){ke(`Texture.setValues(): parameter '${t}' has value of undefined.`);continue}const n=this[t];if(n===void 0){ke(`Texture.setValues(): property '${t}' does not exist.`);continue}n&&i&&n.isVector2&&i.isVector2||n&&i&&n.isVector3&&i.isVector3||n&&i&&n.isMatrix3&&i.isMatrix3?n.copy(i):this[t]=i}}toJSON(e){const t=e===void 0||typeof e=="string";if(!t&&e.textures[this.uuid]!==void 0)return e.textures[this.uuid];const i={metadata:{version:4.7,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,image:this.source.toJSON(e).uuid,mapping:this.mapping,channel:this.channel,repeat:[this.repeat.x,this.repeat.y],offset:[this.offset.x,this.offset.y],center:[this.center.x,this.center.y],rotation:this.rotation,wrap:[this.wrapS,this.wrapT],format:this.format,internalFormat:this.internalFormat,type:this.type,normalized:this.normalized,colorSpace:this.colorSpace,minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy,flipY:this.flipY,generateMipmaps:this.generateMipmaps,premultiplyAlpha:this.premultiplyAlpha,unpackAlignment:this.unpackAlignment};return Object.keys(this.userData).length>0&&(i.userData=this.userData),t||(e.textures[this.uuid]=i),i}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(e){if(this.mapping!==JM)return e;if(e.applyMatrix3(this.matrix),e.x<0||e.x>1)switch(this.wrapS){case No:e.x=e.x-Math.floor(e.x);break;case Ti:e.x=e.x<0?0:1;break;case P0:Math.abs(Math.floor(e.x)%2)===1?e.x=Math.ceil(e.x)-e.x:e.x=e.x-Math.floor(e.x);break}if(e.y<0||e.y>1)switch(this.wrapT){case No:e.y=e.y-Math.floor(e.y);break;case Ti:e.y=e.y<0?0:1;break;case P0:Math.abs(Math.floor(e.y)%2)===1?e.y=Math.ceil(e.y)-e.y:e.y=e.y-Math.floor(e.y);break}return this.flipY&&(e.y=1-e.y),e}set needsUpdate(e){e===!0&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(e){e===!0&&this.pmremVersion++}}ln.DEFAULT_IMAGE=null;ln.DEFAULT_MAPPING=JM;ln.DEFAULT_ANISOTROPY=1;class wt{static{wt.prototype.isVector4=!0}constructor(e=0,t=0,i=0,n=1){this.x=e,this.y=t,this.z=i,this.w=n}get width(){return this.z}set width(e){this.z=e}get height(){return this.w}set height(e){this.w=e}set(e,t,i,n){return this.x=e,this.y=t,this.z=i,this.w=n,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this.w=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setW(e){return this.w=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;case 3:this.w=t;break;default:throw new Error("THREE.Vector4: index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("THREE.Vector4: index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w!==void 0?e.w:1,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this.w+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this.w=e.w+t.w,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this.w+=e.w*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this.w-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this.w=e.w-t.w,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this.w*=e.w,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}applyMatrix4(e){const t=this.x,i=this.y,n=this.z,s=this.w,r=e.elements;return this.x=r[0]*t+r[4]*i+r[8]*n+r[12]*s,this.y=r[1]*t+r[5]*i+r[9]*n+r[13]*s,this.z=r[2]*t+r[6]*i+r[10]*n+r[14]*s,this.w=r[3]*t+r[7]*i+r[11]*n+r[15]*s,this}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this.w/=e.w,this}divideScalar(e){return this.multiplyScalar(1/e)}setAxisAngleFromQuaternion(e){this.w=2*Math.acos(e.w);const t=Math.sqrt(1-e.w*e.w);return t<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=e.x/t,this.y=e.y/t,this.z=e.z/t),this}setAxisAngleFromRotationMatrix(e){let t,i,n,s;const l=e.elements,c=l[0],h=l[4],d=l[8],u=l[1],f=l[5],p=l[9],g=l[2],m=l[6],v=l[10];if(Math.abs(h-u)<.01&&Math.abs(d-g)<.01&&Math.abs(p-m)<.01){if(Math.abs(h+u)<.1&&Math.abs(d+g)<.1&&Math.abs(p+m)<.1&&Math.abs(c+f+v-3)<.1)return this.set(1,0,0,0),this;t=Math.PI;const x=(c+1)/2,y=(f+1)/2,w=(v+1)/2,S=(h+u)/4,A=(d+g)/4,M=(p+m)/4;return x>y&&x>w?x<.01?(i=0,n=.707106781,s=.707106781):(i=Math.sqrt(x),n=S/i,s=A/i):y>w?y<.01?(i=.707106781,n=0,s=.707106781):(n=Math.sqrt(y),i=S/n,s=M/n):w<.01?(i=.707106781,n=.707106781,s=0):(s=Math.sqrt(w),i=A/s,n=M/s),this.set(i,n,s,t),this}let b=Math.sqrt((m-p)*(m-p)+(d-g)*(d-g)+(u-h)*(u-h));return Math.abs(b)<.001&&(b=1),this.x=(m-p)/b,this.y=(d-g)/b,this.z=(u-h)/b,this.w=Math.acos((c+f+v-1)/2),this}setFromMatrixPosition(e){const t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this.w=t[15],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this.w=Math.min(this.w,e.w),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this.w=Math.max(this.w,e.w),this}clamp(e,t){return this.x=nt(this.x,e.x,t.x),this.y=nt(this.y,e.y,t.y),this.z=nt(this.z,e.z,t.z),this.w=nt(this.w,e.w,t.w),this}clampScalar(e,t){return this.x=nt(this.x,e,t),this.y=nt(this.y,e,t),this.z=nt(this.z,e,t),this.w=nt(this.w,e,t),this}clampLength(e,t){const i=this.length();return this.divideScalar(i||1).multiplyScalar(nt(i,e,t))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z+this.w*e.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this.w+=(e.w-this.w)*t,this}lerpVectors(e,t,i){return this.x=e.x+(t.x-e.x)*i,this.y=e.y+(t.y-e.y)*i,this.z=e.z+(t.z-e.z)*i,this.w=e.w+(t.w-e.w)*i,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z&&e.w===this.w}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this.w=e[t+3],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e[t+3]=this.w,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this.w=e.getW(t),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}}class f3 extends Na{constructor(e=1,t=1,i={}){super(),i=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:mt,depthBuffer:!0,stencilBuffer:!1,resolveDepthBuffer:!0,resolveStencilBuffer:!0,depthTexture:null,samples:0,count:1,depth:1,multiview:!1,useArrayDepthTexture:!1},i),this.isRenderTarget=!0,this.width=e,this.height=t,this.depth=i.depth,this.scissor=new wt(0,0,e,t),this.scissorTest=!1,this.viewport=new wt(0,0,e,t),this.textures=[];const n={width:e,height:t,depth:i.depth},s=new ln(n),r=i.count;for(let a=0;a<r;a++)this.textures[a]=s.clone(),this.textures[a].isRenderTargetTexture=!0,this.textures[a].renderTarget=this;this._setTextureOptions(i),this.depthBuffer=i.depthBuffer,this.stencilBuffer=i.stencilBuffer,this.resolveDepthBuffer=i.resolveDepthBuffer,this.resolveStencilBuffer=i.resolveStencilBuffer,this._depthTexture=null,this.depthTexture=i.depthTexture,this.samples=i.samples,this.multiview=i.multiview,this.useArrayDepthTexture=i.useArrayDepthTexture}_setTextureOptions(e={}){const t={minFilter:mt,generateMipmaps:!1,flipY:!1,internalFormat:null};e.mapping!==void 0&&(t.mapping=e.mapping),e.wrapS!==void 0&&(t.wrapS=e.wrapS),e.wrapT!==void 0&&(t.wrapT=e.wrapT),e.wrapR!==void 0&&(t.wrapR=e.wrapR),e.magFilter!==void 0&&(t.magFilter=e.magFilter),e.minFilter!==void 0&&(t.minFilter=e.minFilter),e.format!==void 0&&(t.format=e.format),e.type!==void 0&&(t.type=e.type),e.anisotropy!==void 0&&(t.anisotropy=e.anisotropy),e.colorSpace!==void 0&&(t.colorSpace=e.colorSpace),e.flipY!==void 0&&(t.flipY=e.flipY),e.generateMipmaps!==void 0&&(t.generateMipmaps=e.generateMipmaps),e.internalFormat!==void 0&&(t.internalFormat=e.internalFormat);for(let i=0;i<this.textures.length;i++)this.textures[i].setValues(t)}get texture(){return this.textures[0]}set texture(e){this.textures[0]=e}set depthTexture(e){this._depthTexture!==null&&(this._depthTexture.renderTarget=null),e!==null&&(e.renderTarget=this),this._depthTexture=e}get depthTexture(){return this._depthTexture}setSize(e,t,i=1){if(this.width!==e||this.height!==t||this.depth!==i){this.width=e,this.height=t,this.depth=i;for(let n=0,s=this.textures.length;n<s;n++)this.textures[n].image.width=e,this.textures[n].image.height=t,this.textures[n].image.depth=i,this.textures[n].isData3DTexture!==!0&&(this.textures[n].isArrayTexture=this.textures[n].image.depth>1);this.dispose()}this.viewport.set(0,0,e,t),this.scissor.set(0,0,e,t)}clone(){return new this.constructor().copy(this)}copy(e){this.width=e.width,this.height=e.height,this.depth=e.depth,this.scissor.copy(e.scissor),this.scissorTest=e.scissorTest,this.viewport.copy(e.viewport),this.textures.length=0;for(let t=0,i=e.textures.length;t<i;t++){this.textures[t]=e.textures[t].clone(),this.textures[t].isRenderTargetTexture=!0,this.textures[t].renderTarget=this;const n=Object.assign({},e.textures[t].image);this.textures[t].source=new yg(n)}return this.depthBuffer=e.depthBuffer,this.stencilBuffer=e.stencilBuffer,this.resolveDepthBuffer=e.resolveDepthBuffer,this.resolveStencilBuffer=e.resolveStencilBuffer,e.depthTexture!==null&&(this.depthTexture=e.depthTexture.clone()),this.samples=e.samples,this.multiview=e.multiview,this.useArrayDepthTexture=e.useArrayDepthTexture,this}dispose(){this.dispatchEvent({type:"dispose"})}}class Mi extends f3{constructor(e=1,t=1,i={}){super(e,t,i),this.isWebGLRenderTarget=!0}}class ow extends ln{constructor(e=null,t=1,i=1,n=1){super(null),this.isDataArrayTexture=!0,this.image={data:e,width:t,height:i,depth:n},this.magFilter=Qt,this.minFilter=Qt,this.wrapR=Ti,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1,this.layerUpdates=new Set}addLayerUpdate(e){this.layerUpdates.add(e)}clearLayerUpdates(){this.layerUpdates.clear()}}class lw extends ln{constructor(e=null,t=1,i=1,n=1){super(null),this.isData3DTexture=!0,this.image={data:e,width:t,height:i,depth:n},this.magFilter=Qt,this.minFilter=Qt,this.wrapR=Ti,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}class lt{static{lt.prototype.isMatrix4=!0}constructor(e,t,i,n,s,r,a,l,c,h,d,u,f,p,g,m){this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],e!==void 0&&this.set(e,t,i,n,s,r,a,l,c,h,d,u,f,p,g,m)}set(e,t,i,n,s,r,a,l,c,h,d,u,f,p,g,m){const v=this.elements;return v[0]=e,v[4]=t,v[8]=i,v[12]=n,v[1]=s,v[5]=r,v[9]=a,v[13]=l,v[2]=c,v[6]=h,v[10]=d,v[14]=u,v[3]=f,v[7]=p,v[11]=g,v[15]=m,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return new lt().fromArray(this.elements)}copy(e){const t=this.elements,i=e.elements;return t[0]=i[0],t[1]=i[1],t[2]=i[2],t[3]=i[3],t[4]=i[4],t[5]=i[5],t[6]=i[6],t[7]=i[7],t[8]=i[8],t[9]=i[9],t[10]=i[10],t[11]=i[11],t[12]=i[12],t[13]=i[13],t[14]=i[14],t[15]=i[15],this}copyPosition(e){const t=this.elements,i=e.elements;return t[12]=i[12],t[13]=i[13],t[14]=i[14],this}setFromMatrix3(e){const t=e.elements;return this.set(t[0],t[3],t[6],0,t[1],t[4],t[7],0,t[2],t[5],t[8],0,0,0,0,1),this}extractBasis(e,t,i){return this.determinantAffine()===0?(e.set(1,0,0),t.set(0,1,0),i.set(0,0,1),this):(e.setFromMatrixColumn(this,0),t.setFromMatrixColumn(this,1),i.setFromMatrixColumn(this,2),this)}makeBasis(e,t,i){return this.set(e.x,t.x,i.x,0,e.y,t.y,i.y,0,e.z,t.z,i.z,0,0,0,0,1),this}extractRotation(e){if(e.determinantAffine()===0)return this.identity();const t=this.elements,i=e.elements,n=1/Ko.setFromMatrixColumn(e,0).length(),s=1/Ko.setFromMatrixColumn(e,1).length(),r=1/Ko.setFromMatrixColumn(e,2).length();return t[0]=i[0]*n,t[1]=i[1]*n,t[2]=i[2]*n,t[3]=0,t[4]=i[4]*s,t[5]=i[5]*s,t[6]=i[6]*s,t[7]=0,t[8]=i[8]*r,t[9]=i[9]*r,t[10]=i[10]*r,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromEuler(e){const t=this.elements,i=e.x,n=e.y,s=e.z,r=Math.cos(i),a=Math.sin(i),l=Math.cos(n),c=Math.sin(n),h=Math.cos(s),d=Math.sin(s);if(e.order==="XYZ"){const u=r*h,f=r*d,p=a*h,g=a*d;t[0]=l*h,t[4]=-l*d,t[8]=c,t[1]=f+p*c,t[5]=u-g*c,t[9]=-a*l,t[2]=g-u*c,t[6]=p+f*c,t[10]=r*l}else if(e.order==="YXZ"){const u=l*h,f=l*d,p=c*h,g=c*d;t[0]=u+g*a,t[4]=p*a-f,t[8]=r*c,t[1]=r*d,t[5]=r*h,t[9]=-a,t[2]=f*a-p,t[6]=g+u*a,t[10]=r*l}else if(e.order==="ZXY"){const u=l*h,f=l*d,p=c*h,g=c*d;t[0]=u-g*a,t[4]=-r*d,t[8]=p+f*a,t[1]=f+p*a,t[5]=r*h,t[9]=g-u*a,t[2]=-r*c,t[6]=a,t[10]=r*l}else if(e.order==="ZYX"){const u=r*h,f=r*d,p=a*h,g=a*d;t[0]=l*h,t[4]=p*c-f,t[8]=u*c+g,t[1]=l*d,t[5]=g*c+u,t[9]=f*c-p,t[2]=-c,t[6]=a*l,t[10]=r*l}else if(e.order==="YZX"){const u=r*l,f=r*c,p=a*l,g=a*c;t[0]=l*h,t[4]=g-u*d,t[8]=p*d+f,t[1]=d,t[5]=r*h,t[9]=-a*h,t[2]=-c*h,t[6]=f*d+p,t[10]=u-g*d}else if(e.order==="XZY"){const u=r*l,f=r*c,p=a*l,g=a*c;t[0]=l*h,t[4]=-d,t[8]=c*h,t[1]=u*d+g,t[5]=r*h,t[9]=f*d-p,t[2]=p*d-f,t[6]=a*h,t[10]=g*d+u}return t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromQuaternion(e){return this.compose(p3,e,m3)}lookAt(e,t,i){const n=this.elements;return is.subVectors(e,t),is.lengthSq()===0&&(is.z=1),is.normalize(),Qr.crossVectors(i,is),Qr.lengthSq()===0&&(Math.abs(i.z)===1?is.x+=1e-4:is.z+=1e-4,is.normalize(),Qr.crossVectors(i,is)),Qr.normalize(),$h.crossVectors(is,Qr),n[0]=Qr.x,n[4]=$h.x,n[8]=is.x,n[1]=Qr.y,n[5]=$h.y,n[9]=is.y,n[2]=Qr.z,n[6]=$h.z,n[10]=is.z,this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){const i=e.elements,n=t.elements,s=this.elements,r=i[0],a=i[4],l=i[8],c=i[12],h=i[1],d=i[5],u=i[9],f=i[13],p=i[2],g=i[6],m=i[10],v=i[14],b=i[3],x=i[7],y=i[11],w=i[15],S=n[0],A=n[4],M=n[8],_=n[12],I=n[1],R=n[5],L=n[9],P=n[13],O=n[2],k=n[6],F=n[10],z=n[14],V=n[3],K=n[7],q=n[11],te=n[15];return s[0]=r*S+a*I+l*O+c*V,s[4]=r*A+a*R+l*k+c*K,s[8]=r*M+a*L+l*F+c*q,s[12]=r*_+a*P+l*z+c*te,s[1]=h*S+d*I+u*O+f*V,s[5]=h*A+d*R+u*k+f*K,s[9]=h*M+d*L+u*F+f*q,s[13]=h*_+d*P+u*z+f*te,s[2]=p*S+g*I+m*O+v*V,s[6]=p*A+g*R+m*k+v*K,s[10]=p*M+g*L+m*F+v*q,s[14]=p*_+g*P+m*z+v*te,s[3]=b*S+x*I+y*O+w*V,s[7]=b*A+x*R+y*k+w*K,s[11]=b*M+x*L+y*F+w*q,s[15]=b*_+x*P+y*z+w*te,this}multiplyScalar(e){const t=this.elements;return t[0]*=e,t[4]*=e,t[8]*=e,t[12]*=e,t[1]*=e,t[5]*=e,t[9]*=e,t[13]*=e,t[2]*=e,t[6]*=e,t[10]*=e,t[14]*=e,t[3]*=e,t[7]*=e,t[11]*=e,t[15]*=e,this}determinant(){const e=this.elements,t=e[0],i=e[4],n=e[8],s=e[12],r=e[1],a=e[5],l=e[9],c=e[13],h=e[2],d=e[6],u=e[10],f=e[14],p=e[3],g=e[7],m=e[11],v=e[15],b=l*f-c*u,x=a*f-c*d,y=a*u-l*d,w=r*f-c*h,S=r*u-l*h,A=r*d-a*h;return t*(g*b-m*x+v*y)-i*(p*b-m*w+v*S)+n*(p*x-g*w+v*A)-s*(p*y-g*S+m*A)}determinantAffine(){const e=this.elements,t=e[0],i=e[4],n=e[8],s=e[1],r=e[5],a=e[9],l=e[2],c=e[6],h=e[10];return t*(r*h-a*c)-i*(s*h-a*l)+n*(s*c-r*l)}transpose(){const e=this.elements;let t;return t=e[1],e[1]=e[4],e[4]=t,t=e[2],e[2]=e[8],e[8]=t,t=e[6],e[6]=e[9],e[9]=t,t=e[3],e[3]=e[12],e[12]=t,t=e[7],e[7]=e[13],e[13]=t,t=e[11],e[11]=e[14],e[14]=t,this}setPosition(e,t,i){const n=this.elements;return e.isVector3?(n[12]=e.x,n[13]=e.y,n[14]=e.z):(n[12]=e,n[13]=t,n[14]=i),this}invert(){const e=this.elements,t=e[0],i=e[1],n=e[2],s=e[3],r=e[4],a=e[5],l=e[6],c=e[7],h=e[8],d=e[9],u=e[10],f=e[11],p=e[12],g=e[13],m=e[14],v=e[15],b=t*a-i*r,x=t*l-n*r,y=t*c-s*r,w=i*l-n*a,S=i*c-s*a,A=n*c-s*l,M=h*g-d*p,_=h*m-u*p,I=h*v-f*p,R=d*m-u*g,L=d*v-f*g,P=u*v-f*m,O=b*P-x*L+y*R+w*I-S*_+A*M;if(O===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const k=1/O;return e[0]=(a*P-l*L+c*R)*k,e[1]=(n*L-i*P-s*R)*k,e[2]=(g*A-m*S+v*w)*k,e[3]=(u*S-d*A-f*w)*k,e[4]=(l*I-r*P-c*_)*k,e[5]=(t*P-n*I+s*_)*k,e[6]=(m*y-p*A-v*x)*k,e[7]=(h*A-u*y+f*x)*k,e[8]=(r*L-a*I+c*M)*k,e[9]=(i*I-t*L-s*M)*k,e[10]=(p*S-g*y+v*b)*k,e[11]=(d*y-h*S-f*b)*k,e[12]=(a*_-r*R-l*M)*k,e[13]=(t*R-i*_+n*M)*k,e[14]=(g*x-p*w-m*b)*k,e[15]=(h*w-d*x+u*b)*k,this}scale(e){const t=this.elements,i=e.x,n=e.y,s=e.z;return t[0]*=i,t[4]*=n,t[8]*=s,t[1]*=i,t[5]*=n,t[9]*=s,t[2]*=i,t[6]*=n,t[10]*=s,t[3]*=i,t[7]*=n,t[11]*=s,this}getMaxScaleOnAxis(){const e=this.elements,t=e[0]*e[0]+e[1]*e[1]+e[2]*e[2],i=e[4]*e[4]+e[5]*e[5]+e[6]*e[6],n=e[8]*e[8]+e[9]*e[9]+e[10]*e[10];return Math.sqrt(Math.max(t,i,n))}makeTranslation(e,t,i){return e.isVector3?this.set(1,0,0,e.x,0,1,0,e.y,0,0,1,e.z,0,0,0,1):this.set(1,0,0,e,0,1,0,t,0,0,1,i,0,0,0,1),this}makeRotationX(e){const t=Math.cos(e),i=Math.sin(e);return this.set(1,0,0,0,0,t,-i,0,0,i,t,0,0,0,0,1),this}makeRotationY(e){const t=Math.cos(e),i=Math.sin(e);return this.set(t,0,i,0,0,1,0,0,-i,0,t,0,0,0,0,1),this}makeRotationZ(e){const t=Math.cos(e),i=Math.sin(e);return this.set(t,-i,0,0,i,t,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(e,t){const i=Math.cos(t),n=Math.sin(t),s=1-i,r=e.x,a=e.y,l=e.z,c=s*r,h=s*a;return this.set(c*r+i,c*a-n*l,c*l+n*a,0,c*a+n*l,h*a+i,h*l-n*r,0,c*l-n*a,h*l+n*r,s*l*l+i,0,0,0,0,1),this}makeScale(e,t,i){return this.set(e,0,0,0,0,t,0,0,0,0,i,0,0,0,0,1),this}makeShear(e,t,i,n,s,r){return this.set(1,i,s,0,e,1,r,0,t,n,1,0,0,0,0,1),this}compose(e,t,i){const n=this.elements,s=t._x,r=t._y,a=t._z,l=t._w,c=s+s,h=r+r,d=a+a,u=s*c,f=s*h,p=s*d,g=r*h,m=r*d,v=a*d,b=l*c,x=l*h,y=l*d,w=i.x,S=i.y,A=i.z;return n[0]=(1-(g+v))*w,n[1]=(f+y)*w,n[2]=(p-x)*w,n[3]=0,n[4]=(f-y)*S,n[5]=(1-(u+v))*S,n[6]=(m+b)*S,n[7]=0,n[8]=(p+x)*A,n[9]=(m-b)*A,n[10]=(1-(u+g))*A,n[11]=0,n[12]=e.x,n[13]=e.y,n[14]=e.z,n[15]=1,this}decompose(e,t,i){const n=this.elements;e.x=n[12],e.y=n[13],e.z=n[14];const s=this.determinantAffine();if(s===0)return i.set(1,1,1),t.identity(),this;let r=Ko.set(n[0],n[1],n[2]).length();const a=Ko.set(n[4],n[5],n[6]).length(),l=Ko.set(n[8],n[9],n[10]).length();s<0&&(r=-r),Is.copy(this);const c=1/r,h=1/a,d=1/l;return Is.elements[0]*=c,Is.elements[1]*=c,Is.elements[2]*=c,Is.elements[4]*=h,Is.elements[5]*=h,Is.elements[6]*=h,Is.elements[8]*=d,Is.elements[9]*=d,Is.elements[10]*=d,t.setFromRotationMatrix(Is),i.x=r,i.y=a,i.z=l,this}makePerspective(e,t,i,n,s,r,a=vr,l=!1){const c=this.elements,h=2*s/(t-e),d=2*s/(i-n),u=(t+e)/(t-e),f=(i+n)/(i-n);let p,g;if(l)p=s/(r-s),g=r*s/(r-s);else if(a===vr)p=-(r+s)/(r-s),g=-2*r*s/(r-s);else if(a===xh)p=-r/(r-s),g=-r*s/(r-s);else throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+a);return c[0]=h,c[4]=0,c[8]=u,c[12]=0,c[1]=0,c[5]=d,c[9]=f,c[13]=0,c[2]=0,c[6]=0,c[10]=p,c[14]=g,c[3]=0,c[7]=0,c[11]=-1,c[15]=0,this}makeOrthographic(e,t,i,n,s,r,a=vr,l=!1){const c=this.elements,h=2/(t-e),d=2/(i-n),u=-(t+e)/(t-e),f=-(i+n)/(i-n);let p,g;if(l)p=1/(r-s),g=r/(r-s);else if(a===vr)p=-2/(r-s),g=-(r+s)/(r-s);else if(a===xh)p=-1/(r-s),g=-s/(r-s);else throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+a);return c[0]=h,c[4]=0,c[8]=0,c[12]=u,c[1]=0,c[5]=d,c[9]=0,c[13]=f,c[2]=0,c[6]=0,c[10]=p,c[14]=g,c[3]=0,c[7]=0,c[11]=0,c[15]=1,this}equals(e){const t=this.elements,i=e.elements;for(let n=0;n<16;n++)if(t[n]!==i[n])return!1;return!0}fromArray(e,t=0){for(let i=0;i<16;i++)this.elements[i]=e[i+t];return this}toArray(e=[],t=0){const i=this.elements;return e[t]=i[0],e[t+1]=i[1],e[t+2]=i[2],e[t+3]=i[3],e[t+4]=i[4],e[t+5]=i[5],e[t+6]=i[6],e[t+7]=i[7],e[t+8]=i[8],e[t+9]=i[9],e[t+10]=i[10],e[t+11]=i[11],e[t+12]=i[12],e[t+13]=i[13],e[t+14]=i[14],e[t+15]=i[15],e}}const Ko=new D,Is=new lt,p3=new D(0,0,0),m3=new D(1,1,1),Qr=new D,$h=new D,is=new D,h1=new lt,d1=new An;class wr{constructor(e=0,t=0,i=0,n=wr.DEFAULT_ORDER){this.isEuler=!0,this._x=e,this._y=t,this._z=i,this._order=n}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get order(){return this._order}set order(e){this._order=e,this._onChangeCallback()}set(e,t,i,n=this._order){return this._x=e,this._y=t,this._z=i,this._order=n,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(e){return this._x=e._x,this._y=e._y,this._z=e._z,this._order=e._order,this._onChangeCallback(),this}setFromRotationMatrix(e,t=this._order,i=!0){const n=e.elements,s=n[0],r=n[4],a=n[8],l=n[1],c=n[5],h=n[9],d=n[2],u=n[6],f=n[10];switch(t){case"XYZ":this._y=Math.asin(nt(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-h,f),this._z=Math.atan2(-r,s)):(this._x=Math.atan2(u,c),this._z=0);break;case"YXZ":this._x=Math.asin(-nt(h,-1,1)),Math.abs(h)<.9999999?(this._y=Math.atan2(a,f),this._z=Math.atan2(l,c)):(this._y=Math.atan2(-d,s),this._z=0);break;case"ZXY":this._x=Math.asin(nt(u,-1,1)),Math.abs(u)<.9999999?(this._y=Math.atan2(-d,f),this._z=Math.atan2(-r,c)):(this._y=0,this._z=Math.atan2(l,s));break;case"ZYX":this._y=Math.asin(-nt(d,-1,1)),Math.abs(d)<.9999999?(this._x=Math.atan2(u,f),this._z=Math.atan2(l,s)):(this._x=0,this._z=Math.atan2(-r,c));break;case"YZX":this._z=Math.asin(nt(l,-1,1)),Math.abs(l)<.9999999?(this._x=Math.atan2(-h,c),this._y=Math.atan2(-d,s)):(this._x=0,this._y=Math.atan2(a,f));break;case"XZY":this._z=Math.asin(-nt(r,-1,1)),Math.abs(r)<.9999999?(this._x=Math.atan2(u,c),this._y=Math.atan2(a,s)):(this._x=Math.atan2(-h,f),this._y=0);break;default:ke("Euler: .setFromRotationMatrix() encountered an unknown order: "+t)}return this._order=t,i===!0&&this._onChangeCallback(),this}setFromQuaternion(e,t,i){return h1.makeRotationFromQuaternion(e),this.setFromRotationMatrix(h1,t,i)}setFromVector3(e,t=this._order){return this.set(e.x,e.y,e.z,t)}reorder(e){return d1.setFromEuler(this),this.setFromQuaternion(d1,e)}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._order===this._order}fromArray(e){return this._x=e[0],this._y=e[1],this._z=e[2],e[3]!==void 0&&(this._order=e[3]),this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._order,e}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}wr.DEFAULT_ORDER="XYZ";class bg{constructor(){this.mask=1}set(e){this.mask=(1<<e|0)>>>0}enable(e){this.mask|=1<<e|0}enableAll(){this.mask=-1}toggle(e){this.mask^=1<<e|0}disable(e){this.mask&=~(1<<e|0)}disableAll(){this.mask=0}test(e){return(this.mask&e.mask)!==0}isEnabled(e){return(this.mask&(1<<e|0))!==0}}let g3=0;const u1=new D,Zo=new An,_r=new lt,Yh=new D,vc=new D,v3=new D,y3=new An,f1=new D(1,0,0),p1=new D(0,1,0),m1=new D(0,0,1),g1={type:"added"},b3={type:"removed"},jo={type:"childadded",child:null},jf={type:"childremoved",child:null};class hi extends Na{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:g3++}),this.uuid=Ws(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=hi.DEFAULT_UP.clone();const e=new D,t=new wr,i=new An,n=new D(1,1,1);function s(){i.setFromEuler(t,!1)}function r(){t.setFromQuaternion(i,void 0,!1)}t._onChange(s),i._onChange(r),Object.defineProperties(this,{position:{configurable:!0,enumerable:!0,value:e},rotation:{configurable:!0,enumerable:!0,value:t},quaternion:{configurable:!0,enumerable:!0,value:i},scale:{configurable:!0,enumerable:!0,value:n},modelViewMatrix:{value:new lt},normalMatrix:{value:new Je}}),this.matrix=new lt,this.matrixWorld=new lt,this.matrixAutoUpdate=hi.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=hi.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new bg,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.renderOrder=0,this.animations=[],this.customDepthMaterial=void 0,this.customDistanceMaterial=void 0,this.static=!1,this.userData={},this.pivot=null}onBeforeShadow(){}onAfterShadow(){}onBeforeRender(){}onAfterRender(){}applyMatrix4(e){this.matrixAutoUpdate&&this.updateMatrix(),this.matrix.premultiply(e),this.matrix.decompose(this.position,this.quaternion,this.scale)}applyQuaternion(e){return this.quaternion.premultiply(e),this}setRotationFromAxisAngle(e,t){this.quaternion.setFromAxisAngle(e,t)}setRotationFromEuler(e){this.quaternion.setFromEuler(e,!0)}setRotationFromMatrix(e){this.quaternion.setFromRotationMatrix(e)}setRotationFromQuaternion(e){this.quaternion.copy(e)}rotateOnAxis(e,t){return Zo.setFromAxisAngle(e,t),this.quaternion.multiply(Zo),this}rotateOnWorldAxis(e,t){return Zo.setFromAxisAngle(e,t),this.quaternion.premultiply(Zo),this}rotateX(e){return this.rotateOnAxis(f1,e)}rotateY(e){return this.rotateOnAxis(p1,e)}rotateZ(e){return this.rotateOnAxis(m1,e)}translateOnAxis(e,t){return u1.copy(e).applyQuaternion(this.quaternion),this.position.add(u1.multiplyScalar(t)),this}translateX(e){return this.translateOnAxis(f1,e)}translateY(e){return this.translateOnAxis(p1,e)}translateZ(e){return this.translateOnAxis(m1,e)}localToWorld(e){return this.updateWorldMatrix(!0,!1),e.applyMatrix4(this.matrixWorld)}worldToLocal(e){return this.updateWorldMatrix(!0,!1),e.applyMatrix4(_r.copy(this.matrixWorld).invert())}lookAt(e,t,i){e.isVector3?Yh.copy(e):Yh.set(e,t,i);const n=this.parent;this.updateWorldMatrix(!0,!1),vc.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?_r.lookAt(vc,Yh,this.up):_r.lookAt(Yh,vc,this.up),this.quaternion.setFromRotationMatrix(_r),n&&(_r.extractRotation(n.matrixWorld),Zo.setFromRotationMatrix(_r),this.quaternion.premultiply(Zo.invert()))}add(e){if(arguments.length>1){for(let t=0;t<arguments.length;t++)this.add(arguments[t]);return this}return e===this?(je("Object3D.add: object can't be added as a child of itself.",e),this):(e&&e.isObject3D?(e.removeFromParent(),e.parent=this,this.children.push(e),e.dispatchEvent(g1),jo.child=e,this.dispatchEvent(jo),jo.child=null):je("Object3D.add: object not an instance of THREE.Object3D.",e),this)}remove(e){if(arguments.length>1){for(let i=0;i<arguments.length;i++)this.remove(arguments[i]);return this}const t=this.children.indexOf(e);return t!==-1&&(e.parent=null,this.children.splice(t,1),e.dispatchEvent(b3),jf.child=e,this.dispatchEvent(jf),jf.child=null),this}removeFromParent(){const e=this.parent;return e!==null&&e.remove(this),this}clear(){return this.remove(...this.children)}attach(e){return this.updateWorldMatrix(!0,!1),_r.copy(this.matrixWorld).invert(),e.parent!==null&&(e.parent.updateWorldMatrix(!0,!1),_r.multiply(e.parent.matrixWorld)),e.applyMatrix4(_r),e.removeFromParent(),e.parent=this,this.children.push(e),e.updateWorldMatrix(!1,!0),e.dispatchEvent(g1),jo.child=e,this.dispatchEvent(jo),jo.child=null,this}getObjectById(e){return this.getObjectByProperty("id",e)}getObjectByName(e){return this.getObjectByProperty("name",e)}getObjectByProperty(e,t){if(this[e]===t)return this;for(let i=0,n=this.children.length;i<n;i++){const r=this.children[i].getObjectByProperty(e,t);if(r!==void 0)return r}}getObjectsByProperty(e,t,i=[]){this[e]===t&&i.push(this);const n=this.children;for(let s=0,r=n.length;s<r;s++)n[s].getObjectsByProperty(e,t,i);return i}getWorldPosition(e){return this.updateWorldMatrix(!0,!1),e.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(e){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(vc,e,v3),e}getWorldScale(e){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(vc,y3,e),e}getWorldDirection(e){this.updateWorldMatrix(!0,!1);const t=this.matrixWorld.elements;return e.set(t[8],t[9],t[10]).normalize()}raycast(){}traverse(e){e(this);const t=this.children;for(let i=0,n=t.length;i<n;i++)t[i].traverse(e)}traverseVisible(e){if(this.visible===!1)return;e(this);const t=this.children;for(let i=0,n=t.length;i<n;i++)t[i].traverseVisible(e)}traverseAncestors(e){const t=this.parent;t!==null&&(e(t),t.traverseAncestors(e))}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale);const e=this.pivot;if(e!==null){const t=e.x,i=e.y,n=e.z,s=this.matrix.elements;s[12]+=t-s[0]*t-s[4]*i-s[8]*n,s[13]+=i-s[1]*t-s[5]*i-s[9]*n,s[14]+=n-s[2]*t-s[6]*i-s[10]*n}this.matrixWorldNeedsUpdate=!0}updateMatrixWorld(e){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||e)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,e=!0);const t=this.children;for(let i=0,n=t.length;i<n;i++)t[i].updateMatrixWorld(e)}updateWorldMatrix(e,t,i=!1){const n=this.parent;if(e===!0&&n!==null&&n.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||i)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,i=!0),t===!0){const s=this.children;for(let r=0,a=s.length;r<a;r++)s[r].updateWorldMatrix(!1,!0,i)}}toJSON(e){const t=e===void 0||typeof e=="string",i={};t&&(e={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},i.metadata={version:4.7,type:"Object",generator:"Object3D.toJSON"});const n={};n.uuid=this.uuid,n.type=this.type,this.name!==""&&(n.name=this.name),this.castShadow===!0&&(n.castShadow=!0),this.receiveShadow===!0&&(n.receiveShadow=!0),this.visible===!1&&(n.visible=!1),this.frustumCulled===!1&&(n.frustumCulled=!1),this.renderOrder!==0&&(n.renderOrder=this.renderOrder),this.static!==!1&&(n.static=this.static),Object.keys(this.userData).length>0&&(n.userData=this.userData),n.layers=this.layers.mask,n.matrix=this.matrix.toArray(),n.up=this.up.toArray(),this.pivot!==null&&(n.pivot=this.pivot.toArray()),this.matrixAutoUpdate===!1&&(n.matrixAutoUpdate=!1),this.morphTargetDictionary!==void 0&&(n.morphTargetDictionary=Object.assign({},this.morphTargetDictionary)),this.morphTargetInfluences!==void 0&&(n.morphTargetInfluences=this.morphTargetInfluences.slice()),this.isInstancedMesh&&(n.type="InstancedMesh",n.count=this.count,n.instanceMatrix=this.instanceMatrix.toJSON(),this.instanceColor!==null&&(n.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(n.type="BatchedMesh",n.perObjectFrustumCulled=this.perObjectFrustumCulled,n.sortObjects=this.sortObjects,n.drawRanges=this._drawRanges,n.reservedRanges=this._reservedRanges,n.geometryInfo=this._geometryInfo.map(a=>({...a,boundingBox:a.boundingBox?a.boundingBox.toJSON():void 0,boundingSphere:a.boundingSphere?a.boundingSphere.toJSON():void 0})),n.instanceInfo=this._instanceInfo.map(a=>({...a})),n.availableInstanceIds=this._availableInstanceIds.slice(),n.availableGeometryIds=this._availableGeometryIds.slice(),n.nextIndexStart=this._nextIndexStart,n.nextVertexStart=this._nextVertexStart,n.geometryCount=this._geometryCount,n.maxInstanceCount=this._maxInstanceCount,n.maxVertexCount=this._maxVertexCount,n.maxIndexCount=this._maxIndexCount,n.geometryInitialized=this._geometryInitialized,n.matricesTexture=this._matricesTexture.toJSON(e),n.indirectTexture=this._indirectTexture.toJSON(e),this._colorsTexture!==null&&(n.colorsTexture=this._colorsTexture.toJSON(e)),this.boundingSphere!==null&&(n.boundingSphere=this.boundingSphere.toJSON()),this.boundingBox!==null&&(n.boundingBox=this.boundingBox.toJSON()));function s(a,l){return a[l.uuid]===void 0&&(a[l.uuid]=l.toJSON(e)),l.uuid}if(this.isScene)this.background&&(this.background.isColor?n.background=this.background.toJSON():this.background.isTexture&&(n.background=this.background.toJSON(e).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(n.environment=this.environment.toJSON(e).uuid);else if(this.isMesh||this.isLine||this.isPoints){n.geometry=s(e.geometries,this.geometry);const a=this.geometry.parameters;if(a!==void 0&&a.shapes!==void 0){const l=a.shapes;if(Array.isArray(l))for(let c=0,h=l.length;c<h;c++){const d=l[c];s(e.shapes,d)}else s(e.shapes,l)}}if(this.isSkinnedMesh&&(n.bindMode=this.bindMode,n.bindMatrix=this.bindMatrix.toArray(),this.skeleton!==void 0&&(s(e.skeletons,this.skeleton),n.skeleton=this.skeleton.uuid)),this.material!==void 0)if(Array.isArray(this.material)){const a=[];for(let l=0,c=this.material.length;l<c;l++)a.push(s(e.materials,this.material[l]));n.material=a}else n.material=s(e.materials,this.material);if(this.children.length>0){n.children=[];for(let a=0;a<this.children.length;a++)n.children.push(this.children[a].toJSON(e).object)}if(this.animations.length>0){n.animations=[];for(let a=0;a<this.animations.length;a++){const l=this.animations[a];n.animations.push(s(e.animations,l))}}if(t){const a=r(e.geometries),l=r(e.materials),c=r(e.textures),h=r(e.images),d=r(e.shapes),u=r(e.skeletons),f=r(e.animations),p=r(e.nodes);a.length>0&&(i.geometries=a),l.length>0&&(i.materials=l),c.length>0&&(i.textures=c),h.length>0&&(i.images=h),d.length>0&&(i.shapes=d),u.length>0&&(i.skeletons=u),f.length>0&&(i.animations=f),p.length>0&&(i.nodes=p)}return i.object=n,i;function r(a){const l=[];for(const c in a){const h=a[c];delete h.metadata,l.push(h)}return l}}clone(e){return new this.constructor().copy(this,e)}copy(e,t=!0){if(this.name=e.name,this.up.copy(e.up),this.position.copy(e.position),this.rotation.order=e.rotation.order,this.quaternion.copy(e.quaternion),this.scale.copy(e.scale),this.pivot=e.pivot!==null?e.pivot.clone():null,this.matrix.copy(e.matrix),this.matrixWorld.copy(e.matrixWorld),this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrixWorldAutoUpdate=e.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=e.matrixWorldNeedsUpdate,this.layers.mask=e.layers.mask,this.visible=e.visible,this.castShadow=e.castShadow,this.receiveShadow=e.receiveShadow,this.frustumCulled=e.frustumCulled,this.renderOrder=e.renderOrder,this.static=e.static,this.animations=e.animations.slice(),this.userData=JSON.parse(JSON.stringify(e.userData)),t===!0)for(let i=0;i<e.children.length;i++){const n=e.children[i];this.add(n.clone())}return this}}hi.DEFAULT_UP=new D(0,1,0);hi.DEFAULT_MATRIX_AUTO_UPDATE=!0;hi.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;class Pt extends hi{constructor(){super(),this.isGroup=!0,this.type="Group"}}const M3={type:"move"};class Jf{constructor(){this._targetRay=null,this._grip=null,this._hand=null}getHandSpace(){return this._hand===null&&(this._hand=new Pt,this._hand.matrixAutoUpdate=!1,this._hand.visible=!1,this._hand.joints={},this._hand.inputState={pinching:!1}),this._hand}getTargetRaySpace(){return this._targetRay===null&&(this._targetRay=new Pt,this._targetRay.matrixAutoUpdate=!1,this._targetRay.visible=!1,this._targetRay.hasLinearVelocity=!1,this._targetRay.linearVelocity=new D,this._targetRay.hasAngularVelocity=!1,this._targetRay.angularVelocity=new D),this._targetRay}getGripSpace(){return this._grip===null&&(this._grip=new Pt,this._grip.matrixAutoUpdate=!1,this._grip.visible=!1,this._grip.hasLinearVelocity=!1,this._grip.linearVelocity=new D,this._grip.hasAngularVelocity=!1,this._grip.angularVelocity=new D,this._grip.eventsEnabled=!1),this._grip}dispatchEvent(e){return this._targetRay!==null&&this._targetRay.dispatchEvent(e),this._grip!==null&&this._grip.dispatchEvent(e),this._hand!==null&&this._hand.dispatchEvent(e),this}connect(e){if(e&&e.hand){const t=this._hand;if(t)for(const i of e.hand.values())this._getHandJoint(t,i)}return this.dispatchEvent({type:"connected",data:e}),this}disconnect(e){return this.dispatchEvent({type:"disconnected",data:e}),this._targetRay!==null&&(this._targetRay.visible=!1),this._grip!==null&&(this._grip.visible=!1),this._hand!==null&&(this._hand.visible=!1),this}update(e,t,i){let n=null,s=null,r=null;const a=this._targetRay,l=this._grip,c=this._hand;if(e&&t.session.visibilityState!=="visible-blurred"){if(c&&e.hand){r=!0;for(const g of e.hand.values()){const m=t.getJointPose(g,i),v=this._getHandJoint(c,g);m!==null&&(v.matrix.fromArray(m.transform.matrix),v.matrix.decompose(v.position,v.rotation,v.scale),v.matrixWorldNeedsUpdate=!0,v.jointRadius=m.radius),v.visible=m!==null}const h=c.joints["index-finger-tip"],d=c.joints["thumb-tip"],u=h.position.distanceTo(d.position),f=.02,p=.005;c.inputState.pinching&&u>f+p?(c.inputState.pinching=!1,this.dispatchEvent({type:"pinchend",handedness:e.handedness,target:this})):!c.inputState.pinching&&u<=f-p&&(c.inputState.pinching=!0,this.dispatchEvent({type:"pinchstart",handedness:e.handedness,target:this}))}else l!==null&&e.gripSpace&&(s=t.getPose(e.gripSpace,i),s!==null&&(l.matrix.fromArray(s.transform.matrix),l.matrix.decompose(l.position,l.rotation,l.scale),l.matrixWorldNeedsUpdate=!0,s.linearVelocity?(l.hasLinearVelocity=!0,l.linearVelocity.copy(s.linearVelocity)):l.hasLinearVelocity=!1,s.angularVelocity?(l.hasAngularVelocity=!0,l.angularVelocity.copy(s.angularVelocity)):l.hasAngularVelocity=!1,l.eventsEnabled&&l.dispatchEvent({type:"gripUpdated",data:e,target:this})));a!==null&&(n=t.getPose(e.targetRaySpace,i),n===null&&s!==null&&(n=s),n!==null&&(a.matrix.fromArray(n.transform.matrix),a.matrix.decompose(a.position,a.rotation,a.scale),a.matrixWorldNeedsUpdate=!0,n.linearVelocity?(a.hasLinearVelocity=!0,a.linearVelocity.copy(n.linearVelocity)):a.hasLinearVelocity=!1,n.angularVelocity?(a.hasAngularVelocity=!0,a.angularVelocity.copy(n.angularVelocity)):a.hasAngularVelocity=!1,this.dispatchEvent(M3)))}return a!==null&&(a.visible=n!==null),l!==null&&(l.visible=s!==null),c!==null&&(c.visible=r!==null),this}_getHandJoint(e,t){if(e.joints[t.jointName]===void 0){const i=new Pt;i.matrixAutoUpdate=!1,i.visible=!1,e.joints[t.jointName]=i,e.add(i)}return e.joints[t.jointName]}}const cw={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074},ea={h:0,s:0,l:0},qh={h:0,s:0,l:0};function Qf(o,e,t){return t<0&&(t+=1),t>1&&(t-=1),t<1/6?o+(e-o)*6*t:t<1/2?e:t<2/3?o+(e-o)*6*(2/3-t):o}class ne{constructor(e,t,i){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(e,t,i)}set(e,t,i){if(t===void 0&&i===void 0){const n=e;n&&n.isColor?this.copy(n):typeof n=="number"?this.setHex(n):typeof n=="string"&&this.setStyle(n)}else this.setRGB(e,t,i);return this}setScalar(e){return this.r=e,this.g=e,this.b=e,this}setHex(e,t=an){return e=Math.floor(e),this.r=(e>>16&255)/255,this.g=(e>>8&255)/255,this.b=(e&255)/255,Tt.colorSpaceToWorking(this,t),this}setRGB(e,t,i,n=Tt.workingColorSpace){return this.r=e,this.g=t,this.b=i,Tt.colorSpaceToWorking(this,n),this}setHSL(e,t,i,n=Tt.workingColorSpace){if(e=vg(e,1),t=nt(t,0,1),i=nt(i,0,1),t===0)this.r=this.g=this.b=i;else{const s=i<=.5?i*(1+t):i+t-i*t,r=2*i-s;this.r=Qf(r,s,e+1/3),this.g=Qf(r,s,e),this.b=Qf(r,s,e-1/3)}return Tt.colorSpaceToWorking(this,n),this}setStyle(e,t=an){function i(s){s!==void 0&&parseFloat(s)<1&&ke("Color: Alpha component of "+e+" will be ignored.")}let n;if(n=/^(\w+)\(([^\)]*)\)/.exec(e)){let s;const r=n[1],a=n[2];switch(r){case"rgb":case"rgba":if(s=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return i(s[4]),this.setRGB(Math.min(255,parseInt(s[1],10))/255,Math.min(255,parseInt(s[2],10))/255,Math.min(255,parseInt(s[3],10))/255,t);if(s=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return i(s[4]),this.setRGB(Math.min(100,parseInt(s[1],10))/100,Math.min(100,parseInt(s[2],10))/100,Math.min(100,parseInt(s[3],10))/100,t);break;case"hsl":case"hsla":if(s=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return i(s[4]),this.setHSL(parseFloat(s[1])/360,parseFloat(s[2])/100,parseFloat(s[3])/100,t);break;default:ke("Color: Unknown color model "+e)}}else if(n=/^\#([A-Fa-f\d]+)$/.exec(e)){const s=n[1],r=s.length;if(r===3)return this.setRGB(parseInt(s.charAt(0),16)/15,parseInt(s.charAt(1),16)/15,parseInt(s.charAt(2),16)/15,t);if(r===6)return this.setHex(parseInt(s,16),t);ke("Color: Invalid hex color "+e)}else if(e&&e.length>0)return this.setColorName(e,t);return this}setColorName(e,t=an){const i=cw[e.toLowerCase()];return i!==void 0?this.setHex(i,t):ke("Color: Unknown color "+e),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(e){return this.r=e.r,this.g=e.g,this.b=e.b,this}copySRGBToLinear(e){return this.r=Gr(e.r),this.g=Gr(e.g),this.b=Gr(e.b),this}copyLinearToSRGB(e){return this.r=Gl(e.r),this.g=Gl(e.g),this.b=Gl(e.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(e=an){return Tt.workingToColorSpace(pn.copy(this),e),Math.round(nt(pn.r*255,0,255))*65536+Math.round(nt(pn.g*255,0,255))*256+Math.round(nt(pn.b*255,0,255))}getHexString(e=an){return("000000"+this.getHex(e).toString(16)).slice(-6)}getHSL(e,t=Tt.workingColorSpace){Tt.workingToColorSpace(pn.copy(this),t);const i=pn.r,n=pn.g,s=pn.b,r=Math.max(i,n,s),a=Math.min(i,n,s);let l,c;const h=(a+r)/2;if(a===r)l=0,c=0;else{const d=r-a;switch(c=h<=.5?d/(r+a):d/(2-r-a),r){case i:l=(n-s)/d+(n<s?6:0);break;case n:l=(s-i)/d+2;break;case s:l=(i-n)/d+4;break}l/=6}return e.h=l,e.s=c,e.l=h,e}getRGB(e,t=Tt.workingColorSpace){return Tt.workingToColorSpace(pn.copy(this),t),e.r=pn.r,e.g=pn.g,e.b=pn.b,e}getStyle(e=an){Tt.workingToColorSpace(pn.copy(this),e);const t=pn.r,i=pn.g,n=pn.b;return e!==an?`color(${e} ${t.toFixed(3)} ${i.toFixed(3)} ${n.toFixed(3)})`:`rgb(${Math.round(t*255)},${Math.round(i*255)},${Math.round(n*255)})`}offsetHSL(e,t,i){return this.getHSL(ea),this.setHSL(ea.h+e,ea.s+t,ea.l+i)}add(e){return this.r+=e.r,this.g+=e.g,this.b+=e.b,this}addColors(e,t){return this.r=e.r+t.r,this.g=e.g+t.g,this.b=e.b+t.b,this}addScalar(e){return this.r+=e,this.g+=e,this.b+=e,this}sub(e){return this.r=Math.max(0,this.r-e.r),this.g=Math.max(0,this.g-e.g),this.b=Math.max(0,this.b-e.b),this}multiply(e){return this.r*=e.r,this.g*=e.g,this.b*=e.b,this}multiplyScalar(e){return this.r*=e,this.g*=e,this.b*=e,this}lerp(e,t){return this.r+=(e.r-this.r)*t,this.g+=(e.g-this.g)*t,this.b+=(e.b-this.b)*t,this}lerpColors(e,t,i){return this.r=e.r+(t.r-e.r)*i,this.g=e.g+(t.g-e.g)*i,this.b=e.b+(t.b-e.b)*i,this}lerpHSL(e,t){this.getHSL(ea),e.getHSL(qh);const i=Jc(ea.h,qh.h,t),n=Jc(ea.s,qh.s,t),s=Jc(ea.l,qh.l,t);return this.setHSL(i,n,s),this}setFromVector3(e){return this.r=e.x,this.g=e.y,this.b=e.z,this}applyMatrix3(e){const t=this.r,i=this.g,n=this.b,s=e.elements;return this.r=s[0]*t+s[3]*i+s[6]*n,this.g=s[1]*t+s[4]*i+s[7]*n,this.b=s[2]*t+s[5]*i+s[8]*n,this}equals(e){return e.r===this.r&&e.g===this.g&&e.b===this.b}fromArray(e,t=0){return this.r=e[t],this.g=e[t+1],this.b=e[t+2],this}toArray(e=[],t=0){return e[t]=this.r,e[t+1]=this.g,e[t+2]=this.b,e}fromBufferAttribute(e,t){return this.r=e.getX(t),this.g=e.getY(t),this.b=e.getZ(t),this}toJSON(){return this.getHex()}*[Symbol.iterator](){yield this.r,yield this.g,yield this.b}}const pn=new ne;ne.NAMES=cw;class Mg{constructor(e,t=1,i=1e3){this.isFog=!0,this.name="",this.color=new ne(e),this.near=t,this.far=i}clone(){return new Mg(this.color,this.near,this.far)}toJSON(){return{type:"Fog",name:this.name,color:this.color.getHex(),near:this.near,far:this.far}}}class xr extends hi{constructor(){super(),this.isScene=!0,this.type="Scene",this.background=null,this.environment=null,this.fog=null,this.backgroundBlurriness=0,this.backgroundIntensity=1,this.backgroundRotation=new wr,this.environmentIntensity=1,this.environmentRotation=new wr,this.overrideMaterial=null,typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}copy(e,t){return super.copy(e,t),e.background!==null&&(this.background=e.background.clone()),e.environment!==null&&(this.environment=e.environment.clone()),e.fog!==null&&(this.fog=e.fog.clone()),this.backgroundBlurriness=e.backgroundBlurriness,this.backgroundIntensity=e.backgroundIntensity,this.backgroundRotation.copy(e.backgroundRotation),this.environmentIntensity=e.environmentIntensity,this.environmentRotation.copy(e.environmentRotation),e.overrideMaterial!==null&&(this.overrideMaterial=e.overrideMaterial.clone()),this.matrixAutoUpdate=e.matrixAutoUpdate,this}toJSON(e){const t=super.toJSON(e);return this.fog!==null&&(t.object.fog=this.fog.toJSON()),this.backgroundBlurriness>0&&(t.object.backgroundBlurriness=this.backgroundBlurriness),this.backgroundIntensity!==1&&(t.object.backgroundIntensity=this.backgroundIntensity),t.object.backgroundRotation=this.backgroundRotation.toArray(),this.environmentIntensity!==1&&(t.object.environmentIntensity=this.environmentIntensity),t.object.environmentRotation=this.environmentRotation.toArray(),t}}const Ds=new D,Tr=new D,ep=new D,Ir=new D,Jo=new D,Qo=new D,v1=new D,tp=new D,ip=new D,np=new D,sp=new wt,rp=new wt,ap=new wt;class As{constructor(e=new D,t=new D,i=new D){this.a=e,this.b=t,this.c=i}static getNormal(e,t,i,n){n.subVectors(i,t),Ds.subVectors(e,t),n.cross(Ds);const s=n.lengthSq();return s>0?n.multiplyScalar(1/Math.sqrt(s)):n.set(0,0,0)}static getBarycoord(e,t,i,n,s){Ds.subVectors(n,t),Tr.subVectors(i,t),ep.subVectors(e,t);const r=Ds.dot(Ds),a=Ds.dot(Tr),l=Ds.dot(ep),c=Tr.dot(Tr),h=Tr.dot(ep),d=r*c-a*a;if(d===0)return s.set(0,0,0),null;const u=1/d,f=(c*l-a*h)*u,p=(r*h-a*l)*u;return s.set(1-f-p,p,f)}static containsPoint(e,t,i,n){return this.getBarycoord(e,t,i,n,Ir)===null?!1:Ir.x>=0&&Ir.y>=0&&Ir.x+Ir.y<=1}static getInterpolation(e,t,i,n,s,r,a,l){return this.getBarycoord(e,t,i,n,Ir)===null?(l.x=0,l.y=0,"z"in l&&(l.z=0),"w"in l&&(l.w=0),null):(l.setScalar(0),l.addScaledVector(s,Ir.x),l.addScaledVector(r,Ir.y),l.addScaledVector(a,Ir.z),l)}static getInterpolatedAttribute(e,t,i,n,s,r){return sp.setScalar(0),rp.setScalar(0),ap.setScalar(0),sp.fromBufferAttribute(e,t),rp.fromBufferAttribute(e,i),ap.fromBufferAttribute(e,n),r.setScalar(0),r.addScaledVector(sp,s.x),r.addScaledVector(rp,s.y),r.addScaledVector(ap,s.z),r}static isFrontFacing(e,t,i,n){return Ds.subVectors(i,t),Tr.subVectors(e,t),Ds.cross(Tr).dot(n)<0}set(e,t,i){return this.a.copy(e),this.b.copy(t),this.c.copy(i),this}setFromPointsAndIndices(e,t,i,n){return this.a.copy(e[t]),this.b.copy(e[i]),this.c.copy(e[n]),this}setFromAttributeAndIndices(e,t,i,n){return this.a.fromBufferAttribute(e,t),this.b.fromBufferAttribute(e,i),this.c.fromBufferAttribute(e,n),this}clone(){return new this.constructor().copy(this)}copy(e){return this.a.copy(e.a),this.b.copy(e.b),this.c.copy(e.c),this}getArea(){return Ds.subVectors(this.c,this.b),Tr.subVectors(this.a,this.b),Ds.cross(Tr).length()*.5}getMidpoint(e){return e.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(e){return As.getNormal(this.a,this.b,this.c,e)}getPlane(e){return e.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(e,t){return As.getBarycoord(e,this.a,this.b,this.c,t)}getInterpolation(e,t,i,n,s){return As.getInterpolation(e,this.a,this.b,this.c,t,i,n,s)}containsPoint(e){return As.containsPoint(e,this.a,this.b,this.c)}isFrontFacing(e){return As.isFrontFacing(this.a,this.b,this.c,e)}intersectsBox(e){return e.intersectsTriangle(this)}closestPointToPoint(e,t){const i=this.a,n=this.b,s=this.c;let r,a;Jo.subVectors(n,i),Qo.subVectors(s,i),tp.subVectors(e,i);const l=Jo.dot(tp),c=Qo.dot(tp);if(l<=0&&c<=0)return t.copy(i);ip.subVectors(e,n);const h=Jo.dot(ip),d=Qo.dot(ip);if(h>=0&&d<=h)return t.copy(n);const u=l*d-h*c;if(u<=0&&l>=0&&h<=0)return r=l/(l-h),t.copy(i).addScaledVector(Jo,r);np.subVectors(e,s);const f=Jo.dot(np),p=Qo.dot(np);if(p>=0&&f<=p)return t.copy(s);const g=f*c-l*p;if(g<=0&&c>=0&&p<=0)return a=c/(c-p),t.copy(i).addScaledVector(Qo,a);const m=h*p-f*d;if(m<=0&&d-h>=0&&f-p>=0)return v1.subVectors(s,n),a=(d-h)/(d-h+(f-p)),t.copy(n).addScaledVector(v1,a);const v=1/(m+g+u);return r=g*v,a=u*v,t.copy(i).addScaledVector(Jo,r).addScaledVector(Qo,a)}equals(e){return e.a.equals(this.a)&&e.b.equals(this.b)&&e.c.equals(this.c)}}class on{constructor(e=new D(1/0,1/0,1/0),t=new D(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=e,this.max=t}set(e,t){return this.min.copy(e),this.max.copy(t),this}setFromArray(e){this.makeEmpty();for(let t=0,i=e.length;t<i;t+=3)this.expandByPoint(Rs.fromArray(e,t));return this}setFromBufferAttribute(e){this.makeEmpty();for(let t=0,i=e.count;t<i;t++)this.expandByPoint(Rs.fromBufferAttribute(e,t));return this}setFromPoints(e){this.makeEmpty();for(let t=0,i=e.length;t<i;t++)this.expandByPoint(e[t]);return this}setFromCenterAndSize(e,t){const i=Rs.copy(t).multiplyScalar(.5);return this.min.copy(e).sub(i),this.max.copy(e).add(i),this}setFromObject(e,t=!1){return this.makeEmpty(),this.expandByObject(e,t)}clone(){return new this.constructor().copy(this)}copy(e){return this.min.copy(e.min),this.max.copy(e.max),this}makeEmpty(){return this.min.x=this.min.y=this.min.z=1/0,this.max.x=this.max.y=this.max.z=-1/0,this}isEmpty(){return this.max.x<this.min.x||this.max.y<this.min.y||this.max.z<this.min.z}getCenter(e){return this.isEmpty()?e.set(0,0,0):e.addVectors(this.min,this.max).multiplyScalar(.5)}getSize(e){return this.isEmpty()?e.set(0,0,0):e.subVectors(this.max,this.min)}expandByPoint(e){return this.min.min(e),this.max.max(e),this}expandByVector(e){return this.min.sub(e),this.max.add(e),this}expandByScalar(e){return this.min.addScalar(-e),this.max.addScalar(e),this}expandByObject(e,t=!1){e.updateWorldMatrix(!1,!1);const i=e.geometry;if(i!==void 0){const s=i.getAttribute("position");if(t===!0&&s!==void 0&&e.isInstancedMesh!==!0)for(let r=0,a=s.count;r<a;r++)e.isMesh===!0?e.getVertexPosition(r,Rs):Rs.fromBufferAttribute(s,r),Rs.applyMatrix4(e.matrixWorld),this.expandByPoint(Rs);else e.boundingBox!==void 0?(e.boundingBox===null&&e.computeBoundingBox(),Kh.copy(e.boundingBox)):(i.boundingBox===null&&i.computeBoundingBox(),Kh.copy(i.boundingBox)),Kh.applyMatrix4(e.matrixWorld),this.union(Kh)}const n=e.children;for(let s=0,r=n.length;s<r;s++)this.expandByObject(n[s],t);return this}containsPoint(e){return e.x>=this.min.x&&e.x<=this.max.x&&e.y>=this.min.y&&e.y<=this.max.y&&e.z>=this.min.z&&e.z<=this.max.z}containsBox(e){return this.min.x<=e.min.x&&e.max.x<=this.max.x&&this.min.y<=e.min.y&&e.max.y<=this.max.y&&this.min.z<=e.min.z&&e.max.z<=this.max.z}getParameter(e,t){return t.set((e.x-this.min.x)/(this.max.x-this.min.x),(e.y-this.min.y)/(this.max.y-this.min.y),(e.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(e){return e.max.x>=this.min.x&&e.min.x<=this.max.x&&e.max.y>=this.min.y&&e.min.y<=this.max.y&&e.max.z>=this.min.z&&e.min.z<=this.max.z}intersectsSphere(e){return this.clampPoint(e.center,Rs),Rs.distanceToSquared(e.center)<=e.radius*e.radius}intersectsPlane(e){let t,i;return e.normal.x>0?(t=e.normal.x*this.min.x,i=e.normal.x*this.max.x):(t=e.normal.x*this.max.x,i=e.normal.x*this.min.x),e.normal.y>0?(t+=e.normal.y*this.min.y,i+=e.normal.y*this.max.y):(t+=e.normal.y*this.max.y,i+=e.normal.y*this.min.y),e.normal.z>0?(t+=e.normal.z*this.min.z,i+=e.normal.z*this.max.z):(t+=e.normal.z*this.max.z,i+=e.normal.z*this.min.z),t<=-e.constant&&i>=-e.constant}intersectsTriangle(e){if(this.isEmpty())return!1;this.getCenter(yc),Zh.subVectors(this.max,yc),el.subVectors(e.a,yc),tl.subVectors(e.b,yc),il.subVectors(e.c,yc),ta.subVectors(tl,el),ia.subVectors(il,tl),Ba.subVectors(el,il);let t=[0,-ta.z,ta.y,0,-ia.z,ia.y,0,-Ba.z,Ba.y,ta.z,0,-ta.x,ia.z,0,-ia.x,Ba.z,0,-Ba.x,-ta.y,ta.x,0,-ia.y,ia.x,0,-Ba.y,Ba.x,0];return!op(t,el,tl,il,Zh)||(t=[1,0,0,0,1,0,0,0,1],!op(t,el,tl,il,Zh))?!1:(jh.crossVectors(ta,ia),t=[jh.x,jh.y,jh.z],op(t,el,tl,il,Zh))}clampPoint(e,t){return t.copy(e).clamp(this.min,this.max)}distanceToPoint(e){return this.clampPoint(e,Rs).distanceTo(e)}getBoundingSphere(e){return this.isEmpty()?e.makeEmpty():(this.getCenter(e.center),e.radius=this.getSize(Rs).length()*.5),e}intersect(e){return this.min.max(e.min),this.max.min(e.max),this.isEmpty()&&this.makeEmpty(),this}union(e){return this.min.min(e.min),this.max.max(e.max),this}applyMatrix4(e){return this.isEmpty()?this:(Dr[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(e),Dr[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(e),Dr[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(e),Dr[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(e),Dr[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(e),Dr[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(e),Dr[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(e),Dr[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(e),this.setFromPoints(Dr),this)}translate(e){return this.min.add(e),this.max.add(e),this}equals(e){return e.min.equals(this.min)&&e.max.equals(this.max)}toJSON(){return{min:this.min.toArray(),max:this.max.toArray()}}fromJSON(e){return this.min.fromArray(e.min),this.max.fromArray(e.max),this}}const Dr=[new D,new D,new D,new D,new D,new D,new D,new D],Rs=new D,Kh=new on,el=new D,tl=new D,il=new D,ta=new D,ia=new D,Ba=new D,yc=new D,Zh=new D,jh=new D,za=new D;function op(o,e,t,i,n){for(let s=0,r=o.length-3;s<=r;s+=3){za.fromArray(o,s);const a=n.x*Math.abs(za.x)+n.y*Math.abs(za.y)+n.z*Math.abs(za.z),l=e.dot(za),c=t.dot(za),h=i.dot(za);if(Math.max(-Math.max(l,c,h),Math.min(l,c,h))>a)return!1}return!0}const Br=w3();function w3(){const o=new ArrayBuffer(4),e=new Float32Array(o),t=new Uint32Array(o),i=new Uint32Array(512),n=new Uint32Array(512);for(let l=0;l<256;++l){const c=l-127;c<-27?(i[l]=0,i[l|256]=32768,n[l]=24,n[l|256]=24):c<-14?(i[l]=1024>>-c-14,i[l|256]=1024>>-c-14|32768,n[l]=-c-1,n[l|256]=-c-1):c<=15?(i[l]=c+15<<10,i[l|256]=c+15<<10|32768,n[l]=13,n[l|256]=13):c<128?(i[l]=31744,i[l|256]=64512,n[l]=24,n[l|256]=24):(i[l]=31744,i[l|256]=64512,n[l]=13,n[l|256]=13)}const s=new Uint32Array(2048),r=new Uint32Array(64),a=new Uint32Array(64);for(let l=1;l<1024;++l){let c=l<<13,h=0;for(;(c&8388608)===0;)c<<=1,h-=8388608;c&=-8388609,h+=947912704,s[l]=c|h}for(let l=1024;l<2048;++l)s[l]=939524096+(l-1024<<13);for(let l=1;l<31;++l)r[l]=l<<23;r[31]=1199570944,r[32]=2147483648;for(let l=33;l<63;++l)r[l]=2147483648+(l-32<<23);r[63]=3347054592;for(let l=1;l<64;++l)l!==32&&(a[l]=1024);return{floatView:e,uint32View:t,baseTable:i,shiftTable:n,mantissaTable:s,exponentTable:r,offsetTable:a}}function x3(o){Math.abs(o)>65504&&ke("DataUtils.toHalfFloat(): Value out of range."),o=nt(o,-65504,65504),Br.floatView[0]=o;const e=Br.uint32View[0],t=e>>23&511;return Br.baseTable[t]+((e&8388607)>>Br.shiftTable[t])}function S3(o){const e=o>>10;return Br.uint32View[0]=Br.mantissaTable[Br.offsetTable[e]+(o&1023)]+Br.exponentTable[e],Br.floatView[0]}class fs{static toHalfFloat(e){return x3(e)}static fromHalfFloat(e){return S3(e)}}const Bi=new D,Jh=new we;let E3=0;class st extends Na{constructor(e,t,i=!1){if(super(),Array.isArray(e))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,Object.defineProperty(this,"id",{value:E3++}),this.name="",this.array=e,this.itemSize=t,this.count=e!==void 0?e.length/t:0,this.normalized=i,this.usage=dm,this.updateRanges=[],this.gpuType=En,this.version=0}onUploadCallback(){}set needsUpdate(e){e===!0&&this.version++}setUsage(e){return this.usage=e,this}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}copy(e){return this.name=e.name,this.array=new e.array.constructor(e.array),this.itemSize=e.itemSize,this.count=e.count,this.normalized=e.normalized,this.usage=e.usage,this.gpuType=e.gpuType,this}copyAt(e,t,i){e*=this.itemSize,i*=t.itemSize;for(let n=0,s=this.itemSize;n<s;n++)this.array[e+n]=t.array[i+n];return this}copyArray(e){return this.array.set(e),this}applyMatrix3(e){if(this.itemSize===2)for(let t=0,i=this.count;t<i;t++)Jh.fromBufferAttribute(this,t),Jh.applyMatrix3(e),this.setXY(t,Jh.x,Jh.y);else if(this.itemSize===3)for(let t=0,i=this.count;t<i;t++)Bi.fromBufferAttribute(this,t),Bi.applyMatrix3(e),this.setXYZ(t,Bi.x,Bi.y,Bi.z);return this}applyMatrix4(e){for(let t=0,i=this.count;t<i;t++)Bi.fromBufferAttribute(this,t),Bi.applyMatrix4(e),this.setXYZ(t,Bi.x,Bi.y,Bi.z);return this}applyNormalMatrix(e){for(let t=0,i=this.count;t<i;t++)Bi.fromBufferAttribute(this,t),Bi.applyNormalMatrix(e),this.setXYZ(t,Bi.x,Bi.y,Bi.z);return this}transformDirection(e){for(let t=0,i=this.count;t<i;t++)Bi.fromBufferAttribute(this,t),Bi.transformDirection(e),this.setXYZ(t,Bi.x,Bi.y,Bi.z);return this}set(e,t=0){return this.array.set(e,t),this}getComponent(e,t){let i=this.array[e*this.itemSize+t];return this.normalized&&(i=zs(i,this.array)),i}setComponent(e,t,i){return this.normalized&&(i=qt(i,this.array)),this.array[e*this.itemSize+t]=i,this}getX(e){let t=this.array[e*this.itemSize];return this.normalized&&(t=zs(t,this.array)),t}setX(e,t){return this.normalized&&(t=qt(t,this.array)),this.array[e*this.itemSize]=t,this}getY(e){let t=this.array[e*this.itemSize+1];return this.normalized&&(t=zs(t,this.array)),t}setY(e,t){return this.normalized&&(t=qt(t,this.array)),this.array[e*this.itemSize+1]=t,this}getZ(e){let t=this.array[e*this.itemSize+2];return this.normalized&&(t=zs(t,this.array)),t}setZ(e,t){return this.normalized&&(t=qt(t,this.array)),this.array[e*this.itemSize+2]=t,this}getW(e){let t=this.array[e*this.itemSize+3];return this.normalized&&(t=zs(t,this.array)),t}setW(e,t){return this.normalized&&(t=qt(t,this.array)),this.array[e*this.itemSize+3]=t,this}setXY(e,t,i){return e*=this.itemSize,this.normalized&&(t=qt(t,this.array),i=qt(i,this.array)),this.array[e+0]=t,this.array[e+1]=i,this}setXYZ(e,t,i,n){return e*=this.itemSize,this.normalized&&(t=qt(t,this.array),i=qt(i,this.array),n=qt(n,this.array)),this.array[e+0]=t,this.array[e+1]=i,this.array[e+2]=n,this}setXYZW(e,t,i,n,s){return e*=this.itemSize,this.normalized&&(t=qt(t,this.array),i=qt(i,this.array),n=qt(n,this.array),s=qt(s,this.array)),this.array[e+0]=t,this.array[e+1]=i,this.array[e+2]=n,this.array[e+3]=s,this}onUpload(e){return this.onUploadCallback=e,this}clone(){return new this.constructor(this.array,this.itemSize).copy(this)}toJSON(){const e={itemSize:this.itemSize,type:this.array.constructor.name,array:Array.from(this.array),normalized:this.normalized};return this.name!==""&&(e.name=this.name),this.usage!==dm&&(e.usage=this.usage),e}dispose(){this.dispatchEvent({type:"dispose"})}}class hw extends st{constructor(e,t,i){super(new Uint16Array(e),t,i)}}class wg extends st{constructor(e,t,i){super(new Uint32Array(e),t,i)}}class yt extends st{constructor(e,t,i){super(new Float32Array(e),t,i)}}const A3=new on,bc=new D,lp=new D;class qr{constructor(e=new D,t=-1){this.isSphere=!0,this.center=e,this.radius=t}set(e,t){return this.center.copy(e),this.radius=t,this}setFromPoints(e,t){const i=this.center;t!==void 0?i.copy(t):A3.setFromPoints(e).getCenter(i);let n=0;for(let s=0,r=e.length;s<r;s++)n=Math.max(n,i.distanceToSquared(e[s]));return this.radius=Math.sqrt(n),this}copy(e){return this.center.copy(e.center),this.radius=e.radius,this}isEmpty(){return this.radius<0}makeEmpty(){return this.center.set(0,0,0),this.radius=-1,this}containsPoint(e){return e.distanceToSquared(this.center)<=this.radius*this.radius}distanceToPoint(e){return e.distanceTo(this.center)-this.radius}intersectsSphere(e){const t=this.radius+e.radius;return e.center.distanceToSquared(this.center)<=t*t}intersectsBox(e){return e.intersectsSphere(this)}intersectsPlane(e){return Math.abs(e.distanceToPoint(this.center))<=this.radius}clampPoint(e,t){const i=this.center.distanceToSquared(e);return t.copy(e),i>this.radius*this.radius&&(t.sub(this.center).normalize(),t.multiplyScalar(this.radius).add(this.center)),t}getBoundingBox(e){return this.isEmpty()?(e.makeEmpty(),e):(e.set(this.center,this.center),e.expandByScalar(this.radius),e)}applyMatrix4(e){return this.center.applyMatrix4(e),this.radius=this.radius*e.getMaxScaleOnAxis(),this}translate(e){return this.center.add(e),this}expandByPoint(e){if(this.isEmpty())return this.center.copy(e),this.radius=0,this;bc.subVectors(e,this.center);const t=bc.lengthSq();if(t>this.radius*this.radius){const i=Math.sqrt(t),n=(i-this.radius)*.5;this.center.addScaledVector(bc,n/i),this.radius+=n}return this}union(e){return e.isEmpty()?this:this.isEmpty()?(this.copy(e),this):(this.center.equals(e.center)===!0?this.radius=Math.max(this.radius,e.radius):(lp.subVectors(e.center,this.center).setLength(e.radius),this.expandByPoint(bc.copy(e.center).add(lp)),this.expandByPoint(bc.copy(e.center).sub(lp))),this)}equals(e){return e.center.equals(this.center)&&e.radius===this.radius}clone(){return new this.constructor().copy(this)}toJSON(){return{radius:this.radius,center:this.center.toArray()}}fromJSON(e){return this.radius=e.radius,this.center.fromArray(e.center),this}}let _3=0;const ys=new lt,cp=new hi,nl=new D,ns=new on,Mc=new on,en=new D;class ot extends Na{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:_3++}),this.uuid=Ws(),this.name="",this.type="BufferGeometry",this.index=null,this.indirect=null,this.indirectOffset=0,this.attributes={},this.morphAttributes={},this.morphTargetsRelative=!1,this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.drawRange={start:0,count:1/0},this.userData={},this._transformed=!1}getIndex(){return this.index}setIndex(e){return Array.isArray(e)?this.index=new(GE(e)?wg:hw)(e,1):this.index=e,this}setIndirect(e,t=0){return this.indirect=e,this.indirectOffset=t,this}getIndirect(){return this.indirect}getAttribute(e){return this.attributes[e]}setAttribute(e,t){return this.attributes[e]=t,this}deleteAttribute(e){return delete this.attributes[e],this}hasAttribute(e){return this.attributes[e]!==void 0}addGroup(e,t,i=0){this.groups.push({start:e,count:t,materialIndex:i})}clearGroups(){this.groups=[]}setDrawRange(e,t){this.drawRange.start=e,this.drawRange.count=t}applyMatrix4(e){const t=this.attributes.position;t!==void 0&&(t.applyMatrix4(e),t.needsUpdate=!0);const i=this.attributes.normal;if(i!==void 0){const s=new Je().getNormalMatrix(e);i.applyNormalMatrix(s),i.needsUpdate=!0}const n=this.attributes.tangent;return n!==void 0&&(n.transformDirection(e),n.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this._transformed=!0,this}applyQuaternion(e){return ys.makeRotationFromQuaternion(e),this.applyMatrix4(ys),this}rotateX(e){return ys.makeRotationX(e),this.applyMatrix4(ys),this}rotateY(e){return ys.makeRotationY(e),this.applyMatrix4(ys),this}rotateZ(e){return ys.makeRotationZ(e),this.applyMatrix4(ys),this}translate(e,t,i){return ys.makeTranslation(e,t,i),this.applyMatrix4(ys),this}scale(e,t,i){return ys.makeScale(e,t,i),this.applyMatrix4(ys),this}lookAt(e){return cp.lookAt(e),cp.updateMatrix(),this.applyMatrix4(cp.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(nl).negate(),this.translate(nl.x,nl.y,nl.z),this}setFromPoints(e){const t=this.getAttribute("position");if(t===void 0){const i=[];for(let n=0,s=e.length;n<s;n++){const r=e[n];i.push(r.x,r.y,r.z||0)}this.setAttribute("position",new yt(i,3))}else{const i=Math.min(e.length,t.count);for(let n=0;n<i;n++){const s=e[n];t.setXYZ(n,s.x,s.y,s.z||0)}e.length>t.count&&ke("BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry."),t.needsUpdate=!0}return this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new on);const e=this.attributes.position,t=this.morphAttributes.position;if(e&&e.isGLBufferAttribute){je("BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),this.boundingBox.set(new D(-1/0,-1/0,-1/0),new D(1/0,1/0,1/0));return}if(e!==void 0){if(this.boundingBox.setFromBufferAttribute(e),t)for(let i=0,n=t.length;i<n;i++){const s=t[i];ns.setFromBufferAttribute(s),this.morphTargetsRelative?(en.addVectors(this.boundingBox.min,ns.min),this.boundingBox.expandByPoint(en),en.addVectors(this.boundingBox.max,ns.max),this.boundingBox.expandByPoint(en)):(this.boundingBox.expandByPoint(ns.min),this.boundingBox.expandByPoint(ns.max))}}else this.boundingBox.makeEmpty();(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z))&&je('BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.',this)}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new qr);const e=this.attributes.position,t=this.morphAttributes.position;if(e&&e.isGLBufferAttribute){je("BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.",this),this.boundingSphere.set(new D,1/0);return}if(e){const i=this.boundingSphere.center;if(ns.setFromBufferAttribute(e),t)for(let s=0,r=t.length;s<r;s++){const a=t[s];Mc.setFromBufferAttribute(a),this.morphTargetsRelative?(en.addVectors(ns.min,Mc.min),ns.expandByPoint(en),en.addVectors(ns.max,Mc.max),ns.expandByPoint(en)):(ns.expandByPoint(Mc.min),ns.expandByPoint(Mc.max))}ns.getCenter(i);let n=0;for(let s=0,r=e.count;s<r;s++)en.fromBufferAttribute(e,s),n=Math.max(n,i.distanceToSquared(en));if(t)for(let s=0,r=t.length;s<r;s++){const a=t[s],l=this.morphTargetsRelative;for(let c=0,h=a.count;c<h;c++)en.fromBufferAttribute(a,c),l&&(nl.fromBufferAttribute(e,c),en.add(nl)),n=Math.max(n,i.distanceToSquared(en))}this.boundingSphere.radius=Math.sqrt(n),isNaN(this.boundingSphere.radius)&&je('BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',this)}}computeTangents(){const e=this.index,t=this.attributes;if(e===null||t.position===void 0||t.normal===void 0||t.uv===void 0){je("BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)");return}const i=t.position,n=t.normal,s=t.uv;let r=this.getAttribute("tangent");(r===void 0||r.count!==i.count)&&(r=new st(new Float32Array(4*i.count),4),this.setAttribute("tangent",r));const a=[],l=[];for(let M=0;M<i.count;M++)a[M]=new D,l[M]=new D;const c=new D,h=new D,d=new D,u=new we,f=new we,p=new we,g=new D,m=new D;function v(M,_,I){c.fromBufferAttribute(i,M),h.fromBufferAttribute(i,_),d.fromBufferAttribute(i,I),u.fromBufferAttribute(s,M),f.fromBufferAttribute(s,_),p.fromBufferAttribute(s,I),h.sub(c),d.sub(c),f.sub(u),p.sub(u);const R=1/(f.x*p.y-p.x*f.y);isFinite(R)&&(g.copy(h).multiplyScalar(p.y).addScaledVector(d,-f.y).multiplyScalar(R),m.copy(d).multiplyScalar(f.x).addScaledVector(h,-p.x).multiplyScalar(R),a[M].add(g),a[_].add(g),a[I].add(g),l[M].add(m),l[_].add(m),l[I].add(m))}let b=this.groups;b.length===0&&(b=[{start:0,count:e.count}]);for(let M=0,_=b.length;M<_;++M){const I=b[M],R=I.start,L=I.count;for(let P=R,O=R+L;P<O;P+=3)v(e.getX(P+0),e.getX(P+1),e.getX(P+2))}const x=new D,y=new D,w=new D,S=new D;function A(M){w.fromBufferAttribute(n,M),S.copy(w);const _=a[M];x.copy(_),x.sub(w.multiplyScalar(w.dot(_))).normalize(),y.crossVectors(S,_);const R=y.dot(l[M])<0?-1:1;r.setXYZW(M,x.x,x.y,x.z,R)}for(let M=0,_=b.length;M<_;++M){const I=b[M],R=I.start,L=I.count;for(let P=R,O=R+L;P<O;P+=3)A(e.getX(P+0)),A(e.getX(P+1)),A(e.getX(P+2))}this._transformed=!0}computeVertexNormals(){const e=this.index,t=this.getAttribute("position");if(t!==void 0){let i=this.getAttribute("normal");if(i===void 0||i.count!==t.count)i=new st(new Float32Array(t.count*3),3),this.setAttribute("normal",i);else for(let u=0,f=i.count;u<f;u++)i.setXYZ(u,0,0,0);const n=new D,s=new D,r=new D,a=new D,l=new D,c=new D,h=new D,d=new D;if(e)for(let u=0,f=e.count;u<f;u+=3){const p=e.getX(u+0),g=e.getX(u+1),m=e.getX(u+2);n.fromBufferAttribute(t,p),s.fromBufferAttribute(t,g),r.fromBufferAttribute(t,m),h.subVectors(r,s),d.subVectors(n,s),h.cross(d),a.fromBufferAttribute(i,p),l.fromBufferAttribute(i,g),c.fromBufferAttribute(i,m),a.add(h),l.add(h),c.add(h),i.setXYZ(p,a.x,a.y,a.z),i.setXYZ(g,l.x,l.y,l.z),i.setXYZ(m,c.x,c.y,c.z)}else for(let u=0,f=t.count;u<f;u+=3)n.fromBufferAttribute(t,u+0),s.fromBufferAttribute(t,u+1),r.fromBufferAttribute(t,u+2),h.subVectors(r,s),d.subVectors(n,s),h.cross(d),i.setXYZ(u+0,h.x,h.y,h.z),i.setXYZ(u+1,h.x,h.y,h.z),i.setXYZ(u+2,h.x,h.y,h.z);this.normalizeNormals(),i.needsUpdate=!0}}normalizeNormals(){const e=this.attributes.normal;for(let t=0,i=e.count;t<i;t++)en.fromBufferAttribute(e,t),en.normalize(),e.setXYZ(t,en.x,en.y,en.z)}toNonIndexed(){function e(a,l){const c=a.array,h=a.itemSize,d=a.normalized,u=new c.constructor(l.length*h);let f=0,p=0;for(let g=0,m=l.length;g<m;g++){a.isInterleavedBufferAttribute?f=l[g]*a.data.stride+a.offset:f=l[g]*h;for(let v=0;v<h;v++)u[p++]=c[f++]}return new st(u,h,d)}if(this.index===null)return ke("BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."),this;const t=new ot,i=this.index.array,n=this.attributes;for(const a in n){const l=n[a],c=e(l,i);t.setAttribute(a,c)}const s=this.morphAttributes;for(const a in s){const l=[],c=s[a];for(let h=0,d=c.length;h<d;h++){const u=c[h],f=e(u,i);l.push(f)}t.morphAttributes[a]=l}t.morphTargetsRelative=this.morphTargetsRelative;const r=this.groups;for(let a=0,l=r.length;a<l;a++){const c=r[a];t.addGroup(c.start,c.count,c.materialIndex)}return t}toJSON(){const e={metadata:{version:4.7,type:"BufferGeometry",generator:"BufferGeometry.toJSON"}};if(e.uuid=this.uuid,e.type=this.parameters!==void 0&&this._transformed===!0?"BufferGeometry":this.type,this.name!==""&&(e.name=this.name),Object.keys(this.userData).length>0&&(e.userData=this.userData),this.parameters!==void 0&&this._transformed!==!0){const l=this.parameters;for(const c in l)l[c]!==void 0&&(e[c]=l[c]);return e}e.data={attributes:{}};const t=this.index;t!==null&&(e.data.index={type:t.array.constructor.name,array:Array.prototype.slice.call(t.array)});const i=this.attributes;for(const l in i){const c=i[l];e.data.attributes[l]=c.toJSON(e.data)}const n={};let s=!1;for(const l in this.morphAttributes){const c=this.morphAttributes[l],h=[];for(let d=0,u=c.length;d<u;d++){const f=c[d];h.push(f.toJSON(e.data))}h.length>0&&(n[l]=h,s=!0)}s&&(e.data.morphAttributes=n,e.data.morphTargetsRelative=this.morphTargetsRelative);const r=this.groups;r.length>0&&(e.data.groups=JSON.parse(JSON.stringify(r)));const a=this.boundingSphere;return a!==null&&(e.data.boundingSphere=a.toJSON()),e}clone(){return new this.constructor().copy(this)}copy(e){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const t={};this.name=e.name;const i=e.index;i!==null&&this.setIndex(i.clone());const n=e.attributes;for(const c in n){const h=n[c];this.setAttribute(c,h.clone(t))}const s=e.morphAttributes;for(const c in s){const h=[],d=s[c];for(let u=0,f=d.length;u<f;u++)h.push(d[u].clone(t));this.morphAttributes[c]=h}this.morphTargetsRelative=e.morphTargetsRelative;const r=e.groups;for(let c=0,h=r.length;c<h;c++){const d=r[c];this.addGroup(d.start,d.count,d.materialIndex)}const a=e.boundingBox;a!==null&&(this.boundingBox=a.clone());const l=e.boundingSphere;return l!==null&&(this.boundingSphere=l.clone()),this.drawRange.start=e.drawRange.start,this.drawRange.count=e.drawRange.count,this.userData=e.userData,this._transformed=e._transformed,this}dispose(){this.dispatchEvent({type:"dispose"})}}class dw{constructor(e,t){this.isInterleavedBuffer=!0,this.array=e,this.stride=t,this.count=e!==void 0?e.length/t:0,this.usage=dm,this.updateRanges=[],this.version=0,this.uuid=Ws()}onUploadCallback(){}set needsUpdate(e){e===!0&&this.version++}setUsage(e){return this.usage=e,this}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}copy(e){return this.array=new e.array.constructor(e.array),this.count=e.count,this.stride=e.stride,this.usage=e.usage,this}copyAt(e,t,i){e*=this.stride,i*=t.stride;for(let n=0,s=this.stride;n<s;n++)this.array[e+n]=t.array[i+n];return this}set(e,t=0){return this.array.set(e,t),this}clone(e){e.arrayBuffers===void 0&&(e.arrayBuffers={}),this.array.buffer._uuid===void 0&&(this.array.buffer._uuid=Ws()),e.arrayBuffers[this.array.buffer._uuid]===void 0&&(e.arrayBuffers[this.array.buffer._uuid]=this.array.slice(0).buffer);const t=new this.array.constructor(e.arrayBuffers[this.array.buffer._uuid]),i=new this.constructor(t,this.stride);return i.setUsage(this.usage),i}onUpload(e){return this.onUploadCallback=e,this}toJSON(e){return e.arrayBuffers===void 0&&(e.arrayBuffers={}),this.array.buffer._uuid===void 0&&(this.array.buffer._uuid=Ws()),e.arrayBuffers[this.array.buffer._uuid]===void 0&&(e.arrayBuffers[this.array.buffer._uuid]=Array.from(new Uint32Array(this.array.buffer))),{uuid:this.uuid,buffer:this.array.buffer._uuid,type:this.array.constructor.name,stride:this.stride}}}const _n=new D;class $u{constructor(e,t,i,n=!1){this.isInterleavedBufferAttribute=!0,this.name="",this.data=e,this.itemSize=t,this.offset=i,this.normalized=n}get count(){return this.data.count}get array(){return this.data.array}set needsUpdate(e){this.data.needsUpdate=e}applyMatrix4(e){for(let t=0,i=this.data.count;t<i;t++)_n.fromBufferAttribute(this,t),_n.applyMatrix4(e),this.setXYZ(t,_n.x,_n.y,_n.z);return this}applyNormalMatrix(e){for(let t=0,i=this.count;t<i;t++)_n.fromBufferAttribute(this,t),_n.applyNormalMatrix(e),this.setXYZ(t,_n.x,_n.y,_n.z);return this}transformDirection(e){for(let t=0,i=this.count;t<i;t++)_n.fromBufferAttribute(this,t),_n.transformDirection(e),this.setXYZ(t,_n.x,_n.y,_n.z);return this}getComponent(e,t){let i=this.array[e*this.data.stride+this.offset+t];return this.normalized&&(i=zs(i,this.array)),i}setComponent(e,t,i){return this.normalized&&(i=qt(i,this.array)),this.data.array[e*this.data.stride+this.offset+t]=i,this}setX(e,t){return this.normalized&&(t=qt(t,this.array)),this.data.array[e*this.data.stride+this.offset]=t,this}setY(e,t){return this.normalized&&(t=qt(t,this.array)),this.data.array[e*this.data.stride+this.offset+1]=t,this}setZ(e,t){return this.normalized&&(t=qt(t,this.array)),this.data.array[e*this.data.stride+this.offset+2]=t,this}setW(e,t){return this.normalized&&(t=qt(t,this.array)),this.data.array[e*this.data.stride+this.offset+3]=t,this}getX(e){let t=this.data.array[e*this.data.stride+this.offset];return this.normalized&&(t=zs(t,this.array)),t}getY(e){let t=this.data.array[e*this.data.stride+this.offset+1];return this.normalized&&(t=zs(t,this.array)),t}getZ(e){let t=this.data.array[e*this.data.stride+this.offset+2];return this.normalized&&(t=zs(t,this.array)),t}getW(e){let t=this.data.array[e*this.data.stride+this.offset+3];return this.normalized&&(t=zs(t,this.array)),t}setXY(e,t,i){return e=e*this.data.stride+this.offset,this.normalized&&(t=qt(t,this.array),i=qt(i,this.array)),this.data.array[e+0]=t,this.data.array[e+1]=i,this}setXYZ(e,t,i,n){return e=e*this.data.stride+this.offset,this.normalized&&(t=qt(t,this.array),i=qt(i,this.array),n=qt(n,this.array)),this.data.array[e+0]=t,this.data.array[e+1]=i,this.data.array[e+2]=n,this}setXYZW(e,t,i,n,s){return e=e*this.data.stride+this.offset,this.normalized&&(t=qt(t,this.array),i=qt(i,this.array),n=qt(n,this.array),s=qt(s,this.array)),this.data.array[e+0]=t,this.data.array[e+1]=i,this.data.array[e+2]=n,this.data.array[e+3]=s,this}clone(e){if(e===void 0){Xu("InterleavedBufferAttribute.clone(): Cloning an interleaved buffer attribute will de-interleave buffer data.");const t=[];for(let i=0;i<this.count;i++){const n=i*this.data.stride+this.offset;for(let s=0;s<this.itemSize;s++)t.push(this.data.array[n+s])}return new st(new this.array.constructor(t),this.itemSize,this.normalized)}else return e.interleavedBuffers===void 0&&(e.interleavedBuffers={}),e.interleavedBuffers[this.data.uuid]===void 0&&(e.interleavedBuffers[this.data.uuid]=this.data.clone(e)),new $u(e.interleavedBuffers[this.data.uuid],this.itemSize,this.offset,this.normalized)}toJSON(e){if(e===void 0){Xu("InterleavedBufferAttribute.toJSON(): Serializing an interleaved buffer attribute will de-interleave buffer data.");const t=[];for(let i=0;i<this.count;i++){const n=i*this.data.stride+this.offset;for(let s=0;s<this.itemSize;s++)t.push(this.data.array[n+s])}return{itemSize:this.itemSize,type:this.array.constructor.name,array:t,normalized:this.normalized}}else return e.interleavedBuffers===void 0&&(e.interleavedBuffers={}),e.interleavedBuffers[this.data.uuid]===void 0&&(e.interleavedBuffers[this.data.uuid]=this.data.toJSON(e)),{isInterleavedBufferAttribute:!0,itemSize:this.itemSize,data:this.data.uuid,offset:this.offset,normalized:this.normalized}}}let T3=0;class Ar extends Na{constructor(){super(),this.isMaterial=!0,Object.defineProperty(this,"id",{value:T3++}),this.uuid=Ws(),this.name="",this.type="Material",this.blending=Ia,this.side=Pa,this.vertexColors=!1,this.opacity=1,this.transparent=!1,this.alphaHash=!1,this.blendSrc=A0,this.blendDst=bh,this.blendEquation=eo,this.blendSrcAlpha=null,this.blendDstAlpha=null,this.blendEquationAlpha=null,this.blendColor=new ne(0,0,0),this.blendAlpha=0,this.depthFunc=sc,this.depthTest=!0,this.depthWrite=!0,this.stencilWriteMask=255,this.stencilFunc=s1,this.stencilRef=0,this.stencilFuncMask=255,this.stencilFail=Yo,this.stencilZFail=Yo,this.stencilZPass=Yo,this.stencilWrite=!1,this.clippingPlanes=null,this.clipIntersection=!1,this.clipShadows=!1,this.shadowSide=null,this.colorWrite=!0,this.precision=null,this.polygonOffset=!1,this.polygonOffsetFactor=0,this.polygonOffsetUnits=0,this.dithering=!1,this.alphaToCoverage=!1,this.premultipliedAlpha=!1,this.forceSinglePass=!1,this.allowOverride=!0,this.visible=!0,this.toneMapped=!0,this.userData={},this.version=0,this._alphaTest=0}get alphaTest(){return this._alphaTest}set alphaTest(e){this._alphaTest>0!=e>0&&this.version++,this._alphaTest=e}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(e){if(e!==void 0)for(const t in e){const i=e[t];if(i===void 0){ke(`Material: parameter '${t}' has value of undefined.`);continue}const n=this[t];if(n===void 0){ke(`Material: '${t}' is not a property of THREE.${this.type}.`);continue}n&&n.isColor?n.set(i):n&&n.isVector2&&i&&i.isVector2||n&&n.isEuler&&i&&i.isEuler||n&&n.isVector3&&i&&i.isVector3?n.copy(i):this[t]=i}}toJSON(e){const t=e===void 0||typeof e=="string";t&&(e={textures:{},images:{}});const i={metadata:{version:4.7,type:"Material",generator:"Material.toJSON"}};i.uuid=this.uuid,i.type=this.type,this.name!==""&&(i.name=this.name),this.color&&this.color.isColor&&(i.color=this.color.getHex()),this.roughness!==void 0&&(i.roughness=this.roughness),this.metalness!==void 0&&(i.metalness=this.metalness),this.sheen!==void 0&&(i.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(i.sheenColor=this.sheenColor.getHex()),this.sheenRoughness!==void 0&&(i.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(i.emissive=this.emissive.getHex()),this.emissiveIntensity!==void 0&&this.emissiveIntensity!==1&&(i.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(i.specular=this.specular.getHex()),this.specularIntensity!==void 0&&(i.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(i.specularColor=this.specularColor.getHex()),this.shininess!==void 0&&(i.shininess=this.shininess),this.clearcoat!==void 0&&(i.clearcoat=this.clearcoat),this.clearcoatRoughness!==void 0&&(i.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(i.clearcoatMap=this.clearcoatMap.toJSON(e).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(i.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(e).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(i.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(e).uuid,i.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),this.sheenColorMap&&this.sheenColorMap.isTexture&&(i.sheenColorMap=this.sheenColorMap.toJSON(e).uuid),this.sheenRoughnessMap&&this.sheenRoughnessMap.isTexture&&(i.sheenRoughnessMap=this.sheenRoughnessMap.toJSON(e).uuid),this.dispersion!==void 0&&(i.dispersion=this.dispersion),this.iridescence!==void 0&&(i.iridescence=this.iridescence),this.iridescenceIOR!==void 0&&(i.iridescenceIOR=this.iridescenceIOR),this.iridescenceThicknessRange!==void 0&&(i.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(i.iridescenceMap=this.iridescenceMap.toJSON(e).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(i.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(e).uuid),this.anisotropy!==void 0&&(i.anisotropy=this.anisotropy),this.anisotropyRotation!==void 0&&(i.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(i.anisotropyMap=this.anisotropyMap.toJSON(e).uuid),this.map&&this.map.isTexture&&(i.map=this.map.toJSON(e).uuid),this.matcap&&this.matcap.isTexture&&(i.matcap=this.matcap.toJSON(e).uuid),this.alphaMap&&this.alphaMap.isTexture&&(i.alphaMap=this.alphaMap.toJSON(e).uuid),this.lightMap&&this.lightMap.isTexture&&(i.lightMap=this.lightMap.toJSON(e).uuid,i.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(i.aoMap=this.aoMap.toJSON(e).uuid,i.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(i.bumpMap=this.bumpMap.toJSON(e).uuid,i.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(i.normalMap=this.normalMap.toJSON(e).uuid,i.normalMapType=this.normalMapType,i.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(i.displacementMap=this.displacementMap.toJSON(e).uuid,i.displacementScale=this.displacementScale,i.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(i.roughnessMap=this.roughnessMap.toJSON(e).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(i.metalnessMap=this.metalnessMap.toJSON(e).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(i.emissiveMap=this.emissiveMap.toJSON(e).uuid),this.specularMap&&this.specularMap.isTexture&&(i.specularMap=this.specularMap.toJSON(e).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(i.specularIntensityMap=this.specularIntensityMap.toJSON(e).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(i.specularColorMap=this.specularColorMap.toJSON(e).uuid),this.envMap&&this.envMap.isTexture&&(i.envMap=this.envMap.toJSON(e).uuid,this.combine!==void 0&&(i.combine=this.combine)),this.envMapRotation!==void 0&&(i.envMapRotation=this.envMapRotation.toArray()),this.envMapIntensity!==void 0&&(i.envMapIntensity=this.envMapIntensity),this.reflectivity!==void 0&&(i.reflectivity=this.reflectivity),this.refractionRatio!==void 0&&(i.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(i.gradientMap=this.gradientMap.toJSON(e).uuid),this.transmission!==void 0&&(i.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(i.transmissionMap=this.transmissionMap.toJSON(e).uuid),this.thickness!==void 0&&(i.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(i.thicknessMap=this.thicknessMap.toJSON(e).uuid),this.attenuationDistance!==void 0&&this.attenuationDistance!==1/0&&(i.attenuationDistance=this.attenuationDistance),this.attenuationColor!==void 0&&(i.attenuationColor=this.attenuationColor.getHex()),this.size!==void 0&&(i.size=this.size),this.shadowSide!==null&&(i.shadowSide=this.shadowSide),this.sizeAttenuation!==void 0&&(i.sizeAttenuation=this.sizeAttenuation),this.blending!==Ia&&(i.blending=this.blending),this.side!==Pa&&(i.side=this.side),this.vertexColors===!0&&(i.vertexColors=!0),this.opacity<1&&(i.opacity=this.opacity),this.transparent===!0&&(i.transparent=!0),this.blendSrc!==A0&&(i.blendSrc=this.blendSrc),this.blendDst!==bh&&(i.blendDst=this.blendDst),this.blendEquation!==eo&&(i.blendEquation=this.blendEquation),this.blendSrcAlpha!==null&&(i.blendSrcAlpha=this.blendSrcAlpha),this.blendDstAlpha!==null&&(i.blendDstAlpha=this.blendDstAlpha),this.blendEquationAlpha!==null&&(i.blendEquationAlpha=this.blendEquationAlpha),this.blendColor&&this.blendColor.isColor&&(i.blendColor=this.blendColor.getHex()),this.blendAlpha!==0&&(i.blendAlpha=this.blendAlpha),this.depthFunc!==sc&&(i.depthFunc=this.depthFunc),this.depthTest===!1&&(i.depthTest=this.depthTest),this.depthWrite===!1&&(i.depthWrite=this.depthWrite),this.colorWrite===!1&&(i.colorWrite=this.colorWrite),this.stencilWriteMask!==255&&(i.stencilWriteMask=this.stencilWriteMask),this.stencilFunc!==s1&&(i.stencilFunc=this.stencilFunc),this.stencilRef!==0&&(i.stencilRef=this.stencilRef),this.stencilFuncMask!==255&&(i.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==Yo&&(i.stencilFail=this.stencilFail),this.stencilZFail!==Yo&&(i.stencilZFail=this.stencilZFail),this.stencilZPass!==Yo&&(i.stencilZPass=this.stencilZPass),this.stencilWrite===!0&&(i.stencilWrite=this.stencilWrite),this.rotation!==void 0&&this.rotation!==0&&(i.rotation=this.rotation),this.polygonOffset===!0&&(i.polygonOffset=!0),this.polygonOffsetFactor!==0&&(i.polygonOffsetFactor=this.polygonOffsetFactor),this.polygonOffsetUnits!==0&&(i.polygonOffsetUnits=this.polygonOffsetUnits),this.linewidth!==void 0&&this.linewidth!==1&&(i.linewidth=this.linewidth),this.dashSize!==void 0&&(i.dashSize=this.dashSize),this.gapSize!==void 0&&(i.gapSize=this.gapSize),this.scale!==void 0&&(i.scale=this.scale),this.dithering===!0&&(i.dithering=!0),this.alphaTest>0&&(i.alphaTest=this.alphaTest),this.alphaHash===!0&&(i.alphaHash=!0),this.alphaToCoverage===!0&&(i.alphaToCoverage=!0),this.premultipliedAlpha===!0&&(i.premultipliedAlpha=!0),this.forceSinglePass===!0&&(i.forceSinglePass=!0),this.allowOverride===!1&&(i.allowOverride=!1),this.wireframe===!0&&(i.wireframe=!0),this.wireframeLinewidth>1&&(i.wireframeLinewidth=this.wireframeLinewidth),this.wireframeLinecap!=="round"&&(i.wireframeLinecap=this.wireframeLinecap),this.wireframeLinejoin!=="round"&&(i.wireframeLinejoin=this.wireframeLinejoin),this.flatShading===!0&&(i.flatShading=!0),this.visible===!1&&(i.visible=!1),this.toneMapped===!1&&(i.toneMapped=!1),this.fog===!1&&(i.fog=!1),Object.keys(this.userData).length>0&&(i.userData=this.userData);function n(s){const r=[];for(const a in s){const l=s[a];delete l.metadata,r.push(l)}return r}if(t){const s=n(e.textures),r=n(e.images);s.length>0&&(i.textures=s),r.length>0&&(i.images=r)}return i}fromJSON(e,t){if(e.uuid!==void 0&&(this.uuid=e.uuid),e.name!==void 0&&(this.name=e.name),e.color!==void 0&&this.color!==void 0&&this.color.setHex(e.color),e.roughness!==void 0&&(this.roughness=e.roughness),e.metalness!==void 0&&(this.metalness=e.metalness),e.sheen!==void 0&&(this.sheen=e.sheen),e.sheenColor!==void 0&&(this.sheenColor=new ne().setHex(e.sheenColor)),e.sheenRoughness!==void 0&&(this.sheenRoughness=e.sheenRoughness),e.emissive!==void 0&&this.emissive!==void 0&&this.emissive.setHex(e.emissive),e.specular!==void 0&&this.specular!==void 0&&this.specular.setHex(e.specular),e.specularIntensity!==void 0&&(this.specularIntensity=e.specularIntensity),e.specularColor!==void 0&&this.specularColor!==void 0&&this.specularColor.setHex(e.specularColor),e.shininess!==void 0&&(this.shininess=e.shininess),e.clearcoat!==void 0&&(this.clearcoat=e.clearcoat),e.clearcoatRoughness!==void 0&&(this.clearcoatRoughness=e.clearcoatRoughness),e.dispersion!==void 0&&(this.dispersion=e.dispersion),e.iridescence!==void 0&&(this.iridescence=e.iridescence),e.iridescenceIOR!==void 0&&(this.iridescenceIOR=e.iridescenceIOR),e.iridescenceThicknessRange!==void 0&&(this.iridescenceThicknessRange=e.iridescenceThicknessRange),e.transmission!==void 0&&(this.transmission=e.transmission),e.thickness!==void 0&&(this.thickness=e.thickness),e.attenuationDistance!==void 0&&(this.attenuationDistance=e.attenuationDistance),e.attenuationColor!==void 0&&this.attenuationColor!==void 0&&this.attenuationColor.setHex(e.attenuationColor),e.anisotropy!==void 0&&(this.anisotropy=e.anisotropy),e.anisotropyRotation!==void 0&&(this.anisotropyRotation=e.anisotropyRotation),e.fog!==void 0&&(this.fog=e.fog),e.flatShading!==void 0&&(this.flatShading=e.flatShading),e.blending!==void 0&&(this.blending=e.blending),e.combine!==void 0&&(this.combine=e.combine),e.side!==void 0&&(this.side=e.side),e.shadowSide!==void 0&&(this.shadowSide=e.shadowSide),e.opacity!==void 0&&(this.opacity=e.opacity),e.transparent!==void 0&&(this.transparent=e.transparent),e.alphaTest!==void 0&&(this.alphaTest=e.alphaTest),e.alphaHash!==void 0&&(this.alphaHash=e.alphaHash),e.depthFunc!==void 0&&(this.depthFunc=e.depthFunc),e.depthTest!==void 0&&(this.depthTest=e.depthTest),e.depthWrite!==void 0&&(this.depthWrite=e.depthWrite),e.colorWrite!==void 0&&(this.colorWrite=e.colorWrite),e.blendSrc!==void 0&&(this.blendSrc=e.blendSrc),e.blendDst!==void 0&&(this.blendDst=e.blendDst),e.blendEquation!==void 0&&(this.blendEquation=e.blendEquation),e.blendSrcAlpha!==void 0&&(this.blendSrcAlpha=e.blendSrcAlpha),e.blendDstAlpha!==void 0&&(this.blendDstAlpha=e.blendDstAlpha),e.blendEquationAlpha!==void 0&&(this.blendEquationAlpha=e.blendEquationAlpha),e.blendColor!==void 0&&this.blendColor!==void 0&&this.blendColor.setHex(e.blendColor),e.blendAlpha!==void 0&&(this.blendAlpha=e.blendAlpha),e.stencilWriteMask!==void 0&&(this.stencilWriteMask=e.stencilWriteMask),e.stencilFunc!==void 0&&(this.stencilFunc=e.stencilFunc),e.stencilRef!==void 0&&(this.stencilRef=e.stencilRef),e.stencilFuncMask!==void 0&&(this.stencilFuncMask=e.stencilFuncMask),e.stencilFail!==void 0&&(this.stencilFail=e.stencilFail),e.stencilZFail!==void 0&&(this.stencilZFail=e.stencilZFail),e.stencilZPass!==void 0&&(this.stencilZPass=e.stencilZPass),e.stencilWrite!==void 0&&(this.stencilWrite=e.stencilWrite),e.wireframe!==void 0&&(this.wireframe=e.wireframe),e.wireframeLinewidth!==void 0&&(this.wireframeLinewidth=e.wireframeLinewidth),e.wireframeLinecap!==void 0&&(this.wireframeLinecap=e.wireframeLinecap),e.wireframeLinejoin!==void 0&&(this.wireframeLinejoin=e.wireframeLinejoin),e.rotation!==void 0&&(this.rotation=e.rotation),e.linewidth!==void 0&&(this.linewidth=e.linewidth),e.dashSize!==void 0&&(this.dashSize=e.dashSize),e.gapSize!==void 0&&(this.gapSize=e.gapSize),e.scale!==void 0&&(this.scale=e.scale),e.polygonOffset!==void 0&&(this.polygonOffset=e.polygonOffset),e.polygonOffsetFactor!==void 0&&(this.polygonOffsetFactor=e.polygonOffsetFactor),e.polygonOffsetUnits!==void 0&&(this.polygonOffsetUnits=e.polygonOffsetUnits),e.dithering!==void 0&&(this.dithering=e.dithering),e.alphaToCoverage!==void 0&&(this.alphaToCoverage=e.alphaToCoverage),e.premultipliedAlpha!==void 0&&(this.premultipliedAlpha=e.premultipliedAlpha),e.forceSinglePass!==void 0&&(this.forceSinglePass=e.forceSinglePass),e.allowOverride!==void 0&&(this.allowOverride=e.allowOverride),e.visible!==void 0&&(this.visible=e.visible),e.toneMapped!==void 0&&(this.toneMapped=e.toneMapped),e.userData!==void 0&&(this.userData=e.userData),e.vertexColors!==void 0&&(typeof e.vertexColors=="number"?this.vertexColors=e.vertexColors>0:this.vertexColors=e.vertexColors),e.size!==void 0&&(this.size=e.size),e.sizeAttenuation!==void 0&&(this.sizeAttenuation=e.sizeAttenuation),e.map!==void 0&&(this.map=t[e.map]||null),e.matcap!==void 0&&(this.matcap=t[e.matcap]||null),e.alphaMap!==void 0&&(this.alphaMap=t[e.alphaMap]||null),e.bumpMap!==void 0&&(this.bumpMap=t[e.bumpMap]||null),e.bumpScale!==void 0&&(this.bumpScale=e.bumpScale),e.normalMap!==void 0&&(this.normalMap=t[e.normalMap]||null),e.normalMapType!==void 0&&(this.normalMapType=e.normalMapType),e.normalScale!==void 0){let i=e.normalScale;Array.isArray(i)===!1&&(i=[i,i]),this.normalScale=new we().fromArray(i)}return e.displacementMap!==void 0&&(this.displacementMap=t[e.displacementMap]||null),e.displacementScale!==void 0&&(this.displacementScale=e.displacementScale),e.displacementBias!==void 0&&(this.displacementBias=e.displacementBias),e.roughnessMap!==void 0&&(this.roughnessMap=t[e.roughnessMap]||null),e.metalnessMap!==void 0&&(this.metalnessMap=t[e.metalnessMap]||null),e.emissiveMap!==void 0&&(this.emissiveMap=t[e.emissiveMap]||null),e.emissiveIntensity!==void 0&&(this.emissiveIntensity=e.emissiveIntensity),e.specularMap!==void 0&&(this.specularMap=t[e.specularMap]||null),e.specularIntensityMap!==void 0&&(this.specularIntensityMap=t[e.specularIntensityMap]||null),e.specularColorMap!==void 0&&(this.specularColorMap=t[e.specularColorMap]||null),e.envMap!==void 0&&(this.envMap=t[e.envMap]||null),e.envMapRotation!==void 0&&this.envMapRotation.fromArray(e.envMapRotation),e.envMapIntensity!==void 0&&(this.envMapIntensity=e.envMapIntensity),e.reflectivity!==void 0&&(this.reflectivity=e.reflectivity),e.refractionRatio!==void 0&&(this.refractionRatio=e.refractionRatio),e.lightMap!==void 0&&(this.lightMap=t[e.lightMap]||null),e.lightMapIntensity!==void 0&&(this.lightMapIntensity=e.lightMapIntensity),e.aoMap!==void 0&&(this.aoMap=t[e.aoMap]||null),e.aoMapIntensity!==void 0&&(this.aoMapIntensity=e.aoMapIntensity),e.gradientMap!==void 0&&(this.gradientMap=t[e.gradientMap]||null),e.clearcoatMap!==void 0&&(this.clearcoatMap=t[e.clearcoatMap]||null),e.clearcoatRoughnessMap!==void 0&&(this.clearcoatRoughnessMap=t[e.clearcoatRoughnessMap]||null),e.clearcoatNormalMap!==void 0&&(this.clearcoatNormalMap=t[e.clearcoatNormalMap]||null),e.clearcoatNormalScale!==void 0&&(this.clearcoatNormalScale=new we().fromArray(e.clearcoatNormalScale)),e.iridescenceMap!==void 0&&(this.iridescenceMap=t[e.iridescenceMap]||null),e.iridescenceThicknessMap!==void 0&&(this.iridescenceThicknessMap=t[e.iridescenceThicknessMap]||null),e.transmissionMap!==void 0&&(this.transmissionMap=t[e.transmissionMap]||null),e.thicknessMap!==void 0&&(this.thicknessMap=t[e.thicknessMap]||null),e.anisotropyMap!==void 0&&(this.anisotropyMap=t[e.anisotropyMap]||null),e.sheenColorMap!==void 0&&(this.sheenColorMap=t[e.sheenColorMap]||null),e.sheenRoughnessMap!==void 0&&(this.sheenRoughnessMap=t[e.sheenRoughnessMap]||null),this}clone(){return new this.constructor().copy(this)}copy(e){this.name=e.name,this.blending=e.blending,this.side=e.side,this.vertexColors=e.vertexColors,this.opacity=e.opacity,this.transparent=e.transparent,this.blendSrc=e.blendSrc,this.blendDst=e.blendDst,this.blendEquation=e.blendEquation,this.blendSrcAlpha=e.blendSrcAlpha,this.blendDstAlpha=e.blendDstAlpha,this.blendEquationAlpha=e.blendEquationAlpha,this.blendColor.copy(e.blendColor),this.blendAlpha=e.blendAlpha,this.depthFunc=e.depthFunc,this.depthTest=e.depthTest,this.depthWrite=e.depthWrite,this.stencilWriteMask=e.stencilWriteMask,this.stencilFunc=e.stencilFunc,this.stencilRef=e.stencilRef,this.stencilFuncMask=e.stencilFuncMask,this.stencilFail=e.stencilFail,this.stencilZFail=e.stencilZFail,this.stencilZPass=e.stencilZPass,this.stencilWrite=e.stencilWrite;const t=e.clippingPlanes;let i=null;if(t!==null){const n=t.length;i=new Array(n);for(let s=0;s!==n;++s)i[s]=t[s].clone()}return this.clippingPlanes=i,this.clipIntersection=e.clipIntersection,this.clipShadows=e.clipShadows,this.shadowSide=e.shadowSide,this.colorWrite=e.colorWrite,this.precision=e.precision,this.polygonOffset=e.polygonOffset,this.polygonOffsetFactor=e.polygonOffsetFactor,this.polygonOffsetUnits=e.polygonOffsetUnits,this.dithering=e.dithering,this.alphaTest=e.alphaTest,this.alphaHash=e.alphaHash,this.alphaToCoverage=e.alphaToCoverage,this.premultipliedAlpha=e.premultipliedAlpha,this.forceSinglePass=e.forceSinglePass,this.allowOverride=e.allowOverride,this.visible=e.visible,this.toneMapped=e.toneMapped,this.userData=JSON.parse(JSON.stringify(e.userData)),this}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(e){e===!0&&this.version++}}class eu extends Ar{constructor(e){super(),this.isSpriteMaterial=!0,this.type="SpriteMaterial",this.color=new ne(16777215),this.map=null,this.alphaMap=null,this.rotation=0,this.sizeAttenuation=!0,this.transparent=!0,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.alphaMap=e.alphaMap,this.rotation=e.rotation,this.sizeAttenuation=e.sizeAttenuation,this.fog=e.fog,this}}let sl;const wc=new D,rl=new D,al=new D,ol=new we,xc=new we,uw=new lt,Qh=new D,Sc=new D,ed=new D,y1=new we,hp=new we,b1=new we;class Ec extends hi{constructor(e=new eu){if(super(),this.isSprite=!0,this.type="Sprite",sl===void 0){sl=new ot;const t=new Float32Array([-.5,-.5,0,0,0,.5,-.5,0,1,0,.5,.5,0,1,1,-.5,.5,0,0,1]),i=new dw(t,5);sl.setIndex([0,1,2,0,2,3]),sl.setAttribute("position",new $u(i,3,0,!1)),sl.setAttribute("uv",new $u(i,2,3,!1))}this.geometry=sl,this.material=e,this.center=new we(.5,.5),this.count=1}raycast(e,t){e.camera===null&&je('Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.'),rl.setFromMatrixScale(this.matrixWorld),uw.copy(e.camera.matrixWorld),this.modelViewMatrix.multiplyMatrices(e.camera.matrixWorldInverse,this.matrixWorld),al.setFromMatrixPosition(this.modelViewMatrix),e.camera.isPerspectiveCamera&&this.material.sizeAttenuation===!1&&rl.multiplyScalar(-al.z);const i=this.material.rotation;let n,s;i!==0&&(s=Math.cos(i),n=Math.sin(i));const r=this.center;td(Qh.set(-.5,-.5,0),al,r,rl,n,s),td(Sc.set(.5,-.5,0),al,r,rl,n,s),td(ed.set(.5,.5,0),al,r,rl,n,s),y1.set(0,0),hp.set(1,0),b1.set(1,1);let a=e.ray.intersectTriangle(Qh,Sc,ed,!1,wc);if(a===null&&(td(Sc.set(-.5,.5,0),al,r,rl,n,s),hp.set(0,1),a=e.ray.intersectTriangle(Qh,ed,Sc,!1,wc),a===null))return;const l=e.ray.origin.distanceTo(wc);l<e.near||l>e.far||t.push({distance:l,point:wc.clone(),uv:As.getInterpolation(wc,Qh,Sc,ed,y1,hp,b1,new we),face:null,object:this})}copy(e,t){return super.copy(e,t),e.center!==void 0&&this.center.copy(e.center),this.material=e.material,this}}function td(o,e,t,i,n,s){ol.subVectors(o,t).addScalar(.5).multiply(i),n!==void 0?(xc.x=s*ol.x-n*ol.y,xc.y=n*ol.x+s*ol.y):xc.copy(ol),o.copy(e),o.x+=xc.x,o.y+=xc.y,o.applyMatrix4(uw)}const Rr=new D,dp=new D,id=new D,na=new D,up=new D,nd=new D,fp=new D;class Ch{constructor(e=new D,t=new D(0,0,-1)){this.origin=e,this.direction=t}set(e,t){return this.origin.copy(e),this.direction.copy(t),this}copy(e){return this.origin.copy(e.origin),this.direction.copy(e.direction),this}at(e,t){return t.copy(this.origin).addScaledVector(this.direction,e)}lookAt(e){return this.direction.copy(e).sub(this.origin).normalize(),this}recast(e){return this.origin.copy(this.at(e,Rr)),this}closestPointToPoint(e,t){t.subVectors(e,this.origin);const i=t.dot(this.direction);return i<0?t.copy(this.origin):t.copy(this.origin).addScaledVector(this.direction,i)}distanceToPoint(e){return Math.sqrt(this.distanceSqToPoint(e))}distanceSqToPoint(e){const t=Rr.subVectors(e,this.origin).dot(this.direction);return t<0?this.origin.distanceToSquared(e):(Rr.copy(this.origin).addScaledVector(this.direction,t),Rr.distanceToSquared(e))}distanceSqToSegment(e,t,i,n){dp.copy(e).add(t).multiplyScalar(.5),id.copy(t).sub(e).normalize(),na.copy(this.origin).sub(dp);const s=e.distanceTo(t)*.5,r=-this.direction.dot(id),a=na.dot(this.direction),l=-na.dot(id),c=na.lengthSq(),h=Math.abs(1-r*r);let d,u,f,p;if(h>0)if(d=r*l-a,u=r*a-l,p=s*h,d>=0)if(u>=-p)if(u<=p){const g=1/h;d*=g,u*=g,f=d*(d+r*u+2*a)+u*(r*d+u+2*l)+c}else u=s,d=Math.max(0,-(r*u+a)),f=-d*d+u*(u+2*l)+c;else u=-s,d=Math.max(0,-(r*u+a)),f=-d*d+u*(u+2*l)+c;else u<=-p?(d=Math.max(0,-(-r*s+a)),u=d>0?-s:Math.min(Math.max(-s,-l),s),f=-d*d+u*(u+2*l)+c):u<=p?(d=0,u=Math.min(Math.max(-s,-l),s),f=u*(u+2*l)+c):(d=Math.max(0,-(r*s+a)),u=d>0?s:Math.min(Math.max(-s,-l),s),f=-d*d+u*(u+2*l)+c);else u=r>0?-s:s,d=Math.max(0,-(r*u+a)),f=-d*d+u*(u+2*l)+c;return i&&i.copy(this.origin).addScaledVector(this.direction,d),n&&n.copy(dp).addScaledVector(id,u),f}intersectSphere(e,t){Rr.subVectors(e.center,this.origin);const i=Rr.dot(this.direction),n=Rr.dot(Rr)-i*i,s=e.radius*e.radius;if(n>s)return null;const r=Math.sqrt(s-n),a=i-r,l=i+r;return l<0?null:a<0?this.at(l,t):this.at(a,t)}intersectsSphere(e){return e.radius<0?!1:this.distanceSqToPoint(e.center)<=e.radius*e.radius}distanceToPlane(e){const t=e.normal.dot(this.direction);if(t===0)return e.distanceToPoint(this.origin)===0?0:null;const i=-(this.origin.dot(e.normal)+e.constant)/t;return i>=0?i:null}intersectPlane(e,t){const i=this.distanceToPlane(e);return i===null?null:this.at(i,t)}intersectsPlane(e){const t=e.distanceToPoint(this.origin);return t===0||e.normal.dot(this.direction)*t<0}intersectBox(e,t){let i,n,s,r,a,l;const c=1/this.direction.x,h=1/this.direction.y,d=1/this.direction.z,u=this.origin;return c>=0?(i=(e.min.x-u.x)*c,n=(e.max.x-u.x)*c):(i=(e.max.x-u.x)*c,n=(e.min.x-u.x)*c),h>=0?(s=(e.min.y-u.y)*h,r=(e.max.y-u.y)*h):(s=(e.max.y-u.y)*h,r=(e.min.y-u.y)*h),i>r||s>n||((s>i||isNaN(i))&&(i=s),(r<n||isNaN(n))&&(n=r),d>=0?(a=(e.min.z-u.z)*d,l=(e.max.z-u.z)*d):(a=(e.max.z-u.z)*d,l=(e.min.z-u.z)*d),i>l||a>n)||((a>i||i!==i)&&(i=a),(l<n||n!==n)&&(n=l),n<0)?null:this.at(i>=0?i:n,t)}intersectsBox(e){return this.intersectBox(e,Rr)!==null}intersectTriangle(e,t,i,n,s){up.subVectors(t,e),nd.subVectors(i,e),fp.crossVectors(up,nd);let r=this.direction.dot(fp),a;if(r>0){if(n)return null;a=1}else if(r<0)a=-1,r=-r;else return null;na.subVectors(this.origin,e);const l=a*this.direction.dot(nd.crossVectors(na,nd));if(l<0)return null;const c=a*this.direction.dot(up.cross(na));if(c<0||l+c>r)return null;const h=-a*na.dot(fp);return h<0?null:this.at(h/r,s)}applyMatrix4(e){return this.origin.applyMatrix4(e),this.direction.transformDirection(e),this}equals(e){return e.origin.equals(this.origin)&&e.direction.equals(this.direction)}clone(){return new this.constructor().copy(this)}}class Hn extends Ar{constructor(e){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new ne(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new wr,this.combine=og,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.specularMap=e.specularMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.combine=e.combine,this.reflectivity=e.reflectivity,this.refractionRatio=e.refractionRatio,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.fog=e.fog,this}}const M1=new lt,Ha=new Ch,sd=new qr,w1=new D,rd=new D,ad=new D,od=new D,pp=new D,ld=new D,x1=new D,cd=new D;class Se extends hi{constructor(e=new ot,t=new Hn){super(),this.isMesh=!0,this.type="Mesh",this.geometry=e,this.material=t,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.count=1,this.updateMorphTargets()}copy(e,t){return super.copy(e,t),e.morphTargetInfluences!==void 0&&(this.morphTargetInfluences=e.morphTargetInfluences.slice()),e.morphTargetDictionary!==void 0&&(this.morphTargetDictionary=Object.assign({},e.morphTargetDictionary)),this.material=Array.isArray(e.material)?e.material.slice():e.material,this.geometry=e.geometry,this}updateMorphTargets(){const t=this.geometry.morphAttributes,i=Object.keys(t);if(i.length>0){const n=t[i[0]];if(n!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let s=0,r=n.length;s<r;s++){const a=n[s].name||String(s);this.morphTargetInfluences.push(0),this.morphTargetDictionary[a]=s}}}}getVertexPosition(e,t){const i=this.geometry,n=i.attributes.position,s=i.morphAttributes.position,r=i.morphTargetsRelative;t.fromBufferAttribute(n,e);const a=this.morphTargetInfluences;if(s&&a){ld.set(0,0,0);for(let l=0,c=s.length;l<c;l++){const h=a[l],d=s[l];h!==0&&(pp.fromBufferAttribute(d,e),r?ld.addScaledVector(pp,h):ld.addScaledVector(pp.sub(t),h))}t.add(ld)}return t}raycast(e,t){const i=this.geometry,n=this.material,s=this.matrixWorld;n!==void 0&&(i.boundingSphere===null&&i.computeBoundingSphere(),sd.copy(i.boundingSphere),sd.applyMatrix4(s),Ha.copy(e.ray).recast(e.near),!(sd.containsPoint(Ha.origin)===!1&&(Ha.intersectSphere(sd,w1)===null||Ha.origin.distanceToSquared(w1)>(e.far-e.near)**2))&&(M1.copy(s).invert(),Ha.copy(e.ray).applyMatrix4(M1),!(i.boundingBox!==null&&Ha.intersectsBox(i.boundingBox)===!1)&&this._computeIntersections(e,t,Ha)))}_computeIntersections(e,t,i){let n;const s=this.geometry,r=this.material,a=s.index,l=s.attributes.position,c=s.attributes.uv,h=s.attributes.uv1,d=s.attributes.normal,u=s.groups,f=s.drawRange;if(a!==null)if(Array.isArray(r))for(let p=0,g=u.length;p<g;p++){const m=u[p],v=r[m.materialIndex],b=Math.max(m.start,f.start),x=Math.min(a.count,Math.min(m.start+m.count,f.start+f.count));for(let y=b,w=x;y<w;y+=3){const S=a.getX(y),A=a.getX(y+1),M=a.getX(y+2);n=hd(this,v,e,i,c,h,d,S,A,M),n&&(n.faceIndex=Math.floor(y/3),n.face.materialIndex=m.materialIndex,t.push(n))}}else{const p=Math.max(0,f.start),g=Math.min(a.count,f.start+f.count);for(let m=p,v=g;m<v;m+=3){const b=a.getX(m),x=a.getX(m+1),y=a.getX(m+2);n=hd(this,r,e,i,c,h,d,b,x,y),n&&(n.faceIndex=Math.floor(m/3),t.push(n))}}else if(l!==void 0)if(Array.isArray(r))for(let p=0,g=u.length;p<g;p++){const m=u[p],v=r[m.materialIndex],b=Math.max(m.start,f.start),x=Math.min(l.count,Math.min(m.start+m.count,f.start+f.count));for(let y=b,w=x;y<w;y+=3){const S=y,A=y+1,M=y+2;n=hd(this,v,e,i,c,h,d,S,A,M),n&&(n.faceIndex=Math.floor(y/3),n.face.materialIndex=m.materialIndex,t.push(n))}}else{const p=Math.max(0,f.start),g=Math.min(l.count,f.start+f.count);for(let m=p,v=g;m<v;m+=3){const b=m,x=m+1,y=m+2;n=hd(this,r,e,i,c,h,d,b,x,y),n&&(n.faceIndex=Math.floor(m/3),t.push(n))}}}}function I3(o,e,t,i,n,s,r,a){let l;if(e.side===fi?l=i.intersectTriangle(r,s,n,!0,a):l=i.intersectTriangle(n,s,r,e.side===Pa,a),l===null)return null;cd.copy(a),cd.applyMatrix4(o.matrixWorld);const c=t.ray.origin.distanceTo(cd);return c<t.near||c>t.far?null:{distance:c,point:cd.clone(),object:o}}function hd(o,e,t,i,n,s,r,a,l,c){o.getVertexPosition(a,rd),o.getVertexPosition(l,ad),o.getVertexPosition(c,od);const h=I3(o,e,t,i,rd,ad,od,x1);if(h){const d=new D;As.getBarycoord(x1,rd,ad,od,d),n&&(h.uv=As.getInterpolatedAttribute(n,a,l,c,d,new we)),s&&(h.uv1=As.getInterpolatedAttribute(s,a,l,c,d,new we)),r&&(h.normal=As.getInterpolatedAttribute(r,a,l,c,d,new D),h.normal.dot(i.direction)>0&&h.normal.multiplyScalar(-1));const u={a,b:l,c,normal:new D,materialIndex:0};As.getNormal(rd,ad,od,u.normal),h.face=u,h.barycoord=d}return h}const Ac=new wt,S1=new wt,E1=new wt,D3=new wt,A1=new lt,dd=new D,mp=new qr,_1=new lt,gp=new Ch;class Vk extends Se{constructor(e,t){super(e,t),this.isSkinnedMesh=!0,this.type="SkinnedMesh",this.bindMode=i1,this.bindMatrix=new lt,this.bindMatrixInverse=new lt,this.boundingBox=null,this.boundingSphere=null}computeBoundingBox(){const e=this.geometry;this.boundingBox===null&&(this.boundingBox=new on),this.boundingBox.makeEmpty();const t=e.getAttribute("position");for(let i=0;i<t.count;i++)this.getVertexPosition(i,dd),this.boundingBox.expandByPoint(dd)}computeBoundingSphere(){const e=this.geometry;this.boundingSphere===null&&(this.boundingSphere=new qr),this.boundingSphere.makeEmpty();const t=e.getAttribute("position");for(let i=0;i<t.count;i++)this.getVertexPosition(i,dd),this.boundingSphere.expandByPoint(dd)}copy(e,t){return super.copy(e,t),this.bindMode=e.bindMode,this.bindMatrix.copy(e.bindMatrix),this.bindMatrixInverse.copy(e.bindMatrixInverse),this.skeleton=e.skeleton,e.boundingBox!==null&&(this.boundingBox=e.boundingBox.clone()),e.boundingSphere!==null&&(this.boundingSphere=e.boundingSphere.clone()),this}raycast(e,t){const i=this.material,n=this.matrixWorld;i!==void 0&&(this.boundingSphere===null&&this.computeBoundingSphere(),mp.copy(this.boundingSphere),mp.applyMatrix4(n),e.ray.intersectsSphere(mp)!==!1&&(_1.copy(n).invert(),gp.copy(e.ray).applyMatrix4(_1),!(this.boundingBox!==null&&gp.intersectsBox(this.boundingBox)===!1)&&this._computeIntersections(e,t,gp)))}getVertexPosition(e,t){return super.getVertexPosition(e,t),this.applyBoneTransform(e,t),t}bind(e,t){this.skeleton=e,t===void 0&&(this.updateMatrixWorld(!0),this.skeleton.calculateInverses(),t=this.matrixWorld),this.bindMatrix.copy(t),this.bindMatrixInverse.copy(t).invert()}pose(){this.skeleton.pose()}normalizeSkinWeights(){const e=new wt,t=this.geometry.attributes.skinWeight;for(let i=0,n=t.count;i<n;i++){e.fromBufferAttribute(t,i);const s=1/e.manhattanLength();s!==1/0?e.multiplyScalar(s):e.set(1,0,0,0),t.setXYZW(i,e.x,e.y,e.z,e.w)}}updateMatrixWorld(e){super.updateMatrixWorld(e),this.bindMode===i1?this.bindMatrixInverse.copy(this.matrixWorld).invert():this.bindMode===DE?this.bindMatrixInverse.copy(this.bindMatrix).invert():ke("SkinnedMesh: Unrecognized bindMode: "+this.bindMode)}applyBoneTransform(e,t){const i=this.skeleton,n=this.geometry;S1.fromBufferAttribute(n.attributes.skinIndex,e),E1.fromBufferAttribute(n.attributes.skinWeight,e),t.isVector4?(Ac.copy(t),t.set(0,0,0,0)):(Ac.set(...t,1),t.set(0,0,0)),Ac.applyMatrix4(this.bindMatrix);for(let s=0;s<4;s++){const r=E1.getComponent(s);if(r!==0){const a=S1.getComponent(s);A1.multiplyMatrices(i.bones[a].matrixWorld,i.boneInverses[a]),t.addScaledVector(D3.copy(Ac).applyMatrix4(A1),r)}}return t.isVector4&&(t.w=Ac.w),t.applyMatrix4(this.bindMatrixInverse)}}class R3 extends hi{constructor(){super(),this.isBone=!0,this.type="Bone"}}class ps extends ln{constructor(e=null,t=1,i=1,n,s,r,a,l,c=Qt,h=Qt,d,u){super(null,r,a,l,c,h,n,s,d,u),this.isDataTexture=!0,this.image={data:e,width:t,height:i},this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}const T1=new lt,C3=new lt;class fw{constructor(e=[],t=[]){this.uuid=Ws(),this.bones=e.slice(0),this.boneInverses=t,this.boneMatrices=null,this.boneTexture=null,this.init()}init(){const e=this.bones,t=this.boneInverses;if(this.boneMatrices=new Float32Array(e.length*16),t.length===0)this.calculateInverses();else if(e.length!==t.length){ke("Skeleton: Number of inverse bone matrices does not match amount of bones."),this.boneInverses=[];for(let i=0,n=this.bones.length;i<n;i++)this.boneInverses.push(new lt)}}calculateInverses(){this.boneInverses.length=0;for(let e=0,t=this.bones.length;e<t;e++){const i=new lt;this.bones[e]&&i.copy(this.bones[e].matrixWorld).invert(),this.boneInverses.push(i)}}pose(){for(let e=0,t=this.bones.length;e<t;e++){const i=this.bones[e];i&&i.matrixWorld.copy(this.boneInverses[e]).invert()}for(let e=0,t=this.bones.length;e<t;e++){const i=this.bones[e];i&&(i.parent&&i.parent.isBone?(i.matrix.copy(i.parent.matrixWorld).invert(),i.matrix.multiply(i.matrixWorld)):i.matrix.copy(i.matrixWorld),i.matrix.decompose(i.position,i.quaternion,i.scale))}}update(){const e=this.bones,t=this.boneInverses,i=this.boneMatrices,n=this.boneTexture;for(let s=0,r=e.length;s<r;s++){const a=e[s]?e[s].matrixWorld:C3;T1.multiplyMatrices(a,t[s]),T1.toArray(i,s*16)}n!==null&&(n.needsUpdate=!0)}clone(){return new fw(this.bones,this.boneInverses)}computeBoneTexture(){let e=Math.sqrt(this.bones.length*4);e=Math.ceil(e/4)*4,e=Math.max(e,4);const t=new Float32Array(e*e*4);t.set(this.boneMatrices);const i=new ps(t,e,e,Vi,En);return i.needsUpdate=!0,this.boneMatrices=t,this.boneTexture=i,this}getBoneByName(e){for(let t=0,i=this.bones.length;t<i;t++){const n=this.bones[t];if(n.name===e)return n}}dispose(){this.boneTexture!==null&&(this.boneTexture.dispose(),this.boneTexture=null)}fromJSON(e,t){this.uuid=e.uuid;for(let i=0,n=e.bones.length;i<n;i++){const s=e.bones[i];let r=t[s];r===void 0&&(ke("Skeleton: No bone found with UUID:",s),r=new R3),this.bones.push(r),this.boneInverses.push(new lt().fromArray(e.boneInverses[i]))}return this.init(),this}toJSON(){const e={metadata:{version:4.7,type:"Skeleton",generator:"Skeleton.toJSON"},bones:[],boneInverses:[]};e.uuid=this.uuid;const t=this.bones,i=this.boneInverses;for(let n=0,s=t.length;n<s;n++){const r=t[n];e.bones.push(r.uuid);const a=i[n];e.boneInverses.push(a.toArray())}return e}}class I1 extends st{constructor(e,t,i,n=1){super(e,t,i),this.isInstancedBufferAttribute=!0,this.meshPerAttribute=n}copy(e){return super.copy(e),this.meshPerAttribute=e.meshPerAttribute,this}toJSON(){const e=super.toJSON();return e.meshPerAttribute=this.meshPerAttribute,e.isInstancedBufferAttribute=!0,e}}const ll=new lt,D1=new lt,ud=[],R1=new on,k3=new lt,_c=new Se,Tc=new qr;class Wk extends Se{constructor(e,t,i){super(e,t),this.isInstancedMesh=!0,this.instanceMatrix=new I1(new Float32Array(i*16),16),this.instanceColor=null,this.morphTexture=null,this.count=i,this.boundingBox=null,this.boundingSphere=null;for(let n=0;n<i;n++)this.setMatrixAt(n,k3)}computeBoundingBox(){const e=this.geometry,t=this.count;this.boundingBox===null&&(this.boundingBox=new on),e.boundingBox===null&&e.computeBoundingBox(),this.boundingBox.makeEmpty();for(let i=0;i<t;i++)this.getMatrixAt(i,ll),R1.copy(e.boundingBox).applyMatrix4(ll),this.boundingBox.union(R1)}computeBoundingSphere(){const e=this.geometry,t=this.count;this.boundingSphere===null&&(this.boundingSphere=new qr),e.boundingSphere===null&&e.computeBoundingSphere(),this.boundingSphere.makeEmpty();for(let i=0;i<t;i++)this.getMatrixAt(i,ll),Tc.copy(e.boundingSphere).applyMatrix4(ll),this.boundingSphere.union(Tc)}copy(e,t){return super.copy(e,t),this.instanceMatrix.copy(e.instanceMatrix),e.morphTexture!==null&&(this.morphTexture=e.morphTexture.clone()),e.instanceColor!==null&&(this.instanceColor=e.instanceColor.clone()),this.count=e.count,e.boundingBox!==null&&(this.boundingBox=e.boundingBox.clone()),e.boundingSphere!==null&&(this.boundingSphere=e.boundingSphere.clone()),this}getColorAt(e,t){return this.instanceColor===null?t.setRGB(1,1,1):t.fromArray(this.instanceColor.array,e*3)}getMatrixAt(e,t){return t.fromArray(this.instanceMatrix.array,e*16)}getMorphAt(e,t){const i=t.morphTargetInfluences,n=this.morphTexture.source.data.data,s=i.length+1,r=e*s+1;for(let a=0;a<i.length;a++)i[a]=n[r+a]}raycast(e,t){const i=this.matrixWorld,n=this.count;if(_c.geometry=this.geometry,_c.material=this.material,_c.material!==void 0&&(this.boundingSphere===null&&this.computeBoundingSphere(),Tc.copy(this.boundingSphere),Tc.applyMatrix4(i),e.ray.intersectsSphere(Tc)!==!1))for(let s=0;s<n;s++){this.getMatrixAt(s,ll),D1.multiplyMatrices(i,ll),_c.matrixWorld=D1,_c.raycast(e,ud);for(let r=0,a=ud.length;r<a;r++){const l=ud[r];l.instanceId=s,l.object=this,t.push(l)}ud.length=0}}setColorAt(e,t){return this.instanceColor===null&&(this.instanceColor=new I1(new Float32Array(this.instanceMatrix.count*3).fill(1),3)),t.toArray(this.instanceColor.array,e*3),this}setMatrixAt(e,t){return t.toArray(this.instanceMatrix.array,e*16),this}setMorphAt(e,t){const i=t.morphTargetInfluences,n=i.length+1;this.morphTexture===null&&(this.morphTexture=new ps(new Float32Array(n*this.count),n,this.count,ac,En));const s=this.morphTexture.source.data.data;let r=0;for(let c=0;c<i.length;c++)r+=i[c];const a=this.geometry.morphTargetsRelative?1:1-r,l=n*e;return s[l]=a,s.set(i,l+1),this}updateMorphTargets(){}dispose(){this.dispatchEvent({type:"dispose"}),this.morphTexture!==null&&(this.morphTexture.dispose(),this.morphTexture=null)}}const vp=new D,P3=new D,L3=new Je;class ma{constructor(e=new D(1,0,0),t=0){this.isPlane=!0,this.normal=e,this.constant=t}set(e,t){return this.normal.copy(e),this.constant=t,this}setComponents(e,t,i,n){return this.normal.set(e,t,i),this.constant=n,this}setFromNormalAndCoplanarPoint(e,t){return this.normal.copy(e),this.constant=-t.dot(this.normal),this}setFromCoplanarPoints(e,t,i){const n=vp.subVectors(i,t).cross(P3.subVectors(e,t)).normalize();return this.setFromNormalAndCoplanarPoint(n,e),this}copy(e){return this.normal.copy(e.normal),this.constant=e.constant,this}normalize(){const e=1/this.normal.length();return this.normal.multiplyScalar(e),this.constant*=e,this}negate(){return this.constant*=-1,this.normal.negate(),this}distanceToPoint(e){return this.normal.dot(e)+this.constant}distanceToSphere(e){return this.distanceToPoint(e.center)-e.radius}projectPoint(e,t){return t.copy(e).addScaledVector(this.normal,-this.distanceToPoint(e))}intersectLine(e,t,i=!0){const n=e.delta(vp),s=this.normal.dot(n);if(s===0)return this.distanceToPoint(e.start)===0?t.copy(e.start):null;const r=-(e.start.dot(this.normal)+this.constant)/s;return i===!0&&(r<0||r>1)?null:t.copy(e.start).addScaledVector(n,r)}intersectsLine(e){const t=this.distanceToPoint(e.start),i=this.distanceToPoint(e.end);return t<0&&i>0||i<0&&t>0}intersectsBox(e){return e.intersectsPlane(this)}intersectsSphere(e){return e.intersectsPlane(this)}coplanarPoint(e){return e.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(e,t){const i=t||L3.getNormalMatrix(e),n=this.coplanarPoint(vp).applyMatrix4(e),s=this.normal.applyMatrix3(i).normalize();return this.constant=-n.dot(s),this}translate(e){return this.constant-=e.dot(this.normal),this}equals(e){return e.normal.equals(this.normal)&&e.constant===this.constant}clone(){return new this.constructor().copy(this)}}const Ga=new qr,O3=new we(.5,.5),fd=new D;class xg{constructor(e=new ma,t=new ma,i=new ma,n=new ma,s=new ma,r=new ma){this.planes=[e,t,i,n,s,r]}set(e,t,i,n,s,r){const a=this.planes;return a[0].copy(e),a[1].copy(t),a[2].copy(i),a[3].copy(n),a[4].copy(s),a[5].copy(r),this}copy(e){const t=this.planes;for(let i=0;i<6;i++)t[i].copy(e.planes[i]);return this}setFromProjectionMatrix(e,t=vr,i=!1){const n=this.planes,s=e.elements,r=s[0],a=s[1],l=s[2],c=s[3],h=s[4],d=s[5],u=s[6],f=s[7],p=s[8],g=s[9],m=s[10],v=s[11],b=s[12],x=s[13],y=s[14],w=s[15];if(n[0].setComponents(c-r,f-h,v-p,w-b).normalize(),n[1].setComponents(c+r,f+h,v+p,w+b).normalize(),n[2].setComponents(c+a,f+d,v+g,w+x).normalize(),n[3].setComponents(c-a,f-d,v-g,w-x).normalize(),i)n[4].setComponents(l,u,m,y).normalize(),n[5].setComponents(c-l,f-u,v-m,w-y).normalize();else if(n[4].setComponents(c-l,f-u,v-m,w-y).normalize(),t===vr)n[5].setComponents(c+l,f+u,v+m,w+y).normalize();else if(t===xh)n[5].setComponents(l,u,m,y).normalize();else throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: "+t);return this}intersectsObject(e){if(e.boundingSphere!==void 0)e.boundingSphere===null&&e.computeBoundingSphere(),Ga.copy(e.boundingSphere).applyMatrix4(e.matrixWorld);else{const t=e.geometry;t.boundingSphere===null&&t.computeBoundingSphere(),Ga.copy(t.boundingSphere).applyMatrix4(e.matrixWorld)}return this.intersectsSphere(Ga)}intersectsSprite(e){Ga.center.set(0,0,0);const t=O3.distanceTo(e.center);return Ga.radius=.7071067811865476+t,Ga.applyMatrix4(e.matrixWorld),this.intersectsSphere(Ga)}intersectsSphere(e){const t=this.planes,i=e.center,n=-e.radius;for(let s=0;s<6;s++)if(t[s].distanceToPoint(i)<n)return!1;return!0}intersectsBox(e){const t=this.planes;for(let i=0;i<6;i++){const n=t[i];if(fd.x=n.normal.x>0?e.max.x:e.min.x,fd.y=n.normal.y>0?e.max.y:e.min.y,fd.z=n.normal.z>0?e.max.z:e.min.z,n.distanceToPoint(fd)<0)return!1}return!0}containsPoint(e){const t=this.planes;for(let i=0;i<6;i++)if(t[i].distanceToPoint(e)<0)return!1;return!0}clone(){return new this.constructor().copy(this)}}class N3 extends Ar{constructor(e){super(),this.isLineBasicMaterial=!0,this.type="LineBasicMaterial",this.color=new ne(16777215),this.map=null,this.linewidth=1,this.linecap="round",this.linejoin="round",this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.linewidth=e.linewidth,this.linecap=e.linecap,this.linejoin=e.linejoin,this.fog=e.fog,this}}const Yu=new D,qu=new D,C1=new lt,Ic=new Ch,pd=new qr,yp=new D,k1=new D;class pw extends hi{constructor(e=new ot,t=new N3){super(),this.isLine=!0,this.type="Line",this.geometry=e,this.material=t,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.updateMorphTargets()}copy(e,t){return super.copy(e,t),this.material=Array.isArray(e.material)?e.material.slice():e.material,this.geometry=e.geometry,this}computeLineDistances(){const e=this.geometry;if(e.index===null){const t=e.attributes.position,i=[0];for(let n=1,s=t.count;n<s;n++)Yu.fromBufferAttribute(t,n-1),qu.fromBufferAttribute(t,n),i[n]=i[n-1],i[n]+=Yu.distanceTo(qu);e.setAttribute("lineDistance",new yt(i,1))}else ke("Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.");return this}raycast(e,t){const i=this.geometry,n=this.matrixWorld,s=e.params.Line.threshold,r=i.drawRange;if(i.boundingSphere===null&&i.computeBoundingSphere(),pd.copy(i.boundingSphere),pd.applyMatrix4(n),pd.radius+=s,e.ray.intersectsSphere(pd)===!1)return;C1.copy(n).invert(),Ic.copy(e.ray).applyMatrix4(C1);const a=s/((this.scale.x+this.scale.y+this.scale.z)/3),l=a*a,c=this.isLineSegments?2:1,h=i.index,u=i.attributes.position;if(h!==null){const f=Math.max(0,r.start),p=Math.min(h.count,r.start+r.count);for(let g=f,m=p-1;g<m;g+=c){const v=h.getX(g),b=h.getX(g+1),x=md(this,e,Ic,l,v,b,g);x&&t.push(x)}if(this.isLineLoop){const g=h.getX(p-1),m=h.getX(f),v=md(this,e,Ic,l,g,m,p-1);v&&t.push(v)}}else{const f=Math.max(0,r.start),p=Math.min(u.count,r.start+r.count);for(let g=f,m=p-1;g<m;g+=c){const v=md(this,e,Ic,l,g,g+1,g);v&&t.push(v)}if(this.isLineLoop){const g=md(this,e,Ic,l,p-1,f,p-1);g&&t.push(g)}}}updateMorphTargets(){const t=this.geometry.morphAttributes,i=Object.keys(t);if(i.length>0){const n=t[i[0]];if(n!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let s=0,r=n.length;s<r;s++){const a=n[s].name||String(s);this.morphTargetInfluences.push(0),this.morphTargetDictionary[a]=s}}}}}function md(o,e,t,i,n,s,r){const a=o.geometry.attributes.position;if(Yu.fromBufferAttribute(a,n),qu.fromBufferAttribute(a,s),t.distanceSqToSegment(Yu,qu,yp,k1)>i)return;yp.applyMatrix4(o.matrixWorld);const c=e.ray.origin.distanceTo(yp);if(!(c<e.near||c>e.far))return{distance:c,point:k1.clone().applyMatrix4(o.matrixWorld),index:r,face:null,faceIndex:null,barycoord:null,object:o}}const P1=new D,L1=new D;class Xk extends pw{constructor(e,t){super(e,t),this.isLineSegments=!0,this.type="LineSegments"}computeLineDistances(){const e=this.geometry;if(e.index===null){const t=e.attributes.position,i=[];for(let n=0,s=t.count;n<s;n+=2)P1.fromBufferAttribute(t,n),L1.fromBufferAttribute(t,n+1),i[n]=n===0?0:i[n-1],i[n+1]=i[n]+P1.distanceTo(L1);e.setAttribute("lineDistance",new yt(i,1))}else ke("LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.");return this}}class $k extends pw{constructor(e,t){super(e,t),this.isLineLoop=!0,this.type="LineLoop"}}class um extends Ar{constructor(e){super(),this.isPointsMaterial=!0,this.type="PointsMaterial",this.color=new ne(16777215),this.map=null,this.alphaMap=null,this.size=1,this.sizeAttenuation=!0,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.alphaMap=e.alphaMap,this.size=e.size,this.sizeAttenuation=e.sizeAttenuation,this.fog=e.fog,this}}const O1=new lt,fm=new Ch,gd=new qr,vd=new D;class ls extends hi{constructor(e=new ot,t=new um){super(),this.isPoints=!0,this.type="Points",this.geometry=e,this.material=t,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.updateMorphTargets()}copy(e,t){return super.copy(e,t),this.material=Array.isArray(e.material)?e.material.slice():e.material,this.geometry=e.geometry,this}raycast(e,t){const i=this.geometry,n=this.matrixWorld,s=e.params.Points.threshold,r=i.drawRange;if(i.boundingSphere===null&&i.computeBoundingSphere(),gd.copy(i.boundingSphere),gd.applyMatrix4(n),gd.radius+=s,e.ray.intersectsSphere(gd)===!1)return;O1.copy(n).invert(),fm.copy(e.ray).applyMatrix4(O1);const a=s/((this.scale.x+this.scale.y+this.scale.z)/3),l=a*a,c=i.index,d=i.attributes.position;if(c!==null){const u=Math.max(0,r.start),f=Math.min(c.count,r.start+r.count);for(let p=u,g=f;p<g;p++){const m=c.getX(p);vd.fromBufferAttribute(d,m),N1(vd,m,l,n,e,t,this)}}else{const u=Math.max(0,r.start),f=Math.min(d.count,r.start+r.count);for(let p=u,g=f;p<g;p++)vd.fromBufferAttribute(d,p),N1(vd,p,l,n,e,t,this)}}updateMorphTargets(){const t=this.geometry.morphAttributes,i=Object.keys(t);if(i.length>0){const n=t[i[0]];if(n!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let s=0,r=n.length;s<r;s++){const a=n[s].name||String(s);this.morphTargetInfluences.push(0),this.morphTargetDictionary[a]=s}}}}}function N1(o,e,t,i,n,s,r){const a=fm.distanceSqToPoint(o);if(a<t){const l=new D;fm.closestPointToPoint(o,l),l.applyMatrix4(i);const c=n.ray.origin.distanceTo(l);if(c<n.near||c>n.far)return;s.push({distance:c,distanceToRay:Math.sqrt(a),point:l,index:e,face:null,faceIndex:null,barycoord:null,object:r})}}class mw extends ln{constructor(e=[],t=Oo,i,n,s,r,a,l,c,h){super(e,t,i,n,s,r,a,l,c,h),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(e){this.image=e}}class Kr extends ln{constructor(e,t,i,n,s,r,a,l,c){super(e,t,i,n,s,r,a,l,c),this.isCanvasTexture=!0,this.needsUpdate=!0}}class La extends ln{constructor(e,t,i=Ts,n,s,r,a=Qt,l=Qt,c,h=Wr,d=1){if(h!==Wr&&h!==bo)throw new Error("THREE.DepthTexture: format must be either THREE.DepthFormat or THREE.DepthStencilFormat");const u={width:e,height:t,depth:d};super(u,n,s,r,a,l,h,i,c),this.isDepthTexture=!0,this.flipY=!1,this.generateMipmaps=!1,this.compareFunction=null}copy(e){return super.copy(e),this.source=new yg(Object.assign({},e.image)),this.compareFunction=e.compareFunction,this}toJSON(e){const t=super.toJSON(e);return this.compareFunction!==null&&(t.compareFunction=this.compareFunction),t}}class F3 extends La{constructor(e,t=Ts,i=Oo,n,s,r=Qt,a=Qt,l,c=Wr){const h={width:e,height:e,depth:1},d=[h,h,h,h,h,h];super(e,e,t,i,n,s,r,a,l,c),this.image=d,this.isCubeDepthTexture=!0,this.isCubeTexture=!0}get images(){return this.image}set images(e){this.image=e}}class gw extends ln{constructor(e=null){super(),this.sourceTexture=e,this.isExternalTexture=!0}copy(e){return super.copy(e),this.sourceTexture=e.sourceTexture,this}}class cn extends ot{constructor(e=1,t=1,i=1,n=1,s=1,r=1){super(),this.type="BoxGeometry",this.parameters={width:e,height:t,depth:i,widthSegments:n,heightSegments:s,depthSegments:r};const a=this;n=Math.floor(n),s=Math.floor(s),r=Math.floor(r);const l=[],c=[],h=[],d=[];let u=0,f=0;p("z","y","x",-1,-1,i,t,e,r,s,0),p("z","y","x",1,-1,i,t,-e,r,s,1),p("x","z","y",1,1,e,i,t,n,r,2),p("x","z","y",1,-1,e,i,-t,n,r,3),p("x","y","z",1,-1,e,t,i,n,s,4),p("x","y","z",-1,-1,e,t,-i,n,s,5),this.setIndex(l),this.setAttribute("position",new yt(c,3)),this.setAttribute("normal",new yt(h,3)),this.setAttribute("uv",new yt(d,2));function p(g,m,v,b,x,y,w,S,A,M,_){const I=y/A,R=w/M,L=y/2,P=w/2,O=S/2,k=A+1,F=M+1;let z=0,V=0;const K=new D;for(let q=0;q<F;q++){const te=q*R-P;for(let re=0;re<k;re++){const Ge=re*I-L;K[g]=Ge*b,K[m]=te*x,K[v]=O,c.push(K.x,K.y,K.z),K[g]=0,K[m]=0,K[v]=S>0?1:-1,h.push(K.x,K.y,K.z),d.push(re/A),d.push(1-q/M),z+=1}}for(let q=0;q<M;q++)for(let te=0;te<A;te++){const re=u+te+k*q,Ge=u+te+k*(q+1),ft=u+(te+1)+k*(q+1),it=u+(te+1)+k*q;l.push(re,Ge,it),l.push(Ge,ft,it),V+=6}a.addGroup(f,V,_),f+=V,u+=z}}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new cn(e.width,e.height,e.depth,e.widthSegments,e.heightSegments,e.depthSegments)}}class Sg extends ot{constructor(e=1,t=32,i=0,n=Math.PI*2){super(),this.type="CircleGeometry",this.parameters={radius:e,segments:t,thetaStart:i,thetaLength:n},t=Math.max(3,t);const s=[],r=[],a=[],l=[],c=new D,h=new we;r.push(0,0,0),a.push(0,0,1),l.push(.5,.5);for(let d=0,u=3;d<=t;d++,u+=3){const f=i+d/t*n;c.x=e*Math.cos(f),c.y=e*Math.sin(f),r.push(c.x,c.y,c.z),a.push(0,0,1),h.x=(r[u]/e+1)/2,h.y=(r[u+1]/e+1)/2,l.push(h.x,h.y)}for(let d=1;d<=t;d++)s.push(d,d+1,0);this.setIndex(s),this.setAttribute("position",new yt(r,3)),this.setAttribute("normal",new yt(a,3)),this.setAttribute("uv",new yt(l,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new Sg(e.radius,e.segments,e.thetaStart,e.thetaLength)}}class ms extends ot{constructor(e=1,t=1,i=1,n=32,s=1,r=!1,a=0,l=Math.PI*2){super(),this.type="CylinderGeometry",this.parameters={radiusTop:e,radiusBottom:t,height:i,radialSegments:n,heightSegments:s,openEnded:r,thetaStart:a,thetaLength:l};const c=this;n=Math.floor(n),s=Math.floor(s);const h=[],d=[],u=[],f=[];let p=0;const g=[],m=i/2;let v=0;b(),r===!1&&(e>0&&x(!0),t>0&&x(!1)),this.setIndex(h),this.setAttribute("position",new yt(d,3)),this.setAttribute("normal",new yt(u,3)),this.setAttribute("uv",new yt(f,2));function b(){const y=new D,w=new D;let S=0;const A=(t-e)/i;for(let M=0;M<=s;M++){const _=[],I=M/s,R=I*(t-e)+e;for(let L=0;L<=n;L++){const P=L/n,O=P*l+a,k=Math.sin(O),F=Math.cos(O);w.x=R*k,w.y=-I*i+m,w.z=R*F,d.push(w.x,w.y,w.z),y.set(k,A,F).normalize(),u.push(y.x,y.y,y.z),f.push(P,1-I),_.push(p++)}g.push(_)}for(let M=0;M<n;M++)for(let _=0;_<s;_++){const I=g[_][M],R=g[_+1][M],L=g[_+1][M+1],P=g[_][M+1];(e>0||_!==0)&&(h.push(I,R,P),S+=3),(t>0||_!==s-1)&&(h.push(R,L,P),S+=3)}c.addGroup(v,S,0),v+=S}function x(y){const w=p,S=new we,A=new D;let M=0;const _=y===!0?e:t,I=y===!0?1:-1;for(let L=1;L<=n;L++)d.push(0,m*I,0),u.push(0,I,0),f.push(.5,.5),p++;const R=p;for(let L=0;L<=n;L++){const O=L/n*l+a,k=Math.cos(O),F=Math.sin(O);A.x=_*F,A.y=m*I,A.z=_*k,d.push(A.x,A.y,A.z),u.push(0,I,0),S.x=k*.5+.5,S.y=F*.5*I+.5,f.push(S.x,S.y),p++}for(let L=0;L<n;L++){const P=w+L,O=R+L;y===!0?h.push(O,O+1,P):h.push(O+1,O,P),M+=3}c.addGroup(v,M,y===!0?1:2),v+=M}}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new ms(e.radiusTop,e.radiusBottom,e.height,e.radialSegments,e.heightSegments,e.openEnded,e.thetaStart,e.thetaLength)}}class uc extends ms{constructor(e=1,t=1,i=32,n=1,s=!1,r=0,a=Math.PI*2){super(0,e,t,i,n,s,r,a),this.type="ConeGeometry",this.parameters={radius:e,height:t,radialSegments:i,heightSegments:n,openEnded:s,thetaStart:r,thetaLength:a}}static fromJSON(e){return new uc(e.radius,e.height,e.radialSegments,e.heightSegments,e.openEnded,e.thetaStart,e.thetaLength)}}class Ef extends ot{constructor(e=[new we(0,-.5),new we(.5,0),new we(0,.5)],t=12,i=0,n=Math.PI*2){super(),this.type="LatheGeometry",this.parameters={points:e,segments:t,phiStart:i,phiLength:n},t=Math.floor(t),n=nt(n,0,Math.PI*2);const s=[],r=[],a=[],l=[],c=[],h=1/t,d=new D,u=new we,f=new D,p=new D,g=new D;let m=0,v=0;for(let b=0;b<=e.length-1;b++)switch(b){case 0:m=e[b+1].x-e[b].x,v=e[b+1].y-e[b].y,f.x=v*1,f.y=-m,f.z=v*0,g.copy(f),f.normalize(),l.push(f.x,f.y,f.z);break;case e.length-1:l.push(g.x,g.y,g.z);break;default:m=e[b+1].x-e[b].x,v=e[b+1].y-e[b].y,f.x=v*1,f.y=-m,f.z=v*0,p.copy(f),f.x+=g.x,f.y+=g.y,f.z+=g.z,f.normalize(),l.push(f.x,f.y,f.z),g.copy(p)}for(let b=0;b<=t;b++){const x=i+b*h*n,y=Math.sin(x),w=Math.cos(x);for(let S=0;S<=e.length-1;S++){d.x=e[S].x*y,d.y=e[S].y,d.z=e[S].x*w,r.push(d.x,d.y,d.z),u.x=b/t,u.y=S/(e.length-1),a.push(u.x,u.y);const A=l[3*S+0]*y,M=l[3*S+1],_=l[3*S+0]*w;c.push(A,M,_)}}for(let b=0;b<t;b++)for(let x=0;x<e.length-1;x++){const y=x+b*e.length,w=y,S=y+e.length,A=y+e.length+1,M=y+1;s.push(w,S,M),s.push(A,M,S)}this.setIndex(s),this.setAttribute("position",new yt(r,3)),this.setAttribute("uv",new yt(a,2)),this.setAttribute("normal",new yt(c,3))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new Ef(e.points,e.segments,e.phiStart,e.phiLength)}}class Gn extends ot{constructor(e=1,t=1,i=1,n=1){super(),this.type="PlaneGeometry",this.parameters={width:e,height:t,widthSegments:i,heightSegments:n};const s=e/2,r=t/2,a=Math.floor(i),l=Math.floor(n),c=a+1,h=l+1,d=e/a,u=t/l,f=[],p=[],g=[],m=[];for(let v=0;v<h;v++){const b=v*u-r;for(let x=0;x<c;x++){const y=x*d-s;p.push(y,-b,0),g.push(0,0,1),m.push(x/a),m.push(1-v/l)}}for(let v=0;v<l;v++)for(let b=0;b<a;b++){const x=b+c*v,y=b+c*(v+1),w=b+1+c*(v+1),S=b+1+c*v;f.push(x,y,S),f.push(y,w,S)}this.setIndex(f),this.setAttribute("position",new yt(p,3)),this.setAttribute("normal",new yt(g,3)),this.setAttribute("uv",new yt(m,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new Gn(e.width,e.height,e.widthSegments,e.heightSegments)}}class Ii extends ot{constructor(e=1,t=32,i=16,n=0,s=Math.PI*2,r=0,a=Math.PI){super(),this.type="SphereGeometry",this.parameters={radius:e,widthSegments:t,heightSegments:i,phiStart:n,phiLength:s,thetaStart:r,thetaLength:a},t=Math.max(3,Math.floor(t)),i=Math.max(2,Math.floor(i));const l=Math.min(r+a,Math.PI);let c=0;const h=[],d=new D,u=new D,f=[],p=[],g=[],m=[];for(let v=0;v<=i;v++){const b=[],x=v/i,y=r+x*a,w=e*Math.cos(y),S=Math.sqrt(e*e-w*w);let A=0;v===0&&r===0?A=.5/t:v===i&&l===Math.PI&&(A=-.5/t);for(let M=0;M<=t;M++){const _=M/t,I=n+_*s;d.x=-S*Math.cos(I),d.y=w,d.z=S*Math.sin(I),p.push(d.x,d.y,d.z),u.copy(d).normalize(),g.push(u.x,u.y,u.z),m.push(_+A,1-x),b.push(c++)}h.push(b)}for(let v=0;v<i;v++)for(let b=0;b<t;b++){const x=h[v][b+1],y=h[v][b],w=h[v+1][b],S=h[v+1][b+1];(v!==0||r>0)&&f.push(x,y,S),(v!==i-1||l<Math.PI)&&f.push(y,w,S)}this.setIndex(f),this.setAttribute("position",new yt(p,3)),this.setAttribute("normal",new yt(g,3)),this.setAttribute("uv",new yt(m,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new Ii(e.radius,e.widthSegments,e.heightSegments,e.phiStart,e.phiLength,e.thetaStart,e.thetaLength)}}class Eg extends ot{constructor(e=1,t=.4,i=12,n=48,s=Math.PI*2,r=0,a=Math.PI*2){super(),this.type="TorusGeometry",this.parameters={radius:e,tube:t,radialSegments:i,tubularSegments:n,arc:s,thetaStart:r,thetaLength:a},i=Math.floor(i),n=Math.floor(n);const l=[],c=[],h=[],d=[],u=new D,f=new D,p=new D;for(let g=0;g<=i;g++){const m=r+g/i*a;for(let v=0;v<=n;v++){const b=v/n*s;f.x=(e+t*Math.cos(m))*Math.cos(b),f.y=(e+t*Math.cos(m))*Math.sin(b),f.z=t*Math.sin(m),c.push(f.x,f.y,f.z),u.x=e*Math.cos(b),u.y=e*Math.sin(b),p.subVectors(f,u).normalize(),h.push(p.x,p.y,p.z),d.push(v/n),d.push(g/i)}}for(let g=1;g<=i;g++)for(let m=1;m<=n;m++){const v=(n+1)*g+m-1,b=(n+1)*(g-1)+m-1,x=(n+1)*(g-1)+m,y=(n+1)*g+m;l.push(v,b,y),l.push(b,x,y)}this.setIndex(l),this.setAttribute("position",new yt(c,3)),this.setAttribute("normal",new yt(h,3)),this.setAttribute("uv",new yt(d,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new Eg(e.radius,e.tube,e.radialSegments,e.tubularSegments,e.arc)}}class Yk extends ot{constructor(e=null){if(super(),this.type="WireframeGeometry",this.parameters={geometry:e},e!==null){const t=[],i=new Set,n=new D,s=new D;if(e.index!==null){const r=e.attributes.position,a=e.index;let l=e.groups;l.length===0&&(l=[{start:0,count:a.count,materialIndex:0}]);for(let c=0,h=l.length;c<h;++c){const d=l[c],u=d.start,f=d.count;for(let p=u,g=u+f;p<g;p+=3)for(let m=0;m<3;m++){const v=a.getX(p+m),b=a.getX(p+(m+1)%3);n.fromBufferAttribute(r,v),s.fromBufferAttribute(r,b),F1(n,s,i)===!0&&(t.push(n.x,n.y,n.z),t.push(s.x,s.y,s.z))}}}else{const r=e.attributes.position;for(let a=0,l=r.count/3;a<l;a++)for(let c=0;c<3;c++){const h=3*a+c,d=3*a+(c+1)%3;n.fromBufferAttribute(r,h),s.fromBufferAttribute(r,d),F1(n,s,i)===!0&&(t.push(n.x,n.y,n.z),t.push(s.x,s.y,s.z))}}this.setAttribute("position",new yt(t,3))}}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}}function F1(o,e,t){const i=`${o.x},${o.y},${o.z}-${e.x},${e.y},${e.z}`,n=`${e.x},${e.y},${e.z}-${o.x},${o.y},${o.z}`;return t.has(i)===!0||t.has(n)===!0?!1:(t.add(i),t.add(n),!0)}function lc(o){const e={};for(const t in o){e[t]={};for(const i in o[t]){const n=o[t][i];if(U1(n))n.isRenderTargetTexture?(ke("UniformsUtils: Textures of render targets cannot be cloned via cloneUniforms() or mergeUniforms()."),e[t][i]=null):e[t][i]=n.clone();else if(Array.isArray(n))if(U1(n[0])){const s=[];for(let r=0,a=n.length;r<a;r++)s[r]=n[r].clone();e[t][i]=s}else e[t][i]=n.slice();else e[t][i]=n}}return e}function Tn(o){const e={};for(let t=0;t<o.length;t++){const i=lc(o[t]);for(const n in i)e[n]=i[n]}return e}function U1(o){return o&&(o.isColor||o.isMatrix3||o.isMatrix4||o.isVector2||o.isVector3||o.isVector4||o.isTexture||o.isQuaternion)}function U3(o){const e=[];for(let t=0;t<o.length;t++)e.push(o[t].clone());return e}function vw(o){const e=o.getRenderTarget();return e===null?o.outputColorSpace:e.isXRRenderTarget===!0?e.texture.colorSpace:Tt.workingColorSpace}const B3={clone:lc,merge:Tn};var z3=`void main() {
3160
3160
  gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
3161
3161
  }`,H3=`void main() {
3162
3162
  gl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );
3163
- }`;class Dt extends Ar{constructor(e){super(),this.isShaderMaterial=!0,this.type="ShaderMaterial",this.defines={},this.uniforms={},this.uniformsGroups=[],this.vertexShader=z3,this.fragmentShader=H3,this.linewidth=1,this.wireframe=!1,this.wireframeLinewidth=1,this.fog=!1,this.lights=!1,this.clipping=!1,this.forceSinglePass=!0,this.extensions={clipCullDistance:!1,multiDraw:!1},this.defaultAttributeValues={color:[1,1,1],uv:[0,0],uv1:[0,0]},this.index0AttributeName=void 0,this.uniformsNeedUpdate=!1,this.glslVersion=null,e!==void 0&&this.setValues(e)}copy(e){return super.copy(e),this.fragmentShader=e.fragmentShader,this.vertexShader=e.vertexShader,this.uniforms=lc(e.uniforms),this.uniformsGroups=U3(e.uniformsGroups),this.defines=Object.assign({},e.defines),this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.fog=e.fog,this.lights=e.lights,this.clipping=e.clipping,this.extensions=Object.assign({},e.extensions),this.glslVersion=e.glslVersion,this.defaultAttributeValues=Object.assign({},e.defaultAttributeValues),this.index0AttributeName=e.index0AttributeName,this.uniformsNeedUpdate=e.uniformsNeedUpdate,this}toJSON(e){const t=super.toJSON(e);t.glslVersion=this.glslVersion,t.uniforms={};for(const n in this.uniforms){const r=this.uniforms[n].value;r&&r.isTexture?t.uniforms[n]={type:"t",value:r.toJSON(e).uuid}:r&&r.isColor?t.uniforms[n]={type:"c",value:r.getHex()}:r&&r.isVector2?t.uniforms[n]={type:"v2",value:r.toArray()}:r&&r.isVector3?t.uniforms[n]={type:"v3",value:r.toArray()}:r&&r.isVector4?t.uniforms[n]={type:"v4",value:r.toArray()}:r&&r.isMatrix3?t.uniforms[n]={type:"m3",value:r.toArray()}:r&&r.isMatrix4?t.uniforms[n]={type:"m4",value:r.toArray()}:t.uniforms[n]={value:r}}Object.keys(this.defines).length>0&&(t.defines=this.defines),t.vertexShader=this.vertexShader,t.fragmentShader=this.fragmentShader,t.lights=this.lights,t.clipping=this.clipping;const i={};for(const n in this.extensions)this.extensions[n]===!0&&(i[n]=!0);return Object.keys(i).length>0&&(t.extensions=i),t}fromJSON(e,t){if(super.fromJSON(e,t),e.uniforms!==void 0)for(const i in e.uniforms){const n=e.uniforms[i];switch(this.uniforms[i]={},n.type){case"t":this.uniforms[i].value=t[n.value]||null;break;case"c":this.uniforms[i].value=new ne().setHex(n.value);break;case"v2":this.uniforms[i].value=new we().fromArray(n.value);break;case"v3":this.uniforms[i].value=new D().fromArray(n.value);break;case"v4":this.uniforms[i].value=new wt().fromArray(n.value);break;case"m3":this.uniforms[i].value=new je().fromArray(n.value);break;case"m4":this.uniforms[i].value=new lt().fromArray(n.value);break;default:this.uniforms[i].value=n.value}}if(e.defines!==void 0&&(this.defines=e.defines),e.vertexShader!==void 0&&(this.vertexShader=e.vertexShader),e.fragmentShader!==void 0&&(this.fragmentShader=e.fragmentShader),e.glslVersion!==void 0&&(this.glslVersion=e.glslVersion),e.extensions!==void 0)for(const i in e.extensions)this.extensions[i]=e.extensions[i];return e.lights!==void 0&&(this.lights=e.lights),e.clipping!==void 0&&(this.clipping=e.clipping),this}}class yw extends Dt{constructor(e){super(e),this.isRawShaderMaterial=!0,this.type="RawShaderMaterial"}}class Ma extends Ar{constructor(e){super(),this.isMeshStandardMaterial=!0,this.type="MeshStandardMaterial",this.defines={STANDARD:""},this.color=new ne(16777215),this.roughness=1,this.metalness=0,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new ne(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=Hu,this.normalScale=new we(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.roughnessMap=null,this.metalnessMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new wr,this.envMapIntensity=1,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.defines={STANDARD:""},this.color.copy(e.color),this.roughness=e.roughness,this.metalness=e.metalness,this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.emissive.copy(e.emissive),this.emissiveMap=e.emissiveMap,this.emissiveIntensity=e.emissiveIntensity,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.roughnessMap=e.roughnessMap,this.metalnessMap=e.metalnessMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.envMapIntensity=e.envMapIntensity,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.flatShading=e.flatShading,this.fog=e.fog,this}}class G3 extends Ma{constructor(e){super(),this.isMeshPhysicalMaterial=!0,this.defines={STANDARD:"",PHYSICAL:""},this.type="MeshPhysicalMaterial",this.anisotropyRotation=0,this.anisotropyMap=null,this.clearcoatMap=null,this.clearcoatRoughness=0,this.clearcoatRoughnessMap=null,this.clearcoatNormalScale=new we(1,1),this.clearcoatNormalMap=null,this.ior=1.5,Object.defineProperty(this,"reflectivity",{get:function(){return nt(2.5*(this.ior-1)/(this.ior+1),0,1)},set:function(t){this.ior=(1+.4*t)/(1-.4*t)}}),this.iridescenceMap=null,this.iridescenceIOR=1.3,this.iridescenceThicknessRange=[100,400],this.iridescenceThicknessMap=null,this.sheenColor=new ne(0),this.sheenColorMap=null,this.sheenRoughness=1,this.sheenRoughnessMap=null,this.transmissionMap=null,this.thickness=0,this.thicknessMap=null,this.attenuationDistance=1/0,this.attenuationColor=new ne(1,1,1),this.specularIntensity=1,this.specularIntensityMap=null,this.specularColor=new ne(1,1,1),this.specularColorMap=null,this._anisotropy=0,this._clearcoat=0,this._dispersion=0,this._iridescence=0,this._sheen=0,this._transmission=0,this.setValues(e)}get anisotropy(){return this._anisotropy}set anisotropy(e){this._anisotropy>0!=e>0&&this.version++,this._anisotropy=e}get clearcoat(){return this._clearcoat}set clearcoat(e){this._clearcoat>0!=e>0&&this.version++,this._clearcoat=e}get iridescence(){return this._iridescence}set iridescence(e){this._iridescence>0!=e>0&&this.version++,this._iridescence=e}get dispersion(){return this._dispersion}set dispersion(e){this._dispersion>0!=e>0&&this.version++,this._dispersion=e}get sheen(){return this._sheen}set sheen(e){this._sheen>0!=e>0&&this.version++,this._sheen=e}get transmission(){return this._transmission}set transmission(e){this._transmission>0!=e>0&&this.version++,this._transmission=e}copy(e){return super.copy(e),this.defines={STANDARD:"",PHYSICAL:""},this.anisotropy=e.anisotropy,this.anisotropyRotation=e.anisotropyRotation,this.anisotropyMap=e.anisotropyMap,this.clearcoat=e.clearcoat,this.clearcoatMap=e.clearcoatMap,this.clearcoatRoughness=e.clearcoatRoughness,this.clearcoatRoughnessMap=e.clearcoatRoughnessMap,this.clearcoatNormalMap=e.clearcoatNormalMap,this.clearcoatNormalScale.copy(e.clearcoatNormalScale),this.dispersion=e.dispersion,this.ior=e.ior,this.iridescence=e.iridescence,this.iridescenceMap=e.iridescenceMap,this.iridescenceIOR=e.iridescenceIOR,this.iridescenceThicknessRange=[...e.iridescenceThicknessRange],this.iridescenceThicknessMap=e.iridescenceThicknessMap,this.sheen=e.sheen,this.sheenColor.copy(e.sheenColor),this.sheenColorMap=e.sheenColorMap,this.sheenRoughness=e.sheenRoughness,this.sheenRoughnessMap=e.sheenRoughnessMap,this.transmission=e.transmission,this.transmissionMap=e.transmissionMap,this.thickness=e.thickness,this.thicknessMap=e.thicknessMap,this.attenuationDistance=e.attenuationDistance,this.attenuationColor.copy(e.attenuationColor),this.specularIntensity=e.specularIntensity,this.specularIntensityMap=e.specularIntensityMap,this.specularColor.copy(e.specularColor),this.specularColorMap=e.specularColorMap,this}}class Oa extends Ar{constructor(e){super(),this.isMeshLambertMaterial=!0,this.type="MeshLambertMaterial",this.color=new ne(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new ne(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=Hu,this.normalScale=new we(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new wr,this.combine=og,this.reflectivity=1,this.envMapIntensity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.emissive.copy(e.emissive),this.emissiveMap=e.emissiveMap,this.emissiveIntensity=e.emissiveIntensity,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.specularMap=e.specularMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.combine=e.combine,this.reflectivity=e.reflectivity,this.envMapIntensity=e.envMapIntensity,this.refractionRatio=e.refractionRatio,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.flatShading=e.flatShading,this.fog=e.fog,this}}class V3 extends Ar{constructor(e){super(),this.isMeshDepthMaterial=!0,this.type="MeshDepthMaterial",this.depthPacking=LE,this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.setValues(e)}copy(e){return super.copy(e),this.depthPacking=e.depthPacking,this.map=e.map,this.alphaMap=e.alphaMap,this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this}}class W3 extends Ar{constructor(e){super(),this.isMeshDistanceMaterial=!0,this.type="MeshDistanceMaterial",this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.setValues(e)}copy(e){return super.copy(e),this.map=e.map,this.alphaMap=e.alphaMap,this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this}}function yd(o,e){return!o||o.constructor===e?o:typeof e.BYTES_PER_ELEMENT=="number"?new e(o):Array.prototype.slice.call(o)}function X3(o){function e(n,s){return o[n]-o[s]}const t=o.length,i=new Array(t);for(let n=0;n!==t;++n)i[n]=n;return i.sort(e),i}function B1(o,e,t){const i=o.length,n=new o.constructor(i);for(let s=0,r=0;r!==i;++s){const a=t[s]*e;for(let l=0;l!==e;++l)n[r++]=o[a+l]}return n}function $3(o,e,t,i){let n=1,s=o[0];for(;s!==void 0&&s[i]===void 0;)s=o[n++];if(s===void 0)return;let r=s[i];if(r!==void 0)if(Array.isArray(r))do r=s[i],r!==void 0&&(e.push(s.time),t.push(...r)),s=o[n++];while(s!==void 0);else if(r.toArray!==void 0)do r=s[i],r!==void 0&&(e.push(s.time),r.toArray(t,t.length)),s=o[n++];while(s!==void 0);else do r=s[i],r!==void 0&&(e.push(s.time),t.push(r)),s=o[n++];while(s!==void 0)}class kh{constructor(e,t,i,n){this.parameterPositions=e,this._cachedIndex=0,this.resultBuffer=n!==void 0?n:new t.constructor(i),this.sampleValues=t,this.valueSize=i,this.settings=null,this.DefaultSettings_={}}evaluate(e){const t=this.parameterPositions;let i=this._cachedIndex,n=t[i],s=t[i-1];e:{t:{let r;i:{n:if(!(e<n)){for(let a=i+2;;){if(n===void 0){if(e<s)break n;return i=t.length,this._cachedIndex=i,this.copySampleValue_(i-1)}if(i===a)break;if(s=n,n=t[++i],e<n)break t}r=t.length;break i}if(!(e>=s)){const a=t[1];e<a&&(i=2,s=a);for(let l=i-2;;){if(s===void 0)return this._cachedIndex=0,this.copySampleValue_(0);if(i===l)break;if(n=s,s=t[--i-1],e>=s)break t}r=i,i=0;break i}break e}for(;i<r;){const a=i+r>>>1;e<t[a]?r=a:i=a+1}if(n=t[i],s=t[i-1],s===void 0)return this._cachedIndex=0,this.copySampleValue_(0);if(n===void 0)return i=t.length,this._cachedIndex=i,this.copySampleValue_(i-1)}this._cachedIndex=i,this.intervalChanged_(i,s,n)}return this.interpolate_(i,s,e,n)}getSettings_(){return this.settings||this.DefaultSettings_}copySampleValue_(e){const t=this.resultBuffer,i=this.sampleValues,n=this.valueSize,s=e*n;for(let r=0;r!==n;++r)t[r]=i[s+r];return t}interpolate_(){throw new Error("THREE.Interpolant: Call to abstract method.")}intervalChanged_(){}}class Y3 extends kh{constructor(e,t,i,n){super(e,t,i,n),this._weightPrev=-0,this._offsetPrev=-0,this._weightNext=-0,this._offsetNext=-0,this.DefaultSettings_={endingStart:Tl,endingEnd:Tl}}intervalChanged_(e,t,i){const n=this.parameterPositions;let s=e-2,r=e+1,a=n[s],l=n[r];if(a===void 0)switch(this.getSettings_().endingStart){case Il:s=e,a=2*t-i;break;case zu:s=n.length-2,a=t+n[s]-n[s+1];break;default:s=e,a=i}if(l===void 0)switch(this.getSettings_().endingEnd){case Il:r=e,l=2*i-t;break;case zu:r=1,l=i+n[1]-n[0];break;default:r=e-1,l=t}const c=(i-t)*.5,h=this.valueSize;this._weightPrev=c/(t-a),this._weightNext=c/(l-i),this._offsetPrev=s*h,this._offsetNext=r*h}interpolate_(e,t,i,n){const s=this.resultBuffer,r=this.sampleValues,a=this.valueSize,l=e*a,c=l-a,h=this._offsetPrev,d=this._offsetNext,u=this._weightPrev,f=this._weightNext,p=(i-t)/(n-t),g=p*p,m=g*p,v=-u*m+2*u*g-u*p,b=(1+u)*m+(-1.5-2*u)*g+(-.5+u)*p+1,x=(-1-f)*m+(1.5+f)*g+.5*p,y=f*m-f*g;for(let w=0;w!==a;++w)s[w]=v*r[h+w]+b*r[c+w]+x*r[l+w]+y*r[d+w];return s}}class bw extends kh{constructor(e,t,i,n){super(e,t,i,n)}interpolate_(e,t,i,n){const s=this.resultBuffer,r=this.sampleValues,a=this.valueSize,l=e*a,c=l-a,h=(i-t)/(n-t),d=1-h;for(let u=0;u!==a;++u)s[u]=r[c+u]*d+r[l+u]*h;return s}}class q3 extends kh{constructor(e,t,i,n){super(e,t,i,n)}interpolate_(e){return this.copySampleValue_(e-1)}}class K3 extends kh{interpolate_(e,t,i,n){const s=this.resultBuffer,r=this.sampleValues,a=this.valueSize,l=e*a,c=l-a,h=this.inTangents,d=this.outTangents;if(!h||!d){const p=(i-t)/(n-t),g=1-p;for(let m=0;m!==a;++m)s[m]=r[c+m]*g+r[l+m]*p;return s}const u=a*2,f=e-1;for(let p=0;p!==a;++p){const g=r[c+p],m=r[l+p],v=f*u+p*2,b=d[v],x=d[v+1],y=e*u+p*2,w=h[y],S=h[y+1];let A=(i-t)/(n-t),M,_,I,R,L;for(let P=0;P<8;P++){M=A*A,_=M*A,I=1-A,R=I*I,L=R*I;const k=L*t+3*R*A*b+3*I*M*w+_*n-i;if(Math.abs(k)<1e-10)break;const F=3*R*(b-t)+6*I*A*(w-b)+3*M*(n-w);if(Math.abs(F)<1e-10)break;A=A-k/F,A=Math.max(0,Math.min(1,A))}s[p]=L*g+3*R*A*x+3*I*M*S+_*m}return s}}class Ys{constructor(e,t,i,n){if(e===void 0)throw new Error("THREE.KeyframeTrack: track name is undefined");if(t===void 0||t.length===0)throw new Error("THREE.KeyframeTrack: no keyframes in track named "+e);this.name=e,this.times=yd(t,this.TimeBufferType),this.values=yd(i,this.ValueBufferType),this.setInterpolation(n||this.DefaultInterpolation)}static toJSON(e){const t=e.constructor;let i;if(t.toJSON!==this.toJSON)i=t.toJSON(e);else{i={name:e.name,times:yd(e.times,Array),values:yd(e.values,Array)};const n=e.getInterpolation();n!==e.DefaultInterpolation&&(i.interpolation=n)}return i.type=e.ValueTypeName,i}InterpolantFactoryMethodDiscrete(e){return new q3(this.times,this.values,this.getValueSize(),e)}InterpolantFactoryMethodLinear(e){return new bw(this.times,this.values,this.getValueSize(),e)}InterpolantFactoryMethodSmooth(e){return new Y3(this.times,this.values,this.getValueSize(),e)}InterpolantFactoryMethodBezier(e){const t=new K3(this.times,this.values,this.getValueSize(),e);return this.settings&&(t.inTangents=this.settings.inTangents,t.outTangents=this.settings.outTangents),t}setInterpolation(e){let t;switch(e){case Bu:t=this.InterpolantFactoryMethodDiscrete;break;case hm:t=this.InterpolantFactoryMethodLinear;break;case $f:t=this.InterpolantFactoryMethodSmooth;break;case n1:t=this.InterpolantFactoryMethodBezier;break}if(t===void 0){const i="unsupported interpolation for "+this.ValueTypeName+" keyframe track named "+this.name;if(this.createInterpolant===void 0)if(e!==this.DefaultInterpolation)this.setInterpolation(this.DefaultInterpolation);else throw new Error(i);return ke("KeyframeTrack:",i),this}return this.createInterpolant=t,this}getInterpolation(){switch(this.createInterpolant){case this.InterpolantFactoryMethodDiscrete:return Bu;case this.InterpolantFactoryMethodLinear:return hm;case this.InterpolantFactoryMethodSmooth:return $f;case this.InterpolantFactoryMethodBezier:return n1}}getValueSize(){return this.values.length/this.times.length}shift(e){if(e!==0){const t=this.times;for(let i=0,n=t.length;i!==n;++i)t[i]+=e}return this}scale(e){if(e!==1){const t=this.times;for(let i=0,n=t.length;i!==n;++i)t[i]*=e}return this}trim(e,t){const i=this.times,n=i.length;let s=0,r=n-1;for(;s!==n&&i[s]<e;)++s;for(;r!==-1&&i[r]>t;)--r;if(++r,s!==0||r!==n){s>=r&&(r=Math.max(r,1),s=r-1);const a=this.getValueSize();this.times=i.slice(s,r),this.values=this.values.slice(s*a,r*a)}return this}validate(){let e=!0;const t=this.getValueSize();t-Math.floor(t)!==0&&(Ze("KeyframeTrack: Invalid value size in track.",this),e=!1);const i=this.times,n=this.values,s=i.length;s===0&&(Ze("KeyframeTrack: Track is empty.",this),e=!1);let r=null;for(let a=0;a!==s;a++){const l=i[a];if(typeof l=="number"&&isNaN(l)){Ze("KeyframeTrack: Time is not a valid number.",this,a,l),e=!1;break}if(r!==null&&r>l){Ze("KeyframeTrack: Out of order keys.",this,a,l,r),e=!1;break}r=l}if(n!==void 0&&VE(n))for(let a=0,l=n.length;a!==l;++a){const c=n[a];if(isNaN(c)){Ze("KeyframeTrack: Value is not a valid number.",this,a,c),e=!1;break}}return e}optimize(){const e=this.times.slice(),t=this.values.slice(),i=this.getValueSize(),n=this.getInterpolation()===$f,s=e.length-1;let r=1;for(let a=1;a<s;++a){let l=!1;const c=e[a],h=e[a+1];if(c!==h&&(a!==1||c!==e[0]))if(n)l=!0;else{const d=a*i,u=d-i,f=d+i;for(let p=0;p!==i;++p){const g=t[d+p];if(g!==t[u+p]||g!==t[f+p]){l=!0;break}}}if(l){if(a!==r){e[r]=e[a];const d=a*i,u=r*i;for(let f=0;f!==i;++f)t[u+f]=t[d+f]}++r}}if(s>0){e[r]=e[s];for(let a=s*i,l=r*i,c=0;c!==i;++c)t[l+c]=t[a+c];++r}return r!==e.length?(this.times=e.slice(0,r),this.values=t.slice(0,r*i)):(this.times=e,this.values=t),this}clone(){const e=this.times.slice(),t=this.values.slice(),i=this.constructor,n=new i(this.name,e,t);return n.createInterpolant=this.createInterpolant,n}}Ys.prototype.ValueTypeName="";Ys.prototype.TimeBufferType=Float32Array;Ys.prototype.ValueBufferType=Float32Array;Ys.prototype.DefaultInterpolation=hm;class fc extends Ys{constructor(e,t,i){super(e,t,i)}}fc.prototype.ValueTypeName="bool";fc.prototype.ValueBufferType=Array;fc.prototype.DefaultInterpolation=Bu;fc.prototype.InterpolantFactoryMethodLinear=void 0;fc.prototype.InterpolantFactoryMethodSmooth=void 0;class Mw extends Ys{constructor(e,t,i,n){super(e,t,i,n)}}Mw.prototype.ValueTypeName="color";class Ag extends Ys{constructor(e,t,i,n){super(e,t,i,n)}}Ag.prototype.ValueTypeName="number";class Z3 extends kh{constructor(e,t,i,n){super(e,t,i,n)}interpolate_(e,t,i,n){const s=this.resultBuffer,r=this.sampleValues,a=this.valueSize,l=(i-t)/(n-t);let c=e*a;for(let h=c+a;c!==h;c+=4)An.slerpFlat(s,0,r,c-a,r,c,l);return s}}class _g extends Ys{constructor(e,t,i,n){super(e,t,i,n)}InterpolantFactoryMethodLinear(e){return new Z3(this.times,this.values,this.getValueSize(),e)}}_g.prototype.ValueTypeName="quaternion";_g.prototype.InterpolantFactoryMethodSmooth=void 0;class pc extends Ys{constructor(e,t,i){super(e,t,i)}}pc.prototype.ValueTypeName="string";pc.prototype.ValueBufferType=Array;pc.prototype.DefaultInterpolation=Bu;pc.prototype.InterpolantFactoryMethodLinear=void 0;pc.prototype.InterpolantFactoryMethodSmooth=void 0;class ww extends Ys{constructor(e,t,i,n){super(e,t,i,n)}}ww.prototype.ValueTypeName="vector";class z1{constructor(e="",t=-1,i=[],n=pg){this.name=e,this.tracks=i,this.duration=t,this.blendMode=n,this.uuid=Ws(),this.userData={},this.duration<0&&this.resetDuration()}static parse(e){const t=[],i=e.tracks,n=1/(e.fps||1);for(let r=0,a=i.length;r!==a;++r)t.push(J3(i[r]).scale(n));const s=new this(e.name,e.duration,t,e.blendMode);return s.uuid=e.uuid,s.userData=JSON.parse(e.userData||"{}"),s}static toJSON(e){const t=[],i=e.tracks,n={name:e.name,duration:e.duration,tracks:t,uuid:e.uuid,blendMode:e.blendMode,userData:JSON.stringify(e.userData)};for(let s=0,r=i.length;s!==r;++s)t.push(Ys.toJSON(i[s]));return n}static CreateFromMorphTargetSequence(e,t,i,n){const s=t.length,r=[];for(let a=0;a<s;a++){let l=[],c=[];l.push((a+s-1)%s,a,(a+1)%s),c.push(0,1,0);const h=X3(l);l=B1(l,1,h),c=B1(c,1,h),!n&&l[0]===0&&(l.push(s),c.push(c[0])),r.push(new Ag(".morphTargetInfluences["+t[a].name+"]",l,c).scale(1/i))}return new this(e,-1,r)}static findByName(e,t){let i=e;if(!Array.isArray(e)){const n=e;i=n.geometry&&n.geometry.animations||n.animations}for(let n=0;n<i.length;n++)if(i[n].name===t)return i[n];return null}static CreateClipsFromMorphTargetSequences(e,t,i){const n={},s=/^([\w-]*?)([\d]+)$/;for(let a=0,l=e.length;a<l;a++){const c=e[a],h=c.name.match(s);if(h&&h.length>1){const d=h[1];let u=n[d];u||(n[d]=u=[]),u.push(c)}}const r=[];for(const a in n)r.push(this.CreateFromMorphTargetSequence(a,n[a],t,i));return r}resetDuration(){const e=this.tracks;let t=0;for(let i=0,n=e.length;i!==n;++i){const s=this.tracks[i];t=Math.max(t,s.times[s.times.length-1])}return this.duration=t,this}trim(){for(let e=0;e<this.tracks.length;e++)this.tracks[e].trim(0,this.duration);return this}validate(){let e=!0;for(let t=0;t<this.tracks.length;t++)e=e&&this.tracks[t].validate();return e}optimize(){for(let e=0;e<this.tracks.length;e++)this.tracks[e].optimize();return this}clone(){const e=[];for(let i=0;i<this.tracks.length;i++)e.push(this.tracks[i].clone());const t=new this.constructor(this.name,this.duration,e,this.blendMode);return t.userData=JSON.parse(JSON.stringify(this.userData)),t}toJSON(){return this.constructor.toJSON(this)}}function j3(o){switch(o.toLowerCase()){case"scalar":case"double":case"float":case"number":case"integer":return Ag;case"vector":case"vector2":case"vector3":case"vector4":return ww;case"color":return Mw;case"quaternion":return _g;case"bool":case"boolean":return fc;case"string":return pc}throw new Error("THREE.KeyframeTrack: Unsupported typeName: "+o)}function J3(o){if(o.type===void 0)throw new Error("THREE.KeyframeTrack: track type undefined, can not parse");const e=j3(o.type);if(o.times===void 0){const t=[],i=[];$3(o.keys,t,i,"value"),o.times=t,o.values=i}return e.parse!==void 0?e.parse(o):new e(o.name,o.times,o.values,o.interpolation)}const zr={enabled:!1,files:{},add:function(o,e){this.enabled!==!1&&(H1(o)||(this.files[o]=e))},get:function(o){if(this.enabled!==!1&&!H1(o))return this.files[o]},remove:function(o){delete this.files[o]},clear:function(){this.files={}}};function H1(o){try{const e=o.slice(o.indexOf(":")+1);return new URL(e).protocol==="blob:"}catch{return!1}}class Q3{constructor(e,t,i){const n=this;let s=!1,r=0,a=0,l;const c=[];this.onStart=void 0,this.onLoad=e,this.onProgress=t,this.onError=i,this._abortController=null,this.itemStart=function(h){a++,s===!1&&n.onStart!==void 0&&n.onStart(h,r,a),s=!0},this.itemEnd=function(h){r++,n.onProgress!==void 0&&n.onProgress(h,r,a),r===a&&(s=!1,n.onLoad!==void 0&&n.onLoad())},this.itemError=function(h){n.onError!==void 0&&n.onError(h)},this.resolveURL=function(h){return h=h.normalize("NFC"),l?l(h):h},this.setURLModifier=function(h){return l=h,this},this.addHandler=function(h,d){return c.push(h,d),this},this.removeHandler=function(h){const d=c.indexOf(h);return d!==-1&&c.splice(d,2),this},this.getHandler=function(h){for(let d=0,u=c.length;d<u;d+=2){const f=c[d],p=c[d+1];if(f.global&&(f.lastIndex=0),f.test(h))return p}return null},this.abort=function(){return this.abortController.abort(),this._abortController=null,this}}get abortController(){return this._abortController||(this._abortController=new AbortController),this._abortController}}const eA=new Q3;class Ph{constructor(e){this.manager=e!==void 0?e:eA,this.crossOrigin="anonymous",this.withCredentials=!1,this.path="",this.resourcePath="",this.requestHeader={},typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}load(){}loadAsync(e,t){const i=this;return new Promise(function(n,s){i.load(e,n,t,s)})}parse(){}setCrossOrigin(e){return this.crossOrigin=e,this}setWithCredentials(e){return this.withCredentials=e,this}setPath(e){return this.path=e,this}setResourcePath(e){return this.resourcePath=e,this}setRequestHeader(e){return this.requestHeader=e,this}abort(){return this}}Ph.DEFAULT_MATERIAL_NAME="__DEFAULT";const Cr={};class tA extends Error{constructor(e,t){super(e),this.response=t}}class qk extends Ph{constructor(e){super(e),this.mimeType="",this.responseType="",this._abortController=new AbortController}load(e,t,i,n){e===void 0&&(e=""),this.path!==void 0&&(e=this.path+e),e=this.manager.resolveURL(e);const s=zr.get(`file:${e}`);if(s!==void 0){this.manager.itemStart(e),setTimeout(()=>{t&&t(s),this.manager.itemEnd(e)},0);return}if(Cr[e]!==void 0){Cr[e].push({onLoad:t,onProgress:i,onError:n});return}Cr[e]=[],Cr[e].push({onLoad:t,onProgress:i,onError:n});const r=new Request(e,{headers:new Headers(this.requestHeader),credentials:this.withCredentials?"include":"same-origin",signal:typeof AbortSignal.any=="function"?AbortSignal.any([this._abortController.signal,this.manager.abortController.signal]):this._abortController.signal}),a=this.mimeType,l=this.responseType;fetch(r).then(c=>{if(c.status===200||c.status===0){if(c.status===0&&ke("FileLoader: HTTP Status 0 received."),typeof ReadableStream>"u"||c.body===void 0||c.body.getReader===void 0)return c;const h=Cr[e],d=c.body.getReader(),u=c.headers.get("X-File-Size")||c.headers.get("Content-Length"),f=u?parseInt(u):0,p=f!==0;let g=0;const m=new ReadableStream({start(v){b();function b(){d.read().then(({done:x,value:y})=>{if(x)v.close();else{g+=y.byteLength;const w=new ProgressEvent("progress",{lengthComputable:p,loaded:g,total:f});for(let S=0,A=h.length;S<A;S++){const M=h[S];M.onProgress&&M.onProgress(w)}v.enqueue(y),b()}},x=>{v.error(x)})}}});return new Response(m)}else throw new tA(`fetch for "${c.url}" responded with ${c.status}: ${c.statusText}`,c)}).then(c=>{switch(l){case"arraybuffer":return c.arrayBuffer();case"blob":return c.blob();case"document":return c.text().then(h=>new DOMParser().parseFromString(h,a));case"json":return c.json();default:if(a==="")return c.text();{const d=/charset="?([^;"\s]*)"?/i.exec(a),u=d&&d[1]?d[1].toLowerCase():void 0,f=new TextDecoder(u);return c.arrayBuffer().then(p=>f.decode(p))}}}).then(c=>{zr.add(`file:${e}`,c);const h=Cr[e];delete Cr[e];for(let d=0,u=h.length;d<u;d++){const f=h[d];f.onLoad&&f.onLoad(c)}}).catch(c=>{const h=Cr[e];if(h===void 0)throw this.manager.itemError(e),c;delete Cr[e];for(let d=0,u=h.length;d<u;d++){const f=h[d];f.onError&&f.onError(c)}this.manager.itemError(e)}).finally(()=>{this.manager.itemEnd(e)}),this.manager.itemStart(e)}setResponseType(e){return this.responseType=e,this}setMimeType(e){return this.mimeType=e,this}abort(){return this._abortController.abort(),this._abortController=new AbortController,this}}const cl=new WeakMap;class iA extends Ph{constructor(e){super(e)}load(e,t,i,n){this.path!==void 0&&(e=this.path+e),e=this.manager.resolveURL(e);const s=this,r=zr.get(`image:${e}`);if(r!==void 0){if(r.complete===!0)s.manager.itemStart(e),setTimeout(function(){t&&t(r),s.manager.itemEnd(e)},0);else{let d=cl.get(r);d===void 0&&(d=[],cl.set(r,d)),d.push({onLoad:t,onError:n})}return r}const a=Sh("img");function l(){h(),t&&t(this);const d=cl.get(this)||[];for(let u=0;u<d.length;u++){const f=d[u];f.onLoad&&f.onLoad(this)}cl.delete(this),s.manager.itemEnd(e)}function c(d){h(),n&&n(d),zr.remove(`image:${e}`);const u=cl.get(this)||[];for(let f=0;f<u.length;f++){const p=u[f];p.onError&&p.onError(d)}cl.delete(this),s.manager.itemError(e),s.manager.itemEnd(e)}function h(){a.removeEventListener("load",l,!1),a.removeEventListener("error",c,!1)}return a.addEventListener("load",l,!1),a.addEventListener("error",c,!1),e.slice(0,5)!=="data:"&&this.crossOrigin!==void 0&&(a.crossOrigin=this.crossOrigin),zr.add(`image:${e}`,a),s.manager.itemStart(e),a.src=e,a}}class Kk extends Ph{constructor(e){super(e)}load(e,t,i,n){const s=new ln,r=new iA(this.manager);return r.setCrossOrigin(this.crossOrigin),r.setPath(this.path),r.load(e,function(a){s.image=a,s.needsUpdate=!0,t!==void 0&&t(s)},i,n),s}}class Af extends hi{constructor(e,t=1){super(),this.isLight=!0,this.type="Light",this.color=new ne(e),this.intensity=t}dispose(){this.dispatchEvent({type:"dispose"})}copy(e,t){return super.copy(e,t),this.color.copy(e.color),this.intensity=e.intensity,this}toJSON(e){const t=super.toJSON(e);return t.object.color=this.color.getHex(),t.object.intensity=this.intensity,t}}class nA extends Af{constructor(e,t,i){super(e,i),this.isHemisphereLight=!0,this.type="HemisphereLight",this.position.copy(hi.DEFAULT_UP),this.updateMatrix(),this.groundColor=new ne(t)}copy(e,t){return super.copy(e,t),this.groundColor.copy(e.groundColor),this}toJSON(e){const t=super.toJSON(e);return t.object.groundColor=this.groundColor.getHex(),t}}const bp=new lt,G1=new D,V1=new D;class Tg{constructor(e){this.camera=e,this.intensity=1,this.bias=0,this.biasNode=null,this.normalBias=0,this.radius=1,this.blurSamples=8,this.mapSize=new we(512,512),this.mapType=zn,this.map=null,this.mapPass=null,this.matrix=new lt,this.autoUpdate=!0,this.needsUpdate=!1,this._frustum=new xg,this._frameExtents=new we(1,1),this._viewportCount=1,this._viewports=[new wt(0,0,1,1)]}getViewportCount(){return this._viewportCount}getFrustum(){return this._frustum}updateMatrices(e){const t=this.camera,i=this.matrix;G1.setFromMatrixPosition(e.matrixWorld),t.position.copy(G1),V1.setFromMatrixPosition(e.target.matrixWorld),t.lookAt(V1),t.updateMatrixWorld(),bp.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),this._frustum.setFromProjectionMatrix(bp,t.coordinateSystem,t.reversedDepth),t.coordinateSystem===xh||t.reversedDepth?i.set(.5,0,0,.5,0,.5,0,.5,0,0,1,0,0,0,0,1):i.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),i.multiply(bp)}getViewport(e){return this._viewports[e]}getFrameExtents(){return this._frameExtents}dispose(){this.map&&this.map.dispose(),this.mapPass&&this.mapPass.dispose()}copy(e){return this.camera=e.camera.clone(),this.intensity=e.intensity,this.bias=e.bias,this.radius=e.radius,this.autoUpdate=e.autoUpdate,this.needsUpdate=e.needsUpdate,this.normalBias=e.normalBias,this.blurSamples=e.blurSamples,this.mapSize.copy(e.mapSize),this.biasNode=e.biasNode,this}clone(){return new this.constructor().copy(this)}toJSON(){const e={};return this.intensity!==1&&(e.intensity=this.intensity),this.bias!==0&&(e.bias=this.bias),this.normalBias!==0&&(e.normalBias=this.normalBias),this.radius!==1&&(e.radius=this.radius),(this.mapSize.x!==512||this.mapSize.y!==512)&&(e.mapSize=this.mapSize.toArray()),e.camera=this.camera.toJSON(!1).object,delete e.camera.matrix,e}}const bd=new D,Md=new An,Js=new D;class xw extends hi{constructor(){super(),this.isCamera=!0,this.type="Camera",this.matrixWorldInverse=new lt,this.projectionMatrix=new lt,this.projectionMatrixInverse=new lt,this.coordinateSystem=vr,this._reversedDepth=!1}get reversedDepth(){return this._reversedDepth}copy(e,t){return super.copy(e,t),this.matrixWorldInverse.copy(e.matrixWorldInverse),this.projectionMatrix.copy(e.projectionMatrix),this.projectionMatrixInverse.copy(e.projectionMatrixInverse),this.coordinateSystem=e.coordinateSystem,this}getWorldDirection(e){return super.getWorldDirection(e).negate()}updateMatrixWorld(e){super.updateMatrixWorld(e),this.matrixWorld.decompose(bd,Md,Js),Js.x===1&&Js.y===1&&Js.z===1?this.matrixWorldInverse.copy(this.matrixWorld).invert():this.matrixWorldInverse.compose(bd,Md,Js.set(1,1,1)).invert()}updateWorldMatrix(e,t,i=!1){super.updateWorldMatrix(e,t,i),this.matrixWorld.decompose(bd,Md,Js),Js.x===1&&Js.y===1&&Js.z===1?this.matrixWorldInverse.copy(this.matrixWorld).invert():this.matrixWorldInverse.compose(bd,Md,Js.set(1,1,1)).invert()}clone(){return new this.constructor().copy(this)}}const sa=new D,W1=new we,X1=new we;class Qn extends xw{constructor(e=50,t=1,i=.1,n=2e3){super(),this.isPerspectiveCamera=!0,this.type="PerspectiveCamera",this.fov=e,this.zoom=1,this.near=i,this.far=n,this.focus=10,this.aspect=t,this.view=null,this.filmGauge=35,this.filmOffset=0,this.updateProjectionMatrix()}copy(e,t){return super.copy(e,t),this.fov=e.fov,this.zoom=e.zoom,this.near=e.near,this.far=e.far,this.focus=e.focus,this.aspect=e.aspect,this.view=e.view===null?null:Object.assign({},e.view),this.filmGauge=e.filmGauge,this.filmOffset=e.filmOffset,this}setFocalLength(e){const t=.5*this.getFilmHeight()/e;this.fov=oc*2*Math.atan(t),this.updateProjectionMatrix()}getFocalLength(){const e=Math.tan(jc*.5*this.fov);return .5*this.getFilmHeight()/e}getEffectiveFOV(){return oc*2*Math.atan(Math.tan(jc*.5*this.fov)/this.zoom)}getFilmWidth(){return this.filmGauge*Math.min(this.aspect,1)}getFilmHeight(){return this.filmGauge/Math.max(this.aspect,1)}getViewBounds(e,t,i){sa.set(-1,-1,.5).applyMatrix4(this.projectionMatrixInverse),t.set(sa.x,sa.y).multiplyScalar(-e/sa.z),sa.set(1,1,.5).applyMatrix4(this.projectionMatrixInverse),i.set(sa.x,sa.y).multiplyScalar(-e/sa.z)}getViewSize(e,t){return this.getViewBounds(e,W1,X1),t.subVectors(X1,W1)}setViewOffset(e,t,i,n,s,r){this.aspect=e/t,this.view===null&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=e,this.view.fullHeight=t,this.view.offsetX=i,this.view.offsetY=n,this.view.width=s,this.view.height=r,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const e=this.near;let t=e*Math.tan(jc*.5*this.fov)/this.zoom,i=2*t,n=this.aspect*i,s=-.5*n;const r=this.view;if(this.view!==null&&this.view.enabled){const l=r.fullWidth,c=r.fullHeight;s+=r.offsetX*n/l,t-=r.offsetY*i/c,n*=r.width/l,i*=r.height/c}const a=this.filmOffset;a!==0&&(s+=e*a/this.getFilmWidth()),this.projectionMatrix.makePerspective(s,s+n,t,t-i,e,this.far,this.coordinateSystem,this.reversedDepth),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(e){const t=super.toJSON(e);return t.object.fov=this.fov,t.object.zoom=this.zoom,t.object.near=this.near,t.object.far=this.far,t.object.focus=this.focus,t.object.aspect=this.aspect,this.view!==null&&(t.object.view=Object.assign({},this.view)),t.object.filmGauge=this.filmGauge,t.object.filmOffset=this.filmOffset,t}}class sA extends Tg{constructor(){super(new Qn(50,1,.5,500)),this.isSpotLightShadow=!0,this.focus=1,this.aspect=1}updateMatrices(e){const t=this.camera,i=oc*2*e.angle*this.focus,n=this.mapSize.width/this.mapSize.height*this.aspect,s=e.distance||t.far;(i!==t.fov||n!==t.aspect||s!==t.far)&&(t.fov=i,t.aspect=n,t.far=s,t.updateProjectionMatrix()),super.updateMatrices(e)}copy(e){return super.copy(e),this.focus=e.focus,this}}class Zk extends Af{constructor(e,t,i=0,n=Math.PI/3,s=0,r=2){super(e,t),this.isSpotLight=!0,this.type="SpotLight",this.position.copy(hi.DEFAULT_UP),this.updateMatrix(),this.target=new hi,this.distance=i,this.angle=n,this.penumbra=s,this.decay=r,this.map=null,this.shadow=new sA}get power(){return this.intensity*Math.PI}set power(e){this.intensity=e/Math.PI}dispose(){super.dispose(),this.shadow.dispose()}copy(e,t){return super.copy(e,t),this.distance=e.distance,this.angle=e.angle,this.penumbra=e.penumbra,this.decay=e.decay,this.target=e.target.clone(),this.map=e.map,this.shadow=e.shadow.clone(),this}toJSON(e){const t=super.toJSON(e);return t.object.distance=this.distance,t.object.angle=this.angle,t.object.decay=this.decay,t.object.penumbra=this.penumbra,t.object.target=this.target.uuid,this.map&&this.map.isTexture&&(t.object.map=this.map.toJSON(e).uuid),t.object.shadow=this.shadow.toJSON(),t}}class rA extends Tg{constructor(){super(new Qn(90,1,.5,500)),this.isPointLightShadow=!0}}class Sw extends Af{constructor(e,t,i=0,n=2){super(e,t),this.isPointLight=!0,this.type="PointLight",this.distance=i,this.decay=n,this.shadow=new rA}get power(){return this.intensity*4*Math.PI}set power(e){this.intensity=e/(4*Math.PI)}dispose(){super.dispose(),this.shadow.dispose()}copy(e,t){return super.copy(e,t),this.distance=e.distance,this.decay=e.decay,this.shadow=e.shadow.clone(),this}toJSON(e){const t=super.toJSON(e);return t.object.distance=this.distance,t.object.decay=this.decay,t.object.shadow=this.shadow.toJSON(),t}}class $s extends xw{constructor(e=-1,t=1,i=1,n=-1,s=.1,r=2e3){super(),this.isOrthographicCamera=!0,this.type="OrthographicCamera",this.zoom=1,this.view=null,this.left=e,this.right=t,this.top=i,this.bottom=n,this.near=s,this.far=r,this.updateProjectionMatrix()}copy(e,t){return super.copy(e,t),this.left=e.left,this.right=e.right,this.top=e.top,this.bottom=e.bottom,this.near=e.near,this.far=e.far,this.zoom=e.zoom,this.view=e.view===null?null:Object.assign({},e.view),this}setViewOffset(e,t,i,n,s,r){this.view===null&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=e,this.view.fullHeight=t,this.view.offsetX=i,this.view.offsetY=n,this.view.width=s,this.view.height=r,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const e=(this.right-this.left)/(2*this.zoom),t=(this.top-this.bottom)/(2*this.zoom),i=(this.right+this.left)/2,n=(this.top+this.bottom)/2;let s=i-e,r=i+e,a=n+t,l=n-t;if(this.view!==null&&this.view.enabled){const c=(this.right-this.left)/this.view.fullWidth/this.zoom,h=(this.top-this.bottom)/this.view.fullHeight/this.zoom;s+=c*this.view.offsetX,r=s+c*this.view.width,a-=h*this.view.offsetY,l=a-h*this.view.height}this.projectionMatrix.makeOrthographic(s,r,a,l,this.near,this.far,this.coordinateSystem,this.reversedDepth),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(e){const t=super.toJSON(e);return t.object.zoom=this.zoom,t.object.left=this.left,t.object.right=this.right,t.object.top=this.top,t.object.bottom=this.bottom,t.object.near=this.near,t.object.far=this.far,this.view!==null&&(t.object.view=Object.assign({},this.view)),t}}class aA extends Tg{constructor(){super(new $s(-5,5,5,-5,.5,500)),this.isDirectionalLightShadow=!0}}class $1 extends Af{constructor(e,t){super(e,t),this.isDirectionalLight=!0,this.type="DirectionalLight",this.position.copy(hi.DEFAULT_UP),this.updateMatrix(),this.target=new hi,this.shadow=new aA}dispose(){super.dispose(),this.shadow.dispose()}copy(e){return super.copy(e),this.target=e.target.clone(),this.shadow=e.shadow.clone(),this}toJSON(e){const t=super.toJSON(e);return t.object.shadow=this.shadow.toJSON(),t.object.target=this.target.uuid,t}}class jk{static extractUrlBase(e){const t=e.lastIndexOf("/");return t===-1?"./":e.slice(0,t+1)}static resolveURL(e,t){return typeof e!="string"||e===""?"":(/^https?:\/\//i.test(t)&&/^\//.test(e)&&(t=t.replace(/(^https?:\/\/[^\/]+).*/i,"$1")),/^(https?:)?\/\//i.test(e)||/^data:.*,.*$/i.test(e)||/^blob:.*$/i.test(e)?e:t+e)}}class Jk extends ot{constructor(){super(),this.isInstancedBufferGeometry=!0,this.type="InstancedBufferGeometry",this.instanceCount=1/0}copy(e){return super.copy(e),this.instanceCount=e.instanceCount,this}toJSON(){const e=super.toJSON();return e.instanceCount=this.instanceCount,e.isInstancedBufferGeometry=!0,e}}const Mp=new WeakMap;class Qk extends Ph{constructor(e){super(e),this.isImageBitmapLoader=!0,typeof createImageBitmap>"u"&&ke("ImageBitmapLoader: createImageBitmap() not supported."),typeof fetch>"u"&&ke("ImageBitmapLoader: fetch() not supported."),this.options={premultiplyAlpha:"none"},this._abortController=new AbortController}setOptions(e){return this.options=e,this}load(e,t,i,n){e===void 0&&(e=""),this.path!==void 0&&(e=this.path+e),e=this.manager.resolveURL(e);const s=this,r=zr.get(`image-bitmap:${e}`);if(r!==void 0){if(s.manager.itemStart(e),r.then){r.then(c=>{Mp.has(r)===!0?(n&&n(Mp.get(r)),s.manager.itemError(e),s.manager.itemEnd(e)):(t&&t(c),s.manager.itemEnd(e))});return}setTimeout(function(){t&&t(r),s.manager.itemEnd(e)},0);return}const a={};a.credentials=this.crossOrigin==="anonymous"?"same-origin":"include",a.headers=this.requestHeader,a.signal=typeof AbortSignal.any=="function"?AbortSignal.any([this._abortController.signal,this.manager.abortController.signal]):this._abortController.signal;const l=fetch(e,a).then(function(c){return c.blob()}).then(function(c){return createImageBitmap(c,Object.assign(s.options,{colorSpaceConversion:"none"}))}).then(function(c){zr.add(`image-bitmap:${e}`,c),t&&t(c),s.manager.itemEnd(e)}).catch(function(c){n&&n(c),Mp.set(l,c),zr.remove(`image-bitmap:${e}`),s.manager.itemError(e),s.manager.itemEnd(e)});zr.add(`image-bitmap:${e}`,l),s.manager.itemStart(e)}abort(){return this._abortController.abort(),this._abortController=new AbortController,this}}const hl=-90,dl=1;class Ig extends hi{constructor(e,t,i){super(),this.type="CubeCamera",this.renderTarget=i,this.coordinateSystem=null,this.activeMipmapLevel=0;const n=new Qn(hl,dl,e,t);n.layers=this.layers,this.add(n);const s=new Qn(hl,dl,e,t);s.layers=this.layers,this.add(s);const r=new Qn(hl,dl,e,t);r.layers=this.layers,this.add(r);const a=new Qn(hl,dl,e,t);a.layers=this.layers,this.add(a);const l=new Qn(hl,dl,e,t);l.layers=this.layers,this.add(l);const c=new Qn(hl,dl,e,t);c.layers=this.layers,this.add(c)}updateCoordinateSystem(){const e=this.coordinateSystem,t=this.children.concat(),[i,n,s,r,a,l]=t;for(const c of t)this.remove(c);if(e===vr)i.up.set(0,1,0),i.lookAt(1,0,0),n.up.set(0,1,0),n.lookAt(-1,0,0),s.up.set(0,0,-1),s.lookAt(0,1,0),r.up.set(0,0,1),r.lookAt(0,-1,0),a.up.set(0,1,0),a.lookAt(0,0,1),l.up.set(0,1,0),l.lookAt(0,0,-1);else if(e===xh)i.up.set(0,-1,0),i.lookAt(-1,0,0),n.up.set(0,-1,0),n.lookAt(1,0,0),s.up.set(0,0,1),s.lookAt(0,1,0),r.up.set(0,0,-1),r.lookAt(0,-1,0),a.up.set(0,-1,0),a.lookAt(0,0,1),l.up.set(0,-1,0),l.lookAt(0,0,-1);else throw new Error("THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: "+e);for(const c of t)this.add(c),c.updateMatrixWorld()}update(e,t){this.parent===null&&this.updateMatrixWorld();const{renderTarget:i,activeMipmapLevel:n}=this;this.coordinateSystem!==e.coordinateSystem&&(this.coordinateSystem=e.coordinateSystem,this.updateCoordinateSystem());const[s,r,a,l,c,h]=this.children,d=e.getRenderTarget(),u=e.getActiveCubeFace(),f=e.getActiveMipmapLevel(),p=e.xr.enabled;e.xr.enabled=!1;const g=i.texture.generateMipmaps;i.texture.generateMipmaps=!1;let m=!1;e.isWebGLRenderer===!0?m=e.state.buffers.depth.getReversed():m=e.reversedDepthBuffer,e.setRenderTarget(i,0,n),m&&e.autoClear===!1&&e.clearDepth(),e.render(t,s),e.setRenderTarget(i,1,n),m&&e.autoClear===!1&&e.clearDepth(),e.render(t,r),e.setRenderTarget(i,2,n),m&&e.autoClear===!1&&e.clearDepth(),e.render(t,a),e.setRenderTarget(i,3,n),m&&e.autoClear===!1&&e.clearDepth(),e.render(t,l),e.setRenderTarget(i,4,n),m&&e.autoClear===!1&&e.clearDepth(),e.render(t,c),i.texture.generateMipmaps=g,e.setRenderTarget(i,5,n),m&&e.autoClear===!1&&e.clearDepth(),e.render(t,h),e.setRenderTarget(d,u,f),e.xr.enabled=p,i.texture.needsPMREMUpdate=!0}}class oA extends Qn{constructor(e=[]){super(),this.isArrayCamera=!0,this.isMultiViewCamera=!1,this.cameras=e}}class lA{constructor(e,t,i){this.binding=e,this.valueSize=i;let n,s,r;switch(t){case"quaternion":n=this._slerp,s=this._slerpAdditive,r=this._setAdditiveIdentityQuaternion,this.buffer=new Float64Array(i*6),this._workIndex=5;break;case"string":case"bool":n=this._select,s=this._select,r=this._setAdditiveIdentityOther,this.buffer=new Array(i*5);break;default:n=this._lerp,s=this._lerpAdditive,r=this._setAdditiveIdentityNumeric,this.buffer=new Float64Array(i*5)}this._mixBufferRegion=n,this._mixBufferRegionAdditive=s,this._setIdentity=r,this._origIndex=3,this._addIndex=4,this.cumulativeWeight=0,this.cumulativeWeightAdditive=0,this.useCount=0,this.referenceCount=0}accumulate(e,t){const i=this.buffer,n=this.valueSize,s=e*n+n;let r=this.cumulativeWeight;if(r===0){for(let a=0;a!==n;++a)i[s+a]=i[a];r=t}else{r+=t;const a=t/r;this._mixBufferRegion(i,s,0,a,n)}this.cumulativeWeight=r}accumulateAdditive(e){const t=this.buffer,i=this.valueSize,n=i*this._addIndex;this.cumulativeWeightAdditive===0&&this._setIdentity(),this._mixBufferRegionAdditive(t,n,0,e,i),this.cumulativeWeightAdditive+=e}apply(e){const t=this.valueSize,i=this.buffer,n=e*t+t,s=this.cumulativeWeight,r=this.cumulativeWeightAdditive,a=this.binding;if(this.cumulativeWeight=0,this.cumulativeWeightAdditive=0,s<1){const l=t*this._origIndex;this._mixBufferRegion(i,n,l,1-s,t)}r>0&&this._mixBufferRegionAdditive(i,n,this._addIndex*t,1,t);for(let l=t,c=t+t;l!==c;++l)if(i[l]!==i[l+t]){a.setValue(i,n);break}}saveOriginalState(){const e=this.binding,t=this.buffer,i=this.valueSize,n=i*this._origIndex;e.getValue(t,n);for(let s=i,r=n;s!==r;++s)t[s]=t[n+s%i];this._setIdentity(),this.cumulativeWeight=0,this.cumulativeWeightAdditive=0}restoreOriginalState(){const e=this.valueSize*3;this.binding.setValue(this.buffer,e)}_setAdditiveIdentityNumeric(){const e=this._addIndex*this.valueSize,t=e+this.valueSize;for(let i=e;i<t;i++)this.buffer[i]=0}_setAdditiveIdentityQuaternion(){this._setAdditiveIdentityNumeric(),this.buffer[this._addIndex*this.valueSize+3]=1}_setAdditiveIdentityOther(){const e=this._origIndex*this.valueSize,t=this._addIndex*this.valueSize;for(let i=0;i<this.valueSize;i++)this.buffer[t+i]=this.buffer[e+i]}_select(e,t,i,n,s){if(n>=.5)for(let r=0;r!==s;++r)e[t+r]=e[i+r]}_slerp(e,t,i,n){An.slerpFlat(e,t,e,t,e,i,n)}_slerpAdditive(e,t,i,n,s){const r=this._workIndex*s;An.multiplyQuaternionsFlat(e,r,e,t,e,i),An.slerpFlat(e,t,e,t,e,r,n)}_lerp(e,t,i,n,s){const r=1-n;for(let a=0;a!==s;++a){const l=t+a;e[l]=e[l]*r+e[i+a]*n}}_lerpAdditive(e,t,i,n,s){for(let r=0;r!==s;++r){const a=t+r;e[a]=e[a]+e[i+r]*n}}}const Dg="\\[\\]\\.:\\/",cA=new RegExp("["+Dg+"]","g"),Rg="[^"+Dg+"]",hA="[^"+Dg.replace("\\.","")+"]",dA=/((?:WC+[\/:])*)/.source.replace("WC",Rg),uA=/(WCOD+)?/.source.replace("WCOD",hA),fA=/(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace("WC",Rg),pA=/\.(WC+)(?:\[(.+)\])?/.source.replace("WC",Rg),mA=new RegExp("^"+dA+uA+fA+pA+"$"),gA=["material","materials","bones","map"];class vA{constructor(e,t,i){const n=i||Kt.parseTrackName(t);this._targetGroup=e,this._bindings=e.subscribe_(t,n)}getValue(e,t){this.bind();const i=this._targetGroup.nCachedObjects_,n=this._bindings[i];n!==void 0&&n.getValue(e,t)}setValue(e,t){const i=this._bindings;for(let n=this._targetGroup.nCachedObjects_,s=i.length;n!==s;++n)i[n].setValue(e,t)}bind(){const e=this._bindings;for(let t=this._targetGroup.nCachedObjects_,i=e.length;t!==i;++t)e[t].bind()}unbind(){const e=this._bindings;for(let t=this._targetGroup.nCachedObjects_,i=e.length;t!==i;++t)e[t].unbind()}}class Kt{constructor(e,t,i){this.path=t,this.parsedPath=i||Kt.parseTrackName(t),this.node=Kt.findNode(e,this.parsedPath.nodeName),this.rootNode=e,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}static create(e,t,i){return e&&e.isAnimationObjectGroup?new Kt.Composite(e,t,i):new Kt(e,t,i)}static sanitizeNodeName(e){return e.replace(/\s/g,"_").replace(cA,"")}static parseTrackName(e){const t=mA.exec(e);if(t===null)throw new Error("THREE.PropertyBinding: Cannot parse trackName: "+e);const i={nodeName:t[2],objectName:t[3],objectIndex:t[4],propertyName:t[5],propertyIndex:t[6]},n=i.nodeName&&i.nodeName.lastIndexOf(".");if(n!==void 0&&n!==-1){const s=i.nodeName.substring(n+1);gA.indexOf(s)!==-1&&(i.nodeName=i.nodeName.substring(0,n),i.objectName=s)}if(i.propertyName===null||i.propertyName.length===0)throw new Error("THREE.PropertyBinding: can not parse propertyName from trackName: "+e);return i}static findNode(e,t){if(t===void 0||t===""||t==="."||t===-1||t===e.name||t===e.uuid)return e;if(e.skeleton){const i=e.skeleton.getBoneByName(t);if(i!==void 0)return i}if(e.children){const i=function(s){for(let r=0;r<s.length;r++){const a=s[r];if(a.name===t||a.uuid===t)return a;const l=i(a.children);if(l)return l}return null},n=i(e.children);if(n)return n}return null}_getValue_unavailable(){}_setValue_unavailable(){}_getValue_direct(e,t){e[t]=this.targetObject[this.propertyName]}_getValue_array(e,t){const i=this.resolvedProperty;for(let n=0,s=i.length;n!==s;++n)e[t++]=i[n]}_getValue_arrayElement(e,t){e[t]=this.resolvedProperty[this.propertyIndex]}_getValue_toArray(e,t){this.resolvedProperty.toArray(e,t)}_setValue_direct(e,t){this.targetObject[this.propertyName]=e[t]}_setValue_direct_setNeedsUpdate(e,t){this.targetObject[this.propertyName]=e[t],this.targetObject.needsUpdate=!0}_setValue_direct_setMatrixWorldNeedsUpdate(e,t){this.targetObject[this.propertyName]=e[t],this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_array(e,t){const i=this.resolvedProperty;for(let n=0,s=i.length;n!==s;++n)i[n]=e[t++]}_setValue_array_setNeedsUpdate(e,t){const i=this.resolvedProperty;for(let n=0,s=i.length;n!==s;++n)i[n]=e[t++];this.targetObject.needsUpdate=!0}_setValue_array_setMatrixWorldNeedsUpdate(e,t){const i=this.resolvedProperty;for(let n=0,s=i.length;n!==s;++n)i[n]=e[t++];this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_arrayElement(e,t){this.resolvedProperty[this.propertyIndex]=e[t]}_setValue_arrayElement_setNeedsUpdate(e,t){this.resolvedProperty[this.propertyIndex]=e[t],this.targetObject.needsUpdate=!0}_setValue_arrayElement_setMatrixWorldNeedsUpdate(e,t){this.resolvedProperty[this.propertyIndex]=e[t],this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_fromArray(e,t){this.resolvedProperty.fromArray(e,t)}_setValue_fromArray_setNeedsUpdate(e,t){this.resolvedProperty.fromArray(e,t),this.targetObject.needsUpdate=!0}_setValue_fromArray_setMatrixWorldNeedsUpdate(e,t){this.resolvedProperty.fromArray(e,t),this.targetObject.matrixWorldNeedsUpdate=!0}_getValue_unbound(e,t){this.bind(),this.getValue(e,t)}_setValue_unbound(e,t){this.bind(),this.setValue(e,t)}bind(){let e=this.node;const t=this.parsedPath,i=t.objectName,n=t.propertyName;let s=t.propertyIndex;if(e||(e=Kt.findNode(this.rootNode,t.nodeName),this.node=e),this.getValue=this._getValue_unavailable,this.setValue=this._setValue_unavailable,!e){ke("PropertyBinding: No target node found for track: "+this.path+".");return}if(i){let c=t.objectIndex;switch(i){case"materials":if(!e.material){Ze("PropertyBinding: Can not bind to material as node does not have a material.",this);return}if(!e.material.materials){Ze("PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.",this);return}e=e.material.materials;break;case"bones":if(!e.skeleton){Ze("PropertyBinding: Can not bind to bones as node does not have a skeleton.",this);return}e=e.skeleton.bones;for(let h=0;h<e.length;h++)if(e[h].name===c){c=h;break}break;case"map":if("map"in e){e=e.map;break}if(!e.material){Ze("PropertyBinding: Can not bind to material as node does not have a material.",this);return}if(!e.material.map){Ze("PropertyBinding: Can not bind to material.map as node.material does not have a map.",this);return}e=e.material.map;break;default:if(e[i]===void 0){Ze("PropertyBinding: Can not bind to objectName of node undefined.",this);return}e=e[i]}if(c!==void 0){if(e[c]===void 0){Ze("PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.",this,e);return}e=e[c]}}const r=e[n];if(r===void 0){const c=t.nodeName;Ze("PropertyBinding: Trying to update property for track: "+c+"."+n+" but it wasn't found.",e);return}let a=this.Versioning.None;this.targetObject=e,e.isMaterial===!0?a=this.Versioning.NeedsUpdate:e.isObject3D===!0&&(a=this.Versioning.MatrixWorldNeedsUpdate);let l=this.BindingType.Direct;if(s!==void 0){if(n==="morphTargetInfluences"){if(!e.geometry){Ze("PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.",this);return}if(!e.geometry.morphAttributes){Ze("PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.",this);return}e.morphTargetDictionary[s]!==void 0&&(s=e.morphTargetDictionary[s])}l=this.BindingType.ArrayElement,this.resolvedProperty=r,this.propertyIndex=s}else r.fromArray!==void 0&&r.toArray!==void 0?(l=this.BindingType.HasFromToArray,this.resolvedProperty=r):Array.isArray(r)?(l=this.BindingType.EntireArray,this.resolvedProperty=r):this.propertyName=n;this.getValue=this.GetterByBindingType[l],this.setValue=this.SetterByBindingTypeAndVersioning[l][a]}unbind(){this.node=null,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}}Kt.Composite=vA;Kt.prototype.BindingType={Direct:0,EntireArray:1,ArrayElement:2,HasFromToArray:3};Kt.prototype.Versioning={None:0,NeedsUpdate:1,MatrixWorldNeedsUpdate:2};Kt.prototype.GetterByBindingType=[Kt.prototype._getValue_direct,Kt.prototype._getValue_array,Kt.prototype._getValue_arrayElement,Kt.prototype._getValue_toArray];Kt.prototype.SetterByBindingTypeAndVersioning=[[Kt.prototype._setValue_direct,Kt.prototype._setValue_direct_setNeedsUpdate,Kt.prototype._setValue_direct_setMatrixWorldNeedsUpdate],[Kt.prototype._setValue_array,Kt.prototype._setValue_array_setNeedsUpdate,Kt.prototype._setValue_array_setMatrixWorldNeedsUpdate],[Kt.prototype._setValue_arrayElement,Kt.prototype._setValue_arrayElement_setNeedsUpdate,Kt.prototype._setValue_arrayElement_setMatrixWorldNeedsUpdate],[Kt.prototype._setValue_fromArray,Kt.prototype._setValue_fromArray_setNeedsUpdate,Kt.prototype._setValue_fromArray_setMatrixWorldNeedsUpdate]];class yA{constructor(e,t,i=null,n=t.blendMode){this._mixer=e,this._clip=t,this._localRoot=i,this.blendMode=n;const s=t.tracks,r=s.length,a=new Array(r),l={endingStart:Tl,endingEnd:Tl};for(let c=0;c!==r;++c){const h=s[c].createInterpolant(null);a[c]=h,h.settings=l}this._interpolantSettings=l,this._interpolants=a,this._propertyBindings=new Array(r),this._cacheIndex=null,this._byClipCacheIndex=null,this._timeScaleInterpolant=null,this._restoreTimeScale=null,this._weightInterpolant=null,this.loop=CE,this._loopCount=-1,this._startTime=null,this.time=0,this.timeScale=1,this._effectiveTimeScale=1,this.weight=1,this._effectiveWeight=1,this.repetitions=1/0,this.paused=!1,this.enabled=!0,this.clampWhenFinished=!1,this.zeroSlopeAtStart=!0,this.zeroSlopeAtEnd=!0}play(){return this._mixer._activateAction(this),this}stop(){return this._mixer._deactivateAction(this),this.reset()}reset(){return this.paused=!1,this.enabled=!0,this.time=0,this._loopCount=-1,this._startTime=null,this.stopFading().stopWarping()}isRunning(){return this.enabled&&!this.paused&&this.timeScale!==0&&this._startTime===null&&this._mixer._isActiveAction(this)}isScheduled(){return this._mixer._isActiveAction(this)}startAt(e){return this._startTime=e,this}setLoop(e,t){return this.loop=e,this.repetitions=t,this}setEffectiveWeight(e){return this.weight=e,this._effectiveWeight=this.enabled?e:0,this.stopFading()}getEffectiveWeight(){return this._effectiveWeight}fadeIn(e){return this._scheduleFading(e,0,1)}fadeOut(e){return this._scheduleFading(e,1,0)}crossFadeFrom(e,t,i=!1){if(e.fadeOut(t),this.fadeIn(t),i===!0){const n=this._clip.duration,s=e._clip.duration,r=s/n,a=n/s;e._restoreTimeScale=e.timeScale,this._restoreTimeScale=this.timeScale,e.warp(1,r,t),this.warp(a,1,t)}return this}crossFadeTo(e,t,i=!1){return e.crossFadeFrom(this,t,i)}stopFading(){const e=this._weightInterpolant;return e!==null&&(this._weightInterpolant=null,this._mixer._takeBackControlInterpolant(e)),this}setEffectiveTimeScale(e){return this.timeScale=e,this._effectiveTimeScale=this.paused?0:e,this.stopWarping()}getEffectiveTimeScale(){return this._effectiveTimeScale}setDuration(e){return this.timeScale=this._clip.duration/e,this.stopWarping()}syncWith(e){return this.time=e.time,this.timeScale=e.timeScale,this.stopWarping()}halt(e){return this.warp(this._effectiveTimeScale,0,e)}warp(e,t,i){const n=this._mixer,s=n.time,r=this.timeScale;let a=this._timeScaleInterpolant;a===null&&(a=n._lendControlInterpolant(),this._timeScaleInterpolant=a);const l=a.parameterPositions,c=a.sampleValues;return l[0]=s,l[1]=s+i,c[0]=e/r,c[1]=t/r,this}stopWarping(){const e=this._timeScaleInterpolant;return e!==null&&(this._timeScaleInterpolant=null,this._mixer._takeBackControlInterpolant(e)),this._restoreTimeScale=null,this}getMixer(){return this._mixer}getClip(){return this._clip}getRoot(){return this._localRoot||this._mixer._root}_update(e,t,i,n){if(!this.enabled){this._updateWeight(e);return}const s=this._startTime;if(s!==null){const l=(e-s)*i;l<0||i===0?t=0:(this._startTime=null,t=i*l)}t*=this._updateTimeScale(e);const r=this._updateTime(t),a=this._updateWeight(e);if(a>0){const l=this._interpolants,c=this._propertyBindings;switch(this.blendMode){case PE:for(let h=0,d=l.length;h!==d;++h)l[h].evaluate(r),c[h].accumulateAdditive(a);break;case pg:default:for(let h=0,d=l.length;h!==d;++h)l[h].evaluate(r),c[h].accumulate(n,a)}}}_updateWeight(e){let t=0;if(this.enabled){t=this.weight;const i=this._weightInterpolant;if(i!==null){const n=i.evaluate(e)[0];t*=n,e>i.parameterPositions[1]&&(this.stopFading(),n===0&&(this.enabled=!1))}}return this._effectiveWeight=t,t}_updateTimeScale(e){let t=0;if(!this.paused){t=this.timeScale;const i=this._timeScaleInterpolant;if(i!==null){const n=i.evaluate(e)[0];t*=n,e>i.parameterPositions[1]&&(t===0?this.paused=!0:(this._restoreTimeScale!==null&&(t=this._restoreTimeScale),this.timeScale=t),this.stopWarping())}}return this._effectiveTimeScale=t,t}_updateTime(e){const t=this._clip.duration,i=this.loop;let n=this.time+e,s=this._loopCount;const r=i===kE;if(e===0)return s===-1?n:r&&(s&1)===1?t-n:n;if(i===rw){s===-1&&(this._loopCount=0,this._setEndings(!0,!0,!1));e:{if(n>=t)n=t;else if(n<0)n=0;else{this.time=n;break e}this.clampWhenFinished?this.paused=!0:this.enabled=!1,this.time=n,this._mixer.dispatchEvent({type:"finished",action:this,direction:e<0?-1:1})}}else{if(s===-1&&(e>=0?(s=0,this._setEndings(!0,this.repetitions===0,r)):this._setEndings(this.repetitions===0,!0,r)),n>=t||n<0){const a=Math.floor(n/t);n-=t*a,s+=Math.abs(a);const l=this.repetitions-s;if(l<=0)this.clampWhenFinished?this.paused=!0:this.enabled=!1,n=e>0?t:0,this.time=n,this._mixer.dispatchEvent({type:"finished",action:this,direction:e>0?1:-1});else{if(l===1){const c=e<0;this._setEndings(c,!c,r)}else this._setEndings(!1,!1,r);this._loopCount=s,this.time=n,this._mixer.dispatchEvent({type:"loop",action:this,loopDelta:a})}}else this._loopCount=s,this.time=n;if(r&&(s&1)===1)return t-n}return n}_setEndings(e,t,i){const n=this._interpolantSettings;i?(n.endingStart=Il,n.endingEnd=Il):(e?n.endingStart=this.zeroSlopeAtStart?Il:Tl:n.endingStart=zu,t?n.endingEnd=this.zeroSlopeAtEnd?Il:Tl:n.endingEnd=zu)}_scheduleFading(e,t,i){const n=this._mixer,s=n.time;let r=this._weightInterpolant;r===null&&(r=n._lendControlInterpolant(),this._weightInterpolant=r);const a=r.parameterPositions,l=r.sampleValues;return a[0]=s,l[0]=t,a[1]=s+e,l[1]=i,this}}const bA=new Float32Array(1);class MA extends Na{constructor(e){super(),this._root=e,this._initMemoryManager(),this._accuIndex=0,this.time=0,this.timeScale=1,typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}_bindAction(e,t){const i=e._localRoot||this._root,n=e._clip.tracks,s=n.length,r=e._propertyBindings,a=e._interpolants,l=i.uuid,c=this._bindingsByRootAndName;let h=c[l];h===void 0&&(h={},c[l]=h);for(let d=0;d!==s;++d){const u=n[d],f=u.name;let p=h[f];if(p!==void 0)++p.referenceCount,r[d]=p;else{if(p=r[d],p!==void 0){p._cacheIndex===null&&(++p.referenceCount,this._addInactiveBinding(p,l,f));continue}const g=t&&t._propertyBindings[d].binding.parsedPath;p=new lA(Kt.create(i,f,g),u.ValueTypeName,u.getValueSize()),++p.referenceCount,this._addInactiveBinding(p,l,f),r[d]=p}a[d].resultBuffer=p.buffer}}_activateAction(e){if(!this._isActiveAction(e)){if(e._cacheIndex===null){const i=(e._localRoot||this._root).uuid,n=e._clip.uuid,s=this._actionsByClip[n];this._bindAction(e,s&&s.knownActions[0]),this._addInactiveAction(e,n,i)}const t=e._propertyBindings;for(let i=0,n=t.length;i!==n;++i){const s=t[i];s.useCount++===0&&(this._lendBinding(s),s.saveOriginalState())}this._lendAction(e)}}_deactivateAction(e){if(this._isActiveAction(e)){const t=e._propertyBindings;for(let i=0,n=t.length;i!==n;++i){const s=t[i];--s.useCount===0&&(s.restoreOriginalState(),this._takeBackBinding(s))}this._takeBackAction(e)}}_initMemoryManager(){this._actions=[],this._nActiveActions=0,this._actionsByClip={},this._bindings=[],this._nActiveBindings=0,this._bindingsByRootAndName={},this._controlInterpolants=[],this._nActiveControlInterpolants=0;const e=this;this.stats={actions:{get total(){return e._actions.length},get inUse(){return e._nActiveActions}},bindings:{get total(){return e._bindings.length},get inUse(){return e._nActiveBindings}},controlInterpolants:{get total(){return e._controlInterpolants.length},get inUse(){return e._nActiveControlInterpolants}}}}_isActiveAction(e){const t=e._cacheIndex;return t!==null&&t<this._nActiveActions}_addInactiveAction(e,t,i){const n=this._actions,s=this._actionsByClip;let r=s[t];if(r===void 0)r={knownActions:[e],actionByRoot:{}},e._byClipCacheIndex=0,s[t]=r;else{const a=r.knownActions;e._byClipCacheIndex=a.length,a.push(e)}e._cacheIndex=n.length,n.push(e),r.actionByRoot[i]=e}_removeInactiveAction(e){const t=this._actions,i=t[t.length-1],n=e._cacheIndex;i._cacheIndex=n,t[n]=i,t.pop(),e._cacheIndex=null;const s=e._clip.uuid,r=this._actionsByClip,a=r[s],l=a.knownActions,c=l[l.length-1],h=e._byClipCacheIndex;c._byClipCacheIndex=h,l[h]=c,l.pop(),e._byClipCacheIndex=null;const d=a.actionByRoot,u=(e._localRoot||this._root).uuid;delete d[u],l.length===0&&delete r[s],this._removeInactiveBindingsForAction(e)}_removeInactiveBindingsForAction(e){const t=e._propertyBindings;for(let i=0,n=t.length;i!==n;++i){const s=t[i];--s.referenceCount===0&&this._removeInactiveBinding(s)}}_lendAction(e){const t=this._actions,i=e._cacheIndex,n=this._nActiveActions++,s=t[n];e._cacheIndex=n,t[n]=e,s._cacheIndex=i,t[i]=s}_takeBackAction(e){const t=this._actions,i=e._cacheIndex,n=--this._nActiveActions,s=t[n];e._cacheIndex=n,t[n]=e,s._cacheIndex=i,t[i]=s}_addInactiveBinding(e,t,i){const n=this._bindingsByRootAndName,s=this._bindings;let r=n[t];r===void 0&&(r={},n[t]=r),r[i]=e,e._cacheIndex=s.length,s.push(e)}_removeInactiveBinding(e){const t=this._bindings,i=e.binding,n=i.rootNode.uuid,s=i.path,r=this._bindingsByRootAndName,a=r[n],l=t[t.length-1],c=e._cacheIndex;l._cacheIndex=c,t[c]=l,t.pop(),delete a[s],Object.keys(a).length===0&&delete r[n]}_lendBinding(e){const t=this._bindings,i=e._cacheIndex,n=this._nActiveBindings++,s=t[n];e._cacheIndex=n,t[n]=e,s._cacheIndex=i,t[i]=s}_takeBackBinding(e){const t=this._bindings,i=e._cacheIndex,n=--this._nActiveBindings,s=t[n];e._cacheIndex=n,t[n]=e,s._cacheIndex=i,t[i]=s}_lendControlInterpolant(){const e=this._controlInterpolants,t=this._nActiveControlInterpolants++;let i=e[t];return i===void 0&&(i=new bw(new Float32Array(2),new Float32Array(2),1,bA),i.__cacheIndex=t,e[t]=i),i}_takeBackControlInterpolant(e){const t=this._controlInterpolants,i=e.__cacheIndex,n=--this._nActiveControlInterpolants,s=t[n];e.__cacheIndex=n,t[n]=e,s.__cacheIndex=i,t[i]=s}clipAction(e,t,i){const n=t||this._root,s=n.uuid;let r=typeof e=="string"?z1.findByName(n,e):e;const a=r!==null?r.uuid:e,l=this._actionsByClip[a];let c=null;if(i===void 0&&(r!==null?i=r.blendMode:i=pg),l!==void 0){const d=l.actionByRoot[s];if(d!==void 0&&d.blendMode===i)return d;c=l.knownActions[0],r===null&&(r=c._clip)}if(r===null)return null;const h=new yA(this,r,t,i);return this._bindAction(h,c),this._addInactiveAction(h,a,s),h}existingAction(e,t){const i=t||this._root,n=i.uuid,s=typeof e=="string"?z1.findByName(i,e):e,r=s?s.uuid:e,a=this._actionsByClip[r];return a!==void 0&&a.actionByRoot[n]||null}stopAllAction(){const e=this._actions,t=this._nActiveActions;for(let i=t-1;i>=0;--i)e[i].stop();return this}update(e){e*=this.timeScale;const t=this._actions,i=this._nActiveActions,n=this.time+=e,s=Math.sign(e),r=this._accuIndex^=1;for(let c=0;c!==i;++c)t[c]._update(n,e,s,r);const a=this._bindings,l=this._nActiveBindings;for(let c=0;c!==l;++c)a[c].apply(r);return this}setTime(e){this.time=0;for(let t=0;t<this._actions.length;t++)this._actions[t].time=0;return this.update(e)}getRoot(){return this._root}uncacheClip(e){const t=this._actions,i=e.uuid,n=this._actionsByClip,s=n[i];if(s!==void 0){const r=s.knownActions;for(let a=0,l=r.length;a!==l;++a){const c=r[a];this._deactivateAction(c);const h=c._cacheIndex,d=t[t.length-1];c._cacheIndex=null,c._byClipCacheIndex=null,d._cacheIndex=h,t[h]=d,t.pop(),this._removeInactiveBindingsForAction(c)}delete n[i]}}uncacheRoot(e){const t=e.uuid,i=this._actionsByClip;for(const r in i){const a=i[r].actionByRoot,l=a[t];l!==void 0&&(this._deactivateAction(l),this._removeInactiveAction(l))}const n=this._bindingsByRootAndName,s=n[t];if(s!==void 0)for(const r in s){const a=s[r];a.restoreOriginalState(),this._removeInactiveBinding(a)}}uncacheAction(e,t){const i=this.existingAction(e,t);i!==null&&(this._deactivateAction(i),this._removeInactiveAction(i))}}class eP extends dw{constructor(e,t,i=1){super(e,t),this.isInstancedInterleavedBuffer=!0,this.meshPerAttribute=i}copy(e){return super.copy(e),this.meshPerAttribute=e.meshPerAttribute,this}clone(e){const t=super.clone(e);return t.meshPerAttribute=this.meshPerAttribute,t}toJSON(e){const t=super.toJSON(e);return t.isInstancedInterleavedBuffer=!0,t.meshPerAttribute=this.meshPerAttribute,t}}const Y1=new lt;class tu{constructor(e,t,i=0,n=1/0){this.ray=new Ch(e,t),this.near=i,this.far=n,this.camera=null,this.layers=new bg,this.params={Mesh:{},Line:{threshold:1},LOD:{},Points:{threshold:1},Sprite:{}}}set(e,t){this.ray.set(e,t)}setFromCamera(e,t){t.isPerspectiveCamera?(this.ray.origin.setFromMatrixPosition(t.matrixWorld),this.ray.direction.set(e.x,e.y,.5).unproject(t).sub(this.ray.origin).normalize(),this.camera=t):t.isOrthographicCamera?(this.ray.origin.set(e.x,e.y,t.projectionMatrix.elements[14]).unproject(t),this.ray.direction.set(0,0,-1).transformDirection(t.matrixWorld),this.camera=t):Ze("Raycaster: Unsupported camera type: "+t.type)}setFromXRController(e){return Y1.identity().extractRotation(e.matrixWorld),this.ray.origin.setFromMatrixPosition(e.matrixWorld),this.ray.direction.set(0,0,-1).applyMatrix4(Y1),this}intersectObject(e,t=!0,i=[]){return pm(e,this,i,t),i.sort(q1),i}intersectObjects(e,t=!0,i=[]){for(let n=0,s=e.length;n<s;n++)pm(e[n],this,i,t);return i.sort(q1),i}}function q1(o,e){return o.distance-e.distance}function pm(o,e,t,i){let n=!0;if(o.layers.test(e.layers)&&o.raycast(e,t)===!1&&(n=!1),n===!0&&i===!0){const s=o.children;for(let r=0,a=s.length;r<a;r++)pm(s[r],e,t,!0)}}class Ew{static{Ew.prototype.isMatrix2=!0}constructor(e,t,i,n){this.elements=[1,0,0,1],e!==void 0&&this.set(e,t,i,n)}identity(){return this.set(1,0,0,1),this}fromArray(e,t=0){for(let i=0;i<4;i++)this.elements[i]=e[i+t];return this}set(e,t,i,n){const s=this.elements;return s[0]=e,s[2]=t,s[1]=i,s[3]=n,this}}const K1=new D,wd=new D,ul=new D,fl=new D,wp=new D,wA=new D,xA=new D;class tP{constructor(e=new D,t=new D){this.start=e,this.end=t}set(e,t){return this.start.copy(e),this.end.copy(t),this}copy(e){return this.start.copy(e.start),this.end.copy(e.end),this}getCenter(e){return e.addVectors(this.start,this.end).multiplyScalar(.5)}delta(e){return e.subVectors(this.end,this.start)}distanceSq(){return this.start.distanceToSquared(this.end)}distance(){return this.start.distanceTo(this.end)}at(e,t){return this.delta(t).multiplyScalar(e).add(this.start)}closestPointToPointParameter(e,t){K1.subVectors(e,this.start),wd.subVectors(this.end,this.start);const i=wd.dot(wd);if(i===0)return 0;let s=wd.dot(K1)/i;return t&&(s=nt(s,0,1)),s}closestPointToPoint(e,t,i){const n=this.closestPointToPointParameter(e,t);return this.delta(i).multiplyScalar(n).add(this.start)}distanceSqToLine3(e,t=wA,i=xA){const n=10000000000000001e-32;let s,r;const a=this.start,l=e.start,c=this.end,h=e.end;ul.subVectors(c,a),fl.subVectors(h,l),wp.subVectors(a,l);const d=ul.dot(ul),u=fl.dot(fl),f=fl.dot(wp);if(d<=n&&u<=n)return t.copy(a),i.copy(l),t.sub(i),t.dot(t);if(d<=n)s=0,r=f/u,r=nt(r,0,1);else{const p=ul.dot(wp);if(u<=n)r=0,s=nt(-p/d,0,1);else{const g=ul.dot(fl),m=d*u-g*g;m!==0?s=nt((g*f-p*u)/m,0,1):s=0,r=(g*s+f)/u,r<0?(r=0,s=nt(-p/d,0,1)):r>1&&(r=1,s=nt((g-p)/d,0,1))}}return t.copy(a).addScaledVector(ul,s),i.copy(l).addScaledVector(fl,r),t.distanceToSquared(i)}applyMatrix4(e){return this.start.applyMatrix4(e),this.end.applyMatrix4(e),this}equals(e){return e.start.equals(this.start)&&e.end.equals(this.end)}clone(){return new this.constructor().copy(this)}}function Z1(o,e,t,i){const n=SA(i);switch(t){case nw:return o*e;case ac:return o*e/n.components*n.byteLength;case dg:return o*e/n.components*n.byteLength;case Fo:return o*e*2/n.components*n.byteLength;case ug:return o*e*2/n.components*n.byteLength;case sw:return o*e*3/n.components*n.byteLength;case Vi:return o*e*4/n.components*n.byteLength;case fg:return o*e*4/n.components*n.byteLength;case Zd:case jd:return Math.floor((o+3)/4)*Math.floor((e+3)/4)*8;case Jd:case Qd:return Math.floor((o+3)/4)*Math.floor((e+3)/4)*16;case O0:case F0:return Math.max(o,16)*Math.max(e,8)/4;case L0:case N0:return Math.max(o,8)*Math.max(e,8)/2;case U0:case B0:case H0:case G0:return Math.floor((o+3)/4)*Math.floor((e+3)/4)*8;case z0:case Fu:case V0:return Math.floor((o+3)/4)*Math.floor((e+3)/4)*16;case W0:return Math.floor((o+3)/4)*Math.floor((e+3)/4)*16;case X0:return Math.floor((o+4)/5)*Math.floor((e+3)/4)*16;case $0:return Math.floor((o+4)/5)*Math.floor((e+4)/5)*16;case Y0:return Math.floor((o+5)/6)*Math.floor((e+4)/5)*16;case q0:return Math.floor((o+5)/6)*Math.floor((e+5)/6)*16;case K0:return Math.floor((o+7)/8)*Math.floor((e+4)/5)*16;case Z0:return Math.floor((o+7)/8)*Math.floor((e+5)/6)*16;case j0:return Math.floor((o+7)/8)*Math.floor((e+7)/8)*16;case J0:return Math.floor((o+9)/10)*Math.floor((e+4)/5)*16;case Q0:return Math.floor((o+9)/10)*Math.floor((e+5)/6)*16;case em:return Math.floor((o+9)/10)*Math.floor((e+7)/8)*16;case tm:return Math.floor((o+9)/10)*Math.floor((e+9)/10)*16;case im:return Math.floor((o+11)/12)*Math.floor((e+9)/10)*16;case nm:return Math.floor((o+11)/12)*Math.floor((e+11)/12)*16;case sm:case rm:case am:return Math.ceil(o/4)*Math.ceil(e/4)*16;case om:case lm:return Math.ceil(o/4)*Math.ceil(e/4)*8;case Uu:case cm:return Math.ceil(o/4)*Math.ceil(e/4)*16}throw new Error(`Unable to determine texture byte length for ${t} format.`)}function SA(o){switch(o){case zn:case QM:return{byteLength:1,components:1};case Mh:case ew:case ci:return{byteLength:2,components:1};case cg:case hg:return{byteLength:2,components:4};case Ts:case lg:case En:return{byteLength:4,components:1};case tw:case iw:return{byteLength:4,components:3}}throw new Error(`THREE.TextureUtils: Unknown texture type ${o}.`)}typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:ag}}));typeof window<"u"&&(window.__THREE__?ke("WARNING: Multiple instances of Three.js being imported."):window.__THREE__=ag);/**
3163
+ }`;class Dt extends Ar{constructor(e){super(),this.isShaderMaterial=!0,this.type="ShaderMaterial",this.defines={},this.uniforms={},this.uniformsGroups=[],this.vertexShader=z3,this.fragmentShader=H3,this.linewidth=1,this.wireframe=!1,this.wireframeLinewidth=1,this.fog=!1,this.lights=!1,this.clipping=!1,this.forceSinglePass=!0,this.extensions={clipCullDistance:!1,multiDraw:!1},this.defaultAttributeValues={color:[1,1,1],uv:[0,0],uv1:[0,0]},this.index0AttributeName=void 0,this.uniformsNeedUpdate=!1,this.glslVersion=null,e!==void 0&&this.setValues(e)}copy(e){return super.copy(e),this.fragmentShader=e.fragmentShader,this.vertexShader=e.vertexShader,this.uniforms=lc(e.uniforms),this.uniformsGroups=U3(e.uniformsGroups),this.defines=Object.assign({},e.defines),this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.fog=e.fog,this.lights=e.lights,this.clipping=e.clipping,this.extensions=Object.assign({},e.extensions),this.glslVersion=e.glslVersion,this.defaultAttributeValues=Object.assign({},e.defaultAttributeValues),this.index0AttributeName=e.index0AttributeName,this.uniformsNeedUpdate=e.uniformsNeedUpdate,this}toJSON(e){const t=super.toJSON(e);t.glslVersion=this.glslVersion,t.uniforms={};for(const n in this.uniforms){const r=this.uniforms[n].value;r&&r.isTexture?t.uniforms[n]={type:"t",value:r.toJSON(e).uuid}:r&&r.isColor?t.uniforms[n]={type:"c",value:r.getHex()}:r&&r.isVector2?t.uniforms[n]={type:"v2",value:r.toArray()}:r&&r.isVector3?t.uniforms[n]={type:"v3",value:r.toArray()}:r&&r.isVector4?t.uniforms[n]={type:"v4",value:r.toArray()}:r&&r.isMatrix3?t.uniforms[n]={type:"m3",value:r.toArray()}:r&&r.isMatrix4?t.uniforms[n]={type:"m4",value:r.toArray()}:t.uniforms[n]={value:r}}Object.keys(this.defines).length>0&&(t.defines=this.defines),t.vertexShader=this.vertexShader,t.fragmentShader=this.fragmentShader,t.lights=this.lights,t.clipping=this.clipping;const i={};for(const n in this.extensions)this.extensions[n]===!0&&(i[n]=!0);return Object.keys(i).length>0&&(t.extensions=i),t}fromJSON(e,t){if(super.fromJSON(e,t),e.uniforms!==void 0)for(const i in e.uniforms){const n=e.uniforms[i];switch(this.uniforms[i]={},n.type){case"t":this.uniforms[i].value=t[n.value]||null;break;case"c":this.uniforms[i].value=new ne().setHex(n.value);break;case"v2":this.uniforms[i].value=new we().fromArray(n.value);break;case"v3":this.uniforms[i].value=new D().fromArray(n.value);break;case"v4":this.uniforms[i].value=new wt().fromArray(n.value);break;case"m3":this.uniforms[i].value=new Je().fromArray(n.value);break;case"m4":this.uniforms[i].value=new lt().fromArray(n.value);break;default:this.uniforms[i].value=n.value}}if(e.defines!==void 0&&(this.defines=e.defines),e.vertexShader!==void 0&&(this.vertexShader=e.vertexShader),e.fragmentShader!==void 0&&(this.fragmentShader=e.fragmentShader),e.glslVersion!==void 0&&(this.glslVersion=e.glslVersion),e.extensions!==void 0)for(const i in e.extensions)this.extensions[i]=e.extensions[i];return e.lights!==void 0&&(this.lights=e.lights),e.clipping!==void 0&&(this.clipping=e.clipping),this}}class yw extends Dt{constructor(e){super(e),this.isRawShaderMaterial=!0,this.type="RawShaderMaterial"}}class Ma extends Ar{constructor(e){super(),this.isMeshStandardMaterial=!0,this.type="MeshStandardMaterial",this.defines={STANDARD:""},this.color=new ne(16777215),this.roughness=1,this.metalness=0,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new ne(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=Hu,this.normalScale=new we(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.roughnessMap=null,this.metalnessMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new wr,this.envMapIntensity=1,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.defines={STANDARD:""},this.color.copy(e.color),this.roughness=e.roughness,this.metalness=e.metalness,this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.emissive.copy(e.emissive),this.emissiveMap=e.emissiveMap,this.emissiveIntensity=e.emissiveIntensity,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.roughnessMap=e.roughnessMap,this.metalnessMap=e.metalnessMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.envMapIntensity=e.envMapIntensity,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.flatShading=e.flatShading,this.fog=e.fog,this}}class G3 extends Ma{constructor(e){super(),this.isMeshPhysicalMaterial=!0,this.defines={STANDARD:"",PHYSICAL:""},this.type="MeshPhysicalMaterial",this.anisotropyRotation=0,this.anisotropyMap=null,this.clearcoatMap=null,this.clearcoatRoughness=0,this.clearcoatRoughnessMap=null,this.clearcoatNormalScale=new we(1,1),this.clearcoatNormalMap=null,this.ior=1.5,Object.defineProperty(this,"reflectivity",{get:function(){return nt(2.5*(this.ior-1)/(this.ior+1),0,1)},set:function(t){this.ior=(1+.4*t)/(1-.4*t)}}),this.iridescenceMap=null,this.iridescenceIOR=1.3,this.iridescenceThicknessRange=[100,400],this.iridescenceThicknessMap=null,this.sheenColor=new ne(0),this.sheenColorMap=null,this.sheenRoughness=1,this.sheenRoughnessMap=null,this.transmissionMap=null,this.thickness=0,this.thicknessMap=null,this.attenuationDistance=1/0,this.attenuationColor=new ne(1,1,1),this.specularIntensity=1,this.specularIntensityMap=null,this.specularColor=new ne(1,1,1),this.specularColorMap=null,this._anisotropy=0,this._clearcoat=0,this._dispersion=0,this._iridescence=0,this._sheen=0,this._transmission=0,this.setValues(e)}get anisotropy(){return this._anisotropy}set anisotropy(e){this._anisotropy>0!=e>0&&this.version++,this._anisotropy=e}get clearcoat(){return this._clearcoat}set clearcoat(e){this._clearcoat>0!=e>0&&this.version++,this._clearcoat=e}get iridescence(){return this._iridescence}set iridescence(e){this._iridescence>0!=e>0&&this.version++,this._iridescence=e}get dispersion(){return this._dispersion}set dispersion(e){this._dispersion>0!=e>0&&this.version++,this._dispersion=e}get sheen(){return this._sheen}set sheen(e){this._sheen>0!=e>0&&this.version++,this._sheen=e}get transmission(){return this._transmission}set transmission(e){this._transmission>0!=e>0&&this.version++,this._transmission=e}copy(e){return super.copy(e),this.defines={STANDARD:"",PHYSICAL:""},this.anisotropy=e.anisotropy,this.anisotropyRotation=e.anisotropyRotation,this.anisotropyMap=e.anisotropyMap,this.clearcoat=e.clearcoat,this.clearcoatMap=e.clearcoatMap,this.clearcoatRoughness=e.clearcoatRoughness,this.clearcoatRoughnessMap=e.clearcoatRoughnessMap,this.clearcoatNormalMap=e.clearcoatNormalMap,this.clearcoatNormalScale.copy(e.clearcoatNormalScale),this.dispersion=e.dispersion,this.ior=e.ior,this.iridescence=e.iridescence,this.iridescenceMap=e.iridescenceMap,this.iridescenceIOR=e.iridescenceIOR,this.iridescenceThicknessRange=[...e.iridescenceThicknessRange],this.iridescenceThicknessMap=e.iridescenceThicknessMap,this.sheen=e.sheen,this.sheenColor.copy(e.sheenColor),this.sheenColorMap=e.sheenColorMap,this.sheenRoughness=e.sheenRoughness,this.sheenRoughnessMap=e.sheenRoughnessMap,this.transmission=e.transmission,this.transmissionMap=e.transmissionMap,this.thickness=e.thickness,this.thicknessMap=e.thicknessMap,this.attenuationDistance=e.attenuationDistance,this.attenuationColor.copy(e.attenuationColor),this.specularIntensity=e.specularIntensity,this.specularIntensityMap=e.specularIntensityMap,this.specularColor.copy(e.specularColor),this.specularColorMap=e.specularColorMap,this}}class Oa extends Ar{constructor(e){super(),this.isMeshLambertMaterial=!0,this.type="MeshLambertMaterial",this.color=new ne(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new ne(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=Hu,this.normalScale=new we(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new wr,this.combine=og,this.reflectivity=1,this.envMapIntensity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.emissive.copy(e.emissive),this.emissiveMap=e.emissiveMap,this.emissiveIntensity=e.emissiveIntensity,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.specularMap=e.specularMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.combine=e.combine,this.reflectivity=e.reflectivity,this.envMapIntensity=e.envMapIntensity,this.refractionRatio=e.refractionRatio,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.flatShading=e.flatShading,this.fog=e.fog,this}}class V3 extends Ar{constructor(e){super(),this.isMeshDepthMaterial=!0,this.type="MeshDepthMaterial",this.depthPacking=LE,this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.setValues(e)}copy(e){return super.copy(e),this.depthPacking=e.depthPacking,this.map=e.map,this.alphaMap=e.alphaMap,this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this}}class W3 extends Ar{constructor(e){super(),this.isMeshDistanceMaterial=!0,this.type="MeshDistanceMaterial",this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.setValues(e)}copy(e){return super.copy(e),this.map=e.map,this.alphaMap=e.alphaMap,this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this}}function yd(o,e){return!o||o.constructor===e?o:typeof e.BYTES_PER_ELEMENT=="number"?new e(o):Array.prototype.slice.call(o)}function X3(o){function e(n,s){return o[n]-o[s]}const t=o.length,i=new Array(t);for(let n=0;n!==t;++n)i[n]=n;return i.sort(e),i}function B1(o,e,t){const i=o.length,n=new o.constructor(i);for(let s=0,r=0;r!==i;++s){const a=t[s]*e;for(let l=0;l!==e;++l)n[r++]=o[a+l]}return n}function $3(o,e,t,i){let n=1,s=o[0];for(;s!==void 0&&s[i]===void 0;)s=o[n++];if(s===void 0)return;let r=s[i];if(r!==void 0)if(Array.isArray(r))do r=s[i],r!==void 0&&(e.push(s.time),t.push(...r)),s=o[n++];while(s!==void 0);else if(r.toArray!==void 0)do r=s[i],r!==void 0&&(e.push(s.time),r.toArray(t,t.length)),s=o[n++];while(s!==void 0);else do r=s[i],r!==void 0&&(e.push(s.time),t.push(r)),s=o[n++];while(s!==void 0)}class kh{constructor(e,t,i,n){this.parameterPositions=e,this._cachedIndex=0,this.resultBuffer=n!==void 0?n:new t.constructor(i),this.sampleValues=t,this.valueSize=i,this.settings=null,this.DefaultSettings_={}}evaluate(e){const t=this.parameterPositions;let i=this._cachedIndex,n=t[i],s=t[i-1];e:{t:{let r;i:{n:if(!(e<n)){for(let a=i+2;;){if(n===void 0){if(e<s)break n;return i=t.length,this._cachedIndex=i,this.copySampleValue_(i-1)}if(i===a)break;if(s=n,n=t[++i],e<n)break t}r=t.length;break i}if(!(e>=s)){const a=t[1];e<a&&(i=2,s=a);for(let l=i-2;;){if(s===void 0)return this._cachedIndex=0,this.copySampleValue_(0);if(i===l)break;if(n=s,s=t[--i-1],e>=s)break t}r=i,i=0;break i}break e}for(;i<r;){const a=i+r>>>1;e<t[a]?r=a:i=a+1}if(n=t[i],s=t[i-1],s===void 0)return this._cachedIndex=0,this.copySampleValue_(0);if(n===void 0)return i=t.length,this._cachedIndex=i,this.copySampleValue_(i-1)}this._cachedIndex=i,this.intervalChanged_(i,s,n)}return this.interpolate_(i,s,e,n)}getSettings_(){return this.settings||this.DefaultSettings_}copySampleValue_(e){const t=this.resultBuffer,i=this.sampleValues,n=this.valueSize,s=e*n;for(let r=0;r!==n;++r)t[r]=i[s+r];return t}interpolate_(){throw new Error("THREE.Interpolant: Call to abstract method.")}intervalChanged_(){}}class Y3 extends kh{constructor(e,t,i,n){super(e,t,i,n),this._weightPrev=-0,this._offsetPrev=-0,this._weightNext=-0,this._offsetNext=-0,this.DefaultSettings_={endingStart:Tl,endingEnd:Tl}}intervalChanged_(e,t,i){const n=this.parameterPositions;let s=e-2,r=e+1,a=n[s],l=n[r];if(a===void 0)switch(this.getSettings_().endingStart){case Il:s=e,a=2*t-i;break;case zu:s=n.length-2,a=t+n[s]-n[s+1];break;default:s=e,a=i}if(l===void 0)switch(this.getSettings_().endingEnd){case Il:r=e,l=2*i-t;break;case zu:r=1,l=i+n[1]-n[0];break;default:r=e-1,l=t}const c=(i-t)*.5,h=this.valueSize;this._weightPrev=c/(t-a),this._weightNext=c/(l-i),this._offsetPrev=s*h,this._offsetNext=r*h}interpolate_(e,t,i,n){const s=this.resultBuffer,r=this.sampleValues,a=this.valueSize,l=e*a,c=l-a,h=this._offsetPrev,d=this._offsetNext,u=this._weightPrev,f=this._weightNext,p=(i-t)/(n-t),g=p*p,m=g*p,v=-u*m+2*u*g-u*p,b=(1+u)*m+(-1.5-2*u)*g+(-.5+u)*p+1,x=(-1-f)*m+(1.5+f)*g+.5*p,y=f*m-f*g;for(let w=0;w!==a;++w)s[w]=v*r[h+w]+b*r[c+w]+x*r[l+w]+y*r[d+w];return s}}class bw extends kh{constructor(e,t,i,n){super(e,t,i,n)}interpolate_(e,t,i,n){const s=this.resultBuffer,r=this.sampleValues,a=this.valueSize,l=e*a,c=l-a,h=(i-t)/(n-t),d=1-h;for(let u=0;u!==a;++u)s[u]=r[c+u]*d+r[l+u]*h;return s}}class q3 extends kh{constructor(e,t,i,n){super(e,t,i,n)}interpolate_(e){return this.copySampleValue_(e-1)}}class K3 extends kh{interpolate_(e,t,i,n){const s=this.resultBuffer,r=this.sampleValues,a=this.valueSize,l=e*a,c=l-a,h=this.inTangents,d=this.outTangents;if(!h||!d){const p=(i-t)/(n-t),g=1-p;for(let m=0;m!==a;++m)s[m]=r[c+m]*g+r[l+m]*p;return s}const u=a*2,f=e-1;for(let p=0;p!==a;++p){const g=r[c+p],m=r[l+p],v=f*u+p*2,b=d[v],x=d[v+1],y=e*u+p*2,w=h[y],S=h[y+1];let A=(i-t)/(n-t),M,_,I,R,L;for(let P=0;P<8;P++){M=A*A,_=M*A,I=1-A,R=I*I,L=R*I;const k=L*t+3*R*A*b+3*I*M*w+_*n-i;if(Math.abs(k)<1e-10)break;const F=3*R*(b-t)+6*I*A*(w-b)+3*M*(n-w);if(Math.abs(F)<1e-10)break;A=A-k/F,A=Math.max(0,Math.min(1,A))}s[p]=L*g+3*R*A*x+3*I*M*S+_*m}return s}}class Ys{constructor(e,t,i,n){if(e===void 0)throw new Error("THREE.KeyframeTrack: track name is undefined");if(t===void 0||t.length===0)throw new Error("THREE.KeyframeTrack: no keyframes in track named "+e);this.name=e,this.times=yd(t,this.TimeBufferType),this.values=yd(i,this.ValueBufferType),this.setInterpolation(n||this.DefaultInterpolation)}static toJSON(e){const t=e.constructor;let i;if(t.toJSON!==this.toJSON)i=t.toJSON(e);else{i={name:e.name,times:yd(e.times,Array),values:yd(e.values,Array)};const n=e.getInterpolation();n!==e.DefaultInterpolation&&(i.interpolation=n)}return i.type=e.ValueTypeName,i}InterpolantFactoryMethodDiscrete(e){return new q3(this.times,this.values,this.getValueSize(),e)}InterpolantFactoryMethodLinear(e){return new bw(this.times,this.values,this.getValueSize(),e)}InterpolantFactoryMethodSmooth(e){return new Y3(this.times,this.values,this.getValueSize(),e)}InterpolantFactoryMethodBezier(e){const t=new K3(this.times,this.values,this.getValueSize(),e);return this.settings&&(t.inTangents=this.settings.inTangents,t.outTangents=this.settings.outTangents),t}setInterpolation(e){let t;switch(e){case Bu:t=this.InterpolantFactoryMethodDiscrete;break;case hm:t=this.InterpolantFactoryMethodLinear;break;case $f:t=this.InterpolantFactoryMethodSmooth;break;case n1:t=this.InterpolantFactoryMethodBezier;break}if(t===void 0){const i="unsupported interpolation for "+this.ValueTypeName+" keyframe track named "+this.name;if(this.createInterpolant===void 0)if(e!==this.DefaultInterpolation)this.setInterpolation(this.DefaultInterpolation);else throw new Error(i);return ke("KeyframeTrack:",i),this}return this.createInterpolant=t,this}getInterpolation(){switch(this.createInterpolant){case this.InterpolantFactoryMethodDiscrete:return Bu;case this.InterpolantFactoryMethodLinear:return hm;case this.InterpolantFactoryMethodSmooth:return $f;case this.InterpolantFactoryMethodBezier:return n1}}getValueSize(){return this.values.length/this.times.length}shift(e){if(e!==0){const t=this.times;for(let i=0,n=t.length;i!==n;++i)t[i]+=e}return this}scale(e){if(e!==1){const t=this.times;for(let i=0,n=t.length;i!==n;++i)t[i]*=e}return this}trim(e,t){const i=this.times,n=i.length;let s=0,r=n-1;for(;s!==n&&i[s]<e;)++s;for(;r!==-1&&i[r]>t;)--r;if(++r,s!==0||r!==n){s>=r&&(r=Math.max(r,1),s=r-1);const a=this.getValueSize();this.times=i.slice(s,r),this.values=this.values.slice(s*a,r*a)}return this}validate(){let e=!0;const t=this.getValueSize();t-Math.floor(t)!==0&&(je("KeyframeTrack: Invalid value size in track.",this),e=!1);const i=this.times,n=this.values,s=i.length;s===0&&(je("KeyframeTrack: Track is empty.",this),e=!1);let r=null;for(let a=0;a!==s;a++){const l=i[a];if(typeof l=="number"&&isNaN(l)){je("KeyframeTrack: Time is not a valid number.",this,a,l),e=!1;break}if(r!==null&&r>l){je("KeyframeTrack: Out of order keys.",this,a,l,r),e=!1;break}r=l}if(n!==void 0&&VE(n))for(let a=0,l=n.length;a!==l;++a){const c=n[a];if(isNaN(c)){je("KeyframeTrack: Value is not a valid number.",this,a,c),e=!1;break}}return e}optimize(){const e=this.times.slice(),t=this.values.slice(),i=this.getValueSize(),n=this.getInterpolation()===$f,s=e.length-1;let r=1;for(let a=1;a<s;++a){let l=!1;const c=e[a],h=e[a+1];if(c!==h&&(a!==1||c!==e[0]))if(n)l=!0;else{const d=a*i,u=d-i,f=d+i;for(let p=0;p!==i;++p){const g=t[d+p];if(g!==t[u+p]||g!==t[f+p]){l=!0;break}}}if(l){if(a!==r){e[r]=e[a];const d=a*i,u=r*i;for(let f=0;f!==i;++f)t[u+f]=t[d+f]}++r}}if(s>0){e[r]=e[s];for(let a=s*i,l=r*i,c=0;c!==i;++c)t[l+c]=t[a+c];++r}return r!==e.length?(this.times=e.slice(0,r),this.values=t.slice(0,r*i)):(this.times=e,this.values=t),this}clone(){const e=this.times.slice(),t=this.values.slice(),i=this.constructor,n=new i(this.name,e,t);return n.createInterpolant=this.createInterpolant,n}}Ys.prototype.ValueTypeName="";Ys.prototype.TimeBufferType=Float32Array;Ys.prototype.ValueBufferType=Float32Array;Ys.prototype.DefaultInterpolation=hm;class fc extends Ys{constructor(e,t,i){super(e,t,i)}}fc.prototype.ValueTypeName="bool";fc.prototype.ValueBufferType=Array;fc.prototype.DefaultInterpolation=Bu;fc.prototype.InterpolantFactoryMethodLinear=void 0;fc.prototype.InterpolantFactoryMethodSmooth=void 0;class Mw extends Ys{constructor(e,t,i,n){super(e,t,i,n)}}Mw.prototype.ValueTypeName="color";class Ag extends Ys{constructor(e,t,i,n){super(e,t,i,n)}}Ag.prototype.ValueTypeName="number";class Z3 extends kh{constructor(e,t,i,n){super(e,t,i,n)}interpolate_(e,t,i,n){const s=this.resultBuffer,r=this.sampleValues,a=this.valueSize,l=(i-t)/(n-t);let c=e*a;for(let h=c+a;c!==h;c+=4)An.slerpFlat(s,0,r,c-a,r,c,l);return s}}class _g extends Ys{constructor(e,t,i,n){super(e,t,i,n)}InterpolantFactoryMethodLinear(e){return new Z3(this.times,this.values,this.getValueSize(),e)}}_g.prototype.ValueTypeName="quaternion";_g.prototype.InterpolantFactoryMethodSmooth=void 0;class pc extends Ys{constructor(e,t,i){super(e,t,i)}}pc.prototype.ValueTypeName="string";pc.prototype.ValueBufferType=Array;pc.prototype.DefaultInterpolation=Bu;pc.prototype.InterpolantFactoryMethodLinear=void 0;pc.prototype.InterpolantFactoryMethodSmooth=void 0;class ww extends Ys{constructor(e,t,i,n){super(e,t,i,n)}}ww.prototype.ValueTypeName="vector";class z1{constructor(e="",t=-1,i=[],n=pg){this.name=e,this.tracks=i,this.duration=t,this.blendMode=n,this.uuid=Ws(),this.userData={},this.duration<0&&this.resetDuration()}static parse(e){const t=[],i=e.tracks,n=1/(e.fps||1);for(let r=0,a=i.length;r!==a;++r)t.push(J3(i[r]).scale(n));const s=new this(e.name,e.duration,t,e.blendMode);return s.uuid=e.uuid,s.userData=JSON.parse(e.userData||"{}"),s}static toJSON(e){const t=[],i=e.tracks,n={name:e.name,duration:e.duration,tracks:t,uuid:e.uuid,blendMode:e.blendMode,userData:JSON.stringify(e.userData)};for(let s=0,r=i.length;s!==r;++s)t.push(Ys.toJSON(i[s]));return n}static CreateFromMorphTargetSequence(e,t,i,n){const s=t.length,r=[];for(let a=0;a<s;a++){let l=[],c=[];l.push((a+s-1)%s,a,(a+1)%s),c.push(0,1,0);const h=X3(l);l=B1(l,1,h),c=B1(c,1,h),!n&&l[0]===0&&(l.push(s),c.push(c[0])),r.push(new Ag(".morphTargetInfluences["+t[a].name+"]",l,c).scale(1/i))}return new this(e,-1,r)}static findByName(e,t){let i=e;if(!Array.isArray(e)){const n=e;i=n.geometry&&n.geometry.animations||n.animations}for(let n=0;n<i.length;n++)if(i[n].name===t)return i[n];return null}static CreateClipsFromMorphTargetSequences(e,t,i){const n={},s=/^([\w-]*?)([\d]+)$/;for(let a=0,l=e.length;a<l;a++){const c=e[a],h=c.name.match(s);if(h&&h.length>1){const d=h[1];let u=n[d];u||(n[d]=u=[]),u.push(c)}}const r=[];for(const a in n)r.push(this.CreateFromMorphTargetSequence(a,n[a],t,i));return r}resetDuration(){const e=this.tracks;let t=0;for(let i=0,n=e.length;i!==n;++i){const s=this.tracks[i];t=Math.max(t,s.times[s.times.length-1])}return this.duration=t,this}trim(){for(let e=0;e<this.tracks.length;e++)this.tracks[e].trim(0,this.duration);return this}validate(){let e=!0;for(let t=0;t<this.tracks.length;t++)e=e&&this.tracks[t].validate();return e}optimize(){for(let e=0;e<this.tracks.length;e++)this.tracks[e].optimize();return this}clone(){const e=[];for(let i=0;i<this.tracks.length;i++)e.push(this.tracks[i].clone());const t=new this.constructor(this.name,this.duration,e,this.blendMode);return t.userData=JSON.parse(JSON.stringify(this.userData)),t}toJSON(){return this.constructor.toJSON(this)}}function j3(o){switch(o.toLowerCase()){case"scalar":case"double":case"float":case"number":case"integer":return Ag;case"vector":case"vector2":case"vector3":case"vector4":return ww;case"color":return Mw;case"quaternion":return _g;case"bool":case"boolean":return fc;case"string":return pc}throw new Error("THREE.KeyframeTrack: Unsupported typeName: "+o)}function J3(o){if(o.type===void 0)throw new Error("THREE.KeyframeTrack: track type undefined, can not parse");const e=j3(o.type);if(o.times===void 0){const t=[],i=[];$3(o.keys,t,i,"value"),o.times=t,o.values=i}return e.parse!==void 0?e.parse(o):new e(o.name,o.times,o.values,o.interpolation)}const zr={enabled:!1,files:{},add:function(o,e){this.enabled!==!1&&(H1(o)||(this.files[o]=e))},get:function(o){if(this.enabled!==!1&&!H1(o))return this.files[o]},remove:function(o){delete this.files[o]},clear:function(){this.files={}}};function H1(o){try{const e=o.slice(o.indexOf(":")+1);return new URL(e).protocol==="blob:"}catch{return!1}}class Q3{constructor(e,t,i){const n=this;let s=!1,r=0,a=0,l;const c=[];this.onStart=void 0,this.onLoad=e,this.onProgress=t,this.onError=i,this._abortController=null,this.itemStart=function(h){a++,s===!1&&n.onStart!==void 0&&n.onStart(h,r,a),s=!0},this.itemEnd=function(h){r++,n.onProgress!==void 0&&n.onProgress(h,r,a),r===a&&(s=!1,n.onLoad!==void 0&&n.onLoad())},this.itemError=function(h){n.onError!==void 0&&n.onError(h)},this.resolveURL=function(h){return h=h.normalize("NFC"),l?l(h):h},this.setURLModifier=function(h){return l=h,this},this.addHandler=function(h,d){return c.push(h,d),this},this.removeHandler=function(h){const d=c.indexOf(h);return d!==-1&&c.splice(d,2),this},this.getHandler=function(h){for(let d=0,u=c.length;d<u;d+=2){const f=c[d],p=c[d+1];if(f.global&&(f.lastIndex=0),f.test(h))return p}return null},this.abort=function(){return this.abortController.abort(),this._abortController=null,this}}get abortController(){return this._abortController||(this._abortController=new AbortController),this._abortController}}const eA=new Q3;class Ph{constructor(e){this.manager=e!==void 0?e:eA,this.crossOrigin="anonymous",this.withCredentials=!1,this.path="",this.resourcePath="",this.requestHeader={},typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}load(){}loadAsync(e,t){const i=this;return new Promise(function(n,s){i.load(e,n,t,s)})}parse(){}setCrossOrigin(e){return this.crossOrigin=e,this}setWithCredentials(e){return this.withCredentials=e,this}setPath(e){return this.path=e,this}setResourcePath(e){return this.resourcePath=e,this}setRequestHeader(e){return this.requestHeader=e,this}abort(){return this}}Ph.DEFAULT_MATERIAL_NAME="__DEFAULT";const Cr={};class tA extends Error{constructor(e,t){super(e),this.response=t}}class qk extends Ph{constructor(e){super(e),this.mimeType="",this.responseType="",this._abortController=new AbortController}load(e,t,i,n){e===void 0&&(e=""),this.path!==void 0&&(e=this.path+e),e=this.manager.resolveURL(e);const s=zr.get(`file:${e}`);if(s!==void 0){this.manager.itemStart(e),setTimeout(()=>{t&&t(s),this.manager.itemEnd(e)},0);return}if(Cr[e]!==void 0){Cr[e].push({onLoad:t,onProgress:i,onError:n});return}Cr[e]=[],Cr[e].push({onLoad:t,onProgress:i,onError:n});const r=new Request(e,{headers:new Headers(this.requestHeader),credentials:this.withCredentials?"include":"same-origin",signal:typeof AbortSignal.any=="function"?AbortSignal.any([this._abortController.signal,this.manager.abortController.signal]):this._abortController.signal}),a=this.mimeType,l=this.responseType;fetch(r).then(c=>{if(c.status===200||c.status===0){if(c.status===0&&ke("FileLoader: HTTP Status 0 received."),typeof ReadableStream>"u"||c.body===void 0||c.body.getReader===void 0)return c;const h=Cr[e],d=c.body.getReader(),u=c.headers.get("X-File-Size")||c.headers.get("Content-Length"),f=u?parseInt(u):0,p=f!==0;let g=0;const m=new ReadableStream({start(v){b();function b(){d.read().then(({done:x,value:y})=>{if(x)v.close();else{g+=y.byteLength;const w=new ProgressEvent("progress",{lengthComputable:p,loaded:g,total:f});for(let S=0,A=h.length;S<A;S++){const M=h[S];M.onProgress&&M.onProgress(w)}v.enqueue(y),b()}},x=>{v.error(x)})}}});return new Response(m)}else throw new tA(`fetch for "${c.url}" responded with ${c.status}: ${c.statusText}`,c)}).then(c=>{switch(l){case"arraybuffer":return c.arrayBuffer();case"blob":return c.blob();case"document":return c.text().then(h=>new DOMParser().parseFromString(h,a));case"json":return c.json();default:if(a==="")return c.text();{const d=/charset="?([^;"\s]*)"?/i.exec(a),u=d&&d[1]?d[1].toLowerCase():void 0,f=new TextDecoder(u);return c.arrayBuffer().then(p=>f.decode(p))}}}).then(c=>{zr.add(`file:${e}`,c);const h=Cr[e];delete Cr[e];for(let d=0,u=h.length;d<u;d++){const f=h[d];f.onLoad&&f.onLoad(c)}}).catch(c=>{const h=Cr[e];if(h===void 0)throw this.manager.itemError(e),c;delete Cr[e];for(let d=0,u=h.length;d<u;d++){const f=h[d];f.onError&&f.onError(c)}this.manager.itemError(e)}).finally(()=>{this.manager.itemEnd(e)}),this.manager.itemStart(e)}setResponseType(e){return this.responseType=e,this}setMimeType(e){return this.mimeType=e,this}abort(){return this._abortController.abort(),this._abortController=new AbortController,this}}const cl=new WeakMap;class iA extends Ph{constructor(e){super(e)}load(e,t,i,n){this.path!==void 0&&(e=this.path+e),e=this.manager.resolveURL(e);const s=this,r=zr.get(`image:${e}`);if(r!==void 0){if(r.complete===!0)s.manager.itemStart(e),setTimeout(function(){t&&t(r),s.manager.itemEnd(e)},0);else{let d=cl.get(r);d===void 0&&(d=[],cl.set(r,d)),d.push({onLoad:t,onError:n})}return r}const a=Sh("img");function l(){h(),t&&t(this);const d=cl.get(this)||[];for(let u=0;u<d.length;u++){const f=d[u];f.onLoad&&f.onLoad(this)}cl.delete(this),s.manager.itemEnd(e)}function c(d){h(),n&&n(d),zr.remove(`image:${e}`);const u=cl.get(this)||[];for(let f=0;f<u.length;f++){const p=u[f];p.onError&&p.onError(d)}cl.delete(this),s.manager.itemError(e),s.manager.itemEnd(e)}function h(){a.removeEventListener("load",l,!1),a.removeEventListener("error",c,!1)}return a.addEventListener("load",l,!1),a.addEventListener("error",c,!1),e.slice(0,5)!=="data:"&&this.crossOrigin!==void 0&&(a.crossOrigin=this.crossOrigin),zr.add(`image:${e}`,a),s.manager.itemStart(e),a.src=e,a}}class Kk extends Ph{constructor(e){super(e)}load(e,t,i,n){const s=new ln,r=new iA(this.manager);return r.setCrossOrigin(this.crossOrigin),r.setPath(this.path),r.load(e,function(a){s.image=a,s.needsUpdate=!0,t!==void 0&&t(s)},i,n),s}}class Af extends hi{constructor(e,t=1){super(),this.isLight=!0,this.type="Light",this.color=new ne(e),this.intensity=t}dispose(){this.dispatchEvent({type:"dispose"})}copy(e,t){return super.copy(e,t),this.color.copy(e.color),this.intensity=e.intensity,this}toJSON(e){const t=super.toJSON(e);return t.object.color=this.color.getHex(),t.object.intensity=this.intensity,t}}class nA extends Af{constructor(e,t,i){super(e,i),this.isHemisphereLight=!0,this.type="HemisphereLight",this.position.copy(hi.DEFAULT_UP),this.updateMatrix(),this.groundColor=new ne(t)}copy(e,t){return super.copy(e,t),this.groundColor.copy(e.groundColor),this}toJSON(e){const t=super.toJSON(e);return t.object.groundColor=this.groundColor.getHex(),t}}const bp=new lt,G1=new D,V1=new D;class Tg{constructor(e){this.camera=e,this.intensity=1,this.bias=0,this.biasNode=null,this.normalBias=0,this.radius=1,this.blurSamples=8,this.mapSize=new we(512,512),this.mapType=zn,this.map=null,this.mapPass=null,this.matrix=new lt,this.autoUpdate=!0,this.needsUpdate=!1,this._frustum=new xg,this._frameExtents=new we(1,1),this._viewportCount=1,this._viewports=[new wt(0,0,1,1)]}getViewportCount(){return this._viewportCount}getFrustum(){return this._frustum}updateMatrices(e){const t=this.camera,i=this.matrix;G1.setFromMatrixPosition(e.matrixWorld),t.position.copy(G1),V1.setFromMatrixPosition(e.target.matrixWorld),t.lookAt(V1),t.updateMatrixWorld(),bp.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),this._frustum.setFromProjectionMatrix(bp,t.coordinateSystem,t.reversedDepth),t.coordinateSystem===xh||t.reversedDepth?i.set(.5,0,0,.5,0,.5,0,.5,0,0,1,0,0,0,0,1):i.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),i.multiply(bp)}getViewport(e){return this._viewports[e]}getFrameExtents(){return this._frameExtents}dispose(){this.map&&this.map.dispose(),this.mapPass&&this.mapPass.dispose()}copy(e){return this.camera=e.camera.clone(),this.intensity=e.intensity,this.bias=e.bias,this.radius=e.radius,this.autoUpdate=e.autoUpdate,this.needsUpdate=e.needsUpdate,this.normalBias=e.normalBias,this.blurSamples=e.blurSamples,this.mapSize.copy(e.mapSize),this.biasNode=e.biasNode,this}clone(){return new this.constructor().copy(this)}toJSON(){const e={};return this.intensity!==1&&(e.intensity=this.intensity),this.bias!==0&&(e.bias=this.bias),this.normalBias!==0&&(e.normalBias=this.normalBias),this.radius!==1&&(e.radius=this.radius),(this.mapSize.x!==512||this.mapSize.y!==512)&&(e.mapSize=this.mapSize.toArray()),e.camera=this.camera.toJSON(!1).object,delete e.camera.matrix,e}}const bd=new D,Md=new An,Js=new D;class xw extends hi{constructor(){super(),this.isCamera=!0,this.type="Camera",this.matrixWorldInverse=new lt,this.projectionMatrix=new lt,this.projectionMatrixInverse=new lt,this.coordinateSystem=vr,this._reversedDepth=!1}get reversedDepth(){return this._reversedDepth}copy(e,t){return super.copy(e,t),this.matrixWorldInverse.copy(e.matrixWorldInverse),this.projectionMatrix.copy(e.projectionMatrix),this.projectionMatrixInverse.copy(e.projectionMatrixInverse),this.coordinateSystem=e.coordinateSystem,this}getWorldDirection(e){return super.getWorldDirection(e).negate()}updateMatrixWorld(e){super.updateMatrixWorld(e),this.matrixWorld.decompose(bd,Md,Js),Js.x===1&&Js.y===1&&Js.z===1?this.matrixWorldInverse.copy(this.matrixWorld).invert():this.matrixWorldInverse.compose(bd,Md,Js.set(1,1,1)).invert()}updateWorldMatrix(e,t,i=!1){super.updateWorldMatrix(e,t,i),this.matrixWorld.decompose(bd,Md,Js),Js.x===1&&Js.y===1&&Js.z===1?this.matrixWorldInverse.copy(this.matrixWorld).invert():this.matrixWorldInverse.compose(bd,Md,Js.set(1,1,1)).invert()}clone(){return new this.constructor().copy(this)}}const sa=new D,W1=new we,X1=new we;class Qn extends xw{constructor(e=50,t=1,i=.1,n=2e3){super(),this.isPerspectiveCamera=!0,this.type="PerspectiveCamera",this.fov=e,this.zoom=1,this.near=i,this.far=n,this.focus=10,this.aspect=t,this.view=null,this.filmGauge=35,this.filmOffset=0,this.updateProjectionMatrix()}copy(e,t){return super.copy(e,t),this.fov=e.fov,this.zoom=e.zoom,this.near=e.near,this.far=e.far,this.focus=e.focus,this.aspect=e.aspect,this.view=e.view===null?null:Object.assign({},e.view),this.filmGauge=e.filmGauge,this.filmOffset=e.filmOffset,this}setFocalLength(e){const t=.5*this.getFilmHeight()/e;this.fov=oc*2*Math.atan(t),this.updateProjectionMatrix()}getFocalLength(){const e=Math.tan(jc*.5*this.fov);return .5*this.getFilmHeight()/e}getEffectiveFOV(){return oc*2*Math.atan(Math.tan(jc*.5*this.fov)/this.zoom)}getFilmWidth(){return this.filmGauge*Math.min(this.aspect,1)}getFilmHeight(){return this.filmGauge/Math.max(this.aspect,1)}getViewBounds(e,t,i){sa.set(-1,-1,.5).applyMatrix4(this.projectionMatrixInverse),t.set(sa.x,sa.y).multiplyScalar(-e/sa.z),sa.set(1,1,.5).applyMatrix4(this.projectionMatrixInverse),i.set(sa.x,sa.y).multiplyScalar(-e/sa.z)}getViewSize(e,t){return this.getViewBounds(e,W1,X1),t.subVectors(X1,W1)}setViewOffset(e,t,i,n,s,r){this.aspect=e/t,this.view===null&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=e,this.view.fullHeight=t,this.view.offsetX=i,this.view.offsetY=n,this.view.width=s,this.view.height=r,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const e=this.near;let t=e*Math.tan(jc*.5*this.fov)/this.zoom,i=2*t,n=this.aspect*i,s=-.5*n;const r=this.view;if(this.view!==null&&this.view.enabled){const l=r.fullWidth,c=r.fullHeight;s+=r.offsetX*n/l,t-=r.offsetY*i/c,n*=r.width/l,i*=r.height/c}const a=this.filmOffset;a!==0&&(s+=e*a/this.getFilmWidth()),this.projectionMatrix.makePerspective(s,s+n,t,t-i,e,this.far,this.coordinateSystem,this.reversedDepth),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(e){const t=super.toJSON(e);return t.object.fov=this.fov,t.object.zoom=this.zoom,t.object.near=this.near,t.object.far=this.far,t.object.focus=this.focus,t.object.aspect=this.aspect,this.view!==null&&(t.object.view=Object.assign({},this.view)),t.object.filmGauge=this.filmGauge,t.object.filmOffset=this.filmOffset,t}}class sA extends Tg{constructor(){super(new Qn(50,1,.5,500)),this.isSpotLightShadow=!0,this.focus=1,this.aspect=1}updateMatrices(e){const t=this.camera,i=oc*2*e.angle*this.focus,n=this.mapSize.width/this.mapSize.height*this.aspect,s=e.distance||t.far;(i!==t.fov||n!==t.aspect||s!==t.far)&&(t.fov=i,t.aspect=n,t.far=s,t.updateProjectionMatrix()),super.updateMatrices(e)}copy(e){return super.copy(e),this.focus=e.focus,this}}class Zk extends Af{constructor(e,t,i=0,n=Math.PI/3,s=0,r=2){super(e,t),this.isSpotLight=!0,this.type="SpotLight",this.position.copy(hi.DEFAULT_UP),this.updateMatrix(),this.target=new hi,this.distance=i,this.angle=n,this.penumbra=s,this.decay=r,this.map=null,this.shadow=new sA}get power(){return this.intensity*Math.PI}set power(e){this.intensity=e/Math.PI}dispose(){super.dispose(),this.shadow.dispose()}copy(e,t){return super.copy(e,t),this.distance=e.distance,this.angle=e.angle,this.penumbra=e.penumbra,this.decay=e.decay,this.target=e.target.clone(),this.map=e.map,this.shadow=e.shadow.clone(),this}toJSON(e){const t=super.toJSON(e);return t.object.distance=this.distance,t.object.angle=this.angle,t.object.decay=this.decay,t.object.penumbra=this.penumbra,t.object.target=this.target.uuid,this.map&&this.map.isTexture&&(t.object.map=this.map.toJSON(e).uuid),t.object.shadow=this.shadow.toJSON(),t}}class rA extends Tg{constructor(){super(new Qn(90,1,.5,500)),this.isPointLightShadow=!0}}class Sw extends Af{constructor(e,t,i=0,n=2){super(e,t),this.isPointLight=!0,this.type="PointLight",this.distance=i,this.decay=n,this.shadow=new rA}get power(){return this.intensity*4*Math.PI}set power(e){this.intensity=e/(4*Math.PI)}dispose(){super.dispose(),this.shadow.dispose()}copy(e,t){return super.copy(e,t),this.distance=e.distance,this.decay=e.decay,this.shadow=e.shadow.clone(),this}toJSON(e){const t=super.toJSON(e);return t.object.distance=this.distance,t.object.decay=this.decay,t.object.shadow=this.shadow.toJSON(),t}}class $s extends xw{constructor(e=-1,t=1,i=1,n=-1,s=.1,r=2e3){super(),this.isOrthographicCamera=!0,this.type="OrthographicCamera",this.zoom=1,this.view=null,this.left=e,this.right=t,this.top=i,this.bottom=n,this.near=s,this.far=r,this.updateProjectionMatrix()}copy(e,t){return super.copy(e,t),this.left=e.left,this.right=e.right,this.top=e.top,this.bottom=e.bottom,this.near=e.near,this.far=e.far,this.zoom=e.zoom,this.view=e.view===null?null:Object.assign({},e.view),this}setViewOffset(e,t,i,n,s,r){this.view===null&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=e,this.view.fullHeight=t,this.view.offsetX=i,this.view.offsetY=n,this.view.width=s,this.view.height=r,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const e=(this.right-this.left)/(2*this.zoom),t=(this.top-this.bottom)/(2*this.zoom),i=(this.right+this.left)/2,n=(this.top+this.bottom)/2;let s=i-e,r=i+e,a=n+t,l=n-t;if(this.view!==null&&this.view.enabled){const c=(this.right-this.left)/this.view.fullWidth/this.zoom,h=(this.top-this.bottom)/this.view.fullHeight/this.zoom;s+=c*this.view.offsetX,r=s+c*this.view.width,a-=h*this.view.offsetY,l=a-h*this.view.height}this.projectionMatrix.makeOrthographic(s,r,a,l,this.near,this.far,this.coordinateSystem,this.reversedDepth),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(e){const t=super.toJSON(e);return t.object.zoom=this.zoom,t.object.left=this.left,t.object.right=this.right,t.object.top=this.top,t.object.bottom=this.bottom,t.object.near=this.near,t.object.far=this.far,this.view!==null&&(t.object.view=Object.assign({},this.view)),t}}class aA extends Tg{constructor(){super(new $s(-5,5,5,-5,.5,500)),this.isDirectionalLightShadow=!0}}class $1 extends Af{constructor(e,t){super(e,t),this.isDirectionalLight=!0,this.type="DirectionalLight",this.position.copy(hi.DEFAULT_UP),this.updateMatrix(),this.target=new hi,this.shadow=new aA}dispose(){super.dispose(),this.shadow.dispose()}copy(e){return super.copy(e),this.target=e.target.clone(),this.shadow=e.shadow.clone(),this}toJSON(e){const t=super.toJSON(e);return t.object.shadow=this.shadow.toJSON(),t.object.target=this.target.uuid,t}}class jk{static extractUrlBase(e){const t=e.lastIndexOf("/");return t===-1?"./":e.slice(0,t+1)}static resolveURL(e,t){return typeof e!="string"||e===""?"":(/^https?:\/\//i.test(t)&&/^\//.test(e)&&(t=t.replace(/(^https?:\/\/[^\/]+).*/i,"$1")),/^(https?:)?\/\//i.test(e)||/^data:.*,.*$/i.test(e)||/^blob:.*$/i.test(e)?e:t+e)}}class Jk extends ot{constructor(){super(),this.isInstancedBufferGeometry=!0,this.type="InstancedBufferGeometry",this.instanceCount=1/0}copy(e){return super.copy(e),this.instanceCount=e.instanceCount,this}toJSON(){const e=super.toJSON();return e.instanceCount=this.instanceCount,e.isInstancedBufferGeometry=!0,e}}const Mp=new WeakMap;class Qk extends Ph{constructor(e){super(e),this.isImageBitmapLoader=!0,typeof createImageBitmap>"u"&&ke("ImageBitmapLoader: createImageBitmap() not supported."),typeof fetch>"u"&&ke("ImageBitmapLoader: fetch() not supported."),this.options={premultiplyAlpha:"none"},this._abortController=new AbortController}setOptions(e){return this.options=e,this}load(e,t,i,n){e===void 0&&(e=""),this.path!==void 0&&(e=this.path+e),e=this.manager.resolveURL(e);const s=this,r=zr.get(`image-bitmap:${e}`);if(r!==void 0){if(s.manager.itemStart(e),r.then){r.then(c=>{Mp.has(r)===!0?(n&&n(Mp.get(r)),s.manager.itemError(e),s.manager.itemEnd(e)):(t&&t(c),s.manager.itemEnd(e))});return}setTimeout(function(){t&&t(r),s.manager.itemEnd(e)},0);return}const a={};a.credentials=this.crossOrigin==="anonymous"?"same-origin":"include",a.headers=this.requestHeader,a.signal=typeof AbortSignal.any=="function"?AbortSignal.any([this._abortController.signal,this.manager.abortController.signal]):this._abortController.signal;const l=fetch(e,a).then(function(c){return c.blob()}).then(function(c){return createImageBitmap(c,Object.assign(s.options,{colorSpaceConversion:"none"}))}).then(function(c){zr.add(`image-bitmap:${e}`,c),t&&t(c),s.manager.itemEnd(e)}).catch(function(c){n&&n(c),Mp.set(l,c),zr.remove(`image-bitmap:${e}`),s.manager.itemError(e),s.manager.itemEnd(e)});zr.add(`image-bitmap:${e}`,l),s.manager.itemStart(e)}abort(){return this._abortController.abort(),this._abortController=new AbortController,this}}const hl=-90,dl=1;class Ig extends hi{constructor(e,t,i){super(),this.type="CubeCamera",this.renderTarget=i,this.coordinateSystem=null,this.activeMipmapLevel=0;const n=new Qn(hl,dl,e,t);n.layers=this.layers,this.add(n);const s=new Qn(hl,dl,e,t);s.layers=this.layers,this.add(s);const r=new Qn(hl,dl,e,t);r.layers=this.layers,this.add(r);const a=new Qn(hl,dl,e,t);a.layers=this.layers,this.add(a);const l=new Qn(hl,dl,e,t);l.layers=this.layers,this.add(l);const c=new Qn(hl,dl,e,t);c.layers=this.layers,this.add(c)}updateCoordinateSystem(){const e=this.coordinateSystem,t=this.children.concat(),[i,n,s,r,a,l]=t;for(const c of t)this.remove(c);if(e===vr)i.up.set(0,1,0),i.lookAt(1,0,0),n.up.set(0,1,0),n.lookAt(-1,0,0),s.up.set(0,0,-1),s.lookAt(0,1,0),r.up.set(0,0,1),r.lookAt(0,-1,0),a.up.set(0,1,0),a.lookAt(0,0,1),l.up.set(0,1,0),l.lookAt(0,0,-1);else if(e===xh)i.up.set(0,-1,0),i.lookAt(-1,0,0),n.up.set(0,-1,0),n.lookAt(1,0,0),s.up.set(0,0,1),s.lookAt(0,1,0),r.up.set(0,0,-1),r.lookAt(0,-1,0),a.up.set(0,-1,0),a.lookAt(0,0,1),l.up.set(0,-1,0),l.lookAt(0,0,-1);else throw new Error("THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: "+e);for(const c of t)this.add(c),c.updateMatrixWorld()}update(e,t){this.parent===null&&this.updateMatrixWorld();const{renderTarget:i,activeMipmapLevel:n}=this;this.coordinateSystem!==e.coordinateSystem&&(this.coordinateSystem=e.coordinateSystem,this.updateCoordinateSystem());const[s,r,a,l,c,h]=this.children,d=e.getRenderTarget(),u=e.getActiveCubeFace(),f=e.getActiveMipmapLevel(),p=e.xr.enabled;e.xr.enabled=!1;const g=i.texture.generateMipmaps;i.texture.generateMipmaps=!1;let m=!1;e.isWebGLRenderer===!0?m=e.state.buffers.depth.getReversed():m=e.reversedDepthBuffer,e.setRenderTarget(i,0,n),m&&e.autoClear===!1&&e.clearDepth(),e.render(t,s),e.setRenderTarget(i,1,n),m&&e.autoClear===!1&&e.clearDepth(),e.render(t,r),e.setRenderTarget(i,2,n),m&&e.autoClear===!1&&e.clearDepth(),e.render(t,a),e.setRenderTarget(i,3,n),m&&e.autoClear===!1&&e.clearDepth(),e.render(t,l),e.setRenderTarget(i,4,n),m&&e.autoClear===!1&&e.clearDepth(),e.render(t,c),i.texture.generateMipmaps=g,e.setRenderTarget(i,5,n),m&&e.autoClear===!1&&e.clearDepth(),e.render(t,h),e.setRenderTarget(d,u,f),e.xr.enabled=p,i.texture.needsPMREMUpdate=!0}}class oA extends Qn{constructor(e=[]){super(),this.isArrayCamera=!0,this.isMultiViewCamera=!1,this.cameras=e}}class lA{constructor(e,t,i){this.binding=e,this.valueSize=i;let n,s,r;switch(t){case"quaternion":n=this._slerp,s=this._slerpAdditive,r=this._setAdditiveIdentityQuaternion,this.buffer=new Float64Array(i*6),this._workIndex=5;break;case"string":case"bool":n=this._select,s=this._select,r=this._setAdditiveIdentityOther,this.buffer=new Array(i*5);break;default:n=this._lerp,s=this._lerpAdditive,r=this._setAdditiveIdentityNumeric,this.buffer=new Float64Array(i*5)}this._mixBufferRegion=n,this._mixBufferRegionAdditive=s,this._setIdentity=r,this._origIndex=3,this._addIndex=4,this.cumulativeWeight=0,this.cumulativeWeightAdditive=0,this.useCount=0,this.referenceCount=0}accumulate(e,t){const i=this.buffer,n=this.valueSize,s=e*n+n;let r=this.cumulativeWeight;if(r===0){for(let a=0;a!==n;++a)i[s+a]=i[a];r=t}else{r+=t;const a=t/r;this._mixBufferRegion(i,s,0,a,n)}this.cumulativeWeight=r}accumulateAdditive(e){const t=this.buffer,i=this.valueSize,n=i*this._addIndex;this.cumulativeWeightAdditive===0&&this._setIdentity(),this._mixBufferRegionAdditive(t,n,0,e,i),this.cumulativeWeightAdditive+=e}apply(e){const t=this.valueSize,i=this.buffer,n=e*t+t,s=this.cumulativeWeight,r=this.cumulativeWeightAdditive,a=this.binding;if(this.cumulativeWeight=0,this.cumulativeWeightAdditive=0,s<1){const l=t*this._origIndex;this._mixBufferRegion(i,n,l,1-s,t)}r>0&&this._mixBufferRegionAdditive(i,n,this._addIndex*t,1,t);for(let l=t,c=t+t;l!==c;++l)if(i[l]!==i[l+t]){a.setValue(i,n);break}}saveOriginalState(){const e=this.binding,t=this.buffer,i=this.valueSize,n=i*this._origIndex;e.getValue(t,n);for(let s=i,r=n;s!==r;++s)t[s]=t[n+s%i];this._setIdentity(),this.cumulativeWeight=0,this.cumulativeWeightAdditive=0}restoreOriginalState(){const e=this.valueSize*3;this.binding.setValue(this.buffer,e)}_setAdditiveIdentityNumeric(){const e=this._addIndex*this.valueSize,t=e+this.valueSize;for(let i=e;i<t;i++)this.buffer[i]=0}_setAdditiveIdentityQuaternion(){this._setAdditiveIdentityNumeric(),this.buffer[this._addIndex*this.valueSize+3]=1}_setAdditiveIdentityOther(){const e=this._origIndex*this.valueSize,t=this._addIndex*this.valueSize;for(let i=0;i<this.valueSize;i++)this.buffer[t+i]=this.buffer[e+i]}_select(e,t,i,n,s){if(n>=.5)for(let r=0;r!==s;++r)e[t+r]=e[i+r]}_slerp(e,t,i,n){An.slerpFlat(e,t,e,t,e,i,n)}_slerpAdditive(e,t,i,n,s){const r=this._workIndex*s;An.multiplyQuaternionsFlat(e,r,e,t,e,i),An.slerpFlat(e,t,e,t,e,r,n)}_lerp(e,t,i,n,s){const r=1-n;for(let a=0;a!==s;++a){const l=t+a;e[l]=e[l]*r+e[i+a]*n}}_lerpAdditive(e,t,i,n,s){for(let r=0;r!==s;++r){const a=t+r;e[a]=e[a]+e[i+r]*n}}}const Dg="\\[\\]\\.:\\/",cA=new RegExp("["+Dg+"]","g"),Rg="[^"+Dg+"]",hA="[^"+Dg.replace("\\.","")+"]",dA=/((?:WC+[\/:])*)/.source.replace("WC",Rg),uA=/(WCOD+)?/.source.replace("WCOD",hA),fA=/(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace("WC",Rg),pA=/\.(WC+)(?:\[(.+)\])?/.source.replace("WC",Rg),mA=new RegExp("^"+dA+uA+fA+pA+"$"),gA=["material","materials","bones","map"];class vA{constructor(e,t,i){const n=i||Kt.parseTrackName(t);this._targetGroup=e,this._bindings=e.subscribe_(t,n)}getValue(e,t){this.bind();const i=this._targetGroup.nCachedObjects_,n=this._bindings[i];n!==void 0&&n.getValue(e,t)}setValue(e,t){const i=this._bindings;for(let n=this._targetGroup.nCachedObjects_,s=i.length;n!==s;++n)i[n].setValue(e,t)}bind(){const e=this._bindings;for(let t=this._targetGroup.nCachedObjects_,i=e.length;t!==i;++t)e[t].bind()}unbind(){const e=this._bindings;for(let t=this._targetGroup.nCachedObjects_,i=e.length;t!==i;++t)e[t].unbind()}}class Kt{constructor(e,t,i){this.path=t,this.parsedPath=i||Kt.parseTrackName(t),this.node=Kt.findNode(e,this.parsedPath.nodeName),this.rootNode=e,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}static create(e,t,i){return e&&e.isAnimationObjectGroup?new Kt.Composite(e,t,i):new Kt(e,t,i)}static sanitizeNodeName(e){return e.replace(/\s/g,"_").replace(cA,"")}static parseTrackName(e){const t=mA.exec(e);if(t===null)throw new Error("THREE.PropertyBinding: Cannot parse trackName: "+e);const i={nodeName:t[2],objectName:t[3],objectIndex:t[4],propertyName:t[5],propertyIndex:t[6]},n=i.nodeName&&i.nodeName.lastIndexOf(".");if(n!==void 0&&n!==-1){const s=i.nodeName.substring(n+1);gA.indexOf(s)!==-1&&(i.nodeName=i.nodeName.substring(0,n),i.objectName=s)}if(i.propertyName===null||i.propertyName.length===0)throw new Error("THREE.PropertyBinding: can not parse propertyName from trackName: "+e);return i}static findNode(e,t){if(t===void 0||t===""||t==="."||t===-1||t===e.name||t===e.uuid)return e;if(e.skeleton){const i=e.skeleton.getBoneByName(t);if(i!==void 0)return i}if(e.children){const i=function(s){for(let r=0;r<s.length;r++){const a=s[r];if(a.name===t||a.uuid===t)return a;const l=i(a.children);if(l)return l}return null},n=i(e.children);if(n)return n}return null}_getValue_unavailable(){}_setValue_unavailable(){}_getValue_direct(e,t){e[t]=this.targetObject[this.propertyName]}_getValue_array(e,t){const i=this.resolvedProperty;for(let n=0,s=i.length;n!==s;++n)e[t++]=i[n]}_getValue_arrayElement(e,t){e[t]=this.resolvedProperty[this.propertyIndex]}_getValue_toArray(e,t){this.resolvedProperty.toArray(e,t)}_setValue_direct(e,t){this.targetObject[this.propertyName]=e[t]}_setValue_direct_setNeedsUpdate(e,t){this.targetObject[this.propertyName]=e[t],this.targetObject.needsUpdate=!0}_setValue_direct_setMatrixWorldNeedsUpdate(e,t){this.targetObject[this.propertyName]=e[t],this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_array(e,t){const i=this.resolvedProperty;for(let n=0,s=i.length;n!==s;++n)i[n]=e[t++]}_setValue_array_setNeedsUpdate(e,t){const i=this.resolvedProperty;for(let n=0,s=i.length;n!==s;++n)i[n]=e[t++];this.targetObject.needsUpdate=!0}_setValue_array_setMatrixWorldNeedsUpdate(e,t){const i=this.resolvedProperty;for(let n=0,s=i.length;n!==s;++n)i[n]=e[t++];this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_arrayElement(e,t){this.resolvedProperty[this.propertyIndex]=e[t]}_setValue_arrayElement_setNeedsUpdate(e,t){this.resolvedProperty[this.propertyIndex]=e[t],this.targetObject.needsUpdate=!0}_setValue_arrayElement_setMatrixWorldNeedsUpdate(e,t){this.resolvedProperty[this.propertyIndex]=e[t],this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_fromArray(e,t){this.resolvedProperty.fromArray(e,t)}_setValue_fromArray_setNeedsUpdate(e,t){this.resolvedProperty.fromArray(e,t),this.targetObject.needsUpdate=!0}_setValue_fromArray_setMatrixWorldNeedsUpdate(e,t){this.resolvedProperty.fromArray(e,t),this.targetObject.matrixWorldNeedsUpdate=!0}_getValue_unbound(e,t){this.bind(),this.getValue(e,t)}_setValue_unbound(e,t){this.bind(),this.setValue(e,t)}bind(){let e=this.node;const t=this.parsedPath,i=t.objectName,n=t.propertyName;let s=t.propertyIndex;if(e||(e=Kt.findNode(this.rootNode,t.nodeName),this.node=e),this.getValue=this._getValue_unavailable,this.setValue=this._setValue_unavailable,!e){ke("PropertyBinding: No target node found for track: "+this.path+".");return}if(i){let c=t.objectIndex;switch(i){case"materials":if(!e.material){je("PropertyBinding: Can not bind to material as node does not have a material.",this);return}if(!e.material.materials){je("PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.",this);return}e=e.material.materials;break;case"bones":if(!e.skeleton){je("PropertyBinding: Can not bind to bones as node does not have a skeleton.",this);return}e=e.skeleton.bones;for(let h=0;h<e.length;h++)if(e[h].name===c){c=h;break}break;case"map":if("map"in e){e=e.map;break}if(!e.material){je("PropertyBinding: Can not bind to material as node does not have a material.",this);return}if(!e.material.map){je("PropertyBinding: Can not bind to material.map as node.material does not have a map.",this);return}e=e.material.map;break;default:if(e[i]===void 0){je("PropertyBinding: Can not bind to objectName of node undefined.",this);return}e=e[i]}if(c!==void 0){if(e[c]===void 0){je("PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.",this,e);return}e=e[c]}}const r=e[n];if(r===void 0){const c=t.nodeName;je("PropertyBinding: Trying to update property for track: "+c+"."+n+" but it wasn't found.",e);return}let a=this.Versioning.None;this.targetObject=e,e.isMaterial===!0?a=this.Versioning.NeedsUpdate:e.isObject3D===!0&&(a=this.Versioning.MatrixWorldNeedsUpdate);let l=this.BindingType.Direct;if(s!==void 0){if(n==="morphTargetInfluences"){if(!e.geometry){je("PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.",this);return}if(!e.geometry.morphAttributes){je("PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.",this);return}e.morphTargetDictionary[s]!==void 0&&(s=e.morphTargetDictionary[s])}l=this.BindingType.ArrayElement,this.resolvedProperty=r,this.propertyIndex=s}else r.fromArray!==void 0&&r.toArray!==void 0?(l=this.BindingType.HasFromToArray,this.resolvedProperty=r):Array.isArray(r)?(l=this.BindingType.EntireArray,this.resolvedProperty=r):this.propertyName=n;this.getValue=this.GetterByBindingType[l],this.setValue=this.SetterByBindingTypeAndVersioning[l][a]}unbind(){this.node=null,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}}Kt.Composite=vA;Kt.prototype.BindingType={Direct:0,EntireArray:1,ArrayElement:2,HasFromToArray:3};Kt.prototype.Versioning={None:0,NeedsUpdate:1,MatrixWorldNeedsUpdate:2};Kt.prototype.GetterByBindingType=[Kt.prototype._getValue_direct,Kt.prototype._getValue_array,Kt.prototype._getValue_arrayElement,Kt.prototype._getValue_toArray];Kt.prototype.SetterByBindingTypeAndVersioning=[[Kt.prototype._setValue_direct,Kt.prototype._setValue_direct_setNeedsUpdate,Kt.prototype._setValue_direct_setMatrixWorldNeedsUpdate],[Kt.prototype._setValue_array,Kt.prototype._setValue_array_setNeedsUpdate,Kt.prototype._setValue_array_setMatrixWorldNeedsUpdate],[Kt.prototype._setValue_arrayElement,Kt.prototype._setValue_arrayElement_setNeedsUpdate,Kt.prototype._setValue_arrayElement_setMatrixWorldNeedsUpdate],[Kt.prototype._setValue_fromArray,Kt.prototype._setValue_fromArray_setNeedsUpdate,Kt.prototype._setValue_fromArray_setMatrixWorldNeedsUpdate]];class yA{constructor(e,t,i=null,n=t.blendMode){this._mixer=e,this._clip=t,this._localRoot=i,this.blendMode=n;const s=t.tracks,r=s.length,a=new Array(r),l={endingStart:Tl,endingEnd:Tl};for(let c=0;c!==r;++c){const h=s[c].createInterpolant(null);a[c]=h,h.settings=l}this._interpolantSettings=l,this._interpolants=a,this._propertyBindings=new Array(r),this._cacheIndex=null,this._byClipCacheIndex=null,this._timeScaleInterpolant=null,this._restoreTimeScale=null,this._weightInterpolant=null,this.loop=CE,this._loopCount=-1,this._startTime=null,this.time=0,this.timeScale=1,this._effectiveTimeScale=1,this.weight=1,this._effectiveWeight=1,this.repetitions=1/0,this.paused=!1,this.enabled=!0,this.clampWhenFinished=!1,this.zeroSlopeAtStart=!0,this.zeroSlopeAtEnd=!0}play(){return this._mixer._activateAction(this),this}stop(){return this._mixer._deactivateAction(this),this.reset()}reset(){return this.paused=!1,this.enabled=!0,this.time=0,this._loopCount=-1,this._startTime=null,this.stopFading().stopWarping()}isRunning(){return this.enabled&&!this.paused&&this.timeScale!==0&&this._startTime===null&&this._mixer._isActiveAction(this)}isScheduled(){return this._mixer._isActiveAction(this)}startAt(e){return this._startTime=e,this}setLoop(e,t){return this.loop=e,this.repetitions=t,this}setEffectiveWeight(e){return this.weight=e,this._effectiveWeight=this.enabled?e:0,this.stopFading()}getEffectiveWeight(){return this._effectiveWeight}fadeIn(e){return this._scheduleFading(e,0,1)}fadeOut(e){return this._scheduleFading(e,1,0)}crossFadeFrom(e,t,i=!1){if(e.fadeOut(t),this.fadeIn(t),i===!0){const n=this._clip.duration,s=e._clip.duration,r=s/n,a=n/s;e._restoreTimeScale=e.timeScale,this._restoreTimeScale=this.timeScale,e.warp(1,r,t),this.warp(a,1,t)}return this}crossFadeTo(e,t,i=!1){return e.crossFadeFrom(this,t,i)}stopFading(){const e=this._weightInterpolant;return e!==null&&(this._weightInterpolant=null,this._mixer._takeBackControlInterpolant(e)),this}setEffectiveTimeScale(e){return this.timeScale=e,this._effectiveTimeScale=this.paused?0:e,this.stopWarping()}getEffectiveTimeScale(){return this._effectiveTimeScale}setDuration(e){return this.timeScale=this._clip.duration/e,this.stopWarping()}syncWith(e){return this.time=e.time,this.timeScale=e.timeScale,this.stopWarping()}halt(e){return this.warp(this._effectiveTimeScale,0,e)}warp(e,t,i){const n=this._mixer,s=n.time,r=this.timeScale;let a=this._timeScaleInterpolant;a===null&&(a=n._lendControlInterpolant(),this._timeScaleInterpolant=a);const l=a.parameterPositions,c=a.sampleValues;return l[0]=s,l[1]=s+i,c[0]=e/r,c[1]=t/r,this}stopWarping(){const e=this._timeScaleInterpolant;return e!==null&&(this._timeScaleInterpolant=null,this._mixer._takeBackControlInterpolant(e)),this._restoreTimeScale=null,this}getMixer(){return this._mixer}getClip(){return this._clip}getRoot(){return this._localRoot||this._mixer._root}_update(e,t,i,n){if(!this.enabled){this._updateWeight(e);return}const s=this._startTime;if(s!==null){const l=(e-s)*i;l<0||i===0?t=0:(this._startTime=null,t=i*l)}t*=this._updateTimeScale(e);const r=this._updateTime(t),a=this._updateWeight(e);if(a>0){const l=this._interpolants,c=this._propertyBindings;switch(this.blendMode){case PE:for(let h=0,d=l.length;h!==d;++h)l[h].evaluate(r),c[h].accumulateAdditive(a);break;case pg:default:for(let h=0,d=l.length;h!==d;++h)l[h].evaluate(r),c[h].accumulate(n,a)}}}_updateWeight(e){let t=0;if(this.enabled){t=this.weight;const i=this._weightInterpolant;if(i!==null){const n=i.evaluate(e)[0];t*=n,e>i.parameterPositions[1]&&(this.stopFading(),n===0&&(this.enabled=!1))}}return this._effectiveWeight=t,t}_updateTimeScale(e){let t=0;if(!this.paused){t=this.timeScale;const i=this._timeScaleInterpolant;if(i!==null){const n=i.evaluate(e)[0];t*=n,e>i.parameterPositions[1]&&(t===0?this.paused=!0:(this._restoreTimeScale!==null&&(t=this._restoreTimeScale),this.timeScale=t),this.stopWarping())}}return this._effectiveTimeScale=t,t}_updateTime(e){const t=this._clip.duration,i=this.loop;let n=this.time+e,s=this._loopCount;const r=i===kE;if(e===0)return s===-1?n:r&&(s&1)===1?t-n:n;if(i===rw){s===-1&&(this._loopCount=0,this._setEndings(!0,!0,!1));e:{if(n>=t)n=t;else if(n<0)n=0;else{this.time=n;break e}this.clampWhenFinished?this.paused=!0:this.enabled=!1,this.time=n,this._mixer.dispatchEvent({type:"finished",action:this,direction:e<0?-1:1})}}else{if(s===-1&&(e>=0?(s=0,this._setEndings(!0,this.repetitions===0,r)):this._setEndings(this.repetitions===0,!0,r)),n>=t||n<0){const a=Math.floor(n/t);n-=t*a,s+=Math.abs(a);const l=this.repetitions-s;if(l<=0)this.clampWhenFinished?this.paused=!0:this.enabled=!1,n=e>0?t:0,this.time=n,this._mixer.dispatchEvent({type:"finished",action:this,direction:e>0?1:-1});else{if(l===1){const c=e<0;this._setEndings(c,!c,r)}else this._setEndings(!1,!1,r);this._loopCount=s,this.time=n,this._mixer.dispatchEvent({type:"loop",action:this,loopDelta:a})}}else this._loopCount=s,this.time=n;if(r&&(s&1)===1)return t-n}return n}_setEndings(e,t,i){const n=this._interpolantSettings;i?(n.endingStart=Il,n.endingEnd=Il):(e?n.endingStart=this.zeroSlopeAtStart?Il:Tl:n.endingStart=zu,t?n.endingEnd=this.zeroSlopeAtEnd?Il:Tl:n.endingEnd=zu)}_scheduleFading(e,t,i){const n=this._mixer,s=n.time;let r=this._weightInterpolant;r===null&&(r=n._lendControlInterpolant(),this._weightInterpolant=r);const a=r.parameterPositions,l=r.sampleValues;return a[0]=s,l[0]=t,a[1]=s+e,l[1]=i,this}}const bA=new Float32Array(1);class MA extends Na{constructor(e){super(),this._root=e,this._initMemoryManager(),this._accuIndex=0,this.time=0,this.timeScale=1,typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}_bindAction(e,t){const i=e._localRoot||this._root,n=e._clip.tracks,s=n.length,r=e._propertyBindings,a=e._interpolants,l=i.uuid,c=this._bindingsByRootAndName;let h=c[l];h===void 0&&(h={},c[l]=h);for(let d=0;d!==s;++d){const u=n[d],f=u.name;let p=h[f];if(p!==void 0)++p.referenceCount,r[d]=p;else{if(p=r[d],p!==void 0){p._cacheIndex===null&&(++p.referenceCount,this._addInactiveBinding(p,l,f));continue}const g=t&&t._propertyBindings[d].binding.parsedPath;p=new lA(Kt.create(i,f,g),u.ValueTypeName,u.getValueSize()),++p.referenceCount,this._addInactiveBinding(p,l,f),r[d]=p}a[d].resultBuffer=p.buffer}}_activateAction(e){if(!this._isActiveAction(e)){if(e._cacheIndex===null){const i=(e._localRoot||this._root).uuid,n=e._clip.uuid,s=this._actionsByClip[n];this._bindAction(e,s&&s.knownActions[0]),this._addInactiveAction(e,n,i)}const t=e._propertyBindings;for(let i=0,n=t.length;i!==n;++i){const s=t[i];s.useCount++===0&&(this._lendBinding(s),s.saveOriginalState())}this._lendAction(e)}}_deactivateAction(e){if(this._isActiveAction(e)){const t=e._propertyBindings;for(let i=0,n=t.length;i!==n;++i){const s=t[i];--s.useCount===0&&(s.restoreOriginalState(),this._takeBackBinding(s))}this._takeBackAction(e)}}_initMemoryManager(){this._actions=[],this._nActiveActions=0,this._actionsByClip={},this._bindings=[],this._nActiveBindings=0,this._bindingsByRootAndName={},this._controlInterpolants=[],this._nActiveControlInterpolants=0;const e=this;this.stats={actions:{get total(){return e._actions.length},get inUse(){return e._nActiveActions}},bindings:{get total(){return e._bindings.length},get inUse(){return e._nActiveBindings}},controlInterpolants:{get total(){return e._controlInterpolants.length},get inUse(){return e._nActiveControlInterpolants}}}}_isActiveAction(e){const t=e._cacheIndex;return t!==null&&t<this._nActiveActions}_addInactiveAction(e,t,i){const n=this._actions,s=this._actionsByClip;let r=s[t];if(r===void 0)r={knownActions:[e],actionByRoot:{}},e._byClipCacheIndex=0,s[t]=r;else{const a=r.knownActions;e._byClipCacheIndex=a.length,a.push(e)}e._cacheIndex=n.length,n.push(e),r.actionByRoot[i]=e}_removeInactiveAction(e){const t=this._actions,i=t[t.length-1],n=e._cacheIndex;i._cacheIndex=n,t[n]=i,t.pop(),e._cacheIndex=null;const s=e._clip.uuid,r=this._actionsByClip,a=r[s],l=a.knownActions,c=l[l.length-1],h=e._byClipCacheIndex;c._byClipCacheIndex=h,l[h]=c,l.pop(),e._byClipCacheIndex=null;const d=a.actionByRoot,u=(e._localRoot||this._root).uuid;delete d[u],l.length===0&&delete r[s],this._removeInactiveBindingsForAction(e)}_removeInactiveBindingsForAction(e){const t=e._propertyBindings;for(let i=0,n=t.length;i!==n;++i){const s=t[i];--s.referenceCount===0&&this._removeInactiveBinding(s)}}_lendAction(e){const t=this._actions,i=e._cacheIndex,n=this._nActiveActions++,s=t[n];e._cacheIndex=n,t[n]=e,s._cacheIndex=i,t[i]=s}_takeBackAction(e){const t=this._actions,i=e._cacheIndex,n=--this._nActiveActions,s=t[n];e._cacheIndex=n,t[n]=e,s._cacheIndex=i,t[i]=s}_addInactiveBinding(e,t,i){const n=this._bindingsByRootAndName,s=this._bindings;let r=n[t];r===void 0&&(r={},n[t]=r),r[i]=e,e._cacheIndex=s.length,s.push(e)}_removeInactiveBinding(e){const t=this._bindings,i=e.binding,n=i.rootNode.uuid,s=i.path,r=this._bindingsByRootAndName,a=r[n],l=t[t.length-1],c=e._cacheIndex;l._cacheIndex=c,t[c]=l,t.pop(),delete a[s],Object.keys(a).length===0&&delete r[n]}_lendBinding(e){const t=this._bindings,i=e._cacheIndex,n=this._nActiveBindings++,s=t[n];e._cacheIndex=n,t[n]=e,s._cacheIndex=i,t[i]=s}_takeBackBinding(e){const t=this._bindings,i=e._cacheIndex,n=--this._nActiveBindings,s=t[n];e._cacheIndex=n,t[n]=e,s._cacheIndex=i,t[i]=s}_lendControlInterpolant(){const e=this._controlInterpolants,t=this._nActiveControlInterpolants++;let i=e[t];return i===void 0&&(i=new bw(new Float32Array(2),new Float32Array(2),1,bA),i.__cacheIndex=t,e[t]=i),i}_takeBackControlInterpolant(e){const t=this._controlInterpolants,i=e.__cacheIndex,n=--this._nActiveControlInterpolants,s=t[n];e.__cacheIndex=n,t[n]=e,s.__cacheIndex=i,t[i]=s}clipAction(e,t,i){const n=t||this._root,s=n.uuid;let r=typeof e=="string"?z1.findByName(n,e):e;const a=r!==null?r.uuid:e,l=this._actionsByClip[a];let c=null;if(i===void 0&&(r!==null?i=r.blendMode:i=pg),l!==void 0){const d=l.actionByRoot[s];if(d!==void 0&&d.blendMode===i)return d;c=l.knownActions[0],r===null&&(r=c._clip)}if(r===null)return null;const h=new yA(this,r,t,i);return this._bindAction(h,c),this._addInactiveAction(h,a,s),h}existingAction(e,t){const i=t||this._root,n=i.uuid,s=typeof e=="string"?z1.findByName(i,e):e,r=s?s.uuid:e,a=this._actionsByClip[r];return a!==void 0&&a.actionByRoot[n]||null}stopAllAction(){const e=this._actions,t=this._nActiveActions;for(let i=t-1;i>=0;--i)e[i].stop();return this}update(e){e*=this.timeScale;const t=this._actions,i=this._nActiveActions,n=this.time+=e,s=Math.sign(e),r=this._accuIndex^=1;for(let c=0;c!==i;++c)t[c]._update(n,e,s,r);const a=this._bindings,l=this._nActiveBindings;for(let c=0;c!==l;++c)a[c].apply(r);return this}setTime(e){this.time=0;for(let t=0;t<this._actions.length;t++)this._actions[t].time=0;return this.update(e)}getRoot(){return this._root}uncacheClip(e){const t=this._actions,i=e.uuid,n=this._actionsByClip,s=n[i];if(s!==void 0){const r=s.knownActions;for(let a=0,l=r.length;a!==l;++a){const c=r[a];this._deactivateAction(c);const h=c._cacheIndex,d=t[t.length-1];c._cacheIndex=null,c._byClipCacheIndex=null,d._cacheIndex=h,t[h]=d,t.pop(),this._removeInactiveBindingsForAction(c)}delete n[i]}}uncacheRoot(e){const t=e.uuid,i=this._actionsByClip;for(const r in i){const a=i[r].actionByRoot,l=a[t];l!==void 0&&(this._deactivateAction(l),this._removeInactiveAction(l))}const n=this._bindingsByRootAndName,s=n[t];if(s!==void 0)for(const r in s){const a=s[r];a.restoreOriginalState(),this._removeInactiveBinding(a)}}uncacheAction(e,t){const i=this.existingAction(e,t);i!==null&&(this._deactivateAction(i),this._removeInactiveAction(i))}}class eP extends dw{constructor(e,t,i=1){super(e,t),this.isInstancedInterleavedBuffer=!0,this.meshPerAttribute=i}copy(e){return super.copy(e),this.meshPerAttribute=e.meshPerAttribute,this}clone(e){const t=super.clone(e);return t.meshPerAttribute=this.meshPerAttribute,t}toJSON(e){const t=super.toJSON(e);return t.isInstancedInterleavedBuffer=!0,t.meshPerAttribute=this.meshPerAttribute,t}}const Y1=new lt;class tu{constructor(e,t,i=0,n=1/0){this.ray=new Ch(e,t),this.near=i,this.far=n,this.camera=null,this.layers=new bg,this.params={Mesh:{},Line:{threshold:1},LOD:{},Points:{threshold:1},Sprite:{}}}set(e,t){this.ray.set(e,t)}setFromCamera(e,t){t.isPerspectiveCamera?(this.ray.origin.setFromMatrixPosition(t.matrixWorld),this.ray.direction.set(e.x,e.y,.5).unproject(t).sub(this.ray.origin).normalize(),this.camera=t):t.isOrthographicCamera?(this.ray.origin.set(e.x,e.y,t.projectionMatrix.elements[14]).unproject(t),this.ray.direction.set(0,0,-1).transformDirection(t.matrixWorld),this.camera=t):je("Raycaster: Unsupported camera type: "+t.type)}setFromXRController(e){return Y1.identity().extractRotation(e.matrixWorld),this.ray.origin.setFromMatrixPosition(e.matrixWorld),this.ray.direction.set(0,0,-1).applyMatrix4(Y1),this}intersectObject(e,t=!0,i=[]){return pm(e,this,i,t),i.sort(q1),i}intersectObjects(e,t=!0,i=[]){for(let n=0,s=e.length;n<s;n++)pm(e[n],this,i,t);return i.sort(q1),i}}function q1(o,e){return o.distance-e.distance}function pm(o,e,t,i){let n=!0;if(o.layers.test(e.layers)&&o.raycast(e,t)===!1&&(n=!1),n===!0&&i===!0){const s=o.children;for(let r=0,a=s.length;r<a;r++)pm(s[r],e,t,!0)}}class Ew{static{Ew.prototype.isMatrix2=!0}constructor(e,t,i,n){this.elements=[1,0,0,1],e!==void 0&&this.set(e,t,i,n)}identity(){return this.set(1,0,0,1),this}fromArray(e,t=0){for(let i=0;i<4;i++)this.elements[i]=e[i+t];return this}set(e,t,i,n){const s=this.elements;return s[0]=e,s[2]=t,s[1]=i,s[3]=n,this}}const K1=new D,wd=new D,ul=new D,fl=new D,wp=new D,wA=new D,xA=new D;class tP{constructor(e=new D,t=new D){this.start=e,this.end=t}set(e,t){return this.start.copy(e),this.end.copy(t),this}copy(e){return this.start.copy(e.start),this.end.copy(e.end),this}getCenter(e){return e.addVectors(this.start,this.end).multiplyScalar(.5)}delta(e){return e.subVectors(this.end,this.start)}distanceSq(){return this.start.distanceToSquared(this.end)}distance(){return this.start.distanceTo(this.end)}at(e,t){return this.delta(t).multiplyScalar(e).add(this.start)}closestPointToPointParameter(e,t){K1.subVectors(e,this.start),wd.subVectors(this.end,this.start);const i=wd.dot(wd);if(i===0)return 0;let s=wd.dot(K1)/i;return t&&(s=nt(s,0,1)),s}closestPointToPoint(e,t,i){const n=this.closestPointToPointParameter(e,t);return this.delta(i).multiplyScalar(n).add(this.start)}distanceSqToLine3(e,t=wA,i=xA){const n=10000000000000001e-32;let s,r;const a=this.start,l=e.start,c=this.end,h=e.end;ul.subVectors(c,a),fl.subVectors(h,l),wp.subVectors(a,l);const d=ul.dot(ul),u=fl.dot(fl),f=fl.dot(wp);if(d<=n&&u<=n)return t.copy(a),i.copy(l),t.sub(i),t.dot(t);if(d<=n)s=0,r=f/u,r=nt(r,0,1);else{const p=ul.dot(wp);if(u<=n)r=0,s=nt(-p/d,0,1);else{const g=ul.dot(fl),m=d*u-g*g;m!==0?s=nt((g*f-p*u)/m,0,1):s=0,r=(g*s+f)/u,r<0?(r=0,s=nt(-p/d,0,1)):r>1&&(r=1,s=nt((g-p)/d,0,1))}}return t.copy(a).addScaledVector(ul,s),i.copy(l).addScaledVector(fl,r),t.distanceToSquared(i)}applyMatrix4(e){return this.start.applyMatrix4(e),this.end.applyMatrix4(e),this}equals(e){return e.start.equals(this.start)&&e.end.equals(this.end)}clone(){return new this.constructor().copy(this)}}function Z1(o,e,t,i){const n=SA(i);switch(t){case nw:return o*e;case ac:return o*e/n.components*n.byteLength;case dg:return o*e/n.components*n.byteLength;case Fo:return o*e*2/n.components*n.byteLength;case ug:return o*e*2/n.components*n.byteLength;case sw:return o*e*3/n.components*n.byteLength;case Vi:return o*e*4/n.components*n.byteLength;case fg:return o*e*4/n.components*n.byteLength;case Zd:case jd:return Math.floor((o+3)/4)*Math.floor((e+3)/4)*8;case Jd:case Qd:return Math.floor((o+3)/4)*Math.floor((e+3)/4)*16;case O0:case F0:return Math.max(o,16)*Math.max(e,8)/4;case L0:case N0:return Math.max(o,8)*Math.max(e,8)/2;case U0:case B0:case H0:case G0:return Math.floor((o+3)/4)*Math.floor((e+3)/4)*8;case z0:case Fu:case V0:return Math.floor((o+3)/4)*Math.floor((e+3)/4)*16;case W0:return Math.floor((o+3)/4)*Math.floor((e+3)/4)*16;case X0:return Math.floor((o+4)/5)*Math.floor((e+3)/4)*16;case $0:return Math.floor((o+4)/5)*Math.floor((e+4)/5)*16;case Y0:return Math.floor((o+5)/6)*Math.floor((e+4)/5)*16;case q0:return Math.floor((o+5)/6)*Math.floor((e+5)/6)*16;case K0:return Math.floor((o+7)/8)*Math.floor((e+4)/5)*16;case Z0:return Math.floor((o+7)/8)*Math.floor((e+5)/6)*16;case j0:return Math.floor((o+7)/8)*Math.floor((e+7)/8)*16;case J0:return Math.floor((o+9)/10)*Math.floor((e+4)/5)*16;case Q0:return Math.floor((o+9)/10)*Math.floor((e+5)/6)*16;case em:return Math.floor((o+9)/10)*Math.floor((e+7)/8)*16;case tm:return Math.floor((o+9)/10)*Math.floor((e+9)/10)*16;case im:return Math.floor((o+11)/12)*Math.floor((e+9)/10)*16;case nm:return Math.floor((o+11)/12)*Math.floor((e+11)/12)*16;case sm:case rm:case am:return Math.ceil(o/4)*Math.ceil(e/4)*16;case om:case lm:return Math.ceil(o/4)*Math.ceil(e/4)*8;case Uu:case cm:return Math.ceil(o/4)*Math.ceil(e/4)*16}throw new Error(`Unable to determine texture byte length for ${t} format.`)}function SA(o){switch(o){case zn:case QM:return{byteLength:1,components:1};case Mh:case ew:case ci:return{byteLength:2,components:1};case cg:case hg:return{byteLength:2,components:4};case Ts:case lg:case En:return{byteLength:4,components:1};case tw:case iw:return{byteLength:4,components:3}}throw new Error(`THREE.TextureUtils: Unknown texture type ${o}.`)}typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:ag}}));typeof window<"u"&&(window.__THREE__?ke("WARNING: Multiple instances of Three.js being imported."):window.__THREE__=ag);/**
3164
3164
  * @license
3165
3165
  * Copyright 2010-2026 Three.js Authors
3166
3166
  * SPDX-License-Identifier: MIT
@@ -6830,7 +6830,7 @@ void main() {
6830
6830
  #include <tonemapping_fragment>
6831
6831
  #include <colorspace_fragment>
6832
6832
  #include <fog_fragment>
6833
- }`,tt={alphahash_fragment:AA,alphahash_pars_fragment:_A,alphamap_fragment:TA,alphamap_pars_fragment:IA,alphatest_fragment:DA,alphatest_pars_fragment:RA,aomap_fragment:CA,aomap_pars_fragment:kA,batching_pars_vertex:PA,batching_vertex:LA,begin_vertex:OA,beginnormal_vertex:NA,bsdfs:FA,iridescence_fragment:UA,bumpmap_pars_fragment:BA,clipping_planes_fragment:zA,clipping_planes_pars_fragment:HA,clipping_planes_pars_vertex:GA,clipping_planes_vertex:VA,color_fragment:WA,color_pars_fragment:XA,color_pars_vertex:$A,color_vertex:YA,common:qA,cube_uv_reflection_fragment:KA,defaultnormal_vertex:ZA,displacementmap_pars_vertex:jA,displacementmap_vertex:JA,emissivemap_fragment:QA,emissivemap_pars_fragment:e_,colorspace_fragment:t_,colorspace_pars_fragment:i_,envmap_fragment:n_,envmap_common_pars_fragment:s_,envmap_pars_fragment:r_,envmap_pars_vertex:a_,envmap_physical_pars_fragment:v_,envmap_vertex:o_,fog_vertex:l_,fog_pars_vertex:c_,fog_fragment:h_,fog_pars_fragment:d_,gradientmap_pars_fragment:u_,lightmap_pars_fragment:f_,lights_lambert_fragment:p_,lights_lambert_pars_fragment:m_,lights_pars_begin:g_,lights_toon_fragment:y_,lights_toon_pars_fragment:b_,lights_phong_fragment:M_,lights_phong_pars_fragment:w_,lights_physical_fragment:x_,lights_physical_pars_fragment:S_,lights_fragment_begin:E_,lights_fragment_maps:A_,lights_fragment_end:__,lightprobes_pars_fragment:T_,logdepthbuf_fragment:I_,logdepthbuf_pars_fragment:D_,logdepthbuf_pars_vertex:R_,logdepthbuf_vertex:C_,map_fragment:k_,map_pars_fragment:P_,map_particle_fragment:L_,map_particle_pars_fragment:O_,metalnessmap_fragment:N_,metalnessmap_pars_fragment:F_,morphinstance_vertex:U_,morphcolor_vertex:B_,morphnormal_vertex:z_,morphtarget_pars_vertex:H_,morphtarget_vertex:G_,normal_fragment_begin:V_,normal_fragment_maps:W_,normal_pars_fragment:X_,normal_pars_vertex:$_,normal_vertex:Y_,normalmap_pars_fragment:q_,clearcoat_normal_fragment_begin:K_,clearcoat_normal_fragment_maps:Z_,clearcoat_pars_fragment:j_,iridescence_pars_fragment:J_,opaque_fragment:Q_,packing:eT,premultiplied_alpha_fragment:tT,project_vertex:iT,dithering_fragment:nT,dithering_pars_fragment:sT,roughnessmap_fragment:rT,roughnessmap_pars_fragment:aT,shadowmap_pars_fragment:oT,shadowmap_pars_vertex:lT,shadowmap_vertex:cT,shadowmask_pars_fragment:hT,skinbase_vertex:dT,skinning_pars_vertex:uT,skinning_vertex:fT,skinnormal_vertex:pT,specularmap_fragment:mT,specularmap_pars_fragment:gT,tonemapping_fragment:vT,tonemapping_pars_fragment:yT,transmission_fragment:bT,transmission_pars_fragment:MT,uv_pars_fragment:wT,uv_pars_vertex:xT,uv_vertex:ST,worldpos_vertex:ET,background_vert:AT,background_frag:_T,backgroundCube_vert:TT,backgroundCube_frag:IT,cube_vert:DT,cube_frag:RT,depth_vert:CT,depth_frag:kT,distance_vert:PT,distance_frag:LT,equirect_vert:OT,equirect_frag:NT,linedashed_vert:FT,linedashed_frag:UT,meshbasic_vert:BT,meshbasic_frag:zT,meshlambert_vert:HT,meshlambert_frag:GT,meshmatcap_vert:VT,meshmatcap_frag:WT,meshnormal_vert:XT,meshnormal_frag:$T,meshphong_vert:YT,meshphong_frag:qT,meshphysical_vert:KT,meshphysical_frag:ZT,meshtoon_vert:jT,meshtoon_frag:JT,points_vert:QT,points_frag:e5,shadow_vert:t5,shadow_frag:i5,sprite_vert:n5,sprite_frag:s5},ye={common:{diffuse:{value:new ne(16777215)},opacity:{value:1},map:{value:null},mapTransform:{value:new je},alphaMap:{value:null},alphaMapTransform:{value:new je},alphaTest:{value:0}},specularmap:{specularMap:{value:null},specularMapTransform:{value:new je}},envmap:{envMap:{value:null},envMapRotation:{value:new je},reflectivity:{value:1},ior:{value:1.5},refractionRatio:{value:.98},dfgLUT:{value:null}},aomap:{aoMap:{value:null},aoMapIntensity:{value:1},aoMapTransform:{value:new je}},lightmap:{lightMap:{value:null},lightMapIntensity:{value:1},lightMapTransform:{value:new je}},bumpmap:{bumpMap:{value:null},bumpMapTransform:{value:new je},bumpScale:{value:1}},normalmap:{normalMap:{value:null},normalMapTransform:{value:new je},normalScale:{value:new we(1,1)}},displacementmap:{displacementMap:{value:null},displacementMapTransform:{value:new je},displacementScale:{value:1},displacementBias:{value:0}},emissivemap:{emissiveMap:{value:null},emissiveMapTransform:{value:new je}},metalnessmap:{metalnessMap:{value:null},metalnessMapTransform:{value:new je}},roughnessmap:{roughnessMap:{value:null},roughnessMapTransform:{value:new je}},gradientmap:{gradientMap:{value:null}},fog:{fogDensity:{value:25e-5},fogNear:{value:1},fogFar:{value:2e3},fogColor:{value:new ne(16777215)}},lights:{ambientLightColor:{value:[]},lightProbe:{value:[]},directionalLights:{value:[],properties:{direction:{},color:{}}},directionalLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},directionalShadowMatrix:{value:[]},spotLights:{value:[],properties:{color:{},position:{},direction:{},distance:{},coneCos:{},penumbraCos:{},decay:{}}},spotLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},spotLightMap:{value:[]},spotLightMatrix:{value:[]},pointLights:{value:[],properties:{color:{},position:{},decay:{},distance:{}}},pointLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{},shadowCameraNear:{},shadowCameraFar:{}}},pointShadowMatrix:{value:[]},hemisphereLights:{value:[],properties:{direction:{},skyColor:{},groundColor:{}}},rectAreaLights:{value:[],properties:{color:{},position:{},width:{},height:{}}},ltc_1:{value:null},ltc_2:{value:null},probesSH:{value:null},probesMin:{value:new D},probesMax:{value:new D},probesResolution:{value:new D}},points:{diffuse:{value:new ne(16777215)},opacity:{value:1},size:{value:1},scale:{value:1},map:{value:null},alphaMap:{value:null},alphaMapTransform:{value:new je},alphaTest:{value:0},uvTransform:{value:new je}},sprite:{diffuse:{value:new ne(16777215)},opacity:{value:1},center:{value:new we(.5,.5)},rotation:{value:0},map:{value:null},mapTransform:{value:new je},alphaMap:{value:null},alphaMapTransform:{value:new je},alphaTest:{value:0}}},lr={basic:{uniforms:Tn([ye.common,ye.specularmap,ye.envmap,ye.aomap,ye.lightmap,ye.fog]),vertexShader:tt.meshbasic_vert,fragmentShader:tt.meshbasic_frag},lambert:{uniforms:Tn([ye.common,ye.specularmap,ye.envmap,ye.aomap,ye.lightmap,ye.emissivemap,ye.bumpmap,ye.normalmap,ye.displacementmap,ye.fog,ye.lights,{emissive:{value:new ne(0)},envMapIntensity:{value:1}}]),vertexShader:tt.meshlambert_vert,fragmentShader:tt.meshlambert_frag},phong:{uniforms:Tn([ye.common,ye.specularmap,ye.envmap,ye.aomap,ye.lightmap,ye.emissivemap,ye.bumpmap,ye.normalmap,ye.displacementmap,ye.fog,ye.lights,{emissive:{value:new ne(0)},specular:{value:new ne(1118481)},shininess:{value:30},envMapIntensity:{value:1}}]),vertexShader:tt.meshphong_vert,fragmentShader:tt.meshphong_frag},standard:{uniforms:Tn([ye.common,ye.envmap,ye.aomap,ye.lightmap,ye.emissivemap,ye.bumpmap,ye.normalmap,ye.displacementmap,ye.roughnessmap,ye.metalnessmap,ye.fog,ye.lights,{emissive:{value:new ne(0)},roughness:{value:1},metalness:{value:0},envMapIntensity:{value:1}}]),vertexShader:tt.meshphysical_vert,fragmentShader:tt.meshphysical_frag},toon:{uniforms:Tn([ye.common,ye.aomap,ye.lightmap,ye.emissivemap,ye.bumpmap,ye.normalmap,ye.displacementmap,ye.gradientmap,ye.fog,ye.lights,{emissive:{value:new ne(0)}}]),vertexShader:tt.meshtoon_vert,fragmentShader:tt.meshtoon_frag},matcap:{uniforms:Tn([ye.common,ye.bumpmap,ye.normalmap,ye.displacementmap,ye.fog,{matcap:{value:null}}]),vertexShader:tt.meshmatcap_vert,fragmentShader:tt.meshmatcap_frag},points:{uniforms:Tn([ye.points,ye.fog]),vertexShader:tt.points_vert,fragmentShader:tt.points_frag},dashed:{uniforms:Tn([ye.common,ye.fog,{scale:{value:1},dashSize:{value:1},totalSize:{value:2}}]),vertexShader:tt.linedashed_vert,fragmentShader:tt.linedashed_frag},depth:{uniforms:Tn([ye.common,ye.displacementmap]),vertexShader:tt.depth_vert,fragmentShader:tt.depth_frag},normal:{uniforms:Tn([ye.common,ye.bumpmap,ye.normalmap,ye.displacementmap,{opacity:{value:1}}]),vertexShader:tt.meshnormal_vert,fragmentShader:tt.meshnormal_frag},sprite:{uniforms:Tn([ye.sprite,ye.fog]),vertexShader:tt.sprite_vert,fragmentShader:tt.sprite_frag},background:{uniforms:{uvTransform:{value:new je},t2D:{value:null},backgroundIntensity:{value:1}},vertexShader:tt.background_vert,fragmentShader:tt.background_frag},backgroundCube:{uniforms:{envMap:{value:null},backgroundBlurriness:{value:0},backgroundIntensity:{value:1},backgroundRotation:{value:new je}},vertexShader:tt.backgroundCube_vert,fragmentShader:tt.backgroundCube_frag},cube:{uniforms:{tCube:{value:null},tFlip:{value:-1},opacity:{value:1}},vertexShader:tt.cube_vert,fragmentShader:tt.cube_frag},equirect:{uniforms:{tEquirect:{value:null}},vertexShader:tt.equirect_vert,fragmentShader:tt.equirect_frag},distance:{uniforms:Tn([ye.common,ye.displacementmap,{referencePosition:{value:new D},nearDistance:{value:1},farDistance:{value:1e3}}]),vertexShader:tt.distance_vert,fragmentShader:tt.distance_frag},shadow:{uniforms:Tn([ye.lights,ye.fog,{color:{value:new ne(0)},opacity:{value:1}}]),vertexShader:tt.shadow_vert,fragmentShader:tt.shadow_frag}};lr.physical={uniforms:Tn([lr.standard.uniforms,{clearcoat:{value:0},clearcoatMap:{value:null},clearcoatMapTransform:{value:new je},clearcoatNormalMap:{value:null},clearcoatNormalMapTransform:{value:new je},clearcoatNormalScale:{value:new we(1,1)},clearcoatRoughness:{value:0},clearcoatRoughnessMap:{value:null},clearcoatRoughnessMapTransform:{value:new je},dispersion:{value:0},iridescence:{value:0},iridescenceMap:{value:null},iridescenceMapTransform:{value:new je},iridescenceIOR:{value:1.3},iridescenceThicknessMinimum:{value:100},iridescenceThicknessMaximum:{value:400},iridescenceThicknessMap:{value:null},iridescenceThicknessMapTransform:{value:new je},sheen:{value:0},sheenColor:{value:new ne(0)},sheenColorMap:{value:null},sheenColorMapTransform:{value:new je},sheenRoughness:{value:1},sheenRoughnessMap:{value:null},sheenRoughnessMapTransform:{value:new je},transmission:{value:0},transmissionMap:{value:null},transmissionMapTransform:{value:new je},transmissionSamplerSize:{value:new we},transmissionSamplerMap:{value:null},thickness:{value:0},thicknessMap:{value:null},thicknessMapTransform:{value:new je},attenuationDistance:{value:0},attenuationColor:{value:new ne(0)},specularColor:{value:new ne(1,1,1)},specularColorMap:{value:null},specularColorMapTransform:{value:new je},specularIntensity:{value:1},specularIntensityMap:{value:null},specularIntensityMapTransform:{value:new je},anisotropyVector:{value:new we},anisotropyMap:{value:null},anisotropyMapTransform:{value:new je}}]),vertexShader:tt.meshphysical_vert,fragmentShader:tt.meshphysical_frag};const xd={r:0,b:0,g:0},r5=new lt,_w=new je;_w.set(-1,0,0,0,1,0,0,0,1);function a5(o,e,t,i,n,s){const r=new ne(0);let a=n===!0?0:1,l,c,h=null,d=0,u=null;function f(b){let x=b.isScene===!0?b.background:null;if(x&&x.isTexture){const y=b.backgroundBlurriness>0;x=e.get(x,y)}return x}function p(b){let x=!1;const y=f(b);y===null?m(r,a):y&&y.isColor&&(m(y,1),x=!0);const w=o.xr.getEnvironmentBlendMode();w==="additive"?t.buffers.color.setClear(0,0,0,1,s):w==="alpha-blend"&&t.buffers.color.setClear(0,0,0,0,s),(o.autoClear||x)&&(t.buffers.depth.setTest(!0),t.buffers.depth.setMask(!0),t.buffers.color.setMask(!0),o.clear(o.autoClearColor,o.autoClearDepth,o.autoClearStencil))}function g(b,x){const y=f(x);y&&(y.isCubeTexture||y.mapping===Sf)?(c===void 0&&(c=new Se(new cn(1,1,1),new Dt({name:"BackgroundCubeMaterial",uniforms:lc(lr.backgroundCube.uniforms),vertexShader:lr.backgroundCube.vertexShader,fragmentShader:lr.backgroundCube.fragmentShader,side:fi,depthTest:!1,depthWrite:!1,fog:!1,allowOverride:!1})),c.geometry.deleteAttribute("normal"),c.geometry.deleteAttribute("uv"),c.onBeforeRender=function(w,S,A){this.matrixWorld.copyPosition(A.matrixWorld)},Object.defineProperty(c.material,"envMap",{get:function(){return this.uniforms.envMap.value}}),i.update(c)),c.material.uniforms.envMap.value=y,c.material.uniforms.backgroundBlurriness.value=x.backgroundBlurriness,c.material.uniforms.backgroundIntensity.value=x.backgroundIntensity,c.material.uniforms.backgroundRotation.value.setFromMatrix4(r5.makeRotationFromEuler(x.backgroundRotation)).transpose(),y.isCubeTexture&&y.isRenderTargetTexture===!1&&c.material.uniforms.backgroundRotation.value.premultiply(_w),c.material.toneMapped=Tt.getTransfer(y.colorSpace)!==Yt,(h!==y||d!==y.version||u!==o.toneMapping)&&(c.material.needsUpdate=!0,h=y,d=y.version,u=o.toneMapping),c.layers.enableAll(),b.unshift(c,c.geometry,c.material,0,0,null)):y&&y.isTexture&&(l===void 0&&(l=new Se(new Gn(2,2),new Dt({name:"BackgroundMaterial",uniforms:lc(lr.background.uniforms),vertexShader:lr.background.vertexShader,fragmentShader:lr.background.fragmentShader,side:Pa,depthTest:!1,depthWrite:!1,fog:!1,allowOverride:!1})),l.geometry.deleteAttribute("normal"),Object.defineProperty(l.material,"map",{get:function(){return this.uniforms.t2D.value}}),i.update(l)),l.material.uniforms.t2D.value=y,l.material.uniforms.backgroundIntensity.value=x.backgroundIntensity,l.material.toneMapped=Tt.getTransfer(y.colorSpace)!==Yt,y.matrixAutoUpdate===!0&&y.updateMatrix(),l.material.uniforms.uvTransform.value.copy(y.matrix),(h!==y||d!==y.version||u!==o.toneMapping)&&(l.material.needsUpdate=!0,h=y,d=y.version,u=o.toneMapping),l.layers.enableAll(),b.unshift(l,l.geometry,l.material,0,0,null))}function m(b,x){b.getRGB(xd,vw(o)),t.buffers.color.setClear(xd.r,xd.g,xd.b,x,s)}function v(){c!==void 0&&(c.geometry.dispose(),c.material.dispose(),c=void 0),l!==void 0&&(l.geometry.dispose(),l.material.dispose(),l=void 0)}return{getClearColor:function(){return r},setClearColor:function(b,x=1){r.set(b),a=x,m(r,a)},getClearAlpha:function(){return a},setClearAlpha:function(b){a=b,m(r,a)},render:p,addToRenderList:g,dispose:v}}function o5(o,e){const t=o.getParameter(o.MAX_VERTEX_ATTRIBS),i={},n=u(null);let s=n,r=!1;function a(R,L,P,O,k){let F=!1;const z=d(R,O,P,L);s!==z&&(s=z,c(s.object)),F=f(R,O,P,k),F&&p(R,O,P,k),k!==null&&e.update(k,o.ELEMENT_ARRAY_BUFFER),(F||r)&&(r=!1,y(R,L,P,O),k!==null&&o.bindBuffer(o.ELEMENT_ARRAY_BUFFER,e.get(k).buffer))}function l(){return o.createVertexArray()}function c(R){return o.bindVertexArray(R)}function h(R){return o.deleteVertexArray(R)}function d(R,L,P,O){const k=O.wireframe===!0;let F=i[L.id];F===void 0&&(F={},i[L.id]=F);const z=R.isInstancedMesh===!0?R.id:0;let V=F[z];V===void 0&&(V={},F[z]=V);let K=V[P.id];K===void 0&&(K={},V[P.id]=K);let q=K[k];return q===void 0&&(q=u(l()),K[k]=q),q}function u(R){const L=[],P=[],O=[];for(let k=0;k<t;k++)L[k]=0,P[k]=0,O[k]=0;return{geometry:null,program:null,wireframe:!1,newAttributes:L,enabledAttributes:P,attributeDivisors:O,object:R,attributes:{},index:null}}function f(R,L,P,O){const k=s.attributes,F=L.attributes;let z=0;const V=P.getAttributes();for(const K in V)if(V[K].location>=0){const te=k[K];let re=F[K];if(re===void 0&&(K==="instanceMatrix"&&R.instanceMatrix&&(re=R.instanceMatrix),K==="instanceColor"&&R.instanceColor&&(re=R.instanceColor)),te===void 0||te.attribute!==re||re&&te.data!==re.data)return!0;z++}return s.attributesNum!==z||s.index!==O}function p(R,L,P,O){const k={},F=L.attributes;let z=0;const V=P.getAttributes();for(const K in V)if(V[K].location>=0){let te=F[K];te===void 0&&(K==="instanceMatrix"&&R.instanceMatrix&&(te=R.instanceMatrix),K==="instanceColor"&&R.instanceColor&&(te=R.instanceColor));const re={};re.attribute=te,te&&te.data&&(re.data=te.data),k[K]=re,z++}s.attributes=k,s.attributesNum=z,s.index=O}function g(){const R=s.newAttributes;for(let L=0,P=R.length;L<P;L++)R[L]=0}function m(R){v(R,0)}function v(R,L){const P=s.newAttributes,O=s.enabledAttributes,k=s.attributeDivisors;P[R]=1,O[R]===0&&(o.enableVertexAttribArray(R),O[R]=1),k[R]!==L&&(o.vertexAttribDivisor(R,L),k[R]=L)}function b(){const R=s.newAttributes,L=s.enabledAttributes;for(let P=0,O=L.length;P<O;P++)L[P]!==R[P]&&(o.disableVertexAttribArray(P),L[P]=0)}function x(R,L,P,O,k,F,z){z===!0?o.vertexAttribIPointer(R,L,P,k,F):o.vertexAttribPointer(R,L,P,O,k,F)}function y(R,L,P,O){g();const k=O.attributes,F=P.getAttributes(),z=L.defaultAttributeValues;for(const V in F){const K=F[V];if(K.location>=0){let q=k[V];if(q===void 0&&(V==="instanceMatrix"&&R.instanceMatrix&&(q=R.instanceMatrix),V==="instanceColor"&&R.instanceColor&&(q=R.instanceColor)),q!==void 0){const te=q.normalized,re=q.itemSize,Ge=e.get(q);if(Ge===void 0)continue;const ft=Ge.buffer,it=Ge.type,Z=Ge.bytesPerElement,ae=it===o.INT||it===o.UNSIGNED_INT||q.gpuType===lg;if(q.isInterleavedBufferAttribute){const se=q.data,G=se.stride,Re=q.offset;if(se.isInstancedInterleavedBuffer){for(let ze=0;ze<K.locationSize;ze++)v(K.location+ze,se.meshPerAttribute);R.isInstancedMesh!==!0&&O._maxInstanceCount===void 0&&(O._maxInstanceCount=se.meshPerAttribute*se.count)}else for(let ze=0;ze<K.locationSize;ze++)m(K.location+ze);o.bindBuffer(o.ARRAY_BUFFER,ft);for(let ze=0;ze<K.locationSize;ze++)x(K.location+ze,re/K.locationSize,it,te,G*Z,(Re+re/K.locationSize*ze)*Z,ae)}else{if(q.isInstancedBufferAttribute){for(let se=0;se<K.locationSize;se++)v(K.location+se,q.meshPerAttribute);R.isInstancedMesh!==!0&&O._maxInstanceCount===void 0&&(O._maxInstanceCount=q.meshPerAttribute*q.count)}else for(let se=0;se<K.locationSize;se++)m(K.location+se);o.bindBuffer(o.ARRAY_BUFFER,ft);for(let se=0;se<K.locationSize;se++)x(K.location+se,re/K.locationSize,it,te,re*Z,re/K.locationSize*se*Z,ae)}}else if(z!==void 0){const te=z[V];if(te!==void 0)switch(te.length){case 2:o.vertexAttrib2fv(K.location,te);break;case 3:o.vertexAttrib3fv(K.location,te);break;case 4:o.vertexAttrib4fv(K.location,te);break;default:o.vertexAttrib1fv(K.location,te)}}}}b()}function w(){_();for(const R in i){const L=i[R];for(const P in L){const O=L[P];for(const k in O){const F=O[k];for(const z in F)h(F[z].object),delete F[z];delete O[k]}}delete i[R]}}function S(R){if(i[R.id]===void 0)return;const L=i[R.id];for(const P in L){const O=L[P];for(const k in O){const F=O[k];for(const z in F)h(F[z].object),delete F[z];delete O[k]}}delete i[R.id]}function A(R){for(const L in i){const P=i[L];for(const O in P){const k=P[O];if(k[R.id]===void 0)continue;const F=k[R.id];for(const z in F)h(F[z].object),delete F[z];delete k[R.id]}}}function M(R){for(const L in i){const P=i[L],O=R.isInstancedMesh===!0?R.id:0,k=P[O];if(k!==void 0){for(const F in k){const z=k[F];for(const V in z)h(z[V].object),delete z[V];delete k[F]}delete P[O],Object.keys(P).length===0&&delete i[L]}}}function _(){I(),r=!0,s!==n&&(s=n,c(s.object))}function I(){n.geometry=null,n.program=null,n.wireframe=!1}return{setup:a,reset:_,resetDefaultState:I,dispose:w,releaseStatesOfGeometry:S,releaseStatesOfObject:M,releaseStatesOfProgram:A,initAttributes:g,enableAttribute:m,disableUnusedAttributes:b}}function l5(o,e,t){let i;function n(l){i=l}function s(l,c){o.drawArrays(i,l,c),t.update(c,i,1)}function r(l,c,h){h!==0&&(o.drawArraysInstanced(i,l,c,h),t.update(c,i,h))}function a(l,c,h){if(h===0)return;e.get("WEBGL_multi_draw").multiDrawArraysWEBGL(i,l,0,c,0,h);let u=0;for(let f=0;f<h;f++)u+=c[f];t.update(u,i,1)}this.setMode=n,this.render=s,this.renderInstances=r,this.renderMultiDraw=a}function c5(o,e,t,i){let n;function s(){if(n!==void 0)return n;if(e.has("EXT_texture_filter_anisotropic")===!0){const A=e.get("EXT_texture_filter_anisotropic");n=o.getParameter(A.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else n=0;return n}function r(A){return!(A!==Vi&&i.convert(A)!==o.getParameter(o.IMPLEMENTATION_COLOR_READ_FORMAT))}function a(A){const M=A===ci&&(e.has("EXT_color_buffer_half_float")||e.has("EXT_color_buffer_float"));return!(A!==zn&&i.convert(A)!==o.getParameter(o.IMPLEMENTATION_COLOR_READ_TYPE)&&A!==En&&!M)}function l(A){if(A==="highp"){if(o.getShaderPrecisionFormat(o.VERTEX_SHADER,o.HIGH_FLOAT).precision>0&&o.getShaderPrecisionFormat(o.FRAGMENT_SHADER,o.HIGH_FLOAT).precision>0)return"highp";A="mediump"}return A==="mediump"&&o.getShaderPrecisionFormat(o.VERTEX_SHADER,o.MEDIUM_FLOAT).precision>0&&o.getShaderPrecisionFormat(o.FRAGMENT_SHADER,o.MEDIUM_FLOAT).precision>0?"mediump":"lowp"}let c=t.precision!==void 0?t.precision:"highp";const h=l(c);h!==c&&(ke("WebGLRenderer:",c,"not supported, using",h,"instead."),c=h);const d=t.logarithmicDepthBuffer===!0,u=t.reversedDepthBuffer===!0&&e.has("EXT_clip_control");t.reversedDepthBuffer===!0&&u===!1&&ke("WebGLRenderer: Unable to use reversed depth buffer due to missing EXT_clip_control extension. Fallback to default depth buffer.");const f=o.getParameter(o.MAX_TEXTURE_IMAGE_UNITS),p=o.getParameter(o.MAX_VERTEX_TEXTURE_IMAGE_UNITS),g=o.getParameter(o.MAX_TEXTURE_SIZE),m=o.getParameter(o.MAX_CUBE_MAP_TEXTURE_SIZE),v=o.getParameter(o.MAX_VERTEX_ATTRIBS),b=o.getParameter(o.MAX_VERTEX_UNIFORM_VECTORS),x=o.getParameter(o.MAX_VARYING_VECTORS),y=o.getParameter(o.MAX_FRAGMENT_UNIFORM_VECTORS),w=o.getParameter(o.MAX_SAMPLES),S=o.getParameter(o.SAMPLES);return{isWebGL2:!0,getMaxAnisotropy:s,getMaxPrecision:l,textureFormatReadable:r,textureTypeReadable:a,precision:c,logarithmicDepthBuffer:d,reversedDepthBuffer:u,maxTextures:f,maxVertexTextures:p,maxTextureSize:g,maxCubemapSize:m,maxAttributes:v,maxVertexUniforms:b,maxVaryings:x,maxFragmentUniforms:y,maxSamples:w,samples:S}}function h5(o){const e=this;let t=null,i=0,n=!1,s=!1;const r=new ma,a=new je,l={value:null,needsUpdate:!1};this.uniform=l,this.numPlanes=0,this.numIntersection=0,this.init=function(d,u){const f=d.length!==0||u||i!==0||n;return n=u,i=d.length,f},this.beginShadows=function(){s=!0,h(null)},this.endShadows=function(){s=!1},this.setGlobalState=function(d,u){t=h(d,u,0)},this.setState=function(d,u,f){const p=d.clippingPlanes,g=d.clipIntersection,m=d.clipShadows,v=o.get(d);if(!n||p===null||p.length===0||s&&!m)s?h(null):c();else{const b=s?0:i,x=b*4;let y=v.clippingState||null;l.value=y,y=h(p,u,x,f);for(let w=0;w!==x;++w)y[w]=t[w];v.clippingState=y,this.numIntersection=g?this.numPlanes:0,this.numPlanes+=b}};function c(){l.value!==t&&(l.value=t,l.needsUpdate=i>0),e.numPlanes=i,e.numIntersection=0}function h(d,u,f,p){const g=d!==null?d.length:0;let m=null;if(g!==0){if(m=l.value,p!==!0||m===null){const v=f+g*4,b=u.matrixWorldInverse;a.getNormalMatrix(b),(m===null||m.length<v)&&(m=new Float32Array(v));for(let x=0,y=f;x!==g;++x,y+=4)r.copy(d[x]).applyMatrix4(b,a),r.normal.toArray(m,y),m[y+3]=r.constant}l.value=m,l.needsUpdate=!0}return e.numPlanes=g,e.numIntersection=0,m}}const Sa=4,j1=[.125,.215,.35,.446,.526,.582],to=20,d5=256,Dc=new $s,J1=new ne;let xp=null,Sp=0,Ep=0,Ap=!1;const u5=new D;class mm{constructor(e){this._renderer=e,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._sizeLods=[],this._sigmas=[],this._lodMeshes=[],this._backgroundBox=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._blurMaterial=null,this._ggxMaterial=null}fromScene(e,t=0,i=.1,n=100,s={}){const{size:r=256,position:a=u5}=s;xp=this._renderer.getRenderTarget(),Sp=this._renderer.getActiveCubeFace(),Ep=this._renderer.getActiveMipmapLevel(),Ap=this._renderer.xr.enabled,this._renderer.xr.enabled=!1,this._setSize(r);const l=this._allocateTargets();return l.depthBuffer=!0,this._sceneToCubeUV(e,i,n,l,a),t>0&&this._blur(l,0,0,t),this._applyPMREM(l),this._cleanup(l),l}fromEquirectangular(e,t=null){return this._fromTexture(e,t)}fromCubemap(e,t=null){return this._fromTexture(e,t)}compileCubemapShader(){this._cubemapMaterial===null&&(this._cubemapMaterial=ty(),this._compileMaterial(this._cubemapMaterial))}compileEquirectangularShader(){this._equirectMaterial===null&&(this._equirectMaterial=ey(),this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),this._cubemapMaterial!==null&&this._cubemapMaterial.dispose(),this._equirectMaterial!==null&&this._equirectMaterial.dispose(),this._backgroundBox!==null&&(this._backgroundBox.geometry.dispose(),this._backgroundBox.material.dispose())}_setSize(e){this._lodMax=Math.floor(Math.log2(e)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){this._blurMaterial!==null&&this._blurMaterial.dispose(),this._ggxMaterial!==null&&this._ggxMaterial.dispose(),this._pingPongRenderTarget!==null&&this._pingPongRenderTarget.dispose();for(let e=0;e<this._lodMeshes.length;e++)this._lodMeshes[e].geometry.dispose()}_cleanup(e){this._renderer.setRenderTarget(xp,Sp,Ep),this._renderer.xr.enabled=Ap,e.scissorTest=!1,pl(e,0,0,e.width,e.height)}_fromTexture(e,t){e.mapping===Oo||e.mapping===rc?this._setSize(e.image.length===0?16:e.image[0].width||e.image[0].image.width):this._setSize(e.image.width/4),xp=this._renderer.getRenderTarget(),Sp=this._renderer.getActiveCubeFace(),Ep=this._renderer.getActiveMipmapLevel(),Ap=this._renderer.xr.enabled,this._renderer.xr.enabled=!1;const i=t||this._allocateTargets();return this._textureToCubeUV(e,i),this._applyPMREM(i),this._cleanup(i),i}_allocateTargets(){const e=3*Math.max(this._cubeSize,112),t=4*this._cubeSize,i={magFilter:mt,minFilter:mt,generateMipmaps:!1,type:ci,format:Vi,colorSpace:Gu,depthBuffer:!1},n=Q1(e,t,i);if(this._pingPongRenderTarget===null||this._pingPongRenderTarget.width!==e||this._pingPongRenderTarget.height!==t){this._pingPongRenderTarget!==null&&this._dispose(),this._pingPongRenderTarget=Q1(e,t,i);const{_lodMax:s}=this;({lodMeshes:this._lodMeshes,sizeLods:this._sizeLods,sigmas:this._sigmas}=f5(s)),this._blurMaterial=m5(s,e,t),this._ggxMaterial=p5(s,e,t)}return n}_compileMaterial(e){const t=new Se(new ot,e);this._renderer.compile(t,Dc)}_sceneToCubeUV(e,t,i,n,s){const l=new Qn(90,1,t,i),c=[1,-1,1,1,1,1],h=[1,1,1,-1,-1,-1],d=this._renderer,u=d.autoClear,f=d.toneMapping;d.getClearColor(J1),d.toneMapping=Mr,d.autoClear=!1,d.state.buffers.depth.getReversed()&&(d.setRenderTarget(n),d.clearDepth(),d.setRenderTarget(null)),this._backgroundBox===null&&(this._backgroundBox=new Se(new cn,new Hn({name:"PMREM.Background",side:fi,depthWrite:!1,depthTest:!1})));const g=this._backgroundBox,m=g.material;let v=!1;const b=e.background;b?b.isColor&&(m.color.copy(b),e.background=null,v=!0):(m.color.copy(J1),v=!0);for(let x=0;x<6;x++){const y=x%3;y===0?(l.up.set(0,c[x],0),l.position.set(s.x,s.y,s.z),l.lookAt(s.x+h[x],s.y,s.z)):y===1?(l.up.set(0,0,c[x]),l.position.set(s.x,s.y,s.z),l.lookAt(s.x,s.y+h[x],s.z)):(l.up.set(0,c[x],0),l.position.set(s.x,s.y,s.z),l.lookAt(s.x,s.y,s.z+h[x]));const w=this._cubeSize;pl(n,y*w,x>2?w:0,w,w),d.setRenderTarget(n),v&&d.render(g,l),d.render(e,l)}d.toneMapping=f,d.autoClear=u,e.background=b}_textureToCubeUV(e,t){const i=this._renderer,n=e.mapping===Oo||e.mapping===rc;n?(this._cubemapMaterial===null&&(this._cubemapMaterial=ty()),this._cubemapMaterial.uniforms.flipEnvMap.value=e.isRenderTargetTexture===!1?-1:1):this._equirectMaterial===null&&(this._equirectMaterial=ey());const s=n?this._cubemapMaterial:this._equirectMaterial,r=this._lodMeshes[0];r.material=s;const a=s.uniforms;a.envMap.value=e;const l=this._cubeSize;pl(t,0,0,3*l,2*l),i.setRenderTarget(t),i.render(r,Dc)}_applyPMREM(e){const t=this._renderer,i=t.autoClear;t.autoClear=!1;const n=this._lodMeshes.length;for(let s=1;s<n;s++)this._applyGGXFilter(e,s-1,s);t.autoClear=i}_applyGGXFilter(e,t,i){const n=this._renderer,s=this._pingPongRenderTarget,r=this._ggxMaterial,a=this._lodMeshes[i];a.material=r;const l=r.uniforms,c=i/(this._lodMeshes.length-1),h=t/(this._lodMeshes.length-1),d=Math.sqrt(c*c-h*h),u=0+c*1.25,f=d*u,{_lodMax:p}=this,g=this._sizeLods[i],m=3*g*(i>p-Sa?i-p+Sa:0),v=4*(this._cubeSize-g);l.envMap.value=e.texture,l.roughness.value=f,l.mipInt.value=p-t,pl(s,m,v,3*g,2*g),n.setRenderTarget(s),n.render(a,Dc),l.envMap.value=s.texture,l.roughness.value=0,l.mipInt.value=p-i,pl(e,m,v,3*g,2*g),n.setRenderTarget(e),n.render(a,Dc)}_blur(e,t,i,n,s){const r=this._pingPongRenderTarget;this._halfBlur(e,r,t,i,n,"latitudinal",s),this._halfBlur(r,e,i,i,n,"longitudinal",s)}_halfBlur(e,t,i,n,s,r,a){const l=this._renderer,c=this._blurMaterial;r!=="latitudinal"&&r!=="longitudinal"&&Ze("blur direction must be either latitudinal or longitudinal!");const h=3,d=this._lodMeshes[n];d.material=c;const u=c.uniforms,f=this._sizeLods[i]-1,p=isFinite(s)?Math.PI/(2*f):2*Math.PI/(2*to-1),g=s/p,m=isFinite(s)?1+Math.floor(h*g):to;m>to&&ke(`sigmaRadians, ${s}, is too large and will clip, as it requested ${m} samples when the maximum is set to ${to}`);const v=[];let b=0;for(let A=0;A<to;++A){const M=A/g,_=Math.exp(-M*M/2);v.push(_),A===0?b+=_:A<m&&(b+=2*_)}for(let A=0;A<v.length;A++)v[A]=v[A]/b;u.envMap.value=e.texture,u.samples.value=m,u.weights.value=v,u.latitudinal.value=r==="latitudinal",a&&(u.poleAxis.value=a);const{_lodMax:x}=this;u.dTheta.value=p,u.mipInt.value=x-i;const y=this._sizeLods[n],w=3*y*(n>x-Sa?n-x+Sa:0),S=4*(this._cubeSize-y);pl(t,w,S,3*y,2*y),l.setRenderTarget(t),l.render(d,Dc)}}function f5(o){const e=[],t=[],i=[];let n=o;const s=o-Sa+1+j1.length;for(let r=0;r<s;r++){const a=Math.pow(2,n);e.push(a);let l=1/a;r>o-Sa?l=j1[r-o+Sa-1]:r===0&&(l=0),t.push(l);const c=1/(a-2),h=-c,d=1+c,u=[h,h,d,h,d,d,h,h,d,d,h,d],f=6,p=6,g=3,m=2,v=1,b=new Float32Array(g*p*f),x=new Float32Array(m*p*f),y=new Float32Array(v*p*f);for(let S=0;S<f;S++){const A=S%3*2/3-1,M=S>2?0:-1,_=[A,M,0,A+2/3,M,0,A+2/3,M+1,0,A,M,0,A+2/3,M+1,0,A,M+1,0];b.set(_,g*p*S),x.set(u,m*p*S);const I=[S,S,S,S,S,S];y.set(I,v*p*S)}const w=new ot;w.setAttribute("position",new st(b,g)),w.setAttribute("uv",new st(x,m)),w.setAttribute("faceIndex",new st(y,v)),i.push(new Se(w,null)),n>Sa&&n--}return{lodMeshes:i,sizeLods:e,sigmas:t}}function Q1(o,e,t){const i=new Mi(o,e,t);return i.texture.mapping=Sf,i.texture.name="PMREM.cubeUv",i.scissorTest=!0,i}function pl(o,e,t,i,n){o.viewport.set(e,t,i,n),o.scissor.set(e,t,i,n)}function p5(o,e,t){return new Dt({name:"PMREMGGXConvolution",defines:{GGX_SAMPLES:d5,CUBEUV_TEXEL_WIDTH:1/e,CUBEUV_TEXEL_HEIGHT:1/t,CUBEUV_MAX_MIP:`${o}.0`},uniforms:{envMap:{value:null},roughness:{value:0},mipInt:{value:0}},vertexShader:_f(),fragmentShader:`
6833
+ }`,tt={alphahash_fragment:AA,alphahash_pars_fragment:_A,alphamap_fragment:TA,alphamap_pars_fragment:IA,alphatest_fragment:DA,alphatest_pars_fragment:RA,aomap_fragment:CA,aomap_pars_fragment:kA,batching_pars_vertex:PA,batching_vertex:LA,begin_vertex:OA,beginnormal_vertex:NA,bsdfs:FA,iridescence_fragment:UA,bumpmap_pars_fragment:BA,clipping_planes_fragment:zA,clipping_planes_pars_fragment:HA,clipping_planes_pars_vertex:GA,clipping_planes_vertex:VA,color_fragment:WA,color_pars_fragment:XA,color_pars_vertex:$A,color_vertex:YA,common:qA,cube_uv_reflection_fragment:KA,defaultnormal_vertex:ZA,displacementmap_pars_vertex:jA,displacementmap_vertex:JA,emissivemap_fragment:QA,emissivemap_pars_fragment:e_,colorspace_fragment:t_,colorspace_pars_fragment:i_,envmap_fragment:n_,envmap_common_pars_fragment:s_,envmap_pars_fragment:r_,envmap_pars_vertex:a_,envmap_physical_pars_fragment:v_,envmap_vertex:o_,fog_vertex:l_,fog_pars_vertex:c_,fog_fragment:h_,fog_pars_fragment:d_,gradientmap_pars_fragment:u_,lightmap_pars_fragment:f_,lights_lambert_fragment:p_,lights_lambert_pars_fragment:m_,lights_pars_begin:g_,lights_toon_fragment:y_,lights_toon_pars_fragment:b_,lights_phong_fragment:M_,lights_phong_pars_fragment:w_,lights_physical_fragment:x_,lights_physical_pars_fragment:S_,lights_fragment_begin:E_,lights_fragment_maps:A_,lights_fragment_end:__,lightprobes_pars_fragment:T_,logdepthbuf_fragment:I_,logdepthbuf_pars_fragment:D_,logdepthbuf_pars_vertex:R_,logdepthbuf_vertex:C_,map_fragment:k_,map_pars_fragment:P_,map_particle_fragment:L_,map_particle_pars_fragment:O_,metalnessmap_fragment:N_,metalnessmap_pars_fragment:F_,morphinstance_vertex:U_,morphcolor_vertex:B_,morphnormal_vertex:z_,morphtarget_pars_vertex:H_,morphtarget_vertex:G_,normal_fragment_begin:V_,normal_fragment_maps:W_,normal_pars_fragment:X_,normal_pars_vertex:$_,normal_vertex:Y_,normalmap_pars_fragment:q_,clearcoat_normal_fragment_begin:K_,clearcoat_normal_fragment_maps:Z_,clearcoat_pars_fragment:j_,iridescence_pars_fragment:J_,opaque_fragment:Q_,packing:eT,premultiplied_alpha_fragment:tT,project_vertex:iT,dithering_fragment:nT,dithering_pars_fragment:sT,roughnessmap_fragment:rT,roughnessmap_pars_fragment:aT,shadowmap_pars_fragment:oT,shadowmap_pars_vertex:lT,shadowmap_vertex:cT,shadowmask_pars_fragment:hT,skinbase_vertex:dT,skinning_pars_vertex:uT,skinning_vertex:fT,skinnormal_vertex:pT,specularmap_fragment:mT,specularmap_pars_fragment:gT,tonemapping_fragment:vT,tonemapping_pars_fragment:yT,transmission_fragment:bT,transmission_pars_fragment:MT,uv_pars_fragment:wT,uv_pars_vertex:xT,uv_vertex:ST,worldpos_vertex:ET,background_vert:AT,background_frag:_T,backgroundCube_vert:TT,backgroundCube_frag:IT,cube_vert:DT,cube_frag:RT,depth_vert:CT,depth_frag:kT,distance_vert:PT,distance_frag:LT,equirect_vert:OT,equirect_frag:NT,linedashed_vert:FT,linedashed_frag:UT,meshbasic_vert:BT,meshbasic_frag:zT,meshlambert_vert:HT,meshlambert_frag:GT,meshmatcap_vert:VT,meshmatcap_frag:WT,meshnormal_vert:XT,meshnormal_frag:$T,meshphong_vert:YT,meshphong_frag:qT,meshphysical_vert:KT,meshphysical_frag:ZT,meshtoon_vert:jT,meshtoon_frag:JT,points_vert:QT,points_frag:e5,shadow_vert:t5,shadow_frag:i5,sprite_vert:n5,sprite_frag:s5},ye={common:{diffuse:{value:new ne(16777215)},opacity:{value:1},map:{value:null},mapTransform:{value:new Je},alphaMap:{value:null},alphaMapTransform:{value:new Je},alphaTest:{value:0}},specularmap:{specularMap:{value:null},specularMapTransform:{value:new Je}},envmap:{envMap:{value:null},envMapRotation:{value:new Je},reflectivity:{value:1},ior:{value:1.5},refractionRatio:{value:.98},dfgLUT:{value:null}},aomap:{aoMap:{value:null},aoMapIntensity:{value:1},aoMapTransform:{value:new Je}},lightmap:{lightMap:{value:null},lightMapIntensity:{value:1},lightMapTransform:{value:new Je}},bumpmap:{bumpMap:{value:null},bumpMapTransform:{value:new Je},bumpScale:{value:1}},normalmap:{normalMap:{value:null},normalMapTransform:{value:new Je},normalScale:{value:new we(1,1)}},displacementmap:{displacementMap:{value:null},displacementMapTransform:{value:new Je},displacementScale:{value:1},displacementBias:{value:0}},emissivemap:{emissiveMap:{value:null},emissiveMapTransform:{value:new Je}},metalnessmap:{metalnessMap:{value:null},metalnessMapTransform:{value:new Je}},roughnessmap:{roughnessMap:{value:null},roughnessMapTransform:{value:new Je}},gradientmap:{gradientMap:{value:null}},fog:{fogDensity:{value:25e-5},fogNear:{value:1},fogFar:{value:2e3},fogColor:{value:new ne(16777215)}},lights:{ambientLightColor:{value:[]},lightProbe:{value:[]},directionalLights:{value:[],properties:{direction:{},color:{}}},directionalLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},directionalShadowMatrix:{value:[]},spotLights:{value:[],properties:{color:{},position:{},direction:{},distance:{},coneCos:{},penumbraCos:{},decay:{}}},spotLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},spotLightMap:{value:[]},spotLightMatrix:{value:[]},pointLights:{value:[],properties:{color:{},position:{},decay:{},distance:{}}},pointLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{},shadowCameraNear:{},shadowCameraFar:{}}},pointShadowMatrix:{value:[]},hemisphereLights:{value:[],properties:{direction:{},skyColor:{},groundColor:{}}},rectAreaLights:{value:[],properties:{color:{},position:{},width:{},height:{}}},ltc_1:{value:null},ltc_2:{value:null},probesSH:{value:null},probesMin:{value:new D},probesMax:{value:new D},probesResolution:{value:new D}},points:{diffuse:{value:new ne(16777215)},opacity:{value:1},size:{value:1},scale:{value:1},map:{value:null},alphaMap:{value:null},alphaMapTransform:{value:new Je},alphaTest:{value:0},uvTransform:{value:new Je}},sprite:{diffuse:{value:new ne(16777215)},opacity:{value:1},center:{value:new we(.5,.5)},rotation:{value:0},map:{value:null},mapTransform:{value:new Je},alphaMap:{value:null},alphaMapTransform:{value:new Je},alphaTest:{value:0}}},lr={basic:{uniforms:Tn([ye.common,ye.specularmap,ye.envmap,ye.aomap,ye.lightmap,ye.fog]),vertexShader:tt.meshbasic_vert,fragmentShader:tt.meshbasic_frag},lambert:{uniforms:Tn([ye.common,ye.specularmap,ye.envmap,ye.aomap,ye.lightmap,ye.emissivemap,ye.bumpmap,ye.normalmap,ye.displacementmap,ye.fog,ye.lights,{emissive:{value:new ne(0)},envMapIntensity:{value:1}}]),vertexShader:tt.meshlambert_vert,fragmentShader:tt.meshlambert_frag},phong:{uniforms:Tn([ye.common,ye.specularmap,ye.envmap,ye.aomap,ye.lightmap,ye.emissivemap,ye.bumpmap,ye.normalmap,ye.displacementmap,ye.fog,ye.lights,{emissive:{value:new ne(0)},specular:{value:new ne(1118481)},shininess:{value:30},envMapIntensity:{value:1}}]),vertexShader:tt.meshphong_vert,fragmentShader:tt.meshphong_frag},standard:{uniforms:Tn([ye.common,ye.envmap,ye.aomap,ye.lightmap,ye.emissivemap,ye.bumpmap,ye.normalmap,ye.displacementmap,ye.roughnessmap,ye.metalnessmap,ye.fog,ye.lights,{emissive:{value:new ne(0)},roughness:{value:1},metalness:{value:0},envMapIntensity:{value:1}}]),vertexShader:tt.meshphysical_vert,fragmentShader:tt.meshphysical_frag},toon:{uniforms:Tn([ye.common,ye.aomap,ye.lightmap,ye.emissivemap,ye.bumpmap,ye.normalmap,ye.displacementmap,ye.gradientmap,ye.fog,ye.lights,{emissive:{value:new ne(0)}}]),vertexShader:tt.meshtoon_vert,fragmentShader:tt.meshtoon_frag},matcap:{uniforms:Tn([ye.common,ye.bumpmap,ye.normalmap,ye.displacementmap,ye.fog,{matcap:{value:null}}]),vertexShader:tt.meshmatcap_vert,fragmentShader:tt.meshmatcap_frag},points:{uniforms:Tn([ye.points,ye.fog]),vertexShader:tt.points_vert,fragmentShader:tt.points_frag},dashed:{uniforms:Tn([ye.common,ye.fog,{scale:{value:1},dashSize:{value:1},totalSize:{value:2}}]),vertexShader:tt.linedashed_vert,fragmentShader:tt.linedashed_frag},depth:{uniforms:Tn([ye.common,ye.displacementmap]),vertexShader:tt.depth_vert,fragmentShader:tt.depth_frag},normal:{uniforms:Tn([ye.common,ye.bumpmap,ye.normalmap,ye.displacementmap,{opacity:{value:1}}]),vertexShader:tt.meshnormal_vert,fragmentShader:tt.meshnormal_frag},sprite:{uniforms:Tn([ye.sprite,ye.fog]),vertexShader:tt.sprite_vert,fragmentShader:tt.sprite_frag},background:{uniforms:{uvTransform:{value:new Je},t2D:{value:null},backgroundIntensity:{value:1}},vertexShader:tt.background_vert,fragmentShader:tt.background_frag},backgroundCube:{uniforms:{envMap:{value:null},backgroundBlurriness:{value:0},backgroundIntensity:{value:1},backgroundRotation:{value:new Je}},vertexShader:tt.backgroundCube_vert,fragmentShader:tt.backgroundCube_frag},cube:{uniforms:{tCube:{value:null},tFlip:{value:-1},opacity:{value:1}},vertexShader:tt.cube_vert,fragmentShader:tt.cube_frag},equirect:{uniforms:{tEquirect:{value:null}},vertexShader:tt.equirect_vert,fragmentShader:tt.equirect_frag},distance:{uniforms:Tn([ye.common,ye.displacementmap,{referencePosition:{value:new D},nearDistance:{value:1},farDistance:{value:1e3}}]),vertexShader:tt.distance_vert,fragmentShader:tt.distance_frag},shadow:{uniforms:Tn([ye.lights,ye.fog,{color:{value:new ne(0)},opacity:{value:1}}]),vertexShader:tt.shadow_vert,fragmentShader:tt.shadow_frag}};lr.physical={uniforms:Tn([lr.standard.uniforms,{clearcoat:{value:0},clearcoatMap:{value:null},clearcoatMapTransform:{value:new Je},clearcoatNormalMap:{value:null},clearcoatNormalMapTransform:{value:new Je},clearcoatNormalScale:{value:new we(1,1)},clearcoatRoughness:{value:0},clearcoatRoughnessMap:{value:null},clearcoatRoughnessMapTransform:{value:new Je},dispersion:{value:0},iridescence:{value:0},iridescenceMap:{value:null},iridescenceMapTransform:{value:new Je},iridescenceIOR:{value:1.3},iridescenceThicknessMinimum:{value:100},iridescenceThicknessMaximum:{value:400},iridescenceThicknessMap:{value:null},iridescenceThicknessMapTransform:{value:new Je},sheen:{value:0},sheenColor:{value:new ne(0)},sheenColorMap:{value:null},sheenColorMapTransform:{value:new Je},sheenRoughness:{value:1},sheenRoughnessMap:{value:null},sheenRoughnessMapTransform:{value:new Je},transmission:{value:0},transmissionMap:{value:null},transmissionMapTransform:{value:new Je},transmissionSamplerSize:{value:new we},transmissionSamplerMap:{value:null},thickness:{value:0},thicknessMap:{value:null},thicknessMapTransform:{value:new Je},attenuationDistance:{value:0},attenuationColor:{value:new ne(0)},specularColor:{value:new ne(1,1,1)},specularColorMap:{value:null},specularColorMapTransform:{value:new Je},specularIntensity:{value:1},specularIntensityMap:{value:null},specularIntensityMapTransform:{value:new Je},anisotropyVector:{value:new we},anisotropyMap:{value:null},anisotropyMapTransform:{value:new Je}}]),vertexShader:tt.meshphysical_vert,fragmentShader:tt.meshphysical_frag};const xd={r:0,b:0,g:0},r5=new lt,_w=new Je;_w.set(-1,0,0,0,1,0,0,0,1);function a5(o,e,t,i,n,s){const r=new ne(0);let a=n===!0?0:1,l,c,h=null,d=0,u=null;function f(b){let x=b.isScene===!0?b.background:null;if(x&&x.isTexture){const y=b.backgroundBlurriness>0;x=e.get(x,y)}return x}function p(b){let x=!1;const y=f(b);y===null?m(r,a):y&&y.isColor&&(m(y,1),x=!0);const w=o.xr.getEnvironmentBlendMode();w==="additive"?t.buffers.color.setClear(0,0,0,1,s):w==="alpha-blend"&&t.buffers.color.setClear(0,0,0,0,s),(o.autoClear||x)&&(t.buffers.depth.setTest(!0),t.buffers.depth.setMask(!0),t.buffers.color.setMask(!0),o.clear(o.autoClearColor,o.autoClearDepth,o.autoClearStencil))}function g(b,x){const y=f(x);y&&(y.isCubeTexture||y.mapping===Sf)?(c===void 0&&(c=new Se(new cn(1,1,1),new Dt({name:"BackgroundCubeMaterial",uniforms:lc(lr.backgroundCube.uniforms),vertexShader:lr.backgroundCube.vertexShader,fragmentShader:lr.backgroundCube.fragmentShader,side:fi,depthTest:!1,depthWrite:!1,fog:!1,allowOverride:!1})),c.geometry.deleteAttribute("normal"),c.geometry.deleteAttribute("uv"),c.onBeforeRender=function(w,S,A){this.matrixWorld.copyPosition(A.matrixWorld)},Object.defineProperty(c.material,"envMap",{get:function(){return this.uniforms.envMap.value}}),i.update(c)),c.material.uniforms.envMap.value=y,c.material.uniforms.backgroundBlurriness.value=x.backgroundBlurriness,c.material.uniforms.backgroundIntensity.value=x.backgroundIntensity,c.material.uniforms.backgroundRotation.value.setFromMatrix4(r5.makeRotationFromEuler(x.backgroundRotation)).transpose(),y.isCubeTexture&&y.isRenderTargetTexture===!1&&c.material.uniforms.backgroundRotation.value.premultiply(_w),c.material.toneMapped=Tt.getTransfer(y.colorSpace)!==Yt,(h!==y||d!==y.version||u!==o.toneMapping)&&(c.material.needsUpdate=!0,h=y,d=y.version,u=o.toneMapping),c.layers.enableAll(),b.unshift(c,c.geometry,c.material,0,0,null)):y&&y.isTexture&&(l===void 0&&(l=new Se(new Gn(2,2),new Dt({name:"BackgroundMaterial",uniforms:lc(lr.background.uniforms),vertexShader:lr.background.vertexShader,fragmentShader:lr.background.fragmentShader,side:Pa,depthTest:!1,depthWrite:!1,fog:!1,allowOverride:!1})),l.geometry.deleteAttribute("normal"),Object.defineProperty(l.material,"map",{get:function(){return this.uniforms.t2D.value}}),i.update(l)),l.material.uniforms.t2D.value=y,l.material.uniforms.backgroundIntensity.value=x.backgroundIntensity,l.material.toneMapped=Tt.getTransfer(y.colorSpace)!==Yt,y.matrixAutoUpdate===!0&&y.updateMatrix(),l.material.uniforms.uvTransform.value.copy(y.matrix),(h!==y||d!==y.version||u!==o.toneMapping)&&(l.material.needsUpdate=!0,h=y,d=y.version,u=o.toneMapping),l.layers.enableAll(),b.unshift(l,l.geometry,l.material,0,0,null))}function m(b,x){b.getRGB(xd,vw(o)),t.buffers.color.setClear(xd.r,xd.g,xd.b,x,s)}function v(){c!==void 0&&(c.geometry.dispose(),c.material.dispose(),c=void 0),l!==void 0&&(l.geometry.dispose(),l.material.dispose(),l=void 0)}return{getClearColor:function(){return r},setClearColor:function(b,x=1){r.set(b),a=x,m(r,a)},getClearAlpha:function(){return a},setClearAlpha:function(b){a=b,m(r,a)},render:p,addToRenderList:g,dispose:v}}function o5(o,e){const t=o.getParameter(o.MAX_VERTEX_ATTRIBS),i={},n=u(null);let s=n,r=!1;function a(R,L,P,O,k){let F=!1;const z=d(R,O,P,L);s!==z&&(s=z,c(s.object)),F=f(R,O,P,k),F&&p(R,O,P,k),k!==null&&e.update(k,o.ELEMENT_ARRAY_BUFFER),(F||r)&&(r=!1,y(R,L,P,O),k!==null&&o.bindBuffer(o.ELEMENT_ARRAY_BUFFER,e.get(k).buffer))}function l(){return o.createVertexArray()}function c(R){return o.bindVertexArray(R)}function h(R){return o.deleteVertexArray(R)}function d(R,L,P,O){const k=O.wireframe===!0;let F=i[L.id];F===void 0&&(F={},i[L.id]=F);const z=R.isInstancedMesh===!0?R.id:0;let V=F[z];V===void 0&&(V={},F[z]=V);let K=V[P.id];K===void 0&&(K={},V[P.id]=K);let q=K[k];return q===void 0&&(q=u(l()),K[k]=q),q}function u(R){const L=[],P=[],O=[];for(let k=0;k<t;k++)L[k]=0,P[k]=0,O[k]=0;return{geometry:null,program:null,wireframe:!1,newAttributes:L,enabledAttributes:P,attributeDivisors:O,object:R,attributes:{},index:null}}function f(R,L,P,O){const k=s.attributes,F=L.attributes;let z=0;const V=P.getAttributes();for(const K in V)if(V[K].location>=0){const te=k[K];let re=F[K];if(re===void 0&&(K==="instanceMatrix"&&R.instanceMatrix&&(re=R.instanceMatrix),K==="instanceColor"&&R.instanceColor&&(re=R.instanceColor)),te===void 0||te.attribute!==re||re&&te.data!==re.data)return!0;z++}return s.attributesNum!==z||s.index!==O}function p(R,L,P,O){const k={},F=L.attributes;let z=0;const V=P.getAttributes();for(const K in V)if(V[K].location>=0){let te=F[K];te===void 0&&(K==="instanceMatrix"&&R.instanceMatrix&&(te=R.instanceMatrix),K==="instanceColor"&&R.instanceColor&&(te=R.instanceColor));const re={};re.attribute=te,te&&te.data&&(re.data=te.data),k[K]=re,z++}s.attributes=k,s.attributesNum=z,s.index=O}function g(){const R=s.newAttributes;for(let L=0,P=R.length;L<P;L++)R[L]=0}function m(R){v(R,0)}function v(R,L){const P=s.newAttributes,O=s.enabledAttributes,k=s.attributeDivisors;P[R]=1,O[R]===0&&(o.enableVertexAttribArray(R),O[R]=1),k[R]!==L&&(o.vertexAttribDivisor(R,L),k[R]=L)}function b(){const R=s.newAttributes,L=s.enabledAttributes;for(let P=0,O=L.length;P<O;P++)L[P]!==R[P]&&(o.disableVertexAttribArray(P),L[P]=0)}function x(R,L,P,O,k,F,z){z===!0?o.vertexAttribIPointer(R,L,P,k,F):o.vertexAttribPointer(R,L,P,O,k,F)}function y(R,L,P,O){g();const k=O.attributes,F=P.getAttributes(),z=L.defaultAttributeValues;for(const V in F){const K=F[V];if(K.location>=0){let q=k[V];if(q===void 0&&(V==="instanceMatrix"&&R.instanceMatrix&&(q=R.instanceMatrix),V==="instanceColor"&&R.instanceColor&&(q=R.instanceColor)),q!==void 0){const te=q.normalized,re=q.itemSize,Ge=e.get(q);if(Ge===void 0)continue;const ft=Ge.buffer,it=Ge.type,Z=Ge.bytesPerElement,ae=it===o.INT||it===o.UNSIGNED_INT||q.gpuType===lg;if(q.isInterleavedBufferAttribute){const se=q.data,G=se.stride,Re=q.offset;if(se.isInstancedInterleavedBuffer){for(let ze=0;ze<K.locationSize;ze++)v(K.location+ze,se.meshPerAttribute);R.isInstancedMesh!==!0&&O._maxInstanceCount===void 0&&(O._maxInstanceCount=se.meshPerAttribute*se.count)}else for(let ze=0;ze<K.locationSize;ze++)m(K.location+ze);o.bindBuffer(o.ARRAY_BUFFER,ft);for(let ze=0;ze<K.locationSize;ze++)x(K.location+ze,re/K.locationSize,it,te,G*Z,(Re+re/K.locationSize*ze)*Z,ae)}else{if(q.isInstancedBufferAttribute){for(let se=0;se<K.locationSize;se++)v(K.location+se,q.meshPerAttribute);R.isInstancedMesh!==!0&&O._maxInstanceCount===void 0&&(O._maxInstanceCount=q.meshPerAttribute*q.count)}else for(let se=0;se<K.locationSize;se++)m(K.location+se);o.bindBuffer(o.ARRAY_BUFFER,ft);for(let se=0;se<K.locationSize;se++)x(K.location+se,re/K.locationSize,it,te,re*Z,re/K.locationSize*se*Z,ae)}}else if(z!==void 0){const te=z[V];if(te!==void 0)switch(te.length){case 2:o.vertexAttrib2fv(K.location,te);break;case 3:o.vertexAttrib3fv(K.location,te);break;case 4:o.vertexAttrib4fv(K.location,te);break;default:o.vertexAttrib1fv(K.location,te)}}}}b()}function w(){_();for(const R in i){const L=i[R];for(const P in L){const O=L[P];for(const k in O){const F=O[k];for(const z in F)h(F[z].object),delete F[z];delete O[k]}}delete i[R]}}function S(R){if(i[R.id]===void 0)return;const L=i[R.id];for(const P in L){const O=L[P];for(const k in O){const F=O[k];for(const z in F)h(F[z].object),delete F[z];delete O[k]}}delete i[R.id]}function A(R){for(const L in i){const P=i[L];for(const O in P){const k=P[O];if(k[R.id]===void 0)continue;const F=k[R.id];for(const z in F)h(F[z].object),delete F[z];delete k[R.id]}}}function M(R){for(const L in i){const P=i[L],O=R.isInstancedMesh===!0?R.id:0,k=P[O];if(k!==void 0){for(const F in k){const z=k[F];for(const V in z)h(z[V].object),delete z[V];delete k[F]}delete P[O],Object.keys(P).length===0&&delete i[L]}}}function _(){I(),r=!0,s!==n&&(s=n,c(s.object))}function I(){n.geometry=null,n.program=null,n.wireframe=!1}return{setup:a,reset:_,resetDefaultState:I,dispose:w,releaseStatesOfGeometry:S,releaseStatesOfObject:M,releaseStatesOfProgram:A,initAttributes:g,enableAttribute:m,disableUnusedAttributes:b}}function l5(o,e,t){let i;function n(l){i=l}function s(l,c){o.drawArrays(i,l,c),t.update(c,i,1)}function r(l,c,h){h!==0&&(o.drawArraysInstanced(i,l,c,h),t.update(c,i,h))}function a(l,c,h){if(h===0)return;e.get("WEBGL_multi_draw").multiDrawArraysWEBGL(i,l,0,c,0,h);let u=0;for(let f=0;f<h;f++)u+=c[f];t.update(u,i,1)}this.setMode=n,this.render=s,this.renderInstances=r,this.renderMultiDraw=a}function c5(o,e,t,i){let n;function s(){if(n!==void 0)return n;if(e.has("EXT_texture_filter_anisotropic")===!0){const A=e.get("EXT_texture_filter_anisotropic");n=o.getParameter(A.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else n=0;return n}function r(A){return!(A!==Vi&&i.convert(A)!==o.getParameter(o.IMPLEMENTATION_COLOR_READ_FORMAT))}function a(A){const M=A===ci&&(e.has("EXT_color_buffer_half_float")||e.has("EXT_color_buffer_float"));return!(A!==zn&&i.convert(A)!==o.getParameter(o.IMPLEMENTATION_COLOR_READ_TYPE)&&A!==En&&!M)}function l(A){if(A==="highp"){if(o.getShaderPrecisionFormat(o.VERTEX_SHADER,o.HIGH_FLOAT).precision>0&&o.getShaderPrecisionFormat(o.FRAGMENT_SHADER,o.HIGH_FLOAT).precision>0)return"highp";A="mediump"}return A==="mediump"&&o.getShaderPrecisionFormat(o.VERTEX_SHADER,o.MEDIUM_FLOAT).precision>0&&o.getShaderPrecisionFormat(o.FRAGMENT_SHADER,o.MEDIUM_FLOAT).precision>0?"mediump":"lowp"}let c=t.precision!==void 0?t.precision:"highp";const h=l(c);h!==c&&(ke("WebGLRenderer:",c,"not supported, using",h,"instead."),c=h);const d=t.logarithmicDepthBuffer===!0,u=t.reversedDepthBuffer===!0&&e.has("EXT_clip_control");t.reversedDepthBuffer===!0&&u===!1&&ke("WebGLRenderer: Unable to use reversed depth buffer due to missing EXT_clip_control extension. Fallback to default depth buffer.");const f=o.getParameter(o.MAX_TEXTURE_IMAGE_UNITS),p=o.getParameter(o.MAX_VERTEX_TEXTURE_IMAGE_UNITS),g=o.getParameter(o.MAX_TEXTURE_SIZE),m=o.getParameter(o.MAX_CUBE_MAP_TEXTURE_SIZE),v=o.getParameter(o.MAX_VERTEX_ATTRIBS),b=o.getParameter(o.MAX_VERTEX_UNIFORM_VECTORS),x=o.getParameter(o.MAX_VARYING_VECTORS),y=o.getParameter(o.MAX_FRAGMENT_UNIFORM_VECTORS),w=o.getParameter(o.MAX_SAMPLES),S=o.getParameter(o.SAMPLES);return{isWebGL2:!0,getMaxAnisotropy:s,getMaxPrecision:l,textureFormatReadable:r,textureTypeReadable:a,precision:c,logarithmicDepthBuffer:d,reversedDepthBuffer:u,maxTextures:f,maxVertexTextures:p,maxTextureSize:g,maxCubemapSize:m,maxAttributes:v,maxVertexUniforms:b,maxVaryings:x,maxFragmentUniforms:y,maxSamples:w,samples:S}}function h5(o){const e=this;let t=null,i=0,n=!1,s=!1;const r=new ma,a=new Je,l={value:null,needsUpdate:!1};this.uniform=l,this.numPlanes=0,this.numIntersection=0,this.init=function(d,u){const f=d.length!==0||u||i!==0||n;return n=u,i=d.length,f},this.beginShadows=function(){s=!0,h(null)},this.endShadows=function(){s=!1},this.setGlobalState=function(d,u){t=h(d,u,0)},this.setState=function(d,u,f){const p=d.clippingPlanes,g=d.clipIntersection,m=d.clipShadows,v=o.get(d);if(!n||p===null||p.length===0||s&&!m)s?h(null):c();else{const b=s?0:i,x=b*4;let y=v.clippingState||null;l.value=y,y=h(p,u,x,f);for(let w=0;w!==x;++w)y[w]=t[w];v.clippingState=y,this.numIntersection=g?this.numPlanes:0,this.numPlanes+=b}};function c(){l.value!==t&&(l.value=t,l.needsUpdate=i>0),e.numPlanes=i,e.numIntersection=0}function h(d,u,f,p){const g=d!==null?d.length:0;let m=null;if(g!==0){if(m=l.value,p!==!0||m===null){const v=f+g*4,b=u.matrixWorldInverse;a.getNormalMatrix(b),(m===null||m.length<v)&&(m=new Float32Array(v));for(let x=0,y=f;x!==g;++x,y+=4)r.copy(d[x]).applyMatrix4(b,a),r.normal.toArray(m,y),m[y+3]=r.constant}l.value=m,l.needsUpdate=!0}return e.numPlanes=g,e.numIntersection=0,m}}const Sa=4,j1=[.125,.215,.35,.446,.526,.582],to=20,d5=256,Dc=new $s,J1=new ne;let xp=null,Sp=0,Ep=0,Ap=!1;const u5=new D;class mm{constructor(e){this._renderer=e,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._sizeLods=[],this._sigmas=[],this._lodMeshes=[],this._backgroundBox=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._blurMaterial=null,this._ggxMaterial=null}fromScene(e,t=0,i=.1,n=100,s={}){const{size:r=256,position:a=u5}=s;xp=this._renderer.getRenderTarget(),Sp=this._renderer.getActiveCubeFace(),Ep=this._renderer.getActiveMipmapLevel(),Ap=this._renderer.xr.enabled,this._renderer.xr.enabled=!1,this._setSize(r);const l=this._allocateTargets();return l.depthBuffer=!0,this._sceneToCubeUV(e,i,n,l,a),t>0&&this._blur(l,0,0,t),this._applyPMREM(l),this._cleanup(l),l}fromEquirectangular(e,t=null){return this._fromTexture(e,t)}fromCubemap(e,t=null){return this._fromTexture(e,t)}compileCubemapShader(){this._cubemapMaterial===null&&(this._cubemapMaterial=ty(),this._compileMaterial(this._cubemapMaterial))}compileEquirectangularShader(){this._equirectMaterial===null&&(this._equirectMaterial=ey(),this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),this._cubemapMaterial!==null&&this._cubemapMaterial.dispose(),this._equirectMaterial!==null&&this._equirectMaterial.dispose(),this._backgroundBox!==null&&(this._backgroundBox.geometry.dispose(),this._backgroundBox.material.dispose())}_setSize(e){this._lodMax=Math.floor(Math.log2(e)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){this._blurMaterial!==null&&this._blurMaterial.dispose(),this._ggxMaterial!==null&&this._ggxMaterial.dispose(),this._pingPongRenderTarget!==null&&this._pingPongRenderTarget.dispose();for(let e=0;e<this._lodMeshes.length;e++)this._lodMeshes[e].geometry.dispose()}_cleanup(e){this._renderer.setRenderTarget(xp,Sp,Ep),this._renderer.xr.enabled=Ap,e.scissorTest=!1,pl(e,0,0,e.width,e.height)}_fromTexture(e,t){e.mapping===Oo||e.mapping===rc?this._setSize(e.image.length===0?16:e.image[0].width||e.image[0].image.width):this._setSize(e.image.width/4),xp=this._renderer.getRenderTarget(),Sp=this._renderer.getActiveCubeFace(),Ep=this._renderer.getActiveMipmapLevel(),Ap=this._renderer.xr.enabled,this._renderer.xr.enabled=!1;const i=t||this._allocateTargets();return this._textureToCubeUV(e,i),this._applyPMREM(i),this._cleanup(i),i}_allocateTargets(){const e=3*Math.max(this._cubeSize,112),t=4*this._cubeSize,i={magFilter:mt,minFilter:mt,generateMipmaps:!1,type:ci,format:Vi,colorSpace:Gu,depthBuffer:!1},n=Q1(e,t,i);if(this._pingPongRenderTarget===null||this._pingPongRenderTarget.width!==e||this._pingPongRenderTarget.height!==t){this._pingPongRenderTarget!==null&&this._dispose(),this._pingPongRenderTarget=Q1(e,t,i);const{_lodMax:s}=this;({lodMeshes:this._lodMeshes,sizeLods:this._sizeLods,sigmas:this._sigmas}=f5(s)),this._blurMaterial=m5(s,e,t),this._ggxMaterial=p5(s,e,t)}return n}_compileMaterial(e){const t=new Se(new ot,e);this._renderer.compile(t,Dc)}_sceneToCubeUV(e,t,i,n,s){const l=new Qn(90,1,t,i),c=[1,-1,1,1,1,1],h=[1,1,1,-1,-1,-1],d=this._renderer,u=d.autoClear,f=d.toneMapping;d.getClearColor(J1),d.toneMapping=Mr,d.autoClear=!1,d.state.buffers.depth.getReversed()&&(d.setRenderTarget(n),d.clearDepth(),d.setRenderTarget(null)),this._backgroundBox===null&&(this._backgroundBox=new Se(new cn,new Hn({name:"PMREM.Background",side:fi,depthWrite:!1,depthTest:!1})));const g=this._backgroundBox,m=g.material;let v=!1;const b=e.background;b?b.isColor&&(m.color.copy(b),e.background=null,v=!0):(m.color.copy(J1),v=!0);for(let x=0;x<6;x++){const y=x%3;y===0?(l.up.set(0,c[x],0),l.position.set(s.x,s.y,s.z),l.lookAt(s.x+h[x],s.y,s.z)):y===1?(l.up.set(0,0,c[x]),l.position.set(s.x,s.y,s.z),l.lookAt(s.x,s.y+h[x],s.z)):(l.up.set(0,c[x],0),l.position.set(s.x,s.y,s.z),l.lookAt(s.x,s.y,s.z+h[x]));const w=this._cubeSize;pl(n,y*w,x>2?w:0,w,w),d.setRenderTarget(n),v&&d.render(g,l),d.render(e,l)}d.toneMapping=f,d.autoClear=u,e.background=b}_textureToCubeUV(e,t){const i=this._renderer,n=e.mapping===Oo||e.mapping===rc;n?(this._cubemapMaterial===null&&(this._cubemapMaterial=ty()),this._cubemapMaterial.uniforms.flipEnvMap.value=e.isRenderTargetTexture===!1?-1:1):this._equirectMaterial===null&&(this._equirectMaterial=ey());const s=n?this._cubemapMaterial:this._equirectMaterial,r=this._lodMeshes[0];r.material=s;const a=s.uniforms;a.envMap.value=e;const l=this._cubeSize;pl(t,0,0,3*l,2*l),i.setRenderTarget(t),i.render(r,Dc)}_applyPMREM(e){const t=this._renderer,i=t.autoClear;t.autoClear=!1;const n=this._lodMeshes.length;for(let s=1;s<n;s++)this._applyGGXFilter(e,s-1,s);t.autoClear=i}_applyGGXFilter(e,t,i){const n=this._renderer,s=this._pingPongRenderTarget,r=this._ggxMaterial,a=this._lodMeshes[i];a.material=r;const l=r.uniforms,c=i/(this._lodMeshes.length-1),h=t/(this._lodMeshes.length-1),d=Math.sqrt(c*c-h*h),u=0+c*1.25,f=d*u,{_lodMax:p}=this,g=this._sizeLods[i],m=3*g*(i>p-Sa?i-p+Sa:0),v=4*(this._cubeSize-g);l.envMap.value=e.texture,l.roughness.value=f,l.mipInt.value=p-t,pl(s,m,v,3*g,2*g),n.setRenderTarget(s),n.render(a,Dc),l.envMap.value=s.texture,l.roughness.value=0,l.mipInt.value=p-i,pl(e,m,v,3*g,2*g),n.setRenderTarget(e),n.render(a,Dc)}_blur(e,t,i,n,s){const r=this._pingPongRenderTarget;this._halfBlur(e,r,t,i,n,"latitudinal",s),this._halfBlur(r,e,i,i,n,"longitudinal",s)}_halfBlur(e,t,i,n,s,r,a){const l=this._renderer,c=this._blurMaterial;r!=="latitudinal"&&r!=="longitudinal"&&je("blur direction must be either latitudinal or longitudinal!");const h=3,d=this._lodMeshes[n];d.material=c;const u=c.uniforms,f=this._sizeLods[i]-1,p=isFinite(s)?Math.PI/(2*f):2*Math.PI/(2*to-1),g=s/p,m=isFinite(s)?1+Math.floor(h*g):to;m>to&&ke(`sigmaRadians, ${s}, is too large and will clip, as it requested ${m} samples when the maximum is set to ${to}`);const v=[];let b=0;for(let A=0;A<to;++A){const M=A/g,_=Math.exp(-M*M/2);v.push(_),A===0?b+=_:A<m&&(b+=2*_)}for(let A=0;A<v.length;A++)v[A]=v[A]/b;u.envMap.value=e.texture,u.samples.value=m,u.weights.value=v,u.latitudinal.value=r==="latitudinal",a&&(u.poleAxis.value=a);const{_lodMax:x}=this;u.dTheta.value=p,u.mipInt.value=x-i;const y=this._sizeLods[n],w=3*y*(n>x-Sa?n-x+Sa:0),S=4*(this._cubeSize-y);pl(t,w,S,3*y,2*y),l.setRenderTarget(t),l.render(d,Dc)}}function f5(o){const e=[],t=[],i=[];let n=o;const s=o-Sa+1+j1.length;for(let r=0;r<s;r++){const a=Math.pow(2,n);e.push(a);let l=1/a;r>o-Sa?l=j1[r-o+Sa-1]:r===0&&(l=0),t.push(l);const c=1/(a-2),h=-c,d=1+c,u=[h,h,d,h,d,d,h,h,d,d,h,d],f=6,p=6,g=3,m=2,v=1,b=new Float32Array(g*p*f),x=new Float32Array(m*p*f),y=new Float32Array(v*p*f);for(let S=0;S<f;S++){const A=S%3*2/3-1,M=S>2?0:-1,_=[A,M,0,A+2/3,M,0,A+2/3,M+1,0,A,M,0,A+2/3,M+1,0,A,M+1,0];b.set(_,g*p*S),x.set(u,m*p*S);const I=[S,S,S,S,S,S];y.set(I,v*p*S)}const w=new ot;w.setAttribute("position",new st(b,g)),w.setAttribute("uv",new st(x,m)),w.setAttribute("faceIndex",new st(y,v)),i.push(new Se(w,null)),n>Sa&&n--}return{lodMeshes:i,sizeLods:e,sigmas:t}}function Q1(o,e,t){const i=new Mi(o,e,t);return i.texture.mapping=Sf,i.texture.name="PMREM.cubeUv",i.scissorTest=!0,i}function pl(o,e,t,i,n){o.viewport.set(e,t,i,n),o.scissor.set(e,t,i,n)}function p5(o,e,t){return new Dt({name:"PMREMGGXConvolution",defines:{GGX_SAMPLES:d5,CUBEUV_TEXEL_WIDTH:1/e,CUBEUV_TEXEL_HEIGHT:1/t,CUBEUV_MAX_MIP:`${o}.0`},uniforms:{envMap:{value:null},roughness:{value:0},mipInt:{value:0}},vertexShader:_f(),fragmentShader:`
6834
6834
 
6835
6835
  precision highp float;
6836
6836
  precision highp int;
@@ -7119,7 +7119,7 @@ void main() {
7119
7119
  gl_FragColor = texture2D( tEquirect, sampleUV );
7120
7120
 
7121
7121
  }
7122
- `},n=new cn(5,5,5),s=new Dt({name:"CubemapFromEquirect",uniforms:lc(i.uniforms),vertexShader:i.vertexShader,fragmentShader:i.fragmentShader,side:fi,blending:br});s.uniforms.tEquirect.value=t;const r=new Se(n,s),a=t.minFilter;return t.minFilter===gr&&(t.minFilter=mt),new Ig(1,10,this).update(e,r),t.minFilter=a,r.geometry.dispose(),r.material.dispose(),this}clear(e,t=!0,i=!0,n=!0){const s=e.getRenderTarget();for(let r=0;r<6;r++)e.setRenderTarget(this,r),e.clear(t,i,n);e.setRenderTarget(s)}}function g5(o){let e=new WeakMap,t=new WeakMap,i=null;function n(u,f=!1){return u==null?null:f?r(u):s(u)}function s(u){if(u&&u.isTexture){const f=u.mapping;if(f===Vf||f===Wf)if(e.has(u)){const p=e.get(u).texture;return a(p,u.mapping)}else{const p=u.image;if(p&&p.height>0){const g=new Eh(p.height);return g.fromEquirectangularTexture(o,u),e.set(u,g),u.addEventListener("dispose",c),a(g.texture,u.mapping)}else return null}}return u}function r(u){if(u&&u.isTexture){const f=u.mapping,p=f===Vf||f===Wf,g=f===Oo||f===rc;if(p||g){let m=t.get(u);const v=m!==void 0?m.texture.pmremVersion:0;if(u.isRenderTargetTexture&&u.pmremVersion!==v)return i===null&&(i=new mm(o)),m=p?i.fromEquirectangular(u,m):i.fromCubemap(u,m),m.texture.pmremVersion=u.pmremVersion,t.set(u,m),m.texture;if(m!==void 0)return m.texture;{const b=u.image;return p&&b&&b.height>0||g&&b&&l(b)?(i===null&&(i=new mm(o)),m=p?i.fromEquirectangular(u):i.fromCubemap(u),m.texture.pmremVersion=u.pmremVersion,t.set(u,m),u.addEventListener("dispose",h),m.texture):null}}}return u}function a(u,f){return f===Vf?u.mapping=Oo:f===Wf&&(u.mapping=rc),u}function l(u){let f=0;const p=6;for(let g=0;g<p;g++)u[g]!==void 0&&f++;return f===p}function c(u){const f=u.target;f.removeEventListener("dispose",c);const p=e.get(f);p!==void 0&&(e.delete(f),p.dispose())}function h(u){const f=u.target;f.removeEventListener("dispose",h);const p=t.get(f);p!==void 0&&(t.delete(f),p.dispose())}function d(){e=new WeakMap,t=new WeakMap,i!==null&&(i.dispose(),i=null)}return{get:n,dispose:d}}function v5(o){const e={};function t(i){if(e[i]!==void 0)return e[i];const n=o.getExtension(i);return e[i]=n,n}return{has:function(i){return t(i)!==null},init:function(){t("EXT_color_buffer_float"),t("WEBGL_clip_cull_distance"),t("OES_texture_float_linear"),t("EXT_color_buffer_half_float"),t("WEBGL_multisampled_render_to_texture"),t("WEBGL_render_shared_exponent")},get:function(i){const n=t(i);return n===null&&Hl("WebGLRenderer: "+i+" extension not supported."),n}}}function y5(o,e,t,i){const n={},s=new WeakMap;function r(d){const u=d.target;u.index!==null&&e.remove(u.index);for(const p in u.attributes)e.remove(u.attributes[p]);u.removeEventListener("dispose",r),delete n[u.id];const f=s.get(u);f&&(e.remove(f),s.delete(u)),i.releaseStatesOfGeometry(u),u.isInstancedBufferGeometry===!0&&delete u._maxInstanceCount,t.memory.geometries--}function a(d,u){return n[u.id]===!0||(u.addEventListener("dispose",r),n[u.id]=!0,t.memory.geometries++),u}function l(d){const u=d.attributes;for(const f in u)e.update(u[f],o.ARRAY_BUFFER)}function c(d){const u=[],f=d.index,p=d.attributes.position;let g=0;if(p===void 0)return;if(f!==null){const b=f.array;g=f.version;for(let x=0,y=b.length;x<y;x+=3){const w=b[x+0],S=b[x+1],A=b[x+2];u.push(w,S,S,A,A,w)}}else{const b=p.array;g=p.version;for(let x=0,y=b.length/3-1;x<y;x+=3){const w=x+0,S=x+1,A=x+2;u.push(w,S,S,A,A,w)}}const m=new(p.count>=65535?wg:hw)(u,1);m.version=g;const v=s.get(d);v&&e.remove(v),s.set(d,m)}function h(d){const u=s.get(d);if(u){const f=d.index;f!==null&&u.version<f.version&&c(d)}else c(d);return s.get(d)}return{get:a,update:l,getWireframeAttribute:h}}function b5(o,e,t){let i;function n(d){i=d}let s,r;function a(d){s=d.type,r=d.bytesPerElement}function l(d,u){o.drawElements(i,u,s,d*r),t.update(u,i,1)}function c(d,u,f){f!==0&&(o.drawElementsInstanced(i,u,s,d*r,f),t.update(u,i,f))}function h(d,u,f){if(f===0)return;e.get("WEBGL_multi_draw").multiDrawElementsWEBGL(i,u,0,s,d,0,f);let g=0;for(let m=0;m<f;m++)g+=u[m];t.update(g,i,1)}this.setMode=n,this.setIndex=a,this.render=l,this.renderInstances=c,this.renderMultiDraw=h}function M5(o){const e={geometries:0,textures:0},t={frame:0,calls:0,triangles:0,points:0,lines:0};function i(s,r,a){switch(t.calls++,r){case o.TRIANGLES:t.triangles+=a*(s/3);break;case o.LINES:t.lines+=a*(s/2);break;case o.LINE_STRIP:t.lines+=a*(s-1);break;case o.LINE_LOOP:t.lines+=a*s;break;case o.POINTS:t.points+=a*s;break;default:Ze("WebGLInfo: Unknown draw mode:",r);break}}function n(){t.calls=0,t.triangles=0,t.points=0,t.lines=0}return{memory:e,render:t,programs:null,autoReset:!0,reset:n,update:i}}function w5(o,e,t){const i=new WeakMap,n=new wt;function s(r,a,l){const c=r.morphTargetInfluences,h=a.morphAttributes.position||a.morphAttributes.normal||a.morphAttributes.color,d=h!==void 0?h.length:0;let u=i.get(a);if(u===void 0||u.count!==d){let _=function(){A.dispose(),i.delete(a),a.removeEventListener("dispose",_)};u!==void 0&&u.texture.dispose();const f=a.morphAttributes.position!==void 0,p=a.morphAttributes.normal!==void 0,g=a.morphAttributes.color!==void 0,m=a.morphAttributes.position||[],v=a.morphAttributes.normal||[],b=a.morphAttributes.color||[];let x=0;f===!0&&(x=1),p===!0&&(x=2),g===!0&&(x=3);let y=a.attributes.position.count*x,w=1;y>e.maxTextureSize&&(w=Math.ceil(y/e.maxTextureSize),y=e.maxTextureSize);const S=new Float32Array(y*w*4*d),A=new ow(S,y,w,d);A.type=En,A.needsUpdate=!0;const M=x*4;for(let I=0;I<d;I++){const R=m[I],L=v[I],P=b[I],O=y*w*4*I;for(let k=0;k<R.count;k++){const F=k*M;f===!0&&(n.fromBufferAttribute(R,k),S[O+F+0]=n.x,S[O+F+1]=n.y,S[O+F+2]=n.z,S[O+F+3]=0),p===!0&&(n.fromBufferAttribute(L,k),S[O+F+4]=n.x,S[O+F+5]=n.y,S[O+F+6]=n.z,S[O+F+7]=0),g===!0&&(n.fromBufferAttribute(P,k),S[O+F+8]=n.x,S[O+F+9]=n.y,S[O+F+10]=n.z,S[O+F+11]=P.itemSize===4?n.w:1)}}u={count:d,texture:A,size:new we(y,w)},i.set(a,u),a.addEventListener("dispose",_)}if(r.isInstancedMesh===!0&&r.morphTexture!==null)l.getUniforms().setValue(o,"morphTexture",r.morphTexture,t);else{let f=0;for(let g=0;g<c.length;g++)f+=c[g];const p=a.morphTargetsRelative?1:1-f;l.getUniforms().setValue(o,"morphTargetBaseInfluence",p),l.getUniforms().setValue(o,"morphTargetInfluences",c)}l.getUniforms().setValue(o,"morphTargetsTexture",u.texture,t),l.getUniforms().setValue(o,"morphTargetsTextureSize",u.size)}return{update:s}}function x5(o,e,t,i,n){let s=new WeakMap;function r(c){const h=n.render.frame,d=c.geometry,u=e.get(c,d);if(s.get(u)!==h&&(e.update(u),s.set(u,h)),c.isInstancedMesh&&(c.hasEventListener("dispose",l)===!1&&c.addEventListener("dispose",l),s.get(c)!==h&&(t.update(c.instanceMatrix,o.ARRAY_BUFFER),c.instanceColor!==null&&t.update(c.instanceColor,o.ARRAY_BUFFER),s.set(c,h))),c.isSkinnedMesh){const f=c.skeleton;s.get(f)!==h&&(f.update(),s.set(f,h))}return u}function a(){s=new WeakMap}function l(c){const h=c.target;h.removeEventListener("dispose",l),i.releaseStatesOfObject(h),t.remove(h.instanceMatrix),h.instanceColor!==null&&t.remove(h.instanceColor)}return{update:r,dispose:a}}const S5={[XM]:"LINEAR_TONE_MAPPING",[$M]:"REINHARD_TONE_MAPPING",[YM]:"CINEON_TONE_MAPPING",[qM]:"ACES_FILMIC_TONE_MAPPING",[ZM]:"AGX_TONE_MAPPING",[jM]:"NEUTRAL_TONE_MAPPING",[KM]:"CUSTOM_TONE_MAPPING"};function E5(o,e,t,i,n,s){const r=new Mi(e,t,{type:o,depthBuffer:n,stencilBuffer:s,samples:i?4:0,depthTexture:n?new La(e,t):void 0}),a=new Mi(e,t,{type:ci,depthBuffer:!1,stencilBuffer:!1}),l=new ot;l.setAttribute("position",new yt([-1,3,0,-1,-1,0,3,-1,0],3)),l.setAttribute("uv",new yt([0,2,0,0,2,0],2));const c=new yw({uniforms:{tDiffuse:{value:null}},vertexShader:`
7122
+ `},n=new cn(5,5,5),s=new Dt({name:"CubemapFromEquirect",uniforms:lc(i.uniforms),vertexShader:i.vertexShader,fragmentShader:i.fragmentShader,side:fi,blending:br});s.uniforms.tEquirect.value=t;const r=new Se(n,s),a=t.minFilter;return t.minFilter===gr&&(t.minFilter=mt),new Ig(1,10,this).update(e,r),t.minFilter=a,r.geometry.dispose(),r.material.dispose(),this}clear(e,t=!0,i=!0,n=!0){const s=e.getRenderTarget();for(let r=0;r<6;r++)e.setRenderTarget(this,r),e.clear(t,i,n);e.setRenderTarget(s)}}function g5(o){let e=new WeakMap,t=new WeakMap,i=null;function n(u,f=!1){return u==null?null:f?r(u):s(u)}function s(u){if(u&&u.isTexture){const f=u.mapping;if(f===Vf||f===Wf)if(e.has(u)){const p=e.get(u).texture;return a(p,u.mapping)}else{const p=u.image;if(p&&p.height>0){const g=new Eh(p.height);return g.fromEquirectangularTexture(o,u),e.set(u,g),u.addEventListener("dispose",c),a(g.texture,u.mapping)}else return null}}return u}function r(u){if(u&&u.isTexture){const f=u.mapping,p=f===Vf||f===Wf,g=f===Oo||f===rc;if(p||g){let m=t.get(u);const v=m!==void 0?m.texture.pmremVersion:0;if(u.isRenderTargetTexture&&u.pmremVersion!==v)return i===null&&(i=new mm(o)),m=p?i.fromEquirectangular(u,m):i.fromCubemap(u,m),m.texture.pmremVersion=u.pmremVersion,t.set(u,m),m.texture;if(m!==void 0)return m.texture;{const b=u.image;return p&&b&&b.height>0||g&&b&&l(b)?(i===null&&(i=new mm(o)),m=p?i.fromEquirectangular(u):i.fromCubemap(u),m.texture.pmremVersion=u.pmremVersion,t.set(u,m),u.addEventListener("dispose",h),m.texture):null}}}return u}function a(u,f){return f===Vf?u.mapping=Oo:f===Wf&&(u.mapping=rc),u}function l(u){let f=0;const p=6;for(let g=0;g<p;g++)u[g]!==void 0&&f++;return f===p}function c(u){const f=u.target;f.removeEventListener("dispose",c);const p=e.get(f);p!==void 0&&(e.delete(f),p.dispose())}function h(u){const f=u.target;f.removeEventListener("dispose",h);const p=t.get(f);p!==void 0&&(t.delete(f),p.dispose())}function d(){e=new WeakMap,t=new WeakMap,i!==null&&(i.dispose(),i=null)}return{get:n,dispose:d}}function v5(o){const e={};function t(i){if(e[i]!==void 0)return e[i];const n=o.getExtension(i);return e[i]=n,n}return{has:function(i){return t(i)!==null},init:function(){t("EXT_color_buffer_float"),t("WEBGL_clip_cull_distance"),t("OES_texture_float_linear"),t("EXT_color_buffer_half_float"),t("WEBGL_multisampled_render_to_texture"),t("WEBGL_render_shared_exponent")},get:function(i){const n=t(i);return n===null&&Hl("WebGLRenderer: "+i+" extension not supported."),n}}}function y5(o,e,t,i){const n={},s=new WeakMap;function r(d){const u=d.target;u.index!==null&&e.remove(u.index);for(const p in u.attributes)e.remove(u.attributes[p]);u.removeEventListener("dispose",r),delete n[u.id];const f=s.get(u);f&&(e.remove(f),s.delete(u)),i.releaseStatesOfGeometry(u),u.isInstancedBufferGeometry===!0&&delete u._maxInstanceCount,t.memory.geometries--}function a(d,u){return n[u.id]===!0||(u.addEventListener("dispose",r),n[u.id]=!0,t.memory.geometries++),u}function l(d){const u=d.attributes;for(const f in u)e.update(u[f],o.ARRAY_BUFFER)}function c(d){const u=[],f=d.index,p=d.attributes.position;let g=0;if(p===void 0)return;if(f!==null){const b=f.array;g=f.version;for(let x=0,y=b.length;x<y;x+=3){const w=b[x+0],S=b[x+1],A=b[x+2];u.push(w,S,S,A,A,w)}}else{const b=p.array;g=p.version;for(let x=0,y=b.length/3-1;x<y;x+=3){const w=x+0,S=x+1,A=x+2;u.push(w,S,S,A,A,w)}}const m=new(p.count>=65535?wg:hw)(u,1);m.version=g;const v=s.get(d);v&&e.remove(v),s.set(d,m)}function h(d){const u=s.get(d);if(u){const f=d.index;f!==null&&u.version<f.version&&c(d)}else c(d);return s.get(d)}return{get:a,update:l,getWireframeAttribute:h}}function b5(o,e,t){let i;function n(d){i=d}let s,r;function a(d){s=d.type,r=d.bytesPerElement}function l(d,u){o.drawElements(i,u,s,d*r),t.update(u,i,1)}function c(d,u,f){f!==0&&(o.drawElementsInstanced(i,u,s,d*r,f),t.update(u,i,f))}function h(d,u,f){if(f===0)return;e.get("WEBGL_multi_draw").multiDrawElementsWEBGL(i,u,0,s,d,0,f);let g=0;for(let m=0;m<f;m++)g+=u[m];t.update(g,i,1)}this.setMode=n,this.setIndex=a,this.render=l,this.renderInstances=c,this.renderMultiDraw=h}function M5(o){const e={geometries:0,textures:0},t={frame:0,calls:0,triangles:0,points:0,lines:0};function i(s,r,a){switch(t.calls++,r){case o.TRIANGLES:t.triangles+=a*(s/3);break;case o.LINES:t.lines+=a*(s/2);break;case o.LINE_STRIP:t.lines+=a*(s-1);break;case o.LINE_LOOP:t.lines+=a*s;break;case o.POINTS:t.points+=a*s;break;default:je("WebGLInfo: Unknown draw mode:",r);break}}function n(){t.calls=0,t.triangles=0,t.points=0,t.lines=0}return{memory:e,render:t,programs:null,autoReset:!0,reset:n,update:i}}function w5(o,e,t){const i=new WeakMap,n=new wt;function s(r,a,l){const c=r.morphTargetInfluences,h=a.morphAttributes.position||a.morphAttributes.normal||a.morphAttributes.color,d=h!==void 0?h.length:0;let u=i.get(a);if(u===void 0||u.count!==d){let _=function(){A.dispose(),i.delete(a),a.removeEventListener("dispose",_)};u!==void 0&&u.texture.dispose();const f=a.morphAttributes.position!==void 0,p=a.morphAttributes.normal!==void 0,g=a.morphAttributes.color!==void 0,m=a.morphAttributes.position||[],v=a.morphAttributes.normal||[],b=a.morphAttributes.color||[];let x=0;f===!0&&(x=1),p===!0&&(x=2),g===!0&&(x=3);let y=a.attributes.position.count*x,w=1;y>e.maxTextureSize&&(w=Math.ceil(y/e.maxTextureSize),y=e.maxTextureSize);const S=new Float32Array(y*w*4*d),A=new ow(S,y,w,d);A.type=En,A.needsUpdate=!0;const M=x*4;for(let I=0;I<d;I++){const R=m[I],L=v[I],P=b[I],O=y*w*4*I;for(let k=0;k<R.count;k++){const F=k*M;f===!0&&(n.fromBufferAttribute(R,k),S[O+F+0]=n.x,S[O+F+1]=n.y,S[O+F+2]=n.z,S[O+F+3]=0),p===!0&&(n.fromBufferAttribute(L,k),S[O+F+4]=n.x,S[O+F+5]=n.y,S[O+F+6]=n.z,S[O+F+7]=0),g===!0&&(n.fromBufferAttribute(P,k),S[O+F+8]=n.x,S[O+F+9]=n.y,S[O+F+10]=n.z,S[O+F+11]=P.itemSize===4?n.w:1)}}u={count:d,texture:A,size:new we(y,w)},i.set(a,u),a.addEventListener("dispose",_)}if(r.isInstancedMesh===!0&&r.morphTexture!==null)l.getUniforms().setValue(o,"morphTexture",r.morphTexture,t);else{let f=0;for(let g=0;g<c.length;g++)f+=c[g];const p=a.morphTargetsRelative?1:1-f;l.getUniforms().setValue(o,"morphTargetBaseInfluence",p),l.getUniforms().setValue(o,"morphTargetInfluences",c)}l.getUniforms().setValue(o,"morphTargetsTexture",u.texture,t),l.getUniforms().setValue(o,"morphTargetsTextureSize",u.size)}return{update:s}}function x5(o,e,t,i,n){let s=new WeakMap;function r(c){const h=n.render.frame,d=c.geometry,u=e.get(c,d);if(s.get(u)!==h&&(e.update(u),s.set(u,h)),c.isInstancedMesh&&(c.hasEventListener("dispose",l)===!1&&c.addEventListener("dispose",l),s.get(c)!==h&&(t.update(c.instanceMatrix,o.ARRAY_BUFFER),c.instanceColor!==null&&t.update(c.instanceColor,o.ARRAY_BUFFER),s.set(c,h))),c.isSkinnedMesh){const f=c.skeleton;s.get(f)!==h&&(f.update(),s.set(f,h))}return u}function a(){s=new WeakMap}function l(c){const h=c.target;h.removeEventListener("dispose",l),i.releaseStatesOfObject(h),t.remove(h.instanceMatrix),h.instanceColor!==null&&t.remove(h.instanceColor)}return{update:r,dispose:a}}const S5={[XM]:"LINEAR_TONE_MAPPING",[$M]:"REINHARD_TONE_MAPPING",[YM]:"CINEON_TONE_MAPPING",[qM]:"ACES_FILMIC_TONE_MAPPING",[ZM]:"AGX_TONE_MAPPING",[jM]:"NEUTRAL_TONE_MAPPING",[KM]:"CUSTOM_TONE_MAPPING"};function E5(o,e,t,i,n,s){const r=new Mi(e,t,{type:o,depthBuffer:n,stencilBuffer:s,samples:i?4:0,depthTexture:n?new La(e,t):void 0}),a=new Mi(e,t,{type:ci,depthBuffer:!1,stencilBuffer:!1}),l=new ot;l.setAttribute("position",new yt([-1,3,0,-1,-1,0,3,-1,0],3)),l.setAttribute("uv",new yt([0,2,0,0,2,0],2));const c=new yw({uniforms:{tDiffuse:{value:null}},vertexShader:`
7123
7123
  precision highp float;
7124
7124
 
7125
7125
  uniform mat4 modelViewMatrix;
@@ -7167,7 +7167,7 @@ void main() {
7167
7167
  #endif
7168
7168
  }`,depthTest:!1,depthWrite:!1}),h=new Se(l,c),d=new $s(-1,1,1,-1,0,1);let u=null,f=null,p=!1,g,m=null,v=[],b=!1;this.setSize=function(x,y){r.setSize(x,y),a.setSize(x,y);for(let w=0;w<v.length;w++){const S=v[w];S.setSize&&S.setSize(x,y)}},this.setEffects=function(x){v=x,b=v.length>0&&v[0].isRenderPass===!0;const y=r.width,w=r.height;for(let S=0;S<v.length;S++){const A=v[S];A.setSize&&A.setSize(y,w)}},this.begin=function(x,y){if(p||x.toneMapping===Mr&&v.length===0)return!1;if(m=y,y!==null){const w=y.width,S=y.height;(r.width!==w||r.height!==S)&&this.setSize(w,S)}return b===!1&&x.setRenderTarget(r),g=x.toneMapping,x.toneMapping=Mr,!0},this.hasRenderPass=function(){return b},this.end=function(x,y){x.toneMapping=g,p=!0;let w=r,S=a;for(let A=0;A<v.length;A++){const M=v[A];if(M.enabled!==!1&&(M.render(x,S,w,y),M.needsSwap!==!1)){const _=w;w=S,S=_}}if(u!==x.outputColorSpace||f!==x.toneMapping){u=x.outputColorSpace,f=x.toneMapping,c.defines={},Tt.getTransfer(u)===Yt&&(c.defines.SRGB_TRANSFER="");const A=S5[f];A&&(c.defines[A]=""),c.needsUpdate=!0}c.uniforms.tDiffuse.value=w.texture,x.setRenderTarget(m),x.render(h,d),m=null,p=!1},this.isCompositing=function(){return p},this.dispose=function(){r.depthTexture&&r.depthTexture.dispose(),r.dispose(),a.dispose(),l.dispose(),c.dispose()}}const Tw=new ln,gm=new La(1,1),Iw=new ow,Dw=new lw,Rw=new mw,iy=[],ny=[],sy=new Float32Array(16),ry=new Float32Array(9),ay=new Float32Array(4);function mc(o,e,t){const i=o[0];if(i<=0||i>0)return o;const n=e*t;let s=iy[n];if(s===void 0&&(s=new Float32Array(n),iy[n]=s),e!==0){i.toArray(s,0);for(let r=1,a=0;r!==e;++r)a+=t,o[r].toArray(s,a)}return s}function Ji(o,e){if(o.length!==e.length)return!1;for(let t=0,i=o.length;t<i;t++)if(o[t]!==e[t])return!1;return!0}function Qi(o,e){for(let t=0,i=e.length;t<i;t++)o[t]=e[t]}function Tf(o,e){let t=ny[e];t===void 0&&(t=new Int32Array(e),ny[e]=t);for(let i=0;i!==e;++i)t[i]=o.allocateTextureUnit();return t}function A5(o,e){const t=this.cache;t[0]!==e&&(o.uniform1f(this.addr,e),t[0]=e)}function _5(o,e){const t=this.cache;if(e.x!==void 0)(t[0]!==e.x||t[1]!==e.y)&&(o.uniform2f(this.addr,e.x,e.y),t[0]=e.x,t[1]=e.y);else{if(Ji(t,e))return;o.uniform2fv(this.addr,e),Qi(t,e)}}function T5(o,e){const t=this.cache;if(e.x!==void 0)(t[0]!==e.x||t[1]!==e.y||t[2]!==e.z)&&(o.uniform3f(this.addr,e.x,e.y,e.z),t[0]=e.x,t[1]=e.y,t[2]=e.z);else if(e.r!==void 0)(t[0]!==e.r||t[1]!==e.g||t[2]!==e.b)&&(o.uniform3f(this.addr,e.r,e.g,e.b),t[0]=e.r,t[1]=e.g,t[2]=e.b);else{if(Ji(t,e))return;o.uniform3fv(this.addr,e),Qi(t,e)}}function I5(o,e){const t=this.cache;if(e.x!==void 0)(t[0]!==e.x||t[1]!==e.y||t[2]!==e.z||t[3]!==e.w)&&(o.uniform4f(this.addr,e.x,e.y,e.z,e.w),t[0]=e.x,t[1]=e.y,t[2]=e.z,t[3]=e.w);else{if(Ji(t,e))return;o.uniform4fv(this.addr,e),Qi(t,e)}}function D5(o,e){const t=this.cache,i=e.elements;if(i===void 0){if(Ji(t,e))return;o.uniformMatrix2fv(this.addr,!1,e),Qi(t,e)}else{if(Ji(t,i))return;ay.set(i),o.uniformMatrix2fv(this.addr,!1,ay),Qi(t,i)}}function R5(o,e){const t=this.cache,i=e.elements;if(i===void 0){if(Ji(t,e))return;o.uniformMatrix3fv(this.addr,!1,e),Qi(t,e)}else{if(Ji(t,i))return;ry.set(i),o.uniformMatrix3fv(this.addr,!1,ry),Qi(t,i)}}function C5(o,e){const t=this.cache,i=e.elements;if(i===void 0){if(Ji(t,e))return;o.uniformMatrix4fv(this.addr,!1,e),Qi(t,e)}else{if(Ji(t,i))return;sy.set(i),o.uniformMatrix4fv(this.addr,!1,sy),Qi(t,i)}}function k5(o,e){const t=this.cache;t[0]!==e&&(o.uniform1i(this.addr,e),t[0]=e)}function P5(o,e){const t=this.cache;if(e.x!==void 0)(t[0]!==e.x||t[1]!==e.y)&&(o.uniform2i(this.addr,e.x,e.y),t[0]=e.x,t[1]=e.y);else{if(Ji(t,e))return;o.uniform2iv(this.addr,e),Qi(t,e)}}function L5(o,e){const t=this.cache;if(e.x!==void 0)(t[0]!==e.x||t[1]!==e.y||t[2]!==e.z)&&(o.uniform3i(this.addr,e.x,e.y,e.z),t[0]=e.x,t[1]=e.y,t[2]=e.z);else{if(Ji(t,e))return;o.uniform3iv(this.addr,e),Qi(t,e)}}function O5(o,e){const t=this.cache;if(e.x!==void 0)(t[0]!==e.x||t[1]!==e.y||t[2]!==e.z||t[3]!==e.w)&&(o.uniform4i(this.addr,e.x,e.y,e.z,e.w),t[0]=e.x,t[1]=e.y,t[2]=e.z,t[3]=e.w);else{if(Ji(t,e))return;o.uniform4iv(this.addr,e),Qi(t,e)}}function N5(o,e){const t=this.cache;t[0]!==e&&(o.uniform1ui(this.addr,e),t[0]=e)}function F5(o,e){const t=this.cache;if(e.x!==void 0)(t[0]!==e.x||t[1]!==e.y)&&(o.uniform2ui(this.addr,e.x,e.y),t[0]=e.x,t[1]=e.y);else{if(Ji(t,e))return;o.uniform2uiv(this.addr,e),Qi(t,e)}}function U5(o,e){const t=this.cache;if(e.x!==void 0)(t[0]!==e.x||t[1]!==e.y||t[2]!==e.z)&&(o.uniform3ui(this.addr,e.x,e.y,e.z),t[0]=e.x,t[1]=e.y,t[2]=e.z);else{if(Ji(t,e))return;o.uniform3uiv(this.addr,e),Qi(t,e)}}function B5(o,e){const t=this.cache;if(e.x!==void 0)(t[0]!==e.x||t[1]!==e.y||t[2]!==e.z||t[3]!==e.w)&&(o.uniform4ui(this.addr,e.x,e.y,e.z,e.w),t[0]=e.x,t[1]=e.y,t[2]=e.z,t[3]=e.w);else{if(Ji(t,e))return;o.uniform4uiv(this.addr,e),Qi(t,e)}}function z5(o,e,t){const i=this.cache,n=t.allocateTextureUnit();i[0]!==n&&(o.uniform1i(this.addr,n),i[0]=n);let s;this.type===o.SAMPLER_2D_SHADOW?(gm.compareFunction=t.isReversedDepthBuffer()?gg:mg,s=gm):s=Tw,t.setTexture2D(e||s,n)}function H5(o,e,t){const i=this.cache,n=t.allocateTextureUnit();i[0]!==n&&(o.uniform1i(this.addr,n),i[0]=n),t.setTexture3D(e||Dw,n)}function G5(o,e,t){const i=this.cache,n=t.allocateTextureUnit();i[0]!==n&&(o.uniform1i(this.addr,n),i[0]=n),t.setTextureCube(e||Rw,n)}function V5(o,e,t){const i=this.cache,n=t.allocateTextureUnit();i[0]!==n&&(o.uniform1i(this.addr,n),i[0]=n),t.setTexture2DArray(e||Iw,n)}function W5(o){switch(o){case 5126:return A5;case 35664:return _5;case 35665:return T5;case 35666:return I5;case 35674:return D5;case 35675:return R5;case 35676:return C5;case 5124:case 35670:return k5;case 35667:case 35671:return P5;case 35668:case 35672:return L5;case 35669:case 35673:return O5;case 5125:return N5;case 36294:return F5;case 36295:return U5;case 36296:return B5;case 35678:case 36198:case 36298:case 36306:case 35682:return z5;case 35679:case 36299:case 36307:return H5;case 35680:case 36300:case 36308:case 36293:return G5;case 36289:case 36303:case 36311:case 36292:return V5}}function X5(o,e){o.uniform1fv(this.addr,e)}function $5(o,e){const t=mc(e,this.size,2);o.uniform2fv(this.addr,t)}function Y5(o,e){const t=mc(e,this.size,3);o.uniform3fv(this.addr,t)}function q5(o,e){const t=mc(e,this.size,4);o.uniform4fv(this.addr,t)}function K5(o,e){const t=mc(e,this.size,4);o.uniformMatrix2fv(this.addr,!1,t)}function Z5(o,e){const t=mc(e,this.size,9);o.uniformMatrix3fv(this.addr,!1,t)}function j5(o,e){const t=mc(e,this.size,16);o.uniformMatrix4fv(this.addr,!1,t)}function J5(o,e){o.uniform1iv(this.addr,e)}function Q5(o,e){o.uniform2iv(this.addr,e)}function eI(o,e){o.uniform3iv(this.addr,e)}function tI(o,e){o.uniform4iv(this.addr,e)}function iI(o,e){o.uniform1uiv(this.addr,e)}function nI(o,e){o.uniform2uiv(this.addr,e)}function sI(o,e){o.uniform3uiv(this.addr,e)}function rI(o,e){o.uniform4uiv(this.addr,e)}function aI(o,e,t){const i=this.cache,n=e.length,s=Tf(t,n);Ji(i,s)||(o.uniform1iv(this.addr,s),Qi(i,s));let r;this.type===o.SAMPLER_2D_SHADOW?r=gm:r=Tw;for(let a=0;a!==n;++a)t.setTexture2D(e[a]||r,s[a])}function oI(o,e,t){const i=this.cache,n=e.length,s=Tf(t,n);Ji(i,s)||(o.uniform1iv(this.addr,s),Qi(i,s));for(let r=0;r!==n;++r)t.setTexture3D(e[r]||Dw,s[r])}function lI(o,e,t){const i=this.cache,n=e.length,s=Tf(t,n);Ji(i,s)||(o.uniform1iv(this.addr,s),Qi(i,s));for(let r=0;r!==n;++r)t.setTextureCube(e[r]||Rw,s[r])}function cI(o,e,t){const i=this.cache,n=e.length,s=Tf(t,n);Ji(i,s)||(o.uniform1iv(this.addr,s),Qi(i,s));for(let r=0;r!==n;++r)t.setTexture2DArray(e[r]||Iw,s[r])}function hI(o){switch(o){case 5126:return X5;case 35664:return $5;case 35665:return Y5;case 35666:return q5;case 35674:return K5;case 35675:return Z5;case 35676:return j5;case 5124:case 35670:return J5;case 35667:case 35671:return Q5;case 35668:case 35672:return eI;case 35669:case 35673:return tI;case 5125:return iI;case 36294:return nI;case 36295:return sI;case 36296:return rI;case 35678:case 36198:case 36298:case 36306:case 35682:return aI;case 35679:case 36299:case 36307:return oI;case 35680:case 36300:case 36308:case 36293:return lI;case 36289:case 36303:case 36311:case 36292:return cI}}class dI{constructor(e,t,i){this.id=e,this.addr=i,this.cache=[],this.type=t.type,this.setValue=W5(t.type)}}class uI{constructor(e,t,i){this.id=e,this.addr=i,this.cache=[],this.type=t.type,this.size=t.size,this.setValue=hI(t.type)}}class fI{constructor(e){this.id=e,this.seq=[],this.map={}}setValue(e,t,i){const n=this.seq;for(let s=0,r=n.length;s!==r;++s){const a=n[s];a.setValue(e,t[a.id],i)}}}const _p=/(\w+)(\])?(\[|\.)?/g;function oy(o,e){o.seq.push(e),o.map[e.id]=e}function pI(o,e,t){const i=o.name,n=i.length;for(_p.lastIndex=0;;){const s=_p.exec(i),r=_p.lastIndex;let a=s[1];const l=s[2]==="]",c=s[3];if(l&&(a=a|0),c===void 0||c==="["&&r+2===n){oy(t,c===void 0?new dI(a,o,e):new uI(a,o,e));break}else{let d=t.map[a];d===void 0&&(d=new fI(a),oy(t,d)),t=d}}}class iu{constructor(e,t){this.seq=[],this.map={};const i=e.getProgramParameter(t,e.ACTIVE_UNIFORMS);for(let r=0;r<i;++r){const a=e.getActiveUniform(t,r),l=e.getUniformLocation(t,a.name);pI(a,l,this)}const n=[],s=[];for(const r of this.seq)r.type===e.SAMPLER_2D_SHADOW||r.type===e.SAMPLER_CUBE_SHADOW||r.type===e.SAMPLER_2D_ARRAY_SHADOW?n.push(r):s.push(r);n.length>0&&(this.seq=n.concat(s))}setValue(e,t,i,n){const s=this.map[t];s!==void 0&&s.setValue(e,i,n)}setOptional(e,t,i){const n=t[i];n!==void 0&&this.setValue(e,i,n)}static upload(e,t,i,n){for(let s=0,r=t.length;s!==r;++s){const a=t[s],l=i[a.id];l.needsUpdate!==!1&&a.setValue(e,l.value,n)}}static seqWithValue(e,t){const i=[];for(let n=0,s=e.length;n!==s;++n){const r=e[n];r.id in t&&i.push(r)}return i}}function ly(o,e,t){const i=o.createShader(e);return o.shaderSource(i,t),o.compileShader(i),i}const mI=37297;let gI=0;function vI(o,e){const t=o.split(`
7169
7169
  `),i=[],n=Math.max(e-6,0),s=Math.min(e+6,t.length);for(let r=n;r<s;r++){const a=r+1;i.push(`${a===e?">":" "} ${a}: ${t[r]}`)}return i.join(`
7170
- `)}const cy=new je;function yI(o){Tt._getMatrix(cy,Tt.workingColorSpace,o);const e=`mat3( ${cy.elements.map(t=>t.toFixed(4))} )`;switch(Tt.getTransfer(o)){case Vu:return[e,"LinearTransferOETF"];case Yt:return[e,"sRGBTransferOETF"];default:return ke("WebGLProgram: Unsupported color space: ",o),[e,"LinearTransferOETF"]}}function hy(o,e,t){const i=o.getShaderParameter(e,o.COMPILE_STATUS),s=(o.getShaderInfoLog(e)||"").trim();if(i&&s==="")return"";const r=/ERROR: 0:(\d+)/.exec(s);if(r){const a=parseInt(r[1]);return t.toUpperCase()+`
7170
+ `)}const cy=new Je;function yI(o){Tt._getMatrix(cy,Tt.workingColorSpace,o);const e=`mat3( ${cy.elements.map(t=>t.toFixed(4))} )`;switch(Tt.getTransfer(o)){case Vu:return[e,"LinearTransferOETF"];case Yt:return[e,"sRGBTransferOETF"];default:return ke("WebGLProgram: Unsupported color space: ",o),[e,"LinearTransferOETF"]}}function hy(o,e,t){const i=o.getShaderParameter(e,o.COMPILE_STATUS),s=(o.getShaderInfoLog(e)||"").trim();if(i&&s==="")return"";const r=/ERROR: 0:(\d+)/.exec(s);if(r){const a=parseInt(r[1]);return t.toUpperCase()+`
7171
7171
 
7172
7172
  `+s+`
7173
7173
 
@@ -7209,7 +7209,7 @@ void main() {
7209
7209
  `)+`
7210
7210
  `+m,v=["#define varying in",t.glslVersion===Wu?"":"layout(location = 0) out highp vec4 pc_fragColor;",t.glslVersion===Wu?"":"#define gl_FragColor pc_fragColor","#define gl_FragDepthEXT gl_FragDepth","#define texture2D texture","#define textureCube texture","#define texture2DProj textureProj","#define texture2DLodEXT textureLod","#define texture2DProjLodEXT textureProjLod","#define textureCubeLodEXT textureLod","#define texture2DGradEXT textureGrad","#define texture2DProjGradEXT textureProjGrad","#define textureCubeGradEXT textureGrad"].join(`
7211
7211
  `)+`
7212
- `+v);const x=b+m+r,y=b+v+a,w=ly(n,n.VERTEX_SHADER,x),S=ly(n,n.FRAGMENT_SHADER,y);n.attachShader(g,w),n.attachShader(g,S),t.index0AttributeName!==void 0?n.bindAttribLocation(g,0,t.index0AttributeName):t.hasPositionAttribute===!0&&n.bindAttribLocation(g,0,"position"),n.linkProgram(g);function A(R){if(o.debug.checkShaderErrors){const L=n.getProgramInfoLog(g)||"",P=n.getShaderInfoLog(w)||"",O=n.getShaderInfoLog(S)||"",k=L.trim(),F=P.trim(),z=O.trim();let V=!0,K=!0;if(n.getProgramParameter(g,n.LINK_STATUS)===!1)if(V=!1,typeof o.debug.onShaderError=="function")o.debug.onShaderError(n,g,w,S);else{const q=hy(n,w,"vertex"),te=hy(n,S,"fragment");Ze("WebGLProgram: Shader Error "+n.getError()+" - VALIDATE_STATUS "+n.getProgramParameter(g,n.VALIDATE_STATUS)+`
7212
+ `+v);const x=b+m+r,y=b+v+a,w=ly(n,n.VERTEX_SHADER,x),S=ly(n,n.FRAGMENT_SHADER,y);n.attachShader(g,w),n.attachShader(g,S),t.index0AttributeName!==void 0?n.bindAttribLocation(g,0,t.index0AttributeName):t.hasPositionAttribute===!0&&n.bindAttribLocation(g,0,"position"),n.linkProgram(g);function A(R){if(o.debug.checkShaderErrors){const L=n.getProgramInfoLog(g)||"",P=n.getShaderInfoLog(w)||"",O=n.getShaderInfoLog(S)||"",k=L.trim(),F=P.trim(),z=O.trim();let V=!0,K=!0;if(n.getProgramParameter(g,n.LINK_STATUS)===!1)if(V=!1,typeof o.debug.onShaderError=="function")o.debug.onShaderError(n,g,w,S);else{const q=hy(n,w,"vertex"),te=hy(n,S,"fragment");je("WebGLProgram: Shader Error "+n.getError()+" - VALIDATE_STATUS "+n.getProgramParameter(g,n.VALIDATE_STATUS)+`
7213
7213
 
7214
7214
  Material Name: `+R.name+`
7215
7215
  Material Type: `+R.type+`
@@ -7243,7 +7243,7 @@ void main() {
7243
7243
  squared_mean = squared_mean / samples;
7244
7244
  float std_dev = sqrt( max( 0.0, squared_mean - mean * mean ) );
7245
7245
  gl_FragColor = vec4( mean, std_dev, 0.0, 1.0 );
7246
- }`,nD=[new D(1,0,0),new D(-1,0,0),new D(0,1,0),new D(0,-1,0),new D(0,0,1),new D(0,0,-1)],sD=[new D(0,-1,0),new D(0,-1,0),new D(0,0,1),new D(0,0,-1),new D(0,-1,0),new D(0,-1,0)],yy=new lt,Rc=new D,Tp=new D;function rD(o,e,t){let i=new xg;const n=new we,s=new we,r=new wt,a=new V3,l=new W3,c={},h=t.maxTextureSize,d={[Pa]:fi,[fi]:Pa,[Bn]:Bn},u=new Dt({defines:{VSM_SAMPLES:8},uniforms:{shadow_pass:{value:null},resolution:{value:new we},radius:{value:4}},vertexShader:tD,fragmentShader:iD}),f=u.clone();f.defines.HORIZONTAL_PASS=1;const p=new ot;p.setAttribute("position",new st(new Float32Array([-1,-1,.5,3,-1,.5,-1,3,.5]),3));const g=new Se(p,u),m=this;this.enabled=!1,this.autoUpdate=!0,this.needsUpdate=!1,this.type=Zc;let v=this.type;this.render=function(S,A,M){if(m.enabled===!1||m.autoUpdate===!1&&m.needsUpdate===!1||S.length===0)return;this.type===dE&&(ke("WebGLShadowMap: PCFSoftShadowMap has been deprecated. Using PCFShadowMap instead."),this.type=Zc);const _=o.getRenderTarget(),I=o.getActiveCubeFace(),R=o.getActiveMipmapLevel(),L=o.state;L.setBlending(br),L.buffers.depth.getReversed()===!0?L.buffers.color.setClear(0,0,0,0):L.buffers.color.setClear(1,1,1,1),L.buffers.depth.setTest(!0),L.setScissorTest(!1);const P=v!==this.type;P&&A.traverse(function(O){O.material&&(Array.isArray(O.material)?O.material.forEach(k=>k.needsUpdate=!0):O.material.needsUpdate=!0)});for(let O=0,k=S.length;O<k;O++){const F=S[O],z=F.shadow;if(z===void 0){ke("WebGLShadowMap:",F,"has no shadow.");continue}if(z.autoUpdate===!1&&z.needsUpdate===!1)continue;n.copy(z.mapSize);const V=z.getFrameExtents();n.multiply(V),s.copy(z.mapSize),(n.x>h||n.y>h)&&(n.x>h&&(s.x=Math.floor(h/V.x),n.x=s.x*V.x,z.mapSize.x=s.x),n.y>h&&(s.y=Math.floor(h/V.y),n.y=s.y*V.y,z.mapSize.y=s.y));const K=o.state.buffers.depth.getReversed();if(z.camera._reversedDepth=K,z.map===null||P===!0){if(z.map!==null&&(z.map.depthTexture!==null&&(z.map.depthTexture.dispose(),z.map.depthTexture=null),z.map.dispose()),this.type===Wc){if(F.isPointLight){ke("WebGLShadowMap: VSM shadow maps are not supported for PointLights. Use PCF or BasicShadowMap instead.");continue}z.map=new Mi(n.x,n.y,{format:Fo,type:ci,minFilter:mt,magFilter:mt,generateMipmaps:!1}),z.map.texture.name=F.name+".shadowMap",z.map.depthTexture=new La(n.x,n.y,En),z.map.depthTexture.name=F.name+".shadowMapDepth",z.map.depthTexture.format=Wr,z.map.depthTexture.compareFunction=null,z.map.depthTexture.minFilter=Qt,z.map.depthTexture.magFilter=Qt}else F.isPointLight?(z.map=new Eh(n.x),z.map.depthTexture=new F3(n.x,Ts)):(z.map=new Mi(n.x,n.y),z.map.depthTexture=new La(n.x,n.y,Ts)),z.map.depthTexture.name=F.name+".shadowMap",z.map.depthTexture.format=Wr,this.type===Zc?(z.map.depthTexture.compareFunction=K?gg:mg,z.map.depthTexture.minFilter=mt,z.map.depthTexture.magFilter=mt):(z.map.depthTexture.compareFunction=null,z.map.depthTexture.minFilter=Qt,z.map.depthTexture.magFilter=Qt);z.camera.updateProjectionMatrix()}const q=z.map.isWebGLCubeRenderTarget?6:1;for(let te=0;te<q;te++){if(z.map.isWebGLCubeRenderTarget)o.setRenderTarget(z.map,te),o.clear();else{te===0&&(o.setRenderTarget(z.map),o.clear());const re=z.getViewport(te);r.set(s.x*re.x,s.y*re.y,s.x*re.z,s.y*re.w),L.viewport(r)}if(F.isPointLight){const re=z.camera,Ge=z.matrix,ft=F.distance||re.far;ft!==re.far&&(re.far=ft,re.updateProjectionMatrix()),Rc.setFromMatrixPosition(F.matrixWorld),re.position.copy(Rc),Tp.copy(re.position),Tp.add(nD[te]),re.up.copy(sD[te]),re.lookAt(Tp),re.updateMatrixWorld(),Ge.makeTranslation(-Rc.x,-Rc.y,-Rc.z),yy.multiplyMatrices(re.projectionMatrix,re.matrixWorldInverse),z._frustum.setFromProjectionMatrix(yy,re.coordinateSystem,re.reversedDepth)}else z.updateMatrices(F);i=z.getFrustum(),y(A,M,z.camera,F,this.type)}z.isPointLightShadow!==!0&&this.type===Wc&&b(z,M),z.needsUpdate=!1}v=this.type,m.needsUpdate=!1,o.setRenderTarget(_,I,R)};function b(S,A){const M=e.update(g);u.defines.VSM_SAMPLES!==S.blurSamples&&(u.defines.VSM_SAMPLES=S.blurSamples,f.defines.VSM_SAMPLES=S.blurSamples,u.needsUpdate=!0,f.needsUpdate=!0),S.mapPass===null&&(S.mapPass=new Mi(n.x,n.y,{format:Fo,type:ci})),u.uniforms.shadow_pass.value=S.map.depthTexture,u.uniforms.resolution.value=S.mapSize,u.uniforms.radius.value=S.radius,o.setRenderTarget(S.mapPass),o.clear(),o.renderBufferDirect(A,null,M,u,g,null),f.uniforms.shadow_pass.value=S.mapPass.texture,f.uniforms.resolution.value=S.mapSize,f.uniforms.radius.value=S.radius,o.setRenderTarget(S.map),o.clear(),o.renderBufferDirect(A,null,M,f,g,null)}function x(S,A,M,_){let I=null;const R=M.isPointLight===!0?S.customDistanceMaterial:S.customDepthMaterial;if(R!==void 0)I=R;else if(I=M.isPointLight===!0?l:a,o.localClippingEnabled&&A.clipShadows===!0&&Array.isArray(A.clippingPlanes)&&A.clippingPlanes.length!==0||A.displacementMap&&A.displacementScale!==0||A.alphaMap&&A.alphaTest>0||A.map&&A.alphaTest>0||A.alphaToCoverage===!0){const L=I.uuid,P=A.uuid;let O=c[L];O===void 0&&(O={},c[L]=O);let k=O[P];k===void 0&&(k=I.clone(),O[P]=k,A.addEventListener("dispose",w)),I=k}if(I.visible=A.visible,I.wireframe=A.wireframe,_===Wc?I.side=A.shadowSide!==null?A.shadowSide:A.side:I.side=A.shadowSide!==null?A.shadowSide:d[A.side],I.alphaMap=A.alphaMap,I.alphaTest=A.alphaToCoverage===!0?.5:A.alphaTest,I.map=A.map,I.clipShadows=A.clipShadows,I.clippingPlanes=A.clippingPlanes,I.clipIntersection=A.clipIntersection,I.displacementMap=A.displacementMap,I.displacementScale=A.displacementScale,I.displacementBias=A.displacementBias,I.wireframeLinewidth=A.wireframeLinewidth,I.linewidth=A.linewidth,M.isPointLight===!0&&I.isMeshDistanceMaterial===!0){const L=o.properties.get(I);L.light=M}return I}function y(S,A,M,_,I){if(S.visible===!1)return;if(S.layers.test(A.layers)&&(S.isMesh||S.isLine||S.isPoints)&&(S.castShadow||S.receiveShadow&&I===Wc)&&(!S.frustumCulled||i.intersectsObject(S))){S.modelViewMatrix.multiplyMatrices(M.matrixWorldInverse,S.matrixWorld);const P=e.update(S),O=S.material;if(Array.isArray(O)){const k=P.groups;for(let F=0,z=k.length;F<z;F++){const V=k[F],K=O[V.materialIndex];if(K&&K.visible){const q=x(S,K,_,I);S.onBeforeShadow(o,S,A,M,P,q,V),o.renderBufferDirect(M,null,P,q,S,V),S.onAfterShadow(o,S,A,M,P,q,V)}}}else if(O.visible){const k=x(S,O,_,I);S.onBeforeShadow(o,S,A,M,P,k,null),o.renderBufferDirect(M,null,P,k,S,null),S.onAfterShadow(o,S,A,M,P,k,null)}}const L=S.children;for(let P=0,O=L.length;P<O;P++)y(L[P],A,M,_,I)}function w(S){S.target.removeEventListener("dispose",w);for(const M in c){const _=c[M],I=S.target.uuid;I in _&&(_[I].dispose(),delete _[I])}}}function aD(o,e){function t(){let N=!1;const he=new wt;let Q=null;const me=new wt(0,0,0,0);return{setMask:function(xe){Q!==xe&&!N&&(o.colorMask(xe,xe,xe,xe),Q=xe)},setLocked:function(xe){N=xe},setClear:function(xe,ie,Pe,Te,Si){Si===!0&&(xe*=Te,ie*=Te,Pe*=Te),he.set(xe,ie,Pe,Te),me.equals(he)===!1&&(o.clearColor(xe,ie,Pe,Te),me.copy(he))},reset:function(){N=!1,Q=null,me.set(-1,0,0,0)}}}function i(){let N=!1,he=!1,Q=null,me=null,xe=null;return{setReversed:function(ie){if(he!==ie){const Pe=e.get("EXT_clip_control");ie?Pe.clipControlEXT(Pe.LOWER_LEFT_EXT,Pe.ZERO_TO_ONE_EXT):Pe.clipControlEXT(Pe.LOWER_LEFT_EXT,Pe.NEGATIVE_ONE_TO_ONE_EXT),he=ie;const Te=xe;xe=null,this.setClear(Te)}},getReversed:function(){return he},setTest:function(ie){ie?se(o.DEPTH_TEST):G(o.DEPTH_TEST)},setMask:function(ie){Q!==ie&&!N&&(o.depthMask(ie),Q=ie)},setFunc:function(ie){if(he&&(ie=$E[ie]),me!==ie){switch(ie){case _0:o.depthFunc(o.NEVER);break;case T0:o.depthFunc(o.ALWAYS);break;case I0:o.depthFunc(o.LESS);break;case sc:o.depthFunc(o.LEQUAL);break;case D0:o.depthFunc(o.EQUAL);break;case R0:o.depthFunc(o.GEQUAL);break;case C0:o.depthFunc(o.GREATER);break;case k0:o.depthFunc(o.NOTEQUAL);break;default:o.depthFunc(o.LEQUAL)}me=ie}},setLocked:function(ie){N=ie},setClear:function(ie){xe!==ie&&(xe=ie,he&&(ie=1-ie),o.clearDepth(ie))},reset:function(){N=!1,Q=null,me=null,xe=null,he=!1}}}function n(){let N=!1,he=null,Q=null,me=null,xe=null,ie=null,Pe=null,Te=null,Si=null;return{setTest:function(ri){N||(ri?se(o.STENCIL_TEST):G(o.STENCIL_TEST))},setMask:function(ri){he!==ri&&!N&&(o.stencilMask(ri),he=ri)},setFunc:function(ri,qs,Ks){(Q!==ri||me!==qs||xe!==Ks)&&(o.stencilFunc(ri,qs,Ks),Q=ri,me=qs,xe=Ks)},setOp:function(ri,qs,Ks){(ie!==ri||Pe!==qs||Te!==Ks)&&(o.stencilOp(ri,qs,Ks),ie=ri,Pe=qs,Te=Ks)},setLocked:function(ri){N=ri},setClear:function(ri){Si!==ri&&(o.clearStencil(ri),Si=ri)},reset:function(){N=!1,he=null,Q=null,me=null,xe=null,ie=null,Pe=null,Te=null,Si=null}}}const s=new t,r=new i,a=new n,l=new WeakMap,c=new WeakMap;let h={},d={},u={},f=new WeakMap,p=[],g=null,m=!1,v=null,b=null,x=null,y=null,w=null,S=null,A=null,M=new ne(0,0,0),_=0,I=!1,R=null,L=null,P=null,O=null,k=null;const F=o.getParameter(o.MAX_COMBINED_TEXTURE_IMAGE_UNITS);let z=!1,V=0;const K=o.getParameter(o.VERSION);K.indexOf("WebGL")!==-1?(V=parseFloat(/^WebGL (\d)/.exec(K)[1]),z=V>=1):K.indexOf("OpenGL ES")!==-1&&(V=parseFloat(/^OpenGL ES (\d)/.exec(K)[1]),z=V>=2);let q=null,te={};const re=o.getParameter(o.SCISSOR_BOX),Ge=o.getParameter(o.VIEWPORT),ft=new wt().fromArray(re),it=new wt().fromArray(Ge);function Z(N,he,Q,me){const xe=new Uint8Array(4),ie=o.createTexture();o.bindTexture(N,ie),o.texParameteri(N,o.TEXTURE_MIN_FILTER,o.NEAREST),o.texParameteri(N,o.TEXTURE_MAG_FILTER,o.NEAREST);for(let Pe=0;Pe<Q;Pe++)N===o.TEXTURE_3D||N===o.TEXTURE_2D_ARRAY?o.texImage3D(he,0,o.RGBA,1,1,me,0,o.RGBA,o.UNSIGNED_BYTE,xe):o.texImage2D(he+Pe,0,o.RGBA,1,1,0,o.RGBA,o.UNSIGNED_BYTE,xe);return ie}const ae={};ae[o.TEXTURE_2D]=Z(o.TEXTURE_2D,o.TEXTURE_2D,1),ae[o.TEXTURE_CUBE_MAP]=Z(o.TEXTURE_CUBE_MAP,o.TEXTURE_CUBE_MAP_POSITIVE_X,6),ae[o.TEXTURE_2D_ARRAY]=Z(o.TEXTURE_2D_ARRAY,o.TEXTURE_2D_ARRAY,1,1),ae[o.TEXTURE_3D]=Z(o.TEXTURE_3D,o.TEXTURE_3D,1,1),s.setClear(0,0,0,1),r.setClear(1),a.setClear(0),se(o.DEPTH_TEST),r.setFunc(sc),zt(!1),Ht(Qv),se(o.CULL_FACE),Xe(br);function se(N){h[N]!==!0&&(o.enable(N),h[N]=!0)}function G(N){h[N]!==!1&&(o.disable(N),h[N]=!1)}function Re(N,he){return u[N]!==he?(o.bindFramebuffer(N,he),u[N]=he,N===o.DRAW_FRAMEBUFFER&&(u[o.FRAMEBUFFER]=he),N===o.FRAMEBUFFER&&(u[o.DRAW_FRAMEBUFFER]=he),!0):!1}function ze(N,he){let Q=p,me=!1;if(N){Q=f.get(he),Q===void 0&&(Q=[],f.set(he,Q));const xe=N.textures;if(Q.length!==xe.length||Q[0]!==o.COLOR_ATTACHMENT0){for(let ie=0,Pe=xe.length;ie<Pe;ie++)Q[ie]=o.COLOR_ATTACHMENT0+ie;Q.length=xe.length,me=!0}}else Q[0]!==o.BACK&&(Q[0]=o.BACK,me=!0);me&&o.drawBuffers(Q)}function Le(N){return g!==N?(o.useProgram(N),g=N,!0):!1}const Ae={[eo]:o.FUNC_ADD,[uE]:o.FUNC_SUBTRACT,[fE]:o.FUNC_REVERSE_SUBTRACT};Ae[pE]=o.MIN,Ae[mE]=o.MAX;const We={[Xc]:o.ZERO,[yh]:o.ONE,[gE]:o.SRC_COLOR,[A0]:o.SRC_ALPHA,[xE]:o.SRC_ALPHA_SATURATE,[ME]:o.DST_COLOR,[yE]:o.DST_ALPHA,[vE]:o.ONE_MINUS_SRC_COLOR,[bh]:o.ONE_MINUS_SRC_ALPHA,[wE]:o.ONE_MINUS_DST_COLOR,[bE]:o.ONE_MINUS_DST_ALPHA,[SE]:o.CONSTANT_COLOR,[EE]:o.ONE_MINUS_CONSTANT_COLOR,[AE]:o.CONSTANT_ALPHA,[_E]:o.ONE_MINUS_CONSTANT_ALPHA};function Xe(N,he,Q,me,xe,ie,Pe,Te,Si,ri){if(N===br){m===!0&&(G(o.BLEND),m=!1);return}if(m===!1&&(se(o.BLEND),m=!0),N!==Rh){if(N!==v||ri!==I){if((b!==eo||w!==eo)&&(o.blendEquation(o.FUNC_ADD),b=eo,w=eo),ri)switch(N){case Ia:o.blendFuncSeparate(o.ONE,o.ONE_MINUS_SRC_ALPHA,o.ONE,o.ONE_MINUS_SRC_ALPHA);break;case Wi:o.blendFunc(o.ONE,o.ONE);break;case e1:o.blendFuncSeparate(o.ZERO,o.ONE_MINUS_SRC_COLOR,o.ZERO,o.ONE);break;case t1:o.blendFuncSeparate(o.DST_COLOR,o.ONE_MINUS_SRC_ALPHA,o.ZERO,o.ONE);break;default:Ze("WebGLState: Invalid blending: ",N);break}else switch(N){case Ia:o.blendFuncSeparate(o.SRC_ALPHA,o.ONE_MINUS_SRC_ALPHA,o.ONE,o.ONE_MINUS_SRC_ALPHA);break;case Wi:o.blendFuncSeparate(o.SRC_ALPHA,o.ONE,o.ONE,o.ONE);break;case e1:Ze("WebGLState: SubtractiveBlending requires material.premultipliedAlpha = true");break;case t1:Ze("WebGLState: MultiplyBlending requires material.premultipliedAlpha = true");break;default:Ze("WebGLState: Invalid blending: ",N);break}x=null,y=null,S=null,A=null,M.set(0,0,0),_=0,v=N,I=ri}return}xe=xe||he,ie=ie||Q,Pe=Pe||me,(he!==b||xe!==w)&&(o.blendEquationSeparate(Ae[he],Ae[xe]),b=he,w=xe),(Q!==x||me!==y||ie!==S||Pe!==A)&&(o.blendFuncSeparate(We[Q],We[me],We[ie],We[Pe]),x=Q,y=me,S=ie,A=Pe),(Te.equals(M)===!1||Si!==_)&&(o.blendColor(Te.r,Te.g,Te.b,Si),M.copy(Te),_=Si),v=N,I=!1}function $e(N,he){N.side===Bn?G(o.CULL_FACE):se(o.CULL_FACE);let Q=N.side===fi;he&&(Q=!Q),zt(Q),N.blending===Ia&&N.transparent===!1?Xe(br):Xe(N.blending,N.blendEquation,N.blendSrc,N.blendDst,N.blendEquationAlpha,N.blendSrcAlpha,N.blendDstAlpha,N.blendColor,N.blendAlpha,N.premultipliedAlpha),r.setFunc(N.depthFunc),r.setTest(N.depthTest),r.setMask(N.depthWrite),s.setMask(N.colorWrite);const me=N.stencilWrite;a.setTest(me),me&&(a.setMask(N.stencilWriteMask),a.setFunc(N.stencilFunc,N.stencilRef,N.stencilFuncMask),a.setOp(N.stencilFail,N.stencilZFail,N.stencilZPass)),pi(N.polygonOffset,N.polygonOffsetFactor,N.polygonOffsetUnits),N.alphaToCoverage===!0?se(o.SAMPLE_ALPHA_TO_COVERAGE):G(o.SAMPLE_ALPHA_TO_COVERAGE)}function zt(N){R!==N&&(N?o.frontFace(o.CW):o.frontFace(o.CCW),R=N)}function Ht(N){N!==cE?(se(o.CULL_FACE),N!==L&&(N===Qv?o.cullFace(o.BACK):N===hE?o.cullFace(o.FRONT):o.cullFace(o.FRONT_AND_BACK))):G(o.CULL_FACE),L=N}function wi(N){N!==P&&(z&&o.lineWidth(N),P=N)}function pi(N,he,Q){N?(se(o.POLYGON_OFFSET_FILL),(O!==he||k!==Q)&&(O=he,k=Q,r.getReversed()&&(he=-he),o.polygonOffset(he,Q))):G(o.POLYGON_OFFSET_FILL)}function xi(N){N?se(o.SCISSOR_TEST):G(o.SCISSOR_TEST)}function Ui(N){N===void 0&&(N=o.TEXTURE0+F-1),q!==N&&(o.activeTexture(N),q=N)}function U(N,he,Q){Q===void 0&&(q===null?Q=o.TEXTURE0+F-1:Q=q);let me=te[Q];me===void 0&&(me={type:void 0,texture:void 0},te[Q]=me),(me.type!==N||me.texture!==he)&&(q!==Q&&(o.activeTexture(Q),q=Q),o.bindTexture(N,he||ae[N]),me.type=N,me.texture=he)}function Vn(){const N=te[q];N!==void 0&&N.type!==void 0&&(o.bindTexture(N.type,null),N.type=void 0,N.texture=void 0)}function Gt(){try{o.compressedTexImage2D(...arguments)}catch(N){Ze("WebGLState:",N)}}function C(){try{o.compressedTexImage3D(...arguments)}catch(N){Ze("WebGLState:",N)}}function E(){try{o.texSubImage2D(...arguments)}catch(N){Ze("WebGLState:",N)}}function H(){try{o.texSubImage3D(...arguments)}catch(N){Ze("WebGLState:",N)}}function $(){try{o.compressedTexSubImage2D(...arguments)}catch(N){Ze("WebGLState:",N)}}function j(){try{o.compressedTexSubImage3D(...arguments)}catch(N){Ze("WebGLState:",N)}}function le(){try{o.texStorage2D(...arguments)}catch(N){Ze("WebGLState:",N)}}function ue(){try{o.texStorage3D(...arguments)}catch(N){Ze("WebGLState:",N)}}function J(){try{o.texImage2D(...arguments)}catch(N){Ze("WebGLState:",N)}}function ee(){try{o.texImage3D(...arguments)}catch(N){Ze("WebGLState:",N)}}function fe(N){return d[N]!==void 0?d[N]:o.getParameter(N)}function Oe(N,he){d[N]!==he&&(o.pixelStorei(N,he),d[N]=he)}function ve(N){ft.equals(N)===!1&&(o.scissor(N.x,N.y,N.z,N.w),ft.copy(N))}function pe(N){it.equals(N)===!1&&(o.viewport(N.x,N.y,N.z,N.w),it.copy(N))}function Ve(N,he){let Q=c.get(he);Q===void 0&&(Q=new WeakMap,c.set(he,Q));let me=Q.get(N);me===void 0&&(me=o.getUniformBlockIndex(he,N.name),Q.set(N,me))}function Ke(N,he){const me=c.get(he).get(N);l.get(he)!==me&&(o.uniformBlockBinding(he,me,N.__bindingPointIndex),l.set(he,me))}function ct(){o.disable(o.BLEND),o.disable(o.CULL_FACE),o.disable(o.DEPTH_TEST),o.disable(o.POLYGON_OFFSET_FILL),o.disable(o.SCISSOR_TEST),o.disable(o.STENCIL_TEST),o.disable(o.SAMPLE_ALPHA_TO_COVERAGE),o.blendEquation(o.FUNC_ADD),o.blendFunc(o.ONE,o.ZERO),o.blendFuncSeparate(o.ONE,o.ZERO,o.ONE,o.ZERO),o.blendColor(0,0,0,0),o.colorMask(!0,!0,!0,!0),o.clearColor(0,0,0,0),o.depthMask(!0),o.depthFunc(o.LESS),r.setReversed(!1),o.clearDepth(1),o.stencilMask(4294967295),o.stencilFunc(o.ALWAYS,0,4294967295),o.stencilOp(o.KEEP,o.KEEP,o.KEEP),o.clearStencil(0),o.cullFace(o.BACK),o.frontFace(o.CCW),o.polygonOffset(0,0),o.activeTexture(o.TEXTURE0),o.bindFramebuffer(o.FRAMEBUFFER,null),o.bindFramebuffer(o.DRAW_FRAMEBUFFER,null),o.bindFramebuffer(o.READ_FRAMEBUFFER,null),o.useProgram(null),o.lineWidth(1),o.scissor(0,0,o.canvas.width,o.canvas.height),o.viewport(0,0,o.canvas.width,o.canvas.height),o.pixelStorei(o.PACK_ALIGNMENT,4),o.pixelStorei(o.UNPACK_ALIGNMENT,4),o.pixelStorei(o.UNPACK_FLIP_Y_WEBGL,!1),o.pixelStorei(o.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),o.pixelStorei(o.UNPACK_COLORSPACE_CONVERSION_WEBGL,o.BROWSER_DEFAULT_WEBGL),o.pixelStorei(o.PACK_ROW_LENGTH,0),o.pixelStorei(o.PACK_SKIP_PIXELS,0),o.pixelStorei(o.PACK_SKIP_ROWS,0),o.pixelStorei(o.UNPACK_ROW_LENGTH,0),o.pixelStorei(o.UNPACK_IMAGE_HEIGHT,0),o.pixelStorei(o.UNPACK_SKIP_PIXELS,0),o.pixelStorei(o.UNPACK_SKIP_ROWS,0),o.pixelStorei(o.UNPACK_SKIP_IMAGES,0),h={},d={},q=null,te={},u={},f=new WeakMap,p=[],g=null,m=!1,v=null,b=null,x=null,y=null,w=null,S=null,A=null,M=new ne(0,0,0),_=0,I=!1,R=null,L=null,P=null,O=null,k=null,ft.set(0,0,o.canvas.width,o.canvas.height),it.set(0,0,o.canvas.width,o.canvas.height),s.reset(),r.reset(),a.reset()}return{buffers:{color:s,depth:r,stencil:a},enable:se,disable:G,bindFramebuffer:Re,drawBuffers:ze,useProgram:Le,setBlending:Xe,setMaterial:$e,setFlipSided:zt,setCullFace:Ht,setLineWidth:wi,setPolygonOffset:pi,setScissorTest:xi,activeTexture:Ui,bindTexture:U,unbindTexture:Vn,compressedTexImage2D:Gt,compressedTexImage3D:C,texImage2D:J,texImage3D:ee,pixelStorei:Oe,getParameter:fe,updateUBOMapping:Ve,uniformBlockBinding:Ke,texStorage2D:le,texStorage3D:ue,texSubImage2D:E,texSubImage3D:H,compressedTexSubImage2D:$,compressedTexSubImage3D:j,scissor:ve,viewport:pe,reset:ct}}function oD(o,e,t,i,n,s,r){const a=e.has("WEBGL_multisampled_render_to_texture")?e.get("WEBGL_multisampled_render_to_texture"):null,l=typeof navigator>"u"?!1:/OculusBrowser/g.test(navigator.userAgent),c=new we,h=new WeakMap,d=new Set;let u;const f=new WeakMap;let p=!1;try{p=typeof OffscreenCanvas<"u"&&new OffscreenCanvas(1,1).getContext("2d")!==null}catch{}function g(C,E){return p?new OffscreenCanvas(C,E):Sh("canvas")}function m(C,E,H){let $=1;const j=Gt(C);if((j.width>H||j.height>H)&&($=H/Math.max(j.width,j.height)),$<1)if(typeof HTMLImageElement<"u"&&C instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&C instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&C instanceof ImageBitmap||typeof VideoFrame<"u"&&C instanceof VideoFrame){const le=Math.floor($*j.width),ue=Math.floor($*j.height);u===void 0&&(u=g(le,ue));const J=E?g(le,ue):u;return J.width=le,J.height=ue,J.getContext("2d").drawImage(C,0,0,le,ue),ke("WebGLRenderer: Texture has been resized from ("+j.width+"x"+j.height+") to ("+le+"x"+ue+")."),J}else return"data"in C&&ke("WebGLRenderer: Image in DataTexture is too big ("+j.width+"x"+j.height+")."),C;return C}function v(C){return C.generateMipmaps}function b(C){o.generateMipmap(C)}function x(C){return C.isWebGLCubeRenderTarget?o.TEXTURE_CUBE_MAP:C.isWebGL3DRenderTarget?o.TEXTURE_3D:C.isWebGLArrayRenderTarget||C.isCompressedArrayTexture?o.TEXTURE_2D_ARRAY:o.TEXTURE_2D}function y(C,E,H,$,j,le=!1){if(C!==null){if(o[C]!==void 0)return o[C];ke("WebGLRenderer: Attempt to use non-existing WebGL internal format '"+C+"'")}let ue;$&&(ue=e.get("EXT_texture_norm16"),ue||ke("WebGLRenderer: Unable to use normalized textures without EXT_texture_norm16 extension"));let J=E;if(E===o.RED&&(H===o.FLOAT&&(J=o.R32F),H===o.HALF_FLOAT&&(J=o.R16F),H===o.UNSIGNED_BYTE&&(J=o.R8),H===o.UNSIGNED_SHORT&&ue&&(J=ue.R16_EXT),H===o.SHORT&&ue&&(J=ue.R16_SNORM_EXT)),E===o.RED_INTEGER&&(H===o.UNSIGNED_BYTE&&(J=o.R8UI),H===o.UNSIGNED_SHORT&&(J=o.R16UI),H===o.UNSIGNED_INT&&(J=o.R32UI),H===o.BYTE&&(J=o.R8I),H===o.SHORT&&(J=o.R16I),H===o.INT&&(J=o.R32I)),E===o.RG&&(H===o.FLOAT&&(J=o.RG32F),H===o.HALF_FLOAT&&(J=o.RG16F),H===o.UNSIGNED_BYTE&&(J=o.RG8),H===o.UNSIGNED_SHORT&&ue&&(J=ue.RG16_EXT),H===o.SHORT&&ue&&(J=ue.RG16_SNORM_EXT)),E===o.RG_INTEGER&&(H===o.UNSIGNED_BYTE&&(J=o.RG8UI),H===o.UNSIGNED_SHORT&&(J=o.RG16UI),H===o.UNSIGNED_INT&&(J=o.RG32UI),H===o.BYTE&&(J=o.RG8I),H===o.SHORT&&(J=o.RG16I),H===o.INT&&(J=o.RG32I)),E===o.RGB_INTEGER&&(H===o.UNSIGNED_BYTE&&(J=o.RGB8UI),H===o.UNSIGNED_SHORT&&(J=o.RGB16UI),H===o.UNSIGNED_INT&&(J=o.RGB32UI),H===o.BYTE&&(J=o.RGB8I),H===o.SHORT&&(J=o.RGB16I),H===o.INT&&(J=o.RGB32I)),E===o.RGBA_INTEGER&&(H===o.UNSIGNED_BYTE&&(J=o.RGBA8UI),H===o.UNSIGNED_SHORT&&(J=o.RGBA16UI),H===o.UNSIGNED_INT&&(J=o.RGBA32UI),H===o.BYTE&&(J=o.RGBA8I),H===o.SHORT&&(J=o.RGBA16I),H===o.INT&&(J=o.RGBA32I)),E===o.RGB&&(H===o.UNSIGNED_SHORT&&ue&&(J=ue.RGB16_EXT),H===o.SHORT&&ue&&(J=ue.RGB16_SNORM_EXT),H===o.UNSIGNED_INT_5_9_9_9_REV&&(J=o.RGB9_E5),H===o.UNSIGNED_INT_10F_11F_11F_REV&&(J=o.R11F_G11F_B10F)),E===o.RGBA){const ee=le?Vu:Tt.getTransfer(j);H===o.FLOAT&&(J=o.RGBA32F),H===o.HALF_FLOAT&&(J=o.RGBA16F),H===o.UNSIGNED_BYTE&&(J=ee===Yt?o.SRGB8_ALPHA8:o.RGBA8),H===o.UNSIGNED_SHORT&&ue&&(J=ue.RGBA16_EXT),H===o.SHORT&&ue&&(J=ue.RGBA16_SNORM_EXT),H===o.UNSIGNED_SHORT_4_4_4_4&&(J=o.RGBA4),H===o.UNSIGNED_SHORT_5_5_5_1&&(J=o.RGB5_A1)}return(J===o.R16F||J===o.R32F||J===o.RG16F||J===o.RG32F||J===o.RGBA16F||J===o.RGBA32F)&&e.get("EXT_color_buffer_float"),J}function w(C,E){let H;return C?E===null||E===Ts||E===wh?H=o.DEPTH24_STENCIL8:E===En?H=o.DEPTH32F_STENCIL8:E===Mh&&(H=o.DEPTH24_STENCIL8,ke("DepthTexture: 16 bit depth attachment is not supported with stencil. Using 24-bit attachment.")):E===null||E===Ts||E===wh?H=o.DEPTH_COMPONENT24:E===En?H=o.DEPTH_COMPONENT32F:E===Mh&&(H=o.DEPTH_COMPONENT16),H}function S(C,E){return v(C)===!0||C.isFramebufferTexture&&C.minFilter!==Qt&&C.minFilter!==mt?Math.log2(Math.max(E.width,E.height))+1:C.mipmaps!==void 0&&C.mipmaps.length>0?C.mipmaps.length:C.isCompressedTexture&&Array.isArray(C.image)?E.mipmaps.length:1}function A(C){const E=C.target;E.removeEventListener("dispose",A),_(E),E.isVideoTexture&&h.delete(E),E.isHTMLTexture&&d.delete(E)}function M(C){const E=C.target;E.removeEventListener("dispose",M),R(E)}function _(C){const E=i.get(C);if(E.__webglInit===void 0)return;const H=C.source,$=f.get(H);if($){const j=$[E.__cacheKey];j.usedTimes--,j.usedTimes===0&&I(C),Object.keys($).length===0&&f.delete(H)}i.remove(C)}function I(C){const E=i.get(C);o.deleteTexture(E.__webglTexture);const H=C.source,$=f.get(H);delete $[E.__cacheKey],r.memory.textures--}function R(C){const E=i.get(C);if(C.depthTexture&&(C.depthTexture.dispose(),i.remove(C.depthTexture)),C.isWebGLCubeRenderTarget)for(let $=0;$<6;$++){if(Array.isArray(E.__webglFramebuffer[$]))for(let j=0;j<E.__webglFramebuffer[$].length;j++)o.deleteFramebuffer(E.__webglFramebuffer[$][j]);else o.deleteFramebuffer(E.__webglFramebuffer[$]);E.__webglDepthbuffer&&o.deleteRenderbuffer(E.__webglDepthbuffer[$])}else{if(Array.isArray(E.__webglFramebuffer))for(let $=0;$<E.__webglFramebuffer.length;$++)o.deleteFramebuffer(E.__webglFramebuffer[$]);else o.deleteFramebuffer(E.__webglFramebuffer);if(E.__webglDepthbuffer&&o.deleteRenderbuffer(E.__webglDepthbuffer),E.__webglMultisampledFramebuffer&&o.deleteFramebuffer(E.__webglMultisampledFramebuffer),E.__webglColorRenderbuffer)for(let $=0;$<E.__webglColorRenderbuffer.length;$++)E.__webglColorRenderbuffer[$]&&o.deleteRenderbuffer(E.__webglColorRenderbuffer[$]);E.__webglDepthRenderbuffer&&o.deleteRenderbuffer(E.__webglDepthRenderbuffer)}const H=C.textures;for(let $=0,j=H.length;$<j;$++){const le=i.get(H[$]);le.__webglTexture&&(o.deleteTexture(le.__webglTexture),r.memory.textures--),i.remove(H[$])}i.remove(C)}let L=0;function P(){L=0}function O(){return L}function k(C){L=C}function F(){const C=L;return C>=n.maxTextures&&ke("WebGLTextures: Trying to use "+C+" texture units while this GPU supports only "+n.maxTextures),L+=1,C}function z(C){const E=[];return E.push(C.wrapS),E.push(C.wrapT),E.push(C.wrapR||0),E.push(C.magFilter),E.push(C.minFilter),E.push(C.anisotropy),E.push(C.internalFormat),E.push(C.format),E.push(C.type),E.push(C.generateMipmaps),E.push(C.premultiplyAlpha),E.push(C.flipY),E.push(C.unpackAlignment),E.push(C.colorSpace),E.join()}function V(C,E){const H=i.get(C);if(C.isVideoTexture&&U(C),C.isRenderTargetTexture===!1&&C.isExternalTexture!==!0&&C.version>0&&H.__version!==C.version){const $=C.image;if($===null)ke("WebGLRenderer: Texture marked for update but no image data found.");else if($.complete===!1)ke("WebGLRenderer: Texture marked for update but image is incomplete");else{G(H,C,E);return}}else C.isExternalTexture&&(H.__webglTexture=C.sourceTexture?C.sourceTexture:null);t.bindTexture(o.TEXTURE_2D,H.__webglTexture,o.TEXTURE0+E)}function K(C,E){const H=i.get(C);if(C.isRenderTargetTexture===!1&&C.version>0&&H.__version!==C.version){G(H,C,E);return}else C.isExternalTexture&&(H.__webglTexture=C.sourceTexture?C.sourceTexture:null);t.bindTexture(o.TEXTURE_2D_ARRAY,H.__webglTexture,o.TEXTURE0+E)}function q(C,E){const H=i.get(C);if(C.isRenderTargetTexture===!1&&C.version>0&&H.__version!==C.version){G(H,C,E);return}t.bindTexture(o.TEXTURE_3D,H.__webglTexture,o.TEXTURE0+E)}function te(C,E){const H=i.get(C);if(C.isCubeDepthTexture!==!0&&C.version>0&&H.__version!==C.version){Re(H,C,E);return}t.bindTexture(o.TEXTURE_CUBE_MAP,H.__webglTexture,o.TEXTURE0+E)}const re={[No]:o.REPEAT,[Ti]:o.CLAMP_TO_EDGE,[P0]:o.MIRRORED_REPEAT},Ge={[Qt]:o.NEAREST,[RE]:o.NEAREST_MIPMAP_NEAREST,[Xh]:o.NEAREST_MIPMAP_LINEAR,[mt]:o.LINEAR,[Xf]:o.LINEAR_MIPMAP_NEAREST,[gr]:o.LINEAR_MIPMAP_LINEAR},ft={[NE]:o.NEVER,[HE]:o.ALWAYS,[FE]:o.LESS,[mg]:o.LEQUAL,[UE]:o.EQUAL,[gg]:o.GEQUAL,[BE]:o.GREATER,[zE]:o.NOTEQUAL};function it(C,E){if(E.type===En&&e.has("OES_texture_float_linear")===!1&&(E.magFilter===mt||E.magFilter===Xf||E.magFilter===Xh||E.magFilter===gr||E.minFilter===mt||E.minFilter===Xf||E.minFilter===Xh||E.minFilter===gr)&&ke("WebGLRenderer: Unable to use linear filtering with floating point textures. OES_texture_float_linear not supported on this device."),o.texParameteri(C,o.TEXTURE_WRAP_S,re[E.wrapS]),o.texParameteri(C,o.TEXTURE_WRAP_T,re[E.wrapT]),(C===o.TEXTURE_3D||C===o.TEXTURE_2D_ARRAY)&&o.texParameteri(C,o.TEXTURE_WRAP_R,re[E.wrapR]),o.texParameteri(C,o.TEXTURE_MAG_FILTER,Ge[E.magFilter]),o.texParameteri(C,o.TEXTURE_MIN_FILTER,Ge[E.minFilter]),E.compareFunction&&(o.texParameteri(C,o.TEXTURE_COMPARE_MODE,o.COMPARE_REF_TO_TEXTURE),o.texParameteri(C,o.TEXTURE_COMPARE_FUNC,ft[E.compareFunction])),e.has("EXT_texture_filter_anisotropic")===!0){if(E.magFilter===Qt||E.minFilter!==Xh&&E.minFilter!==gr||E.type===En&&e.has("OES_texture_float_linear")===!1)return;if(E.anisotropy>1||i.get(E).__currentAnisotropy){const H=e.get("EXT_texture_filter_anisotropic");o.texParameterf(C,H.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(E.anisotropy,n.getMaxAnisotropy())),i.get(E).__currentAnisotropy=E.anisotropy}}}function Z(C,E){let H=!1;C.__webglInit===void 0&&(C.__webglInit=!0,E.addEventListener("dispose",A));const $=E.source;let j=f.get($);j===void 0&&(j={},f.set($,j));const le=z(E);if(le!==C.__cacheKey){j[le]===void 0&&(j[le]={texture:o.createTexture(),usedTimes:0},r.memory.textures++,H=!0),j[le].usedTimes++;const ue=j[C.__cacheKey];ue!==void 0&&(j[C.__cacheKey].usedTimes--,ue.usedTimes===0&&I(E)),C.__cacheKey=le,C.__webglTexture=j[le].texture}return H}function ae(C,E,H){return Math.floor(Math.floor(C/H)/E)}function se(C,E,H,$){const le=C.updateRanges;if(le.length===0)t.texSubImage2D(o.TEXTURE_2D,0,0,0,E.width,E.height,H,$,E.data);else{le.sort((Oe,ve)=>Oe.start-ve.start);let ue=0;for(let Oe=1;Oe<le.length;Oe++){const ve=le[ue],pe=le[Oe],Ve=ve.start+ve.count,Ke=ae(pe.start,E.width,4),ct=ae(ve.start,E.width,4);pe.start<=Ve+1&&Ke===ct&&ae(pe.start+pe.count-1,E.width,4)===Ke?ve.count=Math.max(ve.count,pe.start+pe.count-ve.start):(++ue,le[ue]=pe)}le.length=ue+1;const J=t.getParameter(o.UNPACK_ROW_LENGTH),ee=t.getParameter(o.UNPACK_SKIP_PIXELS),fe=t.getParameter(o.UNPACK_SKIP_ROWS);t.pixelStorei(o.UNPACK_ROW_LENGTH,E.width);for(let Oe=0,ve=le.length;Oe<ve;Oe++){const pe=le[Oe],Ve=Math.floor(pe.start/4),Ke=Math.ceil(pe.count/4),ct=Ve%E.width,N=Math.floor(Ve/E.width),he=Ke,Q=1;t.pixelStorei(o.UNPACK_SKIP_PIXELS,ct),t.pixelStorei(o.UNPACK_SKIP_ROWS,N),t.texSubImage2D(o.TEXTURE_2D,0,ct,N,he,Q,H,$,E.data)}C.clearUpdateRanges(),t.pixelStorei(o.UNPACK_ROW_LENGTH,J),t.pixelStorei(o.UNPACK_SKIP_PIXELS,ee),t.pixelStorei(o.UNPACK_SKIP_ROWS,fe)}}function G(C,E,H){let $=o.TEXTURE_2D;(E.isDataArrayTexture||E.isCompressedArrayTexture)&&($=o.TEXTURE_2D_ARRAY),E.isData3DTexture&&($=o.TEXTURE_3D);const j=Z(C,E),le=E.source;t.bindTexture($,C.__webglTexture,o.TEXTURE0+H);const ue=i.get(le);if(le.version!==ue.__version||j===!0){if(t.activeTexture(o.TEXTURE0+H),(typeof ImageBitmap<"u"&&E.image instanceof ImageBitmap)===!1){const Q=Tt.getPrimaries(Tt.workingColorSpace),me=E.colorSpace===ba?null:Tt.getPrimaries(E.colorSpace),xe=E.colorSpace===ba||Q===me?o.NONE:o.BROWSER_DEFAULT_WEBGL;t.pixelStorei(o.UNPACK_FLIP_Y_WEBGL,E.flipY),t.pixelStorei(o.UNPACK_PREMULTIPLY_ALPHA_WEBGL,E.premultiplyAlpha),t.pixelStorei(o.UNPACK_COLORSPACE_CONVERSION_WEBGL,xe)}t.pixelStorei(o.UNPACK_ALIGNMENT,E.unpackAlignment);let ee=m(E.image,!1,n.maxTextureSize);ee=Vn(E,ee);const fe=s.convert(E.format,E.colorSpace),Oe=s.convert(E.type);let ve=y(E.internalFormat,fe,Oe,E.normalized,E.colorSpace,E.isVideoTexture);it($,E);let pe;const Ve=E.mipmaps,Ke=E.isVideoTexture!==!0,ct=ue.__version===void 0||j===!0,N=le.dataReady,he=S(E,ee);if(E.isDepthTexture)ve=w(E.format===bo,E.type),ct&&(Ke?t.texStorage2D(o.TEXTURE_2D,1,ve,ee.width,ee.height):t.texImage2D(o.TEXTURE_2D,0,ve,ee.width,ee.height,0,fe,Oe,null));else if(E.isDataTexture)if(Ve.length>0){Ke&&ct&&t.texStorage2D(o.TEXTURE_2D,he,ve,Ve[0].width,Ve[0].height);for(let Q=0,me=Ve.length;Q<me;Q++)pe=Ve[Q],Ke?N&&t.texSubImage2D(o.TEXTURE_2D,Q,0,0,pe.width,pe.height,fe,Oe,pe.data):t.texImage2D(o.TEXTURE_2D,Q,ve,pe.width,pe.height,0,fe,Oe,pe.data);E.generateMipmaps=!1}else Ke?(ct&&t.texStorage2D(o.TEXTURE_2D,he,ve,ee.width,ee.height),N&&se(E,ee,fe,Oe)):t.texImage2D(o.TEXTURE_2D,0,ve,ee.width,ee.height,0,fe,Oe,ee.data);else if(E.isCompressedTexture)if(E.isCompressedArrayTexture){Ke&&ct&&t.texStorage3D(o.TEXTURE_2D_ARRAY,he,ve,Ve[0].width,Ve[0].height,ee.depth);for(let Q=0,me=Ve.length;Q<me;Q++)if(pe=Ve[Q],E.format!==Vi)if(fe!==null)if(Ke){if(N)if(E.layerUpdates.size>0){const xe=Z1(pe.width,pe.height,E.format,E.type);for(const ie of E.layerUpdates){const Pe=pe.data.subarray(ie*xe/pe.data.BYTES_PER_ELEMENT,(ie+1)*xe/pe.data.BYTES_PER_ELEMENT);t.compressedTexSubImage3D(o.TEXTURE_2D_ARRAY,Q,0,0,ie,pe.width,pe.height,1,fe,Pe)}E.clearLayerUpdates()}else t.compressedTexSubImage3D(o.TEXTURE_2D_ARRAY,Q,0,0,0,pe.width,pe.height,ee.depth,fe,pe.data)}else t.compressedTexImage3D(o.TEXTURE_2D_ARRAY,Q,ve,pe.width,pe.height,ee.depth,0,pe.data,0,0);else ke("WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()");else Ke?N&&t.texSubImage3D(o.TEXTURE_2D_ARRAY,Q,0,0,0,pe.width,pe.height,ee.depth,fe,Oe,pe.data):t.texImage3D(o.TEXTURE_2D_ARRAY,Q,ve,pe.width,pe.height,ee.depth,0,fe,Oe,pe.data)}else{Ke&&ct&&t.texStorage2D(o.TEXTURE_2D,he,ve,Ve[0].width,Ve[0].height);for(let Q=0,me=Ve.length;Q<me;Q++)pe=Ve[Q],E.format!==Vi?fe!==null?Ke?N&&t.compressedTexSubImage2D(o.TEXTURE_2D,Q,0,0,pe.width,pe.height,fe,pe.data):t.compressedTexImage2D(o.TEXTURE_2D,Q,ve,pe.width,pe.height,0,pe.data):ke("WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()"):Ke?N&&t.texSubImage2D(o.TEXTURE_2D,Q,0,0,pe.width,pe.height,fe,Oe,pe.data):t.texImage2D(o.TEXTURE_2D,Q,ve,pe.width,pe.height,0,fe,Oe,pe.data)}else if(E.isDataArrayTexture)if(Ke){if(ct&&t.texStorage3D(o.TEXTURE_2D_ARRAY,he,ve,ee.width,ee.height,ee.depth),N)if(E.layerUpdates.size>0){const Q=Z1(ee.width,ee.height,E.format,E.type);for(const me of E.layerUpdates){const xe=ee.data.subarray(me*Q/ee.data.BYTES_PER_ELEMENT,(me+1)*Q/ee.data.BYTES_PER_ELEMENT);t.texSubImage3D(o.TEXTURE_2D_ARRAY,0,0,0,me,ee.width,ee.height,1,fe,Oe,xe)}E.clearLayerUpdates()}else t.texSubImage3D(o.TEXTURE_2D_ARRAY,0,0,0,0,ee.width,ee.height,ee.depth,fe,Oe,ee.data)}else t.texImage3D(o.TEXTURE_2D_ARRAY,0,ve,ee.width,ee.height,ee.depth,0,fe,Oe,ee.data);else if(E.isData3DTexture)Ke?(ct&&t.texStorage3D(o.TEXTURE_3D,he,ve,ee.width,ee.height,ee.depth),N&&t.texSubImage3D(o.TEXTURE_3D,0,0,0,0,ee.width,ee.height,ee.depth,fe,Oe,ee.data)):t.texImage3D(o.TEXTURE_3D,0,ve,ee.width,ee.height,ee.depth,0,fe,Oe,ee.data);else if(E.isFramebufferTexture){if(ct)if(Ke)t.texStorage2D(o.TEXTURE_2D,he,ve,ee.width,ee.height);else{let Q=ee.width,me=ee.height;for(let xe=0;xe<he;xe++)t.texImage2D(o.TEXTURE_2D,xe,ve,Q,me,0,fe,Oe,null),Q>>=1,me>>=1}}else if(E.isHTMLTexture){if("texElementImage2D"in o){const Q=o.canvas;if(Q.hasAttribute("layoutsubtree")||Q.setAttribute("layoutsubtree","true"),ee.parentNode!==Q){Q.appendChild(ee),d.add(E),Q.onpaint=me=>{const xe=me.changedElements;for(const ie of d)xe.includes(ie.image)&&(ie.needsUpdate=!0)},Q.requestPaint();return}if(o.texElementImage2D.length===3)o.texElementImage2D(o.TEXTURE_2D,o.RGBA8,ee);else{const xe=o.RGBA,ie=o.RGBA,Pe=o.UNSIGNED_BYTE;o.texElementImage2D(o.TEXTURE_2D,0,xe,ie,Pe,ee)}o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MIN_FILTER,o.LINEAR),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_S,o.CLAMP_TO_EDGE),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_T,o.CLAMP_TO_EDGE)}}else if(Ve.length>0){if(Ke&&ct){const Q=Gt(Ve[0]);t.texStorage2D(o.TEXTURE_2D,he,ve,Q.width,Q.height)}for(let Q=0,me=Ve.length;Q<me;Q++)pe=Ve[Q],Ke?N&&t.texSubImage2D(o.TEXTURE_2D,Q,0,0,fe,Oe,pe):t.texImage2D(o.TEXTURE_2D,Q,ve,fe,Oe,pe);E.generateMipmaps=!1}else if(Ke){if(ct){const Q=Gt(ee);t.texStorage2D(o.TEXTURE_2D,he,ve,Q.width,Q.height)}N&&t.texSubImage2D(o.TEXTURE_2D,0,0,0,fe,Oe,ee)}else t.texImage2D(o.TEXTURE_2D,0,ve,fe,Oe,ee);v(E)&&b($),ue.__version=le.version,E.onUpdate&&E.onUpdate(E)}C.__version=E.version}function Re(C,E,H){if(E.image.length!==6)return;const $=Z(C,E),j=E.source;t.bindTexture(o.TEXTURE_CUBE_MAP,C.__webglTexture,o.TEXTURE0+H);const le=i.get(j);if(j.version!==le.__version||$===!0){t.activeTexture(o.TEXTURE0+H);const ue=Tt.getPrimaries(Tt.workingColorSpace),J=E.colorSpace===ba?null:Tt.getPrimaries(E.colorSpace),ee=E.colorSpace===ba||ue===J?o.NONE:o.BROWSER_DEFAULT_WEBGL;t.pixelStorei(o.UNPACK_FLIP_Y_WEBGL,E.flipY),t.pixelStorei(o.UNPACK_PREMULTIPLY_ALPHA_WEBGL,E.premultiplyAlpha),t.pixelStorei(o.UNPACK_ALIGNMENT,E.unpackAlignment),t.pixelStorei(o.UNPACK_COLORSPACE_CONVERSION_WEBGL,ee);const fe=E.isCompressedTexture||E.image[0].isCompressedTexture,Oe=E.image[0]&&E.image[0].isDataTexture,ve=[];for(let ie=0;ie<6;ie++)!fe&&!Oe?ve[ie]=m(E.image[ie],!0,n.maxCubemapSize):ve[ie]=Oe?E.image[ie].image:E.image[ie],ve[ie]=Vn(E,ve[ie]);const pe=ve[0],Ve=s.convert(E.format,E.colorSpace),Ke=s.convert(E.type),ct=y(E.internalFormat,Ve,Ke,E.normalized,E.colorSpace),N=E.isVideoTexture!==!0,he=le.__version===void 0||$===!0,Q=j.dataReady;let me=S(E,pe);it(o.TEXTURE_CUBE_MAP,E);let xe;if(fe){N&&he&&t.texStorage2D(o.TEXTURE_CUBE_MAP,me,ct,pe.width,pe.height);for(let ie=0;ie<6;ie++){xe=ve[ie].mipmaps;for(let Pe=0;Pe<xe.length;Pe++){const Te=xe[Pe];E.format!==Vi?Ve!==null?N?Q&&t.compressedTexSubImage2D(o.TEXTURE_CUBE_MAP_POSITIVE_X+ie,Pe,0,0,Te.width,Te.height,Ve,Te.data):t.compressedTexImage2D(o.TEXTURE_CUBE_MAP_POSITIVE_X+ie,Pe,ct,Te.width,Te.height,0,Te.data):ke("WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()"):N?Q&&t.texSubImage2D(o.TEXTURE_CUBE_MAP_POSITIVE_X+ie,Pe,0,0,Te.width,Te.height,Ve,Ke,Te.data):t.texImage2D(o.TEXTURE_CUBE_MAP_POSITIVE_X+ie,Pe,ct,Te.width,Te.height,0,Ve,Ke,Te.data)}}}else{if(xe=E.mipmaps,N&&he){xe.length>0&&me++;const ie=Gt(ve[0]);t.texStorage2D(o.TEXTURE_CUBE_MAP,me,ct,ie.width,ie.height)}for(let ie=0;ie<6;ie++)if(Oe){N?Q&&t.texSubImage2D(o.TEXTURE_CUBE_MAP_POSITIVE_X+ie,0,0,0,ve[ie].width,ve[ie].height,Ve,Ke,ve[ie].data):t.texImage2D(o.TEXTURE_CUBE_MAP_POSITIVE_X+ie,0,ct,ve[ie].width,ve[ie].height,0,Ve,Ke,ve[ie].data);for(let Pe=0;Pe<xe.length;Pe++){const Si=xe[Pe].image[ie].image;N?Q&&t.texSubImage2D(o.TEXTURE_CUBE_MAP_POSITIVE_X+ie,Pe+1,0,0,Si.width,Si.height,Ve,Ke,Si.data):t.texImage2D(o.TEXTURE_CUBE_MAP_POSITIVE_X+ie,Pe+1,ct,Si.width,Si.height,0,Ve,Ke,Si.data)}}else{N?Q&&t.texSubImage2D(o.TEXTURE_CUBE_MAP_POSITIVE_X+ie,0,0,0,Ve,Ke,ve[ie]):t.texImage2D(o.TEXTURE_CUBE_MAP_POSITIVE_X+ie,0,ct,Ve,Ke,ve[ie]);for(let Pe=0;Pe<xe.length;Pe++){const Te=xe[Pe];N?Q&&t.texSubImage2D(o.TEXTURE_CUBE_MAP_POSITIVE_X+ie,Pe+1,0,0,Ve,Ke,Te.image[ie]):t.texImage2D(o.TEXTURE_CUBE_MAP_POSITIVE_X+ie,Pe+1,ct,Ve,Ke,Te.image[ie])}}}v(E)&&b(o.TEXTURE_CUBE_MAP),le.__version=j.version,E.onUpdate&&E.onUpdate(E)}C.__version=E.version}function ze(C,E,H,$,j,le){const ue=s.convert(H.format,H.colorSpace),J=s.convert(H.type),ee=y(H.internalFormat,ue,J,H.normalized,H.colorSpace),fe=i.get(E),Oe=i.get(H);if(Oe.__renderTarget=E,!fe.__hasExternalTextures){const ve=Math.max(1,E.width>>le),pe=Math.max(1,E.height>>le);j===o.TEXTURE_3D||j===o.TEXTURE_2D_ARRAY?t.texImage3D(j,le,ee,ve,pe,E.depth,0,ue,J,null):t.texImage2D(j,le,ee,ve,pe,0,ue,J,null)}t.bindFramebuffer(o.FRAMEBUFFER,C),Ui(E)?a.framebufferTexture2DMultisampleEXT(o.FRAMEBUFFER,$,j,Oe.__webglTexture,0,xi(E)):(j===o.TEXTURE_2D||j>=o.TEXTURE_CUBE_MAP_POSITIVE_X&&j<=o.TEXTURE_CUBE_MAP_NEGATIVE_Z)&&o.framebufferTexture2D(o.FRAMEBUFFER,$,j,Oe.__webglTexture,le),t.bindFramebuffer(o.FRAMEBUFFER,null)}function Le(C,E,H){if(o.bindRenderbuffer(o.RENDERBUFFER,C),E.depthBuffer){const $=E.depthTexture,j=$&&$.isDepthTexture?$.type:null,le=w(E.stencilBuffer,j),ue=E.stencilBuffer?o.DEPTH_STENCIL_ATTACHMENT:o.DEPTH_ATTACHMENT;Ui(E)?a.renderbufferStorageMultisampleEXT(o.RENDERBUFFER,xi(E),le,E.width,E.height):H?o.renderbufferStorageMultisample(o.RENDERBUFFER,xi(E),le,E.width,E.height):o.renderbufferStorage(o.RENDERBUFFER,le,E.width,E.height),o.framebufferRenderbuffer(o.FRAMEBUFFER,ue,o.RENDERBUFFER,C)}else{const $=E.textures;for(let j=0;j<$.length;j++){const le=$[j],ue=s.convert(le.format,le.colorSpace),J=s.convert(le.type),ee=y(le.internalFormat,ue,J,le.normalized,le.colorSpace);Ui(E)?a.renderbufferStorageMultisampleEXT(o.RENDERBUFFER,xi(E),ee,E.width,E.height):H?o.renderbufferStorageMultisample(o.RENDERBUFFER,xi(E),ee,E.width,E.height):o.renderbufferStorage(o.RENDERBUFFER,ee,E.width,E.height)}}o.bindRenderbuffer(o.RENDERBUFFER,null)}function Ae(C,E,H){const $=E.isWebGLCubeRenderTarget===!0;if(t.bindFramebuffer(o.FRAMEBUFFER,C),!(E.depthTexture&&E.depthTexture.isDepthTexture))throw new Error("THREE.WebGLTextures: renderTarget.depthTexture must be an instance of THREE.DepthTexture.");const j=i.get(E.depthTexture);if(j.__renderTarget=E,(!j.__webglTexture||E.depthTexture.image.width!==E.width||E.depthTexture.image.height!==E.height)&&(E.depthTexture.image.width=E.width,E.depthTexture.image.height=E.height,E.depthTexture.needsUpdate=!0),$){if(j.__webglInit===void 0&&(j.__webglInit=!0,E.depthTexture.addEventListener("dispose",A)),j.__webglTexture===void 0){j.__webglTexture=o.createTexture(),t.bindTexture(o.TEXTURE_CUBE_MAP,j.__webglTexture),it(o.TEXTURE_CUBE_MAP,E.depthTexture);const fe=s.convert(E.depthTexture.format),Oe=s.convert(E.depthTexture.type);let ve;E.depthTexture.format===Wr?ve=o.DEPTH_COMPONENT24:E.depthTexture.format===bo&&(ve=o.DEPTH24_STENCIL8);for(let pe=0;pe<6;pe++)o.texImage2D(o.TEXTURE_CUBE_MAP_POSITIVE_X+pe,0,ve,E.width,E.height,0,fe,Oe,null)}}else V(E.depthTexture,0);const le=j.__webglTexture,ue=xi(E),J=$?o.TEXTURE_CUBE_MAP_POSITIVE_X+H:o.TEXTURE_2D,ee=E.depthTexture.format===bo?o.DEPTH_STENCIL_ATTACHMENT:o.DEPTH_ATTACHMENT;if(E.depthTexture.format===Wr)Ui(E)?a.framebufferTexture2DMultisampleEXT(o.FRAMEBUFFER,ee,J,le,0,ue):o.framebufferTexture2D(o.FRAMEBUFFER,ee,J,le,0);else if(E.depthTexture.format===bo)Ui(E)?a.framebufferTexture2DMultisampleEXT(o.FRAMEBUFFER,ee,J,le,0,ue):o.framebufferTexture2D(o.FRAMEBUFFER,ee,J,le,0);else throw new Error("THREE.WebGLTextures: Unknown depthTexture format.")}function We(C){const E=i.get(C),H=C.isWebGLCubeRenderTarget===!0;if(E.__boundDepthTexture!==C.depthTexture){const $=C.depthTexture;if(E.__depthDisposeCallback&&E.__depthDisposeCallback(),$){const j=()=>{delete E.__boundDepthTexture,delete E.__depthDisposeCallback,$.removeEventListener("dispose",j)};$.addEventListener("dispose",j),E.__depthDisposeCallback=j}E.__boundDepthTexture=$}if(C.depthTexture&&!E.__autoAllocateDepthBuffer)if(H)for(let $=0;$<6;$++)Ae(E.__webglFramebuffer[$],C,$);else{const $=C.texture.mipmaps;$&&$.length>0?Ae(E.__webglFramebuffer[0],C,0):Ae(E.__webglFramebuffer,C,0)}else if(H){E.__webglDepthbuffer=[];for(let $=0;$<6;$++)if(t.bindFramebuffer(o.FRAMEBUFFER,E.__webglFramebuffer[$]),E.__webglDepthbuffer[$]===void 0)E.__webglDepthbuffer[$]=o.createRenderbuffer(),Le(E.__webglDepthbuffer[$],C,!1);else{const j=C.stencilBuffer?o.DEPTH_STENCIL_ATTACHMENT:o.DEPTH_ATTACHMENT,le=E.__webglDepthbuffer[$];o.bindRenderbuffer(o.RENDERBUFFER,le),o.framebufferRenderbuffer(o.FRAMEBUFFER,j,o.RENDERBUFFER,le)}}else{const $=C.texture.mipmaps;if($&&$.length>0?t.bindFramebuffer(o.FRAMEBUFFER,E.__webglFramebuffer[0]):t.bindFramebuffer(o.FRAMEBUFFER,E.__webglFramebuffer),E.__webglDepthbuffer===void 0)E.__webglDepthbuffer=o.createRenderbuffer(),Le(E.__webglDepthbuffer,C,!1);else{const j=C.stencilBuffer?o.DEPTH_STENCIL_ATTACHMENT:o.DEPTH_ATTACHMENT,le=E.__webglDepthbuffer;o.bindRenderbuffer(o.RENDERBUFFER,le),o.framebufferRenderbuffer(o.FRAMEBUFFER,j,o.RENDERBUFFER,le)}}t.bindFramebuffer(o.FRAMEBUFFER,null)}function Xe(C,E,H){const $=i.get(C);E!==void 0&&ze($.__webglFramebuffer,C,C.texture,o.COLOR_ATTACHMENT0,o.TEXTURE_2D,0),H!==void 0&&We(C)}function $e(C){const E=C.texture,H=i.get(C),$=i.get(E);C.addEventListener("dispose",M);const j=C.textures,le=C.isWebGLCubeRenderTarget===!0,ue=j.length>1;if(ue||($.__webglTexture===void 0&&($.__webglTexture=o.createTexture()),$.__version=E.version,r.memory.textures++),le){H.__webglFramebuffer=[];for(let J=0;J<6;J++)if(E.mipmaps&&E.mipmaps.length>0){H.__webglFramebuffer[J]=[];for(let ee=0;ee<E.mipmaps.length;ee++)H.__webglFramebuffer[J][ee]=o.createFramebuffer()}else H.__webglFramebuffer[J]=o.createFramebuffer()}else{if(E.mipmaps&&E.mipmaps.length>0){H.__webglFramebuffer=[];for(let J=0;J<E.mipmaps.length;J++)H.__webglFramebuffer[J]=o.createFramebuffer()}else H.__webglFramebuffer=o.createFramebuffer();if(ue)for(let J=0,ee=j.length;J<ee;J++){const fe=i.get(j[J]);fe.__webglTexture===void 0&&(fe.__webglTexture=o.createTexture(),r.memory.textures++)}if(C.samples>0&&Ui(C)===!1){H.__webglMultisampledFramebuffer=o.createFramebuffer(),H.__webglColorRenderbuffer=[],t.bindFramebuffer(o.FRAMEBUFFER,H.__webglMultisampledFramebuffer);for(let J=0;J<j.length;J++){const ee=j[J];H.__webglColorRenderbuffer[J]=o.createRenderbuffer(),o.bindRenderbuffer(o.RENDERBUFFER,H.__webglColorRenderbuffer[J]);const fe=s.convert(ee.format,ee.colorSpace),Oe=s.convert(ee.type),ve=y(ee.internalFormat,fe,Oe,ee.normalized,ee.colorSpace,C.isXRRenderTarget===!0),pe=xi(C);o.renderbufferStorageMultisample(o.RENDERBUFFER,pe,ve,C.width,C.height),o.framebufferRenderbuffer(o.FRAMEBUFFER,o.COLOR_ATTACHMENT0+J,o.RENDERBUFFER,H.__webglColorRenderbuffer[J])}o.bindRenderbuffer(o.RENDERBUFFER,null),C.depthBuffer&&(H.__webglDepthRenderbuffer=o.createRenderbuffer(),Le(H.__webglDepthRenderbuffer,C,!0)),t.bindFramebuffer(o.FRAMEBUFFER,null)}}if(le){t.bindTexture(o.TEXTURE_CUBE_MAP,$.__webglTexture),it(o.TEXTURE_CUBE_MAP,E);for(let J=0;J<6;J++)if(E.mipmaps&&E.mipmaps.length>0)for(let ee=0;ee<E.mipmaps.length;ee++)ze(H.__webglFramebuffer[J][ee],C,E,o.COLOR_ATTACHMENT0,o.TEXTURE_CUBE_MAP_POSITIVE_X+J,ee);else ze(H.__webglFramebuffer[J],C,E,o.COLOR_ATTACHMENT0,o.TEXTURE_CUBE_MAP_POSITIVE_X+J,0);v(E)&&b(o.TEXTURE_CUBE_MAP),t.unbindTexture()}else if(ue){for(let J=0,ee=j.length;J<ee;J++){const fe=j[J],Oe=i.get(fe);let ve=o.TEXTURE_2D;(C.isWebGL3DRenderTarget||C.isWebGLArrayRenderTarget)&&(ve=C.isWebGL3DRenderTarget?o.TEXTURE_3D:o.TEXTURE_2D_ARRAY),t.bindTexture(ve,Oe.__webglTexture),it(ve,fe),ze(H.__webglFramebuffer,C,fe,o.COLOR_ATTACHMENT0+J,ve,0),v(fe)&&b(ve)}t.unbindTexture()}else{let J=o.TEXTURE_2D;if((C.isWebGL3DRenderTarget||C.isWebGLArrayRenderTarget)&&(J=C.isWebGL3DRenderTarget?o.TEXTURE_3D:o.TEXTURE_2D_ARRAY),t.bindTexture(J,$.__webglTexture),it(J,E),E.mipmaps&&E.mipmaps.length>0)for(let ee=0;ee<E.mipmaps.length;ee++)ze(H.__webglFramebuffer[ee],C,E,o.COLOR_ATTACHMENT0,J,ee);else ze(H.__webglFramebuffer,C,E,o.COLOR_ATTACHMENT0,J,0);v(E)&&b(J),t.unbindTexture()}C.depthBuffer&&We(C)}function zt(C){const E=C.textures;for(let H=0,$=E.length;H<$;H++){const j=E[H];if(v(j)){const le=x(C),ue=i.get(j).__webglTexture;t.bindTexture(le,ue),b(le),t.unbindTexture()}}}const Ht=[],wi=[];function pi(C){if(C.samples>0){if(Ui(C)===!1){const E=C.textures,H=C.width,$=C.height;let j=o.COLOR_BUFFER_BIT;const le=C.stencilBuffer?o.DEPTH_STENCIL_ATTACHMENT:o.DEPTH_ATTACHMENT,ue=i.get(C),J=E.length>1;if(J)for(let fe=0;fe<E.length;fe++)t.bindFramebuffer(o.FRAMEBUFFER,ue.__webglMultisampledFramebuffer),o.framebufferRenderbuffer(o.FRAMEBUFFER,o.COLOR_ATTACHMENT0+fe,o.RENDERBUFFER,null),t.bindFramebuffer(o.FRAMEBUFFER,ue.__webglFramebuffer),o.framebufferTexture2D(o.DRAW_FRAMEBUFFER,o.COLOR_ATTACHMENT0+fe,o.TEXTURE_2D,null,0);t.bindFramebuffer(o.READ_FRAMEBUFFER,ue.__webglMultisampledFramebuffer);const ee=C.texture.mipmaps;ee&&ee.length>0?t.bindFramebuffer(o.DRAW_FRAMEBUFFER,ue.__webglFramebuffer[0]):t.bindFramebuffer(o.DRAW_FRAMEBUFFER,ue.__webglFramebuffer);for(let fe=0;fe<E.length;fe++){if(C.resolveDepthBuffer&&(C.depthBuffer&&(j|=o.DEPTH_BUFFER_BIT),C.stencilBuffer&&C.resolveStencilBuffer&&(j|=o.STENCIL_BUFFER_BIT)),J){o.framebufferRenderbuffer(o.READ_FRAMEBUFFER,o.COLOR_ATTACHMENT0,o.RENDERBUFFER,ue.__webglColorRenderbuffer[fe]);const Oe=i.get(E[fe]).__webglTexture;o.framebufferTexture2D(o.DRAW_FRAMEBUFFER,o.COLOR_ATTACHMENT0,o.TEXTURE_2D,Oe,0)}o.blitFramebuffer(0,0,H,$,0,0,H,$,j,o.NEAREST),l===!0&&(Ht.length=0,wi.length=0,Ht.push(o.COLOR_ATTACHMENT0+fe),C.depthBuffer&&C.resolveDepthBuffer===!1&&(Ht.push(le),wi.push(le),o.invalidateFramebuffer(o.DRAW_FRAMEBUFFER,wi)),o.invalidateFramebuffer(o.READ_FRAMEBUFFER,Ht))}if(t.bindFramebuffer(o.READ_FRAMEBUFFER,null),t.bindFramebuffer(o.DRAW_FRAMEBUFFER,null),J)for(let fe=0;fe<E.length;fe++){t.bindFramebuffer(o.FRAMEBUFFER,ue.__webglMultisampledFramebuffer),o.framebufferRenderbuffer(o.FRAMEBUFFER,o.COLOR_ATTACHMENT0+fe,o.RENDERBUFFER,ue.__webglColorRenderbuffer[fe]);const Oe=i.get(E[fe]).__webglTexture;t.bindFramebuffer(o.FRAMEBUFFER,ue.__webglFramebuffer),o.framebufferTexture2D(o.DRAW_FRAMEBUFFER,o.COLOR_ATTACHMENT0+fe,o.TEXTURE_2D,Oe,0)}t.bindFramebuffer(o.DRAW_FRAMEBUFFER,ue.__webglMultisampledFramebuffer)}else if(C.depthBuffer&&C.resolveDepthBuffer===!1&&l){const E=C.stencilBuffer?o.DEPTH_STENCIL_ATTACHMENT:o.DEPTH_ATTACHMENT;o.invalidateFramebuffer(o.DRAW_FRAMEBUFFER,[E])}}}function xi(C){return Math.min(n.maxSamples,C.samples)}function Ui(C){const E=i.get(C);return C.samples>0&&e.has("WEBGL_multisampled_render_to_texture")===!0&&E.__useRenderToTexture!==!1}function U(C){const E=r.render.frame;h.get(C)!==E&&(h.set(C,E),C.update())}function Vn(C,E){const H=C.colorSpace,$=C.format,j=C.type;return C.isCompressedTexture===!0||C.isVideoTexture===!0||H!==Gu&&H!==ba&&(Tt.getTransfer(H)===Yt?($!==Vi||j!==zn)&&ke("WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType."):Ze("WebGLTextures: Unsupported texture color space:",H)),E}function Gt(C){return typeof HTMLImageElement<"u"&&C instanceof HTMLImageElement?(c.width=C.naturalWidth||C.width,c.height=C.naturalHeight||C.height):typeof VideoFrame<"u"&&C instanceof VideoFrame?(c.width=C.displayWidth,c.height=C.displayHeight):(c.width=C.width,c.height=C.height),c}this.allocateTextureUnit=F,this.resetTextureUnits=P,this.getTextureUnits=O,this.setTextureUnits=k,this.setTexture2D=V,this.setTexture2DArray=K,this.setTexture3D=q,this.setTextureCube=te,this.rebindTextures=Xe,this.setupRenderTarget=$e,this.updateRenderTargetMipmap=zt,this.updateMultisampleRenderTarget=pi,this.setupDepthRenderbuffer=We,this.setupFrameBufferTexture=ze,this.useMultisampledRTT=Ui,this.isReversedDepthBuffer=function(){return t.buffers.depth.getReversed()}}function lD(o,e){function t(i,n=ba){let s;const r=Tt.getTransfer(n);if(i===zn)return o.UNSIGNED_BYTE;if(i===cg)return o.UNSIGNED_SHORT_4_4_4_4;if(i===hg)return o.UNSIGNED_SHORT_5_5_5_1;if(i===tw)return o.UNSIGNED_INT_5_9_9_9_REV;if(i===iw)return o.UNSIGNED_INT_10F_11F_11F_REV;if(i===QM)return o.BYTE;if(i===ew)return o.SHORT;if(i===Mh)return o.UNSIGNED_SHORT;if(i===lg)return o.INT;if(i===Ts)return o.UNSIGNED_INT;if(i===En)return o.FLOAT;if(i===ci)return o.HALF_FLOAT;if(i===nw)return o.ALPHA;if(i===sw)return o.RGB;if(i===Vi)return o.RGBA;if(i===Wr)return o.DEPTH_COMPONENT;if(i===bo)return o.DEPTH_STENCIL;if(i===ac)return o.RED;if(i===dg)return o.RED_INTEGER;if(i===Fo)return o.RG;if(i===ug)return o.RG_INTEGER;if(i===fg)return o.RGBA_INTEGER;if(i===Zd||i===jd||i===Jd||i===Qd)if(r===Yt)if(s=e.get("WEBGL_compressed_texture_s3tc_srgb"),s!==null){if(i===Zd)return s.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(i===jd)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(i===Jd)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(i===Qd)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else return null;else if(s=e.get("WEBGL_compressed_texture_s3tc"),s!==null){if(i===Zd)return s.COMPRESSED_RGB_S3TC_DXT1_EXT;if(i===jd)return s.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(i===Jd)return s.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(i===Qd)return s.COMPRESSED_RGBA_S3TC_DXT5_EXT}else return null;if(i===L0||i===O0||i===N0||i===F0)if(s=e.get("WEBGL_compressed_texture_pvrtc"),s!==null){if(i===L0)return s.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(i===O0)return s.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(i===N0)return s.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(i===F0)return s.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}else return null;if(i===U0||i===B0||i===z0||i===H0||i===G0||i===Fu||i===V0)if(s=e.get("WEBGL_compressed_texture_etc"),s!==null){if(i===U0||i===B0)return r===Yt?s.COMPRESSED_SRGB8_ETC2:s.COMPRESSED_RGB8_ETC2;if(i===z0)return r===Yt?s.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:s.COMPRESSED_RGBA8_ETC2_EAC;if(i===H0)return s.COMPRESSED_R11_EAC;if(i===G0)return s.COMPRESSED_SIGNED_R11_EAC;if(i===Fu)return s.COMPRESSED_RG11_EAC;if(i===V0)return s.COMPRESSED_SIGNED_RG11_EAC}else return null;if(i===W0||i===X0||i===$0||i===Y0||i===q0||i===K0||i===Z0||i===j0||i===J0||i===Q0||i===em||i===tm||i===im||i===nm)if(s=e.get("WEBGL_compressed_texture_astc"),s!==null){if(i===W0)return r===Yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:s.COMPRESSED_RGBA_ASTC_4x4_KHR;if(i===X0)return r===Yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:s.COMPRESSED_RGBA_ASTC_5x4_KHR;if(i===$0)return r===Yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:s.COMPRESSED_RGBA_ASTC_5x5_KHR;if(i===Y0)return r===Yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:s.COMPRESSED_RGBA_ASTC_6x5_KHR;if(i===q0)return r===Yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:s.COMPRESSED_RGBA_ASTC_6x6_KHR;if(i===K0)return r===Yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:s.COMPRESSED_RGBA_ASTC_8x5_KHR;if(i===Z0)return r===Yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:s.COMPRESSED_RGBA_ASTC_8x6_KHR;if(i===j0)return r===Yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:s.COMPRESSED_RGBA_ASTC_8x8_KHR;if(i===J0)return r===Yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:s.COMPRESSED_RGBA_ASTC_10x5_KHR;if(i===Q0)return r===Yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:s.COMPRESSED_RGBA_ASTC_10x6_KHR;if(i===em)return r===Yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:s.COMPRESSED_RGBA_ASTC_10x8_KHR;if(i===tm)return r===Yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:s.COMPRESSED_RGBA_ASTC_10x10_KHR;if(i===im)return r===Yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:s.COMPRESSED_RGBA_ASTC_12x10_KHR;if(i===nm)return r===Yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:s.COMPRESSED_RGBA_ASTC_12x12_KHR}else return null;if(i===sm||i===rm||i===am)if(s=e.get("EXT_texture_compression_bptc"),s!==null){if(i===sm)return r===Yt?s.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:s.COMPRESSED_RGBA_BPTC_UNORM_EXT;if(i===rm)return s.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT;if(i===am)return s.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT}else return null;if(i===om||i===lm||i===Uu||i===cm)if(s=e.get("EXT_texture_compression_rgtc"),s!==null){if(i===om)return s.COMPRESSED_RED_RGTC1_EXT;if(i===lm)return s.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(i===Uu)return s.COMPRESSED_RED_GREEN_RGTC2_EXT;if(i===cm)return s.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}else return null;return i===wh?o.UNSIGNED_INT_24_8:o[i]!==void 0?o[i]:null}return{convert:t}}const cD=`
7246
+ }`,nD=[new D(1,0,0),new D(-1,0,0),new D(0,1,0),new D(0,-1,0),new D(0,0,1),new D(0,0,-1)],sD=[new D(0,-1,0),new D(0,-1,0),new D(0,0,1),new D(0,0,-1),new D(0,-1,0),new D(0,-1,0)],yy=new lt,Rc=new D,Tp=new D;function rD(o,e,t){let i=new xg;const n=new we,s=new we,r=new wt,a=new V3,l=new W3,c={},h=t.maxTextureSize,d={[Pa]:fi,[fi]:Pa,[Bn]:Bn},u=new Dt({defines:{VSM_SAMPLES:8},uniforms:{shadow_pass:{value:null},resolution:{value:new we},radius:{value:4}},vertexShader:tD,fragmentShader:iD}),f=u.clone();f.defines.HORIZONTAL_PASS=1;const p=new ot;p.setAttribute("position",new st(new Float32Array([-1,-1,.5,3,-1,.5,-1,3,.5]),3));const g=new Se(p,u),m=this;this.enabled=!1,this.autoUpdate=!0,this.needsUpdate=!1,this.type=Zc;let v=this.type;this.render=function(S,A,M){if(m.enabled===!1||m.autoUpdate===!1&&m.needsUpdate===!1||S.length===0)return;this.type===dE&&(ke("WebGLShadowMap: PCFSoftShadowMap has been deprecated. Using PCFShadowMap instead."),this.type=Zc);const _=o.getRenderTarget(),I=o.getActiveCubeFace(),R=o.getActiveMipmapLevel(),L=o.state;L.setBlending(br),L.buffers.depth.getReversed()===!0?L.buffers.color.setClear(0,0,0,0):L.buffers.color.setClear(1,1,1,1),L.buffers.depth.setTest(!0),L.setScissorTest(!1);const P=v!==this.type;P&&A.traverse(function(O){O.material&&(Array.isArray(O.material)?O.material.forEach(k=>k.needsUpdate=!0):O.material.needsUpdate=!0)});for(let O=0,k=S.length;O<k;O++){const F=S[O],z=F.shadow;if(z===void 0){ke("WebGLShadowMap:",F,"has no shadow.");continue}if(z.autoUpdate===!1&&z.needsUpdate===!1)continue;n.copy(z.mapSize);const V=z.getFrameExtents();n.multiply(V),s.copy(z.mapSize),(n.x>h||n.y>h)&&(n.x>h&&(s.x=Math.floor(h/V.x),n.x=s.x*V.x,z.mapSize.x=s.x),n.y>h&&(s.y=Math.floor(h/V.y),n.y=s.y*V.y,z.mapSize.y=s.y));const K=o.state.buffers.depth.getReversed();if(z.camera._reversedDepth=K,z.map===null||P===!0){if(z.map!==null&&(z.map.depthTexture!==null&&(z.map.depthTexture.dispose(),z.map.depthTexture=null),z.map.dispose()),this.type===Wc){if(F.isPointLight){ke("WebGLShadowMap: VSM shadow maps are not supported for PointLights. Use PCF or BasicShadowMap instead.");continue}z.map=new Mi(n.x,n.y,{format:Fo,type:ci,minFilter:mt,magFilter:mt,generateMipmaps:!1}),z.map.texture.name=F.name+".shadowMap",z.map.depthTexture=new La(n.x,n.y,En),z.map.depthTexture.name=F.name+".shadowMapDepth",z.map.depthTexture.format=Wr,z.map.depthTexture.compareFunction=null,z.map.depthTexture.minFilter=Qt,z.map.depthTexture.magFilter=Qt}else F.isPointLight?(z.map=new Eh(n.x),z.map.depthTexture=new F3(n.x,Ts)):(z.map=new Mi(n.x,n.y),z.map.depthTexture=new La(n.x,n.y,Ts)),z.map.depthTexture.name=F.name+".shadowMap",z.map.depthTexture.format=Wr,this.type===Zc?(z.map.depthTexture.compareFunction=K?gg:mg,z.map.depthTexture.minFilter=mt,z.map.depthTexture.magFilter=mt):(z.map.depthTexture.compareFunction=null,z.map.depthTexture.minFilter=Qt,z.map.depthTexture.magFilter=Qt);z.camera.updateProjectionMatrix()}const q=z.map.isWebGLCubeRenderTarget?6:1;for(let te=0;te<q;te++){if(z.map.isWebGLCubeRenderTarget)o.setRenderTarget(z.map,te),o.clear();else{te===0&&(o.setRenderTarget(z.map),o.clear());const re=z.getViewport(te);r.set(s.x*re.x,s.y*re.y,s.x*re.z,s.y*re.w),L.viewport(r)}if(F.isPointLight){const re=z.camera,Ge=z.matrix,ft=F.distance||re.far;ft!==re.far&&(re.far=ft,re.updateProjectionMatrix()),Rc.setFromMatrixPosition(F.matrixWorld),re.position.copy(Rc),Tp.copy(re.position),Tp.add(nD[te]),re.up.copy(sD[te]),re.lookAt(Tp),re.updateMatrixWorld(),Ge.makeTranslation(-Rc.x,-Rc.y,-Rc.z),yy.multiplyMatrices(re.projectionMatrix,re.matrixWorldInverse),z._frustum.setFromProjectionMatrix(yy,re.coordinateSystem,re.reversedDepth)}else z.updateMatrices(F);i=z.getFrustum(),y(A,M,z.camera,F,this.type)}z.isPointLightShadow!==!0&&this.type===Wc&&b(z,M),z.needsUpdate=!1}v=this.type,m.needsUpdate=!1,o.setRenderTarget(_,I,R)};function b(S,A){const M=e.update(g);u.defines.VSM_SAMPLES!==S.blurSamples&&(u.defines.VSM_SAMPLES=S.blurSamples,f.defines.VSM_SAMPLES=S.blurSamples,u.needsUpdate=!0,f.needsUpdate=!0),S.mapPass===null&&(S.mapPass=new Mi(n.x,n.y,{format:Fo,type:ci})),u.uniforms.shadow_pass.value=S.map.depthTexture,u.uniforms.resolution.value=S.mapSize,u.uniforms.radius.value=S.radius,o.setRenderTarget(S.mapPass),o.clear(),o.renderBufferDirect(A,null,M,u,g,null),f.uniforms.shadow_pass.value=S.mapPass.texture,f.uniforms.resolution.value=S.mapSize,f.uniforms.radius.value=S.radius,o.setRenderTarget(S.map),o.clear(),o.renderBufferDirect(A,null,M,f,g,null)}function x(S,A,M,_){let I=null;const R=M.isPointLight===!0?S.customDistanceMaterial:S.customDepthMaterial;if(R!==void 0)I=R;else if(I=M.isPointLight===!0?l:a,o.localClippingEnabled&&A.clipShadows===!0&&Array.isArray(A.clippingPlanes)&&A.clippingPlanes.length!==0||A.displacementMap&&A.displacementScale!==0||A.alphaMap&&A.alphaTest>0||A.map&&A.alphaTest>0||A.alphaToCoverage===!0){const L=I.uuid,P=A.uuid;let O=c[L];O===void 0&&(O={},c[L]=O);let k=O[P];k===void 0&&(k=I.clone(),O[P]=k,A.addEventListener("dispose",w)),I=k}if(I.visible=A.visible,I.wireframe=A.wireframe,_===Wc?I.side=A.shadowSide!==null?A.shadowSide:A.side:I.side=A.shadowSide!==null?A.shadowSide:d[A.side],I.alphaMap=A.alphaMap,I.alphaTest=A.alphaToCoverage===!0?.5:A.alphaTest,I.map=A.map,I.clipShadows=A.clipShadows,I.clippingPlanes=A.clippingPlanes,I.clipIntersection=A.clipIntersection,I.displacementMap=A.displacementMap,I.displacementScale=A.displacementScale,I.displacementBias=A.displacementBias,I.wireframeLinewidth=A.wireframeLinewidth,I.linewidth=A.linewidth,M.isPointLight===!0&&I.isMeshDistanceMaterial===!0){const L=o.properties.get(I);L.light=M}return I}function y(S,A,M,_,I){if(S.visible===!1)return;if(S.layers.test(A.layers)&&(S.isMesh||S.isLine||S.isPoints)&&(S.castShadow||S.receiveShadow&&I===Wc)&&(!S.frustumCulled||i.intersectsObject(S))){S.modelViewMatrix.multiplyMatrices(M.matrixWorldInverse,S.matrixWorld);const P=e.update(S),O=S.material;if(Array.isArray(O)){const k=P.groups;for(let F=0,z=k.length;F<z;F++){const V=k[F],K=O[V.materialIndex];if(K&&K.visible){const q=x(S,K,_,I);S.onBeforeShadow(o,S,A,M,P,q,V),o.renderBufferDirect(M,null,P,q,S,V),S.onAfterShadow(o,S,A,M,P,q,V)}}}else if(O.visible){const k=x(S,O,_,I);S.onBeforeShadow(o,S,A,M,P,k,null),o.renderBufferDirect(M,null,P,k,S,null),S.onAfterShadow(o,S,A,M,P,k,null)}}const L=S.children;for(let P=0,O=L.length;P<O;P++)y(L[P],A,M,_,I)}function w(S){S.target.removeEventListener("dispose",w);for(const M in c){const _=c[M],I=S.target.uuid;I in _&&(_[I].dispose(),delete _[I])}}}function aD(o,e){function t(){let N=!1;const he=new wt;let Q=null;const me=new wt(0,0,0,0);return{setMask:function(xe){Q!==xe&&!N&&(o.colorMask(xe,xe,xe,xe),Q=xe)},setLocked:function(xe){N=xe},setClear:function(xe,ie,Pe,Te,Si){Si===!0&&(xe*=Te,ie*=Te,Pe*=Te),he.set(xe,ie,Pe,Te),me.equals(he)===!1&&(o.clearColor(xe,ie,Pe,Te),me.copy(he))},reset:function(){N=!1,Q=null,me.set(-1,0,0,0)}}}function i(){let N=!1,he=!1,Q=null,me=null,xe=null;return{setReversed:function(ie){if(he!==ie){const Pe=e.get("EXT_clip_control");ie?Pe.clipControlEXT(Pe.LOWER_LEFT_EXT,Pe.ZERO_TO_ONE_EXT):Pe.clipControlEXT(Pe.LOWER_LEFT_EXT,Pe.NEGATIVE_ONE_TO_ONE_EXT),he=ie;const Te=xe;xe=null,this.setClear(Te)}},getReversed:function(){return he},setTest:function(ie){ie?se(o.DEPTH_TEST):G(o.DEPTH_TEST)},setMask:function(ie){Q!==ie&&!N&&(o.depthMask(ie),Q=ie)},setFunc:function(ie){if(he&&(ie=$E[ie]),me!==ie){switch(ie){case _0:o.depthFunc(o.NEVER);break;case T0:o.depthFunc(o.ALWAYS);break;case I0:o.depthFunc(o.LESS);break;case sc:o.depthFunc(o.LEQUAL);break;case D0:o.depthFunc(o.EQUAL);break;case R0:o.depthFunc(o.GEQUAL);break;case C0:o.depthFunc(o.GREATER);break;case k0:o.depthFunc(o.NOTEQUAL);break;default:o.depthFunc(o.LEQUAL)}me=ie}},setLocked:function(ie){N=ie},setClear:function(ie){xe!==ie&&(xe=ie,he&&(ie=1-ie),o.clearDepth(ie))},reset:function(){N=!1,Q=null,me=null,xe=null,he=!1}}}function n(){let N=!1,he=null,Q=null,me=null,xe=null,ie=null,Pe=null,Te=null,Si=null;return{setTest:function(ri){N||(ri?se(o.STENCIL_TEST):G(o.STENCIL_TEST))},setMask:function(ri){he!==ri&&!N&&(o.stencilMask(ri),he=ri)},setFunc:function(ri,qs,Ks){(Q!==ri||me!==qs||xe!==Ks)&&(o.stencilFunc(ri,qs,Ks),Q=ri,me=qs,xe=Ks)},setOp:function(ri,qs,Ks){(ie!==ri||Pe!==qs||Te!==Ks)&&(o.stencilOp(ri,qs,Ks),ie=ri,Pe=qs,Te=Ks)},setLocked:function(ri){N=ri},setClear:function(ri){Si!==ri&&(o.clearStencil(ri),Si=ri)},reset:function(){N=!1,he=null,Q=null,me=null,xe=null,ie=null,Pe=null,Te=null,Si=null}}}const s=new t,r=new i,a=new n,l=new WeakMap,c=new WeakMap;let h={},d={},u={},f=new WeakMap,p=[],g=null,m=!1,v=null,b=null,x=null,y=null,w=null,S=null,A=null,M=new ne(0,0,0),_=0,I=!1,R=null,L=null,P=null,O=null,k=null;const F=o.getParameter(o.MAX_COMBINED_TEXTURE_IMAGE_UNITS);let z=!1,V=0;const K=o.getParameter(o.VERSION);K.indexOf("WebGL")!==-1?(V=parseFloat(/^WebGL (\d)/.exec(K)[1]),z=V>=1):K.indexOf("OpenGL ES")!==-1&&(V=parseFloat(/^OpenGL ES (\d)/.exec(K)[1]),z=V>=2);let q=null,te={};const re=o.getParameter(o.SCISSOR_BOX),Ge=o.getParameter(o.VIEWPORT),ft=new wt().fromArray(re),it=new wt().fromArray(Ge);function Z(N,he,Q,me){const xe=new Uint8Array(4),ie=o.createTexture();o.bindTexture(N,ie),o.texParameteri(N,o.TEXTURE_MIN_FILTER,o.NEAREST),o.texParameteri(N,o.TEXTURE_MAG_FILTER,o.NEAREST);for(let Pe=0;Pe<Q;Pe++)N===o.TEXTURE_3D||N===o.TEXTURE_2D_ARRAY?o.texImage3D(he,0,o.RGBA,1,1,me,0,o.RGBA,o.UNSIGNED_BYTE,xe):o.texImage2D(he+Pe,0,o.RGBA,1,1,0,o.RGBA,o.UNSIGNED_BYTE,xe);return ie}const ae={};ae[o.TEXTURE_2D]=Z(o.TEXTURE_2D,o.TEXTURE_2D,1),ae[o.TEXTURE_CUBE_MAP]=Z(o.TEXTURE_CUBE_MAP,o.TEXTURE_CUBE_MAP_POSITIVE_X,6),ae[o.TEXTURE_2D_ARRAY]=Z(o.TEXTURE_2D_ARRAY,o.TEXTURE_2D_ARRAY,1,1),ae[o.TEXTURE_3D]=Z(o.TEXTURE_3D,o.TEXTURE_3D,1,1),s.setClear(0,0,0,1),r.setClear(1),a.setClear(0),se(o.DEPTH_TEST),r.setFunc(sc),zt(!1),Ht(Qv),se(o.CULL_FACE),Xe(br);function se(N){h[N]!==!0&&(o.enable(N),h[N]=!0)}function G(N){h[N]!==!1&&(o.disable(N),h[N]=!1)}function Re(N,he){return u[N]!==he?(o.bindFramebuffer(N,he),u[N]=he,N===o.DRAW_FRAMEBUFFER&&(u[o.FRAMEBUFFER]=he),N===o.FRAMEBUFFER&&(u[o.DRAW_FRAMEBUFFER]=he),!0):!1}function ze(N,he){let Q=p,me=!1;if(N){Q=f.get(he),Q===void 0&&(Q=[],f.set(he,Q));const xe=N.textures;if(Q.length!==xe.length||Q[0]!==o.COLOR_ATTACHMENT0){for(let ie=0,Pe=xe.length;ie<Pe;ie++)Q[ie]=o.COLOR_ATTACHMENT0+ie;Q.length=xe.length,me=!0}}else Q[0]!==o.BACK&&(Q[0]=o.BACK,me=!0);me&&o.drawBuffers(Q)}function Le(N){return g!==N?(o.useProgram(N),g=N,!0):!1}const Ae={[eo]:o.FUNC_ADD,[uE]:o.FUNC_SUBTRACT,[fE]:o.FUNC_REVERSE_SUBTRACT};Ae[pE]=o.MIN,Ae[mE]=o.MAX;const We={[Xc]:o.ZERO,[yh]:o.ONE,[gE]:o.SRC_COLOR,[A0]:o.SRC_ALPHA,[xE]:o.SRC_ALPHA_SATURATE,[ME]:o.DST_COLOR,[yE]:o.DST_ALPHA,[vE]:o.ONE_MINUS_SRC_COLOR,[bh]:o.ONE_MINUS_SRC_ALPHA,[wE]:o.ONE_MINUS_DST_COLOR,[bE]:o.ONE_MINUS_DST_ALPHA,[SE]:o.CONSTANT_COLOR,[EE]:o.ONE_MINUS_CONSTANT_COLOR,[AE]:o.CONSTANT_ALPHA,[_E]:o.ONE_MINUS_CONSTANT_ALPHA};function Xe(N,he,Q,me,xe,ie,Pe,Te,Si,ri){if(N===br){m===!0&&(G(o.BLEND),m=!1);return}if(m===!1&&(se(o.BLEND),m=!0),N!==Rh){if(N!==v||ri!==I){if((b!==eo||w!==eo)&&(o.blendEquation(o.FUNC_ADD),b=eo,w=eo),ri)switch(N){case Ia:o.blendFuncSeparate(o.ONE,o.ONE_MINUS_SRC_ALPHA,o.ONE,o.ONE_MINUS_SRC_ALPHA);break;case Wi:o.blendFunc(o.ONE,o.ONE);break;case e1:o.blendFuncSeparate(o.ZERO,o.ONE_MINUS_SRC_COLOR,o.ZERO,o.ONE);break;case t1:o.blendFuncSeparate(o.DST_COLOR,o.ONE_MINUS_SRC_ALPHA,o.ZERO,o.ONE);break;default:je("WebGLState: Invalid blending: ",N);break}else switch(N){case Ia:o.blendFuncSeparate(o.SRC_ALPHA,o.ONE_MINUS_SRC_ALPHA,o.ONE,o.ONE_MINUS_SRC_ALPHA);break;case Wi:o.blendFuncSeparate(o.SRC_ALPHA,o.ONE,o.ONE,o.ONE);break;case e1:je("WebGLState: SubtractiveBlending requires material.premultipliedAlpha = true");break;case t1:je("WebGLState: MultiplyBlending requires material.premultipliedAlpha = true");break;default:je("WebGLState: Invalid blending: ",N);break}x=null,y=null,S=null,A=null,M.set(0,0,0),_=0,v=N,I=ri}return}xe=xe||he,ie=ie||Q,Pe=Pe||me,(he!==b||xe!==w)&&(o.blendEquationSeparate(Ae[he],Ae[xe]),b=he,w=xe),(Q!==x||me!==y||ie!==S||Pe!==A)&&(o.blendFuncSeparate(We[Q],We[me],We[ie],We[Pe]),x=Q,y=me,S=ie,A=Pe),(Te.equals(M)===!1||Si!==_)&&(o.blendColor(Te.r,Te.g,Te.b,Si),M.copy(Te),_=Si),v=N,I=!1}function $e(N,he){N.side===Bn?G(o.CULL_FACE):se(o.CULL_FACE);let Q=N.side===fi;he&&(Q=!Q),zt(Q),N.blending===Ia&&N.transparent===!1?Xe(br):Xe(N.blending,N.blendEquation,N.blendSrc,N.blendDst,N.blendEquationAlpha,N.blendSrcAlpha,N.blendDstAlpha,N.blendColor,N.blendAlpha,N.premultipliedAlpha),r.setFunc(N.depthFunc),r.setTest(N.depthTest),r.setMask(N.depthWrite),s.setMask(N.colorWrite);const me=N.stencilWrite;a.setTest(me),me&&(a.setMask(N.stencilWriteMask),a.setFunc(N.stencilFunc,N.stencilRef,N.stencilFuncMask),a.setOp(N.stencilFail,N.stencilZFail,N.stencilZPass)),pi(N.polygonOffset,N.polygonOffsetFactor,N.polygonOffsetUnits),N.alphaToCoverage===!0?se(o.SAMPLE_ALPHA_TO_COVERAGE):G(o.SAMPLE_ALPHA_TO_COVERAGE)}function zt(N){R!==N&&(N?o.frontFace(o.CW):o.frontFace(o.CCW),R=N)}function Ht(N){N!==cE?(se(o.CULL_FACE),N!==L&&(N===Qv?o.cullFace(o.BACK):N===hE?o.cullFace(o.FRONT):o.cullFace(o.FRONT_AND_BACK))):G(o.CULL_FACE),L=N}function wi(N){N!==P&&(z&&o.lineWidth(N),P=N)}function pi(N,he,Q){N?(se(o.POLYGON_OFFSET_FILL),(O!==he||k!==Q)&&(O=he,k=Q,r.getReversed()&&(he=-he),o.polygonOffset(he,Q))):G(o.POLYGON_OFFSET_FILL)}function xi(N){N?se(o.SCISSOR_TEST):G(o.SCISSOR_TEST)}function Ui(N){N===void 0&&(N=o.TEXTURE0+F-1),q!==N&&(o.activeTexture(N),q=N)}function U(N,he,Q){Q===void 0&&(q===null?Q=o.TEXTURE0+F-1:Q=q);let me=te[Q];me===void 0&&(me={type:void 0,texture:void 0},te[Q]=me),(me.type!==N||me.texture!==he)&&(q!==Q&&(o.activeTexture(Q),q=Q),o.bindTexture(N,he||ae[N]),me.type=N,me.texture=he)}function Vn(){const N=te[q];N!==void 0&&N.type!==void 0&&(o.bindTexture(N.type,null),N.type=void 0,N.texture=void 0)}function Gt(){try{o.compressedTexImage2D(...arguments)}catch(N){je("WebGLState:",N)}}function C(){try{o.compressedTexImage3D(...arguments)}catch(N){je("WebGLState:",N)}}function E(){try{o.texSubImage2D(...arguments)}catch(N){je("WebGLState:",N)}}function H(){try{o.texSubImage3D(...arguments)}catch(N){je("WebGLState:",N)}}function $(){try{o.compressedTexSubImage2D(...arguments)}catch(N){je("WebGLState:",N)}}function j(){try{o.compressedTexSubImage3D(...arguments)}catch(N){je("WebGLState:",N)}}function le(){try{o.texStorage2D(...arguments)}catch(N){je("WebGLState:",N)}}function ue(){try{o.texStorage3D(...arguments)}catch(N){je("WebGLState:",N)}}function J(){try{o.texImage2D(...arguments)}catch(N){je("WebGLState:",N)}}function ee(){try{o.texImage3D(...arguments)}catch(N){je("WebGLState:",N)}}function fe(N){return d[N]!==void 0?d[N]:o.getParameter(N)}function Oe(N,he){d[N]!==he&&(o.pixelStorei(N,he),d[N]=he)}function ve(N){ft.equals(N)===!1&&(o.scissor(N.x,N.y,N.z,N.w),ft.copy(N))}function pe(N){it.equals(N)===!1&&(o.viewport(N.x,N.y,N.z,N.w),it.copy(N))}function Ve(N,he){let Q=c.get(he);Q===void 0&&(Q=new WeakMap,c.set(he,Q));let me=Q.get(N);me===void 0&&(me=o.getUniformBlockIndex(he,N.name),Q.set(N,me))}function Ke(N,he){const me=c.get(he).get(N);l.get(he)!==me&&(o.uniformBlockBinding(he,me,N.__bindingPointIndex),l.set(he,me))}function ct(){o.disable(o.BLEND),o.disable(o.CULL_FACE),o.disable(o.DEPTH_TEST),o.disable(o.POLYGON_OFFSET_FILL),o.disable(o.SCISSOR_TEST),o.disable(o.STENCIL_TEST),o.disable(o.SAMPLE_ALPHA_TO_COVERAGE),o.blendEquation(o.FUNC_ADD),o.blendFunc(o.ONE,o.ZERO),o.blendFuncSeparate(o.ONE,o.ZERO,o.ONE,o.ZERO),o.blendColor(0,0,0,0),o.colorMask(!0,!0,!0,!0),o.clearColor(0,0,0,0),o.depthMask(!0),o.depthFunc(o.LESS),r.setReversed(!1),o.clearDepth(1),o.stencilMask(4294967295),o.stencilFunc(o.ALWAYS,0,4294967295),o.stencilOp(o.KEEP,o.KEEP,o.KEEP),o.clearStencil(0),o.cullFace(o.BACK),o.frontFace(o.CCW),o.polygonOffset(0,0),o.activeTexture(o.TEXTURE0),o.bindFramebuffer(o.FRAMEBUFFER,null),o.bindFramebuffer(o.DRAW_FRAMEBUFFER,null),o.bindFramebuffer(o.READ_FRAMEBUFFER,null),o.useProgram(null),o.lineWidth(1),o.scissor(0,0,o.canvas.width,o.canvas.height),o.viewport(0,0,o.canvas.width,o.canvas.height),o.pixelStorei(o.PACK_ALIGNMENT,4),o.pixelStorei(o.UNPACK_ALIGNMENT,4),o.pixelStorei(o.UNPACK_FLIP_Y_WEBGL,!1),o.pixelStorei(o.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),o.pixelStorei(o.UNPACK_COLORSPACE_CONVERSION_WEBGL,o.BROWSER_DEFAULT_WEBGL),o.pixelStorei(o.PACK_ROW_LENGTH,0),o.pixelStorei(o.PACK_SKIP_PIXELS,0),o.pixelStorei(o.PACK_SKIP_ROWS,0),o.pixelStorei(o.UNPACK_ROW_LENGTH,0),o.pixelStorei(o.UNPACK_IMAGE_HEIGHT,0),o.pixelStorei(o.UNPACK_SKIP_PIXELS,0),o.pixelStorei(o.UNPACK_SKIP_ROWS,0),o.pixelStorei(o.UNPACK_SKIP_IMAGES,0),h={},d={},q=null,te={},u={},f=new WeakMap,p=[],g=null,m=!1,v=null,b=null,x=null,y=null,w=null,S=null,A=null,M=new ne(0,0,0),_=0,I=!1,R=null,L=null,P=null,O=null,k=null,ft.set(0,0,o.canvas.width,o.canvas.height),it.set(0,0,o.canvas.width,o.canvas.height),s.reset(),r.reset(),a.reset()}return{buffers:{color:s,depth:r,stencil:a},enable:se,disable:G,bindFramebuffer:Re,drawBuffers:ze,useProgram:Le,setBlending:Xe,setMaterial:$e,setFlipSided:zt,setCullFace:Ht,setLineWidth:wi,setPolygonOffset:pi,setScissorTest:xi,activeTexture:Ui,bindTexture:U,unbindTexture:Vn,compressedTexImage2D:Gt,compressedTexImage3D:C,texImage2D:J,texImage3D:ee,pixelStorei:Oe,getParameter:fe,updateUBOMapping:Ve,uniformBlockBinding:Ke,texStorage2D:le,texStorage3D:ue,texSubImage2D:E,texSubImage3D:H,compressedTexSubImage2D:$,compressedTexSubImage3D:j,scissor:ve,viewport:pe,reset:ct}}function oD(o,e,t,i,n,s,r){const a=e.has("WEBGL_multisampled_render_to_texture")?e.get("WEBGL_multisampled_render_to_texture"):null,l=typeof navigator>"u"?!1:/OculusBrowser/g.test(navigator.userAgent),c=new we,h=new WeakMap,d=new Set;let u;const f=new WeakMap;let p=!1;try{p=typeof OffscreenCanvas<"u"&&new OffscreenCanvas(1,1).getContext("2d")!==null}catch{}function g(C,E){return p?new OffscreenCanvas(C,E):Sh("canvas")}function m(C,E,H){let $=1;const j=Gt(C);if((j.width>H||j.height>H)&&($=H/Math.max(j.width,j.height)),$<1)if(typeof HTMLImageElement<"u"&&C instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&C instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&C instanceof ImageBitmap||typeof VideoFrame<"u"&&C instanceof VideoFrame){const le=Math.floor($*j.width),ue=Math.floor($*j.height);u===void 0&&(u=g(le,ue));const J=E?g(le,ue):u;return J.width=le,J.height=ue,J.getContext("2d").drawImage(C,0,0,le,ue),ke("WebGLRenderer: Texture has been resized from ("+j.width+"x"+j.height+") to ("+le+"x"+ue+")."),J}else return"data"in C&&ke("WebGLRenderer: Image in DataTexture is too big ("+j.width+"x"+j.height+")."),C;return C}function v(C){return C.generateMipmaps}function b(C){o.generateMipmap(C)}function x(C){return C.isWebGLCubeRenderTarget?o.TEXTURE_CUBE_MAP:C.isWebGL3DRenderTarget?o.TEXTURE_3D:C.isWebGLArrayRenderTarget||C.isCompressedArrayTexture?o.TEXTURE_2D_ARRAY:o.TEXTURE_2D}function y(C,E,H,$,j,le=!1){if(C!==null){if(o[C]!==void 0)return o[C];ke("WebGLRenderer: Attempt to use non-existing WebGL internal format '"+C+"'")}let ue;$&&(ue=e.get("EXT_texture_norm16"),ue||ke("WebGLRenderer: Unable to use normalized textures without EXT_texture_norm16 extension"));let J=E;if(E===o.RED&&(H===o.FLOAT&&(J=o.R32F),H===o.HALF_FLOAT&&(J=o.R16F),H===o.UNSIGNED_BYTE&&(J=o.R8),H===o.UNSIGNED_SHORT&&ue&&(J=ue.R16_EXT),H===o.SHORT&&ue&&(J=ue.R16_SNORM_EXT)),E===o.RED_INTEGER&&(H===o.UNSIGNED_BYTE&&(J=o.R8UI),H===o.UNSIGNED_SHORT&&(J=o.R16UI),H===o.UNSIGNED_INT&&(J=o.R32UI),H===o.BYTE&&(J=o.R8I),H===o.SHORT&&(J=o.R16I),H===o.INT&&(J=o.R32I)),E===o.RG&&(H===o.FLOAT&&(J=o.RG32F),H===o.HALF_FLOAT&&(J=o.RG16F),H===o.UNSIGNED_BYTE&&(J=o.RG8),H===o.UNSIGNED_SHORT&&ue&&(J=ue.RG16_EXT),H===o.SHORT&&ue&&(J=ue.RG16_SNORM_EXT)),E===o.RG_INTEGER&&(H===o.UNSIGNED_BYTE&&(J=o.RG8UI),H===o.UNSIGNED_SHORT&&(J=o.RG16UI),H===o.UNSIGNED_INT&&(J=o.RG32UI),H===o.BYTE&&(J=o.RG8I),H===o.SHORT&&(J=o.RG16I),H===o.INT&&(J=o.RG32I)),E===o.RGB_INTEGER&&(H===o.UNSIGNED_BYTE&&(J=o.RGB8UI),H===o.UNSIGNED_SHORT&&(J=o.RGB16UI),H===o.UNSIGNED_INT&&(J=o.RGB32UI),H===o.BYTE&&(J=o.RGB8I),H===o.SHORT&&(J=o.RGB16I),H===o.INT&&(J=o.RGB32I)),E===o.RGBA_INTEGER&&(H===o.UNSIGNED_BYTE&&(J=o.RGBA8UI),H===o.UNSIGNED_SHORT&&(J=o.RGBA16UI),H===o.UNSIGNED_INT&&(J=o.RGBA32UI),H===o.BYTE&&(J=o.RGBA8I),H===o.SHORT&&(J=o.RGBA16I),H===o.INT&&(J=o.RGBA32I)),E===o.RGB&&(H===o.UNSIGNED_SHORT&&ue&&(J=ue.RGB16_EXT),H===o.SHORT&&ue&&(J=ue.RGB16_SNORM_EXT),H===o.UNSIGNED_INT_5_9_9_9_REV&&(J=o.RGB9_E5),H===o.UNSIGNED_INT_10F_11F_11F_REV&&(J=o.R11F_G11F_B10F)),E===o.RGBA){const ee=le?Vu:Tt.getTransfer(j);H===o.FLOAT&&(J=o.RGBA32F),H===o.HALF_FLOAT&&(J=o.RGBA16F),H===o.UNSIGNED_BYTE&&(J=ee===Yt?o.SRGB8_ALPHA8:o.RGBA8),H===o.UNSIGNED_SHORT&&ue&&(J=ue.RGBA16_EXT),H===o.SHORT&&ue&&(J=ue.RGBA16_SNORM_EXT),H===o.UNSIGNED_SHORT_4_4_4_4&&(J=o.RGBA4),H===o.UNSIGNED_SHORT_5_5_5_1&&(J=o.RGB5_A1)}return(J===o.R16F||J===o.R32F||J===o.RG16F||J===o.RG32F||J===o.RGBA16F||J===o.RGBA32F)&&e.get("EXT_color_buffer_float"),J}function w(C,E){let H;return C?E===null||E===Ts||E===wh?H=o.DEPTH24_STENCIL8:E===En?H=o.DEPTH32F_STENCIL8:E===Mh&&(H=o.DEPTH24_STENCIL8,ke("DepthTexture: 16 bit depth attachment is not supported with stencil. Using 24-bit attachment.")):E===null||E===Ts||E===wh?H=o.DEPTH_COMPONENT24:E===En?H=o.DEPTH_COMPONENT32F:E===Mh&&(H=o.DEPTH_COMPONENT16),H}function S(C,E){return v(C)===!0||C.isFramebufferTexture&&C.minFilter!==Qt&&C.minFilter!==mt?Math.log2(Math.max(E.width,E.height))+1:C.mipmaps!==void 0&&C.mipmaps.length>0?C.mipmaps.length:C.isCompressedTexture&&Array.isArray(C.image)?E.mipmaps.length:1}function A(C){const E=C.target;E.removeEventListener("dispose",A),_(E),E.isVideoTexture&&h.delete(E),E.isHTMLTexture&&d.delete(E)}function M(C){const E=C.target;E.removeEventListener("dispose",M),R(E)}function _(C){const E=i.get(C);if(E.__webglInit===void 0)return;const H=C.source,$=f.get(H);if($){const j=$[E.__cacheKey];j.usedTimes--,j.usedTimes===0&&I(C),Object.keys($).length===0&&f.delete(H)}i.remove(C)}function I(C){const E=i.get(C);o.deleteTexture(E.__webglTexture);const H=C.source,$=f.get(H);delete $[E.__cacheKey],r.memory.textures--}function R(C){const E=i.get(C);if(C.depthTexture&&(C.depthTexture.dispose(),i.remove(C.depthTexture)),C.isWebGLCubeRenderTarget)for(let $=0;$<6;$++){if(Array.isArray(E.__webglFramebuffer[$]))for(let j=0;j<E.__webglFramebuffer[$].length;j++)o.deleteFramebuffer(E.__webglFramebuffer[$][j]);else o.deleteFramebuffer(E.__webglFramebuffer[$]);E.__webglDepthbuffer&&o.deleteRenderbuffer(E.__webglDepthbuffer[$])}else{if(Array.isArray(E.__webglFramebuffer))for(let $=0;$<E.__webglFramebuffer.length;$++)o.deleteFramebuffer(E.__webglFramebuffer[$]);else o.deleteFramebuffer(E.__webglFramebuffer);if(E.__webglDepthbuffer&&o.deleteRenderbuffer(E.__webglDepthbuffer),E.__webglMultisampledFramebuffer&&o.deleteFramebuffer(E.__webglMultisampledFramebuffer),E.__webglColorRenderbuffer)for(let $=0;$<E.__webglColorRenderbuffer.length;$++)E.__webglColorRenderbuffer[$]&&o.deleteRenderbuffer(E.__webglColorRenderbuffer[$]);E.__webglDepthRenderbuffer&&o.deleteRenderbuffer(E.__webglDepthRenderbuffer)}const H=C.textures;for(let $=0,j=H.length;$<j;$++){const le=i.get(H[$]);le.__webglTexture&&(o.deleteTexture(le.__webglTexture),r.memory.textures--),i.remove(H[$])}i.remove(C)}let L=0;function P(){L=0}function O(){return L}function k(C){L=C}function F(){const C=L;return C>=n.maxTextures&&ke("WebGLTextures: Trying to use "+C+" texture units while this GPU supports only "+n.maxTextures),L+=1,C}function z(C){const E=[];return E.push(C.wrapS),E.push(C.wrapT),E.push(C.wrapR||0),E.push(C.magFilter),E.push(C.minFilter),E.push(C.anisotropy),E.push(C.internalFormat),E.push(C.format),E.push(C.type),E.push(C.generateMipmaps),E.push(C.premultiplyAlpha),E.push(C.flipY),E.push(C.unpackAlignment),E.push(C.colorSpace),E.join()}function V(C,E){const H=i.get(C);if(C.isVideoTexture&&U(C),C.isRenderTargetTexture===!1&&C.isExternalTexture!==!0&&C.version>0&&H.__version!==C.version){const $=C.image;if($===null)ke("WebGLRenderer: Texture marked for update but no image data found.");else if($.complete===!1)ke("WebGLRenderer: Texture marked for update but image is incomplete");else{G(H,C,E);return}}else C.isExternalTexture&&(H.__webglTexture=C.sourceTexture?C.sourceTexture:null);t.bindTexture(o.TEXTURE_2D,H.__webglTexture,o.TEXTURE0+E)}function K(C,E){const H=i.get(C);if(C.isRenderTargetTexture===!1&&C.version>0&&H.__version!==C.version){G(H,C,E);return}else C.isExternalTexture&&(H.__webglTexture=C.sourceTexture?C.sourceTexture:null);t.bindTexture(o.TEXTURE_2D_ARRAY,H.__webglTexture,o.TEXTURE0+E)}function q(C,E){const H=i.get(C);if(C.isRenderTargetTexture===!1&&C.version>0&&H.__version!==C.version){G(H,C,E);return}t.bindTexture(o.TEXTURE_3D,H.__webglTexture,o.TEXTURE0+E)}function te(C,E){const H=i.get(C);if(C.isCubeDepthTexture!==!0&&C.version>0&&H.__version!==C.version){Re(H,C,E);return}t.bindTexture(o.TEXTURE_CUBE_MAP,H.__webglTexture,o.TEXTURE0+E)}const re={[No]:o.REPEAT,[Ti]:o.CLAMP_TO_EDGE,[P0]:o.MIRRORED_REPEAT},Ge={[Qt]:o.NEAREST,[RE]:o.NEAREST_MIPMAP_NEAREST,[Xh]:o.NEAREST_MIPMAP_LINEAR,[mt]:o.LINEAR,[Xf]:o.LINEAR_MIPMAP_NEAREST,[gr]:o.LINEAR_MIPMAP_LINEAR},ft={[NE]:o.NEVER,[HE]:o.ALWAYS,[FE]:o.LESS,[mg]:o.LEQUAL,[UE]:o.EQUAL,[gg]:o.GEQUAL,[BE]:o.GREATER,[zE]:o.NOTEQUAL};function it(C,E){if(E.type===En&&e.has("OES_texture_float_linear")===!1&&(E.magFilter===mt||E.magFilter===Xf||E.magFilter===Xh||E.magFilter===gr||E.minFilter===mt||E.minFilter===Xf||E.minFilter===Xh||E.minFilter===gr)&&ke("WebGLRenderer: Unable to use linear filtering with floating point textures. OES_texture_float_linear not supported on this device."),o.texParameteri(C,o.TEXTURE_WRAP_S,re[E.wrapS]),o.texParameteri(C,o.TEXTURE_WRAP_T,re[E.wrapT]),(C===o.TEXTURE_3D||C===o.TEXTURE_2D_ARRAY)&&o.texParameteri(C,o.TEXTURE_WRAP_R,re[E.wrapR]),o.texParameteri(C,o.TEXTURE_MAG_FILTER,Ge[E.magFilter]),o.texParameteri(C,o.TEXTURE_MIN_FILTER,Ge[E.minFilter]),E.compareFunction&&(o.texParameteri(C,o.TEXTURE_COMPARE_MODE,o.COMPARE_REF_TO_TEXTURE),o.texParameteri(C,o.TEXTURE_COMPARE_FUNC,ft[E.compareFunction])),e.has("EXT_texture_filter_anisotropic")===!0){if(E.magFilter===Qt||E.minFilter!==Xh&&E.minFilter!==gr||E.type===En&&e.has("OES_texture_float_linear")===!1)return;if(E.anisotropy>1||i.get(E).__currentAnisotropy){const H=e.get("EXT_texture_filter_anisotropic");o.texParameterf(C,H.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(E.anisotropy,n.getMaxAnisotropy())),i.get(E).__currentAnisotropy=E.anisotropy}}}function Z(C,E){let H=!1;C.__webglInit===void 0&&(C.__webglInit=!0,E.addEventListener("dispose",A));const $=E.source;let j=f.get($);j===void 0&&(j={},f.set($,j));const le=z(E);if(le!==C.__cacheKey){j[le]===void 0&&(j[le]={texture:o.createTexture(),usedTimes:0},r.memory.textures++,H=!0),j[le].usedTimes++;const ue=j[C.__cacheKey];ue!==void 0&&(j[C.__cacheKey].usedTimes--,ue.usedTimes===0&&I(E)),C.__cacheKey=le,C.__webglTexture=j[le].texture}return H}function ae(C,E,H){return Math.floor(Math.floor(C/H)/E)}function se(C,E,H,$){const le=C.updateRanges;if(le.length===0)t.texSubImage2D(o.TEXTURE_2D,0,0,0,E.width,E.height,H,$,E.data);else{le.sort((Oe,ve)=>Oe.start-ve.start);let ue=0;for(let Oe=1;Oe<le.length;Oe++){const ve=le[ue],pe=le[Oe],Ve=ve.start+ve.count,Ke=ae(pe.start,E.width,4),ct=ae(ve.start,E.width,4);pe.start<=Ve+1&&Ke===ct&&ae(pe.start+pe.count-1,E.width,4)===Ke?ve.count=Math.max(ve.count,pe.start+pe.count-ve.start):(++ue,le[ue]=pe)}le.length=ue+1;const J=t.getParameter(o.UNPACK_ROW_LENGTH),ee=t.getParameter(o.UNPACK_SKIP_PIXELS),fe=t.getParameter(o.UNPACK_SKIP_ROWS);t.pixelStorei(o.UNPACK_ROW_LENGTH,E.width);for(let Oe=0,ve=le.length;Oe<ve;Oe++){const pe=le[Oe],Ve=Math.floor(pe.start/4),Ke=Math.ceil(pe.count/4),ct=Ve%E.width,N=Math.floor(Ve/E.width),he=Ke,Q=1;t.pixelStorei(o.UNPACK_SKIP_PIXELS,ct),t.pixelStorei(o.UNPACK_SKIP_ROWS,N),t.texSubImage2D(o.TEXTURE_2D,0,ct,N,he,Q,H,$,E.data)}C.clearUpdateRanges(),t.pixelStorei(o.UNPACK_ROW_LENGTH,J),t.pixelStorei(o.UNPACK_SKIP_PIXELS,ee),t.pixelStorei(o.UNPACK_SKIP_ROWS,fe)}}function G(C,E,H){let $=o.TEXTURE_2D;(E.isDataArrayTexture||E.isCompressedArrayTexture)&&($=o.TEXTURE_2D_ARRAY),E.isData3DTexture&&($=o.TEXTURE_3D);const j=Z(C,E),le=E.source;t.bindTexture($,C.__webglTexture,o.TEXTURE0+H);const ue=i.get(le);if(le.version!==ue.__version||j===!0){if(t.activeTexture(o.TEXTURE0+H),(typeof ImageBitmap<"u"&&E.image instanceof ImageBitmap)===!1){const Q=Tt.getPrimaries(Tt.workingColorSpace),me=E.colorSpace===ba?null:Tt.getPrimaries(E.colorSpace),xe=E.colorSpace===ba||Q===me?o.NONE:o.BROWSER_DEFAULT_WEBGL;t.pixelStorei(o.UNPACK_FLIP_Y_WEBGL,E.flipY),t.pixelStorei(o.UNPACK_PREMULTIPLY_ALPHA_WEBGL,E.premultiplyAlpha),t.pixelStorei(o.UNPACK_COLORSPACE_CONVERSION_WEBGL,xe)}t.pixelStorei(o.UNPACK_ALIGNMENT,E.unpackAlignment);let ee=m(E.image,!1,n.maxTextureSize);ee=Vn(E,ee);const fe=s.convert(E.format,E.colorSpace),Oe=s.convert(E.type);let ve=y(E.internalFormat,fe,Oe,E.normalized,E.colorSpace,E.isVideoTexture);it($,E);let pe;const Ve=E.mipmaps,Ke=E.isVideoTexture!==!0,ct=ue.__version===void 0||j===!0,N=le.dataReady,he=S(E,ee);if(E.isDepthTexture)ve=w(E.format===bo,E.type),ct&&(Ke?t.texStorage2D(o.TEXTURE_2D,1,ve,ee.width,ee.height):t.texImage2D(o.TEXTURE_2D,0,ve,ee.width,ee.height,0,fe,Oe,null));else if(E.isDataTexture)if(Ve.length>0){Ke&&ct&&t.texStorage2D(o.TEXTURE_2D,he,ve,Ve[0].width,Ve[0].height);for(let Q=0,me=Ve.length;Q<me;Q++)pe=Ve[Q],Ke?N&&t.texSubImage2D(o.TEXTURE_2D,Q,0,0,pe.width,pe.height,fe,Oe,pe.data):t.texImage2D(o.TEXTURE_2D,Q,ve,pe.width,pe.height,0,fe,Oe,pe.data);E.generateMipmaps=!1}else Ke?(ct&&t.texStorage2D(o.TEXTURE_2D,he,ve,ee.width,ee.height),N&&se(E,ee,fe,Oe)):t.texImage2D(o.TEXTURE_2D,0,ve,ee.width,ee.height,0,fe,Oe,ee.data);else if(E.isCompressedTexture)if(E.isCompressedArrayTexture){Ke&&ct&&t.texStorage3D(o.TEXTURE_2D_ARRAY,he,ve,Ve[0].width,Ve[0].height,ee.depth);for(let Q=0,me=Ve.length;Q<me;Q++)if(pe=Ve[Q],E.format!==Vi)if(fe!==null)if(Ke){if(N)if(E.layerUpdates.size>0){const xe=Z1(pe.width,pe.height,E.format,E.type);for(const ie of E.layerUpdates){const Pe=pe.data.subarray(ie*xe/pe.data.BYTES_PER_ELEMENT,(ie+1)*xe/pe.data.BYTES_PER_ELEMENT);t.compressedTexSubImage3D(o.TEXTURE_2D_ARRAY,Q,0,0,ie,pe.width,pe.height,1,fe,Pe)}E.clearLayerUpdates()}else t.compressedTexSubImage3D(o.TEXTURE_2D_ARRAY,Q,0,0,0,pe.width,pe.height,ee.depth,fe,pe.data)}else t.compressedTexImage3D(o.TEXTURE_2D_ARRAY,Q,ve,pe.width,pe.height,ee.depth,0,pe.data,0,0);else ke("WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()");else Ke?N&&t.texSubImage3D(o.TEXTURE_2D_ARRAY,Q,0,0,0,pe.width,pe.height,ee.depth,fe,Oe,pe.data):t.texImage3D(o.TEXTURE_2D_ARRAY,Q,ve,pe.width,pe.height,ee.depth,0,fe,Oe,pe.data)}else{Ke&&ct&&t.texStorage2D(o.TEXTURE_2D,he,ve,Ve[0].width,Ve[0].height);for(let Q=0,me=Ve.length;Q<me;Q++)pe=Ve[Q],E.format!==Vi?fe!==null?Ke?N&&t.compressedTexSubImage2D(o.TEXTURE_2D,Q,0,0,pe.width,pe.height,fe,pe.data):t.compressedTexImage2D(o.TEXTURE_2D,Q,ve,pe.width,pe.height,0,pe.data):ke("WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()"):Ke?N&&t.texSubImage2D(o.TEXTURE_2D,Q,0,0,pe.width,pe.height,fe,Oe,pe.data):t.texImage2D(o.TEXTURE_2D,Q,ve,pe.width,pe.height,0,fe,Oe,pe.data)}else if(E.isDataArrayTexture)if(Ke){if(ct&&t.texStorage3D(o.TEXTURE_2D_ARRAY,he,ve,ee.width,ee.height,ee.depth),N)if(E.layerUpdates.size>0){const Q=Z1(ee.width,ee.height,E.format,E.type);for(const me of E.layerUpdates){const xe=ee.data.subarray(me*Q/ee.data.BYTES_PER_ELEMENT,(me+1)*Q/ee.data.BYTES_PER_ELEMENT);t.texSubImage3D(o.TEXTURE_2D_ARRAY,0,0,0,me,ee.width,ee.height,1,fe,Oe,xe)}E.clearLayerUpdates()}else t.texSubImage3D(o.TEXTURE_2D_ARRAY,0,0,0,0,ee.width,ee.height,ee.depth,fe,Oe,ee.data)}else t.texImage3D(o.TEXTURE_2D_ARRAY,0,ve,ee.width,ee.height,ee.depth,0,fe,Oe,ee.data);else if(E.isData3DTexture)Ke?(ct&&t.texStorage3D(o.TEXTURE_3D,he,ve,ee.width,ee.height,ee.depth),N&&t.texSubImage3D(o.TEXTURE_3D,0,0,0,0,ee.width,ee.height,ee.depth,fe,Oe,ee.data)):t.texImage3D(o.TEXTURE_3D,0,ve,ee.width,ee.height,ee.depth,0,fe,Oe,ee.data);else if(E.isFramebufferTexture){if(ct)if(Ke)t.texStorage2D(o.TEXTURE_2D,he,ve,ee.width,ee.height);else{let Q=ee.width,me=ee.height;for(let xe=0;xe<he;xe++)t.texImage2D(o.TEXTURE_2D,xe,ve,Q,me,0,fe,Oe,null),Q>>=1,me>>=1}}else if(E.isHTMLTexture){if("texElementImage2D"in o){const Q=o.canvas;if(Q.hasAttribute("layoutsubtree")||Q.setAttribute("layoutsubtree","true"),ee.parentNode!==Q){Q.appendChild(ee),d.add(E),Q.onpaint=me=>{const xe=me.changedElements;for(const ie of d)xe.includes(ie.image)&&(ie.needsUpdate=!0)},Q.requestPaint();return}if(o.texElementImage2D.length===3)o.texElementImage2D(o.TEXTURE_2D,o.RGBA8,ee);else{const xe=o.RGBA,ie=o.RGBA,Pe=o.UNSIGNED_BYTE;o.texElementImage2D(o.TEXTURE_2D,0,xe,ie,Pe,ee)}o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MIN_FILTER,o.LINEAR),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_S,o.CLAMP_TO_EDGE),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_T,o.CLAMP_TO_EDGE)}}else if(Ve.length>0){if(Ke&&ct){const Q=Gt(Ve[0]);t.texStorage2D(o.TEXTURE_2D,he,ve,Q.width,Q.height)}for(let Q=0,me=Ve.length;Q<me;Q++)pe=Ve[Q],Ke?N&&t.texSubImage2D(o.TEXTURE_2D,Q,0,0,fe,Oe,pe):t.texImage2D(o.TEXTURE_2D,Q,ve,fe,Oe,pe);E.generateMipmaps=!1}else if(Ke){if(ct){const Q=Gt(ee);t.texStorage2D(o.TEXTURE_2D,he,ve,Q.width,Q.height)}N&&t.texSubImage2D(o.TEXTURE_2D,0,0,0,fe,Oe,ee)}else t.texImage2D(o.TEXTURE_2D,0,ve,fe,Oe,ee);v(E)&&b($),ue.__version=le.version,E.onUpdate&&E.onUpdate(E)}C.__version=E.version}function Re(C,E,H){if(E.image.length!==6)return;const $=Z(C,E),j=E.source;t.bindTexture(o.TEXTURE_CUBE_MAP,C.__webglTexture,o.TEXTURE0+H);const le=i.get(j);if(j.version!==le.__version||$===!0){t.activeTexture(o.TEXTURE0+H);const ue=Tt.getPrimaries(Tt.workingColorSpace),J=E.colorSpace===ba?null:Tt.getPrimaries(E.colorSpace),ee=E.colorSpace===ba||ue===J?o.NONE:o.BROWSER_DEFAULT_WEBGL;t.pixelStorei(o.UNPACK_FLIP_Y_WEBGL,E.flipY),t.pixelStorei(o.UNPACK_PREMULTIPLY_ALPHA_WEBGL,E.premultiplyAlpha),t.pixelStorei(o.UNPACK_ALIGNMENT,E.unpackAlignment),t.pixelStorei(o.UNPACK_COLORSPACE_CONVERSION_WEBGL,ee);const fe=E.isCompressedTexture||E.image[0].isCompressedTexture,Oe=E.image[0]&&E.image[0].isDataTexture,ve=[];for(let ie=0;ie<6;ie++)!fe&&!Oe?ve[ie]=m(E.image[ie],!0,n.maxCubemapSize):ve[ie]=Oe?E.image[ie].image:E.image[ie],ve[ie]=Vn(E,ve[ie]);const pe=ve[0],Ve=s.convert(E.format,E.colorSpace),Ke=s.convert(E.type),ct=y(E.internalFormat,Ve,Ke,E.normalized,E.colorSpace),N=E.isVideoTexture!==!0,he=le.__version===void 0||$===!0,Q=j.dataReady;let me=S(E,pe);it(o.TEXTURE_CUBE_MAP,E);let xe;if(fe){N&&he&&t.texStorage2D(o.TEXTURE_CUBE_MAP,me,ct,pe.width,pe.height);for(let ie=0;ie<6;ie++){xe=ve[ie].mipmaps;for(let Pe=0;Pe<xe.length;Pe++){const Te=xe[Pe];E.format!==Vi?Ve!==null?N?Q&&t.compressedTexSubImage2D(o.TEXTURE_CUBE_MAP_POSITIVE_X+ie,Pe,0,0,Te.width,Te.height,Ve,Te.data):t.compressedTexImage2D(o.TEXTURE_CUBE_MAP_POSITIVE_X+ie,Pe,ct,Te.width,Te.height,0,Te.data):ke("WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()"):N?Q&&t.texSubImage2D(o.TEXTURE_CUBE_MAP_POSITIVE_X+ie,Pe,0,0,Te.width,Te.height,Ve,Ke,Te.data):t.texImage2D(o.TEXTURE_CUBE_MAP_POSITIVE_X+ie,Pe,ct,Te.width,Te.height,0,Ve,Ke,Te.data)}}}else{if(xe=E.mipmaps,N&&he){xe.length>0&&me++;const ie=Gt(ve[0]);t.texStorage2D(o.TEXTURE_CUBE_MAP,me,ct,ie.width,ie.height)}for(let ie=0;ie<6;ie++)if(Oe){N?Q&&t.texSubImage2D(o.TEXTURE_CUBE_MAP_POSITIVE_X+ie,0,0,0,ve[ie].width,ve[ie].height,Ve,Ke,ve[ie].data):t.texImage2D(o.TEXTURE_CUBE_MAP_POSITIVE_X+ie,0,ct,ve[ie].width,ve[ie].height,0,Ve,Ke,ve[ie].data);for(let Pe=0;Pe<xe.length;Pe++){const Si=xe[Pe].image[ie].image;N?Q&&t.texSubImage2D(o.TEXTURE_CUBE_MAP_POSITIVE_X+ie,Pe+1,0,0,Si.width,Si.height,Ve,Ke,Si.data):t.texImage2D(o.TEXTURE_CUBE_MAP_POSITIVE_X+ie,Pe+1,ct,Si.width,Si.height,0,Ve,Ke,Si.data)}}else{N?Q&&t.texSubImage2D(o.TEXTURE_CUBE_MAP_POSITIVE_X+ie,0,0,0,Ve,Ke,ve[ie]):t.texImage2D(o.TEXTURE_CUBE_MAP_POSITIVE_X+ie,0,ct,Ve,Ke,ve[ie]);for(let Pe=0;Pe<xe.length;Pe++){const Te=xe[Pe];N?Q&&t.texSubImage2D(o.TEXTURE_CUBE_MAP_POSITIVE_X+ie,Pe+1,0,0,Ve,Ke,Te.image[ie]):t.texImage2D(o.TEXTURE_CUBE_MAP_POSITIVE_X+ie,Pe+1,ct,Ve,Ke,Te.image[ie])}}}v(E)&&b(o.TEXTURE_CUBE_MAP),le.__version=j.version,E.onUpdate&&E.onUpdate(E)}C.__version=E.version}function ze(C,E,H,$,j,le){const ue=s.convert(H.format,H.colorSpace),J=s.convert(H.type),ee=y(H.internalFormat,ue,J,H.normalized,H.colorSpace),fe=i.get(E),Oe=i.get(H);if(Oe.__renderTarget=E,!fe.__hasExternalTextures){const ve=Math.max(1,E.width>>le),pe=Math.max(1,E.height>>le);j===o.TEXTURE_3D||j===o.TEXTURE_2D_ARRAY?t.texImage3D(j,le,ee,ve,pe,E.depth,0,ue,J,null):t.texImage2D(j,le,ee,ve,pe,0,ue,J,null)}t.bindFramebuffer(o.FRAMEBUFFER,C),Ui(E)?a.framebufferTexture2DMultisampleEXT(o.FRAMEBUFFER,$,j,Oe.__webglTexture,0,xi(E)):(j===o.TEXTURE_2D||j>=o.TEXTURE_CUBE_MAP_POSITIVE_X&&j<=o.TEXTURE_CUBE_MAP_NEGATIVE_Z)&&o.framebufferTexture2D(o.FRAMEBUFFER,$,j,Oe.__webglTexture,le),t.bindFramebuffer(o.FRAMEBUFFER,null)}function Le(C,E,H){if(o.bindRenderbuffer(o.RENDERBUFFER,C),E.depthBuffer){const $=E.depthTexture,j=$&&$.isDepthTexture?$.type:null,le=w(E.stencilBuffer,j),ue=E.stencilBuffer?o.DEPTH_STENCIL_ATTACHMENT:o.DEPTH_ATTACHMENT;Ui(E)?a.renderbufferStorageMultisampleEXT(o.RENDERBUFFER,xi(E),le,E.width,E.height):H?o.renderbufferStorageMultisample(o.RENDERBUFFER,xi(E),le,E.width,E.height):o.renderbufferStorage(o.RENDERBUFFER,le,E.width,E.height),o.framebufferRenderbuffer(o.FRAMEBUFFER,ue,o.RENDERBUFFER,C)}else{const $=E.textures;for(let j=0;j<$.length;j++){const le=$[j],ue=s.convert(le.format,le.colorSpace),J=s.convert(le.type),ee=y(le.internalFormat,ue,J,le.normalized,le.colorSpace);Ui(E)?a.renderbufferStorageMultisampleEXT(o.RENDERBUFFER,xi(E),ee,E.width,E.height):H?o.renderbufferStorageMultisample(o.RENDERBUFFER,xi(E),ee,E.width,E.height):o.renderbufferStorage(o.RENDERBUFFER,ee,E.width,E.height)}}o.bindRenderbuffer(o.RENDERBUFFER,null)}function Ae(C,E,H){const $=E.isWebGLCubeRenderTarget===!0;if(t.bindFramebuffer(o.FRAMEBUFFER,C),!(E.depthTexture&&E.depthTexture.isDepthTexture))throw new Error("THREE.WebGLTextures: renderTarget.depthTexture must be an instance of THREE.DepthTexture.");const j=i.get(E.depthTexture);if(j.__renderTarget=E,(!j.__webglTexture||E.depthTexture.image.width!==E.width||E.depthTexture.image.height!==E.height)&&(E.depthTexture.image.width=E.width,E.depthTexture.image.height=E.height,E.depthTexture.needsUpdate=!0),$){if(j.__webglInit===void 0&&(j.__webglInit=!0,E.depthTexture.addEventListener("dispose",A)),j.__webglTexture===void 0){j.__webglTexture=o.createTexture(),t.bindTexture(o.TEXTURE_CUBE_MAP,j.__webglTexture),it(o.TEXTURE_CUBE_MAP,E.depthTexture);const fe=s.convert(E.depthTexture.format),Oe=s.convert(E.depthTexture.type);let ve;E.depthTexture.format===Wr?ve=o.DEPTH_COMPONENT24:E.depthTexture.format===bo&&(ve=o.DEPTH24_STENCIL8);for(let pe=0;pe<6;pe++)o.texImage2D(o.TEXTURE_CUBE_MAP_POSITIVE_X+pe,0,ve,E.width,E.height,0,fe,Oe,null)}}else V(E.depthTexture,0);const le=j.__webglTexture,ue=xi(E),J=$?o.TEXTURE_CUBE_MAP_POSITIVE_X+H:o.TEXTURE_2D,ee=E.depthTexture.format===bo?o.DEPTH_STENCIL_ATTACHMENT:o.DEPTH_ATTACHMENT;if(E.depthTexture.format===Wr)Ui(E)?a.framebufferTexture2DMultisampleEXT(o.FRAMEBUFFER,ee,J,le,0,ue):o.framebufferTexture2D(o.FRAMEBUFFER,ee,J,le,0);else if(E.depthTexture.format===bo)Ui(E)?a.framebufferTexture2DMultisampleEXT(o.FRAMEBUFFER,ee,J,le,0,ue):o.framebufferTexture2D(o.FRAMEBUFFER,ee,J,le,0);else throw new Error("THREE.WebGLTextures: Unknown depthTexture format.")}function We(C){const E=i.get(C),H=C.isWebGLCubeRenderTarget===!0;if(E.__boundDepthTexture!==C.depthTexture){const $=C.depthTexture;if(E.__depthDisposeCallback&&E.__depthDisposeCallback(),$){const j=()=>{delete E.__boundDepthTexture,delete E.__depthDisposeCallback,$.removeEventListener("dispose",j)};$.addEventListener("dispose",j),E.__depthDisposeCallback=j}E.__boundDepthTexture=$}if(C.depthTexture&&!E.__autoAllocateDepthBuffer)if(H)for(let $=0;$<6;$++)Ae(E.__webglFramebuffer[$],C,$);else{const $=C.texture.mipmaps;$&&$.length>0?Ae(E.__webglFramebuffer[0],C,0):Ae(E.__webglFramebuffer,C,0)}else if(H){E.__webglDepthbuffer=[];for(let $=0;$<6;$++)if(t.bindFramebuffer(o.FRAMEBUFFER,E.__webglFramebuffer[$]),E.__webglDepthbuffer[$]===void 0)E.__webglDepthbuffer[$]=o.createRenderbuffer(),Le(E.__webglDepthbuffer[$],C,!1);else{const j=C.stencilBuffer?o.DEPTH_STENCIL_ATTACHMENT:o.DEPTH_ATTACHMENT,le=E.__webglDepthbuffer[$];o.bindRenderbuffer(o.RENDERBUFFER,le),o.framebufferRenderbuffer(o.FRAMEBUFFER,j,o.RENDERBUFFER,le)}}else{const $=C.texture.mipmaps;if($&&$.length>0?t.bindFramebuffer(o.FRAMEBUFFER,E.__webglFramebuffer[0]):t.bindFramebuffer(o.FRAMEBUFFER,E.__webglFramebuffer),E.__webglDepthbuffer===void 0)E.__webglDepthbuffer=o.createRenderbuffer(),Le(E.__webglDepthbuffer,C,!1);else{const j=C.stencilBuffer?o.DEPTH_STENCIL_ATTACHMENT:o.DEPTH_ATTACHMENT,le=E.__webglDepthbuffer;o.bindRenderbuffer(o.RENDERBUFFER,le),o.framebufferRenderbuffer(o.FRAMEBUFFER,j,o.RENDERBUFFER,le)}}t.bindFramebuffer(o.FRAMEBUFFER,null)}function Xe(C,E,H){const $=i.get(C);E!==void 0&&ze($.__webglFramebuffer,C,C.texture,o.COLOR_ATTACHMENT0,o.TEXTURE_2D,0),H!==void 0&&We(C)}function $e(C){const E=C.texture,H=i.get(C),$=i.get(E);C.addEventListener("dispose",M);const j=C.textures,le=C.isWebGLCubeRenderTarget===!0,ue=j.length>1;if(ue||($.__webglTexture===void 0&&($.__webglTexture=o.createTexture()),$.__version=E.version,r.memory.textures++),le){H.__webglFramebuffer=[];for(let J=0;J<6;J++)if(E.mipmaps&&E.mipmaps.length>0){H.__webglFramebuffer[J]=[];for(let ee=0;ee<E.mipmaps.length;ee++)H.__webglFramebuffer[J][ee]=o.createFramebuffer()}else H.__webglFramebuffer[J]=o.createFramebuffer()}else{if(E.mipmaps&&E.mipmaps.length>0){H.__webglFramebuffer=[];for(let J=0;J<E.mipmaps.length;J++)H.__webglFramebuffer[J]=o.createFramebuffer()}else H.__webglFramebuffer=o.createFramebuffer();if(ue)for(let J=0,ee=j.length;J<ee;J++){const fe=i.get(j[J]);fe.__webglTexture===void 0&&(fe.__webglTexture=o.createTexture(),r.memory.textures++)}if(C.samples>0&&Ui(C)===!1){H.__webglMultisampledFramebuffer=o.createFramebuffer(),H.__webglColorRenderbuffer=[],t.bindFramebuffer(o.FRAMEBUFFER,H.__webglMultisampledFramebuffer);for(let J=0;J<j.length;J++){const ee=j[J];H.__webglColorRenderbuffer[J]=o.createRenderbuffer(),o.bindRenderbuffer(o.RENDERBUFFER,H.__webglColorRenderbuffer[J]);const fe=s.convert(ee.format,ee.colorSpace),Oe=s.convert(ee.type),ve=y(ee.internalFormat,fe,Oe,ee.normalized,ee.colorSpace,C.isXRRenderTarget===!0),pe=xi(C);o.renderbufferStorageMultisample(o.RENDERBUFFER,pe,ve,C.width,C.height),o.framebufferRenderbuffer(o.FRAMEBUFFER,o.COLOR_ATTACHMENT0+J,o.RENDERBUFFER,H.__webglColorRenderbuffer[J])}o.bindRenderbuffer(o.RENDERBUFFER,null),C.depthBuffer&&(H.__webglDepthRenderbuffer=o.createRenderbuffer(),Le(H.__webglDepthRenderbuffer,C,!0)),t.bindFramebuffer(o.FRAMEBUFFER,null)}}if(le){t.bindTexture(o.TEXTURE_CUBE_MAP,$.__webglTexture),it(o.TEXTURE_CUBE_MAP,E);for(let J=0;J<6;J++)if(E.mipmaps&&E.mipmaps.length>0)for(let ee=0;ee<E.mipmaps.length;ee++)ze(H.__webglFramebuffer[J][ee],C,E,o.COLOR_ATTACHMENT0,o.TEXTURE_CUBE_MAP_POSITIVE_X+J,ee);else ze(H.__webglFramebuffer[J],C,E,o.COLOR_ATTACHMENT0,o.TEXTURE_CUBE_MAP_POSITIVE_X+J,0);v(E)&&b(o.TEXTURE_CUBE_MAP),t.unbindTexture()}else if(ue){for(let J=0,ee=j.length;J<ee;J++){const fe=j[J],Oe=i.get(fe);let ve=o.TEXTURE_2D;(C.isWebGL3DRenderTarget||C.isWebGLArrayRenderTarget)&&(ve=C.isWebGL3DRenderTarget?o.TEXTURE_3D:o.TEXTURE_2D_ARRAY),t.bindTexture(ve,Oe.__webglTexture),it(ve,fe),ze(H.__webglFramebuffer,C,fe,o.COLOR_ATTACHMENT0+J,ve,0),v(fe)&&b(ve)}t.unbindTexture()}else{let J=o.TEXTURE_2D;if((C.isWebGL3DRenderTarget||C.isWebGLArrayRenderTarget)&&(J=C.isWebGL3DRenderTarget?o.TEXTURE_3D:o.TEXTURE_2D_ARRAY),t.bindTexture(J,$.__webglTexture),it(J,E),E.mipmaps&&E.mipmaps.length>0)for(let ee=0;ee<E.mipmaps.length;ee++)ze(H.__webglFramebuffer[ee],C,E,o.COLOR_ATTACHMENT0,J,ee);else ze(H.__webglFramebuffer,C,E,o.COLOR_ATTACHMENT0,J,0);v(E)&&b(J),t.unbindTexture()}C.depthBuffer&&We(C)}function zt(C){const E=C.textures;for(let H=0,$=E.length;H<$;H++){const j=E[H];if(v(j)){const le=x(C),ue=i.get(j).__webglTexture;t.bindTexture(le,ue),b(le),t.unbindTexture()}}}const Ht=[],wi=[];function pi(C){if(C.samples>0){if(Ui(C)===!1){const E=C.textures,H=C.width,$=C.height;let j=o.COLOR_BUFFER_BIT;const le=C.stencilBuffer?o.DEPTH_STENCIL_ATTACHMENT:o.DEPTH_ATTACHMENT,ue=i.get(C),J=E.length>1;if(J)for(let fe=0;fe<E.length;fe++)t.bindFramebuffer(o.FRAMEBUFFER,ue.__webglMultisampledFramebuffer),o.framebufferRenderbuffer(o.FRAMEBUFFER,o.COLOR_ATTACHMENT0+fe,o.RENDERBUFFER,null),t.bindFramebuffer(o.FRAMEBUFFER,ue.__webglFramebuffer),o.framebufferTexture2D(o.DRAW_FRAMEBUFFER,o.COLOR_ATTACHMENT0+fe,o.TEXTURE_2D,null,0);t.bindFramebuffer(o.READ_FRAMEBUFFER,ue.__webglMultisampledFramebuffer);const ee=C.texture.mipmaps;ee&&ee.length>0?t.bindFramebuffer(o.DRAW_FRAMEBUFFER,ue.__webglFramebuffer[0]):t.bindFramebuffer(o.DRAW_FRAMEBUFFER,ue.__webglFramebuffer);for(let fe=0;fe<E.length;fe++){if(C.resolveDepthBuffer&&(C.depthBuffer&&(j|=o.DEPTH_BUFFER_BIT),C.stencilBuffer&&C.resolveStencilBuffer&&(j|=o.STENCIL_BUFFER_BIT)),J){o.framebufferRenderbuffer(o.READ_FRAMEBUFFER,o.COLOR_ATTACHMENT0,o.RENDERBUFFER,ue.__webglColorRenderbuffer[fe]);const Oe=i.get(E[fe]).__webglTexture;o.framebufferTexture2D(o.DRAW_FRAMEBUFFER,o.COLOR_ATTACHMENT0,o.TEXTURE_2D,Oe,0)}o.blitFramebuffer(0,0,H,$,0,0,H,$,j,o.NEAREST),l===!0&&(Ht.length=0,wi.length=0,Ht.push(o.COLOR_ATTACHMENT0+fe),C.depthBuffer&&C.resolveDepthBuffer===!1&&(Ht.push(le),wi.push(le),o.invalidateFramebuffer(o.DRAW_FRAMEBUFFER,wi)),o.invalidateFramebuffer(o.READ_FRAMEBUFFER,Ht))}if(t.bindFramebuffer(o.READ_FRAMEBUFFER,null),t.bindFramebuffer(o.DRAW_FRAMEBUFFER,null),J)for(let fe=0;fe<E.length;fe++){t.bindFramebuffer(o.FRAMEBUFFER,ue.__webglMultisampledFramebuffer),o.framebufferRenderbuffer(o.FRAMEBUFFER,o.COLOR_ATTACHMENT0+fe,o.RENDERBUFFER,ue.__webglColorRenderbuffer[fe]);const Oe=i.get(E[fe]).__webglTexture;t.bindFramebuffer(o.FRAMEBUFFER,ue.__webglFramebuffer),o.framebufferTexture2D(o.DRAW_FRAMEBUFFER,o.COLOR_ATTACHMENT0+fe,o.TEXTURE_2D,Oe,0)}t.bindFramebuffer(o.DRAW_FRAMEBUFFER,ue.__webglMultisampledFramebuffer)}else if(C.depthBuffer&&C.resolveDepthBuffer===!1&&l){const E=C.stencilBuffer?o.DEPTH_STENCIL_ATTACHMENT:o.DEPTH_ATTACHMENT;o.invalidateFramebuffer(o.DRAW_FRAMEBUFFER,[E])}}}function xi(C){return Math.min(n.maxSamples,C.samples)}function Ui(C){const E=i.get(C);return C.samples>0&&e.has("WEBGL_multisampled_render_to_texture")===!0&&E.__useRenderToTexture!==!1}function U(C){const E=r.render.frame;h.get(C)!==E&&(h.set(C,E),C.update())}function Vn(C,E){const H=C.colorSpace,$=C.format,j=C.type;return C.isCompressedTexture===!0||C.isVideoTexture===!0||H!==Gu&&H!==ba&&(Tt.getTransfer(H)===Yt?($!==Vi||j!==zn)&&ke("WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType."):je("WebGLTextures: Unsupported texture color space:",H)),E}function Gt(C){return typeof HTMLImageElement<"u"&&C instanceof HTMLImageElement?(c.width=C.naturalWidth||C.width,c.height=C.naturalHeight||C.height):typeof VideoFrame<"u"&&C instanceof VideoFrame?(c.width=C.displayWidth,c.height=C.displayHeight):(c.width=C.width,c.height=C.height),c}this.allocateTextureUnit=F,this.resetTextureUnits=P,this.getTextureUnits=O,this.setTextureUnits=k,this.setTexture2D=V,this.setTexture2DArray=K,this.setTexture3D=q,this.setTextureCube=te,this.rebindTextures=Xe,this.setupRenderTarget=$e,this.updateRenderTargetMipmap=zt,this.updateMultisampleRenderTarget=pi,this.setupDepthRenderbuffer=We,this.setupFrameBufferTexture=ze,this.useMultisampledRTT=Ui,this.isReversedDepthBuffer=function(){return t.buffers.depth.getReversed()}}function lD(o,e){function t(i,n=ba){let s;const r=Tt.getTransfer(n);if(i===zn)return o.UNSIGNED_BYTE;if(i===cg)return o.UNSIGNED_SHORT_4_4_4_4;if(i===hg)return o.UNSIGNED_SHORT_5_5_5_1;if(i===tw)return o.UNSIGNED_INT_5_9_9_9_REV;if(i===iw)return o.UNSIGNED_INT_10F_11F_11F_REV;if(i===QM)return o.BYTE;if(i===ew)return o.SHORT;if(i===Mh)return o.UNSIGNED_SHORT;if(i===lg)return o.INT;if(i===Ts)return o.UNSIGNED_INT;if(i===En)return o.FLOAT;if(i===ci)return o.HALF_FLOAT;if(i===nw)return o.ALPHA;if(i===sw)return o.RGB;if(i===Vi)return o.RGBA;if(i===Wr)return o.DEPTH_COMPONENT;if(i===bo)return o.DEPTH_STENCIL;if(i===ac)return o.RED;if(i===dg)return o.RED_INTEGER;if(i===Fo)return o.RG;if(i===ug)return o.RG_INTEGER;if(i===fg)return o.RGBA_INTEGER;if(i===Zd||i===jd||i===Jd||i===Qd)if(r===Yt)if(s=e.get("WEBGL_compressed_texture_s3tc_srgb"),s!==null){if(i===Zd)return s.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(i===jd)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(i===Jd)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(i===Qd)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else return null;else if(s=e.get("WEBGL_compressed_texture_s3tc"),s!==null){if(i===Zd)return s.COMPRESSED_RGB_S3TC_DXT1_EXT;if(i===jd)return s.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(i===Jd)return s.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(i===Qd)return s.COMPRESSED_RGBA_S3TC_DXT5_EXT}else return null;if(i===L0||i===O0||i===N0||i===F0)if(s=e.get("WEBGL_compressed_texture_pvrtc"),s!==null){if(i===L0)return s.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(i===O0)return s.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(i===N0)return s.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(i===F0)return s.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}else return null;if(i===U0||i===B0||i===z0||i===H0||i===G0||i===Fu||i===V0)if(s=e.get("WEBGL_compressed_texture_etc"),s!==null){if(i===U0||i===B0)return r===Yt?s.COMPRESSED_SRGB8_ETC2:s.COMPRESSED_RGB8_ETC2;if(i===z0)return r===Yt?s.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:s.COMPRESSED_RGBA8_ETC2_EAC;if(i===H0)return s.COMPRESSED_R11_EAC;if(i===G0)return s.COMPRESSED_SIGNED_R11_EAC;if(i===Fu)return s.COMPRESSED_RG11_EAC;if(i===V0)return s.COMPRESSED_SIGNED_RG11_EAC}else return null;if(i===W0||i===X0||i===$0||i===Y0||i===q0||i===K0||i===Z0||i===j0||i===J0||i===Q0||i===em||i===tm||i===im||i===nm)if(s=e.get("WEBGL_compressed_texture_astc"),s!==null){if(i===W0)return r===Yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:s.COMPRESSED_RGBA_ASTC_4x4_KHR;if(i===X0)return r===Yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:s.COMPRESSED_RGBA_ASTC_5x4_KHR;if(i===$0)return r===Yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:s.COMPRESSED_RGBA_ASTC_5x5_KHR;if(i===Y0)return r===Yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:s.COMPRESSED_RGBA_ASTC_6x5_KHR;if(i===q0)return r===Yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:s.COMPRESSED_RGBA_ASTC_6x6_KHR;if(i===K0)return r===Yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:s.COMPRESSED_RGBA_ASTC_8x5_KHR;if(i===Z0)return r===Yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:s.COMPRESSED_RGBA_ASTC_8x6_KHR;if(i===j0)return r===Yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:s.COMPRESSED_RGBA_ASTC_8x8_KHR;if(i===J0)return r===Yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:s.COMPRESSED_RGBA_ASTC_10x5_KHR;if(i===Q0)return r===Yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:s.COMPRESSED_RGBA_ASTC_10x6_KHR;if(i===em)return r===Yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:s.COMPRESSED_RGBA_ASTC_10x8_KHR;if(i===tm)return r===Yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:s.COMPRESSED_RGBA_ASTC_10x10_KHR;if(i===im)return r===Yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:s.COMPRESSED_RGBA_ASTC_12x10_KHR;if(i===nm)return r===Yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:s.COMPRESSED_RGBA_ASTC_12x12_KHR}else return null;if(i===sm||i===rm||i===am)if(s=e.get("EXT_texture_compression_bptc"),s!==null){if(i===sm)return r===Yt?s.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:s.COMPRESSED_RGBA_BPTC_UNORM_EXT;if(i===rm)return s.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT;if(i===am)return s.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT}else return null;if(i===om||i===lm||i===Uu||i===cm)if(s=e.get("EXT_texture_compression_rgtc"),s!==null){if(i===om)return s.COMPRESSED_RED_RGTC1_EXT;if(i===lm)return s.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(i===Uu)return s.COMPRESSED_RED_GREEN_RGTC2_EXT;if(i===cm)return s.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}else return null;return i===wh?o.UNSIGNED_INT_24_8:o[i]!==void 0?o[i]:null}return{convert:t}}const cD=`
7247
7247
  void main() {
7248
7248
 
7249
7249
  gl_Position = vec4( position, 1.0 );
@@ -7267,7 +7267,7 @@ void main() {
7267
7267
 
7268
7268
  }
7269
7269
 
7270
- }`;class dD{constructor(){this.texture=null,this.mesh=null,this.depthNear=0,this.depthFar=0}init(e,t){if(this.texture===null){const i=new gw(e.texture);(e.depthNear!==t.depthNear||e.depthFar!==t.depthFar)&&(this.depthNear=e.depthNear,this.depthFar=e.depthFar),this.texture=i}}getMesh(e){if(this.texture!==null&&this.mesh===null){const t=e.cameras[0].viewport,i=new Dt({vertexShader:cD,fragmentShader:hD,uniforms:{depthColor:{value:this.texture},depthWidth:{value:t.z},depthHeight:{value:t.w}}});this.mesh=new Se(new Gn(20,20),i)}return this.mesh}reset(){this.texture=null,this.mesh=null}getDepthTexture(){return this.texture}}class uD extends Na{constructor(e,t){super();const i=this;let n=null,s=1,r=null,a="local-floor",l=1,c=null,h=null,d=null,u=null,f=null,p=null;const g=typeof XRWebGLBinding<"u",m=new dD,v={},b=t.getContextAttributes();let x=null,y=null;const w=[],S=[],A=new we;let M=null;const _=new Qn;_.viewport=new wt;const I=new Qn;I.viewport=new wt;const R=[_,I],L=new oA;let P=null,O=null;this.cameraAutoUpdate=!0,this.enabled=!1,this.isPresenting=!1,this.getController=function(Z){let ae=w[Z];return ae===void 0&&(ae=new Jf,w[Z]=ae),ae.getTargetRaySpace()},this.getControllerGrip=function(Z){let ae=w[Z];return ae===void 0&&(ae=new Jf,w[Z]=ae),ae.getGripSpace()},this.getHand=function(Z){let ae=w[Z];return ae===void 0&&(ae=new Jf,w[Z]=ae),ae.getHandSpace()};function k(Z){const ae=S.indexOf(Z.inputSource);if(ae===-1)return;const se=w[ae];se!==void 0&&(se.update(Z.inputSource,Z.frame,c||r),se.dispatchEvent({type:Z.type,data:Z.inputSource}))}function F(){n.removeEventListener("select",k),n.removeEventListener("selectstart",k),n.removeEventListener("selectend",k),n.removeEventListener("squeeze",k),n.removeEventListener("squeezestart",k),n.removeEventListener("squeezeend",k),n.removeEventListener("end",F),n.removeEventListener("inputsourceschange",z);for(let Z=0;Z<w.length;Z++){const ae=S[Z];ae!==null&&(S[Z]=null,w[Z].disconnect(ae))}P=null,O=null,m.reset();for(const Z in v)delete v[Z];e.setRenderTarget(x),f=null,u=null,d=null,n=null,y=null,it.stop(),i.isPresenting=!1,e.setPixelRatio(M),e.setSize(A.width,A.height,!1),i.dispatchEvent({type:"sessionend"})}this.setFramebufferScaleFactor=function(Z){s=Z,i.isPresenting===!0&&ke("WebXRManager: Cannot change framebuffer scale while presenting.")},this.setReferenceSpaceType=function(Z){a=Z,i.isPresenting===!0&&ke("WebXRManager: Cannot change reference space type while presenting.")},this.getReferenceSpace=function(){return c||r},this.setReferenceSpace=function(Z){c=Z},this.getBaseLayer=function(){return u!==null?u:f},this.getBinding=function(){return d===null&&g&&(d=new XRWebGLBinding(n,t)),d},this.getFrame=function(){return p},this.getSession=function(){return n},this.setSession=async function(Z){if(n=Z,n!==null){if(x=e.getRenderTarget(),n.addEventListener("select",k),n.addEventListener("selectstart",k),n.addEventListener("selectend",k),n.addEventListener("squeeze",k),n.addEventListener("squeezestart",k),n.addEventListener("squeezeend",k),n.addEventListener("end",F),n.addEventListener("inputsourceschange",z),b.xrCompatible!==!0&&await t.makeXRCompatible(),M=e.getPixelRatio(),e.getSize(A),g&&"createProjectionLayer"in XRWebGLBinding.prototype){let se=null,G=null,Re=null;b.depth&&(Re=b.stencil?t.DEPTH24_STENCIL8:t.DEPTH_COMPONENT24,se=b.stencil?bo:Wr,G=b.stencil?wh:Ts);const ze={colorFormat:t.RGBA8,depthFormat:Re,scaleFactor:s};d=this.getBinding(),u=d.createProjectionLayer(ze),n.updateRenderState({layers:[u]}),e.setPixelRatio(1),e.setSize(u.textureWidth,u.textureHeight,!1),y=new Mi(u.textureWidth,u.textureHeight,{format:Vi,type:zn,depthTexture:new La(u.textureWidth,u.textureHeight,G,void 0,void 0,void 0,void 0,void 0,void 0,se),stencilBuffer:b.stencil,colorSpace:e.outputColorSpace,samples:b.antialias?4:0,resolveDepthBuffer:u.ignoreDepthValues===!1,resolveStencilBuffer:u.ignoreDepthValues===!1})}else{const se={antialias:b.antialias,alpha:!0,depth:b.depth,stencil:b.stencil,framebufferScaleFactor:s};f=new XRWebGLLayer(n,t,se),n.updateRenderState({baseLayer:f}),e.setPixelRatio(1),e.setSize(f.framebufferWidth,f.framebufferHeight,!1),y=new Mi(f.framebufferWidth,f.framebufferHeight,{format:Vi,type:zn,colorSpace:e.outputColorSpace,stencilBuffer:b.stencil,resolveDepthBuffer:f.ignoreDepthValues===!1,resolveStencilBuffer:f.ignoreDepthValues===!1})}y.isXRRenderTarget=!0,this.setFoveation(l),c=null,r=await n.requestReferenceSpace(a),it.setContext(n),it.start(),i.isPresenting=!0,i.dispatchEvent({type:"sessionstart"})}},this.getEnvironmentBlendMode=function(){if(n!==null)return n.environmentBlendMode},this.getDepthTexture=function(){return m.getDepthTexture()};function z(Z){for(let ae=0;ae<Z.removed.length;ae++){const se=Z.removed[ae],G=S.indexOf(se);G>=0&&(S[G]=null,w[G].disconnect(se))}for(let ae=0;ae<Z.added.length;ae++){const se=Z.added[ae];let G=S.indexOf(se);if(G===-1){for(let ze=0;ze<w.length;ze++)if(ze>=S.length){S.push(se),G=ze;break}else if(S[ze]===null){S[ze]=se,G=ze;break}if(G===-1)break}const Re=w[G];Re&&Re.connect(se)}}const V=new D,K=new D;function q(Z,ae,se){V.setFromMatrixPosition(ae.matrixWorld),K.setFromMatrixPosition(se.matrixWorld);const G=V.distanceTo(K),Re=ae.projectionMatrix.elements,ze=se.projectionMatrix.elements,Le=Re[14]/(Re[10]-1),Ae=Re[14]/(Re[10]+1),We=(Re[9]+1)/Re[5],Xe=(Re[9]-1)/Re[5],$e=(Re[8]-1)/Re[0],zt=(ze[8]+1)/ze[0],Ht=Le*$e,wi=Le*zt,pi=G/(-$e+zt),xi=pi*-$e;if(ae.matrixWorld.decompose(Z.position,Z.quaternion,Z.scale),Z.translateX(xi),Z.translateZ(pi),Z.matrixWorld.compose(Z.position,Z.quaternion,Z.scale),Z.matrixWorldInverse.copy(Z.matrixWorld).invert(),Re[10]===-1)Z.projectionMatrix.copy(ae.projectionMatrix),Z.projectionMatrixInverse.copy(ae.projectionMatrixInverse);else{const Ui=Le+pi,U=Ae+pi,Vn=Ht-xi,Gt=wi+(G-xi),C=We*Ae/U*Ui,E=Xe*Ae/U*Ui;Z.projectionMatrix.makePerspective(Vn,Gt,C,E,Ui,U),Z.projectionMatrixInverse.copy(Z.projectionMatrix).invert()}}function te(Z,ae){ae===null?Z.matrixWorld.copy(Z.matrix):Z.matrixWorld.multiplyMatrices(ae.matrixWorld,Z.matrix),Z.matrixWorldInverse.copy(Z.matrixWorld).invert()}this.updateCamera=function(Z){if(n===null)return;let ae=Z.near,se=Z.far;m.texture!==null&&(m.depthNear>0&&(ae=m.depthNear),m.depthFar>0&&(se=m.depthFar)),L.near=I.near=_.near=ae,L.far=I.far=_.far=se,(P!==L.near||O!==L.far)&&(n.updateRenderState({depthNear:L.near,depthFar:L.far}),P=L.near,O=L.far),L.layers.mask=Z.layers.mask|6,_.layers.mask=L.layers.mask&-5,I.layers.mask=L.layers.mask&-3;const G=Z.parent,Re=L.cameras;te(L,G);for(let ze=0;ze<Re.length;ze++)te(Re[ze],G);Re.length===2?q(L,_,I):L.projectionMatrix.copy(_.projectionMatrix),re(Z,L,G)};function re(Z,ae,se){se===null?Z.matrix.copy(ae.matrixWorld):(Z.matrix.copy(se.matrixWorld),Z.matrix.invert(),Z.matrix.multiply(ae.matrixWorld)),Z.matrix.decompose(Z.position,Z.quaternion,Z.scale),Z.updateMatrixWorld(!0),Z.projectionMatrix.copy(ae.projectionMatrix),Z.projectionMatrixInverse.copy(ae.projectionMatrixInverse),Z.isPerspectiveCamera&&(Z.fov=oc*2*Math.atan(1/Z.projectionMatrix.elements[5]),Z.zoom=1)}this.getCamera=function(){return L},this.getFoveation=function(){if(!(u===null&&f===null))return l},this.setFoveation=function(Z){l=Z,u!==null&&(u.fixedFoveation=Z),f!==null&&f.fixedFoveation!==void 0&&(f.fixedFoveation=Z)},this.hasDepthSensing=function(){return m.texture!==null},this.getDepthSensingMesh=function(){return m.getMesh(L)},this.getCameraTexture=function(Z){return v[Z]};let Ge=null;function ft(Z,ae){if(h=ae.getViewerPose(c||r),p=ae,h!==null){const se=h.views;f!==null&&(e.setRenderTargetFramebuffer(y,f.framebuffer),e.setRenderTarget(y));let G=!1;se.length!==L.cameras.length&&(L.cameras.length=0,G=!0);for(let Ae=0;Ae<se.length;Ae++){const We=se[Ae];let Xe=null;if(f!==null)Xe=f.getViewport(We);else{const zt=d.getViewSubImage(u,We);Xe=zt.viewport,Ae===0&&(e.setRenderTargetTextures(y,zt.colorTexture,zt.depthStencilTexture),e.setRenderTarget(y))}let $e=R[Ae];$e===void 0&&($e=new Qn,$e.layers.enable(Ae),$e.viewport=new wt,R[Ae]=$e),$e.matrix.fromArray(We.transform.matrix),$e.matrix.decompose($e.position,$e.quaternion,$e.scale),$e.projectionMatrix.fromArray(We.projectionMatrix),$e.projectionMatrixInverse.copy($e.projectionMatrix).invert(),$e.viewport.set(Xe.x,Xe.y,Xe.width,Xe.height),Ae===0&&(L.matrix.copy($e.matrix),L.matrix.decompose(L.position,L.quaternion,L.scale)),G===!0&&L.cameras.push($e)}const Re=n.enabledFeatures;if(Re&&Re.includes("depth-sensing")&&n.depthUsage=="gpu-optimized"&&g){d=i.getBinding();const Ae=d.getDepthInformation(se[0]);Ae&&Ae.isValid&&Ae.texture&&m.init(Ae,n.renderState)}if(Re&&Re.includes("camera-access")&&g){e.state.unbindTexture(),d=i.getBinding();for(let Ae=0;Ae<se.length;Ae++){const We=se[Ae].camera;if(We){let Xe=v[We];Xe||(Xe=new gw,v[We]=Xe);const $e=d.getCameraImage(We);Xe.sourceTexture=$e}}}}for(let se=0;se<w.length;se++){const G=S[se],Re=w[se];G!==null&&Re!==void 0&&Re.update(G,ae,c||r)}Ge&&Ge(Z,ae),ae.detectedPlanes&&i.dispatchEvent({type:"planesdetected",data:ae}),p=null}const it=new Aw;it.setAnimationLoop(ft),this.setAnimationLoop=function(Z){Ge=Z},this.dispose=function(){}}}const fD=new lt,Cw=new je;Cw.set(-1,0,0,0,1,0,0,0,1);function pD(o,e){function t(m,v){m.matrixAutoUpdate===!0&&m.updateMatrix(),v.value.copy(m.matrix)}function i(m,v){v.color.getRGB(m.fogColor.value,vw(o)),v.isFog?(m.fogNear.value=v.near,m.fogFar.value=v.far):v.isFogExp2&&(m.fogDensity.value=v.density)}function n(m,v,b,x,y){v.isNodeMaterial?v.uniformsNeedUpdate=!1:v.isMeshBasicMaterial?s(m,v):v.isMeshLambertMaterial?(s(m,v),v.envMap&&(m.envMapIntensity.value=v.envMapIntensity)):v.isMeshToonMaterial?(s(m,v),d(m,v)):v.isMeshPhongMaterial?(s(m,v),h(m,v),v.envMap&&(m.envMapIntensity.value=v.envMapIntensity)):v.isMeshStandardMaterial?(s(m,v),u(m,v),v.isMeshPhysicalMaterial&&f(m,v,y)):v.isMeshMatcapMaterial?(s(m,v),p(m,v)):v.isMeshDepthMaterial?s(m,v):v.isMeshDistanceMaterial?(s(m,v),g(m,v)):v.isMeshNormalMaterial?s(m,v):v.isLineBasicMaterial?(r(m,v),v.isLineDashedMaterial&&a(m,v)):v.isPointsMaterial?l(m,v,b,x):v.isSpriteMaterial?c(m,v):v.isShadowMaterial?(m.color.value.copy(v.color),m.opacity.value=v.opacity):v.isShaderMaterial&&(v.uniformsNeedUpdate=!1)}function s(m,v){m.opacity.value=v.opacity,v.color&&m.diffuse.value.copy(v.color),v.emissive&&m.emissive.value.copy(v.emissive).multiplyScalar(v.emissiveIntensity),v.map&&(m.map.value=v.map,t(v.map,m.mapTransform)),v.alphaMap&&(m.alphaMap.value=v.alphaMap,t(v.alphaMap,m.alphaMapTransform)),v.bumpMap&&(m.bumpMap.value=v.bumpMap,t(v.bumpMap,m.bumpMapTransform),m.bumpScale.value=v.bumpScale,v.side===fi&&(m.bumpScale.value*=-1)),v.normalMap&&(m.normalMap.value=v.normalMap,t(v.normalMap,m.normalMapTransform),m.normalScale.value.copy(v.normalScale),v.side===fi&&m.normalScale.value.negate()),v.displacementMap&&(m.displacementMap.value=v.displacementMap,t(v.displacementMap,m.displacementMapTransform),m.displacementScale.value=v.displacementScale,m.displacementBias.value=v.displacementBias),v.emissiveMap&&(m.emissiveMap.value=v.emissiveMap,t(v.emissiveMap,m.emissiveMapTransform)),v.specularMap&&(m.specularMap.value=v.specularMap,t(v.specularMap,m.specularMapTransform)),v.alphaTest>0&&(m.alphaTest.value=v.alphaTest);const b=e.get(v),x=b.envMap,y=b.envMapRotation;x&&(m.envMap.value=x,m.envMapRotation.value.setFromMatrix4(fD.makeRotationFromEuler(y)).transpose(),x.isCubeTexture&&x.isRenderTargetTexture===!1&&m.envMapRotation.value.premultiply(Cw),m.reflectivity.value=v.reflectivity,m.ior.value=v.ior,m.refractionRatio.value=v.refractionRatio),v.lightMap&&(m.lightMap.value=v.lightMap,m.lightMapIntensity.value=v.lightMapIntensity,t(v.lightMap,m.lightMapTransform)),v.aoMap&&(m.aoMap.value=v.aoMap,m.aoMapIntensity.value=v.aoMapIntensity,t(v.aoMap,m.aoMapTransform))}function r(m,v){m.diffuse.value.copy(v.color),m.opacity.value=v.opacity,v.map&&(m.map.value=v.map,t(v.map,m.mapTransform))}function a(m,v){m.dashSize.value=v.dashSize,m.totalSize.value=v.dashSize+v.gapSize,m.scale.value=v.scale}function l(m,v,b,x){m.diffuse.value.copy(v.color),m.opacity.value=v.opacity,m.size.value=v.size*b,m.scale.value=x*.5,v.map&&(m.map.value=v.map,t(v.map,m.uvTransform)),v.alphaMap&&(m.alphaMap.value=v.alphaMap,t(v.alphaMap,m.alphaMapTransform)),v.alphaTest>0&&(m.alphaTest.value=v.alphaTest)}function c(m,v){m.diffuse.value.copy(v.color),m.opacity.value=v.opacity,m.rotation.value=v.rotation,v.map&&(m.map.value=v.map,t(v.map,m.mapTransform)),v.alphaMap&&(m.alphaMap.value=v.alphaMap,t(v.alphaMap,m.alphaMapTransform)),v.alphaTest>0&&(m.alphaTest.value=v.alphaTest)}function h(m,v){m.specular.value.copy(v.specular),m.shininess.value=Math.max(v.shininess,1e-4)}function d(m,v){v.gradientMap&&(m.gradientMap.value=v.gradientMap)}function u(m,v){m.metalness.value=v.metalness,v.metalnessMap&&(m.metalnessMap.value=v.metalnessMap,t(v.metalnessMap,m.metalnessMapTransform)),m.roughness.value=v.roughness,v.roughnessMap&&(m.roughnessMap.value=v.roughnessMap,t(v.roughnessMap,m.roughnessMapTransform)),v.envMap&&(m.envMapIntensity.value=v.envMapIntensity)}function f(m,v,b){m.ior.value=v.ior,v.sheen>0&&(m.sheenColor.value.copy(v.sheenColor).multiplyScalar(v.sheen),m.sheenRoughness.value=v.sheenRoughness,v.sheenColorMap&&(m.sheenColorMap.value=v.sheenColorMap,t(v.sheenColorMap,m.sheenColorMapTransform)),v.sheenRoughnessMap&&(m.sheenRoughnessMap.value=v.sheenRoughnessMap,t(v.sheenRoughnessMap,m.sheenRoughnessMapTransform))),v.clearcoat>0&&(m.clearcoat.value=v.clearcoat,m.clearcoatRoughness.value=v.clearcoatRoughness,v.clearcoatMap&&(m.clearcoatMap.value=v.clearcoatMap,t(v.clearcoatMap,m.clearcoatMapTransform)),v.clearcoatRoughnessMap&&(m.clearcoatRoughnessMap.value=v.clearcoatRoughnessMap,t(v.clearcoatRoughnessMap,m.clearcoatRoughnessMapTransform)),v.clearcoatNormalMap&&(m.clearcoatNormalMap.value=v.clearcoatNormalMap,t(v.clearcoatNormalMap,m.clearcoatNormalMapTransform),m.clearcoatNormalScale.value.copy(v.clearcoatNormalScale),v.side===fi&&m.clearcoatNormalScale.value.negate())),v.dispersion>0&&(m.dispersion.value=v.dispersion),v.iridescence>0&&(m.iridescence.value=v.iridescence,m.iridescenceIOR.value=v.iridescenceIOR,m.iridescenceThicknessMinimum.value=v.iridescenceThicknessRange[0],m.iridescenceThicknessMaximum.value=v.iridescenceThicknessRange[1],v.iridescenceMap&&(m.iridescenceMap.value=v.iridescenceMap,t(v.iridescenceMap,m.iridescenceMapTransform)),v.iridescenceThicknessMap&&(m.iridescenceThicknessMap.value=v.iridescenceThicknessMap,t(v.iridescenceThicknessMap,m.iridescenceThicknessMapTransform))),v.transmission>0&&(m.transmission.value=v.transmission,m.transmissionSamplerMap.value=b.texture,m.transmissionSamplerSize.value.set(b.width,b.height),v.transmissionMap&&(m.transmissionMap.value=v.transmissionMap,t(v.transmissionMap,m.transmissionMapTransform)),m.thickness.value=v.thickness,v.thicknessMap&&(m.thicknessMap.value=v.thicknessMap,t(v.thicknessMap,m.thicknessMapTransform)),m.attenuationDistance.value=v.attenuationDistance,m.attenuationColor.value.copy(v.attenuationColor)),v.anisotropy>0&&(m.anisotropyVector.value.set(v.anisotropy*Math.cos(v.anisotropyRotation),v.anisotropy*Math.sin(v.anisotropyRotation)),v.anisotropyMap&&(m.anisotropyMap.value=v.anisotropyMap,t(v.anisotropyMap,m.anisotropyMapTransform))),m.specularIntensity.value=v.specularIntensity,m.specularColor.value.copy(v.specularColor),v.specularColorMap&&(m.specularColorMap.value=v.specularColorMap,t(v.specularColorMap,m.specularColorMapTransform)),v.specularIntensityMap&&(m.specularIntensityMap.value=v.specularIntensityMap,t(v.specularIntensityMap,m.specularIntensityMapTransform))}function p(m,v){v.matcap&&(m.matcap.value=v.matcap)}function g(m,v){const b=e.get(v).light;m.referencePosition.value.setFromMatrixPosition(b.matrixWorld),m.nearDistance.value=b.shadow.camera.near,m.farDistance.value=b.shadow.camera.far}return{refreshFogUniforms:i,refreshMaterialUniforms:n}}function mD(o,e,t,i){let n={},s={},r=[];const a=o.getParameter(o.MAX_UNIFORM_BUFFER_BINDINGS);function l(y,w){const S=w.program;i.uniformBlockBinding(y,S)}function c(y,w){let S=n[y.id];S===void 0&&(m(y),S=h(y),n[y.id]=S,y.addEventListener("dispose",b));const A=w.program;i.updateUBOMapping(y,A);const M=e.render.frame;s[y.id]!==M&&(u(y),s[y.id]=M)}function h(y){const w=d();y.__bindingPointIndex=w;const S=o.createBuffer(),A=y.__size,M=y.usage;return o.bindBuffer(o.UNIFORM_BUFFER,S),o.bufferData(o.UNIFORM_BUFFER,A,M),o.bindBuffer(o.UNIFORM_BUFFER,null),o.bindBufferBase(o.UNIFORM_BUFFER,w,S),S}function d(){for(let y=0;y<a;y++)if(r.indexOf(y)===-1)return r.push(y),y;return Ze("WebGLRenderer: Maximum number of simultaneously usable uniforms groups reached."),0}function u(y){const w=n[y.id],S=y.uniforms,A=y.__cache;o.bindBuffer(o.UNIFORM_BUFFER,w);for(let M=0,_=S.length;M<_;M++){const I=S[M];if(Array.isArray(I))for(let R=0,L=I.length;R<L;R++)f(I[R],M,R,A);else f(I,M,0,A)}o.bindBuffer(o.UNIFORM_BUFFER,null)}function f(y,w,S,A){if(g(y,w,S,A)===!0){const M=y.__offset,_=y.value;if(Array.isArray(_)){let I=0;for(let R=0;R<_.length;R++){const L=_[R],P=v(L);p(L,y.__data,I),typeof L!="number"&&typeof L!="boolean"&&!L.isMatrix3&&!ArrayBuffer.isView(L)&&(I+=P.storage/Float32Array.BYTES_PER_ELEMENT)}}else p(_,y.__data,0);o.bufferSubData(o.UNIFORM_BUFFER,M,y.__data)}}function p(y,w,S){typeof y=="number"||typeof y=="boolean"?w[0]=y:y.isMatrix3?(w[0]=y.elements[0],w[1]=y.elements[1],w[2]=y.elements[2],w[3]=0,w[4]=y.elements[3],w[5]=y.elements[4],w[6]=y.elements[5],w[7]=0,w[8]=y.elements[6],w[9]=y.elements[7],w[10]=y.elements[8],w[11]=0):ArrayBuffer.isView(y)?w.set(new y.constructor(y.buffer,y.byteOffset,w.length)):y.toArray(w,S)}function g(y,w,S,A){const M=y.value,_=w+"_"+S;if(A[_]===void 0)return typeof M=="number"||typeof M=="boolean"?A[_]=M:ArrayBuffer.isView(M)?A[_]=M.slice():A[_]=M.clone(),!0;{const I=A[_];if(typeof M=="number"||typeof M=="boolean"){if(I!==M)return A[_]=M,!0}else{if(ArrayBuffer.isView(M))return!0;if(I.equals(M)===!1)return I.copy(M),!0}}return!1}function m(y){const w=y.uniforms;let S=0;const A=16;for(let _=0,I=w.length;_<I;_++){const R=Array.isArray(w[_])?w[_]:[w[_]];for(let L=0,P=R.length;L<P;L++){const O=R[L],k=Array.isArray(O.value)?O.value:[O.value];for(let F=0,z=k.length;F<z;F++){const V=k[F],K=v(V),q=S%A,te=q%K.boundary,re=q+te;S+=te,re!==0&&A-re<K.storage&&(S+=A-re),O.__data=new Float32Array(K.storage/Float32Array.BYTES_PER_ELEMENT),O.__offset=S,S+=K.storage}}}const M=S%A;return M>0&&(S+=A-M),y.__size=S,y.__cache={},this}function v(y){const w={boundary:0,storage:0};return typeof y=="number"||typeof y=="boolean"?(w.boundary=4,w.storage=4):y.isVector2?(w.boundary=8,w.storage=8):y.isVector3||y.isColor?(w.boundary=16,w.storage=12):y.isVector4?(w.boundary=16,w.storage=16):y.isMatrix3?(w.boundary=48,w.storage=48):y.isMatrix4?(w.boundary=64,w.storage=64):y.isTexture?ke("WebGLRenderer: Texture samplers can not be part of an uniforms group."):ArrayBuffer.isView(y)?(w.boundary=16,w.storage=y.byteLength):ke("WebGLRenderer: Unsupported uniform value type.",y),w}function b(y){const w=y.target;w.removeEventListener("dispose",b);const S=r.indexOf(w.__bindingPointIndex);r.splice(S,1),o.deleteBuffer(n[w.id]),delete n[w.id],delete s[w.id]}function x(){for(const y in n)o.deleteBuffer(n[y]);r=[],n={},s={}}return{bind:l,update:c,dispose:x}}const gD=new Uint16Array([12469,15057,12620,14925,13266,14620,13807,14376,14323,13990,14545,13625,14713,13328,14840,12882,14931,12528,14996,12233,15039,11829,15066,11525,15080,11295,15085,10976,15082,10705,15073,10495,13880,14564,13898,14542,13977,14430,14158,14124,14393,13732,14556,13410,14702,12996,14814,12596,14891,12291,14937,11834,14957,11489,14958,11194,14943,10803,14921,10506,14893,10278,14858,9960,14484,14039,14487,14025,14499,13941,14524,13740,14574,13468,14654,13106,14743,12678,14818,12344,14867,11893,14889,11509,14893,11180,14881,10751,14852,10428,14812,10128,14765,9754,14712,9466,14764,13480,14764,13475,14766,13440,14766,13347,14769,13070,14786,12713,14816,12387,14844,11957,14860,11549,14868,11215,14855,10751,14825,10403,14782,10044,14729,9651,14666,9352,14599,9029,14967,12835,14966,12831,14963,12804,14954,12723,14936,12564,14917,12347,14900,11958,14886,11569,14878,11247,14859,10765,14828,10401,14784,10011,14727,9600,14660,9289,14586,8893,14508,8533,15111,12234,15110,12234,15104,12216,15092,12156,15067,12010,15028,11776,14981,11500,14942,11205,14902,10752,14861,10393,14812,9991,14752,9570,14682,9252,14603,8808,14519,8445,14431,8145,15209,11449,15208,11451,15202,11451,15190,11438,15163,11384,15117,11274,15055,10979,14994,10648,14932,10343,14871,9936,14803,9532,14729,9218,14645,8742,14556,8381,14461,8020,14365,7603,15273,10603,15272,10607,15267,10619,15256,10631,15231,10614,15182,10535,15118,10389,15042,10167,14963,9787,14883,9447,14800,9115,14710,8665,14615,8318,14514,7911,14411,7507,14279,7198,15314,9675,15313,9683,15309,9712,15298,9759,15277,9797,15229,9773,15166,9668,15084,9487,14995,9274,14898,8910,14800,8539,14697,8234,14590,7790,14479,7409,14367,7067,14178,6621,15337,8619,15337,8631,15333,8677,15325,8769,15305,8871,15264,8940,15202,8909,15119,8775,15022,8565,14916,8328,14804,8009,14688,7614,14569,7287,14448,6888,14321,6483,14088,6171,15350,7402,15350,7419,15347,7480,15340,7613,15322,7804,15287,7973,15229,8057,15148,8012,15046,7846,14933,7611,14810,7357,14682,7069,14552,6656,14421,6316,14251,5948,14007,5528,15356,5942,15356,5977,15353,6119,15348,6294,15332,6551,15302,6824,15249,7044,15171,7122,15070,7050,14949,6861,14818,6611,14679,6349,14538,6067,14398,5651,14189,5311,13935,4958,15359,4123,15359,4153,15356,4296,15353,4646,15338,5160,15311,5508,15263,5829,15188,6042,15088,6094,14966,6001,14826,5796,14678,5543,14527,5287,14377,4985,14133,4586,13869,4257,15360,1563,15360,1642,15358,2076,15354,2636,15341,3350,15317,4019,15273,4429,15203,4732,15105,4911,14981,4932,14836,4818,14679,4621,14517,4386,14359,4156,14083,3795,13808,3437,15360,122,15360,137,15358,285,15355,636,15344,1274,15322,2177,15281,2765,15215,3223,15120,3451,14995,3569,14846,3567,14681,3466,14511,3305,14344,3121,14037,2800,13753,2467,15360,0,15360,1,15359,21,15355,89,15346,253,15325,479,15287,796,15225,1148,15133,1492,15008,1749,14856,1882,14685,1886,14506,1783,14324,1608,13996,1398,13702,1183]);let Qs=null;function vD(){return Qs===null&&(Qs=new ps(gD,16,16,Fo,ci),Qs.name="DFG_LUT",Qs.minFilter=mt,Qs.magFilter=mt,Qs.wrapS=Ti,Qs.wrapT=Ti,Qs.generateMipmaps=!1,Qs.needsUpdate=!0),Qs}class yD{constructor(e={}){const{canvas:t=WE(),context:i=null,depth:n=!0,stencil:s=!1,alpha:r=!1,antialias:a=!1,premultipliedAlpha:l=!0,preserveDrawingBuffer:c=!1,powerPreference:h="default",failIfMajorPerformanceCaveat:d=!1,reversedDepthBuffer:u=!1,outputBufferType:f=zn}=e;this.isWebGLRenderer=!0;let p;if(i!==null){if(typeof WebGLRenderingContext<"u"&&i instanceof WebGLRenderingContext)throw new Error("THREE.WebGLRenderer: WebGL 1 is not supported since r163.");p=i.getContextAttributes().alpha}else p=r;const g=f,m=new Set([fg,ug,dg]),v=new Set([zn,Ts,Mh,wh,cg,hg]),b=new Uint32Array(4),x=new Int32Array(4),y=new D;let w=null,S=null;const A=[],M=[];let _=null;this.domElement=t,this.debug={checkShaderErrors:!0,onShaderError:null},this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.sortObjects=!0,this.clippingPlanes=[],this.localClippingEnabled=!1,this.toneMapping=Mr,this.toneMappingExposure=1,this.transmissionResolutionScale=1;const I=this;let R=!1,L=null,P=null,O=null,k=null;this._outputColorSpace=an;let F=0,z=0,V=null,K=-1,q=null;const te=new wt,re=new wt;let Ge=null;const ft=new ne(0);let it=0,Z=t.width,ae=t.height,se=1,G=null,Re=null;const ze=new wt(0,0,Z,ae),Le=new wt(0,0,Z,ae);let Ae=!1;const We=new xg;let Xe=!1,$e=!1;const zt=new lt,Ht=new D,wi=new wt,pi={background:null,fog:null,environment:null,overrideMaterial:null,isScene:!0};let xi=!1;function Ui(){return V===null?se:1}let U=i;function Vn(T,B){return t.getContext(T,B)}try{const T={alpha:!0,depth:n,stencil:s,antialias:a,premultipliedAlpha:l,preserveDrawingBuffer:c,powerPreference:h,failIfMajorPerformanceCaveat:d};if("setAttribute"in t&&t.setAttribute("data-engine",`three.js r${ag}`),t.addEventListener("webglcontextlost",Si,!1),t.addEventListener("webglcontextrestored",ri,!1),t.addEventListener("webglcontextcreationerror",qs,!1),U===null){const B="webgl2";if(U=Vn(B,T),U===null)throw Vn(B)?new Error("THREE.WebGLRenderer: Error creating WebGL context with your selected attributes."):new Error("THREE.WebGLRenderer: Error creating WebGL context.")}}catch(T){throw Ze("WebGLRenderer: "+T.message),T}let Gt,C,E,H,$,j,le,ue,J,ee,fe,Oe,ve,pe,Ve,Ke,ct,N,he,Q,me,xe,ie;function Pe(){Gt=new v5(U),Gt.init(),me=new lD(U,Gt),C=new c5(U,Gt,e,me),E=new aD(U,Gt),C.reversedDepthBuffer&&u&&E.buffers.depth.setReversed(!0),P=U.createFramebuffer(),O=U.createFramebuffer(),k=U.createFramebuffer(),H=new M5(U),$=new $I,j=new oD(U,Gt,E,$,C,me,H),le=new g5(I),ue=new EA(U),xe=new o5(U,ue),J=new y5(U,ue,H,xe),ee=new x5(U,J,ue,xe,H),N=new w5(U,C,j),Ve=new h5($),fe=new XI(I,le,Gt,C,xe,Ve),Oe=new pD(I,$),ve=new qI,pe=new eD(Gt),ct=new a5(I,le,E,ee,p,l),Ke=new rD(I,ee,C),ie=new mD(U,H,C,E),he=new l5(U,Gt,H),Q=new b5(U,Gt,H),H.programs=fe.programs,I.capabilities=C,I.extensions=Gt,I.properties=$,I.renderLists=ve,I.shadowMap=Ke,I.state=E,I.info=H}Pe(),g!==zn&&(_=new E5(g,t.width,t.height,a,n,s));const Te=new uD(I,U);this.xr=Te,this.getContext=function(){return U},this.getContextAttributes=function(){return U.getContextAttributes()},this.forceContextLoss=function(){const T=Gt.get("WEBGL_lose_context");T&&T.loseContext()},this.forceContextRestore=function(){const T=Gt.get("WEBGL_lose_context");T&&T.restoreContext()},this.getPixelRatio=function(){return se},this.setPixelRatio=function(T){T!==void 0&&(se=T,this.setSize(Z,ae,!1))},this.getSize=function(T){return T.set(Z,ae)},this.setSize=function(T,B,Y=!0){if(Te.isPresenting){ke("WebGLRenderer: Can't change size while VR device is presenting.");return}Z=T,ae=B,t.width=Math.floor(T*se),t.height=Math.floor(B*se),Y===!0&&(t.style.width=T+"px",t.style.height=B+"px"),_!==null&&_.setSize(t.width,t.height),this.setViewport(0,0,T,B)},this.getDrawingBufferSize=function(T){return T.set(Z*se,ae*se).floor()},this.setDrawingBufferSize=function(T,B,Y){Z=T,ae=B,se=Y,t.width=Math.floor(T*Y),t.height=Math.floor(B*Y),this.setViewport(0,0,T,B)},this.setEffects=function(T){if(g===zn){Ze("WebGLRenderer: setEffects() requires outputBufferType set to HalfFloatType or FloatType.");return}if(T){for(let B=0;B<T.length;B++)if(T[B].isOutputPass===!0){ke("WebGLRenderer: OutputPass is not needed in setEffects(). Tone mapping and color space conversion are applied automatically.");break}}_.setEffects(T||[])},this.getCurrentViewport=function(T){return T.copy(te)},this.getViewport=function(T){return T.copy(ze)},this.setViewport=function(T,B,Y,W){T.isVector4?ze.set(T.x,T.y,T.z,T.w):ze.set(T,B,Y,W),E.viewport(te.copy(ze).multiplyScalar(se).round())},this.getScissor=function(T){return T.copy(Le)},this.setScissor=function(T,B,Y,W){T.isVector4?Le.set(T.x,T.y,T.z,T.w):Le.set(T,B,Y,W),E.scissor(re.copy(Le).multiplyScalar(se).round())},this.getScissorTest=function(){return Ae},this.setScissorTest=function(T){E.setScissorTest(Ae=T)},this.setOpaqueSort=function(T){G=T},this.setTransparentSort=function(T){Re=T},this.getClearColor=function(T){return T.copy(ct.getClearColor())},this.setClearColor=function(){ct.setClearColor(...arguments)},this.getClearAlpha=function(){return ct.getClearAlpha()},this.setClearAlpha=function(){ct.setClearAlpha(...arguments)},this.clear=function(T=!0,B=!0,Y=!0){let W=0;if(T){let X=!1;if(V!==null){const Me=V.texture.format;X=m.has(Me)}if(X){const Me=V.texture.type,_e=v.has(Me),be=ct.getClearColor(),De=ct.getClearAlpha(),Ne=be.r,ht=be.g,gt=be.b;_e?(b[0]=Ne,b[1]=ht,b[2]=gt,b[3]=De,U.clearBufferuiv(U.COLOR,0,b)):(x[0]=Ne,x[1]=ht,x[2]=gt,x[3]=De,U.clearBufferiv(U.COLOR,0,x))}else W|=U.COLOR_BUFFER_BIT}B&&(W|=U.DEPTH_BUFFER_BIT,this.state.buffers.depth.setMask(!0)),Y&&(W|=U.STENCIL_BUFFER_BIT,this.state.buffers.stencil.setMask(4294967295)),W!==0&&U.clear(W)},this.clearColor=function(){this.clear(!0,!1,!1)},this.clearDepth=function(){this.clear(!1,!0,!1)},this.clearStencil=function(){this.clear(!1,!1,!0)},this.setNodesHandler=function(T){T.setRenderer(this),L=T},this.dispose=function(){t.removeEventListener("webglcontextlost",Si,!1),t.removeEventListener("webglcontextrestored",ri,!1),t.removeEventListener("webglcontextcreationerror",qs,!1),ct.dispose(),ve.dispose(),pe.dispose(),$.dispose(),le.dispose(),ee.dispose(),xe.dispose(),ie.dispose(),fe.dispose(),Te.dispose(),Te.removeEventListener("sessionstart",jg),Te.removeEventListener("sessionend",Jg),Fa.stop()};function Si(T){T.preventDefault(),Xu("WebGLRenderer: Context Lost."),R=!0}function ri(){Xu("WebGLRenderer: Context Restored."),R=!1;const T=H.autoReset,B=Ke.enabled,Y=Ke.autoUpdate,W=Ke.needsUpdate,X=Ke.type;Pe(),H.autoReset=T,Ke.enabled=B,Ke.autoUpdate=Y,Ke.needsUpdate=W,Ke.type=X}function qs(T){Ze("WebGLRenderer: A WebGL context could not be created. Reason: ",T.statusMessage)}function Ks(T){const B=T.target;B.removeEventListener("dispose",Ks),T2(B)}function T2(T){I2(T),$.remove(T)}function I2(T){const B=$.get(T).programs;B!==void 0&&(B.forEach(function(Y){fe.releaseProgram(Y)}),T.isShaderMaterial&&fe.releaseShaderCache(T))}this.renderBufferDirect=function(T,B,Y,W,X,Me){B===null&&(B=pi);const _e=X.isMesh&&X.matrixWorld.determinantAffine()<0,be=C2(T,B,Y,W,X);E.setMaterial(W,_e);let De=Y.index,Ne=1;if(W.wireframe===!0){if(De=J.getWireframeAttribute(Y),De===void 0)return;Ne=2}const ht=Y.drawRange,gt=Y.attributes.position;let Be=ht.start*Ne,jt=(ht.start+ht.count)*Ne;Me!==null&&(Be=Math.max(Be,Me.start*Ne),jt=Math.min(jt,(Me.start+Me.count)*Ne)),De!==null?(Be=Math.max(Be,0),jt=Math.min(jt,De.count)):gt!=null&&(Be=Math.max(Be,0),jt=Math.min(jt,gt.count));const Di=jt-Be;if(Di<0||Di===1/0)return;xe.setup(X,W,be,Y,De);let Ei,ei=he;if(De!==null&&(Ei=ue.get(De),ei=Q,ei.setIndex(Ei)),X.isMesh)W.wireframe===!0?(E.setLineWidth(W.wireframeLinewidth*Ui()),ei.setMode(U.LINES)):ei.setMode(U.TRIANGLES);else if(X.isLine){let un=W.linewidth;un===void 0&&(un=1),E.setLineWidth(un*Ui()),X.isLineSegments?ei.setMode(U.LINES):X.isLineLoop?ei.setMode(U.LINE_LOOP):ei.setMode(U.LINE_STRIP)}else X.isPoints?ei.setMode(U.POINTS):X.isSprite&&ei.setMode(U.TRIANGLES);if(X.isBatchedMesh)if(Gt.get("WEBGL_multi_draw"))ei.renderMultiDraw(X._multiDrawStarts,X._multiDrawCounts,X._multiDrawCount);else{const un=X._multiDrawStarts,Ee=X._multiDrawCounts,ts=X._multiDrawCount,Rt=De?ue.get(De).bytesPerElement:1,gs=$.get(W).currentProgram.getUniforms();for(let Zs=0;Zs<ts;Zs++)gs.setValue(U,"_gl_DrawID",Zs),ei.render(un[Zs]/Rt,Ee[Zs])}else if(X.isInstancedMesh)ei.renderInstances(Be,Di,X.count);else if(Y.isInstancedBufferGeometry){const un=Y._maxInstanceCount!==void 0?Y._maxInstanceCount:1/0,Ee=Math.min(Y.instanceCount,un);ei.renderInstances(Be,Di,Ee)}else ei.render(Be,Di)};function Zg(T,B,Y){T.transparent===!0&&T.side===Bn&&T.forceSinglePass===!1?(T.side=fi,T.needsUpdate=!0,Fh(T,B,Y),T.side=Pa,T.needsUpdate=!0,Fh(T,B,Y),T.side=Bn):Fh(T,B,Y)}this.compile=function(T,B,Y=null){Y===null&&(Y=T),S=pe.get(Y),S.init(B),M.push(S),Y.traverseVisible(function(X){X.isLight&&X.layers.test(B.layers)&&(S.pushLight(X),X.castShadow&&S.pushShadow(X))}),T!==Y&&T.traverseVisible(function(X){X.isLight&&X.layers.test(B.layers)&&(S.pushLight(X),X.castShadow&&S.pushShadow(X))}),S.setupLights();const W=new Set;return T.traverse(function(X){if(!(X.isMesh||X.isPoints||X.isLine||X.isSprite))return;const Me=X.material;if(Me)if(Array.isArray(Me))for(let _e=0;_e<Me.length;_e++){const be=Me[_e];Zg(be,Y,X),W.add(be)}else Zg(Me,Y,X),W.add(Me)}),S=M.pop(),W},this.compileAsync=function(T,B,Y=null){const W=this.compile(T,B,Y);return new Promise(X=>{function Me(){if(W.forEach(function(_e){$.get(_e).currentProgram.isReady()&&W.delete(_e)}),W.size===0){X(T);return}setTimeout(Me,10)}Gt.get("KHR_parallel_shader_compile")!==null?Me():setTimeout(Me,10)})};let Ff=null;function D2(T){Ff&&Ff(T)}function jg(){Fa.stop()}function Jg(){Fa.start()}const Fa=new Aw;Fa.setAnimationLoop(D2),typeof self<"u"&&Fa.setContext(self),this.setAnimationLoop=function(T){Ff=T,Te.setAnimationLoop(T),T===null?Fa.stop():Fa.start()},Te.addEventListener("sessionstart",jg),Te.addEventListener("sessionend",Jg),this.render=function(T,B){if(B!==void 0&&B.isCamera!==!0){Ze("WebGLRenderer.render: camera is not an instance of THREE.Camera.");return}if(R===!0)return;L!==null&&L.renderStart(T,B);const Y=Te.enabled===!0&&Te.isPresenting===!0,W=_!==null&&(V===null||Y)&&_.begin(I,V);if(T.matrixWorldAutoUpdate===!0&&T.updateMatrixWorld(),B.parent===null&&B.matrixWorldAutoUpdate===!0&&B.updateMatrixWorld(),Te.enabled===!0&&Te.isPresenting===!0&&(_===null||_.isCompositing()===!1)&&(Te.cameraAutoUpdate===!0&&Te.updateCamera(B),B=Te.getCamera()),T.isScene===!0&&T.onBeforeRender(I,T,B,V),S=pe.get(T,M.length),S.init(B),S.state.textureUnits=j.getTextureUnits(),M.push(S),zt.multiplyMatrices(B.projectionMatrix,B.matrixWorldInverse),We.setFromProjectionMatrix(zt,vr,B.reversedDepth),$e=this.localClippingEnabled,Xe=Ve.init(this.clippingPlanes,$e),w=ve.get(T,A.length),w.init(),A.push(w),Te.enabled===!0&&Te.isPresenting===!0){const _e=I.xr.getDepthSensingMesh();_e!==null&&Uf(_e,B,-1/0,I.sortObjects)}Uf(T,B,0,I.sortObjects),w.finish(),I.sortObjects===!0&&w.sort(G,Re,B.reversedDepth),xi=Te.enabled===!1||Te.isPresenting===!1||Te.hasDepthSensing()===!1,xi&&ct.addToRenderList(w,T),this.info.render.frame++,this.info.autoReset===!0&&this.info.reset(),Xe===!0&&Ve.beginShadows();const X=S.state.shadowsArray;if(Ke.render(X,T,B),Xe===!0&&Ve.endShadows(),(W&&_.hasRenderPass())===!1){const _e=w.opaque,be=w.transmissive;if(S.setupLights(),B.isArrayCamera){const De=B.cameras;if(be.length>0)for(let Ne=0,ht=De.length;Ne<ht;Ne++){const gt=De[Ne];ev(_e,be,T,gt)}xi&&ct.render(T);for(let Ne=0,ht=De.length;Ne<ht;Ne++){const gt=De[Ne];Qg(w,T,gt,gt.viewport)}}else be.length>0&&ev(_e,be,T,B),xi&&ct.render(T),Qg(w,T,B)}V!==null&&z===0&&(j.updateMultisampleRenderTarget(V),j.updateRenderTargetMipmap(V)),W&&_.end(I),T.isScene===!0&&T.onAfterRender(I,T,B),xe.resetDefaultState(),K=-1,q=null,M.pop(),M.length>0?(S=M[M.length-1],j.setTextureUnits(S.state.textureUnits),Xe===!0&&Ve.setGlobalState(I.clippingPlanes,S.state.camera)):S=null,A.pop(),A.length>0?w=A[A.length-1]:w=null,L!==null&&L.renderEnd()};function Uf(T,B,Y,W){if(T.visible===!1)return;if(T.layers.test(B.layers)){if(T.isGroup)Y=T.renderOrder;else if(T.isLOD)T.autoUpdate===!0&&T.update(B);else if(T.isLightProbeGrid)S.pushLightProbeGrid(T);else if(T.isLight)S.pushLight(T),T.castShadow&&S.pushShadow(T);else if(T.isSprite){if(!T.frustumCulled||We.intersectsSprite(T)){W&&wi.setFromMatrixPosition(T.matrixWorld).applyMatrix4(zt);const _e=ee.update(T),be=T.material;be.visible&&w.push(T,_e,be,Y,wi.z,null)}}else if((T.isMesh||T.isLine||T.isPoints)&&(!T.frustumCulled||We.intersectsObject(T))){const _e=ee.update(T),be=T.material;if(W&&(T.boundingSphere!==void 0?(T.boundingSphere===null&&T.computeBoundingSphere(),wi.copy(T.boundingSphere.center)):(_e.boundingSphere===null&&_e.computeBoundingSphere(),wi.copy(_e.boundingSphere.center)),wi.applyMatrix4(T.matrixWorld).applyMatrix4(zt)),Array.isArray(be)){const De=_e.groups;for(let Ne=0,ht=De.length;Ne<ht;Ne++){const gt=De[Ne],Be=be[gt.materialIndex];Be&&Be.visible&&w.push(T,_e,Be,Y,wi.z,gt)}}else be.visible&&w.push(T,_e,be,Y,wi.z,null)}}const Me=T.children;for(let _e=0,be=Me.length;_e<be;_e++)Uf(Me[_e],B,Y,W)}function Qg(T,B,Y,W){const{opaque:X,transmissive:Me,transparent:_e}=T;S.setupLightsView(Y),Xe===!0&&Ve.setGlobalState(I.clippingPlanes,Y),W&&E.viewport(te.copy(W)),X.length>0&&Nh(X,B,Y),Me.length>0&&Nh(Me,B,Y),_e.length>0&&Nh(_e,B,Y),E.buffers.depth.setTest(!0),E.buffers.depth.setMask(!0),E.buffers.color.setMask(!0),E.setPolygonOffset(!1)}function ev(T,B,Y,W){if((Y.isScene===!0?Y.overrideMaterial:null)!==null)return;if(S.state.transmissionRenderTarget[W.id]===void 0){const Be=Gt.has("EXT_color_buffer_half_float")||Gt.has("EXT_color_buffer_float");S.state.transmissionRenderTarget[W.id]=new Mi(1,1,{generateMipmaps:!0,type:Be?ci:zn,minFilter:gr,samples:Math.max(4,C.samples),stencilBuffer:s,resolveDepthBuffer:!1,resolveStencilBuffer:!1,colorSpace:Tt.workingColorSpace})}const Me=S.state.transmissionRenderTarget[W.id],_e=W.viewport||te;Me.setSize(_e.z*I.transmissionResolutionScale,_e.w*I.transmissionResolutionScale);const be=I.getRenderTarget(),De=I.getActiveCubeFace(),Ne=I.getActiveMipmapLevel();I.setRenderTarget(Me),I.getClearColor(ft),it=I.getClearAlpha(),it<1&&I.setClearColor(16777215,.5),I.clear(),xi&&ct.render(Y);const ht=I.toneMapping;I.toneMapping=Mr;const gt=W.viewport;if(W.viewport!==void 0&&(W.viewport=void 0),S.setupLightsView(W),Xe===!0&&Ve.setGlobalState(I.clippingPlanes,W),Nh(T,Y,W),j.updateMultisampleRenderTarget(Me),j.updateRenderTargetMipmap(Me),Gt.has("WEBGL_multisampled_render_to_texture")===!1){let Be=!1;for(let jt=0,Di=B.length;jt<Di;jt++){const Ei=B[jt],{object:ei,geometry:un,material:Ee,group:ts}=Ei;if(Ee.side===Bn&&ei.layers.test(W.layers)){const Rt=Ee.side;Ee.side=fi,Ee.needsUpdate=!0,tv(ei,Y,W,un,Ee,ts),Ee.side=Rt,Ee.needsUpdate=!0,Be=!0}}Be===!0&&(j.updateMultisampleRenderTarget(Me),j.updateRenderTargetMipmap(Me))}I.setRenderTarget(be,De,Ne),I.setClearColor(ft,it),gt!==void 0&&(W.viewport=gt),I.toneMapping=ht}function Nh(T,B,Y){const W=B.isScene===!0?B.overrideMaterial:null;for(let X=0,Me=T.length;X<Me;X++){const _e=T[X],{object:be,geometry:De,group:Ne}=_e;let ht=_e.material;ht.allowOverride===!0&&W!==null&&(ht=W),be.layers.test(Y.layers)&&tv(be,B,Y,De,ht,Ne)}}function tv(T,B,Y,W,X,Me){T.onBeforeRender(I,B,Y,W,X,Me),T.modelViewMatrix.multiplyMatrices(Y.matrixWorldInverse,T.matrixWorld),T.normalMatrix.getNormalMatrix(T.modelViewMatrix),X.onBeforeRender(I,B,Y,W,T,Me),X.transparent===!0&&X.side===Bn&&X.forceSinglePass===!1?(X.side=fi,X.needsUpdate=!0,I.renderBufferDirect(Y,B,W,X,T,Me),X.side=Pa,X.needsUpdate=!0,I.renderBufferDirect(Y,B,W,X,T,Me),X.side=Bn):I.renderBufferDirect(Y,B,W,X,T,Me),T.onAfterRender(I,B,Y,W,X,Me)}function Fh(T,B,Y){B.isScene!==!0&&(B=pi);const W=$.get(T),X=S.state.lights,Me=S.state.shadowsArray,_e=X.state.version,be=fe.getParameters(T,X.state,Me,B,Y,S.state.lightProbeGridArray),De=fe.getProgramCacheKey(be);let Ne=W.programs;W.environment=T.isMeshStandardMaterial||T.isMeshLambertMaterial||T.isMeshPhongMaterial?B.environment:null,W.fog=B.fog;const ht=T.isMeshStandardMaterial||T.isMeshLambertMaterial&&!T.envMap||T.isMeshPhongMaterial&&!T.envMap;W.envMap=le.get(T.envMap||W.environment,ht),W.envMapRotation=W.environment!==null&&T.envMap===null?B.environmentRotation:T.envMapRotation,Ne===void 0&&(T.addEventListener("dispose",Ks),Ne=new Map,W.programs=Ne);let gt=Ne.get(De);if(gt!==void 0){if(W.currentProgram===gt&&W.lightsStateVersion===_e)return nv(T,be),gt}else be.uniforms=fe.getUniforms(T),L!==null&&T.isNodeMaterial&&L.build(T,Y,be),T.onBeforeCompile(be,I),gt=fe.acquireProgram(be,De),Ne.set(De,gt),W.uniforms=be.uniforms;const Be=W.uniforms;return(!T.isShaderMaterial&&!T.isRawShaderMaterial||T.clipping===!0)&&(Be.clippingPlanes=Ve.uniform),nv(T,be),W.needsLights=P2(T),W.lightsStateVersion=_e,W.needsLights&&(Be.ambientLightColor.value=X.state.ambient,Be.lightProbe.value=X.state.probe,Be.directionalLights.value=X.state.directional,Be.directionalLightShadows.value=X.state.directionalShadow,Be.spotLights.value=X.state.spot,Be.spotLightShadows.value=X.state.spotShadow,Be.rectAreaLights.value=X.state.rectArea,Be.ltc_1.value=X.state.rectAreaLTC1,Be.ltc_2.value=X.state.rectAreaLTC2,Be.pointLights.value=X.state.point,Be.pointLightShadows.value=X.state.pointShadow,Be.hemisphereLights.value=X.state.hemi,Be.directionalShadowMatrix.value=X.state.directionalShadowMatrix,Be.spotLightMatrix.value=X.state.spotLightMatrix,Be.spotLightMap.value=X.state.spotLightMap,Be.pointShadowMatrix.value=X.state.pointShadowMatrix),W.lightProbeGrid=S.state.lightProbeGridArray.length>0,W.currentProgram=gt,W.uniformsList=null,gt}function iv(T){if(T.uniformsList===null){const B=T.currentProgram.getUniforms();T.uniformsList=iu.seqWithValue(B.seq,T.uniforms)}return T.uniformsList}function nv(T,B){const Y=$.get(T);Y.outputColorSpace=B.outputColorSpace,Y.batching=B.batching,Y.batchingColor=B.batchingColor,Y.instancing=B.instancing,Y.instancingColor=B.instancingColor,Y.instancingMorph=B.instancingMorph,Y.skinning=B.skinning,Y.morphTargets=B.morphTargets,Y.morphNormals=B.morphNormals,Y.morphColors=B.morphColors,Y.morphTargetsCount=B.morphTargetsCount,Y.numClippingPlanes=B.numClippingPlanes,Y.numIntersection=B.numClipIntersection,Y.vertexAlphas=B.vertexAlphas,Y.vertexTangents=B.vertexTangents,Y.toneMapping=B.toneMapping}function R2(T,B){if(T.length===0)return null;if(T.length===1)return T[0].texture!==null?T[0]:null;y.setFromMatrixPosition(B.matrixWorld);for(let Y=0,W=T.length;Y<W;Y++){const X=T[Y];if(X.texture!==null&&X.boundingBox.containsPoint(y))return X}return null}function C2(T,B,Y,W,X){B.isScene!==!0&&(B=pi),j.resetTextureUnits();const Me=B.fog,_e=W.isMeshStandardMaterial||W.isMeshLambertMaterial||W.isMeshPhongMaterial?B.environment:null,be=V===null?I.outputColorSpace:V.isXRRenderTarget===!0?V.texture.colorSpace:Tt.workingColorSpace,De=W.isMeshStandardMaterial||W.isMeshLambertMaterial&&!W.envMap||W.isMeshPhongMaterial&&!W.envMap,Ne=le.get(W.envMap||_e,De),ht=W.vertexColors===!0&&!!Y.attributes.color&&Y.attributes.color.itemSize===4,gt=!!Y.attributes.tangent&&(!!W.normalMap||W.anisotropy>0),Be=!!Y.morphAttributes.position,jt=!!Y.morphAttributes.normal,Di=!!Y.morphAttributes.color;let Ei=Mr;W.toneMapped&&(V===null||V.isXRRenderTarget===!0)&&(Ei=I.toneMapping);const ei=Y.morphAttributes.position||Y.morphAttributes.normal||Y.morphAttributes.color,un=ei!==void 0?ei.length:0,Ee=$.get(W),ts=S.state.lights;if(Xe===!0&&($e===!0||T!==q)){const ai=T===q&&W.id===K;Ve.setState(W,T,ai)}let Rt=!1;W.version===Ee.__version?(Ee.needsLights&&Ee.lightsStateVersion!==ts.state.version||Ee.outputColorSpace!==be||X.isBatchedMesh&&Ee.batching===!1||!X.isBatchedMesh&&Ee.batching===!0||X.isBatchedMesh&&Ee.batchingColor===!0&&X.colorTexture===null||X.isBatchedMesh&&Ee.batchingColor===!1&&X.colorTexture!==null||X.isInstancedMesh&&Ee.instancing===!1||!X.isInstancedMesh&&Ee.instancing===!0||X.isSkinnedMesh&&Ee.skinning===!1||!X.isSkinnedMesh&&Ee.skinning===!0||X.isInstancedMesh&&Ee.instancingColor===!0&&X.instanceColor===null||X.isInstancedMesh&&Ee.instancingColor===!1&&X.instanceColor!==null||X.isInstancedMesh&&Ee.instancingMorph===!0&&X.morphTexture===null||X.isInstancedMesh&&Ee.instancingMorph===!1&&X.morphTexture!==null||Ee.envMap!==Ne||W.fog===!0&&Ee.fog!==Me||Ee.numClippingPlanes!==void 0&&(Ee.numClippingPlanes!==Ve.numPlanes||Ee.numIntersection!==Ve.numIntersection)||Ee.vertexAlphas!==ht||Ee.vertexTangents!==gt||Ee.morphTargets!==Be||Ee.morphNormals!==jt||Ee.morphColors!==Di||Ee.toneMapping!==Ei||Ee.morphTargetsCount!==un||!!Ee.lightProbeGrid!=S.state.lightProbeGridArray.length>0)&&(Rt=!0):(Rt=!0,Ee.__version=W.version);let gs=Ee.currentProgram;Rt===!0&&(gs=Fh(W,B,X),L&&W.isNodeMaterial&&L.onUpdateProgram(W,gs,Ee));let Zs=!1,Zr=!1,Go=!1;const ti=gs.getUniforms(),Ri=Ee.uniforms;if(E.useProgram(gs.program)&&(Zs=!0,Zr=!0,Go=!0),W.id!==K&&(K=W.id,Zr=!0),Ee.needsLights){const ai=R2(S.state.lightProbeGridArray,X);Ee.lightProbeGrid!==ai&&(Ee.lightProbeGrid=ai,Zr=!0)}if(Zs||q!==T){E.buffers.depth.getReversed()&&T.reversedDepth!==!0&&(T._reversedDepth=!0,T.updateProjectionMatrix()),ti.setValue(U,"projectionMatrix",T.projectionMatrix),ti.setValue(U,"viewMatrix",T.matrixWorldInverse);const Jr=ti.map.cameraPosition;Jr!==void 0&&Jr.setValue(U,Ht.setFromMatrixPosition(T.matrixWorld)),C.logarithmicDepthBuffer&&ti.setValue(U,"logDepthBufFC",2/(Math.log(T.far+1)/Math.LN2)),(W.isMeshPhongMaterial||W.isMeshToonMaterial||W.isMeshLambertMaterial||W.isMeshBasicMaterial||W.isMeshStandardMaterial||W.isShaderMaterial)&&ti.setValue(U,"isOrthographic",T.isOrthographicCamera===!0),q!==T&&(q=T,Zr=!0,Go=!0)}if(Ee.needsLights&&(ts.state.directionalShadowMap.length>0&&ti.setValue(U,"directionalShadowMap",ts.state.directionalShadowMap,j),ts.state.spotShadowMap.length>0&&ti.setValue(U,"spotShadowMap",ts.state.spotShadowMap,j),ts.state.pointShadowMap.length>0&&ti.setValue(U,"pointShadowMap",ts.state.pointShadowMap,j)),X.isSkinnedMesh){ti.setOptional(U,X,"bindMatrix"),ti.setOptional(U,X,"bindMatrixInverse");const ai=X.skeleton;ai&&(ai.boneTexture===null&&ai.computeBoneTexture(),ti.setValue(U,"boneTexture",ai.boneTexture,j))}X.isBatchedMesh&&(ti.setOptional(U,X,"batchingTexture"),ti.setValue(U,"batchingTexture",X._matricesTexture,j),ti.setOptional(U,X,"batchingIdTexture"),ti.setValue(U,"batchingIdTexture",X._indirectTexture,j),ti.setOptional(U,X,"batchingColorTexture"),X._colorsTexture!==null&&ti.setValue(U,"batchingColorTexture",X._colorsTexture,j));const jr=Y.morphAttributes;if((jr.position!==void 0||jr.normal!==void 0||jr.color!==void 0)&&N.update(X,Y,gs),(Zr||Ee.receiveShadow!==X.receiveShadow)&&(Ee.receiveShadow=X.receiveShadow,ti.setValue(U,"receiveShadow",X.receiveShadow)),(W.isMeshStandardMaterial||W.isMeshLambertMaterial||W.isMeshPhongMaterial)&&W.envMap===null&&B.environment!==null&&(Ri.envMapIntensity.value=B.environmentIntensity),Ri.dfgLUT!==void 0&&(Ri.dfgLUT.value=vD()),Zr){if(ti.setValue(U,"toneMappingExposure",I.toneMappingExposure),Ee.needsLights&&k2(Ri,Go),Me&&W.fog===!0&&Oe.refreshFogUniforms(Ri,Me),Oe.refreshMaterialUniforms(Ri,W,se,ae,S.state.transmissionRenderTarget[T.id]),Ee.needsLights&&Ee.lightProbeGrid){const ai=Ee.lightProbeGrid;Ri.probesSH.value=ai.texture,Ri.probesMin.value.copy(ai.boundingBox.min),Ri.probesMax.value.copy(ai.boundingBox.max),Ri.probesResolution.value.copy(ai.resolution)}iu.upload(U,iv(Ee),Ri,j)}if(W.isShaderMaterial&&W.uniformsNeedUpdate===!0&&(iu.upload(U,iv(Ee),Ri,j),W.uniformsNeedUpdate=!1),W.isSpriteMaterial&&ti.setValue(U,"center",X.center),ti.setValue(U,"modelViewMatrix",X.modelViewMatrix),ti.setValue(U,"normalMatrix",X.normalMatrix),ti.setValue(U,"modelMatrix",X.matrixWorld),W.uniformsGroups!==void 0){const ai=W.uniformsGroups;for(let Jr=0,Vo=ai.length;Jr<Vo;Jr++){const sv=ai[Jr];ie.update(sv,gs),ie.bind(sv,gs)}}return gs}function k2(T,B){T.ambientLightColor.needsUpdate=B,T.lightProbe.needsUpdate=B,T.directionalLights.needsUpdate=B,T.directionalLightShadows.needsUpdate=B,T.pointLights.needsUpdate=B,T.pointLightShadows.needsUpdate=B,T.spotLights.needsUpdate=B,T.spotLightShadows.needsUpdate=B,T.rectAreaLights.needsUpdate=B,T.hemisphereLights.needsUpdate=B}function P2(T){return T.isMeshLambertMaterial||T.isMeshToonMaterial||T.isMeshPhongMaterial||T.isMeshStandardMaterial||T.isShadowMaterial||T.isShaderMaterial&&T.lights===!0}this.getActiveCubeFace=function(){return F},this.getActiveMipmapLevel=function(){return z},this.getRenderTarget=function(){return V},this.setRenderTargetTextures=function(T,B,Y){const W=$.get(T);W.__autoAllocateDepthBuffer=T.resolveDepthBuffer===!1,W.__autoAllocateDepthBuffer===!1&&(W.__useRenderToTexture=!1),$.get(T.texture).__webglTexture=B,$.get(T.depthTexture).__webglTexture=W.__autoAllocateDepthBuffer?void 0:Y,W.__hasExternalTextures=!0},this.setRenderTargetFramebuffer=function(T,B){const Y=$.get(T);Y.__webglFramebuffer=B,Y.__useDefaultFramebuffer=B===void 0},this.setRenderTarget=function(T,B=0,Y=0){V=T,F=B,z=Y;let W=null,X=!1,Me=!1;if(T){const be=$.get(T);if(be.__useDefaultFramebuffer!==void 0){E.bindFramebuffer(U.FRAMEBUFFER,be.__webglFramebuffer),te.copy(T.viewport),re.copy(T.scissor),Ge=T.scissorTest,E.viewport(te),E.scissor(re),E.setScissorTest(Ge),K=-1;return}else if(be.__webglFramebuffer===void 0)j.setupRenderTarget(T);else if(be.__hasExternalTextures)j.rebindTextures(T,$.get(T.texture).__webglTexture,$.get(T.depthTexture).__webglTexture);else if(T.depthBuffer){const ht=T.depthTexture;if(be.__boundDepthTexture!==ht){if(ht!==null&&$.has(ht)&&(T.width!==ht.image.width||T.height!==ht.image.height))throw new Error("THREE.WebGLRenderer: Attached DepthTexture is initialized to the incorrect size.");j.setupDepthRenderbuffer(T)}}const De=T.texture;(De.isData3DTexture||De.isDataArrayTexture||De.isCompressedArrayTexture)&&(Me=!0);const Ne=$.get(T).__webglFramebuffer;T.isWebGLCubeRenderTarget?(Array.isArray(Ne[B])?W=Ne[B][Y]:W=Ne[B],X=!0):T.samples>0&&j.useMultisampledRTT(T)===!1?W=$.get(T).__webglMultisampledFramebuffer:Array.isArray(Ne)?W=Ne[Y]:W=Ne,te.copy(T.viewport),re.copy(T.scissor),Ge=T.scissorTest}else te.copy(ze).multiplyScalar(se).floor(),re.copy(Le).multiplyScalar(se).floor(),Ge=Ae;if(Y!==0&&(W=P),E.bindFramebuffer(U.FRAMEBUFFER,W)&&E.drawBuffers(T,W),E.viewport(te),E.scissor(re),E.setScissorTest(Ge),X){const be=$.get(T.texture);U.framebufferTexture2D(U.FRAMEBUFFER,U.COLOR_ATTACHMENT0,U.TEXTURE_CUBE_MAP_POSITIVE_X+B,be.__webglTexture,Y)}else if(Me){const be=B;for(let De=0;De<T.textures.length;De++){const Ne=$.get(T.textures[De]);U.framebufferTextureLayer(U.FRAMEBUFFER,U.COLOR_ATTACHMENT0+De,Ne.__webglTexture,Y,be)}}else if(T!==null&&Y!==0){const be=$.get(T.texture);U.framebufferTexture2D(U.FRAMEBUFFER,U.COLOR_ATTACHMENT0,U.TEXTURE_2D,be.__webglTexture,Y)}K=-1},this.readRenderTargetPixels=function(T,B,Y,W,X,Me,_e,be=0){if(!(T&&T.isWebGLRenderTarget)){Ze("WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");return}let De=$.get(T).__webglFramebuffer;if(T.isWebGLCubeRenderTarget&&_e!==void 0&&(De=De[_e]),De){E.bindFramebuffer(U.FRAMEBUFFER,De);try{const Ne=T.textures[be],ht=Ne.format,gt=Ne.type;if(T.textures.length>1&&U.readBuffer(U.COLOR_ATTACHMENT0+be),!C.textureFormatReadable(ht)){Ze("WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.");return}if(!C.textureTypeReadable(gt)){Ze("WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.");return}B>=0&&B<=T.width-W&&Y>=0&&Y<=T.height-X&&U.readPixels(B,Y,W,X,me.convert(ht),me.convert(gt),Me)}finally{const Ne=V!==null?$.get(V).__webglFramebuffer:null;E.bindFramebuffer(U.FRAMEBUFFER,Ne)}}},this.readRenderTargetPixelsAsync=async function(T,B,Y,W,X,Me,_e,be=0){if(!(T&&T.isWebGLRenderTarget))throw new Error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");let De=$.get(T).__webglFramebuffer;if(T.isWebGLCubeRenderTarget&&_e!==void 0&&(De=De[_e]),De)if(B>=0&&B<=T.width-W&&Y>=0&&Y<=T.height-X){E.bindFramebuffer(U.FRAMEBUFFER,De);const Ne=T.textures[be],ht=Ne.format,gt=Ne.type;if(T.textures.length>1&&U.readBuffer(U.COLOR_ATTACHMENT0+be),!C.textureFormatReadable(ht))throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.");if(!C.textureTypeReadable(gt))throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.");const Be=U.createBuffer();U.bindBuffer(U.PIXEL_PACK_BUFFER,Be),U.bufferData(U.PIXEL_PACK_BUFFER,Me.byteLength,U.STREAM_READ),U.readPixels(B,Y,W,X,me.convert(ht),me.convert(gt),0);const jt=V!==null?$.get(V).__webglFramebuffer:null;E.bindFramebuffer(U.FRAMEBUFFER,jt);const Di=U.fenceSync(U.SYNC_GPU_COMMANDS_COMPLETE,0);return U.flush(),await XE(U,Di,4),U.bindBuffer(U.PIXEL_PACK_BUFFER,Be),U.getBufferSubData(U.PIXEL_PACK_BUFFER,0,Me),U.deleteBuffer(Be),U.deleteSync(Di),Me}else throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: requested read bounds are out of range.")},this.copyFramebufferToTexture=function(T,B=null,Y=0){const W=Math.pow(2,-Y),X=Math.floor(T.image.width*W),Me=Math.floor(T.image.height*W),_e=B!==null?B.x:0,be=B!==null?B.y:0;j.setTexture2D(T,0),U.copyTexSubImage2D(U.TEXTURE_2D,Y,0,0,_e,be,X,Me),E.unbindTexture()},this.copyTextureToTexture=function(T,B,Y=null,W=null,X=0,Me=0){let _e,be,De,Ne,ht,gt,Be,jt,Di;const Ei=T.isCompressedTexture?T.mipmaps[Me]:T.image;if(Y!==null)_e=Y.max.x-Y.min.x,be=Y.max.y-Y.min.y,De=Y.isBox3?Y.max.z-Y.min.z:1,Ne=Y.min.x,ht=Y.min.y,gt=Y.isBox3?Y.min.z:0;else{const Ri=Math.pow(2,-X);_e=Math.floor(Ei.width*Ri),be=Math.floor(Ei.height*Ri),T.isDataArrayTexture?De=Ei.depth:T.isData3DTexture?De=Math.floor(Ei.depth*Ri):De=1,Ne=0,ht=0,gt=0}W!==null?(Be=W.x,jt=W.y,Di=W.z):(Be=0,jt=0,Di=0);const ei=me.convert(B.format),un=me.convert(B.type);let Ee;B.isData3DTexture?(j.setTexture3D(B,0),Ee=U.TEXTURE_3D):B.isDataArrayTexture||B.isCompressedArrayTexture?(j.setTexture2DArray(B,0),Ee=U.TEXTURE_2D_ARRAY):(j.setTexture2D(B,0),Ee=U.TEXTURE_2D),E.activeTexture(U.TEXTURE0),E.pixelStorei(U.UNPACK_FLIP_Y_WEBGL,B.flipY),E.pixelStorei(U.UNPACK_PREMULTIPLY_ALPHA_WEBGL,B.premultiplyAlpha),E.pixelStorei(U.UNPACK_ALIGNMENT,B.unpackAlignment);const ts=E.getParameter(U.UNPACK_ROW_LENGTH),Rt=E.getParameter(U.UNPACK_IMAGE_HEIGHT),gs=E.getParameter(U.UNPACK_SKIP_PIXELS),Zs=E.getParameter(U.UNPACK_SKIP_ROWS),Zr=E.getParameter(U.UNPACK_SKIP_IMAGES);E.pixelStorei(U.UNPACK_ROW_LENGTH,Ei.width),E.pixelStorei(U.UNPACK_IMAGE_HEIGHT,Ei.height),E.pixelStorei(U.UNPACK_SKIP_PIXELS,Ne),E.pixelStorei(U.UNPACK_SKIP_ROWS,ht),E.pixelStorei(U.UNPACK_SKIP_IMAGES,gt);const Go=T.isDataArrayTexture||T.isData3DTexture,ti=B.isDataArrayTexture||B.isData3DTexture;if(T.isDepthTexture){const Ri=$.get(T),jr=$.get(B),ai=$.get(Ri.__renderTarget),Jr=$.get(jr.__renderTarget);E.bindFramebuffer(U.READ_FRAMEBUFFER,ai.__webglFramebuffer),E.bindFramebuffer(U.DRAW_FRAMEBUFFER,Jr.__webglFramebuffer);for(let Vo=0;Vo<De;Vo++)Go&&(U.framebufferTextureLayer(U.READ_FRAMEBUFFER,U.COLOR_ATTACHMENT0,$.get(T).__webglTexture,X,gt+Vo),U.framebufferTextureLayer(U.DRAW_FRAMEBUFFER,U.COLOR_ATTACHMENT0,$.get(B).__webglTexture,Me,Di+Vo)),U.blitFramebuffer(Ne,ht,_e,be,Be,jt,_e,be,U.DEPTH_BUFFER_BIT,U.NEAREST);E.bindFramebuffer(U.READ_FRAMEBUFFER,null),E.bindFramebuffer(U.DRAW_FRAMEBUFFER,null)}else if(X!==0||T.isRenderTargetTexture||$.has(T)){const Ri=$.get(T),jr=$.get(B);E.bindFramebuffer(U.READ_FRAMEBUFFER,O),E.bindFramebuffer(U.DRAW_FRAMEBUFFER,k);for(let ai=0;ai<De;ai++)Go?U.framebufferTextureLayer(U.READ_FRAMEBUFFER,U.COLOR_ATTACHMENT0,Ri.__webglTexture,X,gt+ai):U.framebufferTexture2D(U.READ_FRAMEBUFFER,U.COLOR_ATTACHMENT0,U.TEXTURE_2D,Ri.__webglTexture,X),ti?U.framebufferTextureLayer(U.DRAW_FRAMEBUFFER,U.COLOR_ATTACHMENT0,jr.__webglTexture,Me,Di+ai):U.framebufferTexture2D(U.DRAW_FRAMEBUFFER,U.COLOR_ATTACHMENT0,U.TEXTURE_2D,jr.__webglTexture,Me),X!==0?U.blitFramebuffer(Ne,ht,_e,be,Be,jt,_e,be,U.COLOR_BUFFER_BIT,U.NEAREST):ti?U.copyTexSubImage3D(Ee,Me,Be,jt,Di+ai,Ne,ht,_e,be):U.copyTexSubImage2D(Ee,Me,Be,jt,Ne,ht,_e,be);E.bindFramebuffer(U.READ_FRAMEBUFFER,null),E.bindFramebuffer(U.DRAW_FRAMEBUFFER,null)}else ti?T.isDataTexture||T.isData3DTexture?U.texSubImage3D(Ee,Me,Be,jt,Di,_e,be,De,ei,un,Ei.data):B.isCompressedArrayTexture?U.compressedTexSubImage3D(Ee,Me,Be,jt,Di,_e,be,De,ei,Ei.data):U.texSubImage3D(Ee,Me,Be,jt,Di,_e,be,De,ei,un,Ei):T.isDataTexture?U.texSubImage2D(U.TEXTURE_2D,Me,Be,jt,_e,be,ei,un,Ei.data):T.isCompressedTexture?U.compressedTexSubImage2D(U.TEXTURE_2D,Me,Be,jt,Ei.width,Ei.height,ei,Ei.data):U.texSubImage2D(U.TEXTURE_2D,Me,Be,jt,_e,be,ei,un,Ei);E.pixelStorei(U.UNPACK_ROW_LENGTH,ts),E.pixelStorei(U.UNPACK_IMAGE_HEIGHT,Rt),E.pixelStorei(U.UNPACK_SKIP_PIXELS,gs),E.pixelStorei(U.UNPACK_SKIP_ROWS,Zs),E.pixelStorei(U.UNPACK_SKIP_IMAGES,Zr),Me===0&&B.generateMipmaps&&U.generateMipmap(Ee),E.unbindTexture()},this.initRenderTarget=function(T){$.get(T).__webglFramebuffer===void 0&&j.setupRenderTarget(T)},this.initTexture=function(T){T.isCubeTexture?j.setTextureCube(T,0):T.isData3DTexture?j.setTexture3D(T,0):T.isDataArrayTexture||T.isCompressedArrayTexture?j.setTexture2DArray(T,0):j.setTexture2D(T,0),E.unbindTexture()},this.resetState=function(){F=0,z=0,V=null,E.reset(),xe.reset()},typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}get coordinateSystem(){return vr}get outputColorSpace(){return this._outputColorSpace}set outputColorSpace(e){this._outputColorSpace=e;const t=this.getContext();t.drawingBufferColorSpace=Tt._getDrawingBufferColorSpace(e),t.unpackColorSpace=Tt._getUnpackColorSpace()}}const bD=`
7270
+ }`;class dD{constructor(){this.texture=null,this.mesh=null,this.depthNear=0,this.depthFar=0}init(e,t){if(this.texture===null){const i=new gw(e.texture);(e.depthNear!==t.depthNear||e.depthFar!==t.depthFar)&&(this.depthNear=e.depthNear,this.depthFar=e.depthFar),this.texture=i}}getMesh(e){if(this.texture!==null&&this.mesh===null){const t=e.cameras[0].viewport,i=new Dt({vertexShader:cD,fragmentShader:hD,uniforms:{depthColor:{value:this.texture},depthWidth:{value:t.z},depthHeight:{value:t.w}}});this.mesh=new Se(new Gn(20,20),i)}return this.mesh}reset(){this.texture=null,this.mesh=null}getDepthTexture(){return this.texture}}class uD extends Na{constructor(e,t){super();const i=this;let n=null,s=1,r=null,a="local-floor",l=1,c=null,h=null,d=null,u=null,f=null,p=null;const g=typeof XRWebGLBinding<"u",m=new dD,v={},b=t.getContextAttributes();let x=null,y=null;const w=[],S=[],A=new we;let M=null;const _=new Qn;_.viewport=new wt;const I=new Qn;I.viewport=new wt;const R=[_,I],L=new oA;let P=null,O=null;this.cameraAutoUpdate=!0,this.enabled=!1,this.isPresenting=!1,this.getController=function(Z){let ae=w[Z];return ae===void 0&&(ae=new Jf,w[Z]=ae),ae.getTargetRaySpace()},this.getControllerGrip=function(Z){let ae=w[Z];return ae===void 0&&(ae=new Jf,w[Z]=ae),ae.getGripSpace()},this.getHand=function(Z){let ae=w[Z];return ae===void 0&&(ae=new Jf,w[Z]=ae),ae.getHandSpace()};function k(Z){const ae=S.indexOf(Z.inputSource);if(ae===-1)return;const se=w[ae];se!==void 0&&(se.update(Z.inputSource,Z.frame,c||r),se.dispatchEvent({type:Z.type,data:Z.inputSource}))}function F(){n.removeEventListener("select",k),n.removeEventListener("selectstart",k),n.removeEventListener("selectend",k),n.removeEventListener("squeeze",k),n.removeEventListener("squeezestart",k),n.removeEventListener("squeezeend",k),n.removeEventListener("end",F),n.removeEventListener("inputsourceschange",z);for(let Z=0;Z<w.length;Z++){const ae=S[Z];ae!==null&&(S[Z]=null,w[Z].disconnect(ae))}P=null,O=null,m.reset();for(const Z in v)delete v[Z];e.setRenderTarget(x),f=null,u=null,d=null,n=null,y=null,it.stop(),i.isPresenting=!1,e.setPixelRatio(M),e.setSize(A.width,A.height,!1),i.dispatchEvent({type:"sessionend"})}this.setFramebufferScaleFactor=function(Z){s=Z,i.isPresenting===!0&&ke("WebXRManager: Cannot change framebuffer scale while presenting.")},this.setReferenceSpaceType=function(Z){a=Z,i.isPresenting===!0&&ke("WebXRManager: Cannot change reference space type while presenting.")},this.getReferenceSpace=function(){return c||r},this.setReferenceSpace=function(Z){c=Z},this.getBaseLayer=function(){return u!==null?u:f},this.getBinding=function(){return d===null&&g&&(d=new XRWebGLBinding(n,t)),d},this.getFrame=function(){return p},this.getSession=function(){return n},this.setSession=async function(Z){if(n=Z,n!==null){if(x=e.getRenderTarget(),n.addEventListener("select",k),n.addEventListener("selectstart",k),n.addEventListener("selectend",k),n.addEventListener("squeeze",k),n.addEventListener("squeezestart",k),n.addEventListener("squeezeend",k),n.addEventListener("end",F),n.addEventListener("inputsourceschange",z),b.xrCompatible!==!0&&await t.makeXRCompatible(),M=e.getPixelRatio(),e.getSize(A),g&&"createProjectionLayer"in XRWebGLBinding.prototype){let se=null,G=null,Re=null;b.depth&&(Re=b.stencil?t.DEPTH24_STENCIL8:t.DEPTH_COMPONENT24,se=b.stencil?bo:Wr,G=b.stencil?wh:Ts);const ze={colorFormat:t.RGBA8,depthFormat:Re,scaleFactor:s};d=this.getBinding(),u=d.createProjectionLayer(ze),n.updateRenderState({layers:[u]}),e.setPixelRatio(1),e.setSize(u.textureWidth,u.textureHeight,!1),y=new Mi(u.textureWidth,u.textureHeight,{format:Vi,type:zn,depthTexture:new La(u.textureWidth,u.textureHeight,G,void 0,void 0,void 0,void 0,void 0,void 0,se),stencilBuffer:b.stencil,colorSpace:e.outputColorSpace,samples:b.antialias?4:0,resolveDepthBuffer:u.ignoreDepthValues===!1,resolveStencilBuffer:u.ignoreDepthValues===!1})}else{const se={antialias:b.antialias,alpha:!0,depth:b.depth,stencil:b.stencil,framebufferScaleFactor:s};f=new XRWebGLLayer(n,t,se),n.updateRenderState({baseLayer:f}),e.setPixelRatio(1),e.setSize(f.framebufferWidth,f.framebufferHeight,!1),y=new Mi(f.framebufferWidth,f.framebufferHeight,{format:Vi,type:zn,colorSpace:e.outputColorSpace,stencilBuffer:b.stencil,resolveDepthBuffer:f.ignoreDepthValues===!1,resolveStencilBuffer:f.ignoreDepthValues===!1})}y.isXRRenderTarget=!0,this.setFoveation(l),c=null,r=await n.requestReferenceSpace(a),it.setContext(n),it.start(),i.isPresenting=!0,i.dispatchEvent({type:"sessionstart"})}},this.getEnvironmentBlendMode=function(){if(n!==null)return n.environmentBlendMode},this.getDepthTexture=function(){return m.getDepthTexture()};function z(Z){for(let ae=0;ae<Z.removed.length;ae++){const se=Z.removed[ae],G=S.indexOf(se);G>=0&&(S[G]=null,w[G].disconnect(se))}for(let ae=0;ae<Z.added.length;ae++){const se=Z.added[ae];let G=S.indexOf(se);if(G===-1){for(let ze=0;ze<w.length;ze++)if(ze>=S.length){S.push(se),G=ze;break}else if(S[ze]===null){S[ze]=se,G=ze;break}if(G===-1)break}const Re=w[G];Re&&Re.connect(se)}}const V=new D,K=new D;function q(Z,ae,se){V.setFromMatrixPosition(ae.matrixWorld),K.setFromMatrixPosition(se.matrixWorld);const G=V.distanceTo(K),Re=ae.projectionMatrix.elements,ze=se.projectionMatrix.elements,Le=Re[14]/(Re[10]-1),Ae=Re[14]/(Re[10]+1),We=(Re[9]+1)/Re[5],Xe=(Re[9]-1)/Re[5],$e=(Re[8]-1)/Re[0],zt=(ze[8]+1)/ze[0],Ht=Le*$e,wi=Le*zt,pi=G/(-$e+zt),xi=pi*-$e;if(ae.matrixWorld.decompose(Z.position,Z.quaternion,Z.scale),Z.translateX(xi),Z.translateZ(pi),Z.matrixWorld.compose(Z.position,Z.quaternion,Z.scale),Z.matrixWorldInverse.copy(Z.matrixWorld).invert(),Re[10]===-1)Z.projectionMatrix.copy(ae.projectionMatrix),Z.projectionMatrixInverse.copy(ae.projectionMatrixInverse);else{const Ui=Le+pi,U=Ae+pi,Vn=Ht-xi,Gt=wi+(G-xi),C=We*Ae/U*Ui,E=Xe*Ae/U*Ui;Z.projectionMatrix.makePerspective(Vn,Gt,C,E,Ui,U),Z.projectionMatrixInverse.copy(Z.projectionMatrix).invert()}}function te(Z,ae){ae===null?Z.matrixWorld.copy(Z.matrix):Z.matrixWorld.multiplyMatrices(ae.matrixWorld,Z.matrix),Z.matrixWorldInverse.copy(Z.matrixWorld).invert()}this.updateCamera=function(Z){if(n===null)return;let ae=Z.near,se=Z.far;m.texture!==null&&(m.depthNear>0&&(ae=m.depthNear),m.depthFar>0&&(se=m.depthFar)),L.near=I.near=_.near=ae,L.far=I.far=_.far=se,(P!==L.near||O!==L.far)&&(n.updateRenderState({depthNear:L.near,depthFar:L.far}),P=L.near,O=L.far),L.layers.mask=Z.layers.mask|6,_.layers.mask=L.layers.mask&-5,I.layers.mask=L.layers.mask&-3;const G=Z.parent,Re=L.cameras;te(L,G);for(let ze=0;ze<Re.length;ze++)te(Re[ze],G);Re.length===2?q(L,_,I):L.projectionMatrix.copy(_.projectionMatrix),re(Z,L,G)};function re(Z,ae,se){se===null?Z.matrix.copy(ae.matrixWorld):(Z.matrix.copy(se.matrixWorld),Z.matrix.invert(),Z.matrix.multiply(ae.matrixWorld)),Z.matrix.decompose(Z.position,Z.quaternion,Z.scale),Z.updateMatrixWorld(!0),Z.projectionMatrix.copy(ae.projectionMatrix),Z.projectionMatrixInverse.copy(ae.projectionMatrixInverse),Z.isPerspectiveCamera&&(Z.fov=oc*2*Math.atan(1/Z.projectionMatrix.elements[5]),Z.zoom=1)}this.getCamera=function(){return L},this.getFoveation=function(){if(!(u===null&&f===null))return l},this.setFoveation=function(Z){l=Z,u!==null&&(u.fixedFoveation=Z),f!==null&&f.fixedFoveation!==void 0&&(f.fixedFoveation=Z)},this.hasDepthSensing=function(){return m.texture!==null},this.getDepthSensingMesh=function(){return m.getMesh(L)},this.getCameraTexture=function(Z){return v[Z]};let Ge=null;function ft(Z,ae){if(h=ae.getViewerPose(c||r),p=ae,h!==null){const se=h.views;f!==null&&(e.setRenderTargetFramebuffer(y,f.framebuffer),e.setRenderTarget(y));let G=!1;se.length!==L.cameras.length&&(L.cameras.length=0,G=!0);for(let Ae=0;Ae<se.length;Ae++){const We=se[Ae];let Xe=null;if(f!==null)Xe=f.getViewport(We);else{const zt=d.getViewSubImage(u,We);Xe=zt.viewport,Ae===0&&(e.setRenderTargetTextures(y,zt.colorTexture,zt.depthStencilTexture),e.setRenderTarget(y))}let $e=R[Ae];$e===void 0&&($e=new Qn,$e.layers.enable(Ae),$e.viewport=new wt,R[Ae]=$e),$e.matrix.fromArray(We.transform.matrix),$e.matrix.decompose($e.position,$e.quaternion,$e.scale),$e.projectionMatrix.fromArray(We.projectionMatrix),$e.projectionMatrixInverse.copy($e.projectionMatrix).invert(),$e.viewport.set(Xe.x,Xe.y,Xe.width,Xe.height),Ae===0&&(L.matrix.copy($e.matrix),L.matrix.decompose(L.position,L.quaternion,L.scale)),G===!0&&L.cameras.push($e)}const Re=n.enabledFeatures;if(Re&&Re.includes("depth-sensing")&&n.depthUsage=="gpu-optimized"&&g){d=i.getBinding();const Ae=d.getDepthInformation(se[0]);Ae&&Ae.isValid&&Ae.texture&&m.init(Ae,n.renderState)}if(Re&&Re.includes("camera-access")&&g){e.state.unbindTexture(),d=i.getBinding();for(let Ae=0;Ae<se.length;Ae++){const We=se[Ae].camera;if(We){let Xe=v[We];Xe||(Xe=new gw,v[We]=Xe);const $e=d.getCameraImage(We);Xe.sourceTexture=$e}}}}for(let se=0;se<w.length;se++){const G=S[se],Re=w[se];G!==null&&Re!==void 0&&Re.update(G,ae,c||r)}Ge&&Ge(Z,ae),ae.detectedPlanes&&i.dispatchEvent({type:"planesdetected",data:ae}),p=null}const it=new Aw;it.setAnimationLoop(ft),this.setAnimationLoop=function(Z){Ge=Z},this.dispose=function(){}}}const fD=new lt,Cw=new Je;Cw.set(-1,0,0,0,1,0,0,0,1);function pD(o,e){function t(m,v){m.matrixAutoUpdate===!0&&m.updateMatrix(),v.value.copy(m.matrix)}function i(m,v){v.color.getRGB(m.fogColor.value,vw(o)),v.isFog?(m.fogNear.value=v.near,m.fogFar.value=v.far):v.isFogExp2&&(m.fogDensity.value=v.density)}function n(m,v,b,x,y){v.isNodeMaterial?v.uniformsNeedUpdate=!1:v.isMeshBasicMaterial?s(m,v):v.isMeshLambertMaterial?(s(m,v),v.envMap&&(m.envMapIntensity.value=v.envMapIntensity)):v.isMeshToonMaterial?(s(m,v),d(m,v)):v.isMeshPhongMaterial?(s(m,v),h(m,v),v.envMap&&(m.envMapIntensity.value=v.envMapIntensity)):v.isMeshStandardMaterial?(s(m,v),u(m,v),v.isMeshPhysicalMaterial&&f(m,v,y)):v.isMeshMatcapMaterial?(s(m,v),p(m,v)):v.isMeshDepthMaterial?s(m,v):v.isMeshDistanceMaterial?(s(m,v),g(m,v)):v.isMeshNormalMaterial?s(m,v):v.isLineBasicMaterial?(r(m,v),v.isLineDashedMaterial&&a(m,v)):v.isPointsMaterial?l(m,v,b,x):v.isSpriteMaterial?c(m,v):v.isShadowMaterial?(m.color.value.copy(v.color),m.opacity.value=v.opacity):v.isShaderMaterial&&(v.uniformsNeedUpdate=!1)}function s(m,v){m.opacity.value=v.opacity,v.color&&m.diffuse.value.copy(v.color),v.emissive&&m.emissive.value.copy(v.emissive).multiplyScalar(v.emissiveIntensity),v.map&&(m.map.value=v.map,t(v.map,m.mapTransform)),v.alphaMap&&(m.alphaMap.value=v.alphaMap,t(v.alphaMap,m.alphaMapTransform)),v.bumpMap&&(m.bumpMap.value=v.bumpMap,t(v.bumpMap,m.bumpMapTransform),m.bumpScale.value=v.bumpScale,v.side===fi&&(m.bumpScale.value*=-1)),v.normalMap&&(m.normalMap.value=v.normalMap,t(v.normalMap,m.normalMapTransform),m.normalScale.value.copy(v.normalScale),v.side===fi&&m.normalScale.value.negate()),v.displacementMap&&(m.displacementMap.value=v.displacementMap,t(v.displacementMap,m.displacementMapTransform),m.displacementScale.value=v.displacementScale,m.displacementBias.value=v.displacementBias),v.emissiveMap&&(m.emissiveMap.value=v.emissiveMap,t(v.emissiveMap,m.emissiveMapTransform)),v.specularMap&&(m.specularMap.value=v.specularMap,t(v.specularMap,m.specularMapTransform)),v.alphaTest>0&&(m.alphaTest.value=v.alphaTest);const b=e.get(v),x=b.envMap,y=b.envMapRotation;x&&(m.envMap.value=x,m.envMapRotation.value.setFromMatrix4(fD.makeRotationFromEuler(y)).transpose(),x.isCubeTexture&&x.isRenderTargetTexture===!1&&m.envMapRotation.value.premultiply(Cw),m.reflectivity.value=v.reflectivity,m.ior.value=v.ior,m.refractionRatio.value=v.refractionRatio),v.lightMap&&(m.lightMap.value=v.lightMap,m.lightMapIntensity.value=v.lightMapIntensity,t(v.lightMap,m.lightMapTransform)),v.aoMap&&(m.aoMap.value=v.aoMap,m.aoMapIntensity.value=v.aoMapIntensity,t(v.aoMap,m.aoMapTransform))}function r(m,v){m.diffuse.value.copy(v.color),m.opacity.value=v.opacity,v.map&&(m.map.value=v.map,t(v.map,m.mapTransform))}function a(m,v){m.dashSize.value=v.dashSize,m.totalSize.value=v.dashSize+v.gapSize,m.scale.value=v.scale}function l(m,v,b,x){m.diffuse.value.copy(v.color),m.opacity.value=v.opacity,m.size.value=v.size*b,m.scale.value=x*.5,v.map&&(m.map.value=v.map,t(v.map,m.uvTransform)),v.alphaMap&&(m.alphaMap.value=v.alphaMap,t(v.alphaMap,m.alphaMapTransform)),v.alphaTest>0&&(m.alphaTest.value=v.alphaTest)}function c(m,v){m.diffuse.value.copy(v.color),m.opacity.value=v.opacity,m.rotation.value=v.rotation,v.map&&(m.map.value=v.map,t(v.map,m.mapTransform)),v.alphaMap&&(m.alphaMap.value=v.alphaMap,t(v.alphaMap,m.alphaMapTransform)),v.alphaTest>0&&(m.alphaTest.value=v.alphaTest)}function h(m,v){m.specular.value.copy(v.specular),m.shininess.value=Math.max(v.shininess,1e-4)}function d(m,v){v.gradientMap&&(m.gradientMap.value=v.gradientMap)}function u(m,v){m.metalness.value=v.metalness,v.metalnessMap&&(m.metalnessMap.value=v.metalnessMap,t(v.metalnessMap,m.metalnessMapTransform)),m.roughness.value=v.roughness,v.roughnessMap&&(m.roughnessMap.value=v.roughnessMap,t(v.roughnessMap,m.roughnessMapTransform)),v.envMap&&(m.envMapIntensity.value=v.envMapIntensity)}function f(m,v,b){m.ior.value=v.ior,v.sheen>0&&(m.sheenColor.value.copy(v.sheenColor).multiplyScalar(v.sheen),m.sheenRoughness.value=v.sheenRoughness,v.sheenColorMap&&(m.sheenColorMap.value=v.sheenColorMap,t(v.sheenColorMap,m.sheenColorMapTransform)),v.sheenRoughnessMap&&(m.sheenRoughnessMap.value=v.sheenRoughnessMap,t(v.sheenRoughnessMap,m.sheenRoughnessMapTransform))),v.clearcoat>0&&(m.clearcoat.value=v.clearcoat,m.clearcoatRoughness.value=v.clearcoatRoughness,v.clearcoatMap&&(m.clearcoatMap.value=v.clearcoatMap,t(v.clearcoatMap,m.clearcoatMapTransform)),v.clearcoatRoughnessMap&&(m.clearcoatRoughnessMap.value=v.clearcoatRoughnessMap,t(v.clearcoatRoughnessMap,m.clearcoatRoughnessMapTransform)),v.clearcoatNormalMap&&(m.clearcoatNormalMap.value=v.clearcoatNormalMap,t(v.clearcoatNormalMap,m.clearcoatNormalMapTransform),m.clearcoatNormalScale.value.copy(v.clearcoatNormalScale),v.side===fi&&m.clearcoatNormalScale.value.negate())),v.dispersion>0&&(m.dispersion.value=v.dispersion),v.iridescence>0&&(m.iridescence.value=v.iridescence,m.iridescenceIOR.value=v.iridescenceIOR,m.iridescenceThicknessMinimum.value=v.iridescenceThicknessRange[0],m.iridescenceThicknessMaximum.value=v.iridescenceThicknessRange[1],v.iridescenceMap&&(m.iridescenceMap.value=v.iridescenceMap,t(v.iridescenceMap,m.iridescenceMapTransform)),v.iridescenceThicknessMap&&(m.iridescenceThicknessMap.value=v.iridescenceThicknessMap,t(v.iridescenceThicknessMap,m.iridescenceThicknessMapTransform))),v.transmission>0&&(m.transmission.value=v.transmission,m.transmissionSamplerMap.value=b.texture,m.transmissionSamplerSize.value.set(b.width,b.height),v.transmissionMap&&(m.transmissionMap.value=v.transmissionMap,t(v.transmissionMap,m.transmissionMapTransform)),m.thickness.value=v.thickness,v.thicknessMap&&(m.thicknessMap.value=v.thicknessMap,t(v.thicknessMap,m.thicknessMapTransform)),m.attenuationDistance.value=v.attenuationDistance,m.attenuationColor.value.copy(v.attenuationColor)),v.anisotropy>0&&(m.anisotropyVector.value.set(v.anisotropy*Math.cos(v.anisotropyRotation),v.anisotropy*Math.sin(v.anisotropyRotation)),v.anisotropyMap&&(m.anisotropyMap.value=v.anisotropyMap,t(v.anisotropyMap,m.anisotropyMapTransform))),m.specularIntensity.value=v.specularIntensity,m.specularColor.value.copy(v.specularColor),v.specularColorMap&&(m.specularColorMap.value=v.specularColorMap,t(v.specularColorMap,m.specularColorMapTransform)),v.specularIntensityMap&&(m.specularIntensityMap.value=v.specularIntensityMap,t(v.specularIntensityMap,m.specularIntensityMapTransform))}function p(m,v){v.matcap&&(m.matcap.value=v.matcap)}function g(m,v){const b=e.get(v).light;m.referencePosition.value.setFromMatrixPosition(b.matrixWorld),m.nearDistance.value=b.shadow.camera.near,m.farDistance.value=b.shadow.camera.far}return{refreshFogUniforms:i,refreshMaterialUniforms:n}}function mD(o,e,t,i){let n={},s={},r=[];const a=o.getParameter(o.MAX_UNIFORM_BUFFER_BINDINGS);function l(y,w){const S=w.program;i.uniformBlockBinding(y,S)}function c(y,w){let S=n[y.id];S===void 0&&(m(y),S=h(y),n[y.id]=S,y.addEventListener("dispose",b));const A=w.program;i.updateUBOMapping(y,A);const M=e.render.frame;s[y.id]!==M&&(u(y),s[y.id]=M)}function h(y){const w=d();y.__bindingPointIndex=w;const S=o.createBuffer(),A=y.__size,M=y.usage;return o.bindBuffer(o.UNIFORM_BUFFER,S),o.bufferData(o.UNIFORM_BUFFER,A,M),o.bindBuffer(o.UNIFORM_BUFFER,null),o.bindBufferBase(o.UNIFORM_BUFFER,w,S),S}function d(){for(let y=0;y<a;y++)if(r.indexOf(y)===-1)return r.push(y),y;return je("WebGLRenderer: Maximum number of simultaneously usable uniforms groups reached."),0}function u(y){const w=n[y.id],S=y.uniforms,A=y.__cache;o.bindBuffer(o.UNIFORM_BUFFER,w);for(let M=0,_=S.length;M<_;M++){const I=S[M];if(Array.isArray(I))for(let R=0,L=I.length;R<L;R++)f(I[R],M,R,A);else f(I,M,0,A)}o.bindBuffer(o.UNIFORM_BUFFER,null)}function f(y,w,S,A){if(g(y,w,S,A)===!0){const M=y.__offset,_=y.value;if(Array.isArray(_)){let I=0;for(let R=0;R<_.length;R++){const L=_[R],P=v(L);p(L,y.__data,I),typeof L!="number"&&typeof L!="boolean"&&!L.isMatrix3&&!ArrayBuffer.isView(L)&&(I+=P.storage/Float32Array.BYTES_PER_ELEMENT)}}else p(_,y.__data,0);o.bufferSubData(o.UNIFORM_BUFFER,M,y.__data)}}function p(y,w,S){typeof y=="number"||typeof y=="boolean"?w[0]=y:y.isMatrix3?(w[0]=y.elements[0],w[1]=y.elements[1],w[2]=y.elements[2],w[3]=0,w[4]=y.elements[3],w[5]=y.elements[4],w[6]=y.elements[5],w[7]=0,w[8]=y.elements[6],w[9]=y.elements[7],w[10]=y.elements[8],w[11]=0):ArrayBuffer.isView(y)?w.set(new y.constructor(y.buffer,y.byteOffset,w.length)):y.toArray(w,S)}function g(y,w,S,A){const M=y.value,_=w+"_"+S;if(A[_]===void 0)return typeof M=="number"||typeof M=="boolean"?A[_]=M:ArrayBuffer.isView(M)?A[_]=M.slice():A[_]=M.clone(),!0;{const I=A[_];if(typeof M=="number"||typeof M=="boolean"){if(I!==M)return A[_]=M,!0}else{if(ArrayBuffer.isView(M))return!0;if(I.equals(M)===!1)return I.copy(M),!0}}return!1}function m(y){const w=y.uniforms;let S=0;const A=16;for(let _=0,I=w.length;_<I;_++){const R=Array.isArray(w[_])?w[_]:[w[_]];for(let L=0,P=R.length;L<P;L++){const O=R[L],k=Array.isArray(O.value)?O.value:[O.value];for(let F=0,z=k.length;F<z;F++){const V=k[F],K=v(V),q=S%A,te=q%K.boundary,re=q+te;S+=te,re!==0&&A-re<K.storage&&(S+=A-re),O.__data=new Float32Array(K.storage/Float32Array.BYTES_PER_ELEMENT),O.__offset=S,S+=K.storage}}}const M=S%A;return M>0&&(S+=A-M),y.__size=S,y.__cache={},this}function v(y){const w={boundary:0,storage:0};return typeof y=="number"||typeof y=="boolean"?(w.boundary=4,w.storage=4):y.isVector2?(w.boundary=8,w.storage=8):y.isVector3||y.isColor?(w.boundary=16,w.storage=12):y.isVector4?(w.boundary=16,w.storage=16):y.isMatrix3?(w.boundary=48,w.storage=48):y.isMatrix4?(w.boundary=64,w.storage=64):y.isTexture?ke("WebGLRenderer: Texture samplers can not be part of an uniforms group."):ArrayBuffer.isView(y)?(w.boundary=16,w.storage=y.byteLength):ke("WebGLRenderer: Unsupported uniform value type.",y),w}function b(y){const w=y.target;w.removeEventListener("dispose",b);const S=r.indexOf(w.__bindingPointIndex);r.splice(S,1),o.deleteBuffer(n[w.id]),delete n[w.id],delete s[w.id]}function x(){for(const y in n)o.deleteBuffer(n[y]);r=[],n={},s={}}return{bind:l,update:c,dispose:x}}const gD=new Uint16Array([12469,15057,12620,14925,13266,14620,13807,14376,14323,13990,14545,13625,14713,13328,14840,12882,14931,12528,14996,12233,15039,11829,15066,11525,15080,11295,15085,10976,15082,10705,15073,10495,13880,14564,13898,14542,13977,14430,14158,14124,14393,13732,14556,13410,14702,12996,14814,12596,14891,12291,14937,11834,14957,11489,14958,11194,14943,10803,14921,10506,14893,10278,14858,9960,14484,14039,14487,14025,14499,13941,14524,13740,14574,13468,14654,13106,14743,12678,14818,12344,14867,11893,14889,11509,14893,11180,14881,10751,14852,10428,14812,10128,14765,9754,14712,9466,14764,13480,14764,13475,14766,13440,14766,13347,14769,13070,14786,12713,14816,12387,14844,11957,14860,11549,14868,11215,14855,10751,14825,10403,14782,10044,14729,9651,14666,9352,14599,9029,14967,12835,14966,12831,14963,12804,14954,12723,14936,12564,14917,12347,14900,11958,14886,11569,14878,11247,14859,10765,14828,10401,14784,10011,14727,9600,14660,9289,14586,8893,14508,8533,15111,12234,15110,12234,15104,12216,15092,12156,15067,12010,15028,11776,14981,11500,14942,11205,14902,10752,14861,10393,14812,9991,14752,9570,14682,9252,14603,8808,14519,8445,14431,8145,15209,11449,15208,11451,15202,11451,15190,11438,15163,11384,15117,11274,15055,10979,14994,10648,14932,10343,14871,9936,14803,9532,14729,9218,14645,8742,14556,8381,14461,8020,14365,7603,15273,10603,15272,10607,15267,10619,15256,10631,15231,10614,15182,10535,15118,10389,15042,10167,14963,9787,14883,9447,14800,9115,14710,8665,14615,8318,14514,7911,14411,7507,14279,7198,15314,9675,15313,9683,15309,9712,15298,9759,15277,9797,15229,9773,15166,9668,15084,9487,14995,9274,14898,8910,14800,8539,14697,8234,14590,7790,14479,7409,14367,7067,14178,6621,15337,8619,15337,8631,15333,8677,15325,8769,15305,8871,15264,8940,15202,8909,15119,8775,15022,8565,14916,8328,14804,8009,14688,7614,14569,7287,14448,6888,14321,6483,14088,6171,15350,7402,15350,7419,15347,7480,15340,7613,15322,7804,15287,7973,15229,8057,15148,8012,15046,7846,14933,7611,14810,7357,14682,7069,14552,6656,14421,6316,14251,5948,14007,5528,15356,5942,15356,5977,15353,6119,15348,6294,15332,6551,15302,6824,15249,7044,15171,7122,15070,7050,14949,6861,14818,6611,14679,6349,14538,6067,14398,5651,14189,5311,13935,4958,15359,4123,15359,4153,15356,4296,15353,4646,15338,5160,15311,5508,15263,5829,15188,6042,15088,6094,14966,6001,14826,5796,14678,5543,14527,5287,14377,4985,14133,4586,13869,4257,15360,1563,15360,1642,15358,2076,15354,2636,15341,3350,15317,4019,15273,4429,15203,4732,15105,4911,14981,4932,14836,4818,14679,4621,14517,4386,14359,4156,14083,3795,13808,3437,15360,122,15360,137,15358,285,15355,636,15344,1274,15322,2177,15281,2765,15215,3223,15120,3451,14995,3569,14846,3567,14681,3466,14511,3305,14344,3121,14037,2800,13753,2467,15360,0,15360,1,15359,21,15355,89,15346,253,15325,479,15287,796,15225,1148,15133,1492,15008,1749,14856,1882,14685,1886,14506,1783,14324,1608,13996,1398,13702,1183]);let Qs=null;function vD(){return Qs===null&&(Qs=new ps(gD,16,16,Fo,ci),Qs.name="DFG_LUT",Qs.minFilter=mt,Qs.magFilter=mt,Qs.wrapS=Ti,Qs.wrapT=Ti,Qs.generateMipmaps=!1,Qs.needsUpdate=!0),Qs}class yD{constructor(e={}){const{canvas:t=WE(),context:i=null,depth:n=!0,stencil:s=!1,alpha:r=!1,antialias:a=!1,premultipliedAlpha:l=!0,preserveDrawingBuffer:c=!1,powerPreference:h="default",failIfMajorPerformanceCaveat:d=!1,reversedDepthBuffer:u=!1,outputBufferType:f=zn}=e;this.isWebGLRenderer=!0;let p;if(i!==null){if(typeof WebGLRenderingContext<"u"&&i instanceof WebGLRenderingContext)throw new Error("THREE.WebGLRenderer: WebGL 1 is not supported since r163.");p=i.getContextAttributes().alpha}else p=r;const g=f,m=new Set([fg,ug,dg]),v=new Set([zn,Ts,Mh,wh,cg,hg]),b=new Uint32Array(4),x=new Int32Array(4),y=new D;let w=null,S=null;const A=[],M=[];let _=null;this.domElement=t,this.debug={checkShaderErrors:!0,onShaderError:null},this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.sortObjects=!0,this.clippingPlanes=[],this.localClippingEnabled=!1,this.toneMapping=Mr,this.toneMappingExposure=1,this.transmissionResolutionScale=1;const I=this;let R=!1,L=null,P=null,O=null,k=null;this._outputColorSpace=an;let F=0,z=0,V=null,K=-1,q=null;const te=new wt,re=new wt;let Ge=null;const ft=new ne(0);let it=0,Z=t.width,ae=t.height,se=1,G=null,Re=null;const ze=new wt(0,0,Z,ae),Le=new wt(0,0,Z,ae);let Ae=!1;const We=new xg;let Xe=!1,$e=!1;const zt=new lt,Ht=new D,wi=new wt,pi={background:null,fog:null,environment:null,overrideMaterial:null,isScene:!0};let xi=!1;function Ui(){return V===null?se:1}let U=i;function Vn(T,B){return t.getContext(T,B)}try{const T={alpha:!0,depth:n,stencil:s,antialias:a,premultipliedAlpha:l,preserveDrawingBuffer:c,powerPreference:h,failIfMajorPerformanceCaveat:d};if("setAttribute"in t&&t.setAttribute("data-engine",`three.js r${ag}`),t.addEventListener("webglcontextlost",Si,!1),t.addEventListener("webglcontextrestored",ri,!1),t.addEventListener("webglcontextcreationerror",qs,!1),U===null){const B="webgl2";if(U=Vn(B,T),U===null)throw Vn(B)?new Error("THREE.WebGLRenderer: Error creating WebGL context with your selected attributes."):new Error("THREE.WebGLRenderer: Error creating WebGL context.")}}catch(T){throw je("WebGLRenderer: "+T.message),T}let Gt,C,E,H,$,j,le,ue,J,ee,fe,Oe,ve,pe,Ve,Ke,ct,N,he,Q,me,xe,ie;function Pe(){Gt=new v5(U),Gt.init(),me=new lD(U,Gt),C=new c5(U,Gt,e,me),E=new aD(U,Gt),C.reversedDepthBuffer&&u&&E.buffers.depth.setReversed(!0),P=U.createFramebuffer(),O=U.createFramebuffer(),k=U.createFramebuffer(),H=new M5(U),$=new $I,j=new oD(U,Gt,E,$,C,me,H),le=new g5(I),ue=new EA(U),xe=new o5(U,ue),J=new y5(U,ue,H,xe),ee=new x5(U,J,ue,xe,H),N=new w5(U,C,j),Ve=new h5($),fe=new XI(I,le,Gt,C,xe,Ve),Oe=new pD(I,$),ve=new qI,pe=new eD(Gt),ct=new a5(I,le,E,ee,p,l),Ke=new rD(I,ee,C),ie=new mD(U,H,C,E),he=new l5(U,Gt,H),Q=new b5(U,Gt,H),H.programs=fe.programs,I.capabilities=C,I.extensions=Gt,I.properties=$,I.renderLists=ve,I.shadowMap=Ke,I.state=E,I.info=H}Pe(),g!==zn&&(_=new E5(g,t.width,t.height,a,n,s));const Te=new uD(I,U);this.xr=Te,this.getContext=function(){return U},this.getContextAttributes=function(){return U.getContextAttributes()},this.forceContextLoss=function(){const T=Gt.get("WEBGL_lose_context");T&&T.loseContext()},this.forceContextRestore=function(){const T=Gt.get("WEBGL_lose_context");T&&T.restoreContext()},this.getPixelRatio=function(){return se},this.setPixelRatio=function(T){T!==void 0&&(se=T,this.setSize(Z,ae,!1))},this.getSize=function(T){return T.set(Z,ae)},this.setSize=function(T,B,Y=!0){if(Te.isPresenting){ke("WebGLRenderer: Can't change size while VR device is presenting.");return}Z=T,ae=B,t.width=Math.floor(T*se),t.height=Math.floor(B*se),Y===!0&&(t.style.width=T+"px",t.style.height=B+"px"),_!==null&&_.setSize(t.width,t.height),this.setViewport(0,0,T,B)},this.getDrawingBufferSize=function(T){return T.set(Z*se,ae*se).floor()},this.setDrawingBufferSize=function(T,B,Y){Z=T,ae=B,se=Y,t.width=Math.floor(T*Y),t.height=Math.floor(B*Y),this.setViewport(0,0,T,B)},this.setEffects=function(T){if(g===zn){je("WebGLRenderer: setEffects() requires outputBufferType set to HalfFloatType or FloatType.");return}if(T){for(let B=0;B<T.length;B++)if(T[B].isOutputPass===!0){ke("WebGLRenderer: OutputPass is not needed in setEffects(). Tone mapping and color space conversion are applied automatically.");break}}_.setEffects(T||[])},this.getCurrentViewport=function(T){return T.copy(te)},this.getViewport=function(T){return T.copy(ze)},this.setViewport=function(T,B,Y,W){T.isVector4?ze.set(T.x,T.y,T.z,T.w):ze.set(T,B,Y,W),E.viewport(te.copy(ze).multiplyScalar(se).round())},this.getScissor=function(T){return T.copy(Le)},this.setScissor=function(T,B,Y,W){T.isVector4?Le.set(T.x,T.y,T.z,T.w):Le.set(T,B,Y,W),E.scissor(re.copy(Le).multiplyScalar(se).round())},this.getScissorTest=function(){return Ae},this.setScissorTest=function(T){E.setScissorTest(Ae=T)},this.setOpaqueSort=function(T){G=T},this.setTransparentSort=function(T){Re=T},this.getClearColor=function(T){return T.copy(ct.getClearColor())},this.setClearColor=function(){ct.setClearColor(...arguments)},this.getClearAlpha=function(){return ct.getClearAlpha()},this.setClearAlpha=function(){ct.setClearAlpha(...arguments)},this.clear=function(T=!0,B=!0,Y=!0){let W=0;if(T){let X=!1;if(V!==null){const Me=V.texture.format;X=m.has(Me)}if(X){const Me=V.texture.type,_e=v.has(Me),be=ct.getClearColor(),De=ct.getClearAlpha(),Ne=be.r,ht=be.g,gt=be.b;_e?(b[0]=Ne,b[1]=ht,b[2]=gt,b[3]=De,U.clearBufferuiv(U.COLOR,0,b)):(x[0]=Ne,x[1]=ht,x[2]=gt,x[3]=De,U.clearBufferiv(U.COLOR,0,x))}else W|=U.COLOR_BUFFER_BIT}B&&(W|=U.DEPTH_BUFFER_BIT,this.state.buffers.depth.setMask(!0)),Y&&(W|=U.STENCIL_BUFFER_BIT,this.state.buffers.stencil.setMask(4294967295)),W!==0&&U.clear(W)},this.clearColor=function(){this.clear(!0,!1,!1)},this.clearDepth=function(){this.clear(!1,!0,!1)},this.clearStencil=function(){this.clear(!1,!1,!0)},this.setNodesHandler=function(T){T.setRenderer(this),L=T},this.dispose=function(){t.removeEventListener("webglcontextlost",Si,!1),t.removeEventListener("webglcontextrestored",ri,!1),t.removeEventListener("webglcontextcreationerror",qs,!1),ct.dispose(),ve.dispose(),pe.dispose(),$.dispose(),le.dispose(),ee.dispose(),xe.dispose(),ie.dispose(),fe.dispose(),Te.dispose(),Te.removeEventListener("sessionstart",jg),Te.removeEventListener("sessionend",Jg),Fa.stop()};function Si(T){T.preventDefault(),Xu("WebGLRenderer: Context Lost."),R=!0}function ri(){Xu("WebGLRenderer: Context Restored."),R=!1;const T=H.autoReset,B=Ke.enabled,Y=Ke.autoUpdate,W=Ke.needsUpdate,X=Ke.type;Pe(),H.autoReset=T,Ke.enabled=B,Ke.autoUpdate=Y,Ke.needsUpdate=W,Ke.type=X}function qs(T){je("WebGLRenderer: A WebGL context could not be created. Reason: ",T.statusMessage)}function Ks(T){const B=T.target;B.removeEventListener("dispose",Ks),T2(B)}function T2(T){I2(T),$.remove(T)}function I2(T){const B=$.get(T).programs;B!==void 0&&(B.forEach(function(Y){fe.releaseProgram(Y)}),T.isShaderMaterial&&fe.releaseShaderCache(T))}this.renderBufferDirect=function(T,B,Y,W,X,Me){B===null&&(B=pi);const _e=X.isMesh&&X.matrixWorld.determinantAffine()<0,be=C2(T,B,Y,W,X);E.setMaterial(W,_e);let De=Y.index,Ne=1;if(W.wireframe===!0){if(De=J.getWireframeAttribute(Y),De===void 0)return;Ne=2}const ht=Y.drawRange,gt=Y.attributes.position;let Be=ht.start*Ne,jt=(ht.start+ht.count)*Ne;Me!==null&&(Be=Math.max(Be,Me.start*Ne),jt=Math.min(jt,(Me.start+Me.count)*Ne)),De!==null?(Be=Math.max(Be,0),jt=Math.min(jt,De.count)):gt!=null&&(Be=Math.max(Be,0),jt=Math.min(jt,gt.count));const Di=jt-Be;if(Di<0||Di===1/0)return;xe.setup(X,W,be,Y,De);let Ei,ei=he;if(De!==null&&(Ei=ue.get(De),ei=Q,ei.setIndex(Ei)),X.isMesh)W.wireframe===!0?(E.setLineWidth(W.wireframeLinewidth*Ui()),ei.setMode(U.LINES)):ei.setMode(U.TRIANGLES);else if(X.isLine){let un=W.linewidth;un===void 0&&(un=1),E.setLineWidth(un*Ui()),X.isLineSegments?ei.setMode(U.LINES):X.isLineLoop?ei.setMode(U.LINE_LOOP):ei.setMode(U.LINE_STRIP)}else X.isPoints?ei.setMode(U.POINTS):X.isSprite&&ei.setMode(U.TRIANGLES);if(X.isBatchedMesh)if(Gt.get("WEBGL_multi_draw"))ei.renderMultiDraw(X._multiDrawStarts,X._multiDrawCounts,X._multiDrawCount);else{const un=X._multiDrawStarts,Ee=X._multiDrawCounts,ts=X._multiDrawCount,Rt=De?ue.get(De).bytesPerElement:1,gs=$.get(W).currentProgram.getUniforms();for(let Zs=0;Zs<ts;Zs++)gs.setValue(U,"_gl_DrawID",Zs),ei.render(un[Zs]/Rt,Ee[Zs])}else if(X.isInstancedMesh)ei.renderInstances(Be,Di,X.count);else if(Y.isInstancedBufferGeometry){const un=Y._maxInstanceCount!==void 0?Y._maxInstanceCount:1/0,Ee=Math.min(Y.instanceCount,un);ei.renderInstances(Be,Di,Ee)}else ei.render(Be,Di)};function Zg(T,B,Y){T.transparent===!0&&T.side===Bn&&T.forceSinglePass===!1?(T.side=fi,T.needsUpdate=!0,Fh(T,B,Y),T.side=Pa,T.needsUpdate=!0,Fh(T,B,Y),T.side=Bn):Fh(T,B,Y)}this.compile=function(T,B,Y=null){Y===null&&(Y=T),S=pe.get(Y),S.init(B),M.push(S),Y.traverseVisible(function(X){X.isLight&&X.layers.test(B.layers)&&(S.pushLight(X),X.castShadow&&S.pushShadow(X))}),T!==Y&&T.traverseVisible(function(X){X.isLight&&X.layers.test(B.layers)&&(S.pushLight(X),X.castShadow&&S.pushShadow(X))}),S.setupLights();const W=new Set;return T.traverse(function(X){if(!(X.isMesh||X.isPoints||X.isLine||X.isSprite))return;const Me=X.material;if(Me)if(Array.isArray(Me))for(let _e=0;_e<Me.length;_e++){const be=Me[_e];Zg(be,Y,X),W.add(be)}else Zg(Me,Y,X),W.add(Me)}),S=M.pop(),W},this.compileAsync=function(T,B,Y=null){const W=this.compile(T,B,Y);return new Promise(X=>{function Me(){if(W.forEach(function(_e){$.get(_e).currentProgram.isReady()&&W.delete(_e)}),W.size===0){X(T);return}setTimeout(Me,10)}Gt.get("KHR_parallel_shader_compile")!==null?Me():setTimeout(Me,10)})};let Ff=null;function D2(T){Ff&&Ff(T)}function jg(){Fa.stop()}function Jg(){Fa.start()}const Fa=new Aw;Fa.setAnimationLoop(D2),typeof self<"u"&&Fa.setContext(self),this.setAnimationLoop=function(T){Ff=T,Te.setAnimationLoop(T),T===null?Fa.stop():Fa.start()},Te.addEventListener("sessionstart",jg),Te.addEventListener("sessionend",Jg),this.render=function(T,B){if(B!==void 0&&B.isCamera!==!0){je("WebGLRenderer.render: camera is not an instance of THREE.Camera.");return}if(R===!0)return;L!==null&&L.renderStart(T,B);const Y=Te.enabled===!0&&Te.isPresenting===!0,W=_!==null&&(V===null||Y)&&_.begin(I,V);if(T.matrixWorldAutoUpdate===!0&&T.updateMatrixWorld(),B.parent===null&&B.matrixWorldAutoUpdate===!0&&B.updateMatrixWorld(),Te.enabled===!0&&Te.isPresenting===!0&&(_===null||_.isCompositing()===!1)&&(Te.cameraAutoUpdate===!0&&Te.updateCamera(B),B=Te.getCamera()),T.isScene===!0&&T.onBeforeRender(I,T,B,V),S=pe.get(T,M.length),S.init(B),S.state.textureUnits=j.getTextureUnits(),M.push(S),zt.multiplyMatrices(B.projectionMatrix,B.matrixWorldInverse),We.setFromProjectionMatrix(zt,vr,B.reversedDepth),$e=this.localClippingEnabled,Xe=Ve.init(this.clippingPlanes,$e),w=ve.get(T,A.length),w.init(),A.push(w),Te.enabled===!0&&Te.isPresenting===!0){const _e=I.xr.getDepthSensingMesh();_e!==null&&Uf(_e,B,-1/0,I.sortObjects)}Uf(T,B,0,I.sortObjects),w.finish(),I.sortObjects===!0&&w.sort(G,Re,B.reversedDepth),xi=Te.enabled===!1||Te.isPresenting===!1||Te.hasDepthSensing()===!1,xi&&ct.addToRenderList(w,T),this.info.render.frame++,this.info.autoReset===!0&&this.info.reset(),Xe===!0&&Ve.beginShadows();const X=S.state.shadowsArray;if(Ke.render(X,T,B),Xe===!0&&Ve.endShadows(),(W&&_.hasRenderPass())===!1){const _e=w.opaque,be=w.transmissive;if(S.setupLights(),B.isArrayCamera){const De=B.cameras;if(be.length>0)for(let Ne=0,ht=De.length;Ne<ht;Ne++){const gt=De[Ne];ev(_e,be,T,gt)}xi&&ct.render(T);for(let Ne=0,ht=De.length;Ne<ht;Ne++){const gt=De[Ne];Qg(w,T,gt,gt.viewport)}}else be.length>0&&ev(_e,be,T,B),xi&&ct.render(T),Qg(w,T,B)}V!==null&&z===0&&(j.updateMultisampleRenderTarget(V),j.updateRenderTargetMipmap(V)),W&&_.end(I),T.isScene===!0&&T.onAfterRender(I,T,B),xe.resetDefaultState(),K=-1,q=null,M.pop(),M.length>0?(S=M[M.length-1],j.setTextureUnits(S.state.textureUnits),Xe===!0&&Ve.setGlobalState(I.clippingPlanes,S.state.camera)):S=null,A.pop(),A.length>0?w=A[A.length-1]:w=null,L!==null&&L.renderEnd()};function Uf(T,B,Y,W){if(T.visible===!1)return;if(T.layers.test(B.layers)){if(T.isGroup)Y=T.renderOrder;else if(T.isLOD)T.autoUpdate===!0&&T.update(B);else if(T.isLightProbeGrid)S.pushLightProbeGrid(T);else if(T.isLight)S.pushLight(T),T.castShadow&&S.pushShadow(T);else if(T.isSprite){if(!T.frustumCulled||We.intersectsSprite(T)){W&&wi.setFromMatrixPosition(T.matrixWorld).applyMatrix4(zt);const _e=ee.update(T),be=T.material;be.visible&&w.push(T,_e,be,Y,wi.z,null)}}else if((T.isMesh||T.isLine||T.isPoints)&&(!T.frustumCulled||We.intersectsObject(T))){const _e=ee.update(T),be=T.material;if(W&&(T.boundingSphere!==void 0?(T.boundingSphere===null&&T.computeBoundingSphere(),wi.copy(T.boundingSphere.center)):(_e.boundingSphere===null&&_e.computeBoundingSphere(),wi.copy(_e.boundingSphere.center)),wi.applyMatrix4(T.matrixWorld).applyMatrix4(zt)),Array.isArray(be)){const De=_e.groups;for(let Ne=0,ht=De.length;Ne<ht;Ne++){const gt=De[Ne],Be=be[gt.materialIndex];Be&&Be.visible&&w.push(T,_e,Be,Y,wi.z,gt)}}else be.visible&&w.push(T,_e,be,Y,wi.z,null)}}const Me=T.children;for(let _e=0,be=Me.length;_e<be;_e++)Uf(Me[_e],B,Y,W)}function Qg(T,B,Y,W){const{opaque:X,transmissive:Me,transparent:_e}=T;S.setupLightsView(Y),Xe===!0&&Ve.setGlobalState(I.clippingPlanes,Y),W&&E.viewport(te.copy(W)),X.length>0&&Nh(X,B,Y),Me.length>0&&Nh(Me,B,Y),_e.length>0&&Nh(_e,B,Y),E.buffers.depth.setTest(!0),E.buffers.depth.setMask(!0),E.buffers.color.setMask(!0),E.setPolygonOffset(!1)}function ev(T,B,Y,W){if((Y.isScene===!0?Y.overrideMaterial:null)!==null)return;if(S.state.transmissionRenderTarget[W.id]===void 0){const Be=Gt.has("EXT_color_buffer_half_float")||Gt.has("EXT_color_buffer_float");S.state.transmissionRenderTarget[W.id]=new Mi(1,1,{generateMipmaps:!0,type:Be?ci:zn,minFilter:gr,samples:Math.max(4,C.samples),stencilBuffer:s,resolveDepthBuffer:!1,resolveStencilBuffer:!1,colorSpace:Tt.workingColorSpace})}const Me=S.state.transmissionRenderTarget[W.id],_e=W.viewport||te;Me.setSize(_e.z*I.transmissionResolutionScale,_e.w*I.transmissionResolutionScale);const be=I.getRenderTarget(),De=I.getActiveCubeFace(),Ne=I.getActiveMipmapLevel();I.setRenderTarget(Me),I.getClearColor(ft),it=I.getClearAlpha(),it<1&&I.setClearColor(16777215,.5),I.clear(),xi&&ct.render(Y);const ht=I.toneMapping;I.toneMapping=Mr;const gt=W.viewport;if(W.viewport!==void 0&&(W.viewport=void 0),S.setupLightsView(W),Xe===!0&&Ve.setGlobalState(I.clippingPlanes,W),Nh(T,Y,W),j.updateMultisampleRenderTarget(Me),j.updateRenderTargetMipmap(Me),Gt.has("WEBGL_multisampled_render_to_texture")===!1){let Be=!1;for(let jt=0,Di=B.length;jt<Di;jt++){const Ei=B[jt],{object:ei,geometry:un,material:Ee,group:ts}=Ei;if(Ee.side===Bn&&ei.layers.test(W.layers)){const Rt=Ee.side;Ee.side=fi,Ee.needsUpdate=!0,tv(ei,Y,W,un,Ee,ts),Ee.side=Rt,Ee.needsUpdate=!0,Be=!0}}Be===!0&&(j.updateMultisampleRenderTarget(Me),j.updateRenderTargetMipmap(Me))}I.setRenderTarget(be,De,Ne),I.setClearColor(ft,it),gt!==void 0&&(W.viewport=gt),I.toneMapping=ht}function Nh(T,B,Y){const W=B.isScene===!0?B.overrideMaterial:null;for(let X=0,Me=T.length;X<Me;X++){const _e=T[X],{object:be,geometry:De,group:Ne}=_e;let ht=_e.material;ht.allowOverride===!0&&W!==null&&(ht=W),be.layers.test(Y.layers)&&tv(be,B,Y,De,ht,Ne)}}function tv(T,B,Y,W,X,Me){T.onBeforeRender(I,B,Y,W,X,Me),T.modelViewMatrix.multiplyMatrices(Y.matrixWorldInverse,T.matrixWorld),T.normalMatrix.getNormalMatrix(T.modelViewMatrix),X.onBeforeRender(I,B,Y,W,T,Me),X.transparent===!0&&X.side===Bn&&X.forceSinglePass===!1?(X.side=fi,X.needsUpdate=!0,I.renderBufferDirect(Y,B,W,X,T,Me),X.side=Pa,X.needsUpdate=!0,I.renderBufferDirect(Y,B,W,X,T,Me),X.side=Bn):I.renderBufferDirect(Y,B,W,X,T,Me),T.onAfterRender(I,B,Y,W,X,Me)}function Fh(T,B,Y){B.isScene!==!0&&(B=pi);const W=$.get(T),X=S.state.lights,Me=S.state.shadowsArray,_e=X.state.version,be=fe.getParameters(T,X.state,Me,B,Y,S.state.lightProbeGridArray),De=fe.getProgramCacheKey(be);let Ne=W.programs;W.environment=T.isMeshStandardMaterial||T.isMeshLambertMaterial||T.isMeshPhongMaterial?B.environment:null,W.fog=B.fog;const ht=T.isMeshStandardMaterial||T.isMeshLambertMaterial&&!T.envMap||T.isMeshPhongMaterial&&!T.envMap;W.envMap=le.get(T.envMap||W.environment,ht),W.envMapRotation=W.environment!==null&&T.envMap===null?B.environmentRotation:T.envMapRotation,Ne===void 0&&(T.addEventListener("dispose",Ks),Ne=new Map,W.programs=Ne);let gt=Ne.get(De);if(gt!==void 0){if(W.currentProgram===gt&&W.lightsStateVersion===_e)return nv(T,be),gt}else be.uniforms=fe.getUniforms(T),L!==null&&T.isNodeMaterial&&L.build(T,Y,be),T.onBeforeCompile(be,I),gt=fe.acquireProgram(be,De),Ne.set(De,gt),W.uniforms=be.uniforms;const Be=W.uniforms;return(!T.isShaderMaterial&&!T.isRawShaderMaterial||T.clipping===!0)&&(Be.clippingPlanes=Ve.uniform),nv(T,be),W.needsLights=P2(T),W.lightsStateVersion=_e,W.needsLights&&(Be.ambientLightColor.value=X.state.ambient,Be.lightProbe.value=X.state.probe,Be.directionalLights.value=X.state.directional,Be.directionalLightShadows.value=X.state.directionalShadow,Be.spotLights.value=X.state.spot,Be.spotLightShadows.value=X.state.spotShadow,Be.rectAreaLights.value=X.state.rectArea,Be.ltc_1.value=X.state.rectAreaLTC1,Be.ltc_2.value=X.state.rectAreaLTC2,Be.pointLights.value=X.state.point,Be.pointLightShadows.value=X.state.pointShadow,Be.hemisphereLights.value=X.state.hemi,Be.directionalShadowMatrix.value=X.state.directionalShadowMatrix,Be.spotLightMatrix.value=X.state.spotLightMatrix,Be.spotLightMap.value=X.state.spotLightMap,Be.pointShadowMatrix.value=X.state.pointShadowMatrix),W.lightProbeGrid=S.state.lightProbeGridArray.length>0,W.currentProgram=gt,W.uniformsList=null,gt}function iv(T){if(T.uniformsList===null){const B=T.currentProgram.getUniforms();T.uniformsList=iu.seqWithValue(B.seq,T.uniforms)}return T.uniformsList}function nv(T,B){const Y=$.get(T);Y.outputColorSpace=B.outputColorSpace,Y.batching=B.batching,Y.batchingColor=B.batchingColor,Y.instancing=B.instancing,Y.instancingColor=B.instancingColor,Y.instancingMorph=B.instancingMorph,Y.skinning=B.skinning,Y.morphTargets=B.morphTargets,Y.morphNormals=B.morphNormals,Y.morphColors=B.morphColors,Y.morphTargetsCount=B.morphTargetsCount,Y.numClippingPlanes=B.numClippingPlanes,Y.numIntersection=B.numClipIntersection,Y.vertexAlphas=B.vertexAlphas,Y.vertexTangents=B.vertexTangents,Y.toneMapping=B.toneMapping}function R2(T,B){if(T.length===0)return null;if(T.length===1)return T[0].texture!==null?T[0]:null;y.setFromMatrixPosition(B.matrixWorld);for(let Y=0,W=T.length;Y<W;Y++){const X=T[Y];if(X.texture!==null&&X.boundingBox.containsPoint(y))return X}return null}function C2(T,B,Y,W,X){B.isScene!==!0&&(B=pi),j.resetTextureUnits();const Me=B.fog,_e=W.isMeshStandardMaterial||W.isMeshLambertMaterial||W.isMeshPhongMaterial?B.environment:null,be=V===null?I.outputColorSpace:V.isXRRenderTarget===!0?V.texture.colorSpace:Tt.workingColorSpace,De=W.isMeshStandardMaterial||W.isMeshLambertMaterial&&!W.envMap||W.isMeshPhongMaterial&&!W.envMap,Ne=le.get(W.envMap||_e,De),ht=W.vertexColors===!0&&!!Y.attributes.color&&Y.attributes.color.itemSize===4,gt=!!Y.attributes.tangent&&(!!W.normalMap||W.anisotropy>0),Be=!!Y.morphAttributes.position,jt=!!Y.morphAttributes.normal,Di=!!Y.morphAttributes.color;let Ei=Mr;W.toneMapped&&(V===null||V.isXRRenderTarget===!0)&&(Ei=I.toneMapping);const ei=Y.morphAttributes.position||Y.morphAttributes.normal||Y.morphAttributes.color,un=ei!==void 0?ei.length:0,Ee=$.get(W),ts=S.state.lights;if(Xe===!0&&($e===!0||T!==q)){const ai=T===q&&W.id===K;Ve.setState(W,T,ai)}let Rt=!1;W.version===Ee.__version?(Ee.needsLights&&Ee.lightsStateVersion!==ts.state.version||Ee.outputColorSpace!==be||X.isBatchedMesh&&Ee.batching===!1||!X.isBatchedMesh&&Ee.batching===!0||X.isBatchedMesh&&Ee.batchingColor===!0&&X.colorTexture===null||X.isBatchedMesh&&Ee.batchingColor===!1&&X.colorTexture!==null||X.isInstancedMesh&&Ee.instancing===!1||!X.isInstancedMesh&&Ee.instancing===!0||X.isSkinnedMesh&&Ee.skinning===!1||!X.isSkinnedMesh&&Ee.skinning===!0||X.isInstancedMesh&&Ee.instancingColor===!0&&X.instanceColor===null||X.isInstancedMesh&&Ee.instancingColor===!1&&X.instanceColor!==null||X.isInstancedMesh&&Ee.instancingMorph===!0&&X.morphTexture===null||X.isInstancedMesh&&Ee.instancingMorph===!1&&X.morphTexture!==null||Ee.envMap!==Ne||W.fog===!0&&Ee.fog!==Me||Ee.numClippingPlanes!==void 0&&(Ee.numClippingPlanes!==Ve.numPlanes||Ee.numIntersection!==Ve.numIntersection)||Ee.vertexAlphas!==ht||Ee.vertexTangents!==gt||Ee.morphTargets!==Be||Ee.morphNormals!==jt||Ee.morphColors!==Di||Ee.toneMapping!==Ei||Ee.morphTargetsCount!==un||!!Ee.lightProbeGrid!=S.state.lightProbeGridArray.length>0)&&(Rt=!0):(Rt=!0,Ee.__version=W.version);let gs=Ee.currentProgram;Rt===!0&&(gs=Fh(W,B,X),L&&W.isNodeMaterial&&L.onUpdateProgram(W,gs,Ee));let Zs=!1,Zr=!1,Go=!1;const ti=gs.getUniforms(),Ri=Ee.uniforms;if(E.useProgram(gs.program)&&(Zs=!0,Zr=!0,Go=!0),W.id!==K&&(K=W.id,Zr=!0),Ee.needsLights){const ai=R2(S.state.lightProbeGridArray,X);Ee.lightProbeGrid!==ai&&(Ee.lightProbeGrid=ai,Zr=!0)}if(Zs||q!==T){E.buffers.depth.getReversed()&&T.reversedDepth!==!0&&(T._reversedDepth=!0,T.updateProjectionMatrix()),ti.setValue(U,"projectionMatrix",T.projectionMatrix),ti.setValue(U,"viewMatrix",T.matrixWorldInverse);const Jr=ti.map.cameraPosition;Jr!==void 0&&Jr.setValue(U,Ht.setFromMatrixPosition(T.matrixWorld)),C.logarithmicDepthBuffer&&ti.setValue(U,"logDepthBufFC",2/(Math.log(T.far+1)/Math.LN2)),(W.isMeshPhongMaterial||W.isMeshToonMaterial||W.isMeshLambertMaterial||W.isMeshBasicMaterial||W.isMeshStandardMaterial||W.isShaderMaterial)&&ti.setValue(U,"isOrthographic",T.isOrthographicCamera===!0),q!==T&&(q=T,Zr=!0,Go=!0)}if(Ee.needsLights&&(ts.state.directionalShadowMap.length>0&&ti.setValue(U,"directionalShadowMap",ts.state.directionalShadowMap,j),ts.state.spotShadowMap.length>0&&ti.setValue(U,"spotShadowMap",ts.state.spotShadowMap,j),ts.state.pointShadowMap.length>0&&ti.setValue(U,"pointShadowMap",ts.state.pointShadowMap,j)),X.isSkinnedMesh){ti.setOptional(U,X,"bindMatrix"),ti.setOptional(U,X,"bindMatrixInverse");const ai=X.skeleton;ai&&(ai.boneTexture===null&&ai.computeBoneTexture(),ti.setValue(U,"boneTexture",ai.boneTexture,j))}X.isBatchedMesh&&(ti.setOptional(U,X,"batchingTexture"),ti.setValue(U,"batchingTexture",X._matricesTexture,j),ti.setOptional(U,X,"batchingIdTexture"),ti.setValue(U,"batchingIdTexture",X._indirectTexture,j),ti.setOptional(U,X,"batchingColorTexture"),X._colorsTexture!==null&&ti.setValue(U,"batchingColorTexture",X._colorsTexture,j));const jr=Y.morphAttributes;if((jr.position!==void 0||jr.normal!==void 0||jr.color!==void 0)&&N.update(X,Y,gs),(Zr||Ee.receiveShadow!==X.receiveShadow)&&(Ee.receiveShadow=X.receiveShadow,ti.setValue(U,"receiveShadow",X.receiveShadow)),(W.isMeshStandardMaterial||W.isMeshLambertMaterial||W.isMeshPhongMaterial)&&W.envMap===null&&B.environment!==null&&(Ri.envMapIntensity.value=B.environmentIntensity),Ri.dfgLUT!==void 0&&(Ri.dfgLUT.value=vD()),Zr){if(ti.setValue(U,"toneMappingExposure",I.toneMappingExposure),Ee.needsLights&&k2(Ri,Go),Me&&W.fog===!0&&Oe.refreshFogUniforms(Ri,Me),Oe.refreshMaterialUniforms(Ri,W,se,ae,S.state.transmissionRenderTarget[T.id]),Ee.needsLights&&Ee.lightProbeGrid){const ai=Ee.lightProbeGrid;Ri.probesSH.value=ai.texture,Ri.probesMin.value.copy(ai.boundingBox.min),Ri.probesMax.value.copy(ai.boundingBox.max),Ri.probesResolution.value.copy(ai.resolution)}iu.upload(U,iv(Ee),Ri,j)}if(W.isShaderMaterial&&W.uniformsNeedUpdate===!0&&(iu.upload(U,iv(Ee),Ri,j),W.uniformsNeedUpdate=!1),W.isSpriteMaterial&&ti.setValue(U,"center",X.center),ti.setValue(U,"modelViewMatrix",X.modelViewMatrix),ti.setValue(U,"normalMatrix",X.normalMatrix),ti.setValue(U,"modelMatrix",X.matrixWorld),W.uniformsGroups!==void 0){const ai=W.uniformsGroups;for(let Jr=0,Vo=ai.length;Jr<Vo;Jr++){const sv=ai[Jr];ie.update(sv,gs),ie.bind(sv,gs)}}return gs}function k2(T,B){T.ambientLightColor.needsUpdate=B,T.lightProbe.needsUpdate=B,T.directionalLights.needsUpdate=B,T.directionalLightShadows.needsUpdate=B,T.pointLights.needsUpdate=B,T.pointLightShadows.needsUpdate=B,T.spotLights.needsUpdate=B,T.spotLightShadows.needsUpdate=B,T.rectAreaLights.needsUpdate=B,T.hemisphereLights.needsUpdate=B}function P2(T){return T.isMeshLambertMaterial||T.isMeshToonMaterial||T.isMeshPhongMaterial||T.isMeshStandardMaterial||T.isShadowMaterial||T.isShaderMaterial&&T.lights===!0}this.getActiveCubeFace=function(){return F},this.getActiveMipmapLevel=function(){return z},this.getRenderTarget=function(){return V},this.setRenderTargetTextures=function(T,B,Y){const W=$.get(T);W.__autoAllocateDepthBuffer=T.resolveDepthBuffer===!1,W.__autoAllocateDepthBuffer===!1&&(W.__useRenderToTexture=!1),$.get(T.texture).__webglTexture=B,$.get(T.depthTexture).__webglTexture=W.__autoAllocateDepthBuffer?void 0:Y,W.__hasExternalTextures=!0},this.setRenderTargetFramebuffer=function(T,B){const Y=$.get(T);Y.__webglFramebuffer=B,Y.__useDefaultFramebuffer=B===void 0},this.setRenderTarget=function(T,B=0,Y=0){V=T,F=B,z=Y;let W=null,X=!1,Me=!1;if(T){const be=$.get(T);if(be.__useDefaultFramebuffer!==void 0){E.bindFramebuffer(U.FRAMEBUFFER,be.__webglFramebuffer),te.copy(T.viewport),re.copy(T.scissor),Ge=T.scissorTest,E.viewport(te),E.scissor(re),E.setScissorTest(Ge),K=-1;return}else if(be.__webglFramebuffer===void 0)j.setupRenderTarget(T);else if(be.__hasExternalTextures)j.rebindTextures(T,$.get(T.texture).__webglTexture,$.get(T.depthTexture).__webglTexture);else if(T.depthBuffer){const ht=T.depthTexture;if(be.__boundDepthTexture!==ht){if(ht!==null&&$.has(ht)&&(T.width!==ht.image.width||T.height!==ht.image.height))throw new Error("THREE.WebGLRenderer: Attached DepthTexture is initialized to the incorrect size.");j.setupDepthRenderbuffer(T)}}const De=T.texture;(De.isData3DTexture||De.isDataArrayTexture||De.isCompressedArrayTexture)&&(Me=!0);const Ne=$.get(T).__webglFramebuffer;T.isWebGLCubeRenderTarget?(Array.isArray(Ne[B])?W=Ne[B][Y]:W=Ne[B],X=!0):T.samples>0&&j.useMultisampledRTT(T)===!1?W=$.get(T).__webglMultisampledFramebuffer:Array.isArray(Ne)?W=Ne[Y]:W=Ne,te.copy(T.viewport),re.copy(T.scissor),Ge=T.scissorTest}else te.copy(ze).multiplyScalar(se).floor(),re.copy(Le).multiplyScalar(se).floor(),Ge=Ae;if(Y!==0&&(W=P),E.bindFramebuffer(U.FRAMEBUFFER,W)&&E.drawBuffers(T,W),E.viewport(te),E.scissor(re),E.setScissorTest(Ge),X){const be=$.get(T.texture);U.framebufferTexture2D(U.FRAMEBUFFER,U.COLOR_ATTACHMENT0,U.TEXTURE_CUBE_MAP_POSITIVE_X+B,be.__webglTexture,Y)}else if(Me){const be=B;for(let De=0;De<T.textures.length;De++){const Ne=$.get(T.textures[De]);U.framebufferTextureLayer(U.FRAMEBUFFER,U.COLOR_ATTACHMENT0+De,Ne.__webglTexture,Y,be)}}else if(T!==null&&Y!==0){const be=$.get(T.texture);U.framebufferTexture2D(U.FRAMEBUFFER,U.COLOR_ATTACHMENT0,U.TEXTURE_2D,be.__webglTexture,Y)}K=-1},this.readRenderTargetPixels=function(T,B,Y,W,X,Me,_e,be=0){if(!(T&&T.isWebGLRenderTarget)){je("WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");return}let De=$.get(T).__webglFramebuffer;if(T.isWebGLCubeRenderTarget&&_e!==void 0&&(De=De[_e]),De){E.bindFramebuffer(U.FRAMEBUFFER,De);try{const Ne=T.textures[be],ht=Ne.format,gt=Ne.type;if(T.textures.length>1&&U.readBuffer(U.COLOR_ATTACHMENT0+be),!C.textureFormatReadable(ht)){je("WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.");return}if(!C.textureTypeReadable(gt)){je("WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.");return}B>=0&&B<=T.width-W&&Y>=0&&Y<=T.height-X&&U.readPixels(B,Y,W,X,me.convert(ht),me.convert(gt),Me)}finally{const Ne=V!==null?$.get(V).__webglFramebuffer:null;E.bindFramebuffer(U.FRAMEBUFFER,Ne)}}},this.readRenderTargetPixelsAsync=async function(T,B,Y,W,X,Me,_e,be=0){if(!(T&&T.isWebGLRenderTarget))throw new Error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");let De=$.get(T).__webglFramebuffer;if(T.isWebGLCubeRenderTarget&&_e!==void 0&&(De=De[_e]),De)if(B>=0&&B<=T.width-W&&Y>=0&&Y<=T.height-X){E.bindFramebuffer(U.FRAMEBUFFER,De);const Ne=T.textures[be],ht=Ne.format,gt=Ne.type;if(T.textures.length>1&&U.readBuffer(U.COLOR_ATTACHMENT0+be),!C.textureFormatReadable(ht))throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.");if(!C.textureTypeReadable(gt))throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.");const Be=U.createBuffer();U.bindBuffer(U.PIXEL_PACK_BUFFER,Be),U.bufferData(U.PIXEL_PACK_BUFFER,Me.byteLength,U.STREAM_READ),U.readPixels(B,Y,W,X,me.convert(ht),me.convert(gt),0);const jt=V!==null?$.get(V).__webglFramebuffer:null;E.bindFramebuffer(U.FRAMEBUFFER,jt);const Di=U.fenceSync(U.SYNC_GPU_COMMANDS_COMPLETE,0);return U.flush(),await XE(U,Di,4),U.bindBuffer(U.PIXEL_PACK_BUFFER,Be),U.getBufferSubData(U.PIXEL_PACK_BUFFER,0,Me),U.deleteBuffer(Be),U.deleteSync(Di),Me}else throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: requested read bounds are out of range.")},this.copyFramebufferToTexture=function(T,B=null,Y=0){const W=Math.pow(2,-Y),X=Math.floor(T.image.width*W),Me=Math.floor(T.image.height*W),_e=B!==null?B.x:0,be=B!==null?B.y:0;j.setTexture2D(T,0),U.copyTexSubImage2D(U.TEXTURE_2D,Y,0,0,_e,be,X,Me),E.unbindTexture()},this.copyTextureToTexture=function(T,B,Y=null,W=null,X=0,Me=0){let _e,be,De,Ne,ht,gt,Be,jt,Di;const Ei=T.isCompressedTexture?T.mipmaps[Me]:T.image;if(Y!==null)_e=Y.max.x-Y.min.x,be=Y.max.y-Y.min.y,De=Y.isBox3?Y.max.z-Y.min.z:1,Ne=Y.min.x,ht=Y.min.y,gt=Y.isBox3?Y.min.z:0;else{const Ri=Math.pow(2,-X);_e=Math.floor(Ei.width*Ri),be=Math.floor(Ei.height*Ri),T.isDataArrayTexture?De=Ei.depth:T.isData3DTexture?De=Math.floor(Ei.depth*Ri):De=1,Ne=0,ht=0,gt=0}W!==null?(Be=W.x,jt=W.y,Di=W.z):(Be=0,jt=0,Di=0);const ei=me.convert(B.format),un=me.convert(B.type);let Ee;B.isData3DTexture?(j.setTexture3D(B,0),Ee=U.TEXTURE_3D):B.isDataArrayTexture||B.isCompressedArrayTexture?(j.setTexture2DArray(B,0),Ee=U.TEXTURE_2D_ARRAY):(j.setTexture2D(B,0),Ee=U.TEXTURE_2D),E.activeTexture(U.TEXTURE0),E.pixelStorei(U.UNPACK_FLIP_Y_WEBGL,B.flipY),E.pixelStorei(U.UNPACK_PREMULTIPLY_ALPHA_WEBGL,B.premultiplyAlpha),E.pixelStorei(U.UNPACK_ALIGNMENT,B.unpackAlignment);const ts=E.getParameter(U.UNPACK_ROW_LENGTH),Rt=E.getParameter(U.UNPACK_IMAGE_HEIGHT),gs=E.getParameter(U.UNPACK_SKIP_PIXELS),Zs=E.getParameter(U.UNPACK_SKIP_ROWS),Zr=E.getParameter(U.UNPACK_SKIP_IMAGES);E.pixelStorei(U.UNPACK_ROW_LENGTH,Ei.width),E.pixelStorei(U.UNPACK_IMAGE_HEIGHT,Ei.height),E.pixelStorei(U.UNPACK_SKIP_PIXELS,Ne),E.pixelStorei(U.UNPACK_SKIP_ROWS,ht),E.pixelStorei(U.UNPACK_SKIP_IMAGES,gt);const Go=T.isDataArrayTexture||T.isData3DTexture,ti=B.isDataArrayTexture||B.isData3DTexture;if(T.isDepthTexture){const Ri=$.get(T),jr=$.get(B),ai=$.get(Ri.__renderTarget),Jr=$.get(jr.__renderTarget);E.bindFramebuffer(U.READ_FRAMEBUFFER,ai.__webglFramebuffer),E.bindFramebuffer(U.DRAW_FRAMEBUFFER,Jr.__webglFramebuffer);for(let Vo=0;Vo<De;Vo++)Go&&(U.framebufferTextureLayer(U.READ_FRAMEBUFFER,U.COLOR_ATTACHMENT0,$.get(T).__webglTexture,X,gt+Vo),U.framebufferTextureLayer(U.DRAW_FRAMEBUFFER,U.COLOR_ATTACHMENT0,$.get(B).__webglTexture,Me,Di+Vo)),U.blitFramebuffer(Ne,ht,_e,be,Be,jt,_e,be,U.DEPTH_BUFFER_BIT,U.NEAREST);E.bindFramebuffer(U.READ_FRAMEBUFFER,null),E.bindFramebuffer(U.DRAW_FRAMEBUFFER,null)}else if(X!==0||T.isRenderTargetTexture||$.has(T)){const Ri=$.get(T),jr=$.get(B);E.bindFramebuffer(U.READ_FRAMEBUFFER,O),E.bindFramebuffer(U.DRAW_FRAMEBUFFER,k);for(let ai=0;ai<De;ai++)Go?U.framebufferTextureLayer(U.READ_FRAMEBUFFER,U.COLOR_ATTACHMENT0,Ri.__webglTexture,X,gt+ai):U.framebufferTexture2D(U.READ_FRAMEBUFFER,U.COLOR_ATTACHMENT0,U.TEXTURE_2D,Ri.__webglTexture,X),ti?U.framebufferTextureLayer(U.DRAW_FRAMEBUFFER,U.COLOR_ATTACHMENT0,jr.__webglTexture,Me,Di+ai):U.framebufferTexture2D(U.DRAW_FRAMEBUFFER,U.COLOR_ATTACHMENT0,U.TEXTURE_2D,jr.__webglTexture,Me),X!==0?U.blitFramebuffer(Ne,ht,_e,be,Be,jt,_e,be,U.COLOR_BUFFER_BIT,U.NEAREST):ti?U.copyTexSubImage3D(Ee,Me,Be,jt,Di+ai,Ne,ht,_e,be):U.copyTexSubImage2D(Ee,Me,Be,jt,Ne,ht,_e,be);E.bindFramebuffer(U.READ_FRAMEBUFFER,null),E.bindFramebuffer(U.DRAW_FRAMEBUFFER,null)}else ti?T.isDataTexture||T.isData3DTexture?U.texSubImage3D(Ee,Me,Be,jt,Di,_e,be,De,ei,un,Ei.data):B.isCompressedArrayTexture?U.compressedTexSubImage3D(Ee,Me,Be,jt,Di,_e,be,De,ei,Ei.data):U.texSubImage3D(Ee,Me,Be,jt,Di,_e,be,De,ei,un,Ei):T.isDataTexture?U.texSubImage2D(U.TEXTURE_2D,Me,Be,jt,_e,be,ei,un,Ei.data):T.isCompressedTexture?U.compressedTexSubImage2D(U.TEXTURE_2D,Me,Be,jt,Ei.width,Ei.height,ei,Ei.data):U.texSubImage2D(U.TEXTURE_2D,Me,Be,jt,_e,be,ei,un,Ei);E.pixelStorei(U.UNPACK_ROW_LENGTH,ts),E.pixelStorei(U.UNPACK_IMAGE_HEIGHT,Rt),E.pixelStorei(U.UNPACK_SKIP_PIXELS,gs),E.pixelStorei(U.UNPACK_SKIP_ROWS,Zs),E.pixelStorei(U.UNPACK_SKIP_IMAGES,Zr),Me===0&&B.generateMipmaps&&U.generateMipmap(Ee),E.unbindTexture()},this.initRenderTarget=function(T){$.get(T).__webglFramebuffer===void 0&&j.setupRenderTarget(T)},this.initTexture=function(T){T.isCubeTexture?j.setTextureCube(T,0):T.isData3DTexture?j.setTexture3D(T,0):T.isDataArrayTexture||T.isCompressedArrayTexture?j.setTexture2DArray(T,0):j.setTexture2D(T,0),E.unbindTexture()},this.resetState=function(){F=0,z=0,V=null,E.reset(),xe.reset()},typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}get coordinateSystem(){return vr}get outputColorSpace(){return this._outputColorSpace}set outputColorSpace(e){this._outputColorSpace=e;const t=this.getContext();t.drawingBufferColorSpace=Tt._getDrawingBufferColorSpace(e),t.unpackColorSpace=Tt._getUnpackColorSpace()}}const bD=`
7271
7271
  varying vec3 vDir;
7272
7272
  varying vec3 vWorldDir;
7273
7273
 
@@ -8289,7 +8289,7 @@ void main() {
8289
8289
  float blur = max(vNearBlur, vHaze);
8290
8290
  gl_FragColor = vec4(color, tex.a * uOpacity * vNearFade * (1.0 - blur * ${m4.toFixed(2)}));
8291
8291
  }
8292
- `;function M4(o){let e=o;return function(){e|=0,e=e+1831565813|0;let i=Math.imul(e^e>>>15,1|e);return i=i+Math.imul(i^i>>>7,61|i)^i,((i^i>>>14)>>>0)/4294967296}}const w4=.14,Hy=2.25;let Dd;function x4(){if(Dd)return Dd;const o=128,e=document.createElement("canvas");e.width=o,e.height=o;const t=e.getContext("2d"),i=t.createImageData(o,o),n=o/2,s=o*w4,r=o-s;for(let a=0;a<o;a++)for(let l=0;l<o;l++){const c=l+.5-n,h=a+.5<s?a+.5-s:a+.5>r?a+.5-r:0,d=Math.hypot(c,h),u=Math.exp(-(d*d)/(2*Hy*Hy)),f=(a*o+l)*4;i.data[f]=255,i.data[f+1]=255,i.data[f+2]=255,i.data[f+3]=Math.round(255*Math.min(1,u))}return t.putImageData(i,0,0),Dd=new Kr(e),Dd}function S4(o){const e=M4(o.seed),t=new Float32Array(o.count*3),i=new Float32Array(o.count),n=o.radiusM;for(let c=0;c<o.count;c++){const h=e()*Math.PI*2,d=Math.sqrt(e())*o.radiusM;t[c*3]=Math.cos(h)*d,t[c*3+1]=e()*o.heightM,t[c*3+2]=Math.sin(h)*d,i[c]=.85+e()*.3}const s=new ot;s.setAttribute("position",new st(t,3)),s.setAttribute("aSpeed",new st(i,1)),s.setDrawRange(0,o.visibleCount);const r={uTime:{value:0},uOverallSpeed:{value:o.overallSpeed},uPixelSize:{value:o.pixelSize},uOpacity:{value:o.opacity},uColor:{value:o.color},uUvSquash:{value:1},uSpeedStreak:{value:o.speedStreak},uWindOffset:{value:new we(0,0)},uDropVelocity:{value:new D(0,-1,0)},uAspect:{value:1},uHeight:{value:o.heightM},uBottomY:{value:o.bottomYM},uHalfWidth:{value:n},uTexture:{value:x4()},uNearFocusDistance:{value:o.nearFocusDistanceM},uHazeDistance:{value:o.hazeDistanceM},uHazeColor:{value:o.hazeColor}},a=new Dt({uniforms:r,vertexShader:y4,fragmentShader:b4,transparent:!0,depthWrite:!1,depthTest:!0}),l=new ls(s,a);return l.frustumCulled=!1,{points:l,uniforms:r}}class Yr{static S10_MAG_PER_ARCSEC2=10+2.5*Math.log10(3600*3600);static toMagPerArcsec2(e){return Yr.S10_MAG_PER_ARCSEC2-2.5*Math.log10(Math.max(e,1e-12))}static fromMagPerArcsec2(e){return 10**(.4*(Yr.S10_MAG_PER_ARCSEC2-e))}static latitudeOfRowCoord(e){const t=2*e-1;return 90*Math.sign(t)*t*t}static rowCoordOfLatitude(e){return(Math.sign(e)*Math.sqrt(Math.min(Math.abs(e),90)/90)+1)/2}static angleOfColumnCoord(e){return 180*e*e}static columnCoordOfAngle(e){return Math.sqrt(Math.min(Math.max(e,0),180)/180)}}class Mt{static LONGITUDE_STEPS=256;static LATITUDE_STEPS=128;static SUN_RADIUS_KPC=8.2;static SUN_HEIGHT_KPC=.02;static DISK_SCALE_LENGTH_KPC=2.6;static DISK_SCALE_HEIGHT_KPC=.3;static BULGE_SCALE_KPC=.5;static BULGE_FLATTENING=.6;static BULGE_TO_LOCAL_DISK=20;static DUST_SCALE_LENGTH_KPC=3.5;static DUST_SCALE_HEIGHT_KPC=.1;static EXTINCTION_MAG_PER_KPC=.8;static NEAR_LIMIT_KPC=.01;static FAR_LIMIT_KPC=40;static STEPS=192;static OPAQUE_MAG=15;static PEAK_MAG_PER_ARCSEC2=21;static PEAK_RADIANCE=6.278;static PEAK_LONGITUDE_DEG=0;static PEAK_LATITUDE_DEG=4.5;surfaceBrightnessS10(e,t){return this.radianceTowards(e,t)*Mt.anchor()}static anchor(){return Yr.fromMagPerArcsec2(Mt.PEAK_MAG_PER_ARCSEC2)/Mt.PEAK_RADIANCE}radianceTowards(e,t){return this.trace(e,t).light}extinctionTowards(e,t){return this.trace(e,t).extinctionMag}trace(e,t){const i=e*Math.PI/180,n=t*Math.PI/180,s=-Math.cos(n)*Math.cos(i),r=Math.cos(n)*Math.sin(i),a=Math.sin(n);let l=0,c=0,h=0;const d=Math.log(Mt.NEAR_LIMIT_KPC),u=Math.log(Mt.FAR_LIMIT_KPC)-d;for(let f=0;f<Mt.STEPS;f++){const p=Math.exp(d+u*f/(Mt.STEPS-1)),g=p-h;h=p;const m=p-g/2,v=Mt.SUN_RADIUS_KPC+m*s,b=m*r,x=Mt.SUN_HEIGHT_KPC+m*a,y=Math.hypot(v,b),w=Math.exp(-(y-Mt.SUN_RADIUS_KPC)/Mt.DISK_SCALE_LENGTH_KPC-Math.abs(x)/Mt.DISK_SCALE_HEIGHT_KPC),S=Math.hypot(y,x/Mt.BULGE_FLATTENING),A=Mt.BULGE_TO_LOCAL_DISK*Math.exp(-S/Mt.BULGE_SCALE_KPC);if(l+=(w+A)*g*10**(-.4*c),c+=Mt.EXTINCTION_MAG_PER_KPC*Math.exp(-(y-Mt.SUN_RADIUS_KPC)/Mt.DUST_SCALE_LENGTH_KPC-(Math.abs(x)-Mt.SUN_HEIGHT_KPC)/Mt.DUST_SCALE_HEIGHT_KPC)*g,c>Mt.OPAQUE_MAG)break}return{light:l,extinctionMag:c}}values=new Float32Array(Mt.LONGITUDE_STEPS*Mt.LATITUDE_STEPS);walked=0;get done(){return this.walked>=Mt.LATITUDE_STEPS}walk(e){const t=Mt.LONGITUDE_STEPS,i=Math.min(Mt.LATITUDE_STEPS,this.walked+e);for(;this.walked<i;this.walked++){const n=Yr.latitudeOfRowCoord((this.walked+.5)/Mt.LATITUDE_STEPS);for(let s=0;s<t;s++)this.values[this.walked*t+s]=this.radianceTowards(360*(s+.5)/t,n)}}harvest(){let e=Number.POSITIVE_INFINITY;for(const n of this.values)n<e&&(e=n);const t=Mt.anchor(),i=new Float32Array(this.values.length);for(let n=0;n<i.length;n++)i[n]=(this.values[n]-e)*t;return{width:Mt.LONGITUDE_STEPS,height:Mt.LATITUDE_STEPS,data:i}}}class gi{static LONGITUDE_STEPS=128;static LATITUDE_STEPS=96;static RADIAL_FALLOFF=1.3;static FAN_EXPONENT=2.6;static SUBLIMATION_AU=.1;static NEAR_LIMIT_AU=.004;static FAR_LIMIT_AU=8;static STEPS=224;static LOBE_ASYMMETRY=[.7,-.2,-.81];static LOBE_WEIGHT=[.665,.33,.00541];static RIGHT_ANGLE_S10=200;static POLE_S10=77;surfaceBrightnessS10(e,t){return this.radianceTowards(e,t)*this.anchor()}anchored;anchor(){return this.anchored===void 0&&(this.anchored=gi.RIGHT_ANGLE_S10/this.radianceTowards(90,0)),this.anchored}radianceTowards(e,t){const i=e*Math.PI/180,n=t*Math.PI/180,s=-Math.cos(n)*Math.cos(i),r=-Math.cos(n)*Math.sin(i),a=Math.sin(n),l=-s;let c=0,h=0;const d=Math.log(gi.NEAR_LIMIT_AU),u=Math.log(gi.FAR_LIMIT_AU)-d;for(let f=0;f<gi.STEPS;f++){const p=Math.exp(d+u*f/(gi.STEPS-1)),g=p-h;h=p;const m=p-g/2,v=1+m*s,b=m*r,x=m*a,y=Math.hypot(v,b,x);if(y<gi.SUBLIMATION_AU)continue;const w=x/y,S=y**-1.3*Math.exp(-2.6*Math.abs(w)),A=(l-m)/y;c+=S*this.scattering(A)*g/(y*y)}return c}scattering(e){let t=0;for(let i=0;i<gi.LOBE_ASYMMETRY.length;i++){const n=gi.LOBE_ASYMMETRY[i],s=1+n*n-2*n*e;t+=gi.LOBE_WEIGHT[i]*(1-n*n)/(4*Math.PI*s**1.5)}return t}values=new Float32Array(gi.LONGITUDE_STEPS*gi.LATITUDE_STEPS);walked=0;get done(){return this.walked>=gi.LATITUDE_STEPS}walk(e){const t=gi.LONGITUDE_STEPS,i=Math.min(gi.LATITUDE_STEPS,this.walked+e);for(;this.walked<i;this.walked++){const n=Yr.latitudeOfRowCoord((this.walked+.5)/gi.LATITUDE_STEPS);for(let s=0;s<t;s++){const r=Yr.angleOfColumnCoord((s+.5)/t);this.values[this.walked*t+s]=this.radianceTowards(r,n)}}}harvest(){const e=this.anchor();let t=Number.POSITIVE_INFINITY;for(const n of this.values)n<t&&(t=n);const i=new Float32Array(this.values.length);for(let n=0;n<i.length;n++)i[n]=(this.values[n]-t)*e;return{width:gi.LONGITUDE_STEPS,height:gi.LATITUDE_STEPS,data:i}}}class ce{static get NANOLAMBERTS_PER_S10(){return ce.toNanolamberts(10+2.5*Math.log10(3600*3600))}static nanolambertsOfS10(e){return e*ce.NANOLAMBERTS_PER_S10}static TWILIGHT=[{sunAltitudeDeg:90,magPerArcsec2:3.5},{sunAltitudeDeg:10,magPerArcsec2:4.2},{sunAltitudeDeg:0,magPerArcsec2:7.5},...Array.from({length:15},(e,t)=>{const i=-4-t;return{sunAltitudeDeg:i,magPerArcsec2:ce.patatV(i)}}),{sunAltitudeDeg:-24,magPerArcsec2:22}];static patatV(e){const t=90-e-95;return 11.84+1.518*t-.057*t*t}static moonlessMagPerArcsec2(e){const t=ce.TWILIGHT;for(let i=0;i<t.length-1;i++){const n=t[i],s=t[i+1];if(e<=n.sunAltitudeDeg&&e>=s.sunAltitudeDeg){const r=(n.sunAltitudeDeg-e)/(n.sunAltitudeDeg-s.sunAltitudeDeg);return n.magPerArcsec2+(s.magPerArcsec2-n.magPerArcsec2)*r}}return e>0?t[0].magPerArcsec2:t[t.length-1].magPerArcsec2}static toNanolamberts(e){return 34.08*Math.exp(ce.NANOLAMBERT_OFFSET-ce.PER_MAGNITUDE*e)}static fromNanolamberts(e){return(ce.NANOLAMBERT_OFFSET-Math.log(Math.max(e,1e-6)/34.08))/ce.PER_MAGNITUDE}static NANOLAMBERT_OFFSET=20.7233;static PER_MAGNITUDE=Math.LN10/2.5;static airMass(e){const t=Math.cos(Math.max(e,0)*Math.PI/180);return 1/Math.sqrt(Math.max(1-.96*t*t,.001))}static EXTINCTION_PER_AIR_MASS=.172;static scatteringAt(e){const t=Math.min(Math.max(e,0),180)*Math.PI/180;return 10**5.36*(1.06+Math.cos(t)**2)+10**(6.15-Math.min(e,180)/40)}static scatteredFraction(e){return 1-10**(-.4*ce.EXTINCTION_PER_AIR_MASS*ce.airMass(e))}static AIRGLOW_MAG_PER_ARCSEC2=22;static twilightExcessNanolamberts(e){return Math.max(0,ce.toNanolamberts(ce.moonlessMagPerArcsec2(e))-ce.toNanolamberts(ce.AIRGLOW_MAG_PER_ARCSEC2))}static twilightOutput(e){const t=ce.scatteringAt(90-e)*ce.scatteredFraction(90);return ce.twilightExcessNanolamberts(e)/t}static moonNanolamberts(e,t,i,n){return ce.scatteringAt(i)*ce.moonOutput(e,t)*ce.scatteredFraction(n)}static moonOutput(e,t){if(t<=0)return 0;const i=Math.min(Math.abs(e),180);return 10**(-.4*(3.84+.026*i+4e-9*i**4))*10**(-.4*ce.EXTINCTION_PER_AIR_MASS*ce.airMass(t))}static phaseAngleOf(e){return Math.acos(Math.min(Math.max(2*e-1,-1),1))*180/Math.PI}static magPerArcsec2(e,t,i,n){const s=ce.scatteredFraction(i),r=ce.scatteringAt(e.separationDeg)*ce.twilightOutput(e.altitudeDeg)*s,a=ce.scatteringAt(t.separationDeg)*ce.moonOutput(t.phaseAngleDeg,t.altitudeDeg)*s;return ce.fromNanolamberts(ce.toNanolamberts(ce.AIRGLOW_MAG_PER_ARCSEC2)+r+a+ce.artificialNanolamberts(n,i))}static artificialZenithNanolamberts(e){return e===void 0||!Number.isFinite(e)?0:Math.max(0,ce.toNanolamberts(e)-ce.toNanolamberts(ce.AIRGLOW_MAG_PER_ARCSEC2))}static artificialNanolamberts(e,t){const i=ce.artificialZenithNanolamberts(e);return i>0?i*ce.artificialShape(t):0}static artificialShape(e){return ce.scatteredFraction(e)/ce.scatteredFraction(90)}static nakedEyeLimit(e){return 7.93-5*Math.log10(10**(4.316-e/5)+1)}static starLossMagnitudes(e,t,i){const n=ce.moonlessMagPerArcsec2(e),s=ce.fromNanolamberts(ce.toNanolamberts(n)+ce.scatteringAt(90-t.altitudeDeg)*ce.moonOutput(t.phaseAngleDeg,t.altitudeDeg)*ce.scatteredFraction(90)+ce.artificialZenithNanolamberts(i));return Math.max(0,ce.nakedEyeLimit(n)-ce.nakedEyeLimit(s))}}class sf{static HALF_FLOAT_MAX=65504;static fromMap(e,t){const i=fs.toHalfFloat(1);for(let n=0;n<e.data.length;n++)t[n*4]=fs.toHalfFloat(Math.min(sf.HALF_FLOAT_MAX,ce.nanolambertsOfS10(e.data[n]))),t[n*4+3]=i}}class wa{static pool=typeof Worker>"u"?null:void 0;static with(e,t){const i=wa.pool;if(i===null){t();return}if(i){e(i);return}Ue(async()=>{const{OffThreadTracer:n}=await import("./OffThreadTracer-z-qdZ_d-.js");return{OffThreadTracer:n}},[],import.meta.url).then(({OffThreadTracer:n})=>{wa.pool=n.get(),wa.pool?e(wa.pool):t()},()=>{wa.pool=null,t()})}}class ga{static RADIUS=890;static TOO_BRIGHT_MAG_PER_ARCSEC2=16;static MILKY_WAY_TINT=[.9,.94,1];static ZODIACAL_TINT=[1,.97,.9];object;material;maps=th.shared;milkyWayTexture;zodiacalTexture;milkyWayTexels;zodiacalTexels;repaint;constructor(){this.milkyWayTexels=this.maps.milkyWayTexels,this.milkyWayTexture=ga.buildTexture(this.milkyWayTexels,Mt.LONGITUDE_STEPS,Mt.LATITUDE_STEPS,No),this.zodiacalTexels=this.maps.zodiacalTexels,this.zodiacalTexture=ga.buildTexture(this.zodiacalTexels,gi.LONGITUDE_STEPS,gi.LATITUDE_STEPS,Ti),this.material=new Dt({uniforms:{uMilkyWay:{value:this.milkyWayTexture},uZodiacal:{value:this.zodiacalTexture},uGalactic:{value:new je},uEclipticPole:{value:new D(0,1,0)},uSunLongitude:{value:new D(1,0,0)},uMoonDirection:{value:new D(0,-1,0)},uMoonOutput:{value:0},uSunDirection:{value:new D(0,-1,0)},uTwilightOutput:{value:0},uAirglowNanolamberts:{value:ce.toNanolamberts(ce.AIRGLOW_MAG_PER_ARCSEC2)},uArtificialNanolamberts:{value:0},uSkyColor:{value:new D(0,0,0)},uMilkyWayTint:{value:new D(...ga.MILKY_WAY_TINT)},uZodiacalTint:{value:new D(...ga.ZODIACAL_TINT)},uReady:{value:0},uEncodeDestination:{value:1}},vertexShader:`
8292
+ `;function M4(o){let e=o;return function(){e|=0,e=e+1831565813|0;let i=Math.imul(e^e>>>15,1|e);return i=i+Math.imul(i^i>>>7,61|i)^i,((i^i>>>14)>>>0)/4294967296}}const w4=.14,Hy=2.25;let Dd;function x4(){if(Dd)return Dd;const o=128,e=document.createElement("canvas");e.width=o,e.height=o;const t=e.getContext("2d"),i=t.createImageData(o,o),n=o/2,s=o*w4,r=o-s;for(let a=0;a<o;a++)for(let l=0;l<o;l++){const c=l+.5-n,h=a+.5<s?a+.5-s:a+.5>r?a+.5-r:0,d=Math.hypot(c,h),u=Math.exp(-(d*d)/(2*Hy*Hy)),f=(a*o+l)*4;i.data[f]=255,i.data[f+1]=255,i.data[f+2]=255,i.data[f+3]=Math.round(255*Math.min(1,u))}return t.putImageData(i,0,0),Dd=new Kr(e),Dd}function S4(o){const e=M4(o.seed),t=new Float32Array(o.count*3),i=new Float32Array(o.count),n=o.radiusM;for(let c=0;c<o.count;c++){const h=e()*Math.PI*2,d=Math.sqrt(e())*o.radiusM;t[c*3]=Math.cos(h)*d,t[c*3+1]=e()*o.heightM,t[c*3+2]=Math.sin(h)*d,i[c]=.85+e()*.3}const s=new ot;s.setAttribute("position",new st(t,3)),s.setAttribute("aSpeed",new st(i,1)),s.setDrawRange(0,o.visibleCount);const r={uTime:{value:0},uOverallSpeed:{value:o.overallSpeed},uPixelSize:{value:o.pixelSize},uOpacity:{value:o.opacity},uColor:{value:o.color},uUvSquash:{value:1},uSpeedStreak:{value:o.speedStreak},uWindOffset:{value:new we(0,0)},uDropVelocity:{value:new D(0,-1,0)},uAspect:{value:1},uHeight:{value:o.heightM},uBottomY:{value:o.bottomYM},uHalfWidth:{value:n},uTexture:{value:x4()},uNearFocusDistance:{value:o.nearFocusDistanceM},uHazeDistance:{value:o.hazeDistanceM},uHazeColor:{value:o.hazeColor}},a=new Dt({uniforms:r,vertexShader:y4,fragmentShader:b4,transparent:!0,depthWrite:!1,depthTest:!0}),l=new ls(s,a);return l.frustumCulled=!1,{points:l,uniforms:r}}class Yr{static S10_MAG_PER_ARCSEC2=10+2.5*Math.log10(3600*3600);static toMagPerArcsec2(e){return Yr.S10_MAG_PER_ARCSEC2-2.5*Math.log10(Math.max(e,1e-12))}static fromMagPerArcsec2(e){return 10**(.4*(Yr.S10_MAG_PER_ARCSEC2-e))}static latitudeOfRowCoord(e){const t=2*e-1;return 90*Math.sign(t)*t*t}static rowCoordOfLatitude(e){return(Math.sign(e)*Math.sqrt(Math.min(Math.abs(e),90)/90)+1)/2}static angleOfColumnCoord(e){return 180*e*e}static columnCoordOfAngle(e){return Math.sqrt(Math.min(Math.max(e,0),180)/180)}}class Mt{static LONGITUDE_STEPS=256;static LATITUDE_STEPS=128;static SUN_RADIUS_KPC=8.2;static SUN_HEIGHT_KPC=.02;static DISK_SCALE_LENGTH_KPC=2.6;static DISK_SCALE_HEIGHT_KPC=.3;static BULGE_SCALE_KPC=.5;static BULGE_FLATTENING=.6;static BULGE_TO_LOCAL_DISK=20;static DUST_SCALE_LENGTH_KPC=3.5;static DUST_SCALE_HEIGHT_KPC=.1;static EXTINCTION_MAG_PER_KPC=.8;static NEAR_LIMIT_KPC=.01;static FAR_LIMIT_KPC=40;static STEPS=192;static OPAQUE_MAG=15;static PEAK_MAG_PER_ARCSEC2=21;static PEAK_RADIANCE=6.278;static PEAK_LONGITUDE_DEG=0;static PEAK_LATITUDE_DEG=4.5;surfaceBrightnessS10(e,t){return this.radianceTowards(e,t)*Mt.anchor()}static anchor(){return Yr.fromMagPerArcsec2(Mt.PEAK_MAG_PER_ARCSEC2)/Mt.PEAK_RADIANCE}radianceTowards(e,t){return this.trace(e,t).light}extinctionTowards(e,t){return this.trace(e,t).extinctionMag}trace(e,t){const i=e*Math.PI/180,n=t*Math.PI/180,s=-Math.cos(n)*Math.cos(i),r=Math.cos(n)*Math.sin(i),a=Math.sin(n);let l=0,c=0,h=0;const d=Math.log(Mt.NEAR_LIMIT_KPC),u=Math.log(Mt.FAR_LIMIT_KPC)-d;for(let f=0;f<Mt.STEPS;f++){const p=Math.exp(d+u*f/(Mt.STEPS-1)),g=p-h;h=p;const m=p-g/2,v=Mt.SUN_RADIUS_KPC+m*s,b=m*r,x=Mt.SUN_HEIGHT_KPC+m*a,y=Math.hypot(v,b),w=Math.exp(-(y-Mt.SUN_RADIUS_KPC)/Mt.DISK_SCALE_LENGTH_KPC-Math.abs(x)/Mt.DISK_SCALE_HEIGHT_KPC),S=Math.hypot(y,x/Mt.BULGE_FLATTENING),A=Mt.BULGE_TO_LOCAL_DISK*Math.exp(-S/Mt.BULGE_SCALE_KPC);if(l+=(w+A)*g*10**(-.4*c),c+=Mt.EXTINCTION_MAG_PER_KPC*Math.exp(-(y-Mt.SUN_RADIUS_KPC)/Mt.DUST_SCALE_LENGTH_KPC-(Math.abs(x)-Mt.SUN_HEIGHT_KPC)/Mt.DUST_SCALE_HEIGHT_KPC)*g,c>Mt.OPAQUE_MAG)break}return{light:l,extinctionMag:c}}values=new Float32Array(Mt.LONGITUDE_STEPS*Mt.LATITUDE_STEPS);walked=0;get done(){return this.walked>=Mt.LATITUDE_STEPS}walk(e){const t=Mt.LONGITUDE_STEPS,i=Math.min(Mt.LATITUDE_STEPS,this.walked+e);for(;this.walked<i;this.walked++){const n=Yr.latitudeOfRowCoord((this.walked+.5)/Mt.LATITUDE_STEPS);for(let s=0;s<t;s++)this.values[this.walked*t+s]=this.radianceTowards(360*(s+.5)/t,n)}}harvest(){let e=Number.POSITIVE_INFINITY;for(const n of this.values)n<e&&(e=n);const t=Mt.anchor(),i=new Float32Array(this.values.length);for(let n=0;n<i.length;n++)i[n]=(this.values[n]-e)*t;return{width:Mt.LONGITUDE_STEPS,height:Mt.LATITUDE_STEPS,data:i}}}class gi{static LONGITUDE_STEPS=128;static LATITUDE_STEPS=96;static RADIAL_FALLOFF=1.3;static FAN_EXPONENT=2.6;static SUBLIMATION_AU=.1;static NEAR_LIMIT_AU=.004;static FAR_LIMIT_AU=8;static STEPS=224;static LOBE_ASYMMETRY=[.7,-.2,-.81];static LOBE_WEIGHT=[.665,.33,.00541];static RIGHT_ANGLE_S10=200;static POLE_S10=77;surfaceBrightnessS10(e,t){return this.radianceTowards(e,t)*this.anchor()}anchored;anchor(){return this.anchored===void 0&&(this.anchored=gi.RIGHT_ANGLE_S10/this.radianceTowards(90,0)),this.anchored}radianceTowards(e,t){const i=e*Math.PI/180,n=t*Math.PI/180,s=-Math.cos(n)*Math.cos(i),r=-Math.cos(n)*Math.sin(i),a=Math.sin(n),l=-s;let c=0,h=0;const d=Math.log(gi.NEAR_LIMIT_AU),u=Math.log(gi.FAR_LIMIT_AU)-d;for(let f=0;f<gi.STEPS;f++){const p=Math.exp(d+u*f/(gi.STEPS-1)),g=p-h;h=p;const m=p-g/2,v=1+m*s,b=m*r,x=m*a,y=Math.hypot(v,b,x);if(y<gi.SUBLIMATION_AU)continue;const w=x/y,S=y**-1.3*Math.exp(-2.6*Math.abs(w)),A=(l-m)/y;c+=S*this.scattering(A)*g/(y*y)}return c}scattering(e){let t=0;for(let i=0;i<gi.LOBE_ASYMMETRY.length;i++){const n=gi.LOBE_ASYMMETRY[i],s=1+n*n-2*n*e;t+=gi.LOBE_WEIGHT[i]*(1-n*n)/(4*Math.PI*s**1.5)}return t}values=new Float32Array(gi.LONGITUDE_STEPS*gi.LATITUDE_STEPS);walked=0;get done(){return this.walked>=gi.LATITUDE_STEPS}walk(e){const t=gi.LONGITUDE_STEPS,i=Math.min(gi.LATITUDE_STEPS,this.walked+e);for(;this.walked<i;this.walked++){const n=Yr.latitudeOfRowCoord((this.walked+.5)/gi.LATITUDE_STEPS);for(let s=0;s<t;s++){const r=Yr.angleOfColumnCoord((s+.5)/t);this.values[this.walked*t+s]=this.radianceTowards(r,n)}}}harvest(){const e=this.anchor();let t=Number.POSITIVE_INFINITY;for(const n of this.values)n<t&&(t=n);const i=new Float32Array(this.values.length);for(let n=0;n<i.length;n++)i[n]=(this.values[n]-t)*e;return{width:gi.LONGITUDE_STEPS,height:gi.LATITUDE_STEPS,data:i}}}class ce{static get NANOLAMBERTS_PER_S10(){return ce.toNanolamberts(10+2.5*Math.log10(3600*3600))}static nanolambertsOfS10(e){return e*ce.NANOLAMBERTS_PER_S10}static TWILIGHT=[{sunAltitudeDeg:90,magPerArcsec2:3.5},{sunAltitudeDeg:10,magPerArcsec2:4.2},{sunAltitudeDeg:0,magPerArcsec2:7.5},...Array.from({length:15},(e,t)=>{const i=-4-t;return{sunAltitudeDeg:i,magPerArcsec2:ce.patatV(i)}}),{sunAltitudeDeg:-24,magPerArcsec2:22}];static patatV(e){const t=90-e-95;return 11.84+1.518*t-.057*t*t}static moonlessMagPerArcsec2(e){const t=ce.TWILIGHT;for(let i=0;i<t.length-1;i++){const n=t[i],s=t[i+1];if(e<=n.sunAltitudeDeg&&e>=s.sunAltitudeDeg){const r=(n.sunAltitudeDeg-e)/(n.sunAltitudeDeg-s.sunAltitudeDeg);return n.magPerArcsec2+(s.magPerArcsec2-n.magPerArcsec2)*r}}return e>0?t[0].magPerArcsec2:t[t.length-1].magPerArcsec2}static toNanolamberts(e){return 34.08*Math.exp(ce.NANOLAMBERT_OFFSET-ce.PER_MAGNITUDE*e)}static fromNanolamberts(e){return(ce.NANOLAMBERT_OFFSET-Math.log(Math.max(e,1e-6)/34.08))/ce.PER_MAGNITUDE}static NANOLAMBERT_OFFSET=20.7233;static PER_MAGNITUDE=Math.LN10/2.5;static airMass(e){const t=Math.cos(Math.max(e,0)*Math.PI/180);return 1/Math.sqrt(Math.max(1-.96*t*t,.001))}static EXTINCTION_PER_AIR_MASS=.172;static scatteringAt(e){const t=Math.min(Math.max(e,0),180)*Math.PI/180;return 10**5.36*(1.06+Math.cos(t)**2)+10**(6.15-Math.min(e,180)/40)}static scatteredFraction(e){return 1-10**(-.4*ce.EXTINCTION_PER_AIR_MASS*ce.airMass(e))}static AIRGLOW_MAG_PER_ARCSEC2=22;static twilightExcessNanolamberts(e){return Math.max(0,ce.toNanolamberts(ce.moonlessMagPerArcsec2(e))-ce.toNanolamberts(ce.AIRGLOW_MAG_PER_ARCSEC2))}static twilightOutput(e){const t=ce.scatteringAt(90-e)*ce.scatteredFraction(90);return ce.twilightExcessNanolamberts(e)/t}static moonNanolamberts(e,t,i,n){return ce.scatteringAt(i)*ce.moonOutput(e,t)*ce.scatteredFraction(n)}static moonOutput(e,t){if(t<=0)return 0;const i=Math.min(Math.abs(e),180);return 10**(-.4*(3.84+.026*i+4e-9*i**4))*10**(-.4*ce.EXTINCTION_PER_AIR_MASS*ce.airMass(t))}static phaseAngleOf(e){return Math.acos(Math.min(Math.max(2*e-1,-1),1))*180/Math.PI}static magPerArcsec2(e,t,i,n){const s=ce.scatteredFraction(i),r=ce.scatteringAt(e.separationDeg)*ce.twilightOutput(e.altitudeDeg)*s,a=ce.scatteringAt(t.separationDeg)*ce.moonOutput(t.phaseAngleDeg,t.altitudeDeg)*s;return ce.fromNanolamberts(ce.toNanolamberts(ce.AIRGLOW_MAG_PER_ARCSEC2)+r+a+ce.artificialNanolamberts(n,i))}static artificialZenithNanolamberts(e){return e===void 0||!Number.isFinite(e)?0:Math.max(0,ce.toNanolamberts(e)-ce.toNanolamberts(ce.AIRGLOW_MAG_PER_ARCSEC2))}static artificialNanolamberts(e,t){const i=ce.artificialZenithNanolamberts(e);return i>0?i*ce.artificialShape(t):0}static artificialShape(e){return ce.scatteredFraction(e)/ce.scatteredFraction(90)}static nakedEyeLimit(e){return 7.93-5*Math.log10(10**(4.316-e/5)+1)}static starLossMagnitudes(e,t,i){const n=ce.moonlessMagPerArcsec2(e),s=ce.fromNanolamberts(ce.toNanolamberts(n)+ce.scatteringAt(90-t.altitudeDeg)*ce.moonOutput(t.phaseAngleDeg,t.altitudeDeg)*ce.scatteredFraction(90)+ce.artificialZenithNanolamberts(i));return Math.max(0,ce.nakedEyeLimit(n)-ce.nakedEyeLimit(s))}}class sf{static HALF_FLOAT_MAX=65504;static fromMap(e,t){const i=fs.toHalfFloat(1);for(let n=0;n<e.data.length;n++)t[n*4]=fs.toHalfFloat(Math.min(sf.HALF_FLOAT_MAX,ce.nanolambertsOfS10(e.data[n]))),t[n*4+3]=i}}class wa{static pool=typeof Worker>"u"?null:void 0;static with(e,t){const i=wa.pool;if(i===null){t();return}if(i){e(i);return}Ue(async()=>{const{OffThreadTracer:n}=await import("./OffThreadTracer-z-qdZ_d-.js");return{OffThreadTracer:n}},[],import.meta.url).then(({OffThreadTracer:n})=>{wa.pool=n.get(),wa.pool?e(wa.pool):t()},()=>{wa.pool=null,t()})}}class ga{static RADIUS=890;static TOO_BRIGHT_MAG_PER_ARCSEC2=16;static MILKY_WAY_TINT=[.9,.94,1];static ZODIACAL_TINT=[1,.97,.9];object;material;maps=th.shared;milkyWayTexture;zodiacalTexture;milkyWayTexels;zodiacalTexels;repaint;constructor(){this.milkyWayTexels=this.maps.milkyWayTexels,this.milkyWayTexture=ga.buildTexture(this.milkyWayTexels,Mt.LONGITUDE_STEPS,Mt.LATITUDE_STEPS,No),this.zodiacalTexels=this.maps.zodiacalTexels,this.zodiacalTexture=ga.buildTexture(this.zodiacalTexels,gi.LONGITUDE_STEPS,gi.LATITUDE_STEPS,Ti),this.material=new Dt({uniforms:{uMilkyWay:{value:this.milkyWayTexture},uZodiacal:{value:this.zodiacalTexture},uGalactic:{value:new Je},uEclipticPole:{value:new D(0,1,0)},uSunLongitude:{value:new D(1,0,0)},uMoonDirection:{value:new D(0,-1,0)},uMoonOutput:{value:0},uSunDirection:{value:new D(0,-1,0)},uTwilightOutput:{value:0},uAirglowNanolamberts:{value:ce.toNanolamberts(ce.AIRGLOW_MAG_PER_ARCSEC2)},uArtificialNanolamberts:{value:0},uSkyColor:{value:new D(0,0,0)},uMilkyWayTint:{value:new D(...ga.MILKY_WAY_TINT)},uZodiacalTint:{value:new D(...ga.ZODIACAL_TINT)},uReady:{value:0},uEncodeDestination:{value:1}},vertexShader:`
8293
8293
  varying vec3 vDirection;
8294
8294
  void main() {
8295
8295
  vDirection = normalize((modelMatrix * vec4(position, 1.0)).xyz - cameraPosition);
@@ -8855,7 +8855,7 @@ void main()
8855
8855
  }
8856
8856
  `;let Rd;function _4(){if(Rd)return Rd;const o=256,e=document.createElement("canvas");e.width=o,e.height=o;const t=e.getContext("2d");t.fillStyle="rgba(60,60,60,1)",t.fillRect(0,0,o,o);const i=[[.3,.35,.22,.5],[.7,.6,.16,.35],[.55,.8,.3,.4],[.15,.7,.12,.3],[.85,.2,.18,.3]];for(const[n,s,r,a]of i){const l=t.createRadialGradient(n*o,s*o,0,n*o,s*o,r*o);l.addColorStop(0,`rgba(200,200,200,${a})`),l.addColorStop(1,"rgba(200,200,200,0)"),t.fillStyle=l,t.fillRect(0,0,o,o)}return Rd=new Kr(e),Rd}function T4(){const o={uTime:{value:0},uResolution:{value:new we(1,1)},uLensPosition:{value:new we(0,0)},uColorGain:{value:new ne(55,55,51)},uOpacity:{value:.5},uFlareIntensity:{value:0},uStarPoints:{value:0},uTanHalfFov:{value:Math.tan(Math.PI/6)},uEquidistant:{value:0},uHalfFovRad:{value:Math.PI/6},uSourceRadiusDeg:{value:.265},uVeilStrength:{value:0},uDazzleColour:{value:new ne(1,1,1)},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:_4()}},e=new Dt({uniforms:o,vertexShader:E4,fragmentShader:A4,transparent:!0,depthWrite:!1,depthTest:!1,blending:Wi,fog:!1,name:"LensFlareShader"}),t=new Se(new Gn(2,2),e);return t.frustumCulled=!1,t.renderOrder=20,{mesh:t,uniforms:o}}class es{static material(){return new Hn({vertexColors:!0,transparent:!0,blending:Wi,depthWrite:!1,fog:!1,side:Bn})}static track(e){e.userData.skyRibbon=!0}static twins=new WeakMap;static outputMaterial(e){let t=es.twins.get(e);return t||(t=es.material(),t.depthTest=!1,t.onBeforeCompile=i=>{Object.assign(i.uniforms,Ce.output),i.vertexShader=es.patchOutput(i.vertexShader)},t.customProgramCacheKey=()=>"sky-ribbon-output",es.twins.set(e,t),t)}static patchOutput(e){return e.replace("void main() {",`${Ce.OUTPUT_UNIFORMS_GLSL}
8857
8857
  void main() {`).replace(Ce.PROJECT_ANCHOR,`${Ce.PROJECT_ANCHOR}
8858
- ${Ce.OUTPUT_PROJECTION_GLSL}`)}}class In{constructor(e,t){this.width=e,this.height=t,this.target=new Mi(e,t,{type:ci,samples:4}),this.occlusion=new Mi(...In.occlusionSize(e,t))}static OCCLUDER_LAYER=6;static CLOUD_LAYER=7;static OCCLUSION_SCALE=.5;target;occlusion;scene=new xr;proxies=new Map;foreground=new Hn({color:0,fog:!1});hidden=[];static occlusionSize(e,t){return[Math.max(1,Math.round(e*In.OCCLUSION_SCALE)),Math.max(1,Math.round(t*In.OCCLUSION_SCALE))]}resize(e,t){this.width=e,this.height=t,this.target.setSize(e,t),this.occlusion.setSize(...In.occlusionSize(e,t))}take(e){this.hidden=e.points().filter(t=>In.shown(t)&&In.holdsPoints(t.geometry));for(const t of this.hidden)t.visible=!1;return this.hidden.length>0}restore(){for(const e of this.hidden)e.visible=!0}static shown(e){for(let t=e;t;t=t.parent)if(!t.visible)return!1;return!0}static holdsPoints(e){return(e.getAttribute("position")?.count??0)>0&&e.drawRange.count>0}draw(e,t,i,n,s,r){const a=e.getRenderTarget(),l=e.autoClear,c=e.shadowMap.autoUpdate;e.autoClear=!1,e.shadowMap.autoUpdate=!1,this.drawOcclusion(e,t,i,n);const h=this.width/this.height,d=Ce.output;d.uOutputHalfFovRad.value=s,d.uOutputAspect.value=h,d.uOutputPixelAngle.value=2*s/this.height,d.uSrcTanHalfFovY.value=r,d.uOcclusion.value=this.occlusion.texture,this.placeProxies(),di.clearTransparent(e,this.target),e.setRenderTarget(this.target),e.render(this.scene,i),e.autoClear=l,e.shadowMap.autoUpdate=c,e.setRenderTarget(a)}drawOcclusion(e,t,i,n){In.markForeground(t,n.sky);for(const r of n.clouds())r.layers.enable(In.CLOUD_LAYER);di.clearTransparent(e,this.occlusion),e.setRenderTarget(this.occlusion);const s=t.background;t.background=null,i.layers.set(In.OCCLUDER_LAYER),t.overrideMaterial=this.foreground,e.render(t,i),t.overrideMaterial=null,i.layers.set(In.CLOUD_LAYER),e.render(t,i),i.layers.set(0),t.background=s}static markForeground(e,t){for(const i of e.children)if(i!==t){if(i instanceof Se&&i.layers.isEnabled(0)){const n=Array.isArray(i.material)?i.material[0]:i.material;n.depthWrite!==!1&&!n.transparent&&n.blending!==Wi?i.layers.enable(In.OCCLUDER_LAYER):i.layers.disable(In.OCCLUDER_LAYER)}In.markForeground(i,t)}}placeProxies(){for(const e of this.hidden){let t=this.proxies.get(e);t||(t=e instanceof ls?new ls(e.geometry,Ce.outputMaterial(e.material)):new Se(e.geometry,es.outputMaterial(e.material)),t.matrixAutoUpdate=!1,t.frustumCulled=!1,this.proxies.set(e,t),this.scene.add(t)),t.geometry=e.geometry,e.updateWorldMatrix(!0,!1),t.matrix.copy(e.matrixWorld),t.matrixWorldNeedsUpdate=!0,t.visible=!0}for(const[e,t]of this.proxies)this.hidden.includes(e)||(t.visible=!1,e.parent||(this.scene.remove(t),this.proxies.delete(e)))}dispose(){this.target.dispose(),this.occlusion.dispose(),this.foreground.dispose()}}class di{static MAX_HALF_ANGLE_DEG=80;static MAX_CUBE_FACE=2048;static SAMPLES=4;pointLayer;cubeTarget;cubeCamera;cubeMaterial;cubeRotation=new je;target;overlayTarget;overlayCubeTarget;quadScene=new xr;quadCamera=new $s(-1,1,1,-1,0,1);material;width;height;constructor(e,t){this.width=Math.max(1,e),this.height=Math.max(1,t),this.target=new Mi(this.width,this.height,{type:ci,samples:di.SAMPLES}),this.overlayTarget=new Mi(this.width,this.height,{type:ci,samples:di.SAMPLES}),this.material=new Dt({uniforms:{...Ln,uSource:{value:this.target.texture},uHalfFovRad:{value:.5236},uAspect:{value:this.width/this.height},uSrcTanHalfFovY:{value:1},uResolution:{value:new we(this.width,this.height)},uOverlay:{value:this.overlayTarget.texture},uPoints:{value:null},uPointsOn:{value:0},uMode:{value:hs.Finished}},vertexShader:`
8858
+ ${Ce.OUTPUT_PROJECTION_GLSL}`)}}class In{constructor(e,t){this.width=e,this.height=t,this.target=new Mi(e,t,{type:ci,samples:4}),this.occlusion=new Mi(...In.occlusionSize(e,t))}static OCCLUDER_LAYER=6;static CLOUD_LAYER=7;static OCCLUSION_SCALE=.5;target;occlusion;scene=new xr;proxies=new Map;foreground=new Hn({color:0,fog:!1});hidden=[];static occlusionSize(e,t){return[Math.max(1,Math.round(e*In.OCCLUSION_SCALE)),Math.max(1,Math.round(t*In.OCCLUSION_SCALE))]}resize(e,t){this.width=e,this.height=t,this.target.setSize(e,t),this.occlusion.setSize(...In.occlusionSize(e,t))}take(e){this.hidden=e.points().filter(t=>In.shown(t)&&In.holdsPoints(t.geometry));for(const t of this.hidden)t.visible=!1;return this.hidden.length>0}restore(){for(const e of this.hidden)e.visible=!0}static shown(e){for(let t=e;t;t=t.parent)if(!t.visible)return!1;return!0}static holdsPoints(e){return(e.getAttribute("position")?.count??0)>0&&e.drawRange.count>0}draw(e,t,i,n,s,r){const a=e.getRenderTarget(),l=e.autoClear,c=e.shadowMap.autoUpdate;e.autoClear=!1,e.shadowMap.autoUpdate=!1,this.drawOcclusion(e,t,i,n);const h=this.width/this.height,d=Ce.output;d.uOutputHalfFovRad.value=s,d.uOutputAspect.value=h,d.uOutputPixelAngle.value=2*s/this.height,d.uSrcTanHalfFovY.value=r,d.uOcclusion.value=this.occlusion.texture,this.placeProxies(),di.clearTransparent(e,this.target),e.setRenderTarget(this.target),e.render(this.scene,i),e.autoClear=l,e.shadowMap.autoUpdate=c,e.setRenderTarget(a)}drawOcclusion(e,t,i,n){In.markForeground(t,n.sky);for(const r of n.clouds())r.layers.enable(In.CLOUD_LAYER);di.clearTransparent(e,this.occlusion),e.setRenderTarget(this.occlusion);const s=t.background;t.background=null,i.layers.set(In.OCCLUDER_LAYER),t.overrideMaterial=this.foreground,e.render(t,i),t.overrideMaterial=null,i.layers.set(In.CLOUD_LAYER),e.render(t,i),i.layers.set(0),t.background=s}static markForeground(e,t){for(const i of e.children)if(i!==t){if(i instanceof Se&&i.layers.isEnabled(0)){const n=Array.isArray(i.material)?i.material[0]:i.material;n.depthWrite!==!1&&!n.transparent&&n.blending!==Wi?i.layers.enable(In.OCCLUDER_LAYER):i.layers.disable(In.OCCLUDER_LAYER)}In.markForeground(i,t)}}placeProxies(){for(const e of this.hidden){let t=this.proxies.get(e);t||(t=e instanceof ls?new ls(e.geometry,Ce.outputMaterial(e.material)):new Se(e.geometry,es.outputMaterial(e.material)),t.matrixAutoUpdate=!1,t.frustumCulled=!1,this.proxies.set(e,t),this.scene.add(t)),t.geometry=e.geometry,e.updateWorldMatrix(!0,!1),t.matrix.copy(e.matrixWorld),t.matrixWorldNeedsUpdate=!0,t.visible=!0}for(const[e,t]of this.proxies)this.hidden.includes(e)||(t.visible=!1,e.parent||(this.scene.remove(t),this.proxies.delete(e)))}dispose(){this.target.dispose(),this.occlusion.dispose(),this.foreground.dispose()}}class di{static MAX_HALF_ANGLE_DEG=80;static MAX_CUBE_FACE=2048;static SAMPLES=4;pointLayer;cubeTarget;cubeCamera;cubeMaterial;cubeRotation=new Je;target;overlayTarget;overlayCubeTarget;quadScene=new xr;quadCamera=new $s(-1,1,1,-1,0,1);material;width;height;constructor(e,t){this.width=Math.max(1,e),this.height=Math.max(1,t),this.target=new Mi(this.width,this.height,{type:ci,samples:di.SAMPLES}),this.overlayTarget=new Mi(this.width,this.height,{type:ci,samples:di.SAMPLES}),this.material=new Dt({uniforms:{...Ln,uSource:{value:this.target.texture},uHalfFovRad:{value:.5236},uAspect:{value:this.width/this.height},uSrcTanHalfFovY:{value:1},uResolution:{value:new we(this.width,this.height)},uOverlay:{value:this.overlayTarget.texture},uPoints:{value:null},uPointsOn:{value:0},uMode:{value:hs.Finished}},vertexShader:`
8859
8859
  varying vec2 vNdc;
8860
8860
  void main() {
8861
8861
  vNdc = position.xy;
@@ -9093,7 +9093,7 @@ vLitRank = litRank;`)}`,l.fragmentShader=`uniform float uLitShare;
9093
9093
  varying float vLitRank;
9094
9094
  ${l.fragmentShader.replace("#include <emissivemap_fragment>",`#include <emissivemap_fragment>
9095
9095
  totalEmissiveRadiance *= step(vLitRank, uLitShare);`)}`},r.customProgramCacheKey=()=>"facade-lit-windows";const a=new Se(s,r);return a.castShadow=!0,a.receiveShadow=!0,t.add(a),t}static litWindowShare={value:0};static setLitWindowShare(e){Fe.litWindowShare.value=Math.max(0,Math.min(1,e))}static build(e,t){const i=Fe.hasFacade(e)?Fe.buildFacade(e):e.kind==="building"?Vy(e.floors??tc,e.windows,e.observerSide,e.occupiedFloor,e.observerFacing):e.kind==="tree"?Xy():e.kind==="shrub"?Wy():e.kind==="bridge"?W4(e):e.kind==="wire"?X4(e):e.kind==="wall"?zi.build(e):e.kind==="crop"?Yy():e.kind==="terrace"?Q4():e.kind==="mound"?qy():e.kind==="streetlight"?Ky(t):e.kind==="vehicle"?Zy(t,e.windows,e.observerSide,e.observerFacing):e.kind==="aircraft"?ib():e.kind==="entity"?eb():$m();e.color&&this.paint(i,e.color);const n=this.scaleFor(e),s=new Pt;return e.kind==="building"&&e.roof&&this.addRoof(s,e),i.name=Fe.BODY_NAME,i.scale.copy(n),s.add(i),e.headingDeg!==void 0&&(s.rotation.y=-e.headingDeg*Pp),this.addLights(s,e.lights),Fe.fitLights(s,e,e.sizeM??{}),s}static scaleFor(e){const t=e.sizeM;if(!t||Fe.hasFacade(e)||e.kind==="bridge"||e.kind==="wire"||e.kind==="terrace"||e.kind==="wall")return new D(1,1,1);const i=this.naturalSize(e.kind,e.floors);return new D(t.widthM===void 0?1:Fp(t.widthM,i.widthM),t.heightM===void 0?1:Fp(e.kind==="building"?this.wallHeightOf(e,t.heightM):t.heightM,i.heightM),t.lengthM===void 0?1:Fp(t.lengthM,i.lengthM))}static naturalSize(e,t){const i=e==="building"?Math.max(1,(t??tc)+1):0;if(e==="bridge")return oi.NATURAL_SIZE;if(e==="wire")return xo.NATURAL_SIZE;if(e==="terrace"||e==="wall")return{widthM:1,lengthM:1,heightM:1};const n=`${e}:${i}`,s=jy.get(n);if(s)return s;const r=e==="building"?Vy(i-1,void 0,void 0,void 0):e==="tree"?Xy():e==="shrub"?Wy():e==="crop"?Yy():e==="mound"?qy():e==="streetlight"?Ky(!1):e==="vehicle"?Zy(!1,void 0,void 0):e==="aircraft"?ib():e==="entity"?eb():$m(),a=new on().setFromObject(r),l={widthM:a.max.x-a.min.x,heightM:a.max.y-a.min.y,lengthM:a.max.z-a.min.z};return this.dispose(r),jy.set(n,l),l}static usesModel(e){return mh(e)!==void 0&&!(e.observerSide!==void 0&&ka(e.kind))}static applyModel(e,t,i,n={}){const s=this.bodyOf(e),r=new Pt;r.name=Fe.BODY_NAME,i.rotation.y=-(n.headingOffsetDeg??0)*Pp,i.updateMatrixWorld(!0);const a=new on().setFromObject(i),l={lengthM:a.max.z-a.min.z,heightM:a.max.y-a.min.y,widthM:a.max.x-a.min.x},c=t.kind==="tree"&&t.sizeM?.heightM!==void 0?{heightM:t.sizeM.heightM}:t.sizeM,h=Jy(c,l)??Jy(n.depictedSizeM,l)??1;i.scale.multiplyScalar(h);const d=a.getCenter(new D).multiplyScalar(h);i.position.x-=d.x,i.position.z-=d.z,i.position.y-=t.kind==="aircraft"?d.y:a.min.y*h,i.traverse(u=>{u instanceof Se&&(u.castShadow=!0,u.receiveShadow=!0)}),r.add(i),t.kind==="tree"&&r.add(Fe.trunkShadow(l.heightM*h)),s.parent?(s.parent.add(r),s.removeFromParent()):e.add(r),this.dispose(s),Fe.fitLights(e,t,{widthM:l.widthM*h,heightM:l.heightM*h,lengthM:l.lengthM*h})}static fitLights(e,t,i){const n=gh.byId(Ur.rigOf(t)||void 0)?.referenceSizeM;if(!n||!t.lights)return;const s=(h,d)=>h===void 0||d===0?1:h/d,r=s(i.widthM,n.widthM),a=s(i.heightM,n.heightM),l=s(i.lengthM,n.lengthM),c=new Map(t.lights.map(h=>[h.id,h.offsetM]));e.traverse(h=>{const d=h.userData.lightId,u=d===void 0?void 0:c.get(d);u&&h.position.set(u.x*r,u.y*a,u.z*l)})}static trunkShadow(e){Fe.trunkProxy??={geometry:new ms(1,1.15,1,8),material:new Hn({colorWrite:!1,depthWrite:!1})};const t=new Se(Fe.trunkProxy.geometry,Fe.trunkProxy.material),i=Math.min(.3,Math.max(.12,e*.035)),n=e*.45;return t.scale.set(i,n,i),t.position.y=n/2,t.castShadow=!0,t.receiveShadow=!1,t.userData.sharedModel=!0,t.name="trunk-shadow",t}static trunkProxy;static sizeOf(e){const t=this.naturalSize(e.kind,e.floors);return{widthM:e.sizeM?.widthM??t.widthM,lengthM:e.sizeM?.lengthM??t.lengthM,heightM:e.sizeM?.heightM??t.heightM}}static addLights(e,t){for(const i of t??[]){const n=N4(i.color),s=Ft(e,new Ii(Lp,8,6),n,i.offsetM.y,!0);s.position.set(i.offsetM.x,i.offsetM.y,i.offsetM.z),s.userData={emissive:!0,lightId:i.id,lightColor:n},s.visible=!1;const r=s.material;r.blending=Wi,r.transparent=!0,r.depthWrite=!1,r.fog=!1}}static setLights(e,t,i,n,s=0,r=1,a=R4,l=[1,1,1]){if(!t||t.length===0)return;const c=new Map(t.map(f=>[f.id,f])),h=Math.max(1,n*a/Lp),d=Lp*h,u=r/(Math.PI*d*d);for(const f of e.children){if(!(f instanceof Se))continue;const p=f.userData.lightId;if(!p)continue;const g=c.get(p);if(!g)continue;const m=s>0?TM(g,i,i+s):yS(g,i)?1:0;f.visible=m>0;const v=f.material,b=f.userData.lightColor;if(b){const x=m*C4*(g.intensity??1)*u;v.color.setRGB(b[0]*x*l[0],b[1]*x*l[1],b[2]*x*l[2])}f.scale.setScalar(h)}}static setLit(e,t,i,n=1){const[s,r,a]=t==="streetlight"?[k4,P4,c2]:[L4,O4,h2],l=i?s*n/(Math.PI*r*r):0,c=[a[0]*l,a[1]*l,a[2]*l];e.traverse(h=>{const d=h.userData;!(h instanceof Se)||!d.emissive||d.lightId||h.material.color.setRGB(...c)})}static dispose(e){e.traverse(t=>{if(!(t instanceof Se))return;if(t.userData.sharedModel){for(const n of t.userData.tintedMaterials??[])n.dispose();return}t.geometry.dispose();const i=t.material;for(const n of Array.isArray(i)?i:[i])n.dispose()})}}const Bp="https://ufoathome.org/models/index.json";class nh{attribution="3D models re-hosted by UFO@home, each under its own author's licence";fetchImpl;indexUrls;loading;static shared=new Map;sharing;constructor(e={}){this.sharing=!e.fetchImpl,this.fetchImpl=e.fetchImpl??fetch.bind(globalThis),this.indexUrls=e.indexUrls??nC()}async entries(e){const t=await this.load();return e?t.filter(i=>[i.kind].flat().includes(e)):t}async entry(e){return(await this.load()).find(t=>t.id===e)}load(){if(this.loading)return this.loading;if(!this.sharing)return this.loading=this.fetchFirstAvailable();const e=this.indexUrls.join(`
9096
- `);let t=nh.shared.get(e);return t||(t=this.fetchFirstAvailable(),nh.shared.set(e,t),t.then(i=>{i.length===0&&nh.shared.delete(e)})),this.loading=t}async fetchFirstAvailable(){for(const e of this.indexUrls){const t=await this.fetchIndex(e);if(t)return t}return[]}async fetchIndex(e){try{const t=await this.fetchImpl(e);if(!t.ok)return;const i=await t.json();return Array.isArray(i?.models)?i.models.map(({file:n,...s})=>({...s,url:new URL(n,e).href})):void 0}catch{return}}}function nC(){const o=`?v=${encodeURIComponent("0.115.3")}`,e=typeof location>"u"?void 0:new URL("/models/index.json",location.href).href;return(e&&e!==Bp?[e,Bp]:[Bp]).map(t=>t+o)}const ru=[{id:"ufoathome",name:"UFO@home",credit:"3D models re-hosted by UFO@home, each under its own author's licence",creditUrl:"https://ufoathome.org/models/",create:()=>new nh}];async function zp(o){const{GLTFLoader:e}=await Ue(async()=>{const{GLTFLoader:i}=await import("./GLTFLoader-DQj13T4H.js");return{GLTFLoader:i}},[],import.meta.url),t=new e;return new Promise((i,n)=>{t.load(o,s=>i(Object.assign(s.scene,{animations:s.animations})),void 0,s=>n(new Error(`Could not load 3D model ${o}: ${s instanceof Error?s.message:String(s)}`)))})}const v2=["ellipsoid","sphere","disc","cylinder","cone","box","torus","figure"];class cs{static MIN_ANGLE_RAD=.002;static FILL=(1-Math.exp(-4))/4;static MAX_SHARE=.3;mesh;constructor(e,t){this.mesh=new Se(new Gn(2,2),new Dt({uniforms:{uColor:{value:new ne(0,0,0)},uRadius:{value:1}},vertexShader:cs.VERTEX,fragmentShader:cs.FRAGMENT,transparent:!0,depthWrite:!1,blending:Wi,toneMapped:!1})),this.mesh.name=e,this.mesh.frustumCulled=!1,this.mesh.renderOrder=t,this.mesh.visible=!1}shine(e,t,i){this.mesh.visible=!0,this.mesh.position.set(e.x,e.y,e.z),this.mesh.material.uniforms.uRadius.value=t,this.mesh.material.uniforms.uColor.value.setRGB(i[0],i[1],i[2])}hide(){this.mesh.visible=!1}dispose(){this.mesh.geometry.dispose(),this.mesh.material.dispose()}static spread(e,t,i,n){const s=Math.max(e,n*cs.MIN_ANGLE_RAD),r=cs.FILL*Math.PI*s*s;return{radiusM:s,luminanceCdM2:i*Math.min(cs.MAX_SHARE,t/r)}}static conserving(e){return Math.sqrt(e/(cs.MAX_SHARE*cs.FILL*Math.PI))}static VERTEX=`
9096
+ `);let t=nh.shared.get(e);return t||(t=this.fetchFirstAvailable(),nh.shared.set(e,t),t.then(i=>{i.length===0&&nh.shared.delete(e)})),this.loading=t}async fetchFirstAvailable(){for(const e of this.indexUrls){const t=await this.fetchIndex(e);if(t)return t}return[]}async fetchIndex(e){try{const t=await this.fetchImpl(e);if(!t.ok)return;const i=await t.json();return Array.isArray(i?.models)?i.models.map(({file:n,...s})=>({...s,url:new URL(n,e).href})):void 0}catch{return}}}function nC(){const o=`?v=${encodeURIComponent("0.115.4")}`,e=typeof location>"u"?void 0:new URL("/models/index.json",location.href).href;return(e&&e!==Bp?[e,Bp]:[Bp]).map(t=>t+o)}const ru=[{id:"ufoathome",name:"UFO@home",credit:"3D models re-hosted by UFO@home, each under its own author's licence",creditUrl:"https://ufoathome.org/models/",create:()=>new nh}];async function zp(o){const{GLTFLoader:e}=await Ue(async()=>{const{GLTFLoader:i}=await import("./GLTFLoader-DQj13T4H.js");return{GLTFLoader:i}},[],import.meta.url),t=new e;return new Promise((i,n)=>{t.load(o,s=>i(Object.assign(s.scene,{animations:s.animations})),void 0,s=>n(new Error(`Could not load 3D model ${o}: ${s instanceof Error?s.message:String(s)}`)))})}const v2=["ellipsoid","sphere","disc","cylinder","cone","box","torus","figure"];class cs{static MIN_ANGLE_RAD=.002;static FILL=(1-Math.exp(-4))/4;static MAX_SHARE=.3;mesh;constructor(e,t){this.mesh=new Se(new Gn(2,2),new Dt({uniforms:{uColor:{value:new ne(0,0,0)},uRadius:{value:1}},vertexShader:cs.VERTEX,fragmentShader:cs.FRAGMENT,transparent:!0,depthWrite:!1,blending:Wi,toneMapped:!1})),this.mesh.name=e,this.mesh.frustumCulled=!1,this.mesh.renderOrder=t,this.mesh.visible=!1}shine(e,t,i){this.mesh.visible=!0,this.mesh.position.set(e.x,e.y,e.z),this.mesh.material.uniforms.uRadius.value=t,this.mesh.material.uniforms.uColor.value.setRGB(i[0],i[1],i[2])}hide(){this.mesh.visible=!1}dispose(){this.mesh.geometry.dispose(),this.mesh.material.dispose()}static spread(e,t,i,n){const s=Math.max(e,n*cs.MIN_ANGLE_RAD),r=cs.FILL*Math.PI*s*s;return{radiusM:s,luminanceCdM2:i*Math.min(cs.MAX_SHARE,t/r)}}static conserving(e){return Math.sqrt(e/(cs.MAX_SHARE*cs.FILL*Math.PI))}static VERTEX=`
9097
9097
  uniform float uRadius;
9098
9098
  varying vec2 vOffset;
9099
9099
  void main() {
@@ -9724,7 +9724,7 @@ void main() {`).replace("#include <opaque_fragment>",`
9724
9724
  vec3 light = texture2D(uMap, vec2((along * (uSteps - 1.0) + 0.5) / uSteps, 0.5)).rgb;
9725
9725
  gl_FragColor = vec4(light, 1.0);
9726
9726
  }
9727
- `,transparent:!0,blending:Wi,depthWrite:!1,side:fi,fog:!1});this.object=new Se(new Ii(Yg.RADIUS,128,32,0,Math.PI*2,0,_t.MAX_ANGLE_RAD),t),this.object.renderOrder=-1,this.object.frustumCulled=!1,this.object.visible=!1}show(e,t){if(!e||!t){this.object.visible=!1;return}this.towards.set(e.x,e.y,e.z).normalize(),this.object.quaternion.setFromUnitVectors(this.up,this.towards),this.object.material.uniforms.uSource.value.copy(this.towards);for(let i=0;i<_t.STEPS;i++){for(let n=0;n<3;n++)this.texels[i*4+n]=fs.toHalfFloat(Math.min(t[i*3+n],6e4));this.texels[i*4+3]=fs.toHalfFloat(1)}this.texture.needsUpdate=!0,this.object.visible=!0}dispose(){this.object.geometry.dispose(),this.object.material.dispose(),this.texture.dispose()}}class af{constructor(e){this.generator=e}static SIZE=128;target=new Eh(af.SIZE,{type:ci,generateMipmaps:!1,minFilter:mt,magFilter:mt});camera=new Ig(.1,2e5,this.target);filteredTarget;capturedAtMs=-1/0;capturedVersion;get sharp(){return this.target.texture}get filtered(){return this.filteredTarget?.texture}capture(e,t,i,n=[]){const s=e.shadowMap.autoUpdate;let r=!1;t.traverse(l=>{const c=l;c.isLight&&c.castShadow&&c.shadow&&!c.shadow.map&&(r=!0)}),e.shadowMap.autoUpdate=r?s:!1;const a=n.map(l=>l.visible);for(const l of n)l.visible=!1;this.camera.position.copy(i),this.camera.update(e,t),n.forEach((l,c)=>{l.visible=a[c]}),e.shadowMap.autoUpdate=s,this.filteredTarget=this.generator.fromCubemap(this.target.texture,this.filteredTarget),this.capturedAtMs=performance.now()}dispose(){this.target.dispose(),this.filteredTarget?.dispose()}}class Jn{static REFRESH_MS=250;generator;eye;probes=new Map;constructor(e){Jn.install(),this.generator=new mm(e),this.eye=new af(this.generator)}static decor;refresh(e,t,i,n,s,r,a,l=[],c,h=Jn.REFRESH_MS){for(const m of[...this.probes.keys()])n.some(v=>v.id===m&&v.shiny)||(this.probes.get(m).dispose(),this.probes.delete(m));const d=[{probe:this.eye}];for(const m of n){if(!m.shiny)continue;let v=this.probes.get(m.id);v||(v=new af(this.generator),this.probes.set(m.id,v)),d.push({probe:v,reflector:m})}const u=performance.now(),f=()=>d.filter(({probe:m})=>m.capturedVersion!==a),p=f().filter(({probe:m})=>u-m.capturedAtMs>=h);if(p.length>0){const m=p.reduce((v,b)=>b.probe.capturedAtMs<v.probe.capturedAtMs?b:v);if(m.reflector){const v=m.reflector.holder.getWorldPosition(this.scratch);m.probe.capture(e,t,v,[m.reflector.holder,...s]),Jn.reflectOn(m.reflector.holder,m.probe)}else{m.probe.capture(e,t,i,[...s,...l]),c?.(m.probe.sharp),Jn.decor=m.probe.filtered;for(const v of r)Jn.reflectOn(v,m.probe);for(const v of n)v.shiny||Jn.reflectOn(v.holder,m.probe)}m.probe.capturedVersion=a}const g=f();if(g.length!==0)return Math.max(16,Math.min(...g.map(({probe:m})=>h-(u-m.capturedAtMs))))}scratch=new D;static reflectOn(e,t={filtered:Jn.decor}){e.traverse(i=>{const n=i.material;for(const s of Array.isArray(n)?n:n?[n]:[])s instanceof Th?t.sharp&&s.setSurroundings(t.sharp):s instanceof Ma&&t.filtered&&s.envMap!==t.filtered&&(s.envMap=t.filtered,s.needsUpdate=!0)})}dispose(){this.eye.dispose();for(const e of this.probes.values())e.dispose();this.generator.dispose()}static installed=!1;static install(){if(Jn.installed)return;Jn.installed=!0;const e="iblIrradiance += getIBLIrradiance( geometryNormal );";if(!tt.lights_fragment_maps.includes(e)){console.warn("Reflections: three's lights_fragment_maps changed; the environment will light diffusely too");return}tt.lights_fragment_maps=tt.lights_fragment_maps.replace(e,"// The sky's diffuse light is the hemisphere light's (see Reflections).")}}function aC(o,e){return JSON.stringify(o.cloudLayers)===JSON.stringify(e.cloudLayers)&&o.cloudCover===e.cloudCover&&o.cloudDarkness===e.cloudDarkness&&o.cloudBaseM===e.cloudBaseM&&o.highCloudCover===e.highCloudCover&&o.iceCrystalAlignment===e.iceCrystalAlignment&&o.lowerCloudCover===e.lowerCloudCover&&o.relativeHumidity===e.relativeHumidity&&o.precipitationType===e.precipitationType&&o.precipitationIntensity===e.precipitationIntensity&&o.precipitationAmount===e.precipitationAmount&&o.windDirectionDeg===e.windDirectionDeg&&o.windSpeed===e.windSpeed&&o.storm===e.storm}const Ld=900,Hp=1,sb=4,Gp=5,rb=.5,xl=900,oC=6371e3,lC=3e4;function ab(o){const e=Math.sqrt(2*oC*Math.max(o,0));return Math.max(xl,Math.min(e,lC))}const Vp=.5,Wp=850,Xp=.03,cC=.015,Wn=850,Nc=300,oa=120,hC=700,dC=3.5,Od=20,ob=.04,uC=.26,lb=4,$p=1.5,cb=-1,fC=.01,au=-4,pC=2,mC=20,Nd=2600,gC=.97,vC=.38,Fc=au,yC=8,bC=2,MC=-.5,hb=1500,wC=.7,xC=.3,SC=.32,EC=.65,db=2.4,AC=.9,_C=400,TC=[0,45,90,135,180,225,270,315],IC=2,DC=16,ub=4e3,fb=880,Fd=40,pb=60,RC=10,CC=1,kC=150,PC=55,LC=.5,OC=17,mb=.265,gb=[[0,0],...Array.from({length:8},(o,e)=>{const t=e*Math.PI/4;return[Math.cos(t)*mb,Math.sin(t)*mb]})],Yp=700,qp=250/Zm,NC=12,vb=5,Kp=6,Wa=[.92,.92,.95],Zp=[.15,.15,.19],jp={snow:{fallSpeedMPerS:2,size:.3,color:new ne(1,1,1),driftSensitivity:1,radiusM:25,topYM:20,opacity:.75,poolSize:2400},hail:{fallSpeedMPerS:14,size:.5,color:new ne(.95,.98,1),driftSensitivity:.25,radiusM:25,topYM:10,opacity:.95,poolSize:1200}},Sl=0,Jp=0,FC=150,Qp=3e3,Uc=20,UC=15,yb=Sl,BC=40,bb=1,zC=9;function e0(o){return bb+(zC-bb)*o}const Mb=new ne(.75,.82,.92),HC=10,GC=.5;function wb(o){return sr(o/HC,GC,1)}const Xa=200,xb=.18,Sb=.32,VC=.35,Eb=new ne(.85,.9,.98),Ab=5,_b=.85,Tb=.01;function WC(o,e,t=1){return Math.round(o*(Tb+(1-Tb)*e)*t)}function XC(o,e){return JSON.stringify(o.cloudLayers)===JSON.stringify(e.cloudLayers)&&o.cloudCover===e.cloudCover&&o.cloudDarkness===e.cloudDarkness&&o.cloudBaseM===e.cloudBaseM&&o.highCloudCover===e.highCloudCover&&o.iceCrystalAlignment===e.iceCrystalAlignment&&o.lowerCloudCover===e.lowerCloudCover}const Ib=230,Db=.7,Rb=.05,$C=.6,YC=.7,qC=.15,Cb=.35,KC=3,ZC=1/12,jC=.5,er=new ne(.82,.86,1),JC=2500,QC=1.6,t0=15,e6={Venus:new ne(1,.96,.85),Mars:new ne(1,.55,.4),Jupiter:new ne(.95,.87,.72),Saturn:new ne(.92,.86,.68)};class Je{renderer;scene=new xr;phenomena=new Ls(this.scene);references=new ks(this.scene,()=>this.render());camera;celestialGroup=new Pt;skyMesh;skyGradientMaterial;scatteredSky;lastAstronomy;skyColoursStale=!1;scatteredSkyFrameId=null;skyHoldUntilMs=void 0;onFirstFrameHold;firstFrameReady(){return(!this.scatteredSky||this.scatteredSky.ambient!==void 0)&&!this.iceHalos?.awaitingFirstDisplay}sceneSettled(){return this.firstFrameReady()&&this.arrivalsPending===0&&this.eyeSettledVersion>=this.lastArrivalVersion}arrivalsPending=0;eyeSettledVersion=-1;lastArrivalVersion=0;awaitArrival(e,t){if(this.skyHoldUntilMs===null)return e;this.arrivalsPending++;let i=!0;const n=()=>{i&&(i=!1,this.arrivalsPending--,this.lastArrivalVersion=this.sceneVersion,this.skyHoldUntilMs&&this.redrawHeld())},s=t===void 0?void 0:setTimeout(n,t);return t!==void 0&&(this.arrivalDeadlineMs=Math.max(this.arrivalDeadlineMs,performance.now()+t),this.skyHoldUntilMs&&this.arrivalDeadlineMs>this.skyHoldUntilMs&&(this.skyHoldUntilMs=this.arrivalDeadlineMs,setTimeout(()=>this.render(),t+20))),e.finally(()=>{clearTimeout(s),n()})}static ROADS_PATIENCE_MS=4e3;static TERRAIN_PATIENCE_MS=12e3;arrivalDeadlineMs=0;redrawHeld(){this.frameDirty=!0,!(this.animationFrameId!==null||this.framesDriven||this.flushFrameId!==null)&&(this.flushFrameId=requestAnimationFrame(()=>{this.flushFrameId=null,this.drawIfDirty()}))}holdForNewScene(e){this.surroundings=void 0,this.scatteredSky?.resetSurroundings(),this.startHold(),e&&this.awaitArrival(e).catch(()=>{})}startHold(){this.skyHoldUntilMs=Math.max(performance.now()+ub,this.arrivalDeadlineMs),this.eyeSettledVersion=-1,this.lastArrivalVersion=this.sceneVersion+1,this.iceHalos?.setUrgent(!0),this.skyGlow?.setWithheld(!0),this.onFirstFrameHold?.(!0),setTimeout(()=>this.render(),ub+20)}groundMesh;terrainMesh;terrainProviders;terrainOrigin;terrainMeshOrigin;terrainBuildToken=0;terrainAttribution;roadSystem=new ii;roadAttribution;roadWays;statedRoads=[];traces=[];traceLabels=new Map;tracesShown=!0;traceSystem;traceSystemLoading;traceResolution=new we;decorModelProvider=ru[0].create();decorModelToken=0;decorModelCredits=new Map;bodySystem=new bt(e=>this.awaitArrival(this.loadBodyModel(e)),()=>this.render(),()=>this.relativeScale);bodyOrigin={x:0,z:0};starTiers=[];bodyMeshes=new Map;hitAreas=new Map;glareSprites=new Map;decorObjects=[];terraces=[];decorGroups=new Map;decorPresence=new Map;decorSunlight=new Map;static TRAFFIC_MODEL_RANGE_PER_METRE=133;static TRAFFIC_MODEL_DEFAULT_LENGTH_M=37.6;static trafficModelRangeM(e){return(e.sizeM?.lengthM??Je.TRAFFIC_MODEL_DEFAULT_LENGTH_M)*Je.TRAFFIC_MODEL_RANGE_PER_METRE}pendingTrafficModels=new Map;contrails=[];contrailSystem;contrailSystemLoading;contrailSunlight=new Map;sceneSunBeam=[0,0,0];decorReferencePose;decorCurrentPose;decorTime=0;celestialLight=new $1(16777215,0);celestialLightTarget=new hi;skyLight=new nA(16777215,0,0);streetlightLights=new Map;headlightSystem;headlightLoading;headlightSettings=new Map;observerHeadlights;compassSprites=[];showCompass=!1;compassHovered=!1;compassForced=!1;animationFrameId=null;resolution;cssSize={width:1,height:1};frameDirty=!1;flushFrameId=null;framesDriven=!1;lastFrameTimeMs;raycaster=new tu;weather=pf;observerElevationM=0;siteElevationM=0;air=new xs;groundRadius=xl;terrainRadius=xl;cloudRendering="volume";layeredClouds;cloudLayerOffsetsM={};cloudOffsetM=new D;cloudFieldOffset=new D;cloudMesh;cirrusMesh;cirrusMaterial;cirrusUniforms;cloudMaterial;cloudUniforms;precipitationPoints;precipitationPositions;precipitationPhase;precipitationSpeedJitter;precipitationWobbleFreqJitter;precipitationWobbleAmpJitter;precipitationBounceRemaining;precipitationBounceHeight;precipitationBounceDuration;precipitationBounceVelX;precipitationBounceVelZ;precipitationUniforms;rainSystem;rainSplashSystem;rainCameraDirection=new D;rainLastVerticalFacing=-1;rainViewportSize=new we;lightningArmed=!1;lightningFlashes=[];lightningLevel=0;lightningBolt;lightningLight=new $1(16777215,0);baseFogColor=[0,0,0];lastSunPosition;lensFlare;sunUnhiddenFraction=1;lensFlareArtifactIntensity=0;sunWorldPosition=new D;sunVisible=!1;lensFlareScratch=new D;sunOcclusionRaycaster=new tu;sunOcclusionDirectionScratch=new D;sunOcclusionRightScratch=new D;sunOcclusionUpScratch=new D;ufoOcclusionRaycaster=new tu;projectionKind="rectilinear";starPoints=0;namedStars=[];equidistantPass;depthOfFieldPass;finishPass;exposureAccumulation;exposureInstants=1;get developingExposure(){return this.exposureInstants>1&&this.exposureInstantAt!==void 0}static EXPOSURE_BUDGET_MS=12;static exposureInstantsPerFrame(e){return Math.max(3,Math.round(6e6/Math.max(1,e)))}exposureFrameId=null;exposureInstantsDone=0;exposureInstantAt;restatingExposure=!1;lensOptics;instrumentMagnitudeGain=0;lightPollution;meteorSystem;cometTail;satelliteField;reentrySystem;plumeSystem;iceHalos;lunarDiffraction;eclipsedSun=new Ih;eclipseDiscs;solarCorona;sunBeamFraction=1;sunDiscRadiance=[0,0,0];lunarDiffractionKey="";rainbow;skyGlow;cometKey;novaKeys=new Set;constructor(e,t=QS()){this.renderer=new yD({canvas:e,antialias:!0}),this.resolution=new Ut(Math.min(window.devicePixelRatio||1,2),this.renderer.getContext()),this.renderer.setPixelRatio(this.resolution.pixelRatio),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=Zc,this.camera=new Qn(60,e.width/Math.max(e.height,1),.1,Ld*1.2),this.camera.position.set(0,1.6,0),this.terrainProviders=t,this.celestialLight.shadow.mapSize.set(1024,1024),this.celestialLight.shadow.camera.left=-oa,this.celestialLight.shadow.camera.right=oa,this.celestialLight.shadow.camera.top=oa,this.celestialLight.shadow.camera.bottom=-oa,this.celestialLight.shadow.camera.near=Wn-Nc,this.celestialLight.shadow.camera.far=Wn+Nc,this.celestialLight.shadow.bias=-.03/(2*Nc),this.celestialLight.shadow.normalBias=ob,this.celestialLight.target=this.celestialLightTarget,this.lightningLight.color.copy(er),this.scene.add(this.celestialLight,this.celestialLightTarget,this.skyLight,this.lightningLight),this.scene.add(this.celestialGroup),this.scene.add(this.bodySystem.group),this.scene.add(this.roadSystem.group),this.roadSystem.onMarkings=()=>{this.compileNextFrameOffThread(),this.render()};const i=new dt(this.renderer,()=>{this.skyColoursStale=!0,this.render()});i.supported?this.scatteredSky=i:i.dispose()}get currentTerrainAttribution(){return this.terrainAttribution}get currentRoadAttribution(){return this.roadAttribution}resize(e,t){this.cssSize.width=e,this.cssSize.height=t,this.renderer.setSize(e,t,!1),this.camera.aspect=e/Math.max(t,1),this.camera.updateProjectionMatrix(),this.render()}setCloudRendering(e){e!==this.cloudRendering&&(this.cloudTransmissionMemo.clear(),this.cloudRendering=e,this.layeredClouds?.dispose(),this.layeredClouds=void 0,this.buildClouds(),this.buildCirrus(),this.render())}setCloudOffset(e,t={}){this.cloudOffsetM.set(e.x,0,e.z),this.cloudLayerOffsetsM=t,this.layeredClouds?.setOffsets(e,t),this.cloudFieldOffset.set(e.x*qp,0,e.z*qp);for(const i of[this.cloudUniforms,this.cirrusUniforms])i?.fieldOffset.value.copy(this.cloudFieldOffset);this.iceHalos?.setCloudOffset(this.layeredClouds?.cirrusMask?.offset??this.cloudFieldOffset)}setObserverPose(e){const t=((e.rollDeg??0)+this.gaitOffset.rollDeg)*Ci,i=(e.pitchDeg+this.lookPitchDeg+this.gaitOffset.pitchDeg)*Ci;e.headingDeg!==void 0?this.camera.rotation.set(i,-(e.headingDeg+this.lookYawDeg+this.gaitOffset.yawDeg)*Ci,t,"YXZ"):this.camera.rotation.set(i,this.camera.rotation.y,t,"YXZ"),e.elevationM!==this.observerElevationM&&(this.observerElevationM=e.elevationM,this.syncCloudLayer(),Math.abs(ab(e.elevationM)-this.groundRadius)>1&&(this.buildGround(),this.celestialGroup.scale.setScalar(this.groundRadius/xl),this.camera.far=Math.max(Ld*1.2,this.groundRadius*2.5),this.camera.updateProjectionMatrix())),e.lat!==void 0&&e.lng!==void 0&&this.placeTerrain(e.lat,e.lng,0,0),this.poseElevationM=e.elevationM,this.poseCameraY=this.groundYUnder(0,0)+1.6+e.elevationM,this.camera.position.y=this.poseCameraY,this.celestialGroup.position.y=this.camera.position.y,this.camera.fov!==e.fovDeg&&(this.camera.fov=e.fovDeg,this.camera.updateProjectionMatrix(),this.updateCompassScale())}setTerrainProviders(e){this.stopTerrainFade(),this.terrainProviders=e,this.disposeMesh(this.terrainMesh),this.terrainMesh=void 0,this.terrainOrigin=void 0,this.terrainMeshOrigin=void 0,this.terrainAttribution=void 0,this.roadSystem.clear(),this.roadAttribution=void 0,this.roadWays=void 0,this.applyGroundDepthWrite(),this.terrainBuildToken++}observerRoute;setObserverRoute(e){this.observerRoute=e,this.decorTerrainRadiusM=Je.terrainReachFor(this.decorObjects,e)}decorTerrainRadiusM=0;static terrainReachFor(e,t){if(t&&t.length>=2){const s=t[0];for(const r of t){const a=vt(r.lat,r.lng,s.lat,s.lng);if(Math.hypot(a.x,a.z)>Je.STILL_OBSERVER_M)return 0}}let i=0;for(const s of e){if(s.kind==="aircraft"||s.kind==="observer"||s.track)continue;const r=Math.max(s.sizeM?.widthM??0,s.sizeM?.lengthM??0)/2;i=Math.max(i,Math.hypot(s.eastM,s.northM)+r)}const n=Math.ceil(i/Je.PATCH_WHOLE_SHARE/100)*100;return n>xl*Je.PATCH_WHOLE_SHARE?Math.min(n,Je.MAX_DECOR_TERRAIN_M):0}static STILL_OBSERVER_M=60;static PATCH_WHOLE_SHARE=700/900;static MAX_DECOR_TERRAIN_M=3e3;placeTerrain(e,t,i,n){const s=(r,a)=>{const l=vt(a.lat,a.lng,e,t);r.position.x=l.x-i,r.position.z=l.z+n};this.terrainMesh&&this.terrainMeshOrigin&&s(this.terrainMesh,this.terrainMeshOrigin),this.fadingTerrain&&s(this.fadingTerrain.mesh,this.fadingTerrain.origin)}setTerrainOrigin(e,t,i){if(e===void 0||t===void 0)return;const n=Math.max(this.groundRadius,this.decorTerrainRadiusM);if(this.terrainOrigin&&Math.abs(this.terrainRadius-n)<n*.1){const{x:c,z:h}=vt(e,t,this.terrainOrigin.lat,this.terrainOrigin.lng);if(Math.sqrt(c*c+h*h)<kC*(n/xl))return}const s=this.terrainRadius,r=this.terrainMeshOrigin;r!==void 0&&Math.hypot(vt(e,t,r.lat,r.lng).x,vt(e,t,r.lat,r.lng).z)<=s||(this.roadSystem.clear(),this.roadAttribution=void 0),this.terrainOrigin={lat:e,lng:t},this.terrainRadius=n;const l=++this.terrainBuildToken;this.awaitArrival(d4(e,t,this.terrainProviders,n,{route:this.observerRoute}),Je.TERRAIN_PATIENCE_MS).then(({mesh:c,attribution:h,originElevationM:d})=>{if(l!==this.terrainBuildToken)return;this.setSiteElevation(d??0),this.anchorGrassTo(c,e,t);const u=this.terrainMesh,f=this.terrainMeshOrigin,p=f?vt(e,t,f.lat,f.lng):void 0;u&&p&&Math.hypot(p.x,p.z)<=s&&(c.position.y=u.position.y+this.groundYOfPatch(u,p.x,p.z)),u&&f&&p&&Math.hypot(p.x,p.z)<=s?this.crossfadeTerrain(c,u,f):this.disposeMesh(this.terrainMesh),c.renderOrder=CC,this.terrainMesh=c,this.terrainMeshOrigin={lat:e,lng:t},this.compileNextFrameOffThread(),this.terrainAttribution=h,this.scene.add(c),this.applyGroundDepthWrite(),this.decorCurrentPose&&(this.setObserverPose(this.decorCurrentPose),this.updateDecorAnchoring(this.decorReferencePose,this.decorCurrentPose,this.decorTime)),this.buildRoads(e,t,n),this.drapeStatedRoads(),this.drapeTraces(),this.render(),i?.()}).catch(c=>{console.warn("Terrain build failed, keeping the flat ground fallback:",c),i?.()})}grassReference;anchorGrassTo(e,t,i){if(this.grassReference){const r=vt(this.grassReference.lat,this.grassReference.lng,t,i);Math.hypot(r.x,r.z)>2e4&&(this.grassReference=void 0)}this.grassReference??={lat:t,lng:i};const n=vt(this.grassReference.lat,this.grassReference.lng,t,i);e.material.userData?.grassOrigin?.set(n.x,n.z)}static TERRAIN_CROSSFADE_MS=1200;fadingTerrain;crossfadeTerrain(e,t,i){this.stopTerrainFade();const n=e.material;n.opacity=0,n.polygonOffset=!0,n.polygonOffsetFactor=-1,n.polygonOffsetUnits=-4;const s=performance.now(),r=()=>{const a=Math.min(1,(performance.now()-s)/Je.TERRAIN_CROSSFADE_MS);if(n.opacity=a*a*(3-2*a),this.render(),a<1&&this.fadingTerrain){this.fadingTerrain.frameId=requestAnimationFrame(r);return}n.polygonOffset=!1,n.opacity=1,this.fadingTerrain&&this.disposeMesh(this.fadingTerrain.mesh),this.fadingTerrain=void 0,this.render()};this.fadingTerrain={mesh:t,origin:i,frameId:requestAnimationFrame(r)}}stopTerrainFade(){if(!this.fadingTerrain)return;cancelAnimationFrame(this.fadingTerrain.frameId),this.disposeMesh(this.fadingTerrain.mesh),this.fadingTerrain=void 0;const e=this.terrainMesh?.material;e&&(e.opacity=1,e.polygonOffset=!1)}static ROADS_MAX_RADIUS_M=5e3;buildRoads(e,t,i){const n=this.terrainProviders.roads;if(!n||i>Je.ROADS_MAX_RADIUS_M){this.roadSystem.clear(),this.roadAttribution=void 0;return}const s=this.roadWays;if(s&&s.lat===e&&s.lng===t&&s.radiusM===i){this.drapeRoads(s.ways,e,t,n.contemporary);return}s&&Math.hypot(vt(e,t,s.lat,s.lng).x,vt(e,t,s.lat,s.lng).z)<=s.radiusM&&this.drapeRoads(s.ways,e,t,n.contemporary),this.awaitArrival(n.getRoads(l2(e,t,i)),Je.ROADS_PATIENCE_MS).then(r=>{this.terrainOrigin?.lat!==e||this.terrainOrigin?.lng!==t||(this.roadWays={lat:e,lng:t,radiusM:i,ways:r},this.drapeRoads(r,e,t,n.contemporary))}).catch(r=>{console.warn("Roads unavailable, drawing none:",r)})}setStatedRoads(e){e!==this.statedRoads&&(this.statedRoads=e,this.drapeStatedRoads(),this.render())}drapeStatedRoads(){const e=this.terrainMesh;e&&(this.roadSystem.group.position.copy(e.position),this.roadSystem.setGroundSpacing(this.patchSpacingM(e)),this.roadSystem.setStated(this.statedRoads,(t,i)=>this.groundYOfPatch(e,t,i)))}setTraces(e,t=new Map){e===this.traces&&t===this.traceLabels||(this.traces=e,this.traceLabels=t,!(e.length===0&&!this.traceSystem)&&this.loadTraceSystem().then(()=>{this.drapeTraces(),this.render()}))}setTracesShown(e){e!==this.tracesShown&&(this.tracesShown=e,this.drapeTraces(),this.render())}loadTraceSystem(){return this.traceSystemLoading??=Ue(async()=>{const{TraceSystem:e}=await import("./TraceSystem-dUHBN-oM.js");return{TraceSystem:e}},[],import.meta.url).then(({TraceSystem:e})=>{const t=new e(Gp);this.scene.add(t.group),this.traceSystem=t})}drapeTraces(){const e=this.traceSystem,t=this.terrainMesh,i=this.terrainMeshOrigin;!e||!t||!i||(e.group.position.copy(t.position),e.set(this.tracesShown?this.traces:[],this.traceLabels,i.lat,i.lng,this.siteElevationM,(n,s)=>this.groundYOfPatch(t,n,s)))}drapeRoads(e,t,i,n){const s=this.terrainMesh;s&&(this.roadSystem.group.position.copy(s.position),this.roadSystem.setGroundSpacing(this.patchSpacingM(s)),this.roadSystem.set(e,t,i,(r,a)=>this.groundYOfPatch(s,r,a),n,this.terrainRadius),this.roadAttribution=e.length>0?this.terrainProviders.roads?.attribution:void 0,this.compileNextFrameOffThread(),this.render())}setShowCompass(e){this.showCompass!==e&&(this.showCompass=e,this.disposeCompassLabels(),e&&this.buildCompassLabels(),this.render())}setCompassPoints(e){this.compassPoints!==e&&(this.compassPoints=e,this.showCompass&&(this.disposeCompassLabels(),this.buildCompassLabels(),this.render()))}compassPoints;applyLensFlareTint(e){if(!this.lensFlare)return;const t=PC*(this.sunArriving[1]/OC);this.lensFlare.uniforms.uColorGain.value.setRGB(t*e[0],t*e[1],t*e[2]),this.applyDazzleStrength()}applyDazzleStrength(){if(!this.lensFlare)return;const[e,t,i]=this.sunArriving,n=Math.max(t,1e-30);this.lensFlare.uniforms.uDazzleColour.value.setRGB(e/n,1,i/n),this.lensFlare.uniforms.uVeilStrength.value=rn.K*t*this.sunUnhiddenFraction}sunArriving=[0,0,0];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;if(this.compassSprites.some(t=>t.visible!==e)){for(const t of this.compassSprites)t.visible=e;this.developingExposure?this.exposureInstantsDone>0&&this.presentExposure():this.render()}}setWeather(e){if(aC(this.weather,e))return;this.cloudTransmissionMemo.clear();const t=this.weather;this.weather=e;const i=!XC(t,e),n=t.precipitationType!==e.precipitationType,s=t.precipitationIntensity!==e.precipitationIntensity||t.precipitationAmount!==e.precipitationAmount;(t.relativeHumidity!==e.relativeHumidity||n||s)&&(this.air=xs.of(e),this.applyAir(),this.scatteredSky?.setConditions({aerosolOpticalDepth:e.relativeHumidity===void 0?void 0:Hr.steppedOpticalDepth(e.relativeHumidity)}),this.pumpScatteredSky()),i&&(this.buildClouds(),this.buildCirrus()),n?this.buildPrecipitation():s&&this.updatePrecipitationDensity(),this.lastAstronomy&&(i&&(this.buildIceHalos(this.lastAstronomy.sun,this.lastAstronomy.moon),this.buildLunarDiffraction(this.lastAstronomy.moon)),(i||n||s)&&this.buildRainbow(this.lastAstronomy.sun,this.lastAstronomy.moon)),this.lightningArmed=e.storm&&e.cloudDarkness>=jC,this.syncAnimationLoop(),this.render()}setDecor(e){if(this.decorObjects===e)return;this.decorObjects=e,this.decorTerrainRadiusM=Je.terrainReachFor(e,this.observerRoute),this.decorModelToken++,this.decorModelCredits.clear(),this.pendingTrafficModels.clear();for(const i of this.decorGroups.values())i.removeFromParent(),Fe.dispose(i);this.decorGroups.clear(),this.streetlightLights.clear(),this.headlightSystem?.clear(!0),this.headlightSettings.clear();const t=e.filter(i=>i.kind==="streetlight").sort((i,n)=>Math.hypot(i.eastM,i.northM)-Math.hypot(n.eastM,n.northM)).slice(0,yC);for(const i of e){const n=Fe.build(i,i.lit??!1);this.scene.add(n),this.decorGroups.set(i.id,n),i.kind==="streetlight"&&t.includes(i)&&this.addStreetlightLight(i.id,n,t.indexOf(i)<bC),i.model&&i.id.startsWith(Ss.ID_PREFIX)?(this.pendingTrafficModels.set(i.id,i),this.awaitArrival(this.loadDecorModel(i,this.decorModelToken,!0))):this.reuseLoadedDecorModel(i,n)||this.awaitArrival(this.loadDecorModel(i,this.decorModelToken))}e.some(i=>i.kind==="vehicle")&&this.loadHeadlights(),this.syncHeadlightBeams(),this.celestialLight.castShadow=this.decorGroups.size>0||this.bodySystem.any}setDecorSunlight(e){this.decorSunlight=e}setContrails(e){e!==this.contrails&&(this.contrails=e,!(e.length===0&&!this.contrailSystem)&&this.loadContrailSystem().then(()=>{this.contrailSystem?.set(this.contrails),this.updateContrails(),this.render()}))}setContrailSunlight(e){this.contrailSunlight=e}loadContrailSystem(){return this.contrailSystemLoading??=Ue(async()=>{const{ContrailSystem:e}=await import("./ContrailSystem-BZiaCFt7.js");return{ContrailSystem:e}},__vite__mapDeps([0,1]),import.meta.url).then(({ContrailSystem:e})=>{const t=new e;this.scene.add(t.group),this.contrailSystem=t})}contrailTint(e){const t=this.contrailSunlight.get(e),i=this.lastAstronomy?.sun,n=Je.CONTRAIL_SCATTERING,s=this.skyLight.color,r=[s.r*n*.5,s.g*n*.5,s.b*n*.5];if(t&&i){const a=Fn.litFraction(t.sunElevationDeg,t.heightM);if(a>0){const l=this.air.transmittanceFromSpace(t.heightM,t.sunElevationDeg),c=_t.illuminanceOf(i.magnitude)*this.relativeScale;for(let h=0;h<3;h++)r[h]+=n*c*l[h]*a}}return r}static CONTRAIL_SCATTERING=1/(4*Math.PI);updateContrails(){this.contrailSystem?.update(this.decorTime,{origin:this.bodyOrigin,eye:this.camera.position,pixelRad:this.contrailPixelRad()},e=>this.contrailTint(e))}contrailPixelRad(){const e=Math.max(1,this.renderer.getDrawingBufferSize(this.bloomSize).y);return Math.max(this.lampBloomRadiusRad()??0,this.camera.fov*Math.PI/180/e)}setDecorPresence(e){this.decorPresence=e}entryOfDecorModel(e){return this.decorModelProvider.entry(e).catch(()=>{})}setDecorModelProvider(e){this.decorModelProvider=e;const t=this.decorObjects;this.decorObjects=[],this.setDecor(t)}get currentDecorModelCredits(){return[...this.decorModelCredits.values(),...this.bodySystem.modelCredits]}get bodyGround(){const{x:e,z:t}=this.bodyOrigin,i=this.groundYUnder(e,t);return{heightAt:(n,s)=>this.groundYUnder(e+n,t-s)-i}}bodyMaskedByDecor(e,t){const i=this.decorGroups.get(t);return i?this.bodySystem.maskedShare(e,i):void 0}setBodies(e,t=0,i=e.map(r=>r.id),n=[],s){const{x:r,z:a}=this.bodyOrigin,l=this.scatteredSky;this.bodySystem.set(e,{originX:r,originZ:a,originGroundY:this.groundYUnder(r,a),eye:this.camera.position,groundYAt:(h,d)=>this.groundYUnder(h,d),wind:s,light:this.plumeLight(),occluders:[...this.decorGroups.values()],transmittance:(h,d,u)=>this.transmittanceTo(h,d,u)},t,l?(h,d)=>l.relativeOfLuminance(h,d):void 0,i),this.bodySystem.setSmoke(n,t),this.bodySystem.any&&(this.celestialLight.castShadow=!0),this.fitShadowToBodies();const c=this.bodySystem.furthestFrom(this.camera.position)*1.2;c>this.camera.far&&(this.camera.far=c,this.camera.updateProjectionMatrix())}plumeLight(){const e=this.celestialLight.color,t=this.celestialLight.intensity*.5,i=this.skyLight.color,n=this.skyLight.groundColor,s=this.skyLight.intensity,r=(a,l,c)=>(a*t+(l+c)/2*s)/Math.PI;return[r(e.r,i.r,n.r),r(e.g,i.g,n.g),r(e.b,i.b,n.b)]}bodyOutline(e,t){return this.bodySystem.outlineOf(e,t)}documentUrl;modelUrl(e){return e.url?this.documentRelative(e.url):void 0}documentRelative(e){if(e.startsWith("data:"))return e;const t=this.documentUrl??(typeof location>"u"?void 0:location.href);return t?new URL(e,t).href:e}async loadBodyModel(e){const t=e.url?void 0:e.id?await this.decorModelProvider.entry(e.id):void 0,i=this.modelUrl(e)??t?.url,n=e.credit??t?.credit;if(!(!i||!n))return{scene:await zp(i),credit:n,headingOffsetDeg:e.headingOffsetDeg??t?.headingOffsetDeg}}loadedDecorModels=new Map;reuseLoadedDecorModel(e,t){const i=this.loadedDecorModels.get(e.id);return!i||i.ref!==JSON.stringify(mh(e))||!Fe.usesModel(e)?!1:(this.applyLoadedDecorModel(e,t,i),!0)}applyLoadedDecorModel(e,t,i){const n=i.scene.clone(!0);n.traverse(s=>{s instanceof Se&&(s.userData.sharedModel=!0)}),Fe.applyModelParameters(n,e.modelParameters,i.bindings),Fe.applyModel(t,e,n,{headingOffsetDeg:i.headingOffsetDeg,depictedSizeM:i.depictedSizeM}),this.decorModelCredits.set(e.id,i.credit)}standInScenes=new Map;async loadDecorModel(e,t,i=!1){const n=i?ku[e.kind]:mh(e);if(!(!n||!Fe.usesModel(e)))try{const s=n.url?void 0:n.id?await this.decorModelProvider.entry(n.id):void 0,r=this.modelUrl(n)??s?.url,a=n.credit??s?.credit;if(!r||!a)return;const l=i||e.kind==="tree"?await this.standInScene(r):await zp(r);if(t!==this.decorModelToken||i&&!this.pendingTrafficModels.has(e.id))return;const c=this.decorGroups.get(e.id);if(!c)return;!i&&e.kind!=="tree"&&Jn.reflectOn(l);const h={ref:JSON.stringify(n),scene:l,headingOffsetDeg:n.headingOffsetDeg??s?.headingOffsetDeg,depictedSizeM:s?.sizeM,credit:a,bindings:s?.parameters?.bindings};i||this.loadedDecorModels.set(e.id,h),this.applyLoadedDecorModel(e,c,h),this.render()}catch(s){console.warn(`Keeping the built-in shape for decor "${e.id}":`,s)}}standInScene(e){let t=this.standInScenes.get(e);return t||(t=zp(e).then(i=>(/jungle-jim-realistic-trees/.test(e)||Jn.reflectOn(i),i)),this.standInScenes.set(e,t)),t}updateDecorAnchoring(e,t,i=0){this.decorReferencePose=e,this.decorCurrentPose=t,this.decorTime=i;const n=e?.lat!==void 0&&e.lng!==void 0&&t?.lat!==void 0&&t?.lng!==void 0?vt(e.lat,e.lng,t.lat,t.lng):{x:0,z:0},s=this.decorObjects.find(u=>u.observerSide!==void 0&&ka(u.kind));this.terrainMesh&&t?.lat!==void 0&&t.lng!==void 0&&(this.placeTerrain(t.lat,t.lng,s?0:this.gaitOffset.eastM,s?0:this.gaitOffset.northM),this.roadSystem.group.position.copy(this.terrainMesh.position),this.traceSystem?.group.position.copy(this.terrainMesh.position)),s||(n.x-=this.gaitOffset.eastM,n.z+=this.gaitOffset.northM,this.camera.position.y=this.poseCameraY+this.gaitOffset.upM,this.celestialGroup.position.y=this.camera.position.y);const r={x:0,z:0};let a=0,l;if(s){const u=Gs(s,i),f=Fe.occupantView(s,u.headingDeg),p=-(u.headingDeg??0)*Ci,g=f.x*Math.cos(p)+f.z*Math.sin(p),m=-f.x*Math.sin(p)+f.z*Math.cos(p),v=u.eastM+n.x,b=-u.northM+n.z;r.x=-(v+g),r.z=-(b+m),this.camera.position.y=this.groundYUnder(v,b)+f.eyeY,l=f.eyeY,this.camera.rotation.set(this.indoorLookPitchDeg*Ci,-(f.headingDeg+this.indoorLookYawDeg)*Ci,0,"YXZ")}this.bodyOrigin={x:n.x+r.x,z:n.z+r.z};const c=this.findCabin(i,n,r);this.fitShadowToCabin(c.length>0),this.dimCabinSky(c),this.placeShadowFrustum(),this.placeTerraces(i,n,r);const h=this.terraces.map(u=>[u.x,u.z,u.cos,u.sin,u.halfWidthM,u.halfLengthM,u.levelY].map(f=>f.toFixed(3)).join(",")).join(";");!s&&this.terraces.length>0&&(this.poseCameraY=this.groundYUnder(0,0)+1.6+this.poseElevationM,this.camera.position.y=this.poseCameraY+this.gaitOffset.upM,this.celestialGroup.position.y=this.camera.position.y);for(const u of this.decorObjects){if(u.kind==="terrace")continue;const f=this.decorGroups.get(u.id);if(!f)continue;const p=Gs(u,i),g=p.eastM+n.x+r.x,m=-p.northM+n.z+r.z,v=this.terrainMesh,b=`${v?.geometry.uuid}:${(g-(v?.position.x??0)).toFixed(3)}:${(m-(v?.position.z??0)).toFixed(3)}:${(v?.position.y??0).toFixed(3)}:${p.headingDeg}:${p.altitudeM}:${h}`;if(f.userData.footprintKey!==b){if(u.kind==="wire"){const M=Fe.wireGround(u,g,m,p.headingDeg,(_,I)=>this.groundYUnder(_,I));f.userData.footprintGroundY=M.startY,Fe.shearWire(f,Fe.sizeOf(u).lengthM,M.dropM)}else f.userData.footprintGroundY=this.groundUnderFootprint(u,g,m,p.headingDeg,p.altitudeM);f.userData.footprintKey=b}const y=p.altitudeM>Je.AIRBORNE_M&&Math.hypot(g,m)<Je.CABIN_MATE_RANGE_M?this.poseCameraY-1.6-this.poseElevationM:f.userData.footprintGroundY;if(f.position.set(g,y+p.altitudeM,m),u.kind==="crop"){const M=Math.hypot(g,m);f.visible=M<=FC}const w=this.decorPresence.get(u.id),S=w!==void 0&&(i<w.fromMs||i>w.untilMs);w&&(f.visible=!S);const A=this.decorSunlight.get(u.id);if(A&&!S&&this.lightFromAbove(f,A),p.headingDeg!==void 0&&(f.rotation.y=-p.headingDeg*Ci),u.kind==="crop"&&f.visible){const M=this.terrainMesh,_=[M?.geometry.uuid,g-(M?.position.x??0),m-(M?.position.z??0),f.position.y-(M?.position.y??0),p.headingDeg,p.altitudeM].map(I=>typeof I=="number"?I.toFixed(4):I).join(":");f.userData.cropGroundKey!==_&&(Fe.fitCropToGround(f,(I,R)=>this.groundYUnder(I,R)+p.altitudeM),f.userData.cropGroundKey=_)}if(!S){const M=f.position.distanceTo(this.camera.position);a=Math.max(a,M),M<Je.trafficModelRangeM(u)&&this.pendingTrafficModels.delete(u.id)&&this.loadDecorModel(u,this.decorModelToken)}}if(s&&l!==void 0){const u=this.decorGroups.get(s.id);u&&(this.camera.position.y=u.position.y+l)}this.updateContrails();const d=Math.max(Ld*1.2,this.groundRadius*2.5,a*1.2);Math.abs(this.camera.far-d)>1&&(this.camera.far=d,this.camera.updateProjectionMatrix())}groundYUnder(e,t){const i=this.terrainYUnder(e,t);let n=i;for(const s of this.terraces){const r=e-s.x,a=t-s.z,l=r*s.cos-a*s.sin,c=r*s.sin+a*s.cos;if(Math.abs(l)<=s.halfWidthM&&Math.abs(c)<=s.halfLengthM){const h=Math.min(1,Math.max(0,(s.halfWidthM-Math.abs(l))/s.bankM)),d=h*h*(3-2*h);n=Math.max(n,d*s.levelY+(1-d)*Math.min(s.levelY,i))}}return n}placeTerraces(e,t,i){this.terraces=[];const n=this.terrainMesh;for(const s of this.decorObjects){if(s.kind!=="terrace")continue;const r=this.decorGroups.get(s.id);if(!r)continue;const a=Gs(s,e),l=a.eastM+t.x+i.x,c=-a.northM+t.z+i.z,h=Fe.sizeOf(s),d=-(a.headingDeg??0)*Ci,u=Math.cos(d),f=Math.sin(d),p=`${n?.geometry.uuid}:${(l-(n?.position.x??0)).toFixed(3)}:${(c-(n?.position.z??0)).toFixed(3)}:${(n?.position.y??0).toFixed(3)}:${a.headingDeg}:${h.widthM}:${h.lengthM}:${h.heightM}`;r.position.set(l,0,c),a.headingDeg!==void 0&&(r.rotation.y=d),r.userData.terraceKey!==p&&(r.userData.terraceLevelY=Fe.fitTerrace(r,s,(g,m)=>this.terrainYUnder(l+g*u+m*f,c-g*f+m*u)),r.userData.terraceKey=p),this.terraces.push({x:l,z:c,cos:u,sin:f,halfWidthM:h.widthM/2,halfLengthM:h.lengthM/2,levelY:r.userData.terraceLevelY,bankM:Math.min(10,h.widthM/4)})}}terrainYUnder(e,t){const i=this.terrainMesh;return i?i.position.y+this.groundYOfPatch(i,e-i.position.x,t-i.position.z):Jp}patchSpacingM(e){const t=e.geometry.getAttribute("position");return t&&t.count>=2?Math.abs(t.getX(1)-t.getX(0)):1/0}groundYOfPatch(e,t,i){const n=e.geometry.getAttribute("position"),s=Math.round(Math.sqrt(n.count));if(s<2||s*s!==n.count)return Jp;const r=n.getX(0),a=n.getX(s-1),l=n.getZ(0),c=n.getZ((s-1)*s),h=sr((t-r)/(a-r)*(s-1),0,s-1),d=sr((i-l)/(c-l)*(s-1),0,s-1);if(!Number.isFinite(h)||!Number.isFinite(d))return Jp;const u=Math.min(Math.floor(h),s-2),f=Math.min(Math.floor(d),s-2),p=h-u,g=d-f,m=(w,S)=>n.getY(w*s+S),v=m(f,u),b=m(f,u+1),x=m(f+1,u),y=m(f+1,u+1);return p+g<=1?v+(b-v)*p+(x-v)*g:y+(x-y)*(1-p)+(b-y)*(1-g)}groundUnderFootprint(e,t,i,n,s=0){return Fe.groundUnderFootprint(e,t,i,n,(r,a)=>this.groundYUnder(r,a),s)}lookYawDeg=0;lookPitchDeg=0;poseCameraY=1.6;poseElevationM=0;setGait(e){this.gaitOffset=e}gaitOffset={eastM:0,northM:0,upM:0,rollDeg:0,pitchDeg:0,yawDeg:0};setLookOffset(e,t){this.lookYawDeg=e,this.lookPitchDeg=t}indoorLookYawDeg=0;indoorLookPitchDeg=0;setIndoorLook(e,t){this.indoorLookYawDeg=e,this.indoorLookPitchDeg=t}medium;setMedium(e,t,i,n){const s=e&&t!==void 0&&t>0&&i!==void 0&&i>0?{kind:e.kind,iso:n??e.iso,autoExposure:e.autoExposure===!0,exposureSeconds:t,fNumber:i}:void 0;JSON.stringify(s)!==JSON.stringify(this.medium)&&(this.medium=s,this.render())}applyMedium(){const e=this.medium,t=Math.max(this.relativeScale,1e-30);if(!e){Ln.uMedium.value=0;return}Ln.uMedium.value=e.kind==="negative"?1:e.kind==="slide"?2:3;const i=e.autoExposure?this.scatteredSky?.sceneAdaptation:void 0;Ln.uMediumExposure.value=i!==void 0&&i>0?1/(t*i):.065*e.exposureSeconds*e.iso*this.filterTransmittance/(e.fNumber*e.fNumber*t)}grain;lampBloomRadiusRad(){if(!this.grain)return;const e=this.camera.fov*Math.PI/180,t=this.grain.frameHeightMm/(2*Math.tan(e/2)),i=Math.max(1,this.renderer.getDrawingBufferSize(this.bloomSize).y);return Math.max(this.grain.detailUm*.001/t,e/i)}bloomSize=new we;lampTransmittance(e){const t=this.siteElevationM+this.camera.position.y,i=this.siteElevationM+e.position.y;return this.air.transmittance(t,i,e.position.distanceTo(this.camera.position))}updateDecorLitState(e,t=0){const i=this.lampBloomRadiusRad();for(const n of this.decorObjects){const s=this.decorGroups.get(n.id);if(s&&n.lights?.length&&Fe.setLights(s,n.lights,e,s.position.distanceTo(this.camera.position),t,this.relativeScale,i,this.lampTransmittance(s)),n.kind!=="streetlight"&&n.kind!=="vehicle")continue;const r=this.decorGroups.get(n.id);if(!r)continue;const a=n.kind==="streetlight"&&n.origin!==void 0&&n.lit===void 0&&!n.litKeyframes?.length&&this.lastAstronomy,l=n.kind==="vehicle"?_M(n,e):void 0,c=a?this.lastAstronomy.sun.altitudeDeg<MC:l!==void 0?Ca.lamps(l):Mf(n,e);Fe.setLit(r,n.kind,c,this.relativeScale);const h=this.streetlightLights.get(n.id);h&&(h.visible=c),l!==void 0&&(this.headlightSettings.set(n.id,l),this.aimDecorBeam(n,r,l))}this.aimObserverBeam()}loadHeadlights(){return this.headlightSystem?Promise.resolve():this.headlightLoading??=Ue(async()=>{const{HeadlightSystem:e}=await import("./HeadlightSystem-BipIIHQg.js");return{HeadlightSystem:e}},[],import.meta.url).then(({HeadlightSystem:e})=>{this.headlightSystem??=new e(this.scene),this.syncHeadlightBeams(),this.compileNextFrameOffThread(),this.render()})}syncHeadlightBeams(){const e=this.headlightSystem;if(e){for(const t of this.decorObjects)t.kind==="vehicle"&&e.add(t.id);this.observerHeadlights&&e.add("observer"),this.aimBeams()}}aimBeams(){if(!(!this.headlightSystem||this.headlightSystem.size===0)){for(const e of this.decorObjects){const t=this.headlightSettings.get(e.id),i=this.decorGroups.get(e.id);t!==void 0&&i&&this.aimDecorBeam(e,i,t)}this.aimObserverBeam()}}headlightScatterPerM(){const e=this.siteElevationM+this.camera.position.y,t=200,i=this.air.transmittance(e,e,t)[1];return i>0?-Math.log(Math.min(1,i))/t:.05}aimDecorBeam(e,t,i){if(!this.headlightSystem?.has(e.id))return;t.updateMatrixWorld(!0);const n=new D(0,0,-1).transformDirection(t.matrixWorld);if(n.y=0,n.lengthSq()<1e-9)return;n.normalize();const s=Fe.sizeOf(e).lengthM,r=t.getWorldPosition(new D).addScaledVector(n,s/2-xC);r.y+=wC;const a=Fe.sizeOf(e).widthM;this.headlightSystem.aim(e.id,i,r,n,a*SC,this.relativeScale,this.headlightScatterPerM())}setObserverHeadlights(e){this.observerHeadlights=e,e&&this.loadHeadlights(),this.headlightSystem&&(e?this.headlightSystem.add("observer"):this.headlightSystem.remove("observer"),this.aimObserverBeam())}aimObserverBeam(){const e=this.observerHeadlights;if(!e||!this.headlightSystem?.has("observer"))return;const t=e.setting==="auto"?this.lastAstronomy?Ca.auto(this.lastAstronomy.sun.altitudeDeg):"off":e.setting,i=e.headingDeg*Math.PI/180,n=new D(Math.sin(i),0,-Math.cos(i)),s=new D(n.x*db,this.camera.position.y-AC,n.z*db);this.headlightSystem.aim("observer",t,s,n,EC,this.relativeScale,this.headlightScatterPerM())}addStreetlightLight(e,t,i){const n=Fe.bodyOf(t),s=n.children.find(a=>a.userData.emissive);if(!s)return;const r=new Sw(16764006,hb*this.relativeScale,_C);r.position.copy(s.position).multiply(n.scale),r.castShadow=i,r.shadow.mapSize.set(512,512),r.shadow.bias=-.002,t.add(r),this.streetlightLights.set(e,r)}applyWindowGlow(){const e=this.lastAstronomy;Fe.setLitWindowShare(e?dn.share(e.sun.altitudeDeg,e.localHour):0)}setAstronomy(e){(!this.lastAstronomy||Math.abs(this.lastAstronomy.sun.altitudeDeg-e.sun.altitudeDeg)>2)&&(this.surroundings=void 0,this.scatteredSky?.resetSurroundings()),this.lastAstronomy=e,this.applyWindowGlow(),this.scatteredSky?.update(this.scatteredSkyState(e)),this.skyHoldUntilMs===void 0&&this.startHold(),this.pumpScatteredSky(),this.lastSunPosition=e.sun,this.buildSky(e.sun),this.buildGround();const t=this.magnitudeLimitOf(e);this.buildStars(e.stars,t),this.placeBodies(e,t),this.buildIceHalos(e.sun,e.moon),this.buildRainbow(e.sun,e.moon),this.applySkyColours(e),this.syncAnimationLoop(),this.render()}static relativeSkyOf(e,t){const i=r=>{const a=Hs.luminanceOf(r);if(!(a>0))return[0,0,0];const l=Ie.relativeOfResponse(a)/a;return[r[0]*l,r[1]*l,r[2]*l]},n=i(e.zenith),s=i(e.horizon);return{zenith:n,horizon:s,airlight:s,skyIrradiance:[n[0]*Math.PI,n[1]*Math.PI,n[2]*Math.PI],scale:t}}placeBodies(e,t){this.bodiesScale=this.relativeScale,this.sunBeamFraction=_i.beamFraction(e.eclipse),this.setBodyMesh("sun",e.sun,lb,new ne(1,.96,.88),e.sun.magnitude),this.placeEclipse(e),this.setMoonMesh(e.moon,t),this.buildPlanets(e.planets,t),this.buildComet(e.comet,t),this.buildNovae(e.novae??[],t)}placeEclipse(e){const t=e.eclipse;if(!t||e.sun.altitudeDeg<au){this.eclipsedSun.setMoon(void 0),this.eclipseDiscs=void 0,this.solarCorona?.show(void 0,[0,0,0]);return}const i=lb/Wn*(180/Math.PI),n=i/t.sunRadiusDeg,s=ni(e.sun.altitudeDeg,e.sun.azimuthDeg,1),r=ni(e.moon.altitudeDeg,e.moon.azimuthDeg,1),a=Math.acos(sr(s.x*r.x+s.y*r.y+s.z*r.z,-1,1)),l=a>1e-9?sr(t.separationDeg*n*Ci/a,0,2):0,c=Math.sin(a),[h,d]=a>1e-9?[Math.sin((1-l)*a)/c,Math.sin(l*a)/c]:[1,0],u={x:s.x*h+r.x*d,y:s.y*h+r.y*d,z:s.z*h+r.z*d},f=t.moonRadiusDeg*n;this.eclipseDiscs={sun:new D(s.x,s.y,s.z).normalize(),moon:new D(u.x,u.y,u.z).normalize(),sunRadiusRad:i*Ci,moonRadiusRad:f*Ci};const p=.01,g=(b,x)=>ni(e.sun.altitudeDeg+b,e.sun.azimuthDeg+x,1),m={x:g(p,0).x-g(-p,0).x,y:g(p,0).y-g(-p,0).y,z:g(p,0).z-g(-p,0).z},v={x:g(0,p).x-g(0,-p).x,y:g(0,p).y-g(0,-p).y,z:g(0,p).z-g(0,-p).z};if(this.eclipsedSun.setMoon(u,f,t.limb?{profile:t.limb,scale:n,up:m,right:v}:void 0),t.obscuration<.9){this.solarCorona?.show(void 0,[0,0,0]);return}this.solarCorona||(this.solarCorona=new Pl(i*Math.PI/180,this.eclipsedSun.cut),this.celestialGroup.add(this.solarCorona.object)),this.solarCorona.show(s,this.sunDiscRadiance)}bodiesScale=0;applySkyColours(e){this.skyColoursStale=!1,this.bodiesScale!==this.relativeScale&&(this.placeBodies(e,this.magnitudeLimitOf(e)),this.applyDazzleStrength(),this.buildIceHalos(e.sun,e.moon),this.buildRainbow(e.sun,e.moon));const t=this.scatteredSky?.ambient??Je.relativeSkyOf(Em(e.sun.altitudeDeg),this.relativeScale),i=t,n=this.lightUnderClouds(e),s=r=>n?[0,1,2].map(a=>r[a]*n.through+n.radiance[a]*(1-n.through)):[r[0],r[1],r[2]];this.baseFogColor=[i.horizon[0],i.horizon[1],i.horizon[2]],this.airlight=s(i.airlight),this.skyMesh&&this.skyGradientMaterial&&(this.skyMesh.material=this.scatteredSky?.ready?this.scatteredSky.material:this.skyGradientMaterial),this.updateCelestialLight(e,t),this.updateCloudLighting(e.sun,this.baseFogColor),Ce.setEye(this.scatteredSky?.rodShare??0,this.relativeScale),this.updateTwinkle(this.twinkleSeconds);for(const r of this.streetlightLights.values())r.intensity=hb*this.relativeScale;this.buildSkyGlow(e,i.zenith),this.applyAir(),this.buildLunarDiffraction(e.moon)}reflections;sceneVersion=0;reflectionTimer;buildLunarDiffraction(e){const t=this.scatteredSky?.ready?this.scatteredSky:void 0;if(e.altitudeDeg<-.5||!t){this.lunarDiffraction?.show(void 0),this.lunarDiffractionKey="";return}const i=this.weather.relativeHumidity,n=(i===void 0?He.DEFAULT_AEROSOL_OPTICAL_DEPTH:Hr.opticalDepth(i))*He.aerosolDensity(this.siteElevationM+this.observerElevationM),s=this.cloudTransmission(e),r=-Math.log(Math.max(this.cloudTransmission(e,!0),1e-4)),a=_t.aureoleScale(n,_t.airMass(e.altitudeDeg))*s,l=_t.coronaScale(r),c=_t.illuminanceOf(e.magnitude),h=[e.altitudeDeg.toFixed(1),e.azimuthDeg.toFixed(1),e.magnitude.toFixed(2),a.toExponential(2),l.toExponential(2),Math.log10(Math.max(t.adaptation,1e-12)).toFixed(2)].join(":");if(h===this.lunarDiffractionKey)return;this.lunarDiffractionKey=h,this.lunarDiffraction||(this.lunarDiffraction=new Yg,this.celestialGroup.add(this.lunarDiffraction.object));const d=_t.profile(_t.HAZE_COARSE_MODE),u=_t.profile(_t.CLOUD_DROPLETS),f=Ey(e.altitudeDeg),p=new Float32Array(_t.STEPS*3);let g=0;for(let x=0;x<_t.STEPS;x++){const y=x*3,w=[0,1,2].map(A=>c*f[A]*(a*d[y+A]+l*u[y+A])),S=Hs.shown(w,Hs.luminanceOf(w),(A,M)=>t.relativeOfLuminance(A,M));p.set(S,y),g=Math.max(g,Hs.response(S))}const{x:m,y:v,z:b}=ni(e.altitudeDeg,e.azimuthDeg,1);this.lunarDiffraction.show(g>1/200?{x:m,y:v,z:b}:void 0,p)}applyAir(){this.scene.fog instanceof ko||(this.scene.fog=new ko),this.scene.fog.setAir(this.air,this.siteElevationM,this.airlight)}airlight=[0,0,0];transmittanceTo(e,t,i){const n=this.camera.position;return this.air.transmittance(this.siteElevationM+n.y,this.siteElevationM+t,Math.hypot(e-n.x,t-n.y,i-n.z))}setSiteElevation(e){Math.abs(e-this.siteElevationM)<1||(this.siteElevationM=e,this.applyAir(),this.lastAstronomy&&this.scatteredSky?.update(this.scatteredSkyState(this.lastAstronomy)))}umbraTint(){const e=this.siteElevationM+this.observerElevationM+1.6,[t,i,n]=this.air.transmittance(e,e,Je.UMBRA_PATH_M),s=.2126*t+.7152*i+.0722*n;return s>0?[(.4124*t+.3576*i+.1805*n)/s,1,(.0193*t+.1192*i+.9505*n)/s]:[.9505,1,1.089]}static UMBRA_PATH_M=8e4;umbraOf(e){const t=e.eclipse?.horizonShare;return t&&Math.max(...t)<.1?{share:t,tint:this.umbraTint()}:void 0}scatteredSkyState(e){return{altitudeM:this.siteElevationM+this.observerElevationM+1.6,lightPollution:this.lightPollution,sun:{altitudeDeg:e.sun.altitudeDeg,azimuthDeg:e.sun.azimuthDeg,magnitude:e.sun.magnitude},sunLight:_i.beamFraction(e.eclipse),zenithFloorCdM2:e.eclipse?_i.UMBRA_ZENITH_CD_M2:void 0,umbra:this.umbraOf(e),moon:{altitudeDeg:e.moon.altitudeDeg,azimuthDeg:e.moon.azimuthDeg,magnitude:e.moon.magnitude,phaseAngleDeg:ce.phaseAngleOf(e.moon.phase.illuminatedFraction)}}}pumpScatteredSky(){const e=this.scatteredSky;!e||e.tables.ready||this.scatteredSkyFrameId!==null||this.contextReleased||this.suspended||(this.scatteredSkyFrameId=requestAnimationFrame(()=>{this.scatteredSkyFrameId=null,!this.contextReleased&&(e.advance(this.skyHoldUntilMs?DC:IC),this.pumpScatteredSky())}))}cancelScatteredSkyPump(){this.scatteredSkyFrameId!==null&&(cancelAnimationFrame(this.scatteredSkyFrameId),this.scatteredSkyFrameId=null)}setSatellites(e){if(e.length===0&&!this.satelliteField?.count)return;this.satelliteField||(this.satelliteField=new I4(Wp),this.celestialGroup.add(this.satelliteField.object));const t=this.lastAstronomy?this.magnitudeLimitOf(this.lastAstronomy):Aa(-90,this.instrumentMagnitudeGain);this.satelliteField.set(e,t,i=>this.cloudTransmission(i),(i,n)=>this.arrivingIlluminance(i,n,1)),this.render()}setReentries(e){if(e.length===0&&!this.reentrySystem?.count)return;this.reentrySystem||(this.reentrySystem=new $n,this.celestialGroup.add(this.reentrySystem.object));const t=this.lastAstronomy?this.magnitudeLimitOf(this.lastAstronomy):Aa(-90,this.instrumentMagnitudeGain);this.reentrySystem.set(e,t,i=>this.cloudTransmission(i),(i,n)=>this.arrivingIlluminance(i,n,1)),this.render()}setLaunchPlumes(e){e.length===0&&!this.plumeSystem?.count||(this.plumeSystem||(this.plumeSystem=new hn,this.celestialGroup.add(this.plumeSystem.object)),this.plumeSystem.set(e,this.relativeScale,t=>this.air.transmittanceFromSpace(this.siteElevationM+this.observerElevationM,t.altitudeDeg),t=>this.cloudTransmission(t)),this.render())}get plumePuffCount(){return this.plumeSystem?.count??0}get reentryCount(){return this.reentrySystem?.count??0}pickTrafficAt(e,t){this.aimAtScreenPoint(this.raycaster,e,t);const i=this.raycaster.ray.direction,n=Math.cos(Xp*this.camera.fov*Math.PI/180);let s,r=n;const a=new D;for(const[l,c]of this.decorGroups){if(!c.visible||!l.startsWith(Ss.ID_PREFIX))continue;a.copy(c.position).sub(this.camera.position).normalize();const h=a.dot(i);h>r&&(r=h,s=l)}return s&&!this.groundHides(e,t)?s:void 0}pickSatelliteAt(e,t){if(!this.satelliteField?.count)return;this.aimAtScreenPoint(this.raycaster,e,t);const i=Math.cos(Xp*this.camera.fov*Math.PI/180),n=this.satelliteField.nearest(this.raycaster.ray.direction,i);return n&&this.groundHides(e,t)?void 0:n}updateCelestialLight(e,t){const i=this.relativeScale,n=e.sun.altitudeDeg>=Fc,s=!n&&e.moon.altitudeDeg>=Fc,r=n?e.sun:e.moon,a=[0,0,0],l=Math.max(0,Math.sin(Math.max(r.altitudeDeg,0)*Ci)),c=this.siteElevationM+this.observerElevationM;let h=r,d=n||s?nb.directFraction(r.altitudeDeg,c):0;n&&d<=0&&e.moon.altitudeDeg>=Fc&&(h=e.moon,d=nb.directFraction(h.altitudeDeg,c));const u=Math.max(0,Math.sin(Math.max(h.altitudeDeg,0)*Ci)),f=n||s?this.cloudTransmission(r):1,p=-Math.log(Math.max(f,1e-6)),g=Math.max(0,1/(1+.1125*p)-f),m=[0,0,0];if(n||s){const S=_t.illuminanceOf(r.magnitude)*i,A=this.air.transmittanceFromSpace(c,r.altitudeDeg);for(let R=0;R<3;R++)m[R]=S*A[R]*g*l,this.cloudBeam[R]=S*A[R];const{x:M,y:_,z:I}=ni(r.altitudeDeg,r.azimuthDeg,1);if(this.cloudBeamDirection.set(M,_,I),d>0){const R=_t.illuminanceOf(h.magnitude)*i,L=h===r?A:this.air.transmittanceFromSpace(c,h.altitudeDeg),P=h===r?f:this.cloudTransmission(h);for(let O=0;O<3;O++)a[O]=R*L[O]*P*d}}else this.cloudBeam.fill(0);const v=this.surroundings;if(v)this.skyLight.color.setRGB(v.up[0]*i,v.up[1]*i,v.up[2]*i),this.skyLight.groundColor.setRGB(v.down[0]*i,v.down[1]*i,v.down[2]*i);else{const S=this.skyCloudTransmission(),A=t.skyIrradiance,M=[0,1,2].map(I=>A[I]*S+m[I]);this.skyLight.color.setRGB(M[0],M[1],M[2]);const _=Ye.GROUND_ALBEDO;this.skyLight.groundColor.setRGB(_*(M[0]+a[0]*u),_*(M[1]+a[1]*u),_*(M[2]+a[2]*u))}if(this.skyLight.intensity=1,this.sceneSunBeam=h===e.sun?[a[0],a[1],a[2]]:[0,0,0],!n&&!s||d<=0){this.celestialLight.intensity=0;return}const{x:b,y:x,z:y}=ni(h.altitudeDeg,h.azimuthDeg,1);this.lightDirection.set(b,x,y),this.celestialLight.shadow.normalBias=ob*sr(x/uC,.1,1),this.placeShadowFrustum();const w=Math.max(a[0],a[1],a[2],1e-30);this.celestialLight.color.setRGB(a[0]/w,a[1]/w,a[2]/w),this.celestialLight.intensity=w,this.celestialLight.castShadow=this.decorGroups.size>0||this.bodySystem.any}static MEAN_COSINE=.5;static ABOVE_CLOUD_M=8e3;lightFromAbove(e,t){const i=this.lastAstronomy?.sun,n=[0,0,0];if(i){const s=Fn.litFraction(t.sunElevationDeg,t.heightM);if(s>0){const r=this.air.transmittanceFromSpace(t.heightM,t.sunElevationDeg),a=_t.illuminanceOf(i.magnitude)*this.relativeScale,l=t.heightM>=Je.ABOVE_CLOUD_M?1:this.cloudTransmission(i);for(let c=0;c<3;c++)n[c]=Math.max(0,a*r[c]*s*l-this.sceneSunBeam[c])}}e.traverse(s=>{const r=s.material;if(!(r instanceof Oa||r instanceof Ma)||s.userData.emissive)return;r.map&&!r.emissiveMap&&(r.emissiveMap=r.map,r.needsUpdate=!0);const a=Je.MEAN_COSINE/Math.PI;r.emissive.setRGB(r.color.r*n[0]*a,r.color.g*n[1]*a,r.color.b*n[2]*a)})}lightDirection=new D(0,1,0);placeShadowFrustum(){const e=this.lightDirection,t=this.celestialLight.shadow.camera,i=(t.right-t.left)/this.celestialLight.shadow.mapSize.x,n=this.shadowAxisX.crossVectors(this.shadowUp,e);n.lengthSq()<1e-8&&n.set(1,0,0),n.normalize();const s=this.shadowAxisY.crossVectors(e,n).normalize(),r=this.shadowWorld.set(this.bodyOrigin.x,this.cabinShadow?this.camera.position.y:0,this.bodyOrigin.z),a=c=>{const h=r.dot(c)/i;return(h-Math.round(h))*i},l=this.celestialLightTarget.position.set(0,this.cabinShadow?this.camera.position.y:0,0).addScaledVector(n,a(n)).addScaledVector(s,a(s));this.celestialLightTarget.updateMatrixWorld(),this.celestialLight.position.copy(l).addScaledVector(e,this.shadowLightDistanceM)}fitShadowToCabin(e){if(e===this.cabinShadow)return;this.cabinShadow=e;const t=this.celestialLight.shadow;if(!e){this.shadowHalfExtentM=-1;return}const i=t.camera,n=dC;i.left=-n,i.right=n,i.top=n,i.bottom=-n,this.shadowHalfExtentM=n,this.shadowLightDistanceM=Od+5,i.near=this.shadowLightDistanceM-Od,i.far=this.shadowLightDistanceM+Od,i.updateProjectionMatrix(),t.bias=-.004/(2*Od),t.mapSize.x!==2048&&(t.mapSize.set(2048,2048),t.map?.dispose(),t.map=null)}static CABIN_SKY_SHARE=.3;dimCabinSky(e){for(const t of e)t.traverse(i=>{const n=i.material;for(const s of Array.isArray(n)?n:n?[n]:[]){const r=s;r.isMeshStandardMaterial&&r.envMapIntensity!==Je.CABIN_SKY_SHARE&&(r.envMapIntensity=Je.CABIN_SKY_SHARE)}})}cabinShadow=!1;fitShadowToBodies(){if(this.cabinShadow)return;const e=this.bodySystem.reachFrom(this.camera.position),t=Math.min(hC,Math.max(oa,Math.ceil(e*1.25/20)*20));if(t===this.shadowHalfExtentM)return;this.shadowHalfExtentM=t;const i=this.celestialLight.shadow,n=i.camera;n.left=-t,n.right=t,n.top=t,n.bottom=-t;const s=Math.max(Nc,t*(Nc/oa));this.shadowLightDistanceM=Math.max(Wn,s+10),n.near=this.shadowLightDistanceM-s,n.far=this.shadowLightDistanceM+s,n.updateProjectionMatrix(),i.bias=-.03/(2*s);const r=t>2*oa?2048:1024;i.mapSize.x!==r&&(i.mapSize.set(r,r),i.map?.dispose(),i.map=null),this.placeShadowFrustum()}shadowHalfExtentM=oa;shadowLightDistanceM=Wn;shadowUp=new D(0,1,0);shadowAxisX=new D;shadowAxisY=new D;shadowWorld=new D;skyCloudTransmission(){let e=this.cloudTransmission({altitudeDeg:90,azimuthDeg:0}),t=1;for(const i of[20,45,70]){const n=i*Ci,s=Math.sin(n)*Math.cos(n)*2;for(let r=0;r<360;r+=60)e+=s*this.cloudTransmission({altitudeDeg:i,azimuthDeg:r}),t+=s}return e/t}cloudBeam=[0,0,0];cloudBeamDirection=new D(0,1,0);get relativeScale(){return this.scatteredSky?.relativeScale??1/Ie.semiSaturation(Ie.DAYLIGHT_ANCHOR_CD_M2)}setMeteorShower(e,t,i){this.meteorSystem||(this.meteorSystem=new tn,this.celestialGroup.add(this.meteorSystem.object)),this.meteorSystem.setShower(e,t,i)}get meteorSchedule(){return this.meteorSystem?.schedule??[]}meteorMidpoint(e){return this.meteorSystem?.midpointOf(e)}updateMeteors(e){this.meteorSystem?.update(e)}setInstrument(e){this.projectionKind=e.projection,this.grain=e.detailUm!==void 0&&e.frame?{detailUm:e.detailUm,frameHeightMm:e.frame.heightMm}:void 0;const t=Bt.starPointsOf(e),i=Bt.flareArtifactsOf(e);t===this.starPoints&&i===this.lensFlareArtifactIntensity||(this.starPoints=t,this.lensFlareArtifactIntensity=i,this.lensFlare&&(this.lensFlare.uniforms.uStarPoints.value=t,this.lensFlare.uniforms.uFlareIntensity.value=i),this.render())}magnitudeLimitOf(e){const t=ce.starLossMagnitudes(e.sun.altitudeDeg,{phaseAngleDeg:ce.phaseAngleOf(e.moon.phase.illuminatedFraction),altitudeDeg:e.moon.altitudeDeg},this.lightPollution);return Aa(e.sun.altitudeDeg,this.instrumentMagnitudeGain,t)}setLightPollution(e){e!==this.lightPollution&&(this.lightPollution=e,this.lastAstronomy&&this.scatteredSky?.update(this.scatteredSkyState(this.lastAstronomy)))}setInstrumentGain(e,t=!1,i=0){const n=Number.isFinite(e)?e:0;this.instrumentMagnitudeGain=n-2.5*i,this.filterTransmittance=10**-i,this.scatteredSky?.setInstrument(t,n,i)}filterTransmittance=1;render(){this.restatingExposure||(this.sceneVersion++,this.frameDirty=!0,this.resolution.noteChange(performance.now()),!this.suspended&&(this.syncAnimationLoop(),!(this.animationFrameId!==null||this.framesDriven||this.flushFrameId!==null)&&(this.flushFrameId=requestAnimationFrame(()=>{this.flushFrameId=null,this.drawIfDirty()}))))}drawIfDirty(){if(!(!this.frameDirty||this.contextReleased||this.suspended)){if(this.skyColoursStale&&this.lastAstronomy&&this.applySkyColours(this.lastAstronomy),this.compileBeforeNextDraw){this.compileBeforeNextDraw=!1;const e=this.compileOffThread().then(()=>{this.compiling===e&&(this.compiling=void 0,this.render())});this.compiling=e;return}if(!this.compiling){if(this.skyHoldUntilMs){if(!this.sceneSettled()&&performance.now()<this.skyHoldUntilMs){this.firstFrameReady()&&this.arrivalsPending===0&&this.refreshReflections(!0);return}this.skyHoldUntilMs=null,this.skyGlow?.setWithheld(!1),this.iceHalos?.setUrgent(!1),this.onFirstFrameHold?.(!1),this.skyColoursStale&&this.lastAstronomy&&this.applySkyColours(this.lastAstronomy)}this.frameDirty=!1,this.refreshReflections(),this.resolution.beginDrawing();try{this.renderOnce(),this.drawn++}finally{this.resolution.endDrawing()}this.developingExposure&&this.startExposure()}}}drawn=0;get framesDrawn(){return this.drawn}compileBeforeNextDraw=!1;compiling;static COMPILE_WAIT_MS=1500;compileOffThread(){const e=this.renderer.compile(this.scene,this.camera);if(!this.renderer.extensions.get("KHR_parallel_shader_compile"))return Promise.resolve();const t=this.renderer.properties,i=performance.now()+Je.COMPILE_WAIT_MS;return new Promise(n=>{const s=()=>{if(this.contextReleased)return n();for(const r of e){const a=t.get(r)?.currentProgram;(!a||a.isReady())&&e.delete(r)}e.size===0||performance.now()>i?n():setTimeout(s,10)};s()})}compileNextFrameOffThread(){this.compileBeforeNextDraw=!0}contextReleased=!1;releaseContext(){this.contextReleased||(this.contextReleased=!0,this.stopTwinkle(),this.cancelFlush(),this.cancelExposure(),this.compiling=void 0,this.cancelScatteredSkyPump(),this.renderer.forceContextLoss())}restoreContext(){this.contextReleased&&(this.contextReleased=!1,this.renderer.forceContextRestore(),this.scatteredSky?.invalidate(),this.pumpScatteredSky(),this.compileNextFrameOffThread(),this.syncAnimationLoop(),this.render())}suspended=!1;suspend(){this.suspended||(this.suspended=!0,this.stopTwinkle(),this.cancelFlush(),this.cancelExposure(),this.cancelScatteredSkyPump(),clearTimeout(this.reflectionTimer),this.reflectionTimer=void 0)}resume(){this.suspended&&(this.suspended=!1,this.pumpScatteredSky(),this.syncAnimationLoop(),this.render())}cancelFlush(){this.flushFrameId!==null&&(cancelAnimationFrame(this.flushFrameId),this.flushFrameId=null)}frame(e){if(this.animationsRunning){const t=this.lastFrameTimeMs===void 0?0:e-this.lastFrameTimeMs;this.lastFrameTimeMs=e,this.hasAnimations()&&this.animate(e,t);const i=this.resolution.ratioFor(e,t);i!==this.renderer.getPixelRatio()&&this.applyPixelRatio(i)}this.drawIfDirty()}cabinDecor(){return this.cabinGroups}cabinGroups=[];findCabin(e,t,i){const n=[];for(const s of this.decorObjects){if(s.kind!=="aircraft"||s.observerSide!==void 0&&ka(s.kind))continue;const r=this.decorGroups.get(s.id);if(!r)continue;const a=Gs(s,e),l=a.eastM+t.x+i.x,c=-a.northM+t.z+i.z,h=Fe.sizeOf(s),d=Math.max(h.widthM,h.lengthM)/2;Math.hypot(l,c)<d&&Math.abs(a.altitudeM-this.poseElevationM-1.6)<d&&n.push(r)}return this.cabinGroups=n,n}static CABIN_MATE_RANGE_M=4;static AIRBORNE_M=100;refreshReflections(e=!1){this.reflections??=new Jn(this.renderer);const t=[...this.compassSprites,...this.lensFlare?[this.lensFlare.mesh]:[],...[...this.glareSprites.values()].map(a=>a.mesh)],i=[...this.starTiers.map(a=>a.points),...[...this.bodyMeshes.values()].filter(a=>a instanceof ls),...[this.rainSystem?.points,this.precipitationPoints,this.rainSplashSystem?.points].filter(a=>a!==void 0),...this.cabinDecor()],n=this.relativeScale,s=this.sceneVersion,r=this.reflections.refresh(this.renderer,this.scene,this.camera.position,this.bodySystem.reflectors,t,[...this.decorGroups.values()],s,i,a=>this.measureSurroundings(a,n,s),e?0:Jn.REFRESH_MS);r===void 0||this.reflectionTimer||(this.reflectionTimer=setTimeout(()=>{this.reflectionTimer=void 0,this.frameDirty=!0,!(this.animationFrameId!==null||this.framesDriven||this.flushFrameId!==null)&&(this.flushFrameId=requestAnimationFrame(()=>{this.flushFrameId=null,this.drawIfDirty()}))},r))}measureSurroundings(e,t,i){const n=this.lastAstronomy;if(!n)return;this.probeIrradiance??=new eh;const s=[n.sun,n.moon].filter(r=>r.altitudeDeg>-2).map(r=>ni(r.altitudeDeg,r.azimuthDeg,1));this.probeIrradiance.measure(this.renderer,e,s,r=>{const a=f=>f.map(p=>p/t),l=this.surroundings,c={up:a(r.up),down:a(r.down)},h=(f,p)=>f.some((g,m)=>Math.abs(g-p[m])>.03*Math.max(Math.abs(g),Math.abs(p[m]),1e-12)),d=!l||h(l.up,c.up)||h(l.down,c.down);d&&(this.surroundings=c),this.eyeSettledVersion=-1;const u=this.scatteredSky?.adaptToSurroundings(Math.exp(r.logAverage)/t)??!1;if(!d&&!u){this.eyeSettledVersion=i,this.skyHoldUntilMs&&this.redrawHeld();return}this.skyColoursStale=!0,this.render()})}lightUnderClouds(e){const t=this.surroundings;if(!t)return;const i=e.sun.altitudeDeg>=Fc?e.sun:e.moon.altitudeDeg>=Fc?e.moon:void 0;if(!i)return;const n=this.relativeScale/Math.PI;return{through:this.cloudTransmission(i),radiance:[t.up[0]*n,t.up[1]*n,t.up[2]*n]}}probeIrradiance;surroundings;animate(e,t){const i=Math.min(t/1e3,ZC);this.twinkleSeconds=e/1e3,this.updateTwinkle(this.twinkleSeconds),this.updatePrecipitation(e/1e3,i),this.updateRain(i),this.lensFlare&&(this.lensFlare.uniforms.uTime.value=e/1e3),this.developingExposure||(this.frameDirty=!0)}setMaxPixelRatio(e){this.resolution.maximum=e,this.renderer.getPixelRatio()>this.resolution.maximum&&this.applyPixelRatio(this.resolution.maximum)}applyPixelRatio(e){this.renderer.setPixelRatio(e),this.renderer.setSize(this.cssSize.width,this.cssSize.height,!1),this.frameDirty=!0}setExposure(e,t){const i=t?Math.max(1,Math.round(e)):1;if(i===this.exposureInstants&&(i===1||t===this.exposureInstantAt)){this.exposureInstantAt=t;return}this.exposureInstants=i,this.exposureInstantAt=t,i===1&&(this.cancelExposure(),this.exposureAccumulation?.dispose(),this.exposureAccumulation=void 0),this.render()}renderOnce(e){if(this.aimBeams(),this.onMapSubjectBounds){const r=this.mapSubjectBounds();e?this.exposureSubjectBounds.push(...r):this.onMapSubjectBounds(r)}const t=this.usableEquidistantPass();this.phenomena.setCloudLayers(this.layeredClouds?.volumes??[]),this.phenomena.place(this.camera,(r,a,l)=>this.directionAtScreenPoint(r,a,l),r=>this.screenPointOf(r)),this.references.place(this.camera);const i=Math.max(this.phenomena.furthestM,this.references.furthestM)*1.2;i>this.camera.far&&(this.camera.far=i,this.camera.updateProjectionMatrix()),Ln.uRodShare.value=this.scatteredSky?.rodShare??0,Ln.uRelativeScale.value=this.relativeScale,this.applyMedium();const n=this.references.any||this.phenomena.any||this.compassSprites.some(r=>r.visible);Ln.uHasOverlay.value=n?1:0;const s=n?r=>this.renderOverlayPasses(r):void 0;if(this.skyGlow?.setDestinationEncoded(!1),!t){this.updateLensFlarePosition();const r=this.usableDepthOfFieldPass();r?r.render(this.renderer,this.scene,this.camera,s,e):this.usableFinishPass().render(this.renderer,this.scene,this.camera,s,void 0,e);return}t.render(this.renderer,this.scene,this.camera,this.camera.fov,()=>this.updateLensFlarePosition(),s,r=>{this.lensFlare&&(this.lensFlare.mesh.visible=r?!1:this.sunVisible)},()=>this.renderDazzleOnResample(),e,this.pointLayerHost)}pointLayerHost={points:()=>{const e=[];return this.celestialGroup.traverse(t=>{(t instanceof ls&&t.userData.pointSource||t instanceof Se&&t.userData.skyRibbon)&&e.push(t)}),e},clouds:()=>[...this.layeredClouds?.meshes??[],...this.cloudMesh?[this.cloudMesh]:[],...this.cirrusMesh?[this.cirrusMesh]:[]],sky:this.celestialGroup};renderOverlayPasses(e=this.camera){this.renderReferencesPass(e),this.renderBodiesOverReferences(e),this.renderPhenomenaPass(e),this.renderHudPass(e)}renderHudPass(e){const t=this.traceSystem?.any&&this.tracesShown;if(!t&&!this.compassSprites.some(s=>s.visible))return;t&&this.traceSystem.setView(this.renderer.getDrawingBufferSize(this.traceResolution),e.fov);const i=this.renderer.autoClear,n=this.renderer.shadowMap.autoUpdate;this.renderer.autoClear=!1,this.renderer.shadowMap.autoUpdate=!1,e.layers.set(Gp),this.renderer.render(this.scene,e),e.layers.set(0),this.renderer.autoClear=i,this.renderer.shadowMap.autoUpdate=n}renderBodiesOverReferences(e){if(!this.references.any||!this.bodySystem.any)return;const t=this.renderer.autoClear,i=this.renderer.shadowMap.autoUpdate;this.renderer.autoClear=!1,this.renderer.shadowMap.autoUpdate=!1,e.layers.set(y2),this.scene.overrideMaterial=this.bodyCutOutMaterial,this.renderer.render(this.scene,e),this.scene.overrideMaterial=null,e.layers.set(0),this.renderer.autoClear=t,this.renderer.shadowMap.autoUpdate=i}bodyCutOutMaterial=new Hn({blending:Rh,blendSrc:Xc,blendDst:Xc,blendSrcAlpha:Xc,blendDstAlpha:Xc,toneMapped:!1});renderReferencesPass(e){if(!this.references.any)return;const t=this.renderer.autoClear,i=this.renderer.shadowMap.autoUpdate;this.renderer.autoClear=!1,this.renderer.shadowMap.autoUpdate=!1,e.layers.set(M2),this.renderer.render(this.scene,e),e.layers.set(0),this.renderer.autoClear=t,this.renderer.shadowMap.autoUpdate=i}setReferences(e,t){this.references.set(e.map(i=>{const n=this.documentRelative(i.src);return n===i.src?i:{...i,src:n}}),void 0,t)}referenceAspect(e){return this.references.aspectOf(e)}directionAt(e,t){return this.directionAtScreenPoint(e,t,new D)}referenceFailedToLoad(e){return this.references.failedToLoad(this.documentRelative(e))}setReferencesShown(e){this.references.setShown(e),this.render()}setReferenceView(e,t){this.references.setView(e,t),this.render()}renderPhenomenaPass(e){if(!this.phenomena.any)return;const t=this.renderer.autoClear,i=this.renderer.shadowMap.autoUpdate;this.renderer.autoClear=!1,this.renderer.shadowMap.autoUpdate=!1,this.renderer.clearDepth();for(const n of this.decorObjects){const s=this.decorGroups.get(n.id);s&&Je.markDecorDepth(s,n.kind!=="crop")}e.layers.set(Hp),this.scene.overrideMaterial=this.decorDepthMaterial,this.renderer.render(this.scene,e),this.scene.overrideMaterial=null,e.layers.set(b2),this.renderer.render(this.scene,e),e.layers.set(0),this.renderer.autoClear=t,this.renderer.shadowMap.autoUpdate=i}decorDepthMaterial=new Hn({colorWrite:!1});static markDecorDepth(e,t){e.traverse(i=>{if(!(i instanceof Se))return;const n=Array.isArray(i.material)?i.material[0]:i.material;t&&n.depthWrite!==!1&&n.blending!==Wi?i.layers.enable(Hp):i.layers.disable(Hp)})}startExposure(){this.cancelExposure(),this.exposureSubjectBounds=[];const e=this.renderer.getDrawingBufferSize(new we),t=Math.max(1,Math.round(e.x)),i=Math.max(1,Math.round(e.y));this.exposureAccumulation||(this.exposureAccumulation=new ID(t,i)),this.exposureAccumulation.resize(t,i),this.exposureAccumulation.open(this.renderer),this.exposureInstantsDone=0,this.exposureFrameId=requestAnimationFrame(()=>this.developExposure())}developExposure(){this.exposureFrameId=null;const e=this.exposureInstantAt,t=this.exposureAccumulation;if(!e||!t)return;const i=1/this.exposureInstants;this.resolution.beginDrawing();const n=performance.now()+Je.EXPOSURE_BUDGET_MS,s=Je.exposureInstantsPerFrame(t.instantTarget.scene.width*t.instantTarget.scene.height);let r=0;do{this.restateAt(e,this.exposureInstantsDone);const a=this.compassSprites.map(l=>l.visible);for(const l of this.compassSprites)l.visible=!1;try{this.renderOnce(t.instantTarget)}finally{this.compassSprites.forEach((l,c)=>{l.visible=a[c]})}t.add(this.renderer,i),this.exposureInstantsDone++,r++}while(this.exposureInstantsDone<this.exposureInstants&&performance.now()<n&&r<s);this.restateAt(e,0),this.presentExposure(),this.resolution.endDrawing(),this.exposureInstantsDone<this.exposureInstants&&(this.exposureFrameId=requestAnimationFrame(()=>this.developExposure()))}presentExposure(){if(Ln.uRodShare.value=this.scatteredSky?.rodShare??0,Ln.uHasOverlay.value=1,Ln.uRelativeScale.value=this.relativeScale,this.applyMedium(),this.exposureAccumulation?.develop(this.renderer,this.exposureInstants/this.exposureInstantsDone),this.onMapSubjectBounds?.(this.exposureSubjectBounds),!this.compassSprites.some(s=>s.visible))return;const e=new xr,t=new $s(-1,1,1,-1,0,2),i=Fd/(fb*Math.tan(pb*Ci/2));for(const s of this.compassSprites){if(!s.visible)continue;const r=s.getWorldPosition(new D).sub(this.camera.position).normalize(),a=this.screenPointOf(r);if(!a)continue;const l=new Ec(s.material);l.position.set(a.ndcX,a.ndcY,-1),l.scale.set(i/this.camera.aspect,i,1),e.add(l)}const n=this.renderer.autoClear;this.renderer.autoClear=!1;try{this.renderer.render(e,t)}finally{this.renderer.autoClear=n}}onMapSubjectBounds;exposureSubjectBounds=[];static MAP_SUBJECT_NEAREST_M=8;mapSubjectBounds(){const e=[],t=new on,i=new D,n=this.camera.getWorldDirection(new D),s=this.decorObjects.filter(a=>a.track?.length||a.kind==="aircraft"||a.kind==="vehicle").map(a=>this.decorGroups.get(a.id)),r=this.bodySystem.reflectors.map(a=>a.holder);for(const a of[...s,...r]){if(!a?.visible||(t.setFromObject(a),t.isEmpty())||t.distanceToPoint(this.camera.position)<Je.MAP_SUBJECT_NEAREST_M)continue;let l=1/0,c=-1/0,h=1/0,d=-1/0;for(const u of[t.min.x,t.max.x])for(const f of[t.min.y,t.max.y])for(const p of[t.min.z,t.max.z]){if(i.set(u,f,p).sub(this.camera.position).normalize(),i.dot(n)<=0)continue;const g=this.screenPointOf(i);if(!g)continue;const m=(g.ndcX+1)/2,v=(1-g.ndcY)/2;l=Math.min(l,m),c=Math.max(c,m),h=Math.min(h,v),d=Math.max(d,v)}l=Math.max(l,0),c=Math.min(c,1),h=Math.max(h,0),d=Math.min(d,1),c>=l&&d>=h&&e.push({x:l,y:h,width:c-l,height:d-h})}return e}restateAt(e,t){this.restatingExposure=!0;try{e(t)}finally{this.restatingExposure=!1}}cancelExposure(){this.exposureFrameId!==null&&(cancelAnimationFrame(this.exposureFrameId),this.exposureFrameId=null)}setLensOptics(e){const t=this.lensOptics;this.lensOptics=e,(t===void 0!=(e===void 0)||t&&e&&(t.focalLengthMm!==e.focalLengthMm||t.fNumber!==e.fNumber||t.focusDistance!==e.focusDistance||t.frameHeightMm!==e.frameHeightMm))&&(e&&this.depthOfFieldPass&&this.depthOfFieldPass.setLens(e.focalLengthMm,e.fNumber,e.focusDistance,e.frameHeightMm),this.render())}usableDepthOfFieldPass(){const e=this.lensOptics;if(!e)return;const t=this.renderer.getDrawingBufferSize(new we),i=Math.max(1,Math.round(t.x)),n=Math.max(1,Math.round(t.y));return this.depthOfFieldPass||(this.depthOfFieldPass=new ih(i,n)),this.depthOfFieldPass.resize(i,n),this.depthOfFieldPass.setLens(e.focalLengthMm,e.fNumber,e.focusDistance,e.frameHeightMm),this.depthOfFieldPass}usableFinishPass(){const e=this.renderer.getDrawingBufferSize(new we);return this.finishPass?this.finishPass.resize(e.x,e.y):this.finishPass=new Xg(e.x,e.y),this.finishPass}usableEquidistantPass(){if(this.projectionKind!=="equidistant")return;const e=this.renderer.getDrawingBufferSize(new we);return this.equidistantPass?this.equidistantPass.resize(e.x,e.y):this.equidistantPass=new di(e.x,e.y),this.equidistantPass}aimAtScreenPoint(e,t,i){const n=this.projectionKind==="equidistant"?this.equidistantPass:void 0;if(!n){e.setFromCamera(new we(t,i),this.camera);return}const s=n.directionFor(t,i,this.camera.fov);this.camera.updateMatrixWorld(),e.ray.origin.setFromMatrixPosition(this.camera.matrixWorld),e.ray.direction.set(s.x,s.y,s.z).applyQuaternion(this.camera.quaternion).normalize(),e.camera=this.camera}pickCloudAt(e,t){return this.layeredClouds?.pickInstance(this.cloudDirectionAt(e,t))}cloudDirectionAt(e,t){return this.directionAtScreenPoint(e,t,new D)}directionAtScreenPoint(e,t,i){return this.aimAtScreenPoint(this.ufoOcclusionRaycaster,e,t),i.copy(this.ufoOcclusionRaycaster.ray.direction)}screenPointOf(e){this.camera.updateMatrixWorld();const t=this.screenPointScratch.copy(e).applyQuaternion(this.screenPointQuaternion.copy(this.camera.quaternion).invert()),i=this.renderer.getDrawingBufferSize(this.screenPointSize),n=i.x/Math.max(i.y,1);if(this.projectionKind==="equidistant"&&this.equidistantPass)return di.ndcFor(t,this.camera.fov,n);if(t.z>=0)return;const s=Math.tan(this.camera.fov/2*Ci);return{ndcX:t.x/-t.z/(n*s),ndcY:t.y/-t.z/s}}screenPointScratch=new D;screenPointQuaternion=new An;screenPointSize=new we;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}const t=this.sunVisibleFraction();if(t<=0){e.mesh.visible=!1;return}e.mesh.visible=!0,this.sunUnhiddenFraction=t,this.applyDazzleStrength();const i=this.lensFlareScratch.copy(this.sunWorldPosition).project(this.camera);e.uniforms.uLensPosition.value.set(i.x,i.y);const n=this.renderer.domElement.width,s=this.renderer.domElement.height;e.uniforms.uResolution.value.set(n,s),e.uniforms.uTanHalfFov.value=Math.tan(this.camera.fov*Math.PI/360)}renderDazzleOnResample(){const e=this.lensFlare;if(!e||!this.sunVisible)return;const t=this.sunVisibleFraction();if(t<=0)return;this.sunUnhiddenFraction=t,this.applyDazzleStrength();const i=this.screenPointOf(this.lensFlareScratch.copy(this.sunWorldPosition).sub(this.camera.position).normalize());if(!i)return;const n=this.renderer.getDrawingBufferSize(this.screenPointSize);e.uniforms.uLensPosition.value.set(i.ndcX,i.ndcY),e.uniforms.uResolution.value.set(n.x,n.y),e.uniforms.uEquidistant.value=1,e.uniforms.uHalfFovRad.value=this.camera.fov*Math.PI/360;const s=this.renderer.autoClear;this.renderer.autoClear=!1,e.mesh.visible=!0,e.mesh.layers.enable(sb),this.camera.layers.set(sb),this.renderer.render(this.scene,this.camera),this.camera.layers.set(0),e.mesh.visible=!1,e.uniforms.uEquidistant.value=0,this.renderer.autoClear=s}sunVisibleFraction(){this.raycastableDecor().length>0&&this.scene.updateMatrixWorld();let e=0;for(const t of gb)this.isSunOccluded(t[0],t[1])||e++;return e/gb.length}raycastableDecor(){const e=[];for(const t of this.decorObjects){if(t.kind==="crop")continue;const i=this.decorGroups.get(t.id);i&&e.push(i)}return e}isSunOccluded(e=0,t=0){const i=this.raycastableDecor();if(!this.groundMesh&&!this.terrainMesh&&i.length===0)return!1;const n=this.sunOcclusionDirectionScratch.copy(this.sunWorldPosition).sub(this.camera.position),s=n.length();if(n.normalize(),e!==0||t!==0){const a=Math.PI/180,l=this.sunOcclusionRightScratch.set(n.z,0,-n.x);l.lengthSq()<1e-9&&l.set(1,0,0),l.normalize();const c=this.sunOcclusionUpScratch.crossVectors(l,n).normalize();n.addScaledVector(l,e*a).addScaledVector(c,t*a).normalize()}if(this.groundBlocks(this.camera.position,n,s))return!0;if(i.length===0)return!1;this.sunOcclusionRaycaster.set(this.camera.position,n);const r=this.sunOcclusionRaycaster.intersectObjects(i,!0)[0];return r!==void 0&&r.distance<s}groundBlocks(e,t,i,n=0){const s=this.groundMesh;if(s&&t.y<0){const m=(s.position.y-e.y)/t.y;if(m>n&&m<i){const v=e.x+t.x*m-s.position.x,b=e.z+t.z*m-s.position.z;if(Math.hypot(v,b)<=this.groundRadius)return!0}}const r=this.terrainMesh;if(!r)return!1;const a=r.geometry.getAttribute("position"),l=Math.round(Math.sqrt(a.count));if(l<2||l*l!==a.count)return!1;const c=[r.position.x+a.getX(0),r.position.x+a.getX(l-1)],h=[r.position.z+a.getZ(0),r.position.z+a.getZ((l-1)*l)],d=Math.min(Math.abs(c[1]-c[0]),Math.abs(h[1]-h[0]))/(l-1);if(!(d>0))return!1;let u=n,f=i;for(const[m,v,b]of[[e.x,t.x,c],[e.z,t.z,h]]){const x=Math.min(b[0],b[1]),y=Math.max(b[0],b[1]);if(Math.abs(v)<1e-12){if(m<x||m>y)return!1;continue}const w=(x-m)/v,S=(y-m)/v;u=Math.max(u,Math.min(w,S)),f=Math.min(f,Math.max(w,S))}if(!(f>u))return!1;const p=Math.hypot(t.x,t.z),g=Math.min(4096,Math.max(8,Math.ceil((f-u)*p/(d/2))));for(let m=0;m<=g;m++){const v=u+(f-u)*m/g,b=e.x+t.x*v,x=e.y+t.y*v,y=e.z+t.z*v;if(x<=this.groundYUnder(b,y))return!0}return!1}setPhenomena(e,t){this.phenomena.set(e,t)}decorDistancesAt(e,t,i){this.aimAtScreenPoint(this.ufoOcclusionRaycaster,e,t),this.ufoOcclusionRaycaster.near=rb;let n,s;for(const r of this.decorObjects){if(r.kind==="crop")continue;const a=this.decorGroups.get(r.id);if(!a)continue;const l=this.ufoOcclusionRaycaster.intersectObject(a,!0)[0];l&&(r.occludesSourceIds?.includes(i)?n=n===void 0?l.distance:Math.max(n,l.distance):s=s===void 0?l.distance:Math.min(s,l.distance))}return{behindM:n,inFrontM:s}}pickBodyAt(e,t){this.aimAtScreenPoint(this.raycaster,e,t);const i=this.raycaster.ray.origin,n=this.raycaster.ray.direction,s=fC*this.camera.fov*Math.PI/180,r=[...this.hitAreas.entries()].map(([h,d])=>{const u=d.getWorldPosition(new D).sub(i);return{key:h,direction:u.clone().normalize(),radiusRad:Math.atan2(d.scale.x/2,u.length())}}),a=this.eclipseDiscs,l=a?[{key:"sun",direction:a.sun,radiusRad:a.sunRadiusRad},{key:"moon",direction:a.moon,radiusRad:a.moonRadiusRad,inFront:!0}]:[],c=Je.nearestBody(n,[...r.filter(h=>!a||h.key!=="sun"&&h.key!=="moon"),...l],s);if(c)return this.groundHides(e,t)?void 0:c}static nearestBody(e,t,i){let n,s=1/0,r=1/0,a=!1;for(const l of t){const c=Math.acos(sr(l.direction.dot(e),-1,1))-l.radiusRad;if(c>i)continue;const h=c<=0,d=s<=0,u=l.inFront===!0;(h!==d?h:h?u!==a?u:l.radiusRad<r:c<s)&&(n=l.key,s=c,r=l.radiusRad,a=u)}return n}pickInterpretationBodyAt(e,t){const i=this.bodySystem.group.children.filter(f=>f.visible&&f.name.startsWith("body:"));if(i.length===0)return;this.aimAtScreenPoint(this.raycaster,e,t);const n=this.raycaster.ray.direction,s=this.raycaster.ray.origin,r=cC*this.camera.fov*Math.PI/180,a=[...this.decorGroups.values()],l=a.length>0?Je.firstSolid(this.raycaster.intersectObjects(a,!0))?.distance:void 0;let c,h=1/0;const d=new on,u=new D;for(const f of i){if(d.setFromObject(f),d.isEmpty())continue;d.getCenter(u);const p=d.getSize(new D).length()/2,g=u.clone().sub(s),m=g.length();if(m===0||g.dot(n)<=0||l!==void 0&&l<m-p)continue;const v=Math.acos(Math.min(1,g.normalize().dot(n))),b=Math.atan(p/m);if(b>r){const x=this.raycaster.intersectObject(f,!0)[0];if(!x||l!==void 0&&l<x.distance)continue}else if(v>r)continue;b<h&&(h=b,c=f.name.slice(5))}return c}pickStarAt(e,t){if(this.namedStars.length===0)return;this.aimAtScreenPoint(this.raycaster,e,t);const i=this.raycaster.ray.direction,n=Math.cos(Xp*this.camera.fov*Math.PI/180);let s,r=n;for(const a of this.namedStars){const l=a.direction.dot(i);l>r&&(r=l,s={star:a.star,altitudeDeg:a.altitudeDeg})}return s&&this.groundHides(e,t)?void 0:s}groundHides(e,t){if(!this.terrainMesh&&!this.groundMesh)return!1;this.aimAtScreenPoint(this.ufoOcclusionRaycaster,e,t);const i=this.ufoOcclusionRaycaster.ray;return this.groundBlocks(i.origin,i.direction,1/0,rb)}bodyScreenBox(e){const t=this.bodySystem.boxOf(e,this.bodyBoxScratch);if(!t)return;let i=1/0,n=1/0,s=-1/0,r=-1/0;for(let a=0;a<8;a++){const l=this.bodyCornerScratch.set(a&1?t.max.x:t.min.x,a&2?t.max.y:t.min.y,a&4?t.max.z:t.min.z),c=this.screenPointOf(l.sub(this.camera.position).normalize());if(!c)return;i=Math.min(i,c.ndcX),s=Math.max(s,c.ndcX),n=Math.min(n,c.ndcY),r=Math.max(r,c.ndcY)}return{minX:i,minY:n,maxX:s,maxY:r}}bodyBoxScratch=new on;bodyCornerScratch=new D;pickPlacedBodyAt(e,t){return this.aimAtScreenPoint(this.raycaster,e,t),this.bodySystem.pick(this.raycaster)}decorScreenBox(e){const t=this.decorGroups.get(e);if(!t||!t.visible)return;const i=this.bodyBoxScratch.setFromObject(t);if(i.isEmpty())return;let n=1/0,s=1/0,r=-1/0,a=-1/0;for(let l=0;l<8;l++){const c=this.bodyCornerScratch.set(l&1?i.max.x:i.min.x,l&2?i.max.y:i.min.y,l&4?i.max.z:i.min.z),h=this.screenPointOf(c.sub(this.camera.position).normalize());if(!h)return;n=Math.min(n,h.ndcX),r=Math.max(r,h.ndcX),s=Math.min(s,h.ndcY),a=Math.max(a,h.ndcY)}return{minX:n,minY:s,maxX:r,maxY:a}}decorGroundPointAt(e,t,i,n=0){const s=this.decorGroups.get(e);if(!s)return;this.aimAtScreenPoint(this.raycaster,t,i);const r=this.raycaster.ray.intersectPlane(this.decorPlaneScratch.setComponents(0,1,0,-(s.position.y+n)),this.decorHitScratch);return r?{x:r.x,z:r.z}:void 0}decorDistanceM(e){const t=this.decorGroups.get(e);return t?Math.hypot(t.position.x-this.camera.position.x,t.position.z-this.camera.position.z):void 0}decorMetresPerNdcY(e){const t=this.decorGroups.get(e);return t?t.position.distanceTo(this.camera.position)*Math.tan(this.camera.fov*Ci/2):0}decorGrabHeightAt(e,t,i){const n=this.decorGroups.get(e);if(!n)return 0;const s=this.bodyBoxScratch.setFromObject(n).max.y-n.position.y;this.aimAtScreenPoint(this.raycaster,t,i);const r=this.decorHitScratch.set(this.camera.position.x-n.position.x,0,this.camera.position.z-n.position.z);if(r.lengthSq()<1e-6)return 0;r.normalize();const a=this.decorPlaneScratch.setFromNormalAndCoplanarPoint(r,n.position),l=this.raycaster.ray.intersectPlane(a,this.decorHitScratch);return l?Math.min(Math.max(l.y-n.position.y,0),Math.max(s,0)):0}decorPlaneScratch=new ma;decorHitScratch=new D;static firstSolid(e){return e.find(t=>{const i=t.object.material;return!(Array.isArray(i)?i:[i]).some(s=>s&&s.transparent&&s.opacity<Je.SEE_THROUGH_BELOW)})}static SEE_THROUGH_BELOW=.9;pickDecorAt(e,t){this.aimAtScreenPoint(this.raycaster,e,t);const i=[...this.decorGroups.entries()],n=Je.firstSolid(this.raycaster.intersectObjects(i.map(([,a])=>a),!0));if(!n)return;const s=this.bodySystem.pickHit(this.raycaster);if(s!==void 0&&s.distance<n.distance)return;let r=n.object;for(;r&&!i.some(([,a])=>a===r);)r=r.parent;return i.find(([,a])=>a===r)?.[0]}dispose(){this.stopTerrainFade(),this.stopTwinkle(),this.cancelFlush(),this.phenomena.clear(),this.references.disposeAll(),this.terrainBuildToken++,this.cancelScatteredSkyPump(),this.skyMesh&&this.skyGradientMaterial&&(this.skyMesh.material=this.skyGradientMaterial),this.scatteredSky?.dispose(),this.scatteredSky=void 0,this.disposeMesh(this.skyMesh),this.disposeMesh(this.groundMesh),this.disposeMesh(this.terrainMesh),this.roadSystem.dispose(),this.traceSystem?.dispose(),this.contrailSystem?.dispose(),this.contrailSystem=void 0,this.disposeCloudSystem(),this.disposeCirrus(),this.disposePrecipitationPoints(),this.disposeRain(),this.disposeStarTiers(),this.meteorSystem?.dispose(),this.meteorSystem=void 0,this.iceHalos?.dispose(),this.iceHalos=void 0,this.rainbow?.dispose(),this.rainbow=void 0,this.skyGlow?.dispose(),this.skyGlow=void 0,this.depthOfFieldPass?.dispose(),this.finishPass?.dispose(),this.depthOfFieldPass=void 0,this.cancelExposure(),this.exposureAccumulation?.dispose(),this.exposureAccumulation=void 0,this.cometTail?.dispose(),this.cometTail=void 0,this.satelliteField?.dispose(),this.satelliteField=void 0,this.reentrySystem?.dispose(),this.reentrySystem=void 0,this.plumeSystem?.dispose(),this.plumeSystem=void 0,this.lightningBolt?.dispose(),this.lightningBolt=void 0;for(const e of this.bodyMeshes.values())this.disposeMesh(e);this.bodyMeshes.clear(),this.novaKeys.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())Fe.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;this.cancelFlush();const e=t=>{this.animationFrameId=null,this.frame(t),this.animationFrameId===null&&this.needsAnimationLoop()&&(this.animationFrameId=requestAnimationFrame(e))};this.animationFrameId=requestAnimationFrame(e)}setAnimationsRunning(e,t=!1){const i=e&&t;if(e===this.animationsRunning&&i===this.framesDriven)return;const n=this.animationsRunning;this.animationsRunning=e,this.framesDriven=i,e&&!n&&(this.lastFrameTimeMs=void 0,this.resolution.reset());const s=!e&&this.renderer.getPixelRatio()!==this.resolution.maximum;s&&this.applyPixelRatio(this.resolution.maximum),this.syncAnimationLoop(),(!e||this.frameDirty)&&this.render(),s&&this.drawIfDirty()}stopTwinkle(){this.animationFrameId!==null&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null)}needsAnimationLoop(){return this.animationsRunning&&!this.framesDriven&&!this.suspended&&this.hasAnimations()}hasAnimations(){return this.starTiers.some(e=>e.brightness.length>0)||this.precipitationPoints!==void 0||this.rainSystem!==void 0||this.flareMayShow()}flareAimScratch=new D;flareMayShow(){if(this.lensFlare===void 0||!this.sunVisible)return!1;const e=this.lastAstronomy?.sun;return e!==void 0&&e.altitudeDeg<Je.FLARE_ANIMATION_MIN_ALTITUDE_DEG?!1:(this.camera.getWorldDirection(this.flareAimScratch),this.flareAimScratch.dot(this.lensFlareScratch.copy(this.sunWorldPosition).sub(this.camera.position))>0)}static FLARE_ANIMATION_MIN_ALTITUDE_DEG=-3;syncAnimationLoop(){this.needsAnimationLoop()?this.startTwinkle():this.stopTwinkle()}buildSky(e){const t=this.skyMesh?.geometry??new Ii(Ld,32,16),i=t.attributes.position,n=t.getAttribute("color")??new yt(new Float32Array(i.count*3),3);for(let r=0;r<i.count;r++){const{altitudeDeg:a,azimuthDeg:l}=CD(i.getX(r),i.getY(r),i.getZ(r)),c=BD(a,l,e.azimuthDeg,e.altitudeDeg);n.setXYZ(r,c[0],c[1],c[2])}if(n.needsUpdate=!0,this.skyMesh)return;t.setAttribute("color",n);const s=new Hn({vertexColors:!0,side:fi,fog:!1,depthWrite:!1});this.skyGradientMaterial=s,this.skyMesh=new Se(t,s),this.skyMesh.renderOrder=-1,this.celestialGroup.add(this.skyMesh)}buildGround(){const e=ab(this.observerElevationM);if(this.groundMesh&&e===this.groundRadius)return;this.disposeMesh(this.groundMesh),this.groundRadius=e;const t=new Sg(this.groundRadius,48),i=new Oa({color:new ne(Vp,Vp,Vp),fog:!0});ko.fadeRim(i,this.groundRadius*.75,this.groundRadius),this.groundMesh=new Se(t,i),this.groundMesh.rotation.x=-Math.PI/2,this.groundMesh.position.y=0,this.groundMesh.receiveShadow=!0,this.scene.add(this.groundMesh),this.applyGroundDepthWrite()}applyGroundDepthWrite(){const e=this.groundMesh?.material;if(!e)return;const t=this.terrainMesh===void 0;e.depthWrite!==t&&(e.depthWrite=t,e.needsUpdate=!0);const i=this.terrainMesh;let n=0;if(i){const s=i.geometry.getAttribute("position");n=1/0;for(let r=0;r<s.count;r++)Math.abs(s.getX(r)+i.position.x)>600||Math.abs(s.getZ(r)+i.position.z)>600||(n=Math.min(n,s.getY(r)+i.position.y));n=Number.isFinite(n)?Math.min(0,n)-1:0}this.groundMesh.position.y=n,this.groundMesh.renderOrder=0,e.depthTest=!0,e.needsUpdate=!0}cloudTransmission(e,t=!1){const i=`${e.altitudeDeg.toFixed(1)}:${e.azimuthDeg.toFixed(1)}:${Math.round(this.cloudOffsetM.x/10)}:${Math.round(this.cloudOffsetM.z/10)}:${Math.round(this.observerElevationM)}:`+Object.entries(this.cloudLayerOffsetsM).map(([r,a])=>`${r}=${Math.round(a.x/10)},${Math.round(a.z/10)}`).join(";")+(t?":water":""),n=this.cloudTransmissionMemo.get(i);if(n!==void 0)return n;this.cloudTransmissionMemo.size>256&&this.cloudTransmissionMemo.clear();const s=this.computeCloudTransmission(e,t);return this.cloudTransmissionMemo.set(i,s),s}cloudTransmissionMemo=new Map;computeCloudTransmission(e,t=!1){const i=ni(e.altitudeDeg,e.azimuthDeg,1);if(this.layeredClouds)return this.layeredClouds.transmissionAt(i,t);let n=1;const s=this.lowerCloudCover();s>0&&(n*=1-Nt.alphaAt(i,Math.abs(this.cloudLayerOffset()),s,this.cloudFieldOffset)*gC);const r=t?0:this.weather.highCloudCover??0;return r>0&&(n*=1-Nt.iceAlphaAt(i,Nd,r,this.cloudFieldOffset)*vC),Math.max(0,Math.min(1,n))}setBodyMesh(e,t,i,n,s){if(t.altitudeDeg<au){this.disposeMesh(this.bodyMeshes.get(e)),this.bodyMeshes.delete(e),this.disposeHitArea(e),this.disposeGlare(e),e==="sun"&&(this.sunVisible=!1);return}const{x:r,y:a,z:l}=ni(t.altitudeDeg,t.azimuthDeg,Wn),c=Ey(t.altitudeDeg),h=this.cloudTransmission(t),d=this.arrivingIlluminance(t,s,h),u=Je.unitLuminance(n);let f=this.bodyMeshes.get(e);if(e==="sun"){const p=Math.PI*(i/Wn)**2,g=[0,1,2].map(v=>u[v]*d[v]/(this.sunBeamFraction*p));this.sunDiscRadiance=g;const m=g.map(v=>Math.min(Je.BRIGHTEST_RELATIVE,v));f instanceof Se||(this.disposeMesh(f),f=new Se(new Ii(1,16,16),this.eclipsedSun.material()),this.celestialGroup.add(f),this.bodyMeshes.set(e,f)),f.material.color.setRGB(m[0],m[1],m[2]),f.scale.setScalar(i)}else{if(!(f instanceof ls)){this.disposeMesh(f);const m=new ot;m.setAttribute("position",new st(new Float32Array(3),3)),m.setAttribute("color",new st(new Float32Array(3),3)),f=new ls(m,Ce.material($l[$l.length-1].size,!1)),Ce.track(f),this.celestialGroup.add(f),this.bodyMeshes.set(e,f)}const p=f.geometry.getAttribute("color"),g=e.startsWith("comet:")?this.pointToPixel():1;p.setXYZ(0,u[0]*d[0]*g,u[1]*d[1]*g,u[2]*d[2]*g),p.needsUpdate=!0}if(f.position.set(r,a,l),this.setHitArea(e,r,a,l,i),e==="sun"&&(this.sunArriving=d),e.startsWith("comet:")?this.disposeGlare(e):e!=="sun"&&this.setGlare(e,r,a,l,d,i/Wn*(180/Math.PI),Je.POINT_VEIL_HOLD_DEG),e==="sun"){this.sunVisible=!0;const p=this.celestialGroup.scale.x;this.sunWorldPosition.set(r*p,a*p+this.celestialGroup.position.y,l*p),this.lensFlare||(this.lensFlare=T4(),this.lensFlare.uniforms.uOpacity.value=LC,this.lensFlare.uniforms.uFlareIntensity.value=this.lensFlareArtifactIntensity,this.lensFlare.uniforms.uStarPoints.value=this.starPoints,this.scene.add(this.lensFlare.mesh)),this.applyLensFlareTint(c)}}setMoonMesh(e,t){const i="moon";if(e.magnitude>t||e.altitudeDeg<au){this.disposeMesh(this.bodyMeshes.get(i)),this.bodyMeshes.delete(i),this.disposeHitArea(i),this.disposeGlare(i);return}const{x:n,y:s,z:r}=ni(e.altitudeDeg,e.azimuthDeg,Wn),a=this.cloudTransmission(e),l=this.arrivingIlluminance(e,e.magnitude,a),c=e.radiusDeg??Sn.MEAN_RADIUS_DEG,h=Wn*Math.tan(c*Ci),d=Math.max(sr(e.phase.illuminatedFraction,0,1),.01)*Math.PI*(h/Wn)**2,u=new ne(...l.map(g=>Math.min(Je.BRIGHTEST_RELATIVE,g/d))),f=`${e.phase.phaseFraction<.5}:${Math.round(sr(e.phase.illuminatedFraction,0,1)*500)}`;let p=this.bodyMeshes.get(i);p instanceof Ec?(p.userData.phaseKey!==f&&(p.material.map?.dispose(),p.material.map=Pb(e.phase),p.userData.phaseKey=f),p.material.color.copy(u)):(this.disposeMesh(p),p=new Ec(new eu({map:Pb(e.phase),color:u,fog:!1,blending:Wi,depthWrite:!1})),p.userData.phaseKey=f,this.celestialGroup.add(p),this.bodyMeshes.set(i,p)),p.scale.set(h*2,h*2,1),p.position.set(n,s,r),this.setHitArea(i,n,s,r,h),this.setGlare(i,n,s,r,l,c)}bentLight(e,t,i=pC){const[n,s,r]=this.arrivingIlluminance(e,t,1),a=Math.max(s,1e-30);return{scale:s/i,tint:[n/a,1,r/a]}}static litBySky(e,t){return Je.litScratch.setRGB(e.r*t[0],e.g*t[1],e.b*t[2])}static litScratch=new ne;pointToPixel(){const e=Math.max(1,this.renderer.getDrawingBufferSize(this.pointScratch).y),t=(this.camera.fov*Math.PI/180/e)**2;return Math.min(1,Ce.CONE_SOLID_ANGLE/t)}pointScratch=new we;static POINT_VEIL_HOLD_DEG=.25;static BRIGHTEST_RELATIVE=6e4;arrivingIlluminance(e,t,i){const n=this.air.transmittanceFromSpace(this.siteElevationM+this.observerElevationM,e.altitudeDeg),s=_t.illuminanceOf(t)*i*this.relativeScale;return[n[0]*s,n[1]*s,n[2]*s]}static unitLuminance(e){const t=Hs.luminanceOf([e.r,e.g,e.b]);return t>0?[e.r/t,e.g/t,e.b/t]:[1,1,1]}setHitArea(e,t,i,n,s){let r=this.hitAreas.get(e);if(!r){const l=new eu({transparent:!0,opacity:0,depthTest:!1,depthWrite:!1,fog:!1});r=new Ec(l),this.celestialGroup.add(r),this.hitAreas.set(e,r)}r.position.set(t,i,n);const a=s*2;r.scale.set(a,a,1)}disposeHitArea(e){const t=this.hitAreas.get(e);t&&(t.removeFromParent(),t.material.dispose(),this.hitAreas.delete(e))}setGlare(e,t,i,n,s,r,a=0){if(rn.radiusDeg(rn.K*Math.max(...s))<=Math.max(r,a)){this.disposeGlare(e);return}let l=this.glareSprites.get(e);l||(l=new rn(`veil:${e}`),this.celestialGroup.add(l.mesh),this.glareSprites.set(e,l)),l.shine({x:t,y:i,z:n},s,r,a)}disposeGlare(e){const t=this.glareSprites.get(e);t&&(t.mesh.removeFromParent(),t.dispose(),this.glareSprites.delete(e))}buildComet(e,t){const i=e&&`comet:${e.id}`;if(!e||!i||e.magnitude>t){this.disposeComet();return}this.cometKey&&this.cometKey!==i&&this.disposeComet();const n=Dl(e.magnitude,t),s=Rp(n);this.cometKey=i,this.setBodyMesh(i,e.position,$p*(.5+.5*n),new ne(s,s,s),e.magnitude),this.cometTail||(this.cometTail=new rs(Wn),this.celestialGroup.add(this.cometTail.object)),this.cometTail.set(e.position,e.tailEnd,n)}buildIceHalos(e,t){this.iceHalos||(this.iceHalos=new nn,this.iceHalos.setCloudOffset(this.cloudFieldOffset),this.iceHalos.onReady=()=>this.render(),this.celestialGroup.add(this.iceHalos.object)),this.iceHalos.setUrgent(!!this.skyHoldUntilMs);const i=this.highCloudCover(),n=this.layeredClouds?.cirrusMask;if(this.iceHalos.setCloudOffset(n?.offset??this.cloudFieldOffset),this.layeredClouds?.hostHalo(this.iceHalos),i===void 0){this.iceHalos.update({x:0,y:1,z:0},-1,0,[1,1,1],{cover:0,layerHeight:Nd},0);return}const s=this.lowerCloudCover(),r=At.deckLitUntilDeg(At.DECK_HEIGHT_M),a=e.altitudeDeg>-r?e:t,l=this.bentLight(a,a===e?dt.SUN_MAGNITUDE:t.magnitude),c=At.strength(i,s,a.altitudeDeg,r)*l.scale,{x:h,y:d,z:u}=ni(a.altitudeDeg,a.azimuthDeg,1);this.iceHalos.update({x:h,y:d,z:u},a.altitudeDeg,c,l.tint,{cover:n?.cover??i,layerHeight:n?.layerHeight??Nd},n?.iceCrystalAlignment??this.weather.iceCrystalAlignment??lu)}buildRainbow(e,t){this.rainbow||(this.rainbow=new Mo,this.celestialGroup.add(this.rainbow.object));const i=this.weather.precipitationType==="rain"?this.weather.precipitationIntensity*(this.weather.precipitationAmount??1):0,n=e.altitudeDeg>0,s=n?e:t,r=this.lowerCloudCover(),a=this.bentLight(s,n?dt.SUN_MAGNITUDE:t.magnitude,mC),l=bn.strength(i,r,s.altitudeDeg)*a.scale;if(l<=0){this.rainbow.update({x:0,y:1,z:0},0,[1,1,1],!0);return}const{x:c,y:h,z:d}=ni(s.altitudeDeg,s.azimuthDeg,1);this.rainbow.update({x:c,y:h,z:d},l,a.tint,n)}buildSkyGlow(e,t){if(!e.frame){this.skyGlow?.hide();return}this.skyGlow||(this.skyGlow=new ga,this.skyGlow.setWithheld(!!this.skyHoldUntilMs),this.skyGlow.onReady=()=>this.render(),this.celestialGroup.add(this.skyGlow.object));const{date:i,observer:n}=e.frame,s=as.galactic(i,n),r=Je.directionOf(s.centre),a=Je.directionOf(s.rotation),l=Je.directionOf(s.pole),c=new je().set(r.x,r.y,r.z,a.x,a.y,a.z,l.x,l.y,l.z),h=Je.directionOf(as.eclipticPole(i,n)),d=Je.directionOf(e.sun),u=d.clone().addScaledVector(h,-d.dot(h)).normalize();this.skyGlow.update({galactic:c,eclipticPole:h,sunLongitude:u,sunDirection:d,sunAltitudeDeg:e.sun.altitudeDeg,moon:{direction:Je.directionOf(e.moon),altitudeDeg:e.moon.altitudeDeg,phaseAngleDeg:ce.phaseAngleOf(e.moon.phase.illuminatedFraction)},lightPollution:this.lightPollution,skyColor:new D(t[0],t[1],t[2])})}static directionOf(e){const{x:t,y:i,z:n}=ni(e.altitudeDeg,e.azimuthDeg,1);return new D(t,i,n).normalize()}buildNovae(e,t){const i=new Set;for(const n of e){if(n.magnitude>t)continue;const s=`nova:${n.id}`;i.add(s);const r=Dl(n.magnitude,t),a=Rp(r);this.setBodyMesh(s,n.position,$p*(.5+.5*r),new ne(a,a,a),n.magnitude)}for(const n of this.novaKeys)i.has(n)||(this.disposeMesh(this.bodyMeshes.get(n)),this.bodyMeshes.delete(n),this.disposeHitArea(n),this.disposeGlare(n));this.novaKeys=i}disposeComet(){this.cometTail?.set(void 0,void 0,0),this.cometKey&&(this.disposeMesh(this.bodyMeshes.get(this.cometKey)),this.bodyMeshes.delete(this.cometKey),this.disposeHitArea(this.cometKey),this.disposeGlare(this.cometKey),this.cometKey=void 0)}buildPlanets(e,t){const i=new Set(["sun","moon",...this.cometKey?[this.cometKey]:[],...this.novaKeys]);for(const n of e){if(n.magnitude>t)continue;i.add(n.body);const s=Dl(n.magnitude,t),r=Rp(s),a=e6[n.body]??new ne(1,1,1),l=new ne(a.r*r,a.g*r,a.b*r),c=$p*(.5+.5*s);this.setBodyMesh(n.body,n.position,c,l,n.magnitude)}for(const n of[...this.bodyMeshes.keys()])i.has(n)||(this.disposeMesh(this.bodyMeshes.get(n)),this.bodyMeshes.delete(n),this.disposeHitArea(n),this.disposeGlare(n))}buildStars(e,t){if(this.namedStars=[],!e||e.catalog.count===0){this.disposeStarTiers(),this.syncAnimationLoop();return}const{catalog:i,date:n,observer:s}=e,r=new Us(n,s),a=i0(1337),l=[],c=this.siteElevationM+this.observerElevationM;for(let h=0;h<i.count;h++){const d=i.mag[h];if(d>t)break;const{altitudeDeg:u,azimuthDeg:f}=r.position(i.ra[h],i.dec[h]);if(u<cb)continue;const{x:p,y:g,z:m}=ni(u,f,Wp);l.push({x:p,y:g,z:m,brightness:Dl(d,t),illuminance:this.air.transmittanceFromSpace(c,u).map(v=>v*_t.illuminanceOf(d)),phase:a()*Math.PI*2,speedFactor:.7+a()*.6})}for(const h of r4){if(h.mag>t)continue;const{altitudeDeg:d,azimuthDeg:u}=r.position(h.raHours,h.decDeg);if(d<cb)continue;const{x:f,y:p,z:g}=ni(d,u,Wp);this.namedStars.push({star:h,direction:new D(f,p,g).normalize(),altitudeDeg:d})}this.starTiers=$l.map((h,d)=>{const u=l.filter(w=>Pg(w.brightness)===d),f=new Float32Array(u.length*3),p=new Float32Array(u.length),g=new Float32Array(u.length*3),m=new Float32Array(u.length),v=new Float32Array(u.length);u.forEach((w,S)=>{f[S*3]=w.x,f[S*3+1]=w.y,f[S*3+2]=w.z,p[S]=w.brightness,g.set(w.illuminance,S*3),m[S]=w.phase,v[S]=w.speedFactor});const b=new ot;b.setAttribute("position",new st(f,3)),b.setAttribute("seed",new st(m.map(w=>w/(2*Math.PI)),1));const x=new st(new Float32Array(u.length*3),3);b.setAttribute("color",x);let y=this.starTiers[d]?.points;return y?(y.geometry.dispose(),y.geometry=b):(y=new ls(b,Ce.material(h.size)),Ce.track(y),this.celestialGroup.add(y)),{points:y,colorAttribute:x,brightness:p,illuminance:g,phase:m,speedFactor:v}}),this.starColoursRelative=Number.NaN,this.updateTwinkle(this.twinkleSeconds),this.startTwinkle()}twinkleSeconds=0;starColoursRelative=Number.NaN;updateTwinkle(e){Ce.setTime(e);const t=this.relativeScale;if(t!==this.starColoursRelative){this.starColoursRelative=t;for(const i of this.starTiers){const n=i.colorAttribute.array;for(let s=0;s<i.brightness.length;s++)n[s*3]=i.illuminance[s*3]*t,n[s*3+1]=i.illuminance[s*3+1]*t,n[s*3+2]=i.illuminance[s*3+2]*t;i.colorAttribute.needsUpdate=!0}}}buildClouds(){if(this.cloudRendering==="volume"||this.weather.cloudLayers!==void 0){this.layeredClouds||(this.disposeCloudSystem(),this.layeredClouds=new Wl(this.celestialGroup,Yp,this.cloudRendering)),this.disposeCirrus(),this.layeredClouds.hostHalo(this.iceHalos),this.layeredClouds.update(this.weather,this.observerElevationM+1.6),this.layeredClouds.setOffsets(this.cloudOffsetM,this.cloudLayerOffsetsM),this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor);return}const e=this.lowerCloudCover();if(e<=0){this.disposeCloudSystem();return}const t=this.weather.cloudDarkness,i=new ne(Wa[0]+(Zp[0]-Wa[0])*t,Wa[1]+(Zp[1]-Wa[1])*t,Wa[2]+(Zp[2]-Wa[2])*t);if(this.cloudMesh&&this.cloudUniforms){this.cloudUniforms.coverage.value=e,this.cloudUniforms.baseColor.value.copy(i),this.syncCloudLayer(),this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor);return}this.disposeCloudSystem();const{material:n,uniforms:s}=bm(i,e,Math.abs(this.cloudLayerOffset()));this.cloudMaterial=n,this.cloudUniforms=s,s.fieldOffset.value.copy(this.cloudFieldOffset),this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor);const r=Mm(Yp);this.cloudMesh=new Se(r,n),this.faceCloudDeck(this.cloudMesh,this.cloudLayerOffset()),this.celestialGroup.add(this.cloudMesh)}lowerCloudCover(){return this.weather.cloudLayers?1-this.weather.cloudLayers.filter(e=>e.type!=="cirrus").reduce((e,t)=>e*(1-t.coverage),1):this.weather.lowerCloudCover??this.weather.cloudCover}highCloudCover(){return this.weather.cloudLayers?1-this.weather.cloudLayers.filter(e=>e.type==="cirrus").reduce((e,t)=>e*(1-t.coverage),1):this.weather.highCloudCover}buildCirrus(){const e=this.weather.highCloudCover??0;if(this.layeredClouds||e<=0){this.disposeCirrus();return}if(this.cirrusMesh&&this.cirrusUniforms){this.cirrusUniforms.coverage.value=e,this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor);return}const{material:t,uniforms:i}=bm(new ne(...Wa),e,Nd,1);this.cirrusMaterial=t,this.cirrusUniforms=i,i.fieldOffset.value.copy(this.cloudFieldOffset),this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor),this.cirrusMesh=new Se(Mm(Yp*1.04),t),this.cirrusMesh.renderOrder=vb-1,this.celestialGroup.add(this.cirrusMesh)}disposeCirrus(){this.cirrusMesh&&(this.cirrusMesh.removeFromParent(),this.cirrusMesh.geometry.dispose()),this.cirrusMaterial?.dispose(),this.cirrusMesh=void 0,this.cirrusMaterial=void 0,this.cirrusUniforms=void 0}syncCloudLayer(){this.layeredClouds?.update(this.weather,this.observerElevationM+1.6);const e=this.cloudLayerOffset();this.cloudUniforms&&(this.cloudUniforms.layerHeight.value=Math.abs(e)),this.cloudMesh&&this.faceCloudDeck(this.cloudMesh,e)}faceCloudDeck(e,t){const i=t<0;e.scale.y=i?-1:1,e.renderOrder=i?Wl.deckOrder(!0,0,1):vb}cloudLayerOffset(){const t=((this.weather.cloudBaseM??Zm)-this.observerElevationM)*qp;return Math.sign(t||1)*Math.max(Math.abs(t),NC)}updateCloudLighting(e,t){const i=[this.cloudUniforms,this.cirrusUniforms].filter(d=>d!==void 0);if(i.length===0&&!this.layeredClouds)return;const n=this.cloudBeamDirection,[s,r,a]=this.cloudBeam.map(d=>d/Math.PI),l=this.lightningLevel*t0*this.relativeScale/Math.PI,c=new ne(t[0]+er.r*l,t[1]+er.g*l,t[2]+er.b*l);this.layeredClouds?.setLighting(n.clone(),new ne(s,r,a),c,c);const h=Math.max(0,n.y);for(const d of i)d.sunDir.value.copy(n),d.sunColor.value.setRGB(s*h,r*h,a*h),d.ambientColor.value.copy(c)}disposeCloudSystem(){this.layeredClouds?.dispose(),this.layeredClouds=void 0,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}precipitationCount(e){return WC(e,this.weather.precipitationIntensity,this.weather.precipitationAmount??1)}updatePrecipitationDensity(){const e=[[this.rainSystem?.points,Qp],[this.rainSplashSystem?.points,Xa],[this.precipitationPoints,this.weather.precipitationType==="none"||this.weather.precipitationType==="rain"?void 0:jp[this.weather.precipitationType].poolSize]];for(const[t,i]of e)t&&i!==void 0&&t.geometry.setDrawRange(0,this.precipitationCount(i));this.rainSystem&&(this.rainSystem.uniforms.uSpeedStreak.value=wb(e0(this.weather.precipitationIntensity)))}buildPrecipitation(){this.disposePrecipitationPoints(),this.disposeRain();const e=this.weather.precipitationType;if(e==="none")return;if(e==="rain"){this.buildRain();return}const t=jp[e],i=t.poolSize,n=i0(9001),s=new Float32Array(i*3),r=new Float32Array(i),a=new Float32Array(i),l=new Float32Array(i),c=new Float32Array(i),h=new Float32Array(i),d=new Float32Array(i),u=new Float32Array(i),f=new Float32Array(i),p=new Float32Array(i);for(let x=0;x<i;x++){const y=n()*Math.PI*2,w=n()*t.radiusM;s[x*3]=Math.cos(y)*w,s[x*3+1]=Sl+n()*(t.topYM-Sl),s[x*3+2]=Math.sin(y)*w,r[x]=n()*Math.PI*2,a[x]=.7+n()*.6,l[x]=.6+n()*.8,c[x]=.4+n()*1.2}const g=new ot;g.setAttribute("position",new st(s,3)),g.setDrawRange(0,this.precipitationCount(i));const m={uSize:{value:t.size},uScale:{value:.5*this.renderer.domElement.height},uOpacity:{value:t.opacity},uColor:{value:t.color.clone()},uHazeColor:{value:new ne(...this.baseFogColor)},uTexture:{value:t6(e)},uNearFocusDistance:{value:Ab},uHazeDistance:{value:t.radiusM*_b}},v=new Dt({uniforms:m,vertexShader:o6,fragmentShader:l6,transparent:!0,depthWrite:!1});this.precipitationUniforms=m;const b=new ls(g,v);b.renderOrder=Kp,this.scene.add(b),this.precipitationPoints=b,this.precipitationPositions=s,this.precipitationPhase=r,this.precipitationSpeedJitter=a,this.precipitationWobbleFreqJitter=l,this.precipitationWobbleAmpJitter=c,this.precipitationBounceRemaining=h,this.precipitationBounceHeight=d,this.precipitationBounceDuration=u,this.precipitationBounceVelX=f,this.precipitationBounceVelZ=p}updatePrecipitation(e,t){if(!this.precipitationPoints||!this.precipitationPositions||!this.precipitationPhase||!this.precipitationSpeedJitter)return;this.precipitationUniforms?.uHazeColor.value.setRGB(...this.baseFogColor);const i=this.weather.precipitationType;if(i==="none"||i==="rain")return;const n=jp[i];if(this.precipitationUniforms?.uColor.value.copy(Je.litBySky(n.color,this.baseFogColor)),t<=0)return;const s=this.weather.windDirectionDeg*Ci,r=Math.sin(s)*this.weather.windSpeed*n.driftSensitivity,a=-Math.cos(s)*this.weather.windSpeed*n.driftSensitivity,l=this.precipitationPositions,c=this.precipitationPhase,h=this.precipitationSpeedJitter,d=this.precipitationWobbleFreqJitter,u=this.precipitationWobbleAmpJitter,f=this.precipitationBounceRemaining,p=this.precipitationBounceHeight,g=this.precipitationBounceDuration,m=this.precipitationBounceVelX,v=this.precipitationBounceVelZ,b=i==="snow"&&d&&u,x=i==="hail"&&f&&p&&g&&m&&v;for(let y=0,w=0;y<l.length;y+=3,w++){if(x&&f[w]>0){if(f[w]-=t,f[w]<=0){const M=Math.random()*Math.PI*2,_=Math.sqrt(Math.random())*n.radiusM;l[y]=Math.cos(M)*_,l[y+1]=n.topYM,l[y+2]=Math.sin(M)*_,f[w]=0}else{const M=1-f[w]/g[w];l[y+1]=Sl+Math.sin(Math.PI*M)*p[w],l[y]=Ud(l[y]+(r+m[w])*t,n.radiusM),l[y+2]=Ud(l[y+2]+(a+v[w])*t,n.radiusM)}continue}let S=0,A=0;if(b){const M=$C*d[w],_=YC*u[w];S=Math.sin(e*M*Math.PI*2+c[w])*_,A=Math.sin(e*M*Math.PI*2+c[w]+Math.PI/2)*_}if(l[y]+=(r+S)*t,l[y+1]-=n.fallSpeedMPerS*h[w]*t,l[y+2]+=(a+A)*t,l[y]=Ud(l[y],n.radiusM),l[y+2]=Ud(l[y+2],n.radiusM),l[y+1]<Sl){if(x){p[w]=Cb*(.2+Math.random()*1.6),g[w]=qC*(.5+Math.random()),f[w]=g[w];const I=Math.random()*Math.PI*2,R=KC*(p[w]/Cb);m[w]=Math.cos(I)*R,v[w]=Math.sin(I)*R,l[y+1]=Sl;continue}const M=Math.random()*Math.PI*2,_=Math.sqrt(Math.random())*n.radiusM;l[y]=Math.cos(M)*_,l[y+1]=n.topYM,l[y+2]=Math.sin(M)*_}}this.precipitationPoints.geometry.attributes.position.needsUpdate=!0}buildRain(){const e=e0(this.weather.precipitationIntensity);this.rainSystem=S4({count:Qp,radiusM:Uc,heightM:UC,bottomYM:yb,overallSpeed:BC,color:Mb.clone(),opacity:.85,visibleCount:this.precipitationCount(Qp),speedStreak:wb(e),pixelSize:Ib,seed:9001,nearFocusDistanceM:Ab,hazeDistanceM:Uc*_b,hazeColor:new ne(...this.baseFogColor)}),this.rainLastVerticalFacing=-1,this.syncRainSlant(),this.rainSystem.points.renderOrder=Kp,this.scene.add(this.rainSystem.points),this.buildRainSplashes()}buildRainSplashes(){const e=i0(4242),t=new Float32Array(Xa*3),i=new Float32Array(Xa),n=new Float32Array(Xa),s=new Float32Array(Xa);for(let h=0;h<Xa;h++){const d=e()*Math.PI*2,u=Math.sqrt(e())*Uc;t[h*3]=Math.cos(d)*u,t[h*3+1]=yb,t[h*3+2]=Math.sin(d)*u,n[h]=kb(xb,Sb),i[h]=e()*n[h],s[h]=i[h]/n[h]}const r=new ot;r.setAttribute("position",new st(t,3));const a=new st(s,1);r.setAttribute("aLife",a),r.setDrawRange(0,this.precipitationCount(Xa));const l=new Dt({uniforms:{uMaxSize:{value:VC},uScale:{value:.5*this.renderer.domElement.height},uColor:{value:Eb.clone()},uTexture:{value:s6()}},vertexShader:r6,fragmentShader:a6,transparent:!0,depthWrite:!1}),c=new ls(r,l);c.renderOrder=Kp,this.scene.add(c),this.rainSplashSystem={points:c,positions:t,life:i,duration:n,lifeAttribute:a}}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}syncRainSlant(){const e=this.rainSystem;if(!e)return;const t=this.weather.windDirectionDeg*Ci;e.uniforms.uDropVelocity.value.set(Math.sin(t)*this.weather.windSpeed,-e0(this.weather.precipitationIntensity),-Math.cos(t)*this.weather.windSpeed);const i=this.renderer.getSize(this.rainViewportSize);e.uniforms.uAspect.value=i.x/Math.max(i.y,1)}updateRain(e){const t=this.rainSystem;if(!t)return;t.uniforms.uTime.value+=e,t.uniforms.uHazeColor.value.setRGB(...this.baseFogColor),t.uniforms.uColor.value.copy(Je.litBySky(Mb,this.baseFogColor));const i=this.rainSplashSystem?.points.material?.uniforms?.uColor;i&&i.value.copy(Je.litBySky(Eb,this.baseFogColor));const n=this.weather.windDirectionDeg*Ci,s=Math.sin(n)*this.weather.windSpeed,r=-Math.cos(n)*this.weather.windSpeed,a=Uc,l=h=>(h%(a*2)+a*3)%(a*2)-a;t.uniforms.uWindOffset.value.set(l(t.uniforms.uWindOffset.value.x+s*e),l(t.uniforms.uWindOffset.value.y+r*e)),this.syncRainSlant(),this.camera.getWorldDirection(this.rainCameraDirection);const c=Math.abs(this.rainCameraDirection.y);if(Math.abs(c-this.rainLastVerticalFacing)>.001){this.rainLastVerticalFacing=c;const h=Db+(1-Db)*(1-c),d=Rb+(1-Rb)*(1-c);t.uniforms.uUvSquash.value=d,t.uniforms.uPixelSize.value=Ib*h*(.5+.5*d)}this.updateRainSplashes(e)}updateRainSplashes(e){const t=this.rainSplashSystem;if(!t||e<=0)return;const{positions:i,life:n,duration:s,lifeAttribute:r}=t,a=r.array;for(let l=0,c=0;l<i.length;l+=3,c++){if(n[c]+=e,n[c]>=s[c]){const h=Math.random()*Math.PI*2,d=Math.sqrt(Math.random())*Uc;i[l]=Math.cos(h)*d,i[l+2]=Math.sin(h)*d,s[c]=kb(xb,Sb),n[c]=0}a[c]=n[c]/s[c]}t.points.geometry.attributes.position.needsUpdate=!0,r.needsUpdate=!0}setLightning(e){this.lightningFlashes=e}updateLightning(e){let t,i=0;if(this.lightningArmed)for(const l of this.lightningFlashes){if(l.t>e)break;const c=qi.brightnessAt(l,e);c>i&&(t=l,i=c)}const n=t?Math.min(1,Math.max(.1,(JC/t.distanceM)**2)):0,s=i*n*(t?.cloudToGround?1:.6);if(s===this.lightningLevel&&!t?.cloudToGround)return;if(this.lightningLevel=s,this.scene.fog){const l=this.scene.fog,c=s*t0*this.relativeScale/Math.PI;l.color.setRGB(this.airlight[0]+er.r*c,this.airlight[1]+er.g*c,this.airlight[2]+er.b*c)}const r=this.skyMesh?.material?.color;if(r){const l=s*QC;r.setRGB(1+l*er.r,1+l*er.g,1+l*er.b)}if(this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor),this.lightningLight.intensity=s*t0*this.relativeScale,t){const{x:l,y:c,z:h}=ni(25,t.azimuthDeg,Wn);this.lightningLight.position.set(l,c,h)}this.lightningBolt||(this.lightningBolt=new va(Wn*.95),this.celestialGroup.add(this.lightningBolt.object));const a=this.weather.cloudBaseM??1500;this.lightningBolt.set(t,i,a),this.render()}buildCompassLabels(){this.compassSprites=TC.map(e=>{const t=Ro.point(e,this.compassPoints),i=new eu({map:c6(t),depthTest:!1,fog:!1}),n=new Ec(i),{x:s,y:r,z:a}=ni(0,e,fb);return n.position.set(s,r,a),n.scale.set(Fd,Fd,1),n.renderOrder=RC,n.layers.set(Gp),n.visible=this.compassHovered||this.compassForced,this.celestialGroup.add(n),n}),this.updateCompassScale()}updateCompassScale(){const e=this.camera.fov*Math.PI/360,t=pb*Math.PI/360,i=Fd*Math.tan(e)/Math.tan(t);for(const n of this.compassSprites)n.scale.set(i,i,1)}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 i of Array.isArray(t)?t:[t]){const n=i.map;n&&n.dispose(),i.dispose()}}}const Ci=Math.PI/180;function sr(o,e,t){return Math.max(e,Math.min(t,o))}function kb(o,e){return o+Math.random()*(e-o)}function Ud(o,e){return(o%(e*2)+e*3)%(e*2)-e}let Bd,zd;function t6(o){switch(o){case"snow":return i6();case"hail":return n6()}}function i6(){if(Bd)return Bd;const o=64,e=document.createElement("canvas");e.width=o,e.height=o;const t=e.getContext("2d"),i=t.createRadialGradient(o/2,o/2,0,o/2,o/2,o/2);return i.addColorStop(0,"rgba(255,255,255,0.95)"),i.addColorStop(.5,"rgba(255,255,255,0.55)"),i.addColorStop(1,"rgba(255,255,255,0)"),t.fillStyle=i,t.fillRect(0,0,o,o),Bd=new Kr(e),Bd}function n6(){if(zd)return zd;const o=64,e=document.createElement("canvas");e.width=o,e.height=o;const t=e.getContext("2d"),i=t.createRadialGradient(o/2,o/2,0,o/2,o/2,o/2);return i.addColorStop(0,"rgba(255,255,255,1)"),i.addColorStop(.55,"rgba(255,255,255,0.95)"),i.addColorStop(.8,"rgba(255,255,255,0.4)"),i.addColorStop(1,"rgba(255,255,255,0)"),t.fillStyle=i,t.fillRect(0,0,o,o),zd=new Kr(e),zd}let Hd;function s6(){if(Hd)return Hd;const o=64,e=document.createElement("canvas");e.width=o,e.height=o;const t=e.getContext("2d"),i=t.createRadialGradient(o/2,o/2,0,o/2,o/2,o/2);return i.addColorStop(0,"rgba(255,255,255,0)"),i.addColorStop(.4,"rgba(255,255,255,0)"),i.addColorStop(.6,"rgba(255,255,255,0.9)"),i.addColorStop(.8,"rgba(255,255,255,0.25)"),i.addColorStop(1,"rgba(255,255,255,0)"),t.fillStyle=i,t.fillRect(0,0,o,o),Hd=new Kr(e),Hd}const r6=`
9727
+ `,transparent:!0,blending:Wi,depthWrite:!1,side:fi,fog:!1});this.object=new Se(new Ii(Yg.RADIUS,128,32,0,Math.PI*2,0,_t.MAX_ANGLE_RAD),t),this.object.renderOrder=-1,this.object.frustumCulled=!1,this.object.visible=!1}show(e,t){if(!e||!t){this.object.visible=!1;return}this.towards.set(e.x,e.y,e.z).normalize(),this.object.quaternion.setFromUnitVectors(this.up,this.towards),this.object.material.uniforms.uSource.value.copy(this.towards);for(let i=0;i<_t.STEPS;i++){for(let n=0;n<3;n++)this.texels[i*4+n]=fs.toHalfFloat(Math.min(t[i*3+n],6e4));this.texels[i*4+3]=fs.toHalfFloat(1)}this.texture.needsUpdate=!0,this.object.visible=!0}dispose(){this.object.geometry.dispose(),this.object.material.dispose(),this.texture.dispose()}}class af{constructor(e){this.generator=e}static SIZE=128;target=new Eh(af.SIZE,{type:ci,generateMipmaps:!1,minFilter:mt,magFilter:mt});camera=new Ig(.1,2e5,this.target);filteredTarget;capturedAtMs=-1/0;capturedVersion;get sharp(){return this.target.texture}get filtered(){return this.filteredTarget?.texture}capture(e,t,i,n=[]){const s=e.shadowMap.autoUpdate;let r=!1;t.traverse(l=>{const c=l;c.isLight&&c.castShadow&&c.shadow&&!c.shadow.map&&(r=!0)}),e.shadowMap.autoUpdate=r?s:!1;const a=n.map(l=>l.visible);for(const l of n)l.visible=!1;this.camera.position.copy(i),this.camera.update(e,t),n.forEach((l,c)=>{l.visible=a[c]}),e.shadowMap.autoUpdate=s,this.filteredTarget=this.generator.fromCubemap(this.target.texture,this.filteredTarget),this.capturedAtMs=performance.now()}dispose(){this.target.dispose(),this.filteredTarget?.dispose()}}class Jn{static REFRESH_MS=250;generator;eye;probes=new Map;constructor(e){Jn.install(),this.generator=new mm(e),this.eye=new af(this.generator)}static decor;refresh(e,t,i,n,s,r,a,l=[],c,h=Jn.REFRESH_MS){for(const m of[...this.probes.keys()])n.some(v=>v.id===m&&v.shiny)||(this.probes.get(m).dispose(),this.probes.delete(m));const d=[{probe:this.eye}];for(const m of n){if(!m.shiny)continue;let v=this.probes.get(m.id);v||(v=new af(this.generator),this.probes.set(m.id,v)),d.push({probe:v,reflector:m})}const u=performance.now(),f=()=>d.filter(({probe:m})=>m.capturedVersion!==a),p=f().filter(({probe:m})=>u-m.capturedAtMs>=h);if(p.length>0){const m=p.reduce((v,b)=>b.probe.capturedAtMs<v.probe.capturedAtMs?b:v);if(m.reflector){const v=m.reflector.holder.getWorldPosition(this.scratch);m.probe.capture(e,t,v,[m.reflector.holder,...s]),Jn.reflectOn(m.reflector.holder,m.probe)}else{m.probe.capture(e,t,i,[...s,...l]),c?.(m.probe.sharp),Jn.decor=m.probe.filtered;for(const v of r)Jn.reflectOn(v,m.probe);for(const v of n)v.shiny||Jn.reflectOn(v.holder,m.probe)}m.probe.capturedVersion=a}const g=f();if(g.length!==0)return Math.max(16,Math.min(...g.map(({probe:m})=>h-(u-m.capturedAtMs))))}scratch=new D;static reflectOn(e,t={filtered:Jn.decor}){e.traverse(i=>{const n=i.material;for(const s of Array.isArray(n)?n:n?[n]:[])s instanceof Th?t.sharp&&s.setSurroundings(t.sharp):s instanceof Ma&&t.filtered&&s.envMap!==t.filtered&&(s.envMap=t.filtered,s.needsUpdate=!0)})}dispose(){this.eye.dispose();for(const e of this.probes.values())e.dispose();this.generator.dispose()}static installed=!1;static install(){if(Jn.installed)return;Jn.installed=!0;const e="iblIrradiance += getIBLIrradiance( geometryNormal );";if(!tt.lights_fragment_maps.includes(e)){console.warn("Reflections: three's lights_fragment_maps changed; the environment will light diffusely too");return}tt.lights_fragment_maps=tt.lights_fragment_maps.replace(e,"// The sky's diffuse light is the hemisphere light's (see Reflections).")}}function aC(o,e){return JSON.stringify(o.cloudLayers)===JSON.stringify(e.cloudLayers)&&o.cloudCover===e.cloudCover&&o.cloudDarkness===e.cloudDarkness&&o.cloudBaseM===e.cloudBaseM&&o.highCloudCover===e.highCloudCover&&o.iceCrystalAlignment===e.iceCrystalAlignment&&o.lowerCloudCover===e.lowerCloudCover&&o.relativeHumidity===e.relativeHumidity&&o.precipitationType===e.precipitationType&&o.precipitationIntensity===e.precipitationIntensity&&o.precipitationAmount===e.precipitationAmount&&o.windDirectionDeg===e.windDirectionDeg&&o.windSpeed===e.windSpeed&&o.storm===e.storm}const Ld=900,Hp=1,sb=4,Gp=5,rb=.5,xl=900,oC=6371e3,lC=3e4;function ab(o){const e=Math.sqrt(2*oC*Math.max(o,0));return Math.max(xl,Math.min(e,lC))}const Vp=.5,Wp=850,Xp=.03,cC=.015,Wn=850,Nc=300,oa=120,hC=700,dC=3.5,Od=20,ob=.04,uC=.26,lb=4,$p=1.5,cb=-1,fC=.01,au=-4,pC=2,mC=20,Nd=2600,gC=.97,vC=.38,Fc=au,yC=8,bC=2,MC=-.5,hb=1500,wC=.7,xC=.3,SC=.32,EC=.65,db=2.4,AC=.9,_C=400,TC=[0,45,90,135,180,225,270,315],IC=2,DC=16,ub=4e3,fb=880,Fd=40,pb=60,RC=10,CC=1,kC=150,PC=55,LC=.5,OC=17,mb=.265,gb=[[0,0],...Array.from({length:8},(o,e)=>{const t=e*Math.PI/4;return[Math.cos(t)*mb,Math.sin(t)*mb]})],Yp=700,qp=250/Zm,NC=12,vb=5,Kp=6,Wa=[.92,.92,.95],Zp=[.15,.15,.19],jp={snow:{fallSpeedMPerS:2,size:.3,color:new ne(1,1,1),driftSensitivity:1,radiusM:25,topYM:20,opacity:.75,poolSize:2400},hail:{fallSpeedMPerS:14,size:.5,color:new ne(.95,.98,1),driftSensitivity:.25,radiusM:25,topYM:10,opacity:.95,poolSize:1200}},Sl=0,Jp=0,FC=150,Qp=3e3,Uc=20,UC=15,yb=Sl,BC=40,bb=1,zC=9;function e0(o){return bb+(zC-bb)*o}const Mb=new ne(.75,.82,.92),HC=10,GC=.5;function wb(o){return sr(o/HC,GC,1)}const Xa=200,xb=.18,Sb=.32,VC=.35,Eb=new ne(.85,.9,.98),Ab=5,_b=.85,Tb=.01;function WC(o,e,t=1){return Math.round(o*(Tb+(1-Tb)*e)*t)}function XC(o,e){return JSON.stringify(o.cloudLayers)===JSON.stringify(e.cloudLayers)&&o.cloudCover===e.cloudCover&&o.cloudDarkness===e.cloudDarkness&&o.cloudBaseM===e.cloudBaseM&&o.highCloudCover===e.highCloudCover&&o.iceCrystalAlignment===e.iceCrystalAlignment&&o.lowerCloudCover===e.lowerCloudCover}const Ib=230,Db=.7,Rb=.05,$C=.6,YC=.7,qC=.15,Cb=.35,KC=3,ZC=1/12,jC=.5,er=new ne(.82,.86,1),JC=2500,QC=1.6,t0=15,e6={Venus:new ne(1,.96,.85),Mars:new ne(1,.55,.4),Jupiter:new ne(.95,.87,.72),Saturn:new ne(.92,.86,.68)};class Ze{renderer;scene=new xr;phenomena=new Ls(this.scene);references=new ks(this.scene,()=>this.render());camera;celestialGroup=new Pt;skyMesh;skyGradientMaterial;scatteredSky;lastAstronomy;skyColoursStale=!1;scatteredSkyFrameId=null;skyHoldUntilMs=void 0;onFirstFrameHold;firstFrameReady(){return(!this.scatteredSky||this.scatteredSky.ambient!==void 0)&&!this.iceHalos?.awaitingFirstDisplay}sceneSettled(){return this.firstFrameReady()&&this.arrivalsPending===0&&this.eyeSettledVersion>=this.lastArrivalVersion}arrivalsPending=0;eyeSettledVersion=-1;lastArrivalVersion=0;awaitArrival(e,t){if(this.skyHoldUntilMs===null)return e;this.arrivalsPending++;let i=!0;const n=()=>{i&&(i=!1,this.arrivalsPending--,this.lastArrivalVersion=this.sceneVersion,this.skyHoldUntilMs&&this.redrawHeld())},s=t===void 0?void 0:setTimeout(n,t);return t!==void 0&&(this.arrivalDeadlineMs=Math.max(this.arrivalDeadlineMs,performance.now()+t),this.skyHoldUntilMs&&this.arrivalDeadlineMs>this.skyHoldUntilMs&&(this.skyHoldUntilMs=this.arrivalDeadlineMs,setTimeout(()=>this.render(),t+20))),e.finally(()=>{clearTimeout(s),n()})}static ROADS_PATIENCE_MS=4e3;static TERRAIN_PATIENCE_MS=12e3;arrivalDeadlineMs=0;redrawHeld(){this.frameDirty=!0,!(this.animationFrameId!==null||this.framesDriven||this.flushFrameId!==null)&&(this.flushFrameId=requestAnimationFrame(()=>{this.flushFrameId=null,this.drawIfDirty()}))}holdForNewScene(e){this.surroundings=void 0,this.scatteredSky?.resetSurroundings(),this.startHold(),e&&this.awaitArrival(e).catch(()=>{})}startHold(){this.skyHoldUntilMs=Math.max(performance.now()+ub,this.arrivalDeadlineMs),this.eyeSettledVersion=-1,this.lastArrivalVersion=this.sceneVersion+1,this.iceHalos?.setUrgent(!0),this.skyGlow?.setWithheld(!0),this.onFirstFrameHold?.(!0),setTimeout(()=>this.render(),ub+20)}groundMesh;terrainMesh;terrainProviders;terrainOrigin;terrainMeshOrigin;terrainBuildToken=0;terrainAttribution;roadSystem=new ii;roadAttribution;roadWays;statedRoads=[];traces=[];traceLabels=new Map;tracesShown=!0;traceSystem;traceSystemLoading;traceResolution=new we;decorModelProvider=ru[0].create();decorModelToken=0;decorModelCredits=new Map;bodySystem=new bt(e=>this.awaitArrival(this.loadBodyModel(e)),()=>this.render(),()=>this.relativeScale);bodyOrigin={x:0,z:0};starTiers=[];bodyMeshes=new Map;hitAreas=new Map;glareSprites=new Map;decorObjects=[];terraces=[];decorGroups=new Map;decorPresence=new Map;decorSunlight=new Map;static TRAFFIC_MODEL_RANGE_PER_METRE=133;static TRAFFIC_MODEL_DEFAULT_LENGTH_M=37.6;static trafficModelRangeM(e){return(e.sizeM?.lengthM??Ze.TRAFFIC_MODEL_DEFAULT_LENGTH_M)*Ze.TRAFFIC_MODEL_RANGE_PER_METRE}pendingTrafficModels=new Map;contrails=[];contrailSystem;contrailSystemLoading;contrailSunlight=new Map;sceneSunBeam=[0,0,0];decorReferencePose;decorCurrentPose;decorTime=0;celestialLight=new $1(16777215,0);celestialLightTarget=new hi;skyLight=new nA(16777215,0,0);streetlightLights=new Map;headlightSystem;headlightLoading;headlightSettings=new Map;observerHeadlights;compassSprites=[];showCompass=!1;compassHovered=!1;compassForced=!1;animationFrameId=null;resolution;cssSize={width:1,height:1};frameDirty=!1;flushFrameId=null;framesDriven=!1;lastFrameTimeMs;raycaster=new tu;weather=pf;observerElevationM=0;siteElevationM=0;air=new xs;groundRadius=xl;terrainRadius=xl;cloudRendering="volume";layeredClouds;cloudLayerOffsetsM={};cloudOffsetM=new D;cloudFieldOffset=new D;cloudMesh;cirrusMesh;cirrusMaterial;cirrusUniforms;cloudMaterial;cloudUniforms;precipitationPoints;precipitationPositions;precipitationPhase;precipitationSpeedJitter;precipitationWobbleFreqJitter;precipitationWobbleAmpJitter;precipitationBounceRemaining;precipitationBounceHeight;precipitationBounceDuration;precipitationBounceVelX;precipitationBounceVelZ;precipitationUniforms;rainSystem;rainSplashSystem;rainCameraDirection=new D;rainLastVerticalFacing=-1;rainViewportSize=new we;lightningArmed=!1;lightningFlashes=[];lightningLevel=0;lightningBolt;lightningLight=new $1(16777215,0);baseFogColor=[0,0,0];lastSunPosition;lensFlare;sunUnhiddenFraction=1;lensFlareArtifactIntensity=0;sunWorldPosition=new D;sunVisible=!1;lensFlareScratch=new D;sunOcclusionRaycaster=new tu;sunOcclusionDirectionScratch=new D;sunOcclusionRightScratch=new D;sunOcclusionUpScratch=new D;ufoOcclusionRaycaster=new tu;projectionKind="rectilinear";starPoints=0;namedStars=[];equidistantPass;depthOfFieldPass;finishPass;exposureAccumulation;exposureInstants=1;get developingExposure(){return this.exposureInstants>1&&this.exposureInstantAt!==void 0}static EXPOSURE_BUDGET_MS=12;static exposureInstantsPerFrame(e){return Math.max(3,Math.round(6e6/Math.max(1,e)))}exposureFrameId=null;exposureInstantsDone=0;exposureInstantAt;restatingExposure=!1;lensOptics;instrumentMagnitudeGain=0;lightPollution;meteorSystem;cometTail;satelliteField;reentrySystem;plumeSystem;iceHalos;lunarDiffraction;eclipsedSun=new Ih;eclipseDiscs;solarCorona;sunBeamFraction=1;sunDiscRadiance=[0,0,0];lunarDiffractionKey="";rainbow;skyGlow;cometKey;novaKeys=new Set;constructor(e,t=QS()){this.renderer=new yD({canvas:e,antialias:!0}),this.resolution=new Ut(Math.min(window.devicePixelRatio||1,2),this.renderer.getContext()),this.renderer.setPixelRatio(this.resolution.pixelRatio),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=Zc,this.camera=new Qn(60,e.width/Math.max(e.height,1),.1,Ld*1.2),this.camera.position.set(0,1.6,0),this.terrainProviders=t,this.celestialLight.shadow.mapSize.set(1024,1024),this.celestialLight.shadow.camera.left=-oa,this.celestialLight.shadow.camera.right=oa,this.celestialLight.shadow.camera.top=oa,this.celestialLight.shadow.camera.bottom=-oa,this.celestialLight.shadow.camera.near=Wn-Nc,this.celestialLight.shadow.camera.far=Wn+Nc,this.celestialLight.shadow.bias=-.03/(2*Nc),this.celestialLight.shadow.normalBias=ob,this.celestialLight.target=this.celestialLightTarget,this.lightningLight.color.copy(er),this.scene.add(this.celestialLight,this.celestialLightTarget,this.skyLight,this.lightningLight),this.scene.add(this.celestialGroup),this.scene.add(this.bodySystem.group),this.scene.add(this.roadSystem.group),this.roadSystem.onMarkings=()=>{this.compileNextFrameOffThread(),this.render()};const i=new dt(this.renderer,()=>{this.skyColoursStale=!0,this.render()});i.supported?this.scatteredSky=i:i.dispose()}get currentTerrainAttribution(){return this.terrainAttribution}get currentRoadAttribution(){return this.roadAttribution}resize(e,t){this.cssSize.width=e,this.cssSize.height=t,this.renderer.setSize(e,t,!1),this.camera.aspect=e/Math.max(t,1),this.camera.updateProjectionMatrix(),this.render()}setCloudRendering(e){e!==this.cloudRendering&&(this.cloudTransmissionMemo.clear(),this.cloudRendering=e,this.layeredClouds?.dispose(),this.layeredClouds=void 0,this.buildClouds(),this.buildCirrus(),this.render())}setCloudOffset(e,t={}){this.cloudOffsetM.set(e.x,0,e.z),this.cloudLayerOffsetsM=t,this.layeredClouds?.setOffsets(e,t),this.cloudFieldOffset.set(e.x*qp,0,e.z*qp);for(const i of[this.cloudUniforms,this.cirrusUniforms])i?.fieldOffset.value.copy(this.cloudFieldOffset);this.iceHalos?.setCloudOffset(this.layeredClouds?.cirrusMask?.offset??this.cloudFieldOffset)}setObserverPose(e){const t=((e.rollDeg??0)+this.gaitOffset.rollDeg)*Ci,i=(e.pitchDeg+this.lookPitchDeg+this.gaitOffset.pitchDeg)*Ci;e.headingDeg!==void 0?this.camera.rotation.set(i,-(e.headingDeg+this.lookYawDeg+this.gaitOffset.yawDeg)*Ci,t,"YXZ"):this.camera.rotation.set(i,this.camera.rotation.y,t,"YXZ"),e.elevationM!==this.observerElevationM&&(this.observerElevationM=e.elevationM,this.syncCloudLayer(),Math.abs(ab(e.elevationM)-this.groundRadius)>1&&(this.buildGround(),this.celestialGroup.scale.setScalar(this.groundRadius/xl),this.camera.far=Math.max(Ld*1.2,this.groundRadius*2.5),this.camera.updateProjectionMatrix())),e.lat!==void 0&&e.lng!==void 0&&this.placeTerrain(e.lat,e.lng,0,0),this.poseElevationM=e.elevationM,this.poseCameraY=this.groundYUnder(0,0)+1.6+e.elevationM,this.camera.position.y=this.poseCameraY,this.celestialGroup.position.y=this.camera.position.y,this.camera.fov!==e.fovDeg&&(this.camera.fov=e.fovDeg,this.camera.updateProjectionMatrix(),this.updateCompassScale())}setTerrainProviders(e){this.stopTerrainFade(),this.terrainProviders=e,this.disposeMesh(this.terrainMesh),this.terrainMesh=void 0,this.terrainOrigin=void 0,this.terrainMeshOrigin=void 0,this.terrainAttribution=void 0,this.roadSystem.clear(),this.roadAttribution=void 0,this.roadWays=void 0,this.applyGroundDepthWrite(),this.terrainBuildToken++}observerRoute;setObserverRoute(e){this.observerRoute=e,this.decorTerrainRadiusM=Ze.terrainReachFor(this.decorObjects,e)}decorTerrainRadiusM=0;static terrainReachFor(e,t){if(t&&t.length>=2){const s=t[0];for(const r of t){const a=vt(r.lat,r.lng,s.lat,s.lng);if(Math.hypot(a.x,a.z)>Ze.STILL_OBSERVER_M)return 0}}let i=0;for(const s of e){if(s.kind==="aircraft"||s.kind==="observer"||s.track)continue;const r=Math.max(s.sizeM?.widthM??0,s.sizeM?.lengthM??0)/2;i=Math.max(i,Math.hypot(s.eastM,s.northM)+r)}const n=Math.ceil(i/Ze.PATCH_WHOLE_SHARE/100)*100;return n>xl*Ze.PATCH_WHOLE_SHARE?Math.min(n,Ze.MAX_DECOR_TERRAIN_M):0}static STILL_OBSERVER_M=60;static PATCH_WHOLE_SHARE=700/900;static MAX_DECOR_TERRAIN_M=3e3;placeTerrain(e,t,i,n){const s=(r,a)=>{const l=vt(a.lat,a.lng,e,t);r.position.x=l.x-i,r.position.z=l.z+n};this.terrainMesh&&this.terrainMeshOrigin&&s(this.terrainMesh,this.terrainMeshOrigin),this.fadingTerrain&&s(this.fadingTerrain.mesh,this.fadingTerrain.origin)}setTerrainOrigin(e,t,i){if(e===void 0||t===void 0)return;const n=Math.max(this.groundRadius,this.decorTerrainRadiusM);if(this.terrainOrigin&&Math.abs(this.terrainRadius-n)<n*.1){const{x:c,z:h}=vt(e,t,this.terrainOrigin.lat,this.terrainOrigin.lng);if(Math.sqrt(c*c+h*h)<kC*(n/xl))return}const s=this.terrainRadius,r=this.terrainMeshOrigin;r!==void 0&&Math.hypot(vt(e,t,r.lat,r.lng).x,vt(e,t,r.lat,r.lng).z)<=s||(this.roadSystem.clear(),this.roadAttribution=void 0),this.terrainOrigin={lat:e,lng:t},this.terrainRadius=n;const l=++this.terrainBuildToken;this.awaitArrival(d4(e,t,this.terrainProviders,n,{route:this.observerRoute}),Ze.TERRAIN_PATIENCE_MS).then(({mesh:c,attribution:h,originElevationM:d})=>{if(l!==this.terrainBuildToken)return;this.setSiteElevation(d??0),this.anchorGrassTo(c,e,t);const u=this.terrainMesh,f=this.terrainMeshOrigin,p=f?vt(e,t,f.lat,f.lng):void 0;u&&p&&Math.hypot(p.x,p.z)<=s&&(c.position.y=u.position.y+this.groundYOfPatch(u,p.x,p.z)),u&&f&&p&&Math.hypot(p.x,p.z)<=s?this.crossfadeTerrain(c,u,f):this.disposeMesh(this.terrainMesh),c.renderOrder=CC,this.terrainMesh=c,this.terrainMeshOrigin={lat:e,lng:t},this.compileNextFrameOffThread(),this.terrainAttribution=h,this.scene.add(c),this.applyGroundDepthWrite(),this.decorCurrentPose&&(this.setObserverPose(this.decorCurrentPose),this.updateDecorAnchoring(this.decorReferencePose,this.decorCurrentPose,this.decorTime)),this.buildRoads(e,t,n),this.drapeStatedRoads(),this.drapeTraces(),this.render(),i?.()}).catch(c=>{console.warn("Terrain build failed, keeping the flat ground fallback:",c),i?.()})}grassReference;anchorGrassTo(e,t,i){if(this.grassReference){const r=vt(this.grassReference.lat,this.grassReference.lng,t,i);Math.hypot(r.x,r.z)>2e4&&(this.grassReference=void 0)}this.grassReference??={lat:t,lng:i};const n=vt(this.grassReference.lat,this.grassReference.lng,t,i);e.material.userData?.grassOrigin?.set(n.x,n.z)}static TERRAIN_CROSSFADE_MS=1200;fadingTerrain;crossfadeTerrain(e,t,i){this.stopTerrainFade();const n=e.material;n.opacity=0,n.polygonOffset=!0,n.polygonOffsetFactor=-1,n.polygonOffsetUnits=-4;const s=performance.now(),r=()=>{const a=Math.min(1,(performance.now()-s)/Ze.TERRAIN_CROSSFADE_MS);if(n.opacity=a*a*(3-2*a),this.render(),a<1&&this.fadingTerrain){this.fadingTerrain.frameId=requestAnimationFrame(r);return}n.polygonOffset=!1,n.opacity=1,this.fadingTerrain&&this.disposeMesh(this.fadingTerrain.mesh),this.fadingTerrain=void 0,this.render()};this.fadingTerrain={mesh:t,origin:i,frameId:requestAnimationFrame(r)}}stopTerrainFade(){if(!this.fadingTerrain)return;cancelAnimationFrame(this.fadingTerrain.frameId),this.disposeMesh(this.fadingTerrain.mesh),this.fadingTerrain=void 0;const e=this.terrainMesh?.material;e&&(e.opacity=1,e.polygonOffset=!1)}static ROADS_MAX_RADIUS_M=5e3;buildRoads(e,t,i){const n=this.terrainProviders.roads;if(!n||i>Ze.ROADS_MAX_RADIUS_M){this.roadSystem.clear(),this.roadAttribution=void 0;return}const s=this.roadWays;if(s&&s.lat===e&&s.lng===t&&s.radiusM===i){this.drapeRoads(s.ways,e,t,n.contemporary);return}s&&Math.hypot(vt(e,t,s.lat,s.lng).x,vt(e,t,s.lat,s.lng).z)<=s.radiusM&&this.drapeRoads(s.ways,e,t,n.contemporary),this.awaitArrival(n.getRoads(l2(e,t,i)),Ze.ROADS_PATIENCE_MS).then(r=>{this.terrainOrigin?.lat!==e||this.terrainOrigin?.lng!==t||(this.roadWays={lat:e,lng:t,radiusM:i,ways:r},this.drapeRoads(r,e,t,n.contemporary))}).catch(r=>{console.warn("Roads unavailable, drawing none:",r)})}setStatedRoads(e){e!==this.statedRoads&&(this.statedRoads=e,this.drapeStatedRoads(),this.render())}drapeStatedRoads(){const e=this.terrainMesh;e&&(this.roadSystem.group.position.copy(e.position),this.roadSystem.setGroundSpacing(this.patchSpacingM(e)),this.roadSystem.setStated(this.statedRoads,(t,i)=>this.groundYOfPatch(e,t,i)))}setTraces(e,t=new Map){e===this.traces&&t===this.traceLabels||(this.traces=e,this.traceLabels=t,!(e.length===0&&!this.traceSystem)&&this.loadTraceSystem().then(()=>{this.drapeTraces(),this.render()}))}setTracesShown(e){e!==this.tracesShown&&(this.tracesShown=e,this.drapeTraces(),this.render())}loadTraceSystem(){return this.traceSystemLoading??=Ue(async()=>{const{TraceSystem:e}=await import("./TraceSystem-dUHBN-oM.js");return{TraceSystem:e}},[],import.meta.url).then(({TraceSystem:e})=>{const t=new e(Gp);this.scene.add(t.group),this.traceSystem=t})}drapeTraces(){const e=this.traceSystem,t=this.terrainMesh,i=this.terrainMeshOrigin;!e||!t||!i||(e.group.position.copy(t.position),e.set(this.tracesShown?this.traces:[],this.traceLabels,i.lat,i.lng,this.siteElevationM,(n,s)=>this.groundYOfPatch(t,n,s)))}drapeRoads(e,t,i,n){const s=this.terrainMesh;s&&(this.roadSystem.group.position.copy(s.position),this.roadSystem.setGroundSpacing(this.patchSpacingM(s)),this.roadSystem.set(e,t,i,(r,a)=>this.groundYOfPatch(s,r,a),n,this.terrainRadius),this.roadAttribution=e.length>0?this.terrainProviders.roads?.attribution:void 0,this.compileNextFrameOffThread(),this.render())}setShowCompass(e){this.showCompass!==e&&(this.showCompass=e,this.disposeCompassLabels(),e&&this.buildCompassLabels(),this.render())}setCompassPoints(e){this.compassPoints!==e&&(this.compassPoints=e,this.showCompass&&(this.disposeCompassLabels(),this.buildCompassLabels(),this.render()))}compassPoints;applyLensFlareTint(e){if(!this.lensFlare)return;const t=PC*(this.sunArriving[1]/OC);this.lensFlare.uniforms.uColorGain.value.setRGB(t*e[0],t*e[1],t*e[2]),this.applyDazzleStrength()}applyDazzleStrength(){if(!this.lensFlare)return;const[e,t,i]=this.sunArriving,n=Math.max(t,1e-30);this.lensFlare.uniforms.uDazzleColour.value.setRGB(e/n,1,i/n),this.lensFlare.uniforms.uVeilStrength.value=rn.K*t*this.sunUnhiddenFraction}sunArriving=[0,0,0];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;if(this.compassSprites.some(t=>t.visible!==e)){for(const t of this.compassSprites)t.visible=e;this.developingExposure?this.exposureInstantsDone>0&&this.presentExposure():this.render()}}setWeather(e){if(aC(this.weather,e))return;this.cloudTransmissionMemo.clear();const t=this.weather;this.weather=e;const i=!XC(t,e),n=t.precipitationType!==e.precipitationType,s=t.precipitationIntensity!==e.precipitationIntensity||t.precipitationAmount!==e.precipitationAmount;(t.relativeHumidity!==e.relativeHumidity||n||s)&&(this.air=xs.of(e),this.applyAir(),this.scatteredSky?.setConditions({aerosolOpticalDepth:e.relativeHumidity===void 0?void 0:Hr.steppedOpticalDepth(e.relativeHumidity)}),this.pumpScatteredSky()),i&&(this.buildClouds(),this.buildCirrus()),n?this.buildPrecipitation():s&&this.updatePrecipitationDensity(),this.lastAstronomy&&(i&&(this.buildIceHalos(this.lastAstronomy.sun,this.lastAstronomy.moon),this.buildLunarDiffraction(this.lastAstronomy.moon)),(i||n||s)&&this.buildRainbow(this.lastAstronomy.sun,this.lastAstronomy.moon)),this.lightningArmed=e.storm&&e.cloudDarkness>=jC,this.syncAnimationLoop(),this.render()}setDecor(e){if(this.decorObjects===e)return;this.decorObjects=e,this.decorTerrainRadiusM=Ze.terrainReachFor(e,this.observerRoute),this.decorModelToken++,this.decorModelCredits.clear(),this.pendingTrafficModels.clear();for(const i of this.decorGroups.values())i.removeFromParent(),Fe.dispose(i);this.decorGroups.clear(),this.streetlightLights.clear(),this.headlightSystem?.clear(!0),this.headlightSettings.clear();const t=e.filter(i=>i.kind==="streetlight").sort((i,n)=>Math.hypot(i.eastM,i.northM)-Math.hypot(n.eastM,n.northM)).slice(0,yC);for(const i of e){const n=Fe.build(i,i.lit??!1);this.scene.add(n),this.decorGroups.set(i.id,n),i.kind==="streetlight"&&t.includes(i)&&this.addStreetlightLight(i.id,n,t.indexOf(i)<bC),i.model&&i.id.startsWith(Ss.ID_PREFIX)?(this.pendingTrafficModels.set(i.id,i),this.awaitArrival(this.loadDecorModel(i,this.decorModelToken,!0))):this.reuseLoadedDecorModel(i,n)||this.awaitArrival(this.loadDecorModel(i,this.decorModelToken))}e.some(i=>i.kind==="vehicle")&&this.loadHeadlights(),this.syncHeadlightBeams(),this.celestialLight.castShadow=this.decorGroups.size>0||this.bodySystem.any}setDecorSunlight(e){this.decorSunlight=e}setContrails(e){e!==this.contrails&&(this.contrails=e,!(e.length===0&&!this.contrailSystem)&&this.loadContrailSystem().then(()=>{this.contrailSystem?.set(this.contrails),this.updateContrails(),this.render()}))}setContrailSunlight(e){this.contrailSunlight=e}loadContrailSystem(){return this.contrailSystemLoading??=Ue(async()=>{const{ContrailSystem:e}=await import("./ContrailSystem-BZiaCFt7.js");return{ContrailSystem:e}},__vite__mapDeps([0,1]),import.meta.url).then(({ContrailSystem:e})=>{const t=new e;this.scene.add(t.group),this.contrailSystem=t})}contrailTint(e){const t=this.contrailSunlight.get(e),i=this.lastAstronomy?.sun,n=Ze.CONTRAIL_SCATTERING,s=this.skyLight.color,r=[s.r*n*.5,s.g*n*.5,s.b*n*.5];if(t&&i){const a=Fn.litFraction(t.sunElevationDeg,t.heightM);if(a>0){const l=this.air.transmittanceFromSpace(t.heightM,t.sunElevationDeg),c=_t.illuminanceOf(i.magnitude)*this.relativeScale;for(let h=0;h<3;h++)r[h]+=n*c*l[h]*a}}return r}static CONTRAIL_SCATTERING=1/(4*Math.PI);updateContrails(){this.contrailSystem?.update(this.decorTime,{origin:this.bodyOrigin,eye:this.camera.position,pixelRad:this.contrailPixelRad()},e=>this.contrailTint(e))}contrailPixelRad(){const e=Math.max(1,this.renderer.getDrawingBufferSize(this.bloomSize).y);return Math.max(this.lampBloomRadiusRad()??0,this.camera.fov*Math.PI/180/e)}setDecorPresence(e){this.decorPresence=e}entryOfDecorModel(e){return this.decorModelProvider.entry(e).catch(()=>{})}setDecorModelProvider(e){this.decorModelProvider=e;const t=this.decorObjects;this.decorObjects=[],this.setDecor(t)}get currentDecorModelCredits(){return[...this.decorModelCredits.values(),...this.bodySystem.modelCredits]}get bodyGround(){const{x:e,z:t}=this.bodyOrigin,i=this.groundYUnder(e,t);return{heightAt:(n,s)=>this.groundYUnder(e+n,t-s)-i}}bodyMaskedByDecor(e,t){const i=this.decorGroups.get(t);return i?this.bodySystem.maskedShare(e,i):void 0}setBodies(e,t=0,i=e.map(r=>r.id),n=[],s){const{x:r,z:a}=this.bodyOrigin,l=this.scatteredSky;this.bodySystem.set(e,{originX:r,originZ:a,originGroundY:this.groundYUnder(r,a),eye:this.camera.position,groundYAt:(h,d)=>this.groundYUnder(h,d),wind:s,light:this.plumeLight(),occluders:[...this.decorGroups.values()],transmittance:(h,d,u)=>this.transmittanceTo(h,d,u)},t,l?(h,d)=>l.relativeOfLuminance(h,d):void 0,i),this.bodySystem.setSmoke(n,t),this.bodySystem.any&&(this.celestialLight.castShadow=!0),this.fitShadowToBodies();const c=this.bodySystem.furthestFrom(this.camera.position)*1.2;c>this.camera.far&&(this.camera.far=c,this.camera.updateProjectionMatrix())}plumeLight(){const e=this.celestialLight.color,t=this.celestialLight.intensity*.5,i=this.skyLight.color,n=this.skyLight.groundColor,s=this.skyLight.intensity,r=(a,l,c)=>(a*t+(l+c)/2*s)/Math.PI;return[r(e.r,i.r,n.r),r(e.g,i.g,n.g),r(e.b,i.b,n.b)]}bodyOutline(e,t){return this.bodySystem.outlineOf(e,t)}documentUrl;modelUrl(e){return e.url?this.documentRelative(e.url):void 0}documentRelative(e){if(e.startsWith("data:"))return e;const t=this.documentUrl??(typeof location>"u"?void 0:location.href);return t?new URL(e,t).href:e}async loadBodyModel(e){const t=e.url?void 0:e.id?await this.decorModelProvider.entry(e.id):void 0,i=this.modelUrl(e)??t?.url,n=e.credit??t?.credit;if(!(!i||!n))return{scene:await zp(i),credit:n,headingOffsetDeg:e.headingOffsetDeg??t?.headingOffsetDeg}}loadedDecorModels=new Map;reuseLoadedDecorModel(e,t){const i=this.loadedDecorModels.get(e.id);return!i||i.ref!==JSON.stringify(mh(e))||!Fe.usesModel(e)?!1:(this.applyLoadedDecorModel(e,t,i),!0)}applyLoadedDecorModel(e,t,i){const n=i.scene.clone(!0);n.traverse(s=>{s instanceof Se&&(s.userData.sharedModel=!0)}),Fe.applyModelParameters(n,e.modelParameters,i.bindings),Fe.applyModel(t,e,n,{headingOffsetDeg:i.headingOffsetDeg,depictedSizeM:i.depictedSizeM}),this.decorModelCredits.set(e.id,i.credit)}standInScenes=new Map;async loadDecorModel(e,t,i=!1){const n=i?ku[e.kind]:mh(e);if(!(!n||!Fe.usesModel(e)))try{const s=n.url?void 0:n.id?await this.decorModelProvider.entry(n.id):void 0,r=this.modelUrl(n)??s?.url,a=n.credit??s?.credit;if(!r||!a)return;const l=i||e.kind==="tree"?await this.standInScene(r):await zp(r);if(t!==this.decorModelToken||i&&!this.pendingTrafficModels.has(e.id))return;const c=this.decorGroups.get(e.id);if(!c)return;!i&&e.kind!=="tree"&&Jn.reflectOn(l);const h={ref:JSON.stringify(n),scene:l,headingOffsetDeg:n.headingOffsetDeg??s?.headingOffsetDeg,depictedSizeM:s?.sizeM,credit:a,bindings:s?.parameters?.bindings};i||this.loadedDecorModels.set(e.id,h),this.applyLoadedDecorModel(e,c,h),this.render()}catch(s){console.warn(`Keeping the built-in shape for decor "${e.id}":`,s)}}standInScene(e){let t=this.standInScenes.get(e);return t||(t=zp(e).then(i=>(/jungle-jim-realistic-trees/.test(e)||Jn.reflectOn(i),i)),this.standInScenes.set(e,t)),t}updateDecorAnchoring(e,t,i=0){this.decorReferencePose=e,this.decorCurrentPose=t,this.decorTime=i;const n=e?.lat!==void 0&&e.lng!==void 0&&t?.lat!==void 0&&t?.lng!==void 0?vt(e.lat,e.lng,t.lat,t.lng):{x:0,z:0},s=this.decorObjects.find(u=>u.observerSide!==void 0&&ka(u.kind));this.terrainMesh&&t?.lat!==void 0&&t.lng!==void 0&&(this.placeTerrain(t.lat,t.lng,s?0:this.gaitOffset.eastM,s?0:this.gaitOffset.northM),this.roadSystem.group.position.copy(this.terrainMesh.position),this.traceSystem?.group.position.copy(this.terrainMesh.position)),s||(n.x-=this.gaitOffset.eastM,n.z+=this.gaitOffset.northM,this.camera.position.y=this.poseCameraY+this.gaitOffset.upM,this.celestialGroup.position.y=this.camera.position.y);const r={x:0,z:0};let a=0,l;if(s){const u=Gs(s,i),f=Fe.occupantView(s,u.headingDeg),p=-(u.headingDeg??0)*Ci,g=f.x*Math.cos(p)+f.z*Math.sin(p),m=-f.x*Math.sin(p)+f.z*Math.cos(p),v=u.eastM+n.x,b=-u.northM+n.z;r.x=-(v+g),r.z=-(b+m),this.camera.position.y=this.groundYUnder(v,b)+f.eyeY,l=f.eyeY,this.camera.rotation.set(this.indoorLookPitchDeg*Ci,-(f.headingDeg+this.indoorLookYawDeg)*Ci,0,"YXZ")}this.bodyOrigin={x:n.x+r.x,z:n.z+r.z};const c=this.findCabin(i,n,r);this.fitShadowToCabin(c.length>0),this.dimCabinSky(c),this.placeShadowFrustum(),this.placeTerraces(i,n,r);const h=this.terraces.map(u=>[u.x,u.z,u.cos,u.sin,u.halfWidthM,u.halfLengthM,u.levelY].map(f=>f.toFixed(3)).join(",")).join(";");!s&&this.terraces.length>0&&(this.poseCameraY=this.groundYUnder(0,0)+1.6+this.poseElevationM,this.camera.position.y=this.poseCameraY+this.gaitOffset.upM,this.celestialGroup.position.y=this.camera.position.y);for(const u of this.decorObjects){if(u.kind==="terrace")continue;const f=this.decorGroups.get(u.id);if(!f)continue;const p=Gs(u,i),g=p.eastM+n.x+r.x,m=-p.northM+n.z+r.z,v=this.terrainMesh,b=`${v?.geometry.uuid}:${(g-(v?.position.x??0)).toFixed(3)}:${(m-(v?.position.z??0)).toFixed(3)}:${(v?.position.y??0).toFixed(3)}:${p.headingDeg}:${p.altitudeM}:${h}`;if(f.userData.footprintKey!==b){if(u.kind==="wire"){const M=Fe.wireGround(u,g,m,p.headingDeg,(_,I)=>this.groundYUnder(_,I));f.userData.footprintGroundY=M.startY,Fe.shearWire(f,Fe.sizeOf(u).lengthM,M.dropM)}else f.userData.footprintGroundY=this.groundUnderFootprint(u,g,m,p.headingDeg,p.altitudeM);f.userData.footprintKey=b}const y=p.altitudeM>Ze.AIRBORNE_M&&Math.hypot(g,m)<Ze.CABIN_MATE_RANGE_M?this.poseCameraY-1.6-this.poseElevationM:f.userData.footprintGroundY;if(f.position.set(g,y+p.altitudeM,m),u.kind==="crop"){const M=Math.hypot(g,m);f.visible=M<=FC}const w=this.decorPresence.get(u.id),S=w!==void 0&&(i<w.fromMs||i>w.untilMs);w&&(f.visible=!S);const A=this.decorSunlight.get(u.id);if(A&&!S&&this.lightFromAbove(f,A),p.headingDeg!==void 0&&(f.rotation.y=-p.headingDeg*Ci),u.kind==="crop"&&f.visible){const M=this.terrainMesh,_=[M?.geometry.uuid,g-(M?.position.x??0),m-(M?.position.z??0),f.position.y-(M?.position.y??0),p.headingDeg,p.altitudeM].map(I=>typeof I=="number"?I.toFixed(4):I).join(":");f.userData.cropGroundKey!==_&&(Fe.fitCropToGround(f,(I,R)=>this.groundYUnder(I,R)+p.altitudeM),f.userData.cropGroundKey=_)}if(!S){const M=f.position.distanceTo(this.camera.position);a=Math.max(a,M),M<Ze.trafficModelRangeM(u)&&this.pendingTrafficModels.delete(u.id)&&this.loadDecorModel(u,this.decorModelToken)}}if(s&&l!==void 0){const u=this.decorGroups.get(s.id);u&&(this.camera.position.y=u.position.y+l)}this.updateContrails();const d=Math.max(Ld*1.2,this.groundRadius*2.5,a*1.2);Math.abs(this.camera.far-d)>1&&(this.camera.far=d,this.camera.updateProjectionMatrix())}groundYUnder(e,t){const i=this.terrainYUnder(e,t);let n=i;for(const s of this.terraces){const r=e-s.x,a=t-s.z,l=r*s.cos-a*s.sin,c=r*s.sin+a*s.cos;if(Math.abs(l)<=s.halfWidthM&&Math.abs(c)<=s.halfLengthM){const h=Math.min(1,Math.max(0,(s.halfWidthM-Math.abs(l))/s.bankM)),d=h*h*(3-2*h);n=Math.max(n,d*s.levelY+(1-d)*Math.min(s.levelY,i))}}return n}placeTerraces(e,t,i){this.terraces=[];const n=this.terrainMesh;for(const s of this.decorObjects){if(s.kind!=="terrace")continue;const r=this.decorGroups.get(s.id);if(!r)continue;const a=Gs(s,e),l=a.eastM+t.x+i.x,c=-a.northM+t.z+i.z,h=Fe.sizeOf(s),d=-(a.headingDeg??0)*Ci,u=Math.cos(d),f=Math.sin(d),p=`${n?.geometry.uuid}:${(l-(n?.position.x??0)).toFixed(3)}:${(c-(n?.position.z??0)).toFixed(3)}:${(n?.position.y??0).toFixed(3)}:${a.headingDeg}:${h.widthM}:${h.lengthM}:${h.heightM}`;r.position.set(l,0,c),a.headingDeg!==void 0&&(r.rotation.y=d),r.userData.terraceKey!==p&&(r.userData.terraceLevelY=Fe.fitTerrace(r,s,(g,m)=>this.terrainYUnder(l+g*u+m*f,c-g*f+m*u)),r.userData.terraceKey=p),this.terraces.push({x:l,z:c,cos:u,sin:f,halfWidthM:h.widthM/2,halfLengthM:h.lengthM/2,levelY:r.userData.terraceLevelY,bankM:Math.min(10,h.widthM/4)})}}terrainYUnder(e,t){const i=this.terrainMesh;return i?i.position.y+this.groundYOfPatch(i,e-i.position.x,t-i.position.z):Jp}patchSpacingM(e){const t=e.geometry.getAttribute("position");return t&&t.count>=2?Math.abs(t.getX(1)-t.getX(0)):1/0}groundYOfPatch(e,t,i){const n=e.geometry.getAttribute("position"),s=Math.round(Math.sqrt(n.count));if(s<2||s*s!==n.count)return Jp;const r=n.getX(0),a=n.getX(s-1),l=n.getZ(0),c=n.getZ((s-1)*s),h=sr((t-r)/(a-r)*(s-1),0,s-1),d=sr((i-l)/(c-l)*(s-1),0,s-1);if(!Number.isFinite(h)||!Number.isFinite(d))return Jp;const u=Math.min(Math.floor(h),s-2),f=Math.min(Math.floor(d),s-2),p=h-u,g=d-f,m=(w,S)=>n.getY(w*s+S),v=m(f,u),b=m(f,u+1),x=m(f+1,u),y=m(f+1,u+1);return p+g<=1?v+(b-v)*p+(x-v)*g:y+(x-y)*(1-p)+(b-y)*(1-g)}groundUnderFootprint(e,t,i,n,s=0){return Fe.groundUnderFootprint(e,t,i,n,(r,a)=>this.groundYUnder(r,a),s)}lookYawDeg=0;lookPitchDeg=0;poseCameraY=1.6;poseElevationM=0;setGait(e){this.gaitOffset=e}gaitOffset={eastM:0,northM:0,upM:0,rollDeg:0,pitchDeg:0,yawDeg:0};setLookOffset(e,t){this.lookYawDeg=e,this.lookPitchDeg=t}indoorLookYawDeg=0;indoorLookPitchDeg=0;setIndoorLook(e,t){this.indoorLookYawDeg=e,this.indoorLookPitchDeg=t}medium;setMedium(e,t,i,n){const s=e&&t!==void 0&&t>0&&i!==void 0&&i>0?{kind:e.kind,iso:n??e.iso,autoExposure:e.autoExposure===!0,exposureSeconds:t,fNumber:i}:void 0;JSON.stringify(s)!==JSON.stringify(this.medium)&&(this.medium=s,this.render())}applyMedium(){const e=this.medium,t=Math.max(this.relativeScale,1e-30);if(!e){Ln.uMedium.value=0;return}Ln.uMedium.value=e.kind==="negative"?1:e.kind==="slide"?2:3;const i=e.autoExposure?this.scatteredSky?.sceneAdaptation:void 0;Ln.uMediumExposure.value=i!==void 0&&i>0?1/(t*i):.065*e.exposureSeconds*e.iso*this.filterTransmittance/(e.fNumber*e.fNumber*t)}grain;lampBloomRadiusRad(){if(!this.grain)return;const e=this.camera.fov*Math.PI/180,t=this.grain.frameHeightMm/(2*Math.tan(e/2)),i=Math.max(1,this.renderer.getDrawingBufferSize(this.bloomSize).y);return Math.max(this.grain.detailUm*.001/t,e/i)}bloomSize=new we;lampTransmittance(e){const t=this.siteElevationM+this.camera.position.y,i=this.siteElevationM+e.position.y;return this.air.transmittance(t,i,e.position.distanceTo(this.camera.position))}updateDecorLitState(e,t=0){const i=this.lampBloomRadiusRad();for(const n of this.decorObjects){const s=this.decorGroups.get(n.id);if(s&&n.lights?.length&&Fe.setLights(s,n.lights,e,s.position.distanceTo(this.camera.position),t,this.relativeScale,i,this.lampTransmittance(s)),n.kind!=="streetlight"&&n.kind!=="vehicle")continue;const r=this.decorGroups.get(n.id);if(!r)continue;const a=n.kind==="streetlight"&&n.origin!==void 0&&n.lit===void 0&&!n.litKeyframes?.length&&this.lastAstronomy,l=n.kind==="vehicle"?_M(n,e):void 0,c=a?this.lastAstronomy.sun.altitudeDeg<MC:l!==void 0?Ca.lamps(l):Mf(n,e);Fe.setLit(r,n.kind,c,this.relativeScale);const h=this.streetlightLights.get(n.id);h&&(h.visible=c),l!==void 0&&(this.headlightSettings.set(n.id,l),this.aimDecorBeam(n,r,l))}this.aimObserverBeam()}loadHeadlights(){return this.headlightSystem?Promise.resolve():this.headlightLoading??=Ue(async()=>{const{HeadlightSystem:e}=await import("./HeadlightSystem-BipIIHQg.js");return{HeadlightSystem:e}},[],import.meta.url).then(({HeadlightSystem:e})=>{this.headlightSystem??=new e(this.scene),this.syncHeadlightBeams(),this.compileNextFrameOffThread(),this.render()})}syncHeadlightBeams(){const e=this.headlightSystem;if(e){for(const t of this.decorObjects)t.kind==="vehicle"&&e.add(t.id);this.observerHeadlights&&e.add("observer"),this.aimBeams()}}aimBeams(){if(!(!this.headlightSystem||this.headlightSystem.size===0)){for(const e of this.decorObjects){const t=this.headlightSettings.get(e.id),i=this.decorGroups.get(e.id);t!==void 0&&i&&this.aimDecorBeam(e,i,t)}this.aimObserverBeam()}}headlightScatterPerM(){const e=this.siteElevationM+this.camera.position.y,t=200,i=this.air.transmittance(e,e,t)[1];return i>0?-Math.log(Math.min(1,i))/t:.05}aimDecorBeam(e,t,i){if(!this.headlightSystem?.has(e.id))return;t.updateMatrixWorld(!0);const n=new D(0,0,-1).transformDirection(t.matrixWorld);if(n.y=0,n.lengthSq()<1e-9)return;n.normalize();const s=Fe.sizeOf(e).lengthM,r=t.getWorldPosition(new D).addScaledVector(n,s/2-xC);r.y+=wC;const a=Fe.sizeOf(e).widthM;this.headlightSystem.aim(e.id,i,r,n,a*SC,this.relativeScale,this.headlightScatterPerM())}setObserverHeadlights(e){this.observerHeadlights=e,e&&this.loadHeadlights(),this.headlightSystem&&(e?this.headlightSystem.add("observer"):this.headlightSystem.remove("observer"),this.aimObserverBeam())}aimObserverBeam(){const e=this.observerHeadlights;if(!e||!this.headlightSystem?.has("observer"))return;const t=e.setting==="auto"?this.lastAstronomy?Ca.auto(this.lastAstronomy.sun.altitudeDeg):"off":e.setting,i=e.headingDeg*Math.PI/180,n=new D(Math.sin(i),0,-Math.cos(i)),s=new D(n.x*db,this.camera.position.y-AC,n.z*db);this.headlightSystem.aim("observer",t,s,n,EC,this.relativeScale,this.headlightScatterPerM())}addStreetlightLight(e,t,i){const n=Fe.bodyOf(t),s=n.children.find(a=>a.userData.emissive);if(!s)return;const r=new Sw(16764006,hb*this.relativeScale,_C);r.position.copy(s.position).multiply(n.scale),r.castShadow=i,r.shadow.mapSize.set(512,512),r.shadow.bias=-.002,t.add(r),this.streetlightLights.set(e,r)}applyWindowGlow(){const e=this.lastAstronomy;Fe.setLitWindowShare(e?dn.share(e.sun.altitudeDeg,e.localHour):0)}setAstronomy(e){(!this.lastAstronomy||Math.abs(this.lastAstronomy.sun.altitudeDeg-e.sun.altitudeDeg)>2)&&(this.surroundings=void 0,this.scatteredSky?.resetSurroundings()),this.lastAstronomy=e,this.applyWindowGlow(),this.scatteredSky?.update(this.scatteredSkyState(e)),this.skyHoldUntilMs===void 0&&this.startHold(),this.pumpScatteredSky(),this.lastSunPosition=e.sun,this.buildSky(e.sun),this.buildGround();const t=this.magnitudeLimitOf(e);this.buildStars(e.stars,t),this.placeBodies(e,t),this.buildIceHalos(e.sun,e.moon),this.buildRainbow(e.sun,e.moon),this.applySkyColours(e),this.syncAnimationLoop(),this.render()}static relativeSkyOf(e,t){const i=r=>{const a=Hs.luminanceOf(r);if(!(a>0))return[0,0,0];const l=Ie.relativeOfResponse(a)/a;return[r[0]*l,r[1]*l,r[2]*l]},n=i(e.zenith),s=i(e.horizon);return{zenith:n,horizon:s,airlight:s,skyIrradiance:[n[0]*Math.PI,n[1]*Math.PI,n[2]*Math.PI],scale:t}}placeBodies(e,t){this.bodiesScale=this.relativeScale,this.sunBeamFraction=_i.beamFraction(e.eclipse),this.setBodyMesh("sun",e.sun,lb,new ne(1,.96,.88),e.sun.magnitude),this.placeEclipse(e),this.setMoonMesh(e.moon,t),this.buildPlanets(e.planets,t),this.buildComet(e.comet,t),this.buildNovae(e.novae??[],t)}placeEclipse(e){const t=e.eclipse;if(!t||e.sun.altitudeDeg<au){this.eclipsedSun.setMoon(void 0),this.eclipseDiscs=void 0,this.solarCorona?.show(void 0,[0,0,0]);return}const i=lb/Wn*(180/Math.PI),n=i/t.sunRadiusDeg,s=ni(e.sun.altitudeDeg,e.sun.azimuthDeg,1),r=ni(e.moon.altitudeDeg,e.moon.azimuthDeg,1),a=Math.acos(sr(s.x*r.x+s.y*r.y+s.z*r.z,-1,1)),l=a>1e-9?sr(t.separationDeg*n*Ci/a,0,2):0,c=Math.sin(a),[h,d]=a>1e-9?[Math.sin((1-l)*a)/c,Math.sin(l*a)/c]:[1,0],u={x:s.x*h+r.x*d,y:s.y*h+r.y*d,z:s.z*h+r.z*d},f=t.moonRadiusDeg*n;this.eclipseDiscs={sun:new D(s.x,s.y,s.z).normalize(),moon:new D(u.x,u.y,u.z).normalize(),sunRadiusRad:i*Ci,moonRadiusRad:f*Ci};const p=.01,g=(b,x)=>ni(e.sun.altitudeDeg+b,e.sun.azimuthDeg+x,1),m={x:g(p,0).x-g(-p,0).x,y:g(p,0).y-g(-p,0).y,z:g(p,0).z-g(-p,0).z},v={x:g(0,p).x-g(0,-p).x,y:g(0,p).y-g(0,-p).y,z:g(0,p).z-g(0,-p).z};if(this.eclipsedSun.setMoon(u,f,t.limb?{profile:t.limb,scale:n,up:m,right:v}:void 0),t.obscuration<.9){this.solarCorona?.show(void 0,[0,0,0]);return}this.solarCorona||(this.solarCorona=new Pl(i*Math.PI/180,this.eclipsedSun.cut),this.celestialGroup.add(this.solarCorona.object)),this.solarCorona.show(s,this.sunDiscRadiance)}bodiesScale=0;applySkyColours(e){this.skyColoursStale=!1,this.bodiesScale!==this.relativeScale&&(this.placeBodies(e,this.magnitudeLimitOf(e)),this.applyDazzleStrength(),this.buildIceHalos(e.sun,e.moon),this.buildRainbow(e.sun,e.moon));const t=this.scatteredSky?.ambient??Ze.relativeSkyOf(Em(e.sun.altitudeDeg),this.relativeScale),i=t,n=this.lightUnderClouds(e),s=r=>n?[0,1,2].map(a=>r[a]*n.through+n.radiance[a]*(1-n.through)):[r[0],r[1],r[2]];this.baseFogColor=[i.horizon[0],i.horizon[1],i.horizon[2]],this.airlight=s(i.airlight),this.skyMesh&&this.skyGradientMaterial&&(this.skyMesh.material=this.scatteredSky?.ready?this.scatteredSky.material:this.skyGradientMaterial),this.updateCelestialLight(e,t),this.updateCloudLighting(e.sun,this.baseFogColor),Ce.setEye(this.scatteredSky?.rodShare??0,this.relativeScale),this.updateTwinkle(this.twinkleSeconds);for(const r of this.streetlightLights.values())r.intensity=hb*this.relativeScale;this.buildSkyGlow(e,i.zenith),this.applyAir(),this.buildLunarDiffraction(e.moon)}reflections;sceneVersion=0;reflectionTimer;buildLunarDiffraction(e){const t=this.scatteredSky?.ready?this.scatteredSky:void 0;if(e.altitudeDeg<-.5||!t){this.lunarDiffraction?.show(void 0),this.lunarDiffractionKey="";return}const i=this.weather.relativeHumidity,n=(i===void 0?He.DEFAULT_AEROSOL_OPTICAL_DEPTH:Hr.opticalDepth(i))*He.aerosolDensity(this.siteElevationM+this.observerElevationM),s=this.cloudTransmission(e),r=-Math.log(Math.max(this.cloudTransmission(e,!0),1e-4)),a=_t.aureoleScale(n,_t.airMass(e.altitudeDeg))*s,l=_t.coronaScale(r),c=_t.illuminanceOf(e.magnitude),h=[e.altitudeDeg.toFixed(1),e.azimuthDeg.toFixed(1),e.magnitude.toFixed(2),a.toExponential(2),l.toExponential(2),Math.log10(Math.max(t.adaptation,1e-12)).toFixed(2)].join(":");if(h===this.lunarDiffractionKey)return;this.lunarDiffractionKey=h,this.lunarDiffraction||(this.lunarDiffraction=new Yg,this.celestialGroup.add(this.lunarDiffraction.object));const d=_t.profile(_t.HAZE_COARSE_MODE),u=_t.profile(_t.CLOUD_DROPLETS),f=Ey(e.altitudeDeg),p=new Float32Array(_t.STEPS*3);let g=0;for(let x=0;x<_t.STEPS;x++){const y=x*3,w=[0,1,2].map(A=>c*f[A]*(a*d[y+A]+l*u[y+A])),S=Hs.shown(w,Hs.luminanceOf(w),(A,M)=>t.relativeOfLuminance(A,M));p.set(S,y),g=Math.max(g,Hs.response(S))}const{x:m,y:v,z:b}=ni(e.altitudeDeg,e.azimuthDeg,1);this.lunarDiffraction.show(g>1/200?{x:m,y:v,z:b}:void 0,p)}applyAir(){this.scene.fog instanceof ko||(this.scene.fog=new ko),this.scene.fog.setAir(this.air,this.siteElevationM,this.airlight)}airlight=[0,0,0];transmittanceTo(e,t,i){const n=this.camera.position;return this.air.transmittance(this.siteElevationM+n.y,this.siteElevationM+t,Math.hypot(e-n.x,t-n.y,i-n.z))}setSiteElevation(e){Math.abs(e-this.siteElevationM)<1||(this.siteElevationM=e,this.applyAir(),this.lastAstronomy&&this.scatteredSky?.update(this.scatteredSkyState(this.lastAstronomy)))}umbraTint(){const e=this.siteElevationM+this.observerElevationM+1.6,[t,i,n]=this.air.transmittance(e,e,Ze.UMBRA_PATH_M),s=.2126*t+.7152*i+.0722*n;return s>0?[(.4124*t+.3576*i+.1805*n)/s,1,(.0193*t+.1192*i+.9505*n)/s]:[.9505,1,1.089]}static UMBRA_PATH_M=8e4;umbraOf(e){const t=e.eclipse?.horizonShare;return t&&Math.max(...t)<.1?{share:t,tint:this.umbraTint()}:void 0}scatteredSkyState(e){return{altitudeM:this.siteElevationM+this.observerElevationM+1.6,lightPollution:this.lightPollution,sun:{altitudeDeg:e.sun.altitudeDeg,azimuthDeg:e.sun.azimuthDeg,magnitude:e.sun.magnitude},sunLight:_i.beamFraction(e.eclipse),zenithFloorCdM2:e.eclipse?_i.UMBRA_ZENITH_CD_M2:void 0,umbra:this.umbraOf(e),moon:{altitudeDeg:e.moon.altitudeDeg,azimuthDeg:e.moon.azimuthDeg,magnitude:e.moon.magnitude,phaseAngleDeg:ce.phaseAngleOf(e.moon.phase.illuminatedFraction)}}}pumpScatteredSky(){const e=this.scatteredSky;!e||e.tables.ready||this.scatteredSkyFrameId!==null||this.contextReleased||this.suspended||(this.scatteredSkyFrameId=requestAnimationFrame(()=>{this.scatteredSkyFrameId=null,!this.contextReleased&&(e.advance(this.skyHoldUntilMs?DC:IC),this.pumpScatteredSky())}))}cancelScatteredSkyPump(){this.scatteredSkyFrameId!==null&&(cancelAnimationFrame(this.scatteredSkyFrameId),this.scatteredSkyFrameId=null)}setSatellites(e){if(e.length===0&&!this.satelliteField?.count)return;this.satelliteField||(this.satelliteField=new I4(Wp),this.celestialGroup.add(this.satelliteField.object));const t=this.lastAstronomy?this.magnitudeLimitOf(this.lastAstronomy):Aa(-90,this.instrumentMagnitudeGain);this.satelliteField.set(e,t,i=>this.cloudTransmission(i),(i,n)=>this.arrivingIlluminance(i,n,1)),this.render()}setReentries(e){if(e.length===0&&!this.reentrySystem?.count)return;this.reentrySystem||(this.reentrySystem=new $n,this.celestialGroup.add(this.reentrySystem.object));const t=this.lastAstronomy?this.magnitudeLimitOf(this.lastAstronomy):Aa(-90,this.instrumentMagnitudeGain);this.reentrySystem.set(e,t,i=>this.cloudTransmission(i),(i,n)=>this.arrivingIlluminance(i,n,1)),this.render()}setLaunchPlumes(e){e.length===0&&!this.plumeSystem?.count||(this.plumeSystem||(this.plumeSystem=new hn,this.celestialGroup.add(this.plumeSystem.object)),this.plumeSystem.set(e,this.relativeScale,t=>this.air.transmittanceFromSpace(this.siteElevationM+this.observerElevationM,t.altitudeDeg),t=>this.cloudTransmission(t)),this.render())}get plumePuffCount(){return this.plumeSystem?.count??0}get reentryCount(){return this.reentrySystem?.count??0}pickTrafficAt(e,t){this.aimAtScreenPoint(this.raycaster,e,t);const i=this.raycaster.ray.direction,n=Math.cos(Xp*this.camera.fov*Math.PI/180);let s,r=n;const a=new D;for(const[l,c]of this.decorGroups){if(!c.visible||!l.startsWith(Ss.ID_PREFIX))continue;a.copy(c.position).sub(this.camera.position).normalize();const h=a.dot(i);h>r&&(r=h,s=l)}return s&&!this.groundHides(e,t)?s:void 0}pickSatelliteAt(e,t){if(!this.satelliteField?.count)return;this.aimAtScreenPoint(this.raycaster,e,t);const i=Math.cos(Xp*this.camera.fov*Math.PI/180),n=this.satelliteField.nearest(this.raycaster.ray.direction,i);return n&&this.groundHides(e,t)?void 0:n}updateCelestialLight(e,t){const i=this.relativeScale,n=e.sun.altitudeDeg>=Fc,s=!n&&e.moon.altitudeDeg>=Fc,r=n?e.sun:e.moon,a=[0,0,0],l=Math.max(0,Math.sin(Math.max(r.altitudeDeg,0)*Ci)),c=this.siteElevationM+this.observerElevationM;let h=r,d=n||s?nb.directFraction(r.altitudeDeg,c):0;n&&d<=0&&e.moon.altitudeDeg>=Fc&&(h=e.moon,d=nb.directFraction(h.altitudeDeg,c));const u=Math.max(0,Math.sin(Math.max(h.altitudeDeg,0)*Ci)),f=n||s?this.cloudTransmission(r):1,p=-Math.log(Math.max(f,1e-6)),g=Math.max(0,1/(1+.1125*p)-f),m=[0,0,0];if(n||s){const S=_t.illuminanceOf(r.magnitude)*i,A=this.air.transmittanceFromSpace(c,r.altitudeDeg);for(let R=0;R<3;R++)m[R]=S*A[R]*g*l,this.cloudBeam[R]=S*A[R];const{x:M,y:_,z:I}=ni(r.altitudeDeg,r.azimuthDeg,1);if(this.cloudBeamDirection.set(M,_,I),d>0){const R=_t.illuminanceOf(h.magnitude)*i,L=h===r?A:this.air.transmittanceFromSpace(c,h.altitudeDeg),P=h===r?f:this.cloudTransmission(h);for(let O=0;O<3;O++)a[O]=R*L[O]*P*d}}else this.cloudBeam.fill(0);const v=this.surroundings;if(v)this.skyLight.color.setRGB(v.up[0]*i,v.up[1]*i,v.up[2]*i),this.skyLight.groundColor.setRGB(v.down[0]*i,v.down[1]*i,v.down[2]*i);else{const S=this.skyCloudTransmission(),A=t.skyIrradiance,M=[0,1,2].map(I=>A[I]*S+m[I]);this.skyLight.color.setRGB(M[0],M[1],M[2]);const _=Ye.GROUND_ALBEDO;this.skyLight.groundColor.setRGB(_*(M[0]+a[0]*u),_*(M[1]+a[1]*u),_*(M[2]+a[2]*u))}if(this.skyLight.intensity=1,this.sceneSunBeam=h===e.sun?[a[0],a[1],a[2]]:[0,0,0],!n&&!s||d<=0){this.celestialLight.intensity=0;return}const{x:b,y:x,z:y}=ni(h.altitudeDeg,h.azimuthDeg,1);this.lightDirection.set(b,x,y),this.celestialLight.shadow.normalBias=ob*sr(x/uC,.1,1),this.placeShadowFrustum();const w=Math.max(a[0],a[1],a[2],1e-30);this.celestialLight.color.setRGB(a[0]/w,a[1]/w,a[2]/w),this.celestialLight.intensity=w,this.celestialLight.castShadow=this.decorGroups.size>0||this.bodySystem.any}static MEAN_COSINE=.5;static ABOVE_CLOUD_M=8e3;lightFromAbove(e,t){const i=this.lastAstronomy?.sun,n=[0,0,0];if(i){const s=Fn.litFraction(t.sunElevationDeg,t.heightM);if(s>0){const r=this.air.transmittanceFromSpace(t.heightM,t.sunElevationDeg),a=_t.illuminanceOf(i.magnitude)*this.relativeScale,l=t.heightM>=Ze.ABOVE_CLOUD_M?1:this.cloudTransmission(i);for(let c=0;c<3;c++)n[c]=Math.max(0,a*r[c]*s*l-this.sceneSunBeam[c])}}e.traverse(s=>{const r=s.material;if(!(r instanceof Oa||r instanceof Ma)||s.userData.emissive)return;r.map&&!r.emissiveMap&&(r.emissiveMap=r.map,r.needsUpdate=!0);const a=Ze.MEAN_COSINE/Math.PI;r.emissive.setRGB(r.color.r*n[0]*a,r.color.g*n[1]*a,r.color.b*n[2]*a)})}lightDirection=new D(0,1,0);placeShadowFrustum(){const e=this.lightDirection,t=this.celestialLight.shadow.camera,i=(t.right-t.left)/this.celestialLight.shadow.mapSize.x,n=this.shadowAxisX.crossVectors(this.shadowUp,e);n.lengthSq()<1e-8&&n.set(1,0,0),n.normalize();const s=this.shadowAxisY.crossVectors(e,n).normalize(),r=this.shadowWorld.set(this.bodyOrigin.x,this.cabinShadow?this.camera.position.y:0,this.bodyOrigin.z),a=c=>{const h=r.dot(c)/i;return(h-Math.round(h))*i},l=this.celestialLightTarget.position.set(0,this.cabinShadow?this.camera.position.y:0,0).addScaledVector(n,a(n)).addScaledVector(s,a(s));this.celestialLightTarget.updateMatrixWorld(),this.celestialLight.position.copy(l).addScaledVector(e,this.shadowLightDistanceM)}fitShadowToCabin(e){if(e===this.cabinShadow)return;this.cabinShadow=e;const t=this.celestialLight.shadow;if(!e){this.shadowHalfExtentM=-1;return}const i=t.camera,n=dC;i.left=-n,i.right=n,i.top=n,i.bottom=-n,this.shadowHalfExtentM=n,this.shadowLightDistanceM=Od+5,i.near=this.shadowLightDistanceM-Od,i.far=this.shadowLightDistanceM+Od,i.updateProjectionMatrix(),t.bias=-.004/(2*Od),t.mapSize.x!==2048&&(t.mapSize.set(2048,2048),t.map?.dispose(),t.map=null)}static CABIN_SKY_SHARE=.3;dimCabinSky(e){for(const t of e)t.traverse(i=>{const n=i.material;for(const s of Array.isArray(n)?n:n?[n]:[]){const r=s;r.isMeshStandardMaterial&&r.envMapIntensity!==Ze.CABIN_SKY_SHARE&&(r.envMapIntensity=Ze.CABIN_SKY_SHARE)}})}cabinShadow=!1;fitShadowToBodies(){if(this.cabinShadow)return;const e=this.bodySystem.reachFrom(this.camera.position),t=Math.min(hC,Math.max(oa,Math.ceil(e*1.25/20)*20));if(t===this.shadowHalfExtentM)return;this.shadowHalfExtentM=t;const i=this.celestialLight.shadow,n=i.camera;n.left=-t,n.right=t,n.top=t,n.bottom=-t;const s=Math.max(Nc,t*(Nc/oa));this.shadowLightDistanceM=Math.max(Wn,s+10),n.near=this.shadowLightDistanceM-s,n.far=this.shadowLightDistanceM+s,n.updateProjectionMatrix(),i.bias=-.03/(2*s);const r=t>2*oa?2048:1024;i.mapSize.x!==r&&(i.mapSize.set(r,r),i.map?.dispose(),i.map=null),this.placeShadowFrustum()}shadowHalfExtentM=oa;shadowLightDistanceM=Wn;shadowUp=new D(0,1,0);shadowAxisX=new D;shadowAxisY=new D;shadowWorld=new D;skyCloudTransmission(){let e=this.cloudTransmission({altitudeDeg:90,azimuthDeg:0}),t=1;for(const i of[20,45,70]){const n=i*Ci,s=Math.sin(n)*Math.cos(n)*2;for(let r=0;r<360;r+=60)e+=s*this.cloudTransmission({altitudeDeg:i,azimuthDeg:r}),t+=s}return e/t}cloudBeam=[0,0,0];cloudBeamDirection=new D(0,1,0);get relativeScale(){return this.scatteredSky?.relativeScale??1/Ie.semiSaturation(Ie.DAYLIGHT_ANCHOR_CD_M2)}setMeteorShower(e,t,i){this.meteorSystem||(this.meteorSystem=new tn,this.celestialGroup.add(this.meteorSystem.object)),this.meteorSystem.setShower(e,t,i)}get meteorSchedule(){return this.meteorSystem?.schedule??[]}meteorMidpoint(e){return this.meteorSystem?.midpointOf(e)}updateMeteors(e){this.meteorSystem?.update(e)}setInstrument(e){this.projectionKind=e.projection,this.grain=e.detailUm!==void 0&&e.frame?{detailUm:e.detailUm,frameHeightMm:e.frame.heightMm}:void 0;const t=Bt.starPointsOf(e),i=Bt.flareArtifactsOf(e);t===this.starPoints&&i===this.lensFlareArtifactIntensity||(this.starPoints=t,this.lensFlareArtifactIntensity=i,this.lensFlare&&(this.lensFlare.uniforms.uStarPoints.value=t,this.lensFlare.uniforms.uFlareIntensity.value=i),this.render())}magnitudeLimitOf(e){const t=ce.starLossMagnitudes(e.sun.altitudeDeg,{phaseAngleDeg:ce.phaseAngleOf(e.moon.phase.illuminatedFraction),altitudeDeg:e.moon.altitudeDeg},this.lightPollution);return Aa(e.sun.altitudeDeg,this.instrumentMagnitudeGain,t)}setLightPollution(e){e!==this.lightPollution&&(this.lightPollution=e,this.lastAstronomy&&this.scatteredSky?.update(this.scatteredSkyState(this.lastAstronomy)))}setInstrumentGain(e,t=!1,i=0){const n=Number.isFinite(e)?e:0;this.instrumentMagnitudeGain=n-2.5*i,this.filterTransmittance=10**-i,this.scatteredSky?.setInstrument(t,n,i)}filterTransmittance=1;render(){this.restatingExposure||(this.sceneVersion++,this.frameDirty=!0,this.resolution.noteChange(performance.now()),!this.suspended&&(this.syncAnimationLoop(),!(this.animationFrameId!==null||this.framesDriven||this.flushFrameId!==null)&&(this.flushFrameId=requestAnimationFrame(()=>{this.flushFrameId=null,this.drawIfDirty()}))))}drawIfDirty(){if(!(!this.frameDirty||this.contextReleased||this.suspended)){if(this.skyColoursStale&&this.lastAstronomy&&this.applySkyColours(this.lastAstronomy),this.compileBeforeNextDraw){this.compileBeforeNextDraw=!1;const e=this.compileOffThread().then(()=>{this.compiling===e&&(this.compiling=void 0,this.render())});this.compiling=e;return}if(!this.compiling){if(this.skyHoldUntilMs){if(!this.sceneSettled()&&performance.now()<this.skyHoldUntilMs){this.firstFrameReady()&&this.arrivalsPending===0&&this.refreshReflections(!0);return}this.skyHoldUntilMs=null,this.skyGlow?.setWithheld(!1),this.iceHalos?.setUrgent(!1),this.onFirstFrameHold?.(!1),this.skyColoursStale&&this.lastAstronomy&&this.applySkyColours(this.lastAstronomy)}this.frameDirty=!1,this.refreshReflections(),this.resolution.beginDrawing();try{this.renderOnce(),this.drawn++}finally{this.resolution.endDrawing()}this.developingExposure&&this.startExposure()}}}drawn=0;get framesDrawn(){return this.drawn}compileBeforeNextDraw=!1;compiling;static COMPILE_WAIT_MS=1500;compileOffThread(){const e=this.renderer.compile(this.scene,this.camera);if(!this.renderer.extensions.get("KHR_parallel_shader_compile"))return Promise.resolve();const t=this.renderer.properties,i=performance.now()+Ze.COMPILE_WAIT_MS;return new Promise(n=>{const s=()=>{if(this.contextReleased)return n();for(const r of e){const a=t.get(r)?.currentProgram;(!a||a.isReady())&&e.delete(r)}e.size===0||performance.now()>i?n():setTimeout(s,10)};s()})}compileNextFrameOffThread(){this.compileBeforeNextDraw=!0}contextReleased=!1;releaseContext(){this.contextReleased||(this.contextReleased=!0,this.stopTwinkle(),this.cancelFlush(),this.cancelExposure(),this.compiling=void 0,this.cancelScatteredSkyPump(),this.renderer.forceContextLoss())}restoreContext(){this.contextReleased&&(this.contextReleased=!1,this.renderer.forceContextRestore(),this.scatteredSky?.invalidate(),this.pumpScatteredSky(),this.compileNextFrameOffThread(),this.syncAnimationLoop(),this.render())}suspended=!1;suspend(){this.suspended||(this.suspended=!0,this.stopTwinkle(),this.cancelFlush(),this.cancelExposure(),this.cancelScatteredSkyPump(),clearTimeout(this.reflectionTimer),this.reflectionTimer=void 0)}resume(){this.suspended&&(this.suspended=!1,this.pumpScatteredSky(),this.syncAnimationLoop(),this.render())}cancelFlush(){this.flushFrameId!==null&&(cancelAnimationFrame(this.flushFrameId),this.flushFrameId=null)}frame(e){if(this.animationsRunning){const t=this.lastFrameTimeMs===void 0?0:e-this.lastFrameTimeMs;this.lastFrameTimeMs=e,this.hasAnimations()&&this.animate(e,t);const i=this.resolution.ratioFor(e,t);i!==this.renderer.getPixelRatio()&&this.applyPixelRatio(i)}this.drawIfDirty()}cabinDecor(){return this.cabinGroups}cabinGroups=[];findCabin(e,t,i){const n=[];for(const s of this.decorObjects){if(s.kind!=="aircraft"||s.observerSide!==void 0&&ka(s.kind))continue;const r=this.decorGroups.get(s.id);if(!r)continue;const a=Gs(s,e),l=a.eastM+t.x+i.x,c=-a.northM+t.z+i.z,h=Fe.sizeOf(s),d=Math.max(h.widthM,h.lengthM)/2;Math.hypot(l,c)<d&&Math.abs(a.altitudeM-this.poseElevationM-1.6)<d&&n.push(r)}return this.cabinGroups=n,n}static CABIN_MATE_RANGE_M=4;static AIRBORNE_M=100;refreshReflections(e=!1){this.reflections??=new Jn(this.renderer);const t=[...this.compassSprites,...this.lensFlare?[this.lensFlare.mesh]:[],...[...this.glareSprites.values()].map(a=>a.mesh)],i=[...this.starTiers.map(a=>a.points),...[...this.bodyMeshes.values()].filter(a=>a instanceof ls),...[this.rainSystem?.points,this.precipitationPoints,this.rainSplashSystem?.points].filter(a=>a!==void 0),...this.cabinDecor()],n=this.relativeScale,s=this.sceneVersion,r=this.reflections.refresh(this.renderer,this.scene,this.camera.position,this.bodySystem.reflectors,t,[...this.decorGroups.values()],s,i,a=>this.measureSurroundings(a,n,s),e?0:Jn.REFRESH_MS);r===void 0||this.reflectionTimer||(this.reflectionTimer=setTimeout(()=>{this.reflectionTimer=void 0,this.frameDirty=!0,!(this.animationFrameId!==null||this.framesDriven||this.flushFrameId!==null)&&(this.flushFrameId=requestAnimationFrame(()=>{this.flushFrameId=null,this.drawIfDirty()}))},r))}measureSurroundings(e,t,i){const n=this.lastAstronomy;if(!n)return;this.probeIrradiance??=new eh;const s=[n.sun,n.moon].filter(r=>r.altitudeDeg>-2).map(r=>ni(r.altitudeDeg,r.azimuthDeg,1));this.probeIrradiance.measure(this.renderer,e,s,r=>{const a=f=>f.map(p=>p/t),l=this.surroundings,c={up:a(r.up),down:a(r.down)},h=(f,p)=>f.some((g,m)=>Math.abs(g-p[m])>.03*Math.max(Math.abs(g),Math.abs(p[m]),1e-12)),d=!l||h(l.up,c.up)||h(l.down,c.down);d&&(this.surroundings=c),this.eyeSettledVersion=-1;const u=this.scatteredSky?.adaptToSurroundings(Math.exp(r.logAverage)/t)??!1;if(!d&&!u){this.eyeSettledVersion=i,this.skyHoldUntilMs&&this.redrawHeld();return}this.skyColoursStale=!0,this.render()})}lightUnderClouds(e){const t=this.surroundings;if(!t)return;const i=e.sun.altitudeDeg>=Fc?e.sun:e.moon.altitudeDeg>=Fc?e.moon:void 0;if(!i)return;const n=this.relativeScale/Math.PI;return{through:this.cloudTransmission(i),radiance:[t.up[0]*n,t.up[1]*n,t.up[2]*n]}}probeIrradiance;surroundings;animate(e,t){const i=Math.min(t/1e3,ZC);this.twinkleSeconds=e/1e3,this.updateTwinkle(this.twinkleSeconds),this.updatePrecipitation(e/1e3,i),this.updateRain(i),this.lensFlare&&(this.lensFlare.uniforms.uTime.value=e/1e3),this.developingExposure||(this.frameDirty=!0)}setMaxPixelRatio(e){this.resolution.maximum=e,this.renderer.getPixelRatio()>this.resolution.maximum&&this.applyPixelRatio(this.resolution.maximum)}applyPixelRatio(e){this.renderer.setPixelRatio(e),this.renderer.setSize(this.cssSize.width,this.cssSize.height,!1),this.frameDirty=!0}setExposure(e,t){const i=t?Math.max(1,Math.round(e)):1;if(i===this.exposureInstants&&(i===1||t===this.exposureInstantAt)){this.exposureInstantAt=t;return}this.exposureInstants=i,this.exposureInstantAt=t,i===1&&(this.cancelExposure(),this.exposureAccumulation?.dispose(),this.exposureAccumulation=void 0),this.render()}renderOnce(e){if(this.aimBeams(),this.onMapSubjectBounds){const r=this.mapSubjectBounds();e?this.exposureSubjectBounds.push(...r):this.onMapSubjectBounds(r)}const t=this.usableEquidistantPass();this.phenomena.setCloudLayers(this.layeredClouds?.volumes??[]),this.phenomena.place(this.camera,(r,a,l)=>this.directionAtScreenPoint(r,a,l),r=>this.screenPointOf(r)),this.references.place(this.camera);const i=Math.max(this.phenomena.furthestM,this.references.furthestM)*1.2;i>this.camera.far&&(this.camera.far=i,this.camera.updateProjectionMatrix()),Ln.uRodShare.value=this.scatteredSky?.rodShare??0,Ln.uRelativeScale.value=this.relativeScale,this.applyMedium();const n=this.references.any||this.phenomena.any||this.compassSprites.some(r=>r.visible);Ln.uHasOverlay.value=n?1:0;const s=n?r=>this.renderOverlayPasses(r):void 0;if(this.skyGlow?.setDestinationEncoded(!1),!t){this.updateLensFlarePosition();const r=this.usableDepthOfFieldPass();r?r.render(this.renderer,this.scene,this.camera,s,e):this.usableFinishPass().render(this.renderer,this.scene,this.camera,s,void 0,e);return}t.render(this.renderer,this.scene,this.camera,this.camera.fov,()=>this.updateLensFlarePosition(),s,r=>{this.lensFlare&&(this.lensFlare.mesh.visible=r?!1:this.sunVisible)},()=>this.renderDazzleOnResample(),e,this.pointLayerHost)}pointLayerHost={points:()=>{const e=[];return this.celestialGroup.traverse(t=>{(t instanceof ls&&t.userData.pointSource||t instanceof Se&&t.userData.skyRibbon)&&e.push(t)}),e},clouds:()=>[...this.layeredClouds?.meshes??[],...this.cloudMesh?[this.cloudMesh]:[],...this.cirrusMesh?[this.cirrusMesh]:[]],sky:this.celestialGroup};renderOverlayPasses(e=this.camera){this.renderReferencesPass(e),this.renderBodiesOverReferences(e),this.renderPhenomenaPass(e),this.renderHudPass(e)}renderHudPass(e){const t=this.traceSystem?.any&&this.tracesShown;if(!t&&!this.compassSprites.some(s=>s.visible))return;t&&this.traceSystem.setView(this.renderer.getDrawingBufferSize(this.traceResolution),e.fov);const i=this.renderer.autoClear,n=this.renderer.shadowMap.autoUpdate;this.renderer.autoClear=!1,this.renderer.shadowMap.autoUpdate=!1,e.layers.set(Gp),this.renderer.render(this.scene,e),e.layers.set(0),this.renderer.autoClear=i,this.renderer.shadowMap.autoUpdate=n}renderBodiesOverReferences(e){if(!this.references.any||!this.bodySystem.any)return;const t=this.renderer.autoClear,i=this.renderer.shadowMap.autoUpdate;this.renderer.autoClear=!1,this.renderer.shadowMap.autoUpdate=!1,e.layers.set(y2),this.scene.overrideMaterial=this.bodyCutOutMaterial,this.renderer.render(this.scene,e),this.scene.overrideMaterial=null,e.layers.set(0),this.renderer.autoClear=t,this.renderer.shadowMap.autoUpdate=i}bodyCutOutMaterial=new Hn({blending:Rh,blendSrc:Xc,blendDst:Xc,blendSrcAlpha:Xc,blendDstAlpha:Xc,toneMapped:!1});renderReferencesPass(e){if(!this.references.any)return;const t=this.renderer.autoClear,i=this.renderer.shadowMap.autoUpdate;this.renderer.autoClear=!1,this.renderer.shadowMap.autoUpdate=!1,e.layers.set(M2),this.renderer.render(this.scene,e),e.layers.set(0),this.renderer.autoClear=t,this.renderer.shadowMap.autoUpdate=i}setReferences(e,t){this.references.set(e.map(i=>{const n=this.documentRelative(i.src);return n===i.src?i:{...i,src:n}}),void 0,t)}referenceAspect(e){return this.references.aspectOf(e)}directionAt(e,t){return this.directionAtScreenPoint(e,t,new D)}referenceFailedToLoad(e){return this.references.failedToLoad(this.documentRelative(e))}setReferencesShown(e){this.references.setShown(e),this.render()}setReferenceView(e,t){this.references.setView(e,t),this.render()}renderPhenomenaPass(e){if(!this.phenomena.any)return;const t=this.renderer.autoClear,i=this.renderer.shadowMap.autoUpdate;this.renderer.autoClear=!1,this.renderer.shadowMap.autoUpdate=!1,this.renderer.clearDepth();for(const n of this.decorObjects){const s=this.decorGroups.get(n.id);s&&Ze.markDecorDepth(s,n.kind!=="crop")}e.layers.set(Hp),this.scene.overrideMaterial=this.decorDepthMaterial,this.renderer.render(this.scene,e),this.scene.overrideMaterial=null,e.layers.set(b2),this.renderer.render(this.scene,e),e.layers.set(0),this.renderer.autoClear=t,this.renderer.shadowMap.autoUpdate=i}decorDepthMaterial=new Hn({colorWrite:!1});static isSolidSurface(e){if(!(e instanceof Se))return!0;const t=Array.isArray(e.material)?e.material[0]:e.material;return t.depthWrite!==!1&&t.blending!==Wi}static markDecorDepth(e,t){e.traverse(i=>{if(!(i instanceof Se))return;t&&Ze.isSolidSurface(i)?i.layers.enable(Hp):i.layers.disable(Hp)})}startExposure(){this.cancelExposure(),this.exposureSubjectBounds=[];const e=this.renderer.getDrawingBufferSize(new we),t=Math.max(1,Math.round(e.x)),i=Math.max(1,Math.round(e.y));this.exposureAccumulation||(this.exposureAccumulation=new ID(t,i)),this.exposureAccumulation.resize(t,i),this.exposureAccumulation.open(this.renderer),this.exposureInstantsDone=0,this.exposureFrameId=requestAnimationFrame(()=>this.developExposure())}developExposure(){this.exposureFrameId=null;const e=this.exposureInstantAt,t=this.exposureAccumulation;if(!e||!t)return;const i=1/this.exposureInstants;this.resolution.beginDrawing();const n=performance.now()+Ze.EXPOSURE_BUDGET_MS,s=Ze.exposureInstantsPerFrame(t.instantTarget.scene.width*t.instantTarget.scene.height);let r=0;do{this.restateAt(e,this.exposureInstantsDone);const a=this.compassSprites.map(l=>l.visible);for(const l of this.compassSprites)l.visible=!1;try{this.renderOnce(t.instantTarget)}finally{this.compassSprites.forEach((l,c)=>{l.visible=a[c]})}t.add(this.renderer,i),this.exposureInstantsDone++,r++}while(this.exposureInstantsDone<this.exposureInstants&&performance.now()<n&&r<s);this.restateAt(e,0),this.presentExposure(),this.resolution.endDrawing(),this.exposureInstantsDone<this.exposureInstants&&(this.exposureFrameId=requestAnimationFrame(()=>this.developExposure()))}presentExposure(){if(Ln.uRodShare.value=this.scatteredSky?.rodShare??0,Ln.uHasOverlay.value=1,Ln.uRelativeScale.value=this.relativeScale,this.applyMedium(),this.exposureAccumulation?.develop(this.renderer,this.exposureInstants/this.exposureInstantsDone),this.onMapSubjectBounds?.(this.exposureSubjectBounds),!this.compassSprites.some(s=>s.visible))return;const e=new xr,t=new $s(-1,1,1,-1,0,2),i=Fd/(fb*Math.tan(pb*Ci/2));for(const s of this.compassSprites){if(!s.visible)continue;const r=s.getWorldPosition(new D).sub(this.camera.position).normalize(),a=this.screenPointOf(r);if(!a)continue;const l=new Ec(s.material);l.position.set(a.ndcX,a.ndcY,-1),l.scale.set(i/this.camera.aspect,i,1),e.add(l)}const n=this.renderer.autoClear;this.renderer.autoClear=!1;try{this.renderer.render(e,t)}finally{this.renderer.autoClear=n}}onMapSubjectBounds;exposureSubjectBounds=[];static MAP_SUBJECT_NEAREST_M=8;mapSubjectBounds(){const e=[],t=new on,i=new D,n=this.camera.getWorldDirection(new D),s=this.decorObjects.filter(a=>a.track?.length||a.kind==="aircraft"||a.kind==="vehicle").map(a=>this.decorGroups.get(a.id)),r=this.bodySystem.reflectors.map(a=>a.holder);for(const a of[...s,...r]){if(!a?.visible||(t.setFromObject(a),t.isEmpty())||t.distanceToPoint(this.camera.position)<Ze.MAP_SUBJECT_NEAREST_M)continue;let l=1/0,c=-1/0,h=1/0,d=-1/0;for(const u of[t.min.x,t.max.x])for(const f of[t.min.y,t.max.y])for(const p of[t.min.z,t.max.z]){if(i.set(u,f,p).sub(this.camera.position).normalize(),i.dot(n)<=0)continue;const g=this.screenPointOf(i);if(!g)continue;const m=(g.ndcX+1)/2,v=(1-g.ndcY)/2;l=Math.min(l,m),c=Math.max(c,m),h=Math.min(h,v),d=Math.max(d,v)}l=Math.max(l,0),c=Math.min(c,1),h=Math.max(h,0),d=Math.min(d,1),c>=l&&d>=h&&e.push({x:l,y:h,width:c-l,height:d-h})}return e}restateAt(e,t){this.restatingExposure=!0;try{e(t)}finally{this.restatingExposure=!1}}cancelExposure(){this.exposureFrameId!==null&&(cancelAnimationFrame(this.exposureFrameId),this.exposureFrameId=null)}setLensOptics(e){const t=this.lensOptics;this.lensOptics=e,(t===void 0!=(e===void 0)||t&&e&&(t.focalLengthMm!==e.focalLengthMm||t.fNumber!==e.fNumber||t.focusDistance!==e.focusDistance||t.frameHeightMm!==e.frameHeightMm))&&(e&&this.depthOfFieldPass&&this.depthOfFieldPass.setLens(e.focalLengthMm,e.fNumber,e.focusDistance,e.frameHeightMm),this.render())}usableDepthOfFieldPass(){const e=this.lensOptics;if(!e)return;const t=this.renderer.getDrawingBufferSize(new we),i=Math.max(1,Math.round(t.x)),n=Math.max(1,Math.round(t.y));return this.depthOfFieldPass||(this.depthOfFieldPass=new ih(i,n)),this.depthOfFieldPass.resize(i,n),this.depthOfFieldPass.setLens(e.focalLengthMm,e.fNumber,e.focusDistance,e.frameHeightMm),this.depthOfFieldPass}usableFinishPass(){const e=this.renderer.getDrawingBufferSize(new we);return this.finishPass?this.finishPass.resize(e.x,e.y):this.finishPass=new Xg(e.x,e.y),this.finishPass}usableEquidistantPass(){if(this.projectionKind!=="equidistant")return;const e=this.renderer.getDrawingBufferSize(new we);return this.equidistantPass?this.equidistantPass.resize(e.x,e.y):this.equidistantPass=new di(e.x,e.y),this.equidistantPass}aimAtScreenPoint(e,t,i){const n=this.projectionKind==="equidistant"?this.equidistantPass:void 0;if(!n){e.setFromCamera(new we(t,i),this.camera);return}const s=n.directionFor(t,i,this.camera.fov);this.camera.updateMatrixWorld(),e.ray.origin.setFromMatrixPosition(this.camera.matrixWorld),e.ray.direction.set(s.x,s.y,s.z).applyQuaternion(this.camera.quaternion).normalize(),e.camera=this.camera}pickCloudAt(e,t){return this.layeredClouds?.pickInstance(this.cloudDirectionAt(e,t))}cloudDirectionAt(e,t){return this.directionAtScreenPoint(e,t,new D)}directionAtScreenPoint(e,t,i){return this.aimAtScreenPoint(this.ufoOcclusionRaycaster,e,t),i.copy(this.ufoOcclusionRaycaster.ray.direction)}screenPointOf(e){this.camera.updateMatrixWorld();const t=this.screenPointScratch.copy(e).applyQuaternion(this.screenPointQuaternion.copy(this.camera.quaternion).invert()),i=this.renderer.getDrawingBufferSize(this.screenPointSize),n=i.x/Math.max(i.y,1);if(this.projectionKind==="equidistant"&&this.equidistantPass)return di.ndcFor(t,this.camera.fov,n);if(t.z>=0)return;const s=Math.tan(this.camera.fov/2*Ci);return{ndcX:t.x/-t.z/(n*s),ndcY:t.y/-t.z/s}}screenPointScratch=new D;screenPointQuaternion=new An;screenPointSize=new we;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}const t=this.sunVisibleFraction();if(t<=0){e.mesh.visible=!1;return}e.mesh.visible=!0,this.sunUnhiddenFraction=t,this.applyDazzleStrength();const i=this.lensFlareScratch.copy(this.sunWorldPosition).project(this.camera);e.uniforms.uLensPosition.value.set(i.x,i.y);const n=this.renderer.domElement.width,s=this.renderer.domElement.height;e.uniforms.uResolution.value.set(n,s),e.uniforms.uTanHalfFov.value=Math.tan(this.camera.fov*Math.PI/360)}renderDazzleOnResample(){const e=this.lensFlare;if(!e||!this.sunVisible)return;const t=this.sunVisibleFraction();if(t<=0)return;this.sunUnhiddenFraction=t,this.applyDazzleStrength();const i=this.screenPointOf(this.lensFlareScratch.copy(this.sunWorldPosition).sub(this.camera.position).normalize());if(!i)return;const n=this.renderer.getDrawingBufferSize(this.screenPointSize);e.uniforms.uLensPosition.value.set(i.ndcX,i.ndcY),e.uniforms.uResolution.value.set(n.x,n.y),e.uniforms.uEquidistant.value=1,e.uniforms.uHalfFovRad.value=this.camera.fov*Math.PI/360;const s=this.renderer.autoClear;this.renderer.autoClear=!1,e.mesh.visible=!0,e.mesh.layers.enable(sb),this.camera.layers.set(sb),this.renderer.render(this.scene,this.camera),this.camera.layers.set(0),e.mesh.visible=!1,e.uniforms.uEquidistant.value=0,this.renderer.autoClear=s}sunVisibleFraction(){this.raycastableDecor().length>0&&this.scene.updateMatrixWorld();let e=0;for(const t of gb)this.isSunOccluded(t[0],t[1])||e++;return e/gb.length}raycastableDecor(){const e=[];for(const t of this.decorObjects){if(t.kind==="crop")continue;const i=this.decorGroups.get(t.id);i&&e.push(i)}return e}isSunOccluded(e=0,t=0){const i=this.raycastableDecor();if(!this.groundMesh&&!this.terrainMesh&&i.length===0)return!1;const n=this.sunOcclusionDirectionScratch.copy(this.sunWorldPosition).sub(this.camera.position),s=n.length();if(n.normalize(),e!==0||t!==0){const a=Math.PI/180,l=this.sunOcclusionRightScratch.set(n.z,0,-n.x);l.lengthSq()<1e-9&&l.set(1,0,0),l.normalize();const c=this.sunOcclusionUpScratch.crossVectors(l,n).normalize();n.addScaledVector(l,e*a).addScaledVector(c,t*a).normalize()}if(this.groundBlocks(this.camera.position,n,s))return!0;if(i.length===0)return!1;this.sunOcclusionRaycaster.set(this.camera.position,n);const r=this.sunOcclusionRaycaster.intersectObjects(i,!0)[0];return r!==void 0&&r.distance<s}groundBlocks(e,t,i,n=0){const s=this.groundMesh;if(s&&t.y<0){const m=(s.position.y-e.y)/t.y;if(m>n&&m<i){const v=e.x+t.x*m-s.position.x,b=e.z+t.z*m-s.position.z;if(Math.hypot(v,b)<=this.groundRadius)return!0}}const r=this.terrainMesh;if(!r)return!1;const a=r.geometry.getAttribute("position"),l=Math.round(Math.sqrt(a.count));if(l<2||l*l!==a.count)return!1;const c=[r.position.x+a.getX(0),r.position.x+a.getX(l-1)],h=[r.position.z+a.getZ(0),r.position.z+a.getZ((l-1)*l)],d=Math.min(Math.abs(c[1]-c[0]),Math.abs(h[1]-h[0]))/(l-1);if(!(d>0))return!1;let u=n,f=i;for(const[m,v,b]of[[e.x,t.x,c],[e.z,t.z,h]]){const x=Math.min(b[0],b[1]),y=Math.max(b[0],b[1]);if(Math.abs(v)<1e-12){if(m<x||m>y)return!1;continue}const w=(x-m)/v,S=(y-m)/v;u=Math.max(u,Math.min(w,S)),f=Math.min(f,Math.max(w,S))}if(!(f>u))return!1;const p=Math.hypot(t.x,t.z),g=Math.min(4096,Math.max(8,Math.ceil((f-u)*p/(d/2))));for(let m=0;m<=g;m++){const v=u+(f-u)*m/g,b=e.x+t.x*v,x=e.y+t.y*v,y=e.z+t.z*v;if(x<=this.groundYUnder(b,y))return!0}return!1}setPhenomena(e,t){this.phenomena.set(e,t)}decorDistancesAt(e,t,i){this.aimAtScreenPoint(this.ufoOcclusionRaycaster,e,t),this.ufoOcclusionRaycaster.near=rb;let n,s;for(const r of this.decorObjects){if(r.kind==="crop")continue;const a=this.decorGroups.get(r.id);if(!a)continue;const l=this.ufoOcclusionRaycaster.intersectObject(a,!0).find(c=>Ze.isSolidSurface(c.object));l&&(r.occludesSourceIds?.includes(i)?n=n===void 0?l.distance:Math.max(n,l.distance):s=s===void 0?l.distance:Math.min(s,l.distance))}return{behindM:n,inFrontM:s}}pickBodyAt(e,t){this.aimAtScreenPoint(this.raycaster,e,t);const i=this.raycaster.ray.origin,n=this.raycaster.ray.direction,s=fC*this.camera.fov*Math.PI/180,r=[...this.hitAreas.entries()].map(([h,d])=>{const u=d.getWorldPosition(new D).sub(i);return{key:h,direction:u.clone().normalize(),radiusRad:Math.atan2(d.scale.x/2,u.length())}}),a=this.eclipseDiscs,l=a?[{key:"sun",direction:a.sun,radiusRad:a.sunRadiusRad},{key:"moon",direction:a.moon,radiusRad:a.moonRadiusRad,inFront:!0}]:[],c=Ze.nearestBody(n,[...r.filter(h=>!a||h.key!=="sun"&&h.key!=="moon"),...l],s);if(c)return this.groundHides(e,t)?void 0:c}static nearestBody(e,t,i){let n,s=1/0,r=1/0,a=!1;for(const l of t){const c=Math.acos(sr(l.direction.dot(e),-1,1))-l.radiusRad;if(c>i)continue;const h=c<=0,d=s<=0,u=l.inFront===!0;(h!==d?h:h?u!==a?u:l.radiusRad<r:c<s)&&(n=l.key,s=c,r=l.radiusRad,a=u)}return n}pickInterpretationBodyAt(e,t){const i=this.bodySystem.group.children.filter(f=>f.visible&&f.name.startsWith("body:"));if(i.length===0)return;this.aimAtScreenPoint(this.raycaster,e,t);const n=this.raycaster.ray.direction,s=this.raycaster.ray.origin,r=cC*this.camera.fov*Math.PI/180,a=[...this.decorGroups.values()],l=a.length>0?Ze.firstSolid(this.raycaster.intersectObjects(a,!0))?.distance:void 0;let c,h=1/0;const d=new on,u=new D;for(const f of i){if(d.setFromObject(f),d.isEmpty())continue;d.getCenter(u);const p=d.getSize(new D).length()/2,g=u.clone().sub(s),m=g.length();if(m===0||g.dot(n)<=0||l!==void 0&&l<m-p)continue;const v=Math.acos(Math.min(1,g.normalize().dot(n))),b=Math.atan(p/m);if(b>r){const x=this.raycaster.intersectObject(f,!0)[0];if(!x||l!==void 0&&l<x.distance)continue}else if(v>r)continue;b<h&&(h=b,c=f.name.slice(5))}return c}pickStarAt(e,t){if(this.namedStars.length===0)return;this.aimAtScreenPoint(this.raycaster,e,t);const i=this.raycaster.ray.direction,n=Math.cos(Xp*this.camera.fov*Math.PI/180);let s,r=n;for(const a of this.namedStars){const l=a.direction.dot(i);l>r&&(r=l,s={star:a.star,altitudeDeg:a.altitudeDeg})}return s&&this.groundHides(e,t)?void 0:s}groundHides(e,t){if(!this.terrainMesh&&!this.groundMesh)return!1;this.aimAtScreenPoint(this.ufoOcclusionRaycaster,e,t);const i=this.ufoOcclusionRaycaster.ray;return this.groundBlocks(i.origin,i.direction,1/0,rb)}bodyScreenBox(e){const t=this.bodySystem.boxOf(e,this.bodyBoxScratch);if(!t)return;let i=1/0,n=1/0,s=-1/0,r=-1/0;for(let a=0;a<8;a++){const l=this.bodyCornerScratch.set(a&1?t.max.x:t.min.x,a&2?t.max.y:t.min.y,a&4?t.max.z:t.min.z),c=this.screenPointOf(l.sub(this.camera.position).normalize());if(!c)return;i=Math.min(i,c.ndcX),s=Math.max(s,c.ndcX),n=Math.min(n,c.ndcY),r=Math.max(r,c.ndcY)}return{minX:i,minY:n,maxX:s,maxY:r}}bodyBoxScratch=new on;bodyCornerScratch=new D;pickPlacedBodyAt(e,t){return this.aimAtScreenPoint(this.raycaster,e,t),this.bodySystem.pick(this.raycaster)}decorScreenBox(e){const t=this.decorGroups.get(e);if(!t||!t.visible)return;const i=this.bodyBoxScratch.setFromObject(t);if(i.isEmpty())return;let n=1/0,s=1/0,r=-1/0,a=-1/0;for(let l=0;l<8;l++){const c=this.bodyCornerScratch.set(l&1?i.max.x:i.min.x,l&2?i.max.y:i.min.y,l&4?i.max.z:i.min.z),h=this.screenPointOf(c.sub(this.camera.position).normalize());if(!h)return;n=Math.min(n,h.ndcX),r=Math.max(r,h.ndcX),s=Math.min(s,h.ndcY),a=Math.max(a,h.ndcY)}return{minX:n,minY:s,maxX:r,maxY:a}}decorGroundPointAt(e,t,i,n=0){const s=this.decorGroups.get(e);if(!s)return;this.aimAtScreenPoint(this.raycaster,t,i);const r=this.raycaster.ray.intersectPlane(this.decorPlaneScratch.setComponents(0,1,0,-(s.position.y+n)),this.decorHitScratch);return r?{x:r.x,z:r.z}:void 0}decorDistanceM(e){const t=this.decorGroups.get(e);return t?Math.hypot(t.position.x-this.camera.position.x,t.position.z-this.camera.position.z):void 0}decorMetresPerNdcY(e){const t=this.decorGroups.get(e);return t?t.position.distanceTo(this.camera.position)*Math.tan(this.camera.fov*Ci/2):0}decorGrabHeightAt(e,t,i){const n=this.decorGroups.get(e);if(!n)return 0;const s=this.bodyBoxScratch.setFromObject(n).max.y-n.position.y;this.aimAtScreenPoint(this.raycaster,t,i);const r=this.decorHitScratch.set(this.camera.position.x-n.position.x,0,this.camera.position.z-n.position.z);if(r.lengthSq()<1e-6)return 0;r.normalize();const a=this.decorPlaneScratch.setFromNormalAndCoplanarPoint(r,n.position),l=this.raycaster.ray.intersectPlane(a,this.decorHitScratch);return l?Math.min(Math.max(l.y-n.position.y,0),Math.max(s,0)):0}decorPlaneScratch=new ma;decorHitScratch=new D;static firstSolid(e){return e.find(t=>{const i=t.object.material;return!(Array.isArray(i)?i:[i]).some(s=>s&&s.transparent&&s.opacity<Ze.SEE_THROUGH_BELOW)})}static SEE_THROUGH_BELOW=.9;pickDecorAt(e,t){this.aimAtScreenPoint(this.raycaster,e,t);const i=[...this.decorGroups.entries()],n=Ze.firstSolid(this.raycaster.intersectObjects(i.map(([,a])=>a),!0));if(!n)return;const s=this.bodySystem.pickHit(this.raycaster);if(s!==void 0&&s.distance<n.distance)return;let r=n.object;for(;r&&!i.some(([,a])=>a===r);)r=r.parent;return i.find(([,a])=>a===r)?.[0]}dispose(){this.stopTerrainFade(),this.stopTwinkle(),this.cancelFlush(),this.phenomena.clear(),this.references.disposeAll(),this.terrainBuildToken++,this.cancelScatteredSkyPump(),this.skyMesh&&this.skyGradientMaterial&&(this.skyMesh.material=this.skyGradientMaterial),this.scatteredSky?.dispose(),this.scatteredSky=void 0,this.disposeMesh(this.skyMesh),this.disposeMesh(this.groundMesh),this.disposeMesh(this.terrainMesh),this.roadSystem.dispose(),this.traceSystem?.dispose(),this.contrailSystem?.dispose(),this.contrailSystem=void 0,this.disposeCloudSystem(),this.disposeCirrus(),this.disposePrecipitationPoints(),this.disposeRain(),this.disposeStarTiers(),this.meteorSystem?.dispose(),this.meteorSystem=void 0,this.iceHalos?.dispose(),this.iceHalos=void 0,this.rainbow?.dispose(),this.rainbow=void 0,this.skyGlow?.dispose(),this.skyGlow=void 0,this.depthOfFieldPass?.dispose(),this.finishPass?.dispose(),this.depthOfFieldPass=void 0,this.cancelExposure(),this.exposureAccumulation?.dispose(),this.exposureAccumulation=void 0,this.cometTail?.dispose(),this.cometTail=void 0,this.satelliteField?.dispose(),this.satelliteField=void 0,this.reentrySystem?.dispose(),this.reentrySystem=void 0,this.plumeSystem?.dispose(),this.plumeSystem=void 0,this.lightningBolt?.dispose(),this.lightningBolt=void 0;for(const e of this.bodyMeshes.values())this.disposeMesh(e);this.bodyMeshes.clear(),this.novaKeys.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())Fe.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;this.cancelFlush();const e=t=>{this.animationFrameId=null,this.frame(t),this.animationFrameId===null&&this.needsAnimationLoop()&&(this.animationFrameId=requestAnimationFrame(e))};this.animationFrameId=requestAnimationFrame(e)}setAnimationsRunning(e,t=!1){const i=e&&t;if(e===this.animationsRunning&&i===this.framesDriven)return;const n=this.animationsRunning;this.animationsRunning=e,this.framesDriven=i,e&&!n&&(this.lastFrameTimeMs=void 0,this.resolution.reset());const s=!e&&this.renderer.getPixelRatio()!==this.resolution.maximum;s&&this.applyPixelRatio(this.resolution.maximum),this.syncAnimationLoop(),(!e||this.frameDirty)&&this.render(),s&&this.drawIfDirty()}stopTwinkle(){this.animationFrameId!==null&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null)}needsAnimationLoop(){return this.animationsRunning&&!this.framesDriven&&!this.suspended&&this.hasAnimations()}hasAnimations(){return this.starTiers.some(e=>e.brightness.length>0)||this.precipitationPoints!==void 0||this.rainSystem!==void 0||this.flareMayShow()}flareAimScratch=new D;flareMayShow(){if(this.lensFlare===void 0||!this.sunVisible)return!1;const e=this.lastAstronomy?.sun;return e!==void 0&&e.altitudeDeg<Ze.FLARE_ANIMATION_MIN_ALTITUDE_DEG?!1:(this.camera.getWorldDirection(this.flareAimScratch),this.flareAimScratch.dot(this.lensFlareScratch.copy(this.sunWorldPosition).sub(this.camera.position))>0)}static FLARE_ANIMATION_MIN_ALTITUDE_DEG=-3;syncAnimationLoop(){this.needsAnimationLoop()?this.startTwinkle():this.stopTwinkle()}buildSky(e){const t=this.skyMesh?.geometry??new Ii(Ld,32,16),i=t.attributes.position,n=t.getAttribute("color")??new yt(new Float32Array(i.count*3),3);for(let r=0;r<i.count;r++){const{altitudeDeg:a,azimuthDeg:l}=CD(i.getX(r),i.getY(r),i.getZ(r)),c=BD(a,l,e.azimuthDeg,e.altitudeDeg);n.setXYZ(r,c[0],c[1],c[2])}if(n.needsUpdate=!0,this.skyMesh)return;t.setAttribute("color",n);const s=new Hn({vertexColors:!0,side:fi,fog:!1,depthWrite:!1});this.skyGradientMaterial=s,this.skyMesh=new Se(t,s),this.skyMesh.renderOrder=-1,this.celestialGroup.add(this.skyMesh)}buildGround(){const e=ab(this.observerElevationM);if(this.groundMesh&&e===this.groundRadius)return;this.disposeMesh(this.groundMesh),this.groundRadius=e;const t=new Sg(this.groundRadius,48),i=new Oa({color:new ne(Vp,Vp,Vp),fog:!0});ko.fadeRim(i,this.groundRadius*.75,this.groundRadius),this.groundMesh=new Se(t,i),this.groundMesh.rotation.x=-Math.PI/2,this.groundMesh.position.y=0,this.groundMesh.receiveShadow=!0,this.scene.add(this.groundMesh),this.applyGroundDepthWrite()}applyGroundDepthWrite(){const e=this.groundMesh?.material;if(!e)return;const t=this.terrainMesh===void 0;e.depthWrite!==t&&(e.depthWrite=t,e.needsUpdate=!0);const i=this.terrainMesh;let n=0;if(i){const s=i.geometry.getAttribute("position");n=1/0;for(let r=0;r<s.count;r++)Math.abs(s.getX(r)+i.position.x)>600||Math.abs(s.getZ(r)+i.position.z)>600||(n=Math.min(n,s.getY(r)+i.position.y));n=Number.isFinite(n)?Math.min(0,n)-1:0}this.groundMesh.position.y=n,this.groundMesh.renderOrder=0,e.depthTest=!0,e.needsUpdate=!0}cloudTransmission(e,t=!1){const i=`${e.altitudeDeg.toFixed(1)}:${e.azimuthDeg.toFixed(1)}:${Math.round(this.cloudOffsetM.x/10)}:${Math.round(this.cloudOffsetM.z/10)}:${Math.round(this.observerElevationM)}:`+Object.entries(this.cloudLayerOffsetsM).map(([r,a])=>`${r}=${Math.round(a.x/10)},${Math.round(a.z/10)}`).join(";")+(t?":water":""),n=this.cloudTransmissionMemo.get(i);if(n!==void 0)return n;this.cloudTransmissionMemo.size>256&&this.cloudTransmissionMemo.clear();const s=this.computeCloudTransmission(e,t);return this.cloudTransmissionMemo.set(i,s),s}cloudTransmissionMemo=new Map;computeCloudTransmission(e,t=!1){const i=ni(e.altitudeDeg,e.azimuthDeg,1);if(this.layeredClouds)return this.layeredClouds.transmissionAt(i,t);let n=1;const s=this.lowerCloudCover();s>0&&(n*=1-Nt.alphaAt(i,Math.abs(this.cloudLayerOffset()),s,this.cloudFieldOffset)*gC);const r=t?0:this.weather.highCloudCover??0;return r>0&&(n*=1-Nt.iceAlphaAt(i,Nd,r,this.cloudFieldOffset)*vC),Math.max(0,Math.min(1,n))}setBodyMesh(e,t,i,n,s){if(t.altitudeDeg<au){this.disposeMesh(this.bodyMeshes.get(e)),this.bodyMeshes.delete(e),this.disposeHitArea(e),this.disposeGlare(e),e==="sun"&&(this.sunVisible=!1);return}const{x:r,y:a,z:l}=ni(t.altitudeDeg,t.azimuthDeg,Wn),c=Ey(t.altitudeDeg),h=this.cloudTransmission(t),d=this.arrivingIlluminance(t,s,h),u=Ze.unitLuminance(n);let f=this.bodyMeshes.get(e);if(e==="sun"){const p=Math.PI*(i/Wn)**2,g=[0,1,2].map(v=>u[v]*d[v]/(this.sunBeamFraction*p));this.sunDiscRadiance=g;const m=g.map(v=>Math.min(Ze.BRIGHTEST_RELATIVE,v));f instanceof Se||(this.disposeMesh(f),f=new Se(new Ii(1,16,16),this.eclipsedSun.material()),this.celestialGroup.add(f),this.bodyMeshes.set(e,f)),f.material.color.setRGB(m[0],m[1],m[2]),f.scale.setScalar(i)}else{if(!(f instanceof ls)){this.disposeMesh(f);const m=new ot;m.setAttribute("position",new st(new Float32Array(3),3)),m.setAttribute("color",new st(new Float32Array(3),3)),f=new ls(m,Ce.material($l[$l.length-1].size,!1)),Ce.track(f),this.celestialGroup.add(f),this.bodyMeshes.set(e,f)}const p=f.geometry.getAttribute("color"),g=e.startsWith("comet:")?this.pointToPixel():1;p.setXYZ(0,u[0]*d[0]*g,u[1]*d[1]*g,u[2]*d[2]*g),p.needsUpdate=!0}if(f.position.set(r,a,l),this.setHitArea(e,r,a,l,i),e==="sun"&&(this.sunArriving=d),e.startsWith("comet:")?this.disposeGlare(e):e!=="sun"&&this.setGlare(e,r,a,l,d,i/Wn*(180/Math.PI),Ze.POINT_VEIL_HOLD_DEG),e==="sun"){this.sunVisible=!0;const p=this.celestialGroup.scale.x;this.sunWorldPosition.set(r*p,a*p+this.celestialGroup.position.y,l*p),this.lensFlare||(this.lensFlare=T4(),this.lensFlare.uniforms.uOpacity.value=LC,this.lensFlare.uniforms.uFlareIntensity.value=this.lensFlareArtifactIntensity,this.lensFlare.uniforms.uStarPoints.value=this.starPoints,this.scene.add(this.lensFlare.mesh)),this.applyLensFlareTint(c)}}setMoonMesh(e,t){const i="moon";if(e.magnitude>t||e.altitudeDeg<au){this.disposeMesh(this.bodyMeshes.get(i)),this.bodyMeshes.delete(i),this.disposeHitArea(i),this.disposeGlare(i);return}const{x:n,y:s,z:r}=ni(e.altitudeDeg,e.azimuthDeg,Wn),a=this.cloudTransmission(e),l=this.arrivingIlluminance(e,e.magnitude,a),c=e.radiusDeg??Sn.MEAN_RADIUS_DEG,h=Wn*Math.tan(c*Ci),d=Math.max(sr(e.phase.illuminatedFraction,0,1),.01)*Math.PI*(h/Wn)**2,u=new ne(...l.map(g=>Math.min(Ze.BRIGHTEST_RELATIVE,g/d))),f=`${e.phase.phaseFraction<.5}:${Math.round(sr(e.phase.illuminatedFraction,0,1)*500)}`;let p=this.bodyMeshes.get(i);p instanceof Ec?(p.userData.phaseKey!==f&&(p.material.map?.dispose(),p.material.map=Pb(e.phase),p.userData.phaseKey=f),p.material.color.copy(u)):(this.disposeMesh(p),p=new Ec(new eu({map:Pb(e.phase),color:u,fog:!1,blending:Wi,depthWrite:!1})),p.userData.phaseKey=f,this.celestialGroup.add(p),this.bodyMeshes.set(i,p)),p.scale.set(h*2,h*2,1),p.position.set(n,s,r),this.setHitArea(i,n,s,r,h),this.setGlare(i,n,s,r,l,c)}bentLight(e,t,i=pC){const[n,s,r]=this.arrivingIlluminance(e,t,1),a=Math.max(s,1e-30);return{scale:s/i,tint:[n/a,1,r/a]}}static litBySky(e,t){return Ze.litScratch.setRGB(e.r*t[0],e.g*t[1],e.b*t[2])}static litScratch=new ne;pointToPixel(){const e=Math.max(1,this.renderer.getDrawingBufferSize(this.pointScratch).y),t=(this.camera.fov*Math.PI/180/e)**2;return Math.min(1,Ce.CONE_SOLID_ANGLE/t)}pointScratch=new we;static POINT_VEIL_HOLD_DEG=.25;static BRIGHTEST_RELATIVE=6e4;arrivingIlluminance(e,t,i){const n=this.air.transmittanceFromSpace(this.siteElevationM+this.observerElevationM,e.altitudeDeg),s=_t.illuminanceOf(t)*i*this.relativeScale;return[n[0]*s,n[1]*s,n[2]*s]}static unitLuminance(e){const t=Hs.luminanceOf([e.r,e.g,e.b]);return t>0?[e.r/t,e.g/t,e.b/t]:[1,1,1]}setHitArea(e,t,i,n,s){let r=this.hitAreas.get(e);if(!r){const l=new eu({transparent:!0,opacity:0,depthTest:!1,depthWrite:!1,fog:!1});r=new Ec(l),this.celestialGroup.add(r),this.hitAreas.set(e,r)}r.position.set(t,i,n);const a=s*2;r.scale.set(a,a,1)}disposeHitArea(e){const t=this.hitAreas.get(e);t&&(t.removeFromParent(),t.material.dispose(),this.hitAreas.delete(e))}setGlare(e,t,i,n,s,r,a=0){if(rn.radiusDeg(rn.K*Math.max(...s))<=Math.max(r,a)){this.disposeGlare(e);return}let l=this.glareSprites.get(e);l||(l=new rn(`veil:${e}`),this.celestialGroup.add(l.mesh),this.glareSprites.set(e,l)),l.shine({x:t,y:i,z:n},s,r,a)}disposeGlare(e){const t=this.glareSprites.get(e);t&&(t.mesh.removeFromParent(),t.dispose(),this.glareSprites.delete(e))}buildComet(e,t){const i=e&&`comet:${e.id}`;if(!e||!i||e.magnitude>t){this.disposeComet();return}this.cometKey&&this.cometKey!==i&&this.disposeComet();const n=Dl(e.magnitude,t),s=Rp(n);this.cometKey=i,this.setBodyMesh(i,e.position,$p*(.5+.5*n),new ne(s,s,s),e.magnitude),this.cometTail||(this.cometTail=new rs(Wn),this.celestialGroup.add(this.cometTail.object)),this.cometTail.set(e.position,e.tailEnd,n)}buildIceHalos(e,t){this.iceHalos||(this.iceHalos=new nn,this.iceHalos.setCloudOffset(this.cloudFieldOffset),this.iceHalos.onReady=()=>this.render(),this.celestialGroup.add(this.iceHalos.object)),this.iceHalos.setUrgent(!!this.skyHoldUntilMs);const i=this.highCloudCover(),n=this.layeredClouds?.cirrusMask;if(this.iceHalos.setCloudOffset(n?.offset??this.cloudFieldOffset),this.layeredClouds?.hostHalo(this.iceHalos),i===void 0){this.iceHalos.update({x:0,y:1,z:0},-1,0,[1,1,1],{cover:0,layerHeight:Nd},0);return}const s=this.lowerCloudCover(),r=At.deckLitUntilDeg(At.DECK_HEIGHT_M),a=e.altitudeDeg>-r?e:t,l=this.bentLight(a,a===e?dt.SUN_MAGNITUDE:t.magnitude),c=At.strength(i,s,a.altitudeDeg,r)*l.scale,{x:h,y:d,z:u}=ni(a.altitudeDeg,a.azimuthDeg,1);this.iceHalos.update({x:h,y:d,z:u},a.altitudeDeg,c,l.tint,{cover:n?.cover??i,layerHeight:n?.layerHeight??Nd},n?.iceCrystalAlignment??this.weather.iceCrystalAlignment??lu)}buildRainbow(e,t){this.rainbow||(this.rainbow=new Mo,this.celestialGroup.add(this.rainbow.object));const i=this.weather.precipitationType==="rain"?this.weather.precipitationIntensity*(this.weather.precipitationAmount??1):0,n=e.altitudeDeg>0,s=n?e:t,r=this.lowerCloudCover(),a=this.bentLight(s,n?dt.SUN_MAGNITUDE:t.magnitude,mC),l=bn.strength(i,r,s.altitudeDeg)*a.scale;if(l<=0){this.rainbow.update({x:0,y:1,z:0},0,[1,1,1],!0);return}const{x:c,y:h,z:d}=ni(s.altitudeDeg,s.azimuthDeg,1);this.rainbow.update({x:c,y:h,z:d},l,a.tint,n)}buildSkyGlow(e,t){if(!e.frame){this.skyGlow?.hide();return}this.skyGlow||(this.skyGlow=new ga,this.skyGlow.setWithheld(!!this.skyHoldUntilMs),this.skyGlow.onReady=()=>this.render(),this.celestialGroup.add(this.skyGlow.object));const{date:i,observer:n}=e.frame,s=as.galactic(i,n),r=Ze.directionOf(s.centre),a=Ze.directionOf(s.rotation),l=Ze.directionOf(s.pole),c=new Je().set(r.x,r.y,r.z,a.x,a.y,a.z,l.x,l.y,l.z),h=Ze.directionOf(as.eclipticPole(i,n)),d=Ze.directionOf(e.sun),u=d.clone().addScaledVector(h,-d.dot(h)).normalize();this.skyGlow.update({galactic:c,eclipticPole:h,sunLongitude:u,sunDirection:d,sunAltitudeDeg:e.sun.altitudeDeg,moon:{direction:Ze.directionOf(e.moon),altitudeDeg:e.moon.altitudeDeg,phaseAngleDeg:ce.phaseAngleOf(e.moon.phase.illuminatedFraction)},lightPollution:this.lightPollution,skyColor:new D(t[0],t[1],t[2])})}static directionOf(e){const{x:t,y:i,z:n}=ni(e.altitudeDeg,e.azimuthDeg,1);return new D(t,i,n).normalize()}buildNovae(e,t){const i=new Set;for(const n of e){if(n.magnitude>t)continue;const s=`nova:${n.id}`;i.add(s);const r=Dl(n.magnitude,t),a=Rp(r);this.setBodyMesh(s,n.position,$p*(.5+.5*r),new ne(a,a,a),n.magnitude)}for(const n of this.novaKeys)i.has(n)||(this.disposeMesh(this.bodyMeshes.get(n)),this.bodyMeshes.delete(n),this.disposeHitArea(n),this.disposeGlare(n));this.novaKeys=i}disposeComet(){this.cometTail?.set(void 0,void 0,0),this.cometKey&&(this.disposeMesh(this.bodyMeshes.get(this.cometKey)),this.bodyMeshes.delete(this.cometKey),this.disposeHitArea(this.cometKey),this.disposeGlare(this.cometKey),this.cometKey=void 0)}buildPlanets(e,t){const i=new Set(["sun","moon",...this.cometKey?[this.cometKey]:[],...this.novaKeys]);for(const n of e){if(n.magnitude>t)continue;i.add(n.body);const s=Dl(n.magnitude,t),r=Rp(s),a=e6[n.body]??new ne(1,1,1),l=new ne(a.r*r,a.g*r,a.b*r),c=$p*(.5+.5*s);this.setBodyMesh(n.body,n.position,c,l,n.magnitude)}for(const n of[...this.bodyMeshes.keys()])i.has(n)||(this.disposeMesh(this.bodyMeshes.get(n)),this.bodyMeshes.delete(n),this.disposeHitArea(n),this.disposeGlare(n))}buildStars(e,t){if(this.namedStars=[],!e||e.catalog.count===0){this.disposeStarTiers(),this.syncAnimationLoop();return}const{catalog:i,date:n,observer:s}=e,r=new Us(n,s),a=i0(1337),l=[],c=this.siteElevationM+this.observerElevationM;for(let h=0;h<i.count;h++){const d=i.mag[h];if(d>t)break;const{altitudeDeg:u,azimuthDeg:f}=r.position(i.ra[h],i.dec[h]);if(u<cb)continue;const{x:p,y:g,z:m}=ni(u,f,Wp);l.push({x:p,y:g,z:m,brightness:Dl(d,t),illuminance:this.air.transmittanceFromSpace(c,u).map(v=>v*_t.illuminanceOf(d)),phase:a()*Math.PI*2,speedFactor:.7+a()*.6})}for(const h of r4){if(h.mag>t)continue;const{altitudeDeg:d,azimuthDeg:u}=r.position(h.raHours,h.decDeg);if(d<cb)continue;const{x:f,y:p,z:g}=ni(d,u,Wp);this.namedStars.push({star:h,direction:new D(f,p,g).normalize(),altitudeDeg:d})}this.starTiers=$l.map((h,d)=>{const u=l.filter(w=>Pg(w.brightness)===d),f=new Float32Array(u.length*3),p=new Float32Array(u.length),g=new Float32Array(u.length*3),m=new Float32Array(u.length),v=new Float32Array(u.length);u.forEach((w,S)=>{f[S*3]=w.x,f[S*3+1]=w.y,f[S*3+2]=w.z,p[S]=w.brightness,g.set(w.illuminance,S*3),m[S]=w.phase,v[S]=w.speedFactor});const b=new ot;b.setAttribute("position",new st(f,3)),b.setAttribute("seed",new st(m.map(w=>w/(2*Math.PI)),1));const x=new st(new Float32Array(u.length*3),3);b.setAttribute("color",x);let y=this.starTiers[d]?.points;return y?(y.geometry.dispose(),y.geometry=b):(y=new ls(b,Ce.material(h.size)),Ce.track(y),this.celestialGroup.add(y)),{points:y,colorAttribute:x,brightness:p,illuminance:g,phase:m,speedFactor:v}}),this.starColoursRelative=Number.NaN,this.updateTwinkle(this.twinkleSeconds),this.startTwinkle()}twinkleSeconds=0;starColoursRelative=Number.NaN;updateTwinkle(e){Ce.setTime(e);const t=this.relativeScale;if(t!==this.starColoursRelative){this.starColoursRelative=t;for(const i of this.starTiers){const n=i.colorAttribute.array;for(let s=0;s<i.brightness.length;s++)n[s*3]=i.illuminance[s*3]*t,n[s*3+1]=i.illuminance[s*3+1]*t,n[s*3+2]=i.illuminance[s*3+2]*t;i.colorAttribute.needsUpdate=!0}}}buildClouds(){if(this.cloudRendering==="volume"||this.weather.cloudLayers!==void 0){this.layeredClouds||(this.disposeCloudSystem(),this.layeredClouds=new Wl(this.celestialGroup,Yp,this.cloudRendering)),this.disposeCirrus(),this.layeredClouds.hostHalo(this.iceHalos),this.layeredClouds.update(this.weather,this.observerElevationM+1.6),this.layeredClouds.setOffsets(this.cloudOffsetM,this.cloudLayerOffsetsM),this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor);return}const e=this.lowerCloudCover();if(e<=0){this.disposeCloudSystem();return}const t=this.weather.cloudDarkness,i=new ne(Wa[0]+(Zp[0]-Wa[0])*t,Wa[1]+(Zp[1]-Wa[1])*t,Wa[2]+(Zp[2]-Wa[2])*t);if(this.cloudMesh&&this.cloudUniforms){this.cloudUniforms.coverage.value=e,this.cloudUniforms.baseColor.value.copy(i),this.syncCloudLayer(),this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor);return}this.disposeCloudSystem();const{material:n,uniforms:s}=bm(i,e,Math.abs(this.cloudLayerOffset()));this.cloudMaterial=n,this.cloudUniforms=s,s.fieldOffset.value.copy(this.cloudFieldOffset),this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor);const r=Mm(Yp);this.cloudMesh=new Se(r,n),this.faceCloudDeck(this.cloudMesh,this.cloudLayerOffset()),this.celestialGroup.add(this.cloudMesh)}lowerCloudCover(){return this.weather.cloudLayers?1-this.weather.cloudLayers.filter(e=>e.type!=="cirrus").reduce((e,t)=>e*(1-t.coverage),1):this.weather.lowerCloudCover??this.weather.cloudCover}highCloudCover(){return this.weather.cloudLayers?1-this.weather.cloudLayers.filter(e=>e.type==="cirrus").reduce((e,t)=>e*(1-t.coverage),1):this.weather.highCloudCover}buildCirrus(){const e=this.weather.highCloudCover??0;if(this.layeredClouds||e<=0){this.disposeCirrus();return}if(this.cirrusMesh&&this.cirrusUniforms){this.cirrusUniforms.coverage.value=e,this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor);return}const{material:t,uniforms:i}=bm(new ne(...Wa),e,Nd,1);this.cirrusMaterial=t,this.cirrusUniforms=i,i.fieldOffset.value.copy(this.cloudFieldOffset),this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor),this.cirrusMesh=new Se(Mm(Yp*1.04),t),this.cirrusMesh.renderOrder=vb-1,this.celestialGroup.add(this.cirrusMesh)}disposeCirrus(){this.cirrusMesh&&(this.cirrusMesh.removeFromParent(),this.cirrusMesh.geometry.dispose()),this.cirrusMaterial?.dispose(),this.cirrusMesh=void 0,this.cirrusMaterial=void 0,this.cirrusUniforms=void 0}syncCloudLayer(){this.layeredClouds?.update(this.weather,this.observerElevationM+1.6);const e=this.cloudLayerOffset();this.cloudUniforms&&(this.cloudUniforms.layerHeight.value=Math.abs(e)),this.cloudMesh&&this.faceCloudDeck(this.cloudMesh,e)}faceCloudDeck(e,t){const i=t<0;e.scale.y=i?-1:1,e.renderOrder=i?Wl.deckOrder(!0,0,1):vb}cloudLayerOffset(){const t=((this.weather.cloudBaseM??Zm)-this.observerElevationM)*qp;return Math.sign(t||1)*Math.max(Math.abs(t),NC)}updateCloudLighting(e,t){const i=[this.cloudUniforms,this.cirrusUniforms].filter(d=>d!==void 0);if(i.length===0&&!this.layeredClouds)return;const n=this.cloudBeamDirection,[s,r,a]=this.cloudBeam.map(d=>d/Math.PI),l=this.lightningLevel*t0*this.relativeScale/Math.PI,c=new ne(t[0]+er.r*l,t[1]+er.g*l,t[2]+er.b*l);this.layeredClouds?.setLighting(n.clone(),new ne(s,r,a),c,c);const h=Math.max(0,n.y);for(const d of i)d.sunDir.value.copy(n),d.sunColor.value.setRGB(s*h,r*h,a*h),d.ambientColor.value.copy(c)}disposeCloudSystem(){this.layeredClouds?.dispose(),this.layeredClouds=void 0,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}precipitationCount(e){return WC(e,this.weather.precipitationIntensity,this.weather.precipitationAmount??1)}updatePrecipitationDensity(){const e=[[this.rainSystem?.points,Qp],[this.rainSplashSystem?.points,Xa],[this.precipitationPoints,this.weather.precipitationType==="none"||this.weather.precipitationType==="rain"?void 0:jp[this.weather.precipitationType].poolSize]];for(const[t,i]of e)t&&i!==void 0&&t.geometry.setDrawRange(0,this.precipitationCount(i));this.rainSystem&&(this.rainSystem.uniforms.uSpeedStreak.value=wb(e0(this.weather.precipitationIntensity)))}buildPrecipitation(){this.disposePrecipitationPoints(),this.disposeRain();const e=this.weather.precipitationType;if(e==="none")return;if(e==="rain"){this.buildRain();return}const t=jp[e],i=t.poolSize,n=i0(9001),s=new Float32Array(i*3),r=new Float32Array(i),a=new Float32Array(i),l=new Float32Array(i),c=new Float32Array(i),h=new Float32Array(i),d=new Float32Array(i),u=new Float32Array(i),f=new Float32Array(i),p=new Float32Array(i);for(let x=0;x<i;x++){const y=n()*Math.PI*2,w=n()*t.radiusM;s[x*3]=Math.cos(y)*w,s[x*3+1]=Sl+n()*(t.topYM-Sl),s[x*3+2]=Math.sin(y)*w,r[x]=n()*Math.PI*2,a[x]=.7+n()*.6,l[x]=.6+n()*.8,c[x]=.4+n()*1.2}const g=new ot;g.setAttribute("position",new st(s,3)),g.setDrawRange(0,this.precipitationCount(i));const m={uSize:{value:t.size},uScale:{value:.5*this.renderer.domElement.height},uOpacity:{value:t.opacity},uColor:{value:t.color.clone()},uHazeColor:{value:new ne(...this.baseFogColor)},uTexture:{value:t6(e)},uNearFocusDistance:{value:Ab},uHazeDistance:{value:t.radiusM*_b}},v=new Dt({uniforms:m,vertexShader:o6,fragmentShader:l6,transparent:!0,depthWrite:!1});this.precipitationUniforms=m;const b=new ls(g,v);b.renderOrder=Kp,this.scene.add(b),this.precipitationPoints=b,this.precipitationPositions=s,this.precipitationPhase=r,this.precipitationSpeedJitter=a,this.precipitationWobbleFreqJitter=l,this.precipitationWobbleAmpJitter=c,this.precipitationBounceRemaining=h,this.precipitationBounceHeight=d,this.precipitationBounceDuration=u,this.precipitationBounceVelX=f,this.precipitationBounceVelZ=p}updatePrecipitation(e,t){if(!this.precipitationPoints||!this.precipitationPositions||!this.precipitationPhase||!this.precipitationSpeedJitter)return;this.precipitationUniforms?.uHazeColor.value.setRGB(...this.baseFogColor);const i=this.weather.precipitationType;if(i==="none"||i==="rain")return;const n=jp[i];if(this.precipitationUniforms?.uColor.value.copy(Ze.litBySky(n.color,this.baseFogColor)),t<=0)return;const s=this.weather.windDirectionDeg*Ci,r=Math.sin(s)*this.weather.windSpeed*n.driftSensitivity,a=-Math.cos(s)*this.weather.windSpeed*n.driftSensitivity,l=this.precipitationPositions,c=this.precipitationPhase,h=this.precipitationSpeedJitter,d=this.precipitationWobbleFreqJitter,u=this.precipitationWobbleAmpJitter,f=this.precipitationBounceRemaining,p=this.precipitationBounceHeight,g=this.precipitationBounceDuration,m=this.precipitationBounceVelX,v=this.precipitationBounceVelZ,b=i==="snow"&&d&&u,x=i==="hail"&&f&&p&&g&&m&&v;for(let y=0,w=0;y<l.length;y+=3,w++){if(x&&f[w]>0){if(f[w]-=t,f[w]<=0){const M=Math.random()*Math.PI*2,_=Math.sqrt(Math.random())*n.radiusM;l[y]=Math.cos(M)*_,l[y+1]=n.topYM,l[y+2]=Math.sin(M)*_,f[w]=0}else{const M=1-f[w]/g[w];l[y+1]=Sl+Math.sin(Math.PI*M)*p[w],l[y]=Ud(l[y]+(r+m[w])*t,n.radiusM),l[y+2]=Ud(l[y+2]+(a+v[w])*t,n.radiusM)}continue}let S=0,A=0;if(b){const M=$C*d[w],_=YC*u[w];S=Math.sin(e*M*Math.PI*2+c[w])*_,A=Math.sin(e*M*Math.PI*2+c[w]+Math.PI/2)*_}if(l[y]+=(r+S)*t,l[y+1]-=n.fallSpeedMPerS*h[w]*t,l[y+2]+=(a+A)*t,l[y]=Ud(l[y],n.radiusM),l[y+2]=Ud(l[y+2],n.radiusM),l[y+1]<Sl){if(x){p[w]=Cb*(.2+Math.random()*1.6),g[w]=qC*(.5+Math.random()),f[w]=g[w];const I=Math.random()*Math.PI*2,R=KC*(p[w]/Cb);m[w]=Math.cos(I)*R,v[w]=Math.sin(I)*R,l[y+1]=Sl;continue}const M=Math.random()*Math.PI*2,_=Math.sqrt(Math.random())*n.radiusM;l[y]=Math.cos(M)*_,l[y+1]=n.topYM,l[y+2]=Math.sin(M)*_}}this.precipitationPoints.geometry.attributes.position.needsUpdate=!0}buildRain(){const e=e0(this.weather.precipitationIntensity);this.rainSystem=S4({count:Qp,radiusM:Uc,heightM:UC,bottomYM:yb,overallSpeed:BC,color:Mb.clone(),opacity:.85,visibleCount:this.precipitationCount(Qp),speedStreak:wb(e),pixelSize:Ib,seed:9001,nearFocusDistanceM:Ab,hazeDistanceM:Uc*_b,hazeColor:new ne(...this.baseFogColor)}),this.rainLastVerticalFacing=-1,this.syncRainSlant(),this.rainSystem.points.renderOrder=Kp,this.scene.add(this.rainSystem.points),this.buildRainSplashes()}buildRainSplashes(){const e=i0(4242),t=new Float32Array(Xa*3),i=new Float32Array(Xa),n=new Float32Array(Xa),s=new Float32Array(Xa);for(let h=0;h<Xa;h++){const d=e()*Math.PI*2,u=Math.sqrt(e())*Uc;t[h*3]=Math.cos(d)*u,t[h*3+1]=yb,t[h*3+2]=Math.sin(d)*u,n[h]=kb(xb,Sb),i[h]=e()*n[h],s[h]=i[h]/n[h]}const r=new ot;r.setAttribute("position",new st(t,3));const a=new st(s,1);r.setAttribute("aLife",a),r.setDrawRange(0,this.precipitationCount(Xa));const l=new Dt({uniforms:{uMaxSize:{value:VC},uScale:{value:.5*this.renderer.domElement.height},uColor:{value:Eb.clone()},uTexture:{value:s6()}},vertexShader:r6,fragmentShader:a6,transparent:!0,depthWrite:!1}),c=new ls(r,l);c.renderOrder=Kp,this.scene.add(c),this.rainSplashSystem={points:c,positions:t,life:i,duration:n,lifeAttribute:a}}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}syncRainSlant(){const e=this.rainSystem;if(!e)return;const t=this.weather.windDirectionDeg*Ci;e.uniforms.uDropVelocity.value.set(Math.sin(t)*this.weather.windSpeed,-e0(this.weather.precipitationIntensity),-Math.cos(t)*this.weather.windSpeed);const i=this.renderer.getSize(this.rainViewportSize);e.uniforms.uAspect.value=i.x/Math.max(i.y,1)}updateRain(e){const t=this.rainSystem;if(!t)return;t.uniforms.uTime.value+=e,t.uniforms.uHazeColor.value.setRGB(...this.baseFogColor),t.uniforms.uColor.value.copy(Ze.litBySky(Mb,this.baseFogColor));const i=this.rainSplashSystem?.points.material?.uniforms?.uColor;i&&i.value.copy(Ze.litBySky(Eb,this.baseFogColor));const n=this.weather.windDirectionDeg*Ci,s=Math.sin(n)*this.weather.windSpeed,r=-Math.cos(n)*this.weather.windSpeed,a=Uc,l=h=>(h%(a*2)+a*3)%(a*2)-a;t.uniforms.uWindOffset.value.set(l(t.uniforms.uWindOffset.value.x+s*e),l(t.uniforms.uWindOffset.value.y+r*e)),this.syncRainSlant(),this.camera.getWorldDirection(this.rainCameraDirection);const c=Math.abs(this.rainCameraDirection.y);if(Math.abs(c-this.rainLastVerticalFacing)>.001){this.rainLastVerticalFacing=c;const h=Db+(1-Db)*(1-c),d=Rb+(1-Rb)*(1-c);t.uniforms.uUvSquash.value=d,t.uniforms.uPixelSize.value=Ib*h*(.5+.5*d)}this.updateRainSplashes(e)}updateRainSplashes(e){const t=this.rainSplashSystem;if(!t||e<=0)return;const{positions:i,life:n,duration:s,lifeAttribute:r}=t,a=r.array;for(let l=0,c=0;l<i.length;l+=3,c++){if(n[c]+=e,n[c]>=s[c]){const h=Math.random()*Math.PI*2,d=Math.sqrt(Math.random())*Uc;i[l]=Math.cos(h)*d,i[l+2]=Math.sin(h)*d,s[c]=kb(xb,Sb),n[c]=0}a[c]=n[c]/s[c]}t.points.geometry.attributes.position.needsUpdate=!0,r.needsUpdate=!0}setLightning(e){this.lightningFlashes=e}updateLightning(e){let t,i=0;if(this.lightningArmed)for(const l of this.lightningFlashes){if(l.t>e)break;const c=qi.brightnessAt(l,e);c>i&&(t=l,i=c)}const n=t?Math.min(1,Math.max(.1,(JC/t.distanceM)**2)):0,s=i*n*(t?.cloudToGround?1:.6);if(s===this.lightningLevel&&!t?.cloudToGround)return;if(this.lightningLevel=s,this.scene.fog){const l=this.scene.fog,c=s*t0*this.relativeScale/Math.PI;l.color.setRGB(this.airlight[0]+er.r*c,this.airlight[1]+er.g*c,this.airlight[2]+er.b*c)}const r=this.skyMesh?.material?.color;if(r){const l=s*QC;r.setRGB(1+l*er.r,1+l*er.g,1+l*er.b)}if(this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor),this.lightningLight.intensity=s*t0*this.relativeScale,t){const{x:l,y:c,z:h}=ni(25,t.azimuthDeg,Wn);this.lightningLight.position.set(l,c,h)}this.lightningBolt||(this.lightningBolt=new va(Wn*.95),this.celestialGroup.add(this.lightningBolt.object));const a=this.weather.cloudBaseM??1500;this.lightningBolt.set(t,i,a),this.render()}buildCompassLabels(){this.compassSprites=TC.map(e=>{const t=Ro.point(e,this.compassPoints),i=new eu({map:c6(t),depthTest:!1,fog:!1}),n=new Ec(i),{x:s,y:r,z:a}=ni(0,e,fb);return n.position.set(s,r,a),n.scale.set(Fd,Fd,1),n.renderOrder=RC,n.layers.set(Gp),n.visible=this.compassHovered||this.compassForced,this.celestialGroup.add(n),n}),this.updateCompassScale()}updateCompassScale(){const e=this.camera.fov*Math.PI/360,t=pb*Math.PI/360,i=Fd*Math.tan(e)/Math.tan(t);for(const n of this.compassSprites)n.scale.set(i,i,1)}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 i of Array.isArray(t)?t:[t]){const n=i.map;n&&n.dispose(),i.dispose()}}}const Ci=Math.PI/180;function sr(o,e,t){return Math.max(e,Math.min(t,o))}function kb(o,e){return o+Math.random()*(e-o)}function Ud(o,e){return(o%(e*2)+e*3)%(e*2)-e}let Bd,zd;function t6(o){switch(o){case"snow":return i6();case"hail":return n6()}}function i6(){if(Bd)return Bd;const o=64,e=document.createElement("canvas");e.width=o,e.height=o;const t=e.getContext("2d"),i=t.createRadialGradient(o/2,o/2,0,o/2,o/2,o/2);return i.addColorStop(0,"rgba(255,255,255,0.95)"),i.addColorStop(.5,"rgba(255,255,255,0.55)"),i.addColorStop(1,"rgba(255,255,255,0)"),t.fillStyle=i,t.fillRect(0,0,o,o),Bd=new Kr(e),Bd}function n6(){if(zd)return zd;const o=64,e=document.createElement("canvas");e.width=o,e.height=o;const t=e.getContext("2d"),i=t.createRadialGradient(o/2,o/2,0,o/2,o/2,o/2);return i.addColorStop(0,"rgba(255,255,255,1)"),i.addColorStop(.55,"rgba(255,255,255,0.95)"),i.addColorStop(.8,"rgba(255,255,255,0.4)"),i.addColorStop(1,"rgba(255,255,255,0)"),t.fillStyle=i,t.fillRect(0,0,o,o),zd=new Kr(e),zd}let Hd;function s6(){if(Hd)return Hd;const o=64,e=document.createElement("canvas");e.width=o,e.height=o;const t=e.getContext("2d"),i=t.createRadialGradient(o/2,o/2,0,o/2,o/2,o/2);return i.addColorStop(0,"rgba(255,255,255,0)"),i.addColorStop(.4,"rgba(255,255,255,0)"),i.addColorStop(.6,"rgba(255,255,255,0.9)"),i.addColorStop(.8,"rgba(255,255,255,0.25)"),i.addColorStop(1,"rgba(255,255,255,0)"),t.fillStyle=i,t.fillRect(0,0,o,o),Hd=new Kr(e),Hd}const r6=`
9728
9728
  uniform float uMaxSize;
9729
9729
  uniform float uScale;
9730
9730
  attribute float aLife;
@@ -9790,7 +9790,7 @@ void main() {
9790
9790
  gl_FragColor = vec4(color, tex.a * uOpacity * (1.0 - blur * 0.5));
9791
9791
  }
9792
9792
  `;function Pb(o){const t=document.createElement("canvas");t.width=128,t.height=128;const i=t.getContext("2d"),n=128/2-2,s=128/2,r=128/2,a="#010101",l="#f4f1e2";i.fillStyle=a,i.beginPath(),i.arc(s,r,n,0,Math.PI*2),i.fill();const c=sr(o.illuminatedFraction,0,1),h=o.phaseFraction<.5,d=n*Math.abs(1-2*c),u=c<.5;return i.save(),i.beginPath(),i.arc(s,r,n,0,Math.PI*2),i.clip(),i.fillStyle=l,i.beginPath(),h?(i.arc(s,r,n,-Math.PI/2,Math.PI/2,!1),i.ellipse(s,r,d,n,0,Math.PI/2,-Math.PI/2,u)):(i.arc(s,r,n,Math.PI/2,-Math.PI/2,!1),i.ellipse(s,r,d,n,0,-Math.PI/2,Math.PI/2,u)),i.fill(),i.restore(),new Kr(t)}function c6(o){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(o,64,68),new Kr(e)}function i0(o){let e=o;return function(){e|=0,e=e+1831565813|0;let i=Math.imul(e^e>>>15,1|e);return i=i+Math.imul(i^i>>>7,61|i)^i,((i^i>>>14)>>>0)/4294967296}}class of{constructor(e,t){this.source=e,this.create=t}scene;wanted;pumping=!1;disposed=!1;static PATIENCE_FRAMES=600;static SCENE_WIDTH_PX=480;paint(e,t){this.disposed||(this.wanted={t:e,canvas:t},this.pumping||this.pump())}recordingChanged(e){this.scene&&(this.scene.sightingData=e)}dispose(){this.disposed=!0,this.scene?.remove(),this.scene=void 0}ensureScene(){if(this.scene)return this.scene;const e=this.create();return e.setAttribute("max-pixel-ratio","1"),e.setAttribute("always-live",""),Object.assign(e.style,{position:"fixed",left:"-10000px",top:"0",width:`${of.SCENE_WIDTH_PX}px`,visibility:"hidden",pointerEvents:"none"}),document.body.appendChild(e),e.documentUrl=this.source.documentUrl,e.accountInTheRound=this.source.accountInTheRound,e.sightingData=this.source.sightingData,this.scene=e,e}async pump(){this.pumping=!0;try{for(;this.wanted&&!this.disposed;){const{t:e,canvas:t}=this.wanted;this.wanted=void 0;const i=this.ensureScene();i.interpretation!==this.source.interpretation&&(i.interpretation=this.source.interpretation),i.compareAccount!==this.source.compareAccount&&(i.compareAccount=this.source.compareAccount),i.showAt(e);for(let n=0;n<of.PATIENCE_FRAMES&&!this.wanted&&!this.disposed&&(await new Promise(s=>requestAnimationFrame(()=>s())),!this.wanted);n++)if(i.snapshotTo(t)){t.dataset.ready="true";break}}}finally{this.pumping=!1}}}const n0=7.5,sh=9;class rr{static cache=new Map;static load(e){let t=rr.cache.get(e);return t||(t=fetch(e).then(i=>i.arrayBuffer()).then(i=>rr.parse(i)),rr.cache.set(e,t)),t}static upTo(e,t){const i=e.filter((r,a)=>a===0||e[a-1].magnitudeLimit<t);if(i.length<=1)return rr.load(e[0].url);const n=i.map(r=>r.url).join(`
9793
- `);let s=rr.cache.get(n);return s||(s=Promise.all(i.map(r=>rr.load(r.url))).then(r=>r.reduce((a,l)=>rr.concat(a,l))),rr.cache.set(n,s)),s}static parse(e){const t=e.byteLength/(4*Float32Array.BYTES_PER_ELEMENT),i=t*Float32Array.BYTES_PER_ELEMENT;return{count:t,ra:new Float32Array(e,0*i,t),dec:new Float32Array(e,1*i,t),mag:new Float32Array(e,2*i,t),ci:new Float32Array(e,3*i,t)}}static concat(e,t){const i=(n,s)=>{const r=new Float32Array(n.length+s.length);return r.set(n,0),r.set(s,n.length),r};return{count:e.count+t.count,ra:i(e.ra,t.ra),dec:i(e.dec,t.dec),mag:i(e.mag,t.mag),ci:i(e.ci,t.ci)}}}class Wt{constructor(e){if(this.heights=e,e.length!==Wt.WIDTH*Wt.HEIGHT)throw new Error(`a lunar relief has ${Wt.WIDTH*Wt.HEIGHT} samples, not ${e.length}`)}static SAMPLES_PER_DEGREE=16;static WIDTH=360*Wt.SAMPLES_PER_DEGREE;static HEIGHT=180*Wt.SAMPLES_PER_DEGREE;static UNIT_KM=.1;static REFERENCE_RADIUS_KM=1737.4;static BAND_FROM_DEG=74;static BAND_TO_DEG=106;heightKm(e,t){const i=Wt.SAMPLES_PER_DEGREE,n=(t%360+360)%360*i-.5,s=(90-e)*i-.5,r=Math.floor(n),a=Math.floor(s),l=n-r,c=s-a,h=(f,p)=>{const g=(f%Wt.WIDTH+Wt.WIDTH)%Wt.WIDTH,m=Math.min(Wt.HEIGHT-1,Math.max(0,p));return this.heights[m*Wt.WIDTH+g]},d=h(r,a)*(1-l)+h(r+1,a)*l,u=h(r,a+1)*(1-l)+h(r+1,a+1)*l;return(d*(1-c)+u*c)*Wt.UNIT_KM}static inBand(e,t){const i=Math.PI/180,n=Math.acos(Math.cos(e*i)*Math.cos(t*i))*180/Math.PI;return n>=Wt.BAND_FROM_DEG&&n<=Wt.BAND_TO_DEG}static withBump(e,t,i,n=.4){const s=new Int8Array(Wt.WIDTH*Wt.HEIGHT),r=Wt.SAMPLES_PER_DEGREE,a=Math.ceil(n*r),l=Math.floor(t*r),c=Math.floor((90-e)*r);for(let h=-a;h<=a;h++)for(let d=-a;d<=a;d++)Math.hypot(d,h)<=a&&(s[(c+h)*Wt.WIDTH+(l+d+Wt.WIDTH)%Wt.WIDTH]=Math.round(i/Wt.UNIT_KM));return new Wt(s)}static smooth(){return new Wt(new Int8Array(Wt.WIDTH*Wt.HEIGHT))}}class ws{static SAMPLES=5760;static SEARCH_FROM_DEG=87;static SEARCH_TO_DEG=90.2;static SEARCH_STEP_DEG=.0625;static profile(e,t,i,n=ws.SAMPLES){const{s,u:r,w:a,distanceKm:l}=ws.frame(e,t),c=Math.PI/180,h=new Float32Array(n),d=Wt.REFERENCE_RADIUS_KM;for(let u=0;u<n;u++){const f=u/n*2*Math.PI,p=Math.cos(f),g=Math.sin(f),m=p*r[0]+g*a[0],v=p*r[1]+g*a[1],b=p*r[2]+g*a[2];let x=0;for(let y=ws.SEARCH_FROM_DEG;y<=ws.SEARCH_TO_DEG;y+=ws.SEARCH_STEP_DEG){const w=Math.cos(y*c),S=Math.sin(y*c),A=w*s[0]+S*m,M=w*s[1]+S*v,_=w*s[2]+S*b,I=Math.asin(Math.max(-1,Math.min(1,_)))/c,R=Math.atan2(M,A)/c,L=d+i.heightKm(I,R),P=Math.atan2(L*S,l-L*w);P>x&&(x=P)}h[u]=x/c}return{radiusDeg:h,meanRadiusDeg:Math.asin(d/l)/c}}static frame(e,t){const i=new Xr(t.lat,t.lng,t.elevationM),n=$r(e),s=km(e,i,!1),r=new It(s.x-n.x,s.y-n.y,s.z-n.z,n.t),a=Math.hypot(r.x,r.y,r.z)*ws.AU_KM,l=ws.bodyFixed(e),c=l(r),h=Math.hypot(c[0],c[1],c[2]),d=[c[0]/h,c[1]/h,c[2]/h],u=UR(e,i),f=Hg(u),p=Vr(u,new It(-r.x,-r.y,-r.z,n.t)),g=Math.asin(p.z/Math.hypot(p.x,p.y,p.z)),m=Math.atan2(-p.y,p.x),v=new It(-Math.sin(g)*Math.cos(m),Math.sin(g)*Math.sin(m),Math.cos(g),n.t),b=new It(-Math.sin(m),-Math.cos(m),0,n.t);return{s:d,u:l(Vr(f,v)),w:l(Vr(f,b)),distanceKm:a}}static surfacePoint(e,t,i,n){const{s,u:r,w:a}=ws.frame(e,t),l=Math.PI/180,c=[0,1,2].map(d=>Math.cos(i*l)*r[d]+Math.sin(i*l)*a[d]),h=[0,1,2].map(d=>Math.cos(n*l)*s[d]+Math.sin(n*l)*c[d]);return{latDeg:Math.asin(h[2])/l,lonDeg:Math.atan2(h[1],h[0])/l}}static radiusAt(e,t){const i=e.radiusDeg.length,n=(t/360*i%i+i)%i,s=Math.floor(n),r=n-s;return e.radiusDeg[s]*(1-r)+e.radiusDeg[(s+1)%i]*r}static uncoveredFraction(e,t,i){const n=e.radiusDeg.length,s=i.upDeg*i.upDeg+i.rightDeg*i.rightDeg;let r=0;for(let a=0;a<n;a++){const l=a/n*2*Math.PI,c=Math.cos(l),h=Math.sin(l),d=c*i.upDeg+h*i.rightDeg,u=d*d-s+t*t;if(u<=0)continue;const f=Math.sqrt(u),p=d+f;if(p<=0)continue;const g=Math.max(0,d-f),m=Math.max(g,e.radiusDeg[a]);p>m&&(r+=.5*(p*p-m*m))}return Math.min(1,Math.max(0,r*(2*Math.PI/n)/(Math.PI*t*t)))}static AU_KM=1495978707e-1;static bodyFixed(e){const t=e4(de.Moon,e),i=Math.PI/180,n=t.ra*15*i,s=t.dec*i,r=t.spin*i,a=(c,[h,d,u])=>[Math.cos(c)*h+Math.sin(c)*d,-Math.sin(c)*h+Math.cos(c)*d,u],l=(c,[h,d,u])=>[h,Math.cos(c)*d+Math.sin(c)*u,-Math.sin(c)*d+Math.cos(c)*u];return c=>a(r,l(Math.PI/2-s,a(Math.PI/2+n,[c.x,c.y,c.z])))}static subObserverPoint(e,t){const i=new Xr(t.lat,t.lng,t.elevationM),n=$r(e),s=km(e,i,!1),r=ws.bodyFixed(e)(new It(s.x-n.x,s.y-n.y,s.z-n.z,n.t)),a=Math.hypot(r[0],r[1],r[2]);return{latDeg:Math.asin(r[2]/a)*180/Math.PI,lonDeg:Math.atan2(r[1],r[0])*180/Math.PI}}}class rh{static cache=new Map;static load(e){let t=rh.cache.get(e);return t||(t=rh.fetchRelief(e).catch(()=>{}),rh.cache.set(e,t)),t}static async fetchRelief(e){const t=await fetch(e);if(!t.ok)return;let i=new Uint8Array(await t.arrayBuffer());if(i[0]===31&&i[1]===139){if(typeof DecompressionStream>"u")return;const n=new Blob([i]).stream().pipeThrough(new DecompressionStream("gzip"));i=new Uint8Array(await new Response(n).arrayBuffer())}return new Wt(new Int8Array(i.buffer,i.byteOffset,i.length))}}class lf{constructor(e){this.names=e}body(e,t){return this.names?.bodies[e]??t}star(e){return this.names?.stars[e.name]??e.name}comet(e){return this.names?.comets[e.id]??e.name}nova(e){return this.names?.novae[e.id]??e.name}satelliteClass(e){return this.names?.satelliteClasses[e.id]??e.name}shower(e){return this.names?.showers[e.id]??e.name}lightRig(e){return this.names?.lightRigs[e.id]??e.name}instrument(e){return this.names?.instruments[e.id]??e.name}decorKind(e,t){return this.names?.decorKinds[e]??t}point(e){return Ro.point(e,this.names?.compassPoints)}towards(e){return Ro.towards(e,this.names)}}const h6="Global Meteor Network",d6="https://globalmeteornetwork.org/data/",u6="“Thunder” by Jerimee",f6="https://creativecommons.org/licenses/by/3.0/",p6="CC BY 3.0";class qn{static fill(e,t){e.innerHTML="";const i=h=>e.appendChild(h),n=t.currentTerrainAttribution;n&&i(qn.text(n));const s=t.currentRoadAttribution;s&&i(qn.text(s));const r=t.ufoElement.observerMapCredit;r&&!n?.includes(r)&&i(qn.text(r));for(const h of t.decorModelCredits){const d=h.author?` — ${h.author}`:"",u=document.createElement("li");h.sourceUrl?u.append(qn.link(h.sourceUrl,h.title),document.createTextNode(`${d} (${h.license})`)):u.textContent=`${h.title}${d} (${h.license})`,i(u)}for(const h of t.ufoElement.sighting.references){if(!h.credit)continue;const d=document.createElement("li");h.creditUrl?d.appendChild(qn.link(h.creditUrl,h.credit)):d.textContent=h.credit,i(d)}if(t.ufoElement.sighting.traces.length>0){const h=new Un(_s.preferencesFor(t)),d=new Set(t.ufoElement.sighting.traces.map(u=>h.read(u.source)).filter(u=>!!u));for(const u of d)i(qn.text(u))}const a=t.satelliteState;if(a.status==="ready"&&a.credit){const h=document.createElement("li");h.appendChild(qn.link(a.creditUrl??"",a.credit)),i(h)}if(t.fireballState.status==="ready"&&t.fireballState.records.length>0){const h=document.createElement("li");h.append(qn.link(d6,h6),document.createTextNode(" (CC BY 4.0)")),i(h)}const l=t.aircraftState;if(l.status==="ready"&&l.shown>0){const h=document.createElement("li");if(h.appendChild(qn.link(l.creditUrl,l.credit)),i(h),l.trailCredit){const d=document.createElement("li");d.appendChild(qn.link(l.trailCredit.creditUrl,l.trailCredit.credit)),i(d)}}const c=qn.text(`${u6} (`);c.append(qn.link(f6,p6),document.createTextNode(")")),i(c)}static text(e){const t=document.createElement("li");return t.textContent=e,t}static link(e,t){const i=document.createElement("a");return i.href=e,i.target="_blank",i.rel="noopener",i.textContent=t,i}}const m6=new URL(""+new URL("rain-BvWZrB9h.ogg",import.meta.url).href,import.meta.url).href,g6=new URL(""+new URL("wind-BjklexY7.ogg",import.meta.url).href,import.meta.url).href,v6=new URL(""+new URL("thunder-DA48qs_v.wav",import.meta.url).href,import.meta.url).href,y6=20,b6=1;class M6{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};level=1;master;output(e){return this.master||(this.master=e.createGain(),this.master.gain.value=this.level,this.master.connect(e.destination)),this.master}setLevel(e){this.level=e,this.master&&(this.master.gain.value=e)}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}}To.unlock(this.context)}setAmbient(e,t,i){if(this.requested={type:e,intensity:t,windSpeed:i},!this.context)return;this.paused&&(e="none",t=0,i=0);const n=e==="rain"||e==="hail"?e:"none";if(this.ambientVolume=n==="hail"?Math.min(1,t*1.3+.2):n==="rain"?t:0,n!==this.ambientKey){this.ambientKey=n;const r=++this.ambientToken;this.stopSource(this.ambientSource,this.ambientGain),this.ambientSource=void 0,this.ambientGain=void 0,n!=="none"&&this.startLoop(m6,this.ambientVolume).then(a=>this.applyIfCurrent(a,r,()=>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(i/y6,1);const s=i>b6;if(s!==this.windActive){this.windActive=s;const r=++this.windToken;this.stopSource(this.windSource,this.windGain),this.windSource=void 0,this.windGain=void 0,s&&this.startLoop(g6,this.windVolume).then(a=>this.applyIfCurrent(a,r,()=>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:i,windSpeed:n}=this.requested;this.setAmbient(t,i,n)}playThunder(){!this.context||this.paused||this.playOneShot(v6,.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.master=void 0,this.buffers.clear()}applyIfCurrent(e,t,i,n){if(t!==i()){e?.source.stop();return}n(e)}async startLoop(e,t){const i=this.context;if(i)try{const n=await this.getBuffer(e),s=i.createBufferSource();s.buffer=n,s.loop=!0;const r=i.createGain();return r.gain.value=t,s.connect(r).connect(this.output(i)),s.start(),{source:s,gain:r}}catch(n){console.warn("Weather ambient sound failed to load, staying silent:",n);return}}async playOneShot(e,t){const i=this.context;if(i)try{const n=await this.getBuffer(e),s=i.createBufferSource();s.buffer=n;const r=i.createGain();r.gain.value=t,s.connect(r).connect(this.output(i)),s.start()}catch(n){console.warn("Thunder sound failed to load:",n)}}async getBuffer(e){const t=this.context;if(!t)throw new Error("WeatherAudio: AudioContext not ready — resume() must be called first");let i=this.buffers.get(e);return i||(i=fetch(e).then(n=>{if(!n.ok)throw new Error(`Audio fetch failed (${n.status}): ${e}`);return n.arrayBuffer()}).then(n=>t.decodeAudioData(n)),this.buffers.set(e,i)),i}stopSource(e,t){try{e?.stop()}catch{}e?.disconnect(),t?.disconnect()}}class Nr{constructor(e){this.elements=e;const{eccentricity:t,perihelionAu:i}=e,[n,s]=this.perifocalAxes(),r=Math.sqrt(Nr.SUN_GM_AU3_PER_DAY2*(1+t)/i);this.perihelionPosition=this.scale(n,i),this.perihelionVelocity=this.scale(s,r),this.inverseSemiMajorAxis=(1-t)/i}static SUN_GM_AU3_PER_DAY2=.0002959122082855911;static MAX_ITERATIONS=200;perihelionPosition;perihelionVelocity;inverseSemiMajorAxis;positionAt(e){const t=e-this.elements.perihelionJd,i=this.universalAnomaly(t),n=this.inverseSemiMajorAxis*i*i,s=this.elements.perihelionAu,r=1-i*i/s*Nr.stumpffC(n),a=t-i*i*i/Math.sqrt(Nr.SUN_GM_AU3_PER_DAY2)*Nr.stumpffS(n);return{x:r*this.perihelionPosition.x+a*this.perihelionVelocity.x,y:r*this.perihelionPosition.y+a*this.perihelionVelocity.y,z:r*this.perihelionPosition.z+a*this.perihelionVelocity.z}}heliocentricDistanceAt(e){const t=this.positionAt(e);return Math.hypot(t.x,t.y,t.z)}universalAnomaly(e){if(e===0)return 0;const t=Math.sign(e),i=Math.sqrt(Nr.SUN_GM_AU3_PER_DAY2)*Math.abs(e),n=a=>{const l=this.inverseSemiMajorAxis*a*a,c=this.elements.perihelionAu;return(1-this.inverseSemiMajorAxis*c)*a*a*a*Nr.stumpffS(l)+c*a};let s=Math.max(1,i/this.elements.perihelionAu);for(;n(s)<i;)s*=2;let r=0;for(let a=0;a<Nr.MAX_ITERATIONS&&s-r>1e-13*Math.max(1,s);a++){const l=(r+s)/2;n(l)<i?r=l:s=l}return t*(r+s)/2}perifocalAxes(){const e=this.elements.ascendingNodeDeg*Math.PI/180,t=this.elements.argumentOfPerihelionDeg*Math.PI/180,i=this.elements.inclinationDeg*Math.PI/180,n=Math.cos(e),s=Math.sin(e),r=Math.cos(t),a=Math.sin(t),l=Math.cos(i),c=Math.sin(i);return[{x:n*r-s*a*l,y:s*r+n*a*l,z:a*c},{x:-n*a-s*r*l,y:-s*a+n*r*l,z:r*c}]}scale(e,t){return{x:e.x*t,y:e.y*t,z:e.z*t}}static stumpffC(e){if(Math.abs(e)<1e-6)return 1/2-e/24+e*e/720;if(e>0)return(1-Math.cos(Math.sqrt(e)))/e;const t=Math.sqrt(-e);return(Math.cosh(t)-1)/-e}static stumpffS(e){if(Math.abs(e)<1e-6)return 1/6-e/120+e*e/5040;if(e>0){const i=Math.sqrt(e);return(i-Math.sin(i))/(i*i*i)}const t=Math.sqrt(-e);return(Math.sinh(t)-t)/(t*t*t)}}const w2=[{id:"halley-1910",designation:"1P/Halley",name:"Halley's Comet",orbit:{eccentricity:.9672960498922706,perihelionAu:.5872100477652511,inclinationDeg:162.218798367122,ascendingNodeDeg:58.56208298700436,argumentOfPerihelionDeg:111.7366940639061,perihelionJd:2.4187816784171113e6},peakMagnitude:0,peakOn:"1910-05-20",absoluteMagnitude:4.72,activityExponent:4,tailLengthDeg:100,tailLengthAu:.1638,note:"Passed 0.15 au from Earth on 20 May 1910, and the Earth crossed the outer tail the day before — the apparition that produced a genuine public panic."},{id:"brooks-1911",designation:"C/1911 O1",name:"Comet Brooks",orbit:{eccentricity:.9876404970138669,perihelionAu:.4898172916113738,inclinationDeg:33.34043866978714,ascendingNodeDeg:293.7022074981857,argumentOfPerihelionDeg:153.5578007321686,perihelionJd:2.4193378856140426e6},peakMagnitude:2,peakOn:"1911-10-25",absoluteMagnitude:5.59,activityExponent:4},{id:"skjellerup-maristany-1927",designation:"C/1927 X1",name:"Comet Skjellerup-Maristany",orbit:{eccentricity:.999839726885059,perihelionAu:.1761569619628186,inclinationDeg:85.1125991950808,ascendingNodeDeg:78.24360172472711,argumentOfPerihelionDeg:47.15877857390136,perihelionJd:2.4252326808989984e6},peakMagnitude:-6,peakOn:"1927-12-15",absoluteMagnitude:1.19,activityExponent:4,note:"One of the few comets of the century seen in full daylight."},{id:"de-kock-paraskevopoulos-1941",designation:"C/1941 B2",name:"Comet de Kock-Paraskevopoulos",orbit:{eccentricity:.9991026715181549,perihelionAu:.7900329662827822,inclinationDeg:168.2039226531089,ascendingNodeDeg:43.10609347214336,argumentOfPerihelionDeg:268.6990344196369,perihelionJd:2430022157765061e-9},peakMagnitude:2,peakOn:"1941-02-05",absoluteMagnitude:5.01,activityExponent:4},{id:"southern-1947",designation:"C/1947 X1",name:"the Southern Comet",orbit:{eccentricity:.9998424430916737,perihelionAu:.1100045955093761,inclinationDeg:138.5113919632757,ascendingNodeDeg:337.3114969669252,argumentOfPerihelionDeg:196.1820121395961,perihelionJd:2.4325220864727003e6},peakMagnitude:-3,peakOn:"1947-12-08",absoluteMagnitude:3.01,activityExponent:4,note:"A bright southern-hemisphere comet of December 1947, the month the American sighting wave of that year was still being argued over."},{id:"eclipse-1948",designation:"C/1948 V1",name:"the Eclipse Comet",orbit:{eccentricity:.9999130678247334,perihelionAu:.1354437057263306,inclinationDeg:23.11668597152911,ascendingNodeDeg:211.0454985994762,argumentOfPerihelionDeg:107.2474157073104,perihelionJd:2.4328519265329437e6},peakMagnitude:-2,peakOn:"1948-11-01",absoluteMagnitude:4.79,activityExponent:4,note:"Found during the total solar eclipse of 1 November 1948, which is how a comet that bright had gone unnoticed: it had been hidden in the Sun's glare."},{id:"arend-roland-1957",designation:"C/1956 R1",name:"Comet Arend-Roland",orbit:{eccentricity:1.0002570255357,perihelionAu:.3160532361485914,inclinationDeg:119.9440863251822,ascendingNodeDeg:215.8548157717755,argumentOfPerihelionDeg:308.775920364167,perihelionJd:2.4359365327396123e6},peakMagnitude:.5,peakOn:"1957-04-25",absoluteMagnitude:3.96,activityExponent:4,note:"Showed a spike pointing back TOWARD the Sun in late April 1957 — a real anti-tail, and much reported at the time."},{id:"mrkos-1957",designation:"C/1957 P1",name:"Comet Mrkos",orbit:{eccentricity:.9993521583504134,perihelionAu:.3549238508212375,inclinationDeg:93.9433042053929,ascendingNodeDeg:68.32441518619923,argumentOfPerihelionDeg:40.31823675802871,perihelionJd:243605193752228e-8},peakMagnitude:1,peakOn:"1957-08-05",absoluteMagnitude:5.07,activityExponent:4,note:"The second bright naked-eye comet of 1957, four months after Arend-Roland."},{id:"seki-lines-1962",designation:"C/1962 C1",name:"Comet Seki-Lines",orbit:{eccentricity:1.000003791331562,perihelionAu:.03139689112215131,inclinationDeg:65.01487186102287,ascendingNodeDeg:304.6776602796538,argumentOfPerihelionDeg:11.47295326312573,perihelionJd:2437756163010178e-9},peakMagnitude:-2.5,peakOn:"1962-04-01",absoluteMagnitude:9.3,activityExponent:4},{id:"ikeya-seki-1965",designation:"C/1965 S1",name:"Comet Ikeya-Seki",orbit:{eccentricity:.9999141178248997,perihelionAu:.007785966366889336,inclinationDeg:141.8642315267051,ascendingNodeDeg:346.9951764632611,argumentOfPerihelionDeg:69.04909813996062,perihelionJd:2.4390546837018197e6},peakMagnitude:-10,peakOn:"1965-10-21",alsoRecordedMagnitude:2,alsoRecordedOn:"1965-10-30",absoluteMagnitude:5.26,activityExponent:4.002,tailLengthDeg:25,tailLengthAu:.5048,note:"A sungrazer that passed 450 000 km above the Sun's surface and was seen beside it in broad daylight — the brightest comet of the twentieth century. It then stood in the dawn sky for a fortnight with a tail some 25 degrees long, which is the second magnitude recorded here."},{id:"bennett-1970",designation:"C/1969 Y1",name:"Comet Bennett",orbit:{eccentricity:.9962979048768408,perihelionAu:.5376209981502136,inclinationDeg:90.03975717147327,ascendingNodeDeg:224.6576652531314,argumentOfPerihelionDeg:354.1494209173161,perihelionJd:2.4406655455270996e6},peakMagnitude:0,peakOn:"1970-03-26",absoluteMagnitude:3.36,activityExponent:4},{id:"white-ortiz-bolelli-1970",designation:"C/1970 K1",name:"Comet White-Ortiz-Bolelli",orbit:{eccentricity:.9999488875801225,perihelionAu:.00884411465256722,inclinationDeg:138.9520738221631,ascendingNodeDeg:336.8194095816687,argumentOfPerihelionDeg:61.10224765396615,perihelionJd:2.4407209807728203e6},peakMagnitude:1,peakOn:"1970-05-22",absoluteMagnitude:4.35,activityExponent:4},{id:"kohoutek-1973",designation:"C/1973 E1",name:"Comet Kohoutek",orbit:{eccentricity:1.000007152175185,perihelionAu:.1424250377812859,inclinationDeg:14.30414984159355,ascendingNodeDeg:258.4893339663974,argumentOfPerihelionDeg:37.79772760699667,perihelionJd:2442044930687027e-9},peakMagnitude:0,peakOn:"1974-01-05",absoluteMagnitude:4.89,activityExponent:4,note:"Announced in advance as the comet of the century and remembered for disappointing: it was an ordinary naked-eye object, not the spectacle the press had promised."},{id:"west-1976",designation:"C/1975 V1",name:"Comet West",orbit:{eccentricity:1.000017859625611,perihelionAu:.1966006188461085,inclinationDeg:43.07319920579427,ascendingNodeDeg:118.9189245655447,argumentOfPerihelionDeg:358.4315101259072,perihelionJd:2442833721841768e-9},peakMagnitude:-3,peakOn:"1976-02-25",absoluteMagnitude:4.41,activityExponent:4,tailLengthDeg:30,tailLengthAu:.4325,note:"Broke into four pieces at perihelion. Barely reported at the time — the press had been burned by Kohoutek two years earlier."},{id:"iras-araki-alcock-1983",designation:"C/1983 H1",name:"Comet IRAS-Araki-Alcock",orbit:{eccentricity:.9898409731606003,perihelionAu:.9913412593828502,inclinationDeg:73.25000846947029,ascendingNodeDeg:49.10235754476374,argumentOfPerihelionDeg:192.8506176754439,perihelionJd:2.4454757545235856e6},peakMagnitude:1.7,peakOn:"1983-05-11",absoluteMagnitude:9.04,activityExponent:4,note:"Passed 0.031 au from Earth on 11 May 1983, one of the closest cometary approaches on record: it crossed a quarter of the sky in a night, which no other comet in this list did."},{id:"halley-1986",designation:"1P/Halley",name:"Halley's Comet",orbit:{eccentricity:.9672792271749998,perihelionAu:.5871034488173393,inclinationDeg:162.2422242700916,ascendingNodeDeg:58.85993640671803,argumentOfPerihelionDeg:111.8655480539208,perihelionJd:2.4464709589610207e6},peakMagnitude:2.1,peakOn:"1986-03-10",absoluteMagnitude:2.71,activityExponent:4,note:"The worst-placed return in two thousand years — famous, expected, and for most observers a faint smudge."},{id:"hyakutake-1996",designation:"C/1996 B2",name:"Comet Hyakutake",orbit:{eccentricity:.9997295133739305,perihelionAu:.2302272039470452,inclinationDeg:124.923592343765,ascendingNodeDeg:188.0454295899424,argumentOfPerihelionDeg:130.1724036582639,perihelionJd:2.4502048946148166e6},peakMagnitude:0,peakOn:"1996-03-25",absoluteMagnitude:4.75,activityExponent:4,tailLengthDeg:80,tailLengthAu:1,note:"Passed 0.10 au from Earth in March 1996, five weeks BEFORE perihelion, with a tail measured at some 80 degrees — the longest of the modern era."},{id:"hale-bopp-1997",designation:"C/1995 O1",name:"Comet Hale-Bopp",orbit:{eccentricity:.9951314746156615,perihelionAu:.9141695067003724,inclinationDeg:89.43017155012492,ascendingNodeDeg:282.470602866853,argumentOfPerihelionDeg:130.5872524854533,perihelionJd:2450539633099368e-9},peakMagnitude:-.8,peakOn:"1997-04-01",absoluteMagnitude:-1.06,activityExponent:4,tailLengthDeg:20,tailLengthAu:.9938,note:"Visible to the naked eye for about eighteen months, longer than any comet on record."},{id:"mcnaught-2007",designation:"C/2006 P1",name:"Comet McNaught",orbit:{eccentricity:1.00001811603225,perihelionAu:.1707325614080681,inclinationDeg:77.83726446452654,ascendingNodeDeg:267.4149080498975,argumentOfPerihelionDeg:155.9756130642756,perihelionJd:2454113298753579e-9},peakMagnitude:-5.5,peakOn:"2007-01-13",absoluteMagnitude:2.53,activityExponent:4,tailLengthDeg:35,tailLengthAu:.5009,note:"The brightest comet since Ikeya-Seki, seen in daylight beside the Sun in January 2007."},{id:"lovejoy-2011",designation:"C/2011 W3",name:"Comet Lovejoy",orbit:{eccentricity:.999915056276912,perihelionAu:.005553783989325053,inclinationDeg:134.3558712062691,ascendingNodeDeg:326.3693517957772,argumentOfPerihelionDeg:53.50991655176601,perihelionJd:2455911511809431e-9},peakMagnitude:-3,peakOn:"2011-12-16",alsoRecordedMagnitude:1.5,alsoRecordedOn:"2011-12-22",absoluteMagnitude:3.51,activityExponent:1.194,note:"A sungrazer that was expected to be destroyed at perihelion and came out the other side, to stand in the southern dawn sky for the rest of December — which is the second magnitude recorded here."},{id:"panstarrs-2013",designation:"C/2011 L4",name:"Comet PANSTARRS",orbit:{eccentricity:1.000032542889696,perihelionAu:.301544229714915,inclinationDeg:84.2081978367921,ascendingNodeDeg:65.66588626213694,argumentOfPerihelionDeg:333.6516444379993,perihelionJd:2456361669960698e-9},peakMagnitude:1,peakOn:"2013-03-10",absoluteMagnitude:5.98,activityExponent:4},{id:"neowise-2020",designation:"C/2020 F3",name:"Comet NEOWISE",orbit:{eccentricity:.9991782081129224,perihelionAu:.2946512466331692,inclinationDeg:128.9375043020912,ascendingNodeDeg:61.01042991771634,argumentOfPerihelionDeg:37.2786526292898,perihelionJd:2.4590341788972816e6},peakMagnitude:.9,peakOn:"2020-07-08",absoluteMagnitude:5.79,activityExponent:4,tailLengthDeg:10,tailLengthAu:.1808,note:"The first comet since Hale-Bopp that ordinary observers in the northern hemisphere saw without being told where to look."},{id:"tsuchinshan-atlas-2024",designation:"C/2023 A3",name:"Comet Tsuchinshan-ATLAS",orbit:{eccentricity:1.000020192843226,perihelionAu:.3914228969475176,inclinationDeg:139.1105462619479,ascendingNodeDeg:21.55945689078845,argumentOfPerihelionDeg:308.4913086299446,perihelionJd:2460581242087108e-9},peakMagnitude:0,peakOn:"2024-10-14",absoluteMagnitude:3.97,activityExponent:4,tailLengthDeg:20,tailLengthAu:.1902,note:"Briefly reported far brighter around 9 October 2024, when it stood almost between the observer and the Sun and forward-scattered the light through its own dust — a geometry this catalog's brightness model does not attempt, so what is stored is the ordinary evening-sky peak a few days later."}];class ou{static WINDOW_DAYS=200;static TWILIGHT_ELONGATION_DEG=15;static LIGHT_SPEED_AU_PER_DAY=173.144632674;static orbits=new Map;static aroundDate(e){const t=this.julianDayOf(e);return w2.filter(i=>Math.abs(t-i.orbit.perihelionJd)<=this.WINDOW_DAYS)}static brightestAt(e,t){return this.aroundDate(e).map(i=>this.appearanceOf(i,e,t)).sort((i,n)=>i.magnitude-n.magnitude)[0]}static appearanceOf(e,t,i){const n=Zt(t),s=this.earthPositionAt(n),r=this.apparentPositionOf(e,2451545+n.tt,s),a=this.subtract(r,s),l=this.length(r),c=this.length(a),h=this.tailEndAt(e,r,s,l,n,t,i),d=this.horizontalOf(a,n,t,i);return{apparition:e,position:d,...h,heliocentricDistanceAu:l,earthDistanceAu:c,elongationDeg:this.angleBetween(a,this.subtract({x:0,y:0,z:0},s)),magnitude:this.magnitudeAt(e,l,c)}}static magnitudeAt(e,t,i){const n=e.absoluteMagnitude+5*Math.log10(i)+2.5*e.activityExponent*Math.log10(t);return Math.max(n,e.peakMagnitude)}static tailEndAt(e,t,i,n,s,r,a){if(e.tailLengthAu===void 0)return{};const l=1+e.tailLengthAu/n,c=this.subtract({x:t.x*l,y:t.y*l,z:t.z*l},i),h=this.subtract(t,i);return{tailEnd:this.horizontalOf(c,s,r,a),tailLengthDeg:this.angleBetween(h,c)}}static apparentPositionOf(e,t,i){const n=this.orbitOf(e);let s=n.positionAt(t);for(let r=0;r<2;r++){const a=this.length(this.subtract(s,i))/this.LIGHT_SPEED_AU_PER_DAY;s=n.positionAt(t-a)}return s}static horizontalOf(e,t,i,n){const s=Vr(LR(),new It(e.x,e.y,e.z,t)),r=Vr(n2(t),s),a=km(t,new Xr(n.lat,n.lng,n.elevationM),!0),l=new It(r.x-a.x,r.y-a.y,r.z-a.z,t),c=Of(l);return Wg(c.ra,c.dec,i,n)}static earthPositionAt(e){return Vr(PR(),Da(de.Earth,e))}static julianDayOf(e){return 2451545+Zt(e).tt}static orbitOf(e){const t=this.orbits.get(e.id);if(t)return t;const i=new Nr(e.orbit);return this.orbits.set(e.id,i),i}static subtract(e,t){return{x:e.x-t.x,y:e.y-t.y,z:e.z-t.z}}static length(e){return Math.hypot(e.x,e.y,e.z)}static angleBetween(e,t){const i=(e.x*t.x+e.y*t.y+e.z*t.z)/(this.length(e)*this.length(t)||1);return Math.acos(Math.min(1,Math.max(-1,i)))*180/Math.PI}}const s0=[{id:"sn-1006",kind:"supernova",designation:"SN 1006",name:"Supernova of 1006",raHours:15.03947,decDeg:-42.09694,peakMagnitude:-7.5,peakJd:2088620,startJd:2088620,lightCurve:[[0,-7.5],[29,-5.9],[60,-4.9],[106,-3.2],[166,-1.9],[258,-1],[350,.5],[364,.7],[411,1.2],[456,1.8],[484,2.5],[785.5,7]],source:"Winkler, Gupta & Long 2003 (peak); decline borrowed from SN 1572",note:"The brightest stellar event in recorded history, seen in daylight, low in the southern sky from Europe and the Near East. The decline is modelled, not recorded, and falls below the naked eye after about two years where the chronicles speak of three."},{id:"sn-1054",kind:"supernova",designation:"SN 1054",name:"Supernova of 1054",raHours:5.5755,decDeg:22.0175,peakMagnitude:-6,peakJd:2106216,startJd:2106216,lightCurve:[[0,-6],[23,-4],[642,6]],source:"Chinese chronicles (Song huiyao), via Stephenson & Green 2002",note:"The explosion that left the Crab Nebula. Its magnitude is an estimate; the two durations are recorded."},{id:"sn-1181",kind:"supernova",designation:"SN 1181",name:"Supernova of 1181",raHours:.88645,decDeg:67.50067,peakMagnitude:0,peakJd:2152636,startJd:2152636,lightCurve:[[0,0],[185,6]],source:"Chinese and Japanese chronicles, via Stephenson & Green 2002",note:"Circumpolar from Europe and China, so never set. Its peak magnitude is uncertain by at least a magnitude."},{id:"sn-1572",kind:"supernova",designation:"SN 1572",name:"Tycho's Supernova",raHours:.42264,decDeg:64.14083,peakMagnitude:-4,peakJd:2295551,startJd:2295546,lightCurve:[[0,-3],[5,-4],[34,-2.4],[65,-1.4],[111,.3],[171,1.6],[263,2.5],[355,4],[369,4.2],[416,4.7],[461,5.3],[489,6]],source:"Tycho Brahe and contemporaries, reduced by Ruiz-Lapuente 2004",note:"Circumpolar from northern Europe. Tycho showed it had no parallax, so it was not in the air: a new star, beyond the Moon."},{id:"sn-1604",kind:"supernova",designation:"SN 1604",name:"Kepler's Supernova",raHours:17.51125,decDeg:-21.48733,peakMagnitude:-2.95,peakJd:2307210,startJd:2307191,lightCurve:[[0,.23],[3,-1.3],[6,-2.08],[9,-2.17],[19,-2.95],[27,-2.95],[32,-1.95],[36,-1.52],[86,.9],[96,.45],[103,1],[114,1.2],[118,1.55],[133,1.95],[137,2.3],[170,2.25],[185,2.25],[194,2.4],[197,2.9],[308,4.45],[324,4.45],[339,4.95],[364,4.7]],source:"Kepler, Fabricius, Maestlin and the Korean court astronomers, reduced by Ruiz-Lapuente 2017",note:"The last supernova in our Galaxy seen with the naked eye. It went behind the Sun from mid-November 1604 to January 1605, which is the gap in its record."},{id:"t-crb-1866",kind:"nova",designation:"T CrB",name:"Nova Coronae Borealis 1866",raHours:15.99171,decDeg:25.92017,peakMagnitude:2,peakJd:2402734,startJd:2402734,lightCurve:[[0,2],[1.5,3],[2.5,3.11],[6.5,5.18],[8.5,5.75],[10.5,6.85],[11.5,6.8],[12.5,7.5],[16,8.18],[32,9.27],[38,9.2],[40,8.95],[44,9.4],[48,9.07],[54,9.4],[58,9.21],[79,9.44],[107,9.26],[111,9.01],[115,8.21],[119,7.96],[159,7.51],[179,7.57],[183,7.97],[191,7.66],[199,8.2],[207,8.31],[211,8.83],[215,8.65],[223,8.97],[297,8.9],[345,9.25],[377,9.07],[425,9.3],[537,9.3]],source:"Recorded peak (Birmingham); curve borrowed from its 1946 eruption",note:"The first eruption of the recurrent nova T CrB to be seen. The decline is its 1946 one."},{id:"t-aur-1891",kind:"nova",designation:"T Aur",name:"Nova Aurigae 1891",raHours:5.53309,decDeg:30.44583,peakMagnitude:4.49,peakJd:2412083,startJd:2412079,lightCurve:[[0,5.28],[4,4.49],[24,4.58],[40,4.97],[52,4.95],[56,4.5],[60,4.9],[68,4.88],[72,5.25],[76,4.93],[84,5.44],[88,7.23],[96,8.85],[100,10.44]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"gk-per-1901",kind:"nova",designation:"GK Per",name:"Nova Persei 1901",raHours:3.52,decDeg:43.90431,peakMagnitude:.19,peakJd:24154395e-1,startJd:24154377e-1,lightCurve:[[0,2.7],[.8,.86],[1.8,.19],[2.3,.2],[5.8,1.78],[11.8,2.54],[12.8,2.98],[17.8,3.62],[18.8,3.35],[19.8,3.77],[20.8,3.59],[22.8,3.95],[24.8,3.82],[25.6,4.99],[25.9,4.89],[26.6,3.69],[27.6,3.94],[27.9,4.61],[28.6,5.28],[28.9,4.46],[29.9,3.8],[30.9,4.27],[31.6,5.21],[31.9,5.22],[32.9,3.88],[33.9,4.19],[34.6,4.85],[35.6,4.8],[36.6,4.23],[37.6,4.44],[38.9,4.15],[39.7,5.19],[40.6,5.39],[40.9,5.35],[41.9,4.01],[42.6,4.5],[42.9,4.49],[43.6,5.53],[44,5.23],[44.6,5.61],[44.9,5.5],[45.9,4.17],[46.9,4.69],[47.6,5.5],[48.6,5.59],[49.6,5.14],[49.9,4.48],[50.6,4.45],[50.9,4.55],[51.6,5.47],[52.6,5.74],[53.7,5.66],[55.7,4.41],[56.7,5.43],[58.7,5.81],[58.9,5.58],[59.7,5.64],[59.9,4.76],[60.9,4.26],[61.9,5.62],[62.7,5.85],[62.9,5.53],[63.7,5.8],[64.9,4.28],[65.6,5.33],[66.7,5.87],[66.9,5.56],[68.7,5.7],[68.9,5.3],[69.7,4.47],[70.7,5.65],[72.9,5.98],[73.9,5.71],[74.7,4.98],[74.9,4.46],[75.7,4.87],[76.9,6.05],[77.6,5.76],[78,6],[78.7,5.95],[80.7,4.98],[81.9,5.85],[82.7,6.02],[84.7,5.41],[84.9,5.08],[85.7,5.17],[85.9,5.6],[87,6.1],[88.8,6.2],[89.7,4.96],[89.9,4.93],[90.7,5.9],[91.9,6.32],[92.7,5.86],[93.1,6.24],[93.7,5.38],[93.9,6.2],[96.1,6.12],[97.1,6.37],[97.6,5.12],[98,5.85],[99.3,6.35],[101.3,6.12],[101.7,5.25],[102.3,4.95],[102.7,6.12],[103.2,5.83],[104.7,6.37],[105,6.13],[106,6.22],[106.7,4.88],[107.7,6.3],[108.1,6.4],[109,6],[109.7,5.16],[110,5.82],[112.1,5.89],[113.1,5.5],[115.7,5.8],[116,6.11],[118.7,5.68],[119,6.23],[119.7,5.85],[120,6.12],[121,4.62],[121.8,5.9],[123,5.48],[125,6.05],[126,5.89],[130.9,6.11],[146.1,6.02],[155.6,6.26],[180.4,6.09],[190.4,6.39],[245.5,6.87],[266.2,6.77],[301.1,7.16],[321.5,7.07],[346.5,7.87],[375.7,7.86],[385.8,8.09],[389.8,8.55],[406.1,8.33],[416.5,8.59],[445.9,8.62],[472.1,9.24],[565.9,9.74],[571,9.4],[589.8,9.76]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010",note:"Discovered on 21 February 1901 by Thomas Anderson in Edinburgh, and the brightest nova of the century until V603 Aql."},{id:"dn-gem-1912",kind:"nova",designation:"DN Gem",name:"Nova Geminorum 1912",raHours:6.9151,decDeg:32.14108,peakMagnitude:3.58,peakJd:241947675e-2,startJd:241947275e-2,lightCurve:[[0,11.7],[1,4.5],[4,3.58],[5,4.45],[5.5,5.32],[6,5.53],[6.5,5.11],[8,5.43],[8.5,5.16],[11,5.53],[11.5,5.13],[12,5.18],[13.75,4.5],[15.75,5.3],[18.75,6],[19.75,5.55],[26.75,6],[28.75,5.9],[31.75,6.6],[32.75,6.2],[33.75,6.5],[36.75,6.55],[39.75,6.2],[40.75,6.75],[41.75,7],[44.75,6.75],[52.75,6.75],[54.75,7.23],[58.25,7.5],[62.25,7.3],[64.25,7.47],[66.25,8.1],[70.25,7.5],[72.25,8.1],[78.25,7.55],[80.25,8.2],[86.25,7.2],[90.25,7.3],[92.25,7.8],[152.25,7.2],[160.25,7.4],[166.25,8.2],[168.25,8.2],[170.25,7.3],[180.25,7.4],[182.25,8],[186.25,7.5],[190.25,7.6],[192.25,8],[211.25,7.75],[227.25,8],[275.25,7.78],[315.25,8.6],[331.25,7.79],[339.25,8.27],[363.25,8.61],[443.25,8.93],[451.25,9.2],[535.25,10.3],[567.25,9.9],[615.25,10.8],[631.25,10.63],[647.25,10.88],[679.25,10.8],[695.25,11.07],[727.25,11]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"v603-aql-1918",kind:"nova",designation:"V603 Aql",name:"Nova Aquilae 1918",raHours:18.81518,decDeg:.58414,peakMagnitude:-.5,peakJd:242175475e-2,startJd:242174875e-2,lightCurve:[[0,11.3],[2,10.5],[4,6.6],[4.5,1.04],[6,-.5],[6.5,.18],[10,1.1],[10.5,.95],[12.75,1.89],[21.75,3.07],[23.75,3.76],[29.75,3.16],[34.75,3.5],[36.75,3.86],[44.75,3.79],[48.75,4.43],[52.75,3.84],[56.75,3.95],[57.75,4.04],[58.75,4.49],[59.75,4.42],[60.75,4.69],[62.75,4.6],[63.75,4.11],[64.75,3.97],[68.75,4.18],[70.75,4.65],[71.75,4.51],[73.75,4.73],[75.75,4.44],[79.75,4.85],[83.75,4.43],[89.75,4.88],[92.75,4.86],[94.75,4.58],[96.75,4.92],[99.75,5.05],[163.25,5.45],[167.25,5.7],[179.25,5.48],[191.25,5.8],[203.25,5.5],[247.25,5.9],[251.25,6.25],[257.25,5.5],[265.25,6.13],[281.25,6.33],[345.25,6.3],[385.25,6.73],[393.25,6.43],[425.25,6.71],[433.25,6.56],[461.25,7.27],[525.25,7.6],[541.25,7.47],[637.25,8.3],[669.25,8.17],[717.25,8.55],[749.25,8.4],[765.25,8.68],[885.25,8.75],[949.25,9.4],[1013.25,9.19],[1141.25,9.57],[1269.25,9.48],[1333.25,9.95],[1653.25,9.94],[1781.25,10.28],[1909.25,10.34],[2037.25,10.1],[2101.25,10.46],[2165.25,10.51],[2357.25,10.3],[2549.25,10.77],[2741.25,10.46],[2869.25,10.83],[3125.25,10.71],[3317.25,11.22],[3381.25,10.91],[3637.25,11.42],[3829.25,10.96],[3893.25,11.65],[3957.25,11.63],[4085.25,11.14],[4213.25,11.48],[4277.25,10.7],[4341.25,11.42],[4405.25,11.47],[4469.25,11.06],[4533.25,11.08],[4597.25,11.7],[4725.25,11.45],[4789.25,10.94]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010",note:"The brightest nova of the modern era, at magnitude -0.5 on 9-10 June 1918: as bright as Vega, in a summer evening sky, in wartime."},{id:"v476-cyg-1920",kind:"nova",designation:"V476 Cyg",name:"Nova Cygni 1920",raHours:19.97347,decDeg:53.61858,peakMagnitude:1.94,peakJd:242256025e-2,startJd:242255925e-2,lightCurve:[[0,2.7],[1,1.94],[3,2.07],[4.5,2.95],[8.25,4],[31.75,6.41],[35.75,7.23],[37.75,7.08],[41.75,7.33],[43.75,7.92],[45.75,8.2],[51.75,8.59],[63.75,8.82],[65.75,9.25],[71.75,8.93],[85.75,9.43],[87.75,9.05],[95.75,9.2],[97.75,8.67],[99.75,9.07],[112.75,8.78],[120.75,9.03],[128.75,8.67],[144.75,8.94],[152.75,8.73],[168.75,8.79],[176.75,9.28],[192.75,9],[216.75,9.6],[232.75,9.27],[240.75,9.5],[288.75,9.4],[296.75,9.6],[304.75,9.3],[320.75,9.73],[328.75,9.5],[336.75,9.8],[428.75,9.61],[476.75,10.01],[492.75,9.76],[508.75,9.87],[524.75,9.65],[556.75,9.87],[572.75,9.65],[620.75,10.22],[668.75,10.44],[684.75,10.23],[716.75,10.33],[756.75,10.66],[884.75,10.59],[948.75,10.96],[1108.75,10.96]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"rr-pic-1925",kind:"nova",designation:"RR Pic",name:"Nova Pictoris 1925",raHours:6.59335,decDeg:-62.64008,peakMagnitude:.95,peakJd:24243085e-1,startJd:24242995e-1,lightCurve:[[0,2.43],[5,2.35],[6,2.1],[7,2.4],[9,.95],[13,1.8],[14,1.7],[16,2.15],[18,2.2],[19,1.9],[23,3.1],[27,3.05],[31.5,3.58],[43.5,3.08],[47.5,3.15],[57.5,2.3],[59.5,1.65],[63.5,3.03],[65.5,2.84],[67.5,3.16],[69.5,2.4],[71.5,2.04],[73.5,2.05],[75.5,2.55],[79.5,3],[83.5,3.15],[116.5,3.54],[120.5,3.78],[124.5,3.67],[136.5,4.18],[148.5,4.34],[154.5,4.17],[194.5,4.43],[226.5,4.93],[234.5,4.8],[242.5,5.4],[250.5,5.5],[266.5,5.15],[298.5,5.6],[362.5,5.4],[414.5,5.7],[430.5,5.5],[494.5,6.2],[718.5,6.52],[830.5,6.3],[862.5,6.6],[878.5,6.4],[910.5,6.77],[958.5,6.67],[1062.5,7.07],[1318.5,7.35],[1590.5,8.12],[1718.5,8.25],[2486.5,8.59],[2614.5,8.47],[2742.5,8.7],[3382.5,8.6],[3766.5,8.97],[4022.5,8.79],[4150.5,9.22],[6710.5,10.29],[7414.5,11.03],[8438.5,10.96]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010",note:"A slow nova, and a southern one: more than two months within two magnitudes of its peak."},{id:"dq-her-1934",kind:"nova",designation:"DQ Her",name:"Nova Herculis 1934",raHours:18.12507,decDeg:45.85906,peakMagnitude:1.56,peakJd:24277935e-1,startJd:242778675e-2,lightCurve:[[0,3.4],[1.5,2.4],[3,2.67],[5.75,2.01],[6.75,1.56],[7.75,1.59],[11.75,2.97],[12.75,2.31],[14.75,3.07],[15.75,2.56],[16.75,2.51],[19.75,2.68],[23.75,2.53],[24.75,2.27],[26.75,2.58],[30.75,2.24],[31.75,2.63],[32.75,2.66],[34.75,2.11],[39.75,2.71],[41.75,2.31],[43.75,2.37],[46.75,3.64],[47.75,3.21],[50.75,3.23],[52.75,2.66],[55.75,2.56],[58.75,2.97],[60.75,2.77],[61.75,3.36],[63.75,3.43],[64.75,2.89],[65.75,3.22],[68.75,3.52],[69.75,2.95],[70.75,3.06],[71.75,2.7],[76.75,3.65],[79.75,3.74],[81.75,3.21],[83.75,3.75],[87.75,3.69],[92.75,4.04],[94.75,4.8],[97.75,4.24],[98.75,4.52],[100.75,4.08],[101.75,4.43],[105.75,4.58],[106.75,4.33],[107.75,4.73],[108.75,6.57],[109.75,8.08],[110.75,8.15],[111.75,8.56],[113.75,8.45],[114.75,9.15],[115.75,9.15],[116.75,9.59],[117.75,9.43],[118.75,9.8],[122.75,10.5],[123.75,10.28],[124.75,10.93],[127.75,10.83],[129.75,11.87],[131.75,12.42],[135.75,12.5],[137.75,12.9],[138.75,12.77],[139.75,13],[143.75,12],[144.75,12.33],[146.75,12.35],[147.75,11.64],[148.75,11.83],[150.75,10.9],[151.75,10.78],[152.75,11.17],[154.75,10.32],[155.75,10.4],[165.25,9.24],[185.25,7.74],[225.25,6.8],[273.25,6.72],[321.25,6.97],[333.25,6.79],[353.25,7],[357.25,6.82],[377.25,6.88],[401.25,7.29],[409.25,6.8],[413.25,6.8],[419.25,7.1],[435.25,7.09],[451.25,7.4],[475.25,7],[555.25,7.48],[823.25,7.83],[855.25,8.18],[1135.25,8.43],[1823.25,9.98],[1887.25,9.71],[2015.25,10.55],[2335.25,10.95]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010",note:"Lost about ten magnitudes in a few weeks from April 1935, when dust condensed around it, then came back to naked-eye brightness."},{id:"cp-lac-1936",kind:"nova",designation:"CP Lac",name:"Nova Lacertae 1936",raHours:22.26142,decDeg:55.61703,peakMagnitude:2.02,peakJd:242834025e-2,startJd:242833825e-2,lightCurve:[[0,4.03],[.5,2.9],[1,2.45],[2,2.02],[2.5,2.61],[4,3],[4.5,3.35],[5,3.3],[9.25,4.59],[14.25,5.45],[22.25,6.03],[23.25,6.3],[26.25,6.23],[38.25,6.74],[41.25,6.61],[50.25,7.35],[53.25,7.27],[57.25,7.7],[58.25,7.54],[60.25,7.55],[61.25,7.79],[71.25,7.6],[74.25,7.81],[76.25,8.3],[77.25,7.79],[86.25,8.21],[87.25,8],[88.25,8.25],[92.25,8.17],[94.25,8.47],[102.25,8.27],[103.25,8.7],[104.25,8.4],[110.25,8.66],[116.75,8.55],[122.75,8.83],[126.75,8.7],[140.75,9.06],[154.75,9.01],[164.75,9.36],[170.75,9.18],[174.75,9.48],[186.75,9.42],[188.75,9.73],[192.75,9.53],[200.75,9.74],[202.75,9.5],[204.75,9.77],[208.75,9.6],[214.75,9.75],[216.75,10.05],[222.75,9.7],[232.75,10.03],[236.75,9.82],[250.75,10.1],[254.75,9.9],[260.75,10.1],[264.75,9.8],[266.75,10.15],[268.75,10],[274.75,10.2],[276.75,9.9],[292.75,10.6],[294.75,10.6],[298.75,10.1],[318.75,10.35],[320.75,10.6],[322.75,10.3],[328.75,10.65],[332.75,10.3],[338.75,10.7],[348.75,10.53],[350.75,10.7],[354.75,10.37],[358.75,10.58],[365.75,10.43],[373.75,10.85],[421.75,10.94]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"cp-pup-1942",kind:"nova",designation:"CP Pup",name:"Nova Puppis 1942",raHours:8.19613,decDeg:-35.35139,peakMagnitude:.73,peakJd:243067675e-2,startJd:243067275e-2,lightCurve:[[0,.95],[4,.73],[4.5,1.3],[5.5,1.47],[6,2.01],[7.75,2.88],[8.75,2.97],[10.75,3.5],[11.75,4.02],[13.75,4.4],[14.75,3.8],[17.75,5],[18.75,4.93],[19.75,5.48],[23.75,5.5],[25.75,5.65],[26.75,5.99],[33.25,6.28],[45.25,6.6],[57.25,6.41],[81.25,6.85],[89.25,6.5],[97.25,6.67],[101.25,7],[113.25,6.66],[125.25,7.1],[135.25,6.96],[231.25,7.86],[279.25,7.8],[327.25,8.33],[407.25,8.18],[423.25,8.59],[471.25,8.53],[503.25,8.99],[551.25,8.97],[567.25,8.7],[583.25,9.47],[615.25,8.95],[655.25,9.5],[751.25,9.55],[815.25,10.09],[847.25,10.02],[879.25,10.48],[911.25,10.34],[1023.25,10.79],[1279.25,10.9]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010",note:"One of the fastest bright novae: two magnitudes gone in four days."},{id:"t-crb-1946",kind:"nova",designation:"T CrB",name:"Nova Coronae Borealis 1946",raHours:15.99171,decDeg:25.92017,peakMagnitude:2.5,peakJd:2431860,startJd:2431860,lightCurve:[[0,2.5],[1.5,3.5],[2.5,3.61],[6.5,5.68],[8.5,6.25],[10.5,7.35],[11.5,7.3],[12.5,8],[16,8.68],[32,9.77],[38,9.7],[40,9.45],[44,9.9],[48,9.57],[54,9.9],[58,9.71],[79,9.94],[107,9.76],[111,9.51],[115,8.71],[119,8.46],[159,8.01],[179,8.07],[183,8.47],[191,8.16],[199,8.7],[207,8.81],[211,9.33],[215,9.15],[223,9.47],[297,9.4],[345,9.75],[377,9.57],[425,9.8],[537,9.8]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010",note:"A recurrent nova. It erupted in 1866 and in 1946, and a third eruption was expected from 2024 on."},{id:"v446-her-1960",kind:"nova",designation:"V446 Her",name:"Nova Herculis 1960",raHours:18.956,decDeg:13.24147,peakMagnitude:4.83,peakJd:24370038e-1,startJd:24370033e-1,lightCurve:[[0,5.2],[.5,4.83],[2,4.9],[2.5,5.4],[3,5.05],[3.5,5.57],[4,5.25],[5,5.5],[6.5,5.4],[7.2,5.78],[8.2,5.6],[9.2,5.98],[10.2,5.92],[11.2,6.21],[16.2,6.1],[17.2,6.23],[18.2,7.2],[19.2,6.51],[20.2,6.78],[26.2,6.97],[27.2,7.24],[28.2,7.13],[29.2,7.45],[31.2,7.2],[40.7,7.57],[44.7,8.25],[46.7,7.84],[56.7,8.15],[60.7,8.9],[70.7,8.7],[72.7,8.14],[76.7,8.71],[80.7,8.47],[82.7,8.87],[86.7,8.57],[90.7,8.93],[107.7,9.11],[111.7,8.94],[115.7,9.27],[139.7,9.38],[151.7,9.91],[155.7,9.72],[173.7,10.51],[221.7,10.95]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"v533-her-1963",kind:"nova",designation:"V533 Her",name:"Nova Herculis 1963",raHours:18.23902,decDeg:41.85614,peakMagnitude:3,peakJd:24380605e-1,startJd:24380565e-1,lightCurve:[[0,8],[4,3],[4.5,3],[8,4],[13,3.95],[15,4.6],[21,4.53],[24,5.05],[27,5.15],[32,4.76],[34,4.98],[35,5.39],[37,5.43],[41,6.04],[49,6.02],[56.5,6.34],[60.5,6.11],[74.5,6.72],[102.5,6.99],[137.5,7.81],[197.5,8.31],[217.5,8.8],[225.5,8.57],[233.5,9.03],[237.5,8.78],[277.5,9.44],[301.5,9.46],[315.5,9.86],[323.5,9.73],[339.5,10.05],[355.5,10.74],[363.5,10.32],[371.5,10.6],[387.5,10.69],[427.5,10.38],[435.5,10.84],[443.5,10.74],[451.5,11.33],[459.5,10.98],[467.5,11.17],[507.5,11.16],[539.5,11.66],[603.5,11.7],[619.5,12.05],[651.5,12.03],[659.5,11.74],[667.5,10.9]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"hr-del-1967",kind:"nova",designation:"HR Del",name:"Nova Delphini 1967",raHours:20.70565,decDeg:19.16092,peakMagnitude:3.58,peakJd:2439838,startJd:2439646,lightCurve:[[0,11.9],[6,11.8],[12,8.8],[16,8.3],[20,6.7],[30,5.8],[36,5.51],[66,5.55],[78,5.35],[86,4.89],[96,5],[108,4.75],[136,5.13],[152,4.83],[182,4.93],[186,4.59],[192,3.58],[202,5],[220,5.46],[226,5.14],[230,5.45],[232,5.14],[236,5],[242,5.08],[244,4.59],[246,4.45],[254,5.3],[256,4.75],[260,5.69],[268,4.8],[274,4.94],[276,5.45],[280,5.2],[282,5.51],[286,5.58],[292,4.95],[294,5.16],[298,4.94],[311,5.09],[335,4.4],[367,5.76],[407,6.16],[423,6.55],[603,7.43],[907,8.32],[1451,9.41],[2347,10.75]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010",note:"An exceptionally slow nova: rose over months and stayed near magnitude 4 to 5 for most of 1967 and 1968."},{id:"lv-vul-1968",kind:"nova",designation:"LV Vul",name:"Nova Vulpeculae 1968",raHours:19.80012,decDeg:27.1715,peakMagnitude:4.5,peakJd:243996425e-2,startJd:243996325e-2,lightCurve:[[0,5],[1,4.5],[2,5],[2.5,4.86],[3,5.1],[3.5,4.88],[4,5.1],[5,4.9],[7,5.4],[8,5.23],[10.5,5.42],[12,5.82],[13,5.4],[13.5,5.74],[14,5.7],[14.5,6.08],[15,5.75],[15.5,5.86],[16,5.6],[17,5.8],[18,5.6],[20.5,6.34],[21,6.2],[22.5,6.84],[23,6.57],[24,6.98],[24.5,6.3],[25,7.1],[26,6.65],[34.25,7.48],[35.25,7.23],[39.25,7.32],[44.25,7.76],[45.25,7.49],[46.25,7.78],[50.25,7.84],[51.25,8.1],[53.25,7.9],[54.25,8.13],[56.25,8],[57.75,8.24],[67.75,8.52],[75.75,8.38],[83.75,8.69],[89.75,8.59],[125.75,9.32],[127.75,9.33],[129.75,8.98],[131.75,9.29],[135.75,9.43],[212.75,9.9],[220.75,10.16],[228.75,10.03],[236.75,10.3],[244.75,10.16],[264.75,10.54],[280.75,10.45],[296.75,10.79],[328.75,10.78]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"fh-ser-1970",kind:"nova",designation:"FH Ser",name:"Nova Serpentis 1970",raHours:18.51307,decDeg:2.61444,peakMagnitude:4.5,peakJd:244063425e-2,startJd:244063125e-2,lightCurve:[[0,7],[2,5],[3,4.5],[3.5,5],[4.5,4.6],[5.5,5],[6.5,4.68],[12.25,4.66],[16.25,5.3],[17.25,5.72],[18.25,5.3],[19.25,5.2],[23.25,5.84],[24.25,5.68],[27.25,5.9],[30.25,5.47],[32.25,5.9],[34.25,5.7],[43.25,6.28],[45.25,6.1],[50.25,6.62],[52.25,6.47],[57.25,6.63],[60.25,7.08],[61.25,6.87],[62.25,7.2],[63.25,6.85],[64.25,7.68],[65.25,7.3],[66.25,8.3],[67.25,7.93],[69.25,9.15],[71.25,9.2],[72.25,9.63],[74.25,9.9],[76.25,9.7],[77.25,10.25],[78.25,10.1],[79.25,10.4],[80.25,10.23],[81.25,10.57],[83.25,10.64],[85.25,10.35],[86.25,11.2],[87.25,10.1],[89.25,11.2],[96.25,11.35],[100.25,11.95],[102.25,11.1],[104.25,11.65],[106.25,11.5],[108.25,12.07],[114.75,11.32],[118.75,11.28],[122.75,10.93],[130.75,10.85],[134.75,10.52],[154.75,10.65],[162.75,10.12],[174.75,9.98],[178.75,10.34],[186.75,9.98],[214.75,10.25],[224.75,10.02],[240.75,10.2],[264.75,10],[272.75,10.2],[280.75,10.05],[288.75,10.4],[296.75,10],[348.75,10.7],[396.75,10.3],[444.75,10.73],[460.75,10.59],[540.75,10.94],[556.75,10.82]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"v1500-cyg-1975",kind:"nova",designation:"V1500 Cyg",name:"Nova Cygni 1975",raHours:21.19349,decDeg:48.15056,peakMagnitude:1.88,peakJd:244265525e-2,startJd:244265425e-2,lightCurve:[[0,2.44],[1,1.88],[1.5,1.88],[2.5,2.41],[3,3.38],[4,4.28],[8.25,5.81],[11.25,6.46],[22.25,7.35],[33.25,7.73],[34.25,7.97],[37.25,7.86],[40.25,8.3],[43.25,8.19],[48.25,8.6],[49.25,8.46],[66.25,9.04],[70.25,8.93],[75.25,9.23],[76.25,9.03],[80.25,9.39],[81.25,9.19],[83.25,9.35],[84.25,9.13],[86.25,9.39],[89.25,9.32],[90.25,9.54],[93.25,9.37],[105.75,9.86],[193.75,10.43],[201.75,10.7],[209.75,10.47],[257.75,10.94],[265.75,10.81]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010",note:"One of the fastest novae on record: discovered on 29 August 1975, at its peak of magnitude 1.9 within two days, and two magnitudes down again two days later."},{id:"v842-cen-1986",kind:"nova",designation:"V842 Cen",name:"Nova Centauri 1986",raHours:14.59794,decDeg:-57.6265,peakMagnitude:4.9,peakJd:244675975e-2,startJd:244675725e-2,lightCurve:[[0,5.6],[2.5,4.9],[3.5,5.1],[15.5,5.1],[17.5,5.75],[18.5,5.4],[20.5,5.5],[22.5,5.95],[30.5,6.15],[31.5,6.3],[32,7.5],[34.5,7.2],[38.5,7.5],[39,7],[41.5,7.15],[42.5,6.7],[44.5,7.23],[45.5,6.6],[53,9.3]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"sn-1987a",kind:"supernova",designation:"SN 1987A",name:"Supernova 1987A",raHours:5.59111,decDeg:-69.26975,peakMagnitude:2.98,peakJd:24469425e-1,startJd:24468495e-1,lightCurve:[[0,6.36],[1,6.11],[2,4.63],[4,4.45],[32,3.97],[56,3.15],[93,2.98],[105,3.35],[118,4.11],[134,4.43],[504,8.15],[617,10.27]],source:"V photometry compiled by the Open Supernova Catalog (Sternberg catalogue, IAU circulars, CTIO)",note:"In the Large Magellanic Cloud, 160 000 light years away: the nearest supernova since Kepler's, and invisible north of about 20° N."},{id:"v1974-cyg-1992",kind:"nova",designation:"V1974 Cyg",name:"Nova Cygni 1992",raHours:20.50879,decDeg:52.63078,peakMagnitude:4.27,peakJd:24486753e-1,startJd:24486718e-1,lightCurve:[[0,7.2],[1,5.23],[2,4.62],[3.5,4.27],[4.5,4.59],[6,4.5],[7,4.78],[7.5,4.52],[8,4.82],[10.7,5.25],[11.7,5.66],[16.7,5.85],[21.7,6.47],[22.7,6.3],[27.7,6.46],[29.7,6.83],[34.7,6.9],[35.7,7.25],[36.7,7],[37.7,7.16],[39.7,7.03],[43.7,7.41],[45.7,7.26],[50.7,7.45],[57.7,7.78],[58.7,8.13],[61.7,7.92],[64.7,8.19],[65.7,7.99],[71.7,8.22],[76.7,8.01],[128.2,8.72],[176.2,8.89],[192.2,9.15],[216.2,9.28],[232.2,9.07],[236.2,9.3],[390.2,10.99]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"v382-vel-1999",kind:"nova",designation:"V382 Vel",name:"Nova Velorum 1999",raHours:10.74678,decDeg:-52.42533,peakMagnitude:2.88,peakJd:245132225e-2,startJd:245132075e-2,lightCurve:[[0,2.99],[1.5,2.88],[2.5,3.46],[4.5,3.98],[5,4.32],[5.5,4.23],[7.5,4.85],[21.75,6.67],[30.25,7.2],[40.25,7.41],[93.25,7.95],[97.25,8.25],[101.25,8],[113.25,7.96],[129.25,8.5],[155.25,8.47],[163.25,9.1],[179.25,9],[187.25,8.7],[195.25,9.15],[211.25,9.23],[235.25,9.8],[243.25,9.71],[299.25,10.42],[383.25,10.52],[415.25,10.81]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"v1494-aql-1999",kind:"nova",designation:"V1494 Aql",name:"Nova Aquilae 1999",raHours:19.38482,decDeg:4.9555,peakMagnitude:4.11,peakJd:245151575e-2,startJd:245151425e-2,lightCurve:[[0,5.15],[.5,4.86],[1,4.27],[1.5,4.11],[2.5,4.35],[5,5.48],[10.5,6.26],[14.25,6.28],[20.25,7.43],[24.25,7.25],[25.25,7.63],[27.25,7.7],[29.25,7.42],[33.25,8.08],[35.25,8.03],[36.25,7.6],[37.25,7.6],[46.25,8.5],[54.25,8.28],[56.25,8.63],[58.25,8.4],[61.25,9.53],[62.25,9],[64.25,9.13],[69.25,8.58],[70.25,8.9],[72.25,8.88],[75.25,8.57],[77.25,9],[79.25,8.8],[81.25,9.7],[83.25,9.6],[85.25,9.8],[86.75,9.5],[88.75,9.54],[90.75,8.9],[92.75,8.85],[96.75,9.63],[102.75,9.7],[104.75,8.98],[106.75,8.73],[116.75,9.63],[118.75,9.6],[120.75,9.07],[122.75,9.26],[124.75,9.8],[128.75,9.36],[134.75,9.75],[147.75,9.92],[155.75,9.81],[259.75,10.96]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"v4743-sgr-2002",kind:"nova",designation:"V4743 Sgr",name:"Nova Sagittarii 2002",raHours:19.01926,decDeg:-22.00167,peakMagnitude:5,peakJd:245253775e-2,startJd:245253675e-2,lightCurve:[[0,5.2],[1,5],[2,5.89],[2.5,5.91],[3.5,6.43],[5,6.45],[5.5,6.86],[6,6.59],[7,6.77],[7.5,7.31],[8.5,6.99],[9,7.09],[10.5,7.86],[11,7.58],[11.5,7.89],[15.75,8.33],[17.75,8.18],[18.75,8.58],[19.75,8.44],[22.75,8.83],[23.75,8.6],[24.75,8.85],[27.75,8.83],[30.75,9.4],[31.75,9.09],[36.25,9.08],[38.25,9.34],[62.25,9.75],[66.25,10.1],[70.25,9.7],[74.25,10],[171.25,10.9]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"rs-oph-2006",kind:"nova",designation:"RS Oph",name:"Nova Ophiuchi 2006",raHours:17.83699,decDeg:-6.70792,peakMagnitude:4.8,peakJd:2453779,startJd:2453779,lightCurve:[[0,4.8],[1.25,4.97],[2.75,5.78],[3.25,5.7],[3.75,6.24],[4.25,6.05],[4.75,6.38],[5.25,6.3],[8.5,7.25],[14.5,7.95],[24.5,8.55],[29.5,9.08],[48,9.87],[80,10.28],[107,11.54],[119,11.54],[139,11.98],[147,11.83],[163,12.03],[171,11.97],[175,11.65],[183,11.84],[195,11.64],[203,11.8],[207,12.13],[219,11.45],[277,11.68],[325,11],[341,11.53],[357,11.62],[373,11.3],[405,11.5],[421,11.17],[469,10.96],[501,11.22],[549,10.75],[581,11.08],[597,10.98]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010",note:"A recurrent nova, erupting every twenty years or so (1898, 1907, 1933, 1945, 1958, 1967, 1985, 2006, 2021)."},{id:"v1280-sco-2007",kind:"nova",designation:"V1280 Sco",name:"Nova Scorpii 2007",raHours:16.96145,decDeg:-32.34325,peakMagnitude:3.8,peakJd:2454149,startJd:2454136,lightCurve:[[0,9.7],[13,3.8],[34,5.8],[103,15]],source:"AAVSO (discovery, peak, dust minimum); t2 from Das et al. 2008",note:"Faded from sight quickly when dust formed around it, three weeks after its peak."},{id:"v339-del-2013",kind:"nova",designation:"V339 Del",name:"Nova Delphini 2013",raHours:20.39186,decDeg:20.76772,peakMagnitude:4.4,peakJd:24565214e-1,startJd:24565214e-1,lightCurve:[[0,4.4],[11,6.4],[20,7.4]],source:"Gehrz et al. 2015 (peak, t2, t3)",note:"High in the summer evening sky of the northern hemisphere, and widely photographed."},{id:"v1369-cen-2013",kind:"nova",designation:"V1369 Cen",name:"Nova Centauri 2013",raHours:13.9126,decDeg:-59.15114,peakMagnitude:3.48,peakJd:245663965e-2,startJd:24566285e-1,lightCurve:[[0,5.33],[1.57,4.08],[2.75,3.73],[4.57,4.16],[5.96,4.15],[10.26,3.77],[11.15,3.48],[12.14,3.74],[14.17,4.78],[15.46,4.97],[23.16,4.22],[26.25,4.32],[27.31,4.82],[29.56,5.11],[32.66,4.71],[33.84,4.86],[36.05,4.46],[37.15,4.99],[41.42,4.59],[42.37,4.93],[43.37,4.82],[44.54,5.09],[49.95,5.38],[51.99,5.82],[54.21,5.77]],source:"AAVSO, binned by day, as plotted by Izzo 2017 (arXiv:1704.07214, figure 1)",note:"Discovered on 2 December 2013 by John Seach at magnitude 5.5, it flared several times, reaching about 3.3 around 14 December: the brightest nova of the century so far, and a southern one."},{id:"rs-oph-2021",kind:"nova",designation:"RS Oph",name:"Nova Ophiuchi 2021",raHours:17.83699,decDeg:-6.70792,peakMagnitude:4.6,peakJd:2459436,startJd:2459435,lightCurve:[[0,5],[1,4.6],[2.25,4.77],[3.75,5.58],[4.25,5.5],[4.75,6.04],[5.25,5.85],[5.75,6.18],[6.25,6.1],[9.5,7.05],[15.5,7.75],[25.5,8.35],[30.5,8.88],[49,9.67],[81,10.08],[108,11.34],[120,11.34],[140,11.78],[148,11.63],[164,11.83],[172,11.77],[176,11.45],[184,11.64],[196,11.44],[204,11.6],[208,11.93],[220,11.25],[278,11.48],[326,10.8],[342,11.33],[358,11.42],[374,11.1],[406,11.3],[422,10.97],[470,10.76],[502,11.02],[550,10.55],[582,10.88],[598,10.78]],source:"Recorded discovery and peak (8 and 9 August 2021); curve borrowed from its 2006 eruption",note:"RS Oph's latest eruption, discovered on 8 August 2021. The decline is its 2006 one."}];class cf{static UNIX_EPOCH_JD=24405875e-1;static aroundDate(e){const t=this.julianDayOf(e);return s0.filter(i=>this.magnitudeAt(i,t)!==void 0)}static appearancesAt(e,t){const i=this.julianDayOf(e),n=[];for(const s of s0){const r=this.magnitudeAt(s,i);r!==void 0&&n.push({outburst:s,position:Us.ofJ2000(s.raHours,s.decDeg,e,t),magnitude:r})}return n.sort((s,r)=>s.magnitude-r.magnitude)}static brightestAt(e,t){return this.appearancesAt(e,t)[0]}static byId(e){return s0.find(t=>t.id===e)}static magnitudeAt(e,t){const i=e.lightCurve,n=t-e.startJd;if(i.length===0||n<i[0][0]||n>i[i.length-1][0])return;let s=1;for(;s<i.length-1&&i[s][0]<n;)s++;const[r,a]=i[s-1]??i[0],[l,c]=i[s]??i[0];if(l===r)return a;const h=Math.min(1,Math.max(0,(n-r)/(l-r)));return a+h*(c-a)}static julianDayOf(e){return e.getTime()/864e5+this.UNIX_EPOCH_JD}}const w6=[{id:"quadrantids",code:"QUA",name:"Quadrantids",radiantRaHours:15.33,radiantDecDeg:49.7,start:{month:12,day:28},peak:{month:1,day:3},end:{month:1,day:12},peakZhr:110,velocityKmS:41,populationIndex:2.1},{id:"lyrids",code:"LYR",name:"April Lyrids",radiantRaHours:18.13,radiantDecDeg:33.3,start:{month:4,day:16},peak:{month:4,day:22},end:{month:4,day:25},peakZhr:18,velocityKmS:49,populationIndex:2.1},{id:"eta-aquariids",code:"ETA",name:"eta Aquariids",radiantRaHours:22.53,radiantDecDeg:-1,start:{month:4,day:19},peak:{month:5,day:6},end:{month:5,day:28},peakZhr:50,velocityKmS:66,populationIndex:2.4},{id:"alpha-capricornids",code:"CAP",name:"alpha Capricornids",radiantRaHours:20.47,radiantDecDeg:-9.2,start:{month:7,day:3},peak:{month:7,day:30},end:{month:8,day:15},peakZhr:5,velocityKmS:23,populationIndex:2.5},{id:"southern-delta-aquariids",code:"SDA",name:"Southern delta Aquariids",radiantRaHours:22.67,radiantDecDeg:-16.4,start:{month:7,day:12},peak:{month:7,day:30},end:{month:8,day:23},peakZhr:25,velocityKmS:41,populationIndex:3.2},{id:"perseids",code:"PER",name:"Perseids",radiantRaHours:3.22,radiantDecDeg:58,start:{month:7,day:17},peak:{month:8,day:12},end:{month:8,day:24},peakZhr:100,velocityKmS:59,populationIndex:2.2},{id:"southern-taurids",code:"STA",name:"Southern Taurids",radiantRaHours:3.47,radiantDecDeg:13,start:{month:9,day:10},peak:{month:10,day:10},end:{month:11,day:20},peakZhr:5,velocityKmS:27,populationIndex:2.3},{id:"draconids",code:"DRA",name:"October Draconids",radiantRaHours:17.47,radiantDecDeg:54,start:{month:10,day:6},peak:{month:10,day:8},end:{month:10,day:10},peakZhr:10,velocityKmS:20,populationIndex:2.6},{id:"orionids",code:"ORI",name:"Orionids",radiantRaHours:6.35,radiantDecDeg:15.6,start:{month:10,day:2},peak:{month:10,day:21},end:{month:11,day:7},peakZhr:20,velocityKmS:66,populationIndex:2.5},{id:"northern-taurids",code:"NTA",name:"Northern Taurids",radiantRaHours:3.87,radiantDecDeg:22,start:{month:10,day:20},peak:{month:11,day:12},end:{month:12,day:10},peakZhr:5,velocityKmS:29,populationIndex:2.3},{id:"leonids",code:"LEO",name:"Leonids",radiantRaHours:10.13,radiantDecDeg:21.6,start:{month:11,day:6},peak:{month:11,day:17},end:{month:11,day:30},peakZhr:15,velocityKmS:71,populationIndex:2.5},{id:"geminids",code:"GEM",name:"Geminids",radiantRaHours:7.47,radiantDecDeg:32.3,start:{month:12,day:4},peak:{month:12,day:14},end:{month:12,day:17},peakZhr:150,velocityKmS:35,populationIndex:2.6},{id:"ursids",code:"URS",name:"Ursids",radiantRaHours:14.47,radiantDecDeg:75.3,start:{month:12,day:17},peak:{month:12,day:22},end:{month:12,day:26},peakZhr:10,velocityKmS:33,populationIndex:3}],hc=6.5;class jl{static activeAt(e){return w6.flatMap(t=>{const i=this.nearness(t,e);return i<=0?[]:[{shower:t,zhr:t.peakZhr*i,nearness:i}]})}static nearness(e,t){const i=this.dayOfYear(t),n=this.dayOfYear(this.asDate(e.start)),s=this.dayOfYear(this.asDate(e.peak)),r=this.dayOfYear(this.asDate(e.end)),a=this.wrappedDelta(i,s),l=this.wrappedDelta(s,n),c=this.wrappedDelta(r,s);return a<0?a<-l?0:1+a/l:a>0?a>c?0:1-a/c:1}static observedRatePerHour(e,t,i,n=hc){if(t<=0)return 0;const s=hc-n;return e*Math.sin(t*Math.PI/180)/Math.pow(i,s)}static radiantPosition(e,t,i){return Us.ofJ2000(e.radiantRaHours,e.radiantDecDeg,t,i)}static dayOfYear(e){const t=Date.UTC(e.getUTCFullYear(),0,1);return Math.floor((Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate())-t)/864e5)+1}static asDate(e){return new Date(Date.UTC(2001,e.month-1,e.day))}static wrappedDelta(e,t){const i=e-t;return i>182?i-365:i<-182?i+365:i}}class vi{static QUIET_RATE_PER_HOUR=2;static APEX_RATE_PER_HOUR=8;static POPULATION_INDEX=3;static apexPosition(e,t){const i=Zt(e),n=new Cf(0,uR(e).elon-90,1),s=Vr(BR(i),Vg(n,i)),r=Of(s);return Wg(r.ra,r.dec,e,t)}static observedRatePerHour(e,t=hc){const i=vi.APEX_RATE_PER_HOUR*Math.max(0,Math.sin(e*Math.PI/180)),n=hc-t;return(vi.QUIET_RATE_PER_HOUR+i)/Math.pow(vi.POPULATION_INDEX,n)}static schedule(e){const t=new Nf(e.seed^1542469173);return Co.schedule(e).map(i=>{const n=vi.toCartesian({altitudeDeg:Math.asin(t.next())*180/Math.PI,azimuthDeg:t.between(0,360)}),s=i.fromRadiantDeg*Math.PI/180,r=vi.turnAround(n,t.between(0,360)),a={x:n.x*Math.cos(s)+r.x*Math.sin(s),y:n.y*Math.cos(s)+r.y*Math.sin(s),z:n.z*Math.cos(s)+r.z*Math.sin(s)};return{...i,radiant:vi.toHorizontal(a),bearingDeg:vi.bearingFrom(a,n)}})}static turnAround(e,t){const[i,n]=vi.basisAround(e),s=t*Math.PI/180;return{x:i.x*Math.cos(s)+n.x*Math.sin(s),y:i.y*Math.cos(s)+n.y*Math.sin(s),z:i.z*Math.cos(s)+n.z*Math.sin(s)}}static bearingFrom(e,t){const[i,n]=vi.basisAround(e),s=e.x*t.x+e.y*t.y+e.z*t.z,r=vi.normalise({x:t.x-e.x*s,y:t.y-e.y*s,z:t.z-e.z*s});return(Math.atan2(r.x*n.x+r.y*n.y+r.z*n.z,r.x*i.x+r.y*i.y+r.z*i.z)*180/Math.PI%360+360)%360}static basisAround(e){const t=Math.abs(e.y)<.9?{x:0,y:1,z:0}:{x:1,y:0,z:0},i=vi.normalise(vi.cross(e,t));return[i,vi.normalise(vi.cross(e,i))]}static toHorizontal(e){const t=Math.hypot(e.x,e.y,e.z)||1;return{altitudeDeg:Math.asin(Math.min(1,Math.max(-1,e.y/t)))*180/Math.PI,azimuthDeg:(Math.atan2(e.x,-e.z)*180/Math.PI%360+360)%360}}static appearanceOf(e){const t=vi.toCartesian(e.radiant??{altitudeDeg:90,azimuthDeg:0}),i=vi.turnAround(t,e.bearingDeg),n=e.fromRadiantDeg*Math.PI/180;return vi.toHorizontal({x:t.x*Math.cos(n)+i.x*Math.sin(n),y:t.y*Math.cos(n)+i.y*Math.sin(n),z:t.z*Math.cos(n)+i.z*Math.sin(n)})}static toCartesian(e){const t=e.altitudeDeg*Math.PI/180,i=e.azimuthDeg*Math.PI/180,n=Math.cos(t);return{x:n*Math.sin(i),y:Math.sin(t),z:-n*Math.cos(i)}}static cross(e,t){return{x:e.y*t.z-e.z*t.y,y:e.z*t.x-e.x*t.z,z:e.x*t.y-e.y*t.x}}static normalise(e){const t=Math.hypot(e.x,e.y,e.z)||1;return{x:e.x/t,y:e.y/t,z:e.z/t}}static TYPICAL_VELOCITY_KM_S=40}const Lb="https://ufoathome.org/tle/index.json";class mn{static MAX_ELEMENT_AGE_DAYS=7;static DAY_MS=864e5;fetchImpl;indexUrls;index;files=new Map;constructor(e={}){this.fetchImpl=e.fetchImpl??fetch.bind(globalThis),this.indexUrls=e.indexUrls??mn.defaultIndexUrls()}static defaultIndexUrls(){const e=[];return typeof location<"u"&&/^https?:$/.test(location.protocol)&&e.push(new URL("/tle/index.json",location.href).href),e.includes(Lb)||e.push(Lb),e}static FIRST_SNAPSHOT="2021-02-22";async covers(e){const t=Date.parse(`${mn.FIRST_SNAPSHOT}T00:00:00Z`)-mn.MAX_ELEMENT_AGE_DAYS*mn.DAY_MS;if(e.getTime()<t)return!1;const i=await this.loadIndex();return i?Object.values(i.index.kinds).some(n=>e.getTime()>=Date.parse(n.from)-mn.MAX_ELEMENT_AGE_DAYS*mn.DAY_MS&&e.getTime()<=Date.parse(n.to)+mn.MAX_ELEMENT_AGE_DAYS*mn.DAY_MS):!1}async at(e){const t=await this.loadIndex();if(!t)return;const{index:i,base:n}=t,s=[],r=[];for(const a of Object.keys(i.kinds)){const l=await this.kindAt(a,e,i,n);s.push(...l),r.push(this.coverageOf(a,e,i,l.length>0))}return{objects:s,coverage:r,credit:i.credit,creditUrl:i.source}}async kindAt(e,t,i,n){const s=t.getTime(),r=i.binDays*mn.DAY_MS,a=Math.floor(s/r),l=s-a*r<r/2?a-1:a+1,c=new Set(i.kinds[e].bins),h=[a,l].map(g=>new Date(g*r).toISOString().slice(0,10)).filter(g=>c.has(g));if(h.length===0)return[];const[d,...u]=await Promise.all([this.json(new URL(`objects-${e}.json`,n).href),...h.map(g=>this.binary(new URL(`${e}/${g}.bin`,n).href))]),f=new Map;for(const g of u)for(const m of mn.decode(g,i.recordBytes)){const v=f.get(m.norad);(!v||Math.abs(m.epochMs-s)<Math.abs(v.epochMs-s))&&f.set(m.norad,m)}const p=[];for(const g of f.values()){const m=Math.abs(g.epochMs-s)/mn.DAY_MS;if(m>mn.MAX_ELEMENT_AGE_DAYS)continue;const v=d[g.norad]??{name:String(g.norad)};v.launch&&Date.parse(`${v.launch}T00:00:00Z`)>s||p.push({norad:g.norad,name:v.name,kind:e,launch:v.launch,stdMag:v.stdMag,elements:g,ageDays:m})}return p}coverageOf(e,t,i,n){const{from:s,to:r}=i.kinds[e],a=t.getTime(),l=mn.MAX_ELEMENT_AGE_DAYS*mn.DAY_MS,c=n?"covered":a<Date.parse(s)-l?"before":a>Date.parse(r)+l?"after":"gap";return{kind:e,status:c,from:s,to:r}}static decode(e,t){const i=new DataView(e),n=[];for(let s=0;s+t<=e.byteLength;s+=t)n.push({norad:i.getUint32(s,!0),epochMs:i.getFloat64(s+4,!0),bstar:i.getFloat32(s+12,!0),inclinationDeg:i.getFloat32(s+16,!0),raanDeg:i.getFloat32(s+20,!0),eccentricity:i.getFloat32(s+24,!0),argOfPerigeeDeg:i.getFloat32(s+28,!0),meanAnomalyDeg:i.getFloat32(s+32,!0),meanMotion:i.getFloat64(s+36,!0)});return n}loadIndex(){return this.index??=(async()=>{for(const e of this.indexUrls)try{const t=await this.fetchImpl(e);if(!t.ok)continue;return{index:await t.json(),base:e}}catch{}})(),this.index}json(e){return this.cached(e,async t=>t.json())}binary(e){return this.cached(e,async t=>t.arrayBuffer())}cached(e,t){let i=this.files.get(e);return i||(i=this.fetchImpl(e).then(n=>{if(!n.ok)throw new Error(`${e}: ${n.status}`);return t(n)}),i.catch(()=>this.files.delete(e)),this.files.set(e,i)),i}}class x6{lowerM;upperM;add(e,t){if(!(e<=0)){if(t.behindM!==void 0){const i=pt.sizeMAt(t.behindM,e);this.lowerM=this.lowerM===void 0?i:Math.max(this.lowerM,i)}if(t.inFrontM!==void 0){const i=pt.sizeMAt(t.inFrontM,e);this.upperM=this.upperM===void 0?i:Math.min(this.upperM,i)}}}get sizeRange(){return{minM:this.lowerM,maxM:this.upperM}}get empty(){return this.lowerM===void 0&&this.upperM===void 0}get contradictory(){return this.lowerM!==void 0&&this.upperM!==void 0&&this.lowerM>this.upperM}distanceRangeAt(e){return e<=0?{}:{minM:this.lowerM===void 0?void 0:pt.distanceMAt(this.lowerM,e),maxM:this.upperM===void 0?void 0:pt.distanceMAt(this.upperM,e)}}clear(){this.lowerM=void 0,this.upperM=void 0}}class Po{static DEG_PER_SECOND=360/86164.0905;static degOver(e){return Math.max(0,e)*Po.DEG_PER_SECOND}static instants(e,t){if(!(t>0))return 1;const i=Po.degOver(e)/t;return i<1?1:Math.min(Po.MAX_INSTANTS,Math.max(2,Math.ceil(i)))}static MAX_INSTANTS=64}class vn{static EYE={apertureMm:7,exposureSeconds:.1,resolutionArcsec:60};static WAVELENGTH_M=55e-8;static ARCSEC_PER_RADIAN=180*3600/Math.PI;static UNKNOWN_CAMERA_FOCAL_MM=50;static UNKNOWN_CAMERA_DETAIL_UM=20;static get skyDriftArcsecPerSecond(){return Po.DEG_PER_SECOND*3600}static graspOf(e,t={}){const i=t.exposureSeconds??e.exposureSeconds,n=t.fNumber??e.fNumber;if(i===void 0||n===void 0||!(i>0)||!(n>0))return vn.EYE;const s=t.focalLengthMm??e.frame?.focalLengthMm??vn.UNKNOWN_CAMERA_FOCAL_MM,r=s/n,a=vn.resolutionArcsec(e,s,r);return{apertureMm:r,exposureSeconds:Math.min(i,vn.trailLimitedSeconds(a)),resolutionArcsec:a}}static resolutionArcsec(e,t,i){const s=(e.detailUm??vn.UNKNOWN_CAMERA_DETAIL_UM)/1e3/t*vn.ARCSEC_PER_RADIAN,r=1.22*vn.WAVELENGTH_M/(i/1e3)*vn.ARCSEC_PER_RADIAN;return Math.max(s,r)}static trailLimitedSeconds(e){return e/vn.skyDriftArcsecPerSecond}static gainOverEye(e,t={}){const i=vn.graspOf(e,t),n=vn.EYE,s=(i.apertureMm/n.apertureMm)**2,r=i.exposureSeconds/n.exposureSeconds,a=(n.resolutionArcsec/i.resolutionArcsec)**2;return 1.25*Math.log10(s*r*a)}static gainFor(e,t){const i=t.fieldOfViewDeg===void 0?void 0:Bt.focalLengthMmFor(e,t.fieldOfViewDeg);return vn.gainOverEye(e,{fNumber:t.fNumber,focalLengthMm:i,exposureSeconds:t.exposureSeconds})}}const Ob=111320,Bc=Math.PI/180,S6=1.02,E6=1;class ah{static of(e,t){const i=ah.sightings(e,t);if(i.length<2)return;const n=ah.baseline(i);if(!n)return;const{near:s,far:r,closedM:a}=n,l=Math.tan(r.widthDeg/2*Bc)===0?0:Math.tan(s.widthDeg/2*Bc)/Math.tan(r.widthDeg/2*Bc);if(l<S6)return;const c=a/(l-1),h=pt.sizeMAt(c,s.widthDeg),d=i.map(u=>({t:u.t,m:pt.distanceMAt(h,u.widthDeg)}));return{widthM:h,distanceM:d,nearestM:Math.min(...d.map(u=>u.m)),fromT:r.t,toT:s.t,closedM:a}}static sightings(e,t){return e.timeline.allKeyframes.flatMap(i=>{const n=i.shapes.find(a=>a.sourceId===t)?.shape,s=n?.angular?.widthDeg,r=at(e,i.t);return s===void 0||s<=0||r?.lat===void 0||r.lng===void 0?[]:[{t:i.t,widthDeg:s,lat:r.lat,lng:r.lng,sightAzimuthDeg:n?.aim?.azimuthDeg??r.headingDeg}]}).sort((i,n)=>i.t-n.t)}static baseline(e){let t;for(const i of e)for(const n of e){if(i.t>=n.t)continue;const s=ah.closedAlongSight(i,n),[r,a,l]=s>=0?[n,i,s]:[i,n,-s];l<E6||r.widthDeg<=a.widthDeg||(!t||l>t.closedM)&&(t={near:r,far:a,closedM:l})}return t}static closedAlongSight(e,t){const i=(t.lat-e.lat)*Ob,n=(t.lng-e.lng)*Ob*Math.cos(e.lat*Bc),s=(e.sightAzimuthDeg??0)*Bc;return i*Math.cos(s)+n*Math.sin(s)}}class Dn{static CONVENTIONAL_M=5;static NEAREST_M=.2;static MARGIN=1.1;static resolve(e){if(e.statedM!==void 0&&e.statedM>0)return{distanceM:Dn.atLeastNearest(e.statedM),basis:"stated"};if(e.hypothesisM!==void 0&&e.hypothesisM>0)return{distanceM:Dn.atLeastNearest(e.hypothesisM),basis:"hypothesis"};if(e.derivedM!==void 0&&e.derivedM>0)return{distanceM:Dn.atLeastNearest(e.derivedM),basis:"derived"};const t=Dn.largest(e.range?.minM,e.crossing?.behindM),i=Dn.smallest(e.range?.maxM,e.crossing?.inFrontM),n=t===void 0?void 0:t*Dn.MARGIN,s=i===void 0?void 0:i/Dn.MARGIN;return n!==void 0&&s!==void 0?{distanceM:Dn.atLeastNearest(n<=s?Math.sqrt(n*s):n),basis:"bounded"}:n!==void 0?{distanceM:Dn.atLeastNearest(n),basis:"bounded"}:s!==void 0&&s<Dn.CONVENTIONAL_M?{distanceM:Dn.atLeastNearest(s),basis:"bounded"}:{distanceM:Dn.CONVENTIONAL_M,basis:"conventional"}}static atLeastNearest(e){return Math.max(Dn.NEAREST_M,e)}static largest(...e){const t=e.filter(i=>i!==void 0&&i>0);return t.length===0?void 0:Math.max(...t)}static smallest(...e){const t=e.filter(i=>i!==void 0&&i>0);return t.length===0?void 0:Math.min(...t)}}const r0=Math.PI/180;class et{constructor(e,t,i){this.body=e,this.ground=t;const n=[...e.track].sort((s,r)=>s.t-r.t);this.keys=this.place(n,i);for(const s of n)et.collect(this.motionKeys,s.t,s.motions),et.collect(this.lightKeys,s.t,s.lights)}static EYE_HEIGHT_M=1.6;static MAX_RANGE_M=3e4;static DEFAULT_SIZE={widthM:1,lengthM:1,heightM:1};static DEFAULT_APPEARANCE={color:"#c8c8c8",albedo:.5,luminanceCdM2:0,transparency:0,haloScale:1};keys;motionKeys=new Map;lightKeys=new Map;static collect(e,t,i){for(const[n,s]of Object.entries(i??{})){const r=e.get(n)??[];r.push({t,value:s}),e.set(n,r)}}motionsAt(e){return et.channelsAt(this.motionKeys,e,0)}lightsAt(e){return this.lightKeys.size>0?et.channelsAt(this.lightKeys,e,void 0):void 0}static channelsAt(e,t,i){const n={};for(const[s,r]of e){let a=r.length-1;for(;a>=0&&r[a].t>t;)a--;if(a<0){i!==void 0&&(n[s]=i);continue}const l=r[a],c=r[Math.min(a+1,r.length-1)],h=c===l||c.t===l.t?0:Math.min(1,(t-l.t)/(c.t-l.t));n[s]=et.lerp(l.value,c.value,h)}return n}static eyeOf(e,t,i){const n=at(e,0),s=at(e,t),a=n?.lat!==void 0&&n.lng!==void 0&&s?.lat!==void 0&&s.lng!==void 0?vt(s.lat,s.lng,n.lat,n.lng):void 0,l=a?a.x:0,c=a?-a.z:0;return{eastM:l,northM:c,upM:i.heightAt(l,c)+et.EYE_HEIGHT_M+(s?.elevationM??0),headingDeg:s?.headingDeg}}static lineOfSightMeetsGround(e,t,i,n){const s=et.directionOf(t,i),r=c=>e.upM+s.upM*c-n.heightAt(e.eastM+s.eastM*c,e.northM+s.northM*c);let a=0,l=0;for(;l<et.MAX_RANGE_M;){if(l=a+Math.max(.5,a*.01),r(l)<=0){for(let c=0;c<30;c++){const h=(a+l)/2;r(h)<=0?l=h:a=h}return l}a=l}}static directionOf(e,t){const i=e*r0,n=t*r0;return{eastM:Math.sin(i)*Math.cos(n),northM:Math.cos(i)*Math.cos(n),upM:Math.sin(n)}}at(e){const t=this.keys;if(t.length===0||e<t[0].t)return;let i=t.length-1;for(;i>0&&t[i].t>e;)i--;const n=t[i];if(!n.present)return;const s=t[Math.min(i+1,t.length-1)],r=s===n||s.t===n.t?0:Math.min(1,(e-n.t)/(s.t-n.t)),a=et.lerp(n.eastM,s.eastM,r),l=et.lerp(n.northM,s.northM,r),c={widthM:et.lerp(n.sizeM.widthM,s.sizeM.widthM,r),lengthM:et.lerp(n.sizeM.lengthM,s.sizeM.lengthM,r),heightM:et.lerp(n.sizeM.heightM,s.sizeM.heightM,r)},h={headingDeg:et.lerpAngle(n.attitude.headingDeg,s.attitude.headingDeg,r),pitchDeg:et.lerp(n.attitude.pitchDeg,s.attitude.pitchDeg,r),rollDeg:et.lerp(n.attitude.rollDeg,s.attitude.rollDeg,r)};let d;if("aboveGroundM"in n.vertical&&"aboveGroundM"in s.vertical){const u=et.lerp(n.vertical.aboveGroundM,s.vertical.aboveGroundM,r);d=this.groundUnderFootprint(a,l,c,h.headingDeg)+u+c.heightM/2}else d=et.lerp(this.centreUpOf(n),this.centreUpOf(s),r);return{id:this.body.id,model:this.body.model,explains:this.body.explains??[],outlineNode:this.body.outlineNode,eastM:a,northM:l,upM:d,sizeM:c,attitude:h,appearance:{color:et.lerpColor(n.appearance.color,s.appearance.color,r),albedo:et.lerp(n.appearance.albedo,s.appearance.albedo,r),luminanceCdM2:et.lerp(n.appearance.luminanceCdM2,s.appearance.luminanceCdM2,r),transparency:et.lerp(n.appearance.transparency,s.appearance.transparency,r),haloScale:et.lerp(n.appearance.haloScale,s.appearance.haloScale,r)},flame:et.flameBetween(n.flame,s.flame,r),motions:this.motionsAt(e),lights:this.lightsAt(e),throwsFlame:this.body.track.some(u=>u.flame!==void 0&&u.flame.luminanceCdM2>0)}}static flameBetween(e,t,i){if(!e||e.luminanceCdM2<=0)return i>=1&&t&&t.luminanceCdM2>0?t:void 0;const n=e,s=t??e,r={...i<1?n:s,lengthM:et.lerp(n.lengthM,s.lengthM,i),widthM:et.lerp(n.widthM,s.widthM,i),luminanceCdM2:et.lerp(n.luminanceCdM2,s.luminanceCdM2,i)};return r.luminanceCdM2>0?r:void 0}centreUpOf(e){return"upM"in e.vertical?e.vertical.upM:this.groundUnderFootprint(e.eastM,e.northM,e.sizeM,e.attitude.headingDeg)+e.vertical.aboveGroundM+e.sizeM.heightM/2}groundUnderFootprint(e,t,i,n){const s=n*r0,r={eastM:Math.cos(s),northM:-Math.sin(s)},a={eastM:Math.sin(s),northM:Math.cos(s)};let l=this.ground.heightAt(e,t);for(const[c,h]of[[-1,-1],[1,-1],[-1,1],[1,1]]){const d=c*i.widthM/2,u=h*i.lengthM/2;l=Math.max(l,this.ground.heightAt(e+r.eastM*d+a.eastM*u,t+r.northM*d+a.northM*u))}return l}place(e,t){const i=[];let n;for(const s of e){const r=s.sizeM??n?.sizeM??et.DEFAULT_SIZE,a={headingDeg:s.attitude?.headingDeg??n?.attitude.headingDeg??0,pitchDeg:s.attitude?.pitchDeg??n?.attitude.pitchDeg??0,rollDeg:s.attitude?.rollDeg??n?.attitude.rollDeg??0},l={color:s.appearance?.color??n?.appearance.color??et.DEFAULT_APPEARANCE.color,albedo:s.appearance?.albedo??n?.appearance.albedo??et.DEFAULT_APPEARANCE.albedo,luminanceCdM2:s.appearance?.luminanceCdM2??n?.appearance.luminanceCdM2??et.DEFAULT_APPEARANCE.luminanceCdM2,transparency:s.appearance?.transparency??n?.appearance.transparency??et.DEFAULT_APPEARANCE.transparency,haloScale:s.appearance?.haloScale??n?.appearance.haloScale??et.DEFAULT_APPEARANCE.haloScale},c=this.positionOf(s,r,t)??(n&&{eastM:n.eastM,northM:n.northM,vertical:this.verticalOf(s,r)??n.vertical});if(!c)continue;const h=s.flame??n?.flame,d=s.present??n?.present??!0;n={t:s.t,...c,sizeM:r,attitude:a,appearance:l,flame:h,present:d},i.push(n)}return i}verticalOf(e,t){if(e.onGround)return{aboveGroundM:0};if(e.altitudeAboveGroundM!==void 0)return{aboveGroundM:e.altitudeAboveGroundM};if(e.altitudeM!==void 0)return{upM:e.altitudeM+t.heightM/2}}positionOf(e,t,i){if(e.eastM!==void 0&&e.northM!==void 0)return{eastM:e.eastM,northM:e.northM,vertical:this.verticalOf(e,t)??{aboveGroundM:0}};if(e.azimuthDeg===void 0||e.altitudeDeg===void 0)return;const n=i(e.t);if(!n)return;const s=e.distanceM??(e.onGround?et.lineOfSightMeetsGround(n,e.azimuthDeg,e.altitudeDeg,this.ground):void 0);if(s===void 0)return;const r=et.directionOf(e.azimuthDeg,e.altitudeDeg),a=n.eastM+r.eastM*s,l=n.northM+r.northM*s;return{eastM:a,northM:l,vertical:this.verticalOf(e,t)??{upM:n.upM+r.upM*s}}}static lerp(e,t,i){return e+(t-e)*i}static lerpColor(e,t,i){const n=et.rgbOf(e),s=et.rgbOf(t);return!n||!s?i<1?e:t:"#"+n.map((r,a)=>Math.round(et.lerp(r,s[a],i)).toString(16).padStart(2,"0")).join("")}static rgbOf(e){const t=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e);if(!t)return;const i=t[1].length===3?t[1].replace(/./g,"$&$&"):t[1];return[0,2,4].map(n=>parseInt(i.slice(n,n+2),16))}static lerpAngle(e,t,i){const n=((t-e)%360+540)%360-180;return((e+n*i)%360+360)%360}}class St{static A=6378137;static E2=.00669437999014;static DEG=Math.PI/180;static STANDARD_DISTANCE_KM=100;static DEFAULT_COLOR="#ffb347";static DEFAULT_TRAIN_S=1.5;static FADE_MS=600;static TRAIN_POINTS=8;static leadAt(e,t){const i=e.track;if(i.length<2||t<i[0].t||t>i[i.length-1].t)return;let n=0;for(;n<i.length-2&&i[n+1].t<t;)n++;const s=i[n],r=i[n+1],a=r.t-s.t,l=a>0?(t-s.t)/a:0,[c,h]=St.alongGreatCircle(s,r,l);return{lat:c,lng:h,heightM:(s.altitudeKm+(r.altitudeKm-s.altitudeKm)*l)*1e3}}static viewsAt(e,t,i){const n=[];for(const s of e){const r=s.track[0]?.t??0,a=s.track[s.track.length-1]?.t??0;s.fragments.forEach((l,c)=>{const h=l.fromT??r,d=l.untilT??a;if(t<h||t>d)return;const u=(l.lagS??0)*1e3,f=St.leadAt(s,t-u);if(!f)return;const p=St.seenFrom(i,f);if(p.altitudeDeg<0)return;const g=Math.min(St.FADE_MS,(d-h)/4),m=g>0?Math.min(1,(t-h)/g,(d-t)/g):1,v=-2.5*Math.log10(Math.max(m,.001)),b=l.absoluteMagnitude+5*Math.log10(p.distanceKm/St.STANDARD_DISTANCE_KM)+v,x=[p],y=(l.trainS??St.DEFAULT_TRAIN_S)*1e3;for(let w=1;w<=St.TRAIN_POINTS;w++){const S=Math.min(y*w/St.TRAIN_POINTS,t-h),A=St.leadAt(s,t-u-S);if(!A||(x.push(St.seenFrom(i,A)),S>=t-h))break}n.push({reentryId:s.id,fragmentId:l.id??String(c),head:p,magnitude:b,color:l.color??St.DEFAULT_COLOR,train:x})})}return n}static seenFrom(e,t){const i=St.ecef(e),n=St.ecef(t),s=n[0]-i[0],r=n[1]-i[1],a=n[2]-i[2],l=e.lat*St.DEG,c=e.lng*St.DEG,h=-Math.sin(c)*s+Math.cos(c)*r,d=-Math.sin(l)*Math.cos(c)*s-Math.sin(l)*Math.sin(c)*r+Math.cos(l)*a,u=Math.cos(l)*Math.cos(c)*s+Math.cos(l)*Math.sin(c)*r+Math.sin(l)*a,f=Math.hypot(h,d,u);return{altitudeDeg:Math.asin(u/f)/St.DEG,azimuthDeg:(Math.atan2(h,d)/St.DEG+360)%360,distanceKm:f/1e3}}static ecef(e){const t=e.lat*St.DEG,i=e.lng*St.DEG,n=Math.sin(t),s=St.A/Math.sqrt(1-St.E2*n*n);return[(s+e.heightM)*Math.cos(t)*Math.cos(i),(s+e.heightM)*Math.cos(t)*Math.sin(i),(s*(1-St.E2)+e.heightM)*n]}static alongGreatCircle(e,t,i){const n=h=>{const d=h.lat*St.DEG,u=h.lng*St.DEG;return[Math.cos(d)*Math.cos(u),Math.cos(d)*Math.sin(u),Math.sin(d)]},s=n(e),r=n(t),a=Math.max(-1,Math.min(1,s[0]*r[0]+s[1]*r[1]+s[2]*r[2])),l=Math.acos(a);let c;if(l<1e-12)c=s;else{const h=Math.sin((1-i)*l)/Math.sin(l),d=Math.sin(i*l)/Math.sin(l);c=[s[0]*h+r[0]*d,s[1]*h+r[1]*d,s[2]*h+r[2]*d]}return[Math.atan2(c[2],Math.hypot(c[0],c[1]))/St.DEG,Math.atan2(c[1],c[0])/St.DEG]}}class xt{static EARTH_RADIUS_KM=6371;static SHADOW_RADIUS_KM=xt.EARTH_RADIUS_KM+15;static PENUMBRA_KM=10;static SUN_ILLUMINANCE_LUX=127e3;static RAYLEIGH_PER_M=[58e-7,135e-7,331e-7];static SCALE_HEIGHT_M=8e3;static OZONE_GRAZING_DEPTH=[2.4,1.8,.24];static ANISOTROPY=.7;static ALBEDO=.99;static DEFAULTS={exhaustKgPerS:273,condensedShare:.1,particleRadiusUm:.5,expansionKmPerS:.15,initialRadiusKm:.5,lifetimeS:420,collarShare:.85,collarExpansionKmPerS:2.5,collarLifetimeS:20};static PROPELLANTS={"rp1-lox":{condensedShare:.1,particleRadiusUm:.5},"methane-lox":{condensedShare:.14,particleRadiusUm:.5},"hydrogen-lox":{condensedShare:.2,particleRadiusUm:.5},hypergolic:{condensedShare:.1,particleRadiusUm:.4},solid:{condensedShare:.33,particleRadiusUm:.8}};static G0=9.80665;static COLLAR_SPREAD_OF_EXHAUST_VELOCITY=.735;static plumeOf(e){const t={},i=e.vehicle?.engine;if(i){const n=i.specificImpulseS===void 0?void 0:i.specificImpulseS*xt.G0;i.thrustKN!==void 0&&n&&(t.exhaustKgPerS=i.thrustKN*1e3/n),n&&(t.collarExpansionKmPerS=n/1e3*xt.COLLAR_SPREAD_OF_EXHAUST_VELOCITY),i.propellant&&Object.assign(t,xt.PROPELLANTS[i.propellant])}return{...xt.DEFAULTS,...t,...e.plume}}static PUFF_EVERY_S=.5;static MAX_PUFFS=320;static DEG=Math.PI/180;static sunDirectionAt(e){const t=new Xr(0,0,-6378137),i=cc(de.Sun,e,t,!0,!0),n=(i.ra-Ww(e))*15*xt.DEG,s=i.dec*xt.DEG;return[Math.cos(s)*Math.cos(n),Math.cos(s)*Math.sin(n),Math.sin(s)]}static viewsAt(e,t,i,n){const s=[];for(const r of e){const a=xt.plumeOf(r),l=r.track[0]?.t??0,c=r.track[r.track.length-1]?.t??0,h=r.burnFromT??l,d=Math.min(r.burnUntilT??c,t);if(d<=h)continue;const u=Math.max(xt.PUFF_EVERY_S*1e3,(d-h)/xt.MAX_PUFFS),f=a.particleRadiusUm*1e-6,p=6/(4*917*f),g=a.exhaustKgPerS*(u/1e3)*a.condensedShare,m=[{share:1-a.collarShare,expansionKmPerS:a.expansionKmPerS,lifetimeS:a.lifetimeS},{share:a.collarShare,expansionKmPerS:a.collarExpansionKmPerS,lifetimeS:a.collarLifetimeS}];for(let v=d;v>=h;v-=u){const b=(t-v)/1e3;if(b>a.lifetimeS)break;const x=St.leadAt({id:r.id,track:r.track,fragments:[]},v);if(!x)continue;const y=St.seenFrom(i,x);if(y.altitudeDeg<0)continue;const w=xt.sunlightAt(x,n);if(w.lit<=0)continue;const S=St.leadAt({id:r.id,track:r.track,fragments:[]},Math.max(l,v-u)),A=S?xt.distanceKm(x,S):0,M=xt.scatteringPhase(i,x,n);for(const _ of m){if(_.share<=0||b>_.lifetimeS)continue;const I=a.initialRadiusKm+_.expansionKmPerS*b+A/2,R=3*g*_.share*p/(2*Math.PI*(I*1e3)**2),L=Math.max(0,1-(b/_.lifetimeS)**2),P=xt.SUN_ILLUMINANCE_LUX*xt.ALBEDO*M*R*L*w.lit;P<=0||s.push({launchId:r.id,centre:y,radiusDeg:Math.atan2(I,y.distanceKm)/xt.DEG,luminanceCdM2:P,sunTransmittance:w.transmittance,lit:w.lit,ageS:b})}}}return s}static sunlightAt(e,t){const i=xt.earthCentred(e),n=i[0]*t[0]+i[1]*t[1]+i[2]*t[2];if(n>=0)return{lit:1,transmittance:[1,1,1]};const s=Math.hypot(i[0]-n*t[0],i[1]-n*t[1],i[2]-n*t[2]),r=xt.PENUMBRA_KM,a=Math.min(1,Math.max(0,(s-(xt.SHADOW_RADIUS_KM-r/2))/r));if(a<=0)return{lit:0,transmittance:[0,0,0]};const l=Math.max(0,(s-xt.EARTH_RADIUS_KM)*1e3),c=Math.exp(-l/xt.SCALE_HEIGHT_M),h=Math.sqrt(2*Math.PI*xt.EARTH_RADIUS_KM*1e3*xt.SCALE_HEIGHT_M),d=Math.exp(-(((l/1e3-25)/15)**2)),u=[0,1,2].map(f=>Math.exp(-xt.RAYLEIGH_PER_M[f]*c*h-xt.OZONE_GRAZING_DEPTH[f]*d));return{lit:a,transmittance:u}}static scatteringPhase(e,t,i){const n=xt.earthCentred(e),s=xt.earthCentred(t),r=[n[0]-s[0],n[1]-s[1],n[2]-s[2]],a=Math.hypot(r[0],r[1],r[2])||1,l=-(r[0]*i[0]+r[1]*i[1]+r[2]*i[2])/a,c=xt.ANISOTROPY;return(1-c*c)/(4*Math.PI*(1+c*c-2*c*l)**1.5)}static distanceKm(e,t){const i=xt.earthCentred(e),n=xt.earthCentred(t);return Math.hypot(i[0]-n[0],i[1]-n[1],i[2]-n[2])}static earthCentred(e){const t=e.lat*xt.DEG,i=e.lng*xt.DEG,n=xt.EARTH_RADIUS_KM+e.heightM/1e3;return[n*Math.cos(t)*Math.cos(i),n*Math.cos(t)*Math.sin(i),n*Math.sin(t)]}}class qg{static FIRST_DAY="2022-01-01";static mayCover(e){return new Date(e).toISOString().slice(0,10)>=qg.FIRST_DAY}}class A6{constructor(e,t,i){this.citation=e,this.covers=t,this.load=i}loading;mayCover(e){return this.covers(e)}async between(e,t,i,n){try{return await(await this.provider()).between(e,t,i,n)}catch{return{status:"failed"}}}async describe(e,t){try{return await(await this.provider()).describe?.(e,t)}catch{return}}provider(){if(!this.loading){const e=this.load();this.loading=e,e.catch(()=>{this.loading===e&&(this.loading=void 0)})}return this.loading}}const _6="Aircraft positions: adsb.lol feeders and contributors, Open Database License 1.0 (https://www.adsb.lol/docs/open-data/historical/)",Ym=[{id:"adsb-lol",name:"adsb.lol",credit:"adsb.lol feeders and contributors, ODbL 1.0",creditUrl:"https://www.adsb.lol/docs/open-data/historical/",create:()=>new A6(_6,o=>qg.mayCover(o),async()=>new(await Ue(async()=>{const{AdsbLolArchiveProvider:o}=await import("./AdsbLolArchiveProvider-fy3504GB.js");return{AdsbLolArchiveProvider:o}},[],import.meta.url)).AdsbLolArchiveProvider)}];class Cn{static MAX_GAP_S=60;static FT_TO_M=.3048;static EARTH_RADIUS_KM=6371;static seenFrom(e,t,i){const n=Cn.positionAt(e,i);if(!n)return;const s=St.seenFrom(t,n.geo);if(!(s.altitudeDeg<0))return{track:e,sky:s,altitudeFt:n.altitudeFt,groundSpeedKt:n.groundSpeedKt,trackDeg:n.trackDeg,angularRateDegPerS:Cn.angularRate(e,t,i)}}static viewsAt(e,t,i){return e.flatMap(n=>Cn.seenFrom(n,t,i)??[])}static groundDistanceKm(e,t){const i=Math.PI/180,n=Math.sin((t.lat-e.lat)*i/2)**2+Math.cos(e.lat*i)*Math.cos(t.lat*i)*Math.sin((t.lng-e.lng)*i/2)**2;return 2*Cn.EARTH_RADIUS_KM*Math.asin(Math.min(1,Math.sqrt(n)))}static wrapLongitude(e){return((e+180)%360+360)%360-180}static positionAt(e,t){const i=e.points;if(i.length===0||t<i[0].t||t>i[i.length-1].t)return;let n=0;for(;n<i.length-1&&i[n+1].t<=t;)n++;const s=i[n],r=i[n+1]??s,a=r.t-s.t;if(a>Cn.MAX_GAP_S*1e3)return;const l=a>0?(t-s.t)/a:0,c=s.altitudeFt+(r.altitudeFt-s.altitudeFt)*l,h=(r.lng-s.lng+540)%360-180;return{geo:{lat:s.lat+(r.lat-s.lat)*l,lng:Cn.wrapLongitude(s.lng+h*l),heightM:c*Cn.FT_TO_M},altitudeFt:c,groundSpeedKt:s.groundSpeedKt,trackDeg:s.trackDeg}}static angularRate(e,t,i){const n=Cn.positionAt(e,i-500),s=Cn.positionAt(e,i+500);if(!n||!s)return;const r=Cn.unit(St.seenFrom(t,n.geo)),a=Cn.unit(St.seenFrom(t,s.geo)),l=Math.min(1,Math.max(-1,r[0]*a[0]+r[1]*a[1]+r[2]*a[2]));return Math.acos(l)*180/Math.PI}static unit(e){const t=e.altitudeDeg*Math.PI/180,i=e.azimuthDeg*Math.PI/180;return[Math.cos(t)*Math.sin(i),Math.cos(t)*Math.cos(i),Math.sin(t)]}}const Nb="https://ufoathome.org/fireballs/index.json";class Es{static FIRST_MONTH="2018-12";static STRIKING_MAGNITUDE=-1;static COLOR="#eef2ff";static TRAIN_S=.3;fetchImpl;indexUrls;index;months=new Map;constructor(e={}){this.fetchImpl=e.fetchImpl??fetch.bind(globalThis),this.indexUrls=e.indexUrls??Es.defaultIndexUrls()}static defaultIndexUrls(){const e=[];return typeof location<"u"&&/^https?:$/.test(location.protocol)&&e.push(new URL("/fireballs/index.json",location.href).href),e.includes(Nb)||e.push(Nb),e}static mayCover(e){return new Date(e).toISOString().slice(0,7)>=Es.FIRST_MONTH}async credit(){return(await this.loadIndex())?.index.credit}async between(e,t){if(!Es.mayCover(t))return;const i=await this.loadIndex();if(!i)return;const n=new Set([new Date(e).toISOString().slice(0,7),new Date(t).toISOString().slice(0,7)]);return[...n].some(r=>r>=i.index.from&&r<=i.index.to)?(await Promise.all([...n].filter(r=>i.index.months.includes(r)).map(r=>this.monthOf(r,i.base)))).flat().filter(r=>r.t>=e&&r.t<=t):void 0}static seenFrom(e,t){const i=Es.peakFraction(e),n={lat:e.from[0]+(e.to[0]-e.from[0])*i,lng:e.from[1]+(e.to[1]-e.from[1])*i,heightM:e.peakHeightKm*1e3},s=St.seenFrom(t,n);if(!(s.altitudeDeg<0))return{record:e,peak:s,magnitude:e.peakMagnitude+5*Math.log10(s.distanceKm/St.STANDARD_DISTANCE_KM)}}static asReentry(e,t){const i=e.t-t,n=i+Math.max(e.durationS,.1)*1e3;return{id:`gmn-${e.id}`,track:[{t:i,lat:e.from[0],lng:e.from[1],altitudeKm:e.from[2]},{t:n,lat:e.to[0],lng:e.to[1],altitudeKm:e.to[2]}],fragments:[{absoluteMagnitude:e.peakMagnitude,color:Es.COLOR,trainS:Es.TRAIN_S}]}}static peakFraction(e){const t=e.from[2]-e.to[2];return Math.abs(t)<1e-6?.5:Math.min(1,Math.max(0,(e.from[2]-e.peakHeightKm)/t))}loadIndex(){return this.index??=(async()=>{for(const e of this.indexUrls)try{const t=await this.fetchImpl(e);if(t.ok)return{index:await t.json(),base:e}}catch{}})(),this.index}monthOf(e,t){let i=this.months.get(e);return i||(i=this.fetchImpl(new URL(`${e}.json`,t).href).then(n=>n.ok?n.json():[]).catch(()=>[]),this.months.set(e,i)),i}}const vl=Math.PI/180,zc=180/Math.PI;class Ai{constructor(e){this.timeline=e}static DIRECTION_TOLERANCE_DEG=1;static SIZE_TOLERANCE=1.5;static RINGS=12;static SEGMENTS=24;at(e,t,i,n){const s=[];for(const r of t){const a=Ai.projectionOf(r,i,n?.(r));if(a)for(const l of r.explains){const c=this.timeline.getInterpolatedShapeAt(e,l);!c||c.transparency>=1||s.push({...Ai.compare(l,r.id,{aim:c.aim,angular:c.angular},a),title:c.title})}}return s}static compare(e,t,i,n){const s=[],r=i.aim?Ai.separationDeg(i.aim,n.aim):void 0;if(r!==void 0){const c=Math.max(i.angular?.widthDeg??0,n.angular.widthDeg)/2;r>Math.max(Ai.DIRECTION_TOLERANCE_DEG,c)&&s.push("direction")}const a=i.angular&&i.angular.widthDeg>0?n.angular.widthDeg/i.angular.widthDeg:void 0,l=i.angular&&i.angular.heightDeg>0?n.angular.heightDeg/i.angular.heightDeg:void 0;return a!==void 0&&!Ai.withinSize(a)&&s.push("width"),l!==void 0&&!Ai.withinSize(l)&&s.push("height"),{sourceId:e,bodyId:t,stated:i,predicted:n,separationDeg:r,widthRatio:a,heightRatio:l,disagreements:s}}static projectionOf(e,t,i){const n=i&&i.length>0?i:Ai.outlineOf(e),s=i&&i.length>0?Ai.centreOf(i):e,r=Ai.normalized({eastM:s.eastM-t.eastM,northM:s.northM-t.northM,upM:s.upM-t.upM});if(!r)return;const a=Ai.normalized({eastM:r.northM,northM:-r.eastM,upM:0})??{eastM:1,northM:0,upM:0},l=Ai.cross(a,r);let c=1/0,h=-1/0,d=1/0,u=-1/0;for(const f of n){const p={eastM:f.eastM-t.eastM,northM:f.northM-t.northM,upM:f.upM-t.upM},g=Ai.dot(p,r);if(g<=0)return;const m=Math.atan2(Ai.dot(p,a),g),v=Math.atan2(Ai.dot(p,l),g);c=Math.min(c,m),h=Math.max(h,m),d=Math.min(d,v),u=Math.max(u,v)}return{aim:{azimuthDeg:(Math.atan2(r.eastM,r.northM)*zc+360)%360,altitudeDeg:Math.asin(Math.max(-1,Math.min(1,r.upM)))*zc},angular:{widthDeg:(h-c)*zc,heightDeg:(u-d)*zc}}}static centreOf(e){const t=i=>(Math.min(...e.map(n=>n[i]))+Math.max(...e.map(n=>n[i])))/2;return{eastM:t("eastM"),northM:t("northM"),upM:t("upM")}}static separationDeg(e,t){const i=e.altitudeDeg*vl,n=t.altitudeDeg*vl,s=Math.sin(i)*Math.sin(n)+Math.cos(i)*Math.cos(n)*Math.cos((e.azimuthDeg-t.azimuthDeg)*vl);return Math.acos(Math.max(-1,Math.min(1,s)))*zc}static withinSize(e){return e<=Ai.SIZE_TOLERANCE&&e>=1/Ai.SIZE_TOLERANCE}static outlineOf(e){const t=e.sizeM.widthM/2,i=e.sizeM.lengthM/2,n=e.sizeM.heightM/2,s=[],r=e.model.url===void 0?e.model.id:void 0;if(r!==void 0&&r!=="box"&&v2.includes(r))for(let d=0;d<=Ai.RINGS;d++){const u=d/Ai.RINGS*Math.PI;for(let f=0;f<Ai.SEGMENTS;f++){const p=f/Ai.SEGMENTS*2*Math.PI;s.push([t*Math.sin(u)*Math.cos(p),i*Math.sin(u)*Math.sin(p),n*Math.cos(u)])}}else for(const d of[-t,t])for(const u of[-i,i])for(const f of[-n,n])s.push([d,u,f]);const l=e.attitude.headingDeg*vl,c=e.attitude.pitchDeg*vl,h=e.attitude.rollDeg*vl;return s.map(([d,u,f])=>{const p=d*Math.cos(h)+f*Math.sin(h),g=-d*Math.sin(h)+f*Math.cos(h),m=u*Math.cos(c)-g*Math.sin(c),v=u*Math.sin(c)+g*Math.cos(c);return{eastM:e.eastM+p*Math.cos(l)+m*Math.sin(l),northM:e.northM-p*Math.sin(l)+m*Math.cos(l),upM:e.upM+v}})}static dot(e,t){return e.eastM*t.eastM+e.northM*t.northM+e.upM*t.upM}static cross(e,t){return{eastM:e.northM*t.upM-e.upM*t.northM,northM:e.upM*t.eastM-e.eastM*t.upM,upM:e.eastM*t.northM-e.northM*t.eastM}}static normalized(e){const t=Math.hypot(e.eastM,e.northM,e.upM);return t>1e-9?{eastM:e.eastM/t,northM:e.northM/t,upM:e.upM/t}:void 0}}xf();const T6={sun:"Sun",moon:"Moon",Venus:"Venus",Mars:"Mars",Jupiter:"Jupiter",Saturn:"Saturn"},I6="{name} — mag {mag}, {alt}° above the horizon",D6="{name} — {size}, {distance} away",R6="{name} — satellite, mag {mag}, {height} km up",x2="satellites-change",S2="fireballs-change",C6="aircraft-change",k6="rr0-confrontation",P6="{name} — mag {mag}, {alt}° below the horizontal",a0="Credits",Fb="comet:",Ub="nova:",Bb={building:"Building",tree:"Tree",shrub:"Shrub",bridge:"Bridge",wire:"Overhead line",crop:"Crop row",terrace:"Terrace (restanque)",mound:"Stone heap",wall:"Dry-stone wall",streetlight:"Streetlight",vehicle:"Vehicle",observer:"Observer",aircraft:"Aircraft",entity:"Being"},L6=new URL(""+new URL("lunar-relief.bin-ByThqxUn.gz",import.meta.url).href,import.meta.url).href,O6=new URL(""+new URL("stars-mag7.5-B43R6Wvg.bin",import.meta.url).href,import.meta.url).href,N6=new URL(""+new URL("stars-mag7.5-9-BLV2tFmZ.bin",import.meta.url).href,import.meta.url).href,F6=-18,U6={sun:{altitudeDeg:-3,azimuthDeg:180,magnitude:-26.7},moon:{altitudeDeg:-90,azimuthDeg:0,phase:{phaseFraction:0,illuminatedFraction:0},magnitude:-12.7},planets:[]},Gd={lat:0,lng:0,elevationM:0,headingDeg:void 0,pitchDeg:0,fovDeg:60};class Vt extends HTMLElement{creditsButton;set ownCredits(e){this.creditsButton.hidden=!e}static get observedAttributes(){return["src","star-catalog-src","deep-star-catalog-src","show-compass","max-pixel-ratio",Bl,zl]}shadow;stageElement;frameElement;sceneCanvas;busyElement;busyNote;loaderNote;loaderNotVideo;ufoElement;sceneRenderer;hoverTooltip;holding=!1;resizeObserver;sizeEstimates=new Map;sizeEstimatesFor;distanceHypotheses=new Map;depths=new Map;directionScratch=new D;meteorScheduleFor;lightningScheduleFor;lightningFlashes=[];lastLightningT;lastTimeMs=0;interpretationShown;confrontationReadings=[];confrontationSignature="";comparing=!1;inTheRound=!0;lastSkyKey;starCatalog;starCatalogRequest=0;static tleArchive=new mn;satellitesFor;satelliteRequest=0;satelliteStatus="none";satellites;satellitePassesMemo;static fireballArchive=new Es;fireballs;static aircraftProviders=new Map;static SOUND_LOOKBACK_MS=3e5;static NO_CONTRAILS=[];static upperAirProviders=new Map;static NO_PRESENCE=new Map;aircraftSource=Ym[0];static trafficRuntimeLoading;static trafficRuntime;static loadTrafficRuntime(){return Vt.trafficRuntimeLoading??=Ue(()=>import("./trafficRuntime-j3m3LpCc.js"),__vite__mapDeps([2,1]),import.meta.url).then(e=>Vt.trafficRuntime=e),Vt.trafficRuntimeLoading.catch(()=>{Vt.trafficRuntimeLoading=void 0}),Vt.trafficRuntimeLoading}traffic;lastSun;decorMemo;seatedMemo;starCatalogDepth=0;weatherAudio=new M6;vehicleAudio=new rE;aircraftAudio;vehicleHearing=new Nu;decorAircraftHearing;decorModelSounds=new Map;thunderTimeoutId;handleFullscreenChange=()=>this.resizeToStage();handlePointerMove=e=>{if(this.sceneRenderer.setCompassHovered(!0),this.holding){this.hoverTooltip.hidden=!0;return}const t=this.ufoElement.canvasElement,i=t.getBoundingClientRect();if(i.width===0||i.height===0)return;const n=(e.clientX-i.left)/i.width*t.width,s=(e.clientY-i.top)/i.height*t.height;if(this.ufoElement.hasVisibleShapeAt(n,s)){this.hoverTooltip.hidden=!0;return}const r=(e.clientX-i.left)/i.width*2-1,a=-((e.clientY-i.top)/i.height*2-1),l=this.pickAt(r,a);l?this.showHoverTooltip(e,e.altKey&&l.detail?l.detail():l.name):this.hoverTooltip.hidden=!0};pickAt(e,t){const i=this.naming,n=i.names,s=this.sceneRenderer.pickBodyAt(e,t);if(s)return{kind:"sky",id:s,name:this.bodyName(s)};const r=this.interpretationShown?this.sceneRenderer.pickInterpretationBodyAt(e,t):void 0,a=r?this.interpretationShown?.bodies.find(p=>p.id===r):void 0,l=a?this.said.read(a.title)||(a.model.id==="figure"?i.decorKind("entity",Bb.entity):void 0):void 0;if(r!==void 0&&l)return{kind:"body",id:r,name:l};const c=this.pickDecorAt(e,t),h=c?this.ufoElement.sighting.decor.find(p=>p.id===c):void 0;if(h){const p=this.said.read(h.title)||i.decorKind(h.kind,Bb[h.kind]);return{kind:"decor",id:h.id,name:p,detail:()=>this.decorTooltip(h,p)}}const d=this.trafficTooltipAt(e,t);if(d)return{kind:"traffic",name:d};const u=this.sceneRenderer.pickSatelliteAt(e,t);if(u)return{kind:"satellite",name:(n?.satelliteTooltip??R6).replace("{name}",u.name).replace("{mag}",u.magnitude.toLocaleString(void 0,{maximumFractionDigits:1})).replace("{height}",Math.round(u.heightKm).toLocaleString())};const f=this.sceneRenderer.pickStarAt(e,t);if(f){const p=f.star.mag,g=f.altitudeDeg;return{kind:"star",name:(g<0?n?.starTooltipBelow??P6:n?.starTooltip??I6).replace("{name}",i.star(f.star)).replace("{mag}",p.toLocaleString(void 0,{maximumFractionDigits:Math.abs(p)<1?2:1})).replace("{alt}",String(Math.round(Math.abs(g))))}}}decorTooltip(e,t){const i=c=>c.toLocaleString(void 0,{maximumFractionDigits:c<10?1:0}),n=Fe.sizeOf(e),s=this.sceneRenderer.decorDistanceM(e.id),r=s===void 0?"":s>=1e3?`${(s/1e3).toLocaleString(void 0,{maximumFractionDigits:1})} km`:`${i(s)} m`;return(this.naming.names?.decorTooltip??D6).replace("{name}",t).replace("{size}",`${i(n.widthM)} × ${i(n.lengthM)} × ${i(n.heightM)} m`).replace("{distance}",r)}bodyName(e){const t=e.startsWith(Fb)?e.slice(Fb.length):void 0,i=t?w2.find(r=>r.id===t):void 0;if(i)return this.naming.comet(i);const n=e.startsWith(Ub)?cf.byId(e.slice(Ub.length)):void 0;if(n)return this.naming.nova(n);const s=T6[e];return s===void 0?e:this.naming.body(e,s)}get naming(){return this.sceneNaming}sceneNaming=new lf;namesLanguage="en";async loadSceneNames(){const e=ch(_s.preferencesFor(this),ph);if(e===this.namesLanguage)return;this.namesLanguage=e;const t=await xM(e);e===this.namesLanguage&&this.applySceneNaming(new lf(t))}setBusy(e,t=""){this.busyElement.hidden=!e,this.busyNote.textContent=e?t:"",this.busyElement.setAttribute("aria-label",t),this.busyElement.setAttribute("aria-busy",String(e))}renderLoaderText(e,t){let i=0;const n=(s,r)=>{s.setAttribute("aria-label",r),s.replaceChildren(),r.split(" ").forEach((a,l)=>{l>0&&s.append(" ");const c=document.createElement("span");c.className="scene-loader-word",c.setAttribute("aria-hidden","true");for(const h of a){const d=document.createElement("span");d.className="scene-loader-letter",d.style.setProperty("--i",String(i++)),d.textContent=h,c.append(d)}s.append(c),i++})};n(this.loaderNotVideo,e),i+=6,n(this.loaderNote,t)}applySceneNaming(e){this.sceneNaming=e;const t=e.names?.credits??a0;this.creditsButton.title=t,this.creditsButton.setAttribute("aria-label",t),e.names&&this.renderLoaderText(e.names.notAVideo,e.names.isASimulation),this.sceneRenderer.setCompassPoints(e.names?.compassPoints)}showHoverTooltip(e,t){this.hoverTooltip.textContent=t,this.hoverTooltip.hidden=!1;const i=this.stageElement.getBoundingClientRect();this.hoverTooltip.style.left=`${e.clientX-i.left+12}px`,this.hoverTooltip.style.top=`${e.clientY-i.top+12}px`}handlePointerLeave=()=>{this.hoverTooltip.hidden=!0,this.sceneRenderer.setCompassHovered(!1)};handleLightningFlash(e){clearTimeout(this.thunderTimeoutId),this.thunderTimeoutId=window.setTimeout(()=>this.weatherAudio.playThunder(),qi.thunderDelayMs(e))}handleFirstInteraction=()=>{this.weatherAudio.resume(),this.vehicleAudio.resume(),this.aircraftAudio?.resume(),!this.interacted&&(this.interacted=!0,this.setWeather(Bh(this.ufoElement.sighting,this.lastTimeMs)))};interacted=!1;applyLevel(){const e=this.ufoElement.level;this.weatherAudio.setLevel(e),this.vehicleAudio.setLevel(e),this.aircraftAudio?.setLevel(e)}handlePageGesture=()=>{this.ufoElement.playbackState==="playing"&&this.handleFirstInteraction()};unlockIfAlreadyActivated(){this.interacted||navigator.userActivation?.hasBeenActive&&this.handleFirstInteraction()}static GESTURES=["pointerdown","pointerup","touchend","click","keydown"];handleTimeUpdate=e=>{this.lastTimeMs=e.detail.time,this.syncAnimationsToPlayback(),this.updateAstronomy(this.lastTimeMs),this.ufoElement.playbackState==="playing"&&this.sceneRenderer.frame(performance.now()),this.ufoElement.repaintChrome()};syncAnimationsToPlayback(){const e=this.ufoElement.playbackState==="playing";this.sceneRenderer.setAnimationsRunning(e,e),this.weatherAudio.setPaused(!e),this.vehicleAudio.setPaused(!e),this.aircraftAudio?.setPaused(!e),e&&this.unlockIfAlreadyActivated(),e||clearTimeout(this.thunderTimeoutId)}constructor(){super(),this.shadow=this.attachShadow({mode:"open"});const e=document.createElement("template");e.innerHTML=`<style>${lE}</style>${oE}`,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 Je(this.sceneCanvas);const t=this.shadow.getElementById("scene-loader");this.loaderNote=this.shadow.getElementById("scene-loader-note"),this.loaderNotVideo=this.shadow.getElementById("scene-loader-not-video"),this.renderLoaderText("This is not a video","It is a real-time simulation."),this.busyElement=this.shadow.getElementById("scene-busy"),this.busyNote=this.shadow.getElementById("scene-busy-note"),this.sceneRenderer.onFirstFrameHold=s=>{t.hidden=!s,this.holding=s,s&&(this.hoverTooltip.hidden=!0),this.ufoElement.captionHeld=s,this.ufoElement.holdClock(s)},this.hoverTooltip=this.shadow.getElementById("hover-tooltip"),this.ufoElement=document.createElement(E0),this.ufoElement.classList.add("ufo-overlay"),this.ufoElement.paintsShapes=!1,this.forwardPlayerAttributes(),this.ufoElement.addEventListener("lookat",s=>this.lookToward(s.detail)),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.creditShownExternally=!0,this.creditsButton=this.shadow.getElementById("credits-button");const i=this.shadow.getElementById("credits-panel"),n=this.shadow.getElementById("credits-list");i.addEventListener("beforetoggle",s=>{s.newState==="open"&&qn.fill(n,this)}),this.creditsButton.title=a0,this.creditsButton.setAttribute("aria-label",a0),this.sceneRenderer.onMapSubjectBounds=s=>this.ufoElement.setMapSubjectBounds(s),this.ufoElement.addEventListener("timeupdate",this.handleTimeUpdate),this.ufoElement.seekPreviewPainter=(s,r)=>this.seekPreviewOf(r).paint(s,r),this.ufoElement.addEventListener("mutedchange",()=>this.applyLevel()),this.ufoElement.ambientSound=s=>s.vehicle!==void 0||s.decor.some(r=>r.engine!==void 0)||s.weatherTrack.allKeyframes.some(r=>r.weather.precipitationType!=="none"||r.weather.windSpeed>1),this.ufoElement.addEventListener("referenceview",s=>this.applyReferenceView(s.detail)),this.ufoElement.addEventListener("traceview",s=>this.sceneRenderer.setTracesShown(s.detail.shown)),this.ufoElement.canvasElement.addEventListener("pointermove",this.handlePointerMove),this.ufoElement.canvasElement.addEventListener("pointerleave",this.handlePointerLeave);for(const s of Vt.GESTURES)this.addEventListener(s,this.handleFirstInteraction,!0)}get said(){return this.saidTexts??=new Un(_s.preferencesFor(this))}saidTexts;traceLabelsFor;observerHeadlightsAt(e,t){const i=e.vehicle;return i?{setting:Ca.at(i.headlights??"auto",i.headlightKeyframes,t)??"auto",headingDeg:this.travelHeadingAt(e,t)}:void 0}travelHeadingAt(e,t){const i=at(e,t);if(!i)return 0;for(const n of[400,-400]){const s=at(e,t+n);if(!s||i.lat===void 0||i.lng===void 0||s.lat===void 0||s.lng===void 0)break;const r=vt(s.lat,s.lng,i.lat,i.lng);if(Math.hypot(r.x,r.z)<.8)continue;return(Math.atan2(r.x,-r.z)*180/Math.PI+(n<0?180:0)+360)%360}return i.headingDeg??0}routeCache;routeOf(e){const t=e.allKeyframes;if(this.routeCache?.track===e&&this.routeCache.count===t.length)return this.routeCache.route;const i=t.flatMap(s=>s.pose.lat!==void 0&&s.pose.lng!==void 0?[{lat:s.pose.lat,lng:s.pose.lng}]:[]),n=i.length>=2?i:void 0;return this.routeCache={track:e,count:t.length,route:n},n}traceLabels(e){const t=_s.preferencesFor(this).join();if(this.traceLabelsFor?.traces!==e||this.traceLabelsFor.language!==t){const i=new Map;for(const n of e){const s=this.said.read(n.title);s&&i.set(n.id,s)}this.traceLabelsFor={traces:e,language:t,labels:i}}return this.traceLabelsFor.labels}connectedCallback(){this.saidTexts=void 0,this.loadSceneNames(),this.sceneRenderer.restoreContext(),this.resizeToStage(),this.updateAstronomy(this.lastTimeMs),this.loadStars(),this.resizeObserver=new ResizeObserver(()=>this.resizeToStage()),this.resizeObserver.observe(this.frameElement),this.watchVisibility(),document.addEventListener("fullscreenchange",this.handleFullscreenChange);for(const t of Vt.GESTURES)document.addEventListener(t,this.handlePageGesture,!0);const e=this.getAttribute("src");e&&this.loadFromSrc(e)}watchVisibility(){this.visibilityObserver?.disconnect(),!(typeof IntersectionObserver>"u"||this.hasAttribute("always-live"))&&(this.visibilityObserver=new IntersectionObserver(e=>{if(e[e.length-1].isIntersecting){this.sceneRenderer.resume();return}this.ufoElement.pause(),this.sceneRenderer.suspend()},{rootMargin:"100px"}),this.visibilityObserver.observe(this))}visibilityObserver;disconnectedCallback(){this.visibilityObserver?.disconnect(),this.resizeObserver?.disconnect(),document.removeEventListener("fullscreenchange",this.handleFullscreenChange);for(const e of Vt.GESTURES)document.removeEventListener(e,this.handlePageGesture,!0);this.sceneRenderer.stopTwinkle(),clearTimeout(this.thunderTimeoutId),this.weatherAudio.dispose(),this.vehicleAudio.dispose(),this.aircraftAudio?.dispose(),this.seekPreview?.dispose(),this.seekPreview=void 0,queueMicrotask(()=>{this.isConnected||this.sceneRenderer.releaseContext()})}attributeChangedCallback(e,t,i){if(e==="src"&&i&&i!==t&&this.isConnected&&this.loadFromSrc(i),(e==="star-catalog-src"||e==="deep-star-catalog-src")&&i!==t&&this.isConnected&&this.loadStars(),e==="show-compass"&&i!==t&&this.sceneRenderer.setShowCompass(this.hasAttribute("show-compass")),e==="max-pixel-ratio"&&i!==t){const n=Number(i);this.sceneRenderer.setMaxPixelRatio(Number.isFinite(n)&&n>0?n:Math.min(window.devicePixelRatio||1,2))}(e===Bl||e===zl)&&i!==t&&this.forwardPlayerAttributes()}forwardPlayerAttributes(){for(const e of[Bl,zl]){const t=this.getAttribute(e);t===null?this.ufoElement.removeAttribute(e):this.ufoElement.setAttribute(e,t)}}setCompassForced(e){this.sceneRenderer.setCompassForced(e)}lookToward(e){const t=at(this.ufoElement.sighting,this.lastTimeMs);if(e.kind==="observer"||t?.lat===void 0||t.lng===void 0||t.headingDeg===void 0){this.setLookOffset(0,0);return}const{x:i,z:n}=vt(e.lat,e.lng,t.lat,t.lng);if(Math.hypot(i,n)<1)return this.setLookOffset(0,0);const s=(Math.atan2(i,-n)*180/Math.PI+360)%360;this.setLookOffset(((s-t.headingDeg)%360+540)%360-180,-t.pitchDeg)}setLookOffset(e,t){this.sceneRenderer.setLookOffset(e,t),this.ufoElement.setLookOffset(e,t),this.updateAstronomy(this.lastTimeMs)}setIndoorLook(e,t){this.sceneRenderer.setIndoorLook(e,t)}setCloudRendering(e){this.sceneRenderer.setCloudRendering(e)}setWeather(e){this.sceneRenderer.setWeather(e),this.weatherAudio.setAmbient(e.precipitationType,e.precipitationIntensity*(e.precipitationAmount??1),e.windSpeed)}pickCloudAt(e,t){return this.sceneRenderer.pickCloudAt(e,t)}cloudDirectionAt(e,t){return this.sceneRenderer.cloudDirectionAt(e,t)}pickDecorAt(e,t){return this.sceneRenderer.pickDecorAt(e,t)}decorScreenBox(e){return this.sceneRenderer.decorScreenBox(e)}decorGroundPointAt(e,t,i,n=0){return this.sceneRenderer.decorGroundPointAt(e,t,i,n)}decorMetresPerNdcY(e){return this.sceneRenderer.decorMetresPerNdcY(e)}decorGrabHeightAt(e,t,i){return this.sceneRenderer.decorGrabHeightAt(e,t,i)}bodyScreenBox(e){return this.sceneRenderer.bodyScreenBox(e)}pickPlacedBodyAt(e,t){return this.sceneRenderer.pickPlacedBodyAt(e,t)}resumeWeatherAudio(){this.weatherAudio.resume(),this.vehicleAudio.resume(),this.aircraftAudio?.resume()}async loadFromSrc(e){const t=lh.json(e);this.holdForNewScene(t);const i=await t;this.documentUrl=new URL(e,location.href).href,this.sightingData=i}holdForNewScene(e){this.sceneRenderer.holdForNewScene(e)}get documentUrl(){return this.sceneRenderer.documentUrl}set documentUrl(e){this.sceneRenderer.documentUrl=e}get sightingData(){return this.ufoElement.sightingData}set sightingData(e){this.ufoElement.sightingData=e,this.seekPreview?.recordingChanged(e),this.interpretationShown=this.inTheRound?this.ufoElement.sighting.interpretation:void 0,this.syncAccountHidden(),this.applyFrameFormat(),this.lastTimeMs=0,this.sceneRenderer.compileNextFrameOffThread(),this.updateAstronomy(0)}seekPreview;seekPreviewOf(e){const t=this.sceneCanvas.width>0&&this.sceneCanvas.height>0?this.sceneCanvas.width/this.sceneCanvas.height:1.7777777777777777,i=Math.round(e.width/t);return e.height!==i&&(e.height=i),this.seekPreview??=new of(this,()=>document.createElement(hf))}showAt(e){this.ufoElement.currentTime=e,this.framesAtAsk=this.sceneRenderer.framesDrawn}framesAtAsk=0;snapshotTo(e){if(this.sceneRenderer.frame(performance.now()),this.sceneRenderer.framesDrawn===this.framesAtAsk)return!1;const t=e.getContext("2d");return t?(t.imageSmoothingQuality="high",t.drawImage(this.sceneCanvas,0,0,e.width,e.height),!0):!1}referenceAspect(e){return this.sceneRenderer.referenceAspect(e)}screenPointOf(e){return this.sceneRenderer.screenPointOf(e)}directionAt(e,t){return this.sceneRenderer.directionAt(e,t)}referenceFailedToLoad(e){return this.sceneRenderer.referenceFailedToLoad(e)}applyReferenceView(e){this.sceneRenderer.setReferencesShown(e.shown);for(const t of this.ufoElement.sighting.references){const i=e.views?.[t.id];this.sceneRenderer.setReferenceView(t.id,{opacity:i?i.shown?i.opacity:0:e.opacity})}}get currentTerrainAttribution(){return this.sceneRenderer.currentTerrainAttribution}get currentRoadAttribution(){return this.sceneRenderer.currentRoadAttribution}setTerrainProviders(e){this.sceneRenderer.setTerrainProviders(e)}setDecorModelProvider(e){this.sceneRenderer.setDecorModelProvider(e)}get decorModelCredits(){return[...new Map(this.sceneRenderer.currentDecorModelCredits.map(t=>[`${t.title}|${t.author??""}|${t.license}|${t.sourceUrl??""}`,t])).values()]}applyFrameFormat(){const e=this.ufoElement.sighting.instrument,t=pt.CANVAS_HEIGHT_PX,i=Bt.frameWidthPx(e,t);this.frameElement.style.setProperty("--frame-aspect",`${i} / ${t}`)}resizeToStage(){const e=this.frameElement.getBoundingClientRect(),t=Math.max(1,Math.round(e.width)),i=Math.max(1,Math.round(e.height));this.sceneCanvas.width=t,this.sceneCanvas.height=i,this.sceneRenderer.resize(t,i)}async loadStars(){const e=[{magnitudeLimit:n0,url:this.getAttribute("star-catalog-src")??O6},{magnitudeLimit:sh,url:this.getAttribute("deep-star-catalog-src")??N6}],t=this.instrumentReach(),i=++this.starCatalogRequest;this.starCatalogDepth=t>n0?sh:n0;const n=await rr.upTo(e,t);i===this.starCatalogRequest&&(this.starCatalog=n,this.sceneRenderer.compileNextFrameOffThread(),this.updateAstronomy(this.lastTimeMs))}ensureStarsDeepEnough(){!this.starCatalog||this.starCatalogDepth>=sh||this.instrumentReach()<=this.starCatalogDepth||this.loadStars()}instrumentReach(){const e=this.ufoElement.sighting,t=vn.gainFor(e.instrument,{fNumber:at(e,0)?.fNumber,fieldOfViewDeg:ji.fovOf(e,0),exposureSeconds:e.exposure});return Aa(F6,t)}updateAstronomy(e){this.ensureStarsDeepEnough(),this.applySceneAt(e);const t=Fs.windowEndingAt(e,this.exposureSeconds()),i=t.seconds,n=this.degreesPerPixelAt(e),s=Po.instants(i,n),r=Math.max(s,this.ufoElement.exposureTimes(e).length,Fs.instants(this.decorWithTraffic(this.ufoElement.sighting),at(this.ufoElement.sighting,e)?.elevationM??0,t.fromMs,i,n));if(r<=1){this.sceneRenderer.setExposure(1);return}this.sceneRenderer.setExposure(r,a=>this.applySceneAt(t.fromMs+t.ms*a/(r-1),{sky:Math.floor(a*s/r)!==Math.floor((a-1)*s/r),stepMs:t.ms/r}))}exposureSeconds(){return this.ufoElement.sighting.exposure??0}degreesPerPixelAt(e){const t=this.sceneCanvas.height;return t<=0?0:ji.fovOf(this.ufoElement.sighting,e)/t}roadGradeAt(e,t){return e.observerTrack.allKeyframes.length<2?0:_l.at(e,t,this.sceneRenderer.bodyGround)}get roadGradeDeg(){return this.roadGradeAt(this.ufoElement.sighting,this.ufoElement.currentTime)}applySceneAt(e,t){const i=this.ufoElement.sighting;this.setWeather(Bh(i,e)),this.sceneRenderer.setInstrument(i.instrument),this.sceneRenderer.setLightPollution(i.lightPollution),t||this.vehicleAudio.setVoices(this.vehicleHearing.at(i,e)),t||this.pushAircraftSound(i,e),this.updateMeteorShower(i,e),this.updateLightning(i,e,t!==void 0),this.sceneRenderer.setDecor(this.seatedDecor(this.decorWithTraffic(i),e)),this.sceneRenderer.setDecorPresence(this.traffic?.set?.presence??Vt.NO_PRESENCE),this.sceneRenderer.setDecorSunlight(this.trafficSunlight(e)),this.sceneRenderer.setContrails(this.traffic?.contrails??Vt.NO_CONTRAILS),this.sceneRenderer.setContrailSunlight(this.contrailSunlight(e));const n=at(i,e);this.sceneRenderer.setReferences(i.references,n?.lat!==void 0&&n.lng!==void 0?{lat:n.lat,lng:n.lng}:void 0);const s=at(i,0),r=Li(i,0),a=ds(i.event.time??{},n?.lng??Gd.lng,i.event.utcOffsetHours),l=i.weatherSource!==void 0&&a?iS(a):void 0,c=Object.fromEntries(Ta(Li(i,e)).map(I=>[I.id,Ru(e,i.weatherTrack,r,s,n,I.id,I.instances?.length?void 0:l)]));this.sceneRenderer.setCloudOffset(Ru(e,i.weatherTrack,r,s,n,void 0,l),c),this.sceneRenderer.setObserverPose(n?{...n,pitchDeg:n.pitchDeg+this.roadGradeAt(i,e)}:Gd),this.sceneRenderer.setLensOptics(this.lensOpticsAt(e)),this.sceneRenderer.setInstrumentGain(vn.gainFor(i.instrument,{fNumber:n?.fNumber,fieldOfViewDeg:ji.fovOf(i,e),exposureSeconds:i.exposure}),i.instrument.detailUm!==void 0,Pi.byId(n?.filter).opticalDensity),this.sceneRenderer.setMedium(i.instrument.medium,i.exposure,n?.fNumber??i.instrument.fNumber,i.iso),this.sceneRenderer.setGait($t.bodyAt(i,e,this.ufoElement.steadyBody)),this.sceneRenderer.updateDecorAnchoring(at(i,0),n,e),this.placeBodiesAt(e,t===void 0),this.sceneRenderer.updateDecorLitState(e,t?.stepMs??0),this.sceneRenderer.setObserverRoute(this.routeOf(i.observerTrack)),this.sceneRenderer.setObserverHeadlights(this.observerHeadlightsAt(i,e)),this.sceneRenderer.setTerrainOrigin(n?.lat,n?.lng,()=>{this.placeBodiesAt(this.lastTimeMs,!0),this.sceneRenderer.render()}),this.sceneRenderer.setStatedRoads(i.roads),this.sceneRenderer.setTraces(i.traces,this.traceLabels(i.traces)),this.pushPhenomenaAt(e);const h=n?.lat??Gd.lat,d=n?.lng??Gd.lng,u=ds(i.event.time??{},d,i.event.utcOffsetHours),f={lat:h,lng:d,elevationM:n?.elevationM??0};this.pushSatellitesAt(u,e,f),this.ensureFireballs(u);const p=[...this.interpretationShown?.reentries??[],...this.fireballs?.reentries??[]];this.sceneRenderer.setReentries(p.length===0?[]:St.viewsAt(p,e,{lat:h,lng:d,heightM:f.elevationM}));const g=this.interpretationShown?.launches??[];if(this.sceneRenderer.setLaunchPlumes(g.length===0||!u?[]:xt.viewsAt(g,e,{lat:h,lng:d,heightM:f.elevationM},xt.sunDirectionAt(new Date(u.getTime()+e)))),t&&!t.sky)return;if(!u){this.sceneRenderer.setAstronomy(U6);return}const m=new Date(u.getTime()+e),v=Math.max(1,Math.round(.25*this.degreesPerPixelAt(e)/Po.DEG_PER_SECOND*1e3)),b=Math.max(1e-8,this.degreesPerPixelAt(e)*.1),x=`${Math.floor(m.getTime()/v)}|${Math.round(h/b)}|${Math.round(d/b)}|${Math.round(f.elevationM)}|${this.starCatalog?this.starCatalogDepth:0}`;if(x===this.lastSkyKey){this.sceneRenderer.render();return}this.lastSkyKey=x;const y=Ki("Sun",m,f),w=Ki("Moon",m,f);let S=_i.separationOf(y,w)<1?_i.viewAt(m,f):void 0;if(S){const I=_i.offsetOf(y,w,S.separationDeg);if(S.obscuration>Vt.LIMB_FROM_OBSCURATION){const R=this.limbFor(m,f);R&&(S={...S,obscuration:1-ws.uncoveredFraction(R,S.sunRadiusDeg,I),limb:R})}S={...S,horizonShare:_i.horizonShare(S,I,y.altitudeDeg,y.azimuthDeg,Sn.distanceKm(m,f))}}const A={...y,magnitude:kp("Sun",m)-2.5*Math.log10(_i.beamFraction(S))};this.lastSun={altitudeDeg:A.altitudeDeg,azimuthDeg:A.azimuthDeg};const M={...w,phase:io(m),magnitude:kp("Moon",m),radiusDeg:Sn.apparentRadiusDeg(m,f)},_=t4.map(I=>({body:I,position:Ki(I,m,f),magnitude:kp(I,m)}));this.sceneRenderer.setAstronomy({sun:A,moon:M,planets:_,comet:this.cometAt(m,f),novae:cf.appearancesAt(m,f).map(({outburst:I,position:R,magnitude:L})=>({id:I.id,position:R,magnitude:L})),stars:this.starCatalog?{catalog:this.starCatalog,date:m,observer:f}:void 0,frame:{date:m,observer:f},localHour:((m.getUTCHours()+m.getUTCMinutes()/60+(i.event.utcOffsetHours??Math.round(d/15)))%24+24)%24,eclipse:S}),this.ufoElement.setSunAltitude(A.altitudeDeg)}static LIMB_FROM_OBSCURATION=.98;limbRelief;limbRequested=!1;limbCache;limbFor(e,t){if(!this.limbRelief){this.limbRequested||(this.limbRequested=!0,rh.load(L6).then(s=>{this.limbRelief=s,this.lastSkyKey="",s&&this.isConnected&&this.updateAstronomy(this.lastTimeMs)}));return}const i=this.limbCache;if(i&&Math.abs(e.getTime()-i.atMs)<5e3&&i.lat===t.lat&&i.lng===t.lng&&i.elevationM===t.elevationM)return i.profile;const n=ws.profile(e,t,this.limbRelief);return this.limbCache={profile:n,atMs:e.getTime(),lat:t.lat,lng:t.lng,elevationM:t.elevationM},n}pushSatellitesAt(e,t,i){if(this.ensureSatellites(e),!e||!this.satellites){this.sceneRenderer.setSatellites([]);return}const n=new Date(e.getTime()+t),s=[];for(const r of this.satellites.passes.positionsAt(n,i,-1))r.magnitude!==void 0&&s.push({norad:r.object.norad,name:r.object.name,position:{altitudeDeg:r.altitudeDeg,azimuthDeg:r.azimuthDeg},magnitude:r.magnitude,heightKm:r.heightKm});this.sceneRenderer.setSatellites(s)}ensureFireballs(e){const t=this.ufoElement.sighting,i=Math.max((t.event.durationSeconds??0)*1e3,this.ufoElement.seekableDuration),n=e?.getTime(),s=n===void 0?"":`${n}+${i}`;if(this.fireballs?.key===s)return;if(n===void 0||!Es.mayCover(n+i)){this.fireballs={key:s,status:"outside",reentries:[]};return}const r={key:s,status:"loading",reentries:[]};this.fireballs=r,Vt.fireballArchive.between(n,n+i).then(a=>{r.status=a?"ready":"unavailable",r.records=a??[],r.reentries=r.records.map(l=>Es.asReentry(l,n)),!(this.fireballs!==r||!this.isConnected)&&(this.dispatchEvent(new CustomEvent(S2)),r.reentries.length>0&&this.updateAstronomy(this.lastTimeMs))})}decorWithTraffic(e){const t=this.ensureTraffic(e);if(!t||t.objects.length===0)return e.decor;const i=this.decorMemo;if(i&&i.base===e.decor&&i.traffic===t.objects)return i.merged;const n=[...e.decor,...t.objects];return this.decorMemo={base:e.decor,traffic:t.objects,merged:n},n}seatedDecor(e,t){if(!e.some(r=>r.observerKeyframes?.length))return e;const i=e.map(r=>{if(!r.observerKeyframes?.length)return"";const a=kv(r,t);return`${a.side??"-"}/${a.facing??"-"}`}).join("|"),n=this.seatedMemo;if(n&&n.base===e&&n.seats===i)return n.seated;const s=e.map(r=>{if(!r.observerKeyframes?.length)return r;const a=kv(r,t);return{...r,observerSide:a.side,observerFacing:a.facing}});return this.seatedMemo={base:e,seats:i,seated:s},s}ensureTraffic(e){const t=at(e,0),i=t?.lng===void 0?void 0:ds(e.event.time??{},t.lng,e.event.utcOffsetHours),n=Math.max((e.event.durationSeconds??0)*1e3,this.ufoElement.seekableDuration),s=i?.getTime(),r=s===void 0||t?.lat===void 0||t.lng===void 0?"":`${this.aircraftSource.id}|${s}+${n}|${t.lat.toFixed(3)},${t.lng.toFixed(3)}|${Math.round(t.elevationM??0)}`;if(this.traffic?.key===r)return this.traffic.set;if(r===""||s===void 0||t?.lat===void 0||t.lng===void 0){this.traffic={key:r,status:"outside"};return}let a=Vt.aircraftProviders.get(this.aircraftSource.id);if(a||Vt.aircraftProviders.set(this.aircraftSource.id,a=this.aircraftSource.create()),a.mayCover&&!a.mayCover(s+n)){this.traffic={key:r,status:"outside"};return}const l={key:r,status:"loading",startMs:s,observer:{lat:t.lat,lng:t.lng}};this.traffic=l;const c={lat:t.lat,lng:t.lng,heightM:t.elevationM??0},h=Cn.MAX_GAP_S*1e3,d=Vt.SOUND_LOOKBACK_MS,u={lat:t.lat,lng:t.lng,elevationM:t.elevationM??0},f=(p,g)=>p.TrafficDecor.from(l.tracks??[],c,s,p.TrafficDecor.MAX_OBJECTS,{models:g,sunElevationAt:m=>this.sunElevationAt(m,u)});a.between(c,s-d,s+n+h).then(async p=>{if(this.traffic!==l)return;if(p.status!=="found"){l.status=p.status==="outside"?"outside":"unavailable",this.announceTraffic();return}let g;try{g=await Vt.loadTrafficRuntime()}catch{this.traffic===l&&(l.status="unavailable",this.announceTraffic());return}this.traffic===l&&(l.status="ready",l.tracks=p.tracks,l.set=f(g),this.startAircraftSound(l,g),this.announceTraffic(),this.describeTraffic(a,l,g,f),l.set.shown>0&&this.readUpperAir(l,g,s-d,s+n+h))})}trafficSunlight(e){const t=new Map,i=this.traffic,n=i?.set,s=this.lastSun;if(!n||!s||i.startMs===void 0||!i.observer)return t;for(const[r,a]of n.presence){if(e<a.fromMs||e>a.untilMs)continue;const l=n.flights.get(r),c=l?Cn.positionAt(l,i.startMs+e):void 0;c&&t.set(r,{heightM:c.geo.heightM,sunElevationDeg:Fn.sunElevationDeg(s,i.observer,c.geo)})}return t}trafficTooltipAt(e,t){const i=this.sceneRenderer.pickTrafficAt(e,t),n=i?this.trafficInfoAt(i):void 0;if(!n)return;const s=this.naming,r=Vt.trafficRuntime;return r?.TrafficTooltip.text(n,s.names?.trafficTooltip??r.TrafficTooltip.ENGLISH,a=>s.towards(a))}trafficInfoAt(e){const t=this.traffic,i=t?.set?.flights.get(e);if(!t||!i||t.startMs===void 0||!t.observer)return;const n=Vt.trafficRuntime;if(!n)return;const s=t.descriptions?.get(Ss.keyOf(i)),r=at(this.ufoElement.sighting,this.lastTimeMs),a={lat:t.observer.lat,lng:t.observer.lng,heightM:r?.elevationM??0},l=n.AmbientNoise.dbA(Bh(this.ufoElement.sighting,this.lastTimeMs)),c=n.TrafficInfos.at(i,s,a,t.startMs+this.lastTimeMs,{ambientDbA:l}),h=c&&this.contrailAt(e,this.lastTimeMs);return c&&h?{...c,contrail:h}:c}contrailAt(e,t){const i=this.traffic?.contrails?.find(s=>s.id===e);if(!i)return;let n;for(const s of i.points){if(s.tMs>t)break;n=s}return n?.forms?{persistent:n.persistent,iceRelativeHumidity:n.iceRelativeHumidity}:void 0}startAircraftSound(e,t){this.aircraftAudio??=this.newAircraftAudio(t),this.sortOutAudible(e,t)}sortOutAudible(e,t){!e.set||!e.observer||(e.audible=t.TrafficSound.candidates(e.set.flights,e.descriptions??new Map,Ss.keyOf,{...e.observer,heightM:0},{ambientDbA:t.AmbientNoise.BASE_DB_A}))}pushAircraftSound(e,t){this.startDecorAircraftSound(e);const i=this.aircraftAudio;if(!i)return;const n=Vt.trafficRuntime;if(!n){i.setVoices([]);return}const s=at(e,t),r=Bh(e,t),a={ambientDbA:n.AmbientNoise.dbA(r),referenceAmplitude:n.AmbientNoise.referenceAmplitude(r)},l=this.trafficVoices(t,s,a,n),c=e.event.place?.[0],h={lat:s?.lat??c?.lat,lng:s?.lng??c?.lng};h.lat!==void 0&&h.lng!==void 0&&(this.decorAircraftHearing??=new n.DecorAircraftHearing,l.push(...this.decorAircraftHearing.voices(e,t,{lat:h.lat,lng:h.lng,heightM:s?.elevationM??0},a,d=>this.decorModelSounds.get(d.model?.id??""))),l.sort((d,u)=>u.levelDbA-d.levelDbA),l.length=Math.min(l.length,4)),i.setVoices(l,s?.headingDeg??0)}trafficVoices(e,t,i,n){const s=this.traffic,r=s?.set;if(!s||!r||!s.audible||s.startMs===void 0||!s.observer)return[];const a={lat:s.observer.lat,lng:s.observer.lng,heightM:t?.elevationM??0};return n.TrafficSound.voices(s.audible,r.flights,s.descriptions??new Map,Ss.keyOf,a,s.startMs+e,i)}startDecorAircraftSound(e){const t=e.decor.filter(i=>i.kind==="aircraft"&&i.track?.some(n=>(n.altitudeM??0)>0));if(t.length!==0){for(const i of t){const n=i.model?.id;!n||i.model?.url!==void 0||this.decorModelSounds.has(n)||(this.decorModelSounds.set(n,void 0),this.sceneRenderer.entryOfDecorModel(n).then(s=>{this.decorModelSounds.set(n,s?.parameters?.sound)}))}if(this.aircraftAudio||Vt.trafficRuntime){!this.aircraftAudio&&Vt.trafficRuntime&&(this.aircraftAudio=this.newAircraftAudio(Vt.trafficRuntime));return}Vt.loadTrafficRuntime().catch(()=>{})}}newAircraftAudio(e){const t=new e.AircraftAudio;return t.setLevel(this.ufoElement.level),this.interacted&&t.resume(),t.setPaused(this.ufoElement.playbackState!=="playing"),t}announceTraffic(){this.isConnected&&(this.dispatchEvent(new CustomEvent(C6)),this.updateAstronomy(this.lastTimeMs))}async describeTraffic(e,t,i,n){if(!e.describe||!t.set||!t.tracks)return;const s=new Set([...t.set.flights.values()].map(c=>Ss.keyOf(c))),r=t.tracks.filter(c=>s.has(Ss.keyOf(c))&&c.points.length>0),a=new Map,l=new Map;await Promise.all(r.map(async c=>{const h=new Date(c.points[0].t).toISOString().slice(0,10),d=await e.describe(c,h).catch(()=>{});d&&(l.set(Ss.keyOf(c),d),a.set(Ss.keyOf(c),i.AircraftModels.of(d)))})),!(this.traffic!==t||a.size===0)&&(t.descriptions=l,t.models=a,t.set=n(i,a),this.planContrails(t,i),this.sortOutAudible(t,i),this.announceTraffic())}async readUpperAir(e,t,i,n){if(!e.observer)return;const s=this.upperAirSource??t.UPPER_AIR_SOURCES[0];let r=Vt.upperAirProviders.get(s.id);r||Vt.upperAirProviders.set(s.id,r=s.create());const a=await r.between(e.observer,i,n);this.traffic!==e||a.status!=="found"||(e.air=a.samples,e.airSource=a.source,this.planContrails(e,t),this.announceTraffic())}planContrails(e,t){!e.set||!e.air||e.startMs===void 0||(e.contrails=t.AircraftContrails.plan(e.set,e.models,e.air,e.startMs))}contrailSunlight(e){const t=new Map,i=this.traffic,n=i?.set,s=this.lastSun;if(!n||!s||!i.contrails?.length||i.startMs===void 0||!i.observer)return t;for(const r of i.contrails){const a=n.presence.get(r.id),l=n.flights.get(r.id);if(!a||!l)continue;const c=Cn.positionAt(l,i.startMs+Math.min(a.untilMs,Math.max(a.fromMs,e)));c&&t.set(r.id,{heightM:c.geo.heightM,sunElevationDeg:Fn.sunElevationDeg(s,i.observer,c.geo)})}return t}sunElevationAt(e,t){const i=Ki("Sun",new Date(e.t),t);return Fn.sunElevationDeg(i,t,e)}upperAirSource;setUpperAirSource(e){e.id!==this.upperAirSource?.id&&(this.upperAirSource=e,this.traffic=void 0,this.decorMemo=void 0,this.updateAstronomy(this.lastTimeMs))}setAircraftSource(e){e.id!==this.aircraftSource.id&&(this.aircraftSource=e,this.traffic=void 0,this.decorMemo=void 0,this.updateAstronomy(this.lastTimeMs))}get aircraftState(){const e=this.traffic?.contrails?.length?this.upperAirSource??Vt.trafficRuntime?.UPPER_AIR_SOURCES[0]:void 0;return{trailCredit:e&&{credit:e.credit,creditUrl:e.creditUrl},status:this.traffic?.status??"none",total:this.traffic?.set?.total??0,shown:this.traffic?.set?.shown??0,credit:this.aircraftSource.credit,creditUrl:this.aircraftSource.creditUrl}}get fireballState(){return{status:this.fireballs?.status??"none",records:this.fireballs?.records??[]}}ensureSatellites(e){const t=e?String(e.getTime()):"";if(t===this.satellitesFor)return;this.satellitesFor=t,this.satellites=void 0,this.satellitePassesMemo=void 0;const i=++this.satelliteRequest;if(!e){this.satelliteStatus="none";return}this.satelliteStatus="loading";const n=r=>{i===this.satelliteRequest&&(this.satelliteStatus=r,this.isConnected&&this.dispatchEvent(new CustomEvent(x2)))},s=Vt.tleArchive;(async()=>{if(!await s.covers(e))return n("outside");const[r,a]=await Promise.all([s.at(e),Ue(()=>import("./SatellitePasses-Pfro2-0Z.js"),[],import.meta.url)]);if(i===this.satelliteRequest){if(!r)return n("unavailable");this.satellites={snapshot:r,passes:new a.SatellitePasses(r.objects)},n("ready"),this.isConnected&&this.updateAstronomy(this.lastTimeMs)}})().catch(()=>n("unavailable"))}get satelliteState(){const e=this.satellites?.snapshot;return{status:this.satelliteStatus,coverage:e?.coverage,credit:e?.credit,creditUrl:e?.creditUrl}}satellitePassesDuring(e){const t=this.satellites,i=this.ufoElement.sighting,n=at(i,0),s=i.event.place?.[0],r=n?.lat??s?.lat,a=n?.lng??s?.lng;if(!t||r===void 0||a===void 0)return[];const l=ds(i.event.time??{},a,i.event.utcOffsetHours);if(!l)return[];const c=Math.min(Math.max(e,0),4*36e5),h={lat:r,lng:a,elevationM:n?.elevationM??0},d=JSON.stringify([this.satellitesFor,l.getTime(),r,a,h.elevationM,c]);if(this.satellitePassesMemo?.key===d)return this.satellitePassesMemo.passes;const u=Math.max(10,Math.ceil(c/1e3/600)),f=t.passes.passesDuring(l,new Date(l.getTime()+c),h,u);return this.satellitePassesMemo={key:d,passes:f},f}cometAt(e,t){const i=ou.brightestAt(e,t);if(i)return{id:i.apparition.id,position:i.position,tailEnd:i.tailEnd,magnitude:i.magnitude}}pushPhenomenaAt(e){const t=this.ufoElement.sighting;t!==this.sizeEstimatesFor&&(this.sizeEstimates.clear(),this.distanceHypotheses.clear(),this.sizeEstimatesFor=t);const i=t.timeline,n=this.ufoElement.canvasElement,s=this.ufoElement.frameShiftPx,r=this.projectionAt(e),a=new Map,l=new Map,c=new Set;for(const p of i.sourceIds){const g=i.getInterpolatedShapeAt(e,p);if(!g)continue;const m={...g,bounds:{...g.bounds,x:g.bounds.x+s.x,y:g.bounds.y+s.y}};a.set(p,m);const v=g.aim?this.sceneRenderer.screenPointOf(Ls.directionOf(g.aim,this.directionScratch)):{ndcX:(m.bounds.x+m.bounds.width/2)/n.width*2-1,ndcY:-((m.bounds.y+m.bounds.height/2)/n.height*2-1)},b=v!==void 0&&Math.abs(v.ndcX)<=1&&Math.abs(v.ndcY)<=1,x=b?this.sceneRenderer.decorDistancesAt(v.ndcX,v.ndcY,p):{};c.add(p),(b||g.aim)&&c.delete(p);const y=g.angular?.widthDeg??r.pxToDeg(g.bounds.width),w=this.sizeEstimateOf(p);w.add(y,x);const S=ah.of(t,p);l.set(p,Dn.resolve({hypothesisM:this.distanceHypotheses.get(p),derivedM:S&&y>0?pt.distanceMAt(S.widthM,y):void 0,range:w.distanceRangeAt(y),crossing:x}))}for(const[p,g]of a)for(const[m,v]of a){if(m===p||v.transparency>=1||v.bounds.width*v.bounds.height<=g.bounds.width*g.bounds.height||!(g.bounds.x>=v.bounds.x&&g.bounds.y>=v.bounds.y&&g.bounds.x+g.bounds.width<=v.bounds.x+v.bounds.width&&g.bounds.y+g.bounds.height<=v.bounds.y+v.bounds.height))continue;const x=l.get(m);x&&l.set(p,{distanceM:x.distanceM*.999,basis:x.basis});break}this.depths=l;const h=i.sourceIds,d=[];for(const[p,g]of a)d.push({sourceId:p,shape:g,distanceM:l.get(p).distanceM,renderOrder:h.indexOf(p),aim:g.aim,hidden:c.has(p)||this.interpretationShown!==void 0&&(!this.comparing||g.transparency>=1),ghost:this.interpretationShown!==void 0&&this.comparing});const f=(at(t,e)?.rollDeg??0)+$t.bodyAt(t,e,this.ufoElement.steadyBody).rollDeg;this.sceneRenderer.setPhenomena(d,{projection:r,canvasWidthPx:n.width,canvasHeightPx:n.height,scale:Math.max(1,this.sceneCanvas.height/Math.max(1,n.height)),starPoints:Bt.starPointsOf(t.instrument),rollRad:f*Math.PI/180})}get interpretation(){return this.interpretationShown}set interpretation(e){this.interpretationShown=e,this.ufoElement.playerTitle=e?.title,this.syncAccountHidden(),this.updateAstronomy(this.lastTimeMs),this.ufoElement.repaintChrome()}syncAccountHidden(){this.ufoElement.accountHidden=this.interpretationShown!==void 0&&!this.comparing}get accountInTheRound(){return this.inTheRound}set accountInTheRound(e){this.inTheRound=e}get compareAccount(){return this.comparing}set compareAccount(e){this.comparing=e,this.syncAccountHidden(),this.updateAstronomy(this.lastTimeMs),this.ufoElement.repaintChrome()}get confrontation(){return this.confrontationReadings}groundAlong(e,t,i){const n=this.sceneRenderer.bodyGround,s=et.eyeOf(this.ufoElement.sighting,i,n);return s?et.lineOfSightMeetsGround(s,e,t,n):void 0}bodyMaskedBy(e,t){return this.sceneRenderer.bodyMaskedByDecor(e,t)}bodyReading(e,t){const i=this.sceneRenderer.bodyGround,n=this.ufoElement.sighting,s=u=>et.eyeOf(n,u,i),r=new et(e,i,s).at(t),a=s(t);if(!r||!a)return;const l=r.eastM-a.eastM,c=r.northM-a.northM,h=r.upM-a.upM,d=Math.hypot(l,c);return{azimuthDeg:(Math.atan2(l,c)*180/Math.PI+360)%360,altitudeDeg:Math.atan2(h,d)*180/Math.PI,distanceM:Math.hypot(d,h),eastM:r.eastM,northM:r.northM,aboveGroundM:r.upM-r.sizeM.heightM/2-i.heightAt(r.eastM,r.northM),sizeM:r.sizeM,attitude:r.attitude,appearance:r.appearance}}directionToBody(e,t){const i=this.sceneRenderer.bodyGround,n=this.ufoElement.sighting,s=p=>et.eyeOf(n,p,i),r=new et(e,i,s),a=r.at(t)?t:e.track[0]?.t,l=a===void 0?void 0:r.at(a),c=a===void 0?void 0:s(a);if(!l||!c)return;const h=l.eastM-c.eastM,d=l.northM-c.northM,u=l.upM-c.upM,f=Math.hypot(h,d);if(!(f===0&&u===0))return{azimuthDeg:(Math.atan2(h,d)*180/Math.PI+360)%360,altitudeDeg:Math.atan2(u,f)*180/Math.PI}}placeBodiesAt(e,t){const i=this.interpretationShown,n=this.ufoElement.sighting;let s=[],r=[];const a=this.sceneRenderer.bodyGround,l=p=>et.eyeOf(n,p,a);i&&(s=i.bodies.map(p=>new et(p,a,l).at(e)).filter(p=>p!==void 0));const c=Li(n,e),h=c.windDirectionDeg*Math.PI/180,d={x:c.windSpeed*Math.sin(h),z:-c.windSpeed*Math.cos(h)};this.sceneRenderer.setBodies(s,e/1e3,i?.bodies.map(p=>p.id)??[],i?.smoke??[],d);const u=i&&this.comparing?l(e):void 0;if(u&&(r=new Ai(n.timeline).at(e,s,u,p=>p.outlineNode?this.sceneRenderer.bodyOutline?.(p.id,p.outlineNode):void 0)),this.confrontationReadings=r,!t)return;const f=JSON.stringify(r);f!==this.confrontationSignature&&(this.confrontationSignature=f,this.dispatchEvent(new CustomEvent(k6,{detail:r})))}setDistanceHypothesis(e,t){t===void 0||!(t>0)?this.distanceHypotheses.delete(e):this.distanceHypotheses.set(e,t),this.updateAstronomy(this.lastTimeMs)}depthOf(e){return this.depths.get(e)}sizeRangeOf(e){return this.sizeEstimateOf(e).sizeRange}distanceRangeAt(e,t){const i=this.ufoElement.sighting.timeline.getInterpolatedShapeAt(t,e);if(!i)return{};const n=i.angular?.widthDeg??this.projectionAt(t).pxToDeg(i.bounds.width);return this.sizeEstimateOf(e).distanceRangeAt(n)}sizeContradictory(e){return this.sizeEstimateOf(e).contradictory}updateMeteorShower(e,t){this.ensureMeteorSchedule(e),this.sceneRenderer.updateMeteors(t)}updateLightning(e,t,i){if(this.ensureLightningSchedule(e),this.sceneRenderer.updateLightning(t),i)return;const n=this.lastLightningT;if(this.lastLightningT=t,n===void 0||t<n||this.ufoElement.playbackState!=="playing")return;const s=this.lightningFlashes.filter(r=>r.t>n&&r.t<=t).pop();s&&Li(e,s.t).storm&&this.handleLightningFlash(s)}ensureLightningSchedule(e){const t=Li(e,0).precipitationIntensity,i=`${this.meteorInputsOf(e)}|${t}`;if(i===this.lightningScheduleFor)return;this.lightningScheduleFor=i;const n=e.event.time,s=e.event.place?.[0],r=n?.year!==void 0?ds(n,s?.lng??0,e.event.utcOffsetHours):void 0,a=(e.event.durationSeconds??0)*1e3||e.timeline.duration||2e4,l=Math.round((r?.getTime()??0)/1e3)+Math.round((s?.lat??0)*1e3)+7;this.lightningFlashes=qi.schedule({durationMs:a,seed:l,intensity:t}),this.sceneRenderer.setLightning(this.lightningFlashes)}ensureMeteorSchedule(e){const t=this.meteorInputsOf(e);t!==this.meteorScheduleFor&&(this.meteorScheduleFor=t,this.scheduleMeteors(e))}meteorInputsOf(e){const t=e.event.place?.[0],i=e.event.time;return JSON.stringify([t?.lat,t?.lng,i?.year,i?.month,i?.day,i?.hour,i?.minute,i?.second,e.event.utcOffsetHours,e.event.durationSeconds,e.timeline.duration])}scheduleMeteors(e){const t=e.event.place?.[0],i=e.event.time,n=t?.lat!==void 0&&t.lng!==void 0&&i?.year!==void 0?ds(i,t.lng,e.event.utcOffsetHours):void 0;if(!n||t?.lat===void 0||t.lng===void 0){this.sceneRenderer.setMeteorShower([],0,0);return}const s={lat:t.lat,lng:t.lng,elevationM:0},r=(e.event.durationSeconds??0)*1e3||e.timeline.duration||2e4,a=Math.round(n.getTime()/1e3)+Math.round(t.lat*1e3),l=vi.schedule({ratePerHour:vi.observedRatePerHour(vi.apexPosition(n,s).altitudeDeg),durationMs:r,velocityKmS:vi.TYPICAL_VELOCITY_KM_S,seed:a}),c=jl.activeAt(n).map(d=>{const u=jl.radiantPosition(d.shower,n,s);return{entry:d,position:u,rate:jl.observedRatePerHour(d.zhr,u.altitudeDeg,d.shower.populationIndex)}}).sort((d,u)=>u.rate-d.rate)[0];if(!c||c.rate<=0){this.sceneRenderer.setMeteorShower(l,0,0);return}const h=Co.schedule({ratePerHour:c.rate,durationMs:r,velocityKmS:c.entry.shower.velocityKmS,seed:a+1});this.sceneRenderer.setMeteorShower([...h,...l],c.position.altitudeDeg,c.position.azimuthDeg)}meteorByRank(e){this.ensureMeteorSchedule(this.ufoElement.sighting);const t=[...this.sceneRenderer.meteorSchedule].filter(s=>s.t+s.durationMs<=this.ufoElement.seekableDuration).sort((s,r)=>r.brightness-s.brightness);if(t.length===0)return;const i=t[e%t.length],n=this.sceneRenderer.meteorMidpoint(i);if(n)return{t:Math.round(i.t+i.durationMs*.45),...n}}lensOpticsAt(e){const t=this.ufoElement.sighting,i=t.instrument,n=i.frame,s=at(t,e),r=s?.fNumber??i.fNumber;if(!n||r===void 0)return;const a=Bt.focalLengthMmFor(i,ji.fovOf(t,e));if(a!==void 0)return{focalLengthMm:a,fNumber:r,focusDistance:s?.focusDistanceM??0,frameHeightMm:n.heightMm}}projectionAt(e){const t=this.ufoElement.sighting;return Vs.of(t.instrument,pt.CANVAS_HEIGHT_PX,ji.fovOf(t,e))}sizeEstimateOf(e){let t=this.sizeEstimates.get(e);return t||(t=new x6,this.sizeEstimates.set(e,t)),t}}const hf="rr0-scene";function B6(){xf(),customElements.get(hf)||customElements.define(hf,Vt)}class z6{constructor(e,t){this.timeline=e,this.clock=t}currentPointer=null;shapePrototype=null;sourceId="";start(e,t){this.sourceId=e,this.shapePrototype=t,this.currentPointer=null,this.clock.start(i=>this.recordSample(i))}onPointerMove(e,t){this.currentPointer={x:e,y:t}}stop(){this.clock.stop()}recordSample(e){if(!this.currentPointer||!this.shapePrototype)return;const t=aM(this.shapePrototype,this.currentPointer.x,this.currentPointer.y);this.timeline.addKeyframe(e,[{sourceId:this.sourceId,shape:t}])}}class H6{constructor(e){this.intervalMs=e}rafId=null;startTime=0;lastTick=0;start(e){this.startTime=performance.now(),this.lastTick=0;const t=()=>{const i=performance.now()-this.startTime;i-this.lastTick>=this.intervalMs&&(this.lastTick=i,e(i)),this.rafId=requestAnimationFrame(t)};this.rafId=requestAnimationFrame(t)}stop(){this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null)}}const df="rr0-duration-input",G6=`
9793
+ `);let s=rr.cache.get(n);return s||(s=Promise.all(i.map(r=>rr.load(r.url))).then(r=>r.reduce((a,l)=>rr.concat(a,l))),rr.cache.set(n,s)),s}static parse(e){const t=e.byteLength/(4*Float32Array.BYTES_PER_ELEMENT),i=t*Float32Array.BYTES_PER_ELEMENT;return{count:t,ra:new Float32Array(e,0*i,t),dec:new Float32Array(e,1*i,t),mag:new Float32Array(e,2*i,t),ci:new Float32Array(e,3*i,t)}}static concat(e,t){const i=(n,s)=>{const r=new Float32Array(n.length+s.length);return r.set(n,0),r.set(s,n.length),r};return{count:e.count+t.count,ra:i(e.ra,t.ra),dec:i(e.dec,t.dec),mag:i(e.mag,t.mag),ci:i(e.ci,t.ci)}}}class Wt{constructor(e){if(this.heights=e,e.length!==Wt.WIDTH*Wt.HEIGHT)throw new Error(`a lunar relief has ${Wt.WIDTH*Wt.HEIGHT} samples, not ${e.length}`)}static SAMPLES_PER_DEGREE=16;static WIDTH=360*Wt.SAMPLES_PER_DEGREE;static HEIGHT=180*Wt.SAMPLES_PER_DEGREE;static UNIT_KM=.1;static REFERENCE_RADIUS_KM=1737.4;static BAND_FROM_DEG=74;static BAND_TO_DEG=106;heightKm(e,t){const i=Wt.SAMPLES_PER_DEGREE,n=(t%360+360)%360*i-.5,s=(90-e)*i-.5,r=Math.floor(n),a=Math.floor(s),l=n-r,c=s-a,h=(f,p)=>{const g=(f%Wt.WIDTH+Wt.WIDTH)%Wt.WIDTH,m=Math.min(Wt.HEIGHT-1,Math.max(0,p));return this.heights[m*Wt.WIDTH+g]},d=h(r,a)*(1-l)+h(r+1,a)*l,u=h(r,a+1)*(1-l)+h(r+1,a+1)*l;return(d*(1-c)+u*c)*Wt.UNIT_KM}static inBand(e,t){const i=Math.PI/180,n=Math.acos(Math.cos(e*i)*Math.cos(t*i))*180/Math.PI;return n>=Wt.BAND_FROM_DEG&&n<=Wt.BAND_TO_DEG}static withBump(e,t,i,n=.4){const s=new Int8Array(Wt.WIDTH*Wt.HEIGHT),r=Wt.SAMPLES_PER_DEGREE,a=Math.ceil(n*r),l=Math.floor(t*r),c=Math.floor((90-e)*r);for(let h=-a;h<=a;h++)for(let d=-a;d<=a;d++)Math.hypot(d,h)<=a&&(s[(c+h)*Wt.WIDTH+(l+d+Wt.WIDTH)%Wt.WIDTH]=Math.round(i/Wt.UNIT_KM));return new Wt(s)}static smooth(){return new Wt(new Int8Array(Wt.WIDTH*Wt.HEIGHT))}}class ws{static SAMPLES=5760;static SEARCH_FROM_DEG=87;static SEARCH_TO_DEG=90.2;static SEARCH_STEP_DEG=.0625;static profile(e,t,i,n=ws.SAMPLES){const{s,u:r,w:a,distanceKm:l}=ws.frame(e,t),c=Math.PI/180,h=new Float32Array(n),d=Wt.REFERENCE_RADIUS_KM;for(let u=0;u<n;u++){const f=u/n*2*Math.PI,p=Math.cos(f),g=Math.sin(f),m=p*r[0]+g*a[0],v=p*r[1]+g*a[1],b=p*r[2]+g*a[2];let x=0;for(let y=ws.SEARCH_FROM_DEG;y<=ws.SEARCH_TO_DEG;y+=ws.SEARCH_STEP_DEG){const w=Math.cos(y*c),S=Math.sin(y*c),A=w*s[0]+S*m,M=w*s[1]+S*v,_=w*s[2]+S*b,I=Math.asin(Math.max(-1,Math.min(1,_)))/c,R=Math.atan2(M,A)/c,L=d+i.heightKm(I,R),P=Math.atan2(L*S,l-L*w);P>x&&(x=P)}h[u]=x/c}return{radiusDeg:h,meanRadiusDeg:Math.asin(d/l)/c}}static frame(e,t){const i=new Xr(t.lat,t.lng,t.elevationM),n=$r(e),s=km(e,i,!1),r=new It(s.x-n.x,s.y-n.y,s.z-n.z,n.t),a=Math.hypot(r.x,r.y,r.z)*ws.AU_KM,l=ws.bodyFixed(e),c=l(r),h=Math.hypot(c[0],c[1],c[2]),d=[c[0]/h,c[1]/h,c[2]/h],u=UR(e,i),f=Hg(u),p=Vr(u,new It(-r.x,-r.y,-r.z,n.t)),g=Math.asin(p.z/Math.hypot(p.x,p.y,p.z)),m=Math.atan2(-p.y,p.x),v=new It(-Math.sin(g)*Math.cos(m),Math.sin(g)*Math.sin(m),Math.cos(g),n.t),b=new It(-Math.sin(m),-Math.cos(m),0,n.t);return{s:d,u:l(Vr(f,v)),w:l(Vr(f,b)),distanceKm:a}}static surfacePoint(e,t,i,n){const{s,u:r,w:a}=ws.frame(e,t),l=Math.PI/180,c=[0,1,2].map(d=>Math.cos(i*l)*r[d]+Math.sin(i*l)*a[d]),h=[0,1,2].map(d=>Math.cos(n*l)*s[d]+Math.sin(n*l)*c[d]);return{latDeg:Math.asin(h[2])/l,lonDeg:Math.atan2(h[1],h[0])/l}}static radiusAt(e,t){const i=e.radiusDeg.length,n=(t/360*i%i+i)%i,s=Math.floor(n),r=n-s;return e.radiusDeg[s]*(1-r)+e.radiusDeg[(s+1)%i]*r}static uncoveredFraction(e,t,i){const n=e.radiusDeg.length,s=i.upDeg*i.upDeg+i.rightDeg*i.rightDeg;let r=0;for(let a=0;a<n;a++){const l=a/n*2*Math.PI,c=Math.cos(l),h=Math.sin(l),d=c*i.upDeg+h*i.rightDeg,u=d*d-s+t*t;if(u<=0)continue;const f=Math.sqrt(u),p=d+f;if(p<=0)continue;const g=Math.max(0,d-f),m=Math.max(g,e.radiusDeg[a]);p>m&&(r+=.5*(p*p-m*m))}return Math.min(1,Math.max(0,r*(2*Math.PI/n)/(Math.PI*t*t)))}static AU_KM=1495978707e-1;static bodyFixed(e){const t=e4(de.Moon,e),i=Math.PI/180,n=t.ra*15*i,s=t.dec*i,r=t.spin*i,a=(c,[h,d,u])=>[Math.cos(c)*h+Math.sin(c)*d,-Math.sin(c)*h+Math.cos(c)*d,u],l=(c,[h,d,u])=>[h,Math.cos(c)*d+Math.sin(c)*u,-Math.sin(c)*d+Math.cos(c)*u];return c=>a(r,l(Math.PI/2-s,a(Math.PI/2+n,[c.x,c.y,c.z])))}static subObserverPoint(e,t){const i=new Xr(t.lat,t.lng,t.elevationM),n=$r(e),s=km(e,i,!1),r=ws.bodyFixed(e)(new It(s.x-n.x,s.y-n.y,s.z-n.z,n.t)),a=Math.hypot(r[0],r[1],r[2]);return{latDeg:Math.asin(r[2]/a)*180/Math.PI,lonDeg:Math.atan2(r[1],r[0])*180/Math.PI}}}class rh{static cache=new Map;static load(e){let t=rh.cache.get(e);return t||(t=rh.fetchRelief(e).catch(()=>{}),rh.cache.set(e,t)),t}static async fetchRelief(e){const t=await fetch(e);if(!t.ok)return;let i=new Uint8Array(await t.arrayBuffer());if(i[0]===31&&i[1]===139){if(typeof DecompressionStream>"u")return;const n=new Blob([i]).stream().pipeThrough(new DecompressionStream("gzip"));i=new Uint8Array(await new Response(n).arrayBuffer())}return new Wt(new Int8Array(i.buffer,i.byteOffset,i.length))}}class lf{constructor(e){this.names=e}body(e,t){return this.names?.bodies[e]??t}star(e){return this.names?.stars[e.name]??e.name}comet(e){return this.names?.comets[e.id]??e.name}nova(e){return this.names?.novae[e.id]??e.name}satelliteClass(e){return this.names?.satelliteClasses[e.id]??e.name}shower(e){return this.names?.showers[e.id]??e.name}lightRig(e){return this.names?.lightRigs[e.id]??e.name}instrument(e){return this.names?.instruments[e.id]??e.name}decorKind(e,t){return this.names?.decorKinds[e]??t}point(e){return Ro.point(e,this.names?.compassPoints)}towards(e){return Ro.towards(e,this.names)}}const h6="Global Meteor Network",d6="https://globalmeteornetwork.org/data/",u6="“Thunder” by Jerimee",f6="https://creativecommons.org/licenses/by/3.0/",p6="CC BY 3.0";class qn{static fill(e,t){e.innerHTML="";const i=h=>e.appendChild(h),n=t.currentTerrainAttribution;n&&i(qn.text(n));const s=t.currentRoadAttribution;s&&i(qn.text(s));const r=t.ufoElement.observerMapCredit;r&&!n?.includes(r)&&i(qn.text(r));for(const h of t.decorModelCredits){const d=h.author?` — ${h.author}`:"",u=document.createElement("li");h.sourceUrl?u.append(qn.link(h.sourceUrl,h.title),document.createTextNode(`${d} (${h.license})`)):u.textContent=`${h.title}${d} (${h.license})`,i(u)}for(const h of t.ufoElement.sighting.references){if(!h.credit)continue;const d=document.createElement("li");h.creditUrl?d.appendChild(qn.link(h.creditUrl,h.credit)):d.textContent=h.credit,i(d)}if(t.ufoElement.sighting.traces.length>0){const h=new Un(_s.preferencesFor(t)),d=new Set(t.ufoElement.sighting.traces.map(u=>h.read(u.source)).filter(u=>!!u));for(const u of d)i(qn.text(u))}const a=t.satelliteState;if(a.status==="ready"&&a.credit){const h=document.createElement("li");h.appendChild(qn.link(a.creditUrl??"",a.credit)),i(h)}if(t.fireballState.status==="ready"&&t.fireballState.records.length>0){const h=document.createElement("li");h.append(qn.link(d6,h6),document.createTextNode(" (CC BY 4.0)")),i(h)}const l=t.aircraftState;if(l.status==="ready"&&l.shown>0){const h=document.createElement("li");if(h.appendChild(qn.link(l.creditUrl,l.credit)),i(h),l.trailCredit){const d=document.createElement("li");d.appendChild(qn.link(l.trailCredit.creditUrl,l.trailCredit.credit)),i(d)}}const c=qn.text(`${u6} (`);c.append(qn.link(f6,p6),document.createTextNode(")")),i(c)}static text(e){const t=document.createElement("li");return t.textContent=e,t}static link(e,t){const i=document.createElement("a");return i.href=e,i.target="_blank",i.rel="noopener",i.textContent=t,i}}const m6=new URL(""+new URL("rain-BvWZrB9h.ogg",import.meta.url).href,import.meta.url).href,g6=new URL(""+new URL("wind-BjklexY7.ogg",import.meta.url).href,import.meta.url).href,v6=new URL(""+new URL("thunder-DA48qs_v.wav",import.meta.url).href,import.meta.url).href,y6=20,b6=1;class M6{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};level=1;master;output(e){return this.master||(this.master=e.createGain(),this.master.gain.value=this.level,this.master.connect(e.destination)),this.master}setLevel(e){this.level=e,this.master&&(this.master.gain.value=e)}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}}To.unlock(this.context)}setAmbient(e,t,i){if(this.requested={type:e,intensity:t,windSpeed:i},!this.context)return;this.paused&&(e="none",t=0,i=0);const n=e==="rain"||e==="hail"?e:"none";if(this.ambientVolume=n==="hail"?Math.min(1,t*1.3+.2):n==="rain"?t:0,n!==this.ambientKey){this.ambientKey=n;const r=++this.ambientToken;this.stopSource(this.ambientSource,this.ambientGain),this.ambientSource=void 0,this.ambientGain=void 0,n!=="none"&&this.startLoop(m6,this.ambientVolume).then(a=>this.applyIfCurrent(a,r,()=>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(i/y6,1);const s=i>b6;if(s!==this.windActive){this.windActive=s;const r=++this.windToken;this.stopSource(this.windSource,this.windGain),this.windSource=void 0,this.windGain=void 0,s&&this.startLoop(g6,this.windVolume).then(a=>this.applyIfCurrent(a,r,()=>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:i,windSpeed:n}=this.requested;this.setAmbient(t,i,n)}playThunder(){!this.context||this.paused||this.playOneShot(v6,.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.master=void 0,this.buffers.clear()}applyIfCurrent(e,t,i,n){if(t!==i()){e?.source.stop();return}n(e)}async startLoop(e,t){const i=this.context;if(i)try{const n=await this.getBuffer(e),s=i.createBufferSource();s.buffer=n,s.loop=!0;const r=i.createGain();return r.gain.value=t,s.connect(r).connect(this.output(i)),s.start(),{source:s,gain:r}}catch(n){console.warn("Weather ambient sound failed to load, staying silent:",n);return}}async playOneShot(e,t){const i=this.context;if(i)try{const n=await this.getBuffer(e),s=i.createBufferSource();s.buffer=n;const r=i.createGain();r.gain.value=t,s.connect(r).connect(this.output(i)),s.start()}catch(n){console.warn("Thunder sound failed to load:",n)}}async getBuffer(e){const t=this.context;if(!t)throw new Error("WeatherAudio: AudioContext not ready — resume() must be called first");let i=this.buffers.get(e);return i||(i=fetch(e).then(n=>{if(!n.ok)throw new Error(`Audio fetch failed (${n.status}): ${e}`);return n.arrayBuffer()}).then(n=>t.decodeAudioData(n)),this.buffers.set(e,i)),i}stopSource(e,t){try{e?.stop()}catch{}e?.disconnect(),t?.disconnect()}}class Nr{constructor(e){this.elements=e;const{eccentricity:t,perihelionAu:i}=e,[n,s]=this.perifocalAxes(),r=Math.sqrt(Nr.SUN_GM_AU3_PER_DAY2*(1+t)/i);this.perihelionPosition=this.scale(n,i),this.perihelionVelocity=this.scale(s,r),this.inverseSemiMajorAxis=(1-t)/i}static SUN_GM_AU3_PER_DAY2=.0002959122082855911;static MAX_ITERATIONS=200;perihelionPosition;perihelionVelocity;inverseSemiMajorAxis;positionAt(e){const t=e-this.elements.perihelionJd,i=this.universalAnomaly(t),n=this.inverseSemiMajorAxis*i*i,s=this.elements.perihelionAu,r=1-i*i/s*Nr.stumpffC(n),a=t-i*i*i/Math.sqrt(Nr.SUN_GM_AU3_PER_DAY2)*Nr.stumpffS(n);return{x:r*this.perihelionPosition.x+a*this.perihelionVelocity.x,y:r*this.perihelionPosition.y+a*this.perihelionVelocity.y,z:r*this.perihelionPosition.z+a*this.perihelionVelocity.z}}heliocentricDistanceAt(e){const t=this.positionAt(e);return Math.hypot(t.x,t.y,t.z)}universalAnomaly(e){if(e===0)return 0;const t=Math.sign(e),i=Math.sqrt(Nr.SUN_GM_AU3_PER_DAY2)*Math.abs(e),n=a=>{const l=this.inverseSemiMajorAxis*a*a,c=this.elements.perihelionAu;return(1-this.inverseSemiMajorAxis*c)*a*a*a*Nr.stumpffS(l)+c*a};let s=Math.max(1,i/this.elements.perihelionAu);for(;n(s)<i;)s*=2;let r=0;for(let a=0;a<Nr.MAX_ITERATIONS&&s-r>1e-13*Math.max(1,s);a++){const l=(r+s)/2;n(l)<i?r=l:s=l}return t*(r+s)/2}perifocalAxes(){const e=this.elements.ascendingNodeDeg*Math.PI/180,t=this.elements.argumentOfPerihelionDeg*Math.PI/180,i=this.elements.inclinationDeg*Math.PI/180,n=Math.cos(e),s=Math.sin(e),r=Math.cos(t),a=Math.sin(t),l=Math.cos(i),c=Math.sin(i);return[{x:n*r-s*a*l,y:s*r+n*a*l,z:a*c},{x:-n*a-s*r*l,y:-s*a+n*r*l,z:r*c}]}scale(e,t){return{x:e.x*t,y:e.y*t,z:e.z*t}}static stumpffC(e){if(Math.abs(e)<1e-6)return 1/2-e/24+e*e/720;if(e>0)return(1-Math.cos(Math.sqrt(e)))/e;const t=Math.sqrt(-e);return(Math.cosh(t)-1)/-e}static stumpffS(e){if(Math.abs(e)<1e-6)return 1/6-e/120+e*e/5040;if(e>0){const i=Math.sqrt(e);return(i-Math.sin(i))/(i*i*i)}const t=Math.sqrt(-e);return(Math.sinh(t)-t)/(t*t*t)}}const w2=[{id:"halley-1910",designation:"1P/Halley",name:"Halley's Comet",orbit:{eccentricity:.9672960498922706,perihelionAu:.5872100477652511,inclinationDeg:162.218798367122,ascendingNodeDeg:58.56208298700436,argumentOfPerihelionDeg:111.7366940639061,perihelionJd:2.4187816784171113e6},peakMagnitude:0,peakOn:"1910-05-20",absoluteMagnitude:4.72,activityExponent:4,tailLengthDeg:100,tailLengthAu:.1638,note:"Passed 0.15 au from Earth on 20 May 1910, and the Earth crossed the outer tail the day before — the apparition that produced a genuine public panic."},{id:"brooks-1911",designation:"C/1911 O1",name:"Comet Brooks",orbit:{eccentricity:.9876404970138669,perihelionAu:.4898172916113738,inclinationDeg:33.34043866978714,ascendingNodeDeg:293.7022074981857,argumentOfPerihelionDeg:153.5578007321686,perihelionJd:2.4193378856140426e6},peakMagnitude:2,peakOn:"1911-10-25",absoluteMagnitude:5.59,activityExponent:4},{id:"skjellerup-maristany-1927",designation:"C/1927 X1",name:"Comet Skjellerup-Maristany",orbit:{eccentricity:.999839726885059,perihelionAu:.1761569619628186,inclinationDeg:85.1125991950808,ascendingNodeDeg:78.24360172472711,argumentOfPerihelionDeg:47.15877857390136,perihelionJd:2.4252326808989984e6},peakMagnitude:-6,peakOn:"1927-12-15",absoluteMagnitude:1.19,activityExponent:4,note:"One of the few comets of the century seen in full daylight."},{id:"de-kock-paraskevopoulos-1941",designation:"C/1941 B2",name:"Comet de Kock-Paraskevopoulos",orbit:{eccentricity:.9991026715181549,perihelionAu:.7900329662827822,inclinationDeg:168.2039226531089,ascendingNodeDeg:43.10609347214336,argumentOfPerihelionDeg:268.6990344196369,perihelionJd:2430022157765061e-9},peakMagnitude:2,peakOn:"1941-02-05",absoluteMagnitude:5.01,activityExponent:4},{id:"southern-1947",designation:"C/1947 X1",name:"the Southern Comet",orbit:{eccentricity:.9998424430916737,perihelionAu:.1100045955093761,inclinationDeg:138.5113919632757,ascendingNodeDeg:337.3114969669252,argumentOfPerihelionDeg:196.1820121395961,perihelionJd:2.4325220864727003e6},peakMagnitude:-3,peakOn:"1947-12-08",absoluteMagnitude:3.01,activityExponent:4,note:"A bright southern-hemisphere comet of December 1947, the month the American sighting wave of that year was still being argued over."},{id:"eclipse-1948",designation:"C/1948 V1",name:"the Eclipse Comet",orbit:{eccentricity:.9999130678247334,perihelionAu:.1354437057263306,inclinationDeg:23.11668597152911,ascendingNodeDeg:211.0454985994762,argumentOfPerihelionDeg:107.2474157073104,perihelionJd:2.4328519265329437e6},peakMagnitude:-2,peakOn:"1948-11-01",absoluteMagnitude:4.79,activityExponent:4,note:"Found during the total solar eclipse of 1 November 1948, which is how a comet that bright had gone unnoticed: it had been hidden in the Sun's glare."},{id:"arend-roland-1957",designation:"C/1956 R1",name:"Comet Arend-Roland",orbit:{eccentricity:1.0002570255357,perihelionAu:.3160532361485914,inclinationDeg:119.9440863251822,ascendingNodeDeg:215.8548157717755,argumentOfPerihelionDeg:308.775920364167,perihelionJd:2.4359365327396123e6},peakMagnitude:.5,peakOn:"1957-04-25",absoluteMagnitude:3.96,activityExponent:4,note:"Showed a spike pointing back TOWARD the Sun in late April 1957 — a real anti-tail, and much reported at the time."},{id:"mrkos-1957",designation:"C/1957 P1",name:"Comet Mrkos",orbit:{eccentricity:.9993521583504134,perihelionAu:.3549238508212375,inclinationDeg:93.9433042053929,ascendingNodeDeg:68.32441518619923,argumentOfPerihelionDeg:40.31823675802871,perihelionJd:243605193752228e-8},peakMagnitude:1,peakOn:"1957-08-05",absoluteMagnitude:5.07,activityExponent:4,note:"The second bright naked-eye comet of 1957, four months after Arend-Roland."},{id:"seki-lines-1962",designation:"C/1962 C1",name:"Comet Seki-Lines",orbit:{eccentricity:1.000003791331562,perihelionAu:.03139689112215131,inclinationDeg:65.01487186102287,ascendingNodeDeg:304.6776602796538,argumentOfPerihelionDeg:11.47295326312573,perihelionJd:2437756163010178e-9},peakMagnitude:-2.5,peakOn:"1962-04-01",absoluteMagnitude:9.3,activityExponent:4},{id:"ikeya-seki-1965",designation:"C/1965 S1",name:"Comet Ikeya-Seki",orbit:{eccentricity:.9999141178248997,perihelionAu:.007785966366889336,inclinationDeg:141.8642315267051,ascendingNodeDeg:346.9951764632611,argumentOfPerihelionDeg:69.04909813996062,perihelionJd:2.4390546837018197e6},peakMagnitude:-10,peakOn:"1965-10-21",alsoRecordedMagnitude:2,alsoRecordedOn:"1965-10-30",absoluteMagnitude:5.26,activityExponent:4.002,tailLengthDeg:25,tailLengthAu:.5048,note:"A sungrazer that passed 450 000 km above the Sun's surface and was seen beside it in broad daylight — the brightest comet of the twentieth century. It then stood in the dawn sky for a fortnight with a tail some 25 degrees long, which is the second magnitude recorded here."},{id:"bennett-1970",designation:"C/1969 Y1",name:"Comet Bennett",orbit:{eccentricity:.9962979048768408,perihelionAu:.5376209981502136,inclinationDeg:90.03975717147327,ascendingNodeDeg:224.6576652531314,argumentOfPerihelionDeg:354.1494209173161,perihelionJd:2.4406655455270996e6},peakMagnitude:0,peakOn:"1970-03-26",absoluteMagnitude:3.36,activityExponent:4},{id:"white-ortiz-bolelli-1970",designation:"C/1970 K1",name:"Comet White-Ortiz-Bolelli",orbit:{eccentricity:.9999488875801225,perihelionAu:.00884411465256722,inclinationDeg:138.9520738221631,ascendingNodeDeg:336.8194095816687,argumentOfPerihelionDeg:61.10224765396615,perihelionJd:2.4407209807728203e6},peakMagnitude:1,peakOn:"1970-05-22",absoluteMagnitude:4.35,activityExponent:4},{id:"kohoutek-1973",designation:"C/1973 E1",name:"Comet Kohoutek",orbit:{eccentricity:1.000007152175185,perihelionAu:.1424250377812859,inclinationDeg:14.30414984159355,ascendingNodeDeg:258.4893339663974,argumentOfPerihelionDeg:37.79772760699667,perihelionJd:2442044930687027e-9},peakMagnitude:0,peakOn:"1974-01-05",absoluteMagnitude:4.89,activityExponent:4,note:"Announced in advance as the comet of the century and remembered for disappointing: it was an ordinary naked-eye object, not the spectacle the press had promised."},{id:"west-1976",designation:"C/1975 V1",name:"Comet West",orbit:{eccentricity:1.000017859625611,perihelionAu:.1966006188461085,inclinationDeg:43.07319920579427,ascendingNodeDeg:118.9189245655447,argumentOfPerihelionDeg:358.4315101259072,perihelionJd:2442833721841768e-9},peakMagnitude:-3,peakOn:"1976-02-25",absoluteMagnitude:4.41,activityExponent:4,tailLengthDeg:30,tailLengthAu:.4325,note:"Broke into four pieces at perihelion. Barely reported at the time — the press had been burned by Kohoutek two years earlier."},{id:"iras-araki-alcock-1983",designation:"C/1983 H1",name:"Comet IRAS-Araki-Alcock",orbit:{eccentricity:.9898409731606003,perihelionAu:.9913412593828502,inclinationDeg:73.25000846947029,ascendingNodeDeg:49.10235754476374,argumentOfPerihelionDeg:192.8506176754439,perihelionJd:2.4454757545235856e6},peakMagnitude:1.7,peakOn:"1983-05-11",absoluteMagnitude:9.04,activityExponent:4,note:"Passed 0.031 au from Earth on 11 May 1983, one of the closest cometary approaches on record: it crossed a quarter of the sky in a night, which no other comet in this list did."},{id:"halley-1986",designation:"1P/Halley",name:"Halley's Comet",orbit:{eccentricity:.9672792271749998,perihelionAu:.5871034488173393,inclinationDeg:162.2422242700916,ascendingNodeDeg:58.85993640671803,argumentOfPerihelionDeg:111.8655480539208,perihelionJd:2.4464709589610207e6},peakMagnitude:2.1,peakOn:"1986-03-10",absoluteMagnitude:2.71,activityExponent:4,note:"The worst-placed return in two thousand years — famous, expected, and for most observers a faint smudge."},{id:"hyakutake-1996",designation:"C/1996 B2",name:"Comet Hyakutake",orbit:{eccentricity:.9997295133739305,perihelionAu:.2302272039470452,inclinationDeg:124.923592343765,ascendingNodeDeg:188.0454295899424,argumentOfPerihelionDeg:130.1724036582639,perihelionJd:2.4502048946148166e6},peakMagnitude:0,peakOn:"1996-03-25",absoluteMagnitude:4.75,activityExponent:4,tailLengthDeg:80,tailLengthAu:1,note:"Passed 0.10 au from Earth in March 1996, five weeks BEFORE perihelion, with a tail measured at some 80 degrees — the longest of the modern era."},{id:"hale-bopp-1997",designation:"C/1995 O1",name:"Comet Hale-Bopp",orbit:{eccentricity:.9951314746156615,perihelionAu:.9141695067003724,inclinationDeg:89.43017155012492,ascendingNodeDeg:282.470602866853,argumentOfPerihelionDeg:130.5872524854533,perihelionJd:2450539633099368e-9},peakMagnitude:-.8,peakOn:"1997-04-01",absoluteMagnitude:-1.06,activityExponent:4,tailLengthDeg:20,tailLengthAu:.9938,note:"Visible to the naked eye for about eighteen months, longer than any comet on record."},{id:"mcnaught-2007",designation:"C/2006 P1",name:"Comet McNaught",orbit:{eccentricity:1.00001811603225,perihelionAu:.1707325614080681,inclinationDeg:77.83726446452654,ascendingNodeDeg:267.4149080498975,argumentOfPerihelionDeg:155.9756130642756,perihelionJd:2454113298753579e-9},peakMagnitude:-5.5,peakOn:"2007-01-13",absoluteMagnitude:2.53,activityExponent:4,tailLengthDeg:35,tailLengthAu:.5009,note:"The brightest comet since Ikeya-Seki, seen in daylight beside the Sun in January 2007."},{id:"lovejoy-2011",designation:"C/2011 W3",name:"Comet Lovejoy",orbit:{eccentricity:.999915056276912,perihelionAu:.005553783989325053,inclinationDeg:134.3558712062691,ascendingNodeDeg:326.3693517957772,argumentOfPerihelionDeg:53.50991655176601,perihelionJd:2455911511809431e-9},peakMagnitude:-3,peakOn:"2011-12-16",alsoRecordedMagnitude:1.5,alsoRecordedOn:"2011-12-22",absoluteMagnitude:3.51,activityExponent:1.194,note:"A sungrazer that was expected to be destroyed at perihelion and came out the other side, to stand in the southern dawn sky for the rest of December — which is the second magnitude recorded here."},{id:"panstarrs-2013",designation:"C/2011 L4",name:"Comet PANSTARRS",orbit:{eccentricity:1.000032542889696,perihelionAu:.301544229714915,inclinationDeg:84.2081978367921,ascendingNodeDeg:65.66588626213694,argumentOfPerihelionDeg:333.6516444379993,perihelionJd:2456361669960698e-9},peakMagnitude:1,peakOn:"2013-03-10",absoluteMagnitude:5.98,activityExponent:4},{id:"neowise-2020",designation:"C/2020 F3",name:"Comet NEOWISE",orbit:{eccentricity:.9991782081129224,perihelionAu:.2946512466331692,inclinationDeg:128.9375043020912,ascendingNodeDeg:61.01042991771634,argumentOfPerihelionDeg:37.2786526292898,perihelionJd:2.4590341788972816e6},peakMagnitude:.9,peakOn:"2020-07-08",absoluteMagnitude:5.79,activityExponent:4,tailLengthDeg:10,tailLengthAu:.1808,note:"The first comet since Hale-Bopp that ordinary observers in the northern hemisphere saw without being told where to look."},{id:"tsuchinshan-atlas-2024",designation:"C/2023 A3",name:"Comet Tsuchinshan-ATLAS",orbit:{eccentricity:1.000020192843226,perihelionAu:.3914228969475176,inclinationDeg:139.1105462619479,ascendingNodeDeg:21.55945689078845,argumentOfPerihelionDeg:308.4913086299446,perihelionJd:2460581242087108e-9},peakMagnitude:0,peakOn:"2024-10-14",absoluteMagnitude:3.97,activityExponent:4,tailLengthDeg:20,tailLengthAu:.1902,note:"Briefly reported far brighter around 9 October 2024, when it stood almost between the observer and the Sun and forward-scattered the light through its own dust — a geometry this catalog's brightness model does not attempt, so what is stored is the ordinary evening-sky peak a few days later."}];class ou{static WINDOW_DAYS=200;static TWILIGHT_ELONGATION_DEG=15;static LIGHT_SPEED_AU_PER_DAY=173.144632674;static orbits=new Map;static aroundDate(e){const t=this.julianDayOf(e);return w2.filter(i=>Math.abs(t-i.orbit.perihelionJd)<=this.WINDOW_DAYS)}static brightestAt(e,t){return this.aroundDate(e).map(i=>this.appearanceOf(i,e,t)).sort((i,n)=>i.magnitude-n.magnitude)[0]}static appearanceOf(e,t,i){const n=Zt(t),s=this.earthPositionAt(n),r=this.apparentPositionOf(e,2451545+n.tt,s),a=this.subtract(r,s),l=this.length(r),c=this.length(a),h=this.tailEndAt(e,r,s,l,n,t,i),d=this.horizontalOf(a,n,t,i);return{apparition:e,position:d,...h,heliocentricDistanceAu:l,earthDistanceAu:c,elongationDeg:this.angleBetween(a,this.subtract({x:0,y:0,z:0},s)),magnitude:this.magnitudeAt(e,l,c)}}static magnitudeAt(e,t,i){const n=e.absoluteMagnitude+5*Math.log10(i)+2.5*e.activityExponent*Math.log10(t);return Math.max(n,e.peakMagnitude)}static tailEndAt(e,t,i,n,s,r,a){if(e.tailLengthAu===void 0)return{};const l=1+e.tailLengthAu/n,c=this.subtract({x:t.x*l,y:t.y*l,z:t.z*l},i),h=this.subtract(t,i);return{tailEnd:this.horizontalOf(c,s,r,a),tailLengthDeg:this.angleBetween(h,c)}}static apparentPositionOf(e,t,i){const n=this.orbitOf(e);let s=n.positionAt(t);for(let r=0;r<2;r++){const a=this.length(this.subtract(s,i))/this.LIGHT_SPEED_AU_PER_DAY;s=n.positionAt(t-a)}return s}static horizontalOf(e,t,i,n){const s=Vr(LR(),new It(e.x,e.y,e.z,t)),r=Vr(n2(t),s),a=km(t,new Xr(n.lat,n.lng,n.elevationM),!0),l=new It(r.x-a.x,r.y-a.y,r.z-a.z,t),c=Of(l);return Wg(c.ra,c.dec,i,n)}static earthPositionAt(e){return Vr(PR(),Da(de.Earth,e))}static julianDayOf(e){return 2451545+Zt(e).tt}static orbitOf(e){const t=this.orbits.get(e.id);if(t)return t;const i=new Nr(e.orbit);return this.orbits.set(e.id,i),i}static subtract(e,t){return{x:e.x-t.x,y:e.y-t.y,z:e.z-t.z}}static length(e){return Math.hypot(e.x,e.y,e.z)}static angleBetween(e,t){const i=(e.x*t.x+e.y*t.y+e.z*t.z)/(this.length(e)*this.length(t)||1);return Math.acos(Math.min(1,Math.max(-1,i)))*180/Math.PI}}const s0=[{id:"sn-1006",kind:"supernova",designation:"SN 1006",name:"Supernova of 1006",raHours:15.03947,decDeg:-42.09694,peakMagnitude:-7.5,peakJd:2088620,startJd:2088620,lightCurve:[[0,-7.5],[29,-5.9],[60,-4.9],[106,-3.2],[166,-1.9],[258,-1],[350,.5],[364,.7],[411,1.2],[456,1.8],[484,2.5],[785.5,7]],source:"Winkler, Gupta & Long 2003 (peak); decline borrowed from SN 1572",note:"The brightest stellar event in recorded history, seen in daylight, low in the southern sky from Europe and the Near East. The decline is modelled, not recorded, and falls below the naked eye after about two years where the chronicles speak of three."},{id:"sn-1054",kind:"supernova",designation:"SN 1054",name:"Supernova of 1054",raHours:5.5755,decDeg:22.0175,peakMagnitude:-6,peakJd:2106216,startJd:2106216,lightCurve:[[0,-6],[23,-4],[642,6]],source:"Chinese chronicles (Song huiyao), via Stephenson & Green 2002",note:"The explosion that left the Crab Nebula. Its magnitude is an estimate; the two durations are recorded."},{id:"sn-1181",kind:"supernova",designation:"SN 1181",name:"Supernova of 1181",raHours:.88645,decDeg:67.50067,peakMagnitude:0,peakJd:2152636,startJd:2152636,lightCurve:[[0,0],[185,6]],source:"Chinese and Japanese chronicles, via Stephenson & Green 2002",note:"Circumpolar from Europe and China, so never set. Its peak magnitude is uncertain by at least a magnitude."},{id:"sn-1572",kind:"supernova",designation:"SN 1572",name:"Tycho's Supernova",raHours:.42264,decDeg:64.14083,peakMagnitude:-4,peakJd:2295551,startJd:2295546,lightCurve:[[0,-3],[5,-4],[34,-2.4],[65,-1.4],[111,.3],[171,1.6],[263,2.5],[355,4],[369,4.2],[416,4.7],[461,5.3],[489,6]],source:"Tycho Brahe and contemporaries, reduced by Ruiz-Lapuente 2004",note:"Circumpolar from northern Europe. Tycho showed it had no parallax, so it was not in the air: a new star, beyond the Moon."},{id:"sn-1604",kind:"supernova",designation:"SN 1604",name:"Kepler's Supernova",raHours:17.51125,decDeg:-21.48733,peakMagnitude:-2.95,peakJd:2307210,startJd:2307191,lightCurve:[[0,.23],[3,-1.3],[6,-2.08],[9,-2.17],[19,-2.95],[27,-2.95],[32,-1.95],[36,-1.52],[86,.9],[96,.45],[103,1],[114,1.2],[118,1.55],[133,1.95],[137,2.3],[170,2.25],[185,2.25],[194,2.4],[197,2.9],[308,4.45],[324,4.45],[339,4.95],[364,4.7]],source:"Kepler, Fabricius, Maestlin and the Korean court astronomers, reduced by Ruiz-Lapuente 2017",note:"The last supernova in our Galaxy seen with the naked eye. It went behind the Sun from mid-November 1604 to January 1605, which is the gap in its record."},{id:"t-crb-1866",kind:"nova",designation:"T CrB",name:"Nova Coronae Borealis 1866",raHours:15.99171,decDeg:25.92017,peakMagnitude:2,peakJd:2402734,startJd:2402734,lightCurve:[[0,2],[1.5,3],[2.5,3.11],[6.5,5.18],[8.5,5.75],[10.5,6.85],[11.5,6.8],[12.5,7.5],[16,8.18],[32,9.27],[38,9.2],[40,8.95],[44,9.4],[48,9.07],[54,9.4],[58,9.21],[79,9.44],[107,9.26],[111,9.01],[115,8.21],[119,7.96],[159,7.51],[179,7.57],[183,7.97],[191,7.66],[199,8.2],[207,8.31],[211,8.83],[215,8.65],[223,8.97],[297,8.9],[345,9.25],[377,9.07],[425,9.3],[537,9.3]],source:"Recorded peak (Birmingham); curve borrowed from its 1946 eruption",note:"The first eruption of the recurrent nova T CrB to be seen. The decline is its 1946 one."},{id:"t-aur-1891",kind:"nova",designation:"T Aur",name:"Nova Aurigae 1891",raHours:5.53309,decDeg:30.44583,peakMagnitude:4.49,peakJd:2412083,startJd:2412079,lightCurve:[[0,5.28],[4,4.49],[24,4.58],[40,4.97],[52,4.95],[56,4.5],[60,4.9],[68,4.88],[72,5.25],[76,4.93],[84,5.44],[88,7.23],[96,8.85],[100,10.44]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"gk-per-1901",kind:"nova",designation:"GK Per",name:"Nova Persei 1901",raHours:3.52,decDeg:43.90431,peakMagnitude:.19,peakJd:24154395e-1,startJd:24154377e-1,lightCurve:[[0,2.7],[.8,.86],[1.8,.19],[2.3,.2],[5.8,1.78],[11.8,2.54],[12.8,2.98],[17.8,3.62],[18.8,3.35],[19.8,3.77],[20.8,3.59],[22.8,3.95],[24.8,3.82],[25.6,4.99],[25.9,4.89],[26.6,3.69],[27.6,3.94],[27.9,4.61],[28.6,5.28],[28.9,4.46],[29.9,3.8],[30.9,4.27],[31.6,5.21],[31.9,5.22],[32.9,3.88],[33.9,4.19],[34.6,4.85],[35.6,4.8],[36.6,4.23],[37.6,4.44],[38.9,4.15],[39.7,5.19],[40.6,5.39],[40.9,5.35],[41.9,4.01],[42.6,4.5],[42.9,4.49],[43.6,5.53],[44,5.23],[44.6,5.61],[44.9,5.5],[45.9,4.17],[46.9,4.69],[47.6,5.5],[48.6,5.59],[49.6,5.14],[49.9,4.48],[50.6,4.45],[50.9,4.55],[51.6,5.47],[52.6,5.74],[53.7,5.66],[55.7,4.41],[56.7,5.43],[58.7,5.81],[58.9,5.58],[59.7,5.64],[59.9,4.76],[60.9,4.26],[61.9,5.62],[62.7,5.85],[62.9,5.53],[63.7,5.8],[64.9,4.28],[65.6,5.33],[66.7,5.87],[66.9,5.56],[68.7,5.7],[68.9,5.3],[69.7,4.47],[70.7,5.65],[72.9,5.98],[73.9,5.71],[74.7,4.98],[74.9,4.46],[75.7,4.87],[76.9,6.05],[77.6,5.76],[78,6],[78.7,5.95],[80.7,4.98],[81.9,5.85],[82.7,6.02],[84.7,5.41],[84.9,5.08],[85.7,5.17],[85.9,5.6],[87,6.1],[88.8,6.2],[89.7,4.96],[89.9,4.93],[90.7,5.9],[91.9,6.32],[92.7,5.86],[93.1,6.24],[93.7,5.38],[93.9,6.2],[96.1,6.12],[97.1,6.37],[97.6,5.12],[98,5.85],[99.3,6.35],[101.3,6.12],[101.7,5.25],[102.3,4.95],[102.7,6.12],[103.2,5.83],[104.7,6.37],[105,6.13],[106,6.22],[106.7,4.88],[107.7,6.3],[108.1,6.4],[109,6],[109.7,5.16],[110,5.82],[112.1,5.89],[113.1,5.5],[115.7,5.8],[116,6.11],[118.7,5.68],[119,6.23],[119.7,5.85],[120,6.12],[121,4.62],[121.8,5.9],[123,5.48],[125,6.05],[126,5.89],[130.9,6.11],[146.1,6.02],[155.6,6.26],[180.4,6.09],[190.4,6.39],[245.5,6.87],[266.2,6.77],[301.1,7.16],[321.5,7.07],[346.5,7.87],[375.7,7.86],[385.8,8.09],[389.8,8.55],[406.1,8.33],[416.5,8.59],[445.9,8.62],[472.1,9.24],[565.9,9.74],[571,9.4],[589.8,9.76]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010",note:"Discovered on 21 February 1901 by Thomas Anderson in Edinburgh, and the brightest nova of the century until V603 Aql."},{id:"dn-gem-1912",kind:"nova",designation:"DN Gem",name:"Nova Geminorum 1912",raHours:6.9151,decDeg:32.14108,peakMagnitude:3.58,peakJd:241947675e-2,startJd:241947275e-2,lightCurve:[[0,11.7],[1,4.5],[4,3.58],[5,4.45],[5.5,5.32],[6,5.53],[6.5,5.11],[8,5.43],[8.5,5.16],[11,5.53],[11.5,5.13],[12,5.18],[13.75,4.5],[15.75,5.3],[18.75,6],[19.75,5.55],[26.75,6],[28.75,5.9],[31.75,6.6],[32.75,6.2],[33.75,6.5],[36.75,6.55],[39.75,6.2],[40.75,6.75],[41.75,7],[44.75,6.75],[52.75,6.75],[54.75,7.23],[58.25,7.5],[62.25,7.3],[64.25,7.47],[66.25,8.1],[70.25,7.5],[72.25,8.1],[78.25,7.55],[80.25,8.2],[86.25,7.2],[90.25,7.3],[92.25,7.8],[152.25,7.2],[160.25,7.4],[166.25,8.2],[168.25,8.2],[170.25,7.3],[180.25,7.4],[182.25,8],[186.25,7.5],[190.25,7.6],[192.25,8],[211.25,7.75],[227.25,8],[275.25,7.78],[315.25,8.6],[331.25,7.79],[339.25,8.27],[363.25,8.61],[443.25,8.93],[451.25,9.2],[535.25,10.3],[567.25,9.9],[615.25,10.8],[631.25,10.63],[647.25,10.88],[679.25,10.8],[695.25,11.07],[727.25,11]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"v603-aql-1918",kind:"nova",designation:"V603 Aql",name:"Nova Aquilae 1918",raHours:18.81518,decDeg:.58414,peakMagnitude:-.5,peakJd:242175475e-2,startJd:242174875e-2,lightCurve:[[0,11.3],[2,10.5],[4,6.6],[4.5,1.04],[6,-.5],[6.5,.18],[10,1.1],[10.5,.95],[12.75,1.89],[21.75,3.07],[23.75,3.76],[29.75,3.16],[34.75,3.5],[36.75,3.86],[44.75,3.79],[48.75,4.43],[52.75,3.84],[56.75,3.95],[57.75,4.04],[58.75,4.49],[59.75,4.42],[60.75,4.69],[62.75,4.6],[63.75,4.11],[64.75,3.97],[68.75,4.18],[70.75,4.65],[71.75,4.51],[73.75,4.73],[75.75,4.44],[79.75,4.85],[83.75,4.43],[89.75,4.88],[92.75,4.86],[94.75,4.58],[96.75,4.92],[99.75,5.05],[163.25,5.45],[167.25,5.7],[179.25,5.48],[191.25,5.8],[203.25,5.5],[247.25,5.9],[251.25,6.25],[257.25,5.5],[265.25,6.13],[281.25,6.33],[345.25,6.3],[385.25,6.73],[393.25,6.43],[425.25,6.71],[433.25,6.56],[461.25,7.27],[525.25,7.6],[541.25,7.47],[637.25,8.3],[669.25,8.17],[717.25,8.55],[749.25,8.4],[765.25,8.68],[885.25,8.75],[949.25,9.4],[1013.25,9.19],[1141.25,9.57],[1269.25,9.48],[1333.25,9.95],[1653.25,9.94],[1781.25,10.28],[1909.25,10.34],[2037.25,10.1],[2101.25,10.46],[2165.25,10.51],[2357.25,10.3],[2549.25,10.77],[2741.25,10.46],[2869.25,10.83],[3125.25,10.71],[3317.25,11.22],[3381.25,10.91],[3637.25,11.42],[3829.25,10.96],[3893.25,11.65],[3957.25,11.63],[4085.25,11.14],[4213.25,11.48],[4277.25,10.7],[4341.25,11.42],[4405.25,11.47],[4469.25,11.06],[4533.25,11.08],[4597.25,11.7],[4725.25,11.45],[4789.25,10.94]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010",note:"The brightest nova of the modern era, at magnitude -0.5 on 9-10 June 1918: as bright as Vega, in a summer evening sky, in wartime."},{id:"v476-cyg-1920",kind:"nova",designation:"V476 Cyg",name:"Nova Cygni 1920",raHours:19.97347,decDeg:53.61858,peakMagnitude:1.94,peakJd:242256025e-2,startJd:242255925e-2,lightCurve:[[0,2.7],[1,1.94],[3,2.07],[4.5,2.95],[8.25,4],[31.75,6.41],[35.75,7.23],[37.75,7.08],[41.75,7.33],[43.75,7.92],[45.75,8.2],[51.75,8.59],[63.75,8.82],[65.75,9.25],[71.75,8.93],[85.75,9.43],[87.75,9.05],[95.75,9.2],[97.75,8.67],[99.75,9.07],[112.75,8.78],[120.75,9.03],[128.75,8.67],[144.75,8.94],[152.75,8.73],[168.75,8.79],[176.75,9.28],[192.75,9],[216.75,9.6],[232.75,9.27],[240.75,9.5],[288.75,9.4],[296.75,9.6],[304.75,9.3],[320.75,9.73],[328.75,9.5],[336.75,9.8],[428.75,9.61],[476.75,10.01],[492.75,9.76],[508.75,9.87],[524.75,9.65],[556.75,9.87],[572.75,9.65],[620.75,10.22],[668.75,10.44],[684.75,10.23],[716.75,10.33],[756.75,10.66],[884.75,10.59],[948.75,10.96],[1108.75,10.96]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"rr-pic-1925",kind:"nova",designation:"RR Pic",name:"Nova Pictoris 1925",raHours:6.59335,decDeg:-62.64008,peakMagnitude:.95,peakJd:24243085e-1,startJd:24242995e-1,lightCurve:[[0,2.43],[5,2.35],[6,2.1],[7,2.4],[9,.95],[13,1.8],[14,1.7],[16,2.15],[18,2.2],[19,1.9],[23,3.1],[27,3.05],[31.5,3.58],[43.5,3.08],[47.5,3.15],[57.5,2.3],[59.5,1.65],[63.5,3.03],[65.5,2.84],[67.5,3.16],[69.5,2.4],[71.5,2.04],[73.5,2.05],[75.5,2.55],[79.5,3],[83.5,3.15],[116.5,3.54],[120.5,3.78],[124.5,3.67],[136.5,4.18],[148.5,4.34],[154.5,4.17],[194.5,4.43],[226.5,4.93],[234.5,4.8],[242.5,5.4],[250.5,5.5],[266.5,5.15],[298.5,5.6],[362.5,5.4],[414.5,5.7],[430.5,5.5],[494.5,6.2],[718.5,6.52],[830.5,6.3],[862.5,6.6],[878.5,6.4],[910.5,6.77],[958.5,6.67],[1062.5,7.07],[1318.5,7.35],[1590.5,8.12],[1718.5,8.25],[2486.5,8.59],[2614.5,8.47],[2742.5,8.7],[3382.5,8.6],[3766.5,8.97],[4022.5,8.79],[4150.5,9.22],[6710.5,10.29],[7414.5,11.03],[8438.5,10.96]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010",note:"A slow nova, and a southern one: more than two months within two magnitudes of its peak."},{id:"dq-her-1934",kind:"nova",designation:"DQ Her",name:"Nova Herculis 1934",raHours:18.12507,decDeg:45.85906,peakMagnitude:1.56,peakJd:24277935e-1,startJd:242778675e-2,lightCurve:[[0,3.4],[1.5,2.4],[3,2.67],[5.75,2.01],[6.75,1.56],[7.75,1.59],[11.75,2.97],[12.75,2.31],[14.75,3.07],[15.75,2.56],[16.75,2.51],[19.75,2.68],[23.75,2.53],[24.75,2.27],[26.75,2.58],[30.75,2.24],[31.75,2.63],[32.75,2.66],[34.75,2.11],[39.75,2.71],[41.75,2.31],[43.75,2.37],[46.75,3.64],[47.75,3.21],[50.75,3.23],[52.75,2.66],[55.75,2.56],[58.75,2.97],[60.75,2.77],[61.75,3.36],[63.75,3.43],[64.75,2.89],[65.75,3.22],[68.75,3.52],[69.75,2.95],[70.75,3.06],[71.75,2.7],[76.75,3.65],[79.75,3.74],[81.75,3.21],[83.75,3.75],[87.75,3.69],[92.75,4.04],[94.75,4.8],[97.75,4.24],[98.75,4.52],[100.75,4.08],[101.75,4.43],[105.75,4.58],[106.75,4.33],[107.75,4.73],[108.75,6.57],[109.75,8.08],[110.75,8.15],[111.75,8.56],[113.75,8.45],[114.75,9.15],[115.75,9.15],[116.75,9.59],[117.75,9.43],[118.75,9.8],[122.75,10.5],[123.75,10.28],[124.75,10.93],[127.75,10.83],[129.75,11.87],[131.75,12.42],[135.75,12.5],[137.75,12.9],[138.75,12.77],[139.75,13],[143.75,12],[144.75,12.33],[146.75,12.35],[147.75,11.64],[148.75,11.83],[150.75,10.9],[151.75,10.78],[152.75,11.17],[154.75,10.32],[155.75,10.4],[165.25,9.24],[185.25,7.74],[225.25,6.8],[273.25,6.72],[321.25,6.97],[333.25,6.79],[353.25,7],[357.25,6.82],[377.25,6.88],[401.25,7.29],[409.25,6.8],[413.25,6.8],[419.25,7.1],[435.25,7.09],[451.25,7.4],[475.25,7],[555.25,7.48],[823.25,7.83],[855.25,8.18],[1135.25,8.43],[1823.25,9.98],[1887.25,9.71],[2015.25,10.55],[2335.25,10.95]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010",note:"Lost about ten magnitudes in a few weeks from April 1935, when dust condensed around it, then came back to naked-eye brightness."},{id:"cp-lac-1936",kind:"nova",designation:"CP Lac",name:"Nova Lacertae 1936",raHours:22.26142,decDeg:55.61703,peakMagnitude:2.02,peakJd:242834025e-2,startJd:242833825e-2,lightCurve:[[0,4.03],[.5,2.9],[1,2.45],[2,2.02],[2.5,2.61],[4,3],[4.5,3.35],[5,3.3],[9.25,4.59],[14.25,5.45],[22.25,6.03],[23.25,6.3],[26.25,6.23],[38.25,6.74],[41.25,6.61],[50.25,7.35],[53.25,7.27],[57.25,7.7],[58.25,7.54],[60.25,7.55],[61.25,7.79],[71.25,7.6],[74.25,7.81],[76.25,8.3],[77.25,7.79],[86.25,8.21],[87.25,8],[88.25,8.25],[92.25,8.17],[94.25,8.47],[102.25,8.27],[103.25,8.7],[104.25,8.4],[110.25,8.66],[116.75,8.55],[122.75,8.83],[126.75,8.7],[140.75,9.06],[154.75,9.01],[164.75,9.36],[170.75,9.18],[174.75,9.48],[186.75,9.42],[188.75,9.73],[192.75,9.53],[200.75,9.74],[202.75,9.5],[204.75,9.77],[208.75,9.6],[214.75,9.75],[216.75,10.05],[222.75,9.7],[232.75,10.03],[236.75,9.82],[250.75,10.1],[254.75,9.9],[260.75,10.1],[264.75,9.8],[266.75,10.15],[268.75,10],[274.75,10.2],[276.75,9.9],[292.75,10.6],[294.75,10.6],[298.75,10.1],[318.75,10.35],[320.75,10.6],[322.75,10.3],[328.75,10.65],[332.75,10.3],[338.75,10.7],[348.75,10.53],[350.75,10.7],[354.75,10.37],[358.75,10.58],[365.75,10.43],[373.75,10.85],[421.75,10.94]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"cp-pup-1942",kind:"nova",designation:"CP Pup",name:"Nova Puppis 1942",raHours:8.19613,decDeg:-35.35139,peakMagnitude:.73,peakJd:243067675e-2,startJd:243067275e-2,lightCurve:[[0,.95],[4,.73],[4.5,1.3],[5.5,1.47],[6,2.01],[7.75,2.88],[8.75,2.97],[10.75,3.5],[11.75,4.02],[13.75,4.4],[14.75,3.8],[17.75,5],[18.75,4.93],[19.75,5.48],[23.75,5.5],[25.75,5.65],[26.75,5.99],[33.25,6.28],[45.25,6.6],[57.25,6.41],[81.25,6.85],[89.25,6.5],[97.25,6.67],[101.25,7],[113.25,6.66],[125.25,7.1],[135.25,6.96],[231.25,7.86],[279.25,7.8],[327.25,8.33],[407.25,8.18],[423.25,8.59],[471.25,8.53],[503.25,8.99],[551.25,8.97],[567.25,8.7],[583.25,9.47],[615.25,8.95],[655.25,9.5],[751.25,9.55],[815.25,10.09],[847.25,10.02],[879.25,10.48],[911.25,10.34],[1023.25,10.79],[1279.25,10.9]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010",note:"One of the fastest bright novae: two magnitudes gone in four days."},{id:"t-crb-1946",kind:"nova",designation:"T CrB",name:"Nova Coronae Borealis 1946",raHours:15.99171,decDeg:25.92017,peakMagnitude:2.5,peakJd:2431860,startJd:2431860,lightCurve:[[0,2.5],[1.5,3.5],[2.5,3.61],[6.5,5.68],[8.5,6.25],[10.5,7.35],[11.5,7.3],[12.5,8],[16,8.68],[32,9.77],[38,9.7],[40,9.45],[44,9.9],[48,9.57],[54,9.9],[58,9.71],[79,9.94],[107,9.76],[111,9.51],[115,8.71],[119,8.46],[159,8.01],[179,8.07],[183,8.47],[191,8.16],[199,8.7],[207,8.81],[211,9.33],[215,9.15],[223,9.47],[297,9.4],[345,9.75],[377,9.57],[425,9.8],[537,9.8]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010",note:"A recurrent nova. It erupted in 1866 and in 1946, and a third eruption was expected from 2024 on."},{id:"v446-her-1960",kind:"nova",designation:"V446 Her",name:"Nova Herculis 1960",raHours:18.956,decDeg:13.24147,peakMagnitude:4.83,peakJd:24370038e-1,startJd:24370033e-1,lightCurve:[[0,5.2],[.5,4.83],[2,4.9],[2.5,5.4],[3,5.05],[3.5,5.57],[4,5.25],[5,5.5],[6.5,5.4],[7.2,5.78],[8.2,5.6],[9.2,5.98],[10.2,5.92],[11.2,6.21],[16.2,6.1],[17.2,6.23],[18.2,7.2],[19.2,6.51],[20.2,6.78],[26.2,6.97],[27.2,7.24],[28.2,7.13],[29.2,7.45],[31.2,7.2],[40.7,7.57],[44.7,8.25],[46.7,7.84],[56.7,8.15],[60.7,8.9],[70.7,8.7],[72.7,8.14],[76.7,8.71],[80.7,8.47],[82.7,8.87],[86.7,8.57],[90.7,8.93],[107.7,9.11],[111.7,8.94],[115.7,9.27],[139.7,9.38],[151.7,9.91],[155.7,9.72],[173.7,10.51],[221.7,10.95]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"v533-her-1963",kind:"nova",designation:"V533 Her",name:"Nova Herculis 1963",raHours:18.23902,decDeg:41.85614,peakMagnitude:3,peakJd:24380605e-1,startJd:24380565e-1,lightCurve:[[0,8],[4,3],[4.5,3],[8,4],[13,3.95],[15,4.6],[21,4.53],[24,5.05],[27,5.15],[32,4.76],[34,4.98],[35,5.39],[37,5.43],[41,6.04],[49,6.02],[56.5,6.34],[60.5,6.11],[74.5,6.72],[102.5,6.99],[137.5,7.81],[197.5,8.31],[217.5,8.8],[225.5,8.57],[233.5,9.03],[237.5,8.78],[277.5,9.44],[301.5,9.46],[315.5,9.86],[323.5,9.73],[339.5,10.05],[355.5,10.74],[363.5,10.32],[371.5,10.6],[387.5,10.69],[427.5,10.38],[435.5,10.84],[443.5,10.74],[451.5,11.33],[459.5,10.98],[467.5,11.17],[507.5,11.16],[539.5,11.66],[603.5,11.7],[619.5,12.05],[651.5,12.03],[659.5,11.74],[667.5,10.9]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"hr-del-1967",kind:"nova",designation:"HR Del",name:"Nova Delphini 1967",raHours:20.70565,decDeg:19.16092,peakMagnitude:3.58,peakJd:2439838,startJd:2439646,lightCurve:[[0,11.9],[6,11.8],[12,8.8],[16,8.3],[20,6.7],[30,5.8],[36,5.51],[66,5.55],[78,5.35],[86,4.89],[96,5],[108,4.75],[136,5.13],[152,4.83],[182,4.93],[186,4.59],[192,3.58],[202,5],[220,5.46],[226,5.14],[230,5.45],[232,5.14],[236,5],[242,5.08],[244,4.59],[246,4.45],[254,5.3],[256,4.75],[260,5.69],[268,4.8],[274,4.94],[276,5.45],[280,5.2],[282,5.51],[286,5.58],[292,4.95],[294,5.16],[298,4.94],[311,5.09],[335,4.4],[367,5.76],[407,6.16],[423,6.55],[603,7.43],[907,8.32],[1451,9.41],[2347,10.75]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010",note:"An exceptionally slow nova: rose over months and stayed near magnitude 4 to 5 for most of 1967 and 1968."},{id:"lv-vul-1968",kind:"nova",designation:"LV Vul",name:"Nova Vulpeculae 1968",raHours:19.80012,decDeg:27.1715,peakMagnitude:4.5,peakJd:243996425e-2,startJd:243996325e-2,lightCurve:[[0,5],[1,4.5],[2,5],[2.5,4.86],[3,5.1],[3.5,4.88],[4,5.1],[5,4.9],[7,5.4],[8,5.23],[10.5,5.42],[12,5.82],[13,5.4],[13.5,5.74],[14,5.7],[14.5,6.08],[15,5.75],[15.5,5.86],[16,5.6],[17,5.8],[18,5.6],[20.5,6.34],[21,6.2],[22.5,6.84],[23,6.57],[24,6.98],[24.5,6.3],[25,7.1],[26,6.65],[34.25,7.48],[35.25,7.23],[39.25,7.32],[44.25,7.76],[45.25,7.49],[46.25,7.78],[50.25,7.84],[51.25,8.1],[53.25,7.9],[54.25,8.13],[56.25,8],[57.75,8.24],[67.75,8.52],[75.75,8.38],[83.75,8.69],[89.75,8.59],[125.75,9.32],[127.75,9.33],[129.75,8.98],[131.75,9.29],[135.75,9.43],[212.75,9.9],[220.75,10.16],[228.75,10.03],[236.75,10.3],[244.75,10.16],[264.75,10.54],[280.75,10.45],[296.75,10.79],[328.75,10.78]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"fh-ser-1970",kind:"nova",designation:"FH Ser",name:"Nova Serpentis 1970",raHours:18.51307,decDeg:2.61444,peakMagnitude:4.5,peakJd:244063425e-2,startJd:244063125e-2,lightCurve:[[0,7],[2,5],[3,4.5],[3.5,5],[4.5,4.6],[5.5,5],[6.5,4.68],[12.25,4.66],[16.25,5.3],[17.25,5.72],[18.25,5.3],[19.25,5.2],[23.25,5.84],[24.25,5.68],[27.25,5.9],[30.25,5.47],[32.25,5.9],[34.25,5.7],[43.25,6.28],[45.25,6.1],[50.25,6.62],[52.25,6.47],[57.25,6.63],[60.25,7.08],[61.25,6.87],[62.25,7.2],[63.25,6.85],[64.25,7.68],[65.25,7.3],[66.25,8.3],[67.25,7.93],[69.25,9.15],[71.25,9.2],[72.25,9.63],[74.25,9.9],[76.25,9.7],[77.25,10.25],[78.25,10.1],[79.25,10.4],[80.25,10.23],[81.25,10.57],[83.25,10.64],[85.25,10.35],[86.25,11.2],[87.25,10.1],[89.25,11.2],[96.25,11.35],[100.25,11.95],[102.25,11.1],[104.25,11.65],[106.25,11.5],[108.25,12.07],[114.75,11.32],[118.75,11.28],[122.75,10.93],[130.75,10.85],[134.75,10.52],[154.75,10.65],[162.75,10.12],[174.75,9.98],[178.75,10.34],[186.75,9.98],[214.75,10.25],[224.75,10.02],[240.75,10.2],[264.75,10],[272.75,10.2],[280.75,10.05],[288.75,10.4],[296.75,10],[348.75,10.7],[396.75,10.3],[444.75,10.73],[460.75,10.59],[540.75,10.94],[556.75,10.82]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"v1500-cyg-1975",kind:"nova",designation:"V1500 Cyg",name:"Nova Cygni 1975",raHours:21.19349,decDeg:48.15056,peakMagnitude:1.88,peakJd:244265525e-2,startJd:244265425e-2,lightCurve:[[0,2.44],[1,1.88],[1.5,1.88],[2.5,2.41],[3,3.38],[4,4.28],[8.25,5.81],[11.25,6.46],[22.25,7.35],[33.25,7.73],[34.25,7.97],[37.25,7.86],[40.25,8.3],[43.25,8.19],[48.25,8.6],[49.25,8.46],[66.25,9.04],[70.25,8.93],[75.25,9.23],[76.25,9.03],[80.25,9.39],[81.25,9.19],[83.25,9.35],[84.25,9.13],[86.25,9.39],[89.25,9.32],[90.25,9.54],[93.25,9.37],[105.75,9.86],[193.75,10.43],[201.75,10.7],[209.75,10.47],[257.75,10.94],[265.75,10.81]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010",note:"One of the fastest novae on record: discovered on 29 August 1975, at its peak of magnitude 1.9 within two days, and two magnitudes down again two days later."},{id:"v842-cen-1986",kind:"nova",designation:"V842 Cen",name:"Nova Centauri 1986",raHours:14.59794,decDeg:-57.6265,peakMagnitude:4.9,peakJd:244675975e-2,startJd:244675725e-2,lightCurve:[[0,5.6],[2.5,4.9],[3.5,5.1],[15.5,5.1],[17.5,5.75],[18.5,5.4],[20.5,5.5],[22.5,5.95],[30.5,6.15],[31.5,6.3],[32,7.5],[34.5,7.2],[38.5,7.5],[39,7],[41.5,7.15],[42.5,6.7],[44.5,7.23],[45.5,6.6],[53,9.3]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"sn-1987a",kind:"supernova",designation:"SN 1987A",name:"Supernova 1987A",raHours:5.59111,decDeg:-69.26975,peakMagnitude:2.98,peakJd:24469425e-1,startJd:24468495e-1,lightCurve:[[0,6.36],[1,6.11],[2,4.63],[4,4.45],[32,3.97],[56,3.15],[93,2.98],[105,3.35],[118,4.11],[134,4.43],[504,8.15],[617,10.27]],source:"V photometry compiled by the Open Supernova Catalog (Sternberg catalogue, IAU circulars, CTIO)",note:"In the Large Magellanic Cloud, 160 000 light years away: the nearest supernova since Kepler's, and invisible north of about 20° N."},{id:"v1974-cyg-1992",kind:"nova",designation:"V1974 Cyg",name:"Nova Cygni 1992",raHours:20.50879,decDeg:52.63078,peakMagnitude:4.27,peakJd:24486753e-1,startJd:24486718e-1,lightCurve:[[0,7.2],[1,5.23],[2,4.62],[3.5,4.27],[4.5,4.59],[6,4.5],[7,4.78],[7.5,4.52],[8,4.82],[10.7,5.25],[11.7,5.66],[16.7,5.85],[21.7,6.47],[22.7,6.3],[27.7,6.46],[29.7,6.83],[34.7,6.9],[35.7,7.25],[36.7,7],[37.7,7.16],[39.7,7.03],[43.7,7.41],[45.7,7.26],[50.7,7.45],[57.7,7.78],[58.7,8.13],[61.7,7.92],[64.7,8.19],[65.7,7.99],[71.7,8.22],[76.7,8.01],[128.2,8.72],[176.2,8.89],[192.2,9.15],[216.2,9.28],[232.2,9.07],[236.2,9.3],[390.2,10.99]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"v382-vel-1999",kind:"nova",designation:"V382 Vel",name:"Nova Velorum 1999",raHours:10.74678,decDeg:-52.42533,peakMagnitude:2.88,peakJd:245132225e-2,startJd:245132075e-2,lightCurve:[[0,2.99],[1.5,2.88],[2.5,3.46],[4.5,3.98],[5,4.32],[5.5,4.23],[7.5,4.85],[21.75,6.67],[30.25,7.2],[40.25,7.41],[93.25,7.95],[97.25,8.25],[101.25,8],[113.25,7.96],[129.25,8.5],[155.25,8.47],[163.25,9.1],[179.25,9],[187.25,8.7],[195.25,9.15],[211.25,9.23],[235.25,9.8],[243.25,9.71],[299.25,10.42],[383.25,10.52],[415.25,10.81]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"v1494-aql-1999",kind:"nova",designation:"V1494 Aql",name:"Nova Aquilae 1999",raHours:19.38482,decDeg:4.9555,peakMagnitude:4.11,peakJd:245151575e-2,startJd:245151425e-2,lightCurve:[[0,5.15],[.5,4.86],[1,4.27],[1.5,4.11],[2.5,4.35],[5,5.48],[10.5,6.26],[14.25,6.28],[20.25,7.43],[24.25,7.25],[25.25,7.63],[27.25,7.7],[29.25,7.42],[33.25,8.08],[35.25,8.03],[36.25,7.6],[37.25,7.6],[46.25,8.5],[54.25,8.28],[56.25,8.63],[58.25,8.4],[61.25,9.53],[62.25,9],[64.25,9.13],[69.25,8.58],[70.25,8.9],[72.25,8.88],[75.25,8.57],[77.25,9],[79.25,8.8],[81.25,9.7],[83.25,9.6],[85.25,9.8],[86.75,9.5],[88.75,9.54],[90.75,8.9],[92.75,8.85],[96.75,9.63],[102.75,9.7],[104.75,8.98],[106.75,8.73],[116.75,9.63],[118.75,9.6],[120.75,9.07],[122.75,9.26],[124.75,9.8],[128.75,9.36],[134.75,9.75],[147.75,9.92],[155.75,9.81],[259.75,10.96]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"v4743-sgr-2002",kind:"nova",designation:"V4743 Sgr",name:"Nova Sagittarii 2002",raHours:19.01926,decDeg:-22.00167,peakMagnitude:5,peakJd:245253775e-2,startJd:245253675e-2,lightCurve:[[0,5.2],[1,5],[2,5.89],[2.5,5.91],[3.5,6.43],[5,6.45],[5.5,6.86],[6,6.59],[7,6.77],[7.5,7.31],[8.5,6.99],[9,7.09],[10.5,7.86],[11,7.58],[11.5,7.89],[15.75,8.33],[17.75,8.18],[18.75,8.58],[19.75,8.44],[22.75,8.83],[23.75,8.6],[24.75,8.85],[27.75,8.83],[30.75,9.4],[31.75,9.09],[36.25,9.08],[38.25,9.34],[62.25,9.75],[66.25,10.1],[70.25,9.7],[74.25,10],[171.25,10.9]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"rs-oph-2006",kind:"nova",designation:"RS Oph",name:"Nova Ophiuchi 2006",raHours:17.83699,decDeg:-6.70792,peakMagnitude:4.8,peakJd:2453779,startJd:2453779,lightCurve:[[0,4.8],[1.25,4.97],[2.75,5.78],[3.25,5.7],[3.75,6.24],[4.25,6.05],[4.75,6.38],[5.25,6.3],[8.5,7.25],[14.5,7.95],[24.5,8.55],[29.5,9.08],[48,9.87],[80,10.28],[107,11.54],[119,11.54],[139,11.98],[147,11.83],[163,12.03],[171,11.97],[175,11.65],[183,11.84],[195,11.64],[203,11.8],[207,12.13],[219,11.45],[277,11.68],[325,11],[341,11.53],[357,11.62],[373,11.3],[405,11.5],[421,11.17],[469,10.96],[501,11.22],[549,10.75],[581,11.08],[597,10.98]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010",note:"A recurrent nova, erupting every twenty years or so (1898, 1907, 1933, 1945, 1958, 1967, 1985, 2006, 2021)."},{id:"v1280-sco-2007",kind:"nova",designation:"V1280 Sco",name:"Nova Scorpii 2007",raHours:16.96145,decDeg:-32.34325,peakMagnitude:3.8,peakJd:2454149,startJd:2454136,lightCurve:[[0,9.7],[13,3.8],[34,5.8],[103,15]],source:"AAVSO (discovery, peak, dust minimum); t2 from Das et al. 2008",note:"Faded from sight quickly when dust formed around it, three weeks after its peak."},{id:"v339-del-2013",kind:"nova",designation:"V339 Del",name:"Nova Delphini 2013",raHours:20.39186,decDeg:20.76772,peakMagnitude:4.4,peakJd:24565214e-1,startJd:24565214e-1,lightCurve:[[0,4.4],[11,6.4],[20,7.4]],source:"Gehrz et al. 2015 (peak, t2, t3)",note:"High in the summer evening sky of the northern hemisphere, and widely photographed."},{id:"v1369-cen-2013",kind:"nova",designation:"V1369 Cen",name:"Nova Centauri 2013",raHours:13.9126,decDeg:-59.15114,peakMagnitude:3.48,peakJd:245663965e-2,startJd:24566285e-1,lightCurve:[[0,5.33],[1.57,4.08],[2.75,3.73],[4.57,4.16],[5.96,4.15],[10.26,3.77],[11.15,3.48],[12.14,3.74],[14.17,4.78],[15.46,4.97],[23.16,4.22],[26.25,4.32],[27.31,4.82],[29.56,5.11],[32.66,4.71],[33.84,4.86],[36.05,4.46],[37.15,4.99],[41.42,4.59],[42.37,4.93],[43.37,4.82],[44.54,5.09],[49.95,5.38],[51.99,5.82],[54.21,5.77]],source:"AAVSO, binned by day, as plotted by Izzo 2017 (arXiv:1704.07214, figure 1)",note:"Discovered on 2 December 2013 by John Seach at magnitude 5.5, it flared several times, reaching about 3.3 around 14 December: the brightest nova of the century so far, and a southern one."},{id:"rs-oph-2021",kind:"nova",designation:"RS Oph",name:"Nova Ophiuchi 2021",raHours:17.83699,decDeg:-6.70792,peakMagnitude:4.6,peakJd:2459436,startJd:2459435,lightCurve:[[0,5],[1,4.6],[2.25,4.77],[3.75,5.58],[4.25,5.5],[4.75,6.04],[5.25,5.85],[5.75,6.18],[6.25,6.1],[9.5,7.05],[15.5,7.75],[25.5,8.35],[30.5,8.88],[49,9.67],[81,10.08],[108,11.34],[120,11.34],[140,11.78],[148,11.63],[164,11.83],[172,11.77],[176,11.45],[184,11.64],[196,11.44],[204,11.6],[208,11.93],[220,11.25],[278,11.48],[326,10.8],[342,11.33],[358,11.42],[374,11.1],[406,11.3],[422,10.97],[470,10.76],[502,11.02],[550,10.55],[582,10.88],[598,10.78]],source:"Recorded discovery and peak (8 and 9 August 2021); curve borrowed from its 2006 eruption",note:"RS Oph's latest eruption, discovered on 8 August 2021. The decline is its 2006 one."}];class cf{static UNIX_EPOCH_JD=24405875e-1;static aroundDate(e){const t=this.julianDayOf(e);return s0.filter(i=>this.magnitudeAt(i,t)!==void 0)}static appearancesAt(e,t){const i=this.julianDayOf(e),n=[];for(const s of s0){const r=this.magnitudeAt(s,i);r!==void 0&&n.push({outburst:s,position:Us.ofJ2000(s.raHours,s.decDeg,e,t),magnitude:r})}return n.sort((s,r)=>s.magnitude-r.magnitude)}static brightestAt(e,t){return this.appearancesAt(e,t)[0]}static byId(e){return s0.find(t=>t.id===e)}static magnitudeAt(e,t){const i=e.lightCurve,n=t-e.startJd;if(i.length===0||n<i[0][0]||n>i[i.length-1][0])return;let s=1;for(;s<i.length-1&&i[s][0]<n;)s++;const[r,a]=i[s-1]??i[0],[l,c]=i[s]??i[0];if(l===r)return a;const h=Math.min(1,Math.max(0,(n-r)/(l-r)));return a+h*(c-a)}static julianDayOf(e){return e.getTime()/864e5+this.UNIX_EPOCH_JD}}const w6=[{id:"quadrantids",code:"QUA",name:"Quadrantids",radiantRaHours:15.33,radiantDecDeg:49.7,start:{month:12,day:28},peak:{month:1,day:3},end:{month:1,day:12},peakZhr:110,velocityKmS:41,populationIndex:2.1},{id:"lyrids",code:"LYR",name:"April Lyrids",radiantRaHours:18.13,radiantDecDeg:33.3,start:{month:4,day:16},peak:{month:4,day:22},end:{month:4,day:25},peakZhr:18,velocityKmS:49,populationIndex:2.1},{id:"eta-aquariids",code:"ETA",name:"eta Aquariids",radiantRaHours:22.53,radiantDecDeg:-1,start:{month:4,day:19},peak:{month:5,day:6},end:{month:5,day:28},peakZhr:50,velocityKmS:66,populationIndex:2.4},{id:"alpha-capricornids",code:"CAP",name:"alpha Capricornids",radiantRaHours:20.47,radiantDecDeg:-9.2,start:{month:7,day:3},peak:{month:7,day:30},end:{month:8,day:15},peakZhr:5,velocityKmS:23,populationIndex:2.5},{id:"southern-delta-aquariids",code:"SDA",name:"Southern delta Aquariids",radiantRaHours:22.67,radiantDecDeg:-16.4,start:{month:7,day:12},peak:{month:7,day:30},end:{month:8,day:23},peakZhr:25,velocityKmS:41,populationIndex:3.2},{id:"perseids",code:"PER",name:"Perseids",radiantRaHours:3.22,radiantDecDeg:58,start:{month:7,day:17},peak:{month:8,day:12},end:{month:8,day:24},peakZhr:100,velocityKmS:59,populationIndex:2.2},{id:"southern-taurids",code:"STA",name:"Southern Taurids",radiantRaHours:3.47,radiantDecDeg:13,start:{month:9,day:10},peak:{month:10,day:10},end:{month:11,day:20},peakZhr:5,velocityKmS:27,populationIndex:2.3},{id:"draconids",code:"DRA",name:"October Draconids",radiantRaHours:17.47,radiantDecDeg:54,start:{month:10,day:6},peak:{month:10,day:8},end:{month:10,day:10},peakZhr:10,velocityKmS:20,populationIndex:2.6},{id:"orionids",code:"ORI",name:"Orionids",radiantRaHours:6.35,radiantDecDeg:15.6,start:{month:10,day:2},peak:{month:10,day:21},end:{month:11,day:7},peakZhr:20,velocityKmS:66,populationIndex:2.5},{id:"northern-taurids",code:"NTA",name:"Northern Taurids",radiantRaHours:3.87,radiantDecDeg:22,start:{month:10,day:20},peak:{month:11,day:12},end:{month:12,day:10},peakZhr:5,velocityKmS:29,populationIndex:2.3},{id:"leonids",code:"LEO",name:"Leonids",radiantRaHours:10.13,radiantDecDeg:21.6,start:{month:11,day:6},peak:{month:11,day:17},end:{month:11,day:30},peakZhr:15,velocityKmS:71,populationIndex:2.5},{id:"geminids",code:"GEM",name:"Geminids",radiantRaHours:7.47,radiantDecDeg:32.3,start:{month:12,day:4},peak:{month:12,day:14},end:{month:12,day:17},peakZhr:150,velocityKmS:35,populationIndex:2.6},{id:"ursids",code:"URS",name:"Ursids",radiantRaHours:14.47,radiantDecDeg:75.3,start:{month:12,day:17},peak:{month:12,day:22},end:{month:12,day:26},peakZhr:10,velocityKmS:33,populationIndex:3}],hc=6.5;class jl{static activeAt(e){return w6.flatMap(t=>{const i=this.nearness(t,e);return i<=0?[]:[{shower:t,zhr:t.peakZhr*i,nearness:i}]})}static nearness(e,t){const i=this.dayOfYear(t),n=this.dayOfYear(this.asDate(e.start)),s=this.dayOfYear(this.asDate(e.peak)),r=this.dayOfYear(this.asDate(e.end)),a=this.wrappedDelta(i,s),l=this.wrappedDelta(s,n),c=this.wrappedDelta(r,s);return a<0?a<-l?0:1+a/l:a>0?a>c?0:1-a/c:1}static observedRatePerHour(e,t,i,n=hc){if(t<=0)return 0;const s=hc-n;return e*Math.sin(t*Math.PI/180)/Math.pow(i,s)}static radiantPosition(e,t,i){return Us.ofJ2000(e.radiantRaHours,e.radiantDecDeg,t,i)}static dayOfYear(e){const t=Date.UTC(e.getUTCFullYear(),0,1);return Math.floor((Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate())-t)/864e5)+1}static asDate(e){return new Date(Date.UTC(2001,e.month-1,e.day))}static wrappedDelta(e,t){const i=e-t;return i>182?i-365:i<-182?i+365:i}}class vi{static QUIET_RATE_PER_HOUR=2;static APEX_RATE_PER_HOUR=8;static POPULATION_INDEX=3;static apexPosition(e,t){const i=Zt(e),n=new Cf(0,uR(e).elon-90,1),s=Vr(BR(i),Vg(n,i)),r=Of(s);return Wg(r.ra,r.dec,e,t)}static observedRatePerHour(e,t=hc){const i=vi.APEX_RATE_PER_HOUR*Math.max(0,Math.sin(e*Math.PI/180)),n=hc-t;return(vi.QUIET_RATE_PER_HOUR+i)/Math.pow(vi.POPULATION_INDEX,n)}static schedule(e){const t=new Nf(e.seed^1542469173);return Co.schedule(e).map(i=>{const n=vi.toCartesian({altitudeDeg:Math.asin(t.next())*180/Math.PI,azimuthDeg:t.between(0,360)}),s=i.fromRadiantDeg*Math.PI/180,r=vi.turnAround(n,t.between(0,360)),a={x:n.x*Math.cos(s)+r.x*Math.sin(s),y:n.y*Math.cos(s)+r.y*Math.sin(s),z:n.z*Math.cos(s)+r.z*Math.sin(s)};return{...i,radiant:vi.toHorizontal(a),bearingDeg:vi.bearingFrom(a,n)}})}static turnAround(e,t){const[i,n]=vi.basisAround(e),s=t*Math.PI/180;return{x:i.x*Math.cos(s)+n.x*Math.sin(s),y:i.y*Math.cos(s)+n.y*Math.sin(s),z:i.z*Math.cos(s)+n.z*Math.sin(s)}}static bearingFrom(e,t){const[i,n]=vi.basisAround(e),s=e.x*t.x+e.y*t.y+e.z*t.z,r=vi.normalise({x:t.x-e.x*s,y:t.y-e.y*s,z:t.z-e.z*s});return(Math.atan2(r.x*n.x+r.y*n.y+r.z*n.z,r.x*i.x+r.y*i.y+r.z*i.z)*180/Math.PI%360+360)%360}static basisAround(e){const t=Math.abs(e.y)<.9?{x:0,y:1,z:0}:{x:1,y:0,z:0},i=vi.normalise(vi.cross(e,t));return[i,vi.normalise(vi.cross(e,i))]}static toHorizontal(e){const t=Math.hypot(e.x,e.y,e.z)||1;return{altitudeDeg:Math.asin(Math.min(1,Math.max(-1,e.y/t)))*180/Math.PI,azimuthDeg:(Math.atan2(e.x,-e.z)*180/Math.PI%360+360)%360}}static appearanceOf(e){const t=vi.toCartesian(e.radiant??{altitudeDeg:90,azimuthDeg:0}),i=vi.turnAround(t,e.bearingDeg),n=e.fromRadiantDeg*Math.PI/180;return vi.toHorizontal({x:t.x*Math.cos(n)+i.x*Math.sin(n),y:t.y*Math.cos(n)+i.y*Math.sin(n),z:t.z*Math.cos(n)+i.z*Math.sin(n)})}static toCartesian(e){const t=e.altitudeDeg*Math.PI/180,i=e.azimuthDeg*Math.PI/180,n=Math.cos(t);return{x:n*Math.sin(i),y:Math.sin(t),z:-n*Math.cos(i)}}static cross(e,t){return{x:e.y*t.z-e.z*t.y,y:e.z*t.x-e.x*t.z,z:e.x*t.y-e.y*t.x}}static normalise(e){const t=Math.hypot(e.x,e.y,e.z)||1;return{x:e.x/t,y:e.y/t,z:e.z/t}}static TYPICAL_VELOCITY_KM_S=40}const Lb="https://ufoathome.org/tle/index.json";class mn{static MAX_ELEMENT_AGE_DAYS=7;static DAY_MS=864e5;fetchImpl;indexUrls;index;files=new Map;constructor(e={}){this.fetchImpl=e.fetchImpl??fetch.bind(globalThis),this.indexUrls=e.indexUrls??mn.defaultIndexUrls()}static defaultIndexUrls(){const e=[];return typeof location<"u"&&/^https?:$/.test(location.protocol)&&e.push(new URL("/tle/index.json",location.href).href),e.includes(Lb)||e.push(Lb),e}static FIRST_SNAPSHOT="2021-02-22";async covers(e){const t=Date.parse(`${mn.FIRST_SNAPSHOT}T00:00:00Z`)-mn.MAX_ELEMENT_AGE_DAYS*mn.DAY_MS;if(e.getTime()<t)return!1;const i=await this.loadIndex();return i?Object.values(i.index.kinds).some(n=>e.getTime()>=Date.parse(n.from)-mn.MAX_ELEMENT_AGE_DAYS*mn.DAY_MS&&e.getTime()<=Date.parse(n.to)+mn.MAX_ELEMENT_AGE_DAYS*mn.DAY_MS):!1}async at(e){const t=await this.loadIndex();if(!t)return;const{index:i,base:n}=t,s=[],r=[];for(const a of Object.keys(i.kinds)){const l=await this.kindAt(a,e,i,n);s.push(...l),r.push(this.coverageOf(a,e,i,l.length>0))}return{objects:s,coverage:r,credit:i.credit,creditUrl:i.source}}async kindAt(e,t,i,n){const s=t.getTime(),r=i.binDays*mn.DAY_MS,a=Math.floor(s/r),l=s-a*r<r/2?a-1:a+1,c=new Set(i.kinds[e].bins),h=[a,l].map(g=>new Date(g*r).toISOString().slice(0,10)).filter(g=>c.has(g));if(h.length===0)return[];const[d,...u]=await Promise.all([this.json(new URL(`objects-${e}.json`,n).href),...h.map(g=>this.binary(new URL(`${e}/${g}.bin`,n).href))]),f=new Map;for(const g of u)for(const m of mn.decode(g,i.recordBytes)){const v=f.get(m.norad);(!v||Math.abs(m.epochMs-s)<Math.abs(v.epochMs-s))&&f.set(m.norad,m)}const p=[];for(const g of f.values()){const m=Math.abs(g.epochMs-s)/mn.DAY_MS;if(m>mn.MAX_ELEMENT_AGE_DAYS)continue;const v=d[g.norad]??{name:String(g.norad)};v.launch&&Date.parse(`${v.launch}T00:00:00Z`)>s||p.push({norad:g.norad,name:v.name,kind:e,launch:v.launch,stdMag:v.stdMag,elements:g,ageDays:m})}return p}coverageOf(e,t,i,n){const{from:s,to:r}=i.kinds[e],a=t.getTime(),l=mn.MAX_ELEMENT_AGE_DAYS*mn.DAY_MS,c=n?"covered":a<Date.parse(s)-l?"before":a>Date.parse(r)+l?"after":"gap";return{kind:e,status:c,from:s,to:r}}static decode(e,t){const i=new DataView(e),n=[];for(let s=0;s+t<=e.byteLength;s+=t)n.push({norad:i.getUint32(s,!0),epochMs:i.getFloat64(s+4,!0),bstar:i.getFloat32(s+12,!0),inclinationDeg:i.getFloat32(s+16,!0),raanDeg:i.getFloat32(s+20,!0),eccentricity:i.getFloat32(s+24,!0),argOfPerigeeDeg:i.getFloat32(s+28,!0),meanAnomalyDeg:i.getFloat32(s+32,!0),meanMotion:i.getFloat64(s+36,!0)});return n}loadIndex(){return this.index??=(async()=>{for(const e of this.indexUrls)try{const t=await this.fetchImpl(e);if(!t.ok)continue;return{index:await t.json(),base:e}}catch{}})(),this.index}json(e){return this.cached(e,async t=>t.json())}binary(e){return this.cached(e,async t=>t.arrayBuffer())}cached(e,t){let i=this.files.get(e);return i||(i=this.fetchImpl(e).then(n=>{if(!n.ok)throw new Error(`${e}: ${n.status}`);return t(n)}),i.catch(()=>this.files.delete(e)),this.files.set(e,i)),i}}class x6{lowerM;upperM;add(e,t){if(!(e<=0)){if(t.behindM!==void 0){const i=pt.sizeMAt(t.behindM,e);this.lowerM=this.lowerM===void 0?i:Math.max(this.lowerM,i)}if(t.inFrontM!==void 0){const i=pt.sizeMAt(t.inFrontM,e);this.upperM=this.upperM===void 0?i:Math.min(this.upperM,i)}}}get sizeRange(){return{minM:this.lowerM,maxM:this.upperM}}get empty(){return this.lowerM===void 0&&this.upperM===void 0}get contradictory(){return this.lowerM!==void 0&&this.upperM!==void 0&&this.lowerM>this.upperM}distanceRangeAt(e){return e<=0?{}:{minM:this.lowerM===void 0?void 0:pt.distanceMAt(this.lowerM,e),maxM:this.upperM===void 0?void 0:pt.distanceMAt(this.upperM,e)}}clear(){this.lowerM=void 0,this.upperM=void 0}}class Po{static DEG_PER_SECOND=360/86164.0905;static degOver(e){return Math.max(0,e)*Po.DEG_PER_SECOND}static instants(e,t){if(!(t>0))return 1;const i=Po.degOver(e)/t;return i<1?1:Math.min(Po.MAX_INSTANTS,Math.max(2,Math.ceil(i)))}static MAX_INSTANTS=64}class vn{static EYE={apertureMm:7,exposureSeconds:.1,resolutionArcsec:60};static WAVELENGTH_M=55e-8;static ARCSEC_PER_RADIAN=180*3600/Math.PI;static UNKNOWN_CAMERA_FOCAL_MM=50;static UNKNOWN_CAMERA_DETAIL_UM=20;static get skyDriftArcsecPerSecond(){return Po.DEG_PER_SECOND*3600}static graspOf(e,t={}){const i=t.exposureSeconds??e.exposureSeconds,n=t.fNumber??e.fNumber;if(i===void 0||n===void 0||!(i>0)||!(n>0))return vn.EYE;const s=t.focalLengthMm??e.frame?.focalLengthMm??vn.UNKNOWN_CAMERA_FOCAL_MM,r=s/n,a=vn.resolutionArcsec(e,s,r);return{apertureMm:r,exposureSeconds:Math.min(i,vn.trailLimitedSeconds(a)),resolutionArcsec:a}}static resolutionArcsec(e,t,i){const s=(e.detailUm??vn.UNKNOWN_CAMERA_DETAIL_UM)/1e3/t*vn.ARCSEC_PER_RADIAN,r=1.22*vn.WAVELENGTH_M/(i/1e3)*vn.ARCSEC_PER_RADIAN;return Math.max(s,r)}static trailLimitedSeconds(e){return e/vn.skyDriftArcsecPerSecond}static gainOverEye(e,t={}){const i=vn.graspOf(e,t),n=vn.EYE,s=(i.apertureMm/n.apertureMm)**2,r=i.exposureSeconds/n.exposureSeconds,a=(n.resolutionArcsec/i.resolutionArcsec)**2;return 1.25*Math.log10(s*r*a)}static gainFor(e,t){const i=t.fieldOfViewDeg===void 0?void 0:Bt.focalLengthMmFor(e,t.fieldOfViewDeg);return vn.gainOverEye(e,{fNumber:t.fNumber,focalLengthMm:i,exposureSeconds:t.exposureSeconds})}}const Ob=111320,Bc=Math.PI/180,S6=1.02,E6=1;class ah{static of(e,t){const i=ah.sightings(e,t);if(i.length<2)return;const n=ah.baseline(i);if(!n)return;const{near:s,far:r,closedM:a}=n,l=Math.tan(r.widthDeg/2*Bc)===0?0:Math.tan(s.widthDeg/2*Bc)/Math.tan(r.widthDeg/2*Bc);if(l<S6)return;const c=a/(l-1),h=pt.sizeMAt(c,s.widthDeg),d=i.map(u=>({t:u.t,m:pt.distanceMAt(h,u.widthDeg)}));return{widthM:h,distanceM:d,nearestM:Math.min(...d.map(u=>u.m)),fromT:r.t,toT:s.t,closedM:a}}static sightings(e,t){return e.timeline.allKeyframes.flatMap(i=>{const n=i.shapes.find(a=>a.sourceId===t)?.shape,s=n?.angular?.widthDeg,r=at(e,i.t);return s===void 0||s<=0||r?.lat===void 0||r.lng===void 0?[]:[{t:i.t,widthDeg:s,lat:r.lat,lng:r.lng,sightAzimuthDeg:n?.aim?.azimuthDeg??r.headingDeg}]}).sort((i,n)=>i.t-n.t)}static baseline(e){let t;for(const i of e)for(const n of e){if(i.t>=n.t)continue;const s=ah.closedAlongSight(i,n),[r,a,l]=s>=0?[n,i,s]:[i,n,-s];l<E6||r.widthDeg<=a.widthDeg||(!t||l>t.closedM)&&(t={near:r,far:a,closedM:l})}return t}static closedAlongSight(e,t){const i=(t.lat-e.lat)*Ob,n=(t.lng-e.lng)*Ob*Math.cos(e.lat*Bc),s=(e.sightAzimuthDeg??0)*Bc;return i*Math.cos(s)+n*Math.sin(s)}}class Dn{static CONVENTIONAL_M=5;static NEAREST_M=.2;static MARGIN=1.1;static resolve(e){if(e.statedM!==void 0&&e.statedM>0)return{distanceM:Dn.atLeastNearest(e.statedM),basis:"stated"};if(e.hypothesisM!==void 0&&e.hypothesisM>0)return{distanceM:Dn.atLeastNearest(e.hypothesisM),basis:"hypothesis"};if(e.derivedM!==void 0&&e.derivedM>0)return{distanceM:Dn.atLeastNearest(e.derivedM),basis:"derived"};const t=Dn.largest(e.range?.minM,e.crossing?.behindM),i=Dn.smallest(e.range?.maxM,e.crossing?.inFrontM),n=t===void 0?void 0:t*Dn.MARGIN,s=i===void 0?void 0:i/Dn.MARGIN;return n!==void 0&&s!==void 0?{distanceM:Dn.atLeastNearest(n<=s?Math.sqrt(n*s):n),basis:"bounded"}:n!==void 0?{distanceM:Dn.atLeastNearest(n),basis:"bounded"}:s!==void 0&&s<Dn.CONVENTIONAL_M?{distanceM:Dn.atLeastNearest(s),basis:"bounded"}:{distanceM:Dn.CONVENTIONAL_M,basis:"conventional"}}static atLeastNearest(e){return Math.max(Dn.NEAREST_M,e)}static largest(...e){const t=e.filter(i=>i!==void 0&&i>0);return t.length===0?void 0:Math.max(...t)}static smallest(...e){const t=e.filter(i=>i!==void 0&&i>0);return t.length===0?void 0:Math.min(...t)}}const r0=Math.PI/180;class et{constructor(e,t,i){this.body=e,this.ground=t;const n=[...e.track].sort((s,r)=>s.t-r.t);this.keys=this.place(n,i);for(const s of n)et.collect(this.motionKeys,s.t,s.motions),et.collect(this.lightKeys,s.t,s.lights)}static EYE_HEIGHT_M=1.6;static MAX_RANGE_M=3e4;static DEFAULT_SIZE={widthM:1,lengthM:1,heightM:1};static DEFAULT_APPEARANCE={color:"#c8c8c8",albedo:.5,luminanceCdM2:0,transparency:0,haloScale:1};keys;motionKeys=new Map;lightKeys=new Map;static collect(e,t,i){for(const[n,s]of Object.entries(i??{})){const r=e.get(n)??[];r.push({t,value:s}),e.set(n,r)}}motionsAt(e){return et.channelsAt(this.motionKeys,e,0)}lightsAt(e){return this.lightKeys.size>0?et.channelsAt(this.lightKeys,e,void 0):void 0}static channelsAt(e,t,i){const n={};for(const[s,r]of e){let a=r.length-1;for(;a>=0&&r[a].t>t;)a--;if(a<0){i!==void 0&&(n[s]=i);continue}const l=r[a],c=r[Math.min(a+1,r.length-1)],h=c===l||c.t===l.t?0:Math.min(1,(t-l.t)/(c.t-l.t));n[s]=et.lerp(l.value,c.value,h)}return n}static eyeOf(e,t,i){const n=at(e,0),s=at(e,t),a=n?.lat!==void 0&&n.lng!==void 0&&s?.lat!==void 0&&s.lng!==void 0?vt(s.lat,s.lng,n.lat,n.lng):void 0,l=a?a.x:0,c=a?-a.z:0;return{eastM:l,northM:c,upM:i.heightAt(l,c)+et.EYE_HEIGHT_M+(s?.elevationM??0),headingDeg:s?.headingDeg}}static lineOfSightMeetsGround(e,t,i,n){const s=et.directionOf(t,i),r=c=>e.upM+s.upM*c-n.heightAt(e.eastM+s.eastM*c,e.northM+s.northM*c);let a=0,l=0;for(;l<et.MAX_RANGE_M;){if(l=a+Math.max(.5,a*.01),r(l)<=0){for(let c=0;c<30;c++){const h=(a+l)/2;r(h)<=0?l=h:a=h}return l}a=l}}static directionOf(e,t){const i=e*r0,n=t*r0;return{eastM:Math.sin(i)*Math.cos(n),northM:Math.cos(i)*Math.cos(n),upM:Math.sin(n)}}at(e){const t=this.keys;if(t.length===0||e<t[0].t)return;let i=t.length-1;for(;i>0&&t[i].t>e;)i--;const n=t[i];if(!n.present)return;const s=t[Math.min(i+1,t.length-1)],r=s===n||s.t===n.t?0:Math.min(1,(e-n.t)/(s.t-n.t)),a=et.lerp(n.eastM,s.eastM,r),l=et.lerp(n.northM,s.northM,r),c={widthM:et.lerp(n.sizeM.widthM,s.sizeM.widthM,r),lengthM:et.lerp(n.sizeM.lengthM,s.sizeM.lengthM,r),heightM:et.lerp(n.sizeM.heightM,s.sizeM.heightM,r)},h={headingDeg:et.lerpAngle(n.attitude.headingDeg,s.attitude.headingDeg,r),pitchDeg:et.lerp(n.attitude.pitchDeg,s.attitude.pitchDeg,r),rollDeg:et.lerp(n.attitude.rollDeg,s.attitude.rollDeg,r)};let d;if("aboveGroundM"in n.vertical&&"aboveGroundM"in s.vertical){const u=et.lerp(n.vertical.aboveGroundM,s.vertical.aboveGroundM,r);d=this.groundUnderFootprint(a,l,c,h.headingDeg)+u+c.heightM/2}else d=et.lerp(this.centreUpOf(n),this.centreUpOf(s),r);return{id:this.body.id,model:this.body.model,explains:this.body.explains??[],outlineNode:this.body.outlineNode,eastM:a,northM:l,upM:d,sizeM:c,attitude:h,appearance:{color:et.lerpColor(n.appearance.color,s.appearance.color,r),albedo:et.lerp(n.appearance.albedo,s.appearance.albedo,r),luminanceCdM2:et.lerp(n.appearance.luminanceCdM2,s.appearance.luminanceCdM2,r),transparency:et.lerp(n.appearance.transparency,s.appearance.transparency,r),haloScale:et.lerp(n.appearance.haloScale,s.appearance.haloScale,r)},flame:et.flameBetween(n.flame,s.flame,r),motions:this.motionsAt(e),lights:this.lightsAt(e),throwsFlame:this.body.track.some(u=>u.flame!==void 0&&u.flame.luminanceCdM2>0)}}static flameBetween(e,t,i){if(!e||e.luminanceCdM2<=0)return i>=1&&t&&t.luminanceCdM2>0?t:void 0;const n=e,s=t??e,r={...i<1?n:s,lengthM:et.lerp(n.lengthM,s.lengthM,i),widthM:et.lerp(n.widthM,s.widthM,i),luminanceCdM2:et.lerp(n.luminanceCdM2,s.luminanceCdM2,i)};return r.luminanceCdM2>0?r:void 0}centreUpOf(e){return"upM"in e.vertical?e.vertical.upM:this.groundUnderFootprint(e.eastM,e.northM,e.sizeM,e.attitude.headingDeg)+e.vertical.aboveGroundM+e.sizeM.heightM/2}groundUnderFootprint(e,t,i,n){const s=n*r0,r={eastM:Math.cos(s),northM:-Math.sin(s)},a={eastM:Math.sin(s),northM:Math.cos(s)};let l=this.ground.heightAt(e,t);for(const[c,h]of[[-1,-1],[1,-1],[-1,1],[1,1]]){const d=c*i.widthM/2,u=h*i.lengthM/2;l=Math.max(l,this.ground.heightAt(e+r.eastM*d+a.eastM*u,t+r.northM*d+a.northM*u))}return l}place(e,t){const i=[];let n;for(const s of e){const r=s.sizeM??n?.sizeM??et.DEFAULT_SIZE,a={headingDeg:s.attitude?.headingDeg??n?.attitude.headingDeg??0,pitchDeg:s.attitude?.pitchDeg??n?.attitude.pitchDeg??0,rollDeg:s.attitude?.rollDeg??n?.attitude.rollDeg??0},l={color:s.appearance?.color??n?.appearance.color??et.DEFAULT_APPEARANCE.color,albedo:s.appearance?.albedo??n?.appearance.albedo??et.DEFAULT_APPEARANCE.albedo,luminanceCdM2:s.appearance?.luminanceCdM2??n?.appearance.luminanceCdM2??et.DEFAULT_APPEARANCE.luminanceCdM2,transparency:s.appearance?.transparency??n?.appearance.transparency??et.DEFAULT_APPEARANCE.transparency,haloScale:s.appearance?.haloScale??n?.appearance.haloScale??et.DEFAULT_APPEARANCE.haloScale},c=this.positionOf(s,r,t)??(n&&{eastM:n.eastM,northM:n.northM,vertical:this.verticalOf(s,r)??n.vertical});if(!c)continue;const h=s.flame??n?.flame,d=s.present??n?.present??!0;n={t:s.t,...c,sizeM:r,attitude:a,appearance:l,flame:h,present:d},i.push(n)}return i}verticalOf(e,t){if(e.onGround)return{aboveGroundM:0};if(e.altitudeAboveGroundM!==void 0)return{aboveGroundM:e.altitudeAboveGroundM};if(e.altitudeM!==void 0)return{upM:e.altitudeM+t.heightM/2}}positionOf(e,t,i){if(e.eastM!==void 0&&e.northM!==void 0)return{eastM:e.eastM,northM:e.northM,vertical:this.verticalOf(e,t)??{aboveGroundM:0}};if(e.azimuthDeg===void 0||e.altitudeDeg===void 0)return;const n=i(e.t);if(!n)return;const s=e.distanceM??(e.onGround?et.lineOfSightMeetsGround(n,e.azimuthDeg,e.altitudeDeg,this.ground):void 0);if(s===void 0)return;const r=et.directionOf(e.azimuthDeg,e.altitudeDeg),a=n.eastM+r.eastM*s,l=n.northM+r.northM*s;return{eastM:a,northM:l,vertical:this.verticalOf(e,t)??{upM:n.upM+r.upM*s}}}static lerp(e,t,i){return e+(t-e)*i}static lerpColor(e,t,i){const n=et.rgbOf(e),s=et.rgbOf(t);return!n||!s?i<1?e:t:"#"+n.map((r,a)=>Math.round(et.lerp(r,s[a],i)).toString(16).padStart(2,"0")).join("")}static rgbOf(e){const t=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e);if(!t)return;const i=t[1].length===3?t[1].replace(/./g,"$&$&"):t[1];return[0,2,4].map(n=>parseInt(i.slice(n,n+2),16))}static lerpAngle(e,t,i){const n=((t-e)%360+540)%360-180;return((e+n*i)%360+360)%360}}class St{static A=6378137;static E2=.00669437999014;static DEG=Math.PI/180;static STANDARD_DISTANCE_KM=100;static DEFAULT_COLOR="#ffb347";static DEFAULT_TRAIN_S=1.5;static FADE_MS=600;static TRAIN_POINTS=8;static leadAt(e,t){const i=e.track;if(i.length<2||t<i[0].t||t>i[i.length-1].t)return;let n=0;for(;n<i.length-2&&i[n+1].t<t;)n++;const s=i[n],r=i[n+1],a=r.t-s.t,l=a>0?(t-s.t)/a:0,[c,h]=St.alongGreatCircle(s,r,l);return{lat:c,lng:h,heightM:(s.altitudeKm+(r.altitudeKm-s.altitudeKm)*l)*1e3}}static viewsAt(e,t,i){const n=[];for(const s of e){const r=s.track[0]?.t??0,a=s.track[s.track.length-1]?.t??0;s.fragments.forEach((l,c)=>{const h=l.fromT??r,d=l.untilT??a;if(t<h||t>d)return;const u=(l.lagS??0)*1e3,f=St.leadAt(s,t-u);if(!f)return;const p=St.seenFrom(i,f);if(p.altitudeDeg<0)return;const g=Math.min(St.FADE_MS,(d-h)/4),m=g>0?Math.min(1,(t-h)/g,(d-t)/g):1,v=-2.5*Math.log10(Math.max(m,.001)),b=l.absoluteMagnitude+5*Math.log10(p.distanceKm/St.STANDARD_DISTANCE_KM)+v,x=[p],y=(l.trainS??St.DEFAULT_TRAIN_S)*1e3;for(let w=1;w<=St.TRAIN_POINTS;w++){const S=Math.min(y*w/St.TRAIN_POINTS,t-h),A=St.leadAt(s,t-u-S);if(!A||(x.push(St.seenFrom(i,A)),S>=t-h))break}n.push({reentryId:s.id,fragmentId:l.id??String(c),head:p,magnitude:b,color:l.color??St.DEFAULT_COLOR,train:x})})}return n}static seenFrom(e,t){const i=St.ecef(e),n=St.ecef(t),s=n[0]-i[0],r=n[1]-i[1],a=n[2]-i[2],l=e.lat*St.DEG,c=e.lng*St.DEG,h=-Math.sin(c)*s+Math.cos(c)*r,d=-Math.sin(l)*Math.cos(c)*s-Math.sin(l)*Math.sin(c)*r+Math.cos(l)*a,u=Math.cos(l)*Math.cos(c)*s+Math.cos(l)*Math.sin(c)*r+Math.sin(l)*a,f=Math.hypot(h,d,u);return{altitudeDeg:Math.asin(u/f)/St.DEG,azimuthDeg:(Math.atan2(h,d)/St.DEG+360)%360,distanceKm:f/1e3}}static ecef(e){const t=e.lat*St.DEG,i=e.lng*St.DEG,n=Math.sin(t),s=St.A/Math.sqrt(1-St.E2*n*n);return[(s+e.heightM)*Math.cos(t)*Math.cos(i),(s+e.heightM)*Math.cos(t)*Math.sin(i),(s*(1-St.E2)+e.heightM)*n]}static alongGreatCircle(e,t,i){const n=h=>{const d=h.lat*St.DEG,u=h.lng*St.DEG;return[Math.cos(d)*Math.cos(u),Math.cos(d)*Math.sin(u),Math.sin(d)]},s=n(e),r=n(t),a=Math.max(-1,Math.min(1,s[0]*r[0]+s[1]*r[1]+s[2]*r[2])),l=Math.acos(a);let c;if(l<1e-12)c=s;else{const h=Math.sin((1-i)*l)/Math.sin(l),d=Math.sin(i*l)/Math.sin(l);c=[s[0]*h+r[0]*d,s[1]*h+r[1]*d,s[2]*h+r[2]*d]}return[Math.atan2(c[2],Math.hypot(c[0],c[1]))/St.DEG,Math.atan2(c[1],c[0])/St.DEG]}}class xt{static EARTH_RADIUS_KM=6371;static SHADOW_RADIUS_KM=xt.EARTH_RADIUS_KM+15;static PENUMBRA_KM=10;static SUN_ILLUMINANCE_LUX=127e3;static RAYLEIGH_PER_M=[58e-7,135e-7,331e-7];static SCALE_HEIGHT_M=8e3;static OZONE_GRAZING_DEPTH=[2.4,1.8,.24];static ANISOTROPY=.7;static ALBEDO=.99;static DEFAULTS={exhaustKgPerS:273,condensedShare:.1,particleRadiusUm:.5,expansionKmPerS:.15,initialRadiusKm:.5,lifetimeS:420,collarShare:.85,collarExpansionKmPerS:2.5,collarLifetimeS:20};static PROPELLANTS={"rp1-lox":{condensedShare:.1,particleRadiusUm:.5},"methane-lox":{condensedShare:.14,particleRadiusUm:.5},"hydrogen-lox":{condensedShare:.2,particleRadiusUm:.5},hypergolic:{condensedShare:.1,particleRadiusUm:.4},solid:{condensedShare:.33,particleRadiusUm:.8}};static G0=9.80665;static COLLAR_SPREAD_OF_EXHAUST_VELOCITY=.735;static plumeOf(e){const t={},i=e.vehicle?.engine;if(i){const n=i.specificImpulseS===void 0?void 0:i.specificImpulseS*xt.G0;i.thrustKN!==void 0&&n&&(t.exhaustKgPerS=i.thrustKN*1e3/n),n&&(t.collarExpansionKmPerS=n/1e3*xt.COLLAR_SPREAD_OF_EXHAUST_VELOCITY),i.propellant&&Object.assign(t,xt.PROPELLANTS[i.propellant])}return{...xt.DEFAULTS,...t,...e.plume}}static PUFF_EVERY_S=.5;static MAX_PUFFS=320;static DEG=Math.PI/180;static sunDirectionAt(e){const t=new Xr(0,0,-6378137),i=cc(de.Sun,e,t,!0,!0),n=(i.ra-Ww(e))*15*xt.DEG,s=i.dec*xt.DEG;return[Math.cos(s)*Math.cos(n),Math.cos(s)*Math.sin(n),Math.sin(s)]}static viewsAt(e,t,i,n){const s=[];for(const r of e){const a=xt.plumeOf(r),l=r.track[0]?.t??0,c=r.track[r.track.length-1]?.t??0,h=r.burnFromT??l,d=Math.min(r.burnUntilT??c,t);if(d<=h)continue;const u=Math.max(xt.PUFF_EVERY_S*1e3,(d-h)/xt.MAX_PUFFS),f=a.particleRadiusUm*1e-6,p=6/(4*917*f),g=a.exhaustKgPerS*(u/1e3)*a.condensedShare,m=[{share:1-a.collarShare,expansionKmPerS:a.expansionKmPerS,lifetimeS:a.lifetimeS},{share:a.collarShare,expansionKmPerS:a.collarExpansionKmPerS,lifetimeS:a.collarLifetimeS}];for(let v=d;v>=h;v-=u){const b=(t-v)/1e3;if(b>a.lifetimeS)break;const x=St.leadAt({id:r.id,track:r.track,fragments:[]},v);if(!x)continue;const y=St.seenFrom(i,x);if(y.altitudeDeg<0)continue;const w=xt.sunlightAt(x,n);if(w.lit<=0)continue;const S=St.leadAt({id:r.id,track:r.track,fragments:[]},Math.max(l,v-u)),A=S?xt.distanceKm(x,S):0,M=xt.scatteringPhase(i,x,n);for(const _ of m){if(_.share<=0||b>_.lifetimeS)continue;const I=a.initialRadiusKm+_.expansionKmPerS*b+A/2,R=3*g*_.share*p/(2*Math.PI*(I*1e3)**2),L=Math.max(0,1-(b/_.lifetimeS)**2),P=xt.SUN_ILLUMINANCE_LUX*xt.ALBEDO*M*R*L*w.lit;P<=0||s.push({launchId:r.id,centre:y,radiusDeg:Math.atan2(I,y.distanceKm)/xt.DEG,luminanceCdM2:P,sunTransmittance:w.transmittance,lit:w.lit,ageS:b})}}}return s}static sunlightAt(e,t){const i=xt.earthCentred(e),n=i[0]*t[0]+i[1]*t[1]+i[2]*t[2];if(n>=0)return{lit:1,transmittance:[1,1,1]};const s=Math.hypot(i[0]-n*t[0],i[1]-n*t[1],i[2]-n*t[2]),r=xt.PENUMBRA_KM,a=Math.min(1,Math.max(0,(s-(xt.SHADOW_RADIUS_KM-r/2))/r));if(a<=0)return{lit:0,transmittance:[0,0,0]};const l=Math.max(0,(s-xt.EARTH_RADIUS_KM)*1e3),c=Math.exp(-l/xt.SCALE_HEIGHT_M),h=Math.sqrt(2*Math.PI*xt.EARTH_RADIUS_KM*1e3*xt.SCALE_HEIGHT_M),d=Math.exp(-(((l/1e3-25)/15)**2)),u=[0,1,2].map(f=>Math.exp(-xt.RAYLEIGH_PER_M[f]*c*h-xt.OZONE_GRAZING_DEPTH[f]*d));return{lit:a,transmittance:u}}static scatteringPhase(e,t,i){const n=xt.earthCentred(e),s=xt.earthCentred(t),r=[n[0]-s[0],n[1]-s[1],n[2]-s[2]],a=Math.hypot(r[0],r[1],r[2])||1,l=-(r[0]*i[0]+r[1]*i[1]+r[2]*i[2])/a,c=xt.ANISOTROPY;return(1-c*c)/(4*Math.PI*(1+c*c-2*c*l)**1.5)}static distanceKm(e,t){const i=xt.earthCentred(e),n=xt.earthCentred(t);return Math.hypot(i[0]-n[0],i[1]-n[1],i[2]-n[2])}static earthCentred(e){const t=e.lat*xt.DEG,i=e.lng*xt.DEG,n=xt.EARTH_RADIUS_KM+e.heightM/1e3;return[n*Math.cos(t)*Math.cos(i),n*Math.cos(t)*Math.sin(i),n*Math.sin(t)]}}class qg{static FIRST_DAY="2022-01-01";static mayCover(e){return new Date(e).toISOString().slice(0,10)>=qg.FIRST_DAY}}class A6{constructor(e,t,i){this.citation=e,this.covers=t,this.load=i}loading;mayCover(e){return this.covers(e)}async between(e,t,i,n){try{return await(await this.provider()).between(e,t,i,n)}catch{return{status:"failed"}}}async describe(e,t){try{return await(await this.provider()).describe?.(e,t)}catch{return}}provider(){if(!this.loading){const e=this.load();this.loading=e,e.catch(()=>{this.loading===e&&(this.loading=void 0)})}return this.loading}}const _6="Aircraft positions: adsb.lol feeders and contributors, Open Database License 1.0 (https://www.adsb.lol/docs/open-data/historical/)",Ym=[{id:"adsb-lol",name:"adsb.lol",credit:"adsb.lol feeders and contributors, ODbL 1.0",creditUrl:"https://www.adsb.lol/docs/open-data/historical/",create:()=>new A6(_6,o=>qg.mayCover(o),async()=>new(await Ue(async()=>{const{AdsbLolArchiveProvider:o}=await import("./AdsbLolArchiveProvider-fy3504GB.js");return{AdsbLolArchiveProvider:o}},[],import.meta.url)).AdsbLolArchiveProvider)}];class Cn{static MAX_GAP_S=60;static FT_TO_M=.3048;static EARTH_RADIUS_KM=6371;static seenFrom(e,t,i){const n=Cn.positionAt(e,i);if(!n)return;const s=St.seenFrom(t,n.geo);if(!(s.altitudeDeg<0))return{track:e,sky:s,altitudeFt:n.altitudeFt,groundSpeedKt:n.groundSpeedKt,trackDeg:n.trackDeg,angularRateDegPerS:Cn.angularRate(e,t,i)}}static viewsAt(e,t,i){return e.flatMap(n=>Cn.seenFrom(n,t,i)??[])}static groundDistanceKm(e,t){const i=Math.PI/180,n=Math.sin((t.lat-e.lat)*i/2)**2+Math.cos(e.lat*i)*Math.cos(t.lat*i)*Math.sin((t.lng-e.lng)*i/2)**2;return 2*Cn.EARTH_RADIUS_KM*Math.asin(Math.min(1,Math.sqrt(n)))}static wrapLongitude(e){return((e+180)%360+360)%360-180}static positionAt(e,t){const i=e.points;if(i.length===0||t<i[0].t||t>i[i.length-1].t)return;let n=0;for(;n<i.length-1&&i[n+1].t<=t;)n++;const s=i[n],r=i[n+1]??s,a=r.t-s.t;if(a>Cn.MAX_GAP_S*1e3)return;const l=a>0?(t-s.t)/a:0,c=s.altitudeFt+(r.altitudeFt-s.altitudeFt)*l,h=(r.lng-s.lng+540)%360-180;return{geo:{lat:s.lat+(r.lat-s.lat)*l,lng:Cn.wrapLongitude(s.lng+h*l),heightM:c*Cn.FT_TO_M},altitudeFt:c,groundSpeedKt:s.groundSpeedKt,trackDeg:s.trackDeg}}static angularRate(e,t,i){const n=Cn.positionAt(e,i-500),s=Cn.positionAt(e,i+500);if(!n||!s)return;const r=Cn.unit(St.seenFrom(t,n.geo)),a=Cn.unit(St.seenFrom(t,s.geo)),l=Math.min(1,Math.max(-1,r[0]*a[0]+r[1]*a[1]+r[2]*a[2]));return Math.acos(l)*180/Math.PI}static unit(e){const t=e.altitudeDeg*Math.PI/180,i=e.azimuthDeg*Math.PI/180;return[Math.cos(t)*Math.sin(i),Math.cos(t)*Math.cos(i),Math.sin(t)]}}const Nb="https://ufoathome.org/fireballs/index.json";class Es{static FIRST_MONTH="2018-12";static STRIKING_MAGNITUDE=-1;static COLOR="#eef2ff";static TRAIN_S=.3;fetchImpl;indexUrls;index;months=new Map;constructor(e={}){this.fetchImpl=e.fetchImpl??fetch.bind(globalThis),this.indexUrls=e.indexUrls??Es.defaultIndexUrls()}static defaultIndexUrls(){const e=[];return typeof location<"u"&&/^https?:$/.test(location.protocol)&&e.push(new URL("/fireballs/index.json",location.href).href),e.includes(Nb)||e.push(Nb),e}static mayCover(e){return new Date(e).toISOString().slice(0,7)>=Es.FIRST_MONTH}async credit(){return(await this.loadIndex())?.index.credit}async between(e,t){if(!Es.mayCover(t))return;const i=await this.loadIndex();if(!i)return;const n=new Set([new Date(e).toISOString().slice(0,7),new Date(t).toISOString().slice(0,7)]);return[...n].some(r=>r>=i.index.from&&r<=i.index.to)?(await Promise.all([...n].filter(r=>i.index.months.includes(r)).map(r=>this.monthOf(r,i.base)))).flat().filter(r=>r.t>=e&&r.t<=t):void 0}static seenFrom(e,t){const i=Es.peakFraction(e),n={lat:e.from[0]+(e.to[0]-e.from[0])*i,lng:e.from[1]+(e.to[1]-e.from[1])*i,heightM:e.peakHeightKm*1e3},s=St.seenFrom(t,n);if(!(s.altitudeDeg<0))return{record:e,peak:s,magnitude:e.peakMagnitude+5*Math.log10(s.distanceKm/St.STANDARD_DISTANCE_KM)}}static asReentry(e,t){const i=e.t-t,n=i+Math.max(e.durationS,.1)*1e3;return{id:`gmn-${e.id}`,track:[{t:i,lat:e.from[0],lng:e.from[1],altitudeKm:e.from[2]},{t:n,lat:e.to[0],lng:e.to[1],altitudeKm:e.to[2]}],fragments:[{absoluteMagnitude:e.peakMagnitude,color:Es.COLOR,trainS:Es.TRAIN_S}]}}static peakFraction(e){const t=e.from[2]-e.to[2];return Math.abs(t)<1e-6?.5:Math.min(1,Math.max(0,(e.from[2]-e.peakHeightKm)/t))}loadIndex(){return this.index??=(async()=>{for(const e of this.indexUrls)try{const t=await this.fetchImpl(e);if(t.ok)return{index:await t.json(),base:e}}catch{}})(),this.index}monthOf(e,t){let i=this.months.get(e);return i||(i=this.fetchImpl(new URL(`${e}.json`,t).href).then(n=>n.ok?n.json():[]).catch(()=>[]),this.months.set(e,i)),i}}const vl=Math.PI/180,zc=180/Math.PI;class Ai{constructor(e){this.timeline=e}static DIRECTION_TOLERANCE_DEG=1;static SIZE_TOLERANCE=1.5;static RINGS=12;static SEGMENTS=24;at(e,t,i,n){const s=[];for(const r of t){const a=Ai.projectionOf(r,i,n?.(r));if(a)for(const l of r.explains){const c=this.timeline.getInterpolatedShapeAt(e,l);!c||c.transparency>=1||s.push({...Ai.compare(l,r.id,{aim:c.aim,angular:c.angular},a),title:c.title})}}return s}static compare(e,t,i,n){const s=[],r=i.aim?Ai.separationDeg(i.aim,n.aim):void 0;if(r!==void 0){const c=Math.max(i.angular?.widthDeg??0,n.angular.widthDeg)/2;r>Math.max(Ai.DIRECTION_TOLERANCE_DEG,c)&&s.push("direction")}const a=i.angular&&i.angular.widthDeg>0?n.angular.widthDeg/i.angular.widthDeg:void 0,l=i.angular&&i.angular.heightDeg>0?n.angular.heightDeg/i.angular.heightDeg:void 0;return a!==void 0&&!Ai.withinSize(a)&&s.push("width"),l!==void 0&&!Ai.withinSize(l)&&s.push("height"),{sourceId:e,bodyId:t,stated:i,predicted:n,separationDeg:r,widthRatio:a,heightRatio:l,disagreements:s}}static projectionOf(e,t,i){const n=i&&i.length>0?i:Ai.outlineOf(e),s=i&&i.length>0?Ai.centreOf(i):e,r=Ai.normalized({eastM:s.eastM-t.eastM,northM:s.northM-t.northM,upM:s.upM-t.upM});if(!r)return;const a=Ai.normalized({eastM:r.northM,northM:-r.eastM,upM:0})??{eastM:1,northM:0,upM:0},l=Ai.cross(a,r);let c=1/0,h=-1/0,d=1/0,u=-1/0;for(const f of n){const p={eastM:f.eastM-t.eastM,northM:f.northM-t.northM,upM:f.upM-t.upM},g=Ai.dot(p,r);if(g<=0)return;const m=Math.atan2(Ai.dot(p,a),g),v=Math.atan2(Ai.dot(p,l),g);c=Math.min(c,m),h=Math.max(h,m),d=Math.min(d,v),u=Math.max(u,v)}return{aim:{azimuthDeg:(Math.atan2(r.eastM,r.northM)*zc+360)%360,altitudeDeg:Math.asin(Math.max(-1,Math.min(1,r.upM)))*zc},angular:{widthDeg:(h-c)*zc,heightDeg:(u-d)*zc}}}static centreOf(e){const t=i=>(Math.min(...e.map(n=>n[i]))+Math.max(...e.map(n=>n[i])))/2;return{eastM:t("eastM"),northM:t("northM"),upM:t("upM")}}static separationDeg(e,t){const i=e.altitudeDeg*vl,n=t.altitudeDeg*vl,s=Math.sin(i)*Math.sin(n)+Math.cos(i)*Math.cos(n)*Math.cos((e.azimuthDeg-t.azimuthDeg)*vl);return Math.acos(Math.max(-1,Math.min(1,s)))*zc}static withinSize(e){return e<=Ai.SIZE_TOLERANCE&&e>=1/Ai.SIZE_TOLERANCE}static outlineOf(e){const t=e.sizeM.widthM/2,i=e.sizeM.lengthM/2,n=e.sizeM.heightM/2,s=[],r=e.model.url===void 0?e.model.id:void 0;if(r!==void 0&&r!=="box"&&v2.includes(r))for(let d=0;d<=Ai.RINGS;d++){const u=d/Ai.RINGS*Math.PI;for(let f=0;f<Ai.SEGMENTS;f++){const p=f/Ai.SEGMENTS*2*Math.PI;s.push([t*Math.sin(u)*Math.cos(p),i*Math.sin(u)*Math.sin(p),n*Math.cos(u)])}}else for(const d of[-t,t])for(const u of[-i,i])for(const f of[-n,n])s.push([d,u,f]);const l=e.attitude.headingDeg*vl,c=e.attitude.pitchDeg*vl,h=e.attitude.rollDeg*vl;return s.map(([d,u,f])=>{const p=d*Math.cos(h)+f*Math.sin(h),g=-d*Math.sin(h)+f*Math.cos(h),m=u*Math.cos(c)-g*Math.sin(c),v=u*Math.sin(c)+g*Math.cos(c);return{eastM:e.eastM+p*Math.cos(l)+m*Math.sin(l),northM:e.northM-p*Math.sin(l)+m*Math.cos(l),upM:e.upM+v}})}static dot(e,t){return e.eastM*t.eastM+e.northM*t.northM+e.upM*t.upM}static cross(e,t){return{eastM:e.northM*t.upM-e.upM*t.northM,northM:e.upM*t.eastM-e.eastM*t.upM,upM:e.eastM*t.northM-e.northM*t.eastM}}static normalized(e){const t=Math.hypot(e.eastM,e.northM,e.upM);return t>1e-9?{eastM:e.eastM/t,northM:e.northM/t,upM:e.upM/t}:void 0}}xf();const T6={sun:"Sun",moon:"Moon",Venus:"Venus",Mars:"Mars",Jupiter:"Jupiter",Saturn:"Saturn"},I6="{name} — mag {mag}, {alt}° above the horizon",D6="{name} — {size}, {distance} away",R6="{name} — satellite, mag {mag}, {height} km up",x2="satellites-change",S2="fireballs-change",C6="aircraft-change",k6="rr0-confrontation",P6="{name} — mag {mag}, {alt}° below the horizontal",a0="Credits",Fb="comet:",Ub="nova:",Bb={building:"Building",tree:"Tree",shrub:"Shrub",bridge:"Bridge",wire:"Overhead line",crop:"Crop row",terrace:"Terrace (restanque)",mound:"Stone heap",wall:"Dry-stone wall",streetlight:"Streetlight",vehicle:"Vehicle",observer:"Observer",aircraft:"Aircraft",entity:"Being"},L6=new URL(""+new URL("lunar-relief.bin-ByThqxUn.gz",import.meta.url).href,import.meta.url).href,O6=new URL(""+new URL("stars-mag7.5-B43R6Wvg.bin",import.meta.url).href,import.meta.url).href,N6=new URL(""+new URL("stars-mag7.5-9-BLV2tFmZ.bin",import.meta.url).href,import.meta.url).href,F6=-18,U6={sun:{altitudeDeg:-3,azimuthDeg:180,magnitude:-26.7},moon:{altitudeDeg:-90,azimuthDeg:0,phase:{phaseFraction:0,illuminatedFraction:0},magnitude:-12.7},planets:[]},Gd={lat:0,lng:0,elevationM:0,headingDeg:void 0,pitchDeg:0,fovDeg:60};class Vt extends HTMLElement{creditsButton;set ownCredits(e){this.creditsButton.hidden=!e}static get observedAttributes(){return["src","star-catalog-src","deep-star-catalog-src","show-compass","max-pixel-ratio",Bl,zl]}shadow;stageElement;frameElement;sceneCanvas;busyElement;busyNote;loaderNote;loaderNotVideo;ufoElement;sceneRenderer;hoverTooltip;holding=!1;resizeObserver;sizeEstimates=new Map;sizeEstimatesFor;distanceHypotheses=new Map;depths=new Map;directionScratch=new D;meteorScheduleFor;lightningScheduleFor;lightningFlashes=[];lastLightningT;lastTimeMs=0;interpretationShown;confrontationReadings=[];confrontationSignature="";comparing=!1;inTheRound=!0;lastSkyKey;starCatalog;starCatalogRequest=0;static tleArchive=new mn;satellitesFor;satelliteRequest=0;satelliteStatus="none";satellites;satellitePassesMemo;static fireballArchive=new Es;fireballs;static aircraftProviders=new Map;static SOUND_LOOKBACK_MS=3e5;static NO_CONTRAILS=[];static upperAirProviders=new Map;static NO_PRESENCE=new Map;aircraftSource=Ym[0];static trafficRuntimeLoading;static trafficRuntime;static loadTrafficRuntime(){return Vt.trafficRuntimeLoading??=Ue(()=>import("./trafficRuntime-j3m3LpCc.js"),__vite__mapDeps([2,1]),import.meta.url).then(e=>Vt.trafficRuntime=e),Vt.trafficRuntimeLoading.catch(()=>{Vt.trafficRuntimeLoading=void 0}),Vt.trafficRuntimeLoading}traffic;lastSun;decorMemo;seatedMemo;starCatalogDepth=0;weatherAudio=new M6;vehicleAudio=new rE;aircraftAudio;vehicleHearing=new Nu;decorAircraftHearing;decorModelSounds=new Map;thunderTimeoutId;handleFullscreenChange=()=>this.resizeToStage();handlePointerMove=e=>{if(this.sceneRenderer.setCompassHovered(!0),this.holding){this.hoverTooltip.hidden=!0;return}const t=this.ufoElement.canvasElement,i=t.getBoundingClientRect();if(i.width===0||i.height===0)return;const n=(e.clientX-i.left)/i.width*t.width,s=(e.clientY-i.top)/i.height*t.height;if(this.ufoElement.hasVisibleShapeAt(n,s)){this.hoverTooltip.hidden=!0;return}const r=(e.clientX-i.left)/i.width*2-1,a=-((e.clientY-i.top)/i.height*2-1),l=this.pickAt(r,a);l?this.showHoverTooltip(e,e.altKey&&l.detail?l.detail():l.name):this.hoverTooltip.hidden=!0};pickAt(e,t){const i=this.naming,n=i.names,s=this.sceneRenderer.pickBodyAt(e,t);if(s)return{kind:"sky",id:s,name:this.bodyName(s)};const r=this.interpretationShown?this.sceneRenderer.pickInterpretationBodyAt(e,t):void 0,a=r?this.interpretationShown?.bodies.find(p=>p.id===r):void 0,l=a?this.said.read(a.title)||(a.model.id==="figure"?i.decorKind("entity",Bb.entity):void 0):void 0;if(r!==void 0&&l)return{kind:"body",id:r,name:l};const c=this.pickDecorAt(e,t),h=c?this.ufoElement.sighting.decor.find(p=>p.id===c):void 0;if(h){const p=this.said.read(h.title)||i.decorKind(h.kind,Bb[h.kind]);return{kind:"decor",id:h.id,name:p,detail:()=>this.decorTooltip(h,p)}}const d=this.trafficTooltipAt(e,t);if(d)return{kind:"traffic",name:d};const u=this.sceneRenderer.pickSatelliteAt(e,t);if(u)return{kind:"satellite",name:(n?.satelliteTooltip??R6).replace("{name}",u.name).replace("{mag}",u.magnitude.toLocaleString(void 0,{maximumFractionDigits:1})).replace("{height}",Math.round(u.heightKm).toLocaleString())};const f=this.sceneRenderer.pickStarAt(e,t);if(f){const p=f.star.mag,g=f.altitudeDeg;return{kind:"star",name:(g<0?n?.starTooltipBelow??P6:n?.starTooltip??I6).replace("{name}",i.star(f.star)).replace("{mag}",p.toLocaleString(void 0,{maximumFractionDigits:Math.abs(p)<1?2:1})).replace("{alt}",String(Math.round(Math.abs(g))))}}}decorTooltip(e,t){const i=c=>c.toLocaleString(void 0,{maximumFractionDigits:c<10?1:0}),n=Fe.sizeOf(e),s=this.sceneRenderer.decorDistanceM(e.id),r=s===void 0?"":s>=1e3?`${(s/1e3).toLocaleString(void 0,{maximumFractionDigits:1})} km`:`${i(s)} m`;return(this.naming.names?.decorTooltip??D6).replace("{name}",t).replace("{size}",`${i(n.widthM)} × ${i(n.lengthM)} × ${i(n.heightM)} m`).replace("{distance}",r)}bodyName(e){const t=e.startsWith(Fb)?e.slice(Fb.length):void 0,i=t?w2.find(r=>r.id===t):void 0;if(i)return this.naming.comet(i);const n=e.startsWith(Ub)?cf.byId(e.slice(Ub.length)):void 0;if(n)return this.naming.nova(n);const s=T6[e];return s===void 0?e:this.naming.body(e,s)}get naming(){return this.sceneNaming}sceneNaming=new lf;namesLanguage="en";async loadSceneNames(){const e=ch(_s.preferencesFor(this),ph);if(e===this.namesLanguage)return;this.namesLanguage=e;const t=await xM(e);e===this.namesLanguage&&this.applySceneNaming(new lf(t))}setBusy(e,t=""){this.busyElement.hidden=!e,this.busyNote.textContent=e?t:"",this.busyElement.setAttribute("aria-label",t),this.busyElement.setAttribute("aria-busy",String(e))}renderLoaderText(e,t){let i=0;const n=(s,r)=>{s.setAttribute("aria-label",r),s.replaceChildren(),r.split(" ").forEach((a,l)=>{l>0&&s.append(" ");const c=document.createElement("span");c.className="scene-loader-word",c.setAttribute("aria-hidden","true");for(const h of a){const d=document.createElement("span");d.className="scene-loader-letter",d.style.setProperty("--i",String(i++)),d.textContent=h,c.append(d)}s.append(c),i++})};n(this.loaderNotVideo,e),i+=6,n(this.loaderNote,t)}applySceneNaming(e){this.sceneNaming=e;const t=e.names?.credits??a0;this.creditsButton.title=t,this.creditsButton.setAttribute("aria-label",t),e.names&&this.renderLoaderText(e.names.notAVideo,e.names.isASimulation),this.sceneRenderer.setCompassPoints(e.names?.compassPoints)}showHoverTooltip(e,t){this.hoverTooltip.textContent=t,this.hoverTooltip.hidden=!1;const i=this.stageElement.getBoundingClientRect();this.hoverTooltip.style.left=`${e.clientX-i.left+12}px`,this.hoverTooltip.style.top=`${e.clientY-i.top+12}px`}handlePointerLeave=()=>{this.hoverTooltip.hidden=!0,this.sceneRenderer.setCompassHovered(!1)};handleLightningFlash(e){clearTimeout(this.thunderTimeoutId),this.thunderTimeoutId=window.setTimeout(()=>this.weatherAudio.playThunder(),qi.thunderDelayMs(e))}handleFirstInteraction=()=>{this.weatherAudio.resume(),this.vehicleAudio.resume(),this.aircraftAudio?.resume(),!this.interacted&&(this.interacted=!0,this.setWeather(Bh(this.ufoElement.sighting,this.lastTimeMs)))};interacted=!1;applyLevel(){const e=this.ufoElement.level;this.weatherAudio.setLevel(e),this.vehicleAudio.setLevel(e),this.aircraftAudio?.setLevel(e)}handlePageGesture=()=>{this.ufoElement.playbackState==="playing"&&this.handleFirstInteraction()};unlockIfAlreadyActivated(){this.interacted||navigator.userActivation?.hasBeenActive&&this.handleFirstInteraction()}static GESTURES=["pointerdown","pointerup","touchend","click","keydown"];handleTimeUpdate=e=>{this.lastTimeMs=e.detail.time,this.syncAnimationsToPlayback(),this.updateAstronomy(this.lastTimeMs),this.ufoElement.playbackState==="playing"&&this.sceneRenderer.frame(performance.now()),this.ufoElement.repaintChrome()};syncAnimationsToPlayback(){const e=this.ufoElement.playbackState==="playing";this.sceneRenderer.setAnimationsRunning(e,e),this.weatherAudio.setPaused(!e),this.vehicleAudio.setPaused(!e),this.aircraftAudio?.setPaused(!e),e&&this.unlockIfAlreadyActivated(),e||clearTimeout(this.thunderTimeoutId)}constructor(){super(),this.shadow=this.attachShadow({mode:"open"});const e=document.createElement("template");e.innerHTML=`<style>${lE}</style>${oE}`,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 Ze(this.sceneCanvas);const t=this.shadow.getElementById("scene-loader");this.loaderNote=this.shadow.getElementById("scene-loader-note"),this.loaderNotVideo=this.shadow.getElementById("scene-loader-not-video"),this.renderLoaderText("This is not a video","It is a real-time simulation."),this.busyElement=this.shadow.getElementById("scene-busy"),this.busyNote=this.shadow.getElementById("scene-busy-note"),this.sceneRenderer.onFirstFrameHold=s=>{t.hidden=!s,this.holding=s,s&&(this.hoverTooltip.hidden=!0),this.ufoElement.captionHeld=s,this.ufoElement.holdClock(s)},this.hoverTooltip=this.shadow.getElementById("hover-tooltip"),this.ufoElement=document.createElement(E0),this.ufoElement.classList.add("ufo-overlay"),this.ufoElement.paintsShapes=!1,this.forwardPlayerAttributes(),this.ufoElement.addEventListener("lookat",s=>this.lookToward(s.detail)),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.creditShownExternally=!0,this.creditsButton=this.shadow.getElementById("credits-button");const i=this.shadow.getElementById("credits-panel"),n=this.shadow.getElementById("credits-list");i.addEventListener("beforetoggle",s=>{s.newState==="open"&&qn.fill(n,this)}),this.creditsButton.title=a0,this.creditsButton.setAttribute("aria-label",a0),this.sceneRenderer.onMapSubjectBounds=s=>this.ufoElement.setMapSubjectBounds(s),this.ufoElement.addEventListener("timeupdate",this.handleTimeUpdate),this.ufoElement.seekPreviewPainter=(s,r)=>this.seekPreviewOf(r).paint(s,r),this.ufoElement.addEventListener("mutedchange",()=>this.applyLevel()),this.ufoElement.ambientSound=s=>s.vehicle!==void 0||s.decor.some(r=>r.engine!==void 0)||s.weatherTrack.allKeyframes.some(r=>r.weather.precipitationType!=="none"||r.weather.windSpeed>1),this.ufoElement.addEventListener("referenceview",s=>this.applyReferenceView(s.detail)),this.ufoElement.addEventListener("traceview",s=>this.sceneRenderer.setTracesShown(s.detail.shown)),this.ufoElement.canvasElement.addEventListener("pointermove",this.handlePointerMove),this.ufoElement.canvasElement.addEventListener("pointerleave",this.handlePointerLeave);for(const s of Vt.GESTURES)this.addEventListener(s,this.handleFirstInteraction,!0)}get said(){return this.saidTexts??=new Un(_s.preferencesFor(this))}saidTexts;traceLabelsFor;observerHeadlightsAt(e,t){const i=e.vehicle;return i?{setting:Ca.at(i.headlights??"auto",i.headlightKeyframes,t)??"auto",headingDeg:this.travelHeadingAt(e,t)}:void 0}travelHeadingAt(e,t){const i=at(e,t);if(!i)return 0;for(const n of[400,-400]){const s=at(e,t+n);if(!s||i.lat===void 0||i.lng===void 0||s.lat===void 0||s.lng===void 0)break;const r=vt(s.lat,s.lng,i.lat,i.lng);if(Math.hypot(r.x,r.z)<.8)continue;return(Math.atan2(r.x,-r.z)*180/Math.PI+(n<0?180:0)+360)%360}return i.headingDeg??0}routeCache;routeOf(e){const t=e.allKeyframes;if(this.routeCache?.track===e&&this.routeCache.count===t.length)return this.routeCache.route;const i=t.flatMap(s=>s.pose.lat!==void 0&&s.pose.lng!==void 0?[{lat:s.pose.lat,lng:s.pose.lng}]:[]),n=i.length>=2?i:void 0;return this.routeCache={track:e,count:t.length,route:n},n}traceLabels(e){const t=_s.preferencesFor(this).join();if(this.traceLabelsFor?.traces!==e||this.traceLabelsFor.language!==t){const i=new Map;for(const n of e){const s=this.said.read(n.title);s&&i.set(n.id,s)}this.traceLabelsFor={traces:e,language:t,labels:i}}return this.traceLabelsFor.labels}connectedCallback(){this.saidTexts=void 0,this.loadSceneNames(),this.sceneRenderer.restoreContext(),this.resizeToStage(),this.updateAstronomy(this.lastTimeMs),this.loadStars(),this.resizeObserver=new ResizeObserver(()=>this.resizeToStage()),this.resizeObserver.observe(this.frameElement),this.watchVisibility(),document.addEventListener("fullscreenchange",this.handleFullscreenChange);for(const t of Vt.GESTURES)document.addEventListener(t,this.handlePageGesture,!0);const e=this.getAttribute("src");e&&this.loadFromSrc(e)}watchVisibility(){this.visibilityObserver?.disconnect(),!(typeof IntersectionObserver>"u"||this.hasAttribute("always-live"))&&(this.visibilityObserver=new IntersectionObserver(e=>{if(e[e.length-1].isIntersecting){this.sceneRenderer.resume();return}this.ufoElement.pause(),this.sceneRenderer.suspend()},{rootMargin:"100px"}),this.visibilityObserver.observe(this))}visibilityObserver;disconnectedCallback(){this.visibilityObserver?.disconnect(),this.resizeObserver?.disconnect(),document.removeEventListener("fullscreenchange",this.handleFullscreenChange);for(const e of Vt.GESTURES)document.removeEventListener(e,this.handlePageGesture,!0);this.sceneRenderer.stopTwinkle(),clearTimeout(this.thunderTimeoutId),this.weatherAudio.dispose(),this.vehicleAudio.dispose(),this.aircraftAudio?.dispose(),this.seekPreview?.dispose(),this.seekPreview=void 0,queueMicrotask(()=>{this.isConnected||this.sceneRenderer.releaseContext()})}attributeChangedCallback(e,t,i){if(e==="src"&&i&&i!==t&&this.isConnected&&this.loadFromSrc(i),(e==="star-catalog-src"||e==="deep-star-catalog-src")&&i!==t&&this.isConnected&&this.loadStars(),e==="show-compass"&&i!==t&&this.sceneRenderer.setShowCompass(this.hasAttribute("show-compass")),e==="max-pixel-ratio"&&i!==t){const n=Number(i);this.sceneRenderer.setMaxPixelRatio(Number.isFinite(n)&&n>0?n:Math.min(window.devicePixelRatio||1,2))}(e===Bl||e===zl)&&i!==t&&this.forwardPlayerAttributes()}forwardPlayerAttributes(){for(const e of[Bl,zl]){const t=this.getAttribute(e);t===null?this.ufoElement.removeAttribute(e):this.ufoElement.setAttribute(e,t)}}setCompassForced(e){this.sceneRenderer.setCompassForced(e)}lookToward(e){const t=at(this.ufoElement.sighting,this.lastTimeMs);if(e.kind==="observer"||t?.lat===void 0||t.lng===void 0||t.headingDeg===void 0){this.setLookOffset(0,0);return}const{x:i,z:n}=vt(e.lat,e.lng,t.lat,t.lng);if(Math.hypot(i,n)<1)return this.setLookOffset(0,0);const s=(Math.atan2(i,-n)*180/Math.PI+360)%360;this.setLookOffset(((s-t.headingDeg)%360+540)%360-180,-t.pitchDeg)}setLookOffset(e,t){this.sceneRenderer.setLookOffset(e,t),this.ufoElement.setLookOffset(e,t),this.updateAstronomy(this.lastTimeMs)}setIndoorLook(e,t){this.sceneRenderer.setIndoorLook(e,t)}setCloudRendering(e){this.sceneRenderer.setCloudRendering(e)}setWeather(e){this.sceneRenderer.setWeather(e),this.weatherAudio.setAmbient(e.precipitationType,e.precipitationIntensity*(e.precipitationAmount??1),e.windSpeed)}pickCloudAt(e,t){return this.sceneRenderer.pickCloudAt(e,t)}cloudDirectionAt(e,t){return this.sceneRenderer.cloudDirectionAt(e,t)}pickDecorAt(e,t){return this.sceneRenderer.pickDecorAt(e,t)}decorScreenBox(e){return this.sceneRenderer.decorScreenBox(e)}decorGroundPointAt(e,t,i,n=0){return this.sceneRenderer.decorGroundPointAt(e,t,i,n)}decorMetresPerNdcY(e){return this.sceneRenderer.decorMetresPerNdcY(e)}decorGrabHeightAt(e,t,i){return this.sceneRenderer.decorGrabHeightAt(e,t,i)}bodyScreenBox(e){return this.sceneRenderer.bodyScreenBox(e)}pickPlacedBodyAt(e,t){return this.sceneRenderer.pickPlacedBodyAt(e,t)}resumeWeatherAudio(){this.weatherAudio.resume(),this.vehicleAudio.resume(),this.aircraftAudio?.resume()}async loadFromSrc(e){const t=lh.json(e);this.holdForNewScene(t);const i=await t;this.documentUrl=new URL(e,location.href).href,this.sightingData=i}holdForNewScene(e){this.sceneRenderer.holdForNewScene(e)}get documentUrl(){return this.sceneRenderer.documentUrl}set documentUrl(e){this.sceneRenderer.documentUrl=e}get sightingData(){return this.ufoElement.sightingData}set sightingData(e){this.ufoElement.sightingData=e,this.seekPreview?.recordingChanged(e),this.interpretationShown=this.inTheRound?this.ufoElement.sighting.interpretation:void 0,this.syncAccountHidden(),this.applyFrameFormat(),this.lastTimeMs=0,this.sceneRenderer.compileNextFrameOffThread(),this.updateAstronomy(0)}seekPreview;seekPreviewOf(e){const t=this.sceneCanvas.width>0&&this.sceneCanvas.height>0?this.sceneCanvas.width/this.sceneCanvas.height:1.7777777777777777,i=Math.round(e.width/t);return e.height!==i&&(e.height=i),this.seekPreview??=new of(this,()=>document.createElement(hf))}showAt(e){this.ufoElement.currentTime=e,this.framesAtAsk=this.sceneRenderer.framesDrawn}framesAtAsk=0;snapshotTo(e){if(this.sceneRenderer.frame(performance.now()),this.sceneRenderer.framesDrawn===this.framesAtAsk)return!1;const t=e.getContext("2d");return t?(t.imageSmoothingQuality="high",t.drawImage(this.sceneCanvas,0,0,e.width,e.height),!0):!1}referenceAspect(e){return this.sceneRenderer.referenceAspect(e)}screenPointOf(e){return this.sceneRenderer.screenPointOf(e)}directionAt(e,t){return this.sceneRenderer.directionAt(e,t)}referenceFailedToLoad(e){return this.sceneRenderer.referenceFailedToLoad(e)}applyReferenceView(e){this.sceneRenderer.setReferencesShown(e.shown);for(const t of this.ufoElement.sighting.references){const i=e.views?.[t.id];this.sceneRenderer.setReferenceView(t.id,{opacity:i?i.shown?i.opacity:0:e.opacity})}}get currentTerrainAttribution(){return this.sceneRenderer.currentTerrainAttribution}get currentRoadAttribution(){return this.sceneRenderer.currentRoadAttribution}setTerrainProviders(e){this.sceneRenderer.setTerrainProviders(e)}setDecorModelProvider(e){this.sceneRenderer.setDecorModelProvider(e)}get decorModelCredits(){return[...new Map(this.sceneRenderer.currentDecorModelCredits.map(t=>[`${t.title}|${t.author??""}|${t.license}|${t.sourceUrl??""}`,t])).values()]}applyFrameFormat(){const e=this.ufoElement.sighting.instrument,t=pt.CANVAS_HEIGHT_PX,i=Bt.frameWidthPx(e,t);this.frameElement.style.setProperty("--frame-aspect",`${i} / ${t}`)}resizeToStage(){const e=this.frameElement.getBoundingClientRect(),t=Math.max(1,Math.round(e.width)),i=Math.max(1,Math.round(e.height));this.sceneCanvas.width=t,this.sceneCanvas.height=i,this.sceneRenderer.resize(t,i)}async loadStars(){const e=[{magnitudeLimit:n0,url:this.getAttribute("star-catalog-src")??O6},{magnitudeLimit:sh,url:this.getAttribute("deep-star-catalog-src")??N6}],t=this.instrumentReach(),i=++this.starCatalogRequest;this.starCatalogDepth=t>n0?sh:n0;const n=await rr.upTo(e,t);i===this.starCatalogRequest&&(this.starCatalog=n,this.sceneRenderer.compileNextFrameOffThread(),this.updateAstronomy(this.lastTimeMs))}ensureStarsDeepEnough(){!this.starCatalog||this.starCatalogDepth>=sh||this.instrumentReach()<=this.starCatalogDepth||this.loadStars()}instrumentReach(){const e=this.ufoElement.sighting,t=vn.gainFor(e.instrument,{fNumber:at(e,0)?.fNumber,fieldOfViewDeg:ji.fovOf(e,0),exposureSeconds:e.exposure});return Aa(F6,t)}updateAstronomy(e){this.ensureStarsDeepEnough(),this.applySceneAt(e);const t=Fs.windowEndingAt(e,this.exposureSeconds()),i=t.seconds,n=this.degreesPerPixelAt(e),s=Po.instants(i,n),r=Math.max(s,this.ufoElement.exposureTimes(e).length,Fs.instants(this.decorWithTraffic(this.ufoElement.sighting),at(this.ufoElement.sighting,e)?.elevationM??0,t.fromMs,i,n));if(r<=1){this.sceneRenderer.setExposure(1);return}this.sceneRenderer.setExposure(r,a=>this.applySceneAt(t.fromMs+t.ms*a/(r-1),{sky:Math.floor(a*s/r)!==Math.floor((a-1)*s/r),stepMs:t.ms/r}))}exposureSeconds(){return this.ufoElement.sighting.exposure??0}degreesPerPixelAt(e){const t=this.sceneCanvas.height;return t<=0?0:ji.fovOf(this.ufoElement.sighting,e)/t}roadGradeAt(e,t){return e.observerTrack.allKeyframes.length<2?0:_l.at(e,t,this.sceneRenderer.bodyGround)}get roadGradeDeg(){return this.roadGradeAt(this.ufoElement.sighting,this.ufoElement.currentTime)}applySceneAt(e,t){const i=this.ufoElement.sighting;this.setWeather(Bh(i,e)),this.sceneRenderer.setInstrument(i.instrument),this.sceneRenderer.setLightPollution(i.lightPollution),t||this.vehicleAudio.setVoices(this.vehicleHearing.at(i,e)),t||this.pushAircraftSound(i,e),this.updateMeteorShower(i,e),this.updateLightning(i,e,t!==void 0),this.sceneRenderer.setDecor(this.seatedDecor(this.decorWithTraffic(i),e)),this.sceneRenderer.setDecorPresence(this.traffic?.set?.presence??Vt.NO_PRESENCE),this.sceneRenderer.setDecorSunlight(this.trafficSunlight(e)),this.sceneRenderer.setContrails(this.traffic?.contrails??Vt.NO_CONTRAILS),this.sceneRenderer.setContrailSunlight(this.contrailSunlight(e));const n=at(i,e);this.sceneRenderer.setReferences(i.references,n?.lat!==void 0&&n.lng!==void 0?{lat:n.lat,lng:n.lng}:void 0);const s=at(i,0),r=Li(i,0),a=ds(i.event.time??{},n?.lng??Gd.lng,i.event.utcOffsetHours),l=i.weatherSource!==void 0&&a?iS(a):void 0,c=Object.fromEntries(Ta(Li(i,e)).map(I=>[I.id,Ru(e,i.weatherTrack,r,s,n,I.id,I.instances?.length?void 0:l)]));this.sceneRenderer.setCloudOffset(Ru(e,i.weatherTrack,r,s,n,void 0,l),c),this.sceneRenderer.setObserverPose(n?{...n,pitchDeg:n.pitchDeg+this.roadGradeAt(i,e)}:Gd),this.sceneRenderer.setLensOptics(this.lensOpticsAt(e)),this.sceneRenderer.setInstrumentGain(vn.gainFor(i.instrument,{fNumber:n?.fNumber,fieldOfViewDeg:ji.fovOf(i,e),exposureSeconds:i.exposure}),i.instrument.detailUm!==void 0,Pi.byId(n?.filter).opticalDensity),this.sceneRenderer.setMedium(i.instrument.medium,i.exposure,n?.fNumber??i.instrument.fNumber,i.iso),this.sceneRenderer.setGait($t.bodyAt(i,e,this.ufoElement.steadyBody)),this.sceneRenderer.updateDecorAnchoring(at(i,0),n,e),this.placeBodiesAt(e,t===void 0),this.sceneRenderer.updateDecorLitState(e,t?.stepMs??0),this.sceneRenderer.setObserverRoute(this.routeOf(i.observerTrack)),this.sceneRenderer.setObserverHeadlights(this.observerHeadlightsAt(i,e)),this.sceneRenderer.setTerrainOrigin(n?.lat,n?.lng,()=>{this.placeBodiesAt(this.lastTimeMs,!0),this.sceneRenderer.render()}),this.sceneRenderer.setStatedRoads(i.roads),this.sceneRenderer.setTraces(i.traces,this.traceLabels(i.traces)),this.pushPhenomenaAt(e);const h=n?.lat??Gd.lat,d=n?.lng??Gd.lng,u=ds(i.event.time??{},d,i.event.utcOffsetHours),f={lat:h,lng:d,elevationM:n?.elevationM??0};this.pushSatellitesAt(u,e,f),this.ensureFireballs(u);const p=[...this.interpretationShown?.reentries??[],...this.fireballs?.reentries??[]];this.sceneRenderer.setReentries(p.length===0?[]:St.viewsAt(p,e,{lat:h,lng:d,heightM:f.elevationM}));const g=this.interpretationShown?.launches??[];if(this.sceneRenderer.setLaunchPlumes(g.length===0||!u?[]:xt.viewsAt(g,e,{lat:h,lng:d,heightM:f.elevationM},xt.sunDirectionAt(new Date(u.getTime()+e)))),t&&!t.sky)return;if(!u){this.sceneRenderer.setAstronomy(U6);return}const m=new Date(u.getTime()+e),v=Math.max(1,Math.round(.25*this.degreesPerPixelAt(e)/Po.DEG_PER_SECOND*1e3)),b=Math.max(1e-8,this.degreesPerPixelAt(e)*.1),x=`${Math.floor(m.getTime()/v)}|${Math.round(h/b)}|${Math.round(d/b)}|${Math.round(f.elevationM)}|${this.starCatalog?this.starCatalogDepth:0}`;if(x===this.lastSkyKey){this.sceneRenderer.render();return}this.lastSkyKey=x;const y=Ki("Sun",m,f),w=Ki("Moon",m,f);let S=_i.separationOf(y,w)<1?_i.viewAt(m,f):void 0;if(S){const I=_i.offsetOf(y,w,S.separationDeg);if(S.obscuration>Vt.LIMB_FROM_OBSCURATION){const R=this.limbFor(m,f);R&&(S={...S,obscuration:1-ws.uncoveredFraction(R,S.sunRadiusDeg,I),limb:R})}S={...S,horizonShare:_i.horizonShare(S,I,y.altitudeDeg,y.azimuthDeg,Sn.distanceKm(m,f))}}const A={...y,magnitude:kp("Sun",m)-2.5*Math.log10(_i.beamFraction(S))};this.lastSun={altitudeDeg:A.altitudeDeg,azimuthDeg:A.azimuthDeg};const M={...w,phase:io(m),magnitude:kp("Moon",m),radiusDeg:Sn.apparentRadiusDeg(m,f)},_=t4.map(I=>({body:I,position:Ki(I,m,f),magnitude:kp(I,m)}));this.sceneRenderer.setAstronomy({sun:A,moon:M,planets:_,comet:this.cometAt(m,f),novae:cf.appearancesAt(m,f).map(({outburst:I,position:R,magnitude:L})=>({id:I.id,position:R,magnitude:L})),stars:this.starCatalog?{catalog:this.starCatalog,date:m,observer:f}:void 0,frame:{date:m,observer:f},localHour:((m.getUTCHours()+m.getUTCMinutes()/60+(i.event.utcOffsetHours??Math.round(d/15)))%24+24)%24,eclipse:S}),this.ufoElement.setSunAltitude(A.altitudeDeg)}static LIMB_FROM_OBSCURATION=.98;limbRelief;limbRequested=!1;limbCache;limbFor(e,t){if(!this.limbRelief){this.limbRequested||(this.limbRequested=!0,rh.load(L6).then(s=>{this.limbRelief=s,this.lastSkyKey="",s&&this.isConnected&&this.updateAstronomy(this.lastTimeMs)}));return}const i=this.limbCache;if(i&&Math.abs(e.getTime()-i.atMs)<5e3&&i.lat===t.lat&&i.lng===t.lng&&i.elevationM===t.elevationM)return i.profile;const n=ws.profile(e,t,this.limbRelief);return this.limbCache={profile:n,atMs:e.getTime(),lat:t.lat,lng:t.lng,elevationM:t.elevationM},n}pushSatellitesAt(e,t,i){if(this.ensureSatellites(e),!e||!this.satellites){this.sceneRenderer.setSatellites([]);return}const n=new Date(e.getTime()+t),s=[];for(const r of this.satellites.passes.positionsAt(n,i,-1))r.magnitude!==void 0&&s.push({norad:r.object.norad,name:r.object.name,position:{altitudeDeg:r.altitudeDeg,azimuthDeg:r.azimuthDeg},magnitude:r.magnitude,heightKm:r.heightKm});this.sceneRenderer.setSatellites(s)}ensureFireballs(e){const t=this.ufoElement.sighting,i=Math.max((t.event.durationSeconds??0)*1e3,this.ufoElement.seekableDuration),n=e?.getTime(),s=n===void 0?"":`${n}+${i}`;if(this.fireballs?.key===s)return;if(n===void 0||!Es.mayCover(n+i)){this.fireballs={key:s,status:"outside",reentries:[]};return}const r={key:s,status:"loading",reentries:[]};this.fireballs=r,Vt.fireballArchive.between(n,n+i).then(a=>{r.status=a?"ready":"unavailable",r.records=a??[],r.reentries=r.records.map(l=>Es.asReentry(l,n)),!(this.fireballs!==r||!this.isConnected)&&(this.dispatchEvent(new CustomEvent(S2)),r.reentries.length>0&&this.updateAstronomy(this.lastTimeMs))})}decorWithTraffic(e){const t=this.ensureTraffic(e);if(!t||t.objects.length===0)return e.decor;const i=this.decorMemo;if(i&&i.base===e.decor&&i.traffic===t.objects)return i.merged;const n=[...e.decor,...t.objects];return this.decorMemo={base:e.decor,traffic:t.objects,merged:n},n}seatedDecor(e,t){if(!e.some(r=>r.observerKeyframes?.length))return e;const i=e.map(r=>{if(!r.observerKeyframes?.length)return"";const a=kv(r,t);return`${a.side??"-"}/${a.facing??"-"}`}).join("|"),n=this.seatedMemo;if(n&&n.base===e&&n.seats===i)return n.seated;const s=e.map(r=>{if(!r.observerKeyframes?.length)return r;const a=kv(r,t);return{...r,observerSide:a.side,observerFacing:a.facing}});return this.seatedMemo={base:e,seats:i,seated:s},s}ensureTraffic(e){const t=at(e,0),i=t?.lng===void 0?void 0:ds(e.event.time??{},t.lng,e.event.utcOffsetHours),n=Math.max((e.event.durationSeconds??0)*1e3,this.ufoElement.seekableDuration),s=i?.getTime(),r=s===void 0||t?.lat===void 0||t.lng===void 0?"":`${this.aircraftSource.id}|${s}+${n}|${t.lat.toFixed(3)},${t.lng.toFixed(3)}|${Math.round(t.elevationM??0)}`;if(this.traffic?.key===r)return this.traffic.set;if(r===""||s===void 0||t?.lat===void 0||t.lng===void 0){this.traffic={key:r,status:"outside"};return}let a=Vt.aircraftProviders.get(this.aircraftSource.id);if(a||Vt.aircraftProviders.set(this.aircraftSource.id,a=this.aircraftSource.create()),a.mayCover&&!a.mayCover(s+n)){this.traffic={key:r,status:"outside"};return}const l={key:r,status:"loading",startMs:s,observer:{lat:t.lat,lng:t.lng}};this.traffic=l;const c={lat:t.lat,lng:t.lng,heightM:t.elevationM??0},h=Cn.MAX_GAP_S*1e3,d=Vt.SOUND_LOOKBACK_MS,u={lat:t.lat,lng:t.lng,elevationM:t.elevationM??0},f=(p,g)=>p.TrafficDecor.from(l.tracks??[],c,s,p.TrafficDecor.MAX_OBJECTS,{models:g,sunElevationAt:m=>this.sunElevationAt(m,u)});a.between(c,s-d,s+n+h).then(async p=>{if(this.traffic!==l)return;if(p.status!=="found"){l.status=p.status==="outside"?"outside":"unavailable",this.announceTraffic();return}let g;try{g=await Vt.loadTrafficRuntime()}catch{this.traffic===l&&(l.status="unavailable",this.announceTraffic());return}this.traffic===l&&(l.status="ready",l.tracks=p.tracks,l.set=f(g),this.startAircraftSound(l,g),this.announceTraffic(),this.describeTraffic(a,l,g,f),l.set.shown>0&&this.readUpperAir(l,g,s-d,s+n+h))})}trafficSunlight(e){const t=new Map,i=this.traffic,n=i?.set,s=this.lastSun;if(!n||!s||i.startMs===void 0||!i.observer)return t;for(const[r,a]of n.presence){if(e<a.fromMs||e>a.untilMs)continue;const l=n.flights.get(r),c=l?Cn.positionAt(l,i.startMs+e):void 0;c&&t.set(r,{heightM:c.geo.heightM,sunElevationDeg:Fn.sunElevationDeg(s,i.observer,c.geo)})}return t}trafficTooltipAt(e,t){const i=this.sceneRenderer.pickTrafficAt(e,t),n=i?this.trafficInfoAt(i):void 0;if(!n)return;const s=this.naming,r=Vt.trafficRuntime;return r?.TrafficTooltip.text(n,s.names?.trafficTooltip??r.TrafficTooltip.ENGLISH,a=>s.towards(a))}trafficInfoAt(e){const t=this.traffic,i=t?.set?.flights.get(e);if(!t||!i||t.startMs===void 0||!t.observer)return;const n=Vt.trafficRuntime;if(!n)return;const s=t.descriptions?.get(Ss.keyOf(i)),r=at(this.ufoElement.sighting,this.lastTimeMs),a={lat:t.observer.lat,lng:t.observer.lng,heightM:r?.elevationM??0},l=n.AmbientNoise.dbA(Bh(this.ufoElement.sighting,this.lastTimeMs)),c=n.TrafficInfos.at(i,s,a,t.startMs+this.lastTimeMs,{ambientDbA:l}),h=c&&this.contrailAt(e,this.lastTimeMs);return c&&h?{...c,contrail:h}:c}contrailAt(e,t){const i=this.traffic?.contrails?.find(s=>s.id===e);if(!i)return;let n;for(const s of i.points){if(s.tMs>t)break;n=s}return n?.forms?{persistent:n.persistent,iceRelativeHumidity:n.iceRelativeHumidity}:void 0}startAircraftSound(e,t){this.aircraftAudio??=this.newAircraftAudio(t),this.sortOutAudible(e,t)}sortOutAudible(e,t){!e.set||!e.observer||(e.audible=t.TrafficSound.candidates(e.set.flights,e.descriptions??new Map,Ss.keyOf,{...e.observer,heightM:0},{ambientDbA:t.AmbientNoise.BASE_DB_A}))}pushAircraftSound(e,t){this.startDecorAircraftSound(e);const i=this.aircraftAudio;if(!i)return;const n=Vt.trafficRuntime;if(!n){i.setVoices([]);return}const s=at(e,t),r=Bh(e,t),a={ambientDbA:n.AmbientNoise.dbA(r),referenceAmplitude:n.AmbientNoise.referenceAmplitude(r)},l=this.trafficVoices(t,s,a,n),c=e.event.place?.[0],h={lat:s?.lat??c?.lat,lng:s?.lng??c?.lng};h.lat!==void 0&&h.lng!==void 0&&(this.decorAircraftHearing??=new n.DecorAircraftHearing,l.push(...this.decorAircraftHearing.voices(e,t,{lat:h.lat,lng:h.lng,heightM:s?.elevationM??0},a,d=>this.decorModelSounds.get(d.model?.id??""))),l.sort((d,u)=>u.levelDbA-d.levelDbA),l.length=Math.min(l.length,4)),i.setVoices(l,s?.headingDeg??0)}trafficVoices(e,t,i,n){const s=this.traffic,r=s?.set;if(!s||!r||!s.audible||s.startMs===void 0||!s.observer)return[];const a={lat:s.observer.lat,lng:s.observer.lng,heightM:t?.elevationM??0};return n.TrafficSound.voices(s.audible,r.flights,s.descriptions??new Map,Ss.keyOf,a,s.startMs+e,i)}startDecorAircraftSound(e){const t=e.decor.filter(i=>i.kind==="aircraft"&&i.track?.some(n=>(n.altitudeM??0)>0));if(t.length!==0){for(const i of t){const n=i.model?.id;!n||i.model?.url!==void 0||this.decorModelSounds.has(n)||(this.decorModelSounds.set(n,void 0),this.sceneRenderer.entryOfDecorModel(n).then(s=>{this.decorModelSounds.set(n,s?.parameters?.sound)}))}if(this.aircraftAudio||Vt.trafficRuntime){!this.aircraftAudio&&Vt.trafficRuntime&&(this.aircraftAudio=this.newAircraftAudio(Vt.trafficRuntime));return}Vt.loadTrafficRuntime().catch(()=>{})}}newAircraftAudio(e){const t=new e.AircraftAudio;return t.setLevel(this.ufoElement.level),this.interacted&&t.resume(),t.setPaused(this.ufoElement.playbackState!=="playing"),t}announceTraffic(){this.isConnected&&(this.dispatchEvent(new CustomEvent(C6)),this.updateAstronomy(this.lastTimeMs))}async describeTraffic(e,t,i,n){if(!e.describe||!t.set||!t.tracks)return;const s=new Set([...t.set.flights.values()].map(c=>Ss.keyOf(c))),r=t.tracks.filter(c=>s.has(Ss.keyOf(c))&&c.points.length>0),a=new Map,l=new Map;await Promise.all(r.map(async c=>{const h=new Date(c.points[0].t).toISOString().slice(0,10),d=await e.describe(c,h).catch(()=>{});d&&(l.set(Ss.keyOf(c),d),a.set(Ss.keyOf(c),i.AircraftModels.of(d)))})),!(this.traffic!==t||a.size===0)&&(t.descriptions=l,t.models=a,t.set=n(i,a),this.planContrails(t,i),this.sortOutAudible(t,i),this.announceTraffic())}async readUpperAir(e,t,i,n){if(!e.observer)return;const s=this.upperAirSource??t.UPPER_AIR_SOURCES[0];let r=Vt.upperAirProviders.get(s.id);r||Vt.upperAirProviders.set(s.id,r=s.create());const a=await r.between(e.observer,i,n);this.traffic!==e||a.status!=="found"||(e.air=a.samples,e.airSource=a.source,this.planContrails(e,t),this.announceTraffic())}planContrails(e,t){!e.set||!e.air||e.startMs===void 0||(e.contrails=t.AircraftContrails.plan(e.set,e.models,e.air,e.startMs))}contrailSunlight(e){const t=new Map,i=this.traffic,n=i?.set,s=this.lastSun;if(!n||!s||!i.contrails?.length||i.startMs===void 0||!i.observer)return t;for(const r of i.contrails){const a=n.presence.get(r.id),l=n.flights.get(r.id);if(!a||!l)continue;const c=Cn.positionAt(l,i.startMs+Math.min(a.untilMs,Math.max(a.fromMs,e)));c&&t.set(r.id,{heightM:c.geo.heightM,sunElevationDeg:Fn.sunElevationDeg(s,i.observer,c.geo)})}return t}sunElevationAt(e,t){const i=Ki("Sun",new Date(e.t),t);return Fn.sunElevationDeg(i,t,e)}upperAirSource;setUpperAirSource(e){e.id!==this.upperAirSource?.id&&(this.upperAirSource=e,this.traffic=void 0,this.decorMemo=void 0,this.updateAstronomy(this.lastTimeMs))}setAircraftSource(e){e.id!==this.aircraftSource.id&&(this.aircraftSource=e,this.traffic=void 0,this.decorMemo=void 0,this.updateAstronomy(this.lastTimeMs))}get aircraftState(){const e=this.traffic?.contrails?.length?this.upperAirSource??Vt.trafficRuntime?.UPPER_AIR_SOURCES[0]:void 0;return{trailCredit:e&&{credit:e.credit,creditUrl:e.creditUrl},status:this.traffic?.status??"none",total:this.traffic?.set?.total??0,shown:this.traffic?.set?.shown??0,credit:this.aircraftSource.credit,creditUrl:this.aircraftSource.creditUrl}}get fireballState(){return{status:this.fireballs?.status??"none",records:this.fireballs?.records??[]}}ensureSatellites(e){const t=e?String(e.getTime()):"";if(t===this.satellitesFor)return;this.satellitesFor=t,this.satellites=void 0,this.satellitePassesMemo=void 0;const i=++this.satelliteRequest;if(!e){this.satelliteStatus="none";return}this.satelliteStatus="loading";const n=r=>{i===this.satelliteRequest&&(this.satelliteStatus=r,this.isConnected&&this.dispatchEvent(new CustomEvent(x2)))},s=Vt.tleArchive;(async()=>{if(!await s.covers(e))return n("outside");const[r,a]=await Promise.all([s.at(e),Ue(()=>import("./SatellitePasses-Pfro2-0Z.js"),[],import.meta.url)]);if(i===this.satelliteRequest){if(!r)return n("unavailable");this.satellites={snapshot:r,passes:new a.SatellitePasses(r.objects)},n("ready"),this.isConnected&&this.updateAstronomy(this.lastTimeMs)}})().catch(()=>n("unavailable"))}get satelliteState(){const e=this.satellites?.snapshot;return{status:this.satelliteStatus,coverage:e?.coverage,credit:e?.credit,creditUrl:e?.creditUrl}}satellitePassesDuring(e){const t=this.satellites,i=this.ufoElement.sighting,n=at(i,0),s=i.event.place?.[0],r=n?.lat??s?.lat,a=n?.lng??s?.lng;if(!t||r===void 0||a===void 0)return[];const l=ds(i.event.time??{},a,i.event.utcOffsetHours);if(!l)return[];const c=Math.min(Math.max(e,0),4*36e5),h={lat:r,lng:a,elevationM:n?.elevationM??0},d=JSON.stringify([this.satellitesFor,l.getTime(),r,a,h.elevationM,c]);if(this.satellitePassesMemo?.key===d)return this.satellitePassesMemo.passes;const u=Math.max(10,Math.ceil(c/1e3/600)),f=t.passes.passesDuring(l,new Date(l.getTime()+c),h,u);return this.satellitePassesMemo={key:d,passes:f},f}cometAt(e,t){const i=ou.brightestAt(e,t);if(i)return{id:i.apparition.id,position:i.position,tailEnd:i.tailEnd,magnitude:i.magnitude}}pushPhenomenaAt(e){const t=this.ufoElement.sighting;t!==this.sizeEstimatesFor&&(this.sizeEstimates.clear(),this.distanceHypotheses.clear(),this.sizeEstimatesFor=t);const i=t.timeline,n=this.ufoElement.canvasElement,s=this.ufoElement.frameShiftPx,r=this.projectionAt(e),a=new Map,l=new Map,c=new Set;for(const p of i.sourceIds){const g=i.getInterpolatedShapeAt(e,p);if(!g)continue;const m={...g,bounds:{...g.bounds,x:g.bounds.x+s.x,y:g.bounds.y+s.y}};a.set(p,m);const v=g.aim?this.sceneRenderer.screenPointOf(Ls.directionOf(g.aim,this.directionScratch)):{ndcX:(m.bounds.x+m.bounds.width/2)/n.width*2-1,ndcY:-((m.bounds.y+m.bounds.height/2)/n.height*2-1)},b=v!==void 0&&Math.abs(v.ndcX)<=1&&Math.abs(v.ndcY)<=1,x=b?this.sceneRenderer.decorDistancesAt(v.ndcX,v.ndcY,p):{};c.add(p),(b||g.aim)&&c.delete(p);const y=g.angular?.widthDeg??r.pxToDeg(g.bounds.width),w=this.sizeEstimateOf(p);w.add(y,x);const S=ah.of(t,p);l.set(p,Dn.resolve({hypothesisM:this.distanceHypotheses.get(p),derivedM:S&&y>0?pt.distanceMAt(S.widthM,y):void 0,range:w.distanceRangeAt(y),crossing:x}))}for(const[p,g]of a)for(const[m,v]of a){if(m===p||v.transparency>=1||v.bounds.width*v.bounds.height<=g.bounds.width*g.bounds.height||!(g.bounds.x>=v.bounds.x&&g.bounds.y>=v.bounds.y&&g.bounds.x+g.bounds.width<=v.bounds.x+v.bounds.width&&g.bounds.y+g.bounds.height<=v.bounds.y+v.bounds.height))continue;const x=l.get(m);x&&l.set(p,{distanceM:x.distanceM*.999,basis:x.basis});break}this.depths=l;const h=i.sourceIds,d=[];for(const[p,g]of a)d.push({sourceId:p,shape:g,distanceM:l.get(p).distanceM,renderOrder:h.indexOf(p),aim:g.aim,hidden:c.has(p)||this.interpretationShown!==void 0&&(!this.comparing||g.transparency>=1),ghost:this.interpretationShown!==void 0&&this.comparing});const f=(at(t,e)?.rollDeg??0)+$t.bodyAt(t,e,this.ufoElement.steadyBody).rollDeg;this.sceneRenderer.setPhenomena(d,{projection:r,canvasWidthPx:n.width,canvasHeightPx:n.height,scale:Math.max(1,this.sceneCanvas.height/Math.max(1,n.height)),starPoints:Bt.starPointsOf(t.instrument),rollRad:f*Math.PI/180})}get interpretation(){return this.interpretationShown}set interpretation(e){this.interpretationShown=e,this.ufoElement.playerTitle=e?.title,this.syncAccountHidden(),this.updateAstronomy(this.lastTimeMs),this.ufoElement.repaintChrome()}syncAccountHidden(){this.ufoElement.accountHidden=this.interpretationShown!==void 0&&!this.comparing}get accountInTheRound(){return this.inTheRound}set accountInTheRound(e){this.inTheRound=e}get compareAccount(){return this.comparing}set compareAccount(e){this.comparing=e,this.syncAccountHidden(),this.updateAstronomy(this.lastTimeMs),this.ufoElement.repaintChrome()}get confrontation(){return this.confrontationReadings}groundAlong(e,t,i){const n=this.sceneRenderer.bodyGround,s=et.eyeOf(this.ufoElement.sighting,i,n);return s?et.lineOfSightMeetsGround(s,e,t,n):void 0}bodyMaskedBy(e,t){return this.sceneRenderer.bodyMaskedByDecor(e,t)}bodyReading(e,t){const i=this.sceneRenderer.bodyGround,n=this.ufoElement.sighting,s=u=>et.eyeOf(n,u,i),r=new et(e,i,s).at(t),a=s(t);if(!r||!a)return;const l=r.eastM-a.eastM,c=r.northM-a.northM,h=r.upM-a.upM,d=Math.hypot(l,c);return{azimuthDeg:(Math.atan2(l,c)*180/Math.PI+360)%360,altitudeDeg:Math.atan2(h,d)*180/Math.PI,distanceM:Math.hypot(d,h),eastM:r.eastM,northM:r.northM,aboveGroundM:r.upM-r.sizeM.heightM/2-i.heightAt(r.eastM,r.northM),sizeM:r.sizeM,attitude:r.attitude,appearance:r.appearance}}directionToBody(e,t){const i=this.sceneRenderer.bodyGround,n=this.ufoElement.sighting,s=p=>et.eyeOf(n,p,i),r=new et(e,i,s),a=r.at(t)?t:e.track[0]?.t,l=a===void 0?void 0:r.at(a),c=a===void 0?void 0:s(a);if(!l||!c)return;const h=l.eastM-c.eastM,d=l.northM-c.northM,u=l.upM-c.upM,f=Math.hypot(h,d);if(!(f===0&&u===0))return{azimuthDeg:(Math.atan2(h,d)*180/Math.PI+360)%360,altitudeDeg:Math.atan2(u,f)*180/Math.PI}}placeBodiesAt(e,t){const i=this.interpretationShown,n=this.ufoElement.sighting;let s=[],r=[];const a=this.sceneRenderer.bodyGround,l=p=>et.eyeOf(n,p,a);i&&(s=i.bodies.map(p=>new et(p,a,l).at(e)).filter(p=>p!==void 0));const c=Li(n,e),h=c.windDirectionDeg*Math.PI/180,d={x:c.windSpeed*Math.sin(h),z:-c.windSpeed*Math.cos(h)};this.sceneRenderer.setBodies(s,e/1e3,i?.bodies.map(p=>p.id)??[],i?.smoke??[],d);const u=i&&this.comparing?l(e):void 0;if(u&&(r=new Ai(n.timeline).at(e,s,u,p=>p.outlineNode?this.sceneRenderer.bodyOutline?.(p.id,p.outlineNode):void 0)),this.confrontationReadings=r,!t)return;const f=JSON.stringify(r);f!==this.confrontationSignature&&(this.confrontationSignature=f,this.dispatchEvent(new CustomEvent(k6,{detail:r})))}setDistanceHypothesis(e,t){t===void 0||!(t>0)?this.distanceHypotheses.delete(e):this.distanceHypotheses.set(e,t),this.updateAstronomy(this.lastTimeMs)}depthOf(e){return this.depths.get(e)}sizeRangeOf(e){return this.sizeEstimateOf(e).sizeRange}distanceRangeAt(e,t){const i=this.ufoElement.sighting.timeline.getInterpolatedShapeAt(t,e);if(!i)return{};const n=i.angular?.widthDeg??this.projectionAt(t).pxToDeg(i.bounds.width);return this.sizeEstimateOf(e).distanceRangeAt(n)}sizeContradictory(e){return this.sizeEstimateOf(e).contradictory}updateMeteorShower(e,t){this.ensureMeteorSchedule(e),this.sceneRenderer.updateMeteors(t)}updateLightning(e,t,i){if(this.ensureLightningSchedule(e),this.sceneRenderer.updateLightning(t),i)return;const n=this.lastLightningT;if(this.lastLightningT=t,n===void 0||t<n||this.ufoElement.playbackState!=="playing")return;const s=this.lightningFlashes.filter(r=>r.t>n&&r.t<=t).pop();s&&Li(e,s.t).storm&&this.handleLightningFlash(s)}ensureLightningSchedule(e){const t=Li(e,0).precipitationIntensity,i=`${this.meteorInputsOf(e)}|${t}`;if(i===this.lightningScheduleFor)return;this.lightningScheduleFor=i;const n=e.event.time,s=e.event.place?.[0],r=n?.year!==void 0?ds(n,s?.lng??0,e.event.utcOffsetHours):void 0,a=(e.event.durationSeconds??0)*1e3||e.timeline.duration||2e4,l=Math.round((r?.getTime()??0)/1e3)+Math.round((s?.lat??0)*1e3)+7;this.lightningFlashes=qi.schedule({durationMs:a,seed:l,intensity:t}),this.sceneRenderer.setLightning(this.lightningFlashes)}ensureMeteorSchedule(e){const t=this.meteorInputsOf(e);t!==this.meteorScheduleFor&&(this.meteorScheduleFor=t,this.scheduleMeteors(e))}meteorInputsOf(e){const t=e.event.place?.[0],i=e.event.time;return JSON.stringify([t?.lat,t?.lng,i?.year,i?.month,i?.day,i?.hour,i?.minute,i?.second,e.event.utcOffsetHours,e.event.durationSeconds,e.timeline.duration])}scheduleMeteors(e){const t=e.event.place?.[0],i=e.event.time,n=t?.lat!==void 0&&t.lng!==void 0&&i?.year!==void 0?ds(i,t.lng,e.event.utcOffsetHours):void 0;if(!n||t?.lat===void 0||t.lng===void 0){this.sceneRenderer.setMeteorShower([],0,0);return}const s={lat:t.lat,lng:t.lng,elevationM:0},r=(e.event.durationSeconds??0)*1e3||e.timeline.duration||2e4,a=Math.round(n.getTime()/1e3)+Math.round(t.lat*1e3),l=vi.schedule({ratePerHour:vi.observedRatePerHour(vi.apexPosition(n,s).altitudeDeg),durationMs:r,velocityKmS:vi.TYPICAL_VELOCITY_KM_S,seed:a}),c=jl.activeAt(n).map(d=>{const u=jl.radiantPosition(d.shower,n,s);return{entry:d,position:u,rate:jl.observedRatePerHour(d.zhr,u.altitudeDeg,d.shower.populationIndex)}}).sort((d,u)=>u.rate-d.rate)[0];if(!c||c.rate<=0){this.sceneRenderer.setMeteorShower(l,0,0);return}const h=Co.schedule({ratePerHour:c.rate,durationMs:r,velocityKmS:c.entry.shower.velocityKmS,seed:a+1});this.sceneRenderer.setMeteorShower([...h,...l],c.position.altitudeDeg,c.position.azimuthDeg)}meteorByRank(e){this.ensureMeteorSchedule(this.ufoElement.sighting);const t=[...this.sceneRenderer.meteorSchedule].filter(s=>s.t+s.durationMs<=this.ufoElement.seekableDuration).sort((s,r)=>r.brightness-s.brightness);if(t.length===0)return;const i=t[e%t.length],n=this.sceneRenderer.meteorMidpoint(i);if(n)return{t:Math.round(i.t+i.durationMs*.45),...n}}lensOpticsAt(e){const t=this.ufoElement.sighting,i=t.instrument,n=i.frame,s=at(t,e),r=s?.fNumber??i.fNumber;if(!n||r===void 0)return;const a=Bt.focalLengthMmFor(i,ji.fovOf(t,e));if(a!==void 0)return{focalLengthMm:a,fNumber:r,focusDistance:s?.focusDistanceM??0,frameHeightMm:n.heightMm}}projectionAt(e){const t=this.ufoElement.sighting;return Vs.of(t.instrument,pt.CANVAS_HEIGHT_PX,ji.fovOf(t,e))}sizeEstimateOf(e){let t=this.sizeEstimates.get(e);return t||(t=new x6,this.sizeEstimates.set(e,t)),t}}const hf="rr0-scene";function B6(){xf(),customElements.get(hf)||customElements.define(hf,Vt)}class z6{constructor(e,t){this.timeline=e,this.clock=t}currentPointer=null;shapePrototype=null;sourceId="";start(e,t){this.sourceId=e,this.shapePrototype=t,this.currentPointer=null,this.clock.start(i=>this.recordSample(i))}onPointerMove(e,t){this.currentPointer={x:e,y:t}}stop(){this.clock.stop()}recordSample(e){if(!this.currentPointer||!this.shapePrototype)return;const t=aM(this.shapePrototype,this.currentPointer.x,this.currentPointer.y);this.timeline.addKeyframe(e,[{sourceId:this.sourceId,shape:t}])}}class H6{constructor(e){this.intervalMs=e}rafId=null;startTime=0;lastTick=0;start(e){this.startTime=performance.now(),this.lastTick=0;const t=()=>{const i=performance.now()-this.startTime;i-this.lastTick>=this.intervalMs&&(this.lastTick=i,e(i)),this.rafId=requestAnimationFrame(t)};this.rafId=requestAnimationFrame(t)}stop(){this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null)}}const df="rr0-duration-input",G6=`
9794
9794
  rr0-duration-input { position: relative; display: inline-flex; align-items: center; gap: .3em; }
9795
9795
  rr0-duration-input .duration-field { position: relative; display: inline-flex; align-items: center; gap: .25em; }
9796
9796
  rr0-duration-input .duration-field input[type="text"] { padding-right: 1.6em; }
@@ -9801,7 +9801,7 @@ rr0-duration-input .duration-helppop p { margin: 0 0 .3em; font-weight: 600; }
9801
9801
  rr0-duration-input .duration-helppop ul { margin: 0; padding-left: 1.1em; }
9802
9802
  rr0-duration-input [hidden] { display: none !important; }
9803
9803
  `;class V6 extends HTMLElement{wording=Ao;built=!1;precise=!0;numberInput;textInput;modeButton;helpButton;popup;chosen;build(){if(this.built)return;this.built=!0;const e=this.getAttribute("name"),t=this.ownerDocument,i=t.createElement("style");i.textContent=G6;const n=t.createElement("span");n.className="duration-field",this.numberInput=t.createElement("input"),this.numberInput.type="number",this.numberInput.min="0",this.numberInput.max="86400",this.numberInput.step="0.1",this.numberInput.setAttribute("aria-required","true");const s=t.createElement("span");s.className="duration-unit",s.textContent="s",this.textInput=t.createElement("input"),this.textInput.type="text",this.textInput.hidden=!0,this.helpButton=t.createElement("button"),this.helpButton.type="button",this.helpButton.className="duration-help",this.helpButton.textContent="?",this.helpButton.hidden=!0,this.popup=t.createElement("div"),this.popup.className="duration-helppop",this.popup.hidden=!0,this.chosen=t.createElement("span"),this.chosen.className="duration-chosen",this.chosen.hidden=!0,this.modeButton=t.createElement("button"),this.modeButton.type="button",this.modeButton.className="duration-mode",e&&(this.numberInput.id=e,this.textInput.id=`${e}-text`),n.append(this.numberInput,s,this.textInput,this.helpButton,this.popup),this.append(i,n,this.modeButton,this.chosen),this.numberInput.addEventListener("input",()=>{const r=this.numberInput.value;this.tell(r===""?void 0:Number(r),void 0)}),this.textInput.addEventListener("input",()=>this.readText()),this.textInput.addEventListener("focus",()=>this.showDeduction()),this.modeButton.addEventListener("click",()=>this.setPrecise(!this.precise)),this.helpButton.addEventListener("click",()=>{this.popup.hidden=!this.popup.hidden}),this.applyWording()}connectedCallback(){this.build(),document.addEventListener("pointerdown",this.closeHelpOutside,!0),document.addEventListener("keydown",this.closeHelpOnEscape,!0)}disconnectedCallback(){document.removeEventListener("pointerdown",this.closeHelpOutside,!0),document.removeEventListener("keydown",this.closeHelpOnEscape,!0)}closeHelpOutside=e=>{this.popup&&!this.popup.hidden&&!e.composedPath().includes(this)&&(this.popup.hidden=!0)};closeHelpOnEscape=e=>{e.key==="Escape"&&this.popup&&(this.popup.hidden=!0)};get input(){return this.build(),this.numberInput}get textField(){return this.build(),this.textInput}get isPrecise(){return this.build(),this.precise}set messages(e){this.wording=e,this.built&&this.applyWording()}applyWording(){const e=this.wording;this.modeButton.title=e.durationModeTitle,this.modeButton.setAttribute("aria-label",e.durationModeTitle);const t=this.ownerDocument.createElement("p");t.textContent=e.durationHelpTitle;const i=this.ownerDocument.createElement("ul");for(const n of e.durationHelpLines.split(`
9804
- `)){const s=this.ownerDocument.createElement("li");s.textContent=n,i.append(s)}this.popup.replaceChildren(t,i),this.setPrecise(this.precise)}setPrecise(e){this.build();const t=this.precise;this.precise=e,this.numberInput.hidden=!e,this.querySelector(".duration-unit").hidden=!e,this.textInput.hidden=e,this.helpButton.hidden=e,this.modeButton.textContent=e?this.wording.durationPrecise:this.wording.durationIso,this.modeButton.setAttribute("aria-pressed",String(!e)),!e&&t&&this.textInput.value===""&&this.numberInput.value!==""&&(this.textInput.value=kn.format(Number(this.numberInput.value))),this.showDeduction(),this.showChosen()}set(e,t){this.build(),this.numberInput.value=e===void 0?"":String(e),this.textInput.value=t??"",this.setPrecise(t===void 0)}readText(){const e=this.textInput.value.trim();if(this.showDeduction(),e===""){this.numberInput.value="",this.showChosen(),this.tell(void 0,void 0);return}const t=kn.parse(e);t&&(this.numberInput.value=String(t.chosenSeconds),this.showChosen(),this.tell(t.chosenSeconds,kn.isExact(e)?void 0:e))}tell(e,t){this.dispatchEvent(new CustomEvent("durationchange",{detail:{seconds:e,text:t},bubbles:!0,composed:!0}))}describe(e){const t=this.wording,i=e.minSeconds===e.maxSeconds?kn.say(e.minSeconds):`${kn.say(e.minSeconds)} – ${kn.say(e.maxSeconds)}`,n=e.doubt==="~"?t.timeQualifierApproximate:e.doubt==="?"?t.timeQualifierUncertain:e.doubt==="%"?t.timeQualifierBoth:"";return n?`${i} — ${n.toLowerCase()}`:i}showDeduction(){const e=this.textInput.value.trim();if(this.precise||e===""){this.textInput.title="";return}const t=kn.parse(e);this.textInput.title=t?`→ ${this.describe(t)}`:this.wording.durationInvalid}showChosen(){const e=this.precise?void 0:kn.parse(this.textInput.value),t=e!==void 0&&!kn.isExact(this.textInput.value);this.chosen.hidden=!t,this.chosen.textContent=t?this.wording.durationChosen.replace("{value}",kn.say(e.chosenSeconds)):""}}function W6(){customElements.get(df)||customElements.define(df,V6)}class uf{static easter(e){const t=e%19,i=Math.floor(e/100),n=e%100,s=Math.floor(i/4),r=i%4,a=Math.floor((i+8)/25),l=Math.floor((i-a+1)/3),c=(19*t+i-s-l+15)%30,h=Math.floor(n/4),d=n%4,u=(32+2*r+2*h-c-d)%7,f=Math.floor((t+11*c+22*u)/451),p=Math.floor((c+u-7*f+114)/31),g=(c+u-7*f+114)%31+1;return new Date(Date.UTC(e,p-1,g,12))}static lunation(e){if(e<1583)return;const t=uf.easter(e),i=su(0,t,40);if(!i)return;const n=su(180,i.date,20),s=su(0,new Date(i.date.getTime()+864e5),40);if(!(!n||!s))return{begin:i.date,full:n.date,end:s.date}}static isIn(e){const t=uf.lunation(e.getUTCFullYear());return t!==void 0&&e>=t.begin&&e<t.end}}const X6=[{id:"echo",name:"the Echo balloons",from:"1960-08-12",to:"1969-06-07",peakMagnitude:-1,note:"Echo 1 and 2 were 30- and 40-metre reflective balloons, as bright as the brightest stars and moving slowly enough to be watched — deliberately visible, widely announced in newspapers, and the first objects most people ever saw crossing the night sky. They fall squarely inside the sighting waves this project reconstructs."},{id:"iridium-flares",name:"the Iridium flares",from:"1997-05-05",to:"2019-12-27",peakMagnitude:-8,note:"The original Iridium satellites carried flat, mirror-finish antennas that threw a sunbeam a few kilometres wide across the ground: a still point of sky flaring to magnitude -8 over five seconds and vanishing again. Nothing else in the sky does that."},{id:"iss",name:"the International Space Station",from:"1998-11-20",peakMagnitude:-5.9,note:"Since its first module, and much brighter as it grew: at its best it outshines everything in the sky but the Sun and the Moon, crossing in a straight silent line in about four minutes."},{id:"starlink-trains",name:"the Starlink trains",from:"2019-05-24",peakMagnitude:1,note:"In the days after a launch, satellites still bunched in their deployment string cross as an evenly spaced line of lights — the most reported 'formation of UFOs' of the era. They spread out within weeks, so a train is a fact about the days after a launch rather than about the year."}],$6=23493,zb=[2,3,2,1,2,5,4,6,5,6,6,6,6,6,6,6,9,9,9,9,9,9,14,14,15,16,16,16,16,16,18,22,25,24,29,28,29,33,34,35,40,40,42,42,43,46,48,48,49,53,53,54,58,61,70,70,74,78,79,83,92,92,99,97,101,102,109,115,126,125,123,125,127,130,139,153,157,156,161,156,165,174,193,193,201,203,212,215,224,244,255,263,262,281,293,307,312,327,339,336,343,353,359,369,386,396,405,410,421,419,424,434,443,450,460,480,492,504,509,516,519,524,527,530,527,535,543,549,564,571,573,576,582,584,600,600,608,618,625,632,637,642,648,654,661,667,669,667,671,671,697,692,703,697,710,714,724,731,747,755,764,770,782,802,801,815,819,837,846,856,878,881,877,900,906,907,917,932,932,936,954,973,989,986,991,990,1002,1009,1021,1024,1040,1038,1058,1078,1098,1092,1094,1099,1122,1132,1140,1151,1154,1161,1176,1185,1202,1206,1227,1228,1243,1265,1281,1288,1296,1325,1328,1336,1354,1373,1375,1393,1398,1411,1432,1457,1462,1476,1487,1485,1506,1509,1521,1524,1537,1543,1563,1586,1598,1614,1621,1620,1640,1658,1660,1673,1670,1686,1708,1715,1726,1726,1745,1749,1767,1774,1790,1798,1803,1805,1815,1818,1819,1820,1833,1822,1821,1819,1838,1835,1845,1841,1851,1869,1865,1868,1871,1870,1879,1882,1886,1900,1899,1908,1921,1928,1954,1966,1976,1986,1999,2007,2015,2030,2036,2057,2067,2072,2077,2088,2101,2106,2112,2119,2127,2142,2171,2176,2203,2226,2242,2241,2244,2254,2263,2284,2300,2320,2327,2345,2364,2367,2402,2423,2425,2434,2443,2461,2476,2495,2505,2520,2531,2535,2556,2567,2599,2608,2625,2639,2660,2663,2668,2681,2695,2702,2709,2719,2720,2738,2746,2763,2778,2788,2796,2807,2822,2831,2831,2853,2863,2866,2883,2892,2895,2921,2919,2937,2941,2947,2964,2987,2992,2987,2995,3002,3021,3025,3026,3036,3052,3049,3059,3077,3075,3083,3086,3107,3123,3124,3146,3155,3168,3179,3204,3205,3211,3233,3252,3253,3276,3287,3294,3293,3297,3314,3326,3335,3338,3355,3362,3358,3365,3364,3376,3375,3382,3418,3429,3432,3455,3463,3483,3490,3502,3509,3521,3532,3542,3544,3553,3571,3580,3588,3596,3603,3633,3639,3649,3655,3660,3670,3699,3699,3707,3723,3747,3752,3754,3766,3772,3778,3781,3798,3815,3814,3824,3832,3853,3859,3879,3885,3899,3912,3910,3924,3937,3951,3951,3961,3963,3961,3976,3977,3988,4004,4018,4025,4047,4074,4086,4108,4133,4136,4159,4168,4182,4192,4200,4215,4230,4239,4257,4678,4698,4694,4713,4719,4739,4750,4756,4764,4771,4788,4792,4790,4809,4821,4829,4834,4836,4843,4853,4863,4872,4881,4890,4898,4901,4897,4895,4884,4886,4886,4894,4897,4905,4905,4909,4907,4925,4918,4920,4929,4925,4928,4936,4943,4944,4951,4955,4952,4974,4976,4975,4981,4994,4997,5022,5023,5032,5043,5048,5051,5066,5062,5068,5075,5082,5082,5098,5102,5110,5113,5119,5123,5138,5138,5145,5149,5157,5165,5166,5169,5178,5183,5190,5192,5203,5204,5207,5214,5228,5234,5245,5249,5256,5262,5275,5278,5305,5303,5315,5321,5348,5358,5369,5369,5372,5385,5402,5409,5427,5429,5429,5439,5456,5464,5481,5485,5494,5509,5520,5526,5543,5555,5568,5575,5585,5596,5602,5620,5627,5644,5647,5660,5678,5680,5684,5692,5700,5711,5727,5733,5736,5756,5776,5797,5805,5804,5807,5800,5808,5814,5822,5839,5856,5869,5889,5902,5919,5921,5936,5937,5936,5957,5961,5975,5981,6002,6015,6027,6035,6042,6059,6062,6080,6081,6092,6097,6106,6127,6129,6198,6227,6231,6243,6249,6262,6255,6279,6304,6315,6326,6330,6334,6361,6358,6359,6379,6381,6389,6388,6404,6404,6443,6465,6473,6497,6500,6513,6524,6532,6538,6578,6572,6576,6584,6582,6608,6639,6656,6761,6764,6768,6772,6836,6905,6916,6925,6951,6984,7009,7072,7092,7110,7122,7140,7148,7170,7168,7180,7194,7247,7374,7391,7393,7382,7425,7485,7530,7568,7587,7602,7602,7715,7771,7900,8004,8103,8153,8162,8296,8319,8437,8566,8746,8860,8913,9128,9275,9585,9739,10014,10123,10167,10203,10288,10323,10398,10544,10721,10883,11044,11157,11442,11515,11787,12070,12269,12468,12484,12619,12883,13008,13264,13317,13549,13859,14049,14175,14360,14498,14687,14843,14984,15093,15279,15431,15623,15741,15788,15966,16025,16132,16419,16568,16791,16892,17060,17269,17598,17959,18194,18482,18804,19136,19564,19990,20249,20509,20943,21248,21539,21845,22196,22412];class Os{static FIRST_ORBIT="1957-10-04";static EARTH_RADIUS_KM=6371;static LOW_ORBIT_KM=500;static shadowHeightKm(e){if(e>=0)return 0;const t=-e*Math.PI/180;return Os.EARTH_RADIUS_KM*(1/Math.cos(t)-1)}static isLitOverhead(e,t){return e>Os.shadowHeightKm(t)}static classesAt(e){const t=e.getTime();return X6.filter(i=>{const n=Date.parse(`${i.from}T00:00:00Z`),s=i.to===void 0?1/0:Date.parse(`${i.to}T23:59:59Z`);return t>=n&&t<=s})}static trackedInOrbitAt(e){const t=e.getUTCFullYear()*12+e.getUTCMonth()-$6;if(!(t<0))return zb[Math.min(t,zb.length-1)]}static visibilityAt(e,t){const i=Ki("Sun",e,t).altitudeDeg;return{sunAltitudeDeg:i,shadowHeightKm:Os.shadowHeightKm(i),lowOrbitLit:Os.isLitOverhead(Os.LOW_ORBIT_KM,i),classes:Os.classesAt(e),trackedObjects:Os.trackedInOrbitAt(e),anythingInOrbit:e.getTime()>=Date.parse(`${Os.FIRST_ORBIT}T00:00:00Z`)}}}const Hb="https://ufoathome.org/reentries/index.json";class Kn{static MINUTE_SLACK_MS=60*6e4;static WINDOW_SLACK_MS=60*6e4;static VISIBLE_KM=1500;static VISIBLE_DEG=Kn.VISIBLE_KM/111.2;static EARTH_RADIUS_KM=6371;fetchImpl;indexUrls;index;years=new Map;constructor(e={}){this.fetchImpl=e.fetchImpl??fetch.bind(globalThis),this.indexUrls=e.indexUrls??Kn.defaultIndexUrls()}static defaultIndexUrls(){const e=[];return typeof location<"u"&&/^https?:$/.test(location.protocol)&&e.push(new URL("/reentries/index.json",location.href).href),e.includes(Hb)||e.push(Hb),e}async credit(){return(await this.loadIndex())?.index.credit}async candidates(e,t,i){const n=await this.loadIndex();if(!n)return;const s=new Set;for(const a of[e-Kn.DAY_MS,t+Kn.DAY_MS])s.add(String(new Date(a).getUTCFullYear()));const r=(await Promise.all([...s].filter(a=>n.index.years.includes(a)).map(a=>this.yearOf(a,n.base)))).flat();return Kn.match(r,e,t,i)}static DAY_MS=864e5;static match(e,t,i,n){const s=[];for(const a of e){if(a.inclinationDeg!==void 0&&Math.abs(n.lat)>a.inclinationDeg+Kn.VISIBLE_DEG)continue;const l=Date.parse(a.precision==="day"?`${a.time}T00:00Z`:a.time);if(Number.isFinite(l))if(a.precision==="minute"){const c=l<t?t-l:l>i?l-i:0;if(c>Kn.MINUTE_SLACK_MS)continue;let h;if(a.seenLat!==void 0&&a.seenLng!==void 0&&(h=Kn.distanceKm(n.lat,n.lng,a.seenLat,a.seenLng),h>Kn.VISIBLE_KM))continue;s.push({record:a,timeMs:l,offsetMinutes:Math.round(c/6e4),seenKm:h})}else{const c=a.precision==="day"?Kn.DAY_MS/2:(a.uncertaintyHours??0)*36e5,h=a.precision==="day"?l+c:l,d=Kn.WINDOW_SLACK_MS;if(h+c+d<t||h-c-d>i)continue;s.push({record:a,timeMs:h})}}const r={minute:0,hours:1,day:2};return s.sort((a,l)=>r[a.record.precision]-r[l.record.precision]||(a.record.uncertaintyHours??0)-(l.record.uncertaintyHours??0)||a.timeMs-l.timeMs)}static distanceKm(e,t,i,n){const s=Math.PI/180,r=Math.sin(e*s)*Math.sin(i*s)+Math.cos(e*s)*Math.cos(i*s)*Math.cos((n-t)*s);return Kn.EARTH_RADIUS_KM*Math.acos(Math.max(-1,Math.min(1,r)))}loadIndex(){return this.index??=(async()=>{for(const e of this.indexUrls)try{const t=await this.fetchImpl(e);if(t.ok)return{index:await t.json(),base:e}}catch{}})(),this.index}yearOf(e,t){let i=this.years.get(e);return i||(i=this.fetchImpl(new URL(`${e}.json`,t).href).then(n=>n.ok?n.json():[]).catch(()=>[]),this.years.set(e,i)),i}}const Y6="https://ufoathome.org/light-pollution/index.json";class no{year=2015;citation="World Atlas of the artificial night sky brightness (Falchi et al. 2016, doi:10.1126/sciadv.1600377; data doi:10.5880/GFZ.1.4.2016.001, CC BY-NC 4.0)";static NATURAL_MCD=.171168;fetchImpl;indexUrls;index;tiles=new Map;constructor(e={}){this.fetchImpl=e.fetchImpl??fetch.bind(globalThis),this.indexUrls=e.indexUrls??no.defaultIndexUrls()}static defaultIndexUrls(){const e=typeof location>"u"?void 0:new URL("/light-pollution/index.json",location.href).href;return[...new Set([e,Y6].filter(t=>t!==void 0))]}static magPerArcsec2Of(e){return-2.5*Math.log10((e+no.NATURAL_MCD)/108e6)}static mcdOf(e,t){return e===0?0:t.floorMcd*10**((e-1)/t.subdivisions)}async lookUp(e,t){const i=await this.loadIndex();if(!i)return{status:"failed"};const{index:n,base:s,present:r}=i;if(!(e<n.north&&e>=n.south))return{status:"outside"};const a=((t+180)%360+360)%360-180,l=Math.floor((n.north-e)/n.tileDeg),c=Math.floor((a+180)/n.tileDeg),h=l*(360/n.tileDeg)+c;if(!(r[h>>3]&1<<(h&7)))return{status:"natural"};const d=n.north-l*n.tileDeg,u=-180+c*n.tileDeg,f=no.nameOf(d-n.tileDeg,u),p=await this.tile(`${s}${f}.bin`);if(!p)return{status:"failed"};const g=n.tileDeg/n.cells,m=Math.min(n.cells-1,Math.floor((d-e)/g)),v=Math.min(n.cells-1,Math.floor((a-u)/g)),b=no.mcdOf(p[m*n.cells+v],n);return b===0?{status:"natural"}:{status:"found",lightPollution:Math.round(no.magPerArcsec2Of(b)*100)/100,artificialMcdPerM2:b,lat:d-(m+.5)*g,lng:u+(v+.5)*g}}static nameOf(e,t){const i=`${e<0?"S":"N"}${String(Math.abs(e)).padStart(2,"0")}`,n=`${t<0?"W":"E"}${String(Math.abs(t)).padStart(3,"0")}`;return i+n}loadIndex(){return this.index??=(async()=>{for(const e of this.indexUrls)try{const t=await this.fetchImpl(e);if(!t.ok)continue;const i=await t.json(),n=Uint8Array.from(atob(i.present),s=>s.charCodeAt(0));return{index:i,base:new URL(".",e).href,present:n}}catch{}})(),this.index.then(e=>{e||(this.index=void 0)}),this.index}tile(e){let t=this.tiles.get(e);return t||(t=(async()=>{try{const i=await this.fetchImpl(e);if(!i.ok||!i.body)return;const n=i.body.pipeThrough(new DecompressionStream("deflate-raw"));return new Uint8Array(await new Response(n).arrayBuffer())}catch{return}})(),this.tiles.set(e,t),t.then(i=>{i||this.tiles.delete(e)})),t}}const Gb=[{id:"falchi-2015",name:"World Atlas 2015",credit:"Falchi et al. 2016, CC BY-NC 4.0",creditUrl:"https://doi.org/10.5880/GFZ.1.4.2016.001",create:()=>new no}];class Ct{static COARSE_STEP_DEG=10;static FINE_STEP_DEG=2;static FINE_SPAN_DEG=10;static LOWEST_DEG=5;static THRESHOLD_CONTRAST=.5;static CONE_SEPARATION_DEG=60;galaxy=new Mt;dust=new gi;assess(e,t,i){const n=Ki("Sun",e,t),s=Ki("Moon",e,t),r={altitudeDeg:s.altitudeDeg,phaseAngleDeg:ce.phaseAngleOf(io(e).illuminatedFraction)},a=as.galactic(e,t),l=Ct.unit(a.centre),c=Ct.unit(a.rotation),h=Ct.unit(a.pole),d=Ct.unit(as.eclipticPole(e,t)),u=Ct.unit(n),f=Ct.unit(s),p=Ct.normalize(Ct.reject(u,d));let g,m,v=0;const b=(x,y)=>{const w=Ct.unit({altitudeDeg:x,azimuthDeg:y}),S=Ct.between(w,u),A=ce.magPerArcsec2({altitudeDeg:n.altitudeDeg,separationDeg:S},{...r,separationDeg:Ct.between(w,f)},x,i);A>v&&(v=A);const M=Yr.fromMagPerArcsec2(A),_=10**(-.4*ce.EXTINCTION_PER_AIR_MASS*(ce.airMass(x)-1)),I=this.galaxy.surfaceBrightnessS10(Math.atan2(Ct.dot(w,c),Ct.dot(w,l))*180/Math.PI,Math.asin(Math.max(-1,Math.min(1,Ct.dot(w,h))))*180/Math.PI)*_;g=Ct.better(g,I,M,A,x,y,S);const R=Math.max(-1,Math.min(1,Ct.dot(w,d))),L=Ct.normalize(Ct.reject(w,d)),P=this.dust.surfaceBrightnessS10(Ct.between(L,p),Math.asin(R)*180/Math.PI)*_;m=Ct.better(m,P,M,A,x,y,S)};for(let x=Ct.LOWEST_DEG;x<=90;x+=Ct.COARSE_STEP_DEG)for(let y=0;y<360;y+=Ct.COARSE_STEP_DEG)b(x,y);for(const x of[g,m]){if(!x)continue;const y=Ct.FINE_SPAN_DEG,w=Ct.FINE_STEP_DEG;for(let S=x.altitudeDeg-y;S<=x.altitudeDeg+y;S+=w)if(!(S<Ct.LOWEST_DEG||S>90))for(let A=x.azimuthDeg-y;A<=x.azimuthDeg+y;A+=w)b(S,(A+360)%360)}return{milkyWay:g&&g.contrast>=Ct.THRESHOLD_CONTRAST?g:void 0,zodiacal:m&&m.contrast>=Ct.THRESHOLD_CONTRAST?m:void 0,darkestSkyMagPerArcsec2:v}}static better(e,t,i,n,s,r,a){const l=t/i;return e&&e.contrast>=l?e:{contrast:l,altitudeDeg:s,azimuthDeg:r,magPerArcsec2:Yr.toMagPerArcsec2(t),skyMagPerArcsec2:n,sunSeparationDeg:a}}static unit(e){const t=e.altitudeDeg*Math.PI/180,i=e.azimuthDeg*Math.PI/180,n=Math.cos(t);return[n*Math.sin(i),Math.sin(t),-n*Math.cos(i)]}static dot(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}static between(e,t){return Math.acos(Math.max(-1,Math.min(1,Ct.dot(e,t))))*180/Math.PI}static reject(e,t){const i=Ct.dot(e,t);return[e[0]-i*t[0],e[1]-i*t[1],e[2]-i*t[2]]}static normalize(e){const t=Math.hypot(...e)||1;return[e[0]/t,e[1]/t,e[2]/t]}}const q6=.5,Vd=40,K6=4e5,$a=Math.PI/180,yl=180/Math.PI;class Xn{static localDirection(e,t,i,n=new D){const s=Math.tan(t/2*$a);return n.set((e.u*2-1)*s*i,(1-e.v*2)*s,-1).normalize()}static picturePoint(e,t,i){if(e.z>=0)return;const n=Math.tan(t/2*$a),s=e.x/-e.z/(n*i),r=e.y/-e.z/n;return{u:(s+1)/2,v:(1-r)/2}}static worldDirection(e,t=new D){const i=e.azimuthDeg*$a,n=e.altitudeDeg*$a;return t.set(Math.sin(i)*Math.cos(n),Math.sin(n),-Math.cos(i)*Math.cos(n))}static aimOf(e){const t=Math.hypot(e.x,e.z);return{azimuthDeg:(Math.atan2(e.x,-e.z)*yl+360)%360,altitudeDeg:Math.atan2(e.y,t)*yl}}static rotationOf(e){const t=new hi;return t.rotation.set(e.pitchDeg*$a,-e.headingDeg*$a,-(e.rollDeg??0)*$a,"YXZ"),t.quaternion.clone()}static anglesOf(e){const t=new wr().setFromQuaternion(e,"YXZ"),i=(-t.y*yl%360+360)%360,n=-t.z*yl;return{headingDeg:i,pitchDeg:t.x*yl,rollDeg:Math.abs(n)<1e-9?0:n}}static worldDirectionOf(e,t,i,n=new D){return this.localDirection(e,t.fovDeg,i,n).applyQuaternion(this.rotationOf(t))}static picturePointOf(e,t,i){const n=e.clone().applyQuaternion(this.rotationOf(t).invert()),s=this.picturePoint(n,t.fovDeg,i);if(!(!s||s.u<0||s.u>1||s.v<0||s.v>1))return s}static solve(e,t,i,n=e.length>=3){if(e.length<2)return;if(!n)return this.solveAtField(e,t,i);let s=1,r=179;const a=(Math.sqrt(5)-1)/2;let l=r-a*(r-s),c=s+a*(r-s),h=this.solveAtField(e,t,l),d=this.solveAtField(e,t,c);for(let f=0;f<60&&r-s>1e-4;f++){if(!h||!d)return;h.residualDeg<d.residualDeg?(r=c,c=l,d=h,l=r-a*(r-s),h=this.solveAtField(e,t,l)):(s=l,l=c,h=d,c=s+a*(r-s),d=this.solveAtField(e,t,c))}return h&&d?h.residualDeg<d.residualDeg?h:d:h??d}static solveAtField(e,t,i){const n=e.map(c=>this.localDirection(c.picture,i,t)),s=e.map(c=>this.worldDirection(c.scene)),r=this.triad(n,s);if(!r)return;const a=this.refine(r,n,s);return{registration:{...this.anglesOf(a),fovDeg:i},residualDeg:this.residualDeg(a,n,s)}}static triad(e,t){let i=0,n=1,s=-1;for(let h=0;h<e.length;h++)for(let d=h+1;d<e.length;d++){const u=e[h].clone().cross(e[d]).lengthSq();u>s&&(s=u,i=h,n=d)}if(s<1e-12)return;const r=(h,d)=>{const u=h.clone().normalize(),f=h.clone().cross(d).normalize(),p=f.clone().cross(u);return new je().set(u.x,p.x,f.x,u.y,p.y,f.y,u.z,p.z,f.z)},a=r(e[i],e[n]),c=r(t[i],t[n]).multiply(a.transpose());return new An().setFromRotationMatrix(new lt().setFromMatrix3(c))}static refine(e,t,i){const n=e.clone(),s=new D;for(let r=0;r<20;r++){const a=new je().set(0,0,0,0,0,0,0,0,0),l=a.elements,c=new D;for(let f=0;f<t.length;f++){s.copy(t[f]).applyQuaternion(n);const p=s,g=[[0,p.z,-p.y],[-p.z,0,p.x],[p.y,-p.x,0]],m=[i[f].x-p.x,i[f].y-p.y,i[f].z-p.z];for(let v=0;v<3;v++){for(let b=0;b<3;b++)for(let x=0;x<3;x++)l[b*3+v]+=g[x][v]*g[x][b];c.setComponent(v,c.getComponent(v)+g[0][v]*m[0]+g[1][v]*m[1]+g[2][v]*m[2])}}for(let f=0;f<3;f++)l[f*3+f]+=1e-9;const h=c.applyMatrix3(a.invert()),d=h.length();if(d<1e-12)break;const u=new An().setFromAxisAngle(h.normalize(),d);if(n.premultiply(u).normalize(),d<1e-10)break}return n}static residualDeg(e,t,i){let n=0;const s=new D;for(let r=0;r<t.length;r++){s.copy(t[r]).applyQuaternion(e);const a=s.angleTo(i[r])*yl;n+=a*a}return Math.sqrt(n/t.length)}}const Vb=6371e3,Hc=Math.PI/180;class Ll{constructor(e=t=>fetch(t).then(i=>{if(!i.ok)throw new Error(`${t}: HTTP ${i.status}`);return i.json()})){this.fetchJson=e}static API="https://api.panoramax.xyz/api";static CREDIT="Panoramax";static CREDIT_URL="https://panoramax.fr/";async nearby(e,t,i=300,n=50){const s=i/111320,r=i/(111320*Math.cos(e*Hc)),a=[t-r,e-s,t+r,e+s].map(h=>h.toFixed(6)).join(",");return((await this.fetchJson(`${Ll.API}/search?bbox=${a}&limit=${n}`)).features??[]).map(h=>this.picture(h,e,t)).filter(h=>h!==void 0&&h.distanceM<=i).sort((h,d)=>h.distanceM-d.distanceM)}picture(e,t,i){const[n,s]=e.geometry.coordinates,r=e.assets.sd?.href??e.assets.hd?.href;if(!r)return;const{distanceM:a,bearingDeg:l}=Ll.offset(t,i,s,n),c=e.properties,h=c["pers:interior_orientation"]?.field_of_view,d=(c.providers??[]).map(f=>f.name).filter(f=>!!f),u=c.license??"CC-BY-SA-4.0";return{id:e.id,lat:s,lng:n,distanceM:a,bearingDeg:l,azimuthDeg:c["view:azimuth"],panorama:h!==void 0&&h>=360,takenAt:c.datetime??"",src:r,srcFull:e.assets.hd?.href,credit:`${Ll.CREDIT}${d.length?` — ${d.join(", ")}`:""} (${u})`,creditUrl:`${Ll.API.replace(/\/api$/,"")}/#focus=pic&pic=${e.id}`}}static offset(e,t,i,n){const s=(i-e)*Hc*Vb,r=(n-t)*Hc*Vb*Math.cos((e+i)/2*Hc);return{distanceM:Math.hypot(r,s),bearingDeg:(Math.atan2(r,s)/Hc+360)%360}}}const Wd=36e5,Wb=25;class o0{constructor(e){this.provider=e}async infer(e){const t=this.questionOf(e);if(!t)return{status:"incomplete"};const{origin:i,start:n}=t,s=ec(e.event)??0,r=this.sampleTimings(e,n,s);let a;try{a=await this.provider.getWeather({points:r.map(l=>this.pointAt(e,l,i))})}catch{return{status:"failed",at:n}}return a?{status:"inferred",at:n,source:a.source,keyframes:a.samples.map((l,c)=>({t:r[c].t,weather:l.weather}))}:{status:"unavailable",at:n}}applyTo(e,t){if(!(t.status!=="inferred"||!t.keyframes||!t.source)){e.weatherTrack.clear();for(const i of t.keyframes)e.weatherTrack.addKeyframe(i.t,i.weather);e.weatherSource=t.source}}sampleTimes(e,t){const i=[e],n=e.getTime()+t;let s=Math.floor(e.getTime()/Wd)*Wd+Wd;for(;s<=n&&i.length<Wb;)i.push(new Date(s)),s+=Wd;return t>0&&i[i.length-1].getTime()!==n&&i.length<Wb&&i.push(new Date(n)),i}sampleTimings(e,t,i){const n=e.timeline.duration>0?e.timeline.duration:i;return i<=0||n<=0?[{time:t,t:0}]:this.sampleTimes(t,i).map(s=>{const r=(s.getTime()-t.getTime())/i;return{time:s,t:Math.round(n*Math.max(0,Math.min(1,r)))}})}canInfer(e){return this.questionOf(e)!==void 0}missingOf(e){const t=e.event.time;return{date:t?.year===void 0||t.month===void 0||t.day===void 0,place:this.originOf(e)===void 0}}questionOf(e){const t=this.originOf(e);if(!t)return;const i=e.event.time;if(i?.year===void 0||i.month===void 0||i.day===void 0)return;const n=ds(i,t.lng,e.event.utcOffsetHours);return n?{origin:t,start:n}:void 0}originOf(e){const t=at(e,0),i=e.event.place?.[0],n=t?.lat??i?.lat,s=t?.lng??i?.lng;return n===void 0||s===void 0?void 0:{lat:n,lng:s}}pointAt(e,t,i){const n=at(e,t.t);return{lat:n?.lat??i.lat,lng:n?.lng??i.lng,time:t.time}}}const Z6=Date.UTC(1940,0,1),Xb=36e5,$b=.25,j6=.7,J6=.45,Q6=.1,ek=2,tk=.3,ik=.2,nk=8,l0=.125,sk=.05,Yb=125,qb=100,Kb=2500,c0=3500,h0=8e3,rk=95,ak=99,ok=[96,99],lk=["cloud_cover","cloud_cover_low","cloud_cover_mid","cloud_cover_high","precipitation","snowfall","weather_code","wind_speed_10m","wind_direction_10m","temperature_2m","dew_point_2m"],ck=5;class E2{fetchImpl;baseUrl;forecastUrl;now;cache=new Map;constructor(e={}){this.fetchImpl=e.fetchImpl??fetch.bind(globalThis),this.baseUrl=e.baseUrl??"https://archive-api.open-meteo.com/v1/archive",this.forecastUrl=e.forecastUrl??"https://api.open-meteo.com/v1/forecast",this.now=e.now??(()=>new Date)}async getWeather(e){if(e.points.length===0)return;const t=e.points.map(h=>h.time.getTime()),i=Math.min(...t);if(i<Z6)return;const n=new Map;for(const h of e.points){const d=this.cellKey(h);n.has(d)||n.set(d,{lat:h.lat,lng:h.lng,index:n.size})}const s=i>=this.now().getTime()-ck*864e5,r=this.requestUrl([...n.values()],new Date(i),new Date(Math.max(...t)),s);let a=this.cache.get(r);if(!a){const h=await this.fetchImpl(r);if(!h.ok)throw new Error(`Open-Meteo HTTP ${h.status}`);const d=await h.json();if(a=Array.isArray(d)?d:[d],a.length<n.size||a.some(u=>u.error||!u.hourly))return;this.cache.set(r,a)}const l=s?{id:"open-meteo-forecast",name:"Open-Meteo (forecast model)",url:r}:{id:"era5",name:"ERA5 (Open-Meteo)",url:r},c=e.points.map(h=>this.sampleAt(a[n.get(this.cellKey(h)).index].hourly,h.time));if(!c.some(h=>h===void 0))return{samples:c,source:l}}cellKey(e){return`${Math.round(e.lat/$b)},${Math.round(e.lng/$b)}`}requestUrl(e,t,i,n){const s=new URLSearchParams({latitude:e.map(r=>r.lat).join(","),longitude:e.map(r=>r.lng).join(","),start_date:this.isoDate(t),end_date:this.isoDate(i),hourly:lk.join(","),wind_speed_unit:"ms",timezone:"UTC"});return`${n?this.forecastUrl:this.baseUrl}?${s}`}isoDate(e){return e.toISOString().slice(0,10)}sampleAt(e,t){const i=this.recordAt(e,t);return i&&{time:t,weather:this.toWeather(i)}}recordAt(e,t){const i=e.time.map(a=>Date.parse(`${a}Z`)),n=t.getTime();if(i.length===0||n<i[0]-Xb||n>i[i.length-1]+Xb)return;if(n<=i[0])return this.recordFrom(e,0);if(n>=i[i.length-1])return this.recordFrom(e,i.length-1);let s=0;for(;s+1<i.length&&i[s+1]<=n;)s++;const r=i[s+1]-i[s];return this.blendRecords(this.recordFrom(e,s),this.recordFrom(e,s+1),r>0?(n-i[s])/r:0)}recordFrom(e,t){const i={cloudCover:e.cloud_cover[t]/100,cloudCoverLow:e.cloud_cover_low[t]/100,cloudCoverMid:e.cloud_cover_mid[t]/100,cloudCoverHigh:e.cloud_cover_high[t]/100,precipitationMm:e.precipitation[t],snowfallCm:e.snowfall[t],weatherCode:e.weather_code[t],windSpeedMs:e.wind_speed_10m[t],windFromDeg:e.wind_direction_10m[t],temperatureC:e.temperature_2m[t],dewPointC:e.dew_point_2m[t]};return Object.values(i).some(n=>n===void 0||Number.isNaN(n))?void 0:i}blendRecords(e,t,i){if(!e||!t)return e??t;const n=(r,a)=>r+(a-r)*i,s=((t.windFromDeg-e.windFromDeg)%360+540)%360-180;return{cloudCover:n(e.cloudCover,t.cloudCover),cloudCoverLow:n(e.cloudCoverLow,t.cloudCoverLow),cloudCoverMid:n(e.cloudCoverMid,t.cloudCoverMid),cloudCoverHigh:n(e.cloudCoverHigh,t.cloudCoverHigh),precipitationMm:n(e.precipitationMm,t.precipitationMm),snowfallCm:n(e.snowfallCm,t.snowfallCm),weatherCode:i<.5?e.weatherCode:t.weatherCode,windSpeedMs:n(e.windSpeedMs,t.windSpeedMs),windFromDeg:((e.windFromDeg+s*i)%360+360)%360,temperatureC:n(e.temperatureC,t.temperatureC),dewPointC:n(e.dewPointC,t.dewPointC)}}cloudLayersFrom(e){return[{id:"record-low",type:"unknown",baseM:Math.round(this.clamp(Yb*(e.temperatureC-e.dewPointC),qb,Kb)),thicknessM:650,coverage:this.clamp(e.cloudCoverLow,0,1),sizeM:1400,density:1},{id:"record-mid",type:"unknown",baseM:c0,thicknessM:800,coverage:this.clamp(e.cloudCoverMid,0,1),sizeM:2500,density:1},{id:"record-high",type:"cirrus",baseM:h0,thicknessM:400,coverage:this.clamp(e.cloudCoverHigh,0,1),sizeM:2200,density:.35}]}toWeather(e){const t=e.weatherCode>=rk&&e.weatherCode<=ak,i=this.precipitationTypeFrom(e);return{cloudLayers:this.cloudLayersFrom(e),cloudCover:this.clamp(e.cloudCover,0,1),cloudDarkness:this.cloudDarknessFrom(e,t),cloudBaseM:this.cloudBaseFrom(e),highCloudCover:e.cloudCoverHigh,lowerCloudCover:Math.max(e.cloudCoverLow,e.cloudCoverMid),relativeHumidity:Math.round(Hr.relativeHumidity(e.temperatureC,e.dewPointC)*100)/100,precipitationType:i,precipitationIntensity:i==="none"?0:this.clamp(Math.sqrt(e.precipitationMm/nk),0,1),windDirectionDeg:(e.windFromDeg+180)%360,windSpeed:e.windSpeedMs,storm:t}}precipitationTypeFrom(e){return e.snowfallCm>0?"snow":ok.includes(e.weatherCode)?"hail":e.precipitationMm>0?"rain":"none"}cloudDarknessFrom(e,t){const i=e.cloudCoverLow+e.cloudCoverMid+e.cloudCoverHigh;if(i<=0)return 0;const n=(j6*e.cloudCoverLow+J6*e.cloudCoverMid+Q6*e.cloudCoverHigh)/i,s=Math.min(1,e.precipitationMm/ek);return this.clamp(n+tk*s+(t?ik:0),0,1)}cloudBaseFrom(e){if(e.cloudCover<sk)return;const t=this.clamp(Yb*(e.temperatureC-e.dewPointC),qb,Kb);if(e.cloudCoverLow>=l0)return Math.round(t);if(e.cloudCoverMid>=l0)return c0;if(e.cloudCoverHigh>=l0)return h0;const i=Math.max(e.cloudCoverLow,e.cloudCoverMid,e.cloudCoverHigh);if(!(i<=0))return i===e.cloudCoverLow?Math.round(t):i===e.cloudCoverMid?c0:h0}clamp(e,t,i){return Math.max(t,Math.min(i,e))}}function hk(){return new E2}const dk=5;class A2{attribution={text:"© OpenStreetMap",url:"https://osm.org/copyright"};fetchImpl;baseUrl;reverseUrl;cache=new Map;constructor(e={}){this.fetchImpl=e.fetchImpl??fetch.bind(globalThis),this.baseUrl=e.baseUrl??"https://nominatim.openstreetmap.org/search",this.reverseUrl=e.reverseUrl??"https://nominatim.openstreetmap.org/reverse"}async reverse(e,t,i={}){const n=new URLSearchParams({lat:String(e),lon:String(t),format:"jsonv2"});i.language&&n.set("accept-language",i.language);const s=`${this.reverseUrl}?${n}`,r=this.cache.get(s);if(r)return r[0];const a=await this.fetchImpl(s,{signal:i.signal});if(!a.ok)throw new Error(`Nominatim HTTP ${a.status}`);const l=await a.json(),c=l.error?void 0:this.toMatch(l);return this.cache.set(s,c?[c]:[]),c}async search(e,t={}){const i=e.trim();if(i==="")return[];const n=this.requestUrl(i,t),s=this.cache.get(n);if(s)return s;const r=await this.fetchImpl(n,{signal:t.signal});if(!r.ok)throw new Error(`Nominatim HTTP ${r.status}`);const a=await r.json(),l=(Array.isArray(a)?a:[]).map(c=>this.toMatch(c)).filter(c=>c!==void 0);return this.cache.set(n,l),l}requestUrl(e,t){const i=new URLSearchParams({q:e,format:"jsonv2",limit:String(t.limit??dk)});return t.language&&i.set("accept-language",t.language),`${this.baseUrl}?${i}`}toMatch(e){const t=e.display_name??e.name,i=this.coordinate(e.lat),n=this.coordinate(e.lon);return t&&i!==void 0&&n!==void 0?{name:t,lat:i,lng:n}:void 0}coordinate(e){if(e===void 0||e.trim()==="")return;const t=Number(e);return Number.isFinite(t)?t:void 0}}function uk(){return new A2}const fk=[{id:"nominatim",name:"Nominatim",credit:"© OpenStreetMap",creditUrl:"https://osm.org/copyright",create:()=>new A2}],qm=[{id:"era5",name:"Open-Meteo",credit:"© Copernicus/ECMWF",creditUrl:"https://open-meteo.com/en/docs/historical-weather-api",create:()=>new E2}],d0=o=>o.id==="open-meteo-forecast"||qm.some(e=>e.id===o.id);class pk{attribution;fetchImpl;tileUrlTemplate;constructor(e={}){this.fetchImpl=e.fetchImpl??fetch.bind(globalThis);const t=e.year??2024;this.tileUrlTemplate=`https://tiles.maps.eox.at/wmts/1.0.0/s2cloudless-${t}_3857/default/g/{z}/{y}/{x}.jpg`,this.attribution=`EOxCloudless https://cloudless.eox.at by EOX IT Services GmbH (Contains modified Copernicus Sentinel data ${t})`}async getImageryTexture(e,t){return HM(e,t,i=>this.tileUrlTemplate.replace("{z}",String(i.z)).replace("{y}",String(i.y)).replace("{x}",String(i.x)),this.fetchImpl)}}const u0=[{id:"ign-mnt",name:"IGN LiDAR HD / RGE ALTI",credit:"Relief © IGN, LiDAR HD and RGE ALTI (Licence Ouverte 2.0) in France; © AWS Open Data (SRTM, ETOPO1) elsewhere",creditUrl:"https://geoservices.ign.fr/lidarhd",create:()=>VM()},{id:"aws-terrarium",name:"AWS Terrain Tiles",credit:"© AWS Open Data (SRTM, ETOPO1)",creditUrl:"https://registry.opendata.aws/terrain-tiles/",create:()=>new zM}],Zb=[{id:"esri-world",name:"Esri World Imagery",credit:"Imagery © Esri, Maxar, Earthstar Geographics, and the GIS User Community",creditUrl:"https://www.arcgis.com/home/item.html?id=10df2279f9684e4a9f6a7f08febac2a9",create:()=>new GM},{id:"eox-s2cloudless",name:"EOX Sentinel-2 cloudless",credit:"EOxCloudless by EOX IT Services GmbH (contains modified Copernicus Sentinel data)",creditUrl:"https://cloudless.eox.at",create:()=>new pk}];class oh{constructor(e,t){this.root=e,this.messages=t}static STYLE=`
9804
+ `)){const s=this.ownerDocument.createElement("li");s.textContent=n,i.append(s)}this.popup.replaceChildren(t,i),this.setPrecise(this.precise)}setPrecise(e){this.build();const t=this.precise;this.precise=e,this.numberInput.hidden=!e,this.querySelector(".duration-unit").hidden=!e,this.textInput.hidden=e,this.helpButton.hidden=e,this.modeButton.textContent=e?this.wording.durationPrecise:this.wording.durationIso,this.modeButton.setAttribute("aria-pressed",String(!e)),!e&&t&&this.textInput.value===""&&this.numberInput.value!==""&&(this.textInput.value=kn.format(Number(this.numberInput.value))),this.showDeduction(),this.showChosen()}set(e,t){this.build(),this.numberInput.value=e===void 0?"":String(e),this.textInput.value=t??"",this.setPrecise(t===void 0)}readText(){const e=this.textInput.value.trim();if(this.showDeduction(),e===""){this.numberInput.value="",this.showChosen(),this.tell(void 0,void 0);return}const t=kn.parse(e);t&&(this.numberInput.value=String(t.chosenSeconds),this.showChosen(),this.tell(t.chosenSeconds,kn.isExact(e)?void 0:e))}tell(e,t){this.dispatchEvent(new CustomEvent("durationchange",{detail:{seconds:e,text:t},bubbles:!0,composed:!0}))}describe(e){const t=this.wording,i=e.minSeconds===e.maxSeconds?kn.say(e.minSeconds):`${kn.say(e.minSeconds)} – ${kn.say(e.maxSeconds)}`,n=e.doubt==="~"?t.timeQualifierApproximate:e.doubt==="?"?t.timeQualifierUncertain:e.doubt==="%"?t.timeQualifierBoth:"";return n?`${i} — ${n.toLowerCase()}`:i}showDeduction(){const e=this.textInput.value.trim();if(this.precise||e===""){this.textInput.title="";return}const t=kn.parse(e);this.textInput.title=t?`→ ${this.describe(t)}`:this.wording.durationInvalid}showChosen(){const e=this.precise?void 0:kn.parse(this.textInput.value),t=e!==void 0&&!kn.isExact(this.textInput.value);this.chosen.hidden=!t,this.chosen.textContent=t?this.wording.durationChosen.replace("{value}",kn.say(e.chosenSeconds)):""}}function W6(){customElements.get(df)||customElements.define(df,V6)}class uf{static easter(e){const t=e%19,i=Math.floor(e/100),n=e%100,s=Math.floor(i/4),r=i%4,a=Math.floor((i+8)/25),l=Math.floor((i-a+1)/3),c=(19*t+i-s-l+15)%30,h=Math.floor(n/4),d=n%4,u=(32+2*r+2*h-c-d)%7,f=Math.floor((t+11*c+22*u)/451),p=Math.floor((c+u-7*f+114)/31),g=(c+u-7*f+114)%31+1;return new Date(Date.UTC(e,p-1,g,12))}static lunation(e){if(e<1583)return;const t=uf.easter(e),i=su(0,t,40);if(!i)return;const n=su(180,i.date,20),s=su(0,new Date(i.date.getTime()+864e5),40);if(!(!n||!s))return{begin:i.date,full:n.date,end:s.date}}static isIn(e){const t=uf.lunation(e.getUTCFullYear());return t!==void 0&&e>=t.begin&&e<t.end}}const X6=[{id:"echo",name:"the Echo balloons",from:"1960-08-12",to:"1969-06-07",peakMagnitude:-1,note:"Echo 1 and 2 were 30- and 40-metre reflective balloons, as bright as the brightest stars and moving slowly enough to be watched — deliberately visible, widely announced in newspapers, and the first objects most people ever saw crossing the night sky. They fall squarely inside the sighting waves this project reconstructs."},{id:"iridium-flares",name:"the Iridium flares",from:"1997-05-05",to:"2019-12-27",peakMagnitude:-8,note:"The original Iridium satellites carried flat, mirror-finish antennas that threw a sunbeam a few kilometres wide across the ground: a still point of sky flaring to magnitude -8 over five seconds and vanishing again. Nothing else in the sky does that."},{id:"iss",name:"the International Space Station",from:"1998-11-20",peakMagnitude:-5.9,note:"Since its first module, and much brighter as it grew: at its best it outshines everything in the sky but the Sun and the Moon, crossing in a straight silent line in about four minutes."},{id:"starlink-trains",name:"the Starlink trains",from:"2019-05-24",peakMagnitude:1,note:"In the days after a launch, satellites still bunched in their deployment string cross as an evenly spaced line of lights — the most reported 'formation of UFOs' of the era. They spread out within weeks, so a train is a fact about the days after a launch rather than about the year."}],$6=23493,zb=[2,3,2,1,2,5,4,6,5,6,6,6,6,6,6,6,9,9,9,9,9,9,14,14,15,16,16,16,16,16,18,22,25,24,29,28,29,33,34,35,40,40,42,42,43,46,48,48,49,53,53,54,58,61,70,70,74,78,79,83,92,92,99,97,101,102,109,115,126,125,123,125,127,130,139,153,157,156,161,156,165,174,193,193,201,203,212,215,224,244,255,263,262,281,293,307,312,327,339,336,343,353,359,369,386,396,405,410,421,419,424,434,443,450,460,480,492,504,509,516,519,524,527,530,527,535,543,549,564,571,573,576,582,584,600,600,608,618,625,632,637,642,648,654,661,667,669,667,671,671,697,692,703,697,710,714,724,731,747,755,764,770,782,802,801,815,819,837,846,856,878,881,877,900,906,907,917,932,932,936,954,973,989,986,991,990,1002,1009,1021,1024,1040,1038,1058,1078,1098,1092,1094,1099,1122,1132,1140,1151,1154,1161,1176,1185,1202,1206,1227,1228,1243,1265,1281,1288,1296,1325,1328,1336,1354,1373,1375,1393,1398,1411,1432,1457,1462,1476,1487,1485,1506,1509,1521,1524,1537,1543,1563,1586,1598,1614,1621,1620,1640,1658,1660,1673,1670,1686,1708,1715,1726,1726,1745,1749,1767,1774,1790,1798,1803,1805,1815,1818,1819,1820,1833,1822,1821,1819,1838,1835,1845,1841,1851,1869,1865,1868,1871,1870,1879,1882,1886,1900,1899,1908,1921,1928,1954,1966,1976,1986,1999,2007,2015,2030,2036,2057,2067,2072,2077,2088,2101,2106,2112,2119,2127,2142,2171,2176,2203,2226,2242,2241,2244,2254,2263,2284,2300,2320,2327,2345,2364,2367,2402,2423,2425,2434,2443,2461,2476,2495,2505,2520,2531,2535,2556,2567,2599,2608,2625,2639,2660,2663,2668,2681,2695,2702,2709,2719,2720,2738,2746,2763,2778,2788,2796,2807,2822,2831,2831,2853,2863,2866,2883,2892,2895,2921,2919,2937,2941,2947,2964,2987,2992,2987,2995,3002,3021,3025,3026,3036,3052,3049,3059,3077,3075,3083,3086,3107,3123,3124,3146,3155,3168,3179,3204,3205,3211,3233,3252,3253,3276,3287,3294,3293,3297,3314,3326,3335,3338,3355,3362,3358,3365,3364,3376,3375,3382,3418,3429,3432,3455,3463,3483,3490,3502,3509,3521,3532,3542,3544,3553,3571,3580,3588,3596,3603,3633,3639,3649,3655,3660,3670,3699,3699,3707,3723,3747,3752,3754,3766,3772,3778,3781,3798,3815,3814,3824,3832,3853,3859,3879,3885,3899,3912,3910,3924,3937,3951,3951,3961,3963,3961,3976,3977,3988,4004,4018,4025,4047,4074,4086,4108,4133,4136,4159,4168,4182,4192,4200,4215,4230,4239,4257,4678,4698,4694,4713,4719,4739,4750,4756,4764,4771,4788,4792,4790,4809,4821,4829,4834,4836,4843,4853,4863,4872,4881,4890,4898,4901,4897,4895,4884,4886,4886,4894,4897,4905,4905,4909,4907,4925,4918,4920,4929,4925,4928,4936,4943,4944,4951,4955,4952,4974,4976,4975,4981,4994,4997,5022,5023,5032,5043,5048,5051,5066,5062,5068,5075,5082,5082,5098,5102,5110,5113,5119,5123,5138,5138,5145,5149,5157,5165,5166,5169,5178,5183,5190,5192,5203,5204,5207,5214,5228,5234,5245,5249,5256,5262,5275,5278,5305,5303,5315,5321,5348,5358,5369,5369,5372,5385,5402,5409,5427,5429,5429,5439,5456,5464,5481,5485,5494,5509,5520,5526,5543,5555,5568,5575,5585,5596,5602,5620,5627,5644,5647,5660,5678,5680,5684,5692,5700,5711,5727,5733,5736,5756,5776,5797,5805,5804,5807,5800,5808,5814,5822,5839,5856,5869,5889,5902,5919,5921,5936,5937,5936,5957,5961,5975,5981,6002,6015,6027,6035,6042,6059,6062,6080,6081,6092,6097,6106,6127,6129,6198,6227,6231,6243,6249,6262,6255,6279,6304,6315,6326,6330,6334,6361,6358,6359,6379,6381,6389,6388,6404,6404,6443,6465,6473,6497,6500,6513,6524,6532,6538,6578,6572,6576,6584,6582,6608,6639,6656,6761,6764,6768,6772,6836,6905,6916,6925,6951,6984,7009,7072,7092,7110,7122,7140,7148,7170,7168,7180,7194,7247,7374,7391,7393,7382,7425,7485,7530,7568,7587,7602,7602,7715,7771,7900,8004,8103,8153,8162,8296,8319,8437,8566,8746,8860,8913,9128,9275,9585,9739,10014,10123,10167,10203,10288,10323,10398,10544,10721,10883,11044,11157,11442,11515,11787,12070,12269,12468,12484,12619,12883,13008,13264,13317,13549,13859,14049,14175,14360,14498,14687,14843,14984,15093,15279,15431,15623,15741,15788,15966,16025,16132,16419,16568,16791,16892,17060,17269,17598,17959,18194,18482,18804,19136,19564,19990,20249,20509,20943,21248,21539,21845,22196,22412];class Os{static FIRST_ORBIT="1957-10-04";static EARTH_RADIUS_KM=6371;static LOW_ORBIT_KM=500;static shadowHeightKm(e){if(e>=0)return 0;const t=-e*Math.PI/180;return Os.EARTH_RADIUS_KM*(1/Math.cos(t)-1)}static isLitOverhead(e,t){return e>Os.shadowHeightKm(t)}static classesAt(e){const t=e.getTime();return X6.filter(i=>{const n=Date.parse(`${i.from}T00:00:00Z`),s=i.to===void 0?1/0:Date.parse(`${i.to}T23:59:59Z`);return t>=n&&t<=s})}static trackedInOrbitAt(e){const t=e.getUTCFullYear()*12+e.getUTCMonth()-$6;if(!(t<0))return zb[Math.min(t,zb.length-1)]}static visibilityAt(e,t){const i=Ki("Sun",e,t).altitudeDeg;return{sunAltitudeDeg:i,shadowHeightKm:Os.shadowHeightKm(i),lowOrbitLit:Os.isLitOverhead(Os.LOW_ORBIT_KM,i),classes:Os.classesAt(e),trackedObjects:Os.trackedInOrbitAt(e),anythingInOrbit:e.getTime()>=Date.parse(`${Os.FIRST_ORBIT}T00:00:00Z`)}}}const Hb="https://ufoathome.org/reentries/index.json";class Kn{static MINUTE_SLACK_MS=60*6e4;static WINDOW_SLACK_MS=60*6e4;static VISIBLE_KM=1500;static VISIBLE_DEG=Kn.VISIBLE_KM/111.2;static EARTH_RADIUS_KM=6371;fetchImpl;indexUrls;index;years=new Map;constructor(e={}){this.fetchImpl=e.fetchImpl??fetch.bind(globalThis),this.indexUrls=e.indexUrls??Kn.defaultIndexUrls()}static defaultIndexUrls(){const e=[];return typeof location<"u"&&/^https?:$/.test(location.protocol)&&e.push(new URL("/reentries/index.json",location.href).href),e.includes(Hb)||e.push(Hb),e}async credit(){return(await this.loadIndex())?.index.credit}async candidates(e,t,i){const n=await this.loadIndex();if(!n)return;const s=new Set;for(const a of[e-Kn.DAY_MS,t+Kn.DAY_MS])s.add(String(new Date(a).getUTCFullYear()));const r=(await Promise.all([...s].filter(a=>n.index.years.includes(a)).map(a=>this.yearOf(a,n.base)))).flat();return Kn.match(r,e,t,i)}static DAY_MS=864e5;static match(e,t,i,n){const s=[];for(const a of e){if(a.inclinationDeg!==void 0&&Math.abs(n.lat)>a.inclinationDeg+Kn.VISIBLE_DEG)continue;const l=Date.parse(a.precision==="day"?`${a.time}T00:00Z`:a.time);if(Number.isFinite(l))if(a.precision==="minute"){const c=l<t?t-l:l>i?l-i:0;if(c>Kn.MINUTE_SLACK_MS)continue;let h;if(a.seenLat!==void 0&&a.seenLng!==void 0&&(h=Kn.distanceKm(n.lat,n.lng,a.seenLat,a.seenLng),h>Kn.VISIBLE_KM))continue;s.push({record:a,timeMs:l,offsetMinutes:Math.round(c/6e4),seenKm:h})}else{const c=a.precision==="day"?Kn.DAY_MS/2:(a.uncertaintyHours??0)*36e5,h=a.precision==="day"?l+c:l,d=Kn.WINDOW_SLACK_MS;if(h+c+d<t||h-c-d>i)continue;s.push({record:a,timeMs:h})}}const r={minute:0,hours:1,day:2};return s.sort((a,l)=>r[a.record.precision]-r[l.record.precision]||(a.record.uncertaintyHours??0)-(l.record.uncertaintyHours??0)||a.timeMs-l.timeMs)}static distanceKm(e,t,i,n){const s=Math.PI/180,r=Math.sin(e*s)*Math.sin(i*s)+Math.cos(e*s)*Math.cos(i*s)*Math.cos((n-t)*s);return Kn.EARTH_RADIUS_KM*Math.acos(Math.max(-1,Math.min(1,r)))}loadIndex(){return this.index??=(async()=>{for(const e of this.indexUrls)try{const t=await this.fetchImpl(e);if(t.ok)return{index:await t.json(),base:e}}catch{}})(),this.index}yearOf(e,t){let i=this.years.get(e);return i||(i=this.fetchImpl(new URL(`${e}.json`,t).href).then(n=>n.ok?n.json():[]).catch(()=>[]),this.years.set(e,i)),i}}const Y6="https://ufoathome.org/light-pollution/index.json";class no{year=2015;citation="World Atlas of the artificial night sky brightness (Falchi et al. 2016, doi:10.1126/sciadv.1600377; data doi:10.5880/GFZ.1.4.2016.001, CC BY-NC 4.0)";static NATURAL_MCD=.171168;fetchImpl;indexUrls;index;tiles=new Map;constructor(e={}){this.fetchImpl=e.fetchImpl??fetch.bind(globalThis),this.indexUrls=e.indexUrls??no.defaultIndexUrls()}static defaultIndexUrls(){const e=typeof location>"u"?void 0:new URL("/light-pollution/index.json",location.href).href;return[...new Set([e,Y6].filter(t=>t!==void 0))]}static magPerArcsec2Of(e){return-2.5*Math.log10((e+no.NATURAL_MCD)/108e6)}static mcdOf(e,t){return e===0?0:t.floorMcd*10**((e-1)/t.subdivisions)}async lookUp(e,t){const i=await this.loadIndex();if(!i)return{status:"failed"};const{index:n,base:s,present:r}=i;if(!(e<n.north&&e>=n.south))return{status:"outside"};const a=((t+180)%360+360)%360-180,l=Math.floor((n.north-e)/n.tileDeg),c=Math.floor((a+180)/n.tileDeg),h=l*(360/n.tileDeg)+c;if(!(r[h>>3]&1<<(h&7)))return{status:"natural"};const d=n.north-l*n.tileDeg,u=-180+c*n.tileDeg,f=no.nameOf(d-n.tileDeg,u),p=await this.tile(`${s}${f}.bin`);if(!p)return{status:"failed"};const g=n.tileDeg/n.cells,m=Math.min(n.cells-1,Math.floor((d-e)/g)),v=Math.min(n.cells-1,Math.floor((a-u)/g)),b=no.mcdOf(p[m*n.cells+v],n);return b===0?{status:"natural"}:{status:"found",lightPollution:Math.round(no.magPerArcsec2Of(b)*100)/100,artificialMcdPerM2:b,lat:d-(m+.5)*g,lng:u+(v+.5)*g}}static nameOf(e,t){const i=`${e<0?"S":"N"}${String(Math.abs(e)).padStart(2,"0")}`,n=`${t<0?"W":"E"}${String(Math.abs(t)).padStart(3,"0")}`;return i+n}loadIndex(){return this.index??=(async()=>{for(const e of this.indexUrls)try{const t=await this.fetchImpl(e);if(!t.ok)continue;const i=await t.json(),n=Uint8Array.from(atob(i.present),s=>s.charCodeAt(0));return{index:i,base:new URL(".",e).href,present:n}}catch{}})(),this.index.then(e=>{e||(this.index=void 0)}),this.index}tile(e){let t=this.tiles.get(e);return t||(t=(async()=>{try{const i=await this.fetchImpl(e);if(!i.ok||!i.body)return;const n=i.body.pipeThrough(new DecompressionStream("deflate-raw"));return new Uint8Array(await new Response(n).arrayBuffer())}catch{return}})(),this.tiles.set(e,t),t.then(i=>{i||this.tiles.delete(e)})),t}}const Gb=[{id:"falchi-2015",name:"World Atlas 2015",credit:"Falchi et al. 2016, CC BY-NC 4.0",creditUrl:"https://doi.org/10.5880/GFZ.1.4.2016.001",create:()=>new no}];class Ct{static COARSE_STEP_DEG=10;static FINE_STEP_DEG=2;static FINE_SPAN_DEG=10;static LOWEST_DEG=5;static THRESHOLD_CONTRAST=.5;static CONE_SEPARATION_DEG=60;galaxy=new Mt;dust=new gi;assess(e,t,i){const n=Ki("Sun",e,t),s=Ki("Moon",e,t),r={altitudeDeg:s.altitudeDeg,phaseAngleDeg:ce.phaseAngleOf(io(e).illuminatedFraction)},a=as.galactic(e,t),l=Ct.unit(a.centre),c=Ct.unit(a.rotation),h=Ct.unit(a.pole),d=Ct.unit(as.eclipticPole(e,t)),u=Ct.unit(n),f=Ct.unit(s),p=Ct.normalize(Ct.reject(u,d));let g,m,v=0;const b=(x,y)=>{const w=Ct.unit({altitudeDeg:x,azimuthDeg:y}),S=Ct.between(w,u),A=ce.magPerArcsec2({altitudeDeg:n.altitudeDeg,separationDeg:S},{...r,separationDeg:Ct.between(w,f)},x,i);A>v&&(v=A);const M=Yr.fromMagPerArcsec2(A),_=10**(-.4*ce.EXTINCTION_PER_AIR_MASS*(ce.airMass(x)-1)),I=this.galaxy.surfaceBrightnessS10(Math.atan2(Ct.dot(w,c),Ct.dot(w,l))*180/Math.PI,Math.asin(Math.max(-1,Math.min(1,Ct.dot(w,h))))*180/Math.PI)*_;g=Ct.better(g,I,M,A,x,y,S);const R=Math.max(-1,Math.min(1,Ct.dot(w,d))),L=Ct.normalize(Ct.reject(w,d)),P=this.dust.surfaceBrightnessS10(Ct.between(L,p),Math.asin(R)*180/Math.PI)*_;m=Ct.better(m,P,M,A,x,y,S)};for(let x=Ct.LOWEST_DEG;x<=90;x+=Ct.COARSE_STEP_DEG)for(let y=0;y<360;y+=Ct.COARSE_STEP_DEG)b(x,y);for(const x of[g,m]){if(!x)continue;const y=Ct.FINE_SPAN_DEG,w=Ct.FINE_STEP_DEG;for(let S=x.altitudeDeg-y;S<=x.altitudeDeg+y;S+=w)if(!(S<Ct.LOWEST_DEG||S>90))for(let A=x.azimuthDeg-y;A<=x.azimuthDeg+y;A+=w)b(S,(A+360)%360)}return{milkyWay:g&&g.contrast>=Ct.THRESHOLD_CONTRAST?g:void 0,zodiacal:m&&m.contrast>=Ct.THRESHOLD_CONTRAST?m:void 0,darkestSkyMagPerArcsec2:v}}static better(e,t,i,n,s,r,a){const l=t/i;return e&&e.contrast>=l?e:{contrast:l,altitudeDeg:s,azimuthDeg:r,magPerArcsec2:Yr.toMagPerArcsec2(t),skyMagPerArcsec2:n,sunSeparationDeg:a}}static unit(e){const t=e.altitudeDeg*Math.PI/180,i=e.azimuthDeg*Math.PI/180,n=Math.cos(t);return[n*Math.sin(i),Math.sin(t),-n*Math.cos(i)]}static dot(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}static between(e,t){return Math.acos(Math.max(-1,Math.min(1,Ct.dot(e,t))))*180/Math.PI}static reject(e,t){const i=Ct.dot(e,t);return[e[0]-i*t[0],e[1]-i*t[1],e[2]-i*t[2]]}static normalize(e){const t=Math.hypot(...e)||1;return[e[0]/t,e[1]/t,e[2]/t]}}const q6=.5,Vd=40,K6=4e5,$a=Math.PI/180,yl=180/Math.PI;class Xn{static localDirection(e,t,i,n=new D){const s=Math.tan(t/2*$a);return n.set((e.u*2-1)*s*i,(1-e.v*2)*s,-1).normalize()}static picturePoint(e,t,i){if(e.z>=0)return;const n=Math.tan(t/2*$a),s=e.x/-e.z/(n*i),r=e.y/-e.z/n;return{u:(s+1)/2,v:(1-r)/2}}static worldDirection(e,t=new D){const i=e.azimuthDeg*$a,n=e.altitudeDeg*$a;return t.set(Math.sin(i)*Math.cos(n),Math.sin(n),-Math.cos(i)*Math.cos(n))}static aimOf(e){const t=Math.hypot(e.x,e.z);return{azimuthDeg:(Math.atan2(e.x,-e.z)*yl+360)%360,altitudeDeg:Math.atan2(e.y,t)*yl}}static rotationOf(e){const t=new hi;return t.rotation.set(e.pitchDeg*$a,-e.headingDeg*$a,-(e.rollDeg??0)*$a,"YXZ"),t.quaternion.clone()}static anglesOf(e){const t=new wr().setFromQuaternion(e,"YXZ"),i=(-t.y*yl%360+360)%360,n=-t.z*yl;return{headingDeg:i,pitchDeg:t.x*yl,rollDeg:Math.abs(n)<1e-9?0:n}}static worldDirectionOf(e,t,i,n=new D){return this.localDirection(e,t.fovDeg,i,n).applyQuaternion(this.rotationOf(t))}static picturePointOf(e,t,i){const n=e.clone().applyQuaternion(this.rotationOf(t).invert()),s=this.picturePoint(n,t.fovDeg,i);if(!(!s||s.u<0||s.u>1||s.v<0||s.v>1))return s}static solve(e,t,i,n=e.length>=3){if(e.length<2)return;if(!n)return this.solveAtField(e,t,i);let s=1,r=179;const a=(Math.sqrt(5)-1)/2;let l=r-a*(r-s),c=s+a*(r-s),h=this.solveAtField(e,t,l),d=this.solveAtField(e,t,c);for(let f=0;f<60&&r-s>1e-4;f++){if(!h||!d)return;h.residualDeg<d.residualDeg?(r=c,c=l,d=h,l=r-a*(r-s),h=this.solveAtField(e,t,l)):(s=l,l=c,h=d,c=s+a*(r-s),d=this.solveAtField(e,t,c))}return h&&d?h.residualDeg<d.residualDeg?h:d:h??d}static solveAtField(e,t,i){const n=e.map(c=>this.localDirection(c.picture,i,t)),s=e.map(c=>this.worldDirection(c.scene)),r=this.triad(n,s);if(!r)return;const a=this.refine(r,n,s);return{registration:{...this.anglesOf(a),fovDeg:i},residualDeg:this.residualDeg(a,n,s)}}static triad(e,t){let i=0,n=1,s=-1;for(let h=0;h<e.length;h++)for(let d=h+1;d<e.length;d++){const u=e[h].clone().cross(e[d]).lengthSq();u>s&&(s=u,i=h,n=d)}if(s<1e-12)return;const r=(h,d)=>{const u=h.clone().normalize(),f=h.clone().cross(d).normalize(),p=f.clone().cross(u);return new Je().set(u.x,p.x,f.x,u.y,p.y,f.y,u.z,p.z,f.z)},a=r(e[i],e[n]),c=r(t[i],t[n]).multiply(a.transpose());return new An().setFromRotationMatrix(new lt().setFromMatrix3(c))}static refine(e,t,i){const n=e.clone(),s=new D;for(let r=0;r<20;r++){const a=new Je().set(0,0,0,0,0,0,0,0,0),l=a.elements,c=new D;for(let f=0;f<t.length;f++){s.copy(t[f]).applyQuaternion(n);const p=s,g=[[0,p.z,-p.y],[-p.z,0,p.x],[p.y,-p.x,0]],m=[i[f].x-p.x,i[f].y-p.y,i[f].z-p.z];for(let v=0;v<3;v++){for(let b=0;b<3;b++)for(let x=0;x<3;x++)l[b*3+v]+=g[x][v]*g[x][b];c.setComponent(v,c.getComponent(v)+g[0][v]*m[0]+g[1][v]*m[1]+g[2][v]*m[2])}}for(let f=0;f<3;f++)l[f*3+f]+=1e-9;const h=c.applyMatrix3(a.invert()),d=h.length();if(d<1e-12)break;const u=new An().setFromAxisAngle(h.normalize(),d);if(n.premultiply(u).normalize(),d<1e-10)break}return n}static residualDeg(e,t,i){let n=0;const s=new D;for(let r=0;r<t.length;r++){s.copy(t[r]).applyQuaternion(e);const a=s.angleTo(i[r])*yl;n+=a*a}return Math.sqrt(n/t.length)}}const Vb=6371e3,Hc=Math.PI/180;class Ll{constructor(e=t=>fetch(t).then(i=>{if(!i.ok)throw new Error(`${t}: HTTP ${i.status}`);return i.json()})){this.fetchJson=e}static API="https://api.panoramax.xyz/api";static CREDIT="Panoramax";static CREDIT_URL="https://panoramax.fr/";async nearby(e,t,i=300,n=50){const s=i/111320,r=i/(111320*Math.cos(e*Hc)),a=[t-r,e-s,t+r,e+s].map(h=>h.toFixed(6)).join(",");return((await this.fetchJson(`${Ll.API}/search?bbox=${a}&limit=${n}`)).features??[]).map(h=>this.picture(h,e,t)).filter(h=>h!==void 0&&h.distanceM<=i).sort((h,d)=>h.distanceM-d.distanceM)}picture(e,t,i){const[n,s]=e.geometry.coordinates,r=e.assets.sd?.href??e.assets.hd?.href;if(!r)return;const{distanceM:a,bearingDeg:l}=Ll.offset(t,i,s,n),c=e.properties,h=c["pers:interior_orientation"]?.field_of_view,d=(c.providers??[]).map(f=>f.name).filter(f=>!!f),u=c.license??"CC-BY-SA-4.0";return{id:e.id,lat:s,lng:n,distanceM:a,bearingDeg:l,azimuthDeg:c["view:azimuth"],panorama:h!==void 0&&h>=360,takenAt:c.datetime??"",src:r,srcFull:e.assets.hd?.href,credit:`${Ll.CREDIT}${d.length?` — ${d.join(", ")}`:""} (${u})`,creditUrl:`${Ll.API.replace(/\/api$/,"")}/#focus=pic&pic=${e.id}`}}static offset(e,t,i,n){const s=(i-e)*Hc*Vb,r=(n-t)*Hc*Vb*Math.cos((e+i)/2*Hc);return{distanceM:Math.hypot(r,s),bearingDeg:(Math.atan2(r,s)/Hc+360)%360}}}const Wd=36e5,Wb=25;class o0{constructor(e){this.provider=e}async infer(e){const t=this.questionOf(e);if(!t)return{status:"incomplete"};const{origin:i,start:n}=t,s=ec(e.event)??0,r=this.sampleTimings(e,n,s);let a;try{a=await this.provider.getWeather({points:r.map(l=>this.pointAt(e,l,i))})}catch{return{status:"failed",at:n}}return a?{status:"inferred",at:n,source:a.source,keyframes:a.samples.map((l,c)=>({t:r[c].t,weather:l.weather}))}:{status:"unavailable",at:n}}applyTo(e,t){if(!(t.status!=="inferred"||!t.keyframes||!t.source)){e.weatherTrack.clear();for(const i of t.keyframes)e.weatherTrack.addKeyframe(i.t,i.weather);e.weatherSource=t.source}}sampleTimes(e,t){const i=[e],n=e.getTime()+t;let s=Math.floor(e.getTime()/Wd)*Wd+Wd;for(;s<=n&&i.length<Wb;)i.push(new Date(s)),s+=Wd;return t>0&&i[i.length-1].getTime()!==n&&i.length<Wb&&i.push(new Date(n)),i}sampleTimings(e,t,i){const n=e.timeline.duration>0?e.timeline.duration:i;return i<=0||n<=0?[{time:t,t:0}]:this.sampleTimes(t,i).map(s=>{const r=(s.getTime()-t.getTime())/i;return{time:s,t:Math.round(n*Math.max(0,Math.min(1,r)))}})}canInfer(e){return this.questionOf(e)!==void 0}missingOf(e){const t=e.event.time;return{date:t?.year===void 0||t.month===void 0||t.day===void 0,place:this.originOf(e)===void 0}}questionOf(e){const t=this.originOf(e);if(!t)return;const i=e.event.time;if(i?.year===void 0||i.month===void 0||i.day===void 0)return;const n=ds(i,t.lng,e.event.utcOffsetHours);return n?{origin:t,start:n}:void 0}originOf(e){const t=at(e,0),i=e.event.place?.[0],n=t?.lat??i?.lat,s=t?.lng??i?.lng;return n===void 0||s===void 0?void 0:{lat:n,lng:s}}pointAt(e,t,i){const n=at(e,t.t);return{lat:n?.lat??i.lat,lng:n?.lng??i.lng,time:t.time}}}const Z6=Date.UTC(1940,0,1),Xb=36e5,$b=.25,j6=.7,J6=.45,Q6=.1,ek=2,tk=.3,ik=.2,nk=8,l0=.125,sk=.05,Yb=125,qb=100,Kb=2500,c0=3500,h0=8e3,rk=95,ak=99,ok=[96,99],lk=["cloud_cover","cloud_cover_low","cloud_cover_mid","cloud_cover_high","precipitation","snowfall","weather_code","wind_speed_10m","wind_direction_10m","temperature_2m","dew_point_2m"],ck=5;class E2{fetchImpl;baseUrl;forecastUrl;now;cache=new Map;constructor(e={}){this.fetchImpl=e.fetchImpl??fetch.bind(globalThis),this.baseUrl=e.baseUrl??"https://archive-api.open-meteo.com/v1/archive",this.forecastUrl=e.forecastUrl??"https://api.open-meteo.com/v1/forecast",this.now=e.now??(()=>new Date)}async getWeather(e){if(e.points.length===0)return;const t=e.points.map(h=>h.time.getTime()),i=Math.min(...t);if(i<Z6)return;const n=new Map;for(const h of e.points){const d=this.cellKey(h);n.has(d)||n.set(d,{lat:h.lat,lng:h.lng,index:n.size})}const s=i>=this.now().getTime()-ck*864e5,r=this.requestUrl([...n.values()],new Date(i),new Date(Math.max(...t)),s);let a=this.cache.get(r);if(!a){const h=await this.fetchImpl(r);if(!h.ok)throw new Error(`Open-Meteo HTTP ${h.status}`);const d=await h.json();if(a=Array.isArray(d)?d:[d],a.length<n.size||a.some(u=>u.error||!u.hourly))return;this.cache.set(r,a)}const l=s?{id:"open-meteo-forecast",name:"Open-Meteo (forecast model)",url:r}:{id:"era5",name:"ERA5 (Open-Meteo)",url:r},c=e.points.map(h=>this.sampleAt(a[n.get(this.cellKey(h)).index].hourly,h.time));if(!c.some(h=>h===void 0))return{samples:c,source:l}}cellKey(e){return`${Math.round(e.lat/$b)},${Math.round(e.lng/$b)}`}requestUrl(e,t,i,n){const s=new URLSearchParams({latitude:e.map(r=>r.lat).join(","),longitude:e.map(r=>r.lng).join(","),start_date:this.isoDate(t),end_date:this.isoDate(i),hourly:lk.join(","),wind_speed_unit:"ms",timezone:"UTC"});return`${n?this.forecastUrl:this.baseUrl}?${s}`}isoDate(e){return e.toISOString().slice(0,10)}sampleAt(e,t){const i=this.recordAt(e,t);return i&&{time:t,weather:this.toWeather(i)}}recordAt(e,t){const i=e.time.map(a=>Date.parse(`${a}Z`)),n=t.getTime();if(i.length===0||n<i[0]-Xb||n>i[i.length-1]+Xb)return;if(n<=i[0])return this.recordFrom(e,0);if(n>=i[i.length-1])return this.recordFrom(e,i.length-1);let s=0;for(;s+1<i.length&&i[s+1]<=n;)s++;const r=i[s+1]-i[s];return this.blendRecords(this.recordFrom(e,s),this.recordFrom(e,s+1),r>0?(n-i[s])/r:0)}recordFrom(e,t){const i={cloudCover:e.cloud_cover[t]/100,cloudCoverLow:e.cloud_cover_low[t]/100,cloudCoverMid:e.cloud_cover_mid[t]/100,cloudCoverHigh:e.cloud_cover_high[t]/100,precipitationMm:e.precipitation[t],snowfallCm:e.snowfall[t],weatherCode:e.weather_code[t],windSpeedMs:e.wind_speed_10m[t],windFromDeg:e.wind_direction_10m[t],temperatureC:e.temperature_2m[t],dewPointC:e.dew_point_2m[t]};return Object.values(i).some(n=>n===void 0||Number.isNaN(n))?void 0:i}blendRecords(e,t,i){if(!e||!t)return e??t;const n=(r,a)=>r+(a-r)*i,s=((t.windFromDeg-e.windFromDeg)%360+540)%360-180;return{cloudCover:n(e.cloudCover,t.cloudCover),cloudCoverLow:n(e.cloudCoverLow,t.cloudCoverLow),cloudCoverMid:n(e.cloudCoverMid,t.cloudCoverMid),cloudCoverHigh:n(e.cloudCoverHigh,t.cloudCoverHigh),precipitationMm:n(e.precipitationMm,t.precipitationMm),snowfallCm:n(e.snowfallCm,t.snowfallCm),weatherCode:i<.5?e.weatherCode:t.weatherCode,windSpeedMs:n(e.windSpeedMs,t.windSpeedMs),windFromDeg:((e.windFromDeg+s*i)%360+360)%360,temperatureC:n(e.temperatureC,t.temperatureC),dewPointC:n(e.dewPointC,t.dewPointC)}}cloudLayersFrom(e){return[{id:"record-low",type:"unknown",baseM:Math.round(this.clamp(Yb*(e.temperatureC-e.dewPointC),qb,Kb)),thicknessM:650,coverage:this.clamp(e.cloudCoverLow,0,1),sizeM:1400,density:1},{id:"record-mid",type:"unknown",baseM:c0,thicknessM:800,coverage:this.clamp(e.cloudCoverMid,0,1),sizeM:2500,density:1},{id:"record-high",type:"cirrus",baseM:h0,thicknessM:400,coverage:this.clamp(e.cloudCoverHigh,0,1),sizeM:2200,density:.35}]}toWeather(e){const t=e.weatherCode>=rk&&e.weatherCode<=ak,i=this.precipitationTypeFrom(e);return{cloudLayers:this.cloudLayersFrom(e),cloudCover:this.clamp(e.cloudCover,0,1),cloudDarkness:this.cloudDarknessFrom(e,t),cloudBaseM:this.cloudBaseFrom(e),highCloudCover:e.cloudCoverHigh,lowerCloudCover:Math.max(e.cloudCoverLow,e.cloudCoverMid),relativeHumidity:Math.round(Hr.relativeHumidity(e.temperatureC,e.dewPointC)*100)/100,precipitationType:i,precipitationIntensity:i==="none"?0:this.clamp(Math.sqrt(e.precipitationMm/nk),0,1),windDirectionDeg:(e.windFromDeg+180)%360,windSpeed:e.windSpeedMs,storm:t}}precipitationTypeFrom(e){return e.snowfallCm>0?"snow":ok.includes(e.weatherCode)?"hail":e.precipitationMm>0?"rain":"none"}cloudDarknessFrom(e,t){const i=e.cloudCoverLow+e.cloudCoverMid+e.cloudCoverHigh;if(i<=0)return 0;const n=(j6*e.cloudCoverLow+J6*e.cloudCoverMid+Q6*e.cloudCoverHigh)/i,s=Math.min(1,e.precipitationMm/ek);return this.clamp(n+tk*s+(t?ik:0),0,1)}cloudBaseFrom(e){if(e.cloudCover<sk)return;const t=this.clamp(Yb*(e.temperatureC-e.dewPointC),qb,Kb);if(e.cloudCoverLow>=l0)return Math.round(t);if(e.cloudCoverMid>=l0)return c0;if(e.cloudCoverHigh>=l0)return h0;const i=Math.max(e.cloudCoverLow,e.cloudCoverMid,e.cloudCoverHigh);if(!(i<=0))return i===e.cloudCoverLow?Math.round(t):i===e.cloudCoverMid?c0:h0}clamp(e,t,i){return Math.max(t,Math.min(i,e))}}function hk(){return new E2}const dk=5;class A2{attribution={text:"© OpenStreetMap",url:"https://osm.org/copyright"};fetchImpl;baseUrl;reverseUrl;cache=new Map;constructor(e={}){this.fetchImpl=e.fetchImpl??fetch.bind(globalThis),this.baseUrl=e.baseUrl??"https://nominatim.openstreetmap.org/search",this.reverseUrl=e.reverseUrl??"https://nominatim.openstreetmap.org/reverse"}async reverse(e,t,i={}){const n=new URLSearchParams({lat:String(e),lon:String(t),format:"jsonv2"});i.language&&n.set("accept-language",i.language);const s=`${this.reverseUrl}?${n}`,r=this.cache.get(s);if(r)return r[0];const a=await this.fetchImpl(s,{signal:i.signal});if(!a.ok)throw new Error(`Nominatim HTTP ${a.status}`);const l=await a.json(),c=l.error?void 0:this.toMatch(l);return this.cache.set(s,c?[c]:[]),c}async search(e,t={}){const i=e.trim();if(i==="")return[];const n=this.requestUrl(i,t),s=this.cache.get(n);if(s)return s;const r=await this.fetchImpl(n,{signal:t.signal});if(!r.ok)throw new Error(`Nominatim HTTP ${r.status}`);const a=await r.json(),l=(Array.isArray(a)?a:[]).map(c=>this.toMatch(c)).filter(c=>c!==void 0);return this.cache.set(n,l),l}requestUrl(e,t){const i=new URLSearchParams({q:e,format:"jsonv2",limit:String(t.limit??dk)});return t.language&&i.set("accept-language",t.language),`${this.baseUrl}?${i}`}toMatch(e){const t=e.display_name??e.name,i=this.coordinate(e.lat),n=this.coordinate(e.lon);return t&&i!==void 0&&n!==void 0?{name:t,lat:i,lng:n}:void 0}coordinate(e){if(e===void 0||e.trim()==="")return;const t=Number(e);return Number.isFinite(t)?t:void 0}}function uk(){return new A2}const fk=[{id:"nominatim",name:"Nominatim",credit:"© OpenStreetMap",creditUrl:"https://osm.org/copyright",create:()=>new A2}],qm=[{id:"era5",name:"Open-Meteo",credit:"© Copernicus/ECMWF",creditUrl:"https://open-meteo.com/en/docs/historical-weather-api",create:()=>new E2}],d0=o=>o.id==="open-meteo-forecast"||qm.some(e=>e.id===o.id);class pk{attribution;fetchImpl;tileUrlTemplate;constructor(e={}){this.fetchImpl=e.fetchImpl??fetch.bind(globalThis);const t=e.year??2024;this.tileUrlTemplate=`https://tiles.maps.eox.at/wmts/1.0.0/s2cloudless-${t}_3857/default/g/{z}/{y}/{x}.jpg`,this.attribution=`EOxCloudless https://cloudless.eox.at by EOX IT Services GmbH (Contains modified Copernicus Sentinel data ${t})`}async getImageryTexture(e,t){return HM(e,t,i=>this.tileUrlTemplate.replace("{z}",String(i.z)).replace("{y}",String(i.y)).replace("{x}",String(i.x)),this.fetchImpl)}}const u0=[{id:"ign-mnt",name:"IGN LiDAR HD / RGE ALTI",credit:"Relief © IGN, LiDAR HD and RGE ALTI (Licence Ouverte 2.0) in France; © AWS Open Data (SRTM, ETOPO1) elsewhere",creditUrl:"https://geoservices.ign.fr/lidarhd",create:()=>VM()},{id:"aws-terrarium",name:"AWS Terrain Tiles",credit:"© AWS Open Data (SRTM, ETOPO1)",creditUrl:"https://registry.opendata.aws/terrain-tiles/",create:()=>new zM}],Zb=[{id:"esri-world",name:"Esri World Imagery",credit:"Imagery © Esri, Maxar, Earthstar Geographics, and the GIS User Community",creditUrl:"https://www.arcgis.com/home/item.html?id=10df2279f9684e4a9f6a7f08febac2a9",create:()=>new GM},{id:"eox-s2cloudless",name:"EOX Sentinel-2 cloudless",credit:"EOxCloudless by EOX IT Services GmbH (contains modified Copernicus Sentinel data)",creditUrl:"https://cloudless.eox.at",create:()=>new pk}];class oh{constructor(e,t){this.root=e,this.messages=t}static STYLE=`
9805
9805
  .model-picker-button { display: inline-flex; align-items: center; gap: .5em; cursor: pointer; max-width: 100%; }
9806
9806
  .model-picker-button img { width: 2em; height: 1.5em; object-fit: contain; }
9807
9807
  .model-picker-button span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }