@rr0/ufoathome 0.97.0 → 0.98.0

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.
Files changed (32) hide show
  1. package/dist-embed-scene/UfoMessages_es-LFW_B5H2.js +1 -0
  2. package/dist-embed-scene/UfoMessages_fr-bJNAf-AU.js +1 -0
  3. package/dist-embed-scene/UfoMessages_it-B-jnc4M-.js +1 -0
  4. package/dist-embed-scene/rr0-scene.mjs +36 -36
  5. package/dist-embed-scene/sightingSchema-DbxLUhd5.js +1 -0
  6. package/dist-embed-sighting/UfoMessages_es-LFW_B5H2.js +1 -0
  7. package/dist-embed-sighting/UfoMessages_fr-bJNAf-AU.js +1 -0
  8. package/dist-embed-sighting/UfoMessages_it-B-jnc4M-.js +1 -0
  9. package/dist-embed-sighting/rr0-sighting.mjs +311 -311
  10. package/dist-embed-sighting/sightingSchema-DbxLUhd5.js +1 -0
  11. package/dist-embed-sighting-editor/{SightingEditorMessages_es-ufGhorJf.js → SightingEditorMessages_es-fDj-ntgt.js} +4 -2
  12. package/dist-embed-sighting-editor/{SightingEditorMessages_fr-CgMZWb_F.js → SightingEditorMessages_fr-B289heb4.js} +4 -2
  13. package/dist-embed-sighting-editor/{SightingEditorMessages_it-DpT8Sntn.js → SightingEditorMessages_it-Dfvk8h0m.js} +4 -2
  14. package/dist-embed-sighting-editor/{SightingFileEditor-Cb0SzzMF.js → SightingFileEditor-D8gJRMr-.js} +1 -1
  15. package/dist-embed-sighting-editor/UfoMessages_es-LFW_B5H2.js +1 -0
  16. package/dist-embed-sighting-editor/UfoMessages_fr-bJNAf-AU.js +1 -0
  17. package/dist-embed-sighting-editor/UfoMessages_it-B-jnc4M-.js +1 -0
  18. package/dist-embed-sighting-editor/rr0-sighting-editor.mjs +338 -326
  19. package/dist-embed-sighting-editor/sightingSchema-DbxLUhd5.js +1 -0
  20. package/package.json +3 -3
  21. package/dist-embed-scene/UfoMessages_es-CD_68_jy.js +0 -1
  22. package/dist-embed-scene/UfoMessages_fr-6WbKsRDZ.js +0 -1
  23. package/dist-embed-scene/UfoMessages_it-CHAJPqfh.js +0 -1
  24. package/dist-embed-scene/sightingSchema-07Ux2CE8.js +0 -1
  25. package/dist-embed-sighting/UfoMessages_es-CD_68_jy.js +0 -1
  26. package/dist-embed-sighting/UfoMessages_fr-6WbKsRDZ.js +0 -1
  27. package/dist-embed-sighting/UfoMessages_it-CHAJPqfh.js +0 -1
  28. package/dist-embed-sighting/sightingSchema-07Ux2CE8.js +0 -1
  29. package/dist-embed-sighting-editor/UfoMessages_es-CD_68_jy.js +0 -1
  30. package/dist-embed-sighting-editor/UfoMessages_fr-6WbKsRDZ.js +0 -1
  31. package/dist-embed-sighting-editor/UfoMessages_it-CHAJPqfh.js +0 -1
  32. package/dist-embed-sighting-editor/sightingSchema-07Ux2CE8.js +0 -1
@@ -1406,18 +1406,18 @@ canvas[data-cursor="rotate"] {
1406
1406
  pointer-events: none;
1407
1407
  white-space: nowrap;
1408
1408
  }
1409
- `,xc=[{id:"eye",name:"Naked eye",flare:0,projection:"equidistant",stabilization:.97},{id:"rectilinear-lens",name:"Camera, unknown device",projection:"rectilinear",fNumber:8,fNumberRange:{min:2,max:22},exposureSeconds:1/250,exposureRangeSeconds:{min:1/1e3,max:8},apertureBlades:6},{id:"roamer-1-120",name:"Roamer 1, 120 film",projection:"rectilinear",frame:{widthMm:74,heightMm:60,focalLengthMm:100},fNumber:11,exposureSeconds:1/50,years:{from:1930,to:1965},detailUm:40,medium:{kind:"negative",iso:125}},{id:"instamatic-126",name:"Instamatic, 126 film",projection:"rectilinear",frame:{widthMm:28,heightMm:28,focalLengthMm:43},fNumber:11,exposureSeconds:1/90,years:{from:1963,to:1988},apertureBlades:5,detailUm:20,medium:{kind:"negative",iso:64}},{id:"slr-35mm-50",name:"35 mm SLR, 50 mm lens",projection:"rectilinear",frame:{widthMm:36,heightMm:24,focalLengthMm:50},fNumber:8,fNumberRange:{min:2,max:16},exposureSeconds:1/250,exposureRangeSeconds:{min:1/1e3,max:3600},years:{from:1959},apertureBlades:6,detailUm:20,medium:{kind:"negative",iso:100}},{id:"slr-35mm-zoom",name:"35 mm SLR, 70-210 mm zoom",projection:"rectilinear",frame:{widthMm:36,heightMm:24,focalLengthMm:135,focalRangeMm:{minMm:70,maxMm:210}},fNumber:8,fNumberRange:{min:4,max:22},exposureSeconds:1/250,exposureRangeSeconds:{min:1/1e3,max:3600},apertureBlades:8,years:{from:1975},detailUm:20,medium:{kind:"negative",iso:100}},{id:"phone-landscape",name:"Phone, held sideways",projection:"rectilinear",frame:{widthMm:7.6,heightMm:5.7,focalLengthMm:5.7},fNumber:1.8,exposureSeconds:1/120,exposureRangeSeconds:{min:1/8e3,max:10},years:{from:2007},apertureBlades:void 0,detailUm:1.4,medium:{kind:"sensor",iso:100,autoExposure:!0}},{id:"phone-portrait",name:"Phone, held upright",projection:"rectilinear",frame:{widthMm:5.7,heightMm:7.6,focalLengthMm:5.7},fNumber:1.8,exposureSeconds:1/120,exposureRangeSeconds:{min:1/8e3,max:10},years:{from:2007},apertureBlades:void 0,detailUm:1.4,medium:{kind:"sensor",iso:100,autoExposure:!0}}];class mi{static get default(){return xc[0]}static byId(t){return xc.find(e=>e.id===t)??this.default}static UNAIDED_FIELD_DEG=60;static UNAIDED_ASPECT=16/9;static fieldOfViewDeg(t){const e=t.frame;return e?2*Math.atan(e.heightMm/(2*e.focalLengthMm))*180/Math.PI:mi.UNAIDED_FIELD_DEG}static aspectOf(t){const e=t.frame;return e?e.widthMm/e.heightMm:mi.UNAIDED_ASPECT}static frameWidthPx(t,e){return Math.round(e*mi.aspectOf(t))}static availableAt(t){return t===void 0?xc:xc.filter(e=>!e.years||t>=e.years.from&&(e.years.to===void 0||t<=e.years.to))}static fieldOfViewDegAt(t,e){const i=t.frame;if(!(!i||e<=0))return 2*Math.atan(i.heightMm/(2*e))*180/Math.PI}static focalLengthMmFor(t,e){const i=t.frame;if(!(!i||e<=0||e>=180))return i.heightMm/(2*Math.tan(e*Math.PI/360))}static bladesShowing(t,e){const i=e??t.fNumber;if(i===void 0||t.apertureBlades===void 0)return 0;const n=t.fNumberRange;return!n||n.max<=n.min?1:Math.max(0,Math.min(1,(i-n.min)/(n.max-n.min)))}static LENS_FLARE_ARTIFACTS=1;static flareArtifactsOf(t){return t.flare??mi.LENS_FLARE_ARTIFACTS}static starPointsOf(t){const e=t.apertureBlades;return e===void 0||e<3?0:e%2===0?e:e*2}}class Fa{constructor(t){this.points=t}static STATIONARY_M=5;static of(t){const e=[];for(const i of t.observerTrack.allKeyframes){const{lat:n,lng:s,headingDeg:r}=i.pose;n===void 0||s===void 0||e.push({t:i.t,lat:n,lng:s,headingDeg:r})}if(e.length===0){const i=t.event.place?.[0];if(!i)return;e.push({t:0,lat:i.lat,lng:i.lng})}return new Fa(e)}static TRAVEL_M=50;get travels(){return this.spanM>Fa.TRAVEL_M}get moved(){return this.spanM>Fa.STATIONARY_M}get spanM(){const t=this.box,e=(t.south+t.north)/2,i=(t.west+t.east)/2;return Math.max(Math.abs(je(e,t.east,e,t.west).x),Math.abs(je(t.north,i,t.south,i).z))}get center(){const t=this.box;return{lat:(t.south+t.north)/2,lng:(t.west+t.east)/2}}boundsAround(t,e){const{lat:i,lng:n}=this.center,s=Math.max(this.spanM*(1+e),t)/2;return{north:Sn(0,-s,i,n).lat,south:Sn(0,s,i,n).lat,east:Sn(s,0,i,n).lng,west:Sn(-s,0,i,n).lng}}get box(){const t=this.points.map(i=>i.lat),e=this.points.map(i=>i.lng);return{south:Math.min(...t),north:Math.max(...t),west:Math.min(...e),east:Math.max(...e)}}}class An{constructor(t,e){this.rotationPassed=t,this.scale=e}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(t){const e=t.event.tags?.includes("paralysis")||(t.exposure??0)>An.HAND_HELD_S,i=t.sway??(e?0:1);if(i>0)return new An(Math.max(1-(t.instrument.stabilization??0),An.GAZE_DRIFT_SHARE),i)}offsetAt(t){const e=t/1e3,i=this.scale,n=(u,d)=>Math.sin(2*Math.PI*u*e+d),[s,r,o,c,l,h]=An.HZ;return{eastM:i*An.SWAY_M*(.7*n(s,.3)+.3*n(c,1.9)),northM:i*An.SWAY_M*(.6*n(o,2.2)+.4*n(l,.8)),upM:i*An.BREATH_M*n(r,0),yawDeg:i*this.rotationPassed*An.DRIFT_YAW_DEG*(.6*n(h,1.1)+.4*n(c,2.7)),pitchDeg:i*this.rotationPassed*An.DRIFT_PITCH_DEG*(.5*n(r,1.6)+.5*n(o,.4)),rollDeg:i*this.rotationPassed*An.DRIFT_ROLL_DEG*n(s,2.9)}}}class be{constructor(t,e){this.stretches=t,this.rotationPassed=e}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(t){const e=Fa.of(t);if(!e||e.points.length<2)return;const i=[];let n=0;for(let s=1;s<e.points.length;s++){const r=e.points[s-1],o=e.points[s],c=(o.t-r.t)/1e3;if(c<=0)continue;const l=je(o.lat,o.lng,r.lat,r.lng),h=l.x,u=-l.z,d=Math.hypot(h,u),f=d/c,p=be.stepHzFor(f);i.push({startMs:r.t,endMs:o.t,speedMPerS:f,eastUnit:d>0?h/d:0,northUnit:d>0?u/d:0,stepHz:p,stepsBefore:n,rampsIn:!0,rampsOut:!0}),n+=p*c}for(let s=0;s<i.length;s++){const r=i[s-1],o=i[s+1];i[s].rampsIn=r===void 0||r.stepHz===0,i[s].rampsOut=o===void 0||o.stepHz===0}if(i.some(s=>s.stepHz>0))return new be(i,1-(t.instrument.stabilization??0))}static bodyAt(t,e,i=!1){const n=be.of(t)?.offsetAt(e)??be.STILL;return i?n:be.add(n,An.of(t)?.offsetAt(e))}static stepHzFor(t){return t<be.SLOWEST_WALK_M_PER_S||t>be.FASTEST_WALK_M_PER_S?0:be.REFERENCE_STEP_HZ*Math.pow(t/be.REFERENCE_SPEED_M_PER_S,be.CADENCE_EXPONENT)}offsetAt(t){return be.add(this.cycleAt(t),this.joltAt(t))}joltAt(t){for(const e of this.stretches){if(e.stepHz===0)continue;const i=e.speedMPerS/be.REFERENCE_SPEED_M_PER_S,n=(o,c,l,h)=>{if(o<0||o>be.JOLT_LASTS_MS)return;const u=o/1e3,d=Math.exp(-u/be.JOLT_DECAY_S)*Math.sin(2*Math.PI*be.JOLT_HZ*u),f=h*c*i*d;return{eastM:f*e.eastUnit,northM:f*e.northUnit,upM:-Math.abs(f)*.3,rollDeg:0,pitchDeg:-h*l*i*d*this.rotationPassed,yawDeg:0}},s=e.rampsOut?n(t-e.endMs,be.STOP_LURCH_M,be.STOP_PITCH_DEG,1):void 0;if(s)return s;const r=e.rampsIn?n(t-e.startMs,be.START_LURCH_M,be.START_PITCH_DEG,-1):void 0;if(r)return r}}static add(t,e){return e?{eastM:t.eastM+e.eastM,northM:t.northM+e.northM,upM:t.upM+e.upM,rollDeg:t.rollDeg+e.rollDeg,pitchDeg:t.pitchDeg+e.pitchDeg,yawDeg:t.yawDeg+e.yawDeg}:t}cycleAt(t){const e=this.stretches.find(c=>t>=c.startMs&&t<=c.endMs);if(!e||e.stepHz===0)return be.STILL;const i=e.stepsBefore+e.stepHz*(t-e.startMs)/1e3,n=2*Math.PI*i,s=this.amplitudeAt(e,t),r=be.SWAY_M*s*Math.cos(n/2),o=s*this.rotationPassed*e.speedMPerS/be.REFERENCE_SPEED_M_PER_S;return{eastM:r*e.northUnit,northM:-r*e.eastUnit,upM:be.RISE_M_PER_M_PER_S*e.speedMPerS*s*Math.cos(n),rollDeg:be.HEAD_ROLL_DEG*o*Math.cos(n/2),pitchDeg:-1.25*o*Math.cos(n),yawDeg:be.HEAD_YAW_DEG*o*Math.cos(n/2)}}amplitudeAt(t,e){const i=1e3/t.stepHz,n=Math.min(i,(t.endMs-t.startMs)/2);if(n<=0)return 1;const s=e-t.startMs,r=t.endMs-e,o=Math.min(t.rampsIn?s/n:1,t.rampsOut?r/n:1,1);return(1-Math.cos(Math.PI*Math.max(o,0)))/2}}class zo{static ISO=/^P(?:(\d+(?:[.,]\d+)?)W)?(?:(\d+(?:[.,]\d+)?)D)?(?:T(?:(\d+(?:[.,]\d+)?)H)?(?:(\d+(?:[.,]\d+)?)M)?(?:(\d+(?:[.,]\d+)?)S)?)?$/;static seconds(t){const e=t.trim().toUpperCase(),i=zo.ISO.exec(e);if(!i||e==="P"||e.endsWith("T"))return;const[,n,s,r,o,c]=i,l=u=>u===void 0?0:Number(u.replace(",",".")),h=l(n)*604800+l(s)*86400+l(r)*3600+l(o)*60+l(c);return Number.isFinite(h)?h:void 0}static parse(t){let e=t.trim();if(e==="")return;const i=e.slice(-1),n="?~%".includes(i)?i:"";n!==""&&(e=e.slice(0,-1).trim());const s=e.split("/");if(s.length>2)return;const r=s.map(u=>zo.seconds(u));if(r.some(u=>u===void 0))return;const[o,c]=r,l=Math.min(o,c??o),h=Math.max(o,c??o);return{doubt:n,minSeconds:l,maxSeconds:h,chosenSeconds:(l+h)/2}}static isExact(t){const e=zo.parse(t);return e!==void 0&&e.doubt===""&&e.minSeconds===e.maxSeconds}static format(t){const e=Math.max(0,Math.round(t*10)/10),i=Math.floor(e/3600),n=Math.floor(e%3600/60),s=Math.round(e%60*10)/10;return`PT${`${i>0?`${i}H`:""}${n>0?`${n}M`:""}${s>0||i===0&&n===0?`${s}S`:""}`}`}static say(t){const e=Math.round(t*10)/10;if(e<60)return`${e} s`;const i=Math.floor(e/3600),n=Math.floor(e%3600/60),s=Math.round(e%60*10)/10,r=[];return i>0&&r.push(`${i} h`),n>0&&r.push(`${n} min`),s>0&&r.push(`${s} s`),r.join(" ")}}class Ie{static MOON_ANGULAR_WIDTH_DEG=.5237;static CANVAS_WIDTH_PX=640;static CANVAS_HEIGHT_PX=360;static angularWidthDeg(t){return 2*Math.atan(t.sizeM/(2*t.distanceM))*180/Math.PI}static inMoons(t){return t/Ie.MOON_ANGULAR_WIDTH_DEG}static lerpAngular(t,e,i){if(!(!t||!e))return{widthDeg:t.widthDeg+(e.widthDeg-t.widthDeg)*i,heightDeg:t.heightDeg+(e.heightDeg-t.heightDeg)*i}}static sizeMAt(t,e){return 2*t*Math.tan(e*Math.PI/360)}static distanceMAt(t,e){return t/(2*Math.tan(e*Math.PI/360))}}function Vv(a,t,e){if(!a||!t)return e<1?a:t;const i=((t.azimuthDeg-a.azimuthDeg)%360+540)%360-180;return{azimuthDeg:((a.azimuthDeg+i*e)%360+360)%360,altitudeDeg:a.altitudeDeg+(t.altitudeDeg-a.altitudeDeg)*e}}function Wv(a,t,e){const{bounds:i}=a;return t>=i.x&&t<=i.x+i.width&&e>=i.y&&e<=i.y+i.height}function nn(a,t,e){return a+(t-a)*e}function Lf(a){const t=/^#([0-9a-f]{6})$/i.exec(a);if(!t)return;const e=parseInt(t[1],16);return[e>>16&255,e>>8&255,e&255]}function Xv(a){return`#${a.map(t=>Math.round(t).toString(16).padStart(2,"0")).join("")}`}function Yv(a,t,e){const i=Lf(a),n=Lf(t);return!i||!n?e<1?a:t:Xv([nn(i[0],n[0],e),nn(i[1],n[1],e),nn(i[2],n[2],e)])}function qv(a,t,e){const i={x:nn(a.bounds.x,t.bounds.x,e),y:nn(a.bounds.y,t.bounds.y,e),width:nn(a.bounds.width,t.bounds.width,e),height:nn(a.bounds.height,t.bounds.height,e)},n=nn(a.angle,t.angle,e),s=nn(a.transparency,t.transparency,e),r=nn(a.haloScale,t.haloScale,e),o=nn(a.blur??0,t.blur??0,e),c=nn(a.brightness??0,t.brightness??0,e),l=Yv(a.color,t.color,e),h=Ie.lerpAngular(a.angular,t.angular,e),u=Vv(a.aim,t.aim,e);return a.kind==="polygon"&&t.kind==="polygon"&&a.points.length===t.points.length?{...a,bounds:i,angle:n,transparency:s,haloScale:r,blur:o,brightness:c,color:l,angular:h,aim:u,points:a.points.map((d,f)=>({x:nn(d.x,t.points[f].x,e),y:nn(d.y,t.points[f].y,e)}))}:{...e<1?a:t,bounds:i,angle:n,transparency:s,haloScale:r,blur:o,brightness:c,color:l,angular:h,aim:u}}class Tr{static DEFAULT_COLOR="#e8e6df";static complete(t,e=[]){const i=new Map;return t.map((n,s)=>({keyframe:n,index:s})).sort((n,s)=>n.keyframe.t-s.keyframe.t).map(({keyframe:n,index:s})=>({t:n.t,shapes:(n.shapes??[]).map((r,o)=>{const c=`timeline.keyframes.${s}.shapes.${o}.shape`,l=Tr.completed(r,i.get(r.sourceId),c,e);return i.set(r.sourceId,l),{sourceId:r.sourceId,shape:l}})}))}static completed(t,e,i,n){const s=t.shape??{},r=e??Tr.firstAppearance(s,i,n),o={...r};s.bounds&&e&&(e.aim||e.angular)&&!s.aim&&!s.angular&&n.push({kind:"pixels-over-angles",path:i}),s.bounds&&(s.aim||delete o.aim,s.angular||delete o.angular);const c=s.kind??r.kind??"oval",l={...o,...s,kind:c};if(c==="polygon"&&!l.points){n.push({kind:"defaulted",path:`${i}.points`,expected:"rectangle"});const{width:h,height:u}=l.bounds;return{...l,points:[{x:0,y:0},{x:h,y:0},{x:h,y:u},{x:0,y:u}]}}return l}static firstAppearance(t,e,i){return t.kind||i.push({kind:"defaulted",path:`${e}.kind`,expected:'"oval"'}),t.color||i.push({kind:"defaulted",path:`${e}.color`,expected:`"${Tr.DEFAULT_COLOR}"`}),!t.bounds&&!t.aim&&i.push({kind:"unplaced",path:e}),!t.bounds&&!t.angular&&i.push({kind:"unsized",path:e}),{kind:t.kind??"oval",bounds:{...Tr.NEUTRAL_BOUNDS},color:Tr.DEFAULT_COLOR,angle:0,transparency:0,haloScale:0,selected:!1}}static NEUTRAL_BOUNDS={x:Ie.CANVAS_WIDTH_PX/2,y:Ie.CANVAS_HEIGHT_PX/2,width:1,height:1}}class lh{keyframes=[];order=[];groups=[];addKeyframe(t,e){const i=this.findInsertIndex(t);if(this.keyframes[i]?.t===t){const n=new Set(e.map(s=>s.sourceId));this.keyframes[i]={t,shapes:[...this.keyframes[i].shapes.filter(s=>!n.has(s.sourceId)),...e]}}else this.keyframes.splice(i,0,{t,shapes:[...e]});for(const n of e)this.order.includes(n.sourceId)||this.order.push(n.sourceId)}findInsertIndex(t){let e=0,i=this.keyframes.length;for(;e<i;){const n=e+i>>>1;this.keyframes[n].t<t?e=n+1:i=n}return e}getKeyframeAt(t){const e=this.findInsertIndex(t),i=this.keyframes[e];return i?.t===t?i:void 0}getShapeAt(t,e){return this.getKeyframeAt(t)?.shapes.find(i=>i.sourceId===e)?.shape}getLatestShapeAt(t,e){let i=this.findInsertIndex(t);for(this.keyframes[i]?.t!==t&&(i-=1);i>=0;i--){const n=this.keyframes[i].shapes.find(s=>s.sourceId===e);if(n)return n.shape}}getInterpolatedShapeAt(t,e){const i=this.findShapeAtOrBefore(t,e);if(i?.t===t)return i.shape;const n=this.findShapeAtOrAfter(t,e);return i?n?qv(i.shape,n.shape,(t-i.t)/(n.t-i.t)):i.shape:n?.shape}findShapeAtOrBefore(t,e){let i=this.findInsertIndex(t);for(this.keyframes[i]?.t!==t&&(i-=1);i>=0;i--){const n=this.keyframes[i].shapes.find(s=>s.sourceId===e);if(n)return{t:this.keyframes[i].t,shape:n.shape}}}findShapeAtOrAfter(t,e){for(let i=this.findInsertIndex(t);i<this.keyframes.length;i++){const n=this.keyframes[i].shapes.find(s=>s.sourceId===e);if(n)return{t:this.keyframes[i].t,shape:n.shape}}}hitTest(t,e,i,n){const s=this.sourceIds;for(let r=s.length-1;r>=0;r--){if(n?.has(s[r]))continue;const o=this.getInterpolatedShapeAt(t,s[r]);if(o&&Wv(o,e,i))return{sourceId:s[r],shape:o}}}removeSource(t){for(let e=this.keyframes.length-1;e>=0;e--){const i=this.keyframes[e].shapes.filter(n=>n.sourceId!==t);i.length===0?this.keyframes.splice(e,1):i.length!==this.keyframes[e].shapes.length&&(this.keyframes[e]={t:this.keyframes[e].t,shapes:i})}this.order=this.order.filter(e=>e!==t),this.removeFromGroup(t)}group(t){if(!(t.length<2)){for(const e of t)this.removeFromGroup(e);this.groups.push([...t])}}ungroup(t){const e=this.groups.findIndex(i=>i.includes(t));e!==-1&&this.groups.splice(e,1)}groupMembers(t){return this.groups.find(e=>e.includes(t))}removeFromGroup(t){const e=this.groups.findIndex(n=>n.includes(t));if(e===-1)return;const i=this.groups[e].filter(n=>n!==t);i.length<2?this.groups.splice(e,1):this.groups[e]=i}bringToFront(t){const e=this.order.indexOf(t);e!==-1&&(this.order.splice(e,1),this.order.push(t))}sendToBack(t){const e=this.order.indexOf(t);e!==-1&&(this.order.splice(e,1),this.order.unshift(t))}get duration(){return this.keyframes.length===0?0:this.keyframes[this.keyframes.length-1].t}get sourceIds(){return[...this.order]}get allKeyframes(){return this.keyframes}toJSON(){return{keyframes:this.keyframes,order:this.order,groups:this.groups}}static fromJSON(t,e){const i=new lh;for(const n of Tr.complete(t.keyframes??[],e))i.addKeyframe(n.t,n.shapes);if(t.order){const n=i.order.filter(s=>!t.order.includes(s));i.order=[...t.order,...n]}return t.groups&&(i.groups=t.groups.map(n=>n.filter(s=>i.order.includes(s))).filter(n=>n.length>=2)),i}}function $v(a,t,e){return Math.max(t,Math.min(e,a))}function Kv(a,t,e){const i=((t-a)%360+540)%360-180;return((a+i*e)%360+360)%360}function Qr(a,t,e){return a+(t-a)*e}function Zv(a,t,e){return{lat:a.lat===void 0||t.lat===void 0?void 0:Qr(a.lat,t.lat,e),lng:a.lng===void 0||t.lng===void 0?void 0:Qr(a.lng,t.lng,e),elevationM:Qr(a.elevationM,t.elevationM,e),headingDeg:a.headingDeg===void 0||t.headingDeg===void 0?void 0:Kv(a.headingDeg,t.headingDeg,e),pitchDeg:Qr(a.pitchDeg,t.pitchDeg,e),rollDeg:Qr(a.rollDeg??0,t.rollDeg??0,e),fovDeg:Qr(a.fovDeg,t.fovDeg,e),fNumber:a.fNumber,focusDistanceM:a.focusDistanceM}}class Br{static at(t,e,i,n,s){const r=t[i],c=t[i+1]-r;if(c<=0)return e[i];const l=Br.tangent(t,e,i,s),h=Br.tangent(t,e,i+1,s),u=(n-r)/c,d=u*u,f=d*u;return(2*f-3*d+1)*e[i]+(f-2*d+u)*c*l+(-2*f+3*d)*e[i+1]+(f-d)*c*h}static BRAKE_S=.8;static paced(t,e,i,n){if(!i&&!n)return t;const s=e>0?Math.min(.5,Br.BRAKE_S/e):.5;if(i&&n){const o=1/(1-s);return t<=s?o*t*t/(2*s):t>=1-s?1-o*(1-t)*(1-t)/(2*s):o*(t-s/2)}const r=o=>{const c=1/(1-s/2);if(o<=1-s)return c*o;const l=o-(1-s);return c*(1-s)+c*(l-l*l/(2*s))};return n?r(t):1-r(1-t)}static tangent(t,e,i,n){const s=t.length-1,r=f=>(e[f+1]-e[f])/(t[f+1]-t[f]||1);if(i===0)return n?0:r(0);if(i===s)return n?0:r(s-1);const o=r(i-1),c=r(i);if(o*c<=0)return 0;const l=t[i]-t[i-1],h=t[i+1]-t[i],u=2*h+l,d=h+2*l;return(u+d)/(u/o+d/c)}}class jo{keyframes=[];addKeyframe(t,e){const i=this.findInsertIndex(t);this.keyframes[i]?.t===t?this.keyframes[i]={t,pose:e}:this.keyframes.splice(i,0,{t,pose:e})}clear(){this.keyframes.length=0}removeKeyframeAt(t){const e=this.findInsertIndex(t);this.keyframes[e]?.t===t&&this.keyframes.splice(e,1)}findInsertIndex(t){let e=0,i=this.keyframes.length;for(;e<i;){const n=e+i>>>1;this.keyframes[n].t<t?e=n+1:i=n}return e}getLatestPoseAt(t){let e=this.findInsertIndex(t);return this.keyframes[e]?.t!==t&&(e-=1),e>=0?this.keyframes[e].pose:void 0}getInterpolatedPoseAt(t){const e=this.findInsertIndex(t),i=this.keyframes[e]?.t===t?this.keyframes[e]:this.keyframes[e-1];if(i?.t===t)return i.pose;const n=this.keyframes[e]?.t===t?void 0:this.keyframes[e];if(!i)return n?.pose;if(!n)return i.pose;const s=Zv(i.pose,n.pose,$v((t-i.t)/(n.t-i.t),0,1));return this.humanly(e-1,t,s)}humanly(t,e,i){const n=Math.max(0,t-1),s=Math.min(this.keyframes.length-1,t+2),r=this.keyframes.slice(n,s+1),o=t-n,c=r.map(x=>x.t),l=(x,M)=>{const b=r.map(w=>x(w.pose));if(!b.some(w=>w===void 0))return Br.at(c,b,o,e,M)},h=r.map(x=>x.pose.headingDeg);let u;if(h.every(x=>x!==void 0)){const x=[h[0]];for(let M=1;M<h.length;M++)x.push(x[M-1]+((h[M]-h[M-1])%360+540)%360-180);u=(Br.at(c,x,o,e,!0)%360+360)%360}const d=this.keyframes[t],f=this.keyframes[t+1],p=(x,M)=>x.lat===M.lat&&x.lng===M.lng&&x.elevationM===M.elevationM,v=!p(d.pose,f.pose),m=v&&t>0&&p(this.keyframes[t-1].pose,d.pose),g=v&&t+2<this.keyframes.length&&p(f.pose,this.keyframes[t+2].pose);let S;if(m||g){const x=Br.paced((e-d.t)/(f.t-d.t),(f.t-d.t)/1e3,m,g),M=(b,w)=>b===void 0||w===void 0?void 0:b+(w-b)*x;S={lat:M(d.pose.lat,f.pose.lat),lng:M(d.pose.lng,f.pose.lng),elevationM:M(d.pose.elevationM,f.pose.elevationM)}}return{...i,lat:S?S.lat:l(x=>x.lat,!1)??i.lat,lng:S?S.lng:l(x=>x.lng,!1)??i.lng,elevationM:S?S.elevationM:l(x=>x.elevationM,!1)??i.elevationM,headingDeg:u??i.headingDeg,pitchDeg:l(x=>x.pitchDeg,!0)??i.pitchDeg,rollDeg:l(x=>x.rollDeg??0,!0)??i.rollDeg,fovDeg:l(x=>x.fovDeg,!0)??i.fovDeg}}get duration(){return this.keyframes.length===0?0:this.keyframes[this.keyframes.length-1].t}get allKeyframes(){return this.keyframes}toJSON(){return{keyframes:this.keyframes}}static fromJSON(t){const e=new jo;for(const i of t.keyframes)e.addKeyframe(i.t,i.pose);return e}}class tr{static MAX_CHANGE_PER_S=.05;points;followed;constructor(t){let e="none",i=0;this.points=t.map(({t:n,weather:s})=>(s.precipitationType!=="none"&&(e=s.precipitationType,i=s.precipitationIntensity),{t:n,lastFalling:e,lastFallingIntensity:i,intensity:s.precipitationType==="none"?0:s.precipitationIntensity,type:s.precipitationType})),this.followed=[];for(let n=0;n<this.points.length;n++){if(n===0){this.followed.push(this.points[0].intensity);continue}const s=this.points[n-1],r=this.points[n];this.followed.push(tr.follow(this.followed[n-1],s.intensity,r.intensity,(r.t-s.t)/1e3,(r.t-s.t)/1e3))}}at(t){if(this.points.length===0||t<this.points[0].t)return;let e=this.points.length-1;for(;e>0&&this.points[e].t>t;)e--;const i=this.points[e],n=this.points[e+1],s=n?tr.follow(this.followed[e],i.intensity,n.intensity,(n.t-i.t)/1e3,(t-i.t)/1e3):tr.follow(this.followed[e],i.intensity,i.intensity,1,(t-i.t)/1e3);return{type:tr.typeBetween(i,n,t,s),intensity:s,character:tr.characterBetween(i,n,t)}}static characterBetween(t,e,i){return t.type==="none"?e&&e.type!=="none"?e.intensity:t.lastFallingIntensity:!e||e.type==="none"?t.intensity:t.intensity+(e.intensity-t.intensity)*(i-t.t)/(e.t-t.t||1)}static typeBetween(t,e,i,n){return t.type==="none"?e&&e.type!=="none"&&i>t.t?e.type:n>0?t.lastFalling:"none":e&&e.type==="none"&&n<=0?"none":t.type}static follow(t,e,i,n,s){const r=tr.MAX_CHANGE_PER_S,o=n>0?(i-e)/n:0,c=u=>e+o*Math.min(Math.max(u,0),n);let l=t,h=0;for(let u=0;u<8&&h<s;u++){const d=c(h)-l;if(Math.abs(d)<1e-9){const x=h<n?o:0;if(Math.abs(x)<=r){const b=h<n?Math.min(s,n):s;l=c(b),h=b;continue}const M=Math.min(s,n);l+=Math.sign(x)*r*(M-h),h=M;continue}const f=Math.sign(d),p=h<n?o:0,v=r-f*p,m=v>0?h+Math.abs(d)/v:1/0,g=h<n?n:1/0,S=Math.min(s,m,g);l+=f*r*(S-h),h=S,S===m&&(l=c(h))}return Math.min(1,Math.max(0,l))}}function He(a,t,e){return a+(t-a)*e}function E0(a,t,e){const i=((t-a)%360+540)%360-180;return((a+i*e)%360+360)%360}function Jv(a,t,e){return Math.max(t,Math.min(e,a))}function jv(a=[],t=[],e){if(!(!a.length&&!t.length))return[...new Set([...a.map(i=>i.id),...t.map(i=>i.id)])].map(i=>{const n=a.find(c=>c.id===i),s=t.find(c=>c.id===i),r=n??{...s,density:0},o=s??{...n,density:0};return{...r,eastM:He(r.eastM,o.eastM,e),northM:He(r.northM,o.northM,e),baseM:He(r.baseM,o.baseM,e),thicknessM:He(r.thicknessM,o.thicknessM,e),widthM:He(r.widthM,o.widthM,e),depthM:He(r.depthM,o.depthM,e),rotationDeg:E0(r.rotationDeg,o.rotationDeg,e),density:He(r.density,o.density,e),darkness:He(r.darkness??0,o.darkness??0,e)}})}function Qv(a,t,e){if(a.cloudLayers===void 0&&t.cloudLayers===void 0)return;const i=Ul(a),n=Ul(t);return e>=1?n.map(r=>({...r})):[...new Set([...i.map(r=>r.id),...n.map(r=>r.id)])].map(r=>{const o=i.find(u=>u.id===r),c=n.find(u=>u.id===r),l=o??{...c,coverage:0},h=c??{...o,coverage:0};return{...l,instances:jv(o?.instances,c?.instances,e),baseM:He(l.baseM,h.baseM,e),thicknessM:He(l.thicknessM,h.thicknessM,e),coverage:He(l.coverage,h.coverage,e),sizeM:He(l.sizeM,h.sizeM,e),density:He(l.density,h.density,e),darkness:He(l.darkness??a.cloudDarkness,h.darkness??t.cloudDarkness,e),iceCrystalAlignment:l.iceCrystalAlignment===void 0||h.iceCrystalAlignment===void 0?void 0:He(l.iceCrystalAlignment,h.iceCrystalAlignment,e),windSpeed:l.windSpeed===void 0&&h.windSpeed===void 0?void 0:He(l.windSpeed??a.windSpeed,h.windSpeed??t.windSpeed,e),windDirectionDeg:l.windDirectionDeg===void 0&&h.windDirectionDeg===void 0?void 0:E0(l.windDirectionDeg??a.windDirectionDeg,h.windDirectionDeg??t.windDirectionDeg,e)}})}function t2(a,t,e){return{cloudLayers:Qv(a,t,e),cloudCover:He(a.cloudCover,t.cloudCover,e),cloudDarkness:He(a.cloudDarkness,t.cloudDarkness,e),highCloudCover:a.highCloudCover===void 0||t.highCloudCover===void 0?void 0:He(a.highCloudCover,t.highCloudCover,e),iceCrystalAlignment:a.iceCrystalAlignment===void 0||t.iceCrystalAlignment===void 0?void 0:He(a.iceCrystalAlignment,t.iceCrystalAlignment,e),lowerCloudCover:a.lowerCloudCover===void 0||t.lowerCloudCover===void 0?void 0:He(a.lowerCloudCover,t.lowerCloudCover,e),cloudBaseM:a.cloudBaseM===void 0||t.cloudBaseM===void 0?void 0:He(a.cloudBaseM,t.cloudBaseM,e),relativeHumidity:a.relativeHumidity===void 0||t.relativeHumidity===void 0?void 0:He(a.relativeHumidity,t.relativeHumidity,e),precipitationType:e<1?a.precipitationType:t.precipitationType,precipitationIntensity:He(a.precipitationIntensity,t.precipitationIntensity,e),windDirectionDeg:E0(a.windDirectionDeg,t.windDirectionDeg,e),windSpeed:He(a.windSpeed,t.windSpeed,e),storm:e<1?a.storm:t.storm}}class Qo{keyframes=[];ramp;addKeyframe(t,e){this.ramp=void 0;const i=this.findInsertIndex(t);this.keyframes[i]?.t===t?this.keyframes[i]={t,weather:e}:this.keyframes.splice(i,0,{t,weather:e})}clear(){this.ramp=void 0,this.keyframes.length=0}removeKeyframeAt(t){this.ramp=void 0;const e=this.findInsertIndex(t);this.keyframes[e]?.t===t&&this.keyframes.splice(e,1)}findInsertIndex(t){let e=0,i=this.keyframes.length;for(;e<i;){const n=e+i>>>1;this.keyframes[n].t<t?e=n+1:i=n}return e}getLatestWeatherAt(t){let e=this.findInsertIndex(t);return this.keyframes[e]?.t!==t&&(e-=1),e>=0?this.keyframes[e].weather:void 0}getInterpolatedWeatherAt(t){const e=this.findInsertIndex(t),i=this.keyframes[e]?.t===t?this.keyframes[e]:this.keyframes[e-1];if(i?.t===t)return i.weather;const n=this.keyframes[e]?.t===t?void 0:this.keyframes[e];return i?n?t2(i.weather,n.weather,Jv((t-i.t)/(n.t-i.t),0,1)):i.weather:n?.weather}getActualWeatherAt(t){const e=this.getInterpolatedWeatherAt(t);if(!e)return;const i=(this.ramp??=new tr(this.keyframes)).at(t);if(!i)return e;const{type:n,intensity:s,character:r}=i,o=r>0?Math.min(1,s/r):n==="none"?0:1;return{...e,precipitationType:n,precipitationIntensity:r,precipitationAmount:o}}get duration(){return this.keyframes.length===0?0:this.keyframes[this.keyframes.length-1].t}get allKeyframes(){return this.keyframes}toJSON(){return{keyframes:this.keyframes}}static fromJSON(t){const e=new Qo;for(const i of t.keyframes)e.addKeyframe(i.t,{...ch,...i.weather});return e}}class tc{keyframes=[];addKeyframe(t,e){const i=this.findInsertIndex(t);this.keyframes[i]?.t===t?this.keyframes[i]={t,sound:e}:this.keyframes.splice(i,0,{t,sound:e})}clear(){this.keyframes.length=0}removeKeyframeAt(t){const e=this.findInsertIndex(t);this.keyframes[e]?.t===t&&this.keyframes.splice(e,1)}getLatestSoundAt(t){let e=this.findInsertIndex(t);return this.keyframes[e]?.t!==t&&(e-=1),e>=0?this.keyframes[e].sound:void 0}getInterpolatedSoundAt(t){const e=this.findInsertIndex(t),i=this.keyframes[e]?.t===t?this.keyframes[e]:this.keyframes[e-1];if(i?.t===t)return i.sound;const n=this.keyframes[e]?.t===t?void 0:this.keyframes[e];if(!i)return n?.sound;if(!n)return i.sound;const s=(t-i.t)/(n.t-i.t);return this.lerp(i.sound,n.sound,Math.max(0,Math.min(1,s)))}get duration(){return this.keyframes.length===0?0:this.keyframes[this.keyframes.length-1].t}get allKeyframes(){return this.keyframes}toJSON(){return{keyframes:this.keyframes}}static fromJSON(t){const e=new tc;for(const i of t.keyframes)e.addKeyframe(i.t,i.sound);return e}lerp(t,e,i){return{kind:i<1?t.kind:e.kind,volume:t.volume+(e.volume-t.volume)*i,pitchHz:t.pitchHz+(e.pitchHz-t.pitchHz)*i,src:i<1?t.src:e.src}}findInsertIndex(t){let e=0,i=this.keyframes.length;for(;e<i;){const n=e+i>>>1;this.keyframes[n].t<t?e=n+1:i=n}return e}}const e2=100,i2={kind:"none",volume:0,pitchHz:e2};class Dn{constructor(t){this.entries=t}static empty(){return new Dn(new Map)}get size(){return this.entries.size}at(t){return this.entries.get(t)}paths(){return[...this.entries.keys()]}set(t,e){e.basis==="stated"&&e.rationale===void 0?this.entries.delete(t):this.entries.set(t,e)}clear(t){for(const e of this.entries.keys())(e===t||e.startsWith(`${t}.`))&&this.entries.delete(e)}static strip(t){const e=new Dn(new Map);return{recording:Dn.stripValue(t,[],e),provenance:e}}static restore(t,e){if(e.size===0)return t;const i=structuredClone(t);for(const n of e.paths()){const s=e.at(n),r=n.split("."),o=Dn.holderOf(i,r);if(!o)continue;const c=r[r.length-1],l=o[c];l!==void 0&&(s.of!==void 0&&JSON.stringify(s.of)!==JSON.stringify(l)||(o[c]={value:l,...s.basis==="stated"?{}:{basis:s.basis},...s.rationale===void 0?{}:{rationale:s.rationale}}))}return i}static isWrapper(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)&&"value"in t}static stripValue(t,e,i){return Dn.isWrapper(t)?(i.set(e.join("."),{basis:t.basis??"stated",...t.rationale===void 0?{}:{rationale:t.rationale},of:t.value}),Dn.stripValue(t.value,e,i)):Array.isArray(t)?t.map((n,s)=>Dn.stripValue(n,[...e,String(s)],i)):typeof t=="object"&&t!==null?Object.fromEntries(Object.entries(t).map(([n,s])=>[n,Dn.stripValue(s,[...e,n],i)])):t}static holderOf(t,e){let i=t;for(const n of e.slice(0,-1)){if(typeof i!="object"||i===null)return;i=i[n]}return typeof i=="object"&&i!==null?i:void 0}}function Ju(a){if(a.year!==void 0)return Date.UTC(a.year,(a.month??1)-1,a.day??1,a.hour??0,a.minute??0,a.second??0)}function Of(a){return(((a.day??0)*24+(a.hour??0))*60+(a.minute??0))*6e4+(a.second??0)*1e3}const n2=["year","month","day","hour","minute"],s2=["day","hour","minute"];function Nf(a,t){return t.filter(e=>a[e]!==void 0).join(",")}function r2(a){if(a.durationSeconds!==void 0)return a.durationSeconds*1e3;const t=a.durationText===void 0?void 0:zo.parse(a.durationText);if(t)return t.chosenSeconds*1e3;if(!a.time||!a.endTime)return;const e=a.time.year!==void 0&&a.endTime.year!==void 0,i=e?n2:s2,n=Nf(a.time,i);if(!(n===""||n!==Nf(a.endTime,i)))return e?Ju(a.endTime)-Ju(a.time):Of(a.endTime)-Of(a.time)}class hh{constructor(t,e,i,n,s,r,o,c,l=[],h,u,d,f=[],p=[],v=[],m=[]){this.event=t,this.timeline=e,this.observerTrack=i,this.weatherTrack=n,this.soundTrack=s,this.observer=r,this.id=o,this.weather=c,this.decor=l,this.weatherSource=h,this.instrumentId=u,this.exposureSeconds=d,this.milestones=f,this.references=p,this.roads=v,this.traces=m}provenance=Dn.empty();loadIssues=[];account;sources;interpretation;sway;lightPollution;observerMap;iso;vehicle;get observerCount(){return 1+this.decor.filter(t=>t.kind==="observer").length}get exposure(){return this.exposureSeconds??this.instrument.exposureSeconds}get instrument(){return mi.byId(this.instrumentId)}static create(t,e,i){return new hh({eventType:"sighting",time:t,place:e},new lh,new jo,new Qo,new tc,i)}}const a2=0,o2=0;function Je(a,t){const e=a.observerTrack.getInterpolatedPoseAt(t);if(e)return e;const i=a.event.place?.[0];if(i)return{lat:i.lat,lng:i.lng,elevationM:a2,headingDeg:void 0,pitchDeg:o2,fovDeg:mi.fieldOfViewDeg(a.instrument)}}function ao(a,t){return a.weatherTrack.getInterpolatedWeatherAt(t)??a.weather??ch}function yc(a,t){return a.weatherTrack.getActualWeatherAt(t)??a.weather??ch}function c2(a,t){return a.soundTrack.getInterpolatedSoundAt(t)??i2}class l2{constructor(t,e){this.timeline=t,this.onFrame=e}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 t=()=>{if(this.state!=="playing")return;const e=performance.now();if(this.currentT+=(e-this.lastWallTime)*this.playbackRate,this.lastWallTime=e,this.currentT>=this.seekableDuration){if(this.loop&&this.seekableDuration>0){this.currentT%=this.seekableDuration,this.resolveFrame(this.currentT),this.rafId=requestAnimationFrame(t);return}this.currentT=this.seekableDuration,this.stop(),this.resolveFrame(this.currentT),this.onEnded?.();return}this.resolveFrame(this.currentT),this.rafId=requestAnimationFrame(t)};this.rafId=requestAnimationFrame(t)}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(t){this.currentT=Math.max(0,Math.min(t,this.seekableDuration)),this.resolveFrame(this.currentT)}get playbackState(){return this.state}get time(){return this.currentT}resolveFrame(t){const e=new Map;for(const i of this.timeline.sourceIds){const n=this.timeline.getInterpolatedShapeAt(t,i);n&&e.set(i,n)}this.onFrame(t,e)}}const kg=["nw","n","ne","e","se","s","sw","w"],h2=24,Sc=8,u2=3,d2=8;function _c(a,t,e){const i=a.x-t.x,n=a.y-t.y,s=Math.cos(e),r=Math.sin(e);return{x:t.x+i*s-n*r,y:t.y+i*r+n*s}}function oo(a){return{x:a.x+a.width/2,y:a.y+a.height/2}}const f2={nw:{left:!0,top:!0},n:{top:!0},ne:{right:!0,top:!0},e:{right:!0},se:{right:!0,bottom:!0},s:{bottom:!0},sw:{left:!0,bottom:!0},w:{left:!0}};class pn{static handlePointsFor(t){const{x:e,y:i,width:n,height:s}=t.bounds,r={nw:{x:e,y:i},n:{x:e+n/2,y:i},ne:{x:e+n,y:i},e:{x:e+n,y:i+s/2},se:{x:e+n,y:i+s},s:{x:e+n/2,y:i+s},sw:{x:e,y:i+s},w:{x:e,y:i+s/2},rotate:{x:e+n/2,y:i-h2}},o=oo(t.bounds),c={};for(const l of Object.keys(r))c[l]=_c(r[l],o,t.angle);return c}static hitTestHandle(t,e,i=8,n=[...kg,"rotate"]){const s=pn.handlePointsFor(t);for(const r of n)if(Math.hypot(e.x-s[r].x,e.y-s[r].y)<=i)return r}static HANDLE_DIRECTION_DEG={e:0,se:45,s:90,sw:135,w:180,nw:225,n:270,ne:315};static resizeAxisFor(t,e){const n=((pn.HANDLE_DIRECTION_DEG[t]+e*180/Math.PI)%180+180)%180/45,s=["ew","nwse","ns","nesw"];return s[Math.round(n)%s.length]}static resizeBounds(t,e,i,n){const s=oo(t),r=_c(n,s,-e),{x:o,y:c,width:l,height:h}=t,u=f2[i];let d=o,f=c,p=o+l,v=c+h;return u.left&&(d=Math.min(r.x,p-Sc)),u.right&&(p=Math.max(r.x,d+Sc)),u.top&&(f=Math.min(r.y,v-Sc)),u.bottom&&(v=Math.max(r.y,f+Sc)),{x:d,y:f,width:p-d,height:v-f}}static resizeShape(t,e,i){if(e==="rotate")throw new Error("resizeShape does not accept the rotate handle");const{width:n,height:s}=t.bounds,r=pn.resizeBounds(t.bounds,t.angle,e,i);if(t.kind==="oval")return{...t,bounds:r};const o=n===0?1:r.width/n,c=s===0?1:r.height/s;return{...t,bounds:r,points:t.points.map(l=>({x:l.x*o,y:l.y*c}))}}static rotateShape(t,e){const i=oo(t.bounds),n=Math.atan2(e.y-i.y,e.x-i.x)+Math.PI/2;return{...t,angle:n}}static groupBoundsFor(t){const e=Math.min(...t.map(r=>r.x)),i=Math.min(...t.map(r=>r.y)),n=Math.max(...t.map(r=>r.x+r.width)),s=Math.max(...t.map(r=>r.y+r.height));return{x:e,y:i,width:n-e,height:s-i}}static vertexPointsFor(t){const e=oo(t.bounds);return t.points.map(i=>_c({x:t.bounds.x+i.x,y:t.bounds.y+i.y},e,t.angle))}static hitTestVertex(t,e,i=d2){const n=pn.vertexPointsFor(t);let s,r=i;return n.forEach((o,c)=>{const l=Math.hypot(e.x-o.x,e.y-o.y);l<=r&&(r=l,s=c)}),s}static toLocalPoint(t,e){const i=oo(t.bounds),n=_c(e,i,-t.angle);return{x:n.x-t.bounds.x,y:n.y-t.bounds.y}}static moveVertex(t,e,i){const n=t.points.map((u,d)=>d===e?pn.toLocalPoint(t,i):u),s=Math.min(...n.map(u=>u.x)),r=Math.min(...n.map(u=>u.y)),o=Math.max(...n.map(u=>u.x)),c=Math.max(...n.map(u=>u.y)),l={x:t.bounds.x+s,y:t.bounds.y+r,width:o-s,height:c-r},h=n.map(u=>({x:u.x-s,y:u.y-r}));return{...t,bounds:l,points:h}}static insertVertexNear(t,e){const i=pn.toLocalPoint(t,e),{points:n}=t;let s=n.length-1,r=1/0;for(let c=0;c<n.length;c++){const l=n[c],h=n[(c+1)%n.length],u=pn.distanceToSegment(i,l,h);u<r&&(r=u,s=c)}const o=[...n.slice(0,s+1),i,...n.slice(s+1)];return{...t,points:o}}static distanceToSegment(t,e,i){const n=i.x-e.x,s=i.y-e.y,r=n*n+s*s,o=r===0?0:Math.max(0,Math.min(1,((t.x-e.x)*n+(t.y-e.y)*s)/r)),c=e.x+o*n,l=e.y+o*s;return Math.hypot(t.x-c,t.y-l)}static deleteVertex(t,e){return t.points.length<=u2?t:{...t,points:t.points.filter((i,n)=>n!==e)}}}const ju=6,bc=ju/2,Ff=20,Uf=24,kf=9,zf=6,Bf=7,Hf=6,es=4;class ec{constructor(t){this.ctx=t}starPoints=0;roll=0;clear(t,e){this.ctx.clearRect(0,0,t,e)}static paintExtent(t){const{x:e,y:i,width:n,height:s}=t.bounds,r=e+n/2,o=i+s/2,c=t.angle%(2*Math.PI)!==0,l=Math.hypot(n,s)/2,h=c?l:n/2,u=c?l:s/2,d=Math.max(n,s)/2,f=t.brightness??0,p=f>0?Math.max(d*(1+kf*f),Hf*f)-d:0,v=f>0?d*(1+Bf*f)-d:0,m=3*Uf*(t.blur??0)+1.5*Ff*t.haloScale,g=Math.max(p,v,0)+m+2;return{x:r-h-g,y:o-u-g,width:2*(h+g),height:2*(u+g)}}paintInto(t,e,i,n=!1){this.ctx.save(),this.ctx.scale(i,i),this.ctx.translate(-e.x,-e.y);const s=t.selected?{...t,selected:!1}:t;n?this.paintGhost(s,1.5):this.paintShape(s),this.ctx.restore()}paintShape(t){this.ctx.save(),this.ctx.globalAlpha=1-t.transparency;const e=t.blur??0;e>0&&(this.ctx.filter=`blur(${(Uf*e).toFixed(2)}px)`);const i=t.brightness??0;i>0&&this.paintDazzle(t,i),t.haloScale>0&&this.paintHalo(t),this.paintBase(t),this.ctx.restore(),t.selected&&this.paintSelectionHandles(t)}setStarPoints(t){this.starPoints=Math.max(0,Math.floor(t))}setRoll(t){this.roll=t}paintDazzle(t,e){const{x:i,y:n,width:s,height:r}=t.bounds,o=i+s/2,c=n+r/2,l=Math.max(s,r)/2,h=Math.max(l*(1+kf*e),Hf*e);if(h<=0)return;this.ctx.save(),this.ctx.globalCompositeOperation="lighter";const u=this.ctx.createRadialGradient(o,c,0,o,c,h);for(let d=0;d<=zf;d++){const f=d/zf,p=1/(1+24*f*f);this.ctx.globalAlpha=1,u.addColorStop(f,this.withAlpha(t.color,p*e*.55))}if(this.ctx.fillStyle=u,this.ctx.beginPath(),this.ctx.arc(o,c,h,0,2*Math.PI),this.ctx.fill(),this.starPoints>0){const d=l*(1+Bf*e);this.ctx.lineWidth=Math.max(1,l*.12),this.ctx.lineCap="round";for(let f=0;f<this.starPoints;f++){const p=f/this.starPoints*Math.PI*2+this.roll,v=o+Math.cos(p)*d,m=c+Math.sin(p)*d,g=this.ctx.createLinearGradient(o,c,v,m);g.addColorStop(0,this.withAlpha(t.color,e*.55)),g.addColorStop(.35,this.withAlpha(t.color,e*.22)),g.addColorStop(1,this.withAlpha(t.color,0)),this.ctx.strokeStyle=g,this.ctx.beginPath(),this.ctx.moveTo(o,c),this.ctx.lineTo(v,m),this.ctx.stroke()}}this.ctx.restore()}dazzledFill(t,e){if(e<=0)return t.color;const i=/^#([0-9a-f]{6})$/i.exec(t.color.trim());if(!i)return t.color;const n=Number.parseInt(i[1],16),s=r=>Math.round(r+(255-r)*e);return`rgb(${s(n>>16&255)}, ${s(n>>8&255)}, ${s(n&255)})`}withAlpha(t,e){const i=Math.max(0,Math.min(1,e)),n=/^#([0-9a-f]{6})$/i.exec(t.trim());if(!n)return t;const s=Number.parseInt(n[1],16);return`rgba(${s>>16&255}, ${s>>8&255}, ${s&255}, ${i.toFixed(3)})`}paintBase(t){this.ctx.fillStyle=this.dazzledFill(t,t.brightness??0),this.tracePath(t),this.ctx.fill()}paintGhost(t,e){this.ctx.save(),this.tracePath(t),this.ctx.setLineDash([e*3,e*2]),this.ctx.lineWidth=e,this.ctx.strokeStyle=t.color,this.ctx.stroke(),this.ctx.restore()}tracePath(t){if(this.ctx.beginPath(),t.kind==="oval"){const{x:e,y:i,width:n,height:s}=t.bounds,r=n/2,o=s/2;this.ctx.ellipse(e+r,i+o,r,o,t.angle,0,2*Math.PI)}else{const{x:e,y:i,width:n,height:s}=t.bounds;this.ctx.save(),this.ctx.translate(e+n/2,i+s/2),this.ctx.rotate(t.angle),this.ctx.translate(-n/2,-s/2),t.points.forEach((r,o)=>{o===0?this.ctx.moveTo(r.x,r.y):this.ctx.lineTo(r.x,r.y)}),this.ctx.closePath(),this.ctx.restore()}}paintHalo(t){this.ctx.save(),this.ctx.shadowColor=t.color,this.ctx.shadowBlur=Ff*t.haloScale,this.paintBase(t),this.ctx.restore()}paintSelectionHandles(t){this.paintHandleFrame(pn.handlePointsFor(t),{includeRotate:!0}),t.kind==="polygon"&&this.paintVertexHandles(t)}paintVertexHandles(t){this.ctx.fillStyle="#39f";for(const e of pn.vertexPointsFor(t))this.ctx.beginPath(),this.ctx.ellipse(e.x,e.y,es,es,0,0,2*Math.PI),this.ctx.fill()}paintMemberOutline(t){this.paintOutline(pn.handlePointsFor(t))}paintSelectionOnly(t){this.paintSelectionHandles(t)}paintPictureFrame(t,e,i){const n=this.ctx;if(n.save(),t&&t.length===4){n.strokeStyle="#39f",n.lineWidth=1.5,n.setLineDash([6,4]),n.beginPath(),n.moveTo(t[0].x,t[0].y);for(const s of t.slice(1))n.lineTo(s.x,s.y);n.closePath(),n.stroke(),n.setLineDash([])}for(const s of e){const r=ec.landmarkColour(s.residualDeg),o=s.selected?3:2;s.selected&&(n.strokeStyle="#fff",n.lineWidth=o+3,n.beginPath(),n.ellipse(s.picture.x,s.picture.y,es+2,es+2,0,0,2*Math.PI),n.stroke()),s.scene&&(n.strokeStyle=r,n.lineWidth=1,n.beginPath(),n.moveTo(s.picture.x,s.picture.y),n.lineTo(s.scene.x,s.scene.y),n.stroke(),n.fillStyle=r,n.beginPath(),n.ellipse(s.scene.x,s.scene.y,es,es,0,0,2*Math.PI),n.fill()),n.strokeStyle=r,n.lineWidth=o,n.beginPath(),n.ellipse(s.picture.x,s.picture.y,es+2,es+2,0,0,2*Math.PI),n.stroke(),this.paintLabel(s.label,s.picture.x+es+5,s.picture.y-es-2,r)}i&&this.paintLabel(i,8,8,"#fff",13),n.restore()}static landmarkColour(t){return t===void 0?"#ffb000":t<=1?"#3c3":t<=3?"#ffb000":"#f33"}paintLabel(t,e,i,n,s=11){const r=this.ctx;r.save(),r.font=`${s}px system-ui, sans-serif`,r.textBaseline="top";const o=r.measureText(t).width;r.fillStyle="rgba(0, 0, 0, 0.6)",r.fillRect(e-3,i-2,o+6,s+4),r.fillStyle=n,r.fillText(t,e,i),r.restore()}paintGroupHandles(t){this.paintHandleFrame(pn.handlePointsFor({bounds:t,angle:0}),{includeRotate:!0})}paintOutline(t){this.ctx.strokeStyle="lightgray",this.ctx.beginPath(),this.ctx.moveTo(t.nw.x,t.nw.y),this.ctx.lineTo(t.ne.x,t.ne.y),this.ctx.lineTo(t.se.x,t.se.y),this.ctx.lineTo(t.sw.x,t.sw.y),this.ctx.closePath(),this.ctx.stroke()}paintHandleFrame(t,{includeRotate:e}){this.paintOutline(t),this.ctx.fillStyle="lightgray";for(const i of kg){const n=t[i];this.ctx.fillRect(n.x-bc,n.y-bc,ju,ju)}e&&(this.ctx.beginPath(),this.ctx.moveTo(t.n.x,t.n.y),this.ctx.lineTo(t.rotate.x,t.rotate.y),this.ctx.stroke(),this.ctx.beginPath(),this.ctx.ellipse(t.rotate.x,t.rotate.y,bc+1,bc+1,0,0,2*Math.PI),this.ctx.fill())}}const Gf=.05,Vf=.08,Wf=2,Xf=3,p2=14,m2=.02;class g2{context;voice;voiceToken=0;buffers=new Map;noiseBuffer;crackleBuffer;requested;level=1;master;output(t){return this.master||(this.master=t.createGain(),this.master.gain.value=this.level,this.master.connect(t.destination)),this.master}setLevel(t){this.level=t,this.master&&(this.master.gain.value=t)}resume(){if(!this.context){if(typeof AudioContext>"u")return;try{this.context=new AudioContext}catch(t){console.warn("SightingAudio: Web Audio unavailable, the sighting stays silent:",t);return}}zr.unlock(this.context)}setSound(t){if(this.requested=t,!this.context)return;const e=this.keyFor(t);if(!e){this.silence();return}if(this.voice?.key!==e){this.stopVoice();const i=++this.voiceToken;e.startsWith("src:")?this.buildRecordedVoice(t.src,e,i):this.voice=this.buildSynthesizedVoice(t,e)}this.applyTo(this.voice,t)}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(t){if(!(t.volume<=0))return t.src?`src:${t.src}`:t.kind==="none"?void 0:t.kind}applyTo(t,e){const i=this.context;if(!t||!i)return;const n=i.currentTime;t.volumeParam.setTargetAtTime(Math.max(0,Math.min(1,e.volume))*t.gainScale,n,Gf);for(const{param:s,ratio:r}of t.pitch)s.setTargetAtTime(Math.min(e.pitchHz*r,i.sampleRate/2-1),n,Gf)}buildSynthesizedVoice(t,e){const i=this.context;if(i)switch(t.kind){case"hum":return this.buildHum(i,e);case"whistle":return this.buildWhistle(i,e);case"rumble":return this.buildRumble(i,e);case"crackle":return this.buildCrackle(i,e);default:return}}buildHum(t,e){const i=t.createOscillator();i.type="sawtooth";const n=t.createOscillator();n.type="sawtooth";const s=t.createBiquadFilter();s.type="lowpass",s.Q.value=1;const r=t.createGain();return r.gain.value=0,i.connect(s),n.connect(s),s.connect(r).connect(this.output(t)),i.start(),n.start(),{key:e,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(t,e){const i=t.createOscillator();i.type="sine";const n=t.createOscillator();n.type="sine",n.frequency.value=5;const s=t.createGain(),r=t.createGain();return r.gain.value=0,n.connect(s).connect(i.frequency),i.connect(r).connect(this.output(t)),i.start(),n.start(),{key:e,nodes:[s,r],sources:[i,n],volumeParam:r.gain,gainScale:.22,pitch:[{param:i.frequency,ratio:1},{param:s.gain,ratio:.012}]}}buildRumble(t,e){const i=t.createBufferSource();i.buffer=this.brownNoise(t),i.loop=!0;const n=t.createBiquadFilter();n.type="lowpass",n.Q.value=.8;const s=t.createGain();return s.gain.value=0,i.connect(n).connect(s).connect(this.output(t)),i.start(),{key:e,nodes:[n,s],sources:[i],volumeParam:s.gain,gainScale:1.4,pitch:[{param:n.frequency,ratio:1}]}}buildCrackle(t,e){const i=t.createBufferSource();i.buffer=this.whiteNoise(t),i.loop=!0;const n=t.createBiquadFilter();n.type="bandpass",n.Q.value=1.2;const s=t.createGain();s.gain.value=0;const r=t.createBufferSource();r.buffer=this.crackleEnvelope(t),r.loop=!0;const o=t.createGain();return o.gain.value=0,r.connect(o).connect(s.gain),i.connect(n).connect(s).connect(this.output(t)),i.start(),r.start(),{key:e,nodes:[n,s,o],sources:[i,r],volumeParam:o.gain,gainScale:.9,pitch:[{param:n.frequency,ratio:4}]}}async buildRecordedVoice(t,e,i){const n=this.context;if(!n)return;let s;try{s=await this.getBuffer(t)}catch(c){console.warn("SightingAudio: the recorded sound failed to load, staying silent:",c);return}if(i!==this.voiceToken||!this.context)return;const r=n.createBufferSource();r.buffer=s,r.loop=!0;const o=n.createGain();o.gain.value=0,r.connect(o).connect(this.output(n)),r.start(),this.voice={key:e,nodes:[o],sources:[r],volumeParam:o.gain,gainScale:1,pitch:[]},this.requested&&this.applyTo(this.voice,this.requested)}async getBuffer(t){const e=this.context;if(!e)throw new Error("SightingAudio: AudioContext not ready — resume() must be called first");let i=this.buffers.get(t);return i||(i=fetch(t).then(n=>{if(!n.ok)throw new Error(`Audio fetch failed (${n.status}): ${t}`);return n.arrayBuffer()}).then(n=>e.decodeAudioData(n)),this.buffers.set(t,i)),i}whiteNoise(t){if(!this.noiseBuffer){const e=t.createBuffer(1,Math.floor(t.sampleRate*Wf),t.sampleRate),i=e.getChannelData(0);for(let n=0;n<i.length;n++)i[n]=Math.random()*2-1;this.noiseBuffer=e}return this.noiseBuffer}brownNoise(t){const e=t.createBuffer(1,Math.floor(t.sampleRate*Wf),t.sampleRate),i=e.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 e}crackleEnvelope(t){if(!this.crackleBuffer){const e=t.createBuffer(1,Math.floor(t.sampleRate*Xf),t.sampleRate),i=e.getChannelData(0),n=Math.max(1,Math.floor(m2*t.sampleRate)),s=Math.round(Xf*p2);for(let r=0;r<s;r++){const o=Math.floor(Math.random()*i.length),c=.4+Math.random()*.6;for(let l=0;l<n&&o+l<i.length;l++)i[o+l]=Math.max(i[o+l],c*(1-l/n))}this.crackleBuffer=e}return this.crackleBuffer}stopVoice(){const t=this.voice,e=this.context;if(this.voice=void 0,!t||!e)return;const i=e.currentTime;t.volumeParam.cancelScheduledValues(i),t.volumeParam.setTargetAtTime(0,i,Vf/3);const n=i+Vf;for(const s of t.sources){s.onended=()=>{s.disconnect();for(const r of t.nodes)r.disconnect()};try{s.stop(n)}catch{s.disconnect();for(const r of t.nodes)r.disconnect()}}}}class Vt{static svg(t){return`<svg viewBox="0 0 24 24" width="1.5em" height="1.5em" aria-hidden="true" focusable="false"><path d="${t}" fill="currentColor"/></svg>`}static outline(t){return`<svg viewBox="0 0 24 24" width="1.5em" height="1.5em" aria-hidden="true" focusable="false"><path d="${t}" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linejoin="round" stroke-linecap="round"/></svg>`}static solid(t){return`<svg viewBox="0 0 24 24" width="1.5em" height="1.5em" aria-hidden="true" focusable="false"><path d="${t}" 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=Vt.outline(Vt.BOOKMARK);static MILESTONES_ON=Vt.solid(Vt.BOOKMARK);static PICTURES_OFF=Vt.outline(`${Vt.PICTURE}${Vt.PICTURE_HILLS}`);static PICTURES_ON=Vt.solid(`${Vt.PICTURE}${Vt.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=Vt.outline(`${Vt.TRACE_LINE}${Vt.TRACE_MARK}`);static TRACES_ON=Vt.solid(`${Vt.TRACE_LINE}${Vt.TRACE_MARK}`);static MAP_OFF=Vt.outline(`${Vt.PIN}${Vt.PIN_HOLE}`);static MAP_ON=Vt.solid(`${Vt.PIN}${Vt.PIN_HOLE}`);static SHARE=Vt.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=Vt.svg("M15.4 7.4 14 6l-6 6 6 6 1.4-1.4L10.8 12z");static UNFOLDED=Vt.svg("M8.6 16.6 10 18l6-6-6-6-1.4 1.4 4.6 4.6z");static PLAY=Vt.svg("M7.4 5v14l11-7z");static PAUSE=Vt.svg("M6 5h4v14H6zM14 5h4v14h-4z");static VOLUME=Vt.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=Vt.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=Vt.svg("M5 5h5v2H7v3H5V5zm9 0h5v5h-2V7h-3V5zM5 14h2v3h3v2H5v-5zm12 0h2v5h-5v-2h3v-3z");static EXIT_FULLSCREEN=Vt.svg("M8 5h2v5H5V8h3V5zm6 0h2v3h3v2h-5V5zM5 14h5v5H8v-3H5v-2zm9 0h5v2h-3v3h-2v-5z")}function Bo(a){return[...a].sort((t,e)=>t.t-e.t)}function Ah(a,t){let e;for(const i of Bo(a)){if(i.t>t)break;e=i}return e}const Th=Math.PI/180,wc=180/Math.PI;class Ls{constructor(t,e,i){this.kind=t,this.canvasHeightPx=e,this.fovDeg=i;const n=i*Th/2;this.focalPx=t==="equidistant"?e/2/n:e/2/Math.tan(n)}focalPx;static of(t,e,i){return new Ls(t.projection,e,i)}degToPx(t){const e=t*Th;return this.kind==="equidistant"?this.focalPx*e:2*this.focalPx*Math.tan(e/2)}pxToDeg(t){return this.kind==="equidistant"?t/this.focalPx*wc:2*Math.atan(t/(2*this.focalPx))*wc}angleDegToRadiusPx(t){const e=t*Th;return this.kind==="equidistant"?this.focalPx*e:this.focalPx*Math.tan(e)}halfWidthAngleDeg(t){return this.radiusPxToAngleDeg(this.canvasHeightPx*t/2)}radiusPxToAngleDeg(t){return this.kind==="equidistant"?t/this.focalPx*wc:Math.atan(t/this.focalPx)*wc}ofBounds(t){return{widthDeg:this.pxToDeg(t.width),heightDeg:this.pxToDeg(t.height)}}toBoundsSize(t){return{width:this.degToPx(t.widthDeg),height:this.degToPx(t.heightDeg)}}widthPx(t){return this.degToPx(Ie.angularWidthDeg(t))}}class an{static fovOf(t,e){return Je(t,e)?.fovDeg??mi.fieldOfViewDeg(t.instrument)}static toAngular(t){this.eachKeyframe(t,(e,i)=>({...e,angular:i.ofBounds(e.bounds)}))}static toBounds(t){this.eachKeyframe(t,(e,i)=>{if(!e.angular)return e;const{width:n,height:s}=i.toBoundsSize(e.angular),r={x:e.bounds.x+(e.bounds.width-n)/2,y:e.bounds.y+(e.bounds.height-s)/2,width:n,height:s};if(e.kind!=="polygon")return{...e,bounds:r};const o=e.bounds.width===0?1:n/e.bounds.width,c=e.bounds.height===0?1:s/e.bounds.height;return{...e,bounds:r,points:e.points.map(l=>({x:l.x*o,y:l.y*c}))}})}static toAim(t){this.eachKeyframe(t,(e,i,n)=>{const s=e.aim&&this.positionOf(t,e.aim,e.bounds,i,n);if(s&&Math.abs(s.x-e.bounds.x)<an.UNMOVED_PX&&Math.abs(s.y-e.bounds.y)<an.UNMOVED_PX)return e;const r=this.aimFrom(t,i,n,e.bounds);return r?{...e,aim:r}:e})}static UNMOVED_PX=.01;static aimOf(t,e,i){const n=Ls.of(t.instrument,Ie.CANVAS_HEIGHT_PX,this.fovOf(t,e));return this.aimFrom(t,n,Je(t,e),i)}static aimFrom(t,e,i,n){if(i?.headingDeg===void 0)return;const s=this.frameCentre(t),r=e.radiusPxToAngleDeg(n.x+n.width/2-s.x),o=e.radiusPxToAngleDeg(s.y-(n.y+n.height/2));return{azimuthDeg:((i.headingDeg+r)%360+360)%360,altitudeDeg:i.pitchDeg+o}}static toPosition(t){this.eachKeyframe(t,(e,i,n)=>{const s=e.aim&&this.positionOf(t,e.aim,e.bounds,i,n);return s?{...e,bounds:{...e.bounds,...s}}:e})}static positionOf(t,e,i,n,s){if(s?.headingDeg===void 0)return;const r=this.frameCentre(t),o=this.shortestArc(e.azimuthDeg-s.headingDeg),c=e.altitudeDeg-s.pitchDeg;return{x:r.x+this.offAxisPx(n,o)-i.width/2,y:r.y-this.offAxisPx(n,c)-i.height/2}}static frameCentre(t){return{x:mi.frameWidthPx(t.instrument,Ie.CANVAS_HEIGHT_PX)/2,y:Ie.CANVAS_HEIGHT_PX/2}}static shortestArc(t){return(t%360+540)%360-180}static offAxisPx(t,e){return Math.abs(e)>=an.OFF_CANVAS_DEG?Math.sign(e)*an.OFF_CANVAS_PX:t.angleDegToRadiusPx(e)}static OFF_CANVAS_DEG=89;static OFF_CANVAS_PX=1e5;static reproject(t,e,i){const n=mi.frameWidthPx(e,Ie.CANVAS_HEIGHT_PX)/2,s=mi.frameWidthPx(t.instrument,Ie.CANVAS_HEIGHT_PX)/2,r=Ie.CANVAS_HEIGHT_PX/2;for(const o of[...t.timeline.allKeyframes]){const c=this.fovOf(t,o.t),l=i?.get(o.t)??c,h=Ls.of(e,Ie.CANVAS_HEIGHT_PX,l),u=Ls.of(t.instrument,Ie.CANVAS_HEIGHT_PX,c);t.timeline.addKeyframe(o.t,o.shapes.map(d=>{const{bounds:f}=d.shape,p=f.x+f.width/2-n,v=f.y+f.height/2-r,m=Math.hypot(p,v),g=m===0?1:u.angleDegToRadiusPx(h.radiusPxToAngleDeg(m))/m,S={...f,x:s+p*g-f.width/2,y:r+v*g-f.height/2};return{...d,shape:{...d.shape,bounds:S}}}))}this.toBounds(t)}static eachKeyframe(t,e){const{timeline:i}=t;for(const n of[...i.allKeyframes]){const s=Je(t,n.t),r=this.fovOf(t,n.t),o=Ls.of(t.instrument,Ie.CANVAS_HEIGHT_PX,r);i.addKeyframe(n.t,n.shapes.map(c=>({...c,shape:e(c.shape,o,s)})))}}}function v2(a){return Dn.restore(M2(a),a.provenance)}function M2(a){return an.toAngular(a),an.toAim(a),{version:1,id:a.id,time:a.event.time,endTime:a.event.endTime,durationSeconds:a.event.durationSeconds,durationText:a.event.durationText,utcOffsetHours:a.event.utcOffsetHours,timeZone:a.event.timeZone,place:a.event.place,observer:a.observer,account:a.account,sources:a.sources?.length?a.sources:void 0,sway:a.sway,vehicle:a.vehicle,description:a.event.description,tags:a.event.tags,timeline:a.timeline.toJSON(),observerTrack:a.observerTrack.toJSON(),weatherTrack:a.weatherTrack.toJSON(),soundTrack:a.soundTrack.toJSON(),weather:a.weather,decor:a.decor,milestones:a.milestones.length>0?a.milestones:void 0,references:a.references.length>0?a.references:void 0,roads:a.roads.length>0?a.roads:void 0,traces:a.traces.length>0?a.traces:void 0,weatherSource:a.weatherSource,instrument:a.instrumentId,exposureSeconds:a.exposureSeconds,iso:a.iso,lightPollution:a.lightPollution,observerMap:a.observerMap,interpretation:a.interpretation}}function x2(a){const{recording:t,provenance:e}=Dn.strip(a),i=y2(t);return i.provenance=e,i}function y2(a){const t=[],e=new hh({eventType:"sighting",time:a.time,endTime:a.endTime,durationSeconds:a.durationSeconds,durationText:a.durationText,utcOffsetHours:a.utcOffsetHours,timeZone:a.timeZone,place:a.place,description:a.description,tags:a.tags},lh.fromJSON(a.timeline,t),a.observerTrack?jo.fromJSON(a.observerTrack):new jo,a.weatherTrack?Qo.fromJSON(a.weatherTrack):new Qo,a.soundTrack?tc.fromJSON(a.soundTrack):new tc,a.observer&&{id:a.observer.id,title:a.observer.title,lastName:a.observer.lastName,firstNames:a.observer.firstNames},a.id,a.weather,a.decor??[],a.weatherSource,a.instrument,a.exposureSeconds??a.observerTrack?.keyframes.map(i=>i.pose.exposureSeconds).find(i=>i!==void 0),Bo(a.milestones??[]),a.references??[],a.roads??[],a.traces??[]);return e.account=a.account,e.sources=a.sources,e.sway=a.sway,e.iso=a.iso,e.lightPollution=a.lightPollution,e.observerMap=a.observerMap,e.vehicle=a.vehicle,e.interpretation=a.interpretation,e.loadIssues=t,an.toBounds(e),an.toPosition(e),e}class Za{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(t,e=Za.EN){return e[t.kind].replace("{path}",t.path).replace("{expected}",t.expected??"").replace("{found}",t.found??"")}static warn(t,e){if(t.length===0)return;const i=t.map(n=>` ${Za.text(n)}`);console.warn(`UFO@home: ${t.length} problem(s) in ${e??"this recording"}:
1409
+ `,xc=[{id:"eye",name:"Naked eye",flare:0,projection:"equidistant",stabilization:.97},{id:"rectilinear-lens",name:"Camera, unknown device",projection:"rectilinear",fNumber:8,fNumberRange:{min:2,max:22},exposureSeconds:1/250,exposureRangeSeconds:{min:1/1e3,max:8},apertureBlades:6},{id:"roamer-1-120",name:"Roamer 1, 120 film",projection:"rectilinear",frame:{widthMm:74,heightMm:60,focalLengthMm:100},fNumber:11,exposureSeconds:1/50,years:{from:1930,to:1965},detailUm:40,medium:{kind:"negative",iso:125}},{id:"instamatic-126",name:"Instamatic, 126 film",projection:"rectilinear",frame:{widthMm:28,heightMm:28,focalLengthMm:43},fNumber:11,exposureSeconds:1/90,years:{from:1963,to:1988},apertureBlades:5,detailUm:20,medium:{kind:"negative",iso:64}},{id:"slr-35mm-50",name:"35 mm SLR, 50 mm lens",projection:"rectilinear",frame:{widthMm:36,heightMm:24,focalLengthMm:50},fNumber:8,fNumberRange:{min:2,max:16},exposureSeconds:1/250,exposureRangeSeconds:{min:1/1e3,max:3600},years:{from:1959},apertureBlades:6,detailUm:20,medium:{kind:"negative",iso:100}},{id:"slr-35mm-zoom",name:"35 mm SLR, 70-210 mm zoom",projection:"rectilinear",frame:{widthMm:36,heightMm:24,focalLengthMm:135,focalRangeMm:{minMm:70,maxMm:210}},fNumber:8,fNumberRange:{min:4,max:22},exposureSeconds:1/250,exposureRangeSeconds:{min:1/1e3,max:3600},apertureBlades:8,years:{from:1975},detailUm:20,medium:{kind:"negative",iso:100}},{id:"phone-landscape",name:"Phone, held sideways",projection:"rectilinear",frame:{widthMm:7.6,heightMm:5.7,focalLengthMm:5.7},fNumber:1.8,exposureSeconds:1/120,exposureRangeSeconds:{min:1/8e3,max:10},years:{from:2007},apertureBlades:void 0,detailUm:1.4,medium:{kind:"sensor",iso:100,autoExposure:!0}},{id:"phone-portrait",name:"Phone, held upright",projection:"rectilinear",frame:{widthMm:5.7,heightMm:7.6,focalLengthMm:5.7},fNumber:1.8,exposureSeconds:1/120,exposureRangeSeconds:{min:1/8e3,max:10},years:{from:2007},apertureBlades:void 0,detailUm:1.4,medium:{kind:"sensor",iso:100,autoExposure:!0}}];class mi{static get default(){return xc[0]}static byId(t){return xc.find(e=>e.id===t)??this.default}static UNAIDED_FIELD_DEG=60;static UNAIDED_ASPECT=16/9;static fieldOfViewDeg(t){const e=t.frame;return e?2*Math.atan(e.heightMm/(2*e.focalLengthMm))*180/Math.PI:mi.UNAIDED_FIELD_DEG}static aspectOf(t){const e=t.frame;return e?e.widthMm/e.heightMm:mi.UNAIDED_ASPECT}static frameWidthPx(t,e){return Math.round(e*mi.aspectOf(t))}static availableAt(t){return t===void 0?xc:xc.filter(e=>!e.years||t>=e.years.from&&(e.years.to===void 0||t<=e.years.to))}static fieldOfViewDegAt(t,e){const i=t.frame;if(!(!i||e<=0))return 2*Math.atan(i.heightMm/(2*e))*180/Math.PI}static focalLengthMmFor(t,e){const i=t.frame;if(!(!i||e<=0||e>=180))return i.heightMm/(2*Math.tan(e*Math.PI/360))}static bladesShowing(t,e){const i=e??t.fNumber;if(i===void 0||t.apertureBlades===void 0)return 0;const n=t.fNumberRange;return!n||n.max<=n.min?1:Math.max(0,Math.min(1,(i-n.min)/(n.max-n.min)))}static LENS_FLARE_ARTIFACTS=1;static flareArtifactsOf(t){return t.flare??mi.LENS_FLARE_ARTIFACTS}static starPointsOf(t){const e=t.apertureBlades;return e===void 0||e<3?0:e%2===0?e:e*2}}class Fa{constructor(t){this.points=t}static STATIONARY_M=5;static of(t){const e=[];for(const i of t.observerTrack.allKeyframes){const{lat:n,lng:s,headingDeg:r}=i.pose;n===void 0||s===void 0||e.push({t:i.t,lat:n,lng:s,headingDeg:r})}if(e.length===0){const i=t.event.place?.[0];if(!i)return;e.push({t:0,lat:i.lat,lng:i.lng})}return new Fa(e)}static TRAVEL_M=50;get travels(){return this.spanM>Fa.TRAVEL_M}get moved(){return this.spanM>Fa.STATIONARY_M}get spanM(){const t=this.box,e=(t.south+t.north)/2,i=(t.west+t.east)/2;return Math.max(Math.abs(je(e,t.east,e,t.west).x),Math.abs(je(t.north,i,t.south,i).z))}get center(){const t=this.box;return{lat:(t.south+t.north)/2,lng:(t.west+t.east)/2}}boundsAround(t,e){const{lat:i,lng:n}=this.center,s=Math.max(this.spanM*(1+e),t)/2;return{north:Sn(0,-s,i,n).lat,south:Sn(0,s,i,n).lat,east:Sn(s,0,i,n).lng,west:Sn(-s,0,i,n).lng}}get box(){const t=this.points.map(i=>i.lat),e=this.points.map(i=>i.lng);return{south:Math.min(...t),north:Math.max(...t),west:Math.min(...e),east:Math.max(...e)}}}class An{constructor(t,e){this.rotationPassed=t,this.scale=e}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(t){const e=t.event.tags?.includes("paralysis")||(t.exposure??0)>An.HAND_HELD_S,i=t.sway??(e?0:1);if(i>0)return new An(Math.max(1-(t.instrument.stabilization??0),An.GAZE_DRIFT_SHARE),i)}offsetAt(t){const e=t/1e3,i=this.scale,n=(u,d)=>Math.sin(2*Math.PI*u*e+d),[s,r,o,c,l,h]=An.HZ;return{eastM:i*An.SWAY_M*(.7*n(s,.3)+.3*n(c,1.9)),northM:i*An.SWAY_M*(.6*n(o,2.2)+.4*n(l,.8)),upM:i*An.BREATH_M*n(r,0),yawDeg:i*this.rotationPassed*An.DRIFT_YAW_DEG*(.6*n(h,1.1)+.4*n(c,2.7)),pitchDeg:i*this.rotationPassed*An.DRIFT_PITCH_DEG*(.5*n(r,1.6)+.5*n(o,.4)),rollDeg:i*this.rotationPassed*An.DRIFT_ROLL_DEG*n(s,2.9)}}}class be{constructor(t,e){this.stretches=t,this.rotationPassed=e}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(t){const e=Fa.of(t);if(!e||e.points.length<2)return;const i=[];let n=0;for(let s=1;s<e.points.length;s++){const r=e.points[s-1],o=e.points[s],c=(o.t-r.t)/1e3;if(c<=0)continue;const l=je(o.lat,o.lng,r.lat,r.lng),h=l.x,u=-l.z,d=Math.hypot(h,u),f=d/c,p=be.stepHzFor(f);i.push({startMs:r.t,endMs:o.t,speedMPerS:f,eastUnit:d>0?h/d:0,northUnit:d>0?u/d:0,stepHz:p,stepsBefore:n,rampsIn:!0,rampsOut:!0}),n+=p*c}for(let s=0;s<i.length;s++){const r=i[s-1],o=i[s+1];i[s].rampsIn=r===void 0||r.stepHz===0,i[s].rampsOut=o===void 0||o.stepHz===0}if(i.some(s=>s.stepHz>0))return new be(i,1-(t.instrument.stabilization??0))}static bodyAt(t,e,i=!1){const n=be.of(t)?.offsetAt(e)??be.STILL;return i?n:be.add(n,An.of(t)?.offsetAt(e))}static stepHzFor(t){return t<be.SLOWEST_WALK_M_PER_S||t>be.FASTEST_WALK_M_PER_S?0:be.REFERENCE_STEP_HZ*Math.pow(t/be.REFERENCE_SPEED_M_PER_S,be.CADENCE_EXPONENT)}offsetAt(t){return be.add(this.cycleAt(t),this.joltAt(t))}joltAt(t){for(const e of this.stretches){if(e.stepHz===0)continue;const i=e.speedMPerS/be.REFERENCE_SPEED_M_PER_S,n=(o,c,l,h)=>{if(o<0||o>be.JOLT_LASTS_MS)return;const u=o/1e3,d=Math.exp(-u/be.JOLT_DECAY_S)*Math.sin(2*Math.PI*be.JOLT_HZ*u),f=h*c*i*d;return{eastM:f*e.eastUnit,northM:f*e.northUnit,upM:-Math.abs(f)*.3,rollDeg:0,pitchDeg:-h*l*i*d*this.rotationPassed,yawDeg:0}},s=e.rampsOut?n(t-e.endMs,be.STOP_LURCH_M,be.STOP_PITCH_DEG,1):void 0;if(s)return s;const r=e.rampsIn?n(t-e.startMs,be.START_LURCH_M,be.START_PITCH_DEG,-1):void 0;if(r)return r}}static add(t,e){return e?{eastM:t.eastM+e.eastM,northM:t.northM+e.northM,upM:t.upM+e.upM,rollDeg:t.rollDeg+e.rollDeg,pitchDeg:t.pitchDeg+e.pitchDeg,yawDeg:t.yawDeg+e.yawDeg}:t}cycleAt(t){const e=this.stretches.find(c=>t>=c.startMs&&t<=c.endMs);if(!e||e.stepHz===0)return be.STILL;const i=e.stepsBefore+e.stepHz*(t-e.startMs)/1e3,n=2*Math.PI*i,s=this.amplitudeAt(e,t),r=be.SWAY_M*s*Math.cos(n/2),o=s*this.rotationPassed*e.speedMPerS/be.REFERENCE_SPEED_M_PER_S;return{eastM:r*e.northUnit,northM:-r*e.eastUnit,upM:be.RISE_M_PER_M_PER_S*e.speedMPerS*s*Math.cos(n),rollDeg:be.HEAD_ROLL_DEG*o*Math.cos(n/2),pitchDeg:-1.25*o*Math.cos(n),yawDeg:be.HEAD_YAW_DEG*o*Math.cos(n/2)}}amplitudeAt(t,e){const i=1e3/t.stepHz,n=Math.min(i,(t.endMs-t.startMs)/2);if(n<=0)return 1;const s=e-t.startMs,r=t.endMs-e,o=Math.min(t.rampsIn?s/n:1,t.rampsOut?r/n:1,1);return(1-Math.cos(Math.PI*Math.max(o,0)))/2}}class zo{static ISO=/^P(?:(\d+(?:[.,]\d+)?)W)?(?:(\d+(?:[.,]\d+)?)D)?(?:T(?:(\d+(?:[.,]\d+)?)H)?(?:(\d+(?:[.,]\d+)?)M)?(?:(\d+(?:[.,]\d+)?)S)?)?$/;static seconds(t){const e=t.trim().toUpperCase(),i=zo.ISO.exec(e);if(!i||e==="P"||e.endsWith("T"))return;const[,n,s,r,o,c]=i,l=u=>u===void 0?0:Number(u.replace(",",".")),h=l(n)*604800+l(s)*86400+l(r)*3600+l(o)*60+l(c);return Number.isFinite(h)?h:void 0}static parse(t){let e=t.trim();if(e==="")return;const i=e.slice(-1),n="?~%".includes(i)?i:"";n!==""&&(e=e.slice(0,-1).trim());const s=e.split("/");if(s.length>2)return;const r=s.map(u=>zo.seconds(u));if(r.some(u=>u===void 0))return;const[o,c]=r,l=Math.min(o,c??o),h=Math.max(o,c??o);return{doubt:n,minSeconds:l,maxSeconds:h,chosenSeconds:(l+h)/2}}static isExact(t){const e=zo.parse(t);return e!==void 0&&e.doubt===""&&e.minSeconds===e.maxSeconds}static format(t){const e=Math.max(0,Math.round(t*10)/10),i=Math.floor(e/3600),n=Math.floor(e%3600/60),s=Math.round(e%60*10)/10;return`PT${`${i>0?`${i}H`:""}${n>0?`${n}M`:""}${s>0||i===0&&n===0?`${s}S`:""}`}`}static say(t){const e=Math.round(t*10)/10;if(e<60)return`${e} s`;const i=Math.floor(e/3600),n=Math.floor(e%3600/60),s=Math.round(e%60*10)/10,r=[];return i>0&&r.push(`${i} h`),n>0&&r.push(`${n} min`),s>0&&r.push(`${s} s`),r.join(" ")}}class Ie{static MOON_ANGULAR_WIDTH_DEG=.5237;static CANVAS_WIDTH_PX=640;static CANVAS_HEIGHT_PX=360;static angularWidthDeg(t){return 2*Math.atan(t.sizeM/(2*t.distanceM))*180/Math.PI}static inMoons(t){return t/Ie.MOON_ANGULAR_WIDTH_DEG}static lerpAngular(t,e,i){if(!(!t||!e))return{widthDeg:t.widthDeg+(e.widthDeg-t.widthDeg)*i,heightDeg:t.heightDeg+(e.heightDeg-t.heightDeg)*i}}static sizeMAt(t,e){return 2*t*Math.tan(e*Math.PI/360)}static distanceMAt(t,e){return t/(2*Math.tan(e*Math.PI/360))}}function Vv(a,t,e){if(!a||!t)return e<1?a:t;const i=((t.azimuthDeg-a.azimuthDeg)%360+540)%360-180;return{azimuthDeg:((a.azimuthDeg+i*e)%360+360)%360,altitudeDeg:a.altitudeDeg+(t.altitudeDeg-a.altitudeDeg)*e}}function Wv(a,t,e){const{bounds:i}=a;return t>=i.x&&t<=i.x+i.width&&e>=i.y&&e<=i.y+i.height}function nn(a,t,e){return a+(t-a)*e}function Lf(a){const t=/^#([0-9a-f]{6})$/i.exec(a);if(!t)return;const e=parseInt(t[1],16);return[e>>16&255,e>>8&255,e&255]}function Xv(a){return`#${a.map(t=>Math.round(t).toString(16).padStart(2,"0")).join("")}`}function Yv(a,t,e){const i=Lf(a),n=Lf(t);return!i||!n?e<1?a:t:Xv([nn(i[0],n[0],e),nn(i[1],n[1],e),nn(i[2],n[2],e)])}function qv(a,t,e){const i={x:nn(a.bounds.x,t.bounds.x,e),y:nn(a.bounds.y,t.bounds.y,e),width:nn(a.bounds.width,t.bounds.width,e),height:nn(a.bounds.height,t.bounds.height,e)},n=nn(a.angle,t.angle,e),s=nn(a.transparency,t.transparency,e),r=nn(a.haloScale,t.haloScale,e),o=nn(a.blur??0,t.blur??0,e),c=nn(a.brightness??0,t.brightness??0,e),l=Yv(a.color,t.color,e),h=Ie.lerpAngular(a.angular,t.angular,e),u=Vv(a.aim,t.aim,e);return a.kind==="polygon"&&t.kind==="polygon"&&a.points.length===t.points.length?{...a,bounds:i,angle:n,transparency:s,haloScale:r,blur:o,brightness:c,color:l,angular:h,aim:u,points:a.points.map((d,f)=>({x:nn(d.x,t.points[f].x,e),y:nn(d.y,t.points[f].y,e)}))}:{...e<1?a:t,bounds:i,angle:n,transparency:s,haloScale:r,blur:o,brightness:c,color:l,angular:h,aim:u}}class Tr{static DEFAULT_COLOR="#e8e6df";static complete(t,e=[]){const i=new Map;return t.map((n,s)=>({keyframe:n,index:s})).sort((n,s)=>n.keyframe.t-s.keyframe.t).map(({keyframe:n,index:s})=>({t:n.t,shapes:(n.shapes??[]).map((r,o)=>{const c=`timeline.keyframes.${s}.shapes.${o}.shape`,l=Tr.completed(r,i.get(r.sourceId),c,e);return i.set(r.sourceId,l),{sourceId:r.sourceId,shape:l}})}))}static completed(t,e,i,n){const s=t.shape??{},r=e??Tr.firstAppearance(s,i,n),o={...r};s.bounds&&e&&(e.aim||e.angular)&&!s.aim&&!s.angular&&n.push({kind:"pixels-over-angles",path:i}),s.bounds&&(s.aim||delete o.aim,s.angular||delete o.angular);const c=s.kind??r.kind??"oval",l={...o,...s,kind:c};if(c==="polygon"&&!l.points){n.push({kind:"defaulted",path:`${i}.points`,expected:"rectangle"});const{width:h,height:u}=l.bounds;return{...l,points:[{x:0,y:0},{x:h,y:0},{x:h,y:u},{x:0,y:u}]}}return l}static firstAppearance(t,e,i){return t.kind||i.push({kind:"defaulted",path:`${e}.kind`,expected:'"oval"'}),t.color||i.push({kind:"defaulted",path:`${e}.color`,expected:`"${Tr.DEFAULT_COLOR}"`}),!t.bounds&&!t.aim&&i.push({kind:"unplaced",path:e}),!t.bounds&&!t.angular&&i.push({kind:"unsized",path:e}),{kind:t.kind??"oval",bounds:{...Tr.NEUTRAL_BOUNDS},color:Tr.DEFAULT_COLOR,angle:0,transparency:0,haloScale:0,selected:!1}}static NEUTRAL_BOUNDS={x:Ie.CANVAS_WIDTH_PX/2,y:Ie.CANVAS_HEIGHT_PX/2,width:1,height:1}}class lh{keyframes=[];order=[];groups=[];addKeyframe(t,e){const i=this.findInsertIndex(t);if(this.keyframes[i]?.t===t){const n=new Set(e.map(s=>s.sourceId));this.keyframes[i]={t,shapes:[...this.keyframes[i].shapes.filter(s=>!n.has(s.sourceId)),...e]}}else this.keyframes.splice(i,0,{t,shapes:[...e]});for(const n of e)this.order.includes(n.sourceId)||this.order.push(n.sourceId)}findInsertIndex(t){let e=0,i=this.keyframes.length;for(;e<i;){const n=e+i>>>1;this.keyframes[n].t<t?e=n+1:i=n}return e}getKeyframeAt(t){const e=this.findInsertIndex(t),i=this.keyframes[e];return i?.t===t?i:void 0}getShapeAt(t,e){return this.getKeyframeAt(t)?.shapes.find(i=>i.sourceId===e)?.shape}getLatestShapeAt(t,e){let i=this.findInsertIndex(t);for(this.keyframes[i]?.t!==t&&(i-=1);i>=0;i--){const n=this.keyframes[i].shapes.find(s=>s.sourceId===e);if(n)return n.shape}}getInterpolatedShapeAt(t,e){const i=this.findShapeAtOrBefore(t,e);if(i?.t===t)return i.shape;const n=this.findShapeAtOrAfter(t,e);return i?n?qv(i.shape,n.shape,(t-i.t)/(n.t-i.t)):i.shape:n?.shape}findShapeAtOrBefore(t,e){let i=this.findInsertIndex(t);for(this.keyframes[i]?.t!==t&&(i-=1);i>=0;i--){const n=this.keyframes[i].shapes.find(s=>s.sourceId===e);if(n)return{t:this.keyframes[i].t,shape:n.shape}}}findShapeAtOrAfter(t,e){for(let i=this.findInsertIndex(t);i<this.keyframes.length;i++){const n=this.keyframes[i].shapes.find(s=>s.sourceId===e);if(n)return{t:this.keyframes[i].t,shape:n.shape}}}hitTest(t,e,i,n){const s=this.sourceIds;for(let r=s.length-1;r>=0;r--){if(n?.has(s[r]))continue;const o=this.getInterpolatedShapeAt(t,s[r]);if(o&&Wv(o,e,i))return{sourceId:s[r],shape:o}}}removeSource(t){for(let e=this.keyframes.length-1;e>=0;e--){const i=this.keyframes[e].shapes.filter(n=>n.sourceId!==t);i.length===0?this.keyframes.splice(e,1):i.length!==this.keyframes[e].shapes.length&&(this.keyframes[e]={t:this.keyframes[e].t,shapes:i})}this.order=this.order.filter(e=>e!==t),this.removeFromGroup(t)}group(t){if(!(t.length<2)){for(const e of t)this.removeFromGroup(e);this.groups.push([...t])}}ungroup(t){const e=this.groups.findIndex(i=>i.includes(t));e!==-1&&this.groups.splice(e,1)}groupMembers(t){return this.groups.find(e=>e.includes(t))}removeFromGroup(t){const e=this.groups.findIndex(n=>n.includes(t));if(e===-1)return;const i=this.groups[e].filter(n=>n!==t);i.length<2?this.groups.splice(e,1):this.groups[e]=i}bringToFront(t){const e=this.order.indexOf(t);e!==-1&&(this.order.splice(e,1),this.order.push(t))}sendToBack(t){const e=this.order.indexOf(t);e!==-1&&(this.order.splice(e,1),this.order.unshift(t))}get duration(){return this.keyframes.length===0?0:this.keyframes[this.keyframes.length-1].t}get sourceIds(){return[...this.order]}get allKeyframes(){return this.keyframes}toJSON(){return{keyframes:this.keyframes,order:this.order,groups:this.groups}}static fromJSON(t,e){const i=new lh;for(const n of Tr.complete(t.keyframes??[],e))i.addKeyframe(n.t,n.shapes);if(t.order){const n=i.order.filter(s=>!t.order.includes(s));i.order=[...t.order,...n]}return t.groups&&(i.groups=t.groups.map(n=>n.filter(s=>i.order.includes(s))).filter(n=>n.length>=2)),i}}function $v(a,t,e){return Math.max(t,Math.min(e,a))}function Kv(a,t,e){const i=((t-a)%360+540)%360-180;return((a+i*e)%360+360)%360}function Qr(a,t,e){return a+(t-a)*e}function Zv(a,t,e){return{lat:a.lat===void 0||t.lat===void 0?void 0:Qr(a.lat,t.lat,e),lng:a.lng===void 0||t.lng===void 0?void 0:Qr(a.lng,t.lng,e),elevationM:Qr(a.elevationM,t.elevationM,e),headingDeg:a.headingDeg===void 0||t.headingDeg===void 0?void 0:Kv(a.headingDeg,t.headingDeg,e),pitchDeg:Qr(a.pitchDeg,t.pitchDeg,e),rollDeg:Qr(a.rollDeg??0,t.rollDeg??0,e),fovDeg:Qr(a.fovDeg,t.fovDeg,e),fNumber:a.fNumber,focusDistanceM:a.focusDistanceM}}class Br{static at(t,e,i,n,s){const r=t[i],c=t[i+1]-r;if(c<=0)return e[i];const l=Br.tangent(t,e,i,s),h=Br.tangent(t,e,i+1,s),u=(n-r)/c,d=u*u,f=d*u;return(2*f-3*d+1)*e[i]+(f-2*d+u)*c*l+(-2*f+3*d)*e[i+1]+(f-d)*c*h}static BRAKE_S=.8;static paced(t,e,i,n){if(!i&&!n)return t;const s=e>0?Math.min(.5,Br.BRAKE_S/e):.5;if(i&&n){const o=1/(1-s);return t<=s?o*t*t/(2*s):t>=1-s?1-o*(1-t)*(1-t)/(2*s):o*(t-s/2)}const r=o=>{const c=1/(1-s/2);if(o<=1-s)return c*o;const l=o-(1-s);return c*(1-s)+c*(l-l*l/(2*s))};return n?r(t):1-r(1-t)}static tangent(t,e,i,n){const s=t.length-1,r=f=>(e[f+1]-e[f])/(t[f+1]-t[f]||1);if(i===0)return n?0:r(0);if(i===s)return n?0:r(s-1);const o=r(i-1),c=r(i);if(o*c<=0)return 0;const l=t[i]-t[i-1],h=t[i+1]-t[i],u=2*h+l,d=h+2*l;return(u+d)/(u/o+d/c)}}class jo{keyframes=[];addKeyframe(t,e){const i=this.findInsertIndex(t);this.keyframes[i]?.t===t?this.keyframes[i]={t,pose:e}:this.keyframes.splice(i,0,{t,pose:e})}clear(){this.keyframes.length=0}removeKeyframeAt(t){const e=this.findInsertIndex(t);this.keyframes[e]?.t===t&&this.keyframes.splice(e,1)}findInsertIndex(t){let e=0,i=this.keyframes.length;for(;e<i;){const n=e+i>>>1;this.keyframes[n].t<t?e=n+1:i=n}return e}getLatestPoseAt(t){let e=this.findInsertIndex(t);return this.keyframes[e]?.t!==t&&(e-=1),e>=0?this.keyframes[e].pose:void 0}getInterpolatedPoseAt(t){const e=this.findInsertIndex(t),i=this.keyframes[e]?.t===t?this.keyframes[e]:this.keyframes[e-1];if(i?.t===t)return i.pose;const n=this.keyframes[e]?.t===t?void 0:this.keyframes[e];if(!i)return n?.pose;if(!n)return i.pose;const s=Zv(i.pose,n.pose,$v((t-i.t)/(n.t-i.t),0,1));return this.humanly(e-1,t,s)}humanly(t,e,i){const n=Math.max(0,t-1),s=Math.min(this.keyframes.length-1,t+2),r=this.keyframes.slice(n,s+1),o=t-n,c=r.map(x=>x.t),l=(x,M)=>{const b=r.map(w=>x(w.pose));if(!b.some(w=>w===void 0))return Br.at(c,b,o,e,M)},h=r.map(x=>x.pose.headingDeg);let u;if(h.every(x=>x!==void 0)){const x=[h[0]];for(let M=1;M<h.length;M++)x.push(x[M-1]+((h[M]-h[M-1])%360+540)%360-180);u=(Br.at(c,x,o,e,!0)%360+360)%360}const d=this.keyframes[t],f=this.keyframes[t+1],p=(x,M)=>x.lat===M.lat&&x.lng===M.lng&&x.elevationM===M.elevationM,v=!p(d.pose,f.pose),m=v&&t>0&&p(this.keyframes[t-1].pose,d.pose),g=v&&t+2<this.keyframes.length&&p(f.pose,this.keyframes[t+2].pose);let S;if(m||g){const x=Br.paced((e-d.t)/(f.t-d.t),(f.t-d.t)/1e3,m,g),M=(b,w)=>b===void 0||w===void 0?void 0:b+(w-b)*x;S={lat:M(d.pose.lat,f.pose.lat),lng:M(d.pose.lng,f.pose.lng),elevationM:M(d.pose.elevationM,f.pose.elevationM)}}return{...i,lat:S?S.lat:l(x=>x.lat,!1)??i.lat,lng:S?S.lng:l(x=>x.lng,!1)??i.lng,elevationM:S?S.elevationM:l(x=>x.elevationM,!1)??i.elevationM,headingDeg:u??i.headingDeg,pitchDeg:l(x=>x.pitchDeg,!0)??i.pitchDeg,rollDeg:l(x=>x.rollDeg??0,!0)??i.rollDeg,fovDeg:l(x=>x.fovDeg,!0)??i.fovDeg}}get duration(){return this.keyframes.length===0?0:this.keyframes[this.keyframes.length-1].t}get allKeyframes(){return this.keyframes}toJSON(){return{keyframes:this.keyframes}}static fromJSON(t){const e=new jo;for(const i of t.keyframes)e.addKeyframe(i.t,i.pose);return e}}class tr{static MAX_CHANGE_PER_S=.05;points;followed;constructor(t){let e="none",i=0;this.points=t.map(({t:n,weather:s})=>(s.precipitationType!=="none"&&(e=s.precipitationType,i=s.precipitationIntensity),{t:n,lastFalling:e,lastFallingIntensity:i,intensity:s.precipitationType==="none"?0:s.precipitationIntensity,type:s.precipitationType})),this.followed=[];for(let n=0;n<this.points.length;n++){if(n===0){this.followed.push(this.points[0].intensity);continue}const s=this.points[n-1],r=this.points[n];this.followed.push(tr.follow(this.followed[n-1],s.intensity,r.intensity,(r.t-s.t)/1e3,(r.t-s.t)/1e3))}}at(t){if(this.points.length===0||t<this.points[0].t)return;let e=this.points.length-1;for(;e>0&&this.points[e].t>t;)e--;const i=this.points[e],n=this.points[e+1],s=n?tr.follow(this.followed[e],i.intensity,n.intensity,(n.t-i.t)/1e3,(t-i.t)/1e3):tr.follow(this.followed[e],i.intensity,i.intensity,1,(t-i.t)/1e3);return{type:tr.typeBetween(i,n,t,s),intensity:s,character:tr.characterBetween(i,n,t)}}static characterBetween(t,e,i){return t.type==="none"?e&&e.type!=="none"?e.intensity:t.lastFallingIntensity:!e||e.type==="none"?t.intensity:t.intensity+(e.intensity-t.intensity)*(i-t.t)/(e.t-t.t||1)}static typeBetween(t,e,i,n){return t.type==="none"?e&&e.type!=="none"&&i>t.t?e.type:n>0?t.lastFalling:"none":e&&e.type==="none"&&n<=0?"none":t.type}static follow(t,e,i,n,s){const r=tr.MAX_CHANGE_PER_S,o=n>0?(i-e)/n:0,c=u=>e+o*Math.min(Math.max(u,0),n);let l=t,h=0;for(let u=0;u<8&&h<s;u++){const d=c(h)-l;if(Math.abs(d)<1e-9){const x=h<n?o:0;if(Math.abs(x)<=r){const b=h<n?Math.min(s,n):s;l=c(b),h=b;continue}const M=Math.min(s,n);l+=Math.sign(x)*r*(M-h),h=M;continue}const f=Math.sign(d),p=h<n?o:0,v=r-f*p,m=v>0?h+Math.abs(d)/v:1/0,g=h<n?n:1/0,S=Math.min(s,m,g);l+=f*r*(S-h),h=S,S===m&&(l=c(h))}return Math.min(1,Math.max(0,l))}}function He(a,t,e){return a+(t-a)*e}function E0(a,t,e){const i=((t-a)%360+540)%360-180;return((a+i*e)%360+360)%360}function Jv(a,t,e){return Math.max(t,Math.min(e,a))}function jv(a=[],t=[],e){if(!(!a.length&&!t.length))return[...new Set([...a.map(i=>i.id),...t.map(i=>i.id)])].map(i=>{const n=a.find(c=>c.id===i),s=t.find(c=>c.id===i),r=n??{...s,density:0},o=s??{...n,density:0};return{...r,eastM:He(r.eastM,o.eastM,e),northM:He(r.northM,o.northM,e),baseM:He(r.baseM,o.baseM,e),thicknessM:He(r.thicknessM,o.thicknessM,e),widthM:He(r.widthM,o.widthM,e),depthM:He(r.depthM,o.depthM,e),rotationDeg:E0(r.rotationDeg,o.rotationDeg,e),density:He(r.density,o.density,e),darkness:He(r.darkness??0,o.darkness??0,e)}})}function Qv(a,t,e){if(a.cloudLayers===void 0&&t.cloudLayers===void 0)return;const i=Ul(a),n=Ul(t);return e>=1?n.map(r=>({...r})):[...new Set([...i.map(r=>r.id),...n.map(r=>r.id)])].map(r=>{const o=i.find(u=>u.id===r),c=n.find(u=>u.id===r),l=o??{...c,coverage:0},h=c??{...o,coverage:0};return{...l,instances:jv(o?.instances,c?.instances,e),baseM:He(l.baseM,h.baseM,e),thicknessM:He(l.thicknessM,h.thicknessM,e),coverage:He(l.coverage,h.coverage,e),sizeM:He(l.sizeM,h.sizeM,e),density:He(l.density,h.density,e),darkness:He(l.darkness??a.cloudDarkness,h.darkness??t.cloudDarkness,e),iceCrystalAlignment:l.iceCrystalAlignment===void 0||h.iceCrystalAlignment===void 0?void 0:He(l.iceCrystalAlignment,h.iceCrystalAlignment,e),windSpeed:l.windSpeed===void 0&&h.windSpeed===void 0?void 0:He(l.windSpeed??a.windSpeed,h.windSpeed??t.windSpeed,e),windDirectionDeg:l.windDirectionDeg===void 0&&h.windDirectionDeg===void 0?void 0:E0(l.windDirectionDeg??a.windDirectionDeg,h.windDirectionDeg??t.windDirectionDeg,e)}})}function t2(a,t,e){return{cloudLayers:Qv(a,t,e),cloudCover:He(a.cloudCover,t.cloudCover,e),cloudDarkness:He(a.cloudDarkness,t.cloudDarkness,e),highCloudCover:a.highCloudCover===void 0||t.highCloudCover===void 0?void 0:He(a.highCloudCover,t.highCloudCover,e),iceCrystalAlignment:a.iceCrystalAlignment===void 0||t.iceCrystalAlignment===void 0?void 0:He(a.iceCrystalAlignment,t.iceCrystalAlignment,e),lowerCloudCover:a.lowerCloudCover===void 0||t.lowerCloudCover===void 0?void 0:He(a.lowerCloudCover,t.lowerCloudCover,e),cloudBaseM:a.cloudBaseM===void 0||t.cloudBaseM===void 0?void 0:He(a.cloudBaseM,t.cloudBaseM,e),relativeHumidity:a.relativeHumidity===void 0||t.relativeHumidity===void 0?void 0:He(a.relativeHumidity,t.relativeHumidity,e),precipitationType:e<1?a.precipitationType:t.precipitationType,precipitationIntensity:He(a.precipitationIntensity,t.precipitationIntensity,e),windDirectionDeg:E0(a.windDirectionDeg,t.windDirectionDeg,e),windSpeed:He(a.windSpeed,t.windSpeed,e),storm:e<1?a.storm:t.storm}}class Qo{keyframes=[];ramp;addKeyframe(t,e){this.ramp=void 0;const i=this.findInsertIndex(t);this.keyframes[i]?.t===t?this.keyframes[i]={t,weather:e}:this.keyframes.splice(i,0,{t,weather:e})}clear(){this.ramp=void 0,this.keyframes.length=0}removeKeyframeAt(t){this.ramp=void 0;const e=this.findInsertIndex(t);this.keyframes[e]?.t===t&&this.keyframes.splice(e,1)}findInsertIndex(t){let e=0,i=this.keyframes.length;for(;e<i;){const n=e+i>>>1;this.keyframes[n].t<t?e=n+1:i=n}return e}getLatestWeatherAt(t){let e=this.findInsertIndex(t);return this.keyframes[e]?.t!==t&&(e-=1),e>=0?this.keyframes[e].weather:void 0}getInterpolatedWeatherAt(t){const e=this.findInsertIndex(t),i=this.keyframes[e]?.t===t?this.keyframes[e]:this.keyframes[e-1];if(i?.t===t)return i.weather;const n=this.keyframes[e]?.t===t?void 0:this.keyframes[e];return i?n?t2(i.weather,n.weather,Jv((t-i.t)/(n.t-i.t),0,1)):i.weather:n?.weather}getActualWeatherAt(t){const e=this.getInterpolatedWeatherAt(t);if(!e)return;const i=(this.ramp??=new tr(this.keyframes)).at(t);if(!i)return e;const{type:n,intensity:s,character:r}=i,o=r>0?Math.min(1,s/r):n==="none"?0:1;return{...e,precipitationType:n,precipitationIntensity:r,precipitationAmount:o}}get duration(){return this.keyframes.length===0?0:this.keyframes[this.keyframes.length-1].t}get allKeyframes(){return this.keyframes}toJSON(){return{keyframes:this.keyframes}}static fromJSON(t){const e=new Qo;for(const i of t.keyframes)e.addKeyframe(i.t,{...ch,...i.weather});return e}}class tc{keyframes=[];addKeyframe(t,e){const i=this.findInsertIndex(t);this.keyframes[i]?.t===t?this.keyframes[i]={t,sound:e}:this.keyframes.splice(i,0,{t,sound:e})}clear(){this.keyframes.length=0}removeKeyframeAt(t){const e=this.findInsertIndex(t);this.keyframes[e]?.t===t&&this.keyframes.splice(e,1)}getLatestSoundAt(t){let e=this.findInsertIndex(t);return this.keyframes[e]?.t!==t&&(e-=1),e>=0?this.keyframes[e].sound:void 0}getInterpolatedSoundAt(t){const e=this.findInsertIndex(t),i=this.keyframes[e]?.t===t?this.keyframes[e]:this.keyframes[e-1];if(i?.t===t)return i.sound;const n=this.keyframes[e]?.t===t?void 0:this.keyframes[e];if(!i)return n?.sound;if(!n)return i.sound;const s=(t-i.t)/(n.t-i.t);return this.lerp(i.sound,n.sound,Math.max(0,Math.min(1,s)))}get duration(){return this.keyframes.length===0?0:this.keyframes[this.keyframes.length-1].t}get allKeyframes(){return this.keyframes}toJSON(){return{keyframes:this.keyframes}}static fromJSON(t){const e=new tc;for(const i of t.keyframes)e.addKeyframe(i.t,i.sound);return e}lerp(t,e,i){return{kind:i<1?t.kind:e.kind,volume:t.volume+(e.volume-t.volume)*i,pitchHz:t.pitchHz+(e.pitchHz-t.pitchHz)*i,src:i<1?t.src:e.src}}findInsertIndex(t){let e=0,i=this.keyframes.length;for(;e<i;){const n=e+i>>>1;this.keyframes[n].t<t?e=n+1:i=n}return e}}const e2=100,i2={kind:"none",volume:0,pitchHz:e2};class Dn{constructor(t){this.entries=t}static empty(){return new Dn(new Map)}get size(){return this.entries.size}at(t){return this.entries.get(t)}paths(){return[...this.entries.keys()]}set(t,e){e.basis==="stated"&&e.rationale===void 0?this.entries.delete(t):this.entries.set(t,e)}clear(t){for(const e of this.entries.keys())(e===t||e.startsWith(`${t}.`))&&this.entries.delete(e)}static strip(t){const e=new Dn(new Map);return{recording:Dn.stripValue(t,[],e),provenance:e}}static restore(t,e){if(e.size===0)return t;const i=structuredClone(t);for(const n of e.paths()){const s=e.at(n),r=n.split("."),o=Dn.holderOf(i,r);if(!o)continue;const c=r[r.length-1],l=o[c];l!==void 0&&(s.of!==void 0&&JSON.stringify(s.of)!==JSON.stringify(l)||(o[c]={value:l,...s.basis==="stated"?{}:{basis:s.basis},...s.rationale===void 0?{}:{rationale:s.rationale}}))}return i}static isWrapper(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)&&"value"in t}static stripValue(t,e,i){return Dn.isWrapper(t)?(i.set(e.join("."),{basis:t.basis??"stated",...t.rationale===void 0?{}:{rationale:t.rationale},of:t.value}),Dn.stripValue(t.value,e,i)):Array.isArray(t)?t.map((n,s)=>Dn.stripValue(n,[...e,String(s)],i)):typeof t=="object"&&t!==null?Object.fromEntries(Object.entries(t).map(([n,s])=>[n,Dn.stripValue(s,[...e,n],i)])):t}static holderOf(t,e){let i=t;for(const n of e.slice(0,-1)){if(typeof i!="object"||i===null)return;i=i[n]}return typeof i=="object"&&i!==null?i:void 0}}function Ju(a){if(a.year!==void 0)return Date.UTC(a.year,(a.month??1)-1,a.day??1,a.hour??0,a.minute??0,a.second??0)}function Of(a){return(((a.day??0)*24+(a.hour??0))*60+(a.minute??0))*6e4+(a.second??0)*1e3}const n2=["year","month","day","hour","minute"],s2=["day","hour","minute"];function Nf(a,t){return t.filter(e=>a[e]!==void 0).join(",")}function r2(a){if(a.durationSeconds!==void 0)return a.durationSeconds*1e3;const t=a.durationText===void 0?void 0:zo.parse(a.durationText);if(t)return t.chosenSeconds*1e3;if(!a.time||!a.endTime)return;const e=a.time.year!==void 0&&a.endTime.year!==void 0,i=e?n2:s2,n=Nf(a.time,i);if(!(n===""||n!==Nf(a.endTime,i)))return e?Ju(a.endTime)-Ju(a.time):Of(a.endTime)-Of(a.time)}class hh{constructor(t,e,i,n,s,r,o,c,l=[],h,u,d,f=[],p=[],v=[],m=[]){this.event=t,this.timeline=e,this.observerTrack=i,this.weatherTrack=n,this.soundTrack=s,this.observer=r,this.id=o,this.weather=c,this.decor=l,this.weatherSource=h,this.instrumentId=u,this.exposureSeconds=d,this.milestones=f,this.references=p,this.roads=v,this.traces=m}provenance=Dn.empty();loadIssues=[];account;sources;interpretation;sway;lightPollution;observerMap;iso;vehicle;get observerCount(){return 1+this.decor.filter(t=>t.kind==="observer").length}get exposure(){return this.exposureSeconds??this.instrument.exposureSeconds}get instrument(){return mi.byId(this.instrumentId)}static create(t,e,i){return new hh({eventType:"sighting",time:t,place:e},new lh,new jo,new Qo,new tc,i)}}const a2=0,o2=0;function Je(a,t){const e=a.observerTrack.getInterpolatedPoseAt(t);if(e)return e;const i=a.event.place?.[0];if(i)return{lat:i.lat,lng:i.lng,elevationM:a2,headingDeg:void 0,pitchDeg:o2,fovDeg:mi.fieldOfViewDeg(a.instrument)}}function ao(a,t){return a.weatherTrack.getInterpolatedWeatherAt(t)??a.weather??ch}function yc(a,t){return a.weatherTrack.getActualWeatherAt(t)??a.weather??ch}function c2(a,t){return a.soundTrack.getInterpolatedSoundAt(t)??i2}class l2{constructor(t,e){this.timeline=t,this.onFrame=e}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 t=()=>{if(this.state!=="playing")return;const e=performance.now();if(this.currentT+=(e-this.lastWallTime)*this.playbackRate,this.lastWallTime=e,this.currentT>=this.seekableDuration){if(this.loop&&this.seekableDuration>0){this.currentT%=this.seekableDuration,this.resolveFrame(this.currentT),this.rafId=requestAnimationFrame(t);return}this.currentT=this.seekableDuration,this.stop(),this.resolveFrame(this.currentT),this.onEnded?.();return}this.resolveFrame(this.currentT),this.rafId=requestAnimationFrame(t)};this.rafId=requestAnimationFrame(t)}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(t){this.currentT=Math.max(0,Math.min(t,this.seekableDuration)),this.resolveFrame(this.currentT)}get playbackState(){return this.state}get time(){return this.currentT}resolveFrame(t){const e=new Map;for(const i of this.timeline.sourceIds){const n=this.timeline.getInterpolatedShapeAt(t,i);n&&e.set(i,n)}this.onFrame(t,e)}}const kg=["nw","n","ne","e","se","s","sw","w"],h2=24,Sc=8,u2=3,d2=8;function _c(a,t,e){const i=a.x-t.x,n=a.y-t.y,s=Math.cos(e),r=Math.sin(e);return{x:t.x+i*s-n*r,y:t.y+i*r+n*s}}function oo(a){return{x:a.x+a.width/2,y:a.y+a.height/2}}const f2={nw:{left:!0,top:!0},n:{top:!0},ne:{right:!0,top:!0},e:{right:!0},se:{right:!0,bottom:!0},s:{bottom:!0},sw:{left:!0,bottom:!0},w:{left:!0}};class pn{static handlePointsFor(t){const{x:e,y:i,width:n,height:s}=t.bounds,r={nw:{x:e,y:i},n:{x:e+n/2,y:i},ne:{x:e+n,y:i},e:{x:e+n,y:i+s/2},se:{x:e+n,y:i+s},s:{x:e+n/2,y:i+s},sw:{x:e,y:i+s},w:{x:e,y:i+s/2},rotate:{x:e+n/2,y:i-h2}},o=oo(t.bounds),c={};for(const l of Object.keys(r))c[l]=_c(r[l],o,t.angle);return c}static hitTestHandle(t,e,i=8,n=[...kg,"rotate"]){const s=pn.handlePointsFor(t);for(const r of n)if(Math.hypot(e.x-s[r].x,e.y-s[r].y)<=i)return r}static HANDLE_DIRECTION_DEG={e:0,se:45,s:90,sw:135,w:180,nw:225,n:270,ne:315};static resizeAxisFor(t,e){const n=((pn.HANDLE_DIRECTION_DEG[t]+e*180/Math.PI)%180+180)%180/45,s=["ew","nwse","ns","nesw"];return s[Math.round(n)%s.length]}static resizeBounds(t,e,i,n){const s=oo(t),r=_c(n,s,-e),{x:o,y:c,width:l,height:h}=t,u=f2[i];let d=o,f=c,p=o+l,v=c+h;return u.left&&(d=Math.min(r.x,p-Sc)),u.right&&(p=Math.max(r.x,d+Sc)),u.top&&(f=Math.min(r.y,v-Sc)),u.bottom&&(v=Math.max(r.y,f+Sc)),{x:d,y:f,width:p-d,height:v-f}}static resizeShape(t,e,i){if(e==="rotate")throw new Error("resizeShape does not accept the rotate handle");const{width:n,height:s}=t.bounds,r=pn.resizeBounds(t.bounds,t.angle,e,i);if(t.kind==="oval")return{...t,bounds:r};const o=n===0?1:r.width/n,c=s===0?1:r.height/s;return{...t,bounds:r,points:t.points.map(l=>({x:l.x*o,y:l.y*c}))}}static rotateShape(t,e){const i=oo(t.bounds),n=Math.atan2(e.y-i.y,e.x-i.x)+Math.PI/2;return{...t,angle:n}}static groupBoundsFor(t){const e=Math.min(...t.map(r=>r.x)),i=Math.min(...t.map(r=>r.y)),n=Math.max(...t.map(r=>r.x+r.width)),s=Math.max(...t.map(r=>r.y+r.height));return{x:e,y:i,width:n-e,height:s-i}}static vertexPointsFor(t){const e=oo(t.bounds);return t.points.map(i=>_c({x:t.bounds.x+i.x,y:t.bounds.y+i.y},e,t.angle))}static hitTestVertex(t,e,i=d2){const n=pn.vertexPointsFor(t);let s,r=i;return n.forEach((o,c)=>{const l=Math.hypot(e.x-o.x,e.y-o.y);l<=r&&(r=l,s=c)}),s}static toLocalPoint(t,e){const i=oo(t.bounds),n=_c(e,i,-t.angle);return{x:n.x-t.bounds.x,y:n.y-t.bounds.y}}static moveVertex(t,e,i){const n=t.points.map((u,d)=>d===e?pn.toLocalPoint(t,i):u),s=Math.min(...n.map(u=>u.x)),r=Math.min(...n.map(u=>u.y)),o=Math.max(...n.map(u=>u.x)),c=Math.max(...n.map(u=>u.y)),l={x:t.bounds.x+s,y:t.bounds.y+r,width:o-s,height:c-r},h=n.map(u=>({x:u.x-s,y:u.y-r}));return{...t,bounds:l,points:h}}static insertVertexNear(t,e){const i=pn.toLocalPoint(t,e),{points:n}=t;let s=n.length-1,r=1/0;for(let c=0;c<n.length;c++){const l=n[c],h=n[(c+1)%n.length],u=pn.distanceToSegment(i,l,h);u<r&&(r=u,s=c)}const o=[...n.slice(0,s+1),i,...n.slice(s+1)];return{...t,points:o}}static distanceToSegment(t,e,i){const n=i.x-e.x,s=i.y-e.y,r=n*n+s*s,o=r===0?0:Math.max(0,Math.min(1,((t.x-e.x)*n+(t.y-e.y)*s)/r)),c=e.x+o*n,l=e.y+o*s;return Math.hypot(t.x-c,t.y-l)}static deleteVertex(t,e){return t.points.length<=u2?t:{...t,points:t.points.filter((i,n)=>n!==e)}}}const ju=6,bc=ju/2,Ff=20,Uf=24,kf=9,zf=6,Bf=7,Hf=6,es=4;class ec{constructor(t){this.ctx=t}starPoints=0;roll=0;clear(t,e){this.ctx.clearRect(0,0,t,e)}static paintExtent(t){const{x:e,y:i,width:n,height:s}=t.bounds,r=e+n/2,o=i+s/2,c=t.angle%(2*Math.PI)!==0,l=Math.hypot(n,s)/2,h=c?l:n/2,u=c?l:s/2,d=Math.max(n,s)/2,f=t.brightness??0,p=f>0?Math.max(d*(1+kf*f),Hf*f)-d:0,v=f>0?d*(1+Bf*f)-d:0,m=3*Uf*(t.blur??0)+1.5*Ff*t.haloScale,g=Math.max(p,v,0)+m+2;return{x:r-h-g,y:o-u-g,width:2*(h+g),height:2*(u+g)}}paintInto(t,e,i,n=!1){this.ctx.save(),this.ctx.scale(i,i),this.ctx.translate(-e.x,-e.y);const s=t.selected?{...t,selected:!1}:t;n?this.paintGhost(s,1.5):this.paintShape(s),this.ctx.restore()}paintShape(t){this.ctx.save(),this.ctx.globalAlpha=1-t.transparency;const e=t.blur??0;e>0&&(this.ctx.filter=`blur(${(Uf*e).toFixed(2)}px)`);const i=t.brightness??0;i>0&&this.paintDazzle(t,i),t.haloScale>0&&this.paintHalo(t),this.paintBase(t),this.ctx.restore(),t.selected&&this.paintSelectionHandles(t)}setStarPoints(t){this.starPoints=Math.max(0,Math.floor(t))}setRoll(t){this.roll=t}paintDazzle(t,e){const{x:i,y:n,width:s,height:r}=t.bounds,o=i+s/2,c=n+r/2,l=Math.max(s,r)/2,h=Math.max(l*(1+kf*e),Hf*e);if(h<=0)return;this.ctx.save(),this.ctx.globalCompositeOperation="lighter";const u=this.ctx.createRadialGradient(o,c,0,o,c,h);for(let d=0;d<=zf;d++){const f=d/zf,p=1/(1+24*f*f);this.ctx.globalAlpha=1,u.addColorStop(f,this.withAlpha(t.color,p*e*.55))}if(this.ctx.fillStyle=u,this.ctx.beginPath(),this.ctx.arc(o,c,h,0,2*Math.PI),this.ctx.fill(),this.starPoints>0){const d=l*(1+Bf*e);this.ctx.lineWidth=Math.max(1,l*.12),this.ctx.lineCap="round";for(let f=0;f<this.starPoints;f++){const p=f/this.starPoints*Math.PI*2+this.roll,v=o+Math.cos(p)*d,m=c+Math.sin(p)*d,g=this.ctx.createLinearGradient(o,c,v,m);g.addColorStop(0,this.withAlpha(t.color,e*.55)),g.addColorStop(.35,this.withAlpha(t.color,e*.22)),g.addColorStop(1,this.withAlpha(t.color,0)),this.ctx.strokeStyle=g,this.ctx.beginPath(),this.ctx.moveTo(o,c),this.ctx.lineTo(v,m),this.ctx.stroke()}}this.ctx.restore()}dazzledFill(t,e){if(e<=0)return t.color;const i=/^#([0-9a-f]{6})$/i.exec(t.color.trim());if(!i)return t.color;const n=Number.parseInt(i[1],16),s=r=>Math.round(r+(255-r)*e);return`rgb(${s(n>>16&255)}, ${s(n>>8&255)}, ${s(n&255)})`}withAlpha(t,e){const i=Math.max(0,Math.min(1,e)),n=/^#([0-9a-f]{6})$/i.exec(t.trim());if(!n)return t;const s=Number.parseInt(n[1],16);return`rgba(${s>>16&255}, ${s>>8&255}, ${s&255}, ${i.toFixed(3)})`}paintBase(t){this.ctx.fillStyle=this.dazzledFill(t,t.brightness??0),this.tracePath(t),this.ctx.fill()}paintGhost(t,e){this.ctx.save(),this.tracePath(t),this.ctx.setLineDash([e*3,e*2]),this.ctx.lineWidth=e,this.ctx.strokeStyle=t.color,this.ctx.stroke(),this.ctx.restore()}tracePath(t){if(this.ctx.beginPath(),t.kind==="oval"){const{x:e,y:i,width:n,height:s}=t.bounds,r=n/2,o=s/2;this.ctx.ellipse(e+r,i+o,r,o,t.angle,0,2*Math.PI)}else{const{x:e,y:i,width:n,height:s}=t.bounds;this.ctx.save(),this.ctx.translate(e+n/2,i+s/2),this.ctx.rotate(t.angle),this.ctx.translate(-n/2,-s/2),t.points.forEach((r,o)=>{o===0?this.ctx.moveTo(r.x,r.y):this.ctx.lineTo(r.x,r.y)}),this.ctx.closePath(),this.ctx.restore()}}paintHalo(t){this.ctx.save(),this.ctx.shadowColor=t.color,this.ctx.shadowBlur=Ff*t.haloScale,this.paintBase(t),this.ctx.restore()}paintSelectionHandles(t){this.paintHandleFrame(pn.handlePointsFor(t),{includeRotate:!0}),t.kind==="polygon"&&this.paintVertexHandles(t)}paintVertexHandles(t){this.ctx.fillStyle="#39f";for(const e of pn.vertexPointsFor(t))this.ctx.beginPath(),this.ctx.ellipse(e.x,e.y,es,es,0,0,2*Math.PI),this.ctx.fill()}paintMemberOutline(t){this.paintOutline(pn.handlePointsFor(t))}paintSelectionOnly(t){this.paintSelectionHandles(t)}paintPictureFrame(t,e,i){const n=this.ctx;if(n.save(),t&&t.length===4){n.strokeStyle="#39f",n.lineWidth=1.5,n.setLineDash([6,4]),n.beginPath(),n.moveTo(t[0].x,t[0].y);for(const s of t.slice(1))n.lineTo(s.x,s.y);n.closePath(),n.stroke(),n.setLineDash([])}for(const s of e){const r=ec.landmarkColour(s.residualDeg),o=s.selected?3:2;s.selected&&(n.strokeStyle="#fff",n.lineWidth=o+3,n.beginPath(),n.ellipse(s.picture.x,s.picture.y,es+2,es+2,0,0,2*Math.PI),n.stroke()),s.scene&&(n.strokeStyle=r,n.lineWidth=1,n.beginPath(),n.moveTo(s.picture.x,s.picture.y),n.lineTo(s.scene.x,s.scene.y),n.stroke(),n.fillStyle=r,n.beginPath(),n.ellipse(s.scene.x,s.scene.y,es,es,0,0,2*Math.PI),n.fill()),n.strokeStyle=r,n.lineWidth=o,n.beginPath(),n.ellipse(s.picture.x,s.picture.y,es+2,es+2,0,0,2*Math.PI),n.stroke(),this.paintLabel(s.label,s.picture.x+es+5,s.picture.y-es-2,r)}i&&this.paintLabel(i,8,8,"#fff",13),n.restore()}static landmarkColour(t){return t===void 0?"#ffb000":t<=1?"#3c3":t<=3?"#ffb000":"#f33"}paintLabel(t,e,i,n,s=11){const r=this.ctx;r.save(),r.font=`${s}px system-ui, sans-serif`,r.textBaseline="top";const o=r.measureText(t).width;r.fillStyle="rgba(0, 0, 0, 0.6)",r.fillRect(e-3,i-2,o+6,s+4),r.fillStyle=n,r.fillText(t,e,i),r.restore()}paintGroupHandles(t){this.paintHandleFrame(pn.handlePointsFor({bounds:t,angle:0}),{includeRotate:!0})}paintOutline(t){this.ctx.strokeStyle="lightgray",this.ctx.beginPath(),this.ctx.moveTo(t.nw.x,t.nw.y),this.ctx.lineTo(t.ne.x,t.ne.y),this.ctx.lineTo(t.se.x,t.se.y),this.ctx.lineTo(t.sw.x,t.sw.y),this.ctx.closePath(),this.ctx.stroke()}paintHandleFrame(t,{includeRotate:e}){this.paintOutline(t),this.ctx.fillStyle="lightgray";for(const i of kg){const n=t[i];this.ctx.fillRect(n.x-bc,n.y-bc,ju,ju)}e&&(this.ctx.beginPath(),this.ctx.moveTo(t.n.x,t.n.y),this.ctx.lineTo(t.rotate.x,t.rotate.y),this.ctx.stroke(),this.ctx.beginPath(),this.ctx.ellipse(t.rotate.x,t.rotate.y,bc+1,bc+1,0,0,2*Math.PI),this.ctx.fill())}}const Gf=.05,Vf=.08,Wf=2,Xf=3,p2=14,m2=.02;class g2{context;voice;voiceToken=0;buffers=new Map;noiseBuffer;crackleBuffer;requested;level=1;master;output(t){return this.master||(this.master=t.createGain(),this.master.gain.value=this.level,this.master.connect(t.destination)),this.master}setLevel(t){this.level=t,this.master&&(this.master.gain.value=t)}resume(){if(!this.context){if(typeof AudioContext>"u")return;try{this.context=new AudioContext}catch(t){console.warn("SightingAudio: Web Audio unavailable, the sighting stays silent:",t);return}}zr.unlock(this.context)}setSound(t){if(this.requested=t,!this.context)return;const e=this.keyFor(t);if(!e){this.silence();return}if(this.voice?.key!==e){this.stopVoice();const i=++this.voiceToken;e.startsWith("src:")?this.buildRecordedVoice(t.src,e,i):this.voice=this.buildSynthesizedVoice(t,e)}this.applyTo(this.voice,t)}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(t){if(!(t.volume<=0))return t.src?`src:${t.src}`:t.kind==="none"?void 0:t.kind}applyTo(t,e){const i=this.context;if(!t||!i)return;const n=i.currentTime;t.volumeParam.setTargetAtTime(Math.max(0,Math.min(1,e.volume))*t.gainScale,n,Gf);for(const{param:s,ratio:r}of t.pitch)s.setTargetAtTime(Math.min(e.pitchHz*r,i.sampleRate/2-1),n,Gf)}buildSynthesizedVoice(t,e){const i=this.context;if(i)switch(t.kind){case"hum":return this.buildHum(i,e);case"whistle":return this.buildWhistle(i,e);case"rumble":return this.buildRumble(i,e);case"crackle":return this.buildCrackle(i,e);default:return}}buildHum(t,e){const i=t.createOscillator();i.type="sawtooth";const n=t.createOscillator();n.type="sawtooth";const s=t.createBiquadFilter();s.type="lowpass",s.Q.value=1;const r=t.createGain();return r.gain.value=0,i.connect(s),n.connect(s),s.connect(r).connect(this.output(t)),i.start(),n.start(),{key:e,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(t,e){const i=t.createOscillator();i.type="sine";const n=t.createOscillator();n.type="sine",n.frequency.value=5;const s=t.createGain(),r=t.createGain();return r.gain.value=0,n.connect(s).connect(i.frequency),i.connect(r).connect(this.output(t)),i.start(),n.start(),{key:e,nodes:[s,r],sources:[i,n],volumeParam:r.gain,gainScale:.22,pitch:[{param:i.frequency,ratio:1},{param:s.gain,ratio:.012}]}}buildRumble(t,e){const i=t.createBufferSource();i.buffer=this.brownNoise(t),i.loop=!0;const n=t.createBiquadFilter();n.type="lowpass",n.Q.value=.8;const s=t.createGain();return s.gain.value=0,i.connect(n).connect(s).connect(this.output(t)),i.start(),{key:e,nodes:[n,s],sources:[i],volumeParam:s.gain,gainScale:1.4,pitch:[{param:n.frequency,ratio:1}]}}buildCrackle(t,e){const i=t.createBufferSource();i.buffer=this.whiteNoise(t),i.loop=!0;const n=t.createBiquadFilter();n.type="bandpass",n.Q.value=1.2;const s=t.createGain();s.gain.value=0;const r=t.createBufferSource();r.buffer=this.crackleEnvelope(t),r.loop=!0;const o=t.createGain();return o.gain.value=0,r.connect(o).connect(s.gain),i.connect(n).connect(s).connect(this.output(t)),i.start(),r.start(),{key:e,nodes:[n,s,o],sources:[i,r],volumeParam:o.gain,gainScale:.9,pitch:[{param:n.frequency,ratio:4}]}}async buildRecordedVoice(t,e,i){const n=this.context;if(!n)return;let s;try{s=await this.getBuffer(t)}catch(c){console.warn("SightingAudio: the recorded sound failed to load, staying silent:",c);return}if(i!==this.voiceToken||!this.context)return;const r=n.createBufferSource();r.buffer=s,r.loop=!0;const o=n.createGain();o.gain.value=0,r.connect(o).connect(this.output(n)),r.start(),this.voice={key:e,nodes:[o],sources:[r],volumeParam:o.gain,gainScale:1,pitch:[]},this.requested&&this.applyTo(this.voice,this.requested)}async getBuffer(t){const e=this.context;if(!e)throw new Error("SightingAudio: AudioContext not ready — resume() must be called first");let i=this.buffers.get(t);return i||(i=fetch(t).then(n=>{if(!n.ok)throw new Error(`Audio fetch failed (${n.status}): ${t}`);return n.arrayBuffer()}).then(n=>e.decodeAudioData(n)),this.buffers.set(t,i)),i}whiteNoise(t){if(!this.noiseBuffer){const e=t.createBuffer(1,Math.floor(t.sampleRate*Wf),t.sampleRate),i=e.getChannelData(0);for(let n=0;n<i.length;n++)i[n]=Math.random()*2-1;this.noiseBuffer=e}return this.noiseBuffer}brownNoise(t){const e=t.createBuffer(1,Math.floor(t.sampleRate*Wf),t.sampleRate),i=e.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 e}crackleEnvelope(t){if(!this.crackleBuffer){const e=t.createBuffer(1,Math.floor(t.sampleRate*Xf),t.sampleRate),i=e.getChannelData(0),n=Math.max(1,Math.floor(m2*t.sampleRate)),s=Math.round(Xf*p2);for(let r=0;r<s;r++){const o=Math.floor(Math.random()*i.length),c=.4+Math.random()*.6;for(let l=0;l<n&&o+l<i.length;l++)i[o+l]=Math.max(i[o+l],c*(1-l/n))}this.crackleBuffer=e}return this.crackleBuffer}stopVoice(){const t=this.voice,e=this.context;if(this.voice=void 0,!t||!e)return;const i=e.currentTime;t.volumeParam.cancelScheduledValues(i),t.volumeParam.setTargetAtTime(0,i,Vf/3);const n=i+Vf;for(const s of t.sources){s.onended=()=>{s.disconnect();for(const r of t.nodes)r.disconnect()};try{s.stop(n)}catch{s.disconnect();for(const r of t.nodes)r.disconnect()}}}}class Gt{static svg(t){return`<svg viewBox="0 0 24 24" width="1.5em" height="1.5em" aria-hidden="true" focusable="false"><path d="${t}" fill="currentColor"/></svg>`}static outline(t){return`<svg viewBox="0 0 24 24" width="1.5em" height="1.5em" aria-hidden="true" focusable="false"><path d="${t}" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linejoin="round" stroke-linecap="round"/></svg>`}static solid(t){return`<svg viewBox="0 0 24 24" width="1.5em" height="1.5em" aria-hidden="true" focusable="false"><path d="${t}" 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=Gt.outline(Gt.BOOKMARK);static MILESTONES_ON=Gt.solid(Gt.BOOKMARK);static PICTURES_OFF=Gt.outline(`${Gt.PICTURE}${Gt.PICTURE_HILLS}`);static PICTURES_ON=Gt.solid(`${Gt.PICTURE}${Gt.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=Gt.outline(`${Gt.TRACE_LINE}${Gt.TRACE_MARK}`);static TRACES_ON=Gt.solid(`${Gt.TRACE_LINE}${Gt.TRACE_MARK}`);static MAP_OFF=Gt.outline(`${Gt.PIN}${Gt.PIN_HOLE}`);static MAP_ON=Gt.solid(`${Gt.PIN}${Gt.PIN_HOLE}`);static SHARE=Gt.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=Gt.svg("M15.4 7.4 14 6l-6 6 6 6 1.4-1.4L10.8 12z");static UNFOLDED=Gt.svg("M8.6 16.6 10 18l6-6-6-6-1.4 1.4 4.6 4.6z");static PLAY=Gt.svg("M7.4 5v14l11-7z");static PAUSE=Gt.svg("M6 5h4v14H6zM14 5h4v14h-4z");static VOLUME=Gt.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=Gt.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=Gt.svg("M5 5h5v2H7v3H5V5zm9 0h5v5h-2V7h-3V5zM5 14h2v3h3v2H5v-5zm12 0h2v5h-5v-2h3v-3z");static EXIT_FULLSCREEN=Gt.svg("M8 5h2v5H5V8h3V5zm6 0h2v3h3v2h-5V5zM5 14h5v5H8v-3H5v-2zm9 0h5v2h-3v3h-2v-5z")}function Bo(a){return[...a].sort((t,e)=>t.t-e.t)}function Ah(a,t){let e;for(const i of Bo(a)){if(i.t>t)break;e=i}return e}const Th=Math.PI/180,wc=180/Math.PI;class Ls{constructor(t,e,i){this.kind=t,this.canvasHeightPx=e,this.fovDeg=i;const n=i*Th/2;this.focalPx=t==="equidistant"?e/2/n:e/2/Math.tan(n)}focalPx;static of(t,e,i){return new Ls(t.projection,e,i)}degToPx(t){const e=t*Th;return this.kind==="equidistant"?this.focalPx*e:2*this.focalPx*Math.tan(e/2)}pxToDeg(t){return this.kind==="equidistant"?t/this.focalPx*wc:2*Math.atan(t/(2*this.focalPx))*wc}angleDegToRadiusPx(t){const e=t*Th;return this.kind==="equidistant"?this.focalPx*e:this.focalPx*Math.tan(e)}halfWidthAngleDeg(t){return this.radiusPxToAngleDeg(this.canvasHeightPx*t/2)}radiusPxToAngleDeg(t){return this.kind==="equidistant"?t/this.focalPx*wc:Math.atan(t/this.focalPx)*wc}ofBounds(t){return{widthDeg:this.pxToDeg(t.width),heightDeg:this.pxToDeg(t.height)}}toBoundsSize(t){return{width:this.degToPx(t.widthDeg),height:this.degToPx(t.heightDeg)}}widthPx(t){return this.degToPx(Ie.angularWidthDeg(t))}}class an{static fovOf(t,e){return Je(t,e)?.fovDeg??mi.fieldOfViewDeg(t.instrument)}static toAngular(t){this.eachKeyframe(t,(e,i)=>({...e,angular:i.ofBounds(e.bounds)}))}static toBounds(t){this.eachKeyframe(t,(e,i)=>{if(!e.angular)return e;const{width:n,height:s}=i.toBoundsSize(e.angular),r={x:e.bounds.x+(e.bounds.width-n)/2,y:e.bounds.y+(e.bounds.height-s)/2,width:n,height:s};if(e.kind!=="polygon")return{...e,bounds:r};const o=e.bounds.width===0?1:n/e.bounds.width,c=e.bounds.height===0?1:s/e.bounds.height;return{...e,bounds:r,points:e.points.map(l=>({x:l.x*o,y:l.y*c}))}})}static toAim(t){this.eachKeyframe(t,(e,i,n)=>{const s=e.aim&&this.positionOf(t,e.aim,e.bounds,i,n);if(s&&Math.abs(s.x-e.bounds.x)<an.UNMOVED_PX&&Math.abs(s.y-e.bounds.y)<an.UNMOVED_PX)return e;const r=this.aimFrom(t,i,n,e.bounds);return r?{...e,aim:r}:e})}static UNMOVED_PX=.01;static aimOf(t,e,i){const n=Ls.of(t.instrument,Ie.CANVAS_HEIGHT_PX,this.fovOf(t,e));return this.aimFrom(t,n,Je(t,e),i)}static aimFrom(t,e,i,n){if(i?.headingDeg===void 0)return;const s=this.frameCentre(t),r=e.radiusPxToAngleDeg(n.x+n.width/2-s.x),o=e.radiusPxToAngleDeg(s.y-(n.y+n.height/2));return{azimuthDeg:((i.headingDeg+r)%360+360)%360,altitudeDeg:i.pitchDeg+o}}static toPosition(t){this.eachKeyframe(t,(e,i,n)=>{const s=e.aim&&this.positionOf(t,e.aim,e.bounds,i,n);return s?{...e,bounds:{...e.bounds,...s}}:e})}static positionOf(t,e,i,n,s){if(s?.headingDeg===void 0)return;const r=this.frameCentre(t),o=this.shortestArc(e.azimuthDeg-s.headingDeg),c=e.altitudeDeg-s.pitchDeg;return{x:r.x+this.offAxisPx(n,o)-i.width/2,y:r.y-this.offAxisPx(n,c)-i.height/2}}static frameCentre(t){return{x:mi.frameWidthPx(t.instrument,Ie.CANVAS_HEIGHT_PX)/2,y:Ie.CANVAS_HEIGHT_PX/2}}static shortestArc(t){return(t%360+540)%360-180}static offAxisPx(t,e){return Math.abs(e)>=an.OFF_CANVAS_DEG?Math.sign(e)*an.OFF_CANVAS_PX:t.angleDegToRadiusPx(e)}static OFF_CANVAS_DEG=89;static OFF_CANVAS_PX=1e5;static reproject(t,e,i){const n=mi.frameWidthPx(e,Ie.CANVAS_HEIGHT_PX)/2,s=mi.frameWidthPx(t.instrument,Ie.CANVAS_HEIGHT_PX)/2,r=Ie.CANVAS_HEIGHT_PX/2;for(const o of[...t.timeline.allKeyframes]){const c=this.fovOf(t,o.t),l=i?.get(o.t)??c,h=Ls.of(e,Ie.CANVAS_HEIGHT_PX,l),u=Ls.of(t.instrument,Ie.CANVAS_HEIGHT_PX,c);t.timeline.addKeyframe(o.t,o.shapes.map(d=>{const{bounds:f}=d.shape,p=f.x+f.width/2-n,v=f.y+f.height/2-r,m=Math.hypot(p,v),g=m===0?1:u.angleDegToRadiusPx(h.radiusPxToAngleDeg(m))/m,S={...f,x:s+p*g-f.width/2,y:r+v*g-f.height/2};return{...d,shape:{...d.shape,bounds:S}}}))}this.toBounds(t)}static eachKeyframe(t,e){const{timeline:i}=t;for(const n of[...i.allKeyframes]){const s=Je(t,n.t),r=this.fovOf(t,n.t),o=Ls.of(t.instrument,Ie.CANVAS_HEIGHT_PX,r);i.addKeyframe(n.t,n.shapes.map(c=>({...c,shape:e(c.shape,o,s)})))}}}function v2(a){return Dn.restore(M2(a),a.provenance)}function M2(a){return an.toAngular(a),an.toAim(a),{version:1,id:a.id,time:a.event.time,endTime:a.event.endTime,durationSeconds:a.event.durationSeconds,durationText:a.event.durationText,utcOffsetHours:a.event.utcOffsetHours,timeZone:a.event.timeZone,place:a.event.place,observer:a.observer,account:a.account,sources:a.sources?.length?a.sources:void 0,sway:a.sway,vehicle:a.vehicle,description:a.event.description,tags:a.event.tags,timeline:a.timeline.toJSON(),observerTrack:a.observerTrack.toJSON(),weatherTrack:a.weatherTrack.toJSON(),soundTrack:a.soundTrack.toJSON(),weather:a.weather,decor:a.decor,milestones:a.milestones.length>0?a.milestones:void 0,references:a.references.length>0?a.references:void 0,roads:a.roads.length>0?a.roads:void 0,traces:a.traces.length>0?a.traces:void 0,weatherSource:a.weatherSource,instrument:a.instrumentId,exposureSeconds:a.exposureSeconds,iso:a.iso,lightPollution:a.lightPollution,observerMap:a.observerMap,interpretation:a.interpretation}}function x2(a){const{recording:t,provenance:e}=Dn.strip(a),i=y2(t);return i.provenance=e,i}function y2(a){const t=[],e=new hh({eventType:"sighting",time:a.time,endTime:a.endTime,durationSeconds:a.durationSeconds,durationText:a.durationText,utcOffsetHours:a.utcOffsetHours,timeZone:a.timeZone,place:a.place,description:a.description,tags:a.tags},lh.fromJSON(a.timeline,t),a.observerTrack?jo.fromJSON(a.observerTrack):new jo,a.weatherTrack?Qo.fromJSON(a.weatherTrack):new Qo,a.soundTrack?tc.fromJSON(a.soundTrack):new tc,a.observer&&{id:a.observer.id,title:a.observer.title,lastName:a.observer.lastName,firstNames:a.observer.firstNames},a.id,a.weather,a.decor??[],a.weatherSource,a.instrument,a.exposureSeconds??a.observerTrack?.keyframes.map(i=>i.pose.exposureSeconds).find(i=>i!==void 0),Bo(a.milestones??[]),a.references??[],a.roads??[],a.traces??[]);return e.account=a.account,e.sources=a.sources,e.sway=a.sway,e.iso=a.iso,e.lightPollution=a.lightPollution,e.observerMap=a.observerMap,e.vehicle=a.vehicle,e.interpretation=a.interpretation,e.loadIssues=t,an.toBounds(e),an.toPosition(e),e}class Za{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(t,e=Za.EN){return e[t.kind].replace("{path}",t.path).replace("{expected}",t.expected??"").replace("{found}",t.found??"")}static warn(t,e){if(t.length===0)return;const i=t.map(n=>` ${Za.text(n)}`);console.warn(`UFO@home: ${t.length} problem(s) in ${e??"this recording"}:
1410
1410
  ${i.join(`
1411
- `)}`)}}class Bn{constructor(t){this.format=t}issues(t){const e=[];return this.object(t,this.format,"",e),e}object(t,e,i,n){if(!Bn.isObject(t)){n.push({kind:"wrong-type",path:i||"(the file)",expected:"object",found:Bn.typeOf(t)});return}for(const[s,r]of Object.entries(t)){const o=i?`${i}.${s}`:s,c=e[s];c?this.field(r,c,o,n):n.push({kind:"unknown-key",path:o})}}field(t,e,i,n){if(Bn.isStated(t)){this.field(t.value,e,i,n);return}if(!(e.loose||t===void 0||t===null))switch(e.type){case"enum":(typeof t!="string"||!e.values?.includes(t))&&n.push({kind:"not-in-list",path:i,expected:(e.values??[]).map(s=>`"${s}"`).join(", "),found:JSON.stringify(t)});return;case"object":e.fields?this.object(t,e.fields,i,n):Bn.isObject(t)||n.push({kind:"wrong-type",path:i,expected:"object",found:Bn.typeOf(t)});return;case"array":Array.isArray(t)?e.fields&&t.forEach((s,r)=>{const o=Bn.isStated(s)?s.value:s;this.object(o,e.fields,`${i}.${r}`,n)}):n.push({kind:"wrong-type",path:i,expected:"array",found:Bn.typeOf(t)});return;default:typeof t!==e.type&&n.push({kind:"wrong-type",path:i,expected:e.type,found:Bn.typeOf(t)})}}static isObject(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}static isStated(t){return Bn.isObject(t)&&"value"in t&&Object.keys(t).every(e=>e==="value"||e==="basis"||e==="rationale")}static typeOf(t){return Array.isArray(t)?"array":t===null?"null":typeof t}}class Xn{static PIXELS_PER_INSTANT=2;static INSTANTS_PER_FLASH=2;static MAX_INSTANTS=512;static windowEndingAt(t,e){const i=Number.isFinite(e)?Math.max(0,e):0,n=Math.max(0,t-i*1e3),s=Math.max(0,t-n);return{fromMs:n,toMs:t,ms:s,seconds:s/1e3}}static instants(t,e,i,n,s){if(!(n>0))return 1;const r=s>0?Xn.travelDegOver(t,e,i,i+n*1e3)/s/Xn.PIXELS_PER_INSTANT:0,o=Xn.flashesOver(t,n)*Xn.INSTANTS_PER_FLASH,c=Math.ceil(Math.max(r,o));return c<2?1:Math.min(Xn.MAX_INSTANTS,c)}static travelDegOver(t,e,i,n){let s=0;for(const r of t){if(!r.track||r.track.length<2)continue;const o=Xn.directionAt(r,e,i),c=Xn.directionAt(r,e,n),l=Math.min(1,Math.max(-1,o.x*c.x+o.y*c.y+o.z*c.z));s=Math.max(s,Math.acos(l)*180/Math.PI)}return s}static flashesOver(t,e){let i=0;for(const n of t)for(const s of n.lights??[])s.pattern.kind==="flash"&&(i=Math.max(i,s.pattern.perMinute));return i/60*e}static directionAt(t,e,i){const n=Zo(t,i),s=n.eastM,r=n.altitudeM-e,o=n.northM,c=Math.hypot(s,r,o);return c===0?{x:0,y:1,z:0}:{x:s/c,y:r/c,z:o/c}}}function zg(a,t){for(const e of a){const i=e.toLowerCase().split("-")[0];if(t.includes(i))return i}return"en"}class Ua{static preferencesFor(t){const e=navigator.languages??[],i=this.declaredFor(t);return i?[i,...e]:e}static declaredFor(t){for(let e=t;e;){const i=e.closest("[lang]")?.getAttribute("lang")?.trim();if(i)return i;const n=e.getRootNode();e=n instanceof ShadowRoot?n.host:void 0}}}class Cs{constructor(t){this.preferences=t}read(t){if(t===void 0||typeof t=="string")return t===""?void 0:t;for(const i of this.preferences){const n=t[i]??t[Cs.base(i)];if(n)return n}const e=new Set(this.preferences.map(i=>Cs.base(i)));for(const[i,n]of Object.entries(t))if(n&&e.has(Cs.base(i)))return n;return Object.values(t).find(i=>i)??void 0}write(t,e,i){const n=e?.trim()?e.trim():void 0;if(t===void 0||typeof t=="string")return n;const s={...t},r=Object.keys(s).find(o=>o===i)??Object.keys(s).find(o=>Cs.base(o)===Cs.base(i))??i;return n===void 0?delete s[r]:s[r]=n,Object.keys(s).length===0?void 0:s}static base(t){return t.toLowerCase().split("-")[0]}}const Bg=["en","fr","es","it"],S2={en:()=>$i(()=>Promise.resolve().then(()=>w2),void 0,import.meta.url).then(a=>a.ufoMessages_en),fr:()=>$i(()=>import("./UfoMessages_fr-6WbKsRDZ.js"),[],import.meta.url).then(a=>a.ufoMessages_fr),es:()=>$i(()=>import("./UfoMessages_es-CD_68_jy.js"),[],import.meta.url).then(a=>a.ufoMessages_es),it:()=>$i(()=>import("./UfoMessages_it-CHAJPqfh.js"),[],import.meta.url).then(a=>a.ufoMessages_it)};function _2(a){return S2[a]()}function b2(a){switch(a){case"fr":return $i(()=>import("./SceneNames_fr-Ctvv7Jq8.js"),[],import.meta.url).then(t=>t.sceneNames_fr);case"es":return $i(()=>import("./SceneNames_es-3l2Xsebd.js"),[],import.meta.url).then(t=>t.sceneNames_es);case"it":return $i(()=>import("./SceneNames_it-B1_4bOob.js"),[],import.meta.url).then(t=>t.sceneNames_it);default:return Promise.resolve(void 0)}}const Hg={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",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:Za.EN},w2=Object.freeze(Object.defineProperty({__proto__:null,ufoMessages_en:Hg},Symbol.toStringTag,{value:"Module"})),Gg=Math.PI/180,E2=180/Math.PI,A2=256,Vg=19,T2=1.25;function Wg(a,t){return 156543.03392*Math.cos(a*Gg)/2**t}function Xg(a,t){return Wg(a,t)*A2}function R2(a,t){let e=0;for(;e<Vg&&Xg(a,e+1)>=t;)e++;return e}function Yg(a,t){return Xg(a,t)}function D2(a,t){const e=t*T2;let i=0;for(;i<Vg&&Wg(a,i)>e;)i++;return i}function wl(a){const t=a*Gg;return(1-Math.log(Math.tan(t)+1/Math.cos(t))/Math.PI)/2}function qg(a,t,e){const i=2**e;return{x:(a+180)/360*i,y:wl(t)*i}}function $g(a,t,e){const i=wl(a.north),n=wl(a.south);return{x:(t-a.west)/(a.east-a.west),y:(wl(e)-i)/(n-i)}}function I2(a,t,e){const{x:i,y:n}=qg(a,t,e);return{x:Math.floor(i),y:Math.floor(n),z:e}}function C2(a){const t=2**a.z,e=a.x/t*360-180,i=(a.x+1)/t*360-180,n=Yf(a.y,t);return{south:Yf(a.y+1,t),north:n,west:e,east:i}}function Yf(a,t){const e=a/t;return Math.atan(Math.sinh(Math.PI*(1-2*e)))*E2}function Kg(a,t,e,i){const n=I2(a,t,e),s=Math.floor(i/2),r=[];for(let l=-s;l<=s;l++)for(let h=-s;h<=s;h++)r.push({x:n.x+h,y:n.y+l,z:e});const o=r.map(C2),c={south:Math.min(...o.map(l=>l.south)),north:Math.max(...o.map(l=>l.north)),west:Math.min(...o.map(l=>l.west)),east:Math.max(...o.map(l=>l.east))};return{tiles:r,bounds:c}}const P2="#2ec4ff";class Rr{constructor(t){this.ctx=t}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(t,e){let i,n=1/0;for(const s of this.targets){const r=Math.hypot(s.x-t,s.y-e);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(t){const{ctx:e}=this;e.save(),this.targets=[],e.clearRect(0,0,this.width,this.height),this.paintGround(t),this.paintNight(t.nightFraction),this.paintPath(t),this.paintTraces(t),t.position?(this.paintCone(t,t.position),this.paintDecor(t),this.paintMarkers(t),this.paintObserver(t,t.position)):(this.paintDecor(t),this.paintMarkers(t)),this.paintNorth(),this.paintFooter(t.bounds,t.attribution),e.restore()}toCanvas(t,e,i){const n=$g(t,i,e);return{x:n.x*this.width,y:n.y*this.height}}paintGround(t){const{ctx:e}=this;e.fillStyle="#1d2321",e.fillRect(0,0,this.width,this.height);const i=t.imagery;if(!i)return;const n=this.toCanvas(t.bounds,i.bounds.north,i.bounds.west),s=this.toCanvas(t.bounds,i.bounds.south,i.bounds.east);e.drawImage(i.source,n.x,n.y,s.x-n.x,s.y-n.y)}paintNight(t=0){if(t<=0)return;const{ctx:e}=this;e.save(),e.fillStyle=`rgba(6, 12, 30, ${Math.min(t,1)*.78})`,e.fillRect(0,0,this.width,this.height),e.restore()}paintDecor(t){const{ctx:e}=this;for(const i of t.decor){const n=this.toCanvas(t.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}),e.beginPath(),e.rect(n.x-3.5,n.y-3.5,7,7),e.fillStyle="rgba(120, 220, 255, 0.85)",e.fill(),e.lineWidth=1.5,e.strokeStyle="rgba(0, 0, 0, 0.7)",e.stroke(),i.headingDeg===void 0)continue;const s=(i.headingDeg-90)*Math.PI/180;e.beginPath(),e.moveTo(n.x,n.y),e.lineTo(n.x+Math.cos(s)*10,n.y+Math.sin(s)*10),e.lineWidth=3,e.strokeStyle="rgba(0, 0, 0, 0.6)",e.stroke(),e.lineWidth=1.5,e.strokeStyle="rgba(120, 220, 255, 0.9)",e.stroke()}}paintPath(t){if(!t.path.moved)return;const{ctx:e}=this,i=t.path.points.map(n=>this.toCanvas(t.bounds,n.lat,n.lng));e.beginPath(),e.moveTo(i[0].x,i[0].y);for(const n of i.slice(1))e.lineTo(n.x,n.y);e.lineJoin="round",e.lineCap="round",e.strokeStyle="rgba(0, 0, 0, 0.65)",e.lineWidth=5,e.stroke(),e.strokeStyle="rgba(255, 255, 255, 0.9)",e.lineWidth=2,e.stroke()}paintTraces(t){const{ctx:e}=this;for(const i of t.traces??[]){const n=i.points.map(r=>this.toCanvas(t.bounds,r.lat,r.lng));if(n.length===0)continue;const s=i.color??P2;if(i.kind==="point")e.beginPath(),e.moveTo(n[0].x,n[0].y-6),e.lineTo(n[0].x+6,n[0].y),e.lineTo(n[0].x,n[0].y+6),e.lineTo(n[0].x-6,n[0].y),e.closePath(),e.fillStyle=s,e.fill(),e.lineWidth=1.5,e.strokeStyle="rgba(0, 0, 0, 0.8)",e.stroke();else{e.beginPath(),e.moveTo(n[0].x,n[0].y);for(const r of n.slice(1))e.lineTo(r.x,r.y);i.kind==="polygon"&&e.closePath(),e.lineJoin="round",e.setLineDash([]),e.strokeStyle="rgba(0, 0, 0, 0.65)",e.lineWidth=4.5,e.stroke(),e.setLineDash([9,5]),e.strokeStyle=s,e.lineWidth=2.5,e.stroke(),e.setLineDash([])}if(i.label){e.font="11px sans-serif",e.textAlign="left",e.textBaseline="middle";let r=n[0];if(i.kind==="line"&&t.position){const o=this.toCanvas(t.bounds,t.position.lat,t.position.lng);r=n.reduce((c,l)=>Math.hypot(l.x-o.x,l.y-o.y)>Math.hypot(c.x-o.x,c.y-o.y)?l:c)}this.paintOutlinedText(i.label,r.x+9,r.y-9)}}}paintCone(t,e){const{headingDeg:i,coneHalfAngleDeg:n}=t;if(i===void 0||n===void 0)return;const{ctx:s}=this,r=this.toCanvas(t.bounds,e.lat,e.lng),o=Math.hypot(this.width,this.height),c=(i-90)*Math.PI/180,l=n*Math.PI/180;s.save(),s.beginPath(),s.moveTo(r.x,r.y),s.arc(r.x,r.y,o,c-l,c+l),s.closePath();const h=s.createRadialGradient(r.x,r.y,0,r.x,r.y,o);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(t){const{ctx:e}=this;e.textAlign="center",e.textBaseline="middle",e.font="bold 10px sans-serif";for(const i of[...t.markers].sort((n,s)=>Number(n.current)-Number(s.current))){const n=this.toCanvas(t.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:Rr.MARKER_RADIUS_PX}),e.beginPath(),e.arc(n.x,n.y,Rr.MARKER_RADIUS_PX,0,Math.PI*2),e.fillStyle=i.current?"rgba(255, 224, 130, 0.95)":"rgba(0, 0, 0, 0.55)",e.fill(),e.lineWidth=2,e.strokeStyle="rgba(255, 255, 255, 0.9)",e.stroke(),e.fillStyle=i.current?"#1d2321":"#fff",e.fillText(i.label,n.x,n.y)}}paintObserver(t,e){const{ctx:i}=this,n=this.toCanvas(t.bounds,e.lat,e.lng);t.observerLabel&&this.targets.push({kind:"observer",label:t.observerLabel,lat:e.lat,lng:e.lng,x:n.x,y:n.y,radius:8});const s=t.markers.some(r=>{if(!r.current)return!1;const o=je(r.lat,r.lng,e.lat,e.lng);return Math.hypot(o.x,o.z)<=Rr.ON_MARKER_M});i.beginPath(),i.arc(n.x,n.y,s?Rr.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:t}=this,e=this.width-14,i=16;t.beginPath(),t.moveTo(e,i-9),t.lineTo(e-4.5,i+5),t.lineTo(e,i+2),t.lineTo(e+4.5,i+5),t.closePath(),t.fillStyle="rgba(255, 255, 255, 0.92)",t.strokeStyle="rgba(0, 0, 0, 0.6)",t.lineWidth=1,t.fill(),t.stroke(),t.font="bold 9px sans-serif",t.textAlign="center",t.textBaseline="top",t.strokeText("N",e,i+6),t.fillText("N",e,i+6)}paintFooter(t,e){const{ctx:i}=this;i.font="9px sans-serif",i.textBaseline="bottom";const n=e?this.wrap(e,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=(t.south+t.north)/2,c=Math.abs(je(r,t.east,r,t.west).x)/this.width,l=Rr.SCALE_STEPS_M.find(f=>f/c<=this.width/3);if(l===void 0)return;const h=l/c,u=8,d=s-3;i.lineWidth=3,i.strokeStyle="rgba(0, 0, 0, 0.6)",i.beginPath(),i.moveTo(u,d),i.lineTo(u+h,d),i.stroke(),i.lineWidth=1.5,i.strokeStyle="rgba(255, 255, 255, 0.95)",i.stroke(),i.textAlign="left",this.paintOutlinedText(l>=1e3?`${l/1e3} km`:`${l} m`,u,d-3)}paintOutlinedText(t,e,i){const{ctx:n}=this;n.lineWidth=3,n.strokeStyle="rgba(0, 0, 0, 0.75)",n.strokeText(t,e,i),n.fillStyle="#fff",n.fillText(t,e,i)}wrap(t,e){const i=[];let n="";for(const s of t.split(" ")){const r=n?`${n} ${s}`:s;n&&this.ctx.measureText(r).width>e?(i.push(n),n=s):n=r}return n&&i.push(n),i}}class Ye{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(t,e,i){const n=Math.min(Ye.MAX_ZOOM,Math.max(Ye.MIN_ZOOM,this.zoom*i)),s=this.centerX+(t-.5)/this.zoom,r=this.centerY+(e-.5)/this.zoom;this.centerX=s-(t-.5)/n,this.centerY=r-(e-.5)/n,this.zoom=n}panBy(t,e){this.centerX-=t/this.zoom,this.centerY-=e/this.zoom}refit(t,e){if(!this.changed)return;const i=this.boundsWithin(t),n=Ye.mercatorY01(e.north),s=Ye.mercatorY01(e.south),r=Ye.mercatorY01(i.north),o=Ye.mercatorY01(i.south);this.zoom=(e.east-e.west)/(i.east-i.west),this.centerX=((i.west+i.east)/2-e.west)/(e.east-e.west),this.centerY=((r+o)/2-n)/(s-n)}keepInView(t,e,i){if(!this.changed)return!1;const n=this.boundsWithin(t),s=Ye.mercatorY01(n.north),r=Ye.mercatorY01(n.south),o=(e.lng-n.west)/(n.east-n.west),c=(Ye.mercatorY01(e.lat)-s)/(r-s);return o>=i&&o<=1-i&&c>=i&&c<=1-i?!1:(this.panBy(.5-o,.5-c),!0)}boundsWithin(t){if(!this.changed)return t;const e=.5/this.zoom,i=Ye.mercatorY01(t.north),n=Ye.mercatorY01(t.south),s=t.east-t.west;return{west:t.west+(this.centerX-e)*s,east:t.west+(this.centerX+e)*s,north:Ye.latitudeAt(i+(this.centerY-e)*(n-i)),south:Ye.latitudeAt(i+(this.centerY+e)*(n-i))}}static including(t,e,i=3){const n=(t.north+t.south)/2,s=(t.east+t.west)/2,r=je(n,t.east,n,s).x;let o=r;for(const c of e){const{x:l,z:h}=je(c.lat,c.lng,n,s),u=Math.max(Math.abs(l),Math.abs(h));u<=r*i&&(o=Math.max(o,u*1.15))}return o<=r?t:{north:Sn(0,-o,n,s).lat,south:Sn(0,o,n,s).lat,east:Sn(o,0,n,s).lng,west:Sn(-o,0,n,s).lng}}static expand(t,e){const i=t.east-t.west,n=t.north-t.south;return{west:t.west-i*e,east:t.east+i*e,south:t.south-n*e,north:t.north+n*e}}static pointAt(t,e,i){const n=Ye.mercatorY01(t.north),s=Ye.mercatorY01(t.south);return{lat:Ye.latitudeAt(n+i*(s-n)),lng:t.west+e*(t.east-t.west)}}static mercatorY01(t){const e=t*Math.PI/180;return(1-Math.log(Math.tan(e)+1/Math.cos(e))/Math.PI)/2}static latitudeAt(t){return Math.atan(Math.sinh(Math.PI*(1-2*t)))*180/Math.PI}}const wn=256,qf=3,L2=32768;class O2{fetchImpl;tileUrlTemplate;constructor(t={}){this.fetchImpl=t.fetchImpl??fetch.bind(globalThis),this.tileUrlTemplate=t.tileUrlTemplate??"https://s3.amazonaws.com/elevation-tiles-prod/terrarium/{z}/{x}/{y}.png"}async getElevationGrid(t,e){const i=(t.south+t.north)/2,n=(t.west+t.east)/2,s=Math.abs(je(i,t.east,i,t.west).x),r=Math.abs(je(t.north,n,t.south,n).z),o=R2(i,Math.max(s,r)),{tiles:c}=Kg(n,i,o,qf),l=qf*wn,h=new Float32Array(l*l),u=c[0];await Promise.all(c.map(f=>this.decodeTileInto(f,u,h,l)));const d=new Float32Array(e.width*e.height);for(let f=0;f<e.height;f++){const p=t.north+(t.south-t.north)*(f/(e.height-1));for(let v=0;v<e.width;v++){const m=t.west+(t.east-t.west)*(v/(e.width-1));d[f*e.width+v]=this.sampleAt(p,m,o,u,h,l)}}return{heights:d,width:e.width,height:e.height,bounds:t}}async decodeTileInto(t,e,i,n){const s=this.tileUrlTemplate.replace("{z}",String(t.z)).replace("{x}",String(t.x)).replace("{y}",String(t.y)),r=await this.fetchImpl(s);if(!r.ok)throw new Error(`Elevation tile fetch failed (${r.status}): ${s}`);const o=await createImageBitmap(await r.blob()),c=document.createElement("canvas");c.width=wn,c.height=wn;const l=c.getContext("2d");if(!l)throw new Error("2D canvas context unavailable");l.drawImage(o,0,0);const{data:h}=l.getImageData(0,0,wn,wn),u=(t.x-e.x)*wn,d=(t.y-e.y)*wn;for(let f=0;f<wn;f++)for(let p=0;p<wn;p++){const v=(f*wn+p)*4,m=h[v]*256+h[v+1]+h[v+2]/256-L2,g=u+p,S=d+f;i[S*n+g]=m}}sampleAt(t,e,i,n,s,r){const{x:o,y:c}=qg(e,t,i),l=(o-n.x)*wn,h=(c-n.y)*wn,u=Math.max(0,Math.min(r-1,Math.floor(l))),d=Math.max(0,Math.min(r-1,Math.floor(h))),f=Math.min(r-1,u+1),p=Math.min(r-1,d+1),v=l-u,m=h-d,g=s[d*r+u],S=s[d*r+f],x=s[p*r+u],M=s[p*r+f],b=g+(S-g)*v,w=x+(M-x)*v;return b+(w-b)*m}}const El=256,N2=5;async function F2(a,t,e,i){const n=(a.south+a.north)/2,s=(a.west+a.east)/2,r=Math.abs(je(n,a.east,n,a.west).x),o=Math.abs(je(a.north,s,a.south,s).z),c=Math.max(r,o),{zoom:l,gridSize:h}=U2(n,c,Math.max(t.width,t.height)),{tiles:u,bounds:d}=Kg(s,n,l,h),f=h*El,p=document.createElement("canvas");p.width=f,p.height=f;const v=p.getContext("2d");if(!v)throw new Error("2D canvas context unavailable");const m=u[0];await Promise.all(u.map(async M=>{const b=e(M),w=await i(b);if(!w.ok)throw new Error(`Imagery tile fetch failed (${w.status}): ${b}`);const T=await createImageBitmap(await w.blob());v.drawImage(T,(M.x-m.x)*El,(M.y-m.y)*El)}));const g=Math.min(Math.max(t.width,t.height),f);if(g===f)return{source:p,width:f,height:f,bounds:d};const S=document.createElement("canvas");S.width=g,S.height=g;const x=S.getContext("2d");if(!x)throw new Error("2D canvas context unavailable");return x.drawImage(p,0,0,f,f,0,0,g,g),{source:S,width:g,height:g,bounds:d}}function U2(a,t,e){let i=D2(a,t/Math.max(1,e)),n=$f(a,i,t);for(;n>N2&&i>0;)i--,n=$f(a,i,t);return{zoom:i,gridSize:n,mPerPixel:Yg(a,i)/El}}function $f(a,t,e){const i=Math.ceil(e/2/Yg(a,t));return Math.max(3,2*i+1)}class k2{attribution="Imagery © Esri, Maxar, Earthstar Geographics, and the GIS User Community";fetchImpl;tileUrlTemplate;constructor(t={}){this.fetchImpl=t.fetchImpl??fetch.bind(globalThis),this.tileUrlTemplate=t.tileUrlTemplate??"https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"}async getImageryTexture(t,e){return F2(t,e,i=>this.tileUrlTemplate.replace("{z}",String(i.z)).replace("{y}",String(i.y)).replace("{x}",String(i.x)),this.fetchImpl)}}class Hn{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;static ENDPOINTS=["https://overpass-api.de/api/interpreter","https://overpass.kumi.systems/api/interpreter","https://overpass.private.coffee/api/interpreter"];fetchImpl;endpoints;constructor(t={}){this.fetchImpl=t.fetchImpl??fetch.bind(globalThis),this.endpoints=t.endpoints??Hn.ENDPOINTS}static queue=Promise.resolve();static RETRY_MS=4e3;async getRoads(t){const e=`${t.south},${t.west},${t.north},${t.east}`,i=`[out:json][timeout:30];way["highway"~"^(${Hn.DRIVABLE.join("|")})$"](${e});out geom;`;return this.waysFrom(await this.queued(()=>this.ask(i)))}waysFrom(t){const e=[];for(const i of t.elements??[]){const n=i.geometry,s=i.tags;!s||!n||n.length<2||e.push({id:`osm-${i.id??e.length}`,name:s.name,surface:Hn.surfaceOf(s),widthM:Hn.widthOf(s),points:n.map(r=>({lat:r.lat,lng:r.lon}))})}return e}queued(t){const e=Hn.queue.then(t,t);return Hn.queue=e.catch(()=>{}),e}async ask(t){let e;for(const i of this.endpoints)for(let n=0;n<2;n++){try{const s=await this.fetchImpl(`${i}?data=${encodeURIComponent(t)}`);if(s.ok)return await s.json();if(e=new Error(`${new URL(i).host} refused (${s.status})`),s.status!==429&&s.status!==504)break}catch(s){e=new Error(`${new URL(i).host} unreachable (${String(s)})`);break}await new Promise(s=>setTimeout(s,Hn.RETRY_MS))}throw e??new Error("No Overpass instance answered")}static widthOf(t){const e=Number.parseFloat(t.width??t.est_width??"");if(Number.isFinite(e)&&e>0)return e;const i=Number.parseInt(t.lanes??"",10);return Number.isFinite(i)&&i>0?i*3.5:Hn.WIDTH_M[t.highway]??Hn.DEFAULT_WIDTH_M}static surfaceOf(t){const e=t.surface;return e==="dirt"||e==="earth"||e==="mud"?"dirt":e==="gravel"||e==="fine_gravel"||e==="compacted"||e==="ground"||e==="sand"||e==="unpaved"?"gravel":e?"paved":t.highway==="track"?"gravel":"paved"}}const Rh="https://ufoathome.org/roads/index.json";class Ra{attributionRead;contemporaryRead;fetchImpl;indexUrls;fallback;index;static shared=new Map;sharing;constructor(t={}){this.sharing=!t.fetchImpl,this.fetchImpl=t.fetchImpl??fetch.bind(globalThis),this.indexUrls=t.indexUrls??Ra.defaultIndexUrls(),this.fallback=t.fallback}get attribution(){return this.attributionRead??this.fallback?.attribution??"Roads © OpenStreetMap contributors"}get contemporary(){return this.contemporaryRead??this.fallback?.contemporary??!0}async getRoads(t){const e=await this.held(t);if(e)return e;if(!this.fallback)return[];const i=await this.fallback.getRoads(t);return this.attributionRead=this.fallback.attribution,this.contemporaryRead=this.fallback.contemporary,i}async held(t){let e;try{e=await this.load()}catch{return}const i=e.find(({entry:n})=>n.north>=t.north&&n.south<=t.south&&n.east>=t.east&&n.west<=t.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 t=this.indexUrls.join(`
1412
- `);let e=Ra.shared.get(t);return e||(e=this.fetchFirstAvailable(),Ra.shared.set(t,e),e.then(i=>{i.length===0&&Ra.shared.delete(t)})),this.index=e}async fetchFirstAvailable(){for(const t of this.indexUrls)try{const e=await this.fetchImpl(t);if(!e.ok)continue;const i=await e.json();if(Array.isArray(i?.entries))return i.entries.map(n=>({entry:n,indexUrl:t}))}catch{}return[]}static defaultIndexUrls(){const t=`?v=${encodeURIComponent("0.97.0")}`,e=typeof location>"u"?void 0:new URL("/roads/index.json",location.href).href;return(e&&e!==Rh?[e,Rh]:[Rh]).map(i=>i+t)}}function z2(){return{elevation:new O2,imagery:Zg(),roads:B2()}}function Zg(){return new k2}function B2(){return new Ra({fallback:new Hn})}const H2=new Set,ka="show-observer-map",za="hide-milestones";class pe extends HTMLElement{static get observedAttributes(){return["src",ka,za]}shadow;stageElement;canvas;canvasRenderer;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 Ye;observerMapDrag;suppressObserverMapClick=!1;observerMapImageryTimer;observerPlacing=!1;seekInput;playbackFlash;milestoneMarks;milestoneCaption;timeStartLabel;timeEndLabel;timePill;muteButton;volumeInput;controlsRow;momentsBox;momentsButton;momentsCurrent;momentsMenu;moreButton;controlsRight;seekSegments;seekDot;seekPreview;seekPreviewCanvas;seekPreviewTitle;seekPreviewTime;observerPath;observerMapBounds;observerMapImagery;observerMapImageryBounds;observerMapImageryViewWidth=0;observerMapImageryLoading=!1;observerMapImageryCredit;observerMapImageryFailed=!1;creditShownExternally=!1;lookYawDeg=0;lookPitchDeg=0;milestonesShown=!0;currentSighting=hh.create();issues=[];issueCheck=0;sightingAudio=new g2;soundPreview;player;loopEnabled=!1;playbackBeforeClick;highlightedSourceIds=new Set;paintsShapes=!0;steadyObserver=!1;selectionShown=!0;overlayPainter;enableClickToPlay=!0;fullscreenTarget;messages=Hg;realDurationMs;realStartMs;showClockTime=!0;handleFullscreenChange=()=>{this.updateFullscreenButton(),this.updateMuteButton(),this.resizeObserverMap()};controlsFitObserver=typeof ResizeObserver>"u"?void 0:new ResizeObserver(()=>this.fitControls());controlsMutations;fitControls(){const t=this.controlsRow,e=t.classList.contains("more-open"),i=()=>t.scrollWidth>t.clientWidth+1,n=!this.momentsMenu.hidden;if(this.momentsMenu.hidden=!0,t.classList.remove("narrow","more-open","nomoments","compact","tiny"),t.clientWidth>0&&i()){t.classList.add("narrow");for(const s of["nomoments","compact","tiny"]){if(!i())break;t.classList.add(s)}e&&t.classList.add("more-open")}this.momentsMenu.hidden=!n,this.updateMoreButton()}setControlsFolded(t){this.controlsRow.classList.toggle("more-open",!t),this.updateMoreButton()}updateMoreButton(){const t=this.controlsRow.classList.contains("more-open");pe.setIcon(this.moreButton,t?Vt.UNFOLDED:Vt.FOLDED);const e=t?this.messages.fewerControls:this.messages.moreControls;this.moreButton.title=e,this.moreButton.setAttribute("aria-label",e),this.moreButton.setAttribute("aria-expanded",String(t))}addControl(t){this.controlsRight.insertBefore(t,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=t=>{t.key==="Escape"&&this.exitSimulatedFullscreen()};handlePointerMove=t=>{const e=this.canvasPointFromEvent(t),i=e&&this.shapeAt(e.x,e.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=`${t.clientX-s.left+12}px`,this.tooltip.style.top=`${t.clientY-s.top+12}px`};handleObserverMapPointerMove=t=>{if(this.dragObserverMap(t))return;const e=this.observerMapTargetFrom(t);if(!e){if(!this.observerPlacing){this.tooltip.hidden=!0,this.observerMapCanvas.style.cursor="grab";return}this.observerMapCanvas.style.cursor="crosshair",this.showObserverMapTooltip(t,this.messages.placeObserverHere);return}this.observerMapCanvas.style.cursor="pointer",this.showObserverMapTooltip(t,e.label)};showObserverMapTooltip(t,e){this.tooltip.textContent=e,this.tooltip.hidden=!1;const i=this.stageElement.getBoundingClientRect();this.tooltip.style.left=`${t.clientX-i.left+12}px`,this.tooltip.style.top=`${t.clientY-i.top+12}px`}handleObserverMapClick=t=>{if(this.suppressObserverMapClick){this.suppressObserverMapClick=!1;return}const e=this.observerMapTargetFrom(t);if(!e){this.observerPlacing&&this.placeObserverFrom(t);return}if(e.kind==="milestone"&&e.t!==void 0){this.player.seek(e.t);return}this.dispatchEvent(new CustomEvent("lookat",{detail:{lat:e.lat,lng:e.lng,kind:e.kind},bubbles:!0,composed:!0}))};observerMapTargetFrom(t){const e=this.observerMapCanvas.getBoundingClientRect();if(!(e.width===0||e.height===0))return this.observerMapRenderer.hitTest((t.clientX-e.left)/e.width*this.observerMapCanvas.width,(t.clientY-e.top)/e.height*this.observerMapCanvas.height)}handlePointerLeave=()=>{this.tooltip.hidden=!0};handleObserverMapPointerDown=t=>{t.button===0&&(this.suppressObserverMapClick=!1,this.observerMapDrag={pointerId:t.pointerId,startX:t.clientX,startY:t.clientY,lastX:t.clientX,lastY:t.clientY,moved:!1})};handleObserverMapPointerUp=t=>{const e=this.observerMapDrag;!e||e.pointerId!==t.pointerId||(this.observerMapDrag=void 0,this.observerMapCanvas.classList.remove("dragging"),e.moved&&(this.suppressObserverMapClick=!0,this.paintObserverMap(this.currentTime),this.observerMapCanvas.hasPointerCapture?.(t.pointerId)&&this.observerMapCanvas.releasePointerCapture(t.pointerId)))};dragObserverMap(t){const e=this.observerMapDrag;if(!e||e.pointerId!==t.pointerId)return!1;if(!e.moved){if(Math.hypot(t.clientX-e.startX,t.clientY-e.startY)<pe.OBSERVER_MAP_DRAG_PX)return!1;e.moved=!0,this.tooltip.hidden=!0,this.observerMapCanvas.classList.add("dragging"),this.observerMapCanvas.setPointerCapture?.(t.pointerId)}const i=this.observerMapCanvas.getBoundingClientRect();return i.width>0&&i.height>0&&(this.observerMapView.panBy((t.clientX-e.lastX)/i.width,(t.clientY-e.lastY)/i.height),this.observerMapViewChanged()),e.lastX=t.clientX,e.lastY=t.clientY,!0}static OBSERVER_MAP_DRAG_PX=4;handleObserverMapWheel=t=>{t.preventDefault();const e=this.observerMapCanvas.getBoundingClientRect();if(e.width===0||e.height===0)return;const i=t.deltaMode===0?t.deltaY:t.deltaY*40;this.zoomObserverMap((t.clientX-e.left)/e.width,(t.clientY-e.top)/e.height,Math.exp(-i*.002))};zoomObserverMap(t,e,i){this.observerMapView.zoomAt(t,e,i),this.observerMapViewChanged()}observerMapViewChanged(){this.mapFitButton.hidden=!this.observerMapView.changed,this.mapZoomInButton.disabled=this.observerMapView.zoomFactor>=Ye.MAX_ZOOM,this.mapZoomOutButton.disabled=this.observerMapView.zoomFactor<=Ye.MIN_ZOOM,this.paintObserverMap(this.currentTime),this.scheduleObserverMapImagery()}scheduleObserverMapImagery(){this.observerMapImageryTimer===void 0&&(this.observerMapImageryTimer=setTimeout(()=>{this.observerMapImageryTimer=void 0,this.loadObserverMapImagery()},pe.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(t){const e=this.observerMapViewBounds,i=this.observerMapCanvas.getBoundingClientRect();if(!e||i.width===0||i.height===0)return;const n=Ye.pointAt(e,(t.clientX-i.left)/i.width,(t.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 t=document.createElement("template");t.innerHTML=`<style>${Gv}</style>${Hv}`,this.shadow.appendChild(t.content.cloneNode(!0)),this.stageElement=this.shadow.getElementById("stage"),this.canvas=this.shadow.getElementById("canvas"),this.canvasRenderer=new ec(this.canvas.getContext("2d")),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",e=>{e.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 Rr(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.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",e=>{e.key!=="Enter"&&e.key!==" "||(e.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",e=>{this.suspendForScrub(),this.seekSnapArmed=!0,this.nameMarkUnder(e),this.beginTouchScrub(e)}),this.seekInput.addEventListener("pointerup",e=>{this.seekSnapArmed=!1,this.endTouchScrub(e)}),this.seekInput.addEventListener("pointercancel",e=>this.endTouchScrub(e)),this.seekInput.addEventListener("pointermove",e=>{this.nameMarkUnder(e),this.hoverSeek(e),this.touchScrub(e)}),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 e of["touchend","click"])this.stageElement.addEventListener(e,()=>this.sightingAudio.resume(),!0);this.stageElement.addEventListener("pointermove",()=>this.touchedStage()),this.canvas.addEventListener("click",e=>{if(this.enableClickToPlay){if(this.tapRevealedOnly){this.tapRevealedOnly=!1;return}e.detail<=1&&(this.playbackBeforeClick={state:this.playbackState,time:this.currentTime}),this.togglePlayPause()}}),this.canvas.addEventListener("dblclick",e=>{this.enableClickToPlay&&(e.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.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 t=this.getAttribute("src");t&&this.loadFromSrc(t)}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.controlsFitObserver?.disconnect(),this.controlsMutations?.disconnect(),this.exitSimulatedFullscreen(),this.sightingAudio.dispose()}attributeChangedCallback(t,e,i){t==="src"&&i&&i!==e&&this.isConnected&&this.loadFromSrc(i),t===ka&&this.applyObserverMapDefault(),t===za&&this.setMilestonesShown(!this.hasAttribute(za))}async loadFromSrc(t){this.sightingData=await Ug.json(t)}get sightingData(){return v2(this.currentSighting)}set sightingData(t){this.player.stop(),this.soundPreview=void 0,this.sightingAudio.silence(),this.currentSighting=x2(t),this.issuesPanel.hidden=!0,this.issuesButton.setAttribute("aria-expanded","false"),this.reportIssues(t,this.currentSighting),this.observerMapView.reset(),this.mapFitButton.hidden=!0,this.observerMapAsked=!1,this.player=this.createPlayer(),this.updateTimeLabels(),this.updatePlayPauseButton(),this.refresh(),this.applyObserverMapDefault()}get recordingIssues(){return this.issues}async reportIssues(t,e){const i=++this.issueCheck;let n=[];try{const{default:s}=await $i(async()=>{const{default:r}=await import("./sightingSchema-07Ux2CE8.js");return{default:r}},[],import.meta.url);n=new Bn(s).issues(t)}catch{}i===this.issueCheck&&(this.issues=[...n,...e.loadIssues],Za.warn(this.issues,e.id),this.renderIssues(),this.dispatchEvent(new CustomEvent(G2,{detail:{issues:this.issues},bubbles:!0,composed:!0})))}renderIssues(){const t=this.issues.length;this.issuesBox.hidden=t===0,this.shadow.getElementById("issues-count").textContent=String(t);const e=this.messages.recordingIssues.replace("{count}",String(t));this.issuesButton.title=e,this.issuesButton.setAttribute("aria-label",e),this.shadow.getElementById("issues-title").textContent=e,this.shadow.getElementById("issues-list").replaceChildren(...this.issues.map(i=>{const n=document.createElement("li");return n.textContent=Za.text(i,this.messages.issueTemplates),n}))}get sighting(){return this.currentSighting}previewSound(t){this.soundPreview=t,this.sightingAudio.resume(),this.sightingAudio.setSound(t)}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(t){this.player.seek(t)}get seekableDuration(){return this.player.seekableDuration}get autoReplayEnabled(){return this.loopEnabled}set autoReplayEnabled(t){t!==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(t){if(t!==this.clockHeld){if(this.clockHeld=t,t){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(t){this.toolbar.classList.toggle("hidden",!t),t?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(t){this.currentSighting.event.durationSeconds=t,this.updateTimeLabels(),this.refresh(),this.updatePlayPauseButton()}set selectedSourceIds(t){const e=new Set(t);e.size===this.highlightedSourceIds.size&&[...e].every(n=>this.highlightedSourceIds.has(n))||(this.highlightedSourceIds=e,this.refresh())}hasVisibleShapeAt(t,e){return this.shapeAt(t,e)!==void 0}refresh(){this.applyFrameFormat(),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(t){const e=[this.milestonesButton,this.referencesButton,this.referenceOpacityInput,this.tracesButton,this.observerMapButton];if(t)for(const i of e)t.appendChild(i);else{const i=this.fullscreenButton.parentElement===this.controlsRight?this.fullscreenButton:null;for(const n of e)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 t=this.currentSighting.references;!this.referenceOpacityTouched&&t.length>0&&(this.referenceOpacityInput.value=String(t[0].opacity));for(const e of[...this.referenceViews.keys()])t.some(i=>i.id===e)||this.referenceViews.delete(e);this.severalReferences?this.referencesMenu.hidden||this.renderReferencesMenu():this.closeReferencesMenu(),this.updateReferencesButton(),this.severalReferences&&this.dispatchReferenceView()}viewOfReference(t){let e=this.referenceViews.get(t.id);return e||(e={shown:!0,opacity:t.opacity},this.referenceViews.set(t.id,e)),e}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=t=>{const e=t.composedPath();e.includes(this.referencesMenu)||e.includes(this.referencesButton)||this.closeReferencesMenu()};handleReferencesMenuKey=t=>{t.key==="Escape"&&(this.closeReferencesMenu(),this.referencesButton.focus())};placeReferencesMenu(){const t=this.referencesButton.getBoundingClientRect(),e=this.referencesMenu,i=4;e.style.bottom=`${Math.max(i,window.innerHeight-t.top+i)}px`,e.style.top="auto";const n=e.getBoundingClientRect().width;e.style.left=`${Math.max(i,Math.min(t.left,window.innerWidth-n-i))}px`}renderReferencesMenu(){const t=this.currentSighting.references.map(e=>{const i=this.viewOfReference(e),n=this.said.read(e.title)??e.id,s=document.createElement("div");s.className="reference-row";const r=document.createElement("label"),o=document.createElement("input");o.type="checkbox",o.checked=i.shown;const c=document.createElement("span");c.textContent=n,c.title=n,r.append(o,c);const l=document.createElement("input");return l.type="range",l.min="0",l.max="1",l.step="0.05",l.value=String(i.opacity),l.title=this.messages.referenceOpacity,l.setAttribute("aria-label",`${this.messages.referenceOpacity}: ${n}`),l.disabled=!i.shown,o.addEventListener("change",()=>{i.shown=o.checked,l.disabled=!i.shown,this.updateReferencesButton(),this.dispatchReferenceView()}),l.addEventListener("input",()=>{i.opacity=Number(l.value),this.dispatchReferenceView()}),s.append(r,l),s});this.referencesMenu.setAttribute("aria-label",this.messages.referencesMenu),this.referencesMenu.replaceChildren(...t)}updateReferencesButton(){const t=this.currentSighting.references.length>0,e=this.severalReferences,i=e?this.currentSighting.references.some(s=>this.viewOfReference(s).shown):this.referencesShownState;this.referencesButton.hidden=!t,this.referenceOpacityInput.hidden=!t||!this.referencesShownState||e,this.referencesButton.setAttribute("aria-pressed",String(i)),e?this.referencesButton.setAttribute("aria-haspopup","true"):this.referencesButton.removeAttribute("aria-haspopup"),pe.setIcon(this.referencesButton,i?Vt.PICTURES_ON:Vt.PICTURES_OFF);const n=e?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)),pe.setIcon(this.tracesButton,this.tracesShownState?Vt.TRACES_ON:Vt.TRACES_OFF);const t=this.tracesShownState?this.messages.hideTraces:this.messages.showTraces;this.tracesButton.title=t,this.tracesButton.setAttribute("aria-label",t)}dispatchReferenceView(){const t=this.severalReferences?Object.fromEntries(this.currentSighting.references.map(e=>[e.id,{...this.viewOfReference(e)}])):void 0;this.dispatchEvent(new CustomEvent("referenceview",{detail:{shown:this.referencesShown,opacity:this.referenceOpacity,views:t}}))}refreshMilestoneMarks(){const t=this.player.seekableDuration,e=t>0?Bo(this.sighting.milestones):[];this.milestoneMarks.replaceChildren(...e.map(i=>{const n=document.createElement("button");n.type="button",n.className="milestone-mark",n.style.left=`${Math.min(Math.max(i.t/t,0),1)*100}%`;const s=this.said.read(i.label)??"",r=this.said.read(i.note),o=r?`${s} — ${r}`:s;return n.title=o,n.setAttribute("aria-label",o),n.dataset.t=String(i.t),n.addEventListener("click",()=>this.player.seek(i.t)),n})),this.refreshSeekSegments(t,e.map(i=>i.t)),this.refreshMomentsPicker(e)}refreshMomentsPicker(t){const e=this.milestonesShown&&t.length>0;this.momentsBox.hidden=!e,this.closeMomentsMenu(),this.momentsMenu.replaceChildren(...t.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)??"",o=this.said.read(i.note);return s.textContent=o?`${r} — ${o}`: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(t){const i=(t?this.said.read(t.label)??"":"")||this.messages.moments;this.momentsCurrent.textContent!==i&&(this.momentsCurrent.textContent=i);for(const n of this.momentsMenu.querySelectorAll("button")){const s=t!==void 0&&Number(n.dataset.t)===t.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=t=>{if(!this.momentsMenu.hidden){if(t instanceof KeyboardEvent){t.key==="Escape"&&this.closeMomentsMenu();return}t.composedPath().some(e=>e===this.momentsMenu||e===this.momentsButton)||this.closeMomentsMenu()}};seekSegmentList=[];refreshSeekSegments(t,e){const n=[0,...this.milestonesShown&&t>0?[...new Set(e.filter(r=>r>0&&r<t))].sort((r,o)=>r-o):[],Math.max(t,0)];this.seekSegmentList=[];const s=[];for(let r=0;r<n.length-1;r++){const o=document.createElement("div");o.className="seek-segment",o.style.flexGrow=String(Math.max(n[r+1]-n[r],1));const c=document.createElement("i");c.className="seek-hover";const l=document.createElement("i");l.className="seek-played",o.append(c,l),s.push(o),this.seekSegmentList.push({start:n[r],end:n[r+1],element:o,played:l,hover:c})}this.seekSegments.replaceChildren(...s),this.paintSeekProgress(this.player.time)}static fillOf(t,e){const i=t.end-t.start,n=i>0?(e-t.start)/i:e>=t.end?1:0;return`${Math.min(Math.max(n,0),1)*100}%`}paintSeekProgress(t){for(const i of this.seekSegmentList)i.played.style.width=pe.fillOf(i,t);const e=this.player.seekableDuration;this.seekDot.style.left=`${e>0?Math.min(Math.max(t/e,0),1)*100:0}%`}hoverSeek(t){const e=this.seekInput.getBoundingClientRect(),i=this.player.seekableDuration;if(e.width<=0||i<=0)return;const n=Math.min(Math.max((t.clientX-e.left)/e.width,0),1),s=n*i,r=this.seekSegmentList.length-1;this.seekSegmentList.forEach((f,p)=>{f.hover.style.width=pe.fillOf(f,s),f.element.classList.toggle("hovered",s>=f.start&&(s<f.end||p===r))});const o=this.milestonesShown?this.sighting.milestones:[],c=o.length>0?Ah(o,s):void 0,l=c?this.said.read(c.label)??"":"",h=c?this.said.read(c.note):void 0,u=h?`${l} — ${h}`:l;this.seekPreviewTitle.textContent=u,this.seekPreviewTime.textContent=this.formatPosition(s),this.seekPreview.hidden=!1;const d=this.seekPreview.offsetWidth;this.seekPreview.style.left=`${Math.min(Math.max(n*e.width-d/2,0),Math.max(e.width-d,0))}px`,this.paintSeekPreview(s)}leaveSeek(){for(const t of this.seekSegmentList)t.hover.style.width="0",t.element.classList.remove("hovered");this.seekPreview.hidden=!0}seekPreviewPainter;paintSeekPreview(t){const e=this.seekPreviewPainter;this.seekPreviewCanvas.hidden=e===void 0,e?.(t,this.seekPreviewCanvas)}scrubbingPointer;beginTouchScrub(t){if(t.pointerType!=="mouse"){this.scrubbingPointer=t.pointerId;try{this.seekInput.setPointerCapture(t.pointerId)}catch{}this.seekToPointer(t)}}touchScrub(t){t.pointerId===this.scrubbingPointer&&this.seekToPointer(t)}endTouchScrub(t){t.pointerId===this.scrubbingPointer&&(this.scrubbingPointer=void 0,this.seekToPointer(t))}seekToPointer(t){const e=this.seekInput.getBoundingClientRect(),i=this.player.seekableDuration;if(e.width<=0||i<=0)return;const n=Math.min(Math.max((t.clientX-e.left)/e.width,0),1);this.player.seek(this.snapSeekToMark(n*i))}seekSnapArmed=!1;static MARK_SNAP_PX=6;markNear(t){const e=this.player.seekableDuration,i=this.seekInput.getBoundingClientRect().width;if(e<=0||i<=0)return;const n=pe.MARK_SNAP_PX/i*e;let s;for(const r of this.milestoneMarks.children){const o=Number(r.dataset.t);Math.abs(o-t)>n||(!s||Math.abs(o-t)<Math.abs(s.t-t))&&(s={t:o,name:r.title})}return s}snapSeekToMark(t){return this.seekSnapArmed?(this.seekSnapArmed=!1,this.markNear(t)?.t??t):t}nameMarkUnder(t){const e=this.seekInput.getBoundingClientRect(),i=this.player.seekableDuration;if(e.width<=0||i<=0)return;const n=(t.clientX-e.left)/e.width*i,s=this.markNear(n);s?this.seekInput.title=s.name:this.seekInput.removeAttribute("title")}showMilestoneAt(t){const e=this.milestonesShown&&this.sighting.milestones.length>0?Ah(this.sighting.milestones,t):void 0;if(this.milestoneCaption.hidden=e===void 0,this.showCurrentMoment(e),!e)return;const i=document.createElement("b");i.textContent=this.said.read(e.label)??"";const n=this.said.read(e.note),s=n?` — ${n}`:"";this.milestoneCaption.replaceChildren(i,document.createTextNode(s))}exposureInstants(t){const e=this.exposureTimes(t),i=1/e.length;return e.map(n=>({shapes:this.shapesAt(n),share:i}))}exposureTimes(t=this.currentTime){const e=Xn.windowEndingAt(t,this.currentSighting.exposure??0);if(e.ms<pe.SHORTEST_VISIBLE_EXPOSURE_MS)return[t];const i=Math.min(pe.MAX_EXPOSURE_STEPS,Math.max(2,Math.round(e.ms/pe.SHORTEST_VISIBLE_EXPOSURE_MS))),n=Math.ceil(this.travelPxOver(e.fromMs,e.ms)/pe.EXPOSURE_STEP_PX),s=Math.min(pe.MAX_TRAVEL_STEPS,Math.max(i,n)),r=[];for(let o=0;o<s;o++)r.push(e.fromMs+e.ms*o/(s-1));return r}travelPxOver(t,e){const i=this.shapesAt(t),n=this.shapesAt(t+e);let s=0;for(const[r,o]of i){const c=n.get(r);if(!c)continue;const l=c.bounds.x+c.bounds.width/2-(o.bounds.x+o.bounds.width/2),h=c.bounds.y+c.bounds.height/2-(o.bounds.y+o.bounds.height/2);s=Math.max(s,Math.hypot(l,h))}return s}shapeAt(t,e,i){if(!this.accountHidden)for(const n of this.exposureTimes()){const s=this.currentSighting.timeline.hitTest(n,t,e,i);if(s)return s}}shapesAt(t){const e=new Map;for(const i of this.currentSighting.timeline.sourceIds){const n=this.currentSighting.timeline.getInterpolatedShapeAt(t,i);n&&e.set(i,n)}return e}static SHORTEST_VISIBLE_EXPOSURE_MS=20;static MAX_EXPOSURE_STEPS=48;static EXPOSURE_STEP_PX=2;static MAX_TRAVEL_STEPS=320;applyFrameFormat(){const t=mi.frameWidthPx(this.currentSighting.instrument,this.canvas.height);if(this.canvas.width===t)return;this.canvas.width=t,this.canvas.parentElement?.style.setProperty("--frame-aspect",`${t} / ${this.canvas.height}`)}canvasPointFromEvent(t){const e=this.canvas.getBoundingClientRect();if(!(e.width===0||e.height===0))return{x:(t.clientX-e.left)/e.width*this.canvas.width,y:(t.clientY-e.top)/e.height*this.canvas.height}}onFrame(t,e){this.canvasRenderer.clear(this.canvas.width,this.canvas.height);const i=this.playbackState!=="playing"?this.highlightedSourceIds:H2;this.canvasRenderer.setStarPoints(mi.starPointsOf(this.sighting.instrument));const n=(Je(this.sighting,t)?.rollDeg??0)+this.gaitAt(t).rollDeg;this.canvasRenderer.setRoll(n*Math.PI/180);const s=this.exposureInstants(t),r=this.frameShift;if(this.paintsShapes)for(const o of s)for(const[,c]of o.shapes){const l=o.share,h=l===1?c:{...c,transparency:1-(1-c.transparency)*l};this.canvasRenderer.paintShape(this.shifted(h,r))}for(const[o,c]of s[0].shapes)!this.selectionShown||!i.has(o)||(this.paintsShapes?i.size===1?this.canvasRenderer.paintShape({...c,selected:!0}):this.canvasRenderer.paintMemberOutline(c):this.canvasRenderer.paintSelectionOnly(this.shifted(c,r)));if(this.selectionShown&&i.size>1){const o=pn.groupBoundsFor([...e].filter(([c])=>i.has(c)).map(([,c])=>c.bounds));this.canvasRenderer.paintGroupHandles(o)}this.overlayPainter?.(this.canvasRenderer),this.mapShapeBounds=s.flatMap(o=>[...o.shapes.values()].filter(c=>c.transparency<1).map(c=>this.shifted(c,r).bounds)),this.keepObserverMapClear(),this.seekInput.value=String(t),this.paintSeekProgress(t),this.timeStartLabel.textContent=this.formatPosition(t),this.showMilestoneAt(t),this.paintObserverMap(t),this.playbackState==="playing"?(this.soundPreview=void 0,this.sightingAudio.setSound(c2(this.currentSighting,t))):this.soundPreview?this.sightingAudio.setSound(this.soundPreview):this.sightingAudio.silence(),this.updatePlayPauseButton(),this.dispatchEvent(new CustomEvent("timeupdate",{detail:{time:t}}))}shifted(t,e){return e.x===0&&e.y===0?t:{...t,bounds:{...t.bounds,x:t.bounds.x+e.x,y:t.bounds.y+e.y}}}createPlayer(){const t=new l2(this.currentSighting.timeline,(e,i)=>this.onFrame(e,i));return t.loop=this.loopEnabled,t.onEnded=()=>{this.updatePlayPauseButton(),this.dispatchEvent(new CustomEvent("ended",{bubbles:!0,composed:!0}))},t}static SEEK_KEY_STEP_MS=5e3;handleFullscreenKey=t=>{t.key.toLowerCase()!=="f"||t.altKey||t.ctrlKey||t.metaKey||!this.enableClickToPlay||t.composedPath().some(i=>i instanceof HTMLElement&&(i.isContentEditable||["INPUT","TEXTAREA","SELECT"].includes(i.tagName)&&i.type!=="range"))||(t.preventDefault(),this.toggleFullscreen())};handleSeekKey=t=>{if(t.altKey||t.ctrlKey||t.metaKey)return;const e=t.key==="ArrowLeft"?-1:t.key==="ArrowRight"?1:0;if(e){t.preventDefault();const i=this.player.seekableDuration;this.player.seek(Math.min(i,Math.max(0,this.player.time+e*pe.SEEK_KEY_STEP_MS)))}else t.key===" "&&(t.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 t=this.playbackFlash;t.innerHTML=this.player.playbackState==="playing"?Vt.PLAY:Vt.PAUSE,t.classList.remove("flashing"),t.offsetWidth,t.classList.add("flashing")}static icons=new WeakMap;static setIcon(t,e){pe.icons.get(t)!==e&&(pe.icons.set(t,e),t.innerHTML=e)}set captionHeld(t){this.stageElement.classList.toggle("caption-held",t)}static CONTROLS_IDLE_MS=3e3;controlsIdleTimer;wasPlaying=!1;quietControlsValue=!1;get quietControls(){return this.quietControlsValue}set quietControls(t){this.quietControlsValue=t,this.stageElement.classList.toggle("quiet",t)}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},pe.CONTROLS_IDLE_MS)))}updatePlayPauseButton(){const t=this.player.playbackState==="playing";this.stageElement.classList.toggle("paused",!t),t!==this.wasPlaying&&t&&this.hoverless&&(!this.quietControlsValue||this.stageElement.classList.contains("touched"))&&this.revealControls(),this.wasPlaying=t,pe.setIcon(this.playPauseButton,t?Vt.PAUSE:Vt.PLAY);const e=this.player.seekableDuration>0;this.playPauseButton.disabled=!e;const i=e?t?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 t=this.playbackBeforeClick;t&&(this.currentTime=t.time,t.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(t=>{console.error("<rr0-ufo>: requestFullscreen() failed —",t)})}enterSimulatedFullscreen(){const t=this.fullscreenTarget;this.styleBeforeSimulatedFullscreen=t.getAttribute("style")??"",this.bodyOverflowBeforeSimulatedFullscreen=document.body.style.overflow;const e=t.style;e.setProperty("position","fixed"),e.setProperty("inset","0"),e.setProperty("margin","0"),e.setProperty("max-width","none"),e.setProperty("max-height","none"),e.setProperty("aspect-ratio","auto"),e.setProperty("z-index","2147483647"),e.setProperty("background","#000"),e.setProperty("width","100vw"),e.setProperty("width","100dvw"),e.setProperty("height","100vh"),e.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 t=this.fullscreenTarget;this.styleBeforeSimulatedFullscreen?t.setAttribute("style",this.styleBeforeSimulatedFullscreen):t.removeAttribute("style"),document.body.style.overflow=this.bodyOverflowBeforeSimulatedFullscreen??"",this.simulatedFullscreen=!1,document.removeEventListener("keydown",this.handleSimulatedFullscreenKey),this.updateFullscreenButton(),this.updateMuteButton()}toggleObserverMap(){const t=this.observerMapPanel.hidden;this.observerMapAsked=t,this.setObserverMapOpen(t),this.keepObserverMapClear(),this.dispatchEvent(new CustomEvent("observermapchange",{bubbles:!0,composed:!0,detail:{open:t}}))}observerMapAsked=!1;applyObserverMapDefault(){const t=this.getAttribute(ka),e=t===null?this.sighting.observerMap??this.observerPath?.travels===!0:t!=="false";this.setObserverMapOpen(e&&this.observerPath!==void 0)}setObserverMapOpen(t){this.observerMapPanel.hidden=!t,this.observerMapPanel.removeAttribute("title"),this.observerMapButton.setAttribute("aria-pressed",String(t)),this.updateObserverMapButton(),t&&(this.sizeObserverMapCanvas(),this.loadObserverMapImagery(),this.paintObserverMap(this.currentTime))}updateObserverMapButton(){const t=!this.observerMapPanel.hidden;pe.setIcon(this.observerMapButton,t?Vt.MAP_ON:Vt.MAP_OFF);const e=t?this.messages.hideObserverMap:this.messages.showObserverMap;this.observerMapButton.title=e,this.observerMapButton.setAttribute("aria-label",e);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 t=this.observerPath!==void 0;if(this.observerPath=Fa.of(this.currentSighting),this.observerMapButton.hidden=this.observerPath===void 0,!t&&this.observerPath&&this.applyObserverMapDefault(),!this.observerPath){this.setObserverMapOpen(!1),this.observerMapBounds=void 0;return}const e=this.tracesShownState?this.currentSighting.traces.flatMap(n=>n.points):[],i=Ye.including(this.observerPath.boundsAround(pe.OBSERVER_MAP_MIN_SPAN_M,pe.OBSERVER_MAP_MARGIN),e);(!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(t,e){const i=Math.abs(t.east-t.west)/20;return Math.abs(t.north-e.north)<i&&Math.abs(t.south-e.south)<i&&Math.abs(t.west-e.west)<i&&Math.abs(t.east-e.east)<i}async loadObserverMapImagery(){const t=this.observerMapViewBounds;if(!t||this.observerMapPanel.hidden||this.observerMapImageryLoading||!this.observerMapImageryNeededFor(t))return;const e=this.observerMapView.changed,i=e?Ye.expand(t,pe.OBSERVER_MAP_IMAGERY_AHEAD):t,n=pe.OBSERVER_MAP_IMAGERY_PX*(e?1+2*pe.OBSERVER_MAP_IMAGERY_AHEAD:1);this.observerMapImageryBounds=i,this.observerMapImageryViewWidth=t.east-t.west,this.observerMapImageryLoading=!0;const s=Zg();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(t){const e=this.observerMapImageryBounds;if(!e)return!0;const i=this.observerMapImagery?.bounds??e,n=this.observerMapView.changed?Ye.expand(t,pe.OBSERVER_MAP_IMAGERY_LOOKAHEAD):t,s=n.west>=i.west&&n.east<=i.east&&n.south>=i.south&&n.north<=i.north,r=t.east-t.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(t){this.mapSceneBounds=t.map(e=>({x:e.x*this.canvas.width,y:e.y*this.canvas.height,width:e.width*this.canvas.width,height:e.height*this.canvas.height})),this.keepObserverMapClear()}keepObserverMapClear(){if(this.observerMapPanel.hidden)return;const t=this.observerMapBoxPx;if(!t)return;const e=[...this.mapShapeBounds,...this.mapSceneBounds],i=(l,h,u)=>{for(const d of e)if(!(d.x+d.width<l-u||d.x>h+u)&&!(d.y>t.bottom+u||d.y+d.height<t.top-u))return!0;return!1},n=[this.canvas.width-t.width,this.canvas.width],s=[0,t.width],r=pe.OBSERVER_MAP_CLEARANCE_PX,o=i(...n,0),c=i(...s,0);if(this.observerMapPanel.classList.toggle("subject-overlap",o&&c&&!this.observerMapAsked),this.observerMapPanel.classList.contains("on-the-left")){!o&&(c||!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 t=this.observerMapPanel.clientWidth;if(t===0)return;const e=Math.round(t*(globalThis.devicePixelRatio??1));this.measureObserverMapBox(),this.observerMapCanvas.width!==e&&(this.observerMapCanvas.width=e,this.observerMapCanvas.height=e)}measureObserverMapBox(){const t=this.observerMapPanel.getBoundingClientRect(),e=this.canvas.getBoundingClientRect();if(e.width===0||e.height===0)return;const i=this.canvas.width/e.width,n=this.canvas.height/e.height;this.observerMapBoxPx={width:t.width*i,top:(t.top-e.top)*n,bottom:(t.bottom-e.top)*n}}paintObserverMap(t){if(this.observerMapPanel.hidden||!this.observerPath||!this.observerMapBounds)return;const e=Je(this.currentSighting,t);e?.lat!==void 0&&e.lng!==void 0&&!this.observerMapDrag?.moved&&this.observerMapView.keepInView(this.observerMapBounds,{lat:e.lat,lng:e.lng},pe.OBSERVER_MAP_FOLLOW_MARGIN)&&this.scheduleObserverMapImagery();const i=this.currentSighting.instrument,n=[],s=this.currentSighting.milestones.length>0?Ah(this.currentSighting.milestones,t):void 0;for(const r of this.milestonesShown?Bo(this.currentSighting.milestones):[]){const o=Je(this.currentSighting,r.t);o?.lat===void 0||o.lng===void 0||n.push({label:this.said.read(r.label)??"",note:this.said.read(r.note),t:r.t,lat:o.lat,lng:o.lng,current:r===s})}this.observerMapRenderer.paint({bounds:this.observerMapViewBounds,imagery:this.observerMapImagery,path:this.observerPath,position:e?.lat!==void 0&&e.lng!==void 0?{lat:e.lat,lng:e.lng}:void 0,headingDeg:e?.headingDeg===void 0?void 0:e.headingDeg+this.lookYawDeg,coneHalfAngleDeg:e?Ls.of(i,this.canvas.height,e.fovDeg).halfWidthAngleDeg(mi.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(t),observerLabel:this.said.read(this.currentSighting.observer?.title)??this.messages.observerHere,nightFraction:this.observerMapNightFraction,attribution:this.observerMapFooterLine})}toggleMilestones(){this.setMilestonesShown(!this.milestonesShown)}setMilestonesShown(t){this.milestonesShown=t,this.milestoneMarks.hidden=!t,this.momentsBox.hidden=!t||this.sighting.milestones.length===0,this.refreshSeekSegments(this.player.seekableDuration,Bo(this.sighting.milestones).map(e=>e.t)),this.milestonesButton.setAttribute("aria-pressed",String(t)),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,pe.setIcon(this.milestonesButton,this.milestonesShown?Vt.MILESTONES_ON:Vt.MILESTONES_OFF);const t=this.milestonesShown?this.messages.hideMilestones:this.messages.showMilestones;this.milestonesButton.title=t,this.milestonesButton.setAttribute("aria-label",t)}observerMapDecorAt(t){const e=Je(this.currentSighting,0);return e?.lat===void 0||e.lng===void 0?[]:this.currentSighting.decor.filter(i=>i.kind!=="crop").map(i=>{const n=Zo(i,t),{lat:s,lng:r}=Sn(n.eastM,-n.northM,e.lat,e.lng);return{lat:s,lng:r,headingDeg:n.headingDeg,label:this.said.read(i.title)??this.messages.decorHere}})}observerMapNightFraction;setSunAltitude(t){const e=t===void 0?void 0:Math.max(0,Math.min(1,-t/12));e!==this.observerMapNightFraction&&(this.observerMapNightFraction=e,this.paintObserverMap(this.currentTime))}setLookOffset(t,e){t===this.lookYawDeg&&e===this.lookPitchDeg||(this.lookYawDeg=t,this.lookPitchDeg=e,this.refresh())}get frameShiftPx(){return this.frameShift}get frameShift(){const t=this.gaitAt(this.currentTime),e=this.lookYawDeg+t.yawDeg,i=this.lookPitchDeg+t.pitchDeg;if(e===0&&i===0)return{x:0,y:0};const n=Je(this.currentSighting,this.currentTime),s=Ls.of(this.currentSighting.instrument,this.canvas.height,n?.fovDeg??60);return{x:-s.angleDegToRadiusPx(e),y:s.angleDegToRadiusPx(i)}}gaitAt(t){return be.bodyAt(this.currentSighting,t,this.steadyObserver)}mutedState=!1;get muted(){return this.mutedState}set muted(t){t!==this.mutedState&&(this.mutedState=t,!t&&this.volumeState===0&&(this.volumeState=pe.RESTORED_VOLUME),this.applyLevel())}volumeState=1;static RESTORED_VOLUME=.5;get volume(){return this.volumeState}set volume(t){this.setVolume(t)}setVolume(t){this.volumeState=Math.min(Math.max(t,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.muted=!this.mutedState}updateMuteButton(){pe.setIcon(this.muteButton,this.mutedState?Vt.MUTED:Vt.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 t=this.simulatedFullscreen||document.fullscreenElement===this.fullscreenTarget;pe.setIcon(this.fullscreenButton,t?Vt.EXIT_FULLSCREEN:Vt.ENTER_FULLSCREEN),this.fullscreenButton.title=t?this.messages.exitFullscreen:this.messages.fullscreen,this.fullscreenButton.setAttribute("aria-label",this.fullscreenButton.title)}get said(){return this.saidTexts??=new Cs(Ua.preferencesFor(this))}saidTexts;async loadLocaleMessages(){const t=zg(Ua.preferencesFor(this),Bg);if(t===this.messagesLanguage||t==="en"&&this.messagesLanguage===void 0)return;this.messagesLanguage=t;const e=await _2(t);this.messagesLanguage===t&&this.applyMessages(e)}messagesLanguage;updateTimeLabelTitles(){const t=this.showClockTime?this.messages.switchToElapsed:this.messages.switchToClockTime,e=this.canSwitchTimeDisplay?` — ${t}`:"";this.timeStartLabel.title=this.messages.currentPosition+e,this.timeEndLabel.title=this.messages.duration+e,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(t){this.messages=t,this.updateTimeLabelTitles(),this.updatePlayPauseButton(),this.updateFullscreenButton(),this.updateMuteButton(),this.updateObserverMapButton(),this.updateReferencesButton(),this.updateTracesButton(),this.updateMilestonesButton(),this.renderIssues()}updateTimeLabels(){const t=this.currentSighting.event,e=r2(t);this.realDurationMs=e!==void 0&&e>0?e:void 0,this.realStartMs=t.time?Ju(t.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(t){if(this.realDurationMs===void 0)return Ec(t);const e=this.currentSighting.timeline.duration,i=e>0&&t<=e?t/e*this.realDurationMs:t;return this.canShowClockTime?Zf(Kf(this.realStartMs+i)):Ec(i)}formatEndOfTimeline(){return this.realDurationMs===void 0?Ec(this.currentSighting.timeline.duration):this.canShowClockTime?Zf(Kf(this.realStartMs+this.realDurationMs)):Ec(this.realDurationMs)}}function Kf(a){const t=new Date(a);return{hour:t.getUTCHours(),minute:t.getUTCMinutes(),second:t.getUTCSeconds()}}function Zf(a){if(a.hour===void 0)return"0:00";const t=e=>String(e).padStart(2,"0");return a.second?`${t(a.hour)}:${t(a.minute??0)}:${t(a.second)}`:`${t(a.hour)}:${t(a.minute??0)}`}function Ec(a){const t=Math.round(a/1e3),e=Math.floor(t/60),i=t%60;return`${e}:${String(i).padStart(2,"0")}`}const Qu="rr0-ufo";function Jg(){customElements.get(Qu)||customElements.define(Qu,pe)}const G2="recordingissues";/**
1411
+ `)}`)}}class Bn{constructor(t){this.format=t}issues(t){const e=[];return this.object(t,this.format,"",e),e}object(t,e,i,n){if(!Bn.isObject(t)){n.push({kind:"wrong-type",path:i||"(the file)",expected:"object",found:Bn.typeOf(t)});return}for(const[s,r]of Object.entries(t)){const o=i?`${i}.${s}`:s,c=e[s];c?this.field(r,c,o,n):n.push({kind:"unknown-key",path:o})}}field(t,e,i,n){if(Bn.isStated(t)){this.field(t.value,e,i,n);return}if(!(e.loose||t===void 0||t===null))switch(e.type){case"enum":(typeof t!="string"||!e.values?.includes(t))&&n.push({kind:"not-in-list",path:i,expected:(e.values??[]).map(s=>`"${s}"`).join(", "),found:JSON.stringify(t)});return;case"object":e.fields?this.object(t,e.fields,i,n):Bn.isObject(t)||n.push({kind:"wrong-type",path:i,expected:"object",found:Bn.typeOf(t)});return;case"array":Array.isArray(t)?e.fields&&t.forEach((s,r)=>{const o=Bn.isStated(s)?s.value:s;this.object(o,e.fields,`${i}.${r}`,n)}):n.push({kind:"wrong-type",path:i,expected:"array",found:Bn.typeOf(t)});return;default:typeof t!==e.type&&n.push({kind:"wrong-type",path:i,expected:e.type,found:Bn.typeOf(t)})}}static isObject(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}static isStated(t){return Bn.isObject(t)&&"value"in t&&Object.keys(t).every(e=>e==="value"||e==="basis"||e==="rationale")}static typeOf(t){return Array.isArray(t)?"array":t===null?"null":typeof t}}class Xn{static PIXELS_PER_INSTANT=2;static INSTANTS_PER_FLASH=2;static MAX_INSTANTS=512;static windowEndingAt(t,e){const i=Number.isFinite(e)?Math.max(0,e):0,n=Math.max(0,t-i*1e3),s=Math.max(0,t-n);return{fromMs:n,toMs:t,ms:s,seconds:s/1e3}}static instants(t,e,i,n,s){if(!(n>0))return 1;const r=s>0?Xn.travelDegOver(t,e,i,i+n*1e3)/s/Xn.PIXELS_PER_INSTANT:0,o=Xn.flashesOver(t,n)*Xn.INSTANTS_PER_FLASH,c=Math.ceil(Math.max(r,o));return c<2?1:Math.min(Xn.MAX_INSTANTS,c)}static travelDegOver(t,e,i,n){let s=0;for(const r of t){if(!r.track||r.track.length<2)continue;const o=Xn.directionAt(r,e,i),c=Xn.directionAt(r,e,n),l=Math.min(1,Math.max(-1,o.x*c.x+o.y*c.y+o.z*c.z));s=Math.max(s,Math.acos(l)*180/Math.PI)}return s}static flashesOver(t,e){let i=0;for(const n of t)for(const s of n.lights??[])s.pattern.kind==="flash"&&(i=Math.max(i,s.pattern.perMinute));return i/60*e}static directionAt(t,e,i){const n=Zo(t,i),s=n.eastM,r=n.altitudeM-e,o=n.northM,c=Math.hypot(s,r,o);return c===0?{x:0,y:1,z:0}:{x:s/c,y:r/c,z:o/c}}}function zg(a,t){for(const e of a){const i=e.toLowerCase().split("-")[0];if(t.includes(i))return i}return"en"}class Ua{static preferencesFor(t){const e=navigator.languages??[],i=this.declaredFor(t);return i?[i,...e]:e}static declaredFor(t){for(let e=t;e;){const i=e.closest("[lang]")?.getAttribute("lang")?.trim();if(i)return i;const n=e.getRootNode();e=n instanceof ShadowRoot?n.host:void 0}}}class Cs{constructor(t){this.preferences=t}read(t){if(t===void 0||typeof t=="string")return t===""?void 0:t;for(const i of this.preferences){const n=t[i]??t[Cs.base(i)];if(n)return n}const e=new Set(this.preferences.map(i=>Cs.base(i)));for(const[i,n]of Object.entries(t))if(n&&e.has(Cs.base(i)))return n;return Object.values(t).find(i=>i)??void 0}write(t,e,i){const n=e?.trim()?e.trim():void 0;if(t===void 0||typeof t=="string")return n;const s={...t},r=Object.keys(s).find(o=>o===i)??Object.keys(s).find(o=>Cs.base(o)===Cs.base(i))??i;return n===void 0?delete s[r]:s[r]=n,Object.keys(s).length===0?void 0:s}static base(t){return t.toLowerCase().split("-")[0]}}const Bg=["en","fr","es","it"],S2={en:()=>$i(()=>Promise.resolve().then(()=>w2),void 0,import.meta.url).then(a=>a.ufoMessages_en),fr:()=>$i(()=>import("./UfoMessages_fr-bJNAf-AU.js"),[],import.meta.url).then(a=>a.ufoMessages_fr),es:()=>$i(()=>import("./UfoMessages_es-LFW_B5H2.js"),[],import.meta.url).then(a=>a.ufoMessages_es),it:()=>$i(()=>import("./UfoMessages_it-B-jnc4M-.js"),[],import.meta.url).then(a=>a.ufoMessages_it)};function _2(a){return S2[a]()}function b2(a){switch(a){case"fr":return $i(()=>import("./SceneNames_fr-Ctvv7Jq8.js"),[],import.meta.url).then(t=>t.sceneNames_fr);case"es":return $i(()=>import("./SceneNames_es-3l2Xsebd.js"),[],import.meta.url).then(t=>t.sceneNames_es);case"it":return $i(()=>import("./SceneNames_it-B1_4bOob.js"),[],import.meta.url).then(t=>t.sceneNames_it);default:return Promise.resolve(void 0)}}const Hg={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:Za.EN},w2=Object.freeze(Object.defineProperty({__proto__:null,ufoMessages_en:Hg},Symbol.toStringTag,{value:"Module"})),Gg=Math.PI/180,E2=180/Math.PI,A2=256,Vg=19,T2=1.25;function Wg(a,t){return 156543.03392*Math.cos(a*Gg)/2**t}function Xg(a,t){return Wg(a,t)*A2}function R2(a,t){let e=0;for(;e<Vg&&Xg(a,e+1)>=t;)e++;return e}function Yg(a,t){return Xg(a,t)}function D2(a,t){const e=t*T2;let i=0;for(;i<Vg&&Wg(a,i)>e;)i++;return i}function wl(a){const t=a*Gg;return(1-Math.log(Math.tan(t)+1/Math.cos(t))/Math.PI)/2}function qg(a,t,e){const i=2**e;return{x:(a+180)/360*i,y:wl(t)*i}}function $g(a,t,e){const i=wl(a.north),n=wl(a.south);return{x:(t-a.west)/(a.east-a.west),y:(wl(e)-i)/(n-i)}}function I2(a,t,e){const{x:i,y:n}=qg(a,t,e);return{x:Math.floor(i),y:Math.floor(n),z:e}}function C2(a){const t=2**a.z,e=a.x/t*360-180,i=(a.x+1)/t*360-180,n=Yf(a.y,t);return{south:Yf(a.y+1,t),north:n,west:e,east:i}}function Yf(a,t){const e=a/t;return Math.atan(Math.sinh(Math.PI*(1-2*e)))*E2}function Kg(a,t,e,i){const n=I2(a,t,e),s=Math.floor(i/2),r=[];for(let l=-s;l<=s;l++)for(let h=-s;h<=s;h++)r.push({x:n.x+h,y:n.y+l,z:e});const o=r.map(C2),c={south:Math.min(...o.map(l=>l.south)),north:Math.max(...o.map(l=>l.north)),west:Math.min(...o.map(l=>l.west)),east:Math.max(...o.map(l=>l.east))};return{tiles:r,bounds:c}}const P2="#2ec4ff";class Rr{constructor(t){this.ctx=t}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(t,e){let i,n=1/0;for(const s of this.targets){const r=Math.hypot(s.x-t,s.y-e);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(t){const{ctx:e}=this;e.save(),this.targets=[],e.clearRect(0,0,this.width,this.height),this.paintGround(t),this.paintNight(t.nightFraction),this.paintPath(t),this.paintTraces(t),t.position?(this.paintCone(t,t.position),this.paintDecor(t),this.paintMarkers(t),this.paintObserver(t,t.position)):(this.paintDecor(t),this.paintMarkers(t)),this.paintNorth(),this.paintFooter(t.bounds,t.attribution),e.restore()}toCanvas(t,e,i){const n=$g(t,i,e);return{x:n.x*this.width,y:n.y*this.height}}paintGround(t){const{ctx:e}=this;e.fillStyle="#1d2321",e.fillRect(0,0,this.width,this.height);const i=t.imagery;if(!i)return;const n=this.toCanvas(t.bounds,i.bounds.north,i.bounds.west),s=this.toCanvas(t.bounds,i.bounds.south,i.bounds.east);e.drawImage(i.source,n.x,n.y,s.x-n.x,s.y-n.y)}paintNight(t=0){if(t<=0)return;const{ctx:e}=this;e.save(),e.fillStyle=`rgba(6, 12, 30, ${Math.min(t,1)*.78})`,e.fillRect(0,0,this.width,this.height),e.restore()}paintDecor(t){const{ctx:e}=this;for(const i of t.decor){const n=this.toCanvas(t.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}),e.beginPath(),e.rect(n.x-3.5,n.y-3.5,7,7),e.fillStyle="rgba(120, 220, 255, 0.85)",e.fill(),e.lineWidth=1.5,e.strokeStyle="rgba(0, 0, 0, 0.7)",e.stroke(),i.headingDeg===void 0)continue;const s=(i.headingDeg-90)*Math.PI/180;e.beginPath(),e.moveTo(n.x,n.y),e.lineTo(n.x+Math.cos(s)*10,n.y+Math.sin(s)*10),e.lineWidth=3,e.strokeStyle="rgba(0, 0, 0, 0.6)",e.stroke(),e.lineWidth=1.5,e.strokeStyle="rgba(120, 220, 255, 0.9)",e.stroke()}}paintPath(t){if(!t.path.moved)return;const{ctx:e}=this,i=t.path.points.map(n=>this.toCanvas(t.bounds,n.lat,n.lng));e.beginPath(),e.moveTo(i[0].x,i[0].y);for(const n of i.slice(1))e.lineTo(n.x,n.y);e.lineJoin="round",e.lineCap="round",e.strokeStyle="rgba(0, 0, 0, 0.65)",e.lineWidth=5,e.stroke(),e.strokeStyle="rgba(255, 255, 255, 0.9)",e.lineWidth=2,e.stroke()}paintTraces(t){const{ctx:e}=this;for(const i of t.traces??[]){const n=i.points.map(r=>this.toCanvas(t.bounds,r.lat,r.lng));if(n.length===0)continue;const s=i.color??P2;if(i.kind==="point")e.beginPath(),e.moveTo(n[0].x,n[0].y-6),e.lineTo(n[0].x+6,n[0].y),e.lineTo(n[0].x,n[0].y+6),e.lineTo(n[0].x-6,n[0].y),e.closePath(),e.fillStyle=s,e.fill(),e.lineWidth=1.5,e.strokeStyle="rgba(0, 0, 0, 0.8)",e.stroke();else{e.beginPath(),e.moveTo(n[0].x,n[0].y);for(const r of n.slice(1))e.lineTo(r.x,r.y);i.kind==="polygon"&&e.closePath(),e.lineJoin="round",e.setLineDash([]),e.strokeStyle="rgba(0, 0, 0, 0.65)",e.lineWidth=4.5,e.stroke(),e.setLineDash([9,5]),e.strokeStyle=s,e.lineWidth=2.5,e.stroke(),e.setLineDash([])}if(i.label){e.font="11px sans-serif",e.textAlign="left",e.textBaseline="middle";let r=n[0];if(i.kind==="line"&&t.position){const o=this.toCanvas(t.bounds,t.position.lat,t.position.lng);r=n.reduce((c,l)=>Math.hypot(l.x-o.x,l.y-o.y)>Math.hypot(c.x-o.x,c.y-o.y)?l:c)}this.paintOutlinedText(i.label,r.x+9,r.y-9)}}}paintCone(t,e){const{headingDeg:i,coneHalfAngleDeg:n}=t;if(i===void 0||n===void 0)return;const{ctx:s}=this,r=this.toCanvas(t.bounds,e.lat,e.lng),o=Math.hypot(this.width,this.height),c=(i-90)*Math.PI/180,l=n*Math.PI/180;s.save(),s.beginPath(),s.moveTo(r.x,r.y),s.arc(r.x,r.y,o,c-l,c+l),s.closePath();const h=s.createRadialGradient(r.x,r.y,0,r.x,r.y,o);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(t){const{ctx:e}=this;e.textAlign="center",e.textBaseline="middle",e.font="bold 10px sans-serif";for(const i of[...t.markers].sort((n,s)=>Number(n.current)-Number(s.current))){const n=this.toCanvas(t.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:Rr.MARKER_RADIUS_PX}),e.beginPath(),e.arc(n.x,n.y,Rr.MARKER_RADIUS_PX,0,Math.PI*2),e.fillStyle=i.current?"rgba(255, 224, 130, 0.95)":"rgba(0, 0, 0, 0.55)",e.fill(),e.lineWidth=2,e.strokeStyle="rgba(255, 255, 255, 0.9)",e.stroke(),e.fillStyle=i.current?"#1d2321":"#fff",e.fillText(i.label,n.x,n.y)}}paintObserver(t,e){const{ctx:i}=this,n=this.toCanvas(t.bounds,e.lat,e.lng);t.observerLabel&&this.targets.push({kind:"observer",label:t.observerLabel,lat:e.lat,lng:e.lng,x:n.x,y:n.y,radius:8});const s=t.markers.some(r=>{if(!r.current)return!1;const o=je(r.lat,r.lng,e.lat,e.lng);return Math.hypot(o.x,o.z)<=Rr.ON_MARKER_M});i.beginPath(),i.arc(n.x,n.y,s?Rr.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:t}=this,e=this.width-14,i=16;t.beginPath(),t.moveTo(e,i-9),t.lineTo(e-4.5,i+5),t.lineTo(e,i+2),t.lineTo(e+4.5,i+5),t.closePath(),t.fillStyle="rgba(255, 255, 255, 0.92)",t.strokeStyle="rgba(0, 0, 0, 0.6)",t.lineWidth=1,t.fill(),t.stroke(),t.font="bold 9px sans-serif",t.textAlign="center",t.textBaseline="top",t.strokeText("N",e,i+6),t.fillText("N",e,i+6)}paintFooter(t,e){const{ctx:i}=this;i.font="9px sans-serif",i.textBaseline="bottom";const n=e?this.wrap(e,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=(t.south+t.north)/2,c=Math.abs(je(r,t.east,r,t.west).x)/this.width,l=Rr.SCALE_STEPS_M.find(f=>f/c<=this.width/3);if(l===void 0)return;const h=l/c,u=8,d=s-3;i.lineWidth=3,i.strokeStyle="rgba(0, 0, 0, 0.6)",i.beginPath(),i.moveTo(u,d),i.lineTo(u+h,d),i.stroke(),i.lineWidth=1.5,i.strokeStyle="rgba(255, 255, 255, 0.95)",i.stroke(),i.textAlign="left",this.paintOutlinedText(l>=1e3?`${l/1e3} km`:`${l} m`,u,d-3)}paintOutlinedText(t,e,i){const{ctx:n}=this;n.lineWidth=3,n.strokeStyle="rgba(0, 0, 0, 0.75)",n.strokeText(t,e,i),n.fillStyle="#fff",n.fillText(t,e,i)}wrap(t,e){const i=[];let n="";for(const s of t.split(" ")){const r=n?`${n} ${s}`:s;n&&this.ctx.measureText(r).width>e?(i.push(n),n=s):n=r}return n&&i.push(n),i}}class Ye{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(t,e,i){const n=Math.min(Ye.MAX_ZOOM,Math.max(Ye.MIN_ZOOM,this.zoom*i)),s=this.centerX+(t-.5)/this.zoom,r=this.centerY+(e-.5)/this.zoom;this.centerX=s-(t-.5)/n,this.centerY=r-(e-.5)/n,this.zoom=n}panBy(t,e){this.centerX-=t/this.zoom,this.centerY-=e/this.zoom}refit(t,e){if(!this.changed)return;const i=this.boundsWithin(t),n=Ye.mercatorY01(e.north),s=Ye.mercatorY01(e.south),r=Ye.mercatorY01(i.north),o=Ye.mercatorY01(i.south);this.zoom=(e.east-e.west)/(i.east-i.west),this.centerX=((i.west+i.east)/2-e.west)/(e.east-e.west),this.centerY=((r+o)/2-n)/(s-n)}keepInView(t,e,i){if(!this.changed)return!1;const n=this.boundsWithin(t),s=Ye.mercatorY01(n.north),r=Ye.mercatorY01(n.south),o=(e.lng-n.west)/(n.east-n.west),c=(Ye.mercatorY01(e.lat)-s)/(r-s);return o>=i&&o<=1-i&&c>=i&&c<=1-i?!1:(this.panBy(.5-o,.5-c),!0)}boundsWithin(t){if(!this.changed)return t;const e=.5/this.zoom,i=Ye.mercatorY01(t.north),n=Ye.mercatorY01(t.south),s=t.east-t.west;return{west:t.west+(this.centerX-e)*s,east:t.west+(this.centerX+e)*s,north:Ye.latitudeAt(i+(this.centerY-e)*(n-i)),south:Ye.latitudeAt(i+(this.centerY+e)*(n-i))}}static including(t,e,i=3){const n=(t.north+t.south)/2,s=(t.east+t.west)/2,r=je(n,t.east,n,s).x;let o=r;for(const c of e){const{x:l,z:h}=je(c.lat,c.lng,n,s),u=Math.max(Math.abs(l),Math.abs(h));u<=r*i&&(o=Math.max(o,u*1.15))}return o<=r?t:{north:Sn(0,-o,n,s).lat,south:Sn(0,o,n,s).lat,east:Sn(o,0,n,s).lng,west:Sn(-o,0,n,s).lng}}static expand(t,e){const i=t.east-t.west,n=t.north-t.south;return{west:t.west-i*e,east:t.east+i*e,south:t.south-n*e,north:t.north+n*e}}static pointAt(t,e,i){const n=Ye.mercatorY01(t.north),s=Ye.mercatorY01(t.south);return{lat:Ye.latitudeAt(n+i*(s-n)),lng:t.west+e*(t.east-t.west)}}static mercatorY01(t){const e=t*Math.PI/180;return(1-Math.log(Math.tan(e)+1/Math.cos(e))/Math.PI)/2}static latitudeAt(t){return Math.atan(Math.sinh(Math.PI*(1-2*t)))*180/Math.PI}}const wn=256,qf=3,L2=32768;class O2{fetchImpl;tileUrlTemplate;constructor(t={}){this.fetchImpl=t.fetchImpl??fetch.bind(globalThis),this.tileUrlTemplate=t.tileUrlTemplate??"https://s3.amazonaws.com/elevation-tiles-prod/terrarium/{z}/{x}/{y}.png"}async getElevationGrid(t,e){const i=(t.south+t.north)/2,n=(t.west+t.east)/2,s=Math.abs(je(i,t.east,i,t.west).x),r=Math.abs(je(t.north,n,t.south,n).z),o=R2(i,Math.max(s,r)),{tiles:c}=Kg(n,i,o,qf),l=qf*wn,h=new Float32Array(l*l),u=c[0];await Promise.all(c.map(f=>this.decodeTileInto(f,u,h,l)));const d=new Float32Array(e.width*e.height);for(let f=0;f<e.height;f++){const p=t.north+(t.south-t.north)*(f/(e.height-1));for(let v=0;v<e.width;v++){const m=t.west+(t.east-t.west)*(v/(e.width-1));d[f*e.width+v]=this.sampleAt(p,m,o,u,h,l)}}return{heights:d,width:e.width,height:e.height,bounds:t}}async decodeTileInto(t,e,i,n){const s=this.tileUrlTemplate.replace("{z}",String(t.z)).replace("{x}",String(t.x)).replace("{y}",String(t.y)),r=await this.fetchImpl(s);if(!r.ok)throw new Error(`Elevation tile fetch failed (${r.status}): ${s}`);const o=await createImageBitmap(await r.blob()),c=document.createElement("canvas");c.width=wn,c.height=wn;const l=c.getContext("2d");if(!l)throw new Error("2D canvas context unavailable");l.drawImage(o,0,0);const{data:h}=l.getImageData(0,0,wn,wn),u=(t.x-e.x)*wn,d=(t.y-e.y)*wn;for(let f=0;f<wn;f++)for(let p=0;p<wn;p++){const v=(f*wn+p)*4,m=h[v]*256+h[v+1]+h[v+2]/256-L2,g=u+p,S=d+f;i[S*n+g]=m}}sampleAt(t,e,i,n,s,r){const{x:o,y:c}=qg(e,t,i),l=(o-n.x)*wn,h=(c-n.y)*wn,u=Math.max(0,Math.min(r-1,Math.floor(l))),d=Math.max(0,Math.min(r-1,Math.floor(h))),f=Math.min(r-1,u+1),p=Math.min(r-1,d+1),v=l-u,m=h-d,g=s[d*r+u],S=s[d*r+f],x=s[p*r+u],M=s[p*r+f],b=g+(S-g)*v,w=x+(M-x)*v;return b+(w-b)*m}}const El=256,N2=5;async function F2(a,t,e,i){const n=(a.south+a.north)/2,s=(a.west+a.east)/2,r=Math.abs(je(n,a.east,n,a.west).x),o=Math.abs(je(a.north,s,a.south,s).z),c=Math.max(r,o),{zoom:l,gridSize:h}=U2(n,c,Math.max(t.width,t.height)),{tiles:u,bounds:d}=Kg(s,n,l,h),f=h*El,p=document.createElement("canvas");p.width=f,p.height=f;const v=p.getContext("2d");if(!v)throw new Error("2D canvas context unavailable");const m=u[0];await Promise.all(u.map(async M=>{const b=e(M),w=await i(b);if(!w.ok)throw new Error(`Imagery tile fetch failed (${w.status}): ${b}`);const T=await createImageBitmap(await w.blob());v.drawImage(T,(M.x-m.x)*El,(M.y-m.y)*El)}));const g=Math.min(Math.max(t.width,t.height),f);if(g===f)return{source:p,width:f,height:f,bounds:d};const S=document.createElement("canvas");S.width=g,S.height=g;const x=S.getContext("2d");if(!x)throw new Error("2D canvas context unavailable");return x.drawImage(p,0,0,f,f,0,0,g,g),{source:S,width:g,height:g,bounds:d}}function U2(a,t,e){let i=D2(a,t/Math.max(1,e)),n=$f(a,i,t);for(;n>N2&&i>0;)i--,n=$f(a,i,t);return{zoom:i,gridSize:n,mPerPixel:Yg(a,i)/El}}function $f(a,t,e){const i=Math.ceil(e/2/Yg(a,t));return Math.max(3,2*i+1)}class k2{attribution="Imagery © Esri, Maxar, Earthstar Geographics, and the GIS User Community";fetchImpl;tileUrlTemplate;constructor(t={}){this.fetchImpl=t.fetchImpl??fetch.bind(globalThis),this.tileUrlTemplate=t.tileUrlTemplate??"https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"}async getImageryTexture(t,e){return F2(t,e,i=>this.tileUrlTemplate.replace("{z}",String(i.z)).replace("{y}",String(i.y)).replace("{x}",String(i.x)),this.fetchImpl)}}class Hn{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;static ENDPOINTS=["https://overpass-api.de/api/interpreter","https://overpass.kumi.systems/api/interpreter","https://overpass.private.coffee/api/interpreter"];fetchImpl;endpoints;constructor(t={}){this.fetchImpl=t.fetchImpl??fetch.bind(globalThis),this.endpoints=t.endpoints??Hn.ENDPOINTS}static queue=Promise.resolve();static RETRY_MS=4e3;async getRoads(t){const e=`${t.south},${t.west},${t.north},${t.east}`,i=`[out:json][timeout:30];way["highway"~"^(${Hn.DRIVABLE.join("|")})$"](${e});out geom;`;return this.waysFrom(await this.queued(()=>this.ask(i)))}waysFrom(t){const e=[];for(const i of t.elements??[]){const n=i.geometry,s=i.tags;!s||!n||n.length<2||e.push({id:`osm-${i.id??e.length}`,name:s.name,surface:Hn.surfaceOf(s),widthM:Hn.widthOf(s),points:n.map(r=>({lat:r.lat,lng:r.lon}))})}return e}queued(t){const e=Hn.queue.then(t,t);return Hn.queue=e.catch(()=>{}),e}async ask(t){let e;for(const i of this.endpoints)for(let n=0;n<2;n++){try{const s=await this.fetchImpl(`${i}?data=${encodeURIComponent(t)}`);if(s.ok)return await s.json();if(e=new Error(`${new URL(i).host} refused (${s.status})`),s.status!==429&&s.status!==504)break}catch(s){e=new Error(`${new URL(i).host} unreachable (${String(s)})`);break}await new Promise(s=>setTimeout(s,Hn.RETRY_MS))}throw e??new Error("No Overpass instance answered")}static widthOf(t){const e=Number.parseFloat(t.width??t.est_width??"");if(Number.isFinite(e)&&e>0)return e;const i=Number.parseInt(t.lanes??"",10);return Number.isFinite(i)&&i>0?i*3.5:Hn.WIDTH_M[t.highway]??Hn.DEFAULT_WIDTH_M}static surfaceOf(t){const e=t.surface;return e==="dirt"||e==="earth"||e==="mud"?"dirt":e==="gravel"||e==="fine_gravel"||e==="compacted"||e==="ground"||e==="sand"||e==="unpaved"?"gravel":e?"paved":t.highway==="track"?"gravel":"paved"}}const Rh="https://ufoathome.org/roads/index.json";class Ra{attributionRead;contemporaryRead;fetchImpl;indexUrls;fallback;index;static shared=new Map;sharing;constructor(t={}){this.sharing=!t.fetchImpl,this.fetchImpl=t.fetchImpl??fetch.bind(globalThis),this.indexUrls=t.indexUrls??Ra.defaultIndexUrls(),this.fallback=t.fallback}get attribution(){return this.attributionRead??this.fallback?.attribution??"Roads © OpenStreetMap contributors"}get contemporary(){return this.contemporaryRead??this.fallback?.contemporary??!0}async getRoads(t){const e=await this.held(t);if(e)return e;if(!this.fallback)return[];const i=await this.fallback.getRoads(t);return this.attributionRead=this.fallback.attribution,this.contemporaryRead=this.fallback.contemporary,i}async held(t){let e;try{e=await this.load()}catch{return}const i=e.find(({entry:n})=>n.north>=t.north&&n.south<=t.south&&n.east>=t.east&&n.west<=t.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 t=this.indexUrls.join(`
1412
+ `);let e=Ra.shared.get(t);return e||(e=this.fetchFirstAvailable(),Ra.shared.set(t,e),e.then(i=>{i.length===0&&Ra.shared.delete(t)})),this.index=e}async fetchFirstAvailable(){for(const t of this.indexUrls)try{const e=await this.fetchImpl(t);if(!e.ok)continue;const i=await e.json();if(Array.isArray(i?.entries))return i.entries.map(n=>({entry:n,indexUrl:t}))}catch{}return[]}static defaultIndexUrls(){const t=`?v=${encodeURIComponent("0.98.0")}`,e=typeof location>"u"?void 0:new URL("/roads/index.json",location.href).href;return(e&&e!==Rh?[e,Rh]:[Rh]).map(i=>i+t)}}function z2(){return{elevation:new O2,imagery:Zg(),roads:B2()}}function Zg(){return new k2}function B2(){return new Ra({fallback:new Hn})}const H2=new Set,ka="show-observer-map",za="hide-milestones";class he extends HTMLElement{static get observedAttributes(){return["src",ka,za]}shadow;stageElement;canvas;canvasRenderer;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 Ye;observerMapDrag;suppressObserverMapClick=!1;observerMapImageryTimer;observerPlacing=!1;seekInput;playbackFlash;milestoneMarks;milestoneCaption;timeStartLabel;timeEndLabel;timePill;muteButton;volumeInput;controlsRow;momentsBox;momentsButton;momentsCurrent;momentsMenu;moreButton;controlsRight;seekSegments;seekDot;seekPreview;seekPreviewCanvas;seekPreviewTitle;seekPreviewTime;observerPath;observerMapBounds;observerMapImagery;observerMapImageryBounds;observerMapImageryViewWidth=0;observerMapImageryLoading=!1;observerMapImageryCredit;observerMapImageryFailed=!1;creditShownExternally=!1;lookYawDeg=0;lookPitchDeg=0;milestonesShown=!0;currentSighting=hh.create();issues=[];issueCheck=0;sightingAudio=new g2;soundPreview;player;loopEnabled=!1;playbackBeforeClick;highlightedSourceIds=new Set;paintsShapes=!0;steadyObserver=!1;selectionShown=!0;overlayPainter;enableClickToPlay=!0;fullscreenTarget;messages=Hg;realDurationMs;realStartMs;showClockTime=!0;handleFullscreenChange=()=>{this.updateFullscreenButton(),this.updateMuteButton(),this.resizeObserverMap()};controlsFitObserver=typeof ResizeObserver>"u"?void 0:new ResizeObserver(()=>this.fitControls());controlsMutations;fitControls(){const t=this.controlsRow,e=t.classList.contains("more-open"),i=()=>t.scrollWidth>t.clientWidth+1,n=!this.momentsMenu.hidden;if(this.momentsMenu.hidden=!0,t.classList.remove("narrow","more-open","nomoments","compact","tiny"),t.clientWidth>0&&i()){t.classList.add("narrow");for(const s of["nomoments","compact","tiny"]){if(!i())break;t.classList.add(s)}e&&t.classList.add("more-open")}this.momentsMenu.hidden=!n,this.updateMoreButton()}setControlsFolded(t){this.controlsRow.classList.toggle("more-open",!t),this.updateMoreButton()}updateMoreButton(){const t=this.controlsRow.classList.contains("more-open");he.setIcon(this.moreButton,t?Gt.UNFOLDED:Gt.FOLDED);const e=t?this.messages.fewerControls:this.messages.moreControls;this.moreButton.title=e,this.moreButton.setAttribute("aria-label",e),this.moreButton.setAttribute("aria-expanded",String(t))}addControl(t){this.controlsRight.insertBefore(t,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=t=>{t.key==="Escape"&&this.exitSimulatedFullscreen()};handlePointerMove=t=>{const e=this.canvasPointFromEvent(t),i=e&&this.shapeAt(e.x,e.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=`${t.clientX-s.left+12}px`,this.tooltip.style.top=`${t.clientY-s.top+12}px`};handleObserverMapPointerMove=t=>{if(this.dragObserverMap(t))return;const e=this.observerMapTargetFrom(t);if(!e){if(!this.observerPlacing){this.tooltip.hidden=!0,this.observerMapCanvas.style.cursor="grab";return}this.observerMapCanvas.style.cursor="crosshair",this.showObserverMapTooltip(t,this.messages.placeObserverHere);return}this.observerMapCanvas.style.cursor="pointer",this.showObserverMapTooltip(t,e.label)};showObserverMapTooltip(t,e){this.tooltip.textContent=e,this.tooltip.hidden=!1;const i=this.stageElement.getBoundingClientRect();this.tooltip.style.left=`${t.clientX-i.left+12}px`,this.tooltip.style.top=`${t.clientY-i.top+12}px`}handleObserverMapClick=t=>{if(this.suppressObserverMapClick){this.suppressObserverMapClick=!1;return}const e=this.observerMapTargetFrom(t);if(!e){this.observerPlacing&&this.placeObserverFrom(t);return}if(e.kind==="milestone"&&e.t!==void 0){this.player.seek(e.t);return}this.dispatchEvent(new CustomEvent("lookat",{detail:{lat:e.lat,lng:e.lng,kind:e.kind},bubbles:!0,composed:!0}))};observerMapTargetFrom(t){const e=this.observerMapCanvas.getBoundingClientRect();if(!(e.width===0||e.height===0))return this.observerMapRenderer.hitTest((t.clientX-e.left)/e.width*this.observerMapCanvas.width,(t.clientY-e.top)/e.height*this.observerMapCanvas.height)}handlePointerLeave=()=>{this.tooltip.hidden=!0};handleObserverMapPointerDown=t=>{t.button===0&&(this.suppressObserverMapClick=!1,this.observerMapDrag={pointerId:t.pointerId,startX:t.clientX,startY:t.clientY,lastX:t.clientX,lastY:t.clientY,moved:!1})};handleObserverMapPointerUp=t=>{const e=this.observerMapDrag;!e||e.pointerId!==t.pointerId||(this.observerMapDrag=void 0,this.observerMapCanvas.classList.remove("dragging"),e.moved&&(this.suppressObserverMapClick=!0,this.paintObserverMap(this.currentTime),this.observerMapCanvas.hasPointerCapture?.(t.pointerId)&&this.observerMapCanvas.releasePointerCapture(t.pointerId)))};dragObserverMap(t){const e=this.observerMapDrag;if(!e||e.pointerId!==t.pointerId)return!1;if(!e.moved){if(Math.hypot(t.clientX-e.startX,t.clientY-e.startY)<he.OBSERVER_MAP_DRAG_PX)return!1;e.moved=!0,this.tooltip.hidden=!0,this.observerMapCanvas.classList.add("dragging"),this.observerMapCanvas.setPointerCapture?.(t.pointerId)}const i=this.observerMapCanvas.getBoundingClientRect();return i.width>0&&i.height>0&&(this.observerMapView.panBy((t.clientX-e.lastX)/i.width,(t.clientY-e.lastY)/i.height),this.observerMapViewChanged()),e.lastX=t.clientX,e.lastY=t.clientY,!0}static OBSERVER_MAP_DRAG_PX=4;handleObserverMapWheel=t=>{t.preventDefault();const e=this.observerMapCanvas.getBoundingClientRect();if(e.width===0||e.height===0)return;const i=t.deltaMode===0?t.deltaY:t.deltaY*40;this.zoomObserverMap((t.clientX-e.left)/e.width,(t.clientY-e.top)/e.height,Math.exp(-i*.002))};zoomObserverMap(t,e,i){this.observerMapView.zoomAt(t,e,i),this.observerMapViewChanged()}observerMapViewChanged(){this.mapFitButton.hidden=!this.observerMapView.changed,this.mapZoomInButton.disabled=this.observerMapView.zoomFactor>=Ye.MAX_ZOOM,this.mapZoomOutButton.disabled=this.observerMapView.zoomFactor<=Ye.MIN_ZOOM,this.paintObserverMap(this.currentTime),this.scheduleObserverMapImagery()}scheduleObserverMapImagery(){this.observerMapImageryTimer===void 0&&(this.observerMapImageryTimer=setTimeout(()=>{this.observerMapImageryTimer=void 0,this.loadObserverMapImagery()},he.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(t){const e=this.observerMapViewBounds,i=this.observerMapCanvas.getBoundingClientRect();if(!e||i.width===0||i.height===0)return;const n=Ye.pointAt(e,(t.clientX-i.left)/i.width,(t.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 t=document.createElement("template");t.innerHTML=`<style>${Gv}</style>${Hv}`,this.shadow.appendChild(t.content.cloneNode(!0)),this.stageElement=this.shadow.getElementById("stage"),this.canvas=this.shadow.getElementById("canvas"),this.canvasRenderer=new ec(this.canvas.getContext("2d")),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",e=>{e.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 Rr(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.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",e=>{e.key!=="Enter"&&e.key!==" "||(e.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",e=>{this.suspendForScrub(),this.seekSnapArmed=!0,this.nameMarkUnder(e),this.beginTouchScrub(e)}),this.seekInput.addEventListener("pointerup",e=>{this.seekSnapArmed=!1,this.endTouchScrub(e)}),this.seekInput.addEventListener("pointercancel",e=>this.endTouchScrub(e)),this.seekInput.addEventListener("pointermove",e=>{this.nameMarkUnder(e),this.hoverSeek(e),this.touchScrub(e)}),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 e of["touchend","click"])this.stageElement.addEventListener(e,()=>this.sightingAudio.resume(),!0);this.stageElement.addEventListener("pointermove",()=>this.touchedStage()),this.canvas.addEventListener("click",e=>{if(this.enableClickToPlay){if(this.tapRevealedOnly){this.tapRevealedOnly=!1;return}e.detail<=1&&(this.playbackBeforeClick={state:this.playbackState,time:this.currentTime}),this.togglePlayPause()}}),this.canvas.addEventListener("dblclick",e=>{this.enableClickToPlay&&(e.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.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 t=this.getAttribute("src");t&&this.loadFromSrc(t)}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.controlsFitObserver?.disconnect(),this.controlsMutations?.disconnect(),this.exitSimulatedFullscreen(),this.sightingAudio.dispose()}attributeChangedCallback(t,e,i){t==="src"&&i&&i!==e&&this.isConnected&&this.loadFromSrc(i),t===ka&&this.applyObserverMapDefault(),t===za&&this.setMilestonesShown(!this.hasAttribute(za))}async loadFromSrc(t){this.sightingData=await Ug.json(t)}get sightingData(){return v2(this.currentSighting)}set sightingData(t){this.player.stop(),this.soundPreview=void 0,this.sightingAudio.silence(),this.currentSighting=x2(t),this.issuesPanel.hidden=!0,this.issuesButton.setAttribute("aria-expanded","false"),this.reportIssues(t,this.currentSighting),this.observerMapView.reset(),this.mapFitButton.hidden=!0,this.observerMapAsked=!1,this.player=this.createPlayer(),this.updateTimeLabels(),this.updatePlayPauseButton(),this.refresh(),this.applyObserverMapDefault()}get recordingIssues(){return this.issues}async reportIssues(t,e){const i=++this.issueCheck;let n=[];try{const{default:s}=await $i(async()=>{const{default:r}=await import("./sightingSchema-DbxLUhd5.js");return{default:r}},[],import.meta.url);n=new Bn(s).issues(t)}catch{}i===this.issueCheck&&(this.issues=[...n,...e.loadIssues],Za.warn(this.issues,e.id),this.renderIssues(),this.dispatchEvent(new CustomEvent(G2,{detail:{issues:this.issues},bubbles:!0,composed:!0})))}renderIssues(){const t=this.issues.length;this.issuesBox.hidden=t===0,this.shadow.getElementById("issues-count").textContent=String(t);const e=this.messages.recordingIssues.replace("{count}",String(t));this.issuesButton.title=e,this.issuesButton.setAttribute("aria-label",e),this.shadow.getElementById("issues-title").textContent=e,this.shadow.getElementById("issues-list").replaceChildren(...this.issues.map(i=>{const n=document.createElement("li");return n.textContent=Za.text(i,this.messages.issueTemplates),n}))}get sighting(){return this.currentSighting}previewSound(t){this.soundPreview=t,this.sightingAudio.resume(),this.sightingAudio.setSound(t)}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(t){this.player.seek(t)}get seekableDuration(){return this.player.seekableDuration}get autoReplayEnabled(){return this.loopEnabled}set autoReplayEnabled(t){t!==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(t){if(t!==this.clockHeld){if(this.clockHeld=t,t){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(t){this.toolbar.classList.toggle("hidden",!t),t?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(t){this.currentSighting.event.durationSeconds=t,this.updateTimeLabels(),this.refresh(),this.updatePlayPauseButton()}set selectedSourceIds(t){const e=new Set(t);e.size===this.highlightedSourceIds.size&&[...e].every(n=>this.highlightedSourceIds.has(n))||(this.highlightedSourceIds=e,this.refresh())}hasVisibleShapeAt(t,e){return this.shapeAt(t,e)!==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(t){const e=[this.milestonesButton,this.referencesButton,this.referenceOpacityInput,this.tracesButton,this.observerMapButton];if(t)for(const i of e)t.appendChild(i);else{const i=this.fullscreenButton.parentElement===this.controlsRight?this.fullscreenButton:null;for(const n of e)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 t=this.currentSighting.references;!this.referenceOpacityTouched&&t.length>0&&(this.referenceOpacityInput.value=String(t[0].opacity));for(const e of[...this.referenceViews.keys()])t.some(i=>i.id===e)||this.referenceViews.delete(e);this.severalReferences?this.referencesMenu.hidden||this.renderReferencesMenu():this.closeReferencesMenu(),this.updateReferencesButton(),this.severalReferences&&this.dispatchReferenceView()}viewOfReference(t){let e=this.referenceViews.get(t.id);return e||(e={shown:!0,opacity:t.opacity},this.referenceViews.set(t.id,e)),e}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=t=>{const e=t.composedPath();e.includes(this.referencesMenu)||e.includes(this.referencesButton)||this.closeReferencesMenu()};handleReferencesMenuKey=t=>{t.key==="Escape"&&(this.closeReferencesMenu(),this.referencesButton.focus())};placeReferencesMenu(){const t=this.referencesButton.getBoundingClientRect(),e=this.referencesMenu,i=4;e.style.bottom=`${Math.max(i,window.innerHeight-t.top+i)}px`,e.style.top="auto";const n=e.getBoundingClientRect().width;e.style.left=`${Math.max(i,Math.min(t.left,window.innerWidth-n-i))}px`}renderReferencesMenu(){const t=this.currentSighting.references.map(e=>{const i=this.viewOfReference(e),n=this.said.read(e.title)??e.id,s=document.createElement("div");s.className="reference-row";const r=document.createElement("label"),o=document.createElement("input");o.type="checkbox",o.checked=i.shown;const c=document.createElement("span");c.textContent=n,c.title=n,r.append(o,c);const l=document.createElement("input");return l.type="range",l.min="0",l.max="1",l.step="0.05",l.value=String(i.opacity),l.title=this.messages.referenceOpacity,l.setAttribute("aria-label",`${this.messages.referenceOpacity}: ${n}`),l.disabled=!i.shown,o.addEventListener("change",()=>{i.shown=o.checked,l.disabled=!i.shown,this.updateReferencesButton(),this.dispatchReferenceView()}),l.addEventListener("input",()=>{i.opacity=Number(l.value),this.dispatchReferenceView()}),s.append(r,l),s});this.referencesMenu.setAttribute("aria-label",this.messages.referencesMenu),this.referencesMenu.replaceChildren(...t)}updateReferencesButton(){const t=this.currentSighting.references.length>0,e=this.severalReferences,i=e?this.currentSighting.references.some(s=>this.viewOfReference(s).shown):this.referencesShownState;this.referencesButton.hidden=!t,this.referenceOpacityInput.hidden=!t||!this.referencesShownState||e,this.referencesButton.setAttribute("aria-pressed",String(i)),e?this.referencesButton.setAttribute("aria-haspopup","true"):this.referencesButton.removeAttribute("aria-haspopup"),he.setIcon(this.referencesButton,i?Gt.PICTURES_ON:Gt.PICTURES_OFF);const n=e?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)),he.setIcon(this.tracesButton,this.tracesShownState?Gt.TRACES_ON:Gt.TRACES_OFF);const t=this.tracesShownState?this.messages.hideTraces:this.messages.showTraces;this.tracesButton.title=t,this.tracesButton.setAttribute("aria-label",t)}dispatchReferenceView(){const t=this.severalReferences?Object.fromEntries(this.currentSighting.references.map(e=>[e.id,{...this.viewOfReference(e)}])):void 0;this.dispatchEvent(new CustomEvent("referenceview",{detail:{shown:this.referencesShown,opacity:this.referenceOpacity,views:t}}))}refreshMilestoneMarks(){const t=this.player.seekableDuration,e=t>0?Bo(this.sighting.milestones):[];this.milestoneMarks.replaceChildren(...e.map(i=>{const n=document.createElement("button");n.type="button",n.className="milestone-mark",n.style.left=`${Math.min(Math.max(i.t/t,0),1)*100}%`;const s=this.said.read(i.label)??"",r=this.said.read(i.note),o=r?`${s} — ${r}`:s;return n.title=o,n.setAttribute("aria-label",o),n.dataset.t=String(i.t),n.addEventListener("click",()=>this.player.seek(i.t)),n})),this.refreshSeekSegments(t,e.map(i=>i.t)),this.refreshMomentsPicker(e)}refreshMomentsPicker(t){const e=this.milestonesShown&&t.length>0;this.momentsBox.hidden=!e,this.closeMomentsMenu(),this.momentsMenu.replaceChildren(...t.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)??"",o=this.said.read(i.note);return s.textContent=o?`${r} — ${o}`: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(t){const i=(t?this.said.read(t.label)??"":"")||this.messages.moments;this.momentsCurrent.textContent!==i&&(this.momentsCurrent.textContent=i);for(const n of this.momentsMenu.querySelectorAll("button")){const s=t!==void 0&&Number(n.dataset.t)===t.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=t=>{if(!this.momentsMenu.hidden){if(t instanceof KeyboardEvent){t.key==="Escape"&&this.closeMomentsMenu();return}t.composedPath().some(e=>e===this.momentsMenu||e===this.momentsButton)||this.closeMomentsMenu()}};seekSegmentList=[];refreshSeekSegments(t,e){const n=[0,...this.milestonesShown&&t>0?[...new Set(e.filter(r=>r>0&&r<t))].sort((r,o)=>r-o):[],Math.max(t,0)];this.seekSegmentList=[];const s=[];for(let r=0;r<n.length-1;r++){const o=document.createElement("div");o.className="seek-segment",o.style.flexGrow=String(Math.max(n[r+1]-n[r],1));const c=document.createElement("i");c.className="seek-hover";const l=document.createElement("i");l.className="seek-played",o.append(c,l),s.push(o),this.seekSegmentList.push({start:n[r],end:n[r+1],element:o,played:l,hover:c})}this.seekSegments.replaceChildren(...s),this.paintSeekProgress(this.player.time)}static fillOf(t,e){const i=t.end-t.start,n=i>0?(e-t.start)/i:e>=t.end?1:0;return`${Math.min(Math.max(n,0),1)*100}%`}paintSeekProgress(t){for(const i of this.seekSegmentList)i.played.style.width=he.fillOf(i,t);const e=this.player.seekableDuration;this.seekDot.style.left=`${e>0?Math.min(Math.max(t/e,0),1)*100:0}%`}hoverSeek(t){const e=this.seekInput.getBoundingClientRect(),i=this.player.seekableDuration;if(e.width<=0||i<=0)return;const n=Math.min(Math.max((t.clientX-e.left)/e.width,0),1),s=n*i,r=this.seekSegmentList.length-1;this.seekSegmentList.forEach((f,p)=>{f.hover.style.width=he.fillOf(f,s),f.element.classList.toggle("hovered",s>=f.start&&(s<f.end||p===r))});const o=this.milestonesShown?this.sighting.milestones:[],c=o.length>0?Ah(o,s):void 0,l=c?this.said.read(c.label)??"":"",h=c?this.said.read(c.note):void 0,u=h?`${l} — ${h}`:l;this.seekPreviewTitle.textContent=u,this.seekPreviewTime.textContent=this.formatPosition(s),this.seekPreview.hidden=!1;const d=this.seekPreview.offsetWidth;this.seekPreview.style.left=`${Math.min(Math.max(n*e.width-d/2,0),Math.max(e.width-d,0))}px`,this.paintSeekPreview(s)}leaveSeek(){for(const t of this.seekSegmentList)t.hover.style.width="0",t.element.classList.remove("hovered");this.seekPreview.hidden=!0}seekPreviewPainter;paintSeekPreview(t){const e=this.seekPreviewPainter;this.seekPreviewCanvas.hidden=e===void 0,e?.(t,this.seekPreviewCanvas)}scrubbingPointer;beginTouchScrub(t){if(t.pointerType!=="mouse"){this.scrubbingPointer=t.pointerId;try{this.seekInput.setPointerCapture(t.pointerId)}catch{}this.seekToPointer(t)}}touchScrub(t){t.pointerId===this.scrubbingPointer&&this.seekToPointer(t)}endTouchScrub(t){t.pointerId===this.scrubbingPointer&&(this.scrubbingPointer=void 0,this.seekToPointer(t))}seekToPointer(t){const e=this.seekInput.getBoundingClientRect(),i=this.player.seekableDuration;if(e.width<=0||i<=0)return;const n=Math.min(Math.max((t.clientX-e.left)/e.width,0),1);this.player.seek(this.snapSeekToMark(n*i))}seekSnapArmed=!1;static MARK_SNAP_PX=6;markNear(t){const e=this.player.seekableDuration,i=this.seekInput.getBoundingClientRect().width;if(e<=0||i<=0)return;const n=he.MARK_SNAP_PX/i*e;let s;for(const r of this.milestoneMarks.children){const o=Number(r.dataset.t);Math.abs(o-t)>n||(!s||Math.abs(o-t)<Math.abs(s.t-t))&&(s={t:o,name:r.title})}return s}snapSeekToMark(t){return this.seekSnapArmed?(this.seekSnapArmed=!1,this.markNear(t)?.t??t):t}nameMarkUnder(t){const e=this.seekInput.getBoundingClientRect(),i=this.player.seekableDuration;if(e.width<=0||i<=0)return;const n=(t.clientX-e.left)/e.width*i,s=this.markNear(n);s?this.seekInput.title=s.name:this.seekInput.removeAttribute("title")}showMilestoneAt(t){const e=this.milestonesShown&&this.sighting.milestones.length>0?Ah(this.sighting.milestones,t):void 0;if(this.milestoneCaption.hidden=e===void 0,this.showCurrentMoment(e),!e)return;const i=document.createElement("b");i.textContent=this.said.read(e.label)??"";const n=this.said.read(e.note),s=n?` — ${n}`:"";this.milestoneCaption.replaceChildren(i,document.createTextNode(s))}exposureInstants(t){const e=this.exposureTimes(t),i=1/e.length;return e.map(n=>({shapes:this.shapesAt(n),share:i}))}exposureTimes(t=this.currentTime){const e=Xn.windowEndingAt(t,this.currentSighting.exposure??0);if(e.ms<he.SHORTEST_VISIBLE_EXPOSURE_MS)return[t];const i=Math.min(he.MAX_EXPOSURE_STEPS,Math.max(2,Math.round(e.ms/he.SHORTEST_VISIBLE_EXPOSURE_MS))),n=Math.ceil(this.travelPxOver(e.fromMs,e.ms)/he.EXPOSURE_STEP_PX),s=Math.min(he.MAX_TRAVEL_STEPS,Math.max(i,n)),r=[];for(let o=0;o<s;o++)r.push(e.fromMs+e.ms*o/(s-1));return r}travelPxOver(t,e){const i=this.shapesAt(t),n=this.shapesAt(t+e);let s=0;for(const[r,o]of i){const c=n.get(r);if(!c)continue;const l=c.bounds.x+c.bounds.width/2-(o.bounds.x+o.bounds.width/2),h=c.bounds.y+c.bounds.height/2-(o.bounds.y+o.bounds.height/2);s=Math.max(s,Math.hypot(l,h))}return s}shapeAt(t,e,i){if(!this.accountHidden)for(const n of this.exposureTimes()){const s=this.currentSighting.timeline.hitTest(n,t,e,i);if(s)return s}}shapesAt(t){const e=new Map;for(const i of this.currentSighting.timeline.sourceIds){const n=this.currentSighting.timeline.getInterpolatedShapeAt(t,i);n&&e.set(i,n)}return e}static SHORTEST_VISIBLE_EXPOSURE_MS=20;static MAX_EXPOSURE_STEPS=48;static EXPOSURE_STEP_PX=2;static MAX_TRAVEL_STEPS=320;applyFrameFormat(){const t=mi.frameWidthPx(this.currentSighting.instrument,this.canvas.height);if(this.canvas.width===t)return;this.canvas.width=t,this.canvas.parentElement?.style.setProperty("--frame-aspect",`${t} / ${this.canvas.height}`)}canvasPointFromEvent(t){const e=this.canvas.getBoundingClientRect();if(!(e.width===0||e.height===0))return{x:(t.clientX-e.left)/e.width*this.canvas.width,y:(t.clientY-e.top)/e.height*this.canvas.height}}onFrame(t,e){this.canvasRenderer.clear(this.canvas.width,this.canvas.height);const i=this.playbackState!=="playing"?this.highlightedSourceIds:H2;this.canvasRenderer.setStarPoints(mi.starPointsOf(this.sighting.instrument));const n=(Je(this.sighting,t)?.rollDeg??0)+this.gaitAt(t).rollDeg;this.canvasRenderer.setRoll(n*Math.PI/180);const s=this.exposureInstants(t),r=this.frameShift;if(this.paintsShapes)for(const o of s)for(const[,c]of o.shapes){const l=o.share,h=l===1?c:{...c,transparency:1-(1-c.transparency)*l};this.canvasRenderer.paintShape(this.shifted(h,r))}for(const[o,c]of s[0].shapes)!this.selectionShown||!i.has(o)||(this.paintsShapes?i.size===1?this.canvasRenderer.paintShape({...c,selected:!0}):this.canvasRenderer.paintMemberOutline(c):this.canvasRenderer.paintSelectionOnly(this.shifted(c,r)));if(this.selectionShown&&i.size>1){const o=pn.groupBoundsFor([...e].filter(([c])=>i.has(c)).map(([,c])=>c.bounds));this.canvasRenderer.paintGroupHandles(o)}this.overlayPainter?.(this.canvasRenderer),this.mapShapeBounds=s.flatMap(o=>[...o.shapes.values()].filter(c=>c.transparency<1).map(c=>this.shifted(c,r).bounds)),this.keepObserverMapClear(),this.seekInput.value=String(t),this.paintSeekProgress(t),this.timeStartLabel.textContent=this.formatPosition(t),this.showMilestoneAt(t),this.paintObserverMap(t),this.playbackState==="playing"?(this.soundPreview=void 0,this.sightingAudio.setSound(c2(this.currentSighting,t))):this.soundPreview?this.sightingAudio.setSound(this.soundPreview):this.sightingAudio.silence(),this.updatePlayPauseButton(),this.dispatchEvent(new CustomEvent("timeupdate",{detail:{time:t}}))}shifted(t,e){return e.x===0&&e.y===0?t:{...t,bounds:{...t.bounds,x:t.bounds.x+e.x,y:t.bounds.y+e.y}}}createPlayer(){const t=new l2(this.currentSighting.timeline,(e,i)=>this.onFrame(e,i));return t.loop=this.loopEnabled,t.onEnded=()=>{this.updatePlayPauseButton(),this.dispatchEvent(new CustomEvent("ended",{bubbles:!0,composed:!0}))},t}static SEEK_KEY_STEP_MS=5e3;handleFullscreenKey=t=>{t.key.toLowerCase()!=="f"||t.altKey||t.ctrlKey||t.metaKey||!this.enableClickToPlay||t.composedPath().some(i=>i instanceof HTMLElement&&(i.isContentEditable||["INPUT","TEXTAREA","SELECT"].includes(i.tagName)&&i.type!=="range"))||(t.preventDefault(),this.toggleFullscreen())};handleSeekKey=t=>{if(t.altKey||t.ctrlKey||t.metaKey)return;const e=t.key==="ArrowLeft"?-1:t.key==="ArrowRight"?1:0;if(e){t.preventDefault();const i=this.player.seekableDuration;this.player.seek(Math.min(i,Math.max(0,this.player.time+e*he.SEEK_KEY_STEP_MS)))}else t.key===" "&&(t.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 t=this.playbackFlash;t.innerHTML=this.player.playbackState==="playing"?Gt.PLAY:Gt.PAUSE,t.classList.remove("flashing"),t.offsetWidth,t.classList.add("flashing")}static icons=new WeakMap;static setIcon(t,e){he.icons.get(t)!==e&&(he.icons.set(t,e),t.innerHTML=e)}set captionHeld(t){this.stageElement.classList.toggle("caption-held",t)}static CONTROLS_IDLE_MS=3e3;controlsIdleTimer;wasPlaying=!1;quietControlsValue=!1;get quietControls(){return this.quietControlsValue}set quietControls(t){this.quietControlsValue=t,this.stageElement.classList.toggle("quiet",t)}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},he.CONTROLS_IDLE_MS)))}updatePlayPauseButton(){const t=this.player.playbackState==="playing";this.stageElement.classList.toggle("paused",!t),t!==this.wasPlaying&&t&&this.hoverless&&(!this.quietControlsValue||this.stageElement.classList.contains("touched"))&&this.revealControls(),this.wasPlaying=t,he.setIcon(this.playPauseButton,t?Gt.PAUSE:Gt.PLAY);const e=this.player.seekableDuration>0;this.playPauseButton.disabled=!e;const i=e?t?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 t=this.playbackBeforeClick;t&&(this.currentTime=t.time,t.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(t=>{console.error("<rr0-ufo>: requestFullscreen() failed —",t)})}enterSimulatedFullscreen(){const t=this.fullscreenTarget;this.styleBeforeSimulatedFullscreen=t.getAttribute("style")??"",this.bodyOverflowBeforeSimulatedFullscreen=document.body.style.overflow;const e=t.style;e.setProperty("position","fixed"),e.setProperty("inset","0"),e.setProperty("margin","0"),e.setProperty("max-width","none"),e.setProperty("max-height","none"),e.setProperty("aspect-ratio","auto"),e.setProperty("z-index","2147483647"),e.setProperty("background","#000"),e.setProperty("width","100vw"),e.setProperty("width","100dvw"),e.setProperty("height","100vh"),e.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 t=this.fullscreenTarget;this.styleBeforeSimulatedFullscreen?t.setAttribute("style",this.styleBeforeSimulatedFullscreen):t.removeAttribute("style"),document.body.style.overflow=this.bodyOverflowBeforeSimulatedFullscreen??"",this.simulatedFullscreen=!1,document.removeEventListener("keydown",this.handleSimulatedFullscreenKey),this.updateFullscreenButton(),this.updateMuteButton()}toggleObserverMap(){const t=this.observerMapPanel.hidden;this.observerMapAsked=t,this.setObserverMapOpen(t),this.keepObserverMapClear(),this.dispatchEvent(new CustomEvent("observermapchange",{bubbles:!0,composed:!0,detail:{open:t}}))}observerMapAsked=!1;applyObserverMapDefault(){const t=this.getAttribute(ka),e=t===null?this.sighting.observerMap??this.observerPath?.travels===!0:t!=="false";this.setObserverMapOpen(e&&this.observerPath!==void 0)}setObserverMapOpen(t){this.observerMapPanel.hidden=!t,this.observerMapPanel.removeAttribute("title"),this.observerMapButton.setAttribute("aria-pressed",String(t)),this.updateObserverMapButton(),t&&(this.sizeObserverMapCanvas(),this.loadObserverMapImagery(),this.paintObserverMap(this.currentTime))}updateObserverMapButton(){const t=!this.observerMapPanel.hidden;he.setIcon(this.observerMapButton,t?Gt.MAP_ON:Gt.MAP_OFF);const e=t?this.messages.hideObserverMap:this.messages.showObserverMap;this.observerMapButton.title=e,this.observerMapButton.setAttribute("aria-label",e);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 t=this.observerPath!==void 0;if(this.observerPath=Fa.of(this.currentSighting),this.observerMapButton.hidden=this.observerPath===void 0,!t&&this.observerPath&&this.applyObserverMapDefault(),!this.observerPath){this.setObserverMapOpen(!1),this.observerMapBounds=void 0;return}const e=this.tracesShownState?this.currentSighting.traces.flatMap(n=>n.points):[],i=Ye.including(this.observerPath.boundsAround(he.OBSERVER_MAP_MIN_SPAN_M,he.OBSERVER_MAP_MARGIN),e);(!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(t,e){const i=Math.abs(t.east-t.west)/20;return Math.abs(t.north-e.north)<i&&Math.abs(t.south-e.south)<i&&Math.abs(t.west-e.west)<i&&Math.abs(t.east-e.east)<i}async loadObserverMapImagery(){const t=this.observerMapViewBounds;if(!t||this.observerMapPanel.hidden||this.observerMapImageryLoading||!this.observerMapImageryNeededFor(t))return;const e=this.observerMapView.changed,i=e?Ye.expand(t,he.OBSERVER_MAP_IMAGERY_AHEAD):t,n=he.OBSERVER_MAP_IMAGERY_PX*(e?1+2*he.OBSERVER_MAP_IMAGERY_AHEAD:1);this.observerMapImageryBounds=i,this.observerMapImageryViewWidth=t.east-t.west,this.observerMapImageryLoading=!0;const s=Zg();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(t){const e=this.observerMapImageryBounds;if(!e)return!0;const i=this.observerMapImagery?.bounds??e,n=this.observerMapView.changed?Ye.expand(t,he.OBSERVER_MAP_IMAGERY_LOOKAHEAD):t,s=n.west>=i.west&&n.east<=i.east&&n.south>=i.south&&n.north<=i.north,r=t.east-t.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(t){this.mapSceneBounds=t.map(e=>({x:e.x*this.canvas.width,y:e.y*this.canvas.height,width:e.width*this.canvas.width,height:e.height*this.canvas.height})),this.keepObserverMapClear()}keepObserverMapClear(){if(this.observerMapPanel.hidden)return;const t=this.observerMapBoxPx;if(!t)return;const e=[...this.mapShapeBounds,...this.mapSceneBounds],i=(l,h,u)=>{for(const d of e)if(!(d.x+d.width<l-u||d.x>h+u)&&!(d.y>t.bottom+u||d.y+d.height<t.top-u))return!0;return!1},n=[this.canvas.width-t.width,this.canvas.width],s=[0,t.width],r=he.OBSERVER_MAP_CLEARANCE_PX,o=i(...n,0),c=i(...s,0);if(this.observerMapPanel.classList.toggle("subject-overlap",o&&c&&!this.observerMapAsked),this.observerMapPanel.classList.contains("on-the-left")){!o&&(c||!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 t=this.observerMapPanel.clientWidth;if(t===0)return;const e=Math.round(t*(globalThis.devicePixelRatio??1));this.measureObserverMapBox(),this.observerMapCanvas.width!==e&&(this.observerMapCanvas.width=e,this.observerMapCanvas.height=e)}measureObserverMapBox(){const t=this.observerMapPanel.getBoundingClientRect(),e=this.canvas.getBoundingClientRect();if(e.width===0||e.height===0)return;const i=this.canvas.width/e.width,n=this.canvas.height/e.height;this.observerMapBoxPx={width:t.width*i,top:(t.top-e.top)*n,bottom:(t.bottom-e.top)*n}}paintObserverMap(t){if(this.observerMapPanel.hidden||!this.observerPath||!this.observerMapBounds)return;const e=Je(this.currentSighting,t);e?.lat!==void 0&&e.lng!==void 0&&!this.observerMapDrag?.moved&&this.observerMapView.keepInView(this.observerMapBounds,{lat:e.lat,lng:e.lng},he.OBSERVER_MAP_FOLLOW_MARGIN)&&this.scheduleObserverMapImagery();const i=this.currentSighting.instrument,n=[],s=this.currentSighting.milestones.length>0?Ah(this.currentSighting.milestones,t):void 0;for(const r of this.milestonesShown?Bo(this.currentSighting.milestones):[]){const o=Je(this.currentSighting,r.t);o?.lat===void 0||o.lng===void 0||n.push({label:this.said.read(r.label)??"",note:this.said.read(r.note),t:r.t,lat:o.lat,lng:o.lng,current:r===s})}this.observerMapRenderer.paint({bounds:this.observerMapViewBounds,imagery:this.observerMapImagery,path:this.observerPath,position:e?.lat!==void 0&&e.lng!==void 0?{lat:e.lat,lng:e.lng}:void 0,headingDeg:e?.headingDeg===void 0?void 0:e.headingDeg+this.lookYawDeg,coneHalfAngleDeg:e?Ls.of(i,this.canvas.height,e.fovDeg).halfWidthAngleDeg(mi.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(t),observerLabel:this.said.read(this.currentSighting.observer?.title)??this.messages.observerHere,nightFraction:this.observerMapNightFraction,attribution:this.observerMapFooterLine})}toggleMilestones(){this.setMilestonesShown(!this.milestonesShown)}setMilestonesShown(t){this.milestonesShown=t,this.milestoneMarks.hidden=!t,this.momentsBox.hidden=!t||this.sighting.milestones.length===0,this.refreshSeekSegments(this.player.seekableDuration,Bo(this.sighting.milestones).map(e=>e.t)),this.milestonesButton.setAttribute("aria-pressed",String(t)),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,he.setIcon(this.milestonesButton,this.milestonesShown?Gt.MILESTONES_ON:Gt.MILESTONES_OFF);const t=this.milestonesShown?this.messages.hideMilestones:this.messages.showMilestones;this.milestonesButton.title=t,this.milestonesButton.setAttribute("aria-label",t)}observerMapDecorAt(t){const e=Je(this.currentSighting,0);return e?.lat===void 0||e.lng===void 0?[]:this.currentSighting.decor.filter(i=>i.kind!=="crop").map(i=>{const n=Zo(i,t),{lat:s,lng:r}=Sn(n.eastM,-n.northM,e.lat,e.lng);return{lat:s,lng:r,headingDeg:n.headingDeg,label:this.said.read(i.title)??this.messages.decorHere}})}observerMapNightFraction;setSunAltitude(t){const e=t===void 0?void 0:Math.max(0,Math.min(1,-t/12));e!==this.observerMapNightFraction&&(this.observerMapNightFraction=e,this.paintObserverMap(this.currentTime))}setLookOffset(t,e){t===this.lookYawDeg&&e===this.lookPitchDeg||(this.lookYawDeg=t,this.lookPitchDeg=e,this.refresh())}get frameShiftPx(){return this.frameShift}get frameShift(){const t=this.gaitAt(this.currentTime),e=this.lookYawDeg+t.yawDeg,i=this.lookPitchDeg+t.pitchDeg;if(e===0&&i===0)return{x:0,y:0};const n=Je(this.currentSighting,this.currentTime),s=Ls.of(this.currentSighting.instrument,this.canvas.height,n?.fovDeg??60);return{x:-s.angleDegToRadiusPx(e),y:s.angleDegToRadiusPx(i)}}gaitAt(t){return be.bodyAt(this.currentSighting,t,this.steadyObserver)}mutedState=!1;get muted(){return this.mutedState}set muted(t){t!==this.mutedState&&(this.mutedState=t,!t&&this.volumeState===0&&(this.volumeState=he.RESTORED_VOLUME),this.applyLevel())}volumeState=1;static RESTORED_VOLUME=.5;get volume(){return this.volumeState}set volume(t){this.setVolume(t)}setVolume(t){this.volumeState=Math.min(Math.max(t,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)}get hasSound(){return this.currentSighting.soundTrack.allKeyframes.length>0}updateMuteButton(){const t=!this.hasSound;if(this.muteButton.disabled=t,this.volumeInput.hidden=t,t){he.setIcon(this.muteButton,Gt.MUTED),this.muteButton.title=this.messages.noSound,this.muteButton.setAttribute("aria-label",this.messages.noSound),this.muteButton.setAttribute("aria-pressed","true");return}he.setIcon(this.muteButton,this.mutedState?Gt.MUTED:Gt.VOLUME);const e=this.mutedState?this.messages.unmute:this.messages.mute;this.muteButton.title=e,this.muteButton.setAttribute("aria-label",e),this.muteButton.setAttribute("aria-pressed",String(this.mutedState)),this.volumeInput.value=String(this.level)}updateFullscreenButton(){const t=this.simulatedFullscreen||document.fullscreenElement===this.fullscreenTarget;he.setIcon(this.fullscreenButton,t?Gt.EXIT_FULLSCREEN:Gt.ENTER_FULLSCREEN),this.fullscreenButton.title=t?this.messages.exitFullscreen:this.messages.fullscreen,this.fullscreenButton.setAttribute("aria-label",this.fullscreenButton.title)}get said(){return this.saidTexts??=new Cs(Ua.preferencesFor(this))}saidTexts;async loadLocaleMessages(){const t=zg(Ua.preferencesFor(this),Bg);if(t===this.messagesLanguage||t==="en"&&this.messagesLanguage===void 0)return;this.messagesLanguage=t;const e=await _2(t);this.messagesLanguage===t&&this.applyMessages(e)}messagesLanguage;updateTimeLabelTitles(){const t=this.showClockTime?this.messages.switchToElapsed:this.messages.switchToClockTime,e=this.canSwitchTimeDisplay?` — ${t}`:"";this.timeStartLabel.title=this.messages.currentPosition+e,this.timeEndLabel.title=this.messages.duration+e,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(t){this.messages=t,this.updateTimeLabelTitles(),this.updatePlayPauseButton(),this.updateFullscreenButton(),this.updateMuteButton(),this.updateObserverMapButton(),this.updateReferencesButton(),this.updateTracesButton(),this.updateMilestonesButton(),this.renderIssues()}updateTimeLabels(){const t=this.currentSighting.event,e=r2(t);this.realDurationMs=e!==void 0&&e>0?e:void 0,this.realStartMs=t.time?Ju(t.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(t){if(this.realDurationMs===void 0)return Ec(t);const e=this.currentSighting.timeline.duration,i=e>0&&t<=e?t/e*this.realDurationMs:t;return this.canShowClockTime?Zf(Kf(this.realStartMs+i)):Ec(i)}formatEndOfTimeline(){return this.realDurationMs===void 0?Ec(this.currentSighting.timeline.duration):this.canShowClockTime?Zf(Kf(this.realStartMs+this.realDurationMs)):Ec(this.realDurationMs)}}function Kf(a){const t=new Date(a);return{hour:t.getUTCHours(),minute:t.getUTCMinutes(),second:t.getUTCSeconds()}}function Zf(a){if(a.hour===void 0)return"0:00";const t=e=>String(e).padStart(2,"0");return a.second?`${t(a.hour)}:${t(a.minute??0)}:${t(a.second)}`:`${t(a.hour)}:${t(a.minute??0)}`}function Ec(a){const t=Math.round(a/1e3),e=Math.floor(t/60),i=t%60;return`${e}:${String(i).padStart(2,"0")}`}const Qu="rr0-ufo";function Jg(){customElements.get(Qu)||customElements.define(Qu,he)}const G2="recordingissues";/**
1413
1413
  * @license
1414
1414
  * Copyright 2010-2026 Three.js Authors
1415
1415
  * SPDX-License-Identifier: MIT
1416
- */const A0="185",V2=0,Jf=1,W2=2,Ho=1,X2=2,Lo=3,pr=0,qe=1,xn=2,vs=0,dr=1,Ai=2,jf=3,Qf=4,dc=5,Dr=100,Y2=101,q2=102,$2=103,K2=104,Oo=200,ic=201,Z2=202,J2=203,td=204,nc=205,j2=206,Q2=207,tM=208,eM=209,iM=210,nM=211,sM=212,rM=213,aM=214,ed=0,id=1,nd=2,Ja=3,sd=4,rd=5,ad=6,od=7,T0=0,oM=1,cM=2,Ms=0,jg=1,Qg=2,t1=3,e1=4,i1=5,n1=6,s1=7,tp="attached",lM="detached",r1=300,Xr=301,ja=302,Dh=303,Ih=304,uh=306,sc=1e3,Ri=1001,cd=1002,Ce=1003,hM=1004,Ac=1005,le=1006,Ch=1007,Lr=1008,yn=1009,a1=1010,o1=1011,rc=1012,R0=1013,Nn=1014,Ui=1015,$e=1016,D0=1017,I0=1018,ac=1020,c1=35902,l1=35899,h1=1021,u1=1022,Di=1023,Fs=1026,Or=1027,dh=1028,C0=1029,Yr=1030,P0=1031,L0=1033,Al=33776,Tl=33777,Rl=33778,Dl=33779,ld=35840,hd=35841,ud=35842,dd=35843,fd=36196,pd=37492,md=37496,gd=37488,vd=37489,kl=37490,Md=37491,xd=37808,yd=37809,Sd=37810,_d=37811,bd=37812,wd=37813,Ed=37814,Ad=37815,Td=37816,Rd=37817,Dd=37818,Id=37819,Cd=37820,Pd=37821,Ld=36492,Od=36494,Nd=36495,Fd=36283,Ud=36284,zl=36285,kd=36286,d1=2200,uM=2201,dM=2202,Bl=2300,zd=2301,Ph=2302,ep=2303,Da=2400,Ia=2401,Hl=2402,O0=2500,fM=2501,XA=0,YA=1,qA=2,pM=3200,Gl=0,mM=1,rr="",qi="srgb",Vl="srgb-linear",Wl="linear",we="srgb",ta=7680,ip=519,gM=512,vM=513,MM=514,N0=515,xM=516,yM=517,F0=518,SM=519,Bd=35044,Xl="300 es",ms=2e3,oc=2001;function _M(a){for(let t=a.length-1;t>=0;--t)if(a[t]>=65535)return!0;return!1}function bM(a){return ArrayBuffer.isView(a)&&!(a instanceof DataView)}function cc(a){return document.createElementNS("http://www.w3.org/1999/xhtml",a)}function wM(){const a=cc("canvas");return a.style.display="block",a}const np={};function Yl(...a){const t="THREE."+a.shift();console.log(t,...a)}function f1(a){const t=a[0];if(typeof t=="string"&&t.startsWith("TSL:")){const e=a[1];e&&e.isStackTrace?a[0]+=" "+e.getLocation():a[1]='Stack trace not available. Enable "THREE.Node.captureStackTrace" to capture stack traces.'}return a}function It(...a){a=f1(a);const t="THREE."+a.shift();{const e=a[0];e&&e.isStackTrace?console.warn(e.getError(t)):console.warn(t,...a)}}function Wt(...a){a=f1(a);const t="THREE."+a.shift();{const e=a[0];e&&e.isStackTrace?console.error(e.getError(t)):console.error(t,...a)}}function Ba(...a){const t=a.join(" ");t in np||(np[t]=!0,It(...a))}function EM(a,t,e){return new Promise(function(i,n){function s(){switch(a.clientWaitSync(t,a.SYNC_FLUSH_COMMANDS_BIT,0)){case a.WAIT_FAILED:n();break;case a.TIMEOUT_EXPIRED:setTimeout(s,e);break;default:i()}}setTimeout(s,e)})}const AM={[ed]:id,[nd]:ad,[sd]:od,[Ja]:rd,[id]:ed,[ad]:nd,[od]:sd,[rd]:Ja};class vr{addEventListener(t,e){this._listeners===void 0&&(this._listeners={});const i=this._listeners;i[t]===void 0&&(i[t]=[]),i[t].indexOf(e)===-1&&i[t].push(e)}hasEventListener(t,e){const i=this._listeners;return i===void 0?!1:i[t]!==void 0&&i[t].indexOf(e)!==-1}removeEventListener(t,e){const i=this._listeners;if(i===void 0)return;const n=i[t];if(n!==void 0){const s=n.indexOf(e);s!==-1&&n.splice(s,1)}}dispatchEvent(t){const e=this._listeners;if(e===void 0)return;const i=e[t.type];if(i!==void 0){t.target=this;const n=i.slice(0);for(let s=0,r=n.length;s<r;s++)n[s].call(this,t);t.target=null}}}const Pi=["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 sp=1234567;const Go=Math.PI/180,Qa=180/Math.PI;function Kn(){const a=Math.random()*4294967295|0,t=Math.random()*4294967295|0,e=Math.random()*4294967295|0,i=Math.random()*4294967295|0;return(Pi[a&255]+Pi[a>>8&255]+Pi[a>>16&255]+Pi[a>>24&255]+"-"+Pi[t&255]+Pi[t>>8&255]+"-"+Pi[t>>16&15|64]+Pi[t>>24&255]+"-"+Pi[e&63|128]+Pi[e>>8&255]+"-"+Pi[e>>16&255]+Pi[e>>24&255]+Pi[i&255]+Pi[i>>8&255]+Pi[i>>16&255]+Pi[i>>24&255]).toLowerCase()}function Zt(a,t,e){return Math.max(t,Math.min(e,a))}function U0(a,t){return(a%t+t)%t}function TM(a,t,e,i,n){return i+(a-t)*(n-i)/(e-t)}function RM(a,t,e){return a!==t?(e-a)/(t-a):0}function Vo(a,t,e){return(1-e)*a+e*t}function DM(a,t,e,i){return Vo(a,t,1-Math.exp(-e*i))}function IM(a,t=1){return t-Math.abs(U0(a,t*2)-t)}function CM(a,t,e){return a<=t?0:a>=e?1:(a=(a-t)/(e-t),a*a*(3-2*a))}function PM(a,t,e){return a<=t?0:a>=e?1:(a=(a-t)/(e-t),a*a*a*(a*(a*6-15)+10))}function LM(a,t){return a+Math.floor(Math.random()*(t-a+1))}function OM(a,t){return a+Math.random()*(t-a)}function NM(a){return a*(.5-Math.random())}function FM(a){a!==void 0&&(sp=a);let t=sp+=1831565813;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}function UM(a){return a*Go}function kM(a){return a*Qa}function zM(a){return(a&a-1)===0&&a!==0}function BM(a){return Math.pow(2,Math.ceil(Math.log(a)/Math.LN2))}function HM(a){return Math.pow(2,Math.floor(Math.log(a)/Math.LN2))}function GM(a,t,e,i,n){const s=Math.cos,r=Math.sin,o=s(e/2),c=r(e/2),l=s((t+i)/2),h=r((t+i)/2),u=s((t-i)/2),d=r((t-i)/2),f=s((i-t)/2),p=r((i-t)/2);switch(n){case"XYX":a.set(o*h,c*u,c*d,o*l);break;case"YZY":a.set(c*d,o*h,c*u,o*l);break;case"ZXZ":a.set(c*u,c*d,o*h,o*l);break;case"XZX":a.set(o*h,c*p,c*f,o*l);break;case"YXY":a.set(c*f,o*h,c*p,o*l);break;case"ZYZ":a.set(c*p,c*f,o*h,o*l);break;default:It("MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+n)}}function qn(a,t){switch(t.constructor){case Float32Array:return a;case Uint32Array:return a/4294967295;case Uint16Array:return a/65535;case Uint8Array:return a/255;case Int32Array:return Math.max(a/2147483647,-1);case Int16Array:return Math.max(a/32767,-1);case Int8Array:return Math.max(a/127,-1);default:throw new Error("THREE.MathUtils: Invalid component type.")}}function Ee(a,t){switch(t.constructor){case Float32Array:return a;case Uint32Array:return Math.round(a*4294967295);case Uint16Array:return Math.round(a*65535);case Uint8Array:return Math.round(a*255);case Int32Array:return Math.round(a*2147483647);case Int16Array:return Math.round(a*32767);case Int8Array:return Math.round(a*127);default:throw new Error("THREE.MathUtils: Invalid component type.")}}const $A={DEG2RAD:Go,RAD2DEG:Qa,generateUUID:Kn,clamp:Zt,euclideanModulo:U0,mapLinear:TM,inverseLerp:RM,lerp:Vo,damp:DM,pingpong:IM,smoothstep:CM,smootherstep:PM,randInt:LM,randFloat:OM,randFloatSpread:NM,seededRandom:FM,degToRad:UM,radToDeg:kM,isPowerOfTwo:zM,ceilPowerOfTwo:BM,floorPowerOfTwo:HM,setQuaternionFromProperEuler:GM,normalize:Ee,denormalize:qn};class Mt{static{Mt.prototype.isVector2=!0}constructor(t=0,e=0){this.x=t,this.y=e}get width(){return this.x}set width(t){this.x=t}get height(){return this.y}set height(t){this.y=t}set(t,e){return this.x=t,this.y=e,this}setScalar(t){return this.x=t,this.y=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;default:throw new Error("THREE.Vector2: index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;default:throw new Error("THREE.Vector2: index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y)}copy(t){return this.x=t.x,this.y=t.y,this}add(t){return this.x+=t.x,this.y+=t.y,this}addScalar(t){return this.x+=t,this.y+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this}subScalar(t){return this.x-=t,this.y-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this}multiply(t){return this.x*=t.x,this.y*=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divide(t){return this.x/=t.x,this.y/=t.y,this}divideScalar(t){return this.multiplyScalar(1/t)}applyMatrix3(t){const e=this.x,i=this.y,n=t.elements;return this.x=n[0]*e+n[3]*i+n[6],this.y=n[1]*e+n[4]*i+n[7],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this}clamp(t,e){return this.x=Zt(this.x,t.x,e.x),this.y=Zt(this.y,t.y,e.y),this}clampScalar(t,e){return this.x=Zt(this.x,t,e),this.y=Zt(this.y,t,e),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Zt(i,t,e))}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(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.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(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;const i=this.dot(t)/e;return Math.acos(Zt(i,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,i=this.y-t.y;return e*e+i*i}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this}lerpVectors(t,e,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this}equals(t){return t.x===this.x&&t.y===this.y}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this}rotateAround(t,e){const i=Math.cos(e),n=Math.sin(e),s=this.x-t.x,r=this.y-t.y;return this.x=s*i-r*n+t.x,this.y=s*n+r*i+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class on{constructor(t=0,e=0,i=0,n=1){this.isQuaternion=!0,this._x=t,this._y=e,this._z=i,this._w=n}static slerpFlat(t,e,i,n,s,r,o){let c=i[n+0],l=i[n+1],h=i[n+2],u=i[n+3],d=s[r+0],f=s[r+1],p=s[r+2],v=s[r+3];if(u!==v||c!==d||l!==f||h!==p){let m=c*d+l*f+h*p+u*v;m<0&&(d=-d,f=-f,p=-p,v=-v,m=-m);let g=1-o;if(m<.9995){const S=Math.acos(m),x=Math.sin(S);g=Math.sin(g*S)/x,o=Math.sin(o*S)/x,c=c*g+d*o,l=l*g+f*o,h=h*g+p*o,u=u*g+v*o}else{c=c*g+d*o,l=l*g+f*o,h=h*g+p*o,u=u*g+v*o;const S=1/Math.sqrt(c*c+l*l+h*h+u*u);c*=S,l*=S,h*=S,u*=S}}t[e]=c,t[e+1]=l,t[e+2]=h,t[e+3]=u}static multiplyQuaternionsFlat(t,e,i,n,s,r){const o=i[n],c=i[n+1],l=i[n+2],h=i[n+3],u=s[r],d=s[r+1],f=s[r+2],p=s[r+3];return t[e]=o*p+h*u+c*f-l*d,t[e+1]=c*p+h*d+l*u-o*f,t[e+2]=l*p+h*f+o*d-c*u,t[e+3]=h*p-o*u-c*d-l*f,t}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get w(){return this._w}set w(t){this._w=t,this._onChangeCallback()}set(t,e,i,n){return this._x=t,this._y=e,this._z=i,this._w=n,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback(),this}setFromEuler(t,e=!0){const i=t._x,n=t._y,s=t._z,r=t._order,o=Math.cos,c=Math.sin,l=o(i/2),h=o(n/2),u=o(s/2),d=c(i/2),f=c(n/2),p=c(s/2);switch(r){case"XYZ":this._x=d*h*u+l*f*p,this._y=l*f*u-d*h*p,this._z=l*h*p+d*f*u,this._w=l*h*u-d*f*p;break;case"YXZ":this._x=d*h*u+l*f*p,this._y=l*f*u-d*h*p,this._z=l*h*p-d*f*u,this._w=l*h*u+d*f*p;break;case"ZXY":this._x=d*h*u-l*f*p,this._y=l*f*u+d*h*p,this._z=l*h*p+d*f*u,this._w=l*h*u-d*f*p;break;case"ZYX":this._x=d*h*u-l*f*p,this._y=l*f*u+d*h*p,this._z=l*h*p-d*f*u,this._w=l*h*u+d*f*p;break;case"YZX":this._x=d*h*u+l*f*p,this._y=l*f*u+d*h*p,this._z=l*h*p-d*f*u,this._w=l*h*u-d*f*p;break;case"XZY":this._x=d*h*u-l*f*p,this._y=l*f*u-d*h*p,this._z=l*h*p+d*f*u,this._w=l*h*u+d*f*p;break;default:It("Quaternion: .setFromEuler() encountered an unknown order: "+r)}return e===!0&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const i=e/2,n=Math.sin(i);return this._x=t.x*n,this._y=t.y*n,this._z=t.z*n,this._w=Math.cos(i),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,i=e[0],n=e[4],s=e[8],r=e[1],o=e[5],c=e[9],l=e[2],h=e[6],u=e[10],d=i+o+u;if(d>0){const f=.5/Math.sqrt(d+1);this._w=.25/f,this._x=(h-c)*f,this._y=(s-l)*f,this._z=(r-n)*f}else if(i>o&&i>u){const f=2*Math.sqrt(1+i-o-u);this._w=(h-c)/f,this._x=.25*f,this._y=(n+r)/f,this._z=(s+l)/f}else if(o>u){const f=2*Math.sqrt(1+o-i-u);this._w=(s-l)/f,this._x=(n+r)/f,this._y=.25*f,this._z=(c+h)/f}else{const f=2*Math.sqrt(1+u-i-o);this._w=(r-n)/f,this._x=(s+l)/f,this._y=(c+h)/f,this._z=.25*f}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let i=t.dot(e)+1;return i<1e-8?(i=0,Math.abs(t.x)>Math.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=i):(this._x=0,this._y=-t.z,this._z=t.y,this._w=i)):(this._x=t.y*e.z-t.z*e.y,this._y=t.z*e.x-t.x*e.z,this._z=t.x*e.y-t.y*e.x,this._w=i),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(Zt(this.dot(t),-1,1)))}rotateTowards(t,e){const i=this.angleTo(t);if(i===0)return this;const n=Math.min(1,e/i);return this.slerp(t,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(t){return this._x*t._x+this._y*t._y+this._z*t._z+this._w*t._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 t=this.length();return t===0?(this._x=0,this._y=0,this._z=0,this._w=1):(t=1/t,this._x=this._x*t,this._y=this._y*t,this._z=this._z*t,this._w=this._w*t),this._onChangeCallback(),this}multiply(t){return this.multiplyQuaternions(this,t)}premultiply(t){return this.multiplyQuaternions(t,this)}multiplyQuaternions(t,e){const i=t._x,n=t._y,s=t._z,r=t._w,o=e._x,c=e._y,l=e._z,h=e._w;return this._x=i*h+r*o+n*l-s*c,this._y=n*h+r*c+s*o-i*l,this._z=s*h+r*l+i*c-n*o,this._w=r*h-i*o-n*c-s*l,this._onChangeCallback(),this}slerp(t,e){let i=t._x,n=t._y,s=t._z,r=t._w,o=this.dot(t);o<0&&(i=-i,n=-n,s=-s,r=-r,o=-o);let c=1-e;if(o<.9995){const l=Math.acos(o),h=Math.sin(l);c=Math.sin(c*l)/h,e=Math.sin(e*l)/h,this._x=this._x*c+i*e,this._y=this._y*c+n*e,this._z=this._z*c+s*e,this._w=this._w*c+r*e,this._onChangeCallback()}else this._x=this._x*c+i*e,this._y=this._y*c+n*e,this._z=this._z*c+s*e,this._w=this._w*c+r*e,this.normalize();return this}slerpQuaternions(t,e,i){return this.copy(t).slerp(e,i)}random(){const t=2*Math.PI*Math.random(),e=2*Math.PI*Math.random(),i=Math.random(),n=Math.sqrt(1-i),s=Math.sqrt(i);return this.set(n*Math.sin(t),n*Math.cos(t),s*Math.sin(e),s*Math.cos(e))}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._w===this._w}fromArray(t,e=0){return this._x=t[e],this._y=t[e+1],this._z=t[e+2],this._w=t[e+3],this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._w,t}fromBufferAttribute(t,e){return this._x=t.getX(e),this._y=t.getY(e),this._z=t.getZ(e),this._w=t.getW(e),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class R{static{R.prototype.isVector3=!0}constructor(t=0,e=0,i=0){this.x=t,this.y=e,this.z=i}set(t,e,i){return i===void 0&&(i=this.z),this.x=t,this.y=e,this.z=i,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;default:throw new Error("THREE.Vector3: index is out of range: "+t)}return this}getComponent(t){switch(t){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: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}multiplyVectors(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this.z=t.z*e.z,this}applyEuler(t){return this.applyQuaternion(rp.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(rp.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,i=this.y,n=this.z,s=t.elements;return this.x=s[0]*e+s[3]*i+s[6]*n,this.y=s[1]*e+s[4]*i+s[7]*n,this.z=s[2]*e+s[5]*i+s[8]*n,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,i=this.y,n=this.z,s=t.elements,r=1/(s[3]*e+s[7]*i+s[11]*n+s[15]);return this.x=(s[0]*e+s[4]*i+s[8]*n+s[12])*r,this.y=(s[1]*e+s[5]*i+s[9]*n+s[13])*r,this.z=(s[2]*e+s[6]*i+s[10]*n+s[14])*r,this}applyQuaternion(t){const e=this.x,i=this.y,n=this.z,s=t.x,r=t.y,o=t.z,c=t.w,l=2*(r*n-o*i),h=2*(o*e-s*n),u=2*(s*i-r*e);return this.x=e+c*l+r*u-o*h,this.y=i+c*h+o*l-s*u,this.z=n+c*u+s*h-r*l,this}project(t){return this.applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix)}unproject(t){return this.applyMatrix4(t.projectionMatrixInverse).applyMatrix4(t.matrixWorld)}transformDirection(t){const e=this.x,i=this.y,n=this.z,s=t.elements;return this.x=s[0]*e+s[4]*i+s[8]*n,this.y=s[1]*e+s[5]*i+s[9]*n,this.z=s[2]*e+s[6]*i+s[10]*n,this.normalize()}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this}divideScalar(t){return this.multiplyScalar(1/t)}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this}clamp(t,e){return this.x=Zt(this.x,t.x,e.x),this.y=Zt(this.y,t.y,e.y),this.z=Zt(this.z,t.z,e.z),this}clampScalar(t,e){return this.x=Zt(this.x,t,e),this.y=Zt(this.y,t,e),this.z=Zt(this.z,t,e),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Zt(i,t,e))}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(t){return this.x*t.x+this.y*t.y+this.z*t.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(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this}lerpVectors(t,e,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this.z=t.z+(e.z-t.z)*i,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){const i=t.x,n=t.y,s=t.z,r=e.x,o=e.y,c=e.z;return this.x=n*c-s*o,this.y=s*r-i*c,this.z=i*o-n*r,this}projectOnVector(t){const e=t.lengthSq();if(e===0)return this.set(0,0,0);const i=t.dot(this)/e;return this.copy(t).multiplyScalar(i)}projectOnPlane(t){return Lh.copy(this).projectOnVector(t),this.sub(Lh)}reflect(t){return this.sub(Lh.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;const i=this.dot(t)/e;return Math.acos(Zt(i,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,i=this.y-t.y,n=this.z-t.z;return e*e+i*i+n*n}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)}setFromSpherical(t){return this.setFromSphericalCoords(t.radius,t.phi,t.theta)}setFromSphericalCoords(t,e,i){const n=Math.sin(e)*t;return this.x=n*Math.sin(i),this.y=Math.cos(e)*t,this.z=n*Math.cos(i),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,i){return this.x=t*Math.sin(e),this.y=i,this.z=t*Math.cos(e),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this}setFromMatrixScale(t){const e=this.setFromMatrixColumn(t,0).length(),i=this.setFromMatrixColumn(t,1).length(),n=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=i,this.z=n,this}setFromMatrixColumn(t,e){return this.fromArray(t.elements,e*4)}setFromMatrix3Column(t,e){return this.fromArray(t.elements,e*3)}setFromEuler(t){return this.x=t._x,this.y=t._y,this.z=t._z,this}setFromColor(t){return this.x=t.r,this.y=t.g,this.z=t.b,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const t=Math.random()*Math.PI*2,e=Math.random()*2-1,i=Math.sqrt(1-e*e);return this.x=i*Math.cos(t),this.y=e,this.z=i*Math.sin(t),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const Lh=new R,rp=new on;class $t{static{$t.prototype.isMatrix3=!0}constructor(t,e,i,n,s,r,o,c,l){this.elements=[1,0,0,0,1,0,0,0,1],t!==void 0&&this.set(t,e,i,n,s,r,o,c,l)}set(t,e,i,n,s,r,o,c,l){const h=this.elements;return h[0]=t,h[1]=n,h[2]=o,h[3]=e,h[4]=s,h[5]=c,h[6]=i,h[7]=r,h[8]=l,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){const e=this.elements,i=t.elements;return e[0]=i[0],e[1]=i[1],e[2]=i[2],e[3]=i[3],e[4]=i[4],e[5]=i[5],e[6]=i[6],e[7]=i[7],e[8]=i[8],this}extractBasis(t,e,i){return t.setFromMatrix3Column(this,0),e.setFromMatrix3Column(this,1),i.setFromMatrix3Column(this,2),this}setFromMatrix4(t){const e=t.elements;return this.set(e[0],e[4],e[8],e[1],e[5],e[9],e[2],e[6],e[10]),this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const i=t.elements,n=e.elements,s=this.elements,r=i[0],o=i[3],c=i[6],l=i[1],h=i[4],u=i[7],d=i[2],f=i[5],p=i[8],v=n[0],m=n[3],g=n[6],S=n[1],x=n[4],M=n[7],b=n[2],w=n[5],T=n[8];return s[0]=r*v+o*S+c*b,s[3]=r*m+o*x+c*w,s[6]=r*g+o*M+c*T,s[1]=l*v+h*S+u*b,s[4]=l*m+h*x+u*w,s[7]=l*g+h*M+u*T,s[2]=d*v+f*S+p*b,s[5]=d*m+f*x+p*w,s[8]=d*g+f*M+p*T,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[3]*=t,e[6]*=t,e[1]*=t,e[4]*=t,e[7]*=t,e[2]*=t,e[5]*=t,e[8]*=t,this}determinant(){const t=this.elements,e=t[0],i=t[1],n=t[2],s=t[3],r=t[4],o=t[5],c=t[6],l=t[7],h=t[8];return e*r*h-e*o*l-i*s*h+i*o*c+n*s*l-n*r*c}invert(){const t=this.elements,e=t[0],i=t[1],n=t[2],s=t[3],r=t[4],o=t[5],c=t[6],l=t[7],h=t[8],u=h*r-o*l,d=o*c-h*s,f=l*s-r*c,p=e*u+i*d+n*f;if(p===0)return this.set(0,0,0,0,0,0,0,0,0);const v=1/p;return t[0]=u*v,t[1]=(n*l-h*i)*v,t[2]=(o*i-n*r)*v,t[3]=d*v,t[4]=(h*e-n*c)*v,t[5]=(n*s-o*e)*v,t[6]=f*v,t[7]=(i*c-l*e)*v,t[8]=(r*e-i*s)*v,this}transpose(){let t;const e=this.elements;return t=e[1],e[1]=e[3],e[3]=t,t=e[2],e[2]=e[6],e[6]=t,t=e[5],e[5]=e[7],e[7]=t,this}getNormalMatrix(t){return this.setFromMatrix4(t).invert().transpose()}transposeIntoArray(t){const e=this.elements;return t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8],this}setUvTransform(t,e,i,n,s,r,o){const c=Math.cos(s),l=Math.sin(s);return this.set(i*c,i*l,-i*(c*r+l*o)+r+t,-n*l,n*c,-n*(-l*r+c*o)+o+e,0,0,1),this}scale(t,e){return Ba("Matrix3: .scale() is deprecated. Use .makeScale() instead."),this.premultiply(Oh.makeScale(t,e)),this}rotate(t){return Ba("Matrix3: .rotate() is deprecated. Use .makeRotation() instead."),this.premultiply(Oh.makeRotation(-t)),this}translate(t,e){return Ba("Matrix3: .translate() is deprecated. Use .makeTranslation() instead."),this.premultiply(Oh.makeTranslation(t,e)),this}makeTranslation(t,e){return t.isVector2?this.set(1,0,t.x,0,1,t.y,0,0,1):this.set(1,0,t,0,1,e,0,0,1),this}makeRotation(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,-i,0,i,e,0,0,0,1),this}makeScale(t,e){return this.set(t,0,0,0,e,0,0,0,1),this}equals(t){const e=this.elements,i=t.elements;for(let n=0;n<9;n++)if(e[n]!==i[n])return!1;return!0}fromArray(t,e=0){for(let i=0;i<9;i++)this.elements[i]=t[i+e];return this}toArray(t=[],e=0){const i=this.elements;return t[e]=i[0],t[e+1]=i[1],t[e+2]=i[2],t[e+3]=i[3],t[e+4]=i[4],t[e+5]=i[5],t[e+6]=i[6],t[e+7]=i[7],t[e+8]=i[8],t}clone(){return new this.constructor().fromArray(this.elements)}}const Oh=new $t,ap=new $t().set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),op=new $t().set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);function VM(){const a={enabled:!0,workingColorSpace:Vl,spaces:{},convert:function(n,s,r){return this.enabled===!1||s===r||!s||!r||(this.spaces[s].transfer===we&&(n.r=Ns(n.r),n.g=Ns(n.g),n.b=Ns(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===we&&(n.r=Ha(n.r),n.g=Ha(n.g),n.b=Ha(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===rr?Wl: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 Ba("ColorManagement: .fromWorkingColorSpace() has been renamed to .workingToColorSpace()."),a.workingToColorSpace(n,s)},toWorkingColorSpace:function(n,s){return Ba("ColorManagement: .toWorkingColorSpace() has been renamed to .colorSpaceToWorking()."),a.colorSpaceToWorking(n,s)}},t=[.64,.33,.3,.6,.15,.06],e=[.2126,.7152,.0722],i=[.3127,.329];return a.define({[Vl]:{primaries:t,whitePoint:i,transfer:Wl,toXYZ:ap,fromXYZ:op,luminanceCoefficients:e,workingColorSpaceConfig:{unpackColorSpace:qi},outputColorSpaceConfig:{drawingBufferColorSpace:qi}},[qi]:{primaries:t,whitePoint:i,transfer:we,toXYZ:ap,fromXYZ:op,luminanceCoefficients:e,outputColorSpaceConfig:{drawingBufferColorSpace:qi}}}),a}const ce=VM();function Ns(a){return a<.04045?a*.0773993808:Math.pow(a*.9478672986+.0521327014,2.4)}function Ha(a){return a<.0031308?a*12.92:1.055*Math.pow(a,.41666)-.055}let ea;class WM{static getDataURL(t,e="image/png"){if(/^data:/i.test(t.src)||typeof HTMLCanvasElement>"u")return t.src;let i;if(t instanceof HTMLCanvasElement)i=t;else{ea===void 0&&(ea=cc("canvas")),ea.width=t.width,ea.height=t.height;const n=ea.getContext("2d");t instanceof ImageData?n.putImageData(t,0,0):n.drawImage(t,0,0,t.width,t.height),i=ea}return i.toDataURL(e)}static sRGBToLinear(t){if(typeof HTMLImageElement<"u"&&t instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&t instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&t instanceof ImageBitmap){const e=cc("canvas");e.width=t.width,e.height=t.height;const i=e.getContext("2d");i.drawImage(t,0,0,t.width,t.height);const n=i.getImageData(0,0,t.width,t.height),s=n.data;for(let r=0;r<s.length;r++)s[r]=Ns(s[r]/255)*255;return i.putImageData(n,0,0),e}else if(t.data){const e=t.data.slice(0);for(let i=0;i<e.length;i++)e instanceof Uint8Array||e instanceof Uint8ClampedArray?e[i]=Math.floor(Ns(e[i]/255)*255):e[i]=Ns(e[i]);return{data:e,width:t.width,height:t.height}}else return It("ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."),t}}let XM=0;class k0{constructor(t=null){this.isSource=!0,Object.defineProperty(this,"id",{value:XM++}),this.uuid=Kn(),this.data=t,this.dataReady=!0,this.version=0}getSize(t){const e=this.data;return typeof HTMLVideoElement<"u"&&e instanceof HTMLVideoElement?t.set(e.videoWidth,e.videoHeight,0):typeof VideoFrame<"u"&&e instanceof VideoFrame?t.set(e.displayWidth,e.displayHeight,0):e!==null?t.set(e.width,e.height,e.depth||0):t.set(0,0,0),t}set needsUpdate(t){t===!0&&this.version++}toJSON(t){const e=t===void 0||typeof t=="string";if(!e&&t.images[this.uuid]!==void 0)return t.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,o=n.length;r<o;r++)n[r].isDataTexture?s.push(Nh(n[r].image)):s.push(Nh(n[r]))}else s=Nh(n);i.url=s}return e||(t.images[this.uuid]=i),i}}function Nh(a){return typeof HTMLImageElement<"u"&&a instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&a instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&a instanceof ImageBitmap?WM.getDataURL(a):a.data?{data:Array.from(a.data),width:a.width,height:a.height,type:a.data.constructor.name}:(It("Texture: Unable to serialize Texture."),{})}let YM=0;const Fh=new R;class Ei extends vr{constructor(t=Ei.DEFAULT_IMAGE,e=Ei.DEFAULT_MAPPING,i=Ri,n=Ri,s=le,r=Lr,o=Di,c=yn,l=Ei.DEFAULT_ANISOTROPY,h=rr){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:YM++}),this.uuid=Kn(),this.name="",this.source=new k0(t),this.mipmaps=[],this.mapping=e,this.channel=0,this.wrapS=i,this.wrapT=n,this.magFilter=s,this.minFilter=r,this.anisotropy=l,this.format=o,this.internalFormat=null,this.type=c,this.offset=new Mt(0,0),this.repeat=new Mt(1,1),this.center=new Mt(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new $t,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=!!(t&&t.depth&&t.depth>1),this.pmremVersion=0,this.normalized=!1}get width(){return this.source.getSize(Fh).x}get height(){return this.source.getSize(Fh).y}get depth(){return this.source.getSize(Fh).z}get image(){return this.source.data}set image(t){this.source.data=t}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(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}clone(){return new this.constructor().copy(this)}copy(t){return this.name=t.name,this.source=t.source,this.mipmaps=t.mipmaps.slice(0),this.mapping=t.mapping,this.channel=t.channel,this.wrapS=t.wrapS,this.wrapT=t.wrapT,this.magFilter=t.magFilter,this.minFilter=t.minFilter,this.anisotropy=t.anisotropy,this.format=t.format,this.internalFormat=t.internalFormat,this.type=t.type,this.normalized=t.normalized,this.offset.copy(t.offset),this.repeat.copy(t.repeat),this.center.copy(t.center),this.rotation=t.rotation,this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrix.copy(t.matrix),this.generateMipmaps=t.generateMipmaps,this.premultiplyAlpha=t.premultiplyAlpha,this.flipY=t.flipY,this.unpackAlignment=t.unpackAlignment,this.colorSpace=t.colorSpace,this.renderTarget=t.renderTarget,this.isRenderTargetTexture=t.isRenderTargetTexture,this.isArrayTexture=t.isArrayTexture,this.userData=JSON.parse(JSON.stringify(t.userData)),this.needsUpdate=!0,this}setValues(t){for(const e in t){const i=t[e];if(i===void 0){It(`Texture.setValues(): parameter '${e}' has value of undefined.`);continue}const n=this[e];if(n===void 0){It(`Texture.setValues(): property '${e}' 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[e]=i}}toJSON(t){const e=t===void 0||typeof t=="string";if(!e&&t.textures[this.uuid]!==void 0)return t.textures[this.uuid];const i={metadata:{version:4.7,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,image:this.source.toJSON(t).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),e||(t.textures[this.uuid]=i),i}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(t){if(this.mapping!==r1)return t;if(t.applyMatrix3(this.matrix),t.x<0||t.x>1)switch(this.wrapS){case sc:t.x=t.x-Math.floor(t.x);break;case Ri:t.x=t.x<0?0:1;break;case cd:Math.abs(Math.floor(t.x)%2)===1?t.x=Math.ceil(t.x)-t.x:t.x=t.x-Math.floor(t.x);break}if(t.y<0||t.y>1)switch(this.wrapT){case sc:t.y=t.y-Math.floor(t.y);break;case Ri:t.y=t.y<0?0:1;break;case cd:Math.abs(Math.floor(t.y)%2)===1?t.y=Math.ceil(t.y)-t.y:t.y=t.y-Math.floor(t.y);break}return this.flipY&&(t.y=1-t.y),t}set needsUpdate(t){t===!0&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(t){t===!0&&this.pmremVersion++}}Ei.DEFAULT_IMAGE=null;Ei.DEFAULT_MAPPING=r1;Ei.DEFAULT_ANISOTROPY=1;class ae{static{ae.prototype.isVector4=!0}constructor(t=0,e=0,i=0,n=1){this.x=t,this.y=e,this.z=i,this.w=n}get width(){return this.z}set width(t){this.z=t}get height(){return this.w}set height(t){this.w=t}set(t,e,i,n){return this.x=t,this.y=e,this.z=i,this.w=n,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this.w=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setW(t){return this.w=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;case 3:this.w=e;break;default:throw new Error("THREE.Vector4: index is out of range: "+t)}return this}getComponent(t){switch(t){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: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w!==void 0?t.w:1,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this.w+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this.w=t.w+e.w,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this.w+=t.w*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this.w-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this.w=t.w-e.w,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this.w*=t.w,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this}applyMatrix4(t){const e=this.x,i=this.y,n=this.z,s=this.w,r=t.elements;return this.x=r[0]*e+r[4]*i+r[8]*n+r[12]*s,this.y=r[1]*e+r[5]*i+r[9]*n+r[13]*s,this.z=r[2]*e+r[6]*i+r[10]*n+r[14]*s,this.w=r[3]*e+r[7]*i+r[11]*n+r[15]*s,this}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this.w/=t.w,this}divideScalar(t){return this.multiplyScalar(1/t)}setAxisAngleFromQuaternion(t){this.w=2*Math.acos(t.w);const e=Math.sqrt(1-t.w*t.w);return e<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=t.x/e,this.y=t.y/e,this.z=t.z/e),this}setAxisAngleFromRotationMatrix(t){let e,i,n,s;const c=t.elements,l=c[0],h=c[4],u=c[8],d=c[1],f=c[5],p=c[9],v=c[2],m=c[6],g=c[10];if(Math.abs(h-d)<.01&&Math.abs(u-v)<.01&&Math.abs(p-m)<.01){if(Math.abs(h+d)<.1&&Math.abs(u+v)<.1&&Math.abs(p+m)<.1&&Math.abs(l+f+g-3)<.1)return this.set(1,0,0,0),this;e=Math.PI;const x=(l+1)/2,M=(f+1)/2,b=(g+1)/2,w=(h+d)/4,T=(u+v)/4,y=(p+m)/4;return x>M&&x>b?x<.01?(i=0,n=.707106781,s=.707106781):(i=Math.sqrt(x),n=w/i,s=T/i):M>b?M<.01?(i=.707106781,n=0,s=.707106781):(n=Math.sqrt(M),i=w/n,s=y/n):b<.01?(i=.707106781,n=.707106781,s=0):(s=Math.sqrt(b),i=T/s,n=y/s),this.set(i,n,s,e),this}let S=Math.sqrt((m-p)*(m-p)+(u-v)*(u-v)+(d-h)*(d-h));return Math.abs(S)<.001&&(S=1),this.x=(m-p)/S,this.y=(u-v)/S,this.z=(d-h)/S,this.w=Math.acos((l+f+g-1)/2),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this.w=e[15],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this.w=Math.min(this.w,t.w),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this.w=Math.max(this.w,t.w),this}clamp(t,e){return this.x=Zt(this.x,t.x,e.x),this.y=Zt(this.y,t.y,e.y),this.z=Zt(this.z,t.z,e.z),this.w=Zt(this.w,t.w,e.w),this}clampScalar(t,e){return this.x=Zt(this.x,t,e),this.y=Zt(this.y,t,e),this.z=Zt(this.z,t,e),this.w=Zt(this.w,t,e),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Zt(i,t,e))}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(t){return this.x*t.x+this.y*t.y+this.z*t.z+this.w*t.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(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this.w+=(t.w-this.w)*e,this}lerpVectors(t,e,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this.z=t.z+(e.z-t.z)*i,this.w=t.w+(e.w-t.w)*i,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z&&t.w===this.w}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this.w=t[e+3],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t[e+3]=this.w,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this.w=t.getW(e),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 qM extends vr{constructor(t=1,e=1,i={}){super(),i=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:le,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=t,this.height=e,this.depth=i.depth,this.scissor=new ae(0,0,t,e),this.scissorTest=!1,this.viewport=new ae(0,0,t,e),this.textures=[];const n={width:t,height:e,depth:i.depth},s=new Ei(n),r=i.count;for(let o=0;o<r;o++)this.textures[o]=s.clone(),this.textures[o].isRenderTargetTexture=!0,this.textures[o].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(t={}){const e={minFilter:le,generateMipmaps:!1,flipY:!1,internalFormat:null};t.mapping!==void 0&&(e.mapping=t.mapping),t.wrapS!==void 0&&(e.wrapS=t.wrapS),t.wrapT!==void 0&&(e.wrapT=t.wrapT),t.wrapR!==void 0&&(e.wrapR=t.wrapR),t.magFilter!==void 0&&(e.magFilter=t.magFilter),t.minFilter!==void 0&&(e.minFilter=t.minFilter),t.format!==void 0&&(e.format=t.format),t.type!==void 0&&(e.type=t.type),t.anisotropy!==void 0&&(e.anisotropy=t.anisotropy),t.colorSpace!==void 0&&(e.colorSpace=t.colorSpace),t.flipY!==void 0&&(e.flipY=t.flipY),t.generateMipmaps!==void 0&&(e.generateMipmaps=t.generateMipmaps),t.internalFormat!==void 0&&(e.internalFormat=t.internalFormat);for(let i=0;i<this.textures.length;i++)this.textures[i].setValues(e)}get texture(){return this.textures[0]}set texture(t){this.textures[0]=t}set depthTexture(t){this._depthTexture!==null&&(this._depthTexture.renderTarget=null),t!==null&&(t.renderTarget=this),this._depthTexture=t}get depthTexture(){return this._depthTexture}setSize(t,e,i=1){if(this.width!==t||this.height!==e||this.depth!==i){this.width=t,this.height=e,this.depth=i;for(let n=0,s=this.textures.length;n<s;n++)this.textures[n].image.width=t,this.textures[n].image.height=e,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,t,e),this.scissor.set(0,0,t,e)}clone(){return new this.constructor().copy(this)}copy(t){this.width=t.width,this.height=t.height,this.depth=t.depth,this.scissor.copy(t.scissor),this.scissorTest=t.scissorTest,this.viewport.copy(t.viewport),this.textures.length=0;for(let e=0,i=t.textures.length;e<i;e++){this.textures[e]=t.textures[e].clone(),this.textures[e].isRenderTargetTexture=!0,this.textures[e].renderTarget=this;const n=Object.assign({},t.textures[e].image);this.textures[e].source=new k0(n)}return this.depthBuffer=t.depthBuffer,this.stencilBuffer=t.stencilBuffer,this.resolveDepthBuffer=t.resolveDepthBuffer,this.resolveStencilBuffer=t.resolveStencilBuffer,t.depthTexture!==null&&(this.depthTexture=t.depthTexture.clone()),this.samples=t.samples,this.multiview=t.multiview,this.useArrayDepthTexture=t.useArrayDepthTexture,this}dispose(){this.dispatchEvent({type:"dispose"})}}class Qe extends qM{constructor(t=1,e=1,i={}){super(t,e,i),this.isWebGLRenderTarget=!0}}class p1 extends Ei{constructor(t=null,e=1,i=1,n=1){super(null),this.isDataArrayTexture=!0,this.image={data:t,width:e,height:i,depth:n},this.magFilter=Ce,this.minFilter=Ce,this.wrapR=Ri,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1,this.layerUpdates=new Set}addLayerUpdate(t){this.layerUpdates.add(t)}clearLayerUpdates(){this.layerUpdates.clear()}}class m1 extends Ei{constructor(t=null,e=1,i=1,n=1){super(null),this.isData3DTexture=!0,this.image={data:t,width:e,height:i,depth:n},this.magFilter=Ce,this.minFilter=Ce,this.wrapR=Ri,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}class te{static{te.prototype.isMatrix4=!0}constructor(t,e,i,n,s,r,o,c,l,h,u,d,f,p,v,m){this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],t!==void 0&&this.set(t,e,i,n,s,r,o,c,l,h,u,d,f,p,v,m)}set(t,e,i,n,s,r,o,c,l,h,u,d,f,p,v,m){const g=this.elements;return g[0]=t,g[4]=e,g[8]=i,g[12]=n,g[1]=s,g[5]=r,g[9]=o,g[13]=c,g[2]=l,g[6]=h,g[10]=u,g[14]=d,g[3]=f,g[7]=p,g[11]=v,g[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 te().fromArray(this.elements)}copy(t){const e=this.elements,i=t.elements;return e[0]=i[0],e[1]=i[1],e[2]=i[2],e[3]=i[3],e[4]=i[4],e[5]=i[5],e[6]=i[6],e[7]=i[7],e[8]=i[8],e[9]=i[9],e[10]=i[10],e[11]=i[11],e[12]=i[12],e[13]=i[13],e[14]=i[14],e[15]=i[15],this}copyPosition(t){const e=this.elements,i=t.elements;return e[12]=i[12],e[13]=i[13],e[14]=i[14],this}setFromMatrix3(t){const e=t.elements;return this.set(e[0],e[3],e[6],0,e[1],e[4],e[7],0,e[2],e[5],e[8],0,0,0,0,1),this}extractBasis(t,e,i){return this.determinantAffine()===0?(t.set(1,0,0),e.set(0,1,0),i.set(0,0,1),this):(t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),i.setFromMatrixColumn(this,2),this)}makeBasis(t,e,i){return this.set(t.x,e.x,i.x,0,t.y,e.y,i.y,0,t.z,e.z,i.z,0,0,0,0,1),this}extractRotation(t){if(t.determinantAffine()===0)return this.identity();const e=this.elements,i=t.elements,n=1/ia.setFromMatrixColumn(t,0).length(),s=1/ia.setFromMatrixColumn(t,1).length(),r=1/ia.setFromMatrixColumn(t,2).length();return e[0]=i[0]*n,e[1]=i[1]*n,e[2]=i[2]*n,e[3]=0,e[4]=i[4]*s,e[5]=i[5]*s,e[6]=i[6]*s,e[7]=0,e[8]=i[8]*r,e[9]=i[9]*r,e[10]=i[10]*r,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){const e=this.elements,i=t.x,n=t.y,s=t.z,r=Math.cos(i),o=Math.sin(i),c=Math.cos(n),l=Math.sin(n),h=Math.cos(s),u=Math.sin(s);if(t.order==="XYZ"){const d=r*h,f=r*u,p=o*h,v=o*u;e[0]=c*h,e[4]=-c*u,e[8]=l,e[1]=f+p*l,e[5]=d-v*l,e[9]=-o*c,e[2]=v-d*l,e[6]=p+f*l,e[10]=r*c}else if(t.order==="YXZ"){const d=c*h,f=c*u,p=l*h,v=l*u;e[0]=d+v*o,e[4]=p*o-f,e[8]=r*l,e[1]=r*u,e[5]=r*h,e[9]=-o,e[2]=f*o-p,e[6]=v+d*o,e[10]=r*c}else if(t.order==="ZXY"){const d=c*h,f=c*u,p=l*h,v=l*u;e[0]=d-v*o,e[4]=-r*u,e[8]=p+f*o,e[1]=f+p*o,e[5]=r*h,e[9]=v-d*o,e[2]=-r*l,e[6]=o,e[10]=r*c}else if(t.order==="ZYX"){const d=r*h,f=r*u,p=o*h,v=o*u;e[0]=c*h,e[4]=p*l-f,e[8]=d*l+v,e[1]=c*u,e[5]=v*l+d,e[9]=f*l-p,e[2]=-l,e[6]=o*c,e[10]=r*c}else if(t.order==="YZX"){const d=r*c,f=r*l,p=o*c,v=o*l;e[0]=c*h,e[4]=v-d*u,e[8]=p*u+f,e[1]=u,e[5]=r*h,e[9]=-o*h,e[2]=-l*h,e[6]=f*u+p,e[10]=d-v*u}else if(t.order==="XZY"){const d=r*c,f=r*l,p=o*c,v=o*l;e[0]=c*h,e[4]=-u,e[8]=l*h,e[1]=d*u+v,e[5]=r*h,e[9]=f*u-p,e[2]=p*u-f,e[6]=o*h,e[10]=v*u+d}return e[3]=0,e[7]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromQuaternion(t){return this.compose($M,t,KM)}lookAt(t,e,i){const n=this.elements;return ln.subVectors(t,e),ln.lengthSq()===0&&(ln.z=1),ln.normalize(),Ws.crossVectors(i,ln),Ws.lengthSq()===0&&(Math.abs(i.z)===1?ln.x+=1e-4:ln.z+=1e-4,ln.normalize(),Ws.crossVectors(i,ln)),Ws.normalize(),Tc.crossVectors(ln,Ws),n[0]=Ws.x,n[4]=Tc.x,n[8]=ln.x,n[1]=Ws.y,n[5]=Tc.y,n[9]=ln.y,n[2]=Ws.z,n[6]=Tc.z,n[10]=ln.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const i=t.elements,n=e.elements,s=this.elements,r=i[0],o=i[4],c=i[8],l=i[12],h=i[1],u=i[5],d=i[9],f=i[13],p=i[2],v=i[6],m=i[10],g=i[14],S=i[3],x=i[7],M=i[11],b=i[15],w=n[0],T=n[4],y=n[8],A=n[12],C=n[1],I=n[5],P=n[9],V=n[13],X=n[2],L=n[6],B=n[10],k=n[14],$=n[3],tt=n[7],J=n[11],it=n[15];return s[0]=r*w+o*C+c*X+l*$,s[4]=r*T+o*I+c*L+l*tt,s[8]=r*y+o*P+c*B+l*J,s[12]=r*A+o*V+c*k+l*it,s[1]=h*w+u*C+d*X+f*$,s[5]=h*T+u*I+d*L+f*tt,s[9]=h*y+u*P+d*B+f*J,s[13]=h*A+u*V+d*k+f*it,s[2]=p*w+v*C+m*X+g*$,s[6]=p*T+v*I+m*L+g*tt,s[10]=p*y+v*P+m*B+g*J,s[14]=p*A+v*V+m*k+g*it,s[3]=S*w+x*C+M*X+b*$,s[7]=S*T+x*I+M*L+b*tt,s[11]=S*y+x*P+M*B+b*J,s[15]=S*A+x*V+M*k+b*it,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[4]*=t,e[8]*=t,e[12]*=t,e[1]*=t,e[5]*=t,e[9]*=t,e[13]*=t,e[2]*=t,e[6]*=t,e[10]*=t,e[14]*=t,e[3]*=t,e[7]*=t,e[11]*=t,e[15]*=t,this}determinant(){const t=this.elements,e=t[0],i=t[4],n=t[8],s=t[12],r=t[1],o=t[5],c=t[9],l=t[13],h=t[2],u=t[6],d=t[10],f=t[14],p=t[3],v=t[7],m=t[11],g=t[15],S=c*f-l*d,x=o*f-l*u,M=o*d-c*u,b=r*f-l*h,w=r*d-c*h,T=r*u-o*h;return e*(v*S-m*x+g*M)-i*(p*S-m*b+g*w)+n*(p*x-v*b+g*T)-s*(p*M-v*w+m*T)}determinantAffine(){const t=this.elements,e=t[0],i=t[4],n=t[8],s=t[1],r=t[5],o=t[9],c=t[2],l=t[6],h=t[10];return e*(r*h-o*l)-i*(s*h-o*c)+n*(s*l-r*c)}transpose(){const t=this.elements;let e;return e=t[1],t[1]=t[4],t[4]=e,e=t[2],t[2]=t[8],t[8]=e,e=t[6],t[6]=t[9],t[9]=e,e=t[3],t[3]=t[12],t[12]=e,e=t[7],t[7]=t[13],t[13]=e,e=t[11],t[11]=t[14],t[14]=e,this}setPosition(t,e,i){const n=this.elements;return t.isVector3?(n[12]=t.x,n[13]=t.y,n[14]=t.z):(n[12]=t,n[13]=e,n[14]=i),this}invert(){const t=this.elements,e=t[0],i=t[1],n=t[2],s=t[3],r=t[4],o=t[5],c=t[6],l=t[7],h=t[8],u=t[9],d=t[10],f=t[11],p=t[12],v=t[13],m=t[14],g=t[15],S=e*o-i*r,x=e*c-n*r,M=e*l-s*r,b=i*c-n*o,w=i*l-s*o,T=n*l-s*c,y=h*v-u*p,A=h*m-d*p,C=h*g-f*p,I=u*m-d*v,P=u*g-f*v,V=d*g-f*m,X=S*V-x*P+M*I+b*C-w*A+T*y;if(X===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const L=1/X;return t[0]=(o*V-c*P+l*I)*L,t[1]=(n*P-i*V-s*I)*L,t[2]=(v*T-m*w+g*b)*L,t[3]=(d*w-u*T-f*b)*L,t[4]=(c*C-r*V-l*A)*L,t[5]=(e*V-n*C+s*A)*L,t[6]=(m*M-p*T-g*x)*L,t[7]=(h*T-d*M+f*x)*L,t[8]=(r*P-o*C+l*y)*L,t[9]=(i*C-e*P-s*y)*L,t[10]=(p*w-v*M+g*S)*L,t[11]=(u*M-h*w-f*S)*L,t[12]=(o*A-r*I-c*y)*L,t[13]=(e*I-i*A+n*y)*L,t[14]=(v*x-p*b-m*S)*L,t[15]=(h*b-u*x+d*S)*L,this}scale(t){const e=this.elements,i=t.x,n=t.y,s=t.z;return e[0]*=i,e[4]*=n,e[8]*=s,e[1]*=i,e[5]*=n,e[9]*=s,e[2]*=i,e[6]*=n,e[10]*=s,e[3]*=i,e[7]*=n,e[11]*=s,this}getMaxScaleOnAxis(){const t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],i=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],n=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,i,n))}makeTranslation(t,e,i){return t.isVector3?this.set(1,0,0,t.x,0,1,0,t.y,0,0,1,t.z,0,0,0,1):this.set(1,0,0,t,0,1,0,e,0,0,1,i,0,0,0,1),this}makeRotationX(t){const e=Math.cos(t),i=Math.sin(t);return this.set(1,0,0,0,0,e,-i,0,0,i,e,0,0,0,0,1),this}makeRotationY(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,0,i,0,0,1,0,0,-i,0,e,0,0,0,0,1),this}makeRotationZ(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,-i,0,0,i,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){const i=Math.cos(e),n=Math.sin(e),s=1-i,r=t.x,o=t.y,c=t.z,l=s*r,h=s*o;return this.set(l*r+i,l*o-n*c,l*c+n*o,0,l*o+n*c,h*o+i,h*c-n*r,0,l*c-n*o,h*c+n*r,s*c*c+i,0,0,0,0,1),this}makeScale(t,e,i){return this.set(t,0,0,0,0,e,0,0,0,0,i,0,0,0,0,1),this}makeShear(t,e,i,n,s,r){return this.set(1,i,s,0,t,1,r,0,e,n,1,0,0,0,0,1),this}compose(t,e,i){const n=this.elements,s=e._x,r=e._y,o=e._z,c=e._w,l=s+s,h=r+r,u=o+o,d=s*l,f=s*h,p=s*u,v=r*h,m=r*u,g=o*u,S=c*l,x=c*h,M=c*u,b=i.x,w=i.y,T=i.z;return n[0]=(1-(v+g))*b,n[1]=(f+M)*b,n[2]=(p-x)*b,n[3]=0,n[4]=(f-M)*w,n[5]=(1-(d+g))*w,n[6]=(m+S)*w,n[7]=0,n[8]=(p+x)*T,n[9]=(m-S)*T,n[10]=(1-(d+v))*T,n[11]=0,n[12]=t.x,n[13]=t.y,n[14]=t.z,n[15]=1,this}decompose(t,e,i){const n=this.elements;t.x=n[12],t.y=n[13],t.z=n[14];const s=this.determinantAffine();if(s===0)return i.set(1,1,1),e.identity(),this;let r=ia.set(n[0],n[1],n[2]).length();const o=ia.set(n[4],n[5],n[6]).length(),c=ia.set(n[8],n[9],n[10]).length();s<0&&(r=-r),Un.copy(this);const l=1/r,h=1/o,u=1/c;return Un.elements[0]*=l,Un.elements[1]*=l,Un.elements[2]*=l,Un.elements[4]*=h,Un.elements[5]*=h,Un.elements[6]*=h,Un.elements[8]*=u,Un.elements[9]*=u,Un.elements[10]*=u,e.setFromRotationMatrix(Un),i.x=r,i.y=o,i.z=c,this}makePerspective(t,e,i,n,s,r,o=ms,c=!1){const l=this.elements,h=2*s/(e-t),u=2*s/(i-n),d=(e+t)/(e-t),f=(i+n)/(i-n);let p,v;if(c)p=s/(r-s),v=r*s/(r-s);else if(o===ms)p=-(r+s)/(r-s),v=-2*r*s/(r-s);else if(o===oc)p=-r/(r-s),v=-r*s/(r-s);else throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+o);return l[0]=h,l[4]=0,l[8]=d,l[12]=0,l[1]=0,l[5]=u,l[9]=f,l[13]=0,l[2]=0,l[6]=0,l[10]=p,l[14]=v,l[3]=0,l[7]=0,l[11]=-1,l[15]=0,this}makeOrthographic(t,e,i,n,s,r,o=ms,c=!1){const l=this.elements,h=2/(e-t),u=2/(i-n),d=-(e+t)/(e-t),f=-(i+n)/(i-n);let p,v;if(c)p=1/(r-s),v=r/(r-s);else if(o===ms)p=-2/(r-s),v=-(r+s)/(r-s);else if(o===oc)p=-1/(r-s),v=-s/(r-s);else throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+o);return l[0]=h,l[4]=0,l[8]=0,l[12]=d,l[1]=0,l[5]=u,l[9]=0,l[13]=f,l[2]=0,l[6]=0,l[10]=p,l[14]=v,l[3]=0,l[7]=0,l[11]=0,l[15]=1,this}equals(t){const e=this.elements,i=t.elements;for(let n=0;n<16;n++)if(e[n]!==i[n])return!1;return!0}fromArray(t,e=0){for(let i=0;i<16;i++)this.elements[i]=t[i+e];return this}toArray(t=[],e=0){const i=this.elements;return t[e]=i[0],t[e+1]=i[1],t[e+2]=i[2],t[e+3]=i[3],t[e+4]=i[4],t[e+5]=i[5],t[e+6]=i[6],t[e+7]=i[7],t[e+8]=i[8],t[e+9]=i[9],t[e+10]=i[10],t[e+11]=i[11],t[e+12]=i[12],t[e+13]=i[13],t[e+14]=i[14],t[e+15]=i[15],t}}const ia=new R,Un=new te,$M=new R(0,0,0),KM=new R(1,1,1),Ws=new R,Tc=new R,ln=new R,cp=new te,lp=new on;class Us{constructor(t=0,e=0,i=0,n=Us.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=e,this._z=i,this._order=n}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get order(){return this._order}set order(t){this._order=t,this._onChangeCallback()}set(t,e,i,n=this._order){return this._x=t,this._y=e,this._z=i,this._order=n,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(t){return this._x=t._x,this._y=t._y,this._z=t._z,this._order=t._order,this._onChangeCallback(),this}setFromRotationMatrix(t,e=this._order,i=!0){const n=t.elements,s=n[0],r=n[4],o=n[8],c=n[1],l=n[5],h=n[9],u=n[2],d=n[6],f=n[10];switch(e){case"XYZ":this._y=Math.asin(Zt(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-h,f),this._z=Math.atan2(-r,s)):(this._x=Math.atan2(d,l),this._z=0);break;case"YXZ":this._x=Math.asin(-Zt(h,-1,1)),Math.abs(h)<.9999999?(this._y=Math.atan2(o,f),this._z=Math.atan2(c,l)):(this._y=Math.atan2(-u,s),this._z=0);break;case"ZXY":this._x=Math.asin(Zt(d,-1,1)),Math.abs(d)<.9999999?(this._y=Math.atan2(-u,f),this._z=Math.atan2(-r,l)):(this._y=0,this._z=Math.atan2(c,s));break;case"ZYX":this._y=Math.asin(-Zt(u,-1,1)),Math.abs(u)<.9999999?(this._x=Math.atan2(d,f),this._z=Math.atan2(c,s)):(this._x=0,this._z=Math.atan2(-r,l));break;case"YZX":this._z=Math.asin(Zt(c,-1,1)),Math.abs(c)<.9999999?(this._x=Math.atan2(-h,l),this._y=Math.atan2(-u,s)):(this._x=0,this._y=Math.atan2(o,f));break;case"XZY":this._z=Math.asin(-Zt(r,-1,1)),Math.abs(r)<.9999999?(this._x=Math.atan2(d,l),this._y=Math.atan2(o,s)):(this._x=Math.atan2(-h,f),this._y=0);break;default:It("Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,i===!0&&this._onChangeCallback(),this}setFromQuaternion(t,e,i){return cp.makeRotationFromQuaternion(t),this.setFromRotationMatrix(cp,e,i)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return lp.setFromEuler(this),this.setFromQuaternion(lp,t)}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._order===this._order}fromArray(t){return this._x=t[0],this._y=t[1],this._z=t[2],t[3]!==void 0&&(this._order=t[3]),this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._order,t}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}Us.DEFAULT_ORDER="XYZ";class z0{constructor(){this.mask=1}set(t){this.mask=(1<<t|0)>>>0}enable(t){this.mask|=1<<t|0}enableAll(){this.mask=-1}toggle(t){this.mask^=1<<t|0}disable(t){this.mask&=~(1<<t|0)}disableAll(){this.mask=0}test(t){return(this.mask&t.mask)!==0}isEnabled(t){return(this.mask&(1<<t|0))!==0}}let ZM=0;const hp=new R,na=new on,Ss=new te,Rc=new R,co=new R,JM=new R,jM=new on,up=new R(1,0,0),dp=new R(0,1,0),fp=new R(0,0,1),pp={type:"added"},QM={type:"removed"},sa={type:"childadded",child:null},Uh={type:"childremoved",child:null};class Ge extends vr{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:ZM++}),this.uuid=Kn(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=Ge.DEFAULT_UP.clone();const t=new R,e=new Us,i=new on,n=new R(1,1,1);function s(){i.setFromEuler(e,!1)}function r(){e.setFromQuaternion(i,void 0,!1)}e._onChange(s),i._onChange(r),Object.defineProperties(this,{position:{configurable:!0,enumerable:!0,value:t},rotation:{configurable:!0,enumerable:!0,value:e},quaternion:{configurable:!0,enumerable:!0,value:i},scale:{configurable:!0,enumerable:!0,value:n},modelViewMatrix:{value:new te},normalMatrix:{value:new $t}}),this.matrix=new te,this.matrixWorld=new te,this.matrixAutoUpdate=Ge.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=Ge.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new z0,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(t){this.matrixAutoUpdate&&this.updateMatrix(),this.matrix.premultiply(t),this.matrix.decompose(this.position,this.quaternion,this.scale)}applyQuaternion(t){return this.quaternion.premultiply(t),this}setRotationFromAxisAngle(t,e){this.quaternion.setFromAxisAngle(t,e)}setRotationFromEuler(t){this.quaternion.setFromEuler(t,!0)}setRotationFromMatrix(t){this.quaternion.setFromRotationMatrix(t)}setRotationFromQuaternion(t){this.quaternion.copy(t)}rotateOnAxis(t,e){return na.setFromAxisAngle(t,e),this.quaternion.multiply(na),this}rotateOnWorldAxis(t,e){return na.setFromAxisAngle(t,e),this.quaternion.premultiply(na),this}rotateX(t){return this.rotateOnAxis(up,t)}rotateY(t){return this.rotateOnAxis(dp,t)}rotateZ(t){return this.rotateOnAxis(fp,t)}translateOnAxis(t,e){return hp.copy(t).applyQuaternion(this.quaternion),this.position.add(hp.multiplyScalar(e)),this}translateX(t){return this.translateOnAxis(up,t)}translateY(t){return this.translateOnAxis(dp,t)}translateZ(t){return this.translateOnAxis(fp,t)}localToWorld(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(this.matrixWorld)}worldToLocal(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(Ss.copy(this.matrixWorld).invert())}lookAt(t,e,i){t.isVector3?Rc.copy(t):Rc.set(t,e,i);const n=this.parent;this.updateWorldMatrix(!0,!1),co.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?Ss.lookAt(co,Rc,this.up):Ss.lookAt(Rc,co,this.up),this.quaternion.setFromRotationMatrix(Ss),n&&(Ss.extractRotation(n.matrixWorld),na.setFromRotationMatrix(Ss),this.quaternion.premultiply(na.invert()))}add(t){if(arguments.length>1){for(let e=0;e<arguments.length;e++)this.add(arguments[e]);return this}return t===this?(Wt("Object3D.add: object can't be added as a child of itself.",t),this):(t&&t.isObject3D?(t.removeFromParent(),t.parent=this,this.children.push(t),t.dispatchEvent(pp),sa.child=t,this.dispatchEvent(sa),sa.child=null):Wt("Object3D.add: object not an instance of THREE.Object3D.",t),this)}remove(t){if(arguments.length>1){for(let i=0;i<arguments.length;i++)this.remove(arguments[i]);return this}const e=this.children.indexOf(t);return e!==-1&&(t.parent=null,this.children.splice(e,1),t.dispatchEvent(QM),Uh.child=t,this.dispatchEvent(Uh),Uh.child=null),this}removeFromParent(){const t=this.parent;return t!==null&&t.remove(this),this}clear(){return this.remove(...this.children)}attach(t){return this.updateWorldMatrix(!0,!1),Ss.copy(this.matrixWorld).invert(),t.parent!==null&&(t.parent.updateWorldMatrix(!0,!1),Ss.multiply(t.parent.matrixWorld)),t.applyMatrix4(Ss),t.removeFromParent(),t.parent=this,this.children.push(t),t.updateWorldMatrix(!1,!0),t.dispatchEvent(pp),sa.child=t,this.dispatchEvent(sa),sa.child=null,this}getObjectById(t){return this.getObjectByProperty("id",t)}getObjectByName(t){return this.getObjectByProperty("name",t)}getObjectByProperty(t,e){if(this[t]===e)return this;for(let i=0,n=this.children.length;i<n;i++){const r=this.children[i].getObjectByProperty(t,e);if(r!==void 0)return r}}getObjectsByProperty(t,e,i=[]){this[t]===e&&i.push(this);const n=this.children;for(let s=0,r=n.length;s<r;s++)n[s].getObjectsByProperty(t,e,i);return i}getWorldPosition(t){return this.updateWorldMatrix(!0,!1),t.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(co,t,JM),t}getWorldScale(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(co,jM,t),t}getWorldDirection(t){this.updateWorldMatrix(!0,!1);const e=this.matrixWorld.elements;return t.set(e[8],e[9],e[10]).normalize()}raycast(){}traverse(t){t(this);const e=this.children;for(let i=0,n=e.length;i<n;i++)e[i].traverse(t)}traverseVisible(t){if(this.visible===!1)return;t(this);const e=this.children;for(let i=0,n=e.length;i<n;i++)e[i].traverseVisible(t)}traverseAncestors(t){const e=this.parent;e!==null&&(t(e),e.traverseAncestors(t))}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale);const t=this.pivot;if(t!==null){const e=t.x,i=t.y,n=t.z,s=this.matrix.elements;s[12]+=e-s[0]*e-s[4]*i-s[8]*n,s[13]+=i-s[1]*e-s[5]*i-s[9]*n,s[14]+=n-s[2]*e-s[6]*i-s[10]*n}this.matrixWorldNeedsUpdate=!0}updateMatrixWorld(t){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||t)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,t=!0);const e=this.children;for(let i=0,n=e.length;i<n;i++)e[i].updateMatrixWorld(t)}updateWorldMatrix(t,e,i=!1){const n=this.parent;if(t===!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),e===!0){const s=this.children;for(let r=0,o=s.length;r<o;r++)s[r].updateWorldMatrix(!1,!0,i)}}toJSON(t){const e=t===void 0||typeof t=="string",i={};e&&(t={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(o=>({...o,boundingBox:o.boundingBox?o.boundingBox.toJSON():void 0,boundingSphere:o.boundingSphere?o.boundingSphere.toJSON():void 0})),n.instanceInfo=this._instanceInfo.map(o=>({...o})),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(t),n.indirectTexture=this._indirectTexture.toJSON(t),this._colorsTexture!==null&&(n.colorsTexture=this._colorsTexture.toJSON(t)),this.boundingSphere!==null&&(n.boundingSphere=this.boundingSphere.toJSON()),this.boundingBox!==null&&(n.boundingBox=this.boundingBox.toJSON()));function s(o,c){return o[c.uuid]===void 0&&(o[c.uuid]=c.toJSON(t)),c.uuid}if(this.isScene)this.background&&(this.background.isColor?n.background=this.background.toJSON():this.background.isTexture&&(n.background=this.background.toJSON(t).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(n.environment=this.environment.toJSON(t).uuid);else if(this.isMesh||this.isLine||this.isPoints){n.geometry=s(t.geometries,this.geometry);const o=this.geometry.parameters;if(o!==void 0&&o.shapes!==void 0){const c=o.shapes;if(Array.isArray(c))for(let l=0,h=c.length;l<h;l++){const u=c[l];s(t.shapes,u)}else s(t.shapes,c)}}if(this.isSkinnedMesh&&(n.bindMode=this.bindMode,n.bindMatrix=this.bindMatrix.toArray(),this.skeleton!==void 0&&(s(t.skeletons,this.skeleton),n.skeleton=this.skeleton.uuid)),this.material!==void 0)if(Array.isArray(this.material)){const o=[];for(let c=0,l=this.material.length;c<l;c++)o.push(s(t.materials,this.material[c]));n.material=o}else n.material=s(t.materials,this.material);if(this.children.length>0){n.children=[];for(let o=0;o<this.children.length;o++)n.children.push(this.children[o].toJSON(t).object)}if(this.animations.length>0){n.animations=[];for(let o=0;o<this.animations.length;o++){const c=this.animations[o];n.animations.push(s(t.animations,c))}}if(e){const o=r(t.geometries),c=r(t.materials),l=r(t.textures),h=r(t.images),u=r(t.shapes),d=r(t.skeletons),f=r(t.animations),p=r(t.nodes);o.length>0&&(i.geometries=o),c.length>0&&(i.materials=c),l.length>0&&(i.textures=l),h.length>0&&(i.images=h),u.length>0&&(i.shapes=u),d.length>0&&(i.skeletons=d),f.length>0&&(i.animations=f),p.length>0&&(i.nodes=p)}return i.object=n,i;function r(o){const c=[];for(const l in o){const h=o[l];delete h.metadata,c.push(h)}return c}}clone(t){return new this.constructor().copy(this,t)}copy(t,e=!0){if(this.name=t.name,this.up.copy(t.up),this.position.copy(t.position),this.rotation.order=t.rotation.order,this.quaternion.copy(t.quaternion),this.scale.copy(t.scale),this.pivot=t.pivot!==null?t.pivot.clone():null,this.matrix.copy(t.matrix),this.matrixWorld.copy(t.matrixWorld),this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrixWorldAutoUpdate=t.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=t.matrixWorldNeedsUpdate,this.layers.mask=t.layers.mask,this.visible=t.visible,this.castShadow=t.castShadow,this.receiveShadow=t.receiveShadow,this.frustumCulled=t.frustumCulled,this.renderOrder=t.renderOrder,this.static=t.static,this.animations=t.animations.slice(),this.userData=JSON.parse(JSON.stringify(t.userData)),e===!0)for(let i=0;i<t.children.length;i++){const n=t.children[i];this.add(n.clone())}return this}}Ge.DEFAULT_UP=new R(0,1,0);Ge.DEFAULT_MATRIX_AUTO_UPDATE=!0;Ge.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;class Re extends Ge{constructor(){super(),this.isGroup=!0,this.type="Group"}}const tx={type:"move"};class kh{constructor(){this._targetRay=null,this._grip=null,this._hand=null}getHandSpace(){return this._hand===null&&(this._hand=new Re,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 Re,this._targetRay.matrixAutoUpdate=!1,this._targetRay.visible=!1,this._targetRay.hasLinearVelocity=!1,this._targetRay.linearVelocity=new R,this._targetRay.hasAngularVelocity=!1,this._targetRay.angularVelocity=new R),this._targetRay}getGripSpace(){return this._grip===null&&(this._grip=new Re,this._grip.matrixAutoUpdate=!1,this._grip.visible=!1,this._grip.hasLinearVelocity=!1,this._grip.linearVelocity=new R,this._grip.hasAngularVelocity=!1,this._grip.angularVelocity=new R,this._grip.eventsEnabled=!1),this._grip}dispatchEvent(t){return this._targetRay!==null&&this._targetRay.dispatchEvent(t),this._grip!==null&&this._grip.dispatchEvent(t),this._hand!==null&&this._hand.dispatchEvent(t),this}connect(t){if(t&&t.hand){const e=this._hand;if(e)for(const i of t.hand.values())this._getHandJoint(e,i)}return this.dispatchEvent({type:"connected",data:t}),this}disconnect(t){return this.dispatchEvent({type:"disconnected",data:t}),this._targetRay!==null&&(this._targetRay.visible=!1),this._grip!==null&&(this._grip.visible=!1),this._hand!==null&&(this._hand.visible=!1),this}update(t,e,i){let n=null,s=null,r=null;const o=this._targetRay,c=this._grip,l=this._hand;if(t&&e.session.visibilityState!=="visible-blurred"){if(l&&t.hand){r=!0;for(const v of t.hand.values()){const m=e.getJointPose(v,i),g=this._getHandJoint(l,v);m!==null&&(g.matrix.fromArray(m.transform.matrix),g.matrix.decompose(g.position,g.rotation,g.scale),g.matrixWorldNeedsUpdate=!0,g.jointRadius=m.radius),g.visible=m!==null}const h=l.joints["index-finger-tip"],u=l.joints["thumb-tip"],d=h.position.distanceTo(u.position),f=.02,p=.005;l.inputState.pinching&&d>f+p?(l.inputState.pinching=!1,this.dispatchEvent({type:"pinchend",handedness:t.handedness,target:this})):!l.inputState.pinching&&d<=f-p&&(l.inputState.pinching=!0,this.dispatchEvent({type:"pinchstart",handedness:t.handedness,target:this}))}else c!==null&&t.gripSpace&&(s=e.getPose(t.gripSpace,i),s!==null&&(c.matrix.fromArray(s.transform.matrix),c.matrix.decompose(c.position,c.rotation,c.scale),c.matrixWorldNeedsUpdate=!0,s.linearVelocity?(c.hasLinearVelocity=!0,c.linearVelocity.copy(s.linearVelocity)):c.hasLinearVelocity=!1,s.angularVelocity?(c.hasAngularVelocity=!0,c.angularVelocity.copy(s.angularVelocity)):c.hasAngularVelocity=!1,c.eventsEnabled&&c.dispatchEvent({type:"gripUpdated",data:t,target:this})));o!==null&&(n=e.getPose(t.targetRaySpace,i),n===null&&s!==null&&(n=s),n!==null&&(o.matrix.fromArray(n.transform.matrix),o.matrix.decompose(o.position,o.rotation,o.scale),o.matrixWorldNeedsUpdate=!0,n.linearVelocity?(o.hasLinearVelocity=!0,o.linearVelocity.copy(n.linearVelocity)):o.hasLinearVelocity=!1,n.angularVelocity?(o.hasAngularVelocity=!0,o.angularVelocity.copy(n.angularVelocity)):o.hasAngularVelocity=!1,this.dispatchEvent(tx)))}return o!==null&&(o.visible=n!==null),c!==null&&(c.visible=s!==null),l!==null&&(l.visible=r!==null),this}_getHandJoint(t,e){if(t.joints[e.jointName]===void 0){const i=new Re;i.matrixAutoUpdate=!1,i.visible=!1,t.joints[e.jointName]=i,t.add(i)}return t.joints[e.jointName]}}const g1={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},Xs={h:0,s:0,l:0},Dc={h:0,s:0,l:0};function zh(a,t,e){return e<0&&(e+=1),e>1&&(e-=1),e<1/6?a+(t-a)*6*e:e<1/2?t:e<2/3?a+(t-a)*6*(2/3-e):a}class st{constructor(t,e,i){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(t,e,i)}set(t,e,i){if(e===void 0&&i===void 0){const n=t;n&&n.isColor?this.copy(n):typeof n=="number"?this.setHex(n):typeof n=="string"&&this.setStyle(n)}else this.setRGB(t,e,i);return this}setScalar(t){return this.r=t,this.g=t,this.b=t,this}setHex(t,e=qi){return t=Math.floor(t),this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(t&255)/255,ce.colorSpaceToWorking(this,e),this}setRGB(t,e,i,n=ce.workingColorSpace){return this.r=t,this.g=e,this.b=i,ce.colorSpaceToWorking(this,n),this}setHSL(t,e,i,n=ce.workingColorSpace){if(t=U0(t,1),e=Zt(e,0,1),i=Zt(i,0,1),e===0)this.r=this.g=this.b=i;else{const s=i<=.5?i*(1+e):i+e-i*e,r=2*i-s;this.r=zh(r,s,t+1/3),this.g=zh(r,s,t),this.b=zh(r,s,t-1/3)}return ce.colorSpaceToWorking(this,n),this}setStyle(t,e=qi){function i(s){s!==void 0&&parseFloat(s)<1&&It("Color: Alpha component of "+t+" will be ignored.")}let n;if(n=/^(\w+)\(([^\)]*)\)/.exec(t)){let s;const r=n[1],o=n[2];switch(r){case"rgb":case"rgba":if(s=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))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,e);if(s=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))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,e);break;case"hsl":case"hsla":if(s=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return i(s[4]),this.setHSL(parseFloat(s[1])/360,parseFloat(s[2])/100,parseFloat(s[3])/100,e);break;default:It("Color: Unknown color model "+t)}}else if(n=/^\#([A-Fa-f\d]+)$/.exec(t)){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,e);if(r===6)return this.setHex(parseInt(s,16),e);It("Color: Invalid hex color "+t)}else if(t&&t.length>0)return this.setColorName(t,e);return this}setColorName(t,e=qi){const i=g1[t.toLowerCase()];return i!==void 0?this.setHex(i,e):It("Color: Unknown color "+t),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(t){return this.r=t.r,this.g=t.g,this.b=t.b,this}copySRGBToLinear(t){return this.r=Ns(t.r),this.g=Ns(t.g),this.b=Ns(t.b),this}copyLinearToSRGB(t){return this.r=Ha(t.r),this.g=Ha(t.g),this.b=Ha(t.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(t=qi){return ce.workingToColorSpace(Li.copy(this),t),Math.round(Zt(Li.r*255,0,255))*65536+Math.round(Zt(Li.g*255,0,255))*256+Math.round(Zt(Li.b*255,0,255))}getHexString(t=qi){return("000000"+this.getHex(t).toString(16)).slice(-6)}getHSL(t,e=ce.workingColorSpace){ce.workingToColorSpace(Li.copy(this),e);const i=Li.r,n=Li.g,s=Li.b,r=Math.max(i,n,s),o=Math.min(i,n,s);let c,l;const h=(o+r)/2;if(o===r)c=0,l=0;else{const u=r-o;switch(l=h<=.5?u/(r+o):u/(2-r-o),r){case i:c=(n-s)/u+(n<s?6:0);break;case n:c=(s-i)/u+2;break;case s:c=(i-n)/u+4;break}c/=6}return t.h=c,t.s=l,t.l=h,t}getRGB(t,e=ce.workingColorSpace){return ce.workingToColorSpace(Li.copy(this),e),t.r=Li.r,t.g=Li.g,t.b=Li.b,t}getStyle(t=qi){ce.workingToColorSpace(Li.copy(this),t);const e=Li.r,i=Li.g,n=Li.b;return t!==qi?`color(${t} ${e.toFixed(3)} ${i.toFixed(3)} ${n.toFixed(3)})`:`rgb(${Math.round(e*255)},${Math.round(i*255)},${Math.round(n*255)})`}offsetHSL(t,e,i){return this.getHSL(Xs),this.setHSL(Xs.h+t,Xs.s+e,Xs.l+i)}add(t){return this.r+=t.r,this.g+=t.g,this.b+=t.b,this}addColors(t,e){return this.r=t.r+e.r,this.g=t.g+e.g,this.b=t.b+e.b,this}addScalar(t){return this.r+=t,this.g+=t,this.b+=t,this}sub(t){return this.r=Math.max(0,this.r-t.r),this.g=Math.max(0,this.g-t.g),this.b=Math.max(0,this.b-t.b),this}multiply(t){return this.r*=t.r,this.g*=t.g,this.b*=t.b,this}multiplyScalar(t){return this.r*=t,this.g*=t,this.b*=t,this}lerp(t,e){return this.r+=(t.r-this.r)*e,this.g+=(t.g-this.g)*e,this.b+=(t.b-this.b)*e,this}lerpColors(t,e,i){return this.r=t.r+(e.r-t.r)*i,this.g=t.g+(e.g-t.g)*i,this.b=t.b+(e.b-t.b)*i,this}lerpHSL(t,e){this.getHSL(Xs),t.getHSL(Dc);const i=Vo(Xs.h,Dc.h,e),n=Vo(Xs.s,Dc.s,e),s=Vo(Xs.l,Dc.l,e);return this.setHSL(i,n,s),this}setFromVector3(t){return this.r=t.x,this.g=t.y,this.b=t.z,this}applyMatrix3(t){const e=this.r,i=this.g,n=this.b,s=t.elements;return this.r=s[0]*e+s[3]*i+s[6]*n,this.g=s[1]*e+s[4]*i+s[7]*n,this.b=s[2]*e+s[5]*i+s[8]*n,this}equals(t){return t.r===this.r&&t.g===this.g&&t.b===this.b}fromArray(t,e=0){return this.r=t[e],this.g=t[e+1],this.b=t[e+2],this}toArray(t=[],e=0){return t[e]=this.r,t[e+1]=this.g,t[e+2]=this.b,t}fromBufferAttribute(t,e){return this.r=t.getX(e),this.g=t.getY(e),this.b=t.getZ(e),this}toJSON(){return this.getHex()}*[Symbol.iterator](){yield this.r,yield this.g,yield this.b}}const Li=new st;st.NAMES=g1;class B0{constructor(t,e=1,i=1e3){this.isFog=!0,this.name="",this.color=new st(t),this.near=e,this.far=i}clone(){return new B0(this.color,this.near,this.far)}toJSON(){return{type:"Fog",name:this.name,color:this.color.getHex(),near:this.near,far:this.far}}}class ys extends Ge{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 Us,this.environmentIntensity=1,this.environmentRotation=new Us,this.overrideMaterial=null,typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}copy(t,e){return super.copy(t,e),t.background!==null&&(this.background=t.background.clone()),t.environment!==null&&(this.environment=t.environment.clone()),t.fog!==null&&(this.fog=t.fog.clone()),this.backgroundBlurriness=t.backgroundBlurriness,this.backgroundIntensity=t.backgroundIntensity,this.backgroundRotation.copy(t.backgroundRotation),this.environmentIntensity=t.environmentIntensity,this.environmentRotation.copy(t.environmentRotation),t.overrideMaterial!==null&&(this.overrideMaterial=t.overrideMaterial.clone()),this.matrixAutoUpdate=t.matrixAutoUpdate,this}toJSON(t){const e=super.toJSON(t);return this.fog!==null&&(e.object.fog=this.fog.toJSON()),this.backgroundBlurriness>0&&(e.object.backgroundBlurriness=this.backgroundBlurriness),this.backgroundIntensity!==1&&(e.object.backgroundIntensity=this.backgroundIntensity),e.object.backgroundRotation=this.backgroundRotation.toArray(),this.environmentIntensity!==1&&(e.object.environmentIntensity=this.environmentIntensity),e.object.environmentRotation=this.environmentRotation.toArray(),e}}const kn=new R,_s=new R,Bh=new R,bs=new R,ra=new R,aa=new R,mp=new R,Hh=new R,Gh=new R,Vh=new R,Wh=new ae,Xh=new ae,Yh=new ae;class Pn{constructor(t=new R,e=new R,i=new R){this.a=t,this.b=e,this.c=i}static getNormal(t,e,i,n){n.subVectors(i,e),kn.subVectors(t,e),n.cross(kn);const s=n.lengthSq();return s>0?n.multiplyScalar(1/Math.sqrt(s)):n.set(0,0,0)}static getBarycoord(t,e,i,n,s){kn.subVectors(n,e),_s.subVectors(i,e),Bh.subVectors(t,e);const r=kn.dot(kn),o=kn.dot(_s),c=kn.dot(Bh),l=_s.dot(_s),h=_s.dot(Bh),u=r*l-o*o;if(u===0)return s.set(0,0,0),null;const d=1/u,f=(l*c-o*h)*d,p=(r*h-o*c)*d;return s.set(1-f-p,p,f)}static containsPoint(t,e,i,n){return this.getBarycoord(t,e,i,n,bs)===null?!1:bs.x>=0&&bs.y>=0&&bs.x+bs.y<=1}static getInterpolation(t,e,i,n,s,r,o,c){return this.getBarycoord(t,e,i,n,bs)===null?(c.x=0,c.y=0,"z"in c&&(c.z=0),"w"in c&&(c.w=0),null):(c.setScalar(0),c.addScaledVector(s,bs.x),c.addScaledVector(r,bs.y),c.addScaledVector(o,bs.z),c)}static getInterpolatedAttribute(t,e,i,n,s,r){return Wh.setScalar(0),Xh.setScalar(0),Yh.setScalar(0),Wh.fromBufferAttribute(t,e),Xh.fromBufferAttribute(t,i),Yh.fromBufferAttribute(t,n),r.setScalar(0),r.addScaledVector(Wh,s.x),r.addScaledVector(Xh,s.y),r.addScaledVector(Yh,s.z),r}static isFrontFacing(t,e,i,n){return kn.subVectors(i,e),_s.subVectors(t,e),kn.cross(_s).dot(n)<0}set(t,e,i){return this.a.copy(t),this.b.copy(e),this.c.copy(i),this}setFromPointsAndIndices(t,e,i,n){return this.a.copy(t[e]),this.b.copy(t[i]),this.c.copy(t[n]),this}setFromAttributeAndIndices(t,e,i,n){return this.a.fromBufferAttribute(t,e),this.b.fromBufferAttribute(t,i),this.c.fromBufferAttribute(t,n),this}clone(){return new this.constructor().copy(this)}copy(t){return this.a.copy(t.a),this.b.copy(t.b),this.c.copy(t.c),this}getArea(){return kn.subVectors(this.c,this.b),_s.subVectors(this.a,this.b),kn.cross(_s).length()*.5}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return Pn.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return Pn.getBarycoord(t,this.a,this.b,this.c,e)}getInterpolation(t,e,i,n,s){return Pn.getInterpolation(t,this.a,this.b,this.c,e,i,n,s)}containsPoint(t){return Pn.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return Pn.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(t){return t.intersectsTriangle(this)}closestPointToPoint(t,e){const i=this.a,n=this.b,s=this.c;let r,o;ra.subVectors(n,i),aa.subVectors(s,i),Hh.subVectors(t,i);const c=ra.dot(Hh),l=aa.dot(Hh);if(c<=0&&l<=0)return e.copy(i);Gh.subVectors(t,n);const h=ra.dot(Gh),u=aa.dot(Gh);if(h>=0&&u<=h)return e.copy(n);const d=c*u-h*l;if(d<=0&&c>=0&&h<=0)return r=c/(c-h),e.copy(i).addScaledVector(ra,r);Vh.subVectors(t,s);const f=ra.dot(Vh),p=aa.dot(Vh);if(p>=0&&f<=p)return e.copy(s);const v=f*l-c*p;if(v<=0&&l>=0&&p<=0)return o=l/(l-p),e.copy(i).addScaledVector(aa,o);const m=h*p-f*u;if(m<=0&&u-h>=0&&f-p>=0)return mp.subVectors(s,n),o=(u-h)/(u-h+(f-p)),e.copy(n).addScaledVector(mp,o);const g=1/(m+v+d);return r=v*g,o=d*g,e.copy(i).addScaledVector(ra,r).addScaledVector(aa,o)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}}class ki{constructor(t=new R(1/0,1/0,1/0),e=new R(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=t,this.max=e}set(t,e){return this.min.copy(t),this.max.copy(e),this}setFromArray(t){this.makeEmpty();for(let e=0,i=t.length;e<i;e+=3)this.expandByPoint(zn.fromArray(t,e));return this}setFromBufferAttribute(t){this.makeEmpty();for(let e=0,i=t.count;e<i;e++)this.expandByPoint(zn.fromBufferAttribute(t,e));return this}setFromPoints(t){this.makeEmpty();for(let e=0,i=t.length;e<i;e++)this.expandByPoint(t[e]);return this}setFromCenterAndSize(t,e){const i=zn.copy(e).multiplyScalar(.5);return this.min.copy(t).sub(i),this.max.copy(t).add(i),this}setFromObject(t,e=!1){return this.makeEmpty(),this.expandByObject(t,e)}clone(){return new this.constructor().copy(this)}copy(t){return this.min.copy(t.min),this.max.copy(t.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(t){return this.isEmpty()?t.set(0,0,0):t.addVectors(this.min,this.max).multiplyScalar(.5)}getSize(t){return this.isEmpty()?t.set(0,0,0):t.subVectors(this.max,this.min)}expandByPoint(t){return this.min.min(t),this.max.max(t),this}expandByVector(t){return this.min.sub(t),this.max.add(t),this}expandByScalar(t){return this.min.addScalar(-t),this.max.addScalar(t),this}expandByObject(t,e=!1){t.updateWorldMatrix(!1,!1);const i=t.geometry;if(i!==void 0){const s=i.getAttribute("position");if(e===!0&&s!==void 0&&t.isInstancedMesh!==!0)for(let r=0,o=s.count;r<o;r++)t.isMesh===!0?t.getVertexPosition(r,zn):zn.fromBufferAttribute(s,r),zn.applyMatrix4(t.matrixWorld),this.expandByPoint(zn);else t.boundingBox!==void 0?(t.boundingBox===null&&t.computeBoundingBox(),Ic.copy(t.boundingBox)):(i.boundingBox===null&&i.computeBoundingBox(),Ic.copy(i.boundingBox)),Ic.applyMatrix4(t.matrixWorld),this.union(Ic)}const n=t.children;for(let s=0,r=n.length;s<r;s++)this.expandByObject(n[s],e);return this}containsPoint(t){return t.x>=this.min.x&&t.x<=this.max.x&&t.y>=this.min.y&&t.y<=this.max.y&&t.z>=this.min.z&&t.z<=this.max.z}containsBox(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y&&this.min.z<=t.min.z&&t.max.z<=this.max.z}getParameter(t,e){return e.set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y),(t.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(t){return t.max.x>=this.min.x&&t.min.x<=this.max.x&&t.max.y>=this.min.y&&t.min.y<=this.max.y&&t.max.z>=this.min.z&&t.min.z<=this.max.z}intersectsSphere(t){return this.clampPoint(t.center,zn),zn.distanceToSquared(t.center)<=t.radius*t.radius}intersectsPlane(t){let e,i;return t.normal.x>0?(e=t.normal.x*this.min.x,i=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,i=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,i+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,i+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,i+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,i+=t.normal.z*this.min.z),e<=-t.constant&&i>=-t.constant}intersectsTriangle(t){if(this.isEmpty())return!1;this.getCenter(lo),Cc.subVectors(this.max,lo),oa.subVectors(t.a,lo),ca.subVectors(t.b,lo),la.subVectors(t.c,lo),Ys.subVectors(ca,oa),qs.subVectors(la,ca),yr.subVectors(oa,la);let e=[0,-Ys.z,Ys.y,0,-qs.z,qs.y,0,-yr.z,yr.y,Ys.z,0,-Ys.x,qs.z,0,-qs.x,yr.z,0,-yr.x,-Ys.y,Ys.x,0,-qs.y,qs.x,0,-yr.y,yr.x,0];return!qh(e,oa,ca,la,Cc)||(e=[1,0,0,0,1,0,0,0,1],!qh(e,oa,ca,la,Cc))?!1:(Pc.crossVectors(Ys,qs),e=[Pc.x,Pc.y,Pc.z],qh(e,oa,ca,la,Cc))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,zn).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=this.getSize(zn).length()*.5),t}intersect(t){return this.min.max(t.min),this.max.min(t.max),this.isEmpty()&&this.makeEmpty(),this}union(t){return this.min.min(t.min),this.max.max(t.max),this}applyMatrix4(t){return this.isEmpty()?this:(ws[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),ws[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),ws[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),ws[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),ws[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),ws[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),ws[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),ws[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(ws),this)}translate(t){return this.min.add(t),this.max.add(t),this}equals(t){return t.min.equals(this.min)&&t.max.equals(this.max)}toJSON(){return{min:this.min.toArray(),max:this.max.toArray()}}fromJSON(t){return this.min.fromArray(t.min),this.max.fromArray(t.max),this}}const ws=[new R,new R,new R,new R,new R,new R,new R,new R],zn=new R,Ic=new ki,oa=new R,ca=new R,la=new R,Ys=new R,qs=new R,yr=new R,lo=new R,Cc=new R,Pc=new R,Sr=new R;function qh(a,t,e,i,n){for(let s=0,r=a.length-3;s<=r;s+=3){Sr.fromArray(a,s);const o=n.x*Math.abs(Sr.x)+n.y*Math.abs(Sr.y)+n.z*Math.abs(Sr.z),c=t.dot(Sr),l=e.dot(Sr),h=i.dot(Sr);if(Math.max(-Math.max(c,l,h),Math.min(c,l,h))>o)return!1}return!0}const Ps=ex();function ex(){const a=new ArrayBuffer(4),t=new Float32Array(a),e=new Uint32Array(a),i=new Uint32Array(512),n=new Uint32Array(512);for(let c=0;c<256;++c){const l=c-127;l<-27?(i[c]=0,i[c|256]=32768,n[c]=24,n[c|256]=24):l<-14?(i[c]=1024>>-l-14,i[c|256]=1024>>-l-14|32768,n[c]=-l-1,n[c|256]=-l-1):l<=15?(i[c]=l+15<<10,i[c|256]=l+15<<10|32768,n[c]=13,n[c|256]=13):l<128?(i[c]=31744,i[c|256]=64512,n[c]=24,n[c|256]=24):(i[c]=31744,i[c|256]=64512,n[c]=13,n[c|256]=13)}const s=new Uint32Array(2048),r=new Uint32Array(64),o=new Uint32Array(64);for(let c=1;c<1024;++c){let l=c<<13,h=0;for(;(l&8388608)===0;)l<<=1,h-=8388608;l&=-8388609,h+=947912704,s[c]=l|h}for(let c=1024;c<2048;++c)s[c]=939524096+(c-1024<<13);for(let c=1;c<31;++c)r[c]=c<<23;r[31]=1199570944,r[32]=2147483648;for(let c=33;c<63;++c)r[c]=2147483648+(c-32<<23);r[63]=3347054592;for(let c=1;c<64;++c)c!==32&&(o[c]=1024);return{floatView:t,uint32View:e,baseTable:i,shiftTable:n,mantissaTable:s,exponentTable:r,offsetTable:o}}function ix(a){Math.abs(a)>65504&&It("DataUtils.toHalfFloat(): Value out of range."),a=Zt(a,-65504,65504),Ps.floatView[0]=a;const t=Ps.uint32View[0],e=t>>23&511;return Ps.baseTable[e]+((t&8388607)>>Ps.shiftTable[e])}function nx(a){const t=a>>10;return Ps.uint32View[0]=Ps.mantissaTable[Ps.offsetTable[t]+(a&1023)]+Ps.exponentTable[t],Ps.floatView[0]}class Ln{static toHalfFloat(t){return ix(t)}static fromHalfFloat(t){return nx(t)}}const pi=new R,Lc=new Mt;let sx=0;class Jt extends vr{constructor(t,e,i=!1){if(super(),Array.isArray(t))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,Object.defineProperty(this,"id",{value:sx++}),this.name="",this.array=t,this.itemSize=e,this.count=t!==void 0?t.length/e:0,this.normalized=i,this.usage=Bd,this.updateRanges=[],this.gpuType=Ui,this.version=0}onUploadCallback(){}set needsUpdate(t){t===!0&&this.version++}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.name=t.name,this.array=new t.array.constructor(t.array),this.itemSize=t.itemSize,this.count=t.count,this.normalized=t.normalized,this.usage=t.usage,this.gpuType=t.gpuType,this}copyAt(t,e,i){t*=this.itemSize,i*=e.itemSize;for(let n=0,s=this.itemSize;n<s;n++)this.array[t+n]=e.array[i+n];return this}copyArray(t){return this.array.set(t),this}applyMatrix3(t){if(this.itemSize===2)for(let e=0,i=this.count;e<i;e++)Lc.fromBufferAttribute(this,e),Lc.applyMatrix3(t),this.setXY(e,Lc.x,Lc.y);else if(this.itemSize===3)for(let e=0,i=this.count;e<i;e++)pi.fromBufferAttribute(this,e),pi.applyMatrix3(t),this.setXYZ(e,pi.x,pi.y,pi.z);return this}applyMatrix4(t){for(let e=0,i=this.count;e<i;e++)pi.fromBufferAttribute(this,e),pi.applyMatrix4(t),this.setXYZ(e,pi.x,pi.y,pi.z);return this}applyNormalMatrix(t){for(let e=0,i=this.count;e<i;e++)pi.fromBufferAttribute(this,e),pi.applyNormalMatrix(t),this.setXYZ(e,pi.x,pi.y,pi.z);return this}transformDirection(t){for(let e=0,i=this.count;e<i;e++)pi.fromBufferAttribute(this,e),pi.transformDirection(t),this.setXYZ(e,pi.x,pi.y,pi.z);return this}set(t,e=0){return this.array.set(t,e),this}getComponent(t,e){let i=this.array[t*this.itemSize+e];return this.normalized&&(i=qn(i,this.array)),i}setComponent(t,e,i){return this.normalized&&(i=Ee(i,this.array)),this.array[t*this.itemSize+e]=i,this}getX(t){let e=this.array[t*this.itemSize];return this.normalized&&(e=qn(e,this.array)),e}setX(t,e){return this.normalized&&(e=Ee(e,this.array)),this.array[t*this.itemSize]=e,this}getY(t){let e=this.array[t*this.itemSize+1];return this.normalized&&(e=qn(e,this.array)),e}setY(t,e){return this.normalized&&(e=Ee(e,this.array)),this.array[t*this.itemSize+1]=e,this}getZ(t){let e=this.array[t*this.itemSize+2];return this.normalized&&(e=qn(e,this.array)),e}setZ(t,e){return this.normalized&&(e=Ee(e,this.array)),this.array[t*this.itemSize+2]=e,this}getW(t){let e=this.array[t*this.itemSize+3];return this.normalized&&(e=qn(e,this.array)),e}setW(t,e){return this.normalized&&(e=Ee(e,this.array)),this.array[t*this.itemSize+3]=e,this}setXY(t,e,i){return t*=this.itemSize,this.normalized&&(e=Ee(e,this.array),i=Ee(i,this.array)),this.array[t+0]=e,this.array[t+1]=i,this}setXYZ(t,e,i,n){return t*=this.itemSize,this.normalized&&(e=Ee(e,this.array),i=Ee(i,this.array),n=Ee(n,this.array)),this.array[t+0]=e,this.array[t+1]=i,this.array[t+2]=n,this}setXYZW(t,e,i,n,s){return t*=this.itemSize,this.normalized&&(e=Ee(e,this.array),i=Ee(i,this.array),n=Ee(n,this.array),s=Ee(s,this.array)),this.array[t+0]=e,this.array[t+1]=i,this.array[t+2]=n,this.array[t+3]=s,this}onUpload(t){return this.onUploadCallback=t,this}clone(){return new this.constructor(this.array,this.itemSize).copy(this)}toJSON(){const t={itemSize:this.itemSize,type:this.array.constructor.name,array:Array.from(this.array),normalized:this.normalized};return this.name!==""&&(t.name=this.name),this.usage!==Bd&&(t.usage=this.usage),t}dispose(){this.dispatchEvent({type:"dispose"})}}class v1 extends Jt{constructor(t,e,i){super(new Uint16Array(t),e,i)}}class H0 extends Jt{constructor(t,e,i){super(new Uint32Array(t),e,i)}}class ue extends Jt{constructor(t,e,i){super(new Float32Array(t),e,i)}}const rx=new ki,ho=new R,$h=new R;class ks{constructor(t=new R,e=-1){this.isSphere=!0,this.center=t,this.radius=e}set(t,e){return this.center.copy(t),this.radius=e,this}setFromPoints(t,e){const i=this.center;e!==void 0?i.copy(e):rx.setFromPoints(t).getCenter(i);let n=0;for(let s=0,r=t.length;s<r;s++)n=Math.max(n,i.distanceToSquared(t[s]));return this.radius=Math.sqrt(n),this}copy(t){return this.center.copy(t.center),this.radius=t.radius,this}isEmpty(){return this.radius<0}makeEmpty(){return this.center.set(0,0,0),this.radius=-1,this}containsPoint(t){return t.distanceToSquared(this.center)<=this.radius*this.radius}distanceToPoint(t){return t.distanceTo(this.center)-this.radius}intersectsSphere(t){const e=this.radius+t.radius;return t.center.distanceToSquared(this.center)<=e*e}intersectsBox(t){return t.intersectsSphere(this)}intersectsPlane(t){return Math.abs(t.distanceToPoint(this.center))<=this.radius}clampPoint(t,e){const i=this.center.distanceToSquared(t);return e.copy(t),i>this.radius*this.radius&&(e.sub(this.center).normalize(),e.multiplyScalar(this.radius).add(this.center)),e}getBoundingBox(t){return this.isEmpty()?(t.makeEmpty(),t):(t.set(this.center,this.center),t.expandByScalar(this.radius),t)}applyMatrix4(t){return this.center.applyMatrix4(t),this.radius=this.radius*t.getMaxScaleOnAxis(),this}translate(t){return this.center.add(t),this}expandByPoint(t){if(this.isEmpty())return this.center.copy(t),this.radius=0,this;ho.subVectors(t,this.center);const e=ho.lengthSq();if(e>this.radius*this.radius){const i=Math.sqrt(e),n=(i-this.radius)*.5;this.center.addScaledVector(ho,n/i),this.radius+=n}return this}union(t){return t.isEmpty()?this:this.isEmpty()?(this.copy(t),this):(this.center.equals(t.center)===!0?this.radius=Math.max(this.radius,t.radius):($h.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint(ho.copy(t.center).add($h)),this.expandByPoint(ho.copy(t.center).sub($h))),this)}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return new this.constructor().copy(this)}toJSON(){return{radius:this.radius,center:this.center.toArray()}}fromJSON(t){return this.radius=t.radius,this.center.fromArray(t.center),this}}let ax=0;const En=new te,Kh=new Ge,ha=new R,hn=new ki,uo=new ki,yi=new R;class se extends vr{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:ax++}),this.uuid=Kn(),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(t){return Array.isArray(t)?this.index=new(_M(t)?H0:v1)(t,1):this.index=t,this}setIndirect(t,e=0){return this.indirect=t,this.indirectOffset=e,this}getIndirect(){return this.indirect}getAttribute(t){return this.attributes[t]}setAttribute(t,e){return this.attributes[t]=e,this}deleteAttribute(t){return delete this.attributes[t],this}hasAttribute(t){return this.attributes[t]!==void 0}addGroup(t,e,i=0){this.groups.push({start:t,count:e,materialIndex:i})}clearGroups(){this.groups=[]}setDrawRange(t,e){this.drawRange.start=t,this.drawRange.count=e}applyMatrix4(t){const e=this.attributes.position;e!==void 0&&(e.applyMatrix4(t),e.needsUpdate=!0);const i=this.attributes.normal;if(i!==void 0){const s=new $t().getNormalMatrix(t);i.applyNormalMatrix(s),i.needsUpdate=!0}const n=this.attributes.tangent;return n!==void 0&&(n.transformDirection(t),n.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this._transformed=!0,this}applyQuaternion(t){return En.makeRotationFromQuaternion(t),this.applyMatrix4(En),this}rotateX(t){return En.makeRotationX(t),this.applyMatrix4(En),this}rotateY(t){return En.makeRotationY(t),this.applyMatrix4(En),this}rotateZ(t){return En.makeRotationZ(t),this.applyMatrix4(En),this}translate(t,e,i){return En.makeTranslation(t,e,i),this.applyMatrix4(En),this}scale(t,e,i){return En.makeScale(t,e,i),this.applyMatrix4(En),this}lookAt(t){return Kh.lookAt(t),Kh.updateMatrix(),this.applyMatrix4(Kh.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(ha).negate(),this.translate(ha.x,ha.y,ha.z),this}setFromPoints(t){const e=this.getAttribute("position");if(e===void 0){const i=[];for(let n=0,s=t.length;n<s;n++){const r=t[n];i.push(r.x,r.y,r.z||0)}this.setAttribute("position",new ue(i,3))}else{const i=Math.min(t.length,e.count);for(let n=0;n<i;n++){const s=t[n];e.setXYZ(n,s.x,s.y,s.z||0)}t.length>e.count&&It("BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry."),e.needsUpdate=!0}return this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new ki);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){Wt("BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),this.boundingBox.set(new R(-1/0,-1/0,-1/0),new R(1/0,1/0,1/0));return}if(t!==void 0){if(this.boundingBox.setFromBufferAttribute(t),e)for(let i=0,n=e.length;i<n;i++){const s=e[i];hn.setFromBufferAttribute(s),this.morphTargetsRelative?(yi.addVectors(this.boundingBox.min,hn.min),this.boundingBox.expandByPoint(yi),yi.addVectors(this.boundingBox.max,hn.max),this.boundingBox.expandByPoint(yi)):(this.boundingBox.expandByPoint(hn.min),this.boundingBox.expandByPoint(hn.max))}}else this.boundingBox.makeEmpty();(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z))&&Wt('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 ks);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){Wt("BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.",this),this.boundingSphere.set(new R,1/0);return}if(t){const i=this.boundingSphere.center;if(hn.setFromBufferAttribute(t),e)for(let s=0,r=e.length;s<r;s++){const o=e[s];uo.setFromBufferAttribute(o),this.morphTargetsRelative?(yi.addVectors(hn.min,uo.min),hn.expandByPoint(yi),yi.addVectors(hn.max,uo.max),hn.expandByPoint(yi)):(hn.expandByPoint(uo.min),hn.expandByPoint(uo.max))}hn.getCenter(i);let n=0;for(let s=0,r=t.count;s<r;s++)yi.fromBufferAttribute(t,s),n=Math.max(n,i.distanceToSquared(yi));if(e)for(let s=0,r=e.length;s<r;s++){const o=e[s],c=this.morphTargetsRelative;for(let l=0,h=o.count;l<h;l++)yi.fromBufferAttribute(o,l),c&&(ha.fromBufferAttribute(t,l),yi.add(ha)),n=Math.max(n,i.distanceToSquared(yi))}this.boundingSphere.radius=Math.sqrt(n),isNaN(this.boundingSphere.radius)&&Wt('BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',this)}}computeTangents(){const t=this.index,e=this.attributes;if(t===null||e.position===void 0||e.normal===void 0||e.uv===void 0){Wt("BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)");return}const i=e.position,n=e.normal,s=e.uv;let r=this.getAttribute("tangent");(r===void 0||r.count!==i.count)&&(r=new Jt(new Float32Array(4*i.count),4),this.setAttribute("tangent",r));const o=[],c=[];for(let y=0;y<i.count;y++)o[y]=new R,c[y]=new R;const l=new R,h=new R,u=new R,d=new Mt,f=new Mt,p=new Mt,v=new R,m=new R;function g(y,A,C){l.fromBufferAttribute(i,y),h.fromBufferAttribute(i,A),u.fromBufferAttribute(i,C),d.fromBufferAttribute(s,y),f.fromBufferAttribute(s,A),p.fromBufferAttribute(s,C),h.sub(l),u.sub(l),f.sub(d),p.sub(d);const I=1/(f.x*p.y-p.x*f.y);isFinite(I)&&(v.copy(h).multiplyScalar(p.y).addScaledVector(u,-f.y).multiplyScalar(I),m.copy(u).multiplyScalar(f.x).addScaledVector(h,-p.x).multiplyScalar(I),o[y].add(v),o[A].add(v),o[C].add(v),c[y].add(m),c[A].add(m),c[C].add(m))}let S=this.groups;S.length===0&&(S=[{start:0,count:t.count}]);for(let y=0,A=S.length;y<A;++y){const C=S[y],I=C.start,P=C.count;for(let V=I,X=I+P;V<X;V+=3)g(t.getX(V+0),t.getX(V+1),t.getX(V+2))}const x=new R,M=new R,b=new R,w=new R;function T(y){b.fromBufferAttribute(n,y),w.copy(b);const A=o[y];x.copy(A),x.sub(b.multiplyScalar(b.dot(A))).normalize(),M.crossVectors(w,A);const I=M.dot(c[y])<0?-1:1;r.setXYZW(y,x.x,x.y,x.z,I)}for(let y=0,A=S.length;y<A;++y){const C=S[y],I=C.start,P=C.count;for(let V=I,X=I+P;V<X;V+=3)T(t.getX(V+0)),T(t.getX(V+1)),T(t.getX(V+2))}this._transformed=!0}computeVertexNormals(){const t=this.index,e=this.getAttribute("position");if(e!==void 0){let i=this.getAttribute("normal");if(i===void 0||i.count!==e.count)i=new Jt(new Float32Array(e.count*3),3),this.setAttribute("normal",i);else for(let d=0,f=i.count;d<f;d++)i.setXYZ(d,0,0,0);const n=new R,s=new R,r=new R,o=new R,c=new R,l=new R,h=new R,u=new R;if(t)for(let d=0,f=t.count;d<f;d+=3){const p=t.getX(d+0),v=t.getX(d+1),m=t.getX(d+2);n.fromBufferAttribute(e,p),s.fromBufferAttribute(e,v),r.fromBufferAttribute(e,m),h.subVectors(r,s),u.subVectors(n,s),h.cross(u),o.fromBufferAttribute(i,p),c.fromBufferAttribute(i,v),l.fromBufferAttribute(i,m),o.add(h),c.add(h),l.add(h),i.setXYZ(p,o.x,o.y,o.z),i.setXYZ(v,c.x,c.y,c.z),i.setXYZ(m,l.x,l.y,l.z)}else for(let d=0,f=e.count;d<f;d+=3)n.fromBufferAttribute(e,d+0),s.fromBufferAttribute(e,d+1),r.fromBufferAttribute(e,d+2),h.subVectors(r,s),u.subVectors(n,s),h.cross(u),i.setXYZ(d+0,h.x,h.y,h.z),i.setXYZ(d+1,h.x,h.y,h.z),i.setXYZ(d+2,h.x,h.y,h.z);this.normalizeNormals(),i.needsUpdate=!0}}normalizeNormals(){const t=this.attributes.normal;for(let e=0,i=t.count;e<i;e++)yi.fromBufferAttribute(t,e),yi.normalize(),t.setXYZ(e,yi.x,yi.y,yi.z)}toNonIndexed(){function t(o,c){const l=o.array,h=o.itemSize,u=o.normalized,d=new l.constructor(c.length*h);let f=0,p=0;for(let v=0,m=c.length;v<m;v++){o.isInterleavedBufferAttribute?f=c[v]*o.data.stride+o.offset:f=c[v]*h;for(let g=0;g<h;g++)d[p++]=l[f++]}return new Jt(d,h,u)}if(this.index===null)return It("BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."),this;const e=new se,i=this.index.array,n=this.attributes;for(const o in n){const c=n[o],l=t(c,i);e.setAttribute(o,l)}const s=this.morphAttributes;for(const o in s){const c=[],l=s[o];for(let h=0,u=l.length;h<u;h++){const d=l[h],f=t(d,i);c.push(f)}e.morphAttributes[o]=c}e.morphTargetsRelative=this.morphTargetsRelative;const r=this.groups;for(let o=0,c=r.length;o<c;o++){const l=r[o];e.addGroup(l.start,l.count,l.materialIndex)}return e}toJSON(){const t={metadata:{version:4.7,type:"BufferGeometry",generator:"BufferGeometry.toJSON"}};if(t.uuid=this.uuid,t.type=this.parameters!==void 0&&this._transformed===!0?"BufferGeometry":this.type,this.name!==""&&(t.name=this.name),Object.keys(this.userData).length>0&&(t.userData=this.userData),this.parameters!==void 0&&this._transformed!==!0){const c=this.parameters;for(const l in c)c[l]!==void 0&&(t[l]=c[l]);return t}t.data={attributes:{}};const e=this.index;e!==null&&(t.data.index={type:e.array.constructor.name,array:Array.prototype.slice.call(e.array)});const i=this.attributes;for(const c in i){const l=i[c];t.data.attributes[c]=l.toJSON(t.data)}const n={};let s=!1;for(const c in this.morphAttributes){const l=this.morphAttributes[c],h=[];for(let u=0,d=l.length;u<d;u++){const f=l[u];h.push(f.toJSON(t.data))}h.length>0&&(n[c]=h,s=!0)}s&&(t.data.morphAttributes=n,t.data.morphTargetsRelative=this.morphTargetsRelative);const r=this.groups;r.length>0&&(t.data.groups=JSON.parse(JSON.stringify(r)));const o=this.boundingSphere;return o!==null&&(t.data.boundingSphere=o.toJSON()),t}clone(){return new this.constructor().copy(this)}copy(t){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const e={};this.name=t.name;const i=t.index;i!==null&&this.setIndex(i.clone());const n=t.attributes;for(const l in n){const h=n[l];this.setAttribute(l,h.clone(e))}const s=t.morphAttributes;for(const l in s){const h=[],u=s[l];for(let d=0,f=u.length;d<f;d++)h.push(u[d].clone(e));this.morphAttributes[l]=h}this.morphTargetsRelative=t.morphTargetsRelative;const r=t.groups;for(let l=0,h=r.length;l<h;l++){const u=r[l];this.addGroup(u.start,u.count,u.materialIndex)}const o=t.boundingBox;o!==null&&(this.boundingBox=o.clone());const c=t.boundingSphere;return c!==null&&(this.boundingSphere=c.clone()),this.drawRange.start=t.drawRange.start,this.drawRange.count=t.drawRange.count,this.userData=t.userData,this._transformed=t._transformed,this}dispose(){this.dispatchEvent({type:"dispose"})}}class M1{constructor(t,e){this.isInterleavedBuffer=!0,this.array=t,this.stride=e,this.count=t!==void 0?t.length/e:0,this.usage=Bd,this.updateRanges=[],this.version=0,this.uuid=Kn()}onUploadCallback(){}set needsUpdate(t){t===!0&&this.version++}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.array=new t.array.constructor(t.array),this.count=t.count,this.stride=t.stride,this.usage=t.usage,this}copyAt(t,e,i){t*=this.stride,i*=e.stride;for(let n=0,s=this.stride;n<s;n++)this.array[t+n]=e.array[i+n];return this}set(t,e=0){return this.array.set(t,e),this}clone(t){t.arrayBuffers===void 0&&(t.arrayBuffers={}),this.array.buffer._uuid===void 0&&(this.array.buffer._uuid=Kn()),t.arrayBuffers[this.array.buffer._uuid]===void 0&&(t.arrayBuffers[this.array.buffer._uuid]=this.array.slice(0).buffer);const e=new this.array.constructor(t.arrayBuffers[this.array.buffer._uuid]),i=new this.constructor(e,this.stride);return i.setUsage(this.usage),i}onUpload(t){return this.onUploadCallback=t,this}toJSON(t){return t.arrayBuffers===void 0&&(t.arrayBuffers={}),this.array.buffer._uuid===void 0&&(this.array.buffer._uuid=Kn()),t.arrayBuffers[this.array.buffer._uuid]===void 0&&(t.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 zi=new R;class ql{constructor(t,e,i,n=!1){this.isInterleavedBufferAttribute=!0,this.name="",this.data=t,this.itemSize=e,this.offset=i,this.normalized=n}get count(){return this.data.count}get array(){return this.data.array}set needsUpdate(t){this.data.needsUpdate=t}applyMatrix4(t){for(let e=0,i=this.data.count;e<i;e++)zi.fromBufferAttribute(this,e),zi.applyMatrix4(t),this.setXYZ(e,zi.x,zi.y,zi.z);return this}applyNormalMatrix(t){for(let e=0,i=this.count;e<i;e++)zi.fromBufferAttribute(this,e),zi.applyNormalMatrix(t),this.setXYZ(e,zi.x,zi.y,zi.z);return this}transformDirection(t){for(let e=0,i=this.count;e<i;e++)zi.fromBufferAttribute(this,e),zi.transformDirection(t),this.setXYZ(e,zi.x,zi.y,zi.z);return this}getComponent(t,e){let i=this.array[t*this.data.stride+this.offset+e];return this.normalized&&(i=qn(i,this.array)),i}setComponent(t,e,i){return this.normalized&&(i=Ee(i,this.array)),this.data.array[t*this.data.stride+this.offset+e]=i,this}setX(t,e){return this.normalized&&(e=Ee(e,this.array)),this.data.array[t*this.data.stride+this.offset]=e,this}setY(t,e){return this.normalized&&(e=Ee(e,this.array)),this.data.array[t*this.data.stride+this.offset+1]=e,this}setZ(t,e){return this.normalized&&(e=Ee(e,this.array)),this.data.array[t*this.data.stride+this.offset+2]=e,this}setW(t,e){return this.normalized&&(e=Ee(e,this.array)),this.data.array[t*this.data.stride+this.offset+3]=e,this}getX(t){let e=this.data.array[t*this.data.stride+this.offset];return this.normalized&&(e=qn(e,this.array)),e}getY(t){let e=this.data.array[t*this.data.stride+this.offset+1];return this.normalized&&(e=qn(e,this.array)),e}getZ(t){let e=this.data.array[t*this.data.stride+this.offset+2];return this.normalized&&(e=qn(e,this.array)),e}getW(t){let e=this.data.array[t*this.data.stride+this.offset+3];return this.normalized&&(e=qn(e,this.array)),e}setXY(t,e,i){return t=t*this.data.stride+this.offset,this.normalized&&(e=Ee(e,this.array),i=Ee(i,this.array)),this.data.array[t+0]=e,this.data.array[t+1]=i,this}setXYZ(t,e,i,n){return t=t*this.data.stride+this.offset,this.normalized&&(e=Ee(e,this.array),i=Ee(i,this.array),n=Ee(n,this.array)),this.data.array[t+0]=e,this.data.array[t+1]=i,this.data.array[t+2]=n,this}setXYZW(t,e,i,n,s){return t=t*this.data.stride+this.offset,this.normalized&&(e=Ee(e,this.array),i=Ee(i,this.array),n=Ee(n,this.array),s=Ee(s,this.array)),this.data.array[t+0]=e,this.data.array[t+1]=i,this.data.array[t+2]=n,this.data.array[t+3]=s,this}clone(t){if(t===void 0){Yl("InterleavedBufferAttribute.clone(): Cloning an interleaved buffer attribute will de-interleave buffer data.");const e=[];for(let i=0;i<this.count;i++){const n=i*this.data.stride+this.offset;for(let s=0;s<this.itemSize;s++)e.push(this.data.array[n+s])}return new Jt(new this.array.constructor(e),this.itemSize,this.normalized)}else return t.interleavedBuffers===void 0&&(t.interleavedBuffers={}),t.interleavedBuffers[this.data.uuid]===void 0&&(t.interleavedBuffers[this.data.uuid]=this.data.clone(t)),new ql(t.interleavedBuffers[this.data.uuid],this.itemSize,this.offset,this.normalized)}toJSON(t){if(t===void 0){Yl("InterleavedBufferAttribute.toJSON(): Serializing an interleaved buffer attribute will de-interleave buffer data.");const e=[];for(let i=0;i<this.count;i++){const n=i*this.data.stride+this.offset;for(let s=0;s<this.itemSize;s++)e.push(this.data.array[n+s])}return{itemSize:this.itemSize,type:this.array.constructor.name,array:e,normalized:this.normalized}}else return t.interleavedBuffers===void 0&&(t.interleavedBuffers={}),t.interleavedBuffers[this.data.uuid]===void 0&&(t.interleavedBuffers[this.data.uuid]=this.data.toJSON(t)),{isInterleavedBufferAttribute:!0,itemSize:this.itemSize,data:this.data.uuid,offset:this.offset,normalized:this.normalized}}}let ox=0;class zs extends vr{constructor(){super(),this.isMaterial=!0,Object.defineProperty(this,"id",{value:ox++}),this.uuid=Kn(),this.name="",this.type="Material",this.blending=dr,this.side=pr,this.vertexColors=!1,this.opacity=1,this.transparent=!1,this.alphaHash=!1,this.blendSrc=td,this.blendDst=nc,this.blendEquation=Dr,this.blendSrcAlpha=null,this.blendDstAlpha=null,this.blendEquationAlpha=null,this.blendColor=new st(0,0,0),this.blendAlpha=0,this.depthFunc=Ja,this.depthTest=!0,this.depthWrite=!0,this.stencilWriteMask=255,this.stencilFunc=ip,this.stencilRef=0,this.stencilFuncMask=255,this.stencilFail=ta,this.stencilZFail=ta,this.stencilZPass=ta,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(t){this._alphaTest>0!=t>0&&this.version++,this._alphaTest=t}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(t){if(t!==void 0)for(const e in t){const i=t[e];if(i===void 0){It(`Material: parameter '${e}' has value of undefined.`);continue}const n=this[e];if(n===void 0){It(`Material: '${e}' 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[e]=i}}toJSON(t){const e=t===void 0||typeof t=="string";e&&(t={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(t).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(i.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(t).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(i.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(t).uuid,i.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),this.sheenColorMap&&this.sheenColorMap.isTexture&&(i.sheenColorMap=this.sheenColorMap.toJSON(t).uuid),this.sheenRoughnessMap&&this.sheenRoughnessMap.isTexture&&(i.sheenRoughnessMap=this.sheenRoughnessMap.toJSON(t).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(t).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(i.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(t).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(t).uuid),this.map&&this.map.isTexture&&(i.map=this.map.toJSON(t).uuid),this.matcap&&this.matcap.isTexture&&(i.matcap=this.matcap.toJSON(t).uuid),this.alphaMap&&this.alphaMap.isTexture&&(i.alphaMap=this.alphaMap.toJSON(t).uuid),this.lightMap&&this.lightMap.isTexture&&(i.lightMap=this.lightMap.toJSON(t).uuid,i.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(i.aoMap=this.aoMap.toJSON(t).uuid,i.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(i.bumpMap=this.bumpMap.toJSON(t).uuid,i.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(i.normalMap=this.normalMap.toJSON(t).uuid,i.normalMapType=this.normalMapType,i.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(i.displacementMap=this.displacementMap.toJSON(t).uuid,i.displacementScale=this.displacementScale,i.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(i.roughnessMap=this.roughnessMap.toJSON(t).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(i.metalnessMap=this.metalnessMap.toJSON(t).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(i.emissiveMap=this.emissiveMap.toJSON(t).uuid),this.specularMap&&this.specularMap.isTexture&&(i.specularMap=this.specularMap.toJSON(t).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(i.specularIntensityMap=this.specularIntensityMap.toJSON(t).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(i.specularColorMap=this.specularColorMap.toJSON(t).uuid),this.envMap&&this.envMap.isTexture&&(i.envMap=this.envMap.toJSON(t).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(t).uuid),this.transmission!==void 0&&(i.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(i.transmissionMap=this.transmissionMap.toJSON(t).uuid),this.thickness!==void 0&&(i.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(i.thicknessMap=this.thicknessMap.toJSON(t).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!==dr&&(i.blending=this.blending),this.side!==pr&&(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!==td&&(i.blendSrc=this.blendSrc),this.blendDst!==nc&&(i.blendDst=this.blendDst),this.blendEquation!==Dr&&(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!==Ja&&(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!==ip&&(i.stencilFunc=this.stencilFunc),this.stencilRef!==0&&(i.stencilRef=this.stencilRef),this.stencilFuncMask!==255&&(i.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==ta&&(i.stencilFail=this.stencilFail),this.stencilZFail!==ta&&(i.stencilZFail=this.stencilZFail),this.stencilZPass!==ta&&(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 o in s){const c=s[o];delete c.metadata,r.push(c)}return r}if(e){const s=n(t.textures),r=n(t.images);s.length>0&&(i.textures=s),r.length>0&&(i.images=r)}return i}fromJSON(t,e){if(t.uuid!==void 0&&(this.uuid=t.uuid),t.name!==void 0&&(this.name=t.name),t.color!==void 0&&this.color!==void 0&&this.color.setHex(t.color),t.roughness!==void 0&&(this.roughness=t.roughness),t.metalness!==void 0&&(this.metalness=t.metalness),t.sheen!==void 0&&(this.sheen=t.sheen),t.sheenColor!==void 0&&(this.sheenColor=new st().setHex(t.sheenColor)),t.sheenRoughness!==void 0&&(this.sheenRoughness=t.sheenRoughness),t.emissive!==void 0&&this.emissive!==void 0&&this.emissive.setHex(t.emissive),t.specular!==void 0&&this.specular!==void 0&&this.specular.setHex(t.specular),t.specularIntensity!==void 0&&(this.specularIntensity=t.specularIntensity),t.specularColor!==void 0&&this.specularColor!==void 0&&this.specularColor.setHex(t.specularColor),t.shininess!==void 0&&(this.shininess=t.shininess),t.clearcoat!==void 0&&(this.clearcoat=t.clearcoat),t.clearcoatRoughness!==void 0&&(this.clearcoatRoughness=t.clearcoatRoughness),t.dispersion!==void 0&&(this.dispersion=t.dispersion),t.iridescence!==void 0&&(this.iridescence=t.iridescence),t.iridescenceIOR!==void 0&&(this.iridescenceIOR=t.iridescenceIOR),t.iridescenceThicknessRange!==void 0&&(this.iridescenceThicknessRange=t.iridescenceThicknessRange),t.transmission!==void 0&&(this.transmission=t.transmission),t.thickness!==void 0&&(this.thickness=t.thickness),t.attenuationDistance!==void 0&&(this.attenuationDistance=t.attenuationDistance),t.attenuationColor!==void 0&&this.attenuationColor!==void 0&&this.attenuationColor.setHex(t.attenuationColor),t.anisotropy!==void 0&&(this.anisotropy=t.anisotropy),t.anisotropyRotation!==void 0&&(this.anisotropyRotation=t.anisotropyRotation),t.fog!==void 0&&(this.fog=t.fog),t.flatShading!==void 0&&(this.flatShading=t.flatShading),t.blending!==void 0&&(this.blending=t.blending),t.combine!==void 0&&(this.combine=t.combine),t.side!==void 0&&(this.side=t.side),t.shadowSide!==void 0&&(this.shadowSide=t.shadowSide),t.opacity!==void 0&&(this.opacity=t.opacity),t.transparent!==void 0&&(this.transparent=t.transparent),t.alphaTest!==void 0&&(this.alphaTest=t.alphaTest),t.alphaHash!==void 0&&(this.alphaHash=t.alphaHash),t.depthFunc!==void 0&&(this.depthFunc=t.depthFunc),t.depthTest!==void 0&&(this.depthTest=t.depthTest),t.depthWrite!==void 0&&(this.depthWrite=t.depthWrite),t.colorWrite!==void 0&&(this.colorWrite=t.colorWrite),t.blendSrc!==void 0&&(this.blendSrc=t.blendSrc),t.blendDst!==void 0&&(this.blendDst=t.blendDst),t.blendEquation!==void 0&&(this.blendEquation=t.blendEquation),t.blendSrcAlpha!==void 0&&(this.blendSrcAlpha=t.blendSrcAlpha),t.blendDstAlpha!==void 0&&(this.blendDstAlpha=t.blendDstAlpha),t.blendEquationAlpha!==void 0&&(this.blendEquationAlpha=t.blendEquationAlpha),t.blendColor!==void 0&&this.blendColor!==void 0&&this.blendColor.setHex(t.blendColor),t.blendAlpha!==void 0&&(this.blendAlpha=t.blendAlpha),t.stencilWriteMask!==void 0&&(this.stencilWriteMask=t.stencilWriteMask),t.stencilFunc!==void 0&&(this.stencilFunc=t.stencilFunc),t.stencilRef!==void 0&&(this.stencilRef=t.stencilRef),t.stencilFuncMask!==void 0&&(this.stencilFuncMask=t.stencilFuncMask),t.stencilFail!==void 0&&(this.stencilFail=t.stencilFail),t.stencilZFail!==void 0&&(this.stencilZFail=t.stencilZFail),t.stencilZPass!==void 0&&(this.stencilZPass=t.stencilZPass),t.stencilWrite!==void 0&&(this.stencilWrite=t.stencilWrite),t.wireframe!==void 0&&(this.wireframe=t.wireframe),t.wireframeLinewidth!==void 0&&(this.wireframeLinewidth=t.wireframeLinewidth),t.wireframeLinecap!==void 0&&(this.wireframeLinecap=t.wireframeLinecap),t.wireframeLinejoin!==void 0&&(this.wireframeLinejoin=t.wireframeLinejoin),t.rotation!==void 0&&(this.rotation=t.rotation),t.linewidth!==void 0&&(this.linewidth=t.linewidth),t.dashSize!==void 0&&(this.dashSize=t.dashSize),t.gapSize!==void 0&&(this.gapSize=t.gapSize),t.scale!==void 0&&(this.scale=t.scale),t.polygonOffset!==void 0&&(this.polygonOffset=t.polygonOffset),t.polygonOffsetFactor!==void 0&&(this.polygonOffsetFactor=t.polygonOffsetFactor),t.polygonOffsetUnits!==void 0&&(this.polygonOffsetUnits=t.polygonOffsetUnits),t.dithering!==void 0&&(this.dithering=t.dithering),t.alphaToCoverage!==void 0&&(this.alphaToCoverage=t.alphaToCoverage),t.premultipliedAlpha!==void 0&&(this.premultipliedAlpha=t.premultipliedAlpha),t.forceSinglePass!==void 0&&(this.forceSinglePass=t.forceSinglePass),t.allowOverride!==void 0&&(this.allowOverride=t.allowOverride),t.visible!==void 0&&(this.visible=t.visible),t.toneMapped!==void 0&&(this.toneMapped=t.toneMapped),t.userData!==void 0&&(this.userData=t.userData),t.vertexColors!==void 0&&(typeof t.vertexColors=="number"?this.vertexColors=t.vertexColors>0:this.vertexColors=t.vertexColors),t.size!==void 0&&(this.size=t.size),t.sizeAttenuation!==void 0&&(this.sizeAttenuation=t.sizeAttenuation),t.map!==void 0&&(this.map=e[t.map]||null),t.matcap!==void 0&&(this.matcap=e[t.matcap]||null),t.alphaMap!==void 0&&(this.alphaMap=e[t.alphaMap]||null),t.bumpMap!==void 0&&(this.bumpMap=e[t.bumpMap]||null),t.bumpScale!==void 0&&(this.bumpScale=t.bumpScale),t.normalMap!==void 0&&(this.normalMap=e[t.normalMap]||null),t.normalMapType!==void 0&&(this.normalMapType=t.normalMapType),t.normalScale!==void 0){let i=t.normalScale;Array.isArray(i)===!1&&(i=[i,i]),this.normalScale=new Mt().fromArray(i)}return t.displacementMap!==void 0&&(this.displacementMap=e[t.displacementMap]||null),t.displacementScale!==void 0&&(this.displacementScale=t.displacementScale),t.displacementBias!==void 0&&(this.displacementBias=t.displacementBias),t.roughnessMap!==void 0&&(this.roughnessMap=e[t.roughnessMap]||null),t.metalnessMap!==void 0&&(this.metalnessMap=e[t.metalnessMap]||null),t.emissiveMap!==void 0&&(this.emissiveMap=e[t.emissiveMap]||null),t.emissiveIntensity!==void 0&&(this.emissiveIntensity=t.emissiveIntensity),t.specularMap!==void 0&&(this.specularMap=e[t.specularMap]||null),t.specularIntensityMap!==void 0&&(this.specularIntensityMap=e[t.specularIntensityMap]||null),t.specularColorMap!==void 0&&(this.specularColorMap=e[t.specularColorMap]||null),t.envMap!==void 0&&(this.envMap=e[t.envMap]||null),t.envMapRotation!==void 0&&this.envMapRotation.fromArray(t.envMapRotation),t.envMapIntensity!==void 0&&(this.envMapIntensity=t.envMapIntensity),t.reflectivity!==void 0&&(this.reflectivity=t.reflectivity),t.refractionRatio!==void 0&&(this.refractionRatio=t.refractionRatio),t.lightMap!==void 0&&(this.lightMap=e[t.lightMap]||null),t.lightMapIntensity!==void 0&&(this.lightMapIntensity=t.lightMapIntensity),t.aoMap!==void 0&&(this.aoMap=e[t.aoMap]||null),t.aoMapIntensity!==void 0&&(this.aoMapIntensity=t.aoMapIntensity),t.gradientMap!==void 0&&(this.gradientMap=e[t.gradientMap]||null),t.clearcoatMap!==void 0&&(this.clearcoatMap=e[t.clearcoatMap]||null),t.clearcoatRoughnessMap!==void 0&&(this.clearcoatRoughnessMap=e[t.clearcoatRoughnessMap]||null),t.clearcoatNormalMap!==void 0&&(this.clearcoatNormalMap=e[t.clearcoatNormalMap]||null),t.clearcoatNormalScale!==void 0&&(this.clearcoatNormalScale=new Mt().fromArray(t.clearcoatNormalScale)),t.iridescenceMap!==void 0&&(this.iridescenceMap=e[t.iridescenceMap]||null),t.iridescenceThicknessMap!==void 0&&(this.iridescenceThicknessMap=e[t.iridescenceThicknessMap]||null),t.transmissionMap!==void 0&&(this.transmissionMap=e[t.transmissionMap]||null),t.thicknessMap!==void 0&&(this.thicknessMap=e[t.thicknessMap]||null),t.anisotropyMap!==void 0&&(this.anisotropyMap=e[t.anisotropyMap]||null),t.sheenColorMap!==void 0&&(this.sheenColorMap=e[t.sheenColorMap]||null),t.sheenRoughnessMap!==void 0&&(this.sheenRoughnessMap=e[t.sheenRoughnessMap]||null),this}clone(){return new this.constructor().copy(this)}copy(t){this.name=t.name,this.blending=t.blending,this.side=t.side,this.vertexColors=t.vertexColors,this.opacity=t.opacity,this.transparent=t.transparent,this.blendSrc=t.blendSrc,this.blendDst=t.blendDst,this.blendEquation=t.blendEquation,this.blendSrcAlpha=t.blendSrcAlpha,this.blendDstAlpha=t.blendDstAlpha,this.blendEquationAlpha=t.blendEquationAlpha,this.blendColor.copy(t.blendColor),this.blendAlpha=t.blendAlpha,this.depthFunc=t.depthFunc,this.depthTest=t.depthTest,this.depthWrite=t.depthWrite,this.stencilWriteMask=t.stencilWriteMask,this.stencilFunc=t.stencilFunc,this.stencilRef=t.stencilRef,this.stencilFuncMask=t.stencilFuncMask,this.stencilFail=t.stencilFail,this.stencilZFail=t.stencilZFail,this.stencilZPass=t.stencilZPass,this.stencilWrite=t.stencilWrite;const e=t.clippingPlanes;let i=null;if(e!==null){const n=e.length;i=new Array(n);for(let s=0;s!==n;++s)i[s]=e[s].clone()}return this.clippingPlanes=i,this.clipIntersection=t.clipIntersection,this.clipShadows=t.clipShadows,this.shadowSide=t.shadowSide,this.colorWrite=t.colorWrite,this.precision=t.precision,this.polygonOffset=t.polygonOffset,this.polygonOffsetFactor=t.polygonOffsetFactor,this.polygonOffsetUnits=t.polygonOffsetUnits,this.dithering=t.dithering,this.alphaTest=t.alphaTest,this.alphaHash=t.alphaHash,this.alphaToCoverage=t.alphaToCoverage,this.premultipliedAlpha=t.premultipliedAlpha,this.forceSinglePass=t.forceSinglePass,this.allowOverride=t.allowOverride,this.visible=t.visible,this.toneMapped=t.toneMapped,this.userData=JSON.parse(JSON.stringify(t.userData)),this}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(t){t===!0&&this.version++}}class Il extends zs{constructor(t){super(),this.isSpriteMaterial=!0,this.type="SpriteMaterial",this.color=new st(16777215),this.map=null,this.alphaMap=null,this.rotation=0,this.sizeAttenuation=!0,this.transparent=!0,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.alphaMap=t.alphaMap,this.rotation=t.rotation,this.sizeAttenuation=t.sizeAttenuation,this.fog=t.fog,this}}let ua;const fo=new R,da=new R,fa=new R,pa=new Mt,po=new Mt,x1=new te,Oc=new R,mo=new R,Nc=new R,gp=new Mt,Zh=new Mt,vp=new Mt;class go extends Ge{constructor(t=new Il){if(super(),this.isSprite=!0,this.type="Sprite",ua===void 0){ua=new se;const e=new Float32Array([-.5,-.5,0,0,0,.5,-.5,0,1,0,.5,.5,0,1,1,-.5,.5,0,0,1]),i=new M1(e,5);ua.setIndex([0,1,2,0,2,3]),ua.setAttribute("position",new ql(i,3,0,!1)),ua.setAttribute("uv",new ql(i,2,3,!1))}this.geometry=ua,this.material=t,this.center=new Mt(.5,.5),this.count=1}raycast(t,e){t.camera===null&&Wt('Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.'),da.setFromMatrixScale(this.matrixWorld),x1.copy(t.camera.matrixWorld),this.modelViewMatrix.multiplyMatrices(t.camera.matrixWorldInverse,this.matrixWorld),fa.setFromMatrixPosition(this.modelViewMatrix),t.camera.isPerspectiveCamera&&this.material.sizeAttenuation===!1&&da.multiplyScalar(-fa.z);const i=this.material.rotation;let n,s;i!==0&&(s=Math.cos(i),n=Math.sin(i));const r=this.center;Fc(Oc.set(-.5,-.5,0),fa,r,da,n,s),Fc(mo.set(.5,-.5,0),fa,r,da,n,s),Fc(Nc.set(.5,.5,0),fa,r,da,n,s),gp.set(0,0),Zh.set(1,0),vp.set(1,1);let o=t.ray.intersectTriangle(Oc,mo,Nc,!1,fo);if(o===null&&(Fc(mo.set(-.5,.5,0),fa,r,da,n,s),Zh.set(0,1),o=t.ray.intersectTriangle(Oc,Nc,mo,!1,fo),o===null))return;const c=t.ray.origin.distanceTo(fo);c<t.near||c>t.far||e.push({distance:c,point:fo.clone(),uv:Pn.getInterpolation(fo,Oc,mo,Nc,gp,Zh,vp,new Mt),face:null,object:this})}copy(t,e){return super.copy(t,e),t.center!==void 0&&this.center.copy(t.center),this.material=t.material,this}}function Fc(a,t,e,i,n,s){pa.subVectors(a,e).addScalar(.5).multiply(i),n!==void 0?(po.x=s*pa.x-n*pa.y,po.y=n*pa.x+s*pa.y):po.copy(pa),a.copy(t),a.x+=po.x,a.y+=po.y,a.applyMatrix4(x1)}const Es=new R,Jh=new R,Uc=new R,$s=new R,jh=new R,kc=new R,Qh=new R;class fc{constructor(t=new R,e=new R(0,0,-1)){this.origin=t,this.direction=e}set(t,e){return this.origin.copy(t),this.direction.copy(e),this}copy(t){return this.origin.copy(t.origin),this.direction.copy(t.direction),this}at(t,e){return e.copy(this.origin).addScaledVector(this.direction,t)}lookAt(t){return this.direction.copy(t).sub(this.origin).normalize(),this}recast(t){return this.origin.copy(this.at(t,Es)),this}closestPointToPoint(t,e){e.subVectors(t,this.origin);const i=e.dot(this.direction);return i<0?e.copy(this.origin):e.copy(this.origin).addScaledVector(this.direction,i)}distanceToPoint(t){return Math.sqrt(this.distanceSqToPoint(t))}distanceSqToPoint(t){const e=Es.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):(Es.copy(this.origin).addScaledVector(this.direction,e),Es.distanceToSquared(t))}distanceSqToSegment(t,e,i,n){Jh.copy(t).add(e).multiplyScalar(.5),Uc.copy(e).sub(t).normalize(),$s.copy(this.origin).sub(Jh);const s=t.distanceTo(e)*.5,r=-this.direction.dot(Uc),o=$s.dot(this.direction),c=-$s.dot(Uc),l=$s.lengthSq(),h=Math.abs(1-r*r);let u,d,f,p;if(h>0)if(u=r*c-o,d=r*o-c,p=s*h,u>=0)if(d>=-p)if(d<=p){const v=1/h;u*=v,d*=v,f=u*(u+r*d+2*o)+d*(r*u+d+2*c)+l}else d=s,u=Math.max(0,-(r*d+o)),f=-u*u+d*(d+2*c)+l;else d=-s,u=Math.max(0,-(r*d+o)),f=-u*u+d*(d+2*c)+l;else d<=-p?(u=Math.max(0,-(-r*s+o)),d=u>0?-s:Math.min(Math.max(-s,-c),s),f=-u*u+d*(d+2*c)+l):d<=p?(u=0,d=Math.min(Math.max(-s,-c),s),f=d*(d+2*c)+l):(u=Math.max(0,-(r*s+o)),d=u>0?s:Math.min(Math.max(-s,-c),s),f=-u*u+d*(d+2*c)+l);else d=r>0?-s:s,u=Math.max(0,-(r*d+o)),f=-u*u+d*(d+2*c)+l;return i&&i.copy(this.origin).addScaledVector(this.direction,u),n&&n.copy(Jh).addScaledVector(Uc,d),f}intersectSphere(t,e){Es.subVectors(t.center,this.origin);const i=Es.dot(this.direction),n=Es.dot(Es)-i*i,s=t.radius*t.radius;if(n>s)return null;const r=Math.sqrt(s-n),o=i-r,c=i+r;return c<0?null:o<0?this.at(c,e):this.at(o,e)}intersectsSphere(t){return t.radius<0?!1:this.distanceSqToPoint(t.center)<=t.radius*t.radius}distanceToPlane(t){const e=t.normal.dot(this.direction);if(e===0)return t.distanceToPoint(this.origin)===0?0:null;const i=-(this.origin.dot(t.normal)+t.constant)/e;return i>=0?i:null}intersectPlane(t,e){const i=this.distanceToPlane(t);return i===null?null:this.at(i,e)}intersectsPlane(t){const e=t.distanceToPoint(this.origin);return e===0||t.normal.dot(this.direction)*e<0}intersectBox(t,e){let i,n,s,r,o,c;const l=1/this.direction.x,h=1/this.direction.y,u=1/this.direction.z,d=this.origin;return l>=0?(i=(t.min.x-d.x)*l,n=(t.max.x-d.x)*l):(i=(t.max.x-d.x)*l,n=(t.min.x-d.x)*l),h>=0?(s=(t.min.y-d.y)*h,r=(t.max.y-d.y)*h):(s=(t.max.y-d.y)*h,r=(t.min.y-d.y)*h),i>r||s>n||((s>i||isNaN(i))&&(i=s),(r<n||isNaN(n))&&(n=r),u>=0?(o=(t.min.z-d.z)*u,c=(t.max.z-d.z)*u):(o=(t.max.z-d.z)*u,c=(t.min.z-d.z)*u),i>c||o>n)||((o>i||i!==i)&&(i=o),(c<n||n!==n)&&(n=c),n<0)?null:this.at(i>=0?i:n,e)}intersectsBox(t){return this.intersectBox(t,Es)!==null}intersectTriangle(t,e,i,n,s){jh.subVectors(e,t),kc.subVectors(i,t),Qh.crossVectors(jh,kc);let r=this.direction.dot(Qh),o;if(r>0){if(n)return null;o=1}else if(r<0)o=-1,r=-r;else return null;$s.subVectors(this.origin,t);const c=o*this.direction.dot(kc.crossVectors($s,kc));if(c<0)return null;const l=o*this.direction.dot(jh.cross($s));if(l<0||c+l>r)return null;const h=-o*$s.dot(Qh);return h<0?null:this.at(h/r,s)}applyMatrix4(t){return this.origin.applyMatrix4(t),this.direction.transformDirection(t),this}equals(t){return t.origin.equals(this.origin)&&t.direction.equals(this.direction)}clone(){return new this.constructor().copy(this)}}class _n extends zs{constructor(t){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new st(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 Us,this.combine=T0,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapRotation.copy(t.envMapRotation),this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.fog=t.fog,this}}const Mp=new te,_r=new fc,zc=new ks,xp=new R,Bc=new R,Hc=new R,Gc=new R,tu=new R,Vc=new R,yp=new R,Wc=new R;class bt extends Ge{constructor(t=new se,e=new _n){super(),this.isMesh=!0,this.type="Mesh",this.geometry=t,this.material=e,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.count=1,this.updateMorphTargets()}copy(t,e){return super.copy(t,e),t.morphTargetInfluences!==void 0&&(this.morphTargetInfluences=t.morphTargetInfluences.slice()),t.morphTargetDictionary!==void 0&&(this.morphTargetDictionary=Object.assign({},t.morphTargetDictionary)),this.material=Array.isArray(t.material)?t.material.slice():t.material,this.geometry=t.geometry,this}updateMorphTargets(){const e=this.geometry.morphAttributes,i=Object.keys(e);if(i.length>0){const n=e[i[0]];if(n!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let s=0,r=n.length;s<r;s++){const o=n[s].name||String(s);this.morphTargetInfluences.push(0),this.morphTargetDictionary[o]=s}}}}getVertexPosition(t,e){const i=this.geometry,n=i.attributes.position,s=i.morphAttributes.position,r=i.morphTargetsRelative;e.fromBufferAttribute(n,t);const o=this.morphTargetInfluences;if(s&&o){Vc.set(0,0,0);for(let c=0,l=s.length;c<l;c++){const h=o[c],u=s[c];h!==0&&(tu.fromBufferAttribute(u,t),r?Vc.addScaledVector(tu,h):Vc.addScaledVector(tu.sub(e),h))}e.add(Vc)}return e}raycast(t,e){const i=this.geometry,n=this.material,s=this.matrixWorld;n!==void 0&&(i.boundingSphere===null&&i.computeBoundingSphere(),zc.copy(i.boundingSphere),zc.applyMatrix4(s),_r.copy(t.ray).recast(t.near),!(zc.containsPoint(_r.origin)===!1&&(_r.intersectSphere(zc,xp)===null||_r.origin.distanceToSquared(xp)>(t.far-t.near)**2))&&(Mp.copy(s).invert(),_r.copy(t.ray).applyMatrix4(Mp),!(i.boundingBox!==null&&_r.intersectsBox(i.boundingBox)===!1)&&this._computeIntersections(t,e,_r)))}_computeIntersections(t,e,i){let n;const s=this.geometry,r=this.material,o=s.index,c=s.attributes.position,l=s.attributes.uv,h=s.attributes.uv1,u=s.attributes.normal,d=s.groups,f=s.drawRange;if(o!==null)if(Array.isArray(r))for(let p=0,v=d.length;p<v;p++){const m=d[p],g=r[m.materialIndex],S=Math.max(m.start,f.start),x=Math.min(o.count,Math.min(m.start+m.count,f.start+f.count));for(let M=S,b=x;M<b;M+=3){const w=o.getX(M),T=o.getX(M+1),y=o.getX(M+2);n=Xc(this,g,t,i,l,h,u,w,T,y),n&&(n.faceIndex=Math.floor(M/3),n.face.materialIndex=m.materialIndex,e.push(n))}}else{const p=Math.max(0,f.start),v=Math.min(o.count,f.start+f.count);for(let m=p,g=v;m<g;m+=3){const S=o.getX(m),x=o.getX(m+1),M=o.getX(m+2);n=Xc(this,r,t,i,l,h,u,S,x,M),n&&(n.faceIndex=Math.floor(m/3),e.push(n))}}else if(c!==void 0)if(Array.isArray(r))for(let p=0,v=d.length;p<v;p++){const m=d[p],g=r[m.materialIndex],S=Math.max(m.start,f.start),x=Math.min(c.count,Math.min(m.start+m.count,f.start+f.count));for(let M=S,b=x;M<b;M+=3){const w=M,T=M+1,y=M+2;n=Xc(this,g,t,i,l,h,u,w,T,y),n&&(n.faceIndex=Math.floor(M/3),n.face.materialIndex=m.materialIndex,e.push(n))}}else{const p=Math.max(0,f.start),v=Math.min(c.count,f.start+f.count);for(let m=p,g=v;m<g;m+=3){const S=m,x=m+1,M=m+2;n=Xc(this,r,t,i,l,h,u,S,x,M),n&&(n.faceIndex=Math.floor(m/3),e.push(n))}}}}function cx(a,t,e,i,n,s,r,o){let c;if(t.side===qe?c=i.intersectTriangle(r,s,n,!0,o):c=i.intersectTriangle(n,s,r,t.side===pr,o),c===null)return null;Wc.copy(o),Wc.applyMatrix4(a.matrixWorld);const l=e.ray.origin.distanceTo(Wc);return l<e.near||l>e.far?null:{distance:l,point:Wc.clone(),object:a}}function Xc(a,t,e,i,n,s,r,o,c,l){a.getVertexPosition(o,Bc),a.getVertexPosition(c,Hc),a.getVertexPosition(l,Gc);const h=cx(a,t,e,i,Bc,Hc,Gc,yp);if(h){const u=new R;Pn.getBarycoord(yp,Bc,Hc,Gc,u),n&&(h.uv=Pn.getInterpolatedAttribute(n,o,c,l,u,new Mt)),s&&(h.uv1=Pn.getInterpolatedAttribute(s,o,c,l,u,new Mt)),r&&(h.normal=Pn.getInterpolatedAttribute(r,o,c,l,u,new R),h.normal.dot(i.direction)>0&&h.normal.multiplyScalar(-1));const d={a:o,b:c,c:l,normal:new R,materialIndex:0};Pn.getNormal(Bc,Hc,Gc,d.normal),h.face=d,h.barycoord=u}return h}const vo=new ae,Sp=new ae,_p=new ae,lx=new ae,bp=new te,Yc=new R,eu=new ks,wp=new te,iu=new fc;class KA extends bt{constructor(t,e){super(t,e),this.isSkinnedMesh=!0,this.type="SkinnedMesh",this.bindMode=tp,this.bindMatrix=new te,this.bindMatrixInverse=new te,this.boundingBox=null,this.boundingSphere=null}computeBoundingBox(){const t=this.geometry;this.boundingBox===null&&(this.boundingBox=new ki),this.boundingBox.makeEmpty();const e=t.getAttribute("position");for(let i=0;i<e.count;i++)this.getVertexPosition(i,Yc),this.boundingBox.expandByPoint(Yc)}computeBoundingSphere(){const t=this.geometry;this.boundingSphere===null&&(this.boundingSphere=new ks),this.boundingSphere.makeEmpty();const e=t.getAttribute("position");for(let i=0;i<e.count;i++)this.getVertexPosition(i,Yc),this.boundingSphere.expandByPoint(Yc)}copy(t,e){return super.copy(t,e),this.bindMode=t.bindMode,this.bindMatrix.copy(t.bindMatrix),this.bindMatrixInverse.copy(t.bindMatrixInverse),this.skeleton=t.skeleton,t.boundingBox!==null&&(this.boundingBox=t.boundingBox.clone()),t.boundingSphere!==null&&(this.boundingSphere=t.boundingSphere.clone()),this}raycast(t,e){const i=this.material,n=this.matrixWorld;i!==void 0&&(this.boundingSphere===null&&this.computeBoundingSphere(),eu.copy(this.boundingSphere),eu.applyMatrix4(n),t.ray.intersectsSphere(eu)!==!1&&(wp.copy(n).invert(),iu.copy(t.ray).applyMatrix4(wp),!(this.boundingBox!==null&&iu.intersectsBox(this.boundingBox)===!1)&&this._computeIntersections(t,e,iu)))}getVertexPosition(t,e){return super.getVertexPosition(t,e),this.applyBoneTransform(t,e),e}bind(t,e){this.skeleton=t,e===void 0&&(this.updateMatrixWorld(!0),this.skeleton.calculateInverses(),e=this.matrixWorld),this.bindMatrix.copy(e),this.bindMatrixInverse.copy(e).invert()}pose(){this.skeleton.pose()}normalizeSkinWeights(){const t=new ae,e=this.geometry.attributes.skinWeight;for(let i=0,n=e.count;i<n;i++){t.fromBufferAttribute(e,i);const s=1/t.manhattanLength();s!==1/0?t.multiplyScalar(s):t.set(1,0,0,0),e.setXYZW(i,t.x,t.y,t.z,t.w)}}updateMatrixWorld(t){super.updateMatrixWorld(t),this.bindMode===tp?this.bindMatrixInverse.copy(this.matrixWorld).invert():this.bindMode===lM?this.bindMatrixInverse.copy(this.bindMatrix).invert():It("SkinnedMesh: Unrecognized bindMode: "+this.bindMode)}applyBoneTransform(t,e){const i=this.skeleton,n=this.geometry;Sp.fromBufferAttribute(n.attributes.skinIndex,t),_p.fromBufferAttribute(n.attributes.skinWeight,t),e.isVector4?(vo.copy(e),e.set(0,0,0,0)):(vo.set(...e,1),e.set(0,0,0)),vo.applyMatrix4(this.bindMatrix);for(let s=0;s<4;s++){const r=_p.getComponent(s);if(r!==0){const o=Sp.getComponent(s);bp.multiplyMatrices(i.bones[o].matrixWorld,i.boneInverses[o]),e.addScaledVector(lx.copy(vo).applyMatrix4(bp),r)}}return e.isVector4&&(e.w=vo.w),e.applyMatrix4(this.bindMatrixInverse)}}class hx extends Ge{constructor(){super(),this.isBone=!0,this.type="Bone"}}class Mr extends Ei{constructor(t=null,e=1,i=1,n,s,r,o,c,l=Ce,h=Ce,u,d){super(null,r,o,c,l,h,n,s,u,d),this.isDataTexture=!0,this.image={data:t,width:e,height:i},this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}const Ep=new te,ux=new te;class y1{constructor(t=[],e=[]){this.uuid=Kn(),this.bones=t.slice(0),this.boneInverses=e,this.boneMatrices=null,this.boneTexture=null,this.init()}init(){const t=this.bones,e=this.boneInverses;if(this.boneMatrices=new Float32Array(t.length*16),e.length===0)this.calculateInverses();else if(t.length!==e.length){It("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 te)}}calculateInverses(){this.boneInverses.length=0;for(let t=0,e=this.bones.length;t<e;t++){const i=new te;this.bones[t]&&i.copy(this.bones[t].matrixWorld).invert(),this.boneInverses.push(i)}}pose(){for(let t=0,e=this.bones.length;t<e;t++){const i=this.bones[t];i&&i.matrixWorld.copy(this.boneInverses[t]).invert()}for(let t=0,e=this.bones.length;t<e;t++){const i=this.bones[t];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 t=this.bones,e=this.boneInverses,i=this.boneMatrices,n=this.boneTexture;for(let s=0,r=t.length;s<r;s++){const o=t[s]?t[s].matrixWorld:ux;Ep.multiplyMatrices(o,e[s]),Ep.toArray(i,s*16)}n!==null&&(n.needsUpdate=!0)}clone(){return new y1(this.bones,this.boneInverses)}computeBoneTexture(){let t=Math.sqrt(this.bones.length*4);t=Math.ceil(t/4)*4,t=Math.max(t,4);const e=new Float32Array(t*t*4);e.set(this.boneMatrices);const i=new Mr(e,t,t,Di,Ui);return i.needsUpdate=!0,this.boneMatrices=e,this.boneTexture=i,this}getBoneByName(t){for(let e=0,i=this.bones.length;e<i;e++){const n=this.bones[e];if(n.name===t)return n}}dispose(){this.boneTexture!==null&&(this.boneTexture.dispose(),this.boneTexture=null)}fromJSON(t,e){this.uuid=t.uuid;for(let i=0,n=t.bones.length;i<n;i++){const s=t.bones[i];let r=e[s];r===void 0&&(It("Skeleton: No bone found with UUID:",s),r=new hx),this.bones.push(r),this.boneInverses.push(new te().fromArray(t.boneInverses[i]))}return this.init(),this}toJSON(){const t={metadata:{version:4.7,type:"Skeleton",generator:"Skeleton.toJSON"},bones:[],boneInverses:[]};t.uuid=this.uuid;const e=this.bones,i=this.boneInverses;for(let n=0,s=e.length;n<s;n++){const r=e[n];t.bones.push(r.uuid);const o=i[n];t.boneInverses.push(o.toArray())}return t}}class Ap extends Jt{constructor(t,e,i,n=1){super(t,e,i),this.isInstancedBufferAttribute=!0,this.meshPerAttribute=n}copy(t){return super.copy(t),this.meshPerAttribute=t.meshPerAttribute,this}toJSON(){const t=super.toJSON();return t.meshPerAttribute=this.meshPerAttribute,t.isInstancedBufferAttribute=!0,t}}const ma=new te,Tp=new te,qc=[],Rp=new ki,dx=new te,Mo=new bt,xo=new ks;class ZA extends bt{constructor(t,e,i){super(t,e),this.isInstancedMesh=!0,this.instanceMatrix=new Ap(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,dx)}computeBoundingBox(){const t=this.geometry,e=this.count;this.boundingBox===null&&(this.boundingBox=new ki),t.boundingBox===null&&t.computeBoundingBox(),this.boundingBox.makeEmpty();for(let i=0;i<e;i++)this.getMatrixAt(i,ma),Rp.copy(t.boundingBox).applyMatrix4(ma),this.boundingBox.union(Rp)}computeBoundingSphere(){const t=this.geometry,e=this.count;this.boundingSphere===null&&(this.boundingSphere=new ks),t.boundingSphere===null&&t.computeBoundingSphere(),this.boundingSphere.makeEmpty();for(let i=0;i<e;i++)this.getMatrixAt(i,ma),xo.copy(t.boundingSphere).applyMatrix4(ma),this.boundingSphere.union(xo)}copy(t,e){return super.copy(t,e),this.instanceMatrix.copy(t.instanceMatrix),t.morphTexture!==null&&(this.morphTexture=t.morphTexture.clone()),t.instanceColor!==null&&(this.instanceColor=t.instanceColor.clone()),this.count=t.count,t.boundingBox!==null&&(this.boundingBox=t.boundingBox.clone()),t.boundingSphere!==null&&(this.boundingSphere=t.boundingSphere.clone()),this}getColorAt(t,e){return this.instanceColor===null?e.setRGB(1,1,1):e.fromArray(this.instanceColor.array,t*3)}getMatrixAt(t,e){return e.fromArray(this.instanceMatrix.array,t*16)}getMorphAt(t,e){const i=e.morphTargetInfluences,n=this.morphTexture.source.data.data,s=i.length+1,r=t*s+1;for(let o=0;o<i.length;o++)i[o]=n[r+o]}raycast(t,e){const i=this.matrixWorld,n=this.count;if(Mo.geometry=this.geometry,Mo.material=this.material,Mo.material!==void 0&&(this.boundingSphere===null&&this.computeBoundingSphere(),xo.copy(this.boundingSphere),xo.applyMatrix4(i),t.ray.intersectsSphere(xo)!==!1))for(let s=0;s<n;s++){this.getMatrixAt(s,ma),Tp.multiplyMatrices(i,ma),Mo.matrixWorld=Tp,Mo.raycast(t,qc);for(let r=0,o=qc.length;r<o;r++){const c=qc[r];c.instanceId=s,c.object=this,e.push(c)}qc.length=0}}setColorAt(t,e){return this.instanceColor===null&&(this.instanceColor=new Ap(new Float32Array(this.instanceMatrix.count*3).fill(1),3)),e.toArray(this.instanceColor.array,t*3),this}setMatrixAt(t,e){return e.toArray(this.instanceMatrix.array,t*16),this}setMorphAt(t,e){const i=e.morphTargetInfluences,n=i.length+1;this.morphTexture===null&&(this.morphTexture=new Mr(new Float32Array(n*this.count),n,this.count,dh,Ui));const s=this.morphTexture.source.data.data;let r=0;for(let l=0;l<i.length;l++)r+=i[l];const o=this.geometry.morphTargetsRelative?1:1-r,c=n*t;return s[c]=o,s.set(i,c+1),this}updateMorphTargets(){}dispose(){this.dispatchEvent({type:"dispose"}),this.morphTexture!==null&&(this.morphTexture.dispose(),this.morphTexture=null)}}const nu=new R,fx=new R,px=new $t;class er{constructor(t=new R(1,0,0),e=0){this.isPlane=!0,this.normal=t,this.constant=e}set(t,e){return this.normal.copy(t),this.constant=e,this}setComponents(t,e,i,n){return this.normal.set(t,e,i),this.constant=n,this}setFromNormalAndCoplanarPoint(t,e){return this.normal.copy(t),this.constant=-e.dot(this.normal),this}setFromCoplanarPoints(t,e,i){const n=nu.subVectors(i,e).cross(fx.subVectors(t,e)).normalize();return this.setFromNormalAndCoplanarPoint(n,t),this}copy(t){return this.normal.copy(t.normal),this.constant=t.constant,this}normalize(){const t=1/this.normal.length();return this.normal.multiplyScalar(t),this.constant*=t,this}negate(){return this.constant*=-1,this.normal.negate(),this}distanceToPoint(t){return this.normal.dot(t)+this.constant}distanceToSphere(t){return this.distanceToPoint(t.center)-t.radius}projectPoint(t,e){return e.copy(t).addScaledVector(this.normal,-this.distanceToPoint(t))}intersectLine(t,e,i=!0){const n=t.delta(nu),s=this.normal.dot(n);if(s===0)return this.distanceToPoint(t.start)===0?e.copy(t.start):null;const r=-(t.start.dot(this.normal)+this.constant)/s;return i===!0&&(r<0||r>1)?null:e.copy(t.start).addScaledVector(n,r)}intersectsLine(t){const e=this.distanceToPoint(t.start),i=this.distanceToPoint(t.end);return e<0&&i>0||i<0&&e>0}intersectsBox(t){return t.intersectsPlane(this)}intersectsSphere(t){return t.intersectsPlane(this)}coplanarPoint(t){return t.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(t,e){const i=e||px.getNormalMatrix(t),n=this.coplanarPoint(nu).applyMatrix4(t),s=this.normal.applyMatrix3(i).normalize();return this.constant=-n.dot(s),this}translate(t){return this.constant-=t.dot(this.normal),this}equals(t){return t.normal.equals(this.normal)&&t.constant===this.constant}clone(){return new this.constructor().copy(this)}}const br=new ks,mx=new Mt(.5,.5),$c=new R;class G0{constructor(t=new er,e=new er,i=new er,n=new er,s=new er,r=new er){this.planes=[t,e,i,n,s,r]}set(t,e,i,n,s,r){const o=this.planes;return o[0].copy(t),o[1].copy(e),o[2].copy(i),o[3].copy(n),o[4].copy(s),o[5].copy(r),this}copy(t){const e=this.planes;for(let i=0;i<6;i++)e[i].copy(t.planes[i]);return this}setFromProjectionMatrix(t,e=ms,i=!1){const n=this.planes,s=t.elements,r=s[0],o=s[1],c=s[2],l=s[3],h=s[4],u=s[5],d=s[6],f=s[7],p=s[8],v=s[9],m=s[10],g=s[11],S=s[12],x=s[13],M=s[14],b=s[15];if(n[0].setComponents(l-r,f-h,g-p,b-S).normalize(),n[1].setComponents(l+r,f+h,g+p,b+S).normalize(),n[2].setComponents(l+o,f+u,g+v,b+x).normalize(),n[3].setComponents(l-o,f-u,g-v,b-x).normalize(),i)n[4].setComponents(c,d,m,M).normalize(),n[5].setComponents(l-c,f-d,g-m,b-M).normalize();else if(n[4].setComponents(l-c,f-d,g-m,b-M).normalize(),e===ms)n[5].setComponents(l+c,f+d,g+m,b+M).normalize();else if(e===oc)n[5].setComponents(c,d,m,M).normalize();else throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: "+e);return this}intersectsObject(t){if(t.boundingSphere!==void 0)t.boundingSphere===null&&t.computeBoundingSphere(),br.copy(t.boundingSphere).applyMatrix4(t.matrixWorld);else{const e=t.geometry;e.boundingSphere===null&&e.computeBoundingSphere(),br.copy(e.boundingSphere).applyMatrix4(t.matrixWorld)}return this.intersectsSphere(br)}intersectsSprite(t){br.center.set(0,0,0);const e=mx.distanceTo(t.center);return br.radius=.7071067811865476+e,br.applyMatrix4(t.matrixWorld),this.intersectsSphere(br)}intersectsSphere(t){const e=this.planes,i=t.center,n=-t.radius;for(let s=0;s<6;s++)if(e[s].distanceToPoint(i)<n)return!1;return!0}intersectsBox(t){const e=this.planes;for(let i=0;i<6;i++){const n=e[i];if($c.x=n.normal.x>0?t.max.x:t.min.x,$c.y=n.normal.y>0?t.max.y:t.min.y,$c.z=n.normal.z>0?t.max.z:t.min.z,n.distanceToPoint($c)<0)return!1}return!0}containsPoint(t){const e=this.planes;for(let i=0;i<6;i++)if(e[i].distanceToPoint(t)<0)return!1;return!0}clone(){return new this.constructor().copy(this)}}class gx extends zs{constructor(t){super(),this.isLineBasicMaterial=!0,this.type="LineBasicMaterial",this.color=new st(16777215),this.map=null,this.linewidth=1,this.linecap="round",this.linejoin="round",this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.linewidth=t.linewidth,this.linecap=t.linecap,this.linejoin=t.linejoin,this.fog=t.fog,this}}const $l=new R,Kl=new R,Dp=new te,yo=new fc,Kc=new ks,su=new R,Ip=new R;class S1 extends Ge{constructor(t=new se,e=new gx){super(),this.isLine=!0,this.type="Line",this.geometry=t,this.material=e,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.updateMorphTargets()}copy(t,e){return super.copy(t,e),this.material=Array.isArray(t.material)?t.material.slice():t.material,this.geometry=t.geometry,this}computeLineDistances(){const t=this.geometry;if(t.index===null){const e=t.attributes.position,i=[0];for(let n=1,s=e.count;n<s;n++)$l.fromBufferAttribute(e,n-1),Kl.fromBufferAttribute(e,n),i[n]=i[n-1],i[n]+=$l.distanceTo(Kl);t.setAttribute("lineDistance",new ue(i,1))}else It("Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.");return this}raycast(t,e){const i=this.geometry,n=this.matrixWorld,s=t.params.Line.threshold,r=i.drawRange;if(i.boundingSphere===null&&i.computeBoundingSphere(),Kc.copy(i.boundingSphere),Kc.applyMatrix4(n),Kc.radius+=s,t.ray.intersectsSphere(Kc)===!1)return;Dp.copy(n).invert(),yo.copy(t.ray).applyMatrix4(Dp);const o=s/((this.scale.x+this.scale.y+this.scale.z)/3),c=o*o,l=this.isLineSegments?2:1,h=i.index,d=i.attributes.position;if(h!==null){const f=Math.max(0,r.start),p=Math.min(h.count,r.start+r.count);for(let v=f,m=p-1;v<m;v+=l){const g=h.getX(v),S=h.getX(v+1),x=Zc(this,t,yo,c,g,S,v);x&&e.push(x)}if(this.isLineLoop){const v=h.getX(p-1),m=h.getX(f),g=Zc(this,t,yo,c,v,m,p-1);g&&e.push(g)}}else{const f=Math.max(0,r.start),p=Math.min(d.count,r.start+r.count);for(let v=f,m=p-1;v<m;v+=l){const g=Zc(this,t,yo,c,v,v+1,v);g&&e.push(g)}if(this.isLineLoop){const v=Zc(this,t,yo,c,p-1,f,p-1);v&&e.push(v)}}}updateMorphTargets(){const e=this.geometry.morphAttributes,i=Object.keys(e);if(i.length>0){const n=e[i[0]];if(n!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let s=0,r=n.length;s<r;s++){const o=n[s].name||String(s);this.morphTargetInfluences.push(0),this.morphTargetDictionary[o]=s}}}}}function Zc(a,t,e,i,n,s,r){const o=a.geometry.attributes.position;if($l.fromBufferAttribute(o,n),Kl.fromBufferAttribute(o,s),e.distanceSqToSegment($l,Kl,su,Ip)>i)return;su.applyMatrix4(a.matrixWorld);const l=t.ray.origin.distanceTo(su);if(!(l<t.near||l>t.far))return{distance:l,point:Ip.clone().applyMatrix4(a.matrixWorld),index:r,face:null,faceIndex:null,barycoord:null,object:a}}const Cp=new R,Pp=new R;class JA extends S1{constructor(t,e){super(t,e),this.isLineSegments=!0,this.type="LineSegments"}computeLineDistances(){const t=this.geometry;if(t.index===null){const e=t.attributes.position,i=[];for(let n=0,s=e.count;n<s;n+=2)Cp.fromBufferAttribute(e,n),Pp.fromBufferAttribute(e,n+1),i[n]=n===0?0:i[n-1],i[n+1]=i[n]+Cp.distanceTo(Pp);t.setAttribute("lineDistance",new ue(i,1))}else It("LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.");return this}}class jA extends S1{constructor(t,e){super(t,e),this.isLineLoop=!0,this.type="LineLoop"}}class Hd extends zs{constructor(t){super(),this.isPointsMaterial=!0,this.type="PointsMaterial",this.color=new st(16777215),this.map=null,this.alphaMap=null,this.size=1,this.sizeAttenuation=!0,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.alphaMap=t.alphaMap,this.size=t.size,this.sizeAttenuation=t.sizeAttenuation,this.fog=t.fog,this}}const Lp=new te,Gd=new fc,Jc=new ks,jc=new R;class mn extends Ge{constructor(t=new se,e=new Hd){super(),this.isPoints=!0,this.type="Points",this.geometry=t,this.material=e,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.updateMorphTargets()}copy(t,e){return super.copy(t,e),this.material=Array.isArray(t.material)?t.material.slice():t.material,this.geometry=t.geometry,this}raycast(t,e){const i=this.geometry,n=this.matrixWorld,s=t.params.Points.threshold,r=i.drawRange;if(i.boundingSphere===null&&i.computeBoundingSphere(),Jc.copy(i.boundingSphere),Jc.applyMatrix4(n),Jc.radius+=s,t.ray.intersectsSphere(Jc)===!1)return;Lp.copy(n).invert(),Gd.copy(t.ray).applyMatrix4(Lp);const o=s/((this.scale.x+this.scale.y+this.scale.z)/3),c=o*o,l=i.index,u=i.attributes.position;if(l!==null){const d=Math.max(0,r.start),f=Math.min(l.count,r.start+r.count);for(let p=d,v=f;p<v;p++){const m=l.getX(p);jc.fromBufferAttribute(u,m),Op(jc,m,c,n,t,e,this)}}else{const d=Math.max(0,r.start),f=Math.min(u.count,r.start+r.count);for(let p=d,v=f;p<v;p++)jc.fromBufferAttribute(u,p),Op(jc,p,c,n,t,e,this)}}updateMorphTargets(){const e=this.geometry.morphAttributes,i=Object.keys(e);if(i.length>0){const n=e[i[0]];if(n!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let s=0,r=n.length;s<r;s++){const o=n[s].name||String(s);this.morphTargetInfluences.push(0),this.morphTargetDictionary[o]=s}}}}}function Op(a,t,e,i,n,s,r){const o=Gd.distanceSqToPoint(a);if(o<e){const c=new R;Gd.closestPointToPoint(a,c),c.applyMatrix4(i);const l=n.ray.origin.distanceTo(c);if(l<n.near||l>n.far)return;s.push({distance:l,distanceToRay:Math.sqrt(o),point:c,index:t,face:null,faceIndex:null,barycoord:null,object:r})}}class _1 extends Ei{constructor(t=[],e=Xr,i,n,s,r,o,c,l,h){super(t,e,i,n,s,r,o,c,l,h),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(t){this.image=t}}class Bs extends Ei{constructor(t,e,i,n,s,r,o,c,l){super(t,e,i,n,s,r,o,c,l),this.isCanvasTexture=!0,this.needsUpdate=!0}}class mr extends Ei{constructor(t,e,i=Nn,n,s,r,o=Ce,c=Ce,l,h=Fs,u=1){if(h!==Fs&&h!==Or)throw new Error("THREE.DepthTexture: format must be either THREE.DepthFormat or THREE.DepthStencilFormat");const d={width:t,height:e,depth:u};super(d,n,s,r,o,c,h,i,l),this.isDepthTexture=!0,this.flipY=!1,this.generateMipmaps=!1,this.compareFunction=null}copy(t){return super.copy(t),this.source=new k0(Object.assign({},t.image)),this.compareFunction=t.compareFunction,this}toJSON(t){const e=super.toJSON(t);return this.compareFunction!==null&&(e.compareFunction=this.compareFunction),e}}class vx extends mr{constructor(t,e=Nn,i=Xr,n,s,r=Ce,o=Ce,c,l=Fs){const h={width:t,height:t,depth:1},u=[h,h,h,h,h,h];super(t,t,e,i,n,s,r,o,c,l),this.image=u,this.isCubeDepthTexture=!0,this.isCubeTexture=!0}get images(){return this.image}set images(t){this.image=t}}class b1 extends Ei{constructor(t=null){super(),this.sourceTexture=t,this.isExternalTexture=!0}copy(t){return super.copy(t),this.sourceTexture=t.sourceTexture,this}}class Ki extends se{constructor(t=1,e=1,i=1,n=1,s=1,r=1){super(),this.type="BoxGeometry",this.parameters={width:t,height:e,depth:i,widthSegments:n,heightSegments:s,depthSegments:r};const o=this;n=Math.floor(n),s=Math.floor(s),r=Math.floor(r);const c=[],l=[],h=[],u=[];let d=0,f=0;p("z","y","x",-1,-1,i,e,t,r,s,0),p("z","y","x",1,-1,i,e,-t,r,s,1),p("x","z","y",1,1,t,i,e,n,r,2),p("x","z","y",1,-1,t,i,-e,n,r,3),p("x","y","z",1,-1,t,e,i,n,s,4),p("x","y","z",-1,-1,t,e,-i,n,s,5),this.setIndex(c),this.setAttribute("position",new ue(l,3)),this.setAttribute("normal",new ue(h,3)),this.setAttribute("uv",new ue(u,2));function p(v,m,g,S,x,M,b,w,T,y,A){const C=M/T,I=b/y,P=M/2,V=b/2,X=w/2,L=T+1,B=y+1;let k=0,$=0;const tt=new R;for(let J=0;J<B;J++){const it=J*I-V;for(let at=0;at<L;at++){const Xt=at*C-P;tt[v]=Xt*S,tt[m]=it*x,tt[g]=X,l.push(tt.x,tt.y,tt.z),tt[v]=0,tt[m]=0,tt[g]=w>0?1:-1,h.push(tt.x,tt.y,tt.z),u.push(at/T),u.push(1-J/y),k+=1}}for(let J=0;J<y;J++)for(let it=0;it<T;it++){const at=d+it+L*J,Xt=d+it+L*(J+1),ee=d+(it+1)+L*(J+1),Kt=d+(it+1)+L*J;c.push(at,Xt,Kt),c.push(Xt,ee,Kt),$+=6}o.addGroup(f,$,A),f+=$,d+=k}}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new Ki(t.width,t.height,t.depth,t.widthSegments,t.heightSegments,t.depthSegments)}}class V0 extends se{constructor(t=1,e=32,i=0,n=Math.PI*2){super(),this.type="CircleGeometry",this.parameters={radius:t,segments:e,thetaStart:i,thetaLength:n},e=Math.max(3,e);const s=[],r=[],o=[],c=[],l=new R,h=new Mt;r.push(0,0,0),o.push(0,0,1),c.push(.5,.5);for(let u=0,d=3;u<=e;u++,d+=3){const f=i+u/e*n;l.x=t*Math.cos(f),l.y=t*Math.sin(f),r.push(l.x,l.y,l.z),o.push(0,0,1),h.x=(r[d]/t+1)/2,h.y=(r[d+1]/t+1)/2,c.push(h.x,h.y)}for(let u=1;u<=e;u++)s.push(u,u+1,0);this.setIndex(s),this.setAttribute("position",new ue(r,3)),this.setAttribute("normal",new ue(o,3)),this.setAttribute("uv",new ue(c,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new V0(t.radius,t.segments,t.thetaStart,t.thetaLength)}}class Fn extends se{constructor(t=1,e=1,i=1,n=32,s=1,r=!1,o=0,c=Math.PI*2){super(),this.type="CylinderGeometry",this.parameters={radiusTop:t,radiusBottom:e,height:i,radialSegments:n,heightSegments:s,openEnded:r,thetaStart:o,thetaLength:c};const l=this;n=Math.floor(n),s=Math.floor(s);const h=[],u=[],d=[],f=[];let p=0;const v=[],m=i/2;let g=0;S(),r===!1&&(t>0&&x(!0),e>0&&x(!1)),this.setIndex(h),this.setAttribute("position",new ue(u,3)),this.setAttribute("normal",new ue(d,3)),this.setAttribute("uv",new ue(f,2));function S(){const M=new R,b=new R;let w=0;const T=(e-t)/i;for(let y=0;y<=s;y++){const A=[],C=y/s,I=C*(e-t)+t;for(let P=0;P<=n;P++){const V=P/n,X=V*c+o,L=Math.sin(X),B=Math.cos(X);b.x=I*L,b.y=-C*i+m,b.z=I*B,u.push(b.x,b.y,b.z),M.set(L,T,B).normalize(),d.push(M.x,M.y,M.z),f.push(V,1-C),A.push(p++)}v.push(A)}for(let y=0;y<n;y++)for(let A=0;A<s;A++){const C=v[A][y],I=v[A+1][y],P=v[A+1][y+1],V=v[A][y+1];(t>0||A!==0)&&(h.push(C,I,V),w+=3),(e>0||A!==s-1)&&(h.push(I,P,V),w+=3)}l.addGroup(g,w,0),g+=w}function x(M){const b=p,w=new Mt,T=new R;let y=0;const A=M===!0?t:e,C=M===!0?1:-1;for(let P=1;P<=n;P++)u.push(0,m*C,0),d.push(0,C,0),f.push(.5,.5),p++;const I=p;for(let P=0;P<=n;P++){const X=P/n*c+o,L=Math.cos(X),B=Math.sin(X);T.x=A*B,T.y=m*C,T.z=A*L,u.push(T.x,T.y,T.z),d.push(0,C,0),w.x=L*.5+.5,w.y=B*.5*C+.5,f.push(w.x,w.y),p++}for(let P=0;P<n;P++){const V=b+P,X=I+P;M===!0?h.push(X,X+1,V):h.push(X+1,X,V),y+=3}l.addGroup(g,y,M===!0?1:2),g+=y}}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new Fn(t.radiusTop,t.radiusBottom,t.height,t.radialSegments,t.heightSegments,t.openEnded,t.thetaStart,t.thetaLength)}}class io extends Fn{constructor(t=1,e=1,i=32,n=1,s=!1,r=0,o=Math.PI*2){super(0,t,e,i,n,s,r,o),this.type="ConeGeometry",this.parameters={radius:t,height:e,radialSegments:i,heightSegments:n,openEnded:s,thetaStart:r,thetaLength:o}}static fromJSON(t){return new io(t.radius,t.height,t.radialSegments,t.heightSegments,t.openEnded,t.thetaStart,t.thetaLength)}}class fh extends se{constructor(t=[new Mt(0,-.5),new Mt(.5,0),new Mt(0,.5)],e=12,i=0,n=Math.PI*2){super(),this.type="LatheGeometry",this.parameters={points:t,segments:e,phiStart:i,phiLength:n},e=Math.floor(e),n=Zt(n,0,Math.PI*2);const s=[],r=[],o=[],c=[],l=[],h=1/e,u=new R,d=new Mt,f=new R,p=new R,v=new R;let m=0,g=0;for(let S=0;S<=t.length-1;S++)switch(S){case 0:m=t[S+1].x-t[S].x,g=t[S+1].y-t[S].y,f.x=g*1,f.y=-m,f.z=g*0,v.copy(f),f.normalize(),c.push(f.x,f.y,f.z);break;case t.length-1:c.push(v.x,v.y,v.z);break;default:m=t[S+1].x-t[S].x,g=t[S+1].y-t[S].y,f.x=g*1,f.y=-m,f.z=g*0,p.copy(f),f.x+=v.x,f.y+=v.y,f.z+=v.z,f.normalize(),c.push(f.x,f.y,f.z),v.copy(p)}for(let S=0;S<=e;S++){const x=i+S*h*n,M=Math.sin(x),b=Math.cos(x);for(let w=0;w<=t.length-1;w++){u.x=t[w].x*M,u.y=t[w].y,u.z=t[w].x*b,r.push(u.x,u.y,u.z),d.x=S/e,d.y=w/(t.length-1),o.push(d.x,d.y);const T=c[3*w+0]*M,y=c[3*w+1],A=c[3*w+0]*b;l.push(T,y,A)}}for(let S=0;S<e;S++)for(let x=0;x<t.length-1;x++){const M=x+S*t.length,b=M,w=M+t.length,T=M+t.length+1,y=M+1;s.push(b,w,y),s.push(T,y,w)}this.setIndex(s),this.setAttribute("position",new ue(r,3)),this.setAttribute("uv",new ue(o,2)),this.setAttribute("normal",new ue(l,3))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new fh(t.points,t.segments,t.phiStart,t.phiLength)}}class Zi extends se{constructor(t=1,e=1,i=1,n=1){super(),this.type="PlaneGeometry",this.parameters={width:t,height:e,widthSegments:i,heightSegments:n};const s=t/2,r=e/2,o=Math.floor(i),c=Math.floor(n),l=o+1,h=c+1,u=t/o,d=e/c,f=[],p=[],v=[],m=[];for(let g=0;g<h;g++){const S=g*d-r;for(let x=0;x<l;x++){const M=x*u-s;p.push(M,-S,0),v.push(0,0,1),m.push(x/o),m.push(1-g/c)}}for(let g=0;g<c;g++)for(let S=0;S<o;S++){const x=S+l*g,M=S+l*(g+1),b=S+1+l*(g+1),w=S+1+l*g;f.push(x,M,w),f.push(M,b,w)}this.setIndex(f),this.setAttribute("position",new ue(p,3)),this.setAttribute("normal",new ue(v,3)),this.setAttribute("uv",new ue(m,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new Zi(t.width,t.height,t.widthSegments,t.heightSegments)}}class di extends se{constructor(t=1,e=32,i=16,n=0,s=Math.PI*2,r=0,o=Math.PI){super(),this.type="SphereGeometry",this.parameters={radius:t,widthSegments:e,heightSegments:i,phiStart:n,phiLength:s,thetaStart:r,thetaLength:o},e=Math.max(3,Math.floor(e)),i=Math.max(2,Math.floor(i));const c=Math.min(r+o,Math.PI);let l=0;const h=[],u=new R,d=new R,f=[],p=[],v=[],m=[];for(let g=0;g<=i;g++){const S=[],x=g/i,M=r+x*o,b=t*Math.cos(M),w=Math.sqrt(t*t-b*b);let T=0;g===0&&r===0?T=.5/e:g===i&&c===Math.PI&&(T=-.5/e);for(let y=0;y<=e;y++){const A=y/e,C=n+A*s;u.x=-w*Math.cos(C),u.y=b,u.z=w*Math.sin(C),p.push(u.x,u.y,u.z),d.copy(u).normalize(),v.push(d.x,d.y,d.z),m.push(A+T,1-x),S.push(l++)}h.push(S)}for(let g=0;g<i;g++)for(let S=0;S<e;S++){const x=h[g][S+1],M=h[g][S],b=h[g+1][S],w=h[g+1][S+1];(g!==0||r>0)&&f.push(x,M,w),(g!==i-1||c<Math.PI)&&f.push(M,b,w)}this.setIndex(f),this.setAttribute("position",new ue(p,3)),this.setAttribute("normal",new ue(v,3)),this.setAttribute("uv",new ue(m,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new di(t.radius,t.widthSegments,t.heightSegments,t.phiStart,t.phiLength,t.thetaStart,t.thetaLength)}}class W0 extends se{constructor(t=1,e=.4,i=12,n=48,s=Math.PI*2,r=0,o=Math.PI*2){super(),this.type="TorusGeometry",this.parameters={radius:t,tube:e,radialSegments:i,tubularSegments:n,arc:s,thetaStart:r,thetaLength:o},i=Math.floor(i),n=Math.floor(n);const c=[],l=[],h=[],u=[],d=new R,f=new R,p=new R;for(let v=0;v<=i;v++){const m=r+v/i*o;for(let g=0;g<=n;g++){const S=g/n*s;f.x=(t+e*Math.cos(m))*Math.cos(S),f.y=(t+e*Math.cos(m))*Math.sin(S),f.z=e*Math.sin(m),l.push(f.x,f.y,f.z),d.x=t*Math.cos(S),d.y=t*Math.sin(S),p.subVectors(f,d).normalize(),h.push(p.x,p.y,p.z),u.push(g/n),u.push(v/i)}}for(let v=1;v<=i;v++)for(let m=1;m<=n;m++){const g=(n+1)*v+m-1,S=(n+1)*(v-1)+m-1,x=(n+1)*(v-1)+m,M=(n+1)*v+m;c.push(g,S,M),c.push(S,x,M)}this.setIndex(c),this.setAttribute("position",new ue(l,3)),this.setAttribute("normal",new ue(h,3)),this.setAttribute("uv",new ue(u,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new W0(t.radius,t.tube,t.radialSegments,t.tubularSegments,t.arc)}}class QA extends se{constructor(t=null){if(super(),this.type="WireframeGeometry",this.parameters={geometry:t},t!==null){const e=[],i=new Set,n=new R,s=new R;if(t.index!==null){const r=t.attributes.position,o=t.index;let c=t.groups;c.length===0&&(c=[{start:0,count:o.count,materialIndex:0}]);for(let l=0,h=c.length;l<h;++l){const u=c[l],d=u.start,f=u.count;for(let p=d,v=d+f;p<v;p+=3)for(let m=0;m<3;m++){const g=o.getX(p+m),S=o.getX(p+(m+1)%3);n.fromBufferAttribute(r,g),s.fromBufferAttribute(r,S),Np(n,s,i)===!0&&(e.push(n.x,n.y,n.z),e.push(s.x,s.y,s.z))}}}else{const r=t.attributes.position;for(let o=0,c=r.count/3;o<c;o++)for(let l=0;l<3;l++){const h=3*o+l,u=3*o+(l+1)%3;n.fromBufferAttribute(r,h),s.fromBufferAttribute(r,u),Np(n,s,i)===!0&&(e.push(n.x,n.y,n.z),e.push(s.x,s.y,s.z))}}this.setAttribute("position",new ue(e,3))}}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}}function Np(a,t,e){const i=`${a.x},${a.y},${a.z}-${t.x},${t.y},${t.z}`,n=`${t.x},${t.y},${t.z}-${a.x},${a.y},${a.z}`;return e.has(i)===!0||e.has(n)===!0?!1:(e.add(i),e.add(n),!0)}function to(a){const t={};for(const e in a){t[e]={};for(const i in a[e]){const n=a[e][i];if(Fp(n))n.isRenderTargetTexture?(It("UniformsUtils: Textures of render targets cannot be cloned via cloneUniforms() or mergeUniforms()."),t[e][i]=null):t[e][i]=n.clone();else if(Array.isArray(n))if(Fp(n[0])){const s=[];for(let r=0,o=n.length;r<o;r++)s[r]=n[r].clone();t[e][i]=s}else t[e][i]=n.slice();else t[e][i]=n}}return t}function Bi(a){const t={};for(let e=0;e<a.length;e++){const i=to(a[e]);for(const n in i)t[n]=i[n]}return t}function Fp(a){return a&&(a.isColor||a.isMatrix3||a.isMatrix4||a.isVector2||a.isVector3||a.isVector4||a.isTexture||a.isQuaternion)}function Mx(a){const t=[];for(let e=0;e<a.length;e++)t.push(a[e].clone());return t}function w1(a){const t=a.getRenderTarget();return t===null?a.outputColorSpace:t.isXRRenderTarget===!0?t.texture.colorSpace:ce.workingColorSpace}const xx={clone:to,merge:Bi};var yx=`void main() {
1416
+ */const A0="185",V2=0,Jf=1,W2=2,Ho=1,X2=2,Lo=3,pr=0,qe=1,xn=2,vs=0,dr=1,Ai=2,jf=3,Qf=4,dc=5,Dr=100,Y2=101,q2=102,$2=103,K2=104,Oo=200,ic=201,Z2=202,J2=203,td=204,nc=205,j2=206,Q2=207,tM=208,eM=209,iM=210,nM=211,sM=212,rM=213,aM=214,ed=0,id=1,nd=2,Ja=3,sd=4,rd=5,ad=6,od=7,T0=0,oM=1,cM=2,Ms=0,jg=1,Qg=2,t1=3,e1=4,i1=5,n1=6,s1=7,tp="attached",lM="detached",r1=300,Xr=301,ja=302,Dh=303,Ih=304,uh=306,sc=1e3,Ri=1001,cd=1002,Ce=1003,hM=1004,Ac=1005,le=1006,Ch=1007,Lr=1008,yn=1009,a1=1010,o1=1011,rc=1012,R0=1013,Nn=1014,Ui=1015,$e=1016,D0=1017,I0=1018,ac=1020,c1=35902,l1=35899,h1=1021,u1=1022,Di=1023,Fs=1026,Or=1027,dh=1028,C0=1029,Yr=1030,P0=1031,L0=1033,Al=33776,Tl=33777,Rl=33778,Dl=33779,ld=35840,hd=35841,ud=35842,dd=35843,fd=36196,pd=37492,md=37496,gd=37488,vd=37489,kl=37490,Md=37491,xd=37808,yd=37809,Sd=37810,_d=37811,bd=37812,wd=37813,Ed=37814,Ad=37815,Td=37816,Rd=37817,Dd=37818,Id=37819,Cd=37820,Pd=37821,Ld=36492,Od=36494,Nd=36495,Fd=36283,Ud=36284,zl=36285,kd=36286,d1=2200,uM=2201,dM=2202,Bl=2300,zd=2301,Ph=2302,ep=2303,Da=2400,Ia=2401,Hl=2402,O0=2500,fM=2501,XA=0,YA=1,qA=2,pM=3200,Gl=0,mM=1,rr="",qi="srgb",Vl="srgb-linear",Wl="linear",we="srgb",ta=7680,ip=519,gM=512,vM=513,MM=514,N0=515,xM=516,yM=517,F0=518,SM=519,Bd=35044,Xl="300 es",ms=2e3,oc=2001;function _M(a){for(let t=a.length-1;t>=0;--t)if(a[t]>=65535)return!0;return!1}function bM(a){return ArrayBuffer.isView(a)&&!(a instanceof DataView)}function cc(a){return document.createElementNS("http://www.w3.org/1999/xhtml",a)}function wM(){const a=cc("canvas");return a.style.display="block",a}const np={};function Yl(...a){const t="THREE."+a.shift();console.log(t,...a)}function f1(a){const t=a[0];if(typeof t=="string"&&t.startsWith("TSL:")){const e=a[1];e&&e.isStackTrace?a[0]+=" "+e.getLocation():a[1]='Stack trace not available. Enable "THREE.Node.captureStackTrace" to capture stack traces.'}return a}function It(...a){a=f1(a);const t="THREE."+a.shift();{const e=a[0];e&&e.isStackTrace?console.warn(e.getError(t)):console.warn(t,...a)}}function Wt(...a){a=f1(a);const t="THREE."+a.shift();{const e=a[0];e&&e.isStackTrace?console.error(e.getError(t)):console.error(t,...a)}}function Ba(...a){const t=a.join(" ");t in np||(np[t]=!0,It(...a))}function EM(a,t,e){return new Promise(function(i,n){function s(){switch(a.clientWaitSync(t,a.SYNC_FLUSH_COMMANDS_BIT,0)){case a.WAIT_FAILED:n();break;case a.TIMEOUT_EXPIRED:setTimeout(s,e);break;default:i()}}setTimeout(s,e)})}const AM={[ed]:id,[nd]:ad,[sd]:od,[Ja]:rd,[id]:ed,[ad]:nd,[od]:sd,[rd]:Ja};class vr{addEventListener(t,e){this._listeners===void 0&&(this._listeners={});const i=this._listeners;i[t]===void 0&&(i[t]=[]),i[t].indexOf(e)===-1&&i[t].push(e)}hasEventListener(t,e){const i=this._listeners;return i===void 0?!1:i[t]!==void 0&&i[t].indexOf(e)!==-1}removeEventListener(t,e){const i=this._listeners;if(i===void 0)return;const n=i[t];if(n!==void 0){const s=n.indexOf(e);s!==-1&&n.splice(s,1)}}dispatchEvent(t){const e=this._listeners;if(e===void 0)return;const i=e[t.type];if(i!==void 0){t.target=this;const n=i.slice(0);for(let s=0,r=n.length;s<r;s++)n[s].call(this,t);t.target=null}}}const Pi=["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 sp=1234567;const Go=Math.PI/180,Qa=180/Math.PI;function Kn(){const a=Math.random()*4294967295|0,t=Math.random()*4294967295|0,e=Math.random()*4294967295|0,i=Math.random()*4294967295|0;return(Pi[a&255]+Pi[a>>8&255]+Pi[a>>16&255]+Pi[a>>24&255]+"-"+Pi[t&255]+Pi[t>>8&255]+"-"+Pi[t>>16&15|64]+Pi[t>>24&255]+"-"+Pi[e&63|128]+Pi[e>>8&255]+"-"+Pi[e>>16&255]+Pi[e>>24&255]+Pi[i&255]+Pi[i>>8&255]+Pi[i>>16&255]+Pi[i>>24&255]).toLowerCase()}function Zt(a,t,e){return Math.max(t,Math.min(e,a))}function U0(a,t){return(a%t+t)%t}function TM(a,t,e,i,n){return i+(a-t)*(n-i)/(e-t)}function RM(a,t,e){return a!==t?(e-a)/(t-a):0}function Vo(a,t,e){return(1-e)*a+e*t}function DM(a,t,e,i){return Vo(a,t,1-Math.exp(-e*i))}function IM(a,t=1){return t-Math.abs(U0(a,t*2)-t)}function CM(a,t,e){return a<=t?0:a>=e?1:(a=(a-t)/(e-t),a*a*(3-2*a))}function PM(a,t,e){return a<=t?0:a>=e?1:(a=(a-t)/(e-t),a*a*a*(a*(a*6-15)+10))}function LM(a,t){return a+Math.floor(Math.random()*(t-a+1))}function OM(a,t){return a+Math.random()*(t-a)}function NM(a){return a*(.5-Math.random())}function FM(a){a!==void 0&&(sp=a);let t=sp+=1831565813;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}function UM(a){return a*Go}function kM(a){return a*Qa}function zM(a){return(a&a-1)===0&&a!==0}function BM(a){return Math.pow(2,Math.ceil(Math.log(a)/Math.LN2))}function HM(a){return Math.pow(2,Math.floor(Math.log(a)/Math.LN2))}function GM(a,t,e,i,n){const s=Math.cos,r=Math.sin,o=s(e/2),c=r(e/2),l=s((t+i)/2),h=r((t+i)/2),u=s((t-i)/2),d=r((t-i)/2),f=s((i-t)/2),p=r((i-t)/2);switch(n){case"XYX":a.set(o*h,c*u,c*d,o*l);break;case"YZY":a.set(c*d,o*h,c*u,o*l);break;case"ZXZ":a.set(c*u,c*d,o*h,o*l);break;case"XZX":a.set(o*h,c*p,c*f,o*l);break;case"YXY":a.set(c*f,o*h,c*p,o*l);break;case"ZYZ":a.set(c*p,c*f,o*h,o*l);break;default:It("MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+n)}}function qn(a,t){switch(t.constructor){case Float32Array:return a;case Uint32Array:return a/4294967295;case Uint16Array:return a/65535;case Uint8Array:return a/255;case Int32Array:return Math.max(a/2147483647,-1);case Int16Array:return Math.max(a/32767,-1);case Int8Array:return Math.max(a/127,-1);default:throw new Error("THREE.MathUtils: Invalid component type.")}}function Ee(a,t){switch(t.constructor){case Float32Array:return a;case Uint32Array:return Math.round(a*4294967295);case Uint16Array:return Math.round(a*65535);case Uint8Array:return Math.round(a*255);case Int32Array:return Math.round(a*2147483647);case Int16Array:return Math.round(a*32767);case Int8Array:return Math.round(a*127);default:throw new Error("THREE.MathUtils: Invalid component type.")}}const $A={DEG2RAD:Go,RAD2DEG:Qa,generateUUID:Kn,clamp:Zt,euclideanModulo:U0,mapLinear:TM,inverseLerp:RM,lerp:Vo,damp:DM,pingpong:IM,smoothstep:CM,smootherstep:PM,randInt:LM,randFloat:OM,randFloatSpread:NM,seededRandom:FM,degToRad:UM,radToDeg:kM,isPowerOfTwo:zM,ceilPowerOfTwo:BM,floorPowerOfTwo:HM,setQuaternionFromProperEuler:GM,normalize:Ee,denormalize:qn};class Mt{static{Mt.prototype.isVector2=!0}constructor(t=0,e=0){this.x=t,this.y=e}get width(){return this.x}set width(t){this.x=t}get height(){return this.y}set height(t){this.y=t}set(t,e){return this.x=t,this.y=e,this}setScalar(t){return this.x=t,this.y=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;default:throw new Error("THREE.Vector2: index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;default:throw new Error("THREE.Vector2: index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y)}copy(t){return this.x=t.x,this.y=t.y,this}add(t){return this.x+=t.x,this.y+=t.y,this}addScalar(t){return this.x+=t,this.y+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this}subScalar(t){return this.x-=t,this.y-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this}multiply(t){return this.x*=t.x,this.y*=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divide(t){return this.x/=t.x,this.y/=t.y,this}divideScalar(t){return this.multiplyScalar(1/t)}applyMatrix3(t){const e=this.x,i=this.y,n=t.elements;return this.x=n[0]*e+n[3]*i+n[6],this.y=n[1]*e+n[4]*i+n[7],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this}clamp(t,e){return this.x=Zt(this.x,t.x,e.x),this.y=Zt(this.y,t.y,e.y),this}clampScalar(t,e){return this.x=Zt(this.x,t,e),this.y=Zt(this.y,t,e),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Zt(i,t,e))}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(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.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(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;const i=this.dot(t)/e;return Math.acos(Zt(i,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,i=this.y-t.y;return e*e+i*i}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this}lerpVectors(t,e,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this}equals(t){return t.x===this.x&&t.y===this.y}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this}rotateAround(t,e){const i=Math.cos(e),n=Math.sin(e),s=this.x-t.x,r=this.y-t.y;return this.x=s*i-r*n+t.x,this.y=s*n+r*i+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class on{constructor(t=0,e=0,i=0,n=1){this.isQuaternion=!0,this._x=t,this._y=e,this._z=i,this._w=n}static slerpFlat(t,e,i,n,s,r,o){let c=i[n+0],l=i[n+1],h=i[n+2],u=i[n+3],d=s[r+0],f=s[r+1],p=s[r+2],v=s[r+3];if(u!==v||c!==d||l!==f||h!==p){let m=c*d+l*f+h*p+u*v;m<0&&(d=-d,f=-f,p=-p,v=-v,m=-m);let g=1-o;if(m<.9995){const S=Math.acos(m),x=Math.sin(S);g=Math.sin(g*S)/x,o=Math.sin(o*S)/x,c=c*g+d*o,l=l*g+f*o,h=h*g+p*o,u=u*g+v*o}else{c=c*g+d*o,l=l*g+f*o,h=h*g+p*o,u=u*g+v*o;const S=1/Math.sqrt(c*c+l*l+h*h+u*u);c*=S,l*=S,h*=S,u*=S}}t[e]=c,t[e+1]=l,t[e+2]=h,t[e+3]=u}static multiplyQuaternionsFlat(t,e,i,n,s,r){const o=i[n],c=i[n+1],l=i[n+2],h=i[n+3],u=s[r],d=s[r+1],f=s[r+2],p=s[r+3];return t[e]=o*p+h*u+c*f-l*d,t[e+1]=c*p+h*d+l*u-o*f,t[e+2]=l*p+h*f+o*d-c*u,t[e+3]=h*p-o*u-c*d-l*f,t}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get w(){return this._w}set w(t){this._w=t,this._onChangeCallback()}set(t,e,i,n){return this._x=t,this._y=e,this._z=i,this._w=n,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback(),this}setFromEuler(t,e=!0){const i=t._x,n=t._y,s=t._z,r=t._order,o=Math.cos,c=Math.sin,l=o(i/2),h=o(n/2),u=o(s/2),d=c(i/2),f=c(n/2),p=c(s/2);switch(r){case"XYZ":this._x=d*h*u+l*f*p,this._y=l*f*u-d*h*p,this._z=l*h*p+d*f*u,this._w=l*h*u-d*f*p;break;case"YXZ":this._x=d*h*u+l*f*p,this._y=l*f*u-d*h*p,this._z=l*h*p-d*f*u,this._w=l*h*u+d*f*p;break;case"ZXY":this._x=d*h*u-l*f*p,this._y=l*f*u+d*h*p,this._z=l*h*p+d*f*u,this._w=l*h*u-d*f*p;break;case"ZYX":this._x=d*h*u-l*f*p,this._y=l*f*u+d*h*p,this._z=l*h*p-d*f*u,this._w=l*h*u+d*f*p;break;case"YZX":this._x=d*h*u+l*f*p,this._y=l*f*u+d*h*p,this._z=l*h*p-d*f*u,this._w=l*h*u-d*f*p;break;case"XZY":this._x=d*h*u-l*f*p,this._y=l*f*u-d*h*p,this._z=l*h*p+d*f*u,this._w=l*h*u+d*f*p;break;default:It("Quaternion: .setFromEuler() encountered an unknown order: "+r)}return e===!0&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const i=e/2,n=Math.sin(i);return this._x=t.x*n,this._y=t.y*n,this._z=t.z*n,this._w=Math.cos(i),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,i=e[0],n=e[4],s=e[8],r=e[1],o=e[5],c=e[9],l=e[2],h=e[6],u=e[10],d=i+o+u;if(d>0){const f=.5/Math.sqrt(d+1);this._w=.25/f,this._x=(h-c)*f,this._y=(s-l)*f,this._z=(r-n)*f}else if(i>o&&i>u){const f=2*Math.sqrt(1+i-o-u);this._w=(h-c)/f,this._x=.25*f,this._y=(n+r)/f,this._z=(s+l)/f}else if(o>u){const f=2*Math.sqrt(1+o-i-u);this._w=(s-l)/f,this._x=(n+r)/f,this._y=.25*f,this._z=(c+h)/f}else{const f=2*Math.sqrt(1+u-i-o);this._w=(r-n)/f,this._x=(s+l)/f,this._y=(c+h)/f,this._z=.25*f}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let i=t.dot(e)+1;return i<1e-8?(i=0,Math.abs(t.x)>Math.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=i):(this._x=0,this._y=-t.z,this._z=t.y,this._w=i)):(this._x=t.y*e.z-t.z*e.y,this._y=t.z*e.x-t.x*e.z,this._z=t.x*e.y-t.y*e.x,this._w=i),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(Zt(this.dot(t),-1,1)))}rotateTowards(t,e){const i=this.angleTo(t);if(i===0)return this;const n=Math.min(1,e/i);return this.slerp(t,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(t){return this._x*t._x+this._y*t._y+this._z*t._z+this._w*t._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 t=this.length();return t===0?(this._x=0,this._y=0,this._z=0,this._w=1):(t=1/t,this._x=this._x*t,this._y=this._y*t,this._z=this._z*t,this._w=this._w*t),this._onChangeCallback(),this}multiply(t){return this.multiplyQuaternions(this,t)}premultiply(t){return this.multiplyQuaternions(t,this)}multiplyQuaternions(t,e){const i=t._x,n=t._y,s=t._z,r=t._w,o=e._x,c=e._y,l=e._z,h=e._w;return this._x=i*h+r*o+n*l-s*c,this._y=n*h+r*c+s*o-i*l,this._z=s*h+r*l+i*c-n*o,this._w=r*h-i*o-n*c-s*l,this._onChangeCallback(),this}slerp(t,e){let i=t._x,n=t._y,s=t._z,r=t._w,o=this.dot(t);o<0&&(i=-i,n=-n,s=-s,r=-r,o=-o);let c=1-e;if(o<.9995){const l=Math.acos(o),h=Math.sin(l);c=Math.sin(c*l)/h,e=Math.sin(e*l)/h,this._x=this._x*c+i*e,this._y=this._y*c+n*e,this._z=this._z*c+s*e,this._w=this._w*c+r*e,this._onChangeCallback()}else this._x=this._x*c+i*e,this._y=this._y*c+n*e,this._z=this._z*c+s*e,this._w=this._w*c+r*e,this.normalize();return this}slerpQuaternions(t,e,i){return this.copy(t).slerp(e,i)}random(){const t=2*Math.PI*Math.random(),e=2*Math.PI*Math.random(),i=Math.random(),n=Math.sqrt(1-i),s=Math.sqrt(i);return this.set(n*Math.sin(t),n*Math.cos(t),s*Math.sin(e),s*Math.cos(e))}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._w===this._w}fromArray(t,e=0){return this._x=t[e],this._y=t[e+1],this._z=t[e+2],this._w=t[e+3],this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._w,t}fromBufferAttribute(t,e){return this._x=t.getX(e),this._y=t.getY(e),this._z=t.getZ(e),this._w=t.getW(e),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class R{static{R.prototype.isVector3=!0}constructor(t=0,e=0,i=0){this.x=t,this.y=e,this.z=i}set(t,e,i){return i===void 0&&(i=this.z),this.x=t,this.y=e,this.z=i,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;default:throw new Error("THREE.Vector3: index is out of range: "+t)}return this}getComponent(t){switch(t){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: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}multiplyVectors(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this.z=t.z*e.z,this}applyEuler(t){return this.applyQuaternion(rp.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(rp.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,i=this.y,n=this.z,s=t.elements;return this.x=s[0]*e+s[3]*i+s[6]*n,this.y=s[1]*e+s[4]*i+s[7]*n,this.z=s[2]*e+s[5]*i+s[8]*n,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,i=this.y,n=this.z,s=t.elements,r=1/(s[3]*e+s[7]*i+s[11]*n+s[15]);return this.x=(s[0]*e+s[4]*i+s[8]*n+s[12])*r,this.y=(s[1]*e+s[5]*i+s[9]*n+s[13])*r,this.z=(s[2]*e+s[6]*i+s[10]*n+s[14])*r,this}applyQuaternion(t){const e=this.x,i=this.y,n=this.z,s=t.x,r=t.y,o=t.z,c=t.w,l=2*(r*n-o*i),h=2*(o*e-s*n),u=2*(s*i-r*e);return this.x=e+c*l+r*u-o*h,this.y=i+c*h+o*l-s*u,this.z=n+c*u+s*h-r*l,this}project(t){return this.applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix)}unproject(t){return this.applyMatrix4(t.projectionMatrixInverse).applyMatrix4(t.matrixWorld)}transformDirection(t){const e=this.x,i=this.y,n=this.z,s=t.elements;return this.x=s[0]*e+s[4]*i+s[8]*n,this.y=s[1]*e+s[5]*i+s[9]*n,this.z=s[2]*e+s[6]*i+s[10]*n,this.normalize()}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this}divideScalar(t){return this.multiplyScalar(1/t)}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this}clamp(t,e){return this.x=Zt(this.x,t.x,e.x),this.y=Zt(this.y,t.y,e.y),this.z=Zt(this.z,t.z,e.z),this}clampScalar(t,e){return this.x=Zt(this.x,t,e),this.y=Zt(this.y,t,e),this.z=Zt(this.z,t,e),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Zt(i,t,e))}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(t){return this.x*t.x+this.y*t.y+this.z*t.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(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this}lerpVectors(t,e,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this.z=t.z+(e.z-t.z)*i,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){const i=t.x,n=t.y,s=t.z,r=e.x,o=e.y,c=e.z;return this.x=n*c-s*o,this.y=s*r-i*c,this.z=i*o-n*r,this}projectOnVector(t){const e=t.lengthSq();if(e===0)return this.set(0,0,0);const i=t.dot(this)/e;return this.copy(t).multiplyScalar(i)}projectOnPlane(t){return Lh.copy(this).projectOnVector(t),this.sub(Lh)}reflect(t){return this.sub(Lh.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;const i=this.dot(t)/e;return Math.acos(Zt(i,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,i=this.y-t.y,n=this.z-t.z;return e*e+i*i+n*n}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)}setFromSpherical(t){return this.setFromSphericalCoords(t.radius,t.phi,t.theta)}setFromSphericalCoords(t,e,i){const n=Math.sin(e)*t;return this.x=n*Math.sin(i),this.y=Math.cos(e)*t,this.z=n*Math.cos(i),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,i){return this.x=t*Math.sin(e),this.y=i,this.z=t*Math.cos(e),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this}setFromMatrixScale(t){const e=this.setFromMatrixColumn(t,0).length(),i=this.setFromMatrixColumn(t,1).length(),n=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=i,this.z=n,this}setFromMatrixColumn(t,e){return this.fromArray(t.elements,e*4)}setFromMatrix3Column(t,e){return this.fromArray(t.elements,e*3)}setFromEuler(t){return this.x=t._x,this.y=t._y,this.z=t._z,this}setFromColor(t){return this.x=t.r,this.y=t.g,this.z=t.b,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const t=Math.random()*Math.PI*2,e=Math.random()*2-1,i=Math.sqrt(1-e*e);return this.x=i*Math.cos(t),this.y=e,this.z=i*Math.sin(t),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const Lh=new R,rp=new on;class $t{static{$t.prototype.isMatrix3=!0}constructor(t,e,i,n,s,r,o,c,l){this.elements=[1,0,0,0,1,0,0,0,1],t!==void 0&&this.set(t,e,i,n,s,r,o,c,l)}set(t,e,i,n,s,r,o,c,l){const h=this.elements;return h[0]=t,h[1]=n,h[2]=o,h[3]=e,h[4]=s,h[5]=c,h[6]=i,h[7]=r,h[8]=l,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){const e=this.elements,i=t.elements;return e[0]=i[0],e[1]=i[1],e[2]=i[2],e[3]=i[3],e[4]=i[4],e[5]=i[5],e[6]=i[6],e[7]=i[7],e[8]=i[8],this}extractBasis(t,e,i){return t.setFromMatrix3Column(this,0),e.setFromMatrix3Column(this,1),i.setFromMatrix3Column(this,2),this}setFromMatrix4(t){const e=t.elements;return this.set(e[0],e[4],e[8],e[1],e[5],e[9],e[2],e[6],e[10]),this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const i=t.elements,n=e.elements,s=this.elements,r=i[0],o=i[3],c=i[6],l=i[1],h=i[4],u=i[7],d=i[2],f=i[5],p=i[8],v=n[0],m=n[3],g=n[6],S=n[1],x=n[4],M=n[7],b=n[2],w=n[5],T=n[8];return s[0]=r*v+o*S+c*b,s[3]=r*m+o*x+c*w,s[6]=r*g+o*M+c*T,s[1]=l*v+h*S+u*b,s[4]=l*m+h*x+u*w,s[7]=l*g+h*M+u*T,s[2]=d*v+f*S+p*b,s[5]=d*m+f*x+p*w,s[8]=d*g+f*M+p*T,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[3]*=t,e[6]*=t,e[1]*=t,e[4]*=t,e[7]*=t,e[2]*=t,e[5]*=t,e[8]*=t,this}determinant(){const t=this.elements,e=t[0],i=t[1],n=t[2],s=t[3],r=t[4],o=t[5],c=t[6],l=t[7],h=t[8];return e*r*h-e*o*l-i*s*h+i*o*c+n*s*l-n*r*c}invert(){const t=this.elements,e=t[0],i=t[1],n=t[2],s=t[3],r=t[4],o=t[5],c=t[6],l=t[7],h=t[8],u=h*r-o*l,d=o*c-h*s,f=l*s-r*c,p=e*u+i*d+n*f;if(p===0)return this.set(0,0,0,0,0,0,0,0,0);const v=1/p;return t[0]=u*v,t[1]=(n*l-h*i)*v,t[2]=(o*i-n*r)*v,t[3]=d*v,t[4]=(h*e-n*c)*v,t[5]=(n*s-o*e)*v,t[6]=f*v,t[7]=(i*c-l*e)*v,t[8]=(r*e-i*s)*v,this}transpose(){let t;const e=this.elements;return t=e[1],e[1]=e[3],e[3]=t,t=e[2],e[2]=e[6],e[6]=t,t=e[5],e[5]=e[7],e[7]=t,this}getNormalMatrix(t){return this.setFromMatrix4(t).invert().transpose()}transposeIntoArray(t){const e=this.elements;return t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8],this}setUvTransform(t,e,i,n,s,r,o){const c=Math.cos(s),l=Math.sin(s);return this.set(i*c,i*l,-i*(c*r+l*o)+r+t,-n*l,n*c,-n*(-l*r+c*o)+o+e,0,0,1),this}scale(t,e){return Ba("Matrix3: .scale() is deprecated. Use .makeScale() instead."),this.premultiply(Oh.makeScale(t,e)),this}rotate(t){return Ba("Matrix3: .rotate() is deprecated. Use .makeRotation() instead."),this.premultiply(Oh.makeRotation(-t)),this}translate(t,e){return Ba("Matrix3: .translate() is deprecated. Use .makeTranslation() instead."),this.premultiply(Oh.makeTranslation(t,e)),this}makeTranslation(t,e){return t.isVector2?this.set(1,0,t.x,0,1,t.y,0,0,1):this.set(1,0,t,0,1,e,0,0,1),this}makeRotation(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,-i,0,i,e,0,0,0,1),this}makeScale(t,e){return this.set(t,0,0,0,e,0,0,0,1),this}equals(t){const e=this.elements,i=t.elements;for(let n=0;n<9;n++)if(e[n]!==i[n])return!1;return!0}fromArray(t,e=0){for(let i=0;i<9;i++)this.elements[i]=t[i+e];return this}toArray(t=[],e=0){const i=this.elements;return t[e]=i[0],t[e+1]=i[1],t[e+2]=i[2],t[e+3]=i[3],t[e+4]=i[4],t[e+5]=i[5],t[e+6]=i[6],t[e+7]=i[7],t[e+8]=i[8],t}clone(){return new this.constructor().fromArray(this.elements)}}const Oh=new $t,ap=new $t().set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),op=new $t().set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);function VM(){const a={enabled:!0,workingColorSpace:Vl,spaces:{},convert:function(n,s,r){return this.enabled===!1||s===r||!s||!r||(this.spaces[s].transfer===we&&(n.r=Ns(n.r),n.g=Ns(n.g),n.b=Ns(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===we&&(n.r=Ha(n.r),n.g=Ha(n.g),n.b=Ha(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===rr?Wl: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 Ba("ColorManagement: .fromWorkingColorSpace() has been renamed to .workingToColorSpace()."),a.workingToColorSpace(n,s)},toWorkingColorSpace:function(n,s){return Ba("ColorManagement: .toWorkingColorSpace() has been renamed to .colorSpaceToWorking()."),a.colorSpaceToWorking(n,s)}},t=[.64,.33,.3,.6,.15,.06],e=[.2126,.7152,.0722],i=[.3127,.329];return a.define({[Vl]:{primaries:t,whitePoint:i,transfer:Wl,toXYZ:ap,fromXYZ:op,luminanceCoefficients:e,workingColorSpaceConfig:{unpackColorSpace:qi},outputColorSpaceConfig:{drawingBufferColorSpace:qi}},[qi]:{primaries:t,whitePoint:i,transfer:we,toXYZ:ap,fromXYZ:op,luminanceCoefficients:e,outputColorSpaceConfig:{drawingBufferColorSpace:qi}}}),a}const ce=VM();function Ns(a){return a<.04045?a*.0773993808:Math.pow(a*.9478672986+.0521327014,2.4)}function Ha(a){return a<.0031308?a*12.92:1.055*Math.pow(a,.41666)-.055}let ea;class WM{static getDataURL(t,e="image/png"){if(/^data:/i.test(t.src)||typeof HTMLCanvasElement>"u")return t.src;let i;if(t instanceof HTMLCanvasElement)i=t;else{ea===void 0&&(ea=cc("canvas")),ea.width=t.width,ea.height=t.height;const n=ea.getContext("2d");t instanceof ImageData?n.putImageData(t,0,0):n.drawImage(t,0,0,t.width,t.height),i=ea}return i.toDataURL(e)}static sRGBToLinear(t){if(typeof HTMLImageElement<"u"&&t instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&t instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&t instanceof ImageBitmap){const e=cc("canvas");e.width=t.width,e.height=t.height;const i=e.getContext("2d");i.drawImage(t,0,0,t.width,t.height);const n=i.getImageData(0,0,t.width,t.height),s=n.data;for(let r=0;r<s.length;r++)s[r]=Ns(s[r]/255)*255;return i.putImageData(n,0,0),e}else if(t.data){const e=t.data.slice(0);for(let i=0;i<e.length;i++)e instanceof Uint8Array||e instanceof Uint8ClampedArray?e[i]=Math.floor(Ns(e[i]/255)*255):e[i]=Ns(e[i]);return{data:e,width:t.width,height:t.height}}else return It("ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."),t}}let XM=0;class k0{constructor(t=null){this.isSource=!0,Object.defineProperty(this,"id",{value:XM++}),this.uuid=Kn(),this.data=t,this.dataReady=!0,this.version=0}getSize(t){const e=this.data;return typeof HTMLVideoElement<"u"&&e instanceof HTMLVideoElement?t.set(e.videoWidth,e.videoHeight,0):typeof VideoFrame<"u"&&e instanceof VideoFrame?t.set(e.displayWidth,e.displayHeight,0):e!==null?t.set(e.width,e.height,e.depth||0):t.set(0,0,0),t}set needsUpdate(t){t===!0&&this.version++}toJSON(t){const e=t===void 0||typeof t=="string";if(!e&&t.images[this.uuid]!==void 0)return t.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,o=n.length;r<o;r++)n[r].isDataTexture?s.push(Nh(n[r].image)):s.push(Nh(n[r]))}else s=Nh(n);i.url=s}return e||(t.images[this.uuid]=i),i}}function Nh(a){return typeof HTMLImageElement<"u"&&a instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&a instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&a instanceof ImageBitmap?WM.getDataURL(a):a.data?{data:Array.from(a.data),width:a.width,height:a.height,type:a.data.constructor.name}:(It("Texture: Unable to serialize Texture."),{})}let YM=0;const Fh=new R;class Ei extends vr{constructor(t=Ei.DEFAULT_IMAGE,e=Ei.DEFAULT_MAPPING,i=Ri,n=Ri,s=le,r=Lr,o=Di,c=yn,l=Ei.DEFAULT_ANISOTROPY,h=rr){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:YM++}),this.uuid=Kn(),this.name="",this.source=new k0(t),this.mipmaps=[],this.mapping=e,this.channel=0,this.wrapS=i,this.wrapT=n,this.magFilter=s,this.minFilter=r,this.anisotropy=l,this.format=o,this.internalFormat=null,this.type=c,this.offset=new Mt(0,0),this.repeat=new Mt(1,1),this.center=new Mt(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new $t,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=!!(t&&t.depth&&t.depth>1),this.pmremVersion=0,this.normalized=!1}get width(){return this.source.getSize(Fh).x}get height(){return this.source.getSize(Fh).y}get depth(){return this.source.getSize(Fh).z}get image(){return this.source.data}set image(t){this.source.data=t}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(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}clone(){return new this.constructor().copy(this)}copy(t){return this.name=t.name,this.source=t.source,this.mipmaps=t.mipmaps.slice(0),this.mapping=t.mapping,this.channel=t.channel,this.wrapS=t.wrapS,this.wrapT=t.wrapT,this.magFilter=t.magFilter,this.minFilter=t.minFilter,this.anisotropy=t.anisotropy,this.format=t.format,this.internalFormat=t.internalFormat,this.type=t.type,this.normalized=t.normalized,this.offset.copy(t.offset),this.repeat.copy(t.repeat),this.center.copy(t.center),this.rotation=t.rotation,this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrix.copy(t.matrix),this.generateMipmaps=t.generateMipmaps,this.premultiplyAlpha=t.premultiplyAlpha,this.flipY=t.flipY,this.unpackAlignment=t.unpackAlignment,this.colorSpace=t.colorSpace,this.renderTarget=t.renderTarget,this.isRenderTargetTexture=t.isRenderTargetTexture,this.isArrayTexture=t.isArrayTexture,this.userData=JSON.parse(JSON.stringify(t.userData)),this.needsUpdate=!0,this}setValues(t){for(const e in t){const i=t[e];if(i===void 0){It(`Texture.setValues(): parameter '${e}' has value of undefined.`);continue}const n=this[e];if(n===void 0){It(`Texture.setValues(): property '${e}' 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[e]=i}}toJSON(t){const e=t===void 0||typeof t=="string";if(!e&&t.textures[this.uuid]!==void 0)return t.textures[this.uuid];const i={metadata:{version:4.7,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,image:this.source.toJSON(t).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),e||(t.textures[this.uuid]=i),i}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(t){if(this.mapping!==r1)return t;if(t.applyMatrix3(this.matrix),t.x<0||t.x>1)switch(this.wrapS){case sc:t.x=t.x-Math.floor(t.x);break;case Ri:t.x=t.x<0?0:1;break;case cd:Math.abs(Math.floor(t.x)%2)===1?t.x=Math.ceil(t.x)-t.x:t.x=t.x-Math.floor(t.x);break}if(t.y<0||t.y>1)switch(this.wrapT){case sc:t.y=t.y-Math.floor(t.y);break;case Ri:t.y=t.y<0?0:1;break;case cd:Math.abs(Math.floor(t.y)%2)===1?t.y=Math.ceil(t.y)-t.y:t.y=t.y-Math.floor(t.y);break}return this.flipY&&(t.y=1-t.y),t}set needsUpdate(t){t===!0&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(t){t===!0&&this.pmremVersion++}}Ei.DEFAULT_IMAGE=null;Ei.DEFAULT_MAPPING=r1;Ei.DEFAULT_ANISOTROPY=1;class ae{static{ae.prototype.isVector4=!0}constructor(t=0,e=0,i=0,n=1){this.x=t,this.y=e,this.z=i,this.w=n}get width(){return this.z}set width(t){this.z=t}get height(){return this.w}set height(t){this.w=t}set(t,e,i,n){return this.x=t,this.y=e,this.z=i,this.w=n,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this.w=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setW(t){return this.w=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;case 3:this.w=e;break;default:throw new Error("THREE.Vector4: index is out of range: "+t)}return this}getComponent(t){switch(t){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: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w!==void 0?t.w:1,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this.w+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this.w=t.w+e.w,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this.w+=t.w*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this.w-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this.w=t.w-e.w,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this.w*=t.w,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this}applyMatrix4(t){const e=this.x,i=this.y,n=this.z,s=this.w,r=t.elements;return this.x=r[0]*e+r[4]*i+r[8]*n+r[12]*s,this.y=r[1]*e+r[5]*i+r[9]*n+r[13]*s,this.z=r[2]*e+r[6]*i+r[10]*n+r[14]*s,this.w=r[3]*e+r[7]*i+r[11]*n+r[15]*s,this}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this.w/=t.w,this}divideScalar(t){return this.multiplyScalar(1/t)}setAxisAngleFromQuaternion(t){this.w=2*Math.acos(t.w);const e=Math.sqrt(1-t.w*t.w);return e<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=t.x/e,this.y=t.y/e,this.z=t.z/e),this}setAxisAngleFromRotationMatrix(t){let e,i,n,s;const c=t.elements,l=c[0],h=c[4],u=c[8],d=c[1],f=c[5],p=c[9],v=c[2],m=c[6],g=c[10];if(Math.abs(h-d)<.01&&Math.abs(u-v)<.01&&Math.abs(p-m)<.01){if(Math.abs(h+d)<.1&&Math.abs(u+v)<.1&&Math.abs(p+m)<.1&&Math.abs(l+f+g-3)<.1)return this.set(1,0,0,0),this;e=Math.PI;const x=(l+1)/2,M=(f+1)/2,b=(g+1)/2,w=(h+d)/4,T=(u+v)/4,y=(p+m)/4;return x>M&&x>b?x<.01?(i=0,n=.707106781,s=.707106781):(i=Math.sqrt(x),n=w/i,s=T/i):M>b?M<.01?(i=.707106781,n=0,s=.707106781):(n=Math.sqrt(M),i=w/n,s=y/n):b<.01?(i=.707106781,n=.707106781,s=0):(s=Math.sqrt(b),i=T/s,n=y/s),this.set(i,n,s,e),this}let S=Math.sqrt((m-p)*(m-p)+(u-v)*(u-v)+(d-h)*(d-h));return Math.abs(S)<.001&&(S=1),this.x=(m-p)/S,this.y=(u-v)/S,this.z=(d-h)/S,this.w=Math.acos((l+f+g-1)/2),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this.w=e[15],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this.w=Math.min(this.w,t.w),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this.w=Math.max(this.w,t.w),this}clamp(t,e){return this.x=Zt(this.x,t.x,e.x),this.y=Zt(this.y,t.y,e.y),this.z=Zt(this.z,t.z,e.z),this.w=Zt(this.w,t.w,e.w),this}clampScalar(t,e){return this.x=Zt(this.x,t,e),this.y=Zt(this.y,t,e),this.z=Zt(this.z,t,e),this.w=Zt(this.w,t,e),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Zt(i,t,e))}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(t){return this.x*t.x+this.y*t.y+this.z*t.z+this.w*t.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(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this.w+=(t.w-this.w)*e,this}lerpVectors(t,e,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this.z=t.z+(e.z-t.z)*i,this.w=t.w+(e.w-t.w)*i,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z&&t.w===this.w}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this.w=t[e+3],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t[e+3]=this.w,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this.w=t.getW(e),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 qM extends vr{constructor(t=1,e=1,i={}){super(),i=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:le,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=t,this.height=e,this.depth=i.depth,this.scissor=new ae(0,0,t,e),this.scissorTest=!1,this.viewport=new ae(0,0,t,e),this.textures=[];const n={width:t,height:e,depth:i.depth},s=new Ei(n),r=i.count;for(let o=0;o<r;o++)this.textures[o]=s.clone(),this.textures[o].isRenderTargetTexture=!0,this.textures[o].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(t={}){const e={minFilter:le,generateMipmaps:!1,flipY:!1,internalFormat:null};t.mapping!==void 0&&(e.mapping=t.mapping),t.wrapS!==void 0&&(e.wrapS=t.wrapS),t.wrapT!==void 0&&(e.wrapT=t.wrapT),t.wrapR!==void 0&&(e.wrapR=t.wrapR),t.magFilter!==void 0&&(e.magFilter=t.magFilter),t.minFilter!==void 0&&(e.minFilter=t.minFilter),t.format!==void 0&&(e.format=t.format),t.type!==void 0&&(e.type=t.type),t.anisotropy!==void 0&&(e.anisotropy=t.anisotropy),t.colorSpace!==void 0&&(e.colorSpace=t.colorSpace),t.flipY!==void 0&&(e.flipY=t.flipY),t.generateMipmaps!==void 0&&(e.generateMipmaps=t.generateMipmaps),t.internalFormat!==void 0&&(e.internalFormat=t.internalFormat);for(let i=0;i<this.textures.length;i++)this.textures[i].setValues(e)}get texture(){return this.textures[0]}set texture(t){this.textures[0]=t}set depthTexture(t){this._depthTexture!==null&&(this._depthTexture.renderTarget=null),t!==null&&(t.renderTarget=this),this._depthTexture=t}get depthTexture(){return this._depthTexture}setSize(t,e,i=1){if(this.width!==t||this.height!==e||this.depth!==i){this.width=t,this.height=e,this.depth=i;for(let n=0,s=this.textures.length;n<s;n++)this.textures[n].image.width=t,this.textures[n].image.height=e,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,t,e),this.scissor.set(0,0,t,e)}clone(){return new this.constructor().copy(this)}copy(t){this.width=t.width,this.height=t.height,this.depth=t.depth,this.scissor.copy(t.scissor),this.scissorTest=t.scissorTest,this.viewport.copy(t.viewport),this.textures.length=0;for(let e=0,i=t.textures.length;e<i;e++){this.textures[e]=t.textures[e].clone(),this.textures[e].isRenderTargetTexture=!0,this.textures[e].renderTarget=this;const n=Object.assign({},t.textures[e].image);this.textures[e].source=new k0(n)}return this.depthBuffer=t.depthBuffer,this.stencilBuffer=t.stencilBuffer,this.resolveDepthBuffer=t.resolveDepthBuffer,this.resolveStencilBuffer=t.resolveStencilBuffer,t.depthTexture!==null&&(this.depthTexture=t.depthTexture.clone()),this.samples=t.samples,this.multiview=t.multiview,this.useArrayDepthTexture=t.useArrayDepthTexture,this}dispose(){this.dispatchEvent({type:"dispose"})}}class Qe extends qM{constructor(t=1,e=1,i={}){super(t,e,i),this.isWebGLRenderTarget=!0}}class p1 extends Ei{constructor(t=null,e=1,i=1,n=1){super(null),this.isDataArrayTexture=!0,this.image={data:t,width:e,height:i,depth:n},this.magFilter=Ce,this.minFilter=Ce,this.wrapR=Ri,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1,this.layerUpdates=new Set}addLayerUpdate(t){this.layerUpdates.add(t)}clearLayerUpdates(){this.layerUpdates.clear()}}class m1 extends Ei{constructor(t=null,e=1,i=1,n=1){super(null),this.isData3DTexture=!0,this.image={data:t,width:e,height:i,depth:n},this.magFilter=Ce,this.minFilter=Ce,this.wrapR=Ri,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}class te{static{te.prototype.isMatrix4=!0}constructor(t,e,i,n,s,r,o,c,l,h,u,d,f,p,v,m){this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],t!==void 0&&this.set(t,e,i,n,s,r,o,c,l,h,u,d,f,p,v,m)}set(t,e,i,n,s,r,o,c,l,h,u,d,f,p,v,m){const g=this.elements;return g[0]=t,g[4]=e,g[8]=i,g[12]=n,g[1]=s,g[5]=r,g[9]=o,g[13]=c,g[2]=l,g[6]=h,g[10]=u,g[14]=d,g[3]=f,g[7]=p,g[11]=v,g[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 te().fromArray(this.elements)}copy(t){const e=this.elements,i=t.elements;return e[0]=i[0],e[1]=i[1],e[2]=i[2],e[3]=i[3],e[4]=i[4],e[5]=i[5],e[6]=i[6],e[7]=i[7],e[8]=i[8],e[9]=i[9],e[10]=i[10],e[11]=i[11],e[12]=i[12],e[13]=i[13],e[14]=i[14],e[15]=i[15],this}copyPosition(t){const e=this.elements,i=t.elements;return e[12]=i[12],e[13]=i[13],e[14]=i[14],this}setFromMatrix3(t){const e=t.elements;return this.set(e[0],e[3],e[6],0,e[1],e[4],e[7],0,e[2],e[5],e[8],0,0,0,0,1),this}extractBasis(t,e,i){return this.determinantAffine()===0?(t.set(1,0,0),e.set(0,1,0),i.set(0,0,1),this):(t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),i.setFromMatrixColumn(this,2),this)}makeBasis(t,e,i){return this.set(t.x,e.x,i.x,0,t.y,e.y,i.y,0,t.z,e.z,i.z,0,0,0,0,1),this}extractRotation(t){if(t.determinantAffine()===0)return this.identity();const e=this.elements,i=t.elements,n=1/ia.setFromMatrixColumn(t,0).length(),s=1/ia.setFromMatrixColumn(t,1).length(),r=1/ia.setFromMatrixColumn(t,2).length();return e[0]=i[0]*n,e[1]=i[1]*n,e[2]=i[2]*n,e[3]=0,e[4]=i[4]*s,e[5]=i[5]*s,e[6]=i[6]*s,e[7]=0,e[8]=i[8]*r,e[9]=i[9]*r,e[10]=i[10]*r,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){const e=this.elements,i=t.x,n=t.y,s=t.z,r=Math.cos(i),o=Math.sin(i),c=Math.cos(n),l=Math.sin(n),h=Math.cos(s),u=Math.sin(s);if(t.order==="XYZ"){const d=r*h,f=r*u,p=o*h,v=o*u;e[0]=c*h,e[4]=-c*u,e[8]=l,e[1]=f+p*l,e[5]=d-v*l,e[9]=-o*c,e[2]=v-d*l,e[6]=p+f*l,e[10]=r*c}else if(t.order==="YXZ"){const d=c*h,f=c*u,p=l*h,v=l*u;e[0]=d+v*o,e[4]=p*o-f,e[8]=r*l,e[1]=r*u,e[5]=r*h,e[9]=-o,e[2]=f*o-p,e[6]=v+d*o,e[10]=r*c}else if(t.order==="ZXY"){const d=c*h,f=c*u,p=l*h,v=l*u;e[0]=d-v*o,e[4]=-r*u,e[8]=p+f*o,e[1]=f+p*o,e[5]=r*h,e[9]=v-d*o,e[2]=-r*l,e[6]=o,e[10]=r*c}else if(t.order==="ZYX"){const d=r*h,f=r*u,p=o*h,v=o*u;e[0]=c*h,e[4]=p*l-f,e[8]=d*l+v,e[1]=c*u,e[5]=v*l+d,e[9]=f*l-p,e[2]=-l,e[6]=o*c,e[10]=r*c}else if(t.order==="YZX"){const d=r*c,f=r*l,p=o*c,v=o*l;e[0]=c*h,e[4]=v-d*u,e[8]=p*u+f,e[1]=u,e[5]=r*h,e[9]=-o*h,e[2]=-l*h,e[6]=f*u+p,e[10]=d-v*u}else if(t.order==="XZY"){const d=r*c,f=r*l,p=o*c,v=o*l;e[0]=c*h,e[4]=-u,e[8]=l*h,e[1]=d*u+v,e[5]=r*h,e[9]=f*u-p,e[2]=p*u-f,e[6]=o*h,e[10]=v*u+d}return e[3]=0,e[7]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromQuaternion(t){return this.compose($M,t,KM)}lookAt(t,e,i){const n=this.elements;return ln.subVectors(t,e),ln.lengthSq()===0&&(ln.z=1),ln.normalize(),Ws.crossVectors(i,ln),Ws.lengthSq()===0&&(Math.abs(i.z)===1?ln.x+=1e-4:ln.z+=1e-4,ln.normalize(),Ws.crossVectors(i,ln)),Ws.normalize(),Tc.crossVectors(ln,Ws),n[0]=Ws.x,n[4]=Tc.x,n[8]=ln.x,n[1]=Ws.y,n[5]=Tc.y,n[9]=ln.y,n[2]=Ws.z,n[6]=Tc.z,n[10]=ln.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const i=t.elements,n=e.elements,s=this.elements,r=i[0],o=i[4],c=i[8],l=i[12],h=i[1],u=i[5],d=i[9],f=i[13],p=i[2],v=i[6],m=i[10],g=i[14],S=i[3],x=i[7],M=i[11],b=i[15],w=n[0],T=n[4],y=n[8],A=n[12],C=n[1],I=n[5],P=n[9],V=n[13],X=n[2],L=n[6],B=n[10],k=n[14],$=n[3],tt=n[7],J=n[11],it=n[15];return s[0]=r*w+o*C+c*X+l*$,s[4]=r*T+o*I+c*L+l*tt,s[8]=r*y+o*P+c*B+l*J,s[12]=r*A+o*V+c*k+l*it,s[1]=h*w+u*C+d*X+f*$,s[5]=h*T+u*I+d*L+f*tt,s[9]=h*y+u*P+d*B+f*J,s[13]=h*A+u*V+d*k+f*it,s[2]=p*w+v*C+m*X+g*$,s[6]=p*T+v*I+m*L+g*tt,s[10]=p*y+v*P+m*B+g*J,s[14]=p*A+v*V+m*k+g*it,s[3]=S*w+x*C+M*X+b*$,s[7]=S*T+x*I+M*L+b*tt,s[11]=S*y+x*P+M*B+b*J,s[15]=S*A+x*V+M*k+b*it,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[4]*=t,e[8]*=t,e[12]*=t,e[1]*=t,e[5]*=t,e[9]*=t,e[13]*=t,e[2]*=t,e[6]*=t,e[10]*=t,e[14]*=t,e[3]*=t,e[7]*=t,e[11]*=t,e[15]*=t,this}determinant(){const t=this.elements,e=t[0],i=t[4],n=t[8],s=t[12],r=t[1],o=t[5],c=t[9],l=t[13],h=t[2],u=t[6],d=t[10],f=t[14],p=t[3],v=t[7],m=t[11],g=t[15],S=c*f-l*d,x=o*f-l*u,M=o*d-c*u,b=r*f-l*h,w=r*d-c*h,T=r*u-o*h;return e*(v*S-m*x+g*M)-i*(p*S-m*b+g*w)+n*(p*x-v*b+g*T)-s*(p*M-v*w+m*T)}determinantAffine(){const t=this.elements,e=t[0],i=t[4],n=t[8],s=t[1],r=t[5],o=t[9],c=t[2],l=t[6],h=t[10];return e*(r*h-o*l)-i*(s*h-o*c)+n*(s*l-r*c)}transpose(){const t=this.elements;let e;return e=t[1],t[1]=t[4],t[4]=e,e=t[2],t[2]=t[8],t[8]=e,e=t[6],t[6]=t[9],t[9]=e,e=t[3],t[3]=t[12],t[12]=e,e=t[7],t[7]=t[13],t[13]=e,e=t[11],t[11]=t[14],t[14]=e,this}setPosition(t,e,i){const n=this.elements;return t.isVector3?(n[12]=t.x,n[13]=t.y,n[14]=t.z):(n[12]=t,n[13]=e,n[14]=i),this}invert(){const t=this.elements,e=t[0],i=t[1],n=t[2],s=t[3],r=t[4],o=t[5],c=t[6],l=t[7],h=t[8],u=t[9],d=t[10],f=t[11],p=t[12],v=t[13],m=t[14],g=t[15],S=e*o-i*r,x=e*c-n*r,M=e*l-s*r,b=i*c-n*o,w=i*l-s*o,T=n*l-s*c,y=h*v-u*p,A=h*m-d*p,C=h*g-f*p,I=u*m-d*v,P=u*g-f*v,V=d*g-f*m,X=S*V-x*P+M*I+b*C-w*A+T*y;if(X===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const L=1/X;return t[0]=(o*V-c*P+l*I)*L,t[1]=(n*P-i*V-s*I)*L,t[2]=(v*T-m*w+g*b)*L,t[3]=(d*w-u*T-f*b)*L,t[4]=(c*C-r*V-l*A)*L,t[5]=(e*V-n*C+s*A)*L,t[6]=(m*M-p*T-g*x)*L,t[7]=(h*T-d*M+f*x)*L,t[8]=(r*P-o*C+l*y)*L,t[9]=(i*C-e*P-s*y)*L,t[10]=(p*w-v*M+g*S)*L,t[11]=(u*M-h*w-f*S)*L,t[12]=(o*A-r*I-c*y)*L,t[13]=(e*I-i*A+n*y)*L,t[14]=(v*x-p*b-m*S)*L,t[15]=(h*b-u*x+d*S)*L,this}scale(t){const e=this.elements,i=t.x,n=t.y,s=t.z;return e[0]*=i,e[4]*=n,e[8]*=s,e[1]*=i,e[5]*=n,e[9]*=s,e[2]*=i,e[6]*=n,e[10]*=s,e[3]*=i,e[7]*=n,e[11]*=s,this}getMaxScaleOnAxis(){const t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],i=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],n=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,i,n))}makeTranslation(t,e,i){return t.isVector3?this.set(1,0,0,t.x,0,1,0,t.y,0,0,1,t.z,0,0,0,1):this.set(1,0,0,t,0,1,0,e,0,0,1,i,0,0,0,1),this}makeRotationX(t){const e=Math.cos(t),i=Math.sin(t);return this.set(1,0,0,0,0,e,-i,0,0,i,e,0,0,0,0,1),this}makeRotationY(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,0,i,0,0,1,0,0,-i,0,e,0,0,0,0,1),this}makeRotationZ(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,-i,0,0,i,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){const i=Math.cos(e),n=Math.sin(e),s=1-i,r=t.x,o=t.y,c=t.z,l=s*r,h=s*o;return this.set(l*r+i,l*o-n*c,l*c+n*o,0,l*o+n*c,h*o+i,h*c-n*r,0,l*c-n*o,h*c+n*r,s*c*c+i,0,0,0,0,1),this}makeScale(t,e,i){return this.set(t,0,0,0,0,e,0,0,0,0,i,0,0,0,0,1),this}makeShear(t,e,i,n,s,r){return this.set(1,i,s,0,t,1,r,0,e,n,1,0,0,0,0,1),this}compose(t,e,i){const n=this.elements,s=e._x,r=e._y,o=e._z,c=e._w,l=s+s,h=r+r,u=o+o,d=s*l,f=s*h,p=s*u,v=r*h,m=r*u,g=o*u,S=c*l,x=c*h,M=c*u,b=i.x,w=i.y,T=i.z;return n[0]=(1-(v+g))*b,n[1]=(f+M)*b,n[2]=(p-x)*b,n[3]=0,n[4]=(f-M)*w,n[5]=(1-(d+g))*w,n[6]=(m+S)*w,n[7]=0,n[8]=(p+x)*T,n[9]=(m-S)*T,n[10]=(1-(d+v))*T,n[11]=0,n[12]=t.x,n[13]=t.y,n[14]=t.z,n[15]=1,this}decompose(t,e,i){const n=this.elements;t.x=n[12],t.y=n[13],t.z=n[14];const s=this.determinantAffine();if(s===0)return i.set(1,1,1),e.identity(),this;let r=ia.set(n[0],n[1],n[2]).length();const o=ia.set(n[4],n[5],n[6]).length(),c=ia.set(n[8],n[9],n[10]).length();s<0&&(r=-r),Un.copy(this);const l=1/r,h=1/o,u=1/c;return Un.elements[0]*=l,Un.elements[1]*=l,Un.elements[2]*=l,Un.elements[4]*=h,Un.elements[5]*=h,Un.elements[6]*=h,Un.elements[8]*=u,Un.elements[9]*=u,Un.elements[10]*=u,e.setFromRotationMatrix(Un),i.x=r,i.y=o,i.z=c,this}makePerspective(t,e,i,n,s,r,o=ms,c=!1){const l=this.elements,h=2*s/(e-t),u=2*s/(i-n),d=(e+t)/(e-t),f=(i+n)/(i-n);let p,v;if(c)p=s/(r-s),v=r*s/(r-s);else if(o===ms)p=-(r+s)/(r-s),v=-2*r*s/(r-s);else if(o===oc)p=-r/(r-s),v=-r*s/(r-s);else throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+o);return l[0]=h,l[4]=0,l[8]=d,l[12]=0,l[1]=0,l[5]=u,l[9]=f,l[13]=0,l[2]=0,l[6]=0,l[10]=p,l[14]=v,l[3]=0,l[7]=0,l[11]=-1,l[15]=0,this}makeOrthographic(t,e,i,n,s,r,o=ms,c=!1){const l=this.elements,h=2/(e-t),u=2/(i-n),d=-(e+t)/(e-t),f=-(i+n)/(i-n);let p,v;if(c)p=1/(r-s),v=r/(r-s);else if(o===ms)p=-2/(r-s),v=-(r+s)/(r-s);else if(o===oc)p=-1/(r-s),v=-s/(r-s);else throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+o);return l[0]=h,l[4]=0,l[8]=0,l[12]=d,l[1]=0,l[5]=u,l[9]=0,l[13]=f,l[2]=0,l[6]=0,l[10]=p,l[14]=v,l[3]=0,l[7]=0,l[11]=0,l[15]=1,this}equals(t){const e=this.elements,i=t.elements;for(let n=0;n<16;n++)if(e[n]!==i[n])return!1;return!0}fromArray(t,e=0){for(let i=0;i<16;i++)this.elements[i]=t[i+e];return this}toArray(t=[],e=0){const i=this.elements;return t[e]=i[0],t[e+1]=i[1],t[e+2]=i[2],t[e+3]=i[3],t[e+4]=i[4],t[e+5]=i[5],t[e+6]=i[6],t[e+7]=i[7],t[e+8]=i[8],t[e+9]=i[9],t[e+10]=i[10],t[e+11]=i[11],t[e+12]=i[12],t[e+13]=i[13],t[e+14]=i[14],t[e+15]=i[15],t}}const ia=new R,Un=new te,$M=new R(0,0,0),KM=new R(1,1,1),Ws=new R,Tc=new R,ln=new R,cp=new te,lp=new on;class Us{constructor(t=0,e=0,i=0,n=Us.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=e,this._z=i,this._order=n}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get order(){return this._order}set order(t){this._order=t,this._onChangeCallback()}set(t,e,i,n=this._order){return this._x=t,this._y=e,this._z=i,this._order=n,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(t){return this._x=t._x,this._y=t._y,this._z=t._z,this._order=t._order,this._onChangeCallback(),this}setFromRotationMatrix(t,e=this._order,i=!0){const n=t.elements,s=n[0],r=n[4],o=n[8],c=n[1],l=n[5],h=n[9],u=n[2],d=n[6],f=n[10];switch(e){case"XYZ":this._y=Math.asin(Zt(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-h,f),this._z=Math.atan2(-r,s)):(this._x=Math.atan2(d,l),this._z=0);break;case"YXZ":this._x=Math.asin(-Zt(h,-1,1)),Math.abs(h)<.9999999?(this._y=Math.atan2(o,f),this._z=Math.atan2(c,l)):(this._y=Math.atan2(-u,s),this._z=0);break;case"ZXY":this._x=Math.asin(Zt(d,-1,1)),Math.abs(d)<.9999999?(this._y=Math.atan2(-u,f),this._z=Math.atan2(-r,l)):(this._y=0,this._z=Math.atan2(c,s));break;case"ZYX":this._y=Math.asin(-Zt(u,-1,1)),Math.abs(u)<.9999999?(this._x=Math.atan2(d,f),this._z=Math.atan2(c,s)):(this._x=0,this._z=Math.atan2(-r,l));break;case"YZX":this._z=Math.asin(Zt(c,-1,1)),Math.abs(c)<.9999999?(this._x=Math.atan2(-h,l),this._y=Math.atan2(-u,s)):(this._x=0,this._y=Math.atan2(o,f));break;case"XZY":this._z=Math.asin(-Zt(r,-1,1)),Math.abs(r)<.9999999?(this._x=Math.atan2(d,l),this._y=Math.atan2(o,s)):(this._x=Math.atan2(-h,f),this._y=0);break;default:It("Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,i===!0&&this._onChangeCallback(),this}setFromQuaternion(t,e,i){return cp.makeRotationFromQuaternion(t),this.setFromRotationMatrix(cp,e,i)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return lp.setFromEuler(this),this.setFromQuaternion(lp,t)}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._order===this._order}fromArray(t){return this._x=t[0],this._y=t[1],this._z=t[2],t[3]!==void 0&&(this._order=t[3]),this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._order,t}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}Us.DEFAULT_ORDER="XYZ";class z0{constructor(){this.mask=1}set(t){this.mask=(1<<t|0)>>>0}enable(t){this.mask|=1<<t|0}enableAll(){this.mask=-1}toggle(t){this.mask^=1<<t|0}disable(t){this.mask&=~(1<<t|0)}disableAll(){this.mask=0}test(t){return(this.mask&t.mask)!==0}isEnabled(t){return(this.mask&(1<<t|0))!==0}}let ZM=0;const hp=new R,na=new on,Ss=new te,Rc=new R,co=new R,JM=new R,jM=new on,up=new R(1,0,0),dp=new R(0,1,0),fp=new R(0,0,1),pp={type:"added"},QM={type:"removed"},sa={type:"childadded",child:null},Uh={type:"childremoved",child:null};class Ge extends vr{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:ZM++}),this.uuid=Kn(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=Ge.DEFAULT_UP.clone();const t=new R,e=new Us,i=new on,n=new R(1,1,1);function s(){i.setFromEuler(e,!1)}function r(){e.setFromQuaternion(i,void 0,!1)}e._onChange(s),i._onChange(r),Object.defineProperties(this,{position:{configurable:!0,enumerable:!0,value:t},rotation:{configurable:!0,enumerable:!0,value:e},quaternion:{configurable:!0,enumerable:!0,value:i},scale:{configurable:!0,enumerable:!0,value:n},modelViewMatrix:{value:new te},normalMatrix:{value:new $t}}),this.matrix=new te,this.matrixWorld=new te,this.matrixAutoUpdate=Ge.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=Ge.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new z0,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(t){this.matrixAutoUpdate&&this.updateMatrix(),this.matrix.premultiply(t),this.matrix.decompose(this.position,this.quaternion,this.scale)}applyQuaternion(t){return this.quaternion.premultiply(t),this}setRotationFromAxisAngle(t,e){this.quaternion.setFromAxisAngle(t,e)}setRotationFromEuler(t){this.quaternion.setFromEuler(t,!0)}setRotationFromMatrix(t){this.quaternion.setFromRotationMatrix(t)}setRotationFromQuaternion(t){this.quaternion.copy(t)}rotateOnAxis(t,e){return na.setFromAxisAngle(t,e),this.quaternion.multiply(na),this}rotateOnWorldAxis(t,e){return na.setFromAxisAngle(t,e),this.quaternion.premultiply(na),this}rotateX(t){return this.rotateOnAxis(up,t)}rotateY(t){return this.rotateOnAxis(dp,t)}rotateZ(t){return this.rotateOnAxis(fp,t)}translateOnAxis(t,e){return hp.copy(t).applyQuaternion(this.quaternion),this.position.add(hp.multiplyScalar(e)),this}translateX(t){return this.translateOnAxis(up,t)}translateY(t){return this.translateOnAxis(dp,t)}translateZ(t){return this.translateOnAxis(fp,t)}localToWorld(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(this.matrixWorld)}worldToLocal(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(Ss.copy(this.matrixWorld).invert())}lookAt(t,e,i){t.isVector3?Rc.copy(t):Rc.set(t,e,i);const n=this.parent;this.updateWorldMatrix(!0,!1),co.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?Ss.lookAt(co,Rc,this.up):Ss.lookAt(Rc,co,this.up),this.quaternion.setFromRotationMatrix(Ss),n&&(Ss.extractRotation(n.matrixWorld),na.setFromRotationMatrix(Ss),this.quaternion.premultiply(na.invert()))}add(t){if(arguments.length>1){for(let e=0;e<arguments.length;e++)this.add(arguments[e]);return this}return t===this?(Wt("Object3D.add: object can't be added as a child of itself.",t),this):(t&&t.isObject3D?(t.removeFromParent(),t.parent=this,this.children.push(t),t.dispatchEvent(pp),sa.child=t,this.dispatchEvent(sa),sa.child=null):Wt("Object3D.add: object not an instance of THREE.Object3D.",t),this)}remove(t){if(arguments.length>1){for(let i=0;i<arguments.length;i++)this.remove(arguments[i]);return this}const e=this.children.indexOf(t);return e!==-1&&(t.parent=null,this.children.splice(e,1),t.dispatchEvent(QM),Uh.child=t,this.dispatchEvent(Uh),Uh.child=null),this}removeFromParent(){const t=this.parent;return t!==null&&t.remove(this),this}clear(){return this.remove(...this.children)}attach(t){return this.updateWorldMatrix(!0,!1),Ss.copy(this.matrixWorld).invert(),t.parent!==null&&(t.parent.updateWorldMatrix(!0,!1),Ss.multiply(t.parent.matrixWorld)),t.applyMatrix4(Ss),t.removeFromParent(),t.parent=this,this.children.push(t),t.updateWorldMatrix(!1,!0),t.dispatchEvent(pp),sa.child=t,this.dispatchEvent(sa),sa.child=null,this}getObjectById(t){return this.getObjectByProperty("id",t)}getObjectByName(t){return this.getObjectByProperty("name",t)}getObjectByProperty(t,e){if(this[t]===e)return this;for(let i=0,n=this.children.length;i<n;i++){const r=this.children[i].getObjectByProperty(t,e);if(r!==void 0)return r}}getObjectsByProperty(t,e,i=[]){this[t]===e&&i.push(this);const n=this.children;for(let s=0,r=n.length;s<r;s++)n[s].getObjectsByProperty(t,e,i);return i}getWorldPosition(t){return this.updateWorldMatrix(!0,!1),t.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(co,t,JM),t}getWorldScale(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(co,jM,t),t}getWorldDirection(t){this.updateWorldMatrix(!0,!1);const e=this.matrixWorld.elements;return t.set(e[8],e[9],e[10]).normalize()}raycast(){}traverse(t){t(this);const e=this.children;for(let i=0,n=e.length;i<n;i++)e[i].traverse(t)}traverseVisible(t){if(this.visible===!1)return;t(this);const e=this.children;for(let i=0,n=e.length;i<n;i++)e[i].traverseVisible(t)}traverseAncestors(t){const e=this.parent;e!==null&&(t(e),e.traverseAncestors(t))}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale);const t=this.pivot;if(t!==null){const e=t.x,i=t.y,n=t.z,s=this.matrix.elements;s[12]+=e-s[0]*e-s[4]*i-s[8]*n,s[13]+=i-s[1]*e-s[5]*i-s[9]*n,s[14]+=n-s[2]*e-s[6]*i-s[10]*n}this.matrixWorldNeedsUpdate=!0}updateMatrixWorld(t){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||t)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,t=!0);const e=this.children;for(let i=0,n=e.length;i<n;i++)e[i].updateMatrixWorld(t)}updateWorldMatrix(t,e,i=!1){const n=this.parent;if(t===!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),e===!0){const s=this.children;for(let r=0,o=s.length;r<o;r++)s[r].updateWorldMatrix(!1,!0,i)}}toJSON(t){const e=t===void 0||typeof t=="string",i={};e&&(t={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(o=>({...o,boundingBox:o.boundingBox?o.boundingBox.toJSON():void 0,boundingSphere:o.boundingSphere?o.boundingSphere.toJSON():void 0})),n.instanceInfo=this._instanceInfo.map(o=>({...o})),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(t),n.indirectTexture=this._indirectTexture.toJSON(t),this._colorsTexture!==null&&(n.colorsTexture=this._colorsTexture.toJSON(t)),this.boundingSphere!==null&&(n.boundingSphere=this.boundingSphere.toJSON()),this.boundingBox!==null&&(n.boundingBox=this.boundingBox.toJSON()));function s(o,c){return o[c.uuid]===void 0&&(o[c.uuid]=c.toJSON(t)),c.uuid}if(this.isScene)this.background&&(this.background.isColor?n.background=this.background.toJSON():this.background.isTexture&&(n.background=this.background.toJSON(t).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(n.environment=this.environment.toJSON(t).uuid);else if(this.isMesh||this.isLine||this.isPoints){n.geometry=s(t.geometries,this.geometry);const o=this.geometry.parameters;if(o!==void 0&&o.shapes!==void 0){const c=o.shapes;if(Array.isArray(c))for(let l=0,h=c.length;l<h;l++){const u=c[l];s(t.shapes,u)}else s(t.shapes,c)}}if(this.isSkinnedMesh&&(n.bindMode=this.bindMode,n.bindMatrix=this.bindMatrix.toArray(),this.skeleton!==void 0&&(s(t.skeletons,this.skeleton),n.skeleton=this.skeleton.uuid)),this.material!==void 0)if(Array.isArray(this.material)){const o=[];for(let c=0,l=this.material.length;c<l;c++)o.push(s(t.materials,this.material[c]));n.material=o}else n.material=s(t.materials,this.material);if(this.children.length>0){n.children=[];for(let o=0;o<this.children.length;o++)n.children.push(this.children[o].toJSON(t).object)}if(this.animations.length>0){n.animations=[];for(let o=0;o<this.animations.length;o++){const c=this.animations[o];n.animations.push(s(t.animations,c))}}if(e){const o=r(t.geometries),c=r(t.materials),l=r(t.textures),h=r(t.images),u=r(t.shapes),d=r(t.skeletons),f=r(t.animations),p=r(t.nodes);o.length>0&&(i.geometries=o),c.length>0&&(i.materials=c),l.length>0&&(i.textures=l),h.length>0&&(i.images=h),u.length>0&&(i.shapes=u),d.length>0&&(i.skeletons=d),f.length>0&&(i.animations=f),p.length>0&&(i.nodes=p)}return i.object=n,i;function r(o){const c=[];for(const l in o){const h=o[l];delete h.metadata,c.push(h)}return c}}clone(t){return new this.constructor().copy(this,t)}copy(t,e=!0){if(this.name=t.name,this.up.copy(t.up),this.position.copy(t.position),this.rotation.order=t.rotation.order,this.quaternion.copy(t.quaternion),this.scale.copy(t.scale),this.pivot=t.pivot!==null?t.pivot.clone():null,this.matrix.copy(t.matrix),this.matrixWorld.copy(t.matrixWorld),this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrixWorldAutoUpdate=t.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=t.matrixWorldNeedsUpdate,this.layers.mask=t.layers.mask,this.visible=t.visible,this.castShadow=t.castShadow,this.receiveShadow=t.receiveShadow,this.frustumCulled=t.frustumCulled,this.renderOrder=t.renderOrder,this.static=t.static,this.animations=t.animations.slice(),this.userData=JSON.parse(JSON.stringify(t.userData)),e===!0)for(let i=0;i<t.children.length;i++){const n=t.children[i];this.add(n.clone())}return this}}Ge.DEFAULT_UP=new R(0,1,0);Ge.DEFAULT_MATRIX_AUTO_UPDATE=!0;Ge.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;class Re extends Ge{constructor(){super(),this.isGroup=!0,this.type="Group"}}const tx={type:"move"};class kh{constructor(){this._targetRay=null,this._grip=null,this._hand=null}getHandSpace(){return this._hand===null&&(this._hand=new Re,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 Re,this._targetRay.matrixAutoUpdate=!1,this._targetRay.visible=!1,this._targetRay.hasLinearVelocity=!1,this._targetRay.linearVelocity=new R,this._targetRay.hasAngularVelocity=!1,this._targetRay.angularVelocity=new R),this._targetRay}getGripSpace(){return this._grip===null&&(this._grip=new Re,this._grip.matrixAutoUpdate=!1,this._grip.visible=!1,this._grip.hasLinearVelocity=!1,this._grip.linearVelocity=new R,this._grip.hasAngularVelocity=!1,this._grip.angularVelocity=new R,this._grip.eventsEnabled=!1),this._grip}dispatchEvent(t){return this._targetRay!==null&&this._targetRay.dispatchEvent(t),this._grip!==null&&this._grip.dispatchEvent(t),this._hand!==null&&this._hand.dispatchEvent(t),this}connect(t){if(t&&t.hand){const e=this._hand;if(e)for(const i of t.hand.values())this._getHandJoint(e,i)}return this.dispatchEvent({type:"connected",data:t}),this}disconnect(t){return this.dispatchEvent({type:"disconnected",data:t}),this._targetRay!==null&&(this._targetRay.visible=!1),this._grip!==null&&(this._grip.visible=!1),this._hand!==null&&(this._hand.visible=!1),this}update(t,e,i){let n=null,s=null,r=null;const o=this._targetRay,c=this._grip,l=this._hand;if(t&&e.session.visibilityState!=="visible-blurred"){if(l&&t.hand){r=!0;for(const v of t.hand.values()){const m=e.getJointPose(v,i),g=this._getHandJoint(l,v);m!==null&&(g.matrix.fromArray(m.transform.matrix),g.matrix.decompose(g.position,g.rotation,g.scale),g.matrixWorldNeedsUpdate=!0,g.jointRadius=m.radius),g.visible=m!==null}const h=l.joints["index-finger-tip"],u=l.joints["thumb-tip"],d=h.position.distanceTo(u.position),f=.02,p=.005;l.inputState.pinching&&d>f+p?(l.inputState.pinching=!1,this.dispatchEvent({type:"pinchend",handedness:t.handedness,target:this})):!l.inputState.pinching&&d<=f-p&&(l.inputState.pinching=!0,this.dispatchEvent({type:"pinchstart",handedness:t.handedness,target:this}))}else c!==null&&t.gripSpace&&(s=e.getPose(t.gripSpace,i),s!==null&&(c.matrix.fromArray(s.transform.matrix),c.matrix.decompose(c.position,c.rotation,c.scale),c.matrixWorldNeedsUpdate=!0,s.linearVelocity?(c.hasLinearVelocity=!0,c.linearVelocity.copy(s.linearVelocity)):c.hasLinearVelocity=!1,s.angularVelocity?(c.hasAngularVelocity=!0,c.angularVelocity.copy(s.angularVelocity)):c.hasAngularVelocity=!1,c.eventsEnabled&&c.dispatchEvent({type:"gripUpdated",data:t,target:this})));o!==null&&(n=e.getPose(t.targetRaySpace,i),n===null&&s!==null&&(n=s),n!==null&&(o.matrix.fromArray(n.transform.matrix),o.matrix.decompose(o.position,o.rotation,o.scale),o.matrixWorldNeedsUpdate=!0,n.linearVelocity?(o.hasLinearVelocity=!0,o.linearVelocity.copy(n.linearVelocity)):o.hasLinearVelocity=!1,n.angularVelocity?(o.hasAngularVelocity=!0,o.angularVelocity.copy(n.angularVelocity)):o.hasAngularVelocity=!1,this.dispatchEvent(tx)))}return o!==null&&(o.visible=n!==null),c!==null&&(c.visible=s!==null),l!==null&&(l.visible=r!==null),this}_getHandJoint(t,e){if(t.joints[e.jointName]===void 0){const i=new Re;i.matrixAutoUpdate=!1,i.visible=!1,t.joints[e.jointName]=i,t.add(i)}return t.joints[e.jointName]}}const g1={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},Xs={h:0,s:0,l:0},Dc={h:0,s:0,l:0};function zh(a,t,e){return e<0&&(e+=1),e>1&&(e-=1),e<1/6?a+(t-a)*6*e:e<1/2?t:e<2/3?a+(t-a)*6*(2/3-e):a}class st{constructor(t,e,i){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(t,e,i)}set(t,e,i){if(e===void 0&&i===void 0){const n=t;n&&n.isColor?this.copy(n):typeof n=="number"?this.setHex(n):typeof n=="string"&&this.setStyle(n)}else this.setRGB(t,e,i);return this}setScalar(t){return this.r=t,this.g=t,this.b=t,this}setHex(t,e=qi){return t=Math.floor(t),this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(t&255)/255,ce.colorSpaceToWorking(this,e),this}setRGB(t,e,i,n=ce.workingColorSpace){return this.r=t,this.g=e,this.b=i,ce.colorSpaceToWorking(this,n),this}setHSL(t,e,i,n=ce.workingColorSpace){if(t=U0(t,1),e=Zt(e,0,1),i=Zt(i,0,1),e===0)this.r=this.g=this.b=i;else{const s=i<=.5?i*(1+e):i+e-i*e,r=2*i-s;this.r=zh(r,s,t+1/3),this.g=zh(r,s,t),this.b=zh(r,s,t-1/3)}return ce.colorSpaceToWorking(this,n),this}setStyle(t,e=qi){function i(s){s!==void 0&&parseFloat(s)<1&&It("Color: Alpha component of "+t+" will be ignored.")}let n;if(n=/^(\w+)\(([^\)]*)\)/.exec(t)){let s;const r=n[1],o=n[2];switch(r){case"rgb":case"rgba":if(s=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))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,e);if(s=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))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,e);break;case"hsl":case"hsla":if(s=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return i(s[4]),this.setHSL(parseFloat(s[1])/360,parseFloat(s[2])/100,parseFloat(s[3])/100,e);break;default:It("Color: Unknown color model "+t)}}else if(n=/^\#([A-Fa-f\d]+)$/.exec(t)){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,e);if(r===6)return this.setHex(parseInt(s,16),e);It("Color: Invalid hex color "+t)}else if(t&&t.length>0)return this.setColorName(t,e);return this}setColorName(t,e=qi){const i=g1[t.toLowerCase()];return i!==void 0?this.setHex(i,e):It("Color: Unknown color "+t),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(t){return this.r=t.r,this.g=t.g,this.b=t.b,this}copySRGBToLinear(t){return this.r=Ns(t.r),this.g=Ns(t.g),this.b=Ns(t.b),this}copyLinearToSRGB(t){return this.r=Ha(t.r),this.g=Ha(t.g),this.b=Ha(t.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(t=qi){return ce.workingToColorSpace(Li.copy(this),t),Math.round(Zt(Li.r*255,0,255))*65536+Math.round(Zt(Li.g*255,0,255))*256+Math.round(Zt(Li.b*255,0,255))}getHexString(t=qi){return("000000"+this.getHex(t).toString(16)).slice(-6)}getHSL(t,e=ce.workingColorSpace){ce.workingToColorSpace(Li.copy(this),e);const i=Li.r,n=Li.g,s=Li.b,r=Math.max(i,n,s),o=Math.min(i,n,s);let c,l;const h=(o+r)/2;if(o===r)c=0,l=0;else{const u=r-o;switch(l=h<=.5?u/(r+o):u/(2-r-o),r){case i:c=(n-s)/u+(n<s?6:0);break;case n:c=(s-i)/u+2;break;case s:c=(i-n)/u+4;break}c/=6}return t.h=c,t.s=l,t.l=h,t}getRGB(t,e=ce.workingColorSpace){return ce.workingToColorSpace(Li.copy(this),e),t.r=Li.r,t.g=Li.g,t.b=Li.b,t}getStyle(t=qi){ce.workingToColorSpace(Li.copy(this),t);const e=Li.r,i=Li.g,n=Li.b;return t!==qi?`color(${t} ${e.toFixed(3)} ${i.toFixed(3)} ${n.toFixed(3)})`:`rgb(${Math.round(e*255)},${Math.round(i*255)},${Math.round(n*255)})`}offsetHSL(t,e,i){return this.getHSL(Xs),this.setHSL(Xs.h+t,Xs.s+e,Xs.l+i)}add(t){return this.r+=t.r,this.g+=t.g,this.b+=t.b,this}addColors(t,e){return this.r=t.r+e.r,this.g=t.g+e.g,this.b=t.b+e.b,this}addScalar(t){return this.r+=t,this.g+=t,this.b+=t,this}sub(t){return this.r=Math.max(0,this.r-t.r),this.g=Math.max(0,this.g-t.g),this.b=Math.max(0,this.b-t.b),this}multiply(t){return this.r*=t.r,this.g*=t.g,this.b*=t.b,this}multiplyScalar(t){return this.r*=t,this.g*=t,this.b*=t,this}lerp(t,e){return this.r+=(t.r-this.r)*e,this.g+=(t.g-this.g)*e,this.b+=(t.b-this.b)*e,this}lerpColors(t,e,i){return this.r=t.r+(e.r-t.r)*i,this.g=t.g+(e.g-t.g)*i,this.b=t.b+(e.b-t.b)*i,this}lerpHSL(t,e){this.getHSL(Xs),t.getHSL(Dc);const i=Vo(Xs.h,Dc.h,e),n=Vo(Xs.s,Dc.s,e),s=Vo(Xs.l,Dc.l,e);return this.setHSL(i,n,s),this}setFromVector3(t){return this.r=t.x,this.g=t.y,this.b=t.z,this}applyMatrix3(t){const e=this.r,i=this.g,n=this.b,s=t.elements;return this.r=s[0]*e+s[3]*i+s[6]*n,this.g=s[1]*e+s[4]*i+s[7]*n,this.b=s[2]*e+s[5]*i+s[8]*n,this}equals(t){return t.r===this.r&&t.g===this.g&&t.b===this.b}fromArray(t,e=0){return this.r=t[e],this.g=t[e+1],this.b=t[e+2],this}toArray(t=[],e=0){return t[e]=this.r,t[e+1]=this.g,t[e+2]=this.b,t}fromBufferAttribute(t,e){return this.r=t.getX(e),this.g=t.getY(e),this.b=t.getZ(e),this}toJSON(){return this.getHex()}*[Symbol.iterator](){yield this.r,yield this.g,yield this.b}}const Li=new st;st.NAMES=g1;class B0{constructor(t,e=1,i=1e3){this.isFog=!0,this.name="",this.color=new st(t),this.near=e,this.far=i}clone(){return new B0(this.color,this.near,this.far)}toJSON(){return{type:"Fog",name:this.name,color:this.color.getHex(),near:this.near,far:this.far}}}class ys extends Ge{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 Us,this.environmentIntensity=1,this.environmentRotation=new Us,this.overrideMaterial=null,typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}copy(t,e){return super.copy(t,e),t.background!==null&&(this.background=t.background.clone()),t.environment!==null&&(this.environment=t.environment.clone()),t.fog!==null&&(this.fog=t.fog.clone()),this.backgroundBlurriness=t.backgroundBlurriness,this.backgroundIntensity=t.backgroundIntensity,this.backgroundRotation.copy(t.backgroundRotation),this.environmentIntensity=t.environmentIntensity,this.environmentRotation.copy(t.environmentRotation),t.overrideMaterial!==null&&(this.overrideMaterial=t.overrideMaterial.clone()),this.matrixAutoUpdate=t.matrixAutoUpdate,this}toJSON(t){const e=super.toJSON(t);return this.fog!==null&&(e.object.fog=this.fog.toJSON()),this.backgroundBlurriness>0&&(e.object.backgroundBlurriness=this.backgroundBlurriness),this.backgroundIntensity!==1&&(e.object.backgroundIntensity=this.backgroundIntensity),e.object.backgroundRotation=this.backgroundRotation.toArray(),this.environmentIntensity!==1&&(e.object.environmentIntensity=this.environmentIntensity),e.object.environmentRotation=this.environmentRotation.toArray(),e}}const kn=new R,_s=new R,Bh=new R,bs=new R,ra=new R,aa=new R,mp=new R,Hh=new R,Gh=new R,Vh=new R,Wh=new ae,Xh=new ae,Yh=new ae;class Pn{constructor(t=new R,e=new R,i=new R){this.a=t,this.b=e,this.c=i}static getNormal(t,e,i,n){n.subVectors(i,e),kn.subVectors(t,e),n.cross(kn);const s=n.lengthSq();return s>0?n.multiplyScalar(1/Math.sqrt(s)):n.set(0,0,0)}static getBarycoord(t,e,i,n,s){kn.subVectors(n,e),_s.subVectors(i,e),Bh.subVectors(t,e);const r=kn.dot(kn),o=kn.dot(_s),c=kn.dot(Bh),l=_s.dot(_s),h=_s.dot(Bh),u=r*l-o*o;if(u===0)return s.set(0,0,0),null;const d=1/u,f=(l*c-o*h)*d,p=(r*h-o*c)*d;return s.set(1-f-p,p,f)}static containsPoint(t,e,i,n){return this.getBarycoord(t,e,i,n,bs)===null?!1:bs.x>=0&&bs.y>=0&&bs.x+bs.y<=1}static getInterpolation(t,e,i,n,s,r,o,c){return this.getBarycoord(t,e,i,n,bs)===null?(c.x=0,c.y=0,"z"in c&&(c.z=0),"w"in c&&(c.w=0),null):(c.setScalar(0),c.addScaledVector(s,bs.x),c.addScaledVector(r,bs.y),c.addScaledVector(o,bs.z),c)}static getInterpolatedAttribute(t,e,i,n,s,r){return Wh.setScalar(0),Xh.setScalar(0),Yh.setScalar(0),Wh.fromBufferAttribute(t,e),Xh.fromBufferAttribute(t,i),Yh.fromBufferAttribute(t,n),r.setScalar(0),r.addScaledVector(Wh,s.x),r.addScaledVector(Xh,s.y),r.addScaledVector(Yh,s.z),r}static isFrontFacing(t,e,i,n){return kn.subVectors(i,e),_s.subVectors(t,e),kn.cross(_s).dot(n)<0}set(t,e,i){return this.a.copy(t),this.b.copy(e),this.c.copy(i),this}setFromPointsAndIndices(t,e,i,n){return this.a.copy(t[e]),this.b.copy(t[i]),this.c.copy(t[n]),this}setFromAttributeAndIndices(t,e,i,n){return this.a.fromBufferAttribute(t,e),this.b.fromBufferAttribute(t,i),this.c.fromBufferAttribute(t,n),this}clone(){return new this.constructor().copy(this)}copy(t){return this.a.copy(t.a),this.b.copy(t.b),this.c.copy(t.c),this}getArea(){return kn.subVectors(this.c,this.b),_s.subVectors(this.a,this.b),kn.cross(_s).length()*.5}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return Pn.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return Pn.getBarycoord(t,this.a,this.b,this.c,e)}getInterpolation(t,e,i,n,s){return Pn.getInterpolation(t,this.a,this.b,this.c,e,i,n,s)}containsPoint(t){return Pn.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return Pn.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(t){return t.intersectsTriangle(this)}closestPointToPoint(t,e){const i=this.a,n=this.b,s=this.c;let r,o;ra.subVectors(n,i),aa.subVectors(s,i),Hh.subVectors(t,i);const c=ra.dot(Hh),l=aa.dot(Hh);if(c<=0&&l<=0)return e.copy(i);Gh.subVectors(t,n);const h=ra.dot(Gh),u=aa.dot(Gh);if(h>=0&&u<=h)return e.copy(n);const d=c*u-h*l;if(d<=0&&c>=0&&h<=0)return r=c/(c-h),e.copy(i).addScaledVector(ra,r);Vh.subVectors(t,s);const f=ra.dot(Vh),p=aa.dot(Vh);if(p>=0&&f<=p)return e.copy(s);const v=f*l-c*p;if(v<=0&&l>=0&&p<=0)return o=l/(l-p),e.copy(i).addScaledVector(aa,o);const m=h*p-f*u;if(m<=0&&u-h>=0&&f-p>=0)return mp.subVectors(s,n),o=(u-h)/(u-h+(f-p)),e.copy(n).addScaledVector(mp,o);const g=1/(m+v+d);return r=v*g,o=d*g,e.copy(i).addScaledVector(ra,r).addScaledVector(aa,o)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}}class ki{constructor(t=new R(1/0,1/0,1/0),e=new R(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=t,this.max=e}set(t,e){return this.min.copy(t),this.max.copy(e),this}setFromArray(t){this.makeEmpty();for(let e=0,i=t.length;e<i;e+=3)this.expandByPoint(zn.fromArray(t,e));return this}setFromBufferAttribute(t){this.makeEmpty();for(let e=0,i=t.count;e<i;e++)this.expandByPoint(zn.fromBufferAttribute(t,e));return this}setFromPoints(t){this.makeEmpty();for(let e=0,i=t.length;e<i;e++)this.expandByPoint(t[e]);return this}setFromCenterAndSize(t,e){const i=zn.copy(e).multiplyScalar(.5);return this.min.copy(t).sub(i),this.max.copy(t).add(i),this}setFromObject(t,e=!1){return this.makeEmpty(),this.expandByObject(t,e)}clone(){return new this.constructor().copy(this)}copy(t){return this.min.copy(t.min),this.max.copy(t.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(t){return this.isEmpty()?t.set(0,0,0):t.addVectors(this.min,this.max).multiplyScalar(.5)}getSize(t){return this.isEmpty()?t.set(0,0,0):t.subVectors(this.max,this.min)}expandByPoint(t){return this.min.min(t),this.max.max(t),this}expandByVector(t){return this.min.sub(t),this.max.add(t),this}expandByScalar(t){return this.min.addScalar(-t),this.max.addScalar(t),this}expandByObject(t,e=!1){t.updateWorldMatrix(!1,!1);const i=t.geometry;if(i!==void 0){const s=i.getAttribute("position");if(e===!0&&s!==void 0&&t.isInstancedMesh!==!0)for(let r=0,o=s.count;r<o;r++)t.isMesh===!0?t.getVertexPosition(r,zn):zn.fromBufferAttribute(s,r),zn.applyMatrix4(t.matrixWorld),this.expandByPoint(zn);else t.boundingBox!==void 0?(t.boundingBox===null&&t.computeBoundingBox(),Ic.copy(t.boundingBox)):(i.boundingBox===null&&i.computeBoundingBox(),Ic.copy(i.boundingBox)),Ic.applyMatrix4(t.matrixWorld),this.union(Ic)}const n=t.children;for(let s=0,r=n.length;s<r;s++)this.expandByObject(n[s],e);return this}containsPoint(t){return t.x>=this.min.x&&t.x<=this.max.x&&t.y>=this.min.y&&t.y<=this.max.y&&t.z>=this.min.z&&t.z<=this.max.z}containsBox(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y&&this.min.z<=t.min.z&&t.max.z<=this.max.z}getParameter(t,e){return e.set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y),(t.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(t){return t.max.x>=this.min.x&&t.min.x<=this.max.x&&t.max.y>=this.min.y&&t.min.y<=this.max.y&&t.max.z>=this.min.z&&t.min.z<=this.max.z}intersectsSphere(t){return this.clampPoint(t.center,zn),zn.distanceToSquared(t.center)<=t.radius*t.radius}intersectsPlane(t){let e,i;return t.normal.x>0?(e=t.normal.x*this.min.x,i=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,i=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,i+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,i+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,i+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,i+=t.normal.z*this.min.z),e<=-t.constant&&i>=-t.constant}intersectsTriangle(t){if(this.isEmpty())return!1;this.getCenter(lo),Cc.subVectors(this.max,lo),oa.subVectors(t.a,lo),ca.subVectors(t.b,lo),la.subVectors(t.c,lo),Ys.subVectors(ca,oa),qs.subVectors(la,ca),yr.subVectors(oa,la);let e=[0,-Ys.z,Ys.y,0,-qs.z,qs.y,0,-yr.z,yr.y,Ys.z,0,-Ys.x,qs.z,0,-qs.x,yr.z,0,-yr.x,-Ys.y,Ys.x,0,-qs.y,qs.x,0,-yr.y,yr.x,0];return!qh(e,oa,ca,la,Cc)||(e=[1,0,0,0,1,0,0,0,1],!qh(e,oa,ca,la,Cc))?!1:(Pc.crossVectors(Ys,qs),e=[Pc.x,Pc.y,Pc.z],qh(e,oa,ca,la,Cc))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,zn).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=this.getSize(zn).length()*.5),t}intersect(t){return this.min.max(t.min),this.max.min(t.max),this.isEmpty()&&this.makeEmpty(),this}union(t){return this.min.min(t.min),this.max.max(t.max),this}applyMatrix4(t){return this.isEmpty()?this:(ws[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),ws[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),ws[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),ws[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),ws[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),ws[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),ws[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),ws[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(ws),this)}translate(t){return this.min.add(t),this.max.add(t),this}equals(t){return t.min.equals(this.min)&&t.max.equals(this.max)}toJSON(){return{min:this.min.toArray(),max:this.max.toArray()}}fromJSON(t){return this.min.fromArray(t.min),this.max.fromArray(t.max),this}}const ws=[new R,new R,new R,new R,new R,new R,new R,new R],zn=new R,Ic=new ki,oa=new R,ca=new R,la=new R,Ys=new R,qs=new R,yr=new R,lo=new R,Cc=new R,Pc=new R,Sr=new R;function qh(a,t,e,i,n){for(let s=0,r=a.length-3;s<=r;s+=3){Sr.fromArray(a,s);const o=n.x*Math.abs(Sr.x)+n.y*Math.abs(Sr.y)+n.z*Math.abs(Sr.z),c=t.dot(Sr),l=e.dot(Sr),h=i.dot(Sr);if(Math.max(-Math.max(c,l,h),Math.min(c,l,h))>o)return!1}return!0}const Ps=ex();function ex(){const a=new ArrayBuffer(4),t=new Float32Array(a),e=new Uint32Array(a),i=new Uint32Array(512),n=new Uint32Array(512);for(let c=0;c<256;++c){const l=c-127;l<-27?(i[c]=0,i[c|256]=32768,n[c]=24,n[c|256]=24):l<-14?(i[c]=1024>>-l-14,i[c|256]=1024>>-l-14|32768,n[c]=-l-1,n[c|256]=-l-1):l<=15?(i[c]=l+15<<10,i[c|256]=l+15<<10|32768,n[c]=13,n[c|256]=13):l<128?(i[c]=31744,i[c|256]=64512,n[c]=24,n[c|256]=24):(i[c]=31744,i[c|256]=64512,n[c]=13,n[c|256]=13)}const s=new Uint32Array(2048),r=new Uint32Array(64),o=new Uint32Array(64);for(let c=1;c<1024;++c){let l=c<<13,h=0;for(;(l&8388608)===0;)l<<=1,h-=8388608;l&=-8388609,h+=947912704,s[c]=l|h}for(let c=1024;c<2048;++c)s[c]=939524096+(c-1024<<13);for(let c=1;c<31;++c)r[c]=c<<23;r[31]=1199570944,r[32]=2147483648;for(let c=33;c<63;++c)r[c]=2147483648+(c-32<<23);r[63]=3347054592;for(let c=1;c<64;++c)c!==32&&(o[c]=1024);return{floatView:t,uint32View:e,baseTable:i,shiftTable:n,mantissaTable:s,exponentTable:r,offsetTable:o}}function ix(a){Math.abs(a)>65504&&It("DataUtils.toHalfFloat(): Value out of range."),a=Zt(a,-65504,65504),Ps.floatView[0]=a;const t=Ps.uint32View[0],e=t>>23&511;return Ps.baseTable[e]+((t&8388607)>>Ps.shiftTable[e])}function nx(a){const t=a>>10;return Ps.uint32View[0]=Ps.mantissaTable[Ps.offsetTable[t]+(a&1023)]+Ps.exponentTable[t],Ps.floatView[0]}class Ln{static toHalfFloat(t){return ix(t)}static fromHalfFloat(t){return nx(t)}}const pi=new R,Lc=new Mt;let sx=0;class Jt extends vr{constructor(t,e,i=!1){if(super(),Array.isArray(t))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,Object.defineProperty(this,"id",{value:sx++}),this.name="",this.array=t,this.itemSize=e,this.count=t!==void 0?t.length/e:0,this.normalized=i,this.usage=Bd,this.updateRanges=[],this.gpuType=Ui,this.version=0}onUploadCallback(){}set needsUpdate(t){t===!0&&this.version++}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.name=t.name,this.array=new t.array.constructor(t.array),this.itemSize=t.itemSize,this.count=t.count,this.normalized=t.normalized,this.usage=t.usage,this.gpuType=t.gpuType,this}copyAt(t,e,i){t*=this.itemSize,i*=e.itemSize;for(let n=0,s=this.itemSize;n<s;n++)this.array[t+n]=e.array[i+n];return this}copyArray(t){return this.array.set(t),this}applyMatrix3(t){if(this.itemSize===2)for(let e=0,i=this.count;e<i;e++)Lc.fromBufferAttribute(this,e),Lc.applyMatrix3(t),this.setXY(e,Lc.x,Lc.y);else if(this.itemSize===3)for(let e=0,i=this.count;e<i;e++)pi.fromBufferAttribute(this,e),pi.applyMatrix3(t),this.setXYZ(e,pi.x,pi.y,pi.z);return this}applyMatrix4(t){for(let e=0,i=this.count;e<i;e++)pi.fromBufferAttribute(this,e),pi.applyMatrix4(t),this.setXYZ(e,pi.x,pi.y,pi.z);return this}applyNormalMatrix(t){for(let e=0,i=this.count;e<i;e++)pi.fromBufferAttribute(this,e),pi.applyNormalMatrix(t),this.setXYZ(e,pi.x,pi.y,pi.z);return this}transformDirection(t){for(let e=0,i=this.count;e<i;e++)pi.fromBufferAttribute(this,e),pi.transformDirection(t),this.setXYZ(e,pi.x,pi.y,pi.z);return this}set(t,e=0){return this.array.set(t,e),this}getComponent(t,e){let i=this.array[t*this.itemSize+e];return this.normalized&&(i=qn(i,this.array)),i}setComponent(t,e,i){return this.normalized&&(i=Ee(i,this.array)),this.array[t*this.itemSize+e]=i,this}getX(t){let e=this.array[t*this.itemSize];return this.normalized&&(e=qn(e,this.array)),e}setX(t,e){return this.normalized&&(e=Ee(e,this.array)),this.array[t*this.itemSize]=e,this}getY(t){let e=this.array[t*this.itemSize+1];return this.normalized&&(e=qn(e,this.array)),e}setY(t,e){return this.normalized&&(e=Ee(e,this.array)),this.array[t*this.itemSize+1]=e,this}getZ(t){let e=this.array[t*this.itemSize+2];return this.normalized&&(e=qn(e,this.array)),e}setZ(t,e){return this.normalized&&(e=Ee(e,this.array)),this.array[t*this.itemSize+2]=e,this}getW(t){let e=this.array[t*this.itemSize+3];return this.normalized&&(e=qn(e,this.array)),e}setW(t,e){return this.normalized&&(e=Ee(e,this.array)),this.array[t*this.itemSize+3]=e,this}setXY(t,e,i){return t*=this.itemSize,this.normalized&&(e=Ee(e,this.array),i=Ee(i,this.array)),this.array[t+0]=e,this.array[t+1]=i,this}setXYZ(t,e,i,n){return t*=this.itemSize,this.normalized&&(e=Ee(e,this.array),i=Ee(i,this.array),n=Ee(n,this.array)),this.array[t+0]=e,this.array[t+1]=i,this.array[t+2]=n,this}setXYZW(t,e,i,n,s){return t*=this.itemSize,this.normalized&&(e=Ee(e,this.array),i=Ee(i,this.array),n=Ee(n,this.array),s=Ee(s,this.array)),this.array[t+0]=e,this.array[t+1]=i,this.array[t+2]=n,this.array[t+3]=s,this}onUpload(t){return this.onUploadCallback=t,this}clone(){return new this.constructor(this.array,this.itemSize).copy(this)}toJSON(){const t={itemSize:this.itemSize,type:this.array.constructor.name,array:Array.from(this.array),normalized:this.normalized};return this.name!==""&&(t.name=this.name),this.usage!==Bd&&(t.usage=this.usage),t}dispose(){this.dispatchEvent({type:"dispose"})}}class v1 extends Jt{constructor(t,e,i){super(new Uint16Array(t),e,i)}}class H0 extends Jt{constructor(t,e,i){super(new Uint32Array(t),e,i)}}class de extends Jt{constructor(t,e,i){super(new Float32Array(t),e,i)}}const rx=new ki,ho=new R,$h=new R;class ks{constructor(t=new R,e=-1){this.isSphere=!0,this.center=t,this.radius=e}set(t,e){return this.center.copy(t),this.radius=e,this}setFromPoints(t,e){const i=this.center;e!==void 0?i.copy(e):rx.setFromPoints(t).getCenter(i);let n=0;for(let s=0,r=t.length;s<r;s++)n=Math.max(n,i.distanceToSquared(t[s]));return this.radius=Math.sqrt(n),this}copy(t){return this.center.copy(t.center),this.radius=t.radius,this}isEmpty(){return this.radius<0}makeEmpty(){return this.center.set(0,0,0),this.radius=-1,this}containsPoint(t){return t.distanceToSquared(this.center)<=this.radius*this.radius}distanceToPoint(t){return t.distanceTo(this.center)-this.radius}intersectsSphere(t){const e=this.radius+t.radius;return t.center.distanceToSquared(this.center)<=e*e}intersectsBox(t){return t.intersectsSphere(this)}intersectsPlane(t){return Math.abs(t.distanceToPoint(this.center))<=this.radius}clampPoint(t,e){const i=this.center.distanceToSquared(t);return e.copy(t),i>this.radius*this.radius&&(e.sub(this.center).normalize(),e.multiplyScalar(this.radius).add(this.center)),e}getBoundingBox(t){return this.isEmpty()?(t.makeEmpty(),t):(t.set(this.center,this.center),t.expandByScalar(this.radius),t)}applyMatrix4(t){return this.center.applyMatrix4(t),this.radius=this.radius*t.getMaxScaleOnAxis(),this}translate(t){return this.center.add(t),this}expandByPoint(t){if(this.isEmpty())return this.center.copy(t),this.radius=0,this;ho.subVectors(t,this.center);const e=ho.lengthSq();if(e>this.radius*this.radius){const i=Math.sqrt(e),n=(i-this.radius)*.5;this.center.addScaledVector(ho,n/i),this.radius+=n}return this}union(t){return t.isEmpty()?this:this.isEmpty()?(this.copy(t),this):(this.center.equals(t.center)===!0?this.radius=Math.max(this.radius,t.radius):($h.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint(ho.copy(t.center).add($h)),this.expandByPoint(ho.copy(t.center).sub($h))),this)}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return new this.constructor().copy(this)}toJSON(){return{radius:this.radius,center:this.center.toArray()}}fromJSON(t){return this.radius=t.radius,this.center.fromArray(t.center),this}}let ax=0;const En=new te,Kh=new Ge,ha=new R,hn=new ki,uo=new ki,yi=new R;class se extends vr{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:ax++}),this.uuid=Kn(),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(t){return Array.isArray(t)?this.index=new(_M(t)?H0:v1)(t,1):this.index=t,this}setIndirect(t,e=0){return this.indirect=t,this.indirectOffset=e,this}getIndirect(){return this.indirect}getAttribute(t){return this.attributes[t]}setAttribute(t,e){return this.attributes[t]=e,this}deleteAttribute(t){return delete this.attributes[t],this}hasAttribute(t){return this.attributes[t]!==void 0}addGroup(t,e,i=0){this.groups.push({start:t,count:e,materialIndex:i})}clearGroups(){this.groups=[]}setDrawRange(t,e){this.drawRange.start=t,this.drawRange.count=e}applyMatrix4(t){const e=this.attributes.position;e!==void 0&&(e.applyMatrix4(t),e.needsUpdate=!0);const i=this.attributes.normal;if(i!==void 0){const s=new $t().getNormalMatrix(t);i.applyNormalMatrix(s),i.needsUpdate=!0}const n=this.attributes.tangent;return n!==void 0&&(n.transformDirection(t),n.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this._transformed=!0,this}applyQuaternion(t){return En.makeRotationFromQuaternion(t),this.applyMatrix4(En),this}rotateX(t){return En.makeRotationX(t),this.applyMatrix4(En),this}rotateY(t){return En.makeRotationY(t),this.applyMatrix4(En),this}rotateZ(t){return En.makeRotationZ(t),this.applyMatrix4(En),this}translate(t,e,i){return En.makeTranslation(t,e,i),this.applyMatrix4(En),this}scale(t,e,i){return En.makeScale(t,e,i),this.applyMatrix4(En),this}lookAt(t){return Kh.lookAt(t),Kh.updateMatrix(),this.applyMatrix4(Kh.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(ha).negate(),this.translate(ha.x,ha.y,ha.z),this}setFromPoints(t){const e=this.getAttribute("position");if(e===void 0){const i=[];for(let n=0,s=t.length;n<s;n++){const r=t[n];i.push(r.x,r.y,r.z||0)}this.setAttribute("position",new de(i,3))}else{const i=Math.min(t.length,e.count);for(let n=0;n<i;n++){const s=t[n];e.setXYZ(n,s.x,s.y,s.z||0)}t.length>e.count&&It("BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry."),e.needsUpdate=!0}return this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new ki);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){Wt("BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),this.boundingBox.set(new R(-1/0,-1/0,-1/0),new R(1/0,1/0,1/0));return}if(t!==void 0){if(this.boundingBox.setFromBufferAttribute(t),e)for(let i=0,n=e.length;i<n;i++){const s=e[i];hn.setFromBufferAttribute(s),this.morphTargetsRelative?(yi.addVectors(this.boundingBox.min,hn.min),this.boundingBox.expandByPoint(yi),yi.addVectors(this.boundingBox.max,hn.max),this.boundingBox.expandByPoint(yi)):(this.boundingBox.expandByPoint(hn.min),this.boundingBox.expandByPoint(hn.max))}}else this.boundingBox.makeEmpty();(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z))&&Wt('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 ks);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){Wt("BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.",this),this.boundingSphere.set(new R,1/0);return}if(t){const i=this.boundingSphere.center;if(hn.setFromBufferAttribute(t),e)for(let s=0,r=e.length;s<r;s++){const o=e[s];uo.setFromBufferAttribute(o),this.morphTargetsRelative?(yi.addVectors(hn.min,uo.min),hn.expandByPoint(yi),yi.addVectors(hn.max,uo.max),hn.expandByPoint(yi)):(hn.expandByPoint(uo.min),hn.expandByPoint(uo.max))}hn.getCenter(i);let n=0;for(let s=0,r=t.count;s<r;s++)yi.fromBufferAttribute(t,s),n=Math.max(n,i.distanceToSquared(yi));if(e)for(let s=0,r=e.length;s<r;s++){const o=e[s],c=this.morphTargetsRelative;for(let l=0,h=o.count;l<h;l++)yi.fromBufferAttribute(o,l),c&&(ha.fromBufferAttribute(t,l),yi.add(ha)),n=Math.max(n,i.distanceToSquared(yi))}this.boundingSphere.radius=Math.sqrt(n),isNaN(this.boundingSphere.radius)&&Wt('BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',this)}}computeTangents(){const t=this.index,e=this.attributes;if(t===null||e.position===void 0||e.normal===void 0||e.uv===void 0){Wt("BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)");return}const i=e.position,n=e.normal,s=e.uv;let r=this.getAttribute("tangent");(r===void 0||r.count!==i.count)&&(r=new Jt(new Float32Array(4*i.count),4),this.setAttribute("tangent",r));const o=[],c=[];for(let y=0;y<i.count;y++)o[y]=new R,c[y]=new R;const l=new R,h=new R,u=new R,d=new Mt,f=new Mt,p=new Mt,v=new R,m=new R;function g(y,A,C){l.fromBufferAttribute(i,y),h.fromBufferAttribute(i,A),u.fromBufferAttribute(i,C),d.fromBufferAttribute(s,y),f.fromBufferAttribute(s,A),p.fromBufferAttribute(s,C),h.sub(l),u.sub(l),f.sub(d),p.sub(d);const I=1/(f.x*p.y-p.x*f.y);isFinite(I)&&(v.copy(h).multiplyScalar(p.y).addScaledVector(u,-f.y).multiplyScalar(I),m.copy(u).multiplyScalar(f.x).addScaledVector(h,-p.x).multiplyScalar(I),o[y].add(v),o[A].add(v),o[C].add(v),c[y].add(m),c[A].add(m),c[C].add(m))}let S=this.groups;S.length===0&&(S=[{start:0,count:t.count}]);for(let y=0,A=S.length;y<A;++y){const C=S[y],I=C.start,P=C.count;for(let V=I,X=I+P;V<X;V+=3)g(t.getX(V+0),t.getX(V+1),t.getX(V+2))}const x=new R,M=new R,b=new R,w=new R;function T(y){b.fromBufferAttribute(n,y),w.copy(b);const A=o[y];x.copy(A),x.sub(b.multiplyScalar(b.dot(A))).normalize(),M.crossVectors(w,A);const I=M.dot(c[y])<0?-1:1;r.setXYZW(y,x.x,x.y,x.z,I)}for(let y=0,A=S.length;y<A;++y){const C=S[y],I=C.start,P=C.count;for(let V=I,X=I+P;V<X;V+=3)T(t.getX(V+0)),T(t.getX(V+1)),T(t.getX(V+2))}this._transformed=!0}computeVertexNormals(){const t=this.index,e=this.getAttribute("position");if(e!==void 0){let i=this.getAttribute("normal");if(i===void 0||i.count!==e.count)i=new Jt(new Float32Array(e.count*3),3),this.setAttribute("normal",i);else for(let d=0,f=i.count;d<f;d++)i.setXYZ(d,0,0,0);const n=new R,s=new R,r=new R,o=new R,c=new R,l=new R,h=new R,u=new R;if(t)for(let d=0,f=t.count;d<f;d+=3){const p=t.getX(d+0),v=t.getX(d+1),m=t.getX(d+2);n.fromBufferAttribute(e,p),s.fromBufferAttribute(e,v),r.fromBufferAttribute(e,m),h.subVectors(r,s),u.subVectors(n,s),h.cross(u),o.fromBufferAttribute(i,p),c.fromBufferAttribute(i,v),l.fromBufferAttribute(i,m),o.add(h),c.add(h),l.add(h),i.setXYZ(p,o.x,o.y,o.z),i.setXYZ(v,c.x,c.y,c.z),i.setXYZ(m,l.x,l.y,l.z)}else for(let d=0,f=e.count;d<f;d+=3)n.fromBufferAttribute(e,d+0),s.fromBufferAttribute(e,d+1),r.fromBufferAttribute(e,d+2),h.subVectors(r,s),u.subVectors(n,s),h.cross(u),i.setXYZ(d+0,h.x,h.y,h.z),i.setXYZ(d+1,h.x,h.y,h.z),i.setXYZ(d+2,h.x,h.y,h.z);this.normalizeNormals(),i.needsUpdate=!0}}normalizeNormals(){const t=this.attributes.normal;for(let e=0,i=t.count;e<i;e++)yi.fromBufferAttribute(t,e),yi.normalize(),t.setXYZ(e,yi.x,yi.y,yi.z)}toNonIndexed(){function t(o,c){const l=o.array,h=o.itemSize,u=o.normalized,d=new l.constructor(c.length*h);let f=0,p=0;for(let v=0,m=c.length;v<m;v++){o.isInterleavedBufferAttribute?f=c[v]*o.data.stride+o.offset:f=c[v]*h;for(let g=0;g<h;g++)d[p++]=l[f++]}return new Jt(d,h,u)}if(this.index===null)return It("BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."),this;const e=new se,i=this.index.array,n=this.attributes;for(const o in n){const c=n[o],l=t(c,i);e.setAttribute(o,l)}const s=this.morphAttributes;for(const o in s){const c=[],l=s[o];for(let h=0,u=l.length;h<u;h++){const d=l[h],f=t(d,i);c.push(f)}e.morphAttributes[o]=c}e.morphTargetsRelative=this.morphTargetsRelative;const r=this.groups;for(let o=0,c=r.length;o<c;o++){const l=r[o];e.addGroup(l.start,l.count,l.materialIndex)}return e}toJSON(){const t={metadata:{version:4.7,type:"BufferGeometry",generator:"BufferGeometry.toJSON"}};if(t.uuid=this.uuid,t.type=this.parameters!==void 0&&this._transformed===!0?"BufferGeometry":this.type,this.name!==""&&(t.name=this.name),Object.keys(this.userData).length>0&&(t.userData=this.userData),this.parameters!==void 0&&this._transformed!==!0){const c=this.parameters;for(const l in c)c[l]!==void 0&&(t[l]=c[l]);return t}t.data={attributes:{}};const e=this.index;e!==null&&(t.data.index={type:e.array.constructor.name,array:Array.prototype.slice.call(e.array)});const i=this.attributes;for(const c in i){const l=i[c];t.data.attributes[c]=l.toJSON(t.data)}const n={};let s=!1;for(const c in this.morphAttributes){const l=this.morphAttributes[c],h=[];for(let u=0,d=l.length;u<d;u++){const f=l[u];h.push(f.toJSON(t.data))}h.length>0&&(n[c]=h,s=!0)}s&&(t.data.morphAttributes=n,t.data.morphTargetsRelative=this.morphTargetsRelative);const r=this.groups;r.length>0&&(t.data.groups=JSON.parse(JSON.stringify(r)));const o=this.boundingSphere;return o!==null&&(t.data.boundingSphere=o.toJSON()),t}clone(){return new this.constructor().copy(this)}copy(t){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const e={};this.name=t.name;const i=t.index;i!==null&&this.setIndex(i.clone());const n=t.attributes;for(const l in n){const h=n[l];this.setAttribute(l,h.clone(e))}const s=t.morphAttributes;for(const l in s){const h=[],u=s[l];for(let d=0,f=u.length;d<f;d++)h.push(u[d].clone(e));this.morphAttributes[l]=h}this.morphTargetsRelative=t.morphTargetsRelative;const r=t.groups;for(let l=0,h=r.length;l<h;l++){const u=r[l];this.addGroup(u.start,u.count,u.materialIndex)}const o=t.boundingBox;o!==null&&(this.boundingBox=o.clone());const c=t.boundingSphere;return c!==null&&(this.boundingSphere=c.clone()),this.drawRange.start=t.drawRange.start,this.drawRange.count=t.drawRange.count,this.userData=t.userData,this._transformed=t._transformed,this}dispose(){this.dispatchEvent({type:"dispose"})}}class M1{constructor(t,e){this.isInterleavedBuffer=!0,this.array=t,this.stride=e,this.count=t!==void 0?t.length/e:0,this.usage=Bd,this.updateRanges=[],this.version=0,this.uuid=Kn()}onUploadCallback(){}set needsUpdate(t){t===!0&&this.version++}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.array=new t.array.constructor(t.array),this.count=t.count,this.stride=t.stride,this.usage=t.usage,this}copyAt(t,e,i){t*=this.stride,i*=e.stride;for(let n=0,s=this.stride;n<s;n++)this.array[t+n]=e.array[i+n];return this}set(t,e=0){return this.array.set(t,e),this}clone(t){t.arrayBuffers===void 0&&(t.arrayBuffers={}),this.array.buffer._uuid===void 0&&(this.array.buffer._uuid=Kn()),t.arrayBuffers[this.array.buffer._uuid]===void 0&&(t.arrayBuffers[this.array.buffer._uuid]=this.array.slice(0).buffer);const e=new this.array.constructor(t.arrayBuffers[this.array.buffer._uuid]),i=new this.constructor(e,this.stride);return i.setUsage(this.usage),i}onUpload(t){return this.onUploadCallback=t,this}toJSON(t){return t.arrayBuffers===void 0&&(t.arrayBuffers={}),this.array.buffer._uuid===void 0&&(this.array.buffer._uuid=Kn()),t.arrayBuffers[this.array.buffer._uuid]===void 0&&(t.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 zi=new R;class ql{constructor(t,e,i,n=!1){this.isInterleavedBufferAttribute=!0,this.name="",this.data=t,this.itemSize=e,this.offset=i,this.normalized=n}get count(){return this.data.count}get array(){return this.data.array}set needsUpdate(t){this.data.needsUpdate=t}applyMatrix4(t){for(let e=0,i=this.data.count;e<i;e++)zi.fromBufferAttribute(this,e),zi.applyMatrix4(t),this.setXYZ(e,zi.x,zi.y,zi.z);return this}applyNormalMatrix(t){for(let e=0,i=this.count;e<i;e++)zi.fromBufferAttribute(this,e),zi.applyNormalMatrix(t),this.setXYZ(e,zi.x,zi.y,zi.z);return this}transformDirection(t){for(let e=0,i=this.count;e<i;e++)zi.fromBufferAttribute(this,e),zi.transformDirection(t),this.setXYZ(e,zi.x,zi.y,zi.z);return this}getComponent(t,e){let i=this.array[t*this.data.stride+this.offset+e];return this.normalized&&(i=qn(i,this.array)),i}setComponent(t,e,i){return this.normalized&&(i=Ee(i,this.array)),this.data.array[t*this.data.stride+this.offset+e]=i,this}setX(t,e){return this.normalized&&(e=Ee(e,this.array)),this.data.array[t*this.data.stride+this.offset]=e,this}setY(t,e){return this.normalized&&(e=Ee(e,this.array)),this.data.array[t*this.data.stride+this.offset+1]=e,this}setZ(t,e){return this.normalized&&(e=Ee(e,this.array)),this.data.array[t*this.data.stride+this.offset+2]=e,this}setW(t,e){return this.normalized&&(e=Ee(e,this.array)),this.data.array[t*this.data.stride+this.offset+3]=e,this}getX(t){let e=this.data.array[t*this.data.stride+this.offset];return this.normalized&&(e=qn(e,this.array)),e}getY(t){let e=this.data.array[t*this.data.stride+this.offset+1];return this.normalized&&(e=qn(e,this.array)),e}getZ(t){let e=this.data.array[t*this.data.stride+this.offset+2];return this.normalized&&(e=qn(e,this.array)),e}getW(t){let e=this.data.array[t*this.data.stride+this.offset+3];return this.normalized&&(e=qn(e,this.array)),e}setXY(t,e,i){return t=t*this.data.stride+this.offset,this.normalized&&(e=Ee(e,this.array),i=Ee(i,this.array)),this.data.array[t+0]=e,this.data.array[t+1]=i,this}setXYZ(t,e,i,n){return t=t*this.data.stride+this.offset,this.normalized&&(e=Ee(e,this.array),i=Ee(i,this.array),n=Ee(n,this.array)),this.data.array[t+0]=e,this.data.array[t+1]=i,this.data.array[t+2]=n,this}setXYZW(t,e,i,n,s){return t=t*this.data.stride+this.offset,this.normalized&&(e=Ee(e,this.array),i=Ee(i,this.array),n=Ee(n,this.array),s=Ee(s,this.array)),this.data.array[t+0]=e,this.data.array[t+1]=i,this.data.array[t+2]=n,this.data.array[t+3]=s,this}clone(t){if(t===void 0){Yl("InterleavedBufferAttribute.clone(): Cloning an interleaved buffer attribute will de-interleave buffer data.");const e=[];for(let i=0;i<this.count;i++){const n=i*this.data.stride+this.offset;for(let s=0;s<this.itemSize;s++)e.push(this.data.array[n+s])}return new Jt(new this.array.constructor(e),this.itemSize,this.normalized)}else return t.interleavedBuffers===void 0&&(t.interleavedBuffers={}),t.interleavedBuffers[this.data.uuid]===void 0&&(t.interleavedBuffers[this.data.uuid]=this.data.clone(t)),new ql(t.interleavedBuffers[this.data.uuid],this.itemSize,this.offset,this.normalized)}toJSON(t){if(t===void 0){Yl("InterleavedBufferAttribute.toJSON(): Serializing an interleaved buffer attribute will de-interleave buffer data.");const e=[];for(let i=0;i<this.count;i++){const n=i*this.data.stride+this.offset;for(let s=0;s<this.itemSize;s++)e.push(this.data.array[n+s])}return{itemSize:this.itemSize,type:this.array.constructor.name,array:e,normalized:this.normalized}}else return t.interleavedBuffers===void 0&&(t.interleavedBuffers={}),t.interleavedBuffers[this.data.uuid]===void 0&&(t.interleavedBuffers[this.data.uuid]=this.data.toJSON(t)),{isInterleavedBufferAttribute:!0,itemSize:this.itemSize,data:this.data.uuid,offset:this.offset,normalized:this.normalized}}}let ox=0;class zs extends vr{constructor(){super(),this.isMaterial=!0,Object.defineProperty(this,"id",{value:ox++}),this.uuid=Kn(),this.name="",this.type="Material",this.blending=dr,this.side=pr,this.vertexColors=!1,this.opacity=1,this.transparent=!1,this.alphaHash=!1,this.blendSrc=td,this.blendDst=nc,this.blendEquation=Dr,this.blendSrcAlpha=null,this.blendDstAlpha=null,this.blendEquationAlpha=null,this.blendColor=new st(0,0,0),this.blendAlpha=0,this.depthFunc=Ja,this.depthTest=!0,this.depthWrite=!0,this.stencilWriteMask=255,this.stencilFunc=ip,this.stencilRef=0,this.stencilFuncMask=255,this.stencilFail=ta,this.stencilZFail=ta,this.stencilZPass=ta,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(t){this._alphaTest>0!=t>0&&this.version++,this._alphaTest=t}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(t){if(t!==void 0)for(const e in t){const i=t[e];if(i===void 0){It(`Material: parameter '${e}' has value of undefined.`);continue}const n=this[e];if(n===void 0){It(`Material: '${e}' 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[e]=i}}toJSON(t){const e=t===void 0||typeof t=="string";e&&(t={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(t).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(i.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(t).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(i.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(t).uuid,i.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),this.sheenColorMap&&this.sheenColorMap.isTexture&&(i.sheenColorMap=this.sheenColorMap.toJSON(t).uuid),this.sheenRoughnessMap&&this.sheenRoughnessMap.isTexture&&(i.sheenRoughnessMap=this.sheenRoughnessMap.toJSON(t).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(t).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(i.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(t).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(t).uuid),this.map&&this.map.isTexture&&(i.map=this.map.toJSON(t).uuid),this.matcap&&this.matcap.isTexture&&(i.matcap=this.matcap.toJSON(t).uuid),this.alphaMap&&this.alphaMap.isTexture&&(i.alphaMap=this.alphaMap.toJSON(t).uuid),this.lightMap&&this.lightMap.isTexture&&(i.lightMap=this.lightMap.toJSON(t).uuid,i.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(i.aoMap=this.aoMap.toJSON(t).uuid,i.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(i.bumpMap=this.bumpMap.toJSON(t).uuid,i.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(i.normalMap=this.normalMap.toJSON(t).uuid,i.normalMapType=this.normalMapType,i.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(i.displacementMap=this.displacementMap.toJSON(t).uuid,i.displacementScale=this.displacementScale,i.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(i.roughnessMap=this.roughnessMap.toJSON(t).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(i.metalnessMap=this.metalnessMap.toJSON(t).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(i.emissiveMap=this.emissiveMap.toJSON(t).uuid),this.specularMap&&this.specularMap.isTexture&&(i.specularMap=this.specularMap.toJSON(t).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(i.specularIntensityMap=this.specularIntensityMap.toJSON(t).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(i.specularColorMap=this.specularColorMap.toJSON(t).uuid),this.envMap&&this.envMap.isTexture&&(i.envMap=this.envMap.toJSON(t).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(t).uuid),this.transmission!==void 0&&(i.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(i.transmissionMap=this.transmissionMap.toJSON(t).uuid),this.thickness!==void 0&&(i.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(i.thicknessMap=this.thicknessMap.toJSON(t).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!==dr&&(i.blending=this.blending),this.side!==pr&&(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!==td&&(i.blendSrc=this.blendSrc),this.blendDst!==nc&&(i.blendDst=this.blendDst),this.blendEquation!==Dr&&(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!==Ja&&(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!==ip&&(i.stencilFunc=this.stencilFunc),this.stencilRef!==0&&(i.stencilRef=this.stencilRef),this.stencilFuncMask!==255&&(i.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==ta&&(i.stencilFail=this.stencilFail),this.stencilZFail!==ta&&(i.stencilZFail=this.stencilZFail),this.stencilZPass!==ta&&(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 o in s){const c=s[o];delete c.metadata,r.push(c)}return r}if(e){const s=n(t.textures),r=n(t.images);s.length>0&&(i.textures=s),r.length>0&&(i.images=r)}return i}fromJSON(t,e){if(t.uuid!==void 0&&(this.uuid=t.uuid),t.name!==void 0&&(this.name=t.name),t.color!==void 0&&this.color!==void 0&&this.color.setHex(t.color),t.roughness!==void 0&&(this.roughness=t.roughness),t.metalness!==void 0&&(this.metalness=t.metalness),t.sheen!==void 0&&(this.sheen=t.sheen),t.sheenColor!==void 0&&(this.sheenColor=new st().setHex(t.sheenColor)),t.sheenRoughness!==void 0&&(this.sheenRoughness=t.sheenRoughness),t.emissive!==void 0&&this.emissive!==void 0&&this.emissive.setHex(t.emissive),t.specular!==void 0&&this.specular!==void 0&&this.specular.setHex(t.specular),t.specularIntensity!==void 0&&(this.specularIntensity=t.specularIntensity),t.specularColor!==void 0&&this.specularColor!==void 0&&this.specularColor.setHex(t.specularColor),t.shininess!==void 0&&(this.shininess=t.shininess),t.clearcoat!==void 0&&(this.clearcoat=t.clearcoat),t.clearcoatRoughness!==void 0&&(this.clearcoatRoughness=t.clearcoatRoughness),t.dispersion!==void 0&&(this.dispersion=t.dispersion),t.iridescence!==void 0&&(this.iridescence=t.iridescence),t.iridescenceIOR!==void 0&&(this.iridescenceIOR=t.iridescenceIOR),t.iridescenceThicknessRange!==void 0&&(this.iridescenceThicknessRange=t.iridescenceThicknessRange),t.transmission!==void 0&&(this.transmission=t.transmission),t.thickness!==void 0&&(this.thickness=t.thickness),t.attenuationDistance!==void 0&&(this.attenuationDistance=t.attenuationDistance),t.attenuationColor!==void 0&&this.attenuationColor!==void 0&&this.attenuationColor.setHex(t.attenuationColor),t.anisotropy!==void 0&&(this.anisotropy=t.anisotropy),t.anisotropyRotation!==void 0&&(this.anisotropyRotation=t.anisotropyRotation),t.fog!==void 0&&(this.fog=t.fog),t.flatShading!==void 0&&(this.flatShading=t.flatShading),t.blending!==void 0&&(this.blending=t.blending),t.combine!==void 0&&(this.combine=t.combine),t.side!==void 0&&(this.side=t.side),t.shadowSide!==void 0&&(this.shadowSide=t.shadowSide),t.opacity!==void 0&&(this.opacity=t.opacity),t.transparent!==void 0&&(this.transparent=t.transparent),t.alphaTest!==void 0&&(this.alphaTest=t.alphaTest),t.alphaHash!==void 0&&(this.alphaHash=t.alphaHash),t.depthFunc!==void 0&&(this.depthFunc=t.depthFunc),t.depthTest!==void 0&&(this.depthTest=t.depthTest),t.depthWrite!==void 0&&(this.depthWrite=t.depthWrite),t.colorWrite!==void 0&&(this.colorWrite=t.colorWrite),t.blendSrc!==void 0&&(this.blendSrc=t.blendSrc),t.blendDst!==void 0&&(this.blendDst=t.blendDst),t.blendEquation!==void 0&&(this.blendEquation=t.blendEquation),t.blendSrcAlpha!==void 0&&(this.blendSrcAlpha=t.blendSrcAlpha),t.blendDstAlpha!==void 0&&(this.blendDstAlpha=t.blendDstAlpha),t.blendEquationAlpha!==void 0&&(this.blendEquationAlpha=t.blendEquationAlpha),t.blendColor!==void 0&&this.blendColor!==void 0&&this.blendColor.setHex(t.blendColor),t.blendAlpha!==void 0&&(this.blendAlpha=t.blendAlpha),t.stencilWriteMask!==void 0&&(this.stencilWriteMask=t.stencilWriteMask),t.stencilFunc!==void 0&&(this.stencilFunc=t.stencilFunc),t.stencilRef!==void 0&&(this.stencilRef=t.stencilRef),t.stencilFuncMask!==void 0&&(this.stencilFuncMask=t.stencilFuncMask),t.stencilFail!==void 0&&(this.stencilFail=t.stencilFail),t.stencilZFail!==void 0&&(this.stencilZFail=t.stencilZFail),t.stencilZPass!==void 0&&(this.stencilZPass=t.stencilZPass),t.stencilWrite!==void 0&&(this.stencilWrite=t.stencilWrite),t.wireframe!==void 0&&(this.wireframe=t.wireframe),t.wireframeLinewidth!==void 0&&(this.wireframeLinewidth=t.wireframeLinewidth),t.wireframeLinecap!==void 0&&(this.wireframeLinecap=t.wireframeLinecap),t.wireframeLinejoin!==void 0&&(this.wireframeLinejoin=t.wireframeLinejoin),t.rotation!==void 0&&(this.rotation=t.rotation),t.linewidth!==void 0&&(this.linewidth=t.linewidth),t.dashSize!==void 0&&(this.dashSize=t.dashSize),t.gapSize!==void 0&&(this.gapSize=t.gapSize),t.scale!==void 0&&(this.scale=t.scale),t.polygonOffset!==void 0&&(this.polygonOffset=t.polygonOffset),t.polygonOffsetFactor!==void 0&&(this.polygonOffsetFactor=t.polygonOffsetFactor),t.polygonOffsetUnits!==void 0&&(this.polygonOffsetUnits=t.polygonOffsetUnits),t.dithering!==void 0&&(this.dithering=t.dithering),t.alphaToCoverage!==void 0&&(this.alphaToCoverage=t.alphaToCoverage),t.premultipliedAlpha!==void 0&&(this.premultipliedAlpha=t.premultipliedAlpha),t.forceSinglePass!==void 0&&(this.forceSinglePass=t.forceSinglePass),t.allowOverride!==void 0&&(this.allowOverride=t.allowOverride),t.visible!==void 0&&(this.visible=t.visible),t.toneMapped!==void 0&&(this.toneMapped=t.toneMapped),t.userData!==void 0&&(this.userData=t.userData),t.vertexColors!==void 0&&(typeof t.vertexColors=="number"?this.vertexColors=t.vertexColors>0:this.vertexColors=t.vertexColors),t.size!==void 0&&(this.size=t.size),t.sizeAttenuation!==void 0&&(this.sizeAttenuation=t.sizeAttenuation),t.map!==void 0&&(this.map=e[t.map]||null),t.matcap!==void 0&&(this.matcap=e[t.matcap]||null),t.alphaMap!==void 0&&(this.alphaMap=e[t.alphaMap]||null),t.bumpMap!==void 0&&(this.bumpMap=e[t.bumpMap]||null),t.bumpScale!==void 0&&(this.bumpScale=t.bumpScale),t.normalMap!==void 0&&(this.normalMap=e[t.normalMap]||null),t.normalMapType!==void 0&&(this.normalMapType=t.normalMapType),t.normalScale!==void 0){let i=t.normalScale;Array.isArray(i)===!1&&(i=[i,i]),this.normalScale=new Mt().fromArray(i)}return t.displacementMap!==void 0&&(this.displacementMap=e[t.displacementMap]||null),t.displacementScale!==void 0&&(this.displacementScale=t.displacementScale),t.displacementBias!==void 0&&(this.displacementBias=t.displacementBias),t.roughnessMap!==void 0&&(this.roughnessMap=e[t.roughnessMap]||null),t.metalnessMap!==void 0&&(this.metalnessMap=e[t.metalnessMap]||null),t.emissiveMap!==void 0&&(this.emissiveMap=e[t.emissiveMap]||null),t.emissiveIntensity!==void 0&&(this.emissiveIntensity=t.emissiveIntensity),t.specularMap!==void 0&&(this.specularMap=e[t.specularMap]||null),t.specularIntensityMap!==void 0&&(this.specularIntensityMap=e[t.specularIntensityMap]||null),t.specularColorMap!==void 0&&(this.specularColorMap=e[t.specularColorMap]||null),t.envMap!==void 0&&(this.envMap=e[t.envMap]||null),t.envMapRotation!==void 0&&this.envMapRotation.fromArray(t.envMapRotation),t.envMapIntensity!==void 0&&(this.envMapIntensity=t.envMapIntensity),t.reflectivity!==void 0&&(this.reflectivity=t.reflectivity),t.refractionRatio!==void 0&&(this.refractionRatio=t.refractionRatio),t.lightMap!==void 0&&(this.lightMap=e[t.lightMap]||null),t.lightMapIntensity!==void 0&&(this.lightMapIntensity=t.lightMapIntensity),t.aoMap!==void 0&&(this.aoMap=e[t.aoMap]||null),t.aoMapIntensity!==void 0&&(this.aoMapIntensity=t.aoMapIntensity),t.gradientMap!==void 0&&(this.gradientMap=e[t.gradientMap]||null),t.clearcoatMap!==void 0&&(this.clearcoatMap=e[t.clearcoatMap]||null),t.clearcoatRoughnessMap!==void 0&&(this.clearcoatRoughnessMap=e[t.clearcoatRoughnessMap]||null),t.clearcoatNormalMap!==void 0&&(this.clearcoatNormalMap=e[t.clearcoatNormalMap]||null),t.clearcoatNormalScale!==void 0&&(this.clearcoatNormalScale=new Mt().fromArray(t.clearcoatNormalScale)),t.iridescenceMap!==void 0&&(this.iridescenceMap=e[t.iridescenceMap]||null),t.iridescenceThicknessMap!==void 0&&(this.iridescenceThicknessMap=e[t.iridescenceThicknessMap]||null),t.transmissionMap!==void 0&&(this.transmissionMap=e[t.transmissionMap]||null),t.thicknessMap!==void 0&&(this.thicknessMap=e[t.thicknessMap]||null),t.anisotropyMap!==void 0&&(this.anisotropyMap=e[t.anisotropyMap]||null),t.sheenColorMap!==void 0&&(this.sheenColorMap=e[t.sheenColorMap]||null),t.sheenRoughnessMap!==void 0&&(this.sheenRoughnessMap=e[t.sheenRoughnessMap]||null),this}clone(){return new this.constructor().copy(this)}copy(t){this.name=t.name,this.blending=t.blending,this.side=t.side,this.vertexColors=t.vertexColors,this.opacity=t.opacity,this.transparent=t.transparent,this.blendSrc=t.blendSrc,this.blendDst=t.blendDst,this.blendEquation=t.blendEquation,this.blendSrcAlpha=t.blendSrcAlpha,this.blendDstAlpha=t.blendDstAlpha,this.blendEquationAlpha=t.blendEquationAlpha,this.blendColor.copy(t.blendColor),this.blendAlpha=t.blendAlpha,this.depthFunc=t.depthFunc,this.depthTest=t.depthTest,this.depthWrite=t.depthWrite,this.stencilWriteMask=t.stencilWriteMask,this.stencilFunc=t.stencilFunc,this.stencilRef=t.stencilRef,this.stencilFuncMask=t.stencilFuncMask,this.stencilFail=t.stencilFail,this.stencilZFail=t.stencilZFail,this.stencilZPass=t.stencilZPass,this.stencilWrite=t.stencilWrite;const e=t.clippingPlanes;let i=null;if(e!==null){const n=e.length;i=new Array(n);for(let s=0;s!==n;++s)i[s]=e[s].clone()}return this.clippingPlanes=i,this.clipIntersection=t.clipIntersection,this.clipShadows=t.clipShadows,this.shadowSide=t.shadowSide,this.colorWrite=t.colorWrite,this.precision=t.precision,this.polygonOffset=t.polygonOffset,this.polygonOffsetFactor=t.polygonOffsetFactor,this.polygonOffsetUnits=t.polygonOffsetUnits,this.dithering=t.dithering,this.alphaTest=t.alphaTest,this.alphaHash=t.alphaHash,this.alphaToCoverage=t.alphaToCoverage,this.premultipliedAlpha=t.premultipliedAlpha,this.forceSinglePass=t.forceSinglePass,this.allowOverride=t.allowOverride,this.visible=t.visible,this.toneMapped=t.toneMapped,this.userData=JSON.parse(JSON.stringify(t.userData)),this}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(t){t===!0&&this.version++}}class Il extends zs{constructor(t){super(),this.isSpriteMaterial=!0,this.type="SpriteMaterial",this.color=new st(16777215),this.map=null,this.alphaMap=null,this.rotation=0,this.sizeAttenuation=!0,this.transparent=!0,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.alphaMap=t.alphaMap,this.rotation=t.rotation,this.sizeAttenuation=t.sizeAttenuation,this.fog=t.fog,this}}let ua;const fo=new R,da=new R,fa=new R,pa=new Mt,po=new Mt,x1=new te,Oc=new R,mo=new R,Nc=new R,gp=new Mt,Zh=new Mt,vp=new Mt;class go extends Ge{constructor(t=new Il){if(super(),this.isSprite=!0,this.type="Sprite",ua===void 0){ua=new se;const e=new Float32Array([-.5,-.5,0,0,0,.5,-.5,0,1,0,.5,.5,0,1,1,-.5,.5,0,0,1]),i=new M1(e,5);ua.setIndex([0,1,2,0,2,3]),ua.setAttribute("position",new ql(i,3,0,!1)),ua.setAttribute("uv",new ql(i,2,3,!1))}this.geometry=ua,this.material=t,this.center=new Mt(.5,.5),this.count=1}raycast(t,e){t.camera===null&&Wt('Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.'),da.setFromMatrixScale(this.matrixWorld),x1.copy(t.camera.matrixWorld),this.modelViewMatrix.multiplyMatrices(t.camera.matrixWorldInverse,this.matrixWorld),fa.setFromMatrixPosition(this.modelViewMatrix),t.camera.isPerspectiveCamera&&this.material.sizeAttenuation===!1&&da.multiplyScalar(-fa.z);const i=this.material.rotation;let n,s;i!==0&&(s=Math.cos(i),n=Math.sin(i));const r=this.center;Fc(Oc.set(-.5,-.5,0),fa,r,da,n,s),Fc(mo.set(.5,-.5,0),fa,r,da,n,s),Fc(Nc.set(.5,.5,0),fa,r,da,n,s),gp.set(0,0),Zh.set(1,0),vp.set(1,1);let o=t.ray.intersectTriangle(Oc,mo,Nc,!1,fo);if(o===null&&(Fc(mo.set(-.5,.5,0),fa,r,da,n,s),Zh.set(0,1),o=t.ray.intersectTriangle(Oc,Nc,mo,!1,fo),o===null))return;const c=t.ray.origin.distanceTo(fo);c<t.near||c>t.far||e.push({distance:c,point:fo.clone(),uv:Pn.getInterpolation(fo,Oc,mo,Nc,gp,Zh,vp,new Mt),face:null,object:this})}copy(t,e){return super.copy(t,e),t.center!==void 0&&this.center.copy(t.center),this.material=t.material,this}}function Fc(a,t,e,i,n,s){pa.subVectors(a,e).addScalar(.5).multiply(i),n!==void 0?(po.x=s*pa.x-n*pa.y,po.y=n*pa.x+s*pa.y):po.copy(pa),a.copy(t),a.x+=po.x,a.y+=po.y,a.applyMatrix4(x1)}const Es=new R,Jh=new R,Uc=new R,$s=new R,jh=new R,kc=new R,Qh=new R;class fc{constructor(t=new R,e=new R(0,0,-1)){this.origin=t,this.direction=e}set(t,e){return this.origin.copy(t),this.direction.copy(e),this}copy(t){return this.origin.copy(t.origin),this.direction.copy(t.direction),this}at(t,e){return e.copy(this.origin).addScaledVector(this.direction,t)}lookAt(t){return this.direction.copy(t).sub(this.origin).normalize(),this}recast(t){return this.origin.copy(this.at(t,Es)),this}closestPointToPoint(t,e){e.subVectors(t,this.origin);const i=e.dot(this.direction);return i<0?e.copy(this.origin):e.copy(this.origin).addScaledVector(this.direction,i)}distanceToPoint(t){return Math.sqrt(this.distanceSqToPoint(t))}distanceSqToPoint(t){const e=Es.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):(Es.copy(this.origin).addScaledVector(this.direction,e),Es.distanceToSquared(t))}distanceSqToSegment(t,e,i,n){Jh.copy(t).add(e).multiplyScalar(.5),Uc.copy(e).sub(t).normalize(),$s.copy(this.origin).sub(Jh);const s=t.distanceTo(e)*.5,r=-this.direction.dot(Uc),o=$s.dot(this.direction),c=-$s.dot(Uc),l=$s.lengthSq(),h=Math.abs(1-r*r);let u,d,f,p;if(h>0)if(u=r*c-o,d=r*o-c,p=s*h,u>=0)if(d>=-p)if(d<=p){const v=1/h;u*=v,d*=v,f=u*(u+r*d+2*o)+d*(r*u+d+2*c)+l}else d=s,u=Math.max(0,-(r*d+o)),f=-u*u+d*(d+2*c)+l;else d=-s,u=Math.max(0,-(r*d+o)),f=-u*u+d*(d+2*c)+l;else d<=-p?(u=Math.max(0,-(-r*s+o)),d=u>0?-s:Math.min(Math.max(-s,-c),s),f=-u*u+d*(d+2*c)+l):d<=p?(u=0,d=Math.min(Math.max(-s,-c),s),f=d*(d+2*c)+l):(u=Math.max(0,-(r*s+o)),d=u>0?s:Math.min(Math.max(-s,-c),s),f=-u*u+d*(d+2*c)+l);else d=r>0?-s:s,u=Math.max(0,-(r*d+o)),f=-u*u+d*(d+2*c)+l;return i&&i.copy(this.origin).addScaledVector(this.direction,u),n&&n.copy(Jh).addScaledVector(Uc,d),f}intersectSphere(t,e){Es.subVectors(t.center,this.origin);const i=Es.dot(this.direction),n=Es.dot(Es)-i*i,s=t.radius*t.radius;if(n>s)return null;const r=Math.sqrt(s-n),o=i-r,c=i+r;return c<0?null:o<0?this.at(c,e):this.at(o,e)}intersectsSphere(t){return t.radius<0?!1:this.distanceSqToPoint(t.center)<=t.radius*t.radius}distanceToPlane(t){const e=t.normal.dot(this.direction);if(e===0)return t.distanceToPoint(this.origin)===0?0:null;const i=-(this.origin.dot(t.normal)+t.constant)/e;return i>=0?i:null}intersectPlane(t,e){const i=this.distanceToPlane(t);return i===null?null:this.at(i,e)}intersectsPlane(t){const e=t.distanceToPoint(this.origin);return e===0||t.normal.dot(this.direction)*e<0}intersectBox(t,e){let i,n,s,r,o,c;const l=1/this.direction.x,h=1/this.direction.y,u=1/this.direction.z,d=this.origin;return l>=0?(i=(t.min.x-d.x)*l,n=(t.max.x-d.x)*l):(i=(t.max.x-d.x)*l,n=(t.min.x-d.x)*l),h>=0?(s=(t.min.y-d.y)*h,r=(t.max.y-d.y)*h):(s=(t.max.y-d.y)*h,r=(t.min.y-d.y)*h),i>r||s>n||((s>i||isNaN(i))&&(i=s),(r<n||isNaN(n))&&(n=r),u>=0?(o=(t.min.z-d.z)*u,c=(t.max.z-d.z)*u):(o=(t.max.z-d.z)*u,c=(t.min.z-d.z)*u),i>c||o>n)||((o>i||i!==i)&&(i=o),(c<n||n!==n)&&(n=c),n<0)?null:this.at(i>=0?i:n,e)}intersectsBox(t){return this.intersectBox(t,Es)!==null}intersectTriangle(t,e,i,n,s){jh.subVectors(e,t),kc.subVectors(i,t),Qh.crossVectors(jh,kc);let r=this.direction.dot(Qh),o;if(r>0){if(n)return null;o=1}else if(r<0)o=-1,r=-r;else return null;$s.subVectors(this.origin,t);const c=o*this.direction.dot(kc.crossVectors($s,kc));if(c<0)return null;const l=o*this.direction.dot(jh.cross($s));if(l<0||c+l>r)return null;const h=-o*$s.dot(Qh);return h<0?null:this.at(h/r,s)}applyMatrix4(t){return this.origin.applyMatrix4(t),this.direction.transformDirection(t),this}equals(t){return t.origin.equals(this.origin)&&t.direction.equals(this.direction)}clone(){return new this.constructor().copy(this)}}class _n extends zs{constructor(t){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new st(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 Us,this.combine=T0,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapRotation.copy(t.envMapRotation),this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.fog=t.fog,this}}const Mp=new te,_r=new fc,zc=new ks,xp=new R,Bc=new R,Hc=new R,Gc=new R,tu=new R,Vc=new R,yp=new R,Wc=new R;class bt extends Ge{constructor(t=new se,e=new _n){super(),this.isMesh=!0,this.type="Mesh",this.geometry=t,this.material=e,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.count=1,this.updateMorphTargets()}copy(t,e){return super.copy(t,e),t.morphTargetInfluences!==void 0&&(this.morphTargetInfluences=t.morphTargetInfluences.slice()),t.morphTargetDictionary!==void 0&&(this.morphTargetDictionary=Object.assign({},t.morphTargetDictionary)),this.material=Array.isArray(t.material)?t.material.slice():t.material,this.geometry=t.geometry,this}updateMorphTargets(){const e=this.geometry.morphAttributes,i=Object.keys(e);if(i.length>0){const n=e[i[0]];if(n!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let s=0,r=n.length;s<r;s++){const o=n[s].name||String(s);this.morphTargetInfluences.push(0),this.morphTargetDictionary[o]=s}}}}getVertexPosition(t,e){const i=this.geometry,n=i.attributes.position,s=i.morphAttributes.position,r=i.morphTargetsRelative;e.fromBufferAttribute(n,t);const o=this.morphTargetInfluences;if(s&&o){Vc.set(0,0,0);for(let c=0,l=s.length;c<l;c++){const h=o[c],u=s[c];h!==0&&(tu.fromBufferAttribute(u,t),r?Vc.addScaledVector(tu,h):Vc.addScaledVector(tu.sub(e),h))}e.add(Vc)}return e}raycast(t,e){const i=this.geometry,n=this.material,s=this.matrixWorld;n!==void 0&&(i.boundingSphere===null&&i.computeBoundingSphere(),zc.copy(i.boundingSphere),zc.applyMatrix4(s),_r.copy(t.ray).recast(t.near),!(zc.containsPoint(_r.origin)===!1&&(_r.intersectSphere(zc,xp)===null||_r.origin.distanceToSquared(xp)>(t.far-t.near)**2))&&(Mp.copy(s).invert(),_r.copy(t.ray).applyMatrix4(Mp),!(i.boundingBox!==null&&_r.intersectsBox(i.boundingBox)===!1)&&this._computeIntersections(t,e,_r)))}_computeIntersections(t,e,i){let n;const s=this.geometry,r=this.material,o=s.index,c=s.attributes.position,l=s.attributes.uv,h=s.attributes.uv1,u=s.attributes.normal,d=s.groups,f=s.drawRange;if(o!==null)if(Array.isArray(r))for(let p=0,v=d.length;p<v;p++){const m=d[p],g=r[m.materialIndex],S=Math.max(m.start,f.start),x=Math.min(o.count,Math.min(m.start+m.count,f.start+f.count));for(let M=S,b=x;M<b;M+=3){const w=o.getX(M),T=o.getX(M+1),y=o.getX(M+2);n=Xc(this,g,t,i,l,h,u,w,T,y),n&&(n.faceIndex=Math.floor(M/3),n.face.materialIndex=m.materialIndex,e.push(n))}}else{const p=Math.max(0,f.start),v=Math.min(o.count,f.start+f.count);for(let m=p,g=v;m<g;m+=3){const S=o.getX(m),x=o.getX(m+1),M=o.getX(m+2);n=Xc(this,r,t,i,l,h,u,S,x,M),n&&(n.faceIndex=Math.floor(m/3),e.push(n))}}else if(c!==void 0)if(Array.isArray(r))for(let p=0,v=d.length;p<v;p++){const m=d[p],g=r[m.materialIndex],S=Math.max(m.start,f.start),x=Math.min(c.count,Math.min(m.start+m.count,f.start+f.count));for(let M=S,b=x;M<b;M+=3){const w=M,T=M+1,y=M+2;n=Xc(this,g,t,i,l,h,u,w,T,y),n&&(n.faceIndex=Math.floor(M/3),n.face.materialIndex=m.materialIndex,e.push(n))}}else{const p=Math.max(0,f.start),v=Math.min(c.count,f.start+f.count);for(let m=p,g=v;m<g;m+=3){const S=m,x=m+1,M=m+2;n=Xc(this,r,t,i,l,h,u,S,x,M),n&&(n.faceIndex=Math.floor(m/3),e.push(n))}}}}function cx(a,t,e,i,n,s,r,o){let c;if(t.side===qe?c=i.intersectTriangle(r,s,n,!0,o):c=i.intersectTriangle(n,s,r,t.side===pr,o),c===null)return null;Wc.copy(o),Wc.applyMatrix4(a.matrixWorld);const l=e.ray.origin.distanceTo(Wc);return l<e.near||l>e.far?null:{distance:l,point:Wc.clone(),object:a}}function Xc(a,t,e,i,n,s,r,o,c,l){a.getVertexPosition(o,Bc),a.getVertexPosition(c,Hc),a.getVertexPosition(l,Gc);const h=cx(a,t,e,i,Bc,Hc,Gc,yp);if(h){const u=new R;Pn.getBarycoord(yp,Bc,Hc,Gc,u),n&&(h.uv=Pn.getInterpolatedAttribute(n,o,c,l,u,new Mt)),s&&(h.uv1=Pn.getInterpolatedAttribute(s,o,c,l,u,new Mt)),r&&(h.normal=Pn.getInterpolatedAttribute(r,o,c,l,u,new R),h.normal.dot(i.direction)>0&&h.normal.multiplyScalar(-1));const d={a:o,b:c,c:l,normal:new R,materialIndex:0};Pn.getNormal(Bc,Hc,Gc,d.normal),h.face=d,h.barycoord=u}return h}const vo=new ae,Sp=new ae,_p=new ae,lx=new ae,bp=new te,Yc=new R,eu=new ks,wp=new te,iu=new fc;class KA extends bt{constructor(t,e){super(t,e),this.isSkinnedMesh=!0,this.type="SkinnedMesh",this.bindMode=tp,this.bindMatrix=new te,this.bindMatrixInverse=new te,this.boundingBox=null,this.boundingSphere=null}computeBoundingBox(){const t=this.geometry;this.boundingBox===null&&(this.boundingBox=new ki),this.boundingBox.makeEmpty();const e=t.getAttribute("position");for(let i=0;i<e.count;i++)this.getVertexPosition(i,Yc),this.boundingBox.expandByPoint(Yc)}computeBoundingSphere(){const t=this.geometry;this.boundingSphere===null&&(this.boundingSphere=new ks),this.boundingSphere.makeEmpty();const e=t.getAttribute("position");for(let i=0;i<e.count;i++)this.getVertexPosition(i,Yc),this.boundingSphere.expandByPoint(Yc)}copy(t,e){return super.copy(t,e),this.bindMode=t.bindMode,this.bindMatrix.copy(t.bindMatrix),this.bindMatrixInverse.copy(t.bindMatrixInverse),this.skeleton=t.skeleton,t.boundingBox!==null&&(this.boundingBox=t.boundingBox.clone()),t.boundingSphere!==null&&(this.boundingSphere=t.boundingSphere.clone()),this}raycast(t,e){const i=this.material,n=this.matrixWorld;i!==void 0&&(this.boundingSphere===null&&this.computeBoundingSphere(),eu.copy(this.boundingSphere),eu.applyMatrix4(n),t.ray.intersectsSphere(eu)!==!1&&(wp.copy(n).invert(),iu.copy(t.ray).applyMatrix4(wp),!(this.boundingBox!==null&&iu.intersectsBox(this.boundingBox)===!1)&&this._computeIntersections(t,e,iu)))}getVertexPosition(t,e){return super.getVertexPosition(t,e),this.applyBoneTransform(t,e),e}bind(t,e){this.skeleton=t,e===void 0&&(this.updateMatrixWorld(!0),this.skeleton.calculateInverses(),e=this.matrixWorld),this.bindMatrix.copy(e),this.bindMatrixInverse.copy(e).invert()}pose(){this.skeleton.pose()}normalizeSkinWeights(){const t=new ae,e=this.geometry.attributes.skinWeight;for(let i=0,n=e.count;i<n;i++){t.fromBufferAttribute(e,i);const s=1/t.manhattanLength();s!==1/0?t.multiplyScalar(s):t.set(1,0,0,0),e.setXYZW(i,t.x,t.y,t.z,t.w)}}updateMatrixWorld(t){super.updateMatrixWorld(t),this.bindMode===tp?this.bindMatrixInverse.copy(this.matrixWorld).invert():this.bindMode===lM?this.bindMatrixInverse.copy(this.bindMatrix).invert():It("SkinnedMesh: Unrecognized bindMode: "+this.bindMode)}applyBoneTransform(t,e){const i=this.skeleton,n=this.geometry;Sp.fromBufferAttribute(n.attributes.skinIndex,t),_p.fromBufferAttribute(n.attributes.skinWeight,t),e.isVector4?(vo.copy(e),e.set(0,0,0,0)):(vo.set(...e,1),e.set(0,0,0)),vo.applyMatrix4(this.bindMatrix);for(let s=0;s<4;s++){const r=_p.getComponent(s);if(r!==0){const o=Sp.getComponent(s);bp.multiplyMatrices(i.bones[o].matrixWorld,i.boneInverses[o]),e.addScaledVector(lx.copy(vo).applyMatrix4(bp),r)}}return e.isVector4&&(e.w=vo.w),e.applyMatrix4(this.bindMatrixInverse)}}class hx extends Ge{constructor(){super(),this.isBone=!0,this.type="Bone"}}class Mr extends Ei{constructor(t=null,e=1,i=1,n,s,r,o,c,l=Ce,h=Ce,u,d){super(null,r,o,c,l,h,n,s,u,d),this.isDataTexture=!0,this.image={data:t,width:e,height:i},this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}const Ep=new te,ux=new te;class y1{constructor(t=[],e=[]){this.uuid=Kn(),this.bones=t.slice(0),this.boneInverses=e,this.boneMatrices=null,this.boneTexture=null,this.init()}init(){const t=this.bones,e=this.boneInverses;if(this.boneMatrices=new Float32Array(t.length*16),e.length===0)this.calculateInverses();else if(t.length!==e.length){It("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 te)}}calculateInverses(){this.boneInverses.length=0;for(let t=0,e=this.bones.length;t<e;t++){const i=new te;this.bones[t]&&i.copy(this.bones[t].matrixWorld).invert(),this.boneInverses.push(i)}}pose(){for(let t=0,e=this.bones.length;t<e;t++){const i=this.bones[t];i&&i.matrixWorld.copy(this.boneInverses[t]).invert()}for(let t=0,e=this.bones.length;t<e;t++){const i=this.bones[t];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 t=this.bones,e=this.boneInverses,i=this.boneMatrices,n=this.boneTexture;for(let s=0,r=t.length;s<r;s++){const o=t[s]?t[s].matrixWorld:ux;Ep.multiplyMatrices(o,e[s]),Ep.toArray(i,s*16)}n!==null&&(n.needsUpdate=!0)}clone(){return new y1(this.bones,this.boneInverses)}computeBoneTexture(){let t=Math.sqrt(this.bones.length*4);t=Math.ceil(t/4)*4,t=Math.max(t,4);const e=new Float32Array(t*t*4);e.set(this.boneMatrices);const i=new Mr(e,t,t,Di,Ui);return i.needsUpdate=!0,this.boneMatrices=e,this.boneTexture=i,this}getBoneByName(t){for(let e=0,i=this.bones.length;e<i;e++){const n=this.bones[e];if(n.name===t)return n}}dispose(){this.boneTexture!==null&&(this.boneTexture.dispose(),this.boneTexture=null)}fromJSON(t,e){this.uuid=t.uuid;for(let i=0,n=t.bones.length;i<n;i++){const s=t.bones[i];let r=e[s];r===void 0&&(It("Skeleton: No bone found with UUID:",s),r=new hx),this.bones.push(r),this.boneInverses.push(new te().fromArray(t.boneInverses[i]))}return this.init(),this}toJSON(){const t={metadata:{version:4.7,type:"Skeleton",generator:"Skeleton.toJSON"},bones:[],boneInverses:[]};t.uuid=this.uuid;const e=this.bones,i=this.boneInverses;for(let n=0,s=e.length;n<s;n++){const r=e[n];t.bones.push(r.uuid);const o=i[n];t.boneInverses.push(o.toArray())}return t}}class Ap extends Jt{constructor(t,e,i,n=1){super(t,e,i),this.isInstancedBufferAttribute=!0,this.meshPerAttribute=n}copy(t){return super.copy(t),this.meshPerAttribute=t.meshPerAttribute,this}toJSON(){const t=super.toJSON();return t.meshPerAttribute=this.meshPerAttribute,t.isInstancedBufferAttribute=!0,t}}const ma=new te,Tp=new te,qc=[],Rp=new ki,dx=new te,Mo=new bt,xo=new ks;class ZA extends bt{constructor(t,e,i){super(t,e),this.isInstancedMesh=!0,this.instanceMatrix=new Ap(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,dx)}computeBoundingBox(){const t=this.geometry,e=this.count;this.boundingBox===null&&(this.boundingBox=new ki),t.boundingBox===null&&t.computeBoundingBox(),this.boundingBox.makeEmpty();for(let i=0;i<e;i++)this.getMatrixAt(i,ma),Rp.copy(t.boundingBox).applyMatrix4(ma),this.boundingBox.union(Rp)}computeBoundingSphere(){const t=this.geometry,e=this.count;this.boundingSphere===null&&(this.boundingSphere=new ks),t.boundingSphere===null&&t.computeBoundingSphere(),this.boundingSphere.makeEmpty();for(let i=0;i<e;i++)this.getMatrixAt(i,ma),xo.copy(t.boundingSphere).applyMatrix4(ma),this.boundingSphere.union(xo)}copy(t,e){return super.copy(t,e),this.instanceMatrix.copy(t.instanceMatrix),t.morphTexture!==null&&(this.morphTexture=t.morphTexture.clone()),t.instanceColor!==null&&(this.instanceColor=t.instanceColor.clone()),this.count=t.count,t.boundingBox!==null&&(this.boundingBox=t.boundingBox.clone()),t.boundingSphere!==null&&(this.boundingSphere=t.boundingSphere.clone()),this}getColorAt(t,e){return this.instanceColor===null?e.setRGB(1,1,1):e.fromArray(this.instanceColor.array,t*3)}getMatrixAt(t,e){return e.fromArray(this.instanceMatrix.array,t*16)}getMorphAt(t,e){const i=e.morphTargetInfluences,n=this.morphTexture.source.data.data,s=i.length+1,r=t*s+1;for(let o=0;o<i.length;o++)i[o]=n[r+o]}raycast(t,e){const i=this.matrixWorld,n=this.count;if(Mo.geometry=this.geometry,Mo.material=this.material,Mo.material!==void 0&&(this.boundingSphere===null&&this.computeBoundingSphere(),xo.copy(this.boundingSphere),xo.applyMatrix4(i),t.ray.intersectsSphere(xo)!==!1))for(let s=0;s<n;s++){this.getMatrixAt(s,ma),Tp.multiplyMatrices(i,ma),Mo.matrixWorld=Tp,Mo.raycast(t,qc);for(let r=0,o=qc.length;r<o;r++){const c=qc[r];c.instanceId=s,c.object=this,e.push(c)}qc.length=0}}setColorAt(t,e){return this.instanceColor===null&&(this.instanceColor=new Ap(new Float32Array(this.instanceMatrix.count*3).fill(1),3)),e.toArray(this.instanceColor.array,t*3),this}setMatrixAt(t,e){return e.toArray(this.instanceMatrix.array,t*16),this}setMorphAt(t,e){const i=e.morphTargetInfluences,n=i.length+1;this.morphTexture===null&&(this.morphTexture=new Mr(new Float32Array(n*this.count),n,this.count,dh,Ui));const s=this.morphTexture.source.data.data;let r=0;for(let l=0;l<i.length;l++)r+=i[l];const o=this.geometry.morphTargetsRelative?1:1-r,c=n*t;return s[c]=o,s.set(i,c+1),this}updateMorphTargets(){}dispose(){this.dispatchEvent({type:"dispose"}),this.morphTexture!==null&&(this.morphTexture.dispose(),this.morphTexture=null)}}const nu=new R,fx=new R,px=new $t;class er{constructor(t=new R(1,0,0),e=0){this.isPlane=!0,this.normal=t,this.constant=e}set(t,e){return this.normal.copy(t),this.constant=e,this}setComponents(t,e,i,n){return this.normal.set(t,e,i),this.constant=n,this}setFromNormalAndCoplanarPoint(t,e){return this.normal.copy(t),this.constant=-e.dot(this.normal),this}setFromCoplanarPoints(t,e,i){const n=nu.subVectors(i,e).cross(fx.subVectors(t,e)).normalize();return this.setFromNormalAndCoplanarPoint(n,t),this}copy(t){return this.normal.copy(t.normal),this.constant=t.constant,this}normalize(){const t=1/this.normal.length();return this.normal.multiplyScalar(t),this.constant*=t,this}negate(){return this.constant*=-1,this.normal.negate(),this}distanceToPoint(t){return this.normal.dot(t)+this.constant}distanceToSphere(t){return this.distanceToPoint(t.center)-t.radius}projectPoint(t,e){return e.copy(t).addScaledVector(this.normal,-this.distanceToPoint(t))}intersectLine(t,e,i=!0){const n=t.delta(nu),s=this.normal.dot(n);if(s===0)return this.distanceToPoint(t.start)===0?e.copy(t.start):null;const r=-(t.start.dot(this.normal)+this.constant)/s;return i===!0&&(r<0||r>1)?null:e.copy(t.start).addScaledVector(n,r)}intersectsLine(t){const e=this.distanceToPoint(t.start),i=this.distanceToPoint(t.end);return e<0&&i>0||i<0&&e>0}intersectsBox(t){return t.intersectsPlane(this)}intersectsSphere(t){return t.intersectsPlane(this)}coplanarPoint(t){return t.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(t,e){const i=e||px.getNormalMatrix(t),n=this.coplanarPoint(nu).applyMatrix4(t),s=this.normal.applyMatrix3(i).normalize();return this.constant=-n.dot(s),this}translate(t){return this.constant-=t.dot(this.normal),this}equals(t){return t.normal.equals(this.normal)&&t.constant===this.constant}clone(){return new this.constructor().copy(this)}}const br=new ks,mx=new Mt(.5,.5),$c=new R;class G0{constructor(t=new er,e=new er,i=new er,n=new er,s=new er,r=new er){this.planes=[t,e,i,n,s,r]}set(t,e,i,n,s,r){const o=this.planes;return o[0].copy(t),o[1].copy(e),o[2].copy(i),o[3].copy(n),o[4].copy(s),o[5].copy(r),this}copy(t){const e=this.planes;for(let i=0;i<6;i++)e[i].copy(t.planes[i]);return this}setFromProjectionMatrix(t,e=ms,i=!1){const n=this.planes,s=t.elements,r=s[0],o=s[1],c=s[2],l=s[3],h=s[4],u=s[5],d=s[6],f=s[7],p=s[8],v=s[9],m=s[10],g=s[11],S=s[12],x=s[13],M=s[14],b=s[15];if(n[0].setComponents(l-r,f-h,g-p,b-S).normalize(),n[1].setComponents(l+r,f+h,g+p,b+S).normalize(),n[2].setComponents(l+o,f+u,g+v,b+x).normalize(),n[3].setComponents(l-o,f-u,g-v,b-x).normalize(),i)n[4].setComponents(c,d,m,M).normalize(),n[5].setComponents(l-c,f-d,g-m,b-M).normalize();else if(n[4].setComponents(l-c,f-d,g-m,b-M).normalize(),e===ms)n[5].setComponents(l+c,f+d,g+m,b+M).normalize();else if(e===oc)n[5].setComponents(c,d,m,M).normalize();else throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: "+e);return this}intersectsObject(t){if(t.boundingSphere!==void 0)t.boundingSphere===null&&t.computeBoundingSphere(),br.copy(t.boundingSphere).applyMatrix4(t.matrixWorld);else{const e=t.geometry;e.boundingSphere===null&&e.computeBoundingSphere(),br.copy(e.boundingSphere).applyMatrix4(t.matrixWorld)}return this.intersectsSphere(br)}intersectsSprite(t){br.center.set(0,0,0);const e=mx.distanceTo(t.center);return br.radius=.7071067811865476+e,br.applyMatrix4(t.matrixWorld),this.intersectsSphere(br)}intersectsSphere(t){const e=this.planes,i=t.center,n=-t.radius;for(let s=0;s<6;s++)if(e[s].distanceToPoint(i)<n)return!1;return!0}intersectsBox(t){const e=this.planes;for(let i=0;i<6;i++){const n=e[i];if($c.x=n.normal.x>0?t.max.x:t.min.x,$c.y=n.normal.y>0?t.max.y:t.min.y,$c.z=n.normal.z>0?t.max.z:t.min.z,n.distanceToPoint($c)<0)return!1}return!0}containsPoint(t){const e=this.planes;for(let i=0;i<6;i++)if(e[i].distanceToPoint(t)<0)return!1;return!0}clone(){return new this.constructor().copy(this)}}class gx extends zs{constructor(t){super(),this.isLineBasicMaterial=!0,this.type="LineBasicMaterial",this.color=new st(16777215),this.map=null,this.linewidth=1,this.linecap="round",this.linejoin="round",this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.linewidth=t.linewidth,this.linecap=t.linecap,this.linejoin=t.linejoin,this.fog=t.fog,this}}const $l=new R,Kl=new R,Dp=new te,yo=new fc,Kc=new ks,su=new R,Ip=new R;class S1 extends Ge{constructor(t=new se,e=new gx){super(),this.isLine=!0,this.type="Line",this.geometry=t,this.material=e,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.updateMorphTargets()}copy(t,e){return super.copy(t,e),this.material=Array.isArray(t.material)?t.material.slice():t.material,this.geometry=t.geometry,this}computeLineDistances(){const t=this.geometry;if(t.index===null){const e=t.attributes.position,i=[0];for(let n=1,s=e.count;n<s;n++)$l.fromBufferAttribute(e,n-1),Kl.fromBufferAttribute(e,n),i[n]=i[n-1],i[n]+=$l.distanceTo(Kl);t.setAttribute("lineDistance",new de(i,1))}else It("Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.");return this}raycast(t,e){const i=this.geometry,n=this.matrixWorld,s=t.params.Line.threshold,r=i.drawRange;if(i.boundingSphere===null&&i.computeBoundingSphere(),Kc.copy(i.boundingSphere),Kc.applyMatrix4(n),Kc.radius+=s,t.ray.intersectsSphere(Kc)===!1)return;Dp.copy(n).invert(),yo.copy(t.ray).applyMatrix4(Dp);const o=s/((this.scale.x+this.scale.y+this.scale.z)/3),c=o*o,l=this.isLineSegments?2:1,h=i.index,d=i.attributes.position;if(h!==null){const f=Math.max(0,r.start),p=Math.min(h.count,r.start+r.count);for(let v=f,m=p-1;v<m;v+=l){const g=h.getX(v),S=h.getX(v+1),x=Zc(this,t,yo,c,g,S,v);x&&e.push(x)}if(this.isLineLoop){const v=h.getX(p-1),m=h.getX(f),g=Zc(this,t,yo,c,v,m,p-1);g&&e.push(g)}}else{const f=Math.max(0,r.start),p=Math.min(d.count,r.start+r.count);for(let v=f,m=p-1;v<m;v+=l){const g=Zc(this,t,yo,c,v,v+1,v);g&&e.push(g)}if(this.isLineLoop){const v=Zc(this,t,yo,c,p-1,f,p-1);v&&e.push(v)}}}updateMorphTargets(){const e=this.geometry.morphAttributes,i=Object.keys(e);if(i.length>0){const n=e[i[0]];if(n!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let s=0,r=n.length;s<r;s++){const o=n[s].name||String(s);this.morphTargetInfluences.push(0),this.morphTargetDictionary[o]=s}}}}}function Zc(a,t,e,i,n,s,r){const o=a.geometry.attributes.position;if($l.fromBufferAttribute(o,n),Kl.fromBufferAttribute(o,s),e.distanceSqToSegment($l,Kl,su,Ip)>i)return;su.applyMatrix4(a.matrixWorld);const l=t.ray.origin.distanceTo(su);if(!(l<t.near||l>t.far))return{distance:l,point:Ip.clone().applyMatrix4(a.matrixWorld),index:r,face:null,faceIndex:null,barycoord:null,object:a}}const Cp=new R,Pp=new R;class JA extends S1{constructor(t,e){super(t,e),this.isLineSegments=!0,this.type="LineSegments"}computeLineDistances(){const t=this.geometry;if(t.index===null){const e=t.attributes.position,i=[];for(let n=0,s=e.count;n<s;n+=2)Cp.fromBufferAttribute(e,n),Pp.fromBufferAttribute(e,n+1),i[n]=n===0?0:i[n-1],i[n+1]=i[n]+Cp.distanceTo(Pp);t.setAttribute("lineDistance",new de(i,1))}else It("LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.");return this}}class jA extends S1{constructor(t,e){super(t,e),this.isLineLoop=!0,this.type="LineLoop"}}class Hd extends zs{constructor(t){super(),this.isPointsMaterial=!0,this.type="PointsMaterial",this.color=new st(16777215),this.map=null,this.alphaMap=null,this.size=1,this.sizeAttenuation=!0,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.alphaMap=t.alphaMap,this.size=t.size,this.sizeAttenuation=t.sizeAttenuation,this.fog=t.fog,this}}const Lp=new te,Gd=new fc,Jc=new ks,jc=new R;class mn extends Ge{constructor(t=new se,e=new Hd){super(),this.isPoints=!0,this.type="Points",this.geometry=t,this.material=e,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.updateMorphTargets()}copy(t,e){return super.copy(t,e),this.material=Array.isArray(t.material)?t.material.slice():t.material,this.geometry=t.geometry,this}raycast(t,e){const i=this.geometry,n=this.matrixWorld,s=t.params.Points.threshold,r=i.drawRange;if(i.boundingSphere===null&&i.computeBoundingSphere(),Jc.copy(i.boundingSphere),Jc.applyMatrix4(n),Jc.radius+=s,t.ray.intersectsSphere(Jc)===!1)return;Lp.copy(n).invert(),Gd.copy(t.ray).applyMatrix4(Lp);const o=s/((this.scale.x+this.scale.y+this.scale.z)/3),c=o*o,l=i.index,u=i.attributes.position;if(l!==null){const d=Math.max(0,r.start),f=Math.min(l.count,r.start+r.count);for(let p=d,v=f;p<v;p++){const m=l.getX(p);jc.fromBufferAttribute(u,m),Op(jc,m,c,n,t,e,this)}}else{const d=Math.max(0,r.start),f=Math.min(u.count,r.start+r.count);for(let p=d,v=f;p<v;p++)jc.fromBufferAttribute(u,p),Op(jc,p,c,n,t,e,this)}}updateMorphTargets(){const e=this.geometry.morphAttributes,i=Object.keys(e);if(i.length>0){const n=e[i[0]];if(n!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let s=0,r=n.length;s<r;s++){const o=n[s].name||String(s);this.morphTargetInfluences.push(0),this.morphTargetDictionary[o]=s}}}}}function Op(a,t,e,i,n,s,r){const o=Gd.distanceSqToPoint(a);if(o<e){const c=new R;Gd.closestPointToPoint(a,c),c.applyMatrix4(i);const l=n.ray.origin.distanceTo(c);if(l<n.near||l>n.far)return;s.push({distance:l,distanceToRay:Math.sqrt(o),point:c,index:t,face:null,faceIndex:null,barycoord:null,object:r})}}class _1 extends Ei{constructor(t=[],e=Xr,i,n,s,r,o,c,l,h){super(t,e,i,n,s,r,o,c,l,h),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(t){this.image=t}}class Bs extends Ei{constructor(t,e,i,n,s,r,o,c,l){super(t,e,i,n,s,r,o,c,l),this.isCanvasTexture=!0,this.needsUpdate=!0}}class mr extends Ei{constructor(t,e,i=Nn,n,s,r,o=Ce,c=Ce,l,h=Fs,u=1){if(h!==Fs&&h!==Or)throw new Error("THREE.DepthTexture: format must be either THREE.DepthFormat or THREE.DepthStencilFormat");const d={width:t,height:e,depth:u};super(d,n,s,r,o,c,h,i,l),this.isDepthTexture=!0,this.flipY=!1,this.generateMipmaps=!1,this.compareFunction=null}copy(t){return super.copy(t),this.source=new k0(Object.assign({},t.image)),this.compareFunction=t.compareFunction,this}toJSON(t){const e=super.toJSON(t);return this.compareFunction!==null&&(e.compareFunction=this.compareFunction),e}}class vx extends mr{constructor(t,e=Nn,i=Xr,n,s,r=Ce,o=Ce,c,l=Fs){const h={width:t,height:t,depth:1},u=[h,h,h,h,h,h];super(t,t,e,i,n,s,r,o,c,l),this.image=u,this.isCubeDepthTexture=!0,this.isCubeTexture=!0}get images(){return this.image}set images(t){this.image=t}}class b1 extends Ei{constructor(t=null){super(),this.sourceTexture=t,this.isExternalTexture=!0}copy(t){return super.copy(t),this.sourceTexture=t.sourceTexture,this}}class Ki extends se{constructor(t=1,e=1,i=1,n=1,s=1,r=1){super(),this.type="BoxGeometry",this.parameters={width:t,height:e,depth:i,widthSegments:n,heightSegments:s,depthSegments:r};const o=this;n=Math.floor(n),s=Math.floor(s),r=Math.floor(r);const c=[],l=[],h=[],u=[];let d=0,f=0;p("z","y","x",-1,-1,i,e,t,r,s,0),p("z","y","x",1,-1,i,e,-t,r,s,1),p("x","z","y",1,1,t,i,e,n,r,2),p("x","z","y",1,-1,t,i,-e,n,r,3),p("x","y","z",1,-1,t,e,i,n,s,4),p("x","y","z",-1,-1,t,e,-i,n,s,5),this.setIndex(c),this.setAttribute("position",new de(l,3)),this.setAttribute("normal",new de(h,3)),this.setAttribute("uv",new de(u,2));function p(v,m,g,S,x,M,b,w,T,y,A){const C=M/T,I=b/y,P=M/2,V=b/2,X=w/2,L=T+1,B=y+1;let k=0,$=0;const tt=new R;for(let J=0;J<B;J++){const it=J*I-V;for(let at=0;at<L;at++){const Xt=at*C-P;tt[v]=Xt*S,tt[m]=it*x,tt[g]=X,l.push(tt.x,tt.y,tt.z),tt[v]=0,tt[m]=0,tt[g]=w>0?1:-1,h.push(tt.x,tt.y,tt.z),u.push(at/T),u.push(1-J/y),k+=1}}for(let J=0;J<y;J++)for(let it=0;it<T;it++){const at=d+it+L*J,Xt=d+it+L*(J+1),ee=d+(it+1)+L*(J+1),Kt=d+(it+1)+L*J;c.push(at,Xt,Kt),c.push(Xt,ee,Kt),$+=6}o.addGroup(f,$,A),f+=$,d+=k}}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new Ki(t.width,t.height,t.depth,t.widthSegments,t.heightSegments,t.depthSegments)}}class V0 extends se{constructor(t=1,e=32,i=0,n=Math.PI*2){super(),this.type="CircleGeometry",this.parameters={radius:t,segments:e,thetaStart:i,thetaLength:n},e=Math.max(3,e);const s=[],r=[],o=[],c=[],l=new R,h=new Mt;r.push(0,0,0),o.push(0,0,1),c.push(.5,.5);for(let u=0,d=3;u<=e;u++,d+=3){const f=i+u/e*n;l.x=t*Math.cos(f),l.y=t*Math.sin(f),r.push(l.x,l.y,l.z),o.push(0,0,1),h.x=(r[d]/t+1)/2,h.y=(r[d+1]/t+1)/2,c.push(h.x,h.y)}for(let u=1;u<=e;u++)s.push(u,u+1,0);this.setIndex(s),this.setAttribute("position",new de(r,3)),this.setAttribute("normal",new de(o,3)),this.setAttribute("uv",new de(c,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new V0(t.radius,t.segments,t.thetaStart,t.thetaLength)}}class Fn extends se{constructor(t=1,e=1,i=1,n=32,s=1,r=!1,o=0,c=Math.PI*2){super(),this.type="CylinderGeometry",this.parameters={radiusTop:t,radiusBottom:e,height:i,radialSegments:n,heightSegments:s,openEnded:r,thetaStart:o,thetaLength:c};const l=this;n=Math.floor(n),s=Math.floor(s);const h=[],u=[],d=[],f=[];let p=0;const v=[],m=i/2;let g=0;S(),r===!1&&(t>0&&x(!0),e>0&&x(!1)),this.setIndex(h),this.setAttribute("position",new de(u,3)),this.setAttribute("normal",new de(d,3)),this.setAttribute("uv",new de(f,2));function S(){const M=new R,b=new R;let w=0;const T=(e-t)/i;for(let y=0;y<=s;y++){const A=[],C=y/s,I=C*(e-t)+t;for(let P=0;P<=n;P++){const V=P/n,X=V*c+o,L=Math.sin(X),B=Math.cos(X);b.x=I*L,b.y=-C*i+m,b.z=I*B,u.push(b.x,b.y,b.z),M.set(L,T,B).normalize(),d.push(M.x,M.y,M.z),f.push(V,1-C),A.push(p++)}v.push(A)}for(let y=0;y<n;y++)for(let A=0;A<s;A++){const C=v[A][y],I=v[A+1][y],P=v[A+1][y+1],V=v[A][y+1];(t>0||A!==0)&&(h.push(C,I,V),w+=3),(e>0||A!==s-1)&&(h.push(I,P,V),w+=3)}l.addGroup(g,w,0),g+=w}function x(M){const b=p,w=new Mt,T=new R;let y=0;const A=M===!0?t:e,C=M===!0?1:-1;for(let P=1;P<=n;P++)u.push(0,m*C,0),d.push(0,C,0),f.push(.5,.5),p++;const I=p;for(let P=0;P<=n;P++){const X=P/n*c+o,L=Math.cos(X),B=Math.sin(X);T.x=A*B,T.y=m*C,T.z=A*L,u.push(T.x,T.y,T.z),d.push(0,C,0),w.x=L*.5+.5,w.y=B*.5*C+.5,f.push(w.x,w.y),p++}for(let P=0;P<n;P++){const V=b+P,X=I+P;M===!0?h.push(X,X+1,V):h.push(X+1,X,V),y+=3}l.addGroup(g,y,M===!0?1:2),g+=y}}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new Fn(t.radiusTop,t.radiusBottom,t.height,t.radialSegments,t.heightSegments,t.openEnded,t.thetaStart,t.thetaLength)}}class io extends Fn{constructor(t=1,e=1,i=32,n=1,s=!1,r=0,o=Math.PI*2){super(0,t,e,i,n,s,r,o),this.type="ConeGeometry",this.parameters={radius:t,height:e,radialSegments:i,heightSegments:n,openEnded:s,thetaStart:r,thetaLength:o}}static fromJSON(t){return new io(t.radius,t.height,t.radialSegments,t.heightSegments,t.openEnded,t.thetaStart,t.thetaLength)}}class fh extends se{constructor(t=[new Mt(0,-.5),new Mt(.5,0),new Mt(0,.5)],e=12,i=0,n=Math.PI*2){super(),this.type="LatheGeometry",this.parameters={points:t,segments:e,phiStart:i,phiLength:n},e=Math.floor(e),n=Zt(n,0,Math.PI*2);const s=[],r=[],o=[],c=[],l=[],h=1/e,u=new R,d=new Mt,f=new R,p=new R,v=new R;let m=0,g=0;for(let S=0;S<=t.length-1;S++)switch(S){case 0:m=t[S+1].x-t[S].x,g=t[S+1].y-t[S].y,f.x=g*1,f.y=-m,f.z=g*0,v.copy(f),f.normalize(),c.push(f.x,f.y,f.z);break;case t.length-1:c.push(v.x,v.y,v.z);break;default:m=t[S+1].x-t[S].x,g=t[S+1].y-t[S].y,f.x=g*1,f.y=-m,f.z=g*0,p.copy(f),f.x+=v.x,f.y+=v.y,f.z+=v.z,f.normalize(),c.push(f.x,f.y,f.z),v.copy(p)}for(let S=0;S<=e;S++){const x=i+S*h*n,M=Math.sin(x),b=Math.cos(x);for(let w=0;w<=t.length-1;w++){u.x=t[w].x*M,u.y=t[w].y,u.z=t[w].x*b,r.push(u.x,u.y,u.z),d.x=S/e,d.y=w/(t.length-1),o.push(d.x,d.y);const T=c[3*w+0]*M,y=c[3*w+1],A=c[3*w+0]*b;l.push(T,y,A)}}for(let S=0;S<e;S++)for(let x=0;x<t.length-1;x++){const M=x+S*t.length,b=M,w=M+t.length,T=M+t.length+1,y=M+1;s.push(b,w,y),s.push(T,y,w)}this.setIndex(s),this.setAttribute("position",new de(r,3)),this.setAttribute("uv",new de(o,2)),this.setAttribute("normal",new de(l,3))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new fh(t.points,t.segments,t.phiStart,t.phiLength)}}class Zi extends se{constructor(t=1,e=1,i=1,n=1){super(),this.type="PlaneGeometry",this.parameters={width:t,height:e,widthSegments:i,heightSegments:n};const s=t/2,r=e/2,o=Math.floor(i),c=Math.floor(n),l=o+1,h=c+1,u=t/o,d=e/c,f=[],p=[],v=[],m=[];for(let g=0;g<h;g++){const S=g*d-r;for(let x=0;x<l;x++){const M=x*u-s;p.push(M,-S,0),v.push(0,0,1),m.push(x/o),m.push(1-g/c)}}for(let g=0;g<c;g++)for(let S=0;S<o;S++){const x=S+l*g,M=S+l*(g+1),b=S+1+l*(g+1),w=S+1+l*g;f.push(x,M,w),f.push(M,b,w)}this.setIndex(f),this.setAttribute("position",new de(p,3)),this.setAttribute("normal",new de(v,3)),this.setAttribute("uv",new de(m,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new Zi(t.width,t.height,t.widthSegments,t.heightSegments)}}class di extends se{constructor(t=1,e=32,i=16,n=0,s=Math.PI*2,r=0,o=Math.PI){super(),this.type="SphereGeometry",this.parameters={radius:t,widthSegments:e,heightSegments:i,phiStart:n,phiLength:s,thetaStart:r,thetaLength:o},e=Math.max(3,Math.floor(e)),i=Math.max(2,Math.floor(i));const c=Math.min(r+o,Math.PI);let l=0;const h=[],u=new R,d=new R,f=[],p=[],v=[],m=[];for(let g=0;g<=i;g++){const S=[],x=g/i,M=r+x*o,b=t*Math.cos(M),w=Math.sqrt(t*t-b*b);let T=0;g===0&&r===0?T=.5/e:g===i&&c===Math.PI&&(T=-.5/e);for(let y=0;y<=e;y++){const A=y/e,C=n+A*s;u.x=-w*Math.cos(C),u.y=b,u.z=w*Math.sin(C),p.push(u.x,u.y,u.z),d.copy(u).normalize(),v.push(d.x,d.y,d.z),m.push(A+T,1-x),S.push(l++)}h.push(S)}for(let g=0;g<i;g++)for(let S=0;S<e;S++){const x=h[g][S+1],M=h[g][S],b=h[g+1][S],w=h[g+1][S+1];(g!==0||r>0)&&f.push(x,M,w),(g!==i-1||c<Math.PI)&&f.push(M,b,w)}this.setIndex(f),this.setAttribute("position",new de(p,3)),this.setAttribute("normal",new de(v,3)),this.setAttribute("uv",new de(m,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new di(t.radius,t.widthSegments,t.heightSegments,t.phiStart,t.phiLength,t.thetaStart,t.thetaLength)}}class W0 extends se{constructor(t=1,e=.4,i=12,n=48,s=Math.PI*2,r=0,o=Math.PI*2){super(),this.type="TorusGeometry",this.parameters={radius:t,tube:e,radialSegments:i,tubularSegments:n,arc:s,thetaStart:r,thetaLength:o},i=Math.floor(i),n=Math.floor(n);const c=[],l=[],h=[],u=[],d=new R,f=new R,p=new R;for(let v=0;v<=i;v++){const m=r+v/i*o;for(let g=0;g<=n;g++){const S=g/n*s;f.x=(t+e*Math.cos(m))*Math.cos(S),f.y=(t+e*Math.cos(m))*Math.sin(S),f.z=e*Math.sin(m),l.push(f.x,f.y,f.z),d.x=t*Math.cos(S),d.y=t*Math.sin(S),p.subVectors(f,d).normalize(),h.push(p.x,p.y,p.z),u.push(g/n),u.push(v/i)}}for(let v=1;v<=i;v++)for(let m=1;m<=n;m++){const g=(n+1)*v+m-1,S=(n+1)*(v-1)+m-1,x=(n+1)*(v-1)+m,M=(n+1)*v+m;c.push(g,S,M),c.push(S,x,M)}this.setIndex(c),this.setAttribute("position",new de(l,3)),this.setAttribute("normal",new de(h,3)),this.setAttribute("uv",new de(u,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new W0(t.radius,t.tube,t.radialSegments,t.tubularSegments,t.arc)}}class QA extends se{constructor(t=null){if(super(),this.type="WireframeGeometry",this.parameters={geometry:t},t!==null){const e=[],i=new Set,n=new R,s=new R;if(t.index!==null){const r=t.attributes.position,o=t.index;let c=t.groups;c.length===0&&(c=[{start:0,count:o.count,materialIndex:0}]);for(let l=0,h=c.length;l<h;++l){const u=c[l],d=u.start,f=u.count;for(let p=d,v=d+f;p<v;p+=3)for(let m=0;m<3;m++){const g=o.getX(p+m),S=o.getX(p+(m+1)%3);n.fromBufferAttribute(r,g),s.fromBufferAttribute(r,S),Np(n,s,i)===!0&&(e.push(n.x,n.y,n.z),e.push(s.x,s.y,s.z))}}}else{const r=t.attributes.position;for(let o=0,c=r.count/3;o<c;o++)for(let l=0;l<3;l++){const h=3*o+l,u=3*o+(l+1)%3;n.fromBufferAttribute(r,h),s.fromBufferAttribute(r,u),Np(n,s,i)===!0&&(e.push(n.x,n.y,n.z),e.push(s.x,s.y,s.z))}}this.setAttribute("position",new de(e,3))}}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}}function Np(a,t,e){const i=`${a.x},${a.y},${a.z}-${t.x},${t.y},${t.z}`,n=`${t.x},${t.y},${t.z}-${a.x},${a.y},${a.z}`;return e.has(i)===!0||e.has(n)===!0?!1:(e.add(i),e.add(n),!0)}function to(a){const t={};for(const e in a){t[e]={};for(const i in a[e]){const n=a[e][i];if(Fp(n))n.isRenderTargetTexture?(It("UniformsUtils: Textures of render targets cannot be cloned via cloneUniforms() or mergeUniforms()."),t[e][i]=null):t[e][i]=n.clone();else if(Array.isArray(n))if(Fp(n[0])){const s=[];for(let r=0,o=n.length;r<o;r++)s[r]=n[r].clone();t[e][i]=s}else t[e][i]=n.slice();else t[e][i]=n}}return t}function Bi(a){const t={};for(let e=0;e<a.length;e++){const i=to(a[e]);for(const n in i)t[n]=i[n]}return t}function Fp(a){return a&&(a.isColor||a.isMatrix3||a.isMatrix4||a.isVector2||a.isVector3||a.isVector4||a.isTexture||a.isQuaternion)}function Mx(a){const t=[];for(let e=0;e<a.length;e++)t.push(a[e].clone());return t}function w1(a){const t=a.getRenderTarget();return t===null?a.outputColorSpace:t.isXRRenderTarget===!0?t.texture.colorSpace:ce.workingColorSpace}const xx={clone:to,merge:Bi};var yx=`void main() {
1417
1417
  gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
1418
1418
  }`,Sx=`void main() {
1419
1419
  gl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );
1420
- }`;class de extends zs{constructor(t){super(),this.isShaderMaterial=!0,this.type="ShaderMaterial",this.defines={},this.uniforms={},this.uniformsGroups=[],this.vertexShader=yx,this.fragmentShader=Sx,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,t!==void 0&&this.setValues(t)}copy(t){return super.copy(t),this.fragmentShader=t.fragmentShader,this.vertexShader=t.vertexShader,this.uniforms=to(t.uniforms),this.uniformsGroups=Mx(t.uniformsGroups),this.defines=Object.assign({},t.defines),this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.fog=t.fog,this.lights=t.lights,this.clipping=t.clipping,this.extensions=Object.assign({},t.extensions),this.glslVersion=t.glslVersion,this.defaultAttributeValues=Object.assign({},t.defaultAttributeValues),this.index0AttributeName=t.index0AttributeName,this.uniformsNeedUpdate=t.uniformsNeedUpdate,this}toJSON(t){const e=super.toJSON(t);e.glslVersion=this.glslVersion,e.uniforms={};for(const n in this.uniforms){const r=this.uniforms[n].value;r&&r.isTexture?e.uniforms[n]={type:"t",value:r.toJSON(t).uuid}:r&&r.isColor?e.uniforms[n]={type:"c",value:r.getHex()}:r&&r.isVector2?e.uniforms[n]={type:"v2",value:r.toArray()}:r&&r.isVector3?e.uniforms[n]={type:"v3",value:r.toArray()}:r&&r.isVector4?e.uniforms[n]={type:"v4",value:r.toArray()}:r&&r.isMatrix3?e.uniforms[n]={type:"m3",value:r.toArray()}:r&&r.isMatrix4?e.uniforms[n]={type:"m4",value:r.toArray()}:e.uniforms[n]={value:r}}Object.keys(this.defines).length>0&&(e.defines=this.defines),e.vertexShader=this.vertexShader,e.fragmentShader=this.fragmentShader,e.lights=this.lights,e.clipping=this.clipping;const i={};for(const n in this.extensions)this.extensions[n]===!0&&(i[n]=!0);return Object.keys(i).length>0&&(e.extensions=i),e}fromJSON(t,e){if(super.fromJSON(t,e),t.uniforms!==void 0)for(const i in t.uniforms){const n=t.uniforms[i];switch(this.uniforms[i]={},n.type){case"t":this.uniforms[i].value=e[n.value]||null;break;case"c":this.uniforms[i].value=new st().setHex(n.value);break;case"v2":this.uniforms[i].value=new Mt().fromArray(n.value);break;case"v3":this.uniforms[i].value=new R().fromArray(n.value);break;case"v4":this.uniforms[i].value=new ae().fromArray(n.value);break;case"m3":this.uniforms[i].value=new $t().fromArray(n.value);break;case"m4":this.uniforms[i].value=new te().fromArray(n.value);break;default:this.uniforms[i].value=n.value}}if(t.defines!==void 0&&(this.defines=t.defines),t.vertexShader!==void 0&&(this.vertexShader=t.vertexShader),t.fragmentShader!==void 0&&(this.fragmentShader=t.fragmentShader),t.glslVersion!==void 0&&(this.glslVersion=t.glslVersion),t.extensions!==void 0)for(const i in t.extensions)this.extensions[i]=t.extensions[i];return t.lights!==void 0&&(this.lights=t.lights),t.clipping!==void 0&&(this.clipping=t.clipping),this}}class E1 extends de{constructor(t){super(t),this.isRawShaderMaterial=!0,this.type="RawShaderMaterial"}}class ar extends zs{constructor(t){super(),this.isMeshStandardMaterial=!0,this.type="MeshStandardMaterial",this.defines={STANDARD:""},this.color=new st(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 st(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=Gl,this.normalScale=new Mt(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 Us,this.envMapIntensity=1,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.defines={STANDARD:""},this.color.copy(t.color),this.roughness=t.roughness,this.metalness=t.metalness,this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.roughnessMap=t.roughnessMap,this.metalnessMap=t.metalnessMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapRotation.copy(t.envMapRotation),this.envMapIntensity=t.envMapIntensity,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.flatShading=t.flatShading,this.fog=t.fog,this}}class _x extends ar{constructor(t){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 Mt(1,1),this.clearcoatNormalMap=null,this.ior=1.5,Object.defineProperty(this,"reflectivity",{get:function(){return Zt(2.5*(this.ior-1)/(this.ior+1),0,1)},set:function(e){this.ior=(1+.4*e)/(1-.4*e)}}),this.iridescenceMap=null,this.iridescenceIOR=1.3,this.iridescenceThicknessRange=[100,400],this.iridescenceThicknessMap=null,this.sheenColor=new st(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 st(1,1,1),this.specularIntensity=1,this.specularIntensityMap=null,this.specularColor=new st(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(t)}get anisotropy(){return this._anisotropy}set anisotropy(t){this._anisotropy>0!=t>0&&this.version++,this._anisotropy=t}get clearcoat(){return this._clearcoat}set clearcoat(t){this._clearcoat>0!=t>0&&this.version++,this._clearcoat=t}get iridescence(){return this._iridescence}set iridescence(t){this._iridescence>0!=t>0&&this.version++,this._iridescence=t}get dispersion(){return this._dispersion}set dispersion(t){this._dispersion>0!=t>0&&this.version++,this._dispersion=t}get sheen(){return this._sheen}set sheen(t){this._sheen>0!=t>0&&this.version++,this._sheen=t}get transmission(){return this._transmission}set transmission(t){this._transmission>0!=t>0&&this.version++,this._transmission=t}copy(t){return super.copy(t),this.defines={STANDARD:"",PHYSICAL:""},this.anisotropy=t.anisotropy,this.anisotropyRotation=t.anisotropyRotation,this.anisotropyMap=t.anisotropyMap,this.clearcoat=t.clearcoat,this.clearcoatMap=t.clearcoatMap,this.clearcoatRoughness=t.clearcoatRoughness,this.clearcoatRoughnessMap=t.clearcoatRoughnessMap,this.clearcoatNormalMap=t.clearcoatNormalMap,this.clearcoatNormalScale.copy(t.clearcoatNormalScale),this.dispersion=t.dispersion,this.ior=t.ior,this.iridescence=t.iridescence,this.iridescenceMap=t.iridescenceMap,this.iridescenceIOR=t.iridescenceIOR,this.iridescenceThicknessRange=[...t.iridescenceThicknessRange],this.iridescenceThicknessMap=t.iridescenceThicknessMap,this.sheen=t.sheen,this.sheenColor.copy(t.sheenColor),this.sheenColorMap=t.sheenColorMap,this.sheenRoughness=t.sheenRoughness,this.sheenRoughnessMap=t.sheenRoughnessMap,this.transmission=t.transmission,this.transmissionMap=t.transmissionMap,this.thickness=t.thickness,this.thicknessMap=t.thicknessMap,this.attenuationDistance=t.attenuationDistance,this.attenuationColor.copy(t.attenuationColor),this.specularIntensity=t.specularIntensity,this.specularIntensityMap=t.specularIntensityMap,this.specularColor.copy(t.specularColor),this.specularColorMap=t.specularColorMap,this}}class qr extends zs{constructor(t){super(),this.isMeshLambertMaterial=!0,this.type="MeshLambertMaterial",this.color=new st(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new st(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=Gl,this.normalScale=new Mt(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new Us,this.combine=T0,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(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapRotation.copy(t.envMapRotation),this.combine=t.combine,this.reflectivity=t.reflectivity,this.envMapIntensity=t.envMapIntensity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.flatShading=t.flatShading,this.fog=t.fog,this}}class bx extends zs{constructor(t){super(),this.isMeshDepthMaterial=!0,this.type="MeshDepthMaterial",this.depthPacking=pM,this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.setValues(t)}copy(t){return super.copy(t),this.depthPacking=t.depthPacking,this.map=t.map,this.alphaMap=t.alphaMap,this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this}}class wx extends zs{constructor(t){super(),this.isMeshDistanceMaterial=!0,this.type="MeshDistanceMaterial",this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.setValues(t)}copy(t){return super.copy(t),this.map=t.map,this.alphaMap=t.alphaMap,this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this}}function Qc(a,t){return!a||a.constructor===t?a:typeof t.BYTES_PER_ELEMENT=="number"?new t(a):Array.prototype.slice.call(a)}function Ex(a){function t(n,s){return a[n]-a[s]}const e=a.length,i=new Array(e);for(let n=0;n!==e;++n)i[n]=n;return i.sort(t),i}function Up(a,t,e){const i=a.length,n=new a.constructor(i);for(let s=0,r=0;r!==i;++s){const o=e[s]*t;for(let c=0;c!==t;++c)n[r++]=a[o+c]}return n}function Ax(a,t,e,i){let n=1,s=a[0];for(;s!==void 0&&s[i]===void 0;)s=a[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&&(t.push(s.time),e.push(...r)),s=a[n++];while(s!==void 0);else if(r.toArray!==void 0)do r=s[i],r!==void 0&&(t.push(s.time),r.toArray(e,e.length)),s=a[n++];while(s!==void 0);else do r=s[i],r!==void 0&&(t.push(s.time),e.push(r)),s=a[n++];while(s!==void 0)}class pc{constructor(t,e,i,n){this.parameterPositions=t,this._cachedIndex=0,this.resultBuffer=n!==void 0?n:new e.constructor(i),this.sampleValues=e,this.valueSize=i,this.settings=null,this.DefaultSettings_={}}evaluate(t){const e=this.parameterPositions;let i=this._cachedIndex,n=e[i],s=e[i-1];t:{e:{let r;i:{n:if(!(t<n)){for(let o=i+2;;){if(n===void 0){if(t<s)break n;return i=e.length,this._cachedIndex=i,this.copySampleValue_(i-1)}if(i===o)break;if(s=n,n=e[++i],t<n)break e}r=e.length;break i}if(!(t>=s)){const o=e[1];t<o&&(i=2,s=o);for(let c=i-2;;){if(s===void 0)return this._cachedIndex=0,this.copySampleValue_(0);if(i===c)break;if(n=s,s=e[--i-1],t>=s)break e}r=i,i=0;break i}break t}for(;i<r;){const o=i+r>>>1;t<e[o]?r=o:i=o+1}if(n=e[i],s=e[i-1],s===void 0)return this._cachedIndex=0,this.copySampleValue_(0);if(n===void 0)return i=e.length,this._cachedIndex=i,this.copySampleValue_(i-1)}this._cachedIndex=i,this.intervalChanged_(i,s,n)}return this.interpolate_(i,s,t,n)}getSettings_(){return this.settings||this.DefaultSettings_}copySampleValue_(t){const e=this.resultBuffer,i=this.sampleValues,n=this.valueSize,s=t*n;for(let r=0;r!==n;++r)e[r]=i[s+r];return e}interpolate_(){throw new Error("THREE.Interpolant: Call to abstract method.")}intervalChanged_(){}}class Tx extends pc{constructor(t,e,i,n){super(t,e,i,n),this._weightPrev=-0,this._offsetPrev=-0,this._weightNext=-0,this._offsetNext=-0,this.DefaultSettings_={endingStart:Da,endingEnd:Da}}intervalChanged_(t,e,i){const n=this.parameterPositions;let s=t-2,r=t+1,o=n[s],c=n[r];if(o===void 0)switch(this.getSettings_().endingStart){case Ia:s=t,o=2*e-i;break;case Hl:s=n.length-2,o=e+n[s]-n[s+1];break;default:s=t,o=i}if(c===void 0)switch(this.getSettings_().endingEnd){case Ia:r=t,c=2*i-e;break;case Hl:r=1,c=i+n[1]-n[0];break;default:r=t-1,c=e}const l=(i-e)*.5,h=this.valueSize;this._weightPrev=l/(e-o),this._weightNext=l/(c-i),this._offsetPrev=s*h,this._offsetNext=r*h}interpolate_(t,e,i,n){const s=this.resultBuffer,r=this.sampleValues,o=this.valueSize,c=t*o,l=c-o,h=this._offsetPrev,u=this._offsetNext,d=this._weightPrev,f=this._weightNext,p=(i-e)/(n-e),v=p*p,m=v*p,g=-d*m+2*d*v-d*p,S=(1+d)*m+(-1.5-2*d)*v+(-.5+d)*p+1,x=(-1-f)*m+(1.5+f)*v+.5*p,M=f*m-f*v;for(let b=0;b!==o;++b)s[b]=g*r[h+b]+S*r[l+b]+x*r[c+b]+M*r[u+b];return s}}class A1 extends pc{constructor(t,e,i,n){super(t,e,i,n)}interpolate_(t,e,i,n){const s=this.resultBuffer,r=this.sampleValues,o=this.valueSize,c=t*o,l=c-o,h=(i-e)/(n-e),u=1-h;for(let d=0;d!==o;++d)s[d]=r[l+d]*u+r[c+d]*h;return s}}class Rx extends pc{constructor(t,e,i,n){super(t,e,i,n)}interpolate_(t){return this.copySampleValue_(t-1)}}class Dx extends pc{interpolate_(t,e,i,n){const s=this.resultBuffer,r=this.sampleValues,o=this.valueSize,c=t*o,l=c-o,h=this.inTangents,u=this.outTangents;if(!h||!u){const p=(i-e)/(n-e),v=1-p;for(let m=0;m!==o;++m)s[m]=r[l+m]*v+r[c+m]*p;return s}const d=o*2,f=t-1;for(let p=0;p!==o;++p){const v=r[l+p],m=r[c+p],g=f*d+p*2,S=u[g],x=u[g+1],M=t*d+p*2,b=h[M],w=h[M+1];let T=(i-e)/(n-e),y,A,C,I,P;for(let V=0;V<8;V++){y=T*T,A=y*T,C=1-T,I=C*C,P=I*C;const L=P*e+3*I*T*S+3*C*y*b+A*n-i;if(Math.abs(L)<1e-10)break;const B=3*I*(S-e)+6*C*T*(b-S)+3*y*(n-b);if(Math.abs(B)<1e-10)break;T=T-L/B,T=Math.max(0,Math.min(1,T))}s[p]=P*v+3*I*T*x+3*C*y*w+A*m}return s}}class Jn{constructor(t,e,i,n){if(t===void 0)throw new Error("THREE.KeyframeTrack: track name is undefined");if(e===void 0||e.length===0)throw new Error("THREE.KeyframeTrack: no keyframes in track named "+t);this.name=t,this.times=Qc(e,this.TimeBufferType),this.values=Qc(i,this.ValueBufferType),this.setInterpolation(n||this.DefaultInterpolation)}static toJSON(t){const e=t.constructor;let i;if(e.toJSON!==this.toJSON)i=e.toJSON(t);else{i={name:t.name,times:Qc(t.times,Array),values:Qc(t.values,Array)};const n=t.getInterpolation();n!==t.DefaultInterpolation&&(i.interpolation=n)}return i.type=t.ValueTypeName,i}InterpolantFactoryMethodDiscrete(t){return new Rx(this.times,this.values,this.getValueSize(),t)}InterpolantFactoryMethodLinear(t){return new A1(this.times,this.values,this.getValueSize(),t)}InterpolantFactoryMethodSmooth(t){return new Tx(this.times,this.values,this.getValueSize(),t)}InterpolantFactoryMethodBezier(t){const e=new Dx(this.times,this.values,this.getValueSize(),t);return this.settings&&(e.inTangents=this.settings.inTangents,e.outTangents=this.settings.outTangents),e}setInterpolation(t){let e;switch(t){case Bl:e=this.InterpolantFactoryMethodDiscrete;break;case zd:e=this.InterpolantFactoryMethodLinear;break;case Ph:e=this.InterpolantFactoryMethodSmooth;break;case ep:e=this.InterpolantFactoryMethodBezier;break}if(e===void 0){const i="unsupported interpolation for "+this.ValueTypeName+" keyframe track named "+this.name;if(this.createInterpolant===void 0)if(t!==this.DefaultInterpolation)this.setInterpolation(this.DefaultInterpolation);else throw new Error(i);return It("KeyframeTrack:",i),this}return this.createInterpolant=e,this}getInterpolation(){switch(this.createInterpolant){case this.InterpolantFactoryMethodDiscrete:return Bl;case this.InterpolantFactoryMethodLinear:return zd;case this.InterpolantFactoryMethodSmooth:return Ph;case this.InterpolantFactoryMethodBezier:return ep}}getValueSize(){return this.values.length/this.times.length}shift(t){if(t!==0){const e=this.times;for(let i=0,n=e.length;i!==n;++i)e[i]+=t}return this}scale(t){if(t!==1){const e=this.times;for(let i=0,n=e.length;i!==n;++i)e[i]*=t}return this}trim(t,e){const i=this.times,n=i.length;let s=0,r=n-1;for(;s!==n&&i[s]<t;)++s;for(;r!==-1&&i[r]>e;)--r;if(++r,s!==0||r!==n){s>=r&&(r=Math.max(r,1),s=r-1);const o=this.getValueSize();this.times=i.slice(s,r),this.values=this.values.slice(s*o,r*o)}return this}validate(){let t=!0;const e=this.getValueSize();e-Math.floor(e)!==0&&(Wt("KeyframeTrack: Invalid value size in track.",this),t=!1);const i=this.times,n=this.values,s=i.length;s===0&&(Wt("KeyframeTrack: Track is empty.",this),t=!1);let r=null;for(let o=0;o!==s;o++){const c=i[o];if(typeof c=="number"&&isNaN(c)){Wt("KeyframeTrack: Time is not a valid number.",this,o,c),t=!1;break}if(r!==null&&r>c){Wt("KeyframeTrack: Out of order keys.",this,o,c,r),t=!1;break}r=c}if(n!==void 0&&bM(n))for(let o=0,c=n.length;o!==c;++o){const l=n[o];if(isNaN(l)){Wt("KeyframeTrack: Value is not a valid number.",this,o,l),t=!1;break}}return t}optimize(){const t=this.times.slice(),e=this.values.slice(),i=this.getValueSize(),n=this.getInterpolation()===Ph,s=t.length-1;let r=1;for(let o=1;o<s;++o){let c=!1;const l=t[o],h=t[o+1];if(l!==h&&(o!==1||l!==t[0]))if(n)c=!0;else{const u=o*i,d=u-i,f=u+i;for(let p=0;p!==i;++p){const v=e[u+p];if(v!==e[d+p]||v!==e[f+p]){c=!0;break}}}if(c){if(o!==r){t[r]=t[o];const u=o*i,d=r*i;for(let f=0;f!==i;++f)e[d+f]=e[u+f]}++r}}if(s>0){t[r]=t[s];for(let o=s*i,c=r*i,l=0;l!==i;++l)e[c+l]=e[o+l];++r}return r!==t.length?(this.times=t.slice(0,r),this.values=e.slice(0,r*i)):(this.times=t,this.values=e),this}clone(){const t=this.times.slice(),e=this.values.slice(),i=this.constructor,n=new i(this.name,t,e);return n.createInterpolant=this.createInterpolant,n}}Jn.prototype.ValueTypeName="";Jn.prototype.TimeBufferType=Float32Array;Jn.prototype.ValueBufferType=Float32Array;Jn.prototype.DefaultInterpolation=zd;class no extends Jn{constructor(t,e,i){super(t,e,i)}}no.prototype.ValueTypeName="bool";no.prototype.ValueBufferType=Array;no.prototype.DefaultInterpolation=Bl;no.prototype.InterpolantFactoryMethodLinear=void 0;no.prototype.InterpolantFactoryMethodSmooth=void 0;class T1 extends Jn{constructor(t,e,i,n){super(t,e,i,n)}}T1.prototype.ValueTypeName="color";class X0 extends Jn{constructor(t,e,i,n){super(t,e,i,n)}}X0.prototype.ValueTypeName="number";class Ix extends pc{constructor(t,e,i,n){super(t,e,i,n)}interpolate_(t,e,i,n){const s=this.resultBuffer,r=this.sampleValues,o=this.valueSize,c=(i-e)/(n-e);let l=t*o;for(let h=l+o;l!==h;l+=4)on.slerpFlat(s,0,r,l-o,r,l,c);return s}}class Y0 extends Jn{constructor(t,e,i,n){super(t,e,i,n)}InterpolantFactoryMethodLinear(t){return new Ix(this.times,this.values,this.getValueSize(),t)}}Y0.prototype.ValueTypeName="quaternion";Y0.prototype.InterpolantFactoryMethodSmooth=void 0;class so extends Jn{constructor(t,e,i){super(t,e,i)}}so.prototype.ValueTypeName="string";so.prototype.ValueBufferType=Array;so.prototype.DefaultInterpolation=Bl;so.prototype.InterpolantFactoryMethodLinear=void 0;so.prototype.InterpolantFactoryMethodSmooth=void 0;class R1 extends Jn{constructor(t,e,i,n){super(t,e,i,n)}}R1.prototype.ValueTypeName="vector";class kp{constructor(t="",e=-1,i=[],n=O0){this.name=t,this.tracks=i,this.duration=e,this.blendMode=n,this.uuid=Kn(),this.userData={},this.duration<0&&this.resetDuration()}static parse(t){const e=[],i=t.tracks,n=1/(t.fps||1);for(let r=0,o=i.length;r!==o;++r)e.push(Px(i[r]).scale(n));const s=new this(t.name,t.duration,e,t.blendMode);return s.uuid=t.uuid,s.userData=JSON.parse(t.userData||"{}"),s}static toJSON(t){const e=[],i=t.tracks,n={name:t.name,duration:t.duration,tracks:e,uuid:t.uuid,blendMode:t.blendMode,userData:JSON.stringify(t.userData)};for(let s=0,r=i.length;s!==r;++s)e.push(Jn.toJSON(i[s]));return n}static CreateFromMorphTargetSequence(t,e,i,n){const s=e.length,r=[];for(let o=0;o<s;o++){let c=[],l=[];c.push((o+s-1)%s,o,(o+1)%s),l.push(0,1,0);const h=Ex(c);c=Up(c,1,h),l=Up(l,1,h),!n&&c[0]===0&&(c.push(s),l.push(l[0])),r.push(new X0(".morphTargetInfluences["+e[o].name+"]",c,l).scale(1/i))}return new this(t,-1,r)}static findByName(t,e){let i=t;if(!Array.isArray(t)){const n=t;i=n.geometry&&n.geometry.animations||n.animations}for(let n=0;n<i.length;n++)if(i[n].name===e)return i[n];return null}static CreateClipsFromMorphTargetSequences(t,e,i){const n={},s=/^([\w-]*?)([\d]+)$/;for(let o=0,c=t.length;o<c;o++){const l=t[o],h=l.name.match(s);if(h&&h.length>1){const u=h[1];let d=n[u];d||(n[u]=d=[]),d.push(l)}}const r=[];for(const o in n)r.push(this.CreateFromMorphTargetSequence(o,n[o],e,i));return r}resetDuration(){const t=this.tracks;let e=0;for(let i=0,n=t.length;i!==n;++i){const s=this.tracks[i];e=Math.max(e,s.times[s.times.length-1])}return this.duration=e,this}trim(){for(let t=0;t<this.tracks.length;t++)this.tracks[t].trim(0,this.duration);return this}validate(){let t=!0;for(let e=0;e<this.tracks.length;e++)t=t&&this.tracks[e].validate();return t}optimize(){for(let t=0;t<this.tracks.length;t++)this.tracks[t].optimize();return this}clone(){const t=[];for(let i=0;i<this.tracks.length;i++)t.push(this.tracks[i].clone());const e=new this.constructor(this.name,this.duration,t,this.blendMode);return e.userData=JSON.parse(JSON.stringify(this.userData)),e}toJSON(){return this.constructor.toJSON(this)}}function Cx(a){switch(a.toLowerCase()){case"scalar":case"double":case"float":case"number":case"integer":return X0;case"vector":case"vector2":case"vector3":case"vector4":return R1;case"color":return T1;case"quaternion":return Y0;case"bool":case"boolean":return no;case"string":return so}throw new Error("THREE.KeyframeTrack: Unsupported typeName: "+a)}function Px(a){if(a.type===void 0)throw new Error("THREE.KeyframeTrack: track type undefined, can not parse");const t=Cx(a.type);if(a.times===void 0){const e=[],i=[];Ax(a.keys,e,i,"value"),a.times=e,a.values=i}return t.parse!==void 0?t.parse(a):new t(a.name,a.times,a.values,a.interpolation)}const Os={enabled:!1,files:{},add:function(a,t){this.enabled!==!1&&(zp(a)||(this.files[a]=t))},get:function(a){if(this.enabled!==!1&&!zp(a))return this.files[a]},remove:function(a){delete this.files[a]},clear:function(){this.files={}}};function zp(a){try{const t=a.slice(a.indexOf(":")+1);return new URL(t).protocol==="blob:"}catch{return!1}}class Lx{constructor(t,e,i){const n=this;let s=!1,r=0,o=0,c;const l=[];this.onStart=void 0,this.onLoad=t,this.onProgress=e,this.onError=i,this._abortController=null,this.itemStart=function(h){o++,s===!1&&n.onStart!==void 0&&n.onStart(h,r,o),s=!0},this.itemEnd=function(h){r++,n.onProgress!==void 0&&n.onProgress(h,r,o),r===o&&(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"),c?c(h):h},this.setURLModifier=function(h){return c=h,this},this.addHandler=function(h,u){return l.push(h,u),this},this.removeHandler=function(h){const u=l.indexOf(h);return u!==-1&&l.splice(u,2),this},this.getHandler=function(h){for(let u=0,d=l.length;u<d;u+=2){const f=l[u],p=l[u+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 Ox=new Lx;class mc{constructor(t){this.manager=t!==void 0?t:Ox,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(t,e){const i=this;return new Promise(function(n,s){i.load(t,n,e,s)})}parse(){}setCrossOrigin(t){return this.crossOrigin=t,this}setWithCredentials(t){return this.withCredentials=t,this}setPath(t){return this.path=t,this}setResourcePath(t){return this.resourcePath=t,this}setRequestHeader(t){return this.requestHeader=t,this}abort(){return this}}mc.DEFAULT_MATERIAL_NAME="__DEFAULT";const As={};class Nx extends Error{constructor(t,e){super(t),this.response=e}}class tT extends mc{constructor(t){super(t),this.mimeType="",this.responseType="",this._abortController=new AbortController}load(t,e,i,n){t===void 0&&(t=""),this.path!==void 0&&(t=this.path+t),t=this.manager.resolveURL(t);const s=Os.get(`file:${t}`);if(s!==void 0){this.manager.itemStart(t),setTimeout(()=>{e&&e(s),this.manager.itemEnd(t)},0);return}if(As[t]!==void 0){As[t].push({onLoad:e,onProgress:i,onError:n});return}As[t]=[],As[t].push({onLoad:e,onProgress:i,onError:n});const r=new Request(t,{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}),o=this.mimeType,c=this.responseType;fetch(r).then(l=>{if(l.status===200||l.status===0){if(l.status===0&&It("FileLoader: HTTP Status 0 received."),typeof ReadableStream>"u"||l.body===void 0||l.body.getReader===void 0)return l;const h=As[t],u=l.body.getReader(),d=l.headers.get("X-File-Size")||l.headers.get("Content-Length"),f=d?parseInt(d):0,p=f!==0;let v=0;const m=new ReadableStream({start(g){S();function S(){u.read().then(({done:x,value:M})=>{if(x)g.close();else{v+=M.byteLength;const b=new ProgressEvent("progress",{lengthComputable:p,loaded:v,total:f});for(let w=0,T=h.length;w<T;w++){const y=h[w];y.onProgress&&y.onProgress(b)}g.enqueue(M),S()}},x=>{g.error(x)})}}});return new Response(m)}else throw new Nx(`fetch for "${l.url}" responded with ${l.status}: ${l.statusText}`,l)}).then(l=>{switch(c){case"arraybuffer":return l.arrayBuffer();case"blob":return l.blob();case"document":return l.text().then(h=>new DOMParser().parseFromString(h,o));case"json":return l.json();default:if(o==="")return l.text();{const u=/charset="?([^;"\s]*)"?/i.exec(o),d=u&&u[1]?u[1].toLowerCase():void 0,f=new TextDecoder(d);return l.arrayBuffer().then(p=>f.decode(p))}}}).then(l=>{Os.add(`file:${t}`,l);const h=As[t];delete As[t];for(let u=0,d=h.length;u<d;u++){const f=h[u];f.onLoad&&f.onLoad(l)}}).catch(l=>{const h=As[t];if(h===void 0)throw this.manager.itemError(t),l;delete As[t];for(let u=0,d=h.length;u<d;u++){const f=h[u];f.onError&&f.onError(l)}this.manager.itemError(t)}).finally(()=>{this.manager.itemEnd(t)}),this.manager.itemStart(t)}setResponseType(t){return this.responseType=t,this}setMimeType(t){return this.mimeType=t,this}abort(){return this._abortController.abort(),this._abortController=new AbortController,this}}const ga=new WeakMap;class Fx extends mc{constructor(t){super(t)}load(t,e,i,n){this.path!==void 0&&(t=this.path+t),t=this.manager.resolveURL(t);const s=this,r=Os.get(`image:${t}`);if(r!==void 0){if(r.complete===!0)s.manager.itemStart(t),setTimeout(function(){e&&e(r),s.manager.itemEnd(t)},0);else{let u=ga.get(r);u===void 0&&(u=[],ga.set(r,u)),u.push({onLoad:e,onError:n})}return r}const o=cc("img");function c(){h(),e&&e(this);const u=ga.get(this)||[];for(let d=0;d<u.length;d++){const f=u[d];f.onLoad&&f.onLoad(this)}ga.delete(this),s.manager.itemEnd(t)}function l(u){h(),n&&n(u),Os.remove(`image:${t}`);const d=ga.get(this)||[];for(let f=0;f<d.length;f++){const p=d[f];p.onError&&p.onError(u)}ga.delete(this),s.manager.itemError(t),s.manager.itemEnd(t)}function h(){o.removeEventListener("load",c,!1),o.removeEventListener("error",l,!1)}return o.addEventListener("load",c,!1),o.addEventListener("error",l,!1),t.slice(0,5)!=="data:"&&this.crossOrigin!==void 0&&(o.crossOrigin=this.crossOrigin),Os.add(`image:${t}`,o),s.manager.itemStart(t),o.src=t,o}}class eT extends mc{constructor(t){super(t)}load(t,e,i,n){const s=new Ei,r=new Fx(this.manager);return r.setCrossOrigin(this.crossOrigin),r.setPath(this.path),r.load(t,function(o){s.image=o,s.needsUpdate=!0,e!==void 0&&e(s)},i,n),s}}class ph extends Ge{constructor(t,e=1){super(),this.isLight=!0,this.type="Light",this.color=new st(t),this.intensity=e}dispose(){this.dispatchEvent({type:"dispose"})}copy(t,e){return super.copy(t,e),this.color.copy(t.color),this.intensity=t.intensity,this}toJSON(t){const e=super.toJSON(t);return e.object.color=this.color.getHex(),e.object.intensity=this.intensity,e}}class Ux extends ph{constructor(t,e,i){super(t,i),this.isHemisphereLight=!0,this.type="HemisphereLight",this.position.copy(Ge.DEFAULT_UP),this.updateMatrix(),this.groundColor=new st(e)}copy(t,e){return super.copy(t,e),this.groundColor.copy(t.groundColor),this}toJSON(t){const e=super.toJSON(t);return e.object.groundColor=this.groundColor.getHex(),e}}const ru=new te,Bp=new R,Hp=new R;class q0{constructor(t){this.camera=t,this.intensity=1,this.bias=0,this.biasNode=null,this.normalBias=0,this.radius=1,this.blurSamples=8,this.mapSize=new Mt(512,512),this.mapType=yn,this.map=null,this.mapPass=null,this.matrix=new te,this.autoUpdate=!0,this.needsUpdate=!1,this._frustum=new G0,this._frameExtents=new Mt(1,1),this._viewportCount=1,this._viewports=[new ae(0,0,1,1)]}getViewportCount(){return this._viewportCount}getFrustum(){return this._frustum}updateMatrices(t){const e=this.camera,i=this.matrix;Bp.setFromMatrixPosition(t.matrixWorld),e.position.copy(Bp),Hp.setFromMatrixPosition(t.target.matrixWorld),e.lookAt(Hp),e.updateMatrixWorld(),ru.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),this._frustum.setFromProjectionMatrix(ru,e.coordinateSystem,e.reversedDepth),e.coordinateSystem===oc||e.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(ru)}getViewport(t){return this._viewports[t]}getFrameExtents(){return this._frameExtents}dispose(){this.map&&this.map.dispose(),this.mapPass&&this.mapPass.dispose()}copy(t){return this.camera=t.camera.clone(),this.intensity=t.intensity,this.bias=t.bias,this.radius=t.radius,this.autoUpdate=t.autoUpdate,this.needsUpdate=t.needsUpdate,this.normalBias=t.normalBias,this.blurSamples=t.blurSamples,this.mapSize.copy(t.mapSize),this.biasNode=t.biasNode,this}clone(){return new this.constructor().copy(this)}toJSON(){const t={};return this.intensity!==1&&(t.intensity=this.intensity),this.bias!==0&&(t.bias=this.bias),this.normalBias!==0&&(t.normalBias=this.normalBias),this.radius!==1&&(t.radius=this.radius),(this.mapSize.x!==512||this.mapSize.y!==512)&&(t.mapSize=this.mapSize.toArray()),t.camera=this.camera.toJSON(!1).object,delete t.camera.matrix,t}}const tl=new R,el=new on,is=new R;class D1 extends Ge{constructor(){super(),this.isCamera=!0,this.type="Camera",this.matrixWorldInverse=new te,this.projectionMatrix=new te,this.projectionMatrixInverse=new te,this.coordinateSystem=ms,this._reversedDepth=!1}get reversedDepth(){return this._reversedDepth}copy(t,e){return super.copy(t,e),this.matrixWorldInverse.copy(t.matrixWorldInverse),this.projectionMatrix.copy(t.projectionMatrix),this.projectionMatrixInverse.copy(t.projectionMatrixInverse),this.coordinateSystem=t.coordinateSystem,this}getWorldDirection(t){return super.getWorldDirection(t).negate()}updateMatrixWorld(t){super.updateMatrixWorld(t),this.matrixWorld.decompose(tl,el,is),is.x===1&&is.y===1&&is.z===1?this.matrixWorldInverse.copy(this.matrixWorld).invert():this.matrixWorldInverse.compose(tl,el,is.set(1,1,1)).invert()}updateWorldMatrix(t,e,i=!1){super.updateWorldMatrix(t,e,i),this.matrixWorld.decompose(tl,el,is),is.x===1&&is.y===1&&is.z===1?this.matrixWorldInverse.copy(this.matrixWorld).invert():this.matrixWorldInverse.compose(tl,el,is.set(1,1,1)).invert()}clone(){return new this.constructor().copy(this)}}const Ks=new R,Gp=new Mt,Vp=new Mt;class rn extends D1{constructor(t=50,e=1,i=.1,n=2e3){super(),this.isPerspectiveCamera=!0,this.type="PerspectiveCamera",this.fov=t,this.zoom=1,this.near=i,this.far=n,this.focus=10,this.aspect=e,this.view=null,this.filmGauge=35,this.filmOffset=0,this.updateProjectionMatrix()}copy(t,e){return super.copy(t,e),this.fov=t.fov,this.zoom=t.zoom,this.near=t.near,this.far=t.far,this.focus=t.focus,this.aspect=t.aspect,this.view=t.view===null?null:Object.assign({},t.view),this.filmGauge=t.filmGauge,this.filmOffset=t.filmOffset,this}setFocalLength(t){const e=.5*this.getFilmHeight()/t;this.fov=Qa*2*Math.atan(e),this.updateProjectionMatrix()}getFocalLength(){const t=Math.tan(Go*.5*this.fov);return .5*this.getFilmHeight()/t}getEffectiveFOV(){return Qa*2*Math.atan(Math.tan(Go*.5*this.fov)/this.zoom)}getFilmWidth(){return this.filmGauge*Math.min(this.aspect,1)}getFilmHeight(){return this.filmGauge/Math.max(this.aspect,1)}getViewBounds(t,e,i){Ks.set(-1,-1,.5).applyMatrix4(this.projectionMatrixInverse),e.set(Ks.x,Ks.y).multiplyScalar(-t/Ks.z),Ks.set(1,1,.5).applyMatrix4(this.projectionMatrixInverse),i.set(Ks.x,Ks.y).multiplyScalar(-t/Ks.z)}getViewSize(t,e){return this.getViewBounds(t,Gp,Vp),e.subVectors(Vp,Gp)}setViewOffset(t,e,i,n,s,r){this.aspect=t/e,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=t,this.view.fullHeight=e,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 t=this.near;let e=t*Math.tan(Go*.5*this.fov)/this.zoom,i=2*e,n=this.aspect*i,s=-.5*n;const r=this.view;if(this.view!==null&&this.view.enabled){const c=r.fullWidth,l=r.fullHeight;s+=r.offsetX*n/c,e-=r.offsetY*i/l,n*=r.width/c,i*=r.height/l}const o=this.filmOffset;o!==0&&(s+=t*o/this.getFilmWidth()),this.projectionMatrix.makePerspective(s,s+n,e,e-i,t,this.far,this.coordinateSystem,this.reversedDepth),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(t){const e=super.toJSON(t);return e.object.fov=this.fov,e.object.zoom=this.zoom,e.object.near=this.near,e.object.far=this.far,e.object.focus=this.focus,e.object.aspect=this.aspect,this.view!==null&&(e.object.view=Object.assign({},this.view)),e.object.filmGauge=this.filmGauge,e.object.filmOffset=this.filmOffset,e}}class kx extends q0{constructor(){super(new rn(50,1,.5,500)),this.isSpotLightShadow=!0,this.focus=1,this.aspect=1}updateMatrices(t){const e=this.camera,i=Qa*2*t.angle*this.focus,n=this.mapSize.width/this.mapSize.height*this.aspect,s=t.distance||e.far;(i!==e.fov||n!==e.aspect||s!==e.far)&&(e.fov=i,e.aspect=n,e.far=s,e.updateProjectionMatrix()),super.updateMatrices(t)}copy(t){return super.copy(t),this.focus=t.focus,this}}class iT extends ph{constructor(t,e,i=0,n=Math.PI/3,s=0,r=2){super(t,e),this.isSpotLight=!0,this.type="SpotLight",this.position.copy(Ge.DEFAULT_UP),this.updateMatrix(),this.target=new Ge,this.distance=i,this.angle=n,this.penumbra=s,this.decay=r,this.map=null,this.shadow=new kx}get power(){return this.intensity*Math.PI}set power(t){this.intensity=t/Math.PI}dispose(){super.dispose(),this.shadow.dispose()}copy(t,e){return super.copy(t,e),this.distance=t.distance,this.angle=t.angle,this.penumbra=t.penumbra,this.decay=t.decay,this.target=t.target.clone(),this.map=t.map,this.shadow=t.shadow.clone(),this}toJSON(t){const e=super.toJSON(t);return e.object.distance=this.distance,e.object.angle=this.angle,e.object.decay=this.decay,e.object.penumbra=this.penumbra,e.object.target=this.target.uuid,this.map&&this.map.isTexture&&(e.object.map=this.map.toJSON(t).uuid),e.object.shadow=this.shadow.toJSON(),e}}class zx extends q0{constructor(){super(new rn(90,1,.5,500)),this.isPointLightShadow=!0}}class I1 extends ph{constructor(t,e,i=0,n=2){super(t,e),this.isPointLight=!0,this.type="PointLight",this.distance=i,this.decay=n,this.shadow=new zx}get power(){return this.intensity*4*Math.PI}set power(t){this.intensity=t/(4*Math.PI)}dispose(){super.dispose(),this.shadow.dispose()}copy(t,e){return super.copy(t,e),this.distance=t.distance,this.decay=t.decay,this.shadow=t.shadow.clone(),this}toJSON(t){const e=super.toJSON(t);return e.object.distance=this.distance,e.object.decay=this.decay,e.object.shadow=this.shadow.toJSON(),e}}class Zn extends D1{constructor(t=-1,e=1,i=1,n=-1,s=.1,r=2e3){super(),this.isOrthographicCamera=!0,this.type="OrthographicCamera",this.zoom=1,this.view=null,this.left=t,this.right=e,this.top=i,this.bottom=n,this.near=s,this.far=r,this.updateProjectionMatrix()}copy(t,e){return super.copy(t,e),this.left=t.left,this.right=t.right,this.top=t.top,this.bottom=t.bottom,this.near=t.near,this.far=t.far,this.zoom=t.zoom,this.view=t.view===null?null:Object.assign({},t.view),this}setViewOffset(t,e,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=t,this.view.fullHeight=e,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 t=(this.right-this.left)/(2*this.zoom),e=(this.top-this.bottom)/(2*this.zoom),i=(this.right+this.left)/2,n=(this.top+this.bottom)/2;let s=i-t,r=i+t,o=n+e,c=n-e;if(this.view!==null&&this.view.enabled){const l=(this.right-this.left)/this.view.fullWidth/this.zoom,h=(this.top-this.bottom)/this.view.fullHeight/this.zoom;s+=l*this.view.offsetX,r=s+l*this.view.width,o-=h*this.view.offsetY,c=o-h*this.view.height}this.projectionMatrix.makeOrthographic(s,r,o,c,this.near,this.far,this.coordinateSystem,this.reversedDepth),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(t){const e=super.toJSON(t);return e.object.zoom=this.zoom,e.object.left=this.left,e.object.right=this.right,e.object.top=this.top,e.object.bottom=this.bottom,e.object.near=this.near,e.object.far=this.far,this.view!==null&&(e.object.view=Object.assign({},this.view)),e}}class Bx extends q0{constructor(){super(new Zn(-5,5,5,-5,.5,500)),this.isDirectionalLightShadow=!0}}class Wp extends ph{constructor(t,e){super(t,e),this.isDirectionalLight=!0,this.type="DirectionalLight",this.position.copy(Ge.DEFAULT_UP),this.updateMatrix(),this.target=new Ge,this.shadow=new Bx}dispose(){super.dispose(),this.shadow.dispose()}copy(t){return super.copy(t),this.target=t.target.clone(),this.shadow=t.shadow.clone(),this}toJSON(t){const e=super.toJSON(t);return e.object.shadow=this.shadow.toJSON(),e.object.target=this.target.uuid,e}}class nT{static extractUrlBase(t){const e=t.lastIndexOf("/");return e===-1?"./":t.slice(0,e+1)}static resolveURL(t,e){return typeof t!="string"||t===""?"":(/^https?:\/\//i.test(e)&&/^\//.test(t)&&(e=e.replace(/(^https?:\/\/[^\/]+).*/i,"$1")),/^(https?:)?\/\//i.test(t)||/^data:.*,.*$/i.test(t)||/^blob:.*$/i.test(t)?t:e+t)}}class sT extends se{constructor(){super(),this.isInstancedBufferGeometry=!0,this.type="InstancedBufferGeometry",this.instanceCount=1/0}copy(t){return super.copy(t),this.instanceCount=t.instanceCount,this}toJSON(){const t=super.toJSON();return t.instanceCount=this.instanceCount,t.isInstancedBufferGeometry=!0,t}}const au=new WeakMap;class rT extends mc{constructor(t){super(t),this.isImageBitmapLoader=!0,typeof createImageBitmap>"u"&&It("ImageBitmapLoader: createImageBitmap() not supported."),typeof fetch>"u"&&It("ImageBitmapLoader: fetch() not supported."),this.options={premultiplyAlpha:"none"},this._abortController=new AbortController}setOptions(t){return this.options=t,this}load(t,e,i,n){t===void 0&&(t=""),this.path!==void 0&&(t=this.path+t),t=this.manager.resolveURL(t);const s=this,r=Os.get(`image-bitmap:${t}`);if(r!==void 0){if(s.manager.itemStart(t),r.then){r.then(l=>{au.has(r)===!0?(n&&n(au.get(r)),s.manager.itemError(t),s.manager.itemEnd(t)):(e&&e(l),s.manager.itemEnd(t))});return}setTimeout(function(){e&&e(r),s.manager.itemEnd(t)},0);return}const o={};o.credentials=this.crossOrigin==="anonymous"?"same-origin":"include",o.headers=this.requestHeader,o.signal=typeof AbortSignal.any=="function"?AbortSignal.any([this._abortController.signal,this.manager.abortController.signal]):this._abortController.signal;const c=fetch(t,o).then(function(l){return l.blob()}).then(function(l){return createImageBitmap(l,Object.assign(s.options,{colorSpaceConversion:"none"}))}).then(function(l){Os.add(`image-bitmap:${t}`,l),e&&e(l),s.manager.itemEnd(t)}).catch(function(l){n&&n(l),au.set(c,l),Os.remove(`image-bitmap:${t}`),s.manager.itemError(t),s.manager.itemEnd(t)});Os.add(`image-bitmap:${t}`,c),s.manager.itemStart(t)}abort(){return this._abortController.abort(),this._abortController=new AbortController,this}}const va=-90,Ma=1;class $0 extends Ge{constructor(t,e,i){super(),this.type="CubeCamera",this.renderTarget=i,this.coordinateSystem=null,this.activeMipmapLevel=0;const n=new rn(va,Ma,t,e);n.layers=this.layers,this.add(n);const s=new rn(va,Ma,t,e);s.layers=this.layers,this.add(s);const r=new rn(va,Ma,t,e);r.layers=this.layers,this.add(r);const o=new rn(va,Ma,t,e);o.layers=this.layers,this.add(o);const c=new rn(va,Ma,t,e);c.layers=this.layers,this.add(c);const l=new rn(va,Ma,t,e);l.layers=this.layers,this.add(l)}updateCoordinateSystem(){const t=this.coordinateSystem,e=this.children.concat(),[i,n,s,r,o,c]=e;for(const l of e)this.remove(l);if(t===ms)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),o.up.set(0,1,0),o.lookAt(0,0,1),c.up.set(0,1,0),c.lookAt(0,0,-1);else if(t===oc)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),o.up.set(0,-1,0),o.lookAt(0,0,1),c.up.set(0,-1,0),c.lookAt(0,0,-1);else throw new Error("THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: "+t);for(const l of e)this.add(l),l.updateMatrixWorld()}update(t,e){this.parent===null&&this.updateMatrixWorld();const{renderTarget:i,activeMipmapLevel:n}=this;this.coordinateSystem!==t.coordinateSystem&&(this.coordinateSystem=t.coordinateSystem,this.updateCoordinateSystem());const[s,r,o,c,l,h]=this.children,u=t.getRenderTarget(),d=t.getActiveCubeFace(),f=t.getActiveMipmapLevel(),p=t.xr.enabled;t.xr.enabled=!1;const v=i.texture.generateMipmaps;i.texture.generateMipmaps=!1;let m=!1;t.isWebGLRenderer===!0?m=t.state.buffers.depth.getReversed():m=t.reversedDepthBuffer,t.setRenderTarget(i,0,n),m&&t.autoClear===!1&&t.clearDepth(),t.render(e,s),t.setRenderTarget(i,1,n),m&&t.autoClear===!1&&t.clearDepth(),t.render(e,r),t.setRenderTarget(i,2,n),m&&t.autoClear===!1&&t.clearDepth(),t.render(e,o),t.setRenderTarget(i,3,n),m&&t.autoClear===!1&&t.clearDepth(),t.render(e,c),t.setRenderTarget(i,4,n),m&&t.autoClear===!1&&t.clearDepth(),t.render(e,l),i.texture.generateMipmaps=v,t.setRenderTarget(i,5,n),m&&t.autoClear===!1&&t.clearDepth(),t.render(e,h),t.setRenderTarget(u,d,f),t.xr.enabled=p,i.texture.needsPMREMUpdate=!0}}class Hx extends rn{constructor(t=[]){super(),this.isArrayCamera=!0,this.isMultiViewCamera=!1,this.cameras=t}}class Gx{constructor(t,e,i){this.binding=t,this.valueSize=i;let n,s,r;switch(e){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(t,e){const i=this.buffer,n=this.valueSize,s=t*n+n;let r=this.cumulativeWeight;if(r===0){for(let o=0;o!==n;++o)i[s+o]=i[o];r=e}else{r+=e;const o=e/r;this._mixBufferRegion(i,s,0,o,n)}this.cumulativeWeight=r}accumulateAdditive(t){const e=this.buffer,i=this.valueSize,n=i*this._addIndex;this.cumulativeWeightAdditive===0&&this._setIdentity(),this._mixBufferRegionAdditive(e,n,0,t,i),this.cumulativeWeightAdditive+=t}apply(t){const e=this.valueSize,i=this.buffer,n=t*e+e,s=this.cumulativeWeight,r=this.cumulativeWeightAdditive,o=this.binding;if(this.cumulativeWeight=0,this.cumulativeWeightAdditive=0,s<1){const c=e*this._origIndex;this._mixBufferRegion(i,n,c,1-s,e)}r>0&&this._mixBufferRegionAdditive(i,n,this._addIndex*e,1,e);for(let c=e,l=e+e;c!==l;++c)if(i[c]!==i[c+e]){o.setValue(i,n);break}}saveOriginalState(){const t=this.binding,e=this.buffer,i=this.valueSize,n=i*this._origIndex;t.getValue(e,n);for(let s=i,r=n;s!==r;++s)e[s]=e[n+s%i];this._setIdentity(),this.cumulativeWeight=0,this.cumulativeWeightAdditive=0}restoreOriginalState(){const t=this.valueSize*3;this.binding.setValue(this.buffer,t)}_setAdditiveIdentityNumeric(){const t=this._addIndex*this.valueSize,e=t+this.valueSize;for(let i=t;i<e;i++)this.buffer[i]=0}_setAdditiveIdentityQuaternion(){this._setAdditiveIdentityNumeric(),this.buffer[this._addIndex*this.valueSize+3]=1}_setAdditiveIdentityOther(){const t=this._origIndex*this.valueSize,e=this._addIndex*this.valueSize;for(let i=0;i<this.valueSize;i++)this.buffer[e+i]=this.buffer[t+i]}_select(t,e,i,n,s){if(n>=.5)for(let r=0;r!==s;++r)t[e+r]=t[i+r]}_slerp(t,e,i,n){on.slerpFlat(t,e,t,e,t,i,n)}_slerpAdditive(t,e,i,n,s){const r=this._workIndex*s;on.multiplyQuaternionsFlat(t,r,t,e,t,i),on.slerpFlat(t,e,t,e,t,r,n)}_lerp(t,e,i,n,s){const r=1-n;for(let o=0;o!==s;++o){const c=e+o;t[c]=t[c]*r+t[i+o]*n}}_lerpAdditive(t,e,i,n,s){for(let r=0;r!==s;++r){const o=e+r;t[o]=t[o]+t[i+r]*n}}}const K0="\\[\\]\\.:\\/",Vx=new RegExp("["+K0+"]","g"),Z0="[^"+K0+"]",Wx="[^"+K0.replace("\\.","")+"]",Xx=/((?:WC+[\/:])*)/.source.replace("WC",Z0),Yx=/(WCOD+)?/.source.replace("WCOD",Wx),qx=/(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace("WC",Z0),$x=/\.(WC+)(?:\[(.+)\])?/.source.replace("WC",Z0),Kx=new RegExp("^"+Xx+Yx+qx+$x+"$"),Zx=["material","materials","bones","map"];class Jx{constructor(t,e,i){const n=i||Ae.parseTrackName(e);this._targetGroup=t,this._bindings=t.subscribe_(e,n)}getValue(t,e){this.bind();const i=this._targetGroup.nCachedObjects_,n=this._bindings[i];n!==void 0&&n.getValue(t,e)}setValue(t,e){const i=this._bindings;for(let n=this._targetGroup.nCachedObjects_,s=i.length;n!==s;++n)i[n].setValue(t,e)}bind(){const t=this._bindings;for(let e=this._targetGroup.nCachedObjects_,i=t.length;e!==i;++e)t[e].bind()}unbind(){const t=this._bindings;for(let e=this._targetGroup.nCachedObjects_,i=t.length;e!==i;++e)t[e].unbind()}}class Ae{constructor(t,e,i){this.path=e,this.parsedPath=i||Ae.parseTrackName(e),this.node=Ae.findNode(t,this.parsedPath.nodeName),this.rootNode=t,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}static create(t,e,i){return t&&t.isAnimationObjectGroup?new Ae.Composite(t,e,i):new Ae(t,e,i)}static sanitizeNodeName(t){return t.replace(/\s/g,"_").replace(Vx,"")}static parseTrackName(t){const e=Kx.exec(t);if(e===null)throw new Error("THREE.PropertyBinding: Cannot parse trackName: "+t);const i={nodeName:e[2],objectName:e[3],objectIndex:e[4],propertyName:e[5],propertyIndex:e[6]},n=i.nodeName&&i.nodeName.lastIndexOf(".");if(n!==void 0&&n!==-1){const s=i.nodeName.substring(n+1);Zx.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: "+t);return i}static findNode(t,e){if(e===void 0||e===""||e==="."||e===-1||e===t.name||e===t.uuid)return t;if(t.skeleton){const i=t.skeleton.getBoneByName(e);if(i!==void 0)return i}if(t.children){const i=function(s){for(let r=0;r<s.length;r++){const o=s[r];if(o.name===e||o.uuid===e)return o;const c=i(o.children);if(c)return c}return null},n=i(t.children);if(n)return n}return null}_getValue_unavailable(){}_setValue_unavailable(){}_getValue_direct(t,e){t[e]=this.targetObject[this.propertyName]}_getValue_array(t,e){const i=this.resolvedProperty;for(let n=0,s=i.length;n!==s;++n)t[e++]=i[n]}_getValue_arrayElement(t,e){t[e]=this.resolvedProperty[this.propertyIndex]}_getValue_toArray(t,e){this.resolvedProperty.toArray(t,e)}_setValue_direct(t,e){this.targetObject[this.propertyName]=t[e]}_setValue_direct_setNeedsUpdate(t,e){this.targetObject[this.propertyName]=t[e],this.targetObject.needsUpdate=!0}_setValue_direct_setMatrixWorldNeedsUpdate(t,e){this.targetObject[this.propertyName]=t[e],this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_array(t,e){const i=this.resolvedProperty;for(let n=0,s=i.length;n!==s;++n)i[n]=t[e++]}_setValue_array_setNeedsUpdate(t,e){const i=this.resolvedProperty;for(let n=0,s=i.length;n!==s;++n)i[n]=t[e++];this.targetObject.needsUpdate=!0}_setValue_array_setMatrixWorldNeedsUpdate(t,e){const i=this.resolvedProperty;for(let n=0,s=i.length;n!==s;++n)i[n]=t[e++];this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_arrayElement(t,e){this.resolvedProperty[this.propertyIndex]=t[e]}_setValue_arrayElement_setNeedsUpdate(t,e){this.resolvedProperty[this.propertyIndex]=t[e],this.targetObject.needsUpdate=!0}_setValue_arrayElement_setMatrixWorldNeedsUpdate(t,e){this.resolvedProperty[this.propertyIndex]=t[e],this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_fromArray(t,e){this.resolvedProperty.fromArray(t,e)}_setValue_fromArray_setNeedsUpdate(t,e){this.resolvedProperty.fromArray(t,e),this.targetObject.needsUpdate=!0}_setValue_fromArray_setMatrixWorldNeedsUpdate(t,e){this.resolvedProperty.fromArray(t,e),this.targetObject.matrixWorldNeedsUpdate=!0}_getValue_unbound(t,e){this.bind(),this.getValue(t,e)}_setValue_unbound(t,e){this.bind(),this.setValue(t,e)}bind(){let t=this.node;const e=this.parsedPath,i=e.objectName,n=e.propertyName;let s=e.propertyIndex;if(t||(t=Ae.findNode(this.rootNode,e.nodeName),this.node=t),this.getValue=this._getValue_unavailable,this.setValue=this._setValue_unavailable,!t){It("PropertyBinding: No target node found for track: "+this.path+".");return}if(i){let l=e.objectIndex;switch(i){case"materials":if(!t.material){Wt("PropertyBinding: Can not bind to material as node does not have a material.",this);return}if(!t.material.materials){Wt("PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.",this);return}t=t.material.materials;break;case"bones":if(!t.skeleton){Wt("PropertyBinding: Can not bind to bones as node does not have a skeleton.",this);return}t=t.skeleton.bones;for(let h=0;h<t.length;h++)if(t[h].name===l){l=h;break}break;case"map":if("map"in t){t=t.map;break}if(!t.material){Wt("PropertyBinding: Can not bind to material as node does not have a material.",this);return}if(!t.material.map){Wt("PropertyBinding: Can not bind to material.map as node.material does not have a map.",this);return}t=t.material.map;break;default:if(t[i]===void 0){Wt("PropertyBinding: Can not bind to objectName of node undefined.",this);return}t=t[i]}if(l!==void 0){if(t[l]===void 0){Wt("PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.",this,t);return}t=t[l]}}const r=t[n];if(r===void 0){const l=e.nodeName;Wt("PropertyBinding: Trying to update property for track: "+l+"."+n+" but it wasn't found.",t);return}let o=this.Versioning.None;this.targetObject=t,t.isMaterial===!0?o=this.Versioning.NeedsUpdate:t.isObject3D===!0&&(o=this.Versioning.MatrixWorldNeedsUpdate);let c=this.BindingType.Direct;if(s!==void 0){if(n==="morphTargetInfluences"){if(!t.geometry){Wt("PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.",this);return}if(!t.geometry.morphAttributes){Wt("PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.",this);return}t.morphTargetDictionary[s]!==void 0&&(s=t.morphTargetDictionary[s])}c=this.BindingType.ArrayElement,this.resolvedProperty=r,this.propertyIndex=s}else r.fromArray!==void 0&&r.toArray!==void 0?(c=this.BindingType.HasFromToArray,this.resolvedProperty=r):Array.isArray(r)?(c=this.BindingType.EntireArray,this.resolvedProperty=r):this.propertyName=n;this.getValue=this.GetterByBindingType[c],this.setValue=this.SetterByBindingTypeAndVersioning[c][o]}unbind(){this.node=null,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}}Ae.Composite=Jx;Ae.prototype.BindingType={Direct:0,EntireArray:1,ArrayElement:2,HasFromToArray:3};Ae.prototype.Versioning={None:0,NeedsUpdate:1,MatrixWorldNeedsUpdate:2};Ae.prototype.GetterByBindingType=[Ae.prototype._getValue_direct,Ae.prototype._getValue_array,Ae.prototype._getValue_arrayElement,Ae.prototype._getValue_toArray];Ae.prototype.SetterByBindingTypeAndVersioning=[[Ae.prototype._setValue_direct,Ae.prototype._setValue_direct_setNeedsUpdate,Ae.prototype._setValue_direct_setMatrixWorldNeedsUpdate],[Ae.prototype._setValue_array,Ae.prototype._setValue_array_setNeedsUpdate,Ae.prototype._setValue_array_setMatrixWorldNeedsUpdate],[Ae.prototype._setValue_arrayElement,Ae.prototype._setValue_arrayElement_setNeedsUpdate,Ae.prototype._setValue_arrayElement_setMatrixWorldNeedsUpdate],[Ae.prototype._setValue_fromArray,Ae.prototype._setValue_fromArray_setNeedsUpdate,Ae.prototype._setValue_fromArray_setMatrixWorldNeedsUpdate]];class jx{constructor(t,e,i=null,n=e.blendMode){this._mixer=t,this._clip=e,this._localRoot=i,this.blendMode=n;const s=e.tracks,r=s.length,o=new Array(r),c={endingStart:Da,endingEnd:Da};for(let l=0;l!==r;++l){const h=s[l].createInterpolant(null);o[l]=h,h.settings=c}this._interpolantSettings=c,this._interpolants=o,this._propertyBindings=new Array(r),this._cacheIndex=null,this._byClipCacheIndex=null,this._timeScaleInterpolant=null,this._restoreTimeScale=null,this._weightInterpolant=null,this.loop=uM,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(t){return this._startTime=t,this}setLoop(t,e){return this.loop=t,this.repetitions=e,this}setEffectiveWeight(t){return this.weight=t,this._effectiveWeight=this.enabled?t:0,this.stopFading()}getEffectiveWeight(){return this._effectiveWeight}fadeIn(t){return this._scheduleFading(t,0,1)}fadeOut(t){return this._scheduleFading(t,1,0)}crossFadeFrom(t,e,i=!1){if(t.fadeOut(e),this.fadeIn(e),i===!0){const n=this._clip.duration,s=t._clip.duration,r=s/n,o=n/s;t._restoreTimeScale=t.timeScale,this._restoreTimeScale=this.timeScale,t.warp(1,r,e),this.warp(o,1,e)}return this}crossFadeTo(t,e,i=!1){return t.crossFadeFrom(this,e,i)}stopFading(){const t=this._weightInterpolant;return t!==null&&(this._weightInterpolant=null,this._mixer._takeBackControlInterpolant(t)),this}setEffectiveTimeScale(t){return this.timeScale=t,this._effectiveTimeScale=this.paused?0:t,this.stopWarping()}getEffectiveTimeScale(){return this._effectiveTimeScale}setDuration(t){return this.timeScale=this._clip.duration/t,this.stopWarping()}syncWith(t){return this.time=t.time,this.timeScale=t.timeScale,this.stopWarping()}halt(t){return this.warp(this._effectiveTimeScale,0,t)}warp(t,e,i){const n=this._mixer,s=n.time,r=this.timeScale;let o=this._timeScaleInterpolant;o===null&&(o=n._lendControlInterpolant(),this._timeScaleInterpolant=o);const c=o.parameterPositions,l=o.sampleValues;return c[0]=s,c[1]=s+i,l[0]=t/r,l[1]=e/r,this}stopWarping(){const t=this._timeScaleInterpolant;return t!==null&&(this._timeScaleInterpolant=null,this._mixer._takeBackControlInterpolant(t)),this._restoreTimeScale=null,this}getMixer(){return this._mixer}getClip(){return this._clip}getRoot(){return this._localRoot||this._mixer._root}_update(t,e,i,n){if(!this.enabled){this._updateWeight(t);return}const s=this._startTime;if(s!==null){const c=(t-s)*i;c<0||i===0?e=0:(this._startTime=null,e=i*c)}e*=this._updateTimeScale(t);const r=this._updateTime(e),o=this._updateWeight(t);if(o>0){const c=this._interpolants,l=this._propertyBindings;switch(this.blendMode){case fM:for(let h=0,u=c.length;h!==u;++h)c[h].evaluate(r),l[h].accumulateAdditive(o);break;case O0:default:for(let h=0,u=c.length;h!==u;++h)c[h].evaluate(r),l[h].accumulate(n,o)}}}_updateWeight(t){let e=0;if(this.enabled){e=this.weight;const i=this._weightInterpolant;if(i!==null){const n=i.evaluate(t)[0];e*=n,t>i.parameterPositions[1]&&(this.stopFading(),n===0&&(this.enabled=!1))}}return this._effectiveWeight=e,e}_updateTimeScale(t){let e=0;if(!this.paused){e=this.timeScale;const i=this._timeScaleInterpolant;if(i!==null){const n=i.evaluate(t)[0];e*=n,t>i.parameterPositions[1]&&(e===0?this.paused=!0:(this._restoreTimeScale!==null&&(e=this._restoreTimeScale),this.timeScale=e),this.stopWarping())}}return this._effectiveTimeScale=e,e}_updateTime(t){const e=this._clip.duration,i=this.loop;let n=this.time+t,s=this._loopCount;const r=i===dM;if(t===0)return s===-1?n:r&&(s&1)===1?e-n:n;if(i===d1){s===-1&&(this._loopCount=0,this._setEndings(!0,!0,!1));t:{if(n>=e)n=e;else if(n<0)n=0;else{this.time=n;break t}this.clampWhenFinished?this.paused=!0:this.enabled=!1,this.time=n,this._mixer.dispatchEvent({type:"finished",action:this,direction:t<0?-1:1})}}else{if(s===-1&&(t>=0?(s=0,this._setEndings(!0,this.repetitions===0,r)):this._setEndings(this.repetitions===0,!0,r)),n>=e||n<0){const o=Math.floor(n/e);n-=e*o,s+=Math.abs(o);const c=this.repetitions-s;if(c<=0)this.clampWhenFinished?this.paused=!0:this.enabled=!1,n=t>0?e:0,this.time=n,this._mixer.dispatchEvent({type:"finished",action:this,direction:t>0?1:-1});else{if(c===1){const l=t<0;this._setEndings(l,!l,r)}else this._setEndings(!1,!1,r);this._loopCount=s,this.time=n,this._mixer.dispatchEvent({type:"loop",action:this,loopDelta:o})}}else this._loopCount=s,this.time=n;if(r&&(s&1)===1)return e-n}return n}_setEndings(t,e,i){const n=this._interpolantSettings;i?(n.endingStart=Ia,n.endingEnd=Ia):(t?n.endingStart=this.zeroSlopeAtStart?Ia:Da:n.endingStart=Hl,e?n.endingEnd=this.zeroSlopeAtEnd?Ia:Da:n.endingEnd=Hl)}_scheduleFading(t,e,i){const n=this._mixer,s=n.time;let r=this._weightInterpolant;r===null&&(r=n._lendControlInterpolant(),this._weightInterpolant=r);const o=r.parameterPositions,c=r.sampleValues;return o[0]=s,c[0]=e,o[1]=s+t,c[1]=i,this}}const Qx=new Float32Array(1);class ty extends vr{constructor(t){super(),this._root=t,this._initMemoryManager(),this._accuIndex=0,this.time=0,this.timeScale=1,typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}_bindAction(t,e){const i=t._localRoot||this._root,n=t._clip.tracks,s=n.length,r=t._propertyBindings,o=t._interpolants,c=i.uuid,l=this._bindingsByRootAndName;let h=l[c];h===void 0&&(h={},l[c]=h);for(let u=0;u!==s;++u){const d=n[u],f=d.name;let p=h[f];if(p!==void 0)++p.referenceCount,r[u]=p;else{if(p=r[u],p!==void 0){p._cacheIndex===null&&(++p.referenceCount,this._addInactiveBinding(p,c,f));continue}const v=e&&e._propertyBindings[u].binding.parsedPath;p=new Gx(Ae.create(i,f,v),d.ValueTypeName,d.getValueSize()),++p.referenceCount,this._addInactiveBinding(p,c,f),r[u]=p}o[u].resultBuffer=p.buffer}}_activateAction(t){if(!this._isActiveAction(t)){if(t._cacheIndex===null){const i=(t._localRoot||this._root).uuid,n=t._clip.uuid,s=this._actionsByClip[n];this._bindAction(t,s&&s.knownActions[0]),this._addInactiveAction(t,n,i)}const e=t._propertyBindings;for(let i=0,n=e.length;i!==n;++i){const s=e[i];s.useCount++===0&&(this._lendBinding(s),s.saveOriginalState())}this._lendAction(t)}}_deactivateAction(t){if(this._isActiveAction(t)){const e=t._propertyBindings;for(let i=0,n=e.length;i!==n;++i){const s=e[i];--s.useCount===0&&(s.restoreOriginalState(),this._takeBackBinding(s))}this._takeBackAction(t)}}_initMemoryManager(){this._actions=[],this._nActiveActions=0,this._actionsByClip={},this._bindings=[],this._nActiveBindings=0,this._bindingsByRootAndName={},this._controlInterpolants=[],this._nActiveControlInterpolants=0;const t=this;this.stats={actions:{get total(){return t._actions.length},get inUse(){return t._nActiveActions}},bindings:{get total(){return t._bindings.length},get inUse(){return t._nActiveBindings}},controlInterpolants:{get total(){return t._controlInterpolants.length},get inUse(){return t._nActiveControlInterpolants}}}}_isActiveAction(t){const e=t._cacheIndex;return e!==null&&e<this._nActiveActions}_addInactiveAction(t,e,i){const n=this._actions,s=this._actionsByClip;let r=s[e];if(r===void 0)r={knownActions:[t],actionByRoot:{}},t._byClipCacheIndex=0,s[e]=r;else{const o=r.knownActions;t._byClipCacheIndex=o.length,o.push(t)}t._cacheIndex=n.length,n.push(t),r.actionByRoot[i]=t}_removeInactiveAction(t){const e=this._actions,i=e[e.length-1],n=t._cacheIndex;i._cacheIndex=n,e[n]=i,e.pop(),t._cacheIndex=null;const s=t._clip.uuid,r=this._actionsByClip,o=r[s],c=o.knownActions,l=c[c.length-1],h=t._byClipCacheIndex;l._byClipCacheIndex=h,c[h]=l,c.pop(),t._byClipCacheIndex=null;const u=o.actionByRoot,d=(t._localRoot||this._root).uuid;delete u[d],c.length===0&&delete r[s],this._removeInactiveBindingsForAction(t)}_removeInactiveBindingsForAction(t){const e=t._propertyBindings;for(let i=0,n=e.length;i!==n;++i){const s=e[i];--s.referenceCount===0&&this._removeInactiveBinding(s)}}_lendAction(t){const e=this._actions,i=t._cacheIndex,n=this._nActiveActions++,s=e[n];t._cacheIndex=n,e[n]=t,s._cacheIndex=i,e[i]=s}_takeBackAction(t){const e=this._actions,i=t._cacheIndex,n=--this._nActiveActions,s=e[n];t._cacheIndex=n,e[n]=t,s._cacheIndex=i,e[i]=s}_addInactiveBinding(t,e,i){const n=this._bindingsByRootAndName,s=this._bindings;let r=n[e];r===void 0&&(r={},n[e]=r),r[i]=t,t._cacheIndex=s.length,s.push(t)}_removeInactiveBinding(t){const e=this._bindings,i=t.binding,n=i.rootNode.uuid,s=i.path,r=this._bindingsByRootAndName,o=r[n],c=e[e.length-1],l=t._cacheIndex;c._cacheIndex=l,e[l]=c,e.pop(),delete o[s],Object.keys(o).length===0&&delete r[n]}_lendBinding(t){const e=this._bindings,i=t._cacheIndex,n=this._nActiveBindings++,s=e[n];t._cacheIndex=n,e[n]=t,s._cacheIndex=i,e[i]=s}_takeBackBinding(t){const e=this._bindings,i=t._cacheIndex,n=--this._nActiveBindings,s=e[n];t._cacheIndex=n,e[n]=t,s._cacheIndex=i,e[i]=s}_lendControlInterpolant(){const t=this._controlInterpolants,e=this._nActiveControlInterpolants++;let i=t[e];return i===void 0&&(i=new A1(new Float32Array(2),new Float32Array(2),1,Qx),i.__cacheIndex=e,t[e]=i),i}_takeBackControlInterpolant(t){const e=this._controlInterpolants,i=t.__cacheIndex,n=--this._nActiveControlInterpolants,s=e[n];t.__cacheIndex=n,e[n]=t,s.__cacheIndex=i,e[i]=s}clipAction(t,e,i){const n=e||this._root,s=n.uuid;let r=typeof t=="string"?kp.findByName(n,t):t;const o=r!==null?r.uuid:t,c=this._actionsByClip[o];let l=null;if(i===void 0&&(r!==null?i=r.blendMode:i=O0),c!==void 0){const u=c.actionByRoot[s];if(u!==void 0&&u.blendMode===i)return u;l=c.knownActions[0],r===null&&(r=l._clip)}if(r===null)return null;const h=new jx(this,r,e,i);return this._bindAction(h,l),this._addInactiveAction(h,o,s),h}existingAction(t,e){const i=e||this._root,n=i.uuid,s=typeof t=="string"?kp.findByName(i,t):t,r=s?s.uuid:t,o=this._actionsByClip[r];return o!==void 0&&o.actionByRoot[n]||null}stopAllAction(){const t=this._actions,e=this._nActiveActions;for(let i=e-1;i>=0;--i)t[i].stop();return this}update(t){t*=this.timeScale;const e=this._actions,i=this._nActiveActions,n=this.time+=t,s=Math.sign(t),r=this._accuIndex^=1;for(let l=0;l!==i;++l)e[l]._update(n,t,s,r);const o=this._bindings,c=this._nActiveBindings;for(let l=0;l!==c;++l)o[l].apply(r);return this}setTime(t){this.time=0;for(let e=0;e<this._actions.length;e++)this._actions[e].time=0;return this.update(t)}getRoot(){return this._root}uncacheClip(t){const e=this._actions,i=t.uuid,n=this._actionsByClip,s=n[i];if(s!==void 0){const r=s.knownActions;for(let o=0,c=r.length;o!==c;++o){const l=r[o];this._deactivateAction(l);const h=l._cacheIndex,u=e[e.length-1];l._cacheIndex=null,l._byClipCacheIndex=null,u._cacheIndex=h,e[h]=u,e.pop(),this._removeInactiveBindingsForAction(l)}delete n[i]}}uncacheRoot(t){const e=t.uuid,i=this._actionsByClip;for(const r in i){const o=i[r].actionByRoot,c=o[e];c!==void 0&&(this._deactivateAction(c),this._removeInactiveAction(c))}const n=this._bindingsByRootAndName,s=n[e];if(s!==void 0)for(const r in s){const o=s[r];o.restoreOriginalState(),this._removeInactiveBinding(o)}}uncacheAction(t,e){const i=this.existingAction(t,e);i!==null&&(this._deactivateAction(i),this._removeInactiveAction(i))}}class aT extends M1{constructor(t,e,i=1){super(t,e),this.isInstancedInterleavedBuffer=!0,this.meshPerAttribute=i}copy(t){return super.copy(t),this.meshPerAttribute=t.meshPerAttribute,this}clone(t){const e=super.clone(t);return e.meshPerAttribute=this.meshPerAttribute,e}toJSON(t){const e=super.toJSON(t);return e.isInstancedInterleavedBuffer=!0,e.meshPerAttribute=this.meshPerAttribute,e}}const Xp=new te;class Cl{constructor(t,e,i=0,n=1/0){this.ray=new fc(t,e),this.near=i,this.far=n,this.camera=null,this.layers=new z0,this.params={Mesh:{},Line:{threshold:1},LOD:{},Points:{threshold:1},Sprite:{}}}set(t,e){this.ray.set(t,e)}setFromCamera(t,e){e.isPerspectiveCamera?(this.ray.origin.setFromMatrixPosition(e.matrixWorld),this.ray.direction.set(t.x,t.y,.5).unproject(e).sub(this.ray.origin).normalize(),this.camera=e):e.isOrthographicCamera?(this.ray.origin.set(t.x,t.y,e.projectionMatrix.elements[14]).unproject(e),this.ray.direction.set(0,0,-1).transformDirection(e.matrixWorld),this.camera=e):Wt("Raycaster: Unsupported camera type: "+e.type)}setFromXRController(t){return Xp.identity().extractRotation(t.matrixWorld),this.ray.origin.setFromMatrixPosition(t.matrixWorld),this.ray.direction.set(0,0,-1).applyMatrix4(Xp),this}intersectObject(t,e=!0,i=[]){return Vd(t,this,i,e),i.sort(Yp),i}intersectObjects(t,e=!0,i=[]){for(let n=0,s=t.length;n<s;n++)Vd(t[n],this,i,e);return i.sort(Yp),i}}function Yp(a,t){return a.distance-t.distance}function Vd(a,t,e,i){let n=!0;if(a.layers.test(t.layers)&&a.raycast(t,e)===!1&&(n=!1),n===!0&&i===!0){const s=a.children;for(let r=0,o=s.length;r<o;r++)Vd(s[r],t,e,!0)}}class C1{static{C1.prototype.isMatrix2=!0}constructor(t,e,i,n){this.elements=[1,0,0,1],t!==void 0&&this.set(t,e,i,n)}identity(){return this.set(1,0,0,1),this}fromArray(t,e=0){for(let i=0;i<4;i++)this.elements[i]=t[i+e];return this}set(t,e,i,n){const s=this.elements;return s[0]=t,s[2]=e,s[1]=i,s[3]=n,this}}const qp=new R,il=new R,xa=new R,ya=new R,ou=new R,ey=new R,iy=new R;class oT{constructor(t=new R,e=new R){this.start=t,this.end=e}set(t,e){return this.start.copy(t),this.end.copy(e),this}copy(t){return this.start.copy(t.start),this.end.copy(t.end),this}getCenter(t){return t.addVectors(this.start,this.end).multiplyScalar(.5)}delta(t){return t.subVectors(this.end,this.start)}distanceSq(){return this.start.distanceToSquared(this.end)}distance(){return this.start.distanceTo(this.end)}at(t,e){return this.delta(e).multiplyScalar(t).add(this.start)}closestPointToPointParameter(t,e){qp.subVectors(t,this.start),il.subVectors(this.end,this.start);const i=il.dot(il);if(i===0)return 0;let s=il.dot(qp)/i;return e&&(s=Zt(s,0,1)),s}closestPointToPoint(t,e,i){const n=this.closestPointToPointParameter(t,e);return this.delta(i).multiplyScalar(n).add(this.start)}distanceSqToLine3(t,e=ey,i=iy){const n=10000000000000001e-32;let s,r;const o=this.start,c=t.start,l=this.end,h=t.end;xa.subVectors(l,o),ya.subVectors(h,c),ou.subVectors(o,c);const u=xa.dot(xa),d=ya.dot(ya),f=ya.dot(ou);if(u<=n&&d<=n)return e.copy(o),i.copy(c),e.sub(i),e.dot(e);if(u<=n)s=0,r=f/d,r=Zt(r,0,1);else{const p=xa.dot(ou);if(d<=n)r=0,s=Zt(-p/u,0,1);else{const v=xa.dot(ya),m=u*d-v*v;m!==0?s=Zt((v*f-p*d)/m,0,1):s=0,r=(v*s+f)/d,r<0?(r=0,s=Zt(-p/u,0,1)):r>1&&(r=1,s=Zt((v-p)/u,0,1))}}return e.copy(o).addScaledVector(xa,s),i.copy(c).addScaledVector(ya,r),e.distanceToSquared(i)}applyMatrix4(t){return this.start.applyMatrix4(t),this.end.applyMatrix4(t),this}equals(t){return t.start.equals(this.start)&&t.end.equals(this.end)}clone(){return new this.constructor().copy(this)}}function $p(a,t,e,i){const n=ny(i);switch(e){case h1:return a*t;case dh:return a*t/n.components*n.byteLength;case C0:return a*t/n.components*n.byteLength;case Yr:return a*t*2/n.components*n.byteLength;case P0:return a*t*2/n.components*n.byteLength;case u1:return a*t*3/n.components*n.byteLength;case Di:return a*t*4/n.components*n.byteLength;case L0:return a*t*4/n.components*n.byteLength;case Al:case Tl:return Math.floor((a+3)/4)*Math.floor((t+3)/4)*8;case Rl:case Dl:return Math.floor((a+3)/4)*Math.floor((t+3)/4)*16;case hd:case dd:return Math.max(a,16)*Math.max(t,8)/4;case ld:case ud:return Math.max(a,8)*Math.max(t,8)/2;case fd:case pd:case gd:case vd:return Math.floor((a+3)/4)*Math.floor((t+3)/4)*8;case md:case kl:case Md:return Math.floor((a+3)/4)*Math.floor((t+3)/4)*16;case xd:return Math.floor((a+3)/4)*Math.floor((t+3)/4)*16;case yd:return Math.floor((a+4)/5)*Math.floor((t+3)/4)*16;case Sd:return Math.floor((a+4)/5)*Math.floor((t+4)/5)*16;case _d:return Math.floor((a+5)/6)*Math.floor((t+4)/5)*16;case bd:return Math.floor((a+5)/6)*Math.floor((t+5)/6)*16;case wd:return Math.floor((a+7)/8)*Math.floor((t+4)/5)*16;case Ed:return Math.floor((a+7)/8)*Math.floor((t+5)/6)*16;case Ad:return Math.floor((a+7)/8)*Math.floor((t+7)/8)*16;case Td:return Math.floor((a+9)/10)*Math.floor((t+4)/5)*16;case Rd:return Math.floor((a+9)/10)*Math.floor((t+5)/6)*16;case Dd:return Math.floor((a+9)/10)*Math.floor((t+7)/8)*16;case Id:return Math.floor((a+9)/10)*Math.floor((t+9)/10)*16;case Cd:return Math.floor((a+11)/12)*Math.floor((t+9)/10)*16;case Pd:return Math.floor((a+11)/12)*Math.floor((t+11)/12)*16;case Ld:case Od:case Nd:return Math.ceil(a/4)*Math.ceil(t/4)*16;case Fd:case Ud:return Math.ceil(a/4)*Math.ceil(t/4)*8;case zl:case kd:return Math.ceil(a/4)*Math.ceil(t/4)*16}throw new Error(`Unable to determine texture byte length for ${e} format.`)}function ny(a){switch(a){case yn:case a1:return{byteLength:1,components:1};case rc:case o1:case $e:return{byteLength:2,components:1};case D0:case I0:return{byteLength:2,components:4};case Nn:case R0:case Ui:return{byteLength:4,components:1};case c1:case l1:return{byteLength:4,components:3}}throw new Error(`THREE.TextureUtils: Unknown texture type ${a}.`)}typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:A0}}));typeof window<"u"&&(window.__THREE__?It("WARNING: Multiple instances of Three.js being imported."):window.__THREE__=A0);/**
1420
+ }`;class fe extends zs{constructor(t){super(),this.isShaderMaterial=!0,this.type="ShaderMaterial",this.defines={},this.uniforms={},this.uniformsGroups=[],this.vertexShader=yx,this.fragmentShader=Sx,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,t!==void 0&&this.setValues(t)}copy(t){return super.copy(t),this.fragmentShader=t.fragmentShader,this.vertexShader=t.vertexShader,this.uniforms=to(t.uniforms),this.uniformsGroups=Mx(t.uniformsGroups),this.defines=Object.assign({},t.defines),this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.fog=t.fog,this.lights=t.lights,this.clipping=t.clipping,this.extensions=Object.assign({},t.extensions),this.glslVersion=t.glslVersion,this.defaultAttributeValues=Object.assign({},t.defaultAttributeValues),this.index0AttributeName=t.index0AttributeName,this.uniformsNeedUpdate=t.uniformsNeedUpdate,this}toJSON(t){const e=super.toJSON(t);e.glslVersion=this.glslVersion,e.uniforms={};for(const n in this.uniforms){const r=this.uniforms[n].value;r&&r.isTexture?e.uniforms[n]={type:"t",value:r.toJSON(t).uuid}:r&&r.isColor?e.uniforms[n]={type:"c",value:r.getHex()}:r&&r.isVector2?e.uniforms[n]={type:"v2",value:r.toArray()}:r&&r.isVector3?e.uniforms[n]={type:"v3",value:r.toArray()}:r&&r.isVector4?e.uniforms[n]={type:"v4",value:r.toArray()}:r&&r.isMatrix3?e.uniforms[n]={type:"m3",value:r.toArray()}:r&&r.isMatrix4?e.uniforms[n]={type:"m4",value:r.toArray()}:e.uniforms[n]={value:r}}Object.keys(this.defines).length>0&&(e.defines=this.defines),e.vertexShader=this.vertexShader,e.fragmentShader=this.fragmentShader,e.lights=this.lights,e.clipping=this.clipping;const i={};for(const n in this.extensions)this.extensions[n]===!0&&(i[n]=!0);return Object.keys(i).length>0&&(e.extensions=i),e}fromJSON(t,e){if(super.fromJSON(t,e),t.uniforms!==void 0)for(const i in t.uniforms){const n=t.uniforms[i];switch(this.uniforms[i]={},n.type){case"t":this.uniforms[i].value=e[n.value]||null;break;case"c":this.uniforms[i].value=new st().setHex(n.value);break;case"v2":this.uniforms[i].value=new Mt().fromArray(n.value);break;case"v3":this.uniforms[i].value=new R().fromArray(n.value);break;case"v4":this.uniforms[i].value=new ae().fromArray(n.value);break;case"m3":this.uniforms[i].value=new $t().fromArray(n.value);break;case"m4":this.uniforms[i].value=new te().fromArray(n.value);break;default:this.uniforms[i].value=n.value}}if(t.defines!==void 0&&(this.defines=t.defines),t.vertexShader!==void 0&&(this.vertexShader=t.vertexShader),t.fragmentShader!==void 0&&(this.fragmentShader=t.fragmentShader),t.glslVersion!==void 0&&(this.glslVersion=t.glslVersion),t.extensions!==void 0)for(const i in t.extensions)this.extensions[i]=t.extensions[i];return t.lights!==void 0&&(this.lights=t.lights),t.clipping!==void 0&&(this.clipping=t.clipping),this}}class E1 extends fe{constructor(t){super(t),this.isRawShaderMaterial=!0,this.type="RawShaderMaterial"}}class ar extends zs{constructor(t){super(),this.isMeshStandardMaterial=!0,this.type="MeshStandardMaterial",this.defines={STANDARD:""},this.color=new st(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 st(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=Gl,this.normalScale=new Mt(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 Us,this.envMapIntensity=1,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.defines={STANDARD:""},this.color.copy(t.color),this.roughness=t.roughness,this.metalness=t.metalness,this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.roughnessMap=t.roughnessMap,this.metalnessMap=t.metalnessMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapRotation.copy(t.envMapRotation),this.envMapIntensity=t.envMapIntensity,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.flatShading=t.flatShading,this.fog=t.fog,this}}class _x extends ar{constructor(t){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 Mt(1,1),this.clearcoatNormalMap=null,this.ior=1.5,Object.defineProperty(this,"reflectivity",{get:function(){return Zt(2.5*(this.ior-1)/(this.ior+1),0,1)},set:function(e){this.ior=(1+.4*e)/(1-.4*e)}}),this.iridescenceMap=null,this.iridescenceIOR=1.3,this.iridescenceThicknessRange=[100,400],this.iridescenceThicknessMap=null,this.sheenColor=new st(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 st(1,1,1),this.specularIntensity=1,this.specularIntensityMap=null,this.specularColor=new st(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(t)}get anisotropy(){return this._anisotropy}set anisotropy(t){this._anisotropy>0!=t>0&&this.version++,this._anisotropy=t}get clearcoat(){return this._clearcoat}set clearcoat(t){this._clearcoat>0!=t>0&&this.version++,this._clearcoat=t}get iridescence(){return this._iridescence}set iridescence(t){this._iridescence>0!=t>0&&this.version++,this._iridescence=t}get dispersion(){return this._dispersion}set dispersion(t){this._dispersion>0!=t>0&&this.version++,this._dispersion=t}get sheen(){return this._sheen}set sheen(t){this._sheen>0!=t>0&&this.version++,this._sheen=t}get transmission(){return this._transmission}set transmission(t){this._transmission>0!=t>0&&this.version++,this._transmission=t}copy(t){return super.copy(t),this.defines={STANDARD:"",PHYSICAL:""},this.anisotropy=t.anisotropy,this.anisotropyRotation=t.anisotropyRotation,this.anisotropyMap=t.anisotropyMap,this.clearcoat=t.clearcoat,this.clearcoatMap=t.clearcoatMap,this.clearcoatRoughness=t.clearcoatRoughness,this.clearcoatRoughnessMap=t.clearcoatRoughnessMap,this.clearcoatNormalMap=t.clearcoatNormalMap,this.clearcoatNormalScale.copy(t.clearcoatNormalScale),this.dispersion=t.dispersion,this.ior=t.ior,this.iridescence=t.iridescence,this.iridescenceMap=t.iridescenceMap,this.iridescenceIOR=t.iridescenceIOR,this.iridescenceThicknessRange=[...t.iridescenceThicknessRange],this.iridescenceThicknessMap=t.iridescenceThicknessMap,this.sheen=t.sheen,this.sheenColor.copy(t.sheenColor),this.sheenColorMap=t.sheenColorMap,this.sheenRoughness=t.sheenRoughness,this.sheenRoughnessMap=t.sheenRoughnessMap,this.transmission=t.transmission,this.transmissionMap=t.transmissionMap,this.thickness=t.thickness,this.thicknessMap=t.thicknessMap,this.attenuationDistance=t.attenuationDistance,this.attenuationColor.copy(t.attenuationColor),this.specularIntensity=t.specularIntensity,this.specularIntensityMap=t.specularIntensityMap,this.specularColor.copy(t.specularColor),this.specularColorMap=t.specularColorMap,this}}class qr extends zs{constructor(t){super(),this.isMeshLambertMaterial=!0,this.type="MeshLambertMaterial",this.color=new st(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new st(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=Gl,this.normalScale=new Mt(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new Us,this.combine=T0,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(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapRotation.copy(t.envMapRotation),this.combine=t.combine,this.reflectivity=t.reflectivity,this.envMapIntensity=t.envMapIntensity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.flatShading=t.flatShading,this.fog=t.fog,this}}class bx extends zs{constructor(t){super(),this.isMeshDepthMaterial=!0,this.type="MeshDepthMaterial",this.depthPacking=pM,this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.setValues(t)}copy(t){return super.copy(t),this.depthPacking=t.depthPacking,this.map=t.map,this.alphaMap=t.alphaMap,this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this}}class wx extends zs{constructor(t){super(),this.isMeshDistanceMaterial=!0,this.type="MeshDistanceMaterial",this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.setValues(t)}copy(t){return super.copy(t),this.map=t.map,this.alphaMap=t.alphaMap,this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this}}function Qc(a,t){return!a||a.constructor===t?a:typeof t.BYTES_PER_ELEMENT=="number"?new t(a):Array.prototype.slice.call(a)}function Ex(a){function t(n,s){return a[n]-a[s]}const e=a.length,i=new Array(e);for(let n=0;n!==e;++n)i[n]=n;return i.sort(t),i}function Up(a,t,e){const i=a.length,n=new a.constructor(i);for(let s=0,r=0;r!==i;++s){const o=e[s]*t;for(let c=0;c!==t;++c)n[r++]=a[o+c]}return n}function Ax(a,t,e,i){let n=1,s=a[0];for(;s!==void 0&&s[i]===void 0;)s=a[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&&(t.push(s.time),e.push(...r)),s=a[n++];while(s!==void 0);else if(r.toArray!==void 0)do r=s[i],r!==void 0&&(t.push(s.time),r.toArray(e,e.length)),s=a[n++];while(s!==void 0);else do r=s[i],r!==void 0&&(t.push(s.time),e.push(r)),s=a[n++];while(s!==void 0)}class pc{constructor(t,e,i,n){this.parameterPositions=t,this._cachedIndex=0,this.resultBuffer=n!==void 0?n:new e.constructor(i),this.sampleValues=e,this.valueSize=i,this.settings=null,this.DefaultSettings_={}}evaluate(t){const e=this.parameterPositions;let i=this._cachedIndex,n=e[i],s=e[i-1];t:{e:{let r;i:{n:if(!(t<n)){for(let o=i+2;;){if(n===void 0){if(t<s)break n;return i=e.length,this._cachedIndex=i,this.copySampleValue_(i-1)}if(i===o)break;if(s=n,n=e[++i],t<n)break e}r=e.length;break i}if(!(t>=s)){const o=e[1];t<o&&(i=2,s=o);for(let c=i-2;;){if(s===void 0)return this._cachedIndex=0,this.copySampleValue_(0);if(i===c)break;if(n=s,s=e[--i-1],t>=s)break e}r=i,i=0;break i}break t}for(;i<r;){const o=i+r>>>1;t<e[o]?r=o:i=o+1}if(n=e[i],s=e[i-1],s===void 0)return this._cachedIndex=0,this.copySampleValue_(0);if(n===void 0)return i=e.length,this._cachedIndex=i,this.copySampleValue_(i-1)}this._cachedIndex=i,this.intervalChanged_(i,s,n)}return this.interpolate_(i,s,t,n)}getSettings_(){return this.settings||this.DefaultSettings_}copySampleValue_(t){const e=this.resultBuffer,i=this.sampleValues,n=this.valueSize,s=t*n;for(let r=0;r!==n;++r)e[r]=i[s+r];return e}interpolate_(){throw new Error("THREE.Interpolant: Call to abstract method.")}intervalChanged_(){}}class Tx extends pc{constructor(t,e,i,n){super(t,e,i,n),this._weightPrev=-0,this._offsetPrev=-0,this._weightNext=-0,this._offsetNext=-0,this.DefaultSettings_={endingStart:Da,endingEnd:Da}}intervalChanged_(t,e,i){const n=this.parameterPositions;let s=t-2,r=t+1,o=n[s],c=n[r];if(o===void 0)switch(this.getSettings_().endingStart){case Ia:s=t,o=2*e-i;break;case Hl:s=n.length-2,o=e+n[s]-n[s+1];break;default:s=t,o=i}if(c===void 0)switch(this.getSettings_().endingEnd){case Ia:r=t,c=2*i-e;break;case Hl:r=1,c=i+n[1]-n[0];break;default:r=t-1,c=e}const l=(i-e)*.5,h=this.valueSize;this._weightPrev=l/(e-o),this._weightNext=l/(c-i),this._offsetPrev=s*h,this._offsetNext=r*h}interpolate_(t,e,i,n){const s=this.resultBuffer,r=this.sampleValues,o=this.valueSize,c=t*o,l=c-o,h=this._offsetPrev,u=this._offsetNext,d=this._weightPrev,f=this._weightNext,p=(i-e)/(n-e),v=p*p,m=v*p,g=-d*m+2*d*v-d*p,S=(1+d)*m+(-1.5-2*d)*v+(-.5+d)*p+1,x=(-1-f)*m+(1.5+f)*v+.5*p,M=f*m-f*v;for(let b=0;b!==o;++b)s[b]=g*r[h+b]+S*r[l+b]+x*r[c+b]+M*r[u+b];return s}}class A1 extends pc{constructor(t,e,i,n){super(t,e,i,n)}interpolate_(t,e,i,n){const s=this.resultBuffer,r=this.sampleValues,o=this.valueSize,c=t*o,l=c-o,h=(i-e)/(n-e),u=1-h;for(let d=0;d!==o;++d)s[d]=r[l+d]*u+r[c+d]*h;return s}}class Rx extends pc{constructor(t,e,i,n){super(t,e,i,n)}interpolate_(t){return this.copySampleValue_(t-1)}}class Dx extends pc{interpolate_(t,e,i,n){const s=this.resultBuffer,r=this.sampleValues,o=this.valueSize,c=t*o,l=c-o,h=this.inTangents,u=this.outTangents;if(!h||!u){const p=(i-e)/(n-e),v=1-p;for(let m=0;m!==o;++m)s[m]=r[l+m]*v+r[c+m]*p;return s}const d=o*2,f=t-1;for(let p=0;p!==o;++p){const v=r[l+p],m=r[c+p],g=f*d+p*2,S=u[g],x=u[g+1],M=t*d+p*2,b=h[M],w=h[M+1];let T=(i-e)/(n-e),y,A,C,I,P;for(let V=0;V<8;V++){y=T*T,A=y*T,C=1-T,I=C*C,P=I*C;const L=P*e+3*I*T*S+3*C*y*b+A*n-i;if(Math.abs(L)<1e-10)break;const B=3*I*(S-e)+6*C*T*(b-S)+3*y*(n-b);if(Math.abs(B)<1e-10)break;T=T-L/B,T=Math.max(0,Math.min(1,T))}s[p]=P*v+3*I*T*x+3*C*y*w+A*m}return s}}class Jn{constructor(t,e,i,n){if(t===void 0)throw new Error("THREE.KeyframeTrack: track name is undefined");if(e===void 0||e.length===0)throw new Error("THREE.KeyframeTrack: no keyframes in track named "+t);this.name=t,this.times=Qc(e,this.TimeBufferType),this.values=Qc(i,this.ValueBufferType),this.setInterpolation(n||this.DefaultInterpolation)}static toJSON(t){const e=t.constructor;let i;if(e.toJSON!==this.toJSON)i=e.toJSON(t);else{i={name:t.name,times:Qc(t.times,Array),values:Qc(t.values,Array)};const n=t.getInterpolation();n!==t.DefaultInterpolation&&(i.interpolation=n)}return i.type=t.ValueTypeName,i}InterpolantFactoryMethodDiscrete(t){return new Rx(this.times,this.values,this.getValueSize(),t)}InterpolantFactoryMethodLinear(t){return new A1(this.times,this.values,this.getValueSize(),t)}InterpolantFactoryMethodSmooth(t){return new Tx(this.times,this.values,this.getValueSize(),t)}InterpolantFactoryMethodBezier(t){const e=new Dx(this.times,this.values,this.getValueSize(),t);return this.settings&&(e.inTangents=this.settings.inTangents,e.outTangents=this.settings.outTangents),e}setInterpolation(t){let e;switch(t){case Bl:e=this.InterpolantFactoryMethodDiscrete;break;case zd:e=this.InterpolantFactoryMethodLinear;break;case Ph:e=this.InterpolantFactoryMethodSmooth;break;case ep:e=this.InterpolantFactoryMethodBezier;break}if(e===void 0){const i="unsupported interpolation for "+this.ValueTypeName+" keyframe track named "+this.name;if(this.createInterpolant===void 0)if(t!==this.DefaultInterpolation)this.setInterpolation(this.DefaultInterpolation);else throw new Error(i);return It("KeyframeTrack:",i),this}return this.createInterpolant=e,this}getInterpolation(){switch(this.createInterpolant){case this.InterpolantFactoryMethodDiscrete:return Bl;case this.InterpolantFactoryMethodLinear:return zd;case this.InterpolantFactoryMethodSmooth:return Ph;case this.InterpolantFactoryMethodBezier:return ep}}getValueSize(){return this.values.length/this.times.length}shift(t){if(t!==0){const e=this.times;for(let i=0,n=e.length;i!==n;++i)e[i]+=t}return this}scale(t){if(t!==1){const e=this.times;for(let i=0,n=e.length;i!==n;++i)e[i]*=t}return this}trim(t,e){const i=this.times,n=i.length;let s=0,r=n-1;for(;s!==n&&i[s]<t;)++s;for(;r!==-1&&i[r]>e;)--r;if(++r,s!==0||r!==n){s>=r&&(r=Math.max(r,1),s=r-1);const o=this.getValueSize();this.times=i.slice(s,r),this.values=this.values.slice(s*o,r*o)}return this}validate(){let t=!0;const e=this.getValueSize();e-Math.floor(e)!==0&&(Wt("KeyframeTrack: Invalid value size in track.",this),t=!1);const i=this.times,n=this.values,s=i.length;s===0&&(Wt("KeyframeTrack: Track is empty.",this),t=!1);let r=null;for(let o=0;o!==s;o++){const c=i[o];if(typeof c=="number"&&isNaN(c)){Wt("KeyframeTrack: Time is not a valid number.",this,o,c),t=!1;break}if(r!==null&&r>c){Wt("KeyframeTrack: Out of order keys.",this,o,c,r),t=!1;break}r=c}if(n!==void 0&&bM(n))for(let o=0,c=n.length;o!==c;++o){const l=n[o];if(isNaN(l)){Wt("KeyframeTrack: Value is not a valid number.",this,o,l),t=!1;break}}return t}optimize(){const t=this.times.slice(),e=this.values.slice(),i=this.getValueSize(),n=this.getInterpolation()===Ph,s=t.length-1;let r=1;for(let o=1;o<s;++o){let c=!1;const l=t[o],h=t[o+1];if(l!==h&&(o!==1||l!==t[0]))if(n)c=!0;else{const u=o*i,d=u-i,f=u+i;for(let p=0;p!==i;++p){const v=e[u+p];if(v!==e[d+p]||v!==e[f+p]){c=!0;break}}}if(c){if(o!==r){t[r]=t[o];const u=o*i,d=r*i;for(let f=0;f!==i;++f)e[d+f]=e[u+f]}++r}}if(s>0){t[r]=t[s];for(let o=s*i,c=r*i,l=0;l!==i;++l)e[c+l]=e[o+l];++r}return r!==t.length?(this.times=t.slice(0,r),this.values=e.slice(0,r*i)):(this.times=t,this.values=e),this}clone(){const t=this.times.slice(),e=this.values.slice(),i=this.constructor,n=new i(this.name,t,e);return n.createInterpolant=this.createInterpolant,n}}Jn.prototype.ValueTypeName="";Jn.prototype.TimeBufferType=Float32Array;Jn.prototype.ValueBufferType=Float32Array;Jn.prototype.DefaultInterpolation=zd;class no extends Jn{constructor(t,e,i){super(t,e,i)}}no.prototype.ValueTypeName="bool";no.prototype.ValueBufferType=Array;no.prototype.DefaultInterpolation=Bl;no.prototype.InterpolantFactoryMethodLinear=void 0;no.prototype.InterpolantFactoryMethodSmooth=void 0;class T1 extends Jn{constructor(t,e,i,n){super(t,e,i,n)}}T1.prototype.ValueTypeName="color";class X0 extends Jn{constructor(t,e,i,n){super(t,e,i,n)}}X0.prototype.ValueTypeName="number";class Ix extends pc{constructor(t,e,i,n){super(t,e,i,n)}interpolate_(t,e,i,n){const s=this.resultBuffer,r=this.sampleValues,o=this.valueSize,c=(i-e)/(n-e);let l=t*o;for(let h=l+o;l!==h;l+=4)on.slerpFlat(s,0,r,l-o,r,l,c);return s}}class Y0 extends Jn{constructor(t,e,i,n){super(t,e,i,n)}InterpolantFactoryMethodLinear(t){return new Ix(this.times,this.values,this.getValueSize(),t)}}Y0.prototype.ValueTypeName="quaternion";Y0.prototype.InterpolantFactoryMethodSmooth=void 0;class so extends Jn{constructor(t,e,i){super(t,e,i)}}so.prototype.ValueTypeName="string";so.prototype.ValueBufferType=Array;so.prototype.DefaultInterpolation=Bl;so.prototype.InterpolantFactoryMethodLinear=void 0;so.prototype.InterpolantFactoryMethodSmooth=void 0;class R1 extends Jn{constructor(t,e,i,n){super(t,e,i,n)}}R1.prototype.ValueTypeName="vector";class kp{constructor(t="",e=-1,i=[],n=O0){this.name=t,this.tracks=i,this.duration=e,this.blendMode=n,this.uuid=Kn(),this.userData={},this.duration<0&&this.resetDuration()}static parse(t){const e=[],i=t.tracks,n=1/(t.fps||1);for(let r=0,o=i.length;r!==o;++r)e.push(Px(i[r]).scale(n));const s=new this(t.name,t.duration,e,t.blendMode);return s.uuid=t.uuid,s.userData=JSON.parse(t.userData||"{}"),s}static toJSON(t){const e=[],i=t.tracks,n={name:t.name,duration:t.duration,tracks:e,uuid:t.uuid,blendMode:t.blendMode,userData:JSON.stringify(t.userData)};for(let s=0,r=i.length;s!==r;++s)e.push(Jn.toJSON(i[s]));return n}static CreateFromMorphTargetSequence(t,e,i,n){const s=e.length,r=[];for(let o=0;o<s;o++){let c=[],l=[];c.push((o+s-1)%s,o,(o+1)%s),l.push(0,1,0);const h=Ex(c);c=Up(c,1,h),l=Up(l,1,h),!n&&c[0]===0&&(c.push(s),l.push(l[0])),r.push(new X0(".morphTargetInfluences["+e[o].name+"]",c,l).scale(1/i))}return new this(t,-1,r)}static findByName(t,e){let i=t;if(!Array.isArray(t)){const n=t;i=n.geometry&&n.geometry.animations||n.animations}for(let n=0;n<i.length;n++)if(i[n].name===e)return i[n];return null}static CreateClipsFromMorphTargetSequences(t,e,i){const n={},s=/^([\w-]*?)([\d]+)$/;for(let o=0,c=t.length;o<c;o++){const l=t[o],h=l.name.match(s);if(h&&h.length>1){const u=h[1];let d=n[u];d||(n[u]=d=[]),d.push(l)}}const r=[];for(const o in n)r.push(this.CreateFromMorphTargetSequence(o,n[o],e,i));return r}resetDuration(){const t=this.tracks;let e=0;for(let i=0,n=t.length;i!==n;++i){const s=this.tracks[i];e=Math.max(e,s.times[s.times.length-1])}return this.duration=e,this}trim(){for(let t=0;t<this.tracks.length;t++)this.tracks[t].trim(0,this.duration);return this}validate(){let t=!0;for(let e=0;e<this.tracks.length;e++)t=t&&this.tracks[e].validate();return t}optimize(){for(let t=0;t<this.tracks.length;t++)this.tracks[t].optimize();return this}clone(){const t=[];for(let i=0;i<this.tracks.length;i++)t.push(this.tracks[i].clone());const e=new this.constructor(this.name,this.duration,t,this.blendMode);return e.userData=JSON.parse(JSON.stringify(this.userData)),e}toJSON(){return this.constructor.toJSON(this)}}function Cx(a){switch(a.toLowerCase()){case"scalar":case"double":case"float":case"number":case"integer":return X0;case"vector":case"vector2":case"vector3":case"vector4":return R1;case"color":return T1;case"quaternion":return Y0;case"bool":case"boolean":return no;case"string":return so}throw new Error("THREE.KeyframeTrack: Unsupported typeName: "+a)}function Px(a){if(a.type===void 0)throw new Error("THREE.KeyframeTrack: track type undefined, can not parse");const t=Cx(a.type);if(a.times===void 0){const e=[],i=[];Ax(a.keys,e,i,"value"),a.times=e,a.values=i}return t.parse!==void 0?t.parse(a):new t(a.name,a.times,a.values,a.interpolation)}const Os={enabled:!1,files:{},add:function(a,t){this.enabled!==!1&&(zp(a)||(this.files[a]=t))},get:function(a){if(this.enabled!==!1&&!zp(a))return this.files[a]},remove:function(a){delete this.files[a]},clear:function(){this.files={}}};function zp(a){try{const t=a.slice(a.indexOf(":")+1);return new URL(t).protocol==="blob:"}catch{return!1}}class Lx{constructor(t,e,i){const n=this;let s=!1,r=0,o=0,c;const l=[];this.onStart=void 0,this.onLoad=t,this.onProgress=e,this.onError=i,this._abortController=null,this.itemStart=function(h){o++,s===!1&&n.onStart!==void 0&&n.onStart(h,r,o),s=!0},this.itemEnd=function(h){r++,n.onProgress!==void 0&&n.onProgress(h,r,o),r===o&&(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"),c?c(h):h},this.setURLModifier=function(h){return c=h,this},this.addHandler=function(h,u){return l.push(h,u),this},this.removeHandler=function(h){const u=l.indexOf(h);return u!==-1&&l.splice(u,2),this},this.getHandler=function(h){for(let u=0,d=l.length;u<d;u+=2){const f=l[u],p=l[u+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 Ox=new Lx;class mc{constructor(t){this.manager=t!==void 0?t:Ox,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(t,e){const i=this;return new Promise(function(n,s){i.load(t,n,e,s)})}parse(){}setCrossOrigin(t){return this.crossOrigin=t,this}setWithCredentials(t){return this.withCredentials=t,this}setPath(t){return this.path=t,this}setResourcePath(t){return this.resourcePath=t,this}setRequestHeader(t){return this.requestHeader=t,this}abort(){return this}}mc.DEFAULT_MATERIAL_NAME="__DEFAULT";const As={};class Nx extends Error{constructor(t,e){super(t),this.response=e}}class tT extends mc{constructor(t){super(t),this.mimeType="",this.responseType="",this._abortController=new AbortController}load(t,e,i,n){t===void 0&&(t=""),this.path!==void 0&&(t=this.path+t),t=this.manager.resolveURL(t);const s=Os.get(`file:${t}`);if(s!==void 0){this.manager.itemStart(t),setTimeout(()=>{e&&e(s),this.manager.itemEnd(t)},0);return}if(As[t]!==void 0){As[t].push({onLoad:e,onProgress:i,onError:n});return}As[t]=[],As[t].push({onLoad:e,onProgress:i,onError:n});const r=new Request(t,{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}),o=this.mimeType,c=this.responseType;fetch(r).then(l=>{if(l.status===200||l.status===0){if(l.status===0&&It("FileLoader: HTTP Status 0 received."),typeof ReadableStream>"u"||l.body===void 0||l.body.getReader===void 0)return l;const h=As[t],u=l.body.getReader(),d=l.headers.get("X-File-Size")||l.headers.get("Content-Length"),f=d?parseInt(d):0,p=f!==0;let v=0;const m=new ReadableStream({start(g){S();function S(){u.read().then(({done:x,value:M})=>{if(x)g.close();else{v+=M.byteLength;const b=new ProgressEvent("progress",{lengthComputable:p,loaded:v,total:f});for(let w=0,T=h.length;w<T;w++){const y=h[w];y.onProgress&&y.onProgress(b)}g.enqueue(M),S()}},x=>{g.error(x)})}}});return new Response(m)}else throw new Nx(`fetch for "${l.url}" responded with ${l.status}: ${l.statusText}`,l)}).then(l=>{switch(c){case"arraybuffer":return l.arrayBuffer();case"blob":return l.blob();case"document":return l.text().then(h=>new DOMParser().parseFromString(h,o));case"json":return l.json();default:if(o==="")return l.text();{const u=/charset="?([^;"\s]*)"?/i.exec(o),d=u&&u[1]?u[1].toLowerCase():void 0,f=new TextDecoder(d);return l.arrayBuffer().then(p=>f.decode(p))}}}).then(l=>{Os.add(`file:${t}`,l);const h=As[t];delete As[t];for(let u=0,d=h.length;u<d;u++){const f=h[u];f.onLoad&&f.onLoad(l)}}).catch(l=>{const h=As[t];if(h===void 0)throw this.manager.itemError(t),l;delete As[t];for(let u=0,d=h.length;u<d;u++){const f=h[u];f.onError&&f.onError(l)}this.manager.itemError(t)}).finally(()=>{this.manager.itemEnd(t)}),this.manager.itemStart(t)}setResponseType(t){return this.responseType=t,this}setMimeType(t){return this.mimeType=t,this}abort(){return this._abortController.abort(),this._abortController=new AbortController,this}}const ga=new WeakMap;class Fx extends mc{constructor(t){super(t)}load(t,e,i,n){this.path!==void 0&&(t=this.path+t),t=this.manager.resolveURL(t);const s=this,r=Os.get(`image:${t}`);if(r!==void 0){if(r.complete===!0)s.manager.itemStart(t),setTimeout(function(){e&&e(r),s.manager.itemEnd(t)},0);else{let u=ga.get(r);u===void 0&&(u=[],ga.set(r,u)),u.push({onLoad:e,onError:n})}return r}const o=cc("img");function c(){h(),e&&e(this);const u=ga.get(this)||[];for(let d=0;d<u.length;d++){const f=u[d];f.onLoad&&f.onLoad(this)}ga.delete(this),s.manager.itemEnd(t)}function l(u){h(),n&&n(u),Os.remove(`image:${t}`);const d=ga.get(this)||[];for(let f=0;f<d.length;f++){const p=d[f];p.onError&&p.onError(u)}ga.delete(this),s.manager.itemError(t),s.manager.itemEnd(t)}function h(){o.removeEventListener("load",c,!1),o.removeEventListener("error",l,!1)}return o.addEventListener("load",c,!1),o.addEventListener("error",l,!1),t.slice(0,5)!=="data:"&&this.crossOrigin!==void 0&&(o.crossOrigin=this.crossOrigin),Os.add(`image:${t}`,o),s.manager.itemStart(t),o.src=t,o}}class eT extends mc{constructor(t){super(t)}load(t,e,i,n){const s=new Ei,r=new Fx(this.manager);return r.setCrossOrigin(this.crossOrigin),r.setPath(this.path),r.load(t,function(o){s.image=o,s.needsUpdate=!0,e!==void 0&&e(s)},i,n),s}}class ph extends Ge{constructor(t,e=1){super(),this.isLight=!0,this.type="Light",this.color=new st(t),this.intensity=e}dispose(){this.dispatchEvent({type:"dispose"})}copy(t,e){return super.copy(t,e),this.color.copy(t.color),this.intensity=t.intensity,this}toJSON(t){const e=super.toJSON(t);return e.object.color=this.color.getHex(),e.object.intensity=this.intensity,e}}class Ux extends ph{constructor(t,e,i){super(t,i),this.isHemisphereLight=!0,this.type="HemisphereLight",this.position.copy(Ge.DEFAULT_UP),this.updateMatrix(),this.groundColor=new st(e)}copy(t,e){return super.copy(t,e),this.groundColor.copy(t.groundColor),this}toJSON(t){const e=super.toJSON(t);return e.object.groundColor=this.groundColor.getHex(),e}}const ru=new te,Bp=new R,Hp=new R;class q0{constructor(t){this.camera=t,this.intensity=1,this.bias=0,this.biasNode=null,this.normalBias=0,this.radius=1,this.blurSamples=8,this.mapSize=new Mt(512,512),this.mapType=yn,this.map=null,this.mapPass=null,this.matrix=new te,this.autoUpdate=!0,this.needsUpdate=!1,this._frustum=new G0,this._frameExtents=new Mt(1,1),this._viewportCount=1,this._viewports=[new ae(0,0,1,1)]}getViewportCount(){return this._viewportCount}getFrustum(){return this._frustum}updateMatrices(t){const e=this.camera,i=this.matrix;Bp.setFromMatrixPosition(t.matrixWorld),e.position.copy(Bp),Hp.setFromMatrixPosition(t.target.matrixWorld),e.lookAt(Hp),e.updateMatrixWorld(),ru.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),this._frustum.setFromProjectionMatrix(ru,e.coordinateSystem,e.reversedDepth),e.coordinateSystem===oc||e.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(ru)}getViewport(t){return this._viewports[t]}getFrameExtents(){return this._frameExtents}dispose(){this.map&&this.map.dispose(),this.mapPass&&this.mapPass.dispose()}copy(t){return this.camera=t.camera.clone(),this.intensity=t.intensity,this.bias=t.bias,this.radius=t.radius,this.autoUpdate=t.autoUpdate,this.needsUpdate=t.needsUpdate,this.normalBias=t.normalBias,this.blurSamples=t.blurSamples,this.mapSize.copy(t.mapSize),this.biasNode=t.biasNode,this}clone(){return new this.constructor().copy(this)}toJSON(){const t={};return this.intensity!==1&&(t.intensity=this.intensity),this.bias!==0&&(t.bias=this.bias),this.normalBias!==0&&(t.normalBias=this.normalBias),this.radius!==1&&(t.radius=this.radius),(this.mapSize.x!==512||this.mapSize.y!==512)&&(t.mapSize=this.mapSize.toArray()),t.camera=this.camera.toJSON(!1).object,delete t.camera.matrix,t}}const tl=new R,el=new on,is=new R;class D1 extends Ge{constructor(){super(),this.isCamera=!0,this.type="Camera",this.matrixWorldInverse=new te,this.projectionMatrix=new te,this.projectionMatrixInverse=new te,this.coordinateSystem=ms,this._reversedDepth=!1}get reversedDepth(){return this._reversedDepth}copy(t,e){return super.copy(t,e),this.matrixWorldInverse.copy(t.matrixWorldInverse),this.projectionMatrix.copy(t.projectionMatrix),this.projectionMatrixInverse.copy(t.projectionMatrixInverse),this.coordinateSystem=t.coordinateSystem,this}getWorldDirection(t){return super.getWorldDirection(t).negate()}updateMatrixWorld(t){super.updateMatrixWorld(t),this.matrixWorld.decompose(tl,el,is),is.x===1&&is.y===1&&is.z===1?this.matrixWorldInverse.copy(this.matrixWorld).invert():this.matrixWorldInverse.compose(tl,el,is.set(1,1,1)).invert()}updateWorldMatrix(t,e,i=!1){super.updateWorldMatrix(t,e,i),this.matrixWorld.decompose(tl,el,is),is.x===1&&is.y===1&&is.z===1?this.matrixWorldInverse.copy(this.matrixWorld).invert():this.matrixWorldInverse.compose(tl,el,is.set(1,1,1)).invert()}clone(){return new this.constructor().copy(this)}}const Ks=new R,Gp=new Mt,Vp=new Mt;class rn extends D1{constructor(t=50,e=1,i=.1,n=2e3){super(),this.isPerspectiveCamera=!0,this.type="PerspectiveCamera",this.fov=t,this.zoom=1,this.near=i,this.far=n,this.focus=10,this.aspect=e,this.view=null,this.filmGauge=35,this.filmOffset=0,this.updateProjectionMatrix()}copy(t,e){return super.copy(t,e),this.fov=t.fov,this.zoom=t.zoom,this.near=t.near,this.far=t.far,this.focus=t.focus,this.aspect=t.aspect,this.view=t.view===null?null:Object.assign({},t.view),this.filmGauge=t.filmGauge,this.filmOffset=t.filmOffset,this}setFocalLength(t){const e=.5*this.getFilmHeight()/t;this.fov=Qa*2*Math.atan(e),this.updateProjectionMatrix()}getFocalLength(){const t=Math.tan(Go*.5*this.fov);return .5*this.getFilmHeight()/t}getEffectiveFOV(){return Qa*2*Math.atan(Math.tan(Go*.5*this.fov)/this.zoom)}getFilmWidth(){return this.filmGauge*Math.min(this.aspect,1)}getFilmHeight(){return this.filmGauge/Math.max(this.aspect,1)}getViewBounds(t,e,i){Ks.set(-1,-1,.5).applyMatrix4(this.projectionMatrixInverse),e.set(Ks.x,Ks.y).multiplyScalar(-t/Ks.z),Ks.set(1,1,.5).applyMatrix4(this.projectionMatrixInverse),i.set(Ks.x,Ks.y).multiplyScalar(-t/Ks.z)}getViewSize(t,e){return this.getViewBounds(t,Gp,Vp),e.subVectors(Vp,Gp)}setViewOffset(t,e,i,n,s,r){this.aspect=t/e,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=t,this.view.fullHeight=e,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 t=this.near;let e=t*Math.tan(Go*.5*this.fov)/this.zoom,i=2*e,n=this.aspect*i,s=-.5*n;const r=this.view;if(this.view!==null&&this.view.enabled){const c=r.fullWidth,l=r.fullHeight;s+=r.offsetX*n/c,e-=r.offsetY*i/l,n*=r.width/c,i*=r.height/l}const o=this.filmOffset;o!==0&&(s+=t*o/this.getFilmWidth()),this.projectionMatrix.makePerspective(s,s+n,e,e-i,t,this.far,this.coordinateSystem,this.reversedDepth),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(t){const e=super.toJSON(t);return e.object.fov=this.fov,e.object.zoom=this.zoom,e.object.near=this.near,e.object.far=this.far,e.object.focus=this.focus,e.object.aspect=this.aspect,this.view!==null&&(e.object.view=Object.assign({},this.view)),e.object.filmGauge=this.filmGauge,e.object.filmOffset=this.filmOffset,e}}class kx extends q0{constructor(){super(new rn(50,1,.5,500)),this.isSpotLightShadow=!0,this.focus=1,this.aspect=1}updateMatrices(t){const e=this.camera,i=Qa*2*t.angle*this.focus,n=this.mapSize.width/this.mapSize.height*this.aspect,s=t.distance||e.far;(i!==e.fov||n!==e.aspect||s!==e.far)&&(e.fov=i,e.aspect=n,e.far=s,e.updateProjectionMatrix()),super.updateMatrices(t)}copy(t){return super.copy(t),this.focus=t.focus,this}}class iT extends ph{constructor(t,e,i=0,n=Math.PI/3,s=0,r=2){super(t,e),this.isSpotLight=!0,this.type="SpotLight",this.position.copy(Ge.DEFAULT_UP),this.updateMatrix(),this.target=new Ge,this.distance=i,this.angle=n,this.penumbra=s,this.decay=r,this.map=null,this.shadow=new kx}get power(){return this.intensity*Math.PI}set power(t){this.intensity=t/Math.PI}dispose(){super.dispose(),this.shadow.dispose()}copy(t,e){return super.copy(t,e),this.distance=t.distance,this.angle=t.angle,this.penumbra=t.penumbra,this.decay=t.decay,this.target=t.target.clone(),this.map=t.map,this.shadow=t.shadow.clone(),this}toJSON(t){const e=super.toJSON(t);return e.object.distance=this.distance,e.object.angle=this.angle,e.object.decay=this.decay,e.object.penumbra=this.penumbra,e.object.target=this.target.uuid,this.map&&this.map.isTexture&&(e.object.map=this.map.toJSON(t).uuid),e.object.shadow=this.shadow.toJSON(),e}}class zx extends q0{constructor(){super(new rn(90,1,.5,500)),this.isPointLightShadow=!0}}class I1 extends ph{constructor(t,e,i=0,n=2){super(t,e),this.isPointLight=!0,this.type="PointLight",this.distance=i,this.decay=n,this.shadow=new zx}get power(){return this.intensity*4*Math.PI}set power(t){this.intensity=t/(4*Math.PI)}dispose(){super.dispose(),this.shadow.dispose()}copy(t,e){return super.copy(t,e),this.distance=t.distance,this.decay=t.decay,this.shadow=t.shadow.clone(),this}toJSON(t){const e=super.toJSON(t);return e.object.distance=this.distance,e.object.decay=this.decay,e.object.shadow=this.shadow.toJSON(),e}}class Zn extends D1{constructor(t=-1,e=1,i=1,n=-1,s=.1,r=2e3){super(),this.isOrthographicCamera=!0,this.type="OrthographicCamera",this.zoom=1,this.view=null,this.left=t,this.right=e,this.top=i,this.bottom=n,this.near=s,this.far=r,this.updateProjectionMatrix()}copy(t,e){return super.copy(t,e),this.left=t.left,this.right=t.right,this.top=t.top,this.bottom=t.bottom,this.near=t.near,this.far=t.far,this.zoom=t.zoom,this.view=t.view===null?null:Object.assign({},t.view),this}setViewOffset(t,e,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=t,this.view.fullHeight=e,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 t=(this.right-this.left)/(2*this.zoom),e=(this.top-this.bottom)/(2*this.zoom),i=(this.right+this.left)/2,n=(this.top+this.bottom)/2;let s=i-t,r=i+t,o=n+e,c=n-e;if(this.view!==null&&this.view.enabled){const l=(this.right-this.left)/this.view.fullWidth/this.zoom,h=(this.top-this.bottom)/this.view.fullHeight/this.zoom;s+=l*this.view.offsetX,r=s+l*this.view.width,o-=h*this.view.offsetY,c=o-h*this.view.height}this.projectionMatrix.makeOrthographic(s,r,o,c,this.near,this.far,this.coordinateSystem,this.reversedDepth),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(t){const e=super.toJSON(t);return e.object.zoom=this.zoom,e.object.left=this.left,e.object.right=this.right,e.object.top=this.top,e.object.bottom=this.bottom,e.object.near=this.near,e.object.far=this.far,this.view!==null&&(e.object.view=Object.assign({},this.view)),e}}class Bx extends q0{constructor(){super(new Zn(-5,5,5,-5,.5,500)),this.isDirectionalLightShadow=!0}}class Wp extends ph{constructor(t,e){super(t,e),this.isDirectionalLight=!0,this.type="DirectionalLight",this.position.copy(Ge.DEFAULT_UP),this.updateMatrix(),this.target=new Ge,this.shadow=new Bx}dispose(){super.dispose(),this.shadow.dispose()}copy(t){return super.copy(t),this.target=t.target.clone(),this.shadow=t.shadow.clone(),this}toJSON(t){const e=super.toJSON(t);return e.object.shadow=this.shadow.toJSON(),e.object.target=this.target.uuid,e}}class nT{static extractUrlBase(t){const e=t.lastIndexOf("/");return e===-1?"./":t.slice(0,e+1)}static resolveURL(t,e){return typeof t!="string"||t===""?"":(/^https?:\/\//i.test(e)&&/^\//.test(t)&&(e=e.replace(/(^https?:\/\/[^\/]+).*/i,"$1")),/^(https?:)?\/\//i.test(t)||/^data:.*,.*$/i.test(t)||/^blob:.*$/i.test(t)?t:e+t)}}class sT extends se{constructor(){super(),this.isInstancedBufferGeometry=!0,this.type="InstancedBufferGeometry",this.instanceCount=1/0}copy(t){return super.copy(t),this.instanceCount=t.instanceCount,this}toJSON(){const t=super.toJSON();return t.instanceCount=this.instanceCount,t.isInstancedBufferGeometry=!0,t}}const au=new WeakMap;class rT extends mc{constructor(t){super(t),this.isImageBitmapLoader=!0,typeof createImageBitmap>"u"&&It("ImageBitmapLoader: createImageBitmap() not supported."),typeof fetch>"u"&&It("ImageBitmapLoader: fetch() not supported."),this.options={premultiplyAlpha:"none"},this._abortController=new AbortController}setOptions(t){return this.options=t,this}load(t,e,i,n){t===void 0&&(t=""),this.path!==void 0&&(t=this.path+t),t=this.manager.resolveURL(t);const s=this,r=Os.get(`image-bitmap:${t}`);if(r!==void 0){if(s.manager.itemStart(t),r.then){r.then(l=>{au.has(r)===!0?(n&&n(au.get(r)),s.manager.itemError(t),s.manager.itemEnd(t)):(e&&e(l),s.manager.itemEnd(t))});return}setTimeout(function(){e&&e(r),s.manager.itemEnd(t)},0);return}const o={};o.credentials=this.crossOrigin==="anonymous"?"same-origin":"include",o.headers=this.requestHeader,o.signal=typeof AbortSignal.any=="function"?AbortSignal.any([this._abortController.signal,this.manager.abortController.signal]):this._abortController.signal;const c=fetch(t,o).then(function(l){return l.blob()}).then(function(l){return createImageBitmap(l,Object.assign(s.options,{colorSpaceConversion:"none"}))}).then(function(l){Os.add(`image-bitmap:${t}`,l),e&&e(l),s.manager.itemEnd(t)}).catch(function(l){n&&n(l),au.set(c,l),Os.remove(`image-bitmap:${t}`),s.manager.itemError(t),s.manager.itemEnd(t)});Os.add(`image-bitmap:${t}`,c),s.manager.itemStart(t)}abort(){return this._abortController.abort(),this._abortController=new AbortController,this}}const va=-90,Ma=1;class $0 extends Ge{constructor(t,e,i){super(),this.type="CubeCamera",this.renderTarget=i,this.coordinateSystem=null,this.activeMipmapLevel=0;const n=new rn(va,Ma,t,e);n.layers=this.layers,this.add(n);const s=new rn(va,Ma,t,e);s.layers=this.layers,this.add(s);const r=new rn(va,Ma,t,e);r.layers=this.layers,this.add(r);const o=new rn(va,Ma,t,e);o.layers=this.layers,this.add(o);const c=new rn(va,Ma,t,e);c.layers=this.layers,this.add(c);const l=new rn(va,Ma,t,e);l.layers=this.layers,this.add(l)}updateCoordinateSystem(){const t=this.coordinateSystem,e=this.children.concat(),[i,n,s,r,o,c]=e;for(const l of e)this.remove(l);if(t===ms)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),o.up.set(0,1,0),o.lookAt(0,0,1),c.up.set(0,1,0),c.lookAt(0,0,-1);else if(t===oc)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),o.up.set(0,-1,0),o.lookAt(0,0,1),c.up.set(0,-1,0),c.lookAt(0,0,-1);else throw new Error("THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: "+t);for(const l of e)this.add(l),l.updateMatrixWorld()}update(t,e){this.parent===null&&this.updateMatrixWorld();const{renderTarget:i,activeMipmapLevel:n}=this;this.coordinateSystem!==t.coordinateSystem&&(this.coordinateSystem=t.coordinateSystem,this.updateCoordinateSystem());const[s,r,o,c,l,h]=this.children,u=t.getRenderTarget(),d=t.getActiveCubeFace(),f=t.getActiveMipmapLevel(),p=t.xr.enabled;t.xr.enabled=!1;const v=i.texture.generateMipmaps;i.texture.generateMipmaps=!1;let m=!1;t.isWebGLRenderer===!0?m=t.state.buffers.depth.getReversed():m=t.reversedDepthBuffer,t.setRenderTarget(i,0,n),m&&t.autoClear===!1&&t.clearDepth(),t.render(e,s),t.setRenderTarget(i,1,n),m&&t.autoClear===!1&&t.clearDepth(),t.render(e,r),t.setRenderTarget(i,2,n),m&&t.autoClear===!1&&t.clearDepth(),t.render(e,o),t.setRenderTarget(i,3,n),m&&t.autoClear===!1&&t.clearDepth(),t.render(e,c),t.setRenderTarget(i,4,n),m&&t.autoClear===!1&&t.clearDepth(),t.render(e,l),i.texture.generateMipmaps=v,t.setRenderTarget(i,5,n),m&&t.autoClear===!1&&t.clearDepth(),t.render(e,h),t.setRenderTarget(u,d,f),t.xr.enabled=p,i.texture.needsPMREMUpdate=!0}}class Hx extends rn{constructor(t=[]){super(),this.isArrayCamera=!0,this.isMultiViewCamera=!1,this.cameras=t}}class Gx{constructor(t,e,i){this.binding=t,this.valueSize=i;let n,s,r;switch(e){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(t,e){const i=this.buffer,n=this.valueSize,s=t*n+n;let r=this.cumulativeWeight;if(r===0){for(let o=0;o!==n;++o)i[s+o]=i[o];r=e}else{r+=e;const o=e/r;this._mixBufferRegion(i,s,0,o,n)}this.cumulativeWeight=r}accumulateAdditive(t){const e=this.buffer,i=this.valueSize,n=i*this._addIndex;this.cumulativeWeightAdditive===0&&this._setIdentity(),this._mixBufferRegionAdditive(e,n,0,t,i),this.cumulativeWeightAdditive+=t}apply(t){const e=this.valueSize,i=this.buffer,n=t*e+e,s=this.cumulativeWeight,r=this.cumulativeWeightAdditive,o=this.binding;if(this.cumulativeWeight=0,this.cumulativeWeightAdditive=0,s<1){const c=e*this._origIndex;this._mixBufferRegion(i,n,c,1-s,e)}r>0&&this._mixBufferRegionAdditive(i,n,this._addIndex*e,1,e);for(let c=e,l=e+e;c!==l;++c)if(i[c]!==i[c+e]){o.setValue(i,n);break}}saveOriginalState(){const t=this.binding,e=this.buffer,i=this.valueSize,n=i*this._origIndex;t.getValue(e,n);for(let s=i,r=n;s!==r;++s)e[s]=e[n+s%i];this._setIdentity(),this.cumulativeWeight=0,this.cumulativeWeightAdditive=0}restoreOriginalState(){const t=this.valueSize*3;this.binding.setValue(this.buffer,t)}_setAdditiveIdentityNumeric(){const t=this._addIndex*this.valueSize,e=t+this.valueSize;for(let i=t;i<e;i++)this.buffer[i]=0}_setAdditiveIdentityQuaternion(){this._setAdditiveIdentityNumeric(),this.buffer[this._addIndex*this.valueSize+3]=1}_setAdditiveIdentityOther(){const t=this._origIndex*this.valueSize,e=this._addIndex*this.valueSize;for(let i=0;i<this.valueSize;i++)this.buffer[e+i]=this.buffer[t+i]}_select(t,e,i,n,s){if(n>=.5)for(let r=0;r!==s;++r)t[e+r]=t[i+r]}_slerp(t,e,i,n){on.slerpFlat(t,e,t,e,t,i,n)}_slerpAdditive(t,e,i,n,s){const r=this._workIndex*s;on.multiplyQuaternionsFlat(t,r,t,e,t,i),on.slerpFlat(t,e,t,e,t,r,n)}_lerp(t,e,i,n,s){const r=1-n;for(let o=0;o!==s;++o){const c=e+o;t[c]=t[c]*r+t[i+o]*n}}_lerpAdditive(t,e,i,n,s){for(let r=0;r!==s;++r){const o=e+r;t[o]=t[o]+t[i+r]*n}}}const K0="\\[\\]\\.:\\/",Vx=new RegExp("["+K0+"]","g"),Z0="[^"+K0+"]",Wx="[^"+K0.replace("\\.","")+"]",Xx=/((?:WC+[\/:])*)/.source.replace("WC",Z0),Yx=/(WCOD+)?/.source.replace("WCOD",Wx),qx=/(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace("WC",Z0),$x=/\.(WC+)(?:\[(.+)\])?/.source.replace("WC",Z0),Kx=new RegExp("^"+Xx+Yx+qx+$x+"$"),Zx=["material","materials","bones","map"];class Jx{constructor(t,e,i){const n=i||Ae.parseTrackName(e);this._targetGroup=t,this._bindings=t.subscribe_(e,n)}getValue(t,e){this.bind();const i=this._targetGroup.nCachedObjects_,n=this._bindings[i];n!==void 0&&n.getValue(t,e)}setValue(t,e){const i=this._bindings;for(let n=this._targetGroup.nCachedObjects_,s=i.length;n!==s;++n)i[n].setValue(t,e)}bind(){const t=this._bindings;for(let e=this._targetGroup.nCachedObjects_,i=t.length;e!==i;++e)t[e].bind()}unbind(){const t=this._bindings;for(let e=this._targetGroup.nCachedObjects_,i=t.length;e!==i;++e)t[e].unbind()}}class Ae{constructor(t,e,i){this.path=e,this.parsedPath=i||Ae.parseTrackName(e),this.node=Ae.findNode(t,this.parsedPath.nodeName),this.rootNode=t,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}static create(t,e,i){return t&&t.isAnimationObjectGroup?new Ae.Composite(t,e,i):new Ae(t,e,i)}static sanitizeNodeName(t){return t.replace(/\s/g,"_").replace(Vx,"")}static parseTrackName(t){const e=Kx.exec(t);if(e===null)throw new Error("THREE.PropertyBinding: Cannot parse trackName: "+t);const i={nodeName:e[2],objectName:e[3],objectIndex:e[4],propertyName:e[5],propertyIndex:e[6]},n=i.nodeName&&i.nodeName.lastIndexOf(".");if(n!==void 0&&n!==-1){const s=i.nodeName.substring(n+1);Zx.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: "+t);return i}static findNode(t,e){if(e===void 0||e===""||e==="."||e===-1||e===t.name||e===t.uuid)return t;if(t.skeleton){const i=t.skeleton.getBoneByName(e);if(i!==void 0)return i}if(t.children){const i=function(s){for(let r=0;r<s.length;r++){const o=s[r];if(o.name===e||o.uuid===e)return o;const c=i(o.children);if(c)return c}return null},n=i(t.children);if(n)return n}return null}_getValue_unavailable(){}_setValue_unavailable(){}_getValue_direct(t,e){t[e]=this.targetObject[this.propertyName]}_getValue_array(t,e){const i=this.resolvedProperty;for(let n=0,s=i.length;n!==s;++n)t[e++]=i[n]}_getValue_arrayElement(t,e){t[e]=this.resolvedProperty[this.propertyIndex]}_getValue_toArray(t,e){this.resolvedProperty.toArray(t,e)}_setValue_direct(t,e){this.targetObject[this.propertyName]=t[e]}_setValue_direct_setNeedsUpdate(t,e){this.targetObject[this.propertyName]=t[e],this.targetObject.needsUpdate=!0}_setValue_direct_setMatrixWorldNeedsUpdate(t,e){this.targetObject[this.propertyName]=t[e],this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_array(t,e){const i=this.resolvedProperty;for(let n=0,s=i.length;n!==s;++n)i[n]=t[e++]}_setValue_array_setNeedsUpdate(t,e){const i=this.resolvedProperty;for(let n=0,s=i.length;n!==s;++n)i[n]=t[e++];this.targetObject.needsUpdate=!0}_setValue_array_setMatrixWorldNeedsUpdate(t,e){const i=this.resolvedProperty;for(let n=0,s=i.length;n!==s;++n)i[n]=t[e++];this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_arrayElement(t,e){this.resolvedProperty[this.propertyIndex]=t[e]}_setValue_arrayElement_setNeedsUpdate(t,e){this.resolvedProperty[this.propertyIndex]=t[e],this.targetObject.needsUpdate=!0}_setValue_arrayElement_setMatrixWorldNeedsUpdate(t,e){this.resolvedProperty[this.propertyIndex]=t[e],this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_fromArray(t,e){this.resolvedProperty.fromArray(t,e)}_setValue_fromArray_setNeedsUpdate(t,e){this.resolvedProperty.fromArray(t,e),this.targetObject.needsUpdate=!0}_setValue_fromArray_setMatrixWorldNeedsUpdate(t,e){this.resolvedProperty.fromArray(t,e),this.targetObject.matrixWorldNeedsUpdate=!0}_getValue_unbound(t,e){this.bind(),this.getValue(t,e)}_setValue_unbound(t,e){this.bind(),this.setValue(t,e)}bind(){let t=this.node;const e=this.parsedPath,i=e.objectName,n=e.propertyName;let s=e.propertyIndex;if(t||(t=Ae.findNode(this.rootNode,e.nodeName),this.node=t),this.getValue=this._getValue_unavailable,this.setValue=this._setValue_unavailable,!t){It("PropertyBinding: No target node found for track: "+this.path+".");return}if(i){let l=e.objectIndex;switch(i){case"materials":if(!t.material){Wt("PropertyBinding: Can not bind to material as node does not have a material.",this);return}if(!t.material.materials){Wt("PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.",this);return}t=t.material.materials;break;case"bones":if(!t.skeleton){Wt("PropertyBinding: Can not bind to bones as node does not have a skeleton.",this);return}t=t.skeleton.bones;for(let h=0;h<t.length;h++)if(t[h].name===l){l=h;break}break;case"map":if("map"in t){t=t.map;break}if(!t.material){Wt("PropertyBinding: Can not bind to material as node does not have a material.",this);return}if(!t.material.map){Wt("PropertyBinding: Can not bind to material.map as node.material does not have a map.",this);return}t=t.material.map;break;default:if(t[i]===void 0){Wt("PropertyBinding: Can not bind to objectName of node undefined.",this);return}t=t[i]}if(l!==void 0){if(t[l]===void 0){Wt("PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.",this,t);return}t=t[l]}}const r=t[n];if(r===void 0){const l=e.nodeName;Wt("PropertyBinding: Trying to update property for track: "+l+"."+n+" but it wasn't found.",t);return}let o=this.Versioning.None;this.targetObject=t,t.isMaterial===!0?o=this.Versioning.NeedsUpdate:t.isObject3D===!0&&(o=this.Versioning.MatrixWorldNeedsUpdate);let c=this.BindingType.Direct;if(s!==void 0){if(n==="morphTargetInfluences"){if(!t.geometry){Wt("PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.",this);return}if(!t.geometry.morphAttributes){Wt("PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.",this);return}t.morphTargetDictionary[s]!==void 0&&(s=t.morphTargetDictionary[s])}c=this.BindingType.ArrayElement,this.resolvedProperty=r,this.propertyIndex=s}else r.fromArray!==void 0&&r.toArray!==void 0?(c=this.BindingType.HasFromToArray,this.resolvedProperty=r):Array.isArray(r)?(c=this.BindingType.EntireArray,this.resolvedProperty=r):this.propertyName=n;this.getValue=this.GetterByBindingType[c],this.setValue=this.SetterByBindingTypeAndVersioning[c][o]}unbind(){this.node=null,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}}Ae.Composite=Jx;Ae.prototype.BindingType={Direct:0,EntireArray:1,ArrayElement:2,HasFromToArray:3};Ae.prototype.Versioning={None:0,NeedsUpdate:1,MatrixWorldNeedsUpdate:2};Ae.prototype.GetterByBindingType=[Ae.prototype._getValue_direct,Ae.prototype._getValue_array,Ae.prototype._getValue_arrayElement,Ae.prototype._getValue_toArray];Ae.prototype.SetterByBindingTypeAndVersioning=[[Ae.prototype._setValue_direct,Ae.prototype._setValue_direct_setNeedsUpdate,Ae.prototype._setValue_direct_setMatrixWorldNeedsUpdate],[Ae.prototype._setValue_array,Ae.prototype._setValue_array_setNeedsUpdate,Ae.prototype._setValue_array_setMatrixWorldNeedsUpdate],[Ae.prototype._setValue_arrayElement,Ae.prototype._setValue_arrayElement_setNeedsUpdate,Ae.prototype._setValue_arrayElement_setMatrixWorldNeedsUpdate],[Ae.prototype._setValue_fromArray,Ae.prototype._setValue_fromArray_setNeedsUpdate,Ae.prototype._setValue_fromArray_setMatrixWorldNeedsUpdate]];class jx{constructor(t,e,i=null,n=e.blendMode){this._mixer=t,this._clip=e,this._localRoot=i,this.blendMode=n;const s=e.tracks,r=s.length,o=new Array(r),c={endingStart:Da,endingEnd:Da};for(let l=0;l!==r;++l){const h=s[l].createInterpolant(null);o[l]=h,h.settings=c}this._interpolantSettings=c,this._interpolants=o,this._propertyBindings=new Array(r),this._cacheIndex=null,this._byClipCacheIndex=null,this._timeScaleInterpolant=null,this._restoreTimeScale=null,this._weightInterpolant=null,this.loop=uM,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(t){return this._startTime=t,this}setLoop(t,e){return this.loop=t,this.repetitions=e,this}setEffectiveWeight(t){return this.weight=t,this._effectiveWeight=this.enabled?t:0,this.stopFading()}getEffectiveWeight(){return this._effectiveWeight}fadeIn(t){return this._scheduleFading(t,0,1)}fadeOut(t){return this._scheduleFading(t,1,0)}crossFadeFrom(t,e,i=!1){if(t.fadeOut(e),this.fadeIn(e),i===!0){const n=this._clip.duration,s=t._clip.duration,r=s/n,o=n/s;t._restoreTimeScale=t.timeScale,this._restoreTimeScale=this.timeScale,t.warp(1,r,e),this.warp(o,1,e)}return this}crossFadeTo(t,e,i=!1){return t.crossFadeFrom(this,e,i)}stopFading(){const t=this._weightInterpolant;return t!==null&&(this._weightInterpolant=null,this._mixer._takeBackControlInterpolant(t)),this}setEffectiveTimeScale(t){return this.timeScale=t,this._effectiveTimeScale=this.paused?0:t,this.stopWarping()}getEffectiveTimeScale(){return this._effectiveTimeScale}setDuration(t){return this.timeScale=this._clip.duration/t,this.stopWarping()}syncWith(t){return this.time=t.time,this.timeScale=t.timeScale,this.stopWarping()}halt(t){return this.warp(this._effectiveTimeScale,0,t)}warp(t,e,i){const n=this._mixer,s=n.time,r=this.timeScale;let o=this._timeScaleInterpolant;o===null&&(o=n._lendControlInterpolant(),this._timeScaleInterpolant=o);const c=o.parameterPositions,l=o.sampleValues;return c[0]=s,c[1]=s+i,l[0]=t/r,l[1]=e/r,this}stopWarping(){const t=this._timeScaleInterpolant;return t!==null&&(this._timeScaleInterpolant=null,this._mixer._takeBackControlInterpolant(t)),this._restoreTimeScale=null,this}getMixer(){return this._mixer}getClip(){return this._clip}getRoot(){return this._localRoot||this._mixer._root}_update(t,e,i,n){if(!this.enabled){this._updateWeight(t);return}const s=this._startTime;if(s!==null){const c=(t-s)*i;c<0||i===0?e=0:(this._startTime=null,e=i*c)}e*=this._updateTimeScale(t);const r=this._updateTime(e),o=this._updateWeight(t);if(o>0){const c=this._interpolants,l=this._propertyBindings;switch(this.blendMode){case fM:for(let h=0,u=c.length;h!==u;++h)c[h].evaluate(r),l[h].accumulateAdditive(o);break;case O0:default:for(let h=0,u=c.length;h!==u;++h)c[h].evaluate(r),l[h].accumulate(n,o)}}}_updateWeight(t){let e=0;if(this.enabled){e=this.weight;const i=this._weightInterpolant;if(i!==null){const n=i.evaluate(t)[0];e*=n,t>i.parameterPositions[1]&&(this.stopFading(),n===0&&(this.enabled=!1))}}return this._effectiveWeight=e,e}_updateTimeScale(t){let e=0;if(!this.paused){e=this.timeScale;const i=this._timeScaleInterpolant;if(i!==null){const n=i.evaluate(t)[0];e*=n,t>i.parameterPositions[1]&&(e===0?this.paused=!0:(this._restoreTimeScale!==null&&(e=this._restoreTimeScale),this.timeScale=e),this.stopWarping())}}return this._effectiveTimeScale=e,e}_updateTime(t){const e=this._clip.duration,i=this.loop;let n=this.time+t,s=this._loopCount;const r=i===dM;if(t===0)return s===-1?n:r&&(s&1)===1?e-n:n;if(i===d1){s===-1&&(this._loopCount=0,this._setEndings(!0,!0,!1));t:{if(n>=e)n=e;else if(n<0)n=0;else{this.time=n;break t}this.clampWhenFinished?this.paused=!0:this.enabled=!1,this.time=n,this._mixer.dispatchEvent({type:"finished",action:this,direction:t<0?-1:1})}}else{if(s===-1&&(t>=0?(s=0,this._setEndings(!0,this.repetitions===0,r)):this._setEndings(this.repetitions===0,!0,r)),n>=e||n<0){const o=Math.floor(n/e);n-=e*o,s+=Math.abs(o);const c=this.repetitions-s;if(c<=0)this.clampWhenFinished?this.paused=!0:this.enabled=!1,n=t>0?e:0,this.time=n,this._mixer.dispatchEvent({type:"finished",action:this,direction:t>0?1:-1});else{if(c===1){const l=t<0;this._setEndings(l,!l,r)}else this._setEndings(!1,!1,r);this._loopCount=s,this.time=n,this._mixer.dispatchEvent({type:"loop",action:this,loopDelta:o})}}else this._loopCount=s,this.time=n;if(r&&(s&1)===1)return e-n}return n}_setEndings(t,e,i){const n=this._interpolantSettings;i?(n.endingStart=Ia,n.endingEnd=Ia):(t?n.endingStart=this.zeroSlopeAtStart?Ia:Da:n.endingStart=Hl,e?n.endingEnd=this.zeroSlopeAtEnd?Ia:Da:n.endingEnd=Hl)}_scheduleFading(t,e,i){const n=this._mixer,s=n.time;let r=this._weightInterpolant;r===null&&(r=n._lendControlInterpolant(),this._weightInterpolant=r);const o=r.parameterPositions,c=r.sampleValues;return o[0]=s,c[0]=e,o[1]=s+t,c[1]=i,this}}const Qx=new Float32Array(1);class ty extends vr{constructor(t){super(),this._root=t,this._initMemoryManager(),this._accuIndex=0,this.time=0,this.timeScale=1,typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}_bindAction(t,e){const i=t._localRoot||this._root,n=t._clip.tracks,s=n.length,r=t._propertyBindings,o=t._interpolants,c=i.uuid,l=this._bindingsByRootAndName;let h=l[c];h===void 0&&(h={},l[c]=h);for(let u=0;u!==s;++u){const d=n[u],f=d.name;let p=h[f];if(p!==void 0)++p.referenceCount,r[u]=p;else{if(p=r[u],p!==void 0){p._cacheIndex===null&&(++p.referenceCount,this._addInactiveBinding(p,c,f));continue}const v=e&&e._propertyBindings[u].binding.parsedPath;p=new Gx(Ae.create(i,f,v),d.ValueTypeName,d.getValueSize()),++p.referenceCount,this._addInactiveBinding(p,c,f),r[u]=p}o[u].resultBuffer=p.buffer}}_activateAction(t){if(!this._isActiveAction(t)){if(t._cacheIndex===null){const i=(t._localRoot||this._root).uuid,n=t._clip.uuid,s=this._actionsByClip[n];this._bindAction(t,s&&s.knownActions[0]),this._addInactiveAction(t,n,i)}const e=t._propertyBindings;for(let i=0,n=e.length;i!==n;++i){const s=e[i];s.useCount++===0&&(this._lendBinding(s),s.saveOriginalState())}this._lendAction(t)}}_deactivateAction(t){if(this._isActiveAction(t)){const e=t._propertyBindings;for(let i=0,n=e.length;i!==n;++i){const s=e[i];--s.useCount===0&&(s.restoreOriginalState(),this._takeBackBinding(s))}this._takeBackAction(t)}}_initMemoryManager(){this._actions=[],this._nActiveActions=0,this._actionsByClip={},this._bindings=[],this._nActiveBindings=0,this._bindingsByRootAndName={},this._controlInterpolants=[],this._nActiveControlInterpolants=0;const t=this;this.stats={actions:{get total(){return t._actions.length},get inUse(){return t._nActiveActions}},bindings:{get total(){return t._bindings.length},get inUse(){return t._nActiveBindings}},controlInterpolants:{get total(){return t._controlInterpolants.length},get inUse(){return t._nActiveControlInterpolants}}}}_isActiveAction(t){const e=t._cacheIndex;return e!==null&&e<this._nActiveActions}_addInactiveAction(t,e,i){const n=this._actions,s=this._actionsByClip;let r=s[e];if(r===void 0)r={knownActions:[t],actionByRoot:{}},t._byClipCacheIndex=0,s[e]=r;else{const o=r.knownActions;t._byClipCacheIndex=o.length,o.push(t)}t._cacheIndex=n.length,n.push(t),r.actionByRoot[i]=t}_removeInactiveAction(t){const e=this._actions,i=e[e.length-1],n=t._cacheIndex;i._cacheIndex=n,e[n]=i,e.pop(),t._cacheIndex=null;const s=t._clip.uuid,r=this._actionsByClip,o=r[s],c=o.knownActions,l=c[c.length-1],h=t._byClipCacheIndex;l._byClipCacheIndex=h,c[h]=l,c.pop(),t._byClipCacheIndex=null;const u=o.actionByRoot,d=(t._localRoot||this._root).uuid;delete u[d],c.length===0&&delete r[s],this._removeInactiveBindingsForAction(t)}_removeInactiveBindingsForAction(t){const e=t._propertyBindings;for(let i=0,n=e.length;i!==n;++i){const s=e[i];--s.referenceCount===0&&this._removeInactiveBinding(s)}}_lendAction(t){const e=this._actions,i=t._cacheIndex,n=this._nActiveActions++,s=e[n];t._cacheIndex=n,e[n]=t,s._cacheIndex=i,e[i]=s}_takeBackAction(t){const e=this._actions,i=t._cacheIndex,n=--this._nActiveActions,s=e[n];t._cacheIndex=n,e[n]=t,s._cacheIndex=i,e[i]=s}_addInactiveBinding(t,e,i){const n=this._bindingsByRootAndName,s=this._bindings;let r=n[e];r===void 0&&(r={},n[e]=r),r[i]=t,t._cacheIndex=s.length,s.push(t)}_removeInactiveBinding(t){const e=this._bindings,i=t.binding,n=i.rootNode.uuid,s=i.path,r=this._bindingsByRootAndName,o=r[n],c=e[e.length-1],l=t._cacheIndex;c._cacheIndex=l,e[l]=c,e.pop(),delete o[s],Object.keys(o).length===0&&delete r[n]}_lendBinding(t){const e=this._bindings,i=t._cacheIndex,n=this._nActiveBindings++,s=e[n];t._cacheIndex=n,e[n]=t,s._cacheIndex=i,e[i]=s}_takeBackBinding(t){const e=this._bindings,i=t._cacheIndex,n=--this._nActiveBindings,s=e[n];t._cacheIndex=n,e[n]=t,s._cacheIndex=i,e[i]=s}_lendControlInterpolant(){const t=this._controlInterpolants,e=this._nActiveControlInterpolants++;let i=t[e];return i===void 0&&(i=new A1(new Float32Array(2),new Float32Array(2),1,Qx),i.__cacheIndex=e,t[e]=i),i}_takeBackControlInterpolant(t){const e=this._controlInterpolants,i=t.__cacheIndex,n=--this._nActiveControlInterpolants,s=e[n];t.__cacheIndex=n,e[n]=t,s.__cacheIndex=i,e[i]=s}clipAction(t,e,i){const n=e||this._root,s=n.uuid;let r=typeof t=="string"?kp.findByName(n,t):t;const o=r!==null?r.uuid:t,c=this._actionsByClip[o];let l=null;if(i===void 0&&(r!==null?i=r.blendMode:i=O0),c!==void 0){const u=c.actionByRoot[s];if(u!==void 0&&u.blendMode===i)return u;l=c.knownActions[0],r===null&&(r=l._clip)}if(r===null)return null;const h=new jx(this,r,e,i);return this._bindAction(h,l),this._addInactiveAction(h,o,s),h}existingAction(t,e){const i=e||this._root,n=i.uuid,s=typeof t=="string"?kp.findByName(i,t):t,r=s?s.uuid:t,o=this._actionsByClip[r];return o!==void 0&&o.actionByRoot[n]||null}stopAllAction(){const t=this._actions,e=this._nActiveActions;for(let i=e-1;i>=0;--i)t[i].stop();return this}update(t){t*=this.timeScale;const e=this._actions,i=this._nActiveActions,n=this.time+=t,s=Math.sign(t),r=this._accuIndex^=1;for(let l=0;l!==i;++l)e[l]._update(n,t,s,r);const o=this._bindings,c=this._nActiveBindings;for(let l=0;l!==c;++l)o[l].apply(r);return this}setTime(t){this.time=0;for(let e=0;e<this._actions.length;e++)this._actions[e].time=0;return this.update(t)}getRoot(){return this._root}uncacheClip(t){const e=this._actions,i=t.uuid,n=this._actionsByClip,s=n[i];if(s!==void 0){const r=s.knownActions;for(let o=0,c=r.length;o!==c;++o){const l=r[o];this._deactivateAction(l);const h=l._cacheIndex,u=e[e.length-1];l._cacheIndex=null,l._byClipCacheIndex=null,u._cacheIndex=h,e[h]=u,e.pop(),this._removeInactiveBindingsForAction(l)}delete n[i]}}uncacheRoot(t){const e=t.uuid,i=this._actionsByClip;for(const r in i){const o=i[r].actionByRoot,c=o[e];c!==void 0&&(this._deactivateAction(c),this._removeInactiveAction(c))}const n=this._bindingsByRootAndName,s=n[e];if(s!==void 0)for(const r in s){const o=s[r];o.restoreOriginalState(),this._removeInactiveBinding(o)}}uncacheAction(t,e){const i=this.existingAction(t,e);i!==null&&(this._deactivateAction(i),this._removeInactiveAction(i))}}class aT extends M1{constructor(t,e,i=1){super(t,e),this.isInstancedInterleavedBuffer=!0,this.meshPerAttribute=i}copy(t){return super.copy(t),this.meshPerAttribute=t.meshPerAttribute,this}clone(t){const e=super.clone(t);return e.meshPerAttribute=this.meshPerAttribute,e}toJSON(t){const e=super.toJSON(t);return e.isInstancedInterleavedBuffer=!0,e.meshPerAttribute=this.meshPerAttribute,e}}const Xp=new te;class Cl{constructor(t,e,i=0,n=1/0){this.ray=new fc(t,e),this.near=i,this.far=n,this.camera=null,this.layers=new z0,this.params={Mesh:{},Line:{threshold:1},LOD:{},Points:{threshold:1},Sprite:{}}}set(t,e){this.ray.set(t,e)}setFromCamera(t,e){e.isPerspectiveCamera?(this.ray.origin.setFromMatrixPosition(e.matrixWorld),this.ray.direction.set(t.x,t.y,.5).unproject(e).sub(this.ray.origin).normalize(),this.camera=e):e.isOrthographicCamera?(this.ray.origin.set(t.x,t.y,e.projectionMatrix.elements[14]).unproject(e),this.ray.direction.set(0,0,-1).transformDirection(e.matrixWorld),this.camera=e):Wt("Raycaster: Unsupported camera type: "+e.type)}setFromXRController(t){return Xp.identity().extractRotation(t.matrixWorld),this.ray.origin.setFromMatrixPosition(t.matrixWorld),this.ray.direction.set(0,0,-1).applyMatrix4(Xp),this}intersectObject(t,e=!0,i=[]){return Vd(t,this,i,e),i.sort(Yp),i}intersectObjects(t,e=!0,i=[]){for(let n=0,s=t.length;n<s;n++)Vd(t[n],this,i,e);return i.sort(Yp),i}}function Yp(a,t){return a.distance-t.distance}function Vd(a,t,e,i){let n=!0;if(a.layers.test(t.layers)&&a.raycast(t,e)===!1&&(n=!1),n===!0&&i===!0){const s=a.children;for(let r=0,o=s.length;r<o;r++)Vd(s[r],t,e,!0)}}class C1{static{C1.prototype.isMatrix2=!0}constructor(t,e,i,n){this.elements=[1,0,0,1],t!==void 0&&this.set(t,e,i,n)}identity(){return this.set(1,0,0,1),this}fromArray(t,e=0){for(let i=0;i<4;i++)this.elements[i]=t[i+e];return this}set(t,e,i,n){const s=this.elements;return s[0]=t,s[2]=e,s[1]=i,s[3]=n,this}}const qp=new R,il=new R,xa=new R,ya=new R,ou=new R,ey=new R,iy=new R;class oT{constructor(t=new R,e=new R){this.start=t,this.end=e}set(t,e){return this.start.copy(t),this.end.copy(e),this}copy(t){return this.start.copy(t.start),this.end.copy(t.end),this}getCenter(t){return t.addVectors(this.start,this.end).multiplyScalar(.5)}delta(t){return t.subVectors(this.end,this.start)}distanceSq(){return this.start.distanceToSquared(this.end)}distance(){return this.start.distanceTo(this.end)}at(t,e){return this.delta(e).multiplyScalar(t).add(this.start)}closestPointToPointParameter(t,e){qp.subVectors(t,this.start),il.subVectors(this.end,this.start);const i=il.dot(il);if(i===0)return 0;let s=il.dot(qp)/i;return e&&(s=Zt(s,0,1)),s}closestPointToPoint(t,e,i){const n=this.closestPointToPointParameter(t,e);return this.delta(i).multiplyScalar(n).add(this.start)}distanceSqToLine3(t,e=ey,i=iy){const n=10000000000000001e-32;let s,r;const o=this.start,c=t.start,l=this.end,h=t.end;xa.subVectors(l,o),ya.subVectors(h,c),ou.subVectors(o,c);const u=xa.dot(xa),d=ya.dot(ya),f=ya.dot(ou);if(u<=n&&d<=n)return e.copy(o),i.copy(c),e.sub(i),e.dot(e);if(u<=n)s=0,r=f/d,r=Zt(r,0,1);else{const p=xa.dot(ou);if(d<=n)r=0,s=Zt(-p/u,0,1);else{const v=xa.dot(ya),m=u*d-v*v;m!==0?s=Zt((v*f-p*d)/m,0,1):s=0,r=(v*s+f)/d,r<0?(r=0,s=Zt(-p/u,0,1)):r>1&&(r=1,s=Zt((v-p)/u,0,1))}}return e.copy(o).addScaledVector(xa,s),i.copy(c).addScaledVector(ya,r),e.distanceToSquared(i)}applyMatrix4(t){return this.start.applyMatrix4(t),this.end.applyMatrix4(t),this}equals(t){return t.start.equals(this.start)&&t.end.equals(this.end)}clone(){return new this.constructor().copy(this)}}function $p(a,t,e,i){const n=ny(i);switch(e){case h1:return a*t;case dh:return a*t/n.components*n.byteLength;case C0:return a*t/n.components*n.byteLength;case Yr:return a*t*2/n.components*n.byteLength;case P0:return a*t*2/n.components*n.byteLength;case u1:return a*t*3/n.components*n.byteLength;case Di:return a*t*4/n.components*n.byteLength;case L0:return a*t*4/n.components*n.byteLength;case Al:case Tl:return Math.floor((a+3)/4)*Math.floor((t+3)/4)*8;case Rl:case Dl:return Math.floor((a+3)/4)*Math.floor((t+3)/4)*16;case hd:case dd:return Math.max(a,16)*Math.max(t,8)/4;case ld:case ud:return Math.max(a,8)*Math.max(t,8)/2;case fd:case pd:case gd:case vd:return Math.floor((a+3)/4)*Math.floor((t+3)/4)*8;case md:case kl:case Md:return Math.floor((a+3)/4)*Math.floor((t+3)/4)*16;case xd:return Math.floor((a+3)/4)*Math.floor((t+3)/4)*16;case yd:return Math.floor((a+4)/5)*Math.floor((t+3)/4)*16;case Sd:return Math.floor((a+4)/5)*Math.floor((t+4)/5)*16;case _d:return Math.floor((a+5)/6)*Math.floor((t+4)/5)*16;case bd:return Math.floor((a+5)/6)*Math.floor((t+5)/6)*16;case wd:return Math.floor((a+7)/8)*Math.floor((t+4)/5)*16;case Ed:return Math.floor((a+7)/8)*Math.floor((t+5)/6)*16;case Ad:return Math.floor((a+7)/8)*Math.floor((t+7)/8)*16;case Td:return Math.floor((a+9)/10)*Math.floor((t+4)/5)*16;case Rd:return Math.floor((a+9)/10)*Math.floor((t+5)/6)*16;case Dd:return Math.floor((a+9)/10)*Math.floor((t+7)/8)*16;case Id:return Math.floor((a+9)/10)*Math.floor((t+9)/10)*16;case Cd:return Math.floor((a+11)/12)*Math.floor((t+9)/10)*16;case Pd:return Math.floor((a+11)/12)*Math.floor((t+11)/12)*16;case Ld:case Od:case Nd:return Math.ceil(a/4)*Math.ceil(t/4)*16;case Fd:case Ud:return Math.ceil(a/4)*Math.ceil(t/4)*8;case zl:case kd:return Math.ceil(a/4)*Math.ceil(t/4)*16}throw new Error(`Unable to determine texture byte length for ${e} format.`)}function ny(a){switch(a){case yn:case a1:return{byteLength:1,components:1};case rc:case o1:case $e:return{byteLength:2,components:1};case D0:case I0:return{byteLength:2,components:4};case Nn:case R0:case Ui:return{byteLength:4,components:1};case c1:case l1:return{byteLength:4,components:3}}throw new Error(`THREE.TextureUtils: Unknown texture type ${a}.`)}typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:A0}}));typeof window<"u"&&(window.__THREE__?It("WARNING: Multiple instances of Three.js being imported."):window.__THREE__=A0);/**
1421
1421
  * @license
1422
1422
  * Copyright 2010-2026 Three.js Authors
1423
1423
  * SPDX-License-Identifier: MIT
@@ -5087,7 +5087,7 @@ void main() {
5087
5087
  #include <tonemapping_fragment>
5088
5088
  #include <colorspace_fragment>
5089
5089
  #include <fog_fragment>
5090
- }`,qt={alphahash_fragment:ry,alphahash_pars_fragment:ay,alphamap_fragment:oy,alphamap_pars_fragment:cy,alphatest_fragment:ly,alphatest_pars_fragment:hy,aomap_fragment:uy,aomap_pars_fragment:dy,batching_pars_vertex:fy,batching_vertex:py,begin_vertex:my,beginnormal_vertex:gy,bsdfs:vy,iridescence_fragment:My,bumpmap_pars_fragment:xy,clipping_planes_fragment:yy,clipping_planes_pars_fragment:Sy,clipping_planes_pars_vertex:_y,clipping_planes_vertex:by,color_fragment:wy,color_pars_fragment:Ey,color_pars_vertex:Ay,color_vertex:Ty,common:Ry,cube_uv_reflection_fragment:Dy,defaultnormal_vertex:Iy,displacementmap_pars_vertex:Cy,displacementmap_vertex:Py,emissivemap_fragment:Ly,emissivemap_pars_fragment:Oy,colorspace_fragment:Ny,colorspace_pars_fragment:Fy,envmap_fragment:Uy,envmap_common_pars_fragment:ky,envmap_pars_fragment:zy,envmap_pars_vertex:By,envmap_physical_pars_fragment:Jy,envmap_vertex:Hy,fog_vertex:Gy,fog_pars_vertex:Vy,fog_fragment:Wy,fog_pars_fragment:Xy,gradientmap_pars_fragment:Yy,lightmap_pars_fragment:qy,lights_lambert_fragment:$y,lights_lambert_pars_fragment:Ky,lights_pars_begin:Zy,lights_toon_fragment:jy,lights_toon_pars_fragment:Qy,lights_phong_fragment:t3,lights_phong_pars_fragment:e3,lights_physical_fragment:i3,lights_physical_pars_fragment:n3,lights_fragment_begin:s3,lights_fragment_maps:r3,lights_fragment_end:a3,lightprobes_pars_fragment:o3,logdepthbuf_fragment:c3,logdepthbuf_pars_fragment:l3,logdepthbuf_pars_vertex:h3,logdepthbuf_vertex:u3,map_fragment:d3,map_pars_fragment:f3,map_particle_fragment:p3,map_particle_pars_fragment:m3,metalnessmap_fragment:g3,metalnessmap_pars_fragment:v3,morphinstance_vertex:M3,morphcolor_vertex:x3,morphnormal_vertex:y3,morphtarget_pars_vertex:S3,morphtarget_vertex:_3,normal_fragment_begin:b3,normal_fragment_maps:w3,normal_pars_fragment:E3,normal_pars_vertex:A3,normal_vertex:T3,normalmap_pars_fragment:R3,clearcoat_normal_fragment_begin:D3,clearcoat_normal_fragment_maps:I3,clearcoat_pars_fragment:C3,iridescence_pars_fragment:P3,opaque_fragment:L3,packing:O3,premultiplied_alpha_fragment:N3,project_vertex:F3,dithering_fragment:U3,dithering_pars_fragment:k3,roughnessmap_fragment:z3,roughnessmap_pars_fragment:B3,shadowmap_pars_fragment:H3,shadowmap_pars_vertex:G3,shadowmap_vertex:V3,shadowmask_pars_fragment:W3,skinbase_vertex:X3,skinning_pars_vertex:Y3,skinning_vertex:q3,skinnormal_vertex:$3,specularmap_fragment:K3,specularmap_pars_fragment:Z3,tonemapping_fragment:J3,tonemapping_pars_fragment:j3,transmission_fragment:Q3,transmission_pars_fragment:tS,uv_pars_fragment:eS,uv_pars_vertex:iS,uv_vertex:nS,worldpos_vertex:sS,background_vert:rS,background_frag:aS,backgroundCube_vert:oS,backgroundCube_frag:cS,cube_vert:lS,cube_frag:hS,depth_vert:uS,depth_frag:dS,distance_vert:fS,distance_frag:pS,equirect_vert:mS,equirect_frag:gS,linedashed_vert:vS,linedashed_frag:MS,meshbasic_vert:xS,meshbasic_frag:yS,meshlambert_vert:SS,meshlambert_frag:_S,meshmatcap_vert:bS,meshmatcap_frag:wS,meshnormal_vert:ES,meshnormal_frag:AS,meshphong_vert:TS,meshphong_frag:RS,meshphysical_vert:DS,meshphysical_frag:IS,meshtoon_vert:CS,meshtoon_frag:PS,points_vert:LS,points_frag:OS,shadow_vert:NS,shadow_frag:FS,sprite_vert:US,sprite_frag:kS},pt={common:{diffuse:{value:new st(16777215)},opacity:{value:1},map:{value:null},mapTransform:{value:new $t},alphaMap:{value:null},alphaMapTransform:{value:new $t},alphaTest:{value:0}},specularmap:{specularMap:{value:null},specularMapTransform:{value:new $t}},envmap:{envMap:{value:null},envMapRotation:{value:new $t},reflectivity:{value:1},ior:{value:1.5},refractionRatio:{value:.98},dfgLUT:{value:null}},aomap:{aoMap:{value:null},aoMapIntensity:{value:1},aoMapTransform:{value:new $t}},lightmap:{lightMap:{value:null},lightMapIntensity:{value:1},lightMapTransform:{value:new $t}},bumpmap:{bumpMap:{value:null},bumpMapTransform:{value:new $t},bumpScale:{value:1}},normalmap:{normalMap:{value:null},normalMapTransform:{value:new $t},normalScale:{value:new Mt(1,1)}},displacementmap:{displacementMap:{value:null},displacementMapTransform:{value:new $t},displacementScale:{value:1},displacementBias:{value:0}},emissivemap:{emissiveMap:{value:null},emissiveMapTransform:{value:new $t}},metalnessmap:{metalnessMap:{value:null},metalnessMapTransform:{value:new $t}},roughnessmap:{roughnessMap:{value:null},roughnessMapTransform:{value:new $t}},gradientmap:{gradientMap:{value:null}},fog:{fogDensity:{value:25e-5},fogNear:{value:1},fogFar:{value:2e3},fogColor:{value:new st(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 R},probesMax:{value:new R},probesResolution:{value:new R}},points:{diffuse:{value:new st(16777215)},opacity:{value:1},size:{value:1},scale:{value:1},map:{value:null},alphaMap:{value:null},alphaMapTransform:{value:new $t},alphaTest:{value:0},uvTransform:{value:new $t}},sprite:{diffuse:{value:new st(16777215)},opacity:{value:1},center:{value:new Mt(.5,.5)},rotation:{value:0},map:{value:null},mapTransform:{value:new $t},alphaMap:{value:null},alphaMapTransform:{value:new $t},alphaTest:{value:0}}},cs={basic:{uniforms:Bi([pt.common,pt.specularmap,pt.envmap,pt.aomap,pt.lightmap,pt.fog]),vertexShader:qt.meshbasic_vert,fragmentShader:qt.meshbasic_frag},lambert:{uniforms:Bi([pt.common,pt.specularmap,pt.envmap,pt.aomap,pt.lightmap,pt.emissivemap,pt.bumpmap,pt.normalmap,pt.displacementmap,pt.fog,pt.lights,{emissive:{value:new st(0)},envMapIntensity:{value:1}}]),vertexShader:qt.meshlambert_vert,fragmentShader:qt.meshlambert_frag},phong:{uniforms:Bi([pt.common,pt.specularmap,pt.envmap,pt.aomap,pt.lightmap,pt.emissivemap,pt.bumpmap,pt.normalmap,pt.displacementmap,pt.fog,pt.lights,{emissive:{value:new st(0)},specular:{value:new st(1118481)},shininess:{value:30},envMapIntensity:{value:1}}]),vertexShader:qt.meshphong_vert,fragmentShader:qt.meshphong_frag},standard:{uniforms:Bi([pt.common,pt.envmap,pt.aomap,pt.lightmap,pt.emissivemap,pt.bumpmap,pt.normalmap,pt.displacementmap,pt.roughnessmap,pt.metalnessmap,pt.fog,pt.lights,{emissive:{value:new st(0)},roughness:{value:1},metalness:{value:0},envMapIntensity:{value:1}}]),vertexShader:qt.meshphysical_vert,fragmentShader:qt.meshphysical_frag},toon:{uniforms:Bi([pt.common,pt.aomap,pt.lightmap,pt.emissivemap,pt.bumpmap,pt.normalmap,pt.displacementmap,pt.gradientmap,pt.fog,pt.lights,{emissive:{value:new st(0)}}]),vertexShader:qt.meshtoon_vert,fragmentShader:qt.meshtoon_frag},matcap:{uniforms:Bi([pt.common,pt.bumpmap,pt.normalmap,pt.displacementmap,pt.fog,{matcap:{value:null}}]),vertexShader:qt.meshmatcap_vert,fragmentShader:qt.meshmatcap_frag},points:{uniforms:Bi([pt.points,pt.fog]),vertexShader:qt.points_vert,fragmentShader:qt.points_frag},dashed:{uniforms:Bi([pt.common,pt.fog,{scale:{value:1},dashSize:{value:1},totalSize:{value:2}}]),vertexShader:qt.linedashed_vert,fragmentShader:qt.linedashed_frag},depth:{uniforms:Bi([pt.common,pt.displacementmap]),vertexShader:qt.depth_vert,fragmentShader:qt.depth_frag},normal:{uniforms:Bi([pt.common,pt.bumpmap,pt.normalmap,pt.displacementmap,{opacity:{value:1}}]),vertexShader:qt.meshnormal_vert,fragmentShader:qt.meshnormal_frag},sprite:{uniforms:Bi([pt.sprite,pt.fog]),vertexShader:qt.sprite_vert,fragmentShader:qt.sprite_frag},background:{uniforms:{uvTransform:{value:new $t},t2D:{value:null},backgroundIntensity:{value:1}},vertexShader:qt.background_vert,fragmentShader:qt.background_frag},backgroundCube:{uniforms:{envMap:{value:null},backgroundBlurriness:{value:0},backgroundIntensity:{value:1},backgroundRotation:{value:new $t}},vertexShader:qt.backgroundCube_vert,fragmentShader:qt.backgroundCube_frag},cube:{uniforms:{tCube:{value:null},tFlip:{value:-1},opacity:{value:1}},vertexShader:qt.cube_vert,fragmentShader:qt.cube_frag},equirect:{uniforms:{tEquirect:{value:null}},vertexShader:qt.equirect_vert,fragmentShader:qt.equirect_frag},distance:{uniforms:Bi([pt.common,pt.displacementmap,{referencePosition:{value:new R},nearDistance:{value:1},farDistance:{value:1e3}}]),vertexShader:qt.distance_vert,fragmentShader:qt.distance_frag},shadow:{uniforms:Bi([pt.lights,pt.fog,{color:{value:new st(0)},opacity:{value:1}}]),vertexShader:qt.shadow_vert,fragmentShader:qt.shadow_frag}};cs.physical={uniforms:Bi([cs.standard.uniforms,{clearcoat:{value:0},clearcoatMap:{value:null},clearcoatMapTransform:{value:new $t},clearcoatNormalMap:{value:null},clearcoatNormalMapTransform:{value:new $t},clearcoatNormalScale:{value:new Mt(1,1)},clearcoatRoughness:{value:0},clearcoatRoughnessMap:{value:null},clearcoatRoughnessMapTransform:{value:new $t},dispersion:{value:0},iridescence:{value:0},iridescenceMap:{value:null},iridescenceMapTransform:{value:new $t},iridescenceIOR:{value:1.3},iridescenceThicknessMinimum:{value:100},iridescenceThicknessMaximum:{value:400},iridescenceThicknessMap:{value:null},iridescenceThicknessMapTransform:{value:new $t},sheen:{value:0},sheenColor:{value:new st(0)},sheenColorMap:{value:null},sheenColorMapTransform:{value:new $t},sheenRoughness:{value:1},sheenRoughnessMap:{value:null},sheenRoughnessMapTransform:{value:new $t},transmission:{value:0},transmissionMap:{value:null},transmissionMapTransform:{value:new $t},transmissionSamplerSize:{value:new Mt},transmissionSamplerMap:{value:null},thickness:{value:0},thicknessMap:{value:null},thicknessMapTransform:{value:new $t},attenuationDistance:{value:0},attenuationColor:{value:new st(0)},specularColor:{value:new st(1,1,1)},specularColorMap:{value:null},specularColorMapTransform:{value:new $t},specularIntensity:{value:1},specularIntensityMap:{value:null},specularIntensityMapTransform:{value:new $t},anisotropyVector:{value:new Mt},anisotropyMap:{value:null},anisotropyMapTransform:{value:new $t}}]),vertexShader:qt.meshphysical_vert,fragmentShader:qt.meshphysical_frag};const nl={r:0,b:0,g:0},zS=new te,L1=new $t;L1.set(-1,0,0,0,1,0,0,0,1);function BS(a,t,e,i,n,s){const r=new st(0);let o=n===!0?0:1,c,l,h=null,u=0,d=null;function f(S){let x=S.isScene===!0?S.background:null;if(x&&x.isTexture){const M=S.backgroundBlurriness>0;x=t.get(x,M)}return x}function p(S){let x=!1;const M=f(S);M===null?m(r,o):M&&M.isColor&&(m(M,1),x=!0);const b=a.xr.getEnvironmentBlendMode();b==="additive"?e.buffers.color.setClear(0,0,0,1,s):b==="alpha-blend"&&e.buffers.color.setClear(0,0,0,0,s),(a.autoClear||x)&&(e.buffers.depth.setTest(!0),e.buffers.depth.setMask(!0),e.buffers.color.setMask(!0),a.clear(a.autoClearColor,a.autoClearDepth,a.autoClearStencil))}function v(S,x){const M=f(x);M&&(M.isCubeTexture||M.mapping===uh)?(l===void 0&&(l=new bt(new Ki(1,1,1),new de({name:"BackgroundCubeMaterial",uniforms:to(cs.backgroundCube.uniforms),vertexShader:cs.backgroundCube.vertexShader,fragmentShader:cs.backgroundCube.fragmentShader,side:qe,depthTest:!1,depthWrite:!1,fog:!1,allowOverride:!1})),l.geometry.deleteAttribute("normal"),l.geometry.deleteAttribute("uv"),l.onBeforeRender=function(b,w,T){this.matrixWorld.copyPosition(T.matrixWorld)},Object.defineProperty(l.material,"envMap",{get:function(){return this.uniforms.envMap.value}}),i.update(l)),l.material.uniforms.envMap.value=M,l.material.uniforms.backgroundBlurriness.value=x.backgroundBlurriness,l.material.uniforms.backgroundIntensity.value=x.backgroundIntensity,l.material.uniforms.backgroundRotation.value.setFromMatrix4(zS.makeRotationFromEuler(x.backgroundRotation)).transpose(),M.isCubeTexture&&M.isRenderTargetTexture===!1&&l.material.uniforms.backgroundRotation.value.premultiply(L1),l.material.toneMapped=ce.getTransfer(M.colorSpace)!==we,(h!==M||u!==M.version||d!==a.toneMapping)&&(l.material.needsUpdate=!0,h=M,u=M.version,d=a.toneMapping),l.layers.enableAll(),S.unshift(l,l.geometry,l.material,0,0,null)):M&&M.isTexture&&(c===void 0&&(c=new bt(new Zi(2,2),new de({name:"BackgroundMaterial",uniforms:to(cs.background.uniforms),vertexShader:cs.background.vertexShader,fragmentShader:cs.background.fragmentShader,side:pr,depthTest:!1,depthWrite:!1,fog:!1,allowOverride:!1})),c.geometry.deleteAttribute("normal"),Object.defineProperty(c.material,"map",{get:function(){return this.uniforms.t2D.value}}),i.update(c)),c.material.uniforms.t2D.value=M,c.material.uniforms.backgroundIntensity.value=x.backgroundIntensity,c.material.toneMapped=ce.getTransfer(M.colorSpace)!==we,M.matrixAutoUpdate===!0&&M.updateMatrix(),c.material.uniforms.uvTransform.value.copy(M.matrix),(h!==M||u!==M.version||d!==a.toneMapping)&&(c.material.needsUpdate=!0,h=M,u=M.version,d=a.toneMapping),c.layers.enableAll(),S.unshift(c,c.geometry,c.material,0,0,null))}function m(S,x){S.getRGB(nl,w1(a)),e.buffers.color.setClear(nl.r,nl.g,nl.b,x,s)}function g(){l!==void 0&&(l.geometry.dispose(),l.material.dispose(),l=void 0),c!==void 0&&(c.geometry.dispose(),c.material.dispose(),c=void 0)}return{getClearColor:function(){return r},setClearColor:function(S,x=1){r.set(S),o=x,m(r,o)},getClearAlpha:function(){return o},setClearAlpha:function(S){o=S,m(r,o)},render:p,addToRenderList:v,dispose:g}}function HS(a,t){const e=a.getParameter(a.MAX_VERTEX_ATTRIBS),i={},n=d(null);let s=n,r=!1;function o(I,P,V,X,L){let B=!1;const k=u(I,X,V,P);s!==k&&(s=k,l(s.object)),B=f(I,X,V,L),B&&p(I,X,V,L),L!==null&&t.update(L,a.ELEMENT_ARRAY_BUFFER),(B||r)&&(r=!1,M(I,P,V,X),L!==null&&a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,t.get(L).buffer))}function c(){return a.createVertexArray()}function l(I){return a.bindVertexArray(I)}function h(I){return a.deleteVertexArray(I)}function u(I,P,V,X){const L=X.wireframe===!0;let B=i[P.id];B===void 0&&(B={},i[P.id]=B);const k=I.isInstancedMesh===!0?I.id:0;let $=B[k];$===void 0&&($={},B[k]=$);let tt=$[V.id];tt===void 0&&(tt={},$[V.id]=tt);let J=tt[L];return J===void 0&&(J=d(c()),tt[L]=J),J}function d(I){const P=[],V=[],X=[];for(let L=0;L<e;L++)P[L]=0,V[L]=0,X[L]=0;return{geometry:null,program:null,wireframe:!1,newAttributes:P,enabledAttributes:V,attributeDivisors:X,object:I,attributes:{},index:null}}function f(I,P,V,X){const L=s.attributes,B=P.attributes;let k=0;const $=V.getAttributes();for(const tt in $)if($[tt].location>=0){const it=L[tt];let at=B[tt];if(at===void 0&&(tt==="instanceMatrix"&&I.instanceMatrix&&(at=I.instanceMatrix),tt==="instanceColor"&&I.instanceColor&&(at=I.instanceColor)),it===void 0||it.attribute!==at||at&&it.data!==at.data)return!0;k++}return s.attributesNum!==k||s.index!==X}function p(I,P,V,X){const L={},B=P.attributes;let k=0;const $=V.getAttributes();for(const tt in $)if($[tt].location>=0){let it=B[tt];it===void 0&&(tt==="instanceMatrix"&&I.instanceMatrix&&(it=I.instanceMatrix),tt==="instanceColor"&&I.instanceColor&&(it=I.instanceColor));const at={};at.attribute=it,it&&it.data&&(at.data=it.data),L[tt]=at,k++}s.attributes=L,s.attributesNum=k,s.index=X}function v(){const I=s.newAttributes;for(let P=0,V=I.length;P<V;P++)I[P]=0}function m(I){g(I,0)}function g(I,P){const V=s.newAttributes,X=s.enabledAttributes,L=s.attributeDivisors;V[I]=1,X[I]===0&&(a.enableVertexAttribArray(I),X[I]=1),L[I]!==P&&(a.vertexAttribDivisor(I,P),L[I]=P)}function S(){const I=s.newAttributes,P=s.enabledAttributes;for(let V=0,X=P.length;V<X;V++)P[V]!==I[V]&&(a.disableVertexAttribArray(V),P[V]=0)}function x(I,P,V,X,L,B,k){k===!0?a.vertexAttribIPointer(I,P,V,L,B):a.vertexAttribPointer(I,P,V,X,L,B)}function M(I,P,V,X){v();const L=X.attributes,B=V.getAttributes(),k=P.defaultAttributeValues;for(const $ in B){const tt=B[$];if(tt.location>=0){let J=L[$];if(J===void 0&&($==="instanceMatrix"&&I.instanceMatrix&&(J=I.instanceMatrix),$==="instanceColor"&&I.instanceColor&&(J=I.instanceColor)),J!==void 0){const it=J.normalized,at=J.itemSize,Xt=t.get(J);if(Xt===void 0)continue;const ee=Xt.buffer,Kt=Xt.type,q=Xt.bytesPerElement,rt=Kt===a.INT||Kt===a.UNSIGNED_INT||J.gpuType===R0;if(J.isInterleavedBufferAttribute){const nt=J.data,z=nt.stride,Rt=J.offset;if(nt.isInstancedInterleavedBuffer){for(let Ft=0;Ft<tt.locationSize;Ft++)g(tt.location+Ft,nt.meshPerAttribute);I.isInstancedMesh!==!0&&X._maxInstanceCount===void 0&&(X._maxInstanceCount=nt.meshPerAttribute*nt.count)}else for(let Ft=0;Ft<tt.locationSize;Ft++)m(tt.location+Ft);a.bindBuffer(a.ARRAY_BUFFER,ee);for(let Ft=0;Ft<tt.locationSize;Ft++)x(tt.location+Ft,at/tt.locationSize,Kt,it,z*q,(Rt+at/tt.locationSize*Ft)*q,rt)}else{if(J.isInstancedBufferAttribute){for(let nt=0;nt<tt.locationSize;nt++)g(tt.location+nt,J.meshPerAttribute);I.isInstancedMesh!==!0&&X._maxInstanceCount===void 0&&(X._maxInstanceCount=J.meshPerAttribute*J.count)}else for(let nt=0;nt<tt.locationSize;nt++)m(tt.location+nt);a.bindBuffer(a.ARRAY_BUFFER,ee);for(let nt=0;nt<tt.locationSize;nt++)x(tt.location+nt,at/tt.locationSize,Kt,it,at*q,at/tt.locationSize*nt*q,rt)}}else if(k!==void 0){const it=k[$];if(it!==void 0)switch(it.length){case 2:a.vertexAttrib2fv(tt.location,it);break;case 3:a.vertexAttrib3fv(tt.location,it);break;case 4:a.vertexAttrib4fv(tt.location,it);break;default:a.vertexAttrib1fv(tt.location,it)}}}}S()}function b(){A();for(const I in i){const P=i[I];for(const V in P){const X=P[V];for(const L in X){const B=X[L];for(const k in B)h(B[k].object),delete B[k];delete X[L]}}delete i[I]}}function w(I){if(i[I.id]===void 0)return;const P=i[I.id];for(const V in P){const X=P[V];for(const L in X){const B=X[L];for(const k in B)h(B[k].object),delete B[k];delete X[L]}}delete i[I.id]}function T(I){for(const P in i){const V=i[P];for(const X in V){const L=V[X];if(L[I.id]===void 0)continue;const B=L[I.id];for(const k in B)h(B[k].object),delete B[k];delete L[I.id]}}}function y(I){for(const P in i){const V=i[P],X=I.isInstancedMesh===!0?I.id:0,L=V[X];if(L!==void 0){for(const B in L){const k=L[B];for(const $ in k)h(k[$].object),delete k[$];delete L[B]}delete V[X],Object.keys(V).length===0&&delete i[P]}}}function A(){C(),r=!0,s!==n&&(s=n,l(s.object))}function C(){n.geometry=null,n.program=null,n.wireframe=!1}return{setup:o,reset:A,resetDefaultState:C,dispose:b,releaseStatesOfGeometry:w,releaseStatesOfObject:y,releaseStatesOfProgram:T,initAttributes:v,enableAttribute:m,disableUnusedAttributes:S}}function GS(a,t,e){let i;function n(c){i=c}function s(c,l){a.drawArrays(i,c,l),e.update(l,i,1)}function r(c,l,h){h!==0&&(a.drawArraysInstanced(i,c,l,h),e.update(l,i,h))}function o(c,l,h){if(h===0)return;t.get("WEBGL_multi_draw").multiDrawArraysWEBGL(i,c,0,l,0,h);let d=0;for(let f=0;f<h;f++)d+=l[f];e.update(d,i,1)}this.setMode=n,this.render=s,this.renderInstances=r,this.renderMultiDraw=o}function VS(a,t,e,i){let n;function s(){if(n!==void 0)return n;if(t.has("EXT_texture_filter_anisotropic")===!0){const T=t.get("EXT_texture_filter_anisotropic");n=a.getParameter(T.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else n=0;return n}function r(T){return!(T!==Di&&i.convert(T)!==a.getParameter(a.IMPLEMENTATION_COLOR_READ_FORMAT))}function o(T){const y=T===$e&&(t.has("EXT_color_buffer_half_float")||t.has("EXT_color_buffer_float"));return!(T!==yn&&i.convert(T)!==a.getParameter(a.IMPLEMENTATION_COLOR_READ_TYPE)&&T!==Ui&&!y)}function c(T){if(T==="highp"){if(a.getShaderPrecisionFormat(a.VERTEX_SHADER,a.HIGH_FLOAT).precision>0&&a.getShaderPrecisionFormat(a.FRAGMENT_SHADER,a.HIGH_FLOAT).precision>0)return"highp";T="mediump"}return T==="mediump"&&a.getShaderPrecisionFormat(a.VERTEX_SHADER,a.MEDIUM_FLOAT).precision>0&&a.getShaderPrecisionFormat(a.FRAGMENT_SHADER,a.MEDIUM_FLOAT).precision>0?"mediump":"lowp"}let l=e.precision!==void 0?e.precision:"highp";const h=c(l);h!==l&&(It("WebGLRenderer:",l,"not supported, using",h,"instead."),l=h);const u=e.logarithmicDepthBuffer===!0,d=e.reversedDepthBuffer===!0&&t.has("EXT_clip_control");e.reversedDepthBuffer===!0&&d===!1&&It("WebGLRenderer: Unable to use reversed depth buffer due to missing EXT_clip_control extension. Fallback to default depth buffer.");const f=a.getParameter(a.MAX_TEXTURE_IMAGE_UNITS),p=a.getParameter(a.MAX_VERTEX_TEXTURE_IMAGE_UNITS),v=a.getParameter(a.MAX_TEXTURE_SIZE),m=a.getParameter(a.MAX_CUBE_MAP_TEXTURE_SIZE),g=a.getParameter(a.MAX_VERTEX_ATTRIBS),S=a.getParameter(a.MAX_VERTEX_UNIFORM_VECTORS),x=a.getParameter(a.MAX_VARYING_VECTORS),M=a.getParameter(a.MAX_FRAGMENT_UNIFORM_VECTORS),b=a.getParameter(a.MAX_SAMPLES),w=a.getParameter(a.SAMPLES);return{isWebGL2:!0,getMaxAnisotropy:s,getMaxPrecision:c,textureFormatReadable:r,textureTypeReadable:o,precision:l,logarithmicDepthBuffer:u,reversedDepthBuffer:d,maxTextures:f,maxVertexTextures:p,maxTextureSize:v,maxCubemapSize:m,maxAttributes:g,maxVertexUniforms:S,maxVaryings:x,maxFragmentUniforms:M,maxSamples:b,samples:w}}function WS(a){const t=this;let e=null,i=0,n=!1,s=!1;const r=new er,o=new $t,c={value:null,needsUpdate:!1};this.uniform=c,this.numPlanes=0,this.numIntersection=0,this.init=function(u,d){const f=u.length!==0||d||i!==0||n;return n=d,i=u.length,f},this.beginShadows=function(){s=!0,h(null)},this.endShadows=function(){s=!1},this.setGlobalState=function(u,d){e=h(u,d,0)},this.setState=function(u,d,f){const p=u.clippingPlanes,v=u.clipIntersection,m=u.clipShadows,g=a.get(u);if(!n||p===null||p.length===0||s&&!m)s?h(null):l();else{const S=s?0:i,x=S*4;let M=g.clippingState||null;c.value=M,M=h(p,d,x,f);for(let b=0;b!==x;++b)M[b]=e[b];g.clippingState=M,this.numIntersection=v?this.numPlanes:0,this.numPlanes+=S}};function l(){c.value!==e&&(c.value=e,c.needsUpdate=i>0),t.numPlanes=i,t.numIntersection=0}function h(u,d,f,p){const v=u!==null?u.length:0;let m=null;if(v!==0){if(m=c.value,p!==!0||m===null){const g=f+v*4,S=d.matrixWorldInverse;o.getNormalMatrix(S),(m===null||m.length<g)&&(m=new Float32Array(g));for(let x=0,M=f;x!==v;++x,M+=4)r.copy(u[x]).applyMatrix4(S,o),r.normal.toArray(m,M),m[M+3]=r.constant}c.value=m,c.needsUpdate=!0}return t.numPlanes=v,t.numIntersection=0,m}}const cr=4,Kp=[.125,.215,.35,.446,.526,.582],Ir=20,XS=256,So=new Zn,Zp=new st;let cu=null,lu=0,hu=0,uu=!1;const YS=new R;class Wd{constructor(t){this._renderer=t,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(t,e=0,i=.1,n=100,s={}){const{size:r=256,position:o=YS}=s;cu=this._renderer.getRenderTarget(),lu=this._renderer.getActiveCubeFace(),hu=this._renderer.getActiveMipmapLevel(),uu=this._renderer.xr.enabled,this._renderer.xr.enabled=!1,this._setSize(r);const c=this._allocateTargets();return c.depthBuffer=!0,this._sceneToCubeUV(t,i,n,c,o),e>0&&this._blur(c,0,0,e),this._applyPMREM(c),this._cleanup(c),c}fromEquirectangular(t,e=null){return this._fromTexture(t,e)}fromCubemap(t,e=null){return this._fromTexture(t,e)}compileCubemapShader(){this._cubemapMaterial===null&&(this._cubemapMaterial=Qp(),this._compileMaterial(this._cubemapMaterial))}compileEquirectangularShader(){this._equirectMaterial===null&&(this._equirectMaterial=jp(),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(t){this._lodMax=Math.floor(Math.log2(t)),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 t=0;t<this._lodMeshes.length;t++)this._lodMeshes[t].geometry.dispose()}_cleanup(t){this._renderer.setRenderTarget(cu,lu,hu),this._renderer.xr.enabled=uu,t.scissorTest=!1,Sa(t,0,0,t.width,t.height)}_fromTexture(t,e){t.mapping===Xr||t.mapping===ja?this._setSize(t.image.length===0?16:t.image[0].width||t.image[0].image.width):this._setSize(t.image.width/4),cu=this._renderer.getRenderTarget(),lu=this._renderer.getActiveCubeFace(),hu=this._renderer.getActiveMipmapLevel(),uu=this._renderer.xr.enabled,this._renderer.xr.enabled=!1;const i=e||this._allocateTargets();return this._textureToCubeUV(t,i),this._applyPMREM(i),this._cleanup(i),i}_allocateTargets(){const t=3*Math.max(this._cubeSize,112),e=4*this._cubeSize,i={magFilter:le,minFilter:le,generateMipmaps:!1,type:$e,format:Di,colorSpace:Vl,depthBuffer:!1},n=Jp(t,e,i);if(this._pingPongRenderTarget===null||this._pingPongRenderTarget.width!==t||this._pingPongRenderTarget.height!==e){this._pingPongRenderTarget!==null&&this._dispose(),this._pingPongRenderTarget=Jp(t,e,i);const{_lodMax:s}=this;({lodMeshes:this._lodMeshes,sizeLods:this._sizeLods,sigmas:this._sigmas}=qS(s)),this._blurMaterial=KS(s,t,e),this._ggxMaterial=$S(s,t,e)}return n}_compileMaterial(t){const e=new bt(new se,t);this._renderer.compile(e,So)}_sceneToCubeUV(t,e,i,n,s){const c=new rn(90,1,e,i),l=[1,-1,1,1,1,1],h=[1,1,1,-1,-1,-1],u=this._renderer,d=u.autoClear,f=u.toneMapping;u.getClearColor(Zp),u.toneMapping=Ms,u.autoClear=!1,u.state.buffers.depth.getReversed()&&(u.setRenderTarget(n),u.clearDepth(),u.setRenderTarget(null)),this._backgroundBox===null&&(this._backgroundBox=new bt(new Ki,new _n({name:"PMREM.Background",side:qe,depthWrite:!1,depthTest:!1})));const v=this._backgroundBox,m=v.material;let g=!1;const S=t.background;S?S.isColor&&(m.color.copy(S),t.background=null,g=!0):(m.color.copy(Zp),g=!0);for(let x=0;x<6;x++){const M=x%3;M===0?(c.up.set(0,l[x],0),c.position.set(s.x,s.y,s.z),c.lookAt(s.x+h[x],s.y,s.z)):M===1?(c.up.set(0,0,l[x]),c.position.set(s.x,s.y,s.z),c.lookAt(s.x,s.y+h[x],s.z)):(c.up.set(0,l[x],0),c.position.set(s.x,s.y,s.z),c.lookAt(s.x,s.y,s.z+h[x]));const b=this._cubeSize;Sa(n,M*b,x>2?b:0,b,b),u.setRenderTarget(n),g&&u.render(v,c),u.render(t,c)}u.toneMapping=f,u.autoClear=d,t.background=S}_textureToCubeUV(t,e){const i=this._renderer,n=t.mapping===Xr||t.mapping===ja;n?(this._cubemapMaterial===null&&(this._cubemapMaterial=Qp()),this._cubemapMaterial.uniforms.flipEnvMap.value=t.isRenderTargetTexture===!1?-1:1):this._equirectMaterial===null&&(this._equirectMaterial=jp());const s=n?this._cubemapMaterial:this._equirectMaterial,r=this._lodMeshes[0];r.material=s;const o=s.uniforms;o.envMap.value=t;const c=this._cubeSize;Sa(e,0,0,3*c,2*c),i.setRenderTarget(e),i.render(r,So)}_applyPMREM(t){const e=this._renderer,i=e.autoClear;e.autoClear=!1;const n=this._lodMeshes.length;for(let s=1;s<n;s++)this._applyGGXFilter(t,s-1,s);e.autoClear=i}_applyGGXFilter(t,e,i){const n=this._renderer,s=this._pingPongRenderTarget,r=this._ggxMaterial,o=this._lodMeshes[i];o.material=r;const c=r.uniforms,l=i/(this._lodMeshes.length-1),h=e/(this._lodMeshes.length-1),u=Math.sqrt(l*l-h*h),d=0+l*1.25,f=u*d,{_lodMax:p}=this,v=this._sizeLods[i],m=3*v*(i>p-cr?i-p+cr:0),g=4*(this._cubeSize-v);c.envMap.value=t.texture,c.roughness.value=f,c.mipInt.value=p-e,Sa(s,m,g,3*v,2*v),n.setRenderTarget(s),n.render(o,So),c.envMap.value=s.texture,c.roughness.value=0,c.mipInt.value=p-i,Sa(t,m,g,3*v,2*v),n.setRenderTarget(t),n.render(o,So)}_blur(t,e,i,n,s){const r=this._pingPongRenderTarget;this._halfBlur(t,r,e,i,n,"latitudinal",s),this._halfBlur(r,t,i,i,n,"longitudinal",s)}_halfBlur(t,e,i,n,s,r,o){const c=this._renderer,l=this._blurMaterial;r!=="latitudinal"&&r!=="longitudinal"&&Wt("blur direction must be either latitudinal or longitudinal!");const h=3,u=this._lodMeshes[n];u.material=l;const d=l.uniforms,f=this._sizeLods[i]-1,p=isFinite(s)?Math.PI/(2*f):2*Math.PI/(2*Ir-1),v=s/p,m=isFinite(s)?1+Math.floor(h*v):Ir;m>Ir&&It(`sigmaRadians, ${s}, is too large and will clip, as it requested ${m} samples when the maximum is set to ${Ir}`);const g=[];let S=0;for(let T=0;T<Ir;++T){const y=T/v,A=Math.exp(-y*y/2);g.push(A),T===0?S+=A:T<m&&(S+=2*A)}for(let T=0;T<g.length;T++)g[T]=g[T]/S;d.envMap.value=t.texture,d.samples.value=m,d.weights.value=g,d.latitudinal.value=r==="latitudinal",o&&(d.poleAxis.value=o);const{_lodMax:x}=this;d.dTheta.value=p,d.mipInt.value=x-i;const M=this._sizeLods[n],b=3*M*(n>x-cr?n-x+cr:0),w=4*(this._cubeSize-M);Sa(e,b,w,3*M,2*M),c.setRenderTarget(e),c.render(u,So)}}function qS(a){const t=[],e=[],i=[];let n=a;const s=a-cr+1+Kp.length;for(let r=0;r<s;r++){const o=Math.pow(2,n);t.push(o);let c=1/o;r>a-cr?c=Kp[r-a+cr-1]:r===0&&(c=0),e.push(c);const l=1/(o-2),h=-l,u=1+l,d=[h,h,u,h,u,u,h,h,u,u,h,u],f=6,p=6,v=3,m=2,g=1,S=new Float32Array(v*p*f),x=new Float32Array(m*p*f),M=new Float32Array(g*p*f);for(let w=0;w<f;w++){const T=w%3*2/3-1,y=w>2?0:-1,A=[T,y,0,T+2/3,y,0,T+2/3,y+1,0,T,y,0,T+2/3,y+1,0,T,y+1,0];S.set(A,v*p*w),x.set(d,m*p*w);const C=[w,w,w,w,w,w];M.set(C,g*p*w)}const b=new se;b.setAttribute("position",new Jt(S,v)),b.setAttribute("uv",new Jt(x,m)),b.setAttribute("faceIndex",new Jt(M,g)),i.push(new bt(b,null)),n>cr&&n--}return{lodMeshes:i,sizeLods:t,sigmas:e}}function Jp(a,t,e){const i=new Qe(a,t,e);return i.texture.mapping=uh,i.texture.name="PMREM.cubeUv",i.scissorTest=!0,i}function Sa(a,t,e,i,n){a.viewport.set(t,e,i,n),a.scissor.set(t,e,i,n)}function $S(a,t,e){return new de({name:"PMREMGGXConvolution",defines:{GGX_SAMPLES:XS,CUBEUV_TEXEL_WIDTH:1/t,CUBEUV_TEXEL_HEIGHT:1/e,CUBEUV_MAX_MIP:`${a}.0`},uniforms:{envMap:{value:null},roughness:{value:0},mipInt:{value:0}},vertexShader:mh(),fragmentShader:`
5090
+ }`,qt={alphahash_fragment:ry,alphahash_pars_fragment:ay,alphamap_fragment:oy,alphamap_pars_fragment:cy,alphatest_fragment:ly,alphatest_pars_fragment:hy,aomap_fragment:uy,aomap_pars_fragment:dy,batching_pars_vertex:fy,batching_vertex:py,begin_vertex:my,beginnormal_vertex:gy,bsdfs:vy,iridescence_fragment:My,bumpmap_pars_fragment:xy,clipping_planes_fragment:yy,clipping_planes_pars_fragment:Sy,clipping_planes_pars_vertex:_y,clipping_planes_vertex:by,color_fragment:wy,color_pars_fragment:Ey,color_pars_vertex:Ay,color_vertex:Ty,common:Ry,cube_uv_reflection_fragment:Dy,defaultnormal_vertex:Iy,displacementmap_pars_vertex:Cy,displacementmap_vertex:Py,emissivemap_fragment:Ly,emissivemap_pars_fragment:Oy,colorspace_fragment:Ny,colorspace_pars_fragment:Fy,envmap_fragment:Uy,envmap_common_pars_fragment:ky,envmap_pars_fragment:zy,envmap_pars_vertex:By,envmap_physical_pars_fragment:Jy,envmap_vertex:Hy,fog_vertex:Gy,fog_pars_vertex:Vy,fog_fragment:Wy,fog_pars_fragment:Xy,gradientmap_pars_fragment:Yy,lightmap_pars_fragment:qy,lights_lambert_fragment:$y,lights_lambert_pars_fragment:Ky,lights_pars_begin:Zy,lights_toon_fragment:jy,lights_toon_pars_fragment:Qy,lights_phong_fragment:t3,lights_phong_pars_fragment:e3,lights_physical_fragment:i3,lights_physical_pars_fragment:n3,lights_fragment_begin:s3,lights_fragment_maps:r3,lights_fragment_end:a3,lightprobes_pars_fragment:o3,logdepthbuf_fragment:c3,logdepthbuf_pars_fragment:l3,logdepthbuf_pars_vertex:h3,logdepthbuf_vertex:u3,map_fragment:d3,map_pars_fragment:f3,map_particle_fragment:p3,map_particle_pars_fragment:m3,metalnessmap_fragment:g3,metalnessmap_pars_fragment:v3,morphinstance_vertex:M3,morphcolor_vertex:x3,morphnormal_vertex:y3,morphtarget_pars_vertex:S3,morphtarget_vertex:_3,normal_fragment_begin:b3,normal_fragment_maps:w3,normal_pars_fragment:E3,normal_pars_vertex:A3,normal_vertex:T3,normalmap_pars_fragment:R3,clearcoat_normal_fragment_begin:D3,clearcoat_normal_fragment_maps:I3,clearcoat_pars_fragment:C3,iridescence_pars_fragment:P3,opaque_fragment:L3,packing:O3,premultiplied_alpha_fragment:N3,project_vertex:F3,dithering_fragment:U3,dithering_pars_fragment:k3,roughnessmap_fragment:z3,roughnessmap_pars_fragment:B3,shadowmap_pars_fragment:H3,shadowmap_pars_vertex:G3,shadowmap_vertex:V3,shadowmask_pars_fragment:W3,skinbase_vertex:X3,skinning_pars_vertex:Y3,skinning_vertex:q3,skinnormal_vertex:$3,specularmap_fragment:K3,specularmap_pars_fragment:Z3,tonemapping_fragment:J3,tonemapping_pars_fragment:j3,transmission_fragment:Q3,transmission_pars_fragment:tS,uv_pars_fragment:eS,uv_pars_vertex:iS,uv_vertex:nS,worldpos_vertex:sS,background_vert:rS,background_frag:aS,backgroundCube_vert:oS,backgroundCube_frag:cS,cube_vert:lS,cube_frag:hS,depth_vert:uS,depth_frag:dS,distance_vert:fS,distance_frag:pS,equirect_vert:mS,equirect_frag:gS,linedashed_vert:vS,linedashed_frag:MS,meshbasic_vert:xS,meshbasic_frag:yS,meshlambert_vert:SS,meshlambert_frag:_S,meshmatcap_vert:bS,meshmatcap_frag:wS,meshnormal_vert:ES,meshnormal_frag:AS,meshphong_vert:TS,meshphong_frag:RS,meshphysical_vert:DS,meshphysical_frag:IS,meshtoon_vert:CS,meshtoon_frag:PS,points_vert:LS,points_frag:OS,shadow_vert:NS,shadow_frag:FS,sprite_vert:US,sprite_frag:kS},pt={common:{diffuse:{value:new st(16777215)},opacity:{value:1},map:{value:null},mapTransform:{value:new $t},alphaMap:{value:null},alphaMapTransform:{value:new $t},alphaTest:{value:0}},specularmap:{specularMap:{value:null},specularMapTransform:{value:new $t}},envmap:{envMap:{value:null},envMapRotation:{value:new $t},reflectivity:{value:1},ior:{value:1.5},refractionRatio:{value:.98},dfgLUT:{value:null}},aomap:{aoMap:{value:null},aoMapIntensity:{value:1},aoMapTransform:{value:new $t}},lightmap:{lightMap:{value:null},lightMapIntensity:{value:1},lightMapTransform:{value:new $t}},bumpmap:{bumpMap:{value:null},bumpMapTransform:{value:new $t},bumpScale:{value:1}},normalmap:{normalMap:{value:null},normalMapTransform:{value:new $t},normalScale:{value:new Mt(1,1)}},displacementmap:{displacementMap:{value:null},displacementMapTransform:{value:new $t},displacementScale:{value:1},displacementBias:{value:0}},emissivemap:{emissiveMap:{value:null},emissiveMapTransform:{value:new $t}},metalnessmap:{metalnessMap:{value:null},metalnessMapTransform:{value:new $t}},roughnessmap:{roughnessMap:{value:null},roughnessMapTransform:{value:new $t}},gradientmap:{gradientMap:{value:null}},fog:{fogDensity:{value:25e-5},fogNear:{value:1},fogFar:{value:2e3},fogColor:{value:new st(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 R},probesMax:{value:new R},probesResolution:{value:new R}},points:{diffuse:{value:new st(16777215)},opacity:{value:1},size:{value:1},scale:{value:1},map:{value:null},alphaMap:{value:null},alphaMapTransform:{value:new $t},alphaTest:{value:0},uvTransform:{value:new $t}},sprite:{diffuse:{value:new st(16777215)},opacity:{value:1},center:{value:new Mt(.5,.5)},rotation:{value:0},map:{value:null},mapTransform:{value:new $t},alphaMap:{value:null},alphaMapTransform:{value:new $t},alphaTest:{value:0}}},cs={basic:{uniforms:Bi([pt.common,pt.specularmap,pt.envmap,pt.aomap,pt.lightmap,pt.fog]),vertexShader:qt.meshbasic_vert,fragmentShader:qt.meshbasic_frag},lambert:{uniforms:Bi([pt.common,pt.specularmap,pt.envmap,pt.aomap,pt.lightmap,pt.emissivemap,pt.bumpmap,pt.normalmap,pt.displacementmap,pt.fog,pt.lights,{emissive:{value:new st(0)},envMapIntensity:{value:1}}]),vertexShader:qt.meshlambert_vert,fragmentShader:qt.meshlambert_frag},phong:{uniforms:Bi([pt.common,pt.specularmap,pt.envmap,pt.aomap,pt.lightmap,pt.emissivemap,pt.bumpmap,pt.normalmap,pt.displacementmap,pt.fog,pt.lights,{emissive:{value:new st(0)},specular:{value:new st(1118481)},shininess:{value:30},envMapIntensity:{value:1}}]),vertexShader:qt.meshphong_vert,fragmentShader:qt.meshphong_frag},standard:{uniforms:Bi([pt.common,pt.envmap,pt.aomap,pt.lightmap,pt.emissivemap,pt.bumpmap,pt.normalmap,pt.displacementmap,pt.roughnessmap,pt.metalnessmap,pt.fog,pt.lights,{emissive:{value:new st(0)},roughness:{value:1},metalness:{value:0},envMapIntensity:{value:1}}]),vertexShader:qt.meshphysical_vert,fragmentShader:qt.meshphysical_frag},toon:{uniforms:Bi([pt.common,pt.aomap,pt.lightmap,pt.emissivemap,pt.bumpmap,pt.normalmap,pt.displacementmap,pt.gradientmap,pt.fog,pt.lights,{emissive:{value:new st(0)}}]),vertexShader:qt.meshtoon_vert,fragmentShader:qt.meshtoon_frag},matcap:{uniforms:Bi([pt.common,pt.bumpmap,pt.normalmap,pt.displacementmap,pt.fog,{matcap:{value:null}}]),vertexShader:qt.meshmatcap_vert,fragmentShader:qt.meshmatcap_frag},points:{uniforms:Bi([pt.points,pt.fog]),vertexShader:qt.points_vert,fragmentShader:qt.points_frag},dashed:{uniforms:Bi([pt.common,pt.fog,{scale:{value:1},dashSize:{value:1},totalSize:{value:2}}]),vertexShader:qt.linedashed_vert,fragmentShader:qt.linedashed_frag},depth:{uniforms:Bi([pt.common,pt.displacementmap]),vertexShader:qt.depth_vert,fragmentShader:qt.depth_frag},normal:{uniforms:Bi([pt.common,pt.bumpmap,pt.normalmap,pt.displacementmap,{opacity:{value:1}}]),vertexShader:qt.meshnormal_vert,fragmentShader:qt.meshnormal_frag},sprite:{uniforms:Bi([pt.sprite,pt.fog]),vertexShader:qt.sprite_vert,fragmentShader:qt.sprite_frag},background:{uniforms:{uvTransform:{value:new $t},t2D:{value:null},backgroundIntensity:{value:1}},vertexShader:qt.background_vert,fragmentShader:qt.background_frag},backgroundCube:{uniforms:{envMap:{value:null},backgroundBlurriness:{value:0},backgroundIntensity:{value:1},backgroundRotation:{value:new $t}},vertexShader:qt.backgroundCube_vert,fragmentShader:qt.backgroundCube_frag},cube:{uniforms:{tCube:{value:null},tFlip:{value:-1},opacity:{value:1}},vertexShader:qt.cube_vert,fragmentShader:qt.cube_frag},equirect:{uniforms:{tEquirect:{value:null}},vertexShader:qt.equirect_vert,fragmentShader:qt.equirect_frag},distance:{uniforms:Bi([pt.common,pt.displacementmap,{referencePosition:{value:new R},nearDistance:{value:1},farDistance:{value:1e3}}]),vertexShader:qt.distance_vert,fragmentShader:qt.distance_frag},shadow:{uniforms:Bi([pt.lights,pt.fog,{color:{value:new st(0)},opacity:{value:1}}]),vertexShader:qt.shadow_vert,fragmentShader:qt.shadow_frag}};cs.physical={uniforms:Bi([cs.standard.uniforms,{clearcoat:{value:0},clearcoatMap:{value:null},clearcoatMapTransform:{value:new $t},clearcoatNormalMap:{value:null},clearcoatNormalMapTransform:{value:new $t},clearcoatNormalScale:{value:new Mt(1,1)},clearcoatRoughness:{value:0},clearcoatRoughnessMap:{value:null},clearcoatRoughnessMapTransform:{value:new $t},dispersion:{value:0},iridescence:{value:0},iridescenceMap:{value:null},iridescenceMapTransform:{value:new $t},iridescenceIOR:{value:1.3},iridescenceThicknessMinimum:{value:100},iridescenceThicknessMaximum:{value:400},iridescenceThicknessMap:{value:null},iridescenceThicknessMapTransform:{value:new $t},sheen:{value:0},sheenColor:{value:new st(0)},sheenColorMap:{value:null},sheenColorMapTransform:{value:new $t},sheenRoughness:{value:1},sheenRoughnessMap:{value:null},sheenRoughnessMapTransform:{value:new $t},transmission:{value:0},transmissionMap:{value:null},transmissionMapTransform:{value:new $t},transmissionSamplerSize:{value:new Mt},transmissionSamplerMap:{value:null},thickness:{value:0},thicknessMap:{value:null},thicknessMapTransform:{value:new $t},attenuationDistance:{value:0},attenuationColor:{value:new st(0)},specularColor:{value:new st(1,1,1)},specularColorMap:{value:null},specularColorMapTransform:{value:new $t},specularIntensity:{value:1},specularIntensityMap:{value:null},specularIntensityMapTransform:{value:new $t},anisotropyVector:{value:new Mt},anisotropyMap:{value:null},anisotropyMapTransform:{value:new $t}}]),vertexShader:qt.meshphysical_vert,fragmentShader:qt.meshphysical_frag};const nl={r:0,b:0,g:0},zS=new te,L1=new $t;L1.set(-1,0,0,0,1,0,0,0,1);function BS(a,t,e,i,n,s){const r=new st(0);let o=n===!0?0:1,c,l,h=null,u=0,d=null;function f(S){let x=S.isScene===!0?S.background:null;if(x&&x.isTexture){const M=S.backgroundBlurriness>0;x=t.get(x,M)}return x}function p(S){let x=!1;const M=f(S);M===null?m(r,o):M&&M.isColor&&(m(M,1),x=!0);const b=a.xr.getEnvironmentBlendMode();b==="additive"?e.buffers.color.setClear(0,0,0,1,s):b==="alpha-blend"&&e.buffers.color.setClear(0,0,0,0,s),(a.autoClear||x)&&(e.buffers.depth.setTest(!0),e.buffers.depth.setMask(!0),e.buffers.color.setMask(!0),a.clear(a.autoClearColor,a.autoClearDepth,a.autoClearStencil))}function v(S,x){const M=f(x);M&&(M.isCubeTexture||M.mapping===uh)?(l===void 0&&(l=new bt(new Ki(1,1,1),new fe({name:"BackgroundCubeMaterial",uniforms:to(cs.backgroundCube.uniforms),vertexShader:cs.backgroundCube.vertexShader,fragmentShader:cs.backgroundCube.fragmentShader,side:qe,depthTest:!1,depthWrite:!1,fog:!1,allowOverride:!1})),l.geometry.deleteAttribute("normal"),l.geometry.deleteAttribute("uv"),l.onBeforeRender=function(b,w,T){this.matrixWorld.copyPosition(T.matrixWorld)},Object.defineProperty(l.material,"envMap",{get:function(){return this.uniforms.envMap.value}}),i.update(l)),l.material.uniforms.envMap.value=M,l.material.uniforms.backgroundBlurriness.value=x.backgroundBlurriness,l.material.uniforms.backgroundIntensity.value=x.backgroundIntensity,l.material.uniforms.backgroundRotation.value.setFromMatrix4(zS.makeRotationFromEuler(x.backgroundRotation)).transpose(),M.isCubeTexture&&M.isRenderTargetTexture===!1&&l.material.uniforms.backgroundRotation.value.premultiply(L1),l.material.toneMapped=ce.getTransfer(M.colorSpace)!==we,(h!==M||u!==M.version||d!==a.toneMapping)&&(l.material.needsUpdate=!0,h=M,u=M.version,d=a.toneMapping),l.layers.enableAll(),S.unshift(l,l.geometry,l.material,0,0,null)):M&&M.isTexture&&(c===void 0&&(c=new bt(new Zi(2,2),new fe({name:"BackgroundMaterial",uniforms:to(cs.background.uniforms),vertexShader:cs.background.vertexShader,fragmentShader:cs.background.fragmentShader,side:pr,depthTest:!1,depthWrite:!1,fog:!1,allowOverride:!1})),c.geometry.deleteAttribute("normal"),Object.defineProperty(c.material,"map",{get:function(){return this.uniforms.t2D.value}}),i.update(c)),c.material.uniforms.t2D.value=M,c.material.uniforms.backgroundIntensity.value=x.backgroundIntensity,c.material.toneMapped=ce.getTransfer(M.colorSpace)!==we,M.matrixAutoUpdate===!0&&M.updateMatrix(),c.material.uniforms.uvTransform.value.copy(M.matrix),(h!==M||u!==M.version||d!==a.toneMapping)&&(c.material.needsUpdate=!0,h=M,u=M.version,d=a.toneMapping),c.layers.enableAll(),S.unshift(c,c.geometry,c.material,0,0,null))}function m(S,x){S.getRGB(nl,w1(a)),e.buffers.color.setClear(nl.r,nl.g,nl.b,x,s)}function g(){l!==void 0&&(l.geometry.dispose(),l.material.dispose(),l=void 0),c!==void 0&&(c.geometry.dispose(),c.material.dispose(),c=void 0)}return{getClearColor:function(){return r},setClearColor:function(S,x=1){r.set(S),o=x,m(r,o)},getClearAlpha:function(){return o},setClearAlpha:function(S){o=S,m(r,o)},render:p,addToRenderList:v,dispose:g}}function HS(a,t){const e=a.getParameter(a.MAX_VERTEX_ATTRIBS),i={},n=d(null);let s=n,r=!1;function o(I,P,V,X,L){let B=!1;const k=u(I,X,V,P);s!==k&&(s=k,l(s.object)),B=f(I,X,V,L),B&&p(I,X,V,L),L!==null&&t.update(L,a.ELEMENT_ARRAY_BUFFER),(B||r)&&(r=!1,M(I,P,V,X),L!==null&&a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,t.get(L).buffer))}function c(){return a.createVertexArray()}function l(I){return a.bindVertexArray(I)}function h(I){return a.deleteVertexArray(I)}function u(I,P,V,X){const L=X.wireframe===!0;let B=i[P.id];B===void 0&&(B={},i[P.id]=B);const k=I.isInstancedMesh===!0?I.id:0;let $=B[k];$===void 0&&($={},B[k]=$);let tt=$[V.id];tt===void 0&&(tt={},$[V.id]=tt);let J=tt[L];return J===void 0&&(J=d(c()),tt[L]=J),J}function d(I){const P=[],V=[],X=[];for(let L=0;L<e;L++)P[L]=0,V[L]=0,X[L]=0;return{geometry:null,program:null,wireframe:!1,newAttributes:P,enabledAttributes:V,attributeDivisors:X,object:I,attributes:{},index:null}}function f(I,P,V,X){const L=s.attributes,B=P.attributes;let k=0;const $=V.getAttributes();for(const tt in $)if($[tt].location>=0){const it=L[tt];let at=B[tt];if(at===void 0&&(tt==="instanceMatrix"&&I.instanceMatrix&&(at=I.instanceMatrix),tt==="instanceColor"&&I.instanceColor&&(at=I.instanceColor)),it===void 0||it.attribute!==at||at&&it.data!==at.data)return!0;k++}return s.attributesNum!==k||s.index!==X}function p(I,P,V,X){const L={},B=P.attributes;let k=0;const $=V.getAttributes();for(const tt in $)if($[tt].location>=0){let it=B[tt];it===void 0&&(tt==="instanceMatrix"&&I.instanceMatrix&&(it=I.instanceMatrix),tt==="instanceColor"&&I.instanceColor&&(it=I.instanceColor));const at={};at.attribute=it,it&&it.data&&(at.data=it.data),L[tt]=at,k++}s.attributes=L,s.attributesNum=k,s.index=X}function v(){const I=s.newAttributes;for(let P=0,V=I.length;P<V;P++)I[P]=0}function m(I){g(I,0)}function g(I,P){const V=s.newAttributes,X=s.enabledAttributes,L=s.attributeDivisors;V[I]=1,X[I]===0&&(a.enableVertexAttribArray(I),X[I]=1),L[I]!==P&&(a.vertexAttribDivisor(I,P),L[I]=P)}function S(){const I=s.newAttributes,P=s.enabledAttributes;for(let V=0,X=P.length;V<X;V++)P[V]!==I[V]&&(a.disableVertexAttribArray(V),P[V]=0)}function x(I,P,V,X,L,B,k){k===!0?a.vertexAttribIPointer(I,P,V,L,B):a.vertexAttribPointer(I,P,V,X,L,B)}function M(I,P,V,X){v();const L=X.attributes,B=V.getAttributes(),k=P.defaultAttributeValues;for(const $ in B){const tt=B[$];if(tt.location>=0){let J=L[$];if(J===void 0&&($==="instanceMatrix"&&I.instanceMatrix&&(J=I.instanceMatrix),$==="instanceColor"&&I.instanceColor&&(J=I.instanceColor)),J!==void 0){const it=J.normalized,at=J.itemSize,Xt=t.get(J);if(Xt===void 0)continue;const ee=Xt.buffer,Kt=Xt.type,q=Xt.bytesPerElement,rt=Kt===a.INT||Kt===a.UNSIGNED_INT||J.gpuType===R0;if(J.isInterleavedBufferAttribute){const nt=J.data,z=nt.stride,Rt=J.offset;if(nt.isInstancedInterleavedBuffer){for(let Ft=0;Ft<tt.locationSize;Ft++)g(tt.location+Ft,nt.meshPerAttribute);I.isInstancedMesh!==!0&&X._maxInstanceCount===void 0&&(X._maxInstanceCount=nt.meshPerAttribute*nt.count)}else for(let Ft=0;Ft<tt.locationSize;Ft++)m(tt.location+Ft);a.bindBuffer(a.ARRAY_BUFFER,ee);for(let Ft=0;Ft<tt.locationSize;Ft++)x(tt.location+Ft,at/tt.locationSize,Kt,it,z*q,(Rt+at/tt.locationSize*Ft)*q,rt)}else{if(J.isInstancedBufferAttribute){for(let nt=0;nt<tt.locationSize;nt++)g(tt.location+nt,J.meshPerAttribute);I.isInstancedMesh!==!0&&X._maxInstanceCount===void 0&&(X._maxInstanceCount=J.meshPerAttribute*J.count)}else for(let nt=0;nt<tt.locationSize;nt++)m(tt.location+nt);a.bindBuffer(a.ARRAY_BUFFER,ee);for(let nt=0;nt<tt.locationSize;nt++)x(tt.location+nt,at/tt.locationSize,Kt,it,at*q,at/tt.locationSize*nt*q,rt)}}else if(k!==void 0){const it=k[$];if(it!==void 0)switch(it.length){case 2:a.vertexAttrib2fv(tt.location,it);break;case 3:a.vertexAttrib3fv(tt.location,it);break;case 4:a.vertexAttrib4fv(tt.location,it);break;default:a.vertexAttrib1fv(tt.location,it)}}}}S()}function b(){A();for(const I in i){const P=i[I];for(const V in P){const X=P[V];for(const L in X){const B=X[L];for(const k in B)h(B[k].object),delete B[k];delete X[L]}}delete i[I]}}function w(I){if(i[I.id]===void 0)return;const P=i[I.id];for(const V in P){const X=P[V];for(const L in X){const B=X[L];for(const k in B)h(B[k].object),delete B[k];delete X[L]}}delete i[I.id]}function T(I){for(const P in i){const V=i[P];for(const X in V){const L=V[X];if(L[I.id]===void 0)continue;const B=L[I.id];for(const k in B)h(B[k].object),delete B[k];delete L[I.id]}}}function y(I){for(const P in i){const V=i[P],X=I.isInstancedMesh===!0?I.id:0,L=V[X];if(L!==void 0){for(const B in L){const k=L[B];for(const $ in k)h(k[$].object),delete k[$];delete L[B]}delete V[X],Object.keys(V).length===0&&delete i[P]}}}function A(){C(),r=!0,s!==n&&(s=n,l(s.object))}function C(){n.geometry=null,n.program=null,n.wireframe=!1}return{setup:o,reset:A,resetDefaultState:C,dispose:b,releaseStatesOfGeometry:w,releaseStatesOfObject:y,releaseStatesOfProgram:T,initAttributes:v,enableAttribute:m,disableUnusedAttributes:S}}function GS(a,t,e){let i;function n(c){i=c}function s(c,l){a.drawArrays(i,c,l),e.update(l,i,1)}function r(c,l,h){h!==0&&(a.drawArraysInstanced(i,c,l,h),e.update(l,i,h))}function o(c,l,h){if(h===0)return;t.get("WEBGL_multi_draw").multiDrawArraysWEBGL(i,c,0,l,0,h);let d=0;for(let f=0;f<h;f++)d+=l[f];e.update(d,i,1)}this.setMode=n,this.render=s,this.renderInstances=r,this.renderMultiDraw=o}function VS(a,t,e,i){let n;function s(){if(n!==void 0)return n;if(t.has("EXT_texture_filter_anisotropic")===!0){const T=t.get("EXT_texture_filter_anisotropic");n=a.getParameter(T.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else n=0;return n}function r(T){return!(T!==Di&&i.convert(T)!==a.getParameter(a.IMPLEMENTATION_COLOR_READ_FORMAT))}function o(T){const y=T===$e&&(t.has("EXT_color_buffer_half_float")||t.has("EXT_color_buffer_float"));return!(T!==yn&&i.convert(T)!==a.getParameter(a.IMPLEMENTATION_COLOR_READ_TYPE)&&T!==Ui&&!y)}function c(T){if(T==="highp"){if(a.getShaderPrecisionFormat(a.VERTEX_SHADER,a.HIGH_FLOAT).precision>0&&a.getShaderPrecisionFormat(a.FRAGMENT_SHADER,a.HIGH_FLOAT).precision>0)return"highp";T="mediump"}return T==="mediump"&&a.getShaderPrecisionFormat(a.VERTEX_SHADER,a.MEDIUM_FLOAT).precision>0&&a.getShaderPrecisionFormat(a.FRAGMENT_SHADER,a.MEDIUM_FLOAT).precision>0?"mediump":"lowp"}let l=e.precision!==void 0?e.precision:"highp";const h=c(l);h!==l&&(It("WebGLRenderer:",l,"not supported, using",h,"instead."),l=h);const u=e.logarithmicDepthBuffer===!0,d=e.reversedDepthBuffer===!0&&t.has("EXT_clip_control");e.reversedDepthBuffer===!0&&d===!1&&It("WebGLRenderer: Unable to use reversed depth buffer due to missing EXT_clip_control extension. Fallback to default depth buffer.");const f=a.getParameter(a.MAX_TEXTURE_IMAGE_UNITS),p=a.getParameter(a.MAX_VERTEX_TEXTURE_IMAGE_UNITS),v=a.getParameter(a.MAX_TEXTURE_SIZE),m=a.getParameter(a.MAX_CUBE_MAP_TEXTURE_SIZE),g=a.getParameter(a.MAX_VERTEX_ATTRIBS),S=a.getParameter(a.MAX_VERTEX_UNIFORM_VECTORS),x=a.getParameter(a.MAX_VARYING_VECTORS),M=a.getParameter(a.MAX_FRAGMENT_UNIFORM_VECTORS),b=a.getParameter(a.MAX_SAMPLES),w=a.getParameter(a.SAMPLES);return{isWebGL2:!0,getMaxAnisotropy:s,getMaxPrecision:c,textureFormatReadable:r,textureTypeReadable:o,precision:l,logarithmicDepthBuffer:u,reversedDepthBuffer:d,maxTextures:f,maxVertexTextures:p,maxTextureSize:v,maxCubemapSize:m,maxAttributes:g,maxVertexUniforms:S,maxVaryings:x,maxFragmentUniforms:M,maxSamples:b,samples:w}}function WS(a){const t=this;let e=null,i=0,n=!1,s=!1;const r=new er,o=new $t,c={value:null,needsUpdate:!1};this.uniform=c,this.numPlanes=0,this.numIntersection=0,this.init=function(u,d){const f=u.length!==0||d||i!==0||n;return n=d,i=u.length,f},this.beginShadows=function(){s=!0,h(null)},this.endShadows=function(){s=!1},this.setGlobalState=function(u,d){e=h(u,d,0)},this.setState=function(u,d,f){const p=u.clippingPlanes,v=u.clipIntersection,m=u.clipShadows,g=a.get(u);if(!n||p===null||p.length===0||s&&!m)s?h(null):l();else{const S=s?0:i,x=S*4;let M=g.clippingState||null;c.value=M,M=h(p,d,x,f);for(let b=0;b!==x;++b)M[b]=e[b];g.clippingState=M,this.numIntersection=v?this.numPlanes:0,this.numPlanes+=S}};function l(){c.value!==e&&(c.value=e,c.needsUpdate=i>0),t.numPlanes=i,t.numIntersection=0}function h(u,d,f,p){const v=u!==null?u.length:0;let m=null;if(v!==0){if(m=c.value,p!==!0||m===null){const g=f+v*4,S=d.matrixWorldInverse;o.getNormalMatrix(S),(m===null||m.length<g)&&(m=new Float32Array(g));for(let x=0,M=f;x!==v;++x,M+=4)r.copy(u[x]).applyMatrix4(S,o),r.normal.toArray(m,M),m[M+3]=r.constant}c.value=m,c.needsUpdate=!0}return t.numPlanes=v,t.numIntersection=0,m}}const cr=4,Kp=[.125,.215,.35,.446,.526,.582],Ir=20,XS=256,So=new Zn,Zp=new st;let cu=null,lu=0,hu=0,uu=!1;const YS=new R;class Wd{constructor(t){this._renderer=t,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(t,e=0,i=.1,n=100,s={}){const{size:r=256,position:o=YS}=s;cu=this._renderer.getRenderTarget(),lu=this._renderer.getActiveCubeFace(),hu=this._renderer.getActiveMipmapLevel(),uu=this._renderer.xr.enabled,this._renderer.xr.enabled=!1,this._setSize(r);const c=this._allocateTargets();return c.depthBuffer=!0,this._sceneToCubeUV(t,i,n,c,o),e>0&&this._blur(c,0,0,e),this._applyPMREM(c),this._cleanup(c),c}fromEquirectangular(t,e=null){return this._fromTexture(t,e)}fromCubemap(t,e=null){return this._fromTexture(t,e)}compileCubemapShader(){this._cubemapMaterial===null&&(this._cubemapMaterial=Qp(),this._compileMaterial(this._cubemapMaterial))}compileEquirectangularShader(){this._equirectMaterial===null&&(this._equirectMaterial=jp(),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(t){this._lodMax=Math.floor(Math.log2(t)),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 t=0;t<this._lodMeshes.length;t++)this._lodMeshes[t].geometry.dispose()}_cleanup(t){this._renderer.setRenderTarget(cu,lu,hu),this._renderer.xr.enabled=uu,t.scissorTest=!1,Sa(t,0,0,t.width,t.height)}_fromTexture(t,e){t.mapping===Xr||t.mapping===ja?this._setSize(t.image.length===0?16:t.image[0].width||t.image[0].image.width):this._setSize(t.image.width/4),cu=this._renderer.getRenderTarget(),lu=this._renderer.getActiveCubeFace(),hu=this._renderer.getActiveMipmapLevel(),uu=this._renderer.xr.enabled,this._renderer.xr.enabled=!1;const i=e||this._allocateTargets();return this._textureToCubeUV(t,i),this._applyPMREM(i),this._cleanup(i),i}_allocateTargets(){const t=3*Math.max(this._cubeSize,112),e=4*this._cubeSize,i={magFilter:le,minFilter:le,generateMipmaps:!1,type:$e,format:Di,colorSpace:Vl,depthBuffer:!1},n=Jp(t,e,i);if(this._pingPongRenderTarget===null||this._pingPongRenderTarget.width!==t||this._pingPongRenderTarget.height!==e){this._pingPongRenderTarget!==null&&this._dispose(),this._pingPongRenderTarget=Jp(t,e,i);const{_lodMax:s}=this;({lodMeshes:this._lodMeshes,sizeLods:this._sizeLods,sigmas:this._sigmas}=qS(s)),this._blurMaterial=KS(s,t,e),this._ggxMaterial=$S(s,t,e)}return n}_compileMaterial(t){const e=new bt(new se,t);this._renderer.compile(e,So)}_sceneToCubeUV(t,e,i,n,s){const c=new rn(90,1,e,i),l=[1,-1,1,1,1,1],h=[1,1,1,-1,-1,-1],u=this._renderer,d=u.autoClear,f=u.toneMapping;u.getClearColor(Zp),u.toneMapping=Ms,u.autoClear=!1,u.state.buffers.depth.getReversed()&&(u.setRenderTarget(n),u.clearDepth(),u.setRenderTarget(null)),this._backgroundBox===null&&(this._backgroundBox=new bt(new Ki,new _n({name:"PMREM.Background",side:qe,depthWrite:!1,depthTest:!1})));const v=this._backgroundBox,m=v.material;let g=!1;const S=t.background;S?S.isColor&&(m.color.copy(S),t.background=null,g=!0):(m.color.copy(Zp),g=!0);for(let x=0;x<6;x++){const M=x%3;M===0?(c.up.set(0,l[x],0),c.position.set(s.x,s.y,s.z),c.lookAt(s.x+h[x],s.y,s.z)):M===1?(c.up.set(0,0,l[x]),c.position.set(s.x,s.y,s.z),c.lookAt(s.x,s.y+h[x],s.z)):(c.up.set(0,l[x],0),c.position.set(s.x,s.y,s.z),c.lookAt(s.x,s.y,s.z+h[x]));const b=this._cubeSize;Sa(n,M*b,x>2?b:0,b,b),u.setRenderTarget(n),g&&u.render(v,c),u.render(t,c)}u.toneMapping=f,u.autoClear=d,t.background=S}_textureToCubeUV(t,e){const i=this._renderer,n=t.mapping===Xr||t.mapping===ja;n?(this._cubemapMaterial===null&&(this._cubemapMaterial=Qp()),this._cubemapMaterial.uniforms.flipEnvMap.value=t.isRenderTargetTexture===!1?-1:1):this._equirectMaterial===null&&(this._equirectMaterial=jp());const s=n?this._cubemapMaterial:this._equirectMaterial,r=this._lodMeshes[0];r.material=s;const o=s.uniforms;o.envMap.value=t;const c=this._cubeSize;Sa(e,0,0,3*c,2*c),i.setRenderTarget(e),i.render(r,So)}_applyPMREM(t){const e=this._renderer,i=e.autoClear;e.autoClear=!1;const n=this._lodMeshes.length;for(let s=1;s<n;s++)this._applyGGXFilter(t,s-1,s);e.autoClear=i}_applyGGXFilter(t,e,i){const n=this._renderer,s=this._pingPongRenderTarget,r=this._ggxMaterial,o=this._lodMeshes[i];o.material=r;const c=r.uniforms,l=i/(this._lodMeshes.length-1),h=e/(this._lodMeshes.length-1),u=Math.sqrt(l*l-h*h),d=0+l*1.25,f=u*d,{_lodMax:p}=this,v=this._sizeLods[i],m=3*v*(i>p-cr?i-p+cr:0),g=4*(this._cubeSize-v);c.envMap.value=t.texture,c.roughness.value=f,c.mipInt.value=p-e,Sa(s,m,g,3*v,2*v),n.setRenderTarget(s),n.render(o,So),c.envMap.value=s.texture,c.roughness.value=0,c.mipInt.value=p-i,Sa(t,m,g,3*v,2*v),n.setRenderTarget(t),n.render(o,So)}_blur(t,e,i,n,s){const r=this._pingPongRenderTarget;this._halfBlur(t,r,e,i,n,"latitudinal",s),this._halfBlur(r,t,i,i,n,"longitudinal",s)}_halfBlur(t,e,i,n,s,r,o){const c=this._renderer,l=this._blurMaterial;r!=="latitudinal"&&r!=="longitudinal"&&Wt("blur direction must be either latitudinal or longitudinal!");const h=3,u=this._lodMeshes[n];u.material=l;const d=l.uniforms,f=this._sizeLods[i]-1,p=isFinite(s)?Math.PI/(2*f):2*Math.PI/(2*Ir-1),v=s/p,m=isFinite(s)?1+Math.floor(h*v):Ir;m>Ir&&It(`sigmaRadians, ${s}, is too large and will clip, as it requested ${m} samples when the maximum is set to ${Ir}`);const g=[];let S=0;for(let T=0;T<Ir;++T){const y=T/v,A=Math.exp(-y*y/2);g.push(A),T===0?S+=A:T<m&&(S+=2*A)}for(let T=0;T<g.length;T++)g[T]=g[T]/S;d.envMap.value=t.texture,d.samples.value=m,d.weights.value=g,d.latitudinal.value=r==="latitudinal",o&&(d.poleAxis.value=o);const{_lodMax:x}=this;d.dTheta.value=p,d.mipInt.value=x-i;const M=this._sizeLods[n],b=3*M*(n>x-cr?n-x+cr:0),w=4*(this._cubeSize-M);Sa(e,b,w,3*M,2*M),c.setRenderTarget(e),c.render(u,So)}}function qS(a){const t=[],e=[],i=[];let n=a;const s=a-cr+1+Kp.length;for(let r=0;r<s;r++){const o=Math.pow(2,n);t.push(o);let c=1/o;r>a-cr?c=Kp[r-a+cr-1]:r===0&&(c=0),e.push(c);const l=1/(o-2),h=-l,u=1+l,d=[h,h,u,h,u,u,h,h,u,u,h,u],f=6,p=6,v=3,m=2,g=1,S=new Float32Array(v*p*f),x=new Float32Array(m*p*f),M=new Float32Array(g*p*f);for(let w=0;w<f;w++){const T=w%3*2/3-1,y=w>2?0:-1,A=[T,y,0,T+2/3,y,0,T+2/3,y+1,0,T,y,0,T+2/3,y+1,0,T,y+1,0];S.set(A,v*p*w),x.set(d,m*p*w);const C=[w,w,w,w,w,w];M.set(C,g*p*w)}const b=new se;b.setAttribute("position",new Jt(S,v)),b.setAttribute("uv",new Jt(x,m)),b.setAttribute("faceIndex",new Jt(M,g)),i.push(new bt(b,null)),n>cr&&n--}return{lodMeshes:i,sizeLods:t,sigmas:e}}function Jp(a,t,e){const i=new Qe(a,t,e);return i.texture.mapping=uh,i.texture.name="PMREM.cubeUv",i.scissorTest=!0,i}function Sa(a,t,e,i,n){a.viewport.set(t,e,i,n),a.scissor.set(t,e,i,n)}function $S(a,t,e){return new fe({name:"PMREMGGXConvolution",defines:{GGX_SAMPLES:XS,CUBEUV_TEXEL_WIDTH:1/t,CUBEUV_TEXEL_HEIGHT:1/e,CUBEUV_MAX_MIP:`${a}.0`},uniforms:{envMap:{value:null},roughness:{value:0},mipInt:{value:0}},vertexShader:mh(),fragmentShader:`
5091
5091
 
5092
5092
  precision highp float;
5093
5093
  precision highp int;
@@ -5191,7 +5191,7 @@ void main() {
5191
5191
 
5192
5192
  gl_FragColor = vec4(prefilteredColor, 1.0);
5193
5193
  }
5194
- `,blending:vs,depthTest:!1,depthWrite:!1})}function KS(a,t,e){const i=new Float32Array(Ir),n=new R(0,1,0);return new de({name:"SphericalGaussianBlur",defines:{n:Ir,CUBEUV_TEXEL_WIDTH:1/t,CUBEUV_TEXEL_HEIGHT:1/e,CUBEUV_MAX_MIP:`${a}.0`},uniforms:{envMap:{value:null},samples:{value:1},weights:{value:i},latitudinal:{value:!1},dTheta:{value:0},mipInt:{value:0},poleAxis:{value:n}},vertexShader:mh(),fragmentShader:`
5194
+ `,blending:vs,depthTest:!1,depthWrite:!1})}function KS(a,t,e){const i=new Float32Array(Ir),n=new R(0,1,0);return new fe({name:"SphericalGaussianBlur",defines:{n:Ir,CUBEUV_TEXEL_WIDTH:1/t,CUBEUV_TEXEL_HEIGHT:1/e,CUBEUV_MAX_MIP:`${a}.0`},uniforms:{envMap:{value:null},samples:{value:1},weights:{value:i},latitudinal:{value:!1},dTheta:{value:0},mipInt:{value:0},poleAxis:{value:n}},vertexShader:mh(),fragmentShader:`
5195
5195
 
5196
5196
  precision mediump float;
5197
5197
  precision mediump int;
@@ -5251,7 +5251,7 @@ void main() {
5251
5251
  }
5252
5252
 
5253
5253
  }
5254
- `,blending:vs,depthTest:!1,depthWrite:!1})}function jp(){return new de({name:"EquirectangularToCubeUV",uniforms:{envMap:{value:null}},vertexShader:mh(),fragmentShader:`
5254
+ `,blending:vs,depthTest:!1,depthWrite:!1})}function jp(){return new fe({name:"EquirectangularToCubeUV",uniforms:{envMap:{value:null}},vertexShader:mh(),fragmentShader:`
5255
5255
 
5256
5256
  precision mediump float;
5257
5257
  precision mediump int;
@@ -5270,7 +5270,7 @@ void main() {
5270
5270
  gl_FragColor = vec4( texture2D ( envMap, uv ).rgb, 1.0 );
5271
5271
 
5272
5272
  }
5273
- `,blending:vs,depthTest:!1,depthWrite:!1})}function Qp(){return new de({name:"CubemapToCubeUV",uniforms:{envMap:{value:null},flipEnvMap:{value:-1}},vertexShader:mh(),fragmentShader:`
5273
+ `,blending:vs,depthTest:!1,depthWrite:!1})}function Qp(){return new fe({name:"CubemapToCubeUV",uniforms:{envMap:{value:null},flipEnvMap:{value:-1}},vertexShader:mh(),fragmentShader:`
5274
5274
 
5275
5275
  precision mediump float;
5276
5276
  precision mediump int;
@@ -5376,7 +5376,7 @@ void main() {
5376
5376
  gl_FragColor = texture2D( tEquirect, sampleUV );
5377
5377
 
5378
5378
  }
5379
- `},n=new Ki(5,5,5),s=new de({name:"CubemapFromEquirect",uniforms:to(i.uniforms),vertexShader:i.vertexShader,fragmentShader:i.fragmentShader,side:qe,blending:vs});s.uniforms.tEquirect.value=e;const r=new bt(n,s),o=e.minFilter;return e.minFilter===Lr&&(e.minFilter=le),new $0(1,10,this).update(t,r),e.minFilter=o,r.geometry.dispose(),r.material.dispose(),this}clear(t,e=!0,i=!0,n=!0){const s=t.getRenderTarget();for(let r=0;r<6;r++)t.setRenderTarget(this,r),t.clear(e,i,n);t.setRenderTarget(s)}}function ZS(a){let t=new WeakMap,e=new WeakMap,i=null;function n(d,f=!1){return d==null?null:f?r(d):s(d)}function s(d){if(d&&d.isTexture){const f=d.mapping;if(f===Dh||f===Ih)if(t.has(d)){const p=t.get(d).texture;return o(p,d.mapping)}else{const p=d.image;if(p&&p.height>0){const v=new lc(p.height);return v.fromEquirectangularTexture(a,d),t.set(d,v),d.addEventListener("dispose",l),o(v.texture,d.mapping)}else return null}}return d}function r(d){if(d&&d.isTexture){const f=d.mapping,p=f===Dh||f===Ih,v=f===Xr||f===ja;if(p||v){let m=e.get(d);const g=m!==void 0?m.texture.pmremVersion:0;if(d.isRenderTargetTexture&&d.pmremVersion!==g)return i===null&&(i=new Wd(a)),m=p?i.fromEquirectangular(d,m):i.fromCubemap(d,m),m.texture.pmremVersion=d.pmremVersion,e.set(d,m),m.texture;if(m!==void 0)return m.texture;{const S=d.image;return p&&S&&S.height>0||v&&S&&c(S)?(i===null&&(i=new Wd(a)),m=p?i.fromEquirectangular(d):i.fromCubemap(d),m.texture.pmremVersion=d.pmremVersion,e.set(d,m),d.addEventListener("dispose",h),m.texture):null}}}return d}function o(d,f){return f===Dh?d.mapping=Xr:f===Ih&&(d.mapping=ja),d}function c(d){let f=0;const p=6;for(let v=0;v<p;v++)d[v]!==void 0&&f++;return f===p}function l(d){const f=d.target;f.removeEventListener("dispose",l);const p=t.get(f);p!==void 0&&(t.delete(f),p.dispose())}function h(d){const f=d.target;f.removeEventListener("dispose",h);const p=e.get(f);p!==void 0&&(e.delete(f),p.dispose())}function u(){t=new WeakMap,e=new WeakMap,i!==null&&(i.dispose(),i=null)}return{get:n,dispose:u}}function JS(a){const t={};function e(i){if(t[i]!==void 0)return t[i];const n=a.getExtension(i);return t[i]=n,n}return{has:function(i){return e(i)!==null},init:function(){e("EXT_color_buffer_float"),e("WEBGL_clip_cull_distance"),e("OES_texture_float_linear"),e("EXT_color_buffer_half_float"),e("WEBGL_multisampled_render_to_texture"),e("WEBGL_render_shared_exponent")},get:function(i){const n=e(i);return n===null&&Ba("WebGLRenderer: "+i+" extension not supported."),n}}}function jS(a,t,e,i){const n={},s=new WeakMap;function r(u){const d=u.target;d.index!==null&&t.remove(d.index);for(const p in d.attributes)t.remove(d.attributes[p]);d.removeEventListener("dispose",r),delete n[d.id];const f=s.get(d);f&&(t.remove(f),s.delete(d)),i.releaseStatesOfGeometry(d),d.isInstancedBufferGeometry===!0&&delete d._maxInstanceCount,e.memory.geometries--}function o(u,d){return n[d.id]===!0||(d.addEventListener("dispose",r),n[d.id]=!0,e.memory.geometries++),d}function c(u){const d=u.attributes;for(const f in d)t.update(d[f],a.ARRAY_BUFFER)}function l(u){const d=[],f=u.index,p=u.attributes.position;let v=0;if(p===void 0)return;if(f!==null){const S=f.array;v=f.version;for(let x=0,M=S.length;x<M;x+=3){const b=S[x+0],w=S[x+1],T=S[x+2];d.push(b,w,w,T,T,b)}}else{const S=p.array;v=p.version;for(let x=0,M=S.length/3-1;x<M;x+=3){const b=x+0,w=x+1,T=x+2;d.push(b,w,w,T,T,b)}}const m=new(p.count>=65535?H0:v1)(d,1);m.version=v;const g=s.get(u);g&&t.remove(g),s.set(u,m)}function h(u){const d=s.get(u);if(d){const f=u.index;f!==null&&d.version<f.version&&l(u)}else l(u);return s.get(u)}return{get:o,update:c,getWireframeAttribute:h}}function QS(a,t,e){let i;function n(u){i=u}let s,r;function o(u){s=u.type,r=u.bytesPerElement}function c(u,d){a.drawElements(i,d,s,u*r),e.update(d,i,1)}function l(u,d,f){f!==0&&(a.drawElementsInstanced(i,d,s,u*r,f),e.update(d,i,f))}function h(u,d,f){if(f===0)return;t.get("WEBGL_multi_draw").multiDrawElementsWEBGL(i,d,0,s,u,0,f);let v=0;for(let m=0;m<f;m++)v+=d[m];e.update(v,i,1)}this.setMode=n,this.setIndex=o,this.render=c,this.renderInstances=l,this.renderMultiDraw=h}function t_(a){const t={geometries:0,textures:0},e={frame:0,calls:0,triangles:0,points:0,lines:0};function i(s,r,o){switch(e.calls++,r){case a.TRIANGLES:e.triangles+=o*(s/3);break;case a.LINES:e.lines+=o*(s/2);break;case a.LINE_STRIP:e.lines+=o*(s-1);break;case a.LINE_LOOP:e.lines+=o*s;break;case a.POINTS:e.points+=o*s;break;default:Wt("WebGLInfo: Unknown draw mode:",r);break}}function n(){e.calls=0,e.triangles=0,e.points=0,e.lines=0}return{memory:t,render:e,programs:null,autoReset:!0,reset:n,update:i}}function e_(a,t,e){const i=new WeakMap,n=new ae;function s(r,o,c){const l=r.morphTargetInfluences,h=o.morphAttributes.position||o.morphAttributes.normal||o.morphAttributes.color,u=h!==void 0?h.length:0;let d=i.get(o);if(d===void 0||d.count!==u){let A=function(){T.dispose(),i.delete(o),o.removeEventListener("dispose",A)};d!==void 0&&d.texture.dispose();const f=o.morphAttributes.position!==void 0,p=o.morphAttributes.normal!==void 0,v=o.morphAttributes.color!==void 0,m=o.morphAttributes.position||[],g=o.morphAttributes.normal||[],S=o.morphAttributes.color||[];let x=0;f===!0&&(x=1),p===!0&&(x=2),v===!0&&(x=3);let M=o.attributes.position.count*x,b=1;M>t.maxTextureSize&&(b=Math.ceil(M/t.maxTextureSize),M=t.maxTextureSize);const w=new Float32Array(M*b*4*u),T=new p1(w,M,b,u);T.type=Ui,T.needsUpdate=!0;const y=x*4;for(let C=0;C<u;C++){const I=m[C],P=g[C],V=S[C],X=M*b*4*C;for(let L=0;L<I.count;L++){const B=L*y;f===!0&&(n.fromBufferAttribute(I,L),w[X+B+0]=n.x,w[X+B+1]=n.y,w[X+B+2]=n.z,w[X+B+3]=0),p===!0&&(n.fromBufferAttribute(P,L),w[X+B+4]=n.x,w[X+B+5]=n.y,w[X+B+6]=n.z,w[X+B+7]=0),v===!0&&(n.fromBufferAttribute(V,L),w[X+B+8]=n.x,w[X+B+9]=n.y,w[X+B+10]=n.z,w[X+B+11]=V.itemSize===4?n.w:1)}}d={count:u,texture:T,size:new Mt(M,b)},i.set(o,d),o.addEventListener("dispose",A)}if(r.isInstancedMesh===!0&&r.morphTexture!==null)c.getUniforms().setValue(a,"morphTexture",r.morphTexture,e);else{let f=0;for(let v=0;v<l.length;v++)f+=l[v];const p=o.morphTargetsRelative?1:1-f;c.getUniforms().setValue(a,"morphTargetBaseInfluence",p),c.getUniforms().setValue(a,"morphTargetInfluences",l)}c.getUniforms().setValue(a,"morphTargetsTexture",d.texture,e),c.getUniforms().setValue(a,"morphTargetsTextureSize",d.size)}return{update:s}}function i_(a,t,e,i,n){let s=new WeakMap;function r(l){const h=n.render.frame,u=l.geometry,d=t.get(l,u);if(s.get(d)!==h&&(t.update(d),s.set(d,h)),l.isInstancedMesh&&(l.hasEventListener("dispose",c)===!1&&l.addEventListener("dispose",c),s.get(l)!==h&&(e.update(l.instanceMatrix,a.ARRAY_BUFFER),l.instanceColor!==null&&e.update(l.instanceColor,a.ARRAY_BUFFER),s.set(l,h))),l.isSkinnedMesh){const f=l.skeleton;s.get(f)!==h&&(f.update(),s.set(f,h))}return d}function o(){s=new WeakMap}function c(l){const h=l.target;h.removeEventListener("dispose",c),i.releaseStatesOfObject(h),e.remove(h.instanceMatrix),h.instanceColor!==null&&e.remove(h.instanceColor)}return{update:r,dispose:o}}const n_={[jg]:"LINEAR_TONE_MAPPING",[Qg]:"REINHARD_TONE_MAPPING",[t1]:"CINEON_TONE_MAPPING",[e1]:"ACES_FILMIC_TONE_MAPPING",[n1]:"AGX_TONE_MAPPING",[s1]:"NEUTRAL_TONE_MAPPING",[i1]:"CUSTOM_TONE_MAPPING"};function s_(a,t,e,i,n,s){const r=new Qe(t,e,{type:a,depthBuffer:n,stencilBuffer:s,samples:i?4:0,depthTexture:n?new mr(t,e):void 0}),o=new Qe(t,e,{type:$e,depthBuffer:!1,stencilBuffer:!1}),c=new se;c.setAttribute("position",new ue([-1,3,0,-1,-1,0,3,-1,0],3)),c.setAttribute("uv",new ue([0,2,0,0,2,0],2));const l=new E1({uniforms:{tDiffuse:{value:null}},vertexShader:`
5379
+ `},n=new Ki(5,5,5),s=new fe({name:"CubemapFromEquirect",uniforms:to(i.uniforms),vertexShader:i.vertexShader,fragmentShader:i.fragmentShader,side:qe,blending:vs});s.uniforms.tEquirect.value=e;const r=new bt(n,s),o=e.minFilter;return e.minFilter===Lr&&(e.minFilter=le),new $0(1,10,this).update(t,r),e.minFilter=o,r.geometry.dispose(),r.material.dispose(),this}clear(t,e=!0,i=!0,n=!0){const s=t.getRenderTarget();for(let r=0;r<6;r++)t.setRenderTarget(this,r),t.clear(e,i,n);t.setRenderTarget(s)}}function ZS(a){let t=new WeakMap,e=new WeakMap,i=null;function n(d,f=!1){return d==null?null:f?r(d):s(d)}function s(d){if(d&&d.isTexture){const f=d.mapping;if(f===Dh||f===Ih)if(t.has(d)){const p=t.get(d).texture;return o(p,d.mapping)}else{const p=d.image;if(p&&p.height>0){const v=new lc(p.height);return v.fromEquirectangularTexture(a,d),t.set(d,v),d.addEventListener("dispose",l),o(v.texture,d.mapping)}else return null}}return d}function r(d){if(d&&d.isTexture){const f=d.mapping,p=f===Dh||f===Ih,v=f===Xr||f===ja;if(p||v){let m=e.get(d);const g=m!==void 0?m.texture.pmremVersion:0;if(d.isRenderTargetTexture&&d.pmremVersion!==g)return i===null&&(i=new Wd(a)),m=p?i.fromEquirectangular(d,m):i.fromCubemap(d,m),m.texture.pmremVersion=d.pmremVersion,e.set(d,m),m.texture;if(m!==void 0)return m.texture;{const S=d.image;return p&&S&&S.height>0||v&&S&&c(S)?(i===null&&(i=new Wd(a)),m=p?i.fromEquirectangular(d):i.fromCubemap(d),m.texture.pmremVersion=d.pmremVersion,e.set(d,m),d.addEventListener("dispose",h),m.texture):null}}}return d}function o(d,f){return f===Dh?d.mapping=Xr:f===Ih&&(d.mapping=ja),d}function c(d){let f=0;const p=6;for(let v=0;v<p;v++)d[v]!==void 0&&f++;return f===p}function l(d){const f=d.target;f.removeEventListener("dispose",l);const p=t.get(f);p!==void 0&&(t.delete(f),p.dispose())}function h(d){const f=d.target;f.removeEventListener("dispose",h);const p=e.get(f);p!==void 0&&(e.delete(f),p.dispose())}function u(){t=new WeakMap,e=new WeakMap,i!==null&&(i.dispose(),i=null)}return{get:n,dispose:u}}function JS(a){const t={};function e(i){if(t[i]!==void 0)return t[i];const n=a.getExtension(i);return t[i]=n,n}return{has:function(i){return e(i)!==null},init:function(){e("EXT_color_buffer_float"),e("WEBGL_clip_cull_distance"),e("OES_texture_float_linear"),e("EXT_color_buffer_half_float"),e("WEBGL_multisampled_render_to_texture"),e("WEBGL_render_shared_exponent")},get:function(i){const n=e(i);return n===null&&Ba("WebGLRenderer: "+i+" extension not supported."),n}}}function jS(a,t,e,i){const n={},s=new WeakMap;function r(u){const d=u.target;d.index!==null&&t.remove(d.index);for(const p in d.attributes)t.remove(d.attributes[p]);d.removeEventListener("dispose",r),delete n[d.id];const f=s.get(d);f&&(t.remove(f),s.delete(d)),i.releaseStatesOfGeometry(d),d.isInstancedBufferGeometry===!0&&delete d._maxInstanceCount,e.memory.geometries--}function o(u,d){return n[d.id]===!0||(d.addEventListener("dispose",r),n[d.id]=!0,e.memory.geometries++),d}function c(u){const d=u.attributes;for(const f in d)t.update(d[f],a.ARRAY_BUFFER)}function l(u){const d=[],f=u.index,p=u.attributes.position;let v=0;if(p===void 0)return;if(f!==null){const S=f.array;v=f.version;for(let x=0,M=S.length;x<M;x+=3){const b=S[x+0],w=S[x+1],T=S[x+2];d.push(b,w,w,T,T,b)}}else{const S=p.array;v=p.version;for(let x=0,M=S.length/3-1;x<M;x+=3){const b=x+0,w=x+1,T=x+2;d.push(b,w,w,T,T,b)}}const m=new(p.count>=65535?H0:v1)(d,1);m.version=v;const g=s.get(u);g&&t.remove(g),s.set(u,m)}function h(u){const d=s.get(u);if(d){const f=u.index;f!==null&&d.version<f.version&&l(u)}else l(u);return s.get(u)}return{get:o,update:c,getWireframeAttribute:h}}function QS(a,t,e){let i;function n(u){i=u}let s,r;function o(u){s=u.type,r=u.bytesPerElement}function c(u,d){a.drawElements(i,d,s,u*r),e.update(d,i,1)}function l(u,d,f){f!==0&&(a.drawElementsInstanced(i,d,s,u*r,f),e.update(d,i,f))}function h(u,d,f){if(f===0)return;t.get("WEBGL_multi_draw").multiDrawElementsWEBGL(i,d,0,s,u,0,f);let v=0;for(let m=0;m<f;m++)v+=d[m];e.update(v,i,1)}this.setMode=n,this.setIndex=o,this.render=c,this.renderInstances=l,this.renderMultiDraw=h}function t_(a){const t={geometries:0,textures:0},e={frame:0,calls:0,triangles:0,points:0,lines:0};function i(s,r,o){switch(e.calls++,r){case a.TRIANGLES:e.triangles+=o*(s/3);break;case a.LINES:e.lines+=o*(s/2);break;case a.LINE_STRIP:e.lines+=o*(s-1);break;case a.LINE_LOOP:e.lines+=o*s;break;case a.POINTS:e.points+=o*s;break;default:Wt("WebGLInfo: Unknown draw mode:",r);break}}function n(){e.calls=0,e.triangles=0,e.points=0,e.lines=0}return{memory:t,render:e,programs:null,autoReset:!0,reset:n,update:i}}function e_(a,t,e){const i=new WeakMap,n=new ae;function s(r,o,c){const l=r.morphTargetInfluences,h=o.morphAttributes.position||o.morphAttributes.normal||o.morphAttributes.color,u=h!==void 0?h.length:0;let d=i.get(o);if(d===void 0||d.count!==u){let A=function(){T.dispose(),i.delete(o),o.removeEventListener("dispose",A)};d!==void 0&&d.texture.dispose();const f=o.morphAttributes.position!==void 0,p=o.morphAttributes.normal!==void 0,v=o.morphAttributes.color!==void 0,m=o.morphAttributes.position||[],g=o.morphAttributes.normal||[],S=o.morphAttributes.color||[];let x=0;f===!0&&(x=1),p===!0&&(x=2),v===!0&&(x=3);let M=o.attributes.position.count*x,b=1;M>t.maxTextureSize&&(b=Math.ceil(M/t.maxTextureSize),M=t.maxTextureSize);const w=new Float32Array(M*b*4*u),T=new p1(w,M,b,u);T.type=Ui,T.needsUpdate=!0;const y=x*4;for(let C=0;C<u;C++){const I=m[C],P=g[C],V=S[C],X=M*b*4*C;for(let L=0;L<I.count;L++){const B=L*y;f===!0&&(n.fromBufferAttribute(I,L),w[X+B+0]=n.x,w[X+B+1]=n.y,w[X+B+2]=n.z,w[X+B+3]=0),p===!0&&(n.fromBufferAttribute(P,L),w[X+B+4]=n.x,w[X+B+5]=n.y,w[X+B+6]=n.z,w[X+B+7]=0),v===!0&&(n.fromBufferAttribute(V,L),w[X+B+8]=n.x,w[X+B+9]=n.y,w[X+B+10]=n.z,w[X+B+11]=V.itemSize===4?n.w:1)}}d={count:u,texture:T,size:new Mt(M,b)},i.set(o,d),o.addEventListener("dispose",A)}if(r.isInstancedMesh===!0&&r.morphTexture!==null)c.getUniforms().setValue(a,"morphTexture",r.morphTexture,e);else{let f=0;for(let v=0;v<l.length;v++)f+=l[v];const p=o.morphTargetsRelative?1:1-f;c.getUniforms().setValue(a,"morphTargetBaseInfluence",p),c.getUniforms().setValue(a,"morphTargetInfluences",l)}c.getUniforms().setValue(a,"morphTargetsTexture",d.texture,e),c.getUniforms().setValue(a,"morphTargetsTextureSize",d.size)}return{update:s}}function i_(a,t,e,i,n){let s=new WeakMap;function r(l){const h=n.render.frame,u=l.geometry,d=t.get(l,u);if(s.get(d)!==h&&(t.update(d),s.set(d,h)),l.isInstancedMesh&&(l.hasEventListener("dispose",c)===!1&&l.addEventListener("dispose",c),s.get(l)!==h&&(e.update(l.instanceMatrix,a.ARRAY_BUFFER),l.instanceColor!==null&&e.update(l.instanceColor,a.ARRAY_BUFFER),s.set(l,h))),l.isSkinnedMesh){const f=l.skeleton;s.get(f)!==h&&(f.update(),s.set(f,h))}return d}function o(){s=new WeakMap}function c(l){const h=l.target;h.removeEventListener("dispose",c),i.releaseStatesOfObject(h),e.remove(h.instanceMatrix),h.instanceColor!==null&&e.remove(h.instanceColor)}return{update:r,dispose:o}}const n_={[jg]:"LINEAR_TONE_MAPPING",[Qg]:"REINHARD_TONE_MAPPING",[t1]:"CINEON_TONE_MAPPING",[e1]:"ACES_FILMIC_TONE_MAPPING",[n1]:"AGX_TONE_MAPPING",[s1]:"NEUTRAL_TONE_MAPPING",[i1]:"CUSTOM_TONE_MAPPING"};function s_(a,t,e,i,n,s){const r=new Qe(t,e,{type:a,depthBuffer:n,stencilBuffer:s,samples:i?4:0,depthTexture:n?new mr(t,e):void 0}),o=new Qe(t,e,{type:$e,depthBuffer:!1,stencilBuffer:!1}),c=new se;c.setAttribute("position",new de([-1,3,0,-1,-1,0,3,-1,0],3)),c.setAttribute("uv",new de([0,2,0,0,2,0],2));const l=new E1({uniforms:{tDiffuse:{value:null}},vertexShader:`
5380
5380
  precision highp float;
5381
5381
 
5382
5382
  uniform mat4 modelViewMatrix;
@@ -5473,7 +5473,7 @@ Material Type: `+I.type+`
5473
5473
 
5474
5474
  Program Info Log: `+L+`
5475
5475
  `+J+`
5476
- `+it)}else L!==""?It("WebGLProgram: Program Info Log:",L):(B===""||k==="")&&(tt=!1);tt&&(I.diagnostics={runnable:$,programLog:L,vertexShader:{log:B,prefix:m},fragmentShader:{log:k,prefix:g}})}n.deleteShader(b),n.deleteShader(w),y=new Pl(n,v),A=rb(n,v)}let y;this.getUniforms=function(){return y===void 0&&T(this),y};let A;this.getAttributes=function(){return A===void 0&&T(this),A};let C=e.rendererExtensionParallelShaderCompile===!1;return this.isReady=function(){return C===!1&&(C=n.getProgramParameter(v,K_)),C},this.destroy=function(){i.releaseStatesOfProgram(this),n.deleteProgram(v),this.program=void 0},this.type=e.shaderType,this.name=e.shaderName,this.id=Z_++,this.cacheKey=t,this.usedTimes=1,this.program=v,this.vertexShader=b,this.fragmentShader=w,this}let Sb=0;class _b{constructor(){this.shaderCache=new Map,this.materialCache=new Map}update(t,e,i){const n=this._getShaderCacheForMaterial(t);return n.has(e)===!1&&(n.add(e),e.usedTimes++),n.has(i)===!1&&(n.add(i),i.usedTimes++),this}remove(t){const e=this.materialCache.get(t);for(const i of e)i.usedTimes--,i.usedTimes===0&&this.shaderCache.delete(i.code);return this.materialCache.delete(t),this}getVertexShaderStage(t){return this._getShaderStage(t.vertexShader)}getFragmentShaderStage(t){return this._getShaderStage(t.fragmentShader)}dispose(){this.shaderCache.clear(),this.materialCache.clear()}_getShaderCacheForMaterial(t){const e=this.materialCache;let i=e.get(t);return i===void 0&&(i=new Set,e.set(t,i)),i}_getShaderStage(t){const e=this.shaderCache;let i=e.get(t);return i===void 0&&(i=new bb(t),e.set(t,i)),i}}class bb{constructor(t){this.id=Sb++,this.code=t,this.usedTimes=0}}function wb(a){return a===Yr||a===kl||a===zl}function Eb(a,t,e,i,n,s){const r=new z0,o=new _b,c=new Set,l=[],h=new Map,u=i.logarithmicDepthBuffer;let d=i.precision;const f={MeshDepthMaterial:"depth",MeshDistanceMaterial:"distance",MeshNormalMaterial:"normal",MeshBasicMaterial:"basic",MeshLambertMaterial:"lambert",MeshPhongMaterial:"phong",MeshToonMaterial:"toon",MeshStandardMaterial:"physical",MeshPhysicalMaterial:"physical",MeshMatcapMaterial:"matcap",LineBasicMaterial:"basic",LineDashedMaterial:"dashed",PointsMaterial:"points",ShadowMaterial:"shadow",SpriteMaterial:"sprite"};function p(y){return c.add(y),y===0?"uv":`uv${y}`}function v(y,A,C,I,P,V){const X=I.fog,L=P.geometry,B=y.isMeshStandardMaterial||y.isMeshLambertMaterial||y.isMeshPhongMaterial?I.environment:null,k=y.isMeshStandardMaterial||y.isMeshLambertMaterial&&!y.envMap||y.isMeshPhongMaterial&&!y.envMap,$=t.get(y.envMap||B,k),tt=$&&$.mapping===uh?$.image.height:null,J=f[y.type];y.precision!==null&&(d=i.getMaxPrecision(y.precision),d!==y.precision&&It("WebGLProgram.getParameters:",y.precision,"not supported, using",d,"instead."));const it=L.morphAttributes.position||L.morphAttributes.normal||L.morphAttributes.color,at=it!==void 0?it.length:0;let Xt=0;L.morphAttributes.position!==void 0&&(Xt=1),L.morphAttributes.normal!==void 0&&(Xt=2),L.morphAttributes.color!==void 0&&(Xt=3);let ee,Kt,q,rt;if(J){const wt=cs[J];ee=wt.vertexShader,Kt=wt.fragmentShader}else{ee=y.vertexShader,Kt=y.fragmentShader;const wt=o.getVertexShaderStage(y),ni=o.getFragmentShaderStage(y);o.update(y,wt,ni),q=wt.id,rt=ni.id}const nt=a.getRenderTarget(),z=a.state.buffers.depth.getReversed(),Rt=P.isInstancedMesh===!0,Ft=P.isBatchedMesh===!0,Pt=!!y.map,St=!!y.matcap,zt=!!$,Bt=!!y.aoMap,Ht=!!y.lightMap,ye=!!y.bumpMap&&y.wireframe===!1,Se=!!y.normalMap,ei=!!y.displacementMap,Ve=!!y.emissiveMap,ii=!!y.metalnessMap,fi=!!y.roughnessMap,N=y.anisotropy>0,Ji=y.clearcoat>0,_e=y.dispersion>0,D=y.iridescence>0,_=y.sheen>0,U=y.transmission>0,W=N&&!!y.anisotropyMap,K=Ji&&!!y.clearcoatMap,ot=Ji&&!!y.clearcoatNormalMap,lt=Ji&&!!y.clearcoatRoughnessMap,Z=D&&!!y.iridescenceMap,Q=D&&!!y.iridescenceThicknessMap,ht=_&&!!y.sheenColorMap,Lt=_&&!!y.sheenRoughnessMap,ft=!!y.specularMap,ut=!!y.specularColorMap,kt=!!y.specularIntensityMap,Gt=U&&!!y.transmissionMap,jt=U&&!!y.thicknessMap,O=!!y.gradientMap,ct=!!y.alphaMap,j=y.alphaTest>0,dt=!!y.alphaHash,vt=!!y.extensions;let et=Ms;y.toneMapped&&(nt===null||nt.isXRRenderTarget===!0)&&(et=a.toneMapping);const Ct={shaderID:J,shaderType:y.type,shaderName:y.name,vertexShader:ee,fragmentShader:Kt,defines:y.defines,customVertexShaderID:q,customFragmentShaderID:rt,isRawShaderMaterial:y.isRawShaderMaterial===!0,glslVersion:y.glslVersion,precision:d,batching:Ft,batchingColor:Ft&&P._colorsTexture!==null,instancing:Rt,instancingColor:Rt&&P.instanceColor!==null,instancingMorph:Rt&&P.morphTexture!==null,outputColorSpace:nt===null?a.outputColorSpace:nt.isXRRenderTarget===!0?nt.texture.colorSpace:ce.workingColorSpace,alphaToCoverage:!!y.alphaToCoverage,map:Pt,matcap:St,envMap:zt,envMapMode:zt&&$.mapping,envMapCubeUVHeight:tt,aoMap:Bt,lightMap:Ht,bumpMap:ye,normalMap:Se,displacementMap:ei,emissiveMap:Ve,normalMapObjectSpace:Se&&y.normalMapType===mM,normalMapTangentSpace:Se&&y.normalMapType===Gl,packedNormalMap:Se&&y.normalMapType===Gl&&wb(y.normalMap.format),metalnessMap:ii,roughnessMap:fi,anisotropy:N,anisotropyMap:W,clearcoat:Ji,clearcoatMap:K,clearcoatNormalMap:ot,clearcoatRoughnessMap:lt,dispersion:_e,iridescence:D,iridescenceMap:Z,iridescenceThicknessMap:Q,sheen:_,sheenColorMap:ht,sheenRoughnessMap:Lt,specularMap:ft,specularColorMap:ut,specularIntensityMap:kt,transmission:U,transmissionMap:Gt,thicknessMap:jt,gradientMap:O,opaque:y.transparent===!1&&y.blending===dr&&y.alphaToCoverage===!1,alphaMap:ct,alphaTest:j,alphaHash:dt,combine:y.combine,mapUv:Pt&&p(y.map.channel),aoMapUv:Bt&&p(y.aoMap.channel),lightMapUv:Ht&&p(y.lightMap.channel),bumpMapUv:ye&&p(y.bumpMap.channel),normalMapUv:Se&&p(y.normalMap.channel),displacementMapUv:ei&&p(y.displacementMap.channel),emissiveMapUv:Ve&&p(y.emissiveMap.channel),metalnessMapUv:ii&&p(y.metalnessMap.channel),roughnessMapUv:fi&&p(y.roughnessMap.channel),anisotropyMapUv:W&&p(y.anisotropyMap.channel),clearcoatMapUv:K&&p(y.clearcoatMap.channel),clearcoatNormalMapUv:ot&&p(y.clearcoatNormalMap.channel),clearcoatRoughnessMapUv:lt&&p(y.clearcoatRoughnessMap.channel),iridescenceMapUv:Z&&p(y.iridescenceMap.channel),iridescenceThicknessMapUv:Q&&p(y.iridescenceThicknessMap.channel),sheenColorMapUv:ht&&p(y.sheenColorMap.channel),sheenRoughnessMapUv:Lt&&p(y.sheenRoughnessMap.channel),specularMapUv:ft&&p(y.specularMap.channel),specularColorMapUv:ut&&p(y.specularColorMap.channel),specularIntensityMapUv:kt&&p(y.specularIntensityMap.channel),transmissionMapUv:Gt&&p(y.transmissionMap.channel),thicknessMapUv:jt&&p(y.thicknessMap.channel),alphaMapUv:ct&&p(y.alphaMap.channel),vertexTangents:!!L.attributes.tangent&&(Se||N),vertexNormals:!!L.attributes.normal,vertexColors:y.vertexColors,vertexAlphas:y.vertexColors===!0&&!!L.attributes.color&&L.attributes.color.itemSize===4,pointsUvs:P.isPoints===!0&&!!L.attributes.uv&&(Pt||ct),fog:!!X,useFog:y.fog===!0,fogExp2:!!X&&X.isFogExp2,flatShading:y.wireframe===!1&&(y.flatShading===!0||L.attributes.normal===void 0&&Se===!1&&(y.isMeshLambertMaterial||y.isMeshPhongMaterial||y.isMeshStandardMaterial||y.isMeshPhysicalMaterial)),sizeAttenuation:y.sizeAttenuation===!0,logarithmicDepthBuffer:u,reversedDepthBuffer:z,skinning:P.isSkinnedMesh===!0,hasPositionAttribute:L.attributes.position!==void 0,morphTargets:L.morphAttributes.position!==void 0,morphNormals:L.morphAttributes.normal!==void 0,morphColors:L.morphAttributes.color!==void 0,morphTargetsCount:at,morphTextureStride:Xt,numDirLights:A.directional.length,numPointLights:A.point.length,numSpotLights:A.spot.length,numSpotLightMaps:A.spotLightMap.length,numRectAreaLights:A.rectArea.length,numHemiLights:A.hemi.length,numDirLightShadows:A.directionalShadowMap.length,numPointLightShadows:A.pointShadowMap.length,numSpotLightShadows:A.spotShadowMap.length,numSpotLightShadowsWithMaps:A.numSpotLightShadowsWithMaps,numLightProbes:A.numLightProbes,numLightProbeGrids:V.length,numClippingPlanes:s.numPlanes,numClipIntersection:s.numIntersection,dithering:y.dithering,shadowMapEnabled:a.shadowMap.enabled&&C.length>0,shadowMapType:a.shadowMap.type,toneMapping:et,decodeVideoTexture:Pt&&y.map.isVideoTexture===!0&&ce.getTransfer(y.map.colorSpace)===we,decodeVideoTextureEmissive:Ve&&y.emissiveMap.isVideoTexture===!0&&ce.getTransfer(y.emissiveMap.colorSpace)===we,premultipliedAlpha:y.premultipliedAlpha,doubleSided:y.side===xn,flipSided:y.side===qe,useDepthPacking:y.depthPacking>=0,depthPacking:y.depthPacking||0,index0AttributeName:y.index0AttributeName,extensionClipCullDistance:vt&&y.extensions.clipCullDistance===!0&&e.has("WEBGL_clip_cull_distance"),extensionMultiDraw:(vt&&y.extensions.multiDraw===!0||Ft)&&e.has("WEBGL_multi_draw"),rendererExtensionParallelShaderCompile:e.has("KHR_parallel_shader_compile"),customProgramCacheKey:y.customProgramCacheKey()};return Ct.vertexUv1s=c.has(1),Ct.vertexUv2s=c.has(2),Ct.vertexUv3s=c.has(3),c.clear(),Ct}function m(y){const A=[];if(y.shaderID?A.push(y.shaderID):(A.push(y.customVertexShaderID),A.push(y.customFragmentShaderID)),y.defines!==void 0)for(const C in y.defines)A.push(C),A.push(y.defines[C]);return y.isRawShaderMaterial===!1&&(g(A,y),S(A,y),A.push(a.outputColorSpace)),A.push(y.customProgramCacheKey),A.join()}function g(y,A){y.push(A.precision),y.push(A.outputColorSpace),y.push(A.envMapMode),y.push(A.envMapCubeUVHeight),y.push(A.mapUv),y.push(A.alphaMapUv),y.push(A.lightMapUv),y.push(A.aoMapUv),y.push(A.bumpMapUv),y.push(A.normalMapUv),y.push(A.displacementMapUv),y.push(A.emissiveMapUv),y.push(A.metalnessMapUv),y.push(A.roughnessMapUv),y.push(A.anisotropyMapUv),y.push(A.clearcoatMapUv),y.push(A.clearcoatNormalMapUv),y.push(A.clearcoatRoughnessMapUv),y.push(A.iridescenceMapUv),y.push(A.iridescenceThicknessMapUv),y.push(A.sheenColorMapUv),y.push(A.sheenRoughnessMapUv),y.push(A.specularMapUv),y.push(A.specularColorMapUv),y.push(A.specularIntensityMapUv),y.push(A.transmissionMapUv),y.push(A.thicknessMapUv),y.push(A.combine),y.push(A.fogExp2),y.push(A.sizeAttenuation),y.push(A.morphTargetsCount),y.push(A.morphAttributeCount),y.push(A.numDirLights),y.push(A.numPointLights),y.push(A.numSpotLights),y.push(A.numSpotLightMaps),y.push(A.numHemiLights),y.push(A.numRectAreaLights),y.push(A.numDirLightShadows),y.push(A.numPointLightShadows),y.push(A.numSpotLightShadows),y.push(A.numSpotLightShadowsWithMaps),y.push(A.numLightProbes),y.push(A.shadowMapType),y.push(A.toneMapping),y.push(A.numClippingPlanes),y.push(A.numClipIntersection),y.push(A.depthPacking)}function S(y,A){r.disableAll(),A.instancing&&r.enable(0),A.instancingColor&&r.enable(1),A.instancingMorph&&r.enable(2),A.matcap&&r.enable(3),A.envMap&&r.enable(4),A.normalMapObjectSpace&&r.enable(5),A.normalMapTangentSpace&&r.enable(6),A.clearcoat&&r.enable(7),A.iridescence&&r.enable(8),A.alphaTest&&r.enable(9),A.vertexColors&&r.enable(10),A.vertexAlphas&&r.enable(11),A.vertexUv1s&&r.enable(12),A.vertexUv2s&&r.enable(13),A.vertexUv3s&&r.enable(14),A.vertexTangents&&r.enable(15),A.anisotropy&&r.enable(16),A.alphaHash&&r.enable(17),A.batching&&r.enable(18),A.dispersion&&r.enable(19),A.batchingColor&&r.enable(20),A.gradientMap&&r.enable(21),A.packedNormalMap&&r.enable(22),A.vertexNormals&&r.enable(23),y.push(r.mask),r.disableAll(),A.fog&&r.enable(0),A.useFog&&r.enable(1),A.flatShading&&r.enable(2),A.logarithmicDepthBuffer&&r.enable(3),A.reversedDepthBuffer&&r.enable(4),A.skinning&&r.enable(5),A.morphTargets&&r.enable(6),A.morphNormals&&r.enable(7),A.morphColors&&r.enable(8),A.premultipliedAlpha&&r.enable(9),A.shadowMapEnabled&&r.enable(10),A.doubleSided&&r.enable(11),A.flipSided&&r.enable(12),A.useDepthPacking&&r.enable(13),A.dithering&&r.enable(14),A.transmission&&r.enable(15),A.sheen&&r.enable(16),A.opaque&&r.enable(17),A.pointsUvs&&r.enable(18),A.decodeVideoTexture&&r.enable(19),A.decodeVideoTextureEmissive&&r.enable(20),A.alphaToCoverage&&r.enable(21),A.numLightProbeGrids>0&&r.enable(22),A.hasPositionAttribute&&r.enable(23),y.push(r.mask)}function x(y){const A=f[y.type];let C;if(A){const I=cs[A];C=xx.clone(I.uniforms)}else C=y.uniforms;return C}function M(y,A){let C=h.get(A);return C!==void 0?++C.usedTimes:(C=new yb(a,A,y,n),l.push(C),h.set(A,C)),C}function b(y){if(--y.usedTimes===0){const A=l.indexOf(y);l[A]=l[l.length-1],l.pop(),h.delete(y.cacheKey),y.destroy()}}function w(y){o.remove(y)}function T(){o.dispose()}return{getParameters:v,getProgramCacheKey:m,getUniforms:x,acquireProgram:M,releaseProgram:b,releaseShaderCache:w,programs:l,dispose:T}}function Ab(){let a=new WeakMap;function t(r){return a.has(r)}function e(r){let o=a.get(r);return o===void 0&&(o={},a.set(r,o)),o}function i(r){a.delete(r)}function n(r,o,c){a.get(r)[o]=c}function s(){a=new WeakMap}return{has:t,get:e,remove:i,update:n,dispose:s}}function Tb(a,t){return a.groupOrder!==t.groupOrder?a.groupOrder-t.groupOrder:a.renderOrder!==t.renderOrder?a.renderOrder-t.renderOrder:a.material.id!==t.material.id?a.material.id-t.material.id:a.materialVariant!==t.materialVariant?a.materialVariant-t.materialVariant:a.z!==t.z?a.z-t.z:a.id-t.id}function fm(a,t){return a.groupOrder!==t.groupOrder?a.groupOrder-t.groupOrder:a.renderOrder!==t.renderOrder?a.renderOrder-t.renderOrder:a.z!==t.z?t.z-a.z:a.id-t.id}function pm(){const a=[];let t=0;const e=[],i=[],n=[];function s(){t=0,e.length=0,i.length=0,n.length=0}function r(d){let f=0;return d.isInstancedMesh&&(f+=2),d.isSkinnedMesh&&(f+=1),f}function o(d,f,p,v,m,g){let S=a[t];return S===void 0?(S={id:d.id,object:d,geometry:f,material:p,materialVariant:r(d),groupOrder:v,renderOrder:d.renderOrder,z:m,group:g},a[t]=S):(S.id=d.id,S.object=d,S.geometry=f,S.material=p,S.materialVariant=r(d),S.groupOrder=v,S.renderOrder=d.renderOrder,S.z=m,S.group=g),t++,S}function c(d,f,p,v,m,g){const S=o(d,f,p,v,m,g);p.transmission>0?i.push(S):p.transparent===!0?n.push(S):e.push(S)}function l(d,f,p,v,m,g){const S=o(d,f,p,v,m,g);p.transmission>0?i.unshift(S):p.transparent===!0?n.unshift(S):e.unshift(S)}function h(d,f,p){e.length>1&&e.sort(d||Tb),i.length>1&&i.sort(f||fm),n.length>1&&n.sort(f||fm),p&&(e.reverse(),i.reverse(),n.reverse())}function u(){for(let d=t,f=a.length;d<f;d++){const p=a[d];if(p.id===null)break;p.id=null,p.object=null,p.geometry=null,p.material=null,p.group=null}}return{opaque:e,transmissive:i,transparent:n,init:s,push:c,unshift:l,finish:u,sort:h}}function Rb(){let a=new WeakMap;function t(i,n){const s=a.get(i);let r;return s===void 0?(r=new pm,a.set(i,[r])):n>=s.length?(r=new pm,s.push(r)):r=s[n],r}function e(){a=new WeakMap}return{get:t,dispose:e}}function Db(){const a={};return{get:function(t){if(a[t.id]!==void 0)return a[t.id];let e;switch(t.type){case"DirectionalLight":e={direction:new R,color:new st};break;case"SpotLight":e={position:new R,direction:new R,color:new st,distance:0,coneCos:0,penumbraCos:0,decay:0};break;case"PointLight":e={position:new R,color:new st,distance:0,decay:0};break;case"HemisphereLight":e={direction:new R,skyColor:new st,groundColor:new st};break;case"RectAreaLight":e={color:new st,position:new R,halfWidth:new R,halfHeight:new R};break}return a[t.id]=e,e}}}function Ib(){const a={};return{get:function(t){if(a[t.id]!==void 0)return a[t.id];let e;switch(t.type){case"DirectionalLight":e={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new Mt};break;case"SpotLight":e={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new Mt};break;case"PointLight":e={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new Mt,shadowCameraNear:1,shadowCameraFar:1e3};break}return a[t.id]=e,e}}}let Cb=0;function Pb(a,t){return(t.castShadow?2:0)-(a.castShadow?2:0)+(t.map?1:0)-(a.map?1:0)}function Lb(a){const t=new Db,e=Ib(),i={version:0,hash:{directionalLength:-1,pointLength:-1,spotLength:-1,rectAreaLength:-1,hemiLength:-1,numDirectionalShadows:-1,numPointShadows:-1,numSpotShadows:-1,numSpotMaps:-1,numLightProbes:-1},ambient:[0,0,0],probe:[],directional:[],directionalShadow:[],directionalShadowMap:[],directionalShadowMatrix:[],spot:[],spotLightMap:[],spotShadow:[],spotShadowMap:[],spotLightMatrix:[],rectArea:[],rectAreaLTC1:null,rectAreaLTC2:null,point:[],pointShadow:[],pointShadowMap:[],pointShadowMatrix:[],hemi:[],numSpotLightShadowsWithMaps:0,numLightProbes:0};for(let l=0;l<9;l++)i.probe.push(new R);const n=new R,s=new te,r=new te;function o(l){let h=0,u=0,d=0;for(let A=0;A<9;A++)i.probe[A].set(0,0,0);let f=0,p=0,v=0,m=0,g=0,S=0,x=0,M=0,b=0,w=0,T=0;l.sort(Pb);for(let A=0,C=l.length;A<C;A++){const I=l[A],P=I.color,V=I.intensity,X=I.distance;let L=null;if(I.shadow&&I.shadow.map&&(I.shadow.map.texture.format===Yr?L=I.shadow.map.texture:L=I.shadow.map.depthTexture||I.shadow.map.texture),I.isAmbientLight)h+=P.r*V,u+=P.g*V,d+=P.b*V;else if(I.isLightProbe){for(let B=0;B<9;B++)i.probe[B].addScaledVector(I.sh.coefficients[B],V);T++}else if(I.isDirectionalLight){const B=t.get(I);if(B.color.copy(I.color).multiplyScalar(I.intensity),I.castShadow){const k=I.shadow,$=e.get(I);$.shadowIntensity=k.intensity,$.shadowBias=k.bias,$.shadowNormalBias=k.normalBias,$.shadowRadius=k.radius,$.shadowMapSize=k.mapSize,i.directionalShadow[f]=$,i.directionalShadowMap[f]=L,i.directionalShadowMatrix[f]=I.shadow.matrix,S++}i.directional[f]=B,f++}else if(I.isSpotLight){const B=t.get(I);B.position.setFromMatrixPosition(I.matrixWorld),B.color.copy(P).multiplyScalar(V),B.distance=X,B.coneCos=Math.cos(I.angle),B.penumbraCos=Math.cos(I.angle*(1-I.penumbra)),B.decay=I.decay,i.spot[v]=B;const k=I.shadow;if(I.map&&(i.spotLightMap[b]=I.map,b++,k.updateMatrices(I),I.castShadow&&w++),i.spotLightMatrix[v]=k.matrix,I.castShadow){const $=e.get(I);$.shadowIntensity=k.intensity,$.shadowBias=k.bias,$.shadowNormalBias=k.normalBias,$.shadowRadius=k.radius,$.shadowMapSize=k.mapSize,i.spotShadow[v]=$,i.spotShadowMap[v]=L,M++}v++}else if(I.isRectAreaLight){const B=t.get(I);B.color.copy(P).multiplyScalar(V),B.halfWidth.set(I.width*.5,0,0),B.halfHeight.set(0,I.height*.5,0),i.rectArea[m]=B,m++}else if(I.isPointLight){const B=t.get(I);if(B.color.copy(I.color).multiplyScalar(I.intensity),B.distance=I.distance,B.decay=I.decay,I.castShadow){const k=I.shadow,$=e.get(I);$.shadowIntensity=k.intensity,$.shadowBias=k.bias,$.shadowNormalBias=k.normalBias,$.shadowRadius=k.radius,$.shadowMapSize=k.mapSize,$.shadowCameraNear=k.camera.near,$.shadowCameraFar=k.camera.far,i.pointShadow[p]=$,i.pointShadowMap[p]=L,i.pointShadowMatrix[p]=I.shadow.matrix,x++}i.point[p]=B,p++}else if(I.isHemisphereLight){const B=t.get(I);B.skyColor.copy(I.color).multiplyScalar(V),B.groundColor.copy(I.groundColor).multiplyScalar(V),i.hemi[g]=B,g++}}m>0&&(a.has("OES_texture_float_linear")===!0?(i.rectAreaLTC1=pt.LTC_FLOAT_1,i.rectAreaLTC2=pt.LTC_FLOAT_2):(i.rectAreaLTC1=pt.LTC_HALF_1,i.rectAreaLTC2=pt.LTC_HALF_2)),i.ambient[0]=h,i.ambient[1]=u,i.ambient[2]=d;const y=i.hash;(y.directionalLength!==f||y.pointLength!==p||y.spotLength!==v||y.rectAreaLength!==m||y.hemiLength!==g||y.numDirectionalShadows!==S||y.numPointShadows!==x||y.numSpotShadows!==M||y.numSpotMaps!==b||y.numLightProbes!==T)&&(i.directional.length=f,i.spot.length=v,i.rectArea.length=m,i.point.length=p,i.hemi.length=g,i.directionalShadow.length=S,i.directionalShadowMap.length=S,i.pointShadow.length=x,i.pointShadowMap.length=x,i.spotShadow.length=M,i.spotShadowMap.length=M,i.directionalShadowMatrix.length=S,i.pointShadowMatrix.length=x,i.spotLightMatrix.length=M+b-w,i.spotLightMap.length=b,i.numSpotLightShadowsWithMaps=w,i.numLightProbes=T,y.directionalLength=f,y.pointLength=p,y.spotLength=v,y.rectAreaLength=m,y.hemiLength=g,y.numDirectionalShadows=S,y.numPointShadows=x,y.numSpotShadows=M,y.numSpotMaps=b,y.numLightProbes=T,i.version=Cb++)}function c(l,h){let u=0,d=0,f=0,p=0,v=0;const m=h.matrixWorldInverse;for(let g=0,S=l.length;g<S;g++){const x=l[g];if(x.isDirectionalLight){const M=i.directional[u];M.direction.setFromMatrixPosition(x.matrixWorld),n.setFromMatrixPosition(x.target.matrixWorld),M.direction.sub(n),M.direction.transformDirection(m),u++}else if(x.isSpotLight){const M=i.spot[f];M.position.setFromMatrixPosition(x.matrixWorld),M.position.applyMatrix4(m),M.direction.setFromMatrixPosition(x.matrixWorld),n.setFromMatrixPosition(x.target.matrixWorld),M.direction.sub(n),M.direction.transformDirection(m),f++}else if(x.isRectAreaLight){const M=i.rectArea[p];M.position.setFromMatrixPosition(x.matrixWorld),M.position.applyMatrix4(m),r.identity(),s.copy(x.matrixWorld),s.premultiply(m),r.extractRotation(s),M.halfWidth.set(x.width*.5,0,0),M.halfHeight.set(0,x.height*.5,0),M.halfWidth.applyMatrix4(r),M.halfHeight.applyMatrix4(r),p++}else if(x.isPointLight){const M=i.point[d];M.position.setFromMatrixPosition(x.matrixWorld),M.position.applyMatrix4(m),d++}else if(x.isHemisphereLight){const M=i.hemi[v];M.direction.setFromMatrixPosition(x.matrixWorld),M.direction.transformDirection(m),v++}}}return{setup:o,setupView:c,state:i}}function mm(a){const t=new Lb(a),e=[],i=[],n=[];function s(d){u.camera=d,e.length=0,i.length=0,n.length=0}function r(d){e.push(d)}function o(d){i.push(d)}function c(d){n.push(d)}function l(){t.setup(e)}function h(d){t.setupView(e,d)}const u={lightsArray:e,shadowsArray:i,lightProbeGridArray:n,camera:null,lights:t,transmissionRenderTarget:{},textureUnits:0};return{init:s,state:u,setupLights:l,setupLightsView:h,pushLight:r,pushShadow:o,pushLightProbeGrid:c}}function Ob(a){let t=new WeakMap;function e(n,s=0){const r=t.get(n);let o;return r===void 0?(o=new mm(a),t.set(n,[o])):s>=r.length?(o=new mm(a),r.push(o)):o=r[s],o}function i(){t=new WeakMap}return{get:e,dispose:i}}const Nb=`void main() {
5476
+ `+it)}else L!==""?It("WebGLProgram: Program Info Log:",L):(B===""||k==="")&&(tt=!1);tt&&(I.diagnostics={runnable:$,programLog:L,vertexShader:{log:B,prefix:m},fragmentShader:{log:k,prefix:g}})}n.deleteShader(b),n.deleteShader(w),y=new Pl(n,v),A=rb(n,v)}let y;this.getUniforms=function(){return y===void 0&&T(this),y};let A;this.getAttributes=function(){return A===void 0&&T(this),A};let C=e.rendererExtensionParallelShaderCompile===!1;return this.isReady=function(){return C===!1&&(C=n.getProgramParameter(v,K_)),C},this.destroy=function(){i.releaseStatesOfProgram(this),n.deleteProgram(v),this.program=void 0},this.type=e.shaderType,this.name=e.shaderName,this.id=Z_++,this.cacheKey=t,this.usedTimes=1,this.program=v,this.vertexShader=b,this.fragmentShader=w,this}let Sb=0;class _b{constructor(){this.shaderCache=new Map,this.materialCache=new Map}update(t,e,i){const n=this._getShaderCacheForMaterial(t);return n.has(e)===!1&&(n.add(e),e.usedTimes++),n.has(i)===!1&&(n.add(i),i.usedTimes++),this}remove(t){const e=this.materialCache.get(t);for(const i of e)i.usedTimes--,i.usedTimes===0&&this.shaderCache.delete(i.code);return this.materialCache.delete(t),this}getVertexShaderStage(t){return this._getShaderStage(t.vertexShader)}getFragmentShaderStage(t){return this._getShaderStage(t.fragmentShader)}dispose(){this.shaderCache.clear(),this.materialCache.clear()}_getShaderCacheForMaterial(t){const e=this.materialCache;let i=e.get(t);return i===void 0&&(i=new Set,e.set(t,i)),i}_getShaderStage(t){const e=this.shaderCache;let i=e.get(t);return i===void 0&&(i=new bb(t),e.set(t,i)),i}}class bb{constructor(t){this.id=Sb++,this.code=t,this.usedTimes=0}}function wb(a){return a===Yr||a===kl||a===zl}function Eb(a,t,e,i,n,s){const r=new z0,o=new _b,c=new Set,l=[],h=new Map,u=i.logarithmicDepthBuffer;let d=i.precision;const f={MeshDepthMaterial:"depth",MeshDistanceMaterial:"distance",MeshNormalMaterial:"normal",MeshBasicMaterial:"basic",MeshLambertMaterial:"lambert",MeshPhongMaterial:"phong",MeshToonMaterial:"toon",MeshStandardMaterial:"physical",MeshPhysicalMaterial:"physical",MeshMatcapMaterial:"matcap",LineBasicMaterial:"basic",LineDashedMaterial:"dashed",PointsMaterial:"points",ShadowMaterial:"shadow",SpriteMaterial:"sprite"};function p(y){return c.add(y),y===0?"uv":`uv${y}`}function v(y,A,C,I,P,V){const X=I.fog,L=P.geometry,B=y.isMeshStandardMaterial||y.isMeshLambertMaterial||y.isMeshPhongMaterial?I.environment:null,k=y.isMeshStandardMaterial||y.isMeshLambertMaterial&&!y.envMap||y.isMeshPhongMaterial&&!y.envMap,$=t.get(y.envMap||B,k),tt=$&&$.mapping===uh?$.image.height:null,J=f[y.type];y.precision!==null&&(d=i.getMaxPrecision(y.precision),d!==y.precision&&It("WebGLProgram.getParameters:",y.precision,"not supported, using",d,"instead."));const it=L.morphAttributes.position||L.morphAttributes.normal||L.morphAttributes.color,at=it!==void 0?it.length:0;let Xt=0;L.morphAttributes.position!==void 0&&(Xt=1),L.morphAttributes.normal!==void 0&&(Xt=2),L.morphAttributes.color!==void 0&&(Xt=3);let ee,Kt,q,rt;if(J){const wt=cs[J];ee=wt.vertexShader,Kt=wt.fragmentShader}else{ee=y.vertexShader,Kt=y.fragmentShader;const wt=o.getVertexShaderStage(y),ni=o.getFragmentShaderStage(y);o.update(y,wt,ni),q=wt.id,rt=ni.id}const nt=a.getRenderTarget(),z=a.state.buffers.depth.getReversed(),Rt=P.isInstancedMesh===!0,Ft=P.isBatchedMesh===!0,Pt=!!y.map,St=!!y.matcap,zt=!!$,Bt=!!y.aoMap,Ht=!!y.lightMap,ye=!!y.bumpMap&&y.wireframe===!1,Se=!!y.normalMap,ei=!!y.displacementMap,Ve=!!y.emissiveMap,ii=!!y.metalnessMap,fi=!!y.roughnessMap,N=y.anisotropy>0,Ji=y.clearcoat>0,_e=y.dispersion>0,D=y.iridescence>0,_=y.sheen>0,U=y.transmission>0,W=N&&!!y.anisotropyMap,K=Ji&&!!y.clearcoatMap,ot=Ji&&!!y.clearcoatNormalMap,lt=Ji&&!!y.clearcoatRoughnessMap,Z=D&&!!y.iridescenceMap,Q=D&&!!y.iridescenceThicknessMap,ht=_&&!!y.sheenColorMap,Lt=_&&!!y.sheenRoughnessMap,ft=!!y.specularMap,ut=!!y.specularColorMap,kt=!!y.specularIntensityMap,Vt=U&&!!y.transmissionMap,jt=U&&!!y.thicknessMap,O=!!y.gradientMap,ct=!!y.alphaMap,j=y.alphaTest>0,dt=!!y.alphaHash,vt=!!y.extensions;let et=Ms;y.toneMapped&&(nt===null||nt.isXRRenderTarget===!0)&&(et=a.toneMapping);const Ct={shaderID:J,shaderType:y.type,shaderName:y.name,vertexShader:ee,fragmentShader:Kt,defines:y.defines,customVertexShaderID:q,customFragmentShaderID:rt,isRawShaderMaterial:y.isRawShaderMaterial===!0,glslVersion:y.glslVersion,precision:d,batching:Ft,batchingColor:Ft&&P._colorsTexture!==null,instancing:Rt,instancingColor:Rt&&P.instanceColor!==null,instancingMorph:Rt&&P.morphTexture!==null,outputColorSpace:nt===null?a.outputColorSpace:nt.isXRRenderTarget===!0?nt.texture.colorSpace:ce.workingColorSpace,alphaToCoverage:!!y.alphaToCoverage,map:Pt,matcap:St,envMap:zt,envMapMode:zt&&$.mapping,envMapCubeUVHeight:tt,aoMap:Bt,lightMap:Ht,bumpMap:ye,normalMap:Se,displacementMap:ei,emissiveMap:Ve,normalMapObjectSpace:Se&&y.normalMapType===mM,normalMapTangentSpace:Se&&y.normalMapType===Gl,packedNormalMap:Se&&y.normalMapType===Gl&&wb(y.normalMap.format),metalnessMap:ii,roughnessMap:fi,anisotropy:N,anisotropyMap:W,clearcoat:Ji,clearcoatMap:K,clearcoatNormalMap:ot,clearcoatRoughnessMap:lt,dispersion:_e,iridescence:D,iridescenceMap:Z,iridescenceThicknessMap:Q,sheen:_,sheenColorMap:ht,sheenRoughnessMap:Lt,specularMap:ft,specularColorMap:ut,specularIntensityMap:kt,transmission:U,transmissionMap:Vt,thicknessMap:jt,gradientMap:O,opaque:y.transparent===!1&&y.blending===dr&&y.alphaToCoverage===!1,alphaMap:ct,alphaTest:j,alphaHash:dt,combine:y.combine,mapUv:Pt&&p(y.map.channel),aoMapUv:Bt&&p(y.aoMap.channel),lightMapUv:Ht&&p(y.lightMap.channel),bumpMapUv:ye&&p(y.bumpMap.channel),normalMapUv:Se&&p(y.normalMap.channel),displacementMapUv:ei&&p(y.displacementMap.channel),emissiveMapUv:Ve&&p(y.emissiveMap.channel),metalnessMapUv:ii&&p(y.metalnessMap.channel),roughnessMapUv:fi&&p(y.roughnessMap.channel),anisotropyMapUv:W&&p(y.anisotropyMap.channel),clearcoatMapUv:K&&p(y.clearcoatMap.channel),clearcoatNormalMapUv:ot&&p(y.clearcoatNormalMap.channel),clearcoatRoughnessMapUv:lt&&p(y.clearcoatRoughnessMap.channel),iridescenceMapUv:Z&&p(y.iridescenceMap.channel),iridescenceThicknessMapUv:Q&&p(y.iridescenceThicknessMap.channel),sheenColorMapUv:ht&&p(y.sheenColorMap.channel),sheenRoughnessMapUv:Lt&&p(y.sheenRoughnessMap.channel),specularMapUv:ft&&p(y.specularMap.channel),specularColorMapUv:ut&&p(y.specularColorMap.channel),specularIntensityMapUv:kt&&p(y.specularIntensityMap.channel),transmissionMapUv:Vt&&p(y.transmissionMap.channel),thicknessMapUv:jt&&p(y.thicknessMap.channel),alphaMapUv:ct&&p(y.alphaMap.channel),vertexTangents:!!L.attributes.tangent&&(Se||N),vertexNormals:!!L.attributes.normal,vertexColors:y.vertexColors,vertexAlphas:y.vertexColors===!0&&!!L.attributes.color&&L.attributes.color.itemSize===4,pointsUvs:P.isPoints===!0&&!!L.attributes.uv&&(Pt||ct),fog:!!X,useFog:y.fog===!0,fogExp2:!!X&&X.isFogExp2,flatShading:y.wireframe===!1&&(y.flatShading===!0||L.attributes.normal===void 0&&Se===!1&&(y.isMeshLambertMaterial||y.isMeshPhongMaterial||y.isMeshStandardMaterial||y.isMeshPhysicalMaterial)),sizeAttenuation:y.sizeAttenuation===!0,logarithmicDepthBuffer:u,reversedDepthBuffer:z,skinning:P.isSkinnedMesh===!0,hasPositionAttribute:L.attributes.position!==void 0,morphTargets:L.morphAttributes.position!==void 0,morphNormals:L.morphAttributes.normal!==void 0,morphColors:L.morphAttributes.color!==void 0,morphTargetsCount:at,morphTextureStride:Xt,numDirLights:A.directional.length,numPointLights:A.point.length,numSpotLights:A.spot.length,numSpotLightMaps:A.spotLightMap.length,numRectAreaLights:A.rectArea.length,numHemiLights:A.hemi.length,numDirLightShadows:A.directionalShadowMap.length,numPointLightShadows:A.pointShadowMap.length,numSpotLightShadows:A.spotShadowMap.length,numSpotLightShadowsWithMaps:A.numSpotLightShadowsWithMaps,numLightProbes:A.numLightProbes,numLightProbeGrids:V.length,numClippingPlanes:s.numPlanes,numClipIntersection:s.numIntersection,dithering:y.dithering,shadowMapEnabled:a.shadowMap.enabled&&C.length>0,shadowMapType:a.shadowMap.type,toneMapping:et,decodeVideoTexture:Pt&&y.map.isVideoTexture===!0&&ce.getTransfer(y.map.colorSpace)===we,decodeVideoTextureEmissive:Ve&&y.emissiveMap.isVideoTexture===!0&&ce.getTransfer(y.emissiveMap.colorSpace)===we,premultipliedAlpha:y.premultipliedAlpha,doubleSided:y.side===xn,flipSided:y.side===qe,useDepthPacking:y.depthPacking>=0,depthPacking:y.depthPacking||0,index0AttributeName:y.index0AttributeName,extensionClipCullDistance:vt&&y.extensions.clipCullDistance===!0&&e.has("WEBGL_clip_cull_distance"),extensionMultiDraw:(vt&&y.extensions.multiDraw===!0||Ft)&&e.has("WEBGL_multi_draw"),rendererExtensionParallelShaderCompile:e.has("KHR_parallel_shader_compile"),customProgramCacheKey:y.customProgramCacheKey()};return Ct.vertexUv1s=c.has(1),Ct.vertexUv2s=c.has(2),Ct.vertexUv3s=c.has(3),c.clear(),Ct}function m(y){const A=[];if(y.shaderID?A.push(y.shaderID):(A.push(y.customVertexShaderID),A.push(y.customFragmentShaderID)),y.defines!==void 0)for(const C in y.defines)A.push(C),A.push(y.defines[C]);return y.isRawShaderMaterial===!1&&(g(A,y),S(A,y),A.push(a.outputColorSpace)),A.push(y.customProgramCacheKey),A.join()}function g(y,A){y.push(A.precision),y.push(A.outputColorSpace),y.push(A.envMapMode),y.push(A.envMapCubeUVHeight),y.push(A.mapUv),y.push(A.alphaMapUv),y.push(A.lightMapUv),y.push(A.aoMapUv),y.push(A.bumpMapUv),y.push(A.normalMapUv),y.push(A.displacementMapUv),y.push(A.emissiveMapUv),y.push(A.metalnessMapUv),y.push(A.roughnessMapUv),y.push(A.anisotropyMapUv),y.push(A.clearcoatMapUv),y.push(A.clearcoatNormalMapUv),y.push(A.clearcoatRoughnessMapUv),y.push(A.iridescenceMapUv),y.push(A.iridescenceThicknessMapUv),y.push(A.sheenColorMapUv),y.push(A.sheenRoughnessMapUv),y.push(A.specularMapUv),y.push(A.specularColorMapUv),y.push(A.specularIntensityMapUv),y.push(A.transmissionMapUv),y.push(A.thicknessMapUv),y.push(A.combine),y.push(A.fogExp2),y.push(A.sizeAttenuation),y.push(A.morphTargetsCount),y.push(A.morphAttributeCount),y.push(A.numDirLights),y.push(A.numPointLights),y.push(A.numSpotLights),y.push(A.numSpotLightMaps),y.push(A.numHemiLights),y.push(A.numRectAreaLights),y.push(A.numDirLightShadows),y.push(A.numPointLightShadows),y.push(A.numSpotLightShadows),y.push(A.numSpotLightShadowsWithMaps),y.push(A.numLightProbes),y.push(A.shadowMapType),y.push(A.toneMapping),y.push(A.numClippingPlanes),y.push(A.numClipIntersection),y.push(A.depthPacking)}function S(y,A){r.disableAll(),A.instancing&&r.enable(0),A.instancingColor&&r.enable(1),A.instancingMorph&&r.enable(2),A.matcap&&r.enable(3),A.envMap&&r.enable(4),A.normalMapObjectSpace&&r.enable(5),A.normalMapTangentSpace&&r.enable(6),A.clearcoat&&r.enable(7),A.iridescence&&r.enable(8),A.alphaTest&&r.enable(9),A.vertexColors&&r.enable(10),A.vertexAlphas&&r.enable(11),A.vertexUv1s&&r.enable(12),A.vertexUv2s&&r.enable(13),A.vertexUv3s&&r.enable(14),A.vertexTangents&&r.enable(15),A.anisotropy&&r.enable(16),A.alphaHash&&r.enable(17),A.batching&&r.enable(18),A.dispersion&&r.enable(19),A.batchingColor&&r.enable(20),A.gradientMap&&r.enable(21),A.packedNormalMap&&r.enable(22),A.vertexNormals&&r.enable(23),y.push(r.mask),r.disableAll(),A.fog&&r.enable(0),A.useFog&&r.enable(1),A.flatShading&&r.enable(2),A.logarithmicDepthBuffer&&r.enable(3),A.reversedDepthBuffer&&r.enable(4),A.skinning&&r.enable(5),A.morphTargets&&r.enable(6),A.morphNormals&&r.enable(7),A.morphColors&&r.enable(8),A.premultipliedAlpha&&r.enable(9),A.shadowMapEnabled&&r.enable(10),A.doubleSided&&r.enable(11),A.flipSided&&r.enable(12),A.useDepthPacking&&r.enable(13),A.dithering&&r.enable(14),A.transmission&&r.enable(15),A.sheen&&r.enable(16),A.opaque&&r.enable(17),A.pointsUvs&&r.enable(18),A.decodeVideoTexture&&r.enable(19),A.decodeVideoTextureEmissive&&r.enable(20),A.alphaToCoverage&&r.enable(21),A.numLightProbeGrids>0&&r.enable(22),A.hasPositionAttribute&&r.enable(23),y.push(r.mask)}function x(y){const A=f[y.type];let C;if(A){const I=cs[A];C=xx.clone(I.uniforms)}else C=y.uniforms;return C}function M(y,A){let C=h.get(A);return C!==void 0?++C.usedTimes:(C=new yb(a,A,y,n),l.push(C),h.set(A,C)),C}function b(y){if(--y.usedTimes===0){const A=l.indexOf(y);l[A]=l[l.length-1],l.pop(),h.delete(y.cacheKey),y.destroy()}}function w(y){o.remove(y)}function T(){o.dispose()}return{getParameters:v,getProgramCacheKey:m,getUniforms:x,acquireProgram:M,releaseProgram:b,releaseShaderCache:w,programs:l,dispose:T}}function Ab(){let a=new WeakMap;function t(r){return a.has(r)}function e(r){let o=a.get(r);return o===void 0&&(o={},a.set(r,o)),o}function i(r){a.delete(r)}function n(r,o,c){a.get(r)[o]=c}function s(){a=new WeakMap}return{has:t,get:e,remove:i,update:n,dispose:s}}function Tb(a,t){return a.groupOrder!==t.groupOrder?a.groupOrder-t.groupOrder:a.renderOrder!==t.renderOrder?a.renderOrder-t.renderOrder:a.material.id!==t.material.id?a.material.id-t.material.id:a.materialVariant!==t.materialVariant?a.materialVariant-t.materialVariant:a.z!==t.z?a.z-t.z:a.id-t.id}function fm(a,t){return a.groupOrder!==t.groupOrder?a.groupOrder-t.groupOrder:a.renderOrder!==t.renderOrder?a.renderOrder-t.renderOrder:a.z!==t.z?t.z-a.z:a.id-t.id}function pm(){const a=[];let t=0;const e=[],i=[],n=[];function s(){t=0,e.length=0,i.length=0,n.length=0}function r(d){let f=0;return d.isInstancedMesh&&(f+=2),d.isSkinnedMesh&&(f+=1),f}function o(d,f,p,v,m,g){let S=a[t];return S===void 0?(S={id:d.id,object:d,geometry:f,material:p,materialVariant:r(d),groupOrder:v,renderOrder:d.renderOrder,z:m,group:g},a[t]=S):(S.id=d.id,S.object=d,S.geometry=f,S.material=p,S.materialVariant=r(d),S.groupOrder=v,S.renderOrder=d.renderOrder,S.z=m,S.group=g),t++,S}function c(d,f,p,v,m,g){const S=o(d,f,p,v,m,g);p.transmission>0?i.push(S):p.transparent===!0?n.push(S):e.push(S)}function l(d,f,p,v,m,g){const S=o(d,f,p,v,m,g);p.transmission>0?i.unshift(S):p.transparent===!0?n.unshift(S):e.unshift(S)}function h(d,f,p){e.length>1&&e.sort(d||Tb),i.length>1&&i.sort(f||fm),n.length>1&&n.sort(f||fm),p&&(e.reverse(),i.reverse(),n.reverse())}function u(){for(let d=t,f=a.length;d<f;d++){const p=a[d];if(p.id===null)break;p.id=null,p.object=null,p.geometry=null,p.material=null,p.group=null}}return{opaque:e,transmissive:i,transparent:n,init:s,push:c,unshift:l,finish:u,sort:h}}function Rb(){let a=new WeakMap;function t(i,n){const s=a.get(i);let r;return s===void 0?(r=new pm,a.set(i,[r])):n>=s.length?(r=new pm,s.push(r)):r=s[n],r}function e(){a=new WeakMap}return{get:t,dispose:e}}function Db(){const a={};return{get:function(t){if(a[t.id]!==void 0)return a[t.id];let e;switch(t.type){case"DirectionalLight":e={direction:new R,color:new st};break;case"SpotLight":e={position:new R,direction:new R,color:new st,distance:0,coneCos:0,penumbraCos:0,decay:0};break;case"PointLight":e={position:new R,color:new st,distance:0,decay:0};break;case"HemisphereLight":e={direction:new R,skyColor:new st,groundColor:new st};break;case"RectAreaLight":e={color:new st,position:new R,halfWidth:new R,halfHeight:new R};break}return a[t.id]=e,e}}}function Ib(){const a={};return{get:function(t){if(a[t.id]!==void 0)return a[t.id];let e;switch(t.type){case"DirectionalLight":e={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new Mt};break;case"SpotLight":e={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new Mt};break;case"PointLight":e={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new Mt,shadowCameraNear:1,shadowCameraFar:1e3};break}return a[t.id]=e,e}}}let Cb=0;function Pb(a,t){return(t.castShadow?2:0)-(a.castShadow?2:0)+(t.map?1:0)-(a.map?1:0)}function Lb(a){const t=new Db,e=Ib(),i={version:0,hash:{directionalLength:-1,pointLength:-1,spotLength:-1,rectAreaLength:-1,hemiLength:-1,numDirectionalShadows:-1,numPointShadows:-1,numSpotShadows:-1,numSpotMaps:-1,numLightProbes:-1},ambient:[0,0,0],probe:[],directional:[],directionalShadow:[],directionalShadowMap:[],directionalShadowMatrix:[],spot:[],spotLightMap:[],spotShadow:[],spotShadowMap:[],spotLightMatrix:[],rectArea:[],rectAreaLTC1:null,rectAreaLTC2:null,point:[],pointShadow:[],pointShadowMap:[],pointShadowMatrix:[],hemi:[],numSpotLightShadowsWithMaps:0,numLightProbes:0};for(let l=0;l<9;l++)i.probe.push(new R);const n=new R,s=new te,r=new te;function o(l){let h=0,u=0,d=0;for(let A=0;A<9;A++)i.probe[A].set(0,0,0);let f=0,p=0,v=0,m=0,g=0,S=0,x=0,M=0,b=0,w=0,T=0;l.sort(Pb);for(let A=0,C=l.length;A<C;A++){const I=l[A],P=I.color,V=I.intensity,X=I.distance;let L=null;if(I.shadow&&I.shadow.map&&(I.shadow.map.texture.format===Yr?L=I.shadow.map.texture:L=I.shadow.map.depthTexture||I.shadow.map.texture),I.isAmbientLight)h+=P.r*V,u+=P.g*V,d+=P.b*V;else if(I.isLightProbe){for(let B=0;B<9;B++)i.probe[B].addScaledVector(I.sh.coefficients[B],V);T++}else if(I.isDirectionalLight){const B=t.get(I);if(B.color.copy(I.color).multiplyScalar(I.intensity),I.castShadow){const k=I.shadow,$=e.get(I);$.shadowIntensity=k.intensity,$.shadowBias=k.bias,$.shadowNormalBias=k.normalBias,$.shadowRadius=k.radius,$.shadowMapSize=k.mapSize,i.directionalShadow[f]=$,i.directionalShadowMap[f]=L,i.directionalShadowMatrix[f]=I.shadow.matrix,S++}i.directional[f]=B,f++}else if(I.isSpotLight){const B=t.get(I);B.position.setFromMatrixPosition(I.matrixWorld),B.color.copy(P).multiplyScalar(V),B.distance=X,B.coneCos=Math.cos(I.angle),B.penumbraCos=Math.cos(I.angle*(1-I.penumbra)),B.decay=I.decay,i.spot[v]=B;const k=I.shadow;if(I.map&&(i.spotLightMap[b]=I.map,b++,k.updateMatrices(I),I.castShadow&&w++),i.spotLightMatrix[v]=k.matrix,I.castShadow){const $=e.get(I);$.shadowIntensity=k.intensity,$.shadowBias=k.bias,$.shadowNormalBias=k.normalBias,$.shadowRadius=k.radius,$.shadowMapSize=k.mapSize,i.spotShadow[v]=$,i.spotShadowMap[v]=L,M++}v++}else if(I.isRectAreaLight){const B=t.get(I);B.color.copy(P).multiplyScalar(V),B.halfWidth.set(I.width*.5,0,0),B.halfHeight.set(0,I.height*.5,0),i.rectArea[m]=B,m++}else if(I.isPointLight){const B=t.get(I);if(B.color.copy(I.color).multiplyScalar(I.intensity),B.distance=I.distance,B.decay=I.decay,I.castShadow){const k=I.shadow,$=e.get(I);$.shadowIntensity=k.intensity,$.shadowBias=k.bias,$.shadowNormalBias=k.normalBias,$.shadowRadius=k.radius,$.shadowMapSize=k.mapSize,$.shadowCameraNear=k.camera.near,$.shadowCameraFar=k.camera.far,i.pointShadow[p]=$,i.pointShadowMap[p]=L,i.pointShadowMatrix[p]=I.shadow.matrix,x++}i.point[p]=B,p++}else if(I.isHemisphereLight){const B=t.get(I);B.skyColor.copy(I.color).multiplyScalar(V),B.groundColor.copy(I.groundColor).multiplyScalar(V),i.hemi[g]=B,g++}}m>0&&(a.has("OES_texture_float_linear")===!0?(i.rectAreaLTC1=pt.LTC_FLOAT_1,i.rectAreaLTC2=pt.LTC_FLOAT_2):(i.rectAreaLTC1=pt.LTC_HALF_1,i.rectAreaLTC2=pt.LTC_HALF_2)),i.ambient[0]=h,i.ambient[1]=u,i.ambient[2]=d;const y=i.hash;(y.directionalLength!==f||y.pointLength!==p||y.spotLength!==v||y.rectAreaLength!==m||y.hemiLength!==g||y.numDirectionalShadows!==S||y.numPointShadows!==x||y.numSpotShadows!==M||y.numSpotMaps!==b||y.numLightProbes!==T)&&(i.directional.length=f,i.spot.length=v,i.rectArea.length=m,i.point.length=p,i.hemi.length=g,i.directionalShadow.length=S,i.directionalShadowMap.length=S,i.pointShadow.length=x,i.pointShadowMap.length=x,i.spotShadow.length=M,i.spotShadowMap.length=M,i.directionalShadowMatrix.length=S,i.pointShadowMatrix.length=x,i.spotLightMatrix.length=M+b-w,i.spotLightMap.length=b,i.numSpotLightShadowsWithMaps=w,i.numLightProbes=T,y.directionalLength=f,y.pointLength=p,y.spotLength=v,y.rectAreaLength=m,y.hemiLength=g,y.numDirectionalShadows=S,y.numPointShadows=x,y.numSpotShadows=M,y.numSpotMaps=b,y.numLightProbes=T,i.version=Cb++)}function c(l,h){let u=0,d=0,f=0,p=0,v=0;const m=h.matrixWorldInverse;for(let g=0,S=l.length;g<S;g++){const x=l[g];if(x.isDirectionalLight){const M=i.directional[u];M.direction.setFromMatrixPosition(x.matrixWorld),n.setFromMatrixPosition(x.target.matrixWorld),M.direction.sub(n),M.direction.transformDirection(m),u++}else if(x.isSpotLight){const M=i.spot[f];M.position.setFromMatrixPosition(x.matrixWorld),M.position.applyMatrix4(m),M.direction.setFromMatrixPosition(x.matrixWorld),n.setFromMatrixPosition(x.target.matrixWorld),M.direction.sub(n),M.direction.transformDirection(m),f++}else if(x.isRectAreaLight){const M=i.rectArea[p];M.position.setFromMatrixPosition(x.matrixWorld),M.position.applyMatrix4(m),r.identity(),s.copy(x.matrixWorld),s.premultiply(m),r.extractRotation(s),M.halfWidth.set(x.width*.5,0,0),M.halfHeight.set(0,x.height*.5,0),M.halfWidth.applyMatrix4(r),M.halfHeight.applyMatrix4(r),p++}else if(x.isPointLight){const M=i.point[d];M.position.setFromMatrixPosition(x.matrixWorld),M.position.applyMatrix4(m),d++}else if(x.isHemisphereLight){const M=i.hemi[v];M.direction.setFromMatrixPosition(x.matrixWorld),M.direction.transformDirection(m),v++}}}return{setup:o,setupView:c,state:i}}function mm(a){const t=new Lb(a),e=[],i=[],n=[];function s(d){u.camera=d,e.length=0,i.length=0,n.length=0}function r(d){e.push(d)}function o(d){i.push(d)}function c(d){n.push(d)}function l(){t.setup(e)}function h(d){t.setupView(e,d)}const u={lightsArray:e,shadowsArray:i,lightProbeGridArray:n,camera:null,lights:t,transmissionRenderTarget:{},textureUnits:0};return{init:s,state:u,setupLights:l,setupLightsView:h,pushLight:r,pushShadow:o,pushLightProbeGrid:c}}function Ob(a){let t=new WeakMap;function e(n,s=0){const r=t.get(n);let o;return r===void 0?(o=new mm(a),t.set(n,[o])):s>=r.length?(o=new mm(a),r.push(o)):o=r[s],o}function i(){t=new WeakMap}return{get:e,dispose:i}}const Nb=`void main() {
5477
5477
  gl_Position = vec4( position, 1.0 );
5478
5478
  }`,Fb=`uniform sampler2D shadow_pass;
5479
5479
  uniform vec2 resolution;
@@ -5500,7 +5500,7 @@ void main() {
5500
5500
  squared_mean = squared_mean / samples;
5501
5501
  float std_dev = sqrt( max( 0.0, squared_mean - mean * mean ) );
5502
5502
  gl_FragColor = vec4( mean, std_dev, 0.0, 1.0 );
5503
- }`,Ub=[new R(1,0,0),new R(-1,0,0),new R(0,1,0),new R(0,-1,0),new R(0,0,1),new R(0,0,-1)],kb=[new R(0,-1,0),new R(0,-1,0),new R(0,0,1),new R(0,0,-1),new R(0,-1,0),new R(0,-1,0)],gm=new te,_o=new R,fu=new R;function zb(a,t,e){let i=new G0;const n=new Mt,s=new Mt,r=new ae,o=new bx,c=new wx,l={},h=e.maxTextureSize,u={[pr]:qe,[qe]:pr,[xn]:xn},d=new de({defines:{VSM_SAMPLES:8},uniforms:{shadow_pass:{value:null},resolution:{value:new Mt},radius:{value:4}},vertexShader:Nb,fragmentShader:Fb}),f=d.clone();f.defines.HORIZONTAL_PASS=1;const p=new se;p.setAttribute("position",new Jt(new Float32Array([-1,-1,.5,3,-1,.5,-1,3,.5]),3));const v=new bt(p,d),m=this;this.enabled=!1,this.autoUpdate=!0,this.needsUpdate=!1,this.type=Ho;let g=this.type;this.render=function(w,T,y){if(m.enabled===!1||m.autoUpdate===!1&&m.needsUpdate===!1||w.length===0)return;this.type===X2&&(It("WebGLShadowMap: PCFSoftShadowMap has been deprecated. Using PCFShadowMap instead."),this.type=Ho);const A=a.getRenderTarget(),C=a.getActiveCubeFace(),I=a.getActiveMipmapLevel(),P=a.state;P.setBlending(vs),P.buffers.depth.getReversed()===!0?P.buffers.color.setClear(0,0,0,0):P.buffers.color.setClear(1,1,1,1),P.buffers.depth.setTest(!0),P.setScissorTest(!1);const V=g!==this.type;V&&T.traverse(function(X){X.material&&(Array.isArray(X.material)?X.material.forEach(L=>L.needsUpdate=!0):X.material.needsUpdate=!0)});for(let X=0,L=w.length;X<L;X++){const B=w[X],k=B.shadow;if(k===void 0){It("WebGLShadowMap:",B,"has no shadow.");continue}if(k.autoUpdate===!1&&k.needsUpdate===!1)continue;n.copy(k.mapSize);const $=k.getFrameExtents();n.multiply($),s.copy(k.mapSize),(n.x>h||n.y>h)&&(n.x>h&&(s.x=Math.floor(h/$.x),n.x=s.x*$.x,k.mapSize.x=s.x),n.y>h&&(s.y=Math.floor(h/$.y),n.y=s.y*$.y,k.mapSize.y=s.y));const tt=a.state.buffers.depth.getReversed();if(k.camera._reversedDepth=tt,k.map===null||V===!0){if(k.map!==null&&(k.map.depthTexture!==null&&(k.map.depthTexture.dispose(),k.map.depthTexture=null),k.map.dispose()),this.type===Lo){if(B.isPointLight){It("WebGLShadowMap: VSM shadow maps are not supported for PointLights. Use PCF or BasicShadowMap instead.");continue}k.map=new Qe(n.x,n.y,{format:Yr,type:$e,minFilter:le,magFilter:le,generateMipmaps:!1}),k.map.texture.name=B.name+".shadowMap",k.map.depthTexture=new mr(n.x,n.y,Ui),k.map.depthTexture.name=B.name+".shadowMapDepth",k.map.depthTexture.format=Fs,k.map.depthTexture.compareFunction=null,k.map.depthTexture.minFilter=Ce,k.map.depthTexture.magFilter=Ce}else B.isPointLight?(k.map=new lc(n.x),k.map.depthTexture=new vx(n.x,Nn)):(k.map=new Qe(n.x,n.y),k.map.depthTexture=new mr(n.x,n.y,Nn)),k.map.depthTexture.name=B.name+".shadowMap",k.map.depthTexture.format=Fs,this.type===Ho?(k.map.depthTexture.compareFunction=tt?F0:N0,k.map.depthTexture.minFilter=le,k.map.depthTexture.magFilter=le):(k.map.depthTexture.compareFunction=null,k.map.depthTexture.minFilter=Ce,k.map.depthTexture.magFilter=Ce);k.camera.updateProjectionMatrix()}const J=k.map.isWebGLCubeRenderTarget?6:1;for(let it=0;it<J;it++){if(k.map.isWebGLCubeRenderTarget)a.setRenderTarget(k.map,it),a.clear();else{it===0&&(a.setRenderTarget(k.map),a.clear());const at=k.getViewport(it);r.set(s.x*at.x,s.y*at.y,s.x*at.z,s.y*at.w),P.viewport(r)}if(B.isPointLight){const at=k.camera,Xt=k.matrix,ee=B.distance||at.far;ee!==at.far&&(at.far=ee,at.updateProjectionMatrix()),_o.setFromMatrixPosition(B.matrixWorld),at.position.copy(_o),fu.copy(at.position),fu.add(Ub[it]),at.up.copy(kb[it]),at.lookAt(fu),at.updateMatrixWorld(),Xt.makeTranslation(-_o.x,-_o.y,-_o.z),gm.multiplyMatrices(at.projectionMatrix,at.matrixWorldInverse),k._frustum.setFromProjectionMatrix(gm,at.coordinateSystem,at.reversedDepth)}else k.updateMatrices(B);i=k.getFrustum(),M(T,y,k.camera,B,this.type)}k.isPointLightShadow!==!0&&this.type===Lo&&S(k,y),k.needsUpdate=!1}g=this.type,m.needsUpdate=!1,a.setRenderTarget(A,C,I)};function S(w,T){const y=t.update(v);d.defines.VSM_SAMPLES!==w.blurSamples&&(d.defines.VSM_SAMPLES=w.blurSamples,f.defines.VSM_SAMPLES=w.blurSamples,d.needsUpdate=!0,f.needsUpdate=!0),w.mapPass===null&&(w.mapPass=new Qe(n.x,n.y,{format:Yr,type:$e})),d.uniforms.shadow_pass.value=w.map.depthTexture,d.uniforms.resolution.value=w.mapSize,d.uniforms.radius.value=w.radius,a.setRenderTarget(w.mapPass),a.clear(),a.renderBufferDirect(T,null,y,d,v,null),f.uniforms.shadow_pass.value=w.mapPass.texture,f.uniforms.resolution.value=w.mapSize,f.uniforms.radius.value=w.radius,a.setRenderTarget(w.map),a.clear(),a.renderBufferDirect(T,null,y,f,v,null)}function x(w,T,y,A){let C=null;const I=y.isPointLight===!0?w.customDistanceMaterial:w.customDepthMaterial;if(I!==void 0)C=I;else if(C=y.isPointLight===!0?c:o,a.localClippingEnabled&&T.clipShadows===!0&&Array.isArray(T.clippingPlanes)&&T.clippingPlanes.length!==0||T.displacementMap&&T.displacementScale!==0||T.alphaMap&&T.alphaTest>0||T.map&&T.alphaTest>0||T.alphaToCoverage===!0){const P=C.uuid,V=T.uuid;let X=l[P];X===void 0&&(X={},l[P]=X);let L=X[V];L===void 0&&(L=C.clone(),X[V]=L,T.addEventListener("dispose",b)),C=L}if(C.visible=T.visible,C.wireframe=T.wireframe,A===Lo?C.side=T.shadowSide!==null?T.shadowSide:T.side:C.side=T.shadowSide!==null?T.shadowSide:u[T.side],C.alphaMap=T.alphaMap,C.alphaTest=T.alphaToCoverage===!0?.5:T.alphaTest,C.map=T.map,C.clipShadows=T.clipShadows,C.clippingPlanes=T.clippingPlanes,C.clipIntersection=T.clipIntersection,C.displacementMap=T.displacementMap,C.displacementScale=T.displacementScale,C.displacementBias=T.displacementBias,C.wireframeLinewidth=T.wireframeLinewidth,C.linewidth=T.linewidth,y.isPointLight===!0&&C.isMeshDistanceMaterial===!0){const P=a.properties.get(C);P.light=y}return C}function M(w,T,y,A,C){if(w.visible===!1)return;if(w.layers.test(T.layers)&&(w.isMesh||w.isLine||w.isPoints)&&(w.castShadow||w.receiveShadow&&C===Lo)&&(!w.frustumCulled||i.intersectsObject(w))){w.modelViewMatrix.multiplyMatrices(y.matrixWorldInverse,w.matrixWorld);const V=t.update(w),X=w.material;if(Array.isArray(X)){const L=V.groups;for(let B=0,k=L.length;B<k;B++){const $=L[B],tt=X[$.materialIndex];if(tt&&tt.visible){const J=x(w,tt,A,C);w.onBeforeShadow(a,w,T,y,V,J,$),a.renderBufferDirect(y,null,V,J,w,$),w.onAfterShadow(a,w,T,y,V,J,$)}}}else if(X.visible){const L=x(w,X,A,C);w.onBeforeShadow(a,w,T,y,V,L,null),a.renderBufferDirect(y,null,V,L,w,null),w.onAfterShadow(a,w,T,y,V,L,null)}}const P=w.children;for(let V=0,X=P.length;V<X;V++)M(P[V],T,y,A,C)}function b(w){w.target.removeEventListener("dispose",b);for(const y in l){const A=l[y],C=w.target.uuid;C in A&&(A[C].dispose(),delete A[C])}}}function Bb(a,t){function e(){let O=!1;const ct=new ae;let j=null;const dt=new ae(0,0,0,0);return{setMask:function(vt){j!==vt&&!O&&(a.colorMask(vt,vt,vt,vt),j=vt)},setLocked:function(vt){O=vt},setClear:function(vt,et,Ct,wt,ni){ni===!0&&(vt*=wt,et*=wt,Ct*=wt),ct.set(vt,et,Ct,wt),dt.equals(ct)===!1&&(a.clearColor(vt,et,Ct,wt),dt.copy(ct))},reset:function(){O=!1,j=null,dt.set(-1,0,0,0)}}}function i(){let O=!1,ct=!1,j=null,dt=null,vt=null;return{setReversed:function(et){if(ct!==et){const Ct=t.get("EXT_clip_control");et?Ct.clipControlEXT(Ct.LOWER_LEFT_EXT,Ct.ZERO_TO_ONE_EXT):Ct.clipControlEXT(Ct.LOWER_LEFT_EXT,Ct.NEGATIVE_ONE_TO_ONE_EXT),ct=et;const wt=vt;vt=null,this.setClear(wt)}},getReversed:function(){return ct},setTest:function(et){et?nt(a.DEPTH_TEST):z(a.DEPTH_TEST)},setMask:function(et){j!==et&&!O&&(a.depthMask(et),j=et)},setFunc:function(et){if(ct&&(et=AM[et]),dt!==et){switch(et){case ed:a.depthFunc(a.NEVER);break;case id:a.depthFunc(a.ALWAYS);break;case nd:a.depthFunc(a.LESS);break;case Ja:a.depthFunc(a.LEQUAL);break;case sd:a.depthFunc(a.EQUAL);break;case rd:a.depthFunc(a.GEQUAL);break;case ad:a.depthFunc(a.GREATER);break;case od:a.depthFunc(a.NOTEQUAL);break;default:a.depthFunc(a.LEQUAL)}dt=et}},setLocked:function(et){O=et},setClear:function(et){vt!==et&&(vt=et,ct&&(et=1-et),a.clearDepth(et))},reset:function(){O=!1,j=null,dt=null,vt=null,ct=!1}}}function n(){let O=!1,ct=null,j=null,dt=null,vt=null,et=null,Ct=null,wt=null,ni=null;return{setTest:function(Ne){O||(Ne?nt(a.STENCIL_TEST):z(a.STENCIL_TEST))},setMask:function(Ne){ct!==Ne&&!O&&(a.stencilMask(Ne),ct=Ne)},setFunc:function(Ne,jn,Qn){(j!==Ne||dt!==jn||vt!==Qn)&&(a.stencilFunc(Ne,jn,Qn),j=Ne,dt=jn,vt=Qn)},setOp:function(Ne,jn,Qn){(et!==Ne||Ct!==jn||wt!==Qn)&&(a.stencilOp(Ne,jn,Qn),et=Ne,Ct=jn,wt=Qn)},setLocked:function(Ne){O=Ne},setClear:function(Ne){ni!==Ne&&(a.clearStencil(Ne),ni=Ne)},reset:function(){O=!1,ct=null,j=null,dt=null,vt=null,et=null,Ct=null,wt=null,ni=null}}}const s=new e,r=new i,o=new n,c=new WeakMap,l=new WeakMap;let h={},u={},d={},f=new WeakMap,p=[],v=null,m=!1,g=null,S=null,x=null,M=null,b=null,w=null,T=null,y=new st(0,0,0),A=0,C=!1,I=null,P=null,V=null,X=null,L=null;const B=a.getParameter(a.MAX_COMBINED_TEXTURE_IMAGE_UNITS);let k=!1,$=0;const tt=a.getParameter(a.VERSION);tt.indexOf("WebGL")!==-1?($=parseFloat(/^WebGL (\d)/.exec(tt)[1]),k=$>=1):tt.indexOf("OpenGL ES")!==-1&&($=parseFloat(/^OpenGL ES (\d)/.exec(tt)[1]),k=$>=2);let J=null,it={};const at=a.getParameter(a.SCISSOR_BOX),Xt=a.getParameter(a.VIEWPORT),ee=new ae().fromArray(at),Kt=new ae().fromArray(Xt);function q(O,ct,j,dt){const vt=new Uint8Array(4),et=a.createTexture();a.bindTexture(O,et),a.texParameteri(O,a.TEXTURE_MIN_FILTER,a.NEAREST),a.texParameteri(O,a.TEXTURE_MAG_FILTER,a.NEAREST);for(let Ct=0;Ct<j;Ct++)O===a.TEXTURE_3D||O===a.TEXTURE_2D_ARRAY?a.texImage3D(ct,0,a.RGBA,1,1,dt,0,a.RGBA,a.UNSIGNED_BYTE,vt):a.texImage2D(ct+Ct,0,a.RGBA,1,1,0,a.RGBA,a.UNSIGNED_BYTE,vt);return et}const rt={};rt[a.TEXTURE_2D]=q(a.TEXTURE_2D,a.TEXTURE_2D,1),rt[a.TEXTURE_CUBE_MAP]=q(a.TEXTURE_CUBE_MAP,a.TEXTURE_CUBE_MAP_POSITIVE_X,6),rt[a.TEXTURE_2D_ARRAY]=q(a.TEXTURE_2D_ARRAY,a.TEXTURE_2D_ARRAY,1,1),rt[a.TEXTURE_3D]=q(a.TEXTURE_3D,a.TEXTURE_3D,1,1),s.setClear(0,0,0,1),r.setClear(1),o.setClear(0),nt(a.DEPTH_TEST),r.setFunc(Ja),ye(!1),Se(Jf),nt(a.CULL_FACE),Bt(vs);function nt(O){h[O]!==!0&&(a.enable(O),h[O]=!0)}function z(O){h[O]!==!1&&(a.disable(O),h[O]=!1)}function Rt(O,ct){return d[O]!==ct?(a.bindFramebuffer(O,ct),d[O]=ct,O===a.DRAW_FRAMEBUFFER&&(d[a.FRAMEBUFFER]=ct),O===a.FRAMEBUFFER&&(d[a.DRAW_FRAMEBUFFER]=ct),!0):!1}function Ft(O,ct){let j=p,dt=!1;if(O){j=f.get(ct),j===void 0&&(j=[],f.set(ct,j));const vt=O.textures;if(j.length!==vt.length||j[0]!==a.COLOR_ATTACHMENT0){for(let et=0,Ct=vt.length;et<Ct;et++)j[et]=a.COLOR_ATTACHMENT0+et;j.length=vt.length,dt=!0}}else j[0]!==a.BACK&&(j[0]=a.BACK,dt=!0);dt&&a.drawBuffers(j)}function Pt(O){return v!==O?(a.useProgram(O),v=O,!0):!1}const St={[Dr]:a.FUNC_ADD,[Y2]:a.FUNC_SUBTRACT,[q2]:a.FUNC_REVERSE_SUBTRACT};St[$2]=a.MIN,St[K2]=a.MAX;const zt={[Oo]:a.ZERO,[ic]:a.ONE,[Z2]:a.SRC_COLOR,[td]:a.SRC_ALPHA,[iM]:a.SRC_ALPHA_SATURATE,[tM]:a.DST_COLOR,[j2]:a.DST_ALPHA,[J2]:a.ONE_MINUS_SRC_COLOR,[nc]:a.ONE_MINUS_SRC_ALPHA,[eM]:a.ONE_MINUS_DST_COLOR,[Q2]:a.ONE_MINUS_DST_ALPHA,[nM]:a.CONSTANT_COLOR,[sM]:a.ONE_MINUS_CONSTANT_COLOR,[rM]:a.CONSTANT_ALPHA,[aM]:a.ONE_MINUS_CONSTANT_ALPHA};function Bt(O,ct,j,dt,vt,et,Ct,wt,ni,Ne){if(O===vs){m===!0&&(z(a.BLEND),m=!1);return}if(m===!1&&(nt(a.BLEND),m=!0),O!==dc){if(O!==g||Ne!==C){if((S!==Dr||b!==Dr)&&(a.blendEquation(a.FUNC_ADD),S=Dr,b=Dr),Ne)switch(O){case dr:a.blendFuncSeparate(a.ONE,a.ONE_MINUS_SRC_ALPHA,a.ONE,a.ONE_MINUS_SRC_ALPHA);break;case Ai:a.blendFunc(a.ONE,a.ONE);break;case jf:a.blendFuncSeparate(a.ZERO,a.ONE_MINUS_SRC_COLOR,a.ZERO,a.ONE);break;case Qf:a.blendFuncSeparate(a.DST_COLOR,a.ONE_MINUS_SRC_ALPHA,a.ZERO,a.ONE);break;default:Wt("WebGLState: Invalid blending: ",O);break}else switch(O){case dr:a.blendFuncSeparate(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA,a.ONE,a.ONE_MINUS_SRC_ALPHA);break;case Ai:a.blendFuncSeparate(a.SRC_ALPHA,a.ONE,a.ONE,a.ONE);break;case jf:Wt("WebGLState: SubtractiveBlending requires material.premultipliedAlpha = true");break;case Qf:Wt("WebGLState: MultiplyBlending requires material.premultipliedAlpha = true");break;default:Wt("WebGLState: Invalid blending: ",O);break}x=null,M=null,w=null,T=null,y.set(0,0,0),A=0,g=O,C=Ne}return}vt=vt||ct,et=et||j,Ct=Ct||dt,(ct!==S||vt!==b)&&(a.blendEquationSeparate(St[ct],St[vt]),S=ct,b=vt),(j!==x||dt!==M||et!==w||Ct!==T)&&(a.blendFuncSeparate(zt[j],zt[dt],zt[et],zt[Ct]),x=j,M=dt,w=et,T=Ct),(wt.equals(y)===!1||ni!==A)&&(a.blendColor(wt.r,wt.g,wt.b,ni),y.copy(wt),A=ni),g=O,C=!1}function Ht(O,ct){O.side===xn?z(a.CULL_FACE):nt(a.CULL_FACE);let j=O.side===qe;ct&&(j=!j),ye(j),O.blending===dr&&O.transparent===!1?Bt(vs):Bt(O.blending,O.blendEquation,O.blendSrc,O.blendDst,O.blendEquationAlpha,O.blendSrcAlpha,O.blendDstAlpha,O.blendColor,O.blendAlpha,O.premultipliedAlpha),r.setFunc(O.depthFunc),r.setTest(O.depthTest),r.setMask(O.depthWrite),s.setMask(O.colorWrite);const dt=O.stencilWrite;o.setTest(dt),dt&&(o.setMask(O.stencilWriteMask),o.setFunc(O.stencilFunc,O.stencilRef,O.stencilFuncMask),o.setOp(O.stencilFail,O.stencilZFail,O.stencilZPass)),Ve(O.polygonOffset,O.polygonOffsetFactor,O.polygonOffsetUnits),O.alphaToCoverage===!0?nt(a.SAMPLE_ALPHA_TO_COVERAGE):z(a.SAMPLE_ALPHA_TO_COVERAGE)}function ye(O){I!==O&&(O?a.frontFace(a.CW):a.frontFace(a.CCW),I=O)}function Se(O){O!==V2?(nt(a.CULL_FACE),O!==P&&(O===Jf?a.cullFace(a.BACK):O===W2?a.cullFace(a.FRONT):a.cullFace(a.FRONT_AND_BACK))):z(a.CULL_FACE),P=O}function ei(O){O!==V&&(k&&a.lineWidth(O),V=O)}function Ve(O,ct,j){O?(nt(a.POLYGON_OFFSET_FILL),(X!==ct||L!==j)&&(X=ct,L=j,r.getReversed()&&(ct=-ct),a.polygonOffset(ct,j))):z(a.POLYGON_OFFSET_FILL)}function ii(O){O?nt(a.SCISSOR_TEST):z(a.SCISSOR_TEST)}function fi(O){O===void 0&&(O=a.TEXTURE0+B-1),J!==O&&(a.activeTexture(O),J=O)}function N(O,ct,j){j===void 0&&(J===null?j=a.TEXTURE0+B-1:j=J);let dt=it[j];dt===void 0&&(dt={type:void 0,texture:void 0},it[j]=dt),(dt.type!==O||dt.texture!==ct)&&(J!==j&&(a.activeTexture(j),J=j),a.bindTexture(O,ct||rt[O]),dt.type=O,dt.texture=ct)}function Ji(){const O=it[J];O!==void 0&&O.type!==void 0&&(a.bindTexture(O.type,null),O.type=void 0,O.texture=void 0)}function _e(){try{a.compressedTexImage2D(...arguments)}catch(O){Wt("WebGLState:",O)}}function D(){try{a.compressedTexImage3D(...arguments)}catch(O){Wt("WebGLState:",O)}}function _(){try{a.texSubImage2D(...arguments)}catch(O){Wt("WebGLState:",O)}}function U(){try{a.texSubImage3D(...arguments)}catch(O){Wt("WebGLState:",O)}}function W(){try{a.compressedTexSubImage2D(...arguments)}catch(O){Wt("WebGLState:",O)}}function K(){try{a.compressedTexSubImage3D(...arguments)}catch(O){Wt("WebGLState:",O)}}function ot(){try{a.texStorage2D(...arguments)}catch(O){Wt("WebGLState:",O)}}function lt(){try{a.texStorage3D(...arguments)}catch(O){Wt("WebGLState:",O)}}function Z(){try{a.texImage2D(...arguments)}catch(O){Wt("WebGLState:",O)}}function Q(){try{a.texImage3D(...arguments)}catch(O){Wt("WebGLState:",O)}}function ht(O){return u[O]!==void 0?u[O]:a.getParameter(O)}function Lt(O,ct){u[O]!==ct&&(a.pixelStorei(O,ct),u[O]=ct)}function ft(O){ee.equals(O)===!1&&(a.scissor(O.x,O.y,O.z,O.w),ee.copy(O))}function ut(O){Kt.equals(O)===!1&&(a.viewport(O.x,O.y,O.z,O.w),Kt.copy(O))}function kt(O,ct){let j=l.get(ct);j===void 0&&(j=new WeakMap,l.set(ct,j));let dt=j.get(O);dt===void 0&&(dt=a.getUniformBlockIndex(ct,O.name),j.set(O,dt))}function Gt(O,ct){const dt=l.get(ct).get(O);c.get(ct)!==dt&&(a.uniformBlockBinding(ct,dt,O.__bindingPointIndex),c.set(ct,dt))}function jt(){a.disable(a.BLEND),a.disable(a.CULL_FACE),a.disable(a.DEPTH_TEST),a.disable(a.POLYGON_OFFSET_FILL),a.disable(a.SCISSOR_TEST),a.disable(a.STENCIL_TEST),a.disable(a.SAMPLE_ALPHA_TO_COVERAGE),a.blendEquation(a.FUNC_ADD),a.blendFunc(a.ONE,a.ZERO),a.blendFuncSeparate(a.ONE,a.ZERO,a.ONE,a.ZERO),a.blendColor(0,0,0,0),a.colorMask(!0,!0,!0,!0),a.clearColor(0,0,0,0),a.depthMask(!0),a.depthFunc(a.LESS),r.setReversed(!1),a.clearDepth(1),a.stencilMask(4294967295),a.stencilFunc(a.ALWAYS,0,4294967295),a.stencilOp(a.KEEP,a.KEEP,a.KEEP),a.clearStencil(0),a.cullFace(a.BACK),a.frontFace(a.CCW),a.polygonOffset(0,0),a.activeTexture(a.TEXTURE0),a.bindFramebuffer(a.FRAMEBUFFER,null),a.bindFramebuffer(a.DRAW_FRAMEBUFFER,null),a.bindFramebuffer(a.READ_FRAMEBUFFER,null),a.useProgram(null),a.lineWidth(1),a.scissor(0,0,a.canvas.width,a.canvas.height),a.viewport(0,0,a.canvas.width,a.canvas.height),a.pixelStorei(a.PACK_ALIGNMENT,4),a.pixelStorei(a.UNPACK_ALIGNMENT,4),a.pixelStorei(a.UNPACK_FLIP_Y_WEBGL,!1),a.pixelStorei(a.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),a.pixelStorei(a.UNPACK_COLORSPACE_CONVERSION_WEBGL,a.BROWSER_DEFAULT_WEBGL),a.pixelStorei(a.PACK_ROW_LENGTH,0),a.pixelStorei(a.PACK_SKIP_PIXELS,0),a.pixelStorei(a.PACK_SKIP_ROWS,0),a.pixelStorei(a.UNPACK_ROW_LENGTH,0),a.pixelStorei(a.UNPACK_IMAGE_HEIGHT,0),a.pixelStorei(a.UNPACK_SKIP_PIXELS,0),a.pixelStorei(a.UNPACK_SKIP_ROWS,0),a.pixelStorei(a.UNPACK_SKIP_IMAGES,0),h={},u={},J=null,it={},d={},f=new WeakMap,p=[],v=null,m=!1,g=null,S=null,x=null,M=null,b=null,w=null,T=null,y=new st(0,0,0),A=0,C=!1,I=null,P=null,V=null,X=null,L=null,ee.set(0,0,a.canvas.width,a.canvas.height),Kt.set(0,0,a.canvas.width,a.canvas.height),s.reset(),r.reset(),o.reset()}return{buffers:{color:s,depth:r,stencil:o},enable:nt,disable:z,bindFramebuffer:Rt,drawBuffers:Ft,useProgram:Pt,setBlending:Bt,setMaterial:Ht,setFlipSided:ye,setCullFace:Se,setLineWidth:ei,setPolygonOffset:Ve,setScissorTest:ii,activeTexture:fi,bindTexture:N,unbindTexture:Ji,compressedTexImage2D:_e,compressedTexImage3D:D,texImage2D:Z,texImage3D:Q,pixelStorei:Lt,getParameter:ht,updateUBOMapping:kt,uniformBlockBinding:Gt,texStorage2D:ot,texStorage3D:lt,texSubImage2D:_,texSubImage3D:U,compressedTexSubImage2D:W,compressedTexSubImage3D:K,scissor:ft,viewport:ut,reset:jt}}function Hb(a,t,e,i,n,s,r){const o=t.has("WEBGL_multisampled_render_to_texture")?t.get("WEBGL_multisampled_render_to_texture"):null,c=typeof navigator>"u"?!1:/OculusBrowser/g.test(navigator.userAgent),l=new Mt,h=new WeakMap,u=new Set;let d;const f=new WeakMap;let p=!1;try{p=typeof OffscreenCanvas<"u"&&new OffscreenCanvas(1,1).getContext("2d")!==null}catch{}function v(D,_){return p?new OffscreenCanvas(D,_):cc("canvas")}function m(D,_,U){let W=1;const K=_e(D);if((K.width>U||K.height>U)&&(W=U/Math.max(K.width,K.height)),W<1)if(typeof HTMLImageElement<"u"&&D instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&D instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&D instanceof ImageBitmap||typeof VideoFrame<"u"&&D instanceof VideoFrame){const ot=Math.floor(W*K.width),lt=Math.floor(W*K.height);d===void 0&&(d=v(ot,lt));const Z=_?v(ot,lt):d;return Z.width=ot,Z.height=lt,Z.getContext("2d").drawImage(D,0,0,ot,lt),It("WebGLRenderer: Texture has been resized from ("+K.width+"x"+K.height+") to ("+ot+"x"+lt+")."),Z}else return"data"in D&&It("WebGLRenderer: Image in DataTexture is too big ("+K.width+"x"+K.height+")."),D;return D}function g(D){return D.generateMipmaps}function S(D){a.generateMipmap(D)}function x(D){return D.isWebGLCubeRenderTarget?a.TEXTURE_CUBE_MAP:D.isWebGL3DRenderTarget?a.TEXTURE_3D:D.isWebGLArrayRenderTarget||D.isCompressedArrayTexture?a.TEXTURE_2D_ARRAY:a.TEXTURE_2D}function M(D,_,U,W,K,ot=!1){if(D!==null){if(a[D]!==void 0)return a[D];It("WebGLRenderer: Attempt to use non-existing WebGL internal format '"+D+"'")}let lt;W&&(lt=t.get("EXT_texture_norm16"),lt||It("WebGLRenderer: Unable to use normalized textures without EXT_texture_norm16 extension"));let Z=_;if(_===a.RED&&(U===a.FLOAT&&(Z=a.R32F),U===a.HALF_FLOAT&&(Z=a.R16F),U===a.UNSIGNED_BYTE&&(Z=a.R8),U===a.UNSIGNED_SHORT&&lt&&(Z=lt.R16_EXT),U===a.SHORT&&lt&&(Z=lt.R16_SNORM_EXT)),_===a.RED_INTEGER&&(U===a.UNSIGNED_BYTE&&(Z=a.R8UI),U===a.UNSIGNED_SHORT&&(Z=a.R16UI),U===a.UNSIGNED_INT&&(Z=a.R32UI),U===a.BYTE&&(Z=a.R8I),U===a.SHORT&&(Z=a.R16I),U===a.INT&&(Z=a.R32I)),_===a.RG&&(U===a.FLOAT&&(Z=a.RG32F),U===a.HALF_FLOAT&&(Z=a.RG16F),U===a.UNSIGNED_BYTE&&(Z=a.RG8),U===a.UNSIGNED_SHORT&&lt&&(Z=lt.RG16_EXT),U===a.SHORT&&lt&&(Z=lt.RG16_SNORM_EXT)),_===a.RG_INTEGER&&(U===a.UNSIGNED_BYTE&&(Z=a.RG8UI),U===a.UNSIGNED_SHORT&&(Z=a.RG16UI),U===a.UNSIGNED_INT&&(Z=a.RG32UI),U===a.BYTE&&(Z=a.RG8I),U===a.SHORT&&(Z=a.RG16I),U===a.INT&&(Z=a.RG32I)),_===a.RGB_INTEGER&&(U===a.UNSIGNED_BYTE&&(Z=a.RGB8UI),U===a.UNSIGNED_SHORT&&(Z=a.RGB16UI),U===a.UNSIGNED_INT&&(Z=a.RGB32UI),U===a.BYTE&&(Z=a.RGB8I),U===a.SHORT&&(Z=a.RGB16I),U===a.INT&&(Z=a.RGB32I)),_===a.RGBA_INTEGER&&(U===a.UNSIGNED_BYTE&&(Z=a.RGBA8UI),U===a.UNSIGNED_SHORT&&(Z=a.RGBA16UI),U===a.UNSIGNED_INT&&(Z=a.RGBA32UI),U===a.BYTE&&(Z=a.RGBA8I),U===a.SHORT&&(Z=a.RGBA16I),U===a.INT&&(Z=a.RGBA32I)),_===a.RGB&&(U===a.UNSIGNED_SHORT&&lt&&(Z=lt.RGB16_EXT),U===a.SHORT&&lt&&(Z=lt.RGB16_SNORM_EXT),U===a.UNSIGNED_INT_5_9_9_9_REV&&(Z=a.RGB9_E5),U===a.UNSIGNED_INT_10F_11F_11F_REV&&(Z=a.R11F_G11F_B10F)),_===a.RGBA){const Q=ot?Wl:ce.getTransfer(K);U===a.FLOAT&&(Z=a.RGBA32F),U===a.HALF_FLOAT&&(Z=a.RGBA16F),U===a.UNSIGNED_BYTE&&(Z=Q===we?a.SRGB8_ALPHA8:a.RGBA8),U===a.UNSIGNED_SHORT&&lt&&(Z=lt.RGBA16_EXT),U===a.SHORT&&lt&&(Z=lt.RGBA16_SNORM_EXT),U===a.UNSIGNED_SHORT_4_4_4_4&&(Z=a.RGBA4),U===a.UNSIGNED_SHORT_5_5_5_1&&(Z=a.RGB5_A1)}return(Z===a.R16F||Z===a.R32F||Z===a.RG16F||Z===a.RG32F||Z===a.RGBA16F||Z===a.RGBA32F)&&t.get("EXT_color_buffer_float"),Z}function b(D,_){let U;return D?_===null||_===Nn||_===ac?U=a.DEPTH24_STENCIL8:_===Ui?U=a.DEPTH32F_STENCIL8:_===rc&&(U=a.DEPTH24_STENCIL8,It("DepthTexture: 16 bit depth attachment is not supported with stencil. Using 24-bit attachment.")):_===null||_===Nn||_===ac?U=a.DEPTH_COMPONENT24:_===Ui?U=a.DEPTH_COMPONENT32F:_===rc&&(U=a.DEPTH_COMPONENT16),U}function w(D,_){return g(D)===!0||D.isFramebufferTexture&&D.minFilter!==Ce&&D.minFilter!==le?Math.log2(Math.max(_.width,_.height))+1:D.mipmaps!==void 0&&D.mipmaps.length>0?D.mipmaps.length:D.isCompressedTexture&&Array.isArray(D.image)?_.mipmaps.length:1}function T(D){const _=D.target;_.removeEventListener("dispose",T),A(_),_.isVideoTexture&&h.delete(_),_.isHTMLTexture&&u.delete(_)}function y(D){const _=D.target;_.removeEventListener("dispose",y),I(_)}function A(D){const _=i.get(D);if(_.__webglInit===void 0)return;const U=D.source,W=f.get(U);if(W){const K=W[_.__cacheKey];K.usedTimes--,K.usedTimes===0&&C(D),Object.keys(W).length===0&&f.delete(U)}i.remove(D)}function C(D){const _=i.get(D);a.deleteTexture(_.__webglTexture);const U=D.source,W=f.get(U);delete W[_.__cacheKey],r.memory.textures--}function I(D){const _=i.get(D);if(D.depthTexture&&(D.depthTexture.dispose(),i.remove(D.depthTexture)),D.isWebGLCubeRenderTarget)for(let W=0;W<6;W++){if(Array.isArray(_.__webglFramebuffer[W]))for(let K=0;K<_.__webglFramebuffer[W].length;K++)a.deleteFramebuffer(_.__webglFramebuffer[W][K]);else a.deleteFramebuffer(_.__webglFramebuffer[W]);_.__webglDepthbuffer&&a.deleteRenderbuffer(_.__webglDepthbuffer[W])}else{if(Array.isArray(_.__webglFramebuffer))for(let W=0;W<_.__webglFramebuffer.length;W++)a.deleteFramebuffer(_.__webglFramebuffer[W]);else a.deleteFramebuffer(_.__webglFramebuffer);if(_.__webglDepthbuffer&&a.deleteRenderbuffer(_.__webglDepthbuffer),_.__webglMultisampledFramebuffer&&a.deleteFramebuffer(_.__webglMultisampledFramebuffer),_.__webglColorRenderbuffer)for(let W=0;W<_.__webglColorRenderbuffer.length;W++)_.__webglColorRenderbuffer[W]&&a.deleteRenderbuffer(_.__webglColorRenderbuffer[W]);_.__webglDepthRenderbuffer&&a.deleteRenderbuffer(_.__webglDepthRenderbuffer)}const U=D.textures;for(let W=0,K=U.length;W<K;W++){const ot=i.get(U[W]);ot.__webglTexture&&(a.deleteTexture(ot.__webglTexture),r.memory.textures--),i.remove(U[W])}i.remove(D)}let P=0;function V(){P=0}function X(){return P}function L(D){P=D}function B(){const D=P;return D>=n.maxTextures&&It("WebGLTextures: Trying to use "+D+" texture units while this GPU supports only "+n.maxTextures),P+=1,D}function k(D){const _=[];return _.push(D.wrapS),_.push(D.wrapT),_.push(D.wrapR||0),_.push(D.magFilter),_.push(D.minFilter),_.push(D.anisotropy),_.push(D.internalFormat),_.push(D.format),_.push(D.type),_.push(D.generateMipmaps),_.push(D.premultiplyAlpha),_.push(D.flipY),_.push(D.unpackAlignment),_.push(D.colorSpace),_.join()}function $(D,_){const U=i.get(D);if(D.isVideoTexture&&N(D),D.isRenderTargetTexture===!1&&D.isExternalTexture!==!0&&D.version>0&&U.__version!==D.version){const W=D.image;if(W===null)It("WebGLRenderer: Texture marked for update but no image data found.");else if(W.complete===!1)It("WebGLRenderer: Texture marked for update but image is incomplete");else{z(U,D,_);return}}else D.isExternalTexture&&(U.__webglTexture=D.sourceTexture?D.sourceTexture:null);e.bindTexture(a.TEXTURE_2D,U.__webglTexture,a.TEXTURE0+_)}function tt(D,_){const U=i.get(D);if(D.isRenderTargetTexture===!1&&D.version>0&&U.__version!==D.version){z(U,D,_);return}else D.isExternalTexture&&(U.__webglTexture=D.sourceTexture?D.sourceTexture:null);e.bindTexture(a.TEXTURE_2D_ARRAY,U.__webglTexture,a.TEXTURE0+_)}function J(D,_){const U=i.get(D);if(D.isRenderTargetTexture===!1&&D.version>0&&U.__version!==D.version){z(U,D,_);return}e.bindTexture(a.TEXTURE_3D,U.__webglTexture,a.TEXTURE0+_)}function it(D,_){const U=i.get(D);if(D.isCubeDepthTexture!==!0&&D.version>0&&U.__version!==D.version){Rt(U,D,_);return}e.bindTexture(a.TEXTURE_CUBE_MAP,U.__webglTexture,a.TEXTURE0+_)}const at={[sc]:a.REPEAT,[Ri]:a.CLAMP_TO_EDGE,[cd]:a.MIRRORED_REPEAT},Xt={[Ce]:a.NEAREST,[hM]:a.NEAREST_MIPMAP_NEAREST,[Ac]:a.NEAREST_MIPMAP_LINEAR,[le]:a.LINEAR,[Ch]:a.LINEAR_MIPMAP_NEAREST,[Lr]:a.LINEAR_MIPMAP_LINEAR},ee={[gM]:a.NEVER,[SM]:a.ALWAYS,[vM]:a.LESS,[N0]:a.LEQUAL,[MM]:a.EQUAL,[F0]:a.GEQUAL,[xM]:a.GREATER,[yM]:a.NOTEQUAL};function Kt(D,_){if(_.type===Ui&&t.has("OES_texture_float_linear")===!1&&(_.magFilter===le||_.magFilter===Ch||_.magFilter===Ac||_.magFilter===Lr||_.minFilter===le||_.minFilter===Ch||_.minFilter===Ac||_.minFilter===Lr)&&It("WebGLRenderer: Unable to use linear filtering with floating point textures. OES_texture_float_linear not supported on this device."),a.texParameteri(D,a.TEXTURE_WRAP_S,at[_.wrapS]),a.texParameteri(D,a.TEXTURE_WRAP_T,at[_.wrapT]),(D===a.TEXTURE_3D||D===a.TEXTURE_2D_ARRAY)&&a.texParameteri(D,a.TEXTURE_WRAP_R,at[_.wrapR]),a.texParameteri(D,a.TEXTURE_MAG_FILTER,Xt[_.magFilter]),a.texParameteri(D,a.TEXTURE_MIN_FILTER,Xt[_.minFilter]),_.compareFunction&&(a.texParameteri(D,a.TEXTURE_COMPARE_MODE,a.COMPARE_REF_TO_TEXTURE),a.texParameteri(D,a.TEXTURE_COMPARE_FUNC,ee[_.compareFunction])),t.has("EXT_texture_filter_anisotropic")===!0){if(_.magFilter===Ce||_.minFilter!==Ac&&_.minFilter!==Lr||_.type===Ui&&t.has("OES_texture_float_linear")===!1)return;if(_.anisotropy>1||i.get(_).__currentAnisotropy){const U=t.get("EXT_texture_filter_anisotropic");a.texParameterf(D,U.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(_.anisotropy,n.getMaxAnisotropy())),i.get(_).__currentAnisotropy=_.anisotropy}}}function q(D,_){let U=!1;D.__webglInit===void 0&&(D.__webglInit=!0,_.addEventListener("dispose",T));const W=_.source;let K=f.get(W);K===void 0&&(K={},f.set(W,K));const ot=k(_);if(ot!==D.__cacheKey){K[ot]===void 0&&(K[ot]={texture:a.createTexture(),usedTimes:0},r.memory.textures++,U=!0),K[ot].usedTimes++;const lt=K[D.__cacheKey];lt!==void 0&&(K[D.__cacheKey].usedTimes--,lt.usedTimes===0&&C(_)),D.__cacheKey=ot,D.__webglTexture=K[ot].texture}return U}function rt(D,_,U){return Math.floor(Math.floor(D/U)/_)}function nt(D,_,U,W){const ot=D.updateRanges;if(ot.length===0)e.texSubImage2D(a.TEXTURE_2D,0,0,0,_.width,_.height,U,W,_.data);else{ot.sort((Lt,ft)=>Lt.start-ft.start);let lt=0;for(let Lt=1;Lt<ot.length;Lt++){const ft=ot[lt],ut=ot[Lt],kt=ft.start+ft.count,Gt=rt(ut.start,_.width,4),jt=rt(ft.start,_.width,4);ut.start<=kt+1&&Gt===jt&&rt(ut.start+ut.count-1,_.width,4)===Gt?ft.count=Math.max(ft.count,ut.start+ut.count-ft.start):(++lt,ot[lt]=ut)}ot.length=lt+1;const Z=e.getParameter(a.UNPACK_ROW_LENGTH),Q=e.getParameter(a.UNPACK_SKIP_PIXELS),ht=e.getParameter(a.UNPACK_SKIP_ROWS);e.pixelStorei(a.UNPACK_ROW_LENGTH,_.width);for(let Lt=0,ft=ot.length;Lt<ft;Lt++){const ut=ot[Lt],kt=Math.floor(ut.start/4),Gt=Math.ceil(ut.count/4),jt=kt%_.width,O=Math.floor(kt/_.width),ct=Gt,j=1;e.pixelStorei(a.UNPACK_SKIP_PIXELS,jt),e.pixelStorei(a.UNPACK_SKIP_ROWS,O),e.texSubImage2D(a.TEXTURE_2D,0,jt,O,ct,j,U,W,_.data)}D.clearUpdateRanges(),e.pixelStorei(a.UNPACK_ROW_LENGTH,Z),e.pixelStorei(a.UNPACK_SKIP_PIXELS,Q),e.pixelStorei(a.UNPACK_SKIP_ROWS,ht)}}function z(D,_,U){let W=a.TEXTURE_2D;(_.isDataArrayTexture||_.isCompressedArrayTexture)&&(W=a.TEXTURE_2D_ARRAY),_.isData3DTexture&&(W=a.TEXTURE_3D);const K=q(D,_),ot=_.source;e.bindTexture(W,D.__webglTexture,a.TEXTURE0+U);const lt=i.get(ot);if(ot.version!==lt.__version||K===!0){if(e.activeTexture(a.TEXTURE0+U),(typeof ImageBitmap<"u"&&_.image instanceof ImageBitmap)===!1){const j=ce.getPrimaries(ce.workingColorSpace),dt=_.colorSpace===rr?null:ce.getPrimaries(_.colorSpace),vt=_.colorSpace===rr||j===dt?a.NONE:a.BROWSER_DEFAULT_WEBGL;e.pixelStorei(a.UNPACK_FLIP_Y_WEBGL,_.flipY),e.pixelStorei(a.UNPACK_PREMULTIPLY_ALPHA_WEBGL,_.premultiplyAlpha),e.pixelStorei(a.UNPACK_COLORSPACE_CONVERSION_WEBGL,vt)}e.pixelStorei(a.UNPACK_ALIGNMENT,_.unpackAlignment);let Q=m(_.image,!1,n.maxTextureSize);Q=Ji(_,Q);const ht=s.convert(_.format,_.colorSpace),Lt=s.convert(_.type);let ft=M(_.internalFormat,ht,Lt,_.normalized,_.colorSpace,_.isVideoTexture);Kt(W,_);let ut;const kt=_.mipmaps,Gt=_.isVideoTexture!==!0,jt=lt.__version===void 0||K===!0,O=ot.dataReady,ct=w(_,Q);if(_.isDepthTexture)ft=b(_.format===Or,_.type),jt&&(Gt?e.texStorage2D(a.TEXTURE_2D,1,ft,Q.width,Q.height):e.texImage2D(a.TEXTURE_2D,0,ft,Q.width,Q.height,0,ht,Lt,null));else if(_.isDataTexture)if(kt.length>0){Gt&&jt&&e.texStorage2D(a.TEXTURE_2D,ct,ft,kt[0].width,kt[0].height);for(let j=0,dt=kt.length;j<dt;j++)ut=kt[j],Gt?O&&e.texSubImage2D(a.TEXTURE_2D,j,0,0,ut.width,ut.height,ht,Lt,ut.data):e.texImage2D(a.TEXTURE_2D,j,ft,ut.width,ut.height,0,ht,Lt,ut.data);_.generateMipmaps=!1}else Gt?(jt&&e.texStorage2D(a.TEXTURE_2D,ct,ft,Q.width,Q.height),O&&nt(_,Q,ht,Lt)):e.texImage2D(a.TEXTURE_2D,0,ft,Q.width,Q.height,0,ht,Lt,Q.data);else if(_.isCompressedTexture)if(_.isCompressedArrayTexture){Gt&&jt&&e.texStorage3D(a.TEXTURE_2D_ARRAY,ct,ft,kt[0].width,kt[0].height,Q.depth);for(let j=0,dt=kt.length;j<dt;j++)if(ut=kt[j],_.format!==Di)if(ht!==null)if(Gt){if(O)if(_.layerUpdates.size>0){const vt=$p(ut.width,ut.height,_.format,_.type);for(const et of _.layerUpdates){const Ct=ut.data.subarray(et*vt/ut.data.BYTES_PER_ELEMENT,(et+1)*vt/ut.data.BYTES_PER_ELEMENT);e.compressedTexSubImage3D(a.TEXTURE_2D_ARRAY,j,0,0,et,ut.width,ut.height,1,ht,Ct)}_.clearLayerUpdates()}else e.compressedTexSubImage3D(a.TEXTURE_2D_ARRAY,j,0,0,0,ut.width,ut.height,Q.depth,ht,ut.data)}else e.compressedTexImage3D(a.TEXTURE_2D_ARRAY,j,ft,ut.width,ut.height,Q.depth,0,ut.data,0,0);else It("WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()");else Gt?O&&e.texSubImage3D(a.TEXTURE_2D_ARRAY,j,0,0,0,ut.width,ut.height,Q.depth,ht,Lt,ut.data):e.texImage3D(a.TEXTURE_2D_ARRAY,j,ft,ut.width,ut.height,Q.depth,0,ht,Lt,ut.data)}else{Gt&&jt&&e.texStorage2D(a.TEXTURE_2D,ct,ft,kt[0].width,kt[0].height);for(let j=0,dt=kt.length;j<dt;j++)ut=kt[j],_.format!==Di?ht!==null?Gt?O&&e.compressedTexSubImage2D(a.TEXTURE_2D,j,0,0,ut.width,ut.height,ht,ut.data):e.compressedTexImage2D(a.TEXTURE_2D,j,ft,ut.width,ut.height,0,ut.data):It("WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()"):Gt?O&&e.texSubImage2D(a.TEXTURE_2D,j,0,0,ut.width,ut.height,ht,Lt,ut.data):e.texImage2D(a.TEXTURE_2D,j,ft,ut.width,ut.height,0,ht,Lt,ut.data)}else if(_.isDataArrayTexture)if(Gt){if(jt&&e.texStorage3D(a.TEXTURE_2D_ARRAY,ct,ft,Q.width,Q.height,Q.depth),O)if(_.layerUpdates.size>0){const j=$p(Q.width,Q.height,_.format,_.type);for(const dt of _.layerUpdates){const vt=Q.data.subarray(dt*j/Q.data.BYTES_PER_ELEMENT,(dt+1)*j/Q.data.BYTES_PER_ELEMENT);e.texSubImage3D(a.TEXTURE_2D_ARRAY,0,0,0,dt,Q.width,Q.height,1,ht,Lt,vt)}_.clearLayerUpdates()}else e.texSubImage3D(a.TEXTURE_2D_ARRAY,0,0,0,0,Q.width,Q.height,Q.depth,ht,Lt,Q.data)}else e.texImage3D(a.TEXTURE_2D_ARRAY,0,ft,Q.width,Q.height,Q.depth,0,ht,Lt,Q.data);else if(_.isData3DTexture)Gt?(jt&&e.texStorage3D(a.TEXTURE_3D,ct,ft,Q.width,Q.height,Q.depth),O&&e.texSubImage3D(a.TEXTURE_3D,0,0,0,0,Q.width,Q.height,Q.depth,ht,Lt,Q.data)):e.texImage3D(a.TEXTURE_3D,0,ft,Q.width,Q.height,Q.depth,0,ht,Lt,Q.data);else if(_.isFramebufferTexture){if(jt)if(Gt)e.texStorage2D(a.TEXTURE_2D,ct,ft,Q.width,Q.height);else{let j=Q.width,dt=Q.height;for(let vt=0;vt<ct;vt++)e.texImage2D(a.TEXTURE_2D,vt,ft,j,dt,0,ht,Lt,null),j>>=1,dt>>=1}}else if(_.isHTMLTexture){if("texElementImage2D"in a){const j=a.canvas;if(j.hasAttribute("layoutsubtree")||j.setAttribute("layoutsubtree","true"),Q.parentNode!==j){j.appendChild(Q),u.add(_),j.onpaint=dt=>{const vt=dt.changedElements;for(const et of u)vt.includes(et.image)&&(et.needsUpdate=!0)},j.requestPaint();return}if(a.texElementImage2D.length===3)a.texElementImage2D(a.TEXTURE_2D,a.RGBA8,Q);else{const vt=a.RGBA,et=a.RGBA,Ct=a.UNSIGNED_BYTE;a.texElementImage2D(a.TEXTURE_2D,0,vt,et,Ct,Q)}a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,a.LINEAR),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_S,a.CLAMP_TO_EDGE),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_T,a.CLAMP_TO_EDGE)}}else if(kt.length>0){if(Gt&&jt){const j=_e(kt[0]);e.texStorage2D(a.TEXTURE_2D,ct,ft,j.width,j.height)}for(let j=0,dt=kt.length;j<dt;j++)ut=kt[j],Gt?O&&e.texSubImage2D(a.TEXTURE_2D,j,0,0,ht,Lt,ut):e.texImage2D(a.TEXTURE_2D,j,ft,ht,Lt,ut);_.generateMipmaps=!1}else if(Gt){if(jt){const j=_e(Q);e.texStorage2D(a.TEXTURE_2D,ct,ft,j.width,j.height)}O&&e.texSubImage2D(a.TEXTURE_2D,0,0,0,ht,Lt,Q)}else e.texImage2D(a.TEXTURE_2D,0,ft,ht,Lt,Q);g(_)&&S(W),lt.__version=ot.version,_.onUpdate&&_.onUpdate(_)}D.__version=_.version}function Rt(D,_,U){if(_.image.length!==6)return;const W=q(D,_),K=_.source;e.bindTexture(a.TEXTURE_CUBE_MAP,D.__webglTexture,a.TEXTURE0+U);const ot=i.get(K);if(K.version!==ot.__version||W===!0){e.activeTexture(a.TEXTURE0+U);const lt=ce.getPrimaries(ce.workingColorSpace),Z=_.colorSpace===rr?null:ce.getPrimaries(_.colorSpace),Q=_.colorSpace===rr||lt===Z?a.NONE:a.BROWSER_DEFAULT_WEBGL;e.pixelStorei(a.UNPACK_FLIP_Y_WEBGL,_.flipY),e.pixelStorei(a.UNPACK_PREMULTIPLY_ALPHA_WEBGL,_.premultiplyAlpha),e.pixelStorei(a.UNPACK_ALIGNMENT,_.unpackAlignment),e.pixelStorei(a.UNPACK_COLORSPACE_CONVERSION_WEBGL,Q);const ht=_.isCompressedTexture||_.image[0].isCompressedTexture,Lt=_.image[0]&&_.image[0].isDataTexture,ft=[];for(let et=0;et<6;et++)!ht&&!Lt?ft[et]=m(_.image[et],!0,n.maxCubemapSize):ft[et]=Lt?_.image[et].image:_.image[et],ft[et]=Ji(_,ft[et]);const ut=ft[0],kt=s.convert(_.format,_.colorSpace),Gt=s.convert(_.type),jt=M(_.internalFormat,kt,Gt,_.normalized,_.colorSpace),O=_.isVideoTexture!==!0,ct=ot.__version===void 0||W===!0,j=K.dataReady;let dt=w(_,ut);Kt(a.TEXTURE_CUBE_MAP,_);let vt;if(ht){O&&ct&&e.texStorage2D(a.TEXTURE_CUBE_MAP,dt,jt,ut.width,ut.height);for(let et=0;et<6;et++){vt=ft[et].mipmaps;for(let Ct=0;Ct<vt.length;Ct++){const wt=vt[Ct];_.format!==Di?kt!==null?O?j&&e.compressedTexSubImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,Ct,0,0,wt.width,wt.height,kt,wt.data):e.compressedTexImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,Ct,jt,wt.width,wt.height,0,wt.data):It("WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()"):O?j&&e.texSubImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,Ct,0,0,wt.width,wt.height,kt,Gt,wt.data):e.texImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,Ct,jt,wt.width,wt.height,0,kt,Gt,wt.data)}}}else{if(vt=_.mipmaps,O&&ct){vt.length>0&&dt++;const et=_e(ft[0]);e.texStorage2D(a.TEXTURE_CUBE_MAP,dt,jt,et.width,et.height)}for(let et=0;et<6;et++)if(Lt){O?j&&e.texSubImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,0,0,0,ft[et].width,ft[et].height,kt,Gt,ft[et].data):e.texImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,0,jt,ft[et].width,ft[et].height,0,kt,Gt,ft[et].data);for(let Ct=0;Ct<vt.length;Ct++){const ni=vt[Ct].image[et].image;O?j&&e.texSubImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,Ct+1,0,0,ni.width,ni.height,kt,Gt,ni.data):e.texImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,Ct+1,jt,ni.width,ni.height,0,kt,Gt,ni.data)}}else{O?j&&e.texSubImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,0,0,0,kt,Gt,ft[et]):e.texImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,0,jt,kt,Gt,ft[et]);for(let Ct=0;Ct<vt.length;Ct++){const wt=vt[Ct];O?j&&e.texSubImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,Ct+1,0,0,kt,Gt,wt.image[et]):e.texImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,Ct+1,jt,kt,Gt,wt.image[et])}}}g(_)&&S(a.TEXTURE_CUBE_MAP),ot.__version=K.version,_.onUpdate&&_.onUpdate(_)}D.__version=_.version}function Ft(D,_,U,W,K,ot){const lt=s.convert(U.format,U.colorSpace),Z=s.convert(U.type),Q=M(U.internalFormat,lt,Z,U.normalized,U.colorSpace),ht=i.get(_),Lt=i.get(U);if(Lt.__renderTarget=_,!ht.__hasExternalTextures){const ft=Math.max(1,_.width>>ot),ut=Math.max(1,_.height>>ot);K===a.TEXTURE_3D||K===a.TEXTURE_2D_ARRAY?e.texImage3D(K,ot,Q,ft,ut,_.depth,0,lt,Z,null):e.texImage2D(K,ot,Q,ft,ut,0,lt,Z,null)}e.bindFramebuffer(a.FRAMEBUFFER,D),fi(_)?o.framebufferTexture2DMultisampleEXT(a.FRAMEBUFFER,W,K,Lt.__webglTexture,0,ii(_)):(K===a.TEXTURE_2D||K>=a.TEXTURE_CUBE_MAP_POSITIVE_X&&K<=a.TEXTURE_CUBE_MAP_NEGATIVE_Z)&&a.framebufferTexture2D(a.FRAMEBUFFER,W,K,Lt.__webglTexture,ot),e.bindFramebuffer(a.FRAMEBUFFER,null)}function Pt(D,_,U){if(a.bindRenderbuffer(a.RENDERBUFFER,D),_.depthBuffer){const W=_.depthTexture,K=W&&W.isDepthTexture?W.type:null,ot=b(_.stencilBuffer,K),lt=_.stencilBuffer?a.DEPTH_STENCIL_ATTACHMENT:a.DEPTH_ATTACHMENT;fi(_)?o.renderbufferStorageMultisampleEXT(a.RENDERBUFFER,ii(_),ot,_.width,_.height):U?a.renderbufferStorageMultisample(a.RENDERBUFFER,ii(_),ot,_.width,_.height):a.renderbufferStorage(a.RENDERBUFFER,ot,_.width,_.height),a.framebufferRenderbuffer(a.FRAMEBUFFER,lt,a.RENDERBUFFER,D)}else{const W=_.textures;for(let K=0;K<W.length;K++){const ot=W[K],lt=s.convert(ot.format,ot.colorSpace),Z=s.convert(ot.type),Q=M(ot.internalFormat,lt,Z,ot.normalized,ot.colorSpace);fi(_)?o.renderbufferStorageMultisampleEXT(a.RENDERBUFFER,ii(_),Q,_.width,_.height):U?a.renderbufferStorageMultisample(a.RENDERBUFFER,ii(_),Q,_.width,_.height):a.renderbufferStorage(a.RENDERBUFFER,Q,_.width,_.height)}}a.bindRenderbuffer(a.RENDERBUFFER,null)}function St(D,_,U){const W=_.isWebGLCubeRenderTarget===!0;if(e.bindFramebuffer(a.FRAMEBUFFER,D),!(_.depthTexture&&_.depthTexture.isDepthTexture))throw new Error("THREE.WebGLTextures: renderTarget.depthTexture must be an instance of THREE.DepthTexture.");const K=i.get(_.depthTexture);if(K.__renderTarget=_,(!K.__webglTexture||_.depthTexture.image.width!==_.width||_.depthTexture.image.height!==_.height)&&(_.depthTexture.image.width=_.width,_.depthTexture.image.height=_.height,_.depthTexture.needsUpdate=!0),W){if(K.__webglInit===void 0&&(K.__webglInit=!0,_.depthTexture.addEventListener("dispose",T)),K.__webglTexture===void 0){K.__webglTexture=a.createTexture(),e.bindTexture(a.TEXTURE_CUBE_MAP,K.__webglTexture),Kt(a.TEXTURE_CUBE_MAP,_.depthTexture);const ht=s.convert(_.depthTexture.format),Lt=s.convert(_.depthTexture.type);let ft;_.depthTexture.format===Fs?ft=a.DEPTH_COMPONENT24:_.depthTexture.format===Or&&(ft=a.DEPTH24_STENCIL8);for(let ut=0;ut<6;ut++)a.texImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+ut,0,ft,_.width,_.height,0,ht,Lt,null)}}else $(_.depthTexture,0);const ot=K.__webglTexture,lt=ii(_),Z=W?a.TEXTURE_CUBE_MAP_POSITIVE_X+U:a.TEXTURE_2D,Q=_.depthTexture.format===Or?a.DEPTH_STENCIL_ATTACHMENT:a.DEPTH_ATTACHMENT;if(_.depthTexture.format===Fs)fi(_)?o.framebufferTexture2DMultisampleEXT(a.FRAMEBUFFER,Q,Z,ot,0,lt):a.framebufferTexture2D(a.FRAMEBUFFER,Q,Z,ot,0);else if(_.depthTexture.format===Or)fi(_)?o.framebufferTexture2DMultisampleEXT(a.FRAMEBUFFER,Q,Z,ot,0,lt):a.framebufferTexture2D(a.FRAMEBUFFER,Q,Z,ot,0);else throw new Error("THREE.WebGLTextures: Unknown depthTexture format.")}function zt(D){const _=i.get(D),U=D.isWebGLCubeRenderTarget===!0;if(_.__boundDepthTexture!==D.depthTexture){const W=D.depthTexture;if(_.__depthDisposeCallback&&_.__depthDisposeCallback(),W){const K=()=>{delete _.__boundDepthTexture,delete _.__depthDisposeCallback,W.removeEventListener("dispose",K)};W.addEventListener("dispose",K),_.__depthDisposeCallback=K}_.__boundDepthTexture=W}if(D.depthTexture&&!_.__autoAllocateDepthBuffer)if(U)for(let W=0;W<6;W++)St(_.__webglFramebuffer[W],D,W);else{const W=D.texture.mipmaps;W&&W.length>0?St(_.__webglFramebuffer[0],D,0):St(_.__webglFramebuffer,D,0)}else if(U){_.__webglDepthbuffer=[];for(let W=0;W<6;W++)if(e.bindFramebuffer(a.FRAMEBUFFER,_.__webglFramebuffer[W]),_.__webglDepthbuffer[W]===void 0)_.__webglDepthbuffer[W]=a.createRenderbuffer(),Pt(_.__webglDepthbuffer[W],D,!1);else{const K=D.stencilBuffer?a.DEPTH_STENCIL_ATTACHMENT:a.DEPTH_ATTACHMENT,ot=_.__webglDepthbuffer[W];a.bindRenderbuffer(a.RENDERBUFFER,ot),a.framebufferRenderbuffer(a.FRAMEBUFFER,K,a.RENDERBUFFER,ot)}}else{const W=D.texture.mipmaps;if(W&&W.length>0?e.bindFramebuffer(a.FRAMEBUFFER,_.__webglFramebuffer[0]):e.bindFramebuffer(a.FRAMEBUFFER,_.__webglFramebuffer),_.__webglDepthbuffer===void 0)_.__webglDepthbuffer=a.createRenderbuffer(),Pt(_.__webglDepthbuffer,D,!1);else{const K=D.stencilBuffer?a.DEPTH_STENCIL_ATTACHMENT:a.DEPTH_ATTACHMENT,ot=_.__webglDepthbuffer;a.bindRenderbuffer(a.RENDERBUFFER,ot),a.framebufferRenderbuffer(a.FRAMEBUFFER,K,a.RENDERBUFFER,ot)}}e.bindFramebuffer(a.FRAMEBUFFER,null)}function Bt(D,_,U){const W=i.get(D);_!==void 0&&Ft(W.__webglFramebuffer,D,D.texture,a.COLOR_ATTACHMENT0,a.TEXTURE_2D,0),U!==void 0&&zt(D)}function Ht(D){const _=D.texture,U=i.get(D),W=i.get(_);D.addEventListener("dispose",y);const K=D.textures,ot=D.isWebGLCubeRenderTarget===!0,lt=K.length>1;if(lt||(W.__webglTexture===void 0&&(W.__webglTexture=a.createTexture()),W.__version=_.version,r.memory.textures++),ot){U.__webglFramebuffer=[];for(let Z=0;Z<6;Z++)if(_.mipmaps&&_.mipmaps.length>0){U.__webglFramebuffer[Z]=[];for(let Q=0;Q<_.mipmaps.length;Q++)U.__webglFramebuffer[Z][Q]=a.createFramebuffer()}else U.__webglFramebuffer[Z]=a.createFramebuffer()}else{if(_.mipmaps&&_.mipmaps.length>0){U.__webglFramebuffer=[];for(let Z=0;Z<_.mipmaps.length;Z++)U.__webglFramebuffer[Z]=a.createFramebuffer()}else U.__webglFramebuffer=a.createFramebuffer();if(lt)for(let Z=0,Q=K.length;Z<Q;Z++){const ht=i.get(K[Z]);ht.__webglTexture===void 0&&(ht.__webglTexture=a.createTexture(),r.memory.textures++)}if(D.samples>0&&fi(D)===!1){U.__webglMultisampledFramebuffer=a.createFramebuffer(),U.__webglColorRenderbuffer=[],e.bindFramebuffer(a.FRAMEBUFFER,U.__webglMultisampledFramebuffer);for(let Z=0;Z<K.length;Z++){const Q=K[Z];U.__webglColorRenderbuffer[Z]=a.createRenderbuffer(),a.bindRenderbuffer(a.RENDERBUFFER,U.__webglColorRenderbuffer[Z]);const ht=s.convert(Q.format,Q.colorSpace),Lt=s.convert(Q.type),ft=M(Q.internalFormat,ht,Lt,Q.normalized,Q.colorSpace,D.isXRRenderTarget===!0),ut=ii(D);a.renderbufferStorageMultisample(a.RENDERBUFFER,ut,ft,D.width,D.height),a.framebufferRenderbuffer(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0+Z,a.RENDERBUFFER,U.__webglColorRenderbuffer[Z])}a.bindRenderbuffer(a.RENDERBUFFER,null),D.depthBuffer&&(U.__webglDepthRenderbuffer=a.createRenderbuffer(),Pt(U.__webglDepthRenderbuffer,D,!0)),e.bindFramebuffer(a.FRAMEBUFFER,null)}}if(ot){e.bindTexture(a.TEXTURE_CUBE_MAP,W.__webglTexture),Kt(a.TEXTURE_CUBE_MAP,_);for(let Z=0;Z<6;Z++)if(_.mipmaps&&_.mipmaps.length>0)for(let Q=0;Q<_.mipmaps.length;Q++)Ft(U.__webglFramebuffer[Z][Q],D,_,a.COLOR_ATTACHMENT0,a.TEXTURE_CUBE_MAP_POSITIVE_X+Z,Q);else Ft(U.__webglFramebuffer[Z],D,_,a.COLOR_ATTACHMENT0,a.TEXTURE_CUBE_MAP_POSITIVE_X+Z,0);g(_)&&S(a.TEXTURE_CUBE_MAP),e.unbindTexture()}else if(lt){for(let Z=0,Q=K.length;Z<Q;Z++){const ht=K[Z],Lt=i.get(ht);let ft=a.TEXTURE_2D;(D.isWebGL3DRenderTarget||D.isWebGLArrayRenderTarget)&&(ft=D.isWebGL3DRenderTarget?a.TEXTURE_3D:a.TEXTURE_2D_ARRAY),e.bindTexture(ft,Lt.__webglTexture),Kt(ft,ht),Ft(U.__webglFramebuffer,D,ht,a.COLOR_ATTACHMENT0+Z,ft,0),g(ht)&&S(ft)}e.unbindTexture()}else{let Z=a.TEXTURE_2D;if((D.isWebGL3DRenderTarget||D.isWebGLArrayRenderTarget)&&(Z=D.isWebGL3DRenderTarget?a.TEXTURE_3D:a.TEXTURE_2D_ARRAY),e.bindTexture(Z,W.__webglTexture),Kt(Z,_),_.mipmaps&&_.mipmaps.length>0)for(let Q=0;Q<_.mipmaps.length;Q++)Ft(U.__webglFramebuffer[Q],D,_,a.COLOR_ATTACHMENT0,Z,Q);else Ft(U.__webglFramebuffer,D,_,a.COLOR_ATTACHMENT0,Z,0);g(_)&&S(Z),e.unbindTexture()}D.depthBuffer&&zt(D)}function ye(D){const _=D.textures;for(let U=0,W=_.length;U<W;U++){const K=_[U];if(g(K)){const ot=x(D),lt=i.get(K).__webglTexture;e.bindTexture(ot,lt),S(ot),e.unbindTexture()}}}const Se=[],ei=[];function Ve(D){if(D.samples>0){if(fi(D)===!1){const _=D.textures,U=D.width,W=D.height;let K=a.COLOR_BUFFER_BIT;const ot=D.stencilBuffer?a.DEPTH_STENCIL_ATTACHMENT:a.DEPTH_ATTACHMENT,lt=i.get(D),Z=_.length>1;if(Z)for(let ht=0;ht<_.length;ht++)e.bindFramebuffer(a.FRAMEBUFFER,lt.__webglMultisampledFramebuffer),a.framebufferRenderbuffer(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0+ht,a.RENDERBUFFER,null),e.bindFramebuffer(a.FRAMEBUFFER,lt.__webglFramebuffer),a.framebufferTexture2D(a.DRAW_FRAMEBUFFER,a.COLOR_ATTACHMENT0+ht,a.TEXTURE_2D,null,0);e.bindFramebuffer(a.READ_FRAMEBUFFER,lt.__webglMultisampledFramebuffer);const Q=D.texture.mipmaps;Q&&Q.length>0?e.bindFramebuffer(a.DRAW_FRAMEBUFFER,lt.__webglFramebuffer[0]):e.bindFramebuffer(a.DRAW_FRAMEBUFFER,lt.__webglFramebuffer);for(let ht=0;ht<_.length;ht++){if(D.resolveDepthBuffer&&(D.depthBuffer&&(K|=a.DEPTH_BUFFER_BIT),D.stencilBuffer&&D.resolveStencilBuffer&&(K|=a.STENCIL_BUFFER_BIT)),Z){a.framebufferRenderbuffer(a.READ_FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.RENDERBUFFER,lt.__webglColorRenderbuffer[ht]);const Lt=i.get(_[ht]).__webglTexture;a.framebufferTexture2D(a.DRAW_FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.TEXTURE_2D,Lt,0)}a.blitFramebuffer(0,0,U,W,0,0,U,W,K,a.NEAREST),c===!0&&(Se.length=0,ei.length=0,Se.push(a.COLOR_ATTACHMENT0+ht),D.depthBuffer&&D.resolveDepthBuffer===!1&&(Se.push(ot),ei.push(ot),a.invalidateFramebuffer(a.DRAW_FRAMEBUFFER,ei)),a.invalidateFramebuffer(a.READ_FRAMEBUFFER,Se))}if(e.bindFramebuffer(a.READ_FRAMEBUFFER,null),e.bindFramebuffer(a.DRAW_FRAMEBUFFER,null),Z)for(let ht=0;ht<_.length;ht++){e.bindFramebuffer(a.FRAMEBUFFER,lt.__webglMultisampledFramebuffer),a.framebufferRenderbuffer(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0+ht,a.RENDERBUFFER,lt.__webglColorRenderbuffer[ht]);const Lt=i.get(_[ht]).__webglTexture;e.bindFramebuffer(a.FRAMEBUFFER,lt.__webglFramebuffer),a.framebufferTexture2D(a.DRAW_FRAMEBUFFER,a.COLOR_ATTACHMENT0+ht,a.TEXTURE_2D,Lt,0)}e.bindFramebuffer(a.DRAW_FRAMEBUFFER,lt.__webglMultisampledFramebuffer)}else if(D.depthBuffer&&D.resolveDepthBuffer===!1&&c){const _=D.stencilBuffer?a.DEPTH_STENCIL_ATTACHMENT:a.DEPTH_ATTACHMENT;a.invalidateFramebuffer(a.DRAW_FRAMEBUFFER,[_])}}}function ii(D){return Math.min(n.maxSamples,D.samples)}function fi(D){const _=i.get(D);return D.samples>0&&t.has("WEBGL_multisampled_render_to_texture")===!0&&_.__useRenderToTexture!==!1}function N(D){const _=r.render.frame;h.get(D)!==_&&(h.set(D,_),D.update())}function Ji(D,_){const U=D.colorSpace,W=D.format,K=D.type;return D.isCompressedTexture===!0||D.isVideoTexture===!0||U!==Vl&&U!==rr&&(ce.getTransfer(U)===we?(W!==Di||K!==yn)&&It("WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType."):Wt("WebGLTextures: Unsupported texture color space:",U)),_}function _e(D){return typeof HTMLImageElement<"u"&&D instanceof HTMLImageElement?(l.width=D.naturalWidth||D.width,l.height=D.naturalHeight||D.height):typeof VideoFrame<"u"&&D instanceof VideoFrame?(l.width=D.displayWidth,l.height=D.displayHeight):(l.width=D.width,l.height=D.height),l}this.allocateTextureUnit=B,this.resetTextureUnits=V,this.getTextureUnits=X,this.setTextureUnits=L,this.setTexture2D=$,this.setTexture2DArray=tt,this.setTexture3D=J,this.setTextureCube=it,this.rebindTextures=Bt,this.setupRenderTarget=Ht,this.updateRenderTargetMipmap=ye,this.updateMultisampleRenderTarget=Ve,this.setupDepthRenderbuffer=zt,this.setupFrameBufferTexture=Ft,this.useMultisampledRTT=fi,this.isReversedDepthBuffer=function(){return e.buffers.depth.getReversed()}}function Gb(a,t){function e(i,n=rr){let s;const r=ce.getTransfer(n);if(i===yn)return a.UNSIGNED_BYTE;if(i===D0)return a.UNSIGNED_SHORT_4_4_4_4;if(i===I0)return a.UNSIGNED_SHORT_5_5_5_1;if(i===c1)return a.UNSIGNED_INT_5_9_9_9_REV;if(i===l1)return a.UNSIGNED_INT_10F_11F_11F_REV;if(i===a1)return a.BYTE;if(i===o1)return a.SHORT;if(i===rc)return a.UNSIGNED_SHORT;if(i===R0)return a.INT;if(i===Nn)return a.UNSIGNED_INT;if(i===Ui)return a.FLOAT;if(i===$e)return a.HALF_FLOAT;if(i===h1)return a.ALPHA;if(i===u1)return a.RGB;if(i===Di)return a.RGBA;if(i===Fs)return a.DEPTH_COMPONENT;if(i===Or)return a.DEPTH_STENCIL;if(i===dh)return a.RED;if(i===C0)return a.RED_INTEGER;if(i===Yr)return a.RG;if(i===P0)return a.RG_INTEGER;if(i===L0)return a.RGBA_INTEGER;if(i===Al||i===Tl||i===Rl||i===Dl)if(r===we)if(s=t.get("WEBGL_compressed_texture_s3tc_srgb"),s!==null){if(i===Al)return s.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(i===Tl)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(i===Rl)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(i===Dl)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else return null;else if(s=t.get("WEBGL_compressed_texture_s3tc"),s!==null){if(i===Al)return s.COMPRESSED_RGB_S3TC_DXT1_EXT;if(i===Tl)return s.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(i===Rl)return s.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(i===Dl)return s.COMPRESSED_RGBA_S3TC_DXT5_EXT}else return null;if(i===ld||i===hd||i===ud||i===dd)if(s=t.get("WEBGL_compressed_texture_pvrtc"),s!==null){if(i===ld)return s.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(i===hd)return s.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(i===ud)return s.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(i===dd)return s.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}else return null;if(i===fd||i===pd||i===md||i===gd||i===vd||i===kl||i===Md)if(s=t.get("WEBGL_compressed_texture_etc"),s!==null){if(i===fd||i===pd)return r===we?s.COMPRESSED_SRGB8_ETC2:s.COMPRESSED_RGB8_ETC2;if(i===md)return r===we?s.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:s.COMPRESSED_RGBA8_ETC2_EAC;if(i===gd)return s.COMPRESSED_R11_EAC;if(i===vd)return s.COMPRESSED_SIGNED_R11_EAC;if(i===kl)return s.COMPRESSED_RG11_EAC;if(i===Md)return s.COMPRESSED_SIGNED_RG11_EAC}else return null;if(i===xd||i===yd||i===Sd||i===_d||i===bd||i===wd||i===Ed||i===Ad||i===Td||i===Rd||i===Dd||i===Id||i===Cd||i===Pd)if(s=t.get("WEBGL_compressed_texture_astc"),s!==null){if(i===xd)return r===we?s.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:s.COMPRESSED_RGBA_ASTC_4x4_KHR;if(i===yd)return r===we?s.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:s.COMPRESSED_RGBA_ASTC_5x4_KHR;if(i===Sd)return r===we?s.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:s.COMPRESSED_RGBA_ASTC_5x5_KHR;if(i===_d)return r===we?s.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:s.COMPRESSED_RGBA_ASTC_6x5_KHR;if(i===bd)return r===we?s.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:s.COMPRESSED_RGBA_ASTC_6x6_KHR;if(i===wd)return r===we?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:s.COMPRESSED_RGBA_ASTC_8x5_KHR;if(i===Ed)return r===we?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:s.COMPRESSED_RGBA_ASTC_8x6_KHR;if(i===Ad)return r===we?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:s.COMPRESSED_RGBA_ASTC_8x8_KHR;if(i===Td)return r===we?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:s.COMPRESSED_RGBA_ASTC_10x5_KHR;if(i===Rd)return r===we?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:s.COMPRESSED_RGBA_ASTC_10x6_KHR;if(i===Dd)return r===we?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:s.COMPRESSED_RGBA_ASTC_10x8_KHR;if(i===Id)return r===we?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:s.COMPRESSED_RGBA_ASTC_10x10_KHR;if(i===Cd)return r===we?s.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:s.COMPRESSED_RGBA_ASTC_12x10_KHR;if(i===Pd)return r===we?s.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:s.COMPRESSED_RGBA_ASTC_12x12_KHR}else return null;if(i===Ld||i===Od||i===Nd)if(s=t.get("EXT_texture_compression_bptc"),s!==null){if(i===Ld)return r===we?s.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:s.COMPRESSED_RGBA_BPTC_UNORM_EXT;if(i===Od)return s.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT;if(i===Nd)return s.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT}else return null;if(i===Fd||i===Ud||i===zl||i===kd)if(s=t.get("EXT_texture_compression_rgtc"),s!==null){if(i===Fd)return s.COMPRESSED_RED_RGTC1_EXT;if(i===Ud)return s.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(i===zl)return s.COMPRESSED_RED_GREEN_RGTC2_EXT;if(i===kd)return s.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}else return null;return i===ac?a.UNSIGNED_INT_24_8:a[i]!==void 0?a[i]:null}return{convert:e}}const Vb=`
5503
+ }`,Ub=[new R(1,0,0),new R(-1,0,0),new R(0,1,0),new R(0,-1,0),new R(0,0,1),new R(0,0,-1)],kb=[new R(0,-1,0),new R(0,-1,0),new R(0,0,1),new R(0,0,-1),new R(0,-1,0),new R(0,-1,0)],gm=new te,_o=new R,fu=new R;function zb(a,t,e){let i=new G0;const n=new Mt,s=new Mt,r=new ae,o=new bx,c=new wx,l={},h=e.maxTextureSize,u={[pr]:qe,[qe]:pr,[xn]:xn},d=new fe({defines:{VSM_SAMPLES:8},uniforms:{shadow_pass:{value:null},resolution:{value:new Mt},radius:{value:4}},vertexShader:Nb,fragmentShader:Fb}),f=d.clone();f.defines.HORIZONTAL_PASS=1;const p=new se;p.setAttribute("position",new Jt(new Float32Array([-1,-1,.5,3,-1,.5,-1,3,.5]),3));const v=new bt(p,d),m=this;this.enabled=!1,this.autoUpdate=!0,this.needsUpdate=!1,this.type=Ho;let g=this.type;this.render=function(w,T,y){if(m.enabled===!1||m.autoUpdate===!1&&m.needsUpdate===!1||w.length===0)return;this.type===X2&&(It("WebGLShadowMap: PCFSoftShadowMap has been deprecated. Using PCFShadowMap instead."),this.type=Ho);const A=a.getRenderTarget(),C=a.getActiveCubeFace(),I=a.getActiveMipmapLevel(),P=a.state;P.setBlending(vs),P.buffers.depth.getReversed()===!0?P.buffers.color.setClear(0,0,0,0):P.buffers.color.setClear(1,1,1,1),P.buffers.depth.setTest(!0),P.setScissorTest(!1);const V=g!==this.type;V&&T.traverse(function(X){X.material&&(Array.isArray(X.material)?X.material.forEach(L=>L.needsUpdate=!0):X.material.needsUpdate=!0)});for(let X=0,L=w.length;X<L;X++){const B=w[X],k=B.shadow;if(k===void 0){It("WebGLShadowMap:",B,"has no shadow.");continue}if(k.autoUpdate===!1&&k.needsUpdate===!1)continue;n.copy(k.mapSize);const $=k.getFrameExtents();n.multiply($),s.copy(k.mapSize),(n.x>h||n.y>h)&&(n.x>h&&(s.x=Math.floor(h/$.x),n.x=s.x*$.x,k.mapSize.x=s.x),n.y>h&&(s.y=Math.floor(h/$.y),n.y=s.y*$.y,k.mapSize.y=s.y));const tt=a.state.buffers.depth.getReversed();if(k.camera._reversedDepth=tt,k.map===null||V===!0){if(k.map!==null&&(k.map.depthTexture!==null&&(k.map.depthTexture.dispose(),k.map.depthTexture=null),k.map.dispose()),this.type===Lo){if(B.isPointLight){It("WebGLShadowMap: VSM shadow maps are not supported for PointLights. Use PCF or BasicShadowMap instead.");continue}k.map=new Qe(n.x,n.y,{format:Yr,type:$e,minFilter:le,magFilter:le,generateMipmaps:!1}),k.map.texture.name=B.name+".shadowMap",k.map.depthTexture=new mr(n.x,n.y,Ui),k.map.depthTexture.name=B.name+".shadowMapDepth",k.map.depthTexture.format=Fs,k.map.depthTexture.compareFunction=null,k.map.depthTexture.minFilter=Ce,k.map.depthTexture.magFilter=Ce}else B.isPointLight?(k.map=new lc(n.x),k.map.depthTexture=new vx(n.x,Nn)):(k.map=new Qe(n.x,n.y),k.map.depthTexture=new mr(n.x,n.y,Nn)),k.map.depthTexture.name=B.name+".shadowMap",k.map.depthTexture.format=Fs,this.type===Ho?(k.map.depthTexture.compareFunction=tt?F0:N0,k.map.depthTexture.minFilter=le,k.map.depthTexture.magFilter=le):(k.map.depthTexture.compareFunction=null,k.map.depthTexture.minFilter=Ce,k.map.depthTexture.magFilter=Ce);k.camera.updateProjectionMatrix()}const J=k.map.isWebGLCubeRenderTarget?6:1;for(let it=0;it<J;it++){if(k.map.isWebGLCubeRenderTarget)a.setRenderTarget(k.map,it),a.clear();else{it===0&&(a.setRenderTarget(k.map),a.clear());const at=k.getViewport(it);r.set(s.x*at.x,s.y*at.y,s.x*at.z,s.y*at.w),P.viewport(r)}if(B.isPointLight){const at=k.camera,Xt=k.matrix,ee=B.distance||at.far;ee!==at.far&&(at.far=ee,at.updateProjectionMatrix()),_o.setFromMatrixPosition(B.matrixWorld),at.position.copy(_o),fu.copy(at.position),fu.add(Ub[it]),at.up.copy(kb[it]),at.lookAt(fu),at.updateMatrixWorld(),Xt.makeTranslation(-_o.x,-_o.y,-_o.z),gm.multiplyMatrices(at.projectionMatrix,at.matrixWorldInverse),k._frustum.setFromProjectionMatrix(gm,at.coordinateSystem,at.reversedDepth)}else k.updateMatrices(B);i=k.getFrustum(),M(T,y,k.camera,B,this.type)}k.isPointLightShadow!==!0&&this.type===Lo&&S(k,y),k.needsUpdate=!1}g=this.type,m.needsUpdate=!1,a.setRenderTarget(A,C,I)};function S(w,T){const y=t.update(v);d.defines.VSM_SAMPLES!==w.blurSamples&&(d.defines.VSM_SAMPLES=w.blurSamples,f.defines.VSM_SAMPLES=w.blurSamples,d.needsUpdate=!0,f.needsUpdate=!0),w.mapPass===null&&(w.mapPass=new Qe(n.x,n.y,{format:Yr,type:$e})),d.uniforms.shadow_pass.value=w.map.depthTexture,d.uniforms.resolution.value=w.mapSize,d.uniforms.radius.value=w.radius,a.setRenderTarget(w.mapPass),a.clear(),a.renderBufferDirect(T,null,y,d,v,null),f.uniforms.shadow_pass.value=w.mapPass.texture,f.uniforms.resolution.value=w.mapSize,f.uniforms.radius.value=w.radius,a.setRenderTarget(w.map),a.clear(),a.renderBufferDirect(T,null,y,f,v,null)}function x(w,T,y,A){let C=null;const I=y.isPointLight===!0?w.customDistanceMaterial:w.customDepthMaterial;if(I!==void 0)C=I;else if(C=y.isPointLight===!0?c:o,a.localClippingEnabled&&T.clipShadows===!0&&Array.isArray(T.clippingPlanes)&&T.clippingPlanes.length!==0||T.displacementMap&&T.displacementScale!==0||T.alphaMap&&T.alphaTest>0||T.map&&T.alphaTest>0||T.alphaToCoverage===!0){const P=C.uuid,V=T.uuid;let X=l[P];X===void 0&&(X={},l[P]=X);let L=X[V];L===void 0&&(L=C.clone(),X[V]=L,T.addEventListener("dispose",b)),C=L}if(C.visible=T.visible,C.wireframe=T.wireframe,A===Lo?C.side=T.shadowSide!==null?T.shadowSide:T.side:C.side=T.shadowSide!==null?T.shadowSide:u[T.side],C.alphaMap=T.alphaMap,C.alphaTest=T.alphaToCoverage===!0?.5:T.alphaTest,C.map=T.map,C.clipShadows=T.clipShadows,C.clippingPlanes=T.clippingPlanes,C.clipIntersection=T.clipIntersection,C.displacementMap=T.displacementMap,C.displacementScale=T.displacementScale,C.displacementBias=T.displacementBias,C.wireframeLinewidth=T.wireframeLinewidth,C.linewidth=T.linewidth,y.isPointLight===!0&&C.isMeshDistanceMaterial===!0){const P=a.properties.get(C);P.light=y}return C}function M(w,T,y,A,C){if(w.visible===!1)return;if(w.layers.test(T.layers)&&(w.isMesh||w.isLine||w.isPoints)&&(w.castShadow||w.receiveShadow&&C===Lo)&&(!w.frustumCulled||i.intersectsObject(w))){w.modelViewMatrix.multiplyMatrices(y.matrixWorldInverse,w.matrixWorld);const V=t.update(w),X=w.material;if(Array.isArray(X)){const L=V.groups;for(let B=0,k=L.length;B<k;B++){const $=L[B],tt=X[$.materialIndex];if(tt&&tt.visible){const J=x(w,tt,A,C);w.onBeforeShadow(a,w,T,y,V,J,$),a.renderBufferDirect(y,null,V,J,w,$),w.onAfterShadow(a,w,T,y,V,J,$)}}}else if(X.visible){const L=x(w,X,A,C);w.onBeforeShadow(a,w,T,y,V,L,null),a.renderBufferDirect(y,null,V,L,w,null),w.onAfterShadow(a,w,T,y,V,L,null)}}const P=w.children;for(let V=0,X=P.length;V<X;V++)M(P[V],T,y,A,C)}function b(w){w.target.removeEventListener("dispose",b);for(const y in l){const A=l[y],C=w.target.uuid;C in A&&(A[C].dispose(),delete A[C])}}}function Bb(a,t){function e(){let O=!1;const ct=new ae;let j=null;const dt=new ae(0,0,0,0);return{setMask:function(vt){j!==vt&&!O&&(a.colorMask(vt,vt,vt,vt),j=vt)},setLocked:function(vt){O=vt},setClear:function(vt,et,Ct,wt,ni){ni===!0&&(vt*=wt,et*=wt,Ct*=wt),ct.set(vt,et,Ct,wt),dt.equals(ct)===!1&&(a.clearColor(vt,et,Ct,wt),dt.copy(ct))},reset:function(){O=!1,j=null,dt.set(-1,0,0,0)}}}function i(){let O=!1,ct=!1,j=null,dt=null,vt=null;return{setReversed:function(et){if(ct!==et){const Ct=t.get("EXT_clip_control");et?Ct.clipControlEXT(Ct.LOWER_LEFT_EXT,Ct.ZERO_TO_ONE_EXT):Ct.clipControlEXT(Ct.LOWER_LEFT_EXT,Ct.NEGATIVE_ONE_TO_ONE_EXT),ct=et;const wt=vt;vt=null,this.setClear(wt)}},getReversed:function(){return ct},setTest:function(et){et?nt(a.DEPTH_TEST):z(a.DEPTH_TEST)},setMask:function(et){j!==et&&!O&&(a.depthMask(et),j=et)},setFunc:function(et){if(ct&&(et=AM[et]),dt!==et){switch(et){case ed:a.depthFunc(a.NEVER);break;case id:a.depthFunc(a.ALWAYS);break;case nd:a.depthFunc(a.LESS);break;case Ja:a.depthFunc(a.LEQUAL);break;case sd:a.depthFunc(a.EQUAL);break;case rd:a.depthFunc(a.GEQUAL);break;case ad:a.depthFunc(a.GREATER);break;case od:a.depthFunc(a.NOTEQUAL);break;default:a.depthFunc(a.LEQUAL)}dt=et}},setLocked:function(et){O=et},setClear:function(et){vt!==et&&(vt=et,ct&&(et=1-et),a.clearDepth(et))},reset:function(){O=!1,j=null,dt=null,vt=null,ct=!1}}}function n(){let O=!1,ct=null,j=null,dt=null,vt=null,et=null,Ct=null,wt=null,ni=null;return{setTest:function(Ne){O||(Ne?nt(a.STENCIL_TEST):z(a.STENCIL_TEST))},setMask:function(Ne){ct!==Ne&&!O&&(a.stencilMask(Ne),ct=Ne)},setFunc:function(Ne,jn,Qn){(j!==Ne||dt!==jn||vt!==Qn)&&(a.stencilFunc(Ne,jn,Qn),j=Ne,dt=jn,vt=Qn)},setOp:function(Ne,jn,Qn){(et!==Ne||Ct!==jn||wt!==Qn)&&(a.stencilOp(Ne,jn,Qn),et=Ne,Ct=jn,wt=Qn)},setLocked:function(Ne){O=Ne},setClear:function(Ne){ni!==Ne&&(a.clearStencil(Ne),ni=Ne)},reset:function(){O=!1,ct=null,j=null,dt=null,vt=null,et=null,Ct=null,wt=null,ni=null}}}const s=new e,r=new i,o=new n,c=new WeakMap,l=new WeakMap;let h={},u={},d={},f=new WeakMap,p=[],v=null,m=!1,g=null,S=null,x=null,M=null,b=null,w=null,T=null,y=new st(0,0,0),A=0,C=!1,I=null,P=null,V=null,X=null,L=null;const B=a.getParameter(a.MAX_COMBINED_TEXTURE_IMAGE_UNITS);let k=!1,$=0;const tt=a.getParameter(a.VERSION);tt.indexOf("WebGL")!==-1?($=parseFloat(/^WebGL (\d)/.exec(tt)[1]),k=$>=1):tt.indexOf("OpenGL ES")!==-1&&($=parseFloat(/^OpenGL ES (\d)/.exec(tt)[1]),k=$>=2);let J=null,it={};const at=a.getParameter(a.SCISSOR_BOX),Xt=a.getParameter(a.VIEWPORT),ee=new ae().fromArray(at),Kt=new ae().fromArray(Xt);function q(O,ct,j,dt){const vt=new Uint8Array(4),et=a.createTexture();a.bindTexture(O,et),a.texParameteri(O,a.TEXTURE_MIN_FILTER,a.NEAREST),a.texParameteri(O,a.TEXTURE_MAG_FILTER,a.NEAREST);for(let Ct=0;Ct<j;Ct++)O===a.TEXTURE_3D||O===a.TEXTURE_2D_ARRAY?a.texImage3D(ct,0,a.RGBA,1,1,dt,0,a.RGBA,a.UNSIGNED_BYTE,vt):a.texImage2D(ct+Ct,0,a.RGBA,1,1,0,a.RGBA,a.UNSIGNED_BYTE,vt);return et}const rt={};rt[a.TEXTURE_2D]=q(a.TEXTURE_2D,a.TEXTURE_2D,1),rt[a.TEXTURE_CUBE_MAP]=q(a.TEXTURE_CUBE_MAP,a.TEXTURE_CUBE_MAP_POSITIVE_X,6),rt[a.TEXTURE_2D_ARRAY]=q(a.TEXTURE_2D_ARRAY,a.TEXTURE_2D_ARRAY,1,1),rt[a.TEXTURE_3D]=q(a.TEXTURE_3D,a.TEXTURE_3D,1,1),s.setClear(0,0,0,1),r.setClear(1),o.setClear(0),nt(a.DEPTH_TEST),r.setFunc(Ja),ye(!1),Se(Jf),nt(a.CULL_FACE),Bt(vs);function nt(O){h[O]!==!0&&(a.enable(O),h[O]=!0)}function z(O){h[O]!==!1&&(a.disable(O),h[O]=!1)}function Rt(O,ct){return d[O]!==ct?(a.bindFramebuffer(O,ct),d[O]=ct,O===a.DRAW_FRAMEBUFFER&&(d[a.FRAMEBUFFER]=ct),O===a.FRAMEBUFFER&&(d[a.DRAW_FRAMEBUFFER]=ct),!0):!1}function Ft(O,ct){let j=p,dt=!1;if(O){j=f.get(ct),j===void 0&&(j=[],f.set(ct,j));const vt=O.textures;if(j.length!==vt.length||j[0]!==a.COLOR_ATTACHMENT0){for(let et=0,Ct=vt.length;et<Ct;et++)j[et]=a.COLOR_ATTACHMENT0+et;j.length=vt.length,dt=!0}}else j[0]!==a.BACK&&(j[0]=a.BACK,dt=!0);dt&&a.drawBuffers(j)}function Pt(O){return v!==O?(a.useProgram(O),v=O,!0):!1}const St={[Dr]:a.FUNC_ADD,[Y2]:a.FUNC_SUBTRACT,[q2]:a.FUNC_REVERSE_SUBTRACT};St[$2]=a.MIN,St[K2]=a.MAX;const zt={[Oo]:a.ZERO,[ic]:a.ONE,[Z2]:a.SRC_COLOR,[td]:a.SRC_ALPHA,[iM]:a.SRC_ALPHA_SATURATE,[tM]:a.DST_COLOR,[j2]:a.DST_ALPHA,[J2]:a.ONE_MINUS_SRC_COLOR,[nc]:a.ONE_MINUS_SRC_ALPHA,[eM]:a.ONE_MINUS_DST_COLOR,[Q2]:a.ONE_MINUS_DST_ALPHA,[nM]:a.CONSTANT_COLOR,[sM]:a.ONE_MINUS_CONSTANT_COLOR,[rM]:a.CONSTANT_ALPHA,[aM]:a.ONE_MINUS_CONSTANT_ALPHA};function Bt(O,ct,j,dt,vt,et,Ct,wt,ni,Ne){if(O===vs){m===!0&&(z(a.BLEND),m=!1);return}if(m===!1&&(nt(a.BLEND),m=!0),O!==dc){if(O!==g||Ne!==C){if((S!==Dr||b!==Dr)&&(a.blendEquation(a.FUNC_ADD),S=Dr,b=Dr),Ne)switch(O){case dr:a.blendFuncSeparate(a.ONE,a.ONE_MINUS_SRC_ALPHA,a.ONE,a.ONE_MINUS_SRC_ALPHA);break;case Ai:a.blendFunc(a.ONE,a.ONE);break;case jf:a.blendFuncSeparate(a.ZERO,a.ONE_MINUS_SRC_COLOR,a.ZERO,a.ONE);break;case Qf:a.blendFuncSeparate(a.DST_COLOR,a.ONE_MINUS_SRC_ALPHA,a.ZERO,a.ONE);break;default:Wt("WebGLState: Invalid blending: ",O);break}else switch(O){case dr:a.blendFuncSeparate(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA,a.ONE,a.ONE_MINUS_SRC_ALPHA);break;case Ai:a.blendFuncSeparate(a.SRC_ALPHA,a.ONE,a.ONE,a.ONE);break;case jf:Wt("WebGLState: SubtractiveBlending requires material.premultipliedAlpha = true");break;case Qf:Wt("WebGLState: MultiplyBlending requires material.premultipliedAlpha = true");break;default:Wt("WebGLState: Invalid blending: ",O);break}x=null,M=null,w=null,T=null,y.set(0,0,0),A=0,g=O,C=Ne}return}vt=vt||ct,et=et||j,Ct=Ct||dt,(ct!==S||vt!==b)&&(a.blendEquationSeparate(St[ct],St[vt]),S=ct,b=vt),(j!==x||dt!==M||et!==w||Ct!==T)&&(a.blendFuncSeparate(zt[j],zt[dt],zt[et],zt[Ct]),x=j,M=dt,w=et,T=Ct),(wt.equals(y)===!1||ni!==A)&&(a.blendColor(wt.r,wt.g,wt.b,ni),y.copy(wt),A=ni),g=O,C=!1}function Ht(O,ct){O.side===xn?z(a.CULL_FACE):nt(a.CULL_FACE);let j=O.side===qe;ct&&(j=!j),ye(j),O.blending===dr&&O.transparent===!1?Bt(vs):Bt(O.blending,O.blendEquation,O.blendSrc,O.blendDst,O.blendEquationAlpha,O.blendSrcAlpha,O.blendDstAlpha,O.blendColor,O.blendAlpha,O.premultipliedAlpha),r.setFunc(O.depthFunc),r.setTest(O.depthTest),r.setMask(O.depthWrite),s.setMask(O.colorWrite);const dt=O.stencilWrite;o.setTest(dt),dt&&(o.setMask(O.stencilWriteMask),o.setFunc(O.stencilFunc,O.stencilRef,O.stencilFuncMask),o.setOp(O.stencilFail,O.stencilZFail,O.stencilZPass)),Ve(O.polygonOffset,O.polygonOffsetFactor,O.polygonOffsetUnits),O.alphaToCoverage===!0?nt(a.SAMPLE_ALPHA_TO_COVERAGE):z(a.SAMPLE_ALPHA_TO_COVERAGE)}function ye(O){I!==O&&(O?a.frontFace(a.CW):a.frontFace(a.CCW),I=O)}function Se(O){O!==V2?(nt(a.CULL_FACE),O!==P&&(O===Jf?a.cullFace(a.BACK):O===W2?a.cullFace(a.FRONT):a.cullFace(a.FRONT_AND_BACK))):z(a.CULL_FACE),P=O}function ei(O){O!==V&&(k&&a.lineWidth(O),V=O)}function Ve(O,ct,j){O?(nt(a.POLYGON_OFFSET_FILL),(X!==ct||L!==j)&&(X=ct,L=j,r.getReversed()&&(ct=-ct),a.polygonOffset(ct,j))):z(a.POLYGON_OFFSET_FILL)}function ii(O){O?nt(a.SCISSOR_TEST):z(a.SCISSOR_TEST)}function fi(O){O===void 0&&(O=a.TEXTURE0+B-1),J!==O&&(a.activeTexture(O),J=O)}function N(O,ct,j){j===void 0&&(J===null?j=a.TEXTURE0+B-1:j=J);let dt=it[j];dt===void 0&&(dt={type:void 0,texture:void 0},it[j]=dt),(dt.type!==O||dt.texture!==ct)&&(J!==j&&(a.activeTexture(j),J=j),a.bindTexture(O,ct||rt[O]),dt.type=O,dt.texture=ct)}function Ji(){const O=it[J];O!==void 0&&O.type!==void 0&&(a.bindTexture(O.type,null),O.type=void 0,O.texture=void 0)}function _e(){try{a.compressedTexImage2D(...arguments)}catch(O){Wt("WebGLState:",O)}}function D(){try{a.compressedTexImage3D(...arguments)}catch(O){Wt("WebGLState:",O)}}function _(){try{a.texSubImage2D(...arguments)}catch(O){Wt("WebGLState:",O)}}function U(){try{a.texSubImage3D(...arguments)}catch(O){Wt("WebGLState:",O)}}function W(){try{a.compressedTexSubImage2D(...arguments)}catch(O){Wt("WebGLState:",O)}}function K(){try{a.compressedTexSubImage3D(...arguments)}catch(O){Wt("WebGLState:",O)}}function ot(){try{a.texStorage2D(...arguments)}catch(O){Wt("WebGLState:",O)}}function lt(){try{a.texStorage3D(...arguments)}catch(O){Wt("WebGLState:",O)}}function Z(){try{a.texImage2D(...arguments)}catch(O){Wt("WebGLState:",O)}}function Q(){try{a.texImage3D(...arguments)}catch(O){Wt("WebGLState:",O)}}function ht(O){return u[O]!==void 0?u[O]:a.getParameter(O)}function Lt(O,ct){u[O]!==ct&&(a.pixelStorei(O,ct),u[O]=ct)}function ft(O){ee.equals(O)===!1&&(a.scissor(O.x,O.y,O.z,O.w),ee.copy(O))}function ut(O){Kt.equals(O)===!1&&(a.viewport(O.x,O.y,O.z,O.w),Kt.copy(O))}function kt(O,ct){let j=l.get(ct);j===void 0&&(j=new WeakMap,l.set(ct,j));let dt=j.get(O);dt===void 0&&(dt=a.getUniformBlockIndex(ct,O.name),j.set(O,dt))}function Vt(O,ct){const dt=l.get(ct).get(O);c.get(ct)!==dt&&(a.uniformBlockBinding(ct,dt,O.__bindingPointIndex),c.set(ct,dt))}function jt(){a.disable(a.BLEND),a.disable(a.CULL_FACE),a.disable(a.DEPTH_TEST),a.disable(a.POLYGON_OFFSET_FILL),a.disable(a.SCISSOR_TEST),a.disable(a.STENCIL_TEST),a.disable(a.SAMPLE_ALPHA_TO_COVERAGE),a.blendEquation(a.FUNC_ADD),a.blendFunc(a.ONE,a.ZERO),a.blendFuncSeparate(a.ONE,a.ZERO,a.ONE,a.ZERO),a.blendColor(0,0,0,0),a.colorMask(!0,!0,!0,!0),a.clearColor(0,0,0,0),a.depthMask(!0),a.depthFunc(a.LESS),r.setReversed(!1),a.clearDepth(1),a.stencilMask(4294967295),a.stencilFunc(a.ALWAYS,0,4294967295),a.stencilOp(a.KEEP,a.KEEP,a.KEEP),a.clearStencil(0),a.cullFace(a.BACK),a.frontFace(a.CCW),a.polygonOffset(0,0),a.activeTexture(a.TEXTURE0),a.bindFramebuffer(a.FRAMEBUFFER,null),a.bindFramebuffer(a.DRAW_FRAMEBUFFER,null),a.bindFramebuffer(a.READ_FRAMEBUFFER,null),a.useProgram(null),a.lineWidth(1),a.scissor(0,0,a.canvas.width,a.canvas.height),a.viewport(0,0,a.canvas.width,a.canvas.height),a.pixelStorei(a.PACK_ALIGNMENT,4),a.pixelStorei(a.UNPACK_ALIGNMENT,4),a.pixelStorei(a.UNPACK_FLIP_Y_WEBGL,!1),a.pixelStorei(a.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),a.pixelStorei(a.UNPACK_COLORSPACE_CONVERSION_WEBGL,a.BROWSER_DEFAULT_WEBGL),a.pixelStorei(a.PACK_ROW_LENGTH,0),a.pixelStorei(a.PACK_SKIP_PIXELS,0),a.pixelStorei(a.PACK_SKIP_ROWS,0),a.pixelStorei(a.UNPACK_ROW_LENGTH,0),a.pixelStorei(a.UNPACK_IMAGE_HEIGHT,0),a.pixelStorei(a.UNPACK_SKIP_PIXELS,0),a.pixelStorei(a.UNPACK_SKIP_ROWS,0),a.pixelStorei(a.UNPACK_SKIP_IMAGES,0),h={},u={},J=null,it={},d={},f=new WeakMap,p=[],v=null,m=!1,g=null,S=null,x=null,M=null,b=null,w=null,T=null,y=new st(0,0,0),A=0,C=!1,I=null,P=null,V=null,X=null,L=null,ee.set(0,0,a.canvas.width,a.canvas.height),Kt.set(0,0,a.canvas.width,a.canvas.height),s.reset(),r.reset(),o.reset()}return{buffers:{color:s,depth:r,stencil:o},enable:nt,disable:z,bindFramebuffer:Rt,drawBuffers:Ft,useProgram:Pt,setBlending:Bt,setMaterial:Ht,setFlipSided:ye,setCullFace:Se,setLineWidth:ei,setPolygonOffset:Ve,setScissorTest:ii,activeTexture:fi,bindTexture:N,unbindTexture:Ji,compressedTexImage2D:_e,compressedTexImage3D:D,texImage2D:Z,texImage3D:Q,pixelStorei:Lt,getParameter:ht,updateUBOMapping:kt,uniformBlockBinding:Vt,texStorage2D:ot,texStorage3D:lt,texSubImage2D:_,texSubImage3D:U,compressedTexSubImage2D:W,compressedTexSubImage3D:K,scissor:ft,viewport:ut,reset:jt}}function Hb(a,t,e,i,n,s,r){const o=t.has("WEBGL_multisampled_render_to_texture")?t.get("WEBGL_multisampled_render_to_texture"):null,c=typeof navigator>"u"?!1:/OculusBrowser/g.test(navigator.userAgent),l=new Mt,h=new WeakMap,u=new Set;let d;const f=new WeakMap;let p=!1;try{p=typeof OffscreenCanvas<"u"&&new OffscreenCanvas(1,1).getContext("2d")!==null}catch{}function v(D,_){return p?new OffscreenCanvas(D,_):cc("canvas")}function m(D,_,U){let W=1;const K=_e(D);if((K.width>U||K.height>U)&&(W=U/Math.max(K.width,K.height)),W<1)if(typeof HTMLImageElement<"u"&&D instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&D instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&D instanceof ImageBitmap||typeof VideoFrame<"u"&&D instanceof VideoFrame){const ot=Math.floor(W*K.width),lt=Math.floor(W*K.height);d===void 0&&(d=v(ot,lt));const Z=_?v(ot,lt):d;return Z.width=ot,Z.height=lt,Z.getContext("2d").drawImage(D,0,0,ot,lt),It("WebGLRenderer: Texture has been resized from ("+K.width+"x"+K.height+") to ("+ot+"x"+lt+")."),Z}else return"data"in D&&It("WebGLRenderer: Image in DataTexture is too big ("+K.width+"x"+K.height+")."),D;return D}function g(D){return D.generateMipmaps}function S(D){a.generateMipmap(D)}function x(D){return D.isWebGLCubeRenderTarget?a.TEXTURE_CUBE_MAP:D.isWebGL3DRenderTarget?a.TEXTURE_3D:D.isWebGLArrayRenderTarget||D.isCompressedArrayTexture?a.TEXTURE_2D_ARRAY:a.TEXTURE_2D}function M(D,_,U,W,K,ot=!1){if(D!==null){if(a[D]!==void 0)return a[D];It("WebGLRenderer: Attempt to use non-existing WebGL internal format '"+D+"'")}let lt;W&&(lt=t.get("EXT_texture_norm16"),lt||It("WebGLRenderer: Unable to use normalized textures without EXT_texture_norm16 extension"));let Z=_;if(_===a.RED&&(U===a.FLOAT&&(Z=a.R32F),U===a.HALF_FLOAT&&(Z=a.R16F),U===a.UNSIGNED_BYTE&&(Z=a.R8),U===a.UNSIGNED_SHORT&&lt&&(Z=lt.R16_EXT),U===a.SHORT&&lt&&(Z=lt.R16_SNORM_EXT)),_===a.RED_INTEGER&&(U===a.UNSIGNED_BYTE&&(Z=a.R8UI),U===a.UNSIGNED_SHORT&&(Z=a.R16UI),U===a.UNSIGNED_INT&&(Z=a.R32UI),U===a.BYTE&&(Z=a.R8I),U===a.SHORT&&(Z=a.R16I),U===a.INT&&(Z=a.R32I)),_===a.RG&&(U===a.FLOAT&&(Z=a.RG32F),U===a.HALF_FLOAT&&(Z=a.RG16F),U===a.UNSIGNED_BYTE&&(Z=a.RG8),U===a.UNSIGNED_SHORT&&lt&&(Z=lt.RG16_EXT),U===a.SHORT&&lt&&(Z=lt.RG16_SNORM_EXT)),_===a.RG_INTEGER&&(U===a.UNSIGNED_BYTE&&(Z=a.RG8UI),U===a.UNSIGNED_SHORT&&(Z=a.RG16UI),U===a.UNSIGNED_INT&&(Z=a.RG32UI),U===a.BYTE&&(Z=a.RG8I),U===a.SHORT&&(Z=a.RG16I),U===a.INT&&(Z=a.RG32I)),_===a.RGB_INTEGER&&(U===a.UNSIGNED_BYTE&&(Z=a.RGB8UI),U===a.UNSIGNED_SHORT&&(Z=a.RGB16UI),U===a.UNSIGNED_INT&&(Z=a.RGB32UI),U===a.BYTE&&(Z=a.RGB8I),U===a.SHORT&&(Z=a.RGB16I),U===a.INT&&(Z=a.RGB32I)),_===a.RGBA_INTEGER&&(U===a.UNSIGNED_BYTE&&(Z=a.RGBA8UI),U===a.UNSIGNED_SHORT&&(Z=a.RGBA16UI),U===a.UNSIGNED_INT&&(Z=a.RGBA32UI),U===a.BYTE&&(Z=a.RGBA8I),U===a.SHORT&&(Z=a.RGBA16I),U===a.INT&&(Z=a.RGBA32I)),_===a.RGB&&(U===a.UNSIGNED_SHORT&&lt&&(Z=lt.RGB16_EXT),U===a.SHORT&&lt&&(Z=lt.RGB16_SNORM_EXT),U===a.UNSIGNED_INT_5_9_9_9_REV&&(Z=a.RGB9_E5),U===a.UNSIGNED_INT_10F_11F_11F_REV&&(Z=a.R11F_G11F_B10F)),_===a.RGBA){const Q=ot?Wl:ce.getTransfer(K);U===a.FLOAT&&(Z=a.RGBA32F),U===a.HALF_FLOAT&&(Z=a.RGBA16F),U===a.UNSIGNED_BYTE&&(Z=Q===we?a.SRGB8_ALPHA8:a.RGBA8),U===a.UNSIGNED_SHORT&&lt&&(Z=lt.RGBA16_EXT),U===a.SHORT&&lt&&(Z=lt.RGBA16_SNORM_EXT),U===a.UNSIGNED_SHORT_4_4_4_4&&(Z=a.RGBA4),U===a.UNSIGNED_SHORT_5_5_5_1&&(Z=a.RGB5_A1)}return(Z===a.R16F||Z===a.R32F||Z===a.RG16F||Z===a.RG32F||Z===a.RGBA16F||Z===a.RGBA32F)&&t.get("EXT_color_buffer_float"),Z}function b(D,_){let U;return D?_===null||_===Nn||_===ac?U=a.DEPTH24_STENCIL8:_===Ui?U=a.DEPTH32F_STENCIL8:_===rc&&(U=a.DEPTH24_STENCIL8,It("DepthTexture: 16 bit depth attachment is not supported with stencil. Using 24-bit attachment.")):_===null||_===Nn||_===ac?U=a.DEPTH_COMPONENT24:_===Ui?U=a.DEPTH_COMPONENT32F:_===rc&&(U=a.DEPTH_COMPONENT16),U}function w(D,_){return g(D)===!0||D.isFramebufferTexture&&D.minFilter!==Ce&&D.minFilter!==le?Math.log2(Math.max(_.width,_.height))+1:D.mipmaps!==void 0&&D.mipmaps.length>0?D.mipmaps.length:D.isCompressedTexture&&Array.isArray(D.image)?_.mipmaps.length:1}function T(D){const _=D.target;_.removeEventListener("dispose",T),A(_),_.isVideoTexture&&h.delete(_),_.isHTMLTexture&&u.delete(_)}function y(D){const _=D.target;_.removeEventListener("dispose",y),I(_)}function A(D){const _=i.get(D);if(_.__webglInit===void 0)return;const U=D.source,W=f.get(U);if(W){const K=W[_.__cacheKey];K.usedTimes--,K.usedTimes===0&&C(D),Object.keys(W).length===0&&f.delete(U)}i.remove(D)}function C(D){const _=i.get(D);a.deleteTexture(_.__webglTexture);const U=D.source,W=f.get(U);delete W[_.__cacheKey],r.memory.textures--}function I(D){const _=i.get(D);if(D.depthTexture&&(D.depthTexture.dispose(),i.remove(D.depthTexture)),D.isWebGLCubeRenderTarget)for(let W=0;W<6;W++){if(Array.isArray(_.__webglFramebuffer[W]))for(let K=0;K<_.__webglFramebuffer[W].length;K++)a.deleteFramebuffer(_.__webglFramebuffer[W][K]);else a.deleteFramebuffer(_.__webglFramebuffer[W]);_.__webglDepthbuffer&&a.deleteRenderbuffer(_.__webglDepthbuffer[W])}else{if(Array.isArray(_.__webglFramebuffer))for(let W=0;W<_.__webglFramebuffer.length;W++)a.deleteFramebuffer(_.__webglFramebuffer[W]);else a.deleteFramebuffer(_.__webglFramebuffer);if(_.__webglDepthbuffer&&a.deleteRenderbuffer(_.__webglDepthbuffer),_.__webglMultisampledFramebuffer&&a.deleteFramebuffer(_.__webglMultisampledFramebuffer),_.__webglColorRenderbuffer)for(let W=0;W<_.__webglColorRenderbuffer.length;W++)_.__webglColorRenderbuffer[W]&&a.deleteRenderbuffer(_.__webglColorRenderbuffer[W]);_.__webglDepthRenderbuffer&&a.deleteRenderbuffer(_.__webglDepthRenderbuffer)}const U=D.textures;for(let W=0,K=U.length;W<K;W++){const ot=i.get(U[W]);ot.__webglTexture&&(a.deleteTexture(ot.__webglTexture),r.memory.textures--),i.remove(U[W])}i.remove(D)}let P=0;function V(){P=0}function X(){return P}function L(D){P=D}function B(){const D=P;return D>=n.maxTextures&&It("WebGLTextures: Trying to use "+D+" texture units while this GPU supports only "+n.maxTextures),P+=1,D}function k(D){const _=[];return _.push(D.wrapS),_.push(D.wrapT),_.push(D.wrapR||0),_.push(D.magFilter),_.push(D.minFilter),_.push(D.anisotropy),_.push(D.internalFormat),_.push(D.format),_.push(D.type),_.push(D.generateMipmaps),_.push(D.premultiplyAlpha),_.push(D.flipY),_.push(D.unpackAlignment),_.push(D.colorSpace),_.join()}function $(D,_){const U=i.get(D);if(D.isVideoTexture&&N(D),D.isRenderTargetTexture===!1&&D.isExternalTexture!==!0&&D.version>0&&U.__version!==D.version){const W=D.image;if(W===null)It("WebGLRenderer: Texture marked for update but no image data found.");else if(W.complete===!1)It("WebGLRenderer: Texture marked for update but image is incomplete");else{z(U,D,_);return}}else D.isExternalTexture&&(U.__webglTexture=D.sourceTexture?D.sourceTexture:null);e.bindTexture(a.TEXTURE_2D,U.__webglTexture,a.TEXTURE0+_)}function tt(D,_){const U=i.get(D);if(D.isRenderTargetTexture===!1&&D.version>0&&U.__version!==D.version){z(U,D,_);return}else D.isExternalTexture&&(U.__webglTexture=D.sourceTexture?D.sourceTexture:null);e.bindTexture(a.TEXTURE_2D_ARRAY,U.__webglTexture,a.TEXTURE0+_)}function J(D,_){const U=i.get(D);if(D.isRenderTargetTexture===!1&&D.version>0&&U.__version!==D.version){z(U,D,_);return}e.bindTexture(a.TEXTURE_3D,U.__webglTexture,a.TEXTURE0+_)}function it(D,_){const U=i.get(D);if(D.isCubeDepthTexture!==!0&&D.version>0&&U.__version!==D.version){Rt(U,D,_);return}e.bindTexture(a.TEXTURE_CUBE_MAP,U.__webglTexture,a.TEXTURE0+_)}const at={[sc]:a.REPEAT,[Ri]:a.CLAMP_TO_EDGE,[cd]:a.MIRRORED_REPEAT},Xt={[Ce]:a.NEAREST,[hM]:a.NEAREST_MIPMAP_NEAREST,[Ac]:a.NEAREST_MIPMAP_LINEAR,[le]:a.LINEAR,[Ch]:a.LINEAR_MIPMAP_NEAREST,[Lr]:a.LINEAR_MIPMAP_LINEAR},ee={[gM]:a.NEVER,[SM]:a.ALWAYS,[vM]:a.LESS,[N0]:a.LEQUAL,[MM]:a.EQUAL,[F0]:a.GEQUAL,[xM]:a.GREATER,[yM]:a.NOTEQUAL};function Kt(D,_){if(_.type===Ui&&t.has("OES_texture_float_linear")===!1&&(_.magFilter===le||_.magFilter===Ch||_.magFilter===Ac||_.magFilter===Lr||_.minFilter===le||_.minFilter===Ch||_.minFilter===Ac||_.minFilter===Lr)&&It("WebGLRenderer: Unable to use linear filtering with floating point textures. OES_texture_float_linear not supported on this device."),a.texParameteri(D,a.TEXTURE_WRAP_S,at[_.wrapS]),a.texParameteri(D,a.TEXTURE_WRAP_T,at[_.wrapT]),(D===a.TEXTURE_3D||D===a.TEXTURE_2D_ARRAY)&&a.texParameteri(D,a.TEXTURE_WRAP_R,at[_.wrapR]),a.texParameteri(D,a.TEXTURE_MAG_FILTER,Xt[_.magFilter]),a.texParameteri(D,a.TEXTURE_MIN_FILTER,Xt[_.minFilter]),_.compareFunction&&(a.texParameteri(D,a.TEXTURE_COMPARE_MODE,a.COMPARE_REF_TO_TEXTURE),a.texParameteri(D,a.TEXTURE_COMPARE_FUNC,ee[_.compareFunction])),t.has("EXT_texture_filter_anisotropic")===!0){if(_.magFilter===Ce||_.minFilter!==Ac&&_.minFilter!==Lr||_.type===Ui&&t.has("OES_texture_float_linear")===!1)return;if(_.anisotropy>1||i.get(_).__currentAnisotropy){const U=t.get("EXT_texture_filter_anisotropic");a.texParameterf(D,U.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(_.anisotropy,n.getMaxAnisotropy())),i.get(_).__currentAnisotropy=_.anisotropy}}}function q(D,_){let U=!1;D.__webglInit===void 0&&(D.__webglInit=!0,_.addEventListener("dispose",T));const W=_.source;let K=f.get(W);K===void 0&&(K={},f.set(W,K));const ot=k(_);if(ot!==D.__cacheKey){K[ot]===void 0&&(K[ot]={texture:a.createTexture(),usedTimes:0},r.memory.textures++,U=!0),K[ot].usedTimes++;const lt=K[D.__cacheKey];lt!==void 0&&(K[D.__cacheKey].usedTimes--,lt.usedTimes===0&&C(_)),D.__cacheKey=ot,D.__webglTexture=K[ot].texture}return U}function rt(D,_,U){return Math.floor(Math.floor(D/U)/_)}function nt(D,_,U,W){const ot=D.updateRanges;if(ot.length===0)e.texSubImage2D(a.TEXTURE_2D,0,0,0,_.width,_.height,U,W,_.data);else{ot.sort((Lt,ft)=>Lt.start-ft.start);let lt=0;for(let Lt=1;Lt<ot.length;Lt++){const ft=ot[lt],ut=ot[Lt],kt=ft.start+ft.count,Vt=rt(ut.start,_.width,4),jt=rt(ft.start,_.width,4);ut.start<=kt+1&&Vt===jt&&rt(ut.start+ut.count-1,_.width,4)===Vt?ft.count=Math.max(ft.count,ut.start+ut.count-ft.start):(++lt,ot[lt]=ut)}ot.length=lt+1;const Z=e.getParameter(a.UNPACK_ROW_LENGTH),Q=e.getParameter(a.UNPACK_SKIP_PIXELS),ht=e.getParameter(a.UNPACK_SKIP_ROWS);e.pixelStorei(a.UNPACK_ROW_LENGTH,_.width);for(let Lt=0,ft=ot.length;Lt<ft;Lt++){const ut=ot[Lt],kt=Math.floor(ut.start/4),Vt=Math.ceil(ut.count/4),jt=kt%_.width,O=Math.floor(kt/_.width),ct=Vt,j=1;e.pixelStorei(a.UNPACK_SKIP_PIXELS,jt),e.pixelStorei(a.UNPACK_SKIP_ROWS,O),e.texSubImage2D(a.TEXTURE_2D,0,jt,O,ct,j,U,W,_.data)}D.clearUpdateRanges(),e.pixelStorei(a.UNPACK_ROW_LENGTH,Z),e.pixelStorei(a.UNPACK_SKIP_PIXELS,Q),e.pixelStorei(a.UNPACK_SKIP_ROWS,ht)}}function z(D,_,U){let W=a.TEXTURE_2D;(_.isDataArrayTexture||_.isCompressedArrayTexture)&&(W=a.TEXTURE_2D_ARRAY),_.isData3DTexture&&(W=a.TEXTURE_3D);const K=q(D,_),ot=_.source;e.bindTexture(W,D.__webglTexture,a.TEXTURE0+U);const lt=i.get(ot);if(ot.version!==lt.__version||K===!0){if(e.activeTexture(a.TEXTURE0+U),(typeof ImageBitmap<"u"&&_.image instanceof ImageBitmap)===!1){const j=ce.getPrimaries(ce.workingColorSpace),dt=_.colorSpace===rr?null:ce.getPrimaries(_.colorSpace),vt=_.colorSpace===rr||j===dt?a.NONE:a.BROWSER_DEFAULT_WEBGL;e.pixelStorei(a.UNPACK_FLIP_Y_WEBGL,_.flipY),e.pixelStorei(a.UNPACK_PREMULTIPLY_ALPHA_WEBGL,_.premultiplyAlpha),e.pixelStorei(a.UNPACK_COLORSPACE_CONVERSION_WEBGL,vt)}e.pixelStorei(a.UNPACK_ALIGNMENT,_.unpackAlignment);let Q=m(_.image,!1,n.maxTextureSize);Q=Ji(_,Q);const ht=s.convert(_.format,_.colorSpace),Lt=s.convert(_.type);let ft=M(_.internalFormat,ht,Lt,_.normalized,_.colorSpace,_.isVideoTexture);Kt(W,_);let ut;const kt=_.mipmaps,Vt=_.isVideoTexture!==!0,jt=lt.__version===void 0||K===!0,O=ot.dataReady,ct=w(_,Q);if(_.isDepthTexture)ft=b(_.format===Or,_.type),jt&&(Vt?e.texStorage2D(a.TEXTURE_2D,1,ft,Q.width,Q.height):e.texImage2D(a.TEXTURE_2D,0,ft,Q.width,Q.height,0,ht,Lt,null));else if(_.isDataTexture)if(kt.length>0){Vt&&jt&&e.texStorage2D(a.TEXTURE_2D,ct,ft,kt[0].width,kt[0].height);for(let j=0,dt=kt.length;j<dt;j++)ut=kt[j],Vt?O&&e.texSubImage2D(a.TEXTURE_2D,j,0,0,ut.width,ut.height,ht,Lt,ut.data):e.texImage2D(a.TEXTURE_2D,j,ft,ut.width,ut.height,0,ht,Lt,ut.data);_.generateMipmaps=!1}else Vt?(jt&&e.texStorage2D(a.TEXTURE_2D,ct,ft,Q.width,Q.height),O&&nt(_,Q,ht,Lt)):e.texImage2D(a.TEXTURE_2D,0,ft,Q.width,Q.height,0,ht,Lt,Q.data);else if(_.isCompressedTexture)if(_.isCompressedArrayTexture){Vt&&jt&&e.texStorage3D(a.TEXTURE_2D_ARRAY,ct,ft,kt[0].width,kt[0].height,Q.depth);for(let j=0,dt=kt.length;j<dt;j++)if(ut=kt[j],_.format!==Di)if(ht!==null)if(Vt){if(O)if(_.layerUpdates.size>0){const vt=$p(ut.width,ut.height,_.format,_.type);for(const et of _.layerUpdates){const Ct=ut.data.subarray(et*vt/ut.data.BYTES_PER_ELEMENT,(et+1)*vt/ut.data.BYTES_PER_ELEMENT);e.compressedTexSubImage3D(a.TEXTURE_2D_ARRAY,j,0,0,et,ut.width,ut.height,1,ht,Ct)}_.clearLayerUpdates()}else e.compressedTexSubImage3D(a.TEXTURE_2D_ARRAY,j,0,0,0,ut.width,ut.height,Q.depth,ht,ut.data)}else e.compressedTexImage3D(a.TEXTURE_2D_ARRAY,j,ft,ut.width,ut.height,Q.depth,0,ut.data,0,0);else It("WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()");else Vt?O&&e.texSubImage3D(a.TEXTURE_2D_ARRAY,j,0,0,0,ut.width,ut.height,Q.depth,ht,Lt,ut.data):e.texImage3D(a.TEXTURE_2D_ARRAY,j,ft,ut.width,ut.height,Q.depth,0,ht,Lt,ut.data)}else{Vt&&jt&&e.texStorage2D(a.TEXTURE_2D,ct,ft,kt[0].width,kt[0].height);for(let j=0,dt=kt.length;j<dt;j++)ut=kt[j],_.format!==Di?ht!==null?Vt?O&&e.compressedTexSubImage2D(a.TEXTURE_2D,j,0,0,ut.width,ut.height,ht,ut.data):e.compressedTexImage2D(a.TEXTURE_2D,j,ft,ut.width,ut.height,0,ut.data):It("WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()"):Vt?O&&e.texSubImage2D(a.TEXTURE_2D,j,0,0,ut.width,ut.height,ht,Lt,ut.data):e.texImage2D(a.TEXTURE_2D,j,ft,ut.width,ut.height,0,ht,Lt,ut.data)}else if(_.isDataArrayTexture)if(Vt){if(jt&&e.texStorage3D(a.TEXTURE_2D_ARRAY,ct,ft,Q.width,Q.height,Q.depth),O)if(_.layerUpdates.size>0){const j=$p(Q.width,Q.height,_.format,_.type);for(const dt of _.layerUpdates){const vt=Q.data.subarray(dt*j/Q.data.BYTES_PER_ELEMENT,(dt+1)*j/Q.data.BYTES_PER_ELEMENT);e.texSubImage3D(a.TEXTURE_2D_ARRAY,0,0,0,dt,Q.width,Q.height,1,ht,Lt,vt)}_.clearLayerUpdates()}else e.texSubImage3D(a.TEXTURE_2D_ARRAY,0,0,0,0,Q.width,Q.height,Q.depth,ht,Lt,Q.data)}else e.texImage3D(a.TEXTURE_2D_ARRAY,0,ft,Q.width,Q.height,Q.depth,0,ht,Lt,Q.data);else if(_.isData3DTexture)Vt?(jt&&e.texStorage3D(a.TEXTURE_3D,ct,ft,Q.width,Q.height,Q.depth),O&&e.texSubImage3D(a.TEXTURE_3D,0,0,0,0,Q.width,Q.height,Q.depth,ht,Lt,Q.data)):e.texImage3D(a.TEXTURE_3D,0,ft,Q.width,Q.height,Q.depth,0,ht,Lt,Q.data);else if(_.isFramebufferTexture){if(jt)if(Vt)e.texStorage2D(a.TEXTURE_2D,ct,ft,Q.width,Q.height);else{let j=Q.width,dt=Q.height;for(let vt=0;vt<ct;vt++)e.texImage2D(a.TEXTURE_2D,vt,ft,j,dt,0,ht,Lt,null),j>>=1,dt>>=1}}else if(_.isHTMLTexture){if("texElementImage2D"in a){const j=a.canvas;if(j.hasAttribute("layoutsubtree")||j.setAttribute("layoutsubtree","true"),Q.parentNode!==j){j.appendChild(Q),u.add(_),j.onpaint=dt=>{const vt=dt.changedElements;for(const et of u)vt.includes(et.image)&&(et.needsUpdate=!0)},j.requestPaint();return}if(a.texElementImage2D.length===3)a.texElementImage2D(a.TEXTURE_2D,a.RGBA8,Q);else{const vt=a.RGBA,et=a.RGBA,Ct=a.UNSIGNED_BYTE;a.texElementImage2D(a.TEXTURE_2D,0,vt,et,Ct,Q)}a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,a.LINEAR),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_S,a.CLAMP_TO_EDGE),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_T,a.CLAMP_TO_EDGE)}}else if(kt.length>0){if(Vt&&jt){const j=_e(kt[0]);e.texStorage2D(a.TEXTURE_2D,ct,ft,j.width,j.height)}for(let j=0,dt=kt.length;j<dt;j++)ut=kt[j],Vt?O&&e.texSubImage2D(a.TEXTURE_2D,j,0,0,ht,Lt,ut):e.texImage2D(a.TEXTURE_2D,j,ft,ht,Lt,ut);_.generateMipmaps=!1}else if(Vt){if(jt){const j=_e(Q);e.texStorage2D(a.TEXTURE_2D,ct,ft,j.width,j.height)}O&&e.texSubImage2D(a.TEXTURE_2D,0,0,0,ht,Lt,Q)}else e.texImage2D(a.TEXTURE_2D,0,ft,ht,Lt,Q);g(_)&&S(W),lt.__version=ot.version,_.onUpdate&&_.onUpdate(_)}D.__version=_.version}function Rt(D,_,U){if(_.image.length!==6)return;const W=q(D,_),K=_.source;e.bindTexture(a.TEXTURE_CUBE_MAP,D.__webglTexture,a.TEXTURE0+U);const ot=i.get(K);if(K.version!==ot.__version||W===!0){e.activeTexture(a.TEXTURE0+U);const lt=ce.getPrimaries(ce.workingColorSpace),Z=_.colorSpace===rr?null:ce.getPrimaries(_.colorSpace),Q=_.colorSpace===rr||lt===Z?a.NONE:a.BROWSER_DEFAULT_WEBGL;e.pixelStorei(a.UNPACK_FLIP_Y_WEBGL,_.flipY),e.pixelStorei(a.UNPACK_PREMULTIPLY_ALPHA_WEBGL,_.premultiplyAlpha),e.pixelStorei(a.UNPACK_ALIGNMENT,_.unpackAlignment),e.pixelStorei(a.UNPACK_COLORSPACE_CONVERSION_WEBGL,Q);const ht=_.isCompressedTexture||_.image[0].isCompressedTexture,Lt=_.image[0]&&_.image[0].isDataTexture,ft=[];for(let et=0;et<6;et++)!ht&&!Lt?ft[et]=m(_.image[et],!0,n.maxCubemapSize):ft[et]=Lt?_.image[et].image:_.image[et],ft[et]=Ji(_,ft[et]);const ut=ft[0],kt=s.convert(_.format,_.colorSpace),Vt=s.convert(_.type),jt=M(_.internalFormat,kt,Vt,_.normalized,_.colorSpace),O=_.isVideoTexture!==!0,ct=ot.__version===void 0||W===!0,j=K.dataReady;let dt=w(_,ut);Kt(a.TEXTURE_CUBE_MAP,_);let vt;if(ht){O&&ct&&e.texStorage2D(a.TEXTURE_CUBE_MAP,dt,jt,ut.width,ut.height);for(let et=0;et<6;et++){vt=ft[et].mipmaps;for(let Ct=0;Ct<vt.length;Ct++){const wt=vt[Ct];_.format!==Di?kt!==null?O?j&&e.compressedTexSubImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,Ct,0,0,wt.width,wt.height,kt,wt.data):e.compressedTexImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,Ct,jt,wt.width,wt.height,0,wt.data):It("WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()"):O?j&&e.texSubImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,Ct,0,0,wt.width,wt.height,kt,Vt,wt.data):e.texImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,Ct,jt,wt.width,wt.height,0,kt,Vt,wt.data)}}}else{if(vt=_.mipmaps,O&&ct){vt.length>0&&dt++;const et=_e(ft[0]);e.texStorage2D(a.TEXTURE_CUBE_MAP,dt,jt,et.width,et.height)}for(let et=0;et<6;et++)if(Lt){O?j&&e.texSubImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,0,0,0,ft[et].width,ft[et].height,kt,Vt,ft[et].data):e.texImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,0,jt,ft[et].width,ft[et].height,0,kt,Vt,ft[et].data);for(let Ct=0;Ct<vt.length;Ct++){const ni=vt[Ct].image[et].image;O?j&&e.texSubImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,Ct+1,0,0,ni.width,ni.height,kt,Vt,ni.data):e.texImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,Ct+1,jt,ni.width,ni.height,0,kt,Vt,ni.data)}}else{O?j&&e.texSubImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,0,0,0,kt,Vt,ft[et]):e.texImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,0,jt,kt,Vt,ft[et]);for(let Ct=0;Ct<vt.length;Ct++){const wt=vt[Ct];O?j&&e.texSubImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,Ct+1,0,0,kt,Vt,wt.image[et]):e.texImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,Ct+1,jt,kt,Vt,wt.image[et])}}}g(_)&&S(a.TEXTURE_CUBE_MAP),ot.__version=K.version,_.onUpdate&&_.onUpdate(_)}D.__version=_.version}function Ft(D,_,U,W,K,ot){const lt=s.convert(U.format,U.colorSpace),Z=s.convert(U.type),Q=M(U.internalFormat,lt,Z,U.normalized,U.colorSpace),ht=i.get(_),Lt=i.get(U);if(Lt.__renderTarget=_,!ht.__hasExternalTextures){const ft=Math.max(1,_.width>>ot),ut=Math.max(1,_.height>>ot);K===a.TEXTURE_3D||K===a.TEXTURE_2D_ARRAY?e.texImage3D(K,ot,Q,ft,ut,_.depth,0,lt,Z,null):e.texImage2D(K,ot,Q,ft,ut,0,lt,Z,null)}e.bindFramebuffer(a.FRAMEBUFFER,D),fi(_)?o.framebufferTexture2DMultisampleEXT(a.FRAMEBUFFER,W,K,Lt.__webglTexture,0,ii(_)):(K===a.TEXTURE_2D||K>=a.TEXTURE_CUBE_MAP_POSITIVE_X&&K<=a.TEXTURE_CUBE_MAP_NEGATIVE_Z)&&a.framebufferTexture2D(a.FRAMEBUFFER,W,K,Lt.__webglTexture,ot),e.bindFramebuffer(a.FRAMEBUFFER,null)}function Pt(D,_,U){if(a.bindRenderbuffer(a.RENDERBUFFER,D),_.depthBuffer){const W=_.depthTexture,K=W&&W.isDepthTexture?W.type:null,ot=b(_.stencilBuffer,K),lt=_.stencilBuffer?a.DEPTH_STENCIL_ATTACHMENT:a.DEPTH_ATTACHMENT;fi(_)?o.renderbufferStorageMultisampleEXT(a.RENDERBUFFER,ii(_),ot,_.width,_.height):U?a.renderbufferStorageMultisample(a.RENDERBUFFER,ii(_),ot,_.width,_.height):a.renderbufferStorage(a.RENDERBUFFER,ot,_.width,_.height),a.framebufferRenderbuffer(a.FRAMEBUFFER,lt,a.RENDERBUFFER,D)}else{const W=_.textures;for(let K=0;K<W.length;K++){const ot=W[K],lt=s.convert(ot.format,ot.colorSpace),Z=s.convert(ot.type),Q=M(ot.internalFormat,lt,Z,ot.normalized,ot.colorSpace);fi(_)?o.renderbufferStorageMultisampleEXT(a.RENDERBUFFER,ii(_),Q,_.width,_.height):U?a.renderbufferStorageMultisample(a.RENDERBUFFER,ii(_),Q,_.width,_.height):a.renderbufferStorage(a.RENDERBUFFER,Q,_.width,_.height)}}a.bindRenderbuffer(a.RENDERBUFFER,null)}function St(D,_,U){const W=_.isWebGLCubeRenderTarget===!0;if(e.bindFramebuffer(a.FRAMEBUFFER,D),!(_.depthTexture&&_.depthTexture.isDepthTexture))throw new Error("THREE.WebGLTextures: renderTarget.depthTexture must be an instance of THREE.DepthTexture.");const K=i.get(_.depthTexture);if(K.__renderTarget=_,(!K.__webglTexture||_.depthTexture.image.width!==_.width||_.depthTexture.image.height!==_.height)&&(_.depthTexture.image.width=_.width,_.depthTexture.image.height=_.height,_.depthTexture.needsUpdate=!0),W){if(K.__webglInit===void 0&&(K.__webglInit=!0,_.depthTexture.addEventListener("dispose",T)),K.__webglTexture===void 0){K.__webglTexture=a.createTexture(),e.bindTexture(a.TEXTURE_CUBE_MAP,K.__webglTexture),Kt(a.TEXTURE_CUBE_MAP,_.depthTexture);const ht=s.convert(_.depthTexture.format),Lt=s.convert(_.depthTexture.type);let ft;_.depthTexture.format===Fs?ft=a.DEPTH_COMPONENT24:_.depthTexture.format===Or&&(ft=a.DEPTH24_STENCIL8);for(let ut=0;ut<6;ut++)a.texImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+ut,0,ft,_.width,_.height,0,ht,Lt,null)}}else $(_.depthTexture,0);const ot=K.__webglTexture,lt=ii(_),Z=W?a.TEXTURE_CUBE_MAP_POSITIVE_X+U:a.TEXTURE_2D,Q=_.depthTexture.format===Or?a.DEPTH_STENCIL_ATTACHMENT:a.DEPTH_ATTACHMENT;if(_.depthTexture.format===Fs)fi(_)?o.framebufferTexture2DMultisampleEXT(a.FRAMEBUFFER,Q,Z,ot,0,lt):a.framebufferTexture2D(a.FRAMEBUFFER,Q,Z,ot,0);else if(_.depthTexture.format===Or)fi(_)?o.framebufferTexture2DMultisampleEXT(a.FRAMEBUFFER,Q,Z,ot,0,lt):a.framebufferTexture2D(a.FRAMEBUFFER,Q,Z,ot,0);else throw new Error("THREE.WebGLTextures: Unknown depthTexture format.")}function zt(D){const _=i.get(D),U=D.isWebGLCubeRenderTarget===!0;if(_.__boundDepthTexture!==D.depthTexture){const W=D.depthTexture;if(_.__depthDisposeCallback&&_.__depthDisposeCallback(),W){const K=()=>{delete _.__boundDepthTexture,delete _.__depthDisposeCallback,W.removeEventListener("dispose",K)};W.addEventListener("dispose",K),_.__depthDisposeCallback=K}_.__boundDepthTexture=W}if(D.depthTexture&&!_.__autoAllocateDepthBuffer)if(U)for(let W=0;W<6;W++)St(_.__webglFramebuffer[W],D,W);else{const W=D.texture.mipmaps;W&&W.length>0?St(_.__webglFramebuffer[0],D,0):St(_.__webglFramebuffer,D,0)}else if(U){_.__webglDepthbuffer=[];for(let W=0;W<6;W++)if(e.bindFramebuffer(a.FRAMEBUFFER,_.__webglFramebuffer[W]),_.__webglDepthbuffer[W]===void 0)_.__webglDepthbuffer[W]=a.createRenderbuffer(),Pt(_.__webglDepthbuffer[W],D,!1);else{const K=D.stencilBuffer?a.DEPTH_STENCIL_ATTACHMENT:a.DEPTH_ATTACHMENT,ot=_.__webglDepthbuffer[W];a.bindRenderbuffer(a.RENDERBUFFER,ot),a.framebufferRenderbuffer(a.FRAMEBUFFER,K,a.RENDERBUFFER,ot)}}else{const W=D.texture.mipmaps;if(W&&W.length>0?e.bindFramebuffer(a.FRAMEBUFFER,_.__webglFramebuffer[0]):e.bindFramebuffer(a.FRAMEBUFFER,_.__webglFramebuffer),_.__webglDepthbuffer===void 0)_.__webglDepthbuffer=a.createRenderbuffer(),Pt(_.__webglDepthbuffer,D,!1);else{const K=D.stencilBuffer?a.DEPTH_STENCIL_ATTACHMENT:a.DEPTH_ATTACHMENT,ot=_.__webglDepthbuffer;a.bindRenderbuffer(a.RENDERBUFFER,ot),a.framebufferRenderbuffer(a.FRAMEBUFFER,K,a.RENDERBUFFER,ot)}}e.bindFramebuffer(a.FRAMEBUFFER,null)}function Bt(D,_,U){const W=i.get(D);_!==void 0&&Ft(W.__webglFramebuffer,D,D.texture,a.COLOR_ATTACHMENT0,a.TEXTURE_2D,0),U!==void 0&&zt(D)}function Ht(D){const _=D.texture,U=i.get(D),W=i.get(_);D.addEventListener("dispose",y);const K=D.textures,ot=D.isWebGLCubeRenderTarget===!0,lt=K.length>1;if(lt||(W.__webglTexture===void 0&&(W.__webglTexture=a.createTexture()),W.__version=_.version,r.memory.textures++),ot){U.__webglFramebuffer=[];for(let Z=0;Z<6;Z++)if(_.mipmaps&&_.mipmaps.length>0){U.__webglFramebuffer[Z]=[];for(let Q=0;Q<_.mipmaps.length;Q++)U.__webglFramebuffer[Z][Q]=a.createFramebuffer()}else U.__webglFramebuffer[Z]=a.createFramebuffer()}else{if(_.mipmaps&&_.mipmaps.length>0){U.__webglFramebuffer=[];for(let Z=0;Z<_.mipmaps.length;Z++)U.__webglFramebuffer[Z]=a.createFramebuffer()}else U.__webglFramebuffer=a.createFramebuffer();if(lt)for(let Z=0,Q=K.length;Z<Q;Z++){const ht=i.get(K[Z]);ht.__webglTexture===void 0&&(ht.__webglTexture=a.createTexture(),r.memory.textures++)}if(D.samples>0&&fi(D)===!1){U.__webglMultisampledFramebuffer=a.createFramebuffer(),U.__webglColorRenderbuffer=[],e.bindFramebuffer(a.FRAMEBUFFER,U.__webglMultisampledFramebuffer);for(let Z=0;Z<K.length;Z++){const Q=K[Z];U.__webglColorRenderbuffer[Z]=a.createRenderbuffer(),a.bindRenderbuffer(a.RENDERBUFFER,U.__webglColorRenderbuffer[Z]);const ht=s.convert(Q.format,Q.colorSpace),Lt=s.convert(Q.type),ft=M(Q.internalFormat,ht,Lt,Q.normalized,Q.colorSpace,D.isXRRenderTarget===!0),ut=ii(D);a.renderbufferStorageMultisample(a.RENDERBUFFER,ut,ft,D.width,D.height),a.framebufferRenderbuffer(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0+Z,a.RENDERBUFFER,U.__webglColorRenderbuffer[Z])}a.bindRenderbuffer(a.RENDERBUFFER,null),D.depthBuffer&&(U.__webglDepthRenderbuffer=a.createRenderbuffer(),Pt(U.__webglDepthRenderbuffer,D,!0)),e.bindFramebuffer(a.FRAMEBUFFER,null)}}if(ot){e.bindTexture(a.TEXTURE_CUBE_MAP,W.__webglTexture),Kt(a.TEXTURE_CUBE_MAP,_);for(let Z=0;Z<6;Z++)if(_.mipmaps&&_.mipmaps.length>0)for(let Q=0;Q<_.mipmaps.length;Q++)Ft(U.__webglFramebuffer[Z][Q],D,_,a.COLOR_ATTACHMENT0,a.TEXTURE_CUBE_MAP_POSITIVE_X+Z,Q);else Ft(U.__webglFramebuffer[Z],D,_,a.COLOR_ATTACHMENT0,a.TEXTURE_CUBE_MAP_POSITIVE_X+Z,0);g(_)&&S(a.TEXTURE_CUBE_MAP),e.unbindTexture()}else if(lt){for(let Z=0,Q=K.length;Z<Q;Z++){const ht=K[Z],Lt=i.get(ht);let ft=a.TEXTURE_2D;(D.isWebGL3DRenderTarget||D.isWebGLArrayRenderTarget)&&(ft=D.isWebGL3DRenderTarget?a.TEXTURE_3D:a.TEXTURE_2D_ARRAY),e.bindTexture(ft,Lt.__webglTexture),Kt(ft,ht),Ft(U.__webglFramebuffer,D,ht,a.COLOR_ATTACHMENT0+Z,ft,0),g(ht)&&S(ft)}e.unbindTexture()}else{let Z=a.TEXTURE_2D;if((D.isWebGL3DRenderTarget||D.isWebGLArrayRenderTarget)&&(Z=D.isWebGL3DRenderTarget?a.TEXTURE_3D:a.TEXTURE_2D_ARRAY),e.bindTexture(Z,W.__webglTexture),Kt(Z,_),_.mipmaps&&_.mipmaps.length>0)for(let Q=0;Q<_.mipmaps.length;Q++)Ft(U.__webglFramebuffer[Q],D,_,a.COLOR_ATTACHMENT0,Z,Q);else Ft(U.__webglFramebuffer,D,_,a.COLOR_ATTACHMENT0,Z,0);g(_)&&S(Z),e.unbindTexture()}D.depthBuffer&&zt(D)}function ye(D){const _=D.textures;for(let U=0,W=_.length;U<W;U++){const K=_[U];if(g(K)){const ot=x(D),lt=i.get(K).__webglTexture;e.bindTexture(ot,lt),S(ot),e.unbindTexture()}}}const Se=[],ei=[];function Ve(D){if(D.samples>0){if(fi(D)===!1){const _=D.textures,U=D.width,W=D.height;let K=a.COLOR_BUFFER_BIT;const ot=D.stencilBuffer?a.DEPTH_STENCIL_ATTACHMENT:a.DEPTH_ATTACHMENT,lt=i.get(D),Z=_.length>1;if(Z)for(let ht=0;ht<_.length;ht++)e.bindFramebuffer(a.FRAMEBUFFER,lt.__webglMultisampledFramebuffer),a.framebufferRenderbuffer(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0+ht,a.RENDERBUFFER,null),e.bindFramebuffer(a.FRAMEBUFFER,lt.__webglFramebuffer),a.framebufferTexture2D(a.DRAW_FRAMEBUFFER,a.COLOR_ATTACHMENT0+ht,a.TEXTURE_2D,null,0);e.bindFramebuffer(a.READ_FRAMEBUFFER,lt.__webglMultisampledFramebuffer);const Q=D.texture.mipmaps;Q&&Q.length>0?e.bindFramebuffer(a.DRAW_FRAMEBUFFER,lt.__webglFramebuffer[0]):e.bindFramebuffer(a.DRAW_FRAMEBUFFER,lt.__webglFramebuffer);for(let ht=0;ht<_.length;ht++){if(D.resolveDepthBuffer&&(D.depthBuffer&&(K|=a.DEPTH_BUFFER_BIT),D.stencilBuffer&&D.resolveStencilBuffer&&(K|=a.STENCIL_BUFFER_BIT)),Z){a.framebufferRenderbuffer(a.READ_FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.RENDERBUFFER,lt.__webglColorRenderbuffer[ht]);const Lt=i.get(_[ht]).__webglTexture;a.framebufferTexture2D(a.DRAW_FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.TEXTURE_2D,Lt,0)}a.blitFramebuffer(0,0,U,W,0,0,U,W,K,a.NEAREST),c===!0&&(Se.length=0,ei.length=0,Se.push(a.COLOR_ATTACHMENT0+ht),D.depthBuffer&&D.resolveDepthBuffer===!1&&(Se.push(ot),ei.push(ot),a.invalidateFramebuffer(a.DRAW_FRAMEBUFFER,ei)),a.invalidateFramebuffer(a.READ_FRAMEBUFFER,Se))}if(e.bindFramebuffer(a.READ_FRAMEBUFFER,null),e.bindFramebuffer(a.DRAW_FRAMEBUFFER,null),Z)for(let ht=0;ht<_.length;ht++){e.bindFramebuffer(a.FRAMEBUFFER,lt.__webglMultisampledFramebuffer),a.framebufferRenderbuffer(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0+ht,a.RENDERBUFFER,lt.__webglColorRenderbuffer[ht]);const Lt=i.get(_[ht]).__webglTexture;e.bindFramebuffer(a.FRAMEBUFFER,lt.__webglFramebuffer),a.framebufferTexture2D(a.DRAW_FRAMEBUFFER,a.COLOR_ATTACHMENT0+ht,a.TEXTURE_2D,Lt,0)}e.bindFramebuffer(a.DRAW_FRAMEBUFFER,lt.__webglMultisampledFramebuffer)}else if(D.depthBuffer&&D.resolveDepthBuffer===!1&&c){const _=D.stencilBuffer?a.DEPTH_STENCIL_ATTACHMENT:a.DEPTH_ATTACHMENT;a.invalidateFramebuffer(a.DRAW_FRAMEBUFFER,[_])}}}function ii(D){return Math.min(n.maxSamples,D.samples)}function fi(D){const _=i.get(D);return D.samples>0&&t.has("WEBGL_multisampled_render_to_texture")===!0&&_.__useRenderToTexture!==!1}function N(D){const _=r.render.frame;h.get(D)!==_&&(h.set(D,_),D.update())}function Ji(D,_){const U=D.colorSpace,W=D.format,K=D.type;return D.isCompressedTexture===!0||D.isVideoTexture===!0||U!==Vl&&U!==rr&&(ce.getTransfer(U)===we?(W!==Di||K!==yn)&&It("WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType."):Wt("WebGLTextures: Unsupported texture color space:",U)),_}function _e(D){return typeof HTMLImageElement<"u"&&D instanceof HTMLImageElement?(l.width=D.naturalWidth||D.width,l.height=D.naturalHeight||D.height):typeof VideoFrame<"u"&&D instanceof VideoFrame?(l.width=D.displayWidth,l.height=D.displayHeight):(l.width=D.width,l.height=D.height),l}this.allocateTextureUnit=B,this.resetTextureUnits=V,this.getTextureUnits=X,this.setTextureUnits=L,this.setTexture2D=$,this.setTexture2DArray=tt,this.setTexture3D=J,this.setTextureCube=it,this.rebindTextures=Bt,this.setupRenderTarget=Ht,this.updateRenderTargetMipmap=ye,this.updateMultisampleRenderTarget=Ve,this.setupDepthRenderbuffer=zt,this.setupFrameBufferTexture=Ft,this.useMultisampledRTT=fi,this.isReversedDepthBuffer=function(){return e.buffers.depth.getReversed()}}function Gb(a,t){function e(i,n=rr){let s;const r=ce.getTransfer(n);if(i===yn)return a.UNSIGNED_BYTE;if(i===D0)return a.UNSIGNED_SHORT_4_4_4_4;if(i===I0)return a.UNSIGNED_SHORT_5_5_5_1;if(i===c1)return a.UNSIGNED_INT_5_9_9_9_REV;if(i===l1)return a.UNSIGNED_INT_10F_11F_11F_REV;if(i===a1)return a.BYTE;if(i===o1)return a.SHORT;if(i===rc)return a.UNSIGNED_SHORT;if(i===R0)return a.INT;if(i===Nn)return a.UNSIGNED_INT;if(i===Ui)return a.FLOAT;if(i===$e)return a.HALF_FLOAT;if(i===h1)return a.ALPHA;if(i===u1)return a.RGB;if(i===Di)return a.RGBA;if(i===Fs)return a.DEPTH_COMPONENT;if(i===Or)return a.DEPTH_STENCIL;if(i===dh)return a.RED;if(i===C0)return a.RED_INTEGER;if(i===Yr)return a.RG;if(i===P0)return a.RG_INTEGER;if(i===L0)return a.RGBA_INTEGER;if(i===Al||i===Tl||i===Rl||i===Dl)if(r===we)if(s=t.get("WEBGL_compressed_texture_s3tc_srgb"),s!==null){if(i===Al)return s.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(i===Tl)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(i===Rl)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(i===Dl)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else return null;else if(s=t.get("WEBGL_compressed_texture_s3tc"),s!==null){if(i===Al)return s.COMPRESSED_RGB_S3TC_DXT1_EXT;if(i===Tl)return s.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(i===Rl)return s.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(i===Dl)return s.COMPRESSED_RGBA_S3TC_DXT5_EXT}else return null;if(i===ld||i===hd||i===ud||i===dd)if(s=t.get("WEBGL_compressed_texture_pvrtc"),s!==null){if(i===ld)return s.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(i===hd)return s.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(i===ud)return s.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(i===dd)return s.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}else return null;if(i===fd||i===pd||i===md||i===gd||i===vd||i===kl||i===Md)if(s=t.get("WEBGL_compressed_texture_etc"),s!==null){if(i===fd||i===pd)return r===we?s.COMPRESSED_SRGB8_ETC2:s.COMPRESSED_RGB8_ETC2;if(i===md)return r===we?s.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:s.COMPRESSED_RGBA8_ETC2_EAC;if(i===gd)return s.COMPRESSED_R11_EAC;if(i===vd)return s.COMPRESSED_SIGNED_R11_EAC;if(i===kl)return s.COMPRESSED_RG11_EAC;if(i===Md)return s.COMPRESSED_SIGNED_RG11_EAC}else return null;if(i===xd||i===yd||i===Sd||i===_d||i===bd||i===wd||i===Ed||i===Ad||i===Td||i===Rd||i===Dd||i===Id||i===Cd||i===Pd)if(s=t.get("WEBGL_compressed_texture_astc"),s!==null){if(i===xd)return r===we?s.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:s.COMPRESSED_RGBA_ASTC_4x4_KHR;if(i===yd)return r===we?s.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:s.COMPRESSED_RGBA_ASTC_5x4_KHR;if(i===Sd)return r===we?s.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:s.COMPRESSED_RGBA_ASTC_5x5_KHR;if(i===_d)return r===we?s.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:s.COMPRESSED_RGBA_ASTC_6x5_KHR;if(i===bd)return r===we?s.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:s.COMPRESSED_RGBA_ASTC_6x6_KHR;if(i===wd)return r===we?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:s.COMPRESSED_RGBA_ASTC_8x5_KHR;if(i===Ed)return r===we?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:s.COMPRESSED_RGBA_ASTC_8x6_KHR;if(i===Ad)return r===we?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:s.COMPRESSED_RGBA_ASTC_8x8_KHR;if(i===Td)return r===we?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:s.COMPRESSED_RGBA_ASTC_10x5_KHR;if(i===Rd)return r===we?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:s.COMPRESSED_RGBA_ASTC_10x6_KHR;if(i===Dd)return r===we?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:s.COMPRESSED_RGBA_ASTC_10x8_KHR;if(i===Id)return r===we?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:s.COMPRESSED_RGBA_ASTC_10x10_KHR;if(i===Cd)return r===we?s.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:s.COMPRESSED_RGBA_ASTC_12x10_KHR;if(i===Pd)return r===we?s.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:s.COMPRESSED_RGBA_ASTC_12x12_KHR}else return null;if(i===Ld||i===Od||i===Nd)if(s=t.get("EXT_texture_compression_bptc"),s!==null){if(i===Ld)return r===we?s.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:s.COMPRESSED_RGBA_BPTC_UNORM_EXT;if(i===Od)return s.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT;if(i===Nd)return s.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT}else return null;if(i===Fd||i===Ud||i===zl||i===kd)if(s=t.get("EXT_texture_compression_rgtc"),s!==null){if(i===Fd)return s.COMPRESSED_RED_RGTC1_EXT;if(i===Ud)return s.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(i===zl)return s.COMPRESSED_RED_GREEN_RGTC2_EXT;if(i===kd)return s.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}else return null;return i===ac?a.UNSIGNED_INT_24_8:a[i]!==void 0?a[i]:null}return{convert:e}}const Vb=`
5504
5504
  void main() {
5505
5505
 
5506
5506
  gl_Position = vec4( position, 1.0 );
@@ -5524,7 +5524,7 @@ void main() {
5524
5524
 
5525
5525
  }
5526
5526
 
5527
- }`;class Xb{constructor(){this.texture=null,this.mesh=null,this.depthNear=0,this.depthFar=0}init(t,e){if(this.texture===null){const i=new b1(t.texture);(t.depthNear!==e.depthNear||t.depthFar!==e.depthFar)&&(this.depthNear=t.depthNear,this.depthFar=t.depthFar),this.texture=i}}getMesh(t){if(this.texture!==null&&this.mesh===null){const e=t.cameras[0].viewport,i=new de({vertexShader:Vb,fragmentShader:Wb,uniforms:{depthColor:{value:this.texture},depthWidth:{value:e.z},depthHeight:{value:e.w}}});this.mesh=new bt(new Zi(20,20),i)}return this.mesh}reset(){this.texture=null,this.mesh=null}getDepthTexture(){return this.texture}}class Yb extends vr{constructor(t,e){super();const i=this;let n=null,s=1,r=null,o="local-floor",c=1,l=null,h=null,u=null,d=null,f=null,p=null;const v=typeof XRWebGLBinding<"u",m=new Xb,g={},S=e.getContextAttributes();let x=null,M=null;const b=[],w=[],T=new Mt;let y=null;const A=new rn;A.viewport=new ae;const C=new rn;C.viewport=new ae;const I=[A,C],P=new Hx;let V=null,X=null;this.cameraAutoUpdate=!0,this.enabled=!1,this.isPresenting=!1,this.getController=function(q){let rt=b[q];return rt===void 0&&(rt=new kh,b[q]=rt),rt.getTargetRaySpace()},this.getControllerGrip=function(q){let rt=b[q];return rt===void 0&&(rt=new kh,b[q]=rt),rt.getGripSpace()},this.getHand=function(q){let rt=b[q];return rt===void 0&&(rt=new kh,b[q]=rt),rt.getHandSpace()};function L(q){const rt=w.indexOf(q.inputSource);if(rt===-1)return;const nt=b[rt];nt!==void 0&&(nt.update(q.inputSource,q.frame,l||r),nt.dispatchEvent({type:q.type,data:q.inputSource}))}function B(){n.removeEventListener("select",L),n.removeEventListener("selectstart",L),n.removeEventListener("selectend",L),n.removeEventListener("squeeze",L),n.removeEventListener("squeezestart",L),n.removeEventListener("squeezeend",L),n.removeEventListener("end",B),n.removeEventListener("inputsourceschange",k);for(let q=0;q<b.length;q++){const rt=w[q];rt!==null&&(w[q]=null,b[q].disconnect(rt))}V=null,X=null,m.reset();for(const q in g)delete g[q];t.setRenderTarget(x),f=null,d=null,u=null,n=null,M=null,Kt.stop(),i.isPresenting=!1,t.setPixelRatio(y),t.setSize(T.width,T.height,!1),i.dispatchEvent({type:"sessionend"})}this.setFramebufferScaleFactor=function(q){s=q,i.isPresenting===!0&&It("WebXRManager: Cannot change framebuffer scale while presenting.")},this.setReferenceSpaceType=function(q){o=q,i.isPresenting===!0&&It("WebXRManager: Cannot change reference space type while presenting.")},this.getReferenceSpace=function(){return l||r},this.setReferenceSpace=function(q){l=q},this.getBaseLayer=function(){return d!==null?d:f},this.getBinding=function(){return u===null&&v&&(u=new XRWebGLBinding(n,e)),u},this.getFrame=function(){return p},this.getSession=function(){return n},this.setSession=async function(q){if(n=q,n!==null){if(x=t.getRenderTarget(),n.addEventListener("select",L),n.addEventListener("selectstart",L),n.addEventListener("selectend",L),n.addEventListener("squeeze",L),n.addEventListener("squeezestart",L),n.addEventListener("squeezeend",L),n.addEventListener("end",B),n.addEventListener("inputsourceschange",k),S.xrCompatible!==!0&&await e.makeXRCompatible(),y=t.getPixelRatio(),t.getSize(T),v&&"createProjectionLayer"in XRWebGLBinding.prototype){let nt=null,z=null,Rt=null;S.depth&&(Rt=S.stencil?e.DEPTH24_STENCIL8:e.DEPTH_COMPONENT24,nt=S.stencil?Or:Fs,z=S.stencil?ac:Nn);const Ft={colorFormat:e.RGBA8,depthFormat:Rt,scaleFactor:s};u=this.getBinding(),d=u.createProjectionLayer(Ft),n.updateRenderState({layers:[d]}),t.setPixelRatio(1),t.setSize(d.textureWidth,d.textureHeight,!1),M=new Qe(d.textureWidth,d.textureHeight,{format:Di,type:yn,depthTexture:new mr(d.textureWidth,d.textureHeight,z,void 0,void 0,void 0,void 0,void 0,void 0,nt),stencilBuffer:S.stencil,colorSpace:t.outputColorSpace,samples:S.antialias?4:0,resolveDepthBuffer:d.ignoreDepthValues===!1,resolveStencilBuffer:d.ignoreDepthValues===!1})}else{const nt={antialias:S.antialias,alpha:!0,depth:S.depth,stencil:S.stencil,framebufferScaleFactor:s};f=new XRWebGLLayer(n,e,nt),n.updateRenderState({baseLayer:f}),t.setPixelRatio(1),t.setSize(f.framebufferWidth,f.framebufferHeight,!1),M=new Qe(f.framebufferWidth,f.framebufferHeight,{format:Di,type:yn,colorSpace:t.outputColorSpace,stencilBuffer:S.stencil,resolveDepthBuffer:f.ignoreDepthValues===!1,resolveStencilBuffer:f.ignoreDepthValues===!1})}M.isXRRenderTarget=!0,this.setFoveation(c),l=null,r=await n.requestReferenceSpace(o),Kt.setContext(n),Kt.start(),i.isPresenting=!0,i.dispatchEvent({type:"sessionstart"})}},this.getEnvironmentBlendMode=function(){if(n!==null)return n.environmentBlendMode},this.getDepthTexture=function(){return m.getDepthTexture()};function k(q){for(let rt=0;rt<q.removed.length;rt++){const nt=q.removed[rt],z=w.indexOf(nt);z>=0&&(w[z]=null,b[z].disconnect(nt))}for(let rt=0;rt<q.added.length;rt++){const nt=q.added[rt];let z=w.indexOf(nt);if(z===-1){for(let Ft=0;Ft<b.length;Ft++)if(Ft>=w.length){w.push(nt),z=Ft;break}else if(w[Ft]===null){w[Ft]=nt,z=Ft;break}if(z===-1)break}const Rt=b[z];Rt&&Rt.connect(nt)}}const $=new R,tt=new R;function J(q,rt,nt){$.setFromMatrixPosition(rt.matrixWorld),tt.setFromMatrixPosition(nt.matrixWorld);const z=$.distanceTo(tt),Rt=rt.projectionMatrix.elements,Ft=nt.projectionMatrix.elements,Pt=Rt[14]/(Rt[10]-1),St=Rt[14]/(Rt[10]+1),zt=(Rt[9]+1)/Rt[5],Bt=(Rt[9]-1)/Rt[5],Ht=(Rt[8]-1)/Rt[0],ye=(Ft[8]+1)/Ft[0],Se=Pt*Ht,ei=Pt*ye,Ve=z/(-Ht+ye),ii=Ve*-Ht;if(rt.matrixWorld.decompose(q.position,q.quaternion,q.scale),q.translateX(ii),q.translateZ(Ve),q.matrixWorld.compose(q.position,q.quaternion,q.scale),q.matrixWorldInverse.copy(q.matrixWorld).invert(),Rt[10]===-1)q.projectionMatrix.copy(rt.projectionMatrix),q.projectionMatrixInverse.copy(rt.projectionMatrixInverse);else{const fi=Pt+Ve,N=St+Ve,Ji=Se-ii,_e=ei+(z-ii),D=zt*St/N*fi,_=Bt*St/N*fi;q.projectionMatrix.makePerspective(Ji,_e,D,_,fi,N),q.projectionMatrixInverse.copy(q.projectionMatrix).invert()}}function it(q,rt){rt===null?q.matrixWorld.copy(q.matrix):q.matrixWorld.multiplyMatrices(rt.matrixWorld,q.matrix),q.matrixWorldInverse.copy(q.matrixWorld).invert()}this.updateCamera=function(q){if(n===null)return;let rt=q.near,nt=q.far;m.texture!==null&&(m.depthNear>0&&(rt=m.depthNear),m.depthFar>0&&(nt=m.depthFar)),P.near=C.near=A.near=rt,P.far=C.far=A.far=nt,(V!==P.near||X!==P.far)&&(n.updateRenderState({depthNear:P.near,depthFar:P.far}),V=P.near,X=P.far),P.layers.mask=q.layers.mask|6,A.layers.mask=P.layers.mask&-5,C.layers.mask=P.layers.mask&-3;const z=q.parent,Rt=P.cameras;it(P,z);for(let Ft=0;Ft<Rt.length;Ft++)it(Rt[Ft],z);Rt.length===2?J(P,A,C):P.projectionMatrix.copy(A.projectionMatrix),at(q,P,z)};function at(q,rt,nt){nt===null?q.matrix.copy(rt.matrixWorld):(q.matrix.copy(nt.matrixWorld),q.matrix.invert(),q.matrix.multiply(rt.matrixWorld)),q.matrix.decompose(q.position,q.quaternion,q.scale),q.updateMatrixWorld(!0),q.projectionMatrix.copy(rt.projectionMatrix),q.projectionMatrixInverse.copy(rt.projectionMatrixInverse),q.isPerspectiveCamera&&(q.fov=Qa*2*Math.atan(1/q.projectionMatrix.elements[5]),q.zoom=1)}this.getCamera=function(){return P},this.getFoveation=function(){if(!(d===null&&f===null))return c},this.setFoveation=function(q){c=q,d!==null&&(d.fixedFoveation=q),f!==null&&f.fixedFoveation!==void 0&&(f.fixedFoveation=q)},this.hasDepthSensing=function(){return m.texture!==null},this.getDepthSensingMesh=function(){return m.getMesh(P)},this.getCameraTexture=function(q){return g[q]};let Xt=null;function ee(q,rt){if(h=rt.getViewerPose(l||r),p=rt,h!==null){const nt=h.views;f!==null&&(t.setRenderTargetFramebuffer(M,f.framebuffer),t.setRenderTarget(M));let z=!1;nt.length!==P.cameras.length&&(P.cameras.length=0,z=!0);for(let St=0;St<nt.length;St++){const zt=nt[St];let Bt=null;if(f!==null)Bt=f.getViewport(zt);else{const ye=u.getViewSubImage(d,zt);Bt=ye.viewport,St===0&&(t.setRenderTargetTextures(M,ye.colorTexture,ye.depthStencilTexture),t.setRenderTarget(M))}let Ht=I[St];Ht===void 0&&(Ht=new rn,Ht.layers.enable(St),Ht.viewport=new ae,I[St]=Ht),Ht.matrix.fromArray(zt.transform.matrix),Ht.matrix.decompose(Ht.position,Ht.quaternion,Ht.scale),Ht.projectionMatrix.fromArray(zt.projectionMatrix),Ht.projectionMatrixInverse.copy(Ht.projectionMatrix).invert(),Ht.viewport.set(Bt.x,Bt.y,Bt.width,Bt.height),St===0&&(P.matrix.copy(Ht.matrix),P.matrix.decompose(P.position,P.quaternion,P.scale)),z===!0&&P.cameras.push(Ht)}const Rt=n.enabledFeatures;if(Rt&&Rt.includes("depth-sensing")&&n.depthUsage=="gpu-optimized"&&v){u=i.getBinding();const St=u.getDepthInformation(nt[0]);St&&St.isValid&&St.texture&&m.init(St,n.renderState)}if(Rt&&Rt.includes("camera-access")&&v){t.state.unbindTexture(),u=i.getBinding();for(let St=0;St<nt.length;St++){const zt=nt[St].camera;if(zt){let Bt=g[zt];Bt||(Bt=new b1,g[zt]=Bt);const Ht=u.getCameraImage(zt);Bt.sourceTexture=Ht}}}}for(let nt=0;nt<b.length;nt++){const z=w[nt],Rt=b[nt];z!==null&&Rt!==void 0&&Rt.update(z,rt,l||r)}Xt&&Xt(q,rt),rt.detectedPlanes&&i.dispatchEvent({type:"planesdetected",data:rt}),p=null}const Kt=new P1;Kt.setAnimationLoop(ee),this.setAnimationLoop=function(q){Xt=q},this.dispose=function(){}}}const qb=new te,k1=new $t;k1.set(-1,0,0,0,1,0,0,0,1);function $b(a,t){function e(m,g){m.matrixAutoUpdate===!0&&m.updateMatrix(),g.value.copy(m.matrix)}function i(m,g){g.color.getRGB(m.fogColor.value,w1(a)),g.isFog?(m.fogNear.value=g.near,m.fogFar.value=g.far):g.isFogExp2&&(m.fogDensity.value=g.density)}function n(m,g,S,x,M){g.isNodeMaterial?g.uniformsNeedUpdate=!1:g.isMeshBasicMaterial?s(m,g):g.isMeshLambertMaterial?(s(m,g),g.envMap&&(m.envMapIntensity.value=g.envMapIntensity)):g.isMeshToonMaterial?(s(m,g),u(m,g)):g.isMeshPhongMaterial?(s(m,g),h(m,g),g.envMap&&(m.envMapIntensity.value=g.envMapIntensity)):g.isMeshStandardMaterial?(s(m,g),d(m,g),g.isMeshPhysicalMaterial&&f(m,g,M)):g.isMeshMatcapMaterial?(s(m,g),p(m,g)):g.isMeshDepthMaterial?s(m,g):g.isMeshDistanceMaterial?(s(m,g),v(m,g)):g.isMeshNormalMaterial?s(m,g):g.isLineBasicMaterial?(r(m,g),g.isLineDashedMaterial&&o(m,g)):g.isPointsMaterial?c(m,g,S,x):g.isSpriteMaterial?l(m,g):g.isShadowMaterial?(m.color.value.copy(g.color),m.opacity.value=g.opacity):g.isShaderMaterial&&(g.uniformsNeedUpdate=!1)}function s(m,g){m.opacity.value=g.opacity,g.color&&m.diffuse.value.copy(g.color),g.emissive&&m.emissive.value.copy(g.emissive).multiplyScalar(g.emissiveIntensity),g.map&&(m.map.value=g.map,e(g.map,m.mapTransform)),g.alphaMap&&(m.alphaMap.value=g.alphaMap,e(g.alphaMap,m.alphaMapTransform)),g.bumpMap&&(m.bumpMap.value=g.bumpMap,e(g.bumpMap,m.bumpMapTransform),m.bumpScale.value=g.bumpScale,g.side===qe&&(m.bumpScale.value*=-1)),g.normalMap&&(m.normalMap.value=g.normalMap,e(g.normalMap,m.normalMapTransform),m.normalScale.value.copy(g.normalScale),g.side===qe&&m.normalScale.value.negate()),g.displacementMap&&(m.displacementMap.value=g.displacementMap,e(g.displacementMap,m.displacementMapTransform),m.displacementScale.value=g.displacementScale,m.displacementBias.value=g.displacementBias),g.emissiveMap&&(m.emissiveMap.value=g.emissiveMap,e(g.emissiveMap,m.emissiveMapTransform)),g.specularMap&&(m.specularMap.value=g.specularMap,e(g.specularMap,m.specularMapTransform)),g.alphaTest>0&&(m.alphaTest.value=g.alphaTest);const S=t.get(g),x=S.envMap,M=S.envMapRotation;x&&(m.envMap.value=x,m.envMapRotation.value.setFromMatrix4(qb.makeRotationFromEuler(M)).transpose(),x.isCubeTexture&&x.isRenderTargetTexture===!1&&m.envMapRotation.value.premultiply(k1),m.reflectivity.value=g.reflectivity,m.ior.value=g.ior,m.refractionRatio.value=g.refractionRatio),g.lightMap&&(m.lightMap.value=g.lightMap,m.lightMapIntensity.value=g.lightMapIntensity,e(g.lightMap,m.lightMapTransform)),g.aoMap&&(m.aoMap.value=g.aoMap,m.aoMapIntensity.value=g.aoMapIntensity,e(g.aoMap,m.aoMapTransform))}function r(m,g){m.diffuse.value.copy(g.color),m.opacity.value=g.opacity,g.map&&(m.map.value=g.map,e(g.map,m.mapTransform))}function o(m,g){m.dashSize.value=g.dashSize,m.totalSize.value=g.dashSize+g.gapSize,m.scale.value=g.scale}function c(m,g,S,x){m.diffuse.value.copy(g.color),m.opacity.value=g.opacity,m.size.value=g.size*S,m.scale.value=x*.5,g.map&&(m.map.value=g.map,e(g.map,m.uvTransform)),g.alphaMap&&(m.alphaMap.value=g.alphaMap,e(g.alphaMap,m.alphaMapTransform)),g.alphaTest>0&&(m.alphaTest.value=g.alphaTest)}function l(m,g){m.diffuse.value.copy(g.color),m.opacity.value=g.opacity,m.rotation.value=g.rotation,g.map&&(m.map.value=g.map,e(g.map,m.mapTransform)),g.alphaMap&&(m.alphaMap.value=g.alphaMap,e(g.alphaMap,m.alphaMapTransform)),g.alphaTest>0&&(m.alphaTest.value=g.alphaTest)}function h(m,g){m.specular.value.copy(g.specular),m.shininess.value=Math.max(g.shininess,1e-4)}function u(m,g){g.gradientMap&&(m.gradientMap.value=g.gradientMap)}function d(m,g){m.metalness.value=g.metalness,g.metalnessMap&&(m.metalnessMap.value=g.metalnessMap,e(g.metalnessMap,m.metalnessMapTransform)),m.roughness.value=g.roughness,g.roughnessMap&&(m.roughnessMap.value=g.roughnessMap,e(g.roughnessMap,m.roughnessMapTransform)),g.envMap&&(m.envMapIntensity.value=g.envMapIntensity)}function f(m,g,S){m.ior.value=g.ior,g.sheen>0&&(m.sheenColor.value.copy(g.sheenColor).multiplyScalar(g.sheen),m.sheenRoughness.value=g.sheenRoughness,g.sheenColorMap&&(m.sheenColorMap.value=g.sheenColorMap,e(g.sheenColorMap,m.sheenColorMapTransform)),g.sheenRoughnessMap&&(m.sheenRoughnessMap.value=g.sheenRoughnessMap,e(g.sheenRoughnessMap,m.sheenRoughnessMapTransform))),g.clearcoat>0&&(m.clearcoat.value=g.clearcoat,m.clearcoatRoughness.value=g.clearcoatRoughness,g.clearcoatMap&&(m.clearcoatMap.value=g.clearcoatMap,e(g.clearcoatMap,m.clearcoatMapTransform)),g.clearcoatRoughnessMap&&(m.clearcoatRoughnessMap.value=g.clearcoatRoughnessMap,e(g.clearcoatRoughnessMap,m.clearcoatRoughnessMapTransform)),g.clearcoatNormalMap&&(m.clearcoatNormalMap.value=g.clearcoatNormalMap,e(g.clearcoatNormalMap,m.clearcoatNormalMapTransform),m.clearcoatNormalScale.value.copy(g.clearcoatNormalScale),g.side===qe&&m.clearcoatNormalScale.value.negate())),g.dispersion>0&&(m.dispersion.value=g.dispersion),g.iridescence>0&&(m.iridescence.value=g.iridescence,m.iridescenceIOR.value=g.iridescenceIOR,m.iridescenceThicknessMinimum.value=g.iridescenceThicknessRange[0],m.iridescenceThicknessMaximum.value=g.iridescenceThicknessRange[1],g.iridescenceMap&&(m.iridescenceMap.value=g.iridescenceMap,e(g.iridescenceMap,m.iridescenceMapTransform)),g.iridescenceThicknessMap&&(m.iridescenceThicknessMap.value=g.iridescenceThicknessMap,e(g.iridescenceThicknessMap,m.iridescenceThicknessMapTransform))),g.transmission>0&&(m.transmission.value=g.transmission,m.transmissionSamplerMap.value=S.texture,m.transmissionSamplerSize.value.set(S.width,S.height),g.transmissionMap&&(m.transmissionMap.value=g.transmissionMap,e(g.transmissionMap,m.transmissionMapTransform)),m.thickness.value=g.thickness,g.thicknessMap&&(m.thicknessMap.value=g.thicknessMap,e(g.thicknessMap,m.thicknessMapTransform)),m.attenuationDistance.value=g.attenuationDistance,m.attenuationColor.value.copy(g.attenuationColor)),g.anisotropy>0&&(m.anisotropyVector.value.set(g.anisotropy*Math.cos(g.anisotropyRotation),g.anisotropy*Math.sin(g.anisotropyRotation)),g.anisotropyMap&&(m.anisotropyMap.value=g.anisotropyMap,e(g.anisotropyMap,m.anisotropyMapTransform))),m.specularIntensity.value=g.specularIntensity,m.specularColor.value.copy(g.specularColor),g.specularColorMap&&(m.specularColorMap.value=g.specularColorMap,e(g.specularColorMap,m.specularColorMapTransform)),g.specularIntensityMap&&(m.specularIntensityMap.value=g.specularIntensityMap,e(g.specularIntensityMap,m.specularIntensityMapTransform))}function p(m,g){g.matcap&&(m.matcap.value=g.matcap)}function v(m,g){const S=t.get(g).light;m.referencePosition.value.setFromMatrixPosition(S.matrixWorld),m.nearDistance.value=S.shadow.camera.near,m.farDistance.value=S.shadow.camera.far}return{refreshFogUniforms:i,refreshMaterialUniforms:n}}function Kb(a,t,e,i){let n={},s={},r=[];const o=a.getParameter(a.MAX_UNIFORM_BUFFER_BINDINGS);function c(M,b){const w=b.program;i.uniformBlockBinding(M,w)}function l(M,b){let w=n[M.id];w===void 0&&(m(M),w=h(M),n[M.id]=w,M.addEventListener("dispose",S));const T=b.program;i.updateUBOMapping(M,T);const y=t.render.frame;s[M.id]!==y&&(d(M),s[M.id]=y)}function h(M){const b=u();M.__bindingPointIndex=b;const w=a.createBuffer(),T=M.__size,y=M.usage;return a.bindBuffer(a.UNIFORM_BUFFER,w),a.bufferData(a.UNIFORM_BUFFER,T,y),a.bindBuffer(a.UNIFORM_BUFFER,null),a.bindBufferBase(a.UNIFORM_BUFFER,b,w),w}function u(){for(let M=0;M<o;M++)if(r.indexOf(M)===-1)return r.push(M),M;return Wt("WebGLRenderer: Maximum number of simultaneously usable uniforms groups reached."),0}function d(M){const b=n[M.id],w=M.uniforms,T=M.__cache;a.bindBuffer(a.UNIFORM_BUFFER,b);for(let y=0,A=w.length;y<A;y++){const C=w[y];if(Array.isArray(C))for(let I=0,P=C.length;I<P;I++)f(C[I],y,I,T);else f(C,y,0,T)}a.bindBuffer(a.UNIFORM_BUFFER,null)}function f(M,b,w,T){if(v(M,b,w,T)===!0){const y=M.__offset,A=M.value;if(Array.isArray(A)){let C=0;for(let I=0;I<A.length;I++){const P=A[I],V=g(P);p(P,M.__data,C),typeof P!="number"&&typeof P!="boolean"&&!P.isMatrix3&&!ArrayBuffer.isView(P)&&(C+=V.storage/Float32Array.BYTES_PER_ELEMENT)}}else p(A,M.__data,0);a.bufferSubData(a.UNIFORM_BUFFER,y,M.__data)}}function p(M,b,w){typeof M=="number"||typeof M=="boolean"?b[0]=M:M.isMatrix3?(b[0]=M.elements[0],b[1]=M.elements[1],b[2]=M.elements[2],b[3]=0,b[4]=M.elements[3],b[5]=M.elements[4],b[6]=M.elements[5],b[7]=0,b[8]=M.elements[6],b[9]=M.elements[7],b[10]=M.elements[8],b[11]=0):ArrayBuffer.isView(M)?b.set(new M.constructor(M.buffer,M.byteOffset,b.length)):M.toArray(b,w)}function v(M,b,w,T){const y=M.value,A=b+"_"+w;if(T[A]===void 0)return typeof y=="number"||typeof y=="boolean"?T[A]=y:ArrayBuffer.isView(y)?T[A]=y.slice():T[A]=y.clone(),!0;{const C=T[A];if(typeof y=="number"||typeof y=="boolean"){if(C!==y)return T[A]=y,!0}else{if(ArrayBuffer.isView(y))return!0;if(C.equals(y)===!1)return C.copy(y),!0}}return!1}function m(M){const b=M.uniforms;let w=0;const T=16;for(let A=0,C=b.length;A<C;A++){const I=Array.isArray(b[A])?b[A]:[b[A]];for(let P=0,V=I.length;P<V;P++){const X=I[P],L=Array.isArray(X.value)?X.value:[X.value];for(let B=0,k=L.length;B<k;B++){const $=L[B],tt=g($),J=w%T,it=J%tt.boundary,at=J+it;w+=it,at!==0&&T-at<tt.storage&&(w+=T-at),X.__data=new Float32Array(tt.storage/Float32Array.BYTES_PER_ELEMENT),X.__offset=w,w+=tt.storage}}}const y=w%T;return y>0&&(w+=T-y),M.__size=w,M.__cache={},this}function g(M){const b={boundary:0,storage:0};return typeof M=="number"||typeof M=="boolean"?(b.boundary=4,b.storage=4):M.isVector2?(b.boundary=8,b.storage=8):M.isVector3||M.isColor?(b.boundary=16,b.storage=12):M.isVector4?(b.boundary=16,b.storage=16):M.isMatrix3?(b.boundary=48,b.storage=48):M.isMatrix4?(b.boundary=64,b.storage=64):M.isTexture?It("WebGLRenderer: Texture samplers can not be part of an uniforms group."):ArrayBuffer.isView(M)?(b.boundary=16,b.storage=M.byteLength):It("WebGLRenderer: Unsupported uniform value type.",M),b}function S(M){const b=M.target;b.removeEventListener("dispose",S);const w=r.indexOf(b.__bindingPointIndex);r.splice(w,1),a.deleteBuffer(n[b.id]),delete n[b.id],delete s[b.id]}function x(){for(const M in n)a.deleteBuffer(n[M]);r=[],n={},s={}}return{bind:c,update:l,dispose:x}}const Zb=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 ns=null;function Jb(){return ns===null&&(ns=new Mr(Zb,16,16,Yr,$e),ns.name="DFG_LUT",ns.minFilter=le,ns.magFilter=le,ns.wrapS=Ri,ns.wrapT=Ri,ns.generateMipmaps=!1,ns.needsUpdate=!0),ns}class jb{constructor(t={}){const{canvas:e=wM(),context:i=null,depth:n=!0,stencil:s=!1,alpha:r=!1,antialias:o=!1,premultipliedAlpha:c=!0,preserveDrawingBuffer:l=!1,powerPreference:h="default",failIfMajorPerformanceCaveat:u=!1,reversedDepthBuffer:d=!1,outputBufferType:f=yn}=t;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 v=f,m=new Set([L0,P0,C0]),g=new Set([yn,Nn,rc,ac,D0,I0]),S=new Uint32Array(4),x=new Int32Array(4),M=new R;let b=null,w=null;const T=[],y=[];let A=null;this.domElement=e,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=Ms,this.toneMappingExposure=1,this.transmissionResolutionScale=1;const C=this;let I=!1,P=null,V=null,X=null,L=null;this._outputColorSpace=qi;let B=0,k=0,$=null,tt=-1,J=null;const it=new ae,at=new ae;let Xt=null;const ee=new st(0);let Kt=0,q=e.width,rt=e.height,nt=1,z=null,Rt=null;const Ft=new ae(0,0,q,rt),Pt=new ae(0,0,q,rt);let St=!1;const zt=new G0;let Bt=!1,Ht=!1;const ye=new te,Se=new R,ei=new ae,Ve={background:null,fog:null,environment:null,overrideMaterial:null,isScene:!0};let ii=!1;function fi(){return $===null?nt:1}let N=i;function Ji(E,F){return e.getContext(E,F)}try{const E={alpha:!0,depth:n,stencil:s,antialias:o,premultipliedAlpha:c,preserveDrawingBuffer:l,powerPreference:h,failIfMajorPerformanceCaveat:u};if("setAttribute"in e&&e.setAttribute("data-engine",`three.js r${A0}`),e.addEventListener("webglcontextlost",ni,!1),e.addEventListener("webglcontextrestored",Ne,!1),e.addEventListener("webglcontextcreationerror",jn,!1),N===null){const F="webgl2";if(N=Ji(F,E),N===null)throw Ji(F)?new Error("THREE.WebGLRenderer: Error creating WebGL context with your selected attributes."):new Error("THREE.WebGLRenderer: Error creating WebGL context.")}}catch(E){throw Wt("WebGLRenderer: "+E.message),E}let _e,D,_,U,W,K,ot,lt,Z,Q,ht,Lt,ft,ut,kt,Gt,jt,O,ct,j,dt,vt,et;function Ct(){_e=new JS(N),_e.init(),dt=new Gb(N,_e),D=new VS(N,_e,t,dt),_=new Bb(N,_e),D.reversedDepthBuffer&&d&&_.buffers.depth.setReversed(!0),V=N.createFramebuffer(),X=N.createFramebuffer(),L=N.createFramebuffer(),U=new t_(N),W=new Ab,K=new Hb(N,_e,_,W,D,dt,U),ot=new ZS(C),lt=new sy(N),vt=new HS(N,lt),Z=new jS(N,lt,U,vt),Q=new i_(N,Z,lt,vt,U),O=new e_(N,D,K),kt=new WS(W),ht=new Eb(C,ot,_e,D,vt,kt),Lt=new $b(C,W),ft=new Rb,ut=new Ob(_e),jt=new BS(C,ot,_,Q,p,c),Gt=new zb(C,Q,D),et=new Kb(N,U,D,_),ct=new GS(N,_e,U),j=new QS(N,_e,U),U.programs=ht.programs,C.capabilities=D,C.extensions=_e,C.properties=W,C.renderLists=ft,C.shadowMap=Gt,C.state=_,C.info=U}Ct(),v!==yn&&(A=new s_(v,e.width,e.height,o,n,s));const wt=new Yb(C,N);this.xr=wt,this.getContext=function(){return N},this.getContextAttributes=function(){return N.getContextAttributes()},this.forceContextLoss=function(){const E=_e.get("WEBGL_lose_context");E&&E.loseContext()},this.forceContextRestore=function(){const E=_e.get("WEBGL_lose_context");E&&E.restoreContext()},this.getPixelRatio=function(){return nt},this.setPixelRatio=function(E){E!==void 0&&(nt=E,this.setSize(q,rt,!1))},this.getSize=function(E){return E.set(q,rt)},this.setSize=function(E,F,Y=!0){if(wt.isPresenting){It("WebGLRenderer: Can't change size while VR device is presenting.");return}q=E,rt=F,e.width=Math.floor(E*nt),e.height=Math.floor(F*nt),Y===!0&&(e.style.width=E+"px",e.style.height=F+"px"),A!==null&&A.setSize(e.width,e.height),this.setViewport(0,0,E,F)},this.getDrawingBufferSize=function(E){return E.set(q*nt,rt*nt).floor()},this.setDrawingBufferSize=function(E,F,Y){q=E,rt=F,nt=Y,e.width=Math.floor(E*Y),e.height=Math.floor(F*Y),this.setViewport(0,0,E,F)},this.setEffects=function(E){if(v===yn){Wt("WebGLRenderer: setEffects() requires outputBufferType set to HalfFloatType or FloatType.");return}if(E){for(let F=0;F<E.length;F++)if(E[F].isOutputPass===!0){It("WebGLRenderer: OutputPass is not needed in setEffects(). Tone mapping and color space conversion are applied automatically.");break}}A.setEffects(E||[])},this.getCurrentViewport=function(E){return E.copy(it)},this.getViewport=function(E){return E.copy(Ft)},this.setViewport=function(E,F,Y,H){E.isVector4?Ft.set(E.x,E.y,E.z,E.w):Ft.set(E,F,Y,H),_.viewport(it.copy(Ft).multiplyScalar(nt).round())},this.getScissor=function(E){return E.copy(Pt)},this.setScissor=function(E,F,Y,H){E.isVector4?Pt.set(E.x,E.y,E.z,E.w):Pt.set(E,F,Y,H),_.scissor(at.copy(Pt).multiplyScalar(nt).round())},this.getScissorTest=function(){return St},this.setScissorTest=function(E){_.setScissorTest(St=E)},this.setOpaqueSort=function(E){z=E},this.setTransparentSort=function(E){Rt=E},this.getClearColor=function(E){return E.copy(jt.getClearColor())},this.setClearColor=function(){jt.setClearColor(...arguments)},this.getClearAlpha=function(){return jt.getClearAlpha()},this.setClearAlpha=function(){jt.setClearAlpha(...arguments)},this.clear=function(E=!0,F=!0,Y=!0){let H=0;if(E){let G=!1;if($!==null){const gt=$.texture.format;G=m.has(gt)}if(G){const gt=$.texture.type,_t=g.has(gt),mt=jt.getClearColor(),Tt=jt.getClearAlpha(),Ot=mt.r,Qt=mt.g,ie=mt.b;_t?(S[0]=Ot,S[1]=Qt,S[2]=ie,S[3]=Tt,N.clearBufferuiv(N.COLOR,0,S)):(x[0]=Ot,x[1]=Qt,x[2]=ie,x[3]=Tt,N.clearBufferiv(N.COLOR,0,x))}else H|=N.COLOR_BUFFER_BIT}F&&(H|=N.DEPTH_BUFFER_BIT,this.state.buffers.depth.setMask(!0)),Y&&(H|=N.STENCIL_BUFFER_BIT,this.state.buffers.stencil.setMask(4294967295)),H!==0&&N.clear(H)},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(E){E.setRenderer(this),P=E},this.dispose=function(){e.removeEventListener("webglcontextlost",ni,!1),e.removeEventListener("webglcontextrestored",Ne,!1),e.removeEventListener("webglcontextcreationerror",jn,!1),jt.dispose(),ft.dispose(),ut.dispose(),W.dispose(),ot.dispose(),Q.dispose(),vt.dispose(),et.dispose(),ht.dispose(),wt.dispose(),wt.removeEventListener("sessionstart",gf),wt.removeEventListener("sessionend",vf),xr.stop()};function ni(E){E.preventDefault(),Yl("WebGLRenderer: Context Lost."),I=!0}function Ne(){Yl("WebGLRenderer: Context Restored."),I=!1;const E=U.autoReset,F=Gt.enabled,Y=Gt.autoUpdate,H=Gt.needsUpdate,G=Gt.type;Ct(),U.autoReset=E,Gt.enabled=F,Gt.autoUpdate=Y,Gt.needsUpdate=H,Gt.type=G}function jn(E){Wt("WebGLRenderer: A WebGL context could not be created. Reason: ",E.statusMessage)}function Qn(E){const F=E.target;F.removeEventListener("dispose",Qn),bv(F)}function bv(E){wv(E),W.remove(E)}function wv(E){const F=W.get(E).programs;F!==void 0&&(F.forEach(function(Y){ht.releaseProgram(Y)}),E.isShaderMaterial&&ht.releaseShaderCache(E))}this.renderBufferDirect=function(E,F,Y,H,G,gt){F===null&&(F=Ve);const _t=G.isMesh&&G.matrixWorld.determinantAffine()<0,mt=Tv(E,F,Y,H,G);_.setMaterial(H,_t);let Tt=Y.index,Ot=1;if(H.wireframe===!0){if(Tt=Z.getWireframeAttribute(Y),Tt===void 0)return;Ot=2}const Qt=Y.drawRange,ie=Y.attributes.position;let Nt=Qt.start*Ot,De=(Qt.start+Qt.count)*Ot;gt!==null&&(Nt=Math.max(Nt,gt.start*Ot),De=Math.min(De,(gt.start+gt.count)*Ot)),Tt!==null?(Nt=Math.max(Nt,0),De=Math.min(De,Tt.count)):ie!=null&&(Nt=Math.max(Nt,0),De=Math.min(De,ie.count));const ci=De-Nt;if(ci<0||ci===1/0)return;vt.setup(G,H,mt,Y,Tt);let si,Le=ct;if(Tt!==null&&(si=lt.get(Tt),Le=j,Le.setIndex(si)),G.isMesh)H.wireframe===!0?(_.setLineWidth(H.wireframeLinewidth*fi()),Le.setMode(N.LINES)):Le.setMode(N.TRIANGLES);else if(G.isLine){let Ci=H.linewidth;Ci===void 0&&(Ci=1),_.setLineWidth(Ci*fi()),G.isLineSegments?Le.setMode(N.LINES):G.isLineLoop?Le.setMode(N.LINE_LOOP):Le.setMode(N.LINE_STRIP)}else G.isPoints?Le.setMode(N.POINTS):G.isSprite&&Le.setMode(N.TRIANGLES);if(G.isBatchedMesh)if(_e.get("WEBGL_multi_draw"))Le.renderMultiDraw(G._multiDrawStarts,G._multiDrawCounts,G._multiDrawCount);else{const Ci=G._multiDrawStarts,yt=G._multiDrawCounts,cn=G._multiDrawCount,fe=Tt?lt.get(Tt).bytesPerElement:1,bn=W.get(H).currentProgram.getUniforms();for(let ts=0;ts<cn;ts++)bn.setValue(N,"_gl_DrawID",ts),Le.render(Ci[ts]/fe,yt[ts])}else if(G.isInstancedMesh)Le.renderInstances(Nt,ci,G.count);else if(Y.isInstancedBufferGeometry){const Ci=Y._maxInstanceCount!==void 0?Y._maxInstanceCount:1/0,yt=Math.min(Y.instanceCount,Ci);Le.renderInstances(Nt,ci,yt)}else Le.render(Nt,ci)};function mf(E,F,Y){E.transparent===!0&&E.side===xn&&E.forceSinglePass===!1?(E.side=qe,E.needsUpdate=!0,Mc(E,F,Y),E.side=pr,E.needsUpdate=!0,Mc(E,F,Y),E.side=xn):Mc(E,F,Y)}this.compile=function(E,F,Y=null){Y===null&&(Y=E),w=ut.get(Y),w.init(F),y.push(w),Y.traverseVisible(function(G){G.isLight&&G.layers.test(F.layers)&&(w.pushLight(G),G.castShadow&&w.pushShadow(G))}),E!==Y&&E.traverseVisible(function(G){G.isLight&&G.layers.test(F.layers)&&(w.pushLight(G),G.castShadow&&w.pushShadow(G))}),w.setupLights();const H=new Set;return E.traverse(function(G){if(!(G.isMesh||G.isPoints||G.isLine||G.isSprite))return;const gt=G.material;if(gt)if(Array.isArray(gt))for(let _t=0;_t<gt.length;_t++){const mt=gt[_t];mf(mt,Y,G),H.add(mt)}else mf(gt,Y,G),H.add(gt)}),w=y.pop(),H},this.compileAsync=function(E,F,Y=null){const H=this.compile(E,F,Y);return new Promise(G=>{function gt(){if(H.forEach(function(_t){W.get(_t).currentProgram.isReady()&&H.delete(_t)}),H.size===0){G(E);return}setTimeout(gt,10)}_e.get("KHR_parallel_shader_compile")!==null?gt():setTimeout(gt,10)})};let wh=null;function Ev(E){wh&&wh(E)}function gf(){xr.stop()}function vf(){xr.start()}const xr=new P1;xr.setAnimationLoop(Ev),typeof self<"u"&&xr.setContext(self),this.setAnimationLoop=function(E){wh=E,wt.setAnimationLoop(E),E===null?xr.stop():xr.start()},wt.addEventListener("sessionstart",gf),wt.addEventListener("sessionend",vf),this.render=function(E,F){if(F!==void 0&&F.isCamera!==!0){Wt("WebGLRenderer.render: camera is not an instance of THREE.Camera.");return}if(I===!0)return;P!==null&&P.renderStart(E,F);const Y=wt.enabled===!0&&wt.isPresenting===!0,H=A!==null&&($===null||Y)&&A.begin(C,$);if(E.matrixWorldAutoUpdate===!0&&E.updateMatrixWorld(),F.parent===null&&F.matrixWorldAutoUpdate===!0&&F.updateMatrixWorld(),wt.enabled===!0&&wt.isPresenting===!0&&(A===null||A.isCompositing()===!1)&&(wt.cameraAutoUpdate===!0&&wt.updateCamera(F),F=wt.getCamera()),E.isScene===!0&&E.onBeforeRender(C,E,F,$),w=ut.get(E,y.length),w.init(F),w.state.textureUnits=K.getTextureUnits(),y.push(w),ye.multiplyMatrices(F.projectionMatrix,F.matrixWorldInverse),zt.setFromProjectionMatrix(ye,ms,F.reversedDepth),Ht=this.localClippingEnabled,Bt=kt.init(this.clippingPlanes,Ht),b=ft.get(E,T.length),b.init(),T.push(b),wt.enabled===!0&&wt.isPresenting===!0){const _t=C.xr.getDepthSensingMesh();_t!==null&&Eh(_t,F,-1/0,C.sortObjects)}Eh(E,F,0,C.sortObjects),b.finish(),C.sortObjects===!0&&b.sort(z,Rt,F.reversedDepth),ii=wt.enabled===!1||wt.isPresenting===!1||wt.hasDepthSensing()===!1,ii&&jt.addToRenderList(b,E),this.info.render.frame++,this.info.autoReset===!0&&this.info.reset(),Bt===!0&&kt.beginShadows();const G=w.state.shadowsArray;if(Gt.render(G,E,F),Bt===!0&&kt.endShadows(),(H&&A.hasRenderPass())===!1){const _t=b.opaque,mt=b.transmissive;if(w.setupLights(),F.isArrayCamera){const Tt=F.cameras;if(mt.length>0)for(let Ot=0,Qt=Tt.length;Ot<Qt;Ot++){const ie=Tt[Ot];xf(_t,mt,E,ie)}ii&&jt.render(E);for(let Ot=0,Qt=Tt.length;Ot<Qt;Ot++){const ie=Tt[Ot];Mf(b,E,ie,ie.viewport)}}else mt.length>0&&xf(_t,mt,E,F),ii&&jt.render(E),Mf(b,E,F)}$!==null&&k===0&&(K.updateMultisampleRenderTarget($),K.updateRenderTargetMipmap($)),H&&A.end(C),E.isScene===!0&&E.onAfterRender(C,E,F),vt.resetDefaultState(),tt=-1,J=null,y.pop(),y.length>0?(w=y[y.length-1],K.setTextureUnits(w.state.textureUnits),Bt===!0&&kt.setGlobalState(C.clippingPlanes,w.state.camera)):w=null,T.pop(),T.length>0?b=T[T.length-1]:b=null,P!==null&&P.renderEnd()};function Eh(E,F,Y,H){if(E.visible===!1)return;if(E.layers.test(F.layers)){if(E.isGroup)Y=E.renderOrder;else if(E.isLOD)E.autoUpdate===!0&&E.update(F);else if(E.isLightProbeGrid)w.pushLightProbeGrid(E);else if(E.isLight)w.pushLight(E),E.castShadow&&w.pushShadow(E);else if(E.isSprite){if(!E.frustumCulled||zt.intersectsSprite(E)){H&&ei.setFromMatrixPosition(E.matrixWorld).applyMatrix4(ye);const _t=Q.update(E),mt=E.material;mt.visible&&b.push(E,_t,mt,Y,ei.z,null)}}else if((E.isMesh||E.isLine||E.isPoints)&&(!E.frustumCulled||zt.intersectsObject(E))){const _t=Q.update(E),mt=E.material;if(H&&(E.boundingSphere!==void 0?(E.boundingSphere===null&&E.computeBoundingSphere(),ei.copy(E.boundingSphere.center)):(_t.boundingSphere===null&&_t.computeBoundingSphere(),ei.copy(_t.boundingSphere.center)),ei.applyMatrix4(E.matrixWorld).applyMatrix4(ye)),Array.isArray(mt)){const Tt=_t.groups;for(let Ot=0,Qt=Tt.length;Ot<Qt;Ot++){const ie=Tt[Ot],Nt=mt[ie.materialIndex];Nt&&Nt.visible&&b.push(E,_t,Nt,Y,ei.z,ie)}}else mt.visible&&b.push(E,_t,mt,Y,ei.z,null)}}const gt=E.children;for(let _t=0,mt=gt.length;_t<mt;_t++)Eh(gt[_t],F,Y,H)}function Mf(E,F,Y,H){const{opaque:G,transmissive:gt,transparent:_t}=E;w.setupLightsView(Y),Bt===!0&&kt.setGlobalState(C.clippingPlanes,Y),H&&_.viewport(it.copy(H)),G.length>0&&vc(G,F,Y),gt.length>0&&vc(gt,F,Y),_t.length>0&&vc(_t,F,Y),_.buffers.depth.setTest(!0),_.buffers.depth.setMask(!0),_.buffers.color.setMask(!0),_.setPolygonOffset(!1)}function xf(E,F,Y,H){if((Y.isScene===!0?Y.overrideMaterial:null)!==null)return;if(w.state.transmissionRenderTarget[H.id]===void 0){const Nt=_e.has("EXT_color_buffer_half_float")||_e.has("EXT_color_buffer_float");w.state.transmissionRenderTarget[H.id]=new Qe(1,1,{generateMipmaps:!0,type:Nt?$e:yn,minFilter:Lr,samples:Math.max(4,D.samples),stencilBuffer:s,resolveDepthBuffer:!1,resolveStencilBuffer:!1,colorSpace:ce.workingColorSpace})}const gt=w.state.transmissionRenderTarget[H.id],_t=H.viewport||it;gt.setSize(_t.z*C.transmissionResolutionScale,_t.w*C.transmissionResolutionScale);const mt=C.getRenderTarget(),Tt=C.getActiveCubeFace(),Ot=C.getActiveMipmapLevel();C.setRenderTarget(gt),C.getClearColor(ee),Kt=C.getClearAlpha(),Kt<1&&C.setClearColor(16777215,.5),C.clear(),ii&&jt.render(Y);const Qt=C.toneMapping;C.toneMapping=Ms;const ie=H.viewport;if(H.viewport!==void 0&&(H.viewport=void 0),w.setupLightsView(H),Bt===!0&&kt.setGlobalState(C.clippingPlanes,H),vc(E,Y,H),K.updateMultisampleRenderTarget(gt),K.updateRenderTargetMipmap(gt),_e.has("WEBGL_multisampled_render_to_texture")===!1){let Nt=!1;for(let De=0,ci=F.length;De<ci;De++){const si=F[De],{object:Le,geometry:Ci,material:yt,group:cn}=si;if(yt.side===xn&&Le.layers.test(H.layers)){const fe=yt.side;yt.side=qe,yt.needsUpdate=!0,yf(Le,Y,H,Ci,yt,cn),yt.side=fe,yt.needsUpdate=!0,Nt=!0}}Nt===!0&&(K.updateMultisampleRenderTarget(gt),K.updateRenderTargetMipmap(gt))}C.setRenderTarget(mt,Tt,Ot),C.setClearColor(ee,Kt),ie!==void 0&&(H.viewport=ie),C.toneMapping=Qt}function vc(E,F,Y){const H=F.isScene===!0?F.overrideMaterial:null;for(let G=0,gt=E.length;G<gt;G++){const _t=E[G],{object:mt,geometry:Tt,group:Ot}=_t;let Qt=_t.material;Qt.allowOverride===!0&&H!==null&&(Qt=H),mt.layers.test(Y.layers)&&yf(mt,F,Y,Tt,Qt,Ot)}}function yf(E,F,Y,H,G,gt){E.onBeforeRender(C,F,Y,H,G,gt),E.modelViewMatrix.multiplyMatrices(Y.matrixWorldInverse,E.matrixWorld),E.normalMatrix.getNormalMatrix(E.modelViewMatrix),G.onBeforeRender(C,F,Y,H,E,gt),G.transparent===!0&&G.side===xn&&G.forceSinglePass===!1?(G.side=qe,G.needsUpdate=!0,C.renderBufferDirect(Y,F,H,G,E,gt),G.side=pr,G.needsUpdate=!0,C.renderBufferDirect(Y,F,H,G,E,gt),G.side=xn):C.renderBufferDirect(Y,F,H,G,E,gt),E.onAfterRender(C,F,Y,H,G,gt)}function Mc(E,F,Y){F.isScene!==!0&&(F=Ve);const H=W.get(E),G=w.state.lights,gt=w.state.shadowsArray,_t=G.state.version,mt=ht.getParameters(E,G.state,gt,F,Y,w.state.lightProbeGridArray),Tt=ht.getProgramCacheKey(mt);let Ot=H.programs;H.environment=E.isMeshStandardMaterial||E.isMeshLambertMaterial||E.isMeshPhongMaterial?F.environment:null,H.fog=F.fog;const Qt=E.isMeshStandardMaterial||E.isMeshLambertMaterial&&!E.envMap||E.isMeshPhongMaterial&&!E.envMap;H.envMap=ot.get(E.envMap||H.environment,Qt),H.envMapRotation=H.environment!==null&&E.envMap===null?F.environmentRotation:E.envMapRotation,Ot===void 0&&(E.addEventListener("dispose",Qn),Ot=new Map,H.programs=Ot);let ie=Ot.get(Tt);if(ie!==void 0){if(H.currentProgram===ie&&H.lightsStateVersion===_t)return _f(E,mt),ie}else mt.uniforms=ht.getUniforms(E),P!==null&&E.isNodeMaterial&&P.build(E,Y,mt),E.onBeforeCompile(mt,C),ie=ht.acquireProgram(mt,Tt),Ot.set(Tt,ie),H.uniforms=mt.uniforms;const Nt=H.uniforms;return(!E.isShaderMaterial&&!E.isRawShaderMaterial||E.clipping===!0)&&(Nt.clippingPlanes=kt.uniform),_f(E,mt),H.needsLights=Dv(E),H.lightsStateVersion=_t,H.needsLights&&(Nt.ambientLightColor.value=G.state.ambient,Nt.lightProbe.value=G.state.probe,Nt.directionalLights.value=G.state.directional,Nt.directionalLightShadows.value=G.state.directionalShadow,Nt.spotLights.value=G.state.spot,Nt.spotLightShadows.value=G.state.spotShadow,Nt.rectAreaLights.value=G.state.rectArea,Nt.ltc_1.value=G.state.rectAreaLTC1,Nt.ltc_2.value=G.state.rectAreaLTC2,Nt.pointLights.value=G.state.point,Nt.pointLightShadows.value=G.state.pointShadow,Nt.hemisphereLights.value=G.state.hemi,Nt.directionalShadowMatrix.value=G.state.directionalShadowMatrix,Nt.spotLightMatrix.value=G.state.spotLightMatrix,Nt.spotLightMap.value=G.state.spotLightMap,Nt.pointShadowMatrix.value=G.state.pointShadowMatrix),H.lightProbeGrid=w.state.lightProbeGridArray.length>0,H.currentProgram=ie,H.uniformsList=null,ie}function Sf(E){if(E.uniformsList===null){const F=E.currentProgram.getUniforms();E.uniformsList=Pl.seqWithValue(F.seq,E.uniforms)}return E.uniformsList}function _f(E,F){const Y=W.get(E);Y.outputColorSpace=F.outputColorSpace,Y.batching=F.batching,Y.batchingColor=F.batchingColor,Y.instancing=F.instancing,Y.instancingColor=F.instancingColor,Y.instancingMorph=F.instancingMorph,Y.skinning=F.skinning,Y.morphTargets=F.morphTargets,Y.morphNormals=F.morphNormals,Y.morphColors=F.morphColors,Y.morphTargetsCount=F.morphTargetsCount,Y.numClippingPlanes=F.numClippingPlanes,Y.numIntersection=F.numClipIntersection,Y.vertexAlphas=F.vertexAlphas,Y.vertexTangents=F.vertexTangents,Y.toneMapping=F.toneMapping}function Av(E,F){if(E.length===0)return null;if(E.length===1)return E[0].texture!==null?E[0]:null;M.setFromMatrixPosition(F.matrixWorld);for(let Y=0,H=E.length;Y<H;Y++){const G=E[Y];if(G.texture!==null&&G.boundingBox.containsPoint(M))return G}return null}function Tv(E,F,Y,H,G){F.isScene!==!0&&(F=Ve),K.resetTextureUnits();const gt=F.fog,_t=H.isMeshStandardMaterial||H.isMeshLambertMaterial||H.isMeshPhongMaterial?F.environment:null,mt=$===null?C.outputColorSpace:$.isXRRenderTarget===!0?$.texture.colorSpace:ce.workingColorSpace,Tt=H.isMeshStandardMaterial||H.isMeshLambertMaterial&&!H.envMap||H.isMeshPhongMaterial&&!H.envMap,Ot=ot.get(H.envMap||_t,Tt),Qt=H.vertexColors===!0&&!!Y.attributes.color&&Y.attributes.color.itemSize===4,ie=!!Y.attributes.tangent&&(!!H.normalMap||H.anisotropy>0),Nt=!!Y.morphAttributes.position,De=!!Y.morphAttributes.normal,ci=!!Y.morphAttributes.color;let si=Ms;H.toneMapped&&($===null||$.isXRRenderTarget===!0)&&(si=C.toneMapping);const Le=Y.morphAttributes.position||Y.morphAttributes.normal||Y.morphAttributes.color,Ci=Le!==void 0?Le.length:0,yt=W.get(H),cn=w.state.lights;if(Bt===!0&&(Ht===!0||E!==J)){const Fe=E===J&&H.id===tt;kt.setState(H,E,Fe)}let fe=!1;H.version===yt.__version?(yt.needsLights&&yt.lightsStateVersion!==cn.state.version||yt.outputColorSpace!==mt||G.isBatchedMesh&&yt.batching===!1||!G.isBatchedMesh&&yt.batching===!0||G.isBatchedMesh&&yt.batchingColor===!0&&G.colorTexture===null||G.isBatchedMesh&&yt.batchingColor===!1&&G.colorTexture!==null||G.isInstancedMesh&&yt.instancing===!1||!G.isInstancedMesh&&yt.instancing===!0||G.isSkinnedMesh&&yt.skinning===!1||!G.isSkinnedMesh&&yt.skinning===!0||G.isInstancedMesh&&yt.instancingColor===!0&&G.instanceColor===null||G.isInstancedMesh&&yt.instancingColor===!1&&G.instanceColor!==null||G.isInstancedMesh&&yt.instancingMorph===!0&&G.morphTexture===null||G.isInstancedMesh&&yt.instancingMorph===!1&&G.morphTexture!==null||yt.envMap!==Ot||H.fog===!0&&yt.fog!==gt||yt.numClippingPlanes!==void 0&&(yt.numClippingPlanes!==kt.numPlanes||yt.numIntersection!==kt.numIntersection)||yt.vertexAlphas!==Qt||yt.vertexTangents!==ie||yt.morphTargets!==Nt||yt.morphNormals!==De||yt.morphColors!==ci||yt.toneMapping!==si||yt.morphTargetsCount!==Ci||!!yt.lightProbeGrid!=w.state.lightProbeGridArray.length>0)&&(fe=!0):(fe=!0,yt.__version=H.version);let bn=yt.currentProgram;fe===!0&&(bn=Mc(H,F,G),P&&H.isNodeMaterial&&P.onUpdateProgram(H,bn,yt));let ts=!1,Hs=!1,Zr=!1;const Oe=bn.getUniforms(),li=yt.uniforms;if(_.useProgram(bn.program)&&(ts=!0,Hs=!0,Zr=!0),H.id!==tt&&(tt=H.id,Hs=!0),yt.needsLights){const Fe=Av(w.state.lightProbeGridArray,G);yt.lightProbeGrid!==Fe&&(yt.lightProbeGrid=Fe,Hs=!0)}if(ts||J!==E){_.buffers.depth.getReversed()&&E.reversedDepth!==!0&&(E._reversedDepth=!0,E.updateProjectionMatrix()),Oe.setValue(N,"projectionMatrix",E.projectionMatrix),Oe.setValue(N,"viewMatrix",E.matrixWorldInverse);const Vs=Oe.map.cameraPosition;Vs!==void 0&&Vs.setValue(N,Se.setFromMatrixPosition(E.matrixWorld)),D.logarithmicDepthBuffer&&Oe.setValue(N,"logDepthBufFC",2/(Math.log(E.far+1)/Math.LN2)),(H.isMeshPhongMaterial||H.isMeshToonMaterial||H.isMeshLambertMaterial||H.isMeshBasicMaterial||H.isMeshStandardMaterial||H.isShaderMaterial)&&Oe.setValue(N,"isOrthographic",E.isOrthographicCamera===!0),J!==E&&(J=E,Hs=!0,Zr=!0)}if(yt.needsLights&&(cn.state.directionalShadowMap.length>0&&Oe.setValue(N,"directionalShadowMap",cn.state.directionalShadowMap,K),cn.state.spotShadowMap.length>0&&Oe.setValue(N,"spotShadowMap",cn.state.spotShadowMap,K),cn.state.pointShadowMap.length>0&&Oe.setValue(N,"pointShadowMap",cn.state.pointShadowMap,K)),G.isSkinnedMesh){Oe.setOptional(N,G,"bindMatrix"),Oe.setOptional(N,G,"bindMatrixInverse");const Fe=G.skeleton;Fe&&(Fe.boneTexture===null&&Fe.computeBoneTexture(),Oe.setValue(N,"boneTexture",Fe.boneTexture,K))}G.isBatchedMesh&&(Oe.setOptional(N,G,"batchingTexture"),Oe.setValue(N,"batchingTexture",G._matricesTexture,K),Oe.setOptional(N,G,"batchingIdTexture"),Oe.setValue(N,"batchingIdTexture",G._indirectTexture,K),Oe.setOptional(N,G,"batchingColorTexture"),G._colorsTexture!==null&&Oe.setValue(N,"batchingColorTexture",G._colorsTexture,K));const Gs=Y.morphAttributes;if((Gs.position!==void 0||Gs.normal!==void 0||Gs.color!==void 0)&&O.update(G,Y,bn),(Hs||yt.receiveShadow!==G.receiveShadow)&&(yt.receiveShadow=G.receiveShadow,Oe.setValue(N,"receiveShadow",G.receiveShadow)),(H.isMeshStandardMaterial||H.isMeshLambertMaterial||H.isMeshPhongMaterial)&&H.envMap===null&&F.environment!==null&&(li.envMapIntensity.value=F.environmentIntensity),li.dfgLUT!==void 0&&(li.dfgLUT.value=Jb()),Hs){if(Oe.setValue(N,"toneMappingExposure",C.toneMappingExposure),yt.needsLights&&Rv(li,Zr),gt&&H.fog===!0&&Lt.refreshFogUniforms(li,gt),Lt.refreshMaterialUniforms(li,H,nt,rt,w.state.transmissionRenderTarget[E.id]),yt.needsLights&&yt.lightProbeGrid){const Fe=yt.lightProbeGrid;li.probesSH.value=Fe.texture,li.probesMin.value.copy(Fe.boundingBox.min),li.probesMax.value.copy(Fe.boundingBox.max),li.probesResolution.value.copy(Fe.resolution)}Pl.upload(N,Sf(yt),li,K)}if(H.isShaderMaterial&&H.uniformsNeedUpdate===!0&&(Pl.upload(N,Sf(yt),li,K),H.uniformsNeedUpdate=!1),H.isSpriteMaterial&&Oe.setValue(N,"center",G.center),Oe.setValue(N,"modelViewMatrix",G.modelViewMatrix),Oe.setValue(N,"normalMatrix",G.normalMatrix),Oe.setValue(N,"modelMatrix",G.matrixWorld),H.uniformsGroups!==void 0){const Fe=H.uniformsGroups;for(let Vs=0,Jr=Fe.length;Vs<Jr;Vs++){const bf=Fe[Vs];et.update(bf,bn),et.bind(bf,bn)}}return bn}function Rv(E,F){E.ambientLightColor.needsUpdate=F,E.lightProbe.needsUpdate=F,E.directionalLights.needsUpdate=F,E.directionalLightShadows.needsUpdate=F,E.pointLights.needsUpdate=F,E.pointLightShadows.needsUpdate=F,E.spotLights.needsUpdate=F,E.spotLightShadows.needsUpdate=F,E.rectAreaLights.needsUpdate=F,E.hemisphereLights.needsUpdate=F}function Dv(E){return E.isMeshLambertMaterial||E.isMeshToonMaterial||E.isMeshPhongMaterial||E.isMeshStandardMaterial||E.isShadowMaterial||E.isShaderMaterial&&E.lights===!0}this.getActiveCubeFace=function(){return B},this.getActiveMipmapLevel=function(){return k},this.getRenderTarget=function(){return $},this.setRenderTargetTextures=function(E,F,Y){const H=W.get(E);H.__autoAllocateDepthBuffer=E.resolveDepthBuffer===!1,H.__autoAllocateDepthBuffer===!1&&(H.__useRenderToTexture=!1),W.get(E.texture).__webglTexture=F,W.get(E.depthTexture).__webglTexture=H.__autoAllocateDepthBuffer?void 0:Y,H.__hasExternalTextures=!0},this.setRenderTargetFramebuffer=function(E,F){const Y=W.get(E);Y.__webglFramebuffer=F,Y.__useDefaultFramebuffer=F===void 0},this.setRenderTarget=function(E,F=0,Y=0){$=E,B=F,k=Y;let H=null,G=!1,gt=!1;if(E){const mt=W.get(E);if(mt.__useDefaultFramebuffer!==void 0){_.bindFramebuffer(N.FRAMEBUFFER,mt.__webglFramebuffer),it.copy(E.viewport),at.copy(E.scissor),Xt=E.scissorTest,_.viewport(it),_.scissor(at),_.setScissorTest(Xt),tt=-1;return}else if(mt.__webglFramebuffer===void 0)K.setupRenderTarget(E);else if(mt.__hasExternalTextures)K.rebindTextures(E,W.get(E.texture).__webglTexture,W.get(E.depthTexture).__webglTexture);else if(E.depthBuffer){const Qt=E.depthTexture;if(mt.__boundDepthTexture!==Qt){if(Qt!==null&&W.has(Qt)&&(E.width!==Qt.image.width||E.height!==Qt.image.height))throw new Error("THREE.WebGLRenderer: Attached DepthTexture is initialized to the incorrect size.");K.setupDepthRenderbuffer(E)}}const Tt=E.texture;(Tt.isData3DTexture||Tt.isDataArrayTexture||Tt.isCompressedArrayTexture)&&(gt=!0);const Ot=W.get(E).__webglFramebuffer;E.isWebGLCubeRenderTarget?(Array.isArray(Ot[F])?H=Ot[F][Y]:H=Ot[F],G=!0):E.samples>0&&K.useMultisampledRTT(E)===!1?H=W.get(E).__webglMultisampledFramebuffer:Array.isArray(Ot)?H=Ot[Y]:H=Ot,it.copy(E.viewport),at.copy(E.scissor),Xt=E.scissorTest}else it.copy(Ft).multiplyScalar(nt).floor(),at.copy(Pt).multiplyScalar(nt).floor(),Xt=St;if(Y!==0&&(H=V),_.bindFramebuffer(N.FRAMEBUFFER,H)&&_.drawBuffers(E,H),_.viewport(it),_.scissor(at),_.setScissorTest(Xt),G){const mt=W.get(E.texture);N.framebufferTexture2D(N.FRAMEBUFFER,N.COLOR_ATTACHMENT0,N.TEXTURE_CUBE_MAP_POSITIVE_X+F,mt.__webglTexture,Y)}else if(gt){const mt=F;for(let Tt=0;Tt<E.textures.length;Tt++){const Ot=W.get(E.textures[Tt]);N.framebufferTextureLayer(N.FRAMEBUFFER,N.COLOR_ATTACHMENT0+Tt,Ot.__webglTexture,Y,mt)}}else if(E!==null&&Y!==0){const mt=W.get(E.texture);N.framebufferTexture2D(N.FRAMEBUFFER,N.COLOR_ATTACHMENT0,N.TEXTURE_2D,mt.__webglTexture,Y)}tt=-1},this.readRenderTargetPixels=function(E,F,Y,H,G,gt,_t,mt=0){if(!(E&&E.isWebGLRenderTarget)){Wt("WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");return}let Tt=W.get(E).__webglFramebuffer;if(E.isWebGLCubeRenderTarget&&_t!==void 0&&(Tt=Tt[_t]),Tt){_.bindFramebuffer(N.FRAMEBUFFER,Tt);try{const Ot=E.textures[mt],Qt=Ot.format,ie=Ot.type;if(E.textures.length>1&&N.readBuffer(N.COLOR_ATTACHMENT0+mt),!D.textureFormatReadable(Qt)){Wt("WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.");return}if(!D.textureTypeReadable(ie)){Wt("WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.");return}F>=0&&F<=E.width-H&&Y>=0&&Y<=E.height-G&&N.readPixels(F,Y,H,G,dt.convert(Qt),dt.convert(ie),gt)}finally{const Ot=$!==null?W.get($).__webglFramebuffer:null;_.bindFramebuffer(N.FRAMEBUFFER,Ot)}}},this.readRenderTargetPixelsAsync=async function(E,F,Y,H,G,gt,_t,mt=0){if(!(E&&E.isWebGLRenderTarget))throw new Error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");let Tt=W.get(E).__webglFramebuffer;if(E.isWebGLCubeRenderTarget&&_t!==void 0&&(Tt=Tt[_t]),Tt)if(F>=0&&F<=E.width-H&&Y>=0&&Y<=E.height-G){_.bindFramebuffer(N.FRAMEBUFFER,Tt);const Ot=E.textures[mt],Qt=Ot.format,ie=Ot.type;if(E.textures.length>1&&N.readBuffer(N.COLOR_ATTACHMENT0+mt),!D.textureFormatReadable(Qt))throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.");if(!D.textureTypeReadable(ie))throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.");const Nt=N.createBuffer();N.bindBuffer(N.PIXEL_PACK_BUFFER,Nt),N.bufferData(N.PIXEL_PACK_BUFFER,gt.byteLength,N.STREAM_READ),N.readPixels(F,Y,H,G,dt.convert(Qt),dt.convert(ie),0);const De=$!==null?W.get($).__webglFramebuffer:null;_.bindFramebuffer(N.FRAMEBUFFER,De);const ci=N.fenceSync(N.SYNC_GPU_COMMANDS_COMPLETE,0);return N.flush(),await EM(N,ci,4),N.bindBuffer(N.PIXEL_PACK_BUFFER,Nt),N.getBufferSubData(N.PIXEL_PACK_BUFFER,0,gt),N.deleteBuffer(Nt),N.deleteSync(ci),gt}else throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: requested read bounds are out of range.")},this.copyFramebufferToTexture=function(E,F=null,Y=0){const H=Math.pow(2,-Y),G=Math.floor(E.image.width*H),gt=Math.floor(E.image.height*H),_t=F!==null?F.x:0,mt=F!==null?F.y:0;K.setTexture2D(E,0),N.copyTexSubImage2D(N.TEXTURE_2D,Y,0,0,_t,mt,G,gt),_.unbindTexture()},this.copyTextureToTexture=function(E,F,Y=null,H=null,G=0,gt=0){let _t,mt,Tt,Ot,Qt,ie,Nt,De,ci;const si=E.isCompressedTexture?E.mipmaps[gt]:E.image;if(Y!==null)_t=Y.max.x-Y.min.x,mt=Y.max.y-Y.min.y,Tt=Y.isBox3?Y.max.z-Y.min.z:1,Ot=Y.min.x,Qt=Y.min.y,ie=Y.isBox3?Y.min.z:0;else{const li=Math.pow(2,-G);_t=Math.floor(si.width*li),mt=Math.floor(si.height*li),E.isDataArrayTexture?Tt=si.depth:E.isData3DTexture?Tt=Math.floor(si.depth*li):Tt=1,Ot=0,Qt=0,ie=0}H!==null?(Nt=H.x,De=H.y,ci=H.z):(Nt=0,De=0,ci=0);const Le=dt.convert(F.format),Ci=dt.convert(F.type);let yt;F.isData3DTexture?(K.setTexture3D(F,0),yt=N.TEXTURE_3D):F.isDataArrayTexture||F.isCompressedArrayTexture?(K.setTexture2DArray(F,0),yt=N.TEXTURE_2D_ARRAY):(K.setTexture2D(F,0),yt=N.TEXTURE_2D),_.activeTexture(N.TEXTURE0),_.pixelStorei(N.UNPACK_FLIP_Y_WEBGL,F.flipY),_.pixelStorei(N.UNPACK_PREMULTIPLY_ALPHA_WEBGL,F.premultiplyAlpha),_.pixelStorei(N.UNPACK_ALIGNMENT,F.unpackAlignment);const cn=_.getParameter(N.UNPACK_ROW_LENGTH),fe=_.getParameter(N.UNPACK_IMAGE_HEIGHT),bn=_.getParameter(N.UNPACK_SKIP_PIXELS),ts=_.getParameter(N.UNPACK_SKIP_ROWS),Hs=_.getParameter(N.UNPACK_SKIP_IMAGES);_.pixelStorei(N.UNPACK_ROW_LENGTH,si.width),_.pixelStorei(N.UNPACK_IMAGE_HEIGHT,si.height),_.pixelStorei(N.UNPACK_SKIP_PIXELS,Ot),_.pixelStorei(N.UNPACK_SKIP_ROWS,Qt),_.pixelStorei(N.UNPACK_SKIP_IMAGES,ie);const Zr=E.isDataArrayTexture||E.isData3DTexture,Oe=F.isDataArrayTexture||F.isData3DTexture;if(E.isDepthTexture){const li=W.get(E),Gs=W.get(F),Fe=W.get(li.__renderTarget),Vs=W.get(Gs.__renderTarget);_.bindFramebuffer(N.READ_FRAMEBUFFER,Fe.__webglFramebuffer),_.bindFramebuffer(N.DRAW_FRAMEBUFFER,Vs.__webglFramebuffer);for(let Jr=0;Jr<Tt;Jr++)Zr&&(N.framebufferTextureLayer(N.READ_FRAMEBUFFER,N.COLOR_ATTACHMENT0,W.get(E).__webglTexture,G,ie+Jr),N.framebufferTextureLayer(N.DRAW_FRAMEBUFFER,N.COLOR_ATTACHMENT0,W.get(F).__webglTexture,gt,ci+Jr)),N.blitFramebuffer(Ot,Qt,_t,mt,Nt,De,_t,mt,N.DEPTH_BUFFER_BIT,N.NEAREST);_.bindFramebuffer(N.READ_FRAMEBUFFER,null),_.bindFramebuffer(N.DRAW_FRAMEBUFFER,null)}else if(G!==0||E.isRenderTargetTexture||W.has(E)){const li=W.get(E),Gs=W.get(F);_.bindFramebuffer(N.READ_FRAMEBUFFER,X),_.bindFramebuffer(N.DRAW_FRAMEBUFFER,L);for(let Fe=0;Fe<Tt;Fe++)Zr?N.framebufferTextureLayer(N.READ_FRAMEBUFFER,N.COLOR_ATTACHMENT0,li.__webglTexture,G,ie+Fe):N.framebufferTexture2D(N.READ_FRAMEBUFFER,N.COLOR_ATTACHMENT0,N.TEXTURE_2D,li.__webglTexture,G),Oe?N.framebufferTextureLayer(N.DRAW_FRAMEBUFFER,N.COLOR_ATTACHMENT0,Gs.__webglTexture,gt,ci+Fe):N.framebufferTexture2D(N.DRAW_FRAMEBUFFER,N.COLOR_ATTACHMENT0,N.TEXTURE_2D,Gs.__webglTexture,gt),G!==0?N.blitFramebuffer(Ot,Qt,_t,mt,Nt,De,_t,mt,N.COLOR_BUFFER_BIT,N.NEAREST):Oe?N.copyTexSubImage3D(yt,gt,Nt,De,ci+Fe,Ot,Qt,_t,mt):N.copyTexSubImage2D(yt,gt,Nt,De,Ot,Qt,_t,mt);_.bindFramebuffer(N.READ_FRAMEBUFFER,null),_.bindFramebuffer(N.DRAW_FRAMEBUFFER,null)}else Oe?E.isDataTexture||E.isData3DTexture?N.texSubImage3D(yt,gt,Nt,De,ci,_t,mt,Tt,Le,Ci,si.data):F.isCompressedArrayTexture?N.compressedTexSubImage3D(yt,gt,Nt,De,ci,_t,mt,Tt,Le,si.data):N.texSubImage3D(yt,gt,Nt,De,ci,_t,mt,Tt,Le,Ci,si):E.isDataTexture?N.texSubImage2D(N.TEXTURE_2D,gt,Nt,De,_t,mt,Le,Ci,si.data):E.isCompressedTexture?N.compressedTexSubImage2D(N.TEXTURE_2D,gt,Nt,De,si.width,si.height,Le,si.data):N.texSubImage2D(N.TEXTURE_2D,gt,Nt,De,_t,mt,Le,Ci,si);_.pixelStorei(N.UNPACK_ROW_LENGTH,cn),_.pixelStorei(N.UNPACK_IMAGE_HEIGHT,fe),_.pixelStorei(N.UNPACK_SKIP_PIXELS,bn),_.pixelStorei(N.UNPACK_SKIP_ROWS,ts),_.pixelStorei(N.UNPACK_SKIP_IMAGES,Hs),gt===0&&F.generateMipmaps&&N.generateMipmap(yt),_.unbindTexture()},this.initRenderTarget=function(E){W.get(E).__webglFramebuffer===void 0&&K.setupRenderTarget(E)},this.initTexture=function(E){E.isCubeTexture?K.setTextureCube(E,0):E.isData3DTexture?K.setTexture3D(E,0):E.isDataArrayTexture||E.isCompressedArrayTexture?K.setTexture2DArray(E,0):K.setTexture2D(E,0),_.unbindTexture()},this.resetState=function(){B=0,k=0,$=null,_.reset(),vt.reset()},typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}get coordinateSystem(){return ms}get outputColorSpace(){return this._outputColorSpace}set outputColorSpace(t){this._outputColorSpace=t;const e=this.getContext();e.drawingBufferColorSpace=ce._getDrawingBufferColorSpace(t),e.unpackColorSpace=ce._getUnpackColorSpace()}}const Qb=`
5527
+ }`;class Xb{constructor(){this.texture=null,this.mesh=null,this.depthNear=0,this.depthFar=0}init(t,e){if(this.texture===null){const i=new b1(t.texture);(t.depthNear!==e.depthNear||t.depthFar!==e.depthFar)&&(this.depthNear=t.depthNear,this.depthFar=t.depthFar),this.texture=i}}getMesh(t){if(this.texture!==null&&this.mesh===null){const e=t.cameras[0].viewport,i=new fe({vertexShader:Vb,fragmentShader:Wb,uniforms:{depthColor:{value:this.texture},depthWidth:{value:e.z},depthHeight:{value:e.w}}});this.mesh=new bt(new Zi(20,20),i)}return this.mesh}reset(){this.texture=null,this.mesh=null}getDepthTexture(){return this.texture}}class Yb extends vr{constructor(t,e){super();const i=this;let n=null,s=1,r=null,o="local-floor",c=1,l=null,h=null,u=null,d=null,f=null,p=null;const v=typeof XRWebGLBinding<"u",m=new Xb,g={},S=e.getContextAttributes();let x=null,M=null;const b=[],w=[],T=new Mt;let y=null;const A=new rn;A.viewport=new ae;const C=new rn;C.viewport=new ae;const I=[A,C],P=new Hx;let V=null,X=null;this.cameraAutoUpdate=!0,this.enabled=!1,this.isPresenting=!1,this.getController=function(q){let rt=b[q];return rt===void 0&&(rt=new kh,b[q]=rt),rt.getTargetRaySpace()},this.getControllerGrip=function(q){let rt=b[q];return rt===void 0&&(rt=new kh,b[q]=rt),rt.getGripSpace()},this.getHand=function(q){let rt=b[q];return rt===void 0&&(rt=new kh,b[q]=rt),rt.getHandSpace()};function L(q){const rt=w.indexOf(q.inputSource);if(rt===-1)return;const nt=b[rt];nt!==void 0&&(nt.update(q.inputSource,q.frame,l||r),nt.dispatchEvent({type:q.type,data:q.inputSource}))}function B(){n.removeEventListener("select",L),n.removeEventListener("selectstart",L),n.removeEventListener("selectend",L),n.removeEventListener("squeeze",L),n.removeEventListener("squeezestart",L),n.removeEventListener("squeezeend",L),n.removeEventListener("end",B),n.removeEventListener("inputsourceschange",k);for(let q=0;q<b.length;q++){const rt=w[q];rt!==null&&(w[q]=null,b[q].disconnect(rt))}V=null,X=null,m.reset();for(const q in g)delete g[q];t.setRenderTarget(x),f=null,d=null,u=null,n=null,M=null,Kt.stop(),i.isPresenting=!1,t.setPixelRatio(y),t.setSize(T.width,T.height,!1),i.dispatchEvent({type:"sessionend"})}this.setFramebufferScaleFactor=function(q){s=q,i.isPresenting===!0&&It("WebXRManager: Cannot change framebuffer scale while presenting.")},this.setReferenceSpaceType=function(q){o=q,i.isPresenting===!0&&It("WebXRManager: Cannot change reference space type while presenting.")},this.getReferenceSpace=function(){return l||r},this.setReferenceSpace=function(q){l=q},this.getBaseLayer=function(){return d!==null?d:f},this.getBinding=function(){return u===null&&v&&(u=new XRWebGLBinding(n,e)),u},this.getFrame=function(){return p},this.getSession=function(){return n},this.setSession=async function(q){if(n=q,n!==null){if(x=t.getRenderTarget(),n.addEventListener("select",L),n.addEventListener("selectstart",L),n.addEventListener("selectend",L),n.addEventListener("squeeze",L),n.addEventListener("squeezestart",L),n.addEventListener("squeezeend",L),n.addEventListener("end",B),n.addEventListener("inputsourceschange",k),S.xrCompatible!==!0&&await e.makeXRCompatible(),y=t.getPixelRatio(),t.getSize(T),v&&"createProjectionLayer"in XRWebGLBinding.prototype){let nt=null,z=null,Rt=null;S.depth&&(Rt=S.stencil?e.DEPTH24_STENCIL8:e.DEPTH_COMPONENT24,nt=S.stencil?Or:Fs,z=S.stencil?ac:Nn);const Ft={colorFormat:e.RGBA8,depthFormat:Rt,scaleFactor:s};u=this.getBinding(),d=u.createProjectionLayer(Ft),n.updateRenderState({layers:[d]}),t.setPixelRatio(1),t.setSize(d.textureWidth,d.textureHeight,!1),M=new Qe(d.textureWidth,d.textureHeight,{format:Di,type:yn,depthTexture:new mr(d.textureWidth,d.textureHeight,z,void 0,void 0,void 0,void 0,void 0,void 0,nt),stencilBuffer:S.stencil,colorSpace:t.outputColorSpace,samples:S.antialias?4:0,resolveDepthBuffer:d.ignoreDepthValues===!1,resolveStencilBuffer:d.ignoreDepthValues===!1})}else{const nt={antialias:S.antialias,alpha:!0,depth:S.depth,stencil:S.stencil,framebufferScaleFactor:s};f=new XRWebGLLayer(n,e,nt),n.updateRenderState({baseLayer:f}),t.setPixelRatio(1),t.setSize(f.framebufferWidth,f.framebufferHeight,!1),M=new Qe(f.framebufferWidth,f.framebufferHeight,{format:Di,type:yn,colorSpace:t.outputColorSpace,stencilBuffer:S.stencil,resolveDepthBuffer:f.ignoreDepthValues===!1,resolveStencilBuffer:f.ignoreDepthValues===!1})}M.isXRRenderTarget=!0,this.setFoveation(c),l=null,r=await n.requestReferenceSpace(o),Kt.setContext(n),Kt.start(),i.isPresenting=!0,i.dispatchEvent({type:"sessionstart"})}},this.getEnvironmentBlendMode=function(){if(n!==null)return n.environmentBlendMode},this.getDepthTexture=function(){return m.getDepthTexture()};function k(q){for(let rt=0;rt<q.removed.length;rt++){const nt=q.removed[rt],z=w.indexOf(nt);z>=0&&(w[z]=null,b[z].disconnect(nt))}for(let rt=0;rt<q.added.length;rt++){const nt=q.added[rt];let z=w.indexOf(nt);if(z===-1){for(let Ft=0;Ft<b.length;Ft++)if(Ft>=w.length){w.push(nt),z=Ft;break}else if(w[Ft]===null){w[Ft]=nt,z=Ft;break}if(z===-1)break}const Rt=b[z];Rt&&Rt.connect(nt)}}const $=new R,tt=new R;function J(q,rt,nt){$.setFromMatrixPosition(rt.matrixWorld),tt.setFromMatrixPosition(nt.matrixWorld);const z=$.distanceTo(tt),Rt=rt.projectionMatrix.elements,Ft=nt.projectionMatrix.elements,Pt=Rt[14]/(Rt[10]-1),St=Rt[14]/(Rt[10]+1),zt=(Rt[9]+1)/Rt[5],Bt=(Rt[9]-1)/Rt[5],Ht=(Rt[8]-1)/Rt[0],ye=(Ft[8]+1)/Ft[0],Se=Pt*Ht,ei=Pt*ye,Ve=z/(-Ht+ye),ii=Ve*-Ht;if(rt.matrixWorld.decompose(q.position,q.quaternion,q.scale),q.translateX(ii),q.translateZ(Ve),q.matrixWorld.compose(q.position,q.quaternion,q.scale),q.matrixWorldInverse.copy(q.matrixWorld).invert(),Rt[10]===-1)q.projectionMatrix.copy(rt.projectionMatrix),q.projectionMatrixInverse.copy(rt.projectionMatrixInverse);else{const fi=Pt+Ve,N=St+Ve,Ji=Se-ii,_e=ei+(z-ii),D=zt*St/N*fi,_=Bt*St/N*fi;q.projectionMatrix.makePerspective(Ji,_e,D,_,fi,N),q.projectionMatrixInverse.copy(q.projectionMatrix).invert()}}function it(q,rt){rt===null?q.matrixWorld.copy(q.matrix):q.matrixWorld.multiplyMatrices(rt.matrixWorld,q.matrix),q.matrixWorldInverse.copy(q.matrixWorld).invert()}this.updateCamera=function(q){if(n===null)return;let rt=q.near,nt=q.far;m.texture!==null&&(m.depthNear>0&&(rt=m.depthNear),m.depthFar>0&&(nt=m.depthFar)),P.near=C.near=A.near=rt,P.far=C.far=A.far=nt,(V!==P.near||X!==P.far)&&(n.updateRenderState({depthNear:P.near,depthFar:P.far}),V=P.near,X=P.far),P.layers.mask=q.layers.mask|6,A.layers.mask=P.layers.mask&-5,C.layers.mask=P.layers.mask&-3;const z=q.parent,Rt=P.cameras;it(P,z);for(let Ft=0;Ft<Rt.length;Ft++)it(Rt[Ft],z);Rt.length===2?J(P,A,C):P.projectionMatrix.copy(A.projectionMatrix),at(q,P,z)};function at(q,rt,nt){nt===null?q.matrix.copy(rt.matrixWorld):(q.matrix.copy(nt.matrixWorld),q.matrix.invert(),q.matrix.multiply(rt.matrixWorld)),q.matrix.decompose(q.position,q.quaternion,q.scale),q.updateMatrixWorld(!0),q.projectionMatrix.copy(rt.projectionMatrix),q.projectionMatrixInverse.copy(rt.projectionMatrixInverse),q.isPerspectiveCamera&&(q.fov=Qa*2*Math.atan(1/q.projectionMatrix.elements[5]),q.zoom=1)}this.getCamera=function(){return P},this.getFoveation=function(){if(!(d===null&&f===null))return c},this.setFoveation=function(q){c=q,d!==null&&(d.fixedFoveation=q),f!==null&&f.fixedFoveation!==void 0&&(f.fixedFoveation=q)},this.hasDepthSensing=function(){return m.texture!==null},this.getDepthSensingMesh=function(){return m.getMesh(P)},this.getCameraTexture=function(q){return g[q]};let Xt=null;function ee(q,rt){if(h=rt.getViewerPose(l||r),p=rt,h!==null){const nt=h.views;f!==null&&(t.setRenderTargetFramebuffer(M,f.framebuffer),t.setRenderTarget(M));let z=!1;nt.length!==P.cameras.length&&(P.cameras.length=0,z=!0);for(let St=0;St<nt.length;St++){const zt=nt[St];let Bt=null;if(f!==null)Bt=f.getViewport(zt);else{const ye=u.getViewSubImage(d,zt);Bt=ye.viewport,St===0&&(t.setRenderTargetTextures(M,ye.colorTexture,ye.depthStencilTexture),t.setRenderTarget(M))}let Ht=I[St];Ht===void 0&&(Ht=new rn,Ht.layers.enable(St),Ht.viewport=new ae,I[St]=Ht),Ht.matrix.fromArray(zt.transform.matrix),Ht.matrix.decompose(Ht.position,Ht.quaternion,Ht.scale),Ht.projectionMatrix.fromArray(zt.projectionMatrix),Ht.projectionMatrixInverse.copy(Ht.projectionMatrix).invert(),Ht.viewport.set(Bt.x,Bt.y,Bt.width,Bt.height),St===0&&(P.matrix.copy(Ht.matrix),P.matrix.decompose(P.position,P.quaternion,P.scale)),z===!0&&P.cameras.push(Ht)}const Rt=n.enabledFeatures;if(Rt&&Rt.includes("depth-sensing")&&n.depthUsage=="gpu-optimized"&&v){u=i.getBinding();const St=u.getDepthInformation(nt[0]);St&&St.isValid&&St.texture&&m.init(St,n.renderState)}if(Rt&&Rt.includes("camera-access")&&v){t.state.unbindTexture(),u=i.getBinding();for(let St=0;St<nt.length;St++){const zt=nt[St].camera;if(zt){let Bt=g[zt];Bt||(Bt=new b1,g[zt]=Bt);const Ht=u.getCameraImage(zt);Bt.sourceTexture=Ht}}}}for(let nt=0;nt<b.length;nt++){const z=w[nt],Rt=b[nt];z!==null&&Rt!==void 0&&Rt.update(z,rt,l||r)}Xt&&Xt(q,rt),rt.detectedPlanes&&i.dispatchEvent({type:"planesdetected",data:rt}),p=null}const Kt=new P1;Kt.setAnimationLoop(ee),this.setAnimationLoop=function(q){Xt=q},this.dispose=function(){}}}const qb=new te,k1=new $t;k1.set(-1,0,0,0,1,0,0,0,1);function $b(a,t){function e(m,g){m.matrixAutoUpdate===!0&&m.updateMatrix(),g.value.copy(m.matrix)}function i(m,g){g.color.getRGB(m.fogColor.value,w1(a)),g.isFog?(m.fogNear.value=g.near,m.fogFar.value=g.far):g.isFogExp2&&(m.fogDensity.value=g.density)}function n(m,g,S,x,M){g.isNodeMaterial?g.uniformsNeedUpdate=!1:g.isMeshBasicMaterial?s(m,g):g.isMeshLambertMaterial?(s(m,g),g.envMap&&(m.envMapIntensity.value=g.envMapIntensity)):g.isMeshToonMaterial?(s(m,g),u(m,g)):g.isMeshPhongMaterial?(s(m,g),h(m,g),g.envMap&&(m.envMapIntensity.value=g.envMapIntensity)):g.isMeshStandardMaterial?(s(m,g),d(m,g),g.isMeshPhysicalMaterial&&f(m,g,M)):g.isMeshMatcapMaterial?(s(m,g),p(m,g)):g.isMeshDepthMaterial?s(m,g):g.isMeshDistanceMaterial?(s(m,g),v(m,g)):g.isMeshNormalMaterial?s(m,g):g.isLineBasicMaterial?(r(m,g),g.isLineDashedMaterial&&o(m,g)):g.isPointsMaterial?c(m,g,S,x):g.isSpriteMaterial?l(m,g):g.isShadowMaterial?(m.color.value.copy(g.color),m.opacity.value=g.opacity):g.isShaderMaterial&&(g.uniformsNeedUpdate=!1)}function s(m,g){m.opacity.value=g.opacity,g.color&&m.diffuse.value.copy(g.color),g.emissive&&m.emissive.value.copy(g.emissive).multiplyScalar(g.emissiveIntensity),g.map&&(m.map.value=g.map,e(g.map,m.mapTransform)),g.alphaMap&&(m.alphaMap.value=g.alphaMap,e(g.alphaMap,m.alphaMapTransform)),g.bumpMap&&(m.bumpMap.value=g.bumpMap,e(g.bumpMap,m.bumpMapTransform),m.bumpScale.value=g.bumpScale,g.side===qe&&(m.bumpScale.value*=-1)),g.normalMap&&(m.normalMap.value=g.normalMap,e(g.normalMap,m.normalMapTransform),m.normalScale.value.copy(g.normalScale),g.side===qe&&m.normalScale.value.negate()),g.displacementMap&&(m.displacementMap.value=g.displacementMap,e(g.displacementMap,m.displacementMapTransform),m.displacementScale.value=g.displacementScale,m.displacementBias.value=g.displacementBias),g.emissiveMap&&(m.emissiveMap.value=g.emissiveMap,e(g.emissiveMap,m.emissiveMapTransform)),g.specularMap&&(m.specularMap.value=g.specularMap,e(g.specularMap,m.specularMapTransform)),g.alphaTest>0&&(m.alphaTest.value=g.alphaTest);const S=t.get(g),x=S.envMap,M=S.envMapRotation;x&&(m.envMap.value=x,m.envMapRotation.value.setFromMatrix4(qb.makeRotationFromEuler(M)).transpose(),x.isCubeTexture&&x.isRenderTargetTexture===!1&&m.envMapRotation.value.premultiply(k1),m.reflectivity.value=g.reflectivity,m.ior.value=g.ior,m.refractionRatio.value=g.refractionRatio),g.lightMap&&(m.lightMap.value=g.lightMap,m.lightMapIntensity.value=g.lightMapIntensity,e(g.lightMap,m.lightMapTransform)),g.aoMap&&(m.aoMap.value=g.aoMap,m.aoMapIntensity.value=g.aoMapIntensity,e(g.aoMap,m.aoMapTransform))}function r(m,g){m.diffuse.value.copy(g.color),m.opacity.value=g.opacity,g.map&&(m.map.value=g.map,e(g.map,m.mapTransform))}function o(m,g){m.dashSize.value=g.dashSize,m.totalSize.value=g.dashSize+g.gapSize,m.scale.value=g.scale}function c(m,g,S,x){m.diffuse.value.copy(g.color),m.opacity.value=g.opacity,m.size.value=g.size*S,m.scale.value=x*.5,g.map&&(m.map.value=g.map,e(g.map,m.uvTransform)),g.alphaMap&&(m.alphaMap.value=g.alphaMap,e(g.alphaMap,m.alphaMapTransform)),g.alphaTest>0&&(m.alphaTest.value=g.alphaTest)}function l(m,g){m.diffuse.value.copy(g.color),m.opacity.value=g.opacity,m.rotation.value=g.rotation,g.map&&(m.map.value=g.map,e(g.map,m.mapTransform)),g.alphaMap&&(m.alphaMap.value=g.alphaMap,e(g.alphaMap,m.alphaMapTransform)),g.alphaTest>0&&(m.alphaTest.value=g.alphaTest)}function h(m,g){m.specular.value.copy(g.specular),m.shininess.value=Math.max(g.shininess,1e-4)}function u(m,g){g.gradientMap&&(m.gradientMap.value=g.gradientMap)}function d(m,g){m.metalness.value=g.metalness,g.metalnessMap&&(m.metalnessMap.value=g.metalnessMap,e(g.metalnessMap,m.metalnessMapTransform)),m.roughness.value=g.roughness,g.roughnessMap&&(m.roughnessMap.value=g.roughnessMap,e(g.roughnessMap,m.roughnessMapTransform)),g.envMap&&(m.envMapIntensity.value=g.envMapIntensity)}function f(m,g,S){m.ior.value=g.ior,g.sheen>0&&(m.sheenColor.value.copy(g.sheenColor).multiplyScalar(g.sheen),m.sheenRoughness.value=g.sheenRoughness,g.sheenColorMap&&(m.sheenColorMap.value=g.sheenColorMap,e(g.sheenColorMap,m.sheenColorMapTransform)),g.sheenRoughnessMap&&(m.sheenRoughnessMap.value=g.sheenRoughnessMap,e(g.sheenRoughnessMap,m.sheenRoughnessMapTransform))),g.clearcoat>0&&(m.clearcoat.value=g.clearcoat,m.clearcoatRoughness.value=g.clearcoatRoughness,g.clearcoatMap&&(m.clearcoatMap.value=g.clearcoatMap,e(g.clearcoatMap,m.clearcoatMapTransform)),g.clearcoatRoughnessMap&&(m.clearcoatRoughnessMap.value=g.clearcoatRoughnessMap,e(g.clearcoatRoughnessMap,m.clearcoatRoughnessMapTransform)),g.clearcoatNormalMap&&(m.clearcoatNormalMap.value=g.clearcoatNormalMap,e(g.clearcoatNormalMap,m.clearcoatNormalMapTransform),m.clearcoatNormalScale.value.copy(g.clearcoatNormalScale),g.side===qe&&m.clearcoatNormalScale.value.negate())),g.dispersion>0&&(m.dispersion.value=g.dispersion),g.iridescence>0&&(m.iridescence.value=g.iridescence,m.iridescenceIOR.value=g.iridescenceIOR,m.iridescenceThicknessMinimum.value=g.iridescenceThicknessRange[0],m.iridescenceThicknessMaximum.value=g.iridescenceThicknessRange[1],g.iridescenceMap&&(m.iridescenceMap.value=g.iridescenceMap,e(g.iridescenceMap,m.iridescenceMapTransform)),g.iridescenceThicknessMap&&(m.iridescenceThicknessMap.value=g.iridescenceThicknessMap,e(g.iridescenceThicknessMap,m.iridescenceThicknessMapTransform))),g.transmission>0&&(m.transmission.value=g.transmission,m.transmissionSamplerMap.value=S.texture,m.transmissionSamplerSize.value.set(S.width,S.height),g.transmissionMap&&(m.transmissionMap.value=g.transmissionMap,e(g.transmissionMap,m.transmissionMapTransform)),m.thickness.value=g.thickness,g.thicknessMap&&(m.thicknessMap.value=g.thicknessMap,e(g.thicknessMap,m.thicknessMapTransform)),m.attenuationDistance.value=g.attenuationDistance,m.attenuationColor.value.copy(g.attenuationColor)),g.anisotropy>0&&(m.anisotropyVector.value.set(g.anisotropy*Math.cos(g.anisotropyRotation),g.anisotropy*Math.sin(g.anisotropyRotation)),g.anisotropyMap&&(m.anisotropyMap.value=g.anisotropyMap,e(g.anisotropyMap,m.anisotropyMapTransform))),m.specularIntensity.value=g.specularIntensity,m.specularColor.value.copy(g.specularColor),g.specularColorMap&&(m.specularColorMap.value=g.specularColorMap,e(g.specularColorMap,m.specularColorMapTransform)),g.specularIntensityMap&&(m.specularIntensityMap.value=g.specularIntensityMap,e(g.specularIntensityMap,m.specularIntensityMapTransform))}function p(m,g){g.matcap&&(m.matcap.value=g.matcap)}function v(m,g){const S=t.get(g).light;m.referencePosition.value.setFromMatrixPosition(S.matrixWorld),m.nearDistance.value=S.shadow.camera.near,m.farDistance.value=S.shadow.camera.far}return{refreshFogUniforms:i,refreshMaterialUniforms:n}}function Kb(a,t,e,i){let n={},s={},r=[];const o=a.getParameter(a.MAX_UNIFORM_BUFFER_BINDINGS);function c(M,b){const w=b.program;i.uniformBlockBinding(M,w)}function l(M,b){let w=n[M.id];w===void 0&&(m(M),w=h(M),n[M.id]=w,M.addEventListener("dispose",S));const T=b.program;i.updateUBOMapping(M,T);const y=t.render.frame;s[M.id]!==y&&(d(M),s[M.id]=y)}function h(M){const b=u();M.__bindingPointIndex=b;const w=a.createBuffer(),T=M.__size,y=M.usage;return a.bindBuffer(a.UNIFORM_BUFFER,w),a.bufferData(a.UNIFORM_BUFFER,T,y),a.bindBuffer(a.UNIFORM_BUFFER,null),a.bindBufferBase(a.UNIFORM_BUFFER,b,w),w}function u(){for(let M=0;M<o;M++)if(r.indexOf(M)===-1)return r.push(M),M;return Wt("WebGLRenderer: Maximum number of simultaneously usable uniforms groups reached."),0}function d(M){const b=n[M.id],w=M.uniforms,T=M.__cache;a.bindBuffer(a.UNIFORM_BUFFER,b);for(let y=0,A=w.length;y<A;y++){const C=w[y];if(Array.isArray(C))for(let I=0,P=C.length;I<P;I++)f(C[I],y,I,T);else f(C,y,0,T)}a.bindBuffer(a.UNIFORM_BUFFER,null)}function f(M,b,w,T){if(v(M,b,w,T)===!0){const y=M.__offset,A=M.value;if(Array.isArray(A)){let C=0;for(let I=0;I<A.length;I++){const P=A[I],V=g(P);p(P,M.__data,C),typeof P!="number"&&typeof P!="boolean"&&!P.isMatrix3&&!ArrayBuffer.isView(P)&&(C+=V.storage/Float32Array.BYTES_PER_ELEMENT)}}else p(A,M.__data,0);a.bufferSubData(a.UNIFORM_BUFFER,y,M.__data)}}function p(M,b,w){typeof M=="number"||typeof M=="boolean"?b[0]=M:M.isMatrix3?(b[0]=M.elements[0],b[1]=M.elements[1],b[2]=M.elements[2],b[3]=0,b[4]=M.elements[3],b[5]=M.elements[4],b[6]=M.elements[5],b[7]=0,b[8]=M.elements[6],b[9]=M.elements[7],b[10]=M.elements[8],b[11]=0):ArrayBuffer.isView(M)?b.set(new M.constructor(M.buffer,M.byteOffset,b.length)):M.toArray(b,w)}function v(M,b,w,T){const y=M.value,A=b+"_"+w;if(T[A]===void 0)return typeof y=="number"||typeof y=="boolean"?T[A]=y:ArrayBuffer.isView(y)?T[A]=y.slice():T[A]=y.clone(),!0;{const C=T[A];if(typeof y=="number"||typeof y=="boolean"){if(C!==y)return T[A]=y,!0}else{if(ArrayBuffer.isView(y))return!0;if(C.equals(y)===!1)return C.copy(y),!0}}return!1}function m(M){const b=M.uniforms;let w=0;const T=16;for(let A=0,C=b.length;A<C;A++){const I=Array.isArray(b[A])?b[A]:[b[A]];for(let P=0,V=I.length;P<V;P++){const X=I[P],L=Array.isArray(X.value)?X.value:[X.value];for(let B=0,k=L.length;B<k;B++){const $=L[B],tt=g($),J=w%T,it=J%tt.boundary,at=J+it;w+=it,at!==0&&T-at<tt.storage&&(w+=T-at),X.__data=new Float32Array(tt.storage/Float32Array.BYTES_PER_ELEMENT),X.__offset=w,w+=tt.storage}}}const y=w%T;return y>0&&(w+=T-y),M.__size=w,M.__cache={},this}function g(M){const b={boundary:0,storage:0};return typeof M=="number"||typeof M=="boolean"?(b.boundary=4,b.storage=4):M.isVector2?(b.boundary=8,b.storage=8):M.isVector3||M.isColor?(b.boundary=16,b.storage=12):M.isVector4?(b.boundary=16,b.storage=16):M.isMatrix3?(b.boundary=48,b.storage=48):M.isMatrix4?(b.boundary=64,b.storage=64):M.isTexture?It("WebGLRenderer: Texture samplers can not be part of an uniforms group."):ArrayBuffer.isView(M)?(b.boundary=16,b.storage=M.byteLength):It("WebGLRenderer: Unsupported uniform value type.",M),b}function S(M){const b=M.target;b.removeEventListener("dispose",S);const w=r.indexOf(b.__bindingPointIndex);r.splice(w,1),a.deleteBuffer(n[b.id]),delete n[b.id],delete s[b.id]}function x(){for(const M in n)a.deleteBuffer(n[M]);r=[],n={},s={}}return{bind:c,update:l,dispose:x}}const Zb=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 ns=null;function Jb(){return ns===null&&(ns=new Mr(Zb,16,16,Yr,$e),ns.name="DFG_LUT",ns.minFilter=le,ns.magFilter=le,ns.wrapS=Ri,ns.wrapT=Ri,ns.generateMipmaps=!1,ns.needsUpdate=!0),ns}class jb{constructor(t={}){const{canvas:e=wM(),context:i=null,depth:n=!0,stencil:s=!1,alpha:r=!1,antialias:o=!1,premultipliedAlpha:c=!0,preserveDrawingBuffer:l=!1,powerPreference:h="default",failIfMajorPerformanceCaveat:u=!1,reversedDepthBuffer:d=!1,outputBufferType:f=yn}=t;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 v=f,m=new Set([L0,P0,C0]),g=new Set([yn,Nn,rc,ac,D0,I0]),S=new Uint32Array(4),x=new Int32Array(4),M=new R;let b=null,w=null;const T=[],y=[];let A=null;this.domElement=e,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=Ms,this.toneMappingExposure=1,this.transmissionResolutionScale=1;const C=this;let I=!1,P=null,V=null,X=null,L=null;this._outputColorSpace=qi;let B=0,k=0,$=null,tt=-1,J=null;const it=new ae,at=new ae;let Xt=null;const ee=new st(0);let Kt=0,q=e.width,rt=e.height,nt=1,z=null,Rt=null;const Ft=new ae(0,0,q,rt),Pt=new ae(0,0,q,rt);let St=!1;const zt=new G0;let Bt=!1,Ht=!1;const ye=new te,Se=new R,ei=new ae,Ve={background:null,fog:null,environment:null,overrideMaterial:null,isScene:!0};let ii=!1;function fi(){return $===null?nt:1}let N=i;function Ji(E,F){return e.getContext(E,F)}try{const E={alpha:!0,depth:n,stencil:s,antialias:o,premultipliedAlpha:c,preserveDrawingBuffer:l,powerPreference:h,failIfMajorPerformanceCaveat:u};if("setAttribute"in e&&e.setAttribute("data-engine",`three.js r${A0}`),e.addEventListener("webglcontextlost",ni,!1),e.addEventListener("webglcontextrestored",Ne,!1),e.addEventListener("webglcontextcreationerror",jn,!1),N===null){const F="webgl2";if(N=Ji(F,E),N===null)throw Ji(F)?new Error("THREE.WebGLRenderer: Error creating WebGL context with your selected attributes."):new Error("THREE.WebGLRenderer: Error creating WebGL context.")}}catch(E){throw Wt("WebGLRenderer: "+E.message),E}let _e,D,_,U,W,K,ot,lt,Z,Q,ht,Lt,ft,ut,kt,Vt,jt,O,ct,j,dt,vt,et;function Ct(){_e=new JS(N),_e.init(),dt=new Gb(N,_e),D=new VS(N,_e,t,dt),_=new Bb(N,_e),D.reversedDepthBuffer&&d&&_.buffers.depth.setReversed(!0),V=N.createFramebuffer(),X=N.createFramebuffer(),L=N.createFramebuffer(),U=new t_(N),W=new Ab,K=new Hb(N,_e,_,W,D,dt,U),ot=new ZS(C),lt=new sy(N),vt=new HS(N,lt),Z=new jS(N,lt,U,vt),Q=new i_(N,Z,lt,vt,U),O=new e_(N,D,K),kt=new WS(W),ht=new Eb(C,ot,_e,D,vt,kt),Lt=new $b(C,W),ft=new Rb,ut=new Ob(_e),jt=new BS(C,ot,_,Q,p,c),Vt=new zb(C,Q,D),et=new Kb(N,U,D,_),ct=new GS(N,_e,U),j=new QS(N,_e,U),U.programs=ht.programs,C.capabilities=D,C.extensions=_e,C.properties=W,C.renderLists=ft,C.shadowMap=Vt,C.state=_,C.info=U}Ct(),v!==yn&&(A=new s_(v,e.width,e.height,o,n,s));const wt=new Yb(C,N);this.xr=wt,this.getContext=function(){return N},this.getContextAttributes=function(){return N.getContextAttributes()},this.forceContextLoss=function(){const E=_e.get("WEBGL_lose_context");E&&E.loseContext()},this.forceContextRestore=function(){const E=_e.get("WEBGL_lose_context");E&&E.restoreContext()},this.getPixelRatio=function(){return nt},this.setPixelRatio=function(E){E!==void 0&&(nt=E,this.setSize(q,rt,!1))},this.getSize=function(E){return E.set(q,rt)},this.setSize=function(E,F,Y=!0){if(wt.isPresenting){It("WebGLRenderer: Can't change size while VR device is presenting.");return}q=E,rt=F,e.width=Math.floor(E*nt),e.height=Math.floor(F*nt),Y===!0&&(e.style.width=E+"px",e.style.height=F+"px"),A!==null&&A.setSize(e.width,e.height),this.setViewport(0,0,E,F)},this.getDrawingBufferSize=function(E){return E.set(q*nt,rt*nt).floor()},this.setDrawingBufferSize=function(E,F,Y){q=E,rt=F,nt=Y,e.width=Math.floor(E*Y),e.height=Math.floor(F*Y),this.setViewport(0,0,E,F)},this.setEffects=function(E){if(v===yn){Wt("WebGLRenderer: setEffects() requires outputBufferType set to HalfFloatType or FloatType.");return}if(E){for(let F=0;F<E.length;F++)if(E[F].isOutputPass===!0){It("WebGLRenderer: OutputPass is not needed in setEffects(). Tone mapping and color space conversion are applied automatically.");break}}A.setEffects(E||[])},this.getCurrentViewport=function(E){return E.copy(it)},this.getViewport=function(E){return E.copy(Ft)},this.setViewport=function(E,F,Y,H){E.isVector4?Ft.set(E.x,E.y,E.z,E.w):Ft.set(E,F,Y,H),_.viewport(it.copy(Ft).multiplyScalar(nt).round())},this.getScissor=function(E){return E.copy(Pt)},this.setScissor=function(E,F,Y,H){E.isVector4?Pt.set(E.x,E.y,E.z,E.w):Pt.set(E,F,Y,H),_.scissor(at.copy(Pt).multiplyScalar(nt).round())},this.getScissorTest=function(){return St},this.setScissorTest=function(E){_.setScissorTest(St=E)},this.setOpaqueSort=function(E){z=E},this.setTransparentSort=function(E){Rt=E},this.getClearColor=function(E){return E.copy(jt.getClearColor())},this.setClearColor=function(){jt.setClearColor(...arguments)},this.getClearAlpha=function(){return jt.getClearAlpha()},this.setClearAlpha=function(){jt.setClearAlpha(...arguments)},this.clear=function(E=!0,F=!0,Y=!0){let H=0;if(E){let G=!1;if($!==null){const gt=$.texture.format;G=m.has(gt)}if(G){const gt=$.texture.type,_t=g.has(gt),mt=jt.getClearColor(),Tt=jt.getClearAlpha(),Ot=mt.r,Qt=mt.g,ie=mt.b;_t?(S[0]=Ot,S[1]=Qt,S[2]=ie,S[3]=Tt,N.clearBufferuiv(N.COLOR,0,S)):(x[0]=Ot,x[1]=Qt,x[2]=ie,x[3]=Tt,N.clearBufferiv(N.COLOR,0,x))}else H|=N.COLOR_BUFFER_BIT}F&&(H|=N.DEPTH_BUFFER_BIT,this.state.buffers.depth.setMask(!0)),Y&&(H|=N.STENCIL_BUFFER_BIT,this.state.buffers.stencil.setMask(4294967295)),H!==0&&N.clear(H)},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(E){E.setRenderer(this),P=E},this.dispose=function(){e.removeEventListener("webglcontextlost",ni,!1),e.removeEventListener("webglcontextrestored",Ne,!1),e.removeEventListener("webglcontextcreationerror",jn,!1),jt.dispose(),ft.dispose(),ut.dispose(),W.dispose(),ot.dispose(),Q.dispose(),vt.dispose(),et.dispose(),ht.dispose(),wt.dispose(),wt.removeEventListener("sessionstart",gf),wt.removeEventListener("sessionend",vf),xr.stop()};function ni(E){E.preventDefault(),Yl("WebGLRenderer: Context Lost."),I=!0}function Ne(){Yl("WebGLRenderer: Context Restored."),I=!1;const E=U.autoReset,F=Vt.enabled,Y=Vt.autoUpdate,H=Vt.needsUpdate,G=Vt.type;Ct(),U.autoReset=E,Vt.enabled=F,Vt.autoUpdate=Y,Vt.needsUpdate=H,Vt.type=G}function jn(E){Wt("WebGLRenderer: A WebGL context could not be created. Reason: ",E.statusMessage)}function Qn(E){const F=E.target;F.removeEventListener("dispose",Qn),bv(F)}function bv(E){wv(E),W.remove(E)}function wv(E){const F=W.get(E).programs;F!==void 0&&(F.forEach(function(Y){ht.releaseProgram(Y)}),E.isShaderMaterial&&ht.releaseShaderCache(E))}this.renderBufferDirect=function(E,F,Y,H,G,gt){F===null&&(F=Ve);const _t=G.isMesh&&G.matrixWorld.determinantAffine()<0,mt=Tv(E,F,Y,H,G);_.setMaterial(H,_t);let Tt=Y.index,Ot=1;if(H.wireframe===!0){if(Tt=Z.getWireframeAttribute(Y),Tt===void 0)return;Ot=2}const Qt=Y.drawRange,ie=Y.attributes.position;let Nt=Qt.start*Ot,De=(Qt.start+Qt.count)*Ot;gt!==null&&(Nt=Math.max(Nt,gt.start*Ot),De=Math.min(De,(gt.start+gt.count)*Ot)),Tt!==null?(Nt=Math.max(Nt,0),De=Math.min(De,Tt.count)):ie!=null&&(Nt=Math.max(Nt,0),De=Math.min(De,ie.count));const ci=De-Nt;if(ci<0||ci===1/0)return;vt.setup(G,H,mt,Y,Tt);let si,Le=ct;if(Tt!==null&&(si=lt.get(Tt),Le=j,Le.setIndex(si)),G.isMesh)H.wireframe===!0?(_.setLineWidth(H.wireframeLinewidth*fi()),Le.setMode(N.LINES)):Le.setMode(N.TRIANGLES);else if(G.isLine){let Ci=H.linewidth;Ci===void 0&&(Ci=1),_.setLineWidth(Ci*fi()),G.isLineSegments?Le.setMode(N.LINES):G.isLineLoop?Le.setMode(N.LINE_LOOP):Le.setMode(N.LINE_STRIP)}else G.isPoints?Le.setMode(N.POINTS):G.isSprite&&Le.setMode(N.TRIANGLES);if(G.isBatchedMesh)if(_e.get("WEBGL_multi_draw"))Le.renderMultiDraw(G._multiDrawStarts,G._multiDrawCounts,G._multiDrawCount);else{const Ci=G._multiDrawStarts,yt=G._multiDrawCounts,cn=G._multiDrawCount,pe=Tt?lt.get(Tt).bytesPerElement:1,bn=W.get(H).currentProgram.getUniforms();for(let ts=0;ts<cn;ts++)bn.setValue(N,"_gl_DrawID",ts),Le.render(Ci[ts]/pe,yt[ts])}else if(G.isInstancedMesh)Le.renderInstances(Nt,ci,G.count);else if(Y.isInstancedBufferGeometry){const Ci=Y._maxInstanceCount!==void 0?Y._maxInstanceCount:1/0,yt=Math.min(Y.instanceCount,Ci);Le.renderInstances(Nt,ci,yt)}else Le.render(Nt,ci)};function mf(E,F,Y){E.transparent===!0&&E.side===xn&&E.forceSinglePass===!1?(E.side=qe,E.needsUpdate=!0,Mc(E,F,Y),E.side=pr,E.needsUpdate=!0,Mc(E,F,Y),E.side=xn):Mc(E,F,Y)}this.compile=function(E,F,Y=null){Y===null&&(Y=E),w=ut.get(Y),w.init(F),y.push(w),Y.traverseVisible(function(G){G.isLight&&G.layers.test(F.layers)&&(w.pushLight(G),G.castShadow&&w.pushShadow(G))}),E!==Y&&E.traverseVisible(function(G){G.isLight&&G.layers.test(F.layers)&&(w.pushLight(G),G.castShadow&&w.pushShadow(G))}),w.setupLights();const H=new Set;return E.traverse(function(G){if(!(G.isMesh||G.isPoints||G.isLine||G.isSprite))return;const gt=G.material;if(gt)if(Array.isArray(gt))for(let _t=0;_t<gt.length;_t++){const mt=gt[_t];mf(mt,Y,G),H.add(mt)}else mf(gt,Y,G),H.add(gt)}),w=y.pop(),H},this.compileAsync=function(E,F,Y=null){const H=this.compile(E,F,Y);return new Promise(G=>{function gt(){if(H.forEach(function(_t){W.get(_t).currentProgram.isReady()&&H.delete(_t)}),H.size===0){G(E);return}setTimeout(gt,10)}_e.get("KHR_parallel_shader_compile")!==null?gt():setTimeout(gt,10)})};let wh=null;function Ev(E){wh&&wh(E)}function gf(){xr.stop()}function vf(){xr.start()}const xr=new P1;xr.setAnimationLoop(Ev),typeof self<"u"&&xr.setContext(self),this.setAnimationLoop=function(E){wh=E,wt.setAnimationLoop(E),E===null?xr.stop():xr.start()},wt.addEventListener("sessionstart",gf),wt.addEventListener("sessionend",vf),this.render=function(E,F){if(F!==void 0&&F.isCamera!==!0){Wt("WebGLRenderer.render: camera is not an instance of THREE.Camera.");return}if(I===!0)return;P!==null&&P.renderStart(E,F);const Y=wt.enabled===!0&&wt.isPresenting===!0,H=A!==null&&($===null||Y)&&A.begin(C,$);if(E.matrixWorldAutoUpdate===!0&&E.updateMatrixWorld(),F.parent===null&&F.matrixWorldAutoUpdate===!0&&F.updateMatrixWorld(),wt.enabled===!0&&wt.isPresenting===!0&&(A===null||A.isCompositing()===!1)&&(wt.cameraAutoUpdate===!0&&wt.updateCamera(F),F=wt.getCamera()),E.isScene===!0&&E.onBeforeRender(C,E,F,$),w=ut.get(E,y.length),w.init(F),w.state.textureUnits=K.getTextureUnits(),y.push(w),ye.multiplyMatrices(F.projectionMatrix,F.matrixWorldInverse),zt.setFromProjectionMatrix(ye,ms,F.reversedDepth),Ht=this.localClippingEnabled,Bt=kt.init(this.clippingPlanes,Ht),b=ft.get(E,T.length),b.init(),T.push(b),wt.enabled===!0&&wt.isPresenting===!0){const _t=C.xr.getDepthSensingMesh();_t!==null&&Eh(_t,F,-1/0,C.sortObjects)}Eh(E,F,0,C.sortObjects),b.finish(),C.sortObjects===!0&&b.sort(z,Rt,F.reversedDepth),ii=wt.enabled===!1||wt.isPresenting===!1||wt.hasDepthSensing()===!1,ii&&jt.addToRenderList(b,E),this.info.render.frame++,this.info.autoReset===!0&&this.info.reset(),Bt===!0&&kt.beginShadows();const G=w.state.shadowsArray;if(Vt.render(G,E,F),Bt===!0&&kt.endShadows(),(H&&A.hasRenderPass())===!1){const _t=b.opaque,mt=b.transmissive;if(w.setupLights(),F.isArrayCamera){const Tt=F.cameras;if(mt.length>0)for(let Ot=0,Qt=Tt.length;Ot<Qt;Ot++){const ie=Tt[Ot];xf(_t,mt,E,ie)}ii&&jt.render(E);for(let Ot=0,Qt=Tt.length;Ot<Qt;Ot++){const ie=Tt[Ot];Mf(b,E,ie,ie.viewport)}}else mt.length>0&&xf(_t,mt,E,F),ii&&jt.render(E),Mf(b,E,F)}$!==null&&k===0&&(K.updateMultisampleRenderTarget($),K.updateRenderTargetMipmap($)),H&&A.end(C),E.isScene===!0&&E.onAfterRender(C,E,F),vt.resetDefaultState(),tt=-1,J=null,y.pop(),y.length>0?(w=y[y.length-1],K.setTextureUnits(w.state.textureUnits),Bt===!0&&kt.setGlobalState(C.clippingPlanes,w.state.camera)):w=null,T.pop(),T.length>0?b=T[T.length-1]:b=null,P!==null&&P.renderEnd()};function Eh(E,F,Y,H){if(E.visible===!1)return;if(E.layers.test(F.layers)){if(E.isGroup)Y=E.renderOrder;else if(E.isLOD)E.autoUpdate===!0&&E.update(F);else if(E.isLightProbeGrid)w.pushLightProbeGrid(E);else if(E.isLight)w.pushLight(E),E.castShadow&&w.pushShadow(E);else if(E.isSprite){if(!E.frustumCulled||zt.intersectsSprite(E)){H&&ei.setFromMatrixPosition(E.matrixWorld).applyMatrix4(ye);const _t=Q.update(E),mt=E.material;mt.visible&&b.push(E,_t,mt,Y,ei.z,null)}}else if((E.isMesh||E.isLine||E.isPoints)&&(!E.frustumCulled||zt.intersectsObject(E))){const _t=Q.update(E),mt=E.material;if(H&&(E.boundingSphere!==void 0?(E.boundingSphere===null&&E.computeBoundingSphere(),ei.copy(E.boundingSphere.center)):(_t.boundingSphere===null&&_t.computeBoundingSphere(),ei.copy(_t.boundingSphere.center)),ei.applyMatrix4(E.matrixWorld).applyMatrix4(ye)),Array.isArray(mt)){const Tt=_t.groups;for(let Ot=0,Qt=Tt.length;Ot<Qt;Ot++){const ie=Tt[Ot],Nt=mt[ie.materialIndex];Nt&&Nt.visible&&b.push(E,_t,Nt,Y,ei.z,ie)}}else mt.visible&&b.push(E,_t,mt,Y,ei.z,null)}}const gt=E.children;for(let _t=0,mt=gt.length;_t<mt;_t++)Eh(gt[_t],F,Y,H)}function Mf(E,F,Y,H){const{opaque:G,transmissive:gt,transparent:_t}=E;w.setupLightsView(Y),Bt===!0&&kt.setGlobalState(C.clippingPlanes,Y),H&&_.viewport(it.copy(H)),G.length>0&&vc(G,F,Y),gt.length>0&&vc(gt,F,Y),_t.length>0&&vc(_t,F,Y),_.buffers.depth.setTest(!0),_.buffers.depth.setMask(!0),_.buffers.color.setMask(!0),_.setPolygonOffset(!1)}function xf(E,F,Y,H){if((Y.isScene===!0?Y.overrideMaterial:null)!==null)return;if(w.state.transmissionRenderTarget[H.id]===void 0){const Nt=_e.has("EXT_color_buffer_half_float")||_e.has("EXT_color_buffer_float");w.state.transmissionRenderTarget[H.id]=new Qe(1,1,{generateMipmaps:!0,type:Nt?$e:yn,minFilter:Lr,samples:Math.max(4,D.samples),stencilBuffer:s,resolveDepthBuffer:!1,resolveStencilBuffer:!1,colorSpace:ce.workingColorSpace})}const gt=w.state.transmissionRenderTarget[H.id],_t=H.viewport||it;gt.setSize(_t.z*C.transmissionResolutionScale,_t.w*C.transmissionResolutionScale);const mt=C.getRenderTarget(),Tt=C.getActiveCubeFace(),Ot=C.getActiveMipmapLevel();C.setRenderTarget(gt),C.getClearColor(ee),Kt=C.getClearAlpha(),Kt<1&&C.setClearColor(16777215,.5),C.clear(),ii&&jt.render(Y);const Qt=C.toneMapping;C.toneMapping=Ms;const ie=H.viewport;if(H.viewport!==void 0&&(H.viewport=void 0),w.setupLightsView(H),Bt===!0&&kt.setGlobalState(C.clippingPlanes,H),vc(E,Y,H),K.updateMultisampleRenderTarget(gt),K.updateRenderTargetMipmap(gt),_e.has("WEBGL_multisampled_render_to_texture")===!1){let Nt=!1;for(let De=0,ci=F.length;De<ci;De++){const si=F[De],{object:Le,geometry:Ci,material:yt,group:cn}=si;if(yt.side===xn&&Le.layers.test(H.layers)){const pe=yt.side;yt.side=qe,yt.needsUpdate=!0,yf(Le,Y,H,Ci,yt,cn),yt.side=pe,yt.needsUpdate=!0,Nt=!0}}Nt===!0&&(K.updateMultisampleRenderTarget(gt),K.updateRenderTargetMipmap(gt))}C.setRenderTarget(mt,Tt,Ot),C.setClearColor(ee,Kt),ie!==void 0&&(H.viewport=ie),C.toneMapping=Qt}function vc(E,F,Y){const H=F.isScene===!0?F.overrideMaterial:null;for(let G=0,gt=E.length;G<gt;G++){const _t=E[G],{object:mt,geometry:Tt,group:Ot}=_t;let Qt=_t.material;Qt.allowOverride===!0&&H!==null&&(Qt=H),mt.layers.test(Y.layers)&&yf(mt,F,Y,Tt,Qt,Ot)}}function yf(E,F,Y,H,G,gt){E.onBeforeRender(C,F,Y,H,G,gt),E.modelViewMatrix.multiplyMatrices(Y.matrixWorldInverse,E.matrixWorld),E.normalMatrix.getNormalMatrix(E.modelViewMatrix),G.onBeforeRender(C,F,Y,H,E,gt),G.transparent===!0&&G.side===xn&&G.forceSinglePass===!1?(G.side=qe,G.needsUpdate=!0,C.renderBufferDirect(Y,F,H,G,E,gt),G.side=pr,G.needsUpdate=!0,C.renderBufferDirect(Y,F,H,G,E,gt),G.side=xn):C.renderBufferDirect(Y,F,H,G,E,gt),E.onAfterRender(C,F,Y,H,G,gt)}function Mc(E,F,Y){F.isScene!==!0&&(F=Ve);const H=W.get(E),G=w.state.lights,gt=w.state.shadowsArray,_t=G.state.version,mt=ht.getParameters(E,G.state,gt,F,Y,w.state.lightProbeGridArray),Tt=ht.getProgramCacheKey(mt);let Ot=H.programs;H.environment=E.isMeshStandardMaterial||E.isMeshLambertMaterial||E.isMeshPhongMaterial?F.environment:null,H.fog=F.fog;const Qt=E.isMeshStandardMaterial||E.isMeshLambertMaterial&&!E.envMap||E.isMeshPhongMaterial&&!E.envMap;H.envMap=ot.get(E.envMap||H.environment,Qt),H.envMapRotation=H.environment!==null&&E.envMap===null?F.environmentRotation:E.envMapRotation,Ot===void 0&&(E.addEventListener("dispose",Qn),Ot=new Map,H.programs=Ot);let ie=Ot.get(Tt);if(ie!==void 0){if(H.currentProgram===ie&&H.lightsStateVersion===_t)return _f(E,mt),ie}else mt.uniforms=ht.getUniforms(E),P!==null&&E.isNodeMaterial&&P.build(E,Y,mt),E.onBeforeCompile(mt,C),ie=ht.acquireProgram(mt,Tt),Ot.set(Tt,ie),H.uniforms=mt.uniforms;const Nt=H.uniforms;return(!E.isShaderMaterial&&!E.isRawShaderMaterial||E.clipping===!0)&&(Nt.clippingPlanes=kt.uniform),_f(E,mt),H.needsLights=Dv(E),H.lightsStateVersion=_t,H.needsLights&&(Nt.ambientLightColor.value=G.state.ambient,Nt.lightProbe.value=G.state.probe,Nt.directionalLights.value=G.state.directional,Nt.directionalLightShadows.value=G.state.directionalShadow,Nt.spotLights.value=G.state.spot,Nt.spotLightShadows.value=G.state.spotShadow,Nt.rectAreaLights.value=G.state.rectArea,Nt.ltc_1.value=G.state.rectAreaLTC1,Nt.ltc_2.value=G.state.rectAreaLTC2,Nt.pointLights.value=G.state.point,Nt.pointLightShadows.value=G.state.pointShadow,Nt.hemisphereLights.value=G.state.hemi,Nt.directionalShadowMatrix.value=G.state.directionalShadowMatrix,Nt.spotLightMatrix.value=G.state.spotLightMatrix,Nt.spotLightMap.value=G.state.spotLightMap,Nt.pointShadowMatrix.value=G.state.pointShadowMatrix),H.lightProbeGrid=w.state.lightProbeGridArray.length>0,H.currentProgram=ie,H.uniformsList=null,ie}function Sf(E){if(E.uniformsList===null){const F=E.currentProgram.getUniforms();E.uniformsList=Pl.seqWithValue(F.seq,E.uniforms)}return E.uniformsList}function _f(E,F){const Y=W.get(E);Y.outputColorSpace=F.outputColorSpace,Y.batching=F.batching,Y.batchingColor=F.batchingColor,Y.instancing=F.instancing,Y.instancingColor=F.instancingColor,Y.instancingMorph=F.instancingMorph,Y.skinning=F.skinning,Y.morphTargets=F.morphTargets,Y.morphNormals=F.morphNormals,Y.morphColors=F.morphColors,Y.morphTargetsCount=F.morphTargetsCount,Y.numClippingPlanes=F.numClippingPlanes,Y.numIntersection=F.numClipIntersection,Y.vertexAlphas=F.vertexAlphas,Y.vertexTangents=F.vertexTangents,Y.toneMapping=F.toneMapping}function Av(E,F){if(E.length===0)return null;if(E.length===1)return E[0].texture!==null?E[0]:null;M.setFromMatrixPosition(F.matrixWorld);for(let Y=0,H=E.length;Y<H;Y++){const G=E[Y];if(G.texture!==null&&G.boundingBox.containsPoint(M))return G}return null}function Tv(E,F,Y,H,G){F.isScene!==!0&&(F=Ve),K.resetTextureUnits();const gt=F.fog,_t=H.isMeshStandardMaterial||H.isMeshLambertMaterial||H.isMeshPhongMaterial?F.environment:null,mt=$===null?C.outputColorSpace:$.isXRRenderTarget===!0?$.texture.colorSpace:ce.workingColorSpace,Tt=H.isMeshStandardMaterial||H.isMeshLambertMaterial&&!H.envMap||H.isMeshPhongMaterial&&!H.envMap,Ot=ot.get(H.envMap||_t,Tt),Qt=H.vertexColors===!0&&!!Y.attributes.color&&Y.attributes.color.itemSize===4,ie=!!Y.attributes.tangent&&(!!H.normalMap||H.anisotropy>0),Nt=!!Y.morphAttributes.position,De=!!Y.morphAttributes.normal,ci=!!Y.morphAttributes.color;let si=Ms;H.toneMapped&&($===null||$.isXRRenderTarget===!0)&&(si=C.toneMapping);const Le=Y.morphAttributes.position||Y.morphAttributes.normal||Y.morphAttributes.color,Ci=Le!==void 0?Le.length:0,yt=W.get(H),cn=w.state.lights;if(Bt===!0&&(Ht===!0||E!==J)){const Fe=E===J&&H.id===tt;kt.setState(H,E,Fe)}let pe=!1;H.version===yt.__version?(yt.needsLights&&yt.lightsStateVersion!==cn.state.version||yt.outputColorSpace!==mt||G.isBatchedMesh&&yt.batching===!1||!G.isBatchedMesh&&yt.batching===!0||G.isBatchedMesh&&yt.batchingColor===!0&&G.colorTexture===null||G.isBatchedMesh&&yt.batchingColor===!1&&G.colorTexture!==null||G.isInstancedMesh&&yt.instancing===!1||!G.isInstancedMesh&&yt.instancing===!0||G.isSkinnedMesh&&yt.skinning===!1||!G.isSkinnedMesh&&yt.skinning===!0||G.isInstancedMesh&&yt.instancingColor===!0&&G.instanceColor===null||G.isInstancedMesh&&yt.instancingColor===!1&&G.instanceColor!==null||G.isInstancedMesh&&yt.instancingMorph===!0&&G.morphTexture===null||G.isInstancedMesh&&yt.instancingMorph===!1&&G.morphTexture!==null||yt.envMap!==Ot||H.fog===!0&&yt.fog!==gt||yt.numClippingPlanes!==void 0&&(yt.numClippingPlanes!==kt.numPlanes||yt.numIntersection!==kt.numIntersection)||yt.vertexAlphas!==Qt||yt.vertexTangents!==ie||yt.morphTargets!==Nt||yt.morphNormals!==De||yt.morphColors!==ci||yt.toneMapping!==si||yt.morphTargetsCount!==Ci||!!yt.lightProbeGrid!=w.state.lightProbeGridArray.length>0)&&(pe=!0):(pe=!0,yt.__version=H.version);let bn=yt.currentProgram;pe===!0&&(bn=Mc(H,F,G),P&&H.isNodeMaterial&&P.onUpdateProgram(H,bn,yt));let ts=!1,Hs=!1,Zr=!1;const Oe=bn.getUniforms(),li=yt.uniforms;if(_.useProgram(bn.program)&&(ts=!0,Hs=!0,Zr=!0),H.id!==tt&&(tt=H.id,Hs=!0),yt.needsLights){const Fe=Av(w.state.lightProbeGridArray,G);yt.lightProbeGrid!==Fe&&(yt.lightProbeGrid=Fe,Hs=!0)}if(ts||J!==E){_.buffers.depth.getReversed()&&E.reversedDepth!==!0&&(E._reversedDepth=!0,E.updateProjectionMatrix()),Oe.setValue(N,"projectionMatrix",E.projectionMatrix),Oe.setValue(N,"viewMatrix",E.matrixWorldInverse);const Vs=Oe.map.cameraPosition;Vs!==void 0&&Vs.setValue(N,Se.setFromMatrixPosition(E.matrixWorld)),D.logarithmicDepthBuffer&&Oe.setValue(N,"logDepthBufFC",2/(Math.log(E.far+1)/Math.LN2)),(H.isMeshPhongMaterial||H.isMeshToonMaterial||H.isMeshLambertMaterial||H.isMeshBasicMaterial||H.isMeshStandardMaterial||H.isShaderMaterial)&&Oe.setValue(N,"isOrthographic",E.isOrthographicCamera===!0),J!==E&&(J=E,Hs=!0,Zr=!0)}if(yt.needsLights&&(cn.state.directionalShadowMap.length>0&&Oe.setValue(N,"directionalShadowMap",cn.state.directionalShadowMap,K),cn.state.spotShadowMap.length>0&&Oe.setValue(N,"spotShadowMap",cn.state.spotShadowMap,K),cn.state.pointShadowMap.length>0&&Oe.setValue(N,"pointShadowMap",cn.state.pointShadowMap,K)),G.isSkinnedMesh){Oe.setOptional(N,G,"bindMatrix"),Oe.setOptional(N,G,"bindMatrixInverse");const Fe=G.skeleton;Fe&&(Fe.boneTexture===null&&Fe.computeBoneTexture(),Oe.setValue(N,"boneTexture",Fe.boneTexture,K))}G.isBatchedMesh&&(Oe.setOptional(N,G,"batchingTexture"),Oe.setValue(N,"batchingTexture",G._matricesTexture,K),Oe.setOptional(N,G,"batchingIdTexture"),Oe.setValue(N,"batchingIdTexture",G._indirectTexture,K),Oe.setOptional(N,G,"batchingColorTexture"),G._colorsTexture!==null&&Oe.setValue(N,"batchingColorTexture",G._colorsTexture,K));const Gs=Y.morphAttributes;if((Gs.position!==void 0||Gs.normal!==void 0||Gs.color!==void 0)&&O.update(G,Y,bn),(Hs||yt.receiveShadow!==G.receiveShadow)&&(yt.receiveShadow=G.receiveShadow,Oe.setValue(N,"receiveShadow",G.receiveShadow)),(H.isMeshStandardMaterial||H.isMeshLambertMaterial||H.isMeshPhongMaterial)&&H.envMap===null&&F.environment!==null&&(li.envMapIntensity.value=F.environmentIntensity),li.dfgLUT!==void 0&&(li.dfgLUT.value=Jb()),Hs){if(Oe.setValue(N,"toneMappingExposure",C.toneMappingExposure),yt.needsLights&&Rv(li,Zr),gt&&H.fog===!0&&Lt.refreshFogUniforms(li,gt),Lt.refreshMaterialUniforms(li,H,nt,rt,w.state.transmissionRenderTarget[E.id]),yt.needsLights&&yt.lightProbeGrid){const Fe=yt.lightProbeGrid;li.probesSH.value=Fe.texture,li.probesMin.value.copy(Fe.boundingBox.min),li.probesMax.value.copy(Fe.boundingBox.max),li.probesResolution.value.copy(Fe.resolution)}Pl.upload(N,Sf(yt),li,K)}if(H.isShaderMaterial&&H.uniformsNeedUpdate===!0&&(Pl.upload(N,Sf(yt),li,K),H.uniformsNeedUpdate=!1),H.isSpriteMaterial&&Oe.setValue(N,"center",G.center),Oe.setValue(N,"modelViewMatrix",G.modelViewMatrix),Oe.setValue(N,"normalMatrix",G.normalMatrix),Oe.setValue(N,"modelMatrix",G.matrixWorld),H.uniformsGroups!==void 0){const Fe=H.uniformsGroups;for(let Vs=0,Jr=Fe.length;Vs<Jr;Vs++){const bf=Fe[Vs];et.update(bf,bn),et.bind(bf,bn)}}return bn}function Rv(E,F){E.ambientLightColor.needsUpdate=F,E.lightProbe.needsUpdate=F,E.directionalLights.needsUpdate=F,E.directionalLightShadows.needsUpdate=F,E.pointLights.needsUpdate=F,E.pointLightShadows.needsUpdate=F,E.spotLights.needsUpdate=F,E.spotLightShadows.needsUpdate=F,E.rectAreaLights.needsUpdate=F,E.hemisphereLights.needsUpdate=F}function Dv(E){return E.isMeshLambertMaterial||E.isMeshToonMaterial||E.isMeshPhongMaterial||E.isMeshStandardMaterial||E.isShadowMaterial||E.isShaderMaterial&&E.lights===!0}this.getActiveCubeFace=function(){return B},this.getActiveMipmapLevel=function(){return k},this.getRenderTarget=function(){return $},this.setRenderTargetTextures=function(E,F,Y){const H=W.get(E);H.__autoAllocateDepthBuffer=E.resolveDepthBuffer===!1,H.__autoAllocateDepthBuffer===!1&&(H.__useRenderToTexture=!1),W.get(E.texture).__webglTexture=F,W.get(E.depthTexture).__webglTexture=H.__autoAllocateDepthBuffer?void 0:Y,H.__hasExternalTextures=!0},this.setRenderTargetFramebuffer=function(E,F){const Y=W.get(E);Y.__webglFramebuffer=F,Y.__useDefaultFramebuffer=F===void 0},this.setRenderTarget=function(E,F=0,Y=0){$=E,B=F,k=Y;let H=null,G=!1,gt=!1;if(E){const mt=W.get(E);if(mt.__useDefaultFramebuffer!==void 0){_.bindFramebuffer(N.FRAMEBUFFER,mt.__webglFramebuffer),it.copy(E.viewport),at.copy(E.scissor),Xt=E.scissorTest,_.viewport(it),_.scissor(at),_.setScissorTest(Xt),tt=-1;return}else if(mt.__webglFramebuffer===void 0)K.setupRenderTarget(E);else if(mt.__hasExternalTextures)K.rebindTextures(E,W.get(E.texture).__webglTexture,W.get(E.depthTexture).__webglTexture);else if(E.depthBuffer){const Qt=E.depthTexture;if(mt.__boundDepthTexture!==Qt){if(Qt!==null&&W.has(Qt)&&(E.width!==Qt.image.width||E.height!==Qt.image.height))throw new Error("THREE.WebGLRenderer: Attached DepthTexture is initialized to the incorrect size.");K.setupDepthRenderbuffer(E)}}const Tt=E.texture;(Tt.isData3DTexture||Tt.isDataArrayTexture||Tt.isCompressedArrayTexture)&&(gt=!0);const Ot=W.get(E).__webglFramebuffer;E.isWebGLCubeRenderTarget?(Array.isArray(Ot[F])?H=Ot[F][Y]:H=Ot[F],G=!0):E.samples>0&&K.useMultisampledRTT(E)===!1?H=W.get(E).__webglMultisampledFramebuffer:Array.isArray(Ot)?H=Ot[Y]:H=Ot,it.copy(E.viewport),at.copy(E.scissor),Xt=E.scissorTest}else it.copy(Ft).multiplyScalar(nt).floor(),at.copy(Pt).multiplyScalar(nt).floor(),Xt=St;if(Y!==0&&(H=V),_.bindFramebuffer(N.FRAMEBUFFER,H)&&_.drawBuffers(E,H),_.viewport(it),_.scissor(at),_.setScissorTest(Xt),G){const mt=W.get(E.texture);N.framebufferTexture2D(N.FRAMEBUFFER,N.COLOR_ATTACHMENT0,N.TEXTURE_CUBE_MAP_POSITIVE_X+F,mt.__webglTexture,Y)}else if(gt){const mt=F;for(let Tt=0;Tt<E.textures.length;Tt++){const Ot=W.get(E.textures[Tt]);N.framebufferTextureLayer(N.FRAMEBUFFER,N.COLOR_ATTACHMENT0+Tt,Ot.__webglTexture,Y,mt)}}else if(E!==null&&Y!==0){const mt=W.get(E.texture);N.framebufferTexture2D(N.FRAMEBUFFER,N.COLOR_ATTACHMENT0,N.TEXTURE_2D,mt.__webglTexture,Y)}tt=-1},this.readRenderTargetPixels=function(E,F,Y,H,G,gt,_t,mt=0){if(!(E&&E.isWebGLRenderTarget)){Wt("WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");return}let Tt=W.get(E).__webglFramebuffer;if(E.isWebGLCubeRenderTarget&&_t!==void 0&&(Tt=Tt[_t]),Tt){_.bindFramebuffer(N.FRAMEBUFFER,Tt);try{const Ot=E.textures[mt],Qt=Ot.format,ie=Ot.type;if(E.textures.length>1&&N.readBuffer(N.COLOR_ATTACHMENT0+mt),!D.textureFormatReadable(Qt)){Wt("WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.");return}if(!D.textureTypeReadable(ie)){Wt("WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.");return}F>=0&&F<=E.width-H&&Y>=0&&Y<=E.height-G&&N.readPixels(F,Y,H,G,dt.convert(Qt),dt.convert(ie),gt)}finally{const Ot=$!==null?W.get($).__webglFramebuffer:null;_.bindFramebuffer(N.FRAMEBUFFER,Ot)}}},this.readRenderTargetPixelsAsync=async function(E,F,Y,H,G,gt,_t,mt=0){if(!(E&&E.isWebGLRenderTarget))throw new Error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");let Tt=W.get(E).__webglFramebuffer;if(E.isWebGLCubeRenderTarget&&_t!==void 0&&(Tt=Tt[_t]),Tt)if(F>=0&&F<=E.width-H&&Y>=0&&Y<=E.height-G){_.bindFramebuffer(N.FRAMEBUFFER,Tt);const Ot=E.textures[mt],Qt=Ot.format,ie=Ot.type;if(E.textures.length>1&&N.readBuffer(N.COLOR_ATTACHMENT0+mt),!D.textureFormatReadable(Qt))throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.");if(!D.textureTypeReadable(ie))throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.");const Nt=N.createBuffer();N.bindBuffer(N.PIXEL_PACK_BUFFER,Nt),N.bufferData(N.PIXEL_PACK_BUFFER,gt.byteLength,N.STREAM_READ),N.readPixels(F,Y,H,G,dt.convert(Qt),dt.convert(ie),0);const De=$!==null?W.get($).__webglFramebuffer:null;_.bindFramebuffer(N.FRAMEBUFFER,De);const ci=N.fenceSync(N.SYNC_GPU_COMMANDS_COMPLETE,0);return N.flush(),await EM(N,ci,4),N.bindBuffer(N.PIXEL_PACK_BUFFER,Nt),N.getBufferSubData(N.PIXEL_PACK_BUFFER,0,gt),N.deleteBuffer(Nt),N.deleteSync(ci),gt}else throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: requested read bounds are out of range.")},this.copyFramebufferToTexture=function(E,F=null,Y=0){const H=Math.pow(2,-Y),G=Math.floor(E.image.width*H),gt=Math.floor(E.image.height*H),_t=F!==null?F.x:0,mt=F!==null?F.y:0;K.setTexture2D(E,0),N.copyTexSubImage2D(N.TEXTURE_2D,Y,0,0,_t,mt,G,gt),_.unbindTexture()},this.copyTextureToTexture=function(E,F,Y=null,H=null,G=0,gt=0){let _t,mt,Tt,Ot,Qt,ie,Nt,De,ci;const si=E.isCompressedTexture?E.mipmaps[gt]:E.image;if(Y!==null)_t=Y.max.x-Y.min.x,mt=Y.max.y-Y.min.y,Tt=Y.isBox3?Y.max.z-Y.min.z:1,Ot=Y.min.x,Qt=Y.min.y,ie=Y.isBox3?Y.min.z:0;else{const li=Math.pow(2,-G);_t=Math.floor(si.width*li),mt=Math.floor(si.height*li),E.isDataArrayTexture?Tt=si.depth:E.isData3DTexture?Tt=Math.floor(si.depth*li):Tt=1,Ot=0,Qt=0,ie=0}H!==null?(Nt=H.x,De=H.y,ci=H.z):(Nt=0,De=0,ci=0);const Le=dt.convert(F.format),Ci=dt.convert(F.type);let yt;F.isData3DTexture?(K.setTexture3D(F,0),yt=N.TEXTURE_3D):F.isDataArrayTexture||F.isCompressedArrayTexture?(K.setTexture2DArray(F,0),yt=N.TEXTURE_2D_ARRAY):(K.setTexture2D(F,0),yt=N.TEXTURE_2D),_.activeTexture(N.TEXTURE0),_.pixelStorei(N.UNPACK_FLIP_Y_WEBGL,F.flipY),_.pixelStorei(N.UNPACK_PREMULTIPLY_ALPHA_WEBGL,F.premultiplyAlpha),_.pixelStorei(N.UNPACK_ALIGNMENT,F.unpackAlignment);const cn=_.getParameter(N.UNPACK_ROW_LENGTH),pe=_.getParameter(N.UNPACK_IMAGE_HEIGHT),bn=_.getParameter(N.UNPACK_SKIP_PIXELS),ts=_.getParameter(N.UNPACK_SKIP_ROWS),Hs=_.getParameter(N.UNPACK_SKIP_IMAGES);_.pixelStorei(N.UNPACK_ROW_LENGTH,si.width),_.pixelStorei(N.UNPACK_IMAGE_HEIGHT,si.height),_.pixelStorei(N.UNPACK_SKIP_PIXELS,Ot),_.pixelStorei(N.UNPACK_SKIP_ROWS,Qt),_.pixelStorei(N.UNPACK_SKIP_IMAGES,ie);const Zr=E.isDataArrayTexture||E.isData3DTexture,Oe=F.isDataArrayTexture||F.isData3DTexture;if(E.isDepthTexture){const li=W.get(E),Gs=W.get(F),Fe=W.get(li.__renderTarget),Vs=W.get(Gs.__renderTarget);_.bindFramebuffer(N.READ_FRAMEBUFFER,Fe.__webglFramebuffer),_.bindFramebuffer(N.DRAW_FRAMEBUFFER,Vs.__webglFramebuffer);for(let Jr=0;Jr<Tt;Jr++)Zr&&(N.framebufferTextureLayer(N.READ_FRAMEBUFFER,N.COLOR_ATTACHMENT0,W.get(E).__webglTexture,G,ie+Jr),N.framebufferTextureLayer(N.DRAW_FRAMEBUFFER,N.COLOR_ATTACHMENT0,W.get(F).__webglTexture,gt,ci+Jr)),N.blitFramebuffer(Ot,Qt,_t,mt,Nt,De,_t,mt,N.DEPTH_BUFFER_BIT,N.NEAREST);_.bindFramebuffer(N.READ_FRAMEBUFFER,null),_.bindFramebuffer(N.DRAW_FRAMEBUFFER,null)}else if(G!==0||E.isRenderTargetTexture||W.has(E)){const li=W.get(E),Gs=W.get(F);_.bindFramebuffer(N.READ_FRAMEBUFFER,X),_.bindFramebuffer(N.DRAW_FRAMEBUFFER,L);for(let Fe=0;Fe<Tt;Fe++)Zr?N.framebufferTextureLayer(N.READ_FRAMEBUFFER,N.COLOR_ATTACHMENT0,li.__webglTexture,G,ie+Fe):N.framebufferTexture2D(N.READ_FRAMEBUFFER,N.COLOR_ATTACHMENT0,N.TEXTURE_2D,li.__webglTexture,G),Oe?N.framebufferTextureLayer(N.DRAW_FRAMEBUFFER,N.COLOR_ATTACHMENT0,Gs.__webglTexture,gt,ci+Fe):N.framebufferTexture2D(N.DRAW_FRAMEBUFFER,N.COLOR_ATTACHMENT0,N.TEXTURE_2D,Gs.__webglTexture,gt),G!==0?N.blitFramebuffer(Ot,Qt,_t,mt,Nt,De,_t,mt,N.COLOR_BUFFER_BIT,N.NEAREST):Oe?N.copyTexSubImage3D(yt,gt,Nt,De,ci+Fe,Ot,Qt,_t,mt):N.copyTexSubImage2D(yt,gt,Nt,De,Ot,Qt,_t,mt);_.bindFramebuffer(N.READ_FRAMEBUFFER,null),_.bindFramebuffer(N.DRAW_FRAMEBUFFER,null)}else Oe?E.isDataTexture||E.isData3DTexture?N.texSubImage3D(yt,gt,Nt,De,ci,_t,mt,Tt,Le,Ci,si.data):F.isCompressedArrayTexture?N.compressedTexSubImage3D(yt,gt,Nt,De,ci,_t,mt,Tt,Le,si.data):N.texSubImage3D(yt,gt,Nt,De,ci,_t,mt,Tt,Le,Ci,si):E.isDataTexture?N.texSubImage2D(N.TEXTURE_2D,gt,Nt,De,_t,mt,Le,Ci,si.data):E.isCompressedTexture?N.compressedTexSubImage2D(N.TEXTURE_2D,gt,Nt,De,si.width,si.height,Le,si.data):N.texSubImage2D(N.TEXTURE_2D,gt,Nt,De,_t,mt,Le,Ci,si);_.pixelStorei(N.UNPACK_ROW_LENGTH,cn),_.pixelStorei(N.UNPACK_IMAGE_HEIGHT,pe),_.pixelStorei(N.UNPACK_SKIP_PIXELS,bn),_.pixelStorei(N.UNPACK_SKIP_ROWS,ts),_.pixelStorei(N.UNPACK_SKIP_IMAGES,Hs),gt===0&&F.generateMipmaps&&N.generateMipmap(yt),_.unbindTexture()},this.initRenderTarget=function(E){W.get(E).__webglFramebuffer===void 0&&K.setupRenderTarget(E)},this.initTexture=function(E){E.isCubeTexture?K.setTextureCube(E,0):E.isData3DTexture?K.setTexture3D(E,0):E.isDataArrayTexture||E.isCompressedArrayTexture?K.setTexture2DArray(E,0):K.setTexture2D(E,0),_.unbindTexture()},this.resetState=function(){B=0,k=0,$=null,_.reset(),vt.reset()},typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}get coordinateSystem(){return ms}get outputColorSpace(){return this._outputColorSpace}set outputColorSpace(t){this._outputColorSpace=t;const e=this.getContext();e.drawingBufferColorSpace=ce._getDrawingBufferColorSpace(t),e.unpackColorSpace=ce._getUnpackColorSpace()}}const Qb=`
5528
5528
  varying vec3 vDir;
5529
5529
  varying vec3 vWorldDir;
5530
5530
 
@@ -5833,7 +5833,7 @@ void main() {
5833
5833
  // what is behind: exactly what the display drawn first and the deck laid over it gave.
5834
5834
  gl_FragColor = uPremultiplied > 0.5 ? vec4(color * alpha + halo * (1.0 - alpha), alpha) : vec4(color, alpha);
5835
5835
  }
5836
- `;function $d(a,t,e,i=0){const n={sunDir:{value:new R(0,1,0)},sunColor:{value:new st(1,1,1)},ambientColor:{value:new st(.5,.5,.5)},baseColor:{value:a},coverage:{value:t},opticalDensity:{value:1},darkness:{value:0},layerHeight:{value:e},fieldOffset:{value:new R},fibrous:{value:i},uHaloShown:{value:0},uPremultiplied:{value:0},uSource:{value:new R(0,1,0)},uUp:{value:new R(0,1,0)},uStrength:{value:0},uTint:{value:new R(1,1,1)},uMap:{value:null},uGain:{value:0}};return{material:new de({uniforms:n,vertexShader:Qb,fragmentShader:tw,transparent:!0,depthWrite:!1,depthTest:!0,side:qe}),uniforms:n}}function Kd(a){return new di(a,48,24,0,Math.PI*2,0,Math.PI/2)}class Me{static OCTAVES=4;static GAIN=.55;static LACUNARITY=2.03;static fract(t){return t-Math.floor(t)}static hash3(t,e,i){const n=t*127.1+e*311.7+i*74.7,s=t*269.5+e*183.3+i*246.1,r=t*113.5+e*271.9+i*124.6;return[Me.fract(Math.sin(n)*43758.5453)*2-1,Me.fract(Math.sin(s)*43758.5453)*2-1,Me.fract(Math.sin(r)*43758.5453)*2-1]}static noise3D(t,e,i){const n=Math.floor(t),s=Math.floor(e),r=Math.floor(i),o=t-n,c=e-s,l=i-r,h=o*o*(3-2*o),u=c*c*(3-2*c),d=l*l*(3-2*l),f=(v,m,g)=>{const[S,x,M]=Me.hash3(n+v,s+m,r+g);return S*(o-v)+x*(c-m)+M*(l-g)},p=(v,m,g)=>v+(m-v)*g;return p(p(p(f(0,0,0),f(1,0,0),h),p(f(0,1,0),f(1,1,0),h),u),p(p(f(0,0,1),f(1,0,1),h),p(f(0,1,1),f(1,1,1),h),u),d)}static thresholdFor(t,e,i){const n=Math.min(.999,Math.max(.001,t));return e-i*(Math.sqrt(3)/Math.PI)*Math.log(n/(1-n))}static fbm(t,e,i){let n=0,s=Me.GAIN;for(let r=0;r<Me.OCTAVES;r++)n+=Me.noise3D(t,e,i)*s,t*=Me.LACUNARITY,e*=Me.LACUNARITY,i*=Me.LACUNARITY,s*=Me.GAIN;return n}static worley(t,e,i){const n=Math.floor(t),s=Math.floor(e),r=Math.floor(i),o=t-n,c=e-s,l=i-r;let h=1/0;for(let u=-1;u<=1;u++)for(let d=-1;d<=1;d++)for(let f=-1;f<=1;f++){const[p,v,m]=Me.hash3(n+u,s+d,r+f),g=u+(p*.5+.5)-o,S=d+(v*.5+.5)-c,x=f+(m*.5+.5)-l;h=Math.min(h,g*g+S*S+x*x)}return Math.sqrt(h)}static alphaAt(t,e,i,n={x:0,z:0}){if(i<=0)return 0;const[s,r,o]=Me.warpedAt(t,e,n),c=Me.fbm(s*.014,r*.014,o*.014)*.5+.5,l=1-Me.worley(s*.011,r*.011,o*.011),h=c+(l-c)*.4,u=Me.thresholdFor(i,B1,J0),d=Me.smoothstep(u-Zl,u+Zl,h);return d+(1-d)*Me.smoothstep(.82,1,i)}static iceAlphaAt(t,e,i,n={x:0,z:0}){if(i<=0)return 0;const[s,r,o]=Me.warpedAt(t,e,n),c=s*.0016,l=r*.02,h=o*.045,u=Me.fbm(c,l,h)*.5+.5,d=Me.fbm(c*3.1+7,l*3.1+7,h*3.1+7)*.5+.5,f=Me.thresholdFor(i,j0,vh);return Me.smoothstep(f-qd,f+qd,u*.72+d*.28)}static warpedAt(t,e,i){const n=Math.abs(t.y),s=e/Math.max(n,.04),r=t.x*s+i.x,o=t.y*s,c=t.z*s+i.z,l=r*.006,h=o*.006,u=c*.006;return[r+Me.fbm(l+12.3,h+12.3,u+12.3)*40,o+Me.fbm(l+47.1,h+47.1,u+47.1)*40,c+Me.fbm(l+91.7,h+91.7,u+91.7)*40]}static smoothstep(t,e,i){const n=Math.min(1,Math.max(0,(i-t)/(e-t)));return n*n*(3-2*n)}}const lr=6371e3,ui=64,bo=8,pu=.2787;function Zd(a){if(a.seed!==void 0)return a.seed;let t=2166136261;for(const e of a.id)t=Math.imul(t^e.charCodeAt(0),16777619);return t>>>0}const ew=[[4,.65],[8,.25],[16,.1]];let vm;function iw(){const a=new Uint8Array(ui**3),t=(n,s,r,o)=>{let c=Math.imul(n%o+1,374761393)^Math.imul(s%o+1,668265263)^Math.imul(r%o+1,1274126177);return c=Math.imul(c^c>>>13,1274126177),((c^c>>>16)>>>0)/4294967295},e=n=>n*n*(3-2*n),i=(n,s,r,o)=>{const c=Math.floor(n),l=Math.floor(s),h=Math.floor(r),u=e(n-c),d=e(s-l),f=e(r-h);let p=0;for(let v=0;v<2;v++)for(let m=0;m<2;m++)for(let g=0;g<2;g++)p+=t(c+g,l+m,h+v,o)*(g?u:1-u)*(m?d:1-d)*(v?f:1-f);return p};for(let n=0;n<ui;n++)for(let s=0;s<ui;s++)for(let r=0;r<ui;r++){let o=0;for(const[c,l]of ew)o+=i(r/ui*c,s/ui*c,n/ui*c,c)*l;a[r+ui*(s+ui*n)]=Math.round(o*255)}return a}function nw(){vm??=iw();const a=new m1(vm,ui,ui,ui);return a.format=dh,a.minFilter=a.magFilter=le,a.wrapS=a.wrapT=a.wrapR=sc,a.needsUpdate=!0,a}function sw(a,t,e,i){const n=h=>{const u=(lr+t)*a,d=(t-h)*(2*lr+t+h),f=u*u-d;if(f<0)return;const p=-u-(u>=0?1:-1)*Math.sqrt(f),v=p===0?0:d/p;return[Math.min(p,v),Math.max(p,v)]},s=n(e+i);if(!s||s[1]<=0)return;let r=Math.max(0,s[0]),o=s[1];const c=n(e);c&&(r>=c[0]&&r<c[1]?r=c[1]:c[0]>r&&(o=Math.min(o,c[0])));const l=n(0);return l&&l[0]>=0&&(o=Math.min(o,l[0])),o>r?[r,o]:void 0}const rw=`varying vec3 vCloudDirection;
5836
+ `;function $d(a,t,e,i=0){const n={sunDir:{value:new R(0,1,0)},sunColor:{value:new st(1,1,1)},ambientColor:{value:new st(.5,.5,.5)},baseColor:{value:a},coverage:{value:t},opticalDensity:{value:1},darkness:{value:0},layerHeight:{value:e},fieldOffset:{value:new R},fibrous:{value:i},uHaloShown:{value:0},uPremultiplied:{value:0},uSource:{value:new R(0,1,0)},uUp:{value:new R(0,1,0)},uStrength:{value:0},uTint:{value:new R(1,1,1)},uMap:{value:null},uGain:{value:0}};return{material:new fe({uniforms:n,vertexShader:Qb,fragmentShader:tw,transparent:!0,depthWrite:!1,depthTest:!0,side:qe}),uniforms:n}}function Kd(a){return new di(a,48,24,0,Math.PI*2,0,Math.PI/2)}class Me{static OCTAVES=4;static GAIN=.55;static LACUNARITY=2.03;static fract(t){return t-Math.floor(t)}static hash3(t,e,i){const n=t*127.1+e*311.7+i*74.7,s=t*269.5+e*183.3+i*246.1,r=t*113.5+e*271.9+i*124.6;return[Me.fract(Math.sin(n)*43758.5453)*2-1,Me.fract(Math.sin(s)*43758.5453)*2-1,Me.fract(Math.sin(r)*43758.5453)*2-1]}static noise3D(t,e,i){const n=Math.floor(t),s=Math.floor(e),r=Math.floor(i),o=t-n,c=e-s,l=i-r,h=o*o*(3-2*o),u=c*c*(3-2*c),d=l*l*(3-2*l),f=(v,m,g)=>{const[S,x,M]=Me.hash3(n+v,s+m,r+g);return S*(o-v)+x*(c-m)+M*(l-g)},p=(v,m,g)=>v+(m-v)*g;return p(p(p(f(0,0,0),f(1,0,0),h),p(f(0,1,0),f(1,1,0),h),u),p(p(f(0,0,1),f(1,0,1),h),p(f(0,1,1),f(1,1,1),h),u),d)}static thresholdFor(t,e,i){const n=Math.min(.999,Math.max(.001,t));return e-i*(Math.sqrt(3)/Math.PI)*Math.log(n/(1-n))}static fbm(t,e,i){let n=0,s=Me.GAIN;for(let r=0;r<Me.OCTAVES;r++)n+=Me.noise3D(t,e,i)*s,t*=Me.LACUNARITY,e*=Me.LACUNARITY,i*=Me.LACUNARITY,s*=Me.GAIN;return n}static worley(t,e,i){const n=Math.floor(t),s=Math.floor(e),r=Math.floor(i),o=t-n,c=e-s,l=i-r;let h=1/0;for(let u=-1;u<=1;u++)for(let d=-1;d<=1;d++)for(let f=-1;f<=1;f++){const[p,v,m]=Me.hash3(n+u,s+d,r+f),g=u+(p*.5+.5)-o,S=d+(v*.5+.5)-c,x=f+(m*.5+.5)-l;h=Math.min(h,g*g+S*S+x*x)}return Math.sqrt(h)}static alphaAt(t,e,i,n={x:0,z:0}){if(i<=0)return 0;const[s,r,o]=Me.warpedAt(t,e,n),c=Me.fbm(s*.014,r*.014,o*.014)*.5+.5,l=1-Me.worley(s*.011,r*.011,o*.011),h=c+(l-c)*.4,u=Me.thresholdFor(i,B1,J0),d=Me.smoothstep(u-Zl,u+Zl,h);return d+(1-d)*Me.smoothstep(.82,1,i)}static iceAlphaAt(t,e,i,n={x:0,z:0}){if(i<=0)return 0;const[s,r,o]=Me.warpedAt(t,e,n),c=s*.0016,l=r*.02,h=o*.045,u=Me.fbm(c,l,h)*.5+.5,d=Me.fbm(c*3.1+7,l*3.1+7,h*3.1+7)*.5+.5,f=Me.thresholdFor(i,j0,vh);return Me.smoothstep(f-qd,f+qd,u*.72+d*.28)}static warpedAt(t,e,i){const n=Math.abs(t.y),s=e/Math.max(n,.04),r=t.x*s+i.x,o=t.y*s,c=t.z*s+i.z,l=r*.006,h=o*.006,u=c*.006;return[r+Me.fbm(l+12.3,h+12.3,u+12.3)*40,o+Me.fbm(l+47.1,h+47.1,u+47.1)*40,c+Me.fbm(l+91.7,h+91.7,u+91.7)*40]}static smoothstep(t,e,i){const n=Math.min(1,Math.max(0,(i-t)/(e-t)));return n*n*(3-2*n)}}const lr=6371e3,ui=64,bo=8,pu=.2787;function Zd(a){if(a.seed!==void 0)return a.seed;let t=2166136261;for(const e of a.id)t=Math.imul(t^e.charCodeAt(0),16777619);return t>>>0}const ew=[[4,.65],[8,.25],[16,.1]];let vm;function iw(){const a=new Uint8Array(ui**3),t=(n,s,r,o)=>{let c=Math.imul(n%o+1,374761393)^Math.imul(s%o+1,668265263)^Math.imul(r%o+1,1274126177);return c=Math.imul(c^c>>>13,1274126177),((c^c>>>16)>>>0)/4294967295},e=n=>n*n*(3-2*n),i=(n,s,r,o)=>{const c=Math.floor(n),l=Math.floor(s),h=Math.floor(r),u=e(n-c),d=e(s-l),f=e(r-h);let p=0;for(let v=0;v<2;v++)for(let m=0;m<2;m++)for(let g=0;g<2;g++)p+=t(c+g,l+m,h+v,o)*(g?u:1-u)*(m?d:1-d)*(v?f:1-f);return p};for(let n=0;n<ui;n++)for(let s=0;s<ui;s++)for(let r=0;r<ui;r++){let o=0;for(const[c,l]of ew)o+=i(r/ui*c,s/ui*c,n/ui*c,c)*l;a[r+ui*(s+ui*n)]=Math.round(o*255)}return a}function nw(){vm??=iw();const a=new m1(vm,ui,ui,ui);return a.format=dh,a.minFilter=a.magFilter=le,a.wrapS=a.wrapT=a.wrapR=sc,a.needsUpdate=!0,a}function sw(a,t,e,i){const n=h=>{const u=(lr+t)*a,d=(t-h)*(2*lr+t+h),f=u*u-d;if(f<0)return;const p=-u-(u>=0?1:-1)*Math.sqrt(f),v=p===0?0:d/p;return[Math.min(p,v),Math.max(p,v)]},s=n(e+i);if(!s||s[1]<=0)return;let r=Math.max(0,s[0]),o=s[1];const c=n(e);c&&(r>=c[0]&&r<c[1]?r=c[1]:c[0]>r&&(o=Math.min(o,c[0])));const l=n(0);return l&&l[0]>=0&&(o=Math.min(o,l[0])),o>r?[r,o]:void 0}const rw=`varying vec3 vCloudDirection;
5837
5837
  void main() {
5838
5838
  vCloudDirection = position;
5839
5839
  gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
@@ -6049,7 +6049,7 @@ float transmissionAt(vec3 dir, float distanceM) {
6049
6049
  if (transmission < 0.015) break;
6050
6050
  }
6051
6051
  return transmission;
6052
- }`,i=/\b(noiseMap|sunDir|sunColor|ambientColor|hazeColor|offsetM|seedOffset|localCenter|localSize|localRotation|baseM|thicknessM|eyeM|coverage|sizeM|density|darkness|flatness|SLICE|MAX_HOLES|holeCount|holeCenter|holeSize|holeRotation|R|roots|altitude|coverageThreshold|ellipsoidRadius|clipLocal|densityAt|transmissionAt)\b/g;return(t+e).replace(i,n=>a+n)}class Jl{mesh;uniforms;constructor(t,e){this.uniforms={noiseMap:{value:t},sunDir:{value:new R(0,1,0)},sunColor:{value:new st(1,1,1)},ambientColor:{value:new st(.4,.45,.5)},hazeColor:{value:new st(.5,.6,.7)},offsetM:{value:new R},seedOffset:{value:new R},localCenter:{value:new R},localSize:{value:new R},localRotation:{value:0},holeCount:{value:0},holeCenter:{value:Array.from({length:bo},()=>new R)},holeSize:{value:Array.from({length:bo},()=>new R)},holeRotation:{value:new Array(bo).fill(0)},baseM:{value:1e3},thicknessM:{value:650},eyeM:{value:1.6},coverage:{value:.5},sizeM:{value:1400},density:{value:1},darkness:{value:0},flatness:{value:0}};const i=new de({uniforms:this.uniforms,vertexShader:rw,fragmentShader:Jd,transparent:!0,depthWrite:!1,depthTest:!0,side:qe});this.mesh=new bt(new di(e,32,16),i),this.mesh.frustumCulled=!1}update(t,e,i,n=[]){const s=this.uniforms;s.localSize.value.set(i?.widthM??0,i?.thicknessM??0,i?.depthM??0),s.localCenter.value.set(i?.eastM??0,i?i.baseM+i.thicknessM/2:0,-(i?.northM??0)),s.localRotation.value=(i?.rotationDeg??0)*Math.PI/180,s.holeCount.value=Math.min(bo,n.length),n.slice(0,bo).forEach((o,c)=>{s.holeCenter.value[c].set(o.eastM,o.baseM+o.thicknessM/2,-o.northM),s.holeSize.value[c].set(o.widthM,o.thicknessM,o.depthM),s.holeRotation.value[c]=o.rotationDeg*Math.PI/180}),s.baseM.value=Math.max(0,t.baseM),s.thicknessM.value=Math.max(10,t.thicknessM),s.coverage.value=Math.max(0,Math.min(1,t.coverage)),s.sizeM.value=Math.max(50,t.sizeM),s.density.value=Math.max(0,Math.min(2,t.density)),s.darkness.value=Math.max(0,Math.min(1,t.darkness??0)),s.eyeM.value=Math.max(.1,e),s.flatness.value=t.type==="stratus"?1:t.type==="stratocumulus"?.45:0;const r=Zd(t);s.seedOffset.value.set(r%97/97,r%61/61,r%37/37),this.mesh.visible=s.density.value>0&&(i!==void 0||s.coverage.value>0)}static thresholdFor(t){const e=Math.min(.999,Math.max(.001,t));return .564-.2516*(Math.sqrt(3)/Math.PI)*Math.log(e/(1-e))}densityAt(t){const e=this.uniforms,i=(L,B,k)=>{const $=Math.max(0,Math.min(1,(k-L)/(B-L)));return $*$*(3-2*$)},n=(L,B,k)=>L+(B-L)*k,s=e.eyeM.value+t.y,r=2*lr*s+t.x**2+s**2+t.z**2,o=r/(Math.sqrt(lr**2+r)+lr),c=(o-e.baseM.value)/e.thicknessM.value,l=e.localSize.value.x>0;if(c<=0||c>=1||e.coverage.value<=0&&!l)return 0;const h=(L,B,k)=>{const $=t.x+e.offsetM.value.x-L.x,tt=t.z+e.offsetM.value.z-L.z,J=Math.cos(k),it=Math.sin(k);return Math.hypot((J*$-it*tt)/(B.x*.5),(o-L.y)/(B.y*.5),(it*$+J*tt)/(B.z*.5))},u=l?h(e.localCenter.value,e.localSize.value,e.localRotation.value):0;if(u>1.3)return 0;const d=[t.x,t.y,t.z].map((L,B)=>(L+e.offsetM.value.getComponent(B))/(e.sizeM.value*4)+e.seedOffset.value.getComponent(B)),f=e.noiseMap.value.image.data,p=(L,B,k)=>{const $=[L,B,k].map(at=>(at%1+1)%1*ui-.5),tt=$.map(Math.floor),J=$.map((at,Xt)=>at-tt[Xt]);let it=0;for(let at=0;at<2;at++)for(let Xt=0;Xt<2;Xt++)for(let ee=0;ee<2;ee++){const Kt=(tt[0]+ee+ui)%ui,q=(tt[1]+Xt+ui)%ui,rt=(tt[2]+at+ui)%ui;it+=f[Kt+ui*(q+ui*rt)]/255*(ee?J[0]:1-J[0])*(Xt?J[1]:1-J[1])*(at?J[2]:1-J[2])}return it},v=[d[0]*.173,pu,d[2]*.173];d[0]+=(p(v[0]+.13,v[1]+.27,v[2]+.41)-.5)*1.3,d[2]+=(p(v[0]+.67,v[1]+.53,v[2]+.19)-.5)*1.3;const m=(d[0]*.731+d[2]*.682)*1.371,g=(-d[0]*.682+d[2]*.731)*1.371;let S=i(.2,.8,p(d[0],pu,d[2])*.65+p(m,pu+.37,g)*.35);const x=i(8e3,4e4,Math.hypot(t.x,t.y,t.z)),M=n(p(d[0]*2,d[1]*3,d[2]*2),.5,x),b=n(p(d[0]*7,d[1]*7,d[2]*7),.5,x);let w=Jl.thresholdFor(e.coverage.value),T=1,y=0;if(l){const L=u+(M-.5)*.18;y=1-i(.35,1,L),T=1-i(.85,1.15,L),S=n(S,1,y),w=Math.min(w,Jl.thresholdFor(.5))}for(let L=0;L<e.holeCount.value;L++)T*=i(.85,1.15,h(e.holeCenter.value[L],e.holeSize.value[L],e.holeRotation.value[L])+(M-.5)*.18);if(T<.001)return 0;const A=(1-e.flatness.value)*.3*c*c;let C=i(w-.1+A,w+.1+A,S+(M-.5)*.12*c);if(C=n(C,1,i(.92,1,e.coverage.value)),C=n(C,Math.max(e.coverage.value,y),x),C<.001)return 0;const I=n(.45+.55*M,.96,e.flatness.value),P=i(0,.09,c)*(1-i(I-.22,I,c)),V=n(Math.max(0,C-(1-M)*.38-(1-b)*.1),C*.8,e.flatness.value),X=n(1-x,1,i(.5,.92,e.coverage.value));return P*V*e.density.value*T*X}transmissionAt(t,e=1/0){const i=this.uniforms,n=sw(t.y,i.eyeM.value,i.baseM.value,i.thicknessM.value);if(!n)return 1;let[s,r]=n;if(i.localSize.value.x>0){const h=i.localCenter.value.clone().sub(i.offsetM.value);h.y-=i.eyeM.value+(h.x**2+h.z**2)/(2*lr);const u=i.localSize.value.length()*.5+25,d=t.x*h.x+t.y*h.y+t.z*h.z,f=d*d-h.lengthSq()+u*u;if(f<0)return 1;s=Math.max(s,d-Math.sqrt(f)),r=Math.min(r,d+Math.sqrt(f))}const o=Math.min(r,e,s+18e3);if(o<=s)return 1;const c=(o-s)/48;let l=1;for(let h=0;h<48;h++){const u=s+(h+.5)*c;if(l*=Math.exp(-this.densityAt({x:t.x*u,y:t.y*u,z:t.z*u})*c*.006),l<.015)break}return l}dispose(){this.mesh.removeFromParent(),this.mesh.geometry.dispose(),this.mesh.material.dispose()}}class vi{static VIOLET_NM=400;static DEEP_RED_NM=700;static SAMPLES=vi.build(24);static build(t){const e=[];let i=0,n=0,s=0;for(let r=0;r<t;r++){const o=vi.VIOLET_NM+(r+.5)/t*(vi.DEEP_RED_NM-vi.VIOLET_NM),[c,l,h]=vi.colourMatching(o),u={wavelengthNm:o,r:Math.max(0,3.2406*c-1.5372*l-.4986*h),g:Math.max(0,-.9689*c+1.8758*l+.0415*h),b:Math.max(0,.0557*c-.204*l+1.057*h)};i+=u.r,n+=u.g,s+=u.b,e.push(u)}for(const r of e)r.r/=i,r.g/=n,r.b/=s;return e}static tristimulus(t,e,i){let n=0,s=0,r=0;for(let c=0;c<t.length;c++){const[l,h,u]=vi.colourMatching(t[c]);n+=l*e[c],s+=h*e[c],r+=u*e[c]}const o=683*i;return[n*o,s*o,r*o]}static scotopic(t){const e=t/1e3;return .992*Math.exp(-321.9*(e-.5)**2)}static linearSrgbOf([t,e,i]){return[3.2406*t-1.5372*e-.4986*i,-.9689*t+1.8758*e+.0415*i,.0557*t-.204*e+1.057*i]}static colourMatching(t){const e=(i,n,s)=>{const r=(t-i)/(t<i?n:s);return Math.exp(-.5*r*r)};return[1.056*e(599.8,37.9,31)+.362*e(442,16,26.7)-.065*e(501.1,20.4,26.2),.821*e(568.8,46.9,40.5)+.286*e(530.9,16.3,31.1),1.217*e(437,11.8,36)+.681*e(459,26,13.8)]}}class jl{static reflectance(t,e,i){const s=e/i*Math.sqrt(Math.max(0,1-t*t));if(s>=1)return 1;const r=Math.sqrt(Math.max(0,1-s*s)),o=(i*t-e*r)/(i*t+e*r),c=(e*t-i*r)/(e*t+i*r);return(o*o+c*c)/2}}class bi{static RED_NM=656.3;static BLUE_NM=435.8;static ANCHOR_RED=1.3312;static ANCHOR_BLUE=1.3404;static B=(bi.ANCHOR_BLUE-bi.ANCHOR_RED)/(1/(bi.BLUE_NM*bi.BLUE_NM)-1/(bi.RED_NM*bi.RED_NM));static A=bi.ANCHOR_RED-bi.B/(bi.RED_NM*bi.RED_NM);static indexAt(t){return bi.A+bi.B/(t*t)}}class Ga{static MAX_CHORDS=4;index=1.333;set refractiveIndex(t){this.index=t}trace(t,e){const i=Math.min(1,Math.max(0,t)),n=Math.sqrt(Math.max(0,1-i*i)),s=i/this.index,r=Math.sqrt(Math.max(0,1-s*s)),o=Math.asin(i),c=Math.asin(s),l=jl.reflectance(n,1,this.index);let h=0;e[h].chords=0,e[h].scatteringAngle=Ga.folded(Math.PI-2*o),e[h].weight=l,h++;const u=jl.reflectance(r,this.index,1);let d=1-l;for(let f=1;f<=Ga.MAX_CHORDS&&h<e.length;f++){const p=2*(o-c)+(f-1)*(Math.PI-2*c);e[h].chords=f,e[h].scatteringAngle=Ga.folded(p),e[h].weight=d*(1-u),h++,d*=u}return h}static folded(t){const e=2*Math.PI;let i=t%e;return i<0&&(i+=e),i>Math.PI?e-i:i}}class hi{static BINS=1800;static SOURCE_RADIUS_DEG=.265;static FULL_UNTIL_DEG=60;static FADED_BY_DEG=90;static IMPACT_STEPS=4096;drop=new Ga;previous=hi.emergences();current=hi.emergences();tally=new Float32Array(hi.BINS*3);radiance=new Float32Array(hi.BINS*3);scratch=new Float32Array(hi.BINS*3);static emergences(){return Array.from({length:Ga.MAX_CHORDS+1},()=>({chords:0,scatteringAngle:0,weight:0}))}compute(){this.tally.fill(0);for(const t of vi.SAMPLES)this.sweep(t);return this.toRadiance(),this.blurBySourceDisc(),{bins:hi.BINS,data:this.radiance,binDeg:180/hi.BINS}}sweep(t){this.drop.refractiveIndex=bi.indexAt(t.wavelengthNm);const e=hi.IMPACT_STEPS;let i=this.drop.trace(0,this.previous);const n=1/e;for(let s=1;s<=e;s++){const r=this.drop.trace(Math.sqrt(s/e),this.current);for(let o=0;o<Math.min(r,i);o++){const c=this.previous[o],l=this.current[o];c.chords===l.chords&&this.deposit(c.scatteringAngle,l.scatteringAngle,(c.weight+l.weight)/2*n,t)}i=r,this.copyInto(this.current,this.previous)}}copyInto(t,e){for(let i=0;i<t.length;i++)e[i].chords=t[i].chords,e[i].scatteringAngle=t[i].scatteringAngle,e[i].weight=t[i].weight}deposit(t,e,i,n){if(i<=0)return;const s=hi.BINS,r=Math.PI/s,o=Math.min(t,e),c=Math.max(t,e),l=c-o,h=Math.min(s-1,Math.max(0,Math.floor(o/r))),u=Math.min(s-1,Math.max(0,Math.floor(c/r)));if(l<=0||h===u){this.add(h,i,n);return}for(let d=h;d<=u;d++){const f=Math.min(c,(d+1)*r)-Math.max(o,d*r);f>0&&this.add(d,i*f/l,n)}}add(t,e,i){const n=t*3,s=e*vi.SAMPLES.length;this.tally[n]+=s*i.r,this.tally[n+1]+=s*i.g,this.tally[n+2]+=s*i.b}toRadiance(){const t=hi.BINS,e=Math.PI/t;for(let i=0;i<t;i++){const n=2*Math.PI*(Math.cos(i*e)-Math.cos((i+1)*e)),s=n>0?this.backwardShare((i+.5)*(180/t))/n:0,r=i*3;this.radiance[r]=this.tally[r]*s,this.radiance[r+1]=this.tally[r+1]*s,this.radiance[r+2]=this.tally[r+2]*s}}backwardShare(t){const e=180-t;if(e<=hi.FULL_UNTIL_DEG)return 1;if(e>=hi.FADED_BY_DEG)return 0;const i=(e-hi.FULL_UNTIL_DEG)/(hi.FADED_BY_DEG-hi.FULL_UNTIL_DEG);return Math.cos(i*Math.PI/2)**2}blurBySourceDisc(){const t=hi.BINS,e=hi.SOURCE_RADIUS_DEG*t/180,i=Math.max(1,Math.ceil(e)),n=[];let s=0;for(let r=-i;r<=i;r++){const o=Math.max(0,e*e-r*r),c=Math.sqrt(o);n.push(c),s+=c}if(!(s<=0)){this.scratch.set(this.radiance);for(let r=0;r<t;r++){let o=0,c=0,l=0;for(let u=-i;u<=i;u++){const d=Math.min(t-1,Math.max(0,r+u))*3,f=n[u+i];o+=this.scratch[d]*f,c+=this.scratch[d+1]*f,l+=this.scratch[d+2]*f}const h=r*3;this.radiance[h]=o/s,this.radiance[h+1]=c/s,this.radiance[h+2]=l/s}}}}class Nr{static RADIUS=880;static RENDER_ORDER=5.5;static GAIN=.22;static MOON_SATURATION=.15;object;material;sky=new hi;texture;texels;computed=!1;constructor(){this.texels=new Uint16Array(hi.BINS*4),this.texture=new Mr(this.texels,hi.BINS,1,Di,$e),this.texture.minFilter=le,this.texture.magFilter=le,this.texture.wrapS=Ri,this.texture.wrapT=Ri,this.texture.needsUpdate=!0,this.material=new de({uniforms:{uSource:{value:new R(0,1,0)},uStrength:{value:0},uTint:{value:new R(1,1,1)},uSaturation:{value:1},uProfile:{value:this.texture},uGain:{value:Nr.GAIN}},vertexShader:`
6052
+ }`,i=/\b(noiseMap|sunDir|sunColor|ambientColor|hazeColor|offsetM|seedOffset|localCenter|localSize|localRotation|baseM|thicknessM|eyeM|coverage|sizeM|density|darkness|flatness|SLICE|MAX_HOLES|holeCount|holeCenter|holeSize|holeRotation|R|roots|altitude|coverageThreshold|ellipsoidRadius|clipLocal|densityAt|transmissionAt)\b/g;return(t+e).replace(i,n=>a+n)}class Jl{mesh;uniforms;constructor(t,e){this.uniforms={noiseMap:{value:t},sunDir:{value:new R(0,1,0)},sunColor:{value:new st(1,1,1)},ambientColor:{value:new st(.4,.45,.5)},hazeColor:{value:new st(.5,.6,.7)},offsetM:{value:new R},seedOffset:{value:new R},localCenter:{value:new R},localSize:{value:new R},localRotation:{value:0},holeCount:{value:0},holeCenter:{value:Array.from({length:bo},()=>new R)},holeSize:{value:Array.from({length:bo},()=>new R)},holeRotation:{value:new Array(bo).fill(0)},baseM:{value:1e3},thicknessM:{value:650},eyeM:{value:1.6},coverage:{value:.5},sizeM:{value:1400},density:{value:1},darkness:{value:0},flatness:{value:0}};const i=new fe({uniforms:this.uniforms,vertexShader:rw,fragmentShader:Jd,transparent:!0,depthWrite:!1,depthTest:!0,side:qe});this.mesh=new bt(new di(e,32,16),i),this.mesh.frustumCulled=!1}update(t,e,i,n=[]){const s=this.uniforms;s.localSize.value.set(i?.widthM??0,i?.thicknessM??0,i?.depthM??0),s.localCenter.value.set(i?.eastM??0,i?i.baseM+i.thicknessM/2:0,-(i?.northM??0)),s.localRotation.value=(i?.rotationDeg??0)*Math.PI/180,s.holeCount.value=Math.min(bo,n.length),n.slice(0,bo).forEach((o,c)=>{s.holeCenter.value[c].set(o.eastM,o.baseM+o.thicknessM/2,-o.northM),s.holeSize.value[c].set(o.widthM,o.thicknessM,o.depthM),s.holeRotation.value[c]=o.rotationDeg*Math.PI/180}),s.baseM.value=Math.max(0,t.baseM),s.thicknessM.value=Math.max(10,t.thicknessM),s.coverage.value=Math.max(0,Math.min(1,t.coverage)),s.sizeM.value=Math.max(50,t.sizeM),s.density.value=Math.max(0,Math.min(2,t.density)),s.darkness.value=Math.max(0,Math.min(1,t.darkness??0)),s.eyeM.value=Math.max(.1,e),s.flatness.value=t.type==="stratus"?1:t.type==="stratocumulus"?.45:0;const r=Zd(t);s.seedOffset.value.set(r%97/97,r%61/61,r%37/37),this.mesh.visible=s.density.value>0&&(i!==void 0||s.coverage.value>0)}static thresholdFor(t){const e=Math.min(.999,Math.max(.001,t));return .564-.2516*(Math.sqrt(3)/Math.PI)*Math.log(e/(1-e))}densityAt(t){const e=this.uniforms,i=(L,B,k)=>{const $=Math.max(0,Math.min(1,(k-L)/(B-L)));return $*$*(3-2*$)},n=(L,B,k)=>L+(B-L)*k,s=e.eyeM.value+t.y,r=2*lr*s+t.x**2+s**2+t.z**2,o=r/(Math.sqrt(lr**2+r)+lr),c=(o-e.baseM.value)/e.thicknessM.value,l=e.localSize.value.x>0;if(c<=0||c>=1||e.coverage.value<=0&&!l)return 0;const h=(L,B,k)=>{const $=t.x+e.offsetM.value.x-L.x,tt=t.z+e.offsetM.value.z-L.z,J=Math.cos(k),it=Math.sin(k);return Math.hypot((J*$-it*tt)/(B.x*.5),(o-L.y)/(B.y*.5),(it*$+J*tt)/(B.z*.5))},u=l?h(e.localCenter.value,e.localSize.value,e.localRotation.value):0;if(u>1.3)return 0;const d=[t.x,t.y,t.z].map((L,B)=>(L+e.offsetM.value.getComponent(B))/(e.sizeM.value*4)+e.seedOffset.value.getComponent(B)),f=e.noiseMap.value.image.data,p=(L,B,k)=>{const $=[L,B,k].map(at=>(at%1+1)%1*ui-.5),tt=$.map(Math.floor),J=$.map((at,Xt)=>at-tt[Xt]);let it=0;for(let at=0;at<2;at++)for(let Xt=0;Xt<2;Xt++)for(let ee=0;ee<2;ee++){const Kt=(tt[0]+ee+ui)%ui,q=(tt[1]+Xt+ui)%ui,rt=(tt[2]+at+ui)%ui;it+=f[Kt+ui*(q+ui*rt)]/255*(ee?J[0]:1-J[0])*(Xt?J[1]:1-J[1])*(at?J[2]:1-J[2])}return it},v=[d[0]*.173,pu,d[2]*.173];d[0]+=(p(v[0]+.13,v[1]+.27,v[2]+.41)-.5)*1.3,d[2]+=(p(v[0]+.67,v[1]+.53,v[2]+.19)-.5)*1.3;const m=(d[0]*.731+d[2]*.682)*1.371,g=(-d[0]*.682+d[2]*.731)*1.371;let S=i(.2,.8,p(d[0],pu,d[2])*.65+p(m,pu+.37,g)*.35);const x=i(8e3,4e4,Math.hypot(t.x,t.y,t.z)),M=n(p(d[0]*2,d[1]*3,d[2]*2),.5,x),b=n(p(d[0]*7,d[1]*7,d[2]*7),.5,x);let w=Jl.thresholdFor(e.coverage.value),T=1,y=0;if(l){const L=u+(M-.5)*.18;y=1-i(.35,1,L),T=1-i(.85,1.15,L),S=n(S,1,y),w=Math.min(w,Jl.thresholdFor(.5))}for(let L=0;L<e.holeCount.value;L++)T*=i(.85,1.15,h(e.holeCenter.value[L],e.holeSize.value[L],e.holeRotation.value[L])+(M-.5)*.18);if(T<.001)return 0;const A=(1-e.flatness.value)*.3*c*c;let C=i(w-.1+A,w+.1+A,S+(M-.5)*.12*c);if(C=n(C,1,i(.92,1,e.coverage.value)),C=n(C,Math.max(e.coverage.value,y),x),C<.001)return 0;const I=n(.45+.55*M,.96,e.flatness.value),P=i(0,.09,c)*(1-i(I-.22,I,c)),V=n(Math.max(0,C-(1-M)*.38-(1-b)*.1),C*.8,e.flatness.value),X=n(1-x,1,i(.5,.92,e.coverage.value));return P*V*e.density.value*T*X}transmissionAt(t,e=1/0){const i=this.uniforms,n=sw(t.y,i.eyeM.value,i.baseM.value,i.thicknessM.value);if(!n)return 1;let[s,r]=n;if(i.localSize.value.x>0){const h=i.localCenter.value.clone().sub(i.offsetM.value);h.y-=i.eyeM.value+(h.x**2+h.z**2)/(2*lr);const u=i.localSize.value.length()*.5+25,d=t.x*h.x+t.y*h.y+t.z*h.z,f=d*d-h.lengthSq()+u*u;if(f<0)return 1;s=Math.max(s,d-Math.sqrt(f)),r=Math.min(r,d+Math.sqrt(f))}const o=Math.min(r,e,s+18e3);if(o<=s)return 1;const c=(o-s)/48;let l=1;for(let h=0;h<48;h++){const u=s+(h+.5)*c;if(l*=Math.exp(-this.densityAt({x:t.x*u,y:t.y*u,z:t.z*u})*c*.006),l<.015)break}return l}dispose(){this.mesh.removeFromParent(),this.mesh.geometry.dispose(),this.mesh.material.dispose()}}class vi{static VIOLET_NM=400;static DEEP_RED_NM=700;static SAMPLES=vi.build(24);static build(t){const e=[];let i=0,n=0,s=0;for(let r=0;r<t;r++){const o=vi.VIOLET_NM+(r+.5)/t*(vi.DEEP_RED_NM-vi.VIOLET_NM),[c,l,h]=vi.colourMatching(o),u={wavelengthNm:o,r:Math.max(0,3.2406*c-1.5372*l-.4986*h),g:Math.max(0,-.9689*c+1.8758*l+.0415*h),b:Math.max(0,.0557*c-.204*l+1.057*h)};i+=u.r,n+=u.g,s+=u.b,e.push(u)}for(const r of e)r.r/=i,r.g/=n,r.b/=s;return e}static tristimulus(t,e,i){let n=0,s=0,r=0;for(let c=0;c<t.length;c++){const[l,h,u]=vi.colourMatching(t[c]);n+=l*e[c],s+=h*e[c],r+=u*e[c]}const o=683*i;return[n*o,s*o,r*o]}static scotopic(t){const e=t/1e3;return .992*Math.exp(-321.9*(e-.5)**2)}static linearSrgbOf([t,e,i]){return[3.2406*t-1.5372*e-.4986*i,-.9689*t+1.8758*e+.0415*i,.0557*t-.204*e+1.057*i]}static colourMatching(t){const e=(i,n,s)=>{const r=(t-i)/(t<i?n:s);return Math.exp(-.5*r*r)};return[1.056*e(599.8,37.9,31)+.362*e(442,16,26.7)-.065*e(501.1,20.4,26.2),.821*e(568.8,46.9,40.5)+.286*e(530.9,16.3,31.1),1.217*e(437,11.8,36)+.681*e(459,26,13.8)]}}class jl{static reflectance(t,e,i){const s=e/i*Math.sqrt(Math.max(0,1-t*t));if(s>=1)return 1;const r=Math.sqrt(Math.max(0,1-s*s)),o=(i*t-e*r)/(i*t+e*r),c=(e*t-i*r)/(e*t+i*r);return(o*o+c*c)/2}}class bi{static RED_NM=656.3;static BLUE_NM=435.8;static ANCHOR_RED=1.3312;static ANCHOR_BLUE=1.3404;static B=(bi.ANCHOR_BLUE-bi.ANCHOR_RED)/(1/(bi.BLUE_NM*bi.BLUE_NM)-1/(bi.RED_NM*bi.RED_NM));static A=bi.ANCHOR_RED-bi.B/(bi.RED_NM*bi.RED_NM);static indexAt(t){return bi.A+bi.B/(t*t)}}class Ga{static MAX_CHORDS=4;index=1.333;set refractiveIndex(t){this.index=t}trace(t,e){const i=Math.min(1,Math.max(0,t)),n=Math.sqrt(Math.max(0,1-i*i)),s=i/this.index,r=Math.sqrt(Math.max(0,1-s*s)),o=Math.asin(i),c=Math.asin(s),l=jl.reflectance(n,1,this.index);let h=0;e[h].chords=0,e[h].scatteringAngle=Ga.folded(Math.PI-2*o),e[h].weight=l,h++;const u=jl.reflectance(r,this.index,1);let d=1-l;for(let f=1;f<=Ga.MAX_CHORDS&&h<e.length;f++){const p=2*(o-c)+(f-1)*(Math.PI-2*c);e[h].chords=f,e[h].scatteringAngle=Ga.folded(p),e[h].weight=d*(1-u),h++,d*=u}return h}static folded(t){const e=2*Math.PI;let i=t%e;return i<0&&(i+=e),i>Math.PI?e-i:i}}class hi{static BINS=1800;static SOURCE_RADIUS_DEG=.265;static FULL_UNTIL_DEG=60;static FADED_BY_DEG=90;static IMPACT_STEPS=4096;drop=new Ga;previous=hi.emergences();current=hi.emergences();tally=new Float32Array(hi.BINS*3);radiance=new Float32Array(hi.BINS*3);scratch=new Float32Array(hi.BINS*3);static emergences(){return Array.from({length:Ga.MAX_CHORDS+1},()=>({chords:0,scatteringAngle:0,weight:0}))}compute(){this.tally.fill(0);for(const t of vi.SAMPLES)this.sweep(t);return this.toRadiance(),this.blurBySourceDisc(),{bins:hi.BINS,data:this.radiance,binDeg:180/hi.BINS}}sweep(t){this.drop.refractiveIndex=bi.indexAt(t.wavelengthNm);const e=hi.IMPACT_STEPS;let i=this.drop.trace(0,this.previous);const n=1/e;for(let s=1;s<=e;s++){const r=this.drop.trace(Math.sqrt(s/e),this.current);for(let o=0;o<Math.min(r,i);o++){const c=this.previous[o],l=this.current[o];c.chords===l.chords&&this.deposit(c.scatteringAngle,l.scatteringAngle,(c.weight+l.weight)/2*n,t)}i=r,this.copyInto(this.current,this.previous)}}copyInto(t,e){for(let i=0;i<t.length;i++)e[i].chords=t[i].chords,e[i].scatteringAngle=t[i].scatteringAngle,e[i].weight=t[i].weight}deposit(t,e,i,n){if(i<=0)return;const s=hi.BINS,r=Math.PI/s,o=Math.min(t,e),c=Math.max(t,e),l=c-o,h=Math.min(s-1,Math.max(0,Math.floor(o/r))),u=Math.min(s-1,Math.max(0,Math.floor(c/r)));if(l<=0||h===u){this.add(h,i,n);return}for(let d=h;d<=u;d++){const f=Math.min(c,(d+1)*r)-Math.max(o,d*r);f>0&&this.add(d,i*f/l,n)}}add(t,e,i){const n=t*3,s=e*vi.SAMPLES.length;this.tally[n]+=s*i.r,this.tally[n+1]+=s*i.g,this.tally[n+2]+=s*i.b}toRadiance(){const t=hi.BINS,e=Math.PI/t;for(let i=0;i<t;i++){const n=2*Math.PI*(Math.cos(i*e)-Math.cos((i+1)*e)),s=n>0?this.backwardShare((i+.5)*(180/t))/n:0,r=i*3;this.radiance[r]=this.tally[r]*s,this.radiance[r+1]=this.tally[r+1]*s,this.radiance[r+2]=this.tally[r+2]*s}}backwardShare(t){const e=180-t;if(e<=hi.FULL_UNTIL_DEG)return 1;if(e>=hi.FADED_BY_DEG)return 0;const i=(e-hi.FULL_UNTIL_DEG)/(hi.FADED_BY_DEG-hi.FULL_UNTIL_DEG);return Math.cos(i*Math.PI/2)**2}blurBySourceDisc(){const t=hi.BINS,e=hi.SOURCE_RADIUS_DEG*t/180,i=Math.max(1,Math.ceil(e)),n=[];let s=0;for(let r=-i;r<=i;r++){const o=Math.max(0,e*e-r*r),c=Math.sqrt(o);n.push(c),s+=c}if(!(s<=0)){this.scratch.set(this.radiance);for(let r=0;r<t;r++){let o=0,c=0,l=0;for(let u=-i;u<=i;u++){const d=Math.min(t-1,Math.max(0,r+u))*3,f=n[u+i];o+=this.scratch[d]*f,c+=this.scratch[d+1]*f,l+=this.scratch[d+2]*f}const h=r*3;this.radiance[h]=o/s,this.radiance[h+1]=c/s,this.radiance[h+2]=l/s}}}}class Nr{static RADIUS=880;static RENDER_ORDER=5.5;static GAIN=.22;static MOON_SATURATION=.15;object;material;sky=new hi;texture;texels;computed=!1;constructor(){this.texels=new Uint16Array(hi.BINS*4),this.texture=new Mr(this.texels,hi.BINS,1,Di,$e),this.texture.minFilter=le,this.texture.magFilter=le,this.texture.wrapS=Ri,this.texture.wrapT=Ri,this.texture.needsUpdate=!0,this.material=new fe({uniforms:{uSource:{value:new R(0,1,0)},uStrength:{value:0},uTint:{value:new R(1,1,1)},uSaturation:{value:1},uProfile:{value:this.texture},uGain:{value:Nr.GAIN}},vertexShader:`
6053
6053
  varying vec3 vDirection;
6054
6054
  void main() {
6055
6055
  vDirection = normalize((modelMatrix * vec4(position, 1.0)).xyz - cameraPosition);
@@ -6193,7 +6193,7 @@ vec3 finish(vec3 relative, vec4 overlay) {
6193
6193
  vUv = position.xy * 0.5 + 0.5;
6194
6194
  gl_Position = vec4(position.xy, 0.0, 1.0);
6195
6195
  }
6196
- `;this.addMaterial=new de({uniforms:{uSource:{value:this.frame.scene.texture},uShare:{value:1}},vertexShader:n,fragmentShader:`
6196
+ `;this.addMaterial=new fe({uniforms:{uSource:{value:this.frame.scene.texture},uShare:{value:1}},vertexShader:n,fragmentShader:`
6197
6197
  precision highp float;
6198
6198
  varying vec2 vUv;
6199
6199
  uniform sampler2D uSource;
@@ -6202,7 +6202,7 @@ vec3 finish(vec3 relative, vec4 overlay) {
6202
6202
  // Every channel, coverage included: the overlay's is averaged over the pose like its colour.
6203
6203
  gl_FragColor = texture2D(uSource, vUv) * uShare;
6204
6204
  }
6205
- `,blending:dc,blendSrc:ic,blendDst:ic,depthTest:!1,depthWrite:!1}),this.developMaterial=new de({uniforms:{...Yi,uFilm:{value:this.film.scene.texture},uOverlay:{value:this.film.overlay.texture},uGain:{value:1}},vertexShader:n,fragmentShader:`
6205
+ `,blending:dc,blendSrc:ic,blendDst:ic,depthTest:!1,depthWrite:!1}),this.developMaterial=new fe({uniforms:{...Yi,uFilm:{value:this.film.scene.texture},uOverlay:{value:this.film.overlay.texture},uGain:{value:1}},vertexShader:n,fragmentShader:`
6206
6206
  precision highp float;
6207
6207
  ${Wa}
6208
6208
  varying vec2 vUv;
@@ -6318,7 +6318,7 @@ void main() {`).replace(os.ANCHOR,`float sigma = max(${Dt.MIN_SIGMA_PX.toFixed(2
6318
6318
  float fromCentre = length( gl_PointCoord - vec2( 0.5 ) ) * vRaster;
6319
6319
  if ( fromCentre > ${Dt.EDGE_SIGMAS.toFixed(1)} * sigma ) discard;
6320
6320
  float share = exp( -0.5 * fromCentre * fromCentre / ( sigma * sigma ) ) * vTotal / ( 6.2831853 * sigma * sigma );
6321
- vec4 diffuseColor = vec4( diffuse, opacity * share );`)}static integrateCoverage(){const{core:e,rim:i}=os.FALLOFF;let n=0;for(let s=0;s<2e3;s++){const r=(s+.5)/2e3*i,o=Math.min(Math.max((r-e)/(i-e),0),1),c=1-o*o*(3-2*o);n+=c*2*Math.PI*r*(i/2e3)}return n}}class Ni{static K=10;static FAINTEST=.001;static MAX_RADIUS_DEG=30;mesh;constructor(t){this.mesh=new bt(new Zi(2,2),new de({uniforms:{uColor:{value:new st(0,0,0)},uTanRadius:{value:.1},uSourceDeg:{value:.25},uInnerDeg:{value:0}},vertexShader:Ni.VERTEX,fragmentShader:Ni.FRAGMENT,transparent:!0,depthWrite:!1,depthTest:!1,blending:Ai,fog:!1})),this.mesh.name=t,this.mesh.frustumCulled=!1,this.mesh.visible=!1}static radiusDeg(t){return Math.min(Ni.MAX_RADIUS_DEG,Math.sqrt(Math.max(t,0)/Ni.FAINTEST))}shine(t,e,i,n=0){const s=Ni.K*Math.max(e[0],e[1],e[2]),r=Ni.radiusDeg(s);if(r<=Math.max(i,n)){this.mesh.visible=!1;return}this.mesh.visible=!0,this.mesh.position.set(t.x,t.y,t.z);const o=this.mesh.material.uniforms;o.uColor.value.setRGB(Ni.K*e[0],Ni.K*e[1],Ni.K*e[2]),o.uTanRadius.value=Math.tan(r*Math.PI/180),o.uSourceDeg.value=i,o.uInnerDeg.value=n}hide(){this.mesh.visible=!1}dispose(){this.mesh.geometry.dispose(),this.mesh.material.dispose()}static VERTEX=`
6321
+ vec4 diffuseColor = vec4( diffuse, opacity * share );`)}static integrateCoverage(){const{core:e,rim:i}=os.FALLOFF;let n=0;for(let s=0;s<2e3;s++){const r=(s+.5)/2e3*i,o=Math.min(Math.max((r-e)/(i-e),0),1),c=1-o*o*(3-2*o);n+=c*2*Math.PI*r*(i/2e3)}return n}}class Ni{static K=10;static FAINTEST=.001;static MAX_RADIUS_DEG=30;mesh;constructor(t){this.mesh=new bt(new Zi(2,2),new fe({uniforms:{uColor:{value:new st(0,0,0)},uTanRadius:{value:.1},uSourceDeg:{value:.25},uInnerDeg:{value:0}},vertexShader:Ni.VERTEX,fragmentShader:Ni.FRAGMENT,transparent:!0,depthWrite:!1,depthTest:!1,blending:Ai,fog:!1})),this.mesh.name=t,this.mesh.frustumCulled=!1,this.mesh.visible=!1}static radiusDeg(t){return Math.min(Ni.MAX_RADIUS_DEG,Math.sqrt(Math.max(t,0)/Ni.FAINTEST))}shine(t,e,i,n=0){const s=Ni.K*Math.max(e[0],e[1],e[2]),r=Ni.radiusDeg(s);if(r<=Math.max(i,n)){this.mesh.visible=!1;return}this.mesh.visible=!0,this.mesh.position.set(t.x,t.y,t.z);const o=this.mesh.material.uniforms;o.uColor.value.setRGB(Ni.K*e[0],Ni.K*e[1],Ni.K*e[2]),o.uTanRadius.value=Math.tan(r*Math.PI/180),o.uSourceDeg.value=i,o.uInnerDeg.value=n}hide(){this.mesh.visible=!1}dispose(){this.mesh.geometry.dispose(),this.mesh.material.dispose()}static VERTEX=`
6322
6322
  uniform float uTanRadius;
6323
6323
  varying vec2 vOffset;
6324
6324
  void main() {
@@ -6342,7 +6342,7 @@ void main() {`).replace(os.ANCHOR,`float sigma = max(${Dt.MIN_SIGMA_PX.toFixed(2
6342
6342
  float veil = max(1.0 / (theta * theta) - 1.0 / (edge * edge), 0.0);
6343
6343
  gl_FragColor = vec4(uColor * veil, 1.0);
6344
6344
  }
6345
- `}class Xo{static SAMPLES=4096;static SOURCE_CONE_DEG=1.5;target=new Qe(3,1,{type:Ui,minFilter:Ce,magFilter:Ce,depthBuffer:!1});scene=new ys;camera=new Zn(-1,1,1,-1,0,1);material;reading=!1;constructor(){this.material=new de({uniforms:{uProbe:{value:null},uExcludeA:{value:new ae(0,-1,0,2)},uExcludeB:{value:new ae(0,-1,0,2)}},vertexShader:`
6345
+ `}class Xo{static SAMPLES=4096;static SOURCE_CONE_DEG=1.5;target=new Qe(3,1,{type:Ui,minFilter:Ce,magFilter:Ce,depthBuffer:!1});scene=new ys;camera=new Zn(-1,1,1,-1,0,1);material;reading=!1;constructor(){this.material=new fe({uniforms:{uProbe:{value:null},uExcludeA:{value:new ae(0,-1,0,2)},uExcludeB:{value:new ae(0,-1,0,2)}},vertexShader:`
6346
6346
  void main() { gl_Position = vec4(position.xy, 0.0, 1.0); }
6347
6347
  `,fragmentShader:`
6348
6348
  precision highp float;
@@ -6491,7 +6491,7 @@ void main() {
6491
6491
  float blur = max(vNearBlur, vHaze);
6492
6492
  gl_FragColor = vec4(color, tex.a * uOpacity * vNearFade * (1.0 - blur * ${I5.toFixed(2)}));
6493
6493
  }
6494
- `;function N5(a){let t=a;return function(){t|=0,t=t+1831565813|0;let i=Math.imul(t^t>>>15,1|t);return i=i+Math.imul(i^i>>>7,61|i)^i,((i^i>>>14)>>>0)/4294967296}}const F5=.14,Fm=2.25;let hl;function U5(){if(hl)return hl;const a=128,t=document.createElement("canvas");t.width=a,t.height=a;const e=t.getContext("2d"),i=e.createImageData(a,a),n=a/2,s=a*F5,r=a-s;for(let o=0;o<a;o++)for(let c=0;c<a;c++){const l=c+.5-n,h=o+.5<s?o+.5-s:o+.5>r?o+.5-r:0,u=Math.hypot(l,h),d=Math.exp(-(u*u)/(2*Fm*Fm)),f=(o*a+c)*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,d))}return e.putImageData(i,0,0),hl=new Bs(t),hl}function k5(a){const t=N5(a.seed),e=new Float32Array(a.count*3),i=new Float32Array(a.count),n=a.radiusM;for(let l=0;l<a.count;l++){const h=t()*Math.PI*2,u=Math.sqrt(t())*a.radiusM;e[l*3]=Math.cos(h)*u,e[l*3+1]=t()*a.heightM,e[l*3+2]=Math.sin(h)*u,i[l]=.85+t()*.3}const s=new se;s.setAttribute("position",new Jt(e,3)),s.setAttribute("aSpeed",new Jt(i,1)),s.setDrawRange(0,a.visibleCount);const r={uTime:{value:0},uOverallSpeed:{value:a.overallSpeed},uPixelSize:{value:a.pixelSize},uOpacity:{value:a.opacity},uColor:{value:a.color},uUvSquash:{value:1},uSpeedStreak:{value:a.speedStreak},uWindOffset:{value:new Mt(0,0)},uDropVelocity:{value:new R(0,-1,0)},uAspect:{value:1},uHeight:{value:a.heightM},uBottomY:{value:a.bottomYM},uHalfWidth:{value:n},uTexture:{value:U5()},uNearFocusDistance:{value:a.nearFocusDistanceM},uHazeDistance:{value:a.hazeDistanceM},uHazeColor:{value:a.hazeColor}},o=new de({uniforms:r,vertexShader:L5,fragmentShader:O5,transparent:!0,depthWrite:!1,depthTest:!0}),c=new mn(s,o);return c.frustumCulled=!1,{points:c,uniforms:r}}class Kr{static S10_MAG_PER_ARCSEC2=10+2.5*Math.log10(3600*3600);static toMagPerArcsec2(t){return Kr.S10_MAG_PER_ARCSEC2-2.5*Math.log10(Math.max(t,1e-12))}static fromMagPerArcsec2(t){return 10**(.4*(Kr.S10_MAG_PER_ARCSEC2-t))}static latitudeOfRowCoord(t){const e=2*t-1;return 90*Math.sign(e)*e*e}static rowCoordOfLatitude(t){return(Math.sign(t)*Math.sqrt(Math.min(Math.abs(t),90)/90)+1)/2}static angleOfColumnCoord(t){return 180*t*t}static columnCoordOfAngle(t){return Math.sqrt(Math.min(Math.max(t,0),180)/180)}}class oe{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(t,e){return this.radianceTowards(t,e)*oe.anchor()}static anchor(){return Kr.fromMagPerArcsec2(oe.PEAK_MAG_PER_ARCSEC2)/oe.PEAK_RADIANCE}radianceTowards(t,e){return this.trace(t,e).light}extinctionTowards(t,e){return this.trace(t,e).extinctionMag}trace(t,e){const i=t*Math.PI/180,n=e*Math.PI/180,s=-Math.cos(n)*Math.cos(i),r=Math.cos(n)*Math.sin(i),o=Math.sin(n);let c=0,l=0,h=0;const u=Math.log(oe.NEAR_LIMIT_KPC),d=Math.log(oe.FAR_LIMIT_KPC)-u;for(let f=0;f<oe.STEPS;f++){const p=Math.exp(u+d*f/(oe.STEPS-1)),v=p-h;h=p;const m=p-v/2,g=oe.SUN_RADIUS_KPC+m*s,S=m*r,x=oe.SUN_HEIGHT_KPC+m*o,M=Math.hypot(g,S),b=Math.exp(-(M-oe.SUN_RADIUS_KPC)/oe.DISK_SCALE_LENGTH_KPC-Math.abs(x)/oe.DISK_SCALE_HEIGHT_KPC),w=Math.hypot(M,x/oe.BULGE_FLATTENING),T=oe.BULGE_TO_LOCAL_DISK*Math.exp(-w/oe.BULGE_SCALE_KPC);if(c+=(b+T)*v*10**(-.4*l),l+=oe.EXTINCTION_MAG_PER_KPC*Math.exp(-(M-oe.SUN_RADIUS_KPC)/oe.DUST_SCALE_LENGTH_KPC-(Math.abs(x)-oe.SUN_HEIGHT_KPC)/oe.DUST_SCALE_HEIGHT_KPC)*v,l>oe.OPAQUE_MAG)break}return{light:c,extinctionMag:l}}values=new Float32Array(oe.LONGITUDE_STEPS*oe.LATITUDE_STEPS);walked=0;get done(){return this.walked>=oe.LATITUDE_STEPS}walk(t){const e=oe.LONGITUDE_STEPS,i=Math.min(oe.LATITUDE_STEPS,this.walked+t);for(;this.walked<i;this.walked++){const n=Kr.latitudeOfRowCoord((this.walked+.5)/oe.LATITUDE_STEPS);for(let s=0;s<e;s++)this.values[this.walked*e+s]=this.radianceTowards(360*(s+.5)/e,n)}}harvest(){let t=Number.POSITIVE_INFINITY;for(const n of this.values)n<t&&(t=n);const e=oe.anchor(),i=new Float32Array(this.values.length);for(let n=0;n<i.length;n++)i[n]=(this.values[n]-t)*e;return{width:oe.LONGITUDE_STEPS,height:oe.LATITUDE_STEPS,data:i}}}class Ke{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(t,e){return this.radianceTowards(t,e)*this.anchor()}anchored;anchor(){return this.anchored===void 0&&(this.anchored=Ke.RIGHT_ANGLE_S10/this.radianceTowards(90,0)),this.anchored}radianceTowards(t,e){const i=t*Math.PI/180,n=e*Math.PI/180,s=-Math.cos(n)*Math.cos(i),r=-Math.cos(n)*Math.sin(i),o=Math.sin(n),c=-s;let l=0,h=0;const u=Math.log(Ke.NEAR_LIMIT_AU),d=Math.log(Ke.FAR_LIMIT_AU)-u;for(let f=0;f<Ke.STEPS;f++){const p=Math.exp(u+d*f/(Ke.STEPS-1)),v=p-h;h=p;const m=p-v/2,g=1+m*s,S=m*r,x=m*o,M=Math.hypot(g,S,x);if(M<Ke.SUBLIMATION_AU)continue;const b=x/M,w=M**-1.3*Math.exp(-2.6*Math.abs(b)),T=(c-m)/M;l+=w*this.scattering(T)*v/(M*M)}return l}scattering(t){let e=0;for(let i=0;i<Ke.LOBE_ASYMMETRY.length;i++){const n=Ke.LOBE_ASYMMETRY[i],s=1+n*n-2*n*t;e+=Ke.LOBE_WEIGHT[i]*(1-n*n)/(4*Math.PI*s**1.5)}return e}values=new Float32Array(Ke.LONGITUDE_STEPS*Ke.LATITUDE_STEPS);walked=0;get done(){return this.walked>=Ke.LATITUDE_STEPS}walk(t){const e=Ke.LONGITUDE_STEPS,i=Math.min(Ke.LATITUDE_STEPS,this.walked+t);for(;this.walked<i;this.walked++){const n=Kr.latitudeOfRowCoord((this.walked+.5)/Ke.LATITUDE_STEPS);for(let s=0;s<e;s++){const r=Kr.angleOfColumnCoord((s+.5)/e);this.values[this.walked*e+s]=this.radianceTowards(r,n)}}}harvest(){const t=this.anchor();let e=Number.POSITIVE_INFINITY;for(const n of this.values)n<e&&(e=n);const i=new Float32Array(this.values.length);for(let n=0;n<i.length;n++)i[n]=(this.values[n]-e)*t;return{width:Ke.LONGITUDE_STEPS,height:Ke.LATITUDE_STEPS,data:i}}}class xt{static get NANOLAMBERTS_PER_S10(){return xt.toNanolamberts(10+2.5*Math.log10(3600*3600))}static nanolambertsOfS10(t){return t*xt.NANOLAMBERTS_PER_S10}static TWILIGHT=[{sunAltitudeDeg:90,magPerArcsec2:3.5},{sunAltitudeDeg:10,magPerArcsec2:4.2},{sunAltitudeDeg:0,magPerArcsec2:7.5},...Array.from({length:15},(t,e)=>{const i=-4-e;return{sunAltitudeDeg:i,magPerArcsec2:xt.patatV(i)}}),{sunAltitudeDeg:-24,magPerArcsec2:22}];static patatV(t){const e=90-t-95;return 11.84+1.518*e-.057*e*e}static moonlessMagPerArcsec2(t){const e=xt.TWILIGHT;for(let i=0;i<e.length-1;i++){const n=e[i],s=e[i+1];if(t<=n.sunAltitudeDeg&&t>=s.sunAltitudeDeg){const r=(n.sunAltitudeDeg-t)/(n.sunAltitudeDeg-s.sunAltitudeDeg);return n.magPerArcsec2+(s.magPerArcsec2-n.magPerArcsec2)*r}}return t>0?e[0].magPerArcsec2:e[e.length-1].magPerArcsec2}static toNanolamberts(t){return 34.08*Math.exp(xt.NANOLAMBERT_OFFSET-xt.PER_MAGNITUDE*t)}static fromNanolamberts(t){return(xt.NANOLAMBERT_OFFSET-Math.log(Math.max(t,1e-6)/34.08))/xt.PER_MAGNITUDE}static NANOLAMBERT_OFFSET=20.7233;static PER_MAGNITUDE=Math.LN10/2.5;static airMass(t){const e=Math.cos(Math.max(t,0)*Math.PI/180);return 1/Math.sqrt(Math.max(1-.96*e*e,.001))}static EXTINCTION_PER_AIR_MASS=.172;static scatteringAt(t){const e=Math.min(Math.max(t,0),180)*Math.PI/180;return 10**5.36*(1.06+Math.cos(e)**2)+10**(6.15-Math.min(t,180)/40)}static scatteredFraction(t){return 1-10**(-.4*xt.EXTINCTION_PER_AIR_MASS*xt.airMass(t))}static AIRGLOW_MAG_PER_ARCSEC2=22;static twilightExcessNanolamberts(t){return Math.max(0,xt.toNanolamberts(xt.moonlessMagPerArcsec2(t))-xt.toNanolamberts(xt.AIRGLOW_MAG_PER_ARCSEC2))}static twilightOutput(t){const e=xt.scatteringAt(90-t)*xt.scatteredFraction(90);return xt.twilightExcessNanolamberts(t)/e}static moonNanolamberts(t,e,i,n){return xt.scatteringAt(i)*xt.moonOutput(t,e)*xt.scatteredFraction(n)}static moonOutput(t,e){if(e<=0)return 0;const i=Math.min(Math.abs(t),180);return 10**(-.4*(3.84+.026*i+4e-9*i**4))*10**(-.4*xt.EXTINCTION_PER_AIR_MASS*xt.airMass(e))}static phaseAngleOf(t){return Math.acos(Math.min(Math.max(2*t-1,-1),1))*180/Math.PI}static magPerArcsec2(t,e,i,n){const s=xt.scatteredFraction(i),r=xt.scatteringAt(t.separationDeg)*xt.twilightOutput(t.altitudeDeg)*s,o=xt.scatteringAt(e.separationDeg)*xt.moonOutput(e.phaseAngleDeg,e.altitudeDeg)*s;return xt.fromNanolamberts(xt.toNanolamberts(xt.AIRGLOW_MAG_PER_ARCSEC2)+r+o+xt.artificialNanolamberts(n,i))}static artificialZenithNanolamberts(t){return t===void 0||!Number.isFinite(t)?0:Math.max(0,xt.toNanolamberts(t)-xt.toNanolamberts(xt.AIRGLOW_MAG_PER_ARCSEC2))}static artificialNanolamberts(t,e){const i=xt.artificialZenithNanolamberts(t);return i>0?i*xt.artificialShape(e):0}static artificialShape(t){return xt.scatteredFraction(t)/xt.scatteredFraction(90)}static nakedEyeLimit(t){return 7.93-5*Math.log10(10**(4.316-t/5)+1)}static starLossMagnitudes(t,e,i){const n=xt.moonlessMagPerArcsec2(t),s=xt.fromNanolamberts(xt.toNanolamberts(n)+xt.scatteringAt(90-e.altitudeDeg)*xt.moonOutput(e.phaseAngleDeg,e.altitudeDeg)*xt.scatteredFraction(90)+xt.artificialZenithNanolamberts(i));return Math.max(0,xt.nakedEyeLimit(n)-xt.nakedEyeLimit(s))}}class nh{static HALF_FLOAT_MAX=65504;static fromMap(t,e){const i=Ln.toHalfFloat(1);for(let n=0;n<t.data.length;n++)e[n*4]=Ln.toHalfFloat(Math.min(nh.HALF_FLOAT_MAX,xt.nanolambertsOfS10(t.data[n]))),e[n*4+3]=i}}class or{static pool=typeof Worker>"u"?null:void 0;static with(t,e){const i=or.pool;if(i===null){e();return}if(i){t(i);return}$i(async()=>{const{OffThreadTracer:n}=await import("./OffThreadTracer-z-qdZ_d-.js");return{OffThreadTracer:n}},[],import.meta.url).then(({OffThreadTracer:n})=>{or.pool=n.get(),or.pool?t(or.pool):e()},()=>{or.pool=null,e()})}}class ir{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=Yo.shared;milkyWayTexture;zodiacalTexture;milkyWayTexels;zodiacalTexels;repaint;constructor(){this.milkyWayTexels=this.maps.milkyWayTexels,this.milkyWayTexture=ir.buildTexture(this.milkyWayTexels,oe.LONGITUDE_STEPS,oe.LATITUDE_STEPS,sc),this.zodiacalTexels=this.maps.zodiacalTexels,this.zodiacalTexture=ir.buildTexture(this.zodiacalTexels,Ke.LONGITUDE_STEPS,Ke.LATITUDE_STEPS,Ri),this.material=new de({uniforms:{uMilkyWay:{value:this.milkyWayTexture},uZodiacal:{value:this.zodiacalTexture},uGalactic:{value:new $t},uEclipticPole:{value:new R(0,1,0)},uSunLongitude:{value:new R(1,0,0)},uMoonDirection:{value:new R(0,-1,0)},uMoonOutput:{value:0},uSunDirection:{value:new R(0,-1,0)},uTwilightOutput:{value:0},uAirglowNanolamberts:{value:xt.toNanolamberts(xt.AIRGLOW_MAG_PER_ARCSEC2)},uArtificialNanolamberts:{value:0},uSkyColor:{value:new R(0,0,0)},uMilkyWayTint:{value:new R(...ir.MILKY_WAY_TINT)},uZodiacalTint:{value:new R(...ir.ZODIACAL_TINT)},uReady:{value:0},uEncodeDestination:{value:1}},vertexShader:`
6494
+ `;function N5(a){let t=a;return function(){t|=0,t=t+1831565813|0;let i=Math.imul(t^t>>>15,1|t);return i=i+Math.imul(i^i>>>7,61|i)^i,((i^i>>>14)>>>0)/4294967296}}const F5=.14,Fm=2.25;let hl;function U5(){if(hl)return hl;const a=128,t=document.createElement("canvas");t.width=a,t.height=a;const e=t.getContext("2d"),i=e.createImageData(a,a),n=a/2,s=a*F5,r=a-s;for(let o=0;o<a;o++)for(let c=0;c<a;c++){const l=c+.5-n,h=o+.5<s?o+.5-s:o+.5>r?o+.5-r:0,u=Math.hypot(l,h),d=Math.exp(-(u*u)/(2*Fm*Fm)),f=(o*a+c)*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,d))}return e.putImageData(i,0,0),hl=new Bs(t),hl}function k5(a){const t=N5(a.seed),e=new Float32Array(a.count*3),i=new Float32Array(a.count),n=a.radiusM;for(let l=0;l<a.count;l++){const h=t()*Math.PI*2,u=Math.sqrt(t())*a.radiusM;e[l*3]=Math.cos(h)*u,e[l*3+1]=t()*a.heightM,e[l*3+2]=Math.sin(h)*u,i[l]=.85+t()*.3}const s=new se;s.setAttribute("position",new Jt(e,3)),s.setAttribute("aSpeed",new Jt(i,1)),s.setDrawRange(0,a.visibleCount);const r={uTime:{value:0},uOverallSpeed:{value:a.overallSpeed},uPixelSize:{value:a.pixelSize},uOpacity:{value:a.opacity},uColor:{value:a.color},uUvSquash:{value:1},uSpeedStreak:{value:a.speedStreak},uWindOffset:{value:new Mt(0,0)},uDropVelocity:{value:new R(0,-1,0)},uAspect:{value:1},uHeight:{value:a.heightM},uBottomY:{value:a.bottomYM},uHalfWidth:{value:n},uTexture:{value:U5()},uNearFocusDistance:{value:a.nearFocusDistanceM},uHazeDistance:{value:a.hazeDistanceM},uHazeColor:{value:a.hazeColor}},o=new fe({uniforms:r,vertexShader:L5,fragmentShader:O5,transparent:!0,depthWrite:!1,depthTest:!0}),c=new mn(s,o);return c.frustumCulled=!1,{points:c,uniforms:r}}class Kr{static S10_MAG_PER_ARCSEC2=10+2.5*Math.log10(3600*3600);static toMagPerArcsec2(t){return Kr.S10_MAG_PER_ARCSEC2-2.5*Math.log10(Math.max(t,1e-12))}static fromMagPerArcsec2(t){return 10**(.4*(Kr.S10_MAG_PER_ARCSEC2-t))}static latitudeOfRowCoord(t){const e=2*t-1;return 90*Math.sign(e)*e*e}static rowCoordOfLatitude(t){return(Math.sign(t)*Math.sqrt(Math.min(Math.abs(t),90)/90)+1)/2}static angleOfColumnCoord(t){return 180*t*t}static columnCoordOfAngle(t){return Math.sqrt(Math.min(Math.max(t,0),180)/180)}}class oe{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(t,e){return this.radianceTowards(t,e)*oe.anchor()}static anchor(){return Kr.fromMagPerArcsec2(oe.PEAK_MAG_PER_ARCSEC2)/oe.PEAK_RADIANCE}radianceTowards(t,e){return this.trace(t,e).light}extinctionTowards(t,e){return this.trace(t,e).extinctionMag}trace(t,e){const i=t*Math.PI/180,n=e*Math.PI/180,s=-Math.cos(n)*Math.cos(i),r=Math.cos(n)*Math.sin(i),o=Math.sin(n);let c=0,l=0,h=0;const u=Math.log(oe.NEAR_LIMIT_KPC),d=Math.log(oe.FAR_LIMIT_KPC)-u;for(let f=0;f<oe.STEPS;f++){const p=Math.exp(u+d*f/(oe.STEPS-1)),v=p-h;h=p;const m=p-v/2,g=oe.SUN_RADIUS_KPC+m*s,S=m*r,x=oe.SUN_HEIGHT_KPC+m*o,M=Math.hypot(g,S),b=Math.exp(-(M-oe.SUN_RADIUS_KPC)/oe.DISK_SCALE_LENGTH_KPC-Math.abs(x)/oe.DISK_SCALE_HEIGHT_KPC),w=Math.hypot(M,x/oe.BULGE_FLATTENING),T=oe.BULGE_TO_LOCAL_DISK*Math.exp(-w/oe.BULGE_SCALE_KPC);if(c+=(b+T)*v*10**(-.4*l),l+=oe.EXTINCTION_MAG_PER_KPC*Math.exp(-(M-oe.SUN_RADIUS_KPC)/oe.DUST_SCALE_LENGTH_KPC-(Math.abs(x)-oe.SUN_HEIGHT_KPC)/oe.DUST_SCALE_HEIGHT_KPC)*v,l>oe.OPAQUE_MAG)break}return{light:c,extinctionMag:l}}values=new Float32Array(oe.LONGITUDE_STEPS*oe.LATITUDE_STEPS);walked=0;get done(){return this.walked>=oe.LATITUDE_STEPS}walk(t){const e=oe.LONGITUDE_STEPS,i=Math.min(oe.LATITUDE_STEPS,this.walked+t);for(;this.walked<i;this.walked++){const n=Kr.latitudeOfRowCoord((this.walked+.5)/oe.LATITUDE_STEPS);for(let s=0;s<e;s++)this.values[this.walked*e+s]=this.radianceTowards(360*(s+.5)/e,n)}}harvest(){let t=Number.POSITIVE_INFINITY;for(const n of this.values)n<t&&(t=n);const e=oe.anchor(),i=new Float32Array(this.values.length);for(let n=0;n<i.length;n++)i[n]=(this.values[n]-t)*e;return{width:oe.LONGITUDE_STEPS,height:oe.LATITUDE_STEPS,data:i}}}class Ke{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(t,e){return this.radianceTowards(t,e)*this.anchor()}anchored;anchor(){return this.anchored===void 0&&(this.anchored=Ke.RIGHT_ANGLE_S10/this.radianceTowards(90,0)),this.anchored}radianceTowards(t,e){const i=t*Math.PI/180,n=e*Math.PI/180,s=-Math.cos(n)*Math.cos(i),r=-Math.cos(n)*Math.sin(i),o=Math.sin(n),c=-s;let l=0,h=0;const u=Math.log(Ke.NEAR_LIMIT_AU),d=Math.log(Ke.FAR_LIMIT_AU)-u;for(let f=0;f<Ke.STEPS;f++){const p=Math.exp(u+d*f/(Ke.STEPS-1)),v=p-h;h=p;const m=p-v/2,g=1+m*s,S=m*r,x=m*o,M=Math.hypot(g,S,x);if(M<Ke.SUBLIMATION_AU)continue;const b=x/M,w=M**-1.3*Math.exp(-2.6*Math.abs(b)),T=(c-m)/M;l+=w*this.scattering(T)*v/(M*M)}return l}scattering(t){let e=0;for(let i=0;i<Ke.LOBE_ASYMMETRY.length;i++){const n=Ke.LOBE_ASYMMETRY[i],s=1+n*n-2*n*t;e+=Ke.LOBE_WEIGHT[i]*(1-n*n)/(4*Math.PI*s**1.5)}return e}values=new Float32Array(Ke.LONGITUDE_STEPS*Ke.LATITUDE_STEPS);walked=0;get done(){return this.walked>=Ke.LATITUDE_STEPS}walk(t){const e=Ke.LONGITUDE_STEPS,i=Math.min(Ke.LATITUDE_STEPS,this.walked+t);for(;this.walked<i;this.walked++){const n=Kr.latitudeOfRowCoord((this.walked+.5)/Ke.LATITUDE_STEPS);for(let s=0;s<e;s++){const r=Kr.angleOfColumnCoord((s+.5)/e);this.values[this.walked*e+s]=this.radianceTowards(r,n)}}}harvest(){const t=this.anchor();let e=Number.POSITIVE_INFINITY;for(const n of this.values)n<e&&(e=n);const i=new Float32Array(this.values.length);for(let n=0;n<i.length;n++)i[n]=(this.values[n]-e)*t;return{width:Ke.LONGITUDE_STEPS,height:Ke.LATITUDE_STEPS,data:i}}}class xt{static get NANOLAMBERTS_PER_S10(){return xt.toNanolamberts(10+2.5*Math.log10(3600*3600))}static nanolambertsOfS10(t){return t*xt.NANOLAMBERTS_PER_S10}static TWILIGHT=[{sunAltitudeDeg:90,magPerArcsec2:3.5},{sunAltitudeDeg:10,magPerArcsec2:4.2},{sunAltitudeDeg:0,magPerArcsec2:7.5},...Array.from({length:15},(t,e)=>{const i=-4-e;return{sunAltitudeDeg:i,magPerArcsec2:xt.patatV(i)}}),{sunAltitudeDeg:-24,magPerArcsec2:22}];static patatV(t){const e=90-t-95;return 11.84+1.518*e-.057*e*e}static moonlessMagPerArcsec2(t){const e=xt.TWILIGHT;for(let i=0;i<e.length-1;i++){const n=e[i],s=e[i+1];if(t<=n.sunAltitudeDeg&&t>=s.sunAltitudeDeg){const r=(n.sunAltitudeDeg-t)/(n.sunAltitudeDeg-s.sunAltitudeDeg);return n.magPerArcsec2+(s.magPerArcsec2-n.magPerArcsec2)*r}}return t>0?e[0].magPerArcsec2:e[e.length-1].magPerArcsec2}static toNanolamberts(t){return 34.08*Math.exp(xt.NANOLAMBERT_OFFSET-xt.PER_MAGNITUDE*t)}static fromNanolamberts(t){return(xt.NANOLAMBERT_OFFSET-Math.log(Math.max(t,1e-6)/34.08))/xt.PER_MAGNITUDE}static NANOLAMBERT_OFFSET=20.7233;static PER_MAGNITUDE=Math.LN10/2.5;static airMass(t){const e=Math.cos(Math.max(t,0)*Math.PI/180);return 1/Math.sqrt(Math.max(1-.96*e*e,.001))}static EXTINCTION_PER_AIR_MASS=.172;static scatteringAt(t){const e=Math.min(Math.max(t,0),180)*Math.PI/180;return 10**5.36*(1.06+Math.cos(e)**2)+10**(6.15-Math.min(t,180)/40)}static scatteredFraction(t){return 1-10**(-.4*xt.EXTINCTION_PER_AIR_MASS*xt.airMass(t))}static AIRGLOW_MAG_PER_ARCSEC2=22;static twilightExcessNanolamberts(t){return Math.max(0,xt.toNanolamberts(xt.moonlessMagPerArcsec2(t))-xt.toNanolamberts(xt.AIRGLOW_MAG_PER_ARCSEC2))}static twilightOutput(t){const e=xt.scatteringAt(90-t)*xt.scatteredFraction(90);return xt.twilightExcessNanolamberts(t)/e}static moonNanolamberts(t,e,i,n){return xt.scatteringAt(i)*xt.moonOutput(t,e)*xt.scatteredFraction(n)}static moonOutput(t,e){if(e<=0)return 0;const i=Math.min(Math.abs(t),180);return 10**(-.4*(3.84+.026*i+4e-9*i**4))*10**(-.4*xt.EXTINCTION_PER_AIR_MASS*xt.airMass(e))}static phaseAngleOf(t){return Math.acos(Math.min(Math.max(2*t-1,-1),1))*180/Math.PI}static magPerArcsec2(t,e,i,n){const s=xt.scatteredFraction(i),r=xt.scatteringAt(t.separationDeg)*xt.twilightOutput(t.altitudeDeg)*s,o=xt.scatteringAt(e.separationDeg)*xt.moonOutput(e.phaseAngleDeg,e.altitudeDeg)*s;return xt.fromNanolamberts(xt.toNanolamberts(xt.AIRGLOW_MAG_PER_ARCSEC2)+r+o+xt.artificialNanolamberts(n,i))}static artificialZenithNanolamberts(t){return t===void 0||!Number.isFinite(t)?0:Math.max(0,xt.toNanolamberts(t)-xt.toNanolamberts(xt.AIRGLOW_MAG_PER_ARCSEC2))}static artificialNanolamberts(t,e){const i=xt.artificialZenithNanolamberts(t);return i>0?i*xt.artificialShape(e):0}static artificialShape(t){return xt.scatteredFraction(t)/xt.scatteredFraction(90)}static nakedEyeLimit(t){return 7.93-5*Math.log10(10**(4.316-t/5)+1)}static starLossMagnitudes(t,e,i){const n=xt.moonlessMagPerArcsec2(t),s=xt.fromNanolamberts(xt.toNanolamberts(n)+xt.scatteringAt(90-e.altitudeDeg)*xt.moonOutput(e.phaseAngleDeg,e.altitudeDeg)*xt.scatteredFraction(90)+xt.artificialZenithNanolamberts(i));return Math.max(0,xt.nakedEyeLimit(n)-xt.nakedEyeLimit(s))}}class nh{static HALF_FLOAT_MAX=65504;static fromMap(t,e){const i=Ln.toHalfFloat(1);for(let n=0;n<t.data.length;n++)e[n*4]=Ln.toHalfFloat(Math.min(nh.HALF_FLOAT_MAX,xt.nanolambertsOfS10(t.data[n]))),e[n*4+3]=i}}class or{static pool=typeof Worker>"u"?null:void 0;static with(t,e){const i=or.pool;if(i===null){e();return}if(i){t(i);return}$i(async()=>{const{OffThreadTracer:n}=await import("./OffThreadTracer-z-qdZ_d-.js");return{OffThreadTracer:n}},[],import.meta.url).then(({OffThreadTracer:n})=>{or.pool=n.get(),or.pool?t(or.pool):e()},()=>{or.pool=null,e()})}}class ir{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=Yo.shared;milkyWayTexture;zodiacalTexture;milkyWayTexels;zodiacalTexels;repaint;constructor(){this.milkyWayTexels=this.maps.milkyWayTexels,this.milkyWayTexture=ir.buildTexture(this.milkyWayTexels,oe.LONGITUDE_STEPS,oe.LATITUDE_STEPS,sc),this.zodiacalTexels=this.maps.zodiacalTexels,this.zodiacalTexture=ir.buildTexture(this.zodiacalTexels,Ke.LONGITUDE_STEPS,Ke.LATITUDE_STEPS,Ri),this.material=new fe({uniforms:{uMilkyWay:{value:this.milkyWayTexture},uZodiacal:{value:this.zodiacalTexture},uGalactic:{value:new $t},uEclipticPole:{value:new R(0,1,0)},uSunLongitude:{value:new R(1,0,0)},uMoonDirection:{value:new R(0,-1,0)},uMoonOutput:{value:0},uSunDirection:{value:new R(0,-1,0)},uTwilightOutput:{value:0},uAirglowNanolamberts:{value:xt.toNanolamberts(xt.AIRGLOW_MAG_PER_ARCSEC2)},uArtificialNanolamberts:{value:0},uSkyColor:{value:new R(0,0,0)},uMilkyWayTint:{value:new R(...ir.MILKY_WAY_TINT)},uZodiacalTint:{value:new R(...ir.ZODIACAL_TINT)},uReady:{value:0},uEncodeDestination:{value:1}},vertexShader:`
6495
6495
  varying vec3 vDirection;
6496
6496
  void main() {
6497
6497
  vDirection = normalize((modelMatrix * vec4(position, 1.0)).xyz - cameraPosition);
@@ -7055,9 +7055,9 @@ void main()
7055
7055
  // stays what it always was for the optional artifacts.
7056
7056
  gl_FragColor = vec4(dazzle + artifactsContribution * uOpacity, 1.0);
7057
7057
  }
7058
- `;let ul;function H5(){if(ul)return ul;const a=256,t=document.createElement("canvas");t.width=a,t.height=a;const e=t.getContext("2d");e.fillStyle="rgba(60,60,60,1)",e.fillRect(0,0,a,a);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,o]of i){const c=e.createRadialGradient(n*a,s*a,0,n*a,s*a,r*a);c.addColorStop(0,`rgba(200,200,200,${o})`),c.addColorStop(1,"rgba(200,200,200,0)"),e.fillStyle=c,e.fillRect(0,0,a,a)}return ul=new Bs(t),ul}function G5(){const a={uTime:{value:0},uResolution:{value:new Mt(1,1)},uLensPosition:{value:new Mt(0,0)},uColorGain:{value:new st(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 st(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:H5()}},t=new de({uniforms:a,vertexShader:z5,fragmentShader:B5,transparent:!0,depthWrite:!1,depthTest:!1,blending:Ai,fog:!1,name:"LensFlareShader"}),e=new bt(new Zi(2,2),t);return e.frustumCulled=!1,e.renderOrder=20,{mesh:e,uniforms:a}}class On{static material(){return new _n({vertexColors:!0,transparent:!0,blending:Ai,depthWrite:!1,fog:!1,side:xn})}static track(t){t.userData.skyRibbon=!0}static twins=new WeakMap;static outputMaterial(t){let e=On.twins.get(t);return e||(e=On.material(),e.depthTest=!1,e.onBeforeCompile=i=>{Object.assign(i.uniforms,Dt.output),i.vertexShader=On.patchOutput(i.vertexShader)},e.customProgramCacheKey=()=>"sky-ribbon-output",On.twins.set(t,e),e)}static patchOutput(t){return t.replace("void main() {",`${Dt.OUTPUT_UNIFORMS_GLSL}
7058
+ `;let ul;function H5(){if(ul)return ul;const a=256,t=document.createElement("canvas");t.width=a,t.height=a;const e=t.getContext("2d");e.fillStyle="rgba(60,60,60,1)",e.fillRect(0,0,a,a);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,o]of i){const c=e.createRadialGradient(n*a,s*a,0,n*a,s*a,r*a);c.addColorStop(0,`rgba(200,200,200,${o})`),c.addColorStop(1,"rgba(200,200,200,0)"),e.fillStyle=c,e.fillRect(0,0,a,a)}return ul=new Bs(t),ul}function G5(){const a={uTime:{value:0},uResolution:{value:new Mt(1,1)},uLensPosition:{value:new Mt(0,0)},uColorGain:{value:new st(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 st(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:H5()}},t=new fe({uniforms:a,vertexShader:z5,fragmentShader:B5,transparent:!0,depthWrite:!1,depthTest:!1,blending:Ai,fog:!1,name:"LensFlareShader"}),e=new bt(new Zi(2,2),t);return e.frustumCulled=!1,e.renderOrder=20,{mesh:e,uniforms:a}}class On{static material(){return new _n({vertexColors:!0,transparent:!0,blending:Ai,depthWrite:!1,fog:!1,side:xn})}static track(t){t.userData.skyRibbon=!0}static twins=new WeakMap;static outputMaterial(t){let e=On.twins.get(t);return e||(e=On.material(),e.depthTest=!1,e.onBeforeCompile=i=>{Object.assign(i.uniforms,Dt.output),i.vertexShader=On.patchOutput(i.vertexShader)},e.customProgramCacheKey=()=>"sky-ribbon-output",On.twins.set(t,e),e)}static patchOutput(t){return t.replace("void main() {",`${Dt.OUTPUT_UNIFORMS_GLSL}
7059
7059
  void main() {`).replace(Dt.PROJECT_ANCHOR,`${Dt.PROJECT_ANCHOR}
7060
- ${Dt.OUTPUT_PROJECTION_GLSL}`)}}class Hi{constructor(t,e){this.width=t,this.height=e,this.target=new Qe(t,e,{type:$e,samples:4}),this.occlusion=new Qe(...Hi.occlusionSize(t,e))}static OCCLUDER_LAYER=6;static CLOUD_LAYER=7;static OCCLUSION_SCALE=.5;target;occlusion;scene=new ys;proxies=new Map;foreground=new _n({color:0,fog:!1});hidden=[];static occlusionSize(t,e){return[Math.max(1,Math.round(t*Hi.OCCLUSION_SCALE)),Math.max(1,Math.round(e*Hi.OCCLUSION_SCALE))]}resize(t,e){this.width=t,this.height=e,this.target.setSize(t,e),this.occlusion.setSize(...Hi.occlusionSize(t,e))}take(t){this.hidden=t.points().filter(e=>Hi.shown(e)&&Hi.holdsPoints(e.geometry));for(const e of this.hidden)e.visible=!1;return this.hidden.length>0}restore(){for(const t of this.hidden)t.visible=!0}static shown(t){for(let e=t;e;e=e.parent)if(!e.visible)return!1;return!0}static holdsPoints(t){return(t.getAttribute("position")?.count??0)>0&&t.drawRange.count>0}draw(t,e,i,n,s,r){const o=t.getRenderTarget(),c=t.autoClear,l=t.shadowMap.autoUpdate;t.autoClear=!1,t.shadowMap.autoUpdate=!1,this.drawOcclusion(t,e,i,n);const h=this.width/this.height,u=Dt.output;u.uOutputHalfFovRad.value=s,u.uOutputAspect.value=h,u.uOutputPixelAngle.value=2*s/this.height,u.uSrcTanHalfFovY.value=r,u.uOcclusion.value=this.occlusion.texture,this.placeProxies(),Be.clearTransparent(t,this.target),t.setRenderTarget(this.target),t.render(this.scene,i),t.autoClear=c,t.shadowMap.autoUpdate=l,t.setRenderTarget(o)}drawOcclusion(t,e,i,n){Hi.markForeground(e,n.sky);for(const r of n.clouds())r.layers.enable(Hi.CLOUD_LAYER);Be.clearTransparent(t,this.occlusion),t.setRenderTarget(this.occlusion);const s=e.background;e.background=null,i.layers.set(Hi.OCCLUDER_LAYER),e.overrideMaterial=this.foreground,t.render(e,i),e.overrideMaterial=null,i.layers.set(Hi.CLOUD_LAYER),t.render(e,i),i.layers.set(0),e.background=s}static markForeground(t,e){for(const i of t.children)if(i!==e){if(i instanceof bt&&i.layers.isEnabled(0)){const n=Array.isArray(i.material)?i.material[0]:i.material;n.depthWrite!==!1&&!n.transparent&&n.blending!==Ai?i.layers.enable(Hi.OCCLUDER_LAYER):i.layers.disable(Hi.OCCLUDER_LAYER)}Hi.markForeground(i,e)}}placeProxies(){for(const t of this.hidden){let e=this.proxies.get(t);e||(e=t instanceof mn?new mn(t.geometry,Dt.outputMaterial(t.material)):new bt(t.geometry,On.outputMaterial(t.material)),e.matrixAutoUpdate=!1,e.frustumCulled=!1,this.proxies.set(t,e),this.scene.add(e)),e.geometry=t.geometry,t.updateWorldMatrix(!0,!1),e.matrix.copy(t.matrixWorld),e.matrixWorldNeedsUpdate=!0,e.visible=!0}for(const[t,e]of this.proxies)this.hidden.includes(t)||(e.visible=!1,t.parent||(this.scene.remove(e),this.proxies.delete(t)))}dispose(){this.target.dispose(),this.occlusion.dispose(),this.foreground.dispose()}}class Be{static MAX_HALF_ANGLE_DEG=80;static MAX_CUBE_FACE=2048;static SAMPLES=4;pointLayer;cubeTarget;cubeCamera;cubeMaterial;cubeRotation=new $t;target;overlayTarget;overlayCubeTarget;quadScene=new ys;quadCamera=new Zn(-1,1,1,-1,0,1);material;width;height;constructor(t,e){this.width=Math.max(1,t),this.height=Math.max(1,e),this.target=new Qe(this.width,this.height,{type:$e,samples:Be.SAMPLES}),this.overlayTarget=new Qe(this.width,this.height,{type:$e,samples:Be.SAMPLES}),this.material=new de({uniforms:{...Yi,uSource:{value:this.target.texture},uHalfFovRad:{value:.5236},uAspect:{value:this.width/this.height},uSrcTanHalfFovY:{value:1},uResolution:{value:new Mt(this.width,this.height)},uOverlay:{value:this.overlayTarget.texture},uPoints:{value:null},uPointsOn:{value:0},uMode:{value:Mn.Finished}},vertexShader:`
7060
+ ${Dt.OUTPUT_PROJECTION_GLSL}`)}}class Hi{constructor(t,e){this.width=t,this.height=e,this.target=new Qe(t,e,{type:$e,samples:4}),this.occlusion=new Qe(...Hi.occlusionSize(t,e))}static OCCLUDER_LAYER=6;static CLOUD_LAYER=7;static OCCLUSION_SCALE=.5;target;occlusion;scene=new ys;proxies=new Map;foreground=new _n({color:0,fog:!1});hidden=[];static occlusionSize(t,e){return[Math.max(1,Math.round(t*Hi.OCCLUSION_SCALE)),Math.max(1,Math.round(e*Hi.OCCLUSION_SCALE))]}resize(t,e){this.width=t,this.height=e,this.target.setSize(t,e),this.occlusion.setSize(...Hi.occlusionSize(t,e))}take(t){this.hidden=t.points().filter(e=>Hi.shown(e)&&Hi.holdsPoints(e.geometry));for(const e of this.hidden)e.visible=!1;return this.hidden.length>0}restore(){for(const t of this.hidden)t.visible=!0}static shown(t){for(let e=t;e;e=e.parent)if(!e.visible)return!1;return!0}static holdsPoints(t){return(t.getAttribute("position")?.count??0)>0&&t.drawRange.count>0}draw(t,e,i,n,s,r){const o=t.getRenderTarget(),c=t.autoClear,l=t.shadowMap.autoUpdate;t.autoClear=!1,t.shadowMap.autoUpdate=!1,this.drawOcclusion(t,e,i,n);const h=this.width/this.height,u=Dt.output;u.uOutputHalfFovRad.value=s,u.uOutputAspect.value=h,u.uOutputPixelAngle.value=2*s/this.height,u.uSrcTanHalfFovY.value=r,u.uOcclusion.value=this.occlusion.texture,this.placeProxies(),Be.clearTransparent(t,this.target),t.setRenderTarget(this.target),t.render(this.scene,i),t.autoClear=c,t.shadowMap.autoUpdate=l,t.setRenderTarget(o)}drawOcclusion(t,e,i,n){Hi.markForeground(e,n.sky);for(const r of n.clouds())r.layers.enable(Hi.CLOUD_LAYER);Be.clearTransparent(t,this.occlusion),t.setRenderTarget(this.occlusion);const s=e.background;e.background=null,i.layers.set(Hi.OCCLUDER_LAYER),e.overrideMaterial=this.foreground,t.render(e,i),e.overrideMaterial=null,i.layers.set(Hi.CLOUD_LAYER),t.render(e,i),i.layers.set(0),e.background=s}static markForeground(t,e){for(const i of t.children)if(i!==e){if(i instanceof bt&&i.layers.isEnabled(0)){const n=Array.isArray(i.material)?i.material[0]:i.material;n.depthWrite!==!1&&!n.transparent&&n.blending!==Ai?i.layers.enable(Hi.OCCLUDER_LAYER):i.layers.disable(Hi.OCCLUDER_LAYER)}Hi.markForeground(i,e)}}placeProxies(){for(const t of this.hidden){let e=this.proxies.get(t);e||(e=t instanceof mn?new mn(t.geometry,Dt.outputMaterial(t.material)):new bt(t.geometry,On.outputMaterial(t.material)),e.matrixAutoUpdate=!1,e.frustumCulled=!1,this.proxies.set(t,e),this.scene.add(e)),e.geometry=t.geometry,t.updateWorldMatrix(!0,!1),e.matrix.copy(t.matrixWorld),e.matrixWorldNeedsUpdate=!0,e.visible=!0}for(const[t,e]of this.proxies)this.hidden.includes(t)||(e.visible=!1,t.parent||(this.scene.remove(e),this.proxies.delete(t)))}dispose(){this.target.dispose(),this.occlusion.dispose(),this.foreground.dispose()}}class Be{static MAX_HALF_ANGLE_DEG=80;static MAX_CUBE_FACE=2048;static SAMPLES=4;pointLayer;cubeTarget;cubeCamera;cubeMaterial;cubeRotation=new $t;target;overlayTarget;overlayCubeTarget;quadScene=new ys;quadCamera=new Zn(-1,1,1,-1,0,1);material;width;height;constructor(t,e){this.width=Math.max(1,t),this.height=Math.max(1,e),this.target=new Qe(this.width,this.height,{type:$e,samples:Be.SAMPLES}),this.overlayTarget=new Qe(this.width,this.height,{type:$e,samples:Be.SAMPLES}),this.material=new fe({uniforms:{...Yi,uSource:{value:this.target.texture},uHalfFovRad:{value:.5236},uAspect:{value:this.width/this.height},uSrcTanHalfFovY:{value:1},uResolution:{value:new Mt(this.width,this.height)},uOverlay:{value:this.overlayTarget.texture},uPoints:{value:null},uPointsOn:{value:0},uMode:{value:Mn.Finished}},vertexShader:`
7061
7061
  varying vec2 vNdc;
7062
7062
  void main() {
7063
7063
  vNdc = position.xy;
@@ -7108,7 +7108,7 @@ ${Dt.OUTPUT_PROJECTION_GLSL}`)}}class Hi{constructor(t,e){this.width=t,this.heig
7108
7108
  // when the frame is on its way into a longer exposure, which has to add up light.
7109
7109
  ${Wo}
7110
7110
  }
7111
- `,depthTest:!1,depthWrite:!1}),this.quadScene.add(new bt(new Zi(2,2),this.material))}directionFor(t,e,i){const n=this.width/this.height,s=i/2*Math.PI/180,r=t*n*s,o=e*s,c=Math.hypot(r,o);if(c<1e-6)return{x:0,y:0,z:-1};const l=Math.sin(c);return{x:r/c*l,y:o/c*l,z:-Math.cos(c)}}static ndcFor(t,e,i){const n=Math.hypot(t.x,t.y,t.z);if(n===0||t.z>=n)return;const s=e/2*Math.PI/180,r=Math.acos(Math.min(1,-t.z/n)),o=Math.sin(r),c=o<1e-9?1:r/o,l=t.x/n*c,h=t.y/n*c;return{ndcX:l/(i*s),ndcY:h/s}}static cornerHalfAngleDeg(t,e){return t/2*Math.hypot(e,1)}static supports(t,e){return this.cornerHalfAngleDeg(t,e)<=this.MAX_HALF_ANGLE_DEG}resize(t,e){this.width=Math.max(1,t),this.height=Math.max(1,e),this.target.setSize(this.width,this.height),this.overlayTarget.setSize(this.width,this.height),this.pointLayer?.resize(this.width,this.height),this.material.uniforms.uResolution.value.set(this.width,this.height),this.material.uniforms.uAspect.value=this.width/this.height}render(t,e,i,n,s,r,o,c,l,h){const u=this.width/this.height;if(!Be.supports(n,u)){o?.(!0),this.renderThroughCube(t,e,i,n,r,c,l),o?.(!1);return}this.material.uniforms.uHalfFovRad.value=n/2*Math.PI/180,this.material.uniforms.uSrcTanHalfFovY.value=this.sourceTanHalfFovY(n,u);const d=i.fov;i.fov=this.sourceFovDeg(n,u),i.updateProjectionMatrix(),s?.();const f=t.getRenderTarget();h&&(this.pointLayer??=new Hi(this.width,this.height));const p=h?this.pointLayer.take(h):!1;t.setRenderTarget(this.target),t.render(e,i),r&&(Be.clearTransparent(t,this.overlayTarget),r(i)),p&&(this.pointLayer.restore(),this.pointLayer.draw(t,e,i,h,n/2*Math.PI/180,this.sourceTanHalfFovY(n,u))),this.material.uniforms.uPoints.value=this.pointLayer?.target.texture??null,this.material.uniforms.uPointsOn.value=p?1:0,t.setRenderTarget(f),i.fov=d,i.updateProjectionMatrix(),this.resample(t,this.quadScene.children[0],this.material,f,l)}resample(t,e,i,n,s){const r=e.material;e.material=i,s?(i.uniforms.uMode.value=Mn.Scene,t.setRenderTarget(s.scene),t.render(this.quadScene,this.quadCamera),i.uniforms.uMode.value=Mn.Overlay,t.setRenderTarget(s.overlay),t.render(this.quadScene,this.quadCamera),t.setRenderTarget(n)):(i.uniforms.uMode.value=Mn.Finished,t.setRenderTarget(n),t.render(this.quadScene,this.quadCamera)),e.material=r}static clearTransparent(t,e,i){const n=t.getClearColor(Be.clearScratch),s=t.getClearAlpha(),r=t.autoClear;t.setRenderTarget(e,i),t.setClearColor(0,0),t.clear(!0,!0,!0),t.setClearColor(n,s),e.samples>0&&(t.autoClear=!1,t.render(Be.nothing,Be.nothingCamera),t.autoClear=r)}static nothing=new ys;static nothingCamera=new Zn;static clearScratch=new st;renderThroughCube(t,e,i,n,s,r,o){const c=n*Math.PI/180,l=Math.min(Be.MAX_CUBE_FACE,t.capabilities.maxCubemapSize,Math.max(256,Math.ceil(this.height/c*Math.PI/2))),h={type:$e,minFilter:le,magFilter:le,generateMipmaps:!1};!this.cubeTarget||!this.cubeCamera||!this.cubeMaterial||!this.overlayCubeTarget?(this.cubeTarget=new lc(l,h),this.overlayCubeTarget=new lc(l,h),this.cubeCamera=new $0(i.near,i.far,this.cubeTarget),this.cubeMaterial=this.buildCubeMaterial(this.cubeTarget,this.overlayCubeTarget)):this.cubeTarget.width!==l&&(this.cubeTarget.setSize(l,l),this.overlayCubeTarget.setSize(l,l));const u=this.cubeCamera;i.updateMatrixWorld(),u.position.setFromMatrixPosition(i.matrixWorld);const d=i.getWorldQuaternion(this.quaternionScratch);u.quaternion.copy(d),u.updateMatrixWorld(),u.coordinateSystem!==t.coordinateSystem&&(u.coordinateSystem=t.coordinateSystem,u.updateCoordinateSystem());const f=t.getRenderTarget(),p=t.shadowMap.autoUpdate,v=u.children,m=Be.faceRegions(v,d,n,this.width/this.height,l);v.forEach((x,M)=>{const b=m[M];if(b){(x.near!==i.near||x.far!==i.far)&&(x.near=i.near,x.far=i.far,x.updateProjectionMatrix());for(const w of[this.cubeTarget,this.overlayCubeTarget])w.scissor.set(b.x,b.y,b.width,b.height),w.scissorTest=!0;t.setRenderTarget(this.cubeTarget,M),t.render(e,x),s&&(Be.clearTransparent(t,this.overlayCubeTarget,M),s(x)),t.shadowMap.autoUpdate=!1}}),this.cubeTarget.scissorTest=!1,this.overlayCubeTarget.scissorTest=!1,t.shadowMap.autoUpdate=p;const g=this.cubeMaterial.uniforms;g.uHalfFovRad.value=c/2,g.uAspect.value=this.width/this.height,g.uCameraRotation.value.identity();const S=this.quadScene.children[0];this.resample(t,S,this.cubeMaterial,f,{scene:this.target,overlay:this.overlayTarget}),t.setRenderTarget(this.target),r?.(),this.resample(t,S,this.copyMaterial(),f,o)}copy;copyMaterial(){return this.copy??=new de({uniforms:{...Yi,uSource:{value:this.target.texture},uOverlay:{value:this.overlayTarget.texture},uMode:{value:Mn.Finished}},vertexShader:`
7111
+ `,depthTest:!1,depthWrite:!1}),this.quadScene.add(new bt(new Zi(2,2),this.material))}directionFor(t,e,i){const n=this.width/this.height,s=i/2*Math.PI/180,r=t*n*s,o=e*s,c=Math.hypot(r,o);if(c<1e-6)return{x:0,y:0,z:-1};const l=Math.sin(c);return{x:r/c*l,y:o/c*l,z:-Math.cos(c)}}static ndcFor(t,e,i){const n=Math.hypot(t.x,t.y,t.z);if(n===0||t.z>=n)return;const s=e/2*Math.PI/180,r=Math.acos(Math.min(1,-t.z/n)),o=Math.sin(r),c=o<1e-9?1:r/o,l=t.x/n*c,h=t.y/n*c;return{ndcX:l/(i*s),ndcY:h/s}}static cornerHalfAngleDeg(t,e){return t/2*Math.hypot(e,1)}static supports(t,e){return this.cornerHalfAngleDeg(t,e)<=this.MAX_HALF_ANGLE_DEG}resize(t,e){this.width=Math.max(1,t),this.height=Math.max(1,e),this.target.setSize(this.width,this.height),this.overlayTarget.setSize(this.width,this.height),this.pointLayer?.resize(this.width,this.height),this.material.uniforms.uResolution.value.set(this.width,this.height),this.material.uniforms.uAspect.value=this.width/this.height}render(t,e,i,n,s,r,o,c,l,h){const u=this.width/this.height;if(!Be.supports(n,u)){o?.(!0),this.renderThroughCube(t,e,i,n,r,c,l),o?.(!1);return}this.material.uniforms.uHalfFovRad.value=n/2*Math.PI/180,this.material.uniforms.uSrcTanHalfFovY.value=this.sourceTanHalfFovY(n,u);const d=i.fov;i.fov=this.sourceFovDeg(n,u),i.updateProjectionMatrix(),s?.();const f=t.getRenderTarget();h&&(this.pointLayer??=new Hi(this.width,this.height));const p=h?this.pointLayer.take(h):!1;t.setRenderTarget(this.target),t.render(e,i),r&&(Be.clearTransparent(t,this.overlayTarget),r(i)),p&&(this.pointLayer.restore(),this.pointLayer.draw(t,e,i,h,n/2*Math.PI/180,this.sourceTanHalfFovY(n,u))),this.material.uniforms.uPoints.value=this.pointLayer?.target.texture??null,this.material.uniforms.uPointsOn.value=p?1:0,t.setRenderTarget(f),i.fov=d,i.updateProjectionMatrix(),this.resample(t,this.quadScene.children[0],this.material,f,l)}resample(t,e,i,n,s){const r=e.material;e.material=i,s?(i.uniforms.uMode.value=Mn.Scene,t.setRenderTarget(s.scene),t.render(this.quadScene,this.quadCamera),i.uniforms.uMode.value=Mn.Overlay,t.setRenderTarget(s.overlay),t.render(this.quadScene,this.quadCamera),t.setRenderTarget(n)):(i.uniforms.uMode.value=Mn.Finished,t.setRenderTarget(n),t.render(this.quadScene,this.quadCamera)),e.material=r}static clearTransparent(t,e,i){const n=t.getClearColor(Be.clearScratch),s=t.getClearAlpha(),r=t.autoClear;t.setRenderTarget(e,i),t.setClearColor(0,0),t.clear(!0,!0,!0),t.setClearColor(n,s),e.samples>0&&(t.autoClear=!1,t.render(Be.nothing,Be.nothingCamera),t.autoClear=r)}static nothing=new ys;static nothingCamera=new Zn;static clearScratch=new st;renderThroughCube(t,e,i,n,s,r,o){const c=n*Math.PI/180,l=Math.min(Be.MAX_CUBE_FACE,t.capabilities.maxCubemapSize,Math.max(256,Math.ceil(this.height/c*Math.PI/2))),h={type:$e,minFilter:le,magFilter:le,generateMipmaps:!1};!this.cubeTarget||!this.cubeCamera||!this.cubeMaterial||!this.overlayCubeTarget?(this.cubeTarget=new lc(l,h),this.overlayCubeTarget=new lc(l,h),this.cubeCamera=new $0(i.near,i.far,this.cubeTarget),this.cubeMaterial=this.buildCubeMaterial(this.cubeTarget,this.overlayCubeTarget)):this.cubeTarget.width!==l&&(this.cubeTarget.setSize(l,l),this.overlayCubeTarget.setSize(l,l));const u=this.cubeCamera;i.updateMatrixWorld(),u.position.setFromMatrixPosition(i.matrixWorld);const d=i.getWorldQuaternion(this.quaternionScratch);u.quaternion.copy(d),u.updateMatrixWorld(),u.coordinateSystem!==t.coordinateSystem&&(u.coordinateSystem=t.coordinateSystem,u.updateCoordinateSystem());const f=t.getRenderTarget(),p=t.shadowMap.autoUpdate,v=u.children,m=Be.faceRegions(v,d,n,this.width/this.height,l);v.forEach((x,M)=>{const b=m[M];if(b){(x.near!==i.near||x.far!==i.far)&&(x.near=i.near,x.far=i.far,x.updateProjectionMatrix());for(const w of[this.cubeTarget,this.overlayCubeTarget])w.scissor.set(b.x,b.y,b.width,b.height),w.scissorTest=!0;t.setRenderTarget(this.cubeTarget,M),t.render(e,x),s&&(Be.clearTransparent(t,this.overlayCubeTarget,M),s(x)),t.shadowMap.autoUpdate=!1}}),this.cubeTarget.scissorTest=!1,this.overlayCubeTarget.scissorTest=!1,t.shadowMap.autoUpdate=p;const g=this.cubeMaterial.uniforms;g.uHalfFovRad.value=c/2,g.uAspect.value=this.width/this.height,g.uCameraRotation.value.identity();const S=this.quadScene.children[0];this.resample(t,S,this.cubeMaterial,f,{scene:this.target,overlay:this.overlayTarget}),t.setRenderTarget(this.target),r?.(),this.resample(t,S,this.copyMaterial(),f,o)}copy;copyMaterial(){return this.copy??=new fe({uniforms:{...Yi,uSource:{value:this.target.texture},uOverlay:{value:this.overlayTarget.texture},uMode:{value:Mn.Finished}},vertexShader:`
7112
7112
  varying vec2 vUv;
7113
7113
  void main() {
7114
7114
  vUv = position.xy * 0.5 + 0.5;
@@ -7126,7 +7126,7 @@ ${Dt.OUTPUT_PROJECTION_GLSL}`)}}class Hi{constructor(t,e){this.width=t,this.heig
7126
7126
  vec4 overlay = texture2D(uOverlay, vUv);
7127
7127
  ${Wo}
7128
7128
  }
7129
- `,depthTest:!1,depthWrite:!1}),this.copy}quaternionScratch=new on;static REGION_SAMPLES=32;static faceRegions(t,e,i,n,s){const r=t.map(v=>(v.updateMatrixWorld(),v.matrixWorldInverse)),o=Be.REGION_SAMPLES,c=i/2*Math.PI/180,l=Be.faceScratch,h=[];for(let v=0;v<=o;v++)for(let m=0;m<=o;m++){const g=(-1+2*m/o)*n*c,S=(-1+2*v/o)*c,x=Math.hypot(g,S),M=Math.sin(x);x<1e-6?l.set(0,0,-1):l.set(g/x*M,S/x*M,-Math.cos(x)),l.applyQuaternion(e);let b;for(let w=0;w<r.length&&!b;w++){const T=Be.localScratch.copy(l).transformDirection(r[w]);if(T.z>=0)continue;const y=T.applyMatrix4(t[w].projectionMatrix);Math.abs(y.x)<=1&&Math.abs(y.y)<=1&&(b={face:w,x:(y.x+1)/2*s,y:(y.y+1)/2*s})}h.push(b)}const u=t.map(()=>({minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0,step:0})),d=(v,m)=>{v&&m&&v.face===m.face&&(u[v.face].step=Math.max(u[v.face].step,Math.abs(v.x-m.x),Math.abs(v.y-m.y)))};h.forEach((v,m)=>{if(!v)return;const g=u[v.face];g.minX=Math.min(g.minX,v.x),g.minY=Math.min(g.minY,v.y),g.maxX=Math.max(g.maxX,v.x),g.maxY=Math.max(g.maxY,v.y),m%(o+1)<o&&d(v,h[m+1]),m+o+1<h.length&&d(v,h[m+o+1])});const f=Be.forwardScratch.set(0,0,-1).applyQuaternion(e),p=Be.cornerHalfAngleDeg(i,n);return u.map((v,m)=>{if(v.minX>v.maxX)return Be.faceSeen(t[m],f,p)?{x:0,y:0,width:s,height:s}:void 0;const g=v.step>0?v.step+2:s,S=Math.max(0,Math.floor(v.minX-g)),x=Math.max(0,Math.floor(v.minY-g)),M=Math.min(s,Math.ceil(v.maxX+g)),b=Math.min(s,Math.ceil(v.maxY+g));return{x:S,y:x,width:M-S,height:b-x}})}static faceSeen(t,e,i){t.updateMatrixWorld();const n=Math.cos(Math.min(i+5,180)*Math.PI/180),s=Be.faceScratch;for(let r=0;r<=4;r++)for(let o=0;o<=4;o++)if(s.set(-1+r/2,-1+o/2,-1).normalize().transformDirection(t.matrixWorld),s.dot(e)>=n)return!0;return!1}static faceScratch=new R;static localScratch=new R;static forwardScratch=new R;buildCubeMaterial(t,e){return new de({uniforms:{...Yi,uCube:{value:t.texture},uOverlayCube:{value:e.texture},uHalfFovRad:{value:.5236},uAspect:{value:1},uCameraRotation:{value:this.cubeRotation},uMode:{value:Mn.Finished}},vertexShader:`
7129
+ `,depthTest:!1,depthWrite:!1}),this.copy}quaternionScratch=new on;static REGION_SAMPLES=32;static faceRegions(t,e,i,n,s){const r=t.map(v=>(v.updateMatrixWorld(),v.matrixWorldInverse)),o=Be.REGION_SAMPLES,c=i/2*Math.PI/180,l=Be.faceScratch,h=[];for(let v=0;v<=o;v++)for(let m=0;m<=o;m++){const g=(-1+2*m/o)*n*c,S=(-1+2*v/o)*c,x=Math.hypot(g,S),M=Math.sin(x);x<1e-6?l.set(0,0,-1):l.set(g/x*M,S/x*M,-Math.cos(x)),l.applyQuaternion(e);let b;for(let w=0;w<r.length&&!b;w++){const T=Be.localScratch.copy(l).transformDirection(r[w]);if(T.z>=0)continue;const y=T.applyMatrix4(t[w].projectionMatrix);Math.abs(y.x)<=1&&Math.abs(y.y)<=1&&(b={face:w,x:(y.x+1)/2*s,y:(y.y+1)/2*s})}h.push(b)}const u=t.map(()=>({minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0,step:0})),d=(v,m)=>{v&&m&&v.face===m.face&&(u[v.face].step=Math.max(u[v.face].step,Math.abs(v.x-m.x),Math.abs(v.y-m.y)))};h.forEach((v,m)=>{if(!v)return;const g=u[v.face];g.minX=Math.min(g.minX,v.x),g.minY=Math.min(g.minY,v.y),g.maxX=Math.max(g.maxX,v.x),g.maxY=Math.max(g.maxY,v.y),m%(o+1)<o&&d(v,h[m+1]),m+o+1<h.length&&d(v,h[m+o+1])});const f=Be.forwardScratch.set(0,0,-1).applyQuaternion(e),p=Be.cornerHalfAngleDeg(i,n);return u.map((v,m)=>{if(v.minX>v.maxX)return Be.faceSeen(t[m],f,p)?{x:0,y:0,width:s,height:s}:void 0;const g=v.step>0?v.step+2:s,S=Math.max(0,Math.floor(v.minX-g)),x=Math.max(0,Math.floor(v.minY-g)),M=Math.min(s,Math.ceil(v.maxX+g)),b=Math.min(s,Math.ceil(v.maxY+g));return{x:S,y:x,width:M-S,height:b-x}})}static faceSeen(t,e,i){t.updateMatrixWorld();const n=Math.cos(Math.min(i+5,180)*Math.PI/180),s=Be.faceScratch;for(let r=0;r<=4;r++)for(let o=0;o<=4;o++)if(s.set(-1+r/2,-1+o/2,-1).normalize().transformDirection(t.matrixWorld),s.dot(e)>=n)return!0;return!1}static faceScratch=new R;static localScratch=new R;static forwardScratch=new R;buildCubeMaterial(t,e){return new fe({uniforms:{...Yi,uCube:{value:t.texture},uOverlayCube:{value:e.texture},uHalfFovRad:{value:.5236},uAspect:{value:1},uCameraRotation:{value:this.cubeRotation},uMode:{value:Mn.Finished}},vertexShader:`
7130
7130
  varying vec2 vNdc;
7131
7131
  void main() {
7132
7132
  vNdc = position.xy;
@@ -7161,7 +7161,7 @@ ${Dt.OUTPUT_PROJECTION_GLSL}`)}}class Hi{constructor(t,e){this.width=t,this.heig
7161
7161
  }
7162
7162
  ${Wo}
7163
7163
  }
7164
- `,depthTest:!1,depthWrite:!1})}sourceFovDeg(t,e){return Math.atan(this.sourceTanHalfFovY(t,e))*360/Math.PI}sourceTanHalfFovY(t,e){const i=Be.cornerHalfAngleDeg(t,e)*Math.PI/180;return Math.tan(i)/Math.hypot(e,1)}dispose(){this.target.dispose(),this.overlayTarget.dispose(),this.pointLayer?.dispose(),this.material.dispose(),this.cubeTarget?.dispose(),this.overlayCubeTarget?.dispose(),this.cubeMaterial?.dispose(),this.copy?.dispose(),this.quadScene.clear()}}class qo{static MAX_RADIUS_PX=24;static TAPS=32;target;overlayTarget;quadScene=new ys;quadCamera=new Zn(-1,1,1,-1,0,1);material;width;height;constructor(t,e){this.width=Math.max(1,t),this.height=Math.max(1,e);const i=new mr(this.width,this.height,Nn);i.minFilter=Ce,i.magFilter=Ce,this.target=new Qe(this.width,this.height,{type:$e,depthTexture:i});const n=new mr(this.width,this.height,Nn);n.minFilter=Ce,n.magFilter=Ce,this.overlayTarget=new Qe(this.width,this.height,{type:$e,depthTexture:n}),this.material=new de({uniforms:{...Yi,uColour:{value:this.target.texture},uDepth:{value:i},uResolution:{value:new Mt(this.width,this.height)},uNear:{value:.1},uFar:{value:1e3},uApertureMm2:{value:0},uFocusDistance:{value:0},uFocalLengthMm:{value:50},uPixelsPerMm:{value:0},uMaxRadius:{value:qo.MAX_RADIUS_PX},uOverlay:{value:this.overlayTarget.texture},uOverlayDepth:{value:n},uMode:{value:Mn.Finished}},vertexShader:`
7164
+ `,depthTest:!1,depthWrite:!1})}sourceFovDeg(t,e){return Math.atan(this.sourceTanHalfFovY(t,e))*360/Math.PI}sourceTanHalfFovY(t,e){const i=Be.cornerHalfAngleDeg(t,e)*Math.PI/180;return Math.tan(i)/Math.hypot(e,1)}dispose(){this.target.dispose(),this.overlayTarget.dispose(),this.pointLayer?.dispose(),this.material.dispose(),this.cubeTarget?.dispose(),this.overlayCubeTarget?.dispose(),this.cubeMaterial?.dispose(),this.copy?.dispose(),this.quadScene.clear()}}class qo{static MAX_RADIUS_PX=24;static TAPS=32;target;overlayTarget;quadScene=new ys;quadCamera=new Zn(-1,1,1,-1,0,1);material;width;height;constructor(t,e){this.width=Math.max(1,t),this.height=Math.max(1,e);const i=new mr(this.width,this.height,Nn);i.minFilter=Ce,i.magFilter=Ce,this.target=new Qe(this.width,this.height,{type:$e,depthTexture:i});const n=new mr(this.width,this.height,Nn);n.minFilter=Ce,n.magFilter=Ce,this.overlayTarget=new Qe(this.width,this.height,{type:$e,depthTexture:n}),this.material=new fe({uniforms:{...Yi,uColour:{value:this.target.texture},uDepth:{value:i},uResolution:{value:new Mt(this.width,this.height)},uNear:{value:.1},uFar:{value:1e3},uApertureMm2:{value:0},uFocusDistance:{value:0},uFocalLengthMm:{value:50},uPixelsPerMm:{value:0},uMaxRadius:{value:qo.MAX_RADIUS_PX},uOverlay:{value:this.overlayTarget.texture},uOverlayDepth:{value:n},uMode:{value:Mn.Finished}},vertexShader:`
7165
7165
  varying vec2 vUv;
7166
7166
  void main() {
7167
7167
  vUv = position.xy * 0.5 + 0.5;
@@ -7241,7 +7241,7 @@ ${Dt.OUTPUT_PROJECTION_GLSL}`)}}class Hi{constructor(t,e){this.width=t,this.heig
7241
7241
  vec4 overlay = throughLens(uOverlay, uOverlayDepth);
7242
7242
  ${Wo}
7243
7243
  }
7244
- `,depthTest:!1,depthWrite:!1}),this.quadScene.add(new bt(new Zi(2,2),this.material))}resize(t,e){this.width=Math.max(1,t),this.height=Math.max(1,e),this.target.setSize(this.width,this.height),this.overlayTarget.setSize(this.width,this.height),this.material.uniforms.uResolution.value.set(this.width,this.height)}setLens(t,e,i,n){const s=this.material.uniforms;s.uApertureMm2.value=t*t/Math.max(.1,e),s.uFocusDistance.value=Math.max(0,i),s.uFocalLengthMm.value=t,s.uPixelsPerMm.value=this.height/Math.max(.1,n)}render(t,e,i,n,s){const r=this.material.uniforms;r.uNear.value=i.near,r.uFar.value=i.far;const o=t.getRenderTarget();t.setRenderTarget(this.target),t.clear(),t.render(e,i),n&&(Be.clearTransparent(t,this.overlayTarget),n()),s?(r.uMode.value=Mn.Scene,t.setRenderTarget(s.scene),t.render(this.quadScene,this.quadCamera),r.uMode.value=Mn.Overlay,t.setRenderTarget(s.overlay),t.render(this.quadScene,this.quadCamera)):(r.uMode.value=Mn.Finished,t.setRenderTarget(o),t.render(this.quadScene,this.quadCamera)),t.setRenderTarget(o)}dispose(){this.target.depthTexture?.dispose(),this.target.dispose(),this.overlayTarget.depthTexture?.dispose(),this.overlayTarget.dispose(),this.material.dispose()}}class df{static SAMPLES=4;scene;overlay;quadScene=new ys;quadCamera=new Zn(-1,1,1,-1,0,1);material;constructor(t,e){const i={type:$e,samples:df.SAMPLES};this.scene=new Qe(Math.max(1,t),Math.max(1,e),i),this.overlay=new Qe(Math.max(1,t),Math.max(1,e),i),this.material=new de({uniforms:{...Yi,uSource:{value:this.scene.texture},uOverlay:{value:this.overlay.texture},uMode:{value:Mn.Finished}},vertexShader:`
7244
+ `,depthTest:!1,depthWrite:!1}),this.quadScene.add(new bt(new Zi(2,2),this.material))}resize(t,e){this.width=Math.max(1,t),this.height=Math.max(1,e),this.target.setSize(this.width,this.height),this.overlayTarget.setSize(this.width,this.height),this.material.uniforms.uResolution.value.set(this.width,this.height)}setLens(t,e,i,n){const s=this.material.uniforms;s.uApertureMm2.value=t*t/Math.max(.1,e),s.uFocusDistance.value=Math.max(0,i),s.uFocalLengthMm.value=t,s.uPixelsPerMm.value=this.height/Math.max(.1,n)}render(t,e,i,n,s){const r=this.material.uniforms;r.uNear.value=i.near,r.uFar.value=i.far;const o=t.getRenderTarget();t.setRenderTarget(this.target),t.clear(),t.render(e,i),n&&(Be.clearTransparent(t,this.overlayTarget),n()),s?(r.uMode.value=Mn.Scene,t.setRenderTarget(s.scene),t.render(this.quadScene,this.quadCamera),r.uMode.value=Mn.Overlay,t.setRenderTarget(s.overlay),t.render(this.quadScene,this.quadCamera)):(r.uMode.value=Mn.Finished,t.setRenderTarget(o),t.render(this.quadScene,this.quadCamera)),t.setRenderTarget(o)}dispose(){this.target.depthTexture?.dispose(),this.target.dispose(),this.overlayTarget.depthTexture?.dispose(),this.overlayTarget.dispose(),this.material.dispose()}}class df{static SAMPLES=4;scene;overlay;quadScene=new ys;quadCamera=new Zn(-1,1,1,-1,0,1);material;constructor(t,e){const i={type:$e,samples:df.SAMPLES};this.scene=new Qe(Math.max(1,t),Math.max(1,e),i),this.overlay=new Qe(Math.max(1,t),Math.max(1,e),i),this.material=new fe({uniforms:{...Yi,uSource:{value:this.scene.texture},uOverlay:{value:this.overlay.texture},uMode:{value:Mn.Finished}},vertexShader:`
7245
7245
  varying vec2 vUv;
7246
7246
  void main() {
7247
7247
  vUv = position.xy * 0.5 + 0.5;
@@ -7259,7 +7259,7 @@ ${Dt.OUTPUT_PROJECTION_GLSL}`)}}class Hi{constructor(t,e){this.width=t,this.heig
7259
7259
  vec4 overlay = texture2D(uOverlay, vUv);
7260
7260
  ${Wo}
7261
7261
  }
7262
- `,depthTest:!1,depthWrite:!1}),this.quadScene.add(new bt(new Zi(2,2),this.material))}render(t,e,i,n,s,r){const o=t.getRenderTarget(),c=r??{scene:this.scene,overlay:this.overlay};t.setRenderTarget(c.scene),t.render(e,i),s?.(),(n||r)&&(Be.clearTransparent(t,c.overlay),n?.()),t.setRenderTarget(o),!r&&(this.material.uniforms.uMode.value=Mn.Finished,t.render(this.quadScene,this.quadCamera))}resize(t,e){this.scene.setSize(Math.max(1,t),Math.max(1,e)),this.overlay.setSize(Math.max(1,t),Math.max(1,e))}dispose(){this.scene.dispose(),this.overlay.dispose(),this.material.dispose(),this.quadScene.children[0].geometry.dispose()}}class xe{static MIN_RATIO=1;static STEP=.25;static MIN_SHARE_OF_DISPLAY=.75;static GPU_LATE_MS=12;static GPU_ROOM_MS=6;static INTERVAL_LATE_MS=21;static LOWER_COOLDOWN_MS=750;static RAISE_COOLDOWN_MS=2e3;static PROBE_WATCH_MS=2e3;static PROBE_EVERY_MS=6e3;static PROBE_BACKOFF_MS=3e4;ratio;maxRatio;timer;intervalMs;lastChangeMs=-1/0;nextProbeMs=0;probe;constructor(t,e){this.maxRatio=xe.clamp(t),this.ratio=this.maxRatio,this.timer=e?sh.create(e):void 0}get pixelRatio(){return this.ratio}static SETTLE_MS=400;static SUSTAINED_MS=100;lastEditMs=-1/0;editStreakStartMs=-1/0;wasChanging=!1;noteChange(t){t-this.lastEditMs>xe.SETTLE_MS&&(this.editStreakStartMs=t),this.lastEditMs=t}changing(t){return t-this.lastEditMs<=xe.SETTLE_MS&&this.lastEditMs-this.editStreakStartMs>=xe.SUSTAINED_MS}ratioFor(t,e){return this.changing(t)?this.wasChanging?(this.update(t,e),this.ratio):(this.wasChanging=!0,this.reset(),this.ratio):(this.wasChanging=!1,this.maxRatio)}get timesGpu(){return this.timer!==void 0}set maximum(t){this.maxRatio=xe.clamp(t),this.ratio>this.maxRatio&&(this.ratio=this.maxRatio),this.ratio<this.minimum&&(this.ratio=Math.min(this.maxRatio,this.minimum))}get minimum(){const t=Math.floor(this.maxRatio*xe.MIN_SHARE_OF_DISPLAY/xe.STEP)*xe.STEP;return Math.max(xe.MIN_RATIO,t)}get maximum(){return this.maxRatio}beginDrawing(){this.timer?.begin()}endDrawing(){this.timer?.end()}reset(){this.intervalMs=void 0,this.probe=void 0,this.timer?.reset()}update(t,e){const i=this.timer?.poll();if(!(this.timer&&i===void 0))return i!==void 0?this.followGpu(t,i):this.followIntervals(t,e)}followGpu(t,e){if(e>xe.GPU_LATE_MS)return this.lower(t,xe.LOWER_COOLDOWN_MS);if(e<xe.GPU_ROOM_MS)return this.raise(t,xe.RAISE_COOLDOWN_MS)}followIntervals(t,e){if(!(e>0)||e>1e3)return;this.intervalMs=this.intervalMs===void 0?e:this.intervalMs*.9+e*.1;const i=this.intervalMs>xe.INTERVAL_LATE_MS;if(this.probe){if(i)return this.ratio=this.probe.ratioBefore,this.probe=void 0,this.lastChangeMs=t,this.nextProbeMs=t+xe.PROBE_BACKOFF_MS,this.ratio;t-this.probe.sinceMs>=xe.PROBE_WATCH_MS&&(this.probe=void 0,this.nextProbeMs=t+xe.PROBE_EVERY_MS);return}if(i){const n=this.lower(t,xe.LOWER_COOLDOWN_MS);return n!==void 0&&(this.nextProbeMs=t+xe.PROBE_EVERY_MS),n}if(this.ratio<this.maxRatio&&t>=this.nextProbeMs&&t-this.lastChangeMs>=xe.RAISE_COOLDOWN_MS){const n=this.ratio,s=this.raise(t,0);return s!==void 0&&(this.probe={sinceMs:t,ratioBefore:n}),s}}lower(t,e){if(!(this.ratio<=this.minimum||t-this.lastChangeMs<e))return this.ratio=Math.max(this.minimum,xe.clamp(this.ratio-xe.STEP)),this.lastChangeMs=t,this.ratio}raise(t,e){if(!(this.ratio>=this.maxRatio||t-this.lastChangeMs<e))return this.ratio=Math.min(this.maxRatio,xe.clamp(this.ratio+xe.STEP)),this.lastChangeMs=t,this.ratio}static clamp(t){return Number.isFinite(t)?Math.max(xe.MIN_RATIO,Math.round(t/xe.STEP)*xe.STEP):xe.MIN_RATIO}}class sh{constructor(t,e){this.gl=t,this.extension=e}static IN_FLIGHT_MAX=8;static create(t){if(!(t instanceof WebGL2RenderingContext))return;const e=t.getExtension("EXT_disjoint_timer_query_webgl2");return e?new sh(t,e):void 0}pending=[];active;smoothedMs;begin(){if(!(this.active||this.pending.length>=sh.IN_FLIGHT_MAX))try{const t=this.gl.createQuery();if(!t)return;this.gl.beginQuery(this.extension.TIME_ELAPSED_EXT,t),this.active=t}catch{this.active=void 0}}end(){if(this.active){try{this.gl.endQuery(this.extension.TIME_ELAPSED_EXT),this.pending.push(this.active)}catch{}this.active=void 0}}poll(){const t=this.gl;try{for(let e=0;e<this.pending.length;e++){const i=this.pending[e];if(!t.getQueryParameter(i,t.QUERY_RESULT_AVAILABLE))continue;if(!t.getParameter(this.extension.GPU_DISJOINT_EXT)){const s=t.getQueryParameter(i,t.QUERY_RESULT)/1e6;this.smoothedMs=this.smoothedMs===void 0?s:this.smoothedMs*.8+s*.2}t.deleteQuery(i),this.pending.splice(e,1),e--}}catch{this.pending.length=0}return this.smoothedMs}reset(){this.smoothedMs=void 0}}class ve{static ICE_INDEX_RED=1.3067;static ICE_INDEX_BLUE=1.317;static SIDE_PRISM_ANGLE_DEG=60;static END_PRISM_ANGLE_DEG=90;static get PARHELIA_MAX_SUN_ALTITUDE_DEG(){const t=ve.ICE_INDEX_RED,e=Math.sqrt((4-t*t)/3);return Math.asin(Math.min(1,e))*180/Math.PI}static minimumDeviationDeg(t,e){const i=t*Math.PI/180,n=e*Math.sin(i/2);return n>1?Number.NaN:(2*Math.asin(n)-i)*180/Math.PI}static effectiveIndex(t,e){const i=e*Math.PI/180,n=Math.cos(i);return n<=0?Number.POSITIVE_INFINITY:Math.sqrt(t*t-Math.sin(i)**2)/n}static parheliaAzimuthDeg(t,e=ve.ICE_INDEX_RED){const i=ve.minimumDeviationDeg(ve.SIDE_PRISM_ANGLE_DEG,ve.effectiveIndex(e,t));return Number.isFinite(i)?i:void 0}static parheliaDistanceDeg(t,e=ve.ICE_INDEX_RED){const i=ve.parheliaAzimuthDeg(t,e);if(i===void 0)return;const n=t*Math.PI/180,s=Math.sin(n)**2,r=Math.cos(n)**2*Math.cos(i*Math.PI/180);return Math.acos(Math.max(-1,Math.min(1,s+r)))*180/Math.PI}static get PLATE_END_FACE_LIMIT_DEG(){const t=ve.ICE_INDEX_RED;return Math.asin(Math.min(1,Math.sqrt(t*t-1)))*180/Math.PI}static circumzenithalAltitudeDeg(t,e=ve.ICE_INDEX_RED){if(t<0||t>90-ve.PLATE_END_FACE_LIMIT_DEG)return;const i=Math.cos(t*Math.PI/180),n=Math.sqrt(e*e-i*i);if(!(n>=1))return Math.asin(n)*180/Math.PI}static DECK_HEIGHT_M=8e3;static deckLitUntilDeg(t){return Math.acos(6371e3/(6371e3+Math.max(0,t)))*180/Math.PI}static halo22(){return ve.ringOf("halo22",ve.SIDE_PRISM_ANGLE_DEG)}static halo46(){return ve.ringOf("halo46",ve.END_PRISM_ANGLE_DEG)}static ringOf(t,e){const i=ve.minimumDeviationDeg(e,ve.ICE_INDEX_RED),n=ve.minimumDeviationDeg(e,ve.ICE_INDEX_BLUE);return{id:t,angleDeg:(i+n)/2,redAngleDeg:i,blueAngleDeg:n}}static strength(t,e,i=90,n=0){const s=Math.max(0,Math.min(1,t)),r=Math.max(0,1-Math.max(0,Math.min(1,e))),o=i>=0?1:n<=0?0:Math.max(0,1+i/n);return s*r*o}static formsAt(t,e=0){if(t<=-e)return[];const i=[ve.halo22(),ve.halo46()],n=t>0?ve.parheliaDistanceDeg(t):void 0;n!==void 0&&i.push({id:"parhelia",angleDeg:n,redAngleDeg:n,blueAngleDeg:ve.parheliaDistanceDeg(t,ve.ICE_INDEX_BLUE)}),i.push({id:"tangentArc",angleDeg:ve.halo22().angleDeg}),t>0&&i.push({id:"parhelicCircle",angleDeg:t});const s=ve.circumzenithalAltitudeDeg(t);return s!==void 0&&i.push({id:"circumzenithal",angleDeg:s}),t>ve.PLATE_END_FACE_LIMIT_DEG&&i.push({id:"circumhorizontal"}),t<ve.PILLAR_MAX_SOURCE_ALTITUDE_DEG&&i.push({id:"pillar"}),i}static PILLAR_MAX_SOURCE_ALTITUDE_DEG=20}class dn{static get WATER_INDEX_RED(){return bi.indexAt(bi.RED_NM)}static get WATER_INDEX_BLUE(){return bi.indexAt(bi.BLUE_NM)}static radiusDeg(t,e){const i=(e*e-1)/(t*t-1);if(i<0||i>1)return Number.NaN;const n=Math.acos(Math.sqrt(i)),s=Math.asin(Math.sin(n)/e),r=2*(n-s)+(t-1)*(Math.PI-2*s),o=2*Math.PI;let c=r%o;return c<0&&(c+=o),c>Math.PI&&(c=o-c),180-c*180/Math.PI}static primary(){return dn.bowOf("primary",2,0)}static secondary(){return dn.bowOf("secondary",3,0)}static bowOf(t,e,i){const n=dn.radiusDeg(e,dn.WATER_INDEX_RED),s=dn.radiusDeg(e,dn.WATER_INDEX_BLUE),r=(n+s)/2;return{id:t,radiusDeg:r,redRadiusDeg:n,violetRadiusDeg:s,topAltitudeDeg:r-i}}static alexandersBandDeg(){return{fromDeg:dn.primary().redRadiusDeg,toDeg:dn.secondary().redRadiusDeg}}static formsAt(t){return t<0?[]:[dn.bowOf("primary",2,t),dn.bowOf("secondary",3,t)].filter(e=>e.topAltitudeDeg>0)}static FULL_MOON_MAGNITUDE=-12.7;static moonlightShare(t){return Math.min(1,10**(-.4*(t-dn.FULL_MOON_MAGNITUDE)))}static strength(t,e,i){if(i<=0)return 0;const n=Math.max(0,Math.min(1,t)),s=Math.max(0,1-Math.max(0,Math.min(1,e)));return n*s}}class fn{constructor(t){this.radius=t;const e=fn.SEGMENTS*fn.VERTICES_PER_SEGMENT;this.positions=new Float32Array(e*3),this.colors=new Float32Array(e*3);const i=new se;i.setAttribute("position",new Jt(this.positions,3)),i.setAttribute("color",new Jt(this.colors,3)),i.setDrawRange(0,0),this.object=new bt(i,On.material()),this.object.frustumCulled=!1,On.track(this.object)}static POINTS=24;static SEGMENTS=fn.POINTS-1;static ACROSS=3;static VERTICES_PER_SEGMENT=(fn.ACROSS-1)*6;static HEAD_HALF_WIDTH_DEG=.15;static SPREAD_FRACTION=.05;static FADE_POWER=1.8;object;positions;colors;head;tip;brightness=0;set(t,e,i){this.head=t&&Ze(t.altitudeDeg,t.azimuthDeg,1),this.tip=e&&Ze(e.altitudeDeg,e.azimuthDeg,1),this.brightness=i,this.rebuild()}rebuild(){const t=this.object.geometry,e=this.head,i=this.tip;if(!e||!i||this.brightness<=0){t.setDrawRange(0,0);return}const n=this.angleBetween(e,i);if(n<=0){t.setDrawRange(0,0);return}const s=n*fn.SPREAD_FRACTION*Math.PI/180,r=h=>this.scale(this.slerp(e,i,h),this.radius),o=h=>this.radius*(fn.HEAD_HALF_WIDTH_DEG*Math.PI/180+s*h),c=h=>this.brightness*(1-h)**fn.FADE_POWER;let l=0;for(let h=1;h<fn.POINTS;h++){const u=(h-1)/fn.SEGMENTS,d=h/fn.SEGMENTS;l=this.pushBand(l,r(u),r(d),o(u),o(d),c(u),c(d))}t.setDrawRange(0,l),t.getAttribute("position").needsUpdate=!0,t.getAttribute("color").needsUpdate=!0}pushBand(t,e,i,n,s,r,o){const c=this.normalise(this.cross(this.normalise(e),this.normalise(this.subtract(i,e))));for(let l=0;l<fn.ACROSS-1;l++){const h=l-1,u=l,d=this.across(e,c,n,h),f=this.across(i,c,s,h),p=this.across(e,c,n,u),v=this.across(i,c,s,u),m=(g,S)=>g===0?S:0;t=this.push(t,d,m(h,r)),t=this.push(t,f,m(h,o)),t=this.push(t,p,m(u,r)),t=this.push(t,f,m(h,o)),t=this.push(t,v,m(u,o)),t=this.push(t,p,m(u,r))}return t}across(t,e,i,n){return{x:t.x+e.x*i*n,y:t.y+e.y*i*n,z:t.z+e.z*i*n}}push(t,e,i){const n=t*3;this.positions[n]=e.x,this.positions[n+1]=e.y,this.positions[n+2]=e.z;const s=Et.relativeOfResponse(Math.max(0,Math.min(1,i)));return this.colors[n]=s*.55,this.colors[n+1]=s*.75,this.colors[n+2]=s,t+1}slerp(t,e,i){const n=this.angleBetweenRadians(t,e);if(n<1e-9)return t;const s=Math.sin(n),r=Math.sin((1-i)*n)/s,o=Math.sin(i*n)/s;return{x:t.x*r+e.x*o,y:t.y*r+e.y*o,z:t.z*r+e.z*o}}angleBetween(t,e){return this.angleBetweenRadians(t,e)*180/Math.PI}angleBetweenRadians(t,e){const i=t.x*e.x+t.y*e.y+t.z*e.z;return Math.acos(Math.min(1,Math.max(-1,i)))}scale(t,e){return{x:t.x*e,y:t.y*e,z:t.z*e}}subtract(t,e){return{x:t.x-e.x,y:t.y-e.y,z:t.z-e.z}}cross(t,e){return{x:t.y*e.z-t.z*e.y,y:t.z*e.x-t.x*e.z,z:t.x*e.y-t.y*e.x}}normalise(t){const e=Math.hypot(t.x,t.y,t.z)||1;return{x:t.x/e,y:t.y/e,z:t.z/e}}dispose(){this.object.geometry.dispose(),this.object.material.dispose()}}class V5{object=new Re;radius;tiers;drawn=[];constructor(t){this.radius=t,this.object.name="satellites",this.tiers=Xa.map(e=>{const i=new mn(new se,Dt.material(e.size));return Dt.track(i),i.frustumCulled=!1,this.object.add(i),i})}set(t,e,i,n){const s=this.tiers.map(()=>[]);this.drawn=[];for(const r of t){if(r.magnitude>e)continue;const o=i(r.position);if(o<=0)continue;const c=r.magnitude-2.5*Math.log10(o);if(c>e)continue;const l=Ca(c,e),h=Q0(l),{x:u,y:d,z:f}=Ze(r.position.altitudeDeg,r.position.azimuthDeg,this.radius),[p,v,m]=n(r.position,c);s[h].push({x:u,y:d,z:f,r:p,g:v,b:m,seed:r.norad*.6180339887%1}),this.drawn.push({satellite:r,direction:new R(u,d,f).normalize()})}this.tiers.forEach((r,o)=>{const c=s[o],l=new Float32Array(c.length*3),h=new Float32Array(c.length*3),u=new Float32Array(c.length);c.forEach((f,p)=>{l.set([f.x,f.y,f.z],p*3),h.set([f.r,f.g,f.b],p*3),u[p]=f.seed}),r.geometry.dispose();const d=new se;d.setAttribute("position",new Jt(l,3)),d.setAttribute("color",new Jt(h,3)),d.setAttribute("seed",new Jt(u,1)),r.geometry=d})}get count(){return this.drawn.length}nearest(t,e){let i,n=e;for(const s of this.drawn){const r=s.direction.dot(t);r>n&&(n=r,i=s.satellite)}return i}dispose(){for(const t of this.tiers)t.geometry.dispose(),t.material.dispose();this.object.removeFromParent(),this.drawn=[]}}class Qi{static RADIUS=840;static MAX_SEGMENTS=256;static VERTICES_PER_SEGMENT=12;static MIN_HALF_WIDTH_DEG=.05;static BRIGHT_HALF_WIDTH_DEG=.22;static TRAIN_SHARE=.6;object=new Re;tiers;trains;positions;colors;shown=0;constructor(){this.object.name="reentries",this.tiers=Xa.map(i=>{const n=new mn(new se,Dt.material(i.size,!1));return Dt.track(n),n.frustumCulled=!1,this.object.add(n),n});const t=Qi.MAX_SEGMENTS*Qi.VERTICES_PER_SEGMENT;this.positions=new Float32Array(t*3),this.colors=new Float32Array(t*3);const e=new se;e.setAttribute("position",new Jt(this.positions,3)),e.setAttribute("color",new Jt(this.colors,3)),e.setDrawRange(0,0),this.trains=new bt(e,On.material()),this.trains.frustumCulled=!1,On.track(this.trains),this.object.add(this.trains)}get count(){return this.shown}set(t,e,i,n){const s=this.tiers.map(()=>[]);let r=0,o=0;const c=new st;for(const h of t){const u=i(h.head);if(u<=0)continue;const d=h.magnitude-2.5*Math.log10(u);if(d>e)continue;o++,c.set(h.color);const f=Ca(d,e),{x:p,y:v,z:m}=Ze(h.head.altitudeDeg,h.head.azimuthDeg,Qi.RADIUS),[g,S,x]=n(h.head,d),M=Math.max(c.r,c.g,c.b)||1;s[Q0(f)].push({x:p,y:v,z:m,r:g*c.r/M,g:S*c.g/M,b:x*c.b/M}),r=this.pushTrain(r,h.train,f,c)}this.shown=o,this.tiers.forEach((h,u)=>{const d=s[u],f=new Float32Array(d.length*3),p=new Float32Array(d.length*3);d.forEach((m,g)=>{f.set([m.x,m.y,m.z],g*3),p.set([m.r,m.g,m.b],g*3)}),h.geometry.dispose();const v=new se;v.setAttribute("position",new Jt(f,3)),v.setAttribute("color",new Jt(p,3)),h.geometry=v});const l=this.trains.geometry;l.setDrawRange(0,r),l.getAttribute("position").needsUpdate=!0,l.getAttribute("color").needsUpdate=!0}pushTrain(t,e,i,n){const s=e.length-1;for(let r=0;r<s;r++){if(t+Qi.VERTICES_PER_SEGMENT>Qi.MAX_SEGMENTS*Qi.VERTICES_PER_SEGMENT)return t;const o=1-r/s,c=1-(r+1)/s,l=Ze(e[r].altitudeDeg,e[r].azimuthDeg,Qi.RADIUS),h=Ze(e[r+1].altitudeDeg,e[r+1].azimuthDeg,Qi.RADIUS),u=f=>Qi.RADIUS*((Qi.MIN_HALF_WIDTH_DEG+Qi.BRIGHT_HALF_WIDTH_DEG*i*f)*Math.PI/180),d=f=>Qi.TRAIN_SHARE*i*f**1.6;t=this.pushRibbon(t,l,h,u(o),u(c),d(o),d(c),n)}return t}pushRibbon(t,e,i,n,s,r,o,c){const l={x:i.x-e.x,y:i.y-e.y,z:i.z-e.z};if(Math.hypot(l.x,l.y,l.z)<1e-9)return t;const h=this.normalise(this.cross(this.normalise(e),this.normalise(l)));for(const[u,d]of[[-1,0],[0,1]]){const f=this.across(e,h,n,u),p=this.across(i,h,s,u),v=this.across(e,h,n,d),m=this.across(i,h,s,d),g=(S,x)=>S===0?x:0;t=this.push(t,f,g(u,r),c),t=this.push(t,p,g(u,o),c),t=this.push(t,v,g(d,r),c),t=this.push(t,p,g(u,o),c),t=this.push(t,m,g(d,o),c),t=this.push(t,v,g(d,r),c)}return t}across(t,e,i,n){return{x:t.x+e.x*i*n,y:t.y+e.y*i*n,z:t.z+e.z*i*n}}push(t,e,i,n){const s=t*3;this.positions[s]=e.x,this.positions[s+1]=e.y,this.positions[s+2]=e.z;const r=Et.relativeOfResponse(Math.max(0,Math.min(1,i)));return this.colors[s]=r*n.r,this.colors[s+1]=r*n.g,this.colors[s+2]=r*n.b,t+1}cross(t,e){return{x:t.y*e.z-t.z*e.y,y:t.z*e.x-t.x*e.z,z:t.x*e.y-t.y*e.x}}normalise(t){const e=Math.hypot(t.x,t.y,t.z)||1;return{x:t.x/e,y:t.y/e,z:t.z/e}}dispose(){for(const t of this.tiers)t.geometry.dispose(),t.material.dispose();this.trains.geometry.dispose(),this.trains.material.dispose(),this.object.removeFromParent()}}class bh{constructor(t){this.state=t}next(){this.state=this.state+1831565813|0;let t=this.state;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}between(t,e){return t+this.next()*(e-t)}}class Gr{static MIN_DURATION_MS=250;static MAX_DURATION_MS=1400;static schedule(t){const{ratePerHour:e,durationMs:i,velocityKmS:n,seed:s}=t;if(e<=0||i<=0)return[];const r=e*i/36e5,o=new bh(s),c=Math.floor(r),l=c+(o.next()<r-c?1:0),h=[];for(let u=0;u<l;u++){const d=Math.min(1,Math.max(0,(n-20)/52)),f=Gr.MAX_DURATION_MS-d*(Gr.MAX_DURATION_MS-Gr.MIN_DURATION_MS),p=o.between(5,70);h.push({t:o.between(0,i),durationMs:f*o.between(.7,1.3),fromRadiantDeg:p,bearingDeg:o.between(0,360),lengthDeg:Math.sin(p*Math.PI/180)*o.between(8,40)*(.6+d),brightness:o.next()**3}),h.sort((v,m)=>v.t-m.t)}return h}static aliveAt(t,e){return t.filter(i=>e>=i.t&&e<=i.t+i.durationMs).map(i=>({meteor:i,progress:(e-i.t)/i.durationMs}))}}class nr{object=new Re;radius;core;glow;flashKey;static CORE_WIDTH_DEG=.06;static GLOW_WIDTH_DEG=.5;static SEGMENTS=28;static CORE_RELATIVE=1e3;constructor(t){this.radius=t,this.object.name="lightning-bolt",this.core=new _n({color:15659775,transparent:!0,opacity:0,blending:Ai,depthWrite:!1,fog:!1}),this.glow=new _n({color:10466559,transparent:!0,opacity:0,blending:Ai,depthWrite:!1,fog:!1}),this.object.visible=!1,this.object.renderOrder=5.95}set(t,e,i){if(!t||!t.cloudToGround||e<=.01){this.object.visible=!1;return}const n=`${t.channelSeed}:${Math.round(i)}`;n!==this.flashKey&&this.build(t,i,n),this.core.color.setHex(15659775).multiplyScalar(nr.CORE_RELATIVE*Math.min(1,e*1.4)),this.glow.color.setHex(10466559).multiplyScalar(.1*nr.CORE_RELATIVE*e*.35),this.core.opacity=1,this.glow.opacity=1,this.object.visible=!0}build(t,e,i){this.flashKey=i;for(const l of[...this.object.children])l.geometry.dispose(),this.object.remove(l);const n=new bh(t.channelSeed),s=Math.atan2(e,t.distanceM)*180/Math.PI,r=this.channel(n,t.azimuthDeg,s,0,1),o=[r],c=1+Math.floor(n.next()*2);for(let l=0;l<c;l++){const h=r[Math.floor(n.between(.15,.5)*r.length)];o.push(this.channel(n,h.azimuthDeg,h.altitudeDeg,h.altitudeDeg*n.between(.3,.7),.5))}for(const l of o)this.object.add(new bt(this.ribbon(l,nr.GLOW_WIDTH_DEG),this.glow)),this.object.add(new bt(this.ribbon(l,nr.CORE_WIDTH_DEG),this.core))}channel(t,e,i,n,s){const r=[],o=i-n;let c=e;for(let l=0;l<=nr.SEGMENTS;l++){const h=i-o*l/nr.SEGMENTS;r.push({azimuthDeg:c,altitudeDeg:h}),c+=t.between(-1,1)*o*.06*s}return r}ribbon(t,e){const i=new Float32Array(t.length*2*3),n=[],s=this.radius*Math.tan(e*Math.PI/180)/2,r=t.map(c=>{const{x:l,y:h,z:u}=Ze(c.altitudeDeg,c.azimuthDeg,this.radius);return new R(l,h,u)});r.forEach((c,l)=>{const h=r[Math.min(l+1,r.length-1)],u=r[Math.max(l-1,0)],f=h.clone().sub(u).normalize().cross(c.clone().normalize()).normalize().multiplyScalar(s);if(i.set([c.x+f.x,c.y+f.y,c.z+f.z],l*6),i.set([c.x-f.x,c.y-f.y,c.z-f.z],l*6+3),l<r.length-1){const p=l*2;n.push(p,p+1,p+2,p+1,p+3,p+2)}});const o=new se;return o.setAttribute("position",new Jt(i,3)),o.setIndex(n),o}dispose(){for(const t of this.object.children)t.geometry.dispose();this.core.dispose(),this.glow.dispose(),this.object.removeFromParent()}}class gi{static MIN_INTERVAL_S=8;static MAX_INTERVAL_S=25;static SEVERE_MIN_INTERVAL_S=2;static SEVERE_MAX_INTERVAL_S=8;static CLOUD_TO_GROUND_FRACTION=.25;static MIN_DISTANCE_M=1e3;static MAX_DISTANCE_M=15e3;static INTERSTROKE_MS=60;static STROKE_DECAY_MS=40;static SOUND_SPEED_M_S=343;static schedule(t){const e=new bh(t.seed),i=[],{minS:n,maxS:s}=gi.intervalFor(t.intensity??.5);let r=e.between(0,s)*1e3;for(;r<t.durationMs;){const o=e.next()<gi.CLOUD_TO_GROUND_FRACTION,c=gi.MIN_DISTANCE_M,l=gi.MAX_DISTANCE_M,h=Math.sqrt(e.between(c*c,l*l)),u=o?1+Math.floor(e.next()*4):1,d=[];let f=0;for(let p=0;p<u;p++)d.push({offsetMs:f,intensity:p===0?1:e.between(.4,.9)}),f+=gi.INTERSTROKE_MS*e.between(.5,1.6);i.push({t:r,azimuthDeg:e.between(0,360),distanceM:h,cloudToGround:o,strokes:d,channelSeed:Math.floor(e.next()*2**31)}),r+=e.between(n,s)*1e3}return i}static intervalFor(t){const e=Math.min(1,Math.max(0,(t-.5)/.5));return{minS:gi.MIN_INTERVAL_S-e*(gi.MIN_INTERVAL_S-gi.SEVERE_MIN_INTERVAL_S),maxS:gi.MAX_INTERVAL_S-e*(gi.MAX_INTERVAL_S-gi.SEVERE_MAX_INTERVAL_S)}}static brightnessAt(t,e){let i=0;for(const n of t.strokes){const s=e-t.t-n.offsetMs;s<0||s>gi.STROKE_DECAY_MS*6||(i+=n.intensity*Math.exp(-s/gi.STROKE_DECAY_MS))}return Math.min(1,i)}static endOf(t){const e=t.strokes[t.strokes.length-1];return t.t+e.offsetMs+gi.STROKE_DECAY_MS*6}static thunderDelayMs(t){return t.distanceM/gi.SOUND_SPEED_M_S*1e3}}class tn{static RED_NM=656.3;static BLUE_NM=435.8;static ANCHOR_RED=1.3067;static ANCHOR_BLUE=1.317;static B=(tn.ANCHOR_BLUE-tn.ANCHOR_RED)/(1/(tn.BLUE_NM*tn.BLUE_NM)-1/(tn.RED_NM*tn.RED_NM));static A=tn.ANCHOR_RED-tn.B/(tn.RED_NM*tn.RED_NM);static indexAt(t){return tn.A+tn.B/(t*t)}}class hc{normals=new Float64Array(24);offsets=new Float64Array(8);radius=1;set(t,e,i,n,s,r){let o=0,c=0,l=0;Math.abs(i)<.9?(o=-e,c=t,l=0):(o=0,c=-i,l=e);const h=Math.hypot(o,c,l)||1;o/=h,c/=h,l/=h;const u=e*l-i*c,d=i*o-t*l,f=t*c-e*o,p=s/2,v=r/2;for(let m=0;m<6;m++){const g=n+m*Math.PI/3,S=Math.cos(g),x=Math.sin(g);this.normals[m*3]=o*S+u*x,this.normals[m*3+1]=c*S+d*x,this.normals[m*3+2]=l*S+f*x,this.offsets[m]=p}this.normals[18]=t,this.normals[19]=e,this.normals[20]=i,this.offsets[6]=v,this.normals[21]=-t,this.normals[22]=-e,this.normals[23]=-i,this.offsets[7]=v,this.radius=Math.hypot(p,v)}get aimRadius(){return this.radius}trace(t,e,i,n,s,r,o){let c=-e,l=t,h=0,u=Math.hypot(c,l,h);u<1e-6&&(c=1,l=0,h=0,u=1),c/=u,l/=u,h/=u;const d=e*h-i*l,f=i*c-t*h,p=t*l-e*c,v=c*n+d*s-t*this.radius*2,m=l*n+f*s-e*this.radius*2,g=h*n+p*s-i*this.radius*2;let S=-1,x=-1/0,M=1/0;for(let J=0;J<8;J++){const it=this.normals[J*3],at=this.normals[J*3+1],Xt=this.normals[J*3+2],ee=it*t+at*e+Xt*i,Kt=this.offsets[J]-(it*v+at*m+Xt*g);if(ee>1e-9){const q=Kt/ee;q<M&&(M=q)}else if(ee<-1e-9){const q=Kt/ee;q>x&&(x=q,S=J)}else if(Kt<0)return 0}if(S<0||x>=M)return 0;let b=0;const w=this.normals[S*3],T=this.normals[S*3+1],y=this.normals[S*3+2],A=-(w*t+T*e+y*i),C=jl.reflectance(A,1,r);o[b].x=t+2*A*w,o[b].y=e+2*A*T,o[b].z=i+2*A*y,o[b].weight=C,b++;const I=1/r,P=Math.sqrt(Math.max(0,1-I*I*(1-A*A)));let V=I*t+(I*A-P)*w,X=I*e+(I*A-P)*T,L=I*i+(I*A-P)*y,B=v+t*x,k=m+e*x,$=g+i*x,tt=1-C;for(let J=0;J<hc.MAX_BOUNCES&&tt>hc.MIN_WEIGHT;J++){let it=-1,at=1/0;for(let z=0;z<8;z++){const Rt=this.normals[z*3],Ft=this.normals[z*3+1],Pt=this.normals[z*3+2],St=Rt*V+Ft*X+Pt*L;if(St<=1e-9)continue;const zt=(this.offsets[z]-(Rt*B+Ft*k+Pt*$))/St;zt>1e-9&&zt<at&&(at=zt,it=z)}if(it<0)break;const Xt=this.normals[it*3],ee=this.normals[it*3+1],Kt=this.normals[it*3+2],q=Xt*V+ee*X+Kt*L,rt=r*Math.sqrt(Math.max(0,1-q*q));if(B+=V*at,k+=X*at,$+=L*at,rt<1){const z=Math.sqrt(Math.max(0,1-rt*rt)),Rt=jl.reflectance(q,r,1);if(o[b].x=r*V-(r*q-z)*Xt,o[b].y=r*X-(r*q-z)*ee,o[b].z=r*L-(r*q-z)*Kt,o[b].weight=tt*(1-Rt),b++,b>=o.length)return b;tt*=Rt}const nt=2*q;V-=nt*Xt,X-=nt*ee,L-=nt*Kt}return b}static MAX_BOUNCES=6;static MIN_WEIGHT=1e-4}class Xe{static AZIMUTH_BINS=512;static ALTITUDE_BINS=512;static POPULATIONS=[{orientation:"tumbling",widthMicrons:50,lengthMicrons:50,share:.52},{orientation:"plate",widthMicrons:100,lengthMicrons:15,share:.27},{orientation:"column",widthMicrons:40,lengthMicrons:120,share:.19},{orientation:"parry",widthMicrons:40,lengthMicrons:120,share:.02}];static WORST_TILT_DEG=180;static BEST_TILT_DEG=.5;static SOURCE_RADIUS_DEG=.265;static UNDEVIATED_DEG=.6;crystal=new hc;emergent=Array.from({length:hc.MAX_BOUNCES+2},()=>({x:0,y:0,z:0,weight:0}));tally=new Float32Array(Xe.AZIMUTH_BINS*Xe.ALTITUDE_BINS*3);radiance=new Float32Array(Xe.AZIMUTH_BINS*Xe.ALTITUDE_BINS*3);scratch=new Float32Array(Xe.AZIMUTH_BINS*Xe.ALTITUDE_BINS*3);seed=1;spare=0;hasSpare=!1;altitude=0;tilt=0;alignment=0;traced=0;begin(t,e,i=2654435769){this.seed=i>>>0||1,this.hasSpare=!1,this.tally.fill(0),this.traced=0,this.altitude=t*Math.PI/180,this.alignment=Math.min(1,Math.max(0,e));const n=Xe.WORST_TILT_DEG*(Xe.BEST_TILT_DEG/Xe.WORST_TILT_DEG)**this.alignment;this.tilt=n*Math.PI/180}trace(t){const e=Xe.AZIMUTH_BINS,i=Xe.ALTITUDE_BINS,n=this.tally,s=Xe.SOURCE_RADIUS_DEG*Math.PI/180,r=Math.cos(Xe.UNDEVIATED_DEG*Math.PI/180),o=this.altitude;for(let c=0;c<t;c++){const l=this.pickPopulation();this.orient(l,this.tilt);const h=this.random()*2*Math.PI,u=s*Math.sqrt(this.random()),d=o+u*Math.sin(h),f=u*Math.cos(h)/Math.max(.05,Math.cos(o)),p=-Math.cos(d)*Math.cos(f),v=-Math.cos(d)*Math.sin(f),m=-Math.sin(d),g=this.crystal.aimRadius,S=(this.random()*2-1)*g,x=(this.random()*2-1)*g,M=4*g*g,b=vi.SAMPLES[this.random()*vi.SAMPLES.length|0],w=this.crystal.trace(p,v,m,S,x,tn.indexAt(b.wavelengthNm),this.emergent);for(let T=0;T<w;T++){const y=this.emergent[T],A=Math.hypot(y.x,y.y,y.z);if(A<1e-9||y.weight<=0)continue;const C=y.x/A,I=y.y/A,P=y.z/A;if(C*p+I*v+P*m>r)continue;const V=Math.asin(Math.max(-1,Math.min(1,-P))),X=Math.abs(Math.atan2(-I,-C)),L=Math.min(e-1,X/Math.PI*e|0),k=(Math.min(i-1,(V+Math.PI/2)/Math.PI*i|0)*e+L)*3,$=y.weight*M*vi.SAMPLES.length;n[k]+=$*b.r,n[k+1]+=$*b.g,n[k+2]+=$*b.b}}this.traced+=t}get tracedRays(){return this.traced}harvest(){const t=Xe.AZIMUTH_BINS,e=Xe.ALTITUDE_BINS;return this.toRadiance(t,e),this.smooth(t,e),{width:t,height:e,data:this.radiance,sourceAltitudeDeg:this.altitude*180/Math.PI,alignment:this.alignment,rays:this.traced}}compute(t,e,i,n){return this.begin(t,e,n),this.trace(i),this.harvest()}toRadiance(t,e){const i=2*Math.PI/t,n=Math.max(1,this.traced),s=4*Xe.REFERENCE_MICRONS*Xe.REFERENCE_MICRONS;for(let r=0;r<e;r++){const o=Math.sin(r/e*Math.PI-Math.PI/2),c=Math.sin((r+1)/e*Math.PI-Math.PI/2),l=1/(i*(c-o)*n*s);for(let h=0;h<t;h++){const u=(r*t+h)*3;this.radiance[u]=this.tally[u]*l,this.radiance[u+1]=this.tally[u+1]*l,this.radiance[u+2]=this.tally[u+2]*l}}}static REFERENCE_MICRONS=50;smooth(t,e){const i=this.scratch,n=this.radiance;i.set(n);for(let r=0;r<e;r++){const o=r*t*3;for(let c=0;c<3;c++){let l=i[o+c];for(let h=0;h<t;h++){const u=o+h*3+c,d=h+1<t?i[u+3]:i[u];n[u]=(l+2*i[u]+d)/4,l=i[u]}}}i.set(n);const s=t*3;for(let r=0;r<e;r++){const o=r>0?-s:0,c=r+1<e?s:0,l=r*s;for(let h=l;h<l+s;h++)n[h]=(i[h+o]+2*i[h]+i[h+c])/4}}pickPopulation(){const t=this.random();let e=0;for(const i of Xe.POPULATIONS)if(e+=i.share,t<=e)return i;return Xe.POPULATIONS[Xe.POPULATIONS.length-1]}orient(t,e){const i=this.random()*2*Math.PI;let n=this.random()*2*Math.PI,s=0,r=0,o=1;switch(t.orientation){case"tumbling":{o=this.random()*2-1;const c=Math.sqrt(Math.max(0,1-o*o));s=c*Math.cos(i),r=c*Math.sin(i);break}case"plate":{o=this.spreadAboutAnAxis(e);const c=Math.sqrt(Math.max(0,1-o*o));s=c*Math.cos(i),r=c*Math.sin(i);break}case"column":case"parry":{o=this.spreadAboutAPlane(e);const c=Math.sqrt(Math.max(0,1-o*o));s=c*Math.cos(i),r=c*Math.sin(i),t.orientation==="parry"&&(n=Math.PI/2+this.gaussian()*e);break}}this.crystal.set(s,r,o,n,t.widthMicrons,t.lengthMicrons)}random(){this.seed=this.seed+1831565813>>>0;let t=this.seed;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}spreadAboutAnAxis(t){const e=1/Math.max(1e-6,t*t),i=Math.max(1e-12,this.random()),n=1+Math.log(i+(1-i)*Math.exp(-2*e))/e;return Math.max(-1,Math.min(1,n))}spreadAboutAPlane(t){for(let e=0;e<8;e++){const i=this.gaussian()*t;if(i>=-1&&i<=1)return i}return this.random()*2-1}gaussian(){if(this.hasSpare)return this.hasSpare=!1,this.spare;const t=Math.sqrt(-2*Math.log(Math.max(1e-12,this.random()))),e=2*Math.PI*this.random();return this.spare=t*Math.sin(e),this.hasSpare=!0,t*Math.cos(e)}}class W5{static fromRadiance(t,e){const i=Ln.toHalfFloat(1);for(let n=0,s=0;s<t.length;n+=4,s+=3)e[n]=Ln.toHalfFloat(t[s]),e[n+1]=Ln.toHalfFloat(t[s+1]),e[n+2]=Ln.toHalfFloat(t[s+2]),e[n+3]=i}}class Ti{static RADIUS=880;static RAYS=9e5;static RAYS_PER_BATCH=2e3;static BUDGET_MS=6;static URGENT_BUDGET_MS=40;static ALTITUDE_STEP_DEG=1;static ALIGNMENT_STEP=.05;static LEAP_ALTITUDE_DEG=5;static LEAP_ALIGNMENT=.25;static GAIN=.55;setCloudOffset(t){this.material.uniforms.uFieldOffset.value.copy(t)}object;material;sky=new Xe;texture;texels;mappedAltitudeDeg=Number.NaN;mappedAlignment=Number.NaN;tracing=!1;everDisplayed=!1;urgent=!1;workHandle;onRepaint;constructor(){const t=Xe.AZIMUTH_BINS,e=Xe.ALTITUDE_BINS;this.texels=new Uint16Array(t*e*4),this.texture=new Mr(this.texels,t,e,Di,$e),this.texture.minFilter=le,this.texture.magFilter=le,this.texture.wrapS=Ri,this.texture.wrapT=Ri,this.texture.needsUpdate=!0,this.material=new de({uniforms:{uSource:{value:new R(0,1,0)},uUp:{value:new R(0,1,0)},uStrength:{value:0},uTint:{value:new R(1,.97,.92)},uIceCover:{value:0},uIceHeight:{value:1},uFieldOffset:{value:new R},uMap:{value:this.texture},uGain:{value:Ti.GAIN}},vertexShader:`
7262
+ `,depthTest:!1,depthWrite:!1}),this.quadScene.add(new bt(new Zi(2,2),this.material))}render(t,e,i,n,s,r){const o=t.getRenderTarget(),c=r??{scene:this.scene,overlay:this.overlay};t.setRenderTarget(c.scene),t.render(e,i),s?.(),(n||r)&&(Be.clearTransparent(t,c.overlay),n?.()),t.setRenderTarget(o),!r&&(this.material.uniforms.uMode.value=Mn.Finished,t.render(this.quadScene,this.quadCamera))}resize(t,e){this.scene.setSize(Math.max(1,t),Math.max(1,e)),this.overlay.setSize(Math.max(1,t),Math.max(1,e))}dispose(){this.scene.dispose(),this.overlay.dispose(),this.material.dispose(),this.quadScene.children[0].geometry.dispose()}}class xe{static MIN_RATIO=1;static STEP=.25;static MIN_SHARE_OF_DISPLAY=.75;static GPU_LATE_MS=12;static GPU_ROOM_MS=6;static INTERVAL_LATE_MS=21;static LOWER_COOLDOWN_MS=750;static RAISE_COOLDOWN_MS=2e3;static PROBE_WATCH_MS=2e3;static PROBE_EVERY_MS=6e3;static PROBE_BACKOFF_MS=3e4;ratio;maxRatio;timer;intervalMs;lastChangeMs=-1/0;nextProbeMs=0;probe;constructor(t,e){this.maxRatio=xe.clamp(t),this.ratio=this.maxRatio,this.timer=e?sh.create(e):void 0}get pixelRatio(){return this.ratio}static SETTLE_MS=400;static SUSTAINED_MS=100;lastEditMs=-1/0;editStreakStartMs=-1/0;wasChanging=!1;noteChange(t){t-this.lastEditMs>xe.SETTLE_MS&&(this.editStreakStartMs=t),this.lastEditMs=t}changing(t){return t-this.lastEditMs<=xe.SETTLE_MS&&this.lastEditMs-this.editStreakStartMs>=xe.SUSTAINED_MS}ratioFor(t,e){return this.changing(t)?this.wasChanging?(this.update(t,e),this.ratio):(this.wasChanging=!0,this.reset(),this.ratio):(this.wasChanging=!1,this.maxRatio)}get timesGpu(){return this.timer!==void 0}set maximum(t){this.maxRatio=xe.clamp(t),this.ratio>this.maxRatio&&(this.ratio=this.maxRatio),this.ratio<this.minimum&&(this.ratio=Math.min(this.maxRatio,this.minimum))}get minimum(){const t=Math.floor(this.maxRatio*xe.MIN_SHARE_OF_DISPLAY/xe.STEP)*xe.STEP;return Math.max(xe.MIN_RATIO,t)}get maximum(){return this.maxRatio}beginDrawing(){this.timer?.begin()}endDrawing(){this.timer?.end()}reset(){this.intervalMs=void 0,this.probe=void 0,this.timer?.reset()}update(t,e){const i=this.timer?.poll();if(!(this.timer&&i===void 0))return i!==void 0?this.followGpu(t,i):this.followIntervals(t,e)}followGpu(t,e){if(e>xe.GPU_LATE_MS)return this.lower(t,xe.LOWER_COOLDOWN_MS);if(e<xe.GPU_ROOM_MS)return this.raise(t,xe.RAISE_COOLDOWN_MS)}followIntervals(t,e){if(!(e>0)||e>1e3)return;this.intervalMs=this.intervalMs===void 0?e:this.intervalMs*.9+e*.1;const i=this.intervalMs>xe.INTERVAL_LATE_MS;if(this.probe){if(i)return this.ratio=this.probe.ratioBefore,this.probe=void 0,this.lastChangeMs=t,this.nextProbeMs=t+xe.PROBE_BACKOFF_MS,this.ratio;t-this.probe.sinceMs>=xe.PROBE_WATCH_MS&&(this.probe=void 0,this.nextProbeMs=t+xe.PROBE_EVERY_MS);return}if(i){const n=this.lower(t,xe.LOWER_COOLDOWN_MS);return n!==void 0&&(this.nextProbeMs=t+xe.PROBE_EVERY_MS),n}if(this.ratio<this.maxRatio&&t>=this.nextProbeMs&&t-this.lastChangeMs>=xe.RAISE_COOLDOWN_MS){const n=this.ratio,s=this.raise(t,0);return s!==void 0&&(this.probe={sinceMs:t,ratioBefore:n}),s}}lower(t,e){if(!(this.ratio<=this.minimum||t-this.lastChangeMs<e))return this.ratio=Math.max(this.minimum,xe.clamp(this.ratio-xe.STEP)),this.lastChangeMs=t,this.ratio}raise(t,e){if(!(this.ratio>=this.maxRatio||t-this.lastChangeMs<e))return this.ratio=Math.min(this.maxRatio,xe.clamp(this.ratio+xe.STEP)),this.lastChangeMs=t,this.ratio}static clamp(t){return Number.isFinite(t)?Math.max(xe.MIN_RATIO,Math.round(t/xe.STEP)*xe.STEP):xe.MIN_RATIO}}class sh{constructor(t,e){this.gl=t,this.extension=e}static IN_FLIGHT_MAX=8;static create(t){if(!(t instanceof WebGL2RenderingContext))return;const e=t.getExtension("EXT_disjoint_timer_query_webgl2");return e?new sh(t,e):void 0}pending=[];active;smoothedMs;begin(){if(!(this.active||this.pending.length>=sh.IN_FLIGHT_MAX))try{const t=this.gl.createQuery();if(!t)return;this.gl.beginQuery(this.extension.TIME_ELAPSED_EXT,t),this.active=t}catch{this.active=void 0}}end(){if(this.active){try{this.gl.endQuery(this.extension.TIME_ELAPSED_EXT),this.pending.push(this.active)}catch{}this.active=void 0}}poll(){const t=this.gl;try{for(let e=0;e<this.pending.length;e++){const i=this.pending[e];if(!t.getQueryParameter(i,t.QUERY_RESULT_AVAILABLE))continue;if(!t.getParameter(this.extension.GPU_DISJOINT_EXT)){const s=t.getQueryParameter(i,t.QUERY_RESULT)/1e6;this.smoothedMs=this.smoothedMs===void 0?s:this.smoothedMs*.8+s*.2}t.deleteQuery(i),this.pending.splice(e,1),e--}}catch{this.pending.length=0}return this.smoothedMs}reset(){this.smoothedMs=void 0}}class ve{static ICE_INDEX_RED=1.3067;static ICE_INDEX_BLUE=1.317;static SIDE_PRISM_ANGLE_DEG=60;static END_PRISM_ANGLE_DEG=90;static get PARHELIA_MAX_SUN_ALTITUDE_DEG(){const t=ve.ICE_INDEX_RED,e=Math.sqrt((4-t*t)/3);return Math.asin(Math.min(1,e))*180/Math.PI}static minimumDeviationDeg(t,e){const i=t*Math.PI/180,n=e*Math.sin(i/2);return n>1?Number.NaN:(2*Math.asin(n)-i)*180/Math.PI}static effectiveIndex(t,e){const i=e*Math.PI/180,n=Math.cos(i);return n<=0?Number.POSITIVE_INFINITY:Math.sqrt(t*t-Math.sin(i)**2)/n}static parheliaAzimuthDeg(t,e=ve.ICE_INDEX_RED){const i=ve.minimumDeviationDeg(ve.SIDE_PRISM_ANGLE_DEG,ve.effectiveIndex(e,t));return Number.isFinite(i)?i:void 0}static parheliaDistanceDeg(t,e=ve.ICE_INDEX_RED){const i=ve.parheliaAzimuthDeg(t,e);if(i===void 0)return;const n=t*Math.PI/180,s=Math.sin(n)**2,r=Math.cos(n)**2*Math.cos(i*Math.PI/180);return Math.acos(Math.max(-1,Math.min(1,s+r)))*180/Math.PI}static get PLATE_END_FACE_LIMIT_DEG(){const t=ve.ICE_INDEX_RED;return Math.asin(Math.min(1,Math.sqrt(t*t-1)))*180/Math.PI}static circumzenithalAltitudeDeg(t,e=ve.ICE_INDEX_RED){if(t<0||t>90-ve.PLATE_END_FACE_LIMIT_DEG)return;const i=Math.cos(t*Math.PI/180),n=Math.sqrt(e*e-i*i);if(!(n>=1))return Math.asin(n)*180/Math.PI}static DECK_HEIGHT_M=8e3;static deckLitUntilDeg(t){return Math.acos(6371e3/(6371e3+Math.max(0,t)))*180/Math.PI}static halo22(){return ve.ringOf("halo22",ve.SIDE_PRISM_ANGLE_DEG)}static halo46(){return ve.ringOf("halo46",ve.END_PRISM_ANGLE_DEG)}static ringOf(t,e){const i=ve.minimumDeviationDeg(e,ve.ICE_INDEX_RED),n=ve.minimumDeviationDeg(e,ve.ICE_INDEX_BLUE);return{id:t,angleDeg:(i+n)/2,redAngleDeg:i,blueAngleDeg:n}}static strength(t,e,i=90,n=0){const s=Math.max(0,Math.min(1,t)),r=Math.max(0,1-Math.max(0,Math.min(1,e))),o=i>=0?1:n<=0?0:Math.max(0,1+i/n);return s*r*o}static formsAt(t,e=0){if(t<=-e)return[];const i=[ve.halo22(),ve.halo46()],n=t>0?ve.parheliaDistanceDeg(t):void 0;n!==void 0&&i.push({id:"parhelia",angleDeg:n,redAngleDeg:n,blueAngleDeg:ve.parheliaDistanceDeg(t,ve.ICE_INDEX_BLUE)}),i.push({id:"tangentArc",angleDeg:ve.halo22().angleDeg}),t>0&&i.push({id:"parhelicCircle",angleDeg:t});const s=ve.circumzenithalAltitudeDeg(t);return s!==void 0&&i.push({id:"circumzenithal",angleDeg:s}),t>ve.PLATE_END_FACE_LIMIT_DEG&&i.push({id:"circumhorizontal"}),t<ve.PILLAR_MAX_SOURCE_ALTITUDE_DEG&&i.push({id:"pillar"}),i}static PILLAR_MAX_SOURCE_ALTITUDE_DEG=20}class dn{static get WATER_INDEX_RED(){return bi.indexAt(bi.RED_NM)}static get WATER_INDEX_BLUE(){return bi.indexAt(bi.BLUE_NM)}static radiusDeg(t,e){const i=(e*e-1)/(t*t-1);if(i<0||i>1)return Number.NaN;const n=Math.acos(Math.sqrt(i)),s=Math.asin(Math.sin(n)/e),r=2*(n-s)+(t-1)*(Math.PI-2*s),o=2*Math.PI;let c=r%o;return c<0&&(c+=o),c>Math.PI&&(c=o-c),180-c*180/Math.PI}static primary(){return dn.bowOf("primary",2,0)}static secondary(){return dn.bowOf("secondary",3,0)}static bowOf(t,e,i){const n=dn.radiusDeg(e,dn.WATER_INDEX_RED),s=dn.radiusDeg(e,dn.WATER_INDEX_BLUE),r=(n+s)/2;return{id:t,radiusDeg:r,redRadiusDeg:n,violetRadiusDeg:s,topAltitudeDeg:r-i}}static alexandersBandDeg(){return{fromDeg:dn.primary().redRadiusDeg,toDeg:dn.secondary().redRadiusDeg}}static formsAt(t){return t<0?[]:[dn.bowOf("primary",2,t),dn.bowOf("secondary",3,t)].filter(e=>e.topAltitudeDeg>0)}static FULL_MOON_MAGNITUDE=-12.7;static moonlightShare(t){return Math.min(1,10**(-.4*(t-dn.FULL_MOON_MAGNITUDE)))}static strength(t,e,i){if(i<=0)return 0;const n=Math.max(0,Math.min(1,t)),s=Math.max(0,1-Math.max(0,Math.min(1,e)));return n*s}}class fn{constructor(t){this.radius=t;const e=fn.SEGMENTS*fn.VERTICES_PER_SEGMENT;this.positions=new Float32Array(e*3),this.colors=new Float32Array(e*3);const i=new se;i.setAttribute("position",new Jt(this.positions,3)),i.setAttribute("color",new Jt(this.colors,3)),i.setDrawRange(0,0),this.object=new bt(i,On.material()),this.object.frustumCulled=!1,On.track(this.object)}static POINTS=24;static SEGMENTS=fn.POINTS-1;static ACROSS=3;static VERTICES_PER_SEGMENT=(fn.ACROSS-1)*6;static HEAD_HALF_WIDTH_DEG=.15;static SPREAD_FRACTION=.05;static FADE_POWER=1.8;object;positions;colors;head;tip;brightness=0;set(t,e,i){this.head=t&&Ze(t.altitudeDeg,t.azimuthDeg,1),this.tip=e&&Ze(e.altitudeDeg,e.azimuthDeg,1),this.brightness=i,this.rebuild()}rebuild(){const t=this.object.geometry,e=this.head,i=this.tip;if(!e||!i||this.brightness<=0){t.setDrawRange(0,0);return}const n=this.angleBetween(e,i);if(n<=0){t.setDrawRange(0,0);return}const s=n*fn.SPREAD_FRACTION*Math.PI/180,r=h=>this.scale(this.slerp(e,i,h),this.radius),o=h=>this.radius*(fn.HEAD_HALF_WIDTH_DEG*Math.PI/180+s*h),c=h=>this.brightness*(1-h)**fn.FADE_POWER;let l=0;for(let h=1;h<fn.POINTS;h++){const u=(h-1)/fn.SEGMENTS,d=h/fn.SEGMENTS;l=this.pushBand(l,r(u),r(d),o(u),o(d),c(u),c(d))}t.setDrawRange(0,l),t.getAttribute("position").needsUpdate=!0,t.getAttribute("color").needsUpdate=!0}pushBand(t,e,i,n,s,r,o){const c=this.normalise(this.cross(this.normalise(e),this.normalise(this.subtract(i,e))));for(let l=0;l<fn.ACROSS-1;l++){const h=l-1,u=l,d=this.across(e,c,n,h),f=this.across(i,c,s,h),p=this.across(e,c,n,u),v=this.across(i,c,s,u),m=(g,S)=>g===0?S:0;t=this.push(t,d,m(h,r)),t=this.push(t,f,m(h,o)),t=this.push(t,p,m(u,r)),t=this.push(t,f,m(h,o)),t=this.push(t,v,m(u,o)),t=this.push(t,p,m(u,r))}return t}across(t,e,i,n){return{x:t.x+e.x*i*n,y:t.y+e.y*i*n,z:t.z+e.z*i*n}}push(t,e,i){const n=t*3;this.positions[n]=e.x,this.positions[n+1]=e.y,this.positions[n+2]=e.z;const s=Et.relativeOfResponse(Math.max(0,Math.min(1,i)));return this.colors[n]=s*.55,this.colors[n+1]=s*.75,this.colors[n+2]=s,t+1}slerp(t,e,i){const n=this.angleBetweenRadians(t,e);if(n<1e-9)return t;const s=Math.sin(n),r=Math.sin((1-i)*n)/s,o=Math.sin(i*n)/s;return{x:t.x*r+e.x*o,y:t.y*r+e.y*o,z:t.z*r+e.z*o}}angleBetween(t,e){return this.angleBetweenRadians(t,e)*180/Math.PI}angleBetweenRadians(t,e){const i=t.x*e.x+t.y*e.y+t.z*e.z;return Math.acos(Math.min(1,Math.max(-1,i)))}scale(t,e){return{x:t.x*e,y:t.y*e,z:t.z*e}}subtract(t,e){return{x:t.x-e.x,y:t.y-e.y,z:t.z-e.z}}cross(t,e){return{x:t.y*e.z-t.z*e.y,y:t.z*e.x-t.x*e.z,z:t.x*e.y-t.y*e.x}}normalise(t){const e=Math.hypot(t.x,t.y,t.z)||1;return{x:t.x/e,y:t.y/e,z:t.z/e}}dispose(){this.object.geometry.dispose(),this.object.material.dispose()}}class V5{object=new Re;radius;tiers;drawn=[];constructor(t){this.radius=t,this.object.name="satellites",this.tiers=Xa.map(e=>{const i=new mn(new se,Dt.material(e.size));return Dt.track(i),i.frustumCulled=!1,this.object.add(i),i})}set(t,e,i,n){const s=this.tiers.map(()=>[]);this.drawn=[];for(const r of t){if(r.magnitude>e)continue;const o=i(r.position);if(o<=0)continue;const c=r.magnitude-2.5*Math.log10(o);if(c>e)continue;const l=Ca(c,e),h=Q0(l),{x:u,y:d,z:f}=Ze(r.position.altitudeDeg,r.position.azimuthDeg,this.radius),[p,v,m]=n(r.position,c);s[h].push({x:u,y:d,z:f,r:p,g:v,b:m,seed:r.norad*.6180339887%1}),this.drawn.push({satellite:r,direction:new R(u,d,f).normalize()})}this.tiers.forEach((r,o)=>{const c=s[o],l=new Float32Array(c.length*3),h=new Float32Array(c.length*3),u=new Float32Array(c.length);c.forEach((f,p)=>{l.set([f.x,f.y,f.z],p*3),h.set([f.r,f.g,f.b],p*3),u[p]=f.seed}),r.geometry.dispose();const d=new se;d.setAttribute("position",new Jt(l,3)),d.setAttribute("color",new Jt(h,3)),d.setAttribute("seed",new Jt(u,1)),r.geometry=d})}get count(){return this.drawn.length}nearest(t,e){let i,n=e;for(const s of this.drawn){const r=s.direction.dot(t);r>n&&(n=r,i=s.satellite)}return i}dispose(){for(const t of this.tiers)t.geometry.dispose(),t.material.dispose();this.object.removeFromParent(),this.drawn=[]}}class Qi{static RADIUS=840;static MAX_SEGMENTS=256;static VERTICES_PER_SEGMENT=12;static MIN_HALF_WIDTH_DEG=.05;static BRIGHT_HALF_WIDTH_DEG=.22;static TRAIN_SHARE=.6;object=new Re;tiers;trains;positions;colors;shown=0;constructor(){this.object.name="reentries",this.tiers=Xa.map(i=>{const n=new mn(new se,Dt.material(i.size,!1));return Dt.track(n),n.frustumCulled=!1,this.object.add(n),n});const t=Qi.MAX_SEGMENTS*Qi.VERTICES_PER_SEGMENT;this.positions=new Float32Array(t*3),this.colors=new Float32Array(t*3);const e=new se;e.setAttribute("position",new Jt(this.positions,3)),e.setAttribute("color",new Jt(this.colors,3)),e.setDrawRange(0,0),this.trains=new bt(e,On.material()),this.trains.frustumCulled=!1,On.track(this.trains),this.object.add(this.trains)}get count(){return this.shown}set(t,e,i,n){const s=this.tiers.map(()=>[]);let r=0,o=0;const c=new st;for(const h of t){const u=i(h.head);if(u<=0)continue;const d=h.magnitude-2.5*Math.log10(u);if(d>e)continue;o++,c.set(h.color);const f=Ca(d,e),{x:p,y:v,z:m}=Ze(h.head.altitudeDeg,h.head.azimuthDeg,Qi.RADIUS),[g,S,x]=n(h.head,d),M=Math.max(c.r,c.g,c.b)||1;s[Q0(f)].push({x:p,y:v,z:m,r:g*c.r/M,g:S*c.g/M,b:x*c.b/M}),r=this.pushTrain(r,h.train,f,c)}this.shown=o,this.tiers.forEach((h,u)=>{const d=s[u],f=new Float32Array(d.length*3),p=new Float32Array(d.length*3);d.forEach((m,g)=>{f.set([m.x,m.y,m.z],g*3),p.set([m.r,m.g,m.b],g*3)}),h.geometry.dispose();const v=new se;v.setAttribute("position",new Jt(f,3)),v.setAttribute("color",new Jt(p,3)),h.geometry=v});const l=this.trains.geometry;l.setDrawRange(0,r),l.getAttribute("position").needsUpdate=!0,l.getAttribute("color").needsUpdate=!0}pushTrain(t,e,i,n){const s=e.length-1;for(let r=0;r<s;r++){if(t+Qi.VERTICES_PER_SEGMENT>Qi.MAX_SEGMENTS*Qi.VERTICES_PER_SEGMENT)return t;const o=1-r/s,c=1-(r+1)/s,l=Ze(e[r].altitudeDeg,e[r].azimuthDeg,Qi.RADIUS),h=Ze(e[r+1].altitudeDeg,e[r+1].azimuthDeg,Qi.RADIUS),u=f=>Qi.RADIUS*((Qi.MIN_HALF_WIDTH_DEG+Qi.BRIGHT_HALF_WIDTH_DEG*i*f)*Math.PI/180),d=f=>Qi.TRAIN_SHARE*i*f**1.6;t=this.pushRibbon(t,l,h,u(o),u(c),d(o),d(c),n)}return t}pushRibbon(t,e,i,n,s,r,o,c){const l={x:i.x-e.x,y:i.y-e.y,z:i.z-e.z};if(Math.hypot(l.x,l.y,l.z)<1e-9)return t;const h=this.normalise(this.cross(this.normalise(e),this.normalise(l)));for(const[u,d]of[[-1,0],[0,1]]){const f=this.across(e,h,n,u),p=this.across(i,h,s,u),v=this.across(e,h,n,d),m=this.across(i,h,s,d),g=(S,x)=>S===0?x:0;t=this.push(t,f,g(u,r),c),t=this.push(t,p,g(u,o),c),t=this.push(t,v,g(d,r),c),t=this.push(t,p,g(u,o),c),t=this.push(t,m,g(d,o),c),t=this.push(t,v,g(d,r),c)}return t}across(t,e,i,n){return{x:t.x+e.x*i*n,y:t.y+e.y*i*n,z:t.z+e.z*i*n}}push(t,e,i,n){const s=t*3;this.positions[s]=e.x,this.positions[s+1]=e.y,this.positions[s+2]=e.z;const r=Et.relativeOfResponse(Math.max(0,Math.min(1,i)));return this.colors[s]=r*n.r,this.colors[s+1]=r*n.g,this.colors[s+2]=r*n.b,t+1}cross(t,e){return{x:t.y*e.z-t.z*e.y,y:t.z*e.x-t.x*e.z,z:t.x*e.y-t.y*e.x}}normalise(t){const e=Math.hypot(t.x,t.y,t.z)||1;return{x:t.x/e,y:t.y/e,z:t.z/e}}dispose(){for(const t of this.tiers)t.geometry.dispose(),t.material.dispose();this.trains.geometry.dispose(),this.trains.material.dispose(),this.object.removeFromParent()}}class bh{constructor(t){this.state=t}next(){this.state=this.state+1831565813|0;let t=this.state;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}between(t,e){return t+this.next()*(e-t)}}class Gr{static MIN_DURATION_MS=250;static MAX_DURATION_MS=1400;static schedule(t){const{ratePerHour:e,durationMs:i,velocityKmS:n,seed:s}=t;if(e<=0||i<=0)return[];const r=e*i/36e5,o=new bh(s),c=Math.floor(r),l=c+(o.next()<r-c?1:0),h=[];for(let u=0;u<l;u++){const d=Math.min(1,Math.max(0,(n-20)/52)),f=Gr.MAX_DURATION_MS-d*(Gr.MAX_DURATION_MS-Gr.MIN_DURATION_MS),p=o.between(5,70);h.push({t:o.between(0,i),durationMs:f*o.between(.7,1.3),fromRadiantDeg:p,bearingDeg:o.between(0,360),lengthDeg:Math.sin(p*Math.PI/180)*o.between(8,40)*(.6+d),brightness:o.next()**3}),h.sort((v,m)=>v.t-m.t)}return h}static aliveAt(t,e){return t.filter(i=>e>=i.t&&e<=i.t+i.durationMs).map(i=>({meteor:i,progress:(e-i.t)/i.durationMs}))}}class nr{object=new Re;radius;core;glow;flashKey;static CORE_WIDTH_DEG=.06;static GLOW_WIDTH_DEG=.5;static SEGMENTS=28;static CORE_RELATIVE=1e3;constructor(t){this.radius=t,this.object.name="lightning-bolt",this.core=new _n({color:15659775,transparent:!0,opacity:0,blending:Ai,depthWrite:!1,fog:!1}),this.glow=new _n({color:10466559,transparent:!0,opacity:0,blending:Ai,depthWrite:!1,fog:!1}),this.object.visible=!1,this.object.renderOrder=5.95}set(t,e,i){if(!t||!t.cloudToGround||e<=.01){this.object.visible=!1;return}const n=`${t.channelSeed}:${Math.round(i)}`;n!==this.flashKey&&this.build(t,i,n),this.core.color.setHex(15659775).multiplyScalar(nr.CORE_RELATIVE*Math.min(1,e*1.4)),this.glow.color.setHex(10466559).multiplyScalar(.1*nr.CORE_RELATIVE*e*.35),this.core.opacity=1,this.glow.opacity=1,this.object.visible=!0}build(t,e,i){this.flashKey=i;for(const l of[...this.object.children])l.geometry.dispose(),this.object.remove(l);const n=new bh(t.channelSeed),s=Math.atan2(e,t.distanceM)*180/Math.PI,r=this.channel(n,t.azimuthDeg,s,0,1),o=[r],c=1+Math.floor(n.next()*2);for(let l=0;l<c;l++){const h=r[Math.floor(n.between(.15,.5)*r.length)];o.push(this.channel(n,h.azimuthDeg,h.altitudeDeg,h.altitudeDeg*n.between(.3,.7),.5))}for(const l of o)this.object.add(new bt(this.ribbon(l,nr.GLOW_WIDTH_DEG),this.glow)),this.object.add(new bt(this.ribbon(l,nr.CORE_WIDTH_DEG),this.core))}channel(t,e,i,n,s){const r=[],o=i-n;let c=e;for(let l=0;l<=nr.SEGMENTS;l++){const h=i-o*l/nr.SEGMENTS;r.push({azimuthDeg:c,altitudeDeg:h}),c+=t.between(-1,1)*o*.06*s}return r}ribbon(t,e){const i=new Float32Array(t.length*2*3),n=[],s=this.radius*Math.tan(e*Math.PI/180)/2,r=t.map(c=>{const{x:l,y:h,z:u}=Ze(c.altitudeDeg,c.azimuthDeg,this.radius);return new R(l,h,u)});r.forEach((c,l)=>{const h=r[Math.min(l+1,r.length-1)],u=r[Math.max(l-1,0)],f=h.clone().sub(u).normalize().cross(c.clone().normalize()).normalize().multiplyScalar(s);if(i.set([c.x+f.x,c.y+f.y,c.z+f.z],l*6),i.set([c.x-f.x,c.y-f.y,c.z-f.z],l*6+3),l<r.length-1){const p=l*2;n.push(p,p+1,p+2,p+1,p+3,p+2)}});const o=new se;return o.setAttribute("position",new Jt(i,3)),o.setIndex(n),o}dispose(){for(const t of this.object.children)t.geometry.dispose();this.core.dispose(),this.glow.dispose(),this.object.removeFromParent()}}class gi{static MIN_INTERVAL_S=8;static MAX_INTERVAL_S=25;static SEVERE_MIN_INTERVAL_S=2;static SEVERE_MAX_INTERVAL_S=8;static CLOUD_TO_GROUND_FRACTION=.25;static MIN_DISTANCE_M=1e3;static MAX_DISTANCE_M=15e3;static INTERSTROKE_MS=60;static STROKE_DECAY_MS=40;static SOUND_SPEED_M_S=343;static schedule(t){const e=new bh(t.seed),i=[],{minS:n,maxS:s}=gi.intervalFor(t.intensity??.5);let r=e.between(0,s)*1e3;for(;r<t.durationMs;){const o=e.next()<gi.CLOUD_TO_GROUND_FRACTION,c=gi.MIN_DISTANCE_M,l=gi.MAX_DISTANCE_M,h=Math.sqrt(e.between(c*c,l*l)),u=o?1+Math.floor(e.next()*4):1,d=[];let f=0;for(let p=0;p<u;p++)d.push({offsetMs:f,intensity:p===0?1:e.between(.4,.9)}),f+=gi.INTERSTROKE_MS*e.between(.5,1.6);i.push({t:r,azimuthDeg:e.between(0,360),distanceM:h,cloudToGround:o,strokes:d,channelSeed:Math.floor(e.next()*2**31)}),r+=e.between(n,s)*1e3}return i}static intervalFor(t){const e=Math.min(1,Math.max(0,(t-.5)/.5));return{minS:gi.MIN_INTERVAL_S-e*(gi.MIN_INTERVAL_S-gi.SEVERE_MIN_INTERVAL_S),maxS:gi.MAX_INTERVAL_S-e*(gi.MAX_INTERVAL_S-gi.SEVERE_MAX_INTERVAL_S)}}static brightnessAt(t,e){let i=0;for(const n of t.strokes){const s=e-t.t-n.offsetMs;s<0||s>gi.STROKE_DECAY_MS*6||(i+=n.intensity*Math.exp(-s/gi.STROKE_DECAY_MS))}return Math.min(1,i)}static endOf(t){const e=t.strokes[t.strokes.length-1];return t.t+e.offsetMs+gi.STROKE_DECAY_MS*6}static thunderDelayMs(t){return t.distanceM/gi.SOUND_SPEED_M_S*1e3}}class tn{static RED_NM=656.3;static BLUE_NM=435.8;static ANCHOR_RED=1.3067;static ANCHOR_BLUE=1.317;static B=(tn.ANCHOR_BLUE-tn.ANCHOR_RED)/(1/(tn.BLUE_NM*tn.BLUE_NM)-1/(tn.RED_NM*tn.RED_NM));static A=tn.ANCHOR_RED-tn.B/(tn.RED_NM*tn.RED_NM);static indexAt(t){return tn.A+tn.B/(t*t)}}class hc{normals=new Float64Array(24);offsets=new Float64Array(8);radius=1;set(t,e,i,n,s,r){let o=0,c=0,l=0;Math.abs(i)<.9?(o=-e,c=t,l=0):(o=0,c=-i,l=e);const h=Math.hypot(o,c,l)||1;o/=h,c/=h,l/=h;const u=e*l-i*c,d=i*o-t*l,f=t*c-e*o,p=s/2,v=r/2;for(let m=0;m<6;m++){const g=n+m*Math.PI/3,S=Math.cos(g),x=Math.sin(g);this.normals[m*3]=o*S+u*x,this.normals[m*3+1]=c*S+d*x,this.normals[m*3+2]=l*S+f*x,this.offsets[m]=p}this.normals[18]=t,this.normals[19]=e,this.normals[20]=i,this.offsets[6]=v,this.normals[21]=-t,this.normals[22]=-e,this.normals[23]=-i,this.offsets[7]=v,this.radius=Math.hypot(p,v)}get aimRadius(){return this.radius}trace(t,e,i,n,s,r,o){let c=-e,l=t,h=0,u=Math.hypot(c,l,h);u<1e-6&&(c=1,l=0,h=0,u=1),c/=u,l/=u,h/=u;const d=e*h-i*l,f=i*c-t*h,p=t*l-e*c,v=c*n+d*s-t*this.radius*2,m=l*n+f*s-e*this.radius*2,g=h*n+p*s-i*this.radius*2;let S=-1,x=-1/0,M=1/0;for(let J=0;J<8;J++){const it=this.normals[J*3],at=this.normals[J*3+1],Xt=this.normals[J*3+2],ee=it*t+at*e+Xt*i,Kt=this.offsets[J]-(it*v+at*m+Xt*g);if(ee>1e-9){const q=Kt/ee;q<M&&(M=q)}else if(ee<-1e-9){const q=Kt/ee;q>x&&(x=q,S=J)}else if(Kt<0)return 0}if(S<0||x>=M)return 0;let b=0;const w=this.normals[S*3],T=this.normals[S*3+1],y=this.normals[S*3+2],A=-(w*t+T*e+y*i),C=jl.reflectance(A,1,r);o[b].x=t+2*A*w,o[b].y=e+2*A*T,o[b].z=i+2*A*y,o[b].weight=C,b++;const I=1/r,P=Math.sqrt(Math.max(0,1-I*I*(1-A*A)));let V=I*t+(I*A-P)*w,X=I*e+(I*A-P)*T,L=I*i+(I*A-P)*y,B=v+t*x,k=m+e*x,$=g+i*x,tt=1-C;for(let J=0;J<hc.MAX_BOUNCES&&tt>hc.MIN_WEIGHT;J++){let it=-1,at=1/0;for(let z=0;z<8;z++){const Rt=this.normals[z*3],Ft=this.normals[z*3+1],Pt=this.normals[z*3+2],St=Rt*V+Ft*X+Pt*L;if(St<=1e-9)continue;const zt=(this.offsets[z]-(Rt*B+Ft*k+Pt*$))/St;zt>1e-9&&zt<at&&(at=zt,it=z)}if(it<0)break;const Xt=this.normals[it*3],ee=this.normals[it*3+1],Kt=this.normals[it*3+2],q=Xt*V+ee*X+Kt*L,rt=r*Math.sqrt(Math.max(0,1-q*q));if(B+=V*at,k+=X*at,$+=L*at,rt<1){const z=Math.sqrt(Math.max(0,1-rt*rt)),Rt=jl.reflectance(q,r,1);if(o[b].x=r*V-(r*q-z)*Xt,o[b].y=r*X-(r*q-z)*ee,o[b].z=r*L-(r*q-z)*Kt,o[b].weight=tt*(1-Rt),b++,b>=o.length)return b;tt*=Rt}const nt=2*q;V-=nt*Xt,X-=nt*ee,L-=nt*Kt}return b}static MAX_BOUNCES=6;static MIN_WEIGHT=1e-4}class Xe{static AZIMUTH_BINS=512;static ALTITUDE_BINS=512;static POPULATIONS=[{orientation:"tumbling",widthMicrons:50,lengthMicrons:50,share:.52},{orientation:"plate",widthMicrons:100,lengthMicrons:15,share:.27},{orientation:"column",widthMicrons:40,lengthMicrons:120,share:.19},{orientation:"parry",widthMicrons:40,lengthMicrons:120,share:.02}];static WORST_TILT_DEG=180;static BEST_TILT_DEG=.5;static SOURCE_RADIUS_DEG=.265;static UNDEVIATED_DEG=.6;crystal=new hc;emergent=Array.from({length:hc.MAX_BOUNCES+2},()=>({x:0,y:0,z:0,weight:0}));tally=new Float32Array(Xe.AZIMUTH_BINS*Xe.ALTITUDE_BINS*3);radiance=new Float32Array(Xe.AZIMUTH_BINS*Xe.ALTITUDE_BINS*3);scratch=new Float32Array(Xe.AZIMUTH_BINS*Xe.ALTITUDE_BINS*3);seed=1;spare=0;hasSpare=!1;altitude=0;tilt=0;alignment=0;traced=0;begin(t,e,i=2654435769){this.seed=i>>>0||1,this.hasSpare=!1,this.tally.fill(0),this.traced=0,this.altitude=t*Math.PI/180,this.alignment=Math.min(1,Math.max(0,e));const n=Xe.WORST_TILT_DEG*(Xe.BEST_TILT_DEG/Xe.WORST_TILT_DEG)**this.alignment;this.tilt=n*Math.PI/180}trace(t){const e=Xe.AZIMUTH_BINS,i=Xe.ALTITUDE_BINS,n=this.tally,s=Xe.SOURCE_RADIUS_DEG*Math.PI/180,r=Math.cos(Xe.UNDEVIATED_DEG*Math.PI/180),o=this.altitude;for(let c=0;c<t;c++){const l=this.pickPopulation();this.orient(l,this.tilt);const h=this.random()*2*Math.PI,u=s*Math.sqrt(this.random()),d=o+u*Math.sin(h),f=u*Math.cos(h)/Math.max(.05,Math.cos(o)),p=-Math.cos(d)*Math.cos(f),v=-Math.cos(d)*Math.sin(f),m=-Math.sin(d),g=this.crystal.aimRadius,S=(this.random()*2-1)*g,x=(this.random()*2-1)*g,M=4*g*g,b=vi.SAMPLES[this.random()*vi.SAMPLES.length|0],w=this.crystal.trace(p,v,m,S,x,tn.indexAt(b.wavelengthNm),this.emergent);for(let T=0;T<w;T++){const y=this.emergent[T],A=Math.hypot(y.x,y.y,y.z);if(A<1e-9||y.weight<=0)continue;const C=y.x/A,I=y.y/A,P=y.z/A;if(C*p+I*v+P*m>r)continue;const V=Math.asin(Math.max(-1,Math.min(1,-P))),X=Math.abs(Math.atan2(-I,-C)),L=Math.min(e-1,X/Math.PI*e|0),k=(Math.min(i-1,(V+Math.PI/2)/Math.PI*i|0)*e+L)*3,$=y.weight*M*vi.SAMPLES.length;n[k]+=$*b.r,n[k+1]+=$*b.g,n[k+2]+=$*b.b}}this.traced+=t}get tracedRays(){return this.traced}harvest(){const t=Xe.AZIMUTH_BINS,e=Xe.ALTITUDE_BINS;return this.toRadiance(t,e),this.smooth(t,e),{width:t,height:e,data:this.radiance,sourceAltitudeDeg:this.altitude*180/Math.PI,alignment:this.alignment,rays:this.traced}}compute(t,e,i,n){return this.begin(t,e,n),this.trace(i),this.harvest()}toRadiance(t,e){const i=2*Math.PI/t,n=Math.max(1,this.traced),s=4*Xe.REFERENCE_MICRONS*Xe.REFERENCE_MICRONS;for(let r=0;r<e;r++){const o=Math.sin(r/e*Math.PI-Math.PI/2),c=Math.sin((r+1)/e*Math.PI-Math.PI/2),l=1/(i*(c-o)*n*s);for(let h=0;h<t;h++){const u=(r*t+h)*3;this.radiance[u]=this.tally[u]*l,this.radiance[u+1]=this.tally[u+1]*l,this.radiance[u+2]=this.tally[u+2]*l}}}static REFERENCE_MICRONS=50;smooth(t,e){const i=this.scratch,n=this.radiance;i.set(n);for(let r=0;r<e;r++){const o=r*t*3;for(let c=0;c<3;c++){let l=i[o+c];for(let h=0;h<t;h++){const u=o+h*3+c,d=h+1<t?i[u+3]:i[u];n[u]=(l+2*i[u]+d)/4,l=i[u]}}}i.set(n);const s=t*3;for(let r=0;r<e;r++){const o=r>0?-s:0,c=r+1<e?s:0,l=r*s;for(let h=l;h<l+s;h++)n[h]=(i[h+o]+2*i[h]+i[h+c])/4}}pickPopulation(){const t=this.random();let e=0;for(const i of Xe.POPULATIONS)if(e+=i.share,t<=e)return i;return Xe.POPULATIONS[Xe.POPULATIONS.length-1]}orient(t,e){const i=this.random()*2*Math.PI;let n=this.random()*2*Math.PI,s=0,r=0,o=1;switch(t.orientation){case"tumbling":{o=this.random()*2-1;const c=Math.sqrt(Math.max(0,1-o*o));s=c*Math.cos(i),r=c*Math.sin(i);break}case"plate":{o=this.spreadAboutAnAxis(e);const c=Math.sqrt(Math.max(0,1-o*o));s=c*Math.cos(i),r=c*Math.sin(i);break}case"column":case"parry":{o=this.spreadAboutAPlane(e);const c=Math.sqrt(Math.max(0,1-o*o));s=c*Math.cos(i),r=c*Math.sin(i),t.orientation==="parry"&&(n=Math.PI/2+this.gaussian()*e);break}}this.crystal.set(s,r,o,n,t.widthMicrons,t.lengthMicrons)}random(){this.seed=this.seed+1831565813>>>0;let t=this.seed;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}spreadAboutAnAxis(t){const e=1/Math.max(1e-6,t*t),i=Math.max(1e-12,this.random()),n=1+Math.log(i+(1-i)*Math.exp(-2*e))/e;return Math.max(-1,Math.min(1,n))}spreadAboutAPlane(t){for(let e=0;e<8;e++){const i=this.gaussian()*t;if(i>=-1&&i<=1)return i}return this.random()*2-1}gaussian(){if(this.hasSpare)return this.hasSpare=!1,this.spare;const t=Math.sqrt(-2*Math.log(Math.max(1e-12,this.random()))),e=2*Math.PI*this.random();return this.spare=t*Math.sin(e),this.hasSpare=!0,t*Math.cos(e)}}class W5{static fromRadiance(t,e){const i=Ln.toHalfFloat(1);for(let n=0,s=0;s<t.length;n+=4,s+=3)e[n]=Ln.toHalfFloat(t[s]),e[n+1]=Ln.toHalfFloat(t[s+1]),e[n+2]=Ln.toHalfFloat(t[s+2]),e[n+3]=i}}class Ti{static RADIUS=880;static RAYS=9e5;static RAYS_PER_BATCH=2e3;static BUDGET_MS=6;static URGENT_BUDGET_MS=40;static ALTITUDE_STEP_DEG=1;static ALIGNMENT_STEP=.05;static LEAP_ALTITUDE_DEG=5;static LEAP_ALIGNMENT=.25;static GAIN=.55;setCloudOffset(t){this.material.uniforms.uFieldOffset.value.copy(t)}object;material;sky=new Xe;texture;texels;mappedAltitudeDeg=Number.NaN;mappedAlignment=Number.NaN;tracing=!1;everDisplayed=!1;urgent=!1;workHandle;onRepaint;constructor(){const t=Xe.AZIMUTH_BINS,e=Xe.ALTITUDE_BINS;this.texels=new Uint16Array(t*e*4),this.texture=new Mr(this.texels,t,e,Di,$e),this.texture.minFilter=le,this.texture.magFilter=le,this.texture.wrapS=Ri,this.texture.wrapT=Ri,this.texture.needsUpdate=!0,this.material=new fe({uniforms:{uSource:{value:new R(0,1,0)},uUp:{value:new R(0,1,0)},uStrength:{value:0},uTint:{value:new R(1,.97,.92)},uIceCover:{value:0},uIceHeight:{value:1},uFieldOffset:{value:new R},uMap:{value:this.texture},uGain:{value:Ti.GAIN}},vertexShader:`
7263
7263
  varying vec3 vDirection;
7264
7264
  void main() {
7265
7265
  vDirection = normalize((modelMatrix * vec4(position, 1.0)).xyz - cameraPosition);
@@ -7288,8 +7288,8 @@ ${Dt.OUTPUT_PROJECTION_GLSL}`)}}class Hi{constructor(t,e){this.width=t,this.heig
7288
7288
  if (ice <= 0.0) discard;
7289
7289
  gl_FragColor = vec4(iceHaloLight(dir, ice), 1.0);
7290
7290
  }
7291
- `,transparent:!0,blending:Ai,depthWrite:!1,side:qe,fog:!1}),this.object=new bt(new di(Ti.RADIUS,64,32),this.material),this.object.renderOrder=-1,this.object.frustumCulled=!1,this.object.visible=!1;const i=this.material.uniforms;this.deckUniforms={uSource:i.uSource,uUp:i.uUp,uStrength:i.uStrength,uTint:i.uTint,uMap:i.uMap,uGain:i.uGain,uHaloShown:{value:0}}}deckUniforms;shown=!1;hostedByDeck=!1;set hosted(t){this.hostedByDeck=t,this.show(this.shown)}show(t){this.shown=t,this.object.visible=t&&!this.hostedByDeck,this.deckUniforms.uHaloShown.value=t?1:0}get awaitingFirstDisplay(){return this.tracing&&!this.everDisplayed}setUrgent(t){this.urgent=t}set onReady(t){this.onRepaint=t}update(t,e,i,n,s,r){const o=this.material.uniforms;if(i<=0){o.uStrength.value=0,this.show(!1),this.stopWork();return}o.uSource.value.set(t.x,t.y,t.z).normalize(),o.uStrength.value=i,o.uTint.value.set(n[0],n[1],n[2]),o.uIceCover.value=s.cover,o.uIceHeight.value=s.layerHeight,this.show(this.everDisplayed),this.requestMap(e,r)}requestMap(t,e){if(!(!(Math.abs(t-this.mappedAltitudeDeg)<Ti.ALTITUDE_STEP_DEG)||!(Math.abs(e-this.mappedAlignment)<Ti.ALIGNMENT_STEP))){this.next=void 0;return}if(this.tracing){if(this.tracingFor(t,e)){this.next=void 0;return}if(!(!(Math.abs(t-this.pendingAltitudeDeg)<Ti.LEAP_ALTITUDE_DEG)||!(Math.abs(e-this.pendingAlignment)<Ti.LEAP_ALIGNMENT))){this.next={sourceAltitudeDeg:t,alignment:e};return}}this.next=void 0,this.pendingAltitudeDeg=t,this.pendingAlignment=e,this.stopWork(),this.tracing=!0,this.startTracing(t,e)}startTracing(t,e){const i=++this.ticket,n=()=>{i!==this.ticket||!this.tracing||(this.sky.begin(t,e),this.scheduleWork())};or.with(s=>{i!==this.ticket||!this.tracing||(this.job=s.trace(t,e,Ti.RAYS,r=>{this.job=void 0,this.texels.set(r),this.display(),this.finishTracing()},n))},n)}ticket=0;job;pendingAltitudeDeg=Number.NaN;pendingAlignment=Number.NaN;next;tracingFor(t,e){return this.tracing&&Math.abs(t-this.pendingAltitudeDeg)<Ti.ALTITUDE_STEP_DEG&&Math.abs(e-this.pendingAlignment)<Ti.ALIGNMENT_STEP}scheduleWork(){if(this.workHandle!==void 0)return;const t=()=>{if(this.workHandle=void 0,!this.tracing)return;const e=performance.now(),i=this.urgent?Ti.URGENT_BUDGET_MS:Ti.BUDGET_MS;do this.sky.trace(Ti.RAYS_PER_BATCH);while(this.sky.tracedRays<Ti.RAYS&&performance.now()-e<i);if(this.sky.tracedRays>=Ti.RAYS){this.publish(),this.finishTracing();return}this.workHandle=requestAnimationFrame(t)};this.workHandle=requestAnimationFrame(t)}finishTracing(){this.tracing=!1,this.mappedAltitudeDeg=this.pendingAltitudeDeg,this.mappedAlignment=this.pendingAlignment;const t=this.next;t&&this.requestMap(t.sourceAltitudeDeg,t.alignment)}stopWork(){this.ticket++,this.job?.cancel(),this.job=void 0,this.workHandle!==void 0&&cancelAnimationFrame(this.workHandle),this.workHandle=void 0,this.tracing=!1,this.next=void 0}publish(){W5.fromRadiance(this.sky.harvest().data,this.texels),this.display()}display(){this.texture.needsUpdate=!0,this.everDisplayed=!0,this.show(this.material.uniforms.uStrength.value>0),this.onRepaint?.()}dispose(){this.stopWork(),this.texture.dispose(),this.object.geometry.dispose(),this.material.dispose()}}class _i{static MAX_CONCURRENT=24;static POINTS=8;static SEGMENTS=_i.POINTS-1;static ACROSS=3;static VERTICES_PER_SEGMENT=(_i.ACROSS-1)*6;static RADIUS=840;static MIN_HALF_WIDTH_DEG=.05;static BRIGHT_HALF_WIDTH_DEG=.22;object;positions;colors;meteors=[];radiantAltitudeDeg=0;radiantAzimuthDeg=0;constructor(){const t=_i.MAX_CONCURRENT*_i.SEGMENTS*_i.VERTICES_PER_SEGMENT;this.positions=new Float32Array(t*3),this.colors=new Float32Array(t*3);const e=new se;e.setAttribute("position",new Jt(this.positions,3)),e.setAttribute("color",new Jt(this.colors,3)),e.setDrawRange(0,0),this.object=new bt(e,On.material()),this.object.frustumCulled=!1,On.track(this.object)}get schedule(){return this.meteors}setShower(t,e,i){this.meteors=t,this.radiantAltitudeDeg=e,this.radiantAzimuthDeg=i}update(t){const e=this.object.geometry;if(this.meteors.length===0){e.setDrawRange(0,0);return}const i=Gr.aliveAt(this.meteors,t).slice(0,_i.MAX_CONCURRENT);let n=0;for(const{meteor:s,progress:r}of i){const o=this.radiantOf(s);if(!o)continue;const c=Ze(o.altitudeDeg,o.azimuthDeg,1),[l,h]=this.basisAround(c),u=s.fromRadiantDeg+r*s.lengthDeg,d=Math.max(s.fromRadiantDeg,u-s.lengthDeg*.6),f=Math.min(1,(1-r)*2.5),p=this.turn(l,h,s.bearingDeg),v=(.15+.85*s.brightness)*f,m=x=>v*x**1.6,g=x=>this.onSphere(c,p,d+(u-d)*x),S=x=>_i.RADIUS*((_i.MIN_HALF_WIDTH_DEG+_i.BRIGHT_HALF_WIDTH_DEG*s.brightness*x)*Math.PI/180);for(let x=1;x<_i.POINTS;x++){const M=(x-1)/_i.SEGMENTS,b=x/_i.SEGMENTS;n=this.pushRibbon(n,g(M),g(b),S(M),S(b),m(M),m(b))}}e.setDrawRange(0,n),e.getAttribute("position").needsUpdate=!0,e.getAttribute("color").needsUpdate=!0}midpointOf(t){const e=this.radiantOf(t);if(!e)return;const i=Ze(e.altitudeDeg,e.azimuthDeg,1),[n,s]=this.basisAround(i),r=this.turn(n,s,t.bearingDeg),o=this.onSphere(i,r,t.fromRadiantDeg+t.lengthDeg/2),c=Math.hypot(o.x,o.y,o.z)||1;return{altitudeDeg:Math.asin(o.y/c)*180/Math.PI,azimuthDeg:(Math.atan2(o.x,-o.z)*180/Math.PI+360)%360}}radiantOf(t){return t.radiant?t.radiant:this.radiantAltitudeDeg>0?{altitudeDeg:this.radiantAltitudeDeg,azimuthDeg:this.radiantAzimuthDeg}:void 0}pushRibbon(t,e,i,n,s,r,o){const c=this.normalise(this.cross(this.normalise(e),this.normalise(this.subtract(i,e))));for(let l=0;l<_i.ACROSS-1;l++){const h=l-1,u=l,d=this.across(e,c,n,h),f=this.across(i,c,s,h),p=this.across(e,c,n,u),v=this.across(i,c,s,u),m=(g,S)=>g===0?S:0;t=this.push(t,d,m(h,r)),t=this.push(t,f,m(h,o)),t=this.push(t,p,m(u,r)),t=this.push(t,f,m(h,o)),t=this.push(t,v,m(u,o)),t=this.push(t,p,m(u,r))}return t}across(t,e,i,n){return{x:t.x+e.x*i*n,y:t.y+e.y*i*n,z:t.z+e.z*i*n}}push(t,e,i){const n=t*3;this.positions[n]=e.x,this.positions[n+1]=e.y,this.positions[n+2]=e.z;const s=Et.relativeOfResponse(Math.max(0,Math.min(1,i)));return this.colors[n]=s*.9,this.colors[n+1]=s*.95,this.colors[n+2]=s,t+1}turn(t,e,i){const n=i*Math.PI/180,s=Math.cos(n),r=Math.sin(n);return{x:t.x*s+e.x*r,y:t.y*s+e.y*r,z:t.z*s+e.z*r}}onSphere(t,e,i){const n=i*Math.PI/180,s=Math.cos(n),r=Math.sin(n);return{x:(t.x*s+e.x*r)*_i.RADIUS,y:(t.y*s+e.y*r)*_i.RADIUS,z:(t.z*s+e.z*r)*_i.RADIUS}}basisAround(t){const e=Math.abs(t.y)<.9?{x:0,y:1,z:0}:{x:1,y:0,z:0},i=this.normalise(this.cross(t,e));return[i,this.normalise(this.cross(t,i))]}subtract(t,e){return{x:t.x-e.x,y:t.y-e.y,z:t.z-e.z}}cross(t,e){return{x:t.y*e.z-t.z*e.y,y:t.z*e.x-t.x*e.z,z:t.x*e.y-t.y*e.x}}normalise(t){const e=Math.hypot(t.x,t.y,t.z)||1;return{x:t.x/e,y:t.y/e,z:t.z/e}}dispose(){this.object.geometry.dispose(),this.object.material.dispose()}}class Ue{constructor(t,e={}){this.size=t,this.span=Math.min(t.lengthM,Math.max(0,e.spanM??t.lengthM)),this.bank=(t.lengthM-this.span)/2,this.deck=Math.min(t.heightM,e.deckThicknessM??Ue.DEFAULT_DECK_THICKNESS_M),this.railHeight=e.railing?.heightM??Ue.DEFAULT_RAILING_HEIGHT_M,this.postSpacing=Math.max(.3,e.railing?.postSpacingM??Ue.DEFAULT_POST_SPACING_M),this.rails=Math.max(0,Math.round(e.railing?.rails??Ue.DEFAULT_RAILS))}static DEFAULT_DECK_THICKNESS_M=1.2;static DEFAULT_RAILING_HEIGHT_M=1.05;static DEFAULT_POST_SPACING_M=1.5;static DEFAULT_RAILS=2;static BANK_SLOPE=1.5;static ABUTMENT_THICKNESS_M=1;static POST_SIDE_M=.08;static RAIL_HEIGHT_M=.08;static RAIL_DEPTH_M=.06;static BANK_STATIONS=12;static NATURAL_SIZE=Object.freeze({widthM:9,lengthM:40,heightM:6.5});span;bank;deck;railHeight;postSpacing;rails;roadAt(t){const e=Math.abs(t)-this.span/2;return e<=0?this.size.heightM:this.bank<=0?0:Math.max(0,this.size.heightM*(1-e/this.bank))}build(){const{widthM:t,heightM:e}=this.size,i=this.span/2,n=[];if(this.span>0){n.push(Ue.box(t,this.deck,this.span,0,e-this.deck/2,0));for(const c of[-1,1]){const l=e-this.deck;l>0&&this.bank>0&&n.push(Ue.box(t+1,l,Ue.ABUTMENT_THICKNESS_M,0,l/2,c*(i-Ue.ABUTMENT_THICKNESS_M/2)))}}const s=[];this.span>0&&s.push(Ue.box(t,.04,this.span,0,e+.02,0));const r=[];for(const c of[-1,1])this.bank<=0||(r.push(this.embankment(c)),s.push(this.bankRoad(c)));const o=[];for(const c of[-1,1])o.push(...this.railing(c*(t/2-Ue.POST_SIDE_M)));return{concrete:Ue.merge(n),road:Ue.merge(s),earth:Ue.merge(r),railing:Ue.merge(o)}}embankment(t){const e=this.size.widthM/2,i=this.stations(t),n=[],s=(l,h,u,d)=>{n.push(l.x,l.y,l.z,h.x,h.y,h.z,u.x,u.y,u.z,l.x,l.y,l.z,u.x,u.y,u.z,d.x,d.y,d.z)},r=l=>{const h=this.roadAt(l),u=e+Ue.BANK_SLOPE*h;return{leftFoot:new R(-u,0,l),leftTop:new R(-e,h,l),rightTop:new R(e,h,l),rightFoot:new R(u,0,l)}};for(let l=1;l<i.length;l++){const h=r(i[l-1]),u=r(i[l]),d=t>0,f=(p,v,m,g)=>d?s(p,v,m,g):s(g,m,v,p);f(h.leftFoot,h.leftTop,u.leftTop,u.leftFoot),f(h.leftTop,h.rightTop,u.rightTop,u.leftTop),f(h.rightTop,h.rightFoot,u.rightFoot,u.rightTop)}const o=r(i[0]);t>0?s(o.leftFoot,o.rightFoot,o.rightTop,o.leftTop):s(o.leftTop,o.rightTop,o.rightFoot,o.leftFoot);const c=new se;return c.setAttribute("position",new ue(n,3)),c.computeVertexNormals(),c}bankRoad(t){const e=this.size.widthM/2,i=this.stations(t),n=[];for(let r=1;r<i.length;r++){const o=i[r-1],c=i[r],l=this.roadAt(o)+.02,h=this.roadAt(c)+.02,u=t>0?[[-e,l,o],[e,l,o],[e,h,c],[-e,h,c]]:[[-e,h,c],[e,h,c],[e,l,o],[-e,l,o]];for(const d of[0,2,1,0,3,2])n.push(...u[d])}const s=new se;return s.setAttribute("position",new ue(n,3)),s.computeVertexNormals(),s}stations(t){const e=[];for(let i=0;i<=Ue.BANK_STATIONS;i++)e.push(t*(this.span/2+this.bank*i/Ue.BANK_STATIONS));return e}railing(t){const e=this.size.lengthM/2,i=Math.max(1,Math.round(this.size.lengthM/this.postSpacing)),n=[];for(let o=0;o<=i;o++)n.push(-e+this.size.lengthM*o/i);const s=[],r=Ue.POST_SIDE_M;for(const o of n)s.push(Ue.box(r,this.railHeight,r,t,this.roadAt(o)+this.railHeight/2,o));for(let o=1;o<=this.rails;o++){const c=this.railHeight*o/this.rails-Ue.RAIL_HEIGHT_M/2;for(let l=1;l<n.length;l++){const h=new R(t,this.roadAt(n[l-1])+c,n[l-1]),u=new R(t,this.roadAt(n[l])+c,n[l]);s.push(Ue.beam(h,u))}}return s}static box(t,e,i,n,s,r){return new Ki(t,e,i).translate(n,s,r)}static beam(t,e){const i=new R().subVectors(e,t),n=new Ki(Ue.RAIL_DEPTH_M,Ue.RAIL_HEIGHT_M,i.length()),s=new on().setFromUnitVectors(new R(0,0,1),i.clone().normalize()),r=new R().addVectors(t,e).multiplyScalar(.5);return n.applyMatrix4(new te().compose(r,s,new R(1,1,1)))}static merge(t){const e=t.map(c=>c.getIndex()?c.toNonIndexed():c),i=e.reduce((c,l)=>c+l.getAttribute("position").count,0),n=new Float32Array(i*3),s=new Float32Array(i*3);let r=0;for(const c of e){const l=c.getAttribute("position"),h=c.getAttribute("normal");n.set(l.array,r*3),h&&s.set(h.array,r*3),r+=l.count}const o=new se;o.setAttribute("position",new ue(n,3)),o.setAttribute("normal",new ue(s,3));for(const c of t)c.dispose();for(const c of e)c.dispose();return o}}class Ur{constructor(t,e={}){this.size=t,this.structure=e}static DEFAULT_DIAMETER_M=.008;static POLE_RADIUS_M=.13;static POLE_ABOVE_M=.5;static NATURAL_SIZE=Object.freeze({widthM:1,lengthM:30,heightM:5});get strands(){const t=this.structure.strands;return!t||t.length===0?[{heightM:this.size.heightM,acrossM:0}]:t.map(e=>({heightM:e.heightM,acrossM:e.acrossM??0}))}get poleStations(){const t=this.size.lengthM/2;switch(this.structure.poles??"both"){case"start":return[t];case"end":return[-t];case"none":return[];default:return[-t,t]}}get poleHeightM(){return this.structure.poleHeightM??Math.max(...this.strands.map(t=>t.heightM))+Ur.POLE_ABOVE_M}build(){const t=this.structure.diameterM??Ur.DEFAULT_DIAMETER_M,e=this.strands.map(n=>{const s=new Fn(t/2,t/2,this.size.lengthM,6);return s.rotateX(Math.PI/2),s.translate(n.acrossM,n.heightM,0),s}),i=this.poleStations.map(n=>{const s=new Fn(Ur.POLE_RADIUS_M*.8,Ur.POLE_RADIUS_M,this.poleHeightM,8);return s.translate(0,this.poleHeightM/2,n),s});return{strands:e,poles:i}}}const yu=Math.PI/180;function Pe(a,t,e,i,n=!1){const s=n?new _n({color:new st(...e)}):new qr({color:new st(...e)}),r=new bt(t,s);return r.position.y=i,r.userData={emissive:n},r.castShadow=!n,r.receiveShadow=!n,a.add(r),r}const Su=.25,X5=.002,Y5=100,q5=1500,$5=.25,K5=1e3,Z5=.15;function J5(a){const t=/^#([0-9a-f]{6})$/i.exec(a);if(!t)return[1,1,1];const e=parseInt(t[1],16);return[(e>>16&255)/255,(e>>8&255)/255,(e&255)/255]}const j5=[.32,.32,.3],hv=[1,.85,.5],Q5=[.25,.25,.25],uv=[1,.97,.85],tE=[.55,.68,.72],ls=.03,hs=.05,dv={front:0,behind:Math.PI,left:Math.PI/2,right:-Math.PI/2,"front-left":Math.PI/2,"behind-left":Math.PI/2,"front-right":-Math.PI/2,"behind-right":-Math.PI/2};function Xi(a,t){return a?.[t]}function us(a,t,e,i,n,s,r,o){if(o===void 0)return;const c=new qr({color:new st(...tE),transparent:!0,opacity:o/100}),l=new bt(new Ki(t,e,i),c);l.position.set(n,s,r),a.add(l)}const Rn=.05,_u=[.6,.58,.53],Um=[.5,.5,.48];function Oa(a,t,e,i,n,s,r,o){const c=new qr({color:new st(...o),side:qe}),l=new bt(new Ki(t,e,i),c);l.position.set(n,s,r),a.add(l)}function eE(a,t,e,i,n,s,r,o,c){const l=(i-s)/2,h=(p,v,m,g)=>{p<=0||(t?Oa(a,p,v,Rn,m,o+g,r,c):Oa(a,Rn,v,p,r,o+g,m,c))};h(e,l,0,i/2-l/2),h(e,l,0,-(i/2-l/2));const u=[...n].sort((p,v)=>p.center-v.center);let d=-e/2;for(const p of u){const m=p.center-p.main/2-d;h(m,s,d+m/2,0),d=p.center+p.main/2}const f=e/2-d;h(f,s,d+f/2,0)}function fv(a,t,e,i,n,s,r,o,c,l){const h=(i+n)/2,u=n-i,d=(f,p,v,m)=>{f.length===0?p?Oa(a,v,u,Rn,0,h,m,_u):Oa(a,Rn,u,v,m,h,0,_u):eE(a,p,v,u,f,s,m,h,_u)};d(r,!0,t*2,-e+Rn),d(o,!0,t*2,e-Rn),d(c,!1,e*2,-t+Rn),d(l,!1,e*2,t-Rn),Oa(a,t*2,Rn,e*2,0,i+Rn,0,Um),Oa(a,t*2,Rn,e*2,0,n-Rn,0,Um)}function M0(a,t,e,i){switch(a){case"front":return{x:0,z:-(e-i)};case"behind":return{x:0,z:e-i};case"left":return{x:-(t-i),z:0};case"right":return{x:t-i,z:0};case"front-left":return{x:-(t-i),z:-ds};case"front-right":return{x:t-i,z:-ds};case"behind-left":return{x:-(t-i),z:ds};case"behind-right":return{x:t-i,z:ds}}}function pv(a,t,e,i,n,s,r){const o=S0();o.scale.setScalar(i),o.rotation.y=dv[t];const{x:c,z:l}=M0(t,n,s,r);o.position.set(c,e,l),a.add(o)}const x0=6,y0=6,sr=3,Eo=1.4,Ao=sr*.5,mv=1.2,gv=.35,iE=.75,nE=1.6;function km(a,t,e,i){const n=new Re,s=Math.max(1,a+1),r=s*sr;Pe(n,new Ki(x0,r,y0),[.55,.54,.5],r/2);const o=x0/2,c=y0/2;for(let l=0;l<s;l++){const h=l*sr+sr/2;us(n,Eo,Ao,hs,0,h,-c-ls,Xi(t,"front")),us(n,Eo,Ao,hs,0,h,c+ls,Xi(t,"behind")),us(n,hs,Ao,Eo,-o-ls,h,0,Xi(t,"left")),us(n,hs,Ao,Eo,o+ls,h,0,Xi(t,"right"))}if(e){const l=Math.min(Math.max(i??0,0),s-1);pv(n,e,l*sr,.72,o,c,mv);const h=u=>Xi(t,u)!==void 0?[{main:Eo,center:0}]:[];fv(n,o,c,l*sr,(l+1)*sr,Ao,h("front"),h("behind"),h("left"),h("right"))}return n}function zm(){const a=new Re,t=[[0,0,.55,.5],[.4,.1,.35,.4],[-.35,-.2,.4,.38],[.1,-.4,.35,.36],[-.15,.4,.3,.34]];for(const[e,i,n,s]of t){const r=new di(n,10,7);r.scale(1,.85,1),r.translate(e,0,i),Pe(a,r,[.26,.28,.17],s)}return a}function sE(a){const t=new Re,e=new Ue(oi.sizeOf(a),a.bridge).build();Pe(t,e.concrete,[.6,.6,.58],0);const i=Pe(t,e.road,[.2,.2,.21],0),n=Pe(t,e.earth,[.3,.36,.22],0);for(const s of[i,n])s.material.side=xn;return Pe(t,e.railing,[.5,.52,.55],0),t}function rE(a){const t=new Re,e=new Ur(oi.sizeOf(a),a.wire).build();for(const i of e.strands)Pe(t,i,[.1,.1,.11],0);for(const i of e.poles)Pe(t,i,[.3,.24,.18],0);return t}function Bm(){const a=new Re;return Pe(a,new Fn(.15,.22,2,8),[.32,.22,.14],1),Pe(a,new io(1.4,3,8),[.16,.32,.14],3.5),a}const Hm=.275,aE=.35,oE=.9,cE=34,lE=8,hE=1.4;function Gm(){const a=new Re,t=new di(Hm,7,3,0,Math.PI*2,0,Math.PI/2);t.scale(1,aE/Hm,1);const e=oi.repeatOnGrid(t,cE,oE,lE,hE),i=Pe(a,e,[.26,.28,.22],0);return i.castShadow=!0,i.userData.cropBasePositions=e.getAttribute("position").array.slice(),i.userData.cropVerticesPerClump=t.getAttribute("position").count,t.dispose(),a}function Vm(){const a=new Re,t=new di(1,7,3,0,Math.PI*2,0,Math.PI/2);return Pe(a,t,[.38,.36,.32],0),a}function Wm(a){const t=new Re;return Pe(t,new Fn(.05,.08,5,8),[.28,.28,.3],2.5),Pe(t,new di(.25,12,8),a?hv:j5,5.1,!0),t}const uE=[.08,.08,.08],Qs=.8,Aa=1,rs=1.7,bu=.6,wr=.4,dl=1.2,wa=.7,ds=.5,dE=rs;function Xm(a,t,e){const i=new Re;Pe(i,new Ki(1.8,1.4,4.2),[.45,.14,.14],.7),Pe(i,new Ki(Qs*2,bu,Aa*2),[.4,.12,.12],rs);for(const s of[-1.4,1.4])for(const r of[-.95,.95]){const o=Pe(i,new Fn(.4,.4,.3,12),uE,.4);o.rotation.z=Math.PI/2,o.position.x=r,o.position.z=s}const n=a?uv:Q5;for(const s of[-.7,.7])Pe(i,new di(.15,8,6),n,.7,!0).position.set(s,.7,-2.1);if(us(i,dl,wr,hs,0,rs,-Aa-ls,Xi(t,"front")),us(i,dl,wr,hs,0,rs,Aa+ls,Xi(t,"behind")),us(i,hs,wr,wa,-Qs-ls,rs,-ds,Xi(t,"front-left")),us(i,hs,wr,wa,-Qs-ls,rs,ds,Xi(t,"behind-left")),us(i,hs,wr,wa,Qs+ls,rs,-ds,Xi(t,"front-right")),us(i,hs,wr,wa,Qs+ls,rs,ds,Xi(t,"behind-right")),e){pv(i,e,iE,.5,Qs,Aa,gv);const s=(c,l)=>{const h=[];return Xi(t,c)!==void 0&&h.push({main:wa,center:-ds}),Xi(t,l)!==void 0&&h.push({main:wa,center:ds}),h},r=Xi(t,"front")!==void 0?[{main:dl,center:0}]:[],o=Xi(t,"behind")!==void 0?[{main:dl,center:0}]:[];fv(i,Qs,Aa,rs-bu/2,rs+bu/2,wr,r,o,s("front-left","behind-left"),s("front-right","behind-right"))}return i}const Ym=new Map;function qm(a,t){if(!a)return;const e=[[a.lengthM,t.lengthM],[a.heightM,t.heightM],[a.widthM,t.widthM]];for(const[i,n]of e)if(i!==void 0&&n>1e-6)return i/n}function wu(a,t){return t>1e-6?a/t:1}const vv=[.95,.9,.82],$m=[.72,.74,.78];function Km(){const a=new Re;Pe(a,new Fn(.25,.3,1.5,10),$m,.75),Pe(a,new di(.26,10,8),$m,1.74);const t=Pe(a,new io(.07,.16,8),vv,1.74);return t.rotation.x=-Math.PI/2,t.position.z=-.22,a}function S0(){const a=new Re;Pe(a,new Fn(.25,.3,1.5,10),[.3,.3,.35],.75),Pe(a,new di(.22,10,8),[.62,.52,.46],1.72);const t=Pe(a,new io(.07,.16,8),vv,1.72);return t.rotation.x=-Math.PI/2,t.position.z=-.2,a}const fE=17,Zm=18.5,Eu=[.16,.16,.18];function Jm(){const a=new Re,t=Pe(a,new Fn(1.8,1.8,Zm*2,10),Eu,0);t.rotation.x=Math.PI/2,Pe(a,new Ki(fE*2,.5,4.5),Eu,0);const e=Pe(a,new Ki(.4,5.5,4),Eu,3);return e.position.z=-Zm+2,a}class oi{static GROWS_FROM_GROUND=new Set(["tree","shrub","crop","mound"]);static groundUnderFootprint(t,e,i,n,s,r=0){const o=oi.sizeOf(t);if(r>o.heightM)return s(e,i);const c=(n??0)*Math.PI/180,l=Math.min(21,Math.max(2,Math.ceil(o.lengthM/.75)+1)),h=Math.min(21,Math.max(2,Math.ceil(o.widthM/.75)+1)),u=oi.GROWS_FROM_GROUND.has(t.kind);let d=u?1/0:-1/0;for(let f=0;f<l;f++){const p=(f/(l-1)-.5)*o.lengthM;for(let v=0;v<h;v++){const m=(v/(h-1)-.5)*o.widthM,g=e+Math.sin(c)*p+Math.cos(c)*m,S=i-Math.cos(c)*p+Math.sin(c)*m;d=u?Math.min(d,s(g,S)):Math.max(d,s(g,S))}}return Number.isFinite(d)?d:s(e,i)}static occupantView(t){const e=t.observerSide;if(!e)throw new Error("occupantView requires object.observerSide to be set");const{x:i,z:n}=t.kind==="vehicle"?M0(e,Qs,Aa,gv):M0(e,x0/2,y0/2,mv),s=t.kind==="vehicle"?dE:(t.occupiedFloor??0)*sr+nE,r=(t.headingDeg??0)-dv[e]/yu,o=this.scaleFor(t);return{x:i*o.x,z:n*o.z,eyeY:s*o.y,headingDeg:r}}static BODY_NAME="decor-body";static bodyOf(t){return t.getObjectByName(oi.BODY_NAME)??t}static repeatOnGrid(t,e,i,n,s){const r=t.getAttribute("position"),o=t.getAttribute("normal"),c=t.getIndex();if(!c)throw new Error("repeatOnGrid needs an indexed geometry");const l=r.count,h=e*n,u=new Float32Array(l*h*3),d=new Float32Array(l*h*3),f=new Uint32Array(c.count*h),p=-((e-1)*i)/2,v=-((n-1)*s)/2;let m=0;for(let S=0;S<n;S++)for(let x=0;x<e;x++,m++){const M=v+S*s,b=p+x*i;for(let w=0;w<l;w++){const T=(m*l+w)*3;u[T]=r.getX(w)+M,u[T+1]=r.getY(w),u[T+2]=r.getZ(w)+b,d[T]=o.getX(w),d[T+1]=o.getY(w),d[T+2]=o.getZ(w)}for(let w=0;w<c.count;w++)f[m*c.count+w]=c.getX(w)+m*l}const g=new se;return g.setAttribute("position",new ue(u,3)),g.setAttribute("normal",new ue(d,3)),g.setIndex(new H0(f,1)),g}static fitCropToGround(t,e){t.updateMatrixWorld(!0);const i=new R;t.traverse(n=>{const s=n,r=s.userData.cropBasePositions,o=s.userData.cropVerticesPerClump;if(!s.isMesh||!r||!o)return;const c=s.geometry.getAttribute("position"),l=new te().copy(s.matrixWorld).invert();for(let h=0;h<c.count;h+=o){i.set(r[h*3],0,r[h*3+2]).applyMatrix4(s.matrixWorld),i.y=e(i.x,i.z),i.applyMatrix4(l);for(let u=h;u<h+o;u++)c.setY(u,r[u*3+1]+i.y)}c.needsUpdate=!0,s.geometry.computeBoundingBox(),s.geometry.computeBoundingSphere()})}static paint(t,e){t.traverse(i=>{const n=i,s=n.userData;if(!n.isMesh||s?.emissive)return;const r=n.material;r?.color&&r.color.set(e)})}static build(t,e){const i=t.kind==="building"?km(t.floors??Tf,t.windows,t.observerSide,t.occupiedFloor):t.kind==="tree"?Bm():t.kind==="shrub"?zm():t.kind==="bridge"?sE(t):t.kind==="wire"?rE(t):t.kind==="crop"?Gm():t.kind==="mound"?Vm():t.kind==="streetlight"?Wm(e):t.kind==="vehicle"?Xm(e,t.windows,t.observerSide):t.kind==="aircraft"?Jm():t.kind==="entity"?Km():S0();t.color&&this.paint(i,t.color);const n=this.scaleFor(t),s=new Re;return i.name=oi.BODY_NAME,i.scale.copy(n),s.add(i),t.headingDeg!==void 0&&(s.rotation.y=-t.headingDeg*yu),this.addLights(s,t.lights),s}static scaleFor(t){const e=t.sizeM;if(!e||t.kind==="bridge"||t.kind==="wire")return new R(1,1,1);const i=this.naturalSize(t.kind,t.floors);return new R(e.widthM===void 0?1:wu(e.widthM,i.widthM),e.heightM===void 0?1:wu(e.heightM,i.heightM),e.lengthM===void 0?1:wu(e.lengthM,i.lengthM))}static naturalSize(t,e){const i=t==="building"?Math.max(1,(e??Tf)+1):0;if(t==="bridge")return Ue.NATURAL_SIZE;if(t==="wire")return Ur.NATURAL_SIZE;const n=`${t}:${i}`,s=Ym.get(n);if(s)return s;const r=t==="building"?km(i-1,void 0,void 0,void 0):t==="tree"?Bm():t==="shrub"?zm():t==="crop"?Gm():t==="mound"?Vm():t==="streetlight"?Wm(!1):t==="vehicle"?Xm(!1,void 0,void 0):t==="aircraft"?Jm():t==="entity"?Km():S0(),o=new ki().setFromObject(r),c={widthM:o.max.x-o.min.x,heightM:o.max.y-o.min.y,lengthM:o.max.z-o.min.z};return this.dispose(r),Ym.set(n,c),c}static usesModel(t){return Zu(t)!==void 0&&!(t.observerSide!==void 0&&Lg(t.kind))}static applyModel(t,e,i,n={}){const s=this.bodyOf(t),r=new Re;r.name=oi.BODY_NAME,i.rotation.y=-(n.headingOffsetDeg??0)*yu,i.updateMatrixWorld(!0);const o=new ki().setFromObject(i),c={lengthM:o.max.z-o.min.z,heightM:o.max.y-o.min.y,widthM:o.max.x-o.min.x},l=qm(e.sizeM,c)??qm(n.depictedSizeM,c)??1;i.scale.multiplyScalar(l);const h=o.getCenter(new R).multiplyScalar(l);i.position.x-=h.x,i.position.z-=h.z,i.position.y-=e.kind==="aircraft"?h.y:o.min.y*l,i.traverse(u=>{u instanceof bt&&(u.castShadow=!0,u.receiveShadow=!0)}),r.add(i),s.parent?(s.parent.add(r),s.removeFromParent()):t.add(r),this.dispose(s)}static sizeOf(t){const e=this.naturalSize(t.kind,t.floors);return{widthM:t.sizeM?.widthM??e.widthM,lengthM:t.sizeM?.lengthM??e.lengthM,heightM:t.sizeM?.heightM??e.heightM}}static addLights(t,e){for(const i of e??[]){const n=J5(i.color),s=Pe(t,new di(Su,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=Ai,r.transparent=!0,r.depthWrite=!1,r.fog=!1}}static setLights(t,e,i,n,s=0,r=1,o=X5,c=[1,1,1]){if(!e||e.length===0)return;const l=new Map(e.map(f=>[f.id,f])),h=Math.max(1,n*o/Su),u=Su*h,d=r/(Math.PI*u*u);for(const f of t.children){if(!(f instanceof bt))continue;const p=f.userData.lightId;if(!p)continue;const v=l.get(p);if(!v)continue;const m=s>0?Ng(v,i,i+s):Fv(v,i)?1:0;f.visible=m>0;const g=f.material,S=f.userData.lightColor;if(S){const x=m*Y5*(v.intensity??1)*d;g.color.setRGB(S[0]*x*c[0],S[1]*x*c[1],S[2]*x*c[2])}f.scale.setScalar(h)}}static setLit(t,e,i,n=1){const[s,r,o]=e==="streetlight"?[q5,$5,hv]:[K5,Z5,uv],c=i?s*n/(Math.PI*r*r):0,l=[o[0]*c,o[1]*c,o[2]*c];t.traverse(h=>{const u=h.userData;!(h instanceof bt)||!u.emissive||u.lightId||h.material.color.setRGB(...l)})}static dispose(t){t.traverse(e=>{if(!(e instanceof bt)||e.userData.sharedModel)return;e.geometry.dispose();const i=e.material;for(const n of Array.isArray(i)?i:[i])n.dispose()})}}const Au="https://ufoathome.org/models/index.json";class $o{attribution="3D models re-hosted by UFO@home, each under its own author's licence";fetchImpl;indexUrls;loading;static shared=new Map;sharing;constructor(t={}){this.sharing=!t.fetchImpl,this.fetchImpl=t.fetchImpl??fetch.bind(globalThis),this.indexUrls=t.indexUrls??pE()}async entries(t){const e=await this.load();return t?e.filter(i=>[i.kind].flat().includes(t)):e}async entry(t){return(await this.load()).find(e=>e.id===t)}load(){if(this.loading)return this.loading;if(!this.sharing)return this.loading=this.fetchFirstAvailable();const t=this.indexUrls.join(`
7292
- `);let e=$o.shared.get(t);return e||(e=this.fetchFirstAvailable(),$o.shared.set(t,e),e.then(i=>{i.length===0&&$o.shared.delete(t)})),this.loading=e}async fetchFirstAvailable(){for(const t of this.indexUrls){const e=await this.fetchIndex(t);if(e)return e}return[]}async fetchIndex(t){try{const e=await this.fetchImpl(t);if(!e.ok)return;const i=await e.json();return Array.isArray(i?.models)?i.models.map(({file:n,...s})=>({...s,url:new URL(n,t).href})):void 0}catch{return}}}function pE(){const a=`?v=${encodeURIComponent("0.97.0")}`,t=typeof location>"u"?void 0:new URL("/models/index.json",location.href).href;return(t&&t!==Au?[t,Au]:[Au]).map(e=>e+a)}const mE=[{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 $o}];async function Tu(a){const{GLTFLoader:t}=await $i(async()=>{const{GLTFLoader:i}=await import("./GLTFLoader-DYi1DaRQ.js");return{GLTFLoader:i}},[],import.meta.url),e=new t;return new Promise((i,n)=>{e.load(a,s=>i(Object.assign(s.scene,{animations:s.animations})),void 0,s=>n(new Error(`Could not load 3D model ${a}: ${s instanceof Error?s.message:String(s)}`)))})}const Mv=["ellipsoid","sphere","disc","cylinder","cone","box","torus","figure"];class gn{static MIN_ANGLE_RAD=.002;static FILL=(1-Math.exp(-4))/4;static MAX_SHARE=.3;mesh;constructor(t,e){this.mesh=new bt(new Zi(2,2),new de({uniforms:{uColor:{value:new st(0,0,0)},uRadius:{value:1}},vertexShader:gn.VERTEX,fragmentShader:gn.FRAGMENT,transparent:!0,depthWrite:!1,blending:Ai,toneMapped:!1})),this.mesh.name=t,this.mesh.frustumCulled=!1,this.mesh.renderOrder=e,this.mesh.visible=!1}shine(t,e,i){this.mesh.visible=!0,this.mesh.position.set(t.x,t.y,t.z),this.mesh.material.uniforms.uRadius.value=e,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(t,e,i,n){const s=Math.max(t,n*gn.MIN_ANGLE_RAD),r=gn.FILL*Math.PI*s*s;return{radiusM:s,luminanceCdM2:i*Math.min(gn.MAX_SHARE,e/r)}}static conserving(t){return Math.sqrt(t/(gn.MAX_SHARE*gn.FILL*Math.PI))}static VERTEX=`
7291
+ `,transparent:!0,blending:Ai,depthWrite:!1,side:qe,fog:!1}),this.object=new bt(new di(Ti.RADIUS,64,32),this.material),this.object.renderOrder=-1,this.object.frustumCulled=!1,this.object.visible=!1;const i=this.material.uniforms;this.deckUniforms={uSource:i.uSource,uUp:i.uUp,uStrength:i.uStrength,uTint:i.uTint,uMap:i.uMap,uGain:i.uGain,uHaloShown:{value:0}}}deckUniforms;shown=!1;hostedByDeck=!1;set hosted(t){this.hostedByDeck=t,this.show(this.shown)}show(t){this.shown=t,this.object.visible=t&&!this.hostedByDeck,this.deckUniforms.uHaloShown.value=t?1:0}get awaitingFirstDisplay(){return this.tracing&&!this.everDisplayed}setUrgent(t){this.urgent=t}set onReady(t){this.onRepaint=t}update(t,e,i,n,s,r){const o=this.material.uniforms;if(i<=0){o.uStrength.value=0,this.show(!1),this.stopWork();return}o.uSource.value.set(t.x,t.y,t.z).normalize(),o.uStrength.value=i,o.uTint.value.set(n[0],n[1],n[2]),o.uIceCover.value=s.cover,o.uIceHeight.value=s.layerHeight,this.show(this.everDisplayed),this.requestMap(e,r)}requestMap(t,e){if(!(!(Math.abs(t-this.mappedAltitudeDeg)<Ti.ALTITUDE_STEP_DEG)||!(Math.abs(e-this.mappedAlignment)<Ti.ALIGNMENT_STEP))){this.next=void 0;return}if(this.tracing){if(this.tracingFor(t,e)){this.next=void 0;return}if(!(!(Math.abs(t-this.pendingAltitudeDeg)<Ti.LEAP_ALTITUDE_DEG)||!(Math.abs(e-this.pendingAlignment)<Ti.LEAP_ALIGNMENT))){this.next={sourceAltitudeDeg:t,alignment:e};return}}this.next=void 0,this.pendingAltitudeDeg=t,this.pendingAlignment=e,this.stopWork(),this.tracing=!0,this.startTracing(t,e)}startTracing(t,e){const i=++this.ticket,n=()=>{i!==this.ticket||!this.tracing||(this.sky.begin(t,e),this.scheduleWork())};or.with(s=>{i!==this.ticket||!this.tracing||(this.job=s.trace(t,e,Ti.RAYS,r=>{this.job=void 0,this.texels.set(r),this.display(),this.finishTracing()},n))},n)}ticket=0;job;pendingAltitudeDeg=Number.NaN;pendingAlignment=Number.NaN;next;tracingFor(t,e){return this.tracing&&Math.abs(t-this.pendingAltitudeDeg)<Ti.ALTITUDE_STEP_DEG&&Math.abs(e-this.pendingAlignment)<Ti.ALIGNMENT_STEP}scheduleWork(){if(this.workHandle!==void 0)return;const t=()=>{if(this.workHandle=void 0,!this.tracing)return;const e=performance.now(),i=this.urgent?Ti.URGENT_BUDGET_MS:Ti.BUDGET_MS;do this.sky.trace(Ti.RAYS_PER_BATCH);while(this.sky.tracedRays<Ti.RAYS&&performance.now()-e<i);if(this.sky.tracedRays>=Ti.RAYS){this.publish(),this.finishTracing();return}this.workHandle=requestAnimationFrame(t)};this.workHandle=requestAnimationFrame(t)}finishTracing(){this.tracing=!1,this.mappedAltitudeDeg=this.pendingAltitudeDeg,this.mappedAlignment=this.pendingAlignment;const t=this.next;t&&this.requestMap(t.sourceAltitudeDeg,t.alignment)}stopWork(){this.ticket++,this.job?.cancel(),this.job=void 0,this.workHandle!==void 0&&cancelAnimationFrame(this.workHandle),this.workHandle=void 0,this.tracing=!1,this.next=void 0}publish(){W5.fromRadiance(this.sky.harvest().data,this.texels),this.display()}display(){this.texture.needsUpdate=!0,this.everDisplayed=!0,this.show(this.material.uniforms.uStrength.value>0),this.onRepaint?.()}dispose(){this.stopWork(),this.texture.dispose(),this.object.geometry.dispose(),this.material.dispose()}}class _i{static MAX_CONCURRENT=24;static POINTS=8;static SEGMENTS=_i.POINTS-1;static ACROSS=3;static VERTICES_PER_SEGMENT=(_i.ACROSS-1)*6;static RADIUS=840;static MIN_HALF_WIDTH_DEG=.05;static BRIGHT_HALF_WIDTH_DEG=.22;object;positions;colors;meteors=[];radiantAltitudeDeg=0;radiantAzimuthDeg=0;constructor(){const t=_i.MAX_CONCURRENT*_i.SEGMENTS*_i.VERTICES_PER_SEGMENT;this.positions=new Float32Array(t*3),this.colors=new Float32Array(t*3);const e=new se;e.setAttribute("position",new Jt(this.positions,3)),e.setAttribute("color",new Jt(this.colors,3)),e.setDrawRange(0,0),this.object=new bt(e,On.material()),this.object.frustumCulled=!1,On.track(this.object)}get schedule(){return this.meteors}setShower(t,e,i){this.meteors=t,this.radiantAltitudeDeg=e,this.radiantAzimuthDeg=i}update(t){const e=this.object.geometry;if(this.meteors.length===0){e.setDrawRange(0,0);return}const i=Gr.aliveAt(this.meteors,t).slice(0,_i.MAX_CONCURRENT);let n=0;for(const{meteor:s,progress:r}of i){const o=this.radiantOf(s);if(!o)continue;const c=Ze(o.altitudeDeg,o.azimuthDeg,1),[l,h]=this.basisAround(c),u=s.fromRadiantDeg+r*s.lengthDeg,d=Math.max(s.fromRadiantDeg,u-s.lengthDeg*.6),f=Math.min(1,(1-r)*2.5),p=this.turn(l,h,s.bearingDeg),v=(.15+.85*s.brightness)*f,m=x=>v*x**1.6,g=x=>this.onSphere(c,p,d+(u-d)*x),S=x=>_i.RADIUS*((_i.MIN_HALF_WIDTH_DEG+_i.BRIGHT_HALF_WIDTH_DEG*s.brightness*x)*Math.PI/180);for(let x=1;x<_i.POINTS;x++){const M=(x-1)/_i.SEGMENTS,b=x/_i.SEGMENTS;n=this.pushRibbon(n,g(M),g(b),S(M),S(b),m(M),m(b))}}e.setDrawRange(0,n),e.getAttribute("position").needsUpdate=!0,e.getAttribute("color").needsUpdate=!0}midpointOf(t){const e=this.radiantOf(t);if(!e)return;const i=Ze(e.altitudeDeg,e.azimuthDeg,1),[n,s]=this.basisAround(i),r=this.turn(n,s,t.bearingDeg),o=this.onSphere(i,r,t.fromRadiantDeg+t.lengthDeg/2),c=Math.hypot(o.x,o.y,o.z)||1;return{altitudeDeg:Math.asin(o.y/c)*180/Math.PI,azimuthDeg:(Math.atan2(o.x,-o.z)*180/Math.PI+360)%360}}radiantOf(t){return t.radiant?t.radiant:this.radiantAltitudeDeg>0?{altitudeDeg:this.radiantAltitudeDeg,azimuthDeg:this.radiantAzimuthDeg}:void 0}pushRibbon(t,e,i,n,s,r,o){const c=this.normalise(this.cross(this.normalise(e),this.normalise(this.subtract(i,e))));for(let l=0;l<_i.ACROSS-1;l++){const h=l-1,u=l,d=this.across(e,c,n,h),f=this.across(i,c,s,h),p=this.across(e,c,n,u),v=this.across(i,c,s,u),m=(g,S)=>g===0?S:0;t=this.push(t,d,m(h,r)),t=this.push(t,f,m(h,o)),t=this.push(t,p,m(u,r)),t=this.push(t,f,m(h,o)),t=this.push(t,v,m(u,o)),t=this.push(t,p,m(u,r))}return t}across(t,e,i,n){return{x:t.x+e.x*i*n,y:t.y+e.y*i*n,z:t.z+e.z*i*n}}push(t,e,i){const n=t*3;this.positions[n]=e.x,this.positions[n+1]=e.y,this.positions[n+2]=e.z;const s=Et.relativeOfResponse(Math.max(0,Math.min(1,i)));return this.colors[n]=s*.9,this.colors[n+1]=s*.95,this.colors[n+2]=s,t+1}turn(t,e,i){const n=i*Math.PI/180,s=Math.cos(n),r=Math.sin(n);return{x:t.x*s+e.x*r,y:t.y*s+e.y*r,z:t.z*s+e.z*r}}onSphere(t,e,i){const n=i*Math.PI/180,s=Math.cos(n),r=Math.sin(n);return{x:(t.x*s+e.x*r)*_i.RADIUS,y:(t.y*s+e.y*r)*_i.RADIUS,z:(t.z*s+e.z*r)*_i.RADIUS}}basisAround(t){const e=Math.abs(t.y)<.9?{x:0,y:1,z:0}:{x:1,y:0,z:0},i=this.normalise(this.cross(t,e));return[i,this.normalise(this.cross(t,i))]}subtract(t,e){return{x:t.x-e.x,y:t.y-e.y,z:t.z-e.z}}cross(t,e){return{x:t.y*e.z-t.z*e.y,y:t.z*e.x-t.x*e.z,z:t.x*e.y-t.y*e.x}}normalise(t){const e=Math.hypot(t.x,t.y,t.z)||1;return{x:t.x/e,y:t.y/e,z:t.z/e}}dispose(){this.object.geometry.dispose(),this.object.material.dispose()}}class Ue{constructor(t,e={}){this.size=t,this.span=Math.min(t.lengthM,Math.max(0,e.spanM??t.lengthM)),this.bank=(t.lengthM-this.span)/2,this.deck=Math.min(t.heightM,e.deckThicknessM??Ue.DEFAULT_DECK_THICKNESS_M),this.railHeight=e.railing?.heightM??Ue.DEFAULT_RAILING_HEIGHT_M,this.postSpacing=Math.max(.3,e.railing?.postSpacingM??Ue.DEFAULT_POST_SPACING_M),this.rails=Math.max(0,Math.round(e.railing?.rails??Ue.DEFAULT_RAILS))}static DEFAULT_DECK_THICKNESS_M=1.2;static DEFAULT_RAILING_HEIGHT_M=1.05;static DEFAULT_POST_SPACING_M=1.5;static DEFAULT_RAILS=2;static BANK_SLOPE=1.5;static ABUTMENT_THICKNESS_M=1;static POST_SIDE_M=.08;static RAIL_HEIGHT_M=.08;static RAIL_DEPTH_M=.06;static BANK_STATIONS=12;static NATURAL_SIZE=Object.freeze({widthM:9,lengthM:40,heightM:6.5});span;bank;deck;railHeight;postSpacing;rails;roadAt(t){const e=Math.abs(t)-this.span/2;return e<=0?this.size.heightM:this.bank<=0?0:Math.max(0,this.size.heightM*(1-e/this.bank))}build(){const{widthM:t,heightM:e}=this.size,i=this.span/2,n=[];if(this.span>0){n.push(Ue.box(t,this.deck,this.span,0,e-this.deck/2,0));for(const c of[-1,1]){const l=e-this.deck;l>0&&this.bank>0&&n.push(Ue.box(t+1,l,Ue.ABUTMENT_THICKNESS_M,0,l/2,c*(i-Ue.ABUTMENT_THICKNESS_M/2)))}}const s=[];this.span>0&&s.push(Ue.box(t,.04,this.span,0,e+.02,0));const r=[];for(const c of[-1,1])this.bank<=0||(r.push(this.embankment(c)),s.push(this.bankRoad(c)));const o=[];for(const c of[-1,1])o.push(...this.railing(c*(t/2-Ue.POST_SIDE_M)));return{concrete:Ue.merge(n),road:Ue.merge(s),earth:Ue.merge(r),railing:Ue.merge(o)}}embankment(t){const e=this.size.widthM/2,i=this.stations(t),n=[],s=(l,h,u,d)=>{n.push(l.x,l.y,l.z,h.x,h.y,h.z,u.x,u.y,u.z,l.x,l.y,l.z,u.x,u.y,u.z,d.x,d.y,d.z)},r=l=>{const h=this.roadAt(l),u=e+Ue.BANK_SLOPE*h;return{leftFoot:new R(-u,0,l),leftTop:new R(-e,h,l),rightTop:new R(e,h,l),rightFoot:new R(u,0,l)}};for(let l=1;l<i.length;l++){const h=r(i[l-1]),u=r(i[l]),d=t>0,f=(p,v,m,g)=>d?s(p,v,m,g):s(g,m,v,p);f(h.leftFoot,h.leftTop,u.leftTop,u.leftFoot),f(h.leftTop,h.rightTop,u.rightTop,u.leftTop),f(h.rightTop,h.rightFoot,u.rightFoot,u.rightTop)}const o=r(i[0]);t>0?s(o.leftFoot,o.rightFoot,o.rightTop,o.leftTop):s(o.leftTop,o.rightTop,o.rightFoot,o.leftFoot);const c=new se;return c.setAttribute("position",new de(n,3)),c.computeVertexNormals(),c}bankRoad(t){const e=this.size.widthM/2,i=this.stations(t),n=[];for(let r=1;r<i.length;r++){const o=i[r-1],c=i[r],l=this.roadAt(o)+.02,h=this.roadAt(c)+.02,u=t>0?[[-e,l,o],[e,l,o],[e,h,c],[-e,h,c]]:[[-e,h,c],[e,h,c],[e,l,o],[-e,l,o]];for(const d of[0,2,1,0,3,2])n.push(...u[d])}const s=new se;return s.setAttribute("position",new de(n,3)),s.computeVertexNormals(),s}stations(t){const e=[];for(let i=0;i<=Ue.BANK_STATIONS;i++)e.push(t*(this.span/2+this.bank*i/Ue.BANK_STATIONS));return e}railing(t){const e=this.size.lengthM/2,i=Math.max(1,Math.round(this.size.lengthM/this.postSpacing)),n=[];for(let o=0;o<=i;o++)n.push(-e+this.size.lengthM*o/i);const s=[],r=Ue.POST_SIDE_M;for(const o of n)s.push(Ue.box(r,this.railHeight,r,t,this.roadAt(o)+this.railHeight/2,o));for(let o=1;o<=this.rails;o++){const c=this.railHeight*o/this.rails-Ue.RAIL_HEIGHT_M/2;for(let l=1;l<n.length;l++){const h=new R(t,this.roadAt(n[l-1])+c,n[l-1]),u=new R(t,this.roadAt(n[l])+c,n[l]);s.push(Ue.beam(h,u))}}return s}static box(t,e,i,n,s,r){return new Ki(t,e,i).translate(n,s,r)}static beam(t,e){const i=new R().subVectors(e,t),n=new Ki(Ue.RAIL_DEPTH_M,Ue.RAIL_HEIGHT_M,i.length()),s=new on().setFromUnitVectors(new R(0,0,1),i.clone().normalize()),r=new R().addVectors(t,e).multiplyScalar(.5);return n.applyMatrix4(new te().compose(r,s,new R(1,1,1)))}static merge(t){const e=t.map(c=>c.getIndex()?c.toNonIndexed():c),i=e.reduce((c,l)=>c+l.getAttribute("position").count,0),n=new Float32Array(i*3),s=new Float32Array(i*3);let r=0;for(const c of e){const l=c.getAttribute("position"),h=c.getAttribute("normal");n.set(l.array,r*3),h&&s.set(h.array,r*3),r+=l.count}const o=new se;o.setAttribute("position",new de(n,3)),o.setAttribute("normal",new de(s,3));for(const c of t)c.dispose();for(const c of e)c.dispose();return o}}class Ur{constructor(t,e={}){this.size=t,this.structure=e}static DEFAULT_DIAMETER_M=.008;static POLE_RADIUS_M=.13;static POLE_ABOVE_M=.5;static NATURAL_SIZE=Object.freeze({widthM:1,lengthM:30,heightM:5});get strands(){const t=this.structure.strands;return!t||t.length===0?[{heightM:this.size.heightM,acrossM:0}]:t.map(e=>({heightM:e.heightM,acrossM:e.acrossM??0}))}get poleStations(){const t=this.size.lengthM/2;switch(this.structure.poles??"both"){case"start":return[t];case"end":return[-t];case"none":return[];default:return[-t,t]}}get poleHeightM(){return this.structure.poleHeightM??Math.max(...this.strands.map(t=>t.heightM))+Ur.POLE_ABOVE_M}build(){const t=this.structure.diameterM??Ur.DEFAULT_DIAMETER_M,e=this.strands.map(n=>{const s=new Fn(t/2,t/2,this.size.lengthM,6);return s.rotateX(Math.PI/2),s.translate(n.acrossM,n.heightM,0),s}),i=this.poleStations.map(n=>{const s=new Fn(Ur.POLE_RADIUS_M*.8,Ur.POLE_RADIUS_M,this.poleHeightM,8);return s.translate(0,this.poleHeightM/2,n),s});return{strands:e,poles:i}}}const yu=Math.PI/180;function Pe(a,t,e,i,n=!1){const s=n?new _n({color:new st(...e)}):new qr({color:new st(...e)}),r=new bt(t,s);return r.position.y=i,r.userData={emissive:n},r.castShadow=!n,r.receiveShadow=!n,a.add(r),r}const Su=.25,X5=.002,Y5=100,q5=1500,$5=.25,K5=1e3,Z5=.15;function J5(a){const t=/^#([0-9a-f]{6})$/i.exec(a);if(!t)return[1,1,1];const e=parseInt(t[1],16);return[(e>>16&255)/255,(e>>8&255)/255,(e&255)/255]}const j5=[.32,.32,.3],hv=[1,.85,.5],Q5=[.25,.25,.25],uv=[1,.97,.85],tE=[.55,.68,.72],ls=.03,hs=.05,dv={front:0,behind:Math.PI,left:Math.PI/2,right:-Math.PI/2,"front-left":Math.PI/2,"behind-left":Math.PI/2,"front-right":-Math.PI/2,"behind-right":-Math.PI/2};function Xi(a,t){return a?.[t]}function us(a,t,e,i,n,s,r,o){if(o===void 0)return;const c=new qr({color:new st(...tE),transparent:!0,opacity:o/100}),l=new bt(new Ki(t,e,i),c);l.position.set(n,s,r),a.add(l)}const Rn=.05,_u=[.6,.58,.53],Um=[.5,.5,.48];function Oa(a,t,e,i,n,s,r,o){const c=new qr({color:new st(...o),side:qe}),l=new bt(new Ki(t,e,i),c);l.position.set(n,s,r),a.add(l)}function eE(a,t,e,i,n,s,r,o,c){const l=(i-s)/2,h=(p,v,m,g)=>{p<=0||(t?Oa(a,p,v,Rn,m,o+g,r,c):Oa(a,Rn,v,p,r,o+g,m,c))};h(e,l,0,i/2-l/2),h(e,l,0,-(i/2-l/2));const u=[...n].sort((p,v)=>p.center-v.center);let d=-e/2;for(const p of u){const m=p.center-p.main/2-d;h(m,s,d+m/2,0),d=p.center+p.main/2}const f=e/2-d;h(f,s,d+f/2,0)}function fv(a,t,e,i,n,s,r,o,c,l){const h=(i+n)/2,u=n-i,d=(f,p,v,m)=>{f.length===0?p?Oa(a,v,u,Rn,0,h,m,_u):Oa(a,Rn,u,v,m,h,0,_u):eE(a,p,v,u,f,s,m,h,_u)};d(r,!0,t*2,-e+Rn),d(o,!0,t*2,e-Rn),d(c,!1,e*2,-t+Rn),d(l,!1,e*2,t-Rn),Oa(a,t*2,Rn,e*2,0,i+Rn,0,Um),Oa(a,t*2,Rn,e*2,0,n-Rn,0,Um)}function M0(a,t,e,i){switch(a){case"front":return{x:0,z:-(e-i)};case"behind":return{x:0,z:e-i};case"left":return{x:-(t-i),z:0};case"right":return{x:t-i,z:0};case"front-left":return{x:-(t-i),z:-ds};case"front-right":return{x:t-i,z:-ds};case"behind-left":return{x:-(t-i),z:ds};case"behind-right":return{x:t-i,z:ds}}}function pv(a,t,e,i,n,s,r){const o=S0();o.scale.setScalar(i),o.rotation.y=dv[t];const{x:c,z:l}=M0(t,n,s,r);o.position.set(c,e,l),a.add(o)}const x0=6,y0=6,sr=3,Eo=1.4,Ao=sr*.5,mv=1.2,gv=.35,iE=.75,nE=1.6;function km(a,t,e,i){const n=new Re,s=Math.max(1,a+1),r=s*sr;Pe(n,new Ki(x0,r,y0),[.55,.54,.5],r/2);const o=x0/2,c=y0/2;for(let l=0;l<s;l++){const h=l*sr+sr/2;us(n,Eo,Ao,hs,0,h,-c-ls,Xi(t,"front")),us(n,Eo,Ao,hs,0,h,c+ls,Xi(t,"behind")),us(n,hs,Ao,Eo,-o-ls,h,0,Xi(t,"left")),us(n,hs,Ao,Eo,o+ls,h,0,Xi(t,"right"))}if(e){const l=Math.min(Math.max(i??0,0),s-1);pv(n,e,l*sr,.72,o,c,mv);const h=u=>Xi(t,u)!==void 0?[{main:Eo,center:0}]:[];fv(n,o,c,l*sr,(l+1)*sr,Ao,h("front"),h("behind"),h("left"),h("right"))}return n}function zm(){const a=new Re,t=[[0,0,.55,.5],[.4,.1,.35,.4],[-.35,-.2,.4,.38],[.1,-.4,.35,.36],[-.15,.4,.3,.34]];for(const[e,i,n,s]of t){const r=new di(n,10,7);r.scale(1,.85,1),r.translate(e,0,i),Pe(a,r,[.26,.28,.17],s)}return a}function sE(a){const t=new Re,e=new Ue(oi.sizeOf(a),a.bridge).build();Pe(t,e.concrete,[.6,.6,.58],0);const i=Pe(t,e.road,[.2,.2,.21],0),n=Pe(t,e.earth,[.3,.36,.22],0);for(const s of[i,n])s.material.side=xn;return Pe(t,e.railing,[.5,.52,.55],0),t}function rE(a){const t=new Re,e=new Ur(oi.sizeOf(a),a.wire).build();for(const i of e.strands)Pe(t,i,[.1,.1,.11],0);for(const i of e.poles)Pe(t,i,[.3,.24,.18],0);return t}function Bm(){const a=new Re;return Pe(a,new Fn(.15,.22,2,8),[.32,.22,.14],1),Pe(a,new io(1.4,3,8),[.16,.32,.14],3.5),a}const Hm=.275,aE=.35,oE=.9,cE=34,lE=8,hE=1.4;function Gm(){const a=new Re,t=new di(Hm,7,3,0,Math.PI*2,0,Math.PI/2);t.scale(1,aE/Hm,1);const e=oi.repeatOnGrid(t,cE,oE,lE,hE),i=Pe(a,e,[.26,.28,.22],0);return i.castShadow=!0,i.userData.cropBasePositions=e.getAttribute("position").array.slice(),i.userData.cropVerticesPerClump=t.getAttribute("position").count,t.dispose(),a}function Vm(){const a=new Re,t=new di(1,7,3,0,Math.PI*2,0,Math.PI/2);return Pe(a,t,[.38,.36,.32],0),a}function Wm(a){const t=new Re;return Pe(t,new Fn(.05,.08,5,8),[.28,.28,.3],2.5),Pe(t,new di(.25,12,8),a?hv:j5,5.1,!0),t}const uE=[.08,.08,.08],Qs=.8,Aa=1,rs=1.7,bu=.6,wr=.4,dl=1.2,wa=.7,ds=.5,dE=rs;function Xm(a,t,e){const i=new Re;Pe(i,new Ki(1.8,1.4,4.2),[.45,.14,.14],.7),Pe(i,new Ki(Qs*2,bu,Aa*2),[.4,.12,.12],rs);for(const s of[-1.4,1.4])for(const r of[-.95,.95]){const o=Pe(i,new Fn(.4,.4,.3,12),uE,.4);o.rotation.z=Math.PI/2,o.position.x=r,o.position.z=s}const n=a?uv:Q5;for(const s of[-.7,.7])Pe(i,new di(.15,8,6),n,.7,!0).position.set(s,.7,-2.1);if(us(i,dl,wr,hs,0,rs,-Aa-ls,Xi(t,"front")),us(i,dl,wr,hs,0,rs,Aa+ls,Xi(t,"behind")),us(i,hs,wr,wa,-Qs-ls,rs,-ds,Xi(t,"front-left")),us(i,hs,wr,wa,-Qs-ls,rs,ds,Xi(t,"behind-left")),us(i,hs,wr,wa,Qs+ls,rs,-ds,Xi(t,"front-right")),us(i,hs,wr,wa,Qs+ls,rs,ds,Xi(t,"behind-right")),e){pv(i,e,iE,.5,Qs,Aa,gv);const s=(c,l)=>{const h=[];return Xi(t,c)!==void 0&&h.push({main:wa,center:-ds}),Xi(t,l)!==void 0&&h.push({main:wa,center:ds}),h},r=Xi(t,"front")!==void 0?[{main:dl,center:0}]:[],o=Xi(t,"behind")!==void 0?[{main:dl,center:0}]:[];fv(i,Qs,Aa,rs-bu/2,rs+bu/2,wr,r,o,s("front-left","behind-left"),s("front-right","behind-right"))}return i}const Ym=new Map;function qm(a,t){if(!a)return;const e=[[a.lengthM,t.lengthM],[a.heightM,t.heightM],[a.widthM,t.widthM]];for(const[i,n]of e)if(i!==void 0&&n>1e-6)return i/n}function wu(a,t){return t>1e-6?a/t:1}const vv=[.95,.9,.82],$m=[.72,.74,.78];function Km(){const a=new Re;Pe(a,new Fn(.25,.3,1.5,10),$m,.75),Pe(a,new di(.26,10,8),$m,1.74);const t=Pe(a,new io(.07,.16,8),vv,1.74);return t.rotation.x=-Math.PI/2,t.position.z=-.22,a}function S0(){const a=new Re;Pe(a,new Fn(.25,.3,1.5,10),[.3,.3,.35],.75),Pe(a,new di(.22,10,8),[.62,.52,.46],1.72);const t=Pe(a,new io(.07,.16,8),vv,1.72);return t.rotation.x=-Math.PI/2,t.position.z=-.2,a}const fE=17,Zm=18.5,Eu=[.16,.16,.18];function Jm(){const a=new Re,t=Pe(a,new Fn(1.8,1.8,Zm*2,10),Eu,0);t.rotation.x=Math.PI/2,Pe(a,new Ki(fE*2,.5,4.5),Eu,0);const e=Pe(a,new Ki(.4,5.5,4),Eu,3);return e.position.z=-Zm+2,a}class oi{static GROWS_FROM_GROUND=new Set(["tree","shrub","crop","mound"]);static groundUnderFootprint(t,e,i,n,s,r=0){const o=oi.sizeOf(t);if(r>o.heightM)return s(e,i);const c=(n??0)*Math.PI/180,l=Math.min(21,Math.max(2,Math.ceil(o.lengthM/.75)+1)),h=Math.min(21,Math.max(2,Math.ceil(o.widthM/.75)+1)),u=oi.GROWS_FROM_GROUND.has(t.kind);let d=u?1/0:-1/0;for(let f=0;f<l;f++){const p=(f/(l-1)-.5)*o.lengthM;for(let v=0;v<h;v++){const m=(v/(h-1)-.5)*o.widthM,g=e+Math.sin(c)*p+Math.cos(c)*m,S=i-Math.cos(c)*p+Math.sin(c)*m;d=u?Math.min(d,s(g,S)):Math.max(d,s(g,S))}}return Number.isFinite(d)?d:s(e,i)}static occupantView(t){const e=t.observerSide;if(!e)throw new Error("occupantView requires object.observerSide to be set");const{x:i,z:n}=t.kind==="vehicle"?M0(e,Qs,Aa,gv):M0(e,x0/2,y0/2,mv),s=t.kind==="vehicle"?dE:(t.occupiedFloor??0)*sr+nE,r=(t.headingDeg??0)-dv[e]/yu,o=this.scaleFor(t);return{x:i*o.x,z:n*o.z,eyeY:s*o.y,headingDeg:r}}static BODY_NAME="decor-body";static bodyOf(t){return t.getObjectByName(oi.BODY_NAME)??t}static repeatOnGrid(t,e,i,n,s){const r=t.getAttribute("position"),o=t.getAttribute("normal"),c=t.getIndex();if(!c)throw new Error("repeatOnGrid needs an indexed geometry");const l=r.count,h=e*n,u=new Float32Array(l*h*3),d=new Float32Array(l*h*3),f=new Uint32Array(c.count*h),p=-((e-1)*i)/2,v=-((n-1)*s)/2;let m=0;for(let S=0;S<n;S++)for(let x=0;x<e;x++,m++){const M=v+S*s,b=p+x*i;for(let w=0;w<l;w++){const T=(m*l+w)*3;u[T]=r.getX(w)+M,u[T+1]=r.getY(w),u[T+2]=r.getZ(w)+b,d[T]=o.getX(w),d[T+1]=o.getY(w),d[T+2]=o.getZ(w)}for(let w=0;w<c.count;w++)f[m*c.count+w]=c.getX(w)+m*l}const g=new se;return g.setAttribute("position",new de(u,3)),g.setAttribute("normal",new de(d,3)),g.setIndex(new H0(f,1)),g}static fitCropToGround(t,e){t.updateMatrixWorld(!0);const i=new R;t.traverse(n=>{const s=n,r=s.userData.cropBasePositions,o=s.userData.cropVerticesPerClump;if(!s.isMesh||!r||!o)return;const c=s.geometry.getAttribute("position"),l=new te().copy(s.matrixWorld).invert();for(let h=0;h<c.count;h+=o){i.set(r[h*3],0,r[h*3+2]).applyMatrix4(s.matrixWorld),i.y=e(i.x,i.z),i.applyMatrix4(l);for(let u=h;u<h+o;u++)c.setY(u,r[u*3+1]+i.y)}c.needsUpdate=!0,s.geometry.computeBoundingBox(),s.geometry.computeBoundingSphere()})}static paint(t,e){t.traverse(i=>{const n=i,s=n.userData;if(!n.isMesh||s?.emissive)return;const r=n.material;r?.color&&r.color.set(e)})}static build(t,e){const i=t.kind==="building"?km(t.floors??Tf,t.windows,t.observerSide,t.occupiedFloor):t.kind==="tree"?Bm():t.kind==="shrub"?zm():t.kind==="bridge"?sE(t):t.kind==="wire"?rE(t):t.kind==="crop"?Gm():t.kind==="mound"?Vm():t.kind==="streetlight"?Wm(e):t.kind==="vehicle"?Xm(e,t.windows,t.observerSide):t.kind==="aircraft"?Jm():t.kind==="entity"?Km():S0();t.color&&this.paint(i,t.color);const n=this.scaleFor(t),s=new Re;return i.name=oi.BODY_NAME,i.scale.copy(n),s.add(i),t.headingDeg!==void 0&&(s.rotation.y=-t.headingDeg*yu),this.addLights(s,t.lights),s}static scaleFor(t){const e=t.sizeM;if(!e||t.kind==="bridge"||t.kind==="wire")return new R(1,1,1);const i=this.naturalSize(t.kind,t.floors);return new R(e.widthM===void 0?1:wu(e.widthM,i.widthM),e.heightM===void 0?1:wu(e.heightM,i.heightM),e.lengthM===void 0?1:wu(e.lengthM,i.lengthM))}static naturalSize(t,e){const i=t==="building"?Math.max(1,(e??Tf)+1):0;if(t==="bridge")return Ue.NATURAL_SIZE;if(t==="wire")return Ur.NATURAL_SIZE;const n=`${t}:${i}`,s=Ym.get(n);if(s)return s;const r=t==="building"?km(i-1,void 0,void 0,void 0):t==="tree"?Bm():t==="shrub"?zm():t==="crop"?Gm():t==="mound"?Vm():t==="streetlight"?Wm(!1):t==="vehicle"?Xm(!1,void 0,void 0):t==="aircraft"?Jm():t==="entity"?Km():S0(),o=new ki().setFromObject(r),c={widthM:o.max.x-o.min.x,heightM:o.max.y-o.min.y,lengthM:o.max.z-o.min.z};return this.dispose(r),Ym.set(n,c),c}static usesModel(t){return Zu(t)!==void 0&&!(t.observerSide!==void 0&&Lg(t.kind))}static applyModel(t,e,i,n={}){const s=this.bodyOf(t),r=new Re;r.name=oi.BODY_NAME,i.rotation.y=-(n.headingOffsetDeg??0)*yu,i.updateMatrixWorld(!0);const o=new ki().setFromObject(i),c={lengthM:o.max.z-o.min.z,heightM:o.max.y-o.min.y,widthM:o.max.x-o.min.x},l=qm(e.sizeM,c)??qm(n.depictedSizeM,c)??1;i.scale.multiplyScalar(l);const h=o.getCenter(new R).multiplyScalar(l);i.position.x-=h.x,i.position.z-=h.z,i.position.y-=e.kind==="aircraft"?h.y:o.min.y*l,i.traverse(u=>{u instanceof bt&&(u.castShadow=!0,u.receiveShadow=!0)}),r.add(i),s.parent?(s.parent.add(r),s.removeFromParent()):t.add(r),this.dispose(s)}static sizeOf(t){const e=this.naturalSize(t.kind,t.floors);return{widthM:t.sizeM?.widthM??e.widthM,lengthM:t.sizeM?.lengthM??e.lengthM,heightM:t.sizeM?.heightM??e.heightM}}static addLights(t,e){for(const i of e??[]){const n=J5(i.color),s=Pe(t,new di(Su,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=Ai,r.transparent=!0,r.depthWrite=!1,r.fog=!1}}static setLights(t,e,i,n,s=0,r=1,o=X5,c=[1,1,1]){if(!e||e.length===0)return;const l=new Map(e.map(f=>[f.id,f])),h=Math.max(1,n*o/Su),u=Su*h,d=r/(Math.PI*u*u);for(const f of t.children){if(!(f instanceof bt))continue;const p=f.userData.lightId;if(!p)continue;const v=l.get(p);if(!v)continue;const m=s>0?Ng(v,i,i+s):Fv(v,i)?1:0;f.visible=m>0;const g=f.material,S=f.userData.lightColor;if(S){const x=m*Y5*(v.intensity??1)*d;g.color.setRGB(S[0]*x*c[0],S[1]*x*c[1],S[2]*x*c[2])}f.scale.setScalar(h)}}static setLit(t,e,i,n=1){const[s,r,o]=e==="streetlight"?[q5,$5,hv]:[K5,Z5,uv],c=i?s*n/(Math.PI*r*r):0,l=[o[0]*c,o[1]*c,o[2]*c];t.traverse(h=>{const u=h.userData;!(h instanceof bt)||!u.emissive||u.lightId||h.material.color.setRGB(...l)})}static dispose(t){t.traverse(e=>{if(!(e instanceof bt)||e.userData.sharedModel)return;e.geometry.dispose();const i=e.material;for(const n of Array.isArray(i)?i:[i])n.dispose()})}}const Au="https://ufoathome.org/models/index.json";class $o{attribution="3D models re-hosted by UFO@home, each under its own author's licence";fetchImpl;indexUrls;loading;static shared=new Map;sharing;constructor(t={}){this.sharing=!t.fetchImpl,this.fetchImpl=t.fetchImpl??fetch.bind(globalThis),this.indexUrls=t.indexUrls??pE()}async entries(t){const e=await this.load();return t?e.filter(i=>[i.kind].flat().includes(t)):e}async entry(t){return(await this.load()).find(e=>e.id===t)}load(){if(this.loading)return this.loading;if(!this.sharing)return this.loading=this.fetchFirstAvailable();const t=this.indexUrls.join(`
7292
+ `);let e=$o.shared.get(t);return e||(e=this.fetchFirstAvailable(),$o.shared.set(t,e),e.then(i=>{i.length===0&&$o.shared.delete(t)})),this.loading=e}async fetchFirstAvailable(){for(const t of this.indexUrls){const e=await this.fetchIndex(t);if(e)return e}return[]}async fetchIndex(t){try{const e=await this.fetchImpl(t);if(!e.ok)return;const i=await e.json();return Array.isArray(i?.models)?i.models.map(({file:n,...s})=>({...s,url:new URL(n,t).href})):void 0}catch{return}}}function pE(){const a=`?v=${encodeURIComponent("0.98.0")}`,t=typeof location>"u"?void 0:new URL("/models/index.json",location.href).href;return(t&&t!==Au?[t,Au]:[Au]).map(e=>e+a)}const mE=[{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 $o}];async function Tu(a){const{GLTFLoader:t}=await $i(async()=>{const{GLTFLoader:i}=await import("./GLTFLoader-DYi1DaRQ.js");return{GLTFLoader:i}},[],import.meta.url),e=new t;return new Promise((i,n)=>{e.load(a,s=>i(Object.assign(s.scene,{animations:s.animations})),void 0,s=>n(new Error(`Could not load 3D model ${a}: ${s instanceof Error?s.message:String(s)}`)))})}const Mv=["ellipsoid","sphere","disc","cylinder","cone","box","torus","figure"];class gn{static MIN_ANGLE_RAD=.002;static FILL=(1-Math.exp(-4))/4;static MAX_SHARE=.3;mesh;constructor(t,e){this.mesh=new bt(new Zi(2,2),new fe({uniforms:{uColor:{value:new st(0,0,0)},uRadius:{value:1}},vertexShader:gn.VERTEX,fragmentShader:gn.FRAGMENT,transparent:!0,depthWrite:!1,blending:Ai,toneMapped:!1})),this.mesh.name=t,this.mesh.frustumCulled=!1,this.mesh.renderOrder=e,this.mesh.visible=!1}shine(t,e,i){this.mesh.visible=!0,this.mesh.position.set(t.x,t.y,t.z),this.mesh.material.uniforms.uRadius.value=e,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(t,e,i,n){const s=Math.max(t,n*gn.MIN_ANGLE_RAD),r=gn.FILL*Math.PI*s*s;return{radiusM:s,luminanceCdM2:i*Math.min(gn.MAX_SHARE,e/r)}}static conserving(t){return Math.sqrt(t/(gn.MAX_SHARE*gn.FILL*Math.PI))}static VERTEX=`
7293
7293
  uniform float uRadius;
7294
7294
  varying vec2 vOffset;
7295
7295
  void main() {
@@ -7307,7 +7307,7 @@ ${Dt.OUTPUT_PROJECTION_GLSL}`)}}class Hi{constructor(t,e){this.width=t,this.heig
7307
7307
  float weight = exp(-4.0 * d2);
7308
7308
  gl_FragColor = vec4(uColor * weight, weight);
7309
7309
  }
7310
- `}class kr{static RENDER_ORDER=3;static LIGHT_AT=.35;static GLOW_MIN_ANGLE_RAD=gn.MIN_ANGLE_RAD;static GLOW_FILL=gn.FILL;static GLOW_MAX_SHARE=gn.MAX_SHARE;mesh;light=new I1(16777215,0,0,2);glare=new gn("flame-glow",kr.RENDER_ORDER);scratch=new R;constructor(){const t=[];for(let s=0;s<=32;s++){const r=s/32,o=.5*(.7+.3*Math.sin(Math.min(1,r/.33)*Math.PI/2))*Math.pow(1-r,.55);t.push(new Mt(Math.max(o,1e-4),-r))}const i=new fh(t,48),n=new de({uniforms:{uTime:{value:0},uColor:{value:new st(1,1,1)},uTipColor:{value:new st(1,1,1)}},vertexShader:kr.VERTEX,fragmentShader:kr.FRAGMENT,transparent:!0,depthWrite:!1,blending:Ai,side:xn,toneMapped:!1});this.mesh=new bt(i,n),this.mesh.name="flame",this.mesh.frustumCulled=!1,this.mesh.renderOrder=kr.RENDER_ORDER,this.mesh.visible=!1}get glow(){return this.glare.mesh}static glowFor(t,e){return gn.spread(t.widthM*.6,.7*t.widthM*t.lengthM,t.luminanceCdM2,e)}shine(t,e){this.scratch.set(0,-.5,0).applyMatrix4(this.mesh.matrixWorld),this.glare.shine(this.scratch,t,e)}putOut(){this.mesh.visible=!1,this.glare.hide(),this.light.intensity=0}place(t,e,i,n){this.mesh.visible=!0,this.mesh.position.set(t.x,t.y,t.z),this.mesh.quaternion.set(e.x,e.y,e.z,e.w),this.mesh.scale.set(n,i,n),this.mesh.updateMatrixWorld(),this.light.position.set(0,-.35,0).applyMatrix4(this.mesh.matrixWorld)}set(t,e,i){const n=this.mesh.material.uniforms;n.uColor.value.setRGB(t[0],t[1],t[2]),n.uTipColor.value.setRGB(e[0],e[1],e[2]),n.uTime.value=i}illuminate(t,e){this.light.intensity=t,this.light.color.setRGB(e[0],e[1],e[2])}dispose(){this.mesh.geometry.dispose(),this.mesh.material.dispose(),this.glare.dispose()}static VERTEX=`
7310
+ `}class kr{static RENDER_ORDER=3;static LIGHT_AT=.35;static GLOW_MIN_ANGLE_RAD=gn.MIN_ANGLE_RAD;static GLOW_FILL=gn.FILL;static GLOW_MAX_SHARE=gn.MAX_SHARE;mesh;light=new I1(16777215,0,0,2);glare=new gn("flame-glow",kr.RENDER_ORDER);scratch=new R;constructor(){const t=[];for(let s=0;s<=32;s++){const r=s/32,o=.5*(.7+.3*Math.sin(Math.min(1,r/.33)*Math.PI/2))*Math.pow(1-r,.55);t.push(new Mt(Math.max(o,1e-4),-r))}const i=new fh(t,48),n=new fe({uniforms:{uTime:{value:0},uColor:{value:new st(1,1,1)},uTipColor:{value:new st(1,1,1)}},vertexShader:kr.VERTEX,fragmentShader:kr.FRAGMENT,transparent:!0,depthWrite:!1,blending:Ai,side:xn,toneMapped:!1});this.mesh=new bt(i,n),this.mesh.name="flame",this.mesh.frustumCulled=!1,this.mesh.renderOrder=kr.RENDER_ORDER,this.mesh.visible=!1}get glow(){return this.glare.mesh}static glowFor(t,e){return gn.spread(t.widthM*.6,.7*t.widthM*t.lengthM,t.luminanceCdM2,e)}shine(t,e){this.scratch.set(0,-.5,0).applyMatrix4(this.mesh.matrixWorld),this.glare.shine(this.scratch,t,e)}putOut(){this.mesh.visible=!1,this.glare.hide(),this.light.intensity=0}place(t,e,i,n){this.mesh.visible=!0,this.mesh.position.set(t.x,t.y,t.z),this.mesh.quaternion.set(e.x,e.y,e.z,e.w),this.mesh.scale.set(n,i,n),this.mesh.updateMatrixWorld(),this.light.position.set(0,-.35,0).applyMatrix4(this.mesh.matrixWorld)}set(t,e,i){const n=this.mesh.material.uniforms;n.uColor.value.setRGB(t[0],t[1],t[2]),n.uTipColor.value.setRGB(e[0],e[1],e[2]),n.uTime.value=i}illuminate(t,e){this.light.intensity=t,this.light.color.setRGB(e[0],e[1],e[2])}dispose(){this.mesh.geometry.dispose(),this.mesh.material.dispose(),this.glare.dispose()}static VERTEX=`
7311
7311
  varying vec3 vLocal;
7312
7312
  varying vec3 vViewNormal;
7313
7313
  varying vec3 vViewPosition;
@@ -7368,7 +7368,7 @@ ${Dt.OUTPUT_PROJECTION_GLSL}`)}}class Hi{constructor(t,e){this.width=t,this.heig
7368
7368
  vec3 colour = mix(uColor, uTipColor, smoothstep(0.35, 0.95, s));
7369
7369
  gl_FragColor = vec4(colour * body, body);
7370
7370
  }
7371
- `}class ps{constructor(t){this.kind=t;const e=new se;this.positions=new Float32Array(t.count*3),this.sizes=new Float32Array(t.count),this.alphas=new Float32Array(t.count),e.setAttribute("position",new Jt(this.positions,3)),e.setAttribute("size",new Jt(this.sizes,1)),e.setAttribute("alpha",new Jt(this.alphas,1)),this.seeds=Array.from({length:t.count},(s,r)=>[ps.hash(r*3+1)*2*Math.PI,.5+ps.hash(r*3+2),.6+.8*ps.hash(r*3+3)]);const i=new de({uniforms:{uColour:{value:new st(t.colour[0],t.colour[1],t.colour[2])},uLight:{value:new st(1,1,1)},uHalfHeight:{value:500}},vertexShader:ps.VERTEX,fragmentShader:ps.FRAGMENT,transparent:!0,depthWrite:!1,blending:dr,toneMapped:!1});this.points=new mn(e,i),this.points.frustumCulled=!1,this.points.renderOrder=3,this.points.visible=!1;const n=new Mt;this.points.onBeforeRender=s=>{const r=s.getRenderTarget();this.points.material.uniforms.uHalfHeight.value=(r?r.height:s.getDrawingBufferSize(n).y)/2}}static DUST={count:160,lifeS:2.2,startRadiusM:.4,spreadMS:2.5,riseMS:.8,birthSizeM:.5,deathSizeM:2.2,colour:[.52,.44,.33],opacity:.35};static SMOKE={count:60,lifeS:7,startRadiusM:.1,spreadMS:.15,riseMS:.7,birthSizeM:.6,deathSizeM:3.5,colour:[.42,.42,.42],opacity:.18};points;positions;sizes;alphas;seeds;set(t,e,i,n,s,r,o=[1,1,1]){const c=this.kind;if(this.points.visible=r>0,!this.points.visible)return;this.points.material.uniforms.uLight.value.setRGB(o[0],o[1],o[2]);for(let h=0;h<c.count;h++){const[u,d,f]=this.seeds[h],p=((n+h/c.count*c.lifeS)%c.lifeS+c.lifeS)%c.lifeS,v=p/c.lifeS,m=c.startRadiusM+c.spreadMS*d*Math.sqrt(p);this.positions[h*3]=t+Math.cos(u)*m+s.x*p,this.positions[h*3+1]=e+c.riseMS*f*p,this.positions[h*3+2]=i+Math.sin(u)*m+s.z*p,this.sizes[h]=c.birthSizeM+(c.deathSizeM-c.birthSizeM)*v,this.alphas[h]=c.opacity*r*Math.min(1,v*8)*(1-v)}const l=this.points.geometry;l.getAttribute("position").needsUpdate=!0,l.getAttribute("size").needsUpdate=!0,l.getAttribute("alpha").needsUpdate=!0}dispose(){this.points.geometry.dispose(),this.points.material.dispose()}static hash(t){const e=Math.sin(t*12.9898)*43758.5453;return e-Math.floor(e)}static VERTEX=`
7371
+ `}class ps{constructor(t){this.kind=t;const e=new se;this.positions=new Float32Array(t.count*3),this.sizes=new Float32Array(t.count),this.alphas=new Float32Array(t.count),e.setAttribute("position",new Jt(this.positions,3)),e.setAttribute("size",new Jt(this.sizes,1)),e.setAttribute("alpha",new Jt(this.alphas,1)),this.seeds=Array.from({length:t.count},(s,r)=>[ps.hash(r*3+1)*2*Math.PI,.5+ps.hash(r*3+2),.6+.8*ps.hash(r*3+3)]);const i=new fe({uniforms:{uColour:{value:new st(t.colour[0],t.colour[1],t.colour[2])},uLight:{value:new st(1,1,1)},uHalfHeight:{value:500}},vertexShader:ps.VERTEX,fragmentShader:ps.FRAGMENT,transparent:!0,depthWrite:!1,blending:dr,toneMapped:!1});this.points=new mn(e,i),this.points.frustumCulled=!1,this.points.renderOrder=3,this.points.visible=!1;const n=new Mt;this.points.onBeforeRender=s=>{const r=s.getRenderTarget();this.points.material.uniforms.uHalfHeight.value=(r?r.height:s.getDrawingBufferSize(n).y)/2}}static DUST={count:160,lifeS:2.2,startRadiusM:.4,spreadMS:2.5,riseMS:.8,birthSizeM:.5,deathSizeM:2.2,colour:[.52,.44,.33],opacity:.35};static SMOKE={count:60,lifeS:7,startRadiusM:.1,spreadMS:.15,riseMS:.7,birthSizeM:.6,deathSizeM:3.5,colour:[.42,.42,.42],opacity:.18};points;positions;sizes;alphas;seeds;set(t,e,i,n,s,r,o=[1,1,1]){const c=this.kind;if(this.points.visible=r>0,!this.points.visible)return;this.points.material.uniforms.uLight.value.setRGB(o[0],o[1],o[2]);for(let h=0;h<c.count;h++){const[u,d,f]=this.seeds[h],p=((n+h/c.count*c.lifeS)%c.lifeS+c.lifeS)%c.lifeS,v=p/c.lifeS,m=c.startRadiusM+c.spreadMS*d*Math.sqrt(p);this.positions[h*3]=t+Math.cos(u)*m+s.x*p,this.positions[h*3+1]=e+c.riseMS*f*p,this.positions[h*3+2]=i+Math.sin(u)*m+s.z*p,this.sizes[h]=c.birthSizeM+(c.deathSizeM-c.birthSizeM)*v,this.alphas[h]=c.opacity*r*Math.min(1,v*8)*(1-v)}const l=this.points.geometry;l.getAttribute("position").needsUpdate=!0,l.getAttribute("size").needsUpdate=!0,l.getAttribute("alpha").needsUpdate=!0}dispose(){this.points.geometry.dispose(),this.points.material.dispose()}static hash(t){const e=Math.sin(t*12.9898)*43758.5453;return e-Math.floor(e)}static VERTEX=`
7372
7372
  attribute float size;
7373
7373
  attribute float alpha;
7374
7374
  uniform float uHalfHeight;
@@ -7391,7 +7391,7 @@ ${Dt.OUTPUT_PROJECTION_GLSL}`)}}class Hi{constructor(t,e){this.width=t,this.heig
7391
7391
  if (d2 > 1.0) discard;
7392
7392
  gl_FragColor = vec4(uColour * uLight, vAlpha * exp(-3.0 * d2));
7393
7393
  }
7394
- `}class $n{static shown(t,e,i){const n=i?i([1,1,1],e):$n.withoutPhotometry([1,1,1],e),s=Et.fromLightness(Et.respond($n.luminanceOf(n))),r=Math.max(t[0],t[1],t[2])||1,o=[t[0]/r,t[1]/r,t[2]/r],c=$n.luminanceOf(o);if(!(c>0)||!(s>0))return[0,0,0];const l=Et.relativeOfResponse(Et.lightnessOf(c*s))/c;return[o[0]*l,o[1]*l,o[2]*l]}static response(t){return Et.respond($n.luminanceOf(t))}static withoutPhotometry(t,e){const i=Et.relativeOfResponse(e/(e+1e4));return[t[0]*i,t[1]*i,t[2]*i]}static luminanceOf(t){return .2126*t[0]+.7152*t[1]+.0722*t[2]}}class uc extends de{static ABSORPTION=.03;constructor(t=1.5){super({uniforms:{uSurroundings:{value:null},uIndex:{value:t},uAbsorption:{value:uc.ABSORPTION}},vertexShader:`
7394
+ `}class $n{static shown(t,e,i){const n=i?i([1,1,1],e):$n.withoutPhotometry([1,1,1],e),s=Et.fromLightness(Et.respond($n.luminanceOf(n))),r=Math.max(t[0],t[1],t[2])||1,o=[t[0]/r,t[1]/r,t[2]/r],c=$n.luminanceOf(o);if(!(c>0)||!(s>0))return[0,0,0];const l=Et.relativeOfResponse(Et.lightnessOf(c*s))/c;return[o[0]*l,o[1]*l,o[2]*l]}static response(t){return Et.respond($n.luminanceOf(t))}static withoutPhotometry(t,e){const i=Et.relativeOfResponse(e/(e+1e4));return[t[0]*i,t[1]*i,t[2]*i]}static luminanceOf(t){return .2126*t[0]+.7152*t[1]+.0722*t[2]}}class uc extends fe{static ABSORPTION=.03;constructor(t=1.5){super({uniforms:{uSurroundings:{value:null},uIndex:{value:t},uAbsorption:{value:uc.ABSORPTION}},vertexShader:`
7395
7395
  varying vec3 vWorldPosition;
7396
7396
  varying vec3 vWorldNormal;
7397
7397
  void main() {
@@ -7709,7 +7709,7 @@ cloudPoint = (modelMatrix * vec4(transformed, 1.0)).xyz - cameraPosition;`);let
7709
7709
  }
7710
7710
  outColor = xyzs;
7711
7711
  }
7712
- `}class ke{static AIRGLOW_LAYER_ALTITUDE_M=9e4;static SUN_MAGNITUDE=-26.74;tables;material;onChange;state;drawnKey="";hasViews=!1;adaptingLuminance=1;get adaptation(){return this.adaptingLuminance*this.exposureScale}get sceneAdaptation(){return this.adaptingLuminance}ambientColours;reading=!1;exposureScale=1;seenByEye=!0;readAgain=!1;constructor(t,e){this.onChange=e,this.tables=new Yt(t),this.tables.setMedium(new Ut),this.material=new de({glslVersion:Xl,side:qe,depthWrite:!1,uniforms:{uSunView:{value:this.tables.sunViewTexture},uMoonView:{value:this.tables.moonViewTexture},uSunAzimuth:{value:new Mt(0,-1)},uMoonAzimuth:{value:new Mt(0,-1)},uMoonScale:{value:0},uObserverRadius:{value:Ut.GROUND_RADIUS_M+2},uAirglow:{value:new ae(...ke.airglowXyzs())},uArtificial:{value:new ae(0,0,0,0)},uRodShare:{value:0},uInverseSemiSaturation:{value:1},uExposureScale:{value:1}},vertexShader:`
7712
+ `}class ke{static AIRGLOW_LAYER_ALTITUDE_M=9e4;static SUN_MAGNITUDE=-26.74;tables;material;onChange;state;drawnKey="";hasViews=!1;adaptingLuminance=1;get adaptation(){return this.adaptingLuminance*this.exposureScale}get sceneAdaptation(){return this.adaptingLuminance}ambientColours;reading=!1;exposureScale=1;seenByEye=!0;readAgain=!1;constructor(t,e){this.onChange=e,this.tables=new Yt(t),this.tables.setMedium(new Ut),this.material=new fe({glslVersion:Xl,side:qe,depthWrite:!1,uniforms:{uSunView:{value:this.tables.sunViewTexture},uMoonView:{value:this.tables.moonViewTexture},uSunAzimuth:{value:new Mt(0,-1)},uMoonAzimuth:{value:new Mt(0,-1)},uMoonScale:{value:0},uObserverRadius:{value:Ut.GROUND_RADIUS_M+2},uAirglow:{value:new ae(...ke.airglowXyzs())},uArtificial:{value:new ae(0,0,0,0)},uRodShare:{value:0},uInverseSemiSaturation:{value:1},uExposureScale:{value:1}},vertexShader:`
7713
7713
  varying vec3 vDirection;
7714
7714
  void main() {
7715
7715
  vDirection = (modelMatrix * vec4(position, 1.0)).xyz - cameraPosition;
@@ -7831,7 +7831,7 @@ cloudPoint = (modelMatrix * vec4(transformed, 1.0)).xyz - cameraPosition;`);let
7831
7831
  vec3 aerialTransmittance = exp(-aerialExtinction * aerialDistance);
7832
7832
  gl_FragColor.rgb = gl_FragColor.rgb * aerialTransmittance + fogColor * (1.0 - aerialTransmittance);
7833
7833
  #endif
7834
- #endif`}}class he{static HAZE_COARSE_MODE={medianRadiusUm:1.5,geometricSigma:2};static CLOUD_DROPLETS={medianRadiusUm:8,geometricSigma:1.15};static COARSE_FRACTION=.3;static DIFFRACTED_SHARE=.5;static MAX_ANGLE_RAD=30*Math.PI/180;static STEPS=512;static RADII=32;static bessel1(t){const e=Math.abs(t);if(e<8){const l=t*t,h=t*(72362614232+l*(-7895059235+l*(2423968531e-1+l*(-2972611439e-3+l*(15704.4826+l*-30.16036606))))),u=144725228442+l*(2300535178+l*(1858330474e-2+l*(99447.43394+l*(376.9991397+l))));return h/u}const i=8/e,n=i*i,s=e-2.356194491,r=1+n*(.00183105+n*(-3516396496e-14+n*(2457520174e-15+n*-240337019e-15))),o=.04687499995+n*(-.0002002690873+n*(8449199096e-15+n*(-88228987e-14+n*105787412e-15))),c=Math.sqrt(.636619772/e)*(Math.cos(s)*r-i*Math.sin(s)*o);return t<0?-c:c}static airy(t){if(Math.abs(t)<1e-6)return 1;const e=2*he.bessel1(t)/t;return e*e}static phaseOf(t,e,i){const n=2*Math.PI*e*1e3/i;return n*n/(4*Math.PI)*he.airy(n*Math.sin(t))}static phase(t,e,i){let n=0,s=0;for(const{radiusUm:r,weight:o}of he.radiiOf(i))n+=o*he.phaseOf(t,r,e),s+=o;return n/s}static profile(t){const e=`${t.medianRadiusUm}:${t.geometricSigma}`,i=he.profiles.get(e);if(i)return i;const n=he.STEPS,s=new Float32Array(n*3),r=he.radiiOf(t),o=r.reduce((c,{weight:l})=>c+l,0);for(let c=0;c<n;c++){const l=c/(n-1)*he.MAX_ANGLE_RAD;let h=0,u=0,d=0;for(const f of vi.SAMPLES){let p=0;for(const{radiusUm:v,weight:m}of r)p+=m*he.phaseOf(l,v,f.wavelengthNm);p/=o,h+=p*f.r,u+=p*f.g,d+=p*f.b}s[c*3]=h,s[c*3+1]=u,s[c*3+2]=d}return he.profiles.set(e,s),s}static profiles=new Map;static radiiOf(t){const e=he.RADII,i=Math.log(Math.max(t.geometricSigma,1.0001)),n=[];for(let s=0;s<e;s++){const r=-3+6*(s+.5)/e;n.push({radiusUm:t.medianRadiusUm*Math.exp(r*i),weight:Math.exp(-.5*r*r)})}return n}static illuminanceOf(t){return 10**((-14.18-t)/2.5)}static aureoleScale(t,e){const i=t*e;return he.DIFFRACTED_SHARE*he.COARSE_FRACTION*i*Math.exp(-i)}static coronaScale(t){return he.DIFFRACTED_SHARE*t*Math.exp(-t)}static airMass(t){const e=Math.max(t,0);return 1/(Math.sin(e*Math.PI/180)+.50572*(e+6.07995)**-1.6364)}}class vn{static EARTH_RADIUS_M=6371e3;static DEG=Math.PI/180;static SUN_DISC_DEG=.54;static HORIZON_REFRACTION_DEG=.57;static dipDeg(t){return Math.acos(vn.EARTH_RADIUS_M/(vn.EARTH_RADIUS_M+Math.max(t,0)))/vn.DEG}static sunElevationDeg(t,e,i){const n=vn.DEG,s=e.lat*n,r=e.lng*n,o=t.altitudeDeg*n,c=t.azimuthDeg*n,l=[-Math.sin(r),Math.cos(r),0],h=[-Math.sin(s)*Math.cos(r),-Math.sin(s)*Math.sin(r),Math.cos(s)],u=[Math.cos(s)*Math.cos(r),Math.cos(s)*Math.sin(r),Math.sin(s)],d=[0,1,2].map(g=>l[g]*Math.sin(c)*Math.cos(o)+h[g]*Math.cos(c)*Math.cos(o)+u[g]*Math.sin(o)),f=i.lat*n,p=i.lng*n,v=[Math.cos(f)*Math.cos(p),Math.cos(f)*Math.sin(p),Math.sin(f)],m=d[0]*v[0]+d[1]*v[1]+d[2]*v[2];return Math.asin(Math.max(-1,Math.min(1,m)))/n}static litFraction(t,e){const i=t+vn.dipDeg(e)+vn.HORIZON_REFRACTION_DEG,n=Math.min(1,Math.max(0,i/vn.SUN_DISC_DEG+.5));return n*n*(3-2*n)}}class Cn{static ID_PREFIX="traffic-";static keyOf(t){return`${t.nonIcao?"x":""}${t.icao.toString(16).padStart(6,"0")}`}static idOf(t,e){return`${Cn.ID_PREFIX}${Cn.keyOf(t)}-${e}`}}class ff{static RADIUS=Ti.RADIUS;object;texels;texture;up=new R(0,1,0);towards=new R;constructor(){const t=he.STEPS;this.texels=new Uint16Array(t*4),this.texture=new Mr(this.texels,t,1,Di,$e),this.texture.minFilter=le,this.texture.magFilter=le,this.texture.wrapS=Ri,this.texture.wrapT=Ri,this.texture.needsUpdate=!0;const e=new de({uniforms:{uSource:{value:new R(0,1,0)},uMaxAngle:{value:he.MAX_ANGLE_RAD},uMap:{value:this.texture},uSteps:{value:t}},vertexShader:`
7834
+ #endif`}}class ue{static HAZE_COARSE_MODE={medianRadiusUm:1.5,geometricSigma:2};static CLOUD_DROPLETS={medianRadiusUm:8,geometricSigma:1.15};static COARSE_FRACTION=.3;static DIFFRACTED_SHARE=.5;static MAX_ANGLE_RAD=30*Math.PI/180;static STEPS=512;static RADII=32;static bessel1(t){const e=Math.abs(t);if(e<8){const l=t*t,h=t*(72362614232+l*(-7895059235+l*(2423968531e-1+l*(-2972611439e-3+l*(15704.4826+l*-30.16036606))))),u=144725228442+l*(2300535178+l*(1858330474e-2+l*(99447.43394+l*(376.9991397+l))));return h/u}const i=8/e,n=i*i,s=e-2.356194491,r=1+n*(.00183105+n*(-3516396496e-14+n*(2457520174e-15+n*-240337019e-15))),o=.04687499995+n*(-.0002002690873+n*(8449199096e-15+n*(-88228987e-14+n*105787412e-15))),c=Math.sqrt(.636619772/e)*(Math.cos(s)*r-i*Math.sin(s)*o);return t<0?-c:c}static airy(t){if(Math.abs(t)<1e-6)return 1;const e=2*ue.bessel1(t)/t;return e*e}static phaseOf(t,e,i){const n=2*Math.PI*e*1e3/i;return n*n/(4*Math.PI)*ue.airy(n*Math.sin(t))}static phase(t,e,i){let n=0,s=0;for(const{radiusUm:r,weight:o}of ue.radiiOf(i))n+=o*ue.phaseOf(t,r,e),s+=o;return n/s}static profile(t){const e=`${t.medianRadiusUm}:${t.geometricSigma}`,i=ue.profiles.get(e);if(i)return i;const n=ue.STEPS,s=new Float32Array(n*3),r=ue.radiiOf(t),o=r.reduce((c,{weight:l})=>c+l,0);for(let c=0;c<n;c++){const l=c/(n-1)*ue.MAX_ANGLE_RAD;let h=0,u=0,d=0;for(const f of vi.SAMPLES){let p=0;for(const{radiusUm:v,weight:m}of r)p+=m*ue.phaseOf(l,v,f.wavelengthNm);p/=o,h+=p*f.r,u+=p*f.g,d+=p*f.b}s[c*3]=h,s[c*3+1]=u,s[c*3+2]=d}return ue.profiles.set(e,s),s}static profiles=new Map;static radiiOf(t){const e=ue.RADII,i=Math.log(Math.max(t.geometricSigma,1.0001)),n=[];for(let s=0;s<e;s++){const r=-3+6*(s+.5)/e;n.push({radiusUm:t.medianRadiusUm*Math.exp(r*i),weight:Math.exp(-.5*r*r)})}return n}static illuminanceOf(t){return 10**((-14.18-t)/2.5)}static aureoleScale(t,e){const i=t*e;return ue.DIFFRACTED_SHARE*ue.COARSE_FRACTION*i*Math.exp(-i)}static coronaScale(t){return ue.DIFFRACTED_SHARE*t*Math.exp(-t)}static airMass(t){const e=Math.max(t,0);return 1/(Math.sin(e*Math.PI/180)+.50572*(e+6.07995)**-1.6364)}}class vn{static EARTH_RADIUS_M=6371e3;static DEG=Math.PI/180;static SUN_DISC_DEG=.54;static HORIZON_REFRACTION_DEG=.57;static dipDeg(t){return Math.acos(vn.EARTH_RADIUS_M/(vn.EARTH_RADIUS_M+Math.max(t,0)))/vn.DEG}static sunElevationDeg(t,e,i){const n=vn.DEG,s=e.lat*n,r=e.lng*n,o=t.altitudeDeg*n,c=t.azimuthDeg*n,l=[-Math.sin(r),Math.cos(r),0],h=[-Math.sin(s)*Math.cos(r),-Math.sin(s)*Math.sin(r),Math.cos(s)],u=[Math.cos(s)*Math.cos(r),Math.cos(s)*Math.sin(r),Math.sin(s)],d=[0,1,2].map(g=>l[g]*Math.sin(c)*Math.cos(o)+h[g]*Math.cos(c)*Math.cos(o)+u[g]*Math.sin(o)),f=i.lat*n,p=i.lng*n,v=[Math.cos(f)*Math.cos(p),Math.cos(f)*Math.sin(p),Math.sin(f)],m=d[0]*v[0]+d[1]*v[1]+d[2]*v[2];return Math.asin(Math.max(-1,Math.min(1,m)))/n}static litFraction(t,e){const i=t+vn.dipDeg(e)+vn.HORIZON_REFRACTION_DEG,n=Math.min(1,Math.max(0,i/vn.SUN_DISC_DEG+.5));return n*n*(3-2*n)}}class Cn{static ID_PREFIX="traffic-";static keyOf(t){return`${t.nonIcao?"x":""}${t.icao.toString(16).padStart(6,"0")}`}static idOf(t,e){return`${Cn.ID_PREFIX}${Cn.keyOf(t)}-${e}`}}class ff{static RADIUS=Ti.RADIUS;object;texels;texture;up=new R(0,1,0);towards=new R;constructor(){const t=ue.STEPS;this.texels=new Uint16Array(t*4),this.texture=new Mr(this.texels,t,1,Di,$e),this.texture.minFilter=le,this.texture.magFilter=le,this.texture.wrapS=Ri,this.texture.wrapT=Ri,this.texture.needsUpdate=!0;const e=new fe({uniforms:{uSource:{value:new R(0,1,0)},uMaxAngle:{value:ue.MAX_ANGLE_RAD},uMap:{value:this.texture},uSteps:{value:t}},vertexShader:`
7835
7835
  varying vec3 vDirection;
7836
7836
  void main() {
7837
7837
  vDirection = normalize((modelMatrix * vec4(position, 1.0)).xyz - cameraPosition);
@@ -7852,7 +7852,7 @@ cloudPoint = (modelMatrix * vec4(transformed, 1.0)).xyz - cameraPosition;`);let
7852
7852
  vec3 light = texture2D(uMap, vec2((along * (uSteps - 1.0) + 0.5) / uSteps, 0.5)).rgb;
7853
7853
  gl_FragColor = vec4(light, 1.0);
7854
7854
  }
7855
- `,transparent:!0,blending:Ai,depthWrite:!1,side:qe,fog:!1});this.object=new bt(new di(ff.RADIUS,128,32,0,Math.PI*2,0,he.MAX_ANGLE_RAD),e),this.object.renderOrder=-1,this.object.frustumCulled=!1,this.object.visible=!1}show(t,e){if(!t||!e){this.object.visible=!1;return}this.towards.set(t.x,t.y,t.z).normalize(),this.object.quaternion.setFromUnitVectors(this.up,this.towards),this.object.material.uniforms.uSource.value.copy(this.towards);for(let i=0;i<he.STEPS;i++){for(let n=0;n<3;n++)this.texels[i*4+n]=Ln.toHalfFloat(Math.min(e[i*3+n],6e4));this.texels[i*4+3]=Ln.toHalfFloat(1)}this.texture.needsUpdate=!0,this.object.visible=!0}dispose(){this.object.geometry.dispose(),this.object.material.dispose(),this.texture.dispose()}}class rh{constructor(t){this.generator=t}static SIZE=128;target=new lc(rh.SIZE,{type:$e,generateMipmaps:!1,minFilter:le,magFilter:le});camera=new $0(.1,2e5,this.target);filteredTarget;capturedAtMs=-1/0;capturedVersion;get sharp(){return this.target.texture}get filtered(){return this.filteredTarget?.texture}capture(t,e,i,n=[]){const s=t.shadowMap.autoUpdate;let r=!1;e.traverse(c=>{const l=c;l.isLight&&l.castShadow&&l.shadow&&!l.shadow.map&&(r=!0)}),t.shadowMap.autoUpdate=r?s:!1;const o=n.map(c=>c.visible);for(const c of n)c.visible=!1;this.camera.position.copy(i),this.camera.update(t,e),n.forEach((c,l)=>{c.visible=o[l]}),t.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 sn{static REFRESH_MS=250;generator;eye;probes=new Map;constructor(t){sn.install(),this.generator=new Wd(t),this.eye=new rh(this.generator)}static decor;refresh(t,e,i,n,s,r,o,c=[],l,h=sn.REFRESH_MS){for(const m of[...this.probes.keys()])n.some(g=>g.id===m&&g.shiny)||(this.probes.get(m).dispose(),this.probes.delete(m));const u=[{probe:this.eye}];for(const m of n){if(!m.shiny)continue;let g=this.probes.get(m.id);g||(g=new rh(this.generator),this.probes.set(m.id,g)),u.push({probe:g,reflector:m})}const d=performance.now(),f=()=>u.filter(({probe:m})=>m.capturedVersion!==o),p=f().filter(({probe:m})=>d-m.capturedAtMs>=h);if(p.length>0){const m=p.reduce((g,S)=>S.probe.capturedAtMs<g.probe.capturedAtMs?S:g);if(m.reflector){const g=m.reflector.holder.getWorldPosition(this.scratch);m.probe.capture(t,e,g,[m.reflector.holder,...s]),sn.reflectOn(m.reflector.holder,m.probe)}else{m.probe.capture(t,e,i,[...s,...c]),l?.(m.probe.sharp),sn.decor=m.probe.filtered;for(const g of r)sn.reflectOn(g,m.probe);for(const g of n)g.shiny||sn.reflectOn(g.holder,m.probe)}m.probe.capturedVersion=o}const v=f();if(v.length!==0)return Math.max(16,Math.min(...v.map(({probe:m})=>h-(d-m.capturedAtMs))))}scratch=new R;static reflectOn(t,e={filtered:sn.decor}){t.traverse(i=>{const n=i.material;for(const s of Array.isArray(n)?n:n?[n]:[])s instanceof uc?e.sharp&&s.setSurroundings(e.sharp):s instanceof ar&&e.filtered&&s.envMap!==e.filtered&&(s.envMap=e.filtered,s.needsUpdate=!0)})}dispose(){this.eye.dispose();for(const t of this.probes.values())t.dispose();this.generator.dispose()}static installed=!1;static install(){if(sn.installed)return;sn.installed=!0;const t="iblIrradiance += getIBLIrradiance( geometryNormal );";if(!qt.lights_fragment_maps.includes(t)){console.warn("Reflections: three's lights_fragment_maps changed; the environment will light diffusely too");return}qt.lights_fragment_maps=qt.lights_fragment_maps.replace(t,"// The sky's diffuse light is the hemisphere light's (see Reflections).")}}function ME(a,t){return JSON.stringify(a.cloudLayers)===JSON.stringify(t.cloudLayers)&&a.cloudCover===t.cloudCover&&a.cloudDarkness===t.cloudDarkness&&a.cloudBaseM===t.cloudBaseM&&a.highCloudCover===t.highCloudCover&&a.iceCrystalAlignment===t.iceCrystalAlignment&&a.lowerCloudCover===t.lowerCloudCover&&a.relativeHumidity===t.relativeHumidity&&a.precipitationType===t.precipitationType&&a.precipitationIntensity===t.precipitationIntensity&&a.precipitationAmount===t.precipitationAmount&&a.windDirectionDeg===t.windDirectionDeg&&a.windSpeed===t.windSpeed&&a.storm===t.storm}const ml=900,Ru=1,jm=4,Du=5,Qm=.5,ko=900,xE=6371e3,yE=3e4;function tg(a){const t=Math.sqrt(2*xE*Math.max(a,0));return Math.max(ko,Math.min(t,yE))}const Iu=.5,Cu=850,Pu=.03,SE=.015,un=850,Ro=300,js=120,_E=700,bE=.04,Do=4,Lu=1.5,eg=-1,wE=6,_0=-4,EE=2,AE=20,gl=2600,TE=.97,RE=.38,vl=_0,ig=1500,DE=400,IE=[0,45,90,135,180,225,270,315],CE=2,PE=16,ng=4e3,sg=880,Ml=40,rg=60,LE=10,OE=1,NE=150,FE=55,UE=.5,kE=17,ag=.265,og=[[0,0],...Array.from({length:8},(a,t)=>{const e=t*Math.PI/4;return[Math.cos(e)*ag,Math.sin(e)*ag]})],Ou=700,Nu=250/w0,zE=12,cg=5,Fu=6,Er=[.92,.92,.95],Uu=[.15,.15,.19],ku={snow:{fallSpeedMPerS:2,size:.3,color:new st(1,1,1),driftSensitivity:1,radiusM:25,topYM:20,opacity:.75,poolSize:2400},hail:{fallSpeedMPerS:14,size:.5,color:new st(.95,.98,1),driftSensitivity:.25,radiusM:25,topYM:10,opacity:.95,poolSize:1200}},Ta=0,zu=0,BE=150,Bu=3e3,Io=20,HE=15,lg=Ta,GE=40,hg=1,VE=9;function Hu(a){return hg+(VE-hg)*a}const ug=new st(.75,.82,.92),WE=10,XE=.5;function dg(a){return Na(a/WE,XE,1)}const Ar=200,fg=.18,pg=.32,YE=.35,mg=new st(.85,.9,.98),gg=5,vg=.85,Mg=.01;function qE(a,t,e=1){return Math.round(a*(Mg+(1-Mg)*t)*e)}function $E(a,t){return JSON.stringify(a.cloudLayers)===JSON.stringify(t.cloudLayers)&&a.cloudCover===t.cloudCover&&a.cloudDarkness===t.cloudDarkness&&a.cloudBaseM===t.cloudBaseM&&a.highCloudCover===t.highCloudCover&&a.iceCrystalAlignment===t.iceCrystalAlignment&&a.lowerCloudCover===t.lowerCloudCover}const xg=230,yg=.7,Sg=.05,KE=.6,ZE=.7,JE=.15,_g=.35,jE=3,QE=1/12,tA=.5,ss=new st(.82,.86,1),eA=2500,iA=1.6,Gu=15,nA={Venus:new st(1,.96,.85),Mars:new st(1,.55,.4),Jupiter:new st(.95,.87,.72),Saturn:new st(.92,.86,.68)};class me{renderer;scene=new ys;phenomena=new Wn(this.scene);references=new Gn(this.scene,()=>this.render());camera;celestialGroup=new Re;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(t,e){if(this.skyHoldUntilMs===null)return t;this.arrivalsPending++;let i=!0;const n=()=>{i&&(i=!1,this.arrivalsPending--,this.lastArrivalVersion=this.sceneVersion,this.skyHoldUntilMs&&this.redrawHeld())},s=e===void 0?void 0:setTimeout(n,e);return e!==void 0&&(this.arrivalDeadlineMs=Math.max(this.arrivalDeadlineMs,performance.now()+e),this.skyHoldUntilMs&&this.arrivalDeadlineMs>this.skyHoldUntilMs&&(this.skyHoldUntilMs=this.arrivalDeadlineMs,setTimeout(()=>this.render(),e+20))),t.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(t){this.surroundings=void 0,this.scatteredSky?.resetSurroundings(),this.startHold(),t&&this.awaitArrival(t).catch(()=>{})}startHold(){this.skyHoldUntilMs=Math.max(performance.now()+ng,this.arrivalDeadlineMs),this.eyeSettledVersion=-1,this.lastArrivalVersion=this.sceneVersion+1,this.iceHalos?.setUrgent(!0),this.skyGlow?.setWithheld(!0),this.onFirstFrameHold?.(!0),setTimeout(()=>this.render(),ng+20)}groundMesh;terrainMesh;terrainProviders;terrainOrigin;terrainBuildToken=0;terrainAttribution;roadSystem=new Tn;roadAttribution;roadWays;statedRoads=[];traces=[];traceLabels=new Map;tracesShown=!0;traceSystem;traceSystemLoading;traceResolution=new Mt;decorModelProvider=mE[0].create();decorModelToken=0;decorModelCredits=new Map;bodySystem=new re(t=>this.awaitArrival(this.loadBodyModel(t)),()=>this.render(),()=>this.relativeScale);bodyOrigin={x:0,z:0};starTiers=[];bodyMeshes=new Map;hitAreas=new Map;glareSprites=new Map;decorObjects=[];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(t){return(t.sizeM?.lengthM??me.TRAFFIC_MODEL_DEFAULT_LENGTH_M)*me.TRAFFIC_MODEL_RANGE_PER_METRE}pendingTrafficModels=new Map;contrails=[];contrailSystem;contrailSystemLoading;contrailSunlight=new Map;sceneSunBeam=[0,0,0];decorReferencePose;decorCurrentPose;decorTime=0;celestialLight=new Wp(16777215,0);celestialLightTarget=new Ge;skyLight=new Ux(16777215,0,0);streetlightLights=new Map;compassSprites=[];showCompass=!1;compassHovered=!1;compassForced=!1;animationFrameId=null;resolution;cssSize={width:1,height:1};frameDirty=!1;flushFrameId=null;framesDriven=!1;lastFrameTimeMs;raycaster=new Cl;weather=ch;observerElevationM=0;siteElevationM=0;air=new In;groundRadius=ko;terrainRadius=ko;cloudRendering="volume";layeredClouds;cloudLayerOffsetsM={};cloudOffsetM=new R;cloudFieldOffset=new R;cloudMesh;cirrusMesh;cirrusMaterial;cirrusUniforms;cloudMaterial;cloudUniforms;precipitationPoints;precipitationPositions;precipitationPhase;precipitationSpeedJitter;precipitationWobbleFreqJitter;precipitationWobbleAmpJitter;precipitationBounceRemaining;precipitationBounceHeight;precipitationBounceDuration;precipitationBounceVelX;precipitationBounceVelZ;precipitationUniforms;rainSystem;rainSplashSystem;rainCameraDirection=new R;rainLastVerticalFacing=-1;rainViewportSize=new Mt;lightningArmed=!1;lightningFlashes=[];lightningLevel=0;lightningBolt;lightningLight=new Wp(16777215,0);baseFogColor=[0,0,0];lastSunPosition;lensFlare;sunUnhiddenFraction=1;lensFlareArtifactIntensity=0;sunWorldPosition=new R;sunVisible=!1;lensFlareScratch=new R;sunOcclusionRaycaster=new Cl;sunOcclusionDirectionScratch=new R;sunOcclusionRightScratch=new R;sunOcclusionUpScratch=new R;ufoOcclusionRaycaster=new Cl;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(t){return Math.max(3,Math.round(6e6/Math.max(1,t)))}exposureFrameId=null;exposureInstantsDone=0;exposureInstantAt;restatingExposure=!1;lensOptics;instrumentMagnitudeGain=0;lightPollution;meteorSystem;cometTail;satelliteField;reentrySystem;iceHalos;lunarDiffraction;lunarDiffractionKey="";rainbow;skyGlow;cometKey;novaKeys=new Set;constructor(t,e=z2()){this.renderer=new jb({canvas:t,antialias:!0}),this.resolution=new xe(Math.min(window.devicePixelRatio||1,2),this.renderer.getContext()),this.renderer.setPixelRatio(this.resolution.pixelRatio),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=Ho,this.camera=new rn(60,t.width/Math.max(t.height,1),.1,ml*1.2),this.camera.position.set(0,1.6,0),this.terrainProviders=e,this.celestialLight.shadow.mapSize.set(1024,1024),this.celestialLight.shadow.camera.left=-js,this.celestialLight.shadow.camera.right=js,this.celestialLight.shadow.camera.top=js,this.celestialLight.shadow.camera.bottom=-js,this.celestialLight.shadow.camera.near=un-Ro,this.celestialLight.shadow.camera.far=un+Ro,this.celestialLight.shadow.bias=-.03/(2*Ro),this.celestialLight.shadow.normalBias=bE,this.celestialLight.target=this.celestialLightTarget,this.lightningLight.color.copy(ss),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);const i=new ke(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(t,e){this.cssSize.width=t,this.cssSize.height=e,this.renderer.setSize(t,e,!1),this.camera.aspect=t/Math.max(e,1),this.camera.updateProjectionMatrix(),this.render()}setCloudRendering(t){t!==this.cloudRendering&&(this.cloudTransmissionMemo.clear(),this.cloudRendering=t,this.layeredClouds?.dispose(),this.layeredClouds=void 0,this.buildClouds(),this.buildCirrus(),this.render())}setCloudOffset(t,e={}){this.cloudOffsetM.set(t.x,0,t.z),this.cloudLayerOffsetsM=e,this.layeredClouds?.setOffsets(t,e),this.cloudFieldOffset.set(t.x*Nu,0,t.z*Nu);for(const i of[this.cloudUniforms,this.cirrusUniforms])i?.fieldOffset.value.copy(this.cloudFieldOffset);this.iceHalos?.setCloudOffset(this.layeredClouds?.cirrusMask?.offset??this.cloudFieldOffset)}setObserverPose(t){const e=((t.rollDeg??0)+this.gaitOffset.rollDeg)*ji,i=(t.pitchDeg+this.lookPitchDeg+this.gaitOffset.pitchDeg)*ji;if(t.headingDeg!==void 0?this.camera.rotation.set(i,-(t.headingDeg+this.lookYawDeg+this.gaitOffset.yawDeg)*ji,e,"YXZ"):this.camera.rotation.set(i,this.camera.rotation.y,e,"YXZ"),t.elevationM!==this.observerElevationM&&(this.observerElevationM=t.elevationM,this.syncCloudLayer(),Math.abs(tg(t.elevationM)-this.groundRadius)>1&&(this.buildGround(),this.celestialGroup.scale.setScalar(this.groundRadius/ko),this.camera.far=Math.max(ml*1.2,this.groundRadius*2.5),this.camera.updateProjectionMatrix())),this.terrainMesh&&this.terrainOrigin&&t.lat!==void 0&&t.lng!==void 0){const n=je(this.terrainOrigin.lat,this.terrainOrigin.lng,t.lat,t.lng);this.terrainMesh.position.x=n.x,this.terrainMesh.position.z=n.z}this.poseCameraY=this.groundYUnder(0,0)+1.6+t.elevationM,this.camera.position.y=this.poseCameraY,this.celestialGroup.position.y=this.camera.position.y,this.camera.fov!==t.fovDeg&&(this.camera.fov=t.fovDeg,this.camera.updateProjectionMatrix(),this.updateCompassScale())}setTerrainProviders(t){this.stopTerrainFade(),this.terrainProviders=t,this.disposeMesh(this.terrainMesh),this.terrainMesh=void 0,this.terrainOrigin=void 0,this.terrainAttribution=void 0,this.roadSystem.clear(),this.roadAttribution=void 0,this.roadWays=void 0,this.applyGroundDepthWrite(),this.terrainBuildToken++}setTerrainOrigin(t,e,i){if(t===void 0||e===void 0)return;const n=this.groundRadius;if(this.terrainOrigin&&Math.abs(this.terrainRadius-n)<n*.1){const{x:c,z:l}=je(t,e,this.terrainOrigin.lat,this.terrainOrigin.lng);if(Math.sqrt(c*c+l*l)<NE*(n/ko))return}const s=this.terrainOrigin,r=this.terrainRadius;(!s||s.lat!==t||s.lng!==e)&&(this.roadSystem.clear(),this.roadAttribution=void 0),this.terrainOrigin={lat:t,lng:e},this.terrainRadius=n;const o=++this.terrainBuildToken;this.awaitArrival(A5(t,e,this.terrainProviders,n),me.TERRAIN_PATIENCE_MS).then(({mesh:c,attribution:l,originElevationM:h})=>{if(o!==this.terrainBuildToken)return;this.setSiteElevation(h??0);const u=this.terrainMesh,d=s?je(t,e,s.lat,s.lng):void 0;u&&d&&Math.hypot(d.x,d.z)<=r&&(c.position.y=u.position.y+this.groundYOfPatch(u,d.x,d.z)),u&&d&&Math.hypot(d.x,d.z)<=r?this.crossfadeTerrain(c,u):this.disposeMesh(this.terrainMesh),c.renderOrder=OE,this.terrainMesh=c,this.compileNextFrameOffThread(),this.terrainAttribution=l,this.scene.add(c),this.applyGroundDepthWrite(),this.decorCurrentPose&&(this.setObserverPose(this.decorCurrentPose),this.updateDecorAnchoring(this.decorReferencePose,this.decorCurrentPose,this.decorTime)),this.buildRoads(t,e,n),this.drapeStatedRoads(),this.drapeTraces(),this.render(),i?.()}).catch(c=>{console.warn("Terrain build failed, keeping the flat ground fallback:",c),i?.()})}static TERRAIN_CROSSFADE_MS=1200;fadingTerrain;crossfadeTerrain(t,e){this.stopTerrainFade();const i=t.material;i.opacity=0,i.polygonOffset=!0,i.polygonOffsetFactor=-1,i.polygonOffsetUnits=-4;const n=performance.now(),s=()=>{const r=Math.min(1,(performance.now()-n)/me.TERRAIN_CROSSFADE_MS);if(i.opacity=r*r*(3-2*r),this.render(),r<1&&this.fadingTerrain){this.fadingTerrain.frameId=requestAnimationFrame(s);return}i.polygonOffset=!1,i.opacity=1,this.fadingTerrain&&this.disposeMesh(this.fadingTerrain.mesh),this.fadingTerrain=void 0,this.render()};this.fadingTerrain={mesh:e,frameId:requestAnimationFrame(s)}}stopTerrainFade(){if(!this.fadingTerrain)return;cancelAnimationFrame(this.fadingTerrain.frameId),this.disposeMesh(this.fadingTerrain.mesh),this.fadingTerrain=void 0;const t=this.terrainMesh?.material;t&&(t.opacity=1,t.polygonOffset=!1)}static ROADS_MAX_RADIUS_M=5e3;buildRoads(t,e,i){const n=this.terrainProviders.roads;if(!n||i>me.ROADS_MAX_RADIUS_M){this.roadSystem.clear(),this.roadAttribution=void 0;return}const s=this.roadWays;if(s&&s.lat===t&&s.lng===e&&s.radiusM===i){this.drapeRoads(s.ways,t,e,n.contemporary);return}this.awaitArrival(n.getRoads(lv(t,e,i)),me.ROADS_PATIENCE_MS).then(r=>{this.terrainOrigin?.lat!==t||this.terrainOrigin?.lng!==e||(this.roadWays={lat:t,lng:e,radiusM:i,ways:r},this.drapeRoads(r,t,e,n.contemporary))}).catch(r=>{console.warn("Roads unavailable, drawing none:",r)})}setStatedRoads(t){t!==this.statedRoads&&(this.statedRoads=t,this.drapeStatedRoads(),this.render())}drapeStatedRoads(){const t=this.terrainMesh;t&&(this.roadSystem.group.position.copy(t.position),this.roadSystem.setStated(this.statedRoads,(e,i)=>this.groundYOfPatch(t,e,i)))}setTraces(t,e=new Map){t===this.traces&&e===this.traceLabels||(this.traces=t,this.traceLabels=e,!(t.length===0&&!this.traceSystem)&&this.loadTraceSystem().then(()=>{this.drapeTraces(),this.render()}))}setTracesShown(t){t!==this.tracesShown&&(this.tracesShown=t,this.drapeTraces(),this.render())}loadTraceSystem(){return this.traceSystemLoading??=$i(async()=>{const{TraceSystem:t}=await import("./TraceSystem-DEXV4-2W.js");return{TraceSystem:t}},[],import.meta.url).then(({TraceSystem:t})=>{const e=new t(Du);this.scene.add(e.group),this.traceSystem=e})}drapeTraces(){const t=this.traceSystem,e=this.terrainMesh,i=this.terrainOrigin;!t||!e||!i||(t.group.position.copy(e.position),t.set(this.tracesShown?this.traces:[],this.traceLabels,i.lat,i.lng,this.siteElevationM,(n,s)=>this.groundYOfPatch(e,n,s)))}drapeRoads(t,e,i,n){const s=this.terrainMesh;s&&(this.roadSystem.group.position.copy(s.position),this.roadSystem.set(t,e,i,(r,o)=>this.groundYOfPatch(s,r,o),n),this.roadAttribution=t.length>0?this.terrainProviders.roads?.attribution:void 0,this.compileNextFrameOffThread(),this.render())}setShowCompass(t){this.showCompass!==t&&(this.showCompass=t,this.disposeCompassLabels(),t&&this.buildCompassLabels(),this.render())}setCompassPoints(t){this.compassPoints!==t&&(this.compassPoints=t,this.showCompass&&(this.disposeCompassLabels(),this.buildCompassLabels(),this.render()))}compassPoints;applyLensFlareTint(t){if(!this.lensFlare)return;const e=FE*(this.sunArriving[1]/kE);this.lensFlare.uniforms.uColorGain.value.setRGB(e*t[0],e*t[1],e*t[2]),this.applyDazzleStrength()}applyDazzleStrength(){if(!this.lensFlare)return;const[t,e,i]=this.sunArriving,n=Math.max(e,1e-30);this.lensFlare.uniforms.uDazzleColour.value.setRGB(t/n,1,i/n),this.lensFlare.uniforms.uVeilStrength.value=Ni.K*e*this.sunUnhiddenFraction}sunArriving=[0,0,0];setCompassHovered(t){this.compassHovered!==t&&(this.compassHovered=t,this.updateCompassVisibility())}setCompassForced(t){this.compassForced!==t&&(this.compassForced=t,this.updateCompassVisibility())}updateCompassVisibility(){const t=this.compassHovered||this.compassForced;if(this.compassSprites.some(e=>e.visible!==t)){for(const e of this.compassSprites)e.visible=t;this.developingExposure?this.exposureInstantsDone>0&&this.presentExposure():this.render()}}setWeather(t){if(ME(this.weather,t))return;this.cloudTransmissionMemo.clear();const e=this.weather;this.weather=t;const i=!$E(e,t),n=e.precipitationType!==t.precipitationType,s=e.precipitationIntensity!==t.precipitationIntensity||e.precipitationAmount!==t.precipitationAmount;(e.relativeHumidity!==t.relativeHumidity||n||s)&&(this.air=In.of(t),this.applyAir(),this.scatteredSky?.setConditions({aerosolOpticalDepth:t.relativeHumidity===void 0?void 0:ur.steppedOpticalDepth(t.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=t.storm&&t.cloudDarkness>=tA,this.syncAnimationLoop(),this.render()}setDecor(t){if(this.decorObjects!==t){this.decorObjects=t,this.decorModelToken++,this.decorModelCredits.clear(),this.pendingTrafficModels.clear();for(const e of this.decorGroups.values())e.removeFromParent(),oi.dispose(e);this.decorGroups.clear(),this.streetlightLights.clear();for(const e of t){const i=oi.build(e,e.lit??!1);this.scene.add(i),this.decorGroups.set(e.id,i),e.kind==="streetlight"&&this.addStreetlightLight(e.id,i),e.model&&e.id.startsWith(Cn.ID_PREFIX)?(this.pendingTrafficModels.set(e.id,e),this.awaitArrival(this.loadDecorModel(e,this.decorModelToken,!0))):this.reuseLoadedDecorModel(e,i)||this.awaitArrival(this.loadDecorModel(e,this.decorModelToken))}this.celestialLight.castShadow=this.decorGroups.size>0||this.bodySystem.any}}setDecorSunlight(t){this.decorSunlight=t}setContrails(t){t!==this.contrails&&(this.contrails=t,!(t.length===0&&!this.contrailSystem)&&this.loadContrailSystem().then(()=>{this.contrailSystem?.set(this.contrails),this.updateContrails(),this.render()}))}setContrailSunlight(t){this.contrailSunlight=t}loadContrailSystem(){return this.contrailSystemLoading??=$i(async()=>{const{ContrailSystem:t}=await import("./ContrailSystem-CQsI1Z1v.js");return{ContrailSystem:t}},__vite__mapDeps([0,1]),import.meta.url).then(({ContrailSystem:t})=>{const e=new t;this.scene.add(e.group),this.contrailSystem=e})}contrailTint(t){const e=this.contrailSunlight.get(t),i=this.lastAstronomy?.sun,n=me.CONTRAIL_SCATTERING,s=this.skyLight.color,r=[s.r*n*.5,s.g*n*.5,s.b*n*.5];if(e&&i){const o=vn.litFraction(e.sunElevationDeg,e.heightM);if(o>0){const c=this.air.transmittanceFromSpace(e.heightM,e.sunElevationDeg),l=he.illuminanceOf(i.magnitude)*this.relativeScale;for(let h=0;h<3;h++)r[h]+=n*l*c[h]*o}}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()},t=>this.contrailTint(t))}contrailPixelRad(){const t=Math.max(1,this.renderer.getDrawingBufferSize(this.bloomSize).y);return Math.max(this.lampBloomRadiusRad()??0,this.camera.fov*Math.PI/180/t)}setDecorPresence(t){this.decorPresence=t}setDecorModelProvider(t){this.decorModelProvider=t;const e=this.decorObjects;this.decorObjects=[],this.setDecor(e)}get currentDecorModelCredits(){return[...this.decorModelCredits.values(),...this.bodySystem.modelCredits]}get bodyGround(){const{x:t,z:e}=this.bodyOrigin,i=this.groundYUnder(t,e);return{heightAt:(n,s)=>this.groundYUnder(t+n,e-s)-i}}setBodies(t,e=0,i=t.map(r=>r.id),n=[],s){const{x:r,z:o}=this.bodyOrigin,c=this.scatteredSky;this.bodySystem.set(t,{originX:r,originZ:o,originGroundY:this.groundYUnder(r,o),eye:this.camera.position,groundYAt:(h,u)=>this.groundYUnder(h,u),wind:s,light:this.plumeLight(),occluders:[...this.decorGroups.values()],transmittance:(h,u,d)=>this.transmittanceTo(h,u,d)},e,c?(h,u)=>c.relativeOfLuminance(h,u):void 0,i),this.bodySystem.setSmoke(n,e),this.bodySystem.any&&(this.celestialLight.castShadow=!0),this.fitShadowToBodies();const l=this.bodySystem.furthestFrom(this.camera.position)*1.2;l>this.camera.far&&(this.camera.far=l,this.camera.updateProjectionMatrix())}plumeLight(){const t=this.celestialLight.color,e=this.celestialLight.intensity*.5,i=this.skyLight.color,n=this.skyLight.groundColor,s=this.skyLight.intensity,r=(o,c,l)=>(o*e+(c+l)/2*s)/Math.PI;return[r(t.r,i.r,n.r),r(t.g,i.g,n.g),r(t.b,i.b,n.b)]}bodyOutline(t,e){return this.bodySystem.outlineOf(t,e)}documentUrl;modelUrl(t){return t.url?this.documentRelative(t.url):void 0}documentRelative(t){if(t.startsWith("data:"))return t;const e=this.documentUrl??(typeof location>"u"?void 0:location.href);return e?new URL(t,e).href:t}async loadBodyModel(t){const e=t.url?void 0:t.id?await this.decorModelProvider.entry(t.id):void 0,i=this.modelUrl(t)??e?.url,n=t.credit??e?.credit;if(!(!i||!n))return{scene:await Tu(i),credit:n,headingOffsetDeg:t.headingOffsetDeg??e?.headingOffsetDeg}}loadedDecorModels=new Map;reuseLoadedDecorModel(t,e){const i=this.loadedDecorModels.get(t.id);return!i||i.ref!==JSON.stringify(Zu(t))||!oi.usesModel(t)?!1:(this.applyLoadedDecorModel(t,e,i),!0)}applyLoadedDecorModel(t,e,i){const n=i.scene.clone(!0);n.traverse(s=>{s instanceof bt&&(s.userData.sharedModel=!0)}),oi.applyModel(e,t,n,{headingOffsetDeg:i.headingOffsetDeg,depictedSizeM:i.depictedSizeM}),this.decorModelCredits.set(t.id,i.credit)}standInScenes=new Map;async loadDecorModel(t,e,i=!1){const n=i?Og[t.kind]:Zu(t);if(!(!n||!oi.usesModel(t)))try{const s=n.url?void 0:n.id?await this.decorModelProvider.entry(n.id):void 0,r=this.modelUrl(n)??s?.url,o=n.credit??s?.credit;if(!r||!o)return;const c=i?await this.standInScene(r):await Tu(r);if(e!==this.decorModelToken||i&&!this.pendingTrafficModels.has(t.id))return;const l=this.decorGroups.get(t.id);if(!l)return;i||sn.reflectOn(c);const h={ref:JSON.stringify(n),scene:c,headingOffsetDeg:n.headingOffsetDeg??s?.headingOffsetDeg,depictedSizeM:s?.sizeM,credit:o};i||this.loadedDecorModels.set(t.id,h),this.applyLoadedDecorModel(t,l,h),this.render()}catch(s){console.warn(`Keeping the built-in shape for decor "${t.id}":`,s)}}standInScene(t){let e=this.standInScenes.get(t);return e||(e=Tu(t).then(i=>(sn.reflectOn(i),i)),this.standInScenes.set(t,e)),e}updateDecorAnchoring(t,e,i=0){this.decorReferencePose=t,this.decorCurrentPose=e,this.decorTime=i;const n=t?.lat!==void 0&&t.lng!==void 0&&e?.lat!==void 0&&e?.lng!==void 0?je(t.lat,t.lng,e.lat,e.lng):{x:0,z:0},s=this.decorObjects.find(l=>l.observerSide!==void 0&&Lg(l.kind));if(this.terrainMesh&&this.terrainOrigin&&e?.lat!==void 0&&e.lng!==void 0){const l=je(this.terrainOrigin.lat,this.terrainOrigin.lng,e.lat,e.lng);this.terrainMesh.position.x=l.x-(s?0:this.gaitOffset.eastM),this.terrainMesh.position.z=l.z+(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 o=0;if(s){const l=oi.occupantView(s),h=-(s.headingDeg??0)*ji,u=l.x*Math.cos(h)+l.z*Math.sin(h),d=-l.x*Math.sin(h)+l.z*Math.cos(h),f=s.eastM+n.x,p=-s.northM+n.z;r.x=-(f+u),r.z=-(p+d),this.camera.position.y=this.groundYUnder(f,p)+l.eyeY,this.camera.rotation.set(this.indoorLookPitchDeg*ji,-(l.headingDeg+this.indoorLookYawDeg)*ji,0,"YXZ")}this.bodyOrigin={x:n.x+r.x,z:n.z+r.z},this.placeShadowFrustum();for(const l of this.decorObjects){const h=this.decorGroups.get(l.id);if(!h)continue;const u=Zo(l,i),d=u.eastM+n.x+r.x,f=-u.northM+n.z+r.z,p=this.terrainMesh,v=`${p?.geometry.uuid}:${(d-(p?.position.x??0)).toFixed(3)}:${(f-(p?.position.z??0)).toFixed(3)}:${(p?.position.y??0).toFixed(3)}:${u.headingDeg}:${u.altitudeM}`;if(h.userData.footprintKey!==v&&(h.userData.footprintGroundY=this.groundUnderFootprint(l,d,f,u.headingDeg,u.altitudeM),h.userData.footprintKey=v),h.position.set(d,h.userData.footprintGroundY+u.altitudeM,f),l.kind==="crop"){const x=Math.hypot(d,f);h.visible=x<=BE}const m=this.decorPresence.get(l.id),g=m!==void 0&&(i<m.fromMs||i>m.untilMs);m&&(h.visible=!g);const S=this.decorSunlight.get(l.id);if(S&&!g&&this.lightFromAbove(h,S),u.headingDeg!==void 0&&(h.rotation.y=-u.headingDeg*ji),l.kind==="crop"&&h.visible){const x=this.terrainMesh,M=[x?.geometry.uuid,d-(x?.position.x??0),f-(x?.position.z??0),h.position.y-(x?.position.y??0),u.headingDeg,u.altitudeM].map(b=>typeof b=="number"?b.toFixed(4):b).join(":");h.userData.cropGroundKey!==M&&(oi.fitCropToGround(h,(b,w)=>this.groundYUnder(b,w)+u.altitudeM),h.userData.cropGroundKey=M)}if(!g){const x=h.position.distanceTo(this.camera.position);o=Math.max(o,x),x<me.trafficModelRangeM(l)&&this.pendingTrafficModels.delete(l.id)&&this.loadDecorModel(l,this.decorModelToken)}}this.updateContrails();const c=Math.max(ml*1.2,this.groundRadius*2.5,o*1.2);Math.abs(this.camera.far-c)>1&&(this.camera.far=c,this.camera.updateProjectionMatrix())}groundYUnder(t,e){const i=this.terrainMesh;return i?i.position.y+this.groundYOfPatch(i,t-i.position.x,e-i.position.z):zu}groundYOfPatch(t,e,i){const n=t.geometry.getAttribute("position"),s=Math.round(Math.sqrt(n.count));if(s<2||s*s!==n.count)return zu;const r=n.getX(0),o=n.getX(s-1),c=n.getZ(0),l=n.getZ((s-1)*s),h=Na((e-r)/(o-r)*(s-1),0,s-1),u=Na((i-c)/(l-c)*(s-1),0,s-1);if(!Number.isFinite(h)||!Number.isFinite(u))return zu;const d=Math.min(Math.floor(h),s-2),f=Math.min(Math.floor(u),s-2),p=h-d,v=u-f,m=(b,w)=>n.getY(b*s+w),g=m(f,d),S=m(f,d+1),x=m(f+1,d),M=m(f+1,d+1);return p+v<=1?g+(S-g)*p+(x-g)*v:M+(x-M)*(1-p)+(S-M)*(1-v)}groundUnderFootprint(t,e,i,n,s=0){return oi.groundUnderFootprint(t,e,i,n,(r,o)=>this.groundYUnder(r,o),s)}lookYawDeg=0;lookPitchDeg=0;poseCameraY=1.6;setGait(t){this.gaitOffset=t}gaitOffset={eastM:0,northM:0,upM:0,rollDeg:0,pitchDeg:0,yawDeg:0};setLookOffset(t,e){this.lookYawDeg=t,this.lookPitchDeg=e}indoorLookYawDeg=0;indoorLookPitchDeg=0;setIndoorLook(t,e){this.indoorLookYawDeg=t,this.indoorLookPitchDeg=e}medium;setMedium(t,e,i,n){const s=t&&e!==void 0&&e>0&&i!==void 0&&i>0?{kind:t.kind,iso:n??t.iso,autoExposure:t.autoExposure===!0,exposureSeconds:e,fNumber:i}:void 0;JSON.stringify(s)!==JSON.stringify(this.medium)&&(this.medium=s,this.render())}applyMedium(){const t=this.medium,e=Math.max(this.relativeScale,1e-30);if(!t){Yi.uMedium.value=0;return}Yi.uMedium.value=t.kind==="negative"?1:t.kind==="slide"?2:3;const i=t.autoExposure?this.scatteredSky?.sceneAdaptation:void 0;Yi.uMediumExposure.value=i!==void 0&&i>0?1/(e*i):.065*t.exposureSeconds*t.iso/(t.fNumber*t.fNumber*e)}grain;lampBloomRadiusRad(){if(!this.grain)return;const t=this.camera.fov*Math.PI/180,e=this.grain.frameHeightMm/(2*Math.tan(t/2)),i=Math.max(1,this.renderer.getDrawingBufferSize(this.bloomSize).y);return Math.max(this.grain.detailUm*.001/e,t/i)}bloomSize=new Mt;lampTransmittance(t){const e=this.siteElevationM+this.camera.position.y,i=this.siteElevationM+t.position.y;return this.air.transmittance(e,i,t.position.distanceTo(this.camera.position))}updateDecorLitState(t,e=0){const i=this.lampBloomRadiusRad();for(const n of this.decorObjects){const s=this.decorGroups.get(n.id);if(s&&n.lights?.length&&oi.setLights(s,n.lights,t,s.position.distanceTo(this.camera.position),e,this.relativeScale,i,this.lampTransmittance(s)),n.kind!=="streetlight"&&n.kind!=="vehicle")continue;const r=this.decorGroups.get(n.id);if(!r)continue;const o=Nv(n,t);oi.setLit(r,n.kind,o,this.relativeScale);const c=this.streetlightLights.get(n.id);c&&(c.visible=o)}}addStreetlightLight(t,e){const i=oi.bodyOf(e),n=i.children.find(r=>r.userData.emissive);if(!n)return;const s=new I1(16764006,ig*this.relativeScale,DE);s.position.copy(n.position).multiply(i.scale),s.castShadow=!0,s.shadow.mapSize.set(512,512),s.shadow.bias=-.002,e.add(s),this.streetlightLights.set(t,s)}setAstronomy(t){(!this.lastAstronomy||Math.abs(this.lastAstronomy.sun.altitudeDeg-t.sun.altitudeDeg)>2)&&(this.surroundings=void 0,this.scatteredSky?.resetSurroundings()),this.lastAstronomy=t,this.scatteredSky?.update(this.scatteredSkyState(t)),this.skyHoldUntilMs===void 0&&this.startHold(),this.pumpScatteredSky(),this.lastSunPosition=t.sun,this.buildSky(t.sun),this.buildGround();const e=this.magnitudeLimitOf(t);this.buildStars(t.stars,e),this.placeBodies(t,e),this.buildIceHalos(t.sun,t.moon),this.buildRainbow(t.sun,t.moon),this.applySkyColours(t),this.syncAnimationLoop(),this.render()}static relativeSkyOf(t,e){const i=r=>{const o=$n.luminanceOf(r);if(!(o>0))return[0,0,0];const c=Et.relativeOfResponse(o)/o;return[r[0]*c,r[1]*c,r[2]*c]},n=i(t.zenith),s=i(t.horizon);return{zenith:n,horizon:s,airlight:s,skyIrradiance:[n[0]*Math.PI,n[1]*Math.PI,n[2]*Math.PI],scale:e}}placeBodies(t,e){this.bodiesScale=this.relativeScale,this.setBodyMesh("sun",t.sun,Do,new st(1,.96,.88),t.sun.magnitude),this.setMoonMesh(t.moon,e),this.buildPlanets(t.planets,e),this.buildComet(t.comet,e),this.buildNovae(t.novae??[],e)}bodiesScale=0;applySkyColours(t){this.skyColoursStale=!1,this.bodiesScale!==this.relativeScale&&(this.placeBodies(t,this.magnitudeLimitOf(t)),this.applyDazzleStrength(),this.buildIceHalos(t.sun,t.moon),this.buildRainbow(t.sun,t.moon));const e=this.scatteredSky?.ambient??me.relativeSkyOf(Qd(t.sun.altitudeDeg),this.relativeScale),i=e,n=this.lightUnderClouds(t),s=r=>n?[0,1,2].map(o=>r[o]*n.through+n.radiance[o]*(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(t,e),this.updateCloudLighting(t.sun,this.baseFogColor),Dt.setEye(this.scatteredSky?.rodShare??0,this.relativeScale),this.updateTwinkle(this.twinkleSeconds);for(const r of this.streetlightLights.values())r.intensity=ig*this.relativeScale;this.buildSkyGlow(t,i.zenith),this.applyAir(),this.buildLunarDiffraction(t.moon)}reflections;sceneVersion=0;reflectionTimer;buildLunarDiffraction(t){const e=this.scatteredSky?.ready?this.scatteredSky:void 0;if(t.altitudeDeg<-.5||!e){this.lunarDiffraction?.show(void 0),this.lunarDiffractionKey="";return}const i=this.weather.relativeHumidity,n=(i===void 0?Ut.DEFAULT_AEROSOL_OPTICAL_DEPTH:ur.opticalDepth(i))*Ut.aerosolDensity(this.siteElevationM+this.observerElevationM),s=this.cloudTransmission(t),r=-Math.log(Math.max(this.cloudTransmission(t,!0),1e-4)),o=he.aureoleScale(n,he.airMass(t.altitudeDeg))*s,c=he.coronaScale(r),l=he.illuminanceOf(t.magnitude),h=[t.altitudeDeg.toFixed(1),t.azimuthDeg.toFixed(1),t.magnitude.toFixed(2),o.toExponential(2),c.toExponential(2),Math.log10(Math.max(e.adaptation,1e-12)).toFixed(2)].join(":");if(h===this.lunarDiffractionKey)return;this.lunarDiffractionKey=h,this.lunarDiffraction||(this.lunarDiffraction=new ff,this.celestialGroup.add(this.lunarDiffraction.object));const u=he.profile(he.HAZE_COARSE_MODE),d=he.profile(he.CLOUD_DROPLETS),f=_m(t.altitudeDeg),p=new Float32Array(he.STEPS*3);let v=0;for(let x=0;x<he.STEPS;x++){const M=x*3,b=[0,1,2].map(T=>l*f[T]*(o*u[M+T]+c*d[M+T])),w=$n.shown(b,$n.luminanceOf(b),(T,y)=>e.relativeOfLuminance(T,y));p.set(w,M),v=Math.max(v,$n.response(w))}const{x:m,y:g,z:S}=Ze(t.altitudeDeg,t.azimuthDeg,1);this.lunarDiffraction.show(v>1/200?{x:m,y:g,z:S}:void 0,p)}applyAir(){this.scene.fog instanceof Vr||(this.scene.fog=new Vr),this.scene.fog.setAir(this.air,this.siteElevationM,this.airlight)}airlight=[0,0,0];transmittanceTo(t,e,i){const n=this.camera.position;return this.air.transmittance(this.siteElevationM+n.y,this.siteElevationM+e,Math.hypot(t-n.x,e-n.y,i-n.z))}setSiteElevation(t){Math.abs(t-this.siteElevationM)<1||(this.siteElevationM=t,this.applyAir(),this.lastAstronomy&&this.scatteredSky?.update(this.scatteredSkyState(this.lastAstronomy)))}scatteredSkyState(t){return{altitudeM:this.siteElevationM+this.observerElevationM+1.6,lightPollution:this.lightPollution,sun:{altitudeDeg:t.sun.altitudeDeg,azimuthDeg:t.sun.azimuthDeg,magnitude:t.sun.magnitude},moon:{altitudeDeg:t.moon.altitudeDeg,azimuthDeg:t.moon.azimuthDeg,magnitude:t.moon.magnitude,phaseAngleDeg:xt.phaseAngleOf(t.moon.phase.illuminatedFraction)}}}pumpScatteredSky(){const t=this.scatteredSky;!t||t.tables.ready||this.scatteredSkyFrameId!==null||this.contextReleased||this.suspended||(this.scatteredSkyFrameId=requestAnimationFrame(()=>{this.scatteredSkyFrameId=null,!this.contextReleased&&(t.advance(this.skyHoldUntilMs?PE:CE),this.pumpScatteredSky())}))}cancelScatteredSkyPump(){this.scatteredSkyFrameId!==null&&(cancelAnimationFrame(this.scatteredSkyFrameId),this.scatteredSkyFrameId=null)}setSatellites(t){if(t.length===0&&!this.satelliteField?.count)return;this.satelliteField||(this.satelliteField=new V5(Cu),this.celestialGroup.add(this.satelliteField.object));const e=this.lastAstronomy?this.magnitudeLimitOf(this.lastAstronomy):Ll(-90,this.instrumentMagnitudeGain);this.satelliteField.set(t,e,i=>this.cloudTransmission(i),(i,n)=>this.arrivingIlluminance(i,n,1)),this.render()}setReentries(t){if(t.length===0&&!this.reentrySystem?.count)return;this.reentrySystem||(this.reentrySystem=new Qi,this.celestialGroup.add(this.reentrySystem.object));const e=this.lastAstronomy?this.magnitudeLimitOf(this.lastAstronomy):Ll(-90,this.instrumentMagnitudeGain);this.reentrySystem.set(t,e,i=>this.cloudTransmission(i),(i,n)=>this.arrivingIlluminance(i,n,1)),this.render()}get reentryCount(){return this.reentrySystem?.count??0}pickTrafficAt(t,e){this.aimAtScreenPoint(this.raycaster,t,e);const i=this.raycaster.ray.direction,n=Math.cos(Pu*this.camera.fov*Math.PI/180);let s,r=n;const o=new R;for(const[c,l]of this.decorGroups){if(!l.visible||!c.startsWith(Cn.ID_PREFIX))continue;o.copy(l.position).sub(this.camera.position).normalize();const h=o.dot(i);h>r&&(r=h,s=c)}return s&&!this.groundHides(t,e)?s:void 0}pickSatelliteAt(t,e){if(!this.satelliteField?.count)return;this.aimAtScreenPoint(this.raycaster,t,e);const i=Math.cos(Pu*this.camera.fov*Math.PI/180),n=this.satelliteField.nearest(this.raycaster.ray.direction,i);return n&&this.groundHides(t,e)?void 0:n}updateCelestialLight(t,e){const i=this.relativeScale,n=t.sun.altitudeDeg>=vl,s=!n&&t.moon.altitudeDeg>=vl,r=n?t.sun:t.moon,o=[0,0,0],c=Math.max(0,Math.sin(Math.max(r.altitudeDeg,0)*ji)),l=n||s?this.cloudTransmission(r):1,h=-Math.log(Math.max(l,1e-6)),u=Math.max(0,1/(1+.1125*h)-l),d=[0,0,0];if(n||s){const S=he.illuminanceOf(r.magnitude)*i,x=this.air.transmittanceFromSpace(this.siteElevationM+this.observerElevationM,r.altitudeDeg);for(let T=0;T<3;T++)o[T]=S*x[T]*l,d[T]=S*x[T]*u*c,this.cloudBeam[T]=S*x[T];const{x:M,y:b,z:w}=Ze(r.altitudeDeg,r.azimuthDeg,1);this.cloudBeamDirection.set(M,b,w)}else this.cloudBeam.fill(0);const f=this.surroundings;if(f)this.skyLight.color.setRGB(f.up[0]*i,f.up[1]*i,f.up[2]*i),this.skyLight.groundColor.setRGB(f.down[0]*i,f.down[1]*i,f.down[2]*i);else{const S=this.skyCloudTransmission(),x=e.skyIrradiance,M=[0,1,2].map(w=>x[w]*S+d[w]);this.skyLight.color.setRGB(M[0],M[1],M[2]);const b=Yt.GROUND_ALBEDO;this.skyLight.groundColor.setRGB(b*(M[0]+o[0]*c),b*(M[1]+o[1]*c),b*(M[2]+o[2]*c))}if(this.skyLight.intensity=1,this.sceneSunBeam=n?[o[0],o[1],o[2]]:[0,0,0],!n&&!s){this.celestialLight.intensity=0;return}const{x:p,y:v,z:m}=Ze(r.altitudeDeg,r.azimuthDeg,1);this.lightDirection.set(p,v,m),this.placeShadowFrustum();const g=Math.max(o[0],o[1],o[2],1e-30);this.celestialLight.color.setRGB(o[0]/g,o[1]/g,o[2]/g),this.celestialLight.intensity=g,this.celestialLight.castShadow=this.decorGroups.size>0||this.bodySystem.any}static MEAN_COSINE=.5;static ABOVE_CLOUD_M=8e3;lightFromAbove(t,e){const i=this.lastAstronomy?.sun,n=[0,0,0];if(i){const s=vn.litFraction(e.sunElevationDeg,e.heightM);if(s>0){const r=this.air.transmittanceFromSpace(e.heightM,e.sunElevationDeg),o=he.illuminanceOf(i.magnitude)*this.relativeScale,c=e.heightM>=me.ABOVE_CLOUD_M?1:this.cloudTransmission(i);for(let l=0;l<3;l++)n[l]=Math.max(0,o*r[l]*s*c-this.sceneSunBeam[l])}}t.traverse(s=>{const r=s.material;if(!(r instanceof qr||r instanceof ar)||s.userData.emissive)return;r.map&&!r.emissiveMap&&(r.emissiveMap=r.map,r.needsUpdate=!0);const o=me.MEAN_COSINE/Math.PI;r.emissive.setRGB(r.color.r*n[0]*o,r.color.g*n[1]*o,r.color.b*n[2]*o)})}lightDirection=new R(0,1,0);placeShadowFrustum(){const t=this.lightDirection,e=this.celestialLight.shadow.camera,i=(e.right-e.left)/this.celestialLight.shadow.mapSize.x,n=this.shadowAxisX.crossVectors(this.shadowUp,t);n.lengthSq()<1e-8&&n.set(1,0,0),n.normalize();const s=this.shadowAxisY.crossVectors(t,n).normalize(),r=this.shadowWorld.set(this.bodyOrigin.x,0,this.bodyOrigin.z),o=l=>{const h=r.dot(l)/i;return(h-Math.round(h))*i},c=this.celestialLightTarget.position.set(0,0,0).addScaledVector(n,o(n)).addScaledVector(s,o(s));this.celestialLightTarget.updateMatrixWorld(),this.celestialLight.position.copy(c).addScaledVector(t,this.shadowLightDistanceM)}fitShadowToBodies(){const t=this.bodySystem.reachFrom(this.camera.position),e=Math.min(_E,Math.max(js,Math.ceil(t*1.25/20)*20));if(e===this.shadowHalfExtentM)return;this.shadowHalfExtentM=e;const i=this.celestialLight.shadow,n=i.camera;n.left=-e,n.right=e,n.top=e,n.bottom=-e;const s=Math.max(Ro,e*(Ro/js));this.shadowLightDistanceM=Math.max(un,s+10),n.near=this.shadowLightDistanceM-s,n.far=this.shadowLightDistanceM+s,n.updateProjectionMatrix(),i.bias=-.03/(2*s);const r=e>2*js?2048:1024;i.mapSize.x!==r&&(i.mapSize.set(r,r),i.map?.dispose(),i.map=null),this.placeShadowFrustum()}shadowHalfExtentM=js;shadowLightDistanceM=un;shadowUp=new R(0,1,0);shadowAxisX=new R;shadowAxisY=new R;shadowWorld=new R;skyCloudTransmission(){let t=this.cloudTransmission({altitudeDeg:90,azimuthDeg:0}),e=1;for(const i of[20,45,70]){const n=i*ji,s=Math.sin(n)*Math.cos(n)*2;for(let r=0;r<360;r+=60)t+=s*this.cloudTransmission({altitudeDeg:i,azimuthDeg:r}),e+=s}return t/e}cloudBeam=[0,0,0];cloudBeamDirection=new R(0,1,0);get relativeScale(){return this.scatteredSky?.relativeScale??1/Et.semiSaturation(Et.DAYLIGHT_ANCHOR_CD_M2)}setMeteorShower(t,e,i){this.meteorSystem||(this.meteorSystem=new _i,this.celestialGroup.add(this.meteorSystem.object)),this.meteorSystem.setShower(t,e,i)}get meteorSchedule(){return this.meteorSystem?.schedule??[]}meteorMidpoint(t){return this.meteorSystem?.midpointOf(t)}updateMeteors(t){this.meteorSystem?.update(t)}setInstrument(t){this.projectionKind=t.projection,this.grain=t.detailUm!==void 0&&t.frame?{detailUm:t.detailUm,frameHeightMm:t.frame.heightMm}:void 0;const e=mi.starPointsOf(t),i=mi.flareArtifactsOf(t);e===this.starPoints&&i===this.lensFlareArtifactIntensity||(this.starPoints=e,this.lensFlareArtifactIntensity=i,this.lensFlare&&(this.lensFlare.uniforms.uStarPoints.value=e,this.lensFlare.uniforms.uFlareIntensity.value=i),this.render())}magnitudeLimitOf(t){const e=xt.starLossMagnitudes(t.sun.altitudeDeg,{phaseAngleDeg:xt.phaseAngleOf(t.moon.phase.illuminatedFraction),altitudeDeg:t.moon.altitudeDeg},this.lightPollution);return Ll(t.sun.altitudeDeg,this.instrumentMagnitudeGain,e)}setLightPollution(t){t!==this.lightPollution&&(this.lightPollution=t,this.lastAstronomy&&this.scatteredSky?.update(this.scatteredSkyState(this.lastAstronomy)))}setInstrumentGain(t,e=!1){this.instrumentMagnitudeGain=Number.isFinite(t)?t:0,this.scatteredSky?.setInstrument(e,this.instrumentMagnitudeGain)}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 t=this.compileOffThread().then(()=>{this.compiling===t&&(this.compiling=void 0,this.render())});this.compiling=t;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 t=this.renderer.compile(this.scene,this.camera);if(!this.renderer.extensions.get("KHR_parallel_shader_compile"))return Promise.resolve();const e=this.renderer.properties,i=performance.now()+me.COMPILE_WAIT_MS;return new Promise(n=>{const s=()=>{if(this.contextReleased)return n();for(const r of t){const o=e.get(r)?.currentProgram;(!o||o.isReady())&&t.delete(r)}t.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(t){if(this.animationsRunning){const e=this.lastFrameTimeMs===void 0?0:t-this.lastFrameTimeMs;this.lastFrameTimeMs=t,this.hasAnimations()&&this.animate(t,e);const i=this.resolution.ratioFor(t,e);i!==this.renderer.getPixelRatio()&&this.applyPixelRatio(i)}this.drawIfDirty()}refreshReflections(t=!1){this.reflections??=new sn(this.renderer);const e=[...this.compassSprites,...this.lensFlare?[this.lensFlare.mesh]:[],...[...this.glareSprites.values()].map(o=>o.mesh)],i=[...this.starTiers.map(o=>o.points),...[...this.bodyMeshes.values()].filter(o=>o instanceof mn),...[this.rainSystem?.points,this.precipitationPoints,this.rainSplashSystem?.points].filter(o=>o!==void 0)],n=this.relativeScale,s=this.sceneVersion,r=this.reflections.refresh(this.renderer,this.scene,this.camera.position,this.bodySystem.reflectors,e,[...this.decorGroups.values()],s,i,o=>this.measureSurroundings(o,n,s),t?0:sn.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(t,e,i){const n=this.lastAstronomy;if(!n)return;this.probeIrradiance??=new Xo;const s=[n.sun,n.moon].filter(r=>r.altitudeDeg>-2).map(r=>Ze(r.altitudeDeg,r.azimuthDeg,1));this.probeIrradiance.measure(this.renderer,t,s,r=>{const o=f=>f.map(p=>p/e),c=this.surroundings,l={up:o(r.up),down:o(r.down)},h=(f,p)=>f.some((v,m)=>Math.abs(v-p[m])>.03*Math.max(Math.abs(v),Math.abs(p[m]),1e-12)),u=!c||h(c.up,l.up)||h(c.down,l.down);u&&(this.surroundings=l),this.eyeSettledVersion=-1;const d=this.scatteredSky?.adaptToSurroundings(Math.exp(r.logAverage)/e)??!1;if(!u&&!d){this.eyeSettledVersion=i,this.skyHoldUntilMs&&this.redrawHeld();return}this.skyColoursStale=!0,this.render()})}lightUnderClouds(t){const e=this.surroundings;if(!e)return;const i=t.sun.altitudeDeg>=vl?t.sun:t.moon.altitudeDeg>=vl?t.moon:void 0;if(!i)return;const n=this.relativeScale/Math.PI;return{through:this.cloudTransmission(i),radiance:[e.up[0]*n,e.up[1]*n,e.up[2]*n]}}probeIrradiance;surroundings;animate(t,e){const i=Math.min(e/1e3,QE);this.twinkleSeconds=t/1e3,this.updateTwinkle(this.twinkleSeconds),this.updatePrecipitation(t/1e3,i),this.updateRain(i),this.lensFlare&&(this.lensFlare.uniforms.uTime.value=t/1e3),this.developingExposure||(this.frameDirty=!0)}setMaxPixelRatio(t){this.resolution.maximum=t,this.renderer.getPixelRatio()>this.resolution.maximum&&this.applyPixelRatio(this.resolution.maximum)}applyPixelRatio(t){this.renderer.setPixelRatio(t),this.renderer.setSize(this.cssSize.width,this.cssSize.height,!1),this.frameDirty=!0}setExposure(t,e){const i=e?Math.max(1,Math.round(t)):1;if(i===this.exposureInstants&&(i===1||e===this.exposureInstantAt)){this.exposureInstantAt=e;return}this.exposureInstants=i,this.exposureInstantAt=e,i===1&&(this.cancelExposure(),this.exposureAccumulation?.dispose(),this.exposureAccumulation=void 0),this.render()}renderOnce(t){if(this.onMapSubjectBounds){const r=this.mapSubjectBounds();t?this.exposureSubjectBounds.push(...r):this.onMapSubjectBounds(r)}const e=this.usableEquidistantPass();this.phenomena.setCloudLayers(this.layeredClouds?.volumes??[]),this.phenomena.place(this.camera,(r,o,c)=>this.directionAtScreenPoint(r,o,c),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()),Yi.uRodShare.value=this.scatteredSky?.rodShare??0,Yi.uRelativeScale.value=this.relativeScale,this.applyMedium();const n=this.references.any||this.phenomena.any||this.compassSprites.some(r=>r.visible);Yi.uHasOverlay.value=n?1:0;const s=n?r=>this.renderOverlayPasses(r):void 0;if(this.skyGlow?.setDestinationEncoded(!1),!e){this.updateLensFlarePosition();const r=this.usableDepthOfFieldPass();r?r.render(this.renderer,this.scene,this.camera,s,t):this.usableFinishPass().render(this.renderer,this.scene,this.camera,s,void 0,t);return}e.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(),t,this.pointLayerHost)}pointLayerHost={points:()=>{const t=[];return this.celestialGroup.traverse(e=>{(e instanceof mn&&e.userData.pointSource||e instanceof bt&&e.userData.skyRibbon)&&t.push(e)}),t},clouds:()=>[...this.layeredClouds?.meshes??[],...this.cloudMesh?[this.cloudMesh]:[],...this.cirrusMesh?[this.cirrusMesh]:[]],sky:this.celestialGroup};renderOverlayPasses(t=this.camera){this.renderReferencesPass(t),this.renderBodiesOverReferences(t),this.renderPhenomenaPass(t),this.renderHudPass(t)}renderHudPass(t){const e=this.traceSystem?.any&&this.tracesShown;if(!e&&!this.compassSprites.some(s=>s.visible))return;e&&this.traceSystem.setView(this.renderer.getDrawingBufferSize(this.traceResolution),t.fov);const i=this.renderer.autoClear,n=this.renderer.shadowMap.autoUpdate;this.renderer.autoClear=!1,this.renderer.shadowMap.autoUpdate=!1,t.layers.set(Du),this.renderer.render(this.scene,t),t.layers.set(0),this.renderer.autoClear=i,this.renderer.shadowMap.autoUpdate=n}renderBodiesOverReferences(t){if(!this.references.any||!this.bodySystem.any)return;const e=this.renderer.autoClear,i=this.renderer.shadowMap.autoUpdate;this.renderer.autoClear=!1,this.renderer.shadowMap.autoUpdate=!1,t.layers.set(xv),this.scene.overrideMaterial=this.bodyCutOutMaterial,this.renderer.render(this.scene,t),this.scene.overrideMaterial=null,t.layers.set(0),this.renderer.autoClear=e,this.renderer.shadowMap.autoUpdate=i}bodyCutOutMaterial=new _n({blending:dc,blendSrc:Oo,blendDst:Oo,blendSrcAlpha:Oo,blendDstAlpha:Oo,toneMapped:!1});renderReferencesPass(t){if(!this.references.any)return;const e=this.renderer.autoClear,i=this.renderer.shadowMap.autoUpdate;this.renderer.autoClear=!1,this.renderer.shadowMap.autoUpdate=!1,t.layers.set(Sv),this.renderer.render(this.scene,t),t.layers.set(0),this.renderer.autoClear=e,this.renderer.shadowMap.autoUpdate=i}setReferences(t,e){this.references.set(t.map(i=>{const n=this.documentRelative(i.src);return n===i.src?i:{...i,src:n}}),void 0,e)}referenceAspect(t){return this.references.aspectOf(t)}directionAt(t,e){return this.directionAtScreenPoint(t,e,new R)}referenceFailedToLoad(t){return this.references.failedToLoad(this.documentRelative(t))}setReferencesShown(t){this.references.setShown(t),this.render()}setReferenceView(t,e){this.references.setView(t,e),this.render()}renderPhenomenaPass(t){if(!this.phenomena.any)return;const e=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&&me.markDecorDepth(s,n.kind!=="crop")}t.layers.set(Ru),this.scene.overrideMaterial=this.decorDepthMaterial,this.renderer.render(this.scene,t),this.scene.overrideMaterial=null,t.layers.set(yv),this.renderer.render(this.scene,t),t.layers.set(0),this.renderer.autoClear=e,this.renderer.shadowMap.autoUpdate=i}decorDepthMaterial=new _n({colorWrite:!1});static markDecorDepth(t,e){t.traverse(i=>{if(!(i instanceof bt))return;const n=Array.isArray(i.material)?i.material[0]:i.material;e&&n.depthWrite!==!1&&n.blending!==Ai?i.layers.enable(Ru):i.layers.disable(Ru)})}startExposure(){this.cancelExposure(),this.exposureSubjectBounds=[];const t=this.renderer.getDrawingBufferSize(new Mt),e=Math.max(1,Math.round(t.x)),i=Math.max(1,Math.round(t.y));this.exposureAccumulation||(this.exposureAccumulation=new cw(e,i)),this.exposureAccumulation.resize(e,i),this.exposureAccumulation.open(this.renderer),this.exposureInstantsDone=0,this.exposureFrameId=requestAnimationFrame(()=>this.developExposure())}developExposure(){this.exposureFrameId=null;const t=this.exposureInstantAt,e=this.exposureAccumulation;if(!t||!e)return;const i=1/this.exposureInstants;this.resolution.beginDrawing();const n=performance.now()+me.EXPOSURE_BUDGET_MS,s=me.exposureInstantsPerFrame(e.instantTarget.scene.width*e.instantTarget.scene.height);let r=0;do{this.restateAt(t,this.exposureInstantsDone);const o=this.compassSprites.map(c=>c.visible);for(const c of this.compassSprites)c.visible=!1;try{this.renderOnce(e.instantTarget)}finally{this.compassSprites.forEach((c,l)=>{c.visible=o[l]})}e.add(this.renderer,i),this.exposureInstantsDone++,r++}while(this.exposureInstantsDone<this.exposureInstants&&performance.now()<n&&r<s);this.restateAt(t,0),this.presentExposure(),this.resolution.endDrawing(),this.exposureInstantsDone<this.exposureInstants&&(this.exposureFrameId=requestAnimationFrame(()=>this.developExposure()))}presentExposure(){if(Yi.uRodShare.value=this.scatteredSky?.rodShare??0,Yi.uHasOverlay.value=1,Yi.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 t=new ys,e=new Zn(-1,1,1,-1,0,2),i=Ml/(sg*Math.tan(rg*ji/2));for(const s of this.compassSprites){if(!s.visible)continue;const r=s.getWorldPosition(new R).sub(this.camera.position).normalize(),o=this.screenPointOf(r);if(!o)continue;const c=new go(s.material);c.position.set(o.ndcX,o.ndcY,-1),c.scale.set(i/this.camera.aspect,i,1),t.add(c)}const n=this.renderer.autoClear;this.renderer.autoClear=!1;try{this.renderer.render(t,e)}finally{this.renderer.autoClear=n}}onMapSubjectBounds;exposureSubjectBounds=[];static MAP_SUBJECT_NEAREST_M=8;mapSubjectBounds(){const t=[],e=new ki,i=new R,n=this.camera.getWorldDirection(new R),s=this.decorObjects.filter(o=>o.track?.length||o.kind==="aircraft"||o.kind==="vehicle").map(o=>this.decorGroups.get(o.id)),r=this.bodySystem.reflectors.map(o=>o.holder);for(const o of[...s,...r]){if(!o?.visible||(e.setFromObject(o),e.isEmpty())||e.distanceToPoint(this.camera.position)<me.MAP_SUBJECT_NEAREST_M)continue;let c=1/0,l=-1/0,h=1/0,u=-1/0;for(const d of[e.min.x,e.max.x])for(const f of[e.min.y,e.max.y])for(const p of[e.min.z,e.max.z]){if(i.set(d,f,p).sub(this.camera.position).normalize(),i.dot(n)<=0)continue;const v=this.screenPointOf(i);if(!v)continue;const m=(v.ndcX+1)/2,g=(1-v.ndcY)/2;c=Math.min(c,m),l=Math.max(l,m),h=Math.min(h,g),u=Math.max(u,g)}c=Math.max(c,0),l=Math.min(l,1),h=Math.max(h,0),u=Math.min(u,1),l>=c&&u>=h&&t.push({x:c,y:h,width:l-c,height:u-h})}return t}restateAt(t,e){this.restatingExposure=!0;try{t(e)}finally{this.restatingExposure=!1}}cancelExposure(){this.exposureFrameId!==null&&(cancelAnimationFrame(this.exposureFrameId),this.exposureFrameId=null)}setLensOptics(t){const e=this.lensOptics;this.lensOptics=t,(e===void 0!=(t===void 0)||e&&t&&(e.focalLengthMm!==t.focalLengthMm||e.fNumber!==t.fNumber||e.focusDistance!==t.focusDistance||e.frameHeightMm!==t.frameHeightMm))&&(t&&this.depthOfFieldPass&&this.depthOfFieldPass.setLens(t.focalLengthMm,t.fNumber,t.focusDistance,t.frameHeightMm),this.render())}usableDepthOfFieldPass(){const t=this.lensOptics;if(!t)return;const e=this.renderer.getDrawingBufferSize(new Mt),i=Math.max(1,Math.round(e.x)),n=Math.max(1,Math.round(e.y));return this.depthOfFieldPass||(this.depthOfFieldPass=new qo(i,n)),this.depthOfFieldPass.resize(i,n),this.depthOfFieldPass.setLens(t.focalLengthMm,t.fNumber,t.focusDistance,t.frameHeightMm),this.depthOfFieldPass}usableFinishPass(){const t=this.renderer.getDrawingBufferSize(new Mt);return this.finishPass?this.finishPass.resize(t.x,t.y):this.finishPass=new df(t.x,t.y),this.finishPass}usableEquidistantPass(){if(this.projectionKind!=="equidistant")return;const t=this.renderer.getDrawingBufferSize(new Mt);return this.equidistantPass?this.equidistantPass.resize(t.x,t.y):this.equidistantPass=new Be(t.x,t.y),this.equidistantPass}aimAtScreenPoint(t,e,i){const n=this.projectionKind==="equidistant"?this.equidistantPass:void 0;if(!n){t.setFromCamera(new Mt(e,i),this.camera);return}const s=n.directionFor(e,i,this.camera.fov);this.camera.updateMatrixWorld(),t.ray.origin.setFromMatrixPosition(this.camera.matrixWorld),t.ray.direction.set(s.x,s.y,s.z).applyQuaternion(this.camera.quaternion).normalize(),t.camera=this.camera}pickCloudAt(t,e){return this.layeredClouds?.pickInstance(this.cloudDirectionAt(t,e))}cloudDirectionAt(t,e){return this.directionAtScreenPoint(t,e,new R)}directionAtScreenPoint(t,e,i){return this.aimAtScreenPoint(this.ufoOcclusionRaycaster,t,e),i.copy(this.ufoOcclusionRaycaster.ray.direction)}screenPointOf(t){this.camera.updateMatrixWorld();const e=this.screenPointScratch.copy(t).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 Be.ndcFor(e,this.camera.fov,n);if(e.z>=0)return;const s=Math.tan(this.camera.fov/2*ji);return{ndcX:e.x/-e.z/(n*s),ndcY:e.y/-e.z/s}}screenPointScratch=new R;screenPointQuaternion=new on;screenPointSize=new Mt;updateLensFlarePosition(){const t=this.lensFlare;if(!t)return;if(!this.sunVisible){t.mesh.visible=!1;return}if(this.camera.updateMatrixWorld(),this.lensFlareScratch.copy(this.sunWorldPosition).applyMatrix4(this.camera.matrixWorldInverse),this.lensFlareScratch.z>0){t.mesh.visible=!1;return}const e=this.sunVisibleFraction();if(e<=0){t.mesh.visible=!1;return}t.mesh.visible=!0,this.sunUnhiddenFraction=e,this.applyDazzleStrength();const i=this.lensFlareScratch.copy(this.sunWorldPosition).project(this.camera);t.uniforms.uLensPosition.value.set(i.x,i.y);const n=this.renderer.domElement.width,s=this.renderer.domElement.height;t.uniforms.uResolution.value.set(n,s),t.uniforms.uTanHalfFov.value=Math.tan(this.camera.fov*Math.PI/360)}renderDazzleOnResample(){const t=this.lensFlare;if(!t||!this.sunVisible)return;const e=this.sunVisibleFraction();if(e<=0)return;this.sunUnhiddenFraction=e,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);t.uniforms.uLensPosition.value.set(i.ndcX,i.ndcY),t.uniforms.uResolution.value.set(n.x,n.y),t.uniforms.uEquidistant.value=1,t.uniforms.uHalfFovRad.value=this.camera.fov*Math.PI/360;const s=this.renderer.autoClear;this.renderer.autoClear=!1,t.mesh.visible=!0,t.mesh.layers.enable(jm),this.camera.layers.set(jm),this.renderer.render(this.scene,this.camera),this.camera.layers.set(0),t.mesh.visible=!1,t.uniforms.uEquidistant.value=0,this.renderer.autoClear=s}sunVisibleFraction(){this.raycastableDecor().length>0&&this.scene.updateMatrixWorld();let t=0;for(const e of og)this.isSunOccluded(e[0],e[1])||t++;return t/og.length}raycastableDecor(){const t=[];for(const e of this.decorObjects){if(e.kind==="crop")continue;const i=this.decorGroups.get(e.id);i&&t.push(i)}return t}isSunOccluded(t=0,e=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(),t!==0||e!==0){const o=Math.PI/180,c=this.sunOcclusionRightScratch.set(n.z,0,-n.x);c.lengthSq()<1e-9&&c.set(1,0,0),c.normalize();const l=this.sunOcclusionUpScratch.crossVectors(c,n).normalize();n.addScaledVector(c,t*o).addScaledVector(l,e*o).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(t,e,i,n=0){const s=this.groundMesh;if(s&&e.y<0){const m=(s.position.y-t.y)/e.y;if(m>n&&m<i){const g=t.x+e.x*m-s.position.x,S=t.z+e.z*m-s.position.z;if(Math.hypot(g,S)<=this.groundRadius)return!0}}const r=this.terrainMesh;if(!r)return!1;const o=r.geometry.getAttribute("position"),c=Math.round(Math.sqrt(o.count));if(c<2||c*c!==o.count)return!1;const l=[r.position.x+o.getX(0),r.position.x+o.getX(c-1)],h=[r.position.z+o.getZ(0),r.position.z+o.getZ((c-1)*c)],u=Math.min(Math.abs(l[1]-l[0]),Math.abs(h[1]-h[0]))/(c-1);if(!(u>0))return!1;let d=n,f=i;for(const[m,g,S]of[[t.x,e.x,l],[t.z,e.z,h]]){const x=Math.min(S[0],S[1]),M=Math.max(S[0],S[1]);if(Math.abs(g)<1e-12){if(m<x||m>M)return!1;continue}const b=(x-m)/g,w=(M-m)/g;d=Math.max(d,Math.min(b,w)),f=Math.min(f,Math.max(b,w))}if(!(f>d))return!1;const p=Math.hypot(e.x,e.z),v=Math.min(4096,Math.max(8,Math.ceil((f-d)*p/(u/2))));for(let m=0;m<=v;m++){const g=d+(f-d)*m/v,S=t.x+e.x*g,x=t.y+e.y*g,M=t.z+e.z*g;if(x<=this.groundYUnder(S,M))return!0}return!1}setPhenomena(t,e){this.phenomena.set(t,e)}decorDistancesAt(t,e,i){this.aimAtScreenPoint(this.ufoOcclusionRaycaster,t,e),this.ufoOcclusionRaycaster.near=Qm;let n,s;for(const r of this.decorObjects){if(r.kind==="crop")continue;const o=this.decorGroups.get(r.id);if(!o)continue;const c=this.ufoOcclusionRaycaster.intersectObject(o,!0)[0];c&&(r.occludesSourceIds?.includes(i)?n=n===void 0?c.distance:Math.max(n,c.distance):s=s===void 0?c.distance:Math.min(s,c.distance))}return{behindM:n,inFrontM:s}}pickBodyAt(t,e){this.aimAtScreenPoint(this.raycaster,t,e);const i=[...this.hitAreas.entries()],n=this.raycaster.intersectObjects(i.map(([,s])=>s))[0];if(n&&!this.groundHides(t,e))return i.find(([,s])=>s===n.object)?.[0]}pickInterpretationBodyAt(t,e){const i=this.bodySystem.group.children.filter(f=>f.visible&&f.name.startsWith("body:"));if(i.length===0)return;this.aimAtScreenPoint(this.raycaster,t,e);const n=this.raycaster.ray.direction,s=this.raycaster.ray.origin,r=SE*this.camera.fov*Math.PI/180,o=[...this.decorGroups.values()],c=o.length>0?this.raycaster.intersectObjects(o,!0)[0]?.distance:void 0;let l,h=1/0;const u=new ki,d=new R;for(const f of i){if(u.setFromObject(f),u.isEmpty())continue;u.getCenter(d);const p=u.getSize(new R).length()/2,v=d.clone().sub(s),m=v.length();if(m===0||v.dot(n)<=0||c!==void 0&&c<m-p)continue;const g=Math.acos(Math.min(1,v.normalize().dot(n))),S=Math.max(r,Math.atan(p/m));g<=S&&S<h&&(h=S,l=f.name.slice(5))}return l}pickStarAt(t,e){if(this.namedStars.length===0)return;this.aimAtScreenPoint(this.raycaster,t,e);const i=this.raycaster.ray.direction,n=Math.cos(Pu*this.camera.fov*Math.PI/180);let s,r=n;for(const o of this.namedStars){const c=o.direction.dot(i);c>r&&(r=c,s={star:o.star,altitudeDeg:o.altitudeDeg})}return s&&this.groundHides(t,e)?void 0:s}groundHides(t,e){if(!this.terrainMesh&&!this.groundMesh)return!1;this.aimAtScreenPoint(this.ufoOcclusionRaycaster,t,e);const i=this.ufoOcclusionRaycaster.ray;return this.groundBlocks(i.origin,i.direction,1/0,Qm)}bodyScreenBox(t){const e=this.bodySystem.boxOf(t,this.bodyBoxScratch);if(!e)return;let i=1/0,n=1/0,s=-1/0,r=-1/0;for(let o=0;o<8;o++){const c=this.bodyCornerScratch.set(o&1?e.max.x:e.min.x,o&2?e.max.y:e.min.y,o&4?e.max.z:e.min.z),l=this.screenPointOf(c.sub(this.camera.position).normalize());if(!l)return;i=Math.min(i,l.ndcX),s=Math.max(s,l.ndcX),n=Math.min(n,l.ndcY),r=Math.max(r,l.ndcY)}return{minX:i,minY:n,maxX:s,maxY:r}}bodyBoxScratch=new ki;bodyCornerScratch=new R;pickPlacedBodyAt(t,e){return this.aimAtScreenPoint(this.raycaster,t,e),this.bodySystem.pick(this.raycaster)}decorScreenBox(t){const e=this.decorGroups.get(t);if(!e||!e.visible)return;const i=this.bodyBoxScratch.setFromObject(e);if(i.isEmpty())return;let n=1/0,s=1/0,r=-1/0,o=-1/0;for(let c=0;c<8;c++){const l=this.bodyCornerScratch.set(c&1?i.max.x:i.min.x,c&2?i.max.y:i.min.y,c&4?i.max.z:i.min.z),h=this.screenPointOf(l.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),o=Math.max(o,h.ndcY)}return{minX:n,minY:s,maxX:r,maxY:o}}decorGroundPointAt(t,e,i){const n=this.decorGroups.get(t);if(!n)return;this.aimAtScreenPoint(this.raycaster,e,i);const s=this.raycaster.ray.intersectPlane(this.decorPlaneScratch.setComponents(0,1,0,-n.position.y),this.decorHitScratch);return s?{x:s.x,z:s.z}:void 0}decorPlaneScratch=new er;decorHitScratch=new R;pickDecorAt(t,e){this.aimAtScreenPoint(this.raycaster,t,e);const i=[...this.decorGroups.entries()],n=this.raycaster.intersectObjects(i.map(([,r])=>r),!0)[0];if(!n)return;let s=n.object;for(;s&&!i.some(([,r])=>r===s);)s=s.parent;return i.find(([,r])=>r===s)?.[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.lightningBolt?.dispose(),this.lightningBolt=void 0;for(const t of this.bodyMeshes.values())this.disposeMesh(t);this.bodyMeshes.clear(),this.novaKeys.clear();for(const t of[...this.hitAreas.keys()])this.disposeHitArea(t);for(const t of[...this.glareSprites.keys()])this.disposeGlare(t);this.disposeCompassLabels();for(const t of this.decorGroups.values())oi.dispose(t);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 t=e=>{this.animationFrameId=null,this.frame(e),this.animationFrameId===null&&this.needsAnimationLoop()&&(this.animationFrameId=requestAnimationFrame(t))};this.animationFrameId=requestAnimationFrame(t)}setAnimationsRunning(t,e=!1){const i=t&&e;if(t===this.animationsRunning&&i===this.framesDriven)return;const n=this.animationsRunning;this.animationsRunning=t,this.framesDriven=i,t&&!n&&(this.lastFrameTimeMs=void 0,this.resolution.reset());const s=!t&&this.renderer.getPixelRatio()!==this.resolution.maximum;s&&this.applyPixelRatio(this.resolution.maximum),this.syncAnimationLoop(),(!t||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(t=>t.brightness.length>0)||this.precipitationPoints!==void 0||this.rainSystem!==void 0||this.flareMayShow()}flareAimScratch=new R;flareMayShow(){if(this.lensFlare===void 0||!this.sunVisible)return!1;const t=this.lastAstronomy?.sun;return t!==void 0&&t.altitudeDeg<me.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(t){const e=this.skyMesh?.geometry??new di(ml,32,16),i=e.attributes.position,n=e.getAttribute("color")??new ue(new Float32Array(i.count*3),3);for(let r=0;r<i.count;r++){const{altitudeDeg:o,azimuthDeg:c}=uw(i.getX(r),i.getY(r),i.getZ(r)),l=xw(o,c,t.azimuthDeg,t.altitudeDeg);n.setXYZ(r,l[0],l[1],l[2])}if(n.needsUpdate=!0,this.skyMesh)return;e.setAttribute("color",n);const s=new _n({vertexColors:!0,side:qe,fog:!1,depthWrite:!1});this.skyGradientMaterial=s,this.skyMesh=new bt(e,s),this.skyMesh.renderOrder=-1,this.celestialGroup.add(this.skyMesh)}buildGround(){const t=tg(this.observerElevationM);if(this.groundMesh&&t===this.groundRadius)return;this.disposeMesh(this.groundMesh),this.groundRadius=t;const e=new V0(this.groundRadius,48),i=new qr({color:new st(Iu,Iu,Iu),fog:!0});Vr.fadeRim(i,this.groundRadius*.75,this.groundRadius),this.groundMesh=new bt(e,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 t=this.groundMesh?.material;if(!t)return;const e=this.terrainMesh===void 0;t.depthWrite!==e&&(t.depthWrite=e,t.needsUpdate=!0)}cloudTransmission(t,e=!1){const i=`${t.altitudeDeg.toFixed(1)}:${t.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,o])=>`${r}=${Math.round(o.x/10)},${Math.round(o.z/10)}`).join(";")+(e?":water":""),n=this.cloudTransmissionMemo.get(i);if(n!==void 0)return n;this.cloudTransmissionMemo.size>256&&this.cloudTransmissionMemo.clear();const s=this.computeCloudTransmission(t,e);return this.cloudTransmissionMemo.set(i,s),s}cloudTransmissionMemo=new Map;computeCloudTransmission(t,e=!1){const i=Ze(t.altitudeDeg,t.azimuthDeg,1);if(this.layeredClouds)return this.layeredClouds.transmissionAt(i,e);let n=1;const s=this.lowerCloudCover();s>0&&(n*=1-Me.alphaAt(i,Math.abs(this.cloudLayerOffset()),s,this.cloudFieldOffset)*TE);const r=e?0:this.weather.highCloudCover??0;return r>0&&(n*=1-Me.iceAlphaAt(i,gl,r,this.cloudFieldOffset)*RE),Math.max(0,Math.min(1,n))}setBodyMesh(t,e,i,n,s){if(e.altitudeDeg<_0){this.disposeMesh(this.bodyMeshes.get(t)),this.bodyMeshes.delete(t),this.disposeHitArea(t),this.disposeGlare(t),t==="sun"&&(this.sunVisible=!1);return}const{x:r,y:o,z:c}=Ze(e.altitudeDeg,e.azimuthDeg,un),l=_m(e.altitudeDeg),h=this.cloudTransmission(e),u=this.arrivingIlluminance(e,s,h),d=me.unitLuminance(n);let f=this.bodyMeshes.get(t);if(t==="sun"){const p=Math.PI*(i/un)**2,v=[0,1,2].map(m=>Math.min(me.BRIGHTEST_RELATIVE,d[m]*u[m]/p));f instanceof bt||(this.disposeMesh(f),f=new bt(new di(1,16,16),new _n({fog:!1})),this.celestialGroup.add(f),this.bodyMeshes.set(t,f)),f.material.color.setRGB(v[0],v[1],v[2]),f.scale.setScalar(i)}else{if(!(f instanceof mn)){this.disposeMesh(f);const m=new se;m.setAttribute("position",new Jt(new Float32Array(3),3)),m.setAttribute("color",new Jt(new Float32Array(3),3)),f=new mn(m,Dt.material(Xa[Xa.length-1].size,!1)),Dt.track(f),this.celestialGroup.add(f),this.bodyMeshes.set(t,f)}const p=f.geometry.getAttribute("color"),v=t.startsWith("comet:")?this.pointToPixel():1;p.setXYZ(0,d[0]*u[0]*v,d[1]*u[1]*v,d[2]*u[2]*v),p.needsUpdate=!0}if(f.position.set(r,o,c),this.setHitArea(t,r,o,c,i),t==="sun"&&(this.sunArriving=u),t.startsWith("comet:")?this.disposeGlare(t):t!=="sun"&&this.setGlare(t,r,o,c,u,i/un*(180/Math.PI),me.POINT_VEIL_HOLD_DEG),t==="sun"){this.sunVisible=!0;const p=this.celestialGroup.scale.x;this.sunWorldPosition.set(r*p,o*p+this.celestialGroup.position.y,c*p),this.lensFlare||(this.lensFlare=G5(),this.lensFlare.uniforms.uOpacity.value=UE,this.lensFlare.uniforms.uFlareIntensity.value=this.lensFlareArtifactIntensity,this.lensFlare.uniforms.uStarPoints.value=this.starPoints,this.scene.add(this.lensFlare.mesh)),this.applyLensFlareTint(l)}}setMoonMesh(t,e){const i="moon";if(t.magnitude>e||t.altitudeDeg<_0){this.disposeMesh(this.bodyMeshes.get(i)),this.bodyMeshes.delete(i),this.disposeHitArea(i),this.disposeGlare(i);return}const{x:n,y:s,z:r}=Ze(t.altitudeDeg,t.azimuthDeg,un),o=this.cloudTransmission(t),c=this.arrivingIlluminance(t,t.magnitude,o),l=Math.max(Na(t.phase.illuminatedFraction,0,1),.01)*Math.PI*(Do/un)**2,h=new st(...c.map(f=>Math.min(me.BRIGHTEST_RELATIVE,f/l))),u=`${t.phase.phaseFraction<.5}:${Math.round(Na(t.phase.illuminatedFraction,0,1)*500)}`;let d=this.bodyMeshes.get(i);if(d instanceof go)d.userData.phaseKey!==u&&(d.material.map?.dispose(),d.material.map=wg(t.phase),d.userData.phaseKey=u),d.material.color.copy(h);else{this.disposeMesh(d),d=new go(new Il({map:wg(t.phase),color:h,fog:!1})),d.userData.phaseKey=u;const f=Do*2;d.scale.set(f,f,1),this.celestialGroup.add(d),this.bodyMeshes.set(i,d)}d.position.set(n,s,r),this.setHitArea(i,n,s,r,Do),this.setGlare(i,n,s,r,c,Do/un*(180/Math.PI))}bentLight(t,e,i=EE){const[n,s,r]=this.arrivingIlluminance(t,e,1),o=Math.max(s,1e-30);return{scale:s/i,tint:[n/o,1,r/o]}}static litBySky(t,e){return me.litScratch.setRGB(t.r*e[0],t.g*e[1],t.b*e[2])}static litScratch=new st;pointToPixel(){const t=Math.max(1,this.renderer.getDrawingBufferSize(this.pointScratch).y),e=(this.camera.fov*Math.PI/180/t)**2;return Math.min(1,Dt.CONE_SOLID_ANGLE/e)}pointScratch=new Mt;static POINT_VEIL_HOLD_DEG=.25;static BRIGHTEST_RELATIVE=6e4;arrivingIlluminance(t,e,i){const n=this.air.transmittanceFromSpace(this.siteElevationM+this.observerElevationM,t.altitudeDeg),s=he.illuminanceOf(e)*i*this.relativeScale;return[n[0]*s,n[1]*s,n[2]*s]}static unitLuminance(t){const e=$n.luminanceOf([t.r,t.g,t.b]);return e>0?[t.r/e,t.g/e,t.b/e]:[1,1,1]}setHitArea(t,e,i,n,s){let r=this.hitAreas.get(t);if(!r){const c=new Il({transparent:!0,opacity:0,depthTest:!1,depthWrite:!1,fog:!1});r=new go(c),this.celestialGroup.add(r),this.hitAreas.set(t,r)}r.position.set(e,i,n);const o=s*wE;r.scale.set(o,o,1)}disposeHitArea(t){const e=this.hitAreas.get(t);e&&(e.removeFromParent(),e.material.dispose(),this.hitAreas.delete(t))}setGlare(t,e,i,n,s,r,o=0){if(Ni.radiusDeg(Ni.K*Math.max(...s))<=Math.max(r,o)){this.disposeGlare(t);return}let c=this.glareSprites.get(t);c||(c=new Ni(`veil:${t}`),this.celestialGroup.add(c.mesh),this.glareSprites.set(t,c)),c.shine({x:e,y:i,z:n},s,r,o)}disposeGlare(t){const e=this.glareSprites.get(t);e&&(e.mesh.removeFromParent(),e.dispose(),this.glareSprites.delete(t))}buildComet(t,e){const i=t&&`comet:${t.id}`;if(!t||!i||t.magnitude>e){this.disposeComet();return}this.cometKey&&this.cometKey!==i&&this.disposeComet();const n=Ca(t.magnitude,e),s=gu(n);this.cometKey=i,this.setBodyMesh(i,t.position,Lu*(.5+.5*n),new st(s,s,s),t.magnitude),this.cometTail||(this.cometTail=new fn(un),this.celestialGroup.add(this.cometTail.object)),this.cometTail.set(t.position,t.tailEnd,n)}buildIceHalos(t,e){this.iceHalos||(this.iceHalos=new Ti,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:gl},0);return}const s=this.lowerCloudCover(),r=ve.deckLitUntilDeg(ve.DECK_HEIGHT_M),o=t.altitudeDeg>-r?t:e,c=this.bentLight(o,o===t?ke.SUN_MAGNITUDE:e.magnitude),l=ve.strength(i,s,o.altitudeDeg,r)*c.scale,{x:h,y:u,z:d}=Ze(o.altitudeDeg,o.azimuthDeg,1);this.iceHalos.update({x:h,y:u,z:d},o.altitudeDeg,l,c.tint,{cover:n?.cover??i,layerHeight:n?.layerHeight??gl},n?.iceCrystalAlignment??this.weather.iceCrystalAlignment??Uv)}buildRainbow(t,e){this.rainbow||(this.rainbow=new Nr,this.celestialGroup.add(this.rainbow.object));const i=this.weather.precipitationType==="rain"?this.weather.precipitationIntensity*(this.weather.precipitationAmount??1):0,n=t.altitudeDeg>0,s=n?t:e,r=this.lowerCloudCover(),o=this.bentLight(s,n?ke.SUN_MAGNITUDE:e.magnitude,AE),c=dn.strength(i,r,s.altitudeDeg)*o.scale;if(c<=0){this.rainbow.update({x:0,y:1,z:0},0,[1,1,1],!0);return}const{x:l,y:h,z:u}=Ze(s.altitudeDeg,s.azimuthDeg,1);this.rainbow.update({x:l,y:h,z:u},c,o.tint,n)}buildSkyGlow(t,e){if(!t.frame){this.skyGlow?.hide();return}this.skyGlow||(this.skyGlow=new ir,this.skyGlow.setWithheld(!!this.skyHoldUntilMs),this.skyGlow.onReady=()=>this.render(),this.celestialGroup.add(this.skyGlow.object));const{date:i,observer:n}=t.frame,s=Vn.galactic(i,n),r=me.directionOf(s.centre),o=me.directionOf(s.rotation),c=me.directionOf(s.pole),l=new $t().set(r.x,r.y,r.z,o.x,o.y,o.z,c.x,c.y,c.z),h=me.directionOf(Vn.eclipticPole(i,n)),u=me.directionOf(t.sun),d=u.clone().addScaledVector(h,-u.dot(h)).normalize();this.skyGlow.update({galactic:l,eclipticPole:h,sunLongitude:d,sunDirection:u,sunAltitudeDeg:t.sun.altitudeDeg,moon:{direction:me.directionOf(t.moon),altitudeDeg:t.moon.altitudeDeg,phaseAngleDeg:xt.phaseAngleOf(t.moon.phase.illuminatedFraction)},lightPollution:this.lightPollution,skyColor:new R(e[0],e[1],e[2])})}static directionOf(t){const{x:e,y:i,z:n}=Ze(t.altitudeDeg,t.azimuthDeg,1);return new R(e,i,n).normalize()}buildNovae(t,e){const i=new Set;for(const n of t){if(n.magnitude>e)continue;const s=`nova:${n.id}`;i.add(s);const r=Ca(n.magnitude,e),o=gu(r);this.setBodyMesh(s,n.position,Lu*(.5+.5*r),new st(o,o,o),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(t,e){const i=new Set(["sun","moon",...this.cometKey?[this.cometKey]:[],...this.novaKeys]);for(const n of t){if(n.magnitude>e)continue;i.add(n.body);const s=Ca(n.magnitude,e),r=gu(s),o=nA[n.body]??new st(1,1,1),c=new st(o.r*r,o.g*r,o.b*r),l=Lu*(.5+.5*s);this.setBodyMesh(n.body,n.position,l,c,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(t,e){if(this.namedStars=[],!t||t.catalog.count===0){this.disposeStarTiers(),this.syncAnimationLoop();return}const{catalog:i,date:n,observer:s}=t,r=new Yn(n,s),o=Vu(1337),c=[],l=this.siteElevationM+this.observerElevationM;for(let h=0;h<i.count;h++){const u=i.mag[h];if(u>e)break;const{altitudeDeg:d,azimuthDeg:f}=r.position(i.ra[h],i.dec[h]);if(d<eg)continue;const{x:p,y:v,z:m}=Ze(d,f,Cu);c.push({x:p,y:v,z:m,brightness:Ca(u,e),illuminance:this.air.transmittanceFromSpace(l,d).map(g=>g*he.illuminanceOf(u)),phase:o()*Math.PI*2,speedFactor:.7+o()*.6})}for(const h of S5){if(h.mag>e)continue;const{altitudeDeg:u,azimuthDeg:d}=r.position(h.raHours,h.decDeg);if(u<eg)continue;const{x:f,y:p,z:v}=Ze(u,d,Cu);this.namedStars.push({star:h,direction:new R(f,p,v).normalize(),altitudeDeg:u})}this.starTiers=Xa.map((h,u)=>{const d=c.filter(b=>Q0(b.brightness)===u),f=new Float32Array(d.length*3),p=new Float32Array(d.length),v=new Float32Array(d.length*3),m=new Float32Array(d.length),g=new Float32Array(d.length);d.forEach((b,w)=>{f[w*3]=b.x,f[w*3+1]=b.y,f[w*3+2]=b.z,p[w]=b.brightness,v.set(b.illuminance,w*3),m[w]=b.phase,g[w]=b.speedFactor});const S=new se;S.setAttribute("position",new Jt(f,3)),S.setAttribute("seed",new Jt(m.map(b=>b/(2*Math.PI)),1));const x=new Jt(new Float32Array(d.length*3),3);S.setAttribute("color",x);let M=this.starTiers[u]?.points;return M?(M.geometry.dispose(),M.geometry=S):(M=new mn(S,Dt.material(h.size)),Dt.track(M),this.celestialGroup.add(M)),{points:M,colorAttribute:x,brightness:p,illuminance:v,phase:m,speedFactor:g}}),this.starColoursRelative=Number.NaN,this.updateTwinkle(this.twinkleSeconds),this.startTwinkle()}twinkleSeconds=0;starColoursRelative=Number.NaN;updateTwinkle(t){Dt.setTime(t);const e=this.relativeScale;if(e!==this.starColoursRelative){this.starColoursRelative=e;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]*e,n[s*3+1]=i.illuminance[s*3+1]*e,n[s*3+2]=i.illuminance[s*3+2]*e;i.colorAttribute.needsUpdate=!0}}}buildClouds(){if(this.cloudRendering==="volume"||this.weather.cloudLayers!==void 0){this.layeredClouds||(this.disposeCloudSystem(),this.layeredClouds=new Va(this.celestialGroup,Ou,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 t=this.lowerCloudCover();if(t<=0){this.disposeCloudSystem();return}const e=this.weather.cloudDarkness,i=new st(Er[0]+(Uu[0]-Er[0])*e,Er[1]+(Uu[1]-Er[1])*e,Er[2]+(Uu[2]-Er[2])*e);if(this.cloudMesh&&this.cloudUniforms){this.cloudUniforms.coverage.value=t,this.cloudUniforms.baseColor.value.copy(i),this.syncCloudLayer(),this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor);return}this.disposeCloudSystem();const{material:n,uniforms:s}=$d(i,t,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=Kd(Ou);this.cloudMesh=new bt(r,n),this.faceCloudDeck(this.cloudMesh,this.cloudLayerOffset()),this.celestialGroup.add(this.cloudMesh)}lowerCloudCover(){return this.weather.cloudLayers?1-this.weather.cloudLayers.filter(t=>t.type!=="cirrus").reduce((t,e)=>t*(1-e.coverage),1):this.weather.lowerCloudCover??this.weather.cloudCover}highCloudCover(){return this.weather.cloudLayers?1-this.weather.cloudLayers.filter(t=>t.type==="cirrus").reduce((t,e)=>t*(1-e.coverage),1):this.weather.highCloudCover}buildCirrus(){const t=this.weather.highCloudCover??0;if(this.layeredClouds||t<=0){this.disposeCirrus();return}if(this.cirrusMesh&&this.cirrusUniforms){this.cirrusUniforms.coverage.value=t,this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor);return}const{material:e,uniforms:i}=$d(new st(...Er),t,gl,1);this.cirrusMaterial=e,this.cirrusUniforms=i,i.fieldOffset.value.copy(this.cloudFieldOffset),this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor),this.cirrusMesh=new bt(Kd(Ou*1.04),e),this.cirrusMesh.renderOrder=cg-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 t=this.cloudLayerOffset();this.cloudUniforms&&(this.cloudUniforms.layerHeight.value=Math.abs(t)),this.cloudMesh&&this.faceCloudDeck(this.cloudMesh,t)}faceCloudDeck(t,e){const i=e<0;t.scale.y=i?-1:1,t.renderOrder=i?Va.deckOrder(!0,0,1):cg}cloudLayerOffset(){const e=((this.weather.cloudBaseM??w0)-this.observerElevationM)*Nu;return Math.sign(e||1)*Math.max(Math.abs(e),zE)}updateCloudLighting(t,e){const i=[this.cloudUniforms,this.cirrusUniforms].filter(u=>u!==void 0);if(i.length===0&&!this.layeredClouds)return;const n=this.cloudBeamDirection,[s,r,o]=this.cloudBeam.map(u=>u/Math.PI),c=this.lightningLevel*Gu*this.relativeScale/Math.PI,l=new st(e[0]+ss.r*c,e[1]+ss.g*c,e[2]+ss.b*c);this.layeredClouds?.setLighting(n.clone(),new st(s,r,o),l,l);const h=Math.max(0,n.y);for(const u of i)u.sunDir.value.copy(n),u.sunColor.value.setRGB(s*h,r*h,o*h),u.ambientColor.value.copy(l)}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(t){return qE(t,this.weather.precipitationIntensity,this.weather.precipitationAmount??1)}updatePrecipitationDensity(){const t=[[this.rainSystem?.points,Bu],[this.rainSplashSystem?.points,Ar],[this.precipitationPoints,this.weather.precipitationType==="none"||this.weather.precipitationType==="rain"?void 0:ku[this.weather.precipitationType].poolSize]];for(const[e,i]of t)e&&i!==void 0&&e.geometry.setDrawRange(0,this.precipitationCount(i));this.rainSystem&&(this.rainSystem.uniforms.uSpeedStreak.value=dg(Hu(this.weather.precipitationIntensity)))}buildPrecipitation(){this.disposePrecipitationPoints(),this.disposeRain();const t=this.weather.precipitationType;if(t==="none")return;if(t==="rain"){this.buildRain();return}const e=ku[t],i=e.poolSize,n=Vu(9001),s=new Float32Array(i*3),r=new Float32Array(i),o=new Float32Array(i),c=new Float32Array(i),l=new Float32Array(i),h=new Float32Array(i),u=new Float32Array(i),d=new Float32Array(i),f=new Float32Array(i),p=new Float32Array(i);for(let x=0;x<i;x++){const M=n()*Math.PI*2,b=n()*e.radiusM;s[x*3]=Math.cos(M)*b,s[x*3+1]=Ta+n()*(e.topYM-Ta),s[x*3+2]=Math.sin(M)*b,r[x]=n()*Math.PI*2,o[x]=.7+n()*.6,c[x]=.6+n()*.8,l[x]=.4+n()*1.2}const v=new se;v.setAttribute("position",new Jt(s,3)),v.setDrawRange(0,this.precipitationCount(i));const m={uSize:{value:e.size},uScale:{value:.5*this.renderer.domElement.height},uOpacity:{value:e.opacity},uColor:{value:e.color.clone()},uHazeColor:{value:new st(...this.baseFogColor)},uTexture:{value:sA(t)},uNearFocusDistance:{value:gg},uHazeDistance:{value:e.radiusM*vg}},g=new de({uniforms:m,vertexShader:hA,fragmentShader:uA,transparent:!0,depthWrite:!1});this.precipitationUniforms=m;const S=new mn(v,g);S.renderOrder=Fu,this.scene.add(S),this.precipitationPoints=S,this.precipitationPositions=s,this.precipitationPhase=r,this.precipitationSpeedJitter=o,this.precipitationWobbleFreqJitter=c,this.precipitationWobbleAmpJitter=l,this.precipitationBounceRemaining=h,this.precipitationBounceHeight=u,this.precipitationBounceDuration=d,this.precipitationBounceVelX=f,this.precipitationBounceVelZ=p}updatePrecipitation(t,e){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=ku[i];if(this.precipitationUniforms?.uColor.value.copy(me.litBySky(n.color,this.baseFogColor)),e<=0)return;const s=this.weather.windDirectionDeg*ji,r=Math.sin(s)*this.weather.windSpeed*n.driftSensitivity,o=-Math.cos(s)*this.weather.windSpeed*n.driftSensitivity,c=this.precipitationPositions,l=this.precipitationPhase,h=this.precipitationSpeedJitter,u=this.precipitationWobbleFreqJitter,d=this.precipitationWobbleAmpJitter,f=this.precipitationBounceRemaining,p=this.precipitationBounceHeight,v=this.precipitationBounceDuration,m=this.precipitationBounceVelX,g=this.precipitationBounceVelZ,S=i==="snow"&&u&&d,x=i==="hail"&&f&&p&&v&&m&&g;for(let M=0,b=0;M<c.length;M+=3,b++){if(x&&f[b]>0){if(f[b]-=e,f[b]<=0){const y=Math.random()*Math.PI*2,A=Math.sqrt(Math.random())*n.radiusM;c[M]=Math.cos(y)*A,c[M+1]=n.topYM,c[M+2]=Math.sin(y)*A,f[b]=0}else{const y=1-f[b]/v[b];c[M+1]=Ta+Math.sin(Math.PI*y)*p[b],c[M]=xl(c[M]+(r+m[b])*e,n.radiusM),c[M+2]=xl(c[M+2]+(o+g[b])*e,n.radiusM)}continue}let w=0,T=0;if(S){const y=KE*u[b],A=ZE*d[b];w=Math.sin(t*y*Math.PI*2+l[b])*A,T=Math.sin(t*y*Math.PI*2+l[b]+Math.PI/2)*A}if(c[M]+=(r+w)*e,c[M+1]-=n.fallSpeedMPerS*h[b]*e,c[M+2]+=(o+T)*e,c[M]=xl(c[M],n.radiusM),c[M+2]=xl(c[M+2],n.radiusM),c[M+1]<Ta){if(x){p[b]=_g*(.2+Math.random()*1.6),v[b]=JE*(.5+Math.random()),f[b]=v[b];const C=Math.random()*Math.PI*2,I=jE*(p[b]/_g);m[b]=Math.cos(C)*I,g[b]=Math.sin(C)*I,c[M+1]=Ta;continue}const y=Math.random()*Math.PI*2,A=Math.sqrt(Math.random())*n.radiusM;c[M]=Math.cos(y)*A,c[M+1]=n.topYM,c[M+2]=Math.sin(y)*A}}this.precipitationPoints.geometry.attributes.position.needsUpdate=!0}buildRain(){const t=Hu(this.weather.precipitationIntensity);this.rainSystem=k5({count:Bu,radiusM:Io,heightM:HE,bottomYM:lg,overallSpeed:GE,color:ug.clone(),opacity:.85,visibleCount:this.precipitationCount(Bu),speedStreak:dg(t),pixelSize:xg,seed:9001,nearFocusDistanceM:gg,hazeDistanceM:Io*vg,hazeColor:new st(...this.baseFogColor)}),this.rainLastVerticalFacing=-1,this.syncRainSlant(),this.rainSystem.points.renderOrder=Fu,this.scene.add(this.rainSystem.points),this.buildRainSplashes()}buildRainSplashes(){const t=Vu(4242),e=new Float32Array(Ar*3),i=new Float32Array(Ar),n=new Float32Array(Ar),s=new Float32Array(Ar);for(let h=0;h<Ar;h++){const u=t()*Math.PI*2,d=Math.sqrt(t())*Io;e[h*3]=Math.cos(u)*d,e[h*3+1]=lg,e[h*3+2]=Math.sin(u)*d,n[h]=bg(fg,pg),i[h]=t()*n[h],s[h]=i[h]/n[h]}const r=new se;r.setAttribute("position",new Jt(e,3));const o=new Jt(s,1);r.setAttribute("aLife",o),r.setDrawRange(0,this.precipitationCount(Ar));const c=new de({uniforms:{uMaxSize:{value:YE},uScale:{value:.5*this.renderer.domElement.height},uColor:{value:mg.clone()},uTexture:{value:oA()}},vertexShader:cA,fragmentShader:lA,transparent:!0,depthWrite:!1}),l=new mn(r,c);l.renderOrder=Fu,this.scene.add(l),this.rainSplashSystem={points:l,positions:e,life:i,duration:n,lifeAttribute:o}}disposeRain(){this.rainSystem&&(this.rainSystem.points.removeFromParent(),this.rainSystem.points.geometry.dispose(),this.rainSystem.points.material.dispose()),this.rainSystem=void 0,this.disposeRainSplashes()}disposeRainSplashes(){this.rainSplashSystem&&(this.rainSplashSystem.points.removeFromParent(),this.rainSplashSystem.points.geometry.dispose(),this.rainSplashSystem.points.material.dispose()),this.rainSplashSystem=void 0}syncRainSlant(){const t=this.rainSystem;if(!t)return;const e=this.weather.windDirectionDeg*ji;t.uniforms.uDropVelocity.value.set(Math.sin(e)*this.weather.windSpeed,-Hu(this.weather.precipitationIntensity),-Math.cos(e)*this.weather.windSpeed);const i=this.renderer.getSize(this.rainViewportSize);t.uniforms.uAspect.value=i.x/Math.max(i.y,1)}updateRain(t){const e=this.rainSystem;if(!e)return;e.uniforms.uTime.value+=t,e.uniforms.uHazeColor.value.setRGB(...this.baseFogColor),e.uniforms.uColor.value.copy(me.litBySky(ug,this.baseFogColor));const i=this.rainSplashSystem?.points.material?.uniforms?.uColor;i&&i.value.copy(me.litBySky(mg,this.baseFogColor));const n=this.weather.windDirectionDeg*ji,s=Math.sin(n)*this.weather.windSpeed,r=-Math.cos(n)*this.weather.windSpeed,o=Io,c=h=>(h%(o*2)+o*3)%(o*2)-o;e.uniforms.uWindOffset.value.set(c(e.uniforms.uWindOffset.value.x+s*t),c(e.uniforms.uWindOffset.value.y+r*t)),this.syncRainSlant(),this.camera.getWorldDirection(this.rainCameraDirection);const l=Math.abs(this.rainCameraDirection.y);if(Math.abs(l-this.rainLastVerticalFacing)>.001){this.rainLastVerticalFacing=l;const h=yg+(1-yg)*(1-l),u=Sg+(1-Sg)*(1-l);e.uniforms.uUvSquash.value=u,e.uniforms.uPixelSize.value=xg*h*(.5+.5*u)}this.updateRainSplashes(t)}updateRainSplashes(t){const e=this.rainSplashSystem;if(!e||t<=0)return;const{positions:i,life:n,duration:s,lifeAttribute:r}=e,o=r.array;for(let c=0,l=0;c<i.length;c+=3,l++){if(n[l]+=t,n[l]>=s[l]){const h=Math.random()*Math.PI*2,u=Math.sqrt(Math.random())*Io;i[c]=Math.cos(h)*u,i[c+2]=Math.sin(h)*u,s[l]=bg(fg,pg),n[l]=0}o[l]=n[l]/s[l]}e.points.geometry.attributes.position.needsUpdate=!0,r.needsUpdate=!0}setLightning(t){this.lightningFlashes=t}updateLightning(t){let e,i=0;if(this.lightningArmed)for(const c of this.lightningFlashes){if(c.t>t)break;const l=gi.brightnessAt(c,t);l>i&&(e=c,i=l)}const n=e?Math.min(1,Math.max(.1,(eA/e.distanceM)**2)):0,s=i*n*(e?.cloudToGround?1:.6);if(s===this.lightningLevel&&!e?.cloudToGround)return;if(this.lightningLevel=s,this.scene.fog){const c=this.scene.fog,l=s*Gu*this.relativeScale/Math.PI;c.color.setRGB(this.airlight[0]+ss.r*l,this.airlight[1]+ss.g*l,this.airlight[2]+ss.b*l)}const r=this.skyMesh?.material?.color;if(r){const c=s*iA;r.setRGB(1+c*ss.r,1+c*ss.g,1+c*ss.b)}if(this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor),this.lightningLight.intensity=s*Gu*this.relativeScale,e){const{x:c,y:l,z:h}=Ze(25,e.azimuthDeg,un);this.lightningLight.position.set(c,l,h)}this.lightningBolt||(this.lightningBolt=new nr(un*.95),this.celestialGroup.add(this.lightningBolt.object));const o=this.weather.cloudBaseM??1500;this.lightningBolt.set(e,i,o),this.render()}buildCompassLabels(){this.compassSprites=IE.map(t=>{const e=Hr.point(t,this.compassPoints),i=new Il({map:dA(e),depthTest:!1,fog:!1}),n=new go(i),{x:s,y:r,z:o}=Ze(0,t,sg);return n.position.set(s,r,o),n.scale.set(Ml,Ml,1),n.renderOrder=LE,n.layers.set(Du),n.visible=this.compassHovered||this.compassForced,this.celestialGroup.add(n),n}),this.updateCompassScale()}updateCompassScale(){const t=this.camera.fov*Math.PI/360,e=rg*Math.PI/360,i=Ml*Math.tan(t)/Math.tan(e);for(const n of this.compassSprites)n.scale.set(i,i,1)}disposeCompassLabels(){for(const t of this.compassSprites)t.removeFromParent(),t.material.map?.dispose(),t.material.dispose();this.compassSprites=[]}disposeStarTiers(){for(const t of this.starTiers)this.disposeMesh(t.points);this.starTiers=[]}disposeMesh(t){if(!t)return;t.removeFromParent(),"geometry"in t&&t.geometry.dispose();const e=t.material;for(const i of Array.isArray(e)?e:[e]){const n=i.map;n&&n.dispose(),i.dispose()}}}const ji=Math.PI/180;function Na(a,t,e){return Math.max(t,Math.min(e,a))}function bg(a,t){return a+Math.random()*(t-a)}function xl(a,t){return(a%(t*2)+t*3)%(t*2)-t}let yl,Sl;function sA(a){switch(a){case"snow":return rA();case"hail":return aA()}}function rA(){if(yl)return yl;const a=64,t=document.createElement("canvas");t.width=a,t.height=a;const e=t.getContext("2d"),i=e.createRadialGradient(a/2,a/2,0,a/2,a/2,a/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)"),e.fillStyle=i,e.fillRect(0,0,a,a),yl=new Bs(t),yl}function aA(){if(Sl)return Sl;const a=64,t=document.createElement("canvas");t.width=a,t.height=a;const e=t.getContext("2d"),i=e.createRadialGradient(a/2,a/2,0,a/2,a/2,a/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)"),e.fillStyle=i,e.fillRect(0,0,a,a),Sl=new Bs(t),Sl}let _l;function oA(){if(_l)return _l;const a=64,t=document.createElement("canvas");t.width=a,t.height=a;const e=t.getContext("2d"),i=e.createRadialGradient(a/2,a/2,0,a/2,a/2,a/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)"),e.fillStyle=i,e.fillRect(0,0,a,a),_l=new Bs(t),_l}const cA=`
7855
+ `,transparent:!0,blending:Ai,depthWrite:!1,side:qe,fog:!1});this.object=new bt(new di(ff.RADIUS,128,32,0,Math.PI*2,0,ue.MAX_ANGLE_RAD),e),this.object.renderOrder=-1,this.object.frustumCulled=!1,this.object.visible=!1}show(t,e){if(!t||!e){this.object.visible=!1;return}this.towards.set(t.x,t.y,t.z).normalize(),this.object.quaternion.setFromUnitVectors(this.up,this.towards),this.object.material.uniforms.uSource.value.copy(this.towards);for(let i=0;i<ue.STEPS;i++){for(let n=0;n<3;n++)this.texels[i*4+n]=Ln.toHalfFloat(Math.min(e[i*3+n],6e4));this.texels[i*4+3]=Ln.toHalfFloat(1)}this.texture.needsUpdate=!0,this.object.visible=!0}dispose(){this.object.geometry.dispose(),this.object.material.dispose(),this.texture.dispose()}}class rh{constructor(t){this.generator=t}static SIZE=128;target=new lc(rh.SIZE,{type:$e,generateMipmaps:!1,minFilter:le,magFilter:le});camera=new $0(.1,2e5,this.target);filteredTarget;capturedAtMs=-1/0;capturedVersion;get sharp(){return this.target.texture}get filtered(){return this.filteredTarget?.texture}capture(t,e,i,n=[]){const s=t.shadowMap.autoUpdate;let r=!1;e.traverse(c=>{const l=c;l.isLight&&l.castShadow&&l.shadow&&!l.shadow.map&&(r=!0)}),t.shadowMap.autoUpdate=r?s:!1;const o=n.map(c=>c.visible);for(const c of n)c.visible=!1;this.camera.position.copy(i),this.camera.update(t,e),n.forEach((c,l)=>{c.visible=o[l]}),t.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 sn{static REFRESH_MS=250;generator;eye;probes=new Map;constructor(t){sn.install(),this.generator=new Wd(t),this.eye=new rh(this.generator)}static decor;refresh(t,e,i,n,s,r,o,c=[],l,h=sn.REFRESH_MS){for(const m of[...this.probes.keys()])n.some(g=>g.id===m&&g.shiny)||(this.probes.get(m).dispose(),this.probes.delete(m));const u=[{probe:this.eye}];for(const m of n){if(!m.shiny)continue;let g=this.probes.get(m.id);g||(g=new rh(this.generator),this.probes.set(m.id,g)),u.push({probe:g,reflector:m})}const d=performance.now(),f=()=>u.filter(({probe:m})=>m.capturedVersion!==o),p=f().filter(({probe:m})=>d-m.capturedAtMs>=h);if(p.length>0){const m=p.reduce((g,S)=>S.probe.capturedAtMs<g.probe.capturedAtMs?S:g);if(m.reflector){const g=m.reflector.holder.getWorldPosition(this.scratch);m.probe.capture(t,e,g,[m.reflector.holder,...s]),sn.reflectOn(m.reflector.holder,m.probe)}else{m.probe.capture(t,e,i,[...s,...c]),l?.(m.probe.sharp),sn.decor=m.probe.filtered;for(const g of r)sn.reflectOn(g,m.probe);for(const g of n)g.shiny||sn.reflectOn(g.holder,m.probe)}m.probe.capturedVersion=o}const v=f();if(v.length!==0)return Math.max(16,Math.min(...v.map(({probe:m})=>h-(d-m.capturedAtMs))))}scratch=new R;static reflectOn(t,e={filtered:sn.decor}){t.traverse(i=>{const n=i.material;for(const s of Array.isArray(n)?n:n?[n]:[])s instanceof uc?e.sharp&&s.setSurroundings(e.sharp):s instanceof ar&&e.filtered&&s.envMap!==e.filtered&&(s.envMap=e.filtered,s.needsUpdate=!0)})}dispose(){this.eye.dispose();for(const t of this.probes.values())t.dispose();this.generator.dispose()}static installed=!1;static install(){if(sn.installed)return;sn.installed=!0;const t="iblIrradiance += getIBLIrradiance( geometryNormal );";if(!qt.lights_fragment_maps.includes(t)){console.warn("Reflections: three's lights_fragment_maps changed; the environment will light diffusely too");return}qt.lights_fragment_maps=qt.lights_fragment_maps.replace(t,"// The sky's diffuse light is the hemisphere light's (see Reflections).")}}function ME(a,t){return JSON.stringify(a.cloudLayers)===JSON.stringify(t.cloudLayers)&&a.cloudCover===t.cloudCover&&a.cloudDarkness===t.cloudDarkness&&a.cloudBaseM===t.cloudBaseM&&a.highCloudCover===t.highCloudCover&&a.iceCrystalAlignment===t.iceCrystalAlignment&&a.lowerCloudCover===t.lowerCloudCover&&a.relativeHumidity===t.relativeHumidity&&a.precipitationType===t.precipitationType&&a.precipitationIntensity===t.precipitationIntensity&&a.precipitationAmount===t.precipitationAmount&&a.windDirectionDeg===t.windDirectionDeg&&a.windSpeed===t.windSpeed&&a.storm===t.storm}const ml=900,Ru=1,jm=4,Du=5,Qm=.5,ko=900,xE=6371e3,yE=3e4;function tg(a){const t=Math.sqrt(2*xE*Math.max(a,0));return Math.max(ko,Math.min(t,yE))}const Iu=.5,Cu=850,Pu=.03,SE=.015,un=850,Ro=300,js=120,_E=700,bE=.04,Do=4,Lu=1.5,eg=-1,wE=6,_0=-4,EE=2,AE=20,gl=2600,TE=.97,RE=.38,vl=_0,ig=1500,DE=400,IE=[0,45,90,135,180,225,270,315],CE=2,PE=16,ng=4e3,sg=880,Ml=40,rg=60,LE=10,OE=1,NE=150,FE=55,UE=.5,kE=17,ag=.265,og=[[0,0],...Array.from({length:8},(a,t)=>{const e=t*Math.PI/4;return[Math.cos(e)*ag,Math.sin(e)*ag]})],Ou=700,Nu=250/w0,zE=12,cg=5,Fu=6,Er=[.92,.92,.95],Uu=[.15,.15,.19],ku={snow:{fallSpeedMPerS:2,size:.3,color:new st(1,1,1),driftSensitivity:1,radiusM:25,topYM:20,opacity:.75,poolSize:2400},hail:{fallSpeedMPerS:14,size:.5,color:new st(.95,.98,1),driftSensitivity:.25,radiusM:25,topYM:10,opacity:.95,poolSize:1200}},Ta=0,zu=0,BE=150,Bu=3e3,Io=20,HE=15,lg=Ta,GE=40,hg=1,VE=9;function Hu(a){return hg+(VE-hg)*a}const ug=new st(.75,.82,.92),WE=10,XE=.5;function dg(a){return Na(a/WE,XE,1)}const Ar=200,fg=.18,pg=.32,YE=.35,mg=new st(.85,.9,.98),gg=5,vg=.85,Mg=.01;function qE(a,t,e=1){return Math.round(a*(Mg+(1-Mg)*t)*e)}function $E(a,t){return JSON.stringify(a.cloudLayers)===JSON.stringify(t.cloudLayers)&&a.cloudCover===t.cloudCover&&a.cloudDarkness===t.cloudDarkness&&a.cloudBaseM===t.cloudBaseM&&a.highCloudCover===t.highCloudCover&&a.iceCrystalAlignment===t.iceCrystalAlignment&&a.lowerCloudCover===t.lowerCloudCover}const xg=230,yg=.7,Sg=.05,KE=.6,ZE=.7,JE=.15,_g=.35,jE=3,QE=1/12,tA=.5,ss=new st(.82,.86,1),eA=2500,iA=1.6,Gu=15,nA={Venus:new st(1,.96,.85),Mars:new st(1,.55,.4),Jupiter:new st(.95,.87,.72),Saturn:new st(.92,.86,.68)};class me{renderer;scene=new ys;phenomena=new Wn(this.scene);references=new Gn(this.scene,()=>this.render());camera;celestialGroup=new Re;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(t,e){if(this.skyHoldUntilMs===null)return t;this.arrivalsPending++;let i=!0;const n=()=>{i&&(i=!1,this.arrivalsPending--,this.lastArrivalVersion=this.sceneVersion,this.skyHoldUntilMs&&this.redrawHeld())},s=e===void 0?void 0:setTimeout(n,e);return e!==void 0&&(this.arrivalDeadlineMs=Math.max(this.arrivalDeadlineMs,performance.now()+e),this.skyHoldUntilMs&&this.arrivalDeadlineMs>this.skyHoldUntilMs&&(this.skyHoldUntilMs=this.arrivalDeadlineMs,setTimeout(()=>this.render(),e+20))),t.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(t){this.surroundings=void 0,this.scatteredSky?.resetSurroundings(),this.startHold(),t&&this.awaitArrival(t).catch(()=>{})}startHold(){this.skyHoldUntilMs=Math.max(performance.now()+ng,this.arrivalDeadlineMs),this.eyeSettledVersion=-1,this.lastArrivalVersion=this.sceneVersion+1,this.iceHalos?.setUrgent(!0),this.skyGlow?.setWithheld(!0),this.onFirstFrameHold?.(!0),setTimeout(()=>this.render(),ng+20)}groundMesh;terrainMesh;terrainProviders;terrainOrigin;terrainBuildToken=0;terrainAttribution;roadSystem=new Tn;roadAttribution;roadWays;statedRoads=[];traces=[];traceLabels=new Map;tracesShown=!0;traceSystem;traceSystemLoading;traceResolution=new Mt;decorModelProvider=mE[0].create();decorModelToken=0;decorModelCredits=new Map;bodySystem=new re(t=>this.awaitArrival(this.loadBodyModel(t)),()=>this.render(),()=>this.relativeScale);bodyOrigin={x:0,z:0};starTiers=[];bodyMeshes=new Map;hitAreas=new Map;glareSprites=new Map;decorObjects=[];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(t){return(t.sizeM?.lengthM??me.TRAFFIC_MODEL_DEFAULT_LENGTH_M)*me.TRAFFIC_MODEL_RANGE_PER_METRE}pendingTrafficModels=new Map;contrails=[];contrailSystem;contrailSystemLoading;contrailSunlight=new Map;sceneSunBeam=[0,0,0];decorReferencePose;decorCurrentPose;decorTime=0;celestialLight=new Wp(16777215,0);celestialLightTarget=new Ge;skyLight=new Ux(16777215,0,0);streetlightLights=new Map;compassSprites=[];showCompass=!1;compassHovered=!1;compassForced=!1;animationFrameId=null;resolution;cssSize={width:1,height:1};frameDirty=!1;flushFrameId=null;framesDriven=!1;lastFrameTimeMs;raycaster=new Cl;weather=ch;observerElevationM=0;siteElevationM=0;air=new In;groundRadius=ko;terrainRadius=ko;cloudRendering="volume";layeredClouds;cloudLayerOffsetsM={};cloudOffsetM=new R;cloudFieldOffset=new R;cloudMesh;cirrusMesh;cirrusMaterial;cirrusUniforms;cloudMaterial;cloudUniforms;precipitationPoints;precipitationPositions;precipitationPhase;precipitationSpeedJitter;precipitationWobbleFreqJitter;precipitationWobbleAmpJitter;precipitationBounceRemaining;precipitationBounceHeight;precipitationBounceDuration;precipitationBounceVelX;precipitationBounceVelZ;precipitationUniforms;rainSystem;rainSplashSystem;rainCameraDirection=new R;rainLastVerticalFacing=-1;rainViewportSize=new Mt;lightningArmed=!1;lightningFlashes=[];lightningLevel=0;lightningBolt;lightningLight=new Wp(16777215,0);baseFogColor=[0,0,0];lastSunPosition;lensFlare;sunUnhiddenFraction=1;lensFlareArtifactIntensity=0;sunWorldPosition=new R;sunVisible=!1;lensFlareScratch=new R;sunOcclusionRaycaster=new Cl;sunOcclusionDirectionScratch=new R;sunOcclusionRightScratch=new R;sunOcclusionUpScratch=new R;ufoOcclusionRaycaster=new Cl;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(t){return Math.max(3,Math.round(6e6/Math.max(1,t)))}exposureFrameId=null;exposureInstantsDone=0;exposureInstantAt;restatingExposure=!1;lensOptics;instrumentMagnitudeGain=0;lightPollution;meteorSystem;cometTail;satelliteField;reentrySystem;iceHalos;lunarDiffraction;lunarDiffractionKey="";rainbow;skyGlow;cometKey;novaKeys=new Set;constructor(t,e=z2()){this.renderer=new jb({canvas:t,antialias:!0}),this.resolution=new xe(Math.min(window.devicePixelRatio||1,2),this.renderer.getContext()),this.renderer.setPixelRatio(this.resolution.pixelRatio),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=Ho,this.camera=new rn(60,t.width/Math.max(t.height,1),.1,ml*1.2),this.camera.position.set(0,1.6,0),this.terrainProviders=e,this.celestialLight.shadow.mapSize.set(1024,1024),this.celestialLight.shadow.camera.left=-js,this.celestialLight.shadow.camera.right=js,this.celestialLight.shadow.camera.top=js,this.celestialLight.shadow.camera.bottom=-js,this.celestialLight.shadow.camera.near=un-Ro,this.celestialLight.shadow.camera.far=un+Ro,this.celestialLight.shadow.bias=-.03/(2*Ro),this.celestialLight.shadow.normalBias=bE,this.celestialLight.target=this.celestialLightTarget,this.lightningLight.color.copy(ss),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);const i=new ke(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(t,e){this.cssSize.width=t,this.cssSize.height=e,this.renderer.setSize(t,e,!1),this.camera.aspect=t/Math.max(e,1),this.camera.updateProjectionMatrix(),this.render()}setCloudRendering(t){t!==this.cloudRendering&&(this.cloudTransmissionMemo.clear(),this.cloudRendering=t,this.layeredClouds?.dispose(),this.layeredClouds=void 0,this.buildClouds(),this.buildCirrus(),this.render())}setCloudOffset(t,e={}){this.cloudOffsetM.set(t.x,0,t.z),this.cloudLayerOffsetsM=e,this.layeredClouds?.setOffsets(t,e),this.cloudFieldOffset.set(t.x*Nu,0,t.z*Nu);for(const i of[this.cloudUniforms,this.cirrusUniforms])i?.fieldOffset.value.copy(this.cloudFieldOffset);this.iceHalos?.setCloudOffset(this.layeredClouds?.cirrusMask?.offset??this.cloudFieldOffset)}setObserverPose(t){const e=((t.rollDeg??0)+this.gaitOffset.rollDeg)*ji,i=(t.pitchDeg+this.lookPitchDeg+this.gaitOffset.pitchDeg)*ji;if(t.headingDeg!==void 0?this.camera.rotation.set(i,-(t.headingDeg+this.lookYawDeg+this.gaitOffset.yawDeg)*ji,e,"YXZ"):this.camera.rotation.set(i,this.camera.rotation.y,e,"YXZ"),t.elevationM!==this.observerElevationM&&(this.observerElevationM=t.elevationM,this.syncCloudLayer(),Math.abs(tg(t.elevationM)-this.groundRadius)>1&&(this.buildGround(),this.celestialGroup.scale.setScalar(this.groundRadius/ko),this.camera.far=Math.max(ml*1.2,this.groundRadius*2.5),this.camera.updateProjectionMatrix())),this.terrainMesh&&this.terrainOrigin&&t.lat!==void 0&&t.lng!==void 0){const n=je(this.terrainOrigin.lat,this.terrainOrigin.lng,t.lat,t.lng);this.terrainMesh.position.x=n.x,this.terrainMesh.position.z=n.z}this.poseCameraY=this.groundYUnder(0,0)+1.6+t.elevationM,this.camera.position.y=this.poseCameraY,this.celestialGroup.position.y=this.camera.position.y,this.camera.fov!==t.fovDeg&&(this.camera.fov=t.fovDeg,this.camera.updateProjectionMatrix(),this.updateCompassScale())}setTerrainProviders(t){this.stopTerrainFade(),this.terrainProviders=t,this.disposeMesh(this.terrainMesh),this.terrainMesh=void 0,this.terrainOrigin=void 0,this.terrainAttribution=void 0,this.roadSystem.clear(),this.roadAttribution=void 0,this.roadWays=void 0,this.applyGroundDepthWrite(),this.terrainBuildToken++}setTerrainOrigin(t,e,i){if(t===void 0||e===void 0)return;const n=this.groundRadius;if(this.terrainOrigin&&Math.abs(this.terrainRadius-n)<n*.1){const{x:c,z:l}=je(t,e,this.terrainOrigin.lat,this.terrainOrigin.lng);if(Math.sqrt(c*c+l*l)<NE*(n/ko))return}const s=this.terrainOrigin,r=this.terrainRadius;(!s||s.lat!==t||s.lng!==e)&&(this.roadSystem.clear(),this.roadAttribution=void 0),this.terrainOrigin={lat:t,lng:e},this.terrainRadius=n;const o=++this.terrainBuildToken;this.awaitArrival(A5(t,e,this.terrainProviders,n),me.TERRAIN_PATIENCE_MS).then(({mesh:c,attribution:l,originElevationM:h})=>{if(o!==this.terrainBuildToken)return;this.setSiteElevation(h??0);const u=this.terrainMesh,d=s?je(t,e,s.lat,s.lng):void 0;u&&d&&Math.hypot(d.x,d.z)<=r&&(c.position.y=u.position.y+this.groundYOfPatch(u,d.x,d.z)),u&&d&&Math.hypot(d.x,d.z)<=r?this.crossfadeTerrain(c,u):this.disposeMesh(this.terrainMesh),c.renderOrder=OE,this.terrainMesh=c,this.compileNextFrameOffThread(),this.terrainAttribution=l,this.scene.add(c),this.applyGroundDepthWrite(),this.decorCurrentPose&&(this.setObserverPose(this.decorCurrentPose),this.updateDecorAnchoring(this.decorReferencePose,this.decorCurrentPose,this.decorTime)),this.buildRoads(t,e,n),this.drapeStatedRoads(),this.drapeTraces(),this.render(),i?.()}).catch(c=>{console.warn("Terrain build failed, keeping the flat ground fallback:",c),i?.()})}static TERRAIN_CROSSFADE_MS=1200;fadingTerrain;crossfadeTerrain(t,e){this.stopTerrainFade();const i=t.material;i.opacity=0,i.polygonOffset=!0,i.polygonOffsetFactor=-1,i.polygonOffsetUnits=-4;const n=performance.now(),s=()=>{const r=Math.min(1,(performance.now()-n)/me.TERRAIN_CROSSFADE_MS);if(i.opacity=r*r*(3-2*r),this.render(),r<1&&this.fadingTerrain){this.fadingTerrain.frameId=requestAnimationFrame(s);return}i.polygonOffset=!1,i.opacity=1,this.fadingTerrain&&this.disposeMesh(this.fadingTerrain.mesh),this.fadingTerrain=void 0,this.render()};this.fadingTerrain={mesh:e,frameId:requestAnimationFrame(s)}}stopTerrainFade(){if(!this.fadingTerrain)return;cancelAnimationFrame(this.fadingTerrain.frameId),this.disposeMesh(this.fadingTerrain.mesh),this.fadingTerrain=void 0;const t=this.terrainMesh?.material;t&&(t.opacity=1,t.polygonOffset=!1)}static ROADS_MAX_RADIUS_M=5e3;buildRoads(t,e,i){const n=this.terrainProviders.roads;if(!n||i>me.ROADS_MAX_RADIUS_M){this.roadSystem.clear(),this.roadAttribution=void 0;return}const s=this.roadWays;if(s&&s.lat===t&&s.lng===e&&s.radiusM===i){this.drapeRoads(s.ways,t,e,n.contemporary);return}this.awaitArrival(n.getRoads(lv(t,e,i)),me.ROADS_PATIENCE_MS).then(r=>{this.terrainOrigin?.lat!==t||this.terrainOrigin?.lng!==e||(this.roadWays={lat:t,lng:e,radiusM:i,ways:r},this.drapeRoads(r,t,e,n.contemporary))}).catch(r=>{console.warn("Roads unavailable, drawing none:",r)})}setStatedRoads(t){t!==this.statedRoads&&(this.statedRoads=t,this.drapeStatedRoads(),this.render())}drapeStatedRoads(){const t=this.terrainMesh;t&&(this.roadSystem.group.position.copy(t.position),this.roadSystem.setStated(this.statedRoads,(e,i)=>this.groundYOfPatch(t,e,i)))}setTraces(t,e=new Map){t===this.traces&&e===this.traceLabels||(this.traces=t,this.traceLabels=e,!(t.length===0&&!this.traceSystem)&&this.loadTraceSystem().then(()=>{this.drapeTraces(),this.render()}))}setTracesShown(t){t!==this.tracesShown&&(this.tracesShown=t,this.drapeTraces(),this.render())}loadTraceSystem(){return this.traceSystemLoading??=$i(async()=>{const{TraceSystem:t}=await import("./TraceSystem-DEXV4-2W.js");return{TraceSystem:t}},[],import.meta.url).then(({TraceSystem:t})=>{const e=new t(Du);this.scene.add(e.group),this.traceSystem=e})}drapeTraces(){const t=this.traceSystem,e=this.terrainMesh,i=this.terrainOrigin;!t||!e||!i||(t.group.position.copy(e.position),t.set(this.tracesShown?this.traces:[],this.traceLabels,i.lat,i.lng,this.siteElevationM,(n,s)=>this.groundYOfPatch(e,n,s)))}drapeRoads(t,e,i,n){const s=this.terrainMesh;s&&(this.roadSystem.group.position.copy(s.position),this.roadSystem.set(t,e,i,(r,o)=>this.groundYOfPatch(s,r,o),n),this.roadAttribution=t.length>0?this.terrainProviders.roads?.attribution:void 0,this.compileNextFrameOffThread(),this.render())}setShowCompass(t){this.showCompass!==t&&(this.showCompass=t,this.disposeCompassLabels(),t&&this.buildCompassLabels(),this.render())}setCompassPoints(t){this.compassPoints!==t&&(this.compassPoints=t,this.showCompass&&(this.disposeCompassLabels(),this.buildCompassLabels(),this.render()))}compassPoints;applyLensFlareTint(t){if(!this.lensFlare)return;const e=FE*(this.sunArriving[1]/kE);this.lensFlare.uniforms.uColorGain.value.setRGB(e*t[0],e*t[1],e*t[2]),this.applyDazzleStrength()}applyDazzleStrength(){if(!this.lensFlare)return;const[t,e,i]=this.sunArriving,n=Math.max(e,1e-30);this.lensFlare.uniforms.uDazzleColour.value.setRGB(t/n,1,i/n),this.lensFlare.uniforms.uVeilStrength.value=Ni.K*e*this.sunUnhiddenFraction}sunArriving=[0,0,0];setCompassHovered(t){this.compassHovered!==t&&(this.compassHovered=t,this.updateCompassVisibility())}setCompassForced(t){this.compassForced!==t&&(this.compassForced=t,this.updateCompassVisibility())}updateCompassVisibility(){const t=this.compassHovered||this.compassForced;if(this.compassSprites.some(e=>e.visible!==t)){for(const e of this.compassSprites)e.visible=t;this.developingExposure?this.exposureInstantsDone>0&&this.presentExposure():this.render()}}setWeather(t){if(ME(this.weather,t))return;this.cloudTransmissionMemo.clear();const e=this.weather;this.weather=t;const i=!$E(e,t),n=e.precipitationType!==t.precipitationType,s=e.precipitationIntensity!==t.precipitationIntensity||e.precipitationAmount!==t.precipitationAmount;(e.relativeHumidity!==t.relativeHumidity||n||s)&&(this.air=In.of(t),this.applyAir(),this.scatteredSky?.setConditions({aerosolOpticalDepth:t.relativeHumidity===void 0?void 0:ur.steppedOpticalDepth(t.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=t.storm&&t.cloudDarkness>=tA,this.syncAnimationLoop(),this.render()}setDecor(t){if(this.decorObjects!==t){this.decorObjects=t,this.decorModelToken++,this.decorModelCredits.clear(),this.pendingTrafficModels.clear();for(const e of this.decorGroups.values())e.removeFromParent(),oi.dispose(e);this.decorGroups.clear(),this.streetlightLights.clear();for(const e of t){const i=oi.build(e,e.lit??!1);this.scene.add(i),this.decorGroups.set(e.id,i),e.kind==="streetlight"&&this.addStreetlightLight(e.id,i),e.model&&e.id.startsWith(Cn.ID_PREFIX)?(this.pendingTrafficModels.set(e.id,e),this.awaitArrival(this.loadDecorModel(e,this.decorModelToken,!0))):this.reuseLoadedDecorModel(e,i)||this.awaitArrival(this.loadDecorModel(e,this.decorModelToken))}this.celestialLight.castShadow=this.decorGroups.size>0||this.bodySystem.any}}setDecorSunlight(t){this.decorSunlight=t}setContrails(t){t!==this.contrails&&(this.contrails=t,!(t.length===0&&!this.contrailSystem)&&this.loadContrailSystem().then(()=>{this.contrailSystem?.set(this.contrails),this.updateContrails(),this.render()}))}setContrailSunlight(t){this.contrailSunlight=t}loadContrailSystem(){return this.contrailSystemLoading??=$i(async()=>{const{ContrailSystem:t}=await import("./ContrailSystem-CQsI1Z1v.js");return{ContrailSystem:t}},__vite__mapDeps([0,1]),import.meta.url).then(({ContrailSystem:t})=>{const e=new t;this.scene.add(e.group),this.contrailSystem=e})}contrailTint(t){const e=this.contrailSunlight.get(t),i=this.lastAstronomy?.sun,n=me.CONTRAIL_SCATTERING,s=this.skyLight.color,r=[s.r*n*.5,s.g*n*.5,s.b*n*.5];if(e&&i){const o=vn.litFraction(e.sunElevationDeg,e.heightM);if(o>0){const c=this.air.transmittanceFromSpace(e.heightM,e.sunElevationDeg),l=ue.illuminanceOf(i.magnitude)*this.relativeScale;for(let h=0;h<3;h++)r[h]+=n*l*c[h]*o}}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()},t=>this.contrailTint(t))}contrailPixelRad(){const t=Math.max(1,this.renderer.getDrawingBufferSize(this.bloomSize).y);return Math.max(this.lampBloomRadiusRad()??0,this.camera.fov*Math.PI/180/t)}setDecorPresence(t){this.decorPresence=t}setDecorModelProvider(t){this.decorModelProvider=t;const e=this.decorObjects;this.decorObjects=[],this.setDecor(e)}get currentDecorModelCredits(){return[...this.decorModelCredits.values(),...this.bodySystem.modelCredits]}get bodyGround(){const{x:t,z:e}=this.bodyOrigin,i=this.groundYUnder(t,e);return{heightAt:(n,s)=>this.groundYUnder(t+n,e-s)-i}}setBodies(t,e=0,i=t.map(r=>r.id),n=[],s){const{x:r,z:o}=this.bodyOrigin,c=this.scatteredSky;this.bodySystem.set(t,{originX:r,originZ:o,originGroundY:this.groundYUnder(r,o),eye:this.camera.position,groundYAt:(h,u)=>this.groundYUnder(h,u),wind:s,light:this.plumeLight(),occluders:[...this.decorGroups.values()],transmittance:(h,u,d)=>this.transmittanceTo(h,u,d)},e,c?(h,u)=>c.relativeOfLuminance(h,u):void 0,i),this.bodySystem.setSmoke(n,e),this.bodySystem.any&&(this.celestialLight.castShadow=!0),this.fitShadowToBodies();const l=this.bodySystem.furthestFrom(this.camera.position)*1.2;l>this.camera.far&&(this.camera.far=l,this.camera.updateProjectionMatrix())}plumeLight(){const t=this.celestialLight.color,e=this.celestialLight.intensity*.5,i=this.skyLight.color,n=this.skyLight.groundColor,s=this.skyLight.intensity,r=(o,c,l)=>(o*e+(c+l)/2*s)/Math.PI;return[r(t.r,i.r,n.r),r(t.g,i.g,n.g),r(t.b,i.b,n.b)]}bodyOutline(t,e){return this.bodySystem.outlineOf(t,e)}documentUrl;modelUrl(t){return t.url?this.documentRelative(t.url):void 0}documentRelative(t){if(t.startsWith("data:"))return t;const e=this.documentUrl??(typeof location>"u"?void 0:location.href);return e?new URL(t,e).href:t}async loadBodyModel(t){const e=t.url?void 0:t.id?await this.decorModelProvider.entry(t.id):void 0,i=this.modelUrl(t)??e?.url,n=t.credit??e?.credit;if(!(!i||!n))return{scene:await Tu(i),credit:n,headingOffsetDeg:t.headingOffsetDeg??e?.headingOffsetDeg}}loadedDecorModels=new Map;reuseLoadedDecorModel(t,e){const i=this.loadedDecorModels.get(t.id);return!i||i.ref!==JSON.stringify(Zu(t))||!oi.usesModel(t)?!1:(this.applyLoadedDecorModel(t,e,i),!0)}applyLoadedDecorModel(t,e,i){const n=i.scene.clone(!0);n.traverse(s=>{s instanceof bt&&(s.userData.sharedModel=!0)}),oi.applyModel(e,t,n,{headingOffsetDeg:i.headingOffsetDeg,depictedSizeM:i.depictedSizeM}),this.decorModelCredits.set(t.id,i.credit)}standInScenes=new Map;async loadDecorModel(t,e,i=!1){const n=i?Og[t.kind]:Zu(t);if(!(!n||!oi.usesModel(t)))try{const s=n.url?void 0:n.id?await this.decorModelProvider.entry(n.id):void 0,r=this.modelUrl(n)??s?.url,o=n.credit??s?.credit;if(!r||!o)return;const c=i?await this.standInScene(r):await Tu(r);if(e!==this.decorModelToken||i&&!this.pendingTrafficModels.has(t.id))return;const l=this.decorGroups.get(t.id);if(!l)return;i||sn.reflectOn(c);const h={ref:JSON.stringify(n),scene:c,headingOffsetDeg:n.headingOffsetDeg??s?.headingOffsetDeg,depictedSizeM:s?.sizeM,credit:o};i||this.loadedDecorModels.set(t.id,h),this.applyLoadedDecorModel(t,l,h),this.render()}catch(s){console.warn(`Keeping the built-in shape for decor "${t.id}":`,s)}}standInScene(t){let e=this.standInScenes.get(t);return e||(e=Tu(t).then(i=>(sn.reflectOn(i),i)),this.standInScenes.set(t,e)),e}updateDecorAnchoring(t,e,i=0){this.decorReferencePose=t,this.decorCurrentPose=e,this.decorTime=i;const n=t?.lat!==void 0&&t.lng!==void 0&&e?.lat!==void 0&&e?.lng!==void 0?je(t.lat,t.lng,e.lat,e.lng):{x:0,z:0},s=this.decorObjects.find(l=>l.observerSide!==void 0&&Lg(l.kind));if(this.terrainMesh&&this.terrainOrigin&&e?.lat!==void 0&&e.lng!==void 0){const l=je(this.terrainOrigin.lat,this.terrainOrigin.lng,e.lat,e.lng);this.terrainMesh.position.x=l.x-(s?0:this.gaitOffset.eastM),this.terrainMesh.position.z=l.z+(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 o=0;if(s){const l=oi.occupantView(s),h=-(s.headingDeg??0)*ji,u=l.x*Math.cos(h)+l.z*Math.sin(h),d=-l.x*Math.sin(h)+l.z*Math.cos(h),f=s.eastM+n.x,p=-s.northM+n.z;r.x=-(f+u),r.z=-(p+d),this.camera.position.y=this.groundYUnder(f,p)+l.eyeY,this.camera.rotation.set(this.indoorLookPitchDeg*ji,-(l.headingDeg+this.indoorLookYawDeg)*ji,0,"YXZ")}this.bodyOrigin={x:n.x+r.x,z:n.z+r.z},this.placeShadowFrustum();for(const l of this.decorObjects){const h=this.decorGroups.get(l.id);if(!h)continue;const u=Zo(l,i),d=u.eastM+n.x+r.x,f=-u.northM+n.z+r.z,p=this.terrainMesh,v=`${p?.geometry.uuid}:${(d-(p?.position.x??0)).toFixed(3)}:${(f-(p?.position.z??0)).toFixed(3)}:${(p?.position.y??0).toFixed(3)}:${u.headingDeg}:${u.altitudeM}`;if(h.userData.footprintKey!==v&&(h.userData.footprintGroundY=this.groundUnderFootprint(l,d,f,u.headingDeg,u.altitudeM),h.userData.footprintKey=v),h.position.set(d,h.userData.footprintGroundY+u.altitudeM,f),l.kind==="crop"){const x=Math.hypot(d,f);h.visible=x<=BE}const m=this.decorPresence.get(l.id),g=m!==void 0&&(i<m.fromMs||i>m.untilMs);m&&(h.visible=!g);const S=this.decorSunlight.get(l.id);if(S&&!g&&this.lightFromAbove(h,S),u.headingDeg!==void 0&&(h.rotation.y=-u.headingDeg*ji),l.kind==="crop"&&h.visible){const x=this.terrainMesh,M=[x?.geometry.uuid,d-(x?.position.x??0),f-(x?.position.z??0),h.position.y-(x?.position.y??0),u.headingDeg,u.altitudeM].map(b=>typeof b=="number"?b.toFixed(4):b).join(":");h.userData.cropGroundKey!==M&&(oi.fitCropToGround(h,(b,w)=>this.groundYUnder(b,w)+u.altitudeM),h.userData.cropGroundKey=M)}if(!g){const x=h.position.distanceTo(this.camera.position);o=Math.max(o,x),x<me.trafficModelRangeM(l)&&this.pendingTrafficModels.delete(l.id)&&this.loadDecorModel(l,this.decorModelToken)}}this.updateContrails();const c=Math.max(ml*1.2,this.groundRadius*2.5,o*1.2);Math.abs(this.camera.far-c)>1&&(this.camera.far=c,this.camera.updateProjectionMatrix())}groundYUnder(t,e){const i=this.terrainMesh;return i?i.position.y+this.groundYOfPatch(i,t-i.position.x,e-i.position.z):zu}groundYOfPatch(t,e,i){const n=t.geometry.getAttribute("position"),s=Math.round(Math.sqrt(n.count));if(s<2||s*s!==n.count)return zu;const r=n.getX(0),o=n.getX(s-1),c=n.getZ(0),l=n.getZ((s-1)*s),h=Na((e-r)/(o-r)*(s-1),0,s-1),u=Na((i-c)/(l-c)*(s-1),0,s-1);if(!Number.isFinite(h)||!Number.isFinite(u))return zu;const d=Math.min(Math.floor(h),s-2),f=Math.min(Math.floor(u),s-2),p=h-d,v=u-f,m=(b,w)=>n.getY(b*s+w),g=m(f,d),S=m(f,d+1),x=m(f+1,d),M=m(f+1,d+1);return p+v<=1?g+(S-g)*p+(x-g)*v:M+(x-M)*(1-p)+(S-M)*(1-v)}groundUnderFootprint(t,e,i,n,s=0){return oi.groundUnderFootprint(t,e,i,n,(r,o)=>this.groundYUnder(r,o),s)}lookYawDeg=0;lookPitchDeg=0;poseCameraY=1.6;setGait(t){this.gaitOffset=t}gaitOffset={eastM:0,northM:0,upM:0,rollDeg:0,pitchDeg:0,yawDeg:0};setLookOffset(t,e){this.lookYawDeg=t,this.lookPitchDeg=e}indoorLookYawDeg=0;indoorLookPitchDeg=0;setIndoorLook(t,e){this.indoorLookYawDeg=t,this.indoorLookPitchDeg=e}medium;setMedium(t,e,i,n){const s=t&&e!==void 0&&e>0&&i!==void 0&&i>0?{kind:t.kind,iso:n??t.iso,autoExposure:t.autoExposure===!0,exposureSeconds:e,fNumber:i}:void 0;JSON.stringify(s)!==JSON.stringify(this.medium)&&(this.medium=s,this.render())}applyMedium(){const t=this.medium,e=Math.max(this.relativeScale,1e-30);if(!t){Yi.uMedium.value=0;return}Yi.uMedium.value=t.kind==="negative"?1:t.kind==="slide"?2:3;const i=t.autoExposure?this.scatteredSky?.sceneAdaptation:void 0;Yi.uMediumExposure.value=i!==void 0&&i>0?1/(e*i):.065*t.exposureSeconds*t.iso/(t.fNumber*t.fNumber*e)}grain;lampBloomRadiusRad(){if(!this.grain)return;const t=this.camera.fov*Math.PI/180,e=this.grain.frameHeightMm/(2*Math.tan(t/2)),i=Math.max(1,this.renderer.getDrawingBufferSize(this.bloomSize).y);return Math.max(this.grain.detailUm*.001/e,t/i)}bloomSize=new Mt;lampTransmittance(t){const e=this.siteElevationM+this.camera.position.y,i=this.siteElevationM+t.position.y;return this.air.transmittance(e,i,t.position.distanceTo(this.camera.position))}updateDecorLitState(t,e=0){const i=this.lampBloomRadiusRad();for(const n of this.decorObjects){const s=this.decorGroups.get(n.id);if(s&&n.lights?.length&&oi.setLights(s,n.lights,t,s.position.distanceTo(this.camera.position),e,this.relativeScale,i,this.lampTransmittance(s)),n.kind!=="streetlight"&&n.kind!=="vehicle")continue;const r=this.decorGroups.get(n.id);if(!r)continue;const o=Nv(n,t);oi.setLit(r,n.kind,o,this.relativeScale);const c=this.streetlightLights.get(n.id);c&&(c.visible=o)}}addStreetlightLight(t,e){const i=oi.bodyOf(e),n=i.children.find(r=>r.userData.emissive);if(!n)return;const s=new I1(16764006,ig*this.relativeScale,DE);s.position.copy(n.position).multiply(i.scale),s.castShadow=!0,s.shadow.mapSize.set(512,512),s.shadow.bias=-.002,e.add(s),this.streetlightLights.set(t,s)}setAstronomy(t){(!this.lastAstronomy||Math.abs(this.lastAstronomy.sun.altitudeDeg-t.sun.altitudeDeg)>2)&&(this.surroundings=void 0,this.scatteredSky?.resetSurroundings()),this.lastAstronomy=t,this.scatteredSky?.update(this.scatteredSkyState(t)),this.skyHoldUntilMs===void 0&&this.startHold(),this.pumpScatteredSky(),this.lastSunPosition=t.sun,this.buildSky(t.sun),this.buildGround();const e=this.magnitudeLimitOf(t);this.buildStars(t.stars,e),this.placeBodies(t,e),this.buildIceHalos(t.sun,t.moon),this.buildRainbow(t.sun,t.moon),this.applySkyColours(t),this.syncAnimationLoop(),this.render()}static relativeSkyOf(t,e){const i=r=>{const o=$n.luminanceOf(r);if(!(o>0))return[0,0,0];const c=Et.relativeOfResponse(o)/o;return[r[0]*c,r[1]*c,r[2]*c]},n=i(t.zenith),s=i(t.horizon);return{zenith:n,horizon:s,airlight:s,skyIrradiance:[n[0]*Math.PI,n[1]*Math.PI,n[2]*Math.PI],scale:e}}placeBodies(t,e){this.bodiesScale=this.relativeScale,this.setBodyMesh("sun",t.sun,Do,new st(1,.96,.88),t.sun.magnitude),this.setMoonMesh(t.moon,e),this.buildPlanets(t.planets,e),this.buildComet(t.comet,e),this.buildNovae(t.novae??[],e)}bodiesScale=0;applySkyColours(t){this.skyColoursStale=!1,this.bodiesScale!==this.relativeScale&&(this.placeBodies(t,this.magnitudeLimitOf(t)),this.applyDazzleStrength(),this.buildIceHalos(t.sun,t.moon),this.buildRainbow(t.sun,t.moon));const e=this.scatteredSky?.ambient??me.relativeSkyOf(Qd(t.sun.altitudeDeg),this.relativeScale),i=e,n=this.lightUnderClouds(t),s=r=>n?[0,1,2].map(o=>r[o]*n.through+n.radiance[o]*(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(t,e),this.updateCloudLighting(t.sun,this.baseFogColor),Dt.setEye(this.scatteredSky?.rodShare??0,this.relativeScale),this.updateTwinkle(this.twinkleSeconds);for(const r of this.streetlightLights.values())r.intensity=ig*this.relativeScale;this.buildSkyGlow(t,i.zenith),this.applyAir(),this.buildLunarDiffraction(t.moon)}reflections;sceneVersion=0;reflectionTimer;buildLunarDiffraction(t){const e=this.scatteredSky?.ready?this.scatteredSky:void 0;if(t.altitudeDeg<-.5||!e){this.lunarDiffraction?.show(void 0),this.lunarDiffractionKey="";return}const i=this.weather.relativeHumidity,n=(i===void 0?Ut.DEFAULT_AEROSOL_OPTICAL_DEPTH:ur.opticalDepth(i))*Ut.aerosolDensity(this.siteElevationM+this.observerElevationM),s=this.cloudTransmission(t),r=-Math.log(Math.max(this.cloudTransmission(t,!0),1e-4)),o=ue.aureoleScale(n,ue.airMass(t.altitudeDeg))*s,c=ue.coronaScale(r),l=ue.illuminanceOf(t.magnitude),h=[t.altitudeDeg.toFixed(1),t.azimuthDeg.toFixed(1),t.magnitude.toFixed(2),o.toExponential(2),c.toExponential(2),Math.log10(Math.max(e.adaptation,1e-12)).toFixed(2)].join(":");if(h===this.lunarDiffractionKey)return;this.lunarDiffractionKey=h,this.lunarDiffraction||(this.lunarDiffraction=new ff,this.celestialGroup.add(this.lunarDiffraction.object));const u=ue.profile(ue.HAZE_COARSE_MODE),d=ue.profile(ue.CLOUD_DROPLETS),f=_m(t.altitudeDeg),p=new Float32Array(ue.STEPS*3);let v=0;for(let x=0;x<ue.STEPS;x++){const M=x*3,b=[0,1,2].map(T=>l*f[T]*(o*u[M+T]+c*d[M+T])),w=$n.shown(b,$n.luminanceOf(b),(T,y)=>e.relativeOfLuminance(T,y));p.set(w,M),v=Math.max(v,$n.response(w))}const{x:m,y:g,z:S}=Ze(t.altitudeDeg,t.azimuthDeg,1);this.lunarDiffraction.show(v>1/200?{x:m,y:g,z:S}:void 0,p)}applyAir(){this.scene.fog instanceof Vr||(this.scene.fog=new Vr),this.scene.fog.setAir(this.air,this.siteElevationM,this.airlight)}airlight=[0,0,0];transmittanceTo(t,e,i){const n=this.camera.position;return this.air.transmittance(this.siteElevationM+n.y,this.siteElevationM+e,Math.hypot(t-n.x,e-n.y,i-n.z))}setSiteElevation(t){Math.abs(t-this.siteElevationM)<1||(this.siteElevationM=t,this.applyAir(),this.lastAstronomy&&this.scatteredSky?.update(this.scatteredSkyState(this.lastAstronomy)))}scatteredSkyState(t){return{altitudeM:this.siteElevationM+this.observerElevationM+1.6,lightPollution:this.lightPollution,sun:{altitudeDeg:t.sun.altitudeDeg,azimuthDeg:t.sun.azimuthDeg,magnitude:t.sun.magnitude},moon:{altitudeDeg:t.moon.altitudeDeg,azimuthDeg:t.moon.azimuthDeg,magnitude:t.moon.magnitude,phaseAngleDeg:xt.phaseAngleOf(t.moon.phase.illuminatedFraction)}}}pumpScatteredSky(){const t=this.scatteredSky;!t||t.tables.ready||this.scatteredSkyFrameId!==null||this.contextReleased||this.suspended||(this.scatteredSkyFrameId=requestAnimationFrame(()=>{this.scatteredSkyFrameId=null,!this.contextReleased&&(t.advance(this.skyHoldUntilMs?PE:CE),this.pumpScatteredSky())}))}cancelScatteredSkyPump(){this.scatteredSkyFrameId!==null&&(cancelAnimationFrame(this.scatteredSkyFrameId),this.scatteredSkyFrameId=null)}setSatellites(t){if(t.length===0&&!this.satelliteField?.count)return;this.satelliteField||(this.satelliteField=new V5(Cu),this.celestialGroup.add(this.satelliteField.object));const e=this.lastAstronomy?this.magnitudeLimitOf(this.lastAstronomy):Ll(-90,this.instrumentMagnitudeGain);this.satelliteField.set(t,e,i=>this.cloudTransmission(i),(i,n)=>this.arrivingIlluminance(i,n,1)),this.render()}setReentries(t){if(t.length===0&&!this.reentrySystem?.count)return;this.reentrySystem||(this.reentrySystem=new Qi,this.celestialGroup.add(this.reentrySystem.object));const e=this.lastAstronomy?this.magnitudeLimitOf(this.lastAstronomy):Ll(-90,this.instrumentMagnitudeGain);this.reentrySystem.set(t,e,i=>this.cloudTransmission(i),(i,n)=>this.arrivingIlluminance(i,n,1)),this.render()}get reentryCount(){return this.reentrySystem?.count??0}pickTrafficAt(t,e){this.aimAtScreenPoint(this.raycaster,t,e);const i=this.raycaster.ray.direction,n=Math.cos(Pu*this.camera.fov*Math.PI/180);let s,r=n;const o=new R;for(const[c,l]of this.decorGroups){if(!l.visible||!c.startsWith(Cn.ID_PREFIX))continue;o.copy(l.position).sub(this.camera.position).normalize();const h=o.dot(i);h>r&&(r=h,s=c)}return s&&!this.groundHides(t,e)?s:void 0}pickSatelliteAt(t,e){if(!this.satelliteField?.count)return;this.aimAtScreenPoint(this.raycaster,t,e);const i=Math.cos(Pu*this.camera.fov*Math.PI/180),n=this.satelliteField.nearest(this.raycaster.ray.direction,i);return n&&this.groundHides(t,e)?void 0:n}updateCelestialLight(t,e){const i=this.relativeScale,n=t.sun.altitudeDeg>=vl,s=!n&&t.moon.altitudeDeg>=vl,r=n?t.sun:t.moon,o=[0,0,0],c=Math.max(0,Math.sin(Math.max(r.altitudeDeg,0)*ji)),l=n||s?this.cloudTransmission(r):1,h=-Math.log(Math.max(l,1e-6)),u=Math.max(0,1/(1+.1125*h)-l),d=[0,0,0];if(n||s){const S=ue.illuminanceOf(r.magnitude)*i,x=this.air.transmittanceFromSpace(this.siteElevationM+this.observerElevationM,r.altitudeDeg);for(let T=0;T<3;T++)o[T]=S*x[T]*l,d[T]=S*x[T]*u*c,this.cloudBeam[T]=S*x[T];const{x:M,y:b,z:w}=Ze(r.altitudeDeg,r.azimuthDeg,1);this.cloudBeamDirection.set(M,b,w)}else this.cloudBeam.fill(0);const f=this.surroundings;if(f)this.skyLight.color.setRGB(f.up[0]*i,f.up[1]*i,f.up[2]*i),this.skyLight.groundColor.setRGB(f.down[0]*i,f.down[1]*i,f.down[2]*i);else{const S=this.skyCloudTransmission(),x=e.skyIrradiance,M=[0,1,2].map(w=>x[w]*S+d[w]);this.skyLight.color.setRGB(M[0],M[1],M[2]);const b=Yt.GROUND_ALBEDO;this.skyLight.groundColor.setRGB(b*(M[0]+o[0]*c),b*(M[1]+o[1]*c),b*(M[2]+o[2]*c))}if(this.skyLight.intensity=1,this.sceneSunBeam=n?[o[0],o[1],o[2]]:[0,0,0],!n&&!s){this.celestialLight.intensity=0;return}const{x:p,y:v,z:m}=Ze(r.altitudeDeg,r.azimuthDeg,1);this.lightDirection.set(p,v,m),this.placeShadowFrustum();const g=Math.max(o[0],o[1],o[2],1e-30);this.celestialLight.color.setRGB(o[0]/g,o[1]/g,o[2]/g),this.celestialLight.intensity=g,this.celestialLight.castShadow=this.decorGroups.size>0||this.bodySystem.any}static MEAN_COSINE=.5;static ABOVE_CLOUD_M=8e3;lightFromAbove(t,e){const i=this.lastAstronomy?.sun,n=[0,0,0];if(i){const s=vn.litFraction(e.sunElevationDeg,e.heightM);if(s>0){const r=this.air.transmittanceFromSpace(e.heightM,e.sunElevationDeg),o=ue.illuminanceOf(i.magnitude)*this.relativeScale,c=e.heightM>=me.ABOVE_CLOUD_M?1:this.cloudTransmission(i);for(let l=0;l<3;l++)n[l]=Math.max(0,o*r[l]*s*c-this.sceneSunBeam[l])}}t.traverse(s=>{const r=s.material;if(!(r instanceof qr||r instanceof ar)||s.userData.emissive)return;r.map&&!r.emissiveMap&&(r.emissiveMap=r.map,r.needsUpdate=!0);const o=me.MEAN_COSINE/Math.PI;r.emissive.setRGB(r.color.r*n[0]*o,r.color.g*n[1]*o,r.color.b*n[2]*o)})}lightDirection=new R(0,1,0);placeShadowFrustum(){const t=this.lightDirection,e=this.celestialLight.shadow.camera,i=(e.right-e.left)/this.celestialLight.shadow.mapSize.x,n=this.shadowAxisX.crossVectors(this.shadowUp,t);n.lengthSq()<1e-8&&n.set(1,0,0),n.normalize();const s=this.shadowAxisY.crossVectors(t,n).normalize(),r=this.shadowWorld.set(this.bodyOrigin.x,0,this.bodyOrigin.z),o=l=>{const h=r.dot(l)/i;return(h-Math.round(h))*i},c=this.celestialLightTarget.position.set(0,0,0).addScaledVector(n,o(n)).addScaledVector(s,o(s));this.celestialLightTarget.updateMatrixWorld(),this.celestialLight.position.copy(c).addScaledVector(t,this.shadowLightDistanceM)}fitShadowToBodies(){const t=this.bodySystem.reachFrom(this.camera.position),e=Math.min(_E,Math.max(js,Math.ceil(t*1.25/20)*20));if(e===this.shadowHalfExtentM)return;this.shadowHalfExtentM=e;const i=this.celestialLight.shadow,n=i.camera;n.left=-e,n.right=e,n.top=e,n.bottom=-e;const s=Math.max(Ro,e*(Ro/js));this.shadowLightDistanceM=Math.max(un,s+10),n.near=this.shadowLightDistanceM-s,n.far=this.shadowLightDistanceM+s,n.updateProjectionMatrix(),i.bias=-.03/(2*s);const r=e>2*js?2048:1024;i.mapSize.x!==r&&(i.mapSize.set(r,r),i.map?.dispose(),i.map=null),this.placeShadowFrustum()}shadowHalfExtentM=js;shadowLightDistanceM=un;shadowUp=new R(0,1,0);shadowAxisX=new R;shadowAxisY=new R;shadowWorld=new R;skyCloudTransmission(){let t=this.cloudTransmission({altitudeDeg:90,azimuthDeg:0}),e=1;for(const i of[20,45,70]){const n=i*ji,s=Math.sin(n)*Math.cos(n)*2;for(let r=0;r<360;r+=60)t+=s*this.cloudTransmission({altitudeDeg:i,azimuthDeg:r}),e+=s}return t/e}cloudBeam=[0,0,0];cloudBeamDirection=new R(0,1,0);get relativeScale(){return this.scatteredSky?.relativeScale??1/Et.semiSaturation(Et.DAYLIGHT_ANCHOR_CD_M2)}setMeteorShower(t,e,i){this.meteorSystem||(this.meteorSystem=new _i,this.celestialGroup.add(this.meteorSystem.object)),this.meteorSystem.setShower(t,e,i)}get meteorSchedule(){return this.meteorSystem?.schedule??[]}meteorMidpoint(t){return this.meteorSystem?.midpointOf(t)}updateMeteors(t){this.meteorSystem?.update(t)}setInstrument(t){this.projectionKind=t.projection,this.grain=t.detailUm!==void 0&&t.frame?{detailUm:t.detailUm,frameHeightMm:t.frame.heightMm}:void 0;const e=mi.starPointsOf(t),i=mi.flareArtifactsOf(t);e===this.starPoints&&i===this.lensFlareArtifactIntensity||(this.starPoints=e,this.lensFlareArtifactIntensity=i,this.lensFlare&&(this.lensFlare.uniforms.uStarPoints.value=e,this.lensFlare.uniforms.uFlareIntensity.value=i),this.render())}magnitudeLimitOf(t){const e=xt.starLossMagnitudes(t.sun.altitudeDeg,{phaseAngleDeg:xt.phaseAngleOf(t.moon.phase.illuminatedFraction),altitudeDeg:t.moon.altitudeDeg},this.lightPollution);return Ll(t.sun.altitudeDeg,this.instrumentMagnitudeGain,e)}setLightPollution(t){t!==this.lightPollution&&(this.lightPollution=t,this.lastAstronomy&&this.scatteredSky?.update(this.scatteredSkyState(this.lastAstronomy)))}setInstrumentGain(t,e=!1){this.instrumentMagnitudeGain=Number.isFinite(t)?t:0,this.scatteredSky?.setInstrument(e,this.instrumentMagnitudeGain)}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 t=this.compileOffThread().then(()=>{this.compiling===t&&(this.compiling=void 0,this.render())});this.compiling=t;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 t=this.renderer.compile(this.scene,this.camera);if(!this.renderer.extensions.get("KHR_parallel_shader_compile"))return Promise.resolve();const e=this.renderer.properties,i=performance.now()+me.COMPILE_WAIT_MS;return new Promise(n=>{const s=()=>{if(this.contextReleased)return n();for(const r of t){const o=e.get(r)?.currentProgram;(!o||o.isReady())&&t.delete(r)}t.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(t){if(this.animationsRunning){const e=this.lastFrameTimeMs===void 0?0:t-this.lastFrameTimeMs;this.lastFrameTimeMs=t,this.hasAnimations()&&this.animate(t,e);const i=this.resolution.ratioFor(t,e);i!==this.renderer.getPixelRatio()&&this.applyPixelRatio(i)}this.drawIfDirty()}refreshReflections(t=!1){this.reflections??=new sn(this.renderer);const e=[...this.compassSprites,...this.lensFlare?[this.lensFlare.mesh]:[],...[...this.glareSprites.values()].map(o=>o.mesh)],i=[...this.starTiers.map(o=>o.points),...[...this.bodyMeshes.values()].filter(o=>o instanceof mn),...[this.rainSystem?.points,this.precipitationPoints,this.rainSplashSystem?.points].filter(o=>o!==void 0)],n=this.relativeScale,s=this.sceneVersion,r=this.reflections.refresh(this.renderer,this.scene,this.camera.position,this.bodySystem.reflectors,e,[...this.decorGroups.values()],s,i,o=>this.measureSurroundings(o,n,s),t?0:sn.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(t,e,i){const n=this.lastAstronomy;if(!n)return;this.probeIrradiance??=new Xo;const s=[n.sun,n.moon].filter(r=>r.altitudeDeg>-2).map(r=>Ze(r.altitudeDeg,r.azimuthDeg,1));this.probeIrradiance.measure(this.renderer,t,s,r=>{const o=f=>f.map(p=>p/e),c=this.surroundings,l={up:o(r.up),down:o(r.down)},h=(f,p)=>f.some((v,m)=>Math.abs(v-p[m])>.03*Math.max(Math.abs(v),Math.abs(p[m]),1e-12)),u=!c||h(c.up,l.up)||h(c.down,l.down);u&&(this.surroundings=l),this.eyeSettledVersion=-1;const d=this.scatteredSky?.adaptToSurroundings(Math.exp(r.logAverage)/e)??!1;if(!u&&!d){this.eyeSettledVersion=i,this.skyHoldUntilMs&&this.redrawHeld();return}this.skyColoursStale=!0,this.render()})}lightUnderClouds(t){const e=this.surroundings;if(!e)return;const i=t.sun.altitudeDeg>=vl?t.sun:t.moon.altitudeDeg>=vl?t.moon:void 0;if(!i)return;const n=this.relativeScale/Math.PI;return{through:this.cloudTransmission(i),radiance:[e.up[0]*n,e.up[1]*n,e.up[2]*n]}}probeIrradiance;surroundings;animate(t,e){const i=Math.min(e/1e3,QE);this.twinkleSeconds=t/1e3,this.updateTwinkle(this.twinkleSeconds),this.updatePrecipitation(t/1e3,i),this.updateRain(i),this.lensFlare&&(this.lensFlare.uniforms.uTime.value=t/1e3),this.developingExposure||(this.frameDirty=!0)}setMaxPixelRatio(t){this.resolution.maximum=t,this.renderer.getPixelRatio()>this.resolution.maximum&&this.applyPixelRatio(this.resolution.maximum)}applyPixelRatio(t){this.renderer.setPixelRatio(t),this.renderer.setSize(this.cssSize.width,this.cssSize.height,!1),this.frameDirty=!0}setExposure(t,e){const i=e?Math.max(1,Math.round(t)):1;if(i===this.exposureInstants&&(i===1||e===this.exposureInstantAt)){this.exposureInstantAt=e;return}this.exposureInstants=i,this.exposureInstantAt=e,i===1&&(this.cancelExposure(),this.exposureAccumulation?.dispose(),this.exposureAccumulation=void 0),this.render()}renderOnce(t){if(this.onMapSubjectBounds){const r=this.mapSubjectBounds();t?this.exposureSubjectBounds.push(...r):this.onMapSubjectBounds(r)}const e=this.usableEquidistantPass();this.phenomena.setCloudLayers(this.layeredClouds?.volumes??[]),this.phenomena.place(this.camera,(r,o,c)=>this.directionAtScreenPoint(r,o,c),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()),Yi.uRodShare.value=this.scatteredSky?.rodShare??0,Yi.uRelativeScale.value=this.relativeScale,this.applyMedium();const n=this.references.any||this.phenomena.any||this.compassSprites.some(r=>r.visible);Yi.uHasOverlay.value=n?1:0;const s=n?r=>this.renderOverlayPasses(r):void 0;if(this.skyGlow?.setDestinationEncoded(!1),!e){this.updateLensFlarePosition();const r=this.usableDepthOfFieldPass();r?r.render(this.renderer,this.scene,this.camera,s,t):this.usableFinishPass().render(this.renderer,this.scene,this.camera,s,void 0,t);return}e.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(),t,this.pointLayerHost)}pointLayerHost={points:()=>{const t=[];return this.celestialGroup.traverse(e=>{(e instanceof mn&&e.userData.pointSource||e instanceof bt&&e.userData.skyRibbon)&&t.push(e)}),t},clouds:()=>[...this.layeredClouds?.meshes??[],...this.cloudMesh?[this.cloudMesh]:[],...this.cirrusMesh?[this.cirrusMesh]:[]],sky:this.celestialGroup};renderOverlayPasses(t=this.camera){this.renderReferencesPass(t),this.renderBodiesOverReferences(t),this.renderPhenomenaPass(t),this.renderHudPass(t)}renderHudPass(t){const e=this.traceSystem?.any&&this.tracesShown;if(!e&&!this.compassSprites.some(s=>s.visible))return;e&&this.traceSystem.setView(this.renderer.getDrawingBufferSize(this.traceResolution),t.fov);const i=this.renderer.autoClear,n=this.renderer.shadowMap.autoUpdate;this.renderer.autoClear=!1,this.renderer.shadowMap.autoUpdate=!1,t.layers.set(Du),this.renderer.render(this.scene,t),t.layers.set(0),this.renderer.autoClear=i,this.renderer.shadowMap.autoUpdate=n}renderBodiesOverReferences(t){if(!this.references.any||!this.bodySystem.any)return;const e=this.renderer.autoClear,i=this.renderer.shadowMap.autoUpdate;this.renderer.autoClear=!1,this.renderer.shadowMap.autoUpdate=!1,t.layers.set(xv),this.scene.overrideMaterial=this.bodyCutOutMaterial,this.renderer.render(this.scene,t),this.scene.overrideMaterial=null,t.layers.set(0),this.renderer.autoClear=e,this.renderer.shadowMap.autoUpdate=i}bodyCutOutMaterial=new _n({blending:dc,blendSrc:Oo,blendDst:Oo,blendSrcAlpha:Oo,blendDstAlpha:Oo,toneMapped:!1});renderReferencesPass(t){if(!this.references.any)return;const e=this.renderer.autoClear,i=this.renderer.shadowMap.autoUpdate;this.renderer.autoClear=!1,this.renderer.shadowMap.autoUpdate=!1,t.layers.set(Sv),this.renderer.render(this.scene,t),t.layers.set(0),this.renderer.autoClear=e,this.renderer.shadowMap.autoUpdate=i}setReferences(t,e){this.references.set(t.map(i=>{const n=this.documentRelative(i.src);return n===i.src?i:{...i,src:n}}),void 0,e)}referenceAspect(t){return this.references.aspectOf(t)}directionAt(t,e){return this.directionAtScreenPoint(t,e,new R)}referenceFailedToLoad(t){return this.references.failedToLoad(this.documentRelative(t))}setReferencesShown(t){this.references.setShown(t),this.render()}setReferenceView(t,e){this.references.setView(t,e),this.render()}renderPhenomenaPass(t){if(!this.phenomena.any)return;const e=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&&me.markDecorDepth(s,n.kind!=="crop")}t.layers.set(Ru),this.scene.overrideMaterial=this.decorDepthMaterial,this.renderer.render(this.scene,t),this.scene.overrideMaterial=null,t.layers.set(yv),this.renderer.render(this.scene,t),t.layers.set(0),this.renderer.autoClear=e,this.renderer.shadowMap.autoUpdate=i}decorDepthMaterial=new _n({colorWrite:!1});static markDecorDepth(t,e){t.traverse(i=>{if(!(i instanceof bt))return;const n=Array.isArray(i.material)?i.material[0]:i.material;e&&n.depthWrite!==!1&&n.blending!==Ai?i.layers.enable(Ru):i.layers.disable(Ru)})}startExposure(){this.cancelExposure(),this.exposureSubjectBounds=[];const t=this.renderer.getDrawingBufferSize(new Mt),e=Math.max(1,Math.round(t.x)),i=Math.max(1,Math.round(t.y));this.exposureAccumulation||(this.exposureAccumulation=new cw(e,i)),this.exposureAccumulation.resize(e,i),this.exposureAccumulation.open(this.renderer),this.exposureInstantsDone=0,this.exposureFrameId=requestAnimationFrame(()=>this.developExposure())}developExposure(){this.exposureFrameId=null;const t=this.exposureInstantAt,e=this.exposureAccumulation;if(!t||!e)return;const i=1/this.exposureInstants;this.resolution.beginDrawing();const n=performance.now()+me.EXPOSURE_BUDGET_MS,s=me.exposureInstantsPerFrame(e.instantTarget.scene.width*e.instantTarget.scene.height);let r=0;do{this.restateAt(t,this.exposureInstantsDone);const o=this.compassSprites.map(c=>c.visible);for(const c of this.compassSprites)c.visible=!1;try{this.renderOnce(e.instantTarget)}finally{this.compassSprites.forEach((c,l)=>{c.visible=o[l]})}e.add(this.renderer,i),this.exposureInstantsDone++,r++}while(this.exposureInstantsDone<this.exposureInstants&&performance.now()<n&&r<s);this.restateAt(t,0),this.presentExposure(),this.resolution.endDrawing(),this.exposureInstantsDone<this.exposureInstants&&(this.exposureFrameId=requestAnimationFrame(()=>this.developExposure()))}presentExposure(){if(Yi.uRodShare.value=this.scatteredSky?.rodShare??0,Yi.uHasOverlay.value=1,Yi.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 t=new ys,e=new Zn(-1,1,1,-1,0,2),i=Ml/(sg*Math.tan(rg*ji/2));for(const s of this.compassSprites){if(!s.visible)continue;const r=s.getWorldPosition(new R).sub(this.camera.position).normalize(),o=this.screenPointOf(r);if(!o)continue;const c=new go(s.material);c.position.set(o.ndcX,o.ndcY,-1),c.scale.set(i/this.camera.aspect,i,1),t.add(c)}const n=this.renderer.autoClear;this.renderer.autoClear=!1;try{this.renderer.render(t,e)}finally{this.renderer.autoClear=n}}onMapSubjectBounds;exposureSubjectBounds=[];static MAP_SUBJECT_NEAREST_M=8;mapSubjectBounds(){const t=[],e=new ki,i=new R,n=this.camera.getWorldDirection(new R),s=this.decorObjects.filter(o=>o.track?.length||o.kind==="aircraft"||o.kind==="vehicle").map(o=>this.decorGroups.get(o.id)),r=this.bodySystem.reflectors.map(o=>o.holder);for(const o of[...s,...r]){if(!o?.visible||(e.setFromObject(o),e.isEmpty())||e.distanceToPoint(this.camera.position)<me.MAP_SUBJECT_NEAREST_M)continue;let c=1/0,l=-1/0,h=1/0,u=-1/0;for(const d of[e.min.x,e.max.x])for(const f of[e.min.y,e.max.y])for(const p of[e.min.z,e.max.z]){if(i.set(d,f,p).sub(this.camera.position).normalize(),i.dot(n)<=0)continue;const v=this.screenPointOf(i);if(!v)continue;const m=(v.ndcX+1)/2,g=(1-v.ndcY)/2;c=Math.min(c,m),l=Math.max(l,m),h=Math.min(h,g),u=Math.max(u,g)}c=Math.max(c,0),l=Math.min(l,1),h=Math.max(h,0),u=Math.min(u,1),l>=c&&u>=h&&t.push({x:c,y:h,width:l-c,height:u-h})}return t}restateAt(t,e){this.restatingExposure=!0;try{t(e)}finally{this.restatingExposure=!1}}cancelExposure(){this.exposureFrameId!==null&&(cancelAnimationFrame(this.exposureFrameId),this.exposureFrameId=null)}setLensOptics(t){const e=this.lensOptics;this.lensOptics=t,(e===void 0!=(t===void 0)||e&&t&&(e.focalLengthMm!==t.focalLengthMm||e.fNumber!==t.fNumber||e.focusDistance!==t.focusDistance||e.frameHeightMm!==t.frameHeightMm))&&(t&&this.depthOfFieldPass&&this.depthOfFieldPass.setLens(t.focalLengthMm,t.fNumber,t.focusDistance,t.frameHeightMm),this.render())}usableDepthOfFieldPass(){const t=this.lensOptics;if(!t)return;const e=this.renderer.getDrawingBufferSize(new Mt),i=Math.max(1,Math.round(e.x)),n=Math.max(1,Math.round(e.y));return this.depthOfFieldPass||(this.depthOfFieldPass=new qo(i,n)),this.depthOfFieldPass.resize(i,n),this.depthOfFieldPass.setLens(t.focalLengthMm,t.fNumber,t.focusDistance,t.frameHeightMm),this.depthOfFieldPass}usableFinishPass(){const t=this.renderer.getDrawingBufferSize(new Mt);return this.finishPass?this.finishPass.resize(t.x,t.y):this.finishPass=new df(t.x,t.y),this.finishPass}usableEquidistantPass(){if(this.projectionKind!=="equidistant")return;const t=this.renderer.getDrawingBufferSize(new Mt);return this.equidistantPass?this.equidistantPass.resize(t.x,t.y):this.equidistantPass=new Be(t.x,t.y),this.equidistantPass}aimAtScreenPoint(t,e,i){const n=this.projectionKind==="equidistant"?this.equidistantPass:void 0;if(!n){t.setFromCamera(new Mt(e,i),this.camera);return}const s=n.directionFor(e,i,this.camera.fov);this.camera.updateMatrixWorld(),t.ray.origin.setFromMatrixPosition(this.camera.matrixWorld),t.ray.direction.set(s.x,s.y,s.z).applyQuaternion(this.camera.quaternion).normalize(),t.camera=this.camera}pickCloudAt(t,e){return this.layeredClouds?.pickInstance(this.cloudDirectionAt(t,e))}cloudDirectionAt(t,e){return this.directionAtScreenPoint(t,e,new R)}directionAtScreenPoint(t,e,i){return this.aimAtScreenPoint(this.ufoOcclusionRaycaster,t,e),i.copy(this.ufoOcclusionRaycaster.ray.direction)}screenPointOf(t){this.camera.updateMatrixWorld();const e=this.screenPointScratch.copy(t).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 Be.ndcFor(e,this.camera.fov,n);if(e.z>=0)return;const s=Math.tan(this.camera.fov/2*ji);return{ndcX:e.x/-e.z/(n*s),ndcY:e.y/-e.z/s}}screenPointScratch=new R;screenPointQuaternion=new on;screenPointSize=new Mt;updateLensFlarePosition(){const t=this.lensFlare;if(!t)return;if(!this.sunVisible){t.mesh.visible=!1;return}if(this.camera.updateMatrixWorld(),this.lensFlareScratch.copy(this.sunWorldPosition).applyMatrix4(this.camera.matrixWorldInverse),this.lensFlareScratch.z>0){t.mesh.visible=!1;return}const e=this.sunVisibleFraction();if(e<=0){t.mesh.visible=!1;return}t.mesh.visible=!0,this.sunUnhiddenFraction=e,this.applyDazzleStrength();const i=this.lensFlareScratch.copy(this.sunWorldPosition).project(this.camera);t.uniforms.uLensPosition.value.set(i.x,i.y);const n=this.renderer.domElement.width,s=this.renderer.domElement.height;t.uniforms.uResolution.value.set(n,s),t.uniforms.uTanHalfFov.value=Math.tan(this.camera.fov*Math.PI/360)}renderDazzleOnResample(){const t=this.lensFlare;if(!t||!this.sunVisible)return;const e=this.sunVisibleFraction();if(e<=0)return;this.sunUnhiddenFraction=e,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);t.uniforms.uLensPosition.value.set(i.ndcX,i.ndcY),t.uniforms.uResolution.value.set(n.x,n.y),t.uniforms.uEquidistant.value=1,t.uniforms.uHalfFovRad.value=this.camera.fov*Math.PI/360;const s=this.renderer.autoClear;this.renderer.autoClear=!1,t.mesh.visible=!0,t.mesh.layers.enable(jm),this.camera.layers.set(jm),this.renderer.render(this.scene,this.camera),this.camera.layers.set(0),t.mesh.visible=!1,t.uniforms.uEquidistant.value=0,this.renderer.autoClear=s}sunVisibleFraction(){this.raycastableDecor().length>0&&this.scene.updateMatrixWorld();let t=0;for(const e of og)this.isSunOccluded(e[0],e[1])||t++;return t/og.length}raycastableDecor(){const t=[];for(const e of this.decorObjects){if(e.kind==="crop")continue;const i=this.decorGroups.get(e.id);i&&t.push(i)}return t}isSunOccluded(t=0,e=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(),t!==0||e!==0){const o=Math.PI/180,c=this.sunOcclusionRightScratch.set(n.z,0,-n.x);c.lengthSq()<1e-9&&c.set(1,0,0),c.normalize();const l=this.sunOcclusionUpScratch.crossVectors(c,n).normalize();n.addScaledVector(c,t*o).addScaledVector(l,e*o).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(t,e,i,n=0){const s=this.groundMesh;if(s&&e.y<0){const m=(s.position.y-t.y)/e.y;if(m>n&&m<i){const g=t.x+e.x*m-s.position.x,S=t.z+e.z*m-s.position.z;if(Math.hypot(g,S)<=this.groundRadius)return!0}}const r=this.terrainMesh;if(!r)return!1;const o=r.geometry.getAttribute("position"),c=Math.round(Math.sqrt(o.count));if(c<2||c*c!==o.count)return!1;const l=[r.position.x+o.getX(0),r.position.x+o.getX(c-1)],h=[r.position.z+o.getZ(0),r.position.z+o.getZ((c-1)*c)],u=Math.min(Math.abs(l[1]-l[0]),Math.abs(h[1]-h[0]))/(c-1);if(!(u>0))return!1;let d=n,f=i;for(const[m,g,S]of[[t.x,e.x,l],[t.z,e.z,h]]){const x=Math.min(S[0],S[1]),M=Math.max(S[0],S[1]);if(Math.abs(g)<1e-12){if(m<x||m>M)return!1;continue}const b=(x-m)/g,w=(M-m)/g;d=Math.max(d,Math.min(b,w)),f=Math.min(f,Math.max(b,w))}if(!(f>d))return!1;const p=Math.hypot(e.x,e.z),v=Math.min(4096,Math.max(8,Math.ceil((f-d)*p/(u/2))));for(let m=0;m<=v;m++){const g=d+(f-d)*m/v,S=t.x+e.x*g,x=t.y+e.y*g,M=t.z+e.z*g;if(x<=this.groundYUnder(S,M))return!0}return!1}setPhenomena(t,e){this.phenomena.set(t,e)}decorDistancesAt(t,e,i){this.aimAtScreenPoint(this.ufoOcclusionRaycaster,t,e),this.ufoOcclusionRaycaster.near=Qm;let n,s;for(const r of this.decorObjects){if(r.kind==="crop")continue;const o=this.decorGroups.get(r.id);if(!o)continue;const c=this.ufoOcclusionRaycaster.intersectObject(o,!0)[0];c&&(r.occludesSourceIds?.includes(i)?n=n===void 0?c.distance:Math.max(n,c.distance):s=s===void 0?c.distance:Math.min(s,c.distance))}return{behindM:n,inFrontM:s}}pickBodyAt(t,e){this.aimAtScreenPoint(this.raycaster,t,e);const i=[...this.hitAreas.entries()],n=this.raycaster.intersectObjects(i.map(([,s])=>s))[0];if(n&&!this.groundHides(t,e))return i.find(([,s])=>s===n.object)?.[0]}pickInterpretationBodyAt(t,e){const i=this.bodySystem.group.children.filter(f=>f.visible&&f.name.startsWith("body:"));if(i.length===0)return;this.aimAtScreenPoint(this.raycaster,t,e);const n=this.raycaster.ray.direction,s=this.raycaster.ray.origin,r=SE*this.camera.fov*Math.PI/180,o=[...this.decorGroups.values()],c=o.length>0?this.raycaster.intersectObjects(o,!0)[0]?.distance:void 0;let l,h=1/0;const u=new ki,d=new R;for(const f of i){if(u.setFromObject(f),u.isEmpty())continue;u.getCenter(d);const p=u.getSize(new R).length()/2,v=d.clone().sub(s),m=v.length();if(m===0||v.dot(n)<=0||c!==void 0&&c<m-p)continue;const g=Math.acos(Math.min(1,v.normalize().dot(n))),S=Math.max(r,Math.atan(p/m));g<=S&&S<h&&(h=S,l=f.name.slice(5))}return l}pickStarAt(t,e){if(this.namedStars.length===0)return;this.aimAtScreenPoint(this.raycaster,t,e);const i=this.raycaster.ray.direction,n=Math.cos(Pu*this.camera.fov*Math.PI/180);let s,r=n;for(const o of this.namedStars){const c=o.direction.dot(i);c>r&&(r=c,s={star:o.star,altitudeDeg:o.altitudeDeg})}return s&&this.groundHides(t,e)?void 0:s}groundHides(t,e){if(!this.terrainMesh&&!this.groundMesh)return!1;this.aimAtScreenPoint(this.ufoOcclusionRaycaster,t,e);const i=this.ufoOcclusionRaycaster.ray;return this.groundBlocks(i.origin,i.direction,1/0,Qm)}bodyScreenBox(t){const e=this.bodySystem.boxOf(t,this.bodyBoxScratch);if(!e)return;let i=1/0,n=1/0,s=-1/0,r=-1/0;for(let o=0;o<8;o++){const c=this.bodyCornerScratch.set(o&1?e.max.x:e.min.x,o&2?e.max.y:e.min.y,o&4?e.max.z:e.min.z),l=this.screenPointOf(c.sub(this.camera.position).normalize());if(!l)return;i=Math.min(i,l.ndcX),s=Math.max(s,l.ndcX),n=Math.min(n,l.ndcY),r=Math.max(r,l.ndcY)}return{minX:i,minY:n,maxX:s,maxY:r}}bodyBoxScratch=new ki;bodyCornerScratch=new R;pickPlacedBodyAt(t,e){return this.aimAtScreenPoint(this.raycaster,t,e),this.bodySystem.pick(this.raycaster)}decorScreenBox(t){const e=this.decorGroups.get(t);if(!e||!e.visible)return;const i=this.bodyBoxScratch.setFromObject(e);if(i.isEmpty())return;let n=1/0,s=1/0,r=-1/0,o=-1/0;for(let c=0;c<8;c++){const l=this.bodyCornerScratch.set(c&1?i.max.x:i.min.x,c&2?i.max.y:i.min.y,c&4?i.max.z:i.min.z),h=this.screenPointOf(l.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),o=Math.max(o,h.ndcY)}return{minX:n,minY:s,maxX:r,maxY:o}}decorGroundPointAt(t,e,i){const n=this.decorGroups.get(t);if(!n)return;this.aimAtScreenPoint(this.raycaster,e,i);const s=this.raycaster.ray.intersectPlane(this.decorPlaneScratch.setComponents(0,1,0,-n.position.y),this.decorHitScratch);return s?{x:s.x,z:s.z}:void 0}decorPlaneScratch=new er;decorHitScratch=new R;pickDecorAt(t,e){this.aimAtScreenPoint(this.raycaster,t,e);const i=[...this.decorGroups.entries()],n=this.raycaster.intersectObjects(i.map(([,r])=>r),!0)[0];if(!n)return;let s=n.object;for(;s&&!i.some(([,r])=>r===s);)s=s.parent;return i.find(([,r])=>r===s)?.[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.lightningBolt?.dispose(),this.lightningBolt=void 0;for(const t of this.bodyMeshes.values())this.disposeMesh(t);this.bodyMeshes.clear(),this.novaKeys.clear();for(const t of[...this.hitAreas.keys()])this.disposeHitArea(t);for(const t of[...this.glareSprites.keys()])this.disposeGlare(t);this.disposeCompassLabels();for(const t of this.decorGroups.values())oi.dispose(t);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 t=e=>{this.animationFrameId=null,this.frame(e),this.animationFrameId===null&&this.needsAnimationLoop()&&(this.animationFrameId=requestAnimationFrame(t))};this.animationFrameId=requestAnimationFrame(t)}setAnimationsRunning(t,e=!1){const i=t&&e;if(t===this.animationsRunning&&i===this.framesDriven)return;const n=this.animationsRunning;this.animationsRunning=t,this.framesDriven=i,t&&!n&&(this.lastFrameTimeMs=void 0,this.resolution.reset());const s=!t&&this.renderer.getPixelRatio()!==this.resolution.maximum;s&&this.applyPixelRatio(this.resolution.maximum),this.syncAnimationLoop(),(!t||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(t=>t.brightness.length>0)||this.precipitationPoints!==void 0||this.rainSystem!==void 0||this.flareMayShow()}flareAimScratch=new R;flareMayShow(){if(this.lensFlare===void 0||!this.sunVisible)return!1;const t=this.lastAstronomy?.sun;return t!==void 0&&t.altitudeDeg<me.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(t){const e=this.skyMesh?.geometry??new di(ml,32,16),i=e.attributes.position,n=e.getAttribute("color")??new de(new Float32Array(i.count*3),3);for(let r=0;r<i.count;r++){const{altitudeDeg:o,azimuthDeg:c}=uw(i.getX(r),i.getY(r),i.getZ(r)),l=xw(o,c,t.azimuthDeg,t.altitudeDeg);n.setXYZ(r,l[0],l[1],l[2])}if(n.needsUpdate=!0,this.skyMesh)return;e.setAttribute("color",n);const s=new _n({vertexColors:!0,side:qe,fog:!1,depthWrite:!1});this.skyGradientMaterial=s,this.skyMesh=new bt(e,s),this.skyMesh.renderOrder=-1,this.celestialGroup.add(this.skyMesh)}buildGround(){const t=tg(this.observerElevationM);if(this.groundMesh&&t===this.groundRadius)return;this.disposeMesh(this.groundMesh),this.groundRadius=t;const e=new V0(this.groundRadius,48),i=new qr({color:new st(Iu,Iu,Iu),fog:!0});Vr.fadeRim(i,this.groundRadius*.75,this.groundRadius),this.groundMesh=new bt(e,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 t=this.groundMesh?.material;if(!t)return;const e=this.terrainMesh===void 0;t.depthWrite!==e&&(t.depthWrite=e,t.needsUpdate=!0)}cloudTransmission(t,e=!1){const i=`${t.altitudeDeg.toFixed(1)}:${t.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,o])=>`${r}=${Math.round(o.x/10)},${Math.round(o.z/10)}`).join(";")+(e?":water":""),n=this.cloudTransmissionMemo.get(i);if(n!==void 0)return n;this.cloudTransmissionMemo.size>256&&this.cloudTransmissionMemo.clear();const s=this.computeCloudTransmission(t,e);return this.cloudTransmissionMemo.set(i,s),s}cloudTransmissionMemo=new Map;computeCloudTransmission(t,e=!1){const i=Ze(t.altitudeDeg,t.azimuthDeg,1);if(this.layeredClouds)return this.layeredClouds.transmissionAt(i,e);let n=1;const s=this.lowerCloudCover();s>0&&(n*=1-Me.alphaAt(i,Math.abs(this.cloudLayerOffset()),s,this.cloudFieldOffset)*TE);const r=e?0:this.weather.highCloudCover??0;return r>0&&(n*=1-Me.iceAlphaAt(i,gl,r,this.cloudFieldOffset)*RE),Math.max(0,Math.min(1,n))}setBodyMesh(t,e,i,n,s){if(e.altitudeDeg<_0){this.disposeMesh(this.bodyMeshes.get(t)),this.bodyMeshes.delete(t),this.disposeHitArea(t),this.disposeGlare(t),t==="sun"&&(this.sunVisible=!1);return}const{x:r,y:o,z:c}=Ze(e.altitudeDeg,e.azimuthDeg,un),l=_m(e.altitudeDeg),h=this.cloudTransmission(e),u=this.arrivingIlluminance(e,s,h),d=me.unitLuminance(n);let f=this.bodyMeshes.get(t);if(t==="sun"){const p=Math.PI*(i/un)**2,v=[0,1,2].map(m=>Math.min(me.BRIGHTEST_RELATIVE,d[m]*u[m]/p));f instanceof bt||(this.disposeMesh(f),f=new bt(new di(1,16,16),new _n({fog:!1})),this.celestialGroup.add(f),this.bodyMeshes.set(t,f)),f.material.color.setRGB(v[0],v[1],v[2]),f.scale.setScalar(i)}else{if(!(f instanceof mn)){this.disposeMesh(f);const m=new se;m.setAttribute("position",new Jt(new Float32Array(3),3)),m.setAttribute("color",new Jt(new Float32Array(3),3)),f=new mn(m,Dt.material(Xa[Xa.length-1].size,!1)),Dt.track(f),this.celestialGroup.add(f),this.bodyMeshes.set(t,f)}const p=f.geometry.getAttribute("color"),v=t.startsWith("comet:")?this.pointToPixel():1;p.setXYZ(0,d[0]*u[0]*v,d[1]*u[1]*v,d[2]*u[2]*v),p.needsUpdate=!0}if(f.position.set(r,o,c),this.setHitArea(t,r,o,c,i),t==="sun"&&(this.sunArriving=u),t.startsWith("comet:")?this.disposeGlare(t):t!=="sun"&&this.setGlare(t,r,o,c,u,i/un*(180/Math.PI),me.POINT_VEIL_HOLD_DEG),t==="sun"){this.sunVisible=!0;const p=this.celestialGroup.scale.x;this.sunWorldPosition.set(r*p,o*p+this.celestialGroup.position.y,c*p),this.lensFlare||(this.lensFlare=G5(),this.lensFlare.uniforms.uOpacity.value=UE,this.lensFlare.uniforms.uFlareIntensity.value=this.lensFlareArtifactIntensity,this.lensFlare.uniforms.uStarPoints.value=this.starPoints,this.scene.add(this.lensFlare.mesh)),this.applyLensFlareTint(l)}}setMoonMesh(t,e){const i="moon";if(t.magnitude>e||t.altitudeDeg<_0){this.disposeMesh(this.bodyMeshes.get(i)),this.bodyMeshes.delete(i),this.disposeHitArea(i),this.disposeGlare(i);return}const{x:n,y:s,z:r}=Ze(t.altitudeDeg,t.azimuthDeg,un),o=this.cloudTransmission(t),c=this.arrivingIlluminance(t,t.magnitude,o),l=Math.max(Na(t.phase.illuminatedFraction,0,1),.01)*Math.PI*(Do/un)**2,h=new st(...c.map(f=>Math.min(me.BRIGHTEST_RELATIVE,f/l))),u=`${t.phase.phaseFraction<.5}:${Math.round(Na(t.phase.illuminatedFraction,0,1)*500)}`;let d=this.bodyMeshes.get(i);if(d instanceof go)d.userData.phaseKey!==u&&(d.material.map?.dispose(),d.material.map=wg(t.phase),d.userData.phaseKey=u),d.material.color.copy(h);else{this.disposeMesh(d),d=new go(new Il({map:wg(t.phase),color:h,fog:!1})),d.userData.phaseKey=u;const f=Do*2;d.scale.set(f,f,1),this.celestialGroup.add(d),this.bodyMeshes.set(i,d)}d.position.set(n,s,r),this.setHitArea(i,n,s,r,Do),this.setGlare(i,n,s,r,c,Do/un*(180/Math.PI))}bentLight(t,e,i=EE){const[n,s,r]=this.arrivingIlluminance(t,e,1),o=Math.max(s,1e-30);return{scale:s/i,tint:[n/o,1,r/o]}}static litBySky(t,e){return me.litScratch.setRGB(t.r*e[0],t.g*e[1],t.b*e[2])}static litScratch=new st;pointToPixel(){const t=Math.max(1,this.renderer.getDrawingBufferSize(this.pointScratch).y),e=(this.camera.fov*Math.PI/180/t)**2;return Math.min(1,Dt.CONE_SOLID_ANGLE/e)}pointScratch=new Mt;static POINT_VEIL_HOLD_DEG=.25;static BRIGHTEST_RELATIVE=6e4;arrivingIlluminance(t,e,i){const n=this.air.transmittanceFromSpace(this.siteElevationM+this.observerElevationM,t.altitudeDeg),s=ue.illuminanceOf(e)*i*this.relativeScale;return[n[0]*s,n[1]*s,n[2]*s]}static unitLuminance(t){const e=$n.luminanceOf([t.r,t.g,t.b]);return e>0?[t.r/e,t.g/e,t.b/e]:[1,1,1]}setHitArea(t,e,i,n,s){let r=this.hitAreas.get(t);if(!r){const c=new Il({transparent:!0,opacity:0,depthTest:!1,depthWrite:!1,fog:!1});r=new go(c),this.celestialGroup.add(r),this.hitAreas.set(t,r)}r.position.set(e,i,n);const o=s*wE;r.scale.set(o,o,1)}disposeHitArea(t){const e=this.hitAreas.get(t);e&&(e.removeFromParent(),e.material.dispose(),this.hitAreas.delete(t))}setGlare(t,e,i,n,s,r,o=0){if(Ni.radiusDeg(Ni.K*Math.max(...s))<=Math.max(r,o)){this.disposeGlare(t);return}let c=this.glareSprites.get(t);c||(c=new Ni(`veil:${t}`),this.celestialGroup.add(c.mesh),this.glareSprites.set(t,c)),c.shine({x:e,y:i,z:n},s,r,o)}disposeGlare(t){const e=this.glareSprites.get(t);e&&(e.mesh.removeFromParent(),e.dispose(),this.glareSprites.delete(t))}buildComet(t,e){const i=t&&`comet:${t.id}`;if(!t||!i||t.magnitude>e){this.disposeComet();return}this.cometKey&&this.cometKey!==i&&this.disposeComet();const n=Ca(t.magnitude,e),s=gu(n);this.cometKey=i,this.setBodyMesh(i,t.position,Lu*(.5+.5*n),new st(s,s,s),t.magnitude),this.cometTail||(this.cometTail=new fn(un),this.celestialGroup.add(this.cometTail.object)),this.cometTail.set(t.position,t.tailEnd,n)}buildIceHalos(t,e){this.iceHalos||(this.iceHalos=new Ti,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:gl},0);return}const s=this.lowerCloudCover(),r=ve.deckLitUntilDeg(ve.DECK_HEIGHT_M),o=t.altitudeDeg>-r?t:e,c=this.bentLight(o,o===t?ke.SUN_MAGNITUDE:e.magnitude),l=ve.strength(i,s,o.altitudeDeg,r)*c.scale,{x:h,y:u,z:d}=Ze(o.altitudeDeg,o.azimuthDeg,1);this.iceHalos.update({x:h,y:u,z:d},o.altitudeDeg,l,c.tint,{cover:n?.cover??i,layerHeight:n?.layerHeight??gl},n?.iceCrystalAlignment??this.weather.iceCrystalAlignment??Uv)}buildRainbow(t,e){this.rainbow||(this.rainbow=new Nr,this.celestialGroup.add(this.rainbow.object));const i=this.weather.precipitationType==="rain"?this.weather.precipitationIntensity*(this.weather.precipitationAmount??1):0,n=t.altitudeDeg>0,s=n?t:e,r=this.lowerCloudCover(),o=this.bentLight(s,n?ke.SUN_MAGNITUDE:e.magnitude,AE),c=dn.strength(i,r,s.altitudeDeg)*o.scale;if(c<=0){this.rainbow.update({x:0,y:1,z:0},0,[1,1,1],!0);return}const{x:l,y:h,z:u}=Ze(s.altitudeDeg,s.azimuthDeg,1);this.rainbow.update({x:l,y:h,z:u},c,o.tint,n)}buildSkyGlow(t,e){if(!t.frame){this.skyGlow?.hide();return}this.skyGlow||(this.skyGlow=new ir,this.skyGlow.setWithheld(!!this.skyHoldUntilMs),this.skyGlow.onReady=()=>this.render(),this.celestialGroup.add(this.skyGlow.object));const{date:i,observer:n}=t.frame,s=Vn.galactic(i,n),r=me.directionOf(s.centre),o=me.directionOf(s.rotation),c=me.directionOf(s.pole),l=new $t().set(r.x,r.y,r.z,o.x,o.y,o.z,c.x,c.y,c.z),h=me.directionOf(Vn.eclipticPole(i,n)),u=me.directionOf(t.sun),d=u.clone().addScaledVector(h,-u.dot(h)).normalize();this.skyGlow.update({galactic:l,eclipticPole:h,sunLongitude:d,sunDirection:u,sunAltitudeDeg:t.sun.altitudeDeg,moon:{direction:me.directionOf(t.moon),altitudeDeg:t.moon.altitudeDeg,phaseAngleDeg:xt.phaseAngleOf(t.moon.phase.illuminatedFraction)},lightPollution:this.lightPollution,skyColor:new R(e[0],e[1],e[2])})}static directionOf(t){const{x:e,y:i,z:n}=Ze(t.altitudeDeg,t.azimuthDeg,1);return new R(e,i,n).normalize()}buildNovae(t,e){const i=new Set;for(const n of t){if(n.magnitude>e)continue;const s=`nova:${n.id}`;i.add(s);const r=Ca(n.magnitude,e),o=gu(r);this.setBodyMesh(s,n.position,Lu*(.5+.5*r),new st(o,o,o),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(t,e){const i=new Set(["sun","moon",...this.cometKey?[this.cometKey]:[],...this.novaKeys]);for(const n of t){if(n.magnitude>e)continue;i.add(n.body);const s=Ca(n.magnitude,e),r=gu(s),o=nA[n.body]??new st(1,1,1),c=new st(o.r*r,o.g*r,o.b*r),l=Lu*(.5+.5*s);this.setBodyMesh(n.body,n.position,l,c,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(t,e){if(this.namedStars=[],!t||t.catalog.count===0){this.disposeStarTiers(),this.syncAnimationLoop();return}const{catalog:i,date:n,observer:s}=t,r=new Yn(n,s),o=Vu(1337),c=[],l=this.siteElevationM+this.observerElevationM;for(let h=0;h<i.count;h++){const u=i.mag[h];if(u>e)break;const{altitudeDeg:d,azimuthDeg:f}=r.position(i.ra[h],i.dec[h]);if(d<eg)continue;const{x:p,y:v,z:m}=Ze(d,f,Cu);c.push({x:p,y:v,z:m,brightness:Ca(u,e),illuminance:this.air.transmittanceFromSpace(l,d).map(g=>g*ue.illuminanceOf(u)),phase:o()*Math.PI*2,speedFactor:.7+o()*.6})}for(const h of S5){if(h.mag>e)continue;const{altitudeDeg:u,azimuthDeg:d}=r.position(h.raHours,h.decDeg);if(u<eg)continue;const{x:f,y:p,z:v}=Ze(u,d,Cu);this.namedStars.push({star:h,direction:new R(f,p,v).normalize(),altitudeDeg:u})}this.starTiers=Xa.map((h,u)=>{const d=c.filter(b=>Q0(b.brightness)===u),f=new Float32Array(d.length*3),p=new Float32Array(d.length),v=new Float32Array(d.length*3),m=new Float32Array(d.length),g=new Float32Array(d.length);d.forEach((b,w)=>{f[w*3]=b.x,f[w*3+1]=b.y,f[w*3+2]=b.z,p[w]=b.brightness,v.set(b.illuminance,w*3),m[w]=b.phase,g[w]=b.speedFactor});const S=new se;S.setAttribute("position",new Jt(f,3)),S.setAttribute("seed",new Jt(m.map(b=>b/(2*Math.PI)),1));const x=new Jt(new Float32Array(d.length*3),3);S.setAttribute("color",x);let M=this.starTiers[u]?.points;return M?(M.geometry.dispose(),M.geometry=S):(M=new mn(S,Dt.material(h.size)),Dt.track(M),this.celestialGroup.add(M)),{points:M,colorAttribute:x,brightness:p,illuminance:v,phase:m,speedFactor:g}}),this.starColoursRelative=Number.NaN,this.updateTwinkle(this.twinkleSeconds),this.startTwinkle()}twinkleSeconds=0;starColoursRelative=Number.NaN;updateTwinkle(t){Dt.setTime(t);const e=this.relativeScale;if(e!==this.starColoursRelative){this.starColoursRelative=e;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]*e,n[s*3+1]=i.illuminance[s*3+1]*e,n[s*3+2]=i.illuminance[s*3+2]*e;i.colorAttribute.needsUpdate=!0}}}buildClouds(){if(this.cloudRendering==="volume"||this.weather.cloudLayers!==void 0){this.layeredClouds||(this.disposeCloudSystem(),this.layeredClouds=new Va(this.celestialGroup,Ou,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 t=this.lowerCloudCover();if(t<=0){this.disposeCloudSystem();return}const e=this.weather.cloudDarkness,i=new st(Er[0]+(Uu[0]-Er[0])*e,Er[1]+(Uu[1]-Er[1])*e,Er[2]+(Uu[2]-Er[2])*e);if(this.cloudMesh&&this.cloudUniforms){this.cloudUniforms.coverage.value=t,this.cloudUniforms.baseColor.value.copy(i),this.syncCloudLayer(),this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor);return}this.disposeCloudSystem();const{material:n,uniforms:s}=$d(i,t,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=Kd(Ou);this.cloudMesh=new bt(r,n),this.faceCloudDeck(this.cloudMesh,this.cloudLayerOffset()),this.celestialGroup.add(this.cloudMesh)}lowerCloudCover(){return this.weather.cloudLayers?1-this.weather.cloudLayers.filter(t=>t.type!=="cirrus").reduce((t,e)=>t*(1-e.coverage),1):this.weather.lowerCloudCover??this.weather.cloudCover}highCloudCover(){return this.weather.cloudLayers?1-this.weather.cloudLayers.filter(t=>t.type==="cirrus").reduce((t,e)=>t*(1-e.coverage),1):this.weather.highCloudCover}buildCirrus(){const t=this.weather.highCloudCover??0;if(this.layeredClouds||t<=0){this.disposeCirrus();return}if(this.cirrusMesh&&this.cirrusUniforms){this.cirrusUniforms.coverage.value=t,this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor);return}const{material:e,uniforms:i}=$d(new st(...Er),t,gl,1);this.cirrusMaterial=e,this.cirrusUniforms=i,i.fieldOffset.value.copy(this.cloudFieldOffset),this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor),this.cirrusMesh=new bt(Kd(Ou*1.04),e),this.cirrusMesh.renderOrder=cg-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 t=this.cloudLayerOffset();this.cloudUniforms&&(this.cloudUniforms.layerHeight.value=Math.abs(t)),this.cloudMesh&&this.faceCloudDeck(this.cloudMesh,t)}faceCloudDeck(t,e){const i=e<0;t.scale.y=i?-1:1,t.renderOrder=i?Va.deckOrder(!0,0,1):cg}cloudLayerOffset(){const e=((this.weather.cloudBaseM??w0)-this.observerElevationM)*Nu;return Math.sign(e||1)*Math.max(Math.abs(e),zE)}updateCloudLighting(t,e){const i=[this.cloudUniforms,this.cirrusUniforms].filter(u=>u!==void 0);if(i.length===0&&!this.layeredClouds)return;const n=this.cloudBeamDirection,[s,r,o]=this.cloudBeam.map(u=>u/Math.PI),c=this.lightningLevel*Gu*this.relativeScale/Math.PI,l=new st(e[0]+ss.r*c,e[1]+ss.g*c,e[2]+ss.b*c);this.layeredClouds?.setLighting(n.clone(),new st(s,r,o),l,l);const h=Math.max(0,n.y);for(const u of i)u.sunDir.value.copy(n),u.sunColor.value.setRGB(s*h,r*h,o*h),u.ambientColor.value.copy(l)}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(t){return qE(t,this.weather.precipitationIntensity,this.weather.precipitationAmount??1)}updatePrecipitationDensity(){const t=[[this.rainSystem?.points,Bu],[this.rainSplashSystem?.points,Ar],[this.precipitationPoints,this.weather.precipitationType==="none"||this.weather.precipitationType==="rain"?void 0:ku[this.weather.precipitationType].poolSize]];for(const[e,i]of t)e&&i!==void 0&&e.geometry.setDrawRange(0,this.precipitationCount(i));this.rainSystem&&(this.rainSystem.uniforms.uSpeedStreak.value=dg(Hu(this.weather.precipitationIntensity)))}buildPrecipitation(){this.disposePrecipitationPoints(),this.disposeRain();const t=this.weather.precipitationType;if(t==="none")return;if(t==="rain"){this.buildRain();return}const e=ku[t],i=e.poolSize,n=Vu(9001),s=new Float32Array(i*3),r=new Float32Array(i),o=new Float32Array(i),c=new Float32Array(i),l=new Float32Array(i),h=new Float32Array(i),u=new Float32Array(i),d=new Float32Array(i),f=new Float32Array(i),p=new Float32Array(i);for(let x=0;x<i;x++){const M=n()*Math.PI*2,b=n()*e.radiusM;s[x*3]=Math.cos(M)*b,s[x*3+1]=Ta+n()*(e.topYM-Ta),s[x*3+2]=Math.sin(M)*b,r[x]=n()*Math.PI*2,o[x]=.7+n()*.6,c[x]=.6+n()*.8,l[x]=.4+n()*1.2}const v=new se;v.setAttribute("position",new Jt(s,3)),v.setDrawRange(0,this.precipitationCount(i));const m={uSize:{value:e.size},uScale:{value:.5*this.renderer.domElement.height},uOpacity:{value:e.opacity},uColor:{value:e.color.clone()},uHazeColor:{value:new st(...this.baseFogColor)},uTexture:{value:sA(t)},uNearFocusDistance:{value:gg},uHazeDistance:{value:e.radiusM*vg}},g=new fe({uniforms:m,vertexShader:hA,fragmentShader:uA,transparent:!0,depthWrite:!1});this.precipitationUniforms=m;const S=new mn(v,g);S.renderOrder=Fu,this.scene.add(S),this.precipitationPoints=S,this.precipitationPositions=s,this.precipitationPhase=r,this.precipitationSpeedJitter=o,this.precipitationWobbleFreqJitter=c,this.precipitationWobbleAmpJitter=l,this.precipitationBounceRemaining=h,this.precipitationBounceHeight=u,this.precipitationBounceDuration=d,this.precipitationBounceVelX=f,this.precipitationBounceVelZ=p}updatePrecipitation(t,e){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=ku[i];if(this.precipitationUniforms?.uColor.value.copy(me.litBySky(n.color,this.baseFogColor)),e<=0)return;const s=this.weather.windDirectionDeg*ji,r=Math.sin(s)*this.weather.windSpeed*n.driftSensitivity,o=-Math.cos(s)*this.weather.windSpeed*n.driftSensitivity,c=this.precipitationPositions,l=this.precipitationPhase,h=this.precipitationSpeedJitter,u=this.precipitationWobbleFreqJitter,d=this.precipitationWobbleAmpJitter,f=this.precipitationBounceRemaining,p=this.precipitationBounceHeight,v=this.precipitationBounceDuration,m=this.precipitationBounceVelX,g=this.precipitationBounceVelZ,S=i==="snow"&&u&&d,x=i==="hail"&&f&&p&&v&&m&&g;for(let M=0,b=0;M<c.length;M+=3,b++){if(x&&f[b]>0){if(f[b]-=e,f[b]<=0){const y=Math.random()*Math.PI*2,A=Math.sqrt(Math.random())*n.radiusM;c[M]=Math.cos(y)*A,c[M+1]=n.topYM,c[M+2]=Math.sin(y)*A,f[b]=0}else{const y=1-f[b]/v[b];c[M+1]=Ta+Math.sin(Math.PI*y)*p[b],c[M]=xl(c[M]+(r+m[b])*e,n.radiusM),c[M+2]=xl(c[M+2]+(o+g[b])*e,n.radiusM)}continue}let w=0,T=0;if(S){const y=KE*u[b],A=ZE*d[b];w=Math.sin(t*y*Math.PI*2+l[b])*A,T=Math.sin(t*y*Math.PI*2+l[b]+Math.PI/2)*A}if(c[M]+=(r+w)*e,c[M+1]-=n.fallSpeedMPerS*h[b]*e,c[M+2]+=(o+T)*e,c[M]=xl(c[M],n.radiusM),c[M+2]=xl(c[M+2],n.radiusM),c[M+1]<Ta){if(x){p[b]=_g*(.2+Math.random()*1.6),v[b]=JE*(.5+Math.random()),f[b]=v[b];const C=Math.random()*Math.PI*2,I=jE*(p[b]/_g);m[b]=Math.cos(C)*I,g[b]=Math.sin(C)*I,c[M+1]=Ta;continue}const y=Math.random()*Math.PI*2,A=Math.sqrt(Math.random())*n.radiusM;c[M]=Math.cos(y)*A,c[M+1]=n.topYM,c[M+2]=Math.sin(y)*A}}this.precipitationPoints.geometry.attributes.position.needsUpdate=!0}buildRain(){const t=Hu(this.weather.precipitationIntensity);this.rainSystem=k5({count:Bu,radiusM:Io,heightM:HE,bottomYM:lg,overallSpeed:GE,color:ug.clone(),opacity:.85,visibleCount:this.precipitationCount(Bu),speedStreak:dg(t),pixelSize:xg,seed:9001,nearFocusDistanceM:gg,hazeDistanceM:Io*vg,hazeColor:new st(...this.baseFogColor)}),this.rainLastVerticalFacing=-1,this.syncRainSlant(),this.rainSystem.points.renderOrder=Fu,this.scene.add(this.rainSystem.points),this.buildRainSplashes()}buildRainSplashes(){const t=Vu(4242),e=new Float32Array(Ar*3),i=new Float32Array(Ar),n=new Float32Array(Ar),s=new Float32Array(Ar);for(let h=0;h<Ar;h++){const u=t()*Math.PI*2,d=Math.sqrt(t())*Io;e[h*3]=Math.cos(u)*d,e[h*3+1]=lg,e[h*3+2]=Math.sin(u)*d,n[h]=bg(fg,pg),i[h]=t()*n[h],s[h]=i[h]/n[h]}const r=new se;r.setAttribute("position",new Jt(e,3));const o=new Jt(s,1);r.setAttribute("aLife",o),r.setDrawRange(0,this.precipitationCount(Ar));const c=new fe({uniforms:{uMaxSize:{value:YE},uScale:{value:.5*this.renderer.domElement.height},uColor:{value:mg.clone()},uTexture:{value:oA()}},vertexShader:cA,fragmentShader:lA,transparent:!0,depthWrite:!1}),l=new mn(r,c);l.renderOrder=Fu,this.scene.add(l),this.rainSplashSystem={points:l,positions:e,life:i,duration:n,lifeAttribute:o}}disposeRain(){this.rainSystem&&(this.rainSystem.points.removeFromParent(),this.rainSystem.points.geometry.dispose(),this.rainSystem.points.material.dispose()),this.rainSystem=void 0,this.disposeRainSplashes()}disposeRainSplashes(){this.rainSplashSystem&&(this.rainSplashSystem.points.removeFromParent(),this.rainSplashSystem.points.geometry.dispose(),this.rainSplashSystem.points.material.dispose()),this.rainSplashSystem=void 0}syncRainSlant(){const t=this.rainSystem;if(!t)return;const e=this.weather.windDirectionDeg*ji;t.uniforms.uDropVelocity.value.set(Math.sin(e)*this.weather.windSpeed,-Hu(this.weather.precipitationIntensity),-Math.cos(e)*this.weather.windSpeed);const i=this.renderer.getSize(this.rainViewportSize);t.uniforms.uAspect.value=i.x/Math.max(i.y,1)}updateRain(t){const e=this.rainSystem;if(!e)return;e.uniforms.uTime.value+=t,e.uniforms.uHazeColor.value.setRGB(...this.baseFogColor),e.uniforms.uColor.value.copy(me.litBySky(ug,this.baseFogColor));const i=this.rainSplashSystem?.points.material?.uniforms?.uColor;i&&i.value.copy(me.litBySky(mg,this.baseFogColor));const n=this.weather.windDirectionDeg*ji,s=Math.sin(n)*this.weather.windSpeed,r=-Math.cos(n)*this.weather.windSpeed,o=Io,c=h=>(h%(o*2)+o*3)%(o*2)-o;e.uniforms.uWindOffset.value.set(c(e.uniforms.uWindOffset.value.x+s*t),c(e.uniforms.uWindOffset.value.y+r*t)),this.syncRainSlant(),this.camera.getWorldDirection(this.rainCameraDirection);const l=Math.abs(this.rainCameraDirection.y);if(Math.abs(l-this.rainLastVerticalFacing)>.001){this.rainLastVerticalFacing=l;const h=yg+(1-yg)*(1-l),u=Sg+(1-Sg)*(1-l);e.uniforms.uUvSquash.value=u,e.uniforms.uPixelSize.value=xg*h*(.5+.5*u)}this.updateRainSplashes(t)}updateRainSplashes(t){const e=this.rainSplashSystem;if(!e||t<=0)return;const{positions:i,life:n,duration:s,lifeAttribute:r}=e,o=r.array;for(let c=0,l=0;c<i.length;c+=3,l++){if(n[l]+=t,n[l]>=s[l]){const h=Math.random()*Math.PI*2,u=Math.sqrt(Math.random())*Io;i[c]=Math.cos(h)*u,i[c+2]=Math.sin(h)*u,s[l]=bg(fg,pg),n[l]=0}o[l]=n[l]/s[l]}e.points.geometry.attributes.position.needsUpdate=!0,r.needsUpdate=!0}setLightning(t){this.lightningFlashes=t}updateLightning(t){let e,i=0;if(this.lightningArmed)for(const c of this.lightningFlashes){if(c.t>t)break;const l=gi.brightnessAt(c,t);l>i&&(e=c,i=l)}const n=e?Math.min(1,Math.max(.1,(eA/e.distanceM)**2)):0,s=i*n*(e?.cloudToGround?1:.6);if(s===this.lightningLevel&&!e?.cloudToGround)return;if(this.lightningLevel=s,this.scene.fog){const c=this.scene.fog,l=s*Gu*this.relativeScale/Math.PI;c.color.setRGB(this.airlight[0]+ss.r*l,this.airlight[1]+ss.g*l,this.airlight[2]+ss.b*l)}const r=this.skyMesh?.material?.color;if(r){const c=s*iA;r.setRGB(1+c*ss.r,1+c*ss.g,1+c*ss.b)}if(this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor),this.lightningLight.intensity=s*Gu*this.relativeScale,e){const{x:c,y:l,z:h}=Ze(25,e.azimuthDeg,un);this.lightningLight.position.set(c,l,h)}this.lightningBolt||(this.lightningBolt=new nr(un*.95),this.celestialGroup.add(this.lightningBolt.object));const o=this.weather.cloudBaseM??1500;this.lightningBolt.set(e,i,o),this.render()}buildCompassLabels(){this.compassSprites=IE.map(t=>{const e=Hr.point(t,this.compassPoints),i=new Il({map:dA(e),depthTest:!1,fog:!1}),n=new go(i),{x:s,y:r,z:o}=Ze(0,t,sg);return n.position.set(s,r,o),n.scale.set(Ml,Ml,1),n.renderOrder=LE,n.layers.set(Du),n.visible=this.compassHovered||this.compassForced,this.celestialGroup.add(n),n}),this.updateCompassScale()}updateCompassScale(){const t=this.camera.fov*Math.PI/360,e=rg*Math.PI/360,i=Ml*Math.tan(t)/Math.tan(e);for(const n of this.compassSprites)n.scale.set(i,i,1)}disposeCompassLabels(){for(const t of this.compassSprites)t.removeFromParent(),t.material.map?.dispose(),t.material.dispose();this.compassSprites=[]}disposeStarTiers(){for(const t of this.starTiers)this.disposeMesh(t.points);this.starTiers=[]}disposeMesh(t){if(!t)return;t.removeFromParent(),"geometry"in t&&t.geometry.dispose();const e=t.material;for(const i of Array.isArray(e)?e:[e]){const n=i.map;n&&n.dispose(),i.dispose()}}}const ji=Math.PI/180;function Na(a,t,e){return Math.max(t,Math.min(e,a))}function bg(a,t){return a+Math.random()*(t-a)}function xl(a,t){return(a%(t*2)+t*3)%(t*2)-t}let yl,Sl;function sA(a){switch(a){case"snow":return rA();case"hail":return aA()}}function rA(){if(yl)return yl;const a=64,t=document.createElement("canvas");t.width=a,t.height=a;const e=t.getContext("2d"),i=e.createRadialGradient(a/2,a/2,0,a/2,a/2,a/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)"),e.fillStyle=i,e.fillRect(0,0,a,a),yl=new Bs(t),yl}function aA(){if(Sl)return Sl;const a=64,t=document.createElement("canvas");t.width=a,t.height=a;const e=t.getContext("2d"),i=e.createRadialGradient(a/2,a/2,0,a/2,a/2,a/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)"),e.fillStyle=i,e.fillRect(0,0,a,a),Sl=new Bs(t),Sl}let _l;function oA(){if(_l)return _l;const a=64,t=document.createElement("canvas");t.width=a,t.height=a;const e=t.getContext("2d"),i=e.createRadialGradient(a/2,a/2,0,a/2,a/2,a/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)"),e.fillStyle=i,e.fillRect(0,0,a,a),_l=new Bs(t),_l}const cA=`
7856
7856
  uniform float uMaxSize;
7857
7857
  uniform float uScale;
7858
7858
  attribute float aLife;
@@ -7918,4 +7918,4 @@ void main() {
7918
7918
  gl_FragColor = vec4(color, tex.a * uOpacity * (1.0 - blur * 0.5));
7919
7919
  }
7920
7920
  `;function wg(a){const e=document.createElement("canvas");e.width=128,e.height=128;const i=e.getContext("2d"),n=128/2-2,s=128/2,r=128/2,o="#010101",c="#f4f1e2";i.fillStyle=o,i.beginPath(),i.arc(s,r,n,0,Math.PI*2),i.fill();const l=Na(a.illuminatedFraction,0,1),h=a.phaseFraction<.5,u=n*Math.abs(1-2*l),d=l<.5;return i.save(),i.beginPath(),i.arc(s,r,n,0,Math.PI*2),i.clip(),i.fillStyle=c,i.beginPath(),h?(i.arc(s,r,n,-Math.PI/2,Math.PI/2,!1),i.ellipse(s,r,u,n,0,Math.PI/2,-Math.PI/2,d)):(i.arc(s,r,n,Math.PI/2,-Math.PI/2,!1),i.ellipse(s,r,u,n,0,-Math.PI/2,Math.PI/2,d)),i.fill(),i.restore(),new Bs(e)}function dA(a){const t=document.createElement("canvas");t.width=128,t.height=128;const e=t.getContext("2d");return e.fillStyle="rgba(0, 0, 0, 0.55)",e.beginPath(),e.arc(64,64,60,0,Math.PI*2),e.fill(),e.fillStyle="#ffffff",e.font="bold 52px sans-serif",e.textAlign="center",e.textBaseline="middle",e.fillText(a,64,68),new Bs(t)}function Vu(a){let t=a;return function(){t|=0,t=t+1831565813|0;let i=Math.imul(t^t>>>15,1|t);return i=i+Math.imul(i^i>>>7,61|i)^i,((i^i>>>14)>>>0)/4294967296}}class ah{constructor(t,e){this.source=t,this.create=e}scene;wanted;pumping=!1;disposed=!1;static PATIENCE_FRAMES=600;static SCENE_WIDTH_PX=320;paint(t,e){this.disposed||(this.wanted={t,canvas:e},this.pumping||this.pump())}recordingChanged(t){this.scene&&(this.scene.sightingData=t)}dispose(){this.disposed=!0,this.scene?.remove(),this.scene=void 0}ensureScene(){if(this.scene)return this.scene;const t=this.create();return t.setAttribute("max-pixel-ratio","1"),Object.assign(t.style,{position:"fixed",left:"-10000px",top:"0",width:`${ah.SCENE_WIDTH_PX}px`,visibility:"hidden",pointerEvents:"none"}),document.body.appendChild(t),t.documentUrl=this.source.documentUrl,t.accountInTheRound=this.source.accountInTheRound,t.sightingData=this.source.sightingData,this.scene=t,t}async pump(){this.pumping=!0;try{for(;this.wanted&&!this.disposed;){const{t,canvas:e}=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(t);for(let n=0;n<ah.PATIENCE_FRAMES&&!this.wanted&&!this.disposed&&(await new Promise(s=>requestAnimationFrame(()=>s())),!this.wanted);n++)if(i.snapshotTo(e)){e.dataset.ready="true";break}}}finally{this.pumping=!1}}}const Wu=7.5,Xu=9;class as{static cache=new Map;static load(t){let e=as.cache.get(t);return e||(e=fetch(t).then(i=>i.arrayBuffer()).then(i=>as.parse(i)),as.cache.set(t,e)),e}static upTo(t,e){const i=t.filter((r,o)=>o===0||t[o-1].magnitudeLimit<e);if(i.length<=1)return as.load(t[0].url);const n=i.map(r=>r.url).join(`
7921
- `);let s=as.cache.get(n);return s||(s=Promise.all(i.map(r=>as.load(r.url))).then(r=>r.reduce((o,c)=>as.concat(o,c))),as.cache.set(n,s)),s}static parse(t){const e=t.byteLength/(4*Float32Array.BYTES_PER_ELEMENT),i=e*Float32Array.BYTES_PER_ELEMENT;return{count:e,ra:new Float32Array(t,0*i,e),dec:new Float32Array(t,1*i,e),mag:new Float32Array(t,2*i,e),ci:new Float32Array(t,3*i,e)}}static concat(t,e){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:t.count+e.count,ra:i(t.ra,e.ra),dec:i(t.dec,e.dec),mag:i(t.mag,e.mag),ci:i(t.ci,e.ci)}}}class Eg{constructor(t){this.names=t}body(t,e){return this.names?.bodies[t]??e}star(t){return this.names?.stars[t.name]??t.name}comet(t){return this.names?.comets[t.id]??t.name}nova(t){return this.names?.novae[t.id]??t.name}satelliteClass(t){return this.names?.satelliteClasses[t.id]??t.name}shower(t){return this.names?.showers[t.id]??t.name}lightRig(t){return this.names?.lightRigs[t.id]??t.name}instrument(t){return this.names?.instruments[t.id]??t.name}decorKind(t,e){return this.names?.decorKinds[t]??e}point(t){return Hr.point(t,this.names?.compassPoints)}towards(t){return Hr.towards(t,this.names)}}const fA="Global Meteor Network",pA="https://globalmeteornetwork.org/data/",mA="“Thunder” by Jerimee",gA="https://creativecommons.org/licenses/by/3.0/",vA="CC BY 3.0";class en{static fill(t,e){t.innerHTML="";const i=h=>t.appendChild(h),n=e.currentTerrainAttribution;n&&i(en.text(n));const s=e.currentRoadAttribution;s&&i(en.text(s));const r=e.ufoElement.observerMapCredit;r&&!n?.includes(r)&&i(en.text(r));for(const h of e.decorModelCredits){const u=h.author?` — ${h.author}`:"",d=document.createElement("li");h.sourceUrl?d.append(en.link(h.sourceUrl,h.title),document.createTextNode(`${u} (${h.license})`)):d.textContent=`${h.title}${u} (${h.license})`,i(d)}for(const h of e.ufoElement.sighting.references){if(!h.credit)continue;const u=document.createElement("li");h.creditUrl?u.appendChild(en.link(h.creditUrl,h.credit)):u.textContent=h.credit,i(u)}if(e.ufoElement.sighting.traces.length>0){const h=new Cs(Ua.preferencesFor(e)),u=new Set(e.ufoElement.sighting.traces.map(d=>h.read(d.source)).filter(d=>!!d));for(const d of u)i(en.text(d))}const o=e.satelliteState;if(o.status==="ready"&&o.credit){const h=document.createElement("li");h.appendChild(en.link(o.creditUrl??"",o.credit)),i(h)}if(e.fireballState.status==="ready"&&e.fireballState.records.length>0){const h=document.createElement("li");h.append(en.link(pA,fA),document.createTextNode(" (CC BY 4.0)")),i(h)}const c=e.aircraftState;if(c.status==="ready"&&c.shown>0){const h=document.createElement("li");if(h.appendChild(en.link(c.creditUrl,c.credit)),i(h),c.trailCredit){const u=document.createElement("li");u.appendChild(en.link(c.trailCredit.creditUrl,c.trailCredit.credit)),i(u)}}const l=en.text(`${mA} (`);l.append(en.link(gA,vA),document.createTextNode(")")),i(l)}static text(t){const e=document.createElement("li");return e.textContent=t,e}static link(t,e){const i=document.createElement("a");return i.href=t,i.target="_blank",i.rel="noopener",i.textContent=e,i}}const MA=new URL(""+new URL("rain-BvWZrB9h.ogg",import.meta.url).href,import.meta.url).href,xA=new URL(""+new URL("wind-BjklexY7.ogg",import.meta.url).href,import.meta.url).href,yA=new URL(""+new URL("thunder-DA48qs_v.wav",import.meta.url).href,import.meta.url).href,SA=20,_A=1;class bA{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(t){return this.master||(this.master=t.createGain(),this.master.gain.value=this.level,this.master.connect(t.destination)),this.master}setLevel(t){this.level=t,this.master&&(this.master.gain.value=t)}resume(){if(!this.context){if(typeof AudioContext>"u")return;try{this.context=new AudioContext}catch(t){console.warn("WeatherAudio: Web Audio unavailable, weather sounds disabled:",t);return}}zr.unlock(this.context)}setAmbient(t,e,i){if(this.requested={type:t,intensity:e,windSpeed:i},!this.context)return;this.paused&&(t="none",e=0,i=0);const n=t==="rain"||t==="hail"?t:"none";if(this.ambientVolume=n==="hail"?Math.min(1,e*1.3+.2):n==="rain"?e: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(MA,this.ambientVolume).then(o=>this.applyIfCurrent(o,r,()=>this.ambientToken,c=>{this.ambientSource=c?.source,this.ambientGain=c?.gain,c&&(c.gain.gain.value=this.ambientVolume)}))}else this.ambientGain&&(this.ambientGain.gain.value=this.ambientVolume);this.windVolume=Math.min(i/SA,1);const s=i>_A;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(xA,this.windVolume).then(o=>this.applyIfCurrent(o,r,()=>this.windToken,c=>{this.windSource=c?.source,this.windGain=c?.gain,c&&(c.gain.gain.value=this.windVolume)}))}else this.windGain&&(this.windGain.gain.value=this.windVolume)}setPaused(t){if(t===this.paused)return;this.paused=t;const{type:e,intensity:i,windSpeed:n}=this.requested;this.setAmbient(e,i,n)}playThunder(){!this.context||this.paused||this.playOneShot(yA,.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(t,e,i,n){if(e!==i()){t?.source.stop();return}n(t)}async startLoop(t,e){const i=this.context;if(i)try{const n=await this.getBuffer(t),s=i.createBufferSource();s.buffer=n,s.loop=!0;const r=i.createGain();return r.gain.value=e,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(t,e){const i=this.context;if(i)try{const n=await this.getBuffer(t),s=i.createBufferSource();s.buffer=n;const r=i.createGain();r.gain.value=e,s.connect(r).connect(this.output(i)),s.start()}catch(n){console.warn("Thunder sound failed to load:",n)}}async getBuffer(t){const e=this.context;if(!e)throw new Error("WeatherAudio: AudioContext not ready — resume() must be called first");let i=this.buffers.get(t);return i||(i=fetch(t).then(n=>{if(!n.ok)throw new Error(`Audio fetch failed (${n.status}): ${t}`);return n.arrayBuffer()}).then(n=>e.decodeAudioData(n)),this.buffers.set(t,i)),i}stopSource(t,e){try{t?.stop()}catch{}t?.disconnect(),e?.disconnect()}}class Is{constructor(t){this.elements=t;const{eccentricity:e,perihelionAu:i}=t,[n,s]=this.perifocalAxes(),r=Math.sqrt(Is.SUN_GM_AU3_PER_DAY2*(1+e)/i);this.perihelionPosition=this.scale(n,i),this.perihelionVelocity=this.scale(s,r),this.inverseSemiMajorAxis=(1-e)/i}static SUN_GM_AU3_PER_DAY2=.0002959122082855911;static MAX_ITERATIONS=200;perihelionPosition;perihelionVelocity;inverseSemiMajorAxis;positionAt(t){const e=t-this.elements.perihelionJd,i=this.universalAnomaly(e),n=this.inverseSemiMajorAxis*i*i,s=this.elements.perihelionAu,r=1-i*i/s*Is.stumpffC(n),o=e-i*i*i/Math.sqrt(Is.SUN_GM_AU3_PER_DAY2)*Is.stumpffS(n);return{x:r*this.perihelionPosition.x+o*this.perihelionVelocity.x,y:r*this.perihelionPosition.y+o*this.perihelionVelocity.y,z:r*this.perihelionPosition.z+o*this.perihelionVelocity.z}}heliocentricDistanceAt(t){const e=this.positionAt(t);return Math.hypot(e.x,e.y,e.z)}universalAnomaly(t){if(t===0)return 0;const e=Math.sign(t),i=Math.sqrt(Is.SUN_GM_AU3_PER_DAY2)*Math.abs(t),n=o=>{const c=this.inverseSemiMajorAxis*o*o,l=this.elements.perihelionAu;return(1-this.inverseSemiMajorAxis*l)*o*o*o*Is.stumpffS(c)+l*o};let s=Math.max(1,i/this.elements.perihelionAu);for(;n(s)<i;)s*=2;let r=0;for(let o=0;o<Is.MAX_ITERATIONS&&s-r>1e-13*Math.max(1,s);o++){const c=(r+s)/2;n(c)<i?r=c:s=c}return e*(r+s)/2}perifocalAxes(){const t=this.elements.ascendingNodeDeg*Math.PI/180,e=this.elements.argumentOfPerihelionDeg*Math.PI/180,i=this.elements.inclinationDeg*Math.PI/180,n=Math.cos(t),s=Math.sin(t),r=Math.cos(e),o=Math.sin(e),c=Math.cos(i),l=Math.sin(i);return[{x:n*r-s*o*c,y:s*r+n*o*c,z:o*l},{x:-n*o-s*r*c,y:-s*o+n*r*c,z:r*l}]}scale(t,e){return{x:t.x*e,y:t.y*e,z:t.z*e}}static stumpffC(t){if(Math.abs(t)<1e-6)return 1/2-t/24+t*t/720;if(t>0)return(1-Math.cos(Math.sqrt(t)))/t;const e=Math.sqrt(-t);return(Math.cosh(e)-1)/-t}static stumpffS(t){if(Math.abs(t)<1e-6)return 1/6-t/120+t*t/5040;if(t>0){const i=Math.sqrt(t);return(i-Math.sin(i))/(i*i*i)}const e=Math.sqrt(-t);return(Math.sinh(e)-e)/(e*e*e)}}const _v=[{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 wA{static WINDOW_DAYS=200;static TWILIGHT_ELONGATION_DEG=15;static LIGHT_SPEED_AU_PER_DAY=173.144632674;static orbits=new Map;static aroundDate(t){const e=this.julianDayOf(t);return _v.filter(i=>Math.abs(e-i.orbit.perihelionJd)<=this.WINDOW_DAYS)}static brightestAt(t,e){return this.aroundDate(t).map(i=>this.appearanceOf(i,t,e)).sort((i,n)=>i.magnitude-n.magnitude)[0]}static appearanceOf(t,e,i){const n=ti(e),s=this.earthPositionAt(n),r=this.apparentPositionOf(t,2451545+n.tt,s),o=this.subtract(r,s),c=this.length(r),l=this.length(o),h=this.tailEndAt(t,r,s,c,n,e,i),u=this.horizontalOf(o,n,e,i);return{apparition:t,position:u,...h,heliocentricDistanceAu:c,earthDistanceAu:l,elongationDeg:this.angleBetween(o,this.subtract({x:0,y:0,z:0},s)),magnitude:this.magnitudeAt(t,c,l)}}static magnitudeAt(t,e,i){const n=t.absoluteMagnitude+5*Math.log10(i)+2.5*t.activityExponent*Math.log10(e);return Math.max(n,t.peakMagnitude)}static tailEndAt(t,e,i,n,s,r,o){if(t.tailLengthAu===void 0)return{};const c=1+t.tailLengthAu/n,l=this.subtract({x:e.x*c,y:e.y*c,z:e.z*c},i),h=this.subtract(e,i);return{tailEnd:this.horizontalOf(l,s,r,o),tailLengthDeg:this.angleBetween(h,l)}}static apparentPositionOf(t,e,i){const n=this.orbitOf(t);let s=n.positionAt(e);for(let r=0;r<2;r++){const o=this.length(this.subtract(s,i))/this.LIGHT_SPEED_AU_PER_DAY;s=n.positionAt(e-o)}return s}static horizontalOf(t,e,i,n){const s=Ka(f5(),new ze(t.x,t.y,t.z,e)),r=Ka(ov(e),s),o=Yw(e,new cf(n.lat,n.lng,n.elevationM)),c=new ze(r.x-o.x,r.y-o.y,r.z-o.z,e),l=hf(c);return uf(l.ra,l.dec,i,n)}static earthPositionAt(t){return Ka(d5(),fr(At.Earth,t))}static julianDayOf(t){return 2451545+ti(t).tt}static orbitOf(t){const e=this.orbits.get(t.id);if(e)return e;const i=new Is(t.orbit);return this.orbits.set(t.id,i),i}static subtract(t,e){return{x:t.x-e.x,y:t.y-e.y,z:t.z-e.z}}static length(t){return Math.hypot(t.x,t.y,t.z)}static angleBetween(t,e){const i=(t.x*e.x+t.y*e.y+t.z*e.z)/(this.length(t)*this.length(e)||1);return Math.acos(Math.min(1,Math.max(-1,i)))*180/Math.PI}}const Yu=[{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 Ag{static UNIX_EPOCH_JD=24405875e-1;static aroundDate(t){const e=this.julianDayOf(t);return Yu.filter(i=>this.magnitudeAt(i,e)!==void 0)}static appearancesAt(t,e){const i=this.julianDayOf(t),n=[];for(const s of Yu){const r=this.magnitudeAt(s,i);r!==void 0&&n.push({outburst:s,position:Yn.ofJ2000(s.raHours,s.decDeg,t,e),magnitude:r})}return n.sort((s,r)=>s.magnitude-r.magnitude)}static brightestAt(t,e){return this.appearancesAt(t,e)[0]}static byId(t){return Yu.find(e=>e.id===t)}static magnitudeAt(t,e){const i=t.lightCurve,n=e-t.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,o]=i[s-1]??i[0],[c,l]=i[s]??i[0];if(c===r)return o;const h=Math.min(1,Math.max(0,(n-r)/(c-r)));return o+h*(l-o)}static julianDayOf(t){return t.getTime()/864e5+this.UNIX_EPOCH_JD}}const EA=[{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}],oh=6.5;class qu{static activeAt(t){return EA.flatMap(e=>{const i=this.nearness(e,t);return i<=0?[]:[{shower:e,zhr:e.peakZhr*i,nearness:i}]})}static nearness(t,e){const i=this.dayOfYear(e),n=this.dayOfYear(this.asDate(t.start)),s=this.dayOfYear(this.asDate(t.peak)),r=this.dayOfYear(this.asDate(t.end)),o=this.wrappedDelta(i,s),c=this.wrappedDelta(s,n),l=this.wrappedDelta(r,s);return o<0?o<-c?0:1+o/c:o>0?o>l?0:1-o/l:1}static observedRatePerHour(t,e,i,n=oh){if(e<=0)return 0;const s=oh-n;return t*Math.sin(e*Math.PI/180)/Math.pow(i,s)}static radiantPosition(t,e,i){return Yn.ofJ2000(t.radiantRaHours,t.radiantDecDeg,e,i)}static dayOfYear(t){const e=Date.UTC(t.getUTCFullYear(),0,1);return Math.floor((Date.UTC(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate())-e)/864e5)+1}static asDate(t){return new Date(Date.UTC(2001,t.month-1,t.day))}static wrappedDelta(t,e){const i=t-e;return i>182?i-365:i<-182?i+365:i}}class ai{static QUIET_RATE_PER_HOUR=2;static APEX_RATE_PER_HOUR=8;static POPULATION_INDEX=3;static apexPosition(t,e){const i=ti(t),n=new yh(0,Ww(t).elon-90,1),s=Ka(m5(i),lf(n,i)),r=hf(s);return uf(r.ra,r.dec,t,e)}static observedRatePerHour(t,e=oh){const i=ai.APEX_RATE_PER_HOUR*Math.max(0,Math.sin(t*Math.PI/180)),n=oh-e;return(ai.QUIET_RATE_PER_HOUR+i)/Math.pow(ai.POPULATION_INDEX,n)}static schedule(t){const e=new bh(t.seed^1542469173);return Gr.schedule(t).map(i=>{const n=ai.toCartesian({altitudeDeg:Math.asin(e.next())*180/Math.PI,azimuthDeg:e.between(0,360)}),s=i.fromRadiantDeg*Math.PI/180,r=ai.turnAround(n,e.between(0,360)),o={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:ai.toHorizontal(o),bearingDeg:ai.bearingFrom(o,n)}})}static turnAround(t,e){const[i,n]=ai.basisAround(t),s=e*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(t,e){const[i,n]=ai.basisAround(t),s=t.x*e.x+t.y*e.y+t.z*e.z,r=ai.normalise({x:e.x-t.x*s,y:e.y-t.y*s,z:e.z-t.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(t){const e=Math.abs(t.y)<.9?{x:0,y:1,z:0}:{x:1,y:0,z:0},i=ai.normalise(ai.cross(t,e));return[i,ai.normalise(ai.cross(t,i))]}static toHorizontal(t){const e=Math.hypot(t.x,t.y,t.z)||1;return{altitudeDeg:Math.asin(Math.min(1,Math.max(-1,t.y/e)))*180/Math.PI,azimuthDeg:(Math.atan2(t.x,-t.z)*180/Math.PI%360+360)%360}}static appearanceOf(t){const e=ai.toCartesian(t.radiant??{altitudeDeg:90,azimuthDeg:0}),i=ai.turnAround(e,t.bearingDeg),n=t.fromRadiantDeg*Math.PI/180;return ai.toHorizontal({x:e.x*Math.cos(n)+i.x*Math.sin(n),y:e.y*Math.cos(n)+i.y*Math.sin(n),z:e.z*Math.cos(n)+i.z*Math.sin(n)})}static toCartesian(t){const e=t.altitudeDeg*Math.PI/180,i=t.azimuthDeg*Math.PI/180,n=Math.cos(e);return{x:n*Math.sin(i),y:Math.sin(e),z:-n*Math.cos(i)}}static cross(t,e){return{x:t.y*e.z-t.z*e.y,y:t.z*e.x-t.x*e.z,z:t.x*e.y-t.y*e.x}}static normalise(t){const e=Math.hypot(t.x,t.y,t.z)||1;return{x:t.x/e,y:t.y/e,z:t.z/e}}static TYPICAL_VELOCITY_KM_S=40}const Tg="https://ufoathome.org/tle/index.json";class Oi{static MAX_ELEMENT_AGE_DAYS=7;static DAY_MS=864e5;fetchImpl;indexUrls;index;files=new Map;constructor(t={}){this.fetchImpl=t.fetchImpl??fetch.bind(globalThis),this.indexUrls=t.indexUrls??Oi.defaultIndexUrls()}static defaultIndexUrls(){const t=[];return typeof location<"u"&&/^https?:$/.test(location.protocol)&&t.push(new URL("/tle/index.json",location.href).href),t.includes(Tg)||t.push(Tg),t}static FIRST_SNAPSHOT="2021-02-22";async covers(t){const e=Date.parse(`${Oi.FIRST_SNAPSHOT}T00:00:00Z`)-Oi.MAX_ELEMENT_AGE_DAYS*Oi.DAY_MS;if(t.getTime()<e)return!1;const i=await this.loadIndex();return i?Object.values(i.index.kinds).some(n=>t.getTime()>=Date.parse(n.from)-Oi.MAX_ELEMENT_AGE_DAYS*Oi.DAY_MS&&t.getTime()<=Date.parse(n.to)+Oi.MAX_ELEMENT_AGE_DAYS*Oi.DAY_MS):!1}async at(t){const e=await this.loadIndex();if(!e)return;const{index:i,base:n}=e,s=[],r=[];for(const o of Object.keys(i.kinds)){const c=await this.kindAt(o,t,i,n);s.push(...c),r.push(this.coverageOf(o,t,i,c.length>0))}return{objects:s,coverage:r,credit:i.credit,creditUrl:i.source}}async kindAt(t,e,i,n){const s=e.getTime(),r=i.binDays*Oi.DAY_MS,o=Math.floor(s/r),c=s-o*r<r/2?o-1:o+1,l=new Set(i.kinds[t].bins),h=[o,c].map(v=>new Date(v*r).toISOString().slice(0,10)).filter(v=>l.has(v));if(h.length===0)return[];const[u,...d]=await Promise.all([this.json(new URL(`objects-${t}.json`,n).href),...h.map(v=>this.binary(new URL(`${t}/${v}.bin`,n).href))]),f=new Map;for(const v of d)for(const m of Oi.decode(v,i.recordBytes)){const g=f.get(m.norad);(!g||Math.abs(m.epochMs-s)<Math.abs(g.epochMs-s))&&f.set(m.norad,m)}const p=[];for(const v of f.values()){const m=Math.abs(v.epochMs-s)/Oi.DAY_MS;if(m>Oi.MAX_ELEMENT_AGE_DAYS)continue;const g=u[v.norad]??{name:String(v.norad)};g.launch&&Date.parse(`${g.launch}T00:00:00Z`)>s||p.push({norad:v.norad,name:g.name,kind:t,launch:g.launch,stdMag:g.stdMag,elements:v,ageDays:m})}return p}coverageOf(t,e,i,n){const{from:s,to:r}=i.kinds[t],o=e.getTime(),c=Oi.MAX_ELEMENT_AGE_DAYS*Oi.DAY_MS,l=n?"covered":o<Date.parse(s)-c?"before":o>Date.parse(r)+c?"after":"gap";return{kind:t,status:l,from:s,to:r}}static decode(t,e){const i=new DataView(t),n=[];for(let s=0;s+e<=t.byteLength;s+=e)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 t of this.indexUrls)try{const e=await this.fetchImpl(t);if(!e.ok)continue;return{index:await e.json(),base:t}}catch{}})(),this.index}json(t){return this.cached(t,async e=>e.json())}binary(t){return this.cached(t,async e=>e.arrayBuffer())}cached(t,e){let i=this.files.get(t);return i||(i=this.fetchImpl(t).then(n=>{if(!n.ok)throw new Error(`${t}: ${n.status}`);return e(n)}),i.catch(()=>this.files.delete(t)),this.files.set(t,i)),i}}class AA{lowerM;upperM;add(t,e){if(!(t<=0)){if(e.behindM!==void 0){const i=Ie.sizeMAt(e.behindM,t);this.lowerM=this.lowerM===void 0?i:Math.max(this.lowerM,i)}if(e.inFrontM!==void 0){const i=Ie.sizeMAt(e.inFrontM,t);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(t){return t<=0?{}:{minM:this.lowerM===void 0?void 0:Ie.distanceMAt(this.lowerM,t),maxM:this.upperM===void 0?void 0:Ie.distanceMAt(this.upperM,t)}}clear(){this.lowerM=void 0,this.upperM=void 0}}class Wr{static DEG_PER_SECOND=360/86164.0905;static degOver(t){return Math.max(0,t)*Wr.DEG_PER_SECOND}static instants(t,e){if(!(e>0))return 1;const i=Wr.degOver(t)/e;return i<1?1:Math.min(Wr.MAX_INSTANTS,Math.max(2,Math.ceil(i)))}static MAX_INSTANTS=64}class Vi{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 Wr.DEG_PER_SECOND*3600}static graspOf(t,e={}){const i=e.exposureSeconds??t.exposureSeconds,n=e.fNumber??t.fNumber;if(i===void 0||n===void 0||!(i>0)||!(n>0))return Vi.EYE;const s=e.focalLengthMm??t.frame?.focalLengthMm??Vi.UNKNOWN_CAMERA_FOCAL_MM,r=s/n,o=Vi.resolutionArcsec(t,s,r);return{apertureMm:r,exposureSeconds:Math.min(i,Vi.trailLimitedSeconds(o)),resolutionArcsec:o}}static resolutionArcsec(t,e,i){const s=(t.detailUm??Vi.UNKNOWN_CAMERA_DETAIL_UM)/1e3/e*Vi.ARCSEC_PER_RADIAN,r=1.22*Vi.WAVELENGTH_M/(i/1e3)*Vi.ARCSEC_PER_RADIAN;return Math.max(s,r)}static trailLimitedSeconds(t){return t/Vi.skyDriftArcsecPerSecond}static gainOverEye(t,e={}){const i=Vi.graspOf(t,e),n=Vi.EYE,s=(i.apertureMm/n.apertureMm)**2,r=i.exposureSeconds/n.exposureSeconds,o=(n.resolutionArcsec/i.resolutionArcsec)**2;return 1.25*Math.log10(s*r*o)}static gainFor(t,e){const i=e.fieldOfViewDeg===void 0?void 0:mi.focalLengthMmFor(t,e.fieldOfViewDeg);return Vi.gainOverEye(t,{fNumber:e.fNumber,focalLengthMm:i,exposureSeconds:e.exposureSeconds})}}const Rg=111320,Co=Math.PI/180,TA=1.02,RA=1;class Ko{static of(t,e){const i=Ko.sightings(t,e);if(i.length<2)return;const n=Ko.baseline(i);if(!n)return;const{near:s,far:r,closedM:o}=n,c=Math.tan(r.widthDeg/2*Co)===0?0:Math.tan(s.widthDeg/2*Co)/Math.tan(r.widthDeg/2*Co);if(c<TA)return;const l=o/(c-1),h=Ie.sizeMAt(l,s.widthDeg),u=i.map(d=>({t:d.t,m:Ie.distanceMAt(h,d.widthDeg)}));return{widthM:h,distanceM:u,nearestM:Math.min(...u.map(d=>d.m)),fromT:r.t,toT:s.t,closedM:o}}static sightings(t,e){return t.timeline.allKeyframes.flatMap(i=>{const n=i.shapes.find(o=>o.sourceId===e)?.shape,s=n?.angular?.widthDeg,r=Je(t,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(t){let e;for(const i of t)for(const n of t){if(i.t>=n.t)continue;const s=Ko.closedAlongSight(i,n),[r,o,c]=s>=0?[n,i,s]:[i,n,-s];c<RA||r.widthDeg<=o.widthDeg||(!e||c>e.closedM)&&(e={near:r,far:o,closedM:c})}return e}static closedAlongSight(t,e){const i=(e.lat-t.lat)*Rg,n=(e.lng-t.lng)*Rg*Math.cos(t.lat*Co),s=(t.sightAzimuthDeg??0)*Co;return i*Math.cos(s)+n*Math.sin(s)}}class Gi{static CONVENTIONAL_M=5;static NEAREST_M=.2;static MARGIN=1.1;static resolve(t){if(t.statedM!==void 0&&t.statedM>0)return{distanceM:Gi.atLeastNearest(t.statedM),basis:"stated"};if(t.hypothesisM!==void 0&&t.hypothesisM>0)return{distanceM:Gi.atLeastNearest(t.hypothesisM),basis:"hypothesis"};if(t.derivedM!==void 0&&t.derivedM>0)return{distanceM:Gi.atLeastNearest(t.derivedM),basis:"derived"};const e=Gi.largest(t.range?.minM,t.crossing?.behindM),i=Gi.smallest(t.range?.maxM,t.crossing?.inFrontM),n=e===void 0?void 0:e*Gi.MARGIN,s=i===void 0?void 0:i/Gi.MARGIN;return n!==void 0&&s!==void 0?{distanceM:Gi.atLeastNearest(n<=s?Math.sqrt(n*s):n),basis:"bounded"}:n!==void 0?{distanceM:Gi.atLeastNearest(n),basis:"bounded"}:s!==void 0&&s<Gi.CONVENTIONAL_M?{distanceM:Gi.atLeastNearest(s),basis:"bounded"}:{distanceM:Gi.CONVENTIONAL_M,basis:"conventional"}}static atLeastNearest(t){return Math.max(Gi.NEAREST_M,t)}static largest(...t){const e=t.filter(i=>i!==void 0&&i>0);return e.length===0?void 0:Math.max(...e)}static smallest(...t){const e=t.filter(i=>i!==void 0&&i>0);return e.length===0?void 0:Math.min(...e)}}const $u=Math.PI/180;class ne{constructor(t,e,i){this.body=t,this.ground=e;const n=[...t.track].sort((s,r)=>s.t-r.t);this.keys=this.place(n,i);for(const s of n)ne.collect(this.motionKeys,s.t,s.motions),ne.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};keys;motionKeys=new Map;lightKeys=new Map;static collect(t,e,i){for(const[n,s]of Object.entries(i??{})){const r=t.get(n)??[];r.push({t:e,value:s}),t.set(n,r)}}motionsAt(t){return ne.channelsAt(this.motionKeys,t,0)}lightsAt(t){return this.lightKeys.size>0?ne.channelsAt(this.lightKeys,t,void 0):void 0}static channelsAt(t,e,i){const n={};for(const[s,r]of t){let o=r.length-1;for(;o>=0&&r[o].t>e;)o--;if(o<0){i!==void 0&&(n[s]=i);continue}const c=r[o],l=r[Math.min(o+1,r.length-1)],h=l===c||l.t===c.t?0:Math.min(1,(e-c.t)/(l.t-c.t));n[s]=ne.lerp(c.value,l.value,h)}return n}static eyeOf(t,e,i){const n=Je(t,0),s=Je(t,e),o=n?.lat!==void 0&&n.lng!==void 0&&s?.lat!==void 0&&s.lng!==void 0?je(s.lat,s.lng,n.lat,n.lng):void 0,c=o?o.x:0,l=o?-o.z:0;return{eastM:c,northM:l,upM:i.heightAt(c,l)+ne.EYE_HEIGHT_M+(s?.elevationM??0),headingDeg:s?.headingDeg}}static lineOfSightMeetsGround(t,e,i,n){const s=ne.directionOf(e,i),r=l=>t.upM+s.upM*l-n.heightAt(t.eastM+s.eastM*l,t.northM+s.northM*l);let o=0,c=0;for(;c<ne.MAX_RANGE_M;){if(c=o+Math.max(.5,o*.01),r(c)<=0){for(let l=0;l<30;l++){const h=(o+c)/2;r(h)<=0?c=h:o=h}return c}o=c}}static directionOf(t,e){const i=t*$u,n=e*$u;return{eastM:Math.sin(i)*Math.cos(n),northM:Math.cos(i)*Math.cos(n),upM:Math.sin(n)}}at(t){const e=this.keys;if(e.length===0||t<e[0].t)return;let i=e.length-1;for(;i>0&&e[i].t>t;)i--;const n=e[i];if(!n.present)return;const s=e[Math.min(i+1,e.length-1)],r=s===n||s.t===n.t?0:Math.min(1,(t-n.t)/(s.t-n.t)),o=ne.lerp(n.eastM,s.eastM,r),c=ne.lerp(n.northM,s.northM,r),l={widthM:ne.lerp(n.sizeM.widthM,s.sizeM.widthM,r),lengthM:ne.lerp(n.sizeM.lengthM,s.sizeM.lengthM,r),heightM:ne.lerp(n.sizeM.heightM,s.sizeM.heightM,r)},h={headingDeg:ne.lerpAngle(n.attitude.headingDeg,s.attitude.headingDeg,r),pitchDeg:ne.lerp(n.attitude.pitchDeg,s.attitude.pitchDeg,r),rollDeg:ne.lerp(n.attitude.rollDeg,s.attitude.rollDeg,r)};let u;if("aboveGroundM"in n.vertical&&"aboveGroundM"in s.vertical){const d=ne.lerp(n.vertical.aboveGroundM,s.vertical.aboveGroundM,r);u=this.groundUnderFootprint(o,c,l,h.headingDeg)+d+l.heightM/2}else u=ne.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:o,northM:c,upM:u,sizeM:l,attitude:h,appearance:{color:(r<1?n:s).appearance.color,albedo:ne.lerp(n.appearance.albedo,s.appearance.albedo,r),luminanceCdM2:ne.lerp(n.appearance.luminanceCdM2,s.appearance.luminanceCdM2,r)},flame:ne.flameBetween(n.flame,s.flame,r),motions:this.motionsAt(t),lights:this.lightsAt(t),throwsFlame:this.body.track.some(d=>d.flame!==void 0&&d.flame.luminanceCdM2>0)}}static flameBetween(t,e,i){if(!t||t.luminanceCdM2<=0)return i>=1&&e&&e.luminanceCdM2>0?e:void 0;const n=t,s=e??t,r={...i<1?n:s,lengthM:ne.lerp(n.lengthM,s.lengthM,i),widthM:ne.lerp(n.widthM,s.widthM,i),luminanceCdM2:ne.lerp(n.luminanceCdM2,s.luminanceCdM2,i)};return r.luminanceCdM2>0?r:void 0}centreUpOf(t){return"upM"in t.vertical?t.vertical.upM:this.groundUnderFootprint(t.eastM,t.northM,t.sizeM,t.attitude.headingDeg)+t.vertical.aboveGroundM+t.sizeM.heightM/2}groundUnderFootprint(t,e,i,n){const s=n*$u,r={eastM:Math.cos(s),northM:-Math.sin(s)},o={eastM:Math.sin(s),northM:Math.cos(s)};let c=this.ground.heightAt(t,e);for(const[l,h]of[[-1,-1],[1,-1],[-1,1],[1,1]]){const u=l*i.widthM/2,d=h*i.lengthM/2;c=Math.max(c,this.ground.heightAt(t+r.eastM*u+o.eastM*d,e+r.northM*u+o.northM*d))}return c}place(t,e){const i=[];let n;for(const s of t){const r=s.sizeM??n?.sizeM??ne.DEFAULT_SIZE,o={headingDeg:s.attitude?.headingDeg??n?.attitude.headingDeg??0,pitchDeg:s.attitude?.pitchDeg??n?.attitude.pitchDeg??0,rollDeg:s.attitude?.rollDeg??n?.attitude.rollDeg??0},c={color:s.appearance?.color??n?.appearance.color??ne.DEFAULT_APPEARANCE.color,albedo:s.appearance?.albedo??n?.appearance.albedo??ne.DEFAULT_APPEARANCE.albedo,luminanceCdM2:s.appearance?.luminanceCdM2??n?.appearance.luminanceCdM2??ne.DEFAULT_APPEARANCE.luminanceCdM2},l=this.positionOf(s,e)??(n&&{eastM:n.eastM,northM:n.northM,vertical:this.verticalOf(s)??n.vertical});if(!l)continue;const h=s.flame??n?.flame,u=s.present??n?.present??!0;n={t:s.t,...l,sizeM:r,attitude:o,appearance:c,flame:h,present:u},i.push(n)}return i}verticalOf(t){if(t.onGround)return{aboveGroundM:0};if(t.altitudeAboveGroundM!==void 0)return{aboveGroundM:t.altitudeAboveGroundM}}positionOf(t,e){if(t.eastM!==void 0&&t.northM!==void 0)return{eastM:t.eastM,northM:t.northM,vertical:this.verticalOf(t)??{aboveGroundM:0}};if(t.azimuthDeg===void 0||t.altitudeDeg===void 0)return;const i=e(t.t);if(!i)return;const n=t.distanceM??(t.onGround?ne.lineOfSightMeetsGround(i,t.azimuthDeg,t.altitudeDeg,this.ground):void 0);if(n===void 0)return;const s=ne.directionOf(t.azimuthDeg,t.altitudeDeg),r=i.eastM+s.eastM*n,o=i.northM+s.northM*n;return{eastM:r,northM:o,vertical:this.verticalOf(t)??{upM:i.upM+s.upM*n}}}static lerp(t,e,i){return t+(e-t)*i}static lerpAngle(t,e,i){const n=((e-t)%360+540)%360-180;return((t+n*i)%360+360)%360}}class ge{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(t,e){const i=t.track;if(i.length<2||e<i[0].t||e>i[i.length-1].t)return;let n=0;for(;n<i.length-2&&i[n+1].t<e;)n++;const s=i[n],r=i[n+1],o=r.t-s.t,c=o>0?(e-s.t)/o:0,[l,h]=ge.alongGreatCircle(s,r,c);return{lat:l,lng:h,heightM:(s.altitudeKm+(r.altitudeKm-s.altitudeKm)*c)*1e3}}static viewsAt(t,e,i){const n=[];for(const s of t){const r=s.track[0]?.t??0,o=s.track[s.track.length-1]?.t??0;s.fragments.forEach((c,l)=>{const h=c.fromT??r,u=c.untilT??o;if(e<h||e>u)return;const d=(c.lagS??0)*1e3,f=ge.leadAt(s,e-d);if(!f)return;const p=ge.seenFrom(i,f);if(p.altitudeDeg<0)return;const v=Math.min(ge.FADE_MS,(u-h)/4),m=v>0?Math.min(1,(e-h)/v,(u-e)/v):1,g=-2.5*Math.log10(Math.max(m,.001)),S=c.absoluteMagnitude+5*Math.log10(p.distanceKm/ge.STANDARD_DISTANCE_KM)+g,x=[p],M=(c.trainS??ge.DEFAULT_TRAIN_S)*1e3;for(let b=1;b<=ge.TRAIN_POINTS;b++){const w=Math.min(M*b/ge.TRAIN_POINTS,e-h),T=ge.leadAt(s,e-d-w);if(!T||(x.push(ge.seenFrom(i,T)),w>=e-h))break}n.push({reentryId:s.id,fragmentId:c.id??String(l),head:p,magnitude:S,color:c.color??ge.DEFAULT_COLOR,train:x})})}return n}static seenFrom(t,e){const i=ge.ecef(t),n=ge.ecef(e),s=n[0]-i[0],r=n[1]-i[1],o=n[2]-i[2],c=t.lat*ge.DEG,l=t.lng*ge.DEG,h=-Math.sin(l)*s+Math.cos(l)*r,u=-Math.sin(c)*Math.cos(l)*s-Math.sin(c)*Math.sin(l)*r+Math.cos(c)*o,d=Math.cos(c)*Math.cos(l)*s+Math.cos(c)*Math.sin(l)*r+Math.sin(c)*o,f=Math.hypot(h,u,d);return{altitudeDeg:Math.asin(d/f)/ge.DEG,azimuthDeg:(Math.atan2(h,u)/ge.DEG+360)%360,distanceKm:f/1e3}}static ecef(t){const e=t.lat*ge.DEG,i=t.lng*ge.DEG,n=Math.sin(e),s=ge.A/Math.sqrt(1-ge.E2*n*n);return[(s+t.heightM)*Math.cos(e)*Math.cos(i),(s+t.heightM)*Math.cos(e)*Math.sin(i),(s*(1-ge.E2)+t.heightM)*n]}static alongGreatCircle(t,e,i){const n=h=>{const u=h.lat*ge.DEG,d=h.lng*ge.DEG;return[Math.cos(u)*Math.cos(d),Math.cos(u)*Math.sin(d),Math.sin(u)]},s=n(t),r=n(e),o=Math.max(-1,Math.min(1,s[0]*r[0]+s[1]*r[1]+s[2]*r[2])),c=Math.acos(o);let l;if(c<1e-12)l=s;else{const h=Math.sin((1-i)*c)/Math.sin(c),u=Math.sin(i*c)/Math.sin(c);l=[s[0]*h+r[0]*u,s[1]*h+r[1]*u,s[2]*h+r[2]*u]}return[Math.atan2(l[2],Math.hypot(l[0],l[1]))/ge.DEG,Math.atan2(l[1],l[0])/ge.DEG]}}class pf{static FIRST_DAY="2022-01-01";static mayCover(t){return new Date(t).toISOString().slice(0,10)>=pf.FIRST_DAY}}class DA{constructor(t,e,i){this.citation=t,this.covers=e,this.load=i}loading;mayCover(t){return this.covers(t)}async between(t,e,i,n){try{return await(await this.provider()).between(t,e,i,n)}catch{return{status:"failed"}}}async describe(t,e){try{return await(await this.provider()).describe?.(t,e)}catch{return}}provider(){if(!this.loading){const t=this.load();this.loading=t,t.catch(()=>{this.loading===t&&(this.loading=void 0)})}return this.loading}}const IA="Aircraft positions: adsb.lol feeders and contributors, Open Database License 1.0 (https://www.adsb.lol/docs/open-data/historical/)",CA=[{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 DA(IA,a=>pf.mayCover(a),async()=>new(await $i(async()=>{const{AdsbLolArchiveProvider:a}=await import("./AdsbLolArchiveProvider-2vNkvjL5.js");return{AdsbLolArchiveProvider:a}},[],import.meta.url)).AdsbLolArchiveProvider)}];class Wi{static MAX_GAP_S=60;static FT_TO_M=.3048;static EARTH_RADIUS_KM=6371;static seenFrom(t,e,i){const n=Wi.positionAt(t,i);if(!n)return;const s=ge.seenFrom(e,n.geo);if(!(s.altitudeDeg<0))return{track:t,sky:s,altitudeFt:n.altitudeFt,groundSpeedKt:n.groundSpeedKt,trackDeg:n.trackDeg,angularRateDegPerS:Wi.angularRate(t,e,i)}}static viewsAt(t,e,i){return t.flatMap(n=>Wi.seenFrom(n,e,i)??[])}static groundDistanceKm(t,e){const i=Math.PI/180,n=Math.sin((e.lat-t.lat)*i/2)**2+Math.cos(t.lat*i)*Math.cos(e.lat*i)*Math.sin((e.lng-t.lng)*i/2)**2;return 2*Wi.EARTH_RADIUS_KM*Math.asin(Math.min(1,Math.sqrt(n)))}static wrapLongitude(t){return((t+180)%360+360)%360-180}static positionAt(t,e){const i=t.points;if(i.length===0||e<i[0].t||e>i[i.length-1].t)return;let n=0;for(;n<i.length-1&&i[n+1].t<=e;)n++;const s=i[n],r=i[n+1]??s,o=r.t-s.t;if(o>Wi.MAX_GAP_S*1e3)return;const c=o>0?(e-s.t)/o:0,l=s.altitudeFt+(r.altitudeFt-s.altitudeFt)*c,h=(r.lng-s.lng+540)%360-180;return{geo:{lat:s.lat+(r.lat-s.lat)*c,lng:Wi.wrapLongitude(s.lng+h*c),heightM:l*Wi.FT_TO_M},altitudeFt:l,groundSpeedKt:s.groundSpeedKt,trackDeg:s.trackDeg}}static angularRate(t,e,i){const n=Wi.positionAt(t,i-500),s=Wi.positionAt(t,i+500);if(!n||!s)return;const r=Wi.unit(ge.seenFrom(e,n.geo)),o=Wi.unit(ge.seenFrom(e,s.geo)),c=Math.min(1,Math.max(-1,r[0]*o[0]+r[1]*o[1]+r[2]*o[2]));return Math.acos(c)*180/Math.PI}static unit(t){const e=t.altitudeDeg*Math.PI/180,i=t.azimuthDeg*Math.PI/180;return[Math.cos(e)*Math.sin(i),Math.cos(e)*Math.cos(i),Math.sin(e)]}}const Dg="https://ufoathome.org/fireballs/index.json";class fs{static FIRST_MONTH="2018-12";static STRIKING_MAGNITUDE=-1;static COLOR="#eef2ff";static TRAIN_S=.3;fetchImpl;indexUrls;index;months=new Map;constructor(t={}){this.fetchImpl=t.fetchImpl??fetch.bind(globalThis),this.indexUrls=t.indexUrls??fs.defaultIndexUrls()}static defaultIndexUrls(){const t=[];return typeof location<"u"&&/^https?:$/.test(location.protocol)&&t.push(new URL("/fireballs/index.json",location.href).href),t.includes(Dg)||t.push(Dg),t}static mayCover(t){return new Date(t).toISOString().slice(0,7)>=fs.FIRST_MONTH}async credit(){return(await this.loadIndex())?.index.credit}async between(t,e){if(!fs.mayCover(e))return;const i=await this.loadIndex();if(!i)return;const n=new Set([new Date(t).toISOString().slice(0,7),new Date(e).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>=t&&r.t<=e):void 0}static seenFrom(t,e){const i=fs.peakFraction(t),n={lat:t.from[0]+(t.to[0]-t.from[0])*i,lng:t.from[1]+(t.to[1]-t.from[1])*i,heightM:t.peakHeightKm*1e3},s=ge.seenFrom(e,n);if(!(s.altitudeDeg<0))return{record:t,peak:s,magnitude:t.peakMagnitude+5*Math.log10(s.distanceKm/ge.STANDARD_DISTANCE_KM)}}static asReentry(t,e){const i=t.t-e,n=i+Math.max(t.durationS,.1)*1e3;return{id:`gmn-${t.id}`,track:[{t:i,lat:t.from[0],lng:t.from[1],altitudeKm:t.from[2]},{t:n,lat:t.to[0],lng:t.to[1],altitudeKm:t.to[2]}],fragments:[{absoluteMagnitude:t.peakMagnitude,color:fs.COLOR,trainS:fs.TRAIN_S}]}}static peakFraction(t){const e=t.from[2]-t.to[2];return Math.abs(e)<1e-6?.5:Math.min(1,Math.max(0,(t.from[2]-t.peakHeightKm)/e))}loadIndex(){return this.index??=(async()=>{for(const t of this.indexUrls)try{const e=await this.fetchImpl(t);if(e.ok)return{index:await e.json(),base:t}}catch{}})(),this.index}monthOf(t,e){let i=this.months.get(t);return i||(i=this.fetchImpl(new URL(`${t}.json`,e).href).then(n=>n.ok?n.json():[]).catch(()=>[]),this.months.set(t,i)),i}}const Ea=Math.PI/180,Po=180/Math.PI;class ri{constructor(t){this.timeline=t}static DIRECTION_TOLERANCE_DEG=1;static SIZE_TOLERANCE=1.5;static RINGS=12;static SEGMENTS=24;at(t,e,i,n){const s=[];for(const r of e){const o=ri.projectionOf(r,i,n?.(r));if(o)for(const c of r.explains){const l=this.timeline.getInterpolatedShapeAt(t,c);!l||l.transparency>=1||s.push({...ri.compare(c,r.id,{aim:l.aim,angular:l.angular},o),title:l.title})}}return s}static compare(t,e,i,n){const s=[],r=i.aim?ri.separationDeg(i.aim,n.aim):void 0;if(r!==void 0){const l=Math.max(i.angular?.widthDeg??0,n.angular.widthDeg)/2;r>Math.max(ri.DIRECTION_TOLERANCE_DEG,l)&&s.push("direction")}const o=i.angular&&i.angular.widthDeg>0?n.angular.widthDeg/i.angular.widthDeg:void 0,c=i.angular&&i.angular.heightDeg>0?n.angular.heightDeg/i.angular.heightDeg:void 0;return o!==void 0&&!ri.withinSize(o)&&s.push("width"),c!==void 0&&!ri.withinSize(c)&&s.push("height"),{sourceId:t,bodyId:e,stated:i,predicted:n,separationDeg:r,widthRatio:o,heightRatio:c,disagreements:s}}static projectionOf(t,e,i){const n=i&&i.length>0?i:ri.outlineOf(t),s=i&&i.length>0?ri.centreOf(i):t,r=ri.normalized({eastM:s.eastM-e.eastM,northM:s.northM-e.northM,upM:s.upM-e.upM});if(!r)return;const o=ri.normalized({eastM:r.northM,northM:-r.eastM,upM:0})??{eastM:1,northM:0,upM:0},c=ri.cross(o,r);let l=1/0,h=-1/0,u=1/0,d=-1/0;for(const f of n){const p={eastM:f.eastM-e.eastM,northM:f.northM-e.northM,upM:f.upM-e.upM},v=ri.dot(p,r);if(v<=0)return;const m=Math.atan2(ri.dot(p,o),v),g=Math.atan2(ri.dot(p,c),v);l=Math.min(l,m),h=Math.max(h,m),u=Math.min(u,g),d=Math.max(d,g)}return{aim:{azimuthDeg:(Math.atan2(r.eastM,r.northM)*Po+360)%360,altitudeDeg:Math.asin(Math.max(-1,Math.min(1,r.upM)))*Po},angular:{widthDeg:(h-l)*Po,heightDeg:(d-u)*Po}}}static centreOf(t){const e=i=>(Math.min(...t.map(n=>n[i]))+Math.max(...t.map(n=>n[i])))/2;return{eastM:e("eastM"),northM:e("northM"),upM:e("upM")}}static separationDeg(t,e){const i=t.altitudeDeg*Ea,n=e.altitudeDeg*Ea,s=Math.sin(i)*Math.sin(n)+Math.cos(i)*Math.cos(n)*Math.cos((t.azimuthDeg-e.azimuthDeg)*Ea);return Math.acos(Math.max(-1,Math.min(1,s)))*Po}static withinSize(t){return t<=ri.SIZE_TOLERANCE&&t>=1/ri.SIZE_TOLERANCE}static outlineOf(t){const e=t.sizeM.widthM/2,i=t.sizeM.lengthM/2,n=t.sizeM.heightM/2,s=[],r=t.model.url===void 0?t.model.id:void 0;if(r!==void 0&&r!=="box"&&Mv.includes(r))for(let u=0;u<=ri.RINGS;u++){const d=u/ri.RINGS*Math.PI;for(let f=0;f<ri.SEGMENTS;f++){const p=f/ri.SEGMENTS*2*Math.PI;s.push([e*Math.sin(d)*Math.cos(p),i*Math.sin(d)*Math.sin(p),n*Math.cos(d)])}}else for(const u of[-e,e])for(const d of[-i,i])for(const f of[-n,n])s.push([u,d,f]);const c=t.attitude.headingDeg*Ea,l=t.attitude.pitchDeg*Ea,h=t.attitude.rollDeg*Ea;return s.map(([u,d,f])=>{const p=u*Math.cos(h)+f*Math.sin(h),v=-u*Math.sin(h)+f*Math.cos(h),m=d*Math.cos(l)-v*Math.sin(l),g=d*Math.sin(l)+v*Math.cos(l);return{eastM:t.eastM+p*Math.cos(c)+m*Math.sin(c),northM:t.northM-p*Math.sin(c)+m*Math.cos(c),upM:t.upM+g}})}static dot(t,e){return t.eastM*e.eastM+t.northM*e.northM+t.upM*e.upM}static cross(t,e){return{eastM:t.northM*e.upM-t.upM*e.northM,northM:t.upM*e.eastM-t.eastM*e.upM,upM:t.eastM*e.northM-t.northM*e.eastM}}static normalized(t){const e=Math.hypot(t.eastM,t.northM,t.upM);return e>1e-9?{eastM:t.eastM/e,northM:t.northM/e,upM:t.upM/e}:void 0}}Jg();const PA={sun:"Sun",moon:"Moon",Venus:"Venus",Mars:"Mars",Jupiter:"Jupiter",Saturn:"Saturn"},LA="{name} — mag {mag}, {alt}° above the horizon",OA="{name} — satellite, mag {mag}, {height} km up",NA="satellites-change",FA="fireballs-change",UA="aircraft-change",kA="rr0-confrontation",zA="{name} — mag {mag}, {alt}° below the horizontal",Ku="Credits",Ig="comet:",Cg="nova:",Pg={building:"Building",tree:"Tree",shrub:"Shrub",bridge:"Bridge",wire:"Overhead line",crop:"Crop row",mound:"Stone heap",streetlight:"Streetlight",vehicle:"Vehicle",observer:"Observer",aircraft:"Aircraft",entity:"Being"},BA=new URL(""+new URL("stars-mag7.5-B43R6Wvg.bin",import.meta.url).href,import.meta.url).href,HA=new URL(""+new URL("stars-mag7.5-9-BLV2tFmZ.bin",import.meta.url).href,import.meta.url).href,GA=-18,VA={sun:{altitudeDeg:-3,azimuthDeg:180,magnitude:-26.7},moon:{altitudeDeg:-90,azimuthDeg:0,phase:{phaseFraction:0,illuminatedFraction:0},magnitude:-12.7},planets:[]},bl={lat:0,lng:0,elevationM:0,headingDeg:void 0,pitchDeg:0,fovDeg:60};class We extends HTMLElement{creditsButton;set ownCredits(t){this.creditsButton.hidden=!t}static get observedAttributes(){return["src","star-catalog-src","deep-star-catalog-src","show-compass","max-pixel-ratio",ka,za]}shadow;stageElement;frameElement;sceneCanvas;loaderNote;loaderNotVideo;ufoElement;sceneRenderer;hoverTooltip;resizeObserver;sizeEstimates=new Map;sizeEstimatesFor;distanceHypotheses=new Map;depths=new Map;directionScratch=new R;meteorScheduleFor;lightningScheduleFor;lightningFlashes=[];lastLightningT;lastTimeMs=0;interpretationShown;confrontationReadings=[];confrontationSignature="";comparing=!1;inTheRound=!0;lastSkyKey;starCatalog;starCatalogRequest=0;static tleArchive=new Oi;satellitesFor;satelliteRequest=0;satelliteStatus="none";satellites;satellitePassesMemo;static fireballArchive=new fs;fireballs;static aircraftProviders=new Map;static SOUND_LOOKBACK_MS=3e5;static NO_CONTRAILS=[];static upperAirProviders=new Map;static NO_PRESENCE=new Map;aircraftSource=CA[0];static trafficRuntimeLoading;static trafficRuntime;static loadTrafficRuntime(){return We.trafficRuntimeLoading??=$i(()=>import("./trafficRuntime-VEoNI8g9.js"),__vite__mapDeps([2,1]),import.meta.url).then(t=>We.trafficRuntime=t),We.trafficRuntimeLoading.catch(()=>{We.trafficRuntimeLoading=void 0}),We.trafficRuntimeLoading}traffic;lastSun;decorMemo;starCatalogDepth=0;weatherAudio=new bA;vehicleAudio=new Ov;aircraftAudio;vehicleHearing=new Fl;thunderTimeoutId;handleFullscreenChange=()=>this.resizeToStage();handlePointerMove=t=>{this.sceneRenderer.setCompassHovered(!0);const e=this.ufoElement.canvasElement,i=e.getBoundingClientRect();if(i.width===0||i.height===0)return;const n=(t.clientX-i.left)/i.width*e.width,s=(t.clientY-i.top)/i.height*e.height;if(this.ufoElement.hasVisibleShapeAt(n,s)){this.hoverTooltip.hidden=!0;return}const r=(t.clientX-i.left)/i.width*2-1,o=-((t.clientY-i.top)/i.height*2-1),c=this.naming,l=c.names,h=this.sceneRenderer.pickBodyAt(r,o);if(h){this.showHoverTooltip(t,this.bodyName(h));return}const u=this.interpretationShown?this.sceneRenderer.pickInterpretationBodyAt(r,o):void 0,d=u?this.interpretationShown?.bodies.find(x=>x.id===u):void 0,f=d?this.said.read(d.title)||(d.model.id==="figure"?c.decorKind("entity",Pg.entity):void 0):void 0;if(f){this.showHoverTooltip(t,f);return}const p=this.sceneRenderer.pickDecorAt(r,o),v=p?this.ufoElement.sighting.decor.find(x=>x.id===p):void 0;if(v){this.showHoverTooltip(t,this.said.read(v.title)||c.decorKind(v.kind,Pg[v.kind]));return}const m=this.trafficTooltipAt(r,o);if(m){this.showHoverTooltip(t,m);return}const g=this.sceneRenderer.pickSatelliteAt(r,o);if(g){this.showHoverTooltip(t,(l?.satelliteTooltip??OA).replace("{name}",g.name).replace("{mag}",g.magnitude.toLocaleString(void 0,{maximumFractionDigits:1})).replace("{height}",Math.round(g.heightKm).toLocaleString()));return}const S=this.sceneRenderer.pickStarAt(r,o);if(S){const x=S.star.mag,M=S.altitudeDeg,b=M<0?l?.starTooltipBelow??zA:l?.starTooltip??LA;this.showHoverTooltip(t,b.replace("{name}",c.star(S.star)).replace("{mag}",x.toLocaleString(void 0,{maximumFractionDigits:Math.abs(x)<1?2:1})).replace("{alt}",String(Math.round(Math.abs(M)))));return}this.hoverTooltip.hidden=!0};bodyName(t){const e=t.startsWith(Ig)?t.slice(Ig.length):void 0,i=e?_v.find(r=>r.id===e):void 0;if(i)return this.naming.comet(i);const n=t.startsWith(Cg)?Ag.byId(t.slice(Cg.length)):void 0;if(n)return this.naming.nova(n);const s=PA[t];return s===void 0?t:this.naming.body(t,s)}get naming(){return this.sceneNaming}sceneNaming=new Eg;namesLanguage="en";async loadSceneNames(){const t=zg(Ua.preferencesFor(this),Bg);if(t===this.namesLanguage)return;this.namesLanguage=t;const e=await b2(t);t===this.namesLanguage&&this.applySceneNaming(new Eg(e))}renderLoaderText(t,e){let i=0;const n=(s,r)=>{s.setAttribute("aria-label",r),s.replaceChildren(),r.split(" ").forEach((o,c)=>{c>0&&s.append(" ");const l=document.createElement("span");l.className="scene-loader-word",l.setAttribute("aria-hidden","true");for(const h of o){const u=document.createElement("span");u.className="scene-loader-letter",u.style.setProperty("--i",String(i++)),u.textContent=h,l.append(u)}s.append(l),i++})};n(this.loaderNotVideo,t),i+=6,n(this.loaderNote,e)}applySceneNaming(t){this.sceneNaming=t;const e=t.names?.credits??Ku;this.creditsButton.title=e,this.creditsButton.setAttribute("aria-label",e),t.names&&this.renderLoaderText(t.names.notAVideo,t.names.isASimulation),this.sceneRenderer.setCompassPoints(t.names?.compassPoints)}showHoverTooltip(t,e){this.hoverTooltip.textContent=e,this.hoverTooltip.hidden=!1;const i=this.stageElement.getBoundingClientRect();this.hoverTooltip.style.left=`${t.clientX-i.left+12}px`,this.hoverTooltip.style.top=`${t.clientY-i.top+12}px`}handlePointerLeave=()=>{this.hoverTooltip.hidden=!0,this.sceneRenderer.setCompassHovered(!1)};handleLightningFlash(t){clearTimeout(this.thunderTimeoutId),this.thunderTimeoutId=window.setTimeout(()=>this.weatherAudio.playThunder(),gi.thunderDelayMs(t))}handleFirstInteraction=()=>{this.weatherAudio.resume(),this.vehicleAudio.resume(),this.aircraftAudio?.resume(),!this.interacted&&(this.interacted=!0,this.setWeather(yc(this.ufoElement.sighting,this.lastTimeMs)))};interacted=!1;applyLevel(){const t=this.ufoElement.level;this.weatherAudio.setLevel(t),this.vehicleAudio.setLevel(t),this.aircraftAudio?.setLevel(t)}handlePageGesture=()=>{this.ufoElement.playbackState==="playing"&&this.handleFirstInteraction()};unlockIfAlreadyActivated(){this.interacted||navigator.userActivation?.hasBeenActive&&this.handleFirstInteraction()}static GESTURES=["pointerdown","pointerup","touchend","click","keydown"];handleTimeUpdate=t=>{this.lastTimeMs=t.detail.time,this.syncAnimationsToPlayback(),this.updateAstronomy(this.lastTimeMs),this.ufoElement.playbackState==="playing"&&this.sceneRenderer.frame(performance.now())};syncAnimationsToPlayback(){const t=this.ufoElement.playbackState==="playing";this.sceneRenderer.setAnimationsRunning(t,t),this.weatherAudio.setPaused(!t),this.vehicleAudio.setPaused(!t),this.aircraftAudio?.setPaused(!t),t&&this.unlockIfAlreadyActivated(),t||clearTimeout(this.thunderTimeoutId)}constructor(){super(),this.shadow=this.attachShadow({mode:"open"});const t=document.createElement("template");t.innerHTML=`<style>${Bv}</style>${zv}`,this.shadow.appendChild(t.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 me(this.sceneCanvas);const e=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.sceneRenderer.onFirstFrameHold=s=>{e.hidden=!s,this.ufoElement.captionHeld=s,this.ufoElement.holdClock(s)},this.hoverTooltip=this.shadow.getElementById("hover-tooltip"),this.ufoElement=document.createElement(Qu),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"&&en.fill(n,this)}),this.creditsButton.title=Ku,this.creditsButton.setAttribute("aria-label",Ku),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.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 We.GESTURES)this.addEventListener(s,this.handleFirstInteraction,!0)}get said(){return this.saidTexts??=new Cs(Ua.preferencesFor(this))}saidTexts;traceLabelsFor;traceLabels(t){const e=Ua.preferencesFor(this).join();if(this.traceLabelsFor?.traces!==t||this.traceLabelsFor.language!==e){const i=new Map;for(const n of t){const s=this.said.read(n.title);s&&i.set(n.id,s)}this.traceLabelsFor={traces:t,language:e,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 e of We.GESTURES)document.addEventListener(e,this.handlePageGesture,!0);const t=this.getAttribute("src");t&&this.loadFromSrc(t)}watchVisibility(){this.visibilityObserver?.disconnect(),!(typeof IntersectionObserver>"u")&&(this.visibilityObserver=new IntersectionObserver(t=>{if(t[t.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 t of We.GESTURES)document.removeEventListener(t,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(t,e,i){if(t==="src"&&i&&i!==e&&this.isConnected&&this.loadFromSrc(i),(t==="star-catalog-src"||t==="deep-star-catalog-src")&&i!==e&&this.isConnected&&this.loadStars(),t==="show-compass"&&i!==e&&this.sceneRenderer.setShowCompass(this.hasAttribute("show-compass")),t==="max-pixel-ratio"&&i!==e){const n=Number(i);this.sceneRenderer.setMaxPixelRatio(Number.isFinite(n)&&n>0?n:Math.min(window.devicePixelRatio||1,2))}(t===ka||t===za)&&i!==e&&this.forwardPlayerAttributes()}forwardPlayerAttributes(){for(const t of[ka,za]){const e=this.getAttribute(t);e===null?this.ufoElement.removeAttribute(t):this.ufoElement.setAttribute(t,e)}}setCompassForced(t){this.sceneRenderer.setCompassForced(t)}lookToward(t){const e=Je(this.ufoElement.sighting,this.lastTimeMs);if(t.kind==="observer"||e?.lat===void 0||e.lng===void 0||e.headingDeg===void 0){this.setLookOffset(0,0);return}const{x:i,z:n}=je(t.lat,t.lng,e.lat,e.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-e.headingDeg)%360+540)%360-180,-e.pitchDeg)}setLookOffset(t,e){this.sceneRenderer.setLookOffset(t,e),this.ufoElement.setLookOffset(t,e),this.updateAstronomy(this.lastTimeMs)}setIndoorLook(t,e){this.sceneRenderer.setIndoorLook(t,e)}setCloudRendering(t){this.sceneRenderer.setCloudRendering(t)}setWeather(t){this.sceneRenderer.setWeather(t),this.weatherAudio.setAmbient(t.precipitationType,t.precipitationIntensity*(t.precipitationAmount??1),t.windSpeed)}pickCloudAt(t,e){return this.sceneRenderer.pickCloudAt(t,e)}cloudDirectionAt(t,e){return this.sceneRenderer.cloudDirectionAt(t,e)}pickDecorAt(t,e){return this.sceneRenderer.pickDecorAt(t,e)}decorScreenBox(t){return this.sceneRenderer.decorScreenBox(t)}decorGroundPointAt(t,e,i){return this.sceneRenderer.decorGroundPointAt(t,e,i)}bodyScreenBox(t){return this.sceneRenderer.bodyScreenBox(t)}pickPlacedBodyAt(t,e){return this.sceneRenderer.pickPlacedBodyAt(t,e)}resumeWeatherAudio(){this.weatherAudio.resume(),this.vehicleAudio.resume(),this.aircraftAudio?.resume()}async loadFromSrc(t){const e=Ug.json(t);this.holdForNewScene(e);const i=await e;this.documentUrl=new URL(t,location.href).href,this.sightingData=i}holdForNewScene(t){this.sceneRenderer.holdForNewScene(t)}get documentUrl(){return this.sceneRenderer.documentUrl}set documentUrl(t){this.sceneRenderer.documentUrl=t}get sightingData(){return this.ufoElement.sightingData}set sightingData(t){this.ufoElement.sightingData=t,this.seekPreview?.recordingChanged(t),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(t){const e=this.sceneCanvas.width>0&&this.sceneCanvas.height>0?this.sceneCanvas.width/this.sceneCanvas.height:1.7777777777777777,i=Math.round(t.width/e);return t.height!==i&&(t.height=i),this.seekPreview??=new ah(this,()=>document.createElement(b0))}showAt(t){this.ufoElement.currentTime=t,this.framesAtAsk=this.sceneRenderer.framesDrawn}framesAtAsk=0;snapshotTo(t){if(this.sceneRenderer.frame(performance.now()),this.sceneRenderer.framesDrawn===this.framesAtAsk)return!1;const e=t.getContext("2d");return e?(e.drawImage(this.sceneCanvas,0,0,t.width,t.height),!0):!1}referenceAspect(t){return this.sceneRenderer.referenceAspect(t)}screenPointOf(t){return this.sceneRenderer.screenPointOf(t)}directionAt(t,e){return this.sceneRenderer.directionAt(t,e)}referenceFailedToLoad(t){return this.sceneRenderer.referenceFailedToLoad(t)}applyReferenceView(t){this.sceneRenderer.setReferencesShown(t.shown);for(const e of this.ufoElement.sighting.references){const i=t.views?.[e.id];this.sceneRenderer.setReferenceView(e.id,{opacity:i?i.shown?i.opacity:0:t.opacity})}}get currentTerrainAttribution(){return this.sceneRenderer.currentTerrainAttribution}get currentRoadAttribution(){return this.sceneRenderer.currentRoadAttribution}setTerrainProviders(t){this.sceneRenderer.setTerrainProviders(t)}setDecorModelProvider(t){this.sceneRenderer.setDecorModelProvider(t)}get decorModelCredits(){return[...new Map(this.sceneRenderer.currentDecorModelCredits.map(e=>[`${e.title}|${e.author??""}|${e.license}|${e.sourceUrl??""}`,e])).values()]}applyFrameFormat(){const t=this.ufoElement.sighting.instrument,e=Ie.CANVAS_HEIGHT_PX,i=mi.frameWidthPx(t,e);this.frameElement.style.setProperty("--frame-aspect",`${i} / ${e}`)}resizeToStage(){const t=this.frameElement.getBoundingClientRect(),e=Math.max(1,Math.round(t.width)),i=Math.max(1,Math.round(t.height));this.sceneCanvas.width=e,this.sceneCanvas.height=i,this.sceneRenderer.resize(e,i)}async loadStars(){const t=[{magnitudeLimit:Wu,url:this.getAttribute("star-catalog-src")??BA},{magnitudeLimit:Xu,url:this.getAttribute("deep-star-catalog-src")??HA}],e=this.instrumentReach(),i=++this.starCatalogRequest;this.starCatalogDepth=e>Wu?Xu:Wu;const n=await as.upTo(t,e);i===this.starCatalogRequest&&(this.starCatalog=n,this.sceneRenderer.compileNextFrameOffThread(),this.updateAstronomy(this.lastTimeMs))}ensureStarsDeepEnough(){!this.starCatalog||this.starCatalogDepth>=Xu||this.instrumentReach()<=this.starCatalogDepth||this.loadStars()}instrumentReach(){const t=this.ufoElement.sighting,e=Vi.gainFor(t.instrument,{fNumber:Je(t,0)?.fNumber,fieldOfViewDeg:an.fovOf(t,0),exposureSeconds:t.exposure});return Ll(GA,e)}updateAstronomy(t){this.ensureStarsDeepEnough(),this.applySceneAt(t);const e=Xn.windowEndingAt(t,this.exposureSeconds()),i=e.seconds,n=this.degreesPerPixelAt(t),s=Wr.instants(i,n),r=Math.max(s,this.ufoElement.exposureTimes(t).length,Xn.instants(this.decorWithTraffic(this.ufoElement.sighting),Je(this.ufoElement.sighting,t)?.elevationM??0,e.fromMs,i,n));if(r<=1){this.sceneRenderer.setExposure(1);return}this.sceneRenderer.setExposure(r,o=>this.applySceneAt(e.fromMs+e.ms*o/(r-1),{sky:Math.floor(o*s/r)!==Math.floor((o-1)*s/r),stepMs:e.ms/r}))}exposureSeconds(){return this.ufoElement.sighting.exposure??0}degreesPerPixelAt(t){const e=this.sceneCanvas.height;return e<=0?0:an.fovOf(this.ufoElement.sighting,t)/e}applySceneAt(t,e){const i=this.ufoElement.sighting;this.setWeather(yc(i,t)),this.sceneRenderer.setInstrument(i.instrument),this.sceneRenderer.setLightPollution(i.lightPollution),e||this.vehicleAudio.setVoices(this.vehicleHearing.at(i,t)),e||this.pushAircraftSound(i,t),this.updateMeteorShower(i,t),this.updateLightning(i,t,e!==void 0),this.sceneRenderer.setDecor(this.decorWithTraffic(i)),this.sceneRenderer.setDecorPresence(this.traffic?.set?.presence??We.NO_PRESENCE),this.sceneRenderer.setDecorSunlight(this.trafficSunlight(t)),this.sceneRenderer.setContrails(this.traffic?.contrails??We.NO_CONTRAILS),this.sceneRenderer.setContrailSunlight(this.contrailSunlight(t));const n=Je(i,t);this.sceneRenderer.setReferences(i.references,n?.lat!==void 0&&n.lng!==void 0?{lat:n.lat,lng:n.lng}:void 0);const s=Je(i,0),r=ao(i,0),o=ba(i.event.time??{},n?.lng??bl.lng,i.event.utcOffsetHours),c=i.weatherSource!==void 0&&o?kv(o):void 0,l=Object.fromEntries(Ul(ao(i,t)).map(w=>[w.id,Pf(t,i.weatherTrack,r,s,n,w.id,w.instances?.length?void 0:c)]));this.sceneRenderer.setCloudOffset(Pf(t,i.weatherTrack,r,s,n,void 0,c),l),this.sceneRenderer.setObserverPose(n??bl),this.sceneRenderer.setLensOptics(this.lensOpticsAt(t)),this.sceneRenderer.setInstrumentGain(Vi.gainFor(i.instrument,{fNumber:n?.fNumber,fieldOfViewDeg:an.fovOf(i,t),exposureSeconds:i.exposure}),i.instrument.detailUm!==void 0),this.sceneRenderer.setMedium(i.instrument.medium,i.exposure,n?.fNumber??i.instrument.fNumber,i.iso),this.sceneRenderer.setGait(be.bodyAt(i,t,this.ufoElement.steadyObserver)),this.sceneRenderer.updateDecorAnchoring(Je(i,0),n,t),this.placeBodiesAt(t,e===void 0),this.sceneRenderer.updateDecorLitState(t,e?.stepMs??0),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(t);const h=n?.lat??bl.lat,u=n?.lng??bl.lng,d=ba(i.event.time??{},u,i.event.utcOffsetHours),f={lat:h,lng:u,elevationM:n?.elevationM??0};this.pushSatellitesAt(d,t,f),this.ensureFireballs(d);const p=[...this.interpretationShown?.reentries??[],...this.fireballs?.reentries??[]];if(this.sceneRenderer.setReentries(p.length===0?[]:ge.viewsAt(p,t,{lat:h,lng:u,heightM:f.elevationM})),e&&!e.sky)return;if(!d){this.sceneRenderer.setAstronomy(VA);return}const v=new Date(d.getTime()+t),m=Math.max(1,Math.round(.25*this.degreesPerPixelAt(t)/Wr.DEG_PER_SECOND*1e3)),g=Math.max(1e-8,this.degreesPerPixelAt(t)*.1),S=`${Math.floor(v.getTime()/m)}|${Math.round(h/g)}|${Math.round(u/g)}|${Math.round(f.elevationM)}|${this.starCatalog?this.starCatalogDepth:0}`;if(S===this.lastSkyKey){this.sceneRenderer.render();return}this.lastSkyKey=S;const x={...ll("Sun",v,f),magnitude:xu("Sun",v)};this.lastSun={altitudeDeg:x.altitudeDeg,azimuthDeg:x.azimuthDeg};const M={...ll("Moon",v,f),phase:v5(v),magnitude:xu("Moon",v)},b=g5.map(w=>({body:w,position:ll(w,v,f),magnitude:xu(w,v)}));this.sceneRenderer.setAstronomy({sun:x,moon:M,planets:b,comet:this.cometAt(v,f),novae:Ag.appearancesAt(v,f).map(({outburst:w,position:T,magnitude:y})=>({id:w.id,position:T,magnitude:y})),stars:this.starCatalog?{catalog:this.starCatalog,date:v,observer:f}:void 0,frame:{date:v,observer:f}}),this.ufoElement.setSunAltitude(x.altitudeDeg)}pushSatellitesAt(t,e,i){if(this.ensureSatellites(t),!t||!this.satellites){this.sceneRenderer.setSatellites([]);return}const n=new Date(t.getTime()+e),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(t){const e=this.ufoElement.sighting,i=Math.max((e.event.durationSeconds??0)*1e3,this.ufoElement.seekableDuration),n=t?.getTime(),s=n===void 0?"":`${n}+${i}`;if(this.fireballs?.key===s)return;if(n===void 0||!fs.mayCover(n+i)){this.fireballs={key:s,status:"outside",reentries:[]};return}const r={key:s,status:"loading",reentries:[]};this.fireballs=r,We.fireballArchive.between(n,n+i).then(o=>{r.status=o?"ready":"unavailable",r.records=o??[],r.reentries=r.records.map(c=>fs.asReentry(c,n)),!(this.fireballs!==r||!this.isConnected)&&(this.dispatchEvent(new CustomEvent(FA)),r.reentries.length>0&&this.updateAstronomy(this.lastTimeMs))})}decorWithTraffic(t){const e=this.ensureTraffic(t);if(!e||e.objects.length===0)return t.decor;const i=this.decorMemo;if(i&&i.base===t.decor&&i.traffic===e.objects)return i.merged;const n=[...t.decor,...e.objects];return this.decorMemo={base:t.decor,traffic:e.objects,merged:n},n}ensureTraffic(t){const e=Je(t,0),i=e?.lng===void 0?void 0:ba(t.event.time??{},e.lng,t.event.utcOffsetHours),n=Math.max((t.event.durationSeconds??0)*1e3,this.ufoElement.seekableDuration),s=i?.getTime(),r=s===void 0||e?.lat===void 0||e.lng===void 0?"":`${this.aircraftSource.id}|${s}+${n}|${e.lat.toFixed(3)},${e.lng.toFixed(3)}|${Math.round(e.elevationM??0)}`;if(this.traffic?.key===r)return this.traffic.set;if(r===""||s===void 0||e?.lat===void 0||e.lng===void 0){this.traffic={key:r,status:"outside"};return}let o=We.aircraftProviders.get(this.aircraftSource.id);if(o||We.aircraftProviders.set(this.aircraftSource.id,o=this.aircraftSource.create()),o.mayCover&&!o.mayCover(s+n)){this.traffic={key:r,status:"outside"};return}const c={key:r,status:"loading",startMs:s,observer:{lat:e.lat,lng:e.lng}};this.traffic=c;const l={lat:e.lat,lng:e.lng,heightM:e.elevationM??0},h=Wi.MAX_GAP_S*1e3,u=We.SOUND_LOOKBACK_MS,d={lat:e.lat,lng:e.lng,elevationM:e.elevationM??0},f=(p,v)=>p.TrafficDecor.from(c.tracks??[],l,s,p.TrafficDecor.MAX_OBJECTS,{models:v,sunElevationAt:m=>this.sunElevationAt(m,d)});o.between(l,s-u,s+n+h).then(async p=>{if(this.traffic!==c)return;if(p.status!=="found"){c.status=p.status==="outside"?"outside":"unavailable",this.announceTraffic();return}let v;try{v=await We.loadTrafficRuntime()}catch{this.traffic===c&&(c.status="unavailable",this.announceTraffic());return}this.traffic===c&&(c.status="ready",c.tracks=p.tracks,c.set=f(v),this.startAircraftSound(c,v),this.announceTraffic(),this.describeTraffic(o,c,v,f),c.set.shown>0&&this.readUpperAir(c,v,s-u,s+n+h))})}trafficSunlight(t){const e=new Map,i=this.traffic,n=i?.set,s=this.lastSun;if(!n||!s||i.startMs===void 0||!i.observer)return e;for(const[r,o]of n.presence){if(t<o.fromMs||t>o.untilMs)continue;const c=n.flights.get(r),l=c?Wi.positionAt(c,i.startMs+t):void 0;l&&e.set(r,{heightM:l.geo.heightM,sunElevationDeg:vn.sunElevationDeg(s,i.observer,l.geo)})}return e}trafficTooltipAt(t,e){const i=this.sceneRenderer.pickTrafficAt(t,e),n=i?this.trafficInfoAt(i):void 0;if(!n)return;const s=this.naming,r=We.trafficRuntime;return r?.TrafficTooltip.text(n,s.names?.trafficTooltip??r.TrafficTooltip.ENGLISH,o=>s.towards(o))}trafficInfoAt(t){const e=this.traffic,i=e?.set?.flights.get(t);if(!e||!i||e.startMs===void 0||!e.observer)return;const n=We.trafficRuntime;if(!n)return;const s=e.descriptions?.get(Cn.keyOf(i)),r=Je(this.ufoElement.sighting,this.lastTimeMs),o={lat:e.observer.lat,lng:e.observer.lng,heightM:r?.elevationM??0},c=n.AmbientNoise.dbA(yc(this.ufoElement.sighting,this.lastTimeMs)),l=n.TrafficInfos.at(i,s,o,e.startMs+this.lastTimeMs,{ambientDbA:c}),h=l&&this.contrailAt(t,this.lastTimeMs);return l&&h?{...l,contrail:h}:l}contrailAt(t,e){const i=this.traffic?.contrails?.find(s=>s.id===t);if(!i)return;let n;for(const s of i.points){if(s.tMs>e)break;n=s}return n?.forms?{persistent:n.persistent,iceRelativeHumidity:n.iceRelativeHumidity}:void 0}startAircraftSound(t,e){this.aircraftAudio||(this.aircraftAudio=new e.AircraftAudio,this.aircraftAudio.setLevel(this.ufoElement.level),this.interacted&&this.aircraftAudio.resume(),this.aircraftAudio.setPaused(this.ufoElement.playbackState!=="playing")),this.sortOutAudible(t,e)}sortOutAudible(t,e){!t.set||!t.observer||(t.audible=e.TrafficSound.candidates(t.set.flights,t.descriptions??new Map,Cn.keyOf,{...t.observer,heightM:0},{ambientDbA:e.AmbientNoise.BASE_DB_A}))}pushAircraftSound(t,e){const i=this.aircraftAudio;if(!i)return;const n=We.trafficRuntime,s=this.traffic,r=s?.set;if(!n||!s||!r||!s.audible||s.startMs===void 0||!s.observer){i.setVoices([]);return}const o=Je(t,e),c={lat:s.observer.lat,lng:s.observer.lng,heightM:o?.elevationM??0},l=yc(t,e),h=n.TrafficSound.voices(s.audible,r.flights,s.descriptions??new Map,Cn.keyOf,c,s.startMs+e,{ambientDbA:n.AmbientNoise.dbA(l),referenceAmplitude:n.AmbientNoise.referenceAmplitude(l)});i.setVoices(h,o?.headingDeg??0)}announceTraffic(){this.isConnected&&(this.dispatchEvent(new CustomEvent(UA)),this.updateAstronomy(this.lastTimeMs))}async describeTraffic(t,e,i,n){if(!t.describe||!e.set||!e.tracks)return;const s=new Set([...e.set.flights.values()].map(l=>Cn.keyOf(l))),r=e.tracks.filter(l=>s.has(Cn.keyOf(l))&&l.points.length>0),o=new Map,c=new Map;await Promise.all(r.map(async l=>{const h=new Date(l.points[0].t).toISOString().slice(0,10),u=await t.describe(l,h).catch(()=>{});u&&(c.set(Cn.keyOf(l),u),o.set(Cn.keyOf(l),i.AircraftModels.of(u)))})),!(this.traffic!==e||o.size===0)&&(e.descriptions=c,e.models=o,e.set=n(i,o),this.planContrails(e,i),this.sortOutAudible(e,i),this.announceTraffic())}async readUpperAir(t,e,i,n){if(!t.observer)return;const s=this.upperAirSource??e.UPPER_AIR_SOURCES[0];let r=We.upperAirProviders.get(s.id);r||We.upperAirProviders.set(s.id,r=s.create());const o=await r.between(t.observer,i,n);this.traffic!==t||o.status!=="found"||(t.air=o.samples,t.airSource=o.source,this.planContrails(t,e),this.announceTraffic())}planContrails(t,e){!t.set||!t.air||t.startMs===void 0||(t.contrails=e.AircraftContrails.plan(t.set,t.models,t.air,t.startMs))}contrailSunlight(t){const e=new Map,i=this.traffic,n=i?.set,s=this.lastSun;if(!n||!s||!i.contrails?.length||i.startMs===void 0||!i.observer)return e;for(const r of i.contrails){const o=n.presence.get(r.id),c=n.flights.get(r.id);if(!o||!c)continue;const l=Wi.positionAt(c,i.startMs+Math.min(o.untilMs,Math.max(o.fromMs,t)));l&&e.set(r.id,{heightM:l.geo.heightM,sunElevationDeg:vn.sunElevationDeg(s,i.observer,l.geo)})}return e}sunElevationAt(t,e){const i=ll("Sun",new Date(t.t),e);return vn.sunElevationDeg(i,e,t)}upperAirSource;setUpperAirSource(t){t.id!==this.upperAirSource?.id&&(this.upperAirSource=t,this.traffic=void 0,this.decorMemo=void 0,this.updateAstronomy(this.lastTimeMs))}setAircraftSource(t){t.id!==this.aircraftSource.id&&(this.aircraftSource=t,this.traffic=void 0,this.decorMemo=void 0,this.updateAstronomy(this.lastTimeMs))}get aircraftState(){const t=this.traffic?.contrails?.length?this.upperAirSource??We.trafficRuntime?.UPPER_AIR_SOURCES[0]:void 0;return{trailCredit:t&&{credit:t.credit,creditUrl:t.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(t){const e=t?String(t.getTime()):"";if(e===this.satellitesFor)return;this.satellitesFor=e,this.satellites=void 0,this.satellitePassesMemo=void 0;const i=++this.satelliteRequest;if(!t){this.satelliteStatus="none";return}this.satelliteStatus="loading";const n=r=>{i===this.satelliteRequest&&(this.satelliteStatus=r,this.isConnected&&this.dispatchEvent(new CustomEvent(NA)))},s=We.tleArchive;(async()=>{if(!await s.covers(t))return n("outside");const[r,o]=await Promise.all([s.at(t),$i(()=>import("./SatellitePasses-Pfro2-0Z.js"),[],import.meta.url)]);if(i===this.satelliteRequest){if(!r)return n("unavailable");this.satellites={snapshot:r,passes:new o.SatellitePasses(r.objects)},n("ready"),this.isConnected&&this.updateAstronomy(this.lastTimeMs)}})().catch(()=>n("unavailable"))}get satelliteState(){const t=this.satellites?.snapshot;return{status:this.satelliteStatus,coverage:t?.coverage,credit:t?.credit,creditUrl:t?.creditUrl}}satellitePassesDuring(t){const e=this.satellites,i=this.ufoElement.sighting,n=Je(i,0),s=i.event.place?.[0],r=n?.lat??s?.lat,o=n?.lng??s?.lng;if(!e||r===void 0||o===void 0)return[];const c=ba(i.event.time??{},o,i.event.utcOffsetHours);if(!c)return[];const l=Math.min(Math.max(t,0),4*36e5),h={lat:r,lng:o,elevationM:n?.elevationM??0},u=JSON.stringify([this.satellitesFor,c.getTime(),r,o,h.elevationM,l]);if(this.satellitePassesMemo?.key===u)return this.satellitePassesMemo.passes;const d=Math.max(10,Math.ceil(l/1e3/600)),f=e.passes.passesDuring(c,new Date(c.getTime()+l),h,d);return this.satellitePassesMemo={key:u,passes:f},f}cometAt(t,e){const i=wA.brightestAt(t,e);if(i)return{id:i.apparition.id,position:i.position,tailEnd:i.tailEnd,magnitude:i.magnitude}}pushPhenomenaAt(t){const e=this.ufoElement.sighting;e!==this.sizeEstimatesFor&&(this.sizeEstimates.clear(),this.distanceHypotheses.clear(),this.sizeEstimatesFor=e);const i=e.timeline,n=this.ufoElement.canvasElement,s=this.ufoElement.frameShiftPx,r=this.projectionAt(t),o=new Map,c=new Map,l=new Set;for(const p of i.sourceIds){const v=i.getInterpolatedShapeAt(t,p);if(!v)continue;const m={...v,bounds:{...v.bounds,x:v.bounds.x+s.x,y:v.bounds.y+s.y}};o.set(p,m);const g=v.aim?this.sceneRenderer.screenPointOf(Wn.directionOf(v.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)},S=g!==void 0&&Math.abs(g.ndcX)<=1&&Math.abs(g.ndcY)<=1,x=S?this.sceneRenderer.decorDistancesAt(g.ndcX,g.ndcY,p):{};l.add(p),(S||v.aim)&&l.delete(p);const M=v.angular?.widthDeg??r.pxToDeg(v.bounds.width),b=this.sizeEstimateOf(p);b.add(M,x);const w=Ko.of(e,p);c.set(p,Gi.resolve({hypothesisM:this.distanceHypotheses.get(p),derivedM:w&&M>0?Ie.distanceMAt(w.widthM,M):void 0,range:b.distanceRangeAt(M),crossing:x}))}for(const[p,v]of o)for(const[m,g]of o){if(m===p||g.transparency>=1||g.bounds.width*g.bounds.height<=v.bounds.width*v.bounds.height||!(v.bounds.x>=g.bounds.x&&v.bounds.y>=g.bounds.y&&v.bounds.x+v.bounds.width<=g.bounds.x+g.bounds.width&&v.bounds.y+v.bounds.height<=g.bounds.y+g.bounds.height))continue;const x=c.get(m);x&&c.set(p,{distanceM:x.distanceM*.999,basis:x.basis});break}this.depths=c;const h=i.sourceIds,u=[];for(const[p,v]of o)u.push({sourceId:p,shape:v,distanceM:c.get(p).distanceM,renderOrder:h.indexOf(p),aim:v.aim,hidden:l.has(p)||this.interpretationShown!==void 0&&(!this.comparing||v.transparency>=1),ghost:this.interpretationShown!==void 0&&this.comparing});const f=(Je(e,t)?.rollDeg??0)+be.bodyAt(e,t,this.ufoElement.steadyObserver).rollDeg;this.sceneRenderer.setPhenomena(u,{projection:r,canvasWidthPx:n.width,canvasHeightPx:n.height,scale:Math.max(1,this.sceneCanvas.height/Math.max(1,n.height)),starPoints:mi.starPointsOf(e.instrument),rollRad:f*Math.PI/180})}get interpretation(){return this.interpretationShown}set interpretation(t){this.interpretationShown=t,this.syncAccountHidden(),this.updateAstronomy(this.lastTimeMs)}syncAccountHidden(){this.ufoElement.accountHidden=this.interpretationShown!==void 0&&!this.comparing}get accountInTheRound(){return this.inTheRound}set accountInTheRound(t){this.inTheRound=t}get compareAccount(){return this.comparing}set compareAccount(t){this.comparing=t,this.syncAccountHidden(),this.updateAstronomy(this.lastTimeMs)}get confrontation(){return this.confrontationReadings}groundAlong(t,e,i){const n=this.sceneRenderer.bodyGround,s=ne.eyeOf(this.ufoElement.sighting,i,n);return s?ne.lineOfSightMeetsGround(s,t,e,n):void 0}bodyReading(t,e){const i=this.sceneRenderer.bodyGround,n=this.ufoElement.sighting,s=d=>ne.eyeOf(n,d,i),r=new ne(t,i,s).at(e),o=s(e);if(!r||!o)return;const c=r.eastM-o.eastM,l=r.northM-o.northM,h=r.upM-o.upM,u=Math.hypot(c,l);return{azimuthDeg:(Math.atan2(c,l)*180/Math.PI+360)%360,altitudeDeg:Math.atan2(h,u)*180/Math.PI,distanceM:Math.hypot(u,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(t,e){const i=this.sceneRenderer.bodyGround,n=this.ufoElement.sighting,s=p=>ne.eyeOf(n,p,i),r=new ne(t,i,s),o=r.at(e)?e:t.track[0]?.t,c=o===void 0?void 0:r.at(o),l=o===void 0?void 0:s(o);if(!c||!l)return;const h=c.eastM-l.eastM,u=c.northM-l.northM,d=c.upM-l.upM,f=Math.hypot(h,u);if(!(f===0&&d===0))return{azimuthDeg:(Math.atan2(h,u)*180/Math.PI+360)%360,altitudeDeg:Math.atan2(d,f)*180/Math.PI}}placeBodiesAt(t,e){const i=this.interpretationShown,n=this.ufoElement.sighting;let s=[],r=[];const o=this.sceneRenderer.bodyGround,c=p=>ne.eyeOf(n,p,o);i&&(s=i.bodies.map(p=>new ne(p,o,c).at(t)).filter(p=>p!==void 0));const l=ao(n,t),h=l.windDirectionDeg*Math.PI/180,u={x:l.windSpeed*Math.sin(h),z:-l.windSpeed*Math.cos(h)};this.sceneRenderer.setBodies(s,t/1e3,i?.bodies.map(p=>p.id)??[],i?.smoke??[],u);const d=i&&this.comparing?c(t):void 0;if(d&&(r=new ri(n.timeline).at(t,s,d,p=>p.outlineNode?this.sceneRenderer.bodyOutline?.(p.id,p.outlineNode):void 0)),this.confrontationReadings=r,!e)return;const f=JSON.stringify(r);f!==this.confrontationSignature&&(this.confrontationSignature=f,this.dispatchEvent(new CustomEvent(kA,{detail:r})))}setDistanceHypothesis(t,e){e===void 0||!(e>0)?this.distanceHypotheses.delete(t):this.distanceHypotheses.set(t,e),this.updateAstronomy(this.lastTimeMs)}depthOf(t){return this.depths.get(t)}sizeRangeOf(t){return this.sizeEstimateOf(t).sizeRange}distanceRangeAt(t,e){const i=this.ufoElement.sighting.timeline.getInterpolatedShapeAt(e,t);if(!i)return{};const n=i.angular?.widthDeg??this.projectionAt(e).pxToDeg(i.bounds.width);return this.sizeEstimateOf(t).distanceRangeAt(n)}sizeContradictory(t){return this.sizeEstimateOf(t).contradictory}updateMeteorShower(t,e){this.ensureMeteorSchedule(t),this.sceneRenderer.updateMeteors(e)}updateLightning(t,e,i){if(this.ensureLightningSchedule(t),this.sceneRenderer.updateLightning(e),i)return;const n=this.lastLightningT;if(this.lastLightningT=e,n===void 0||e<n||this.ufoElement.playbackState!=="playing")return;const s=this.lightningFlashes.filter(r=>r.t>n&&r.t<=e).pop();s&&ao(t,s.t).storm&&this.handleLightningFlash(s)}ensureLightningSchedule(t){const e=ao(t,0).precipitationIntensity,i=`${this.meteorInputsOf(t)}|${e}`;if(i===this.lightningScheduleFor)return;this.lightningScheduleFor=i;const n=t.event.time,s=t.event.place?.[0],r=n?.year!==void 0?ba(n,s?.lng??0,t.event.utcOffsetHours):void 0,o=(t.event.durationSeconds??0)*1e3||t.timeline.duration||2e4,c=Math.round((r?.getTime()??0)/1e3)+Math.round((s?.lat??0)*1e3)+7;this.lightningFlashes=gi.schedule({durationMs:o,seed:c,intensity:e}),this.sceneRenderer.setLightning(this.lightningFlashes)}ensureMeteorSchedule(t){const e=this.meteorInputsOf(t);e!==this.meteorScheduleFor&&(this.meteorScheduleFor=e,this.scheduleMeteors(t))}meteorInputsOf(t){const e=t.event.place?.[0],i=t.event.time;return JSON.stringify([e?.lat,e?.lng,i?.year,i?.month,i?.day,i?.hour,i?.minute,i?.second,t.event.utcOffsetHours,t.event.durationSeconds,t.timeline.duration])}scheduleMeteors(t){const e=t.event.place?.[0],i=t.event.time,n=e?.lat!==void 0&&e.lng!==void 0&&i?.year!==void 0?ba(i,e.lng,t.event.utcOffsetHours):void 0;if(!n||e?.lat===void 0||e.lng===void 0){this.sceneRenderer.setMeteorShower([],0,0);return}const s={lat:e.lat,lng:e.lng,elevationM:0},r=(t.event.durationSeconds??0)*1e3||t.timeline.duration||2e4,o=Math.round(n.getTime()/1e3)+Math.round(e.lat*1e3),c=ai.schedule({ratePerHour:ai.observedRatePerHour(ai.apexPosition(n,s).altitudeDeg),durationMs:r,velocityKmS:ai.TYPICAL_VELOCITY_KM_S,seed:o}),l=qu.activeAt(n).map(u=>{const d=qu.radiantPosition(u.shower,n,s);return{entry:u,position:d,rate:qu.observedRatePerHour(u.zhr,d.altitudeDeg,u.shower.populationIndex)}}).sort((u,d)=>d.rate-u.rate)[0];if(!l||l.rate<=0){this.sceneRenderer.setMeteorShower(c,0,0);return}const h=Gr.schedule({ratePerHour:l.rate,durationMs:r,velocityKmS:l.entry.shower.velocityKmS,seed:o+1});this.sceneRenderer.setMeteorShower([...h,...c],l.position.altitudeDeg,l.position.azimuthDeg)}meteorByRank(t){this.ensureMeteorSchedule(this.ufoElement.sighting);const e=[...this.sceneRenderer.meteorSchedule].filter(s=>s.t+s.durationMs<=this.ufoElement.seekableDuration).sort((s,r)=>r.brightness-s.brightness);if(e.length===0)return;const i=e[t%e.length],n=this.sceneRenderer.meteorMidpoint(i);if(n)return{t:Math.round(i.t+i.durationMs*.45),...n}}lensOpticsAt(t){const e=this.ufoElement.sighting,i=e.instrument,n=i.frame,s=Je(e,t),r=s?.fNumber??i.fNumber;if(!n||r===void 0)return;const o=mi.focalLengthMmFor(i,an.fovOf(e,t));if(o!==void 0)return{focalLengthMm:o,fNumber:r,focusDistance:s?.focusDistanceM??0,frameHeightMm:n.heightMm}}projectionAt(t){const e=this.ufoElement.sighting;return Ls.of(e.instrument,Ie.CANVAS_HEIGHT_PX,an.fovOf(e,t))}sizeEstimateOf(t){let e=this.sizeEstimates.get(t);return e||(e=new AA,this.sizeEstimates.set(t,e)),e}}const b0="rr0-scene";function WA(){Jg(),customElements.get(b0)||customElements.define(b0,We)}WA();export{eT as $,zr as A,ki as B,st as C,P2 as D,tT as E,ue as F,Re as G,_x as H,sT as I,Vl as J,qi as K,oT as L,bt as M,iT as N,I1 as O,Hd as P,Wp as Q,ge as R,ks as S,Cn as T,xx as U,R as V,QA as W,ZA as X,on as Y,Ap as Z,Ge as _,Wi as a,rT as a0,M1 as a1,Lr as a2,Ac as a3,Ch as a4,hM as a5,le as a6,Ce as a7,sc as a8,cd as a9,Ri as aa,zs as ab,gx as ac,ar as ad,Ae as ae,KA as af,JA as ag,S1 as ah,jA as ai,rn as aj,Zn as ak,y1 as al,kp as am,hx as an,Bl as ao,zd as ap,Ei as aq,R1 as ar,X0 as as,Y0 as at,ce as au,pr as av,pc as aw,aT as b,ql as c,de as d,cs as e,Mt as f,pt as g,ae as h,te as i,$A as j,se as k,mn as l,Il as m,Bs as n,go as o,je as p,Jt as q,_n as r,xn as s,IA as t,pf as u,XA as v,qA as w,YA as x,mc as y,nT as z};
7921
+ `);let s=as.cache.get(n);return s||(s=Promise.all(i.map(r=>as.load(r.url))).then(r=>r.reduce((o,c)=>as.concat(o,c))),as.cache.set(n,s)),s}static parse(t){const e=t.byteLength/(4*Float32Array.BYTES_PER_ELEMENT),i=e*Float32Array.BYTES_PER_ELEMENT;return{count:e,ra:new Float32Array(t,0*i,e),dec:new Float32Array(t,1*i,e),mag:new Float32Array(t,2*i,e),ci:new Float32Array(t,3*i,e)}}static concat(t,e){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:t.count+e.count,ra:i(t.ra,e.ra),dec:i(t.dec,e.dec),mag:i(t.mag,e.mag),ci:i(t.ci,e.ci)}}}class Eg{constructor(t){this.names=t}body(t,e){return this.names?.bodies[t]??e}star(t){return this.names?.stars[t.name]??t.name}comet(t){return this.names?.comets[t.id]??t.name}nova(t){return this.names?.novae[t.id]??t.name}satelliteClass(t){return this.names?.satelliteClasses[t.id]??t.name}shower(t){return this.names?.showers[t.id]??t.name}lightRig(t){return this.names?.lightRigs[t.id]??t.name}instrument(t){return this.names?.instruments[t.id]??t.name}decorKind(t,e){return this.names?.decorKinds[t]??e}point(t){return Hr.point(t,this.names?.compassPoints)}towards(t){return Hr.towards(t,this.names)}}const fA="Global Meteor Network",pA="https://globalmeteornetwork.org/data/",mA="“Thunder” by Jerimee",gA="https://creativecommons.org/licenses/by/3.0/",vA="CC BY 3.0";class en{static fill(t,e){t.innerHTML="";const i=h=>t.appendChild(h),n=e.currentTerrainAttribution;n&&i(en.text(n));const s=e.currentRoadAttribution;s&&i(en.text(s));const r=e.ufoElement.observerMapCredit;r&&!n?.includes(r)&&i(en.text(r));for(const h of e.decorModelCredits){const u=h.author?` — ${h.author}`:"",d=document.createElement("li");h.sourceUrl?d.append(en.link(h.sourceUrl,h.title),document.createTextNode(`${u} (${h.license})`)):d.textContent=`${h.title}${u} (${h.license})`,i(d)}for(const h of e.ufoElement.sighting.references){if(!h.credit)continue;const u=document.createElement("li");h.creditUrl?u.appendChild(en.link(h.creditUrl,h.credit)):u.textContent=h.credit,i(u)}if(e.ufoElement.sighting.traces.length>0){const h=new Cs(Ua.preferencesFor(e)),u=new Set(e.ufoElement.sighting.traces.map(d=>h.read(d.source)).filter(d=>!!d));for(const d of u)i(en.text(d))}const o=e.satelliteState;if(o.status==="ready"&&o.credit){const h=document.createElement("li");h.appendChild(en.link(o.creditUrl??"",o.credit)),i(h)}if(e.fireballState.status==="ready"&&e.fireballState.records.length>0){const h=document.createElement("li");h.append(en.link(pA,fA),document.createTextNode(" (CC BY 4.0)")),i(h)}const c=e.aircraftState;if(c.status==="ready"&&c.shown>0){const h=document.createElement("li");if(h.appendChild(en.link(c.creditUrl,c.credit)),i(h),c.trailCredit){const u=document.createElement("li");u.appendChild(en.link(c.trailCredit.creditUrl,c.trailCredit.credit)),i(u)}}const l=en.text(`${mA} (`);l.append(en.link(gA,vA),document.createTextNode(")")),i(l)}static text(t){const e=document.createElement("li");return e.textContent=t,e}static link(t,e){const i=document.createElement("a");return i.href=t,i.target="_blank",i.rel="noopener",i.textContent=e,i}}const MA=new URL(""+new URL("rain-BvWZrB9h.ogg",import.meta.url).href,import.meta.url).href,xA=new URL(""+new URL("wind-BjklexY7.ogg",import.meta.url).href,import.meta.url).href,yA=new URL(""+new URL("thunder-DA48qs_v.wav",import.meta.url).href,import.meta.url).href,SA=20,_A=1;class bA{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(t){return this.master||(this.master=t.createGain(),this.master.gain.value=this.level,this.master.connect(t.destination)),this.master}setLevel(t){this.level=t,this.master&&(this.master.gain.value=t)}resume(){if(!this.context){if(typeof AudioContext>"u")return;try{this.context=new AudioContext}catch(t){console.warn("WeatherAudio: Web Audio unavailable, weather sounds disabled:",t);return}}zr.unlock(this.context)}setAmbient(t,e,i){if(this.requested={type:t,intensity:e,windSpeed:i},!this.context)return;this.paused&&(t="none",e=0,i=0);const n=t==="rain"||t==="hail"?t:"none";if(this.ambientVolume=n==="hail"?Math.min(1,e*1.3+.2):n==="rain"?e: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(MA,this.ambientVolume).then(o=>this.applyIfCurrent(o,r,()=>this.ambientToken,c=>{this.ambientSource=c?.source,this.ambientGain=c?.gain,c&&(c.gain.gain.value=this.ambientVolume)}))}else this.ambientGain&&(this.ambientGain.gain.value=this.ambientVolume);this.windVolume=Math.min(i/SA,1);const s=i>_A;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(xA,this.windVolume).then(o=>this.applyIfCurrent(o,r,()=>this.windToken,c=>{this.windSource=c?.source,this.windGain=c?.gain,c&&(c.gain.gain.value=this.windVolume)}))}else this.windGain&&(this.windGain.gain.value=this.windVolume)}setPaused(t){if(t===this.paused)return;this.paused=t;const{type:e,intensity:i,windSpeed:n}=this.requested;this.setAmbient(e,i,n)}playThunder(){!this.context||this.paused||this.playOneShot(yA,.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(t,e,i,n){if(e!==i()){t?.source.stop();return}n(t)}async startLoop(t,e){const i=this.context;if(i)try{const n=await this.getBuffer(t),s=i.createBufferSource();s.buffer=n,s.loop=!0;const r=i.createGain();return r.gain.value=e,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(t,e){const i=this.context;if(i)try{const n=await this.getBuffer(t),s=i.createBufferSource();s.buffer=n;const r=i.createGain();r.gain.value=e,s.connect(r).connect(this.output(i)),s.start()}catch(n){console.warn("Thunder sound failed to load:",n)}}async getBuffer(t){const e=this.context;if(!e)throw new Error("WeatherAudio: AudioContext not ready — resume() must be called first");let i=this.buffers.get(t);return i||(i=fetch(t).then(n=>{if(!n.ok)throw new Error(`Audio fetch failed (${n.status}): ${t}`);return n.arrayBuffer()}).then(n=>e.decodeAudioData(n)),this.buffers.set(t,i)),i}stopSource(t,e){try{t?.stop()}catch{}t?.disconnect(),e?.disconnect()}}class Is{constructor(t){this.elements=t;const{eccentricity:e,perihelionAu:i}=t,[n,s]=this.perifocalAxes(),r=Math.sqrt(Is.SUN_GM_AU3_PER_DAY2*(1+e)/i);this.perihelionPosition=this.scale(n,i),this.perihelionVelocity=this.scale(s,r),this.inverseSemiMajorAxis=(1-e)/i}static SUN_GM_AU3_PER_DAY2=.0002959122082855911;static MAX_ITERATIONS=200;perihelionPosition;perihelionVelocity;inverseSemiMajorAxis;positionAt(t){const e=t-this.elements.perihelionJd,i=this.universalAnomaly(e),n=this.inverseSemiMajorAxis*i*i,s=this.elements.perihelionAu,r=1-i*i/s*Is.stumpffC(n),o=e-i*i*i/Math.sqrt(Is.SUN_GM_AU3_PER_DAY2)*Is.stumpffS(n);return{x:r*this.perihelionPosition.x+o*this.perihelionVelocity.x,y:r*this.perihelionPosition.y+o*this.perihelionVelocity.y,z:r*this.perihelionPosition.z+o*this.perihelionVelocity.z}}heliocentricDistanceAt(t){const e=this.positionAt(t);return Math.hypot(e.x,e.y,e.z)}universalAnomaly(t){if(t===0)return 0;const e=Math.sign(t),i=Math.sqrt(Is.SUN_GM_AU3_PER_DAY2)*Math.abs(t),n=o=>{const c=this.inverseSemiMajorAxis*o*o,l=this.elements.perihelionAu;return(1-this.inverseSemiMajorAxis*l)*o*o*o*Is.stumpffS(c)+l*o};let s=Math.max(1,i/this.elements.perihelionAu);for(;n(s)<i;)s*=2;let r=0;for(let o=0;o<Is.MAX_ITERATIONS&&s-r>1e-13*Math.max(1,s);o++){const c=(r+s)/2;n(c)<i?r=c:s=c}return e*(r+s)/2}perifocalAxes(){const t=this.elements.ascendingNodeDeg*Math.PI/180,e=this.elements.argumentOfPerihelionDeg*Math.PI/180,i=this.elements.inclinationDeg*Math.PI/180,n=Math.cos(t),s=Math.sin(t),r=Math.cos(e),o=Math.sin(e),c=Math.cos(i),l=Math.sin(i);return[{x:n*r-s*o*c,y:s*r+n*o*c,z:o*l},{x:-n*o-s*r*c,y:-s*o+n*r*c,z:r*l}]}scale(t,e){return{x:t.x*e,y:t.y*e,z:t.z*e}}static stumpffC(t){if(Math.abs(t)<1e-6)return 1/2-t/24+t*t/720;if(t>0)return(1-Math.cos(Math.sqrt(t)))/t;const e=Math.sqrt(-t);return(Math.cosh(e)-1)/-t}static stumpffS(t){if(Math.abs(t)<1e-6)return 1/6-t/120+t*t/5040;if(t>0){const i=Math.sqrt(t);return(i-Math.sin(i))/(i*i*i)}const e=Math.sqrt(-t);return(Math.sinh(e)-e)/(e*e*e)}}const _v=[{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 wA{static WINDOW_DAYS=200;static TWILIGHT_ELONGATION_DEG=15;static LIGHT_SPEED_AU_PER_DAY=173.144632674;static orbits=new Map;static aroundDate(t){const e=this.julianDayOf(t);return _v.filter(i=>Math.abs(e-i.orbit.perihelionJd)<=this.WINDOW_DAYS)}static brightestAt(t,e){return this.aroundDate(t).map(i=>this.appearanceOf(i,t,e)).sort((i,n)=>i.magnitude-n.magnitude)[0]}static appearanceOf(t,e,i){const n=ti(e),s=this.earthPositionAt(n),r=this.apparentPositionOf(t,2451545+n.tt,s),o=this.subtract(r,s),c=this.length(r),l=this.length(o),h=this.tailEndAt(t,r,s,c,n,e,i),u=this.horizontalOf(o,n,e,i);return{apparition:t,position:u,...h,heliocentricDistanceAu:c,earthDistanceAu:l,elongationDeg:this.angleBetween(o,this.subtract({x:0,y:0,z:0},s)),magnitude:this.magnitudeAt(t,c,l)}}static magnitudeAt(t,e,i){const n=t.absoluteMagnitude+5*Math.log10(i)+2.5*t.activityExponent*Math.log10(e);return Math.max(n,t.peakMagnitude)}static tailEndAt(t,e,i,n,s,r,o){if(t.tailLengthAu===void 0)return{};const c=1+t.tailLengthAu/n,l=this.subtract({x:e.x*c,y:e.y*c,z:e.z*c},i),h=this.subtract(e,i);return{tailEnd:this.horizontalOf(l,s,r,o),tailLengthDeg:this.angleBetween(h,l)}}static apparentPositionOf(t,e,i){const n=this.orbitOf(t);let s=n.positionAt(e);for(let r=0;r<2;r++){const o=this.length(this.subtract(s,i))/this.LIGHT_SPEED_AU_PER_DAY;s=n.positionAt(e-o)}return s}static horizontalOf(t,e,i,n){const s=Ka(f5(),new ze(t.x,t.y,t.z,e)),r=Ka(ov(e),s),o=Yw(e,new cf(n.lat,n.lng,n.elevationM)),c=new ze(r.x-o.x,r.y-o.y,r.z-o.z,e),l=hf(c);return uf(l.ra,l.dec,i,n)}static earthPositionAt(t){return Ka(d5(),fr(At.Earth,t))}static julianDayOf(t){return 2451545+ti(t).tt}static orbitOf(t){const e=this.orbits.get(t.id);if(e)return e;const i=new Is(t.orbit);return this.orbits.set(t.id,i),i}static subtract(t,e){return{x:t.x-e.x,y:t.y-e.y,z:t.z-e.z}}static length(t){return Math.hypot(t.x,t.y,t.z)}static angleBetween(t,e){const i=(t.x*e.x+t.y*e.y+t.z*e.z)/(this.length(t)*this.length(e)||1);return Math.acos(Math.min(1,Math.max(-1,i)))*180/Math.PI}}const Yu=[{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 Ag{static UNIX_EPOCH_JD=24405875e-1;static aroundDate(t){const e=this.julianDayOf(t);return Yu.filter(i=>this.magnitudeAt(i,e)!==void 0)}static appearancesAt(t,e){const i=this.julianDayOf(t),n=[];for(const s of Yu){const r=this.magnitudeAt(s,i);r!==void 0&&n.push({outburst:s,position:Yn.ofJ2000(s.raHours,s.decDeg,t,e),magnitude:r})}return n.sort((s,r)=>s.magnitude-r.magnitude)}static brightestAt(t,e){return this.appearancesAt(t,e)[0]}static byId(t){return Yu.find(e=>e.id===t)}static magnitudeAt(t,e){const i=t.lightCurve,n=e-t.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,o]=i[s-1]??i[0],[c,l]=i[s]??i[0];if(c===r)return o;const h=Math.min(1,Math.max(0,(n-r)/(c-r)));return o+h*(l-o)}static julianDayOf(t){return t.getTime()/864e5+this.UNIX_EPOCH_JD}}const EA=[{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}],oh=6.5;class qu{static activeAt(t){return EA.flatMap(e=>{const i=this.nearness(e,t);return i<=0?[]:[{shower:e,zhr:e.peakZhr*i,nearness:i}]})}static nearness(t,e){const i=this.dayOfYear(e),n=this.dayOfYear(this.asDate(t.start)),s=this.dayOfYear(this.asDate(t.peak)),r=this.dayOfYear(this.asDate(t.end)),o=this.wrappedDelta(i,s),c=this.wrappedDelta(s,n),l=this.wrappedDelta(r,s);return o<0?o<-c?0:1+o/c:o>0?o>l?0:1-o/l:1}static observedRatePerHour(t,e,i,n=oh){if(e<=0)return 0;const s=oh-n;return t*Math.sin(e*Math.PI/180)/Math.pow(i,s)}static radiantPosition(t,e,i){return Yn.ofJ2000(t.radiantRaHours,t.radiantDecDeg,e,i)}static dayOfYear(t){const e=Date.UTC(t.getUTCFullYear(),0,1);return Math.floor((Date.UTC(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate())-e)/864e5)+1}static asDate(t){return new Date(Date.UTC(2001,t.month-1,t.day))}static wrappedDelta(t,e){const i=t-e;return i>182?i-365:i<-182?i+365:i}}class ai{static QUIET_RATE_PER_HOUR=2;static APEX_RATE_PER_HOUR=8;static POPULATION_INDEX=3;static apexPosition(t,e){const i=ti(t),n=new yh(0,Ww(t).elon-90,1),s=Ka(m5(i),lf(n,i)),r=hf(s);return uf(r.ra,r.dec,t,e)}static observedRatePerHour(t,e=oh){const i=ai.APEX_RATE_PER_HOUR*Math.max(0,Math.sin(t*Math.PI/180)),n=oh-e;return(ai.QUIET_RATE_PER_HOUR+i)/Math.pow(ai.POPULATION_INDEX,n)}static schedule(t){const e=new bh(t.seed^1542469173);return Gr.schedule(t).map(i=>{const n=ai.toCartesian({altitudeDeg:Math.asin(e.next())*180/Math.PI,azimuthDeg:e.between(0,360)}),s=i.fromRadiantDeg*Math.PI/180,r=ai.turnAround(n,e.between(0,360)),o={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:ai.toHorizontal(o),bearingDeg:ai.bearingFrom(o,n)}})}static turnAround(t,e){const[i,n]=ai.basisAround(t),s=e*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(t,e){const[i,n]=ai.basisAround(t),s=t.x*e.x+t.y*e.y+t.z*e.z,r=ai.normalise({x:e.x-t.x*s,y:e.y-t.y*s,z:e.z-t.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(t){const e=Math.abs(t.y)<.9?{x:0,y:1,z:0}:{x:1,y:0,z:0},i=ai.normalise(ai.cross(t,e));return[i,ai.normalise(ai.cross(t,i))]}static toHorizontal(t){const e=Math.hypot(t.x,t.y,t.z)||1;return{altitudeDeg:Math.asin(Math.min(1,Math.max(-1,t.y/e)))*180/Math.PI,azimuthDeg:(Math.atan2(t.x,-t.z)*180/Math.PI%360+360)%360}}static appearanceOf(t){const e=ai.toCartesian(t.radiant??{altitudeDeg:90,azimuthDeg:0}),i=ai.turnAround(e,t.bearingDeg),n=t.fromRadiantDeg*Math.PI/180;return ai.toHorizontal({x:e.x*Math.cos(n)+i.x*Math.sin(n),y:e.y*Math.cos(n)+i.y*Math.sin(n),z:e.z*Math.cos(n)+i.z*Math.sin(n)})}static toCartesian(t){const e=t.altitudeDeg*Math.PI/180,i=t.azimuthDeg*Math.PI/180,n=Math.cos(e);return{x:n*Math.sin(i),y:Math.sin(e),z:-n*Math.cos(i)}}static cross(t,e){return{x:t.y*e.z-t.z*e.y,y:t.z*e.x-t.x*e.z,z:t.x*e.y-t.y*e.x}}static normalise(t){const e=Math.hypot(t.x,t.y,t.z)||1;return{x:t.x/e,y:t.y/e,z:t.z/e}}static TYPICAL_VELOCITY_KM_S=40}const Tg="https://ufoathome.org/tle/index.json";class Oi{static MAX_ELEMENT_AGE_DAYS=7;static DAY_MS=864e5;fetchImpl;indexUrls;index;files=new Map;constructor(t={}){this.fetchImpl=t.fetchImpl??fetch.bind(globalThis),this.indexUrls=t.indexUrls??Oi.defaultIndexUrls()}static defaultIndexUrls(){const t=[];return typeof location<"u"&&/^https?:$/.test(location.protocol)&&t.push(new URL("/tle/index.json",location.href).href),t.includes(Tg)||t.push(Tg),t}static FIRST_SNAPSHOT="2021-02-22";async covers(t){const e=Date.parse(`${Oi.FIRST_SNAPSHOT}T00:00:00Z`)-Oi.MAX_ELEMENT_AGE_DAYS*Oi.DAY_MS;if(t.getTime()<e)return!1;const i=await this.loadIndex();return i?Object.values(i.index.kinds).some(n=>t.getTime()>=Date.parse(n.from)-Oi.MAX_ELEMENT_AGE_DAYS*Oi.DAY_MS&&t.getTime()<=Date.parse(n.to)+Oi.MAX_ELEMENT_AGE_DAYS*Oi.DAY_MS):!1}async at(t){const e=await this.loadIndex();if(!e)return;const{index:i,base:n}=e,s=[],r=[];for(const o of Object.keys(i.kinds)){const c=await this.kindAt(o,t,i,n);s.push(...c),r.push(this.coverageOf(o,t,i,c.length>0))}return{objects:s,coverage:r,credit:i.credit,creditUrl:i.source}}async kindAt(t,e,i,n){const s=e.getTime(),r=i.binDays*Oi.DAY_MS,o=Math.floor(s/r),c=s-o*r<r/2?o-1:o+1,l=new Set(i.kinds[t].bins),h=[o,c].map(v=>new Date(v*r).toISOString().slice(0,10)).filter(v=>l.has(v));if(h.length===0)return[];const[u,...d]=await Promise.all([this.json(new URL(`objects-${t}.json`,n).href),...h.map(v=>this.binary(new URL(`${t}/${v}.bin`,n).href))]),f=new Map;for(const v of d)for(const m of Oi.decode(v,i.recordBytes)){const g=f.get(m.norad);(!g||Math.abs(m.epochMs-s)<Math.abs(g.epochMs-s))&&f.set(m.norad,m)}const p=[];for(const v of f.values()){const m=Math.abs(v.epochMs-s)/Oi.DAY_MS;if(m>Oi.MAX_ELEMENT_AGE_DAYS)continue;const g=u[v.norad]??{name:String(v.norad)};g.launch&&Date.parse(`${g.launch}T00:00:00Z`)>s||p.push({norad:v.norad,name:g.name,kind:t,launch:g.launch,stdMag:g.stdMag,elements:v,ageDays:m})}return p}coverageOf(t,e,i,n){const{from:s,to:r}=i.kinds[t],o=e.getTime(),c=Oi.MAX_ELEMENT_AGE_DAYS*Oi.DAY_MS,l=n?"covered":o<Date.parse(s)-c?"before":o>Date.parse(r)+c?"after":"gap";return{kind:t,status:l,from:s,to:r}}static decode(t,e){const i=new DataView(t),n=[];for(let s=0;s+e<=t.byteLength;s+=e)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 t of this.indexUrls)try{const e=await this.fetchImpl(t);if(!e.ok)continue;return{index:await e.json(),base:t}}catch{}})(),this.index}json(t){return this.cached(t,async e=>e.json())}binary(t){return this.cached(t,async e=>e.arrayBuffer())}cached(t,e){let i=this.files.get(t);return i||(i=this.fetchImpl(t).then(n=>{if(!n.ok)throw new Error(`${t}: ${n.status}`);return e(n)}),i.catch(()=>this.files.delete(t)),this.files.set(t,i)),i}}class AA{lowerM;upperM;add(t,e){if(!(t<=0)){if(e.behindM!==void 0){const i=Ie.sizeMAt(e.behindM,t);this.lowerM=this.lowerM===void 0?i:Math.max(this.lowerM,i)}if(e.inFrontM!==void 0){const i=Ie.sizeMAt(e.inFrontM,t);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(t){return t<=0?{}:{minM:this.lowerM===void 0?void 0:Ie.distanceMAt(this.lowerM,t),maxM:this.upperM===void 0?void 0:Ie.distanceMAt(this.upperM,t)}}clear(){this.lowerM=void 0,this.upperM=void 0}}class Wr{static DEG_PER_SECOND=360/86164.0905;static degOver(t){return Math.max(0,t)*Wr.DEG_PER_SECOND}static instants(t,e){if(!(e>0))return 1;const i=Wr.degOver(t)/e;return i<1?1:Math.min(Wr.MAX_INSTANTS,Math.max(2,Math.ceil(i)))}static MAX_INSTANTS=64}class Vi{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 Wr.DEG_PER_SECOND*3600}static graspOf(t,e={}){const i=e.exposureSeconds??t.exposureSeconds,n=e.fNumber??t.fNumber;if(i===void 0||n===void 0||!(i>0)||!(n>0))return Vi.EYE;const s=e.focalLengthMm??t.frame?.focalLengthMm??Vi.UNKNOWN_CAMERA_FOCAL_MM,r=s/n,o=Vi.resolutionArcsec(t,s,r);return{apertureMm:r,exposureSeconds:Math.min(i,Vi.trailLimitedSeconds(o)),resolutionArcsec:o}}static resolutionArcsec(t,e,i){const s=(t.detailUm??Vi.UNKNOWN_CAMERA_DETAIL_UM)/1e3/e*Vi.ARCSEC_PER_RADIAN,r=1.22*Vi.WAVELENGTH_M/(i/1e3)*Vi.ARCSEC_PER_RADIAN;return Math.max(s,r)}static trailLimitedSeconds(t){return t/Vi.skyDriftArcsecPerSecond}static gainOverEye(t,e={}){const i=Vi.graspOf(t,e),n=Vi.EYE,s=(i.apertureMm/n.apertureMm)**2,r=i.exposureSeconds/n.exposureSeconds,o=(n.resolutionArcsec/i.resolutionArcsec)**2;return 1.25*Math.log10(s*r*o)}static gainFor(t,e){const i=e.fieldOfViewDeg===void 0?void 0:mi.focalLengthMmFor(t,e.fieldOfViewDeg);return Vi.gainOverEye(t,{fNumber:e.fNumber,focalLengthMm:i,exposureSeconds:e.exposureSeconds})}}const Rg=111320,Co=Math.PI/180,TA=1.02,RA=1;class Ko{static of(t,e){const i=Ko.sightings(t,e);if(i.length<2)return;const n=Ko.baseline(i);if(!n)return;const{near:s,far:r,closedM:o}=n,c=Math.tan(r.widthDeg/2*Co)===0?0:Math.tan(s.widthDeg/2*Co)/Math.tan(r.widthDeg/2*Co);if(c<TA)return;const l=o/(c-1),h=Ie.sizeMAt(l,s.widthDeg),u=i.map(d=>({t:d.t,m:Ie.distanceMAt(h,d.widthDeg)}));return{widthM:h,distanceM:u,nearestM:Math.min(...u.map(d=>d.m)),fromT:r.t,toT:s.t,closedM:o}}static sightings(t,e){return t.timeline.allKeyframes.flatMap(i=>{const n=i.shapes.find(o=>o.sourceId===e)?.shape,s=n?.angular?.widthDeg,r=Je(t,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(t){let e;for(const i of t)for(const n of t){if(i.t>=n.t)continue;const s=Ko.closedAlongSight(i,n),[r,o,c]=s>=0?[n,i,s]:[i,n,-s];c<RA||r.widthDeg<=o.widthDeg||(!e||c>e.closedM)&&(e={near:r,far:o,closedM:c})}return e}static closedAlongSight(t,e){const i=(e.lat-t.lat)*Rg,n=(e.lng-t.lng)*Rg*Math.cos(t.lat*Co),s=(t.sightAzimuthDeg??0)*Co;return i*Math.cos(s)+n*Math.sin(s)}}class Gi{static CONVENTIONAL_M=5;static NEAREST_M=.2;static MARGIN=1.1;static resolve(t){if(t.statedM!==void 0&&t.statedM>0)return{distanceM:Gi.atLeastNearest(t.statedM),basis:"stated"};if(t.hypothesisM!==void 0&&t.hypothesisM>0)return{distanceM:Gi.atLeastNearest(t.hypothesisM),basis:"hypothesis"};if(t.derivedM!==void 0&&t.derivedM>0)return{distanceM:Gi.atLeastNearest(t.derivedM),basis:"derived"};const e=Gi.largest(t.range?.minM,t.crossing?.behindM),i=Gi.smallest(t.range?.maxM,t.crossing?.inFrontM),n=e===void 0?void 0:e*Gi.MARGIN,s=i===void 0?void 0:i/Gi.MARGIN;return n!==void 0&&s!==void 0?{distanceM:Gi.atLeastNearest(n<=s?Math.sqrt(n*s):n),basis:"bounded"}:n!==void 0?{distanceM:Gi.atLeastNearest(n),basis:"bounded"}:s!==void 0&&s<Gi.CONVENTIONAL_M?{distanceM:Gi.atLeastNearest(s),basis:"bounded"}:{distanceM:Gi.CONVENTIONAL_M,basis:"conventional"}}static atLeastNearest(t){return Math.max(Gi.NEAREST_M,t)}static largest(...t){const e=t.filter(i=>i!==void 0&&i>0);return e.length===0?void 0:Math.max(...e)}static smallest(...t){const e=t.filter(i=>i!==void 0&&i>0);return e.length===0?void 0:Math.min(...e)}}const $u=Math.PI/180;class ne{constructor(t,e,i){this.body=t,this.ground=e;const n=[...t.track].sort((s,r)=>s.t-r.t);this.keys=this.place(n,i);for(const s of n)ne.collect(this.motionKeys,s.t,s.motions),ne.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};keys;motionKeys=new Map;lightKeys=new Map;static collect(t,e,i){for(const[n,s]of Object.entries(i??{})){const r=t.get(n)??[];r.push({t:e,value:s}),t.set(n,r)}}motionsAt(t){return ne.channelsAt(this.motionKeys,t,0)}lightsAt(t){return this.lightKeys.size>0?ne.channelsAt(this.lightKeys,t,void 0):void 0}static channelsAt(t,e,i){const n={};for(const[s,r]of t){let o=r.length-1;for(;o>=0&&r[o].t>e;)o--;if(o<0){i!==void 0&&(n[s]=i);continue}const c=r[o],l=r[Math.min(o+1,r.length-1)],h=l===c||l.t===c.t?0:Math.min(1,(e-c.t)/(l.t-c.t));n[s]=ne.lerp(c.value,l.value,h)}return n}static eyeOf(t,e,i){const n=Je(t,0),s=Je(t,e),o=n?.lat!==void 0&&n.lng!==void 0&&s?.lat!==void 0&&s.lng!==void 0?je(s.lat,s.lng,n.lat,n.lng):void 0,c=o?o.x:0,l=o?-o.z:0;return{eastM:c,northM:l,upM:i.heightAt(c,l)+ne.EYE_HEIGHT_M+(s?.elevationM??0),headingDeg:s?.headingDeg}}static lineOfSightMeetsGround(t,e,i,n){const s=ne.directionOf(e,i),r=l=>t.upM+s.upM*l-n.heightAt(t.eastM+s.eastM*l,t.northM+s.northM*l);let o=0,c=0;for(;c<ne.MAX_RANGE_M;){if(c=o+Math.max(.5,o*.01),r(c)<=0){for(let l=0;l<30;l++){const h=(o+c)/2;r(h)<=0?c=h:o=h}return c}o=c}}static directionOf(t,e){const i=t*$u,n=e*$u;return{eastM:Math.sin(i)*Math.cos(n),northM:Math.cos(i)*Math.cos(n),upM:Math.sin(n)}}at(t){const e=this.keys;if(e.length===0||t<e[0].t)return;let i=e.length-1;for(;i>0&&e[i].t>t;)i--;const n=e[i];if(!n.present)return;const s=e[Math.min(i+1,e.length-1)],r=s===n||s.t===n.t?0:Math.min(1,(t-n.t)/(s.t-n.t)),o=ne.lerp(n.eastM,s.eastM,r),c=ne.lerp(n.northM,s.northM,r),l={widthM:ne.lerp(n.sizeM.widthM,s.sizeM.widthM,r),lengthM:ne.lerp(n.sizeM.lengthM,s.sizeM.lengthM,r),heightM:ne.lerp(n.sizeM.heightM,s.sizeM.heightM,r)},h={headingDeg:ne.lerpAngle(n.attitude.headingDeg,s.attitude.headingDeg,r),pitchDeg:ne.lerp(n.attitude.pitchDeg,s.attitude.pitchDeg,r),rollDeg:ne.lerp(n.attitude.rollDeg,s.attitude.rollDeg,r)};let u;if("aboveGroundM"in n.vertical&&"aboveGroundM"in s.vertical){const d=ne.lerp(n.vertical.aboveGroundM,s.vertical.aboveGroundM,r);u=this.groundUnderFootprint(o,c,l,h.headingDeg)+d+l.heightM/2}else u=ne.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:o,northM:c,upM:u,sizeM:l,attitude:h,appearance:{color:(r<1?n:s).appearance.color,albedo:ne.lerp(n.appearance.albedo,s.appearance.albedo,r),luminanceCdM2:ne.lerp(n.appearance.luminanceCdM2,s.appearance.luminanceCdM2,r)},flame:ne.flameBetween(n.flame,s.flame,r),motions:this.motionsAt(t),lights:this.lightsAt(t),throwsFlame:this.body.track.some(d=>d.flame!==void 0&&d.flame.luminanceCdM2>0)}}static flameBetween(t,e,i){if(!t||t.luminanceCdM2<=0)return i>=1&&e&&e.luminanceCdM2>0?e:void 0;const n=t,s=e??t,r={...i<1?n:s,lengthM:ne.lerp(n.lengthM,s.lengthM,i),widthM:ne.lerp(n.widthM,s.widthM,i),luminanceCdM2:ne.lerp(n.luminanceCdM2,s.luminanceCdM2,i)};return r.luminanceCdM2>0?r:void 0}centreUpOf(t){return"upM"in t.vertical?t.vertical.upM:this.groundUnderFootprint(t.eastM,t.northM,t.sizeM,t.attitude.headingDeg)+t.vertical.aboveGroundM+t.sizeM.heightM/2}groundUnderFootprint(t,e,i,n){const s=n*$u,r={eastM:Math.cos(s),northM:-Math.sin(s)},o={eastM:Math.sin(s),northM:Math.cos(s)};let c=this.ground.heightAt(t,e);for(const[l,h]of[[-1,-1],[1,-1],[-1,1],[1,1]]){const u=l*i.widthM/2,d=h*i.lengthM/2;c=Math.max(c,this.ground.heightAt(t+r.eastM*u+o.eastM*d,e+r.northM*u+o.northM*d))}return c}place(t,e){const i=[];let n;for(const s of t){const r=s.sizeM??n?.sizeM??ne.DEFAULT_SIZE,o={headingDeg:s.attitude?.headingDeg??n?.attitude.headingDeg??0,pitchDeg:s.attitude?.pitchDeg??n?.attitude.pitchDeg??0,rollDeg:s.attitude?.rollDeg??n?.attitude.rollDeg??0},c={color:s.appearance?.color??n?.appearance.color??ne.DEFAULT_APPEARANCE.color,albedo:s.appearance?.albedo??n?.appearance.albedo??ne.DEFAULT_APPEARANCE.albedo,luminanceCdM2:s.appearance?.luminanceCdM2??n?.appearance.luminanceCdM2??ne.DEFAULT_APPEARANCE.luminanceCdM2},l=this.positionOf(s,e)??(n&&{eastM:n.eastM,northM:n.northM,vertical:this.verticalOf(s)??n.vertical});if(!l)continue;const h=s.flame??n?.flame,u=s.present??n?.present??!0;n={t:s.t,...l,sizeM:r,attitude:o,appearance:c,flame:h,present:u},i.push(n)}return i}verticalOf(t){if(t.onGround)return{aboveGroundM:0};if(t.altitudeAboveGroundM!==void 0)return{aboveGroundM:t.altitudeAboveGroundM}}positionOf(t,e){if(t.eastM!==void 0&&t.northM!==void 0)return{eastM:t.eastM,northM:t.northM,vertical:this.verticalOf(t)??{aboveGroundM:0}};if(t.azimuthDeg===void 0||t.altitudeDeg===void 0)return;const i=e(t.t);if(!i)return;const n=t.distanceM??(t.onGround?ne.lineOfSightMeetsGround(i,t.azimuthDeg,t.altitudeDeg,this.ground):void 0);if(n===void 0)return;const s=ne.directionOf(t.azimuthDeg,t.altitudeDeg),r=i.eastM+s.eastM*n,o=i.northM+s.northM*n;return{eastM:r,northM:o,vertical:this.verticalOf(t)??{upM:i.upM+s.upM*n}}}static lerp(t,e,i){return t+(e-t)*i}static lerpAngle(t,e,i){const n=((e-t)%360+540)%360-180;return((t+n*i)%360+360)%360}}class ge{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(t,e){const i=t.track;if(i.length<2||e<i[0].t||e>i[i.length-1].t)return;let n=0;for(;n<i.length-2&&i[n+1].t<e;)n++;const s=i[n],r=i[n+1],o=r.t-s.t,c=o>0?(e-s.t)/o:0,[l,h]=ge.alongGreatCircle(s,r,c);return{lat:l,lng:h,heightM:(s.altitudeKm+(r.altitudeKm-s.altitudeKm)*c)*1e3}}static viewsAt(t,e,i){const n=[];for(const s of t){const r=s.track[0]?.t??0,o=s.track[s.track.length-1]?.t??0;s.fragments.forEach((c,l)=>{const h=c.fromT??r,u=c.untilT??o;if(e<h||e>u)return;const d=(c.lagS??0)*1e3,f=ge.leadAt(s,e-d);if(!f)return;const p=ge.seenFrom(i,f);if(p.altitudeDeg<0)return;const v=Math.min(ge.FADE_MS,(u-h)/4),m=v>0?Math.min(1,(e-h)/v,(u-e)/v):1,g=-2.5*Math.log10(Math.max(m,.001)),S=c.absoluteMagnitude+5*Math.log10(p.distanceKm/ge.STANDARD_DISTANCE_KM)+g,x=[p],M=(c.trainS??ge.DEFAULT_TRAIN_S)*1e3;for(let b=1;b<=ge.TRAIN_POINTS;b++){const w=Math.min(M*b/ge.TRAIN_POINTS,e-h),T=ge.leadAt(s,e-d-w);if(!T||(x.push(ge.seenFrom(i,T)),w>=e-h))break}n.push({reentryId:s.id,fragmentId:c.id??String(l),head:p,magnitude:S,color:c.color??ge.DEFAULT_COLOR,train:x})})}return n}static seenFrom(t,e){const i=ge.ecef(t),n=ge.ecef(e),s=n[0]-i[0],r=n[1]-i[1],o=n[2]-i[2],c=t.lat*ge.DEG,l=t.lng*ge.DEG,h=-Math.sin(l)*s+Math.cos(l)*r,u=-Math.sin(c)*Math.cos(l)*s-Math.sin(c)*Math.sin(l)*r+Math.cos(c)*o,d=Math.cos(c)*Math.cos(l)*s+Math.cos(c)*Math.sin(l)*r+Math.sin(c)*o,f=Math.hypot(h,u,d);return{altitudeDeg:Math.asin(d/f)/ge.DEG,azimuthDeg:(Math.atan2(h,u)/ge.DEG+360)%360,distanceKm:f/1e3}}static ecef(t){const e=t.lat*ge.DEG,i=t.lng*ge.DEG,n=Math.sin(e),s=ge.A/Math.sqrt(1-ge.E2*n*n);return[(s+t.heightM)*Math.cos(e)*Math.cos(i),(s+t.heightM)*Math.cos(e)*Math.sin(i),(s*(1-ge.E2)+t.heightM)*n]}static alongGreatCircle(t,e,i){const n=h=>{const u=h.lat*ge.DEG,d=h.lng*ge.DEG;return[Math.cos(u)*Math.cos(d),Math.cos(u)*Math.sin(d),Math.sin(u)]},s=n(t),r=n(e),o=Math.max(-1,Math.min(1,s[0]*r[0]+s[1]*r[1]+s[2]*r[2])),c=Math.acos(o);let l;if(c<1e-12)l=s;else{const h=Math.sin((1-i)*c)/Math.sin(c),u=Math.sin(i*c)/Math.sin(c);l=[s[0]*h+r[0]*u,s[1]*h+r[1]*u,s[2]*h+r[2]*u]}return[Math.atan2(l[2],Math.hypot(l[0],l[1]))/ge.DEG,Math.atan2(l[1],l[0])/ge.DEG]}}class pf{static FIRST_DAY="2022-01-01";static mayCover(t){return new Date(t).toISOString().slice(0,10)>=pf.FIRST_DAY}}class DA{constructor(t,e,i){this.citation=t,this.covers=e,this.load=i}loading;mayCover(t){return this.covers(t)}async between(t,e,i,n){try{return await(await this.provider()).between(t,e,i,n)}catch{return{status:"failed"}}}async describe(t,e){try{return await(await this.provider()).describe?.(t,e)}catch{return}}provider(){if(!this.loading){const t=this.load();this.loading=t,t.catch(()=>{this.loading===t&&(this.loading=void 0)})}return this.loading}}const IA="Aircraft positions: adsb.lol feeders and contributors, Open Database License 1.0 (https://www.adsb.lol/docs/open-data/historical/)",CA=[{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 DA(IA,a=>pf.mayCover(a),async()=>new(await $i(async()=>{const{AdsbLolArchiveProvider:a}=await import("./AdsbLolArchiveProvider-2vNkvjL5.js");return{AdsbLolArchiveProvider:a}},[],import.meta.url)).AdsbLolArchiveProvider)}];class Wi{static MAX_GAP_S=60;static FT_TO_M=.3048;static EARTH_RADIUS_KM=6371;static seenFrom(t,e,i){const n=Wi.positionAt(t,i);if(!n)return;const s=ge.seenFrom(e,n.geo);if(!(s.altitudeDeg<0))return{track:t,sky:s,altitudeFt:n.altitudeFt,groundSpeedKt:n.groundSpeedKt,trackDeg:n.trackDeg,angularRateDegPerS:Wi.angularRate(t,e,i)}}static viewsAt(t,e,i){return t.flatMap(n=>Wi.seenFrom(n,e,i)??[])}static groundDistanceKm(t,e){const i=Math.PI/180,n=Math.sin((e.lat-t.lat)*i/2)**2+Math.cos(t.lat*i)*Math.cos(e.lat*i)*Math.sin((e.lng-t.lng)*i/2)**2;return 2*Wi.EARTH_RADIUS_KM*Math.asin(Math.min(1,Math.sqrt(n)))}static wrapLongitude(t){return((t+180)%360+360)%360-180}static positionAt(t,e){const i=t.points;if(i.length===0||e<i[0].t||e>i[i.length-1].t)return;let n=0;for(;n<i.length-1&&i[n+1].t<=e;)n++;const s=i[n],r=i[n+1]??s,o=r.t-s.t;if(o>Wi.MAX_GAP_S*1e3)return;const c=o>0?(e-s.t)/o:0,l=s.altitudeFt+(r.altitudeFt-s.altitudeFt)*c,h=(r.lng-s.lng+540)%360-180;return{geo:{lat:s.lat+(r.lat-s.lat)*c,lng:Wi.wrapLongitude(s.lng+h*c),heightM:l*Wi.FT_TO_M},altitudeFt:l,groundSpeedKt:s.groundSpeedKt,trackDeg:s.trackDeg}}static angularRate(t,e,i){const n=Wi.positionAt(t,i-500),s=Wi.positionAt(t,i+500);if(!n||!s)return;const r=Wi.unit(ge.seenFrom(e,n.geo)),o=Wi.unit(ge.seenFrom(e,s.geo)),c=Math.min(1,Math.max(-1,r[0]*o[0]+r[1]*o[1]+r[2]*o[2]));return Math.acos(c)*180/Math.PI}static unit(t){const e=t.altitudeDeg*Math.PI/180,i=t.azimuthDeg*Math.PI/180;return[Math.cos(e)*Math.sin(i),Math.cos(e)*Math.cos(i),Math.sin(e)]}}const Dg="https://ufoathome.org/fireballs/index.json";class fs{static FIRST_MONTH="2018-12";static STRIKING_MAGNITUDE=-1;static COLOR="#eef2ff";static TRAIN_S=.3;fetchImpl;indexUrls;index;months=new Map;constructor(t={}){this.fetchImpl=t.fetchImpl??fetch.bind(globalThis),this.indexUrls=t.indexUrls??fs.defaultIndexUrls()}static defaultIndexUrls(){const t=[];return typeof location<"u"&&/^https?:$/.test(location.protocol)&&t.push(new URL("/fireballs/index.json",location.href).href),t.includes(Dg)||t.push(Dg),t}static mayCover(t){return new Date(t).toISOString().slice(0,7)>=fs.FIRST_MONTH}async credit(){return(await this.loadIndex())?.index.credit}async between(t,e){if(!fs.mayCover(e))return;const i=await this.loadIndex();if(!i)return;const n=new Set([new Date(t).toISOString().slice(0,7),new Date(e).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>=t&&r.t<=e):void 0}static seenFrom(t,e){const i=fs.peakFraction(t),n={lat:t.from[0]+(t.to[0]-t.from[0])*i,lng:t.from[1]+(t.to[1]-t.from[1])*i,heightM:t.peakHeightKm*1e3},s=ge.seenFrom(e,n);if(!(s.altitudeDeg<0))return{record:t,peak:s,magnitude:t.peakMagnitude+5*Math.log10(s.distanceKm/ge.STANDARD_DISTANCE_KM)}}static asReentry(t,e){const i=t.t-e,n=i+Math.max(t.durationS,.1)*1e3;return{id:`gmn-${t.id}`,track:[{t:i,lat:t.from[0],lng:t.from[1],altitudeKm:t.from[2]},{t:n,lat:t.to[0],lng:t.to[1],altitudeKm:t.to[2]}],fragments:[{absoluteMagnitude:t.peakMagnitude,color:fs.COLOR,trainS:fs.TRAIN_S}]}}static peakFraction(t){const e=t.from[2]-t.to[2];return Math.abs(e)<1e-6?.5:Math.min(1,Math.max(0,(t.from[2]-t.peakHeightKm)/e))}loadIndex(){return this.index??=(async()=>{for(const t of this.indexUrls)try{const e=await this.fetchImpl(t);if(e.ok)return{index:await e.json(),base:t}}catch{}})(),this.index}monthOf(t,e){let i=this.months.get(t);return i||(i=this.fetchImpl(new URL(`${t}.json`,e).href).then(n=>n.ok?n.json():[]).catch(()=>[]),this.months.set(t,i)),i}}const Ea=Math.PI/180,Po=180/Math.PI;class ri{constructor(t){this.timeline=t}static DIRECTION_TOLERANCE_DEG=1;static SIZE_TOLERANCE=1.5;static RINGS=12;static SEGMENTS=24;at(t,e,i,n){const s=[];for(const r of e){const o=ri.projectionOf(r,i,n?.(r));if(o)for(const c of r.explains){const l=this.timeline.getInterpolatedShapeAt(t,c);!l||l.transparency>=1||s.push({...ri.compare(c,r.id,{aim:l.aim,angular:l.angular},o),title:l.title})}}return s}static compare(t,e,i,n){const s=[],r=i.aim?ri.separationDeg(i.aim,n.aim):void 0;if(r!==void 0){const l=Math.max(i.angular?.widthDeg??0,n.angular.widthDeg)/2;r>Math.max(ri.DIRECTION_TOLERANCE_DEG,l)&&s.push("direction")}const o=i.angular&&i.angular.widthDeg>0?n.angular.widthDeg/i.angular.widthDeg:void 0,c=i.angular&&i.angular.heightDeg>0?n.angular.heightDeg/i.angular.heightDeg:void 0;return o!==void 0&&!ri.withinSize(o)&&s.push("width"),c!==void 0&&!ri.withinSize(c)&&s.push("height"),{sourceId:t,bodyId:e,stated:i,predicted:n,separationDeg:r,widthRatio:o,heightRatio:c,disagreements:s}}static projectionOf(t,e,i){const n=i&&i.length>0?i:ri.outlineOf(t),s=i&&i.length>0?ri.centreOf(i):t,r=ri.normalized({eastM:s.eastM-e.eastM,northM:s.northM-e.northM,upM:s.upM-e.upM});if(!r)return;const o=ri.normalized({eastM:r.northM,northM:-r.eastM,upM:0})??{eastM:1,northM:0,upM:0},c=ri.cross(o,r);let l=1/0,h=-1/0,u=1/0,d=-1/0;for(const f of n){const p={eastM:f.eastM-e.eastM,northM:f.northM-e.northM,upM:f.upM-e.upM},v=ri.dot(p,r);if(v<=0)return;const m=Math.atan2(ri.dot(p,o),v),g=Math.atan2(ri.dot(p,c),v);l=Math.min(l,m),h=Math.max(h,m),u=Math.min(u,g),d=Math.max(d,g)}return{aim:{azimuthDeg:(Math.atan2(r.eastM,r.northM)*Po+360)%360,altitudeDeg:Math.asin(Math.max(-1,Math.min(1,r.upM)))*Po},angular:{widthDeg:(h-l)*Po,heightDeg:(d-u)*Po}}}static centreOf(t){const e=i=>(Math.min(...t.map(n=>n[i]))+Math.max(...t.map(n=>n[i])))/2;return{eastM:e("eastM"),northM:e("northM"),upM:e("upM")}}static separationDeg(t,e){const i=t.altitudeDeg*Ea,n=e.altitudeDeg*Ea,s=Math.sin(i)*Math.sin(n)+Math.cos(i)*Math.cos(n)*Math.cos((t.azimuthDeg-e.azimuthDeg)*Ea);return Math.acos(Math.max(-1,Math.min(1,s)))*Po}static withinSize(t){return t<=ri.SIZE_TOLERANCE&&t>=1/ri.SIZE_TOLERANCE}static outlineOf(t){const e=t.sizeM.widthM/2,i=t.sizeM.lengthM/2,n=t.sizeM.heightM/2,s=[],r=t.model.url===void 0?t.model.id:void 0;if(r!==void 0&&r!=="box"&&Mv.includes(r))for(let u=0;u<=ri.RINGS;u++){const d=u/ri.RINGS*Math.PI;for(let f=0;f<ri.SEGMENTS;f++){const p=f/ri.SEGMENTS*2*Math.PI;s.push([e*Math.sin(d)*Math.cos(p),i*Math.sin(d)*Math.sin(p),n*Math.cos(d)])}}else for(const u of[-e,e])for(const d of[-i,i])for(const f of[-n,n])s.push([u,d,f]);const c=t.attitude.headingDeg*Ea,l=t.attitude.pitchDeg*Ea,h=t.attitude.rollDeg*Ea;return s.map(([u,d,f])=>{const p=u*Math.cos(h)+f*Math.sin(h),v=-u*Math.sin(h)+f*Math.cos(h),m=d*Math.cos(l)-v*Math.sin(l),g=d*Math.sin(l)+v*Math.cos(l);return{eastM:t.eastM+p*Math.cos(c)+m*Math.sin(c),northM:t.northM-p*Math.sin(c)+m*Math.cos(c),upM:t.upM+g}})}static dot(t,e){return t.eastM*e.eastM+t.northM*e.northM+t.upM*e.upM}static cross(t,e){return{eastM:t.northM*e.upM-t.upM*e.northM,northM:t.upM*e.eastM-t.eastM*e.upM,upM:t.eastM*e.northM-t.northM*e.eastM}}static normalized(t){const e=Math.hypot(t.eastM,t.northM,t.upM);return e>1e-9?{eastM:t.eastM/e,northM:t.northM/e,upM:t.upM/e}:void 0}}Jg();const PA={sun:"Sun",moon:"Moon",Venus:"Venus",Mars:"Mars",Jupiter:"Jupiter",Saturn:"Saturn"},LA="{name} — mag {mag}, {alt}° above the horizon",OA="{name} — satellite, mag {mag}, {height} km up",NA="satellites-change",FA="fireballs-change",UA="aircraft-change",kA="rr0-confrontation",zA="{name} — mag {mag}, {alt}° below the horizontal",Ku="Credits",Ig="comet:",Cg="nova:",Pg={building:"Building",tree:"Tree",shrub:"Shrub",bridge:"Bridge",wire:"Overhead line",crop:"Crop row",mound:"Stone heap",streetlight:"Streetlight",vehicle:"Vehicle",observer:"Observer",aircraft:"Aircraft",entity:"Being"},BA=new URL(""+new URL("stars-mag7.5-B43R6Wvg.bin",import.meta.url).href,import.meta.url).href,HA=new URL(""+new URL("stars-mag7.5-9-BLV2tFmZ.bin",import.meta.url).href,import.meta.url).href,GA=-18,VA={sun:{altitudeDeg:-3,azimuthDeg:180,magnitude:-26.7},moon:{altitudeDeg:-90,azimuthDeg:0,phase:{phaseFraction:0,illuminatedFraction:0},magnitude:-12.7},planets:[]},bl={lat:0,lng:0,elevationM:0,headingDeg:void 0,pitchDeg:0,fovDeg:60};class We extends HTMLElement{creditsButton;set ownCredits(t){this.creditsButton.hidden=!t}static get observedAttributes(){return["src","star-catalog-src","deep-star-catalog-src","show-compass","max-pixel-ratio",ka,za]}shadow;stageElement;frameElement;sceneCanvas;loaderNote;loaderNotVideo;ufoElement;sceneRenderer;hoverTooltip;resizeObserver;sizeEstimates=new Map;sizeEstimatesFor;distanceHypotheses=new Map;depths=new Map;directionScratch=new R;meteorScheduleFor;lightningScheduleFor;lightningFlashes=[];lastLightningT;lastTimeMs=0;interpretationShown;confrontationReadings=[];confrontationSignature="";comparing=!1;inTheRound=!0;lastSkyKey;starCatalog;starCatalogRequest=0;static tleArchive=new Oi;satellitesFor;satelliteRequest=0;satelliteStatus="none";satellites;satellitePassesMemo;static fireballArchive=new fs;fireballs;static aircraftProviders=new Map;static SOUND_LOOKBACK_MS=3e5;static NO_CONTRAILS=[];static upperAirProviders=new Map;static NO_PRESENCE=new Map;aircraftSource=CA[0];static trafficRuntimeLoading;static trafficRuntime;static loadTrafficRuntime(){return We.trafficRuntimeLoading??=$i(()=>import("./trafficRuntime-VEoNI8g9.js"),__vite__mapDeps([2,1]),import.meta.url).then(t=>We.trafficRuntime=t),We.trafficRuntimeLoading.catch(()=>{We.trafficRuntimeLoading=void 0}),We.trafficRuntimeLoading}traffic;lastSun;decorMemo;starCatalogDepth=0;weatherAudio=new bA;vehicleAudio=new Ov;aircraftAudio;vehicleHearing=new Fl;thunderTimeoutId;handleFullscreenChange=()=>this.resizeToStage();handlePointerMove=t=>{this.sceneRenderer.setCompassHovered(!0);const e=this.ufoElement.canvasElement,i=e.getBoundingClientRect();if(i.width===0||i.height===0)return;const n=(t.clientX-i.left)/i.width*e.width,s=(t.clientY-i.top)/i.height*e.height;if(this.ufoElement.hasVisibleShapeAt(n,s)){this.hoverTooltip.hidden=!0;return}const r=(t.clientX-i.left)/i.width*2-1,o=-((t.clientY-i.top)/i.height*2-1),c=this.naming,l=c.names,h=this.sceneRenderer.pickBodyAt(r,o);if(h){this.showHoverTooltip(t,this.bodyName(h));return}const u=this.interpretationShown?this.sceneRenderer.pickInterpretationBodyAt(r,o):void 0,d=u?this.interpretationShown?.bodies.find(x=>x.id===u):void 0,f=d?this.said.read(d.title)||(d.model.id==="figure"?c.decorKind("entity",Pg.entity):void 0):void 0;if(f){this.showHoverTooltip(t,f);return}const p=this.sceneRenderer.pickDecorAt(r,o),v=p?this.ufoElement.sighting.decor.find(x=>x.id===p):void 0;if(v){this.showHoverTooltip(t,this.said.read(v.title)||c.decorKind(v.kind,Pg[v.kind]));return}const m=this.trafficTooltipAt(r,o);if(m){this.showHoverTooltip(t,m);return}const g=this.sceneRenderer.pickSatelliteAt(r,o);if(g){this.showHoverTooltip(t,(l?.satelliteTooltip??OA).replace("{name}",g.name).replace("{mag}",g.magnitude.toLocaleString(void 0,{maximumFractionDigits:1})).replace("{height}",Math.round(g.heightKm).toLocaleString()));return}const S=this.sceneRenderer.pickStarAt(r,o);if(S){const x=S.star.mag,M=S.altitudeDeg,b=M<0?l?.starTooltipBelow??zA:l?.starTooltip??LA;this.showHoverTooltip(t,b.replace("{name}",c.star(S.star)).replace("{mag}",x.toLocaleString(void 0,{maximumFractionDigits:Math.abs(x)<1?2:1})).replace("{alt}",String(Math.round(Math.abs(M)))));return}this.hoverTooltip.hidden=!0};bodyName(t){const e=t.startsWith(Ig)?t.slice(Ig.length):void 0,i=e?_v.find(r=>r.id===e):void 0;if(i)return this.naming.comet(i);const n=t.startsWith(Cg)?Ag.byId(t.slice(Cg.length)):void 0;if(n)return this.naming.nova(n);const s=PA[t];return s===void 0?t:this.naming.body(t,s)}get naming(){return this.sceneNaming}sceneNaming=new Eg;namesLanguage="en";async loadSceneNames(){const t=zg(Ua.preferencesFor(this),Bg);if(t===this.namesLanguage)return;this.namesLanguage=t;const e=await b2(t);t===this.namesLanguage&&this.applySceneNaming(new Eg(e))}renderLoaderText(t,e){let i=0;const n=(s,r)=>{s.setAttribute("aria-label",r),s.replaceChildren(),r.split(" ").forEach((o,c)=>{c>0&&s.append(" ");const l=document.createElement("span");l.className="scene-loader-word",l.setAttribute("aria-hidden","true");for(const h of o){const u=document.createElement("span");u.className="scene-loader-letter",u.style.setProperty("--i",String(i++)),u.textContent=h,l.append(u)}s.append(l),i++})};n(this.loaderNotVideo,t),i+=6,n(this.loaderNote,e)}applySceneNaming(t){this.sceneNaming=t;const e=t.names?.credits??Ku;this.creditsButton.title=e,this.creditsButton.setAttribute("aria-label",e),t.names&&this.renderLoaderText(t.names.notAVideo,t.names.isASimulation),this.sceneRenderer.setCompassPoints(t.names?.compassPoints)}showHoverTooltip(t,e){this.hoverTooltip.textContent=e,this.hoverTooltip.hidden=!1;const i=this.stageElement.getBoundingClientRect();this.hoverTooltip.style.left=`${t.clientX-i.left+12}px`,this.hoverTooltip.style.top=`${t.clientY-i.top+12}px`}handlePointerLeave=()=>{this.hoverTooltip.hidden=!0,this.sceneRenderer.setCompassHovered(!1)};handleLightningFlash(t){clearTimeout(this.thunderTimeoutId),this.thunderTimeoutId=window.setTimeout(()=>this.weatherAudio.playThunder(),gi.thunderDelayMs(t))}handleFirstInteraction=()=>{this.weatherAudio.resume(),this.vehicleAudio.resume(),this.aircraftAudio?.resume(),!this.interacted&&(this.interacted=!0,this.setWeather(yc(this.ufoElement.sighting,this.lastTimeMs)))};interacted=!1;applyLevel(){const t=this.ufoElement.level;this.weatherAudio.setLevel(t),this.vehicleAudio.setLevel(t),this.aircraftAudio?.setLevel(t)}handlePageGesture=()=>{this.ufoElement.playbackState==="playing"&&this.handleFirstInteraction()};unlockIfAlreadyActivated(){this.interacted||navigator.userActivation?.hasBeenActive&&this.handleFirstInteraction()}static GESTURES=["pointerdown","pointerup","touchend","click","keydown"];handleTimeUpdate=t=>{this.lastTimeMs=t.detail.time,this.syncAnimationsToPlayback(),this.updateAstronomy(this.lastTimeMs),this.ufoElement.playbackState==="playing"&&this.sceneRenderer.frame(performance.now())};syncAnimationsToPlayback(){const t=this.ufoElement.playbackState==="playing";this.sceneRenderer.setAnimationsRunning(t,t),this.weatherAudio.setPaused(!t),this.vehicleAudio.setPaused(!t),this.aircraftAudio?.setPaused(!t),t&&this.unlockIfAlreadyActivated(),t||clearTimeout(this.thunderTimeoutId)}constructor(){super(),this.shadow=this.attachShadow({mode:"open"});const t=document.createElement("template");t.innerHTML=`<style>${Bv}</style>${zv}`,this.shadow.appendChild(t.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 me(this.sceneCanvas);const e=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.sceneRenderer.onFirstFrameHold=s=>{e.hidden=!s,this.ufoElement.captionHeld=s,this.ufoElement.holdClock(s)},this.hoverTooltip=this.shadow.getElementById("hover-tooltip"),this.ufoElement=document.createElement(Qu),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"&&en.fill(n,this)}),this.creditsButton.title=Ku,this.creditsButton.setAttribute("aria-label",Ku),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.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 We.GESTURES)this.addEventListener(s,this.handleFirstInteraction,!0)}get said(){return this.saidTexts??=new Cs(Ua.preferencesFor(this))}saidTexts;traceLabelsFor;traceLabels(t){const e=Ua.preferencesFor(this).join();if(this.traceLabelsFor?.traces!==t||this.traceLabelsFor.language!==e){const i=new Map;for(const n of t){const s=this.said.read(n.title);s&&i.set(n.id,s)}this.traceLabelsFor={traces:t,language:e,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 e of We.GESTURES)document.addEventListener(e,this.handlePageGesture,!0);const t=this.getAttribute("src");t&&this.loadFromSrc(t)}watchVisibility(){this.visibilityObserver?.disconnect(),!(typeof IntersectionObserver>"u")&&(this.visibilityObserver=new IntersectionObserver(t=>{if(t[t.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 t of We.GESTURES)document.removeEventListener(t,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(t,e,i){if(t==="src"&&i&&i!==e&&this.isConnected&&this.loadFromSrc(i),(t==="star-catalog-src"||t==="deep-star-catalog-src")&&i!==e&&this.isConnected&&this.loadStars(),t==="show-compass"&&i!==e&&this.sceneRenderer.setShowCompass(this.hasAttribute("show-compass")),t==="max-pixel-ratio"&&i!==e){const n=Number(i);this.sceneRenderer.setMaxPixelRatio(Number.isFinite(n)&&n>0?n:Math.min(window.devicePixelRatio||1,2))}(t===ka||t===za)&&i!==e&&this.forwardPlayerAttributes()}forwardPlayerAttributes(){for(const t of[ka,za]){const e=this.getAttribute(t);e===null?this.ufoElement.removeAttribute(t):this.ufoElement.setAttribute(t,e)}}setCompassForced(t){this.sceneRenderer.setCompassForced(t)}lookToward(t){const e=Je(this.ufoElement.sighting,this.lastTimeMs);if(t.kind==="observer"||e?.lat===void 0||e.lng===void 0||e.headingDeg===void 0){this.setLookOffset(0,0);return}const{x:i,z:n}=je(t.lat,t.lng,e.lat,e.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-e.headingDeg)%360+540)%360-180,-e.pitchDeg)}setLookOffset(t,e){this.sceneRenderer.setLookOffset(t,e),this.ufoElement.setLookOffset(t,e),this.updateAstronomy(this.lastTimeMs)}setIndoorLook(t,e){this.sceneRenderer.setIndoorLook(t,e)}setCloudRendering(t){this.sceneRenderer.setCloudRendering(t)}setWeather(t){this.sceneRenderer.setWeather(t),this.weatherAudio.setAmbient(t.precipitationType,t.precipitationIntensity*(t.precipitationAmount??1),t.windSpeed)}pickCloudAt(t,e){return this.sceneRenderer.pickCloudAt(t,e)}cloudDirectionAt(t,e){return this.sceneRenderer.cloudDirectionAt(t,e)}pickDecorAt(t,e){return this.sceneRenderer.pickDecorAt(t,e)}decorScreenBox(t){return this.sceneRenderer.decorScreenBox(t)}decorGroundPointAt(t,e,i){return this.sceneRenderer.decorGroundPointAt(t,e,i)}bodyScreenBox(t){return this.sceneRenderer.bodyScreenBox(t)}pickPlacedBodyAt(t,e){return this.sceneRenderer.pickPlacedBodyAt(t,e)}resumeWeatherAudio(){this.weatherAudio.resume(),this.vehicleAudio.resume(),this.aircraftAudio?.resume()}async loadFromSrc(t){const e=Ug.json(t);this.holdForNewScene(e);const i=await e;this.documentUrl=new URL(t,location.href).href,this.sightingData=i}holdForNewScene(t){this.sceneRenderer.holdForNewScene(t)}get documentUrl(){return this.sceneRenderer.documentUrl}set documentUrl(t){this.sceneRenderer.documentUrl=t}get sightingData(){return this.ufoElement.sightingData}set sightingData(t){this.ufoElement.sightingData=t,this.seekPreview?.recordingChanged(t),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(t){const e=this.sceneCanvas.width>0&&this.sceneCanvas.height>0?this.sceneCanvas.width/this.sceneCanvas.height:1.7777777777777777,i=Math.round(t.width/e);return t.height!==i&&(t.height=i),this.seekPreview??=new ah(this,()=>document.createElement(b0))}showAt(t){this.ufoElement.currentTime=t,this.framesAtAsk=this.sceneRenderer.framesDrawn}framesAtAsk=0;snapshotTo(t){if(this.sceneRenderer.frame(performance.now()),this.sceneRenderer.framesDrawn===this.framesAtAsk)return!1;const e=t.getContext("2d");return e?(e.drawImage(this.sceneCanvas,0,0,t.width,t.height),!0):!1}referenceAspect(t){return this.sceneRenderer.referenceAspect(t)}screenPointOf(t){return this.sceneRenderer.screenPointOf(t)}directionAt(t,e){return this.sceneRenderer.directionAt(t,e)}referenceFailedToLoad(t){return this.sceneRenderer.referenceFailedToLoad(t)}applyReferenceView(t){this.sceneRenderer.setReferencesShown(t.shown);for(const e of this.ufoElement.sighting.references){const i=t.views?.[e.id];this.sceneRenderer.setReferenceView(e.id,{opacity:i?i.shown?i.opacity:0:t.opacity})}}get currentTerrainAttribution(){return this.sceneRenderer.currentTerrainAttribution}get currentRoadAttribution(){return this.sceneRenderer.currentRoadAttribution}setTerrainProviders(t){this.sceneRenderer.setTerrainProviders(t)}setDecorModelProvider(t){this.sceneRenderer.setDecorModelProvider(t)}get decorModelCredits(){return[...new Map(this.sceneRenderer.currentDecorModelCredits.map(e=>[`${e.title}|${e.author??""}|${e.license}|${e.sourceUrl??""}`,e])).values()]}applyFrameFormat(){const t=this.ufoElement.sighting.instrument,e=Ie.CANVAS_HEIGHT_PX,i=mi.frameWidthPx(t,e);this.frameElement.style.setProperty("--frame-aspect",`${i} / ${e}`)}resizeToStage(){const t=this.frameElement.getBoundingClientRect(),e=Math.max(1,Math.round(t.width)),i=Math.max(1,Math.round(t.height));this.sceneCanvas.width=e,this.sceneCanvas.height=i,this.sceneRenderer.resize(e,i)}async loadStars(){const t=[{magnitudeLimit:Wu,url:this.getAttribute("star-catalog-src")??BA},{magnitudeLimit:Xu,url:this.getAttribute("deep-star-catalog-src")??HA}],e=this.instrumentReach(),i=++this.starCatalogRequest;this.starCatalogDepth=e>Wu?Xu:Wu;const n=await as.upTo(t,e);i===this.starCatalogRequest&&(this.starCatalog=n,this.sceneRenderer.compileNextFrameOffThread(),this.updateAstronomy(this.lastTimeMs))}ensureStarsDeepEnough(){!this.starCatalog||this.starCatalogDepth>=Xu||this.instrumentReach()<=this.starCatalogDepth||this.loadStars()}instrumentReach(){const t=this.ufoElement.sighting,e=Vi.gainFor(t.instrument,{fNumber:Je(t,0)?.fNumber,fieldOfViewDeg:an.fovOf(t,0),exposureSeconds:t.exposure});return Ll(GA,e)}updateAstronomy(t){this.ensureStarsDeepEnough(),this.applySceneAt(t);const e=Xn.windowEndingAt(t,this.exposureSeconds()),i=e.seconds,n=this.degreesPerPixelAt(t),s=Wr.instants(i,n),r=Math.max(s,this.ufoElement.exposureTimes(t).length,Xn.instants(this.decorWithTraffic(this.ufoElement.sighting),Je(this.ufoElement.sighting,t)?.elevationM??0,e.fromMs,i,n));if(r<=1){this.sceneRenderer.setExposure(1);return}this.sceneRenderer.setExposure(r,o=>this.applySceneAt(e.fromMs+e.ms*o/(r-1),{sky:Math.floor(o*s/r)!==Math.floor((o-1)*s/r),stepMs:e.ms/r}))}exposureSeconds(){return this.ufoElement.sighting.exposure??0}degreesPerPixelAt(t){const e=this.sceneCanvas.height;return e<=0?0:an.fovOf(this.ufoElement.sighting,t)/e}applySceneAt(t,e){const i=this.ufoElement.sighting;this.setWeather(yc(i,t)),this.sceneRenderer.setInstrument(i.instrument),this.sceneRenderer.setLightPollution(i.lightPollution),e||this.vehicleAudio.setVoices(this.vehicleHearing.at(i,t)),e||this.pushAircraftSound(i,t),this.updateMeteorShower(i,t),this.updateLightning(i,t,e!==void 0),this.sceneRenderer.setDecor(this.decorWithTraffic(i)),this.sceneRenderer.setDecorPresence(this.traffic?.set?.presence??We.NO_PRESENCE),this.sceneRenderer.setDecorSunlight(this.trafficSunlight(t)),this.sceneRenderer.setContrails(this.traffic?.contrails??We.NO_CONTRAILS),this.sceneRenderer.setContrailSunlight(this.contrailSunlight(t));const n=Je(i,t);this.sceneRenderer.setReferences(i.references,n?.lat!==void 0&&n.lng!==void 0?{lat:n.lat,lng:n.lng}:void 0);const s=Je(i,0),r=ao(i,0),o=ba(i.event.time??{},n?.lng??bl.lng,i.event.utcOffsetHours),c=i.weatherSource!==void 0&&o?kv(o):void 0,l=Object.fromEntries(Ul(ao(i,t)).map(w=>[w.id,Pf(t,i.weatherTrack,r,s,n,w.id,w.instances?.length?void 0:c)]));this.sceneRenderer.setCloudOffset(Pf(t,i.weatherTrack,r,s,n,void 0,c),l),this.sceneRenderer.setObserverPose(n??bl),this.sceneRenderer.setLensOptics(this.lensOpticsAt(t)),this.sceneRenderer.setInstrumentGain(Vi.gainFor(i.instrument,{fNumber:n?.fNumber,fieldOfViewDeg:an.fovOf(i,t),exposureSeconds:i.exposure}),i.instrument.detailUm!==void 0),this.sceneRenderer.setMedium(i.instrument.medium,i.exposure,n?.fNumber??i.instrument.fNumber,i.iso),this.sceneRenderer.setGait(be.bodyAt(i,t,this.ufoElement.steadyObserver)),this.sceneRenderer.updateDecorAnchoring(Je(i,0),n,t),this.placeBodiesAt(t,e===void 0),this.sceneRenderer.updateDecorLitState(t,e?.stepMs??0),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(t);const h=n?.lat??bl.lat,u=n?.lng??bl.lng,d=ba(i.event.time??{},u,i.event.utcOffsetHours),f={lat:h,lng:u,elevationM:n?.elevationM??0};this.pushSatellitesAt(d,t,f),this.ensureFireballs(d);const p=[...this.interpretationShown?.reentries??[],...this.fireballs?.reentries??[]];if(this.sceneRenderer.setReentries(p.length===0?[]:ge.viewsAt(p,t,{lat:h,lng:u,heightM:f.elevationM})),e&&!e.sky)return;if(!d){this.sceneRenderer.setAstronomy(VA);return}const v=new Date(d.getTime()+t),m=Math.max(1,Math.round(.25*this.degreesPerPixelAt(t)/Wr.DEG_PER_SECOND*1e3)),g=Math.max(1e-8,this.degreesPerPixelAt(t)*.1),S=`${Math.floor(v.getTime()/m)}|${Math.round(h/g)}|${Math.round(u/g)}|${Math.round(f.elevationM)}|${this.starCatalog?this.starCatalogDepth:0}`;if(S===this.lastSkyKey){this.sceneRenderer.render();return}this.lastSkyKey=S;const x={...ll("Sun",v,f),magnitude:xu("Sun",v)};this.lastSun={altitudeDeg:x.altitudeDeg,azimuthDeg:x.azimuthDeg};const M={...ll("Moon",v,f),phase:v5(v),magnitude:xu("Moon",v)},b=g5.map(w=>({body:w,position:ll(w,v,f),magnitude:xu(w,v)}));this.sceneRenderer.setAstronomy({sun:x,moon:M,planets:b,comet:this.cometAt(v,f),novae:Ag.appearancesAt(v,f).map(({outburst:w,position:T,magnitude:y})=>({id:w.id,position:T,magnitude:y})),stars:this.starCatalog?{catalog:this.starCatalog,date:v,observer:f}:void 0,frame:{date:v,observer:f}}),this.ufoElement.setSunAltitude(x.altitudeDeg)}pushSatellitesAt(t,e,i){if(this.ensureSatellites(t),!t||!this.satellites){this.sceneRenderer.setSatellites([]);return}const n=new Date(t.getTime()+e),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(t){const e=this.ufoElement.sighting,i=Math.max((e.event.durationSeconds??0)*1e3,this.ufoElement.seekableDuration),n=t?.getTime(),s=n===void 0?"":`${n}+${i}`;if(this.fireballs?.key===s)return;if(n===void 0||!fs.mayCover(n+i)){this.fireballs={key:s,status:"outside",reentries:[]};return}const r={key:s,status:"loading",reentries:[]};this.fireballs=r,We.fireballArchive.between(n,n+i).then(o=>{r.status=o?"ready":"unavailable",r.records=o??[],r.reentries=r.records.map(c=>fs.asReentry(c,n)),!(this.fireballs!==r||!this.isConnected)&&(this.dispatchEvent(new CustomEvent(FA)),r.reentries.length>0&&this.updateAstronomy(this.lastTimeMs))})}decorWithTraffic(t){const e=this.ensureTraffic(t);if(!e||e.objects.length===0)return t.decor;const i=this.decorMemo;if(i&&i.base===t.decor&&i.traffic===e.objects)return i.merged;const n=[...t.decor,...e.objects];return this.decorMemo={base:t.decor,traffic:e.objects,merged:n},n}ensureTraffic(t){const e=Je(t,0),i=e?.lng===void 0?void 0:ba(t.event.time??{},e.lng,t.event.utcOffsetHours),n=Math.max((t.event.durationSeconds??0)*1e3,this.ufoElement.seekableDuration),s=i?.getTime(),r=s===void 0||e?.lat===void 0||e.lng===void 0?"":`${this.aircraftSource.id}|${s}+${n}|${e.lat.toFixed(3)},${e.lng.toFixed(3)}|${Math.round(e.elevationM??0)}`;if(this.traffic?.key===r)return this.traffic.set;if(r===""||s===void 0||e?.lat===void 0||e.lng===void 0){this.traffic={key:r,status:"outside"};return}let o=We.aircraftProviders.get(this.aircraftSource.id);if(o||We.aircraftProviders.set(this.aircraftSource.id,o=this.aircraftSource.create()),o.mayCover&&!o.mayCover(s+n)){this.traffic={key:r,status:"outside"};return}const c={key:r,status:"loading",startMs:s,observer:{lat:e.lat,lng:e.lng}};this.traffic=c;const l={lat:e.lat,lng:e.lng,heightM:e.elevationM??0},h=Wi.MAX_GAP_S*1e3,u=We.SOUND_LOOKBACK_MS,d={lat:e.lat,lng:e.lng,elevationM:e.elevationM??0},f=(p,v)=>p.TrafficDecor.from(c.tracks??[],l,s,p.TrafficDecor.MAX_OBJECTS,{models:v,sunElevationAt:m=>this.sunElevationAt(m,d)});o.between(l,s-u,s+n+h).then(async p=>{if(this.traffic!==c)return;if(p.status!=="found"){c.status=p.status==="outside"?"outside":"unavailable",this.announceTraffic();return}let v;try{v=await We.loadTrafficRuntime()}catch{this.traffic===c&&(c.status="unavailable",this.announceTraffic());return}this.traffic===c&&(c.status="ready",c.tracks=p.tracks,c.set=f(v),this.startAircraftSound(c,v),this.announceTraffic(),this.describeTraffic(o,c,v,f),c.set.shown>0&&this.readUpperAir(c,v,s-u,s+n+h))})}trafficSunlight(t){const e=new Map,i=this.traffic,n=i?.set,s=this.lastSun;if(!n||!s||i.startMs===void 0||!i.observer)return e;for(const[r,o]of n.presence){if(t<o.fromMs||t>o.untilMs)continue;const c=n.flights.get(r),l=c?Wi.positionAt(c,i.startMs+t):void 0;l&&e.set(r,{heightM:l.geo.heightM,sunElevationDeg:vn.sunElevationDeg(s,i.observer,l.geo)})}return e}trafficTooltipAt(t,e){const i=this.sceneRenderer.pickTrafficAt(t,e),n=i?this.trafficInfoAt(i):void 0;if(!n)return;const s=this.naming,r=We.trafficRuntime;return r?.TrafficTooltip.text(n,s.names?.trafficTooltip??r.TrafficTooltip.ENGLISH,o=>s.towards(o))}trafficInfoAt(t){const e=this.traffic,i=e?.set?.flights.get(t);if(!e||!i||e.startMs===void 0||!e.observer)return;const n=We.trafficRuntime;if(!n)return;const s=e.descriptions?.get(Cn.keyOf(i)),r=Je(this.ufoElement.sighting,this.lastTimeMs),o={lat:e.observer.lat,lng:e.observer.lng,heightM:r?.elevationM??0},c=n.AmbientNoise.dbA(yc(this.ufoElement.sighting,this.lastTimeMs)),l=n.TrafficInfos.at(i,s,o,e.startMs+this.lastTimeMs,{ambientDbA:c}),h=l&&this.contrailAt(t,this.lastTimeMs);return l&&h?{...l,contrail:h}:l}contrailAt(t,e){const i=this.traffic?.contrails?.find(s=>s.id===t);if(!i)return;let n;for(const s of i.points){if(s.tMs>e)break;n=s}return n?.forms?{persistent:n.persistent,iceRelativeHumidity:n.iceRelativeHumidity}:void 0}startAircraftSound(t,e){this.aircraftAudio||(this.aircraftAudio=new e.AircraftAudio,this.aircraftAudio.setLevel(this.ufoElement.level),this.interacted&&this.aircraftAudio.resume(),this.aircraftAudio.setPaused(this.ufoElement.playbackState!=="playing")),this.sortOutAudible(t,e)}sortOutAudible(t,e){!t.set||!t.observer||(t.audible=e.TrafficSound.candidates(t.set.flights,t.descriptions??new Map,Cn.keyOf,{...t.observer,heightM:0},{ambientDbA:e.AmbientNoise.BASE_DB_A}))}pushAircraftSound(t,e){const i=this.aircraftAudio;if(!i)return;const n=We.trafficRuntime,s=this.traffic,r=s?.set;if(!n||!s||!r||!s.audible||s.startMs===void 0||!s.observer){i.setVoices([]);return}const o=Je(t,e),c={lat:s.observer.lat,lng:s.observer.lng,heightM:o?.elevationM??0},l=yc(t,e),h=n.TrafficSound.voices(s.audible,r.flights,s.descriptions??new Map,Cn.keyOf,c,s.startMs+e,{ambientDbA:n.AmbientNoise.dbA(l),referenceAmplitude:n.AmbientNoise.referenceAmplitude(l)});i.setVoices(h,o?.headingDeg??0)}announceTraffic(){this.isConnected&&(this.dispatchEvent(new CustomEvent(UA)),this.updateAstronomy(this.lastTimeMs))}async describeTraffic(t,e,i,n){if(!t.describe||!e.set||!e.tracks)return;const s=new Set([...e.set.flights.values()].map(l=>Cn.keyOf(l))),r=e.tracks.filter(l=>s.has(Cn.keyOf(l))&&l.points.length>0),o=new Map,c=new Map;await Promise.all(r.map(async l=>{const h=new Date(l.points[0].t).toISOString().slice(0,10),u=await t.describe(l,h).catch(()=>{});u&&(c.set(Cn.keyOf(l),u),o.set(Cn.keyOf(l),i.AircraftModels.of(u)))})),!(this.traffic!==e||o.size===0)&&(e.descriptions=c,e.models=o,e.set=n(i,o),this.planContrails(e,i),this.sortOutAudible(e,i),this.announceTraffic())}async readUpperAir(t,e,i,n){if(!t.observer)return;const s=this.upperAirSource??e.UPPER_AIR_SOURCES[0];let r=We.upperAirProviders.get(s.id);r||We.upperAirProviders.set(s.id,r=s.create());const o=await r.between(t.observer,i,n);this.traffic!==t||o.status!=="found"||(t.air=o.samples,t.airSource=o.source,this.planContrails(t,e),this.announceTraffic())}planContrails(t,e){!t.set||!t.air||t.startMs===void 0||(t.contrails=e.AircraftContrails.plan(t.set,t.models,t.air,t.startMs))}contrailSunlight(t){const e=new Map,i=this.traffic,n=i?.set,s=this.lastSun;if(!n||!s||!i.contrails?.length||i.startMs===void 0||!i.observer)return e;for(const r of i.contrails){const o=n.presence.get(r.id),c=n.flights.get(r.id);if(!o||!c)continue;const l=Wi.positionAt(c,i.startMs+Math.min(o.untilMs,Math.max(o.fromMs,t)));l&&e.set(r.id,{heightM:l.geo.heightM,sunElevationDeg:vn.sunElevationDeg(s,i.observer,l.geo)})}return e}sunElevationAt(t,e){const i=ll("Sun",new Date(t.t),e);return vn.sunElevationDeg(i,e,t)}upperAirSource;setUpperAirSource(t){t.id!==this.upperAirSource?.id&&(this.upperAirSource=t,this.traffic=void 0,this.decorMemo=void 0,this.updateAstronomy(this.lastTimeMs))}setAircraftSource(t){t.id!==this.aircraftSource.id&&(this.aircraftSource=t,this.traffic=void 0,this.decorMemo=void 0,this.updateAstronomy(this.lastTimeMs))}get aircraftState(){const t=this.traffic?.contrails?.length?this.upperAirSource??We.trafficRuntime?.UPPER_AIR_SOURCES[0]:void 0;return{trailCredit:t&&{credit:t.credit,creditUrl:t.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(t){const e=t?String(t.getTime()):"";if(e===this.satellitesFor)return;this.satellitesFor=e,this.satellites=void 0,this.satellitePassesMemo=void 0;const i=++this.satelliteRequest;if(!t){this.satelliteStatus="none";return}this.satelliteStatus="loading";const n=r=>{i===this.satelliteRequest&&(this.satelliteStatus=r,this.isConnected&&this.dispatchEvent(new CustomEvent(NA)))},s=We.tleArchive;(async()=>{if(!await s.covers(t))return n("outside");const[r,o]=await Promise.all([s.at(t),$i(()=>import("./SatellitePasses-Pfro2-0Z.js"),[],import.meta.url)]);if(i===this.satelliteRequest){if(!r)return n("unavailable");this.satellites={snapshot:r,passes:new o.SatellitePasses(r.objects)},n("ready"),this.isConnected&&this.updateAstronomy(this.lastTimeMs)}})().catch(()=>n("unavailable"))}get satelliteState(){const t=this.satellites?.snapshot;return{status:this.satelliteStatus,coverage:t?.coverage,credit:t?.credit,creditUrl:t?.creditUrl}}satellitePassesDuring(t){const e=this.satellites,i=this.ufoElement.sighting,n=Je(i,0),s=i.event.place?.[0],r=n?.lat??s?.lat,o=n?.lng??s?.lng;if(!e||r===void 0||o===void 0)return[];const c=ba(i.event.time??{},o,i.event.utcOffsetHours);if(!c)return[];const l=Math.min(Math.max(t,0),4*36e5),h={lat:r,lng:o,elevationM:n?.elevationM??0},u=JSON.stringify([this.satellitesFor,c.getTime(),r,o,h.elevationM,l]);if(this.satellitePassesMemo?.key===u)return this.satellitePassesMemo.passes;const d=Math.max(10,Math.ceil(l/1e3/600)),f=e.passes.passesDuring(c,new Date(c.getTime()+l),h,d);return this.satellitePassesMemo={key:u,passes:f},f}cometAt(t,e){const i=wA.brightestAt(t,e);if(i)return{id:i.apparition.id,position:i.position,tailEnd:i.tailEnd,magnitude:i.magnitude}}pushPhenomenaAt(t){const e=this.ufoElement.sighting;e!==this.sizeEstimatesFor&&(this.sizeEstimates.clear(),this.distanceHypotheses.clear(),this.sizeEstimatesFor=e);const i=e.timeline,n=this.ufoElement.canvasElement,s=this.ufoElement.frameShiftPx,r=this.projectionAt(t),o=new Map,c=new Map,l=new Set;for(const p of i.sourceIds){const v=i.getInterpolatedShapeAt(t,p);if(!v)continue;const m={...v,bounds:{...v.bounds,x:v.bounds.x+s.x,y:v.bounds.y+s.y}};o.set(p,m);const g=v.aim?this.sceneRenderer.screenPointOf(Wn.directionOf(v.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)},S=g!==void 0&&Math.abs(g.ndcX)<=1&&Math.abs(g.ndcY)<=1,x=S?this.sceneRenderer.decorDistancesAt(g.ndcX,g.ndcY,p):{};l.add(p),(S||v.aim)&&l.delete(p);const M=v.angular?.widthDeg??r.pxToDeg(v.bounds.width),b=this.sizeEstimateOf(p);b.add(M,x);const w=Ko.of(e,p);c.set(p,Gi.resolve({hypothesisM:this.distanceHypotheses.get(p),derivedM:w&&M>0?Ie.distanceMAt(w.widthM,M):void 0,range:b.distanceRangeAt(M),crossing:x}))}for(const[p,v]of o)for(const[m,g]of o){if(m===p||g.transparency>=1||g.bounds.width*g.bounds.height<=v.bounds.width*v.bounds.height||!(v.bounds.x>=g.bounds.x&&v.bounds.y>=g.bounds.y&&v.bounds.x+v.bounds.width<=g.bounds.x+g.bounds.width&&v.bounds.y+v.bounds.height<=g.bounds.y+g.bounds.height))continue;const x=c.get(m);x&&c.set(p,{distanceM:x.distanceM*.999,basis:x.basis});break}this.depths=c;const h=i.sourceIds,u=[];for(const[p,v]of o)u.push({sourceId:p,shape:v,distanceM:c.get(p).distanceM,renderOrder:h.indexOf(p),aim:v.aim,hidden:l.has(p)||this.interpretationShown!==void 0&&(!this.comparing||v.transparency>=1),ghost:this.interpretationShown!==void 0&&this.comparing});const f=(Je(e,t)?.rollDeg??0)+be.bodyAt(e,t,this.ufoElement.steadyObserver).rollDeg;this.sceneRenderer.setPhenomena(u,{projection:r,canvasWidthPx:n.width,canvasHeightPx:n.height,scale:Math.max(1,this.sceneCanvas.height/Math.max(1,n.height)),starPoints:mi.starPointsOf(e.instrument),rollRad:f*Math.PI/180})}get interpretation(){return this.interpretationShown}set interpretation(t){this.interpretationShown=t,this.syncAccountHidden(),this.updateAstronomy(this.lastTimeMs)}syncAccountHidden(){this.ufoElement.accountHidden=this.interpretationShown!==void 0&&!this.comparing}get accountInTheRound(){return this.inTheRound}set accountInTheRound(t){this.inTheRound=t}get compareAccount(){return this.comparing}set compareAccount(t){this.comparing=t,this.syncAccountHidden(),this.updateAstronomy(this.lastTimeMs)}get confrontation(){return this.confrontationReadings}groundAlong(t,e,i){const n=this.sceneRenderer.bodyGround,s=ne.eyeOf(this.ufoElement.sighting,i,n);return s?ne.lineOfSightMeetsGround(s,t,e,n):void 0}bodyReading(t,e){const i=this.sceneRenderer.bodyGround,n=this.ufoElement.sighting,s=d=>ne.eyeOf(n,d,i),r=new ne(t,i,s).at(e),o=s(e);if(!r||!o)return;const c=r.eastM-o.eastM,l=r.northM-o.northM,h=r.upM-o.upM,u=Math.hypot(c,l);return{azimuthDeg:(Math.atan2(c,l)*180/Math.PI+360)%360,altitudeDeg:Math.atan2(h,u)*180/Math.PI,distanceM:Math.hypot(u,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(t,e){const i=this.sceneRenderer.bodyGround,n=this.ufoElement.sighting,s=p=>ne.eyeOf(n,p,i),r=new ne(t,i,s),o=r.at(e)?e:t.track[0]?.t,c=o===void 0?void 0:r.at(o),l=o===void 0?void 0:s(o);if(!c||!l)return;const h=c.eastM-l.eastM,u=c.northM-l.northM,d=c.upM-l.upM,f=Math.hypot(h,u);if(!(f===0&&d===0))return{azimuthDeg:(Math.atan2(h,u)*180/Math.PI+360)%360,altitudeDeg:Math.atan2(d,f)*180/Math.PI}}placeBodiesAt(t,e){const i=this.interpretationShown,n=this.ufoElement.sighting;let s=[],r=[];const o=this.sceneRenderer.bodyGround,c=p=>ne.eyeOf(n,p,o);i&&(s=i.bodies.map(p=>new ne(p,o,c).at(t)).filter(p=>p!==void 0));const l=ao(n,t),h=l.windDirectionDeg*Math.PI/180,u={x:l.windSpeed*Math.sin(h),z:-l.windSpeed*Math.cos(h)};this.sceneRenderer.setBodies(s,t/1e3,i?.bodies.map(p=>p.id)??[],i?.smoke??[],u);const d=i&&this.comparing?c(t):void 0;if(d&&(r=new ri(n.timeline).at(t,s,d,p=>p.outlineNode?this.sceneRenderer.bodyOutline?.(p.id,p.outlineNode):void 0)),this.confrontationReadings=r,!e)return;const f=JSON.stringify(r);f!==this.confrontationSignature&&(this.confrontationSignature=f,this.dispatchEvent(new CustomEvent(kA,{detail:r})))}setDistanceHypothesis(t,e){e===void 0||!(e>0)?this.distanceHypotheses.delete(t):this.distanceHypotheses.set(t,e),this.updateAstronomy(this.lastTimeMs)}depthOf(t){return this.depths.get(t)}sizeRangeOf(t){return this.sizeEstimateOf(t).sizeRange}distanceRangeAt(t,e){const i=this.ufoElement.sighting.timeline.getInterpolatedShapeAt(e,t);if(!i)return{};const n=i.angular?.widthDeg??this.projectionAt(e).pxToDeg(i.bounds.width);return this.sizeEstimateOf(t).distanceRangeAt(n)}sizeContradictory(t){return this.sizeEstimateOf(t).contradictory}updateMeteorShower(t,e){this.ensureMeteorSchedule(t),this.sceneRenderer.updateMeteors(e)}updateLightning(t,e,i){if(this.ensureLightningSchedule(t),this.sceneRenderer.updateLightning(e),i)return;const n=this.lastLightningT;if(this.lastLightningT=e,n===void 0||e<n||this.ufoElement.playbackState!=="playing")return;const s=this.lightningFlashes.filter(r=>r.t>n&&r.t<=e).pop();s&&ao(t,s.t).storm&&this.handleLightningFlash(s)}ensureLightningSchedule(t){const e=ao(t,0).precipitationIntensity,i=`${this.meteorInputsOf(t)}|${e}`;if(i===this.lightningScheduleFor)return;this.lightningScheduleFor=i;const n=t.event.time,s=t.event.place?.[0],r=n?.year!==void 0?ba(n,s?.lng??0,t.event.utcOffsetHours):void 0,o=(t.event.durationSeconds??0)*1e3||t.timeline.duration||2e4,c=Math.round((r?.getTime()??0)/1e3)+Math.round((s?.lat??0)*1e3)+7;this.lightningFlashes=gi.schedule({durationMs:o,seed:c,intensity:e}),this.sceneRenderer.setLightning(this.lightningFlashes)}ensureMeteorSchedule(t){const e=this.meteorInputsOf(t);e!==this.meteorScheduleFor&&(this.meteorScheduleFor=e,this.scheduleMeteors(t))}meteorInputsOf(t){const e=t.event.place?.[0],i=t.event.time;return JSON.stringify([e?.lat,e?.lng,i?.year,i?.month,i?.day,i?.hour,i?.minute,i?.second,t.event.utcOffsetHours,t.event.durationSeconds,t.timeline.duration])}scheduleMeteors(t){const e=t.event.place?.[0],i=t.event.time,n=e?.lat!==void 0&&e.lng!==void 0&&i?.year!==void 0?ba(i,e.lng,t.event.utcOffsetHours):void 0;if(!n||e?.lat===void 0||e.lng===void 0){this.sceneRenderer.setMeteorShower([],0,0);return}const s={lat:e.lat,lng:e.lng,elevationM:0},r=(t.event.durationSeconds??0)*1e3||t.timeline.duration||2e4,o=Math.round(n.getTime()/1e3)+Math.round(e.lat*1e3),c=ai.schedule({ratePerHour:ai.observedRatePerHour(ai.apexPosition(n,s).altitudeDeg),durationMs:r,velocityKmS:ai.TYPICAL_VELOCITY_KM_S,seed:o}),l=qu.activeAt(n).map(u=>{const d=qu.radiantPosition(u.shower,n,s);return{entry:u,position:d,rate:qu.observedRatePerHour(u.zhr,d.altitudeDeg,u.shower.populationIndex)}}).sort((u,d)=>d.rate-u.rate)[0];if(!l||l.rate<=0){this.sceneRenderer.setMeteorShower(c,0,0);return}const h=Gr.schedule({ratePerHour:l.rate,durationMs:r,velocityKmS:l.entry.shower.velocityKmS,seed:o+1});this.sceneRenderer.setMeteorShower([...h,...c],l.position.altitudeDeg,l.position.azimuthDeg)}meteorByRank(t){this.ensureMeteorSchedule(this.ufoElement.sighting);const e=[...this.sceneRenderer.meteorSchedule].filter(s=>s.t+s.durationMs<=this.ufoElement.seekableDuration).sort((s,r)=>r.brightness-s.brightness);if(e.length===0)return;const i=e[t%e.length],n=this.sceneRenderer.meteorMidpoint(i);if(n)return{t:Math.round(i.t+i.durationMs*.45),...n}}lensOpticsAt(t){const e=this.ufoElement.sighting,i=e.instrument,n=i.frame,s=Je(e,t),r=s?.fNumber??i.fNumber;if(!n||r===void 0)return;const o=mi.focalLengthMmFor(i,an.fovOf(e,t));if(o!==void 0)return{focalLengthMm:o,fNumber:r,focusDistance:s?.focusDistanceM??0,frameHeightMm:n.heightMm}}projectionAt(t){const e=this.ufoElement.sighting;return Ls.of(e.instrument,Ie.CANVAS_HEIGHT_PX,an.fovOf(e,t))}sizeEstimateOf(t){let e=this.sizeEstimates.get(t);return e||(e=new AA,this.sizeEstimates.set(t,e)),e}}const b0="rr0-scene";function WA(){Jg(),customElements.get(b0)||customElements.define(b0,We)}WA();export{eT as $,zr as A,ki as B,st as C,P2 as D,tT as E,de as F,Re as G,_x as H,sT as I,Vl as J,qi as K,oT as L,bt as M,iT as N,I1 as O,Hd as P,Wp as Q,ge as R,ks as S,Cn as T,xx as U,R as V,QA as W,ZA as X,on as Y,Ap as Z,Ge as _,Wi as a,rT as a0,M1 as a1,Lr as a2,Ac as a3,Ch as a4,hM as a5,le as a6,Ce as a7,sc as a8,cd as a9,Ri as aa,zs as ab,gx as ac,ar as ad,Ae as ae,KA as af,JA as ag,S1 as ah,jA as ai,rn as aj,Zn as ak,y1 as al,kp as am,hx as an,Bl as ao,zd as ap,Ei as aq,R1 as ar,X0 as as,Y0 as at,ce as au,pr as av,pc as aw,aT as b,ql as c,fe as d,cs as e,Mt as f,pt as g,ae as h,te as i,$A as j,se as k,mn as l,Il as m,Bs as n,go as o,je as p,Jt as q,_n as r,xn as s,IA as t,pf as u,XA as v,qA as w,YA as x,mc as y,nT as z};