@rr0/ufoathome 0.74.0 → 0.74.1
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.
|
@@ -468,7 +468,7 @@ const xv=`
|
|
|
468
468
|
margin: 0.4em 0 0;
|
|
469
469
|
padding-left: 1.2em;
|
|
470
470
|
}
|
|
471
|
-
`;class Va extends Error{constructor(e,t,i){super(`${e}: ${t}${i===void 0?"":` (HTTP ${i})`}`),this.kind=e,this.url=t,this.status=i,this.name="SightingFetchError"}}class Ao{static async json(e){const t=new URL(e,location.href);if(location.protocol==="https:"&&t.protocol==="http:")throw new Va("mixed-content",e);let i;try{i=await fetch(e)}catch{throw await this.diagnose(e,t)}if(!i.ok)throw new Va("status",e,i.status);try{return await i.json()}catch{throw new Va("malformed",e)}}static async diagnose(e,t){if(t.origin===location.origin)return new Va("unreachable",e);try{return await fetch(e,{mode:"no-cors"}),new Va("cors",e)}catch{return new Va("unreachable",e)}}}class Zi{constructor(e){this.entries=e}static empty(){return new Zi(new Map)}get size(){return this.entries.size}at(e){return this.entries.get(e)}paths(){return[...this.entries.keys()]}set(e,t){t.basis==="stated"&&t.rationale===void 0?this.entries.delete(e):this.entries.set(e,t)}clear(e){for(const t of this.entries.keys())(t===e||t.startsWith(`${e}.`))&&this.entries.delete(t)}static strip(e){const t=new Zi(new Map);return{recording:Zi.stripValue(e,[],t),provenance:t}}static restore(e,t){if(t.size===0)return e;const i=structuredClone(e);for(const n of t.paths()){const s=t.at(n),a=n.split("."),o=Zi.holderOf(i,a);if(!o)continue;const c=a[a.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(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&"value"in e}static stripValue(e,t,i){return Zi.isWrapper(e)?(i.set(t.join("."),{basis:e.basis??"stated",...e.rationale===void 0?{}:{rationale:e.rationale},of:e.value}),Zi.stripValue(e.value,t,i)):Array.isArray(e)?e.map((n,s)=>Zi.stripValue(n,[...t,String(s)],i)):typeof e=="object"&&e!==null?Object.fromEntries(Object.entries(e).map(([n,s])=>[n,Zi.stripValue(s,[...t,n],i)])):e}static holderOf(e,t){let i=e;for(const n of t.slice(0,-1)){if(typeof i!="object"||i===null)return;i=i[n]}return typeof i=="object"&&i!==null?i:void 0}}class bs{static SIGHTING_EVENT="sighting";static INTERPRETATION_EVENT="interpretation";static isCase(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&Array.isArray(e.events)&&!("timeline"in e)}static sightingUrls(e,t){return(e.events??[]).filter(i=>i.eventType===bs.SIGHTING_EVENT&&typeof i.url=="string"&&i.url!=="").map(i=>new URL(i.url,t).href)}static interpretationEvents(e,t){return t?(e.events??[]).filter(i=>i.eventType===bs.INTERPRETATION_EVENT&&i.sighting===t).map(i=>i):[]}static async interpretationOf(e,t,i){if(e.bodies)return bs.withModelsFrom(Zi.strip({title:e.title,bodies:e.bodies,smoke:e.smoke}).recording,t);if(!e.url)return{title:e.title,bodies:[]};const n=new URL(e.url,t).href,s=await i(n);return bs.withModelsFrom(Zi.strip({title:e.title??s.title,bodies:s.bodies??[],smoke:s.smoke}).recording,n)}static withModelsFrom(e,t){return{...e,bodies:e.bodies.map(i=>i.model?.url?{...i,model:{...i.model,url:new URL(i.model.url,t).href}}:i)}}}class Et{static MOON_ANGULAR_WIDTH_DEG=.5237;static CANVAS_WIDTH_PX=640;static CANVAS_HEIGHT_PX=360;static angularWidthDeg(e){return 2*Math.atan(e.sizeM/(2*e.distanceM))*180/Math.PI}static inMoons(e){return e/Et.MOON_ANGULAR_WIDTH_DEG}static lerpAngular(e,t,i){if(!(!e||!t))return{widthDeg:e.widthDeg+(t.widthDeg-e.widthDeg)*i,heightDeg:e.heightDeg+(t.heightDeg-e.heightDeg)*i}}static sizeMAt(e,t){return 2*e*Math.tan(t*Math.PI/360)}static distanceMAt(e,t){return e/(2*Math.tan(t*Math.PI/360))}}function bv(r,e,t){if(!r||!e)return t<1?r:e;const i=((e.azimuthDeg-r.azimuthDeg)%360+540)%360-180;return{azimuthDeg:((r.azimuthDeg+i*t)%360+360)%360,altitudeDeg:r.altitudeDeg+(e.altitudeDeg-r.altitudeDeg)*t}}function _v(r,e,t){const{bounds:i}=r;return e>=i.x&&e<=i.x+i.width&&t>=i.y&&t<=i.y+i.height}function Ki(r,e,t){return r+(e-r)*t}function of(r){const e=/^#([0-9a-f]{6})$/i.exec(r);if(!e)return;const t=parseInt(e[1],16);return[t>>16&255,t>>8&255,t&255]}function Sv(r){return`#${r.map(e=>Math.round(e).toString(16).padStart(2,"0")).join("")}`}function wv(r,e,t){const i=of(r),n=of(e);return!i||!n?t<1?r:e:Sv([Ki(i[0],n[0],t),Ki(i[1],n[1],t),Ki(i[2],n[2],t)])}function Ev(r,e,t){const i={x:Ki(r.bounds.x,e.bounds.x,t),y:Ki(r.bounds.y,e.bounds.y,t),width:Ki(r.bounds.width,e.bounds.width,t),height:Ki(r.bounds.height,e.bounds.height,t)},n=Ki(r.angle,e.angle,t),s=Ki(r.transparency,e.transparency,t),a=Ki(r.haloScale,e.haloScale,t),o=Ki(r.blur??0,e.blur??0,t),c=Ki(r.brightness??0,e.brightness??0,t),l=wv(r.color,e.color,t),h=Et.lerpAngular(r.angular,e.angular,t),u=bv(r.aim,e.aim,t);return r.kind==="polygon"&&e.kind==="polygon"&&r.points.length===e.points.length?{...r,bounds:i,angle:n,transparency:s,haloScale:a,blur:o,brightness:c,color:l,angular:h,aim:u,points:r.points.map((d,f)=>({x:Ki(d.x,e.points[f].x,t),y:Ki(d.y,e.points[f].y,t)}))}:{...t<1?r:e,bounds:i,angle:n,transparency:s,haloScale:a,blur:o,brightness:c,color:l,angular:h,aim:u}}class xa{static DEFAULT_COLOR="#e8e6df";static complete(e,t=[]){const i=new Map;return e.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((a,o)=>{const c=`timeline.keyframes.${s}.shapes.${o}.shape`,l=xa.completed(a,i.get(a.sourceId),c,t);return i.set(a.sourceId,l),{sourceId:a.sourceId,shape:l}})}))}static completed(e,t,i,n){const s=e.shape??{},a=t??xa.firstAppearance(s,i,n),o={...a};s.bounds&&t&&(t.aim||t.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??a.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(e,t,i){return e.kind||i.push({kind:"defaulted",path:`${t}.kind`,expected:'"oval"'}),e.color||i.push({kind:"defaulted",path:`${t}.color`,expected:`"${xa.DEFAULT_COLOR}"`}),!e.bounds&&!e.aim&&i.push({kind:"unplaced",path:t}),!e.bounds&&!e.angular&&i.push({kind:"unsized",path:t}),{kind:e.kind??"oval",bounds:{...xa.NEUTRAL_BOUNDS},color:xa.DEFAULT_COLOR,angle:0,transparency:0,haloScale:0,selected:!1}}static NEUTRAL_BOUNDS={x:Et.CANVAS_WIDTH_PX/2,y:Et.CANVAS_HEIGHT_PX/2,width:1,height:1}}class Vl{keyframes=[];order=[];groups=[];addKeyframe(e,t){const i=this.findInsertIndex(e);if(this.keyframes[i]?.t===e){const n=new Set(t.map(s=>s.sourceId));this.keyframes[i]={t:e,shapes:[...this.keyframes[i].shapes.filter(s=>!n.has(s.sourceId)),...t]}}else this.keyframes.splice(i,0,{t:e,shapes:[...t]});for(const n of t)this.order.includes(n.sourceId)||this.order.push(n.sourceId)}findInsertIndex(e){let t=0,i=this.keyframes.length;for(;t<i;){const n=t+i>>>1;this.keyframes[n].t<e?t=n+1:i=n}return t}getKeyframeAt(e){const t=this.findInsertIndex(e),i=this.keyframes[t];return i?.t===e?i:void 0}getShapeAt(e,t){return this.getKeyframeAt(e)?.shapes.find(i=>i.sourceId===t)?.shape}getLatestShapeAt(e,t){let i=this.findInsertIndex(e);for(this.keyframes[i]?.t!==e&&(i-=1);i>=0;i--){const n=this.keyframes[i].shapes.find(s=>s.sourceId===t);if(n)return n.shape}}getInterpolatedShapeAt(e,t){const i=this.findShapeAtOrBefore(e,t);if(i?.t===e)return i.shape;const n=this.findShapeAtOrAfter(e,t);return i?n?Ev(i.shape,n.shape,(e-i.t)/(n.t-i.t)):i.shape:n?.shape}findShapeAtOrBefore(e,t){let i=this.findInsertIndex(e);for(this.keyframes[i]?.t!==e&&(i-=1);i>=0;i--){const n=this.keyframes[i].shapes.find(s=>s.sourceId===t);if(n)return{t:this.keyframes[i].t,shape:n.shape}}}findShapeAtOrAfter(e,t){for(let i=this.findInsertIndex(e);i<this.keyframes.length;i++){const n=this.keyframes[i].shapes.find(s=>s.sourceId===t);if(n)return{t:this.keyframes[i].t,shape:n.shape}}}hitTest(e,t,i,n){const s=this.sourceIds;for(let a=s.length-1;a>=0;a--){if(n?.has(s[a]))continue;const o=this.getInterpolatedShapeAt(e,s[a]);if(o&&_v(o,t,i))return{sourceId:s[a],shape:o}}}removeSource(e){for(let t=this.keyframes.length-1;t>=0;t--){const i=this.keyframes[t].shapes.filter(n=>n.sourceId!==e);i.length===0?this.keyframes.splice(t,1):i.length!==this.keyframes[t].shapes.length&&(this.keyframes[t]={t:this.keyframes[t].t,shapes:i})}this.order=this.order.filter(t=>t!==e),this.removeFromGroup(e)}group(e){if(!(e.length<2)){for(const t of e)this.removeFromGroup(t);this.groups.push([...e])}}ungroup(e){const t=this.groups.findIndex(i=>i.includes(e));t!==-1&&this.groups.splice(t,1)}groupMembers(e){return this.groups.find(t=>t.includes(e))}removeFromGroup(e){const t=this.groups.findIndex(n=>n.includes(e));if(t===-1)return;const i=this.groups[t].filter(n=>n!==e);i.length<2?this.groups.splice(t,1):this.groups[t]=i}bringToFront(e){const t=this.order.indexOf(e);t!==-1&&(this.order.splice(t,1),this.order.push(e))}sendToBack(e){const t=this.order.indexOf(e);t!==-1&&(this.order.splice(t,1),this.order.unshift(e))}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(e,t){const i=new Vl;for(const n of xa.complete(e.keyframes??[],t))i.addKeyframe(n.t,n.shapes);if(e.order){const n=i.order.filter(s=>!e.order.includes(s));i.order=[...e.order,...n]}return e.groups&&(i.groups=e.groups.map(n=>n.filter(s=>i.order.includes(s))).filter(n=>n.length>=2)),i}}function Av(r,e,t){return Math.max(e,Math.min(t,r))}function Tv(r,e,t){const i=((e-r)%360+540)%360-180;return((r+i*t)%360+360)%360}function Wa(r,e,t){return r+(e-r)*t}function Rv(r,e,t){return{lat:r.lat===void 0||e.lat===void 0?void 0:Wa(r.lat,e.lat,t),lng:r.lng===void 0||e.lng===void 0?void 0:Wa(r.lng,e.lng,t),elevationM:Wa(r.elevationM,e.elevationM,t),headingDeg:r.headingDeg===void 0||e.headingDeg===void 0?void 0:Tv(r.headingDeg,e.headingDeg,t),pitchDeg:Wa(r.pitchDeg,e.pitchDeg,t),rollDeg:Wa(r.rollDeg??0,e.rollDeg??0,t),fovDeg:Wa(r.fovDeg,e.fovDeg,t),fNumber:r.fNumber,focusDistanceM:r.focusDistanceM}}class Pa{static at(e,t,i,n,s){const a=e[i],c=e[i+1]-a;if(c<=0)return t[i];const l=Pa.tangent(e,t,i,s),h=Pa.tangent(e,t,i+1,s),u=(n-a)/c,d=u*u,f=d*u;return(2*f-3*d+1)*t[i]+(f-2*d+u)*c*l+(-2*f+3*d)*t[i+1]+(f-d)*c*h}static BRAKE_S=.8;static paced(e,t,i,n){if(!i&&!n)return e;const s=t>0?Math.min(.5,Pa.BRAKE_S/t):.5;if(i&&n){const o=1/(1-s);return e<=s?o*e*e/(2*s):e>=1-s?1-o*(1-e)*(1-e)/(2*s):o*(e-s/2)}const a=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?a(e):1-a(1-e)}static tangent(e,t,i,n){const s=e.length-1,a=f=>(t[f+1]-t[f])/(e[f+1]-e[f]||1);if(i===0)return n?0:a(0);if(i===s)return n?0:a(s-1);const o=a(i-1),c=a(i);if(o*c<=0)return 0;const l=e[i]-e[i-1],h=e[i+1]-e[i],u=2*h+l,d=h+2*l;return(u+d)/(u/o+d/c)}}class No{keyframes=[];addKeyframe(e,t){const i=this.findInsertIndex(e);this.keyframes[i]?.t===e?this.keyframes[i]={t:e,pose:t}:this.keyframes.splice(i,0,{t:e,pose:t})}clear(){this.keyframes.length=0}removeKeyframeAt(e){const t=this.findInsertIndex(e);this.keyframes[t]?.t===e&&this.keyframes.splice(t,1)}findInsertIndex(e){let t=0,i=this.keyframes.length;for(;t<i;){const n=t+i>>>1;this.keyframes[n].t<e?t=n+1:i=n}return t}getLatestPoseAt(e){let t=this.findInsertIndex(e);return this.keyframes[t]?.t!==e&&(t-=1),t>=0?this.keyframes[t].pose:void 0}getInterpolatedPoseAt(e){const t=this.findInsertIndex(e),i=this.keyframes[t]?.t===e?this.keyframes[t]:this.keyframes[t-1];if(i?.t===e)return i.pose;const n=this.keyframes[t]?.t===e?void 0:this.keyframes[t];if(!i)return n?.pose;if(!n)return i.pose;const s=Rv(i.pose,n.pose,Av((e-i.t)/(n.t-i.t),0,1));return this.humanly(t-1,e,s)}humanly(e,t,i){const n=Math.max(0,e-1),s=Math.min(this.keyframes.length-1,e+2),a=this.keyframes.slice(n,s+1),o=e-n,c=a.map(b=>b.t),l=(b,M)=>{const S=a.map(w=>b(w.pose));if(!S.some(w=>w===void 0))return Pa.at(c,S,o,t,M)},h=a.map(b=>b.pose.headingDeg);let u;if(h.every(b=>b!==void 0)){const b=[h[0]];for(let M=1;M<h.length;M++)b.push(b[M-1]+((h[M]-h[M-1])%360+540)%360-180);u=(Pa.at(c,b,o,t,!0)%360+360)%360}const d=this.keyframes[e],f=this.keyframes[e+1],p=(b,M)=>b.lat===M.lat&&b.lng===M.lng&&b.elevationM===M.elevationM,v=!p(d.pose,f.pose),m=v&&e>0&&p(this.keyframes[e-1].pose,d.pose),g=v&&e+2<this.keyframes.length&&p(f.pose,this.keyframes[e+2].pose);let _;if(m||g){const b=Pa.paced((t-d.t)/(f.t-d.t),(f.t-d.t)/1e3,m,g),M=(S,w)=>S===void 0||w===void 0?void 0:S+(w-S)*b;_={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:_?_.lat:l(b=>b.lat,!1)??i.lat,lng:_?_.lng:l(b=>b.lng,!1)??i.lng,elevationM:_?_.elevationM:l(b=>b.elevationM,!1)??i.elevationM,headingDeg:u??i.headingDeg,pitchDeg:l(b=>b.pitchDeg,!0)??i.pitchDeg,rollDeg:l(b=>b.rollDeg??0,!0)??i.rollDeg,fovDeg:l(b=>b.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(e){const t=new No;for(const i of e.keyframes)t.addKeyframe(i.t,i.pose);return t}}class qs{static MAX_CHANGE_PER_S=.05;points;followed;constructor(e){let t="none",i=0;this.points=e.map(({t:n,weather:s})=>(s.precipitationType!=="none"&&(t=s.precipitationType,i=s.precipitationIntensity),{t:n,lastFalling:t,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],a=this.points[n];this.followed.push(qs.follow(this.followed[n-1],s.intensity,a.intensity,(a.t-s.t)/1e3,(a.t-s.t)/1e3))}}at(e){if(this.points.length===0||e<this.points[0].t)return;let t=this.points.length-1;for(;t>0&&this.points[t].t>e;)t--;const i=this.points[t],n=this.points[t+1],s=n?qs.follow(this.followed[t],i.intensity,n.intensity,(n.t-i.t)/1e3,(e-i.t)/1e3):qs.follow(this.followed[t],i.intensity,i.intensity,1,(e-i.t)/1e3);return{type:qs.typeBetween(i,n,e,s),intensity:s,character:qs.characterBetween(i,n,e)}}static characterBetween(e,t,i){return e.type==="none"?t&&t.type!=="none"?t.intensity:e.lastFallingIntensity:!t||t.type==="none"?e.intensity:e.intensity+(t.intensity-e.intensity)*(i-e.t)/(t.t-e.t||1)}static typeBetween(e,t,i,n){return e.type==="none"?t&&t.type!=="none"&&i>e.t?t.type:n>0?e.lastFalling:"none":t&&t.type==="none"&&n<=0?"none":e.type}static follow(e,t,i,n,s){const a=qs.MAX_CHANGE_PER_S,o=n>0?(i-t)/n:0,c=u=>t+o*Math.min(Math.max(u,0),n);let l=e,h=0;for(let u=0;u<8&&h<s;u++){const d=c(h)-l;if(Math.abs(d)<1e-9){const b=h<n?o:0;if(Math.abs(b)<=a){const S=h<n?Math.min(s,n):s;l=c(S),h=S;continue}const M=Math.min(s,n);l+=Math.sign(b)*a*(M-h),h=M;continue}const f=Math.sign(d),p=h<n?o:0,v=a-f*p,m=v>0?h+Math.abs(d)/v:1/0,g=h<n?n:1/0,_=Math.min(s,m,g);l+=f*a*(_-h),h=_,_===m&&(l=c(h))}return Math.min(1,Math.max(0,l))}}const s0=1e3,Dv=.65,a0={cloudCover:0,cloudDarkness:0,precipitationType:"none",precipitationIntensity:0,windDirectionDeg:0,windSpeed:0,storm:!1};function gl(r){if(r.cloudLayers!==void 0)return r.cloudLayers;const e=[],t=r.lowerCloudCover??r.cloudCover;return t>0&&e.push({id:"lower",type:"cumulus",baseM:r.cloudBaseM??s0,thicknessM:650,coverage:t,sizeM:1400,density:1,darkness:r.cloudDarkness}),(r.highCloudCover??0)>0&&e.push({id:"cirrus",type:"cirrus",baseM:8e3,thicknessM:400,coverage:r.highCloudCover,sizeM:2200,density:.35,darkness:r.cloudDarkness,iceCrystalAlignment:r.iceCrystalAlignment}),e}function Ft(r,e,t){return r+(e-r)*t}function r0(r,e,t){const i=((e-r)%360+540)%360-180;return((r+i*t)%360+360)%360}function Iv(r,e,t){return Math.max(e,Math.min(t,r))}function Cv(r=[],e=[],t){if(!(!r.length&&!e.length))return[...new Set([...r.map(i=>i.id),...e.map(i=>i.id)])].map(i=>{const n=r.find(c=>c.id===i),s=e.find(c=>c.id===i),a=n??{...s,density:0},o=s??{...n,density:0};return{...a,eastM:Ft(a.eastM,o.eastM,t),northM:Ft(a.northM,o.northM,t),baseM:Ft(a.baseM,o.baseM,t),thicknessM:Ft(a.thicknessM,o.thicknessM,t),widthM:Ft(a.widthM,o.widthM,t),depthM:Ft(a.depthM,o.depthM,t),rotationDeg:r0(a.rotationDeg,o.rotationDeg,t),density:Ft(a.density,o.density,t),darkness:Ft(a.darkness??0,o.darkness??0,t)}})}function Pv(r,e,t){if(r.cloudLayers===void 0&&e.cloudLayers===void 0)return;const i=gl(r),n=gl(e);return t>=1?n.map(a=>({...a})):[...new Set([...i.map(a=>a.id),...n.map(a=>a.id)])].map(a=>{const o=i.find(u=>u.id===a),c=n.find(u=>u.id===a),l=o??{...c,coverage:0},h=c??{...o,coverage:0};return{...l,instances:Cv(o?.instances,c?.instances,t),baseM:Ft(l.baseM,h.baseM,t),thicknessM:Ft(l.thicknessM,h.thicknessM,t),coverage:Ft(l.coverage,h.coverage,t),sizeM:Ft(l.sizeM,h.sizeM,t),density:Ft(l.density,h.density,t),darkness:Ft(l.darkness??r.cloudDarkness,h.darkness??e.cloudDarkness,t),iceCrystalAlignment:l.iceCrystalAlignment===void 0||h.iceCrystalAlignment===void 0?void 0:Ft(l.iceCrystalAlignment,h.iceCrystalAlignment,t),windSpeed:l.windSpeed===void 0&&h.windSpeed===void 0?void 0:Ft(l.windSpeed??r.windSpeed,h.windSpeed??e.windSpeed,t),windDirectionDeg:l.windDirectionDeg===void 0&&h.windDirectionDeg===void 0?void 0:r0(l.windDirectionDeg??r.windDirectionDeg,h.windDirectionDeg??e.windDirectionDeg,t)}})}function Lv(r,e,t){return{cloudLayers:Pv(r,e,t),cloudCover:Ft(r.cloudCover,e.cloudCover,t),cloudDarkness:Ft(r.cloudDarkness,e.cloudDarkness,t),highCloudCover:r.highCloudCover===void 0||e.highCloudCover===void 0?void 0:Ft(r.highCloudCover,e.highCloudCover,t),iceCrystalAlignment:r.iceCrystalAlignment===void 0||e.iceCrystalAlignment===void 0?void 0:Ft(r.iceCrystalAlignment,e.iceCrystalAlignment,t),lowerCloudCover:r.lowerCloudCover===void 0||e.lowerCloudCover===void 0?void 0:Ft(r.lowerCloudCover,e.lowerCloudCover,t),cloudBaseM:r.cloudBaseM===void 0||e.cloudBaseM===void 0?void 0:Ft(r.cloudBaseM,e.cloudBaseM,t),relativeHumidity:r.relativeHumidity===void 0||e.relativeHumidity===void 0?void 0:Ft(r.relativeHumidity,e.relativeHumidity,t),precipitationType:t<1?r.precipitationType:e.precipitationType,precipitationIntensity:Ft(r.precipitationIntensity,e.precipitationIntensity,t),windDirectionDeg:r0(r.windDirectionDeg,e.windDirectionDeg,t),windSpeed:Ft(r.windSpeed,e.windSpeed,t),storm:t<1?r.storm:e.storm}}class Fo{keyframes=[];ramp;addKeyframe(e,t){this.ramp=void 0;const i=this.findInsertIndex(e);this.keyframes[i]?.t===e?this.keyframes[i]={t:e,weather:t}:this.keyframes.splice(i,0,{t:e,weather:t})}clear(){this.ramp=void 0,this.keyframes.length=0}removeKeyframeAt(e){this.ramp=void 0;const t=this.findInsertIndex(e);this.keyframes[t]?.t===e&&this.keyframes.splice(t,1)}findInsertIndex(e){let t=0,i=this.keyframes.length;for(;t<i;){const n=t+i>>>1;this.keyframes[n].t<e?t=n+1:i=n}return t}getLatestWeatherAt(e){let t=this.findInsertIndex(e);return this.keyframes[t]?.t!==e&&(t-=1),t>=0?this.keyframes[t].weather:void 0}getInterpolatedWeatherAt(e){const t=this.findInsertIndex(e),i=this.keyframes[t]?.t===e?this.keyframes[t]:this.keyframes[t-1];if(i?.t===e)return i.weather;const n=this.keyframes[t]?.t===e?void 0:this.keyframes[t];return i?n?Lv(i.weather,n.weather,Iv((e-i.t)/(n.t-i.t),0,1)):i.weather:n?.weather}getActualWeatherAt(e){const t=this.getInterpolatedWeatherAt(e);if(!t)return;const i=(this.ramp??=new qs(this.keyframes)).at(e);if(!i)return t;const{type:n,intensity:s,character:a}=i,o=a>0?Math.min(1,s/a):n==="none"?0:1;return{...t,precipitationType:n,precipitationIntensity:a,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(e){const t=new Fo;for(const i of e.keyframes)t.addKeyframe(i.t,i.weather);return t}}class Uo{keyframes=[];addKeyframe(e,t){const i=this.findInsertIndex(e);this.keyframes[i]?.t===e?this.keyframes[i]={t:e,sound:t}:this.keyframes.splice(i,0,{t:e,sound:t})}clear(){this.keyframes.length=0}removeKeyframeAt(e){const t=this.findInsertIndex(e);this.keyframes[t]?.t===e&&this.keyframes.splice(t,1)}getLatestSoundAt(e){let t=this.findInsertIndex(e);return this.keyframes[t]?.t!==e&&(t-=1),t>=0?this.keyframes[t].sound:void 0}getInterpolatedSoundAt(e){const t=this.findInsertIndex(e),i=this.keyframes[t]?.t===e?this.keyframes[t]:this.keyframes[t-1];if(i?.t===e)return i.sound;const n=this.keyframes[t]?.t===e?void 0:this.keyframes[t];if(!i)return n?.sound;if(!n)return i.sound;const s=(e-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(e){const t=new Uo;for(const i of e.keyframes)t.addKeyframe(i.t,i.sound);return t}lerp(e,t,i){return{kind:i<1?e.kind:t.kind,volume:e.volume+(t.volume-e.volume)*i,pitchHz:e.pitchHz+(t.pitchHz-e.pitchHz)*i,src:i<1?e.src:t.src}}findInsertIndex(e){let t=0,i=this.keyframes.length;for(;t<i;){const n=t+i>>>1;this.keyframes[n].t<e?t=n+1:i=n}return t}}const Ov=100,Nv={kind:"none",volume:0,pitchHz:Ov},ic=[{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:"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 si{static get default(){return ic[0]}static byId(e){return ic.find(t=>t.id===e)??this.default}static UNAIDED_FIELD_DEG=60;static UNAIDED_ASPECT=16/9;static fieldOfViewDeg(e){const t=e.frame;return t?2*Math.atan(t.heightMm/(2*t.focalLengthMm))*180/Math.PI:si.UNAIDED_FIELD_DEG}static aspectOf(e){const t=e.frame;return t?t.widthMm/t.heightMm:si.UNAIDED_ASPECT}static frameWidthPx(e,t){return Math.round(t*si.aspectOf(e))}static availableAt(e){return e===void 0?ic:ic.filter(t=>!t.years||e>=t.years.from&&(t.years.to===void 0||e<=t.years.to))}static fieldOfViewDegAt(e,t){const i=e.frame;if(!(!i||t<=0))return 2*Math.atan(i.heightMm/(2*t))*180/Math.PI}static focalLengthMmFor(e,t){const i=e.frame;if(!(!i||t<=0||t>=180))return i.heightMm/(2*Math.tan(t*Math.PI/360))}static bladesShowing(e,t){const i=t??e.fNumber;if(i===void 0||e.apertureBlades===void 0)return 0;const n=e.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(e){return e.flare??si.LENS_FLARE_ARTIFACTS}static starPointsOf(e){const t=e.apertureBlades;return t===void 0||t<3?0:t%2===0?t:t*2}}function cf(r){if(r.raw!==void 0)return r.raw;if(r.year===void 0){if(r.hour===void 0)return"";let t=`${String(r.hour).padStart(2,"0")}:${String(r.minute??0).padStart(2,"0")}`;return r.second!==void 0&&(t+=`:${String(r.second).padStart(2,"0")}`),t}let e=String(r.year).padStart(4,"0");return r.month===void 0||(e+=`-${String(r.month).padStart(2,"0")}`,r.day===void 0)||(e+=`-${String(r.day).padStart(2,"0")}`,r.hour===void 0)||(e+=`T${String(r.hour).padStart(2,"0")}:${String(r.minute??0).padStart(2,"0")}`,r.second!==void 0&&(e+=`:${String(r.second).padStart(2,"0")}`)),e}function Cu(r){if(r.year!==void 0)return Date.UTC(r.year,(r.month??1)-1,r.day??1,r.hour??0,r.minute??0,r.second??0)}function lf(r){return(((r.day??0)*24+(r.hour??0))*60+(r.minute??0))*6e4+(r.second??0)*1e3}const Fv=["year","month","day","hour","minute"],Uv=["day","hour","minute"];function hf(r,e){return e.filter(t=>r[t]!==void 0).join(",")}function xg(r){if(r.durationSeconds!==void 0)return r.durationSeconds*1e3;if(!r.time||!r.endTime)return;const e=r.time.year!==void 0&&r.endTime.year!==void 0,t=e?Fv:Uv,i=hf(r.time,t);if(!(i===""||i!==hf(r.endTime,t)))return e?Cu(r.endTime)-Cu(r.time):lf(r.endTime)-lf(r.time)}class Wl{constructor(e,t,i,n,s,a,o,c,l=[],h,u,d,f=[],p=[],v=[]){this.event=e,this.timeline=t,this.observerTrack=i,this.weatherTrack=n,this.soundTrack=s,this.observer=a,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}provenance=Zi.empty();loadIssues=[];account;sources;interpretation;sway;lightPollution;iso;vehicle;get observerCount(){return 1+this.decor.filter(e=>e.kind==="observer").length}get exposure(){return this.exposureSeconds??this.instrument.exposureSeconds}get instrument(){return si.byId(this.instrumentId)}static create(e,t,i){return new Wl({eventType:"sighting",time:e,place:t},new Vl,new No,new Fo,new Uo,i)}}const kv=0,zv=0;function jt(r,e){const t=r.observerTrack.getInterpolatedPoseAt(e);if(t)return t;const i=r.event.place?.[0];if(i)return{lat:i.lat,lng:i.lng,elevationM:kv,headingDeg:void 0,pitchDeg:zv,fovDeg:si.fieldOfViewDeg(r.instrument)}}function mr(r,e){return r.weatherTrack.getInterpolatedWeatherAt(e)??r.weather??a0}function uf(r,e){return r.weatherTrack.getActualWeatherAt(e)??r.weather??a0}function yg(r,e){return r.soundTrack.getInterpolatedSoundAt(e)??Nv}const df=2;function bg(r){return r==="building"||r==="vehicle"}function _g(r,e){const t=r.litKeyframes;if(!t||t.length===0)return r.lit??!1;let i=t[0];for(const n of t){if(n.t>e)break;i=n}return i.lit}function Bv(r,e){return r.pattern.kind==="steady"?!0:Sg(r,e,e+1)>.5}function Sg(r,e,t){if(r.pattern.kind==="steady")return 1;const{perMinute:i,dutyCycle:n,phase:s=0}=r.pattern,a=Math.min(Math.max(n,0),1);if(a===0||i<=0)return 0;const o=6e4/i,c=e/o+s,l=t/o+s;if(l<=c)return Math.min(Math.max(c-Math.floor(c),0),a)<a?1:0;const h=u=>Math.floor(u)*a+Math.min(u-Math.floor(u),a);return(h(l)-h(c))/(l-c)}function Or(r,e){const t=r.track,i={eastM:r.eastM,northM:r.northM,altitudeM:0,headingDeg:r.headingDeg};if(!t||t.length===0)return i;if(t.length===1||e<=t[0].t)return ff(t[0],r);const n=t[t.length-1];if(e>=n.t)return ff(n,r);for(let s=0;s<t.length-1;s++){const a=t[s],o=t[s+1];if(e<a.t||e>o.t)continue;const c=o.t-a.t,l=c===0?0:(e-a.t)/c;return{eastM:a.eastM+(o.eastM-a.eastM)*l,northM:a.northM+(o.northM-a.northM)*l,altitudeM:(a.altitudeM??0)+((o.altitudeM??0)-(a.altitudeM??0))*l,headingDeg:a.headingDeg??r.headingDeg}}return i}function ff(r,e){return{eastM:r.eastM,northM:r.northM,altitudeM:r.altitudeM??0,headingDeg:r.headingDeg??e.headingDeg}}const pf="#ff2200",mf="#00ff44",ha="#ffffff",nc="#ffa500",Xa="#ff0000",Hv="#2244ff",Gv=[{id:"airliner",name:"Airliner",kinds:["aircraft"],create:()=>[{id:"nav-port",offsetM:{x:-17,y:0,z:0},color:pf,pattern:{kind:"steady"}},{id:"nav-starboard",offsetM:{x:17,y:0,z:0},color:mf,pattern:{kind:"steady"}},{id:"nav-tail",offsetM:{x:0,y:1,z:-18},color:ha,pattern:{kind:"steady"}},{id:"beacon-top",offsetM:{x:0,y:2,z:0},color:Xa,intensity:1.5,pattern:{kind:"flash",perMinute:45,dutyCycle:.18}},{id:"beacon-bottom",offsetM:{x:0,y:-2,z:0},color:Xa,intensity:1.5,pattern:{kind:"flash",perMinute:45,dutyCycle:.18}},{id:"strobe-port",offsetM:{x:-17,y:0,z:-1},color:ha,intensity:20,pattern:{kind:"flash",perMinute:60,dutyCycle:.01}},{id:"strobe-starboard",offsetM:{x:17,y:0,z:-1},color:ha,intensity:20,pattern:{kind:"flash",perMinute:60,dutyCycle:.01,phase:.08}}]},{id:"helicopter",name:"Helicopter",kinds:["aircraft"],create:()=>[{id:"nav-port",offsetM:{x:-5,y:0,z:0},color:pf,pattern:{kind:"steady"}},{id:"nav-starboard",offsetM:{x:5,y:0,z:0},color:mf,pattern:{kind:"steady"}},{id:"nav-tail",offsetM:{x:0,y:1,z:-7},color:ha,pattern:{kind:"steady"}},{id:"beacon",offsetM:{x:0,y:2,z:-2},color:Xa,intensity:1.5,pattern:{kind:"flash",perMinute:45,dutyCycle:.2}},{id:"strobe",offsetM:{x:0,y:-1,z:0},color:ha,intensity:15,pattern:{kind:"flash",perMinute:75,dutyCycle:.015}}]},{id:"car-headlights",name:"Car, headlights on",kinds:["vehicle"],create:()=>[{id:"head-left",offsetM:{x:-.7,y:.6,z:2},color:ha,intensity:2,pattern:{kind:"steady"}},{id:"head-right",offsetM:{x:.7,y:.6,z:2},color:ha,intensity:2,pattern:{kind:"steady"}},{id:"tail-left",offsetM:{x:-.7,y:.6,z:-2},color:Xa,pattern:{kind:"steady"}},{id:"tail-right",offsetM:{x:.7,y:.6,z:-2},color:Xa,pattern:{kind:"steady"}}]},{id:"car-hazards",name:"Car, hazard flashers",kinds:["vehicle"],create:()=>[{id:"hazard-front-left",offsetM:{x:-.8,y:.6,z:2},color:nc,pattern:{kind:"flash",perMinute:90,dutyCycle:.5}},{id:"hazard-front-right",offsetM:{x:.8,y:.6,z:2},color:nc,pattern:{kind:"flash",perMinute:90,dutyCycle:.5}},{id:"hazard-rear-left",offsetM:{x:-.8,y:.6,z:-2},color:nc,pattern:{kind:"flash",perMinute:90,dutyCycle:.5}},{id:"hazard-rear-right",offsetM:{x:.8,y:.6,z:-2},color:nc,pattern:{kind:"flash",perMinute:90,dutyCycle:.5}}]},{id:"emergency-beacons",name:"Emergency vehicle beacons",kinds:["vehicle"],create:()=>[{id:"beacon-blue",offsetM:{x:-.4,y:1.6,z:0},color:Hv,intensity:2.5,pattern:{kind:"flash",perMinute:120,dutyCycle:.1}},{id:"beacon-red",offsetM:{x:.4,y:1.6,z:0},color:Xa,intensity:2.5,pattern:{kind:"flash",perMinute:120,dutyCycle:.1,phase:.5}}]},{id:"streetlamp",name:"Streetlamp",kinds:["streetlight"],create:()=>[{id:"lamp",offsetM:{x:0,y:5,z:0},color:"#ffd9a0",intensity:2,pattern:{kind:"steady"}}]}];class sl{constructor(e){this.names=e}name(e){return this.names[e.toLowerCase()]??e}stored(e){const t=e.trim().toLowerCase();for(const[i,n]of Object.entries(this.names))if(n.toLowerCase()===t)return i;return e.trim()}}class gf{constructor(e,t,i,n=new sl({})){this.labels=e,this.naming=t,this.said=i,this.tags=n}entriesFor(e,t,i={}){const n=[];return this.addObservation(n,e),this.addObserver(n,e,t),this.addLocation(n,e,t,i.groundElevationM),this.addDecor(n,e,t,i),this.addTemporal(n,e),this.addWeather(n,e,t),this.addSound(n,e,t),n}push(e,t,i,n,s,a="",o={}){s===void 0||s===""||e.push({group:t,field:i,label:n,value:String(s),unit:a,color:o.color,fromSource:o.fromSource===!0})}percent(e){return e===void 0?void 0:`${Math.round(e*100)} %`}rounded(e,t=0){return e===void 0?void 0:String(Number(e.toFixed(t)))}shows(e,t=0){return e!==void 0&&Number(e.toFixed(t))!==0}showsPercent(e){return this.shows(e===void 0?void 0:e*100)}percentShown(e){return this.showsPercent(e)?this.percent(e):void 0}roundedShown(e,t=0){return this.shows(e,t)?this.rounded(e,t):void 0}addObservation(e,t){const i=t.event.tags;this.push(e,"observation","tags",this.labels.tags,i&&i.length>0?i.map(n=>this.tags.name(n)).join(", "):void 0)}addObserver(e,t,i){const n=t.observer;this.push(e,"observer","observerId",this.labels.observerId,n?.id),this.push(e,"observer","observerTitle",this.labels.observerTitle,n?.title),this.push(e,"observer","observerLastName",this.labels.observerLastName,n?.lastName);const s=n?.firstNames;this.push(e,"observer","observerFirstNames",this.labels.observerFirstNames,s&&s.length>0?s.join(", "):void 0);const a=t.instrument;this.push(e,"observer","instrument",this.labels.instrument,this.naming.instrument(a));const o=t.exposure;this.push(e,"observer","exposureSeconds",this.labels.exposure,o===void 0?void 0:o<1?`1/${Math.round(1/o)}`:this.rounded(o,2),"s");const c=jt(t,i);if(c){const l=si.focalLengthMmFor(a,c.fovDeg);l===void 0?this.push(e,"observer","focalLength",this.labels.fieldOfView,this.rounded(c.fovDeg,1),"°"):this.push(e,"observer","focalLength",this.labels.focalLength,this.rounded(l,1),"mm"),this.push(e,"observer","fNumber",this.labels.aperture,this.rounded(c.fNumber??a.fNumber,1)),this.push(e,"observer","focusDistance",this.labels.focusDistance,this.rounded(c.focusDistanceM,1),"m"),this.push(e,"observer","roll",this.labels.roll,this.roundedShown(c.rollDeg),"°")}}addLocation(e,t,i,n){const s=t.event.place?.[0];this.push(e,"location","placeName",this.labels.placeName,s?.name);const a=jt(t,i);if(!a)return;this.push(e,"location","lat",this.labels.latitude,this.rounded(a.lat,6)),this.push(e,"location","lng",this.labels.longitude,this.rounded(a.lng,6));const o=this.rounded(a.headingDeg);this.push(e,"location","heading",this.labels.heading,o,a.headingDeg===void 0?"°":`° (${this.naming.point(a.headingDeg)})`),this.push(e,"location","pitch",this.labels.pitch,this.rounded(a.pitchDeg),"°"),n===void 0?this.push(e,"location","elevation",this.labels.heightAboveGround,this.roundedShown(a.elevationM),"m"):this.push(e,"location","elevation",this.labels.elevation,this.rounded(n+a.elevationM),"m")}addDecor(e,t,i,n){const s=t.decor.find(l=>l.id===n.decorId);if(!s){if(n.decorPicker===!0)for(const l of t.decor)this.push(e,"decor",`decor:${l.id}`,this.decorLabel(l),this.decorKindName(l.kind));return}this.push(e,"decor","decorTitle",this.labels.decorTitle,this.said.read(s.title));const a=Or(s,i);this.push(e,"decor","decorEast",this.labels.decorEast,this.rounded(a.eastM,1),"m"),this.push(e,"decor","decorNorth",this.labels.decorNorth,this.rounded(a.northM,1),"m"),this.push(e,"decor","decorAltitude",this.labels.decorAltitude,this.roundedShown(a.altitudeM),"m"),this.push(e,"decor","decorHeading",this.labels.decorHeading,this.rounded(a.headingDeg),"°"),_g(s,i)&&this.push(e,"decor","decorLit",this.labels.decorLit,"✓");const o=s.lights?.map(l=>l.id).join()??"",c=o===""?void 0:Gv.find(l=>l.create().map(h=>h.id).join()===o);this.push(e,"decor","decorLightRig",this.labels.decorLights,c?.name),this.push(e,"decor","decorFloors",this.labels.decorFloors,s.floors),this.push(e,"decor","decorOccupiedFloor",this.labels.decorOccupiedFloor,s.occupiedFloor),this.push(e,"decor","decorObserverSide",this.labels.decorObserverSide,this.decorSideName(s.observerSide));for(const[l,h]of Object.entries(s.windows??{}))this.push(e,"decor",`decorWindow${this.capitalise(l)}`,`${this.labels.decorWindows} ${this.decorSideName(l)}`,h,"%")}addTemporal(e,t){const i=t.event;this.push(e,"temporal","obs-time",this.labels.observationTime,i.time&&cf(i.time)),this.push(e,"temporal","obs-end-time",this.labels.observationEndTime,i.endTime&&cf(i.endTime));const n=xg(i);this.push(e,"temporal","durationSeconds",this.labels.duration,this.roundedShown(n&&n/1e3,1),"s"),this.push(e,"temporal","timeZone",this.labels.utcOffset,i.timeZone),this.push(e,"temporal","utcOffsetHours",this.labels.utcOffset,this.rounded(i.utcOffsetHours,1),"UTC±h")}addWeather(e,t,i){const n=mr(t,i),a={fromSource:t.weatherSource!==void 0},o=this.showsPercent(n.cloudCover)||this.showsPercent(n.lowerCloudCover)||this.showsPercent(n.highCloudCover);this.push(e,"weather","cloudCover",this.labels.cloudCover,this.percentShown(n.cloudCover),"",a),this.push(e,"weather","highCloudCover",this.labels.highCloudCover,this.percentShown(n.highCloudCover),"",a),this.push(e,"weather","iceCrystalAlignment",this.labels.iceCrystalAlignment,this.showsPercent(n.highCloudCover)?this.percent(n.iceCrystalAlignment):void 0),this.push(e,"weather","cloudDarkness",this.labels.cloudDarkness,o?this.percent(n.cloudDarkness):void 0,"",a),this.push(e,"weather","cloudBase",this.labels.cloudBase,o?this.rounded(n.cloudBaseM):void 0,"m",a);const c=n.precipitationType!=="none"&&this.showsPercent(n.precipitationIntensity);this.push(e,"weather","precipitationType",this.labels.precipitationType,c?this.precipitationName(n.precipitationType):void 0,"",a),this.push(e,"weather","precipitationIntensity",this.labels.precipitationIntensity,c?this.percent(n.precipitationIntensity):void 0,"",a),this.push(e,"weather","windDirection",this.labels.windDirection,this.shows(n.windSpeed,2)?this.rounded(n.windDirectionDeg):void 0,"°",a),this.push(e,"weather","windSpeed",this.labels.windSpeed,this.roundedShown(n.windSpeed,2),"m/s",a),n.storm&&this.push(e,"weather","storm",this.labels.storm,"✓","",a)}addSound(e,t,i){const n=yg(t,i);n.kind!=="none"&&(this.push(e,"sound","soundKind",this.labels.soundKind,this.soundKindName(n.kind)),this.push(e,"sound","soundVolume",this.labels.soundVolume,this.percentShown(n.volume)),this.push(e,"sound","soundPitch",this.labels.soundPitch,this.roundedShown(n.pitchHz),"Hz"),this.push(e,"sound","soundSrc",this.labels.soundSrc,n.src))}decorLabel(e){return this.said.read(e.title)??this.decorKindName(e.kind)}decorKindName(e){switch(e){case"building":return this.labels.decorBuilding;case"tree":return this.labels.decorTree;case"shrub":return this.labels.decorShrub;case"bridge":return this.labels.decorBridge;case"crop":return this.labels.decorCrop;case"mound":return this.labels.decorMound;case"streetlight":return this.labels.decorStreetlight;case"vehicle":return this.labels.decorVehicle;case"aircraft":return this.labels.decorAircraft;default:return this.labels.decorObserver}}decorSideName(e){switch(e){case"front":return this.labels.decorSideFront;case"behind":return this.labels.decorSideBehind;case"left":return this.labels.decorSideLeft;case"right":return this.labels.decorSideRight;case"front-left":return this.labels.decorSideFrontLeft;case"front-right":return this.labels.decorSideFrontRight;case"behind-left":return this.labels.decorSideBehindLeft;case"behind-right":return this.labels.decorSideBehindRight;default:return}}precipitationName(e){switch(e){case"rain":return this.labels.precipitationRain;case"snow":return this.labels.precipitationSnow;case"hail":return this.labels.precipitationHail;default:return this.labels.precipitationNone}}soundKindName(e){switch(e){case"hum":return this.labels.soundHum;case"whistle":return this.labels.soundWhistle;case"rumble":return this.labels.soundRumble;case"crackle":return this.labels.soundCrackle;default:return this.labels.soundNone}}capitalise(e){return e.replace(/(^|-)([a-z])/g,(t,i,n)=>n.toUpperCase())}}const Vv="“Thunder” by Jerimee",Wv="https://creativecommons.org/licenses/by/3.0/",Xv="CC BY 3.0";class Dn{static fill(e,t){e.innerHTML="";const i=l=>e.appendChild(l),n=t.currentTerrainAttribution;n&&i(Dn.text(n));const s=t.currentRoadAttribution;s&&i(Dn.text(s));const a=t.ufoElement.observerMapCredit;a&&!n?.includes(a)&&i(Dn.text(a));for(const l of t.decorModelCredits){const h=l.author?` — ${l.author}`:"",u=document.createElement("li");l.sourceUrl?u.append(Dn.link(l.sourceUrl,l.title),document.createTextNode(`${h} (${l.license})`)):u.textContent=`${l.title}${h} (${l.license})`,i(u)}for(const l of t.ufoElement.sighting.references){if(!l.credit)continue;const h=document.createElement("li");l.creditUrl?h.appendChild(Dn.link(l.creditUrl,l.credit)):h.textContent=l.credit,i(h)}const o=t.satelliteState;if(o.status==="ready"&&o.credit){const l=document.createElement("li");l.appendChild(Dn.link(o.creditUrl??"",o.credit)),i(l)}const c=Dn.text(`${Vv} (`);c.append(Dn.link(Wv,Xv),document.createTextNode(")")),i(c)}static text(e){const t=document.createElement("li");return t.textContent=e,t}static link(e,t){const i=document.createElement("a");return i.href=e,i.target="_blank",i.rel="noopener",i.textContent=t,i}}const Yv="modulepreload",qv=function(r,e){return new URL(r,e).href},vf={},pi=function(e,t,i){let n=Promise.resolve();if(t&&t.length>0){let a=function(h){return Promise.all(h.map(u=>Promise.resolve(u).then(d=>({status:"fulfilled",value:d}),d=>({status:"rejected",reason:d}))))};const o=document.getElementsByTagName("link"),c=document.querySelector("meta[property=csp-nonce]"),l=c?.nonce||c?.getAttribute("nonce");n=a(t.map(h=>{if(h=qv(h,i),h in vf)return;vf[h]=!0;const u=h.endsWith(".css"),d=u?'[rel="stylesheet"]':"";if(!!i)for(let v=o.length-1;v>=0;v--){const m=o[v];if(m.href===h&&(!u||m.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${h}"]${d}`))return;const p=document.createElement("link");if(p.rel=u?"stylesheet":Yv,u||(p.as="script"),p.crossOrigin="",p.href=h,l&&p.setAttribute("nonce",l),document.head.appendChild(p),u)return new Promise((v,m)=>{p.addEventListener("load",v),p.addEventListener("error",()=>m(new Error(`Unable to preload CSS for ${h}`)))})}))}function s(a){const o=new Event("vite:preloadError",{cancelable:!0});if(o.payload=a,window.dispatchEvent(o),!o.defaultPrevented)throw a}return n.then(a=>{for(const o of a||[])o.status==="rejected"&&s(o.reason);return e().catch(s)})},$v=[{id:"coverage",name:"Coverage",credit:"UFO@home",creditUrl:"https://ufoathome.org",create:()=>({about:"observer",assess:async r=>{const{CoverageAssessor:e}=await pi(async()=>{const{CoverageAssessor:t}=await import("./CoverageAssessor-CZfxbN9A.js");return{CoverageAssessor:t}},[],import.meta.url);return new e().assess(r)}})},{id:"hynek",name:"Hynek",credit:"J. Allen Hynek",creditUrl:"https://rr0.org/science/crypto/ufo/observation/classification/hynek/",create:()=>({about:"temporal",assess:async r=>{const{HynekAssessor:e}=await pi(async()=>{const{HynekAssessor:t}=await import("./HynekAssessor-DPsLpEGQ.js");return{HynekAssessor:t}},[],import.meta.url);return new e().assess(r)}})}];class Kv{constructor(e){this.labels=e}async read(e){const t=[],i=new Set;for(const n of $v){let s;try{s=await n.create().assess(e)}catch{continue}for(const o of s.criteria)o.basis===void 0&&!o.unsupported&&i.add(o.id);const a=s.score===void 0?s.verdict===void 0?"":this.verdictName(n.id,s.verdict):`${Math.round(s.score*100)}%`;a!==""&&t.push({group:"assessment",field:n.id,label:this.labels.assessmentNames[n.id]??n.name,value:a,unit:"",fromSource:!1,about:n.create().about})}return{entries:t,unanswered:i}}verdictName(e,t){return this.labels.assessmentVerdicts[`${e}.${t}`]??t.toUpperCase()}}const Zv=.08,Mf=.15,xf=2,Jv=2e3;class jv{context;noiseBuffer;voices=new Map;paused=!0;requested=[];resume(){if(!this.context){if(typeof AudioContext>"u")return;try{this.context=new AudioContext}catch(e){console.warn("VehicleAudio: Web Audio unavailable, vehicles stay silent:",e);return}}this.context.state==="suspended"&&this.context.resume(),this.apply()}setPaused(e){e!==this.paused&&(this.paused=e,this.apply())}setVoices(e){this.requested=e,this.apply()}dispose(){for(const e of[...this.voices.keys()])this.release(e);this.context?.close(),this.context=void 0}apply(){const e=this.context;if(!e)return;const t=this.paused?[]:this.requested.filter(n=>n.inside||n.distanceM<Jv),i=new Set(t.map(n=>n.id));for(const n of[...this.voices.keys()])i.has(n)||this.release(n);for(const n of t){const s=this.voices.get(n.id)??this.build(e,n.id);this.retarget(e,s,n)}}build(e,t){const i=e.createGain();i.gain.value=0;const n=e.createBiquadFilter();n.type="lowpass",n.connect(i).connect(e.destination);const s=e.createOscillator();s.type="sawtooth";const a=e.createOscillator();a.type="sine";const o=e.createGain(),c=e.createBiquadFilter();c.type="lowpass",c.frequency.value=900,s.connect(c),a.connect(c),c.connect(o).connect(n);const l=()=>{const S=e.createBufferSource();return S.buffer=this.noise(e),S.loop=!0,S.loopStart=Math.random()*xf*.5,S},h=l(),u=e.createBiquadFilter();u.type="bandpass",u.Q.value=4;const d=e.createGain();h.connect(u).connect(d).connect(n);const f=l(),p=e.createBiquadFilter();p.type="lowpass",p.frequency.value=600;const v=e.createGain();f.connect(p).connect(v).connect(n);const m=l(),g=e.createBiquadFilter();g.type="bandpass",g.frequency.value=1400,g.Q.value=.7;const _=e.createGain();m.connect(g).connect(_).connect(n);const b=[s,a,h,f,m];for(const S of b)S.start();const M={nodes:[i,n,o,c,u,d,p,v,g,_,...b],sources:b,firing:s,crank:a,knock:u,engineGain:o,knockGain:d,roadGain:v,windGain:_,cabin:n,output:i};return this.voices.set(t,M),M}retarget(e,t,{profile:i,state:n,noise:s,inside:a,windowsOpen:o,distanceM:c}){const l=e.currentTime,h=(_,b)=>_.setTargetAtTime(b,l,Zv),u=n.rpm/60,d=u*i.cylinders/2,f=Math.min(1,n.rpm/i.shiftUpRpm),p=Math.min(1.5,n.speedMps/30);h(t.firing.frequency,d),h(t.crank.frequency,u),h(t.knock.frequency,d*3),h(t.engineGain.gain,i.engineGain*(.25+.75*n.load)*(.5+.5*f)*.3),h(t.knockGain.gain,i.roughness*(.2+.8*n.load)*.4),h(t.roadGain.gain,i.roadGain*p**1.5*.8);const v=!a||o;h(t.windGain.gain,p**2*(v?.5:.06));const m=a?o?3500:700:8e3/(1+c/60);h(t.cabin.frequency,m);const g=a?.5:Math.min(1,8/Math.max(c,1));h(t.output.gain,g*s)}release(e){const t=this.voices.get(e);if(!t)return;this.voices.delete(e);const i=this.context;i&&(t.output.gain.setTargetAtTime(0,i.currentTime,Mf/3),setTimeout(()=>{for(const n of t.sources)try{n.stop()}catch{}for(const n of t.nodes)n.disconnect()},Mf*1e3*3))}noise(e){if(this.noiseBuffer)return this.noiseBuffer;const t=e.createBuffer(1,e.sampleRate*xf,e.sampleRate),i=t.getChannelData(0);for(let n=0;n<i.length;n++)i[n]=Math.random()*2-1;return this.noiseBuffer=t,t}}class ko{static BY_KIND={car:{cylinders:4,idleRpm:800,kmhPer1000Rpm:[8,14,21,29,37,45],shiftUpRpm:3e3,shiftDownRpm:1300,engineGain:.6,roadGain:.5,roughness:.15},generic:{cylinders:4,idleRpm:800,kmhPer1000Rpm:[8,14,21,29,37,45],shiftUpRpm:3e3,shiftDownRpm:1300,engineGain:.6,roadGain:.5,roughness:.15},van:{cylinders:4,idleRpm:750,kmhPer1000Rpm:[7,12,19,27,35,42],shiftUpRpm:2600,shiftDownRpm:1200,engineGain:.8,roadGain:.7,roughness:.45},truck:{cylinders:6,idleRpm:600,kmhPer1000Rpm:[5,8,12,17,23,30,38,48],shiftUpRpm:1900,shiftDownRpm:1e3,engineGain:1,roadGain:.9,roughness:.55},motorcycle:{cylinders:2,idleRpm:1100,kmhPer1000Rpm:[12,18,24,30,35,40],shiftUpRpm:6e3,shiftDownRpm:2500,engineGain:.9,roadGain:.3,roughness:.3}};static of(e){return ko.BY_KIND[e??"generic"]??ko.BY_KIND.generic}}const wg=Math.PI/180,vl=111320;function ni(r,e,t,i){const n=vl*Math.cos(t*wg),s=(r-t)*vl;return{x:(e-i)*n,z:-s}}function _s(r,e,t,i){const n=vl*Math.cos(t*wg),s=-e,a=r;return{lat:t+s/vl,lng:i+a/n}}class Aa{constructor(e,t){this.samples=e,this.startMs=t}static SAMPLE_MS=100;static STANDING_MPS=.3;static of(e,t,i,n){const s=Aa.SAMPLE_MS,a=[];for(let l=i;l<=n+s/2;l+=s){const h=t(l-s/2),u=t(l+s/2);if(!h||!u)return;a.push(Math.hypot(u.eastM-h.eastM,u.northM-h.northM)/(s/1e3))}const o=[];let c=1;for(let l=0;l<a.length;l++){const h=a[l],u=(a[Math.min(l+1,a.length-1)]-a[Math.max(l-1,0)])/(2*s/1e3);if(h<Aa.STANDING_MPS){c=1,o.push({speedMps:h,rpm:e.idleRpm,load:.1,gear:0});continue}const d=h*3.6,f=g=>d/e.kmhPer1000Rpm[g-1]*1e3;for(;c<e.kmhPer1000Rpm.length&&f(c)>e.shiftUpRpm;)c++;for(;c>1&&f(c)<e.shiftDownRpm;)c--;const p=Math.max(f(c),e.idleRpm*(1+.3*Math.min(1,h/3))),v=.15+.5*Math.min(1,(h/35)**2),m=u>.15?Math.min(1,v+u/2.5):u<-.3?.05:v;o.push({speedMps:h,rpm:p,load:m,gear:c})}return new Aa(o,i)}at(e){const t=(e-this.startMs)/Aa.SAMPLE_MS,i=Math.min(Math.max(Math.floor(t),0),this.samples.length-1),n=this.samples[i],s=this.samples[Math.min(i+1,this.samples.length-1)],a=Math.min(Math.max(t-i,0),1);return{speedMps:n.speedMps+(s.speedMps-n.speedMps)*a,rpm:n.rpm+(s.rpm-n.rpm)*a,load:n.load+(s.load-n.load)*a,gear:a<.5?n.gear:s.gear}}}class Ml{drives=new Map;at(e,t){const i=[],n=e.event.place?.[0],s=l=>{const h=e.observerTrack.getInterpolatedPoseAt(l),u=h?.lat??n?.lat,d=h?.lng??n?.lng;if(u===void 0||d===void 0||!n)return;const f=ni(u,d,n.lat,n.lng);return{eastM:f.x,northM:-f.z}},a=Math.max(e.observerTrack.duration,(e.event.durationSeconds??0)*1e3),o=e.vehicle;if(o){const l=ko.of(o.kind),h=this.drive(`observer:${o.kind}`,Ml.trackKey(e),()=>Aa.of(l,s,0,a));h&&i.push({id:"observer",profile:l,state:h.at(t),noise:o.noise??1,inside:!0,windowsOpen:o.windowsOpen===!0,distanceM:0})}const c=s(t);for(const l of e.decor){if(!l.engine||!c)continue;const h=ko.of(l.engine.kind),u=v=>{const m=Or(l,v);return{eastM:m.eastM,northM:m.northM}},d=this.drive(`decor:${l.id}`,Ml.decorKey(l,a),()=>Aa.of(h,u,0,a));if(!d)continue;const f=Or(l,t),p=Math.hypot(f.eastM-c.eastM,f.northM-c.northM,f.altitudeM);i.push({id:`decor:${l.id}`,profile:h,state:d.at(t),noise:l.engine.noise??1,inside:!1,windowsOpen:!0,distanceM:p})}return i}drive(e,t,i){const n=this.drives.get(e);if(n&&n.key===t)return n.drive;const s=i();return this.drives.set(e,{key:t,drive:s}),s}static trackKey(e){return e.observerTrack.allKeyframes.map(i=>`${i.t}:${i.pose.lat}:${i.pose.lng}`).join(";")}static decorKey(e,t){return`${t}|${e.eastM},${e.northM}|`+(e.track??[]).map(i=>`${i.t}:${i.eastM}:${i.northM}`).join(";")}}function yf(r,e,t,i,n,s){const a=i?.lat!==void 0&&i.lng!==void 0&&n?.lat!==void 0&&n.lng!==void 0?ni(n.lat,n.lng,i.lat,i.lng):{x:0,z:0},o=Math.max(0,r),c=[0,...e.allKeyframes.map(l=>l.t).filter(l=>l>0&&l<o),o];for(let l=1;l<c.length;l++){const h=c[l-1],u=c[l]-h;if(u===0)continue;const d=32;for(let f=0;f<=d;f++){const p=e.getInterpolatedWeatherAt(h+u*f/d)??t,v=s===void 0?void 0:p.cloudLayers?.find(b=>b.id===s),m=(v?.windDirectionDeg??p.windDirectionDeg)*Math.PI/180,g=f===0||f===d?1:f%2===0?2:4,_=(v?.windSpeed??p.windSpeed)*u/1e3/d/3*g;a.x-=Math.sin(m)*_,a.z+=Math.cos(m)*_}}return a}const Qv=`
|
|
471
|
+
`;class Va extends Error{constructor(e,t,i){super(`${e}: ${t}${i===void 0?"":` (HTTP ${i})`}`),this.kind=e,this.url=t,this.status=i,this.name="SightingFetchError"}}class Ao{static async json(e){const t=new URL(e,location.href);if(location.protocol==="https:"&&t.protocol==="http:")throw new Va("mixed-content",e);let i;try{i=await fetch(e)}catch{throw await this.diagnose(e,t)}if(!i.ok)throw new Va("status",e,i.status);try{return await i.json()}catch{throw new Va("malformed",e)}}static async diagnose(e,t){if(t.origin===location.origin)return new Va("unreachable",e);try{return await fetch(e,{mode:"no-cors"}),new Va("cors",e)}catch{return new Va("unreachable",e)}}}class Gi{constructor(e){this.entries=e}static empty(){return new Gi(new Map)}get size(){return this.entries.size}at(e){return this.entries.get(e)}paths(){return[...this.entries.keys()]}set(e,t){t.basis==="stated"&&t.rationale===void 0?this.entries.delete(e):this.entries.set(e,t)}clear(e){for(const t of this.entries.keys())(t===e||t.startsWith(`${e}.`))&&this.entries.delete(t)}static strip(e){const t=new Gi(new Map);return{recording:Gi.stripValue(e,[],t),provenance:t}}static restore(e,t){if(t.size===0)return e;const i=structuredClone(e);for(const n of t.paths()){const s=t.at(n),a=n.split("."),o=Gi.holderOf(i,a);if(!o)continue;const c=a[a.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(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&"value"in e}static stripValue(e,t,i){return Gi.isWrapper(e)?(i.set(t.join("."),{basis:e.basis??"stated",...e.rationale===void 0?{}:{rationale:e.rationale},of:e.value}),Gi.stripValue(e.value,t,i)):Array.isArray(e)?e.map((n,s)=>Gi.stripValue(n,[...t,String(s)],i)):typeof e=="object"&&e!==null?Object.fromEntries(Object.entries(e).map(([n,s])=>[n,Gi.stripValue(s,[...t,n],i)])):e}static holderOf(e,t){let i=e;for(const n of t.slice(0,-1)){if(typeof i!="object"||i===null)return;i=i[n]}return typeof i=="object"&&i!==null?i:void 0}}class bs{static SIGHTING_EVENT="sighting";static INTERPRETATION_EVENT="interpretation";static isCase(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&Array.isArray(e.events)&&!("timeline"in e)}static sightingUrls(e,t){return(e.events??[]).filter(i=>i.eventType===bs.SIGHTING_EVENT&&typeof i.url=="string"&&i.url!=="").map(i=>new URL(i.url,t).href)}static interpretationEvents(e,t){return t?(e.events??[]).filter(i=>i.eventType===bs.INTERPRETATION_EVENT&&i.sighting===t).map(i=>i):[]}static async interpretationOf(e,t,i){if(e.bodies)return bs.withModelsFrom(Gi.strip({title:e.title,bodies:e.bodies,smoke:e.smoke}).recording,t);if(!e.url)return{title:e.title,bodies:[]};const n=new URL(e.url,t).href,s=await i(n);return bs.withModelsFrom(Gi.strip({title:e.title??s.title,bodies:s.bodies??[],smoke:s.smoke}).recording,n)}static withModelsFrom(e,t){return{...e,bodies:e.bodies.map(i=>i.model?.url?{...i,model:{...i.model,url:new URL(i.model.url,t).href}}:i)}}}class Et{static MOON_ANGULAR_WIDTH_DEG=.5237;static CANVAS_WIDTH_PX=640;static CANVAS_HEIGHT_PX=360;static angularWidthDeg(e){return 2*Math.atan(e.sizeM/(2*e.distanceM))*180/Math.PI}static inMoons(e){return e/Et.MOON_ANGULAR_WIDTH_DEG}static lerpAngular(e,t,i){if(!(!e||!t))return{widthDeg:e.widthDeg+(t.widthDeg-e.widthDeg)*i,heightDeg:e.heightDeg+(t.heightDeg-e.heightDeg)*i}}static sizeMAt(e,t){return 2*e*Math.tan(t*Math.PI/360)}static distanceMAt(e,t){return e/(2*Math.tan(t*Math.PI/360))}}function bv(r,e,t){if(!r||!e)return t<1?r:e;const i=((e.azimuthDeg-r.azimuthDeg)%360+540)%360-180;return{azimuthDeg:((r.azimuthDeg+i*t)%360+360)%360,altitudeDeg:r.altitudeDeg+(e.altitudeDeg-r.altitudeDeg)*t}}function _v(r,e,t){const{bounds:i}=r;return e>=i.x&&e<=i.x+i.width&&t>=i.y&&t<=i.y+i.height}function Zi(r,e,t){return r+(e-r)*t}function of(r){const e=/^#([0-9a-f]{6})$/i.exec(r);if(!e)return;const t=parseInt(e[1],16);return[t>>16&255,t>>8&255,t&255]}function Sv(r){return`#${r.map(e=>Math.round(e).toString(16).padStart(2,"0")).join("")}`}function wv(r,e,t){const i=of(r),n=of(e);return!i||!n?t<1?r:e:Sv([Zi(i[0],n[0],t),Zi(i[1],n[1],t),Zi(i[2],n[2],t)])}function Ev(r,e,t){const i={x:Zi(r.bounds.x,e.bounds.x,t),y:Zi(r.bounds.y,e.bounds.y,t),width:Zi(r.bounds.width,e.bounds.width,t),height:Zi(r.bounds.height,e.bounds.height,t)},n=Zi(r.angle,e.angle,t),s=Zi(r.transparency,e.transparency,t),a=Zi(r.haloScale,e.haloScale,t),o=Zi(r.blur??0,e.blur??0,t),c=Zi(r.brightness??0,e.brightness??0,t),l=wv(r.color,e.color,t),h=Et.lerpAngular(r.angular,e.angular,t),u=bv(r.aim,e.aim,t);return r.kind==="polygon"&&e.kind==="polygon"&&r.points.length===e.points.length?{...r,bounds:i,angle:n,transparency:s,haloScale:a,blur:o,brightness:c,color:l,angular:h,aim:u,points:r.points.map((d,f)=>({x:Zi(d.x,e.points[f].x,t),y:Zi(d.y,e.points[f].y,t)}))}:{...t<1?r:e,bounds:i,angle:n,transparency:s,haloScale:a,blur:o,brightness:c,color:l,angular:h,aim:u}}class xa{static DEFAULT_COLOR="#e8e6df";static complete(e,t=[]){const i=new Map;return e.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((a,o)=>{const c=`timeline.keyframes.${s}.shapes.${o}.shape`,l=xa.completed(a,i.get(a.sourceId),c,t);return i.set(a.sourceId,l),{sourceId:a.sourceId,shape:l}})}))}static completed(e,t,i,n){const s=e.shape??{},a=t??xa.firstAppearance(s,i,n),o={...a};s.bounds&&t&&(t.aim||t.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??a.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(e,t,i){return e.kind||i.push({kind:"defaulted",path:`${t}.kind`,expected:'"oval"'}),e.color||i.push({kind:"defaulted",path:`${t}.color`,expected:`"${xa.DEFAULT_COLOR}"`}),!e.bounds&&!e.aim&&i.push({kind:"unplaced",path:t}),!e.bounds&&!e.angular&&i.push({kind:"unsized",path:t}),{kind:e.kind??"oval",bounds:{...xa.NEUTRAL_BOUNDS},color:xa.DEFAULT_COLOR,angle:0,transparency:0,haloScale:0,selected:!1}}static NEUTRAL_BOUNDS={x:Et.CANVAS_WIDTH_PX/2,y:Et.CANVAS_HEIGHT_PX/2,width:1,height:1}}class Vl{keyframes=[];order=[];groups=[];addKeyframe(e,t){const i=this.findInsertIndex(e);if(this.keyframes[i]?.t===e){const n=new Set(t.map(s=>s.sourceId));this.keyframes[i]={t:e,shapes:[...this.keyframes[i].shapes.filter(s=>!n.has(s.sourceId)),...t]}}else this.keyframes.splice(i,0,{t:e,shapes:[...t]});for(const n of t)this.order.includes(n.sourceId)||this.order.push(n.sourceId)}findInsertIndex(e){let t=0,i=this.keyframes.length;for(;t<i;){const n=t+i>>>1;this.keyframes[n].t<e?t=n+1:i=n}return t}getKeyframeAt(e){const t=this.findInsertIndex(e),i=this.keyframes[t];return i?.t===e?i:void 0}getShapeAt(e,t){return this.getKeyframeAt(e)?.shapes.find(i=>i.sourceId===t)?.shape}getLatestShapeAt(e,t){let i=this.findInsertIndex(e);for(this.keyframes[i]?.t!==e&&(i-=1);i>=0;i--){const n=this.keyframes[i].shapes.find(s=>s.sourceId===t);if(n)return n.shape}}getInterpolatedShapeAt(e,t){const i=this.findShapeAtOrBefore(e,t);if(i?.t===e)return i.shape;const n=this.findShapeAtOrAfter(e,t);return i?n?Ev(i.shape,n.shape,(e-i.t)/(n.t-i.t)):i.shape:n?.shape}findShapeAtOrBefore(e,t){let i=this.findInsertIndex(e);for(this.keyframes[i]?.t!==e&&(i-=1);i>=0;i--){const n=this.keyframes[i].shapes.find(s=>s.sourceId===t);if(n)return{t:this.keyframes[i].t,shape:n.shape}}}findShapeAtOrAfter(e,t){for(let i=this.findInsertIndex(e);i<this.keyframes.length;i++){const n=this.keyframes[i].shapes.find(s=>s.sourceId===t);if(n)return{t:this.keyframes[i].t,shape:n.shape}}}hitTest(e,t,i,n){const s=this.sourceIds;for(let a=s.length-1;a>=0;a--){if(n?.has(s[a]))continue;const o=this.getInterpolatedShapeAt(e,s[a]);if(o&&_v(o,t,i))return{sourceId:s[a],shape:o}}}removeSource(e){for(let t=this.keyframes.length-1;t>=0;t--){const i=this.keyframes[t].shapes.filter(n=>n.sourceId!==e);i.length===0?this.keyframes.splice(t,1):i.length!==this.keyframes[t].shapes.length&&(this.keyframes[t]={t:this.keyframes[t].t,shapes:i})}this.order=this.order.filter(t=>t!==e),this.removeFromGroup(e)}group(e){if(!(e.length<2)){for(const t of e)this.removeFromGroup(t);this.groups.push([...e])}}ungroup(e){const t=this.groups.findIndex(i=>i.includes(e));t!==-1&&this.groups.splice(t,1)}groupMembers(e){return this.groups.find(t=>t.includes(e))}removeFromGroup(e){const t=this.groups.findIndex(n=>n.includes(e));if(t===-1)return;const i=this.groups[t].filter(n=>n!==e);i.length<2?this.groups.splice(t,1):this.groups[t]=i}bringToFront(e){const t=this.order.indexOf(e);t!==-1&&(this.order.splice(t,1),this.order.push(e))}sendToBack(e){const t=this.order.indexOf(e);t!==-1&&(this.order.splice(t,1),this.order.unshift(e))}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(e,t){const i=new Vl;for(const n of xa.complete(e.keyframes??[],t))i.addKeyframe(n.t,n.shapes);if(e.order){const n=i.order.filter(s=>!e.order.includes(s));i.order=[...e.order,...n]}return e.groups&&(i.groups=e.groups.map(n=>n.filter(s=>i.order.includes(s))).filter(n=>n.length>=2)),i}}function Av(r,e,t){return Math.max(e,Math.min(t,r))}function Tv(r,e,t){const i=((e-r)%360+540)%360-180;return((r+i*t)%360+360)%360}function Wa(r,e,t){return r+(e-r)*t}function Rv(r,e,t){return{lat:r.lat===void 0||e.lat===void 0?void 0:Wa(r.lat,e.lat,t),lng:r.lng===void 0||e.lng===void 0?void 0:Wa(r.lng,e.lng,t),elevationM:Wa(r.elevationM,e.elevationM,t),headingDeg:r.headingDeg===void 0||e.headingDeg===void 0?void 0:Tv(r.headingDeg,e.headingDeg,t),pitchDeg:Wa(r.pitchDeg,e.pitchDeg,t),rollDeg:Wa(r.rollDeg??0,e.rollDeg??0,t),fovDeg:Wa(r.fovDeg,e.fovDeg,t),fNumber:r.fNumber,focusDistanceM:r.focusDistanceM}}class Pa{static at(e,t,i,n,s){const a=e[i],c=e[i+1]-a;if(c<=0)return t[i];const l=Pa.tangent(e,t,i,s),h=Pa.tangent(e,t,i+1,s),u=(n-a)/c,d=u*u,f=d*u;return(2*f-3*d+1)*t[i]+(f-2*d+u)*c*l+(-2*f+3*d)*t[i+1]+(f-d)*c*h}static BRAKE_S=.8;static paced(e,t,i,n){if(!i&&!n)return e;const s=t>0?Math.min(.5,Pa.BRAKE_S/t):.5;if(i&&n){const o=1/(1-s);return e<=s?o*e*e/(2*s):e>=1-s?1-o*(1-e)*(1-e)/(2*s):o*(e-s/2)}const a=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?a(e):1-a(1-e)}static tangent(e,t,i,n){const s=e.length-1,a=f=>(t[f+1]-t[f])/(e[f+1]-e[f]||1);if(i===0)return n?0:a(0);if(i===s)return n?0:a(s-1);const o=a(i-1),c=a(i);if(o*c<=0)return 0;const l=e[i]-e[i-1],h=e[i+1]-e[i],u=2*h+l,d=h+2*l;return(u+d)/(u/o+d/c)}}class No{keyframes=[];addKeyframe(e,t){const i=this.findInsertIndex(e);this.keyframes[i]?.t===e?this.keyframes[i]={t:e,pose:t}:this.keyframes.splice(i,0,{t:e,pose:t})}clear(){this.keyframes.length=0}removeKeyframeAt(e){const t=this.findInsertIndex(e);this.keyframes[t]?.t===e&&this.keyframes.splice(t,1)}findInsertIndex(e){let t=0,i=this.keyframes.length;for(;t<i;){const n=t+i>>>1;this.keyframes[n].t<e?t=n+1:i=n}return t}getLatestPoseAt(e){let t=this.findInsertIndex(e);return this.keyframes[t]?.t!==e&&(t-=1),t>=0?this.keyframes[t].pose:void 0}getInterpolatedPoseAt(e){const t=this.findInsertIndex(e),i=this.keyframes[t]?.t===e?this.keyframes[t]:this.keyframes[t-1];if(i?.t===e)return i.pose;const n=this.keyframes[t]?.t===e?void 0:this.keyframes[t];if(!i)return n?.pose;if(!n)return i.pose;const s=Rv(i.pose,n.pose,Av((e-i.t)/(n.t-i.t),0,1));return this.humanly(t-1,e,s)}humanly(e,t,i){const n=Math.max(0,e-1),s=Math.min(this.keyframes.length-1,e+2),a=this.keyframes.slice(n,s+1),o=e-n,c=a.map(b=>b.t),l=(b,M)=>{const S=a.map(w=>b(w.pose));if(!S.some(w=>w===void 0))return Pa.at(c,S,o,t,M)},h=a.map(b=>b.pose.headingDeg);let u;if(h.every(b=>b!==void 0)){const b=[h[0]];for(let M=1;M<h.length;M++)b.push(b[M-1]+((h[M]-h[M-1])%360+540)%360-180);u=(Pa.at(c,b,o,t,!0)%360+360)%360}const d=this.keyframes[e],f=this.keyframes[e+1],p=(b,M)=>b.lat===M.lat&&b.lng===M.lng&&b.elevationM===M.elevationM,v=!p(d.pose,f.pose),m=v&&e>0&&p(this.keyframes[e-1].pose,d.pose),g=v&&e+2<this.keyframes.length&&p(f.pose,this.keyframes[e+2].pose);let _;if(m||g){const b=Pa.paced((t-d.t)/(f.t-d.t),(f.t-d.t)/1e3,m,g),M=(S,w)=>S===void 0||w===void 0?void 0:S+(w-S)*b;_={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:_?_.lat:l(b=>b.lat,!1)??i.lat,lng:_?_.lng:l(b=>b.lng,!1)??i.lng,elevationM:_?_.elevationM:l(b=>b.elevationM,!1)??i.elevationM,headingDeg:u??i.headingDeg,pitchDeg:l(b=>b.pitchDeg,!0)??i.pitchDeg,rollDeg:l(b=>b.rollDeg??0,!0)??i.rollDeg,fovDeg:l(b=>b.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(e){const t=new No;for(const i of e.keyframes)t.addKeyframe(i.t,i.pose);return t}}class qs{static MAX_CHANGE_PER_S=.05;points;followed;constructor(e){let t="none",i=0;this.points=e.map(({t:n,weather:s})=>(s.precipitationType!=="none"&&(t=s.precipitationType,i=s.precipitationIntensity),{t:n,lastFalling:t,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],a=this.points[n];this.followed.push(qs.follow(this.followed[n-1],s.intensity,a.intensity,(a.t-s.t)/1e3,(a.t-s.t)/1e3))}}at(e){if(this.points.length===0||e<this.points[0].t)return;let t=this.points.length-1;for(;t>0&&this.points[t].t>e;)t--;const i=this.points[t],n=this.points[t+1],s=n?qs.follow(this.followed[t],i.intensity,n.intensity,(n.t-i.t)/1e3,(e-i.t)/1e3):qs.follow(this.followed[t],i.intensity,i.intensity,1,(e-i.t)/1e3);return{type:qs.typeBetween(i,n,e,s),intensity:s,character:qs.characterBetween(i,n,e)}}static characterBetween(e,t,i){return e.type==="none"?t&&t.type!=="none"?t.intensity:e.lastFallingIntensity:!t||t.type==="none"?e.intensity:e.intensity+(t.intensity-e.intensity)*(i-e.t)/(t.t-e.t||1)}static typeBetween(e,t,i,n){return e.type==="none"?t&&t.type!=="none"&&i>e.t?t.type:n>0?e.lastFalling:"none":t&&t.type==="none"&&n<=0?"none":e.type}static follow(e,t,i,n,s){const a=qs.MAX_CHANGE_PER_S,o=n>0?(i-t)/n:0,c=u=>t+o*Math.min(Math.max(u,0),n);let l=e,h=0;for(let u=0;u<8&&h<s;u++){const d=c(h)-l;if(Math.abs(d)<1e-9){const b=h<n?o:0;if(Math.abs(b)<=a){const S=h<n?Math.min(s,n):s;l=c(S),h=S;continue}const M=Math.min(s,n);l+=Math.sign(b)*a*(M-h),h=M;continue}const f=Math.sign(d),p=h<n?o:0,v=a-f*p,m=v>0?h+Math.abs(d)/v:1/0,g=h<n?n:1/0,_=Math.min(s,m,g);l+=f*a*(_-h),h=_,_===m&&(l=c(h))}return Math.min(1,Math.max(0,l))}}const s0=1e3,Dv=.65,a0={cloudCover:0,cloudDarkness:0,precipitationType:"none",precipitationIntensity:0,windDirectionDeg:0,windSpeed:0,storm:!1};function gl(r){if(r.cloudLayers!==void 0)return r.cloudLayers;const e=[],t=r.lowerCloudCover??r.cloudCover;return t>0&&e.push({id:"lower",type:"cumulus",baseM:r.cloudBaseM??s0,thicknessM:650,coverage:t,sizeM:1400,density:1,darkness:r.cloudDarkness}),(r.highCloudCover??0)>0&&e.push({id:"cirrus",type:"cirrus",baseM:8e3,thicknessM:400,coverage:r.highCloudCover,sizeM:2200,density:.35,darkness:r.cloudDarkness,iceCrystalAlignment:r.iceCrystalAlignment}),e}function Ft(r,e,t){return r+(e-r)*t}function r0(r,e,t){const i=((e-r)%360+540)%360-180;return((r+i*t)%360+360)%360}function Iv(r,e,t){return Math.max(e,Math.min(t,r))}function Cv(r=[],e=[],t){if(!(!r.length&&!e.length))return[...new Set([...r.map(i=>i.id),...e.map(i=>i.id)])].map(i=>{const n=r.find(c=>c.id===i),s=e.find(c=>c.id===i),a=n??{...s,density:0},o=s??{...n,density:0};return{...a,eastM:Ft(a.eastM,o.eastM,t),northM:Ft(a.northM,o.northM,t),baseM:Ft(a.baseM,o.baseM,t),thicknessM:Ft(a.thicknessM,o.thicknessM,t),widthM:Ft(a.widthM,o.widthM,t),depthM:Ft(a.depthM,o.depthM,t),rotationDeg:r0(a.rotationDeg,o.rotationDeg,t),density:Ft(a.density,o.density,t),darkness:Ft(a.darkness??0,o.darkness??0,t)}})}function Pv(r,e,t){if(r.cloudLayers===void 0&&e.cloudLayers===void 0)return;const i=gl(r),n=gl(e);return t>=1?n.map(a=>({...a})):[...new Set([...i.map(a=>a.id),...n.map(a=>a.id)])].map(a=>{const o=i.find(u=>u.id===a),c=n.find(u=>u.id===a),l=o??{...c,coverage:0},h=c??{...o,coverage:0};return{...l,instances:Cv(o?.instances,c?.instances,t),baseM:Ft(l.baseM,h.baseM,t),thicknessM:Ft(l.thicknessM,h.thicknessM,t),coverage:Ft(l.coverage,h.coverage,t),sizeM:Ft(l.sizeM,h.sizeM,t),density:Ft(l.density,h.density,t),darkness:Ft(l.darkness??r.cloudDarkness,h.darkness??e.cloudDarkness,t),iceCrystalAlignment:l.iceCrystalAlignment===void 0||h.iceCrystalAlignment===void 0?void 0:Ft(l.iceCrystalAlignment,h.iceCrystalAlignment,t),windSpeed:l.windSpeed===void 0&&h.windSpeed===void 0?void 0:Ft(l.windSpeed??r.windSpeed,h.windSpeed??e.windSpeed,t),windDirectionDeg:l.windDirectionDeg===void 0&&h.windDirectionDeg===void 0?void 0:r0(l.windDirectionDeg??r.windDirectionDeg,h.windDirectionDeg??e.windDirectionDeg,t)}})}function Lv(r,e,t){return{cloudLayers:Pv(r,e,t),cloudCover:Ft(r.cloudCover,e.cloudCover,t),cloudDarkness:Ft(r.cloudDarkness,e.cloudDarkness,t),highCloudCover:r.highCloudCover===void 0||e.highCloudCover===void 0?void 0:Ft(r.highCloudCover,e.highCloudCover,t),iceCrystalAlignment:r.iceCrystalAlignment===void 0||e.iceCrystalAlignment===void 0?void 0:Ft(r.iceCrystalAlignment,e.iceCrystalAlignment,t),lowerCloudCover:r.lowerCloudCover===void 0||e.lowerCloudCover===void 0?void 0:Ft(r.lowerCloudCover,e.lowerCloudCover,t),cloudBaseM:r.cloudBaseM===void 0||e.cloudBaseM===void 0?void 0:Ft(r.cloudBaseM,e.cloudBaseM,t),relativeHumidity:r.relativeHumidity===void 0||e.relativeHumidity===void 0?void 0:Ft(r.relativeHumidity,e.relativeHumidity,t),precipitationType:t<1?r.precipitationType:e.precipitationType,precipitationIntensity:Ft(r.precipitationIntensity,e.precipitationIntensity,t),windDirectionDeg:r0(r.windDirectionDeg,e.windDirectionDeg,t),windSpeed:Ft(r.windSpeed,e.windSpeed,t),storm:t<1?r.storm:e.storm}}class Fo{keyframes=[];ramp;addKeyframe(e,t){this.ramp=void 0;const i=this.findInsertIndex(e);this.keyframes[i]?.t===e?this.keyframes[i]={t:e,weather:t}:this.keyframes.splice(i,0,{t:e,weather:t})}clear(){this.ramp=void 0,this.keyframes.length=0}removeKeyframeAt(e){this.ramp=void 0;const t=this.findInsertIndex(e);this.keyframes[t]?.t===e&&this.keyframes.splice(t,1)}findInsertIndex(e){let t=0,i=this.keyframes.length;for(;t<i;){const n=t+i>>>1;this.keyframes[n].t<e?t=n+1:i=n}return t}getLatestWeatherAt(e){let t=this.findInsertIndex(e);return this.keyframes[t]?.t!==e&&(t-=1),t>=0?this.keyframes[t].weather:void 0}getInterpolatedWeatherAt(e){const t=this.findInsertIndex(e),i=this.keyframes[t]?.t===e?this.keyframes[t]:this.keyframes[t-1];if(i?.t===e)return i.weather;const n=this.keyframes[t]?.t===e?void 0:this.keyframes[t];return i?n?Lv(i.weather,n.weather,Iv((e-i.t)/(n.t-i.t),0,1)):i.weather:n?.weather}getActualWeatherAt(e){const t=this.getInterpolatedWeatherAt(e);if(!t)return;const i=(this.ramp??=new qs(this.keyframes)).at(e);if(!i)return t;const{type:n,intensity:s,character:a}=i,o=a>0?Math.min(1,s/a):n==="none"?0:1;return{...t,precipitationType:n,precipitationIntensity:a,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(e){const t=new Fo;for(const i of e.keyframes)t.addKeyframe(i.t,i.weather);return t}}class Uo{keyframes=[];addKeyframe(e,t){const i=this.findInsertIndex(e);this.keyframes[i]?.t===e?this.keyframes[i]={t:e,sound:t}:this.keyframes.splice(i,0,{t:e,sound:t})}clear(){this.keyframes.length=0}removeKeyframeAt(e){const t=this.findInsertIndex(e);this.keyframes[t]?.t===e&&this.keyframes.splice(t,1)}getLatestSoundAt(e){let t=this.findInsertIndex(e);return this.keyframes[t]?.t!==e&&(t-=1),t>=0?this.keyframes[t].sound:void 0}getInterpolatedSoundAt(e){const t=this.findInsertIndex(e),i=this.keyframes[t]?.t===e?this.keyframes[t]:this.keyframes[t-1];if(i?.t===e)return i.sound;const n=this.keyframes[t]?.t===e?void 0:this.keyframes[t];if(!i)return n?.sound;if(!n)return i.sound;const s=(e-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(e){const t=new Uo;for(const i of e.keyframes)t.addKeyframe(i.t,i.sound);return t}lerp(e,t,i){return{kind:i<1?e.kind:t.kind,volume:e.volume+(t.volume-e.volume)*i,pitchHz:e.pitchHz+(t.pitchHz-e.pitchHz)*i,src:i<1?e.src:t.src}}findInsertIndex(e){let t=0,i=this.keyframes.length;for(;t<i;){const n=t+i>>>1;this.keyframes[n].t<e?t=n+1:i=n}return t}}const Ov=100,Nv={kind:"none",volume:0,pitchHz:Ov},ic=[{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:"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 si{static get default(){return ic[0]}static byId(e){return ic.find(t=>t.id===e)??this.default}static UNAIDED_FIELD_DEG=60;static UNAIDED_ASPECT=16/9;static fieldOfViewDeg(e){const t=e.frame;return t?2*Math.atan(t.heightMm/(2*t.focalLengthMm))*180/Math.PI:si.UNAIDED_FIELD_DEG}static aspectOf(e){const t=e.frame;return t?t.widthMm/t.heightMm:si.UNAIDED_ASPECT}static frameWidthPx(e,t){return Math.round(t*si.aspectOf(e))}static availableAt(e){return e===void 0?ic:ic.filter(t=>!t.years||e>=t.years.from&&(t.years.to===void 0||e<=t.years.to))}static fieldOfViewDegAt(e,t){const i=e.frame;if(!(!i||t<=0))return 2*Math.atan(i.heightMm/(2*t))*180/Math.PI}static focalLengthMmFor(e,t){const i=e.frame;if(!(!i||t<=0||t>=180))return i.heightMm/(2*Math.tan(t*Math.PI/360))}static bladesShowing(e,t){const i=t??e.fNumber;if(i===void 0||e.apertureBlades===void 0)return 0;const n=e.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(e){return e.flare??si.LENS_FLARE_ARTIFACTS}static starPointsOf(e){const t=e.apertureBlades;return t===void 0||t<3?0:t%2===0?t:t*2}}function cf(r){if(r.raw!==void 0)return r.raw;if(r.year===void 0){if(r.hour===void 0)return"";let t=`${String(r.hour).padStart(2,"0")}:${String(r.minute??0).padStart(2,"0")}`;return r.second!==void 0&&(t+=`:${String(r.second).padStart(2,"0")}`),t}let e=String(r.year).padStart(4,"0");return r.month===void 0||(e+=`-${String(r.month).padStart(2,"0")}`,r.day===void 0)||(e+=`-${String(r.day).padStart(2,"0")}`,r.hour===void 0)||(e+=`T${String(r.hour).padStart(2,"0")}:${String(r.minute??0).padStart(2,"0")}`,r.second!==void 0&&(e+=`:${String(r.second).padStart(2,"0")}`)),e}function Cu(r){if(r.year!==void 0)return Date.UTC(r.year,(r.month??1)-1,r.day??1,r.hour??0,r.minute??0,r.second??0)}function lf(r){return(((r.day??0)*24+(r.hour??0))*60+(r.minute??0))*6e4+(r.second??0)*1e3}const Fv=["year","month","day","hour","minute"],Uv=["day","hour","minute"];function hf(r,e){return e.filter(t=>r[t]!==void 0).join(",")}function xg(r){if(r.durationSeconds!==void 0)return r.durationSeconds*1e3;if(!r.time||!r.endTime)return;const e=r.time.year!==void 0&&r.endTime.year!==void 0,t=e?Fv:Uv,i=hf(r.time,t);if(!(i===""||i!==hf(r.endTime,t)))return e?Cu(r.endTime)-Cu(r.time):lf(r.endTime)-lf(r.time)}class Wl{constructor(e,t,i,n,s,a,o,c,l=[],h,u,d,f=[],p=[],v=[]){this.event=e,this.timeline=t,this.observerTrack=i,this.weatherTrack=n,this.soundTrack=s,this.observer=a,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}provenance=Gi.empty();loadIssues=[];account;sources;interpretation;sway;lightPollution;iso;vehicle;get observerCount(){return 1+this.decor.filter(e=>e.kind==="observer").length}get exposure(){return this.exposureSeconds??this.instrument.exposureSeconds}get instrument(){return si.byId(this.instrumentId)}static create(e,t,i){return new Wl({eventType:"sighting",time:e,place:t},new Vl,new No,new Fo,new Uo,i)}}const kv=0,zv=0;function jt(r,e){const t=r.observerTrack.getInterpolatedPoseAt(e);if(t)return t;const i=r.event.place?.[0];if(i)return{lat:i.lat,lng:i.lng,elevationM:kv,headingDeg:void 0,pitchDeg:zv,fovDeg:si.fieldOfViewDeg(r.instrument)}}function mr(r,e){return r.weatherTrack.getInterpolatedWeatherAt(e)??r.weather??a0}function uf(r,e){return r.weatherTrack.getActualWeatherAt(e)??r.weather??a0}function yg(r,e){return r.soundTrack.getInterpolatedSoundAt(e)??Nv}const df=2;function bg(r){return r==="building"||r==="vehicle"}function _g(r,e){const t=r.litKeyframes;if(!t||t.length===0)return r.lit??!1;let i=t[0];for(const n of t){if(n.t>e)break;i=n}return i.lit}function Bv(r,e){return r.pattern.kind==="steady"?!0:Sg(r,e,e+1)>.5}function Sg(r,e,t){if(r.pattern.kind==="steady")return 1;const{perMinute:i,dutyCycle:n,phase:s=0}=r.pattern,a=Math.min(Math.max(n,0),1);if(a===0||i<=0)return 0;const o=6e4/i,c=e/o+s,l=t/o+s;if(l<=c)return Math.min(Math.max(c-Math.floor(c),0),a)<a?1:0;const h=u=>Math.floor(u)*a+Math.min(u-Math.floor(u),a);return(h(l)-h(c))/(l-c)}function Or(r,e){const t=r.track,i={eastM:r.eastM,northM:r.northM,altitudeM:0,headingDeg:r.headingDeg};if(!t||t.length===0)return i;if(t.length===1||e<=t[0].t)return ff(t[0],r);const n=t[t.length-1];if(e>=n.t)return ff(n,r);for(let s=0;s<t.length-1;s++){const a=t[s],o=t[s+1];if(e<a.t||e>o.t)continue;const c=o.t-a.t,l=c===0?0:(e-a.t)/c;return{eastM:a.eastM+(o.eastM-a.eastM)*l,northM:a.northM+(o.northM-a.northM)*l,altitudeM:(a.altitudeM??0)+((o.altitudeM??0)-(a.altitudeM??0))*l,headingDeg:a.headingDeg??r.headingDeg}}return i}function ff(r,e){return{eastM:r.eastM,northM:r.northM,altitudeM:r.altitudeM??0,headingDeg:r.headingDeg??e.headingDeg}}const pf="#ff2200",mf="#00ff44",ha="#ffffff",nc="#ffa500",Xa="#ff0000",Hv="#2244ff",Gv=[{id:"airliner",name:"Airliner",kinds:["aircraft"],create:()=>[{id:"nav-port",offsetM:{x:-17,y:0,z:0},color:pf,pattern:{kind:"steady"}},{id:"nav-starboard",offsetM:{x:17,y:0,z:0},color:mf,pattern:{kind:"steady"}},{id:"nav-tail",offsetM:{x:0,y:1,z:-18},color:ha,pattern:{kind:"steady"}},{id:"beacon-top",offsetM:{x:0,y:2,z:0},color:Xa,intensity:1.5,pattern:{kind:"flash",perMinute:45,dutyCycle:.18}},{id:"beacon-bottom",offsetM:{x:0,y:-2,z:0},color:Xa,intensity:1.5,pattern:{kind:"flash",perMinute:45,dutyCycle:.18}},{id:"strobe-port",offsetM:{x:-17,y:0,z:-1},color:ha,intensity:20,pattern:{kind:"flash",perMinute:60,dutyCycle:.01}},{id:"strobe-starboard",offsetM:{x:17,y:0,z:-1},color:ha,intensity:20,pattern:{kind:"flash",perMinute:60,dutyCycle:.01,phase:.08}}]},{id:"helicopter",name:"Helicopter",kinds:["aircraft"],create:()=>[{id:"nav-port",offsetM:{x:-5,y:0,z:0},color:pf,pattern:{kind:"steady"}},{id:"nav-starboard",offsetM:{x:5,y:0,z:0},color:mf,pattern:{kind:"steady"}},{id:"nav-tail",offsetM:{x:0,y:1,z:-7},color:ha,pattern:{kind:"steady"}},{id:"beacon",offsetM:{x:0,y:2,z:-2},color:Xa,intensity:1.5,pattern:{kind:"flash",perMinute:45,dutyCycle:.2}},{id:"strobe",offsetM:{x:0,y:-1,z:0},color:ha,intensity:15,pattern:{kind:"flash",perMinute:75,dutyCycle:.015}}]},{id:"car-headlights",name:"Car, headlights on",kinds:["vehicle"],create:()=>[{id:"head-left",offsetM:{x:-.7,y:.6,z:2},color:ha,intensity:2,pattern:{kind:"steady"}},{id:"head-right",offsetM:{x:.7,y:.6,z:2},color:ha,intensity:2,pattern:{kind:"steady"}},{id:"tail-left",offsetM:{x:-.7,y:.6,z:-2},color:Xa,pattern:{kind:"steady"}},{id:"tail-right",offsetM:{x:.7,y:.6,z:-2},color:Xa,pattern:{kind:"steady"}}]},{id:"car-hazards",name:"Car, hazard flashers",kinds:["vehicle"],create:()=>[{id:"hazard-front-left",offsetM:{x:-.8,y:.6,z:2},color:nc,pattern:{kind:"flash",perMinute:90,dutyCycle:.5}},{id:"hazard-front-right",offsetM:{x:.8,y:.6,z:2},color:nc,pattern:{kind:"flash",perMinute:90,dutyCycle:.5}},{id:"hazard-rear-left",offsetM:{x:-.8,y:.6,z:-2},color:nc,pattern:{kind:"flash",perMinute:90,dutyCycle:.5}},{id:"hazard-rear-right",offsetM:{x:.8,y:.6,z:-2},color:nc,pattern:{kind:"flash",perMinute:90,dutyCycle:.5}}]},{id:"emergency-beacons",name:"Emergency vehicle beacons",kinds:["vehicle"],create:()=>[{id:"beacon-blue",offsetM:{x:-.4,y:1.6,z:0},color:Hv,intensity:2.5,pattern:{kind:"flash",perMinute:120,dutyCycle:.1}},{id:"beacon-red",offsetM:{x:.4,y:1.6,z:0},color:Xa,intensity:2.5,pattern:{kind:"flash",perMinute:120,dutyCycle:.1,phase:.5}}]},{id:"streetlamp",name:"Streetlamp",kinds:["streetlight"],create:()=>[{id:"lamp",offsetM:{x:0,y:5,z:0},color:"#ffd9a0",intensity:2,pattern:{kind:"steady"}}]}];class sl{constructor(e){this.names=e}name(e){return this.names[e.toLowerCase()]??e}stored(e){const t=e.trim().toLowerCase();for(const[i,n]of Object.entries(this.names))if(n.toLowerCase()===t)return i;return e.trim()}}class gf{constructor(e,t,i,n=new sl({})){this.labels=e,this.naming=t,this.said=i,this.tags=n}entriesFor(e,t,i={}){const n=[];return this.addObservation(n,e),this.addObserver(n,e,t),this.addLocation(n,e,t,i.groundElevationM),this.addDecor(n,e,t,i),this.addTemporal(n,e),this.addWeather(n,e,t),this.addSound(n,e,t),n}push(e,t,i,n,s,a="",o={}){s===void 0||s===""||e.push({group:t,field:i,label:n,value:String(s),unit:a,color:o.color,fromSource:o.fromSource===!0})}percent(e){return e===void 0?void 0:`${Math.round(e*100)} %`}rounded(e,t=0){return e===void 0?void 0:String(Number(e.toFixed(t)))}shows(e,t=0){return e!==void 0&&Number(e.toFixed(t))!==0}showsPercent(e){return this.shows(e===void 0?void 0:e*100)}percentShown(e){return this.showsPercent(e)?this.percent(e):void 0}roundedShown(e,t=0){return this.shows(e,t)?this.rounded(e,t):void 0}addObservation(e,t){const i=t.event.tags;this.push(e,"observation","tags",this.labels.tags,i&&i.length>0?i.map(n=>this.tags.name(n)).join(", "):void 0)}addObserver(e,t,i){const n=t.observer;this.push(e,"observer","observerId",this.labels.observerId,n?.id),this.push(e,"observer","observerTitle",this.labels.observerTitle,n?.title),this.push(e,"observer","observerLastName",this.labels.observerLastName,n?.lastName);const s=n?.firstNames;this.push(e,"observer","observerFirstNames",this.labels.observerFirstNames,s&&s.length>0?s.join(", "):void 0);const a=t.instrument;this.push(e,"observer","instrument",this.labels.instrument,this.naming.instrument(a));const o=t.exposure;this.push(e,"observer","exposureSeconds",this.labels.exposure,o===void 0?void 0:o<1?`1/${Math.round(1/o)}`:this.rounded(o,2),"s");const c=jt(t,i);if(c){const l=si.focalLengthMmFor(a,c.fovDeg);l===void 0?this.push(e,"observer","focalLength",this.labels.fieldOfView,this.rounded(c.fovDeg,1),"°"):this.push(e,"observer","focalLength",this.labels.focalLength,this.rounded(l,1),"mm"),this.push(e,"observer","fNumber",this.labels.aperture,this.rounded(c.fNumber??a.fNumber,1)),this.push(e,"observer","focusDistance",this.labels.focusDistance,this.rounded(c.focusDistanceM,1),"m"),this.push(e,"observer","roll",this.labels.roll,this.roundedShown(c.rollDeg),"°")}}addLocation(e,t,i,n){const s=t.event.place?.[0];this.push(e,"location","placeName",this.labels.placeName,s?.name);const a=jt(t,i);if(!a)return;this.push(e,"location","lat",this.labels.latitude,this.rounded(a.lat,6)),this.push(e,"location","lng",this.labels.longitude,this.rounded(a.lng,6));const o=this.rounded(a.headingDeg);this.push(e,"location","heading",this.labels.heading,o,a.headingDeg===void 0?"°":`° (${this.naming.point(a.headingDeg)})`),this.push(e,"location","pitch",this.labels.pitch,this.rounded(a.pitchDeg),"°"),n===void 0?this.push(e,"location","elevation",this.labels.heightAboveGround,this.roundedShown(a.elevationM),"m"):this.push(e,"location","elevation",this.labels.elevation,this.rounded(n+a.elevationM),"m")}addDecor(e,t,i,n){const s=t.decor.find(l=>l.id===n.decorId);if(!s){if(n.decorPicker===!0)for(const l of t.decor)this.push(e,"decor",`decor:${l.id}`,this.decorLabel(l),this.decorKindName(l.kind));return}this.push(e,"decor","decorTitle",this.labels.decorTitle,this.said.read(s.title));const a=Or(s,i);this.push(e,"decor","decorEast",this.labels.decorEast,this.rounded(a.eastM,1),"m"),this.push(e,"decor","decorNorth",this.labels.decorNorth,this.rounded(a.northM,1),"m"),this.push(e,"decor","decorAltitude",this.labels.decorAltitude,this.roundedShown(a.altitudeM),"m"),this.push(e,"decor","decorHeading",this.labels.decorHeading,this.rounded(a.headingDeg),"°"),_g(s,i)&&this.push(e,"decor","decorLit",this.labels.decorLit,"✓");const o=s.lights?.map(l=>l.id).join()??"",c=o===""?void 0:Gv.find(l=>l.create().map(h=>h.id).join()===o);this.push(e,"decor","decorLightRig",this.labels.decorLights,c?.name),this.push(e,"decor","decorFloors",this.labels.decorFloors,s.floors),this.push(e,"decor","decorOccupiedFloor",this.labels.decorOccupiedFloor,s.occupiedFloor),this.push(e,"decor","decorObserverSide",this.labels.decorObserverSide,this.decorSideName(s.observerSide));for(const[l,h]of Object.entries(s.windows??{}))this.push(e,"decor",`decorWindow${this.capitalise(l)}`,`${this.labels.decorWindows} ${this.decorSideName(l)}`,h,"%")}addTemporal(e,t){const i=t.event;this.push(e,"temporal","obs-time",this.labels.observationTime,i.time&&cf(i.time)),this.push(e,"temporal","obs-end-time",this.labels.observationEndTime,i.endTime&&cf(i.endTime));const n=xg(i);this.push(e,"temporal","durationSeconds",this.labels.duration,this.roundedShown(n&&n/1e3,1),"s"),this.push(e,"temporal","timeZone",this.labels.utcOffset,i.timeZone),this.push(e,"temporal","utcOffsetHours",this.labels.utcOffset,this.rounded(i.utcOffsetHours,1),"UTC±h")}addWeather(e,t,i){const n=mr(t,i),a={fromSource:t.weatherSource!==void 0},o=this.showsPercent(n.cloudCover)||this.showsPercent(n.lowerCloudCover)||this.showsPercent(n.highCloudCover);this.push(e,"weather","cloudCover",this.labels.cloudCover,this.percentShown(n.cloudCover),"",a),this.push(e,"weather","highCloudCover",this.labels.highCloudCover,this.percentShown(n.highCloudCover),"",a),this.push(e,"weather","iceCrystalAlignment",this.labels.iceCrystalAlignment,this.showsPercent(n.highCloudCover)?this.percent(n.iceCrystalAlignment):void 0),this.push(e,"weather","cloudDarkness",this.labels.cloudDarkness,o?this.percent(n.cloudDarkness):void 0,"",a),this.push(e,"weather","cloudBase",this.labels.cloudBase,o?this.rounded(n.cloudBaseM):void 0,"m",a);const c=n.precipitationType!=="none"&&this.showsPercent(n.precipitationIntensity);this.push(e,"weather","precipitationType",this.labels.precipitationType,c?this.precipitationName(n.precipitationType):void 0,"",a),this.push(e,"weather","precipitationIntensity",this.labels.precipitationIntensity,c?this.percent(n.precipitationIntensity):void 0,"",a),this.push(e,"weather","windDirection",this.labels.windDirection,this.shows(n.windSpeed,2)?this.rounded(n.windDirectionDeg):void 0,"°",a),this.push(e,"weather","windSpeed",this.labels.windSpeed,this.roundedShown(n.windSpeed,2),"m/s",a),n.storm&&this.push(e,"weather","storm",this.labels.storm,"✓","",a)}addSound(e,t,i){const n=yg(t,i);n.kind!=="none"&&(this.push(e,"sound","soundKind",this.labels.soundKind,this.soundKindName(n.kind)),this.push(e,"sound","soundVolume",this.labels.soundVolume,this.percentShown(n.volume)),this.push(e,"sound","soundPitch",this.labels.soundPitch,this.roundedShown(n.pitchHz),"Hz"),this.push(e,"sound","soundSrc",this.labels.soundSrc,n.src))}decorLabel(e){return this.said.read(e.title)??this.decorKindName(e.kind)}decorKindName(e){switch(e){case"building":return this.labels.decorBuilding;case"tree":return this.labels.decorTree;case"shrub":return this.labels.decorShrub;case"bridge":return this.labels.decorBridge;case"crop":return this.labels.decorCrop;case"mound":return this.labels.decorMound;case"streetlight":return this.labels.decorStreetlight;case"vehicle":return this.labels.decorVehicle;case"aircraft":return this.labels.decorAircraft;default:return this.labels.decorObserver}}decorSideName(e){switch(e){case"front":return this.labels.decorSideFront;case"behind":return this.labels.decorSideBehind;case"left":return this.labels.decorSideLeft;case"right":return this.labels.decorSideRight;case"front-left":return this.labels.decorSideFrontLeft;case"front-right":return this.labels.decorSideFrontRight;case"behind-left":return this.labels.decorSideBehindLeft;case"behind-right":return this.labels.decorSideBehindRight;default:return}}precipitationName(e){switch(e){case"rain":return this.labels.precipitationRain;case"snow":return this.labels.precipitationSnow;case"hail":return this.labels.precipitationHail;default:return this.labels.precipitationNone}}soundKindName(e){switch(e){case"hum":return this.labels.soundHum;case"whistle":return this.labels.soundWhistle;case"rumble":return this.labels.soundRumble;case"crackle":return this.labels.soundCrackle;default:return this.labels.soundNone}}capitalise(e){return e.replace(/(^|-)([a-z])/g,(t,i,n)=>n.toUpperCase())}}const Vv="“Thunder” by Jerimee",Wv="https://creativecommons.org/licenses/by/3.0/",Xv="CC BY 3.0";class Dn{static fill(e,t){e.innerHTML="";const i=l=>e.appendChild(l),n=t.currentTerrainAttribution;n&&i(Dn.text(n));const s=t.currentRoadAttribution;s&&i(Dn.text(s));const a=t.ufoElement.observerMapCredit;a&&!n?.includes(a)&&i(Dn.text(a));for(const l of t.decorModelCredits){const h=l.author?` — ${l.author}`:"",u=document.createElement("li");l.sourceUrl?u.append(Dn.link(l.sourceUrl,l.title),document.createTextNode(`${h} (${l.license})`)):u.textContent=`${l.title}${h} (${l.license})`,i(u)}for(const l of t.ufoElement.sighting.references){if(!l.credit)continue;const h=document.createElement("li");l.creditUrl?h.appendChild(Dn.link(l.creditUrl,l.credit)):h.textContent=l.credit,i(h)}const o=t.satelliteState;if(o.status==="ready"&&o.credit){const l=document.createElement("li");l.appendChild(Dn.link(o.creditUrl??"",o.credit)),i(l)}const c=Dn.text(`${Vv} (`);c.append(Dn.link(Wv,Xv),document.createTextNode(")")),i(c)}static text(e){const t=document.createElement("li");return t.textContent=e,t}static link(e,t){const i=document.createElement("a");return i.href=e,i.target="_blank",i.rel="noopener",i.textContent=t,i}}const Yv="modulepreload",qv=function(r,e){return new URL(r,e).href},vf={},pi=function(e,t,i){let n=Promise.resolve();if(t&&t.length>0){let a=function(h){return Promise.all(h.map(u=>Promise.resolve(u).then(d=>({status:"fulfilled",value:d}),d=>({status:"rejected",reason:d}))))};const o=document.getElementsByTagName("link"),c=document.querySelector("meta[property=csp-nonce]"),l=c?.nonce||c?.getAttribute("nonce");n=a(t.map(h=>{if(h=qv(h,i),h in vf)return;vf[h]=!0;const u=h.endsWith(".css"),d=u?'[rel="stylesheet"]':"";if(!!i)for(let v=o.length-1;v>=0;v--){const m=o[v];if(m.href===h&&(!u||m.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${h}"]${d}`))return;const p=document.createElement("link");if(p.rel=u?"stylesheet":Yv,u||(p.as="script"),p.crossOrigin="",p.href=h,l&&p.setAttribute("nonce",l),document.head.appendChild(p),u)return new Promise((v,m)=>{p.addEventListener("load",v),p.addEventListener("error",()=>m(new Error(`Unable to preload CSS for ${h}`)))})}))}function s(a){const o=new Event("vite:preloadError",{cancelable:!0});if(o.payload=a,window.dispatchEvent(o),!o.defaultPrevented)throw a}return n.then(a=>{for(const o of a||[])o.status==="rejected"&&s(o.reason);return e().catch(s)})},$v=[{id:"coverage",name:"Coverage",credit:"UFO@home",creditUrl:"https://ufoathome.org",create:()=>({about:"observer",assess:async r=>{const{CoverageAssessor:e}=await pi(async()=>{const{CoverageAssessor:t}=await import("./CoverageAssessor-CZfxbN9A.js");return{CoverageAssessor:t}},[],import.meta.url);return new e().assess(r)}})},{id:"hynek",name:"Hynek",credit:"J. Allen Hynek",creditUrl:"https://rr0.org/science/crypto/ufo/observation/classification/hynek/",create:()=>({about:"temporal",assess:async r=>{const{HynekAssessor:e}=await pi(async()=>{const{HynekAssessor:t}=await import("./HynekAssessor-DPsLpEGQ.js");return{HynekAssessor:t}},[],import.meta.url);return new e().assess(r)}})}];class Kv{constructor(e){this.labels=e}async read(e){const t=[],i=new Set;for(const n of $v){let s;try{s=await n.create().assess(e)}catch{continue}for(const o of s.criteria)o.basis===void 0&&!o.unsupported&&i.add(o.id);const a=s.score===void 0?s.verdict===void 0?"":this.verdictName(n.id,s.verdict):`${Math.round(s.score*100)}%`;a!==""&&t.push({group:"assessment",field:n.id,label:this.labels.assessmentNames[n.id]??n.name,value:a,unit:"",fromSource:!1,about:n.create().about})}return{entries:t,unanswered:i}}verdictName(e,t){return this.labels.assessmentVerdicts[`${e}.${t}`]??t.toUpperCase()}}const Zv=.08,Mf=.15,xf=2,Jv=2e3;class jv{context;noiseBuffer;voices=new Map;paused=!0;requested=[];resume(){if(!this.context){if(typeof AudioContext>"u")return;try{this.context=new AudioContext}catch(e){console.warn("VehicleAudio: Web Audio unavailable, vehicles stay silent:",e);return}}this.context.state==="suspended"&&this.context.resume(),this.apply()}setPaused(e){e!==this.paused&&(this.paused=e,this.apply())}setVoices(e){this.requested=e,this.apply()}dispose(){for(const e of[...this.voices.keys()])this.release(e);this.context?.close(),this.context=void 0}apply(){const e=this.context;if(!e)return;const t=this.paused?[]:this.requested.filter(n=>n.inside||n.distanceM<Jv),i=new Set(t.map(n=>n.id));for(const n of[...this.voices.keys()])i.has(n)||this.release(n);for(const n of t){const s=this.voices.get(n.id)??this.build(e,n.id);this.retarget(e,s,n)}}build(e,t){const i=e.createGain();i.gain.value=0;const n=e.createBiquadFilter();n.type="lowpass",n.connect(i).connect(e.destination);const s=e.createOscillator();s.type="sawtooth";const a=e.createOscillator();a.type="sine";const o=e.createGain(),c=e.createBiquadFilter();c.type="lowpass",c.frequency.value=900,s.connect(c),a.connect(c),c.connect(o).connect(n);const l=()=>{const S=e.createBufferSource();return S.buffer=this.noise(e),S.loop=!0,S.loopStart=Math.random()*xf*.5,S},h=l(),u=e.createBiquadFilter();u.type="bandpass",u.Q.value=4;const d=e.createGain();h.connect(u).connect(d).connect(n);const f=l(),p=e.createBiquadFilter();p.type="lowpass",p.frequency.value=600;const v=e.createGain();f.connect(p).connect(v).connect(n);const m=l(),g=e.createBiquadFilter();g.type="bandpass",g.frequency.value=1400,g.Q.value=.7;const _=e.createGain();m.connect(g).connect(_).connect(n);const b=[s,a,h,f,m];for(const S of b)S.start();const M={nodes:[i,n,o,c,u,d,p,v,g,_,...b],sources:b,firing:s,crank:a,knock:u,engineGain:o,knockGain:d,roadGain:v,windGain:_,cabin:n,output:i};return this.voices.set(t,M),M}retarget(e,t,{profile:i,state:n,noise:s,inside:a,windowsOpen:o,distanceM:c}){const l=e.currentTime,h=(_,b)=>_.setTargetAtTime(b,l,Zv),u=n.rpm/60,d=u*i.cylinders/2,f=Math.min(1,n.rpm/i.shiftUpRpm),p=Math.min(1.5,n.speedMps/30);h(t.firing.frequency,d),h(t.crank.frequency,u),h(t.knock.frequency,d*3),h(t.engineGain.gain,i.engineGain*(.25+.75*n.load)*(.5+.5*f)*.3),h(t.knockGain.gain,i.roughness*(.2+.8*n.load)*.4),h(t.roadGain.gain,i.roadGain*p**1.5*.8);const v=!a||o;h(t.windGain.gain,p**2*(v?.5:.06));const m=a?o?3500:700:8e3/(1+c/60);h(t.cabin.frequency,m);const g=a?.5:Math.min(1,8/Math.max(c,1));h(t.output.gain,g*s)}release(e){const t=this.voices.get(e);if(!t)return;this.voices.delete(e);const i=this.context;i&&(t.output.gain.setTargetAtTime(0,i.currentTime,Mf/3),setTimeout(()=>{for(const n of t.sources)try{n.stop()}catch{}for(const n of t.nodes)n.disconnect()},Mf*1e3*3))}noise(e){if(this.noiseBuffer)return this.noiseBuffer;const t=e.createBuffer(1,e.sampleRate*xf,e.sampleRate),i=t.getChannelData(0);for(let n=0;n<i.length;n++)i[n]=Math.random()*2-1;return this.noiseBuffer=t,t}}class ko{static BY_KIND={car:{cylinders:4,idleRpm:800,kmhPer1000Rpm:[8,14,21,29,37,45],shiftUpRpm:3e3,shiftDownRpm:1300,engineGain:.6,roadGain:.5,roughness:.15},generic:{cylinders:4,idleRpm:800,kmhPer1000Rpm:[8,14,21,29,37,45],shiftUpRpm:3e3,shiftDownRpm:1300,engineGain:.6,roadGain:.5,roughness:.15},van:{cylinders:4,idleRpm:750,kmhPer1000Rpm:[7,12,19,27,35,42],shiftUpRpm:2600,shiftDownRpm:1200,engineGain:.8,roadGain:.7,roughness:.45},truck:{cylinders:6,idleRpm:600,kmhPer1000Rpm:[5,8,12,17,23,30,38,48],shiftUpRpm:1900,shiftDownRpm:1e3,engineGain:1,roadGain:.9,roughness:.55},motorcycle:{cylinders:2,idleRpm:1100,kmhPer1000Rpm:[12,18,24,30,35,40],shiftUpRpm:6e3,shiftDownRpm:2500,engineGain:.9,roadGain:.3,roughness:.3}};static of(e){return ko.BY_KIND[e??"generic"]??ko.BY_KIND.generic}}const wg=Math.PI/180,vl=111320;function ni(r,e,t,i){const n=vl*Math.cos(t*wg),s=(r-t)*vl;return{x:(e-i)*n,z:-s}}function _s(r,e,t,i){const n=vl*Math.cos(t*wg),s=-e,a=r;return{lat:t+s/vl,lng:i+a/n}}class Aa{constructor(e,t){this.samples=e,this.startMs=t}static SAMPLE_MS=100;static STANDING_MPS=.3;static of(e,t,i,n){const s=Aa.SAMPLE_MS,a=[];for(let l=i;l<=n+s/2;l+=s){const h=t(l-s/2),u=t(l+s/2);if(!h||!u)return;a.push(Math.hypot(u.eastM-h.eastM,u.northM-h.northM)/(s/1e3))}const o=[];let c=1;for(let l=0;l<a.length;l++){const h=a[l],u=(a[Math.min(l+1,a.length-1)]-a[Math.max(l-1,0)])/(2*s/1e3);if(h<Aa.STANDING_MPS){c=1,o.push({speedMps:h,rpm:e.idleRpm,load:.1,gear:0});continue}const d=h*3.6,f=g=>d/e.kmhPer1000Rpm[g-1]*1e3;for(;c<e.kmhPer1000Rpm.length&&f(c)>e.shiftUpRpm;)c++;for(;c>1&&f(c)<e.shiftDownRpm;)c--;const p=Math.max(f(c),e.idleRpm*(1+.3*Math.min(1,h/3))),v=.15+.5*Math.min(1,(h/35)**2),m=u>.15?Math.min(1,v+u/2.5):u<-.3?.05:v;o.push({speedMps:h,rpm:p,load:m,gear:c})}return new Aa(o,i)}at(e){const t=(e-this.startMs)/Aa.SAMPLE_MS,i=Math.min(Math.max(Math.floor(t),0),this.samples.length-1),n=this.samples[i],s=this.samples[Math.min(i+1,this.samples.length-1)],a=Math.min(Math.max(t-i,0),1);return{speedMps:n.speedMps+(s.speedMps-n.speedMps)*a,rpm:n.rpm+(s.rpm-n.rpm)*a,load:n.load+(s.load-n.load)*a,gear:a<.5?n.gear:s.gear}}}class Ml{drives=new Map;at(e,t){const i=[],n=e.event.place?.[0],s=l=>{const h=e.observerTrack.getInterpolatedPoseAt(l),u=h?.lat??n?.lat,d=h?.lng??n?.lng;if(u===void 0||d===void 0||!n)return;const f=ni(u,d,n.lat,n.lng);return{eastM:f.x,northM:-f.z}},a=Math.max(e.observerTrack.duration,(e.event.durationSeconds??0)*1e3),o=e.vehicle;if(o){const l=ko.of(o.kind),h=this.drive(`observer:${o.kind}`,Ml.trackKey(e),()=>Aa.of(l,s,0,a));h&&i.push({id:"observer",profile:l,state:h.at(t),noise:o.noise??1,inside:!0,windowsOpen:o.windowsOpen===!0,distanceM:0})}const c=s(t);for(const l of e.decor){if(!l.engine||!c)continue;const h=ko.of(l.engine.kind),u=v=>{const m=Or(l,v);return{eastM:m.eastM,northM:m.northM}},d=this.drive(`decor:${l.id}`,Ml.decorKey(l,a),()=>Aa.of(h,u,0,a));if(!d)continue;const f=Or(l,t),p=Math.hypot(f.eastM-c.eastM,f.northM-c.northM,f.altitudeM);i.push({id:`decor:${l.id}`,profile:h,state:d.at(t),noise:l.engine.noise??1,inside:!1,windowsOpen:!0,distanceM:p})}return i}drive(e,t,i){const n=this.drives.get(e);if(n&&n.key===t)return n.drive;const s=i();return this.drives.set(e,{key:t,drive:s}),s}static trackKey(e){return e.observerTrack.allKeyframes.map(i=>`${i.t}:${i.pose.lat}:${i.pose.lng}`).join(";")}static decorKey(e,t){return`${t}|${e.eastM},${e.northM}|`+(e.track??[]).map(i=>`${i.t}:${i.eastM}:${i.northM}`).join(";")}}function yf(r,e,t,i,n,s){const a=i?.lat!==void 0&&i.lng!==void 0&&n?.lat!==void 0&&n.lng!==void 0?ni(n.lat,n.lng,i.lat,i.lng):{x:0,z:0},o=Math.max(0,r),c=[0,...e.allKeyframes.map(l=>l.t).filter(l=>l>0&&l<o),o];for(let l=1;l<c.length;l++){const h=c[l-1],u=c[l]-h;if(u===0)continue;const d=32;for(let f=0;f<=d;f++){const p=e.getInterpolatedWeatherAt(h+u*f/d)??t,v=s===void 0?void 0:p.cloudLayers?.find(b=>b.id===s),m=(v?.windDirectionDeg??p.windDirectionDeg)*Math.PI/180,g=f===0||f===d?1:f%2===0?2:4,_=(v?.windSpeed??p.windSpeed)*u/1e3/d/3*g;a.x-=Math.sin(m)*_,a.z+=Math.cos(m)*_}}return a}const Qv=`
|
|
472
472
|
<div class="stage" id="stage">
|
|
473
473
|
<div class="frame" id="frame">
|
|
474
474
|
<canvas id="scene-canvas"></canvas>
|
|
@@ -1296,13 +1296,13 @@ input[type=range] {
|
|
|
1296
1296
|
pointer-events: none;
|
|
1297
1297
|
white-space: nowrap;
|
|
1298
1298
|
}
|
|
1299
|
-
`;class wr{constructor(e){this.points=e}static STATIONARY_M=5;static of(e){const t=[];for(const i of e.observerTrack.allKeyframes){const{lat:n,lng:s,headingDeg:a}=i.pose;n===void 0||s===void 0||t.push({t:i.t,lat:n,lng:s,headingDeg:a})}if(t.length===0){const i=e.event.place?.[0];if(!i)return;t.push({t:0,lat:i.lat,lng:i.lng})}return new wr(t)}static TRAVEL_M=50;get travels(){return this.spanM>wr.TRAVEL_M}get moved(){return this.spanM>wr.STATIONARY_M}get spanM(){const e=this.box,t=(e.south+e.north)/2,i=(e.west+e.east)/2;return Math.max(Math.abs(ni(t,e.east,t,e.west).x),Math.abs(ni(e.north,i,e.south,i).z))}get center(){const e=this.box;return{lat:(e.south+e.north)/2,lng:(e.west+e.east)/2}}boundsAround(e,t){const{lat:i,lng:n}=this.center,s=Math.max(this.spanM*(1+t),e)/2;return{north:_s(0,-s,i,n).lat,south:_s(0,s,i,n).lat,east:_s(s,0,i,n).lng,west:_s(-s,0,i,n).lng}}get box(){const e=this.points.map(i=>i.lat),t=this.points.map(i=>i.lng);return{south:Math.min(...e),north:Math.max(...e),west:Math.min(...t),east:Math.max(...t)}}}class gn{constructor(e,t){this.rotationPassed=e,this.scale=t}static SWAY_M=.012;static BREATH_M=.003;static DRIFT_YAW_DEG=.5;static DRIFT_PITCH_DEG=.4;static DRIFT_ROLL_DEG=.3;static GAZE_DRIFT_SHARE=.35;static HAND_HELD_S=.5;static HZ=[.11,.23,.17,.29,.37,.07];static of(e){const t=e.event.tags?.includes("paralysis")||(e.exposure??0)>gn.HAND_HELD_S,i=e.sway??(t?0:1);if(i>0)return new gn(Math.max(1-(e.instrument.stabilization??0),gn.GAZE_DRIFT_SHARE),i)}offsetAt(e){const t=e/1e3,i=this.scale,n=(u,d)=>Math.sin(2*Math.PI*u*t+d),[s,a,o,c,l,h]=gn.HZ;return{eastM:i*gn.SWAY_M*(.7*n(s,.3)+.3*n(c,1.9)),northM:i*gn.SWAY_M*(.6*n(o,2.2)+.4*n(l,.8)),upM:i*gn.BREATH_M*n(a,0),yawDeg:i*this.rotationPassed*gn.DRIFT_YAW_DEG*(.6*n(h,1.1)+.4*n(c,2.7)),pitchDeg:i*this.rotationPassed*gn.DRIFT_PITCH_DEG*(.5*n(a,1.6)+.5*n(o,.4)),rollDeg:i*this.rotationPassed*gn.DRIFT_ROLL_DEG*n(s,2.9)}}}class xt{constructor(e,t){this.stretches=e,this.rotationPassed=t}static REFERENCE_SPEED_M_PER_S=1.4;static REFERENCE_STEP_HZ=1.9;static CADENCE_EXPONENT=.43;static RISE_M_PER_M_PER_S=.0175;static SWAY_M=.0175;static SLOWEST_WALK_M_PER_S=.2;static FASTEST_WALK_M_PER_S=2.2;static HEAD_ROLL_DEG=1.5;static HEAD_PITCH_DEG=1.25;static HEAD_YAW_DEG=1;static STOP_LURCH_M=.035;static STOP_PITCH_DEG=3;static START_LURCH_M=.015;static START_PITCH_DEG=1.2;static JOLT_HZ=1.4;static JOLT_DECAY_S=.35;static JOLT_LASTS_MS=1500;static STILL=Object.freeze({eastM:0,northM:0,upM:0,rollDeg:0,pitchDeg:0,yawDeg:0});static of(e){const t=wr.of(e);if(!t||t.points.length<2)return;const i=[];let n=0;for(let s=1;s<t.points.length;s++){const a=t.points[s-1],o=t.points[s],c=(o.t-a.t)/1e3;if(c<=0)continue;const l=ni(o.lat,o.lng,a.lat,a.lng),h=l.x,u=-l.z,d=Math.hypot(h,u),f=d/c,p=xt.stepHzFor(f);i.push({startMs:a.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 a=i[s-1],o=i[s+1];i[s].rampsIn=a===void 0||a.stepHz===0,i[s].rampsOut=o===void 0||o.stepHz===0}if(i.some(s=>s.stepHz>0))return new xt(i,1-(e.instrument.stabilization??0))}static bodyAt(e,t,i=!1){const n=xt.of(e)?.offsetAt(t)??xt.STILL;return i?n:xt.add(n,gn.of(e)?.offsetAt(t))}static stepHzFor(e){return e<xt.SLOWEST_WALK_M_PER_S||e>xt.FASTEST_WALK_M_PER_S?0:xt.REFERENCE_STEP_HZ*Math.pow(e/xt.REFERENCE_SPEED_M_PER_S,xt.CADENCE_EXPONENT)}offsetAt(e){return xt.add(this.cycleAt(e),this.joltAt(e))}joltAt(e){for(const t of this.stretches){if(t.stepHz===0)continue;const i=t.speedMPerS/xt.REFERENCE_SPEED_M_PER_S,n=(o,c,l,h)=>{if(o<0||o>xt.JOLT_LASTS_MS)return;const u=o/1e3,d=Math.exp(-u/xt.JOLT_DECAY_S)*Math.sin(2*Math.PI*xt.JOLT_HZ*u),f=h*c*i*d;return{eastM:f*t.eastUnit,northM:f*t.northUnit,upM:-Math.abs(f)*.3,rollDeg:0,pitchDeg:-h*l*i*d*this.rotationPassed,yawDeg:0}},s=t.rampsOut?n(e-t.endMs,xt.STOP_LURCH_M,xt.STOP_PITCH_DEG,1):void 0;if(s)return s;const a=t.rampsIn?n(e-t.startMs,xt.START_LURCH_M,xt.START_PITCH_DEG,-1):void 0;if(a)return a}}static add(e,t){return t?{eastM:e.eastM+t.eastM,northM:e.northM+t.northM,upM:e.upM+t.upM,rollDeg:e.rollDeg+t.rollDeg,pitchDeg:e.pitchDeg+t.pitchDeg,yawDeg:e.yawDeg+t.yawDeg}:e}cycleAt(e){const t=this.stretches.find(c=>e>=c.startMs&&e<=c.endMs);if(!t||t.stepHz===0)return xt.STILL;const i=t.stepsBefore+t.stepHz*(e-t.startMs)/1e3,n=2*Math.PI*i,s=this.amplitudeAt(t,e),a=xt.SWAY_M*s*Math.cos(n/2),o=s*this.rotationPassed*t.speedMPerS/xt.REFERENCE_SPEED_M_PER_S;return{eastM:a*t.northUnit,northM:-a*t.eastUnit,upM:xt.RISE_M_PER_M_PER_S*t.speedMPerS*s*Math.cos(n),rollDeg:xt.HEAD_ROLL_DEG*o*Math.cos(n/2),pitchDeg:-1.25*o*Math.cos(n),yawDeg:xt.HEAD_YAW_DEG*o*Math.cos(n/2)}}amplitudeAt(e,t){const i=1e3/e.stepHz,n=Math.min(i,(e.endMs-e.startMs)/2);if(n<=0)return 1;const s=t-e.startMs,a=e.endMs-t,o=Math.min(e.rampsIn?s/n:1,e.rampsOut?a/n:1,1);return(1-Math.cos(Math.PI*Math.max(o,0)))/2}}class n2{constructor(e,t){this.timeline=e,this.onFrame=t}rafId=null;state="stopped";currentT=0;lastWallTime=0;playbackRate=1;loop=!1;onEnded;durationOverrideMs=0;get seekableDuration(){return Math.max(this.timeline.duration,this.durationOverrideMs)}play(){if(this.state==="playing")return;this.currentT>=this.seekableDuration&&(this.currentT=0,this.resolveFrame(0)),this.state="playing",this.lastWallTime=performance.now();const e=()=>{if(this.state!=="playing")return;const t=performance.now();if(this.currentT+=(t-this.lastWallTime)*this.playbackRate,this.lastWallTime=t,this.currentT>=this.seekableDuration){if(this.loop&&this.seekableDuration>0){this.currentT%=this.seekableDuration,this.resolveFrame(this.currentT),this.rafId=requestAnimationFrame(e);return}this.currentT=this.seekableDuration,this.stop(),this.resolveFrame(this.currentT),this.onEnded?.();return}this.resolveFrame(this.currentT),this.rafId=requestAnimationFrame(e)};this.rafId=requestAnimationFrame(e)}pause(){this.state==="playing"&&(this.state="paused",this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null))}stop(){this.state="stopped",this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null)}seek(e){this.currentT=Math.max(0,Math.min(e,this.seekableDuration)),this.resolveFrame(this.currentT)}get playbackState(){return this.state}get time(){return this.currentT}resolveFrame(e){const t=new Map;for(const i of this.timeline.sourceIds){const n=this.timeline.getInterpolatedShapeAt(e,i);n&&t.set(i,n)}this.onFrame(e,t)}}const Eg=["nw","n","ne","e","se","s","sw","w"],s2=24,sc=8,a2=3,r2=8;function ac(r,e,t){const i=r.x-e.x,n=r.y-e.y,s=Math.cos(t),a=Math.sin(t);return{x:e.x+i*s-n*a,y:e.y+i*a+n*s}}function qr(r){return{x:r.x+r.width/2,y:r.y+r.height/2}}const o2={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 ln{static handlePointsFor(e){const{x:t,y:i,width:n,height:s}=e.bounds,a={nw:{x:t,y:i},n:{x:t+n/2,y:i},ne:{x:t+n,y:i},e:{x:t+n,y:i+s/2},se:{x:t+n,y:i+s},s:{x:t+n/2,y:i+s},sw:{x:t,y:i+s},w:{x:t,y:i+s/2},rotate:{x:t+n/2,y:i-s2}},o=qr(e.bounds),c={};for(const l of Object.keys(a))c[l]=ac(a[l],o,e.angle);return c}static hitTestHandle(e,t,i=8,n=[...Eg,"rotate"]){const s=ln.handlePointsFor(e);for(const a of n)if(Math.hypot(t.x-s[a].x,t.y-s[a].y)<=i)return a}static HANDLE_DIRECTION_DEG={e:0,se:45,s:90,sw:135,w:180,nw:225,n:270,ne:315};static resizeAxisFor(e,t){const n=((ln.HANDLE_DIRECTION_DEG[e]+t*180/Math.PI)%180+180)%180/45,s=["ew","nwse","ns","nesw"];return s[Math.round(n)%s.length]}static resizeBounds(e,t,i,n){const s=qr(e),a=ac(n,s,-t),{x:o,y:c,width:l,height:h}=e,u=o2[i];let d=o,f=c,p=o+l,v=c+h;return u.left&&(d=Math.min(a.x,p-sc)),u.right&&(p=Math.max(a.x,d+sc)),u.top&&(f=Math.min(a.y,v-sc)),u.bottom&&(v=Math.max(a.y,f+sc)),{x:d,y:f,width:p-d,height:v-f}}static resizeShape(e,t,i){if(t==="rotate")throw new Error("resizeShape does not accept the rotate handle");const{width:n,height:s}=e.bounds,a=ln.resizeBounds(e.bounds,e.angle,t,i);if(e.kind==="oval")return{...e,bounds:a};const o=n===0?1:a.width/n,c=s===0?1:a.height/s;return{...e,bounds:a,points:e.points.map(l=>({x:l.x*o,y:l.y*c}))}}static rotateShape(e,t){const i=qr(e.bounds),n=Math.atan2(t.y-i.y,t.x-i.x)+Math.PI/2;return{...e,angle:n}}static groupBoundsFor(e){const t=Math.min(...e.map(a=>a.x)),i=Math.min(...e.map(a=>a.y)),n=Math.max(...e.map(a=>a.x+a.width)),s=Math.max(...e.map(a=>a.y+a.height));return{x:t,y:i,width:n-t,height:s-i}}static vertexPointsFor(e){const t=qr(e.bounds);return e.points.map(i=>ac({x:e.bounds.x+i.x,y:e.bounds.y+i.y},t,e.angle))}static hitTestVertex(e,t,i=r2){const n=ln.vertexPointsFor(e);let s,a=i;return n.forEach((o,c)=>{const l=Math.hypot(t.x-o.x,t.y-o.y);l<=a&&(a=l,s=c)}),s}static toLocalPoint(e,t){const i=qr(e.bounds),n=ac(t,i,-e.angle);return{x:n.x-e.bounds.x,y:n.y-e.bounds.y}}static moveVertex(e,t,i){const n=e.points.map((u,d)=>d===t?ln.toLocalPoint(e,i):u),s=Math.min(...n.map(u=>u.x)),a=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:e.bounds.x+s,y:e.bounds.y+a,width:o-s,height:c-a},h=n.map(u=>({x:u.x-s,y:u.y-a}));return{...e,bounds:l,points:h}}static insertVertexNear(e,t){const i=ln.toLocalPoint(e,t),{points:n}=e;let s=n.length-1,a=1/0;for(let c=0;c<n.length;c++){const l=n[c],h=n[(c+1)%n.length],u=ln.distanceToSegment(i,l,h);u<a&&(a=u,s=c)}const o=[...n.slice(0,s+1),i,...n.slice(s+1)];return{...e,points:o}}static distanceToSegment(e,t,i){const n=i.x-t.x,s=i.y-t.y,a=n*n+s*s,o=a===0?0:Math.max(0,Math.min(1,((e.x-t.x)*n+(e.y-t.y)*s)/a)),c=t.x+o*n,l=t.y+o*s;return Math.hypot(e.x-c,e.y-l)}static deleteVertex(e,t){return e.points.length<=a2?e:{...e,points:e.points.filter((i,n)=>n!==t)}}}const Pu=6,rc=Pu/2,bf=20,_f=24,Sf=9,wf=6,Ef=7,Af=6,Wn=4;class zo{constructor(e){this.ctx=e}starPoints=0;roll=0;clear(e,t){this.ctx.clearRect(0,0,e,t)}static paintExtent(e){const{x:t,y:i,width:n,height:s}=e.bounds,a=t+n/2,o=i+s/2,c=e.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=e.brightness??0,p=f>0?Math.max(d*(1+Sf*f),Af*f)-d:0,v=f>0?d*(1+Ef*f)-d:0,m=3*_f*(e.blur??0)+1.5*bf*e.haloScale,g=Math.max(p,v,0)+m+2;return{x:a-h-g,y:o-u-g,width:2*(h+g),height:2*(u+g)}}paintInto(e,t,i,n=!1){this.ctx.save(),this.ctx.scale(i,i),this.ctx.translate(-t.x,-t.y);const s=e.selected?{...e,selected:!1}:e;n?this.paintGhost(s,1.5):this.paintShape(s),this.ctx.restore()}paintShape(e){this.ctx.save(),this.ctx.globalAlpha=1-e.transparency;const t=e.blur??0;t>0&&(this.ctx.filter=`blur(${(_f*t).toFixed(2)}px)`);const i=e.brightness??0;i>0&&this.paintDazzle(e,i),e.haloScale>0&&this.paintHalo(e),this.paintBase(e),this.ctx.restore(),e.selected&&this.paintSelectionHandles(e)}setStarPoints(e){this.starPoints=Math.max(0,Math.floor(e))}setRoll(e){this.roll=e}paintDazzle(e,t){const{x:i,y:n,width:s,height:a}=e.bounds,o=i+s/2,c=n+a/2,l=Math.max(s,a)/2,h=Math.max(l*(1+Sf*t),Af*t);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<=wf;d++){const f=d/wf,p=1/(1+24*f*f);this.ctx.globalAlpha=1,u.addColorStop(f,this.withAlpha(e.color,p*t*.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+Ef*t);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(e.color,t*.55)),g.addColorStop(.35,this.withAlpha(e.color,t*.22)),g.addColorStop(1,this.withAlpha(e.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(e,t){if(t<=0)return e.color;const i=/^#([0-9a-f]{6})$/i.exec(e.color.trim());if(!i)return e.color;const n=Number.parseInt(i[1],16),s=a=>Math.round(a+(255-a)*t);return`rgb(${s(n>>16&255)}, ${s(n>>8&255)}, ${s(n&255)})`}withAlpha(e,t){const i=Math.max(0,Math.min(1,t)),n=/^#([0-9a-f]{6})$/i.exec(e.trim());if(!n)return e;const s=Number.parseInt(n[1],16);return`rgba(${s>>16&255}, ${s>>8&255}, ${s&255}, ${i.toFixed(3)})`}paintBase(e){this.ctx.fillStyle=this.dazzledFill(e,e.brightness??0),this.tracePath(e),this.ctx.fill()}paintGhost(e,t){this.ctx.save(),this.tracePath(e),this.ctx.setLineDash([t*3,t*2]),this.ctx.lineWidth=t,this.ctx.strokeStyle=e.color,this.ctx.stroke(),this.ctx.restore()}tracePath(e){if(this.ctx.beginPath(),e.kind==="oval"){const{x:t,y:i,width:n,height:s}=e.bounds,a=n/2,o=s/2;this.ctx.ellipse(t+a,i+o,a,o,e.angle,0,2*Math.PI)}else{const{x:t,y:i,width:n,height:s}=e.bounds;this.ctx.save(),this.ctx.translate(t+n/2,i+s/2),this.ctx.rotate(e.angle),this.ctx.translate(-n/2,-s/2),e.points.forEach((a,o)=>{o===0?this.ctx.moveTo(a.x,a.y):this.ctx.lineTo(a.x,a.y)}),this.ctx.closePath(),this.ctx.restore()}}paintHalo(e){this.ctx.save(),this.ctx.shadowColor=e.color,this.ctx.shadowBlur=bf*e.haloScale,this.paintBase(e),this.ctx.restore()}paintSelectionHandles(e){this.paintHandleFrame(ln.handlePointsFor(e),{includeRotate:!0}),e.kind==="polygon"&&this.paintVertexHandles(e)}paintVertexHandles(e){this.ctx.fillStyle="#39f";for(const t of ln.vertexPointsFor(e))this.ctx.beginPath(),this.ctx.ellipse(t.x,t.y,Wn,Wn,0,0,2*Math.PI),this.ctx.fill()}paintMemberOutline(e){this.paintOutline(ln.handlePointsFor(e))}paintSelectionOnly(e){this.paintSelectionHandles(e)}paintPictureFrame(e,t,i){const n=this.ctx;if(n.save(),e&&e.length===4){n.strokeStyle="#39f",n.lineWidth=1.5,n.setLineDash([6,4]),n.beginPath(),n.moveTo(e[0].x,e[0].y);for(const s of e.slice(1))n.lineTo(s.x,s.y);n.closePath(),n.stroke(),n.setLineDash([])}for(const s of t){const a=zo.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,Wn+2,Wn+2,0,0,2*Math.PI),n.stroke()),s.scene&&(n.strokeStyle=a,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=a,n.beginPath(),n.ellipse(s.scene.x,s.scene.y,Wn,Wn,0,0,2*Math.PI),n.fill()),n.strokeStyle=a,n.lineWidth=o,n.beginPath(),n.ellipse(s.picture.x,s.picture.y,Wn+2,Wn+2,0,0,2*Math.PI),n.stroke(),this.paintLabel(s.label,s.picture.x+Wn+5,s.picture.y-Wn-2,a)}i&&this.paintLabel(i,8,8,"#fff",13),n.restore()}static landmarkColour(e){return e===void 0?"#ffb000":e<=1?"#3c3":e<=3?"#ffb000":"#f33"}paintLabel(e,t,i,n,s=11){const a=this.ctx;a.save(),a.font=`${s}px system-ui, sans-serif`,a.textBaseline="top";const o=a.measureText(e).width;a.fillStyle="rgba(0, 0, 0, 0.6)",a.fillRect(t-3,i-2,o+6,s+4),a.fillStyle=n,a.fillText(e,t,i),a.restore()}paintGroupHandles(e){this.paintHandleFrame(ln.handlePointsFor({bounds:e,angle:0}),{includeRotate:!0})}paintOutline(e){this.ctx.strokeStyle="lightgray",this.ctx.beginPath(),this.ctx.moveTo(e.nw.x,e.nw.y),this.ctx.lineTo(e.ne.x,e.ne.y),this.ctx.lineTo(e.se.x,e.se.y),this.ctx.lineTo(e.sw.x,e.sw.y),this.ctx.closePath(),this.ctx.stroke()}paintHandleFrame(e,{includeRotate:t}){this.paintOutline(e),this.ctx.fillStyle="lightgray";for(const i of Eg){const n=e[i];this.ctx.fillRect(n.x-rc,n.y-rc,Pu,Pu)}t&&(this.ctx.beginPath(),this.ctx.moveTo(e.n.x,e.n.y),this.ctx.lineTo(e.rotate.x,e.rotate.y),this.ctx.stroke(),this.ctx.beginPath(),this.ctx.ellipse(e.rotate.x,e.rotate.y,rc+1,rc+1,0,0,2*Math.PI),this.ctx.fill())}}const Tf=.05,Rf=.08,Df=2,If=3,c2=14,l2=.02;class h2{context;voice;voiceToken=0;buffers=new Map;noiseBuffer;crackleBuffer;requested;resume(){if(!this.context){if(typeof AudioContext>"u")return;try{this.context=new AudioContext}catch(e){console.warn("SightingAudio: Web Audio unavailable, the sighting stays silent:",e);return}}this.context.state==="suspended"&&this.context.resume()}setSound(e){if(this.requested=e,!this.context)return;const t=this.keyFor(e);if(!t){this.silence();return}if(this.voice?.key!==t){this.stopVoice();const i=++this.voiceToken;t.startsWith("src:")?this.buildRecordedVoice(e.src,t,i):this.voice=this.buildSynthesizedVoice(e,t)}this.applyTo(this.voice,e)}silence(){this.voiceToken++,this.stopVoice()}dispose(){this.silence(),this.context?.close(),this.context=void 0,this.buffers.clear(),this.noiseBuffer=void 0,this.crackleBuffer=void 0}keyFor(e){if(!(e.volume<=0))return e.src?`src:${e.src}`:e.kind==="none"?void 0:e.kind}applyTo(e,t){const i=this.context;if(!e||!i)return;const n=i.currentTime;e.volumeParam.setTargetAtTime(Math.max(0,Math.min(1,t.volume))*e.gainScale,n,Tf);for(const{param:s,ratio:a}of e.pitch)s.setTargetAtTime(Math.min(t.pitchHz*a,i.sampleRate/2-1),n,Tf)}buildSynthesizedVoice(e,t){const i=this.context;if(i)switch(e.kind){case"hum":return this.buildHum(i,t);case"whistle":return this.buildWhistle(i,t);case"rumble":return this.buildRumble(i,t);case"crackle":return this.buildCrackle(i,t);default:return}}buildHum(e,t){const i=e.createOscillator();i.type="sawtooth";const n=e.createOscillator();n.type="sawtooth";const s=e.createBiquadFilter();s.type="lowpass",s.Q.value=1;const a=e.createGain();return a.gain.value=0,i.connect(s),n.connect(s),s.connect(a).connect(e.destination),i.start(),n.start(),{key:t,nodes:[s,a],sources:[i,n],volumeParam:a.gain,gainScale:.16,pitch:[{param:i.frequency,ratio:1},{param:n.frequency,ratio:1.006},{param:s.frequency,ratio:6}]}}buildWhistle(e,t){const i=e.createOscillator();i.type="sine";const n=e.createOscillator();n.type="sine",n.frequency.value=5;const s=e.createGain(),a=e.createGain();return a.gain.value=0,n.connect(s).connect(i.frequency),i.connect(a).connect(e.destination),i.start(),n.start(),{key:t,nodes:[s,a],sources:[i,n],volumeParam:a.gain,gainScale:.22,pitch:[{param:i.frequency,ratio:1},{param:s.gain,ratio:.012}]}}buildRumble(e,t){const i=e.createBufferSource();i.buffer=this.brownNoise(e),i.loop=!0;const n=e.createBiquadFilter();n.type="lowpass",n.Q.value=.8;const s=e.createGain();return s.gain.value=0,i.connect(n).connect(s).connect(e.destination),i.start(),{key:t,nodes:[n,s],sources:[i],volumeParam:s.gain,gainScale:1.4,pitch:[{param:n.frequency,ratio:1}]}}buildCrackle(e,t){const i=e.createBufferSource();i.buffer=this.whiteNoise(e),i.loop=!0;const n=e.createBiquadFilter();n.type="bandpass",n.Q.value=1.2;const s=e.createGain();s.gain.value=0;const a=e.createBufferSource();a.buffer=this.crackleEnvelope(e),a.loop=!0;const o=e.createGain();return o.gain.value=0,a.connect(o).connect(s.gain),i.connect(n).connect(s).connect(e.destination),i.start(),a.start(),{key:t,nodes:[n,s,o],sources:[i,a],volumeParam:o.gain,gainScale:.9,pitch:[{param:n.frequency,ratio:4}]}}async buildRecordedVoice(e,t,i){const n=this.context;if(!n)return;let s;try{s=await this.getBuffer(e)}catch(c){console.warn("SightingAudio: the recorded sound failed to load, staying silent:",c);return}if(i!==this.voiceToken||!this.context)return;const a=n.createBufferSource();a.buffer=s,a.loop=!0;const o=n.createGain();o.gain.value=0,a.connect(o).connect(n.destination),a.start(),this.voice={key:t,nodes:[o],sources:[a],volumeParam:o.gain,gainScale:1,pitch:[]},this.requested&&this.applyTo(this.voice,this.requested)}async getBuffer(e){const t=this.context;if(!t)throw new Error("SightingAudio: AudioContext not ready — resume() must be called first");let i=this.buffers.get(e);return i||(i=fetch(e).then(n=>{if(!n.ok)throw new Error(`Audio fetch failed (${n.status}): ${e}`);return n.arrayBuffer()}).then(n=>t.decodeAudioData(n)),this.buffers.set(e,i)),i}whiteNoise(e){if(!this.noiseBuffer){const t=e.createBuffer(1,Math.floor(e.sampleRate*Df),e.sampleRate),i=t.getChannelData(0);for(let n=0;n<i.length;n++)i[n]=Math.random()*2-1;this.noiseBuffer=t}return this.noiseBuffer}brownNoise(e){const t=e.createBuffer(1,Math.floor(e.sampleRate*Df),e.sampleRate),i=t.getChannelData(0);let n=0,s=0;for(let a=0;a<i.length;a++)n=(n+.02*(Math.random()*2-1))/1.02,i[a]=n,s=Math.max(s,Math.abs(n));if(s>0)for(let a=0;a<i.length;a++)i[a]/=s;return t}crackleEnvelope(e){if(!this.crackleBuffer){const t=e.createBuffer(1,Math.floor(e.sampleRate*If),e.sampleRate),i=t.getChannelData(0),n=Math.max(1,Math.floor(l2*e.sampleRate)),s=Math.round(If*c2);for(let a=0;a<s;a++){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=t}return this.crackleBuffer}stopVoice(){const e=this.voice,t=this.context;if(this.voice=void 0,!e||!t)return;const i=t.currentTime;e.volumeParam.cancelScheduledValues(i),e.volumeParam.setTargetAtTime(0,i,Rf/3);const n=i+Rf;for(const s of e.sources){s.onended=()=>{s.disconnect();for(const a of e.nodes)a.disconnect()};try{s.stop(n)}catch{s.disconnect();for(const a of e.nodes)a.disconnect()}}}}function xl(r){return[...r].sort((e,t)=>e.t-t.t)}function Cf(r,e){let t;for(const i of xl(r)){if(i.t>e)break;t=i}return t}const ch=Math.PI/180,oc=180/Math.PI;class Ss{constructor(e,t,i){this.kind=e,this.canvasHeightPx=t,this.fovDeg=i;const n=i*ch/2;this.focalPx=e==="equidistant"?t/2/n:t/2/Math.tan(n)}focalPx;static of(e,t,i){return new Ss(e.projection,t,i)}degToPx(e){const t=e*ch;return this.kind==="equidistant"?this.focalPx*t:2*this.focalPx*Math.tan(t/2)}pxToDeg(e){return this.kind==="equidistant"?e/this.focalPx*oc:2*Math.atan(e/(2*this.focalPx))*oc}angleDegToRadiusPx(e){const t=e*ch;return this.kind==="equidistant"?this.focalPx*t:this.focalPx*Math.tan(t)}halfWidthAngleDeg(e){return this.radiusPxToAngleDeg(this.canvasHeightPx*e/2)}radiusPxToAngleDeg(e){return this.kind==="equidistant"?e/this.focalPx*oc:Math.atan(e/this.focalPx)*oc}ofBounds(e){return{widthDeg:this.pxToDeg(e.width),heightDeg:this.pxToDeg(e.height)}}toBoundsSize(e){return{width:this.degToPx(e.widthDeg),height:this.degToPx(e.heightDeg)}}widthPx(e){return this.degToPx(Et.angularWidthDeg(e))}}class ji{static fovOf(e,t){return jt(e,t)?.fovDeg??si.fieldOfViewDeg(e.instrument)}static toAngular(e){this.eachKeyframe(e,(t,i)=>({...t,angular:i.ofBounds(t.bounds)}))}static toBounds(e){this.eachKeyframe(e,(t,i)=>{if(!t.angular)return t;const{width:n,height:s}=i.toBoundsSize(t.angular),a={x:t.bounds.x+(t.bounds.width-n)/2,y:t.bounds.y+(t.bounds.height-s)/2,width:n,height:s};if(t.kind!=="polygon")return{...t,bounds:a};const o=t.bounds.width===0?1:n/t.bounds.width,c=t.bounds.height===0?1:s/t.bounds.height;return{...t,bounds:a,points:t.points.map(l=>({x:l.x*o,y:l.y*c}))}})}static toAim(e){this.eachKeyframe(e,(t,i,n)=>{const s=t.aim&&this.positionOf(e,t.aim,t.bounds,i,n);if(s&&Math.abs(s.x-t.bounds.x)<ji.UNMOVED_PX&&Math.abs(s.y-t.bounds.y)<ji.UNMOVED_PX)return t;const a=this.aimFrom(e,i,n,t.bounds);return a?{...t,aim:a}:t})}static UNMOVED_PX=.01;static aimOf(e,t,i){const n=Ss.of(e.instrument,Et.CANVAS_HEIGHT_PX,this.fovOf(e,t));return this.aimFrom(e,n,jt(e,t),i)}static aimFrom(e,t,i,n){if(i?.headingDeg===void 0)return;const s=this.frameCentre(e),a=t.radiusPxToAngleDeg(n.x+n.width/2-s.x),o=t.radiusPxToAngleDeg(s.y-(n.y+n.height/2));return{azimuthDeg:((i.headingDeg+a)%360+360)%360,altitudeDeg:i.pitchDeg+o}}static toPosition(e){this.eachKeyframe(e,(t,i,n)=>{const s=t.aim&&this.positionOf(e,t.aim,t.bounds,i,n);return s?{...t,bounds:{...t.bounds,...s}}:t})}static positionOf(e,t,i,n,s){if(s?.headingDeg===void 0)return;const a=this.frameCentre(e),o=this.shortestArc(t.azimuthDeg-s.headingDeg),c=t.altitudeDeg-s.pitchDeg;return{x:a.x+this.offAxisPx(n,o)-i.width/2,y:a.y-this.offAxisPx(n,c)-i.height/2}}static frameCentre(e){return{x:si.frameWidthPx(e.instrument,Et.CANVAS_HEIGHT_PX)/2,y:Et.CANVAS_HEIGHT_PX/2}}static shortestArc(e){return(e%360+540)%360-180}static offAxisPx(e,t){return Math.abs(t)>=ji.OFF_CANVAS_DEG?Math.sign(t)*ji.OFF_CANVAS_PX:e.angleDegToRadiusPx(t)}static OFF_CANVAS_DEG=89;static OFF_CANVAS_PX=1e5;static reproject(e,t,i){const n=si.frameWidthPx(t,Et.CANVAS_HEIGHT_PX)/2,s=si.frameWidthPx(e.instrument,Et.CANVAS_HEIGHT_PX)/2,a=Et.CANVAS_HEIGHT_PX/2;for(const o of[...e.timeline.allKeyframes]){const c=this.fovOf(e,o.t),l=i?.get(o.t)??c,h=Ss.of(t,Et.CANVAS_HEIGHT_PX,l),u=Ss.of(e.instrument,Et.CANVAS_HEIGHT_PX,c);e.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-a,m=Math.hypot(p,v),g=m===0?1:u.angleDegToRadiusPx(h.radiusPxToAngleDeg(m))/m,_={...f,x:s+p*g-f.width/2,y:a+v*g-f.height/2};return{...d,shape:{...d.shape,bounds:_}}}))}this.toBounds(e)}static eachKeyframe(e,t){const{timeline:i}=e;for(const n of[...i.allKeyframes]){const s=jt(e,n.t),a=this.fovOf(e,n.t),o=Ss.of(e.instrument,Et.CANVAS_HEIGHT_PX,a);i.addKeyframe(n.t,n.shapes.map(c=>({...c,shape:t(c.shape,o,s)})))}}}function u2(r){return Zi.restore(d2(r),r.provenance)}function d2(r){return ji.toAngular(r),ji.toAim(r),{version:1,id:r.id,time:r.event.time,endTime:r.event.endTime,durationSeconds:r.event.durationSeconds,utcOffsetHours:r.event.utcOffsetHours,timeZone:r.event.timeZone,place:r.event.place,observer:r.observer,account:r.account,sources:r.sources?.length?r.sources:void 0,sway:r.sway,vehicle:r.vehicle,description:r.event.description,tags:r.event.tags,timeline:r.timeline.toJSON(),observerTrack:r.observerTrack.toJSON(),weatherTrack:r.weatherTrack.toJSON(),soundTrack:r.soundTrack.toJSON(),weather:r.weather,decor:r.decor,milestones:r.milestones.length>0?r.milestones:void 0,references:r.references.length>0?r.references:void 0,roads:r.roads.length>0?r.roads:void 0,weatherSource:r.weatherSource,instrument:r.instrumentId,exposureSeconds:r.exposureSeconds,iso:r.iso,lightPollution:r.lightPollution,interpretation:r.interpretation}}function f2(r){const{recording:e,provenance:t}=Zi.strip(r),i=p2(e);return i.provenance=t,i}function p2(r){const e=[],t=new Wl({eventType:"sighting",time:r.time,endTime:r.endTime,durationSeconds:r.durationSeconds,utcOffsetHours:r.utcOffsetHours,timeZone:r.timeZone,place:r.place,description:r.description,tags:r.tags},Vl.fromJSON(r.timeline,e),r.observerTrack?No.fromJSON(r.observerTrack):new No,r.weatherTrack?Fo.fromJSON(r.weatherTrack):new Fo,r.soundTrack?Uo.fromJSON(r.soundTrack):new Uo,r.observer&&{id:r.observer.id,title:r.observer.title,lastName:r.observer.lastName,firstNames:r.observer.firstNames},r.id,r.weather,r.decor??[],r.weatherSource,r.instrument,r.exposureSeconds??r.observerTrack?.keyframes.map(i=>i.pose.exposureSeconds).find(i=>i!==void 0),xl(r.milestones??[]),r.references??[],r.roads??[]);return t.account=r.account,t.sources=r.sources,t.sway=r.sway,t.iso=r.iso,t.lightPollution=r.lightPollution,t.vehicle=r.vehicle,t.interpretation=r.interpretation,t.loadIssues=e,ji.toBounds(t),ji.toPosition(t),t}class Nr{static EN={"unknown-key":"{path}: unknown key, ignored","wrong-type":"{path}: expected {expected}, found {found}","not-in-list":"{path}: {found} is not one of {expected}",defaulted:"{path}: missing, {expected} used",unplaced:"{path}: no aim (and no bounds), drawn at the middle of the view",unsized:"{path}: no angular size (and no bounds), drawn one pixel wide","pixels-over-angles":"{path}: bounds restated without aim or angular, so the shape follows the pixels"};static text(e,t=Nr.EN){return t[e.kind].replace("{path}",e.path).replace("{expected}",e.expected??"").replace("{found}",e.found??"")}static warn(e,t){if(e.length===0)return;const i=e.map(n=>` ${Nr.text(n)}`);console.warn(`UFO@home: ${e.length} problem(s) in ${t??"this recording"}:
|
|
1299
|
+
`;class wr{constructor(e){this.points=e}static STATIONARY_M=5;static of(e){const t=[];for(const i of e.observerTrack.allKeyframes){const{lat:n,lng:s,headingDeg:a}=i.pose;n===void 0||s===void 0||t.push({t:i.t,lat:n,lng:s,headingDeg:a})}if(t.length===0){const i=e.event.place?.[0];if(!i)return;t.push({t:0,lat:i.lat,lng:i.lng})}return new wr(t)}static TRAVEL_M=50;get travels(){return this.spanM>wr.TRAVEL_M}get moved(){return this.spanM>wr.STATIONARY_M}get spanM(){const e=this.box,t=(e.south+e.north)/2,i=(e.west+e.east)/2;return Math.max(Math.abs(ni(t,e.east,t,e.west).x),Math.abs(ni(e.north,i,e.south,i).z))}get center(){const e=this.box;return{lat:(e.south+e.north)/2,lng:(e.west+e.east)/2}}boundsAround(e,t){const{lat:i,lng:n}=this.center,s=Math.max(this.spanM*(1+t),e)/2;return{north:_s(0,-s,i,n).lat,south:_s(0,s,i,n).lat,east:_s(s,0,i,n).lng,west:_s(-s,0,i,n).lng}}get box(){const e=this.points.map(i=>i.lat),t=this.points.map(i=>i.lng);return{south:Math.min(...e),north:Math.max(...e),west:Math.min(...t),east:Math.max(...t)}}}class gn{constructor(e,t){this.rotationPassed=e,this.scale=t}static SWAY_M=.012;static BREATH_M=.003;static DRIFT_YAW_DEG=.5;static DRIFT_PITCH_DEG=.4;static DRIFT_ROLL_DEG=.3;static GAZE_DRIFT_SHARE=.35;static HAND_HELD_S=.5;static HZ=[.11,.23,.17,.29,.37,.07];static of(e){const t=e.event.tags?.includes("paralysis")||(e.exposure??0)>gn.HAND_HELD_S,i=e.sway??(t?0:1);if(i>0)return new gn(Math.max(1-(e.instrument.stabilization??0),gn.GAZE_DRIFT_SHARE),i)}offsetAt(e){const t=e/1e3,i=this.scale,n=(u,d)=>Math.sin(2*Math.PI*u*t+d),[s,a,o,c,l,h]=gn.HZ;return{eastM:i*gn.SWAY_M*(.7*n(s,.3)+.3*n(c,1.9)),northM:i*gn.SWAY_M*(.6*n(o,2.2)+.4*n(l,.8)),upM:i*gn.BREATH_M*n(a,0),yawDeg:i*this.rotationPassed*gn.DRIFT_YAW_DEG*(.6*n(h,1.1)+.4*n(c,2.7)),pitchDeg:i*this.rotationPassed*gn.DRIFT_PITCH_DEG*(.5*n(a,1.6)+.5*n(o,.4)),rollDeg:i*this.rotationPassed*gn.DRIFT_ROLL_DEG*n(s,2.9)}}}class xt{constructor(e,t){this.stretches=e,this.rotationPassed=t}static REFERENCE_SPEED_M_PER_S=1.4;static REFERENCE_STEP_HZ=1.9;static CADENCE_EXPONENT=.43;static RISE_M_PER_M_PER_S=.0175;static SWAY_M=.0175;static SLOWEST_WALK_M_PER_S=.2;static FASTEST_WALK_M_PER_S=2.2;static HEAD_ROLL_DEG=1.5;static HEAD_PITCH_DEG=1.25;static HEAD_YAW_DEG=1;static STOP_LURCH_M=.035;static STOP_PITCH_DEG=3;static START_LURCH_M=.015;static START_PITCH_DEG=1.2;static JOLT_HZ=1.4;static JOLT_DECAY_S=.35;static JOLT_LASTS_MS=1500;static STILL=Object.freeze({eastM:0,northM:0,upM:0,rollDeg:0,pitchDeg:0,yawDeg:0});static of(e){const t=wr.of(e);if(!t||t.points.length<2)return;const i=[];let n=0;for(let s=1;s<t.points.length;s++){const a=t.points[s-1],o=t.points[s],c=(o.t-a.t)/1e3;if(c<=0)continue;const l=ni(o.lat,o.lng,a.lat,a.lng),h=l.x,u=-l.z,d=Math.hypot(h,u),f=d/c,p=xt.stepHzFor(f);i.push({startMs:a.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 a=i[s-1],o=i[s+1];i[s].rampsIn=a===void 0||a.stepHz===0,i[s].rampsOut=o===void 0||o.stepHz===0}if(i.some(s=>s.stepHz>0))return new xt(i,1-(e.instrument.stabilization??0))}static bodyAt(e,t,i=!1){const n=xt.of(e)?.offsetAt(t)??xt.STILL;return i?n:xt.add(n,gn.of(e)?.offsetAt(t))}static stepHzFor(e){return e<xt.SLOWEST_WALK_M_PER_S||e>xt.FASTEST_WALK_M_PER_S?0:xt.REFERENCE_STEP_HZ*Math.pow(e/xt.REFERENCE_SPEED_M_PER_S,xt.CADENCE_EXPONENT)}offsetAt(e){return xt.add(this.cycleAt(e),this.joltAt(e))}joltAt(e){for(const t of this.stretches){if(t.stepHz===0)continue;const i=t.speedMPerS/xt.REFERENCE_SPEED_M_PER_S,n=(o,c,l,h)=>{if(o<0||o>xt.JOLT_LASTS_MS)return;const u=o/1e3,d=Math.exp(-u/xt.JOLT_DECAY_S)*Math.sin(2*Math.PI*xt.JOLT_HZ*u),f=h*c*i*d;return{eastM:f*t.eastUnit,northM:f*t.northUnit,upM:-Math.abs(f)*.3,rollDeg:0,pitchDeg:-h*l*i*d*this.rotationPassed,yawDeg:0}},s=t.rampsOut?n(e-t.endMs,xt.STOP_LURCH_M,xt.STOP_PITCH_DEG,1):void 0;if(s)return s;const a=t.rampsIn?n(e-t.startMs,xt.START_LURCH_M,xt.START_PITCH_DEG,-1):void 0;if(a)return a}}static add(e,t){return t?{eastM:e.eastM+t.eastM,northM:e.northM+t.northM,upM:e.upM+t.upM,rollDeg:e.rollDeg+t.rollDeg,pitchDeg:e.pitchDeg+t.pitchDeg,yawDeg:e.yawDeg+t.yawDeg}:e}cycleAt(e){const t=this.stretches.find(c=>e>=c.startMs&&e<=c.endMs);if(!t||t.stepHz===0)return xt.STILL;const i=t.stepsBefore+t.stepHz*(e-t.startMs)/1e3,n=2*Math.PI*i,s=this.amplitudeAt(t,e),a=xt.SWAY_M*s*Math.cos(n/2),o=s*this.rotationPassed*t.speedMPerS/xt.REFERENCE_SPEED_M_PER_S;return{eastM:a*t.northUnit,northM:-a*t.eastUnit,upM:xt.RISE_M_PER_M_PER_S*t.speedMPerS*s*Math.cos(n),rollDeg:xt.HEAD_ROLL_DEG*o*Math.cos(n/2),pitchDeg:-1.25*o*Math.cos(n),yawDeg:xt.HEAD_YAW_DEG*o*Math.cos(n/2)}}amplitudeAt(e,t){const i=1e3/e.stepHz,n=Math.min(i,(e.endMs-e.startMs)/2);if(n<=0)return 1;const s=t-e.startMs,a=e.endMs-t,o=Math.min(e.rampsIn?s/n:1,e.rampsOut?a/n:1,1);return(1-Math.cos(Math.PI*Math.max(o,0)))/2}}class n2{constructor(e,t){this.timeline=e,this.onFrame=t}rafId=null;state="stopped";currentT=0;lastWallTime=0;playbackRate=1;loop=!1;onEnded;durationOverrideMs=0;get seekableDuration(){return Math.max(this.timeline.duration,this.durationOverrideMs)}play(){if(this.state==="playing")return;this.currentT>=this.seekableDuration&&(this.currentT=0,this.resolveFrame(0)),this.state="playing",this.lastWallTime=performance.now();const e=()=>{if(this.state!=="playing")return;const t=performance.now();if(this.currentT+=(t-this.lastWallTime)*this.playbackRate,this.lastWallTime=t,this.currentT>=this.seekableDuration){if(this.loop&&this.seekableDuration>0){this.currentT%=this.seekableDuration,this.resolveFrame(this.currentT),this.rafId=requestAnimationFrame(e);return}this.currentT=this.seekableDuration,this.stop(),this.resolveFrame(this.currentT),this.onEnded?.();return}this.resolveFrame(this.currentT),this.rafId=requestAnimationFrame(e)};this.rafId=requestAnimationFrame(e)}pause(){this.state==="playing"&&(this.state="paused",this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null))}stop(){this.state="stopped",this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null)}seek(e){this.currentT=Math.max(0,Math.min(e,this.seekableDuration)),this.resolveFrame(this.currentT)}get playbackState(){return this.state}get time(){return this.currentT}resolveFrame(e){const t=new Map;for(const i of this.timeline.sourceIds){const n=this.timeline.getInterpolatedShapeAt(e,i);n&&t.set(i,n)}this.onFrame(e,t)}}const Eg=["nw","n","ne","e","se","s","sw","w"],s2=24,sc=8,a2=3,r2=8;function ac(r,e,t){const i=r.x-e.x,n=r.y-e.y,s=Math.cos(t),a=Math.sin(t);return{x:e.x+i*s-n*a,y:e.y+i*a+n*s}}function qr(r){return{x:r.x+r.width/2,y:r.y+r.height/2}}const o2={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 ln{static handlePointsFor(e){const{x:t,y:i,width:n,height:s}=e.bounds,a={nw:{x:t,y:i},n:{x:t+n/2,y:i},ne:{x:t+n,y:i},e:{x:t+n,y:i+s/2},se:{x:t+n,y:i+s},s:{x:t+n/2,y:i+s},sw:{x:t,y:i+s},w:{x:t,y:i+s/2},rotate:{x:t+n/2,y:i-s2}},o=qr(e.bounds),c={};for(const l of Object.keys(a))c[l]=ac(a[l],o,e.angle);return c}static hitTestHandle(e,t,i=8,n=[...Eg,"rotate"]){const s=ln.handlePointsFor(e);for(const a of n)if(Math.hypot(t.x-s[a].x,t.y-s[a].y)<=i)return a}static HANDLE_DIRECTION_DEG={e:0,se:45,s:90,sw:135,w:180,nw:225,n:270,ne:315};static resizeAxisFor(e,t){const n=((ln.HANDLE_DIRECTION_DEG[e]+t*180/Math.PI)%180+180)%180/45,s=["ew","nwse","ns","nesw"];return s[Math.round(n)%s.length]}static resizeBounds(e,t,i,n){const s=qr(e),a=ac(n,s,-t),{x:o,y:c,width:l,height:h}=e,u=o2[i];let d=o,f=c,p=o+l,v=c+h;return u.left&&(d=Math.min(a.x,p-sc)),u.right&&(p=Math.max(a.x,d+sc)),u.top&&(f=Math.min(a.y,v-sc)),u.bottom&&(v=Math.max(a.y,f+sc)),{x:d,y:f,width:p-d,height:v-f}}static resizeShape(e,t,i){if(t==="rotate")throw new Error("resizeShape does not accept the rotate handle");const{width:n,height:s}=e.bounds,a=ln.resizeBounds(e.bounds,e.angle,t,i);if(e.kind==="oval")return{...e,bounds:a};const o=n===0?1:a.width/n,c=s===0?1:a.height/s;return{...e,bounds:a,points:e.points.map(l=>({x:l.x*o,y:l.y*c}))}}static rotateShape(e,t){const i=qr(e.bounds),n=Math.atan2(t.y-i.y,t.x-i.x)+Math.PI/2;return{...e,angle:n}}static groupBoundsFor(e){const t=Math.min(...e.map(a=>a.x)),i=Math.min(...e.map(a=>a.y)),n=Math.max(...e.map(a=>a.x+a.width)),s=Math.max(...e.map(a=>a.y+a.height));return{x:t,y:i,width:n-t,height:s-i}}static vertexPointsFor(e){const t=qr(e.bounds);return e.points.map(i=>ac({x:e.bounds.x+i.x,y:e.bounds.y+i.y},t,e.angle))}static hitTestVertex(e,t,i=r2){const n=ln.vertexPointsFor(e);let s,a=i;return n.forEach((o,c)=>{const l=Math.hypot(t.x-o.x,t.y-o.y);l<=a&&(a=l,s=c)}),s}static toLocalPoint(e,t){const i=qr(e.bounds),n=ac(t,i,-e.angle);return{x:n.x-e.bounds.x,y:n.y-e.bounds.y}}static moveVertex(e,t,i){const n=e.points.map((u,d)=>d===t?ln.toLocalPoint(e,i):u),s=Math.min(...n.map(u=>u.x)),a=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:e.bounds.x+s,y:e.bounds.y+a,width:o-s,height:c-a},h=n.map(u=>({x:u.x-s,y:u.y-a}));return{...e,bounds:l,points:h}}static insertVertexNear(e,t){const i=ln.toLocalPoint(e,t),{points:n}=e;let s=n.length-1,a=1/0;for(let c=0;c<n.length;c++){const l=n[c],h=n[(c+1)%n.length],u=ln.distanceToSegment(i,l,h);u<a&&(a=u,s=c)}const o=[...n.slice(0,s+1),i,...n.slice(s+1)];return{...e,points:o}}static distanceToSegment(e,t,i){const n=i.x-t.x,s=i.y-t.y,a=n*n+s*s,o=a===0?0:Math.max(0,Math.min(1,((e.x-t.x)*n+(e.y-t.y)*s)/a)),c=t.x+o*n,l=t.y+o*s;return Math.hypot(e.x-c,e.y-l)}static deleteVertex(e,t){return e.points.length<=a2?e:{...e,points:e.points.filter((i,n)=>n!==t)}}}const Pu=6,rc=Pu/2,bf=20,_f=24,Sf=9,wf=6,Ef=7,Af=6,Wn=4;class zo{constructor(e){this.ctx=e}starPoints=0;roll=0;clear(e,t){this.ctx.clearRect(0,0,e,t)}static paintExtent(e){const{x:t,y:i,width:n,height:s}=e.bounds,a=t+n/2,o=i+s/2,c=e.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=e.brightness??0,p=f>0?Math.max(d*(1+Sf*f),Af*f)-d:0,v=f>0?d*(1+Ef*f)-d:0,m=3*_f*(e.blur??0)+1.5*bf*e.haloScale,g=Math.max(p,v,0)+m+2;return{x:a-h-g,y:o-u-g,width:2*(h+g),height:2*(u+g)}}paintInto(e,t,i,n=!1){this.ctx.save(),this.ctx.scale(i,i),this.ctx.translate(-t.x,-t.y);const s=e.selected?{...e,selected:!1}:e;n?this.paintGhost(s,1.5):this.paintShape(s),this.ctx.restore()}paintShape(e){this.ctx.save(),this.ctx.globalAlpha=1-e.transparency;const t=e.blur??0;t>0&&(this.ctx.filter=`blur(${(_f*t).toFixed(2)}px)`);const i=e.brightness??0;i>0&&this.paintDazzle(e,i),e.haloScale>0&&this.paintHalo(e),this.paintBase(e),this.ctx.restore(),e.selected&&this.paintSelectionHandles(e)}setStarPoints(e){this.starPoints=Math.max(0,Math.floor(e))}setRoll(e){this.roll=e}paintDazzle(e,t){const{x:i,y:n,width:s,height:a}=e.bounds,o=i+s/2,c=n+a/2,l=Math.max(s,a)/2,h=Math.max(l*(1+Sf*t),Af*t);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<=wf;d++){const f=d/wf,p=1/(1+24*f*f);this.ctx.globalAlpha=1,u.addColorStop(f,this.withAlpha(e.color,p*t*.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+Ef*t);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(e.color,t*.55)),g.addColorStop(.35,this.withAlpha(e.color,t*.22)),g.addColorStop(1,this.withAlpha(e.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(e,t){if(t<=0)return e.color;const i=/^#([0-9a-f]{6})$/i.exec(e.color.trim());if(!i)return e.color;const n=Number.parseInt(i[1],16),s=a=>Math.round(a+(255-a)*t);return`rgb(${s(n>>16&255)}, ${s(n>>8&255)}, ${s(n&255)})`}withAlpha(e,t){const i=Math.max(0,Math.min(1,t)),n=/^#([0-9a-f]{6})$/i.exec(e.trim());if(!n)return e;const s=Number.parseInt(n[1],16);return`rgba(${s>>16&255}, ${s>>8&255}, ${s&255}, ${i.toFixed(3)})`}paintBase(e){this.ctx.fillStyle=this.dazzledFill(e,e.brightness??0),this.tracePath(e),this.ctx.fill()}paintGhost(e,t){this.ctx.save(),this.tracePath(e),this.ctx.setLineDash([t*3,t*2]),this.ctx.lineWidth=t,this.ctx.strokeStyle=e.color,this.ctx.stroke(),this.ctx.restore()}tracePath(e){if(this.ctx.beginPath(),e.kind==="oval"){const{x:t,y:i,width:n,height:s}=e.bounds,a=n/2,o=s/2;this.ctx.ellipse(t+a,i+o,a,o,e.angle,0,2*Math.PI)}else{const{x:t,y:i,width:n,height:s}=e.bounds;this.ctx.save(),this.ctx.translate(t+n/2,i+s/2),this.ctx.rotate(e.angle),this.ctx.translate(-n/2,-s/2),e.points.forEach((a,o)=>{o===0?this.ctx.moveTo(a.x,a.y):this.ctx.lineTo(a.x,a.y)}),this.ctx.closePath(),this.ctx.restore()}}paintHalo(e){this.ctx.save(),this.ctx.shadowColor=e.color,this.ctx.shadowBlur=bf*e.haloScale,this.paintBase(e),this.ctx.restore()}paintSelectionHandles(e){this.paintHandleFrame(ln.handlePointsFor(e),{includeRotate:!0}),e.kind==="polygon"&&this.paintVertexHandles(e)}paintVertexHandles(e){this.ctx.fillStyle="#39f";for(const t of ln.vertexPointsFor(e))this.ctx.beginPath(),this.ctx.ellipse(t.x,t.y,Wn,Wn,0,0,2*Math.PI),this.ctx.fill()}paintMemberOutline(e){this.paintOutline(ln.handlePointsFor(e))}paintSelectionOnly(e){this.paintSelectionHandles(e)}paintPictureFrame(e,t,i){const n=this.ctx;if(n.save(),e&&e.length===4){n.strokeStyle="#39f",n.lineWidth=1.5,n.setLineDash([6,4]),n.beginPath(),n.moveTo(e[0].x,e[0].y);for(const s of e.slice(1))n.lineTo(s.x,s.y);n.closePath(),n.stroke(),n.setLineDash([])}for(const s of t){const a=zo.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,Wn+2,Wn+2,0,0,2*Math.PI),n.stroke()),s.scene&&(n.strokeStyle=a,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=a,n.beginPath(),n.ellipse(s.scene.x,s.scene.y,Wn,Wn,0,0,2*Math.PI),n.fill()),n.strokeStyle=a,n.lineWidth=o,n.beginPath(),n.ellipse(s.picture.x,s.picture.y,Wn+2,Wn+2,0,0,2*Math.PI),n.stroke(),this.paintLabel(s.label,s.picture.x+Wn+5,s.picture.y-Wn-2,a)}i&&this.paintLabel(i,8,8,"#fff",13),n.restore()}static landmarkColour(e){return e===void 0?"#ffb000":e<=1?"#3c3":e<=3?"#ffb000":"#f33"}paintLabel(e,t,i,n,s=11){const a=this.ctx;a.save(),a.font=`${s}px system-ui, sans-serif`,a.textBaseline="top";const o=a.measureText(e).width;a.fillStyle="rgba(0, 0, 0, 0.6)",a.fillRect(t-3,i-2,o+6,s+4),a.fillStyle=n,a.fillText(e,t,i),a.restore()}paintGroupHandles(e){this.paintHandleFrame(ln.handlePointsFor({bounds:e,angle:0}),{includeRotate:!0})}paintOutline(e){this.ctx.strokeStyle="lightgray",this.ctx.beginPath(),this.ctx.moveTo(e.nw.x,e.nw.y),this.ctx.lineTo(e.ne.x,e.ne.y),this.ctx.lineTo(e.se.x,e.se.y),this.ctx.lineTo(e.sw.x,e.sw.y),this.ctx.closePath(),this.ctx.stroke()}paintHandleFrame(e,{includeRotate:t}){this.paintOutline(e),this.ctx.fillStyle="lightgray";for(const i of Eg){const n=e[i];this.ctx.fillRect(n.x-rc,n.y-rc,Pu,Pu)}t&&(this.ctx.beginPath(),this.ctx.moveTo(e.n.x,e.n.y),this.ctx.lineTo(e.rotate.x,e.rotate.y),this.ctx.stroke(),this.ctx.beginPath(),this.ctx.ellipse(e.rotate.x,e.rotate.y,rc+1,rc+1,0,0,2*Math.PI),this.ctx.fill())}}const Tf=.05,Rf=.08,Df=2,If=3,c2=14,l2=.02;class h2{context;voice;voiceToken=0;buffers=new Map;noiseBuffer;crackleBuffer;requested;resume(){if(!this.context){if(typeof AudioContext>"u")return;try{this.context=new AudioContext}catch(e){console.warn("SightingAudio: Web Audio unavailable, the sighting stays silent:",e);return}}this.context.state==="suspended"&&this.context.resume()}setSound(e){if(this.requested=e,!this.context)return;const t=this.keyFor(e);if(!t){this.silence();return}if(this.voice?.key!==t){this.stopVoice();const i=++this.voiceToken;t.startsWith("src:")?this.buildRecordedVoice(e.src,t,i):this.voice=this.buildSynthesizedVoice(e,t)}this.applyTo(this.voice,e)}silence(){this.voiceToken++,this.stopVoice()}dispose(){this.silence(),this.context?.close(),this.context=void 0,this.buffers.clear(),this.noiseBuffer=void 0,this.crackleBuffer=void 0}keyFor(e){if(!(e.volume<=0))return e.src?`src:${e.src}`:e.kind==="none"?void 0:e.kind}applyTo(e,t){const i=this.context;if(!e||!i)return;const n=i.currentTime;e.volumeParam.setTargetAtTime(Math.max(0,Math.min(1,t.volume))*e.gainScale,n,Tf);for(const{param:s,ratio:a}of e.pitch)s.setTargetAtTime(Math.min(t.pitchHz*a,i.sampleRate/2-1),n,Tf)}buildSynthesizedVoice(e,t){const i=this.context;if(i)switch(e.kind){case"hum":return this.buildHum(i,t);case"whistle":return this.buildWhistle(i,t);case"rumble":return this.buildRumble(i,t);case"crackle":return this.buildCrackle(i,t);default:return}}buildHum(e,t){const i=e.createOscillator();i.type="sawtooth";const n=e.createOscillator();n.type="sawtooth";const s=e.createBiquadFilter();s.type="lowpass",s.Q.value=1;const a=e.createGain();return a.gain.value=0,i.connect(s),n.connect(s),s.connect(a).connect(e.destination),i.start(),n.start(),{key:t,nodes:[s,a],sources:[i,n],volumeParam:a.gain,gainScale:.16,pitch:[{param:i.frequency,ratio:1},{param:n.frequency,ratio:1.006},{param:s.frequency,ratio:6}]}}buildWhistle(e,t){const i=e.createOscillator();i.type="sine";const n=e.createOscillator();n.type="sine",n.frequency.value=5;const s=e.createGain(),a=e.createGain();return a.gain.value=0,n.connect(s).connect(i.frequency),i.connect(a).connect(e.destination),i.start(),n.start(),{key:t,nodes:[s,a],sources:[i,n],volumeParam:a.gain,gainScale:.22,pitch:[{param:i.frequency,ratio:1},{param:s.gain,ratio:.012}]}}buildRumble(e,t){const i=e.createBufferSource();i.buffer=this.brownNoise(e),i.loop=!0;const n=e.createBiquadFilter();n.type="lowpass",n.Q.value=.8;const s=e.createGain();return s.gain.value=0,i.connect(n).connect(s).connect(e.destination),i.start(),{key:t,nodes:[n,s],sources:[i],volumeParam:s.gain,gainScale:1.4,pitch:[{param:n.frequency,ratio:1}]}}buildCrackle(e,t){const i=e.createBufferSource();i.buffer=this.whiteNoise(e),i.loop=!0;const n=e.createBiquadFilter();n.type="bandpass",n.Q.value=1.2;const s=e.createGain();s.gain.value=0;const a=e.createBufferSource();a.buffer=this.crackleEnvelope(e),a.loop=!0;const o=e.createGain();return o.gain.value=0,a.connect(o).connect(s.gain),i.connect(n).connect(s).connect(e.destination),i.start(),a.start(),{key:t,nodes:[n,s,o],sources:[i,a],volumeParam:o.gain,gainScale:.9,pitch:[{param:n.frequency,ratio:4}]}}async buildRecordedVoice(e,t,i){const n=this.context;if(!n)return;let s;try{s=await this.getBuffer(e)}catch(c){console.warn("SightingAudio: the recorded sound failed to load, staying silent:",c);return}if(i!==this.voiceToken||!this.context)return;const a=n.createBufferSource();a.buffer=s,a.loop=!0;const o=n.createGain();o.gain.value=0,a.connect(o).connect(n.destination),a.start(),this.voice={key:t,nodes:[o],sources:[a],volumeParam:o.gain,gainScale:1,pitch:[]},this.requested&&this.applyTo(this.voice,this.requested)}async getBuffer(e){const t=this.context;if(!t)throw new Error("SightingAudio: AudioContext not ready — resume() must be called first");let i=this.buffers.get(e);return i||(i=fetch(e).then(n=>{if(!n.ok)throw new Error(`Audio fetch failed (${n.status}): ${e}`);return n.arrayBuffer()}).then(n=>t.decodeAudioData(n)),this.buffers.set(e,i)),i}whiteNoise(e){if(!this.noiseBuffer){const t=e.createBuffer(1,Math.floor(e.sampleRate*Df),e.sampleRate),i=t.getChannelData(0);for(let n=0;n<i.length;n++)i[n]=Math.random()*2-1;this.noiseBuffer=t}return this.noiseBuffer}brownNoise(e){const t=e.createBuffer(1,Math.floor(e.sampleRate*Df),e.sampleRate),i=t.getChannelData(0);let n=0,s=0;for(let a=0;a<i.length;a++)n=(n+.02*(Math.random()*2-1))/1.02,i[a]=n,s=Math.max(s,Math.abs(n));if(s>0)for(let a=0;a<i.length;a++)i[a]/=s;return t}crackleEnvelope(e){if(!this.crackleBuffer){const t=e.createBuffer(1,Math.floor(e.sampleRate*If),e.sampleRate),i=t.getChannelData(0),n=Math.max(1,Math.floor(l2*e.sampleRate)),s=Math.round(If*c2);for(let a=0;a<s;a++){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=t}return this.crackleBuffer}stopVoice(){const e=this.voice,t=this.context;if(this.voice=void 0,!e||!t)return;const i=t.currentTime;e.volumeParam.cancelScheduledValues(i),e.volumeParam.setTargetAtTime(0,i,Rf/3);const n=i+Rf;for(const s of e.sources){s.onended=()=>{s.disconnect();for(const a of e.nodes)a.disconnect()};try{s.stop(n)}catch{s.disconnect();for(const a of e.nodes)a.disconnect()}}}}function xl(r){return[...r].sort((e,t)=>e.t-t.t)}function Cf(r,e){let t;for(const i of xl(r)){if(i.t>e)break;t=i}return t}const ch=Math.PI/180,oc=180/Math.PI;class Ss{constructor(e,t,i){this.kind=e,this.canvasHeightPx=t,this.fovDeg=i;const n=i*ch/2;this.focalPx=e==="equidistant"?t/2/n:t/2/Math.tan(n)}focalPx;static of(e,t,i){return new Ss(e.projection,t,i)}degToPx(e){const t=e*ch;return this.kind==="equidistant"?this.focalPx*t:2*this.focalPx*Math.tan(t/2)}pxToDeg(e){return this.kind==="equidistant"?e/this.focalPx*oc:2*Math.atan(e/(2*this.focalPx))*oc}angleDegToRadiusPx(e){const t=e*ch;return this.kind==="equidistant"?this.focalPx*t:this.focalPx*Math.tan(t)}halfWidthAngleDeg(e){return this.radiusPxToAngleDeg(this.canvasHeightPx*e/2)}radiusPxToAngleDeg(e){return this.kind==="equidistant"?e/this.focalPx*oc:Math.atan(e/this.focalPx)*oc}ofBounds(e){return{widthDeg:this.pxToDeg(e.width),heightDeg:this.pxToDeg(e.height)}}toBoundsSize(e){return{width:this.degToPx(e.widthDeg),height:this.degToPx(e.heightDeg)}}widthPx(e){return this.degToPx(Et.angularWidthDeg(e))}}class ji{static fovOf(e,t){return jt(e,t)?.fovDeg??si.fieldOfViewDeg(e.instrument)}static toAngular(e){this.eachKeyframe(e,(t,i)=>({...t,angular:i.ofBounds(t.bounds)}))}static toBounds(e){this.eachKeyframe(e,(t,i)=>{if(!t.angular)return t;const{width:n,height:s}=i.toBoundsSize(t.angular),a={x:t.bounds.x+(t.bounds.width-n)/2,y:t.bounds.y+(t.bounds.height-s)/2,width:n,height:s};if(t.kind!=="polygon")return{...t,bounds:a};const o=t.bounds.width===0?1:n/t.bounds.width,c=t.bounds.height===0?1:s/t.bounds.height;return{...t,bounds:a,points:t.points.map(l=>({x:l.x*o,y:l.y*c}))}})}static toAim(e){this.eachKeyframe(e,(t,i,n)=>{const s=t.aim&&this.positionOf(e,t.aim,t.bounds,i,n);if(s&&Math.abs(s.x-t.bounds.x)<ji.UNMOVED_PX&&Math.abs(s.y-t.bounds.y)<ji.UNMOVED_PX)return t;const a=this.aimFrom(e,i,n,t.bounds);return a?{...t,aim:a}:t})}static UNMOVED_PX=.01;static aimOf(e,t,i){const n=Ss.of(e.instrument,Et.CANVAS_HEIGHT_PX,this.fovOf(e,t));return this.aimFrom(e,n,jt(e,t),i)}static aimFrom(e,t,i,n){if(i?.headingDeg===void 0)return;const s=this.frameCentre(e),a=t.radiusPxToAngleDeg(n.x+n.width/2-s.x),o=t.radiusPxToAngleDeg(s.y-(n.y+n.height/2));return{azimuthDeg:((i.headingDeg+a)%360+360)%360,altitudeDeg:i.pitchDeg+o}}static toPosition(e){this.eachKeyframe(e,(t,i,n)=>{const s=t.aim&&this.positionOf(e,t.aim,t.bounds,i,n);return s?{...t,bounds:{...t.bounds,...s}}:t})}static positionOf(e,t,i,n,s){if(s?.headingDeg===void 0)return;const a=this.frameCentre(e),o=this.shortestArc(t.azimuthDeg-s.headingDeg),c=t.altitudeDeg-s.pitchDeg;return{x:a.x+this.offAxisPx(n,o)-i.width/2,y:a.y-this.offAxisPx(n,c)-i.height/2}}static frameCentre(e){return{x:si.frameWidthPx(e.instrument,Et.CANVAS_HEIGHT_PX)/2,y:Et.CANVAS_HEIGHT_PX/2}}static shortestArc(e){return(e%360+540)%360-180}static offAxisPx(e,t){return Math.abs(t)>=ji.OFF_CANVAS_DEG?Math.sign(t)*ji.OFF_CANVAS_PX:e.angleDegToRadiusPx(t)}static OFF_CANVAS_DEG=89;static OFF_CANVAS_PX=1e5;static reproject(e,t,i){const n=si.frameWidthPx(t,Et.CANVAS_HEIGHT_PX)/2,s=si.frameWidthPx(e.instrument,Et.CANVAS_HEIGHT_PX)/2,a=Et.CANVAS_HEIGHT_PX/2;for(const o of[...e.timeline.allKeyframes]){const c=this.fovOf(e,o.t),l=i?.get(o.t)??c,h=Ss.of(t,Et.CANVAS_HEIGHT_PX,l),u=Ss.of(e.instrument,Et.CANVAS_HEIGHT_PX,c);e.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-a,m=Math.hypot(p,v),g=m===0?1:u.angleDegToRadiusPx(h.radiusPxToAngleDeg(m))/m,_={...f,x:s+p*g-f.width/2,y:a+v*g-f.height/2};return{...d,shape:{...d.shape,bounds:_}}}))}this.toBounds(e)}static eachKeyframe(e,t){const{timeline:i}=e;for(const n of[...i.allKeyframes]){const s=jt(e,n.t),a=this.fovOf(e,n.t),o=Ss.of(e.instrument,Et.CANVAS_HEIGHT_PX,a);i.addKeyframe(n.t,n.shapes.map(c=>({...c,shape:t(c.shape,o,s)})))}}}function u2(r){return Gi.restore(d2(r),r.provenance)}function d2(r){return ji.toAngular(r),ji.toAim(r),{version:1,id:r.id,time:r.event.time,endTime:r.event.endTime,durationSeconds:r.event.durationSeconds,utcOffsetHours:r.event.utcOffsetHours,timeZone:r.event.timeZone,place:r.event.place,observer:r.observer,account:r.account,sources:r.sources?.length?r.sources:void 0,sway:r.sway,vehicle:r.vehicle,description:r.event.description,tags:r.event.tags,timeline:r.timeline.toJSON(),observerTrack:r.observerTrack.toJSON(),weatherTrack:r.weatherTrack.toJSON(),soundTrack:r.soundTrack.toJSON(),weather:r.weather,decor:r.decor,milestones:r.milestones.length>0?r.milestones:void 0,references:r.references.length>0?r.references:void 0,roads:r.roads.length>0?r.roads:void 0,weatherSource:r.weatherSource,instrument:r.instrumentId,exposureSeconds:r.exposureSeconds,iso:r.iso,lightPollution:r.lightPollution,interpretation:r.interpretation}}function f2(r){const{recording:e,provenance:t}=Gi.strip(r),i=p2(e);return i.provenance=t,i}function p2(r){const e=[],t=new Wl({eventType:"sighting",time:r.time,endTime:r.endTime,durationSeconds:r.durationSeconds,utcOffsetHours:r.utcOffsetHours,timeZone:r.timeZone,place:r.place,description:r.description,tags:r.tags},Vl.fromJSON(r.timeline,e),r.observerTrack?No.fromJSON(r.observerTrack):new No,r.weatherTrack?Fo.fromJSON(r.weatherTrack):new Fo,r.soundTrack?Uo.fromJSON(r.soundTrack):new Uo,r.observer&&{id:r.observer.id,title:r.observer.title,lastName:r.observer.lastName,firstNames:r.observer.firstNames},r.id,r.weather,r.decor??[],r.weatherSource,r.instrument,r.exposureSeconds??r.observerTrack?.keyframes.map(i=>i.pose.exposureSeconds).find(i=>i!==void 0),xl(r.milestones??[]),r.references??[],r.roads??[]);return t.account=r.account,t.sources=r.sources,t.sway=r.sway,t.iso=r.iso,t.lightPollution=r.lightPollution,t.vehicle=r.vehicle,t.interpretation=r.interpretation,t.loadIssues=e,ji.toBounds(t),ji.toPosition(t),t}class Nr{static EN={"unknown-key":"{path}: unknown key, ignored","wrong-type":"{path}: expected {expected}, found {found}","not-in-list":"{path}: {found} is not one of {expected}",defaulted:"{path}: missing, {expected} used",unplaced:"{path}: no aim (and no bounds), drawn at the middle of the view",unsized:"{path}: no angular size (and no bounds), drawn one pixel wide","pixels-over-angles":"{path}: bounds restated without aim or angular, so the shape follows the pixels"};static text(e,t=Nr.EN){return t[e.kind].replace("{path}",e.path).replace("{expected}",e.expected??"").replace("{found}",e.found??"")}static warn(e,t){if(e.length===0)return;const i=e.map(n=>` ${Nr.text(n)}`);console.warn(`UFO@home: ${e.length} problem(s) in ${t??"this recording"}:
|
|
1300
1300
|
${i.join(`
|
|
1301
|
-
`)}`)}}class An{constructor(e){this.format=e}issues(e){const t=[];return this.object(e,this.format,"",t),t}object(e,t,i,n){if(!An.isObject(e)){n.push({kind:"wrong-type",path:i||"(the file)",expected:"object",found:An.typeOf(e)});return}for(const[s,a]of Object.entries(e)){const o=i?`${i}.${s}`:s,c=t[s];c?this.field(a,c,o,n):n.push({kind:"unknown-key",path:o})}}field(e,t,i,n){if(An.isStated(e)){this.field(e.value,t,i,n);return}if(!(t.loose||e===void 0||e===null))switch(t.type){case"enum":(typeof e!="string"||!t.values?.includes(e))&&n.push({kind:"not-in-list",path:i,expected:(t.values??[]).map(s=>`"${s}"`).join(", "),found:JSON.stringify(e)});return;case"object":t.fields?this.object(e,t.fields,i,n):An.isObject(e)||n.push({kind:"wrong-type",path:i,expected:"object",found:An.typeOf(e)});return;case"array":Array.isArray(e)?t.fields&&e.forEach((s,a)=>{const o=An.isStated(s)?s.value:s;this.object(o,t.fields,`${i}.${a}`,n)}):n.push({kind:"wrong-type",path:i,expected:"array",found:An.typeOf(e)});return;default:typeof e!==t.type&&n.push({kind:"wrong-type",path:i,expected:t.type,found:An.typeOf(e)})}}static isObject(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}static isStated(e){return An.isObject(e)&&"value"in e&&Object.keys(e).every(t=>t==="value"||t==="basis"||t==="rationale")}static typeOf(e){return Array.isArray(e)?"array":e===null?"null":typeof e}}class Pn{static PIXELS_PER_INSTANT=2;static INSTANTS_PER_FLASH=2;static MAX_INSTANTS=512;static windowEndingAt(e,t){const i=Number.isFinite(t)?Math.max(0,t):0,n=Math.max(0,e-i*1e3),s=Math.max(0,e-n);return{fromMs:n,toMs:e,ms:s,seconds:s/1e3}}static instants(e,t,i,n,s){if(!(n>0))return 1;const a=s>0?Pn.travelDegOver(e,t,i,i+n*1e3)/s/Pn.PIXELS_PER_INSTANT:0,o=Pn.flashesOver(e,n)*Pn.INSTANTS_PER_FLASH,c=Math.ceil(Math.max(a,o));return c<2?1:Math.min(Pn.MAX_INSTANTS,c)}static travelDegOver(e,t,i,n){let s=0;for(const a of e){if(!a.track||a.track.length<2)continue;const o=Pn.directionAt(a,t,i),c=Pn.directionAt(a,t,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(e,t){let i=0;for(const n of e)for(const s of n.lights??[])s.pattern.kind==="flash"&&(i=Math.max(i,s.pattern.perMinute));return i/60*t}static directionAt(e,t,i){const n=Or(e,i),s=n.eastM,a=n.altitudeM-t,o=n.northM,c=Math.hypot(s,a,o);return c===0?{x:0,y:1,z:0}:{x:s/c,y:a/c,z:o/c}}}function o0(r,e){for(const t of r){const i=t.toLowerCase().split("-")[0];if(e.includes(i))return i}return"en"}class Fr{static preferencesFor(e){const t=navigator.languages??[],i=this.declaredFor(e);return i?[i,...t]:t}static declaredFor(e){for(let t=e;t;){const i=t.closest("[lang]")?.getAttribute("lang")?.trim();if(i)return i;const n=t.getRootNode();t=n instanceof ShadowRoot?n.host:void 0}}}class On{constructor(e){this.preferences=e}read(e){if(e===void 0||typeof e=="string")return e===""?void 0:e;for(const i of this.preferences){const n=e[i]??e[On.base(i)];if(n)return n}const t=new Set(this.preferences.map(i=>On.base(i)));for(const[i,n]of Object.entries(e))if(n&&t.has(On.base(i)))return n;return Object.values(e).find(i=>i)??void 0}write(e,t,i){const n=t?.trim()?t.trim():void 0;if(e===void 0||typeof e=="string")return n;const s={...e},a=Object.keys(s).find(o=>o===i)??Object.keys(s).find(o=>On.base(o)===On.base(i))??i;return n===void 0?delete s[a]:s[a]=n,Object.keys(s).length===0?void 0:s}static base(e){return e.toLowerCase().split("-")[0]}}const c0=["en","fr","es","it"],m2={en:()=>pi(()=>Promise.resolve().then(()=>y2),void 0,import.meta.url).then(r=>r.ufoMessages_en),fr:()=>pi(()=>import("./UfoMessages_fr-DDeCjNS8.js"),[],import.meta.url).then(r=>r.ufoMessages_fr),es:()=>pi(()=>import("./UfoMessages_es-CzuRdJdo.js"),[],import.meta.url).then(r=>r.ufoMessages_es),it:()=>pi(()=>import("./UfoMessages_it-C2dUwy6T.js"),[],import.meta.url).then(r=>r.ufoMessages_it)};function g2(r){return m2[r]()}const v2={en:()=>pi(()=>Promise.resolve().then(()=>AA),void 0,import.meta.url).then(r=>r.sightingMessages_en),fr:()=>pi(()=>import("./SightingMessages_fr-DuTf6Jr9.js"),[],import.meta.url).then(r=>r.sightingMessages_fr),es:()=>pi(()=>import("./SightingMessages_es-DamT2_69.js"),[],import.meta.url).then(r=>r.sightingMessages_es),it:()=>pi(()=>import("./SightingMessages_it-jYUbX7ci.js"),[],import.meta.url).then(r=>r.sightingMessages_it)};function M2(r){return v2[r]()}function x2(r){switch(r){case"fr":return pi(()=>import("./TagNames_fr-Dnqq6HQ5.js"),[],import.meta.url).then(e=>e.tagNames_fr);case"es":return pi(()=>import("./TagNames_es-BfnMpc3D.js"),[],import.meta.url).then(e=>e.tagNames_es);case"it":return pi(()=>import("./TagNames_it-n6E4EGYO.js"),[],import.meta.url).then(e=>e.tagNames_it);default:return Promise.resolve({})}}function Ag(r){switch(r){case"fr":return pi(()=>import("./SceneNames_fr-0Wzm8zKy.js"),[],import.meta.url).then(e=>e.sceneNames_fr);case"es":return pi(()=>import("./SceneNames_es-C1QdYSKO.js"),[],import.meta.url).then(e=>e.sceneNames_es);case"it":return pi(()=>import("./SceneNames_it-C5oOps-9.js"),[],import.meta.url).then(e=>e.sceneNames_it);default:return Promise.resolve(void 0)}}const Tg={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",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",referenceOpacity:"Picture opacity",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:Nr.EN},y2=Object.freeze(Object.defineProperty({__proto__:null,ufoMessages_en:Tg},Symbol.toStringTag,{value:"Module"})),Rg=Math.PI/180,b2=180/Math.PI,_2=256,Dg=19,S2=1.25;function Ig(r,e){return 156543.03392*Math.cos(r*Rg)/2**e}function Cg(r,e){return Ig(r,e)*_2}function w2(r,e){let t=0;for(;t<Dg&&Cg(r,t+1)>=e;)t++;return t}function Pg(r,e){return Cg(r,e)}function E2(r,e){const t=e*S2;let i=0;for(;i<Dg&&Ig(r,i)>t;)i++;return i}function al(r){const e=r*Rg;return(1-Math.log(Math.tan(e)+1/Math.cos(e))/Math.PI)/2}function Lg(r,e,t){const i=2**t;return{x:(r+180)/360*i,y:al(e)*i}}function Og(r,e,t){const i=al(r.north),n=al(r.south);return{x:(e-r.west)/(r.east-r.west),y:(al(t)-i)/(n-i)}}function A2(r,e,t){const{x:i,y:n}=Lg(r,e,t);return{x:Math.floor(i),y:Math.floor(n),z:t}}function T2(r){const e=2**r.z,t=r.x/e*360-180,i=(r.x+1)/e*360-180,n=Pf(r.y,e);return{south:Pf(r.y+1,e),north:n,west:t,east:i}}function Pf(r,e){const t=r/e;return Math.atan(Math.sinh(Math.PI*(1-2*t)))*b2}function Ng(r,e,t,i){const n=A2(r,e,t),s=Math.floor(i/2),a=[];for(let l=-s;l<=s;l++)for(let h=-s;h<=s;h++)a.push({x:n.x+h,y:n.y+l,z:t});const o=a.map(T2),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:a,bounds:c}}class ya{constructor(e){this.ctx=e}static SCALE_STEPS_M=[5e3,2e3,1e3,500,200,100,50,20,10,5];static MARKER_RADIUS_PX=8.5;static ON_MARKER_M=3;targets=[];hitTest(e,t){let i,n=1/0;for(const s of this.targets){const a=Math.hypot(s.x-e,s.y-t);a>s.radius||a>n||(i=s,n=a)}return i}get width(){return this.ctx.canvas.width}get height(){return this.ctx.canvas.height}paint(e){const{ctx:t}=this;t.save(),this.targets=[],t.clearRect(0,0,this.width,this.height),this.paintGround(e),this.paintNight(e.nightFraction),this.paintPath(e),e.position?(this.paintCone(e,e.position),this.paintDecor(e),this.paintMarkers(e),this.paintObserver(e,e.position)):(this.paintDecor(e),this.paintMarkers(e)),this.paintNorth(),this.paintFooter(e.bounds,e.attribution),t.restore()}toCanvas(e,t,i){const n=Og(e,i,t);return{x:n.x*this.width,y:n.y*this.height}}paintGround(e){const{ctx:t}=this;t.fillStyle="#1d2321",t.fillRect(0,0,this.width,this.height);const i=e.imagery;if(!i)return;const n=this.toCanvas(e.bounds,i.bounds.north,i.bounds.west),s=this.toCanvas(e.bounds,i.bounds.south,i.bounds.east);t.drawImage(i.source,n.x,n.y,s.x-n.x,s.y-n.y)}paintNight(e=0){if(e<=0)return;const{ctx:t}=this;t.save(),t.fillStyle=`rgba(6, 12, 30, ${Math.min(e,1)*.78})`,t.fillRect(0,0,this.width,this.height),t.restore()}paintDecor(e){const{ctx:t}=this;for(const i of e.decor){const n=this.toCanvas(e.bounds,i.lat,i.lng);if(i.label&&this.targets.push({kind:"decor",label:i.label,lat:i.lat,lng:i.lng,x:n.x,y:n.y,radius:7}),t.beginPath(),t.rect(n.x-3.5,n.y-3.5,7,7),t.fillStyle="rgba(120, 220, 255, 0.85)",t.fill(),t.lineWidth=1.5,t.strokeStyle="rgba(0, 0, 0, 0.7)",t.stroke(),i.headingDeg===void 0)continue;const s=(i.headingDeg-90)*Math.PI/180;t.beginPath(),t.moveTo(n.x,n.y),t.lineTo(n.x+Math.cos(s)*10,n.y+Math.sin(s)*10),t.lineWidth=3,t.strokeStyle="rgba(0, 0, 0, 0.6)",t.stroke(),t.lineWidth=1.5,t.strokeStyle="rgba(120, 220, 255, 0.9)",t.stroke()}}paintPath(e){if(!e.path.moved)return;const{ctx:t}=this,i=e.path.points.map(n=>this.toCanvas(e.bounds,n.lat,n.lng));t.beginPath(),t.moveTo(i[0].x,i[0].y);for(const n of i.slice(1))t.lineTo(n.x,n.y);t.lineJoin="round",t.lineCap="round",t.strokeStyle="rgba(0, 0, 0, 0.65)",t.lineWidth=5,t.stroke(),t.strokeStyle="rgba(255, 255, 255, 0.9)",t.lineWidth=2,t.stroke()}paintCone(e,t){const{headingDeg:i,coneHalfAngleDeg:n}=e;if(i===void 0||n===void 0)return;const{ctx:s}=this,a=this.toCanvas(e.bounds,t.lat,t.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(a.x,a.y),s.arc(a.x,a.y,o,c-l,c+l),s.closePath();const h=s.createRadialGradient(a.x,a.y,0,a.x,a.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(e){const{ctx:t}=this;t.textAlign="center",t.textBaseline="middle",t.font="bold 10px sans-serif";for(const i of[...e.markers].sort((n,s)=>Number(n.current)-Number(s.current))){const n=this.toCanvas(e.bounds,i.lat,i.lng);this.targets.push({kind:"milestone",label:i.note?`${i.label} — ${i.note}`:i.label,lat:i.lat,lng:i.lng,t:i.t,x:n.x,y:n.y,radius:ya.MARKER_RADIUS_PX}),t.beginPath(),t.arc(n.x,n.y,ya.MARKER_RADIUS_PX,0,Math.PI*2),t.fillStyle=i.current?"rgba(255, 224, 130, 0.95)":"rgba(0, 0, 0, 0.55)",t.fill(),t.lineWidth=2,t.strokeStyle="rgba(255, 255, 255, 0.9)",t.stroke(),t.fillStyle=i.current?"#1d2321":"#fff",t.fillText(i.label,n.x,n.y)}}paintObserver(e,t){const{ctx:i}=this,n=this.toCanvas(e.bounds,t.lat,t.lng);e.observerLabel&&this.targets.push({kind:"observer",label:e.observerLabel,lat:t.lat,lng:t.lng,x:n.x,y:n.y,radius:8});const s=e.markers.some(a=>{if(!a.current)return!1;const o=ni(a.lat,a.lng,t.lat,t.lng);return Math.hypot(o.x,o.z)<=ya.ON_MARKER_M});i.beginPath(),i.arc(n.x,n.y,s?ya.MARKER_RADIUS_PX+2.5:5.5,0,Math.PI*2),s||(i.fillStyle="#ff5a3c",i.fill()),i.lineWidth=4,i.strokeStyle="rgba(0, 0, 0, 0.5)",i.stroke(),i.lineWidth=s?3:2.5,i.strokeStyle=s?"#ff5a3c":"#fff",i.stroke()}paintNorth(){const{ctx:e}=this,t=this.width-14,i=16;e.beginPath(),e.moveTo(t,i-9),e.lineTo(t-4.5,i+5),e.lineTo(t,i+2),e.lineTo(t+4.5,i+5),e.closePath(),e.fillStyle="rgba(255, 255, 255, 0.92)",e.strokeStyle="rgba(0, 0, 0, 0.6)",e.lineWidth=1,e.fill(),e.stroke(),e.font="bold 9px sans-serif",e.textAlign="center",e.textBaseline="top",e.strokeText("N",t,i+6),e.fillText("N",t,i+6)}paintFooter(e,t){const{ctx:i}=this;i.font="9px sans-serif",i.textBaseline="bottom";const n=t?this.wrap(t,this.width-20):[];let s=this.height-4;i.textAlign="right";for(const f of n.slice().reverse())this.paintOutlinedText(f,this.width-6,s),s-=11;const a=(e.south+e.north)/2,c=Math.abs(ni(a,e.east,a,e.west).x)/this.width,l=ya.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(e,t,i){const{ctx:n}=this;n.lineWidth=3,n.strokeStyle="rgba(0, 0, 0, 0.75)",n.strokeText(e,t,i),n.fillStyle="#fff",n.fillText(e,t,i)}wrap(e,t){const i=[];let n="";for(const s of e.split(" ")){const a=n?`${n} ${s}`:s;n&&this.ctx.measureText(a).width>t?(i.push(n),n=s):n=a}return n&&i.push(n),i}}class Vt{static MIN_ZOOM=.25;static MAX_ZOOM=64;zoom=1;centerX=.5;centerY=.5;get changed(){return this.zoom!==1||this.centerX!==.5||this.centerY!==.5}get zoomFactor(){return this.zoom}reset(){this.zoom=1,this.centerX=.5,this.centerY=.5}zoomAt(e,t,i){const n=Math.min(Vt.MAX_ZOOM,Math.max(Vt.MIN_ZOOM,this.zoom*i)),s=this.centerX+(e-.5)/this.zoom,a=this.centerY+(t-.5)/this.zoom;this.centerX=s-(e-.5)/n,this.centerY=a-(t-.5)/n,this.zoom=n}panBy(e,t){this.centerX-=e/this.zoom,this.centerY-=t/this.zoom}refit(e,t){if(!this.changed)return;const i=this.boundsWithin(e),n=Vt.mercatorY01(t.north),s=Vt.mercatorY01(t.south),a=Vt.mercatorY01(i.north),o=Vt.mercatorY01(i.south);this.zoom=(t.east-t.west)/(i.east-i.west),this.centerX=((i.west+i.east)/2-t.west)/(t.east-t.west),this.centerY=((a+o)/2-n)/(s-n)}keepInView(e,t,i){if(!this.changed)return!1;const n=this.boundsWithin(e),s=Vt.mercatorY01(n.north),a=Vt.mercatorY01(n.south),o=(t.lng-n.west)/(n.east-n.west),c=(Vt.mercatorY01(t.lat)-s)/(a-s);return o>=i&&o<=1-i&&c>=i&&c<=1-i?!1:(this.panBy(.5-o,.5-c),!0)}boundsWithin(e){if(!this.changed)return e;const t=.5/this.zoom,i=Vt.mercatorY01(e.north),n=Vt.mercatorY01(e.south),s=e.east-e.west;return{west:e.west+(this.centerX-t)*s,east:e.west+(this.centerX+t)*s,north:Vt.latitudeAt(i+(this.centerY-t)*(n-i)),south:Vt.latitudeAt(i+(this.centerY+t)*(n-i))}}static expand(e,t){const i=e.east-e.west,n=e.north-e.south;return{west:e.west-i*t,east:e.east+i*t,south:e.south-n*t,north:e.north+n*t}}static pointAt(e,t,i){const n=Vt.mercatorY01(e.north),s=Vt.mercatorY01(e.south);return{lat:Vt.latitudeAt(n+i*(s-n)),lng:e.west+t*(e.east-e.west)}}static mercatorY01(e){const t=e*Math.PI/180;return(1-Math.log(Math.tan(t)+1/Math.cos(t))/Math.PI)/2}static latitudeAt(e){return Math.atan(Math.sinh(Math.PI*(1-2*e)))*180/Math.PI}}const pn=256,Lf=3,R2=32768;class D2{fetchImpl;tileUrlTemplate;constructor(e={}){this.fetchImpl=e.fetchImpl??fetch.bind(globalThis),this.tileUrlTemplate=e.tileUrlTemplate??"https://s3.amazonaws.com/elevation-tiles-prod/terrarium/{z}/{x}/{y}.png"}async getElevationGrid(e,t){const i=(e.south+e.north)/2,n=(e.west+e.east)/2,s=Math.abs(ni(i,e.east,i,e.west).x),a=Math.abs(ni(e.north,n,e.south,n).z),o=w2(i,Math.max(s,a)),{tiles:c}=Ng(n,i,o,Lf),l=Lf*pn,h=new Float32Array(l*l),u=c[0];await Promise.all(c.map(f=>this.decodeTileInto(f,u,h,l)));const d=new Float32Array(t.width*t.height);for(let f=0;f<t.height;f++){const p=e.north+(e.south-e.north)*(f/(t.height-1));for(let v=0;v<t.width;v++){const m=e.west+(e.east-e.west)*(v/(t.width-1));d[f*t.width+v]=this.sampleAt(p,m,o,u,h,l)}}return{heights:d,width:t.width,height:t.height,bounds:e}}async decodeTileInto(e,t,i,n){const s=this.tileUrlTemplate.replace("{z}",String(e.z)).replace("{x}",String(e.x)).replace("{y}",String(e.y)),a=await this.fetchImpl(s);if(!a.ok)throw new Error(`Elevation tile fetch failed (${a.status}): ${s}`);const o=await createImageBitmap(await a.blob()),c=document.createElement("canvas");c.width=pn,c.height=pn;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,pn,pn),u=(e.x-t.x)*pn,d=(e.y-t.y)*pn;for(let f=0;f<pn;f++)for(let p=0;p<pn;p++){const v=(f*pn+p)*4,m=h[v]*256+h[v+1]+h[v+2]/256-R2,g=u+p,_=d+f;i[_*n+g]=m}}sampleAt(e,t,i,n,s,a){const{x:o,y:c}=Lg(t,e,i),l=(o-n.x)*pn,h=(c-n.y)*pn,u=Math.max(0,Math.min(a-1,Math.floor(l))),d=Math.max(0,Math.min(a-1,Math.floor(h))),f=Math.min(a-1,u+1),p=Math.min(a-1,d+1),v=l-u,m=h-d,g=s[d*a+u],_=s[d*a+f],b=s[p*a+u],M=s[p*a+f],S=g+(_-g)*v,w=b+(M-b)*v;return S+(w-S)*m}}const rl=256,I2=5;async function C2(r,e,t,i){const n=(r.south+r.north)/2,s=(r.west+r.east)/2,a=Math.abs(ni(n,r.east,n,r.west).x),o=Math.abs(ni(r.north,s,r.south,s).z),c=Math.max(a,o),{zoom:l,gridSize:h}=P2(n,c,Math.max(e.width,e.height)),{tiles:u,bounds:d}=Ng(s,n,l,h),f=h*rl,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 S=t(M),w=await i(S);if(!w.ok)throw new Error(`Imagery tile fetch failed (${w.status}): ${S}`);const T=await createImageBitmap(await w.blob());v.drawImage(T,(M.x-m.x)*rl,(M.y-m.y)*rl)}));const g=Math.min(Math.max(e.width,e.height),f);if(g===f)return{source:p,width:f,height:f,bounds:d};const _=document.createElement("canvas");_.width=g,_.height=g;const b=_.getContext("2d");if(!b)throw new Error("2D canvas context unavailable");return b.drawImage(p,0,0,f,f,0,0,g,g),{source:_,width:g,height:g,bounds:d}}function P2(r,e,t){let i=E2(r,e/Math.max(1,t)),n=Of(r,i,e);for(;n>I2&&i>0;)i--,n=Of(r,i,e);return{zoom:i,gridSize:n,mPerPixel:Pg(r,i)/rl}}function Of(r,e,t){const i=Math.ceil(t/2/Pg(r,e));return Math.max(3,2*i+1)}class L2{attribution="Imagery © Esri, Maxar, Earthstar Geographics, and the GIS User Community";fetchImpl;tileUrlTemplate;constructor(e={}){this.fetchImpl=e.fetchImpl??fetch.bind(globalThis),this.tileUrlTemplate=e.tileUrlTemplate??"https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"}async getImageryTexture(e,t){return C2(e,t,i=>this.tileUrlTemplate.replace("{z}",String(i.z)).replace("{y}",String(i.y)).replace("{x}",String(i.x)),this.fetchImpl)}}class Tn{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(e={}){this.fetchImpl=e.fetchImpl??fetch.bind(globalThis),this.endpoints=e.endpoints??Tn.ENDPOINTS}static queue=Promise.resolve();static RETRY_MS=4e3;async getRoads(e){const t=`${e.south},${e.west},${e.north},${e.east}`,i=`[out:json][timeout:30];way["highway"~"^(${Tn.DRIVABLE.join("|")})$"](${t});out geom;`;return this.waysFrom(await this.queued(()=>this.ask(i)))}waysFrom(e){const t=[];for(const i of e.elements??[]){const n=i.geometry,s=i.tags;!s||!n||n.length<2||t.push({id:`osm-${i.id??t.length}`,name:s.name,surface:Tn.surfaceOf(s),widthM:Tn.widthOf(s),points:n.map(a=>({lat:a.lat,lng:a.lon}))})}return t}queued(e){const t=Tn.queue.then(e,e);return Tn.queue=t.catch(()=>{}),t}async ask(e){let t;for(const i of this.endpoints)for(let n=0;n<2;n++){try{const s=await this.fetchImpl(`${i}?data=${encodeURIComponent(e)}`);if(s.ok)return await s.json();if(t=new Error(`${new URL(i).host} refused (${s.status})`),s.status!==429&&s.status!==504)break}catch(s){t=new Error(`${new URL(i).host} unreachable (${String(s)})`);break}await new Promise(s=>setTimeout(s,Tn.RETRY_MS))}throw t??new Error("No Overpass instance answered")}static widthOf(e){const t=Number.parseFloat(e.width??e.est_width??"");if(Number.isFinite(t)&&t>0)return t;const i=Number.parseInt(e.lanes??"",10);return Number.isFinite(i)&&i>0?i*3.5:Tn.WIDTH_M[e.highway]??Tn.DEFAULT_WIDTH_M}static surfaceOf(e){const t=e.surface;return t==="dirt"||t==="earth"||t==="mud"?"dirt":t==="gravel"||t==="fine_gravel"||t==="compacted"||t==="ground"||t==="sand"||t==="unpaved"?"gravel":t?"paved":e.highway==="track"?"gravel":"paved"}}const lh="https://ufoathome.org/roads/index.json";class l0{attributionRead;contemporaryRead;fetchImpl;indexUrls;fallback;index;constructor(e={}){this.fetchImpl=e.fetchImpl??fetch.bind(globalThis),this.indexUrls=e.indexUrls??l0.defaultIndexUrls(),this.fallback=e.fallback}get attribution(){return this.attributionRead??this.fallback?.attribution??"Roads © OpenStreetMap contributors"}get contemporary(){return this.contemporaryRead??this.fallback?.contemporary??!0}async getRoads(e){const t=await this.held(e);if(t)return t;if(!this.fallback)return[];const i=await this.fallback.getRoads(e);return this.attributionRead=this.fallback.attribution,this.contemporaryRead=this.fallback.contemporary,i}async held(e){let t;try{t=await this.load()}catch{return}const i=t.find(({entry:n})=>n.north>=e.north&&n.south<=e.south&&n.east>=e.east&&n.west<=e.west);if(i)try{const n=await this.fetchImpl(new URL(i.entry.file,i.indexUrl).href);if(!n.ok)return;const s=await n.json();return Array.isArray(s?.ways)?(this.attributionRead=s.attribution,this.contemporaryRead=s.contemporary,s.ways):void 0}catch{return}}load(){return this.index??=this.fetchFirstAvailable(),this.index}async fetchFirstAvailable(){for(const e of this.indexUrls)try{const t=await this.fetchImpl(e);if(!t.ok)continue;const i=await t.json();if(Array.isArray(i?.entries))return i.entries.map(n=>({entry:n,indexUrl:e}))}catch{}return[]}static defaultIndexUrls(){const e=`?v=${encodeURIComponent("0.74.0")}`,t=typeof location>"u"?void 0:new URL("/roads/index.json",location.href).href;return(t&&t!==lh?[t,lh]:[lh]).map(i=>i+e)}}function O2(){return{elevation:new D2,imagery:Fg(),roads:N2()}}function Fg(){return new L2}function N2(){return new l0({fallback:new Tn})}const F2=new Set,Es="show-observer-map",As="hide-milestones";class ui extends HTMLElement{static get observedAttributes(){return["src",Es,As]}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;observerMapButton;referencesButton;referenceOpacityInput;referencesShownState=!0;referenceOpacityTouched=!1;milestonesButton;observerMapPanel;observerMapCanvas;observerMapRenderer;mapZoomInButton;mapZoomOutButton;mapFitButton;observerMapView=new Vt;observerMapDrag;suppressObserverMapClick=!1;observerMapImageryTimer;observerPlacing=!1;seekInput;playbackFlash;milestoneMarks;milestoneCaption;timeStartLabel;timeEndLabel;observerPath;observerMapBounds;observerMapImagery;observerMapImageryBounds;observerMapImageryViewWidth=0;observerMapImageryLoading=!1;observerMapImageryCredit;observerMapImageryFailed=!1;creditShownExternally=!1;lookYawDeg=0;lookPitchDeg=0;milestonesShown=!0;currentSighting=Wl.create();issues=[];issueCheck=0;sightingAudio=new h2;soundPreview;player;loopEnabled=!1;playbackBeforeClick;highlightedSourceIds=new Set;paintsShapes=!0;steadyObserver=!1;selectionShown=!0;overlayPainter;enableClickToPlay=!0;fullscreenTarget;messages=Tg;realDurationMs;realStartMs;showClockTime=!0;handleFullscreenChange=()=>{this.updateFullscreenButton(),this.resizeObserverMap()};observerMapResizeObserver=typeof ResizeObserver>"u"?void 0:new ResizeObserver(()=>this.resizeObserverMap());resizeObserverMap(){this.observerMapPanel.hidden||(this.sizeObserverMapCanvas(),this.paintObserverMap(this.currentTime))}simulatedFullscreen=!1;styleBeforeSimulatedFullscreen;bodyOverflowBeforeSimulatedFullscreen;handleSimulatedFullscreenKey=e=>{e.key==="Escape"&&this.exitSimulatedFullscreen()};handlePointerMove=e=>{const t=this.canvasPointFromEvent(e),i=t&&this.shapeAt(t.x,t.y),n=this.said.read(i?.shape.title);if(!n){this.tooltip.hidden=!0;return}this.tooltip.textContent=n,this.tooltip.hidden=!1;const s=this.stageElement.getBoundingClientRect();this.tooltip.style.left=`${e.clientX-s.left+12}px`,this.tooltip.style.top=`${e.clientY-s.top+12}px`};handleObserverMapPointerMove=e=>{if(this.dragObserverMap(e))return;const t=this.observerMapTargetFrom(e);if(!t){if(!this.observerPlacing){this.tooltip.hidden=!0,this.observerMapCanvas.style.cursor="grab";return}this.observerMapCanvas.style.cursor="crosshair",this.showObserverMapTooltip(e,this.messages.placeObserverHere);return}this.observerMapCanvas.style.cursor="pointer",this.showObserverMapTooltip(e,t.label)};showObserverMapTooltip(e,t){this.tooltip.textContent=t,this.tooltip.hidden=!1;const i=this.stageElement.getBoundingClientRect();this.tooltip.style.left=`${e.clientX-i.left+12}px`,this.tooltip.style.top=`${e.clientY-i.top+12}px`}handleObserverMapClick=e=>{if(this.suppressObserverMapClick){this.suppressObserverMapClick=!1;return}const t=this.observerMapTargetFrom(e);if(!t){this.observerPlacing&&this.placeObserverFrom(e);return}if(t.kind==="milestone"&&t.t!==void 0){this.player.seek(t.t);return}this.dispatchEvent(new CustomEvent("lookat",{detail:{lat:t.lat,lng:t.lng,kind:t.kind},bubbles:!0,composed:!0}))};observerMapTargetFrom(e){const t=this.observerMapCanvas.getBoundingClientRect();if(!(t.width===0||t.height===0))return this.observerMapRenderer.hitTest((e.clientX-t.left)/t.width*this.observerMapCanvas.width,(e.clientY-t.top)/t.height*this.observerMapCanvas.height)}handlePointerLeave=()=>{this.tooltip.hidden=!0};handleObserverMapPointerDown=e=>{e.button===0&&(this.suppressObserverMapClick=!1,this.observerMapDrag={pointerId:e.pointerId,startX:e.clientX,startY:e.clientY,lastX:e.clientX,lastY:e.clientY,moved:!1})};handleObserverMapPointerUp=e=>{const t=this.observerMapDrag;!t||t.pointerId!==e.pointerId||(this.observerMapDrag=void 0,this.observerMapCanvas.classList.remove("dragging"),t.moved&&(this.suppressObserverMapClick=!0,this.paintObserverMap(this.currentTime),this.observerMapCanvas.hasPointerCapture?.(e.pointerId)&&this.observerMapCanvas.releasePointerCapture(e.pointerId)))};dragObserverMap(e){const t=this.observerMapDrag;if(!t||t.pointerId!==e.pointerId)return!1;if(!t.moved){if(Math.hypot(e.clientX-t.startX,e.clientY-t.startY)<ui.OBSERVER_MAP_DRAG_PX)return!1;t.moved=!0,this.tooltip.hidden=!0,this.observerMapCanvas.classList.add("dragging"),this.observerMapCanvas.setPointerCapture?.(e.pointerId)}const i=this.observerMapCanvas.getBoundingClientRect();return i.width>0&&i.height>0&&(this.observerMapView.panBy((e.clientX-t.lastX)/i.width,(e.clientY-t.lastY)/i.height),this.observerMapViewChanged()),t.lastX=e.clientX,t.lastY=e.clientY,!0}static OBSERVER_MAP_DRAG_PX=4;handleObserverMapWheel=e=>{e.preventDefault();const t=this.observerMapCanvas.getBoundingClientRect();if(t.width===0||t.height===0)return;const i=e.deltaMode===0?e.deltaY:e.deltaY*40;this.zoomObserverMap((e.clientX-t.left)/t.width,(e.clientY-t.top)/t.height,Math.exp(-i*.002))};zoomObserverMap(e,t,i){this.observerMapView.zoomAt(e,t,i),this.observerMapViewChanged()}observerMapViewChanged(){this.mapFitButton.hidden=!this.observerMapView.changed,this.mapZoomInButton.disabled=this.observerMapView.zoomFactor>=Vt.MAX_ZOOM,this.mapZoomOutButton.disabled=this.observerMapView.zoomFactor<=Vt.MIN_ZOOM,this.paintObserverMap(this.currentTime),this.scheduleObserverMapImagery()}scheduleObserverMapImagery(){this.observerMapImageryTimer===void 0&&(this.observerMapImageryTimer=setTimeout(()=>{this.observerMapImageryTimer=void 0,this.loadObserverMapImagery()},ui.OBSERVER_MAP_IMAGERY_DELAY_MS))}static OBSERVER_MAP_FOLLOW_MARGIN=.1;static OBSERVER_MAP_IMAGERY_DELAY_MS=300;get observerMapViewBounds(){return this.observerMapBounds&&this.observerMapView.boundsWithin(this.observerMapBounds)}placeObserverFrom(e){const t=this.observerMapViewBounds,i=this.observerMapCanvas.getBoundingClientRect();if(!t||i.width===0||i.height===0)return;const n=Vt.pointAt(t,(e.clientX-i.left)/i.width,(e.clientY-i.top)/i.height);this.dispatchEvent(new CustomEvent("observerplace",{detail:n,bubbles:!0,composed:!0}))}constructor(){super(),this.shadow=this.attachShadow({mode:"open"});const e=document.createElement("template");e.innerHTML=`<style>${i2}</style>${t2}`,this.shadow.appendChild(e.content.cloneNode(!0)),this.stageElement=this.shadow.getElementById("stage"),this.canvas=this.shadow.getElementById("canvas"),this.canvasRenderer=new zo(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",t=>{t.stopPropagation(),this.issuesPanel.hidden=!this.issuesPanel.hidden,this.issuesButton.setAttribute("aria-expanded",String(!this.issuesPanel.hidden))}),this.playPauseButton=this.shadow.getElementById("play-pause"),this.fullscreenButton=this.shadow.getElementById("fullscreen"),this.observerMapButton=this.shadow.getElementById("observer-map"),this.referencesButton=this.shadow.getElementById("references"),this.referenceOpacityInput=this.shadow.getElementById("reference-opacity"),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 ya(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");for(const t of[this.timeStartLabel,this.timeEndLabel])t.addEventListener("click",()=>this.toggleTimeDisplay()),t.addEventListener("keydown",i=>{i.key!=="Enter"&&i.key!==" "||(i.preventDefault(),this.toggleTimeDisplay())});this.fullscreenTarget=this.stageElement,this.playPauseButton.addEventListener("click",()=>this.togglePlayPause()),this.fullscreenButton.addEventListener("click",()=>this.toggleFullscreen()),this.observerMapButton.addEventListener("click",()=>this.toggleObserverMap()),this.referencesButton.addEventListener("click",()=>this.toggleReferences()),this.referenceOpacityInput.addEventListener("input",()=>{this.referenceOpacityTouched=!0,this.dispatchReferenceView()}),this.milestonesButton.addEventListener("click",()=>this.toggleMilestones()),this.observerMapCanvas.addEventListener("pointermove",this.handleObserverMapPointerMove),this.observerMapCanvas.addEventListener("pointerleave",this.handlePointerLeave),this.observerMapCanvas.addEventListener("click",this.handleObserverMapClick),this.observerMapCanvas.addEventListener("pointerdown",this.handleObserverMapPointerDown),this.observerMapCanvas.addEventListener("pointerup",this.handleObserverMapPointerUp),this.observerMapCanvas.addEventListener("pointercancel",this.handleObserverMapPointerUp),this.observerMapCanvas.addEventListener("wheel",this.handleObserverMapWheel,{passive:!1}),this.mapZoomInButton.addEventListener("click",()=>this.zoomObserverMap(.5,.5,2)),this.mapZoomOutButton.addEventListener("click",()=>this.zoomObserverMap(.5,.5,.5)),this.mapFitButton.addEventListener("click",()=>{this.observerMapView.reset(),this.observerMapViewChanged()}),this.seekInput.addEventListener("input",()=>this.player.seek(this.snapSeekToMark(Number(this.seekInput.value)))),this.seekInput.addEventListener("pointerdown",t=>{this.seekSnapArmed=!0,this.nameMarkUnder(t)}),this.seekInput.addEventListener("pointerup",()=>{this.seekSnapArmed=!1}),this.seekInput.addEventListener("pointermove",t=>this.nameMarkUnder(t)),this.seekInput.addEventListener("pointerleave",()=>this.seekInput.removeAttribute("title")),this.seekInput.addEventListener("keydown",this.handleSeekKey),this.canvas.addEventListener("click",t=>{this.enableClickToPlay&&(t.detail<=1&&(this.playbackBeforeClick={state:this.playbackState,time:this.currentTime}),this.togglePlayPause())}),this.canvas.addEventListener("dblclick",t=>{this.enableClickToPlay&&(t.preventDefault(),this.restorePlayback(),this.toggleFullscreen())}),this.canvas.addEventListener("pointermove",this.handlePointerMove),this.canvas.addEventListener("pointerleave",this.handlePointerLeave),document.addEventListener("fullscreenchange",this.handleFullscreenChange),this.observerMapResizeObserver?.observe(this.observerMapPanel),this.hostControls(void 0),this.player=this.createPlayer(),this.updateTimeLabels(),this.updatePlayPauseButton(),this.updateFullscreenButton(),this.updateObserverMapButton(),this.updateReferencesButton(),this.updateMilestonesButton(),this.refresh()}connectedCallback(){this.saidTexts=void 0,this.loadLocaleMessages();const e=this.getAttribute("src");e&&this.loadFromSrc(e)}disconnectedCallback(){document.removeEventListener("fullscreenchange",this.handleFullscreenChange),this.observerMapResizeObserver?.disconnect(),this.exitSimulatedFullscreen(),this.sightingAudio.dispose()}attributeChangedCallback(e,t,i){e==="src"&&i&&i!==t&&this.isConnected&&this.loadFromSrc(i),e===Es&&this.applyObserverMapDefault(),e===As&&this.setMilestonesShown(!this.hasAttribute(As))}async loadFromSrc(e){this.sightingData=await Ao.json(e)}get sightingData(){return u2(this.currentSighting)}set sightingData(e){this.player.stop(),this.soundPreview=void 0,this.sightingAudio.silence(),this.currentSighting=f2(e),this.issuesPanel.hidden=!0,this.issuesButton.setAttribute("aria-expanded","false"),this.reportIssues(e,this.currentSighting),this.observerMapView.reset(),this.mapFitButton.hidden=!0,this.observerMapAsked=!1,this.player=this.createPlayer(),this.updateTimeLabels(),this.updatePlayPauseButton(),this.refresh(),this.applyObserverMapDefault()}get recordingIssues(){return this.issues}async reportIssues(e,t){const i=++this.issueCheck;let n=[];try{const{default:s}=await pi(async()=>{const{default:a}=await import("./sightingSchema-DOOSOVWK.js");return{default:a}},[],import.meta.url);n=new An(s).issues(e)}catch{}i===this.issueCheck&&(this.issues=[...n,...t.loadIssues],Nr.warn(this.issues,t.id),this.renderIssues(),this.dispatchEvent(new CustomEvent(U2,{detail:{issues:this.issues},bubbles:!0,composed:!0})))}renderIssues(){const e=this.issues.length;this.issuesBox.hidden=e===0,this.shadow.getElementById("issues-count").textContent=String(e);const t=this.messages.recordingIssues.replace("{count}",String(e));this.issuesButton.title=t,this.issuesButton.setAttribute("aria-label",t),this.shadow.getElementById("issues-title").textContent=t,this.shadow.getElementById("issues-list").replaceChildren(...this.issues.map(i=>{const n=document.createElement("li");return n.textContent=Nr.text(i,this.messages.issueTemplates),n}))}get sighting(){return this.currentSighting}previewSound(e){this.soundPreview=e,this.sightingAudio.resume(),this.sightingAudio.setSound(e)}stopSoundPreview(){this.soundPreview=void 0,this.sightingAudio.silence()}get canvasElement(){return this.canvas}get renderer(){return this.canvasRenderer}get currentTime(){return this.player.time}set currentTime(e){this.player.seek(e)}get seekableDuration(){return this.player.seekableDuration}get autoReplayEnabled(){return this.loopEnabled}set autoReplayEnabled(e){e!==this.loopEnabled&&this.toggleLoop()}play(){this.player.seekableDuration<=0||this.playbackState==="playing"||this.togglePlayPause()}pause(){this.playbackState==="playing"&&this.togglePlayPause()}get positionLabel(){return this.timeStartLabel.textContent??""}get durationLabel(){return this.timeEndLabel.textContent??""}get showingClockTime(){return this.canShowClockTime}get canSwitchTimeDisplay(){return this.realStartMs!==void 0}toggleTimeDisplay(){this.canSwitchTimeDisplay&&(this.showClockTime=!this.showClockTime,this.updateTimeLabels(),this.updateTimeLabelTitles(),this.dispatchEvent(new CustomEvent("timedisplaychange",{bubbles:!0,composed:!0})))}get canShowClockTime(){return this.realStartMs!==void 0&&this.showClockTime}set showToolbar(e){this.toolbar.classList.toggle("hidden",!e)}get playbackState(){return this.player.playbackState}get selectedSourceIds(){return this.highlightedSourceIds}get durationSeconds(){return this.currentSighting.event.durationSeconds}set durationSeconds(e){this.currentSighting.event.durationSeconds=e,this.updateTimeLabels(),this.refresh(),this.updatePlayPauseButton()}set selectedSourceIds(e){const t=new Set(e);t.size===this.highlightedSourceIds.size&&[...t].every(n=>this.highlightedSourceIds.has(n))||(this.highlightedSourceIds=t,this.refresh())}hasVisibleShapeAt(e,t){return this.shapeAt(e,t)!==void 0}refresh(){this.applyFrameFormat(),this.updateTimeLabels(),this.seekInput.max=String(this.player.seekableDuration),this.refreshMilestoneMarks(),this.updateMilestonesButton(),this.updateObserverMap(),this.updateReferences(),this.player.seek(this.player.time)}hostControls(e){const t=[this.milestonesButton,this.referenceOpacityInput,this.referencesButton,this.observerMapButton];if(e)for(const i of t)e.appendChild(i);else for(const i of t)this.toolbar.appendChild(i)}get referencesShown(){return this.referencesShownState}get referenceOpacity(){return Number(this.referenceOpacityInput.value)}toggleReferences(){this.referencesShownState=!this.referencesShownState,this.updateReferencesButton(),this.dispatchReferenceView()}updateReferences(){const e=this.currentSighting.references;!this.referenceOpacityTouched&&e.length>0&&(this.referenceOpacityInput.value=String(e[0].opacity)),this.updateReferencesButton()}updateReferencesButton(){const e=this.currentSighting.references.length>0;this.referencesButton.hidden=!e,this.referenceOpacityInput.hidden=!e||!this.referencesShownState,this.referencesButton.setAttribute("aria-pressed",String(this.referencesShownState));const t=this.referencesShownState?this.messages.hideReferences:this.messages.showReferences;this.referencesButton.title=t,this.referencesButton.setAttribute("aria-label",t),this.referenceOpacityInput.title=this.messages.referenceOpacity,this.referenceOpacityInput.setAttribute("aria-label",this.messages.referenceOpacity)}dispatchReferenceView(){this.dispatchEvent(new CustomEvent("referenceview",{detail:{shown:this.referencesShown,opacity:this.referenceOpacity}}))}refreshMilestoneMarks(){const e=this.player.seekableDuration,t=e>0?xl(this.sighting.milestones):[];this.milestoneMarks.replaceChildren(...t.map(i=>{const n=document.createElement("button");n.type="button",n.className="milestone-mark",n.style.left=`${Math.min(Math.max(i.t/e,0),1)*100}%`;const s=this.said.read(i.label)??"",a=this.said.read(i.note),o=a?`${s} — ${a}`: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}))}seekSnapArmed=!1;static MARK_SNAP_PX=6;markNear(e){const t=this.player.seekableDuration,i=this.seekInput.getBoundingClientRect().width;if(t<=0||i<=0)return;const n=ui.MARK_SNAP_PX/i*t;let s;for(const a of this.milestoneMarks.children){const o=Number(a.dataset.t);Math.abs(o-e)>n||(!s||Math.abs(o-e)<Math.abs(s.t-e))&&(s={t:o,name:a.title})}return s}snapSeekToMark(e){return this.seekSnapArmed?(this.seekSnapArmed=!1,this.markNear(e)?.t??e):e}nameMarkUnder(e){const t=this.seekInput.getBoundingClientRect(),i=this.player.seekableDuration;if(t.width<=0||i<=0)return;const n=(e.clientX-t.left)/t.width*i,s=this.markNear(n);s?this.seekInput.title=s.name:this.seekInput.removeAttribute("title")}showMilestoneAt(e){const t=this.milestonesShown&&this.sighting.milestones.length>0?Cf(this.sighting.milestones,e):void 0;if(this.milestoneCaption.hidden=t===void 0,!t)return;const i=document.createElement("b");i.textContent=this.said.read(t.label)??"";const n=this.said.read(t.note),s=n?` — ${n}`:"";this.milestoneCaption.replaceChildren(i,document.createTextNode(s))}exposureInstants(e){const t=this.exposureTimes(e),i=1/t.length;return t.map(n=>({shapes:this.shapesAt(n),share:i}))}exposureTimes(e=this.currentTime){const t=Pn.windowEndingAt(e,this.currentSighting.exposure??0);if(t.ms<ui.SHORTEST_VISIBLE_EXPOSURE_MS)return[e];const i=Math.min(ui.MAX_EXPOSURE_STEPS,Math.max(2,Math.round(t.ms/ui.SHORTEST_VISIBLE_EXPOSURE_MS))),n=Math.ceil(this.travelPxOver(t.fromMs,t.ms)/ui.EXPOSURE_STEP_PX),s=Math.min(ui.MAX_TRAVEL_STEPS,Math.max(i,n)),a=[];for(let o=0;o<s;o++)a.push(t.fromMs+t.ms*o/(s-1));return a}travelPxOver(e,t){const i=this.shapesAt(e),n=this.shapesAt(e+t);let s=0;for(const[a,o]of i){const c=n.get(a);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(e,t,i){for(const n of this.exposureTimes()){const s=this.currentSighting.timeline.hitTest(n,e,t,i);if(s)return s}}shapesAt(e){const t=new Map;for(const i of this.currentSighting.timeline.sourceIds){const n=this.currentSighting.timeline.getInterpolatedShapeAt(e,i);n&&t.set(i,n)}return t}static SHORTEST_VISIBLE_EXPOSURE_MS=20;static MAX_EXPOSURE_STEPS=48;static EXPOSURE_STEP_PX=2;static MAX_TRAVEL_STEPS=320;applyFrameFormat(){const e=si.frameWidthPx(this.currentSighting.instrument,this.canvas.height);if(this.canvas.width===e)return;this.canvas.width=e,this.canvas.parentElement?.style.setProperty("--frame-aspect",`${e} / ${this.canvas.height}`)}canvasPointFromEvent(e){const t=this.canvas.getBoundingClientRect();if(!(t.width===0||t.height===0))return{x:(e.clientX-t.left)/t.width*this.canvas.width,y:(e.clientY-t.top)/t.height*this.canvas.height}}onFrame(e,t){this.canvasRenderer.clear(this.canvas.width,this.canvas.height);const i=this.playbackState!=="playing"?this.highlightedSourceIds:F2;this.canvasRenderer.setStarPoints(si.starPointsOf(this.sighting.instrument));const n=(jt(this.sighting,e)?.rollDeg??0)+this.gaitAt(e).rollDeg;this.canvasRenderer.setRoll(n*Math.PI/180);const s=this.exposureInstants(e),a=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,a))}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,a)));if(this.selectionShown&&i.size>1){const o=ln.groupBoundsFor([...t].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,a).bounds)),this.keepObserverMapClear(),this.seekInput.value=String(e),this.timeStartLabel.textContent=this.formatPosition(e),this.showMilestoneAt(e),this.paintObserverMap(e),this.playbackState==="playing"?(this.soundPreview=void 0,this.sightingAudio.setSound(yg(this.currentSighting,e))):this.soundPreview?this.sightingAudio.setSound(this.soundPreview):this.sightingAudio.silence(),this.updatePlayPauseButton(),this.dispatchEvent(new CustomEvent("timeupdate",{detail:{time:e}}))}shifted(e,t){return t.x===0&&t.y===0?e:{...e,bounds:{...e.bounds,x:e.bounds.x+t.x,y:e.bounds.y+t.y}}}createPlayer(){const e=new n2(this.currentSighting.timeline,(t,i)=>this.onFrame(t,i));return e.loop=this.loopEnabled,e.onEnded=()=>{this.updatePlayPauseButton(),this.dispatchEvent(new CustomEvent("ended",{bubbles:!0,composed:!0}))},e}static SEEK_KEY_STEP_MS=5e3;handleSeekKey=e=>{if(e.altKey||e.ctrlKey||e.metaKey)return;const t=e.key==="ArrowLeft"?-1:e.key==="ArrowRight"?1:0;if(t){e.preventDefault();const i=this.player.seekableDuration;this.player.seek(Math.min(i,Math.max(0,this.player.time+t*ui.SEEK_KEY_STEP_MS)))}else e.key===" "&&(e.preventDefault(),this.togglePlayPause())};togglePlayPause(){this.player.seekableDuration<=0||(this.player.playbackState==="playing"?(this.player.pause(),this.soundPreview=void 0,this.sightingAudio.silence(),this.refresh()):(this.sightingAudio.resume(),this.player.play()),this.updatePlayPauseButton(),this.flashPlayback())}flashPlayback(){const e=this.playbackFlash;e.textContent=this.player.playbackState==="playing"?"▶":"⏸",e.classList.remove("flashing"),e.offsetWidth,e.classList.add("flashing")}updatePlayPauseButton(){const e=this.player.playbackState==="playing";this.playPauseButton.textContent=e?"⏸":"▶";const t=this.player.seekableDuration>0;this.playPauseButton.disabled=!t;const i=t?e?this.messages.pause:this.messages.play:this.messages.noDuration;this.playPauseButton.title=i,this.playPauseButton.setAttribute("aria-label",i)}toggleLoop(){this.loopEnabled=!this.loopEnabled,this.player.loop=this.loopEnabled}restorePlayback(){const e=this.playbackBeforeClick;e&&(this.currentTime=e.time,e.state==="playing"?this.play():this.pause())}get canUseNativeFullscreen(){return typeof this.fullscreenTarget.requestFullscreen=="function"&&document.fullscreenEnabled}toggleFullscreen(){if(!this.canUseNativeFullscreen){this.simulatedFullscreen?this.exitSimulatedFullscreen():this.enterSimulatedFullscreen();return}document.fullscreenElement?document.exitFullscreen():this.fullscreenTarget.requestFullscreen().catch(e=>{console.error("<rr0-ufo>: requestFullscreen() failed —",e)})}enterSimulatedFullscreen(){const e=this.fullscreenTarget;this.styleBeforeSimulatedFullscreen=e.getAttribute("style")??"",this.bodyOverflowBeforeSimulatedFullscreen=document.body.style.overflow;const t=e.style;t.setProperty("position","fixed"),t.setProperty("inset","0"),t.setProperty("margin","0"),t.setProperty("max-width","none"),t.setProperty("max-height","none"),t.setProperty("aspect-ratio","auto"),t.setProperty("z-index","2147483647"),t.setProperty("background","#000"),t.setProperty("width","100vw"),t.setProperty("width","100dvw"),t.setProperty("height","100vh"),t.setProperty("height","100dvh"),document.body.style.overflow="hidden",this.simulatedFullscreen=!0,document.addEventListener("keydown",this.handleSimulatedFullscreenKey),this.updateFullscreenButton()}exitSimulatedFullscreen(){if(!this.simulatedFullscreen)return;const e=this.fullscreenTarget;this.styleBeforeSimulatedFullscreen?e.setAttribute("style",this.styleBeforeSimulatedFullscreen):e.removeAttribute("style"),document.body.style.overflow=this.bodyOverflowBeforeSimulatedFullscreen??"",this.simulatedFullscreen=!1,document.removeEventListener("keydown",this.handleSimulatedFullscreenKey),this.updateFullscreenButton()}toggleObserverMap(){const e=this.observerMapPanel.hidden;this.observerMapAsked=e,this.setObserverMapOpen(e),this.keepObserverMapClear()}observerMapAsked=!1;applyObserverMapDefault(){const e=this.getAttribute(Es),t=e===null?this.observerPath?.travels===!0:e!=="false";this.setObserverMapOpen(t&&this.observerPath!==void 0)}setObserverMapOpen(e){this.observerMapPanel.hidden=!e,this.observerMapPanel.removeAttribute("title"),this.observerMapButton.setAttribute("aria-pressed",String(e)),this.updateObserverMapButton(),e&&(this.sizeObserverMapCanvas(),this.loadObserverMapImagery(),this.paintObserverMap(this.currentTime))}updateObserverMapButton(){const t=!this.observerMapPanel.hidden?this.messages.hideObserverMap:this.messages.showObserverMap;this.observerMapButton.title=t,this.observerMapButton.setAttribute("aria-label",t);const i=[[this.mapZoomInButton,this.messages.zoomMapIn],[this.mapZoomOutButton,this.messages.zoomMapOut],[this.mapFitButton,this.messages.fitMap]];for(const[n,s]of i)n.title=s,n.setAttribute("aria-label",s)}updateObserverMap(){const e=this.observerPath!==void 0;if(this.observerPath=wr.of(this.currentSighting),this.observerMapButton.hidden=this.observerPath===void 0,!e&&this.observerPath&&this.applyObserverMapDefault(),!this.observerPath){this.setObserverMapOpen(!1),this.observerMapBounds=void 0;return}const t=this.observerPath.boundsAround(ui.OBSERVER_MAP_MIN_SPAN_M,ui.OBSERVER_MAP_MARGIN);(!this.observerMapBounds||!this.sameGround(this.observerMapBounds,t))&&(this.observerMapBounds&&this.observerMapView.refit(this.observerMapBounds,t),this.observerMapBounds=t,this.observerMapImagery=void 0,this.observerMapImageryCredit=void 0,this.observerMapImageryFailed=!1,this.observerMapImageryBounds=void 0,this.observerMapImageryLoading=!1,this.observerMapPanel.hidden||this.loadObserverMapImagery())}sameGround(e,t){const i=Math.abs(e.east-e.west)/20;return Math.abs(e.north-t.north)<i&&Math.abs(e.south-t.south)<i&&Math.abs(e.west-t.west)<i&&Math.abs(e.east-t.east)<i}async loadObserverMapImagery(){const e=this.observerMapViewBounds;if(!e||this.observerMapPanel.hidden||this.observerMapImageryLoading||!this.observerMapImageryNeededFor(e))return;const t=this.observerMapView.changed,i=t?Vt.expand(e,ui.OBSERVER_MAP_IMAGERY_AHEAD):e,n=ui.OBSERVER_MAP_IMAGERY_PX*(t?1+2*ui.OBSERVER_MAP_IMAGERY_AHEAD:1);this.observerMapImageryBounds=i,this.observerMapImageryViewWidth=e.east-e.west,this.observerMapImageryLoading=!0;const s=Fg();try{const a=await s.getImageryTexture(i,{width:n,height:n});if(this.observerMapImageryBounds!==i)return;this.observerMapImagery=a,this.observerMapImageryCredit=s.attribution,this.observerMapImageryFailed=!1}catch{if(this.observerMapImageryBounds!==i)return;this.observerMapImageryFailed=this.observerMapImagery===void 0}finally{this.observerMapImageryBounds===i&&(this.observerMapImageryLoading=!1)}this.paintObserverMap(this.currentTime),this.scheduleObserverMapImagery()}static OBSERVER_MAP_IMAGERY_AHEAD=.5;static OBSERVER_MAP_IMAGERY_LOOKAHEAD=.25;observerMapImageryNeededFor(e){const t=this.observerMapImageryBounds;if(!t)return!0;const i=this.observerMapImagery?.bounds??t,n=this.observerMapView.changed?Vt.expand(e,ui.OBSERVER_MAP_IMAGERY_LOOKAHEAD):e,s=n.west>=i.west&&n.east<=i.east&&n.south>=i.south&&n.north<=i.north,a=e.east-e.west>this.observerMapImageryViewWidth/2;return!s||!a}get observerMapCredit(){return this.observerMapImageryCredit}get observerMapFooterLine(){return this.observerMapImageryFailed?this.messages.mapImageryUnavailable:this.creditShownExternally?void 0:this.observerMapImageryCredit}mapShapeBounds=[];mapSceneBounds=[];setMapSubjectBounds(e){this.mapSceneBounds=e.map(t=>({x:t.x*this.canvas.width,y:t.y*this.canvas.height,width:t.width*this.canvas.width,height:t.height*this.canvas.height})),this.keepObserverMapClear()}keepObserverMapClear(){if(this.observerMapPanel.hidden)return;const e=this.observerMapBoxPx;if(!e)return;const t=[...this.mapShapeBounds,...this.mapSceneBounds],i=(l,h,u)=>{for(const d of t)if(!(d.x+d.width<l-u||d.x>h+u)&&!(d.y>e.bottom+u||d.y+d.height<e.top-u))return!0;return!1},n=[this.canvas.width-e.width,this.canvas.width],s=[0,e.width],a=ui.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],a))&&this.observerMapPanel.classList.remove("on-the-left");return}i(n[0],n[1],0)&&!i(s[0],s[1],0)&&this.observerMapPanel.classList.add("on-the-left")}observerMapBoxPx;static OBSERVER_MAP_CLEARANCE_PX=24;sizeObserverMapCanvas(){const e=this.observerMapPanel.clientWidth;if(e===0)return;const t=Math.round(e*(globalThis.devicePixelRatio??1));this.measureObserverMapBox(),this.observerMapCanvas.width!==t&&(this.observerMapCanvas.width=t,this.observerMapCanvas.height=t)}measureObserverMapBox(){const e=this.observerMapPanel.getBoundingClientRect(),t=this.canvas.getBoundingClientRect();if(t.width===0||t.height===0)return;const i=this.canvas.width/t.width,n=this.canvas.height/t.height;this.observerMapBoxPx={width:e.width*i,top:(e.top-t.top)*n,bottom:(e.bottom-t.top)*n}}paintObserverMap(e){if(this.observerMapPanel.hidden||!this.observerPath||!this.observerMapBounds)return;const t=jt(this.currentSighting,e);t?.lat!==void 0&&t.lng!==void 0&&!this.observerMapDrag?.moved&&this.observerMapView.keepInView(this.observerMapBounds,{lat:t.lat,lng:t.lng},ui.OBSERVER_MAP_FOLLOW_MARGIN)&&this.scheduleObserverMapImagery();const i=this.currentSighting.instrument,n=[],s=this.currentSighting.milestones.length>0?Cf(this.currentSighting.milestones,e):void 0;for(const a of this.milestonesShown?xl(this.currentSighting.milestones):[]){const o=jt(this.currentSighting,a.t);o?.lat===void 0||o.lng===void 0||n.push({label:this.said.read(a.label)??"",note:this.said.read(a.note),t:a.t,lat:o.lat,lng:o.lng,current:a===s})}this.observerMapRenderer.paint({bounds:this.observerMapViewBounds,imagery:this.observerMapImagery,path:this.observerPath,position:t?.lat!==void 0&&t.lng!==void 0?{lat:t.lat,lng:t.lng}:void 0,headingDeg:t?.headingDeg===void 0?void 0:t.headingDeg+this.lookYawDeg,coneHalfAngleDeg:t?Ss.of(i,this.canvas.height,t.fovDeg).halfWidthAngleDeg(si.aspectOf(i)):void 0,markers:n,decor:this.observerMapDecorAt(e),observerLabel:this.said.read(this.currentSighting.observer?.title)??this.messages.observerHere,nightFraction:this.observerMapNightFraction,attribution:this.observerMapFooterLine})}toggleMilestones(){this.setMilestonesShown(!this.milestonesShown)}setMilestonesShown(e){this.milestonesShown=e,this.milestoneMarks.hidden=!e,this.milestonesButton.setAttribute("aria-pressed",String(e)),this.updateMilestonesButton(),this.showMilestoneAt(this.currentTime),this.paintObserverMap(this.currentTime)}updateMilestonesButton(){this.milestonesButton.hidden=this.currentSighting.milestones.length===0;const e=this.milestonesShown?this.messages.hideMilestones:this.messages.showMilestones;this.milestonesButton.title=e,this.milestonesButton.setAttribute("aria-label",e)}observerMapDecorAt(e){const t=jt(this.currentSighting,0);return t?.lat===void 0||t.lng===void 0?[]:this.currentSighting.decor.filter(i=>i.kind!=="crop").map(i=>{const n=Or(i,e),{lat:s,lng:a}=_s(n.eastM,-n.northM,t.lat,t.lng);return{lat:s,lng:a,headingDeg:n.headingDeg,label:this.said.read(i.title)??this.messages.decorHere}})}observerMapNightFraction;setSunAltitude(e){const t=e===void 0?void 0:Math.max(0,Math.min(1,-e/12));t!==this.observerMapNightFraction&&(this.observerMapNightFraction=t,this.paintObserverMap(this.currentTime))}setLookOffset(e,t){e===this.lookYawDeg&&t===this.lookPitchDeg||(this.lookYawDeg=e,this.lookPitchDeg=t,this.refresh())}get frameShiftPx(){return this.frameShift}get frameShift(){const e=this.gaitAt(this.currentTime),t=this.lookYawDeg+e.yawDeg,i=this.lookPitchDeg+e.pitchDeg;if(t===0&&i===0)return{x:0,y:0};const n=jt(this.currentSighting,this.currentTime),s=Ss.of(this.currentSighting.instrument,this.canvas.height,n?.fovDeg??60);return{x:-s.angleDegToRadiusPx(t),y:s.angleDegToRadiusPx(i)}}gaitAt(e){return xt.bodyAt(this.currentSighting,e,this.steadyObserver)}updateFullscreenButton(){const e=this.simulatedFullscreen||document.fullscreenElement===this.fullscreenTarget;this.fullscreenButton.title=e?this.messages.exitFullscreen:this.messages.fullscreen,this.fullscreenButton.setAttribute("aria-label",this.fullscreenButton.title)}get said(){return this.saidTexts??=new On(Fr.preferencesFor(this))}saidTexts;async loadLocaleMessages(){const e=o0(Fr.preferencesFor(this),c0);if(e===this.messagesLanguage||e==="en"&&this.messagesLanguage===void 0)return;this.messagesLanguage=e;const t=await g2(e);this.messagesLanguage===e&&this.applyMessages(t)}messagesLanguage;updateTimeLabelTitles(){const e=this.showClockTime?this.messages.switchToElapsed:this.messages.switchToClockTime,t=this.canSwitchTimeDisplay?` — ${e}`:"";this.timeStartLabel.title=this.messages.currentPosition+t,this.timeEndLabel.title=this.messages.duration+t;for(const i of[this.timeStartLabel,this.timeEndLabel])i.classList.toggle("switchable",this.canSwitchTimeDisplay),this.canSwitchTimeDisplay?(i.setAttribute("role","button"),i.setAttribute("tabindex","0")):(i.removeAttribute("role"),i.removeAttribute("tabindex"))}applyMessages(e){this.messages=e,this.updateTimeLabelTitles(),this.updatePlayPauseButton(),this.updateFullscreenButton(),this.updateObserverMapButton(),this.updateReferencesButton(),this.updateMilestonesButton(),this.renderIssues()}updateTimeLabels(){const e=this.currentSighting.event,t=xg(e);this.realDurationMs=t!==void 0&&t>0?t:void 0,this.realStartMs=e.time?Cu(e.time):void 0;const i=this.currentSighting.timeline.duration;this.player.playbackRate=this.realDurationMs!==void 0&&i>0?i/this.realDurationMs:1,this.player.durationOverrideMs=i>0?0:this.realDurationMs??0,this.timeEndLabel.textContent=this.formatEndOfTimeline(),this.timeStartLabel.textContent=this.formatPosition(this.player.time),this.updateTimeLabelTitles()}formatPosition(e){if(this.realDurationMs===void 0)return cc(e);const t=this.currentSighting.timeline.duration,i=t>0&&e<=t?e/t*this.realDurationMs:e;return this.canShowClockTime?Ff(Nf(this.realStartMs+i)):cc(i)}formatEndOfTimeline(){return this.realDurationMs===void 0?cc(this.currentSighting.timeline.duration):this.canShowClockTime?Ff(Nf(this.realStartMs+this.realDurationMs)):cc(this.realDurationMs)}}function Nf(r){const e=new Date(r);return{hour:e.getUTCHours(),minute:e.getUTCMinutes(),second:e.getUTCSeconds()}}function Ff(r){if(r.hour===void 0)return"0:00";const e=t=>String(t).padStart(2,"0");return r.second?`${e(r.hour)}:${e(r.minute??0)}:${e(r.second)}`:`${e(r.hour)}:${e(r.minute??0)}`}function cc(r){const e=Math.round(r/1e3),t=Math.floor(e/60),i=e%60;return`${t}:${String(i).padStart(2,"0")}`}const Lu="rr0-ufo";function Ug(){customElements.get(Lu)||customElements.define(Lu,ui)}const U2="recordingissues";/**
|
|
1301
|
+
`)}`)}}class An{constructor(e){this.format=e}issues(e){const t=[];return this.object(e,this.format,"",t),t}object(e,t,i,n){if(!An.isObject(e)){n.push({kind:"wrong-type",path:i||"(the file)",expected:"object",found:An.typeOf(e)});return}for(const[s,a]of Object.entries(e)){const o=i?`${i}.${s}`:s,c=t[s];c?this.field(a,c,o,n):n.push({kind:"unknown-key",path:o})}}field(e,t,i,n){if(An.isStated(e)){this.field(e.value,t,i,n);return}if(!(t.loose||e===void 0||e===null))switch(t.type){case"enum":(typeof e!="string"||!t.values?.includes(e))&&n.push({kind:"not-in-list",path:i,expected:(t.values??[]).map(s=>`"${s}"`).join(", "),found:JSON.stringify(e)});return;case"object":t.fields?this.object(e,t.fields,i,n):An.isObject(e)||n.push({kind:"wrong-type",path:i,expected:"object",found:An.typeOf(e)});return;case"array":Array.isArray(e)?t.fields&&e.forEach((s,a)=>{const o=An.isStated(s)?s.value:s;this.object(o,t.fields,`${i}.${a}`,n)}):n.push({kind:"wrong-type",path:i,expected:"array",found:An.typeOf(e)});return;default:typeof e!==t.type&&n.push({kind:"wrong-type",path:i,expected:t.type,found:An.typeOf(e)})}}static isObject(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}static isStated(e){return An.isObject(e)&&"value"in e&&Object.keys(e).every(t=>t==="value"||t==="basis"||t==="rationale")}static typeOf(e){return Array.isArray(e)?"array":e===null?"null":typeof e}}class Pn{static PIXELS_PER_INSTANT=2;static INSTANTS_PER_FLASH=2;static MAX_INSTANTS=512;static windowEndingAt(e,t){const i=Number.isFinite(t)?Math.max(0,t):0,n=Math.max(0,e-i*1e3),s=Math.max(0,e-n);return{fromMs:n,toMs:e,ms:s,seconds:s/1e3}}static instants(e,t,i,n,s){if(!(n>0))return 1;const a=s>0?Pn.travelDegOver(e,t,i,i+n*1e3)/s/Pn.PIXELS_PER_INSTANT:0,o=Pn.flashesOver(e,n)*Pn.INSTANTS_PER_FLASH,c=Math.ceil(Math.max(a,o));return c<2?1:Math.min(Pn.MAX_INSTANTS,c)}static travelDegOver(e,t,i,n){let s=0;for(const a of e){if(!a.track||a.track.length<2)continue;const o=Pn.directionAt(a,t,i),c=Pn.directionAt(a,t,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(e,t){let i=0;for(const n of e)for(const s of n.lights??[])s.pattern.kind==="flash"&&(i=Math.max(i,s.pattern.perMinute));return i/60*t}static directionAt(e,t,i){const n=Or(e,i),s=n.eastM,a=n.altitudeM-t,o=n.northM,c=Math.hypot(s,a,o);return c===0?{x:0,y:1,z:0}:{x:s/c,y:a/c,z:o/c}}}function o0(r,e){for(const t of r){const i=t.toLowerCase().split("-")[0];if(e.includes(i))return i}return"en"}class Fr{static preferencesFor(e){const t=navigator.languages??[],i=this.declaredFor(e);return i?[i,...t]:t}static declaredFor(e){for(let t=e;t;){const i=t.closest("[lang]")?.getAttribute("lang")?.trim();if(i)return i;const n=t.getRootNode();t=n instanceof ShadowRoot?n.host:void 0}}}class On{constructor(e){this.preferences=e}read(e){if(e===void 0||typeof e=="string")return e===""?void 0:e;for(const i of this.preferences){const n=e[i]??e[On.base(i)];if(n)return n}const t=new Set(this.preferences.map(i=>On.base(i)));for(const[i,n]of Object.entries(e))if(n&&t.has(On.base(i)))return n;return Object.values(e).find(i=>i)??void 0}write(e,t,i){const n=t?.trim()?t.trim():void 0;if(e===void 0||typeof e=="string")return n;const s={...e},a=Object.keys(s).find(o=>o===i)??Object.keys(s).find(o=>On.base(o)===On.base(i))??i;return n===void 0?delete s[a]:s[a]=n,Object.keys(s).length===0?void 0:s}static base(e){return e.toLowerCase().split("-")[0]}}const c0=["en","fr","es","it"],m2={en:()=>pi(()=>Promise.resolve().then(()=>y2),void 0,import.meta.url).then(r=>r.ufoMessages_en),fr:()=>pi(()=>import("./UfoMessages_fr-DDeCjNS8.js"),[],import.meta.url).then(r=>r.ufoMessages_fr),es:()=>pi(()=>import("./UfoMessages_es-CzuRdJdo.js"),[],import.meta.url).then(r=>r.ufoMessages_es),it:()=>pi(()=>import("./UfoMessages_it-C2dUwy6T.js"),[],import.meta.url).then(r=>r.ufoMessages_it)};function g2(r){return m2[r]()}const v2={en:()=>pi(()=>Promise.resolve().then(()=>AA),void 0,import.meta.url).then(r=>r.sightingMessages_en),fr:()=>pi(()=>import("./SightingMessages_fr-DuTf6Jr9.js"),[],import.meta.url).then(r=>r.sightingMessages_fr),es:()=>pi(()=>import("./SightingMessages_es-DamT2_69.js"),[],import.meta.url).then(r=>r.sightingMessages_es),it:()=>pi(()=>import("./SightingMessages_it-jYUbX7ci.js"),[],import.meta.url).then(r=>r.sightingMessages_it)};function M2(r){return v2[r]()}function x2(r){switch(r){case"fr":return pi(()=>import("./TagNames_fr-Dnqq6HQ5.js"),[],import.meta.url).then(e=>e.tagNames_fr);case"es":return pi(()=>import("./TagNames_es-BfnMpc3D.js"),[],import.meta.url).then(e=>e.tagNames_es);case"it":return pi(()=>import("./TagNames_it-n6E4EGYO.js"),[],import.meta.url).then(e=>e.tagNames_it);default:return Promise.resolve({})}}function Ag(r){switch(r){case"fr":return pi(()=>import("./SceneNames_fr-0Wzm8zKy.js"),[],import.meta.url).then(e=>e.sceneNames_fr);case"es":return pi(()=>import("./SceneNames_es-C1QdYSKO.js"),[],import.meta.url).then(e=>e.sceneNames_es);case"it":return pi(()=>import("./SceneNames_it-C5oOps-9.js"),[],import.meta.url).then(e=>e.sceneNames_it);default:return Promise.resolve(void 0)}}const Tg={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",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",referenceOpacity:"Picture opacity",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:Nr.EN},y2=Object.freeze(Object.defineProperty({__proto__:null,ufoMessages_en:Tg},Symbol.toStringTag,{value:"Module"})),Rg=Math.PI/180,b2=180/Math.PI,_2=256,Dg=19,S2=1.25;function Ig(r,e){return 156543.03392*Math.cos(r*Rg)/2**e}function Cg(r,e){return Ig(r,e)*_2}function w2(r,e){let t=0;for(;t<Dg&&Cg(r,t+1)>=e;)t++;return t}function Pg(r,e){return Cg(r,e)}function E2(r,e){const t=e*S2;let i=0;for(;i<Dg&&Ig(r,i)>t;)i++;return i}function al(r){const e=r*Rg;return(1-Math.log(Math.tan(e)+1/Math.cos(e))/Math.PI)/2}function Lg(r,e,t){const i=2**t;return{x:(r+180)/360*i,y:al(e)*i}}function Og(r,e,t){const i=al(r.north),n=al(r.south);return{x:(e-r.west)/(r.east-r.west),y:(al(t)-i)/(n-i)}}function A2(r,e,t){const{x:i,y:n}=Lg(r,e,t);return{x:Math.floor(i),y:Math.floor(n),z:t}}function T2(r){const e=2**r.z,t=r.x/e*360-180,i=(r.x+1)/e*360-180,n=Pf(r.y,e);return{south:Pf(r.y+1,e),north:n,west:t,east:i}}function Pf(r,e){const t=r/e;return Math.atan(Math.sinh(Math.PI*(1-2*t)))*b2}function Ng(r,e,t,i){const n=A2(r,e,t),s=Math.floor(i/2),a=[];for(let l=-s;l<=s;l++)for(let h=-s;h<=s;h++)a.push({x:n.x+h,y:n.y+l,z:t});const o=a.map(T2),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:a,bounds:c}}class ya{constructor(e){this.ctx=e}static SCALE_STEPS_M=[5e3,2e3,1e3,500,200,100,50,20,10,5];static MARKER_RADIUS_PX=8.5;static ON_MARKER_M=3;targets=[];hitTest(e,t){let i,n=1/0;for(const s of this.targets){const a=Math.hypot(s.x-e,s.y-t);a>s.radius||a>n||(i=s,n=a)}return i}get width(){return this.ctx.canvas.width}get height(){return this.ctx.canvas.height}paint(e){const{ctx:t}=this;t.save(),this.targets=[],t.clearRect(0,0,this.width,this.height),this.paintGround(e),this.paintNight(e.nightFraction),this.paintPath(e),e.position?(this.paintCone(e,e.position),this.paintDecor(e),this.paintMarkers(e),this.paintObserver(e,e.position)):(this.paintDecor(e),this.paintMarkers(e)),this.paintNorth(),this.paintFooter(e.bounds,e.attribution),t.restore()}toCanvas(e,t,i){const n=Og(e,i,t);return{x:n.x*this.width,y:n.y*this.height}}paintGround(e){const{ctx:t}=this;t.fillStyle="#1d2321",t.fillRect(0,0,this.width,this.height);const i=e.imagery;if(!i)return;const n=this.toCanvas(e.bounds,i.bounds.north,i.bounds.west),s=this.toCanvas(e.bounds,i.bounds.south,i.bounds.east);t.drawImage(i.source,n.x,n.y,s.x-n.x,s.y-n.y)}paintNight(e=0){if(e<=0)return;const{ctx:t}=this;t.save(),t.fillStyle=`rgba(6, 12, 30, ${Math.min(e,1)*.78})`,t.fillRect(0,0,this.width,this.height),t.restore()}paintDecor(e){const{ctx:t}=this;for(const i of e.decor){const n=this.toCanvas(e.bounds,i.lat,i.lng);if(i.label&&this.targets.push({kind:"decor",label:i.label,lat:i.lat,lng:i.lng,x:n.x,y:n.y,radius:7}),t.beginPath(),t.rect(n.x-3.5,n.y-3.5,7,7),t.fillStyle="rgba(120, 220, 255, 0.85)",t.fill(),t.lineWidth=1.5,t.strokeStyle="rgba(0, 0, 0, 0.7)",t.stroke(),i.headingDeg===void 0)continue;const s=(i.headingDeg-90)*Math.PI/180;t.beginPath(),t.moveTo(n.x,n.y),t.lineTo(n.x+Math.cos(s)*10,n.y+Math.sin(s)*10),t.lineWidth=3,t.strokeStyle="rgba(0, 0, 0, 0.6)",t.stroke(),t.lineWidth=1.5,t.strokeStyle="rgba(120, 220, 255, 0.9)",t.stroke()}}paintPath(e){if(!e.path.moved)return;const{ctx:t}=this,i=e.path.points.map(n=>this.toCanvas(e.bounds,n.lat,n.lng));t.beginPath(),t.moveTo(i[0].x,i[0].y);for(const n of i.slice(1))t.lineTo(n.x,n.y);t.lineJoin="round",t.lineCap="round",t.strokeStyle="rgba(0, 0, 0, 0.65)",t.lineWidth=5,t.stroke(),t.strokeStyle="rgba(255, 255, 255, 0.9)",t.lineWidth=2,t.stroke()}paintCone(e,t){const{headingDeg:i,coneHalfAngleDeg:n}=e;if(i===void 0||n===void 0)return;const{ctx:s}=this,a=this.toCanvas(e.bounds,t.lat,t.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(a.x,a.y),s.arc(a.x,a.y,o,c-l,c+l),s.closePath();const h=s.createRadialGradient(a.x,a.y,0,a.x,a.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(e){const{ctx:t}=this;t.textAlign="center",t.textBaseline="middle",t.font="bold 10px sans-serif";for(const i of[...e.markers].sort((n,s)=>Number(n.current)-Number(s.current))){const n=this.toCanvas(e.bounds,i.lat,i.lng);this.targets.push({kind:"milestone",label:i.note?`${i.label} — ${i.note}`:i.label,lat:i.lat,lng:i.lng,t:i.t,x:n.x,y:n.y,radius:ya.MARKER_RADIUS_PX}),t.beginPath(),t.arc(n.x,n.y,ya.MARKER_RADIUS_PX,0,Math.PI*2),t.fillStyle=i.current?"rgba(255, 224, 130, 0.95)":"rgba(0, 0, 0, 0.55)",t.fill(),t.lineWidth=2,t.strokeStyle="rgba(255, 255, 255, 0.9)",t.stroke(),t.fillStyle=i.current?"#1d2321":"#fff",t.fillText(i.label,n.x,n.y)}}paintObserver(e,t){const{ctx:i}=this,n=this.toCanvas(e.bounds,t.lat,t.lng);e.observerLabel&&this.targets.push({kind:"observer",label:e.observerLabel,lat:t.lat,lng:t.lng,x:n.x,y:n.y,radius:8});const s=e.markers.some(a=>{if(!a.current)return!1;const o=ni(a.lat,a.lng,t.lat,t.lng);return Math.hypot(o.x,o.z)<=ya.ON_MARKER_M});i.beginPath(),i.arc(n.x,n.y,s?ya.MARKER_RADIUS_PX+2.5:5.5,0,Math.PI*2),s||(i.fillStyle="#ff5a3c",i.fill()),i.lineWidth=4,i.strokeStyle="rgba(0, 0, 0, 0.5)",i.stroke(),i.lineWidth=s?3:2.5,i.strokeStyle=s?"#ff5a3c":"#fff",i.stroke()}paintNorth(){const{ctx:e}=this,t=this.width-14,i=16;e.beginPath(),e.moveTo(t,i-9),e.lineTo(t-4.5,i+5),e.lineTo(t,i+2),e.lineTo(t+4.5,i+5),e.closePath(),e.fillStyle="rgba(255, 255, 255, 0.92)",e.strokeStyle="rgba(0, 0, 0, 0.6)",e.lineWidth=1,e.fill(),e.stroke(),e.font="bold 9px sans-serif",e.textAlign="center",e.textBaseline="top",e.strokeText("N",t,i+6),e.fillText("N",t,i+6)}paintFooter(e,t){const{ctx:i}=this;i.font="9px sans-serif",i.textBaseline="bottom";const n=t?this.wrap(t,this.width-20):[];let s=this.height-4;i.textAlign="right";for(const f of n.slice().reverse())this.paintOutlinedText(f,this.width-6,s),s-=11;const a=(e.south+e.north)/2,c=Math.abs(ni(a,e.east,a,e.west).x)/this.width,l=ya.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(e,t,i){const{ctx:n}=this;n.lineWidth=3,n.strokeStyle="rgba(0, 0, 0, 0.75)",n.strokeText(e,t,i),n.fillStyle="#fff",n.fillText(e,t,i)}wrap(e,t){const i=[];let n="";for(const s of e.split(" ")){const a=n?`${n} ${s}`:s;n&&this.ctx.measureText(a).width>t?(i.push(n),n=s):n=a}return n&&i.push(n),i}}class Vt{static MIN_ZOOM=.25;static MAX_ZOOM=64;zoom=1;centerX=.5;centerY=.5;get changed(){return this.zoom!==1||this.centerX!==.5||this.centerY!==.5}get zoomFactor(){return this.zoom}reset(){this.zoom=1,this.centerX=.5,this.centerY=.5}zoomAt(e,t,i){const n=Math.min(Vt.MAX_ZOOM,Math.max(Vt.MIN_ZOOM,this.zoom*i)),s=this.centerX+(e-.5)/this.zoom,a=this.centerY+(t-.5)/this.zoom;this.centerX=s-(e-.5)/n,this.centerY=a-(t-.5)/n,this.zoom=n}panBy(e,t){this.centerX-=e/this.zoom,this.centerY-=t/this.zoom}refit(e,t){if(!this.changed)return;const i=this.boundsWithin(e),n=Vt.mercatorY01(t.north),s=Vt.mercatorY01(t.south),a=Vt.mercatorY01(i.north),o=Vt.mercatorY01(i.south);this.zoom=(t.east-t.west)/(i.east-i.west),this.centerX=((i.west+i.east)/2-t.west)/(t.east-t.west),this.centerY=((a+o)/2-n)/(s-n)}keepInView(e,t,i){if(!this.changed)return!1;const n=this.boundsWithin(e),s=Vt.mercatorY01(n.north),a=Vt.mercatorY01(n.south),o=(t.lng-n.west)/(n.east-n.west),c=(Vt.mercatorY01(t.lat)-s)/(a-s);return o>=i&&o<=1-i&&c>=i&&c<=1-i?!1:(this.panBy(.5-o,.5-c),!0)}boundsWithin(e){if(!this.changed)return e;const t=.5/this.zoom,i=Vt.mercatorY01(e.north),n=Vt.mercatorY01(e.south),s=e.east-e.west;return{west:e.west+(this.centerX-t)*s,east:e.west+(this.centerX+t)*s,north:Vt.latitudeAt(i+(this.centerY-t)*(n-i)),south:Vt.latitudeAt(i+(this.centerY+t)*(n-i))}}static expand(e,t){const i=e.east-e.west,n=e.north-e.south;return{west:e.west-i*t,east:e.east+i*t,south:e.south-n*t,north:e.north+n*t}}static pointAt(e,t,i){const n=Vt.mercatorY01(e.north),s=Vt.mercatorY01(e.south);return{lat:Vt.latitudeAt(n+i*(s-n)),lng:e.west+t*(e.east-e.west)}}static mercatorY01(e){const t=e*Math.PI/180;return(1-Math.log(Math.tan(t)+1/Math.cos(t))/Math.PI)/2}static latitudeAt(e){return Math.atan(Math.sinh(Math.PI*(1-2*e)))*180/Math.PI}}const pn=256,Lf=3,R2=32768;class D2{fetchImpl;tileUrlTemplate;constructor(e={}){this.fetchImpl=e.fetchImpl??fetch.bind(globalThis),this.tileUrlTemplate=e.tileUrlTemplate??"https://s3.amazonaws.com/elevation-tiles-prod/terrarium/{z}/{x}/{y}.png"}async getElevationGrid(e,t){const i=(e.south+e.north)/2,n=(e.west+e.east)/2,s=Math.abs(ni(i,e.east,i,e.west).x),a=Math.abs(ni(e.north,n,e.south,n).z),o=w2(i,Math.max(s,a)),{tiles:c}=Ng(n,i,o,Lf),l=Lf*pn,h=new Float32Array(l*l),u=c[0];await Promise.all(c.map(f=>this.decodeTileInto(f,u,h,l)));const d=new Float32Array(t.width*t.height);for(let f=0;f<t.height;f++){const p=e.north+(e.south-e.north)*(f/(t.height-1));for(let v=0;v<t.width;v++){const m=e.west+(e.east-e.west)*(v/(t.width-1));d[f*t.width+v]=this.sampleAt(p,m,o,u,h,l)}}return{heights:d,width:t.width,height:t.height,bounds:e}}async decodeTileInto(e,t,i,n){const s=this.tileUrlTemplate.replace("{z}",String(e.z)).replace("{x}",String(e.x)).replace("{y}",String(e.y)),a=await this.fetchImpl(s);if(!a.ok)throw new Error(`Elevation tile fetch failed (${a.status}): ${s}`);const o=await createImageBitmap(await a.blob()),c=document.createElement("canvas");c.width=pn,c.height=pn;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,pn,pn),u=(e.x-t.x)*pn,d=(e.y-t.y)*pn;for(let f=0;f<pn;f++)for(let p=0;p<pn;p++){const v=(f*pn+p)*4,m=h[v]*256+h[v+1]+h[v+2]/256-R2,g=u+p,_=d+f;i[_*n+g]=m}}sampleAt(e,t,i,n,s,a){const{x:o,y:c}=Lg(t,e,i),l=(o-n.x)*pn,h=(c-n.y)*pn,u=Math.max(0,Math.min(a-1,Math.floor(l))),d=Math.max(0,Math.min(a-1,Math.floor(h))),f=Math.min(a-1,u+1),p=Math.min(a-1,d+1),v=l-u,m=h-d,g=s[d*a+u],_=s[d*a+f],b=s[p*a+u],M=s[p*a+f],S=g+(_-g)*v,w=b+(M-b)*v;return S+(w-S)*m}}const rl=256,I2=5;async function C2(r,e,t,i){const n=(r.south+r.north)/2,s=(r.west+r.east)/2,a=Math.abs(ni(n,r.east,n,r.west).x),o=Math.abs(ni(r.north,s,r.south,s).z),c=Math.max(a,o),{zoom:l,gridSize:h}=P2(n,c,Math.max(e.width,e.height)),{tiles:u,bounds:d}=Ng(s,n,l,h),f=h*rl,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 S=t(M),w=await i(S);if(!w.ok)throw new Error(`Imagery tile fetch failed (${w.status}): ${S}`);const T=await createImageBitmap(await w.blob());v.drawImage(T,(M.x-m.x)*rl,(M.y-m.y)*rl)}));const g=Math.min(Math.max(e.width,e.height),f);if(g===f)return{source:p,width:f,height:f,bounds:d};const _=document.createElement("canvas");_.width=g,_.height=g;const b=_.getContext("2d");if(!b)throw new Error("2D canvas context unavailable");return b.drawImage(p,0,0,f,f,0,0,g,g),{source:_,width:g,height:g,bounds:d}}function P2(r,e,t){let i=E2(r,e/Math.max(1,t)),n=Of(r,i,e);for(;n>I2&&i>0;)i--,n=Of(r,i,e);return{zoom:i,gridSize:n,mPerPixel:Pg(r,i)/rl}}function Of(r,e,t){const i=Math.ceil(t/2/Pg(r,e));return Math.max(3,2*i+1)}class L2{attribution="Imagery © Esri, Maxar, Earthstar Geographics, and the GIS User Community";fetchImpl;tileUrlTemplate;constructor(e={}){this.fetchImpl=e.fetchImpl??fetch.bind(globalThis),this.tileUrlTemplate=e.tileUrlTemplate??"https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"}async getImageryTexture(e,t){return C2(e,t,i=>this.tileUrlTemplate.replace("{z}",String(i.z)).replace("{y}",String(i.y)).replace("{x}",String(i.x)),this.fetchImpl)}}class Tn{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(e={}){this.fetchImpl=e.fetchImpl??fetch.bind(globalThis),this.endpoints=e.endpoints??Tn.ENDPOINTS}static queue=Promise.resolve();static RETRY_MS=4e3;async getRoads(e){const t=`${e.south},${e.west},${e.north},${e.east}`,i=`[out:json][timeout:30];way["highway"~"^(${Tn.DRIVABLE.join("|")})$"](${t});out geom;`;return this.waysFrom(await this.queued(()=>this.ask(i)))}waysFrom(e){const t=[];for(const i of e.elements??[]){const n=i.geometry,s=i.tags;!s||!n||n.length<2||t.push({id:`osm-${i.id??t.length}`,name:s.name,surface:Tn.surfaceOf(s),widthM:Tn.widthOf(s),points:n.map(a=>({lat:a.lat,lng:a.lon}))})}return t}queued(e){const t=Tn.queue.then(e,e);return Tn.queue=t.catch(()=>{}),t}async ask(e){let t;for(const i of this.endpoints)for(let n=0;n<2;n++){try{const s=await this.fetchImpl(`${i}?data=${encodeURIComponent(e)}`);if(s.ok)return await s.json();if(t=new Error(`${new URL(i).host} refused (${s.status})`),s.status!==429&&s.status!==504)break}catch(s){t=new Error(`${new URL(i).host} unreachable (${String(s)})`);break}await new Promise(s=>setTimeout(s,Tn.RETRY_MS))}throw t??new Error("No Overpass instance answered")}static widthOf(e){const t=Number.parseFloat(e.width??e.est_width??"");if(Number.isFinite(t)&&t>0)return t;const i=Number.parseInt(e.lanes??"",10);return Number.isFinite(i)&&i>0?i*3.5:Tn.WIDTH_M[e.highway]??Tn.DEFAULT_WIDTH_M}static surfaceOf(e){const t=e.surface;return t==="dirt"||t==="earth"||t==="mud"?"dirt":t==="gravel"||t==="fine_gravel"||t==="compacted"||t==="ground"||t==="sand"||t==="unpaved"?"gravel":t?"paved":e.highway==="track"?"gravel":"paved"}}const lh="https://ufoathome.org/roads/index.json";class l0{attributionRead;contemporaryRead;fetchImpl;indexUrls;fallback;index;constructor(e={}){this.fetchImpl=e.fetchImpl??fetch.bind(globalThis),this.indexUrls=e.indexUrls??l0.defaultIndexUrls(),this.fallback=e.fallback}get attribution(){return this.attributionRead??this.fallback?.attribution??"Roads © OpenStreetMap contributors"}get contemporary(){return this.contemporaryRead??this.fallback?.contemporary??!0}async getRoads(e){const t=await this.held(e);if(t)return t;if(!this.fallback)return[];const i=await this.fallback.getRoads(e);return this.attributionRead=this.fallback.attribution,this.contemporaryRead=this.fallback.contemporary,i}async held(e){let t;try{t=await this.load()}catch{return}const i=t.find(({entry:n})=>n.north>=e.north&&n.south<=e.south&&n.east>=e.east&&n.west<=e.west);if(i)try{const n=await this.fetchImpl(new URL(i.entry.file,i.indexUrl).href);if(!n.ok)return;const s=await n.json();return Array.isArray(s?.ways)?(this.attributionRead=s.attribution,this.contemporaryRead=s.contemporary,s.ways):void 0}catch{return}}load(){return this.index??=this.fetchFirstAvailable(),this.index}async fetchFirstAvailable(){for(const e of this.indexUrls)try{const t=await this.fetchImpl(e);if(!t.ok)continue;const i=await t.json();if(Array.isArray(i?.entries))return i.entries.map(n=>({entry:n,indexUrl:e}))}catch{}return[]}static defaultIndexUrls(){const e=`?v=${encodeURIComponent("0.74.1")}`,t=typeof location>"u"?void 0:new URL("/roads/index.json",location.href).href;return(t&&t!==lh?[t,lh]:[lh]).map(i=>i+e)}}function O2(){return{elevation:new D2,imagery:Fg(),roads:N2()}}function Fg(){return new L2}function N2(){return new l0({fallback:new Tn})}const F2=new Set,Es="show-observer-map",As="hide-milestones";class ui extends HTMLElement{static get observedAttributes(){return["src",Es,As]}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;observerMapButton;referencesButton;referenceOpacityInput;referencesShownState=!0;referenceOpacityTouched=!1;milestonesButton;observerMapPanel;observerMapCanvas;observerMapRenderer;mapZoomInButton;mapZoomOutButton;mapFitButton;observerMapView=new Vt;observerMapDrag;suppressObserverMapClick=!1;observerMapImageryTimer;observerPlacing=!1;seekInput;playbackFlash;milestoneMarks;milestoneCaption;timeStartLabel;timeEndLabel;observerPath;observerMapBounds;observerMapImagery;observerMapImageryBounds;observerMapImageryViewWidth=0;observerMapImageryLoading=!1;observerMapImageryCredit;observerMapImageryFailed=!1;creditShownExternally=!1;lookYawDeg=0;lookPitchDeg=0;milestonesShown=!0;currentSighting=Wl.create();issues=[];issueCheck=0;sightingAudio=new h2;soundPreview;player;loopEnabled=!1;playbackBeforeClick;highlightedSourceIds=new Set;paintsShapes=!0;steadyObserver=!1;selectionShown=!0;overlayPainter;enableClickToPlay=!0;fullscreenTarget;messages=Tg;realDurationMs;realStartMs;showClockTime=!0;handleFullscreenChange=()=>{this.updateFullscreenButton(),this.resizeObserverMap()};observerMapResizeObserver=typeof ResizeObserver>"u"?void 0:new ResizeObserver(()=>this.resizeObserverMap());resizeObserverMap(){this.observerMapPanel.hidden||(this.sizeObserverMapCanvas(),this.paintObserverMap(this.currentTime))}simulatedFullscreen=!1;styleBeforeSimulatedFullscreen;bodyOverflowBeforeSimulatedFullscreen;handleSimulatedFullscreenKey=e=>{e.key==="Escape"&&this.exitSimulatedFullscreen()};handlePointerMove=e=>{const t=this.canvasPointFromEvent(e),i=t&&this.shapeAt(t.x,t.y),n=this.said.read(i?.shape.title);if(!n){this.tooltip.hidden=!0;return}this.tooltip.textContent=n,this.tooltip.hidden=!1;const s=this.stageElement.getBoundingClientRect();this.tooltip.style.left=`${e.clientX-s.left+12}px`,this.tooltip.style.top=`${e.clientY-s.top+12}px`};handleObserverMapPointerMove=e=>{if(this.dragObserverMap(e))return;const t=this.observerMapTargetFrom(e);if(!t){if(!this.observerPlacing){this.tooltip.hidden=!0,this.observerMapCanvas.style.cursor="grab";return}this.observerMapCanvas.style.cursor="crosshair",this.showObserverMapTooltip(e,this.messages.placeObserverHere);return}this.observerMapCanvas.style.cursor="pointer",this.showObserverMapTooltip(e,t.label)};showObserverMapTooltip(e,t){this.tooltip.textContent=t,this.tooltip.hidden=!1;const i=this.stageElement.getBoundingClientRect();this.tooltip.style.left=`${e.clientX-i.left+12}px`,this.tooltip.style.top=`${e.clientY-i.top+12}px`}handleObserverMapClick=e=>{if(this.suppressObserverMapClick){this.suppressObserverMapClick=!1;return}const t=this.observerMapTargetFrom(e);if(!t){this.observerPlacing&&this.placeObserverFrom(e);return}if(t.kind==="milestone"&&t.t!==void 0){this.player.seek(t.t);return}this.dispatchEvent(new CustomEvent("lookat",{detail:{lat:t.lat,lng:t.lng,kind:t.kind},bubbles:!0,composed:!0}))};observerMapTargetFrom(e){const t=this.observerMapCanvas.getBoundingClientRect();if(!(t.width===0||t.height===0))return this.observerMapRenderer.hitTest((e.clientX-t.left)/t.width*this.observerMapCanvas.width,(e.clientY-t.top)/t.height*this.observerMapCanvas.height)}handlePointerLeave=()=>{this.tooltip.hidden=!0};handleObserverMapPointerDown=e=>{e.button===0&&(this.suppressObserverMapClick=!1,this.observerMapDrag={pointerId:e.pointerId,startX:e.clientX,startY:e.clientY,lastX:e.clientX,lastY:e.clientY,moved:!1})};handleObserverMapPointerUp=e=>{const t=this.observerMapDrag;!t||t.pointerId!==e.pointerId||(this.observerMapDrag=void 0,this.observerMapCanvas.classList.remove("dragging"),t.moved&&(this.suppressObserverMapClick=!0,this.paintObserverMap(this.currentTime),this.observerMapCanvas.hasPointerCapture?.(e.pointerId)&&this.observerMapCanvas.releasePointerCapture(e.pointerId)))};dragObserverMap(e){const t=this.observerMapDrag;if(!t||t.pointerId!==e.pointerId)return!1;if(!t.moved){if(Math.hypot(e.clientX-t.startX,e.clientY-t.startY)<ui.OBSERVER_MAP_DRAG_PX)return!1;t.moved=!0,this.tooltip.hidden=!0,this.observerMapCanvas.classList.add("dragging"),this.observerMapCanvas.setPointerCapture?.(e.pointerId)}const i=this.observerMapCanvas.getBoundingClientRect();return i.width>0&&i.height>0&&(this.observerMapView.panBy((e.clientX-t.lastX)/i.width,(e.clientY-t.lastY)/i.height),this.observerMapViewChanged()),t.lastX=e.clientX,t.lastY=e.clientY,!0}static OBSERVER_MAP_DRAG_PX=4;handleObserverMapWheel=e=>{e.preventDefault();const t=this.observerMapCanvas.getBoundingClientRect();if(t.width===0||t.height===0)return;const i=e.deltaMode===0?e.deltaY:e.deltaY*40;this.zoomObserverMap((e.clientX-t.left)/t.width,(e.clientY-t.top)/t.height,Math.exp(-i*.002))};zoomObserverMap(e,t,i){this.observerMapView.zoomAt(e,t,i),this.observerMapViewChanged()}observerMapViewChanged(){this.mapFitButton.hidden=!this.observerMapView.changed,this.mapZoomInButton.disabled=this.observerMapView.zoomFactor>=Vt.MAX_ZOOM,this.mapZoomOutButton.disabled=this.observerMapView.zoomFactor<=Vt.MIN_ZOOM,this.paintObserverMap(this.currentTime),this.scheduleObserverMapImagery()}scheduleObserverMapImagery(){this.observerMapImageryTimer===void 0&&(this.observerMapImageryTimer=setTimeout(()=>{this.observerMapImageryTimer=void 0,this.loadObserverMapImagery()},ui.OBSERVER_MAP_IMAGERY_DELAY_MS))}static OBSERVER_MAP_FOLLOW_MARGIN=.1;static OBSERVER_MAP_IMAGERY_DELAY_MS=300;get observerMapViewBounds(){return this.observerMapBounds&&this.observerMapView.boundsWithin(this.observerMapBounds)}placeObserverFrom(e){const t=this.observerMapViewBounds,i=this.observerMapCanvas.getBoundingClientRect();if(!t||i.width===0||i.height===0)return;const n=Vt.pointAt(t,(e.clientX-i.left)/i.width,(e.clientY-i.top)/i.height);this.dispatchEvent(new CustomEvent("observerplace",{detail:n,bubbles:!0,composed:!0}))}constructor(){super(),this.shadow=this.attachShadow({mode:"open"});const e=document.createElement("template");e.innerHTML=`<style>${i2}</style>${t2}`,this.shadow.appendChild(e.content.cloneNode(!0)),this.stageElement=this.shadow.getElementById("stage"),this.canvas=this.shadow.getElementById("canvas"),this.canvasRenderer=new zo(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",t=>{t.stopPropagation(),this.issuesPanel.hidden=!this.issuesPanel.hidden,this.issuesButton.setAttribute("aria-expanded",String(!this.issuesPanel.hidden))}),this.playPauseButton=this.shadow.getElementById("play-pause"),this.fullscreenButton=this.shadow.getElementById("fullscreen"),this.observerMapButton=this.shadow.getElementById("observer-map"),this.referencesButton=this.shadow.getElementById("references"),this.referenceOpacityInput=this.shadow.getElementById("reference-opacity"),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 ya(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");for(const t of[this.timeStartLabel,this.timeEndLabel])t.addEventListener("click",()=>this.toggleTimeDisplay()),t.addEventListener("keydown",i=>{i.key!=="Enter"&&i.key!==" "||(i.preventDefault(),this.toggleTimeDisplay())});this.fullscreenTarget=this.stageElement,this.playPauseButton.addEventListener("click",()=>this.togglePlayPause()),this.fullscreenButton.addEventListener("click",()=>this.toggleFullscreen()),this.observerMapButton.addEventListener("click",()=>this.toggleObserverMap()),this.referencesButton.addEventListener("click",()=>this.toggleReferences()),this.referenceOpacityInput.addEventListener("input",()=>{this.referenceOpacityTouched=!0,this.dispatchReferenceView()}),this.milestonesButton.addEventListener("click",()=>this.toggleMilestones()),this.observerMapCanvas.addEventListener("pointermove",this.handleObserverMapPointerMove),this.observerMapCanvas.addEventListener("pointerleave",this.handlePointerLeave),this.observerMapCanvas.addEventListener("click",this.handleObserverMapClick),this.observerMapCanvas.addEventListener("pointerdown",this.handleObserverMapPointerDown),this.observerMapCanvas.addEventListener("pointerup",this.handleObserverMapPointerUp),this.observerMapCanvas.addEventListener("pointercancel",this.handleObserverMapPointerUp),this.observerMapCanvas.addEventListener("wheel",this.handleObserverMapWheel,{passive:!1}),this.mapZoomInButton.addEventListener("click",()=>this.zoomObserverMap(.5,.5,2)),this.mapZoomOutButton.addEventListener("click",()=>this.zoomObserverMap(.5,.5,.5)),this.mapFitButton.addEventListener("click",()=>{this.observerMapView.reset(),this.observerMapViewChanged()}),this.seekInput.addEventListener("input",()=>this.player.seek(this.snapSeekToMark(Number(this.seekInput.value)))),this.seekInput.addEventListener("pointerdown",t=>{this.seekSnapArmed=!0,this.nameMarkUnder(t)}),this.seekInput.addEventListener("pointerup",()=>{this.seekSnapArmed=!1}),this.seekInput.addEventListener("pointermove",t=>this.nameMarkUnder(t)),this.seekInput.addEventListener("pointerleave",()=>this.seekInput.removeAttribute("title")),this.seekInput.addEventListener("keydown",this.handleSeekKey),this.canvas.addEventListener("click",t=>{this.enableClickToPlay&&(t.detail<=1&&(this.playbackBeforeClick={state:this.playbackState,time:this.currentTime}),this.togglePlayPause())}),this.canvas.addEventListener("dblclick",t=>{this.enableClickToPlay&&(t.preventDefault(),this.restorePlayback(),this.toggleFullscreen())}),this.canvas.addEventListener("pointermove",this.handlePointerMove),this.canvas.addEventListener("pointerleave",this.handlePointerLeave),document.addEventListener("fullscreenchange",this.handleFullscreenChange),this.observerMapResizeObserver?.observe(this.observerMapPanel),this.hostControls(void 0),this.player=this.createPlayer(),this.updateTimeLabels(),this.updatePlayPauseButton(),this.updateFullscreenButton(),this.updateObserverMapButton(),this.updateReferencesButton(),this.updateMilestonesButton(),this.refresh()}connectedCallback(){this.saidTexts=void 0,this.loadLocaleMessages();const e=this.getAttribute("src");e&&this.loadFromSrc(e)}disconnectedCallback(){document.removeEventListener("fullscreenchange",this.handleFullscreenChange),this.observerMapResizeObserver?.disconnect(),this.exitSimulatedFullscreen(),this.sightingAudio.dispose()}attributeChangedCallback(e,t,i){e==="src"&&i&&i!==t&&this.isConnected&&this.loadFromSrc(i),e===Es&&this.applyObserverMapDefault(),e===As&&this.setMilestonesShown(!this.hasAttribute(As))}async loadFromSrc(e){this.sightingData=await Ao.json(e)}get sightingData(){return u2(this.currentSighting)}set sightingData(e){this.player.stop(),this.soundPreview=void 0,this.sightingAudio.silence(),this.currentSighting=f2(e),this.issuesPanel.hidden=!0,this.issuesButton.setAttribute("aria-expanded","false"),this.reportIssues(e,this.currentSighting),this.observerMapView.reset(),this.mapFitButton.hidden=!0,this.observerMapAsked=!1,this.player=this.createPlayer(),this.updateTimeLabels(),this.updatePlayPauseButton(),this.refresh(),this.applyObserverMapDefault()}get recordingIssues(){return this.issues}async reportIssues(e,t){const i=++this.issueCheck;let n=[];try{const{default:s}=await pi(async()=>{const{default:a}=await import("./sightingSchema-DOOSOVWK.js");return{default:a}},[],import.meta.url);n=new An(s).issues(e)}catch{}i===this.issueCheck&&(this.issues=[...n,...t.loadIssues],Nr.warn(this.issues,t.id),this.renderIssues(),this.dispatchEvent(new CustomEvent(U2,{detail:{issues:this.issues},bubbles:!0,composed:!0})))}renderIssues(){const e=this.issues.length;this.issuesBox.hidden=e===0,this.shadow.getElementById("issues-count").textContent=String(e);const t=this.messages.recordingIssues.replace("{count}",String(e));this.issuesButton.title=t,this.issuesButton.setAttribute("aria-label",t),this.shadow.getElementById("issues-title").textContent=t,this.shadow.getElementById("issues-list").replaceChildren(...this.issues.map(i=>{const n=document.createElement("li");return n.textContent=Nr.text(i,this.messages.issueTemplates),n}))}get sighting(){return this.currentSighting}previewSound(e){this.soundPreview=e,this.sightingAudio.resume(),this.sightingAudio.setSound(e)}stopSoundPreview(){this.soundPreview=void 0,this.sightingAudio.silence()}get canvasElement(){return this.canvas}get renderer(){return this.canvasRenderer}get currentTime(){return this.player.time}set currentTime(e){this.player.seek(e)}get seekableDuration(){return this.player.seekableDuration}get autoReplayEnabled(){return this.loopEnabled}set autoReplayEnabled(e){e!==this.loopEnabled&&this.toggleLoop()}play(){this.player.seekableDuration<=0||this.playbackState==="playing"||this.togglePlayPause()}pause(){this.playbackState==="playing"&&this.togglePlayPause()}get positionLabel(){return this.timeStartLabel.textContent??""}get durationLabel(){return this.timeEndLabel.textContent??""}get showingClockTime(){return this.canShowClockTime}get canSwitchTimeDisplay(){return this.realStartMs!==void 0}toggleTimeDisplay(){this.canSwitchTimeDisplay&&(this.showClockTime=!this.showClockTime,this.updateTimeLabels(),this.updateTimeLabelTitles(),this.dispatchEvent(new CustomEvent("timedisplaychange",{bubbles:!0,composed:!0})))}get canShowClockTime(){return this.realStartMs!==void 0&&this.showClockTime}set showToolbar(e){this.toolbar.classList.toggle("hidden",!e)}get playbackState(){return this.player.playbackState}get selectedSourceIds(){return this.highlightedSourceIds}get durationSeconds(){return this.currentSighting.event.durationSeconds}set durationSeconds(e){this.currentSighting.event.durationSeconds=e,this.updateTimeLabels(),this.refresh(),this.updatePlayPauseButton()}set selectedSourceIds(e){const t=new Set(e);t.size===this.highlightedSourceIds.size&&[...t].every(n=>this.highlightedSourceIds.has(n))||(this.highlightedSourceIds=t,this.refresh())}hasVisibleShapeAt(e,t){return this.shapeAt(e,t)!==void 0}refresh(){this.applyFrameFormat(),this.updateTimeLabels(),this.seekInput.max=String(this.player.seekableDuration),this.refreshMilestoneMarks(),this.updateMilestonesButton(),this.updateObserverMap(),this.updateReferences(),this.player.seek(this.player.time)}hostControls(e){const t=[this.milestonesButton,this.referenceOpacityInput,this.referencesButton,this.observerMapButton];if(e)for(const i of t)e.appendChild(i);else for(const i of t)this.toolbar.appendChild(i)}get referencesShown(){return this.referencesShownState}get referenceOpacity(){return Number(this.referenceOpacityInput.value)}toggleReferences(){this.referencesShownState=!this.referencesShownState,this.updateReferencesButton(),this.dispatchReferenceView()}updateReferences(){const e=this.currentSighting.references;!this.referenceOpacityTouched&&e.length>0&&(this.referenceOpacityInput.value=String(e[0].opacity)),this.updateReferencesButton()}updateReferencesButton(){const e=this.currentSighting.references.length>0;this.referencesButton.hidden=!e,this.referenceOpacityInput.hidden=!e||!this.referencesShownState,this.referencesButton.setAttribute("aria-pressed",String(this.referencesShownState));const t=this.referencesShownState?this.messages.hideReferences:this.messages.showReferences;this.referencesButton.title=t,this.referencesButton.setAttribute("aria-label",t),this.referenceOpacityInput.title=this.messages.referenceOpacity,this.referenceOpacityInput.setAttribute("aria-label",this.messages.referenceOpacity)}dispatchReferenceView(){this.dispatchEvent(new CustomEvent("referenceview",{detail:{shown:this.referencesShown,opacity:this.referenceOpacity}}))}refreshMilestoneMarks(){const e=this.player.seekableDuration,t=e>0?xl(this.sighting.milestones):[];this.milestoneMarks.replaceChildren(...t.map(i=>{const n=document.createElement("button");n.type="button",n.className="milestone-mark",n.style.left=`${Math.min(Math.max(i.t/e,0),1)*100}%`;const s=this.said.read(i.label)??"",a=this.said.read(i.note),o=a?`${s} — ${a}`: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}))}seekSnapArmed=!1;static MARK_SNAP_PX=6;markNear(e){const t=this.player.seekableDuration,i=this.seekInput.getBoundingClientRect().width;if(t<=0||i<=0)return;const n=ui.MARK_SNAP_PX/i*t;let s;for(const a of this.milestoneMarks.children){const o=Number(a.dataset.t);Math.abs(o-e)>n||(!s||Math.abs(o-e)<Math.abs(s.t-e))&&(s={t:o,name:a.title})}return s}snapSeekToMark(e){return this.seekSnapArmed?(this.seekSnapArmed=!1,this.markNear(e)?.t??e):e}nameMarkUnder(e){const t=this.seekInput.getBoundingClientRect(),i=this.player.seekableDuration;if(t.width<=0||i<=0)return;const n=(e.clientX-t.left)/t.width*i,s=this.markNear(n);s?this.seekInput.title=s.name:this.seekInput.removeAttribute("title")}showMilestoneAt(e){const t=this.milestonesShown&&this.sighting.milestones.length>0?Cf(this.sighting.milestones,e):void 0;if(this.milestoneCaption.hidden=t===void 0,!t)return;const i=document.createElement("b");i.textContent=this.said.read(t.label)??"";const n=this.said.read(t.note),s=n?` — ${n}`:"";this.milestoneCaption.replaceChildren(i,document.createTextNode(s))}exposureInstants(e){const t=this.exposureTimes(e),i=1/t.length;return t.map(n=>({shapes:this.shapesAt(n),share:i}))}exposureTimes(e=this.currentTime){const t=Pn.windowEndingAt(e,this.currentSighting.exposure??0);if(t.ms<ui.SHORTEST_VISIBLE_EXPOSURE_MS)return[e];const i=Math.min(ui.MAX_EXPOSURE_STEPS,Math.max(2,Math.round(t.ms/ui.SHORTEST_VISIBLE_EXPOSURE_MS))),n=Math.ceil(this.travelPxOver(t.fromMs,t.ms)/ui.EXPOSURE_STEP_PX),s=Math.min(ui.MAX_TRAVEL_STEPS,Math.max(i,n)),a=[];for(let o=0;o<s;o++)a.push(t.fromMs+t.ms*o/(s-1));return a}travelPxOver(e,t){const i=this.shapesAt(e),n=this.shapesAt(e+t);let s=0;for(const[a,o]of i){const c=n.get(a);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(e,t,i){for(const n of this.exposureTimes()){const s=this.currentSighting.timeline.hitTest(n,e,t,i);if(s)return s}}shapesAt(e){const t=new Map;for(const i of this.currentSighting.timeline.sourceIds){const n=this.currentSighting.timeline.getInterpolatedShapeAt(e,i);n&&t.set(i,n)}return t}static SHORTEST_VISIBLE_EXPOSURE_MS=20;static MAX_EXPOSURE_STEPS=48;static EXPOSURE_STEP_PX=2;static MAX_TRAVEL_STEPS=320;applyFrameFormat(){const e=si.frameWidthPx(this.currentSighting.instrument,this.canvas.height);if(this.canvas.width===e)return;this.canvas.width=e,this.canvas.parentElement?.style.setProperty("--frame-aspect",`${e} / ${this.canvas.height}`)}canvasPointFromEvent(e){const t=this.canvas.getBoundingClientRect();if(!(t.width===0||t.height===0))return{x:(e.clientX-t.left)/t.width*this.canvas.width,y:(e.clientY-t.top)/t.height*this.canvas.height}}onFrame(e,t){this.canvasRenderer.clear(this.canvas.width,this.canvas.height);const i=this.playbackState!=="playing"?this.highlightedSourceIds:F2;this.canvasRenderer.setStarPoints(si.starPointsOf(this.sighting.instrument));const n=(jt(this.sighting,e)?.rollDeg??0)+this.gaitAt(e).rollDeg;this.canvasRenderer.setRoll(n*Math.PI/180);const s=this.exposureInstants(e),a=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,a))}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,a)));if(this.selectionShown&&i.size>1){const o=ln.groupBoundsFor([...t].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,a).bounds)),this.keepObserverMapClear(),this.seekInput.value=String(e),this.timeStartLabel.textContent=this.formatPosition(e),this.showMilestoneAt(e),this.paintObserverMap(e),this.playbackState==="playing"?(this.soundPreview=void 0,this.sightingAudio.setSound(yg(this.currentSighting,e))):this.soundPreview?this.sightingAudio.setSound(this.soundPreview):this.sightingAudio.silence(),this.updatePlayPauseButton(),this.dispatchEvent(new CustomEvent("timeupdate",{detail:{time:e}}))}shifted(e,t){return t.x===0&&t.y===0?e:{...e,bounds:{...e.bounds,x:e.bounds.x+t.x,y:e.bounds.y+t.y}}}createPlayer(){const e=new n2(this.currentSighting.timeline,(t,i)=>this.onFrame(t,i));return e.loop=this.loopEnabled,e.onEnded=()=>{this.updatePlayPauseButton(),this.dispatchEvent(new CustomEvent("ended",{bubbles:!0,composed:!0}))},e}static SEEK_KEY_STEP_MS=5e3;handleSeekKey=e=>{if(e.altKey||e.ctrlKey||e.metaKey)return;const t=e.key==="ArrowLeft"?-1:e.key==="ArrowRight"?1:0;if(t){e.preventDefault();const i=this.player.seekableDuration;this.player.seek(Math.min(i,Math.max(0,this.player.time+t*ui.SEEK_KEY_STEP_MS)))}else e.key===" "&&(e.preventDefault(),this.togglePlayPause())};togglePlayPause(){this.player.seekableDuration<=0||(this.player.playbackState==="playing"?(this.player.pause(),this.soundPreview=void 0,this.sightingAudio.silence(),this.refresh()):(this.sightingAudio.resume(),this.player.play()),this.updatePlayPauseButton(),this.flashPlayback())}flashPlayback(){const e=this.playbackFlash;e.textContent=this.player.playbackState==="playing"?"▶":"⏸",e.classList.remove("flashing"),e.offsetWidth,e.classList.add("flashing")}updatePlayPauseButton(){const e=this.player.playbackState==="playing";this.playPauseButton.textContent=e?"⏸":"▶";const t=this.player.seekableDuration>0;this.playPauseButton.disabled=!t;const i=t?e?this.messages.pause:this.messages.play:this.messages.noDuration;this.playPauseButton.title=i,this.playPauseButton.setAttribute("aria-label",i)}toggleLoop(){this.loopEnabled=!this.loopEnabled,this.player.loop=this.loopEnabled}restorePlayback(){const e=this.playbackBeforeClick;e&&(this.currentTime=e.time,e.state==="playing"?this.play():this.pause())}get canUseNativeFullscreen(){return typeof this.fullscreenTarget.requestFullscreen=="function"&&document.fullscreenEnabled}toggleFullscreen(){if(!this.canUseNativeFullscreen){this.simulatedFullscreen?this.exitSimulatedFullscreen():this.enterSimulatedFullscreen();return}document.fullscreenElement?document.exitFullscreen():this.fullscreenTarget.requestFullscreen().catch(e=>{console.error("<rr0-ufo>: requestFullscreen() failed —",e)})}enterSimulatedFullscreen(){const e=this.fullscreenTarget;this.styleBeforeSimulatedFullscreen=e.getAttribute("style")??"",this.bodyOverflowBeforeSimulatedFullscreen=document.body.style.overflow;const t=e.style;t.setProperty("position","fixed"),t.setProperty("inset","0"),t.setProperty("margin","0"),t.setProperty("max-width","none"),t.setProperty("max-height","none"),t.setProperty("aspect-ratio","auto"),t.setProperty("z-index","2147483647"),t.setProperty("background","#000"),t.setProperty("width","100vw"),t.setProperty("width","100dvw"),t.setProperty("height","100vh"),t.setProperty("height","100dvh"),document.body.style.overflow="hidden",this.simulatedFullscreen=!0,document.addEventListener("keydown",this.handleSimulatedFullscreenKey),this.updateFullscreenButton()}exitSimulatedFullscreen(){if(!this.simulatedFullscreen)return;const e=this.fullscreenTarget;this.styleBeforeSimulatedFullscreen?e.setAttribute("style",this.styleBeforeSimulatedFullscreen):e.removeAttribute("style"),document.body.style.overflow=this.bodyOverflowBeforeSimulatedFullscreen??"",this.simulatedFullscreen=!1,document.removeEventListener("keydown",this.handleSimulatedFullscreenKey),this.updateFullscreenButton()}toggleObserverMap(){const e=this.observerMapPanel.hidden;this.observerMapAsked=e,this.setObserverMapOpen(e),this.keepObserverMapClear()}observerMapAsked=!1;applyObserverMapDefault(){const e=this.getAttribute(Es),t=e===null?this.observerPath?.travels===!0:e!=="false";this.setObserverMapOpen(t&&this.observerPath!==void 0)}setObserverMapOpen(e){this.observerMapPanel.hidden=!e,this.observerMapPanel.removeAttribute("title"),this.observerMapButton.setAttribute("aria-pressed",String(e)),this.updateObserverMapButton(),e&&(this.sizeObserverMapCanvas(),this.loadObserverMapImagery(),this.paintObserverMap(this.currentTime))}updateObserverMapButton(){const t=!this.observerMapPanel.hidden?this.messages.hideObserverMap:this.messages.showObserverMap;this.observerMapButton.title=t,this.observerMapButton.setAttribute("aria-label",t);const i=[[this.mapZoomInButton,this.messages.zoomMapIn],[this.mapZoomOutButton,this.messages.zoomMapOut],[this.mapFitButton,this.messages.fitMap]];for(const[n,s]of i)n.title=s,n.setAttribute("aria-label",s)}updateObserverMap(){const e=this.observerPath!==void 0;if(this.observerPath=wr.of(this.currentSighting),this.observerMapButton.hidden=this.observerPath===void 0,!e&&this.observerPath&&this.applyObserverMapDefault(),!this.observerPath){this.setObserverMapOpen(!1),this.observerMapBounds=void 0;return}const t=this.observerPath.boundsAround(ui.OBSERVER_MAP_MIN_SPAN_M,ui.OBSERVER_MAP_MARGIN);(!this.observerMapBounds||!this.sameGround(this.observerMapBounds,t))&&(this.observerMapBounds&&this.observerMapView.refit(this.observerMapBounds,t),this.observerMapBounds=t,this.observerMapImagery=void 0,this.observerMapImageryCredit=void 0,this.observerMapImageryFailed=!1,this.observerMapImageryBounds=void 0,this.observerMapImageryLoading=!1,this.observerMapPanel.hidden||this.loadObserverMapImagery())}sameGround(e,t){const i=Math.abs(e.east-e.west)/20;return Math.abs(e.north-t.north)<i&&Math.abs(e.south-t.south)<i&&Math.abs(e.west-t.west)<i&&Math.abs(e.east-t.east)<i}async loadObserverMapImagery(){const e=this.observerMapViewBounds;if(!e||this.observerMapPanel.hidden||this.observerMapImageryLoading||!this.observerMapImageryNeededFor(e))return;const t=this.observerMapView.changed,i=t?Vt.expand(e,ui.OBSERVER_MAP_IMAGERY_AHEAD):e,n=ui.OBSERVER_MAP_IMAGERY_PX*(t?1+2*ui.OBSERVER_MAP_IMAGERY_AHEAD:1);this.observerMapImageryBounds=i,this.observerMapImageryViewWidth=e.east-e.west,this.observerMapImageryLoading=!0;const s=Fg();try{const a=await s.getImageryTexture(i,{width:n,height:n});if(this.observerMapImageryBounds!==i)return;this.observerMapImagery=a,this.observerMapImageryCredit=s.attribution,this.observerMapImageryFailed=!1}catch{if(this.observerMapImageryBounds!==i)return;this.observerMapImageryFailed=this.observerMapImagery===void 0}finally{this.observerMapImageryBounds===i&&(this.observerMapImageryLoading=!1)}this.paintObserverMap(this.currentTime),this.scheduleObserverMapImagery()}static OBSERVER_MAP_IMAGERY_AHEAD=.5;static OBSERVER_MAP_IMAGERY_LOOKAHEAD=.25;observerMapImageryNeededFor(e){const t=this.observerMapImageryBounds;if(!t)return!0;const i=this.observerMapImagery?.bounds??t,n=this.observerMapView.changed?Vt.expand(e,ui.OBSERVER_MAP_IMAGERY_LOOKAHEAD):e,s=n.west>=i.west&&n.east<=i.east&&n.south>=i.south&&n.north<=i.north,a=e.east-e.west>this.observerMapImageryViewWidth/2;return!s||!a}get observerMapCredit(){return this.observerMapImageryCredit}get observerMapFooterLine(){return this.observerMapImageryFailed?this.messages.mapImageryUnavailable:this.creditShownExternally?void 0:this.observerMapImageryCredit}mapShapeBounds=[];mapSceneBounds=[];setMapSubjectBounds(e){this.mapSceneBounds=e.map(t=>({x:t.x*this.canvas.width,y:t.y*this.canvas.height,width:t.width*this.canvas.width,height:t.height*this.canvas.height})),this.keepObserverMapClear()}keepObserverMapClear(){if(this.observerMapPanel.hidden)return;const e=this.observerMapBoxPx;if(!e)return;const t=[...this.mapShapeBounds,...this.mapSceneBounds],i=(l,h,u)=>{for(const d of t)if(!(d.x+d.width<l-u||d.x>h+u)&&!(d.y>e.bottom+u||d.y+d.height<e.top-u))return!0;return!1},n=[this.canvas.width-e.width,this.canvas.width],s=[0,e.width],a=ui.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],a))&&this.observerMapPanel.classList.remove("on-the-left");return}i(n[0],n[1],0)&&!i(s[0],s[1],0)&&this.observerMapPanel.classList.add("on-the-left")}observerMapBoxPx;static OBSERVER_MAP_CLEARANCE_PX=24;sizeObserverMapCanvas(){const e=this.observerMapPanel.clientWidth;if(e===0)return;const t=Math.round(e*(globalThis.devicePixelRatio??1));this.measureObserverMapBox(),this.observerMapCanvas.width!==t&&(this.observerMapCanvas.width=t,this.observerMapCanvas.height=t)}measureObserverMapBox(){const e=this.observerMapPanel.getBoundingClientRect(),t=this.canvas.getBoundingClientRect();if(t.width===0||t.height===0)return;const i=this.canvas.width/t.width,n=this.canvas.height/t.height;this.observerMapBoxPx={width:e.width*i,top:(e.top-t.top)*n,bottom:(e.bottom-t.top)*n}}paintObserverMap(e){if(this.observerMapPanel.hidden||!this.observerPath||!this.observerMapBounds)return;const t=jt(this.currentSighting,e);t?.lat!==void 0&&t.lng!==void 0&&!this.observerMapDrag?.moved&&this.observerMapView.keepInView(this.observerMapBounds,{lat:t.lat,lng:t.lng},ui.OBSERVER_MAP_FOLLOW_MARGIN)&&this.scheduleObserverMapImagery();const i=this.currentSighting.instrument,n=[],s=this.currentSighting.milestones.length>0?Cf(this.currentSighting.milestones,e):void 0;for(const a of this.milestonesShown?xl(this.currentSighting.milestones):[]){const o=jt(this.currentSighting,a.t);o?.lat===void 0||o.lng===void 0||n.push({label:this.said.read(a.label)??"",note:this.said.read(a.note),t:a.t,lat:o.lat,lng:o.lng,current:a===s})}this.observerMapRenderer.paint({bounds:this.observerMapViewBounds,imagery:this.observerMapImagery,path:this.observerPath,position:t?.lat!==void 0&&t.lng!==void 0?{lat:t.lat,lng:t.lng}:void 0,headingDeg:t?.headingDeg===void 0?void 0:t.headingDeg+this.lookYawDeg,coneHalfAngleDeg:t?Ss.of(i,this.canvas.height,t.fovDeg).halfWidthAngleDeg(si.aspectOf(i)):void 0,markers:n,decor:this.observerMapDecorAt(e),observerLabel:this.said.read(this.currentSighting.observer?.title)??this.messages.observerHere,nightFraction:this.observerMapNightFraction,attribution:this.observerMapFooterLine})}toggleMilestones(){this.setMilestonesShown(!this.milestonesShown)}setMilestonesShown(e){this.milestonesShown=e,this.milestoneMarks.hidden=!e,this.milestonesButton.setAttribute("aria-pressed",String(e)),this.updateMilestonesButton(),this.showMilestoneAt(this.currentTime),this.paintObserverMap(this.currentTime)}updateMilestonesButton(){this.milestonesButton.hidden=this.currentSighting.milestones.length===0;const e=this.milestonesShown?this.messages.hideMilestones:this.messages.showMilestones;this.milestonesButton.title=e,this.milestonesButton.setAttribute("aria-label",e)}observerMapDecorAt(e){const t=jt(this.currentSighting,0);return t?.lat===void 0||t.lng===void 0?[]:this.currentSighting.decor.filter(i=>i.kind!=="crop").map(i=>{const n=Or(i,e),{lat:s,lng:a}=_s(n.eastM,-n.northM,t.lat,t.lng);return{lat:s,lng:a,headingDeg:n.headingDeg,label:this.said.read(i.title)??this.messages.decorHere}})}observerMapNightFraction;setSunAltitude(e){const t=e===void 0?void 0:Math.max(0,Math.min(1,-e/12));t!==this.observerMapNightFraction&&(this.observerMapNightFraction=t,this.paintObserverMap(this.currentTime))}setLookOffset(e,t){e===this.lookYawDeg&&t===this.lookPitchDeg||(this.lookYawDeg=e,this.lookPitchDeg=t,this.refresh())}get frameShiftPx(){return this.frameShift}get frameShift(){const e=this.gaitAt(this.currentTime),t=this.lookYawDeg+e.yawDeg,i=this.lookPitchDeg+e.pitchDeg;if(t===0&&i===0)return{x:0,y:0};const n=jt(this.currentSighting,this.currentTime),s=Ss.of(this.currentSighting.instrument,this.canvas.height,n?.fovDeg??60);return{x:-s.angleDegToRadiusPx(t),y:s.angleDegToRadiusPx(i)}}gaitAt(e){return xt.bodyAt(this.currentSighting,e,this.steadyObserver)}updateFullscreenButton(){const e=this.simulatedFullscreen||document.fullscreenElement===this.fullscreenTarget;this.fullscreenButton.title=e?this.messages.exitFullscreen:this.messages.fullscreen,this.fullscreenButton.setAttribute("aria-label",this.fullscreenButton.title)}get said(){return this.saidTexts??=new On(Fr.preferencesFor(this))}saidTexts;async loadLocaleMessages(){const e=o0(Fr.preferencesFor(this),c0);if(e===this.messagesLanguage||e==="en"&&this.messagesLanguage===void 0)return;this.messagesLanguage=e;const t=await g2(e);this.messagesLanguage===e&&this.applyMessages(t)}messagesLanguage;updateTimeLabelTitles(){const e=this.showClockTime?this.messages.switchToElapsed:this.messages.switchToClockTime,t=this.canSwitchTimeDisplay?` — ${e}`:"";this.timeStartLabel.title=this.messages.currentPosition+t,this.timeEndLabel.title=this.messages.duration+t;for(const i of[this.timeStartLabel,this.timeEndLabel])i.classList.toggle("switchable",this.canSwitchTimeDisplay),this.canSwitchTimeDisplay?(i.setAttribute("role","button"),i.setAttribute("tabindex","0")):(i.removeAttribute("role"),i.removeAttribute("tabindex"))}applyMessages(e){this.messages=e,this.updateTimeLabelTitles(),this.updatePlayPauseButton(),this.updateFullscreenButton(),this.updateObserverMapButton(),this.updateReferencesButton(),this.updateMilestonesButton(),this.renderIssues()}updateTimeLabels(){const e=this.currentSighting.event,t=xg(e);this.realDurationMs=t!==void 0&&t>0?t:void 0,this.realStartMs=e.time?Cu(e.time):void 0;const i=this.currentSighting.timeline.duration;this.player.playbackRate=this.realDurationMs!==void 0&&i>0?i/this.realDurationMs:1,this.player.durationOverrideMs=i>0?0:this.realDurationMs??0,this.timeEndLabel.textContent=this.formatEndOfTimeline(),this.timeStartLabel.textContent=this.formatPosition(this.player.time),this.updateTimeLabelTitles()}formatPosition(e){if(this.realDurationMs===void 0)return cc(e);const t=this.currentSighting.timeline.duration,i=t>0&&e<=t?e/t*this.realDurationMs:e;return this.canShowClockTime?Ff(Nf(this.realStartMs+i)):cc(i)}formatEndOfTimeline(){return this.realDurationMs===void 0?cc(this.currentSighting.timeline.duration):this.canShowClockTime?Ff(Nf(this.realStartMs+this.realDurationMs)):cc(this.realDurationMs)}}function Nf(r){const e=new Date(r);return{hour:e.getUTCHours(),minute:e.getUTCMinutes(),second:e.getUTCSeconds()}}function Ff(r){if(r.hour===void 0)return"0:00";const e=t=>String(t).padStart(2,"0");return r.second?`${e(r.hour)}:${e(r.minute??0)}:${e(r.second)}`:`${e(r.hour)}:${e(r.minute??0)}`}function cc(r){const e=Math.round(r/1e3),t=Math.floor(e/60),i=e%60;return`${t}:${String(i).padStart(2,"0")}`}const Lu="rr0-ufo";function Ug(){customElements.get(Lu)||customElements.define(Lu,ui)}const U2="recordingissues";/**
|
|
1302
1302
|
* @license
|
|
1303
1303
|
* Copyright 2010-2026 Three.js Authors
|
|
1304
1304
|
* SPDX-License-Identifier: MIT
|
|
1305
|
-
*/const h0="185",k2=0,Uf=1,z2=2,To=1,B2=2,xo=3,sa=0,Ht=1,Qi=2,as=0,ia=1,Ni=2,kf=3,zf=4,Xl=5,ba=100,H2=101,G2=102,V2=103,W2=104,X2=200,Bo=201,Y2=202,q2=203,Ou=204,Ho=205,$2=206,K2=207,Z2=208,J2=209,j2=210,Q2=211,eM=212,tM=213,iM=214,Nu=0,Fu=1,Uu=2,Ur=3,ku=4,zu=5,Bu=6,Hu=7,u0=0,nM=1,sM=2,rs=0,kg=1,zg=2,Bg=3,Hg=4,Gg=5,Vg=6,Wg=7,Bf="attached",aM="detached",Xg=300,Ua=301,kr=302,hh=303,uh=304,Yl=306,Go=1e3,wi=1001,Gu=1002,At=1003,rM=1004,lc=1005,rt=1006,dh=1007,Ta=1008,dn=1009,Yg=1010,qg=1011,Vo=1012,d0=1013,_n=1014,Oi=1015,Wt=1016,f0=1017,p0=1018,Wo=1020,$g=35902,Kg=35899,Zg=1021,Jg=1022,Ei=1023,Rs=1026,Ra=1027,ql=1028,m0=1029,ka=1030,g0=1031,v0=1033,ol=33776,cl=33777,ll=33778,hl=33779,Vu=35840,Wu=35841,Xu=35842,Yu=35843,qu=36196,$u=37492,Ku=37496,Zu=37488,Ju=37489,yl=37490,ju=37491,Qu=37808,ed=37809,td=37810,id=37811,nd=37812,sd=37813,ad=37814,rd=37815,od=37816,cd=37817,ld=37818,hd=37819,ud=37820,dd=37821,fd=36492,pd=36494,md=36495,gd=36283,vd=36284,bl=36285,Md=36286,jg=2200,oM=2201,cM=2202,_l=2300,xd=2301,fh=2302,Hf=2303,Mr=2400,xr=2401,Sl=2402,M0=2500,lM=2501,IA=0,CA=1,PA=2,hM=3200,wl=0,uM=1,Js="",Gi="srgb",El="srgb-linear",Al="linear",yt="srgb",Ya=7680,Gf=519,dM=512,fM=513,pM=514,x0=515,mM=516,gM=517,y0=518,vM=519,yd=35044,Tl="300 es",ns=2e3,Xo=2001;function MM(r){for(let e=r.length-1;e>=0;--e)if(r[e]>=65535)return!0;return!1}function xM(r){return ArrayBuffer.isView(r)&&!(r instanceof DataView)}function Yo(r){return document.createElementNS("http://www.w3.org/1999/xhtml",r)}function yM(){const r=Yo("canvas");return r.style.display="block",r}const Vf={};function Rl(...r){const e="THREE."+r.shift();console.log(e,...r)}function Qg(r){const e=r[0];if(typeof e=="string"&&e.startsWith("TSL:")){const t=r[1];t&&t.isStackTrace?r[0]+=" "+t.getLocation():r[1]='Stack trace not available. Enable "THREE.Node.captureStackTrace" to capture stack traces.'}return r}function Re(...r){r=Qg(r);const e="THREE."+r.shift();{const t=r[0];t&&t.isStackTrace?console.warn(t.getError(e)):console.warn(e,...r)}}function Ge(...r){r=Qg(r);const e="THREE."+r.shift();{const t=r[0];t&&t.isStackTrace?console.error(t.getError(e)):console.error(e,...r)}}function Er(...r){const e=r.join(" ");e in Vf||(Vf[e]=!0,Re(...r))}function bM(r,e,t){return new Promise(function(i,n){function s(){switch(r.clientWaitSync(e,r.SYNC_FLUSH_COMMANDS_BIT,0)){case r.WAIT_FAILED:n();break;case r.TIMEOUT_EXPIRED:setTimeout(s,t);break;default:i()}}setTimeout(s,t)})}const _M={[Nu]:Fu,[Uu]:Bu,[ku]:Hu,[Ur]:zu,[Fu]:Nu,[Bu]:Uu,[Hu]:ku,[zu]:Ur};class oa{addEventListener(e,t){this._listeners===void 0&&(this._listeners={});const i=this._listeners;i[e]===void 0&&(i[e]=[]),i[e].indexOf(t)===-1&&i[e].push(t)}hasEventListener(e,t){const i=this._listeners;return i===void 0?!1:i[e]!==void 0&&i[e].indexOf(t)!==-1}removeEventListener(e,t){const i=this._listeners;if(i===void 0)return;const n=i[e];if(n!==void 0){const s=n.indexOf(t);s!==-1&&n.splice(s,1)}}dispatchEvent(e){const t=this._listeners;if(t===void 0)return;const i=t[e.type];if(i!==void 0){e.target=this;const n=i.slice(0);for(let s=0,a=n.length;s<a;s++)n[s].call(this,e);e.target=null}}}const Ri=["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 Wf=1234567;const Ro=Math.PI/180,zr=180/Math.PI;function Un(){const r=Math.random()*4294967295|0,e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,i=Math.random()*4294967295|0;return(Ri[r&255]+Ri[r>>8&255]+Ri[r>>16&255]+Ri[r>>24&255]+"-"+Ri[e&255]+Ri[e>>8&255]+"-"+Ri[e>>16&15|64]+Ri[e>>24&255]+"-"+Ri[t&63|128]+Ri[t>>8&255]+"-"+Ri[t>>16&255]+Ri[t>>24&255]+Ri[i&255]+Ri[i>>8&255]+Ri[i>>16&255]+Ri[i>>24&255]).toLowerCase()}function et(r,e,t){return Math.max(e,Math.min(t,r))}function b0(r,e){return(r%e+e)%e}function SM(r,e,t,i,n){return i+(r-e)*(n-i)/(t-e)}function wM(r,e,t){return r!==e?(t-r)/(e-r):0}function Do(r,e,t){return(1-t)*r+t*e}function EM(r,e,t,i){return Do(r,e,1-Math.exp(-t*i))}function AM(r,e=1){return e-Math.abs(b0(r,e*2)-e)}function TM(r,e,t){return r<=e?0:r>=t?1:(r=(r-e)/(t-e),r*r*(3-2*r))}function RM(r,e,t){return r<=e?0:r>=t?1:(r=(r-e)/(t-e),r*r*r*(r*(r*6-15)+10))}function DM(r,e){return r+Math.floor(Math.random()*(e-r+1))}function IM(r,e){return r+Math.random()*(e-r)}function CM(r){return r*(.5-Math.random())}function PM(r){r!==void 0&&(Wf=r);let e=Wf+=1831565813;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}function LM(r){return r*Ro}function OM(r){return r*zr}function NM(r){return(r&r-1)===0&&r!==0}function FM(r){return Math.pow(2,Math.ceil(Math.log(r)/Math.LN2))}function UM(r){return Math.pow(2,Math.floor(Math.log(r)/Math.LN2))}function kM(r,e,t,i,n){const s=Math.cos,a=Math.sin,o=s(t/2),c=a(t/2),l=s((e+i)/2),h=a((e+i)/2),u=s((e-i)/2),d=a((e-i)/2),f=s((i-e)/2),p=a((i-e)/2);switch(n){case"XYX":r.set(o*h,c*u,c*d,o*l);break;case"YZY":r.set(c*d,o*h,c*u,o*l);break;case"ZXZ":r.set(c*u,c*d,o*h,o*l);break;case"XZX":r.set(o*h,c*p,c*f,o*l);break;case"YXY":r.set(c*f,o*h,c*p,o*l);break;case"ZYZ":r.set(c*p,c*f,o*h,o*l);break;default:Re("MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+n)}}function Nn(r,e){switch(e.constructor){case Float32Array:return r;case Uint32Array:return r/4294967295;case Uint16Array:return r/65535;case Uint8Array:return r/255;case Int32Array:return Math.max(r/2147483647,-1);case Int16Array:return Math.max(r/32767,-1);case Int8Array:return Math.max(r/127,-1);default:throw new Error("THREE.MathUtils: Invalid component type.")}}function bt(r,e){switch(e.constructor){case Float32Array:return r;case Uint32Array:return Math.round(r*4294967295);case Uint16Array:return Math.round(r*65535);case Uint8Array:return Math.round(r*255);case Int32Array:return Math.round(r*2147483647);case Int16Array:return Math.round(r*32767);case Int8Array:return Math.round(r*127);default:throw new Error("THREE.MathUtils: Invalid component type.")}}const LA={DEG2RAD:Ro,RAD2DEG:zr,generateUUID:Un,clamp:et,euclideanModulo:b0,mapLinear:SM,inverseLerp:wM,lerp:Do,damp:EM,pingpong:AM,smoothstep:TM,smootherstep:RM,randInt:DM,randFloat:IM,randFloatSpread:CM,seededRandom:PM,degToRad:LM,radToDeg:OM,isPowerOfTwo:NM,ceilPowerOfTwo:FM,floorPowerOfTwo:UM,setQuaternionFromProperEuler:kM,normalize:bt,denormalize:Nn};class xe{static{xe.prototype.isVector2=!0}constructor(e=0,t=0){this.x=e,this.y=t}get width(){return this.x}set width(e){this.x=e}get height(){return this.y}set height(e){this.y=e}set(e,t){return this.x=e,this.y=t,this}setScalar(e){return this.x=e,this.y=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;default:throw new Error("THREE.Vector2: index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;default:throw new Error("THREE.Vector2: index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}addScalar(e){return this.x+=e,this.y+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this}subScalar(e){return this.x-=e,this.y-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this}multiply(e){return this.x*=e.x,this.y*=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}divide(e){return this.x/=e.x,this.y/=e.y,this}divideScalar(e){return this.multiplyScalar(1/e)}applyMatrix3(e){const t=this.x,i=this.y,n=e.elements;return this.x=n[0]*t+n[3]*i+n[6],this.y=n[1]*t+n[4]*i+n[7],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this}clamp(e,t){return this.x=et(this.x,e.x,t.x),this.y=et(this.y,e.y,t.y),this}clampScalar(e,t){return this.x=et(this.x,e,t),this.y=et(this.y,e,t),this}clampLength(e,t){const i=this.length();return this.divideScalar(i||1).multiplyScalar(et(i,e,t))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(e){return this.x*e.x+this.y*e.y}cross(e){return this.x*e.y-this.y*e.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(e){const t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;const i=this.dot(e)/t;return Math.acos(et(i,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,i=this.y-e.y;return t*t+i*i}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this}lerpVectors(e,t,i){return this.x=e.x+(t.x-e.x)*i,this.y=e.y+(t.y-e.y)*i,this}equals(e){return e.x===this.x&&e.y===this.y}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this}rotateAround(e,t){const i=Math.cos(t),n=Math.sin(t),s=this.x-e.x,a=this.y-e.y;return this.x=s*i-a*n+e.x,this.y=s*n+a*i+e.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class en{constructor(e=0,t=0,i=0,n=1){this.isQuaternion=!0,this._x=e,this._y=t,this._z=i,this._w=n}static slerpFlat(e,t,i,n,s,a,o){let c=i[n+0],l=i[n+1],h=i[n+2],u=i[n+3],d=s[a+0],f=s[a+1],p=s[a+2],v=s[a+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 _=Math.acos(m),b=Math.sin(_);g=Math.sin(g*_)/b,o=Math.sin(o*_)/b,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 _=1/Math.sqrt(c*c+l*l+h*h+u*u);c*=_,l*=_,h*=_,u*=_}}e[t]=c,e[t+1]=l,e[t+2]=h,e[t+3]=u}static multiplyQuaternionsFlat(e,t,i,n,s,a){const o=i[n],c=i[n+1],l=i[n+2],h=i[n+3],u=s[a],d=s[a+1],f=s[a+2],p=s[a+3];return e[t]=o*p+h*u+c*f-l*d,e[t+1]=c*p+h*d+l*u-o*f,e[t+2]=l*p+h*f+o*d-c*u,e[t+3]=h*p-o*u-c*d-l*f,e}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get w(){return this._w}set w(e){this._w=e,this._onChangeCallback()}set(e,t,i,n){return this._x=e,this._y=t,this._z=i,this._w=n,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback(),this}setFromEuler(e,t=!0){const i=e._x,n=e._y,s=e._z,a=e._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(a){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:Re("Quaternion: .setFromEuler() encountered an unknown order: "+a)}return t===!0&&this._onChangeCallback(),this}setFromAxisAngle(e,t){const i=t/2,n=Math.sin(i);return this._x=e.x*n,this._y=e.y*n,this._z=e.z*n,this._w=Math.cos(i),this._onChangeCallback(),this}setFromRotationMatrix(e){const t=e.elements,i=t[0],n=t[4],s=t[8],a=t[1],o=t[5],c=t[9],l=t[2],h=t[6],u=t[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=(a-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+a)/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+a)/f,this._y=.25*f,this._z=(c+h)/f}else{const f=2*Math.sqrt(1+u-i-o);this._w=(a-n)/f,this._x=(s+l)/f,this._y=(c+h)/f,this._z=.25*f}return this._onChangeCallback(),this}setFromUnitVectors(e,t){let i=e.dot(t)+1;return i<1e-8?(i=0,Math.abs(e.x)>Math.abs(e.z)?(this._x=-e.y,this._y=e.x,this._z=0,this._w=i):(this._x=0,this._y=-e.z,this._z=e.y,this._w=i)):(this._x=e.y*t.z-e.z*t.y,this._y=e.z*t.x-e.x*t.z,this._z=e.x*t.y-e.y*t.x,this._w=i),this.normalize()}angleTo(e){return 2*Math.acos(Math.abs(et(this.dot(e),-1,1)))}rotateTowards(e,t){const i=this.angleTo(e);if(i===0)return this;const n=Math.min(1,t/i);return this.slerp(e,n),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(e){return this._x*e._x+this._y*e._y+this._z*e._z+this._w*e._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let e=this.length();return e===0?(this._x=0,this._y=0,this._z=0,this._w=1):(e=1/e,this._x=this._x*e,this._y=this._y*e,this._z=this._z*e,this._w=this._w*e),this._onChangeCallback(),this}multiply(e){return this.multiplyQuaternions(this,e)}premultiply(e){return this.multiplyQuaternions(e,this)}multiplyQuaternions(e,t){const i=e._x,n=e._y,s=e._z,a=e._w,o=t._x,c=t._y,l=t._z,h=t._w;return this._x=i*h+a*o+n*l-s*c,this._y=n*h+a*c+s*o-i*l,this._z=s*h+a*l+i*c-n*o,this._w=a*h-i*o-n*c-s*l,this._onChangeCallback(),this}slerp(e,t){let i=e._x,n=e._y,s=e._z,a=e._w,o=this.dot(e);o<0&&(i=-i,n=-n,s=-s,a=-a,o=-o);let c=1-t;if(o<.9995){const l=Math.acos(o),h=Math.sin(l);c=Math.sin(c*l)/h,t=Math.sin(t*l)/h,this._x=this._x*c+i*t,this._y=this._y*c+n*t,this._z=this._z*c+s*t,this._w=this._w*c+a*t,this._onChangeCallback()}else this._x=this._x*c+i*t,this._y=this._y*c+n*t,this._z=this._z*c+s*t,this._w=this._w*c+a*t,this.normalize();return this}slerpQuaternions(e,t,i){return this.copy(e).slerp(t,i)}random(){const e=2*Math.PI*Math.random(),t=2*Math.PI*Math.random(),i=Math.random(),n=Math.sqrt(1-i),s=Math.sqrt(i);return this.set(n*Math.sin(e),n*Math.cos(e),s*Math.sin(t),s*Math.cos(t))}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._w===this._w}fromArray(e,t=0){return this._x=e[t],this._y=e[t+1],this._z=e[t+2],this._w=e[t+3],this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._w,e}fromBufferAttribute(e,t){return this._x=e.getX(t),this._y=e.getY(t),this._z=e.getZ(t),this._w=e.getW(t),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class R{static{R.prototype.isVector3=!0}constructor(e=0,t=0,i=0){this.x=e,this.y=t,this.z=i}set(e,t,i){return i===void 0&&(i=this.z),this.x=e,this.y=t,this.z=i,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;default:throw new Error("THREE.Vector3: index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("THREE.Vector3: index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}multiplyVectors(e,t){return this.x=e.x*t.x,this.y=e.y*t.y,this.z=e.z*t.z,this}applyEuler(e){return this.applyQuaternion(Xf.setFromEuler(e))}applyAxisAngle(e,t){return this.applyQuaternion(Xf.setFromAxisAngle(e,t))}applyMatrix3(e){const t=this.x,i=this.y,n=this.z,s=e.elements;return this.x=s[0]*t+s[3]*i+s[6]*n,this.y=s[1]*t+s[4]*i+s[7]*n,this.z=s[2]*t+s[5]*i+s[8]*n,this}applyNormalMatrix(e){return this.applyMatrix3(e).normalize()}applyMatrix4(e){const t=this.x,i=this.y,n=this.z,s=e.elements,a=1/(s[3]*t+s[7]*i+s[11]*n+s[15]);return this.x=(s[0]*t+s[4]*i+s[8]*n+s[12])*a,this.y=(s[1]*t+s[5]*i+s[9]*n+s[13])*a,this.z=(s[2]*t+s[6]*i+s[10]*n+s[14])*a,this}applyQuaternion(e){const t=this.x,i=this.y,n=this.z,s=e.x,a=e.y,o=e.z,c=e.w,l=2*(a*n-o*i),h=2*(o*t-s*n),u=2*(s*i-a*t);return this.x=t+c*l+a*u-o*h,this.y=i+c*h+o*l-s*u,this.z=n+c*u+s*h-a*l,this}project(e){return this.applyMatrix4(e.matrixWorldInverse).applyMatrix4(e.projectionMatrix)}unproject(e){return this.applyMatrix4(e.projectionMatrixInverse).applyMatrix4(e.matrixWorld)}transformDirection(e){const t=this.x,i=this.y,n=this.z,s=e.elements;return this.x=s[0]*t+s[4]*i+s[8]*n,this.y=s[1]*t+s[5]*i+s[9]*n,this.z=s[2]*t+s[6]*i+s[10]*n,this.normalize()}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this}divideScalar(e){return this.multiplyScalar(1/e)}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this}clamp(e,t){return this.x=et(this.x,e.x,t.x),this.y=et(this.y,e.y,t.y),this.z=et(this.z,e.z,t.z),this}clampScalar(e,t){return this.x=et(this.x,e,t),this.y=et(this.y,e,t),this.z=et(this.z,e,t),this}clampLength(e,t){const i=this.length();return this.divideScalar(i||1).multiplyScalar(et(i,e,t))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this}lerpVectors(e,t,i){return this.x=e.x+(t.x-e.x)*i,this.y=e.y+(t.y-e.y)*i,this.z=e.z+(t.z-e.z)*i,this}cross(e){return this.crossVectors(this,e)}crossVectors(e,t){const i=e.x,n=e.y,s=e.z,a=t.x,o=t.y,c=t.z;return this.x=n*c-s*o,this.y=s*a-i*c,this.z=i*o-n*a,this}projectOnVector(e){const t=e.lengthSq();if(t===0)return this.set(0,0,0);const i=e.dot(this)/t;return this.copy(e).multiplyScalar(i)}projectOnPlane(e){return ph.copy(this).projectOnVector(e),this.sub(ph)}reflect(e){return this.sub(ph.copy(e).multiplyScalar(2*this.dot(e)))}angleTo(e){const t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;const i=this.dot(e)/t;return Math.acos(et(i,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,i=this.y-e.y,n=this.z-e.z;return t*t+i*i+n*n}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)+Math.abs(this.z-e.z)}setFromSpherical(e){return this.setFromSphericalCoords(e.radius,e.phi,e.theta)}setFromSphericalCoords(e,t,i){const n=Math.sin(t)*e;return this.x=n*Math.sin(i),this.y=Math.cos(t)*e,this.z=n*Math.cos(i),this}setFromCylindrical(e){return this.setFromCylindricalCoords(e.radius,e.theta,e.y)}setFromCylindricalCoords(e,t,i){return this.x=e*Math.sin(t),this.y=i,this.z=e*Math.cos(t),this}setFromMatrixPosition(e){const t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this}setFromMatrixScale(e){const t=this.setFromMatrixColumn(e,0).length(),i=this.setFromMatrixColumn(e,1).length(),n=this.setFromMatrixColumn(e,2).length();return this.x=t,this.y=i,this.z=n,this}setFromMatrixColumn(e,t){return this.fromArray(e.elements,t*4)}setFromMatrix3Column(e,t){return this.fromArray(e.elements,t*3)}setFromEuler(e){return this.x=e._x,this.y=e._y,this.z=e._z,this}setFromColor(e){return this.x=e.r,this.y=e.g,this.z=e.b,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const e=Math.random()*Math.PI*2,t=Math.random()*2-1,i=Math.sqrt(1-t*t);return this.x=i*Math.cos(e),this.y=t,this.z=i*Math.sin(e),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const ph=new R,Xf=new en;class Ye{static{Ye.prototype.isMatrix3=!0}constructor(e,t,i,n,s,a,o,c,l){this.elements=[1,0,0,0,1,0,0,0,1],e!==void 0&&this.set(e,t,i,n,s,a,o,c,l)}set(e,t,i,n,s,a,o,c,l){const h=this.elements;return h[0]=e,h[1]=n,h[2]=o,h[3]=t,h[4]=s,h[5]=c,h[6]=i,h[7]=a,h[8]=l,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(e){const t=this.elements,i=e.elements;return t[0]=i[0],t[1]=i[1],t[2]=i[2],t[3]=i[3],t[4]=i[4],t[5]=i[5],t[6]=i[6],t[7]=i[7],t[8]=i[8],this}extractBasis(e,t,i){return e.setFromMatrix3Column(this,0),t.setFromMatrix3Column(this,1),i.setFromMatrix3Column(this,2),this}setFromMatrix4(e){const t=e.elements;return this.set(t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]),this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){const i=e.elements,n=t.elements,s=this.elements,a=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],_=n[1],b=n[4],M=n[7],S=n[2],w=n[5],T=n[8];return s[0]=a*v+o*_+c*S,s[3]=a*m+o*b+c*w,s[6]=a*g+o*M+c*T,s[1]=l*v+h*_+u*S,s[4]=l*m+h*b+u*w,s[7]=l*g+h*M+u*T,s[2]=d*v+f*_+p*S,s[5]=d*m+f*b+p*w,s[8]=d*g+f*M+p*T,this}multiplyScalar(e){const t=this.elements;return t[0]*=e,t[3]*=e,t[6]*=e,t[1]*=e,t[4]*=e,t[7]*=e,t[2]*=e,t[5]*=e,t[8]*=e,this}determinant(){const e=this.elements,t=e[0],i=e[1],n=e[2],s=e[3],a=e[4],o=e[5],c=e[6],l=e[7],h=e[8];return t*a*h-t*o*l-i*s*h+i*o*c+n*s*l-n*a*c}invert(){const e=this.elements,t=e[0],i=e[1],n=e[2],s=e[3],a=e[4],o=e[5],c=e[6],l=e[7],h=e[8],u=h*a-o*l,d=o*c-h*s,f=l*s-a*c,p=t*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 e[0]=u*v,e[1]=(n*l-h*i)*v,e[2]=(o*i-n*a)*v,e[3]=d*v,e[4]=(h*t-n*c)*v,e[5]=(n*s-o*t)*v,e[6]=f*v,e[7]=(i*c-l*t)*v,e[8]=(a*t-i*s)*v,this}transpose(){let e;const t=this.elements;return e=t[1],t[1]=t[3],t[3]=e,e=t[2],t[2]=t[6],t[6]=e,e=t[5],t[5]=t[7],t[7]=e,this}getNormalMatrix(e){return this.setFromMatrix4(e).invert().transpose()}transposeIntoArray(e){const t=this.elements;return e[0]=t[0],e[1]=t[3],e[2]=t[6],e[3]=t[1],e[4]=t[4],e[5]=t[7],e[6]=t[2],e[7]=t[5],e[8]=t[8],this}setUvTransform(e,t,i,n,s,a,o){const c=Math.cos(s),l=Math.sin(s);return this.set(i*c,i*l,-i*(c*a+l*o)+a+e,-n*l,n*c,-n*(-l*a+c*o)+o+t,0,0,1),this}scale(e,t){return Er("Matrix3: .scale() is deprecated. Use .makeScale() instead."),this.premultiply(mh.makeScale(e,t)),this}rotate(e){return Er("Matrix3: .rotate() is deprecated. Use .makeRotation() instead."),this.premultiply(mh.makeRotation(-e)),this}translate(e,t){return Er("Matrix3: .translate() is deprecated. Use .makeTranslation() instead."),this.premultiply(mh.makeTranslation(e,t)),this}makeTranslation(e,t){return e.isVector2?this.set(1,0,e.x,0,1,e.y,0,0,1):this.set(1,0,e,0,1,t,0,0,1),this}makeRotation(e){const t=Math.cos(e),i=Math.sin(e);return this.set(t,-i,0,i,t,0,0,0,1),this}makeScale(e,t){return this.set(e,0,0,0,t,0,0,0,1),this}equals(e){const t=this.elements,i=e.elements;for(let n=0;n<9;n++)if(t[n]!==i[n])return!1;return!0}fromArray(e,t=0){for(let i=0;i<9;i++)this.elements[i]=e[i+t];return this}toArray(e=[],t=0){const i=this.elements;return e[t]=i[0],e[t+1]=i[1],e[t+2]=i[2],e[t+3]=i[3],e[t+4]=i[4],e[t+5]=i[5],e[t+6]=i[6],e[t+7]=i[7],e[t+8]=i[8],e}clone(){return new this.constructor().fromArray(this.elements)}}const mh=new Ye,Yf=new Ye().set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),qf=new Ye().set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);function zM(){const r={enabled:!0,workingColorSpace:El,spaces:{},convert:function(n,s,a){return this.enabled===!1||s===a||!s||!a||(this.spaces[s].transfer===yt&&(n.r=Ts(n.r),n.g=Ts(n.g),n.b=Ts(n.b)),this.spaces[s].primaries!==this.spaces[a].primaries&&(n.applyMatrix3(this.spaces[s].toXYZ),n.applyMatrix3(this.spaces[a].fromXYZ)),this.spaces[a].transfer===yt&&(n.r=Ar(n.r),n.g=Ar(n.g),n.b=Ar(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===Js?Al: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,a){return n.copy(this.spaces[s].toXYZ).multiply(this.spaces[a].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 Er("ColorManagement: .fromWorkingColorSpace() has been renamed to .workingToColorSpace()."),r.workingToColorSpace(n,s)},toWorkingColorSpace:function(n,s){return Er("ColorManagement: .toWorkingColorSpace() has been renamed to .colorSpaceToWorking()."),r.colorSpaceToWorking(n,s)}},e=[.64,.33,.3,.6,.15,.06],t=[.2126,.7152,.0722],i=[.3127,.329];return r.define({[El]:{primaries:e,whitePoint:i,transfer:Al,toXYZ:Yf,fromXYZ:qf,luminanceCoefficients:t,workingColorSpaceConfig:{unpackColorSpace:Gi},outputColorSpaceConfig:{drawingBufferColorSpace:Gi}},[Gi]:{primaries:e,whitePoint:i,transfer:yt,toXYZ:Yf,fromXYZ:qf,luminanceCoefficients:t,outputColorSpaceConfig:{drawingBufferColorSpace:Gi}}}),r}const at=zM();function Ts(r){return r<.04045?r*.0773993808:Math.pow(r*.9478672986+.0521327014,2.4)}function Ar(r){return r<.0031308?r*12.92:1.055*Math.pow(r,.41666)-.055}let qa;class BM{static getDataURL(e,t="image/png"){if(/^data:/i.test(e.src)||typeof HTMLCanvasElement>"u")return e.src;let i;if(e instanceof HTMLCanvasElement)i=e;else{qa===void 0&&(qa=Yo("canvas")),qa.width=e.width,qa.height=e.height;const n=qa.getContext("2d");e instanceof ImageData?n.putImageData(e,0,0):n.drawImage(e,0,0,e.width,e.height),i=qa}return i.toDataURL(t)}static sRGBToLinear(e){if(typeof HTMLImageElement<"u"&&e instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&e instanceof ImageBitmap){const t=Yo("canvas");t.width=e.width,t.height=e.height;const i=t.getContext("2d");i.drawImage(e,0,0,e.width,e.height);const n=i.getImageData(0,0,e.width,e.height),s=n.data;for(let a=0;a<s.length;a++)s[a]=Ts(s[a]/255)*255;return i.putImageData(n,0,0),t}else if(e.data){const t=e.data.slice(0);for(let i=0;i<t.length;i++)t instanceof Uint8Array||t instanceof Uint8ClampedArray?t[i]=Math.floor(Ts(t[i]/255)*255):t[i]=Ts(t[i]);return{data:t,width:e.width,height:e.height}}else return Re("ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."),e}}let HM=0;class _0{constructor(e=null){this.isSource=!0,Object.defineProperty(this,"id",{value:HM++}),this.uuid=Un(),this.data=e,this.dataReady=!0,this.version=0}getSize(e){const t=this.data;return typeof HTMLVideoElement<"u"&&t instanceof HTMLVideoElement?e.set(t.videoWidth,t.videoHeight,0):typeof VideoFrame<"u"&&t instanceof VideoFrame?e.set(t.displayWidth,t.displayHeight,0):t!==null?e.set(t.width,t.height,t.depth||0):e.set(0,0,0),e}set needsUpdate(e){e===!0&&this.version++}toJSON(e){const t=e===void 0||typeof e=="string";if(!t&&e.images[this.uuid]!==void 0)return e.images[this.uuid];const i={uuid:this.uuid,url:""},n=this.data;if(n!==null){let s;if(Array.isArray(n)){s=[];for(let a=0,o=n.length;a<o;a++)n[a].isDataTexture?s.push(gh(n[a].image)):s.push(gh(n[a]))}else s=gh(n);i.url=s}return t||(e.images[this.uuid]=i),i}}function gh(r){return typeof HTMLImageElement<"u"&&r instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&r instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&r instanceof ImageBitmap?BM.getDataURL(r):r.data?{data:Array.from(r.data),width:r.width,height:r.height,type:r.data.constructor.name}:(Re("Texture: Unable to serialize Texture."),{})}let GM=0;const vh=new R;class Si extends oa{constructor(e=Si.DEFAULT_IMAGE,t=Si.DEFAULT_MAPPING,i=wi,n=wi,s=rt,a=Ta,o=Ei,c=dn,l=Si.DEFAULT_ANISOTROPY,h=Js){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:GM++}),this.uuid=Un(),this.name="",this.source=new _0(e),this.mipmaps=[],this.mapping=t,this.channel=0,this.wrapS=i,this.wrapT=n,this.magFilter=s,this.minFilter=a,this.anisotropy=l,this.format=o,this.internalFormat=null,this.type=c,this.offset=new xe(0,0),this.repeat=new xe(1,1),this.center=new xe(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new Ye,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.colorSpace=h,this.userData={},this.updateRanges=[],this.version=0,this.onUpdate=null,this.renderTarget=null,this.isRenderTargetTexture=!1,this.isArrayTexture=!!(e&&e.depth&&e.depth>1),this.pmremVersion=0,this.normalized=!1}get width(){return this.source.getSize(vh).x}get height(){return this.source.getSize(vh).y}get depth(){return this.source.getSize(vh).z}get image(){return this.source.data}set image(e){this.source.data=e}updateMatrix(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y)}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}clone(){return new this.constructor().copy(this)}copy(e){return this.name=e.name,this.source=e.source,this.mipmaps=e.mipmaps.slice(0),this.mapping=e.mapping,this.channel=e.channel,this.wrapS=e.wrapS,this.wrapT=e.wrapT,this.magFilter=e.magFilter,this.minFilter=e.minFilter,this.anisotropy=e.anisotropy,this.format=e.format,this.internalFormat=e.internalFormat,this.type=e.type,this.normalized=e.normalized,this.offset.copy(e.offset),this.repeat.copy(e.repeat),this.center.copy(e.center),this.rotation=e.rotation,this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrix.copy(e.matrix),this.generateMipmaps=e.generateMipmaps,this.premultiplyAlpha=e.premultiplyAlpha,this.flipY=e.flipY,this.unpackAlignment=e.unpackAlignment,this.colorSpace=e.colorSpace,this.renderTarget=e.renderTarget,this.isRenderTargetTexture=e.isRenderTargetTexture,this.isArrayTexture=e.isArrayTexture,this.userData=JSON.parse(JSON.stringify(e.userData)),this.needsUpdate=!0,this}setValues(e){for(const t in e){const i=e[t];if(i===void 0){Re(`Texture.setValues(): parameter '${t}' has value of undefined.`);continue}const n=this[t];if(n===void 0){Re(`Texture.setValues(): property '${t}' does not exist.`);continue}n&&i&&n.isVector2&&i.isVector2||n&&i&&n.isVector3&&i.isVector3||n&&i&&n.isMatrix3&&i.isMatrix3?n.copy(i):this[t]=i}}toJSON(e){const t=e===void 0||typeof e=="string";if(!t&&e.textures[this.uuid]!==void 0)return e.textures[this.uuid];const i={metadata:{version:4.7,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,image:this.source.toJSON(e).uuid,mapping:this.mapping,channel:this.channel,repeat:[this.repeat.x,this.repeat.y],offset:[this.offset.x,this.offset.y],center:[this.center.x,this.center.y],rotation:this.rotation,wrap:[this.wrapS,this.wrapT],format:this.format,internalFormat:this.internalFormat,type:this.type,normalized:this.normalized,colorSpace:this.colorSpace,minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy,flipY:this.flipY,generateMipmaps:this.generateMipmaps,premultiplyAlpha:this.premultiplyAlpha,unpackAlignment:this.unpackAlignment};return Object.keys(this.userData).length>0&&(i.userData=this.userData),t||(e.textures[this.uuid]=i),i}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(e){if(this.mapping!==Xg)return e;if(e.applyMatrix3(this.matrix),e.x<0||e.x>1)switch(this.wrapS){case Go:e.x=e.x-Math.floor(e.x);break;case wi:e.x=e.x<0?0:1;break;case Gu:Math.abs(Math.floor(e.x)%2)===1?e.x=Math.ceil(e.x)-e.x:e.x=e.x-Math.floor(e.x);break}if(e.y<0||e.y>1)switch(this.wrapT){case Go:e.y=e.y-Math.floor(e.y);break;case wi:e.y=e.y<0?0:1;break;case Gu:Math.abs(Math.floor(e.y)%2)===1?e.y=Math.ceil(e.y)-e.y:e.y=e.y-Math.floor(e.y);break}return this.flipY&&(e.y=1-e.y),e}set needsUpdate(e){e===!0&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(e){e===!0&&this.pmremVersion++}}Si.DEFAULT_IMAGE=null;Si.DEFAULT_MAPPING=Xg;Si.DEFAULT_ANISOTROPY=1;class it{static{it.prototype.isVector4=!0}constructor(e=0,t=0,i=0,n=1){this.x=e,this.y=t,this.z=i,this.w=n}get width(){return this.z}set width(e){this.z=e}get height(){return this.w}set height(e){this.w=e}set(e,t,i,n){return this.x=e,this.y=t,this.z=i,this.w=n,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this.w=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setW(e){return this.w=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;case 3:this.w=t;break;default:throw new Error("THREE.Vector4: index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("THREE.Vector4: index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w!==void 0?e.w:1,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this.w+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this.w=e.w+t.w,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this.w+=e.w*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this.w-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this.w=e.w-t.w,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this.w*=e.w,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}applyMatrix4(e){const t=this.x,i=this.y,n=this.z,s=this.w,a=e.elements;return this.x=a[0]*t+a[4]*i+a[8]*n+a[12]*s,this.y=a[1]*t+a[5]*i+a[9]*n+a[13]*s,this.z=a[2]*t+a[6]*i+a[10]*n+a[14]*s,this.w=a[3]*t+a[7]*i+a[11]*n+a[15]*s,this}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this.w/=e.w,this}divideScalar(e){return this.multiplyScalar(1/e)}setAxisAngleFromQuaternion(e){this.w=2*Math.acos(e.w);const t=Math.sqrt(1-e.w*e.w);return t<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=e.x/t,this.y=e.y/t,this.z=e.z/t),this}setAxisAngleFromRotationMatrix(e){let t,i,n,s;const c=e.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;t=Math.PI;const b=(l+1)/2,M=(f+1)/2,S=(g+1)/2,w=(h+d)/4,T=(u+v)/4,x=(p+m)/4;return b>M&&b>S?b<.01?(i=0,n=.707106781,s=.707106781):(i=Math.sqrt(b),n=w/i,s=T/i):M>S?M<.01?(i=.707106781,n=0,s=.707106781):(n=Math.sqrt(M),i=w/n,s=x/n):S<.01?(i=.707106781,n=.707106781,s=0):(s=Math.sqrt(S),i=T/s,n=x/s),this.set(i,n,s,t),this}let _=Math.sqrt((m-p)*(m-p)+(u-v)*(u-v)+(d-h)*(d-h));return Math.abs(_)<.001&&(_=1),this.x=(m-p)/_,this.y=(u-v)/_,this.z=(d-h)/_,this.w=Math.acos((l+f+g-1)/2),this}setFromMatrixPosition(e){const t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this.w=t[15],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this.w=Math.min(this.w,e.w),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this.w=Math.max(this.w,e.w),this}clamp(e,t){return this.x=et(this.x,e.x,t.x),this.y=et(this.y,e.y,t.y),this.z=et(this.z,e.z,t.z),this.w=et(this.w,e.w,t.w),this}clampScalar(e,t){return this.x=et(this.x,e,t),this.y=et(this.y,e,t),this.z=et(this.z,e,t),this.w=et(this.w,e,t),this}clampLength(e,t){const i=this.length();return this.divideScalar(i||1).multiplyScalar(et(i,e,t))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z+this.w*e.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this.w+=(e.w-this.w)*t,this}lerpVectors(e,t,i){return this.x=e.x+(t.x-e.x)*i,this.y=e.y+(t.y-e.y)*i,this.z=e.z+(t.z-e.z)*i,this.w=e.w+(t.w-e.w)*i,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z&&e.w===this.w}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this.w=e[t+3],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e[t+3]=this.w,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this.w=e.getW(t),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}}class VM extends oa{constructor(e=1,t=1,i={}){super(),i=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:rt,depthBuffer:!0,stencilBuffer:!1,resolveDepthBuffer:!0,resolveStencilBuffer:!0,depthTexture:null,samples:0,count:1,depth:1,multiview:!1,useArrayDepthTexture:!1},i),this.isRenderTarget=!0,this.width=e,this.height=t,this.depth=i.depth,this.scissor=new it(0,0,e,t),this.scissorTest=!1,this.viewport=new it(0,0,e,t),this.textures=[];const n={width:e,height:t,depth:i.depth},s=new Si(n),a=i.count;for(let o=0;o<a;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(e={}){const t={minFilter:rt,generateMipmaps:!1,flipY:!1,internalFormat:null};e.mapping!==void 0&&(t.mapping=e.mapping),e.wrapS!==void 0&&(t.wrapS=e.wrapS),e.wrapT!==void 0&&(t.wrapT=e.wrapT),e.wrapR!==void 0&&(t.wrapR=e.wrapR),e.magFilter!==void 0&&(t.magFilter=e.magFilter),e.minFilter!==void 0&&(t.minFilter=e.minFilter),e.format!==void 0&&(t.format=e.format),e.type!==void 0&&(t.type=e.type),e.anisotropy!==void 0&&(t.anisotropy=e.anisotropy),e.colorSpace!==void 0&&(t.colorSpace=e.colorSpace),e.flipY!==void 0&&(t.flipY=e.flipY),e.generateMipmaps!==void 0&&(t.generateMipmaps=e.generateMipmaps),e.internalFormat!==void 0&&(t.internalFormat=e.internalFormat);for(let i=0;i<this.textures.length;i++)this.textures[i].setValues(t)}get texture(){return this.textures[0]}set texture(e){this.textures[0]=e}set depthTexture(e){this._depthTexture!==null&&(this._depthTexture.renderTarget=null),e!==null&&(e.renderTarget=this),this._depthTexture=e}get depthTexture(){return this._depthTexture}setSize(e,t,i=1){if(this.width!==e||this.height!==t||this.depth!==i){this.width=e,this.height=t,this.depth=i;for(let n=0,s=this.textures.length;n<s;n++)this.textures[n].image.width=e,this.textures[n].image.height=t,this.textures[n].image.depth=i,this.textures[n].isData3DTexture!==!0&&(this.textures[n].isArrayTexture=this.textures[n].image.depth>1);this.dispose()}this.viewport.set(0,0,e,t),this.scissor.set(0,0,e,t)}clone(){return new this.constructor().copy(this)}copy(e){this.width=e.width,this.height=e.height,this.depth=e.depth,this.scissor.copy(e.scissor),this.scissorTest=e.scissorTest,this.viewport.copy(e.viewport),this.textures.length=0;for(let t=0,i=e.textures.length;t<i;t++){this.textures[t]=e.textures[t].clone(),this.textures[t].isRenderTargetTexture=!0,this.textures[t].renderTarget=this;const n=Object.assign({},e.textures[t].image);this.textures[t].source=new _0(n)}return this.depthBuffer=e.depthBuffer,this.stencilBuffer=e.stencilBuffer,this.resolveDepthBuffer=e.resolveDepthBuffer,this.resolveStencilBuffer=e.resolveStencilBuffer,e.depthTexture!==null&&(this.depthTexture=e.depthTexture.clone()),this.samples=e.samples,this.multiview=e.multiview,this.useArrayDepthTexture=e.useArrayDepthTexture,this}dispose(){this.dispatchEvent({type:"dispose"})}}class ai extends VM{constructor(e=1,t=1,i={}){super(e,t,i),this.isWebGLRenderTarget=!0}}class e1 extends Si{constructor(e=null,t=1,i=1,n=1){super(null),this.isDataArrayTexture=!0,this.image={data:e,width:t,height:i,depth:n},this.magFilter=At,this.minFilter=At,this.wrapR=wi,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1,this.layerUpdates=new Set}addLayerUpdate(e){this.layerUpdates.add(e)}clearLayerUpdates(){this.layerUpdates.clear()}}class t1 extends Si{constructor(e=null,t=1,i=1,n=1){super(null),this.isData3DTexture=!0,this.image={data:e,width:t,height:i,depth:n},this.magFilter=At,this.minFilter=At,this.wrapR=wi,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}class Ze{static{Ze.prototype.isMatrix4=!0}constructor(e,t,i,n,s,a,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],e!==void 0&&this.set(e,t,i,n,s,a,o,c,l,h,u,d,f,p,v,m)}set(e,t,i,n,s,a,o,c,l,h,u,d,f,p,v,m){const g=this.elements;return g[0]=e,g[4]=t,g[8]=i,g[12]=n,g[1]=s,g[5]=a,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 Ze().fromArray(this.elements)}copy(e){const t=this.elements,i=e.elements;return t[0]=i[0],t[1]=i[1],t[2]=i[2],t[3]=i[3],t[4]=i[4],t[5]=i[5],t[6]=i[6],t[7]=i[7],t[8]=i[8],t[9]=i[9],t[10]=i[10],t[11]=i[11],t[12]=i[12],t[13]=i[13],t[14]=i[14],t[15]=i[15],this}copyPosition(e){const t=this.elements,i=e.elements;return t[12]=i[12],t[13]=i[13],t[14]=i[14],this}setFromMatrix3(e){const t=e.elements;return this.set(t[0],t[3],t[6],0,t[1],t[4],t[7],0,t[2],t[5],t[8],0,0,0,0,1),this}extractBasis(e,t,i){return this.determinantAffine()===0?(e.set(1,0,0),t.set(0,1,0),i.set(0,0,1),this):(e.setFromMatrixColumn(this,0),t.setFromMatrixColumn(this,1),i.setFromMatrixColumn(this,2),this)}makeBasis(e,t,i){return this.set(e.x,t.x,i.x,0,e.y,t.y,i.y,0,e.z,t.z,i.z,0,0,0,0,1),this}extractRotation(e){if(e.determinantAffine()===0)return this.identity();const t=this.elements,i=e.elements,n=1/$a.setFromMatrixColumn(e,0).length(),s=1/$a.setFromMatrixColumn(e,1).length(),a=1/$a.setFromMatrixColumn(e,2).length();return t[0]=i[0]*n,t[1]=i[1]*n,t[2]=i[2]*n,t[3]=0,t[4]=i[4]*s,t[5]=i[5]*s,t[6]=i[6]*s,t[7]=0,t[8]=i[8]*a,t[9]=i[9]*a,t[10]=i[10]*a,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromEuler(e){const t=this.elements,i=e.x,n=e.y,s=e.z,a=Math.cos(i),o=Math.sin(i),c=Math.cos(n),l=Math.sin(n),h=Math.cos(s),u=Math.sin(s);if(e.order==="XYZ"){const d=a*h,f=a*u,p=o*h,v=o*u;t[0]=c*h,t[4]=-c*u,t[8]=l,t[1]=f+p*l,t[5]=d-v*l,t[9]=-o*c,t[2]=v-d*l,t[6]=p+f*l,t[10]=a*c}else if(e.order==="YXZ"){const d=c*h,f=c*u,p=l*h,v=l*u;t[0]=d+v*o,t[4]=p*o-f,t[8]=a*l,t[1]=a*u,t[5]=a*h,t[9]=-o,t[2]=f*o-p,t[6]=v+d*o,t[10]=a*c}else if(e.order==="ZXY"){const d=c*h,f=c*u,p=l*h,v=l*u;t[0]=d-v*o,t[4]=-a*u,t[8]=p+f*o,t[1]=f+p*o,t[5]=a*h,t[9]=v-d*o,t[2]=-a*l,t[6]=o,t[10]=a*c}else if(e.order==="ZYX"){const d=a*h,f=a*u,p=o*h,v=o*u;t[0]=c*h,t[4]=p*l-f,t[8]=d*l+v,t[1]=c*u,t[5]=v*l+d,t[9]=f*l-p,t[2]=-l,t[6]=o*c,t[10]=a*c}else if(e.order==="YZX"){const d=a*c,f=a*l,p=o*c,v=o*l;t[0]=c*h,t[4]=v-d*u,t[8]=p*u+f,t[1]=u,t[5]=a*h,t[9]=-o*h,t[2]=-l*h,t[6]=f*u+p,t[10]=d-v*u}else if(e.order==="XZY"){const d=a*c,f=a*l,p=o*c,v=o*l;t[0]=c*h,t[4]=-u,t[8]=l*h,t[1]=d*u+v,t[5]=a*h,t[9]=f*u-p,t[2]=p*u-f,t[6]=o*h,t[10]=v*u+d}return t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromQuaternion(e){return this.compose(WM,e,XM)}lookAt(e,t,i){const n=this.elements;return nn.subVectors(e,t),nn.lengthSq()===0&&(nn.z=1),nn.normalize(),Us.crossVectors(i,nn),Us.lengthSq()===0&&(Math.abs(i.z)===1?nn.x+=1e-4:nn.z+=1e-4,nn.normalize(),Us.crossVectors(i,nn)),Us.normalize(),hc.crossVectors(nn,Us),n[0]=Us.x,n[4]=hc.x,n[8]=nn.x,n[1]=Us.y,n[5]=hc.y,n[9]=nn.y,n[2]=Us.z,n[6]=hc.z,n[10]=nn.z,this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){const i=e.elements,n=t.elements,s=this.elements,a=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],_=i[3],b=i[7],M=i[11],S=i[15],w=n[0],T=n[4],x=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],ee=n[7],J=n[11],ie=n[15];return s[0]=a*w+o*C+c*X+l*$,s[4]=a*T+o*I+c*L+l*ee,s[8]=a*x+o*P+c*B+l*J,s[12]=a*A+o*V+c*k+l*ie,s[1]=h*w+u*C+d*X+f*$,s[5]=h*T+u*I+d*L+f*ee,s[9]=h*x+u*P+d*B+f*J,s[13]=h*A+u*V+d*k+f*ie,s[2]=p*w+v*C+m*X+g*$,s[6]=p*T+v*I+m*L+g*ee,s[10]=p*x+v*P+m*B+g*J,s[14]=p*A+v*V+m*k+g*ie,s[3]=_*w+b*C+M*X+S*$,s[7]=_*T+b*I+M*L+S*ee,s[11]=_*x+b*P+M*B+S*J,s[15]=_*A+b*V+M*k+S*ie,this}multiplyScalar(e){const t=this.elements;return t[0]*=e,t[4]*=e,t[8]*=e,t[12]*=e,t[1]*=e,t[5]*=e,t[9]*=e,t[13]*=e,t[2]*=e,t[6]*=e,t[10]*=e,t[14]*=e,t[3]*=e,t[7]*=e,t[11]*=e,t[15]*=e,this}determinant(){const e=this.elements,t=e[0],i=e[4],n=e[8],s=e[12],a=e[1],o=e[5],c=e[9],l=e[13],h=e[2],u=e[6],d=e[10],f=e[14],p=e[3],v=e[7],m=e[11],g=e[15],_=c*f-l*d,b=o*f-l*u,M=o*d-c*u,S=a*f-l*h,w=a*d-c*h,T=a*u-o*h;return t*(v*_-m*b+g*M)-i*(p*_-m*S+g*w)+n*(p*b-v*S+g*T)-s*(p*M-v*w+m*T)}determinantAffine(){const e=this.elements,t=e[0],i=e[4],n=e[8],s=e[1],a=e[5],o=e[9],c=e[2],l=e[6],h=e[10];return t*(a*h-o*l)-i*(s*h-o*c)+n*(s*l-a*c)}transpose(){const e=this.elements;let t;return t=e[1],e[1]=e[4],e[4]=t,t=e[2],e[2]=e[8],e[8]=t,t=e[6],e[6]=e[9],e[9]=t,t=e[3],e[3]=e[12],e[12]=t,t=e[7],e[7]=e[13],e[13]=t,t=e[11],e[11]=e[14],e[14]=t,this}setPosition(e,t,i){const n=this.elements;return e.isVector3?(n[12]=e.x,n[13]=e.y,n[14]=e.z):(n[12]=e,n[13]=t,n[14]=i),this}invert(){const e=this.elements,t=e[0],i=e[1],n=e[2],s=e[3],a=e[4],o=e[5],c=e[6],l=e[7],h=e[8],u=e[9],d=e[10],f=e[11],p=e[12],v=e[13],m=e[14],g=e[15],_=t*o-i*a,b=t*c-n*a,M=t*l-s*a,S=i*c-n*o,w=i*l-s*o,T=n*l-s*c,x=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=_*V-b*P+M*I+S*C-w*A+T*x;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 e[0]=(o*V-c*P+l*I)*L,e[1]=(n*P-i*V-s*I)*L,e[2]=(v*T-m*w+g*S)*L,e[3]=(d*w-u*T-f*S)*L,e[4]=(c*C-a*V-l*A)*L,e[5]=(t*V-n*C+s*A)*L,e[6]=(m*M-p*T-g*b)*L,e[7]=(h*T-d*M+f*b)*L,e[8]=(a*P-o*C+l*x)*L,e[9]=(i*C-t*P-s*x)*L,e[10]=(p*w-v*M+g*_)*L,e[11]=(u*M-h*w-f*_)*L,e[12]=(o*A-a*I-c*x)*L,e[13]=(t*I-i*A+n*x)*L,e[14]=(v*b-p*S-m*_)*L,e[15]=(h*S-u*b+d*_)*L,this}scale(e){const t=this.elements,i=e.x,n=e.y,s=e.z;return t[0]*=i,t[4]*=n,t[8]*=s,t[1]*=i,t[5]*=n,t[9]*=s,t[2]*=i,t[6]*=n,t[10]*=s,t[3]*=i,t[7]*=n,t[11]*=s,this}getMaxScaleOnAxis(){const e=this.elements,t=e[0]*e[0]+e[1]*e[1]+e[2]*e[2],i=e[4]*e[4]+e[5]*e[5]+e[6]*e[6],n=e[8]*e[8]+e[9]*e[9]+e[10]*e[10];return Math.sqrt(Math.max(t,i,n))}makeTranslation(e,t,i){return e.isVector3?this.set(1,0,0,e.x,0,1,0,e.y,0,0,1,e.z,0,0,0,1):this.set(1,0,0,e,0,1,0,t,0,0,1,i,0,0,0,1),this}makeRotationX(e){const t=Math.cos(e),i=Math.sin(e);return this.set(1,0,0,0,0,t,-i,0,0,i,t,0,0,0,0,1),this}makeRotationY(e){const t=Math.cos(e),i=Math.sin(e);return this.set(t,0,i,0,0,1,0,0,-i,0,t,0,0,0,0,1),this}makeRotationZ(e){const t=Math.cos(e),i=Math.sin(e);return this.set(t,-i,0,0,i,t,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(e,t){const i=Math.cos(t),n=Math.sin(t),s=1-i,a=e.x,o=e.y,c=e.z,l=s*a,h=s*o;return this.set(l*a+i,l*o-n*c,l*c+n*o,0,l*o+n*c,h*o+i,h*c-n*a,0,l*c-n*o,h*c+n*a,s*c*c+i,0,0,0,0,1),this}makeScale(e,t,i){return this.set(e,0,0,0,0,t,0,0,0,0,i,0,0,0,0,1),this}makeShear(e,t,i,n,s,a){return this.set(1,i,s,0,e,1,a,0,t,n,1,0,0,0,0,1),this}compose(e,t,i){const n=this.elements,s=t._x,a=t._y,o=t._z,c=t._w,l=s+s,h=a+a,u=o+o,d=s*l,f=s*h,p=s*u,v=a*h,m=a*u,g=o*u,_=c*l,b=c*h,M=c*u,S=i.x,w=i.y,T=i.z;return n[0]=(1-(v+g))*S,n[1]=(f+M)*S,n[2]=(p-b)*S,n[3]=0,n[4]=(f-M)*w,n[5]=(1-(d+g))*w,n[6]=(m+_)*w,n[7]=0,n[8]=(p+b)*T,n[9]=(m-_)*T,n[10]=(1-(d+v))*T,n[11]=0,n[12]=e.x,n[13]=e.y,n[14]=e.z,n[15]=1,this}decompose(e,t,i){const n=this.elements;e.x=n[12],e.y=n[13],e.z=n[14];const s=this.determinantAffine();if(s===0)return i.set(1,1,1),t.identity(),this;let a=$a.set(n[0],n[1],n[2]).length();const o=$a.set(n[4],n[5],n[6]).length(),c=$a.set(n[8],n[9],n[10]).length();s<0&&(a=-a),Sn.copy(this);const l=1/a,h=1/o,u=1/c;return Sn.elements[0]*=l,Sn.elements[1]*=l,Sn.elements[2]*=l,Sn.elements[4]*=h,Sn.elements[5]*=h,Sn.elements[6]*=h,Sn.elements[8]*=u,Sn.elements[9]*=u,Sn.elements[10]*=u,t.setFromRotationMatrix(Sn),i.x=a,i.y=o,i.z=c,this}makePerspective(e,t,i,n,s,a,o=ns,c=!1){const l=this.elements,h=2*s/(t-e),u=2*s/(i-n),d=(t+e)/(t-e),f=(i+n)/(i-n);let p,v;if(c)p=s/(a-s),v=a*s/(a-s);else if(o===ns)p=-(a+s)/(a-s),v=-2*a*s/(a-s);else if(o===Xo)p=-a/(a-s),v=-a*s/(a-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(e,t,i,n,s,a,o=ns,c=!1){const l=this.elements,h=2/(t-e),u=2/(i-n),d=-(t+e)/(t-e),f=-(i+n)/(i-n);let p,v;if(c)p=1/(a-s),v=a/(a-s);else if(o===ns)p=-2/(a-s),v=-(a+s)/(a-s);else if(o===Xo)p=-1/(a-s),v=-s/(a-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(e){const t=this.elements,i=e.elements;for(let n=0;n<16;n++)if(t[n]!==i[n])return!1;return!0}fromArray(e,t=0){for(let i=0;i<16;i++)this.elements[i]=e[i+t];return this}toArray(e=[],t=0){const i=this.elements;return e[t]=i[0],e[t+1]=i[1],e[t+2]=i[2],e[t+3]=i[3],e[t+4]=i[4],e[t+5]=i[5],e[t+6]=i[6],e[t+7]=i[7],e[t+8]=i[8],e[t+9]=i[9],e[t+10]=i[10],e[t+11]=i[11],e[t+12]=i[12],e[t+13]=i[13],e[t+14]=i[14],e[t+15]=i[15],e}}const $a=new R,Sn=new Ze,WM=new R(0,0,0),XM=new R(1,1,1),Us=new R,hc=new R,nn=new R,$f=new Ze,Kf=new en;class Ds{constructor(e=0,t=0,i=0,n=Ds.DEFAULT_ORDER){this.isEuler=!0,this._x=e,this._y=t,this._z=i,this._order=n}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get order(){return this._order}set order(e){this._order=e,this._onChangeCallback()}set(e,t,i,n=this._order){return this._x=e,this._y=t,this._z=i,this._order=n,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(e){return this._x=e._x,this._y=e._y,this._z=e._z,this._order=e._order,this._onChangeCallback(),this}setFromRotationMatrix(e,t=this._order,i=!0){const n=e.elements,s=n[0],a=n[4],o=n[8],c=n[1],l=n[5],h=n[9],u=n[2],d=n[6],f=n[10];switch(t){case"XYZ":this._y=Math.asin(et(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-h,f),this._z=Math.atan2(-a,s)):(this._x=Math.atan2(d,l),this._z=0);break;case"YXZ":this._x=Math.asin(-et(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(et(d,-1,1)),Math.abs(d)<.9999999?(this._y=Math.atan2(-u,f),this._z=Math.atan2(-a,l)):(this._y=0,this._z=Math.atan2(c,s));break;case"ZYX":this._y=Math.asin(-et(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(-a,l));break;case"YZX":this._z=Math.asin(et(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(-et(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(d,l),this._y=Math.atan2(o,s)):(this._x=Math.atan2(-h,f),this._y=0);break;default:Re("Euler: .setFromRotationMatrix() encountered an unknown order: "+t)}return this._order=t,i===!0&&this._onChangeCallback(),this}setFromQuaternion(e,t,i){return $f.makeRotationFromQuaternion(e),this.setFromRotationMatrix($f,t,i)}setFromVector3(e,t=this._order){return this.set(e.x,e.y,e.z,t)}reorder(e){return Kf.setFromEuler(this),this.setFromQuaternion(Kf,e)}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._order===this._order}fromArray(e){return this._x=e[0],this._y=e[1],this._z=e[2],e[3]!==void 0&&(this._order=e[3]),this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._order,e}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}Ds.DEFAULT_ORDER="XYZ";class S0{constructor(){this.mask=1}set(e){this.mask=(1<<e|0)>>>0}enable(e){this.mask|=1<<e|0}enableAll(){this.mask=-1}toggle(e){this.mask^=1<<e|0}disable(e){this.mask&=~(1<<e|0)}disableAll(){this.mask=0}test(e){return(this.mask&e.mask)!==0}isEnabled(e){return(this.mask&(1<<e|0))!==0}}let YM=0;const Zf=new R,Ka=new en,ls=new Ze,uc=new R,$r=new R,qM=new R,$M=new en,Jf=new R(1,0,0),jf=new R(0,1,0),Qf=new R(0,0,1),ep={type:"added"},KM={type:"removed"},Za={type:"childadded",child:null},Mh={type:"childremoved",child:null};class Ut extends oa{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:YM++}),this.uuid=Un(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=Ut.DEFAULT_UP.clone();const e=new R,t=new Ds,i=new en,n=new R(1,1,1);function s(){i.setFromEuler(t,!1)}function a(){t.setFromQuaternion(i,void 0,!1)}t._onChange(s),i._onChange(a),Object.defineProperties(this,{position:{configurable:!0,enumerable:!0,value:e},rotation:{configurable:!0,enumerable:!0,value:t},quaternion:{configurable:!0,enumerable:!0,value:i},scale:{configurable:!0,enumerable:!0,value:n},modelViewMatrix:{value:new Ze},normalMatrix:{value:new Ye}}),this.matrix=new Ze,this.matrixWorld=new Ze,this.matrixAutoUpdate=Ut.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=Ut.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new S0,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.renderOrder=0,this.animations=[],this.customDepthMaterial=void 0,this.customDistanceMaterial=void 0,this.static=!1,this.userData={},this.pivot=null}onBeforeShadow(){}onAfterShadow(){}onBeforeRender(){}onAfterRender(){}applyMatrix4(e){this.matrixAutoUpdate&&this.updateMatrix(),this.matrix.premultiply(e),this.matrix.decompose(this.position,this.quaternion,this.scale)}applyQuaternion(e){return this.quaternion.premultiply(e),this}setRotationFromAxisAngle(e,t){this.quaternion.setFromAxisAngle(e,t)}setRotationFromEuler(e){this.quaternion.setFromEuler(e,!0)}setRotationFromMatrix(e){this.quaternion.setFromRotationMatrix(e)}setRotationFromQuaternion(e){this.quaternion.copy(e)}rotateOnAxis(e,t){return Ka.setFromAxisAngle(e,t),this.quaternion.multiply(Ka),this}rotateOnWorldAxis(e,t){return Ka.setFromAxisAngle(e,t),this.quaternion.premultiply(Ka),this}rotateX(e){return this.rotateOnAxis(Jf,e)}rotateY(e){return this.rotateOnAxis(jf,e)}rotateZ(e){return this.rotateOnAxis(Qf,e)}translateOnAxis(e,t){return Zf.copy(e).applyQuaternion(this.quaternion),this.position.add(Zf.multiplyScalar(t)),this}translateX(e){return this.translateOnAxis(Jf,e)}translateY(e){return this.translateOnAxis(jf,e)}translateZ(e){return this.translateOnAxis(Qf,e)}localToWorld(e){return this.updateWorldMatrix(!0,!1),e.applyMatrix4(this.matrixWorld)}worldToLocal(e){return this.updateWorldMatrix(!0,!1),e.applyMatrix4(ls.copy(this.matrixWorld).invert())}lookAt(e,t,i){e.isVector3?uc.copy(e):uc.set(e,t,i);const n=this.parent;this.updateWorldMatrix(!0,!1),$r.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?ls.lookAt($r,uc,this.up):ls.lookAt(uc,$r,this.up),this.quaternion.setFromRotationMatrix(ls),n&&(ls.extractRotation(n.matrixWorld),Ka.setFromRotationMatrix(ls),this.quaternion.premultiply(Ka.invert()))}add(e){if(arguments.length>1){for(let t=0;t<arguments.length;t++)this.add(arguments[t]);return this}return e===this?(Ge("Object3D.add: object can't be added as a child of itself.",e),this):(e&&e.isObject3D?(e.removeFromParent(),e.parent=this,this.children.push(e),e.dispatchEvent(ep),Za.child=e,this.dispatchEvent(Za),Za.child=null):Ge("Object3D.add: object not an instance of THREE.Object3D.",e),this)}remove(e){if(arguments.length>1){for(let i=0;i<arguments.length;i++)this.remove(arguments[i]);return this}const t=this.children.indexOf(e);return t!==-1&&(e.parent=null,this.children.splice(t,1),e.dispatchEvent(KM),Mh.child=e,this.dispatchEvent(Mh),Mh.child=null),this}removeFromParent(){const e=this.parent;return e!==null&&e.remove(this),this}clear(){return this.remove(...this.children)}attach(e){return this.updateWorldMatrix(!0,!1),ls.copy(this.matrixWorld).invert(),e.parent!==null&&(e.parent.updateWorldMatrix(!0,!1),ls.multiply(e.parent.matrixWorld)),e.applyMatrix4(ls),e.removeFromParent(),e.parent=this,this.children.push(e),e.updateWorldMatrix(!1,!0),e.dispatchEvent(ep),Za.child=e,this.dispatchEvent(Za),Za.child=null,this}getObjectById(e){return this.getObjectByProperty("id",e)}getObjectByName(e){return this.getObjectByProperty("name",e)}getObjectByProperty(e,t){if(this[e]===t)return this;for(let i=0,n=this.children.length;i<n;i++){const a=this.children[i].getObjectByProperty(e,t);if(a!==void 0)return a}}getObjectsByProperty(e,t,i=[]){this[e]===t&&i.push(this);const n=this.children;for(let s=0,a=n.length;s<a;s++)n[s].getObjectsByProperty(e,t,i);return i}getWorldPosition(e){return this.updateWorldMatrix(!0,!1),e.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(e){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose($r,e,qM),e}getWorldScale(e){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose($r,$M,e),e}getWorldDirection(e){this.updateWorldMatrix(!0,!1);const t=this.matrixWorld.elements;return e.set(t[8],t[9],t[10]).normalize()}raycast(){}traverse(e){e(this);const t=this.children;for(let i=0,n=t.length;i<n;i++)t[i].traverse(e)}traverseVisible(e){if(this.visible===!1)return;e(this);const t=this.children;for(let i=0,n=t.length;i<n;i++)t[i].traverseVisible(e)}traverseAncestors(e){const t=this.parent;t!==null&&(e(t),t.traverseAncestors(e))}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale);const e=this.pivot;if(e!==null){const t=e.x,i=e.y,n=e.z,s=this.matrix.elements;s[12]+=t-s[0]*t-s[4]*i-s[8]*n,s[13]+=i-s[1]*t-s[5]*i-s[9]*n,s[14]+=n-s[2]*t-s[6]*i-s[10]*n}this.matrixWorldNeedsUpdate=!0}updateMatrixWorld(e){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||e)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,e=!0);const t=this.children;for(let i=0,n=t.length;i<n;i++)t[i].updateMatrixWorld(e)}updateWorldMatrix(e,t,i=!1){const n=this.parent;if(e===!0&&n!==null&&n.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||i)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,i=!0),t===!0){const s=this.children;for(let a=0,o=s.length;a<o;a++)s[a].updateWorldMatrix(!1,!0,i)}}toJSON(e){const t=e===void 0||typeof e=="string",i={};t&&(e={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},i.metadata={version:4.7,type:"Object",generator:"Object3D.toJSON"});const n={};n.uuid=this.uuid,n.type=this.type,this.name!==""&&(n.name=this.name),this.castShadow===!0&&(n.castShadow=!0),this.receiveShadow===!0&&(n.receiveShadow=!0),this.visible===!1&&(n.visible=!1),this.frustumCulled===!1&&(n.frustumCulled=!1),this.renderOrder!==0&&(n.renderOrder=this.renderOrder),this.static!==!1&&(n.static=this.static),Object.keys(this.userData).length>0&&(n.userData=this.userData),n.layers=this.layers.mask,n.matrix=this.matrix.toArray(),n.up=this.up.toArray(),this.pivot!==null&&(n.pivot=this.pivot.toArray()),this.matrixAutoUpdate===!1&&(n.matrixAutoUpdate=!1),this.morphTargetDictionary!==void 0&&(n.morphTargetDictionary=Object.assign({},this.morphTargetDictionary)),this.morphTargetInfluences!==void 0&&(n.morphTargetInfluences=this.morphTargetInfluences.slice()),this.isInstancedMesh&&(n.type="InstancedMesh",n.count=this.count,n.instanceMatrix=this.instanceMatrix.toJSON(),this.instanceColor!==null&&(n.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(n.type="BatchedMesh",n.perObjectFrustumCulled=this.perObjectFrustumCulled,n.sortObjects=this.sortObjects,n.drawRanges=this._drawRanges,n.reservedRanges=this._reservedRanges,n.geometryInfo=this._geometryInfo.map(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(e),n.indirectTexture=this._indirectTexture.toJSON(e),this._colorsTexture!==null&&(n.colorsTexture=this._colorsTexture.toJSON(e)),this.boundingSphere!==null&&(n.boundingSphere=this.boundingSphere.toJSON()),this.boundingBox!==null&&(n.boundingBox=this.boundingBox.toJSON()));function s(o,c){return o[c.uuid]===void 0&&(o[c.uuid]=c.toJSON(e)),c.uuid}if(this.isScene)this.background&&(this.background.isColor?n.background=this.background.toJSON():this.background.isTexture&&(n.background=this.background.toJSON(e).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(n.environment=this.environment.toJSON(e).uuid);else if(this.isMesh||this.isLine||this.isPoints){n.geometry=s(e.geometries,this.geometry);const 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(e.shapes,u)}else s(e.shapes,c)}}if(this.isSkinnedMesh&&(n.bindMode=this.bindMode,n.bindMatrix=this.bindMatrix.toArray(),this.skeleton!==void 0&&(s(e.skeletons,this.skeleton),n.skeleton=this.skeleton.uuid)),this.material!==void 0)if(Array.isArray(this.material)){const o=[];for(let c=0,l=this.material.length;c<l;c++)o.push(s(e.materials,this.material[c]));n.material=o}else n.material=s(e.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(e).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(e.animations,c))}}if(t){const o=a(e.geometries),c=a(e.materials),l=a(e.textures),h=a(e.images),u=a(e.shapes),d=a(e.skeletons),f=a(e.animations),p=a(e.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 a(o){const c=[];for(const l in o){const h=o[l];delete h.metadata,c.push(h)}return c}}clone(e){return new this.constructor().copy(this,e)}copy(e,t=!0){if(this.name=e.name,this.up.copy(e.up),this.position.copy(e.position),this.rotation.order=e.rotation.order,this.quaternion.copy(e.quaternion),this.scale.copy(e.scale),this.pivot=e.pivot!==null?e.pivot.clone():null,this.matrix.copy(e.matrix),this.matrixWorld.copy(e.matrixWorld),this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrixWorldAutoUpdate=e.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=e.matrixWorldNeedsUpdate,this.layers.mask=e.layers.mask,this.visible=e.visible,this.castShadow=e.castShadow,this.receiveShadow=e.receiveShadow,this.frustumCulled=e.frustumCulled,this.renderOrder=e.renderOrder,this.static=e.static,this.animations=e.animations.slice(),this.userData=JSON.parse(JSON.stringify(e.userData)),t===!0)for(let i=0;i<e.children.length;i++){const n=e.children[i];this.add(n.clone())}return this}}Ut.DEFAULT_UP=new R(0,1,0);Ut.DEFAULT_MATRIX_AUTO_UPDATE=!0;Ut.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;class Dt extends Ut{constructor(){super(),this.isGroup=!0,this.type="Group"}}const ZM={type:"move"};class xh{constructor(){this._targetRay=null,this._grip=null,this._hand=null}getHandSpace(){return this._hand===null&&(this._hand=new Dt,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 Dt,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 Dt,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(e){return this._targetRay!==null&&this._targetRay.dispatchEvent(e),this._grip!==null&&this._grip.dispatchEvent(e),this._hand!==null&&this._hand.dispatchEvent(e),this}connect(e){if(e&&e.hand){const t=this._hand;if(t)for(const i of e.hand.values())this._getHandJoint(t,i)}return this.dispatchEvent({type:"connected",data:e}),this}disconnect(e){return this.dispatchEvent({type:"disconnected",data:e}),this._targetRay!==null&&(this._targetRay.visible=!1),this._grip!==null&&(this._grip.visible=!1),this._hand!==null&&(this._hand.visible=!1),this}update(e,t,i){let n=null,s=null,a=null;const o=this._targetRay,c=this._grip,l=this._hand;if(e&&t.session.visibilityState!=="visible-blurred"){if(l&&e.hand){a=!0;for(const v of e.hand.values()){const m=t.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:e.handedness,target:this})):!l.inputState.pinching&&d<=f-p&&(l.inputState.pinching=!0,this.dispatchEvent({type:"pinchstart",handedness:e.handedness,target:this}))}else c!==null&&e.gripSpace&&(s=t.getPose(e.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:e,target:this})));o!==null&&(n=t.getPose(e.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(ZM)))}return o!==null&&(o.visible=n!==null),c!==null&&(c.visible=s!==null),l!==null&&(l.visible=a!==null),this}_getHandJoint(e,t){if(e.joints[t.jointName]===void 0){const i=new Dt;i.matrixAutoUpdate=!1,i.visible=!1,e.joints[t.jointName]=i,e.add(i)}return e.joints[t.jointName]}}const i1={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},ks={h:0,s:0,l:0},dc={h:0,s:0,l:0};function yh(r,e,t){return t<0&&(t+=1),t>1&&(t-=1),t<1/6?r+(e-r)*6*t:t<1/2?e:t<2/3?r+(e-r)*6*(2/3-t):r}class se{constructor(e,t,i){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(e,t,i)}set(e,t,i){if(t===void 0&&i===void 0){const n=e;n&&n.isColor?this.copy(n):typeof n=="number"?this.setHex(n):typeof n=="string"&&this.setStyle(n)}else this.setRGB(e,t,i);return this}setScalar(e){return this.r=e,this.g=e,this.b=e,this}setHex(e,t=Gi){return e=Math.floor(e),this.r=(e>>16&255)/255,this.g=(e>>8&255)/255,this.b=(e&255)/255,at.colorSpaceToWorking(this,t),this}setRGB(e,t,i,n=at.workingColorSpace){return this.r=e,this.g=t,this.b=i,at.colorSpaceToWorking(this,n),this}setHSL(e,t,i,n=at.workingColorSpace){if(e=b0(e,1),t=et(t,0,1),i=et(i,0,1),t===0)this.r=this.g=this.b=i;else{const s=i<=.5?i*(1+t):i+t-i*t,a=2*i-s;this.r=yh(a,s,e+1/3),this.g=yh(a,s,e),this.b=yh(a,s,e-1/3)}return at.colorSpaceToWorking(this,n),this}setStyle(e,t=Gi){function i(s){s!==void 0&&parseFloat(s)<1&&Re("Color: Alpha component of "+e+" will be ignored.")}let n;if(n=/^(\w+)\(([^\)]*)\)/.exec(e)){let s;const a=n[1],o=n[2];switch(a){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,t);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,t);break;case"hsl":case"hsla":if(s=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return i(s[4]),this.setHSL(parseFloat(s[1])/360,parseFloat(s[2])/100,parseFloat(s[3])/100,t);break;default:Re("Color: Unknown color model "+e)}}else if(n=/^\#([A-Fa-f\d]+)$/.exec(e)){const s=n[1],a=s.length;if(a===3)return this.setRGB(parseInt(s.charAt(0),16)/15,parseInt(s.charAt(1),16)/15,parseInt(s.charAt(2),16)/15,t);if(a===6)return this.setHex(parseInt(s,16),t);Re("Color: Invalid hex color "+e)}else if(e&&e.length>0)return this.setColorName(e,t);return this}setColorName(e,t=Gi){const i=i1[e.toLowerCase()];return i!==void 0?this.setHex(i,t):Re("Color: Unknown color "+e),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(e){return this.r=e.r,this.g=e.g,this.b=e.b,this}copySRGBToLinear(e){return this.r=Ts(e.r),this.g=Ts(e.g),this.b=Ts(e.b),this}copyLinearToSRGB(e){return this.r=Ar(e.r),this.g=Ar(e.g),this.b=Ar(e.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(e=Gi){return at.workingToColorSpace(Di.copy(this),e),Math.round(et(Di.r*255,0,255))*65536+Math.round(et(Di.g*255,0,255))*256+Math.round(et(Di.b*255,0,255))}getHexString(e=Gi){return("000000"+this.getHex(e).toString(16)).slice(-6)}getHSL(e,t=at.workingColorSpace){at.workingToColorSpace(Di.copy(this),t);const i=Di.r,n=Di.g,s=Di.b,a=Math.max(i,n,s),o=Math.min(i,n,s);let c,l;const h=(o+a)/2;if(o===a)c=0,l=0;else{const u=a-o;switch(l=h<=.5?u/(a+o):u/(2-a-o),a){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 e.h=c,e.s=l,e.l=h,e}getRGB(e,t=at.workingColorSpace){return at.workingToColorSpace(Di.copy(this),t),e.r=Di.r,e.g=Di.g,e.b=Di.b,e}getStyle(e=Gi){at.workingToColorSpace(Di.copy(this),e);const t=Di.r,i=Di.g,n=Di.b;return e!==Gi?`color(${e} ${t.toFixed(3)} ${i.toFixed(3)} ${n.toFixed(3)})`:`rgb(${Math.round(t*255)},${Math.round(i*255)},${Math.round(n*255)})`}offsetHSL(e,t,i){return this.getHSL(ks),this.setHSL(ks.h+e,ks.s+t,ks.l+i)}add(e){return this.r+=e.r,this.g+=e.g,this.b+=e.b,this}addColors(e,t){return this.r=e.r+t.r,this.g=e.g+t.g,this.b=e.b+t.b,this}addScalar(e){return this.r+=e,this.g+=e,this.b+=e,this}sub(e){return this.r=Math.max(0,this.r-e.r),this.g=Math.max(0,this.g-e.g),this.b=Math.max(0,this.b-e.b),this}multiply(e){return this.r*=e.r,this.g*=e.g,this.b*=e.b,this}multiplyScalar(e){return this.r*=e,this.g*=e,this.b*=e,this}lerp(e,t){return this.r+=(e.r-this.r)*t,this.g+=(e.g-this.g)*t,this.b+=(e.b-this.b)*t,this}lerpColors(e,t,i){return this.r=e.r+(t.r-e.r)*i,this.g=e.g+(t.g-e.g)*i,this.b=e.b+(t.b-e.b)*i,this}lerpHSL(e,t){this.getHSL(ks),e.getHSL(dc);const i=Do(ks.h,dc.h,t),n=Do(ks.s,dc.s,t),s=Do(ks.l,dc.l,t);return this.setHSL(i,n,s),this}setFromVector3(e){return this.r=e.x,this.g=e.y,this.b=e.z,this}applyMatrix3(e){const t=this.r,i=this.g,n=this.b,s=e.elements;return this.r=s[0]*t+s[3]*i+s[6]*n,this.g=s[1]*t+s[4]*i+s[7]*n,this.b=s[2]*t+s[5]*i+s[8]*n,this}equals(e){return e.r===this.r&&e.g===this.g&&e.b===this.b}fromArray(e,t=0){return this.r=e[t],this.g=e[t+1],this.b=e[t+2],this}toArray(e=[],t=0){return e[t]=this.r,e[t+1]=this.g,e[t+2]=this.b,e}fromBufferAttribute(e,t){return this.r=e.getX(t),this.g=e.getY(t),this.b=e.getZ(t),this}toJSON(){return this.getHex()}*[Symbol.iterator](){yield this.r,yield this.g,yield this.b}}const Di=new se;se.NAMES=i1;class w0{constructor(e,t=1,i=1e3){this.isFog=!0,this.name="",this.color=new se(e),this.near=t,this.far=i}clone(){return new w0(this.color,this.near,this.far)}toJSON(){return{type:"Fog",name:this.name,color:this.color.getHex(),near:this.near,far:this.far}}}class Is extends Ut{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 Ds,this.environmentIntensity=1,this.environmentRotation=new Ds,this.overrideMaterial=null,typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}copy(e,t){return super.copy(e,t),e.background!==null&&(this.background=e.background.clone()),e.environment!==null&&(this.environment=e.environment.clone()),e.fog!==null&&(this.fog=e.fog.clone()),this.backgroundBlurriness=e.backgroundBlurriness,this.backgroundIntensity=e.backgroundIntensity,this.backgroundRotation.copy(e.backgroundRotation),this.environmentIntensity=e.environmentIntensity,this.environmentRotation.copy(e.environmentRotation),e.overrideMaterial!==null&&(this.overrideMaterial=e.overrideMaterial.clone()),this.matrixAutoUpdate=e.matrixAutoUpdate,this}toJSON(e){const t=super.toJSON(e);return this.fog!==null&&(t.object.fog=this.fog.toJSON()),this.backgroundBlurriness>0&&(t.object.backgroundBlurriness=this.backgroundBlurriness),this.backgroundIntensity!==1&&(t.object.backgroundIntensity=this.backgroundIntensity),t.object.backgroundRotation=this.backgroundRotation.toArray(),this.environmentIntensity!==1&&(t.object.environmentIntensity=this.environmentIntensity),t.object.environmentRotation=this.environmentRotation.toArray(),t}}const wn=new R,hs=new R,bh=new R,us=new R,Ja=new R,ja=new R,tp=new R,_h=new R,Sh=new R,wh=new R,Eh=new it,Ah=new it,Th=new it;class yn{constructor(e=new R,t=new R,i=new R){this.a=e,this.b=t,this.c=i}static getNormal(e,t,i,n){n.subVectors(i,t),wn.subVectors(e,t),n.cross(wn);const s=n.lengthSq();return s>0?n.multiplyScalar(1/Math.sqrt(s)):n.set(0,0,0)}static getBarycoord(e,t,i,n,s){wn.subVectors(n,t),hs.subVectors(i,t),bh.subVectors(e,t);const a=wn.dot(wn),o=wn.dot(hs),c=wn.dot(bh),l=hs.dot(hs),h=hs.dot(bh),u=a*l-o*o;if(u===0)return s.set(0,0,0),null;const d=1/u,f=(l*c-o*h)*d,p=(a*h-o*c)*d;return s.set(1-f-p,p,f)}static containsPoint(e,t,i,n){return this.getBarycoord(e,t,i,n,us)===null?!1:us.x>=0&&us.y>=0&&us.x+us.y<=1}static getInterpolation(e,t,i,n,s,a,o,c){return this.getBarycoord(e,t,i,n,us)===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,us.x),c.addScaledVector(a,us.y),c.addScaledVector(o,us.z),c)}static getInterpolatedAttribute(e,t,i,n,s,a){return Eh.setScalar(0),Ah.setScalar(0),Th.setScalar(0),Eh.fromBufferAttribute(e,t),Ah.fromBufferAttribute(e,i),Th.fromBufferAttribute(e,n),a.setScalar(0),a.addScaledVector(Eh,s.x),a.addScaledVector(Ah,s.y),a.addScaledVector(Th,s.z),a}static isFrontFacing(e,t,i,n){return wn.subVectors(i,t),hs.subVectors(e,t),wn.cross(hs).dot(n)<0}set(e,t,i){return this.a.copy(e),this.b.copy(t),this.c.copy(i),this}setFromPointsAndIndices(e,t,i,n){return this.a.copy(e[t]),this.b.copy(e[i]),this.c.copy(e[n]),this}setFromAttributeAndIndices(e,t,i,n){return this.a.fromBufferAttribute(e,t),this.b.fromBufferAttribute(e,i),this.c.fromBufferAttribute(e,n),this}clone(){return new this.constructor().copy(this)}copy(e){return this.a.copy(e.a),this.b.copy(e.b),this.c.copy(e.c),this}getArea(){return wn.subVectors(this.c,this.b),hs.subVectors(this.a,this.b),wn.cross(hs).length()*.5}getMidpoint(e){return e.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(e){return yn.getNormal(this.a,this.b,this.c,e)}getPlane(e){return e.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(e,t){return yn.getBarycoord(e,this.a,this.b,this.c,t)}getInterpolation(e,t,i,n,s){return yn.getInterpolation(e,this.a,this.b,this.c,t,i,n,s)}containsPoint(e){return yn.containsPoint(e,this.a,this.b,this.c)}isFrontFacing(e){return yn.isFrontFacing(this.a,this.b,this.c,e)}intersectsBox(e){return e.intersectsTriangle(this)}closestPointToPoint(e,t){const i=this.a,n=this.b,s=this.c;let a,o;Ja.subVectors(n,i),ja.subVectors(s,i),_h.subVectors(e,i);const c=Ja.dot(_h),l=ja.dot(_h);if(c<=0&&l<=0)return t.copy(i);Sh.subVectors(e,n);const h=Ja.dot(Sh),u=ja.dot(Sh);if(h>=0&&u<=h)return t.copy(n);const d=c*u-h*l;if(d<=0&&c>=0&&h<=0)return a=c/(c-h),t.copy(i).addScaledVector(Ja,a);wh.subVectors(e,s);const f=Ja.dot(wh),p=ja.dot(wh);if(p>=0&&f<=p)return t.copy(s);const v=f*l-c*p;if(v<=0&&l>=0&&p<=0)return o=l/(l-p),t.copy(i).addScaledVector(ja,o);const m=h*p-f*u;if(m<=0&&u-h>=0&&f-p>=0)return tp.subVectors(s,n),o=(u-h)/(u-h+(f-p)),t.copy(n).addScaledVector(tp,o);const g=1/(m+v+d);return a=v*g,o=d*g,t.copy(i).addScaledVector(Ja,a).addScaledVector(ja,o)}equals(e){return e.a.equals(this.a)&&e.b.equals(this.b)&&e.c.equals(this.c)}}class Vi{constructor(e=new R(1/0,1/0,1/0),t=new R(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=e,this.max=t}set(e,t){return this.min.copy(e),this.max.copy(t),this}setFromArray(e){this.makeEmpty();for(let t=0,i=e.length;t<i;t+=3)this.expandByPoint(En.fromArray(e,t));return this}setFromBufferAttribute(e){this.makeEmpty();for(let t=0,i=e.count;t<i;t++)this.expandByPoint(En.fromBufferAttribute(e,t));return this}setFromPoints(e){this.makeEmpty();for(let t=0,i=e.length;t<i;t++)this.expandByPoint(e[t]);return this}setFromCenterAndSize(e,t){const i=En.copy(t).multiplyScalar(.5);return this.min.copy(e).sub(i),this.max.copy(e).add(i),this}setFromObject(e,t=!1){return this.makeEmpty(),this.expandByObject(e,t)}clone(){return new this.constructor().copy(this)}copy(e){return this.min.copy(e.min),this.max.copy(e.max),this}makeEmpty(){return this.min.x=this.min.y=this.min.z=1/0,this.max.x=this.max.y=this.max.z=-1/0,this}isEmpty(){return this.max.x<this.min.x||this.max.y<this.min.y||this.max.z<this.min.z}getCenter(e){return this.isEmpty()?e.set(0,0,0):e.addVectors(this.min,this.max).multiplyScalar(.5)}getSize(e){return this.isEmpty()?e.set(0,0,0):e.subVectors(this.max,this.min)}expandByPoint(e){return this.min.min(e),this.max.max(e),this}expandByVector(e){return this.min.sub(e),this.max.add(e),this}expandByScalar(e){return this.min.addScalar(-e),this.max.addScalar(e),this}expandByObject(e,t=!1){e.updateWorldMatrix(!1,!1);const i=e.geometry;if(i!==void 0){const s=i.getAttribute("position");if(t===!0&&s!==void 0&&e.isInstancedMesh!==!0)for(let a=0,o=s.count;a<o;a++)e.isMesh===!0?e.getVertexPosition(a,En):En.fromBufferAttribute(s,a),En.applyMatrix4(e.matrixWorld),this.expandByPoint(En);else e.boundingBox!==void 0?(e.boundingBox===null&&e.computeBoundingBox(),fc.copy(e.boundingBox)):(i.boundingBox===null&&i.computeBoundingBox(),fc.copy(i.boundingBox)),fc.applyMatrix4(e.matrixWorld),this.union(fc)}const n=e.children;for(let s=0,a=n.length;s<a;s++)this.expandByObject(n[s],t);return this}containsPoint(e){return e.x>=this.min.x&&e.x<=this.max.x&&e.y>=this.min.y&&e.y<=this.max.y&&e.z>=this.min.z&&e.z<=this.max.z}containsBox(e){return this.min.x<=e.min.x&&e.max.x<=this.max.x&&this.min.y<=e.min.y&&e.max.y<=this.max.y&&this.min.z<=e.min.z&&e.max.z<=this.max.z}getParameter(e,t){return t.set((e.x-this.min.x)/(this.max.x-this.min.x),(e.y-this.min.y)/(this.max.y-this.min.y),(e.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(e){return e.max.x>=this.min.x&&e.min.x<=this.max.x&&e.max.y>=this.min.y&&e.min.y<=this.max.y&&e.max.z>=this.min.z&&e.min.z<=this.max.z}intersectsSphere(e){return this.clampPoint(e.center,En),En.distanceToSquared(e.center)<=e.radius*e.radius}intersectsPlane(e){let t,i;return e.normal.x>0?(t=e.normal.x*this.min.x,i=e.normal.x*this.max.x):(t=e.normal.x*this.max.x,i=e.normal.x*this.min.x),e.normal.y>0?(t+=e.normal.y*this.min.y,i+=e.normal.y*this.max.y):(t+=e.normal.y*this.max.y,i+=e.normal.y*this.min.y),e.normal.z>0?(t+=e.normal.z*this.min.z,i+=e.normal.z*this.max.z):(t+=e.normal.z*this.max.z,i+=e.normal.z*this.min.z),t<=-e.constant&&i>=-e.constant}intersectsTriangle(e){if(this.isEmpty())return!1;this.getCenter(Kr),pc.subVectors(this.max,Kr),Qa.subVectors(e.a,Kr),er.subVectors(e.b,Kr),tr.subVectors(e.c,Kr),zs.subVectors(er,Qa),Bs.subVectors(tr,er),ua.subVectors(Qa,tr);let t=[0,-zs.z,zs.y,0,-Bs.z,Bs.y,0,-ua.z,ua.y,zs.z,0,-zs.x,Bs.z,0,-Bs.x,ua.z,0,-ua.x,-zs.y,zs.x,0,-Bs.y,Bs.x,0,-ua.y,ua.x,0];return!Rh(t,Qa,er,tr,pc)||(t=[1,0,0,0,1,0,0,0,1],!Rh(t,Qa,er,tr,pc))?!1:(mc.crossVectors(zs,Bs),t=[mc.x,mc.y,mc.z],Rh(t,Qa,er,tr,pc))}clampPoint(e,t){return t.copy(e).clamp(this.min,this.max)}distanceToPoint(e){return this.clampPoint(e,En).distanceTo(e)}getBoundingSphere(e){return this.isEmpty()?e.makeEmpty():(this.getCenter(e.center),e.radius=this.getSize(En).length()*.5),e}intersect(e){return this.min.max(e.min),this.max.min(e.max),this.isEmpty()&&this.makeEmpty(),this}union(e){return this.min.min(e.min),this.max.max(e.max),this}applyMatrix4(e){return this.isEmpty()?this:(ds[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(e),ds[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(e),ds[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(e),ds[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(e),ds[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(e),ds[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(e),ds[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(e),ds[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(e),this.setFromPoints(ds),this)}translate(e){return this.min.add(e),this.max.add(e),this}equals(e){return e.min.equals(this.min)&&e.max.equals(this.max)}toJSON(){return{min:this.min.toArray(),max:this.max.toArray()}}fromJSON(e){return this.min.fromArray(e.min),this.max.fromArray(e.max),this}}const ds=[new R,new R,new R,new R,new R,new R,new R,new R],En=new R,fc=new Vi,Qa=new R,er=new R,tr=new R,zs=new R,Bs=new R,ua=new R,Kr=new R,pc=new R,mc=new R,da=new R;function Rh(r,e,t,i,n){for(let s=0,a=r.length-3;s<=a;s+=3){da.fromArray(r,s);const o=n.x*Math.abs(da.x)+n.y*Math.abs(da.y)+n.z*Math.abs(da.z),c=e.dot(da),l=t.dot(da),h=i.dot(da);if(Math.max(-Math.max(c,l,h),Math.min(c,l,h))>o)return!1}return!0}const ys=JM();function JM(){const r=new ArrayBuffer(4),e=new Float32Array(r),t=new Uint32Array(r),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),a=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)a[c]=c<<23;a[31]=1199570944,a[32]=2147483648;for(let c=33;c<63;++c)a[c]=2147483648+(c-32<<23);a[63]=3347054592;for(let c=1;c<64;++c)c!==32&&(o[c]=1024);return{floatView:e,uint32View:t,baseTable:i,shiftTable:n,mantissaTable:s,exponentTable:a,offsetTable:o}}function jM(r){Math.abs(r)>65504&&Re("DataUtils.toHalfFloat(): Value out of range."),r=et(r,-65504,65504),ys.floatView[0]=r;const e=ys.uint32View[0],t=e>>23&511;return ys.baseTable[t]+((e&8388607)>>ys.shiftTable[t])}function QM(r){const e=r>>10;return ys.uint32View[0]=ys.mantissaTable[ys.offsetTable[e]+(r&1023)]+ys.exponentTable[e],ys.floatView[0]}class kn{static toHalfFloat(e){return jM(e)}static fromHalfFloat(e){return QM(e)}}const ci=new R,gc=new xe;let ex=0;class tt extends oa{constructor(e,t,i=!1){if(super(),Array.isArray(e))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,Object.defineProperty(this,"id",{value:ex++}),this.name="",this.array=e,this.itemSize=t,this.count=e!==void 0?e.length/t:0,this.normalized=i,this.usage=yd,this.updateRanges=[],this.gpuType=Oi,this.version=0}onUploadCallback(){}set needsUpdate(e){e===!0&&this.version++}setUsage(e){return this.usage=e,this}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}copy(e){return this.name=e.name,this.array=new e.array.constructor(e.array),this.itemSize=e.itemSize,this.count=e.count,this.normalized=e.normalized,this.usage=e.usage,this.gpuType=e.gpuType,this}copyAt(e,t,i){e*=this.itemSize,i*=t.itemSize;for(let n=0,s=this.itemSize;n<s;n++)this.array[e+n]=t.array[i+n];return this}copyArray(e){return this.array.set(e),this}applyMatrix3(e){if(this.itemSize===2)for(let t=0,i=this.count;t<i;t++)gc.fromBufferAttribute(this,t),gc.applyMatrix3(e),this.setXY(t,gc.x,gc.y);else if(this.itemSize===3)for(let t=0,i=this.count;t<i;t++)ci.fromBufferAttribute(this,t),ci.applyMatrix3(e),this.setXYZ(t,ci.x,ci.y,ci.z);return this}applyMatrix4(e){for(let t=0,i=this.count;t<i;t++)ci.fromBufferAttribute(this,t),ci.applyMatrix4(e),this.setXYZ(t,ci.x,ci.y,ci.z);return this}applyNormalMatrix(e){for(let t=0,i=this.count;t<i;t++)ci.fromBufferAttribute(this,t),ci.applyNormalMatrix(e),this.setXYZ(t,ci.x,ci.y,ci.z);return this}transformDirection(e){for(let t=0,i=this.count;t<i;t++)ci.fromBufferAttribute(this,t),ci.transformDirection(e),this.setXYZ(t,ci.x,ci.y,ci.z);return this}set(e,t=0){return this.array.set(e,t),this}getComponent(e,t){let i=this.array[e*this.itemSize+t];return this.normalized&&(i=Nn(i,this.array)),i}setComponent(e,t,i){return this.normalized&&(i=bt(i,this.array)),this.array[e*this.itemSize+t]=i,this}getX(e){let t=this.array[e*this.itemSize];return this.normalized&&(t=Nn(t,this.array)),t}setX(e,t){return this.normalized&&(t=bt(t,this.array)),this.array[e*this.itemSize]=t,this}getY(e){let t=this.array[e*this.itemSize+1];return this.normalized&&(t=Nn(t,this.array)),t}setY(e,t){return this.normalized&&(t=bt(t,this.array)),this.array[e*this.itemSize+1]=t,this}getZ(e){let t=this.array[e*this.itemSize+2];return this.normalized&&(t=Nn(t,this.array)),t}setZ(e,t){return this.normalized&&(t=bt(t,this.array)),this.array[e*this.itemSize+2]=t,this}getW(e){let t=this.array[e*this.itemSize+3];return this.normalized&&(t=Nn(t,this.array)),t}setW(e,t){return this.normalized&&(t=bt(t,this.array)),this.array[e*this.itemSize+3]=t,this}setXY(e,t,i){return e*=this.itemSize,this.normalized&&(t=bt(t,this.array),i=bt(i,this.array)),this.array[e+0]=t,this.array[e+1]=i,this}setXYZ(e,t,i,n){return e*=this.itemSize,this.normalized&&(t=bt(t,this.array),i=bt(i,this.array),n=bt(n,this.array)),this.array[e+0]=t,this.array[e+1]=i,this.array[e+2]=n,this}setXYZW(e,t,i,n,s){return e*=this.itemSize,this.normalized&&(t=bt(t,this.array),i=bt(i,this.array),n=bt(n,this.array),s=bt(s,this.array)),this.array[e+0]=t,this.array[e+1]=i,this.array[e+2]=n,this.array[e+3]=s,this}onUpload(e){return this.onUploadCallback=e,this}clone(){return new this.constructor(this.array,this.itemSize).copy(this)}toJSON(){const e={itemSize:this.itemSize,type:this.array.constructor.name,array:Array.from(this.array),normalized:this.normalized};return this.name!==""&&(e.name=this.name),this.usage!==yd&&(e.usage=this.usage),e}dispose(){this.dispatchEvent({type:"dispose"})}}class n1 extends tt{constructor(e,t,i){super(new Uint16Array(e),t,i)}}class E0 extends tt{constructor(e,t,i){super(new Uint32Array(e),t,i)}}class ut extends tt{constructor(e,t,i){super(new Float32Array(e),t,i)}}const tx=new Vi,Zr=new R,Dh=new R;class Cs{constructor(e=new R,t=-1){this.isSphere=!0,this.center=e,this.radius=t}set(e,t){return this.center.copy(e),this.radius=t,this}setFromPoints(e,t){const i=this.center;t!==void 0?i.copy(t):tx.setFromPoints(e).getCenter(i);let n=0;for(let s=0,a=e.length;s<a;s++)n=Math.max(n,i.distanceToSquared(e[s]));return this.radius=Math.sqrt(n),this}copy(e){return this.center.copy(e.center),this.radius=e.radius,this}isEmpty(){return this.radius<0}makeEmpty(){return this.center.set(0,0,0),this.radius=-1,this}containsPoint(e){return e.distanceToSquared(this.center)<=this.radius*this.radius}distanceToPoint(e){return e.distanceTo(this.center)-this.radius}intersectsSphere(e){const t=this.radius+e.radius;return e.center.distanceToSquared(this.center)<=t*t}intersectsBox(e){return e.intersectsSphere(this)}intersectsPlane(e){return Math.abs(e.distanceToPoint(this.center))<=this.radius}clampPoint(e,t){const i=this.center.distanceToSquared(e);return t.copy(e),i>this.radius*this.radius&&(t.sub(this.center).normalize(),t.multiplyScalar(this.radius).add(this.center)),t}getBoundingBox(e){return this.isEmpty()?(e.makeEmpty(),e):(e.set(this.center,this.center),e.expandByScalar(this.radius),e)}applyMatrix4(e){return this.center.applyMatrix4(e),this.radius=this.radius*e.getMaxScaleOnAxis(),this}translate(e){return this.center.add(e),this}expandByPoint(e){if(this.isEmpty())return this.center.copy(e),this.radius=0,this;Zr.subVectors(e,this.center);const t=Zr.lengthSq();if(t>this.radius*this.radius){const i=Math.sqrt(t),n=(i-this.radius)*.5;this.center.addScaledVector(Zr,n/i),this.radius+=n}return this}union(e){return e.isEmpty()?this:this.isEmpty()?(this.copy(e),this):(this.center.equals(e.center)===!0?this.radius=Math.max(this.radius,e.radius):(Dh.subVectors(e.center,this.center).setLength(e.radius),this.expandByPoint(Zr.copy(e.center).add(Dh)),this.expandByPoint(Zr.copy(e.center).sub(Dh))),this)}equals(e){return e.center.equals(this.center)&&e.radius===this.radius}clone(){return new this.constructor().copy(this)}toJSON(){return{radius:this.radius,center:this.center.toArray()}}fromJSON(e){return this.radius=e.radius,this.center.fromArray(e.center),this}}let ix=0;const mn=new Ze,Ih=new Ut,ir=new R,sn=new Vi,Jr=new Vi,vi=new R;class ot extends oa{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:ix++}),this.uuid=Un(),this.name="",this.type="BufferGeometry",this.index=null,this.indirect=null,this.indirectOffset=0,this.attributes={},this.morphAttributes={},this.morphTargetsRelative=!1,this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.drawRange={start:0,count:1/0},this.userData={},this._transformed=!1}getIndex(){return this.index}setIndex(e){return Array.isArray(e)?this.index=new(MM(e)?E0:n1)(e,1):this.index=e,this}setIndirect(e,t=0){return this.indirect=e,this.indirectOffset=t,this}getIndirect(){return this.indirect}getAttribute(e){return this.attributes[e]}setAttribute(e,t){return this.attributes[e]=t,this}deleteAttribute(e){return delete this.attributes[e],this}hasAttribute(e){return this.attributes[e]!==void 0}addGroup(e,t,i=0){this.groups.push({start:e,count:t,materialIndex:i})}clearGroups(){this.groups=[]}setDrawRange(e,t){this.drawRange.start=e,this.drawRange.count=t}applyMatrix4(e){const t=this.attributes.position;t!==void 0&&(t.applyMatrix4(e),t.needsUpdate=!0);const i=this.attributes.normal;if(i!==void 0){const s=new Ye().getNormalMatrix(e);i.applyNormalMatrix(s),i.needsUpdate=!0}const n=this.attributes.tangent;return n!==void 0&&(n.transformDirection(e),n.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this._transformed=!0,this}applyQuaternion(e){return mn.makeRotationFromQuaternion(e),this.applyMatrix4(mn),this}rotateX(e){return mn.makeRotationX(e),this.applyMatrix4(mn),this}rotateY(e){return mn.makeRotationY(e),this.applyMatrix4(mn),this}rotateZ(e){return mn.makeRotationZ(e),this.applyMatrix4(mn),this}translate(e,t,i){return mn.makeTranslation(e,t,i),this.applyMatrix4(mn),this}scale(e,t,i){return mn.makeScale(e,t,i),this.applyMatrix4(mn),this}lookAt(e){return Ih.lookAt(e),Ih.updateMatrix(),this.applyMatrix4(Ih.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(ir).negate(),this.translate(ir.x,ir.y,ir.z),this}setFromPoints(e){const t=this.getAttribute("position");if(t===void 0){const i=[];for(let n=0,s=e.length;n<s;n++){const a=e[n];i.push(a.x,a.y,a.z||0)}this.setAttribute("position",new ut(i,3))}else{const i=Math.min(e.length,t.count);for(let n=0;n<i;n++){const s=e[n];t.setXYZ(n,s.x,s.y,s.z||0)}e.length>t.count&&Re("BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry."),t.needsUpdate=!0}return this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new Vi);const e=this.attributes.position,t=this.morphAttributes.position;if(e&&e.isGLBufferAttribute){Ge("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(e!==void 0){if(this.boundingBox.setFromBufferAttribute(e),t)for(let i=0,n=t.length;i<n;i++){const s=t[i];sn.setFromBufferAttribute(s),this.morphTargetsRelative?(vi.addVectors(this.boundingBox.min,sn.min),this.boundingBox.expandByPoint(vi),vi.addVectors(this.boundingBox.max,sn.max),this.boundingBox.expandByPoint(vi)):(this.boundingBox.expandByPoint(sn.min),this.boundingBox.expandByPoint(sn.max))}}else this.boundingBox.makeEmpty();(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z))&&Ge('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 Cs);const e=this.attributes.position,t=this.morphAttributes.position;if(e&&e.isGLBufferAttribute){Ge("BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.",this),this.boundingSphere.set(new R,1/0);return}if(e){const i=this.boundingSphere.center;if(sn.setFromBufferAttribute(e),t)for(let s=0,a=t.length;s<a;s++){const o=t[s];Jr.setFromBufferAttribute(o),this.morphTargetsRelative?(vi.addVectors(sn.min,Jr.min),sn.expandByPoint(vi),vi.addVectors(sn.max,Jr.max),sn.expandByPoint(vi)):(sn.expandByPoint(Jr.min),sn.expandByPoint(Jr.max))}sn.getCenter(i);let n=0;for(let s=0,a=e.count;s<a;s++)vi.fromBufferAttribute(e,s),n=Math.max(n,i.distanceToSquared(vi));if(t)for(let s=0,a=t.length;s<a;s++){const o=t[s],c=this.morphTargetsRelative;for(let l=0,h=o.count;l<h;l++)vi.fromBufferAttribute(o,l),c&&(ir.fromBufferAttribute(e,l),vi.add(ir)),n=Math.max(n,i.distanceToSquared(vi))}this.boundingSphere.radius=Math.sqrt(n),isNaN(this.boundingSphere.radius)&&Ge('BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',this)}}computeTangents(){const e=this.index,t=this.attributes;if(e===null||t.position===void 0||t.normal===void 0||t.uv===void 0){Ge("BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)");return}const i=t.position,n=t.normal,s=t.uv;let a=this.getAttribute("tangent");(a===void 0||a.count!==i.count)&&(a=new tt(new Float32Array(4*i.count),4),this.setAttribute("tangent",a));const o=[],c=[];for(let x=0;x<i.count;x++)o[x]=new R,c[x]=new R;const l=new R,h=new R,u=new R,d=new xe,f=new xe,p=new xe,v=new R,m=new R;function g(x,A,C){l.fromBufferAttribute(i,x),h.fromBufferAttribute(i,A),u.fromBufferAttribute(i,C),d.fromBufferAttribute(s,x),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[x].add(v),o[A].add(v),o[C].add(v),c[x].add(m),c[A].add(m),c[C].add(m))}let _=this.groups;_.length===0&&(_=[{start:0,count:e.count}]);for(let x=0,A=_.length;x<A;++x){const C=_[x],I=C.start,P=C.count;for(let V=I,X=I+P;V<X;V+=3)g(e.getX(V+0),e.getX(V+1),e.getX(V+2))}const b=new R,M=new R,S=new R,w=new R;function T(x){S.fromBufferAttribute(n,x),w.copy(S);const A=o[x];b.copy(A),b.sub(S.multiplyScalar(S.dot(A))).normalize(),M.crossVectors(w,A);const I=M.dot(c[x])<0?-1:1;a.setXYZW(x,b.x,b.y,b.z,I)}for(let x=0,A=_.length;x<A;++x){const C=_[x],I=C.start,P=C.count;for(let V=I,X=I+P;V<X;V+=3)T(e.getX(V+0)),T(e.getX(V+1)),T(e.getX(V+2))}this._transformed=!0}computeVertexNormals(){const e=this.index,t=this.getAttribute("position");if(t!==void 0){let i=this.getAttribute("normal");if(i===void 0||i.count!==t.count)i=new tt(new Float32Array(t.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,a=new R,o=new R,c=new R,l=new R,h=new R,u=new R;if(e)for(let d=0,f=e.count;d<f;d+=3){const p=e.getX(d+0),v=e.getX(d+1),m=e.getX(d+2);n.fromBufferAttribute(t,p),s.fromBufferAttribute(t,v),a.fromBufferAttribute(t,m),h.subVectors(a,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=t.count;d<f;d+=3)n.fromBufferAttribute(t,d+0),s.fromBufferAttribute(t,d+1),a.fromBufferAttribute(t,d+2),h.subVectors(a,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 e=this.attributes.normal;for(let t=0,i=e.count;t<i;t++)vi.fromBufferAttribute(e,t),vi.normalize(),e.setXYZ(t,vi.x,vi.y,vi.z)}toNonIndexed(){function e(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 tt(d,h,u)}if(this.index===null)return Re("BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."),this;const t=new ot,i=this.index.array,n=this.attributes;for(const o in n){const c=n[o],l=e(c,i);t.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=e(d,i);c.push(f)}t.morphAttributes[o]=c}t.morphTargetsRelative=this.morphTargetsRelative;const a=this.groups;for(let o=0,c=a.length;o<c;o++){const l=a[o];t.addGroup(l.start,l.count,l.materialIndex)}return t}toJSON(){const e={metadata:{version:4.7,type:"BufferGeometry",generator:"BufferGeometry.toJSON"}};if(e.uuid=this.uuid,e.type=this.parameters!==void 0&&this._transformed===!0?"BufferGeometry":this.type,this.name!==""&&(e.name=this.name),Object.keys(this.userData).length>0&&(e.userData=this.userData),this.parameters!==void 0&&this._transformed!==!0){const c=this.parameters;for(const l in c)c[l]!==void 0&&(e[l]=c[l]);return e}e.data={attributes:{}};const t=this.index;t!==null&&(e.data.index={type:t.array.constructor.name,array:Array.prototype.slice.call(t.array)});const i=this.attributes;for(const c in i){const l=i[c];e.data.attributes[c]=l.toJSON(e.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(e.data))}h.length>0&&(n[c]=h,s=!0)}s&&(e.data.morphAttributes=n,e.data.morphTargetsRelative=this.morphTargetsRelative);const a=this.groups;a.length>0&&(e.data.groups=JSON.parse(JSON.stringify(a)));const o=this.boundingSphere;return o!==null&&(e.data.boundingSphere=o.toJSON()),e}clone(){return new this.constructor().copy(this)}copy(e){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const t={};this.name=e.name;const i=e.index;i!==null&&this.setIndex(i.clone());const n=e.attributes;for(const l in n){const h=n[l];this.setAttribute(l,h.clone(t))}const s=e.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(t));this.morphAttributes[l]=h}this.morphTargetsRelative=e.morphTargetsRelative;const a=e.groups;for(let l=0,h=a.length;l<h;l++){const u=a[l];this.addGroup(u.start,u.count,u.materialIndex)}const o=e.boundingBox;o!==null&&(this.boundingBox=o.clone());const c=e.boundingSphere;return c!==null&&(this.boundingSphere=c.clone()),this.drawRange.start=e.drawRange.start,this.drawRange.count=e.drawRange.count,this.userData=e.userData,this._transformed=e._transformed,this}dispose(){this.dispatchEvent({type:"dispose"})}}class nx{constructor(e,t){this.isInterleavedBuffer=!0,this.array=e,this.stride=t,this.count=e!==void 0?e.length/t:0,this.usage=yd,this.updateRanges=[],this.version=0,this.uuid=Un()}onUploadCallback(){}set needsUpdate(e){e===!0&&this.version++}setUsage(e){return this.usage=e,this}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}copy(e){return this.array=new e.array.constructor(e.array),this.count=e.count,this.stride=e.stride,this.usage=e.usage,this}copyAt(e,t,i){e*=this.stride,i*=t.stride;for(let n=0,s=this.stride;n<s;n++)this.array[e+n]=t.array[i+n];return this}set(e,t=0){return this.array.set(e,t),this}clone(e){e.arrayBuffers===void 0&&(e.arrayBuffers={}),this.array.buffer._uuid===void 0&&(this.array.buffer._uuid=Un()),e.arrayBuffers[this.array.buffer._uuid]===void 0&&(e.arrayBuffers[this.array.buffer._uuid]=this.array.slice(0).buffer);const t=new this.array.constructor(e.arrayBuffers[this.array.buffer._uuid]),i=new this.constructor(t,this.stride);return i.setUsage(this.usage),i}onUpload(e){return this.onUploadCallback=e,this}toJSON(e){return e.arrayBuffers===void 0&&(e.arrayBuffers={}),this.array.buffer._uuid===void 0&&(this.array.buffer._uuid=Un()),e.arrayBuffers[this.array.buffer._uuid]===void 0&&(e.arrayBuffers[this.array.buffer._uuid]=Array.from(new Uint32Array(this.array.buffer))),{uuid:this.uuid,buffer:this.array.buffer._uuid,type:this.array.constructor.name,stride:this.stride}}}const Fi=new R;class Dl{constructor(e,t,i,n=!1){this.isInterleavedBufferAttribute=!0,this.name="",this.data=e,this.itemSize=t,this.offset=i,this.normalized=n}get count(){return this.data.count}get array(){return this.data.array}set needsUpdate(e){this.data.needsUpdate=e}applyMatrix4(e){for(let t=0,i=this.data.count;t<i;t++)Fi.fromBufferAttribute(this,t),Fi.applyMatrix4(e),this.setXYZ(t,Fi.x,Fi.y,Fi.z);return this}applyNormalMatrix(e){for(let t=0,i=this.count;t<i;t++)Fi.fromBufferAttribute(this,t),Fi.applyNormalMatrix(e),this.setXYZ(t,Fi.x,Fi.y,Fi.z);return this}transformDirection(e){for(let t=0,i=this.count;t<i;t++)Fi.fromBufferAttribute(this,t),Fi.transformDirection(e),this.setXYZ(t,Fi.x,Fi.y,Fi.z);return this}getComponent(e,t){let i=this.array[e*this.data.stride+this.offset+t];return this.normalized&&(i=Nn(i,this.array)),i}setComponent(e,t,i){return this.normalized&&(i=bt(i,this.array)),this.data.array[e*this.data.stride+this.offset+t]=i,this}setX(e,t){return this.normalized&&(t=bt(t,this.array)),this.data.array[e*this.data.stride+this.offset]=t,this}setY(e,t){return this.normalized&&(t=bt(t,this.array)),this.data.array[e*this.data.stride+this.offset+1]=t,this}setZ(e,t){return this.normalized&&(t=bt(t,this.array)),this.data.array[e*this.data.stride+this.offset+2]=t,this}setW(e,t){return this.normalized&&(t=bt(t,this.array)),this.data.array[e*this.data.stride+this.offset+3]=t,this}getX(e){let t=this.data.array[e*this.data.stride+this.offset];return this.normalized&&(t=Nn(t,this.array)),t}getY(e){let t=this.data.array[e*this.data.stride+this.offset+1];return this.normalized&&(t=Nn(t,this.array)),t}getZ(e){let t=this.data.array[e*this.data.stride+this.offset+2];return this.normalized&&(t=Nn(t,this.array)),t}getW(e){let t=this.data.array[e*this.data.stride+this.offset+3];return this.normalized&&(t=Nn(t,this.array)),t}setXY(e,t,i){return e=e*this.data.stride+this.offset,this.normalized&&(t=bt(t,this.array),i=bt(i,this.array)),this.data.array[e+0]=t,this.data.array[e+1]=i,this}setXYZ(e,t,i,n){return e=e*this.data.stride+this.offset,this.normalized&&(t=bt(t,this.array),i=bt(i,this.array),n=bt(n,this.array)),this.data.array[e+0]=t,this.data.array[e+1]=i,this.data.array[e+2]=n,this}setXYZW(e,t,i,n,s){return e=e*this.data.stride+this.offset,this.normalized&&(t=bt(t,this.array),i=bt(i,this.array),n=bt(n,this.array),s=bt(s,this.array)),this.data.array[e+0]=t,this.data.array[e+1]=i,this.data.array[e+2]=n,this.data.array[e+3]=s,this}clone(e){if(e===void 0){Rl("InterleavedBufferAttribute.clone(): Cloning an interleaved buffer attribute will de-interleave buffer data.");const t=[];for(let i=0;i<this.count;i++){const n=i*this.data.stride+this.offset;for(let s=0;s<this.itemSize;s++)t.push(this.data.array[n+s])}return new tt(new this.array.constructor(t),this.itemSize,this.normalized)}else return e.interleavedBuffers===void 0&&(e.interleavedBuffers={}),e.interleavedBuffers[this.data.uuid]===void 0&&(e.interleavedBuffers[this.data.uuid]=this.data.clone(e)),new Dl(e.interleavedBuffers[this.data.uuid],this.itemSize,this.offset,this.normalized)}toJSON(e){if(e===void 0){Rl("InterleavedBufferAttribute.toJSON(): Serializing an interleaved buffer attribute will de-interleave buffer data.");const t=[];for(let i=0;i<this.count;i++){const n=i*this.data.stride+this.offset;for(let s=0;s<this.itemSize;s++)t.push(this.data.array[n+s])}return{itemSize:this.itemSize,type:this.array.constructor.name,array:t,normalized:this.normalized}}else return e.interleavedBuffers===void 0&&(e.interleavedBuffers={}),e.interleavedBuffers[this.data.uuid]===void 0&&(e.interleavedBuffers[this.data.uuid]=this.data.toJSON(e)),{isInterleavedBufferAttribute:!0,itemSize:this.itemSize,data:this.data.uuid,offset:this.offset,normalized:this.normalized}}}let sx=0;class Ps extends oa{constructor(){super(),this.isMaterial=!0,Object.defineProperty(this,"id",{value:sx++}),this.uuid=Un(),this.name="",this.type="Material",this.blending=ia,this.side=sa,this.vertexColors=!1,this.opacity=1,this.transparent=!1,this.alphaHash=!1,this.blendSrc=Ou,this.blendDst=Ho,this.blendEquation=ba,this.blendSrcAlpha=null,this.blendDstAlpha=null,this.blendEquationAlpha=null,this.blendColor=new se(0,0,0),this.blendAlpha=0,this.depthFunc=Ur,this.depthTest=!0,this.depthWrite=!0,this.stencilWriteMask=255,this.stencilFunc=Gf,this.stencilRef=0,this.stencilFuncMask=255,this.stencilFail=Ya,this.stencilZFail=Ya,this.stencilZPass=Ya,this.stencilWrite=!1,this.clippingPlanes=null,this.clipIntersection=!1,this.clipShadows=!1,this.shadowSide=null,this.colorWrite=!0,this.precision=null,this.polygonOffset=!1,this.polygonOffsetFactor=0,this.polygonOffsetUnits=0,this.dithering=!1,this.alphaToCoverage=!1,this.premultipliedAlpha=!1,this.forceSinglePass=!1,this.allowOverride=!0,this.visible=!0,this.toneMapped=!0,this.userData={},this.version=0,this._alphaTest=0}get alphaTest(){return this._alphaTest}set alphaTest(e){this._alphaTest>0!=e>0&&this.version++,this._alphaTest=e}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(e){if(e!==void 0)for(const t in e){const i=e[t];if(i===void 0){Re(`Material: parameter '${t}' has value of undefined.`);continue}const n=this[t];if(n===void 0){Re(`Material: '${t}' is not a property of THREE.${this.type}.`);continue}n&&n.isColor?n.set(i):n&&n.isVector2&&i&&i.isVector2||n&&n.isEuler&&i&&i.isEuler||n&&n.isVector3&&i&&i.isVector3?n.copy(i):this[t]=i}}toJSON(e){const t=e===void 0||typeof e=="string";t&&(e={textures:{},images:{}});const i={metadata:{version:4.7,type:"Material",generator:"Material.toJSON"}};i.uuid=this.uuid,i.type=this.type,this.name!==""&&(i.name=this.name),this.color&&this.color.isColor&&(i.color=this.color.getHex()),this.roughness!==void 0&&(i.roughness=this.roughness),this.metalness!==void 0&&(i.metalness=this.metalness),this.sheen!==void 0&&(i.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(i.sheenColor=this.sheenColor.getHex()),this.sheenRoughness!==void 0&&(i.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(i.emissive=this.emissive.getHex()),this.emissiveIntensity!==void 0&&this.emissiveIntensity!==1&&(i.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(i.specular=this.specular.getHex()),this.specularIntensity!==void 0&&(i.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(i.specularColor=this.specularColor.getHex()),this.shininess!==void 0&&(i.shininess=this.shininess),this.clearcoat!==void 0&&(i.clearcoat=this.clearcoat),this.clearcoatRoughness!==void 0&&(i.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(i.clearcoatMap=this.clearcoatMap.toJSON(e).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(i.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(e).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(i.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(e).uuid,i.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),this.sheenColorMap&&this.sheenColorMap.isTexture&&(i.sheenColorMap=this.sheenColorMap.toJSON(e).uuid),this.sheenRoughnessMap&&this.sheenRoughnessMap.isTexture&&(i.sheenRoughnessMap=this.sheenRoughnessMap.toJSON(e).uuid),this.dispersion!==void 0&&(i.dispersion=this.dispersion),this.iridescence!==void 0&&(i.iridescence=this.iridescence),this.iridescenceIOR!==void 0&&(i.iridescenceIOR=this.iridescenceIOR),this.iridescenceThicknessRange!==void 0&&(i.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(i.iridescenceMap=this.iridescenceMap.toJSON(e).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(i.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(e).uuid),this.anisotropy!==void 0&&(i.anisotropy=this.anisotropy),this.anisotropyRotation!==void 0&&(i.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(i.anisotropyMap=this.anisotropyMap.toJSON(e).uuid),this.map&&this.map.isTexture&&(i.map=this.map.toJSON(e).uuid),this.matcap&&this.matcap.isTexture&&(i.matcap=this.matcap.toJSON(e).uuid),this.alphaMap&&this.alphaMap.isTexture&&(i.alphaMap=this.alphaMap.toJSON(e).uuid),this.lightMap&&this.lightMap.isTexture&&(i.lightMap=this.lightMap.toJSON(e).uuid,i.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(i.aoMap=this.aoMap.toJSON(e).uuid,i.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(i.bumpMap=this.bumpMap.toJSON(e).uuid,i.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(i.normalMap=this.normalMap.toJSON(e).uuid,i.normalMapType=this.normalMapType,i.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(i.displacementMap=this.displacementMap.toJSON(e).uuid,i.displacementScale=this.displacementScale,i.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(i.roughnessMap=this.roughnessMap.toJSON(e).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(i.metalnessMap=this.metalnessMap.toJSON(e).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(i.emissiveMap=this.emissiveMap.toJSON(e).uuid),this.specularMap&&this.specularMap.isTexture&&(i.specularMap=this.specularMap.toJSON(e).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(i.specularIntensityMap=this.specularIntensityMap.toJSON(e).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(i.specularColorMap=this.specularColorMap.toJSON(e).uuid),this.envMap&&this.envMap.isTexture&&(i.envMap=this.envMap.toJSON(e).uuid,this.combine!==void 0&&(i.combine=this.combine)),this.envMapRotation!==void 0&&(i.envMapRotation=this.envMapRotation.toArray()),this.envMapIntensity!==void 0&&(i.envMapIntensity=this.envMapIntensity),this.reflectivity!==void 0&&(i.reflectivity=this.reflectivity),this.refractionRatio!==void 0&&(i.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(i.gradientMap=this.gradientMap.toJSON(e).uuid),this.transmission!==void 0&&(i.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(i.transmissionMap=this.transmissionMap.toJSON(e).uuid),this.thickness!==void 0&&(i.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(i.thicknessMap=this.thicknessMap.toJSON(e).uuid),this.attenuationDistance!==void 0&&this.attenuationDistance!==1/0&&(i.attenuationDistance=this.attenuationDistance),this.attenuationColor!==void 0&&(i.attenuationColor=this.attenuationColor.getHex()),this.size!==void 0&&(i.size=this.size),this.shadowSide!==null&&(i.shadowSide=this.shadowSide),this.sizeAttenuation!==void 0&&(i.sizeAttenuation=this.sizeAttenuation),this.blending!==ia&&(i.blending=this.blending),this.side!==sa&&(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!==Ou&&(i.blendSrc=this.blendSrc),this.blendDst!==Ho&&(i.blendDst=this.blendDst),this.blendEquation!==ba&&(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!==Ur&&(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!==Gf&&(i.stencilFunc=this.stencilFunc),this.stencilRef!==0&&(i.stencilRef=this.stencilRef),this.stencilFuncMask!==255&&(i.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==Ya&&(i.stencilFail=this.stencilFail),this.stencilZFail!==Ya&&(i.stencilZFail=this.stencilZFail),this.stencilZPass!==Ya&&(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 a=[];for(const o in s){const c=s[o];delete c.metadata,a.push(c)}return a}if(t){const s=n(e.textures),a=n(e.images);s.length>0&&(i.textures=s),a.length>0&&(i.images=a)}return i}fromJSON(e,t){if(e.uuid!==void 0&&(this.uuid=e.uuid),e.name!==void 0&&(this.name=e.name),e.color!==void 0&&this.color!==void 0&&this.color.setHex(e.color),e.roughness!==void 0&&(this.roughness=e.roughness),e.metalness!==void 0&&(this.metalness=e.metalness),e.sheen!==void 0&&(this.sheen=e.sheen),e.sheenColor!==void 0&&(this.sheenColor=new se().setHex(e.sheenColor)),e.sheenRoughness!==void 0&&(this.sheenRoughness=e.sheenRoughness),e.emissive!==void 0&&this.emissive!==void 0&&this.emissive.setHex(e.emissive),e.specular!==void 0&&this.specular!==void 0&&this.specular.setHex(e.specular),e.specularIntensity!==void 0&&(this.specularIntensity=e.specularIntensity),e.specularColor!==void 0&&this.specularColor!==void 0&&this.specularColor.setHex(e.specularColor),e.shininess!==void 0&&(this.shininess=e.shininess),e.clearcoat!==void 0&&(this.clearcoat=e.clearcoat),e.clearcoatRoughness!==void 0&&(this.clearcoatRoughness=e.clearcoatRoughness),e.dispersion!==void 0&&(this.dispersion=e.dispersion),e.iridescence!==void 0&&(this.iridescence=e.iridescence),e.iridescenceIOR!==void 0&&(this.iridescenceIOR=e.iridescenceIOR),e.iridescenceThicknessRange!==void 0&&(this.iridescenceThicknessRange=e.iridescenceThicknessRange),e.transmission!==void 0&&(this.transmission=e.transmission),e.thickness!==void 0&&(this.thickness=e.thickness),e.attenuationDistance!==void 0&&(this.attenuationDistance=e.attenuationDistance),e.attenuationColor!==void 0&&this.attenuationColor!==void 0&&this.attenuationColor.setHex(e.attenuationColor),e.anisotropy!==void 0&&(this.anisotropy=e.anisotropy),e.anisotropyRotation!==void 0&&(this.anisotropyRotation=e.anisotropyRotation),e.fog!==void 0&&(this.fog=e.fog),e.flatShading!==void 0&&(this.flatShading=e.flatShading),e.blending!==void 0&&(this.blending=e.blending),e.combine!==void 0&&(this.combine=e.combine),e.side!==void 0&&(this.side=e.side),e.shadowSide!==void 0&&(this.shadowSide=e.shadowSide),e.opacity!==void 0&&(this.opacity=e.opacity),e.transparent!==void 0&&(this.transparent=e.transparent),e.alphaTest!==void 0&&(this.alphaTest=e.alphaTest),e.alphaHash!==void 0&&(this.alphaHash=e.alphaHash),e.depthFunc!==void 0&&(this.depthFunc=e.depthFunc),e.depthTest!==void 0&&(this.depthTest=e.depthTest),e.depthWrite!==void 0&&(this.depthWrite=e.depthWrite),e.colorWrite!==void 0&&(this.colorWrite=e.colorWrite),e.blendSrc!==void 0&&(this.blendSrc=e.blendSrc),e.blendDst!==void 0&&(this.blendDst=e.blendDst),e.blendEquation!==void 0&&(this.blendEquation=e.blendEquation),e.blendSrcAlpha!==void 0&&(this.blendSrcAlpha=e.blendSrcAlpha),e.blendDstAlpha!==void 0&&(this.blendDstAlpha=e.blendDstAlpha),e.blendEquationAlpha!==void 0&&(this.blendEquationAlpha=e.blendEquationAlpha),e.blendColor!==void 0&&this.blendColor!==void 0&&this.blendColor.setHex(e.blendColor),e.blendAlpha!==void 0&&(this.blendAlpha=e.blendAlpha),e.stencilWriteMask!==void 0&&(this.stencilWriteMask=e.stencilWriteMask),e.stencilFunc!==void 0&&(this.stencilFunc=e.stencilFunc),e.stencilRef!==void 0&&(this.stencilRef=e.stencilRef),e.stencilFuncMask!==void 0&&(this.stencilFuncMask=e.stencilFuncMask),e.stencilFail!==void 0&&(this.stencilFail=e.stencilFail),e.stencilZFail!==void 0&&(this.stencilZFail=e.stencilZFail),e.stencilZPass!==void 0&&(this.stencilZPass=e.stencilZPass),e.stencilWrite!==void 0&&(this.stencilWrite=e.stencilWrite),e.wireframe!==void 0&&(this.wireframe=e.wireframe),e.wireframeLinewidth!==void 0&&(this.wireframeLinewidth=e.wireframeLinewidth),e.wireframeLinecap!==void 0&&(this.wireframeLinecap=e.wireframeLinecap),e.wireframeLinejoin!==void 0&&(this.wireframeLinejoin=e.wireframeLinejoin),e.rotation!==void 0&&(this.rotation=e.rotation),e.linewidth!==void 0&&(this.linewidth=e.linewidth),e.dashSize!==void 0&&(this.dashSize=e.dashSize),e.gapSize!==void 0&&(this.gapSize=e.gapSize),e.scale!==void 0&&(this.scale=e.scale),e.polygonOffset!==void 0&&(this.polygonOffset=e.polygonOffset),e.polygonOffsetFactor!==void 0&&(this.polygonOffsetFactor=e.polygonOffsetFactor),e.polygonOffsetUnits!==void 0&&(this.polygonOffsetUnits=e.polygonOffsetUnits),e.dithering!==void 0&&(this.dithering=e.dithering),e.alphaToCoverage!==void 0&&(this.alphaToCoverage=e.alphaToCoverage),e.premultipliedAlpha!==void 0&&(this.premultipliedAlpha=e.premultipliedAlpha),e.forceSinglePass!==void 0&&(this.forceSinglePass=e.forceSinglePass),e.allowOverride!==void 0&&(this.allowOverride=e.allowOverride),e.visible!==void 0&&(this.visible=e.visible),e.toneMapped!==void 0&&(this.toneMapped=e.toneMapped),e.userData!==void 0&&(this.userData=e.userData),e.vertexColors!==void 0&&(typeof e.vertexColors=="number"?this.vertexColors=e.vertexColors>0:this.vertexColors=e.vertexColors),e.size!==void 0&&(this.size=e.size),e.sizeAttenuation!==void 0&&(this.sizeAttenuation=e.sizeAttenuation),e.map!==void 0&&(this.map=t[e.map]||null),e.matcap!==void 0&&(this.matcap=t[e.matcap]||null),e.alphaMap!==void 0&&(this.alphaMap=t[e.alphaMap]||null),e.bumpMap!==void 0&&(this.bumpMap=t[e.bumpMap]||null),e.bumpScale!==void 0&&(this.bumpScale=e.bumpScale),e.normalMap!==void 0&&(this.normalMap=t[e.normalMap]||null),e.normalMapType!==void 0&&(this.normalMapType=e.normalMapType),e.normalScale!==void 0){let i=e.normalScale;Array.isArray(i)===!1&&(i=[i,i]),this.normalScale=new xe().fromArray(i)}return e.displacementMap!==void 0&&(this.displacementMap=t[e.displacementMap]||null),e.displacementScale!==void 0&&(this.displacementScale=e.displacementScale),e.displacementBias!==void 0&&(this.displacementBias=e.displacementBias),e.roughnessMap!==void 0&&(this.roughnessMap=t[e.roughnessMap]||null),e.metalnessMap!==void 0&&(this.metalnessMap=t[e.metalnessMap]||null),e.emissiveMap!==void 0&&(this.emissiveMap=t[e.emissiveMap]||null),e.emissiveIntensity!==void 0&&(this.emissiveIntensity=e.emissiveIntensity),e.specularMap!==void 0&&(this.specularMap=t[e.specularMap]||null),e.specularIntensityMap!==void 0&&(this.specularIntensityMap=t[e.specularIntensityMap]||null),e.specularColorMap!==void 0&&(this.specularColorMap=t[e.specularColorMap]||null),e.envMap!==void 0&&(this.envMap=t[e.envMap]||null),e.envMapRotation!==void 0&&this.envMapRotation.fromArray(e.envMapRotation),e.envMapIntensity!==void 0&&(this.envMapIntensity=e.envMapIntensity),e.reflectivity!==void 0&&(this.reflectivity=e.reflectivity),e.refractionRatio!==void 0&&(this.refractionRatio=e.refractionRatio),e.lightMap!==void 0&&(this.lightMap=t[e.lightMap]||null),e.lightMapIntensity!==void 0&&(this.lightMapIntensity=e.lightMapIntensity),e.aoMap!==void 0&&(this.aoMap=t[e.aoMap]||null),e.aoMapIntensity!==void 0&&(this.aoMapIntensity=e.aoMapIntensity),e.gradientMap!==void 0&&(this.gradientMap=t[e.gradientMap]||null),e.clearcoatMap!==void 0&&(this.clearcoatMap=t[e.clearcoatMap]||null),e.clearcoatRoughnessMap!==void 0&&(this.clearcoatRoughnessMap=t[e.clearcoatRoughnessMap]||null),e.clearcoatNormalMap!==void 0&&(this.clearcoatNormalMap=t[e.clearcoatNormalMap]||null),e.clearcoatNormalScale!==void 0&&(this.clearcoatNormalScale=new xe().fromArray(e.clearcoatNormalScale)),e.iridescenceMap!==void 0&&(this.iridescenceMap=t[e.iridescenceMap]||null),e.iridescenceThicknessMap!==void 0&&(this.iridescenceThicknessMap=t[e.iridescenceThicknessMap]||null),e.transmissionMap!==void 0&&(this.transmissionMap=t[e.transmissionMap]||null),e.thicknessMap!==void 0&&(this.thicknessMap=t[e.thicknessMap]||null),e.anisotropyMap!==void 0&&(this.anisotropyMap=t[e.anisotropyMap]||null),e.sheenColorMap!==void 0&&(this.sheenColorMap=t[e.sheenColorMap]||null),e.sheenRoughnessMap!==void 0&&(this.sheenRoughnessMap=t[e.sheenRoughnessMap]||null),this}clone(){return new this.constructor().copy(this)}copy(e){this.name=e.name,this.blending=e.blending,this.side=e.side,this.vertexColors=e.vertexColors,this.opacity=e.opacity,this.transparent=e.transparent,this.blendSrc=e.blendSrc,this.blendDst=e.blendDst,this.blendEquation=e.blendEquation,this.blendSrcAlpha=e.blendSrcAlpha,this.blendDstAlpha=e.blendDstAlpha,this.blendEquationAlpha=e.blendEquationAlpha,this.blendColor.copy(e.blendColor),this.blendAlpha=e.blendAlpha,this.depthFunc=e.depthFunc,this.depthTest=e.depthTest,this.depthWrite=e.depthWrite,this.stencilWriteMask=e.stencilWriteMask,this.stencilFunc=e.stencilFunc,this.stencilRef=e.stencilRef,this.stencilFuncMask=e.stencilFuncMask,this.stencilFail=e.stencilFail,this.stencilZFail=e.stencilZFail,this.stencilZPass=e.stencilZPass,this.stencilWrite=e.stencilWrite;const t=e.clippingPlanes;let i=null;if(t!==null){const n=t.length;i=new Array(n);for(let s=0;s!==n;++s)i[s]=t[s].clone()}return this.clippingPlanes=i,this.clipIntersection=e.clipIntersection,this.clipShadows=e.clipShadows,this.shadowSide=e.shadowSide,this.colorWrite=e.colorWrite,this.precision=e.precision,this.polygonOffset=e.polygonOffset,this.polygonOffsetFactor=e.polygonOffsetFactor,this.polygonOffsetUnits=e.polygonOffsetUnits,this.dithering=e.dithering,this.alphaTest=e.alphaTest,this.alphaHash=e.alphaHash,this.alphaToCoverage=e.alphaToCoverage,this.premultipliedAlpha=e.premultipliedAlpha,this.forceSinglePass=e.forceSinglePass,this.allowOverride=e.allowOverride,this.visible=e.visible,this.toneMapped=e.toneMapped,this.userData=JSON.parse(JSON.stringify(e.userData)),this}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(e){e===!0&&this.version++}}class ul extends Ps{constructor(e){super(),this.isSpriteMaterial=!0,this.type="SpriteMaterial",this.color=new se(16777215),this.map=null,this.alphaMap=null,this.rotation=0,this.sizeAttenuation=!0,this.transparent=!0,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.alphaMap=e.alphaMap,this.rotation=e.rotation,this.sizeAttenuation=e.sizeAttenuation,this.fog=e.fog,this}}let nr;const jr=new R,sr=new R,ar=new R,rr=new xe,Qr=new xe,s1=new Ze,vc=new R,eo=new R,Mc=new R,ip=new xe,Ch=new xe,np=new xe;class to extends Ut{constructor(e=new ul){if(super(),this.isSprite=!0,this.type="Sprite",nr===void 0){nr=new ot;const t=new Float32Array([-.5,-.5,0,0,0,.5,-.5,0,1,0,.5,.5,0,1,1,-.5,.5,0,0,1]),i=new nx(t,5);nr.setIndex([0,1,2,0,2,3]),nr.setAttribute("position",new Dl(i,3,0,!1)),nr.setAttribute("uv",new Dl(i,2,3,!1))}this.geometry=nr,this.material=e,this.center=new xe(.5,.5),this.count=1}raycast(e,t){e.camera===null&&Ge('Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.'),sr.setFromMatrixScale(this.matrixWorld),s1.copy(e.camera.matrixWorld),this.modelViewMatrix.multiplyMatrices(e.camera.matrixWorldInverse,this.matrixWorld),ar.setFromMatrixPosition(this.modelViewMatrix),e.camera.isPerspectiveCamera&&this.material.sizeAttenuation===!1&&sr.multiplyScalar(-ar.z);const i=this.material.rotation;let n,s;i!==0&&(s=Math.cos(i),n=Math.sin(i));const a=this.center;xc(vc.set(-.5,-.5,0),ar,a,sr,n,s),xc(eo.set(.5,-.5,0),ar,a,sr,n,s),xc(Mc.set(.5,.5,0),ar,a,sr,n,s),ip.set(0,0),Ch.set(1,0),np.set(1,1);let o=e.ray.intersectTriangle(vc,eo,Mc,!1,jr);if(o===null&&(xc(eo.set(-.5,.5,0),ar,a,sr,n,s),Ch.set(0,1),o=e.ray.intersectTriangle(vc,Mc,eo,!1,jr),o===null))return;const c=e.ray.origin.distanceTo(jr);c<e.near||c>e.far||t.push({distance:c,point:jr.clone(),uv:yn.getInterpolation(jr,vc,eo,Mc,ip,Ch,np,new xe),face:null,object:this})}copy(e,t){return super.copy(e,t),e.center!==void 0&&this.center.copy(e.center),this.material=e.material,this}}function xc(r,e,t,i,n,s){rr.subVectors(r,t).addScalar(.5).multiply(i),n!==void 0?(Qr.x=s*rr.x-n*rr.y,Qr.y=n*rr.x+s*rr.y):Qr.copy(rr),r.copy(e),r.x+=Qr.x,r.y+=Qr.y,r.applyMatrix4(s1)}const fs=new R,Ph=new R,yc=new R,Hs=new R,Lh=new R,bc=new R,Oh=new R;class Zo{constructor(e=new R,t=new R(0,0,-1)){this.origin=e,this.direction=t}set(e,t){return this.origin.copy(e),this.direction.copy(t),this}copy(e){return this.origin.copy(e.origin),this.direction.copy(e.direction),this}at(e,t){return t.copy(this.origin).addScaledVector(this.direction,e)}lookAt(e){return this.direction.copy(e).sub(this.origin).normalize(),this}recast(e){return this.origin.copy(this.at(e,fs)),this}closestPointToPoint(e,t){t.subVectors(e,this.origin);const i=t.dot(this.direction);return i<0?t.copy(this.origin):t.copy(this.origin).addScaledVector(this.direction,i)}distanceToPoint(e){return Math.sqrt(this.distanceSqToPoint(e))}distanceSqToPoint(e){const t=fs.subVectors(e,this.origin).dot(this.direction);return t<0?this.origin.distanceToSquared(e):(fs.copy(this.origin).addScaledVector(this.direction,t),fs.distanceToSquared(e))}distanceSqToSegment(e,t,i,n){Ph.copy(e).add(t).multiplyScalar(.5),yc.copy(t).sub(e).normalize(),Hs.copy(this.origin).sub(Ph);const s=e.distanceTo(t)*.5,a=-this.direction.dot(yc),o=Hs.dot(this.direction),c=-Hs.dot(yc),l=Hs.lengthSq(),h=Math.abs(1-a*a);let u,d,f,p;if(h>0)if(u=a*c-o,d=a*o-c,p=s*h,u>=0)if(d>=-p)if(d<=p){const v=1/h;u*=v,d*=v,f=u*(u+a*d+2*o)+d*(a*u+d+2*c)+l}else d=s,u=Math.max(0,-(a*d+o)),f=-u*u+d*(d+2*c)+l;else d=-s,u=Math.max(0,-(a*d+o)),f=-u*u+d*(d+2*c)+l;else d<=-p?(u=Math.max(0,-(-a*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,-(a*s+o)),d=u>0?s:Math.min(Math.max(-s,-c),s),f=-u*u+d*(d+2*c)+l);else d=a>0?-s:s,u=Math.max(0,-(a*d+o)),f=-u*u+d*(d+2*c)+l;return i&&i.copy(this.origin).addScaledVector(this.direction,u),n&&n.copy(Ph).addScaledVector(yc,d),f}intersectSphere(e,t){fs.subVectors(e.center,this.origin);const i=fs.dot(this.direction),n=fs.dot(fs)-i*i,s=e.radius*e.radius;if(n>s)return null;const a=Math.sqrt(s-n),o=i-a,c=i+a;return c<0?null:o<0?this.at(c,t):this.at(o,t)}intersectsSphere(e){return e.radius<0?!1:this.distanceSqToPoint(e.center)<=e.radius*e.radius}distanceToPlane(e){const t=e.normal.dot(this.direction);if(t===0)return e.distanceToPoint(this.origin)===0?0:null;const i=-(this.origin.dot(e.normal)+e.constant)/t;return i>=0?i:null}intersectPlane(e,t){const i=this.distanceToPlane(e);return i===null?null:this.at(i,t)}intersectsPlane(e){const t=e.distanceToPoint(this.origin);return t===0||e.normal.dot(this.direction)*t<0}intersectBox(e,t){let i,n,s,a,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=(e.min.x-d.x)*l,n=(e.max.x-d.x)*l):(i=(e.max.x-d.x)*l,n=(e.min.x-d.x)*l),h>=0?(s=(e.min.y-d.y)*h,a=(e.max.y-d.y)*h):(s=(e.max.y-d.y)*h,a=(e.min.y-d.y)*h),i>a||s>n||((s>i||isNaN(i))&&(i=s),(a<n||isNaN(n))&&(n=a),u>=0?(o=(e.min.z-d.z)*u,c=(e.max.z-d.z)*u):(o=(e.max.z-d.z)*u,c=(e.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,t)}intersectsBox(e){return this.intersectBox(e,fs)!==null}intersectTriangle(e,t,i,n,s){Lh.subVectors(t,e),bc.subVectors(i,e),Oh.crossVectors(Lh,bc);let a=this.direction.dot(Oh),o;if(a>0){if(n)return null;o=1}else if(a<0)o=-1,a=-a;else return null;Hs.subVectors(this.origin,e);const c=o*this.direction.dot(bc.crossVectors(Hs,bc));if(c<0)return null;const l=o*this.direction.dot(Lh.cross(Hs));if(l<0||c+l>a)return null;const h=-o*Hs.dot(Oh);return h<0?null:this.at(h/a,s)}applyMatrix4(e){return this.origin.applyMatrix4(e),this.direction.transformDirection(e),this}equals(e){return e.origin.equals(this.origin)&&e.direction.equals(this.direction)}clone(){return new this.constructor().copy(this)}}class bn extends Ps{constructor(e){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new se(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 Ds,this.combine=u0,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.specularMap=e.specularMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.combine=e.combine,this.reflectivity=e.reflectivity,this.refractionRatio=e.refractionRatio,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.fog=e.fog,this}}const sp=new Ze,fa=new Zo,_c=new Cs,ap=new R,Sc=new R,wc=new R,Ec=new R,Nh=new R,Ac=new R,rp=new R,Tc=new R;class De extends Ut{constructor(e=new ot,t=new bn){super(),this.isMesh=!0,this.type="Mesh",this.geometry=e,this.material=t,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.count=1,this.updateMorphTargets()}copy(e,t){return super.copy(e,t),e.morphTargetInfluences!==void 0&&(this.morphTargetInfluences=e.morphTargetInfluences.slice()),e.morphTargetDictionary!==void 0&&(this.morphTargetDictionary=Object.assign({},e.morphTargetDictionary)),this.material=Array.isArray(e.material)?e.material.slice():e.material,this.geometry=e.geometry,this}updateMorphTargets(){const t=this.geometry.morphAttributes,i=Object.keys(t);if(i.length>0){const n=t[i[0]];if(n!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let s=0,a=n.length;s<a;s++){const o=n[s].name||String(s);this.morphTargetInfluences.push(0),this.morphTargetDictionary[o]=s}}}}getVertexPosition(e,t){const i=this.geometry,n=i.attributes.position,s=i.morphAttributes.position,a=i.morphTargetsRelative;t.fromBufferAttribute(n,e);const o=this.morphTargetInfluences;if(s&&o){Ac.set(0,0,0);for(let c=0,l=s.length;c<l;c++){const h=o[c],u=s[c];h!==0&&(Nh.fromBufferAttribute(u,e),a?Ac.addScaledVector(Nh,h):Ac.addScaledVector(Nh.sub(t),h))}t.add(Ac)}return t}raycast(e,t){const i=this.geometry,n=this.material,s=this.matrixWorld;n!==void 0&&(i.boundingSphere===null&&i.computeBoundingSphere(),_c.copy(i.boundingSphere),_c.applyMatrix4(s),fa.copy(e.ray).recast(e.near),!(_c.containsPoint(fa.origin)===!1&&(fa.intersectSphere(_c,ap)===null||fa.origin.distanceToSquared(ap)>(e.far-e.near)**2))&&(sp.copy(s).invert(),fa.copy(e.ray).applyMatrix4(sp),!(i.boundingBox!==null&&fa.intersectsBox(i.boundingBox)===!1)&&this._computeIntersections(e,t,fa)))}_computeIntersections(e,t,i){let n;const s=this.geometry,a=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(a))for(let p=0,v=d.length;p<v;p++){const m=d[p],g=a[m.materialIndex],_=Math.max(m.start,f.start),b=Math.min(o.count,Math.min(m.start+m.count,f.start+f.count));for(let M=_,S=b;M<S;M+=3){const w=o.getX(M),T=o.getX(M+1),x=o.getX(M+2);n=Rc(this,g,e,i,l,h,u,w,T,x),n&&(n.faceIndex=Math.floor(M/3),n.face.materialIndex=m.materialIndex,t.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 _=o.getX(m),b=o.getX(m+1),M=o.getX(m+2);n=Rc(this,a,e,i,l,h,u,_,b,M),n&&(n.faceIndex=Math.floor(m/3),t.push(n))}}else if(c!==void 0)if(Array.isArray(a))for(let p=0,v=d.length;p<v;p++){const m=d[p],g=a[m.materialIndex],_=Math.max(m.start,f.start),b=Math.min(c.count,Math.min(m.start+m.count,f.start+f.count));for(let M=_,S=b;M<S;M+=3){const w=M,T=M+1,x=M+2;n=Rc(this,g,e,i,l,h,u,w,T,x),n&&(n.faceIndex=Math.floor(M/3),n.face.materialIndex=m.materialIndex,t.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 _=m,b=m+1,M=m+2;n=Rc(this,a,e,i,l,h,u,_,b,M),n&&(n.faceIndex=Math.floor(m/3),t.push(n))}}}}function ax(r,e,t,i,n,s,a,o){let c;if(e.side===Ht?c=i.intersectTriangle(a,s,n,!0,o):c=i.intersectTriangle(n,s,a,e.side===sa,o),c===null)return null;Tc.copy(o),Tc.applyMatrix4(r.matrixWorld);const l=t.ray.origin.distanceTo(Tc);return l<t.near||l>t.far?null:{distance:l,point:Tc.clone(),object:r}}function Rc(r,e,t,i,n,s,a,o,c,l){r.getVertexPosition(o,Sc),r.getVertexPosition(c,wc),r.getVertexPosition(l,Ec);const h=ax(r,e,t,i,Sc,wc,Ec,rp);if(h){const u=new R;yn.getBarycoord(rp,Sc,wc,Ec,u),n&&(h.uv=yn.getInterpolatedAttribute(n,o,c,l,u,new xe)),s&&(h.uv1=yn.getInterpolatedAttribute(s,o,c,l,u,new xe)),a&&(h.normal=yn.getInterpolatedAttribute(a,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};yn.getNormal(Sc,wc,Ec,d.normal),h.face=d,h.barycoord=u}return h}const io=new it,op=new it,cp=new it,rx=new it,lp=new Ze,Dc=new R,Fh=new Cs,hp=new Ze,Uh=new Zo;class OA extends De{constructor(e,t){super(e,t),this.isSkinnedMesh=!0,this.type="SkinnedMesh",this.bindMode=Bf,this.bindMatrix=new Ze,this.bindMatrixInverse=new Ze,this.boundingBox=null,this.boundingSphere=null}computeBoundingBox(){const e=this.geometry;this.boundingBox===null&&(this.boundingBox=new Vi),this.boundingBox.makeEmpty();const t=e.getAttribute("position");for(let i=0;i<t.count;i++)this.getVertexPosition(i,Dc),this.boundingBox.expandByPoint(Dc)}computeBoundingSphere(){const e=this.geometry;this.boundingSphere===null&&(this.boundingSphere=new Cs),this.boundingSphere.makeEmpty();const t=e.getAttribute("position");for(let i=0;i<t.count;i++)this.getVertexPosition(i,Dc),this.boundingSphere.expandByPoint(Dc)}copy(e,t){return super.copy(e,t),this.bindMode=e.bindMode,this.bindMatrix.copy(e.bindMatrix),this.bindMatrixInverse.copy(e.bindMatrixInverse),this.skeleton=e.skeleton,e.boundingBox!==null&&(this.boundingBox=e.boundingBox.clone()),e.boundingSphere!==null&&(this.boundingSphere=e.boundingSphere.clone()),this}raycast(e,t){const i=this.material,n=this.matrixWorld;i!==void 0&&(this.boundingSphere===null&&this.computeBoundingSphere(),Fh.copy(this.boundingSphere),Fh.applyMatrix4(n),e.ray.intersectsSphere(Fh)!==!1&&(hp.copy(n).invert(),Uh.copy(e.ray).applyMatrix4(hp),!(this.boundingBox!==null&&Uh.intersectsBox(this.boundingBox)===!1)&&this._computeIntersections(e,t,Uh)))}getVertexPosition(e,t){return super.getVertexPosition(e,t),this.applyBoneTransform(e,t),t}bind(e,t){this.skeleton=e,t===void 0&&(this.updateMatrixWorld(!0),this.skeleton.calculateInverses(),t=this.matrixWorld),this.bindMatrix.copy(t),this.bindMatrixInverse.copy(t).invert()}pose(){this.skeleton.pose()}normalizeSkinWeights(){const e=new it,t=this.geometry.attributes.skinWeight;for(let i=0,n=t.count;i<n;i++){e.fromBufferAttribute(t,i);const s=1/e.manhattanLength();s!==1/0?e.multiplyScalar(s):e.set(1,0,0,0),t.setXYZW(i,e.x,e.y,e.z,e.w)}}updateMatrixWorld(e){super.updateMatrixWorld(e),this.bindMode===Bf?this.bindMatrixInverse.copy(this.matrixWorld).invert():this.bindMode===aM?this.bindMatrixInverse.copy(this.bindMatrix).invert():Re("SkinnedMesh: Unrecognized bindMode: "+this.bindMode)}applyBoneTransform(e,t){const i=this.skeleton,n=this.geometry;op.fromBufferAttribute(n.attributes.skinIndex,e),cp.fromBufferAttribute(n.attributes.skinWeight,e),t.isVector4?(io.copy(t),t.set(0,0,0,0)):(io.set(...t,1),t.set(0,0,0)),io.applyMatrix4(this.bindMatrix);for(let s=0;s<4;s++){const a=cp.getComponent(s);if(a!==0){const o=op.getComponent(s);lp.multiplyMatrices(i.bones[o].matrixWorld,i.boneInverses[o]),t.addScaledVector(rx.copy(io).applyMatrix4(lp),a)}}return t.isVector4&&(t.w=io.w),t.applyMatrix4(this.bindMatrixInverse)}}class ox extends Ut{constructor(){super(),this.isBone=!0,this.type="Bone"}}class ca extends Si{constructor(e=null,t=1,i=1,n,s,a,o,c,l=At,h=At,u,d){super(null,a,o,c,l,h,n,s,u,d),this.isDataTexture=!0,this.image={data:e,width:t,height:i},this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}const up=new Ze,cx=new Ze;class a1{constructor(e=[],t=[]){this.uuid=Un(),this.bones=e.slice(0),this.boneInverses=t,this.boneMatrices=null,this.boneTexture=null,this.init()}init(){const e=this.bones,t=this.boneInverses;if(this.boneMatrices=new Float32Array(e.length*16),t.length===0)this.calculateInverses();else if(e.length!==t.length){Re("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 Ze)}}calculateInverses(){this.boneInverses.length=0;for(let e=0,t=this.bones.length;e<t;e++){const i=new Ze;this.bones[e]&&i.copy(this.bones[e].matrixWorld).invert(),this.boneInverses.push(i)}}pose(){for(let e=0,t=this.bones.length;e<t;e++){const i=this.bones[e];i&&i.matrixWorld.copy(this.boneInverses[e]).invert()}for(let e=0,t=this.bones.length;e<t;e++){const i=this.bones[e];i&&(i.parent&&i.parent.isBone?(i.matrix.copy(i.parent.matrixWorld).invert(),i.matrix.multiply(i.matrixWorld)):i.matrix.copy(i.matrixWorld),i.matrix.decompose(i.position,i.quaternion,i.scale))}}update(){const e=this.bones,t=this.boneInverses,i=this.boneMatrices,n=this.boneTexture;for(let s=0,a=e.length;s<a;s++){const o=e[s]?e[s].matrixWorld:cx;up.multiplyMatrices(o,t[s]),up.toArray(i,s*16)}n!==null&&(n.needsUpdate=!0)}clone(){return new a1(this.bones,this.boneInverses)}computeBoneTexture(){let e=Math.sqrt(this.bones.length*4);e=Math.ceil(e/4)*4,e=Math.max(e,4);const t=new Float32Array(e*e*4);t.set(this.boneMatrices);const i=new ca(t,e,e,Ei,Oi);return i.needsUpdate=!0,this.boneMatrices=t,this.boneTexture=i,this}getBoneByName(e){for(let t=0,i=this.bones.length;t<i;t++){const n=this.bones[t];if(n.name===e)return n}}dispose(){this.boneTexture!==null&&(this.boneTexture.dispose(),this.boneTexture=null)}fromJSON(e,t){this.uuid=e.uuid;for(let i=0,n=e.bones.length;i<n;i++){const s=e.bones[i];let a=t[s];a===void 0&&(Re("Skeleton: No bone found with UUID:",s),a=new ox),this.bones.push(a),this.boneInverses.push(new Ze().fromArray(e.boneInverses[i]))}return this.init(),this}toJSON(){const e={metadata:{version:4.7,type:"Skeleton",generator:"Skeleton.toJSON"},bones:[],boneInverses:[]};e.uuid=this.uuid;const t=this.bones,i=this.boneInverses;for(let n=0,s=t.length;n<s;n++){const a=t[n];e.bones.push(a.uuid);const o=i[n];e.boneInverses.push(o.toArray())}return e}}class dp extends tt{constructor(e,t,i,n=1){super(e,t,i),this.isInstancedBufferAttribute=!0,this.meshPerAttribute=n}copy(e){return super.copy(e),this.meshPerAttribute=e.meshPerAttribute,this}toJSON(){const e=super.toJSON();return e.meshPerAttribute=this.meshPerAttribute,e.isInstancedBufferAttribute=!0,e}}const or=new Ze,fp=new Ze,Ic=[],pp=new Vi,lx=new Ze,no=new De,so=new Cs;class NA extends De{constructor(e,t,i){super(e,t),this.isInstancedMesh=!0,this.instanceMatrix=new dp(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,lx)}computeBoundingBox(){const e=this.geometry,t=this.count;this.boundingBox===null&&(this.boundingBox=new Vi),e.boundingBox===null&&e.computeBoundingBox(),this.boundingBox.makeEmpty();for(let i=0;i<t;i++)this.getMatrixAt(i,or),pp.copy(e.boundingBox).applyMatrix4(or),this.boundingBox.union(pp)}computeBoundingSphere(){const e=this.geometry,t=this.count;this.boundingSphere===null&&(this.boundingSphere=new Cs),e.boundingSphere===null&&e.computeBoundingSphere(),this.boundingSphere.makeEmpty();for(let i=0;i<t;i++)this.getMatrixAt(i,or),so.copy(e.boundingSphere).applyMatrix4(or),this.boundingSphere.union(so)}copy(e,t){return super.copy(e,t),this.instanceMatrix.copy(e.instanceMatrix),e.morphTexture!==null&&(this.morphTexture=e.morphTexture.clone()),e.instanceColor!==null&&(this.instanceColor=e.instanceColor.clone()),this.count=e.count,e.boundingBox!==null&&(this.boundingBox=e.boundingBox.clone()),e.boundingSphere!==null&&(this.boundingSphere=e.boundingSphere.clone()),this}getColorAt(e,t){return this.instanceColor===null?t.setRGB(1,1,1):t.fromArray(this.instanceColor.array,e*3)}getMatrixAt(e,t){return t.fromArray(this.instanceMatrix.array,e*16)}getMorphAt(e,t){const i=t.morphTargetInfluences,n=this.morphTexture.source.data.data,s=i.length+1,a=e*s+1;for(let o=0;o<i.length;o++)i[o]=n[a+o]}raycast(e,t){const i=this.matrixWorld,n=this.count;if(no.geometry=this.geometry,no.material=this.material,no.material!==void 0&&(this.boundingSphere===null&&this.computeBoundingSphere(),so.copy(this.boundingSphere),so.applyMatrix4(i),e.ray.intersectsSphere(so)!==!1))for(let s=0;s<n;s++){this.getMatrixAt(s,or),fp.multiplyMatrices(i,or),no.matrixWorld=fp,no.raycast(e,Ic);for(let a=0,o=Ic.length;a<o;a++){const c=Ic[a];c.instanceId=s,c.object=this,t.push(c)}Ic.length=0}}setColorAt(e,t){return this.instanceColor===null&&(this.instanceColor=new dp(new Float32Array(this.instanceMatrix.count*3).fill(1),3)),t.toArray(this.instanceColor.array,e*3),this}setMatrixAt(e,t){return t.toArray(this.instanceMatrix.array,e*16),this}setMorphAt(e,t){const i=t.morphTargetInfluences,n=i.length+1;this.morphTexture===null&&(this.morphTexture=new ca(new Float32Array(n*this.count),n,this.count,ql,Oi));const s=this.morphTexture.source.data.data;let a=0;for(let l=0;l<i.length;l++)a+=i[l];const o=this.geometry.morphTargetsRelative?1:1-a,c=n*e;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 kh=new R,hx=new R,ux=new Ye;class Ma{constructor(e=new R(1,0,0),t=0){this.isPlane=!0,this.normal=e,this.constant=t}set(e,t){return this.normal.copy(e),this.constant=t,this}setComponents(e,t,i,n){return this.normal.set(e,t,i),this.constant=n,this}setFromNormalAndCoplanarPoint(e,t){return this.normal.copy(e),this.constant=-t.dot(this.normal),this}setFromCoplanarPoints(e,t,i){const n=kh.subVectors(i,t).cross(hx.subVectors(e,t)).normalize();return this.setFromNormalAndCoplanarPoint(n,e),this}copy(e){return this.normal.copy(e.normal),this.constant=e.constant,this}normalize(){const e=1/this.normal.length();return this.normal.multiplyScalar(e),this.constant*=e,this}negate(){return this.constant*=-1,this.normal.negate(),this}distanceToPoint(e){return this.normal.dot(e)+this.constant}distanceToSphere(e){return this.distanceToPoint(e.center)-e.radius}projectPoint(e,t){return t.copy(e).addScaledVector(this.normal,-this.distanceToPoint(e))}intersectLine(e,t,i=!0){const n=e.delta(kh),s=this.normal.dot(n);if(s===0)return this.distanceToPoint(e.start)===0?t.copy(e.start):null;const a=-(e.start.dot(this.normal)+this.constant)/s;return i===!0&&(a<0||a>1)?null:t.copy(e.start).addScaledVector(n,a)}intersectsLine(e){const t=this.distanceToPoint(e.start),i=this.distanceToPoint(e.end);return t<0&&i>0||i<0&&t>0}intersectsBox(e){return e.intersectsPlane(this)}intersectsSphere(e){return e.intersectsPlane(this)}coplanarPoint(e){return e.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(e,t){const i=t||ux.getNormalMatrix(e),n=this.coplanarPoint(kh).applyMatrix4(e),s=this.normal.applyMatrix3(i).normalize();return this.constant=-n.dot(s),this}translate(e){return this.constant-=e.dot(this.normal),this}equals(e){return e.normal.equals(this.normal)&&e.constant===this.constant}clone(){return new this.constructor().copy(this)}}const pa=new Cs,dx=new xe(.5,.5),Cc=new R;class A0{constructor(e=new Ma,t=new Ma,i=new Ma,n=new Ma,s=new Ma,a=new Ma){this.planes=[e,t,i,n,s,a]}set(e,t,i,n,s,a){const o=this.planes;return o[0].copy(e),o[1].copy(t),o[2].copy(i),o[3].copy(n),o[4].copy(s),o[5].copy(a),this}copy(e){const t=this.planes;for(let i=0;i<6;i++)t[i].copy(e.planes[i]);return this}setFromProjectionMatrix(e,t=ns,i=!1){const n=this.planes,s=e.elements,a=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[12],b=s[13],M=s[14],S=s[15];if(n[0].setComponents(l-a,f-h,g-p,S-_).normalize(),n[1].setComponents(l+a,f+h,g+p,S+_).normalize(),n[2].setComponents(l+o,f+u,g+v,S+b).normalize(),n[3].setComponents(l-o,f-u,g-v,S-b).normalize(),i)n[4].setComponents(c,d,m,M).normalize(),n[5].setComponents(l-c,f-d,g-m,S-M).normalize();else if(n[4].setComponents(l-c,f-d,g-m,S-M).normalize(),t===ns)n[5].setComponents(l+c,f+d,g+m,S+M).normalize();else if(t===Xo)n[5].setComponents(c,d,m,M).normalize();else throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: "+t);return this}intersectsObject(e){if(e.boundingSphere!==void 0)e.boundingSphere===null&&e.computeBoundingSphere(),pa.copy(e.boundingSphere).applyMatrix4(e.matrixWorld);else{const t=e.geometry;t.boundingSphere===null&&t.computeBoundingSphere(),pa.copy(t.boundingSphere).applyMatrix4(e.matrixWorld)}return this.intersectsSphere(pa)}intersectsSprite(e){pa.center.set(0,0,0);const t=dx.distanceTo(e.center);return pa.radius=.7071067811865476+t,pa.applyMatrix4(e.matrixWorld),this.intersectsSphere(pa)}intersectsSphere(e){const t=this.planes,i=e.center,n=-e.radius;for(let s=0;s<6;s++)if(t[s].distanceToPoint(i)<n)return!1;return!0}intersectsBox(e){const t=this.planes;for(let i=0;i<6;i++){const n=t[i];if(Cc.x=n.normal.x>0?e.max.x:e.min.x,Cc.y=n.normal.y>0?e.max.y:e.min.y,Cc.z=n.normal.z>0?e.max.z:e.min.z,n.distanceToPoint(Cc)<0)return!1}return!0}containsPoint(e){const t=this.planes;for(let i=0;i<6;i++)if(t[i].distanceToPoint(e)<0)return!1;return!0}clone(){return new this.constructor().copy(this)}}class fx extends Ps{constructor(e){super(),this.isLineBasicMaterial=!0,this.type="LineBasicMaterial",this.color=new se(16777215),this.map=null,this.linewidth=1,this.linecap="round",this.linejoin="round",this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.linewidth=e.linewidth,this.linecap=e.linecap,this.linejoin=e.linejoin,this.fog=e.fog,this}}const Il=new R,Cl=new R,mp=new Ze,ao=new Zo,Pc=new Cs,zh=new R,gp=new R;class r1 extends Ut{constructor(e=new ot,t=new fx){super(),this.isLine=!0,this.type="Line",this.geometry=e,this.material=t,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.updateMorphTargets()}copy(e,t){return super.copy(e,t),this.material=Array.isArray(e.material)?e.material.slice():e.material,this.geometry=e.geometry,this}computeLineDistances(){const e=this.geometry;if(e.index===null){const t=e.attributes.position,i=[0];for(let n=1,s=t.count;n<s;n++)Il.fromBufferAttribute(t,n-1),Cl.fromBufferAttribute(t,n),i[n]=i[n-1],i[n]+=Il.distanceTo(Cl);e.setAttribute("lineDistance",new ut(i,1))}else Re("Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.");return this}raycast(e,t){const i=this.geometry,n=this.matrixWorld,s=e.params.Line.threshold,a=i.drawRange;if(i.boundingSphere===null&&i.computeBoundingSphere(),Pc.copy(i.boundingSphere),Pc.applyMatrix4(n),Pc.radius+=s,e.ray.intersectsSphere(Pc)===!1)return;mp.copy(n).invert(),ao.copy(e.ray).applyMatrix4(mp);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,a.start),p=Math.min(h.count,a.start+a.count);for(let v=f,m=p-1;v<m;v+=l){const g=h.getX(v),_=h.getX(v+1),b=Lc(this,e,ao,c,g,_,v);b&&t.push(b)}if(this.isLineLoop){const v=h.getX(p-1),m=h.getX(f),g=Lc(this,e,ao,c,v,m,p-1);g&&t.push(g)}}else{const f=Math.max(0,a.start),p=Math.min(d.count,a.start+a.count);for(let v=f,m=p-1;v<m;v+=l){const g=Lc(this,e,ao,c,v,v+1,v);g&&t.push(g)}if(this.isLineLoop){const v=Lc(this,e,ao,c,p-1,f,p-1);v&&t.push(v)}}}updateMorphTargets(){const t=this.geometry.morphAttributes,i=Object.keys(t);if(i.length>0){const n=t[i[0]];if(n!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let s=0,a=n.length;s<a;s++){const o=n[s].name||String(s);this.morphTargetInfluences.push(0),this.morphTargetDictionary[o]=s}}}}}function Lc(r,e,t,i,n,s,a){const o=r.geometry.attributes.position;if(Il.fromBufferAttribute(o,n),Cl.fromBufferAttribute(o,s),t.distanceSqToSegment(Il,Cl,zh,gp)>i)return;zh.applyMatrix4(r.matrixWorld);const l=e.ray.origin.distanceTo(zh);if(!(l<e.near||l>e.far))return{distance:l,point:gp.clone().applyMatrix4(r.matrixWorld),index:a,face:null,faceIndex:null,barycoord:null,object:r}}const vp=new R,Mp=new R;class FA extends r1{constructor(e,t){super(e,t),this.isLineSegments=!0,this.type="LineSegments"}computeLineDistances(){const e=this.geometry;if(e.index===null){const t=e.attributes.position,i=[];for(let n=0,s=t.count;n<s;n+=2)vp.fromBufferAttribute(t,n),Mp.fromBufferAttribute(t,n+1),i[n]=n===0?0:i[n-1],i[n+1]=i[n]+vp.distanceTo(Mp);e.setAttribute("lineDistance",new ut(i,1))}else Re("LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.");return this}}class UA extends r1{constructor(e,t){super(e,t),this.isLineLoop=!0,this.type="LineLoop"}}class o1 extends Ps{constructor(e){super(),this.isPointsMaterial=!0,this.type="PointsMaterial",this.color=new se(16777215),this.map=null,this.alphaMap=null,this.size=1,this.sizeAttenuation=!0,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.alphaMap=e.alphaMap,this.size=e.size,this.sizeAttenuation=e.sizeAttenuation,this.fog=e.fog,this}}const xp=new Ze,bd=new Zo,Oc=new Cs,Nc=new R;class xs extends Ut{constructor(e=new ot,t=new o1){super(),this.isPoints=!0,this.type="Points",this.geometry=e,this.material=t,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.updateMorphTargets()}copy(e,t){return super.copy(e,t),this.material=Array.isArray(e.material)?e.material.slice():e.material,this.geometry=e.geometry,this}raycast(e,t){const i=this.geometry,n=this.matrixWorld,s=e.params.Points.threshold,a=i.drawRange;if(i.boundingSphere===null&&i.computeBoundingSphere(),Oc.copy(i.boundingSphere),Oc.applyMatrix4(n),Oc.radius+=s,e.ray.intersectsSphere(Oc)===!1)return;xp.copy(n).invert(),bd.copy(e.ray).applyMatrix4(xp);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,a.start),f=Math.min(l.count,a.start+a.count);for(let p=d,v=f;p<v;p++){const m=l.getX(p);Nc.fromBufferAttribute(u,m),yp(Nc,m,c,n,e,t,this)}}else{const d=Math.max(0,a.start),f=Math.min(u.count,a.start+a.count);for(let p=d,v=f;p<v;p++)Nc.fromBufferAttribute(u,p),yp(Nc,p,c,n,e,t,this)}}updateMorphTargets(){const t=this.geometry.morphAttributes,i=Object.keys(t);if(i.length>0){const n=t[i[0]];if(n!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let s=0,a=n.length;s<a;s++){const o=n[s].name||String(s);this.morphTargetInfluences.push(0),this.morphTargetDictionary[o]=s}}}}}function yp(r,e,t,i,n,s,a){const o=bd.distanceSqToPoint(r);if(o<t){const c=new R;bd.closestPointToPoint(r,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:e,face:null,faceIndex:null,barycoord:null,object:a})}}class c1 extends Si{constructor(e=[],t=Ua,i,n,s,a,o,c,l,h){super(e,t,i,n,s,a,o,c,l,h),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(e){this.image=e}}class Ls extends Si{constructor(e,t,i,n,s,a,o,c,l){super(e,t,i,n,s,a,o,c,l),this.isCanvasTexture=!0,this.needsUpdate=!0}}class aa extends Si{constructor(e,t,i=_n,n,s,a,o=At,c=At,l,h=Rs,u=1){if(h!==Rs&&h!==Ra)throw new Error("THREE.DepthTexture: format must be either THREE.DepthFormat or THREE.DepthStencilFormat");const d={width:e,height:t,depth:u};super(d,n,s,a,o,c,h,i,l),this.isDepthTexture=!0,this.flipY=!1,this.generateMipmaps=!1,this.compareFunction=null}copy(e){return super.copy(e),this.source=new _0(Object.assign({},e.image)),this.compareFunction=e.compareFunction,this}toJSON(e){const t=super.toJSON(e);return this.compareFunction!==null&&(t.compareFunction=this.compareFunction),t}}class px extends aa{constructor(e,t=_n,i=Ua,n,s,a=At,o=At,c,l=Rs){const h={width:e,height:e,depth:1},u=[h,h,h,h,h,h];super(e,e,t,i,n,s,a,o,c,l),this.image=u,this.isCubeDepthTexture=!0,this.isCubeTexture=!0}get images(){return this.image}set images(e){this.image=e}}class l1 extends Si{constructor(e=null){super(),this.sourceTexture=e,this.isExternalTexture=!0}copy(e){return super.copy(e),this.sourceTexture=e.sourceTexture,this}}class Wi extends ot{constructor(e=1,t=1,i=1,n=1,s=1,a=1){super(),this.type="BoxGeometry",this.parameters={width:e,height:t,depth:i,widthSegments:n,heightSegments:s,depthSegments:a};const o=this;n=Math.floor(n),s=Math.floor(s),a=Math.floor(a);const c=[],l=[],h=[],u=[];let d=0,f=0;p("z","y","x",-1,-1,i,t,e,a,s,0),p("z","y","x",1,-1,i,t,-e,a,s,1),p("x","z","y",1,1,e,i,t,n,a,2),p("x","z","y",1,-1,e,i,-t,n,a,3),p("x","y","z",1,-1,e,t,i,n,s,4),p("x","y","z",-1,-1,e,t,-i,n,s,5),this.setIndex(c),this.setAttribute("position",new ut(l,3)),this.setAttribute("normal",new ut(h,3)),this.setAttribute("uv",new ut(u,2));function p(v,m,g,_,b,M,S,w,T,x,A){const C=M/T,I=S/x,P=M/2,V=S/2,X=w/2,L=T+1,B=x+1;let k=0,$=0;const ee=new R;for(let J=0;J<B;J++){const ie=J*I-V;for(let re=0;re<L;re++){const Ve=re*C-P;ee[v]=Ve*_,ee[m]=ie*b,ee[g]=X,l.push(ee.x,ee.y,ee.z),ee[v]=0,ee[m]=0,ee[g]=w>0?1:-1,h.push(ee.x,ee.y,ee.z),u.push(re/T),u.push(1-J/x),k+=1}}for(let J=0;J<x;J++)for(let ie=0;ie<T;ie++){const re=d+ie+L*J,Ve=d+ie+L*(J+1),Je=d+(ie+1)+L*(J+1),qe=d+(ie+1)+L*J;c.push(re,Ve,qe),c.push(Ve,Je,qe),$+=6}o.addGroup(f,$,A),f+=$,d+=k}}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new Wi(e.width,e.height,e.depth,e.widthSegments,e.heightSegments,e.depthSegments)}}class T0 extends ot{constructor(e=1,t=32,i=0,n=Math.PI*2){super(),this.type="CircleGeometry",this.parameters={radius:e,segments:t,thetaStart:i,thetaLength:n},t=Math.max(3,t);const s=[],a=[],o=[],c=[],l=new R,h=new xe;a.push(0,0,0),o.push(0,0,1),c.push(.5,.5);for(let u=0,d=3;u<=t;u++,d+=3){const f=i+u/t*n;l.x=e*Math.cos(f),l.y=e*Math.sin(f),a.push(l.x,l.y,l.z),o.push(0,0,1),h.x=(a[d]/e+1)/2,h.y=(a[d+1]/e+1)/2,c.push(h.x,h.y)}for(let u=1;u<=t;u++)s.push(u,u+1,0);this.setIndex(s),this.setAttribute("position",new ut(a,3)),this.setAttribute("normal",new ut(o,3)),this.setAttribute("uv",new ut(c,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new T0(e.radius,e.segments,e.thetaStart,e.thetaLength)}}class cs extends ot{constructor(e=1,t=1,i=1,n=32,s=1,a=!1,o=0,c=Math.PI*2){super(),this.type="CylinderGeometry",this.parameters={radiusTop:e,radiusBottom:t,height:i,radialSegments:n,heightSegments:s,openEnded:a,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;_(),a===!1&&(e>0&&b(!0),t>0&&b(!1)),this.setIndex(h),this.setAttribute("position",new ut(u,3)),this.setAttribute("normal",new ut(d,3)),this.setAttribute("uv",new ut(f,2));function _(){const M=new R,S=new R;let w=0;const T=(t-e)/i;for(let x=0;x<=s;x++){const A=[],C=x/s,I=C*(t-e)+e;for(let P=0;P<=n;P++){const V=P/n,X=V*c+o,L=Math.sin(X),B=Math.cos(X);S.x=I*L,S.y=-C*i+m,S.z=I*B,u.push(S.x,S.y,S.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 x=0;x<n;x++)for(let A=0;A<s;A++){const C=v[A][x],I=v[A+1][x],P=v[A+1][x+1],V=v[A][x+1];(e>0||A!==0)&&(h.push(C,I,V),w+=3),(t>0||A!==s-1)&&(h.push(I,P,V),w+=3)}l.addGroup(g,w,0),g+=w}function b(M){const S=p,w=new xe,T=new R;let x=0;const A=M===!0?e:t,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=S+P,X=I+P;M===!0?h.push(X,X+1,V):h.push(X+1,X,V),x+=3}l.addGroup(g,x,M===!0?1:2),g+=x}}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new cs(e.radiusTop,e.radiusBottom,e.height,e.radialSegments,e.heightSegments,e.openEnded,e.thetaStart,e.thetaLength)}}class Gr extends cs{constructor(e=1,t=1,i=32,n=1,s=!1,a=0,o=Math.PI*2){super(0,e,t,i,n,s,a,o),this.type="ConeGeometry",this.parameters={radius:e,height:t,radialSegments:i,heightSegments:n,openEnded:s,thetaStart:a,thetaLength:o}}static fromJSON(e){return new Gr(e.radius,e.height,e.radialSegments,e.heightSegments,e.openEnded,e.thetaStart,e.thetaLength)}}class $l extends ot{constructor(e=[new xe(0,-.5),new xe(.5,0),new xe(0,.5)],t=12,i=0,n=Math.PI*2){super(),this.type="LatheGeometry",this.parameters={points:e,segments:t,phiStart:i,phiLength:n},t=Math.floor(t),n=et(n,0,Math.PI*2);const s=[],a=[],o=[],c=[],l=[],h=1/t,u=new R,d=new xe,f=new R,p=new R,v=new R;let m=0,g=0;for(let _=0;_<=e.length-1;_++)switch(_){case 0:m=e[_+1].x-e[_].x,g=e[_+1].y-e[_].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 e.length-1:c.push(v.x,v.y,v.z);break;default:m=e[_+1].x-e[_].x,g=e[_+1].y-e[_].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 _=0;_<=t;_++){const b=i+_*h*n,M=Math.sin(b),S=Math.cos(b);for(let w=0;w<=e.length-1;w++){u.x=e[w].x*M,u.y=e[w].y,u.z=e[w].x*S,a.push(u.x,u.y,u.z),d.x=_/t,d.y=w/(e.length-1),o.push(d.x,d.y);const T=c[3*w+0]*M,x=c[3*w+1],A=c[3*w+0]*S;l.push(T,x,A)}}for(let _=0;_<t;_++)for(let b=0;b<e.length-1;b++){const M=b+_*e.length,S=M,w=M+e.length,T=M+e.length+1,x=M+1;s.push(S,w,x),s.push(T,x,w)}this.setIndex(s),this.setAttribute("position",new ut(a,3)),this.setAttribute("uv",new ut(o,2)),this.setAttribute("normal",new ut(l,3))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new $l(e.points,e.segments,e.phiStart,e.phiLength)}}class Xi extends ot{constructor(e=1,t=1,i=1,n=1){super(),this.type="PlaneGeometry",this.parameters={width:e,height:t,widthSegments:i,heightSegments:n};const s=e/2,a=t/2,o=Math.floor(i),c=Math.floor(n),l=o+1,h=c+1,u=e/o,d=t/c,f=[],p=[],v=[],m=[];for(let g=0;g<h;g++){const _=g*d-a;for(let b=0;b<l;b++){const M=b*u-s;p.push(M,-_,0),v.push(0,0,1),m.push(b/o),m.push(1-g/c)}}for(let g=0;g<c;g++)for(let _=0;_<o;_++){const b=_+l*g,M=_+l*(g+1),S=_+1+l*(g+1),w=_+1+l*g;f.push(b,M,w),f.push(M,S,w)}this.setIndex(f),this.setAttribute("position",new ut(p,3)),this.setAttribute("normal",new ut(v,3)),this.setAttribute("uv",new ut(m,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new Xi(e.width,e.height,e.widthSegments,e.heightSegments)}}class ri extends ot{constructor(e=1,t=32,i=16,n=0,s=Math.PI*2,a=0,o=Math.PI){super(),this.type="SphereGeometry",this.parameters={radius:e,widthSegments:t,heightSegments:i,phiStart:n,phiLength:s,thetaStart:a,thetaLength:o},t=Math.max(3,Math.floor(t)),i=Math.max(2,Math.floor(i));const c=Math.min(a+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 _=[],b=g/i,M=a+b*o,S=e*Math.cos(M),w=Math.sqrt(e*e-S*S);let T=0;g===0&&a===0?T=.5/t:g===i&&c===Math.PI&&(T=-.5/t);for(let x=0;x<=t;x++){const A=x/t,C=n+A*s;u.x=-w*Math.cos(C),u.y=S,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-b),_.push(l++)}h.push(_)}for(let g=0;g<i;g++)for(let _=0;_<t;_++){const b=h[g][_+1],M=h[g][_],S=h[g+1][_],w=h[g+1][_+1];(g!==0||a>0)&&f.push(b,M,w),(g!==i-1||c<Math.PI)&&f.push(M,S,w)}this.setIndex(f),this.setAttribute("position",new ut(p,3)),this.setAttribute("normal",new ut(v,3)),this.setAttribute("uv",new ut(m,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new ri(e.radius,e.widthSegments,e.heightSegments,e.phiStart,e.phiLength,e.thetaStart,e.thetaLength)}}class R0 extends ot{constructor(e=1,t=.4,i=12,n=48,s=Math.PI*2,a=0,o=Math.PI*2){super(),this.type="TorusGeometry",this.parameters={radius:e,tube:t,radialSegments:i,tubularSegments:n,arc:s,thetaStart:a,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=a+v/i*o;for(let g=0;g<=n;g++){const _=g/n*s;f.x=(e+t*Math.cos(m))*Math.cos(_),f.y=(e+t*Math.cos(m))*Math.sin(_),f.z=t*Math.sin(m),l.push(f.x,f.y,f.z),d.x=e*Math.cos(_),d.y=e*Math.sin(_),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,_=(n+1)*(v-1)+m-1,b=(n+1)*(v-1)+m,M=(n+1)*v+m;c.push(g,_,M),c.push(_,b,M)}this.setIndex(c),this.setAttribute("position",new ut(l,3)),this.setAttribute("normal",new ut(h,3)),this.setAttribute("uv",new ut(u,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new R0(e.radius,e.tube,e.radialSegments,e.tubularSegments,e.arc)}}function Br(r){const e={};for(const t in r){e[t]={};for(const i in r[t]){const n=r[t][i];if(bp(n))n.isRenderTargetTexture?(Re("UniformsUtils: Textures of render targets cannot be cloned via cloneUniforms() or mergeUniforms()."),e[t][i]=null):e[t][i]=n.clone();else if(Array.isArray(n))if(bp(n[0])){const s=[];for(let a=0,o=n.length;a<o;a++)s[a]=n[a].clone();e[t][i]=s}else e[t][i]=n.slice();else e[t][i]=n}}return e}function Ui(r){const e={};for(let t=0;t<r.length;t++){const i=Br(r[t]);for(const n in i)e[n]=i[n]}return e}function bp(r){return r&&(r.isColor||r.isMatrix3||r.isMatrix4||r.isVector2||r.isVector3||r.isVector4||r.isTexture||r.isQuaternion)}function mx(r){const e=[];for(let t=0;t<r.length;t++)e.push(r[t].clone());return e}function h1(r){const e=r.getRenderTarget();return e===null?r.outputColorSpace:e.isXRRenderTarget===!0?e.texture.colorSpace:at.workingColorSpace}const gx={clone:Br,merge:Ui};var vx=`void main() {
|
|
1305
|
+
*/const h0="185",k2=0,Uf=1,z2=2,To=1,B2=2,xo=3,sa=0,Ht=1,Qi=2,as=0,ia=1,Ni=2,kf=3,zf=4,Xl=5,ba=100,H2=101,G2=102,V2=103,W2=104,X2=200,Bo=201,Y2=202,q2=203,Ou=204,Ho=205,$2=206,K2=207,Z2=208,J2=209,j2=210,Q2=211,eM=212,tM=213,iM=214,Nu=0,Fu=1,Uu=2,Ur=3,ku=4,zu=5,Bu=6,Hu=7,u0=0,nM=1,sM=2,rs=0,kg=1,zg=2,Bg=3,Hg=4,Gg=5,Vg=6,Wg=7,Bf="attached",aM="detached",Xg=300,Ua=301,kr=302,hh=303,uh=304,Yl=306,Go=1e3,wi=1001,Gu=1002,At=1003,rM=1004,lc=1005,rt=1006,dh=1007,Ta=1008,dn=1009,Yg=1010,qg=1011,Vo=1012,d0=1013,_n=1014,Oi=1015,Wt=1016,f0=1017,p0=1018,Wo=1020,$g=35902,Kg=35899,Zg=1021,Jg=1022,Ei=1023,Rs=1026,Ra=1027,ql=1028,m0=1029,ka=1030,g0=1031,v0=1033,ol=33776,cl=33777,ll=33778,hl=33779,Vu=35840,Wu=35841,Xu=35842,Yu=35843,qu=36196,$u=37492,Ku=37496,Zu=37488,Ju=37489,yl=37490,ju=37491,Qu=37808,ed=37809,td=37810,id=37811,nd=37812,sd=37813,ad=37814,rd=37815,od=37816,cd=37817,ld=37818,hd=37819,ud=37820,dd=37821,fd=36492,pd=36494,md=36495,gd=36283,vd=36284,bl=36285,Md=36286,jg=2200,oM=2201,cM=2202,_l=2300,xd=2301,fh=2302,Hf=2303,Mr=2400,xr=2401,Sl=2402,M0=2500,lM=2501,IA=0,CA=1,PA=2,hM=3200,wl=0,uM=1,Js="",Vi="srgb",El="srgb-linear",Al="linear",yt="srgb",Ya=7680,Gf=519,dM=512,fM=513,pM=514,x0=515,mM=516,gM=517,y0=518,vM=519,yd=35044,Tl="300 es",ns=2e3,Xo=2001;function MM(r){for(let e=r.length-1;e>=0;--e)if(r[e]>=65535)return!0;return!1}function xM(r){return ArrayBuffer.isView(r)&&!(r instanceof DataView)}function Yo(r){return document.createElementNS("http://www.w3.org/1999/xhtml",r)}function yM(){const r=Yo("canvas");return r.style.display="block",r}const Vf={};function Rl(...r){const e="THREE."+r.shift();console.log(e,...r)}function Qg(r){const e=r[0];if(typeof e=="string"&&e.startsWith("TSL:")){const t=r[1];t&&t.isStackTrace?r[0]+=" "+t.getLocation():r[1]='Stack trace not available. Enable "THREE.Node.captureStackTrace" to capture stack traces.'}return r}function Re(...r){r=Qg(r);const e="THREE."+r.shift();{const t=r[0];t&&t.isStackTrace?console.warn(t.getError(e)):console.warn(e,...r)}}function Ge(...r){r=Qg(r);const e="THREE."+r.shift();{const t=r[0];t&&t.isStackTrace?console.error(t.getError(e)):console.error(e,...r)}}function Er(...r){const e=r.join(" ");e in Vf||(Vf[e]=!0,Re(...r))}function bM(r,e,t){return new Promise(function(i,n){function s(){switch(r.clientWaitSync(e,r.SYNC_FLUSH_COMMANDS_BIT,0)){case r.WAIT_FAILED:n();break;case r.TIMEOUT_EXPIRED:setTimeout(s,t);break;default:i()}}setTimeout(s,t)})}const _M={[Nu]:Fu,[Uu]:Bu,[ku]:Hu,[Ur]:zu,[Fu]:Nu,[Bu]:Uu,[Hu]:ku,[zu]:Ur};class oa{addEventListener(e,t){this._listeners===void 0&&(this._listeners={});const i=this._listeners;i[e]===void 0&&(i[e]=[]),i[e].indexOf(t)===-1&&i[e].push(t)}hasEventListener(e,t){const i=this._listeners;return i===void 0?!1:i[e]!==void 0&&i[e].indexOf(t)!==-1}removeEventListener(e,t){const i=this._listeners;if(i===void 0)return;const n=i[e];if(n!==void 0){const s=n.indexOf(t);s!==-1&&n.splice(s,1)}}dispatchEvent(e){const t=this._listeners;if(t===void 0)return;const i=t[e.type];if(i!==void 0){e.target=this;const n=i.slice(0);for(let s=0,a=n.length;s<a;s++)n[s].call(this,e);e.target=null}}}const Ri=["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 Wf=1234567;const Ro=Math.PI/180,zr=180/Math.PI;function Un(){const r=Math.random()*4294967295|0,e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,i=Math.random()*4294967295|0;return(Ri[r&255]+Ri[r>>8&255]+Ri[r>>16&255]+Ri[r>>24&255]+"-"+Ri[e&255]+Ri[e>>8&255]+"-"+Ri[e>>16&15|64]+Ri[e>>24&255]+"-"+Ri[t&63|128]+Ri[t>>8&255]+"-"+Ri[t>>16&255]+Ri[t>>24&255]+Ri[i&255]+Ri[i>>8&255]+Ri[i>>16&255]+Ri[i>>24&255]).toLowerCase()}function et(r,e,t){return Math.max(e,Math.min(t,r))}function b0(r,e){return(r%e+e)%e}function SM(r,e,t,i,n){return i+(r-e)*(n-i)/(t-e)}function wM(r,e,t){return r!==e?(t-r)/(e-r):0}function Do(r,e,t){return(1-t)*r+t*e}function EM(r,e,t,i){return Do(r,e,1-Math.exp(-t*i))}function AM(r,e=1){return e-Math.abs(b0(r,e*2)-e)}function TM(r,e,t){return r<=e?0:r>=t?1:(r=(r-e)/(t-e),r*r*(3-2*r))}function RM(r,e,t){return r<=e?0:r>=t?1:(r=(r-e)/(t-e),r*r*r*(r*(r*6-15)+10))}function DM(r,e){return r+Math.floor(Math.random()*(e-r+1))}function IM(r,e){return r+Math.random()*(e-r)}function CM(r){return r*(.5-Math.random())}function PM(r){r!==void 0&&(Wf=r);let e=Wf+=1831565813;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}function LM(r){return r*Ro}function OM(r){return r*zr}function NM(r){return(r&r-1)===0&&r!==0}function FM(r){return Math.pow(2,Math.ceil(Math.log(r)/Math.LN2))}function UM(r){return Math.pow(2,Math.floor(Math.log(r)/Math.LN2))}function kM(r,e,t,i,n){const s=Math.cos,a=Math.sin,o=s(t/2),c=a(t/2),l=s((e+i)/2),h=a((e+i)/2),u=s((e-i)/2),d=a((e-i)/2),f=s((i-e)/2),p=a((i-e)/2);switch(n){case"XYX":r.set(o*h,c*u,c*d,o*l);break;case"YZY":r.set(c*d,o*h,c*u,o*l);break;case"ZXZ":r.set(c*u,c*d,o*h,o*l);break;case"XZX":r.set(o*h,c*p,c*f,o*l);break;case"YXY":r.set(c*f,o*h,c*p,o*l);break;case"ZYZ":r.set(c*p,c*f,o*h,o*l);break;default:Re("MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+n)}}function Nn(r,e){switch(e.constructor){case Float32Array:return r;case Uint32Array:return r/4294967295;case Uint16Array:return r/65535;case Uint8Array:return r/255;case Int32Array:return Math.max(r/2147483647,-1);case Int16Array:return Math.max(r/32767,-1);case Int8Array:return Math.max(r/127,-1);default:throw new Error("THREE.MathUtils: Invalid component type.")}}function bt(r,e){switch(e.constructor){case Float32Array:return r;case Uint32Array:return Math.round(r*4294967295);case Uint16Array:return Math.round(r*65535);case Uint8Array:return Math.round(r*255);case Int32Array:return Math.round(r*2147483647);case Int16Array:return Math.round(r*32767);case Int8Array:return Math.round(r*127);default:throw new Error("THREE.MathUtils: Invalid component type.")}}const LA={DEG2RAD:Ro,RAD2DEG:zr,generateUUID:Un,clamp:et,euclideanModulo:b0,mapLinear:SM,inverseLerp:wM,lerp:Do,damp:EM,pingpong:AM,smoothstep:TM,smootherstep:RM,randInt:DM,randFloat:IM,randFloatSpread:CM,seededRandom:PM,degToRad:LM,radToDeg:OM,isPowerOfTwo:NM,ceilPowerOfTwo:FM,floorPowerOfTwo:UM,setQuaternionFromProperEuler:kM,normalize:bt,denormalize:Nn};class xe{static{xe.prototype.isVector2=!0}constructor(e=0,t=0){this.x=e,this.y=t}get width(){return this.x}set width(e){this.x=e}get height(){return this.y}set height(e){this.y=e}set(e,t){return this.x=e,this.y=t,this}setScalar(e){return this.x=e,this.y=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;default:throw new Error("THREE.Vector2: index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;default:throw new Error("THREE.Vector2: index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}addScalar(e){return this.x+=e,this.y+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this}subScalar(e){return this.x-=e,this.y-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this}multiply(e){return this.x*=e.x,this.y*=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}divide(e){return this.x/=e.x,this.y/=e.y,this}divideScalar(e){return this.multiplyScalar(1/e)}applyMatrix3(e){const t=this.x,i=this.y,n=e.elements;return this.x=n[0]*t+n[3]*i+n[6],this.y=n[1]*t+n[4]*i+n[7],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this}clamp(e,t){return this.x=et(this.x,e.x,t.x),this.y=et(this.y,e.y,t.y),this}clampScalar(e,t){return this.x=et(this.x,e,t),this.y=et(this.y,e,t),this}clampLength(e,t){const i=this.length();return this.divideScalar(i||1).multiplyScalar(et(i,e,t))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(e){return this.x*e.x+this.y*e.y}cross(e){return this.x*e.y-this.y*e.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(e){const t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;const i=this.dot(e)/t;return Math.acos(et(i,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,i=this.y-e.y;return t*t+i*i}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this}lerpVectors(e,t,i){return this.x=e.x+(t.x-e.x)*i,this.y=e.y+(t.y-e.y)*i,this}equals(e){return e.x===this.x&&e.y===this.y}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this}rotateAround(e,t){const i=Math.cos(t),n=Math.sin(t),s=this.x-e.x,a=this.y-e.y;return this.x=s*i-a*n+e.x,this.y=s*n+a*i+e.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class en{constructor(e=0,t=0,i=0,n=1){this.isQuaternion=!0,this._x=e,this._y=t,this._z=i,this._w=n}static slerpFlat(e,t,i,n,s,a,o){let c=i[n+0],l=i[n+1],h=i[n+2],u=i[n+3],d=s[a+0],f=s[a+1],p=s[a+2],v=s[a+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 _=Math.acos(m),b=Math.sin(_);g=Math.sin(g*_)/b,o=Math.sin(o*_)/b,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 _=1/Math.sqrt(c*c+l*l+h*h+u*u);c*=_,l*=_,h*=_,u*=_}}e[t]=c,e[t+1]=l,e[t+2]=h,e[t+3]=u}static multiplyQuaternionsFlat(e,t,i,n,s,a){const o=i[n],c=i[n+1],l=i[n+2],h=i[n+3],u=s[a],d=s[a+1],f=s[a+2],p=s[a+3];return e[t]=o*p+h*u+c*f-l*d,e[t+1]=c*p+h*d+l*u-o*f,e[t+2]=l*p+h*f+o*d-c*u,e[t+3]=h*p-o*u-c*d-l*f,e}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get w(){return this._w}set w(e){this._w=e,this._onChangeCallback()}set(e,t,i,n){return this._x=e,this._y=t,this._z=i,this._w=n,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback(),this}setFromEuler(e,t=!0){const i=e._x,n=e._y,s=e._z,a=e._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(a){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:Re("Quaternion: .setFromEuler() encountered an unknown order: "+a)}return t===!0&&this._onChangeCallback(),this}setFromAxisAngle(e,t){const i=t/2,n=Math.sin(i);return this._x=e.x*n,this._y=e.y*n,this._z=e.z*n,this._w=Math.cos(i),this._onChangeCallback(),this}setFromRotationMatrix(e){const t=e.elements,i=t[0],n=t[4],s=t[8],a=t[1],o=t[5],c=t[9],l=t[2],h=t[6],u=t[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=(a-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+a)/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+a)/f,this._y=.25*f,this._z=(c+h)/f}else{const f=2*Math.sqrt(1+u-i-o);this._w=(a-n)/f,this._x=(s+l)/f,this._y=(c+h)/f,this._z=.25*f}return this._onChangeCallback(),this}setFromUnitVectors(e,t){let i=e.dot(t)+1;return i<1e-8?(i=0,Math.abs(e.x)>Math.abs(e.z)?(this._x=-e.y,this._y=e.x,this._z=0,this._w=i):(this._x=0,this._y=-e.z,this._z=e.y,this._w=i)):(this._x=e.y*t.z-e.z*t.y,this._y=e.z*t.x-e.x*t.z,this._z=e.x*t.y-e.y*t.x,this._w=i),this.normalize()}angleTo(e){return 2*Math.acos(Math.abs(et(this.dot(e),-1,1)))}rotateTowards(e,t){const i=this.angleTo(e);if(i===0)return this;const n=Math.min(1,t/i);return this.slerp(e,n),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(e){return this._x*e._x+this._y*e._y+this._z*e._z+this._w*e._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let e=this.length();return e===0?(this._x=0,this._y=0,this._z=0,this._w=1):(e=1/e,this._x=this._x*e,this._y=this._y*e,this._z=this._z*e,this._w=this._w*e),this._onChangeCallback(),this}multiply(e){return this.multiplyQuaternions(this,e)}premultiply(e){return this.multiplyQuaternions(e,this)}multiplyQuaternions(e,t){const i=e._x,n=e._y,s=e._z,a=e._w,o=t._x,c=t._y,l=t._z,h=t._w;return this._x=i*h+a*o+n*l-s*c,this._y=n*h+a*c+s*o-i*l,this._z=s*h+a*l+i*c-n*o,this._w=a*h-i*o-n*c-s*l,this._onChangeCallback(),this}slerp(e,t){let i=e._x,n=e._y,s=e._z,a=e._w,o=this.dot(e);o<0&&(i=-i,n=-n,s=-s,a=-a,o=-o);let c=1-t;if(o<.9995){const l=Math.acos(o),h=Math.sin(l);c=Math.sin(c*l)/h,t=Math.sin(t*l)/h,this._x=this._x*c+i*t,this._y=this._y*c+n*t,this._z=this._z*c+s*t,this._w=this._w*c+a*t,this._onChangeCallback()}else this._x=this._x*c+i*t,this._y=this._y*c+n*t,this._z=this._z*c+s*t,this._w=this._w*c+a*t,this.normalize();return this}slerpQuaternions(e,t,i){return this.copy(e).slerp(t,i)}random(){const e=2*Math.PI*Math.random(),t=2*Math.PI*Math.random(),i=Math.random(),n=Math.sqrt(1-i),s=Math.sqrt(i);return this.set(n*Math.sin(e),n*Math.cos(e),s*Math.sin(t),s*Math.cos(t))}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._w===this._w}fromArray(e,t=0){return this._x=e[t],this._y=e[t+1],this._z=e[t+2],this._w=e[t+3],this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._w,e}fromBufferAttribute(e,t){return this._x=e.getX(t),this._y=e.getY(t),this._z=e.getZ(t),this._w=e.getW(t),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class R{static{R.prototype.isVector3=!0}constructor(e=0,t=0,i=0){this.x=e,this.y=t,this.z=i}set(e,t,i){return i===void 0&&(i=this.z),this.x=e,this.y=t,this.z=i,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;default:throw new Error("THREE.Vector3: index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("THREE.Vector3: index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}multiplyVectors(e,t){return this.x=e.x*t.x,this.y=e.y*t.y,this.z=e.z*t.z,this}applyEuler(e){return this.applyQuaternion(Xf.setFromEuler(e))}applyAxisAngle(e,t){return this.applyQuaternion(Xf.setFromAxisAngle(e,t))}applyMatrix3(e){const t=this.x,i=this.y,n=this.z,s=e.elements;return this.x=s[0]*t+s[3]*i+s[6]*n,this.y=s[1]*t+s[4]*i+s[7]*n,this.z=s[2]*t+s[5]*i+s[8]*n,this}applyNormalMatrix(e){return this.applyMatrix3(e).normalize()}applyMatrix4(e){const t=this.x,i=this.y,n=this.z,s=e.elements,a=1/(s[3]*t+s[7]*i+s[11]*n+s[15]);return this.x=(s[0]*t+s[4]*i+s[8]*n+s[12])*a,this.y=(s[1]*t+s[5]*i+s[9]*n+s[13])*a,this.z=(s[2]*t+s[6]*i+s[10]*n+s[14])*a,this}applyQuaternion(e){const t=this.x,i=this.y,n=this.z,s=e.x,a=e.y,o=e.z,c=e.w,l=2*(a*n-o*i),h=2*(o*t-s*n),u=2*(s*i-a*t);return this.x=t+c*l+a*u-o*h,this.y=i+c*h+o*l-s*u,this.z=n+c*u+s*h-a*l,this}project(e){return this.applyMatrix4(e.matrixWorldInverse).applyMatrix4(e.projectionMatrix)}unproject(e){return this.applyMatrix4(e.projectionMatrixInverse).applyMatrix4(e.matrixWorld)}transformDirection(e){const t=this.x,i=this.y,n=this.z,s=e.elements;return this.x=s[0]*t+s[4]*i+s[8]*n,this.y=s[1]*t+s[5]*i+s[9]*n,this.z=s[2]*t+s[6]*i+s[10]*n,this.normalize()}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this}divideScalar(e){return this.multiplyScalar(1/e)}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this}clamp(e,t){return this.x=et(this.x,e.x,t.x),this.y=et(this.y,e.y,t.y),this.z=et(this.z,e.z,t.z),this}clampScalar(e,t){return this.x=et(this.x,e,t),this.y=et(this.y,e,t),this.z=et(this.z,e,t),this}clampLength(e,t){const i=this.length();return this.divideScalar(i||1).multiplyScalar(et(i,e,t))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this}lerpVectors(e,t,i){return this.x=e.x+(t.x-e.x)*i,this.y=e.y+(t.y-e.y)*i,this.z=e.z+(t.z-e.z)*i,this}cross(e){return this.crossVectors(this,e)}crossVectors(e,t){const i=e.x,n=e.y,s=e.z,a=t.x,o=t.y,c=t.z;return this.x=n*c-s*o,this.y=s*a-i*c,this.z=i*o-n*a,this}projectOnVector(e){const t=e.lengthSq();if(t===0)return this.set(0,0,0);const i=e.dot(this)/t;return this.copy(e).multiplyScalar(i)}projectOnPlane(e){return ph.copy(this).projectOnVector(e),this.sub(ph)}reflect(e){return this.sub(ph.copy(e).multiplyScalar(2*this.dot(e)))}angleTo(e){const t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;const i=this.dot(e)/t;return Math.acos(et(i,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,i=this.y-e.y,n=this.z-e.z;return t*t+i*i+n*n}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)+Math.abs(this.z-e.z)}setFromSpherical(e){return this.setFromSphericalCoords(e.radius,e.phi,e.theta)}setFromSphericalCoords(e,t,i){const n=Math.sin(t)*e;return this.x=n*Math.sin(i),this.y=Math.cos(t)*e,this.z=n*Math.cos(i),this}setFromCylindrical(e){return this.setFromCylindricalCoords(e.radius,e.theta,e.y)}setFromCylindricalCoords(e,t,i){return this.x=e*Math.sin(t),this.y=i,this.z=e*Math.cos(t),this}setFromMatrixPosition(e){const t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this}setFromMatrixScale(e){const t=this.setFromMatrixColumn(e,0).length(),i=this.setFromMatrixColumn(e,1).length(),n=this.setFromMatrixColumn(e,2).length();return this.x=t,this.y=i,this.z=n,this}setFromMatrixColumn(e,t){return this.fromArray(e.elements,t*4)}setFromMatrix3Column(e,t){return this.fromArray(e.elements,t*3)}setFromEuler(e){return this.x=e._x,this.y=e._y,this.z=e._z,this}setFromColor(e){return this.x=e.r,this.y=e.g,this.z=e.b,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const e=Math.random()*Math.PI*2,t=Math.random()*2-1,i=Math.sqrt(1-t*t);return this.x=i*Math.cos(e),this.y=t,this.z=i*Math.sin(e),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const ph=new R,Xf=new en;class Ye{static{Ye.prototype.isMatrix3=!0}constructor(e,t,i,n,s,a,o,c,l){this.elements=[1,0,0,0,1,0,0,0,1],e!==void 0&&this.set(e,t,i,n,s,a,o,c,l)}set(e,t,i,n,s,a,o,c,l){const h=this.elements;return h[0]=e,h[1]=n,h[2]=o,h[3]=t,h[4]=s,h[5]=c,h[6]=i,h[7]=a,h[8]=l,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(e){const t=this.elements,i=e.elements;return t[0]=i[0],t[1]=i[1],t[2]=i[2],t[3]=i[3],t[4]=i[4],t[5]=i[5],t[6]=i[6],t[7]=i[7],t[8]=i[8],this}extractBasis(e,t,i){return e.setFromMatrix3Column(this,0),t.setFromMatrix3Column(this,1),i.setFromMatrix3Column(this,2),this}setFromMatrix4(e){const t=e.elements;return this.set(t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]),this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){const i=e.elements,n=t.elements,s=this.elements,a=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],_=n[1],b=n[4],M=n[7],S=n[2],w=n[5],T=n[8];return s[0]=a*v+o*_+c*S,s[3]=a*m+o*b+c*w,s[6]=a*g+o*M+c*T,s[1]=l*v+h*_+u*S,s[4]=l*m+h*b+u*w,s[7]=l*g+h*M+u*T,s[2]=d*v+f*_+p*S,s[5]=d*m+f*b+p*w,s[8]=d*g+f*M+p*T,this}multiplyScalar(e){const t=this.elements;return t[0]*=e,t[3]*=e,t[6]*=e,t[1]*=e,t[4]*=e,t[7]*=e,t[2]*=e,t[5]*=e,t[8]*=e,this}determinant(){const e=this.elements,t=e[0],i=e[1],n=e[2],s=e[3],a=e[4],o=e[5],c=e[6],l=e[7],h=e[8];return t*a*h-t*o*l-i*s*h+i*o*c+n*s*l-n*a*c}invert(){const e=this.elements,t=e[0],i=e[1],n=e[2],s=e[3],a=e[4],o=e[5],c=e[6],l=e[7],h=e[8],u=h*a-o*l,d=o*c-h*s,f=l*s-a*c,p=t*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 e[0]=u*v,e[1]=(n*l-h*i)*v,e[2]=(o*i-n*a)*v,e[3]=d*v,e[4]=(h*t-n*c)*v,e[5]=(n*s-o*t)*v,e[6]=f*v,e[7]=(i*c-l*t)*v,e[8]=(a*t-i*s)*v,this}transpose(){let e;const t=this.elements;return e=t[1],t[1]=t[3],t[3]=e,e=t[2],t[2]=t[6],t[6]=e,e=t[5],t[5]=t[7],t[7]=e,this}getNormalMatrix(e){return this.setFromMatrix4(e).invert().transpose()}transposeIntoArray(e){const t=this.elements;return e[0]=t[0],e[1]=t[3],e[2]=t[6],e[3]=t[1],e[4]=t[4],e[5]=t[7],e[6]=t[2],e[7]=t[5],e[8]=t[8],this}setUvTransform(e,t,i,n,s,a,o){const c=Math.cos(s),l=Math.sin(s);return this.set(i*c,i*l,-i*(c*a+l*o)+a+e,-n*l,n*c,-n*(-l*a+c*o)+o+t,0,0,1),this}scale(e,t){return Er("Matrix3: .scale() is deprecated. Use .makeScale() instead."),this.premultiply(mh.makeScale(e,t)),this}rotate(e){return Er("Matrix3: .rotate() is deprecated. Use .makeRotation() instead."),this.premultiply(mh.makeRotation(-e)),this}translate(e,t){return Er("Matrix3: .translate() is deprecated. Use .makeTranslation() instead."),this.premultiply(mh.makeTranslation(e,t)),this}makeTranslation(e,t){return e.isVector2?this.set(1,0,e.x,0,1,e.y,0,0,1):this.set(1,0,e,0,1,t,0,0,1),this}makeRotation(e){const t=Math.cos(e),i=Math.sin(e);return this.set(t,-i,0,i,t,0,0,0,1),this}makeScale(e,t){return this.set(e,0,0,0,t,0,0,0,1),this}equals(e){const t=this.elements,i=e.elements;for(let n=0;n<9;n++)if(t[n]!==i[n])return!1;return!0}fromArray(e,t=0){for(let i=0;i<9;i++)this.elements[i]=e[i+t];return this}toArray(e=[],t=0){const i=this.elements;return e[t]=i[0],e[t+1]=i[1],e[t+2]=i[2],e[t+3]=i[3],e[t+4]=i[4],e[t+5]=i[5],e[t+6]=i[6],e[t+7]=i[7],e[t+8]=i[8],e}clone(){return new this.constructor().fromArray(this.elements)}}const mh=new Ye,Yf=new Ye().set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),qf=new Ye().set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);function zM(){const r={enabled:!0,workingColorSpace:El,spaces:{},convert:function(n,s,a){return this.enabled===!1||s===a||!s||!a||(this.spaces[s].transfer===yt&&(n.r=Ts(n.r),n.g=Ts(n.g),n.b=Ts(n.b)),this.spaces[s].primaries!==this.spaces[a].primaries&&(n.applyMatrix3(this.spaces[s].toXYZ),n.applyMatrix3(this.spaces[a].fromXYZ)),this.spaces[a].transfer===yt&&(n.r=Ar(n.r),n.g=Ar(n.g),n.b=Ar(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===Js?Al: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,a){return n.copy(this.spaces[s].toXYZ).multiply(this.spaces[a].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 Er("ColorManagement: .fromWorkingColorSpace() has been renamed to .workingToColorSpace()."),r.workingToColorSpace(n,s)},toWorkingColorSpace:function(n,s){return Er("ColorManagement: .toWorkingColorSpace() has been renamed to .colorSpaceToWorking()."),r.colorSpaceToWorking(n,s)}},e=[.64,.33,.3,.6,.15,.06],t=[.2126,.7152,.0722],i=[.3127,.329];return r.define({[El]:{primaries:e,whitePoint:i,transfer:Al,toXYZ:Yf,fromXYZ:qf,luminanceCoefficients:t,workingColorSpaceConfig:{unpackColorSpace:Vi},outputColorSpaceConfig:{drawingBufferColorSpace:Vi}},[Vi]:{primaries:e,whitePoint:i,transfer:yt,toXYZ:Yf,fromXYZ:qf,luminanceCoefficients:t,outputColorSpaceConfig:{drawingBufferColorSpace:Vi}}}),r}const at=zM();function Ts(r){return r<.04045?r*.0773993808:Math.pow(r*.9478672986+.0521327014,2.4)}function Ar(r){return r<.0031308?r*12.92:1.055*Math.pow(r,.41666)-.055}let qa;class BM{static getDataURL(e,t="image/png"){if(/^data:/i.test(e.src)||typeof HTMLCanvasElement>"u")return e.src;let i;if(e instanceof HTMLCanvasElement)i=e;else{qa===void 0&&(qa=Yo("canvas")),qa.width=e.width,qa.height=e.height;const n=qa.getContext("2d");e instanceof ImageData?n.putImageData(e,0,0):n.drawImage(e,0,0,e.width,e.height),i=qa}return i.toDataURL(t)}static sRGBToLinear(e){if(typeof HTMLImageElement<"u"&&e instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&e instanceof ImageBitmap){const t=Yo("canvas");t.width=e.width,t.height=e.height;const i=t.getContext("2d");i.drawImage(e,0,0,e.width,e.height);const n=i.getImageData(0,0,e.width,e.height),s=n.data;for(let a=0;a<s.length;a++)s[a]=Ts(s[a]/255)*255;return i.putImageData(n,0,0),t}else if(e.data){const t=e.data.slice(0);for(let i=0;i<t.length;i++)t instanceof Uint8Array||t instanceof Uint8ClampedArray?t[i]=Math.floor(Ts(t[i]/255)*255):t[i]=Ts(t[i]);return{data:t,width:e.width,height:e.height}}else return Re("ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."),e}}let HM=0;class _0{constructor(e=null){this.isSource=!0,Object.defineProperty(this,"id",{value:HM++}),this.uuid=Un(),this.data=e,this.dataReady=!0,this.version=0}getSize(e){const t=this.data;return typeof HTMLVideoElement<"u"&&t instanceof HTMLVideoElement?e.set(t.videoWidth,t.videoHeight,0):typeof VideoFrame<"u"&&t instanceof VideoFrame?e.set(t.displayWidth,t.displayHeight,0):t!==null?e.set(t.width,t.height,t.depth||0):e.set(0,0,0),e}set needsUpdate(e){e===!0&&this.version++}toJSON(e){const t=e===void 0||typeof e=="string";if(!t&&e.images[this.uuid]!==void 0)return e.images[this.uuid];const i={uuid:this.uuid,url:""},n=this.data;if(n!==null){let s;if(Array.isArray(n)){s=[];for(let a=0,o=n.length;a<o;a++)n[a].isDataTexture?s.push(gh(n[a].image)):s.push(gh(n[a]))}else s=gh(n);i.url=s}return t||(e.images[this.uuid]=i),i}}function gh(r){return typeof HTMLImageElement<"u"&&r instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&r instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&r instanceof ImageBitmap?BM.getDataURL(r):r.data?{data:Array.from(r.data),width:r.width,height:r.height,type:r.data.constructor.name}:(Re("Texture: Unable to serialize Texture."),{})}let GM=0;const vh=new R;class Si extends oa{constructor(e=Si.DEFAULT_IMAGE,t=Si.DEFAULT_MAPPING,i=wi,n=wi,s=rt,a=Ta,o=Ei,c=dn,l=Si.DEFAULT_ANISOTROPY,h=Js){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:GM++}),this.uuid=Un(),this.name="",this.source=new _0(e),this.mipmaps=[],this.mapping=t,this.channel=0,this.wrapS=i,this.wrapT=n,this.magFilter=s,this.minFilter=a,this.anisotropy=l,this.format=o,this.internalFormat=null,this.type=c,this.offset=new xe(0,0),this.repeat=new xe(1,1),this.center=new xe(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new Ye,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.colorSpace=h,this.userData={},this.updateRanges=[],this.version=0,this.onUpdate=null,this.renderTarget=null,this.isRenderTargetTexture=!1,this.isArrayTexture=!!(e&&e.depth&&e.depth>1),this.pmremVersion=0,this.normalized=!1}get width(){return this.source.getSize(vh).x}get height(){return this.source.getSize(vh).y}get depth(){return this.source.getSize(vh).z}get image(){return this.source.data}set image(e){this.source.data=e}updateMatrix(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y)}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}clone(){return new this.constructor().copy(this)}copy(e){return this.name=e.name,this.source=e.source,this.mipmaps=e.mipmaps.slice(0),this.mapping=e.mapping,this.channel=e.channel,this.wrapS=e.wrapS,this.wrapT=e.wrapT,this.magFilter=e.magFilter,this.minFilter=e.minFilter,this.anisotropy=e.anisotropy,this.format=e.format,this.internalFormat=e.internalFormat,this.type=e.type,this.normalized=e.normalized,this.offset.copy(e.offset),this.repeat.copy(e.repeat),this.center.copy(e.center),this.rotation=e.rotation,this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrix.copy(e.matrix),this.generateMipmaps=e.generateMipmaps,this.premultiplyAlpha=e.premultiplyAlpha,this.flipY=e.flipY,this.unpackAlignment=e.unpackAlignment,this.colorSpace=e.colorSpace,this.renderTarget=e.renderTarget,this.isRenderTargetTexture=e.isRenderTargetTexture,this.isArrayTexture=e.isArrayTexture,this.userData=JSON.parse(JSON.stringify(e.userData)),this.needsUpdate=!0,this}setValues(e){for(const t in e){const i=e[t];if(i===void 0){Re(`Texture.setValues(): parameter '${t}' has value of undefined.`);continue}const n=this[t];if(n===void 0){Re(`Texture.setValues(): property '${t}' does not exist.`);continue}n&&i&&n.isVector2&&i.isVector2||n&&i&&n.isVector3&&i.isVector3||n&&i&&n.isMatrix3&&i.isMatrix3?n.copy(i):this[t]=i}}toJSON(e){const t=e===void 0||typeof e=="string";if(!t&&e.textures[this.uuid]!==void 0)return e.textures[this.uuid];const i={metadata:{version:4.7,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,image:this.source.toJSON(e).uuid,mapping:this.mapping,channel:this.channel,repeat:[this.repeat.x,this.repeat.y],offset:[this.offset.x,this.offset.y],center:[this.center.x,this.center.y],rotation:this.rotation,wrap:[this.wrapS,this.wrapT],format:this.format,internalFormat:this.internalFormat,type:this.type,normalized:this.normalized,colorSpace:this.colorSpace,minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy,flipY:this.flipY,generateMipmaps:this.generateMipmaps,premultiplyAlpha:this.premultiplyAlpha,unpackAlignment:this.unpackAlignment};return Object.keys(this.userData).length>0&&(i.userData=this.userData),t||(e.textures[this.uuid]=i),i}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(e){if(this.mapping!==Xg)return e;if(e.applyMatrix3(this.matrix),e.x<0||e.x>1)switch(this.wrapS){case Go:e.x=e.x-Math.floor(e.x);break;case wi:e.x=e.x<0?0:1;break;case Gu:Math.abs(Math.floor(e.x)%2)===1?e.x=Math.ceil(e.x)-e.x:e.x=e.x-Math.floor(e.x);break}if(e.y<0||e.y>1)switch(this.wrapT){case Go:e.y=e.y-Math.floor(e.y);break;case wi:e.y=e.y<0?0:1;break;case Gu:Math.abs(Math.floor(e.y)%2)===1?e.y=Math.ceil(e.y)-e.y:e.y=e.y-Math.floor(e.y);break}return this.flipY&&(e.y=1-e.y),e}set needsUpdate(e){e===!0&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(e){e===!0&&this.pmremVersion++}}Si.DEFAULT_IMAGE=null;Si.DEFAULT_MAPPING=Xg;Si.DEFAULT_ANISOTROPY=1;class it{static{it.prototype.isVector4=!0}constructor(e=0,t=0,i=0,n=1){this.x=e,this.y=t,this.z=i,this.w=n}get width(){return this.z}set width(e){this.z=e}get height(){return this.w}set height(e){this.w=e}set(e,t,i,n){return this.x=e,this.y=t,this.z=i,this.w=n,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this.w=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setW(e){return this.w=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;case 3:this.w=t;break;default:throw new Error("THREE.Vector4: index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("THREE.Vector4: index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w!==void 0?e.w:1,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this.w+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this.w=e.w+t.w,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this.w+=e.w*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this.w-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this.w=e.w-t.w,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this.w*=e.w,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}applyMatrix4(e){const t=this.x,i=this.y,n=this.z,s=this.w,a=e.elements;return this.x=a[0]*t+a[4]*i+a[8]*n+a[12]*s,this.y=a[1]*t+a[5]*i+a[9]*n+a[13]*s,this.z=a[2]*t+a[6]*i+a[10]*n+a[14]*s,this.w=a[3]*t+a[7]*i+a[11]*n+a[15]*s,this}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this.w/=e.w,this}divideScalar(e){return this.multiplyScalar(1/e)}setAxisAngleFromQuaternion(e){this.w=2*Math.acos(e.w);const t=Math.sqrt(1-e.w*e.w);return t<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=e.x/t,this.y=e.y/t,this.z=e.z/t),this}setAxisAngleFromRotationMatrix(e){let t,i,n,s;const c=e.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;t=Math.PI;const b=(l+1)/2,M=(f+1)/2,S=(g+1)/2,w=(h+d)/4,T=(u+v)/4,x=(p+m)/4;return b>M&&b>S?b<.01?(i=0,n=.707106781,s=.707106781):(i=Math.sqrt(b),n=w/i,s=T/i):M>S?M<.01?(i=.707106781,n=0,s=.707106781):(n=Math.sqrt(M),i=w/n,s=x/n):S<.01?(i=.707106781,n=.707106781,s=0):(s=Math.sqrt(S),i=T/s,n=x/s),this.set(i,n,s,t),this}let _=Math.sqrt((m-p)*(m-p)+(u-v)*(u-v)+(d-h)*(d-h));return Math.abs(_)<.001&&(_=1),this.x=(m-p)/_,this.y=(u-v)/_,this.z=(d-h)/_,this.w=Math.acos((l+f+g-1)/2),this}setFromMatrixPosition(e){const t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this.w=t[15],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this.w=Math.min(this.w,e.w),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this.w=Math.max(this.w,e.w),this}clamp(e,t){return this.x=et(this.x,e.x,t.x),this.y=et(this.y,e.y,t.y),this.z=et(this.z,e.z,t.z),this.w=et(this.w,e.w,t.w),this}clampScalar(e,t){return this.x=et(this.x,e,t),this.y=et(this.y,e,t),this.z=et(this.z,e,t),this.w=et(this.w,e,t),this}clampLength(e,t){const i=this.length();return this.divideScalar(i||1).multiplyScalar(et(i,e,t))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z+this.w*e.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this.w+=(e.w-this.w)*t,this}lerpVectors(e,t,i){return this.x=e.x+(t.x-e.x)*i,this.y=e.y+(t.y-e.y)*i,this.z=e.z+(t.z-e.z)*i,this.w=e.w+(t.w-e.w)*i,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z&&e.w===this.w}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this.w=e[t+3],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e[t+3]=this.w,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this.w=e.getW(t),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}}class VM extends oa{constructor(e=1,t=1,i={}){super(),i=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:rt,depthBuffer:!0,stencilBuffer:!1,resolveDepthBuffer:!0,resolveStencilBuffer:!0,depthTexture:null,samples:0,count:1,depth:1,multiview:!1,useArrayDepthTexture:!1},i),this.isRenderTarget=!0,this.width=e,this.height=t,this.depth=i.depth,this.scissor=new it(0,0,e,t),this.scissorTest=!1,this.viewport=new it(0,0,e,t),this.textures=[];const n={width:e,height:t,depth:i.depth},s=new Si(n),a=i.count;for(let o=0;o<a;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(e={}){const t={minFilter:rt,generateMipmaps:!1,flipY:!1,internalFormat:null};e.mapping!==void 0&&(t.mapping=e.mapping),e.wrapS!==void 0&&(t.wrapS=e.wrapS),e.wrapT!==void 0&&(t.wrapT=e.wrapT),e.wrapR!==void 0&&(t.wrapR=e.wrapR),e.magFilter!==void 0&&(t.magFilter=e.magFilter),e.minFilter!==void 0&&(t.minFilter=e.minFilter),e.format!==void 0&&(t.format=e.format),e.type!==void 0&&(t.type=e.type),e.anisotropy!==void 0&&(t.anisotropy=e.anisotropy),e.colorSpace!==void 0&&(t.colorSpace=e.colorSpace),e.flipY!==void 0&&(t.flipY=e.flipY),e.generateMipmaps!==void 0&&(t.generateMipmaps=e.generateMipmaps),e.internalFormat!==void 0&&(t.internalFormat=e.internalFormat);for(let i=0;i<this.textures.length;i++)this.textures[i].setValues(t)}get texture(){return this.textures[0]}set texture(e){this.textures[0]=e}set depthTexture(e){this._depthTexture!==null&&(this._depthTexture.renderTarget=null),e!==null&&(e.renderTarget=this),this._depthTexture=e}get depthTexture(){return this._depthTexture}setSize(e,t,i=1){if(this.width!==e||this.height!==t||this.depth!==i){this.width=e,this.height=t,this.depth=i;for(let n=0,s=this.textures.length;n<s;n++)this.textures[n].image.width=e,this.textures[n].image.height=t,this.textures[n].image.depth=i,this.textures[n].isData3DTexture!==!0&&(this.textures[n].isArrayTexture=this.textures[n].image.depth>1);this.dispose()}this.viewport.set(0,0,e,t),this.scissor.set(0,0,e,t)}clone(){return new this.constructor().copy(this)}copy(e){this.width=e.width,this.height=e.height,this.depth=e.depth,this.scissor.copy(e.scissor),this.scissorTest=e.scissorTest,this.viewport.copy(e.viewport),this.textures.length=0;for(let t=0,i=e.textures.length;t<i;t++){this.textures[t]=e.textures[t].clone(),this.textures[t].isRenderTargetTexture=!0,this.textures[t].renderTarget=this;const n=Object.assign({},e.textures[t].image);this.textures[t].source=new _0(n)}return this.depthBuffer=e.depthBuffer,this.stencilBuffer=e.stencilBuffer,this.resolveDepthBuffer=e.resolveDepthBuffer,this.resolveStencilBuffer=e.resolveStencilBuffer,e.depthTexture!==null&&(this.depthTexture=e.depthTexture.clone()),this.samples=e.samples,this.multiview=e.multiview,this.useArrayDepthTexture=e.useArrayDepthTexture,this}dispose(){this.dispatchEvent({type:"dispose"})}}class ai extends VM{constructor(e=1,t=1,i={}){super(e,t,i),this.isWebGLRenderTarget=!0}}class e1 extends Si{constructor(e=null,t=1,i=1,n=1){super(null),this.isDataArrayTexture=!0,this.image={data:e,width:t,height:i,depth:n},this.magFilter=At,this.minFilter=At,this.wrapR=wi,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1,this.layerUpdates=new Set}addLayerUpdate(e){this.layerUpdates.add(e)}clearLayerUpdates(){this.layerUpdates.clear()}}class t1 extends Si{constructor(e=null,t=1,i=1,n=1){super(null),this.isData3DTexture=!0,this.image={data:e,width:t,height:i,depth:n},this.magFilter=At,this.minFilter=At,this.wrapR=wi,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}class Ze{static{Ze.prototype.isMatrix4=!0}constructor(e,t,i,n,s,a,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],e!==void 0&&this.set(e,t,i,n,s,a,o,c,l,h,u,d,f,p,v,m)}set(e,t,i,n,s,a,o,c,l,h,u,d,f,p,v,m){const g=this.elements;return g[0]=e,g[4]=t,g[8]=i,g[12]=n,g[1]=s,g[5]=a,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 Ze().fromArray(this.elements)}copy(e){const t=this.elements,i=e.elements;return t[0]=i[0],t[1]=i[1],t[2]=i[2],t[3]=i[3],t[4]=i[4],t[5]=i[5],t[6]=i[6],t[7]=i[7],t[8]=i[8],t[9]=i[9],t[10]=i[10],t[11]=i[11],t[12]=i[12],t[13]=i[13],t[14]=i[14],t[15]=i[15],this}copyPosition(e){const t=this.elements,i=e.elements;return t[12]=i[12],t[13]=i[13],t[14]=i[14],this}setFromMatrix3(e){const t=e.elements;return this.set(t[0],t[3],t[6],0,t[1],t[4],t[7],0,t[2],t[5],t[8],0,0,0,0,1),this}extractBasis(e,t,i){return this.determinantAffine()===0?(e.set(1,0,0),t.set(0,1,0),i.set(0,0,1),this):(e.setFromMatrixColumn(this,0),t.setFromMatrixColumn(this,1),i.setFromMatrixColumn(this,2),this)}makeBasis(e,t,i){return this.set(e.x,t.x,i.x,0,e.y,t.y,i.y,0,e.z,t.z,i.z,0,0,0,0,1),this}extractRotation(e){if(e.determinantAffine()===0)return this.identity();const t=this.elements,i=e.elements,n=1/$a.setFromMatrixColumn(e,0).length(),s=1/$a.setFromMatrixColumn(e,1).length(),a=1/$a.setFromMatrixColumn(e,2).length();return t[0]=i[0]*n,t[1]=i[1]*n,t[2]=i[2]*n,t[3]=0,t[4]=i[4]*s,t[5]=i[5]*s,t[6]=i[6]*s,t[7]=0,t[8]=i[8]*a,t[9]=i[9]*a,t[10]=i[10]*a,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromEuler(e){const t=this.elements,i=e.x,n=e.y,s=e.z,a=Math.cos(i),o=Math.sin(i),c=Math.cos(n),l=Math.sin(n),h=Math.cos(s),u=Math.sin(s);if(e.order==="XYZ"){const d=a*h,f=a*u,p=o*h,v=o*u;t[0]=c*h,t[4]=-c*u,t[8]=l,t[1]=f+p*l,t[5]=d-v*l,t[9]=-o*c,t[2]=v-d*l,t[6]=p+f*l,t[10]=a*c}else if(e.order==="YXZ"){const d=c*h,f=c*u,p=l*h,v=l*u;t[0]=d+v*o,t[4]=p*o-f,t[8]=a*l,t[1]=a*u,t[5]=a*h,t[9]=-o,t[2]=f*o-p,t[6]=v+d*o,t[10]=a*c}else if(e.order==="ZXY"){const d=c*h,f=c*u,p=l*h,v=l*u;t[0]=d-v*o,t[4]=-a*u,t[8]=p+f*o,t[1]=f+p*o,t[5]=a*h,t[9]=v-d*o,t[2]=-a*l,t[6]=o,t[10]=a*c}else if(e.order==="ZYX"){const d=a*h,f=a*u,p=o*h,v=o*u;t[0]=c*h,t[4]=p*l-f,t[8]=d*l+v,t[1]=c*u,t[5]=v*l+d,t[9]=f*l-p,t[2]=-l,t[6]=o*c,t[10]=a*c}else if(e.order==="YZX"){const d=a*c,f=a*l,p=o*c,v=o*l;t[0]=c*h,t[4]=v-d*u,t[8]=p*u+f,t[1]=u,t[5]=a*h,t[9]=-o*h,t[2]=-l*h,t[6]=f*u+p,t[10]=d-v*u}else if(e.order==="XZY"){const d=a*c,f=a*l,p=o*c,v=o*l;t[0]=c*h,t[4]=-u,t[8]=l*h,t[1]=d*u+v,t[5]=a*h,t[9]=f*u-p,t[2]=p*u-f,t[6]=o*h,t[10]=v*u+d}return t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromQuaternion(e){return this.compose(WM,e,XM)}lookAt(e,t,i){const n=this.elements;return nn.subVectors(e,t),nn.lengthSq()===0&&(nn.z=1),nn.normalize(),Us.crossVectors(i,nn),Us.lengthSq()===0&&(Math.abs(i.z)===1?nn.x+=1e-4:nn.z+=1e-4,nn.normalize(),Us.crossVectors(i,nn)),Us.normalize(),hc.crossVectors(nn,Us),n[0]=Us.x,n[4]=hc.x,n[8]=nn.x,n[1]=Us.y,n[5]=hc.y,n[9]=nn.y,n[2]=Us.z,n[6]=hc.z,n[10]=nn.z,this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){const i=e.elements,n=t.elements,s=this.elements,a=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],_=i[3],b=i[7],M=i[11],S=i[15],w=n[0],T=n[4],x=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],ee=n[7],J=n[11],ie=n[15];return s[0]=a*w+o*C+c*X+l*$,s[4]=a*T+o*I+c*L+l*ee,s[8]=a*x+o*P+c*B+l*J,s[12]=a*A+o*V+c*k+l*ie,s[1]=h*w+u*C+d*X+f*$,s[5]=h*T+u*I+d*L+f*ee,s[9]=h*x+u*P+d*B+f*J,s[13]=h*A+u*V+d*k+f*ie,s[2]=p*w+v*C+m*X+g*$,s[6]=p*T+v*I+m*L+g*ee,s[10]=p*x+v*P+m*B+g*J,s[14]=p*A+v*V+m*k+g*ie,s[3]=_*w+b*C+M*X+S*$,s[7]=_*T+b*I+M*L+S*ee,s[11]=_*x+b*P+M*B+S*J,s[15]=_*A+b*V+M*k+S*ie,this}multiplyScalar(e){const t=this.elements;return t[0]*=e,t[4]*=e,t[8]*=e,t[12]*=e,t[1]*=e,t[5]*=e,t[9]*=e,t[13]*=e,t[2]*=e,t[6]*=e,t[10]*=e,t[14]*=e,t[3]*=e,t[7]*=e,t[11]*=e,t[15]*=e,this}determinant(){const e=this.elements,t=e[0],i=e[4],n=e[8],s=e[12],a=e[1],o=e[5],c=e[9],l=e[13],h=e[2],u=e[6],d=e[10],f=e[14],p=e[3],v=e[7],m=e[11],g=e[15],_=c*f-l*d,b=o*f-l*u,M=o*d-c*u,S=a*f-l*h,w=a*d-c*h,T=a*u-o*h;return t*(v*_-m*b+g*M)-i*(p*_-m*S+g*w)+n*(p*b-v*S+g*T)-s*(p*M-v*w+m*T)}determinantAffine(){const e=this.elements,t=e[0],i=e[4],n=e[8],s=e[1],a=e[5],o=e[9],c=e[2],l=e[6],h=e[10];return t*(a*h-o*l)-i*(s*h-o*c)+n*(s*l-a*c)}transpose(){const e=this.elements;let t;return t=e[1],e[1]=e[4],e[4]=t,t=e[2],e[2]=e[8],e[8]=t,t=e[6],e[6]=e[9],e[9]=t,t=e[3],e[3]=e[12],e[12]=t,t=e[7],e[7]=e[13],e[13]=t,t=e[11],e[11]=e[14],e[14]=t,this}setPosition(e,t,i){const n=this.elements;return e.isVector3?(n[12]=e.x,n[13]=e.y,n[14]=e.z):(n[12]=e,n[13]=t,n[14]=i),this}invert(){const e=this.elements,t=e[0],i=e[1],n=e[2],s=e[3],a=e[4],o=e[5],c=e[6],l=e[7],h=e[8],u=e[9],d=e[10],f=e[11],p=e[12],v=e[13],m=e[14],g=e[15],_=t*o-i*a,b=t*c-n*a,M=t*l-s*a,S=i*c-n*o,w=i*l-s*o,T=n*l-s*c,x=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=_*V-b*P+M*I+S*C-w*A+T*x;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 e[0]=(o*V-c*P+l*I)*L,e[1]=(n*P-i*V-s*I)*L,e[2]=(v*T-m*w+g*S)*L,e[3]=(d*w-u*T-f*S)*L,e[4]=(c*C-a*V-l*A)*L,e[5]=(t*V-n*C+s*A)*L,e[6]=(m*M-p*T-g*b)*L,e[7]=(h*T-d*M+f*b)*L,e[8]=(a*P-o*C+l*x)*L,e[9]=(i*C-t*P-s*x)*L,e[10]=(p*w-v*M+g*_)*L,e[11]=(u*M-h*w-f*_)*L,e[12]=(o*A-a*I-c*x)*L,e[13]=(t*I-i*A+n*x)*L,e[14]=(v*b-p*S-m*_)*L,e[15]=(h*S-u*b+d*_)*L,this}scale(e){const t=this.elements,i=e.x,n=e.y,s=e.z;return t[0]*=i,t[4]*=n,t[8]*=s,t[1]*=i,t[5]*=n,t[9]*=s,t[2]*=i,t[6]*=n,t[10]*=s,t[3]*=i,t[7]*=n,t[11]*=s,this}getMaxScaleOnAxis(){const e=this.elements,t=e[0]*e[0]+e[1]*e[1]+e[2]*e[2],i=e[4]*e[4]+e[5]*e[5]+e[6]*e[6],n=e[8]*e[8]+e[9]*e[9]+e[10]*e[10];return Math.sqrt(Math.max(t,i,n))}makeTranslation(e,t,i){return e.isVector3?this.set(1,0,0,e.x,0,1,0,e.y,0,0,1,e.z,0,0,0,1):this.set(1,0,0,e,0,1,0,t,0,0,1,i,0,0,0,1),this}makeRotationX(e){const t=Math.cos(e),i=Math.sin(e);return this.set(1,0,0,0,0,t,-i,0,0,i,t,0,0,0,0,1),this}makeRotationY(e){const t=Math.cos(e),i=Math.sin(e);return this.set(t,0,i,0,0,1,0,0,-i,0,t,0,0,0,0,1),this}makeRotationZ(e){const t=Math.cos(e),i=Math.sin(e);return this.set(t,-i,0,0,i,t,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(e,t){const i=Math.cos(t),n=Math.sin(t),s=1-i,a=e.x,o=e.y,c=e.z,l=s*a,h=s*o;return this.set(l*a+i,l*o-n*c,l*c+n*o,0,l*o+n*c,h*o+i,h*c-n*a,0,l*c-n*o,h*c+n*a,s*c*c+i,0,0,0,0,1),this}makeScale(e,t,i){return this.set(e,0,0,0,0,t,0,0,0,0,i,0,0,0,0,1),this}makeShear(e,t,i,n,s,a){return this.set(1,i,s,0,e,1,a,0,t,n,1,0,0,0,0,1),this}compose(e,t,i){const n=this.elements,s=t._x,a=t._y,o=t._z,c=t._w,l=s+s,h=a+a,u=o+o,d=s*l,f=s*h,p=s*u,v=a*h,m=a*u,g=o*u,_=c*l,b=c*h,M=c*u,S=i.x,w=i.y,T=i.z;return n[0]=(1-(v+g))*S,n[1]=(f+M)*S,n[2]=(p-b)*S,n[3]=0,n[4]=(f-M)*w,n[5]=(1-(d+g))*w,n[6]=(m+_)*w,n[7]=0,n[8]=(p+b)*T,n[9]=(m-_)*T,n[10]=(1-(d+v))*T,n[11]=0,n[12]=e.x,n[13]=e.y,n[14]=e.z,n[15]=1,this}decompose(e,t,i){const n=this.elements;e.x=n[12],e.y=n[13],e.z=n[14];const s=this.determinantAffine();if(s===0)return i.set(1,1,1),t.identity(),this;let a=$a.set(n[0],n[1],n[2]).length();const o=$a.set(n[4],n[5],n[6]).length(),c=$a.set(n[8],n[9],n[10]).length();s<0&&(a=-a),Sn.copy(this);const l=1/a,h=1/o,u=1/c;return Sn.elements[0]*=l,Sn.elements[1]*=l,Sn.elements[2]*=l,Sn.elements[4]*=h,Sn.elements[5]*=h,Sn.elements[6]*=h,Sn.elements[8]*=u,Sn.elements[9]*=u,Sn.elements[10]*=u,t.setFromRotationMatrix(Sn),i.x=a,i.y=o,i.z=c,this}makePerspective(e,t,i,n,s,a,o=ns,c=!1){const l=this.elements,h=2*s/(t-e),u=2*s/(i-n),d=(t+e)/(t-e),f=(i+n)/(i-n);let p,v;if(c)p=s/(a-s),v=a*s/(a-s);else if(o===ns)p=-(a+s)/(a-s),v=-2*a*s/(a-s);else if(o===Xo)p=-a/(a-s),v=-a*s/(a-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(e,t,i,n,s,a,o=ns,c=!1){const l=this.elements,h=2/(t-e),u=2/(i-n),d=-(t+e)/(t-e),f=-(i+n)/(i-n);let p,v;if(c)p=1/(a-s),v=a/(a-s);else if(o===ns)p=-2/(a-s),v=-(a+s)/(a-s);else if(o===Xo)p=-1/(a-s),v=-s/(a-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(e){const t=this.elements,i=e.elements;for(let n=0;n<16;n++)if(t[n]!==i[n])return!1;return!0}fromArray(e,t=0){for(let i=0;i<16;i++)this.elements[i]=e[i+t];return this}toArray(e=[],t=0){const i=this.elements;return e[t]=i[0],e[t+1]=i[1],e[t+2]=i[2],e[t+3]=i[3],e[t+4]=i[4],e[t+5]=i[5],e[t+6]=i[6],e[t+7]=i[7],e[t+8]=i[8],e[t+9]=i[9],e[t+10]=i[10],e[t+11]=i[11],e[t+12]=i[12],e[t+13]=i[13],e[t+14]=i[14],e[t+15]=i[15],e}}const $a=new R,Sn=new Ze,WM=new R(0,0,0),XM=new R(1,1,1),Us=new R,hc=new R,nn=new R,$f=new Ze,Kf=new en;class Ds{constructor(e=0,t=0,i=0,n=Ds.DEFAULT_ORDER){this.isEuler=!0,this._x=e,this._y=t,this._z=i,this._order=n}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get order(){return this._order}set order(e){this._order=e,this._onChangeCallback()}set(e,t,i,n=this._order){return this._x=e,this._y=t,this._z=i,this._order=n,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(e){return this._x=e._x,this._y=e._y,this._z=e._z,this._order=e._order,this._onChangeCallback(),this}setFromRotationMatrix(e,t=this._order,i=!0){const n=e.elements,s=n[0],a=n[4],o=n[8],c=n[1],l=n[5],h=n[9],u=n[2],d=n[6],f=n[10];switch(t){case"XYZ":this._y=Math.asin(et(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-h,f),this._z=Math.atan2(-a,s)):(this._x=Math.atan2(d,l),this._z=0);break;case"YXZ":this._x=Math.asin(-et(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(et(d,-1,1)),Math.abs(d)<.9999999?(this._y=Math.atan2(-u,f),this._z=Math.atan2(-a,l)):(this._y=0,this._z=Math.atan2(c,s));break;case"ZYX":this._y=Math.asin(-et(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(-a,l));break;case"YZX":this._z=Math.asin(et(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(-et(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(d,l),this._y=Math.atan2(o,s)):(this._x=Math.atan2(-h,f),this._y=0);break;default:Re("Euler: .setFromRotationMatrix() encountered an unknown order: "+t)}return this._order=t,i===!0&&this._onChangeCallback(),this}setFromQuaternion(e,t,i){return $f.makeRotationFromQuaternion(e),this.setFromRotationMatrix($f,t,i)}setFromVector3(e,t=this._order){return this.set(e.x,e.y,e.z,t)}reorder(e){return Kf.setFromEuler(this),this.setFromQuaternion(Kf,e)}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._order===this._order}fromArray(e){return this._x=e[0],this._y=e[1],this._z=e[2],e[3]!==void 0&&(this._order=e[3]),this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._order,e}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}Ds.DEFAULT_ORDER="XYZ";class S0{constructor(){this.mask=1}set(e){this.mask=(1<<e|0)>>>0}enable(e){this.mask|=1<<e|0}enableAll(){this.mask=-1}toggle(e){this.mask^=1<<e|0}disable(e){this.mask&=~(1<<e|0)}disableAll(){this.mask=0}test(e){return(this.mask&e.mask)!==0}isEnabled(e){return(this.mask&(1<<e|0))!==0}}let YM=0;const Zf=new R,Ka=new en,ls=new Ze,uc=new R,$r=new R,qM=new R,$M=new en,Jf=new R(1,0,0),jf=new R(0,1,0),Qf=new R(0,0,1),ep={type:"added"},KM={type:"removed"},Za={type:"childadded",child:null},Mh={type:"childremoved",child:null};class Ut extends oa{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:YM++}),this.uuid=Un(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=Ut.DEFAULT_UP.clone();const e=new R,t=new Ds,i=new en,n=new R(1,1,1);function s(){i.setFromEuler(t,!1)}function a(){t.setFromQuaternion(i,void 0,!1)}t._onChange(s),i._onChange(a),Object.defineProperties(this,{position:{configurable:!0,enumerable:!0,value:e},rotation:{configurable:!0,enumerable:!0,value:t},quaternion:{configurable:!0,enumerable:!0,value:i},scale:{configurable:!0,enumerable:!0,value:n},modelViewMatrix:{value:new Ze},normalMatrix:{value:new Ye}}),this.matrix=new Ze,this.matrixWorld=new Ze,this.matrixAutoUpdate=Ut.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=Ut.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new S0,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.renderOrder=0,this.animations=[],this.customDepthMaterial=void 0,this.customDistanceMaterial=void 0,this.static=!1,this.userData={},this.pivot=null}onBeforeShadow(){}onAfterShadow(){}onBeforeRender(){}onAfterRender(){}applyMatrix4(e){this.matrixAutoUpdate&&this.updateMatrix(),this.matrix.premultiply(e),this.matrix.decompose(this.position,this.quaternion,this.scale)}applyQuaternion(e){return this.quaternion.premultiply(e),this}setRotationFromAxisAngle(e,t){this.quaternion.setFromAxisAngle(e,t)}setRotationFromEuler(e){this.quaternion.setFromEuler(e,!0)}setRotationFromMatrix(e){this.quaternion.setFromRotationMatrix(e)}setRotationFromQuaternion(e){this.quaternion.copy(e)}rotateOnAxis(e,t){return Ka.setFromAxisAngle(e,t),this.quaternion.multiply(Ka),this}rotateOnWorldAxis(e,t){return Ka.setFromAxisAngle(e,t),this.quaternion.premultiply(Ka),this}rotateX(e){return this.rotateOnAxis(Jf,e)}rotateY(e){return this.rotateOnAxis(jf,e)}rotateZ(e){return this.rotateOnAxis(Qf,e)}translateOnAxis(e,t){return Zf.copy(e).applyQuaternion(this.quaternion),this.position.add(Zf.multiplyScalar(t)),this}translateX(e){return this.translateOnAxis(Jf,e)}translateY(e){return this.translateOnAxis(jf,e)}translateZ(e){return this.translateOnAxis(Qf,e)}localToWorld(e){return this.updateWorldMatrix(!0,!1),e.applyMatrix4(this.matrixWorld)}worldToLocal(e){return this.updateWorldMatrix(!0,!1),e.applyMatrix4(ls.copy(this.matrixWorld).invert())}lookAt(e,t,i){e.isVector3?uc.copy(e):uc.set(e,t,i);const n=this.parent;this.updateWorldMatrix(!0,!1),$r.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?ls.lookAt($r,uc,this.up):ls.lookAt(uc,$r,this.up),this.quaternion.setFromRotationMatrix(ls),n&&(ls.extractRotation(n.matrixWorld),Ka.setFromRotationMatrix(ls),this.quaternion.premultiply(Ka.invert()))}add(e){if(arguments.length>1){for(let t=0;t<arguments.length;t++)this.add(arguments[t]);return this}return e===this?(Ge("Object3D.add: object can't be added as a child of itself.",e),this):(e&&e.isObject3D?(e.removeFromParent(),e.parent=this,this.children.push(e),e.dispatchEvent(ep),Za.child=e,this.dispatchEvent(Za),Za.child=null):Ge("Object3D.add: object not an instance of THREE.Object3D.",e),this)}remove(e){if(arguments.length>1){for(let i=0;i<arguments.length;i++)this.remove(arguments[i]);return this}const t=this.children.indexOf(e);return t!==-1&&(e.parent=null,this.children.splice(t,1),e.dispatchEvent(KM),Mh.child=e,this.dispatchEvent(Mh),Mh.child=null),this}removeFromParent(){const e=this.parent;return e!==null&&e.remove(this),this}clear(){return this.remove(...this.children)}attach(e){return this.updateWorldMatrix(!0,!1),ls.copy(this.matrixWorld).invert(),e.parent!==null&&(e.parent.updateWorldMatrix(!0,!1),ls.multiply(e.parent.matrixWorld)),e.applyMatrix4(ls),e.removeFromParent(),e.parent=this,this.children.push(e),e.updateWorldMatrix(!1,!0),e.dispatchEvent(ep),Za.child=e,this.dispatchEvent(Za),Za.child=null,this}getObjectById(e){return this.getObjectByProperty("id",e)}getObjectByName(e){return this.getObjectByProperty("name",e)}getObjectByProperty(e,t){if(this[e]===t)return this;for(let i=0,n=this.children.length;i<n;i++){const a=this.children[i].getObjectByProperty(e,t);if(a!==void 0)return a}}getObjectsByProperty(e,t,i=[]){this[e]===t&&i.push(this);const n=this.children;for(let s=0,a=n.length;s<a;s++)n[s].getObjectsByProperty(e,t,i);return i}getWorldPosition(e){return this.updateWorldMatrix(!0,!1),e.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(e){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose($r,e,qM),e}getWorldScale(e){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose($r,$M,e),e}getWorldDirection(e){this.updateWorldMatrix(!0,!1);const t=this.matrixWorld.elements;return e.set(t[8],t[9],t[10]).normalize()}raycast(){}traverse(e){e(this);const t=this.children;for(let i=0,n=t.length;i<n;i++)t[i].traverse(e)}traverseVisible(e){if(this.visible===!1)return;e(this);const t=this.children;for(let i=0,n=t.length;i<n;i++)t[i].traverseVisible(e)}traverseAncestors(e){const t=this.parent;t!==null&&(e(t),t.traverseAncestors(e))}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale);const e=this.pivot;if(e!==null){const t=e.x,i=e.y,n=e.z,s=this.matrix.elements;s[12]+=t-s[0]*t-s[4]*i-s[8]*n,s[13]+=i-s[1]*t-s[5]*i-s[9]*n,s[14]+=n-s[2]*t-s[6]*i-s[10]*n}this.matrixWorldNeedsUpdate=!0}updateMatrixWorld(e){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||e)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,e=!0);const t=this.children;for(let i=0,n=t.length;i<n;i++)t[i].updateMatrixWorld(e)}updateWorldMatrix(e,t,i=!1){const n=this.parent;if(e===!0&&n!==null&&n.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||i)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,i=!0),t===!0){const s=this.children;for(let a=0,o=s.length;a<o;a++)s[a].updateWorldMatrix(!1,!0,i)}}toJSON(e){const t=e===void 0||typeof e=="string",i={};t&&(e={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},i.metadata={version:4.7,type:"Object",generator:"Object3D.toJSON"});const n={};n.uuid=this.uuid,n.type=this.type,this.name!==""&&(n.name=this.name),this.castShadow===!0&&(n.castShadow=!0),this.receiveShadow===!0&&(n.receiveShadow=!0),this.visible===!1&&(n.visible=!1),this.frustumCulled===!1&&(n.frustumCulled=!1),this.renderOrder!==0&&(n.renderOrder=this.renderOrder),this.static!==!1&&(n.static=this.static),Object.keys(this.userData).length>0&&(n.userData=this.userData),n.layers=this.layers.mask,n.matrix=this.matrix.toArray(),n.up=this.up.toArray(),this.pivot!==null&&(n.pivot=this.pivot.toArray()),this.matrixAutoUpdate===!1&&(n.matrixAutoUpdate=!1),this.morphTargetDictionary!==void 0&&(n.morphTargetDictionary=Object.assign({},this.morphTargetDictionary)),this.morphTargetInfluences!==void 0&&(n.morphTargetInfluences=this.morphTargetInfluences.slice()),this.isInstancedMesh&&(n.type="InstancedMesh",n.count=this.count,n.instanceMatrix=this.instanceMatrix.toJSON(),this.instanceColor!==null&&(n.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(n.type="BatchedMesh",n.perObjectFrustumCulled=this.perObjectFrustumCulled,n.sortObjects=this.sortObjects,n.drawRanges=this._drawRanges,n.reservedRanges=this._reservedRanges,n.geometryInfo=this._geometryInfo.map(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(e),n.indirectTexture=this._indirectTexture.toJSON(e),this._colorsTexture!==null&&(n.colorsTexture=this._colorsTexture.toJSON(e)),this.boundingSphere!==null&&(n.boundingSphere=this.boundingSphere.toJSON()),this.boundingBox!==null&&(n.boundingBox=this.boundingBox.toJSON()));function s(o,c){return o[c.uuid]===void 0&&(o[c.uuid]=c.toJSON(e)),c.uuid}if(this.isScene)this.background&&(this.background.isColor?n.background=this.background.toJSON():this.background.isTexture&&(n.background=this.background.toJSON(e).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(n.environment=this.environment.toJSON(e).uuid);else if(this.isMesh||this.isLine||this.isPoints){n.geometry=s(e.geometries,this.geometry);const 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(e.shapes,u)}else s(e.shapes,c)}}if(this.isSkinnedMesh&&(n.bindMode=this.bindMode,n.bindMatrix=this.bindMatrix.toArray(),this.skeleton!==void 0&&(s(e.skeletons,this.skeleton),n.skeleton=this.skeleton.uuid)),this.material!==void 0)if(Array.isArray(this.material)){const o=[];for(let c=0,l=this.material.length;c<l;c++)o.push(s(e.materials,this.material[c]));n.material=o}else n.material=s(e.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(e).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(e.animations,c))}}if(t){const o=a(e.geometries),c=a(e.materials),l=a(e.textures),h=a(e.images),u=a(e.shapes),d=a(e.skeletons),f=a(e.animations),p=a(e.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 a(o){const c=[];for(const l in o){const h=o[l];delete h.metadata,c.push(h)}return c}}clone(e){return new this.constructor().copy(this,e)}copy(e,t=!0){if(this.name=e.name,this.up.copy(e.up),this.position.copy(e.position),this.rotation.order=e.rotation.order,this.quaternion.copy(e.quaternion),this.scale.copy(e.scale),this.pivot=e.pivot!==null?e.pivot.clone():null,this.matrix.copy(e.matrix),this.matrixWorld.copy(e.matrixWorld),this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrixWorldAutoUpdate=e.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=e.matrixWorldNeedsUpdate,this.layers.mask=e.layers.mask,this.visible=e.visible,this.castShadow=e.castShadow,this.receiveShadow=e.receiveShadow,this.frustumCulled=e.frustumCulled,this.renderOrder=e.renderOrder,this.static=e.static,this.animations=e.animations.slice(),this.userData=JSON.parse(JSON.stringify(e.userData)),t===!0)for(let i=0;i<e.children.length;i++){const n=e.children[i];this.add(n.clone())}return this}}Ut.DEFAULT_UP=new R(0,1,0);Ut.DEFAULT_MATRIX_AUTO_UPDATE=!0;Ut.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;class Dt extends Ut{constructor(){super(),this.isGroup=!0,this.type="Group"}}const ZM={type:"move"};class xh{constructor(){this._targetRay=null,this._grip=null,this._hand=null}getHandSpace(){return this._hand===null&&(this._hand=new Dt,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 Dt,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 Dt,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(e){return this._targetRay!==null&&this._targetRay.dispatchEvent(e),this._grip!==null&&this._grip.dispatchEvent(e),this._hand!==null&&this._hand.dispatchEvent(e),this}connect(e){if(e&&e.hand){const t=this._hand;if(t)for(const i of e.hand.values())this._getHandJoint(t,i)}return this.dispatchEvent({type:"connected",data:e}),this}disconnect(e){return this.dispatchEvent({type:"disconnected",data:e}),this._targetRay!==null&&(this._targetRay.visible=!1),this._grip!==null&&(this._grip.visible=!1),this._hand!==null&&(this._hand.visible=!1),this}update(e,t,i){let n=null,s=null,a=null;const o=this._targetRay,c=this._grip,l=this._hand;if(e&&t.session.visibilityState!=="visible-blurred"){if(l&&e.hand){a=!0;for(const v of e.hand.values()){const m=t.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:e.handedness,target:this})):!l.inputState.pinching&&d<=f-p&&(l.inputState.pinching=!0,this.dispatchEvent({type:"pinchstart",handedness:e.handedness,target:this}))}else c!==null&&e.gripSpace&&(s=t.getPose(e.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:e,target:this})));o!==null&&(n=t.getPose(e.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(ZM)))}return o!==null&&(o.visible=n!==null),c!==null&&(c.visible=s!==null),l!==null&&(l.visible=a!==null),this}_getHandJoint(e,t){if(e.joints[t.jointName]===void 0){const i=new Dt;i.matrixAutoUpdate=!1,i.visible=!1,e.joints[t.jointName]=i,e.add(i)}return e.joints[t.jointName]}}const i1={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},ks={h:0,s:0,l:0},dc={h:0,s:0,l:0};function yh(r,e,t){return t<0&&(t+=1),t>1&&(t-=1),t<1/6?r+(e-r)*6*t:t<1/2?e:t<2/3?r+(e-r)*6*(2/3-t):r}class se{constructor(e,t,i){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(e,t,i)}set(e,t,i){if(t===void 0&&i===void 0){const n=e;n&&n.isColor?this.copy(n):typeof n=="number"?this.setHex(n):typeof n=="string"&&this.setStyle(n)}else this.setRGB(e,t,i);return this}setScalar(e){return this.r=e,this.g=e,this.b=e,this}setHex(e,t=Vi){return e=Math.floor(e),this.r=(e>>16&255)/255,this.g=(e>>8&255)/255,this.b=(e&255)/255,at.colorSpaceToWorking(this,t),this}setRGB(e,t,i,n=at.workingColorSpace){return this.r=e,this.g=t,this.b=i,at.colorSpaceToWorking(this,n),this}setHSL(e,t,i,n=at.workingColorSpace){if(e=b0(e,1),t=et(t,0,1),i=et(i,0,1),t===0)this.r=this.g=this.b=i;else{const s=i<=.5?i*(1+t):i+t-i*t,a=2*i-s;this.r=yh(a,s,e+1/3),this.g=yh(a,s,e),this.b=yh(a,s,e-1/3)}return at.colorSpaceToWorking(this,n),this}setStyle(e,t=Vi){function i(s){s!==void 0&&parseFloat(s)<1&&Re("Color: Alpha component of "+e+" will be ignored.")}let n;if(n=/^(\w+)\(([^\)]*)\)/.exec(e)){let s;const a=n[1],o=n[2];switch(a){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,t);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,t);break;case"hsl":case"hsla":if(s=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return i(s[4]),this.setHSL(parseFloat(s[1])/360,parseFloat(s[2])/100,parseFloat(s[3])/100,t);break;default:Re("Color: Unknown color model "+e)}}else if(n=/^\#([A-Fa-f\d]+)$/.exec(e)){const s=n[1],a=s.length;if(a===3)return this.setRGB(parseInt(s.charAt(0),16)/15,parseInt(s.charAt(1),16)/15,parseInt(s.charAt(2),16)/15,t);if(a===6)return this.setHex(parseInt(s,16),t);Re("Color: Invalid hex color "+e)}else if(e&&e.length>0)return this.setColorName(e,t);return this}setColorName(e,t=Vi){const i=i1[e.toLowerCase()];return i!==void 0?this.setHex(i,t):Re("Color: Unknown color "+e),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(e){return this.r=e.r,this.g=e.g,this.b=e.b,this}copySRGBToLinear(e){return this.r=Ts(e.r),this.g=Ts(e.g),this.b=Ts(e.b),this}copyLinearToSRGB(e){return this.r=Ar(e.r),this.g=Ar(e.g),this.b=Ar(e.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(e=Vi){return at.workingToColorSpace(Di.copy(this),e),Math.round(et(Di.r*255,0,255))*65536+Math.round(et(Di.g*255,0,255))*256+Math.round(et(Di.b*255,0,255))}getHexString(e=Vi){return("000000"+this.getHex(e).toString(16)).slice(-6)}getHSL(e,t=at.workingColorSpace){at.workingToColorSpace(Di.copy(this),t);const i=Di.r,n=Di.g,s=Di.b,a=Math.max(i,n,s),o=Math.min(i,n,s);let c,l;const h=(o+a)/2;if(o===a)c=0,l=0;else{const u=a-o;switch(l=h<=.5?u/(a+o):u/(2-a-o),a){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 e.h=c,e.s=l,e.l=h,e}getRGB(e,t=at.workingColorSpace){return at.workingToColorSpace(Di.copy(this),t),e.r=Di.r,e.g=Di.g,e.b=Di.b,e}getStyle(e=Vi){at.workingToColorSpace(Di.copy(this),e);const t=Di.r,i=Di.g,n=Di.b;return e!==Vi?`color(${e} ${t.toFixed(3)} ${i.toFixed(3)} ${n.toFixed(3)})`:`rgb(${Math.round(t*255)},${Math.round(i*255)},${Math.round(n*255)})`}offsetHSL(e,t,i){return this.getHSL(ks),this.setHSL(ks.h+e,ks.s+t,ks.l+i)}add(e){return this.r+=e.r,this.g+=e.g,this.b+=e.b,this}addColors(e,t){return this.r=e.r+t.r,this.g=e.g+t.g,this.b=e.b+t.b,this}addScalar(e){return this.r+=e,this.g+=e,this.b+=e,this}sub(e){return this.r=Math.max(0,this.r-e.r),this.g=Math.max(0,this.g-e.g),this.b=Math.max(0,this.b-e.b),this}multiply(e){return this.r*=e.r,this.g*=e.g,this.b*=e.b,this}multiplyScalar(e){return this.r*=e,this.g*=e,this.b*=e,this}lerp(e,t){return this.r+=(e.r-this.r)*t,this.g+=(e.g-this.g)*t,this.b+=(e.b-this.b)*t,this}lerpColors(e,t,i){return this.r=e.r+(t.r-e.r)*i,this.g=e.g+(t.g-e.g)*i,this.b=e.b+(t.b-e.b)*i,this}lerpHSL(e,t){this.getHSL(ks),e.getHSL(dc);const i=Do(ks.h,dc.h,t),n=Do(ks.s,dc.s,t),s=Do(ks.l,dc.l,t);return this.setHSL(i,n,s),this}setFromVector3(e){return this.r=e.x,this.g=e.y,this.b=e.z,this}applyMatrix3(e){const t=this.r,i=this.g,n=this.b,s=e.elements;return this.r=s[0]*t+s[3]*i+s[6]*n,this.g=s[1]*t+s[4]*i+s[7]*n,this.b=s[2]*t+s[5]*i+s[8]*n,this}equals(e){return e.r===this.r&&e.g===this.g&&e.b===this.b}fromArray(e,t=0){return this.r=e[t],this.g=e[t+1],this.b=e[t+2],this}toArray(e=[],t=0){return e[t]=this.r,e[t+1]=this.g,e[t+2]=this.b,e}fromBufferAttribute(e,t){return this.r=e.getX(t),this.g=e.getY(t),this.b=e.getZ(t),this}toJSON(){return this.getHex()}*[Symbol.iterator](){yield this.r,yield this.g,yield this.b}}const Di=new se;se.NAMES=i1;class w0{constructor(e,t=1,i=1e3){this.isFog=!0,this.name="",this.color=new se(e),this.near=t,this.far=i}clone(){return new w0(this.color,this.near,this.far)}toJSON(){return{type:"Fog",name:this.name,color:this.color.getHex(),near:this.near,far:this.far}}}class Is extends Ut{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 Ds,this.environmentIntensity=1,this.environmentRotation=new Ds,this.overrideMaterial=null,typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}copy(e,t){return super.copy(e,t),e.background!==null&&(this.background=e.background.clone()),e.environment!==null&&(this.environment=e.environment.clone()),e.fog!==null&&(this.fog=e.fog.clone()),this.backgroundBlurriness=e.backgroundBlurriness,this.backgroundIntensity=e.backgroundIntensity,this.backgroundRotation.copy(e.backgroundRotation),this.environmentIntensity=e.environmentIntensity,this.environmentRotation.copy(e.environmentRotation),e.overrideMaterial!==null&&(this.overrideMaterial=e.overrideMaterial.clone()),this.matrixAutoUpdate=e.matrixAutoUpdate,this}toJSON(e){const t=super.toJSON(e);return this.fog!==null&&(t.object.fog=this.fog.toJSON()),this.backgroundBlurriness>0&&(t.object.backgroundBlurriness=this.backgroundBlurriness),this.backgroundIntensity!==1&&(t.object.backgroundIntensity=this.backgroundIntensity),t.object.backgroundRotation=this.backgroundRotation.toArray(),this.environmentIntensity!==1&&(t.object.environmentIntensity=this.environmentIntensity),t.object.environmentRotation=this.environmentRotation.toArray(),t}}const wn=new R,hs=new R,bh=new R,us=new R,Ja=new R,ja=new R,tp=new R,_h=new R,Sh=new R,wh=new R,Eh=new it,Ah=new it,Th=new it;class yn{constructor(e=new R,t=new R,i=new R){this.a=e,this.b=t,this.c=i}static getNormal(e,t,i,n){n.subVectors(i,t),wn.subVectors(e,t),n.cross(wn);const s=n.lengthSq();return s>0?n.multiplyScalar(1/Math.sqrt(s)):n.set(0,0,0)}static getBarycoord(e,t,i,n,s){wn.subVectors(n,t),hs.subVectors(i,t),bh.subVectors(e,t);const a=wn.dot(wn),o=wn.dot(hs),c=wn.dot(bh),l=hs.dot(hs),h=hs.dot(bh),u=a*l-o*o;if(u===0)return s.set(0,0,0),null;const d=1/u,f=(l*c-o*h)*d,p=(a*h-o*c)*d;return s.set(1-f-p,p,f)}static containsPoint(e,t,i,n){return this.getBarycoord(e,t,i,n,us)===null?!1:us.x>=0&&us.y>=0&&us.x+us.y<=1}static getInterpolation(e,t,i,n,s,a,o,c){return this.getBarycoord(e,t,i,n,us)===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,us.x),c.addScaledVector(a,us.y),c.addScaledVector(o,us.z),c)}static getInterpolatedAttribute(e,t,i,n,s,a){return Eh.setScalar(0),Ah.setScalar(0),Th.setScalar(0),Eh.fromBufferAttribute(e,t),Ah.fromBufferAttribute(e,i),Th.fromBufferAttribute(e,n),a.setScalar(0),a.addScaledVector(Eh,s.x),a.addScaledVector(Ah,s.y),a.addScaledVector(Th,s.z),a}static isFrontFacing(e,t,i,n){return wn.subVectors(i,t),hs.subVectors(e,t),wn.cross(hs).dot(n)<0}set(e,t,i){return this.a.copy(e),this.b.copy(t),this.c.copy(i),this}setFromPointsAndIndices(e,t,i,n){return this.a.copy(e[t]),this.b.copy(e[i]),this.c.copy(e[n]),this}setFromAttributeAndIndices(e,t,i,n){return this.a.fromBufferAttribute(e,t),this.b.fromBufferAttribute(e,i),this.c.fromBufferAttribute(e,n),this}clone(){return new this.constructor().copy(this)}copy(e){return this.a.copy(e.a),this.b.copy(e.b),this.c.copy(e.c),this}getArea(){return wn.subVectors(this.c,this.b),hs.subVectors(this.a,this.b),wn.cross(hs).length()*.5}getMidpoint(e){return e.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(e){return yn.getNormal(this.a,this.b,this.c,e)}getPlane(e){return e.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(e,t){return yn.getBarycoord(e,this.a,this.b,this.c,t)}getInterpolation(e,t,i,n,s){return yn.getInterpolation(e,this.a,this.b,this.c,t,i,n,s)}containsPoint(e){return yn.containsPoint(e,this.a,this.b,this.c)}isFrontFacing(e){return yn.isFrontFacing(this.a,this.b,this.c,e)}intersectsBox(e){return e.intersectsTriangle(this)}closestPointToPoint(e,t){const i=this.a,n=this.b,s=this.c;let a,o;Ja.subVectors(n,i),ja.subVectors(s,i),_h.subVectors(e,i);const c=Ja.dot(_h),l=ja.dot(_h);if(c<=0&&l<=0)return t.copy(i);Sh.subVectors(e,n);const h=Ja.dot(Sh),u=ja.dot(Sh);if(h>=0&&u<=h)return t.copy(n);const d=c*u-h*l;if(d<=0&&c>=0&&h<=0)return a=c/(c-h),t.copy(i).addScaledVector(Ja,a);wh.subVectors(e,s);const f=Ja.dot(wh),p=ja.dot(wh);if(p>=0&&f<=p)return t.copy(s);const v=f*l-c*p;if(v<=0&&l>=0&&p<=0)return o=l/(l-p),t.copy(i).addScaledVector(ja,o);const m=h*p-f*u;if(m<=0&&u-h>=0&&f-p>=0)return tp.subVectors(s,n),o=(u-h)/(u-h+(f-p)),t.copy(n).addScaledVector(tp,o);const g=1/(m+v+d);return a=v*g,o=d*g,t.copy(i).addScaledVector(Ja,a).addScaledVector(ja,o)}equals(e){return e.a.equals(this.a)&&e.b.equals(this.b)&&e.c.equals(this.c)}}class Wi{constructor(e=new R(1/0,1/0,1/0),t=new R(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=e,this.max=t}set(e,t){return this.min.copy(e),this.max.copy(t),this}setFromArray(e){this.makeEmpty();for(let t=0,i=e.length;t<i;t+=3)this.expandByPoint(En.fromArray(e,t));return this}setFromBufferAttribute(e){this.makeEmpty();for(let t=0,i=e.count;t<i;t++)this.expandByPoint(En.fromBufferAttribute(e,t));return this}setFromPoints(e){this.makeEmpty();for(let t=0,i=e.length;t<i;t++)this.expandByPoint(e[t]);return this}setFromCenterAndSize(e,t){const i=En.copy(t).multiplyScalar(.5);return this.min.copy(e).sub(i),this.max.copy(e).add(i),this}setFromObject(e,t=!1){return this.makeEmpty(),this.expandByObject(e,t)}clone(){return new this.constructor().copy(this)}copy(e){return this.min.copy(e.min),this.max.copy(e.max),this}makeEmpty(){return this.min.x=this.min.y=this.min.z=1/0,this.max.x=this.max.y=this.max.z=-1/0,this}isEmpty(){return this.max.x<this.min.x||this.max.y<this.min.y||this.max.z<this.min.z}getCenter(e){return this.isEmpty()?e.set(0,0,0):e.addVectors(this.min,this.max).multiplyScalar(.5)}getSize(e){return this.isEmpty()?e.set(0,0,0):e.subVectors(this.max,this.min)}expandByPoint(e){return this.min.min(e),this.max.max(e),this}expandByVector(e){return this.min.sub(e),this.max.add(e),this}expandByScalar(e){return this.min.addScalar(-e),this.max.addScalar(e),this}expandByObject(e,t=!1){e.updateWorldMatrix(!1,!1);const i=e.geometry;if(i!==void 0){const s=i.getAttribute("position");if(t===!0&&s!==void 0&&e.isInstancedMesh!==!0)for(let a=0,o=s.count;a<o;a++)e.isMesh===!0?e.getVertexPosition(a,En):En.fromBufferAttribute(s,a),En.applyMatrix4(e.matrixWorld),this.expandByPoint(En);else e.boundingBox!==void 0?(e.boundingBox===null&&e.computeBoundingBox(),fc.copy(e.boundingBox)):(i.boundingBox===null&&i.computeBoundingBox(),fc.copy(i.boundingBox)),fc.applyMatrix4(e.matrixWorld),this.union(fc)}const n=e.children;for(let s=0,a=n.length;s<a;s++)this.expandByObject(n[s],t);return this}containsPoint(e){return e.x>=this.min.x&&e.x<=this.max.x&&e.y>=this.min.y&&e.y<=this.max.y&&e.z>=this.min.z&&e.z<=this.max.z}containsBox(e){return this.min.x<=e.min.x&&e.max.x<=this.max.x&&this.min.y<=e.min.y&&e.max.y<=this.max.y&&this.min.z<=e.min.z&&e.max.z<=this.max.z}getParameter(e,t){return t.set((e.x-this.min.x)/(this.max.x-this.min.x),(e.y-this.min.y)/(this.max.y-this.min.y),(e.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(e){return e.max.x>=this.min.x&&e.min.x<=this.max.x&&e.max.y>=this.min.y&&e.min.y<=this.max.y&&e.max.z>=this.min.z&&e.min.z<=this.max.z}intersectsSphere(e){return this.clampPoint(e.center,En),En.distanceToSquared(e.center)<=e.radius*e.radius}intersectsPlane(e){let t,i;return e.normal.x>0?(t=e.normal.x*this.min.x,i=e.normal.x*this.max.x):(t=e.normal.x*this.max.x,i=e.normal.x*this.min.x),e.normal.y>0?(t+=e.normal.y*this.min.y,i+=e.normal.y*this.max.y):(t+=e.normal.y*this.max.y,i+=e.normal.y*this.min.y),e.normal.z>0?(t+=e.normal.z*this.min.z,i+=e.normal.z*this.max.z):(t+=e.normal.z*this.max.z,i+=e.normal.z*this.min.z),t<=-e.constant&&i>=-e.constant}intersectsTriangle(e){if(this.isEmpty())return!1;this.getCenter(Kr),pc.subVectors(this.max,Kr),Qa.subVectors(e.a,Kr),er.subVectors(e.b,Kr),tr.subVectors(e.c,Kr),zs.subVectors(er,Qa),Bs.subVectors(tr,er),ua.subVectors(Qa,tr);let t=[0,-zs.z,zs.y,0,-Bs.z,Bs.y,0,-ua.z,ua.y,zs.z,0,-zs.x,Bs.z,0,-Bs.x,ua.z,0,-ua.x,-zs.y,zs.x,0,-Bs.y,Bs.x,0,-ua.y,ua.x,0];return!Rh(t,Qa,er,tr,pc)||(t=[1,0,0,0,1,0,0,0,1],!Rh(t,Qa,er,tr,pc))?!1:(mc.crossVectors(zs,Bs),t=[mc.x,mc.y,mc.z],Rh(t,Qa,er,tr,pc))}clampPoint(e,t){return t.copy(e).clamp(this.min,this.max)}distanceToPoint(e){return this.clampPoint(e,En).distanceTo(e)}getBoundingSphere(e){return this.isEmpty()?e.makeEmpty():(this.getCenter(e.center),e.radius=this.getSize(En).length()*.5),e}intersect(e){return this.min.max(e.min),this.max.min(e.max),this.isEmpty()&&this.makeEmpty(),this}union(e){return this.min.min(e.min),this.max.max(e.max),this}applyMatrix4(e){return this.isEmpty()?this:(ds[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(e),ds[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(e),ds[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(e),ds[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(e),ds[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(e),ds[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(e),ds[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(e),ds[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(e),this.setFromPoints(ds),this)}translate(e){return this.min.add(e),this.max.add(e),this}equals(e){return e.min.equals(this.min)&&e.max.equals(this.max)}toJSON(){return{min:this.min.toArray(),max:this.max.toArray()}}fromJSON(e){return this.min.fromArray(e.min),this.max.fromArray(e.max),this}}const ds=[new R,new R,new R,new R,new R,new R,new R,new R],En=new R,fc=new Wi,Qa=new R,er=new R,tr=new R,zs=new R,Bs=new R,ua=new R,Kr=new R,pc=new R,mc=new R,da=new R;function Rh(r,e,t,i,n){for(let s=0,a=r.length-3;s<=a;s+=3){da.fromArray(r,s);const o=n.x*Math.abs(da.x)+n.y*Math.abs(da.y)+n.z*Math.abs(da.z),c=e.dot(da),l=t.dot(da),h=i.dot(da);if(Math.max(-Math.max(c,l,h),Math.min(c,l,h))>o)return!1}return!0}const ys=JM();function JM(){const r=new ArrayBuffer(4),e=new Float32Array(r),t=new Uint32Array(r),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),a=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)a[c]=c<<23;a[31]=1199570944,a[32]=2147483648;for(let c=33;c<63;++c)a[c]=2147483648+(c-32<<23);a[63]=3347054592;for(let c=1;c<64;++c)c!==32&&(o[c]=1024);return{floatView:e,uint32View:t,baseTable:i,shiftTable:n,mantissaTable:s,exponentTable:a,offsetTable:o}}function jM(r){Math.abs(r)>65504&&Re("DataUtils.toHalfFloat(): Value out of range."),r=et(r,-65504,65504),ys.floatView[0]=r;const e=ys.uint32View[0],t=e>>23&511;return ys.baseTable[t]+((e&8388607)>>ys.shiftTable[t])}function QM(r){const e=r>>10;return ys.uint32View[0]=ys.mantissaTable[ys.offsetTable[e]+(r&1023)]+ys.exponentTable[e],ys.floatView[0]}class kn{static toHalfFloat(e){return jM(e)}static fromHalfFloat(e){return QM(e)}}const ci=new R,gc=new xe;let ex=0;class tt extends oa{constructor(e,t,i=!1){if(super(),Array.isArray(e))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,Object.defineProperty(this,"id",{value:ex++}),this.name="",this.array=e,this.itemSize=t,this.count=e!==void 0?e.length/t:0,this.normalized=i,this.usage=yd,this.updateRanges=[],this.gpuType=Oi,this.version=0}onUploadCallback(){}set needsUpdate(e){e===!0&&this.version++}setUsage(e){return this.usage=e,this}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}copy(e){return this.name=e.name,this.array=new e.array.constructor(e.array),this.itemSize=e.itemSize,this.count=e.count,this.normalized=e.normalized,this.usage=e.usage,this.gpuType=e.gpuType,this}copyAt(e,t,i){e*=this.itemSize,i*=t.itemSize;for(let n=0,s=this.itemSize;n<s;n++)this.array[e+n]=t.array[i+n];return this}copyArray(e){return this.array.set(e),this}applyMatrix3(e){if(this.itemSize===2)for(let t=0,i=this.count;t<i;t++)gc.fromBufferAttribute(this,t),gc.applyMatrix3(e),this.setXY(t,gc.x,gc.y);else if(this.itemSize===3)for(let t=0,i=this.count;t<i;t++)ci.fromBufferAttribute(this,t),ci.applyMatrix3(e),this.setXYZ(t,ci.x,ci.y,ci.z);return this}applyMatrix4(e){for(let t=0,i=this.count;t<i;t++)ci.fromBufferAttribute(this,t),ci.applyMatrix4(e),this.setXYZ(t,ci.x,ci.y,ci.z);return this}applyNormalMatrix(e){for(let t=0,i=this.count;t<i;t++)ci.fromBufferAttribute(this,t),ci.applyNormalMatrix(e),this.setXYZ(t,ci.x,ci.y,ci.z);return this}transformDirection(e){for(let t=0,i=this.count;t<i;t++)ci.fromBufferAttribute(this,t),ci.transformDirection(e),this.setXYZ(t,ci.x,ci.y,ci.z);return this}set(e,t=0){return this.array.set(e,t),this}getComponent(e,t){let i=this.array[e*this.itemSize+t];return this.normalized&&(i=Nn(i,this.array)),i}setComponent(e,t,i){return this.normalized&&(i=bt(i,this.array)),this.array[e*this.itemSize+t]=i,this}getX(e){let t=this.array[e*this.itemSize];return this.normalized&&(t=Nn(t,this.array)),t}setX(e,t){return this.normalized&&(t=bt(t,this.array)),this.array[e*this.itemSize]=t,this}getY(e){let t=this.array[e*this.itemSize+1];return this.normalized&&(t=Nn(t,this.array)),t}setY(e,t){return this.normalized&&(t=bt(t,this.array)),this.array[e*this.itemSize+1]=t,this}getZ(e){let t=this.array[e*this.itemSize+2];return this.normalized&&(t=Nn(t,this.array)),t}setZ(e,t){return this.normalized&&(t=bt(t,this.array)),this.array[e*this.itemSize+2]=t,this}getW(e){let t=this.array[e*this.itemSize+3];return this.normalized&&(t=Nn(t,this.array)),t}setW(e,t){return this.normalized&&(t=bt(t,this.array)),this.array[e*this.itemSize+3]=t,this}setXY(e,t,i){return e*=this.itemSize,this.normalized&&(t=bt(t,this.array),i=bt(i,this.array)),this.array[e+0]=t,this.array[e+1]=i,this}setXYZ(e,t,i,n){return e*=this.itemSize,this.normalized&&(t=bt(t,this.array),i=bt(i,this.array),n=bt(n,this.array)),this.array[e+0]=t,this.array[e+1]=i,this.array[e+2]=n,this}setXYZW(e,t,i,n,s){return e*=this.itemSize,this.normalized&&(t=bt(t,this.array),i=bt(i,this.array),n=bt(n,this.array),s=bt(s,this.array)),this.array[e+0]=t,this.array[e+1]=i,this.array[e+2]=n,this.array[e+3]=s,this}onUpload(e){return this.onUploadCallback=e,this}clone(){return new this.constructor(this.array,this.itemSize).copy(this)}toJSON(){const e={itemSize:this.itemSize,type:this.array.constructor.name,array:Array.from(this.array),normalized:this.normalized};return this.name!==""&&(e.name=this.name),this.usage!==yd&&(e.usage=this.usage),e}dispose(){this.dispatchEvent({type:"dispose"})}}class n1 extends tt{constructor(e,t,i){super(new Uint16Array(e),t,i)}}class E0 extends tt{constructor(e,t,i){super(new Uint32Array(e),t,i)}}class ut extends tt{constructor(e,t,i){super(new Float32Array(e),t,i)}}const tx=new Wi,Zr=new R,Dh=new R;class Cs{constructor(e=new R,t=-1){this.isSphere=!0,this.center=e,this.radius=t}set(e,t){return this.center.copy(e),this.radius=t,this}setFromPoints(e,t){const i=this.center;t!==void 0?i.copy(t):tx.setFromPoints(e).getCenter(i);let n=0;for(let s=0,a=e.length;s<a;s++)n=Math.max(n,i.distanceToSquared(e[s]));return this.radius=Math.sqrt(n),this}copy(e){return this.center.copy(e.center),this.radius=e.radius,this}isEmpty(){return this.radius<0}makeEmpty(){return this.center.set(0,0,0),this.radius=-1,this}containsPoint(e){return e.distanceToSquared(this.center)<=this.radius*this.radius}distanceToPoint(e){return e.distanceTo(this.center)-this.radius}intersectsSphere(e){const t=this.radius+e.radius;return e.center.distanceToSquared(this.center)<=t*t}intersectsBox(e){return e.intersectsSphere(this)}intersectsPlane(e){return Math.abs(e.distanceToPoint(this.center))<=this.radius}clampPoint(e,t){const i=this.center.distanceToSquared(e);return t.copy(e),i>this.radius*this.radius&&(t.sub(this.center).normalize(),t.multiplyScalar(this.radius).add(this.center)),t}getBoundingBox(e){return this.isEmpty()?(e.makeEmpty(),e):(e.set(this.center,this.center),e.expandByScalar(this.radius),e)}applyMatrix4(e){return this.center.applyMatrix4(e),this.radius=this.radius*e.getMaxScaleOnAxis(),this}translate(e){return this.center.add(e),this}expandByPoint(e){if(this.isEmpty())return this.center.copy(e),this.radius=0,this;Zr.subVectors(e,this.center);const t=Zr.lengthSq();if(t>this.radius*this.radius){const i=Math.sqrt(t),n=(i-this.radius)*.5;this.center.addScaledVector(Zr,n/i),this.radius+=n}return this}union(e){return e.isEmpty()?this:this.isEmpty()?(this.copy(e),this):(this.center.equals(e.center)===!0?this.radius=Math.max(this.radius,e.radius):(Dh.subVectors(e.center,this.center).setLength(e.radius),this.expandByPoint(Zr.copy(e.center).add(Dh)),this.expandByPoint(Zr.copy(e.center).sub(Dh))),this)}equals(e){return e.center.equals(this.center)&&e.radius===this.radius}clone(){return new this.constructor().copy(this)}toJSON(){return{radius:this.radius,center:this.center.toArray()}}fromJSON(e){return this.radius=e.radius,this.center.fromArray(e.center),this}}let ix=0;const mn=new Ze,Ih=new Ut,ir=new R,sn=new Wi,Jr=new Wi,vi=new R;class ot extends oa{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:ix++}),this.uuid=Un(),this.name="",this.type="BufferGeometry",this.index=null,this.indirect=null,this.indirectOffset=0,this.attributes={},this.morphAttributes={},this.morphTargetsRelative=!1,this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.drawRange={start:0,count:1/0},this.userData={},this._transformed=!1}getIndex(){return this.index}setIndex(e){return Array.isArray(e)?this.index=new(MM(e)?E0:n1)(e,1):this.index=e,this}setIndirect(e,t=0){return this.indirect=e,this.indirectOffset=t,this}getIndirect(){return this.indirect}getAttribute(e){return this.attributes[e]}setAttribute(e,t){return this.attributes[e]=t,this}deleteAttribute(e){return delete this.attributes[e],this}hasAttribute(e){return this.attributes[e]!==void 0}addGroup(e,t,i=0){this.groups.push({start:e,count:t,materialIndex:i})}clearGroups(){this.groups=[]}setDrawRange(e,t){this.drawRange.start=e,this.drawRange.count=t}applyMatrix4(e){const t=this.attributes.position;t!==void 0&&(t.applyMatrix4(e),t.needsUpdate=!0);const i=this.attributes.normal;if(i!==void 0){const s=new Ye().getNormalMatrix(e);i.applyNormalMatrix(s),i.needsUpdate=!0}const n=this.attributes.tangent;return n!==void 0&&(n.transformDirection(e),n.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this._transformed=!0,this}applyQuaternion(e){return mn.makeRotationFromQuaternion(e),this.applyMatrix4(mn),this}rotateX(e){return mn.makeRotationX(e),this.applyMatrix4(mn),this}rotateY(e){return mn.makeRotationY(e),this.applyMatrix4(mn),this}rotateZ(e){return mn.makeRotationZ(e),this.applyMatrix4(mn),this}translate(e,t,i){return mn.makeTranslation(e,t,i),this.applyMatrix4(mn),this}scale(e,t,i){return mn.makeScale(e,t,i),this.applyMatrix4(mn),this}lookAt(e){return Ih.lookAt(e),Ih.updateMatrix(),this.applyMatrix4(Ih.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(ir).negate(),this.translate(ir.x,ir.y,ir.z),this}setFromPoints(e){const t=this.getAttribute("position");if(t===void 0){const i=[];for(let n=0,s=e.length;n<s;n++){const a=e[n];i.push(a.x,a.y,a.z||0)}this.setAttribute("position",new ut(i,3))}else{const i=Math.min(e.length,t.count);for(let n=0;n<i;n++){const s=e[n];t.setXYZ(n,s.x,s.y,s.z||0)}e.length>t.count&&Re("BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry."),t.needsUpdate=!0}return this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new Wi);const e=this.attributes.position,t=this.morphAttributes.position;if(e&&e.isGLBufferAttribute){Ge("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(e!==void 0){if(this.boundingBox.setFromBufferAttribute(e),t)for(let i=0,n=t.length;i<n;i++){const s=t[i];sn.setFromBufferAttribute(s),this.morphTargetsRelative?(vi.addVectors(this.boundingBox.min,sn.min),this.boundingBox.expandByPoint(vi),vi.addVectors(this.boundingBox.max,sn.max),this.boundingBox.expandByPoint(vi)):(this.boundingBox.expandByPoint(sn.min),this.boundingBox.expandByPoint(sn.max))}}else this.boundingBox.makeEmpty();(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z))&&Ge('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 Cs);const e=this.attributes.position,t=this.morphAttributes.position;if(e&&e.isGLBufferAttribute){Ge("BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.",this),this.boundingSphere.set(new R,1/0);return}if(e){const i=this.boundingSphere.center;if(sn.setFromBufferAttribute(e),t)for(let s=0,a=t.length;s<a;s++){const o=t[s];Jr.setFromBufferAttribute(o),this.morphTargetsRelative?(vi.addVectors(sn.min,Jr.min),sn.expandByPoint(vi),vi.addVectors(sn.max,Jr.max),sn.expandByPoint(vi)):(sn.expandByPoint(Jr.min),sn.expandByPoint(Jr.max))}sn.getCenter(i);let n=0;for(let s=0,a=e.count;s<a;s++)vi.fromBufferAttribute(e,s),n=Math.max(n,i.distanceToSquared(vi));if(t)for(let s=0,a=t.length;s<a;s++){const o=t[s],c=this.morphTargetsRelative;for(let l=0,h=o.count;l<h;l++)vi.fromBufferAttribute(o,l),c&&(ir.fromBufferAttribute(e,l),vi.add(ir)),n=Math.max(n,i.distanceToSquared(vi))}this.boundingSphere.radius=Math.sqrt(n),isNaN(this.boundingSphere.radius)&&Ge('BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',this)}}computeTangents(){const e=this.index,t=this.attributes;if(e===null||t.position===void 0||t.normal===void 0||t.uv===void 0){Ge("BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)");return}const i=t.position,n=t.normal,s=t.uv;let a=this.getAttribute("tangent");(a===void 0||a.count!==i.count)&&(a=new tt(new Float32Array(4*i.count),4),this.setAttribute("tangent",a));const o=[],c=[];for(let x=0;x<i.count;x++)o[x]=new R,c[x]=new R;const l=new R,h=new R,u=new R,d=new xe,f=new xe,p=new xe,v=new R,m=new R;function g(x,A,C){l.fromBufferAttribute(i,x),h.fromBufferAttribute(i,A),u.fromBufferAttribute(i,C),d.fromBufferAttribute(s,x),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[x].add(v),o[A].add(v),o[C].add(v),c[x].add(m),c[A].add(m),c[C].add(m))}let _=this.groups;_.length===0&&(_=[{start:0,count:e.count}]);for(let x=0,A=_.length;x<A;++x){const C=_[x],I=C.start,P=C.count;for(let V=I,X=I+P;V<X;V+=3)g(e.getX(V+0),e.getX(V+1),e.getX(V+2))}const b=new R,M=new R,S=new R,w=new R;function T(x){S.fromBufferAttribute(n,x),w.copy(S);const A=o[x];b.copy(A),b.sub(S.multiplyScalar(S.dot(A))).normalize(),M.crossVectors(w,A);const I=M.dot(c[x])<0?-1:1;a.setXYZW(x,b.x,b.y,b.z,I)}for(let x=0,A=_.length;x<A;++x){const C=_[x],I=C.start,P=C.count;for(let V=I,X=I+P;V<X;V+=3)T(e.getX(V+0)),T(e.getX(V+1)),T(e.getX(V+2))}this._transformed=!0}computeVertexNormals(){const e=this.index,t=this.getAttribute("position");if(t!==void 0){let i=this.getAttribute("normal");if(i===void 0||i.count!==t.count)i=new tt(new Float32Array(t.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,a=new R,o=new R,c=new R,l=new R,h=new R,u=new R;if(e)for(let d=0,f=e.count;d<f;d+=3){const p=e.getX(d+0),v=e.getX(d+1),m=e.getX(d+2);n.fromBufferAttribute(t,p),s.fromBufferAttribute(t,v),a.fromBufferAttribute(t,m),h.subVectors(a,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=t.count;d<f;d+=3)n.fromBufferAttribute(t,d+0),s.fromBufferAttribute(t,d+1),a.fromBufferAttribute(t,d+2),h.subVectors(a,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 e=this.attributes.normal;for(let t=0,i=e.count;t<i;t++)vi.fromBufferAttribute(e,t),vi.normalize(),e.setXYZ(t,vi.x,vi.y,vi.z)}toNonIndexed(){function e(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 tt(d,h,u)}if(this.index===null)return Re("BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."),this;const t=new ot,i=this.index.array,n=this.attributes;for(const o in n){const c=n[o],l=e(c,i);t.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=e(d,i);c.push(f)}t.morphAttributes[o]=c}t.morphTargetsRelative=this.morphTargetsRelative;const a=this.groups;for(let o=0,c=a.length;o<c;o++){const l=a[o];t.addGroup(l.start,l.count,l.materialIndex)}return t}toJSON(){const e={metadata:{version:4.7,type:"BufferGeometry",generator:"BufferGeometry.toJSON"}};if(e.uuid=this.uuid,e.type=this.parameters!==void 0&&this._transformed===!0?"BufferGeometry":this.type,this.name!==""&&(e.name=this.name),Object.keys(this.userData).length>0&&(e.userData=this.userData),this.parameters!==void 0&&this._transformed!==!0){const c=this.parameters;for(const l in c)c[l]!==void 0&&(e[l]=c[l]);return e}e.data={attributes:{}};const t=this.index;t!==null&&(e.data.index={type:t.array.constructor.name,array:Array.prototype.slice.call(t.array)});const i=this.attributes;for(const c in i){const l=i[c];e.data.attributes[c]=l.toJSON(e.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(e.data))}h.length>0&&(n[c]=h,s=!0)}s&&(e.data.morphAttributes=n,e.data.morphTargetsRelative=this.morphTargetsRelative);const a=this.groups;a.length>0&&(e.data.groups=JSON.parse(JSON.stringify(a)));const o=this.boundingSphere;return o!==null&&(e.data.boundingSphere=o.toJSON()),e}clone(){return new this.constructor().copy(this)}copy(e){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const t={};this.name=e.name;const i=e.index;i!==null&&this.setIndex(i.clone());const n=e.attributes;for(const l in n){const h=n[l];this.setAttribute(l,h.clone(t))}const s=e.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(t));this.morphAttributes[l]=h}this.morphTargetsRelative=e.morphTargetsRelative;const a=e.groups;for(let l=0,h=a.length;l<h;l++){const u=a[l];this.addGroup(u.start,u.count,u.materialIndex)}const o=e.boundingBox;o!==null&&(this.boundingBox=o.clone());const c=e.boundingSphere;return c!==null&&(this.boundingSphere=c.clone()),this.drawRange.start=e.drawRange.start,this.drawRange.count=e.drawRange.count,this.userData=e.userData,this._transformed=e._transformed,this}dispose(){this.dispatchEvent({type:"dispose"})}}class nx{constructor(e,t){this.isInterleavedBuffer=!0,this.array=e,this.stride=t,this.count=e!==void 0?e.length/t:0,this.usage=yd,this.updateRanges=[],this.version=0,this.uuid=Un()}onUploadCallback(){}set needsUpdate(e){e===!0&&this.version++}setUsage(e){return this.usage=e,this}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}copy(e){return this.array=new e.array.constructor(e.array),this.count=e.count,this.stride=e.stride,this.usage=e.usage,this}copyAt(e,t,i){e*=this.stride,i*=t.stride;for(let n=0,s=this.stride;n<s;n++)this.array[e+n]=t.array[i+n];return this}set(e,t=0){return this.array.set(e,t),this}clone(e){e.arrayBuffers===void 0&&(e.arrayBuffers={}),this.array.buffer._uuid===void 0&&(this.array.buffer._uuid=Un()),e.arrayBuffers[this.array.buffer._uuid]===void 0&&(e.arrayBuffers[this.array.buffer._uuid]=this.array.slice(0).buffer);const t=new this.array.constructor(e.arrayBuffers[this.array.buffer._uuid]),i=new this.constructor(t,this.stride);return i.setUsage(this.usage),i}onUpload(e){return this.onUploadCallback=e,this}toJSON(e){return e.arrayBuffers===void 0&&(e.arrayBuffers={}),this.array.buffer._uuid===void 0&&(this.array.buffer._uuid=Un()),e.arrayBuffers[this.array.buffer._uuid]===void 0&&(e.arrayBuffers[this.array.buffer._uuid]=Array.from(new Uint32Array(this.array.buffer))),{uuid:this.uuid,buffer:this.array.buffer._uuid,type:this.array.constructor.name,stride:this.stride}}}const Fi=new R;class Dl{constructor(e,t,i,n=!1){this.isInterleavedBufferAttribute=!0,this.name="",this.data=e,this.itemSize=t,this.offset=i,this.normalized=n}get count(){return this.data.count}get array(){return this.data.array}set needsUpdate(e){this.data.needsUpdate=e}applyMatrix4(e){for(let t=0,i=this.data.count;t<i;t++)Fi.fromBufferAttribute(this,t),Fi.applyMatrix4(e),this.setXYZ(t,Fi.x,Fi.y,Fi.z);return this}applyNormalMatrix(e){for(let t=0,i=this.count;t<i;t++)Fi.fromBufferAttribute(this,t),Fi.applyNormalMatrix(e),this.setXYZ(t,Fi.x,Fi.y,Fi.z);return this}transformDirection(e){for(let t=0,i=this.count;t<i;t++)Fi.fromBufferAttribute(this,t),Fi.transformDirection(e),this.setXYZ(t,Fi.x,Fi.y,Fi.z);return this}getComponent(e,t){let i=this.array[e*this.data.stride+this.offset+t];return this.normalized&&(i=Nn(i,this.array)),i}setComponent(e,t,i){return this.normalized&&(i=bt(i,this.array)),this.data.array[e*this.data.stride+this.offset+t]=i,this}setX(e,t){return this.normalized&&(t=bt(t,this.array)),this.data.array[e*this.data.stride+this.offset]=t,this}setY(e,t){return this.normalized&&(t=bt(t,this.array)),this.data.array[e*this.data.stride+this.offset+1]=t,this}setZ(e,t){return this.normalized&&(t=bt(t,this.array)),this.data.array[e*this.data.stride+this.offset+2]=t,this}setW(e,t){return this.normalized&&(t=bt(t,this.array)),this.data.array[e*this.data.stride+this.offset+3]=t,this}getX(e){let t=this.data.array[e*this.data.stride+this.offset];return this.normalized&&(t=Nn(t,this.array)),t}getY(e){let t=this.data.array[e*this.data.stride+this.offset+1];return this.normalized&&(t=Nn(t,this.array)),t}getZ(e){let t=this.data.array[e*this.data.stride+this.offset+2];return this.normalized&&(t=Nn(t,this.array)),t}getW(e){let t=this.data.array[e*this.data.stride+this.offset+3];return this.normalized&&(t=Nn(t,this.array)),t}setXY(e,t,i){return e=e*this.data.stride+this.offset,this.normalized&&(t=bt(t,this.array),i=bt(i,this.array)),this.data.array[e+0]=t,this.data.array[e+1]=i,this}setXYZ(e,t,i,n){return e=e*this.data.stride+this.offset,this.normalized&&(t=bt(t,this.array),i=bt(i,this.array),n=bt(n,this.array)),this.data.array[e+0]=t,this.data.array[e+1]=i,this.data.array[e+2]=n,this}setXYZW(e,t,i,n,s){return e=e*this.data.stride+this.offset,this.normalized&&(t=bt(t,this.array),i=bt(i,this.array),n=bt(n,this.array),s=bt(s,this.array)),this.data.array[e+0]=t,this.data.array[e+1]=i,this.data.array[e+2]=n,this.data.array[e+3]=s,this}clone(e){if(e===void 0){Rl("InterleavedBufferAttribute.clone(): Cloning an interleaved buffer attribute will de-interleave buffer data.");const t=[];for(let i=0;i<this.count;i++){const n=i*this.data.stride+this.offset;for(let s=0;s<this.itemSize;s++)t.push(this.data.array[n+s])}return new tt(new this.array.constructor(t),this.itemSize,this.normalized)}else return e.interleavedBuffers===void 0&&(e.interleavedBuffers={}),e.interleavedBuffers[this.data.uuid]===void 0&&(e.interleavedBuffers[this.data.uuid]=this.data.clone(e)),new Dl(e.interleavedBuffers[this.data.uuid],this.itemSize,this.offset,this.normalized)}toJSON(e){if(e===void 0){Rl("InterleavedBufferAttribute.toJSON(): Serializing an interleaved buffer attribute will de-interleave buffer data.");const t=[];for(let i=0;i<this.count;i++){const n=i*this.data.stride+this.offset;for(let s=0;s<this.itemSize;s++)t.push(this.data.array[n+s])}return{itemSize:this.itemSize,type:this.array.constructor.name,array:t,normalized:this.normalized}}else return e.interleavedBuffers===void 0&&(e.interleavedBuffers={}),e.interleavedBuffers[this.data.uuid]===void 0&&(e.interleavedBuffers[this.data.uuid]=this.data.toJSON(e)),{isInterleavedBufferAttribute:!0,itemSize:this.itemSize,data:this.data.uuid,offset:this.offset,normalized:this.normalized}}}let sx=0;class Ps extends oa{constructor(){super(),this.isMaterial=!0,Object.defineProperty(this,"id",{value:sx++}),this.uuid=Un(),this.name="",this.type="Material",this.blending=ia,this.side=sa,this.vertexColors=!1,this.opacity=1,this.transparent=!1,this.alphaHash=!1,this.blendSrc=Ou,this.blendDst=Ho,this.blendEquation=ba,this.blendSrcAlpha=null,this.blendDstAlpha=null,this.blendEquationAlpha=null,this.blendColor=new se(0,0,0),this.blendAlpha=0,this.depthFunc=Ur,this.depthTest=!0,this.depthWrite=!0,this.stencilWriteMask=255,this.stencilFunc=Gf,this.stencilRef=0,this.stencilFuncMask=255,this.stencilFail=Ya,this.stencilZFail=Ya,this.stencilZPass=Ya,this.stencilWrite=!1,this.clippingPlanes=null,this.clipIntersection=!1,this.clipShadows=!1,this.shadowSide=null,this.colorWrite=!0,this.precision=null,this.polygonOffset=!1,this.polygonOffsetFactor=0,this.polygonOffsetUnits=0,this.dithering=!1,this.alphaToCoverage=!1,this.premultipliedAlpha=!1,this.forceSinglePass=!1,this.allowOverride=!0,this.visible=!0,this.toneMapped=!0,this.userData={},this.version=0,this._alphaTest=0}get alphaTest(){return this._alphaTest}set alphaTest(e){this._alphaTest>0!=e>0&&this.version++,this._alphaTest=e}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(e){if(e!==void 0)for(const t in e){const i=e[t];if(i===void 0){Re(`Material: parameter '${t}' has value of undefined.`);continue}const n=this[t];if(n===void 0){Re(`Material: '${t}' is not a property of THREE.${this.type}.`);continue}n&&n.isColor?n.set(i):n&&n.isVector2&&i&&i.isVector2||n&&n.isEuler&&i&&i.isEuler||n&&n.isVector3&&i&&i.isVector3?n.copy(i):this[t]=i}}toJSON(e){const t=e===void 0||typeof e=="string";t&&(e={textures:{},images:{}});const i={metadata:{version:4.7,type:"Material",generator:"Material.toJSON"}};i.uuid=this.uuid,i.type=this.type,this.name!==""&&(i.name=this.name),this.color&&this.color.isColor&&(i.color=this.color.getHex()),this.roughness!==void 0&&(i.roughness=this.roughness),this.metalness!==void 0&&(i.metalness=this.metalness),this.sheen!==void 0&&(i.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(i.sheenColor=this.sheenColor.getHex()),this.sheenRoughness!==void 0&&(i.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(i.emissive=this.emissive.getHex()),this.emissiveIntensity!==void 0&&this.emissiveIntensity!==1&&(i.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(i.specular=this.specular.getHex()),this.specularIntensity!==void 0&&(i.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(i.specularColor=this.specularColor.getHex()),this.shininess!==void 0&&(i.shininess=this.shininess),this.clearcoat!==void 0&&(i.clearcoat=this.clearcoat),this.clearcoatRoughness!==void 0&&(i.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(i.clearcoatMap=this.clearcoatMap.toJSON(e).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(i.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(e).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(i.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(e).uuid,i.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),this.sheenColorMap&&this.sheenColorMap.isTexture&&(i.sheenColorMap=this.sheenColorMap.toJSON(e).uuid),this.sheenRoughnessMap&&this.sheenRoughnessMap.isTexture&&(i.sheenRoughnessMap=this.sheenRoughnessMap.toJSON(e).uuid),this.dispersion!==void 0&&(i.dispersion=this.dispersion),this.iridescence!==void 0&&(i.iridescence=this.iridescence),this.iridescenceIOR!==void 0&&(i.iridescenceIOR=this.iridescenceIOR),this.iridescenceThicknessRange!==void 0&&(i.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(i.iridescenceMap=this.iridescenceMap.toJSON(e).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(i.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(e).uuid),this.anisotropy!==void 0&&(i.anisotropy=this.anisotropy),this.anisotropyRotation!==void 0&&(i.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(i.anisotropyMap=this.anisotropyMap.toJSON(e).uuid),this.map&&this.map.isTexture&&(i.map=this.map.toJSON(e).uuid),this.matcap&&this.matcap.isTexture&&(i.matcap=this.matcap.toJSON(e).uuid),this.alphaMap&&this.alphaMap.isTexture&&(i.alphaMap=this.alphaMap.toJSON(e).uuid),this.lightMap&&this.lightMap.isTexture&&(i.lightMap=this.lightMap.toJSON(e).uuid,i.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(i.aoMap=this.aoMap.toJSON(e).uuid,i.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(i.bumpMap=this.bumpMap.toJSON(e).uuid,i.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(i.normalMap=this.normalMap.toJSON(e).uuid,i.normalMapType=this.normalMapType,i.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(i.displacementMap=this.displacementMap.toJSON(e).uuid,i.displacementScale=this.displacementScale,i.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(i.roughnessMap=this.roughnessMap.toJSON(e).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(i.metalnessMap=this.metalnessMap.toJSON(e).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(i.emissiveMap=this.emissiveMap.toJSON(e).uuid),this.specularMap&&this.specularMap.isTexture&&(i.specularMap=this.specularMap.toJSON(e).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(i.specularIntensityMap=this.specularIntensityMap.toJSON(e).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(i.specularColorMap=this.specularColorMap.toJSON(e).uuid),this.envMap&&this.envMap.isTexture&&(i.envMap=this.envMap.toJSON(e).uuid,this.combine!==void 0&&(i.combine=this.combine)),this.envMapRotation!==void 0&&(i.envMapRotation=this.envMapRotation.toArray()),this.envMapIntensity!==void 0&&(i.envMapIntensity=this.envMapIntensity),this.reflectivity!==void 0&&(i.reflectivity=this.reflectivity),this.refractionRatio!==void 0&&(i.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(i.gradientMap=this.gradientMap.toJSON(e).uuid),this.transmission!==void 0&&(i.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(i.transmissionMap=this.transmissionMap.toJSON(e).uuid),this.thickness!==void 0&&(i.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(i.thicknessMap=this.thicknessMap.toJSON(e).uuid),this.attenuationDistance!==void 0&&this.attenuationDistance!==1/0&&(i.attenuationDistance=this.attenuationDistance),this.attenuationColor!==void 0&&(i.attenuationColor=this.attenuationColor.getHex()),this.size!==void 0&&(i.size=this.size),this.shadowSide!==null&&(i.shadowSide=this.shadowSide),this.sizeAttenuation!==void 0&&(i.sizeAttenuation=this.sizeAttenuation),this.blending!==ia&&(i.blending=this.blending),this.side!==sa&&(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!==Ou&&(i.blendSrc=this.blendSrc),this.blendDst!==Ho&&(i.blendDst=this.blendDst),this.blendEquation!==ba&&(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!==Ur&&(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!==Gf&&(i.stencilFunc=this.stencilFunc),this.stencilRef!==0&&(i.stencilRef=this.stencilRef),this.stencilFuncMask!==255&&(i.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==Ya&&(i.stencilFail=this.stencilFail),this.stencilZFail!==Ya&&(i.stencilZFail=this.stencilZFail),this.stencilZPass!==Ya&&(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 a=[];for(const o in s){const c=s[o];delete c.metadata,a.push(c)}return a}if(t){const s=n(e.textures),a=n(e.images);s.length>0&&(i.textures=s),a.length>0&&(i.images=a)}return i}fromJSON(e,t){if(e.uuid!==void 0&&(this.uuid=e.uuid),e.name!==void 0&&(this.name=e.name),e.color!==void 0&&this.color!==void 0&&this.color.setHex(e.color),e.roughness!==void 0&&(this.roughness=e.roughness),e.metalness!==void 0&&(this.metalness=e.metalness),e.sheen!==void 0&&(this.sheen=e.sheen),e.sheenColor!==void 0&&(this.sheenColor=new se().setHex(e.sheenColor)),e.sheenRoughness!==void 0&&(this.sheenRoughness=e.sheenRoughness),e.emissive!==void 0&&this.emissive!==void 0&&this.emissive.setHex(e.emissive),e.specular!==void 0&&this.specular!==void 0&&this.specular.setHex(e.specular),e.specularIntensity!==void 0&&(this.specularIntensity=e.specularIntensity),e.specularColor!==void 0&&this.specularColor!==void 0&&this.specularColor.setHex(e.specularColor),e.shininess!==void 0&&(this.shininess=e.shininess),e.clearcoat!==void 0&&(this.clearcoat=e.clearcoat),e.clearcoatRoughness!==void 0&&(this.clearcoatRoughness=e.clearcoatRoughness),e.dispersion!==void 0&&(this.dispersion=e.dispersion),e.iridescence!==void 0&&(this.iridescence=e.iridescence),e.iridescenceIOR!==void 0&&(this.iridescenceIOR=e.iridescenceIOR),e.iridescenceThicknessRange!==void 0&&(this.iridescenceThicknessRange=e.iridescenceThicknessRange),e.transmission!==void 0&&(this.transmission=e.transmission),e.thickness!==void 0&&(this.thickness=e.thickness),e.attenuationDistance!==void 0&&(this.attenuationDistance=e.attenuationDistance),e.attenuationColor!==void 0&&this.attenuationColor!==void 0&&this.attenuationColor.setHex(e.attenuationColor),e.anisotropy!==void 0&&(this.anisotropy=e.anisotropy),e.anisotropyRotation!==void 0&&(this.anisotropyRotation=e.anisotropyRotation),e.fog!==void 0&&(this.fog=e.fog),e.flatShading!==void 0&&(this.flatShading=e.flatShading),e.blending!==void 0&&(this.blending=e.blending),e.combine!==void 0&&(this.combine=e.combine),e.side!==void 0&&(this.side=e.side),e.shadowSide!==void 0&&(this.shadowSide=e.shadowSide),e.opacity!==void 0&&(this.opacity=e.opacity),e.transparent!==void 0&&(this.transparent=e.transparent),e.alphaTest!==void 0&&(this.alphaTest=e.alphaTest),e.alphaHash!==void 0&&(this.alphaHash=e.alphaHash),e.depthFunc!==void 0&&(this.depthFunc=e.depthFunc),e.depthTest!==void 0&&(this.depthTest=e.depthTest),e.depthWrite!==void 0&&(this.depthWrite=e.depthWrite),e.colorWrite!==void 0&&(this.colorWrite=e.colorWrite),e.blendSrc!==void 0&&(this.blendSrc=e.blendSrc),e.blendDst!==void 0&&(this.blendDst=e.blendDst),e.blendEquation!==void 0&&(this.blendEquation=e.blendEquation),e.blendSrcAlpha!==void 0&&(this.blendSrcAlpha=e.blendSrcAlpha),e.blendDstAlpha!==void 0&&(this.blendDstAlpha=e.blendDstAlpha),e.blendEquationAlpha!==void 0&&(this.blendEquationAlpha=e.blendEquationAlpha),e.blendColor!==void 0&&this.blendColor!==void 0&&this.blendColor.setHex(e.blendColor),e.blendAlpha!==void 0&&(this.blendAlpha=e.blendAlpha),e.stencilWriteMask!==void 0&&(this.stencilWriteMask=e.stencilWriteMask),e.stencilFunc!==void 0&&(this.stencilFunc=e.stencilFunc),e.stencilRef!==void 0&&(this.stencilRef=e.stencilRef),e.stencilFuncMask!==void 0&&(this.stencilFuncMask=e.stencilFuncMask),e.stencilFail!==void 0&&(this.stencilFail=e.stencilFail),e.stencilZFail!==void 0&&(this.stencilZFail=e.stencilZFail),e.stencilZPass!==void 0&&(this.stencilZPass=e.stencilZPass),e.stencilWrite!==void 0&&(this.stencilWrite=e.stencilWrite),e.wireframe!==void 0&&(this.wireframe=e.wireframe),e.wireframeLinewidth!==void 0&&(this.wireframeLinewidth=e.wireframeLinewidth),e.wireframeLinecap!==void 0&&(this.wireframeLinecap=e.wireframeLinecap),e.wireframeLinejoin!==void 0&&(this.wireframeLinejoin=e.wireframeLinejoin),e.rotation!==void 0&&(this.rotation=e.rotation),e.linewidth!==void 0&&(this.linewidth=e.linewidth),e.dashSize!==void 0&&(this.dashSize=e.dashSize),e.gapSize!==void 0&&(this.gapSize=e.gapSize),e.scale!==void 0&&(this.scale=e.scale),e.polygonOffset!==void 0&&(this.polygonOffset=e.polygonOffset),e.polygonOffsetFactor!==void 0&&(this.polygonOffsetFactor=e.polygonOffsetFactor),e.polygonOffsetUnits!==void 0&&(this.polygonOffsetUnits=e.polygonOffsetUnits),e.dithering!==void 0&&(this.dithering=e.dithering),e.alphaToCoverage!==void 0&&(this.alphaToCoverage=e.alphaToCoverage),e.premultipliedAlpha!==void 0&&(this.premultipliedAlpha=e.premultipliedAlpha),e.forceSinglePass!==void 0&&(this.forceSinglePass=e.forceSinglePass),e.allowOverride!==void 0&&(this.allowOverride=e.allowOverride),e.visible!==void 0&&(this.visible=e.visible),e.toneMapped!==void 0&&(this.toneMapped=e.toneMapped),e.userData!==void 0&&(this.userData=e.userData),e.vertexColors!==void 0&&(typeof e.vertexColors=="number"?this.vertexColors=e.vertexColors>0:this.vertexColors=e.vertexColors),e.size!==void 0&&(this.size=e.size),e.sizeAttenuation!==void 0&&(this.sizeAttenuation=e.sizeAttenuation),e.map!==void 0&&(this.map=t[e.map]||null),e.matcap!==void 0&&(this.matcap=t[e.matcap]||null),e.alphaMap!==void 0&&(this.alphaMap=t[e.alphaMap]||null),e.bumpMap!==void 0&&(this.bumpMap=t[e.bumpMap]||null),e.bumpScale!==void 0&&(this.bumpScale=e.bumpScale),e.normalMap!==void 0&&(this.normalMap=t[e.normalMap]||null),e.normalMapType!==void 0&&(this.normalMapType=e.normalMapType),e.normalScale!==void 0){let i=e.normalScale;Array.isArray(i)===!1&&(i=[i,i]),this.normalScale=new xe().fromArray(i)}return e.displacementMap!==void 0&&(this.displacementMap=t[e.displacementMap]||null),e.displacementScale!==void 0&&(this.displacementScale=e.displacementScale),e.displacementBias!==void 0&&(this.displacementBias=e.displacementBias),e.roughnessMap!==void 0&&(this.roughnessMap=t[e.roughnessMap]||null),e.metalnessMap!==void 0&&(this.metalnessMap=t[e.metalnessMap]||null),e.emissiveMap!==void 0&&(this.emissiveMap=t[e.emissiveMap]||null),e.emissiveIntensity!==void 0&&(this.emissiveIntensity=e.emissiveIntensity),e.specularMap!==void 0&&(this.specularMap=t[e.specularMap]||null),e.specularIntensityMap!==void 0&&(this.specularIntensityMap=t[e.specularIntensityMap]||null),e.specularColorMap!==void 0&&(this.specularColorMap=t[e.specularColorMap]||null),e.envMap!==void 0&&(this.envMap=t[e.envMap]||null),e.envMapRotation!==void 0&&this.envMapRotation.fromArray(e.envMapRotation),e.envMapIntensity!==void 0&&(this.envMapIntensity=e.envMapIntensity),e.reflectivity!==void 0&&(this.reflectivity=e.reflectivity),e.refractionRatio!==void 0&&(this.refractionRatio=e.refractionRatio),e.lightMap!==void 0&&(this.lightMap=t[e.lightMap]||null),e.lightMapIntensity!==void 0&&(this.lightMapIntensity=e.lightMapIntensity),e.aoMap!==void 0&&(this.aoMap=t[e.aoMap]||null),e.aoMapIntensity!==void 0&&(this.aoMapIntensity=e.aoMapIntensity),e.gradientMap!==void 0&&(this.gradientMap=t[e.gradientMap]||null),e.clearcoatMap!==void 0&&(this.clearcoatMap=t[e.clearcoatMap]||null),e.clearcoatRoughnessMap!==void 0&&(this.clearcoatRoughnessMap=t[e.clearcoatRoughnessMap]||null),e.clearcoatNormalMap!==void 0&&(this.clearcoatNormalMap=t[e.clearcoatNormalMap]||null),e.clearcoatNormalScale!==void 0&&(this.clearcoatNormalScale=new xe().fromArray(e.clearcoatNormalScale)),e.iridescenceMap!==void 0&&(this.iridescenceMap=t[e.iridescenceMap]||null),e.iridescenceThicknessMap!==void 0&&(this.iridescenceThicknessMap=t[e.iridescenceThicknessMap]||null),e.transmissionMap!==void 0&&(this.transmissionMap=t[e.transmissionMap]||null),e.thicknessMap!==void 0&&(this.thicknessMap=t[e.thicknessMap]||null),e.anisotropyMap!==void 0&&(this.anisotropyMap=t[e.anisotropyMap]||null),e.sheenColorMap!==void 0&&(this.sheenColorMap=t[e.sheenColorMap]||null),e.sheenRoughnessMap!==void 0&&(this.sheenRoughnessMap=t[e.sheenRoughnessMap]||null),this}clone(){return new this.constructor().copy(this)}copy(e){this.name=e.name,this.blending=e.blending,this.side=e.side,this.vertexColors=e.vertexColors,this.opacity=e.opacity,this.transparent=e.transparent,this.blendSrc=e.blendSrc,this.blendDst=e.blendDst,this.blendEquation=e.blendEquation,this.blendSrcAlpha=e.blendSrcAlpha,this.blendDstAlpha=e.blendDstAlpha,this.blendEquationAlpha=e.blendEquationAlpha,this.blendColor.copy(e.blendColor),this.blendAlpha=e.blendAlpha,this.depthFunc=e.depthFunc,this.depthTest=e.depthTest,this.depthWrite=e.depthWrite,this.stencilWriteMask=e.stencilWriteMask,this.stencilFunc=e.stencilFunc,this.stencilRef=e.stencilRef,this.stencilFuncMask=e.stencilFuncMask,this.stencilFail=e.stencilFail,this.stencilZFail=e.stencilZFail,this.stencilZPass=e.stencilZPass,this.stencilWrite=e.stencilWrite;const t=e.clippingPlanes;let i=null;if(t!==null){const n=t.length;i=new Array(n);for(let s=0;s!==n;++s)i[s]=t[s].clone()}return this.clippingPlanes=i,this.clipIntersection=e.clipIntersection,this.clipShadows=e.clipShadows,this.shadowSide=e.shadowSide,this.colorWrite=e.colorWrite,this.precision=e.precision,this.polygonOffset=e.polygonOffset,this.polygonOffsetFactor=e.polygonOffsetFactor,this.polygonOffsetUnits=e.polygonOffsetUnits,this.dithering=e.dithering,this.alphaTest=e.alphaTest,this.alphaHash=e.alphaHash,this.alphaToCoverage=e.alphaToCoverage,this.premultipliedAlpha=e.premultipliedAlpha,this.forceSinglePass=e.forceSinglePass,this.allowOverride=e.allowOverride,this.visible=e.visible,this.toneMapped=e.toneMapped,this.userData=JSON.parse(JSON.stringify(e.userData)),this}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(e){e===!0&&this.version++}}class ul extends Ps{constructor(e){super(),this.isSpriteMaterial=!0,this.type="SpriteMaterial",this.color=new se(16777215),this.map=null,this.alphaMap=null,this.rotation=0,this.sizeAttenuation=!0,this.transparent=!0,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.alphaMap=e.alphaMap,this.rotation=e.rotation,this.sizeAttenuation=e.sizeAttenuation,this.fog=e.fog,this}}let nr;const jr=new R,sr=new R,ar=new R,rr=new xe,Qr=new xe,s1=new Ze,vc=new R,eo=new R,Mc=new R,ip=new xe,Ch=new xe,np=new xe;class to extends Ut{constructor(e=new ul){if(super(),this.isSprite=!0,this.type="Sprite",nr===void 0){nr=new ot;const t=new Float32Array([-.5,-.5,0,0,0,.5,-.5,0,1,0,.5,.5,0,1,1,-.5,.5,0,0,1]),i=new nx(t,5);nr.setIndex([0,1,2,0,2,3]),nr.setAttribute("position",new Dl(i,3,0,!1)),nr.setAttribute("uv",new Dl(i,2,3,!1))}this.geometry=nr,this.material=e,this.center=new xe(.5,.5),this.count=1}raycast(e,t){e.camera===null&&Ge('Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.'),sr.setFromMatrixScale(this.matrixWorld),s1.copy(e.camera.matrixWorld),this.modelViewMatrix.multiplyMatrices(e.camera.matrixWorldInverse,this.matrixWorld),ar.setFromMatrixPosition(this.modelViewMatrix),e.camera.isPerspectiveCamera&&this.material.sizeAttenuation===!1&&sr.multiplyScalar(-ar.z);const i=this.material.rotation;let n,s;i!==0&&(s=Math.cos(i),n=Math.sin(i));const a=this.center;xc(vc.set(-.5,-.5,0),ar,a,sr,n,s),xc(eo.set(.5,-.5,0),ar,a,sr,n,s),xc(Mc.set(.5,.5,0),ar,a,sr,n,s),ip.set(0,0),Ch.set(1,0),np.set(1,1);let o=e.ray.intersectTriangle(vc,eo,Mc,!1,jr);if(o===null&&(xc(eo.set(-.5,.5,0),ar,a,sr,n,s),Ch.set(0,1),o=e.ray.intersectTriangle(vc,Mc,eo,!1,jr),o===null))return;const c=e.ray.origin.distanceTo(jr);c<e.near||c>e.far||t.push({distance:c,point:jr.clone(),uv:yn.getInterpolation(jr,vc,eo,Mc,ip,Ch,np,new xe),face:null,object:this})}copy(e,t){return super.copy(e,t),e.center!==void 0&&this.center.copy(e.center),this.material=e.material,this}}function xc(r,e,t,i,n,s){rr.subVectors(r,t).addScalar(.5).multiply(i),n!==void 0?(Qr.x=s*rr.x-n*rr.y,Qr.y=n*rr.x+s*rr.y):Qr.copy(rr),r.copy(e),r.x+=Qr.x,r.y+=Qr.y,r.applyMatrix4(s1)}const fs=new R,Ph=new R,yc=new R,Hs=new R,Lh=new R,bc=new R,Oh=new R;class Zo{constructor(e=new R,t=new R(0,0,-1)){this.origin=e,this.direction=t}set(e,t){return this.origin.copy(e),this.direction.copy(t),this}copy(e){return this.origin.copy(e.origin),this.direction.copy(e.direction),this}at(e,t){return t.copy(this.origin).addScaledVector(this.direction,e)}lookAt(e){return this.direction.copy(e).sub(this.origin).normalize(),this}recast(e){return this.origin.copy(this.at(e,fs)),this}closestPointToPoint(e,t){t.subVectors(e,this.origin);const i=t.dot(this.direction);return i<0?t.copy(this.origin):t.copy(this.origin).addScaledVector(this.direction,i)}distanceToPoint(e){return Math.sqrt(this.distanceSqToPoint(e))}distanceSqToPoint(e){const t=fs.subVectors(e,this.origin).dot(this.direction);return t<0?this.origin.distanceToSquared(e):(fs.copy(this.origin).addScaledVector(this.direction,t),fs.distanceToSquared(e))}distanceSqToSegment(e,t,i,n){Ph.copy(e).add(t).multiplyScalar(.5),yc.copy(t).sub(e).normalize(),Hs.copy(this.origin).sub(Ph);const s=e.distanceTo(t)*.5,a=-this.direction.dot(yc),o=Hs.dot(this.direction),c=-Hs.dot(yc),l=Hs.lengthSq(),h=Math.abs(1-a*a);let u,d,f,p;if(h>0)if(u=a*c-o,d=a*o-c,p=s*h,u>=0)if(d>=-p)if(d<=p){const v=1/h;u*=v,d*=v,f=u*(u+a*d+2*o)+d*(a*u+d+2*c)+l}else d=s,u=Math.max(0,-(a*d+o)),f=-u*u+d*(d+2*c)+l;else d=-s,u=Math.max(0,-(a*d+o)),f=-u*u+d*(d+2*c)+l;else d<=-p?(u=Math.max(0,-(-a*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,-(a*s+o)),d=u>0?s:Math.min(Math.max(-s,-c),s),f=-u*u+d*(d+2*c)+l);else d=a>0?-s:s,u=Math.max(0,-(a*d+o)),f=-u*u+d*(d+2*c)+l;return i&&i.copy(this.origin).addScaledVector(this.direction,u),n&&n.copy(Ph).addScaledVector(yc,d),f}intersectSphere(e,t){fs.subVectors(e.center,this.origin);const i=fs.dot(this.direction),n=fs.dot(fs)-i*i,s=e.radius*e.radius;if(n>s)return null;const a=Math.sqrt(s-n),o=i-a,c=i+a;return c<0?null:o<0?this.at(c,t):this.at(o,t)}intersectsSphere(e){return e.radius<0?!1:this.distanceSqToPoint(e.center)<=e.radius*e.radius}distanceToPlane(e){const t=e.normal.dot(this.direction);if(t===0)return e.distanceToPoint(this.origin)===0?0:null;const i=-(this.origin.dot(e.normal)+e.constant)/t;return i>=0?i:null}intersectPlane(e,t){const i=this.distanceToPlane(e);return i===null?null:this.at(i,t)}intersectsPlane(e){const t=e.distanceToPoint(this.origin);return t===0||e.normal.dot(this.direction)*t<0}intersectBox(e,t){let i,n,s,a,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=(e.min.x-d.x)*l,n=(e.max.x-d.x)*l):(i=(e.max.x-d.x)*l,n=(e.min.x-d.x)*l),h>=0?(s=(e.min.y-d.y)*h,a=(e.max.y-d.y)*h):(s=(e.max.y-d.y)*h,a=(e.min.y-d.y)*h),i>a||s>n||((s>i||isNaN(i))&&(i=s),(a<n||isNaN(n))&&(n=a),u>=0?(o=(e.min.z-d.z)*u,c=(e.max.z-d.z)*u):(o=(e.max.z-d.z)*u,c=(e.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,t)}intersectsBox(e){return this.intersectBox(e,fs)!==null}intersectTriangle(e,t,i,n,s){Lh.subVectors(t,e),bc.subVectors(i,e),Oh.crossVectors(Lh,bc);let a=this.direction.dot(Oh),o;if(a>0){if(n)return null;o=1}else if(a<0)o=-1,a=-a;else return null;Hs.subVectors(this.origin,e);const c=o*this.direction.dot(bc.crossVectors(Hs,bc));if(c<0)return null;const l=o*this.direction.dot(Lh.cross(Hs));if(l<0||c+l>a)return null;const h=-o*Hs.dot(Oh);return h<0?null:this.at(h/a,s)}applyMatrix4(e){return this.origin.applyMatrix4(e),this.direction.transformDirection(e),this}equals(e){return e.origin.equals(this.origin)&&e.direction.equals(this.direction)}clone(){return new this.constructor().copy(this)}}class bn extends Ps{constructor(e){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new se(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 Ds,this.combine=u0,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.specularMap=e.specularMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.combine=e.combine,this.reflectivity=e.reflectivity,this.refractionRatio=e.refractionRatio,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.fog=e.fog,this}}const sp=new Ze,fa=new Zo,_c=new Cs,ap=new R,Sc=new R,wc=new R,Ec=new R,Nh=new R,Ac=new R,rp=new R,Tc=new R;class De extends Ut{constructor(e=new ot,t=new bn){super(),this.isMesh=!0,this.type="Mesh",this.geometry=e,this.material=t,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.count=1,this.updateMorphTargets()}copy(e,t){return super.copy(e,t),e.morphTargetInfluences!==void 0&&(this.morphTargetInfluences=e.morphTargetInfluences.slice()),e.morphTargetDictionary!==void 0&&(this.morphTargetDictionary=Object.assign({},e.morphTargetDictionary)),this.material=Array.isArray(e.material)?e.material.slice():e.material,this.geometry=e.geometry,this}updateMorphTargets(){const t=this.geometry.morphAttributes,i=Object.keys(t);if(i.length>0){const n=t[i[0]];if(n!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let s=0,a=n.length;s<a;s++){const o=n[s].name||String(s);this.morphTargetInfluences.push(0),this.morphTargetDictionary[o]=s}}}}getVertexPosition(e,t){const i=this.geometry,n=i.attributes.position,s=i.morphAttributes.position,a=i.morphTargetsRelative;t.fromBufferAttribute(n,e);const o=this.morphTargetInfluences;if(s&&o){Ac.set(0,0,0);for(let c=0,l=s.length;c<l;c++){const h=o[c],u=s[c];h!==0&&(Nh.fromBufferAttribute(u,e),a?Ac.addScaledVector(Nh,h):Ac.addScaledVector(Nh.sub(t),h))}t.add(Ac)}return t}raycast(e,t){const i=this.geometry,n=this.material,s=this.matrixWorld;n!==void 0&&(i.boundingSphere===null&&i.computeBoundingSphere(),_c.copy(i.boundingSphere),_c.applyMatrix4(s),fa.copy(e.ray).recast(e.near),!(_c.containsPoint(fa.origin)===!1&&(fa.intersectSphere(_c,ap)===null||fa.origin.distanceToSquared(ap)>(e.far-e.near)**2))&&(sp.copy(s).invert(),fa.copy(e.ray).applyMatrix4(sp),!(i.boundingBox!==null&&fa.intersectsBox(i.boundingBox)===!1)&&this._computeIntersections(e,t,fa)))}_computeIntersections(e,t,i){let n;const s=this.geometry,a=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(a))for(let p=0,v=d.length;p<v;p++){const m=d[p],g=a[m.materialIndex],_=Math.max(m.start,f.start),b=Math.min(o.count,Math.min(m.start+m.count,f.start+f.count));for(let M=_,S=b;M<S;M+=3){const w=o.getX(M),T=o.getX(M+1),x=o.getX(M+2);n=Rc(this,g,e,i,l,h,u,w,T,x),n&&(n.faceIndex=Math.floor(M/3),n.face.materialIndex=m.materialIndex,t.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 _=o.getX(m),b=o.getX(m+1),M=o.getX(m+2);n=Rc(this,a,e,i,l,h,u,_,b,M),n&&(n.faceIndex=Math.floor(m/3),t.push(n))}}else if(c!==void 0)if(Array.isArray(a))for(let p=0,v=d.length;p<v;p++){const m=d[p],g=a[m.materialIndex],_=Math.max(m.start,f.start),b=Math.min(c.count,Math.min(m.start+m.count,f.start+f.count));for(let M=_,S=b;M<S;M+=3){const w=M,T=M+1,x=M+2;n=Rc(this,g,e,i,l,h,u,w,T,x),n&&(n.faceIndex=Math.floor(M/3),n.face.materialIndex=m.materialIndex,t.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 _=m,b=m+1,M=m+2;n=Rc(this,a,e,i,l,h,u,_,b,M),n&&(n.faceIndex=Math.floor(m/3),t.push(n))}}}}function ax(r,e,t,i,n,s,a,o){let c;if(e.side===Ht?c=i.intersectTriangle(a,s,n,!0,o):c=i.intersectTriangle(n,s,a,e.side===sa,o),c===null)return null;Tc.copy(o),Tc.applyMatrix4(r.matrixWorld);const l=t.ray.origin.distanceTo(Tc);return l<t.near||l>t.far?null:{distance:l,point:Tc.clone(),object:r}}function Rc(r,e,t,i,n,s,a,o,c,l){r.getVertexPosition(o,Sc),r.getVertexPosition(c,wc),r.getVertexPosition(l,Ec);const h=ax(r,e,t,i,Sc,wc,Ec,rp);if(h){const u=new R;yn.getBarycoord(rp,Sc,wc,Ec,u),n&&(h.uv=yn.getInterpolatedAttribute(n,o,c,l,u,new xe)),s&&(h.uv1=yn.getInterpolatedAttribute(s,o,c,l,u,new xe)),a&&(h.normal=yn.getInterpolatedAttribute(a,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};yn.getNormal(Sc,wc,Ec,d.normal),h.face=d,h.barycoord=u}return h}const io=new it,op=new it,cp=new it,rx=new it,lp=new Ze,Dc=new R,Fh=new Cs,hp=new Ze,Uh=new Zo;class OA extends De{constructor(e,t){super(e,t),this.isSkinnedMesh=!0,this.type="SkinnedMesh",this.bindMode=Bf,this.bindMatrix=new Ze,this.bindMatrixInverse=new Ze,this.boundingBox=null,this.boundingSphere=null}computeBoundingBox(){const e=this.geometry;this.boundingBox===null&&(this.boundingBox=new Wi),this.boundingBox.makeEmpty();const t=e.getAttribute("position");for(let i=0;i<t.count;i++)this.getVertexPosition(i,Dc),this.boundingBox.expandByPoint(Dc)}computeBoundingSphere(){const e=this.geometry;this.boundingSphere===null&&(this.boundingSphere=new Cs),this.boundingSphere.makeEmpty();const t=e.getAttribute("position");for(let i=0;i<t.count;i++)this.getVertexPosition(i,Dc),this.boundingSphere.expandByPoint(Dc)}copy(e,t){return super.copy(e,t),this.bindMode=e.bindMode,this.bindMatrix.copy(e.bindMatrix),this.bindMatrixInverse.copy(e.bindMatrixInverse),this.skeleton=e.skeleton,e.boundingBox!==null&&(this.boundingBox=e.boundingBox.clone()),e.boundingSphere!==null&&(this.boundingSphere=e.boundingSphere.clone()),this}raycast(e,t){const i=this.material,n=this.matrixWorld;i!==void 0&&(this.boundingSphere===null&&this.computeBoundingSphere(),Fh.copy(this.boundingSphere),Fh.applyMatrix4(n),e.ray.intersectsSphere(Fh)!==!1&&(hp.copy(n).invert(),Uh.copy(e.ray).applyMatrix4(hp),!(this.boundingBox!==null&&Uh.intersectsBox(this.boundingBox)===!1)&&this._computeIntersections(e,t,Uh)))}getVertexPosition(e,t){return super.getVertexPosition(e,t),this.applyBoneTransform(e,t),t}bind(e,t){this.skeleton=e,t===void 0&&(this.updateMatrixWorld(!0),this.skeleton.calculateInverses(),t=this.matrixWorld),this.bindMatrix.copy(t),this.bindMatrixInverse.copy(t).invert()}pose(){this.skeleton.pose()}normalizeSkinWeights(){const e=new it,t=this.geometry.attributes.skinWeight;for(let i=0,n=t.count;i<n;i++){e.fromBufferAttribute(t,i);const s=1/e.manhattanLength();s!==1/0?e.multiplyScalar(s):e.set(1,0,0,0),t.setXYZW(i,e.x,e.y,e.z,e.w)}}updateMatrixWorld(e){super.updateMatrixWorld(e),this.bindMode===Bf?this.bindMatrixInverse.copy(this.matrixWorld).invert():this.bindMode===aM?this.bindMatrixInverse.copy(this.bindMatrix).invert():Re("SkinnedMesh: Unrecognized bindMode: "+this.bindMode)}applyBoneTransform(e,t){const i=this.skeleton,n=this.geometry;op.fromBufferAttribute(n.attributes.skinIndex,e),cp.fromBufferAttribute(n.attributes.skinWeight,e),t.isVector4?(io.copy(t),t.set(0,0,0,0)):(io.set(...t,1),t.set(0,0,0)),io.applyMatrix4(this.bindMatrix);for(let s=0;s<4;s++){const a=cp.getComponent(s);if(a!==0){const o=op.getComponent(s);lp.multiplyMatrices(i.bones[o].matrixWorld,i.boneInverses[o]),t.addScaledVector(rx.copy(io).applyMatrix4(lp),a)}}return t.isVector4&&(t.w=io.w),t.applyMatrix4(this.bindMatrixInverse)}}class ox extends Ut{constructor(){super(),this.isBone=!0,this.type="Bone"}}class ca extends Si{constructor(e=null,t=1,i=1,n,s,a,o,c,l=At,h=At,u,d){super(null,a,o,c,l,h,n,s,u,d),this.isDataTexture=!0,this.image={data:e,width:t,height:i},this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}const up=new Ze,cx=new Ze;class a1{constructor(e=[],t=[]){this.uuid=Un(),this.bones=e.slice(0),this.boneInverses=t,this.boneMatrices=null,this.boneTexture=null,this.init()}init(){const e=this.bones,t=this.boneInverses;if(this.boneMatrices=new Float32Array(e.length*16),t.length===0)this.calculateInverses();else if(e.length!==t.length){Re("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 Ze)}}calculateInverses(){this.boneInverses.length=0;for(let e=0,t=this.bones.length;e<t;e++){const i=new Ze;this.bones[e]&&i.copy(this.bones[e].matrixWorld).invert(),this.boneInverses.push(i)}}pose(){for(let e=0,t=this.bones.length;e<t;e++){const i=this.bones[e];i&&i.matrixWorld.copy(this.boneInverses[e]).invert()}for(let e=0,t=this.bones.length;e<t;e++){const i=this.bones[e];i&&(i.parent&&i.parent.isBone?(i.matrix.copy(i.parent.matrixWorld).invert(),i.matrix.multiply(i.matrixWorld)):i.matrix.copy(i.matrixWorld),i.matrix.decompose(i.position,i.quaternion,i.scale))}}update(){const e=this.bones,t=this.boneInverses,i=this.boneMatrices,n=this.boneTexture;for(let s=0,a=e.length;s<a;s++){const o=e[s]?e[s].matrixWorld:cx;up.multiplyMatrices(o,t[s]),up.toArray(i,s*16)}n!==null&&(n.needsUpdate=!0)}clone(){return new a1(this.bones,this.boneInverses)}computeBoneTexture(){let e=Math.sqrt(this.bones.length*4);e=Math.ceil(e/4)*4,e=Math.max(e,4);const t=new Float32Array(e*e*4);t.set(this.boneMatrices);const i=new ca(t,e,e,Ei,Oi);return i.needsUpdate=!0,this.boneMatrices=t,this.boneTexture=i,this}getBoneByName(e){for(let t=0,i=this.bones.length;t<i;t++){const n=this.bones[t];if(n.name===e)return n}}dispose(){this.boneTexture!==null&&(this.boneTexture.dispose(),this.boneTexture=null)}fromJSON(e,t){this.uuid=e.uuid;for(let i=0,n=e.bones.length;i<n;i++){const s=e.bones[i];let a=t[s];a===void 0&&(Re("Skeleton: No bone found with UUID:",s),a=new ox),this.bones.push(a),this.boneInverses.push(new Ze().fromArray(e.boneInverses[i]))}return this.init(),this}toJSON(){const e={metadata:{version:4.7,type:"Skeleton",generator:"Skeleton.toJSON"},bones:[],boneInverses:[]};e.uuid=this.uuid;const t=this.bones,i=this.boneInverses;for(let n=0,s=t.length;n<s;n++){const a=t[n];e.bones.push(a.uuid);const o=i[n];e.boneInverses.push(o.toArray())}return e}}class dp extends tt{constructor(e,t,i,n=1){super(e,t,i),this.isInstancedBufferAttribute=!0,this.meshPerAttribute=n}copy(e){return super.copy(e),this.meshPerAttribute=e.meshPerAttribute,this}toJSON(){const e=super.toJSON();return e.meshPerAttribute=this.meshPerAttribute,e.isInstancedBufferAttribute=!0,e}}const or=new Ze,fp=new Ze,Ic=[],pp=new Wi,lx=new Ze,no=new De,so=new Cs;class NA extends De{constructor(e,t,i){super(e,t),this.isInstancedMesh=!0,this.instanceMatrix=new dp(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,lx)}computeBoundingBox(){const e=this.geometry,t=this.count;this.boundingBox===null&&(this.boundingBox=new Wi),e.boundingBox===null&&e.computeBoundingBox(),this.boundingBox.makeEmpty();for(let i=0;i<t;i++)this.getMatrixAt(i,or),pp.copy(e.boundingBox).applyMatrix4(or),this.boundingBox.union(pp)}computeBoundingSphere(){const e=this.geometry,t=this.count;this.boundingSphere===null&&(this.boundingSphere=new Cs),e.boundingSphere===null&&e.computeBoundingSphere(),this.boundingSphere.makeEmpty();for(let i=0;i<t;i++)this.getMatrixAt(i,or),so.copy(e.boundingSphere).applyMatrix4(or),this.boundingSphere.union(so)}copy(e,t){return super.copy(e,t),this.instanceMatrix.copy(e.instanceMatrix),e.morphTexture!==null&&(this.morphTexture=e.morphTexture.clone()),e.instanceColor!==null&&(this.instanceColor=e.instanceColor.clone()),this.count=e.count,e.boundingBox!==null&&(this.boundingBox=e.boundingBox.clone()),e.boundingSphere!==null&&(this.boundingSphere=e.boundingSphere.clone()),this}getColorAt(e,t){return this.instanceColor===null?t.setRGB(1,1,1):t.fromArray(this.instanceColor.array,e*3)}getMatrixAt(e,t){return t.fromArray(this.instanceMatrix.array,e*16)}getMorphAt(e,t){const i=t.morphTargetInfluences,n=this.morphTexture.source.data.data,s=i.length+1,a=e*s+1;for(let o=0;o<i.length;o++)i[o]=n[a+o]}raycast(e,t){const i=this.matrixWorld,n=this.count;if(no.geometry=this.geometry,no.material=this.material,no.material!==void 0&&(this.boundingSphere===null&&this.computeBoundingSphere(),so.copy(this.boundingSphere),so.applyMatrix4(i),e.ray.intersectsSphere(so)!==!1))for(let s=0;s<n;s++){this.getMatrixAt(s,or),fp.multiplyMatrices(i,or),no.matrixWorld=fp,no.raycast(e,Ic);for(let a=0,o=Ic.length;a<o;a++){const c=Ic[a];c.instanceId=s,c.object=this,t.push(c)}Ic.length=0}}setColorAt(e,t){return this.instanceColor===null&&(this.instanceColor=new dp(new Float32Array(this.instanceMatrix.count*3).fill(1),3)),t.toArray(this.instanceColor.array,e*3),this}setMatrixAt(e,t){return t.toArray(this.instanceMatrix.array,e*16),this}setMorphAt(e,t){const i=t.morphTargetInfluences,n=i.length+1;this.morphTexture===null&&(this.morphTexture=new ca(new Float32Array(n*this.count),n,this.count,ql,Oi));const s=this.morphTexture.source.data.data;let a=0;for(let l=0;l<i.length;l++)a+=i[l];const o=this.geometry.morphTargetsRelative?1:1-a,c=n*e;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 kh=new R,hx=new R,ux=new Ye;class Ma{constructor(e=new R(1,0,0),t=0){this.isPlane=!0,this.normal=e,this.constant=t}set(e,t){return this.normal.copy(e),this.constant=t,this}setComponents(e,t,i,n){return this.normal.set(e,t,i),this.constant=n,this}setFromNormalAndCoplanarPoint(e,t){return this.normal.copy(e),this.constant=-t.dot(this.normal),this}setFromCoplanarPoints(e,t,i){const n=kh.subVectors(i,t).cross(hx.subVectors(e,t)).normalize();return this.setFromNormalAndCoplanarPoint(n,e),this}copy(e){return this.normal.copy(e.normal),this.constant=e.constant,this}normalize(){const e=1/this.normal.length();return this.normal.multiplyScalar(e),this.constant*=e,this}negate(){return this.constant*=-1,this.normal.negate(),this}distanceToPoint(e){return this.normal.dot(e)+this.constant}distanceToSphere(e){return this.distanceToPoint(e.center)-e.radius}projectPoint(e,t){return t.copy(e).addScaledVector(this.normal,-this.distanceToPoint(e))}intersectLine(e,t,i=!0){const n=e.delta(kh),s=this.normal.dot(n);if(s===0)return this.distanceToPoint(e.start)===0?t.copy(e.start):null;const a=-(e.start.dot(this.normal)+this.constant)/s;return i===!0&&(a<0||a>1)?null:t.copy(e.start).addScaledVector(n,a)}intersectsLine(e){const t=this.distanceToPoint(e.start),i=this.distanceToPoint(e.end);return t<0&&i>0||i<0&&t>0}intersectsBox(e){return e.intersectsPlane(this)}intersectsSphere(e){return e.intersectsPlane(this)}coplanarPoint(e){return e.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(e,t){const i=t||ux.getNormalMatrix(e),n=this.coplanarPoint(kh).applyMatrix4(e),s=this.normal.applyMatrix3(i).normalize();return this.constant=-n.dot(s),this}translate(e){return this.constant-=e.dot(this.normal),this}equals(e){return e.normal.equals(this.normal)&&e.constant===this.constant}clone(){return new this.constructor().copy(this)}}const pa=new Cs,dx=new xe(.5,.5),Cc=new R;class A0{constructor(e=new Ma,t=new Ma,i=new Ma,n=new Ma,s=new Ma,a=new Ma){this.planes=[e,t,i,n,s,a]}set(e,t,i,n,s,a){const o=this.planes;return o[0].copy(e),o[1].copy(t),o[2].copy(i),o[3].copy(n),o[4].copy(s),o[5].copy(a),this}copy(e){const t=this.planes;for(let i=0;i<6;i++)t[i].copy(e.planes[i]);return this}setFromProjectionMatrix(e,t=ns,i=!1){const n=this.planes,s=e.elements,a=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[12],b=s[13],M=s[14],S=s[15];if(n[0].setComponents(l-a,f-h,g-p,S-_).normalize(),n[1].setComponents(l+a,f+h,g+p,S+_).normalize(),n[2].setComponents(l+o,f+u,g+v,S+b).normalize(),n[3].setComponents(l-o,f-u,g-v,S-b).normalize(),i)n[4].setComponents(c,d,m,M).normalize(),n[5].setComponents(l-c,f-d,g-m,S-M).normalize();else if(n[4].setComponents(l-c,f-d,g-m,S-M).normalize(),t===ns)n[5].setComponents(l+c,f+d,g+m,S+M).normalize();else if(t===Xo)n[5].setComponents(c,d,m,M).normalize();else throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: "+t);return this}intersectsObject(e){if(e.boundingSphere!==void 0)e.boundingSphere===null&&e.computeBoundingSphere(),pa.copy(e.boundingSphere).applyMatrix4(e.matrixWorld);else{const t=e.geometry;t.boundingSphere===null&&t.computeBoundingSphere(),pa.copy(t.boundingSphere).applyMatrix4(e.matrixWorld)}return this.intersectsSphere(pa)}intersectsSprite(e){pa.center.set(0,0,0);const t=dx.distanceTo(e.center);return pa.radius=.7071067811865476+t,pa.applyMatrix4(e.matrixWorld),this.intersectsSphere(pa)}intersectsSphere(e){const t=this.planes,i=e.center,n=-e.radius;for(let s=0;s<6;s++)if(t[s].distanceToPoint(i)<n)return!1;return!0}intersectsBox(e){const t=this.planes;for(let i=0;i<6;i++){const n=t[i];if(Cc.x=n.normal.x>0?e.max.x:e.min.x,Cc.y=n.normal.y>0?e.max.y:e.min.y,Cc.z=n.normal.z>0?e.max.z:e.min.z,n.distanceToPoint(Cc)<0)return!1}return!0}containsPoint(e){const t=this.planes;for(let i=0;i<6;i++)if(t[i].distanceToPoint(e)<0)return!1;return!0}clone(){return new this.constructor().copy(this)}}class fx extends Ps{constructor(e){super(),this.isLineBasicMaterial=!0,this.type="LineBasicMaterial",this.color=new se(16777215),this.map=null,this.linewidth=1,this.linecap="round",this.linejoin="round",this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.linewidth=e.linewidth,this.linecap=e.linecap,this.linejoin=e.linejoin,this.fog=e.fog,this}}const Il=new R,Cl=new R,mp=new Ze,ao=new Zo,Pc=new Cs,zh=new R,gp=new R;class r1 extends Ut{constructor(e=new ot,t=new fx){super(),this.isLine=!0,this.type="Line",this.geometry=e,this.material=t,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.updateMorphTargets()}copy(e,t){return super.copy(e,t),this.material=Array.isArray(e.material)?e.material.slice():e.material,this.geometry=e.geometry,this}computeLineDistances(){const e=this.geometry;if(e.index===null){const t=e.attributes.position,i=[0];for(let n=1,s=t.count;n<s;n++)Il.fromBufferAttribute(t,n-1),Cl.fromBufferAttribute(t,n),i[n]=i[n-1],i[n]+=Il.distanceTo(Cl);e.setAttribute("lineDistance",new ut(i,1))}else Re("Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.");return this}raycast(e,t){const i=this.geometry,n=this.matrixWorld,s=e.params.Line.threshold,a=i.drawRange;if(i.boundingSphere===null&&i.computeBoundingSphere(),Pc.copy(i.boundingSphere),Pc.applyMatrix4(n),Pc.radius+=s,e.ray.intersectsSphere(Pc)===!1)return;mp.copy(n).invert(),ao.copy(e.ray).applyMatrix4(mp);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,a.start),p=Math.min(h.count,a.start+a.count);for(let v=f,m=p-1;v<m;v+=l){const g=h.getX(v),_=h.getX(v+1),b=Lc(this,e,ao,c,g,_,v);b&&t.push(b)}if(this.isLineLoop){const v=h.getX(p-1),m=h.getX(f),g=Lc(this,e,ao,c,v,m,p-1);g&&t.push(g)}}else{const f=Math.max(0,a.start),p=Math.min(d.count,a.start+a.count);for(let v=f,m=p-1;v<m;v+=l){const g=Lc(this,e,ao,c,v,v+1,v);g&&t.push(g)}if(this.isLineLoop){const v=Lc(this,e,ao,c,p-1,f,p-1);v&&t.push(v)}}}updateMorphTargets(){const t=this.geometry.morphAttributes,i=Object.keys(t);if(i.length>0){const n=t[i[0]];if(n!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let s=0,a=n.length;s<a;s++){const o=n[s].name||String(s);this.morphTargetInfluences.push(0),this.morphTargetDictionary[o]=s}}}}}function Lc(r,e,t,i,n,s,a){const o=r.geometry.attributes.position;if(Il.fromBufferAttribute(o,n),Cl.fromBufferAttribute(o,s),t.distanceSqToSegment(Il,Cl,zh,gp)>i)return;zh.applyMatrix4(r.matrixWorld);const l=e.ray.origin.distanceTo(zh);if(!(l<e.near||l>e.far))return{distance:l,point:gp.clone().applyMatrix4(r.matrixWorld),index:a,face:null,faceIndex:null,barycoord:null,object:r}}const vp=new R,Mp=new R;class FA extends r1{constructor(e,t){super(e,t),this.isLineSegments=!0,this.type="LineSegments"}computeLineDistances(){const e=this.geometry;if(e.index===null){const t=e.attributes.position,i=[];for(let n=0,s=t.count;n<s;n+=2)vp.fromBufferAttribute(t,n),Mp.fromBufferAttribute(t,n+1),i[n]=n===0?0:i[n-1],i[n+1]=i[n]+vp.distanceTo(Mp);e.setAttribute("lineDistance",new ut(i,1))}else Re("LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.");return this}}class UA extends r1{constructor(e,t){super(e,t),this.isLineLoop=!0,this.type="LineLoop"}}class o1 extends Ps{constructor(e){super(),this.isPointsMaterial=!0,this.type="PointsMaterial",this.color=new se(16777215),this.map=null,this.alphaMap=null,this.size=1,this.sizeAttenuation=!0,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.alphaMap=e.alphaMap,this.size=e.size,this.sizeAttenuation=e.sizeAttenuation,this.fog=e.fog,this}}const xp=new Ze,bd=new Zo,Oc=new Cs,Nc=new R;class xs extends Ut{constructor(e=new ot,t=new o1){super(),this.isPoints=!0,this.type="Points",this.geometry=e,this.material=t,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.updateMorphTargets()}copy(e,t){return super.copy(e,t),this.material=Array.isArray(e.material)?e.material.slice():e.material,this.geometry=e.geometry,this}raycast(e,t){const i=this.geometry,n=this.matrixWorld,s=e.params.Points.threshold,a=i.drawRange;if(i.boundingSphere===null&&i.computeBoundingSphere(),Oc.copy(i.boundingSphere),Oc.applyMatrix4(n),Oc.radius+=s,e.ray.intersectsSphere(Oc)===!1)return;xp.copy(n).invert(),bd.copy(e.ray).applyMatrix4(xp);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,a.start),f=Math.min(l.count,a.start+a.count);for(let p=d,v=f;p<v;p++){const m=l.getX(p);Nc.fromBufferAttribute(u,m),yp(Nc,m,c,n,e,t,this)}}else{const d=Math.max(0,a.start),f=Math.min(u.count,a.start+a.count);for(let p=d,v=f;p<v;p++)Nc.fromBufferAttribute(u,p),yp(Nc,p,c,n,e,t,this)}}updateMorphTargets(){const t=this.geometry.morphAttributes,i=Object.keys(t);if(i.length>0){const n=t[i[0]];if(n!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let s=0,a=n.length;s<a;s++){const o=n[s].name||String(s);this.morphTargetInfluences.push(0),this.morphTargetDictionary[o]=s}}}}}function yp(r,e,t,i,n,s,a){const o=bd.distanceSqToPoint(r);if(o<t){const c=new R;bd.closestPointToPoint(r,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:e,face:null,faceIndex:null,barycoord:null,object:a})}}class c1 extends Si{constructor(e=[],t=Ua,i,n,s,a,o,c,l,h){super(e,t,i,n,s,a,o,c,l,h),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(e){this.image=e}}class Ls extends Si{constructor(e,t,i,n,s,a,o,c,l){super(e,t,i,n,s,a,o,c,l),this.isCanvasTexture=!0,this.needsUpdate=!0}}class aa extends Si{constructor(e,t,i=_n,n,s,a,o=At,c=At,l,h=Rs,u=1){if(h!==Rs&&h!==Ra)throw new Error("THREE.DepthTexture: format must be either THREE.DepthFormat or THREE.DepthStencilFormat");const d={width:e,height:t,depth:u};super(d,n,s,a,o,c,h,i,l),this.isDepthTexture=!0,this.flipY=!1,this.generateMipmaps=!1,this.compareFunction=null}copy(e){return super.copy(e),this.source=new _0(Object.assign({},e.image)),this.compareFunction=e.compareFunction,this}toJSON(e){const t=super.toJSON(e);return this.compareFunction!==null&&(t.compareFunction=this.compareFunction),t}}class px extends aa{constructor(e,t=_n,i=Ua,n,s,a=At,o=At,c,l=Rs){const h={width:e,height:e,depth:1},u=[h,h,h,h,h,h];super(e,e,t,i,n,s,a,o,c,l),this.image=u,this.isCubeDepthTexture=!0,this.isCubeTexture=!0}get images(){return this.image}set images(e){this.image=e}}class l1 extends Si{constructor(e=null){super(),this.sourceTexture=e,this.isExternalTexture=!0}copy(e){return super.copy(e),this.sourceTexture=e.sourceTexture,this}}class Xi extends ot{constructor(e=1,t=1,i=1,n=1,s=1,a=1){super(),this.type="BoxGeometry",this.parameters={width:e,height:t,depth:i,widthSegments:n,heightSegments:s,depthSegments:a};const o=this;n=Math.floor(n),s=Math.floor(s),a=Math.floor(a);const c=[],l=[],h=[],u=[];let d=0,f=0;p("z","y","x",-1,-1,i,t,e,a,s,0),p("z","y","x",1,-1,i,t,-e,a,s,1),p("x","z","y",1,1,e,i,t,n,a,2),p("x","z","y",1,-1,e,i,-t,n,a,3),p("x","y","z",1,-1,e,t,i,n,s,4),p("x","y","z",-1,-1,e,t,-i,n,s,5),this.setIndex(c),this.setAttribute("position",new ut(l,3)),this.setAttribute("normal",new ut(h,3)),this.setAttribute("uv",new ut(u,2));function p(v,m,g,_,b,M,S,w,T,x,A){const C=M/T,I=S/x,P=M/2,V=S/2,X=w/2,L=T+1,B=x+1;let k=0,$=0;const ee=new R;for(let J=0;J<B;J++){const ie=J*I-V;for(let re=0;re<L;re++){const Ve=re*C-P;ee[v]=Ve*_,ee[m]=ie*b,ee[g]=X,l.push(ee.x,ee.y,ee.z),ee[v]=0,ee[m]=0,ee[g]=w>0?1:-1,h.push(ee.x,ee.y,ee.z),u.push(re/T),u.push(1-J/x),k+=1}}for(let J=0;J<x;J++)for(let ie=0;ie<T;ie++){const re=d+ie+L*J,Ve=d+ie+L*(J+1),Je=d+(ie+1)+L*(J+1),qe=d+(ie+1)+L*J;c.push(re,Ve,qe),c.push(Ve,Je,qe),$+=6}o.addGroup(f,$,A),f+=$,d+=k}}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new Xi(e.width,e.height,e.depth,e.widthSegments,e.heightSegments,e.depthSegments)}}class T0 extends ot{constructor(e=1,t=32,i=0,n=Math.PI*2){super(),this.type="CircleGeometry",this.parameters={radius:e,segments:t,thetaStart:i,thetaLength:n},t=Math.max(3,t);const s=[],a=[],o=[],c=[],l=new R,h=new xe;a.push(0,0,0),o.push(0,0,1),c.push(.5,.5);for(let u=0,d=3;u<=t;u++,d+=3){const f=i+u/t*n;l.x=e*Math.cos(f),l.y=e*Math.sin(f),a.push(l.x,l.y,l.z),o.push(0,0,1),h.x=(a[d]/e+1)/2,h.y=(a[d+1]/e+1)/2,c.push(h.x,h.y)}for(let u=1;u<=t;u++)s.push(u,u+1,0);this.setIndex(s),this.setAttribute("position",new ut(a,3)),this.setAttribute("normal",new ut(o,3)),this.setAttribute("uv",new ut(c,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new T0(e.radius,e.segments,e.thetaStart,e.thetaLength)}}class cs extends ot{constructor(e=1,t=1,i=1,n=32,s=1,a=!1,o=0,c=Math.PI*2){super(),this.type="CylinderGeometry",this.parameters={radiusTop:e,radiusBottom:t,height:i,radialSegments:n,heightSegments:s,openEnded:a,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;_(),a===!1&&(e>0&&b(!0),t>0&&b(!1)),this.setIndex(h),this.setAttribute("position",new ut(u,3)),this.setAttribute("normal",new ut(d,3)),this.setAttribute("uv",new ut(f,2));function _(){const M=new R,S=new R;let w=0;const T=(t-e)/i;for(let x=0;x<=s;x++){const A=[],C=x/s,I=C*(t-e)+e;for(let P=0;P<=n;P++){const V=P/n,X=V*c+o,L=Math.sin(X),B=Math.cos(X);S.x=I*L,S.y=-C*i+m,S.z=I*B,u.push(S.x,S.y,S.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 x=0;x<n;x++)for(let A=0;A<s;A++){const C=v[A][x],I=v[A+1][x],P=v[A+1][x+1],V=v[A][x+1];(e>0||A!==0)&&(h.push(C,I,V),w+=3),(t>0||A!==s-1)&&(h.push(I,P,V),w+=3)}l.addGroup(g,w,0),g+=w}function b(M){const S=p,w=new xe,T=new R;let x=0;const A=M===!0?e:t,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=S+P,X=I+P;M===!0?h.push(X,X+1,V):h.push(X+1,X,V),x+=3}l.addGroup(g,x,M===!0?1:2),g+=x}}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new cs(e.radiusTop,e.radiusBottom,e.height,e.radialSegments,e.heightSegments,e.openEnded,e.thetaStart,e.thetaLength)}}class Gr extends cs{constructor(e=1,t=1,i=32,n=1,s=!1,a=0,o=Math.PI*2){super(0,e,t,i,n,s,a,o),this.type="ConeGeometry",this.parameters={radius:e,height:t,radialSegments:i,heightSegments:n,openEnded:s,thetaStart:a,thetaLength:o}}static fromJSON(e){return new Gr(e.radius,e.height,e.radialSegments,e.heightSegments,e.openEnded,e.thetaStart,e.thetaLength)}}class $l extends ot{constructor(e=[new xe(0,-.5),new xe(.5,0),new xe(0,.5)],t=12,i=0,n=Math.PI*2){super(),this.type="LatheGeometry",this.parameters={points:e,segments:t,phiStart:i,phiLength:n},t=Math.floor(t),n=et(n,0,Math.PI*2);const s=[],a=[],o=[],c=[],l=[],h=1/t,u=new R,d=new xe,f=new R,p=new R,v=new R;let m=0,g=0;for(let _=0;_<=e.length-1;_++)switch(_){case 0:m=e[_+1].x-e[_].x,g=e[_+1].y-e[_].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 e.length-1:c.push(v.x,v.y,v.z);break;default:m=e[_+1].x-e[_].x,g=e[_+1].y-e[_].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 _=0;_<=t;_++){const b=i+_*h*n,M=Math.sin(b),S=Math.cos(b);for(let w=0;w<=e.length-1;w++){u.x=e[w].x*M,u.y=e[w].y,u.z=e[w].x*S,a.push(u.x,u.y,u.z),d.x=_/t,d.y=w/(e.length-1),o.push(d.x,d.y);const T=c[3*w+0]*M,x=c[3*w+1],A=c[3*w+0]*S;l.push(T,x,A)}}for(let _=0;_<t;_++)for(let b=0;b<e.length-1;b++){const M=b+_*e.length,S=M,w=M+e.length,T=M+e.length+1,x=M+1;s.push(S,w,x),s.push(T,x,w)}this.setIndex(s),this.setAttribute("position",new ut(a,3)),this.setAttribute("uv",new ut(o,2)),this.setAttribute("normal",new ut(l,3))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new $l(e.points,e.segments,e.phiStart,e.phiLength)}}class Yi extends ot{constructor(e=1,t=1,i=1,n=1){super(),this.type="PlaneGeometry",this.parameters={width:e,height:t,widthSegments:i,heightSegments:n};const s=e/2,a=t/2,o=Math.floor(i),c=Math.floor(n),l=o+1,h=c+1,u=e/o,d=t/c,f=[],p=[],v=[],m=[];for(let g=0;g<h;g++){const _=g*d-a;for(let b=0;b<l;b++){const M=b*u-s;p.push(M,-_,0),v.push(0,0,1),m.push(b/o),m.push(1-g/c)}}for(let g=0;g<c;g++)for(let _=0;_<o;_++){const b=_+l*g,M=_+l*(g+1),S=_+1+l*(g+1),w=_+1+l*g;f.push(b,M,w),f.push(M,S,w)}this.setIndex(f),this.setAttribute("position",new ut(p,3)),this.setAttribute("normal",new ut(v,3)),this.setAttribute("uv",new ut(m,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new Yi(e.width,e.height,e.widthSegments,e.heightSegments)}}class ri extends ot{constructor(e=1,t=32,i=16,n=0,s=Math.PI*2,a=0,o=Math.PI){super(),this.type="SphereGeometry",this.parameters={radius:e,widthSegments:t,heightSegments:i,phiStart:n,phiLength:s,thetaStart:a,thetaLength:o},t=Math.max(3,Math.floor(t)),i=Math.max(2,Math.floor(i));const c=Math.min(a+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 _=[],b=g/i,M=a+b*o,S=e*Math.cos(M),w=Math.sqrt(e*e-S*S);let T=0;g===0&&a===0?T=.5/t:g===i&&c===Math.PI&&(T=-.5/t);for(let x=0;x<=t;x++){const A=x/t,C=n+A*s;u.x=-w*Math.cos(C),u.y=S,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-b),_.push(l++)}h.push(_)}for(let g=0;g<i;g++)for(let _=0;_<t;_++){const b=h[g][_+1],M=h[g][_],S=h[g+1][_],w=h[g+1][_+1];(g!==0||a>0)&&f.push(b,M,w),(g!==i-1||c<Math.PI)&&f.push(M,S,w)}this.setIndex(f),this.setAttribute("position",new ut(p,3)),this.setAttribute("normal",new ut(v,3)),this.setAttribute("uv",new ut(m,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new ri(e.radius,e.widthSegments,e.heightSegments,e.phiStart,e.phiLength,e.thetaStart,e.thetaLength)}}class R0 extends ot{constructor(e=1,t=.4,i=12,n=48,s=Math.PI*2,a=0,o=Math.PI*2){super(),this.type="TorusGeometry",this.parameters={radius:e,tube:t,radialSegments:i,tubularSegments:n,arc:s,thetaStart:a,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=a+v/i*o;for(let g=0;g<=n;g++){const _=g/n*s;f.x=(e+t*Math.cos(m))*Math.cos(_),f.y=(e+t*Math.cos(m))*Math.sin(_),f.z=t*Math.sin(m),l.push(f.x,f.y,f.z),d.x=e*Math.cos(_),d.y=e*Math.sin(_),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,_=(n+1)*(v-1)+m-1,b=(n+1)*(v-1)+m,M=(n+1)*v+m;c.push(g,_,M),c.push(_,b,M)}this.setIndex(c),this.setAttribute("position",new ut(l,3)),this.setAttribute("normal",new ut(h,3)),this.setAttribute("uv",new ut(u,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new R0(e.radius,e.tube,e.radialSegments,e.tubularSegments,e.arc)}}function Br(r){const e={};for(const t in r){e[t]={};for(const i in r[t]){const n=r[t][i];if(bp(n))n.isRenderTargetTexture?(Re("UniformsUtils: Textures of render targets cannot be cloned via cloneUniforms() or mergeUniforms()."),e[t][i]=null):e[t][i]=n.clone();else if(Array.isArray(n))if(bp(n[0])){const s=[];for(let a=0,o=n.length;a<o;a++)s[a]=n[a].clone();e[t][i]=s}else e[t][i]=n.slice();else e[t][i]=n}}return e}function Ui(r){const e={};for(let t=0;t<r.length;t++){const i=Br(r[t]);for(const n in i)e[n]=i[n]}return e}function bp(r){return r&&(r.isColor||r.isMatrix3||r.isMatrix4||r.isVector2||r.isVector3||r.isVector4||r.isTexture||r.isQuaternion)}function mx(r){const e=[];for(let t=0;t<r.length;t++)e.push(r[t].clone());return e}function h1(r){const e=r.getRenderTarget();return e===null?r.outputColorSpace:e.isXRRenderTarget===!0?e.texture.colorSpace:at.workingColorSpace}const gx={clone:Br,merge:Ui};var vx=`void main() {
|
|
1306
1306
|
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
1307
1307
|
}`,Mx=`void main() {
|
|
1308
1308
|
gl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );
|
|
@@ -4976,7 +4976,7 @@ void main() {
|
|
|
4976
4976
|
#include <tonemapping_fragment>
|
|
4977
4977
|
#include <colorspace_fragment>
|
|
4978
4978
|
#include <fog_fragment>
|
|
4979
|
-
}`,Xe={alphahash_fragment:ey,alphahash_pars_fragment:ty,alphamap_fragment:iy,alphamap_pars_fragment:ny,alphatest_fragment:sy,alphatest_pars_fragment:ay,aomap_fragment:ry,aomap_pars_fragment:oy,batching_pars_vertex:cy,batching_vertex:ly,begin_vertex:hy,beginnormal_vertex:uy,bsdfs:dy,iridescence_fragment:fy,bumpmap_pars_fragment:py,clipping_planes_fragment:my,clipping_planes_pars_fragment:gy,clipping_planes_pars_vertex:vy,clipping_planes_vertex:My,color_fragment:xy,color_pars_fragment:yy,color_pars_vertex:by,color_vertex:_y,common:Sy,cube_uv_reflection_fragment:wy,defaultnormal_vertex:Ey,displacementmap_pars_vertex:Ay,displacementmap_vertex:Ty,emissivemap_fragment:Ry,emissivemap_pars_fragment:Dy,colorspace_fragment:Iy,colorspace_pars_fragment:Cy,envmap_fragment:Py,envmap_common_pars_fragment:Ly,envmap_pars_fragment:Oy,envmap_pars_vertex:Ny,envmap_physical_pars_fragment:Yy,envmap_vertex:Fy,fog_vertex:Uy,fog_pars_vertex:ky,fog_fragment:zy,fog_pars_fragment:By,gradientmap_pars_fragment:Hy,lightmap_pars_fragment:Gy,lights_lambert_fragment:Vy,lights_lambert_pars_fragment:Wy,lights_pars_begin:Xy,lights_toon_fragment:qy,lights_toon_pars_fragment:$y,lights_phong_fragment:Ky,lights_phong_pars_fragment:Zy,lights_physical_fragment:Jy,lights_physical_pars_fragment:jy,lights_fragment_begin:Qy,lights_fragment_maps:eb,lights_fragment_end:tb,lightprobes_pars_fragment:ib,logdepthbuf_fragment:nb,logdepthbuf_pars_fragment:sb,logdepthbuf_pars_vertex:ab,logdepthbuf_vertex:rb,map_fragment:ob,map_pars_fragment:cb,map_particle_fragment:lb,map_particle_pars_fragment:hb,metalnessmap_fragment:ub,metalnessmap_pars_fragment:db,morphinstance_vertex:fb,morphcolor_vertex:pb,morphnormal_vertex:mb,morphtarget_pars_vertex:gb,morphtarget_vertex:vb,normal_fragment_begin:Mb,normal_fragment_maps:xb,normal_pars_fragment:yb,normal_pars_vertex:bb,normal_vertex:_b,normalmap_pars_fragment:Sb,clearcoat_normal_fragment_begin:wb,clearcoat_normal_fragment_maps:Eb,clearcoat_pars_fragment:Ab,iridescence_pars_fragment:Tb,opaque_fragment:Rb,packing:Db,premultiplied_alpha_fragment:Ib,project_vertex:Cb,dithering_fragment:Pb,dithering_pars_fragment:Lb,roughnessmap_fragment:Ob,roughnessmap_pars_fragment:Nb,shadowmap_pars_fragment:Fb,shadowmap_pars_vertex:Ub,shadowmap_vertex:kb,shadowmask_pars_fragment:zb,skinbase_vertex:Bb,skinning_pars_vertex:Hb,skinning_vertex:Gb,skinnormal_vertex:Vb,specularmap_fragment:Wb,specularmap_pars_fragment:Xb,tonemapping_fragment:Yb,tonemapping_pars_fragment:qb,transmission_fragment:$b,transmission_pars_fragment:Kb,uv_pars_fragment:Zb,uv_pars_vertex:Jb,uv_vertex:jb,worldpos_vertex:Qb,background_vert:e_,background_frag:t_,backgroundCube_vert:i_,backgroundCube_frag:n_,cube_vert:s_,cube_frag:a_,depth_vert:r_,depth_frag:o_,distance_vert:c_,distance_frag:l_,equirect_vert:h_,equirect_frag:u_,linedashed_vert:d_,linedashed_frag:f_,meshbasic_vert:p_,meshbasic_frag:m_,meshlambert_vert:g_,meshlambert_frag:v_,meshmatcap_vert:M_,meshmatcap_frag:x_,meshnormal_vert:y_,meshnormal_frag:b_,meshphong_vert:__,meshphong_frag:S_,meshphysical_vert:w_,meshphysical_frag:E_,meshtoon_vert:A_,meshtoon_frag:T_,points_vert:R_,points_frag:D_,shadow_vert:I_,shadow_frag:C_,sprite_vert:P_,sprite_frag:L_},pe={common:{diffuse:{value:new se(16777215)},opacity:{value:1},map:{value:null},mapTransform:{value:new Ye},alphaMap:{value:null},alphaMapTransform:{value:new Ye},alphaTest:{value:0}},specularmap:{specularMap:{value:null},specularMapTransform:{value:new Ye}},envmap:{envMap:{value:null},envMapRotation:{value:new Ye},reflectivity:{value:1},ior:{value:1.5},refractionRatio:{value:.98},dfgLUT:{value:null}},aomap:{aoMap:{value:null},aoMapIntensity:{value:1},aoMapTransform:{value:new Ye}},lightmap:{lightMap:{value:null},lightMapIntensity:{value:1},lightMapTransform:{value:new Ye}},bumpmap:{bumpMap:{value:null},bumpMapTransform:{value:new Ye},bumpScale:{value:1}},normalmap:{normalMap:{value:null},normalMapTransform:{value:new Ye},normalScale:{value:new xe(1,1)}},displacementmap:{displacementMap:{value:null},displacementMapTransform:{value:new Ye},displacementScale:{value:1},displacementBias:{value:0}},emissivemap:{emissiveMap:{value:null},emissiveMapTransform:{value:new Ye}},metalnessmap:{metalnessMap:{value:null},metalnessMapTransform:{value:new Ye}},roughnessmap:{roughnessMap:{value:null},roughnessMapTransform:{value:new Ye}},gradientmap:{gradientMap:{value:null}},fog:{fogDensity:{value:25e-5},fogNear:{value:1},fogFar:{value:2e3},fogColor:{value:new se(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 se(16777215)},opacity:{value:1},size:{value:1},scale:{value:1},map:{value:null},alphaMap:{value:null},alphaMapTransform:{value:new Ye},alphaTest:{value:0},uvTransform:{value:new Ye}},sprite:{diffuse:{value:new se(16777215)},opacity:{value:1},center:{value:new xe(.5,.5)},rotation:{value:0},map:{value:null},mapTransform:{value:new Ye},alphaMap:{value:null},alphaMapTransform:{value:new Ye},alphaTest:{value:0}}},Jn={basic:{uniforms:Ui([pe.common,pe.specularmap,pe.envmap,pe.aomap,pe.lightmap,pe.fog]),vertexShader:Xe.meshbasic_vert,fragmentShader:Xe.meshbasic_frag},lambert:{uniforms:Ui([pe.common,pe.specularmap,pe.envmap,pe.aomap,pe.lightmap,pe.emissivemap,pe.bumpmap,pe.normalmap,pe.displacementmap,pe.fog,pe.lights,{emissive:{value:new se(0)},envMapIntensity:{value:1}}]),vertexShader:Xe.meshlambert_vert,fragmentShader:Xe.meshlambert_frag},phong:{uniforms:Ui([pe.common,pe.specularmap,pe.envmap,pe.aomap,pe.lightmap,pe.emissivemap,pe.bumpmap,pe.normalmap,pe.displacementmap,pe.fog,pe.lights,{emissive:{value:new se(0)},specular:{value:new se(1118481)},shininess:{value:30},envMapIntensity:{value:1}}]),vertexShader:Xe.meshphong_vert,fragmentShader:Xe.meshphong_frag},standard:{uniforms:Ui([pe.common,pe.envmap,pe.aomap,pe.lightmap,pe.emissivemap,pe.bumpmap,pe.normalmap,pe.displacementmap,pe.roughnessmap,pe.metalnessmap,pe.fog,pe.lights,{emissive:{value:new se(0)},roughness:{value:1},metalness:{value:0},envMapIntensity:{value:1}}]),vertexShader:Xe.meshphysical_vert,fragmentShader:Xe.meshphysical_frag},toon:{uniforms:Ui([pe.common,pe.aomap,pe.lightmap,pe.emissivemap,pe.bumpmap,pe.normalmap,pe.displacementmap,pe.gradientmap,pe.fog,pe.lights,{emissive:{value:new se(0)}}]),vertexShader:Xe.meshtoon_vert,fragmentShader:Xe.meshtoon_frag},matcap:{uniforms:Ui([pe.common,pe.bumpmap,pe.normalmap,pe.displacementmap,pe.fog,{matcap:{value:null}}]),vertexShader:Xe.meshmatcap_vert,fragmentShader:Xe.meshmatcap_frag},points:{uniforms:Ui([pe.points,pe.fog]),vertexShader:Xe.points_vert,fragmentShader:Xe.points_frag},dashed:{uniforms:Ui([pe.common,pe.fog,{scale:{value:1},dashSize:{value:1},totalSize:{value:2}}]),vertexShader:Xe.linedashed_vert,fragmentShader:Xe.linedashed_frag},depth:{uniforms:Ui([pe.common,pe.displacementmap]),vertexShader:Xe.depth_vert,fragmentShader:Xe.depth_frag},normal:{uniforms:Ui([pe.common,pe.bumpmap,pe.normalmap,pe.displacementmap,{opacity:{value:1}}]),vertexShader:Xe.meshnormal_vert,fragmentShader:Xe.meshnormal_frag},sprite:{uniforms:Ui([pe.sprite,pe.fog]),vertexShader:Xe.sprite_vert,fragmentShader:Xe.sprite_frag},background:{uniforms:{uvTransform:{value:new Ye},t2D:{value:null},backgroundIntensity:{value:1}},vertexShader:Xe.background_vert,fragmentShader:Xe.background_frag},backgroundCube:{uniforms:{envMap:{value:null},backgroundBlurriness:{value:0},backgroundIntensity:{value:1},backgroundRotation:{value:new Ye}},vertexShader:Xe.backgroundCube_vert,fragmentShader:Xe.backgroundCube_frag},cube:{uniforms:{tCube:{value:null},tFlip:{value:-1},opacity:{value:1}},vertexShader:Xe.cube_vert,fragmentShader:Xe.cube_frag},equirect:{uniforms:{tEquirect:{value:null}},vertexShader:Xe.equirect_vert,fragmentShader:Xe.equirect_frag},distance:{uniforms:Ui([pe.common,pe.displacementmap,{referencePosition:{value:new R},nearDistance:{value:1},farDistance:{value:1e3}}]),vertexShader:Xe.distance_vert,fragmentShader:Xe.distance_frag},shadow:{uniforms:Ui([pe.lights,pe.fog,{color:{value:new se(0)},opacity:{value:1}}]),vertexShader:Xe.shadow_vert,fragmentShader:Xe.shadow_frag}};Jn.physical={uniforms:Ui([Jn.standard.uniforms,{clearcoat:{value:0},clearcoatMap:{value:null},clearcoatMapTransform:{value:new Ye},clearcoatNormalMap:{value:null},clearcoatNormalMapTransform:{value:new Ye},clearcoatNormalScale:{value:new xe(1,1)},clearcoatRoughness:{value:0},clearcoatRoughnessMap:{value:null},clearcoatRoughnessMapTransform:{value:new Ye},dispersion:{value:0},iridescence:{value:0},iridescenceMap:{value:null},iridescenceMapTransform:{value:new Ye},iridescenceIOR:{value:1.3},iridescenceThicknessMinimum:{value:100},iridescenceThicknessMaximum:{value:400},iridescenceThicknessMap:{value:null},iridescenceThicknessMapTransform:{value:new Ye},sheen:{value:0},sheenColor:{value:new se(0)},sheenColorMap:{value:null},sheenColorMapTransform:{value:new Ye},sheenRoughness:{value:1},sheenRoughnessMap:{value:null},sheenRoughnessMapTransform:{value:new Ye},transmission:{value:0},transmissionMap:{value:null},transmissionMapTransform:{value:new Ye},transmissionSamplerSize:{value:new xe},transmissionSamplerMap:{value:null},thickness:{value:0},thicknessMap:{value:null},thicknessMapTransform:{value:new Ye},attenuationDistance:{value:0},attenuationColor:{value:new se(0)},specularColor:{value:new se(1,1,1)},specularColorMap:{value:null},specularColorMapTransform:{value:new Ye},specularIntensity:{value:1},specularIntensityMap:{value:null},specularIntensityMapTransform:{value:new Ye},anisotropyVector:{value:new xe},anisotropyMap:{value:null},anisotropyMapTransform:{value:new Ye}}]),vertexShader:Xe.meshphysical_vert,fragmentShader:Xe.meshphysical_frag};const zc={r:0,b:0,g:0},O_=new Ze,x1=new Ye;x1.set(-1,0,0,0,1,0,0,0,1);function N_(r,e,t,i,n,s){const a=new se(0);let o=n===!0?0:1,c,l,h=null,u=0,d=null;function f(_){let b=_.isScene===!0?_.background:null;if(b&&b.isTexture){const M=_.backgroundBlurriness>0;b=e.get(b,M)}return b}function p(_){let b=!1;const M=f(_);M===null?m(a,o):M&&M.isColor&&(m(M,1),b=!0);const S=r.xr.getEnvironmentBlendMode();S==="additive"?t.buffers.color.setClear(0,0,0,1,s):S==="alpha-blend"&&t.buffers.color.setClear(0,0,0,0,s),(r.autoClear||b)&&(t.buffers.depth.setTest(!0),t.buffers.depth.setMask(!0),t.buffers.color.setMask(!0),r.clear(r.autoClearColor,r.autoClearDepth,r.autoClearStencil))}function v(_,b){const M=f(b);M&&(M.isCubeTexture||M.mapping===Yl)?(l===void 0&&(l=new De(new Wi(1,1,1),new ct({name:"BackgroundCubeMaterial",uniforms:Br(Jn.backgroundCube.uniforms),vertexShader:Jn.backgroundCube.vertexShader,fragmentShader:Jn.backgroundCube.fragmentShader,side:Ht,depthTest:!1,depthWrite:!1,fog:!1,allowOverride:!1})),l.geometry.deleteAttribute("normal"),l.geometry.deleteAttribute("uv"),l.onBeforeRender=function(S,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=b.backgroundBlurriness,l.material.uniforms.backgroundIntensity.value=b.backgroundIntensity,l.material.uniforms.backgroundRotation.value.setFromMatrix4(O_.makeRotationFromEuler(b.backgroundRotation)).transpose(),M.isCubeTexture&&M.isRenderTargetTexture===!1&&l.material.uniforms.backgroundRotation.value.premultiply(x1),l.material.toneMapped=at.getTransfer(M.colorSpace)!==yt,(h!==M||u!==M.version||d!==r.toneMapping)&&(l.material.needsUpdate=!0,h=M,u=M.version,d=r.toneMapping),l.layers.enableAll(),_.unshift(l,l.geometry,l.material,0,0,null)):M&&M.isTexture&&(c===void 0&&(c=new De(new Xi(2,2),new ct({name:"BackgroundMaterial",uniforms:Br(Jn.background.uniforms),vertexShader:Jn.background.vertexShader,fragmentShader:Jn.background.fragmentShader,side:sa,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=b.backgroundIntensity,c.material.toneMapped=at.getTransfer(M.colorSpace)!==yt,M.matrixAutoUpdate===!0&&M.updateMatrix(),c.material.uniforms.uvTransform.value.copy(M.matrix),(h!==M||u!==M.version||d!==r.toneMapping)&&(c.material.needsUpdate=!0,h=M,u=M.version,d=r.toneMapping),c.layers.enableAll(),_.unshift(c,c.geometry,c.material,0,0,null))}function m(_,b){_.getRGB(zc,h1(r)),t.buffers.color.setClear(zc.r,zc.g,zc.b,b,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 a},setClearColor:function(_,b=1){a.set(_),o=b,m(a,o)},getClearAlpha:function(){return o},setClearAlpha:function(_){o=_,m(a,o)},render:p,addToRenderList:v,dispose:g}}function F_(r,e){const t=r.getParameter(r.MAX_VERTEX_ATTRIBS),i={},n=d(null);let s=n,a=!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&&e.update(L,r.ELEMENT_ARRAY_BUFFER),(B||a)&&(a=!1,M(I,P,V,X),L!==null&&r.bindBuffer(r.ELEMENT_ARRAY_BUFFER,e.get(L).buffer))}function c(){return r.createVertexArray()}function l(I){return r.bindVertexArray(I)}function h(I){return r.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 ee=$[V.id];ee===void 0&&(ee={},$[V.id]=ee);let J=ee[L];return J===void 0&&(J=d(c()),ee[L]=J),J}function d(I){const P=[],V=[],X=[];for(let L=0;L<t;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 ee in $)if($[ee].location>=0){const ie=L[ee];let re=B[ee];if(re===void 0&&(ee==="instanceMatrix"&&I.instanceMatrix&&(re=I.instanceMatrix),ee==="instanceColor"&&I.instanceColor&&(re=I.instanceColor)),ie===void 0||ie.attribute!==re||re&&ie.data!==re.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 ee in $)if($[ee].location>=0){let ie=B[ee];ie===void 0&&(ee==="instanceMatrix"&&I.instanceMatrix&&(ie=I.instanceMatrix),ee==="instanceColor"&&I.instanceColor&&(ie=I.instanceColor));const re={};re.attribute=ie,ie&&ie.data&&(re.data=ie.data),L[ee]=re,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&&(r.enableVertexAttribArray(I),X[I]=1),L[I]!==P&&(r.vertexAttribDivisor(I,P),L[I]=P)}function _(){const I=s.newAttributes,P=s.enabledAttributes;for(let V=0,X=P.length;V<X;V++)P[V]!==I[V]&&(r.disableVertexAttribArray(V),P[V]=0)}function b(I,P,V,X,L,B,k){k===!0?r.vertexAttribIPointer(I,P,V,L,B):r.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 ee=B[$];if(ee.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 ie=J.normalized,re=J.itemSize,Ve=e.get(J);if(Ve===void 0)continue;const Je=Ve.buffer,qe=Ve.type,q=Ve.bytesPerElement,ae=qe===r.INT||qe===r.UNSIGNED_INT||J.gpuType===d0;if(J.isInterleavedBufferAttribute){const ne=J.data,z=ne.stride,Te=J.offset;if(ne.isInstancedInterleavedBuffer){for(let Ne=0;Ne<ee.locationSize;Ne++)g(ee.location+Ne,ne.meshPerAttribute);I.isInstancedMesh!==!0&&X._maxInstanceCount===void 0&&(X._maxInstanceCount=ne.meshPerAttribute*ne.count)}else for(let Ne=0;Ne<ee.locationSize;Ne++)m(ee.location+Ne);r.bindBuffer(r.ARRAY_BUFFER,Je);for(let Ne=0;Ne<ee.locationSize;Ne++)b(ee.location+Ne,re/ee.locationSize,qe,ie,z*q,(Te+re/ee.locationSize*Ne)*q,ae)}else{if(J.isInstancedBufferAttribute){for(let ne=0;ne<ee.locationSize;ne++)g(ee.location+ne,J.meshPerAttribute);I.isInstancedMesh!==!0&&X._maxInstanceCount===void 0&&(X._maxInstanceCount=J.meshPerAttribute*J.count)}else for(let ne=0;ne<ee.locationSize;ne++)m(ee.location+ne);r.bindBuffer(r.ARRAY_BUFFER,Je);for(let ne=0;ne<ee.locationSize;ne++)b(ee.location+ne,re/ee.locationSize,qe,ie,re*q,re/ee.locationSize*ne*q,ae)}}else if(k!==void 0){const ie=k[$];if(ie!==void 0)switch(ie.length){case 2:r.vertexAttrib2fv(ee.location,ie);break;case 3:r.vertexAttrib3fv(ee.location,ie);break;case 4:r.vertexAttrib4fv(ee.location,ie);break;default:r.vertexAttrib1fv(ee.location,ie)}}}}_()}function S(){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 x(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(),a=!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:S,releaseStatesOfGeometry:w,releaseStatesOfObject:x,releaseStatesOfProgram:T,initAttributes:v,enableAttribute:m,disableUnusedAttributes:_}}function U_(r,e,t){let i;function n(c){i=c}function s(c,l){r.drawArrays(i,c,l),t.update(l,i,1)}function a(c,l,h){h!==0&&(r.drawArraysInstanced(i,c,l,h),t.update(l,i,h))}function o(c,l,h){if(h===0)return;e.get("WEBGL_multi_draw").multiDrawArraysWEBGL(i,c,0,l,0,h);let d=0;for(let f=0;f<h;f++)d+=l[f];t.update(d,i,1)}this.setMode=n,this.render=s,this.renderInstances=a,this.renderMultiDraw=o}function k_(r,e,t,i){let n;function s(){if(n!==void 0)return n;if(e.has("EXT_texture_filter_anisotropic")===!0){const T=e.get("EXT_texture_filter_anisotropic");n=r.getParameter(T.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else n=0;return n}function a(T){return!(T!==Ei&&i.convert(T)!==r.getParameter(r.IMPLEMENTATION_COLOR_READ_FORMAT))}function o(T){const x=T===Wt&&(e.has("EXT_color_buffer_half_float")||e.has("EXT_color_buffer_float"));return!(T!==dn&&i.convert(T)!==r.getParameter(r.IMPLEMENTATION_COLOR_READ_TYPE)&&T!==Oi&&!x)}function c(T){if(T==="highp"){if(r.getShaderPrecisionFormat(r.VERTEX_SHADER,r.HIGH_FLOAT).precision>0&&r.getShaderPrecisionFormat(r.FRAGMENT_SHADER,r.HIGH_FLOAT).precision>0)return"highp";T="mediump"}return T==="mediump"&&r.getShaderPrecisionFormat(r.VERTEX_SHADER,r.MEDIUM_FLOAT).precision>0&&r.getShaderPrecisionFormat(r.FRAGMENT_SHADER,r.MEDIUM_FLOAT).precision>0?"mediump":"lowp"}let l=t.precision!==void 0?t.precision:"highp";const h=c(l);h!==l&&(Re("WebGLRenderer:",l,"not supported, using",h,"instead."),l=h);const u=t.logarithmicDepthBuffer===!0,d=t.reversedDepthBuffer===!0&&e.has("EXT_clip_control");t.reversedDepthBuffer===!0&&d===!1&&Re("WebGLRenderer: Unable to use reversed depth buffer due to missing EXT_clip_control extension. Fallback to default depth buffer.");const f=r.getParameter(r.MAX_TEXTURE_IMAGE_UNITS),p=r.getParameter(r.MAX_VERTEX_TEXTURE_IMAGE_UNITS),v=r.getParameter(r.MAX_TEXTURE_SIZE),m=r.getParameter(r.MAX_CUBE_MAP_TEXTURE_SIZE),g=r.getParameter(r.MAX_VERTEX_ATTRIBS),_=r.getParameter(r.MAX_VERTEX_UNIFORM_VECTORS),b=r.getParameter(r.MAX_VARYING_VECTORS),M=r.getParameter(r.MAX_FRAGMENT_UNIFORM_VECTORS),S=r.getParameter(r.MAX_SAMPLES),w=r.getParameter(r.SAMPLES);return{isWebGL2:!0,getMaxAnisotropy:s,getMaxPrecision:c,textureFormatReadable:a,textureTypeReadable:o,precision:l,logarithmicDepthBuffer:u,reversedDepthBuffer:d,maxTextures:f,maxVertexTextures:p,maxTextureSize:v,maxCubemapSize:m,maxAttributes:g,maxVertexUniforms:_,maxVaryings:b,maxFragmentUniforms:M,maxSamples:S,samples:w}}function z_(r){const e=this;let t=null,i=0,n=!1,s=!1;const a=new Ma,o=new Ye,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){t=h(u,d,0)},this.setState=function(u,d,f){const p=u.clippingPlanes,v=u.clipIntersection,m=u.clipShadows,g=r.get(u);if(!n||p===null||p.length===0||s&&!m)s?h(null):l();else{const _=s?0:i,b=_*4;let M=g.clippingState||null;c.value=M,M=h(p,d,b,f);for(let S=0;S!==b;++S)M[S]=t[S];g.clippingState=M,this.numIntersection=v?this.numPlanes:0,this.numPlanes+=_}};function l(){c.value!==t&&(c.value=t,c.needsUpdate=i>0),e.numPlanes=i,e.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,_=d.matrixWorldInverse;o.getNormalMatrix(_),(m===null||m.length<g)&&(m=new Float32Array(g));for(let b=0,M=f;b!==v;++b,M+=4)a.copy(u[b]).applyMatrix4(_,o),a.normal.toArray(m,M),m[M+3]=a.constant}c.value=m,c.needsUpdate=!0}return e.numPlanes=v,e.numIntersection=0,m}}const js=4,Lp=[.125,.215,.35,.446,.526,.582],Sa=20,B_=256,ro=new zn,Op=new se;let Gh=null,Vh=0,Wh=0,Xh=!1;const H_=new R;class Sd{constructor(e){this._renderer=e,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._sizeLods=[],this._sigmas=[],this._lodMeshes=[],this._backgroundBox=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._blurMaterial=null,this._ggxMaterial=null}fromScene(e,t=0,i=.1,n=100,s={}){const{size:a=256,position:o=H_}=s;Gh=this._renderer.getRenderTarget(),Vh=this._renderer.getActiveCubeFace(),Wh=this._renderer.getActiveMipmapLevel(),Xh=this._renderer.xr.enabled,this._renderer.xr.enabled=!1,this._setSize(a);const c=this._allocateTargets();return c.depthBuffer=!0,this._sceneToCubeUV(e,i,n,c,o),t>0&&this._blur(c,0,0,t),this._applyPMREM(c),this._cleanup(c),c}fromEquirectangular(e,t=null){return this._fromTexture(e,t)}fromCubemap(e,t=null){return this._fromTexture(e,t)}compileCubemapShader(){this._cubemapMaterial===null&&(this._cubemapMaterial=Up(),this._compileMaterial(this._cubemapMaterial))}compileEquirectangularShader(){this._equirectMaterial===null&&(this._equirectMaterial=Fp(),this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),this._cubemapMaterial!==null&&this._cubemapMaterial.dispose(),this._equirectMaterial!==null&&this._equirectMaterial.dispose(),this._backgroundBox!==null&&(this._backgroundBox.geometry.dispose(),this._backgroundBox.material.dispose())}_setSize(e){this._lodMax=Math.floor(Math.log2(e)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){this._blurMaterial!==null&&this._blurMaterial.dispose(),this._ggxMaterial!==null&&this._ggxMaterial.dispose(),this._pingPongRenderTarget!==null&&this._pingPongRenderTarget.dispose();for(let e=0;e<this._lodMeshes.length;e++)this._lodMeshes[e].geometry.dispose()}_cleanup(e){this._renderer.setRenderTarget(Gh,Vh,Wh),this._renderer.xr.enabled=Xh,e.scissorTest=!1,ur(e,0,0,e.width,e.height)}_fromTexture(e,t){e.mapping===Ua||e.mapping===kr?this._setSize(e.image.length===0?16:e.image[0].width||e.image[0].image.width):this._setSize(e.image.width/4),Gh=this._renderer.getRenderTarget(),Vh=this._renderer.getActiveCubeFace(),Wh=this._renderer.getActiveMipmapLevel(),Xh=this._renderer.xr.enabled,this._renderer.xr.enabled=!1;const i=t||this._allocateTargets();return this._textureToCubeUV(e,i),this._applyPMREM(i),this._cleanup(i),i}_allocateTargets(){const e=3*Math.max(this._cubeSize,112),t=4*this._cubeSize,i={magFilter:rt,minFilter:rt,generateMipmaps:!1,type:Wt,format:Ei,colorSpace:El,depthBuffer:!1},n=Np(e,t,i);if(this._pingPongRenderTarget===null||this._pingPongRenderTarget.width!==e||this._pingPongRenderTarget.height!==t){this._pingPongRenderTarget!==null&&this._dispose(),this._pingPongRenderTarget=Np(e,t,i);const{_lodMax:s}=this;({lodMeshes:this._lodMeshes,sizeLods:this._sizeLods,sigmas:this._sigmas}=G_(s)),this._blurMaterial=W_(s,e,t),this._ggxMaterial=V_(s,e,t)}return n}_compileMaterial(e){const t=new De(new ot,e);this._renderer.compile(t,ro)}_sceneToCubeUV(e,t,i,n,s){const c=new Ji(90,1,t,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(Op),u.toneMapping=rs,u.autoClear=!1,u.state.buffers.depth.getReversed()&&(u.setRenderTarget(n),u.clearDepth(),u.setRenderTarget(null)),this._backgroundBox===null&&(this._backgroundBox=new De(new Wi,new bn({name:"PMREM.Background",side:Ht,depthWrite:!1,depthTest:!1})));const v=this._backgroundBox,m=v.material;let g=!1;const _=e.background;_?_.isColor&&(m.color.copy(_),e.background=null,g=!0):(m.color.copy(Op),g=!0);for(let b=0;b<6;b++){const M=b%3;M===0?(c.up.set(0,l[b],0),c.position.set(s.x,s.y,s.z),c.lookAt(s.x+h[b],s.y,s.z)):M===1?(c.up.set(0,0,l[b]),c.position.set(s.x,s.y,s.z),c.lookAt(s.x,s.y+h[b],s.z)):(c.up.set(0,l[b],0),c.position.set(s.x,s.y,s.z),c.lookAt(s.x,s.y,s.z+h[b]));const S=this._cubeSize;ur(n,M*S,b>2?S:0,S,S),u.setRenderTarget(n),g&&u.render(v,c),u.render(e,c)}u.toneMapping=f,u.autoClear=d,e.background=_}_textureToCubeUV(e,t){const i=this._renderer,n=e.mapping===Ua||e.mapping===kr;n?(this._cubemapMaterial===null&&(this._cubemapMaterial=Up()),this._cubemapMaterial.uniforms.flipEnvMap.value=e.isRenderTargetTexture===!1?-1:1):this._equirectMaterial===null&&(this._equirectMaterial=Fp());const s=n?this._cubemapMaterial:this._equirectMaterial,a=this._lodMeshes[0];a.material=s;const o=s.uniforms;o.envMap.value=e;const c=this._cubeSize;ur(t,0,0,3*c,2*c),i.setRenderTarget(t),i.render(a,ro)}_applyPMREM(e){const t=this._renderer,i=t.autoClear;t.autoClear=!1;const n=this._lodMeshes.length;for(let s=1;s<n;s++)this._applyGGXFilter(e,s-1,s);t.autoClear=i}_applyGGXFilter(e,t,i){const n=this._renderer,s=this._pingPongRenderTarget,a=this._ggxMaterial,o=this._lodMeshes[i];o.material=a;const c=a.uniforms,l=i/(this._lodMeshes.length-1),h=t/(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-js?i-p+js:0),g=4*(this._cubeSize-v);c.envMap.value=e.texture,c.roughness.value=f,c.mipInt.value=p-t,ur(s,m,g,3*v,2*v),n.setRenderTarget(s),n.render(o,ro),c.envMap.value=s.texture,c.roughness.value=0,c.mipInt.value=p-i,ur(e,m,g,3*v,2*v),n.setRenderTarget(e),n.render(o,ro)}_blur(e,t,i,n,s){const a=this._pingPongRenderTarget;this._halfBlur(e,a,t,i,n,"latitudinal",s),this._halfBlur(a,e,i,i,n,"longitudinal",s)}_halfBlur(e,t,i,n,s,a,o){const c=this._renderer,l=this._blurMaterial;a!=="latitudinal"&&a!=="longitudinal"&&Ge("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*Sa-1),v=s/p,m=isFinite(s)?1+Math.floor(h*v):Sa;m>Sa&&Re(`sigmaRadians, ${s}, is too large and will clip, as it requested ${m} samples when the maximum is set to ${Sa}`);const g=[];let _=0;for(let T=0;T<Sa;++T){const x=T/v,A=Math.exp(-x*x/2);g.push(A),T===0?_+=A:T<m&&(_+=2*A)}for(let T=0;T<g.length;T++)g[T]=g[T]/_;d.envMap.value=e.texture,d.samples.value=m,d.weights.value=g,d.latitudinal.value=a==="latitudinal",o&&(d.poleAxis.value=o);const{_lodMax:b}=this;d.dTheta.value=p,d.mipInt.value=b-i;const M=this._sizeLods[n],S=3*M*(n>b-js?n-b+js:0),w=4*(this._cubeSize-M);ur(t,S,w,3*M,2*M),c.setRenderTarget(t),c.render(u,ro)}}function G_(r){const e=[],t=[],i=[];let n=r;const s=r-js+1+Lp.length;for(let a=0;a<s;a++){const o=Math.pow(2,n);e.push(o);let c=1/o;a>r-js?c=Lp[a-r+js-1]:a===0&&(c=0),t.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,_=new Float32Array(v*p*f),b=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,x=w>2?0:-1,A=[T,x,0,T+2/3,x,0,T+2/3,x+1,0,T,x,0,T+2/3,x+1,0,T,x+1,0];_.set(A,v*p*w),b.set(d,m*p*w);const C=[w,w,w,w,w,w];M.set(C,g*p*w)}const S=new ot;S.setAttribute("position",new tt(_,v)),S.setAttribute("uv",new tt(b,m)),S.setAttribute("faceIndex",new tt(M,g)),i.push(new De(S,null)),n>js&&n--}return{lodMeshes:i,sizeLods:e,sigmas:t}}function Np(r,e,t){const i=new ai(r,e,t);return i.texture.mapping=Yl,i.texture.name="PMREM.cubeUv",i.scissorTest=!0,i}function ur(r,e,t,i,n){r.viewport.set(e,t,i,n),r.scissor.set(e,t,i,n)}function V_(r,e,t){return new ct({name:"PMREMGGXConvolution",defines:{GGX_SAMPLES:B_,CUBEUV_TEXEL_WIDTH:1/e,CUBEUV_TEXEL_HEIGHT:1/t,CUBEUV_MAX_MIP:`${r}.0`},uniforms:{envMap:{value:null},roughness:{value:0},mipInt:{value:0}},vertexShader:Zl(),fragmentShader:`
|
|
4979
|
+
}`,Xe={alphahash_fragment:ey,alphahash_pars_fragment:ty,alphamap_fragment:iy,alphamap_pars_fragment:ny,alphatest_fragment:sy,alphatest_pars_fragment:ay,aomap_fragment:ry,aomap_pars_fragment:oy,batching_pars_vertex:cy,batching_vertex:ly,begin_vertex:hy,beginnormal_vertex:uy,bsdfs:dy,iridescence_fragment:fy,bumpmap_pars_fragment:py,clipping_planes_fragment:my,clipping_planes_pars_fragment:gy,clipping_planes_pars_vertex:vy,clipping_planes_vertex:My,color_fragment:xy,color_pars_fragment:yy,color_pars_vertex:by,color_vertex:_y,common:Sy,cube_uv_reflection_fragment:wy,defaultnormal_vertex:Ey,displacementmap_pars_vertex:Ay,displacementmap_vertex:Ty,emissivemap_fragment:Ry,emissivemap_pars_fragment:Dy,colorspace_fragment:Iy,colorspace_pars_fragment:Cy,envmap_fragment:Py,envmap_common_pars_fragment:Ly,envmap_pars_fragment:Oy,envmap_pars_vertex:Ny,envmap_physical_pars_fragment:Yy,envmap_vertex:Fy,fog_vertex:Uy,fog_pars_vertex:ky,fog_fragment:zy,fog_pars_fragment:By,gradientmap_pars_fragment:Hy,lightmap_pars_fragment:Gy,lights_lambert_fragment:Vy,lights_lambert_pars_fragment:Wy,lights_pars_begin:Xy,lights_toon_fragment:qy,lights_toon_pars_fragment:$y,lights_phong_fragment:Ky,lights_phong_pars_fragment:Zy,lights_physical_fragment:Jy,lights_physical_pars_fragment:jy,lights_fragment_begin:Qy,lights_fragment_maps:eb,lights_fragment_end:tb,lightprobes_pars_fragment:ib,logdepthbuf_fragment:nb,logdepthbuf_pars_fragment:sb,logdepthbuf_pars_vertex:ab,logdepthbuf_vertex:rb,map_fragment:ob,map_pars_fragment:cb,map_particle_fragment:lb,map_particle_pars_fragment:hb,metalnessmap_fragment:ub,metalnessmap_pars_fragment:db,morphinstance_vertex:fb,morphcolor_vertex:pb,morphnormal_vertex:mb,morphtarget_pars_vertex:gb,morphtarget_vertex:vb,normal_fragment_begin:Mb,normal_fragment_maps:xb,normal_pars_fragment:yb,normal_pars_vertex:bb,normal_vertex:_b,normalmap_pars_fragment:Sb,clearcoat_normal_fragment_begin:wb,clearcoat_normal_fragment_maps:Eb,clearcoat_pars_fragment:Ab,iridescence_pars_fragment:Tb,opaque_fragment:Rb,packing:Db,premultiplied_alpha_fragment:Ib,project_vertex:Cb,dithering_fragment:Pb,dithering_pars_fragment:Lb,roughnessmap_fragment:Ob,roughnessmap_pars_fragment:Nb,shadowmap_pars_fragment:Fb,shadowmap_pars_vertex:Ub,shadowmap_vertex:kb,shadowmask_pars_fragment:zb,skinbase_vertex:Bb,skinning_pars_vertex:Hb,skinning_vertex:Gb,skinnormal_vertex:Vb,specularmap_fragment:Wb,specularmap_pars_fragment:Xb,tonemapping_fragment:Yb,tonemapping_pars_fragment:qb,transmission_fragment:$b,transmission_pars_fragment:Kb,uv_pars_fragment:Zb,uv_pars_vertex:Jb,uv_vertex:jb,worldpos_vertex:Qb,background_vert:e_,background_frag:t_,backgroundCube_vert:i_,backgroundCube_frag:n_,cube_vert:s_,cube_frag:a_,depth_vert:r_,depth_frag:o_,distance_vert:c_,distance_frag:l_,equirect_vert:h_,equirect_frag:u_,linedashed_vert:d_,linedashed_frag:f_,meshbasic_vert:p_,meshbasic_frag:m_,meshlambert_vert:g_,meshlambert_frag:v_,meshmatcap_vert:M_,meshmatcap_frag:x_,meshnormal_vert:y_,meshnormal_frag:b_,meshphong_vert:__,meshphong_frag:S_,meshphysical_vert:w_,meshphysical_frag:E_,meshtoon_vert:A_,meshtoon_frag:T_,points_vert:R_,points_frag:D_,shadow_vert:I_,shadow_frag:C_,sprite_vert:P_,sprite_frag:L_},pe={common:{diffuse:{value:new se(16777215)},opacity:{value:1},map:{value:null},mapTransform:{value:new Ye},alphaMap:{value:null},alphaMapTransform:{value:new Ye},alphaTest:{value:0}},specularmap:{specularMap:{value:null},specularMapTransform:{value:new Ye}},envmap:{envMap:{value:null},envMapRotation:{value:new Ye},reflectivity:{value:1},ior:{value:1.5},refractionRatio:{value:.98},dfgLUT:{value:null}},aomap:{aoMap:{value:null},aoMapIntensity:{value:1},aoMapTransform:{value:new Ye}},lightmap:{lightMap:{value:null},lightMapIntensity:{value:1},lightMapTransform:{value:new Ye}},bumpmap:{bumpMap:{value:null},bumpMapTransform:{value:new Ye},bumpScale:{value:1}},normalmap:{normalMap:{value:null},normalMapTransform:{value:new Ye},normalScale:{value:new xe(1,1)}},displacementmap:{displacementMap:{value:null},displacementMapTransform:{value:new Ye},displacementScale:{value:1},displacementBias:{value:0}},emissivemap:{emissiveMap:{value:null},emissiveMapTransform:{value:new Ye}},metalnessmap:{metalnessMap:{value:null},metalnessMapTransform:{value:new Ye}},roughnessmap:{roughnessMap:{value:null},roughnessMapTransform:{value:new Ye}},gradientmap:{gradientMap:{value:null}},fog:{fogDensity:{value:25e-5},fogNear:{value:1},fogFar:{value:2e3},fogColor:{value:new se(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 se(16777215)},opacity:{value:1},size:{value:1},scale:{value:1},map:{value:null},alphaMap:{value:null},alphaMapTransform:{value:new Ye},alphaTest:{value:0},uvTransform:{value:new Ye}},sprite:{diffuse:{value:new se(16777215)},opacity:{value:1},center:{value:new xe(.5,.5)},rotation:{value:0},map:{value:null},mapTransform:{value:new Ye},alphaMap:{value:null},alphaMapTransform:{value:new Ye},alphaTest:{value:0}}},Jn={basic:{uniforms:Ui([pe.common,pe.specularmap,pe.envmap,pe.aomap,pe.lightmap,pe.fog]),vertexShader:Xe.meshbasic_vert,fragmentShader:Xe.meshbasic_frag},lambert:{uniforms:Ui([pe.common,pe.specularmap,pe.envmap,pe.aomap,pe.lightmap,pe.emissivemap,pe.bumpmap,pe.normalmap,pe.displacementmap,pe.fog,pe.lights,{emissive:{value:new se(0)},envMapIntensity:{value:1}}]),vertexShader:Xe.meshlambert_vert,fragmentShader:Xe.meshlambert_frag},phong:{uniforms:Ui([pe.common,pe.specularmap,pe.envmap,pe.aomap,pe.lightmap,pe.emissivemap,pe.bumpmap,pe.normalmap,pe.displacementmap,pe.fog,pe.lights,{emissive:{value:new se(0)},specular:{value:new se(1118481)},shininess:{value:30},envMapIntensity:{value:1}}]),vertexShader:Xe.meshphong_vert,fragmentShader:Xe.meshphong_frag},standard:{uniforms:Ui([pe.common,pe.envmap,pe.aomap,pe.lightmap,pe.emissivemap,pe.bumpmap,pe.normalmap,pe.displacementmap,pe.roughnessmap,pe.metalnessmap,pe.fog,pe.lights,{emissive:{value:new se(0)},roughness:{value:1},metalness:{value:0},envMapIntensity:{value:1}}]),vertexShader:Xe.meshphysical_vert,fragmentShader:Xe.meshphysical_frag},toon:{uniforms:Ui([pe.common,pe.aomap,pe.lightmap,pe.emissivemap,pe.bumpmap,pe.normalmap,pe.displacementmap,pe.gradientmap,pe.fog,pe.lights,{emissive:{value:new se(0)}}]),vertexShader:Xe.meshtoon_vert,fragmentShader:Xe.meshtoon_frag},matcap:{uniforms:Ui([pe.common,pe.bumpmap,pe.normalmap,pe.displacementmap,pe.fog,{matcap:{value:null}}]),vertexShader:Xe.meshmatcap_vert,fragmentShader:Xe.meshmatcap_frag},points:{uniforms:Ui([pe.points,pe.fog]),vertexShader:Xe.points_vert,fragmentShader:Xe.points_frag},dashed:{uniforms:Ui([pe.common,pe.fog,{scale:{value:1},dashSize:{value:1},totalSize:{value:2}}]),vertexShader:Xe.linedashed_vert,fragmentShader:Xe.linedashed_frag},depth:{uniforms:Ui([pe.common,pe.displacementmap]),vertexShader:Xe.depth_vert,fragmentShader:Xe.depth_frag},normal:{uniforms:Ui([pe.common,pe.bumpmap,pe.normalmap,pe.displacementmap,{opacity:{value:1}}]),vertexShader:Xe.meshnormal_vert,fragmentShader:Xe.meshnormal_frag},sprite:{uniforms:Ui([pe.sprite,pe.fog]),vertexShader:Xe.sprite_vert,fragmentShader:Xe.sprite_frag},background:{uniforms:{uvTransform:{value:new Ye},t2D:{value:null},backgroundIntensity:{value:1}},vertexShader:Xe.background_vert,fragmentShader:Xe.background_frag},backgroundCube:{uniforms:{envMap:{value:null},backgroundBlurriness:{value:0},backgroundIntensity:{value:1},backgroundRotation:{value:new Ye}},vertexShader:Xe.backgroundCube_vert,fragmentShader:Xe.backgroundCube_frag},cube:{uniforms:{tCube:{value:null},tFlip:{value:-1},opacity:{value:1}},vertexShader:Xe.cube_vert,fragmentShader:Xe.cube_frag},equirect:{uniforms:{tEquirect:{value:null}},vertexShader:Xe.equirect_vert,fragmentShader:Xe.equirect_frag},distance:{uniforms:Ui([pe.common,pe.displacementmap,{referencePosition:{value:new R},nearDistance:{value:1},farDistance:{value:1e3}}]),vertexShader:Xe.distance_vert,fragmentShader:Xe.distance_frag},shadow:{uniforms:Ui([pe.lights,pe.fog,{color:{value:new se(0)},opacity:{value:1}}]),vertexShader:Xe.shadow_vert,fragmentShader:Xe.shadow_frag}};Jn.physical={uniforms:Ui([Jn.standard.uniforms,{clearcoat:{value:0},clearcoatMap:{value:null},clearcoatMapTransform:{value:new Ye},clearcoatNormalMap:{value:null},clearcoatNormalMapTransform:{value:new Ye},clearcoatNormalScale:{value:new xe(1,1)},clearcoatRoughness:{value:0},clearcoatRoughnessMap:{value:null},clearcoatRoughnessMapTransform:{value:new Ye},dispersion:{value:0},iridescence:{value:0},iridescenceMap:{value:null},iridescenceMapTransform:{value:new Ye},iridescenceIOR:{value:1.3},iridescenceThicknessMinimum:{value:100},iridescenceThicknessMaximum:{value:400},iridescenceThicknessMap:{value:null},iridescenceThicknessMapTransform:{value:new Ye},sheen:{value:0},sheenColor:{value:new se(0)},sheenColorMap:{value:null},sheenColorMapTransform:{value:new Ye},sheenRoughness:{value:1},sheenRoughnessMap:{value:null},sheenRoughnessMapTransform:{value:new Ye},transmission:{value:0},transmissionMap:{value:null},transmissionMapTransform:{value:new Ye},transmissionSamplerSize:{value:new xe},transmissionSamplerMap:{value:null},thickness:{value:0},thicknessMap:{value:null},thicknessMapTransform:{value:new Ye},attenuationDistance:{value:0},attenuationColor:{value:new se(0)},specularColor:{value:new se(1,1,1)},specularColorMap:{value:null},specularColorMapTransform:{value:new Ye},specularIntensity:{value:1},specularIntensityMap:{value:null},specularIntensityMapTransform:{value:new Ye},anisotropyVector:{value:new xe},anisotropyMap:{value:null},anisotropyMapTransform:{value:new Ye}}]),vertexShader:Xe.meshphysical_vert,fragmentShader:Xe.meshphysical_frag};const zc={r:0,b:0,g:0},O_=new Ze,x1=new Ye;x1.set(-1,0,0,0,1,0,0,0,1);function N_(r,e,t,i,n,s){const a=new se(0);let o=n===!0?0:1,c,l,h=null,u=0,d=null;function f(_){let b=_.isScene===!0?_.background:null;if(b&&b.isTexture){const M=_.backgroundBlurriness>0;b=e.get(b,M)}return b}function p(_){let b=!1;const M=f(_);M===null?m(a,o):M&&M.isColor&&(m(M,1),b=!0);const S=r.xr.getEnvironmentBlendMode();S==="additive"?t.buffers.color.setClear(0,0,0,1,s):S==="alpha-blend"&&t.buffers.color.setClear(0,0,0,0,s),(r.autoClear||b)&&(t.buffers.depth.setTest(!0),t.buffers.depth.setMask(!0),t.buffers.color.setMask(!0),r.clear(r.autoClearColor,r.autoClearDepth,r.autoClearStencil))}function v(_,b){const M=f(b);M&&(M.isCubeTexture||M.mapping===Yl)?(l===void 0&&(l=new De(new Xi(1,1,1),new ct({name:"BackgroundCubeMaterial",uniforms:Br(Jn.backgroundCube.uniforms),vertexShader:Jn.backgroundCube.vertexShader,fragmentShader:Jn.backgroundCube.fragmentShader,side:Ht,depthTest:!1,depthWrite:!1,fog:!1,allowOverride:!1})),l.geometry.deleteAttribute("normal"),l.geometry.deleteAttribute("uv"),l.onBeforeRender=function(S,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=b.backgroundBlurriness,l.material.uniforms.backgroundIntensity.value=b.backgroundIntensity,l.material.uniforms.backgroundRotation.value.setFromMatrix4(O_.makeRotationFromEuler(b.backgroundRotation)).transpose(),M.isCubeTexture&&M.isRenderTargetTexture===!1&&l.material.uniforms.backgroundRotation.value.premultiply(x1),l.material.toneMapped=at.getTransfer(M.colorSpace)!==yt,(h!==M||u!==M.version||d!==r.toneMapping)&&(l.material.needsUpdate=!0,h=M,u=M.version,d=r.toneMapping),l.layers.enableAll(),_.unshift(l,l.geometry,l.material,0,0,null)):M&&M.isTexture&&(c===void 0&&(c=new De(new Yi(2,2),new ct({name:"BackgroundMaterial",uniforms:Br(Jn.background.uniforms),vertexShader:Jn.background.vertexShader,fragmentShader:Jn.background.fragmentShader,side:sa,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=b.backgroundIntensity,c.material.toneMapped=at.getTransfer(M.colorSpace)!==yt,M.matrixAutoUpdate===!0&&M.updateMatrix(),c.material.uniforms.uvTransform.value.copy(M.matrix),(h!==M||u!==M.version||d!==r.toneMapping)&&(c.material.needsUpdate=!0,h=M,u=M.version,d=r.toneMapping),c.layers.enableAll(),_.unshift(c,c.geometry,c.material,0,0,null))}function m(_,b){_.getRGB(zc,h1(r)),t.buffers.color.setClear(zc.r,zc.g,zc.b,b,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 a},setClearColor:function(_,b=1){a.set(_),o=b,m(a,o)},getClearAlpha:function(){return o},setClearAlpha:function(_){o=_,m(a,o)},render:p,addToRenderList:v,dispose:g}}function F_(r,e){const t=r.getParameter(r.MAX_VERTEX_ATTRIBS),i={},n=d(null);let s=n,a=!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&&e.update(L,r.ELEMENT_ARRAY_BUFFER),(B||a)&&(a=!1,M(I,P,V,X),L!==null&&r.bindBuffer(r.ELEMENT_ARRAY_BUFFER,e.get(L).buffer))}function c(){return r.createVertexArray()}function l(I){return r.bindVertexArray(I)}function h(I){return r.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 ee=$[V.id];ee===void 0&&(ee={},$[V.id]=ee);let J=ee[L];return J===void 0&&(J=d(c()),ee[L]=J),J}function d(I){const P=[],V=[],X=[];for(let L=0;L<t;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 ee in $)if($[ee].location>=0){const ie=L[ee];let re=B[ee];if(re===void 0&&(ee==="instanceMatrix"&&I.instanceMatrix&&(re=I.instanceMatrix),ee==="instanceColor"&&I.instanceColor&&(re=I.instanceColor)),ie===void 0||ie.attribute!==re||re&&ie.data!==re.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 ee in $)if($[ee].location>=0){let ie=B[ee];ie===void 0&&(ee==="instanceMatrix"&&I.instanceMatrix&&(ie=I.instanceMatrix),ee==="instanceColor"&&I.instanceColor&&(ie=I.instanceColor));const re={};re.attribute=ie,ie&&ie.data&&(re.data=ie.data),L[ee]=re,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&&(r.enableVertexAttribArray(I),X[I]=1),L[I]!==P&&(r.vertexAttribDivisor(I,P),L[I]=P)}function _(){const I=s.newAttributes,P=s.enabledAttributes;for(let V=0,X=P.length;V<X;V++)P[V]!==I[V]&&(r.disableVertexAttribArray(V),P[V]=0)}function b(I,P,V,X,L,B,k){k===!0?r.vertexAttribIPointer(I,P,V,L,B):r.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 ee=B[$];if(ee.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 ie=J.normalized,re=J.itemSize,Ve=e.get(J);if(Ve===void 0)continue;const Je=Ve.buffer,qe=Ve.type,q=Ve.bytesPerElement,ae=qe===r.INT||qe===r.UNSIGNED_INT||J.gpuType===d0;if(J.isInterleavedBufferAttribute){const ne=J.data,z=ne.stride,Te=J.offset;if(ne.isInstancedInterleavedBuffer){for(let Ne=0;Ne<ee.locationSize;Ne++)g(ee.location+Ne,ne.meshPerAttribute);I.isInstancedMesh!==!0&&X._maxInstanceCount===void 0&&(X._maxInstanceCount=ne.meshPerAttribute*ne.count)}else for(let Ne=0;Ne<ee.locationSize;Ne++)m(ee.location+Ne);r.bindBuffer(r.ARRAY_BUFFER,Je);for(let Ne=0;Ne<ee.locationSize;Ne++)b(ee.location+Ne,re/ee.locationSize,qe,ie,z*q,(Te+re/ee.locationSize*Ne)*q,ae)}else{if(J.isInstancedBufferAttribute){for(let ne=0;ne<ee.locationSize;ne++)g(ee.location+ne,J.meshPerAttribute);I.isInstancedMesh!==!0&&X._maxInstanceCount===void 0&&(X._maxInstanceCount=J.meshPerAttribute*J.count)}else for(let ne=0;ne<ee.locationSize;ne++)m(ee.location+ne);r.bindBuffer(r.ARRAY_BUFFER,Je);for(let ne=0;ne<ee.locationSize;ne++)b(ee.location+ne,re/ee.locationSize,qe,ie,re*q,re/ee.locationSize*ne*q,ae)}}else if(k!==void 0){const ie=k[$];if(ie!==void 0)switch(ie.length){case 2:r.vertexAttrib2fv(ee.location,ie);break;case 3:r.vertexAttrib3fv(ee.location,ie);break;case 4:r.vertexAttrib4fv(ee.location,ie);break;default:r.vertexAttrib1fv(ee.location,ie)}}}}_()}function S(){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 x(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(),a=!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:S,releaseStatesOfGeometry:w,releaseStatesOfObject:x,releaseStatesOfProgram:T,initAttributes:v,enableAttribute:m,disableUnusedAttributes:_}}function U_(r,e,t){let i;function n(c){i=c}function s(c,l){r.drawArrays(i,c,l),t.update(l,i,1)}function a(c,l,h){h!==0&&(r.drawArraysInstanced(i,c,l,h),t.update(l,i,h))}function o(c,l,h){if(h===0)return;e.get("WEBGL_multi_draw").multiDrawArraysWEBGL(i,c,0,l,0,h);let d=0;for(let f=0;f<h;f++)d+=l[f];t.update(d,i,1)}this.setMode=n,this.render=s,this.renderInstances=a,this.renderMultiDraw=o}function k_(r,e,t,i){let n;function s(){if(n!==void 0)return n;if(e.has("EXT_texture_filter_anisotropic")===!0){const T=e.get("EXT_texture_filter_anisotropic");n=r.getParameter(T.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else n=0;return n}function a(T){return!(T!==Ei&&i.convert(T)!==r.getParameter(r.IMPLEMENTATION_COLOR_READ_FORMAT))}function o(T){const x=T===Wt&&(e.has("EXT_color_buffer_half_float")||e.has("EXT_color_buffer_float"));return!(T!==dn&&i.convert(T)!==r.getParameter(r.IMPLEMENTATION_COLOR_READ_TYPE)&&T!==Oi&&!x)}function c(T){if(T==="highp"){if(r.getShaderPrecisionFormat(r.VERTEX_SHADER,r.HIGH_FLOAT).precision>0&&r.getShaderPrecisionFormat(r.FRAGMENT_SHADER,r.HIGH_FLOAT).precision>0)return"highp";T="mediump"}return T==="mediump"&&r.getShaderPrecisionFormat(r.VERTEX_SHADER,r.MEDIUM_FLOAT).precision>0&&r.getShaderPrecisionFormat(r.FRAGMENT_SHADER,r.MEDIUM_FLOAT).precision>0?"mediump":"lowp"}let l=t.precision!==void 0?t.precision:"highp";const h=c(l);h!==l&&(Re("WebGLRenderer:",l,"not supported, using",h,"instead."),l=h);const u=t.logarithmicDepthBuffer===!0,d=t.reversedDepthBuffer===!0&&e.has("EXT_clip_control");t.reversedDepthBuffer===!0&&d===!1&&Re("WebGLRenderer: Unable to use reversed depth buffer due to missing EXT_clip_control extension. Fallback to default depth buffer.");const f=r.getParameter(r.MAX_TEXTURE_IMAGE_UNITS),p=r.getParameter(r.MAX_VERTEX_TEXTURE_IMAGE_UNITS),v=r.getParameter(r.MAX_TEXTURE_SIZE),m=r.getParameter(r.MAX_CUBE_MAP_TEXTURE_SIZE),g=r.getParameter(r.MAX_VERTEX_ATTRIBS),_=r.getParameter(r.MAX_VERTEX_UNIFORM_VECTORS),b=r.getParameter(r.MAX_VARYING_VECTORS),M=r.getParameter(r.MAX_FRAGMENT_UNIFORM_VECTORS),S=r.getParameter(r.MAX_SAMPLES),w=r.getParameter(r.SAMPLES);return{isWebGL2:!0,getMaxAnisotropy:s,getMaxPrecision:c,textureFormatReadable:a,textureTypeReadable:o,precision:l,logarithmicDepthBuffer:u,reversedDepthBuffer:d,maxTextures:f,maxVertexTextures:p,maxTextureSize:v,maxCubemapSize:m,maxAttributes:g,maxVertexUniforms:_,maxVaryings:b,maxFragmentUniforms:M,maxSamples:S,samples:w}}function z_(r){const e=this;let t=null,i=0,n=!1,s=!1;const a=new Ma,o=new Ye,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){t=h(u,d,0)},this.setState=function(u,d,f){const p=u.clippingPlanes,v=u.clipIntersection,m=u.clipShadows,g=r.get(u);if(!n||p===null||p.length===0||s&&!m)s?h(null):l();else{const _=s?0:i,b=_*4;let M=g.clippingState||null;c.value=M,M=h(p,d,b,f);for(let S=0;S!==b;++S)M[S]=t[S];g.clippingState=M,this.numIntersection=v?this.numPlanes:0,this.numPlanes+=_}};function l(){c.value!==t&&(c.value=t,c.needsUpdate=i>0),e.numPlanes=i,e.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,_=d.matrixWorldInverse;o.getNormalMatrix(_),(m===null||m.length<g)&&(m=new Float32Array(g));for(let b=0,M=f;b!==v;++b,M+=4)a.copy(u[b]).applyMatrix4(_,o),a.normal.toArray(m,M),m[M+3]=a.constant}c.value=m,c.needsUpdate=!0}return e.numPlanes=v,e.numIntersection=0,m}}const js=4,Lp=[.125,.215,.35,.446,.526,.582],Sa=20,B_=256,ro=new zn,Op=new se;let Gh=null,Vh=0,Wh=0,Xh=!1;const H_=new R;class Sd{constructor(e){this._renderer=e,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._sizeLods=[],this._sigmas=[],this._lodMeshes=[],this._backgroundBox=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._blurMaterial=null,this._ggxMaterial=null}fromScene(e,t=0,i=.1,n=100,s={}){const{size:a=256,position:o=H_}=s;Gh=this._renderer.getRenderTarget(),Vh=this._renderer.getActiveCubeFace(),Wh=this._renderer.getActiveMipmapLevel(),Xh=this._renderer.xr.enabled,this._renderer.xr.enabled=!1,this._setSize(a);const c=this._allocateTargets();return c.depthBuffer=!0,this._sceneToCubeUV(e,i,n,c,o),t>0&&this._blur(c,0,0,t),this._applyPMREM(c),this._cleanup(c),c}fromEquirectangular(e,t=null){return this._fromTexture(e,t)}fromCubemap(e,t=null){return this._fromTexture(e,t)}compileCubemapShader(){this._cubemapMaterial===null&&(this._cubemapMaterial=Up(),this._compileMaterial(this._cubemapMaterial))}compileEquirectangularShader(){this._equirectMaterial===null&&(this._equirectMaterial=Fp(),this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),this._cubemapMaterial!==null&&this._cubemapMaterial.dispose(),this._equirectMaterial!==null&&this._equirectMaterial.dispose(),this._backgroundBox!==null&&(this._backgroundBox.geometry.dispose(),this._backgroundBox.material.dispose())}_setSize(e){this._lodMax=Math.floor(Math.log2(e)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){this._blurMaterial!==null&&this._blurMaterial.dispose(),this._ggxMaterial!==null&&this._ggxMaterial.dispose(),this._pingPongRenderTarget!==null&&this._pingPongRenderTarget.dispose();for(let e=0;e<this._lodMeshes.length;e++)this._lodMeshes[e].geometry.dispose()}_cleanup(e){this._renderer.setRenderTarget(Gh,Vh,Wh),this._renderer.xr.enabled=Xh,e.scissorTest=!1,ur(e,0,0,e.width,e.height)}_fromTexture(e,t){e.mapping===Ua||e.mapping===kr?this._setSize(e.image.length===0?16:e.image[0].width||e.image[0].image.width):this._setSize(e.image.width/4),Gh=this._renderer.getRenderTarget(),Vh=this._renderer.getActiveCubeFace(),Wh=this._renderer.getActiveMipmapLevel(),Xh=this._renderer.xr.enabled,this._renderer.xr.enabled=!1;const i=t||this._allocateTargets();return this._textureToCubeUV(e,i),this._applyPMREM(i),this._cleanup(i),i}_allocateTargets(){const e=3*Math.max(this._cubeSize,112),t=4*this._cubeSize,i={magFilter:rt,minFilter:rt,generateMipmaps:!1,type:Wt,format:Ei,colorSpace:El,depthBuffer:!1},n=Np(e,t,i);if(this._pingPongRenderTarget===null||this._pingPongRenderTarget.width!==e||this._pingPongRenderTarget.height!==t){this._pingPongRenderTarget!==null&&this._dispose(),this._pingPongRenderTarget=Np(e,t,i);const{_lodMax:s}=this;({lodMeshes:this._lodMeshes,sizeLods:this._sizeLods,sigmas:this._sigmas}=G_(s)),this._blurMaterial=W_(s,e,t),this._ggxMaterial=V_(s,e,t)}return n}_compileMaterial(e){const t=new De(new ot,e);this._renderer.compile(t,ro)}_sceneToCubeUV(e,t,i,n,s){const c=new Ji(90,1,t,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(Op),u.toneMapping=rs,u.autoClear=!1,u.state.buffers.depth.getReversed()&&(u.setRenderTarget(n),u.clearDepth(),u.setRenderTarget(null)),this._backgroundBox===null&&(this._backgroundBox=new De(new Xi,new bn({name:"PMREM.Background",side:Ht,depthWrite:!1,depthTest:!1})));const v=this._backgroundBox,m=v.material;let g=!1;const _=e.background;_?_.isColor&&(m.color.copy(_),e.background=null,g=!0):(m.color.copy(Op),g=!0);for(let b=0;b<6;b++){const M=b%3;M===0?(c.up.set(0,l[b],0),c.position.set(s.x,s.y,s.z),c.lookAt(s.x+h[b],s.y,s.z)):M===1?(c.up.set(0,0,l[b]),c.position.set(s.x,s.y,s.z),c.lookAt(s.x,s.y+h[b],s.z)):(c.up.set(0,l[b],0),c.position.set(s.x,s.y,s.z),c.lookAt(s.x,s.y,s.z+h[b]));const S=this._cubeSize;ur(n,M*S,b>2?S:0,S,S),u.setRenderTarget(n),g&&u.render(v,c),u.render(e,c)}u.toneMapping=f,u.autoClear=d,e.background=_}_textureToCubeUV(e,t){const i=this._renderer,n=e.mapping===Ua||e.mapping===kr;n?(this._cubemapMaterial===null&&(this._cubemapMaterial=Up()),this._cubemapMaterial.uniforms.flipEnvMap.value=e.isRenderTargetTexture===!1?-1:1):this._equirectMaterial===null&&(this._equirectMaterial=Fp());const s=n?this._cubemapMaterial:this._equirectMaterial,a=this._lodMeshes[0];a.material=s;const o=s.uniforms;o.envMap.value=e;const c=this._cubeSize;ur(t,0,0,3*c,2*c),i.setRenderTarget(t),i.render(a,ro)}_applyPMREM(e){const t=this._renderer,i=t.autoClear;t.autoClear=!1;const n=this._lodMeshes.length;for(let s=1;s<n;s++)this._applyGGXFilter(e,s-1,s);t.autoClear=i}_applyGGXFilter(e,t,i){const n=this._renderer,s=this._pingPongRenderTarget,a=this._ggxMaterial,o=this._lodMeshes[i];o.material=a;const c=a.uniforms,l=i/(this._lodMeshes.length-1),h=t/(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-js?i-p+js:0),g=4*(this._cubeSize-v);c.envMap.value=e.texture,c.roughness.value=f,c.mipInt.value=p-t,ur(s,m,g,3*v,2*v),n.setRenderTarget(s),n.render(o,ro),c.envMap.value=s.texture,c.roughness.value=0,c.mipInt.value=p-i,ur(e,m,g,3*v,2*v),n.setRenderTarget(e),n.render(o,ro)}_blur(e,t,i,n,s){const a=this._pingPongRenderTarget;this._halfBlur(e,a,t,i,n,"latitudinal",s),this._halfBlur(a,e,i,i,n,"longitudinal",s)}_halfBlur(e,t,i,n,s,a,o){const c=this._renderer,l=this._blurMaterial;a!=="latitudinal"&&a!=="longitudinal"&&Ge("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*Sa-1),v=s/p,m=isFinite(s)?1+Math.floor(h*v):Sa;m>Sa&&Re(`sigmaRadians, ${s}, is too large and will clip, as it requested ${m} samples when the maximum is set to ${Sa}`);const g=[];let _=0;for(let T=0;T<Sa;++T){const x=T/v,A=Math.exp(-x*x/2);g.push(A),T===0?_+=A:T<m&&(_+=2*A)}for(let T=0;T<g.length;T++)g[T]=g[T]/_;d.envMap.value=e.texture,d.samples.value=m,d.weights.value=g,d.latitudinal.value=a==="latitudinal",o&&(d.poleAxis.value=o);const{_lodMax:b}=this;d.dTheta.value=p,d.mipInt.value=b-i;const M=this._sizeLods[n],S=3*M*(n>b-js?n-b+js:0),w=4*(this._cubeSize-M);ur(t,S,w,3*M,2*M),c.setRenderTarget(t),c.render(u,ro)}}function G_(r){const e=[],t=[],i=[];let n=r;const s=r-js+1+Lp.length;for(let a=0;a<s;a++){const o=Math.pow(2,n);e.push(o);let c=1/o;a>r-js?c=Lp[a-r+js-1]:a===0&&(c=0),t.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,_=new Float32Array(v*p*f),b=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,x=w>2?0:-1,A=[T,x,0,T+2/3,x,0,T+2/3,x+1,0,T,x,0,T+2/3,x+1,0,T,x+1,0];_.set(A,v*p*w),b.set(d,m*p*w);const C=[w,w,w,w,w,w];M.set(C,g*p*w)}const S=new ot;S.setAttribute("position",new tt(_,v)),S.setAttribute("uv",new tt(b,m)),S.setAttribute("faceIndex",new tt(M,g)),i.push(new De(S,null)),n>js&&n--}return{lodMeshes:i,sizeLods:e,sigmas:t}}function Np(r,e,t){const i=new ai(r,e,t);return i.texture.mapping=Yl,i.texture.name="PMREM.cubeUv",i.scissorTest=!0,i}function ur(r,e,t,i,n){r.viewport.set(e,t,i,n),r.scissor.set(e,t,i,n)}function V_(r,e,t){return new ct({name:"PMREMGGXConvolution",defines:{GGX_SAMPLES:B_,CUBEUV_TEXEL_WIDTH:1/e,CUBEUV_TEXEL_HEIGHT:1/t,CUBEUV_MAX_MIP:`${r}.0`},uniforms:{envMap:{value:null},roughness:{value:0},mipInt:{value:0}},vertexShader:Zl(),fragmentShader:`
|
|
4980
4980
|
|
|
4981
4981
|
precision highp float;
|
|
4982
4982
|
precision highp int;
|
|
@@ -5265,7 +5265,7 @@ void main() {
|
|
|
5265
5265
|
gl_FragColor = texture2D( tEquirect, sampleUV );
|
|
5266
5266
|
|
|
5267
5267
|
}
|
|
5268
|
-
`},n=new
|
|
5268
|
+
`},n=new Xi(5,5,5),s=new ct({name:"CubemapFromEquirect",uniforms:Br(i.uniforms),vertexShader:i.vertexShader,fragmentShader:i.fragmentShader,side:Ht,blending:as});s.uniforms.tEquirect.value=t;const a=new De(n,s),o=t.minFilter;return t.minFilter===Ta&&(t.minFilter=rt),new P0(1,10,this).update(e,a),t.minFilter=o,a.geometry.dispose(),a.material.dispose(),this}clear(e,t=!0,i=!0,n=!0){const s=e.getRenderTarget();for(let a=0;a<6;a++)e.setRenderTarget(this,a),e.clear(t,i,n);e.setRenderTarget(s)}}function X_(r){let e=new WeakMap,t=new WeakMap,i=null;function n(d,f=!1){return d==null?null:f?a(d):s(d)}function s(d){if(d&&d.isTexture){const f=d.mapping;if(f===hh||f===uh)if(e.has(d)){const p=e.get(d).texture;return o(p,d.mapping)}else{const p=d.image;if(p&&p.height>0){const v=new qo(p.height);return v.fromEquirectangularTexture(r,d),e.set(d,v),d.addEventListener("dispose",l),o(v.texture,d.mapping)}else return null}}return d}function a(d){if(d&&d.isTexture){const f=d.mapping,p=f===hh||f===uh,v=f===Ua||f===kr;if(p||v){let m=t.get(d);const g=m!==void 0?m.texture.pmremVersion:0;if(d.isRenderTargetTexture&&d.pmremVersion!==g)return i===null&&(i=new Sd(r)),m=p?i.fromEquirectangular(d,m):i.fromCubemap(d,m),m.texture.pmremVersion=d.pmremVersion,t.set(d,m),m.texture;if(m!==void 0)return m.texture;{const _=d.image;return p&&_&&_.height>0||v&&_&&c(_)?(i===null&&(i=new Sd(r)),m=p?i.fromEquirectangular(d):i.fromCubemap(d),m.texture.pmremVersion=d.pmremVersion,t.set(d,m),d.addEventListener("dispose",h),m.texture):null}}}return d}function o(d,f){return f===hh?d.mapping=Ua:f===uh&&(d.mapping=kr),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=e.get(f);p!==void 0&&(e.delete(f),p.dispose())}function h(d){const f=d.target;f.removeEventListener("dispose",h);const p=t.get(f);p!==void 0&&(t.delete(f),p.dispose())}function u(){e=new WeakMap,t=new WeakMap,i!==null&&(i.dispose(),i=null)}return{get:n,dispose:u}}function Y_(r){const e={};function t(i){if(e[i]!==void 0)return e[i];const n=r.getExtension(i);return e[i]=n,n}return{has:function(i){return t(i)!==null},init:function(){t("EXT_color_buffer_float"),t("WEBGL_clip_cull_distance"),t("OES_texture_float_linear"),t("EXT_color_buffer_half_float"),t("WEBGL_multisampled_render_to_texture"),t("WEBGL_render_shared_exponent")},get:function(i){const n=t(i);return n===null&&Er("WebGLRenderer: "+i+" extension not supported."),n}}}function q_(r,e,t,i){const n={},s=new WeakMap;function a(u){const d=u.target;d.index!==null&&e.remove(d.index);for(const p in d.attributes)e.remove(d.attributes[p]);d.removeEventListener("dispose",a),delete n[d.id];const f=s.get(d);f&&(e.remove(f),s.delete(d)),i.releaseStatesOfGeometry(d),d.isInstancedBufferGeometry===!0&&delete d._maxInstanceCount,t.memory.geometries--}function o(u,d){return n[d.id]===!0||(d.addEventListener("dispose",a),n[d.id]=!0,t.memory.geometries++),d}function c(u){const d=u.attributes;for(const f in d)e.update(d[f],r.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 _=f.array;v=f.version;for(let b=0,M=_.length;b<M;b+=3){const S=_[b+0],w=_[b+1],T=_[b+2];d.push(S,w,w,T,T,S)}}else{const _=p.array;v=p.version;for(let b=0,M=_.length/3-1;b<M;b+=3){const S=b+0,w=b+1,T=b+2;d.push(S,w,w,T,T,S)}}const m=new(p.count>=65535?E0:n1)(d,1);m.version=v;const g=s.get(u);g&&e.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 $_(r,e,t){let i;function n(u){i=u}let s,a;function o(u){s=u.type,a=u.bytesPerElement}function c(u,d){r.drawElements(i,d,s,u*a),t.update(d,i,1)}function l(u,d,f){f!==0&&(r.drawElementsInstanced(i,d,s,u*a,f),t.update(d,i,f))}function h(u,d,f){if(f===0)return;e.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];t.update(v,i,1)}this.setMode=n,this.setIndex=o,this.render=c,this.renderInstances=l,this.renderMultiDraw=h}function K_(r){const e={geometries:0,textures:0},t={frame:0,calls:0,triangles:0,points:0,lines:0};function i(s,a,o){switch(t.calls++,a){case r.TRIANGLES:t.triangles+=o*(s/3);break;case r.LINES:t.lines+=o*(s/2);break;case r.LINE_STRIP:t.lines+=o*(s-1);break;case r.LINE_LOOP:t.lines+=o*s;break;case r.POINTS:t.points+=o*s;break;default:Ge("WebGLInfo: Unknown draw mode:",a);break}}function n(){t.calls=0,t.triangles=0,t.points=0,t.lines=0}return{memory:e,render:t,programs:null,autoReset:!0,reset:n,update:i}}function Z_(r,e,t){const i=new WeakMap,n=new it;function s(a,o,c){const l=a.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||[],_=o.morphAttributes.color||[];let b=0;f===!0&&(b=1),p===!0&&(b=2),v===!0&&(b=3);let M=o.attributes.position.count*b,S=1;M>e.maxTextureSize&&(S=Math.ceil(M/e.maxTextureSize),M=e.maxTextureSize);const w=new Float32Array(M*S*4*u),T=new e1(w,M,S,u);T.type=Oi,T.needsUpdate=!0;const x=b*4;for(let C=0;C<u;C++){const I=m[C],P=g[C],V=_[C],X=M*S*4*C;for(let L=0;L<I.count;L++){const B=L*x;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 xe(M,S)},i.set(o,d),o.addEventListener("dispose",A)}if(a.isInstancedMesh===!0&&a.morphTexture!==null)c.getUniforms().setValue(r,"morphTexture",a.morphTexture,t);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(r,"morphTargetBaseInfluence",p),c.getUniforms().setValue(r,"morphTargetInfluences",l)}c.getUniforms().setValue(r,"morphTargetsTexture",d.texture,t),c.getUniforms().setValue(r,"morphTargetsTextureSize",d.size)}return{update:s}}function J_(r,e,t,i,n){let s=new WeakMap;function a(l){const h=n.render.frame,u=l.geometry,d=e.get(l,u);if(s.get(d)!==h&&(e.update(d),s.set(d,h)),l.isInstancedMesh&&(l.hasEventListener("dispose",c)===!1&&l.addEventListener("dispose",c),s.get(l)!==h&&(t.update(l.instanceMatrix,r.ARRAY_BUFFER),l.instanceColor!==null&&t.update(l.instanceColor,r.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),t.remove(h.instanceMatrix),h.instanceColor!==null&&t.remove(h.instanceColor)}return{update:a,dispose:o}}const j_={[kg]:"LINEAR_TONE_MAPPING",[zg]:"REINHARD_TONE_MAPPING",[Bg]:"CINEON_TONE_MAPPING",[Hg]:"ACES_FILMIC_TONE_MAPPING",[Vg]:"AGX_TONE_MAPPING",[Wg]:"NEUTRAL_TONE_MAPPING",[Gg]:"CUSTOM_TONE_MAPPING"};function Q_(r,e,t,i,n,s){const a=new ai(e,t,{type:r,depthBuffer:n,stencilBuffer:s,samples:i?4:0,depthTexture:n?new aa(e,t):void 0}),o=new ai(e,t,{type:Wt,depthBuffer:!1,stencilBuffer:!1}),c=new ot;c.setAttribute("position",new ut([-1,3,0,-1,-1,0,3,-1,0],3)),c.setAttribute("uv",new ut([0,2,0,0,2,0],2));const l=new u1({uniforms:{tDiffuse:{value:null}},vertexShader:`
|
|
5269
5269
|
precision highp float;
|
|
5270
5270
|
|
|
5271
5271
|
uniform mat4 modelViewMatrix;
|
|
@@ -5362,7 +5362,7 @@ Material Type: `+I.type+`
|
|
|
5362
5362
|
|
|
5363
5363
|
Program Info Log: `+L+`
|
|
5364
5364
|
`+J+`
|
|
5365
|
-
`+ie)}else L!==""?Re("WebGLProgram: Program Info Log:",L):(B===""||k==="")&&(ee=!1);ee&&(I.diagnostics={runnable:$,programLog:L,vertexShader:{log:B,prefix:m},fragmentShader:{log:k,prefix:g}})}n.deleteShader(S),n.deleteShader(w),x=new fl(n,v),A=eS(n,v)}let x;this.getUniforms=function(){return x===void 0&&T(this),x};let A;this.getAttributes=function(){return A===void 0&&T(this),A};let C=t.rendererExtensionParallelShaderCompile===!1;return this.isReady=function(){return C===!1&&(C=n.getProgramParameter(v,W3)),C},this.destroy=function(){i.releaseStatesOfProgram(this),n.deleteProgram(v),this.program=void 0},this.type=t.shaderType,this.name=t.shaderName,this.id=X3++,this.cacheKey=e,this.usedTimes=1,this.program=v,this.vertexShader=S,this.fragmentShader=w,this}let gS=0;class vS{constructor(){this.shaderCache=new Map,this.materialCache=new Map}update(e,t,i){const n=this._getShaderCacheForMaterial(e);return n.has(t)===!1&&(n.add(t),t.usedTimes++),n.has(i)===!1&&(n.add(i),i.usedTimes++),this}remove(e){const t=this.materialCache.get(e);for(const i of t)i.usedTimes--,i.usedTimes===0&&this.shaderCache.delete(i.code);return this.materialCache.delete(e),this}getVertexShaderStage(e){return this._getShaderStage(e.vertexShader)}getFragmentShaderStage(e){return this._getShaderStage(e.fragmentShader)}dispose(){this.shaderCache.clear(),this.materialCache.clear()}_getShaderCacheForMaterial(e){const t=this.materialCache;let i=t.get(e);return i===void 0&&(i=new Set,t.set(e,i)),i}_getShaderStage(e){const t=this.shaderCache;let i=t.get(e);return i===void 0&&(i=new MS(e),t.set(e,i)),i}}class MS{constructor(e){this.id=gS++,this.code=e,this.usedTimes=0}}function xS(r){return r===ka||r===yl||r===bl}function yS(r,e,t,i,n,s){const a=new S0,o=new vS,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(x){return c.add(x),x===0?"uv":`uv${x}`}function v(x,A,C,I,P,V){const X=I.fog,L=P.geometry,B=x.isMeshStandardMaterial||x.isMeshLambertMaterial||x.isMeshPhongMaterial?I.environment:null,k=x.isMeshStandardMaterial||x.isMeshLambertMaterial&&!x.envMap||x.isMeshPhongMaterial&&!x.envMap,$=e.get(x.envMap||B,k),ee=$&&$.mapping===Yl?$.image.height:null,J=f[x.type];x.precision!==null&&(d=i.getMaxPrecision(x.precision),d!==x.precision&&Re("WebGLProgram.getParameters:",x.precision,"not supported, using",d,"instead."));const ie=L.morphAttributes.position||L.morphAttributes.normal||L.morphAttributes.color,re=ie!==void 0?ie.length:0;let Ve=0;L.morphAttributes.position!==void 0&&(Ve=1),L.morphAttributes.normal!==void 0&&(Ve=2),L.morphAttributes.color!==void 0&&(Ve=3);let Je,qe,q,ae;if(J){const Se=Jn[J];Je=Se.vertexShader,qe=Se.fragmentShader}else{Je=x.vertexShader,qe=x.fragmentShader;const Se=o.getVertexShaderStage(x),$t=o.getFragmentShaderStage(x);o.update(x,Se,$t),q=Se.id,ae=$t.id}const ne=r.getRenderTarget(),z=r.state.buffers.depth.getReversed(),Te=P.isInstancedMesh===!0,Ne=P.isBatchedMesh===!0,Ce=!!x.map,be=!!x.matcap,ke=!!$,ze=!!x.aoMap,Be=!!x.lightMap,gt=!!x.bumpMap&&x.wireframe===!1,vt=!!x.normalMap,Yt=!!x.displacementMap,kt=!!x.emissiveMap,qt=!!x.metalnessMap,oi=!!x.roughnessMap,N=x.anisotropy>0,Yi=x.clearcoat>0,Mt=x.dispersion>0,D=x.iridescence>0,y=x.sheen>0,U=x.transmission>0,W=N&&!!x.anisotropyMap,K=Yi&&!!x.clearcoatMap,oe=Yi&&!!x.clearcoatNormalMap,le=Yi&&!!x.clearcoatRoughnessMap,Z=D&&!!x.iridescenceMap,Q=D&&!!x.iridescenceThicknessMap,he=y&&!!x.sheenColorMap,Pe=y&&!!x.sheenRoughnessMap,fe=!!x.specularMap,ue=!!x.specularColorMap,Ue=!!x.specularIntensityMap,He=U&&!!x.transmissionMap,$e=U&&!!x.thicknessMap,O=!!x.gradientMap,ce=!!x.alphaMap,j=x.alphaTest>0,de=!!x.alphaHash,ve=!!x.extensions;let te=rs;x.toneMapped&&(ne===null||ne.isXRRenderTarget===!0)&&(te=r.toneMapping);const Ie={shaderID:J,shaderType:x.type,shaderName:x.name,vertexShader:Je,fragmentShader:qe,defines:x.defines,customVertexShaderID:q,customFragmentShaderID:ae,isRawShaderMaterial:x.isRawShaderMaterial===!0,glslVersion:x.glslVersion,precision:d,batching:Ne,batchingColor:Ne&&P._colorsTexture!==null,instancing:Te,instancingColor:Te&&P.instanceColor!==null,instancingMorph:Te&&P.morphTexture!==null,outputColorSpace:ne===null?r.outputColorSpace:ne.isXRRenderTarget===!0?ne.texture.colorSpace:at.workingColorSpace,alphaToCoverage:!!x.alphaToCoverage,map:Ce,matcap:be,envMap:ke,envMapMode:ke&&$.mapping,envMapCubeUVHeight:ee,aoMap:ze,lightMap:Be,bumpMap:gt,normalMap:vt,displacementMap:Yt,emissiveMap:kt,normalMapObjectSpace:vt&&x.normalMapType===uM,normalMapTangentSpace:vt&&x.normalMapType===wl,packedNormalMap:vt&&x.normalMapType===wl&&xS(x.normalMap.format),metalnessMap:qt,roughnessMap:oi,anisotropy:N,anisotropyMap:W,clearcoat:Yi,clearcoatMap:K,clearcoatNormalMap:oe,clearcoatRoughnessMap:le,dispersion:Mt,iridescence:D,iridescenceMap:Z,iridescenceThicknessMap:Q,sheen:y,sheenColorMap:he,sheenRoughnessMap:Pe,specularMap:fe,specularColorMap:ue,specularIntensityMap:Ue,transmission:U,transmissionMap:He,thicknessMap:$e,gradientMap:O,opaque:x.transparent===!1&&x.blending===ia&&x.alphaToCoverage===!1,alphaMap:ce,alphaTest:j,alphaHash:de,combine:x.combine,mapUv:Ce&&p(x.map.channel),aoMapUv:ze&&p(x.aoMap.channel),lightMapUv:Be&&p(x.lightMap.channel),bumpMapUv:gt&&p(x.bumpMap.channel),normalMapUv:vt&&p(x.normalMap.channel),displacementMapUv:Yt&&p(x.displacementMap.channel),emissiveMapUv:kt&&p(x.emissiveMap.channel),metalnessMapUv:qt&&p(x.metalnessMap.channel),roughnessMapUv:oi&&p(x.roughnessMap.channel),anisotropyMapUv:W&&p(x.anisotropyMap.channel),clearcoatMapUv:K&&p(x.clearcoatMap.channel),clearcoatNormalMapUv:oe&&p(x.clearcoatNormalMap.channel),clearcoatRoughnessMapUv:le&&p(x.clearcoatRoughnessMap.channel),iridescenceMapUv:Z&&p(x.iridescenceMap.channel),iridescenceThicknessMapUv:Q&&p(x.iridescenceThicknessMap.channel),sheenColorMapUv:he&&p(x.sheenColorMap.channel),sheenRoughnessMapUv:Pe&&p(x.sheenRoughnessMap.channel),specularMapUv:fe&&p(x.specularMap.channel),specularColorMapUv:ue&&p(x.specularColorMap.channel),specularIntensityMapUv:Ue&&p(x.specularIntensityMap.channel),transmissionMapUv:He&&p(x.transmissionMap.channel),thicknessMapUv:$e&&p(x.thicknessMap.channel),alphaMapUv:ce&&p(x.alphaMap.channel),vertexTangents:!!L.attributes.tangent&&(vt||N),vertexNormals:!!L.attributes.normal,vertexColors:x.vertexColors,vertexAlphas:x.vertexColors===!0&&!!L.attributes.color&&L.attributes.color.itemSize===4,pointsUvs:P.isPoints===!0&&!!L.attributes.uv&&(Ce||ce),fog:!!X,useFog:x.fog===!0,fogExp2:!!X&&X.isFogExp2,flatShading:x.wireframe===!1&&(x.flatShading===!0||L.attributes.normal===void 0&&vt===!1&&(x.isMeshLambertMaterial||x.isMeshPhongMaterial||x.isMeshStandardMaterial||x.isMeshPhysicalMaterial)),sizeAttenuation:x.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:re,morphTextureStride:Ve,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:x.dithering,shadowMapEnabled:r.shadowMap.enabled&&C.length>0,shadowMapType:r.shadowMap.type,toneMapping:te,decodeVideoTexture:Ce&&x.map.isVideoTexture===!0&&at.getTransfer(x.map.colorSpace)===yt,decodeVideoTextureEmissive:kt&&x.emissiveMap.isVideoTexture===!0&&at.getTransfer(x.emissiveMap.colorSpace)===yt,premultipliedAlpha:x.premultipliedAlpha,doubleSided:x.side===Qi,flipSided:x.side===Ht,useDepthPacking:x.depthPacking>=0,depthPacking:x.depthPacking||0,index0AttributeName:x.index0AttributeName,extensionClipCullDistance:ve&&x.extensions.clipCullDistance===!0&&t.has("WEBGL_clip_cull_distance"),extensionMultiDraw:(ve&&x.extensions.multiDraw===!0||Ne)&&t.has("WEBGL_multi_draw"),rendererExtensionParallelShaderCompile:t.has("KHR_parallel_shader_compile"),customProgramCacheKey:x.customProgramCacheKey()};return Ie.vertexUv1s=c.has(1),Ie.vertexUv2s=c.has(2),Ie.vertexUv3s=c.has(3),c.clear(),Ie}function m(x){const A=[];if(x.shaderID?A.push(x.shaderID):(A.push(x.customVertexShaderID),A.push(x.customFragmentShaderID)),x.defines!==void 0)for(const C in x.defines)A.push(C),A.push(x.defines[C]);return x.isRawShaderMaterial===!1&&(g(A,x),_(A,x),A.push(r.outputColorSpace)),A.push(x.customProgramCacheKey),A.join()}function g(x,A){x.push(A.precision),x.push(A.outputColorSpace),x.push(A.envMapMode),x.push(A.envMapCubeUVHeight),x.push(A.mapUv),x.push(A.alphaMapUv),x.push(A.lightMapUv),x.push(A.aoMapUv),x.push(A.bumpMapUv),x.push(A.normalMapUv),x.push(A.displacementMapUv),x.push(A.emissiveMapUv),x.push(A.metalnessMapUv),x.push(A.roughnessMapUv),x.push(A.anisotropyMapUv),x.push(A.clearcoatMapUv),x.push(A.clearcoatNormalMapUv),x.push(A.clearcoatRoughnessMapUv),x.push(A.iridescenceMapUv),x.push(A.iridescenceThicknessMapUv),x.push(A.sheenColorMapUv),x.push(A.sheenRoughnessMapUv),x.push(A.specularMapUv),x.push(A.specularColorMapUv),x.push(A.specularIntensityMapUv),x.push(A.transmissionMapUv),x.push(A.thicknessMapUv),x.push(A.combine),x.push(A.fogExp2),x.push(A.sizeAttenuation),x.push(A.morphTargetsCount),x.push(A.morphAttributeCount),x.push(A.numDirLights),x.push(A.numPointLights),x.push(A.numSpotLights),x.push(A.numSpotLightMaps),x.push(A.numHemiLights),x.push(A.numRectAreaLights),x.push(A.numDirLightShadows),x.push(A.numPointLightShadows),x.push(A.numSpotLightShadows),x.push(A.numSpotLightShadowsWithMaps),x.push(A.numLightProbes),x.push(A.shadowMapType),x.push(A.toneMapping),x.push(A.numClippingPlanes),x.push(A.numClipIntersection),x.push(A.depthPacking)}function _(x,A){a.disableAll(),A.instancing&&a.enable(0),A.instancingColor&&a.enable(1),A.instancingMorph&&a.enable(2),A.matcap&&a.enable(3),A.envMap&&a.enable(4),A.normalMapObjectSpace&&a.enable(5),A.normalMapTangentSpace&&a.enable(6),A.clearcoat&&a.enable(7),A.iridescence&&a.enable(8),A.alphaTest&&a.enable(9),A.vertexColors&&a.enable(10),A.vertexAlphas&&a.enable(11),A.vertexUv1s&&a.enable(12),A.vertexUv2s&&a.enable(13),A.vertexUv3s&&a.enable(14),A.vertexTangents&&a.enable(15),A.anisotropy&&a.enable(16),A.alphaHash&&a.enable(17),A.batching&&a.enable(18),A.dispersion&&a.enable(19),A.batchingColor&&a.enable(20),A.gradientMap&&a.enable(21),A.packedNormalMap&&a.enable(22),A.vertexNormals&&a.enable(23),x.push(a.mask),a.disableAll(),A.fog&&a.enable(0),A.useFog&&a.enable(1),A.flatShading&&a.enable(2),A.logarithmicDepthBuffer&&a.enable(3),A.reversedDepthBuffer&&a.enable(4),A.skinning&&a.enable(5),A.morphTargets&&a.enable(6),A.morphNormals&&a.enable(7),A.morphColors&&a.enable(8),A.premultipliedAlpha&&a.enable(9),A.shadowMapEnabled&&a.enable(10),A.doubleSided&&a.enable(11),A.flipSided&&a.enable(12),A.useDepthPacking&&a.enable(13),A.dithering&&a.enable(14),A.transmission&&a.enable(15),A.sheen&&a.enable(16),A.opaque&&a.enable(17),A.pointsUvs&&a.enable(18),A.decodeVideoTexture&&a.enable(19),A.decodeVideoTextureEmissive&&a.enable(20),A.alphaToCoverage&&a.enable(21),A.numLightProbeGrids>0&&a.enable(22),A.hasPositionAttribute&&a.enable(23),x.push(a.mask)}function b(x){const A=f[x.type];let C;if(A){const I=Jn[A];C=gx.clone(I.uniforms)}else C=x.uniforms;return C}function M(x,A){let C=h.get(A);return C!==void 0?++C.usedTimes:(C=new mS(r,A,x,n),l.push(C),h.set(A,C)),C}function S(x){if(--x.usedTimes===0){const A=l.indexOf(x);l[A]=l[l.length-1],l.pop(),h.delete(x.cacheKey),x.destroy()}}function w(x){o.remove(x)}function T(){o.dispose()}return{getParameters:v,getProgramCacheKey:m,getUniforms:b,acquireProgram:M,releaseProgram:S,releaseShaderCache:w,programs:l,dispose:T}}function bS(){let r=new WeakMap;function e(a){return r.has(a)}function t(a){let o=r.get(a);return o===void 0&&(o={},r.set(a,o)),o}function i(a){r.delete(a)}function n(a,o,c){r.get(a)[o]=c}function s(){r=new WeakMap}return{has:e,get:t,remove:i,update:n,dispose:s}}function _S(r,e){return r.groupOrder!==e.groupOrder?r.groupOrder-e.groupOrder:r.renderOrder!==e.renderOrder?r.renderOrder-e.renderOrder:r.material.id!==e.material.id?r.material.id-e.material.id:r.materialVariant!==e.materialVariant?r.materialVariant-e.materialVariant:r.z!==e.z?r.z-e.z:r.id-e.id}function Jp(r,e){return r.groupOrder!==e.groupOrder?r.groupOrder-e.groupOrder:r.renderOrder!==e.renderOrder?r.renderOrder-e.renderOrder:r.z!==e.z?e.z-r.z:r.id-e.id}function jp(){const r=[];let e=0;const t=[],i=[],n=[];function s(){e=0,t.length=0,i.length=0,n.length=0}function a(d){let f=0;return d.isInstancedMesh&&(f+=2),d.isSkinnedMesh&&(f+=1),f}function o(d,f,p,v,m,g){let _=r[e];return _===void 0?(_={id:d.id,object:d,geometry:f,material:p,materialVariant:a(d),groupOrder:v,renderOrder:d.renderOrder,z:m,group:g},r[e]=_):(_.id=d.id,_.object=d,_.geometry=f,_.material=p,_.materialVariant=a(d),_.groupOrder=v,_.renderOrder=d.renderOrder,_.z=m,_.group=g),e++,_}function c(d,f,p,v,m,g){const _=o(d,f,p,v,m,g);p.transmission>0?i.push(_):p.transparent===!0?n.push(_):t.push(_)}function l(d,f,p,v,m,g){const _=o(d,f,p,v,m,g);p.transmission>0?i.unshift(_):p.transparent===!0?n.unshift(_):t.unshift(_)}function h(d,f,p){t.length>1&&t.sort(d||_S),i.length>1&&i.sort(f||Jp),n.length>1&&n.sort(f||Jp),p&&(t.reverse(),i.reverse(),n.reverse())}function u(){for(let d=e,f=r.length;d<f;d++){const p=r[d];if(p.id===null)break;p.id=null,p.object=null,p.geometry=null,p.material=null,p.group=null}}return{opaque:t,transmissive:i,transparent:n,init:s,push:c,unshift:l,finish:u,sort:h}}function SS(){let r=new WeakMap;function e(i,n){const s=r.get(i);let a;return s===void 0?(a=new jp,r.set(i,[a])):n>=s.length?(a=new jp,s.push(a)):a=s[n],a}function t(){r=new WeakMap}return{get:e,dispose:t}}function wS(){const r={};return{get:function(e){if(r[e.id]!==void 0)return r[e.id];let t;switch(e.type){case"DirectionalLight":t={direction:new R,color:new se};break;case"SpotLight":t={position:new R,direction:new R,color:new se,distance:0,coneCos:0,penumbraCos:0,decay:0};break;case"PointLight":t={position:new R,color:new se,distance:0,decay:0};break;case"HemisphereLight":t={direction:new R,skyColor:new se,groundColor:new se};break;case"RectAreaLight":t={color:new se,position:new R,halfWidth:new R,halfHeight:new R};break}return r[e.id]=t,t}}}function ES(){const r={};return{get:function(e){if(r[e.id]!==void 0)return r[e.id];let t;switch(e.type){case"DirectionalLight":t={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new xe};break;case"SpotLight":t={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new xe};break;case"PointLight":t={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new xe,shadowCameraNear:1,shadowCameraFar:1e3};break}return r[e.id]=t,t}}}let AS=0;function TS(r,e){return(e.castShadow?2:0)-(r.castShadow?2:0)+(e.map?1:0)-(r.map?1:0)}function RS(r){const e=new wS,t=ES(),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 Ze,a=new Ze;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,_=0,b=0,M=0,S=0,w=0,T=0;l.sort(TS);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===ka?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=e.get(I);if(B.color.copy(I.color).multiplyScalar(I.intensity),I.castShadow){const k=I.shadow,$=t.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,_++}i.directional[f]=B,f++}else if(I.isSpotLight){const B=e.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[S]=I.map,S++,k.updateMatrices(I),I.castShadow&&w++),i.spotLightMatrix[v]=k.matrix,I.castShadow){const $=t.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=e.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=e.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,$=t.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,b++}i.point[p]=B,p++}else if(I.isHemisphereLight){const B=e.get(I);B.skyColor.copy(I.color).multiplyScalar(V),B.groundColor.copy(I.groundColor).multiplyScalar(V),i.hemi[g]=B,g++}}m>0&&(r.has("OES_texture_float_linear")===!0?(i.rectAreaLTC1=pe.LTC_FLOAT_1,i.rectAreaLTC2=pe.LTC_FLOAT_2):(i.rectAreaLTC1=pe.LTC_HALF_1,i.rectAreaLTC2=pe.LTC_HALF_2)),i.ambient[0]=h,i.ambient[1]=u,i.ambient[2]=d;const x=i.hash;(x.directionalLength!==f||x.pointLength!==p||x.spotLength!==v||x.rectAreaLength!==m||x.hemiLength!==g||x.numDirectionalShadows!==_||x.numPointShadows!==b||x.numSpotShadows!==M||x.numSpotMaps!==S||x.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=_,i.directionalShadowMap.length=_,i.pointShadow.length=b,i.pointShadowMap.length=b,i.spotShadow.length=M,i.spotShadowMap.length=M,i.directionalShadowMatrix.length=_,i.pointShadowMatrix.length=b,i.spotLightMatrix.length=M+S-w,i.spotLightMap.length=S,i.numSpotLightShadowsWithMaps=w,i.numLightProbes=T,x.directionalLength=f,x.pointLength=p,x.spotLength=v,x.rectAreaLength=m,x.hemiLength=g,x.numDirectionalShadows=_,x.numPointShadows=b,x.numSpotShadows=M,x.numSpotMaps=S,x.numLightProbes=T,i.version=AS++)}function c(l,h){let u=0,d=0,f=0,p=0,v=0;const m=h.matrixWorldInverse;for(let g=0,_=l.length;g<_;g++){const b=l[g];if(b.isDirectionalLight){const M=i.directional[u];M.direction.setFromMatrixPosition(b.matrixWorld),n.setFromMatrixPosition(b.target.matrixWorld),M.direction.sub(n),M.direction.transformDirection(m),u++}else if(b.isSpotLight){const M=i.spot[f];M.position.setFromMatrixPosition(b.matrixWorld),M.position.applyMatrix4(m),M.direction.setFromMatrixPosition(b.matrixWorld),n.setFromMatrixPosition(b.target.matrixWorld),M.direction.sub(n),M.direction.transformDirection(m),f++}else if(b.isRectAreaLight){const M=i.rectArea[p];M.position.setFromMatrixPosition(b.matrixWorld),M.position.applyMatrix4(m),a.identity(),s.copy(b.matrixWorld),s.premultiply(m),a.extractRotation(s),M.halfWidth.set(b.width*.5,0,0),M.halfHeight.set(0,b.height*.5,0),M.halfWidth.applyMatrix4(a),M.halfHeight.applyMatrix4(a),p++}else if(b.isPointLight){const M=i.point[d];M.position.setFromMatrixPosition(b.matrixWorld),M.position.applyMatrix4(m),d++}else if(b.isHemisphereLight){const M=i.hemi[v];M.direction.setFromMatrixPosition(b.matrixWorld),M.direction.transformDirection(m),v++}}}return{setup:o,setupView:c,state:i}}function Qp(r){const e=new RS(r),t=[],i=[],n=[];function s(d){u.camera=d,t.length=0,i.length=0,n.length=0}function a(d){t.push(d)}function o(d){i.push(d)}function c(d){n.push(d)}function l(){e.setup(t)}function h(d){e.setupView(t,d)}const u={lightsArray:t,shadowsArray:i,lightProbeGridArray:n,camera:null,lights:e,transmissionRenderTarget:{},textureUnits:0};return{init:s,state:u,setupLights:l,setupLightsView:h,pushLight:a,pushShadow:o,pushLightProbeGrid:c}}function DS(r){let e=new WeakMap;function t(n,s=0){const a=e.get(n);let o;return a===void 0?(o=new Qp(r),e.set(n,[o])):s>=a.length?(o=new Qp(r),a.push(o)):o=a[s],o}function i(){e=new WeakMap}return{get:t,dispose:i}}const IS=`void main() {
|
|
5365
|
+
`+ie)}else L!==""?Re("WebGLProgram: Program Info Log:",L):(B===""||k==="")&&(ee=!1);ee&&(I.diagnostics={runnable:$,programLog:L,vertexShader:{log:B,prefix:m},fragmentShader:{log:k,prefix:g}})}n.deleteShader(S),n.deleteShader(w),x=new fl(n,v),A=eS(n,v)}let x;this.getUniforms=function(){return x===void 0&&T(this),x};let A;this.getAttributes=function(){return A===void 0&&T(this),A};let C=t.rendererExtensionParallelShaderCompile===!1;return this.isReady=function(){return C===!1&&(C=n.getProgramParameter(v,W3)),C},this.destroy=function(){i.releaseStatesOfProgram(this),n.deleteProgram(v),this.program=void 0},this.type=t.shaderType,this.name=t.shaderName,this.id=X3++,this.cacheKey=e,this.usedTimes=1,this.program=v,this.vertexShader=S,this.fragmentShader=w,this}let gS=0;class vS{constructor(){this.shaderCache=new Map,this.materialCache=new Map}update(e,t,i){const n=this._getShaderCacheForMaterial(e);return n.has(t)===!1&&(n.add(t),t.usedTimes++),n.has(i)===!1&&(n.add(i),i.usedTimes++),this}remove(e){const t=this.materialCache.get(e);for(const i of t)i.usedTimes--,i.usedTimes===0&&this.shaderCache.delete(i.code);return this.materialCache.delete(e),this}getVertexShaderStage(e){return this._getShaderStage(e.vertexShader)}getFragmentShaderStage(e){return this._getShaderStage(e.fragmentShader)}dispose(){this.shaderCache.clear(),this.materialCache.clear()}_getShaderCacheForMaterial(e){const t=this.materialCache;let i=t.get(e);return i===void 0&&(i=new Set,t.set(e,i)),i}_getShaderStage(e){const t=this.shaderCache;let i=t.get(e);return i===void 0&&(i=new MS(e),t.set(e,i)),i}}class MS{constructor(e){this.id=gS++,this.code=e,this.usedTimes=0}}function xS(r){return r===ka||r===yl||r===bl}function yS(r,e,t,i,n,s){const a=new S0,o=new vS,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(x){return c.add(x),x===0?"uv":`uv${x}`}function v(x,A,C,I,P,V){const X=I.fog,L=P.geometry,B=x.isMeshStandardMaterial||x.isMeshLambertMaterial||x.isMeshPhongMaterial?I.environment:null,k=x.isMeshStandardMaterial||x.isMeshLambertMaterial&&!x.envMap||x.isMeshPhongMaterial&&!x.envMap,$=e.get(x.envMap||B,k),ee=$&&$.mapping===Yl?$.image.height:null,J=f[x.type];x.precision!==null&&(d=i.getMaxPrecision(x.precision),d!==x.precision&&Re("WebGLProgram.getParameters:",x.precision,"not supported, using",d,"instead."));const ie=L.morphAttributes.position||L.morphAttributes.normal||L.morphAttributes.color,re=ie!==void 0?ie.length:0;let Ve=0;L.morphAttributes.position!==void 0&&(Ve=1),L.morphAttributes.normal!==void 0&&(Ve=2),L.morphAttributes.color!==void 0&&(Ve=3);let Je,qe,q,ae;if(J){const Se=Jn[J];Je=Se.vertexShader,qe=Se.fragmentShader}else{Je=x.vertexShader,qe=x.fragmentShader;const Se=o.getVertexShaderStage(x),$t=o.getFragmentShaderStage(x);o.update(x,Se,$t),q=Se.id,ae=$t.id}const ne=r.getRenderTarget(),z=r.state.buffers.depth.getReversed(),Te=P.isInstancedMesh===!0,Ne=P.isBatchedMesh===!0,Ce=!!x.map,be=!!x.matcap,ke=!!$,ze=!!x.aoMap,Be=!!x.lightMap,gt=!!x.bumpMap&&x.wireframe===!1,vt=!!x.normalMap,Yt=!!x.displacementMap,kt=!!x.emissiveMap,qt=!!x.metalnessMap,oi=!!x.roughnessMap,N=x.anisotropy>0,qi=x.clearcoat>0,Mt=x.dispersion>0,D=x.iridescence>0,y=x.sheen>0,U=x.transmission>0,W=N&&!!x.anisotropyMap,K=qi&&!!x.clearcoatMap,oe=qi&&!!x.clearcoatNormalMap,le=qi&&!!x.clearcoatRoughnessMap,Z=D&&!!x.iridescenceMap,Q=D&&!!x.iridescenceThicknessMap,he=y&&!!x.sheenColorMap,Pe=y&&!!x.sheenRoughnessMap,fe=!!x.specularMap,ue=!!x.specularColorMap,Ue=!!x.specularIntensityMap,He=U&&!!x.transmissionMap,$e=U&&!!x.thicknessMap,O=!!x.gradientMap,ce=!!x.alphaMap,j=x.alphaTest>0,de=!!x.alphaHash,ve=!!x.extensions;let te=rs;x.toneMapped&&(ne===null||ne.isXRRenderTarget===!0)&&(te=r.toneMapping);const Ie={shaderID:J,shaderType:x.type,shaderName:x.name,vertexShader:Je,fragmentShader:qe,defines:x.defines,customVertexShaderID:q,customFragmentShaderID:ae,isRawShaderMaterial:x.isRawShaderMaterial===!0,glslVersion:x.glslVersion,precision:d,batching:Ne,batchingColor:Ne&&P._colorsTexture!==null,instancing:Te,instancingColor:Te&&P.instanceColor!==null,instancingMorph:Te&&P.morphTexture!==null,outputColorSpace:ne===null?r.outputColorSpace:ne.isXRRenderTarget===!0?ne.texture.colorSpace:at.workingColorSpace,alphaToCoverage:!!x.alphaToCoverage,map:Ce,matcap:be,envMap:ke,envMapMode:ke&&$.mapping,envMapCubeUVHeight:ee,aoMap:ze,lightMap:Be,bumpMap:gt,normalMap:vt,displacementMap:Yt,emissiveMap:kt,normalMapObjectSpace:vt&&x.normalMapType===uM,normalMapTangentSpace:vt&&x.normalMapType===wl,packedNormalMap:vt&&x.normalMapType===wl&&xS(x.normalMap.format),metalnessMap:qt,roughnessMap:oi,anisotropy:N,anisotropyMap:W,clearcoat:qi,clearcoatMap:K,clearcoatNormalMap:oe,clearcoatRoughnessMap:le,dispersion:Mt,iridescence:D,iridescenceMap:Z,iridescenceThicknessMap:Q,sheen:y,sheenColorMap:he,sheenRoughnessMap:Pe,specularMap:fe,specularColorMap:ue,specularIntensityMap:Ue,transmission:U,transmissionMap:He,thicknessMap:$e,gradientMap:O,opaque:x.transparent===!1&&x.blending===ia&&x.alphaToCoverage===!1,alphaMap:ce,alphaTest:j,alphaHash:de,combine:x.combine,mapUv:Ce&&p(x.map.channel),aoMapUv:ze&&p(x.aoMap.channel),lightMapUv:Be&&p(x.lightMap.channel),bumpMapUv:gt&&p(x.bumpMap.channel),normalMapUv:vt&&p(x.normalMap.channel),displacementMapUv:Yt&&p(x.displacementMap.channel),emissiveMapUv:kt&&p(x.emissiveMap.channel),metalnessMapUv:qt&&p(x.metalnessMap.channel),roughnessMapUv:oi&&p(x.roughnessMap.channel),anisotropyMapUv:W&&p(x.anisotropyMap.channel),clearcoatMapUv:K&&p(x.clearcoatMap.channel),clearcoatNormalMapUv:oe&&p(x.clearcoatNormalMap.channel),clearcoatRoughnessMapUv:le&&p(x.clearcoatRoughnessMap.channel),iridescenceMapUv:Z&&p(x.iridescenceMap.channel),iridescenceThicknessMapUv:Q&&p(x.iridescenceThicknessMap.channel),sheenColorMapUv:he&&p(x.sheenColorMap.channel),sheenRoughnessMapUv:Pe&&p(x.sheenRoughnessMap.channel),specularMapUv:fe&&p(x.specularMap.channel),specularColorMapUv:ue&&p(x.specularColorMap.channel),specularIntensityMapUv:Ue&&p(x.specularIntensityMap.channel),transmissionMapUv:He&&p(x.transmissionMap.channel),thicknessMapUv:$e&&p(x.thicknessMap.channel),alphaMapUv:ce&&p(x.alphaMap.channel),vertexTangents:!!L.attributes.tangent&&(vt||N),vertexNormals:!!L.attributes.normal,vertexColors:x.vertexColors,vertexAlphas:x.vertexColors===!0&&!!L.attributes.color&&L.attributes.color.itemSize===4,pointsUvs:P.isPoints===!0&&!!L.attributes.uv&&(Ce||ce),fog:!!X,useFog:x.fog===!0,fogExp2:!!X&&X.isFogExp2,flatShading:x.wireframe===!1&&(x.flatShading===!0||L.attributes.normal===void 0&&vt===!1&&(x.isMeshLambertMaterial||x.isMeshPhongMaterial||x.isMeshStandardMaterial||x.isMeshPhysicalMaterial)),sizeAttenuation:x.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:re,morphTextureStride:Ve,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:x.dithering,shadowMapEnabled:r.shadowMap.enabled&&C.length>0,shadowMapType:r.shadowMap.type,toneMapping:te,decodeVideoTexture:Ce&&x.map.isVideoTexture===!0&&at.getTransfer(x.map.colorSpace)===yt,decodeVideoTextureEmissive:kt&&x.emissiveMap.isVideoTexture===!0&&at.getTransfer(x.emissiveMap.colorSpace)===yt,premultipliedAlpha:x.premultipliedAlpha,doubleSided:x.side===Qi,flipSided:x.side===Ht,useDepthPacking:x.depthPacking>=0,depthPacking:x.depthPacking||0,index0AttributeName:x.index0AttributeName,extensionClipCullDistance:ve&&x.extensions.clipCullDistance===!0&&t.has("WEBGL_clip_cull_distance"),extensionMultiDraw:(ve&&x.extensions.multiDraw===!0||Ne)&&t.has("WEBGL_multi_draw"),rendererExtensionParallelShaderCompile:t.has("KHR_parallel_shader_compile"),customProgramCacheKey:x.customProgramCacheKey()};return Ie.vertexUv1s=c.has(1),Ie.vertexUv2s=c.has(2),Ie.vertexUv3s=c.has(3),c.clear(),Ie}function m(x){const A=[];if(x.shaderID?A.push(x.shaderID):(A.push(x.customVertexShaderID),A.push(x.customFragmentShaderID)),x.defines!==void 0)for(const C in x.defines)A.push(C),A.push(x.defines[C]);return x.isRawShaderMaterial===!1&&(g(A,x),_(A,x),A.push(r.outputColorSpace)),A.push(x.customProgramCacheKey),A.join()}function g(x,A){x.push(A.precision),x.push(A.outputColorSpace),x.push(A.envMapMode),x.push(A.envMapCubeUVHeight),x.push(A.mapUv),x.push(A.alphaMapUv),x.push(A.lightMapUv),x.push(A.aoMapUv),x.push(A.bumpMapUv),x.push(A.normalMapUv),x.push(A.displacementMapUv),x.push(A.emissiveMapUv),x.push(A.metalnessMapUv),x.push(A.roughnessMapUv),x.push(A.anisotropyMapUv),x.push(A.clearcoatMapUv),x.push(A.clearcoatNormalMapUv),x.push(A.clearcoatRoughnessMapUv),x.push(A.iridescenceMapUv),x.push(A.iridescenceThicknessMapUv),x.push(A.sheenColorMapUv),x.push(A.sheenRoughnessMapUv),x.push(A.specularMapUv),x.push(A.specularColorMapUv),x.push(A.specularIntensityMapUv),x.push(A.transmissionMapUv),x.push(A.thicknessMapUv),x.push(A.combine),x.push(A.fogExp2),x.push(A.sizeAttenuation),x.push(A.morphTargetsCount),x.push(A.morphAttributeCount),x.push(A.numDirLights),x.push(A.numPointLights),x.push(A.numSpotLights),x.push(A.numSpotLightMaps),x.push(A.numHemiLights),x.push(A.numRectAreaLights),x.push(A.numDirLightShadows),x.push(A.numPointLightShadows),x.push(A.numSpotLightShadows),x.push(A.numSpotLightShadowsWithMaps),x.push(A.numLightProbes),x.push(A.shadowMapType),x.push(A.toneMapping),x.push(A.numClippingPlanes),x.push(A.numClipIntersection),x.push(A.depthPacking)}function _(x,A){a.disableAll(),A.instancing&&a.enable(0),A.instancingColor&&a.enable(1),A.instancingMorph&&a.enable(2),A.matcap&&a.enable(3),A.envMap&&a.enable(4),A.normalMapObjectSpace&&a.enable(5),A.normalMapTangentSpace&&a.enable(6),A.clearcoat&&a.enable(7),A.iridescence&&a.enable(8),A.alphaTest&&a.enable(9),A.vertexColors&&a.enable(10),A.vertexAlphas&&a.enable(11),A.vertexUv1s&&a.enable(12),A.vertexUv2s&&a.enable(13),A.vertexUv3s&&a.enable(14),A.vertexTangents&&a.enable(15),A.anisotropy&&a.enable(16),A.alphaHash&&a.enable(17),A.batching&&a.enable(18),A.dispersion&&a.enable(19),A.batchingColor&&a.enable(20),A.gradientMap&&a.enable(21),A.packedNormalMap&&a.enable(22),A.vertexNormals&&a.enable(23),x.push(a.mask),a.disableAll(),A.fog&&a.enable(0),A.useFog&&a.enable(1),A.flatShading&&a.enable(2),A.logarithmicDepthBuffer&&a.enable(3),A.reversedDepthBuffer&&a.enable(4),A.skinning&&a.enable(5),A.morphTargets&&a.enable(6),A.morphNormals&&a.enable(7),A.morphColors&&a.enable(8),A.premultipliedAlpha&&a.enable(9),A.shadowMapEnabled&&a.enable(10),A.doubleSided&&a.enable(11),A.flipSided&&a.enable(12),A.useDepthPacking&&a.enable(13),A.dithering&&a.enable(14),A.transmission&&a.enable(15),A.sheen&&a.enable(16),A.opaque&&a.enable(17),A.pointsUvs&&a.enable(18),A.decodeVideoTexture&&a.enable(19),A.decodeVideoTextureEmissive&&a.enable(20),A.alphaToCoverage&&a.enable(21),A.numLightProbeGrids>0&&a.enable(22),A.hasPositionAttribute&&a.enable(23),x.push(a.mask)}function b(x){const A=f[x.type];let C;if(A){const I=Jn[A];C=gx.clone(I.uniforms)}else C=x.uniforms;return C}function M(x,A){let C=h.get(A);return C!==void 0?++C.usedTimes:(C=new mS(r,A,x,n),l.push(C),h.set(A,C)),C}function S(x){if(--x.usedTimes===0){const A=l.indexOf(x);l[A]=l[l.length-1],l.pop(),h.delete(x.cacheKey),x.destroy()}}function w(x){o.remove(x)}function T(){o.dispose()}return{getParameters:v,getProgramCacheKey:m,getUniforms:b,acquireProgram:M,releaseProgram:S,releaseShaderCache:w,programs:l,dispose:T}}function bS(){let r=new WeakMap;function e(a){return r.has(a)}function t(a){let o=r.get(a);return o===void 0&&(o={},r.set(a,o)),o}function i(a){r.delete(a)}function n(a,o,c){r.get(a)[o]=c}function s(){r=new WeakMap}return{has:e,get:t,remove:i,update:n,dispose:s}}function _S(r,e){return r.groupOrder!==e.groupOrder?r.groupOrder-e.groupOrder:r.renderOrder!==e.renderOrder?r.renderOrder-e.renderOrder:r.material.id!==e.material.id?r.material.id-e.material.id:r.materialVariant!==e.materialVariant?r.materialVariant-e.materialVariant:r.z!==e.z?r.z-e.z:r.id-e.id}function Jp(r,e){return r.groupOrder!==e.groupOrder?r.groupOrder-e.groupOrder:r.renderOrder!==e.renderOrder?r.renderOrder-e.renderOrder:r.z!==e.z?e.z-r.z:r.id-e.id}function jp(){const r=[];let e=0;const t=[],i=[],n=[];function s(){e=0,t.length=0,i.length=0,n.length=0}function a(d){let f=0;return d.isInstancedMesh&&(f+=2),d.isSkinnedMesh&&(f+=1),f}function o(d,f,p,v,m,g){let _=r[e];return _===void 0?(_={id:d.id,object:d,geometry:f,material:p,materialVariant:a(d),groupOrder:v,renderOrder:d.renderOrder,z:m,group:g},r[e]=_):(_.id=d.id,_.object=d,_.geometry=f,_.material=p,_.materialVariant=a(d),_.groupOrder=v,_.renderOrder=d.renderOrder,_.z=m,_.group=g),e++,_}function c(d,f,p,v,m,g){const _=o(d,f,p,v,m,g);p.transmission>0?i.push(_):p.transparent===!0?n.push(_):t.push(_)}function l(d,f,p,v,m,g){const _=o(d,f,p,v,m,g);p.transmission>0?i.unshift(_):p.transparent===!0?n.unshift(_):t.unshift(_)}function h(d,f,p){t.length>1&&t.sort(d||_S),i.length>1&&i.sort(f||Jp),n.length>1&&n.sort(f||Jp),p&&(t.reverse(),i.reverse(),n.reverse())}function u(){for(let d=e,f=r.length;d<f;d++){const p=r[d];if(p.id===null)break;p.id=null,p.object=null,p.geometry=null,p.material=null,p.group=null}}return{opaque:t,transmissive:i,transparent:n,init:s,push:c,unshift:l,finish:u,sort:h}}function SS(){let r=new WeakMap;function e(i,n){const s=r.get(i);let a;return s===void 0?(a=new jp,r.set(i,[a])):n>=s.length?(a=new jp,s.push(a)):a=s[n],a}function t(){r=new WeakMap}return{get:e,dispose:t}}function wS(){const r={};return{get:function(e){if(r[e.id]!==void 0)return r[e.id];let t;switch(e.type){case"DirectionalLight":t={direction:new R,color:new se};break;case"SpotLight":t={position:new R,direction:new R,color:new se,distance:0,coneCos:0,penumbraCos:0,decay:0};break;case"PointLight":t={position:new R,color:new se,distance:0,decay:0};break;case"HemisphereLight":t={direction:new R,skyColor:new se,groundColor:new se};break;case"RectAreaLight":t={color:new se,position:new R,halfWidth:new R,halfHeight:new R};break}return r[e.id]=t,t}}}function ES(){const r={};return{get:function(e){if(r[e.id]!==void 0)return r[e.id];let t;switch(e.type){case"DirectionalLight":t={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new xe};break;case"SpotLight":t={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new xe};break;case"PointLight":t={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new xe,shadowCameraNear:1,shadowCameraFar:1e3};break}return r[e.id]=t,t}}}let AS=0;function TS(r,e){return(e.castShadow?2:0)-(r.castShadow?2:0)+(e.map?1:0)-(r.map?1:0)}function RS(r){const e=new wS,t=ES(),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 Ze,a=new Ze;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,_=0,b=0,M=0,S=0,w=0,T=0;l.sort(TS);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===ka?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=e.get(I);if(B.color.copy(I.color).multiplyScalar(I.intensity),I.castShadow){const k=I.shadow,$=t.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,_++}i.directional[f]=B,f++}else if(I.isSpotLight){const B=e.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[S]=I.map,S++,k.updateMatrices(I),I.castShadow&&w++),i.spotLightMatrix[v]=k.matrix,I.castShadow){const $=t.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=e.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=e.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,$=t.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,b++}i.point[p]=B,p++}else if(I.isHemisphereLight){const B=e.get(I);B.skyColor.copy(I.color).multiplyScalar(V),B.groundColor.copy(I.groundColor).multiplyScalar(V),i.hemi[g]=B,g++}}m>0&&(r.has("OES_texture_float_linear")===!0?(i.rectAreaLTC1=pe.LTC_FLOAT_1,i.rectAreaLTC2=pe.LTC_FLOAT_2):(i.rectAreaLTC1=pe.LTC_HALF_1,i.rectAreaLTC2=pe.LTC_HALF_2)),i.ambient[0]=h,i.ambient[1]=u,i.ambient[2]=d;const x=i.hash;(x.directionalLength!==f||x.pointLength!==p||x.spotLength!==v||x.rectAreaLength!==m||x.hemiLength!==g||x.numDirectionalShadows!==_||x.numPointShadows!==b||x.numSpotShadows!==M||x.numSpotMaps!==S||x.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=_,i.directionalShadowMap.length=_,i.pointShadow.length=b,i.pointShadowMap.length=b,i.spotShadow.length=M,i.spotShadowMap.length=M,i.directionalShadowMatrix.length=_,i.pointShadowMatrix.length=b,i.spotLightMatrix.length=M+S-w,i.spotLightMap.length=S,i.numSpotLightShadowsWithMaps=w,i.numLightProbes=T,x.directionalLength=f,x.pointLength=p,x.spotLength=v,x.rectAreaLength=m,x.hemiLength=g,x.numDirectionalShadows=_,x.numPointShadows=b,x.numSpotShadows=M,x.numSpotMaps=S,x.numLightProbes=T,i.version=AS++)}function c(l,h){let u=0,d=0,f=0,p=0,v=0;const m=h.matrixWorldInverse;for(let g=0,_=l.length;g<_;g++){const b=l[g];if(b.isDirectionalLight){const M=i.directional[u];M.direction.setFromMatrixPosition(b.matrixWorld),n.setFromMatrixPosition(b.target.matrixWorld),M.direction.sub(n),M.direction.transformDirection(m),u++}else if(b.isSpotLight){const M=i.spot[f];M.position.setFromMatrixPosition(b.matrixWorld),M.position.applyMatrix4(m),M.direction.setFromMatrixPosition(b.matrixWorld),n.setFromMatrixPosition(b.target.matrixWorld),M.direction.sub(n),M.direction.transformDirection(m),f++}else if(b.isRectAreaLight){const M=i.rectArea[p];M.position.setFromMatrixPosition(b.matrixWorld),M.position.applyMatrix4(m),a.identity(),s.copy(b.matrixWorld),s.premultiply(m),a.extractRotation(s),M.halfWidth.set(b.width*.5,0,0),M.halfHeight.set(0,b.height*.5,0),M.halfWidth.applyMatrix4(a),M.halfHeight.applyMatrix4(a),p++}else if(b.isPointLight){const M=i.point[d];M.position.setFromMatrixPosition(b.matrixWorld),M.position.applyMatrix4(m),d++}else if(b.isHemisphereLight){const M=i.hemi[v];M.direction.setFromMatrixPosition(b.matrixWorld),M.direction.transformDirection(m),v++}}}return{setup:o,setupView:c,state:i}}function Qp(r){const e=new RS(r),t=[],i=[],n=[];function s(d){u.camera=d,t.length=0,i.length=0,n.length=0}function a(d){t.push(d)}function o(d){i.push(d)}function c(d){n.push(d)}function l(){e.setup(t)}function h(d){e.setupView(t,d)}const u={lightsArray:t,shadowsArray:i,lightProbeGridArray:n,camera:null,lights:e,transmissionRenderTarget:{},textureUnits:0};return{init:s,state:u,setupLights:l,setupLightsView:h,pushLight:a,pushShadow:o,pushLightProbeGrid:c}}function DS(r){let e=new WeakMap;function t(n,s=0){const a=e.get(n);let o;return a===void 0?(o=new Qp(r),e.set(n,[o])):s>=a.length?(o=new Qp(r),a.push(o)):o=a[s],o}function i(){e=new WeakMap}return{get:t,dispose:i}}const IS=`void main() {
|
|
5366
5366
|
gl_Position = vec4( position, 1.0 );
|
|
5367
5367
|
}`,CS=`uniform sampler2D shadow_pass;
|
|
5368
5368
|
uniform vec2 resolution;
|
|
@@ -5389,7 +5389,7 @@ void main() {
|
|
|
5389
5389
|
squared_mean = squared_mean / samples;
|
|
5390
5390
|
float std_dev = sqrt( max( 0.0, squared_mean - mean * mean ) );
|
|
5391
5391
|
gl_FragColor = vec4( mean, std_dev, 0.0, 1.0 );
|
|
5392
|
-
}`,PS=[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)],LS=[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)],em=new Ze,oo=new R,qh=new R;function OS(r,e,t){let i=new A0;const n=new xe,s=new xe,a=new it,o=new yx,c=new bx,l={},h=t.maxTextureSize,u={[sa]:Ht,[Ht]:sa,[Qi]:Qi},d=new ct({defines:{VSM_SAMPLES:8},uniforms:{shadow_pass:{value:null},resolution:{value:new xe},radius:{value:4}},vertexShader:IS,fragmentShader:CS}),f=d.clone();f.defines.HORIZONTAL_PASS=1;const p=new ot;p.setAttribute("position",new tt(new Float32Array([-1,-1,.5,3,-1,.5,-1,3,.5]),3));const v=new De(p,d),m=this;this.enabled=!1,this.autoUpdate=!0,this.needsUpdate=!1,this.type=To;let g=this.type;this.render=function(w,T,x){if(m.enabled===!1||m.autoUpdate===!1&&m.needsUpdate===!1||w.length===0)return;this.type===B2&&(Re("WebGLShadowMap: PCFSoftShadowMap has been deprecated. Using PCFShadowMap instead."),this.type=To);const A=r.getRenderTarget(),C=r.getActiveCubeFace(),I=r.getActiveMipmapLevel(),P=r.state;P.setBlending(as),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){Re("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 ee=r.state.buffers.depth.getReversed();if(k.camera._reversedDepth=ee,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===xo){if(B.isPointLight){Re("WebGLShadowMap: VSM shadow maps are not supported for PointLights. Use PCF or BasicShadowMap instead.");continue}k.map=new ai(n.x,n.y,{format:ka,type:Wt,minFilter:rt,magFilter:rt,generateMipmaps:!1}),k.map.texture.name=B.name+".shadowMap",k.map.depthTexture=new aa(n.x,n.y,Oi),k.map.depthTexture.name=B.name+".shadowMapDepth",k.map.depthTexture.format=Rs,k.map.depthTexture.compareFunction=null,k.map.depthTexture.minFilter=At,k.map.depthTexture.magFilter=At}else B.isPointLight?(k.map=new qo(n.x),k.map.depthTexture=new px(n.x,_n)):(k.map=new ai(n.x,n.y),k.map.depthTexture=new aa(n.x,n.y,_n)),k.map.depthTexture.name=B.name+".shadowMap",k.map.depthTexture.format=Rs,this.type===To?(k.map.depthTexture.compareFunction=ee?y0:x0,k.map.depthTexture.minFilter=rt,k.map.depthTexture.magFilter=rt):(k.map.depthTexture.compareFunction=null,k.map.depthTexture.minFilter=At,k.map.depthTexture.magFilter=At);k.camera.updateProjectionMatrix()}const J=k.map.isWebGLCubeRenderTarget?6:1;for(let ie=0;ie<J;ie++){if(k.map.isWebGLCubeRenderTarget)r.setRenderTarget(k.map,ie),r.clear();else{ie===0&&(r.setRenderTarget(k.map),r.clear());const re=k.getViewport(ie);a.set(s.x*re.x,s.y*re.y,s.x*re.z,s.y*re.w),P.viewport(a)}if(B.isPointLight){const re=k.camera,Ve=k.matrix,Je=B.distance||re.far;Je!==re.far&&(re.far=Je,re.updateProjectionMatrix()),oo.setFromMatrixPosition(B.matrixWorld),re.position.copy(oo),qh.copy(re.position),qh.add(PS[ie]),re.up.copy(LS[ie]),re.lookAt(qh),re.updateMatrixWorld(),Ve.makeTranslation(-oo.x,-oo.y,-oo.z),em.multiplyMatrices(re.projectionMatrix,re.matrixWorldInverse),k._frustum.setFromProjectionMatrix(em,re.coordinateSystem,re.reversedDepth)}else k.updateMatrices(B);i=k.getFrustum(),M(T,x,k.camera,B,this.type)}k.isPointLightShadow!==!0&&this.type===xo&&_(k,x),k.needsUpdate=!1}g=this.type,m.needsUpdate=!1,r.setRenderTarget(A,C,I)};function _(w,T){const x=e.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 ai(n.x,n.y,{format:ka,type:Wt})),d.uniforms.shadow_pass.value=w.map.depthTexture,d.uniforms.resolution.value=w.mapSize,d.uniforms.radius.value=w.radius,r.setRenderTarget(w.mapPass),r.clear(),r.renderBufferDirect(T,null,x,d,v,null),f.uniforms.shadow_pass.value=w.mapPass.texture,f.uniforms.resolution.value=w.mapSize,f.uniforms.radius.value=w.radius,r.setRenderTarget(w.map),r.clear(),r.renderBufferDirect(T,null,x,f,v,null)}function b(w,T,x,A){let C=null;const I=x.isPointLight===!0?w.customDistanceMaterial:w.customDepthMaterial;if(I!==void 0)C=I;else if(C=x.isPointLight===!0?c:o,r.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",S)),C=L}if(C.visible=T.visible,C.wireframe=T.wireframe,A===xo?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,x.isPointLight===!0&&C.isMeshDistanceMaterial===!0){const P=r.properties.get(C);P.light=x}return C}function M(w,T,x,A,C){if(w.visible===!1)return;if(w.layers.test(T.layers)&&(w.isMesh||w.isLine||w.isPoints)&&(w.castShadow||w.receiveShadow&&C===xo)&&(!w.frustumCulled||i.intersectsObject(w))){w.modelViewMatrix.multiplyMatrices(x.matrixWorldInverse,w.matrixWorld);const V=e.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],ee=X[$.materialIndex];if(ee&&ee.visible){const J=b(w,ee,A,C);w.onBeforeShadow(r,w,T,x,V,J,$),r.renderBufferDirect(x,null,V,J,w,$),w.onAfterShadow(r,w,T,x,V,J,$)}}}else if(X.visible){const L=b(w,X,A,C);w.onBeforeShadow(r,w,T,x,V,L,null),r.renderBufferDirect(x,null,V,L,w,null),w.onAfterShadow(r,w,T,x,V,L,null)}}const P=w.children;for(let V=0,X=P.length;V<X;V++)M(P[V],T,x,A,C)}function S(w){w.target.removeEventListener("dispose",S);for(const x in l){const A=l[x],C=w.target.uuid;C in A&&(A[C].dispose(),delete A[C])}}}function NS(r,e){function t(){let O=!1;const ce=new it;let j=null;const de=new it(0,0,0,0);return{setMask:function(ve){j!==ve&&!O&&(r.colorMask(ve,ve,ve,ve),j=ve)},setLocked:function(ve){O=ve},setClear:function(ve,te,Ie,Se,$t){$t===!0&&(ve*=Se,te*=Se,Ie*=Se),ce.set(ve,te,Ie,Se),de.equals(ce)===!1&&(r.clearColor(ve,te,Ie,Se),de.copy(ce))},reset:function(){O=!1,j=null,de.set(-1,0,0,0)}}}function i(){let O=!1,ce=!1,j=null,de=null,ve=null;return{setReversed:function(te){if(ce!==te){const Ie=e.get("EXT_clip_control");te?Ie.clipControlEXT(Ie.LOWER_LEFT_EXT,Ie.ZERO_TO_ONE_EXT):Ie.clipControlEXT(Ie.LOWER_LEFT_EXT,Ie.NEGATIVE_ONE_TO_ONE_EXT),ce=te;const Se=ve;ve=null,this.setClear(Se)}},getReversed:function(){return ce},setTest:function(te){te?ne(r.DEPTH_TEST):z(r.DEPTH_TEST)},setMask:function(te){j!==te&&!O&&(r.depthMask(te),j=te)},setFunc:function(te){if(ce&&(te=_M[te]),de!==te){switch(te){case Nu:r.depthFunc(r.NEVER);break;case Fu:r.depthFunc(r.ALWAYS);break;case Uu:r.depthFunc(r.LESS);break;case Ur:r.depthFunc(r.LEQUAL);break;case ku:r.depthFunc(r.EQUAL);break;case zu:r.depthFunc(r.GEQUAL);break;case Bu:r.depthFunc(r.GREATER);break;case Hu:r.depthFunc(r.NOTEQUAL);break;default:r.depthFunc(r.LEQUAL)}de=te}},setLocked:function(te){O=te},setClear:function(te){ve!==te&&(ve=te,ce&&(te=1-te),r.clearDepth(te))},reset:function(){O=!1,j=null,de=null,ve=null,ce=!1}}}function n(){let O=!1,ce=null,j=null,de=null,ve=null,te=null,Ie=null,Se=null,$t=null;return{setTest:function(It){O||(It?ne(r.STENCIL_TEST):z(r.STENCIL_TEST))},setMask:function(It){ce!==It&&!O&&(r.stencilMask(It),ce=It)},setFunc:function(It,Hn,Gn){(j!==It||de!==Hn||ve!==Gn)&&(r.stencilFunc(It,Hn,Gn),j=It,de=Hn,ve=Gn)},setOp:function(It,Hn,Gn){(te!==It||Ie!==Hn||Se!==Gn)&&(r.stencilOp(It,Hn,Gn),te=It,Ie=Hn,Se=Gn)},setLocked:function(It){O=It},setClear:function(It){$t!==It&&(r.clearStencil(It),$t=It)},reset:function(){O=!1,ce=null,j=null,de=null,ve=null,te=null,Ie=null,Se=null,$t=null}}}const s=new t,a=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,_=null,b=null,M=null,S=null,w=null,T=null,x=new se(0,0,0),A=0,C=!1,I=null,P=null,V=null,X=null,L=null;const B=r.getParameter(r.MAX_COMBINED_TEXTURE_IMAGE_UNITS);let k=!1,$=0;const ee=r.getParameter(r.VERSION);ee.indexOf("WebGL")!==-1?($=parseFloat(/^WebGL (\d)/.exec(ee)[1]),k=$>=1):ee.indexOf("OpenGL ES")!==-1&&($=parseFloat(/^OpenGL ES (\d)/.exec(ee)[1]),k=$>=2);let J=null,ie={};const re=r.getParameter(r.SCISSOR_BOX),Ve=r.getParameter(r.VIEWPORT),Je=new it().fromArray(re),qe=new it().fromArray(Ve);function q(O,ce,j,de){const ve=new Uint8Array(4),te=r.createTexture();r.bindTexture(O,te),r.texParameteri(O,r.TEXTURE_MIN_FILTER,r.NEAREST),r.texParameteri(O,r.TEXTURE_MAG_FILTER,r.NEAREST);for(let Ie=0;Ie<j;Ie++)O===r.TEXTURE_3D||O===r.TEXTURE_2D_ARRAY?r.texImage3D(ce,0,r.RGBA,1,1,de,0,r.RGBA,r.UNSIGNED_BYTE,ve):r.texImage2D(ce+Ie,0,r.RGBA,1,1,0,r.RGBA,r.UNSIGNED_BYTE,ve);return te}const ae={};ae[r.TEXTURE_2D]=q(r.TEXTURE_2D,r.TEXTURE_2D,1),ae[r.TEXTURE_CUBE_MAP]=q(r.TEXTURE_CUBE_MAP,r.TEXTURE_CUBE_MAP_POSITIVE_X,6),ae[r.TEXTURE_2D_ARRAY]=q(r.TEXTURE_2D_ARRAY,r.TEXTURE_2D_ARRAY,1,1),ae[r.TEXTURE_3D]=q(r.TEXTURE_3D,r.TEXTURE_3D,1,1),s.setClear(0,0,0,1),a.setClear(1),o.setClear(0),ne(r.DEPTH_TEST),a.setFunc(Ur),gt(!1),vt(Uf),ne(r.CULL_FACE),ze(as);function ne(O){h[O]!==!0&&(r.enable(O),h[O]=!0)}function z(O){h[O]!==!1&&(r.disable(O),h[O]=!1)}function Te(O,ce){return d[O]!==ce?(r.bindFramebuffer(O,ce),d[O]=ce,O===r.DRAW_FRAMEBUFFER&&(d[r.FRAMEBUFFER]=ce),O===r.FRAMEBUFFER&&(d[r.DRAW_FRAMEBUFFER]=ce),!0):!1}function Ne(O,ce){let j=p,de=!1;if(O){j=f.get(ce),j===void 0&&(j=[],f.set(ce,j));const ve=O.textures;if(j.length!==ve.length||j[0]!==r.COLOR_ATTACHMENT0){for(let te=0,Ie=ve.length;te<Ie;te++)j[te]=r.COLOR_ATTACHMENT0+te;j.length=ve.length,de=!0}}else j[0]!==r.BACK&&(j[0]=r.BACK,de=!0);de&&r.drawBuffers(j)}function Ce(O){return v!==O?(r.useProgram(O),v=O,!0):!1}const be={[ba]:r.FUNC_ADD,[H2]:r.FUNC_SUBTRACT,[G2]:r.FUNC_REVERSE_SUBTRACT};be[V2]=r.MIN,be[W2]=r.MAX;const ke={[X2]:r.ZERO,[Bo]:r.ONE,[Y2]:r.SRC_COLOR,[Ou]:r.SRC_ALPHA,[j2]:r.SRC_ALPHA_SATURATE,[Z2]:r.DST_COLOR,[$2]:r.DST_ALPHA,[q2]:r.ONE_MINUS_SRC_COLOR,[Ho]:r.ONE_MINUS_SRC_ALPHA,[J2]:r.ONE_MINUS_DST_COLOR,[K2]:r.ONE_MINUS_DST_ALPHA,[Q2]:r.CONSTANT_COLOR,[eM]:r.ONE_MINUS_CONSTANT_COLOR,[tM]:r.CONSTANT_ALPHA,[iM]:r.ONE_MINUS_CONSTANT_ALPHA};function ze(O,ce,j,de,ve,te,Ie,Se,$t,It){if(O===as){m===!0&&(z(r.BLEND),m=!1);return}if(m===!1&&(ne(r.BLEND),m=!0),O!==Xl){if(O!==g||It!==C){if((_!==ba||S!==ba)&&(r.blendEquation(r.FUNC_ADD),_=ba,S=ba),It)switch(O){case ia:r.blendFuncSeparate(r.ONE,r.ONE_MINUS_SRC_ALPHA,r.ONE,r.ONE_MINUS_SRC_ALPHA);break;case Ni:r.blendFunc(r.ONE,r.ONE);break;case kf:r.blendFuncSeparate(r.ZERO,r.ONE_MINUS_SRC_COLOR,r.ZERO,r.ONE);break;case zf:r.blendFuncSeparate(r.DST_COLOR,r.ONE_MINUS_SRC_ALPHA,r.ZERO,r.ONE);break;default:Ge("WebGLState: Invalid blending: ",O);break}else switch(O){case ia:r.blendFuncSeparate(r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA,r.ONE,r.ONE_MINUS_SRC_ALPHA);break;case Ni:r.blendFuncSeparate(r.SRC_ALPHA,r.ONE,r.ONE,r.ONE);break;case kf:Ge("WebGLState: SubtractiveBlending requires material.premultipliedAlpha = true");break;case zf:Ge("WebGLState: MultiplyBlending requires material.premultipliedAlpha = true");break;default:Ge("WebGLState: Invalid blending: ",O);break}b=null,M=null,w=null,T=null,x.set(0,0,0),A=0,g=O,C=It}return}ve=ve||ce,te=te||j,Ie=Ie||de,(ce!==_||ve!==S)&&(r.blendEquationSeparate(be[ce],be[ve]),_=ce,S=ve),(j!==b||de!==M||te!==w||Ie!==T)&&(r.blendFuncSeparate(ke[j],ke[de],ke[te],ke[Ie]),b=j,M=de,w=te,T=Ie),(Se.equals(x)===!1||$t!==A)&&(r.blendColor(Se.r,Se.g,Se.b,$t),x.copy(Se),A=$t),g=O,C=!1}function Be(O,ce){O.side===Qi?z(r.CULL_FACE):ne(r.CULL_FACE);let j=O.side===Ht;ce&&(j=!j),gt(j),O.blending===ia&&O.transparent===!1?ze(as):ze(O.blending,O.blendEquation,O.blendSrc,O.blendDst,O.blendEquationAlpha,O.blendSrcAlpha,O.blendDstAlpha,O.blendColor,O.blendAlpha,O.premultipliedAlpha),a.setFunc(O.depthFunc),a.setTest(O.depthTest),a.setMask(O.depthWrite),s.setMask(O.colorWrite);const de=O.stencilWrite;o.setTest(de),de&&(o.setMask(O.stencilWriteMask),o.setFunc(O.stencilFunc,O.stencilRef,O.stencilFuncMask),o.setOp(O.stencilFail,O.stencilZFail,O.stencilZPass)),kt(O.polygonOffset,O.polygonOffsetFactor,O.polygonOffsetUnits),O.alphaToCoverage===!0?ne(r.SAMPLE_ALPHA_TO_COVERAGE):z(r.SAMPLE_ALPHA_TO_COVERAGE)}function gt(O){I!==O&&(O?r.frontFace(r.CW):r.frontFace(r.CCW),I=O)}function vt(O){O!==k2?(ne(r.CULL_FACE),O!==P&&(O===Uf?r.cullFace(r.BACK):O===z2?r.cullFace(r.FRONT):r.cullFace(r.FRONT_AND_BACK))):z(r.CULL_FACE),P=O}function Yt(O){O!==V&&(k&&r.lineWidth(O),V=O)}function kt(O,ce,j){O?(ne(r.POLYGON_OFFSET_FILL),(X!==ce||L!==j)&&(X=ce,L=j,a.getReversed()&&(ce=-ce),r.polygonOffset(ce,j))):z(r.POLYGON_OFFSET_FILL)}function qt(O){O?ne(r.SCISSOR_TEST):z(r.SCISSOR_TEST)}function oi(O){O===void 0&&(O=r.TEXTURE0+B-1),J!==O&&(r.activeTexture(O),J=O)}function N(O,ce,j){j===void 0&&(J===null?j=r.TEXTURE0+B-1:j=J);let de=ie[j];de===void 0&&(de={type:void 0,texture:void 0},ie[j]=de),(de.type!==O||de.texture!==ce)&&(J!==j&&(r.activeTexture(j),J=j),r.bindTexture(O,ce||ae[O]),de.type=O,de.texture=ce)}function Yi(){const O=ie[J];O!==void 0&&O.type!==void 0&&(r.bindTexture(O.type,null),O.type=void 0,O.texture=void 0)}function Mt(){try{r.compressedTexImage2D(...arguments)}catch(O){Ge("WebGLState:",O)}}function D(){try{r.compressedTexImage3D(...arguments)}catch(O){Ge("WebGLState:",O)}}function y(){try{r.texSubImage2D(...arguments)}catch(O){Ge("WebGLState:",O)}}function U(){try{r.texSubImage3D(...arguments)}catch(O){Ge("WebGLState:",O)}}function W(){try{r.compressedTexSubImage2D(...arguments)}catch(O){Ge("WebGLState:",O)}}function K(){try{r.compressedTexSubImage3D(...arguments)}catch(O){Ge("WebGLState:",O)}}function oe(){try{r.texStorage2D(...arguments)}catch(O){Ge("WebGLState:",O)}}function le(){try{r.texStorage3D(...arguments)}catch(O){Ge("WebGLState:",O)}}function Z(){try{r.texImage2D(...arguments)}catch(O){Ge("WebGLState:",O)}}function Q(){try{r.texImage3D(...arguments)}catch(O){Ge("WebGLState:",O)}}function he(O){return u[O]!==void 0?u[O]:r.getParameter(O)}function Pe(O,ce){u[O]!==ce&&(r.pixelStorei(O,ce),u[O]=ce)}function fe(O){Je.equals(O)===!1&&(r.scissor(O.x,O.y,O.z,O.w),Je.copy(O))}function ue(O){qe.equals(O)===!1&&(r.viewport(O.x,O.y,O.z,O.w),qe.copy(O))}function Ue(O,ce){let j=l.get(ce);j===void 0&&(j=new WeakMap,l.set(ce,j));let de=j.get(O);de===void 0&&(de=r.getUniformBlockIndex(ce,O.name),j.set(O,de))}function He(O,ce){const de=l.get(ce).get(O);c.get(ce)!==de&&(r.uniformBlockBinding(ce,de,O.__bindingPointIndex),c.set(ce,de))}function $e(){r.disable(r.BLEND),r.disable(r.CULL_FACE),r.disable(r.DEPTH_TEST),r.disable(r.POLYGON_OFFSET_FILL),r.disable(r.SCISSOR_TEST),r.disable(r.STENCIL_TEST),r.disable(r.SAMPLE_ALPHA_TO_COVERAGE),r.blendEquation(r.FUNC_ADD),r.blendFunc(r.ONE,r.ZERO),r.blendFuncSeparate(r.ONE,r.ZERO,r.ONE,r.ZERO),r.blendColor(0,0,0,0),r.colorMask(!0,!0,!0,!0),r.clearColor(0,0,0,0),r.depthMask(!0),r.depthFunc(r.LESS),a.setReversed(!1),r.clearDepth(1),r.stencilMask(4294967295),r.stencilFunc(r.ALWAYS,0,4294967295),r.stencilOp(r.KEEP,r.KEEP,r.KEEP),r.clearStencil(0),r.cullFace(r.BACK),r.frontFace(r.CCW),r.polygonOffset(0,0),r.activeTexture(r.TEXTURE0),r.bindFramebuffer(r.FRAMEBUFFER,null),r.bindFramebuffer(r.DRAW_FRAMEBUFFER,null),r.bindFramebuffer(r.READ_FRAMEBUFFER,null),r.useProgram(null),r.lineWidth(1),r.scissor(0,0,r.canvas.width,r.canvas.height),r.viewport(0,0,r.canvas.width,r.canvas.height),r.pixelStorei(r.PACK_ALIGNMENT,4),r.pixelStorei(r.UNPACK_ALIGNMENT,4),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,!1),r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),r.pixelStorei(r.UNPACK_COLORSPACE_CONVERSION_WEBGL,r.BROWSER_DEFAULT_WEBGL),r.pixelStorei(r.PACK_ROW_LENGTH,0),r.pixelStorei(r.PACK_SKIP_PIXELS,0),r.pixelStorei(r.PACK_SKIP_ROWS,0),r.pixelStorei(r.UNPACK_ROW_LENGTH,0),r.pixelStorei(r.UNPACK_IMAGE_HEIGHT,0),r.pixelStorei(r.UNPACK_SKIP_PIXELS,0),r.pixelStorei(r.UNPACK_SKIP_ROWS,0),r.pixelStorei(r.UNPACK_SKIP_IMAGES,0),h={},u={},J=null,ie={},d={},f=new WeakMap,p=[],v=null,m=!1,g=null,_=null,b=null,M=null,S=null,w=null,T=null,x=new se(0,0,0),A=0,C=!1,I=null,P=null,V=null,X=null,L=null,Je.set(0,0,r.canvas.width,r.canvas.height),qe.set(0,0,r.canvas.width,r.canvas.height),s.reset(),a.reset(),o.reset()}return{buffers:{color:s,depth:a,stencil:o},enable:ne,disable:z,bindFramebuffer:Te,drawBuffers:Ne,useProgram:Ce,setBlending:ze,setMaterial:Be,setFlipSided:gt,setCullFace:vt,setLineWidth:Yt,setPolygonOffset:kt,setScissorTest:qt,activeTexture:oi,bindTexture:N,unbindTexture:Yi,compressedTexImage2D:Mt,compressedTexImage3D:D,texImage2D:Z,texImage3D:Q,pixelStorei:Pe,getParameter:he,updateUBOMapping:Ue,uniformBlockBinding:He,texStorage2D:oe,texStorage3D:le,texSubImage2D:y,texSubImage3D:U,compressedTexSubImage2D:W,compressedTexSubImage3D:K,scissor:fe,viewport:ue,reset:$e}}function FS(r,e,t,i,n,s,a){const o=e.has("WEBGL_multisampled_render_to_texture")?e.get("WEBGL_multisampled_render_to_texture"):null,c=typeof navigator>"u"?!1:/OculusBrowser/g.test(navigator.userAgent),l=new xe,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,y){return p?new OffscreenCanvas(D,y):Yo("canvas")}function m(D,y,U){let W=1;const K=Mt(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 oe=Math.floor(W*K.width),le=Math.floor(W*K.height);d===void 0&&(d=v(oe,le));const Z=y?v(oe,le):d;return Z.width=oe,Z.height=le,Z.getContext("2d").drawImage(D,0,0,oe,le),Re("WebGLRenderer: Texture has been resized from ("+K.width+"x"+K.height+") to ("+oe+"x"+le+")."),Z}else return"data"in D&&Re("WebGLRenderer: Image in DataTexture is too big ("+K.width+"x"+K.height+")."),D;return D}function g(D){return D.generateMipmaps}function _(D){r.generateMipmap(D)}function b(D){return D.isWebGLCubeRenderTarget?r.TEXTURE_CUBE_MAP:D.isWebGL3DRenderTarget?r.TEXTURE_3D:D.isWebGLArrayRenderTarget||D.isCompressedArrayTexture?r.TEXTURE_2D_ARRAY:r.TEXTURE_2D}function M(D,y,U,W,K,oe=!1){if(D!==null){if(r[D]!==void 0)return r[D];Re("WebGLRenderer: Attempt to use non-existing WebGL internal format '"+D+"'")}let le;W&&(le=e.get("EXT_texture_norm16"),le||Re("WebGLRenderer: Unable to use normalized textures without EXT_texture_norm16 extension"));let Z=y;if(y===r.RED&&(U===r.FLOAT&&(Z=r.R32F),U===r.HALF_FLOAT&&(Z=r.R16F),U===r.UNSIGNED_BYTE&&(Z=r.R8),U===r.UNSIGNED_SHORT&&le&&(Z=le.R16_EXT),U===r.SHORT&&le&&(Z=le.R16_SNORM_EXT)),y===r.RED_INTEGER&&(U===r.UNSIGNED_BYTE&&(Z=r.R8UI),U===r.UNSIGNED_SHORT&&(Z=r.R16UI),U===r.UNSIGNED_INT&&(Z=r.R32UI),U===r.BYTE&&(Z=r.R8I),U===r.SHORT&&(Z=r.R16I),U===r.INT&&(Z=r.R32I)),y===r.RG&&(U===r.FLOAT&&(Z=r.RG32F),U===r.HALF_FLOAT&&(Z=r.RG16F),U===r.UNSIGNED_BYTE&&(Z=r.RG8),U===r.UNSIGNED_SHORT&&le&&(Z=le.RG16_EXT),U===r.SHORT&&le&&(Z=le.RG16_SNORM_EXT)),y===r.RG_INTEGER&&(U===r.UNSIGNED_BYTE&&(Z=r.RG8UI),U===r.UNSIGNED_SHORT&&(Z=r.RG16UI),U===r.UNSIGNED_INT&&(Z=r.RG32UI),U===r.BYTE&&(Z=r.RG8I),U===r.SHORT&&(Z=r.RG16I),U===r.INT&&(Z=r.RG32I)),y===r.RGB_INTEGER&&(U===r.UNSIGNED_BYTE&&(Z=r.RGB8UI),U===r.UNSIGNED_SHORT&&(Z=r.RGB16UI),U===r.UNSIGNED_INT&&(Z=r.RGB32UI),U===r.BYTE&&(Z=r.RGB8I),U===r.SHORT&&(Z=r.RGB16I),U===r.INT&&(Z=r.RGB32I)),y===r.RGBA_INTEGER&&(U===r.UNSIGNED_BYTE&&(Z=r.RGBA8UI),U===r.UNSIGNED_SHORT&&(Z=r.RGBA16UI),U===r.UNSIGNED_INT&&(Z=r.RGBA32UI),U===r.BYTE&&(Z=r.RGBA8I),U===r.SHORT&&(Z=r.RGBA16I),U===r.INT&&(Z=r.RGBA32I)),y===r.RGB&&(U===r.UNSIGNED_SHORT&&le&&(Z=le.RGB16_EXT),U===r.SHORT&&le&&(Z=le.RGB16_SNORM_EXT),U===r.UNSIGNED_INT_5_9_9_9_REV&&(Z=r.RGB9_E5),U===r.UNSIGNED_INT_10F_11F_11F_REV&&(Z=r.R11F_G11F_B10F)),y===r.RGBA){const Q=oe?Al:at.getTransfer(K);U===r.FLOAT&&(Z=r.RGBA32F),U===r.HALF_FLOAT&&(Z=r.RGBA16F),U===r.UNSIGNED_BYTE&&(Z=Q===yt?r.SRGB8_ALPHA8:r.RGBA8),U===r.UNSIGNED_SHORT&&le&&(Z=le.RGBA16_EXT),U===r.SHORT&&le&&(Z=le.RGBA16_SNORM_EXT),U===r.UNSIGNED_SHORT_4_4_4_4&&(Z=r.RGBA4),U===r.UNSIGNED_SHORT_5_5_5_1&&(Z=r.RGB5_A1)}return(Z===r.R16F||Z===r.R32F||Z===r.RG16F||Z===r.RG32F||Z===r.RGBA16F||Z===r.RGBA32F)&&e.get("EXT_color_buffer_float"),Z}function S(D,y){let U;return D?y===null||y===_n||y===Wo?U=r.DEPTH24_STENCIL8:y===Oi?U=r.DEPTH32F_STENCIL8:y===Vo&&(U=r.DEPTH24_STENCIL8,Re("DepthTexture: 16 bit depth attachment is not supported with stencil. Using 24-bit attachment.")):y===null||y===_n||y===Wo?U=r.DEPTH_COMPONENT24:y===Oi?U=r.DEPTH_COMPONENT32F:y===Vo&&(U=r.DEPTH_COMPONENT16),U}function w(D,y){return g(D)===!0||D.isFramebufferTexture&&D.minFilter!==At&&D.minFilter!==rt?Math.log2(Math.max(y.width,y.height))+1:D.mipmaps!==void 0&&D.mipmaps.length>0?D.mipmaps.length:D.isCompressedTexture&&Array.isArray(D.image)?y.mipmaps.length:1}function T(D){const y=D.target;y.removeEventListener("dispose",T),A(y),y.isVideoTexture&&h.delete(y),y.isHTMLTexture&&u.delete(y)}function x(D){const y=D.target;y.removeEventListener("dispose",x),I(y)}function A(D){const y=i.get(D);if(y.__webglInit===void 0)return;const U=D.source,W=f.get(U);if(W){const K=W[y.__cacheKey];K.usedTimes--,K.usedTimes===0&&C(D),Object.keys(W).length===0&&f.delete(U)}i.remove(D)}function C(D){const y=i.get(D);r.deleteTexture(y.__webglTexture);const U=D.source,W=f.get(U);delete W[y.__cacheKey],a.memory.textures--}function I(D){const y=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(y.__webglFramebuffer[W]))for(let K=0;K<y.__webglFramebuffer[W].length;K++)r.deleteFramebuffer(y.__webglFramebuffer[W][K]);else r.deleteFramebuffer(y.__webglFramebuffer[W]);y.__webglDepthbuffer&&r.deleteRenderbuffer(y.__webglDepthbuffer[W])}else{if(Array.isArray(y.__webglFramebuffer))for(let W=0;W<y.__webglFramebuffer.length;W++)r.deleteFramebuffer(y.__webglFramebuffer[W]);else r.deleteFramebuffer(y.__webglFramebuffer);if(y.__webglDepthbuffer&&r.deleteRenderbuffer(y.__webglDepthbuffer),y.__webglMultisampledFramebuffer&&r.deleteFramebuffer(y.__webglMultisampledFramebuffer),y.__webglColorRenderbuffer)for(let W=0;W<y.__webglColorRenderbuffer.length;W++)y.__webglColorRenderbuffer[W]&&r.deleteRenderbuffer(y.__webglColorRenderbuffer[W]);y.__webglDepthRenderbuffer&&r.deleteRenderbuffer(y.__webglDepthRenderbuffer)}const U=D.textures;for(let W=0,K=U.length;W<K;W++){const oe=i.get(U[W]);oe.__webglTexture&&(r.deleteTexture(oe.__webglTexture),a.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&&Re("WebGLTextures: Trying to use "+D+" texture units while this GPU supports only "+n.maxTextures),P+=1,D}function k(D){const y=[];return y.push(D.wrapS),y.push(D.wrapT),y.push(D.wrapR||0),y.push(D.magFilter),y.push(D.minFilter),y.push(D.anisotropy),y.push(D.internalFormat),y.push(D.format),y.push(D.type),y.push(D.generateMipmaps),y.push(D.premultiplyAlpha),y.push(D.flipY),y.push(D.unpackAlignment),y.push(D.colorSpace),y.join()}function $(D,y){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)Re("WebGLRenderer: Texture marked for update but no image data found.");else if(W.complete===!1)Re("WebGLRenderer: Texture marked for update but image is incomplete");else{z(U,D,y);return}}else D.isExternalTexture&&(U.__webglTexture=D.sourceTexture?D.sourceTexture:null);t.bindTexture(r.TEXTURE_2D,U.__webglTexture,r.TEXTURE0+y)}function ee(D,y){const U=i.get(D);if(D.isRenderTargetTexture===!1&&D.version>0&&U.__version!==D.version){z(U,D,y);return}else D.isExternalTexture&&(U.__webglTexture=D.sourceTexture?D.sourceTexture:null);t.bindTexture(r.TEXTURE_2D_ARRAY,U.__webglTexture,r.TEXTURE0+y)}function J(D,y){const U=i.get(D);if(D.isRenderTargetTexture===!1&&D.version>0&&U.__version!==D.version){z(U,D,y);return}t.bindTexture(r.TEXTURE_3D,U.__webglTexture,r.TEXTURE0+y)}function ie(D,y){const U=i.get(D);if(D.isCubeDepthTexture!==!0&&D.version>0&&U.__version!==D.version){Te(U,D,y);return}t.bindTexture(r.TEXTURE_CUBE_MAP,U.__webglTexture,r.TEXTURE0+y)}const re={[Go]:r.REPEAT,[wi]:r.CLAMP_TO_EDGE,[Gu]:r.MIRRORED_REPEAT},Ve={[At]:r.NEAREST,[rM]:r.NEAREST_MIPMAP_NEAREST,[lc]:r.NEAREST_MIPMAP_LINEAR,[rt]:r.LINEAR,[dh]:r.LINEAR_MIPMAP_NEAREST,[Ta]:r.LINEAR_MIPMAP_LINEAR},Je={[dM]:r.NEVER,[vM]:r.ALWAYS,[fM]:r.LESS,[x0]:r.LEQUAL,[pM]:r.EQUAL,[y0]:r.GEQUAL,[mM]:r.GREATER,[gM]:r.NOTEQUAL};function qe(D,y){if(y.type===Oi&&e.has("OES_texture_float_linear")===!1&&(y.magFilter===rt||y.magFilter===dh||y.magFilter===lc||y.magFilter===Ta||y.minFilter===rt||y.minFilter===dh||y.minFilter===lc||y.minFilter===Ta)&&Re("WebGLRenderer: Unable to use linear filtering with floating point textures. OES_texture_float_linear not supported on this device."),r.texParameteri(D,r.TEXTURE_WRAP_S,re[y.wrapS]),r.texParameteri(D,r.TEXTURE_WRAP_T,re[y.wrapT]),(D===r.TEXTURE_3D||D===r.TEXTURE_2D_ARRAY)&&r.texParameteri(D,r.TEXTURE_WRAP_R,re[y.wrapR]),r.texParameteri(D,r.TEXTURE_MAG_FILTER,Ve[y.magFilter]),r.texParameteri(D,r.TEXTURE_MIN_FILTER,Ve[y.minFilter]),y.compareFunction&&(r.texParameteri(D,r.TEXTURE_COMPARE_MODE,r.COMPARE_REF_TO_TEXTURE),r.texParameteri(D,r.TEXTURE_COMPARE_FUNC,Je[y.compareFunction])),e.has("EXT_texture_filter_anisotropic")===!0){if(y.magFilter===At||y.minFilter!==lc&&y.minFilter!==Ta||y.type===Oi&&e.has("OES_texture_float_linear")===!1)return;if(y.anisotropy>1||i.get(y).__currentAnisotropy){const U=e.get("EXT_texture_filter_anisotropic");r.texParameterf(D,U.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(y.anisotropy,n.getMaxAnisotropy())),i.get(y).__currentAnisotropy=y.anisotropy}}}function q(D,y){let U=!1;D.__webglInit===void 0&&(D.__webglInit=!0,y.addEventListener("dispose",T));const W=y.source;let K=f.get(W);K===void 0&&(K={},f.set(W,K));const oe=k(y);if(oe!==D.__cacheKey){K[oe]===void 0&&(K[oe]={texture:r.createTexture(),usedTimes:0},a.memory.textures++,U=!0),K[oe].usedTimes++;const le=K[D.__cacheKey];le!==void 0&&(K[D.__cacheKey].usedTimes--,le.usedTimes===0&&C(y)),D.__cacheKey=oe,D.__webglTexture=K[oe].texture}return U}function ae(D,y,U){return Math.floor(Math.floor(D/U)/y)}function ne(D,y,U,W){const oe=D.updateRanges;if(oe.length===0)t.texSubImage2D(r.TEXTURE_2D,0,0,0,y.width,y.height,U,W,y.data);else{oe.sort((Pe,fe)=>Pe.start-fe.start);let le=0;for(let Pe=1;Pe<oe.length;Pe++){const fe=oe[le],ue=oe[Pe],Ue=fe.start+fe.count,He=ae(ue.start,y.width,4),$e=ae(fe.start,y.width,4);ue.start<=Ue+1&&He===$e&&ae(ue.start+ue.count-1,y.width,4)===He?fe.count=Math.max(fe.count,ue.start+ue.count-fe.start):(++le,oe[le]=ue)}oe.length=le+1;const Z=t.getParameter(r.UNPACK_ROW_LENGTH),Q=t.getParameter(r.UNPACK_SKIP_PIXELS),he=t.getParameter(r.UNPACK_SKIP_ROWS);t.pixelStorei(r.UNPACK_ROW_LENGTH,y.width);for(let Pe=0,fe=oe.length;Pe<fe;Pe++){const ue=oe[Pe],Ue=Math.floor(ue.start/4),He=Math.ceil(ue.count/4),$e=Ue%y.width,O=Math.floor(Ue/y.width),ce=He,j=1;t.pixelStorei(r.UNPACK_SKIP_PIXELS,$e),t.pixelStorei(r.UNPACK_SKIP_ROWS,O),t.texSubImage2D(r.TEXTURE_2D,0,$e,O,ce,j,U,W,y.data)}D.clearUpdateRanges(),t.pixelStorei(r.UNPACK_ROW_LENGTH,Z),t.pixelStorei(r.UNPACK_SKIP_PIXELS,Q),t.pixelStorei(r.UNPACK_SKIP_ROWS,he)}}function z(D,y,U){let W=r.TEXTURE_2D;(y.isDataArrayTexture||y.isCompressedArrayTexture)&&(W=r.TEXTURE_2D_ARRAY),y.isData3DTexture&&(W=r.TEXTURE_3D);const K=q(D,y),oe=y.source;t.bindTexture(W,D.__webglTexture,r.TEXTURE0+U);const le=i.get(oe);if(oe.version!==le.__version||K===!0){if(t.activeTexture(r.TEXTURE0+U),(typeof ImageBitmap<"u"&&y.image instanceof ImageBitmap)===!1){const j=at.getPrimaries(at.workingColorSpace),de=y.colorSpace===Js?null:at.getPrimaries(y.colorSpace),ve=y.colorSpace===Js||j===de?r.NONE:r.BROWSER_DEFAULT_WEBGL;t.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,y.flipY),t.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,y.premultiplyAlpha),t.pixelStorei(r.UNPACK_COLORSPACE_CONVERSION_WEBGL,ve)}t.pixelStorei(r.UNPACK_ALIGNMENT,y.unpackAlignment);let Q=m(y.image,!1,n.maxTextureSize);Q=Yi(y,Q);const he=s.convert(y.format,y.colorSpace),Pe=s.convert(y.type);let fe=M(y.internalFormat,he,Pe,y.normalized,y.colorSpace,y.isVideoTexture);qe(W,y);let ue;const Ue=y.mipmaps,He=y.isVideoTexture!==!0,$e=le.__version===void 0||K===!0,O=oe.dataReady,ce=w(y,Q);if(y.isDepthTexture)fe=S(y.format===Ra,y.type),$e&&(He?t.texStorage2D(r.TEXTURE_2D,1,fe,Q.width,Q.height):t.texImage2D(r.TEXTURE_2D,0,fe,Q.width,Q.height,0,he,Pe,null));else if(y.isDataTexture)if(Ue.length>0){He&&$e&&t.texStorage2D(r.TEXTURE_2D,ce,fe,Ue[0].width,Ue[0].height);for(let j=0,de=Ue.length;j<de;j++)ue=Ue[j],He?O&&t.texSubImage2D(r.TEXTURE_2D,j,0,0,ue.width,ue.height,he,Pe,ue.data):t.texImage2D(r.TEXTURE_2D,j,fe,ue.width,ue.height,0,he,Pe,ue.data);y.generateMipmaps=!1}else He?($e&&t.texStorage2D(r.TEXTURE_2D,ce,fe,Q.width,Q.height),O&&ne(y,Q,he,Pe)):t.texImage2D(r.TEXTURE_2D,0,fe,Q.width,Q.height,0,he,Pe,Q.data);else if(y.isCompressedTexture)if(y.isCompressedArrayTexture){He&&$e&&t.texStorage3D(r.TEXTURE_2D_ARRAY,ce,fe,Ue[0].width,Ue[0].height,Q.depth);for(let j=0,de=Ue.length;j<de;j++)if(ue=Ue[j],y.format!==Ei)if(he!==null)if(He){if(O)if(y.layerUpdates.size>0){const ve=Pp(ue.width,ue.height,y.format,y.type);for(const te of y.layerUpdates){const Ie=ue.data.subarray(te*ve/ue.data.BYTES_PER_ELEMENT,(te+1)*ve/ue.data.BYTES_PER_ELEMENT);t.compressedTexSubImage3D(r.TEXTURE_2D_ARRAY,j,0,0,te,ue.width,ue.height,1,he,Ie)}y.clearLayerUpdates()}else t.compressedTexSubImage3D(r.TEXTURE_2D_ARRAY,j,0,0,0,ue.width,ue.height,Q.depth,he,ue.data)}else t.compressedTexImage3D(r.TEXTURE_2D_ARRAY,j,fe,ue.width,ue.height,Q.depth,0,ue.data,0,0);else Re("WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()");else He?O&&t.texSubImage3D(r.TEXTURE_2D_ARRAY,j,0,0,0,ue.width,ue.height,Q.depth,he,Pe,ue.data):t.texImage3D(r.TEXTURE_2D_ARRAY,j,fe,ue.width,ue.height,Q.depth,0,he,Pe,ue.data)}else{He&&$e&&t.texStorage2D(r.TEXTURE_2D,ce,fe,Ue[0].width,Ue[0].height);for(let j=0,de=Ue.length;j<de;j++)ue=Ue[j],y.format!==Ei?he!==null?He?O&&t.compressedTexSubImage2D(r.TEXTURE_2D,j,0,0,ue.width,ue.height,he,ue.data):t.compressedTexImage2D(r.TEXTURE_2D,j,fe,ue.width,ue.height,0,ue.data):Re("WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()"):He?O&&t.texSubImage2D(r.TEXTURE_2D,j,0,0,ue.width,ue.height,he,Pe,ue.data):t.texImage2D(r.TEXTURE_2D,j,fe,ue.width,ue.height,0,he,Pe,ue.data)}else if(y.isDataArrayTexture)if(He){if($e&&t.texStorage3D(r.TEXTURE_2D_ARRAY,ce,fe,Q.width,Q.height,Q.depth),O)if(y.layerUpdates.size>0){const j=Pp(Q.width,Q.height,y.format,y.type);for(const de of y.layerUpdates){const ve=Q.data.subarray(de*j/Q.data.BYTES_PER_ELEMENT,(de+1)*j/Q.data.BYTES_PER_ELEMENT);t.texSubImage3D(r.TEXTURE_2D_ARRAY,0,0,0,de,Q.width,Q.height,1,he,Pe,ve)}y.clearLayerUpdates()}else t.texSubImage3D(r.TEXTURE_2D_ARRAY,0,0,0,0,Q.width,Q.height,Q.depth,he,Pe,Q.data)}else t.texImage3D(r.TEXTURE_2D_ARRAY,0,fe,Q.width,Q.height,Q.depth,0,he,Pe,Q.data);else if(y.isData3DTexture)He?($e&&t.texStorage3D(r.TEXTURE_3D,ce,fe,Q.width,Q.height,Q.depth),O&&t.texSubImage3D(r.TEXTURE_3D,0,0,0,0,Q.width,Q.height,Q.depth,he,Pe,Q.data)):t.texImage3D(r.TEXTURE_3D,0,fe,Q.width,Q.height,Q.depth,0,he,Pe,Q.data);else if(y.isFramebufferTexture){if($e)if(He)t.texStorage2D(r.TEXTURE_2D,ce,fe,Q.width,Q.height);else{let j=Q.width,de=Q.height;for(let ve=0;ve<ce;ve++)t.texImage2D(r.TEXTURE_2D,ve,fe,j,de,0,he,Pe,null),j>>=1,de>>=1}}else if(y.isHTMLTexture){if("texElementImage2D"in r){const j=r.canvas;if(j.hasAttribute("layoutsubtree")||j.setAttribute("layoutsubtree","true"),Q.parentNode!==j){j.appendChild(Q),u.add(y),j.onpaint=de=>{const ve=de.changedElements;for(const te of u)ve.includes(te.image)&&(te.needsUpdate=!0)},j.requestPaint();return}if(r.texElementImage2D.length===3)r.texElementImage2D(r.TEXTURE_2D,r.RGBA8,Q);else{const ve=r.RGBA,te=r.RGBA,Ie=r.UNSIGNED_BYTE;r.texElementImage2D(r.TEXTURE_2D,0,ve,te,Ie,Q)}r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE)}}else if(Ue.length>0){if(He&&$e){const j=Mt(Ue[0]);t.texStorage2D(r.TEXTURE_2D,ce,fe,j.width,j.height)}for(let j=0,de=Ue.length;j<de;j++)ue=Ue[j],He?O&&t.texSubImage2D(r.TEXTURE_2D,j,0,0,he,Pe,ue):t.texImage2D(r.TEXTURE_2D,j,fe,he,Pe,ue);y.generateMipmaps=!1}else if(He){if($e){const j=Mt(Q);t.texStorage2D(r.TEXTURE_2D,ce,fe,j.width,j.height)}O&&t.texSubImage2D(r.TEXTURE_2D,0,0,0,he,Pe,Q)}else t.texImage2D(r.TEXTURE_2D,0,fe,he,Pe,Q);g(y)&&_(W),le.__version=oe.version,y.onUpdate&&y.onUpdate(y)}D.__version=y.version}function Te(D,y,U){if(y.image.length!==6)return;const W=q(D,y),K=y.source;t.bindTexture(r.TEXTURE_CUBE_MAP,D.__webglTexture,r.TEXTURE0+U);const oe=i.get(K);if(K.version!==oe.__version||W===!0){t.activeTexture(r.TEXTURE0+U);const le=at.getPrimaries(at.workingColorSpace),Z=y.colorSpace===Js?null:at.getPrimaries(y.colorSpace),Q=y.colorSpace===Js||le===Z?r.NONE:r.BROWSER_DEFAULT_WEBGL;t.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,y.flipY),t.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,y.premultiplyAlpha),t.pixelStorei(r.UNPACK_ALIGNMENT,y.unpackAlignment),t.pixelStorei(r.UNPACK_COLORSPACE_CONVERSION_WEBGL,Q);const he=y.isCompressedTexture||y.image[0].isCompressedTexture,Pe=y.image[0]&&y.image[0].isDataTexture,fe=[];for(let te=0;te<6;te++)!he&&!Pe?fe[te]=m(y.image[te],!0,n.maxCubemapSize):fe[te]=Pe?y.image[te].image:y.image[te],fe[te]=Yi(y,fe[te]);const ue=fe[0],Ue=s.convert(y.format,y.colorSpace),He=s.convert(y.type),$e=M(y.internalFormat,Ue,He,y.normalized,y.colorSpace),O=y.isVideoTexture!==!0,ce=oe.__version===void 0||W===!0,j=K.dataReady;let de=w(y,ue);qe(r.TEXTURE_CUBE_MAP,y);let ve;if(he){O&&ce&&t.texStorage2D(r.TEXTURE_CUBE_MAP,de,$e,ue.width,ue.height);for(let te=0;te<6;te++){ve=fe[te].mipmaps;for(let Ie=0;Ie<ve.length;Ie++){const Se=ve[Ie];y.format!==Ei?Ue!==null?O?j&&t.compressedTexSubImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+te,Ie,0,0,Se.width,Se.height,Ue,Se.data):t.compressedTexImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+te,Ie,$e,Se.width,Se.height,0,Se.data):Re("WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()"):O?j&&t.texSubImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+te,Ie,0,0,Se.width,Se.height,Ue,He,Se.data):t.texImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+te,Ie,$e,Se.width,Se.height,0,Ue,He,Se.data)}}}else{if(ve=y.mipmaps,O&&ce){ve.length>0&&de++;const te=Mt(fe[0]);t.texStorage2D(r.TEXTURE_CUBE_MAP,de,$e,te.width,te.height)}for(let te=0;te<6;te++)if(Pe){O?j&&t.texSubImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+te,0,0,0,fe[te].width,fe[te].height,Ue,He,fe[te].data):t.texImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+te,0,$e,fe[te].width,fe[te].height,0,Ue,He,fe[te].data);for(let Ie=0;Ie<ve.length;Ie++){const $t=ve[Ie].image[te].image;O?j&&t.texSubImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+te,Ie+1,0,0,$t.width,$t.height,Ue,He,$t.data):t.texImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+te,Ie+1,$e,$t.width,$t.height,0,Ue,He,$t.data)}}else{O?j&&t.texSubImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+te,0,0,0,Ue,He,fe[te]):t.texImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+te,0,$e,Ue,He,fe[te]);for(let Ie=0;Ie<ve.length;Ie++){const Se=ve[Ie];O?j&&t.texSubImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+te,Ie+1,0,0,Ue,He,Se.image[te]):t.texImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+te,Ie+1,$e,Ue,He,Se.image[te])}}}g(y)&&_(r.TEXTURE_CUBE_MAP),oe.__version=K.version,y.onUpdate&&y.onUpdate(y)}D.__version=y.version}function Ne(D,y,U,W,K,oe){const le=s.convert(U.format,U.colorSpace),Z=s.convert(U.type),Q=M(U.internalFormat,le,Z,U.normalized,U.colorSpace),he=i.get(y),Pe=i.get(U);if(Pe.__renderTarget=y,!he.__hasExternalTextures){const fe=Math.max(1,y.width>>oe),ue=Math.max(1,y.height>>oe);K===r.TEXTURE_3D||K===r.TEXTURE_2D_ARRAY?t.texImage3D(K,oe,Q,fe,ue,y.depth,0,le,Z,null):t.texImage2D(K,oe,Q,fe,ue,0,le,Z,null)}t.bindFramebuffer(r.FRAMEBUFFER,D),oi(y)?o.framebufferTexture2DMultisampleEXT(r.FRAMEBUFFER,W,K,Pe.__webglTexture,0,qt(y)):(K===r.TEXTURE_2D||K>=r.TEXTURE_CUBE_MAP_POSITIVE_X&&K<=r.TEXTURE_CUBE_MAP_NEGATIVE_Z)&&r.framebufferTexture2D(r.FRAMEBUFFER,W,K,Pe.__webglTexture,oe),t.bindFramebuffer(r.FRAMEBUFFER,null)}function Ce(D,y,U){if(r.bindRenderbuffer(r.RENDERBUFFER,D),y.depthBuffer){const W=y.depthTexture,K=W&&W.isDepthTexture?W.type:null,oe=S(y.stencilBuffer,K),le=y.stencilBuffer?r.DEPTH_STENCIL_ATTACHMENT:r.DEPTH_ATTACHMENT;oi(y)?o.renderbufferStorageMultisampleEXT(r.RENDERBUFFER,qt(y),oe,y.width,y.height):U?r.renderbufferStorageMultisample(r.RENDERBUFFER,qt(y),oe,y.width,y.height):r.renderbufferStorage(r.RENDERBUFFER,oe,y.width,y.height),r.framebufferRenderbuffer(r.FRAMEBUFFER,le,r.RENDERBUFFER,D)}else{const W=y.textures;for(let K=0;K<W.length;K++){const oe=W[K],le=s.convert(oe.format,oe.colorSpace),Z=s.convert(oe.type),Q=M(oe.internalFormat,le,Z,oe.normalized,oe.colorSpace);oi(y)?o.renderbufferStorageMultisampleEXT(r.RENDERBUFFER,qt(y),Q,y.width,y.height):U?r.renderbufferStorageMultisample(r.RENDERBUFFER,qt(y),Q,y.width,y.height):r.renderbufferStorage(r.RENDERBUFFER,Q,y.width,y.height)}}r.bindRenderbuffer(r.RENDERBUFFER,null)}function be(D,y,U){const W=y.isWebGLCubeRenderTarget===!0;if(t.bindFramebuffer(r.FRAMEBUFFER,D),!(y.depthTexture&&y.depthTexture.isDepthTexture))throw new Error("THREE.WebGLTextures: renderTarget.depthTexture must be an instance of THREE.DepthTexture.");const K=i.get(y.depthTexture);if(K.__renderTarget=y,(!K.__webglTexture||y.depthTexture.image.width!==y.width||y.depthTexture.image.height!==y.height)&&(y.depthTexture.image.width=y.width,y.depthTexture.image.height=y.height,y.depthTexture.needsUpdate=!0),W){if(K.__webglInit===void 0&&(K.__webglInit=!0,y.depthTexture.addEventListener("dispose",T)),K.__webglTexture===void 0){K.__webglTexture=r.createTexture(),t.bindTexture(r.TEXTURE_CUBE_MAP,K.__webglTexture),qe(r.TEXTURE_CUBE_MAP,y.depthTexture);const he=s.convert(y.depthTexture.format),Pe=s.convert(y.depthTexture.type);let fe;y.depthTexture.format===Rs?fe=r.DEPTH_COMPONENT24:y.depthTexture.format===Ra&&(fe=r.DEPTH24_STENCIL8);for(let ue=0;ue<6;ue++)r.texImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+ue,0,fe,y.width,y.height,0,he,Pe,null)}}else $(y.depthTexture,0);const oe=K.__webglTexture,le=qt(y),Z=W?r.TEXTURE_CUBE_MAP_POSITIVE_X+U:r.TEXTURE_2D,Q=y.depthTexture.format===Ra?r.DEPTH_STENCIL_ATTACHMENT:r.DEPTH_ATTACHMENT;if(y.depthTexture.format===Rs)oi(y)?o.framebufferTexture2DMultisampleEXT(r.FRAMEBUFFER,Q,Z,oe,0,le):r.framebufferTexture2D(r.FRAMEBUFFER,Q,Z,oe,0);else if(y.depthTexture.format===Ra)oi(y)?o.framebufferTexture2DMultisampleEXT(r.FRAMEBUFFER,Q,Z,oe,0,le):r.framebufferTexture2D(r.FRAMEBUFFER,Q,Z,oe,0);else throw new Error("THREE.WebGLTextures: Unknown depthTexture format.")}function ke(D){const y=i.get(D),U=D.isWebGLCubeRenderTarget===!0;if(y.__boundDepthTexture!==D.depthTexture){const W=D.depthTexture;if(y.__depthDisposeCallback&&y.__depthDisposeCallback(),W){const K=()=>{delete y.__boundDepthTexture,delete y.__depthDisposeCallback,W.removeEventListener("dispose",K)};W.addEventListener("dispose",K),y.__depthDisposeCallback=K}y.__boundDepthTexture=W}if(D.depthTexture&&!y.__autoAllocateDepthBuffer)if(U)for(let W=0;W<6;W++)be(y.__webglFramebuffer[W],D,W);else{const W=D.texture.mipmaps;W&&W.length>0?be(y.__webglFramebuffer[0],D,0):be(y.__webglFramebuffer,D,0)}else if(U){y.__webglDepthbuffer=[];for(let W=0;W<6;W++)if(t.bindFramebuffer(r.FRAMEBUFFER,y.__webglFramebuffer[W]),y.__webglDepthbuffer[W]===void 0)y.__webglDepthbuffer[W]=r.createRenderbuffer(),Ce(y.__webglDepthbuffer[W],D,!1);else{const K=D.stencilBuffer?r.DEPTH_STENCIL_ATTACHMENT:r.DEPTH_ATTACHMENT,oe=y.__webglDepthbuffer[W];r.bindRenderbuffer(r.RENDERBUFFER,oe),r.framebufferRenderbuffer(r.FRAMEBUFFER,K,r.RENDERBUFFER,oe)}}else{const W=D.texture.mipmaps;if(W&&W.length>0?t.bindFramebuffer(r.FRAMEBUFFER,y.__webglFramebuffer[0]):t.bindFramebuffer(r.FRAMEBUFFER,y.__webglFramebuffer),y.__webglDepthbuffer===void 0)y.__webglDepthbuffer=r.createRenderbuffer(),Ce(y.__webglDepthbuffer,D,!1);else{const K=D.stencilBuffer?r.DEPTH_STENCIL_ATTACHMENT:r.DEPTH_ATTACHMENT,oe=y.__webglDepthbuffer;r.bindRenderbuffer(r.RENDERBUFFER,oe),r.framebufferRenderbuffer(r.FRAMEBUFFER,K,r.RENDERBUFFER,oe)}}t.bindFramebuffer(r.FRAMEBUFFER,null)}function ze(D,y,U){const W=i.get(D);y!==void 0&&Ne(W.__webglFramebuffer,D,D.texture,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,0),U!==void 0&&ke(D)}function Be(D){const y=D.texture,U=i.get(D),W=i.get(y);D.addEventListener("dispose",x);const K=D.textures,oe=D.isWebGLCubeRenderTarget===!0,le=K.length>1;if(le||(W.__webglTexture===void 0&&(W.__webglTexture=r.createTexture()),W.__version=y.version,a.memory.textures++),oe){U.__webglFramebuffer=[];for(let Z=0;Z<6;Z++)if(y.mipmaps&&y.mipmaps.length>0){U.__webglFramebuffer[Z]=[];for(let Q=0;Q<y.mipmaps.length;Q++)U.__webglFramebuffer[Z][Q]=r.createFramebuffer()}else U.__webglFramebuffer[Z]=r.createFramebuffer()}else{if(y.mipmaps&&y.mipmaps.length>0){U.__webglFramebuffer=[];for(let Z=0;Z<y.mipmaps.length;Z++)U.__webglFramebuffer[Z]=r.createFramebuffer()}else U.__webglFramebuffer=r.createFramebuffer();if(le)for(let Z=0,Q=K.length;Z<Q;Z++){const he=i.get(K[Z]);he.__webglTexture===void 0&&(he.__webglTexture=r.createTexture(),a.memory.textures++)}if(D.samples>0&&oi(D)===!1){U.__webglMultisampledFramebuffer=r.createFramebuffer(),U.__webglColorRenderbuffer=[],t.bindFramebuffer(r.FRAMEBUFFER,U.__webglMultisampledFramebuffer);for(let Z=0;Z<K.length;Z++){const Q=K[Z];U.__webglColorRenderbuffer[Z]=r.createRenderbuffer(),r.bindRenderbuffer(r.RENDERBUFFER,U.__webglColorRenderbuffer[Z]);const he=s.convert(Q.format,Q.colorSpace),Pe=s.convert(Q.type),fe=M(Q.internalFormat,he,Pe,Q.normalized,Q.colorSpace,D.isXRRenderTarget===!0),ue=qt(D);r.renderbufferStorageMultisample(r.RENDERBUFFER,ue,fe,D.width,D.height),r.framebufferRenderbuffer(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0+Z,r.RENDERBUFFER,U.__webglColorRenderbuffer[Z])}r.bindRenderbuffer(r.RENDERBUFFER,null),D.depthBuffer&&(U.__webglDepthRenderbuffer=r.createRenderbuffer(),Ce(U.__webglDepthRenderbuffer,D,!0)),t.bindFramebuffer(r.FRAMEBUFFER,null)}}if(oe){t.bindTexture(r.TEXTURE_CUBE_MAP,W.__webglTexture),qe(r.TEXTURE_CUBE_MAP,y);for(let Z=0;Z<6;Z++)if(y.mipmaps&&y.mipmaps.length>0)for(let Q=0;Q<y.mipmaps.length;Q++)Ne(U.__webglFramebuffer[Z][Q],D,y,r.COLOR_ATTACHMENT0,r.TEXTURE_CUBE_MAP_POSITIVE_X+Z,Q);else Ne(U.__webglFramebuffer[Z],D,y,r.COLOR_ATTACHMENT0,r.TEXTURE_CUBE_MAP_POSITIVE_X+Z,0);g(y)&&_(r.TEXTURE_CUBE_MAP),t.unbindTexture()}else if(le){for(let Z=0,Q=K.length;Z<Q;Z++){const he=K[Z],Pe=i.get(he);let fe=r.TEXTURE_2D;(D.isWebGL3DRenderTarget||D.isWebGLArrayRenderTarget)&&(fe=D.isWebGL3DRenderTarget?r.TEXTURE_3D:r.TEXTURE_2D_ARRAY),t.bindTexture(fe,Pe.__webglTexture),qe(fe,he),Ne(U.__webglFramebuffer,D,he,r.COLOR_ATTACHMENT0+Z,fe,0),g(he)&&_(fe)}t.unbindTexture()}else{let Z=r.TEXTURE_2D;if((D.isWebGL3DRenderTarget||D.isWebGLArrayRenderTarget)&&(Z=D.isWebGL3DRenderTarget?r.TEXTURE_3D:r.TEXTURE_2D_ARRAY),t.bindTexture(Z,W.__webglTexture),qe(Z,y),y.mipmaps&&y.mipmaps.length>0)for(let Q=0;Q<y.mipmaps.length;Q++)Ne(U.__webglFramebuffer[Q],D,y,r.COLOR_ATTACHMENT0,Z,Q);else Ne(U.__webglFramebuffer,D,y,r.COLOR_ATTACHMENT0,Z,0);g(y)&&_(Z),t.unbindTexture()}D.depthBuffer&&ke(D)}function gt(D){const y=D.textures;for(let U=0,W=y.length;U<W;U++){const K=y[U];if(g(K)){const oe=b(D),le=i.get(K).__webglTexture;t.bindTexture(oe,le),_(oe),t.unbindTexture()}}}const vt=[],Yt=[];function kt(D){if(D.samples>0){if(oi(D)===!1){const y=D.textures,U=D.width,W=D.height;let K=r.COLOR_BUFFER_BIT;const oe=D.stencilBuffer?r.DEPTH_STENCIL_ATTACHMENT:r.DEPTH_ATTACHMENT,le=i.get(D),Z=y.length>1;if(Z)for(let he=0;he<y.length;he++)t.bindFramebuffer(r.FRAMEBUFFER,le.__webglMultisampledFramebuffer),r.framebufferRenderbuffer(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0+he,r.RENDERBUFFER,null),t.bindFramebuffer(r.FRAMEBUFFER,le.__webglFramebuffer),r.framebufferTexture2D(r.DRAW_FRAMEBUFFER,r.COLOR_ATTACHMENT0+he,r.TEXTURE_2D,null,0);t.bindFramebuffer(r.READ_FRAMEBUFFER,le.__webglMultisampledFramebuffer);const Q=D.texture.mipmaps;Q&&Q.length>0?t.bindFramebuffer(r.DRAW_FRAMEBUFFER,le.__webglFramebuffer[0]):t.bindFramebuffer(r.DRAW_FRAMEBUFFER,le.__webglFramebuffer);for(let he=0;he<y.length;he++){if(D.resolveDepthBuffer&&(D.depthBuffer&&(K|=r.DEPTH_BUFFER_BIT),D.stencilBuffer&&D.resolveStencilBuffer&&(K|=r.STENCIL_BUFFER_BIT)),Z){r.framebufferRenderbuffer(r.READ_FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.RENDERBUFFER,le.__webglColorRenderbuffer[he]);const Pe=i.get(y[he]).__webglTexture;r.framebufferTexture2D(r.DRAW_FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,Pe,0)}r.blitFramebuffer(0,0,U,W,0,0,U,W,K,r.NEAREST),c===!0&&(vt.length=0,Yt.length=0,vt.push(r.COLOR_ATTACHMENT0+he),D.depthBuffer&&D.resolveDepthBuffer===!1&&(vt.push(oe),Yt.push(oe),r.invalidateFramebuffer(r.DRAW_FRAMEBUFFER,Yt)),r.invalidateFramebuffer(r.READ_FRAMEBUFFER,vt))}if(t.bindFramebuffer(r.READ_FRAMEBUFFER,null),t.bindFramebuffer(r.DRAW_FRAMEBUFFER,null),Z)for(let he=0;he<y.length;he++){t.bindFramebuffer(r.FRAMEBUFFER,le.__webglMultisampledFramebuffer),r.framebufferRenderbuffer(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0+he,r.RENDERBUFFER,le.__webglColorRenderbuffer[he]);const Pe=i.get(y[he]).__webglTexture;t.bindFramebuffer(r.FRAMEBUFFER,le.__webglFramebuffer),r.framebufferTexture2D(r.DRAW_FRAMEBUFFER,r.COLOR_ATTACHMENT0+he,r.TEXTURE_2D,Pe,0)}t.bindFramebuffer(r.DRAW_FRAMEBUFFER,le.__webglMultisampledFramebuffer)}else if(D.depthBuffer&&D.resolveDepthBuffer===!1&&c){const y=D.stencilBuffer?r.DEPTH_STENCIL_ATTACHMENT:r.DEPTH_ATTACHMENT;r.invalidateFramebuffer(r.DRAW_FRAMEBUFFER,[y])}}}function qt(D){return Math.min(n.maxSamples,D.samples)}function oi(D){const y=i.get(D);return D.samples>0&&e.has("WEBGL_multisampled_render_to_texture")===!0&&y.__useRenderToTexture!==!1}function N(D){const y=a.render.frame;h.get(D)!==y&&(h.set(D,y),D.update())}function Yi(D,y){const U=D.colorSpace,W=D.format,K=D.type;return D.isCompressedTexture===!0||D.isVideoTexture===!0||U!==El&&U!==Js&&(at.getTransfer(U)===yt?(W!==Ei||K!==dn)&&Re("WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType."):Ge("WebGLTextures: Unsupported texture color space:",U)),y}function Mt(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=ee,this.setTexture3D=J,this.setTextureCube=ie,this.rebindTextures=ze,this.setupRenderTarget=Be,this.updateRenderTargetMipmap=gt,this.updateMultisampleRenderTarget=kt,this.setupDepthRenderbuffer=ke,this.setupFrameBufferTexture=Ne,this.useMultisampledRTT=oi,this.isReversedDepthBuffer=function(){return t.buffers.depth.getReversed()}}function US(r,e){function t(i,n=Js){let s;const a=at.getTransfer(n);if(i===dn)return r.UNSIGNED_BYTE;if(i===f0)return r.UNSIGNED_SHORT_4_4_4_4;if(i===p0)return r.UNSIGNED_SHORT_5_5_5_1;if(i===$g)return r.UNSIGNED_INT_5_9_9_9_REV;if(i===Kg)return r.UNSIGNED_INT_10F_11F_11F_REV;if(i===Yg)return r.BYTE;if(i===qg)return r.SHORT;if(i===Vo)return r.UNSIGNED_SHORT;if(i===d0)return r.INT;if(i===_n)return r.UNSIGNED_INT;if(i===Oi)return r.FLOAT;if(i===Wt)return r.HALF_FLOAT;if(i===Zg)return r.ALPHA;if(i===Jg)return r.RGB;if(i===Ei)return r.RGBA;if(i===Rs)return r.DEPTH_COMPONENT;if(i===Ra)return r.DEPTH_STENCIL;if(i===ql)return r.RED;if(i===m0)return r.RED_INTEGER;if(i===ka)return r.RG;if(i===g0)return r.RG_INTEGER;if(i===v0)return r.RGBA_INTEGER;if(i===ol||i===cl||i===ll||i===hl)if(a===yt)if(s=e.get("WEBGL_compressed_texture_s3tc_srgb"),s!==null){if(i===ol)return s.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(i===cl)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(i===ll)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(i===hl)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else return null;else if(s=e.get("WEBGL_compressed_texture_s3tc"),s!==null){if(i===ol)return s.COMPRESSED_RGB_S3TC_DXT1_EXT;if(i===cl)return s.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(i===ll)return s.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(i===hl)return s.COMPRESSED_RGBA_S3TC_DXT5_EXT}else return null;if(i===Vu||i===Wu||i===Xu||i===Yu)if(s=e.get("WEBGL_compressed_texture_pvrtc"),s!==null){if(i===Vu)return s.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(i===Wu)return s.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(i===Xu)return s.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(i===Yu)return s.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}else return null;if(i===qu||i===$u||i===Ku||i===Zu||i===Ju||i===yl||i===ju)if(s=e.get("WEBGL_compressed_texture_etc"),s!==null){if(i===qu||i===$u)return a===yt?s.COMPRESSED_SRGB8_ETC2:s.COMPRESSED_RGB8_ETC2;if(i===Ku)return a===yt?s.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:s.COMPRESSED_RGBA8_ETC2_EAC;if(i===Zu)return s.COMPRESSED_R11_EAC;if(i===Ju)return s.COMPRESSED_SIGNED_R11_EAC;if(i===yl)return s.COMPRESSED_RG11_EAC;if(i===ju)return s.COMPRESSED_SIGNED_RG11_EAC}else return null;if(i===Qu||i===ed||i===td||i===id||i===nd||i===sd||i===ad||i===rd||i===od||i===cd||i===ld||i===hd||i===ud||i===dd)if(s=e.get("WEBGL_compressed_texture_astc"),s!==null){if(i===Qu)return a===yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:s.COMPRESSED_RGBA_ASTC_4x4_KHR;if(i===ed)return a===yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:s.COMPRESSED_RGBA_ASTC_5x4_KHR;if(i===td)return a===yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:s.COMPRESSED_RGBA_ASTC_5x5_KHR;if(i===id)return a===yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:s.COMPRESSED_RGBA_ASTC_6x5_KHR;if(i===nd)return a===yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:s.COMPRESSED_RGBA_ASTC_6x6_KHR;if(i===sd)return a===yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:s.COMPRESSED_RGBA_ASTC_8x5_KHR;if(i===ad)return a===yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:s.COMPRESSED_RGBA_ASTC_8x6_KHR;if(i===rd)return a===yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:s.COMPRESSED_RGBA_ASTC_8x8_KHR;if(i===od)return a===yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:s.COMPRESSED_RGBA_ASTC_10x5_KHR;if(i===cd)return a===yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:s.COMPRESSED_RGBA_ASTC_10x6_KHR;if(i===ld)return a===yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:s.COMPRESSED_RGBA_ASTC_10x8_KHR;if(i===hd)return a===yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:s.COMPRESSED_RGBA_ASTC_10x10_KHR;if(i===ud)return a===yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:s.COMPRESSED_RGBA_ASTC_12x10_KHR;if(i===dd)return a===yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:s.COMPRESSED_RGBA_ASTC_12x12_KHR}else return null;if(i===fd||i===pd||i===md)if(s=e.get("EXT_texture_compression_bptc"),s!==null){if(i===fd)return a===yt?s.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:s.COMPRESSED_RGBA_BPTC_UNORM_EXT;if(i===pd)return s.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT;if(i===md)return s.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT}else return null;if(i===gd||i===vd||i===bl||i===Md)if(s=e.get("EXT_texture_compression_rgtc"),s!==null){if(i===gd)return s.COMPRESSED_RED_RGTC1_EXT;if(i===vd)return s.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(i===bl)return s.COMPRESSED_RED_GREEN_RGTC2_EXT;if(i===Md)return s.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}else return null;return i===Wo?r.UNSIGNED_INT_24_8:r[i]!==void 0?r[i]:null}return{convert:t}}const kS=`
|
|
5392
|
+
}`,PS=[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)],LS=[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)],em=new Ze,oo=new R,qh=new R;function OS(r,e,t){let i=new A0;const n=new xe,s=new xe,a=new it,o=new yx,c=new bx,l={},h=t.maxTextureSize,u={[sa]:Ht,[Ht]:sa,[Qi]:Qi},d=new ct({defines:{VSM_SAMPLES:8},uniforms:{shadow_pass:{value:null},resolution:{value:new xe},radius:{value:4}},vertexShader:IS,fragmentShader:CS}),f=d.clone();f.defines.HORIZONTAL_PASS=1;const p=new ot;p.setAttribute("position",new tt(new Float32Array([-1,-1,.5,3,-1,.5,-1,3,.5]),3));const v=new De(p,d),m=this;this.enabled=!1,this.autoUpdate=!0,this.needsUpdate=!1,this.type=To;let g=this.type;this.render=function(w,T,x){if(m.enabled===!1||m.autoUpdate===!1&&m.needsUpdate===!1||w.length===0)return;this.type===B2&&(Re("WebGLShadowMap: PCFSoftShadowMap has been deprecated. Using PCFShadowMap instead."),this.type=To);const A=r.getRenderTarget(),C=r.getActiveCubeFace(),I=r.getActiveMipmapLevel(),P=r.state;P.setBlending(as),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){Re("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 ee=r.state.buffers.depth.getReversed();if(k.camera._reversedDepth=ee,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===xo){if(B.isPointLight){Re("WebGLShadowMap: VSM shadow maps are not supported for PointLights. Use PCF or BasicShadowMap instead.");continue}k.map=new ai(n.x,n.y,{format:ka,type:Wt,minFilter:rt,magFilter:rt,generateMipmaps:!1}),k.map.texture.name=B.name+".shadowMap",k.map.depthTexture=new aa(n.x,n.y,Oi),k.map.depthTexture.name=B.name+".shadowMapDepth",k.map.depthTexture.format=Rs,k.map.depthTexture.compareFunction=null,k.map.depthTexture.minFilter=At,k.map.depthTexture.magFilter=At}else B.isPointLight?(k.map=new qo(n.x),k.map.depthTexture=new px(n.x,_n)):(k.map=new ai(n.x,n.y),k.map.depthTexture=new aa(n.x,n.y,_n)),k.map.depthTexture.name=B.name+".shadowMap",k.map.depthTexture.format=Rs,this.type===To?(k.map.depthTexture.compareFunction=ee?y0:x0,k.map.depthTexture.minFilter=rt,k.map.depthTexture.magFilter=rt):(k.map.depthTexture.compareFunction=null,k.map.depthTexture.minFilter=At,k.map.depthTexture.magFilter=At);k.camera.updateProjectionMatrix()}const J=k.map.isWebGLCubeRenderTarget?6:1;for(let ie=0;ie<J;ie++){if(k.map.isWebGLCubeRenderTarget)r.setRenderTarget(k.map,ie),r.clear();else{ie===0&&(r.setRenderTarget(k.map),r.clear());const re=k.getViewport(ie);a.set(s.x*re.x,s.y*re.y,s.x*re.z,s.y*re.w),P.viewport(a)}if(B.isPointLight){const re=k.camera,Ve=k.matrix,Je=B.distance||re.far;Je!==re.far&&(re.far=Je,re.updateProjectionMatrix()),oo.setFromMatrixPosition(B.matrixWorld),re.position.copy(oo),qh.copy(re.position),qh.add(PS[ie]),re.up.copy(LS[ie]),re.lookAt(qh),re.updateMatrixWorld(),Ve.makeTranslation(-oo.x,-oo.y,-oo.z),em.multiplyMatrices(re.projectionMatrix,re.matrixWorldInverse),k._frustum.setFromProjectionMatrix(em,re.coordinateSystem,re.reversedDepth)}else k.updateMatrices(B);i=k.getFrustum(),M(T,x,k.camera,B,this.type)}k.isPointLightShadow!==!0&&this.type===xo&&_(k,x),k.needsUpdate=!1}g=this.type,m.needsUpdate=!1,r.setRenderTarget(A,C,I)};function _(w,T){const x=e.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 ai(n.x,n.y,{format:ka,type:Wt})),d.uniforms.shadow_pass.value=w.map.depthTexture,d.uniforms.resolution.value=w.mapSize,d.uniforms.radius.value=w.radius,r.setRenderTarget(w.mapPass),r.clear(),r.renderBufferDirect(T,null,x,d,v,null),f.uniforms.shadow_pass.value=w.mapPass.texture,f.uniforms.resolution.value=w.mapSize,f.uniforms.radius.value=w.radius,r.setRenderTarget(w.map),r.clear(),r.renderBufferDirect(T,null,x,f,v,null)}function b(w,T,x,A){let C=null;const I=x.isPointLight===!0?w.customDistanceMaterial:w.customDepthMaterial;if(I!==void 0)C=I;else if(C=x.isPointLight===!0?c:o,r.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",S)),C=L}if(C.visible=T.visible,C.wireframe=T.wireframe,A===xo?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,x.isPointLight===!0&&C.isMeshDistanceMaterial===!0){const P=r.properties.get(C);P.light=x}return C}function M(w,T,x,A,C){if(w.visible===!1)return;if(w.layers.test(T.layers)&&(w.isMesh||w.isLine||w.isPoints)&&(w.castShadow||w.receiveShadow&&C===xo)&&(!w.frustumCulled||i.intersectsObject(w))){w.modelViewMatrix.multiplyMatrices(x.matrixWorldInverse,w.matrixWorld);const V=e.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],ee=X[$.materialIndex];if(ee&&ee.visible){const J=b(w,ee,A,C);w.onBeforeShadow(r,w,T,x,V,J,$),r.renderBufferDirect(x,null,V,J,w,$),w.onAfterShadow(r,w,T,x,V,J,$)}}}else if(X.visible){const L=b(w,X,A,C);w.onBeforeShadow(r,w,T,x,V,L,null),r.renderBufferDirect(x,null,V,L,w,null),w.onAfterShadow(r,w,T,x,V,L,null)}}const P=w.children;for(let V=0,X=P.length;V<X;V++)M(P[V],T,x,A,C)}function S(w){w.target.removeEventListener("dispose",S);for(const x in l){const A=l[x],C=w.target.uuid;C in A&&(A[C].dispose(),delete A[C])}}}function NS(r,e){function t(){let O=!1;const ce=new it;let j=null;const de=new it(0,0,0,0);return{setMask:function(ve){j!==ve&&!O&&(r.colorMask(ve,ve,ve,ve),j=ve)},setLocked:function(ve){O=ve},setClear:function(ve,te,Ie,Se,$t){$t===!0&&(ve*=Se,te*=Se,Ie*=Se),ce.set(ve,te,Ie,Se),de.equals(ce)===!1&&(r.clearColor(ve,te,Ie,Se),de.copy(ce))},reset:function(){O=!1,j=null,de.set(-1,0,0,0)}}}function i(){let O=!1,ce=!1,j=null,de=null,ve=null;return{setReversed:function(te){if(ce!==te){const Ie=e.get("EXT_clip_control");te?Ie.clipControlEXT(Ie.LOWER_LEFT_EXT,Ie.ZERO_TO_ONE_EXT):Ie.clipControlEXT(Ie.LOWER_LEFT_EXT,Ie.NEGATIVE_ONE_TO_ONE_EXT),ce=te;const Se=ve;ve=null,this.setClear(Se)}},getReversed:function(){return ce},setTest:function(te){te?ne(r.DEPTH_TEST):z(r.DEPTH_TEST)},setMask:function(te){j!==te&&!O&&(r.depthMask(te),j=te)},setFunc:function(te){if(ce&&(te=_M[te]),de!==te){switch(te){case Nu:r.depthFunc(r.NEVER);break;case Fu:r.depthFunc(r.ALWAYS);break;case Uu:r.depthFunc(r.LESS);break;case Ur:r.depthFunc(r.LEQUAL);break;case ku:r.depthFunc(r.EQUAL);break;case zu:r.depthFunc(r.GEQUAL);break;case Bu:r.depthFunc(r.GREATER);break;case Hu:r.depthFunc(r.NOTEQUAL);break;default:r.depthFunc(r.LEQUAL)}de=te}},setLocked:function(te){O=te},setClear:function(te){ve!==te&&(ve=te,ce&&(te=1-te),r.clearDepth(te))},reset:function(){O=!1,j=null,de=null,ve=null,ce=!1}}}function n(){let O=!1,ce=null,j=null,de=null,ve=null,te=null,Ie=null,Se=null,$t=null;return{setTest:function(It){O||(It?ne(r.STENCIL_TEST):z(r.STENCIL_TEST))},setMask:function(It){ce!==It&&!O&&(r.stencilMask(It),ce=It)},setFunc:function(It,Hn,Gn){(j!==It||de!==Hn||ve!==Gn)&&(r.stencilFunc(It,Hn,Gn),j=It,de=Hn,ve=Gn)},setOp:function(It,Hn,Gn){(te!==It||Ie!==Hn||Se!==Gn)&&(r.stencilOp(It,Hn,Gn),te=It,Ie=Hn,Se=Gn)},setLocked:function(It){O=It},setClear:function(It){$t!==It&&(r.clearStencil(It),$t=It)},reset:function(){O=!1,ce=null,j=null,de=null,ve=null,te=null,Ie=null,Se=null,$t=null}}}const s=new t,a=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,_=null,b=null,M=null,S=null,w=null,T=null,x=new se(0,0,0),A=0,C=!1,I=null,P=null,V=null,X=null,L=null;const B=r.getParameter(r.MAX_COMBINED_TEXTURE_IMAGE_UNITS);let k=!1,$=0;const ee=r.getParameter(r.VERSION);ee.indexOf("WebGL")!==-1?($=parseFloat(/^WebGL (\d)/.exec(ee)[1]),k=$>=1):ee.indexOf("OpenGL ES")!==-1&&($=parseFloat(/^OpenGL ES (\d)/.exec(ee)[1]),k=$>=2);let J=null,ie={};const re=r.getParameter(r.SCISSOR_BOX),Ve=r.getParameter(r.VIEWPORT),Je=new it().fromArray(re),qe=new it().fromArray(Ve);function q(O,ce,j,de){const ve=new Uint8Array(4),te=r.createTexture();r.bindTexture(O,te),r.texParameteri(O,r.TEXTURE_MIN_FILTER,r.NEAREST),r.texParameteri(O,r.TEXTURE_MAG_FILTER,r.NEAREST);for(let Ie=0;Ie<j;Ie++)O===r.TEXTURE_3D||O===r.TEXTURE_2D_ARRAY?r.texImage3D(ce,0,r.RGBA,1,1,de,0,r.RGBA,r.UNSIGNED_BYTE,ve):r.texImage2D(ce+Ie,0,r.RGBA,1,1,0,r.RGBA,r.UNSIGNED_BYTE,ve);return te}const ae={};ae[r.TEXTURE_2D]=q(r.TEXTURE_2D,r.TEXTURE_2D,1),ae[r.TEXTURE_CUBE_MAP]=q(r.TEXTURE_CUBE_MAP,r.TEXTURE_CUBE_MAP_POSITIVE_X,6),ae[r.TEXTURE_2D_ARRAY]=q(r.TEXTURE_2D_ARRAY,r.TEXTURE_2D_ARRAY,1,1),ae[r.TEXTURE_3D]=q(r.TEXTURE_3D,r.TEXTURE_3D,1,1),s.setClear(0,0,0,1),a.setClear(1),o.setClear(0),ne(r.DEPTH_TEST),a.setFunc(Ur),gt(!1),vt(Uf),ne(r.CULL_FACE),ze(as);function ne(O){h[O]!==!0&&(r.enable(O),h[O]=!0)}function z(O){h[O]!==!1&&(r.disable(O),h[O]=!1)}function Te(O,ce){return d[O]!==ce?(r.bindFramebuffer(O,ce),d[O]=ce,O===r.DRAW_FRAMEBUFFER&&(d[r.FRAMEBUFFER]=ce),O===r.FRAMEBUFFER&&(d[r.DRAW_FRAMEBUFFER]=ce),!0):!1}function Ne(O,ce){let j=p,de=!1;if(O){j=f.get(ce),j===void 0&&(j=[],f.set(ce,j));const ve=O.textures;if(j.length!==ve.length||j[0]!==r.COLOR_ATTACHMENT0){for(let te=0,Ie=ve.length;te<Ie;te++)j[te]=r.COLOR_ATTACHMENT0+te;j.length=ve.length,de=!0}}else j[0]!==r.BACK&&(j[0]=r.BACK,de=!0);de&&r.drawBuffers(j)}function Ce(O){return v!==O?(r.useProgram(O),v=O,!0):!1}const be={[ba]:r.FUNC_ADD,[H2]:r.FUNC_SUBTRACT,[G2]:r.FUNC_REVERSE_SUBTRACT};be[V2]=r.MIN,be[W2]=r.MAX;const ke={[X2]:r.ZERO,[Bo]:r.ONE,[Y2]:r.SRC_COLOR,[Ou]:r.SRC_ALPHA,[j2]:r.SRC_ALPHA_SATURATE,[Z2]:r.DST_COLOR,[$2]:r.DST_ALPHA,[q2]:r.ONE_MINUS_SRC_COLOR,[Ho]:r.ONE_MINUS_SRC_ALPHA,[J2]:r.ONE_MINUS_DST_COLOR,[K2]:r.ONE_MINUS_DST_ALPHA,[Q2]:r.CONSTANT_COLOR,[eM]:r.ONE_MINUS_CONSTANT_COLOR,[tM]:r.CONSTANT_ALPHA,[iM]:r.ONE_MINUS_CONSTANT_ALPHA};function ze(O,ce,j,de,ve,te,Ie,Se,$t,It){if(O===as){m===!0&&(z(r.BLEND),m=!1);return}if(m===!1&&(ne(r.BLEND),m=!0),O!==Xl){if(O!==g||It!==C){if((_!==ba||S!==ba)&&(r.blendEquation(r.FUNC_ADD),_=ba,S=ba),It)switch(O){case ia:r.blendFuncSeparate(r.ONE,r.ONE_MINUS_SRC_ALPHA,r.ONE,r.ONE_MINUS_SRC_ALPHA);break;case Ni:r.blendFunc(r.ONE,r.ONE);break;case kf:r.blendFuncSeparate(r.ZERO,r.ONE_MINUS_SRC_COLOR,r.ZERO,r.ONE);break;case zf:r.blendFuncSeparate(r.DST_COLOR,r.ONE_MINUS_SRC_ALPHA,r.ZERO,r.ONE);break;default:Ge("WebGLState: Invalid blending: ",O);break}else switch(O){case ia:r.blendFuncSeparate(r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA,r.ONE,r.ONE_MINUS_SRC_ALPHA);break;case Ni:r.blendFuncSeparate(r.SRC_ALPHA,r.ONE,r.ONE,r.ONE);break;case kf:Ge("WebGLState: SubtractiveBlending requires material.premultipliedAlpha = true");break;case zf:Ge("WebGLState: MultiplyBlending requires material.premultipliedAlpha = true");break;default:Ge("WebGLState: Invalid blending: ",O);break}b=null,M=null,w=null,T=null,x.set(0,0,0),A=0,g=O,C=It}return}ve=ve||ce,te=te||j,Ie=Ie||de,(ce!==_||ve!==S)&&(r.blendEquationSeparate(be[ce],be[ve]),_=ce,S=ve),(j!==b||de!==M||te!==w||Ie!==T)&&(r.blendFuncSeparate(ke[j],ke[de],ke[te],ke[Ie]),b=j,M=de,w=te,T=Ie),(Se.equals(x)===!1||$t!==A)&&(r.blendColor(Se.r,Se.g,Se.b,$t),x.copy(Se),A=$t),g=O,C=!1}function Be(O,ce){O.side===Qi?z(r.CULL_FACE):ne(r.CULL_FACE);let j=O.side===Ht;ce&&(j=!j),gt(j),O.blending===ia&&O.transparent===!1?ze(as):ze(O.blending,O.blendEquation,O.blendSrc,O.blendDst,O.blendEquationAlpha,O.blendSrcAlpha,O.blendDstAlpha,O.blendColor,O.blendAlpha,O.premultipliedAlpha),a.setFunc(O.depthFunc),a.setTest(O.depthTest),a.setMask(O.depthWrite),s.setMask(O.colorWrite);const de=O.stencilWrite;o.setTest(de),de&&(o.setMask(O.stencilWriteMask),o.setFunc(O.stencilFunc,O.stencilRef,O.stencilFuncMask),o.setOp(O.stencilFail,O.stencilZFail,O.stencilZPass)),kt(O.polygonOffset,O.polygonOffsetFactor,O.polygonOffsetUnits),O.alphaToCoverage===!0?ne(r.SAMPLE_ALPHA_TO_COVERAGE):z(r.SAMPLE_ALPHA_TO_COVERAGE)}function gt(O){I!==O&&(O?r.frontFace(r.CW):r.frontFace(r.CCW),I=O)}function vt(O){O!==k2?(ne(r.CULL_FACE),O!==P&&(O===Uf?r.cullFace(r.BACK):O===z2?r.cullFace(r.FRONT):r.cullFace(r.FRONT_AND_BACK))):z(r.CULL_FACE),P=O}function Yt(O){O!==V&&(k&&r.lineWidth(O),V=O)}function kt(O,ce,j){O?(ne(r.POLYGON_OFFSET_FILL),(X!==ce||L!==j)&&(X=ce,L=j,a.getReversed()&&(ce=-ce),r.polygonOffset(ce,j))):z(r.POLYGON_OFFSET_FILL)}function qt(O){O?ne(r.SCISSOR_TEST):z(r.SCISSOR_TEST)}function oi(O){O===void 0&&(O=r.TEXTURE0+B-1),J!==O&&(r.activeTexture(O),J=O)}function N(O,ce,j){j===void 0&&(J===null?j=r.TEXTURE0+B-1:j=J);let de=ie[j];de===void 0&&(de={type:void 0,texture:void 0},ie[j]=de),(de.type!==O||de.texture!==ce)&&(J!==j&&(r.activeTexture(j),J=j),r.bindTexture(O,ce||ae[O]),de.type=O,de.texture=ce)}function qi(){const O=ie[J];O!==void 0&&O.type!==void 0&&(r.bindTexture(O.type,null),O.type=void 0,O.texture=void 0)}function Mt(){try{r.compressedTexImage2D(...arguments)}catch(O){Ge("WebGLState:",O)}}function D(){try{r.compressedTexImage3D(...arguments)}catch(O){Ge("WebGLState:",O)}}function y(){try{r.texSubImage2D(...arguments)}catch(O){Ge("WebGLState:",O)}}function U(){try{r.texSubImage3D(...arguments)}catch(O){Ge("WebGLState:",O)}}function W(){try{r.compressedTexSubImage2D(...arguments)}catch(O){Ge("WebGLState:",O)}}function K(){try{r.compressedTexSubImage3D(...arguments)}catch(O){Ge("WebGLState:",O)}}function oe(){try{r.texStorage2D(...arguments)}catch(O){Ge("WebGLState:",O)}}function le(){try{r.texStorage3D(...arguments)}catch(O){Ge("WebGLState:",O)}}function Z(){try{r.texImage2D(...arguments)}catch(O){Ge("WebGLState:",O)}}function Q(){try{r.texImage3D(...arguments)}catch(O){Ge("WebGLState:",O)}}function he(O){return u[O]!==void 0?u[O]:r.getParameter(O)}function Pe(O,ce){u[O]!==ce&&(r.pixelStorei(O,ce),u[O]=ce)}function fe(O){Je.equals(O)===!1&&(r.scissor(O.x,O.y,O.z,O.w),Je.copy(O))}function ue(O){qe.equals(O)===!1&&(r.viewport(O.x,O.y,O.z,O.w),qe.copy(O))}function Ue(O,ce){let j=l.get(ce);j===void 0&&(j=new WeakMap,l.set(ce,j));let de=j.get(O);de===void 0&&(de=r.getUniformBlockIndex(ce,O.name),j.set(O,de))}function He(O,ce){const de=l.get(ce).get(O);c.get(ce)!==de&&(r.uniformBlockBinding(ce,de,O.__bindingPointIndex),c.set(ce,de))}function $e(){r.disable(r.BLEND),r.disable(r.CULL_FACE),r.disable(r.DEPTH_TEST),r.disable(r.POLYGON_OFFSET_FILL),r.disable(r.SCISSOR_TEST),r.disable(r.STENCIL_TEST),r.disable(r.SAMPLE_ALPHA_TO_COVERAGE),r.blendEquation(r.FUNC_ADD),r.blendFunc(r.ONE,r.ZERO),r.blendFuncSeparate(r.ONE,r.ZERO,r.ONE,r.ZERO),r.blendColor(0,0,0,0),r.colorMask(!0,!0,!0,!0),r.clearColor(0,0,0,0),r.depthMask(!0),r.depthFunc(r.LESS),a.setReversed(!1),r.clearDepth(1),r.stencilMask(4294967295),r.stencilFunc(r.ALWAYS,0,4294967295),r.stencilOp(r.KEEP,r.KEEP,r.KEEP),r.clearStencil(0),r.cullFace(r.BACK),r.frontFace(r.CCW),r.polygonOffset(0,0),r.activeTexture(r.TEXTURE0),r.bindFramebuffer(r.FRAMEBUFFER,null),r.bindFramebuffer(r.DRAW_FRAMEBUFFER,null),r.bindFramebuffer(r.READ_FRAMEBUFFER,null),r.useProgram(null),r.lineWidth(1),r.scissor(0,0,r.canvas.width,r.canvas.height),r.viewport(0,0,r.canvas.width,r.canvas.height),r.pixelStorei(r.PACK_ALIGNMENT,4),r.pixelStorei(r.UNPACK_ALIGNMENT,4),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,!1),r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),r.pixelStorei(r.UNPACK_COLORSPACE_CONVERSION_WEBGL,r.BROWSER_DEFAULT_WEBGL),r.pixelStorei(r.PACK_ROW_LENGTH,0),r.pixelStorei(r.PACK_SKIP_PIXELS,0),r.pixelStorei(r.PACK_SKIP_ROWS,0),r.pixelStorei(r.UNPACK_ROW_LENGTH,0),r.pixelStorei(r.UNPACK_IMAGE_HEIGHT,0),r.pixelStorei(r.UNPACK_SKIP_PIXELS,0),r.pixelStorei(r.UNPACK_SKIP_ROWS,0),r.pixelStorei(r.UNPACK_SKIP_IMAGES,0),h={},u={},J=null,ie={},d={},f=new WeakMap,p=[],v=null,m=!1,g=null,_=null,b=null,M=null,S=null,w=null,T=null,x=new se(0,0,0),A=0,C=!1,I=null,P=null,V=null,X=null,L=null,Je.set(0,0,r.canvas.width,r.canvas.height),qe.set(0,0,r.canvas.width,r.canvas.height),s.reset(),a.reset(),o.reset()}return{buffers:{color:s,depth:a,stencil:o},enable:ne,disable:z,bindFramebuffer:Te,drawBuffers:Ne,useProgram:Ce,setBlending:ze,setMaterial:Be,setFlipSided:gt,setCullFace:vt,setLineWidth:Yt,setPolygonOffset:kt,setScissorTest:qt,activeTexture:oi,bindTexture:N,unbindTexture:qi,compressedTexImage2D:Mt,compressedTexImage3D:D,texImage2D:Z,texImage3D:Q,pixelStorei:Pe,getParameter:he,updateUBOMapping:Ue,uniformBlockBinding:He,texStorage2D:oe,texStorage3D:le,texSubImage2D:y,texSubImage3D:U,compressedTexSubImage2D:W,compressedTexSubImage3D:K,scissor:fe,viewport:ue,reset:$e}}function FS(r,e,t,i,n,s,a){const o=e.has("WEBGL_multisampled_render_to_texture")?e.get("WEBGL_multisampled_render_to_texture"):null,c=typeof navigator>"u"?!1:/OculusBrowser/g.test(navigator.userAgent),l=new xe,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,y){return p?new OffscreenCanvas(D,y):Yo("canvas")}function m(D,y,U){let W=1;const K=Mt(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 oe=Math.floor(W*K.width),le=Math.floor(W*K.height);d===void 0&&(d=v(oe,le));const Z=y?v(oe,le):d;return Z.width=oe,Z.height=le,Z.getContext("2d").drawImage(D,0,0,oe,le),Re("WebGLRenderer: Texture has been resized from ("+K.width+"x"+K.height+") to ("+oe+"x"+le+")."),Z}else return"data"in D&&Re("WebGLRenderer: Image in DataTexture is too big ("+K.width+"x"+K.height+")."),D;return D}function g(D){return D.generateMipmaps}function _(D){r.generateMipmap(D)}function b(D){return D.isWebGLCubeRenderTarget?r.TEXTURE_CUBE_MAP:D.isWebGL3DRenderTarget?r.TEXTURE_3D:D.isWebGLArrayRenderTarget||D.isCompressedArrayTexture?r.TEXTURE_2D_ARRAY:r.TEXTURE_2D}function M(D,y,U,W,K,oe=!1){if(D!==null){if(r[D]!==void 0)return r[D];Re("WebGLRenderer: Attempt to use non-existing WebGL internal format '"+D+"'")}let le;W&&(le=e.get("EXT_texture_norm16"),le||Re("WebGLRenderer: Unable to use normalized textures without EXT_texture_norm16 extension"));let Z=y;if(y===r.RED&&(U===r.FLOAT&&(Z=r.R32F),U===r.HALF_FLOAT&&(Z=r.R16F),U===r.UNSIGNED_BYTE&&(Z=r.R8),U===r.UNSIGNED_SHORT&&le&&(Z=le.R16_EXT),U===r.SHORT&&le&&(Z=le.R16_SNORM_EXT)),y===r.RED_INTEGER&&(U===r.UNSIGNED_BYTE&&(Z=r.R8UI),U===r.UNSIGNED_SHORT&&(Z=r.R16UI),U===r.UNSIGNED_INT&&(Z=r.R32UI),U===r.BYTE&&(Z=r.R8I),U===r.SHORT&&(Z=r.R16I),U===r.INT&&(Z=r.R32I)),y===r.RG&&(U===r.FLOAT&&(Z=r.RG32F),U===r.HALF_FLOAT&&(Z=r.RG16F),U===r.UNSIGNED_BYTE&&(Z=r.RG8),U===r.UNSIGNED_SHORT&&le&&(Z=le.RG16_EXT),U===r.SHORT&&le&&(Z=le.RG16_SNORM_EXT)),y===r.RG_INTEGER&&(U===r.UNSIGNED_BYTE&&(Z=r.RG8UI),U===r.UNSIGNED_SHORT&&(Z=r.RG16UI),U===r.UNSIGNED_INT&&(Z=r.RG32UI),U===r.BYTE&&(Z=r.RG8I),U===r.SHORT&&(Z=r.RG16I),U===r.INT&&(Z=r.RG32I)),y===r.RGB_INTEGER&&(U===r.UNSIGNED_BYTE&&(Z=r.RGB8UI),U===r.UNSIGNED_SHORT&&(Z=r.RGB16UI),U===r.UNSIGNED_INT&&(Z=r.RGB32UI),U===r.BYTE&&(Z=r.RGB8I),U===r.SHORT&&(Z=r.RGB16I),U===r.INT&&(Z=r.RGB32I)),y===r.RGBA_INTEGER&&(U===r.UNSIGNED_BYTE&&(Z=r.RGBA8UI),U===r.UNSIGNED_SHORT&&(Z=r.RGBA16UI),U===r.UNSIGNED_INT&&(Z=r.RGBA32UI),U===r.BYTE&&(Z=r.RGBA8I),U===r.SHORT&&(Z=r.RGBA16I),U===r.INT&&(Z=r.RGBA32I)),y===r.RGB&&(U===r.UNSIGNED_SHORT&&le&&(Z=le.RGB16_EXT),U===r.SHORT&&le&&(Z=le.RGB16_SNORM_EXT),U===r.UNSIGNED_INT_5_9_9_9_REV&&(Z=r.RGB9_E5),U===r.UNSIGNED_INT_10F_11F_11F_REV&&(Z=r.R11F_G11F_B10F)),y===r.RGBA){const Q=oe?Al:at.getTransfer(K);U===r.FLOAT&&(Z=r.RGBA32F),U===r.HALF_FLOAT&&(Z=r.RGBA16F),U===r.UNSIGNED_BYTE&&(Z=Q===yt?r.SRGB8_ALPHA8:r.RGBA8),U===r.UNSIGNED_SHORT&&le&&(Z=le.RGBA16_EXT),U===r.SHORT&&le&&(Z=le.RGBA16_SNORM_EXT),U===r.UNSIGNED_SHORT_4_4_4_4&&(Z=r.RGBA4),U===r.UNSIGNED_SHORT_5_5_5_1&&(Z=r.RGB5_A1)}return(Z===r.R16F||Z===r.R32F||Z===r.RG16F||Z===r.RG32F||Z===r.RGBA16F||Z===r.RGBA32F)&&e.get("EXT_color_buffer_float"),Z}function S(D,y){let U;return D?y===null||y===_n||y===Wo?U=r.DEPTH24_STENCIL8:y===Oi?U=r.DEPTH32F_STENCIL8:y===Vo&&(U=r.DEPTH24_STENCIL8,Re("DepthTexture: 16 bit depth attachment is not supported with stencil. Using 24-bit attachment.")):y===null||y===_n||y===Wo?U=r.DEPTH_COMPONENT24:y===Oi?U=r.DEPTH_COMPONENT32F:y===Vo&&(U=r.DEPTH_COMPONENT16),U}function w(D,y){return g(D)===!0||D.isFramebufferTexture&&D.minFilter!==At&&D.minFilter!==rt?Math.log2(Math.max(y.width,y.height))+1:D.mipmaps!==void 0&&D.mipmaps.length>0?D.mipmaps.length:D.isCompressedTexture&&Array.isArray(D.image)?y.mipmaps.length:1}function T(D){const y=D.target;y.removeEventListener("dispose",T),A(y),y.isVideoTexture&&h.delete(y),y.isHTMLTexture&&u.delete(y)}function x(D){const y=D.target;y.removeEventListener("dispose",x),I(y)}function A(D){const y=i.get(D);if(y.__webglInit===void 0)return;const U=D.source,W=f.get(U);if(W){const K=W[y.__cacheKey];K.usedTimes--,K.usedTimes===0&&C(D),Object.keys(W).length===0&&f.delete(U)}i.remove(D)}function C(D){const y=i.get(D);r.deleteTexture(y.__webglTexture);const U=D.source,W=f.get(U);delete W[y.__cacheKey],a.memory.textures--}function I(D){const y=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(y.__webglFramebuffer[W]))for(let K=0;K<y.__webglFramebuffer[W].length;K++)r.deleteFramebuffer(y.__webglFramebuffer[W][K]);else r.deleteFramebuffer(y.__webglFramebuffer[W]);y.__webglDepthbuffer&&r.deleteRenderbuffer(y.__webglDepthbuffer[W])}else{if(Array.isArray(y.__webglFramebuffer))for(let W=0;W<y.__webglFramebuffer.length;W++)r.deleteFramebuffer(y.__webglFramebuffer[W]);else r.deleteFramebuffer(y.__webglFramebuffer);if(y.__webglDepthbuffer&&r.deleteRenderbuffer(y.__webglDepthbuffer),y.__webglMultisampledFramebuffer&&r.deleteFramebuffer(y.__webglMultisampledFramebuffer),y.__webglColorRenderbuffer)for(let W=0;W<y.__webglColorRenderbuffer.length;W++)y.__webglColorRenderbuffer[W]&&r.deleteRenderbuffer(y.__webglColorRenderbuffer[W]);y.__webglDepthRenderbuffer&&r.deleteRenderbuffer(y.__webglDepthRenderbuffer)}const U=D.textures;for(let W=0,K=U.length;W<K;W++){const oe=i.get(U[W]);oe.__webglTexture&&(r.deleteTexture(oe.__webglTexture),a.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&&Re("WebGLTextures: Trying to use "+D+" texture units while this GPU supports only "+n.maxTextures),P+=1,D}function k(D){const y=[];return y.push(D.wrapS),y.push(D.wrapT),y.push(D.wrapR||0),y.push(D.magFilter),y.push(D.minFilter),y.push(D.anisotropy),y.push(D.internalFormat),y.push(D.format),y.push(D.type),y.push(D.generateMipmaps),y.push(D.premultiplyAlpha),y.push(D.flipY),y.push(D.unpackAlignment),y.push(D.colorSpace),y.join()}function $(D,y){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)Re("WebGLRenderer: Texture marked for update but no image data found.");else if(W.complete===!1)Re("WebGLRenderer: Texture marked for update but image is incomplete");else{z(U,D,y);return}}else D.isExternalTexture&&(U.__webglTexture=D.sourceTexture?D.sourceTexture:null);t.bindTexture(r.TEXTURE_2D,U.__webglTexture,r.TEXTURE0+y)}function ee(D,y){const U=i.get(D);if(D.isRenderTargetTexture===!1&&D.version>0&&U.__version!==D.version){z(U,D,y);return}else D.isExternalTexture&&(U.__webglTexture=D.sourceTexture?D.sourceTexture:null);t.bindTexture(r.TEXTURE_2D_ARRAY,U.__webglTexture,r.TEXTURE0+y)}function J(D,y){const U=i.get(D);if(D.isRenderTargetTexture===!1&&D.version>0&&U.__version!==D.version){z(U,D,y);return}t.bindTexture(r.TEXTURE_3D,U.__webglTexture,r.TEXTURE0+y)}function ie(D,y){const U=i.get(D);if(D.isCubeDepthTexture!==!0&&D.version>0&&U.__version!==D.version){Te(U,D,y);return}t.bindTexture(r.TEXTURE_CUBE_MAP,U.__webglTexture,r.TEXTURE0+y)}const re={[Go]:r.REPEAT,[wi]:r.CLAMP_TO_EDGE,[Gu]:r.MIRRORED_REPEAT},Ve={[At]:r.NEAREST,[rM]:r.NEAREST_MIPMAP_NEAREST,[lc]:r.NEAREST_MIPMAP_LINEAR,[rt]:r.LINEAR,[dh]:r.LINEAR_MIPMAP_NEAREST,[Ta]:r.LINEAR_MIPMAP_LINEAR},Je={[dM]:r.NEVER,[vM]:r.ALWAYS,[fM]:r.LESS,[x0]:r.LEQUAL,[pM]:r.EQUAL,[y0]:r.GEQUAL,[mM]:r.GREATER,[gM]:r.NOTEQUAL};function qe(D,y){if(y.type===Oi&&e.has("OES_texture_float_linear")===!1&&(y.magFilter===rt||y.magFilter===dh||y.magFilter===lc||y.magFilter===Ta||y.minFilter===rt||y.minFilter===dh||y.minFilter===lc||y.minFilter===Ta)&&Re("WebGLRenderer: Unable to use linear filtering with floating point textures. OES_texture_float_linear not supported on this device."),r.texParameteri(D,r.TEXTURE_WRAP_S,re[y.wrapS]),r.texParameteri(D,r.TEXTURE_WRAP_T,re[y.wrapT]),(D===r.TEXTURE_3D||D===r.TEXTURE_2D_ARRAY)&&r.texParameteri(D,r.TEXTURE_WRAP_R,re[y.wrapR]),r.texParameteri(D,r.TEXTURE_MAG_FILTER,Ve[y.magFilter]),r.texParameteri(D,r.TEXTURE_MIN_FILTER,Ve[y.minFilter]),y.compareFunction&&(r.texParameteri(D,r.TEXTURE_COMPARE_MODE,r.COMPARE_REF_TO_TEXTURE),r.texParameteri(D,r.TEXTURE_COMPARE_FUNC,Je[y.compareFunction])),e.has("EXT_texture_filter_anisotropic")===!0){if(y.magFilter===At||y.minFilter!==lc&&y.minFilter!==Ta||y.type===Oi&&e.has("OES_texture_float_linear")===!1)return;if(y.anisotropy>1||i.get(y).__currentAnisotropy){const U=e.get("EXT_texture_filter_anisotropic");r.texParameterf(D,U.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(y.anisotropy,n.getMaxAnisotropy())),i.get(y).__currentAnisotropy=y.anisotropy}}}function q(D,y){let U=!1;D.__webglInit===void 0&&(D.__webglInit=!0,y.addEventListener("dispose",T));const W=y.source;let K=f.get(W);K===void 0&&(K={},f.set(W,K));const oe=k(y);if(oe!==D.__cacheKey){K[oe]===void 0&&(K[oe]={texture:r.createTexture(),usedTimes:0},a.memory.textures++,U=!0),K[oe].usedTimes++;const le=K[D.__cacheKey];le!==void 0&&(K[D.__cacheKey].usedTimes--,le.usedTimes===0&&C(y)),D.__cacheKey=oe,D.__webglTexture=K[oe].texture}return U}function ae(D,y,U){return Math.floor(Math.floor(D/U)/y)}function ne(D,y,U,W){const oe=D.updateRanges;if(oe.length===0)t.texSubImage2D(r.TEXTURE_2D,0,0,0,y.width,y.height,U,W,y.data);else{oe.sort((Pe,fe)=>Pe.start-fe.start);let le=0;for(let Pe=1;Pe<oe.length;Pe++){const fe=oe[le],ue=oe[Pe],Ue=fe.start+fe.count,He=ae(ue.start,y.width,4),$e=ae(fe.start,y.width,4);ue.start<=Ue+1&&He===$e&&ae(ue.start+ue.count-1,y.width,4)===He?fe.count=Math.max(fe.count,ue.start+ue.count-fe.start):(++le,oe[le]=ue)}oe.length=le+1;const Z=t.getParameter(r.UNPACK_ROW_LENGTH),Q=t.getParameter(r.UNPACK_SKIP_PIXELS),he=t.getParameter(r.UNPACK_SKIP_ROWS);t.pixelStorei(r.UNPACK_ROW_LENGTH,y.width);for(let Pe=0,fe=oe.length;Pe<fe;Pe++){const ue=oe[Pe],Ue=Math.floor(ue.start/4),He=Math.ceil(ue.count/4),$e=Ue%y.width,O=Math.floor(Ue/y.width),ce=He,j=1;t.pixelStorei(r.UNPACK_SKIP_PIXELS,$e),t.pixelStorei(r.UNPACK_SKIP_ROWS,O),t.texSubImage2D(r.TEXTURE_2D,0,$e,O,ce,j,U,W,y.data)}D.clearUpdateRanges(),t.pixelStorei(r.UNPACK_ROW_LENGTH,Z),t.pixelStorei(r.UNPACK_SKIP_PIXELS,Q),t.pixelStorei(r.UNPACK_SKIP_ROWS,he)}}function z(D,y,U){let W=r.TEXTURE_2D;(y.isDataArrayTexture||y.isCompressedArrayTexture)&&(W=r.TEXTURE_2D_ARRAY),y.isData3DTexture&&(W=r.TEXTURE_3D);const K=q(D,y),oe=y.source;t.bindTexture(W,D.__webglTexture,r.TEXTURE0+U);const le=i.get(oe);if(oe.version!==le.__version||K===!0){if(t.activeTexture(r.TEXTURE0+U),(typeof ImageBitmap<"u"&&y.image instanceof ImageBitmap)===!1){const j=at.getPrimaries(at.workingColorSpace),de=y.colorSpace===Js?null:at.getPrimaries(y.colorSpace),ve=y.colorSpace===Js||j===de?r.NONE:r.BROWSER_DEFAULT_WEBGL;t.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,y.flipY),t.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,y.premultiplyAlpha),t.pixelStorei(r.UNPACK_COLORSPACE_CONVERSION_WEBGL,ve)}t.pixelStorei(r.UNPACK_ALIGNMENT,y.unpackAlignment);let Q=m(y.image,!1,n.maxTextureSize);Q=qi(y,Q);const he=s.convert(y.format,y.colorSpace),Pe=s.convert(y.type);let fe=M(y.internalFormat,he,Pe,y.normalized,y.colorSpace,y.isVideoTexture);qe(W,y);let ue;const Ue=y.mipmaps,He=y.isVideoTexture!==!0,$e=le.__version===void 0||K===!0,O=oe.dataReady,ce=w(y,Q);if(y.isDepthTexture)fe=S(y.format===Ra,y.type),$e&&(He?t.texStorage2D(r.TEXTURE_2D,1,fe,Q.width,Q.height):t.texImage2D(r.TEXTURE_2D,0,fe,Q.width,Q.height,0,he,Pe,null));else if(y.isDataTexture)if(Ue.length>0){He&&$e&&t.texStorage2D(r.TEXTURE_2D,ce,fe,Ue[0].width,Ue[0].height);for(let j=0,de=Ue.length;j<de;j++)ue=Ue[j],He?O&&t.texSubImage2D(r.TEXTURE_2D,j,0,0,ue.width,ue.height,he,Pe,ue.data):t.texImage2D(r.TEXTURE_2D,j,fe,ue.width,ue.height,0,he,Pe,ue.data);y.generateMipmaps=!1}else He?($e&&t.texStorage2D(r.TEXTURE_2D,ce,fe,Q.width,Q.height),O&&ne(y,Q,he,Pe)):t.texImage2D(r.TEXTURE_2D,0,fe,Q.width,Q.height,0,he,Pe,Q.data);else if(y.isCompressedTexture)if(y.isCompressedArrayTexture){He&&$e&&t.texStorage3D(r.TEXTURE_2D_ARRAY,ce,fe,Ue[0].width,Ue[0].height,Q.depth);for(let j=0,de=Ue.length;j<de;j++)if(ue=Ue[j],y.format!==Ei)if(he!==null)if(He){if(O)if(y.layerUpdates.size>0){const ve=Pp(ue.width,ue.height,y.format,y.type);for(const te of y.layerUpdates){const Ie=ue.data.subarray(te*ve/ue.data.BYTES_PER_ELEMENT,(te+1)*ve/ue.data.BYTES_PER_ELEMENT);t.compressedTexSubImage3D(r.TEXTURE_2D_ARRAY,j,0,0,te,ue.width,ue.height,1,he,Ie)}y.clearLayerUpdates()}else t.compressedTexSubImage3D(r.TEXTURE_2D_ARRAY,j,0,0,0,ue.width,ue.height,Q.depth,he,ue.data)}else t.compressedTexImage3D(r.TEXTURE_2D_ARRAY,j,fe,ue.width,ue.height,Q.depth,0,ue.data,0,0);else Re("WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()");else He?O&&t.texSubImage3D(r.TEXTURE_2D_ARRAY,j,0,0,0,ue.width,ue.height,Q.depth,he,Pe,ue.data):t.texImage3D(r.TEXTURE_2D_ARRAY,j,fe,ue.width,ue.height,Q.depth,0,he,Pe,ue.data)}else{He&&$e&&t.texStorage2D(r.TEXTURE_2D,ce,fe,Ue[0].width,Ue[0].height);for(let j=0,de=Ue.length;j<de;j++)ue=Ue[j],y.format!==Ei?he!==null?He?O&&t.compressedTexSubImage2D(r.TEXTURE_2D,j,0,0,ue.width,ue.height,he,ue.data):t.compressedTexImage2D(r.TEXTURE_2D,j,fe,ue.width,ue.height,0,ue.data):Re("WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()"):He?O&&t.texSubImage2D(r.TEXTURE_2D,j,0,0,ue.width,ue.height,he,Pe,ue.data):t.texImage2D(r.TEXTURE_2D,j,fe,ue.width,ue.height,0,he,Pe,ue.data)}else if(y.isDataArrayTexture)if(He){if($e&&t.texStorage3D(r.TEXTURE_2D_ARRAY,ce,fe,Q.width,Q.height,Q.depth),O)if(y.layerUpdates.size>0){const j=Pp(Q.width,Q.height,y.format,y.type);for(const de of y.layerUpdates){const ve=Q.data.subarray(de*j/Q.data.BYTES_PER_ELEMENT,(de+1)*j/Q.data.BYTES_PER_ELEMENT);t.texSubImage3D(r.TEXTURE_2D_ARRAY,0,0,0,de,Q.width,Q.height,1,he,Pe,ve)}y.clearLayerUpdates()}else t.texSubImage3D(r.TEXTURE_2D_ARRAY,0,0,0,0,Q.width,Q.height,Q.depth,he,Pe,Q.data)}else t.texImage3D(r.TEXTURE_2D_ARRAY,0,fe,Q.width,Q.height,Q.depth,0,he,Pe,Q.data);else if(y.isData3DTexture)He?($e&&t.texStorage3D(r.TEXTURE_3D,ce,fe,Q.width,Q.height,Q.depth),O&&t.texSubImage3D(r.TEXTURE_3D,0,0,0,0,Q.width,Q.height,Q.depth,he,Pe,Q.data)):t.texImage3D(r.TEXTURE_3D,0,fe,Q.width,Q.height,Q.depth,0,he,Pe,Q.data);else if(y.isFramebufferTexture){if($e)if(He)t.texStorage2D(r.TEXTURE_2D,ce,fe,Q.width,Q.height);else{let j=Q.width,de=Q.height;for(let ve=0;ve<ce;ve++)t.texImage2D(r.TEXTURE_2D,ve,fe,j,de,0,he,Pe,null),j>>=1,de>>=1}}else if(y.isHTMLTexture){if("texElementImage2D"in r){const j=r.canvas;if(j.hasAttribute("layoutsubtree")||j.setAttribute("layoutsubtree","true"),Q.parentNode!==j){j.appendChild(Q),u.add(y),j.onpaint=de=>{const ve=de.changedElements;for(const te of u)ve.includes(te.image)&&(te.needsUpdate=!0)},j.requestPaint();return}if(r.texElementImage2D.length===3)r.texElementImage2D(r.TEXTURE_2D,r.RGBA8,Q);else{const ve=r.RGBA,te=r.RGBA,Ie=r.UNSIGNED_BYTE;r.texElementImage2D(r.TEXTURE_2D,0,ve,te,Ie,Q)}r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE)}}else if(Ue.length>0){if(He&&$e){const j=Mt(Ue[0]);t.texStorage2D(r.TEXTURE_2D,ce,fe,j.width,j.height)}for(let j=0,de=Ue.length;j<de;j++)ue=Ue[j],He?O&&t.texSubImage2D(r.TEXTURE_2D,j,0,0,he,Pe,ue):t.texImage2D(r.TEXTURE_2D,j,fe,he,Pe,ue);y.generateMipmaps=!1}else if(He){if($e){const j=Mt(Q);t.texStorage2D(r.TEXTURE_2D,ce,fe,j.width,j.height)}O&&t.texSubImage2D(r.TEXTURE_2D,0,0,0,he,Pe,Q)}else t.texImage2D(r.TEXTURE_2D,0,fe,he,Pe,Q);g(y)&&_(W),le.__version=oe.version,y.onUpdate&&y.onUpdate(y)}D.__version=y.version}function Te(D,y,U){if(y.image.length!==6)return;const W=q(D,y),K=y.source;t.bindTexture(r.TEXTURE_CUBE_MAP,D.__webglTexture,r.TEXTURE0+U);const oe=i.get(K);if(K.version!==oe.__version||W===!0){t.activeTexture(r.TEXTURE0+U);const le=at.getPrimaries(at.workingColorSpace),Z=y.colorSpace===Js?null:at.getPrimaries(y.colorSpace),Q=y.colorSpace===Js||le===Z?r.NONE:r.BROWSER_DEFAULT_WEBGL;t.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,y.flipY),t.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,y.premultiplyAlpha),t.pixelStorei(r.UNPACK_ALIGNMENT,y.unpackAlignment),t.pixelStorei(r.UNPACK_COLORSPACE_CONVERSION_WEBGL,Q);const he=y.isCompressedTexture||y.image[0].isCompressedTexture,Pe=y.image[0]&&y.image[0].isDataTexture,fe=[];for(let te=0;te<6;te++)!he&&!Pe?fe[te]=m(y.image[te],!0,n.maxCubemapSize):fe[te]=Pe?y.image[te].image:y.image[te],fe[te]=qi(y,fe[te]);const ue=fe[0],Ue=s.convert(y.format,y.colorSpace),He=s.convert(y.type),$e=M(y.internalFormat,Ue,He,y.normalized,y.colorSpace),O=y.isVideoTexture!==!0,ce=oe.__version===void 0||W===!0,j=K.dataReady;let de=w(y,ue);qe(r.TEXTURE_CUBE_MAP,y);let ve;if(he){O&&ce&&t.texStorage2D(r.TEXTURE_CUBE_MAP,de,$e,ue.width,ue.height);for(let te=0;te<6;te++){ve=fe[te].mipmaps;for(let Ie=0;Ie<ve.length;Ie++){const Se=ve[Ie];y.format!==Ei?Ue!==null?O?j&&t.compressedTexSubImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+te,Ie,0,0,Se.width,Se.height,Ue,Se.data):t.compressedTexImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+te,Ie,$e,Se.width,Se.height,0,Se.data):Re("WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()"):O?j&&t.texSubImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+te,Ie,0,0,Se.width,Se.height,Ue,He,Se.data):t.texImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+te,Ie,$e,Se.width,Se.height,0,Ue,He,Se.data)}}}else{if(ve=y.mipmaps,O&&ce){ve.length>0&&de++;const te=Mt(fe[0]);t.texStorage2D(r.TEXTURE_CUBE_MAP,de,$e,te.width,te.height)}for(let te=0;te<6;te++)if(Pe){O?j&&t.texSubImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+te,0,0,0,fe[te].width,fe[te].height,Ue,He,fe[te].data):t.texImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+te,0,$e,fe[te].width,fe[te].height,0,Ue,He,fe[te].data);for(let Ie=0;Ie<ve.length;Ie++){const $t=ve[Ie].image[te].image;O?j&&t.texSubImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+te,Ie+1,0,0,$t.width,$t.height,Ue,He,$t.data):t.texImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+te,Ie+1,$e,$t.width,$t.height,0,Ue,He,$t.data)}}else{O?j&&t.texSubImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+te,0,0,0,Ue,He,fe[te]):t.texImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+te,0,$e,Ue,He,fe[te]);for(let Ie=0;Ie<ve.length;Ie++){const Se=ve[Ie];O?j&&t.texSubImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+te,Ie+1,0,0,Ue,He,Se.image[te]):t.texImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+te,Ie+1,$e,Ue,He,Se.image[te])}}}g(y)&&_(r.TEXTURE_CUBE_MAP),oe.__version=K.version,y.onUpdate&&y.onUpdate(y)}D.__version=y.version}function Ne(D,y,U,W,K,oe){const le=s.convert(U.format,U.colorSpace),Z=s.convert(U.type),Q=M(U.internalFormat,le,Z,U.normalized,U.colorSpace),he=i.get(y),Pe=i.get(U);if(Pe.__renderTarget=y,!he.__hasExternalTextures){const fe=Math.max(1,y.width>>oe),ue=Math.max(1,y.height>>oe);K===r.TEXTURE_3D||K===r.TEXTURE_2D_ARRAY?t.texImage3D(K,oe,Q,fe,ue,y.depth,0,le,Z,null):t.texImage2D(K,oe,Q,fe,ue,0,le,Z,null)}t.bindFramebuffer(r.FRAMEBUFFER,D),oi(y)?o.framebufferTexture2DMultisampleEXT(r.FRAMEBUFFER,W,K,Pe.__webglTexture,0,qt(y)):(K===r.TEXTURE_2D||K>=r.TEXTURE_CUBE_MAP_POSITIVE_X&&K<=r.TEXTURE_CUBE_MAP_NEGATIVE_Z)&&r.framebufferTexture2D(r.FRAMEBUFFER,W,K,Pe.__webglTexture,oe),t.bindFramebuffer(r.FRAMEBUFFER,null)}function Ce(D,y,U){if(r.bindRenderbuffer(r.RENDERBUFFER,D),y.depthBuffer){const W=y.depthTexture,K=W&&W.isDepthTexture?W.type:null,oe=S(y.stencilBuffer,K),le=y.stencilBuffer?r.DEPTH_STENCIL_ATTACHMENT:r.DEPTH_ATTACHMENT;oi(y)?o.renderbufferStorageMultisampleEXT(r.RENDERBUFFER,qt(y),oe,y.width,y.height):U?r.renderbufferStorageMultisample(r.RENDERBUFFER,qt(y),oe,y.width,y.height):r.renderbufferStorage(r.RENDERBUFFER,oe,y.width,y.height),r.framebufferRenderbuffer(r.FRAMEBUFFER,le,r.RENDERBUFFER,D)}else{const W=y.textures;for(let K=0;K<W.length;K++){const oe=W[K],le=s.convert(oe.format,oe.colorSpace),Z=s.convert(oe.type),Q=M(oe.internalFormat,le,Z,oe.normalized,oe.colorSpace);oi(y)?o.renderbufferStorageMultisampleEXT(r.RENDERBUFFER,qt(y),Q,y.width,y.height):U?r.renderbufferStorageMultisample(r.RENDERBUFFER,qt(y),Q,y.width,y.height):r.renderbufferStorage(r.RENDERBUFFER,Q,y.width,y.height)}}r.bindRenderbuffer(r.RENDERBUFFER,null)}function be(D,y,U){const W=y.isWebGLCubeRenderTarget===!0;if(t.bindFramebuffer(r.FRAMEBUFFER,D),!(y.depthTexture&&y.depthTexture.isDepthTexture))throw new Error("THREE.WebGLTextures: renderTarget.depthTexture must be an instance of THREE.DepthTexture.");const K=i.get(y.depthTexture);if(K.__renderTarget=y,(!K.__webglTexture||y.depthTexture.image.width!==y.width||y.depthTexture.image.height!==y.height)&&(y.depthTexture.image.width=y.width,y.depthTexture.image.height=y.height,y.depthTexture.needsUpdate=!0),W){if(K.__webglInit===void 0&&(K.__webglInit=!0,y.depthTexture.addEventListener("dispose",T)),K.__webglTexture===void 0){K.__webglTexture=r.createTexture(),t.bindTexture(r.TEXTURE_CUBE_MAP,K.__webglTexture),qe(r.TEXTURE_CUBE_MAP,y.depthTexture);const he=s.convert(y.depthTexture.format),Pe=s.convert(y.depthTexture.type);let fe;y.depthTexture.format===Rs?fe=r.DEPTH_COMPONENT24:y.depthTexture.format===Ra&&(fe=r.DEPTH24_STENCIL8);for(let ue=0;ue<6;ue++)r.texImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+ue,0,fe,y.width,y.height,0,he,Pe,null)}}else $(y.depthTexture,0);const oe=K.__webglTexture,le=qt(y),Z=W?r.TEXTURE_CUBE_MAP_POSITIVE_X+U:r.TEXTURE_2D,Q=y.depthTexture.format===Ra?r.DEPTH_STENCIL_ATTACHMENT:r.DEPTH_ATTACHMENT;if(y.depthTexture.format===Rs)oi(y)?o.framebufferTexture2DMultisampleEXT(r.FRAMEBUFFER,Q,Z,oe,0,le):r.framebufferTexture2D(r.FRAMEBUFFER,Q,Z,oe,0);else if(y.depthTexture.format===Ra)oi(y)?o.framebufferTexture2DMultisampleEXT(r.FRAMEBUFFER,Q,Z,oe,0,le):r.framebufferTexture2D(r.FRAMEBUFFER,Q,Z,oe,0);else throw new Error("THREE.WebGLTextures: Unknown depthTexture format.")}function ke(D){const y=i.get(D),U=D.isWebGLCubeRenderTarget===!0;if(y.__boundDepthTexture!==D.depthTexture){const W=D.depthTexture;if(y.__depthDisposeCallback&&y.__depthDisposeCallback(),W){const K=()=>{delete y.__boundDepthTexture,delete y.__depthDisposeCallback,W.removeEventListener("dispose",K)};W.addEventListener("dispose",K),y.__depthDisposeCallback=K}y.__boundDepthTexture=W}if(D.depthTexture&&!y.__autoAllocateDepthBuffer)if(U)for(let W=0;W<6;W++)be(y.__webglFramebuffer[W],D,W);else{const W=D.texture.mipmaps;W&&W.length>0?be(y.__webglFramebuffer[0],D,0):be(y.__webglFramebuffer,D,0)}else if(U){y.__webglDepthbuffer=[];for(let W=0;W<6;W++)if(t.bindFramebuffer(r.FRAMEBUFFER,y.__webglFramebuffer[W]),y.__webglDepthbuffer[W]===void 0)y.__webglDepthbuffer[W]=r.createRenderbuffer(),Ce(y.__webglDepthbuffer[W],D,!1);else{const K=D.stencilBuffer?r.DEPTH_STENCIL_ATTACHMENT:r.DEPTH_ATTACHMENT,oe=y.__webglDepthbuffer[W];r.bindRenderbuffer(r.RENDERBUFFER,oe),r.framebufferRenderbuffer(r.FRAMEBUFFER,K,r.RENDERBUFFER,oe)}}else{const W=D.texture.mipmaps;if(W&&W.length>0?t.bindFramebuffer(r.FRAMEBUFFER,y.__webglFramebuffer[0]):t.bindFramebuffer(r.FRAMEBUFFER,y.__webglFramebuffer),y.__webglDepthbuffer===void 0)y.__webglDepthbuffer=r.createRenderbuffer(),Ce(y.__webglDepthbuffer,D,!1);else{const K=D.stencilBuffer?r.DEPTH_STENCIL_ATTACHMENT:r.DEPTH_ATTACHMENT,oe=y.__webglDepthbuffer;r.bindRenderbuffer(r.RENDERBUFFER,oe),r.framebufferRenderbuffer(r.FRAMEBUFFER,K,r.RENDERBUFFER,oe)}}t.bindFramebuffer(r.FRAMEBUFFER,null)}function ze(D,y,U){const W=i.get(D);y!==void 0&&Ne(W.__webglFramebuffer,D,D.texture,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,0),U!==void 0&&ke(D)}function Be(D){const y=D.texture,U=i.get(D),W=i.get(y);D.addEventListener("dispose",x);const K=D.textures,oe=D.isWebGLCubeRenderTarget===!0,le=K.length>1;if(le||(W.__webglTexture===void 0&&(W.__webglTexture=r.createTexture()),W.__version=y.version,a.memory.textures++),oe){U.__webglFramebuffer=[];for(let Z=0;Z<6;Z++)if(y.mipmaps&&y.mipmaps.length>0){U.__webglFramebuffer[Z]=[];for(let Q=0;Q<y.mipmaps.length;Q++)U.__webglFramebuffer[Z][Q]=r.createFramebuffer()}else U.__webglFramebuffer[Z]=r.createFramebuffer()}else{if(y.mipmaps&&y.mipmaps.length>0){U.__webglFramebuffer=[];for(let Z=0;Z<y.mipmaps.length;Z++)U.__webglFramebuffer[Z]=r.createFramebuffer()}else U.__webglFramebuffer=r.createFramebuffer();if(le)for(let Z=0,Q=K.length;Z<Q;Z++){const he=i.get(K[Z]);he.__webglTexture===void 0&&(he.__webglTexture=r.createTexture(),a.memory.textures++)}if(D.samples>0&&oi(D)===!1){U.__webglMultisampledFramebuffer=r.createFramebuffer(),U.__webglColorRenderbuffer=[],t.bindFramebuffer(r.FRAMEBUFFER,U.__webglMultisampledFramebuffer);for(let Z=0;Z<K.length;Z++){const Q=K[Z];U.__webglColorRenderbuffer[Z]=r.createRenderbuffer(),r.bindRenderbuffer(r.RENDERBUFFER,U.__webglColorRenderbuffer[Z]);const he=s.convert(Q.format,Q.colorSpace),Pe=s.convert(Q.type),fe=M(Q.internalFormat,he,Pe,Q.normalized,Q.colorSpace,D.isXRRenderTarget===!0),ue=qt(D);r.renderbufferStorageMultisample(r.RENDERBUFFER,ue,fe,D.width,D.height),r.framebufferRenderbuffer(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0+Z,r.RENDERBUFFER,U.__webglColorRenderbuffer[Z])}r.bindRenderbuffer(r.RENDERBUFFER,null),D.depthBuffer&&(U.__webglDepthRenderbuffer=r.createRenderbuffer(),Ce(U.__webglDepthRenderbuffer,D,!0)),t.bindFramebuffer(r.FRAMEBUFFER,null)}}if(oe){t.bindTexture(r.TEXTURE_CUBE_MAP,W.__webglTexture),qe(r.TEXTURE_CUBE_MAP,y);for(let Z=0;Z<6;Z++)if(y.mipmaps&&y.mipmaps.length>0)for(let Q=0;Q<y.mipmaps.length;Q++)Ne(U.__webglFramebuffer[Z][Q],D,y,r.COLOR_ATTACHMENT0,r.TEXTURE_CUBE_MAP_POSITIVE_X+Z,Q);else Ne(U.__webglFramebuffer[Z],D,y,r.COLOR_ATTACHMENT0,r.TEXTURE_CUBE_MAP_POSITIVE_X+Z,0);g(y)&&_(r.TEXTURE_CUBE_MAP),t.unbindTexture()}else if(le){for(let Z=0,Q=K.length;Z<Q;Z++){const he=K[Z],Pe=i.get(he);let fe=r.TEXTURE_2D;(D.isWebGL3DRenderTarget||D.isWebGLArrayRenderTarget)&&(fe=D.isWebGL3DRenderTarget?r.TEXTURE_3D:r.TEXTURE_2D_ARRAY),t.bindTexture(fe,Pe.__webglTexture),qe(fe,he),Ne(U.__webglFramebuffer,D,he,r.COLOR_ATTACHMENT0+Z,fe,0),g(he)&&_(fe)}t.unbindTexture()}else{let Z=r.TEXTURE_2D;if((D.isWebGL3DRenderTarget||D.isWebGLArrayRenderTarget)&&(Z=D.isWebGL3DRenderTarget?r.TEXTURE_3D:r.TEXTURE_2D_ARRAY),t.bindTexture(Z,W.__webglTexture),qe(Z,y),y.mipmaps&&y.mipmaps.length>0)for(let Q=0;Q<y.mipmaps.length;Q++)Ne(U.__webglFramebuffer[Q],D,y,r.COLOR_ATTACHMENT0,Z,Q);else Ne(U.__webglFramebuffer,D,y,r.COLOR_ATTACHMENT0,Z,0);g(y)&&_(Z),t.unbindTexture()}D.depthBuffer&&ke(D)}function gt(D){const y=D.textures;for(let U=0,W=y.length;U<W;U++){const K=y[U];if(g(K)){const oe=b(D),le=i.get(K).__webglTexture;t.bindTexture(oe,le),_(oe),t.unbindTexture()}}}const vt=[],Yt=[];function kt(D){if(D.samples>0){if(oi(D)===!1){const y=D.textures,U=D.width,W=D.height;let K=r.COLOR_BUFFER_BIT;const oe=D.stencilBuffer?r.DEPTH_STENCIL_ATTACHMENT:r.DEPTH_ATTACHMENT,le=i.get(D),Z=y.length>1;if(Z)for(let he=0;he<y.length;he++)t.bindFramebuffer(r.FRAMEBUFFER,le.__webglMultisampledFramebuffer),r.framebufferRenderbuffer(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0+he,r.RENDERBUFFER,null),t.bindFramebuffer(r.FRAMEBUFFER,le.__webglFramebuffer),r.framebufferTexture2D(r.DRAW_FRAMEBUFFER,r.COLOR_ATTACHMENT0+he,r.TEXTURE_2D,null,0);t.bindFramebuffer(r.READ_FRAMEBUFFER,le.__webglMultisampledFramebuffer);const Q=D.texture.mipmaps;Q&&Q.length>0?t.bindFramebuffer(r.DRAW_FRAMEBUFFER,le.__webglFramebuffer[0]):t.bindFramebuffer(r.DRAW_FRAMEBUFFER,le.__webglFramebuffer);for(let he=0;he<y.length;he++){if(D.resolveDepthBuffer&&(D.depthBuffer&&(K|=r.DEPTH_BUFFER_BIT),D.stencilBuffer&&D.resolveStencilBuffer&&(K|=r.STENCIL_BUFFER_BIT)),Z){r.framebufferRenderbuffer(r.READ_FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.RENDERBUFFER,le.__webglColorRenderbuffer[he]);const Pe=i.get(y[he]).__webglTexture;r.framebufferTexture2D(r.DRAW_FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,Pe,0)}r.blitFramebuffer(0,0,U,W,0,0,U,W,K,r.NEAREST),c===!0&&(vt.length=0,Yt.length=0,vt.push(r.COLOR_ATTACHMENT0+he),D.depthBuffer&&D.resolveDepthBuffer===!1&&(vt.push(oe),Yt.push(oe),r.invalidateFramebuffer(r.DRAW_FRAMEBUFFER,Yt)),r.invalidateFramebuffer(r.READ_FRAMEBUFFER,vt))}if(t.bindFramebuffer(r.READ_FRAMEBUFFER,null),t.bindFramebuffer(r.DRAW_FRAMEBUFFER,null),Z)for(let he=0;he<y.length;he++){t.bindFramebuffer(r.FRAMEBUFFER,le.__webglMultisampledFramebuffer),r.framebufferRenderbuffer(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0+he,r.RENDERBUFFER,le.__webglColorRenderbuffer[he]);const Pe=i.get(y[he]).__webglTexture;t.bindFramebuffer(r.FRAMEBUFFER,le.__webglFramebuffer),r.framebufferTexture2D(r.DRAW_FRAMEBUFFER,r.COLOR_ATTACHMENT0+he,r.TEXTURE_2D,Pe,0)}t.bindFramebuffer(r.DRAW_FRAMEBUFFER,le.__webglMultisampledFramebuffer)}else if(D.depthBuffer&&D.resolveDepthBuffer===!1&&c){const y=D.stencilBuffer?r.DEPTH_STENCIL_ATTACHMENT:r.DEPTH_ATTACHMENT;r.invalidateFramebuffer(r.DRAW_FRAMEBUFFER,[y])}}}function qt(D){return Math.min(n.maxSamples,D.samples)}function oi(D){const y=i.get(D);return D.samples>0&&e.has("WEBGL_multisampled_render_to_texture")===!0&&y.__useRenderToTexture!==!1}function N(D){const y=a.render.frame;h.get(D)!==y&&(h.set(D,y),D.update())}function qi(D,y){const U=D.colorSpace,W=D.format,K=D.type;return D.isCompressedTexture===!0||D.isVideoTexture===!0||U!==El&&U!==Js&&(at.getTransfer(U)===yt?(W!==Ei||K!==dn)&&Re("WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType."):Ge("WebGLTextures: Unsupported texture color space:",U)),y}function Mt(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=ee,this.setTexture3D=J,this.setTextureCube=ie,this.rebindTextures=ze,this.setupRenderTarget=Be,this.updateRenderTargetMipmap=gt,this.updateMultisampleRenderTarget=kt,this.setupDepthRenderbuffer=ke,this.setupFrameBufferTexture=Ne,this.useMultisampledRTT=oi,this.isReversedDepthBuffer=function(){return t.buffers.depth.getReversed()}}function US(r,e){function t(i,n=Js){let s;const a=at.getTransfer(n);if(i===dn)return r.UNSIGNED_BYTE;if(i===f0)return r.UNSIGNED_SHORT_4_4_4_4;if(i===p0)return r.UNSIGNED_SHORT_5_5_5_1;if(i===$g)return r.UNSIGNED_INT_5_9_9_9_REV;if(i===Kg)return r.UNSIGNED_INT_10F_11F_11F_REV;if(i===Yg)return r.BYTE;if(i===qg)return r.SHORT;if(i===Vo)return r.UNSIGNED_SHORT;if(i===d0)return r.INT;if(i===_n)return r.UNSIGNED_INT;if(i===Oi)return r.FLOAT;if(i===Wt)return r.HALF_FLOAT;if(i===Zg)return r.ALPHA;if(i===Jg)return r.RGB;if(i===Ei)return r.RGBA;if(i===Rs)return r.DEPTH_COMPONENT;if(i===Ra)return r.DEPTH_STENCIL;if(i===ql)return r.RED;if(i===m0)return r.RED_INTEGER;if(i===ka)return r.RG;if(i===g0)return r.RG_INTEGER;if(i===v0)return r.RGBA_INTEGER;if(i===ol||i===cl||i===ll||i===hl)if(a===yt)if(s=e.get("WEBGL_compressed_texture_s3tc_srgb"),s!==null){if(i===ol)return s.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(i===cl)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(i===ll)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(i===hl)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else return null;else if(s=e.get("WEBGL_compressed_texture_s3tc"),s!==null){if(i===ol)return s.COMPRESSED_RGB_S3TC_DXT1_EXT;if(i===cl)return s.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(i===ll)return s.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(i===hl)return s.COMPRESSED_RGBA_S3TC_DXT5_EXT}else return null;if(i===Vu||i===Wu||i===Xu||i===Yu)if(s=e.get("WEBGL_compressed_texture_pvrtc"),s!==null){if(i===Vu)return s.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(i===Wu)return s.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(i===Xu)return s.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(i===Yu)return s.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}else return null;if(i===qu||i===$u||i===Ku||i===Zu||i===Ju||i===yl||i===ju)if(s=e.get("WEBGL_compressed_texture_etc"),s!==null){if(i===qu||i===$u)return a===yt?s.COMPRESSED_SRGB8_ETC2:s.COMPRESSED_RGB8_ETC2;if(i===Ku)return a===yt?s.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:s.COMPRESSED_RGBA8_ETC2_EAC;if(i===Zu)return s.COMPRESSED_R11_EAC;if(i===Ju)return s.COMPRESSED_SIGNED_R11_EAC;if(i===yl)return s.COMPRESSED_RG11_EAC;if(i===ju)return s.COMPRESSED_SIGNED_RG11_EAC}else return null;if(i===Qu||i===ed||i===td||i===id||i===nd||i===sd||i===ad||i===rd||i===od||i===cd||i===ld||i===hd||i===ud||i===dd)if(s=e.get("WEBGL_compressed_texture_astc"),s!==null){if(i===Qu)return a===yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:s.COMPRESSED_RGBA_ASTC_4x4_KHR;if(i===ed)return a===yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:s.COMPRESSED_RGBA_ASTC_5x4_KHR;if(i===td)return a===yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:s.COMPRESSED_RGBA_ASTC_5x5_KHR;if(i===id)return a===yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:s.COMPRESSED_RGBA_ASTC_6x5_KHR;if(i===nd)return a===yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:s.COMPRESSED_RGBA_ASTC_6x6_KHR;if(i===sd)return a===yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:s.COMPRESSED_RGBA_ASTC_8x5_KHR;if(i===ad)return a===yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:s.COMPRESSED_RGBA_ASTC_8x6_KHR;if(i===rd)return a===yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:s.COMPRESSED_RGBA_ASTC_8x8_KHR;if(i===od)return a===yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:s.COMPRESSED_RGBA_ASTC_10x5_KHR;if(i===cd)return a===yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:s.COMPRESSED_RGBA_ASTC_10x6_KHR;if(i===ld)return a===yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:s.COMPRESSED_RGBA_ASTC_10x8_KHR;if(i===hd)return a===yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:s.COMPRESSED_RGBA_ASTC_10x10_KHR;if(i===ud)return a===yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:s.COMPRESSED_RGBA_ASTC_12x10_KHR;if(i===dd)return a===yt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:s.COMPRESSED_RGBA_ASTC_12x12_KHR}else return null;if(i===fd||i===pd||i===md)if(s=e.get("EXT_texture_compression_bptc"),s!==null){if(i===fd)return a===yt?s.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:s.COMPRESSED_RGBA_BPTC_UNORM_EXT;if(i===pd)return s.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT;if(i===md)return s.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT}else return null;if(i===gd||i===vd||i===bl||i===Md)if(s=e.get("EXT_texture_compression_rgtc"),s!==null){if(i===gd)return s.COMPRESSED_RED_RGTC1_EXT;if(i===vd)return s.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(i===bl)return s.COMPRESSED_RED_GREEN_RGTC2_EXT;if(i===Md)return s.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}else return null;return i===Wo?r.UNSIGNED_INT_24_8:r[i]!==void 0?r[i]:null}return{convert:t}}const kS=`
|
|
5393
5393
|
void main() {
|
|
5394
5394
|
|
|
5395
5395
|
gl_Position = vec4( position, 1.0 );
|
|
@@ -5413,7 +5413,7 @@ void main() {
|
|
|
5413
5413
|
|
|
5414
5414
|
}
|
|
5415
5415
|
|
|
5416
|
-
}`;class BS{constructor(){this.texture=null,this.mesh=null,this.depthNear=0,this.depthFar=0}init(e,t){if(this.texture===null){const i=new l1(e.texture);(e.depthNear!==t.depthNear||e.depthFar!==t.depthFar)&&(this.depthNear=e.depthNear,this.depthFar=e.depthFar),this.texture=i}}getMesh(e){if(this.texture!==null&&this.mesh===null){const t=e.cameras[0].viewport,i=new ct({vertexShader:kS,fragmentShader:zS,uniforms:{depthColor:{value:this.texture},depthWidth:{value:t.z},depthHeight:{value:t.w}}});this.mesh=new De(new Xi(20,20),i)}return this.mesh}reset(){this.texture=null,this.mesh=null}getDepthTexture(){return this.texture}}class HS extends oa{constructor(e,t){super();const i=this;let n=null,s=1,a=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 BS,g={},_=t.getContextAttributes();let b=null,M=null;const S=[],w=[],T=new xe;let x=null;const A=new Ji;A.viewport=new it;const C=new Ji;C.viewport=new it;const I=[A,C],P=new kx;let V=null,X=null;this.cameraAutoUpdate=!0,this.enabled=!1,this.isPresenting=!1,this.getController=function(q){let ae=S[q];return ae===void 0&&(ae=new xh,S[q]=ae),ae.getTargetRaySpace()},this.getControllerGrip=function(q){let ae=S[q];return ae===void 0&&(ae=new xh,S[q]=ae),ae.getGripSpace()},this.getHand=function(q){let ae=S[q];return ae===void 0&&(ae=new xh,S[q]=ae),ae.getHandSpace()};function L(q){const ae=w.indexOf(q.inputSource);if(ae===-1)return;const ne=S[ae];ne!==void 0&&(ne.update(q.inputSource,q.frame,l||a),ne.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<S.length;q++){const ae=w[q];ae!==null&&(w[q]=null,S[q].disconnect(ae))}V=null,X=null,m.reset();for(const q in g)delete g[q];e.setRenderTarget(b),f=null,d=null,u=null,n=null,M=null,qe.stop(),i.isPresenting=!1,e.setPixelRatio(x),e.setSize(T.width,T.height,!1),i.dispatchEvent({type:"sessionend"})}this.setFramebufferScaleFactor=function(q){s=q,i.isPresenting===!0&&Re("WebXRManager: Cannot change framebuffer scale while presenting.")},this.setReferenceSpaceType=function(q){o=q,i.isPresenting===!0&&Re("WebXRManager: Cannot change reference space type while presenting.")},this.getReferenceSpace=function(){return l||a},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,t)),u},this.getFrame=function(){return p},this.getSession=function(){return n},this.setSession=async function(q){if(n=q,n!==null){if(b=e.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),_.xrCompatible!==!0&&await t.makeXRCompatible(),x=e.getPixelRatio(),e.getSize(T),v&&"createProjectionLayer"in XRWebGLBinding.prototype){let ne=null,z=null,Te=null;_.depth&&(Te=_.stencil?t.DEPTH24_STENCIL8:t.DEPTH_COMPONENT24,ne=_.stencil?Ra:Rs,z=_.stencil?Wo:_n);const Ne={colorFormat:t.RGBA8,depthFormat:Te,scaleFactor:s};u=this.getBinding(),d=u.createProjectionLayer(Ne),n.updateRenderState({layers:[d]}),e.setPixelRatio(1),e.setSize(d.textureWidth,d.textureHeight,!1),M=new ai(d.textureWidth,d.textureHeight,{format:Ei,type:dn,depthTexture:new aa(d.textureWidth,d.textureHeight,z,void 0,void 0,void 0,void 0,void 0,void 0,ne),stencilBuffer:_.stencil,colorSpace:e.outputColorSpace,samples:_.antialias?4:0,resolveDepthBuffer:d.ignoreDepthValues===!1,resolveStencilBuffer:d.ignoreDepthValues===!1})}else{const ne={antialias:_.antialias,alpha:!0,depth:_.depth,stencil:_.stencil,framebufferScaleFactor:s};f=new XRWebGLLayer(n,t,ne),n.updateRenderState({baseLayer:f}),e.setPixelRatio(1),e.setSize(f.framebufferWidth,f.framebufferHeight,!1),M=new ai(f.framebufferWidth,f.framebufferHeight,{format:Ei,type:dn,colorSpace:e.outputColorSpace,stencilBuffer:_.stencil,resolveDepthBuffer:f.ignoreDepthValues===!1,resolveStencilBuffer:f.ignoreDepthValues===!1})}M.isXRRenderTarget=!0,this.setFoveation(c),l=null,a=await n.requestReferenceSpace(o),qe.setContext(n),qe.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 ae=0;ae<q.removed.length;ae++){const ne=q.removed[ae],z=w.indexOf(ne);z>=0&&(w[z]=null,S[z].disconnect(ne))}for(let ae=0;ae<q.added.length;ae++){const ne=q.added[ae];let z=w.indexOf(ne);if(z===-1){for(let Ne=0;Ne<S.length;Ne++)if(Ne>=w.length){w.push(ne),z=Ne;break}else if(w[Ne]===null){w[Ne]=ne,z=Ne;break}if(z===-1)break}const Te=S[z];Te&&Te.connect(ne)}}const $=new R,ee=new R;function J(q,ae,ne){$.setFromMatrixPosition(ae.matrixWorld),ee.setFromMatrixPosition(ne.matrixWorld);const z=$.distanceTo(ee),Te=ae.projectionMatrix.elements,Ne=ne.projectionMatrix.elements,Ce=Te[14]/(Te[10]-1),be=Te[14]/(Te[10]+1),ke=(Te[9]+1)/Te[5],ze=(Te[9]-1)/Te[5],Be=(Te[8]-1)/Te[0],gt=(Ne[8]+1)/Ne[0],vt=Ce*Be,Yt=Ce*gt,kt=z/(-Be+gt),qt=kt*-Be;if(ae.matrixWorld.decompose(q.position,q.quaternion,q.scale),q.translateX(qt),q.translateZ(kt),q.matrixWorld.compose(q.position,q.quaternion,q.scale),q.matrixWorldInverse.copy(q.matrixWorld).invert(),Te[10]===-1)q.projectionMatrix.copy(ae.projectionMatrix),q.projectionMatrixInverse.copy(ae.projectionMatrixInverse);else{const oi=Ce+kt,N=be+kt,Yi=vt-qt,Mt=Yt+(z-qt),D=ke*be/N*oi,y=ze*be/N*oi;q.projectionMatrix.makePerspective(Yi,Mt,D,y,oi,N),q.projectionMatrixInverse.copy(q.projectionMatrix).invert()}}function ie(q,ae){ae===null?q.matrixWorld.copy(q.matrix):q.matrixWorld.multiplyMatrices(ae.matrixWorld,q.matrix),q.matrixWorldInverse.copy(q.matrixWorld).invert()}this.updateCamera=function(q){if(n===null)return;let ae=q.near,ne=q.far;m.texture!==null&&(m.depthNear>0&&(ae=m.depthNear),m.depthFar>0&&(ne=m.depthFar)),P.near=C.near=A.near=ae,P.far=C.far=A.far=ne,(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,Te=P.cameras;ie(P,z);for(let Ne=0;Ne<Te.length;Ne++)ie(Te[Ne],z);Te.length===2?J(P,A,C):P.projectionMatrix.copy(A.projectionMatrix),re(q,P,z)};function re(q,ae,ne){ne===null?q.matrix.copy(ae.matrixWorld):(q.matrix.copy(ne.matrixWorld),q.matrix.invert(),q.matrix.multiply(ae.matrixWorld)),q.matrix.decompose(q.position,q.quaternion,q.scale),q.updateMatrixWorld(!0),q.projectionMatrix.copy(ae.projectionMatrix),q.projectionMatrixInverse.copy(ae.projectionMatrixInverse),q.isPerspectiveCamera&&(q.fov=zr*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 Ve=null;function Je(q,ae){if(h=ae.getViewerPose(l||a),p=ae,h!==null){const ne=h.views;f!==null&&(e.setRenderTargetFramebuffer(M,f.framebuffer),e.setRenderTarget(M));let z=!1;ne.length!==P.cameras.length&&(P.cameras.length=0,z=!0);for(let be=0;be<ne.length;be++){const ke=ne[be];let ze=null;if(f!==null)ze=f.getViewport(ke);else{const gt=u.getViewSubImage(d,ke);ze=gt.viewport,be===0&&(e.setRenderTargetTextures(M,gt.colorTexture,gt.depthStencilTexture),e.setRenderTarget(M))}let Be=I[be];Be===void 0&&(Be=new Ji,Be.layers.enable(be),Be.viewport=new it,I[be]=Be),Be.matrix.fromArray(ke.transform.matrix),Be.matrix.decompose(Be.position,Be.quaternion,Be.scale),Be.projectionMatrix.fromArray(ke.projectionMatrix),Be.projectionMatrixInverse.copy(Be.projectionMatrix).invert(),Be.viewport.set(ze.x,ze.y,ze.width,ze.height),be===0&&(P.matrix.copy(Be.matrix),P.matrix.decompose(P.position,P.quaternion,P.scale)),z===!0&&P.cameras.push(Be)}const Te=n.enabledFeatures;if(Te&&Te.includes("depth-sensing")&&n.depthUsage=="gpu-optimized"&&v){u=i.getBinding();const be=u.getDepthInformation(ne[0]);be&&be.isValid&&be.texture&&m.init(be,n.renderState)}if(Te&&Te.includes("camera-access")&&v){e.state.unbindTexture(),u=i.getBinding();for(let be=0;be<ne.length;be++){const ke=ne[be].camera;if(ke){let ze=g[ke];ze||(ze=new l1,g[ke]=ze);const Be=u.getCameraImage(ke);ze.sourceTexture=Be}}}}for(let ne=0;ne<S.length;ne++){const z=w[ne],Te=S[ne];z!==null&&Te!==void 0&&Te.update(z,ae,l||a)}Ve&&Ve(q,ae),ae.detectedPlanes&&i.dispatchEvent({type:"planesdetected",data:ae}),p=null}const qe=new M1;qe.setAnimationLoop(Je),this.setAnimationLoop=function(q){Ve=q},this.dispose=function(){}}}const GS=new Ze,w1=new Ye;w1.set(-1,0,0,0,1,0,0,0,1);function VS(r,e){function t(m,g){m.matrixAutoUpdate===!0&&m.updateMatrix(),g.value.copy(m.matrix)}function i(m,g){g.color.getRGB(m.fogColor.value,h1(r)),g.isFog?(m.fogNear.value=g.near,m.fogFar.value=g.far):g.isFogExp2&&(m.fogDensity.value=g.density)}function n(m,g,_,b,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?(a(m,g),g.isLineDashedMaterial&&o(m,g)):g.isPointsMaterial?c(m,g,_,b):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,t(g.map,m.mapTransform)),g.alphaMap&&(m.alphaMap.value=g.alphaMap,t(g.alphaMap,m.alphaMapTransform)),g.bumpMap&&(m.bumpMap.value=g.bumpMap,t(g.bumpMap,m.bumpMapTransform),m.bumpScale.value=g.bumpScale,g.side===Ht&&(m.bumpScale.value*=-1)),g.normalMap&&(m.normalMap.value=g.normalMap,t(g.normalMap,m.normalMapTransform),m.normalScale.value.copy(g.normalScale),g.side===Ht&&m.normalScale.value.negate()),g.displacementMap&&(m.displacementMap.value=g.displacementMap,t(g.displacementMap,m.displacementMapTransform),m.displacementScale.value=g.displacementScale,m.displacementBias.value=g.displacementBias),g.emissiveMap&&(m.emissiveMap.value=g.emissiveMap,t(g.emissiveMap,m.emissiveMapTransform)),g.specularMap&&(m.specularMap.value=g.specularMap,t(g.specularMap,m.specularMapTransform)),g.alphaTest>0&&(m.alphaTest.value=g.alphaTest);const _=e.get(g),b=_.envMap,M=_.envMapRotation;b&&(m.envMap.value=b,m.envMapRotation.value.setFromMatrix4(GS.makeRotationFromEuler(M)).transpose(),b.isCubeTexture&&b.isRenderTargetTexture===!1&&m.envMapRotation.value.premultiply(w1),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,t(g.lightMap,m.lightMapTransform)),g.aoMap&&(m.aoMap.value=g.aoMap,m.aoMapIntensity.value=g.aoMapIntensity,t(g.aoMap,m.aoMapTransform))}function a(m,g){m.diffuse.value.copy(g.color),m.opacity.value=g.opacity,g.map&&(m.map.value=g.map,t(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,_,b){m.diffuse.value.copy(g.color),m.opacity.value=g.opacity,m.size.value=g.size*_,m.scale.value=b*.5,g.map&&(m.map.value=g.map,t(g.map,m.uvTransform)),g.alphaMap&&(m.alphaMap.value=g.alphaMap,t(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,t(g.map,m.mapTransform)),g.alphaMap&&(m.alphaMap.value=g.alphaMap,t(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,t(g.metalnessMap,m.metalnessMapTransform)),m.roughness.value=g.roughness,g.roughnessMap&&(m.roughnessMap.value=g.roughnessMap,t(g.roughnessMap,m.roughnessMapTransform)),g.envMap&&(m.envMapIntensity.value=g.envMapIntensity)}function f(m,g,_){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,t(g.sheenColorMap,m.sheenColorMapTransform)),g.sheenRoughnessMap&&(m.sheenRoughnessMap.value=g.sheenRoughnessMap,t(g.sheenRoughnessMap,m.sheenRoughnessMapTransform))),g.clearcoat>0&&(m.clearcoat.value=g.clearcoat,m.clearcoatRoughness.value=g.clearcoatRoughness,g.clearcoatMap&&(m.clearcoatMap.value=g.clearcoatMap,t(g.clearcoatMap,m.clearcoatMapTransform)),g.clearcoatRoughnessMap&&(m.clearcoatRoughnessMap.value=g.clearcoatRoughnessMap,t(g.clearcoatRoughnessMap,m.clearcoatRoughnessMapTransform)),g.clearcoatNormalMap&&(m.clearcoatNormalMap.value=g.clearcoatNormalMap,t(g.clearcoatNormalMap,m.clearcoatNormalMapTransform),m.clearcoatNormalScale.value.copy(g.clearcoatNormalScale),g.side===Ht&&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,t(g.iridescenceMap,m.iridescenceMapTransform)),g.iridescenceThicknessMap&&(m.iridescenceThicknessMap.value=g.iridescenceThicknessMap,t(g.iridescenceThicknessMap,m.iridescenceThicknessMapTransform))),g.transmission>0&&(m.transmission.value=g.transmission,m.transmissionSamplerMap.value=_.texture,m.transmissionSamplerSize.value.set(_.width,_.height),g.transmissionMap&&(m.transmissionMap.value=g.transmissionMap,t(g.transmissionMap,m.transmissionMapTransform)),m.thickness.value=g.thickness,g.thicknessMap&&(m.thicknessMap.value=g.thicknessMap,t(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,t(g.anisotropyMap,m.anisotropyMapTransform))),m.specularIntensity.value=g.specularIntensity,m.specularColor.value.copy(g.specularColor),g.specularColorMap&&(m.specularColorMap.value=g.specularColorMap,t(g.specularColorMap,m.specularColorMapTransform)),g.specularIntensityMap&&(m.specularIntensityMap.value=g.specularIntensityMap,t(g.specularIntensityMap,m.specularIntensityMapTransform))}function p(m,g){g.matcap&&(m.matcap.value=g.matcap)}function v(m,g){const _=e.get(g).light;m.referencePosition.value.setFromMatrixPosition(_.matrixWorld),m.nearDistance.value=_.shadow.camera.near,m.farDistance.value=_.shadow.camera.far}return{refreshFogUniforms:i,refreshMaterialUniforms:n}}function WS(r,e,t,i){let n={},s={},a=[];const o=r.getParameter(r.MAX_UNIFORM_BUFFER_BINDINGS);function c(M,S){const w=S.program;i.uniformBlockBinding(M,w)}function l(M,S){let w=n[M.id];w===void 0&&(m(M),w=h(M),n[M.id]=w,M.addEventListener("dispose",_));const T=S.program;i.updateUBOMapping(M,T);const x=e.render.frame;s[M.id]!==x&&(d(M),s[M.id]=x)}function h(M){const S=u();M.__bindingPointIndex=S;const w=r.createBuffer(),T=M.__size,x=M.usage;return r.bindBuffer(r.UNIFORM_BUFFER,w),r.bufferData(r.UNIFORM_BUFFER,T,x),r.bindBuffer(r.UNIFORM_BUFFER,null),r.bindBufferBase(r.UNIFORM_BUFFER,S,w),w}function u(){for(let M=0;M<o;M++)if(a.indexOf(M)===-1)return a.push(M),M;return Ge("WebGLRenderer: Maximum number of simultaneously usable uniforms groups reached."),0}function d(M){const S=n[M.id],w=M.uniforms,T=M.__cache;r.bindBuffer(r.UNIFORM_BUFFER,S);for(let x=0,A=w.length;x<A;x++){const C=w[x];if(Array.isArray(C))for(let I=0,P=C.length;I<P;I++)f(C[I],x,I,T);else f(C,x,0,T)}r.bindBuffer(r.UNIFORM_BUFFER,null)}function f(M,S,w,T){if(v(M,S,w,T)===!0){const x=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);r.bufferSubData(r.UNIFORM_BUFFER,x,M.__data)}}function p(M,S,w){typeof M=="number"||typeof M=="boolean"?S[0]=M:M.isMatrix3?(S[0]=M.elements[0],S[1]=M.elements[1],S[2]=M.elements[2],S[3]=0,S[4]=M.elements[3],S[5]=M.elements[4],S[6]=M.elements[5],S[7]=0,S[8]=M.elements[6],S[9]=M.elements[7],S[10]=M.elements[8],S[11]=0):ArrayBuffer.isView(M)?S.set(new M.constructor(M.buffer,M.byteOffset,S.length)):M.toArray(S,w)}function v(M,S,w,T){const x=M.value,A=S+"_"+w;if(T[A]===void 0)return typeof x=="number"||typeof x=="boolean"?T[A]=x:ArrayBuffer.isView(x)?T[A]=x.slice():T[A]=x.clone(),!0;{const C=T[A];if(typeof x=="number"||typeof x=="boolean"){if(C!==x)return T[A]=x,!0}else{if(ArrayBuffer.isView(x))return!0;if(C.equals(x)===!1)return C.copy(x),!0}}return!1}function m(M){const S=M.uniforms;let w=0;const T=16;for(let A=0,C=S.length;A<C;A++){const I=Array.isArray(S[A])?S[A]:[S[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],ee=g($),J=w%T,ie=J%ee.boundary,re=J+ie;w+=ie,re!==0&&T-re<ee.storage&&(w+=T-re),X.__data=new Float32Array(ee.storage/Float32Array.BYTES_PER_ELEMENT),X.__offset=w,w+=ee.storage}}}const x=w%T;return x>0&&(w+=T-x),M.__size=w,M.__cache={},this}function g(M){const S={boundary:0,storage:0};return typeof M=="number"||typeof M=="boolean"?(S.boundary=4,S.storage=4):M.isVector2?(S.boundary=8,S.storage=8):M.isVector3||M.isColor?(S.boundary=16,S.storage=12):M.isVector4?(S.boundary=16,S.storage=16):M.isMatrix3?(S.boundary=48,S.storage=48):M.isMatrix4?(S.boundary=64,S.storage=64):M.isTexture?Re("WebGLRenderer: Texture samplers can not be part of an uniforms group."):ArrayBuffer.isView(M)?(S.boundary=16,S.storage=M.byteLength):Re("WebGLRenderer: Unsupported uniform value type.",M),S}function _(M){const S=M.target;S.removeEventListener("dispose",_);const w=a.indexOf(S.__bindingPointIndex);a.splice(w,1),r.deleteBuffer(n[S.id]),delete n[S.id],delete s[S.id]}function b(){for(const M in n)r.deleteBuffer(n[M]);a=[],n={},s={}}return{bind:c,update:l,dispose:b}}const XS=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 Yn=null;function YS(){return Yn===null&&(Yn=new ca(XS,16,16,ka,Wt),Yn.name="DFG_LUT",Yn.minFilter=rt,Yn.magFilter=rt,Yn.wrapS=wi,Yn.wrapT=wi,Yn.generateMipmaps=!1,Yn.needsUpdate=!0),Yn}class qS{constructor(e={}){const{canvas:t=yM(),context:i=null,depth:n=!0,stencil:s=!1,alpha:a=!1,antialias:o=!1,premultipliedAlpha:c=!0,preserveDrawingBuffer:l=!1,powerPreference:h="default",failIfMajorPerformanceCaveat:u=!1,reversedDepthBuffer:d=!1,outputBufferType:f=dn}=e;this.isWebGLRenderer=!0;let p;if(i!==null){if(typeof WebGLRenderingContext<"u"&&i instanceof WebGLRenderingContext)throw new Error("THREE.WebGLRenderer: WebGL 1 is not supported since r163.");p=i.getContextAttributes().alpha}else p=a;const v=f,m=new Set([v0,g0,m0]),g=new Set([dn,_n,Vo,Wo,f0,p0]),_=new Uint32Array(4),b=new Int32Array(4),M=new R;let S=null,w=null;const T=[],x=[];let A=null;this.domElement=t,this.debug={checkShaderErrors:!0,onShaderError:null},this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.sortObjects=!0,this.clippingPlanes=[],this.localClippingEnabled=!1,this.toneMapping=rs,this.toneMappingExposure=1,this.transmissionResolutionScale=1;const C=this;let I=!1,P=null,V=null,X=null,L=null;this._outputColorSpace=Gi;let B=0,k=0,$=null,ee=-1,J=null;const ie=new it,re=new it;let Ve=null;const Je=new se(0);let qe=0,q=t.width,ae=t.height,ne=1,z=null,Te=null;const Ne=new it(0,0,q,ae),Ce=new it(0,0,q,ae);let be=!1;const ke=new A0;let ze=!1,Be=!1;const gt=new Ze,vt=new R,Yt=new it,kt={background:null,fog:null,environment:null,overrideMaterial:null,isScene:!0};let qt=!1;function oi(){return $===null?ne:1}let N=i;function Yi(E,F){return t.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 t&&t.setAttribute("data-engine",`three.js r${h0}`),t.addEventListener("webglcontextlost",$t,!1),t.addEventListener("webglcontextrestored",It,!1),t.addEventListener("webglcontextcreationerror",Hn,!1),N===null){const F="webgl2";if(N=Yi(F,E),N===null)throw Yi(F)?new Error("THREE.WebGLRenderer: Error creating WebGL context with your selected attributes."):new Error("THREE.WebGLRenderer: Error creating WebGL context.")}}catch(E){throw Ge("WebGLRenderer: "+E.message),E}let Mt,D,y,U,W,K,oe,le,Z,Q,he,Pe,fe,ue,Ue,He,$e,O,ce,j,de,ve,te;function Ie(){Mt=new Y_(N),Mt.init(),de=new US(N,Mt),D=new k_(N,Mt,e,de),y=new NS(N,Mt),D.reversedDepthBuffer&&d&&y.buffers.depth.setReversed(!0),V=N.createFramebuffer(),X=N.createFramebuffer(),L=N.createFramebuffer(),U=new K_(N),W=new bS,K=new FS(N,Mt,y,W,D,de,U),oe=new X_(C),le=new Qx(N),ve=new F_(N,le),Z=new q_(N,le,U,ve),Q=new J_(N,Z,le,ve,U),O=new Z_(N,D,K),Ue=new z_(W),he=new yS(C,oe,Mt,D,ve,Ue),Pe=new VS(C,W),fe=new SS,ue=new DS(Mt),$e=new N_(C,oe,y,Q,p,c),He=new OS(C,Q,D),te=new WS(N,U,D,y),ce=new U_(N,Mt,U),j=new $_(N,Mt,U),U.programs=he.programs,C.capabilities=D,C.extensions=Mt,C.properties=W,C.renderLists=fe,C.shadowMap=He,C.state=y,C.info=U}Ie(),v!==dn&&(A=new Q_(v,t.width,t.height,o,n,s));const Se=new HS(C,N);this.xr=Se,this.getContext=function(){return N},this.getContextAttributes=function(){return N.getContextAttributes()},this.forceContextLoss=function(){const E=Mt.get("WEBGL_lose_context");E&&E.loseContext()},this.forceContextRestore=function(){const E=Mt.get("WEBGL_lose_context");E&&E.restoreContext()},this.getPixelRatio=function(){return ne},this.setPixelRatio=function(E){E!==void 0&&(ne=E,this.setSize(q,ae,!1))},this.getSize=function(E){return E.set(q,ae)},this.setSize=function(E,F,Y=!0){if(Se.isPresenting){Re("WebGLRenderer: Can't change size while VR device is presenting.");return}q=E,ae=F,t.width=Math.floor(E*ne),t.height=Math.floor(F*ne),Y===!0&&(t.style.width=E+"px",t.style.height=F+"px"),A!==null&&A.setSize(t.width,t.height),this.setViewport(0,0,E,F)},this.getDrawingBufferSize=function(E){return E.set(q*ne,ae*ne).floor()},this.setDrawingBufferSize=function(E,F,Y){q=E,ae=F,ne=Y,t.width=Math.floor(E*Y),t.height=Math.floor(F*Y),this.setViewport(0,0,E,F)},this.setEffects=function(E){if(v===dn){Ge("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){Re("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(ie)},this.getViewport=function(E){return E.copy(Ne)},this.setViewport=function(E,F,Y,H){E.isVector4?Ne.set(E.x,E.y,E.z,E.w):Ne.set(E,F,Y,H),y.viewport(ie.copy(Ne).multiplyScalar(ne).round())},this.getScissor=function(E){return E.copy(Ce)},this.setScissor=function(E,F,Y,H){E.isVector4?Ce.set(E.x,E.y,E.z,E.w):Ce.set(E,F,Y,H),y.scissor(re.copy(Ce).multiplyScalar(ne).round())},this.getScissorTest=function(){return be},this.setScissorTest=function(E){y.setScissorTest(be=E)},this.setOpaqueSort=function(E){z=E},this.setTransparentSort=function(E){Te=E},this.getClearColor=function(E){return E.copy($e.getClearColor())},this.setClearColor=function(){$e.setClearColor(...arguments)},this.getClearAlpha=function(){return $e.getClearAlpha()},this.setClearAlpha=function(){$e.setClearAlpha(...arguments)},this.clear=function(E=!0,F=!0,Y=!0){let H=0;if(E){let G=!1;if($!==null){const ge=$.texture.format;G=m.has(ge)}if(G){const ge=$.texture.type,_e=g.has(ge),me=$e.getClearColor(),Ee=$e.getClearAlpha(),Le=me.r,Ke=me.g,je=me.b;_e?(_[0]=Le,_[1]=Ke,_[2]=je,_[3]=Ee,N.clearBufferuiv(N.COLOR,0,_)):(b[0]=Le,b[1]=Ke,b[2]=je,b[3]=Ee,N.clearBufferiv(N.COLOR,0,b))}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(){t.removeEventListener("webglcontextlost",$t,!1),t.removeEventListener("webglcontextrestored",It,!1),t.removeEventListener("webglcontextcreationerror",Hn,!1),$e.dispose(),fe.dispose(),ue.dispose(),W.dispose(),oe.dispose(),Q.dispose(),ve.dispose(),te.dispose(),he.dispose(),Se.dispose(),Se.removeEventListener("sessionstart",j0),Se.removeEventListener("sessionend",Q0),la.stop()};function $t(E){E.preventDefault(),Rl("WebGLRenderer: Context Lost."),I=!0}function It(){Rl("WebGLRenderer: Context Restored."),I=!1;const E=U.autoReset,F=He.enabled,Y=He.autoUpdate,H=He.needsUpdate,G=He.type;Ie(),U.autoReset=E,He.enabled=F,He.autoUpdate=Y,He.needsUpdate=H,He.type=G}function Hn(E){Ge("WebGLRenderer: A WebGL context could not be created. Reason: ",E.statusMessage)}function Gn(E){const F=E.target;F.removeEventListener("dispose",Gn),dv(F)}function dv(E){fv(E),W.remove(E)}function fv(E){const F=W.get(E).programs;F!==void 0&&(F.forEach(function(Y){he.releaseProgram(Y)}),E.isShaderMaterial&&he.releaseShaderCache(E))}this.renderBufferDirect=function(E,F,Y,H,G,ge){F===null&&(F=kt);const _e=G.isMesh&&G.matrixWorld.determinantAffine()<0,me=gv(E,F,Y,H,G);y.setMaterial(H,_e);let Ee=Y.index,Le=1;if(H.wireframe===!0){if(Ee=Z.getWireframeAttribute(Y),Ee===void 0)return;Le=2}const Ke=Y.drawRange,je=Y.attributes.position;let Oe=Ke.start*Le,wt=(Ke.start+Ke.count)*Le;ge!==null&&(Oe=Math.max(Oe,ge.start*Le),wt=Math.min(wt,(ge.start+ge.count)*Le)),Ee!==null?(Oe=Math.max(Oe,0),wt=Math.min(wt,Ee.count)):je!=null&&(Oe=Math.max(Oe,0),wt=Math.min(wt,je.count));const Qt=wt-Oe;if(Qt<0||Qt===1/0)return;ve.setup(G,H,me,Y,Ee);let Kt,Tt=ce;if(Ee!==null&&(Kt=le.get(Ee),Tt=j,Tt.setIndex(Kt)),G.isMesh)H.wireframe===!0?(y.setLineWidth(H.wireframeLinewidth*oi()),Tt.setMode(N.LINES)):Tt.setMode(N.TRIANGLES);else if(G.isLine){let Ti=H.linewidth;Ti===void 0&&(Ti=1),y.setLineWidth(Ti*oi()),G.isLineSegments?Tt.setMode(N.LINES):G.isLineLoop?Tt.setMode(N.LINE_LOOP):Tt.setMode(N.LINE_STRIP)}else G.isPoints?Tt.setMode(N.POINTS):G.isSprite&&Tt.setMode(N.TRIANGLES);if(G.isBatchedMesh)if(Mt.get("WEBGL_multi_draw"))Tt.renderMultiDraw(G._multiDrawStarts,G._multiDrawCounts,G._multiDrawCount);else{const Ti=G._multiDrawStarts,ye=G._multiDrawCounts,tn=G._multiDrawCount,lt=Ee?le.get(Ee).bytesPerElement:1,fn=W.get(H).currentProgram.getUniforms();for(let Vn=0;Vn<tn;Vn++)fn.setValue(N,"_gl_DrawID",Vn),Tt.render(Ti[Vn]/lt,ye[Vn])}else if(G.isInstancedMesh)Tt.renderInstances(Oe,Qt,G.count);else if(Y.isInstancedBufferGeometry){const Ti=Y._maxInstanceCount!==void 0?Y._maxInstanceCount:1/0,ye=Math.min(Y.instanceCount,Ti);Tt.renderInstances(Oe,Qt,ye)}else Tt.render(Oe,Qt)};function J0(E,F,Y){E.transparent===!0&&E.side===Qi&&E.forceSinglePass===!1?(E.side=Ht,E.needsUpdate=!0,tc(E,F,Y),E.side=sa,E.needsUpdate=!0,tc(E,F,Y),E.side=Qi):tc(E,F,Y)}this.compile=function(E,F,Y=null){Y===null&&(Y=E),w=ue.get(Y),w.init(F),x.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 ge=G.material;if(ge)if(Array.isArray(ge))for(let _e=0;_e<ge.length;_e++){const me=ge[_e];J0(me,Y,G),H.add(me)}else J0(ge,Y,G),H.add(ge)}),w=x.pop(),H},this.compileAsync=function(E,F,Y=null){const H=this.compile(E,F,Y);return new Promise(G=>{function ge(){if(H.forEach(function(_e){W.get(_e).currentProgram.isReady()&&H.delete(_e)}),H.size===0){G(E);return}setTimeout(ge,10)}Mt.get("KHR_parallel_shader_compile")!==null?ge():setTimeout(ge,10)})};let rh=null;function pv(E){rh&&rh(E)}function j0(){la.stop()}function Q0(){la.start()}const la=new M1;la.setAnimationLoop(pv),typeof self<"u"&&la.setContext(self),this.setAnimationLoop=function(E){rh=E,Se.setAnimationLoop(E),E===null?la.stop():la.start()},Se.addEventListener("sessionstart",j0),Se.addEventListener("sessionend",Q0),this.render=function(E,F){if(F!==void 0&&F.isCamera!==!0){Ge("WebGLRenderer.render: camera is not an instance of THREE.Camera.");return}if(I===!0)return;P!==null&&P.renderStart(E,F);const Y=Se.enabled===!0&&Se.isPresenting===!0,H=A!==null&&($===null||Y)&&A.begin(C,$);if(E.matrixWorldAutoUpdate===!0&&E.updateMatrixWorld(),F.parent===null&&F.matrixWorldAutoUpdate===!0&&F.updateMatrixWorld(),Se.enabled===!0&&Se.isPresenting===!0&&(A===null||A.isCompositing()===!1)&&(Se.cameraAutoUpdate===!0&&Se.updateCamera(F),F=Se.getCamera()),E.isScene===!0&&E.onBeforeRender(C,E,F,$),w=ue.get(E,x.length),w.init(F),w.state.textureUnits=K.getTextureUnits(),x.push(w),gt.multiplyMatrices(F.projectionMatrix,F.matrixWorldInverse),ke.setFromProjectionMatrix(gt,ns,F.reversedDepth),Be=this.localClippingEnabled,ze=Ue.init(this.clippingPlanes,Be),S=fe.get(E,T.length),S.init(),T.push(S),Se.enabled===!0&&Se.isPresenting===!0){const _e=C.xr.getDepthSensingMesh();_e!==null&&oh(_e,F,-1/0,C.sortObjects)}oh(E,F,0,C.sortObjects),S.finish(),C.sortObjects===!0&&S.sort(z,Te,F.reversedDepth),qt=Se.enabled===!1||Se.isPresenting===!1||Se.hasDepthSensing()===!1,qt&&$e.addToRenderList(S,E),this.info.render.frame++,this.info.autoReset===!0&&this.info.reset(),ze===!0&&Ue.beginShadows();const G=w.state.shadowsArray;if(He.render(G,E,F),ze===!0&&Ue.endShadows(),(H&&A.hasRenderPass())===!1){const _e=S.opaque,me=S.transmissive;if(w.setupLights(),F.isArrayCamera){const Ee=F.cameras;if(me.length>0)for(let Le=0,Ke=Ee.length;Le<Ke;Le++){const je=Ee[Le];tf(_e,me,E,je)}qt&&$e.render(E);for(let Le=0,Ke=Ee.length;Le<Ke;Le++){const je=Ee[Le];ef(S,E,je,je.viewport)}}else me.length>0&&tf(_e,me,E,F),qt&&$e.render(E),ef(S,E,F)}$!==null&&k===0&&(K.updateMultisampleRenderTarget($),K.updateRenderTargetMipmap($)),H&&A.end(C),E.isScene===!0&&E.onAfterRender(C,E,F),ve.resetDefaultState(),ee=-1,J=null,x.pop(),x.length>0?(w=x[x.length-1],K.setTextureUnits(w.state.textureUnits),ze===!0&&Ue.setGlobalState(C.clippingPlanes,w.state.camera)):w=null,T.pop(),T.length>0?S=T[T.length-1]:S=null,P!==null&&P.renderEnd()};function oh(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||ke.intersectsSprite(E)){H&&Yt.setFromMatrixPosition(E.matrixWorld).applyMatrix4(gt);const _e=Q.update(E),me=E.material;me.visible&&S.push(E,_e,me,Y,Yt.z,null)}}else if((E.isMesh||E.isLine||E.isPoints)&&(!E.frustumCulled||ke.intersectsObject(E))){const _e=Q.update(E),me=E.material;if(H&&(E.boundingSphere!==void 0?(E.boundingSphere===null&&E.computeBoundingSphere(),Yt.copy(E.boundingSphere.center)):(_e.boundingSphere===null&&_e.computeBoundingSphere(),Yt.copy(_e.boundingSphere.center)),Yt.applyMatrix4(E.matrixWorld).applyMatrix4(gt)),Array.isArray(me)){const Ee=_e.groups;for(let Le=0,Ke=Ee.length;Le<Ke;Le++){const je=Ee[Le],Oe=me[je.materialIndex];Oe&&Oe.visible&&S.push(E,_e,Oe,Y,Yt.z,je)}}else me.visible&&S.push(E,_e,me,Y,Yt.z,null)}}const ge=E.children;for(let _e=0,me=ge.length;_e<me;_e++)oh(ge[_e],F,Y,H)}function ef(E,F,Y,H){const{opaque:G,transmissive:ge,transparent:_e}=E;w.setupLightsView(Y),ze===!0&&Ue.setGlobalState(C.clippingPlanes,Y),H&&y.viewport(ie.copy(H)),G.length>0&&ec(G,F,Y),ge.length>0&&ec(ge,F,Y),_e.length>0&&ec(_e,F,Y),y.buffers.depth.setTest(!0),y.buffers.depth.setMask(!0),y.buffers.color.setMask(!0),y.setPolygonOffset(!1)}function tf(E,F,Y,H){if((Y.isScene===!0?Y.overrideMaterial:null)!==null)return;if(w.state.transmissionRenderTarget[H.id]===void 0){const Oe=Mt.has("EXT_color_buffer_half_float")||Mt.has("EXT_color_buffer_float");w.state.transmissionRenderTarget[H.id]=new ai(1,1,{generateMipmaps:!0,type:Oe?Wt:dn,minFilter:Ta,samples:Math.max(4,D.samples),stencilBuffer:s,resolveDepthBuffer:!1,resolveStencilBuffer:!1,colorSpace:at.workingColorSpace})}const ge=w.state.transmissionRenderTarget[H.id],_e=H.viewport||ie;ge.setSize(_e.z*C.transmissionResolutionScale,_e.w*C.transmissionResolutionScale);const me=C.getRenderTarget(),Ee=C.getActiveCubeFace(),Le=C.getActiveMipmapLevel();C.setRenderTarget(ge),C.getClearColor(Je),qe=C.getClearAlpha(),qe<1&&C.setClearColor(16777215,.5),C.clear(),qt&&$e.render(Y);const Ke=C.toneMapping;C.toneMapping=rs;const je=H.viewport;if(H.viewport!==void 0&&(H.viewport=void 0),w.setupLightsView(H),ze===!0&&Ue.setGlobalState(C.clippingPlanes,H),ec(E,Y,H),K.updateMultisampleRenderTarget(ge),K.updateRenderTargetMipmap(ge),Mt.has("WEBGL_multisampled_render_to_texture")===!1){let Oe=!1;for(let wt=0,Qt=F.length;wt<Qt;wt++){const Kt=F[wt],{object:Tt,geometry:Ti,material:ye,group:tn}=Kt;if(ye.side===Qi&&Tt.layers.test(H.layers)){const lt=ye.side;ye.side=Ht,ye.needsUpdate=!0,nf(Tt,Y,H,Ti,ye,tn),ye.side=lt,ye.needsUpdate=!0,Oe=!0}}Oe===!0&&(K.updateMultisampleRenderTarget(ge),K.updateRenderTargetMipmap(ge))}C.setRenderTarget(me,Ee,Le),C.setClearColor(Je,qe),je!==void 0&&(H.viewport=je),C.toneMapping=Ke}function ec(E,F,Y){const H=F.isScene===!0?F.overrideMaterial:null;for(let G=0,ge=E.length;G<ge;G++){const _e=E[G],{object:me,geometry:Ee,group:Le}=_e;let Ke=_e.material;Ke.allowOverride===!0&&H!==null&&(Ke=H),me.layers.test(Y.layers)&&nf(me,F,Y,Ee,Ke,Le)}}function nf(E,F,Y,H,G,ge){E.onBeforeRender(C,F,Y,H,G,ge),E.modelViewMatrix.multiplyMatrices(Y.matrixWorldInverse,E.matrixWorld),E.normalMatrix.getNormalMatrix(E.modelViewMatrix),G.onBeforeRender(C,F,Y,H,E,ge),G.transparent===!0&&G.side===Qi&&G.forceSinglePass===!1?(G.side=Ht,G.needsUpdate=!0,C.renderBufferDirect(Y,F,H,G,E,ge),G.side=sa,G.needsUpdate=!0,C.renderBufferDirect(Y,F,H,G,E,ge),G.side=Qi):C.renderBufferDirect(Y,F,H,G,E,ge),E.onAfterRender(C,F,Y,H,G,ge)}function tc(E,F,Y){F.isScene!==!0&&(F=kt);const H=W.get(E),G=w.state.lights,ge=w.state.shadowsArray,_e=G.state.version,me=he.getParameters(E,G.state,ge,F,Y,w.state.lightProbeGridArray),Ee=he.getProgramCacheKey(me);let Le=H.programs;H.environment=E.isMeshStandardMaterial||E.isMeshLambertMaterial||E.isMeshPhongMaterial?F.environment:null,H.fog=F.fog;const Ke=E.isMeshStandardMaterial||E.isMeshLambertMaterial&&!E.envMap||E.isMeshPhongMaterial&&!E.envMap;H.envMap=oe.get(E.envMap||H.environment,Ke),H.envMapRotation=H.environment!==null&&E.envMap===null?F.environmentRotation:E.envMapRotation,Le===void 0&&(E.addEventListener("dispose",Gn),Le=new Map,H.programs=Le);let je=Le.get(Ee);if(je!==void 0){if(H.currentProgram===je&&H.lightsStateVersion===_e)return af(E,me),je}else me.uniforms=he.getUniforms(E),P!==null&&E.isNodeMaterial&&P.build(E,Y,me),E.onBeforeCompile(me,C),je=he.acquireProgram(me,Ee),Le.set(Ee,je),H.uniforms=me.uniforms;const Oe=H.uniforms;return(!E.isShaderMaterial&&!E.isRawShaderMaterial||E.clipping===!0)&&(Oe.clippingPlanes=Ue.uniform),af(E,me),H.needsLights=Mv(E),H.lightsStateVersion=_e,H.needsLights&&(Oe.ambientLightColor.value=G.state.ambient,Oe.lightProbe.value=G.state.probe,Oe.directionalLights.value=G.state.directional,Oe.directionalLightShadows.value=G.state.directionalShadow,Oe.spotLights.value=G.state.spot,Oe.spotLightShadows.value=G.state.spotShadow,Oe.rectAreaLights.value=G.state.rectArea,Oe.ltc_1.value=G.state.rectAreaLTC1,Oe.ltc_2.value=G.state.rectAreaLTC2,Oe.pointLights.value=G.state.point,Oe.pointLightShadows.value=G.state.pointShadow,Oe.hemisphereLights.value=G.state.hemi,Oe.directionalShadowMatrix.value=G.state.directionalShadowMatrix,Oe.spotLightMatrix.value=G.state.spotLightMatrix,Oe.spotLightMap.value=G.state.spotLightMap,Oe.pointShadowMatrix.value=G.state.pointShadowMatrix),H.lightProbeGrid=w.state.lightProbeGridArray.length>0,H.currentProgram=je,H.uniformsList=null,je}function sf(E){if(E.uniformsList===null){const F=E.currentProgram.getUniforms();E.uniformsList=fl.seqWithValue(F.seq,E.uniforms)}return E.uniformsList}function af(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 mv(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 gv(E,F,Y,H,G){F.isScene!==!0&&(F=kt),K.resetTextureUnits();const ge=F.fog,_e=H.isMeshStandardMaterial||H.isMeshLambertMaterial||H.isMeshPhongMaterial?F.environment:null,me=$===null?C.outputColorSpace:$.isXRRenderTarget===!0?$.texture.colorSpace:at.workingColorSpace,Ee=H.isMeshStandardMaterial||H.isMeshLambertMaterial&&!H.envMap||H.isMeshPhongMaterial&&!H.envMap,Le=oe.get(H.envMap||_e,Ee),Ke=H.vertexColors===!0&&!!Y.attributes.color&&Y.attributes.color.itemSize===4,je=!!Y.attributes.tangent&&(!!H.normalMap||H.anisotropy>0),Oe=!!Y.morphAttributes.position,wt=!!Y.morphAttributes.normal,Qt=!!Y.morphAttributes.color;let Kt=rs;H.toneMapped&&($===null||$.isXRRenderTarget===!0)&&(Kt=C.toneMapping);const Tt=Y.morphAttributes.position||Y.morphAttributes.normal||Y.morphAttributes.color,Ti=Tt!==void 0?Tt.length:0,ye=W.get(H),tn=w.state.lights;if(ze===!0&&(Be===!0||E!==J)){const Ct=E===J&&H.id===ee;Ue.setState(H,E,Ct)}let lt=!1;H.version===ye.__version?(ye.needsLights&&ye.lightsStateVersion!==tn.state.version||ye.outputColorSpace!==me||G.isBatchedMesh&&ye.batching===!1||!G.isBatchedMesh&&ye.batching===!0||G.isBatchedMesh&&ye.batchingColor===!0&&G.colorTexture===null||G.isBatchedMesh&&ye.batchingColor===!1&&G.colorTexture!==null||G.isInstancedMesh&&ye.instancing===!1||!G.isInstancedMesh&&ye.instancing===!0||G.isSkinnedMesh&&ye.skinning===!1||!G.isSkinnedMesh&&ye.skinning===!0||G.isInstancedMesh&&ye.instancingColor===!0&&G.instanceColor===null||G.isInstancedMesh&&ye.instancingColor===!1&&G.instanceColor!==null||G.isInstancedMesh&&ye.instancingMorph===!0&&G.morphTexture===null||G.isInstancedMesh&&ye.instancingMorph===!1&&G.morphTexture!==null||ye.envMap!==Le||H.fog===!0&&ye.fog!==ge||ye.numClippingPlanes!==void 0&&(ye.numClippingPlanes!==Ue.numPlanes||ye.numIntersection!==Ue.numIntersection)||ye.vertexAlphas!==Ke||ye.vertexTangents!==je||ye.morphTargets!==Oe||ye.morphNormals!==wt||ye.morphColors!==Qt||ye.toneMapping!==Kt||ye.morphTargetsCount!==Ti||!!ye.lightProbeGrid!=w.state.lightProbeGridArray.length>0)&&(lt=!0):(lt=!0,ye.__version=H.version);let fn=ye.currentProgram;lt===!0&&(fn=tc(H,F,G),P&&H.isNodeMaterial&&P.onUpdateProgram(H,fn,ye));let Vn=!1,Os=!1,Ha=!1;const Rt=fn.getUniforms(),ei=ye.uniforms;if(y.useProgram(fn.program)&&(Vn=!0,Os=!0,Ha=!0),H.id!==ee&&(ee=H.id,Os=!0),ye.needsLights){const Ct=mv(w.state.lightProbeGridArray,G);ye.lightProbeGrid!==Ct&&(ye.lightProbeGrid=Ct,Os=!0)}if(Vn||J!==E){y.buffers.depth.getReversed()&&E.reversedDepth!==!0&&(E._reversedDepth=!0,E.updateProjectionMatrix()),Rt.setValue(N,"projectionMatrix",E.projectionMatrix),Rt.setValue(N,"viewMatrix",E.matrixWorldInverse);const Fs=Rt.map.cameraPosition;Fs!==void 0&&Fs.setValue(N,vt.setFromMatrixPosition(E.matrixWorld)),D.logarithmicDepthBuffer&&Rt.setValue(N,"logDepthBufFC",2/(Math.log(E.far+1)/Math.LN2)),(H.isMeshPhongMaterial||H.isMeshToonMaterial||H.isMeshLambertMaterial||H.isMeshBasicMaterial||H.isMeshStandardMaterial||H.isShaderMaterial)&&Rt.setValue(N,"isOrthographic",E.isOrthographicCamera===!0),J!==E&&(J=E,Os=!0,Ha=!0)}if(ye.needsLights&&(tn.state.directionalShadowMap.length>0&&Rt.setValue(N,"directionalShadowMap",tn.state.directionalShadowMap,K),tn.state.spotShadowMap.length>0&&Rt.setValue(N,"spotShadowMap",tn.state.spotShadowMap,K),tn.state.pointShadowMap.length>0&&Rt.setValue(N,"pointShadowMap",tn.state.pointShadowMap,K)),G.isSkinnedMesh){Rt.setOptional(N,G,"bindMatrix"),Rt.setOptional(N,G,"bindMatrixInverse");const Ct=G.skeleton;Ct&&(Ct.boneTexture===null&&Ct.computeBoneTexture(),Rt.setValue(N,"boneTexture",Ct.boneTexture,K))}G.isBatchedMesh&&(Rt.setOptional(N,G,"batchingTexture"),Rt.setValue(N,"batchingTexture",G._matricesTexture,K),Rt.setOptional(N,G,"batchingIdTexture"),Rt.setValue(N,"batchingIdTexture",G._indirectTexture,K),Rt.setOptional(N,G,"batchingColorTexture"),G._colorsTexture!==null&&Rt.setValue(N,"batchingColorTexture",G._colorsTexture,K));const Ns=Y.morphAttributes;if((Ns.position!==void 0||Ns.normal!==void 0||Ns.color!==void 0)&&O.update(G,Y,fn),(Os||ye.receiveShadow!==G.receiveShadow)&&(ye.receiveShadow=G.receiveShadow,Rt.setValue(N,"receiveShadow",G.receiveShadow)),(H.isMeshStandardMaterial||H.isMeshLambertMaterial||H.isMeshPhongMaterial)&&H.envMap===null&&F.environment!==null&&(ei.envMapIntensity.value=F.environmentIntensity),ei.dfgLUT!==void 0&&(ei.dfgLUT.value=YS()),Os){if(Rt.setValue(N,"toneMappingExposure",C.toneMappingExposure),ye.needsLights&&vv(ei,Ha),ge&&H.fog===!0&&Pe.refreshFogUniforms(ei,ge),Pe.refreshMaterialUniforms(ei,H,ne,ae,w.state.transmissionRenderTarget[E.id]),ye.needsLights&&ye.lightProbeGrid){const Ct=ye.lightProbeGrid;ei.probesSH.value=Ct.texture,ei.probesMin.value.copy(Ct.boundingBox.min),ei.probesMax.value.copy(Ct.boundingBox.max),ei.probesResolution.value.copy(Ct.resolution)}fl.upload(N,sf(ye),ei,K)}if(H.isShaderMaterial&&H.uniformsNeedUpdate===!0&&(fl.upload(N,sf(ye),ei,K),H.uniformsNeedUpdate=!1),H.isSpriteMaterial&&Rt.setValue(N,"center",G.center),Rt.setValue(N,"modelViewMatrix",G.modelViewMatrix),Rt.setValue(N,"normalMatrix",G.normalMatrix),Rt.setValue(N,"modelMatrix",G.matrixWorld),H.uniformsGroups!==void 0){const Ct=H.uniformsGroups;for(let Fs=0,Ga=Ct.length;Fs<Ga;Fs++){const rf=Ct[Fs];te.update(rf,fn),te.bind(rf,fn)}}return fn}function vv(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 Mv(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,ge=!1;if(E){const me=W.get(E);if(me.__useDefaultFramebuffer!==void 0){y.bindFramebuffer(N.FRAMEBUFFER,me.__webglFramebuffer),ie.copy(E.viewport),re.copy(E.scissor),Ve=E.scissorTest,y.viewport(ie),y.scissor(re),y.setScissorTest(Ve),ee=-1;return}else if(me.__webglFramebuffer===void 0)K.setupRenderTarget(E);else if(me.__hasExternalTextures)K.rebindTextures(E,W.get(E.texture).__webglTexture,W.get(E.depthTexture).__webglTexture);else if(E.depthBuffer){const Ke=E.depthTexture;if(me.__boundDepthTexture!==Ke){if(Ke!==null&&W.has(Ke)&&(E.width!==Ke.image.width||E.height!==Ke.image.height))throw new Error("THREE.WebGLRenderer: Attached DepthTexture is initialized to the incorrect size.");K.setupDepthRenderbuffer(E)}}const Ee=E.texture;(Ee.isData3DTexture||Ee.isDataArrayTexture||Ee.isCompressedArrayTexture)&&(ge=!0);const Le=W.get(E).__webglFramebuffer;E.isWebGLCubeRenderTarget?(Array.isArray(Le[F])?H=Le[F][Y]:H=Le[F],G=!0):E.samples>0&&K.useMultisampledRTT(E)===!1?H=W.get(E).__webglMultisampledFramebuffer:Array.isArray(Le)?H=Le[Y]:H=Le,ie.copy(E.viewport),re.copy(E.scissor),Ve=E.scissorTest}else ie.copy(Ne).multiplyScalar(ne).floor(),re.copy(Ce).multiplyScalar(ne).floor(),Ve=be;if(Y!==0&&(H=V),y.bindFramebuffer(N.FRAMEBUFFER,H)&&y.drawBuffers(E,H),y.viewport(ie),y.scissor(re),y.setScissorTest(Ve),G){const me=W.get(E.texture);N.framebufferTexture2D(N.FRAMEBUFFER,N.COLOR_ATTACHMENT0,N.TEXTURE_CUBE_MAP_POSITIVE_X+F,me.__webglTexture,Y)}else if(ge){const me=F;for(let Ee=0;Ee<E.textures.length;Ee++){const Le=W.get(E.textures[Ee]);N.framebufferTextureLayer(N.FRAMEBUFFER,N.COLOR_ATTACHMENT0+Ee,Le.__webglTexture,Y,me)}}else if(E!==null&&Y!==0){const me=W.get(E.texture);N.framebufferTexture2D(N.FRAMEBUFFER,N.COLOR_ATTACHMENT0,N.TEXTURE_2D,me.__webglTexture,Y)}ee=-1},this.readRenderTargetPixels=function(E,F,Y,H,G,ge,_e,me=0){if(!(E&&E.isWebGLRenderTarget)){Ge("WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");return}let Ee=W.get(E).__webglFramebuffer;if(E.isWebGLCubeRenderTarget&&_e!==void 0&&(Ee=Ee[_e]),Ee){y.bindFramebuffer(N.FRAMEBUFFER,Ee);try{const Le=E.textures[me],Ke=Le.format,je=Le.type;if(E.textures.length>1&&N.readBuffer(N.COLOR_ATTACHMENT0+me),!D.textureFormatReadable(Ke)){Ge("WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.");return}if(!D.textureTypeReadable(je)){Ge("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,de.convert(Ke),de.convert(je),ge)}finally{const Le=$!==null?W.get($).__webglFramebuffer:null;y.bindFramebuffer(N.FRAMEBUFFER,Le)}}},this.readRenderTargetPixelsAsync=async function(E,F,Y,H,G,ge,_e,me=0){if(!(E&&E.isWebGLRenderTarget))throw new Error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");let Ee=W.get(E).__webglFramebuffer;if(E.isWebGLCubeRenderTarget&&_e!==void 0&&(Ee=Ee[_e]),Ee)if(F>=0&&F<=E.width-H&&Y>=0&&Y<=E.height-G){y.bindFramebuffer(N.FRAMEBUFFER,Ee);const Le=E.textures[me],Ke=Le.format,je=Le.type;if(E.textures.length>1&&N.readBuffer(N.COLOR_ATTACHMENT0+me),!D.textureFormatReadable(Ke))throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.");if(!D.textureTypeReadable(je))throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.");const Oe=N.createBuffer();N.bindBuffer(N.PIXEL_PACK_BUFFER,Oe),N.bufferData(N.PIXEL_PACK_BUFFER,ge.byteLength,N.STREAM_READ),N.readPixels(F,Y,H,G,de.convert(Ke),de.convert(je),0);const wt=$!==null?W.get($).__webglFramebuffer:null;y.bindFramebuffer(N.FRAMEBUFFER,wt);const Qt=N.fenceSync(N.SYNC_GPU_COMMANDS_COMPLETE,0);return N.flush(),await bM(N,Qt,4),N.bindBuffer(N.PIXEL_PACK_BUFFER,Oe),N.getBufferSubData(N.PIXEL_PACK_BUFFER,0,ge),N.deleteBuffer(Oe),N.deleteSync(Qt),ge}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),ge=Math.floor(E.image.height*H),_e=F!==null?F.x:0,me=F!==null?F.y:0;K.setTexture2D(E,0),N.copyTexSubImage2D(N.TEXTURE_2D,Y,0,0,_e,me,G,ge),y.unbindTexture()},this.copyTextureToTexture=function(E,F,Y=null,H=null,G=0,ge=0){let _e,me,Ee,Le,Ke,je,Oe,wt,Qt;const Kt=E.isCompressedTexture?E.mipmaps[ge]:E.image;if(Y!==null)_e=Y.max.x-Y.min.x,me=Y.max.y-Y.min.y,Ee=Y.isBox3?Y.max.z-Y.min.z:1,Le=Y.min.x,Ke=Y.min.y,je=Y.isBox3?Y.min.z:0;else{const ei=Math.pow(2,-G);_e=Math.floor(Kt.width*ei),me=Math.floor(Kt.height*ei),E.isDataArrayTexture?Ee=Kt.depth:E.isData3DTexture?Ee=Math.floor(Kt.depth*ei):Ee=1,Le=0,Ke=0,je=0}H!==null?(Oe=H.x,wt=H.y,Qt=H.z):(Oe=0,wt=0,Qt=0);const Tt=de.convert(F.format),Ti=de.convert(F.type);let ye;F.isData3DTexture?(K.setTexture3D(F,0),ye=N.TEXTURE_3D):F.isDataArrayTexture||F.isCompressedArrayTexture?(K.setTexture2DArray(F,0),ye=N.TEXTURE_2D_ARRAY):(K.setTexture2D(F,0),ye=N.TEXTURE_2D),y.activeTexture(N.TEXTURE0),y.pixelStorei(N.UNPACK_FLIP_Y_WEBGL,F.flipY),y.pixelStorei(N.UNPACK_PREMULTIPLY_ALPHA_WEBGL,F.premultiplyAlpha),y.pixelStorei(N.UNPACK_ALIGNMENT,F.unpackAlignment);const tn=y.getParameter(N.UNPACK_ROW_LENGTH),lt=y.getParameter(N.UNPACK_IMAGE_HEIGHT),fn=y.getParameter(N.UNPACK_SKIP_PIXELS),Vn=y.getParameter(N.UNPACK_SKIP_ROWS),Os=y.getParameter(N.UNPACK_SKIP_IMAGES);y.pixelStorei(N.UNPACK_ROW_LENGTH,Kt.width),y.pixelStorei(N.UNPACK_IMAGE_HEIGHT,Kt.height),y.pixelStorei(N.UNPACK_SKIP_PIXELS,Le),y.pixelStorei(N.UNPACK_SKIP_ROWS,Ke),y.pixelStorei(N.UNPACK_SKIP_IMAGES,je);const Ha=E.isDataArrayTexture||E.isData3DTexture,Rt=F.isDataArrayTexture||F.isData3DTexture;if(E.isDepthTexture){const ei=W.get(E),Ns=W.get(F),Ct=W.get(ei.__renderTarget),Fs=W.get(Ns.__renderTarget);y.bindFramebuffer(N.READ_FRAMEBUFFER,Ct.__webglFramebuffer),y.bindFramebuffer(N.DRAW_FRAMEBUFFER,Fs.__webglFramebuffer);for(let Ga=0;Ga<Ee;Ga++)Ha&&(N.framebufferTextureLayer(N.READ_FRAMEBUFFER,N.COLOR_ATTACHMENT0,W.get(E).__webglTexture,G,je+Ga),N.framebufferTextureLayer(N.DRAW_FRAMEBUFFER,N.COLOR_ATTACHMENT0,W.get(F).__webglTexture,ge,Qt+Ga)),N.blitFramebuffer(Le,Ke,_e,me,Oe,wt,_e,me,N.DEPTH_BUFFER_BIT,N.NEAREST);y.bindFramebuffer(N.READ_FRAMEBUFFER,null),y.bindFramebuffer(N.DRAW_FRAMEBUFFER,null)}else if(G!==0||E.isRenderTargetTexture||W.has(E)){const ei=W.get(E),Ns=W.get(F);y.bindFramebuffer(N.READ_FRAMEBUFFER,X),y.bindFramebuffer(N.DRAW_FRAMEBUFFER,L);for(let Ct=0;Ct<Ee;Ct++)Ha?N.framebufferTextureLayer(N.READ_FRAMEBUFFER,N.COLOR_ATTACHMENT0,ei.__webglTexture,G,je+Ct):N.framebufferTexture2D(N.READ_FRAMEBUFFER,N.COLOR_ATTACHMENT0,N.TEXTURE_2D,ei.__webglTexture,G),Rt?N.framebufferTextureLayer(N.DRAW_FRAMEBUFFER,N.COLOR_ATTACHMENT0,Ns.__webglTexture,ge,Qt+Ct):N.framebufferTexture2D(N.DRAW_FRAMEBUFFER,N.COLOR_ATTACHMENT0,N.TEXTURE_2D,Ns.__webglTexture,ge),G!==0?N.blitFramebuffer(Le,Ke,_e,me,Oe,wt,_e,me,N.COLOR_BUFFER_BIT,N.NEAREST):Rt?N.copyTexSubImage3D(ye,ge,Oe,wt,Qt+Ct,Le,Ke,_e,me):N.copyTexSubImage2D(ye,ge,Oe,wt,Le,Ke,_e,me);y.bindFramebuffer(N.READ_FRAMEBUFFER,null),y.bindFramebuffer(N.DRAW_FRAMEBUFFER,null)}else Rt?E.isDataTexture||E.isData3DTexture?N.texSubImage3D(ye,ge,Oe,wt,Qt,_e,me,Ee,Tt,Ti,Kt.data):F.isCompressedArrayTexture?N.compressedTexSubImage3D(ye,ge,Oe,wt,Qt,_e,me,Ee,Tt,Kt.data):N.texSubImage3D(ye,ge,Oe,wt,Qt,_e,me,Ee,Tt,Ti,Kt):E.isDataTexture?N.texSubImage2D(N.TEXTURE_2D,ge,Oe,wt,_e,me,Tt,Ti,Kt.data):E.isCompressedTexture?N.compressedTexSubImage2D(N.TEXTURE_2D,ge,Oe,wt,Kt.width,Kt.height,Tt,Kt.data):N.texSubImage2D(N.TEXTURE_2D,ge,Oe,wt,_e,me,Tt,Ti,Kt);y.pixelStorei(N.UNPACK_ROW_LENGTH,tn),y.pixelStorei(N.UNPACK_IMAGE_HEIGHT,lt),y.pixelStorei(N.UNPACK_SKIP_PIXELS,fn),y.pixelStorei(N.UNPACK_SKIP_ROWS,Vn),y.pixelStorei(N.UNPACK_SKIP_IMAGES,Os),ge===0&&F.generateMipmaps&&N.generateMipmap(ye),y.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),y.unbindTexture()},this.resetState=function(){B=0,k=0,$=null,y.reset(),ve.reset()},typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}get coordinateSystem(){return ns}get outputColorSpace(){return this._outputColorSpace}set outputColorSpace(e){this._outputColorSpace=e;const t=this.getContext();t.drawingBufferColorSpace=at._getDrawingBufferColorSpace(e),t.unpackColorSpace=at._getUnpackColorSpace()}}const $S=`
|
|
5416
|
+
}`;class BS{constructor(){this.texture=null,this.mesh=null,this.depthNear=0,this.depthFar=0}init(e,t){if(this.texture===null){const i=new l1(e.texture);(e.depthNear!==t.depthNear||e.depthFar!==t.depthFar)&&(this.depthNear=e.depthNear,this.depthFar=e.depthFar),this.texture=i}}getMesh(e){if(this.texture!==null&&this.mesh===null){const t=e.cameras[0].viewport,i=new ct({vertexShader:kS,fragmentShader:zS,uniforms:{depthColor:{value:this.texture},depthWidth:{value:t.z},depthHeight:{value:t.w}}});this.mesh=new De(new Yi(20,20),i)}return this.mesh}reset(){this.texture=null,this.mesh=null}getDepthTexture(){return this.texture}}class HS extends oa{constructor(e,t){super();const i=this;let n=null,s=1,a=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 BS,g={},_=t.getContextAttributes();let b=null,M=null;const S=[],w=[],T=new xe;let x=null;const A=new Ji;A.viewport=new it;const C=new Ji;C.viewport=new it;const I=[A,C],P=new kx;let V=null,X=null;this.cameraAutoUpdate=!0,this.enabled=!1,this.isPresenting=!1,this.getController=function(q){let ae=S[q];return ae===void 0&&(ae=new xh,S[q]=ae),ae.getTargetRaySpace()},this.getControllerGrip=function(q){let ae=S[q];return ae===void 0&&(ae=new xh,S[q]=ae),ae.getGripSpace()},this.getHand=function(q){let ae=S[q];return ae===void 0&&(ae=new xh,S[q]=ae),ae.getHandSpace()};function L(q){const ae=w.indexOf(q.inputSource);if(ae===-1)return;const ne=S[ae];ne!==void 0&&(ne.update(q.inputSource,q.frame,l||a),ne.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<S.length;q++){const ae=w[q];ae!==null&&(w[q]=null,S[q].disconnect(ae))}V=null,X=null,m.reset();for(const q in g)delete g[q];e.setRenderTarget(b),f=null,d=null,u=null,n=null,M=null,qe.stop(),i.isPresenting=!1,e.setPixelRatio(x),e.setSize(T.width,T.height,!1),i.dispatchEvent({type:"sessionend"})}this.setFramebufferScaleFactor=function(q){s=q,i.isPresenting===!0&&Re("WebXRManager: Cannot change framebuffer scale while presenting.")},this.setReferenceSpaceType=function(q){o=q,i.isPresenting===!0&&Re("WebXRManager: Cannot change reference space type while presenting.")},this.getReferenceSpace=function(){return l||a},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,t)),u},this.getFrame=function(){return p},this.getSession=function(){return n},this.setSession=async function(q){if(n=q,n!==null){if(b=e.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),_.xrCompatible!==!0&&await t.makeXRCompatible(),x=e.getPixelRatio(),e.getSize(T),v&&"createProjectionLayer"in XRWebGLBinding.prototype){let ne=null,z=null,Te=null;_.depth&&(Te=_.stencil?t.DEPTH24_STENCIL8:t.DEPTH_COMPONENT24,ne=_.stencil?Ra:Rs,z=_.stencil?Wo:_n);const Ne={colorFormat:t.RGBA8,depthFormat:Te,scaleFactor:s};u=this.getBinding(),d=u.createProjectionLayer(Ne),n.updateRenderState({layers:[d]}),e.setPixelRatio(1),e.setSize(d.textureWidth,d.textureHeight,!1),M=new ai(d.textureWidth,d.textureHeight,{format:Ei,type:dn,depthTexture:new aa(d.textureWidth,d.textureHeight,z,void 0,void 0,void 0,void 0,void 0,void 0,ne),stencilBuffer:_.stencil,colorSpace:e.outputColorSpace,samples:_.antialias?4:0,resolveDepthBuffer:d.ignoreDepthValues===!1,resolveStencilBuffer:d.ignoreDepthValues===!1})}else{const ne={antialias:_.antialias,alpha:!0,depth:_.depth,stencil:_.stencil,framebufferScaleFactor:s};f=new XRWebGLLayer(n,t,ne),n.updateRenderState({baseLayer:f}),e.setPixelRatio(1),e.setSize(f.framebufferWidth,f.framebufferHeight,!1),M=new ai(f.framebufferWidth,f.framebufferHeight,{format:Ei,type:dn,colorSpace:e.outputColorSpace,stencilBuffer:_.stencil,resolveDepthBuffer:f.ignoreDepthValues===!1,resolveStencilBuffer:f.ignoreDepthValues===!1})}M.isXRRenderTarget=!0,this.setFoveation(c),l=null,a=await n.requestReferenceSpace(o),qe.setContext(n),qe.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 ae=0;ae<q.removed.length;ae++){const ne=q.removed[ae],z=w.indexOf(ne);z>=0&&(w[z]=null,S[z].disconnect(ne))}for(let ae=0;ae<q.added.length;ae++){const ne=q.added[ae];let z=w.indexOf(ne);if(z===-1){for(let Ne=0;Ne<S.length;Ne++)if(Ne>=w.length){w.push(ne),z=Ne;break}else if(w[Ne]===null){w[Ne]=ne,z=Ne;break}if(z===-1)break}const Te=S[z];Te&&Te.connect(ne)}}const $=new R,ee=new R;function J(q,ae,ne){$.setFromMatrixPosition(ae.matrixWorld),ee.setFromMatrixPosition(ne.matrixWorld);const z=$.distanceTo(ee),Te=ae.projectionMatrix.elements,Ne=ne.projectionMatrix.elements,Ce=Te[14]/(Te[10]-1),be=Te[14]/(Te[10]+1),ke=(Te[9]+1)/Te[5],ze=(Te[9]-1)/Te[5],Be=(Te[8]-1)/Te[0],gt=(Ne[8]+1)/Ne[0],vt=Ce*Be,Yt=Ce*gt,kt=z/(-Be+gt),qt=kt*-Be;if(ae.matrixWorld.decompose(q.position,q.quaternion,q.scale),q.translateX(qt),q.translateZ(kt),q.matrixWorld.compose(q.position,q.quaternion,q.scale),q.matrixWorldInverse.copy(q.matrixWorld).invert(),Te[10]===-1)q.projectionMatrix.copy(ae.projectionMatrix),q.projectionMatrixInverse.copy(ae.projectionMatrixInverse);else{const oi=Ce+kt,N=be+kt,qi=vt-qt,Mt=Yt+(z-qt),D=ke*be/N*oi,y=ze*be/N*oi;q.projectionMatrix.makePerspective(qi,Mt,D,y,oi,N),q.projectionMatrixInverse.copy(q.projectionMatrix).invert()}}function ie(q,ae){ae===null?q.matrixWorld.copy(q.matrix):q.matrixWorld.multiplyMatrices(ae.matrixWorld,q.matrix),q.matrixWorldInverse.copy(q.matrixWorld).invert()}this.updateCamera=function(q){if(n===null)return;let ae=q.near,ne=q.far;m.texture!==null&&(m.depthNear>0&&(ae=m.depthNear),m.depthFar>0&&(ne=m.depthFar)),P.near=C.near=A.near=ae,P.far=C.far=A.far=ne,(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,Te=P.cameras;ie(P,z);for(let Ne=0;Ne<Te.length;Ne++)ie(Te[Ne],z);Te.length===2?J(P,A,C):P.projectionMatrix.copy(A.projectionMatrix),re(q,P,z)};function re(q,ae,ne){ne===null?q.matrix.copy(ae.matrixWorld):(q.matrix.copy(ne.matrixWorld),q.matrix.invert(),q.matrix.multiply(ae.matrixWorld)),q.matrix.decompose(q.position,q.quaternion,q.scale),q.updateMatrixWorld(!0),q.projectionMatrix.copy(ae.projectionMatrix),q.projectionMatrixInverse.copy(ae.projectionMatrixInverse),q.isPerspectiveCamera&&(q.fov=zr*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 Ve=null;function Je(q,ae){if(h=ae.getViewerPose(l||a),p=ae,h!==null){const ne=h.views;f!==null&&(e.setRenderTargetFramebuffer(M,f.framebuffer),e.setRenderTarget(M));let z=!1;ne.length!==P.cameras.length&&(P.cameras.length=0,z=!0);for(let be=0;be<ne.length;be++){const ke=ne[be];let ze=null;if(f!==null)ze=f.getViewport(ke);else{const gt=u.getViewSubImage(d,ke);ze=gt.viewport,be===0&&(e.setRenderTargetTextures(M,gt.colorTexture,gt.depthStencilTexture),e.setRenderTarget(M))}let Be=I[be];Be===void 0&&(Be=new Ji,Be.layers.enable(be),Be.viewport=new it,I[be]=Be),Be.matrix.fromArray(ke.transform.matrix),Be.matrix.decompose(Be.position,Be.quaternion,Be.scale),Be.projectionMatrix.fromArray(ke.projectionMatrix),Be.projectionMatrixInverse.copy(Be.projectionMatrix).invert(),Be.viewport.set(ze.x,ze.y,ze.width,ze.height),be===0&&(P.matrix.copy(Be.matrix),P.matrix.decompose(P.position,P.quaternion,P.scale)),z===!0&&P.cameras.push(Be)}const Te=n.enabledFeatures;if(Te&&Te.includes("depth-sensing")&&n.depthUsage=="gpu-optimized"&&v){u=i.getBinding();const be=u.getDepthInformation(ne[0]);be&&be.isValid&&be.texture&&m.init(be,n.renderState)}if(Te&&Te.includes("camera-access")&&v){e.state.unbindTexture(),u=i.getBinding();for(let be=0;be<ne.length;be++){const ke=ne[be].camera;if(ke){let ze=g[ke];ze||(ze=new l1,g[ke]=ze);const Be=u.getCameraImage(ke);ze.sourceTexture=Be}}}}for(let ne=0;ne<S.length;ne++){const z=w[ne],Te=S[ne];z!==null&&Te!==void 0&&Te.update(z,ae,l||a)}Ve&&Ve(q,ae),ae.detectedPlanes&&i.dispatchEvent({type:"planesdetected",data:ae}),p=null}const qe=new M1;qe.setAnimationLoop(Je),this.setAnimationLoop=function(q){Ve=q},this.dispose=function(){}}}const GS=new Ze,w1=new Ye;w1.set(-1,0,0,0,1,0,0,0,1);function VS(r,e){function t(m,g){m.matrixAutoUpdate===!0&&m.updateMatrix(),g.value.copy(m.matrix)}function i(m,g){g.color.getRGB(m.fogColor.value,h1(r)),g.isFog?(m.fogNear.value=g.near,m.fogFar.value=g.far):g.isFogExp2&&(m.fogDensity.value=g.density)}function n(m,g,_,b,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?(a(m,g),g.isLineDashedMaterial&&o(m,g)):g.isPointsMaterial?c(m,g,_,b):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,t(g.map,m.mapTransform)),g.alphaMap&&(m.alphaMap.value=g.alphaMap,t(g.alphaMap,m.alphaMapTransform)),g.bumpMap&&(m.bumpMap.value=g.bumpMap,t(g.bumpMap,m.bumpMapTransform),m.bumpScale.value=g.bumpScale,g.side===Ht&&(m.bumpScale.value*=-1)),g.normalMap&&(m.normalMap.value=g.normalMap,t(g.normalMap,m.normalMapTransform),m.normalScale.value.copy(g.normalScale),g.side===Ht&&m.normalScale.value.negate()),g.displacementMap&&(m.displacementMap.value=g.displacementMap,t(g.displacementMap,m.displacementMapTransform),m.displacementScale.value=g.displacementScale,m.displacementBias.value=g.displacementBias),g.emissiveMap&&(m.emissiveMap.value=g.emissiveMap,t(g.emissiveMap,m.emissiveMapTransform)),g.specularMap&&(m.specularMap.value=g.specularMap,t(g.specularMap,m.specularMapTransform)),g.alphaTest>0&&(m.alphaTest.value=g.alphaTest);const _=e.get(g),b=_.envMap,M=_.envMapRotation;b&&(m.envMap.value=b,m.envMapRotation.value.setFromMatrix4(GS.makeRotationFromEuler(M)).transpose(),b.isCubeTexture&&b.isRenderTargetTexture===!1&&m.envMapRotation.value.premultiply(w1),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,t(g.lightMap,m.lightMapTransform)),g.aoMap&&(m.aoMap.value=g.aoMap,m.aoMapIntensity.value=g.aoMapIntensity,t(g.aoMap,m.aoMapTransform))}function a(m,g){m.diffuse.value.copy(g.color),m.opacity.value=g.opacity,g.map&&(m.map.value=g.map,t(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,_,b){m.diffuse.value.copy(g.color),m.opacity.value=g.opacity,m.size.value=g.size*_,m.scale.value=b*.5,g.map&&(m.map.value=g.map,t(g.map,m.uvTransform)),g.alphaMap&&(m.alphaMap.value=g.alphaMap,t(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,t(g.map,m.mapTransform)),g.alphaMap&&(m.alphaMap.value=g.alphaMap,t(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,t(g.metalnessMap,m.metalnessMapTransform)),m.roughness.value=g.roughness,g.roughnessMap&&(m.roughnessMap.value=g.roughnessMap,t(g.roughnessMap,m.roughnessMapTransform)),g.envMap&&(m.envMapIntensity.value=g.envMapIntensity)}function f(m,g,_){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,t(g.sheenColorMap,m.sheenColorMapTransform)),g.sheenRoughnessMap&&(m.sheenRoughnessMap.value=g.sheenRoughnessMap,t(g.sheenRoughnessMap,m.sheenRoughnessMapTransform))),g.clearcoat>0&&(m.clearcoat.value=g.clearcoat,m.clearcoatRoughness.value=g.clearcoatRoughness,g.clearcoatMap&&(m.clearcoatMap.value=g.clearcoatMap,t(g.clearcoatMap,m.clearcoatMapTransform)),g.clearcoatRoughnessMap&&(m.clearcoatRoughnessMap.value=g.clearcoatRoughnessMap,t(g.clearcoatRoughnessMap,m.clearcoatRoughnessMapTransform)),g.clearcoatNormalMap&&(m.clearcoatNormalMap.value=g.clearcoatNormalMap,t(g.clearcoatNormalMap,m.clearcoatNormalMapTransform),m.clearcoatNormalScale.value.copy(g.clearcoatNormalScale),g.side===Ht&&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,t(g.iridescenceMap,m.iridescenceMapTransform)),g.iridescenceThicknessMap&&(m.iridescenceThicknessMap.value=g.iridescenceThicknessMap,t(g.iridescenceThicknessMap,m.iridescenceThicknessMapTransform))),g.transmission>0&&(m.transmission.value=g.transmission,m.transmissionSamplerMap.value=_.texture,m.transmissionSamplerSize.value.set(_.width,_.height),g.transmissionMap&&(m.transmissionMap.value=g.transmissionMap,t(g.transmissionMap,m.transmissionMapTransform)),m.thickness.value=g.thickness,g.thicknessMap&&(m.thicknessMap.value=g.thicknessMap,t(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,t(g.anisotropyMap,m.anisotropyMapTransform))),m.specularIntensity.value=g.specularIntensity,m.specularColor.value.copy(g.specularColor),g.specularColorMap&&(m.specularColorMap.value=g.specularColorMap,t(g.specularColorMap,m.specularColorMapTransform)),g.specularIntensityMap&&(m.specularIntensityMap.value=g.specularIntensityMap,t(g.specularIntensityMap,m.specularIntensityMapTransform))}function p(m,g){g.matcap&&(m.matcap.value=g.matcap)}function v(m,g){const _=e.get(g).light;m.referencePosition.value.setFromMatrixPosition(_.matrixWorld),m.nearDistance.value=_.shadow.camera.near,m.farDistance.value=_.shadow.camera.far}return{refreshFogUniforms:i,refreshMaterialUniforms:n}}function WS(r,e,t,i){let n={},s={},a=[];const o=r.getParameter(r.MAX_UNIFORM_BUFFER_BINDINGS);function c(M,S){const w=S.program;i.uniformBlockBinding(M,w)}function l(M,S){let w=n[M.id];w===void 0&&(m(M),w=h(M),n[M.id]=w,M.addEventListener("dispose",_));const T=S.program;i.updateUBOMapping(M,T);const x=e.render.frame;s[M.id]!==x&&(d(M),s[M.id]=x)}function h(M){const S=u();M.__bindingPointIndex=S;const w=r.createBuffer(),T=M.__size,x=M.usage;return r.bindBuffer(r.UNIFORM_BUFFER,w),r.bufferData(r.UNIFORM_BUFFER,T,x),r.bindBuffer(r.UNIFORM_BUFFER,null),r.bindBufferBase(r.UNIFORM_BUFFER,S,w),w}function u(){for(let M=0;M<o;M++)if(a.indexOf(M)===-1)return a.push(M),M;return Ge("WebGLRenderer: Maximum number of simultaneously usable uniforms groups reached."),0}function d(M){const S=n[M.id],w=M.uniforms,T=M.__cache;r.bindBuffer(r.UNIFORM_BUFFER,S);for(let x=0,A=w.length;x<A;x++){const C=w[x];if(Array.isArray(C))for(let I=0,P=C.length;I<P;I++)f(C[I],x,I,T);else f(C,x,0,T)}r.bindBuffer(r.UNIFORM_BUFFER,null)}function f(M,S,w,T){if(v(M,S,w,T)===!0){const x=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);r.bufferSubData(r.UNIFORM_BUFFER,x,M.__data)}}function p(M,S,w){typeof M=="number"||typeof M=="boolean"?S[0]=M:M.isMatrix3?(S[0]=M.elements[0],S[1]=M.elements[1],S[2]=M.elements[2],S[3]=0,S[4]=M.elements[3],S[5]=M.elements[4],S[6]=M.elements[5],S[7]=0,S[8]=M.elements[6],S[9]=M.elements[7],S[10]=M.elements[8],S[11]=0):ArrayBuffer.isView(M)?S.set(new M.constructor(M.buffer,M.byteOffset,S.length)):M.toArray(S,w)}function v(M,S,w,T){const x=M.value,A=S+"_"+w;if(T[A]===void 0)return typeof x=="number"||typeof x=="boolean"?T[A]=x:ArrayBuffer.isView(x)?T[A]=x.slice():T[A]=x.clone(),!0;{const C=T[A];if(typeof x=="number"||typeof x=="boolean"){if(C!==x)return T[A]=x,!0}else{if(ArrayBuffer.isView(x))return!0;if(C.equals(x)===!1)return C.copy(x),!0}}return!1}function m(M){const S=M.uniforms;let w=0;const T=16;for(let A=0,C=S.length;A<C;A++){const I=Array.isArray(S[A])?S[A]:[S[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],ee=g($),J=w%T,ie=J%ee.boundary,re=J+ie;w+=ie,re!==0&&T-re<ee.storage&&(w+=T-re),X.__data=new Float32Array(ee.storage/Float32Array.BYTES_PER_ELEMENT),X.__offset=w,w+=ee.storage}}}const x=w%T;return x>0&&(w+=T-x),M.__size=w,M.__cache={},this}function g(M){const S={boundary:0,storage:0};return typeof M=="number"||typeof M=="boolean"?(S.boundary=4,S.storage=4):M.isVector2?(S.boundary=8,S.storage=8):M.isVector3||M.isColor?(S.boundary=16,S.storage=12):M.isVector4?(S.boundary=16,S.storage=16):M.isMatrix3?(S.boundary=48,S.storage=48):M.isMatrix4?(S.boundary=64,S.storage=64):M.isTexture?Re("WebGLRenderer: Texture samplers can not be part of an uniforms group."):ArrayBuffer.isView(M)?(S.boundary=16,S.storage=M.byteLength):Re("WebGLRenderer: Unsupported uniform value type.",M),S}function _(M){const S=M.target;S.removeEventListener("dispose",_);const w=a.indexOf(S.__bindingPointIndex);a.splice(w,1),r.deleteBuffer(n[S.id]),delete n[S.id],delete s[S.id]}function b(){for(const M in n)r.deleteBuffer(n[M]);a=[],n={},s={}}return{bind:c,update:l,dispose:b}}const XS=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 Yn=null;function YS(){return Yn===null&&(Yn=new ca(XS,16,16,ka,Wt),Yn.name="DFG_LUT",Yn.minFilter=rt,Yn.magFilter=rt,Yn.wrapS=wi,Yn.wrapT=wi,Yn.generateMipmaps=!1,Yn.needsUpdate=!0),Yn}class qS{constructor(e={}){const{canvas:t=yM(),context:i=null,depth:n=!0,stencil:s=!1,alpha:a=!1,antialias:o=!1,premultipliedAlpha:c=!0,preserveDrawingBuffer:l=!1,powerPreference:h="default",failIfMajorPerformanceCaveat:u=!1,reversedDepthBuffer:d=!1,outputBufferType:f=dn}=e;this.isWebGLRenderer=!0;let p;if(i!==null){if(typeof WebGLRenderingContext<"u"&&i instanceof WebGLRenderingContext)throw new Error("THREE.WebGLRenderer: WebGL 1 is not supported since r163.");p=i.getContextAttributes().alpha}else p=a;const v=f,m=new Set([v0,g0,m0]),g=new Set([dn,_n,Vo,Wo,f0,p0]),_=new Uint32Array(4),b=new Int32Array(4),M=new R;let S=null,w=null;const T=[],x=[];let A=null;this.domElement=t,this.debug={checkShaderErrors:!0,onShaderError:null},this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.sortObjects=!0,this.clippingPlanes=[],this.localClippingEnabled=!1,this.toneMapping=rs,this.toneMappingExposure=1,this.transmissionResolutionScale=1;const C=this;let I=!1,P=null,V=null,X=null,L=null;this._outputColorSpace=Vi;let B=0,k=0,$=null,ee=-1,J=null;const ie=new it,re=new it;let Ve=null;const Je=new se(0);let qe=0,q=t.width,ae=t.height,ne=1,z=null,Te=null;const Ne=new it(0,0,q,ae),Ce=new it(0,0,q,ae);let be=!1;const ke=new A0;let ze=!1,Be=!1;const gt=new Ze,vt=new R,Yt=new it,kt={background:null,fog:null,environment:null,overrideMaterial:null,isScene:!0};let qt=!1;function oi(){return $===null?ne:1}let N=i;function qi(E,F){return t.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 t&&t.setAttribute("data-engine",`three.js r${h0}`),t.addEventListener("webglcontextlost",$t,!1),t.addEventListener("webglcontextrestored",It,!1),t.addEventListener("webglcontextcreationerror",Hn,!1),N===null){const F="webgl2";if(N=qi(F,E),N===null)throw qi(F)?new Error("THREE.WebGLRenderer: Error creating WebGL context with your selected attributes."):new Error("THREE.WebGLRenderer: Error creating WebGL context.")}}catch(E){throw Ge("WebGLRenderer: "+E.message),E}let Mt,D,y,U,W,K,oe,le,Z,Q,he,Pe,fe,ue,Ue,He,$e,O,ce,j,de,ve,te;function Ie(){Mt=new Y_(N),Mt.init(),de=new US(N,Mt),D=new k_(N,Mt,e,de),y=new NS(N,Mt),D.reversedDepthBuffer&&d&&y.buffers.depth.setReversed(!0),V=N.createFramebuffer(),X=N.createFramebuffer(),L=N.createFramebuffer(),U=new K_(N),W=new bS,K=new FS(N,Mt,y,W,D,de,U),oe=new X_(C),le=new Qx(N),ve=new F_(N,le),Z=new q_(N,le,U,ve),Q=new J_(N,Z,le,ve,U),O=new Z_(N,D,K),Ue=new z_(W),he=new yS(C,oe,Mt,D,ve,Ue),Pe=new VS(C,W),fe=new SS,ue=new DS(Mt),$e=new N_(C,oe,y,Q,p,c),He=new OS(C,Q,D),te=new WS(N,U,D,y),ce=new U_(N,Mt,U),j=new $_(N,Mt,U),U.programs=he.programs,C.capabilities=D,C.extensions=Mt,C.properties=W,C.renderLists=fe,C.shadowMap=He,C.state=y,C.info=U}Ie(),v!==dn&&(A=new Q_(v,t.width,t.height,o,n,s));const Se=new HS(C,N);this.xr=Se,this.getContext=function(){return N},this.getContextAttributes=function(){return N.getContextAttributes()},this.forceContextLoss=function(){const E=Mt.get("WEBGL_lose_context");E&&E.loseContext()},this.forceContextRestore=function(){const E=Mt.get("WEBGL_lose_context");E&&E.restoreContext()},this.getPixelRatio=function(){return ne},this.setPixelRatio=function(E){E!==void 0&&(ne=E,this.setSize(q,ae,!1))},this.getSize=function(E){return E.set(q,ae)},this.setSize=function(E,F,Y=!0){if(Se.isPresenting){Re("WebGLRenderer: Can't change size while VR device is presenting.");return}q=E,ae=F,t.width=Math.floor(E*ne),t.height=Math.floor(F*ne),Y===!0&&(t.style.width=E+"px",t.style.height=F+"px"),A!==null&&A.setSize(t.width,t.height),this.setViewport(0,0,E,F)},this.getDrawingBufferSize=function(E){return E.set(q*ne,ae*ne).floor()},this.setDrawingBufferSize=function(E,F,Y){q=E,ae=F,ne=Y,t.width=Math.floor(E*Y),t.height=Math.floor(F*Y),this.setViewport(0,0,E,F)},this.setEffects=function(E){if(v===dn){Ge("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){Re("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(ie)},this.getViewport=function(E){return E.copy(Ne)},this.setViewport=function(E,F,Y,H){E.isVector4?Ne.set(E.x,E.y,E.z,E.w):Ne.set(E,F,Y,H),y.viewport(ie.copy(Ne).multiplyScalar(ne).round())},this.getScissor=function(E){return E.copy(Ce)},this.setScissor=function(E,F,Y,H){E.isVector4?Ce.set(E.x,E.y,E.z,E.w):Ce.set(E,F,Y,H),y.scissor(re.copy(Ce).multiplyScalar(ne).round())},this.getScissorTest=function(){return be},this.setScissorTest=function(E){y.setScissorTest(be=E)},this.setOpaqueSort=function(E){z=E},this.setTransparentSort=function(E){Te=E},this.getClearColor=function(E){return E.copy($e.getClearColor())},this.setClearColor=function(){$e.setClearColor(...arguments)},this.getClearAlpha=function(){return $e.getClearAlpha()},this.setClearAlpha=function(){$e.setClearAlpha(...arguments)},this.clear=function(E=!0,F=!0,Y=!0){let H=0;if(E){let G=!1;if($!==null){const ge=$.texture.format;G=m.has(ge)}if(G){const ge=$.texture.type,_e=g.has(ge),me=$e.getClearColor(),Ee=$e.getClearAlpha(),Le=me.r,Ke=me.g,je=me.b;_e?(_[0]=Le,_[1]=Ke,_[2]=je,_[3]=Ee,N.clearBufferuiv(N.COLOR,0,_)):(b[0]=Le,b[1]=Ke,b[2]=je,b[3]=Ee,N.clearBufferiv(N.COLOR,0,b))}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(){t.removeEventListener("webglcontextlost",$t,!1),t.removeEventListener("webglcontextrestored",It,!1),t.removeEventListener("webglcontextcreationerror",Hn,!1),$e.dispose(),fe.dispose(),ue.dispose(),W.dispose(),oe.dispose(),Q.dispose(),ve.dispose(),te.dispose(),he.dispose(),Se.dispose(),Se.removeEventListener("sessionstart",j0),Se.removeEventListener("sessionend",Q0),la.stop()};function $t(E){E.preventDefault(),Rl("WebGLRenderer: Context Lost."),I=!0}function It(){Rl("WebGLRenderer: Context Restored."),I=!1;const E=U.autoReset,F=He.enabled,Y=He.autoUpdate,H=He.needsUpdate,G=He.type;Ie(),U.autoReset=E,He.enabled=F,He.autoUpdate=Y,He.needsUpdate=H,He.type=G}function Hn(E){Ge("WebGLRenderer: A WebGL context could not be created. Reason: ",E.statusMessage)}function Gn(E){const F=E.target;F.removeEventListener("dispose",Gn),dv(F)}function dv(E){fv(E),W.remove(E)}function fv(E){const F=W.get(E).programs;F!==void 0&&(F.forEach(function(Y){he.releaseProgram(Y)}),E.isShaderMaterial&&he.releaseShaderCache(E))}this.renderBufferDirect=function(E,F,Y,H,G,ge){F===null&&(F=kt);const _e=G.isMesh&&G.matrixWorld.determinantAffine()<0,me=gv(E,F,Y,H,G);y.setMaterial(H,_e);let Ee=Y.index,Le=1;if(H.wireframe===!0){if(Ee=Z.getWireframeAttribute(Y),Ee===void 0)return;Le=2}const Ke=Y.drawRange,je=Y.attributes.position;let Oe=Ke.start*Le,wt=(Ke.start+Ke.count)*Le;ge!==null&&(Oe=Math.max(Oe,ge.start*Le),wt=Math.min(wt,(ge.start+ge.count)*Le)),Ee!==null?(Oe=Math.max(Oe,0),wt=Math.min(wt,Ee.count)):je!=null&&(Oe=Math.max(Oe,0),wt=Math.min(wt,je.count));const Qt=wt-Oe;if(Qt<0||Qt===1/0)return;ve.setup(G,H,me,Y,Ee);let Kt,Tt=ce;if(Ee!==null&&(Kt=le.get(Ee),Tt=j,Tt.setIndex(Kt)),G.isMesh)H.wireframe===!0?(y.setLineWidth(H.wireframeLinewidth*oi()),Tt.setMode(N.LINES)):Tt.setMode(N.TRIANGLES);else if(G.isLine){let Ti=H.linewidth;Ti===void 0&&(Ti=1),y.setLineWidth(Ti*oi()),G.isLineSegments?Tt.setMode(N.LINES):G.isLineLoop?Tt.setMode(N.LINE_LOOP):Tt.setMode(N.LINE_STRIP)}else G.isPoints?Tt.setMode(N.POINTS):G.isSprite&&Tt.setMode(N.TRIANGLES);if(G.isBatchedMesh)if(Mt.get("WEBGL_multi_draw"))Tt.renderMultiDraw(G._multiDrawStarts,G._multiDrawCounts,G._multiDrawCount);else{const Ti=G._multiDrawStarts,ye=G._multiDrawCounts,tn=G._multiDrawCount,lt=Ee?le.get(Ee).bytesPerElement:1,fn=W.get(H).currentProgram.getUniforms();for(let Vn=0;Vn<tn;Vn++)fn.setValue(N,"_gl_DrawID",Vn),Tt.render(Ti[Vn]/lt,ye[Vn])}else if(G.isInstancedMesh)Tt.renderInstances(Oe,Qt,G.count);else if(Y.isInstancedBufferGeometry){const Ti=Y._maxInstanceCount!==void 0?Y._maxInstanceCount:1/0,ye=Math.min(Y.instanceCount,Ti);Tt.renderInstances(Oe,Qt,ye)}else Tt.render(Oe,Qt)};function J0(E,F,Y){E.transparent===!0&&E.side===Qi&&E.forceSinglePass===!1?(E.side=Ht,E.needsUpdate=!0,tc(E,F,Y),E.side=sa,E.needsUpdate=!0,tc(E,F,Y),E.side=Qi):tc(E,F,Y)}this.compile=function(E,F,Y=null){Y===null&&(Y=E),w=ue.get(Y),w.init(F),x.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 ge=G.material;if(ge)if(Array.isArray(ge))for(let _e=0;_e<ge.length;_e++){const me=ge[_e];J0(me,Y,G),H.add(me)}else J0(ge,Y,G),H.add(ge)}),w=x.pop(),H},this.compileAsync=function(E,F,Y=null){const H=this.compile(E,F,Y);return new Promise(G=>{function ge(){if(H.forEach(function(_e){W.get(_e).currentProgram.isReady()&&H.delete(_e)}),H.size===0){G(E);return}setTimeout(ge,10)}Mt.get("KHR_parallel_shader_compile")!==null?ge():setTimeout(ge,10)})};let rh=null;function pv(E){rh&&rh(E)}function j0(){la.stop()}function Q0(){la.start()}const la=new M1;la.setAnimationLoop(pv),typeof self<"u"&&la.setContext(self),this.setAnimationLoop=function(E){rh=E,Se.setAnimationLoop(E),E===null?la.stop():la.start()},Se.addEventListener("sessionstart",j0),Se.addEventListener("sessionend",Q0),this.render=function(E,F){if(F!==void 0&&F.isCamera!==!0){Ge("WebGLRenderer.render: camera is not an instance of THREE.Camera.");return}if(I===!0)return;P!==null&&P.renderStart(E,F);const Y=Se.enabled===!0&&Se.isPresenting===!0,H=A!==null&&($===null||Y)&&A.begin(C,$);if(E.matrixWorldAutoUpdate===!0&&E.updateMatrixWorld(),F.parent===null&&F.matrixWorldAutoUpdate===!0&&F.updateMatrixWorld(),Se.enabled===!0&&Se.isPresenting===!0&&(A===null||A.isCompositing()===!1)&&(Se.cameraAutoUpdate===!0&&Se.updateCamera(F),F=Se.getCamera()),E.isScene===!0&&E.onBeforeRender(C,E,F,$),w=ue.get(E,x.length),w.init(F),w.state.textureUnits=K.getTextureUnits(),x.push(w),gt.multiplyMatrices(F.projectionMatrix,F.matrixWorldInverse),ke.setFromProjectionMatrix(gt,ns,F.reversedDepth),Be=this.localClippingEnabled,ze=Ue.init(this.clippingPlanes,Be),S=fe.get(E,T.length),S.init(),T.push(S),Se.enabled===!0&&Se.isPresenting===!0){const _e=C.xr.getDepthSensingMesh();_e!==null&&oh(_e,F,-1/0,C.sortObjects)}oh(E,F,0,C.sortObjects),S.finish(),C.sortObjects===!0&&S.sort(z,Te,F.reversedDepth),qt=Se.enabled===!1||Se.isPresenting===!1||Se.hasDepthSensing()===!1,qt&&$e.addToRenderList(S,E),this.info.render.frame++,this.info.autoReset===!0&&this.info.reset(),ze===!0&&Ue.beginShadows();const G=w.state.shadowsArray;if(He.render(G,E,F),ze===!0&&Ue.endShadows(),(H&&A.hasRenderPass())===!1){const _e=S.opaque,me=S.transmissive;if(w.setupLights(),F.isArrayCamera){const Ee=F.cameras;if(me.length>0)for(let Le=0,Ke=Ee.length;Le<Ke;Le++){const je=Ee[Le];tf(_e,me,E,je)}qt&&$e.render(E);for(let Le=0,Ke=Ee.length;Le<Ke;Le++){const je=Ee[Le];ef(S,E,je,je.viewport)}}else me.length>0&&tf(_e,me,E,F),qt&&$e.render(E),ef(S,E,F)}$!==null&&k===0&&(K.updateMultisampleRenderTarget($),K.updateRenderTargetMipmap($)),H&&A.end(C),E.isScene===!0&&E.onAfterRender(C,E,F),ve.resetDefaultState(),ee=-1,J=null,x.pop(),x.length>0?(w=x[x.length-1],K.setTextureUnits(w.state.textureUnits),ze===!0&&Ue.setGlobalState(C.clippingPlanes,w.state.camera)):w=null,T.pop(),T.length>0?S=T[T.length-1]:S=null,P!==null&&P.renderEnd()};function oh(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||ke.intersectsSprite(E)){H&&Yt.setFromMatrixPosition(E.matrixWorld).applyMatrix4(gt);const _e=Q.update(E),me=E.material;me.visible&&S.push(E,_e,me,Y,Yt.z,null)}}else if((E.isMesh||E.isLine||E.isPoints)&&(!E.frustumCulled||ke.intersectsObject(E))){const _e=Q.update(E),me=E.material;if(H&&(E.boundingSphere!==void 0?(E.boundingSphere===null&&E.computeBoundingSphere(),Yt.copy(E.boundingSphere.center)):(_e.boundingSphere===null&&_e.computeBoundingSphere(),Yt.copy(_e.boundingSphere.center)),Yt.applyMatrix4(E.matrixWorld).applyMatrix4(gt)),Array.isArray(me)){const Ee=_e.groups;for(let Le=0,Ke=Ee.length;Le<Ke;Le++){const je=Ee[Le],Oe=me[je.materialIndex];Oe&&Oe.visible&&S.push(E,_e,Oe,Y,Yt.z,je)}}else me.visible&&S.push(E,_e,me,Y,Yt.z,null)}}const ge=E.children;for(let _e=0,me=ge.length;_e<me;_e++)oh(ge[_e],F,Y,H)}function ef(E,F,Y,H){const{opaque:G,transmissive:ge,transparent:_e}=E;w.setupLightsView(Y),ze===!0&&Ue.setGlobalState(C.clippingPlanes,Y),H&&y.viewport(ie.copy(H)),G.length>0&&ec(G,F,Y),ge.length>0&&ec(ge,F,Y),_e.length>0&&ec(_e,F,Y),y.buffers.depth.setTest(!0),y.buffers.depth.setMask(!0),y.buffers.color.setMask(!0),y.setPolygonOffset(!1)}function tf(E,F,Y,H){if((Y.isScene===!0?Y.overrideMaterial:null)!==null)return;if(w.state.transmissionRenderTarget[H.id]===void 0){const Oe=Mt.has("EXT_color_buffer_half_float")||Mt.has("EXT_color_buffer_float");w.state.transmissionRenderTarget[H.id]=new ai(1,1,{generateMipmaps:!0,type:Oe?Wt:dn,minFilter:Ta,samples:Math.max(4,D.samples),stencilBuffer:s,resolveDepthBuffer:!1,resolveStencilBuffer:!1,colorSpace:at.workingColorSpace})}const ge=w.state.transmissionRenderTarget[H.id],_e=H.viewport||ie;ge.setSize(_e.z*C.transmissionResolutionScale,_e.w*C.transmissionResolutionScale);const me=C.getRenderTarget(),Ee=C.getActiveCubeFace(),Le=C.getActiveMipmapLevel();C.setRenderTarget(ge),C.getClearColor(Je),qe=C.getClearAlpha(),qe<1&&C.setClearColor(16777215,.5),C.clear(),qt&&$e.render(Y);const Ke=C.toneMapping;C.toneMapping=rs;const je=H.viewport;if(H.viewport!==void 0&&(H.viewport=void 0),w.setupLightsView(H),ze===!0&&Ue.setGlobalState(C.clippingPlanes,H),ec(E,Y,H),K.updateMultisampleRenderTarget(ge),K.updateRenderTargetMipmap(ge),Mt.has("WEBGL_multisampled_render_to_texture")===!1){let Oe=!1;for(let wt=0,Qt=F.length;wt<Qt;wt++){const Kt=F[wt],{object:Tt,geometry:Ti,material:ye,group:tn}=Kt;if(ye.side===Qi&&Tt.layers.test(H.layers)){const lt=ye.side;ye.side=Ht,ye.needsUpdate=!0,nf(Tt,Y,H,Ti,ye,tn),ye.side=lt,ye.needsUpdate=!0,Oe=!0}}Oe===!0&&(K.updateMultisampleRenderTarget(ge),K.updateRenderTargetMipmap(ge))}C.setRenderTarget(me,Ee,Le),C.setClearColor(Je,qe),je!==void 0&&(H.viewport=je),C.toneMapping=Ke}function ec(E,F,Y){const H=F.isScene===!0?F.overrideMaterial:null;for(let G=0,ge=E.length;G<ge;G++){const _e=E[G],{object:me,geometry:Ee,group:Le}=_e;let Ke=_e.material;Ke.allowOverride===!0&&H!==null&&(Ke=H),me.layers.test(Y.layers)&&nf(me,F,Y,Ee,Ke,Le)}}function nf(E,F,Y,H,G,ge){E.onBeforeRender(C,F,Y,H,G,ge),E.modelViewMatrix.multiplyMatrices(Y.matrixWorldInverse,E.matrixWorld),E.normalMatrix.getNormalMatrix(E.modelViewMatrix),G.onBeforeRender(C,F,Y,H,E,ge),G.transparent===!0&&G.side===Qi&&G.forceSinglePass===!1?(G.side=Ht,G.needsUpdate=!0,C.renderBufferDirect(Y,F,H,G,E,ge),G.side=sa,G.needsUpdate=!0,C.renderBufferDirect(Y,F,H,G,E,ge),G.side=Qi):C.renderBufferDirect(Y,F,H,G,E,ge),E.onAfterRender(C,F,Y,H,G,ge)}function tc(E,F,Y){F.isScene!==!0&&(F=kt);const H=W.get(E),G=w.state.lights,ge=w.state.shadowsArray,_e=G.state.version,me=he.getParameters(E,G.state,ge,F,Y,w.state.lightProbeGridArray),Ee=he.getProgramCacheKey(me);let Le=H.programs;H.environment=E.isMeshStandardMaterial||E.isMeshLambertMaterial||E.isMeshPhongMaterial?F.environment:null,H.fog=F.fog;const Ke=E.isMeshStandardMaterial||E.isMeshLambertMaterial&&!E.envMap||E.isMeshPhongMaterial&&!E.envMap;H.envMap=oe.get(E.envMap||H.environment,Ke),H.envMapRotation=H.environment!==null&&E.envMap===null?F.environmentRotation:E.envMapRotation,Le===void 0&&(E.addEventListener("dispose",Gn),Le=new Map,H.programs=Le);let je=Le.get(Ee);if(je!==void 0){if(H.currentProgram===je&&H.lightsStateVersion===_e)return af(E,me),je}else me.uniforms=he.getUniforms(E),P!==null&&E.isNodeMaterial&&P.build(E,Y,me),E.onBeforeCompile(me,C),je=he.acquireProgram(me,Ee),Le.set(Ee,je),H.uniforms=me.uniforms;const Oe=H.uniforms;return(!E.isShaderMaterial&&!E.isRawShaderMaterial||E.clipping===!0)&&(Oe.clippingPlanes=Ue.uniform),af(E,me),H.needsLights=Mv(E),H.lightsStateVersion=_e,H.needsLights&&(Oe.ambientLightColor.value=G.state.ambient,Oe.lightProbe.value=G.state.probe,Oe.directionalLights.value=G.state.directional,Oe.directionalLightShadows.value=G.state.directionalShadow,Oe.spotLights.value=G.state.spot,Oe.spotLightShadows.value=G.state.spotShadow,Oe.rectAreaLights.value=G.state.rectArea,Oe.ltc_1.value=G.state.rectAreaLTC1,Oe.ltc_2.value=G.state.rectAreaLTC2,Oe.pointLights.value=G.state.point,Oe.pointLightShadows.value=G.state.pointShadow,Oe.hemisphereLights.value=G.state.hemi,Oe.directionalShadowMatrix.value=G.state.directionalShadowMatrix,Oe.spotLightMatrix.value=G.state.spotLightMatrix,Oe.spotLightMap.value=G.state.spotLightMap,Oe.pointShadowMatrix.value=G.state.pointShadowMatrix),H.lightProbeGrid=w.state.lightProbeGridArray.length>0,H.currentProgram=je,H.uniformsList=null,je}function sf(E){if(E.uniformsList===null){const F=E.currentProgram.getUniforms();E.uniformsList=fl.seqWithValue(F.seq,E.uniforms)}return E.uniformsList}function af(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 mv(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 gv(E,F,Y,H,G){F.isScene!==!0&&(F=kt),K.resetTextureUnits();const ge=F.fog,_e=H.isMeshStandardMaterial||H.isMeshLambertMaterial||H.isMeshPhongMaterial?F.environment:null,me=$===null?C.outputColorSpace:$.isXRRenderTarget===!0?$.texture.colorSpace:at.workingColorSpace,Ee=H.isMeshStandardMaterial||H.isMeshLambertMaterial&&!H.envMap||H.isMeshPhongMaterial&&!H.envMap,Le=oe.get(H.envMap||_e,Ee),Ke=H.vertexColors===!0&&!!Y.attributes.color&&Y.attributes.color.itemSize===4,je=!!Y.attributes.tangent&&(!!H.normalMap||H.anisotropy>0),Oe=!!Y.morphAttributes.position,wt=!!Y.morphAttributes.normal,Qt=!!Y.morphAttributes.color;let Kt=rs;H.toneMapped&&($===null||$.isXRRenderTarget===!0)&&(Kt=C.toneMapping);const Tt=Y.morphAttributes.position||Y.morphAttributes.normal||Y.morphAttributes.color,Ti=Tt!==void 0?Tt.length:0,ye=W.get(H),tn=w.state.lights;if(ze===!0&&(Be===!0||E!==J)){const Ct=E===J&&H.id===ee;Ue.setState(H,E,Ct)}let lt=!1;H.version===ye.__version?(ye.needsLights&&ye.lightsStateVersion!==tn.state.version||ye.outputColorSpace!==me||G.isBatchedMesh&&ye.batching===!1||!G.isBatchedMesh&&ye.batching===!0||G.isBatchedMesh&&ye.batchingColor===!0&&G.colorTexture===null||G.isBatchedMesh&&ye.batchingColor===!1&&G.colorTexture!==null||G.isInstancedMesh&&ye.instancing===!1||!G.isInstancedMesh&&ye.instancing===!0||G.isSkinnedMesh&&ye.skinning===!1||!G.isSkinnedMesh&&ye.skinning===!0||G.isInstancedMesh&&ye.instancingColor===!0&&G.instanceColor===null||G.isInstancedMesh&&ye.instancingColor===!1&&G.instanceColor!==null||G.isInstancedMesh&&ye.instancingMorph===!0&&G.morphTexture===null||G.isInstancedMesh&&ye.instancingMorph===!1&&G.morphTexture!==null||ye.envMap!==Le||H.fog===!0&&ye.fog!==ge||ye.numClippingPlanes!==void 0&&(ye.numClippingPlanes!==Ue.numPlanes||ye.numIntersection!==Ue.numIntersection)||ye.vertexAlphas!==Ke||ye.vertexTangents!==je||ye.morphTargets!==Oe||ye.morphNormals!==wt||ye.morphColors!==Qt||ye.toneMapping!==Kt||ye.morphTargetsCount!==Ti||!!ye.lightProbeGrid!=w.state.lightProbeGridArray.length>0)&&(lt=!0):(lt=!0,ye.__version=H.version);let fn=ye.currentProgram;lt===!0&&(fn=tc(H,F,G),P&&H.isNodeMaterial&&P.onUpdateProgram(H,fn,ye));let Vn=!1,Os=!1,Ha=!1;const Rt=fn.getUniforms(),ei=ye.uniforms;if(y.useProgram(fn.program)&&(Vn=!0,Os=!0,Ha=!0),H.id!==ee&&(ee=H.id,Os=!0),ye.needsLights){const Ct=mv(w.state.lightProbeGridArray,G);ye.lightProbeGrid!==Ct&&(ye.lightProbeGrid=Ct,Os=!0)}if(Vn||J!==E){y.buffers.depth.getReversed()&&E.reversedDepth!==!0&&(E._reversedDepth=!0,E.updateProjectionMatrix()),Rt.setValue(N,"projectionMatrix",E.projectionMatrix),Rt.setValue(N,"viewMatrix",E.matrixWorldInverse);const Fs=Rt.map.cameraPosition;Fs!==void 0&&Fs.setValue(N,vt.setFromMatrixPosition(E.matrixWorld)),D.logarithmicDepthBuffer&&Rt.setValue(N,"logDepthBufFC",2/(Math.log(E.far+1)/Math.LN2)),(H.isMeshPhongMaterial||H.isMeshToonMaterial||H.isMeshLambertMaterial||H.isMeshBasicMaterial||H.isMeshStandardMaterial||H.isShaderMaterial)&&Rt.setValue(N,"isOrthographic",E.isOrthographicCamera===!0),J!==E&&(J=E,Os=!0,Ha=!0)}if(ye.needsLights&&(tn.state.directionalShadowMap.length>0&&Rt.setValue(N,"directionalShadowMap",tn.state.directionalShadowMap,K),tn.state.spotShadowMap.length>0&&Rt.setValue(N,"spotShadowMap",tn.state.spotShadowMap,K),tn.state.pointShadowMap.length>0&&Rt.setValue(N,"pointShadowMap",tn.state.pointShadowMap,K)),G.isSkinnedMesh){Rt.setOptional(N,G,"bindMatrix"),Rt.setOptional(N,G,"bindMatrixInverse");const Ct=G.skeleton;Ct&&(Ct.boneTexture===null&&Ct.computeBoneTexture(),Rt.setValue(N,"boneTexture",Ct.boneTexture,K))}G.isBatchedMesh&&(Rt.setOptional(N,G,"batchingTexture"),Rt.setValue(N,"batchingTexture",G._matricesTexture,K),Rt.setOptional(N,G,"batchingIdTexture"),Rt.setValue(N,"batchingIdTexture",G._indirectTexture,K),Rt.setOptional(N,G,"batchingColorTexture"),G._colorsTexture!==null&&Rt.setValue(N,"batchingColorTexture",G._colorsTexture,K));const Ns=Y.morphAttributes;if((Ns.position!==void 0||Ns.normal!==void 0||Ns.color!==void 0)&&O.update(G,Y,fn),(Os||ye.receiveShadow!==G.receiveShadow)&&(ye.receiveShadow=G.receiveShadow,Rt.setValue(N,"receiveShadow",G.receiveShadow)),(H.isMeshStandardMaterial||H.isMeshLambertMaterial||H.isMeshPhongMaterial)&&H.envMap===null&&F.environment!==null&&(ei.envMapIntensity.value=F.environmentIntensity),ei.dfgLUT!==void 0&&(ei.dfgLUT.value=YS()),Os){if(Rt.setValue(N,"toneMappingExposure",C.toneMappingExposure),ye.needsLights&&vv(ei,Ha),ge&&H.fog===!0&&Pe.refreshFogUniforms(ei,ge),Pe.refreshMaterialUniforms(ei,H,ne,ae,w.state.transmissionRenderTarget[E.id]),ye.needsLights&&ye.lightProbeGrid){const Ct=ye.lightProbeGrid;ei.probesSH.value=Ct.texture,ei.probesMin.value.copy(Ct.boundingBox.min),ei.probesMax.value.copy(Ct.boundingBox.max),ei.probesResolution.value.copy(Ct.resolution)}fl.upload(N,sf(ye),ei,K)}if(H.isShaderMaterial&&H.uniformsNeedUpdate===!0&&(fl.upload(N,sf(ye),ei,K),H.uniformsNeedUpdate=!1),H.isSpriteMaterial&&Rt.setValue(N,"center",G.center),Rt.setValue(N,"modelViewMatrix",G.modelViewMatrix),Rt.setValue(N,"normalMatrix",G.normalMatrix),Rt.setValue(N,"modelMatrix",G.matrixWorld),H.uniformsGroups!==void 0){const Ct=H.uniformsGroups;for(let Fs=0,Ga=Ct.length;Fs<Ga;Fs++){const rf=Ct[Fs];te.update(rf,fn),te.bind(rf,fn)}}return fn}function vv(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 Mv(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,ge=!1;if(E){const me=W.get(E);if(me.__useDefaultFramebuffer!==void 0){y.bindFramebuffer(N.FRAMEBUFFER,me.__webglFramebuffer),ie.copy(E.viewport),re.copy(E.scissor),Ve=E.scissorTest,y.viewport(ie),y.scissor(re),y.setScissorTest(Ve),ee=-1;return}else if(me.__webglFramebuffer===void 0)K.setupRenderTarget(E);else if(me.__hasExternalTextures)K.rebindTextures(E,W.get(E.texture).__webglTexture,W.get(E.depthTexture).__webglTexture);else if(E.depthBuffer){const Ke=E.depthTexture;if(me.__boundDepthTexture!==Ke){if(Ke!==null&&W.has(Ke)&&(E.width!==Ke.image.width||E.height!==Ke.image.height))throw new Error("THREE.WebGLRenderer: Attached DepthTexture is initialized to the incorrect size.");K.setupDepthRenderbuffer(E)}}const Ee=E.texture;(Ee.isData3DTexture||Ee.isDataArrayTexture||Ee.isCompressedArrayTexture)&&(ge=!0);const Le=W.get(E).__webglFramebuffer;E.isWebGLCubeRenderTarget?(Array.isArray(Le[F])?H=Le[F][Y]:H=Le[F],G=!0):E.samples>0&&K.useMultisampledRTT(E)===!1?H=W.get(E).__webglMultisampledFramebuffer:Array.isArray(Le)?H=Le[Y]:H=Le,ie.copy(E.viewport),re.copy(E.scissor),Ve=E.scissorTest}else ie.copy(Ne).multiplyScalar(ne).floor(),re.copy(Ce).multiplyScalar(ne).floor(),Ve=be;if(Y!==0&&(H=V),y.bindFramebuffer(N.FRAMEBUFFER,H)&&y.drawBuffers(E,H),y.viewport(ie),y.scissor(re),y.setScissorTest(Ve),G){const me=W.get(E.texture);N.framebufferTexture2D(N.FRAMEBUFFER,N.COLOR_ATTACHMENT0,N.TEXTURE_CUBE_MAP_POSITIVE_X+F,me.__webglTexture,Y)}else if(ge){const me=F;for(let Ee=0;Ee<E.textures.length;Ee++){const Le=W.get(E.textures[Ee]);N.framebufferTextureLayer(N.FRAMEBUFFER,N.COLOR_ATTACHMENT0+Ee,Le.__webglTexture,Y,me)}}else if(E!==null&&Y!==0){const me=W.get(E.texture);N.framebufferTexture2D(N.FRAMEBUFFER,N.COLOR_ATTACHMENT0,N.TEXTURE_2D,me.__webglTexture,Y)}ee=-1},this.readRenderTargetPixels=function(E,F,Y,H,G,ge,_e,me=0){if(!(E&&E.isWebGLRenderTarget)){Ge("WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");return}let Ee=W.get(E).__webglFramebuffer;if(E.isWebGLCubeRenderTarget&&_e!==void 0&&(Ee=Ee[_e]),Ee){y.bindFramebuffer(N.FRAMEBUFFER,Ee);try{const Le=E.textures[me],Ke=Le.format,je=Le.type;if(E.textures.length>1&&N.readBuffer(N.COLOR_ATTACHMENT0+me),!D.textureFormatReadable(Ke)){Ge("WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.");return}if(!D.textureTypeReadable(je)){Ge("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,de.convert(Ke),de.convert(je),ge)}finally{const Le=$!==null?W.get($).__webglFramebuffer:null;y.bindFramebuffer(N.FRAMEBUFFER,Le)}}},this.readRenderTargetPixelsAsync=async function(E,F,Y,H,G,ge,_e,me=0){if(!(E&&E.isWebGLRenderTarget))throw new Error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");let Ee=W.get(E).__webglFramebuffer;if(E.isWebGLCubeRenderTarget&&_e!==void 0&&(Ee=Ee[_e]),Ee)if(F>=0&&F<=E.width-H&&Y>=0&&Y<=E.height-G){y.bindFramebuffer(N.FRAMEBUFFER,Ee);const Le=E.textures[me],Ke=Le.format,je=Le.type;if(E.textures.length>1&&N.readBuffer(N.COLOR_ATTACHMENT0+me),!D.textureFormatReadable(Ke))throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.");if(!D.textureTypeReadable(je))throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.");const Oe=N.createBuffer();N.bindBuffer(N.PIXEL_PACK_BUFFER,Oe),N.bufferData(N.PIXEL_PACK_BUFFER,ge.byteLength,N.STREAM_READ),N.readPixels(F,Y,H,G,de.convert(Ke),de.convert(je),0);const wt=$!==null?W.get($).__webglFramebuffer:null;y.bindFramebuffer(N.FRAMEBUFFER,wt);const Qt=N.fenceSync(N.SYNC_GPU_COMMANDS_COMPLETE,0);return N.flush(),await bM(N,Qt,4),N.bindBuffer(N.PIXEL_PACK_BUFFER,Oe),N.getBufferSubData(N.PIXEL_PACK_BUFFER,0,ge),N.deleteBuffer(Oe),N.deleteSync(Qt),ge}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),ge=Math.floor(E.image.height*H),_e=F!==null?F.x:0,me=F!==null?F.y:0;K.setTexture2D(E,0),N.copyTexSubImage2D(N.TEXTURE_2D,Y,0,0,_e,me,G,ge),y.unbindTexture()},this.copyTextureToTexture=function(E,F,Y=null,H=null,G=0,ge=0){let _e,me,Ee,Le,Ke,je,Oe,wt,Qt;const Kt=E.isCompressedTexture?E.mipmaps[ge]:E.image;if(Y!==null)_e=Y.max.x-Y.min.x,me=Y.max.y-Y.min.y,Ee=Y.isBox3?Y.max.z-Y.min.z:1,Le=Y.min.x,Ke=Y.min.y,je=Y.isBox3?Y.min.z:0;else{const ei=Math.pow(2,-G);_e=Math.floor(Kt.width*ei),me=Math.floor(Kt.height*ei),E.isDataArrayTexture?Ee=Kt.depth:E.isData3DTexture?Ee=Math.floor(Kt.depth*ei):Ee=1,Le=0,Ke=0,je=0}H!==null?(Oe=H.x,wt=H.y,Qt=H.z):(Oe=0,wt=0,Qt=0);const Tt=de.convert(F.format),Ti=de.convert(F.type);let ye;F.isData3DTexture?(K.setTexture3D(F,0),ye=N.TEXTURE_3D):F.isDataArrayTexture||F.isCompressedArrayTexture?(K.setTexture2DArray(F,0),ye=N.TEXTURE_2D_ARRAY):(K.setTexture2D(F,0),ye=N.TEXTURE_2D),y.activeTexture(N.TEXTURE0),y.pixelStorei(N.UNPACK_FLIP_Y_WEBGL,F.flipY),y.pixelStorei(N.UNPACK_PREMULTIPLY_ALPHA_WEBGL,F.premultiplyAlpha),y.pixelStorei(N.UNPACK_ALIGNMENT,F.unpackAlignment);const tn=y.getParameter(N.UNPACK_ROW_LENGTH),lt=y.getParameter(N.UNPACK_IMAGE_HEIGHT),fn=y.getParameter(N.UNPACK_SKIP_PIXELS),Vn=y.getParameter(N.UNPACK_SKIP_ROWS),Os=y.getParameter(N.UNPACK_SKIP_IMAGES);y.pixelStorei(N.UNPACK_ROW_LENGTH,Kt.width),y.pixelStorei(N.UNPACK_IMAGE_HEIGHT,Kt.height),y.pixelStorei(N.UNPACK_SKIP_PIXELS,Le),y.pixelStorei(N.UNPACK_SKIP_ROWS,Ke),y.pixelStorei(N.UNPACK_SKIP_IMAGES,je);const Ha=E.isDataArrayTexture||E.isData3DTexture,Rt=F.isDataArrayTexture||F.isData3DTexture;if(E.isDepthTexture){const ei=W.get(E),Ns=W.get(F),Ct=W.get(ei.__renderTarget),Fs=W.get(Ns.__renderTarget);y.bindFramebuffer(N.READ_FRAMEBUFFER,Ct.__webglFramebuffer),y.bindFramebuffer(N.DRAW_FRAMEBUFFER,Fs.__webglFramebuffer);for(let Ga=0;Ga<Ee;Ga++)Ha&&(N.framebufferTextureLayer(N.READ_FRAMEBUFFER,N.COLOR_ATTACHMENT0,W.get(E).__webglTexture,G,je+Ga),N.framebufferTextureLayer(N.DRAW_FRAMEBUFFER,N.COLOR_ATTACHMENT0,W.get(F).__webglTexture,ge,Qt+Ga)),N.blitFramebuffer(Le,Ke,_e,me,Oe,wt,_e,me,N.DEPTH_BUFFER_BIT,N.NEAREST);y.bindFramebuffer(N.READ_FRAMEBUFFER,null),y.bindFramebuffer(N.DRAW_FRAMEBUFFER,null)}else if(G!==0||E.isRenderTargetTexture||W.has(E)){const ei=W.get(E),Ns=W.get(F);y.bindFramebuffer(N.READ_FRAMEBUFFER,X),y.bindFramebuffer(N.DRAW_FRAMEBUFFER,L);for(let Ct=0;Ct<Ee;Ct++)Ha?N.framebufferTextureLayer(N.READ_FRAMEBUFFER,N.COLOR_ATTACHMENT0,ei.__webglTexture,G,je+Ct):N.framebufferTexture2D(N.READ_FRAMEBUFFER,N.COLOR_ATTACHMENT0,N.TEXTURE_2D,ei.__webglTexture,G),Rt?N.framebufferTextureLayer(N.DRAW_FRAMEBUFFER,N.COLOR_ATTACHMENT0,Ns.__webglTexture,ge,Qt+Ct):N.framebufferTexture2D(N.DRAW_FRAMEBUFFER,N.COLOR_ATTACHMENT0,N.TEXTURE_2D,Ns.__webglTexture,ge),G!==0?N.blitFramebuffer(Le,Ke,_e,me,Oe,wt,_e,me,N.COLOR_BUFFER_BIT,N.NEAREST):Rt?N.copyTexSubImage3D(ye,ge,Oe,wt,Qt+Ct,Le,Ke,_e,me):N.copyTexSubImage2D(ye,ge,Oe,wt,Le,Ke,_e,me);y.bindFramebuffer(N.READ_FRAMEBUFFER,null),y.bindFramebuffer(N.DRAW_FRAMEBUFFER,null)}else Rt?E.isDataTexture||E.isData3DTexture?N.texSubImage3D(ye,ge,Oe,wt,Qt,_e,me,Ee,Tt,Ti,Kt.data):F.isCompressedArrayTexture?N.compressedTexSubImage3D(ye,ge,Oe,wt,Qt,_e,me,Ee,Tt,Kt.data):N.texSubImage3D(ye,ge,Oe,wt,Qt,_e,me,Ee,Tt,Ti,Kt):E.isDataTexture?N.texSubImage2D(N.TEXTURE_2D,ge,Oe,wt,_e,me,Tt,Ti,Kt.data):E.isCompressedTexture?N.compressedTexSubImage2D(N.TEXTURE_2D,ge,Oe,wt,Kt.width,Kt.height,Tt,Kt.data):N.texSubImage2D(N.TEXTURE_2D,ge,Oe,wt,_e,me,Tt,Ti,Kt);y.pixelStorei(N.UNPACK_ROW_LENGTH,tn),y.pixelStorei(N.UNPACK_IMAGE_HEIGHT,lt),y.pixelStorei(N.UNPACK_SKIP_PIXELS,fn),y.pixelStorei(N.UNPACK_SKIP_ROWS,Vn),y.pixelStorei(N.UNPACK_SKIP_IMAGES,Os),ge===0&&F.generateMipmaps&&N.generateMipmap(ye),y.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),y.unbindTexture()},this.resetState=function(){B=0,k=0,$=null,y.reset(),ve.reset()},typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}get coordinateSystem(){return ns}get outputColorSpace(){return this._outputColorSpace}set outputColorSpace(e){this._outputColorSpace=e;const t=this.getContext();t.drawingBufferColorSpace=at._getDrawingBufferColorSpace(e),t.unpackColorSpace=at._getUnpackColorSpace()}}const $S=`
|
|
5417
5417
|
varying vec3 vDir;
|
|
5418
5418
|
varying vec3 vWorldDir;
|
|
5419
5419
|
|
|
@@ -6101,7 +6101,7 @@ vec3 finish(vec3 relative, vec4 overlay) {
|
|
|
6101
6101
|
void main() {
|
|
6102
6102
|
gl_FragColor = vec4(finish(texture2D(uFilm, vUv).rgb * uGain, texture2D(uOverlay, vUv) * uGain), 1.0);
|
|
6103
6103
|
}
|
|
6104
|
-
`,blending:as,depthTest:!1,depthWrite:!1}),this.quad=new De(new
|
|
6104
|
+
`,blending:as,depthTest:!1,depthWrite:!1}),this.quad=new De(new Yi(2,2),this.addMaterial),this.quadScene.add(this.quad)}get instantTarget(){return this.frame}open(e){const t=e.getRenderTarget();for(const i of[this.film.scene,this.film.overlay])e.setRenderTarget(i),e.setClearColor(0,0),e.clear(!0,!0,!0);e.setRenderTarget(t)}add(e,t){this.addMaterial.uniforms.uShare.value=t,this.quad.material=this.addMaterial;const i=e.getRenderTarget(),n=e.autoClear;e.autoClear=!1;for(const[s,a]of[[this.frame.scene,this.film.scene],[this.frame.overlay,this.film.overlay]])this.addMaterial.uniforms.uSource.value=s.texture,e.setRenderTarget(a),e.render(this.quadScene,this.quadCamera);e.setRenderTarget(i),e.autoClear=n}develop(e,t=1){this.developMaterial.uniforms.uGain.value=t,this.quad.material=this.developMaterial,e.setRenderTarget(null),e.render(this.quadScene,this.quadCamera)}resize(e,t){this.width=Math.max(1,e),this.height=Math.max(1,t);for(const i of[this.frame.scene,this.frame.overlay,this.film.scene,this.film.overlay])i.setSize(this.width,this.height)}dispose(){for(const e of[this.frame.scene,this.frame.overlay,this.film.scene,this.film.overlay])e.dispose();this.addMaterial.dispose(),this.developMaterial.dispose(),this.quad.geometry.dispose(),this.quadScene.clear()}}const Cd=Math.PI/180,tm=180/Math.PI;function Ql(r,e,t){return Math.max(e,Math.min(t,r))}const Vs=[{altitudeDeg:-90,zenith:[0,0,.02],horizon:[.01,.01,.03]},{altitudeDeg:-18,zenith:[.01,.01,.05],horizon:[.03,.02,.08]},{altitudeDeg:-6,zenith:[.02,.03,.12],horizon:[.25,.12,.15]},{altitudeDeg:0,zenith:[.05,.1,.35],horizon:[.9,.55,.35]},{altitudeDeg:8,zenith:[.1,.22,.55],horizon:[.82,.6,.45]},{altitudeDeg:25,zenith:[.15,.38,.78],horizon:[.76,.82,.91]},{altitudeDeg:90,zenith:[.15,.45,.9],horizon:[.7,.8,.95]}];function Kh(r,e,t){return r+(e-r)*t}function Nl(r,e,t){return[Kh(r[0],e[0],t),Kh(r[1],e[1],t),Kh(r[2],e[2],t)]}function Pd(r){const e=Math.max(Vs[0].altitudeDeg,Math.min(Vs[Vs.length-1].altitudeDeg,r));for(let i=0;i<Vs.length-1;i++){const n=Vs[i],s=Vs[i+1];if(e>=n.altitudeDeg&&e<=s.altitudeDeg){const a=(e-n.altitudeDeg)/(s.altitudeDeg-n.altitudeDeg);return{zenith:Nl(n.zenith,s.zenith,a),horizon:Nl(n.horizon,s.horizon,a)}}}const t=Vs[Vs.length-1];return{zenith:t.zenith,horizon:t.horizon}}const im=-18,nm=-4,iw=1.8;function Ld(r,e=0,t=0){if(r<=im)return pl+e-t;if(r>=0)return nm+e-t;const i=r/im;return pl-(pl-nm)*(1-i)**iw+e-t}const sm=-1.5,pl=6.5,nw=1.6;function bo(r,e=pl){const t=Math.max(e,sm+1),i=(t-r)/(t-sm);return Ql(i,0,1)**nw}function li(r,e,t){const i=r*Cd,n=e*Cd,s=t*Math.cos(i);return{x:s*Math.sin(n),y:t*Math.sin(i),z:-s*Math.cos(n)}}function sw(r,e,t){const i=Math.sqrt(r*r+e*e+t*t),n=i===0?0:Math.asin(Ql(e/i,-1,1))*tm,s=(Math.atan2(r,-t)*tm+360)%360;return{altitudeDeg:n,azimuthDeg:s}}function aw(r,e){const t=Math.abs(r-e)%360;return t>180?360-t:t}function rw(r,e,t,i){const n=Math.max(0,1-aw(r,t)/ow),s=Math.exp(-Math.max(0,e)/cw),a=i>0?Math.max(0,1-i/lw):Math.max(0,1-Math.abs(i+hw)/uw);return n*s*a}const ow=90,cw=12,lw=8,hw=2,uw=12;function dw(r,e,t,i){const{zenith:n,horizon:s}=Pd(i),a=Ql((r+90)/180,0,1),o=Nl(s,n,a),c=rw(e,r,t,i);if(c<=0)return o;const l=Pd(i+fw).horizon,h=[Math.max(s[0],l[0]),Math.max(s[1],l[1]),Math.max(s[2],l[2])];return Nl(o,h,c)}const fw=6;function Zh(r){return .12+.88*r}function pw(r){const e=Math.max(r,-4),t=Math.sin(e*Cd)+.50572*Math.pow(e+6.07995,-1.6364);return Ql(1/t,1,40)}function am(r){const e=pw(r)-1;return[1,Math.exp(-.022*e),Math.exp(-.062*e)]}const Co=[{maxBrightness:.35,size:1.2},{maxBrightness:.7,size:2},{maxBrightness:1/0,size:3.2}];function I1(r){return Co.findIndex(e=>r<=e.maxBrightness)}/**
|
|
6105
6105
|
@preserve
|
|
6106
6106
|
|
|
6107
6107
|
Astronomy library for JavaScript (browser and Node.js).
|
|
@@ -6185,7 +6185,7 @@ void main() {`).replace(Zn.ANCHOR,`float sigma = max(${st.MIN_SIGMA_PX.toFixed(2
|
|
|
6185
6185
|
float fromCentre = length( gl_PointCoord - vec2( 0.5 ) ) * vRaster;
|
|
6186
6186
|
if ( fromCentre > ${st.EDGE_SIGMAS.toFixed(1)} * sigma ) discard;
|
|
6187
6187
|
float share = exp( -0.5 * fromCentre * fromCentre / ( sigma * sigma ) ) * vTotal / ( 6.2831853 * sigma * sigma );
|
|
6188
|
-
vec4 diffuseColor = vec4( diffuse, opacity * share );`)}static integrateCoverage(){const{core:t,rim:i}=Zn.FALLOFF;let n=0;for(let s=0;s<2e3;s++){const a=(s+.5)/2e3*i,o=Math.min(Math.max((a-t)/(i-t),0),1),c=1-o*o*(3-2*o);n+=c*2*Math.PI*a*(i/2e3)}return n}}class Pi{static K=10;static FAINTEST=.001;static MAX_RADIUS_DEG=30;mesh;constructor(e){this.mesh=new De(new
|
|
6188
|
+
vec4 diffuseColor = vec4( diffuse, opacity * share );`)}static integrateCoverage(){const{core:t,rim:i}=Zn.FALLOFF;let n=0;for(let s=0;s<2e3;s++){const a=(s+.5)/2e3*i,o=Math.min(Math.max((a-t)/(i-t),0),1),c=1-o*o*(3-2*o);n+=c*2*Math.PI*a*(i/2e3)}return n}}class Pi{static K=10;static FAINTEST=.001;static MAX_RADIUS_DEG=30;mesh;constructor(e){this.mesh=new De(new Yi(2,2),new ct({uniforms:{uColor:{value:new se(0,0,0)},uTanRadius:{value:.1},uSourceDeg:{value:.25},uInnerDeg:{value:0}},vertexShader:Pi.VERTEX,fragmentShader:Pi.FRAGMENT,transparent:!0,depthWrite:!1,depthTest:!1,blending:Ni,fog:!1})),this.mesh.name=e,this.mesh.frustumCulled=!1,this.mesh.visible=!1}static radiusDeg(e){return Math.min(Pi.MAX_RADIUS_DEG,Math.sqrt(Math.max(e,0)/Pi.FAINTEST))}shine(e,t,i,n=0){const s=Pi.K*Math.max(t[0],t[1],t[2]),a=Pi.radiusDeg(s);if(a<=Math.max(i,n)){this.mesh.visible=!1;return}this.mesh.visible=!0,this.mesh.position.set(e.x,e.y,e.z);const o=this.mesh.material.uniforms;o.uColor.value.setRGB(Pi.K*t[0],Pi.K*t[1],Pi.K*t[2]),o.uTanRadius.value=Math.tan(a*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=`
|
|
6189
6189
|
uniform float uTanRadius;
|
|
6190
6190
|
varying vec2 vOffset;
|
|
6191
6191
|
void main() {
|
|
@@ -6242,7 +6242,7 @@ void main() {`).replace(Zn.ANCHOR,`float sigma = max(${st.MIN_SIGMA_PX.toFixed(2
|
|
|
6242
6242
|
if (which < 2) gl_FragColor = vec4(sum * 4.0 * PI / SAMPLES, 1.0);
|
|
6243
6243
|
else gl_FragColor = vec4(count > 0.0 ? logSum / count : -27.6, count, 0.0, 1.0);
|
|
6244
6244
|
}
|
|
6245
|
-
`,depthTest:!1,depthWrite:!1}),this.scene.add(new De(new Xi(2,2),this.material))}measure(e,t,i,n){if(this.reading)return;const s=this.material.uniforms;s.uProbe.value=t;const a=Math.cos(Po.SOURCE_CONE_DEG*Math.PI/180);[s.uExcludeA.value,s.uExcludeB.value].forEach((h,u)=>{const d=i[u];d?h.set(d.x,d.y,d.z,a):h.set(0,-1,0,2)});const c=e.getRenderTarget();e.setRenderTarget(this.target),e.render(this.scene,this.camera),e.setRenderTarget(c),this.reading=!0;const l=new Float32Array(12);e.readRenderTargetPixelsAsync(this.target,0,0,3,1,l).then(()=>n({up:[l[0],l[1],l[2]],down:[l[4],l[5],l[6]],logAverage:l[8]})).catch(()=>{}).finally(()=>{this.reading=!1})}dispose(){this.target.dispose(),this.material.dispose(),this.scene.children[0].geometry.dispose()}}const p5=[{name:"Sirius",raHours:6.7525,decDeg:-16.7161,mag:-1.44},{name:"Canopus",raHours:6.3992,decDeg:-52.6957,mag:-.62},{name:"Arcturus",raHours:14.261,decDeg:19.1824,mag:-.05},{name:"Rigil Kentaurus",raHours:14.6608,decDeg:-60.834,mag:-.01},{name:"Vega",raHours:18.6156,decDeg:38.7837,mag:.03},{name:"Capella",raHours:5.2782,decDeg:45.998,mag:.08},{name:"Rigel",raHours:5.2423,decDeg:-8.2016,mag:.18},{name:"Procyon",raHours:7.655,decDeg:5.225,mag:.4},{name:"Achernar",raHours:1.6286,decDeg:-57.2368,mag:.45},{name:"Betelgeuse",raHours:5.9195,decDeg:7.4071,mag:.45},{name:"Hadar",raHours:14.0637,decDeg:-60.373,mag:.61},{name:"Altair",raHours:19.8464,decDeg:8.8683,mag:.76},{name:"Acrux",raHours:12.4433,decDeg:-63.0991,mag:.77},{name:"Aldebaran",raHours:4.5987,decDeg:16.5093,mag:.87},{name:"Spica",raHours:13.4199,decDeg:-11.1613,mag:.98},{name:"Antares",raHours:16.4901,decDeg:-26.432,mag:1.06},{name:"Pollux",raHours:7.7553,decDeg:28.0262,mag:1.16},{name:"Fomalhaut",raHours:22.9608,decDeg:-29.6222,mag:1.17},{name:"Mimosa",raHours:12.7954,decDeg:-59.6888,mag:1.25},{name:"Deneb",raHours:20.6905,decDeg:45.2803,mag:1.25},{name:"Toliman",raHours:14.6603,decDeg:-60.8383,mag:1.35},{name:"Regulus",raHours:10.1395,decDeg:11.9672,mag:1.36},{name:"Adhara",raHours:6.9771,decDeg:-28.9721,mag:1.5},{name:"Castor",raHours:7.5766,decDeg:31.8883,mag:1.58},{name:"Gacrux",raHours:12.5194,decDeg:-57.1132,mag:1.59},{name:"Shaula",raHours:17.5601,decDeg:-37.1038,mag:1.62},{name:"Bellatrix",raHours:5.4189,decDeg:6.3497,mag:1.64},{name:"Elnath",raHours:5.4382,decDeg:28.6075,mag:1.65},{name:"Miaplacidus",raHours:9.22,decDeg:-69.7172,mag:1.67},{name:"Alnilam",raHours:5.6036,decDeg:-1.2019,mag:1.69},{name:"Alnair",raHours:22.1372,decDeg:-46.961,mag:1.73},{name:"Alnitak",raHours:5.6793,decDeg:-1.9426,mag:1.74},{name:"γ² Velorum",raHours:8.1589,decDeg:-47.3366,mag:1.75},{name:"Alioth",raHours:12.9005,decDeg:55.9598,mag:1.76},{name:"Mirfak",raHours:3.4054,decDeg:49.8612,mag:1.79},{name:"Kaus Australis",raHours:18.4029,decDeg:-34.3846,mag:1.79},{name:"Dubhe",raHours:11.0622,decDeg:61.751,mag:1.81},{name:"Wezen",raHours:7.1399,decDeg:-26.3932,mag:1.83},{name:"Alkaid",raHours:13.7924,decDeg:49.3133,mag:1.85},{name:"Avior",raHours:8.3752,decDeg:-59.5095,mag:1.86},{name:"Sargas",raHours:17.622,decDeg:-42.9978,mag:1.86},{name:"Menkalinan",raHours:5.9921,decDeg:44.9474,mag:1.9},{name:"Atria",raHours:16.8111,decDeg:-69.0277,mag:1.91},{name:"Alhena",raHours:6.6285,decDeg:16.3993,mag:1.93},{name:"Alsephina",raHours:8.7451,decDeg:-54.7088,mag:1.93},{name:"Peacock",raHours:20.4275,decDeg:-56.7351,mag:1.94},{name:"Polaris",raHours:2.5297,decDeg:89.2641,mag:1.97},{name:"Mirzam",raHours:6.3783,decDeg:-17.9559,mag:1.98},{name:"Alphard",raHours:9.4598,decDeg:-8.6586,mag:1.99},{name:"Hamal",raHours:2.1196,decDeg:23.4624,mag:2.01},{name:"Algieba",raHours:10.3329,decDeg:19.8415,mag:2.01},{name:"Diphda",raHours:.7265,decDeg:-17.9866,mag:2.04},{name:"Nunki",raHours:18.9211,decDeg:-26.2967,mag:2.05},{name:"Menkent",raHours:14.1114,decDeg:-36.37,mag:2.06},{name:"Alpheratz",raHours:.1398,decDeg:29.0904,mag:2.07},{name:"Mirach",raHours:1.1622,decDeg:35.6206,mag:2.07},{name:"Saiph",raHours:5.7959,decDeg:-9.6696,mag:2.07},{name:"Kochab",raHours:14.8451,decDeg:74.1555,mag:2.07},{name:"Tiaki",raHours:22.7111,decDeg:-46.8846,mag:2.07},{name:"Rasalhague",raHours:17.5822,decDeg:12.56,mag:2.08},{name:"Algol",raHours:3.1361,decDeg:40.9556,mag:2.09},{name:"Almach",raHours:2.065,decDeg:42.3297,mag:2.1},{name:"Denebola",raHours:11.8177,decDeg:14.5721,mag:2.14},{name:"Cih",raHours:.9451,decDeg:60.7167,mag:2.15},{name:"γ Centauri",raHours:12.692,decDeg:-48.9599,mag:2.2},{name:"Naos",raHours:8.0597,decDeg:-40.0031,mag:2.21},{name:"Aspidiske",raHours:9.2848,decDeg:-59.2752,mag:2.21},{name:"Alphecca",raHours:15.5781,decDeg:26.7147,mag:2.22},{name:"Suhail",raHours:9.1333,decDeg:-43.4326,mag:2.23},{name:"Mizar",raHours:13.3987,decDeg:54.9254,mag:2.23},{name:"Sadr",raHours:20.3705,decDeg:40.2567,mag:2.23},{name:"Schedar",raHours:.6751,decDeg:56.5373,mag:2.24},{name:"Eltanin",raHours:17.9434,decDeg:51.4889,mag:2.24},{name:"Mintaka",raHours:5.5334,decDeg:-.2991,mag:2.25},{name:"Caph",raHours:.1529,decDeg:59.1498,mag:2.28},{name:"ε Centauri",raHours:13.6648,decDeg:-53.4664,mag:2.29},{name:"Dschubba",raHours:16.0056,decDeg:-22.6217,mag:2.29},{name:"Larawag",raHours:16.8361,decDeg:-34.2932,mag:2.29},{name:"α Lupi",raHours:14.6988,decDeg:-47.3882,mag:2.3},{name:"η Centauri",raHours:14.5918,decDeg:-42.1578,mag:2.33},{name:"Merak",raHours:11.0307,decDeg:56.3824,mag:2.34},{name:"Izar",raHours:14.7498,decDeg:27.0742,mag:2.35},{name:"Enif",raHours:21.7364,decDeg:9.875,mag:2.38},{name:"κ Scorpii",raHours:17.7081,decDeg:-39.03,mag:2.39},{name:"Ankaa",raHours:.4381,decDeg:-42.306,mag:2.4},{name:"Phecda",raHours:11.8972,decDeg:53.6948,mag:2.41},{name:"Sabik",raHours:17.173,decDeg:-15.7249,mag:2.43},{name:"Scheat",raHours:23.0629,decDeg:28.0828,mag:2.44},{name:"Aludra",raHours:7.4016,decDeg:-29.3031,mag:2.45},{name:"Alderamin",raHours:21.3096,decDeg:62.5856,mag:2.45},{name:"Markeb",raHours:9.3686,decDeg:-55.0107,mag:2.47},{name:"Aljanah",raHours:20.7702,decDeg:33.9703,mag:2.48},{name:"Markab",raHours:23.0793,decDeg:15.2053,mag:2.49},{name:"Menkar",raHours:3.038,decDeg:4.0897,mag:2.54},{name:"ζ Ophiuchi",raHours:16.6193,decDeg:-10.5671,mag:2.54},{name:"ζ Centauri",raHours:13.9257,decDeg:-47.2884,mag:2.55},{name:"Zosma",raHours:11.2351,decDeg:20.5237,mag:2.56},{name:"Acrab",raHours:16.0906,decDeg:-19.8055,mag:2.56},{name:"Arneb",raHours:5.5455,decDeg:-17.8223,mag:2.58},{name:"δ Centauri",raHours:12.1393,decDeg:-50.7224,mag:2.58},{name:"Gienah",raHours:12.2634,decDeg:-17.5419,mag:2.58},{name:"Ascella",raHours:19.0435,decDeg:-29.8801,mag:2.6},{name:"Zubeneschamali",raHours:15.2834,decDeg:-9.3829,mag:2.61},{name:"Unukalhai",raHours:15.7378,decDeg:6.4256,mag:2.63},{name:"Sheratan",raHours:1.9107,decDeg:20.808,mag:2.64},{name:"Phact",raHours:5.6608,decDeg:-34.0741,mag:2.65},{name:"Mahasim",raHours:5.9954,decDeg:37.2126,mag:2.65},{name:"Kraz",raHours:12.5731,decDeg:-23.3968,mag:2.65},{name:"Ruchbah",raHours:1.4302,decDeg:60.2353,mag:2.66},{name:"Muphrid",raHours:13.9114,decDeg:18.3977,mag:2.68},{name:"β Lupi",raHours:14.9755,decDeg:-43.134,mag:2.68},{name:"Hassaleh",raHours:4.9499,decDeg:33.1661,mag:2.69},{name:"μ Velorum",raHours:10.7795,decDeg:-49.4203,mag:2.69},{name:"α Muscae",raHours:12.6197,decDeg:-69.1356,mag:2.69},{name:"Lesath",raHours:17.5127,decDeg:-37.2958,mag:2.7},{name:"π Puppis",raHours:7.2857,decDeg:-37.0975,mag:2.71},{name:"Kaus Media",raHours:18.3499,decDeg:-29.8281,mag:2.72},{name:"Tarazed",raHours:19.771,decDeg:10.6133,mag:2.72},{name:"Yed Prior",raHours:16.2391,decDeg:-3.6943,mag:2.73},{name:"Athebyne",raHours:16.3999,decDeg:61.5142,mag:2.73},{name:"θ Carinae",raHours:10.7159,decDeg:-64.3945,mag:2.74},{name:"Porrima",raHours:12.6943,decDeg:-1.4494,mag:2.74},{name:"Hatysa",raHours:5.5906,decDeg:-5.9099,mag:2.75},{name:"ι Centauri",raHours:13.3433,decDeg:-36.7123,mag:2.75},{name:"Zubenelgenubi",raHours:14.848,decDeg:-16.0418,mag:2.75},{name:"Cebalrai",raHours:17.7245,decDeg:4.5673,mag:2.76},{name:"Cursa",raHours:5.1308,decDeg:-5.0864,mag:2.78},{name:"Kornephoros",raHours:16.5037,decDeg:21.4896,mag:2.78},{name:"Rasalgethi",raHours:17.2441,decDeg:14.3903,mag:2.78},{name:"Imai",raHours:12.2524,decDeg:-58.7489,mag:2.79},{name:"Rastaban",raHours:17.5072,decDeg:52.3014,mag:2.79},{name:"γ Lupi",raHours:15.5857,decDeg:-41.1668,mag:2.8},{name:"Nihal",raHours:5.4708,decDeg:-20.7594,mag:2.81},{name:"ζ Herculis",raHours:16.6881,decDeg:31.6027,mag:2.81},{name:"β Hydri",raHours:.4279,decDeg:-77.2542,mag:2.82},{name:"Paikauhale",raHours:16.598,decDeg:-28.216,mag:2.82},{name:"Kaus Borealis",raHours:18.4662,decDeg:-25.4217,mag:2.82},{name:"Algenib",raHours:.2206,decDeg:15.1836,mag:2.83},{name:"Tureis",raHours:8.1257,decDeg:-24.3043,mag:2.83},{name:"β Trianguli Australis",raHours:15.9191,decDeg:-63.4307,mag:2.83},{name:"ζ Persei",raHours:3.9022,decDeg:31.8836,mag:2.84},{name:"β Arae",raHours:17.4217,decDeg:-55.5299,mag:2.84},{name:"α Arae",raHours:17.5307,decDeg:-49.8761,mag:2.84},{name:"Alcyone",raHours:3.7914,decDeg:24.1051,mag:2.85},{name:"Vindemiatrix",raHours:13.0363,decDeg:10.9591,mag:2.85},{name:"Deneb Algedi",raHours:21.784,decDeg:-16.1273,mag:2.85},{name:"Castor B",raHours:7.5768,decDeg:31.8905,mag:2.85},{name:"α Hydri",raHours:1.9795,decDeg:-61.5699,mag:2.86},{name:"Fawaris",raHours:19.7496,decDeg:45.1308,mag:2.86},{name:"Tejat",raHours:6.3827,decDeg:22.5136,mag:2.87},{name:"γ Trianguli Australis",raHours:15.3152,decDeg:-68.6795,mag:2.87},{name:"α Tucanae",raHours:22.3084,decDeg:-60.2596,mag:2.87},{name:"Acamar",raHours:2.971,decDeg:-40.3047,mag:2.88},{name:"Albaldah",raHours:19.1627,decDeg:-21.0236,mag:2.88},{name:"Gomeisa",raHours:7.4525,decDeg:8.2893,mag:2.89},{name:"Cor Caroli",raHours:12.9338,decDeg:38.3184,mag:2.89},{name:"Fang",raHours:15.9809,decDeg:-26.1141,mag:2.89},{name:"ε Persei",raHours:3.9642,decDeg:40.0102,mag:2.9},{name:"Alniyat",raHours:16.3531,decDeg:-25.5928,mag:2.9},{name:"Sadalsuud",raHours:21.526,decDeg:-5.5712,mag:2.9},{name:"γ Persei",raHours:3.0799,decDeg:53.5064,mag:2.91},{name:"υ Carinae",raHours:9.785,decDeg:-65.072,mag:2.92},{name:"Matar",raHours:22.7167,decDeg:30.2212,mag:2.93},{name:"τ Puppis",raHours:6.8323,decDeg:-50.6146,mag:2.94},{name:"Algorab",raHours:12.4977,decDeg:-16.5154,mag:2.94},{name:"Sadalmelik",raHours:22.0964,decDeg:-.3199,mag:2.95},{name:"Zaurak",raHours:3.9672,decDeg:-13.5085,mag:2.97},{name:"Tianguan",raHours:5.6274,decDeg:21.1425,mag:2.97},{name:"Ras Elased Australis",raHours:9.7642,decDeg:23.7743,mag:2.97},{name:"Alnasl",raHours:18.0968,decDeg:-30.4241,mag:2.98},{name:"γ Hydrae",raHours:13.3154,decDeg:-23.1715,mag:2.99},{name:"ι¹ Scorpii",raHours:17.7931,decDeg:-40.127,mag:2.99},{name:"Okab",raHours:19.0902,decDeg:13.8635,mag:2.99},{name:"β Trianguli",raHours:2.1591,decDeg:34.9873,mag:3},{name:"ψ Ursae Majoris",raHours:11.1611,decDeg:44.4985,mag:3},{name:"Pherkad",raHours:15.3455,decDeg:71.834,mag:3},{name:"Xamidimura",raHours:16.8645,decDeg:-38.0474,mag:3},{name:"Aldhanab",raHours:21.8988,decDeg:-37.3649,mag:3}],wo=64,Mi=wo+1,Mm=2048,m5=900,g5=700/900,v5=0,M5=.01;function Z1(r,e,t){return{north:_s(0,-t,r,e).lat,south:_s(0,t,r,e).lat,east:_s(t,0,r,e).lng,west:_s(-t,0,r,e).lng}}async function x5(r,e,t,i=m5){const n=i,s=i*g5,a=Z1(r,e,n),o={width:Mi,height:Mi},[c,l]=await Promise.all([t.elevation.getElevationGrid(a,o),t.imagery.getImageryTexture(a,{width:Mm,height:Mm})]),h=Math.floor(Mi/2),u=c.heights[h*Mi+h],d=new Float32Array(Mi*Mi*3),f=new Float32Array(Mi*Mi*2),p=new Float32Array(Mi*Mi*4);for(let S=0;S<Mi;S++){const w=S/(Mi-1),T=a.north+(a.south-a.north)*w;for(let x=0;x<Mi;x++){const A=x/(Mi-1),C=a.west+(a.east-a.west)*A,{x:I,z:P}=ni(T,C,r,e),V=c.heights[S*Mi+x],X=Math.max(Math.abs(I),Math.abs(P)),L=1-y5((X-s)/(n-s),0,1),B=v5+M5+(V-u),k=S*Mi+x;d[k*3]=I,d[k*3+1]=B,d[k*3+2]=P;const $=Og(l.bounds,C,T);f[k*2]=$.x,f[k*2+1]=$.y,p[k*4]=1,p[k*4+1]=1,p[k*4+2]=1,p[k*4+3]=L}}const v=new Uint16Array(wo*wo*6);let m=0;for(let S=0;S<wo;S++)for(let w=0;w<wo;w++){const T=S*Mi+w,x=T+1,A=T+Mi,C=A+1;v[m++]=T,v[m++]=A,v[m++]=x,v[m++]=x,v[m++]=A,v[m++]=C}const g=new ot;g.setAttribute("position",new tt(d,3)),g.setAttribute("uv",new tt(f,2)),g.setAttribute("color",new tt(p,4)),g.setIndex(new tt(v,1)),g.computeVertexNormals();const _=new Ls(l.source);_.flipY=!1,_.colorSpace=Gi,_.anisotropy=8;const b=new Vr({map:_,color:new se(1,1,1),vertexColors:!0,transparent:!0,fog:!0}),M=new De(g,b);return M.receiveShadow=!0,M.castShadow=!0,{mesh:M,attribution:t.imagery.attribution,originElevationM:Number.isFinite(u)?u:void 0}}function y5(r,e,t){return Math.max(e,Math.min(t,r))}class vn{static STEP_M=8;static LIFT_M=.06;static CONTEMPORARY_OPACITY=.45;static ALBEDO={paved:[.16,.16,.17],gravel:[.42,.38,.31],dirt:[.34,.28,.21]};group=new Dt;surveyed=new Dt;stated=new Dt;constructor(){this.group.name="roads",this.surveyed.name="roads surveyed",this.stated.name="roads stated",this.group.add(this.surveyed,this.stated)}set(e,t,i,n,s){vn.empty(this.surveyed);const a=new Map;for(const o of e){const c=a.get(o.surface)??{positions:[],indices:[]};a.set(o.surface,c),this.appendRibbon(o,t,i,n,c)}for(const[o,c]of a){const l=this.meshOf(o,c,s);l&&this.surveyed.add(l)}}setStated(e,t){vn.empty(this.stated);const i=new Map;for(const n of e){const s=i.get(n.surface)??{positions:[],indices:[]};i.set(n.surface,s),this.appendPath(n.path.map(a=>({x:a.eastM,z:-a.northM})),n.widthM,t,s)}for(const[n,s]of i){const a=this.meshOf(n,s,!1);a&&this.stated.add(a)}}clear(){vn.empty(this.surveyed)}static empty(e){for(const t of[...e.children]){e.remove(t);const i=t;i.geometry?.dispose(),i.material?.dispose()}}dispose(){vn.empty(this.surveyed),vn.empty(this.stated)}appendRibbon(e,t,i,n,s){this.appendPath(e.points.map(a=>ni(a.lat,a.lng,t,i)),e.widthM,n,s)}appendPath(e,t,i,n){const s=this.resample(e);if(s.length<2)return;const a=Math.max(.5,t/2),o=n.positions.length/3;for(let c=0;c<s.length;c++){const l=s[Math.max(0,c-1)],h=s[Math.min(s.length-1,c+1)];let u=h.x-l.x,d=h.z-l.z;const f=Math.hypot(u,d);f<1e-6?(u=1,d=0):(u/=f,d/=f);const p=-d*a,v=u*a,m={x:s[c].x+p,z:s[c].z+v},g={x:s[c].x-p,z:s[c].z-v};n.positions.push(m.x,i(m.x,m.z)+vn.LIFT_M,m.z,g.x,i(g.x,g.z)+vn.LIFT_M,g.z)}for(let c=0;c<s.length-1;c++){const l=o+c*2;n.indices.push(l,l+2,l+1,l+1,l+2,l+3)}}meshOf(e,t,i){if(t.indices.length===0)return;const n=new ot;n.setAttribute("position",new tt(new Float32Array(t.positions),3)),n.setIndex(new tt(new Uint32Array(t.indices),1)),n.computeVertexNormals();const s=vn.ALBEDO[e],a=new Vr({color:new se(s[0],s[1],s[2]),transparent:i,opacity:i?vn.CONTEMPORARY_OPACITY:1,fog:!0,polygonOffset:!0,polygonOffsetFactor:-2,polygonOffsetUnits:-2}),o=new De(n,a);return o.name=`roads ${e}`,o.receiveShadow=!0,o.castShadow=!1,o}resample(e){const t=[];for(let n=0;n<e.length-1;n++){const s=e[n],a=e[n+1],o=Math.hypot(a.x-s.x,a.z-s.z),c=Math.max(1,Math.ceil(o/vn.STEP_M));for(let l=0;l<c;l++){const h=l/c;t.push({x:s.x+(a.x-s.x)*h,z:s.z+(a.z-s.z)*h})}}const i=e[e.length-1];return i&&t.push({x:i.x,z:i.z}),t}}const b5=18,_5=.55,S5=.5,w5=.4,E5=2,A5=`
|
|
6245
|
+
`,depthTest:!1,depthWrite:!1}),this.scene.add(new De(new Yi(2,2),this.material))}measure(e,t,i,n){if(this.reading)return;const s=this.material.uniforms;s.uProbe.value=t;const a=Math.cos(Po.SOURCE_CONE_DEG*Math.PI/180);[s.uExcludeA.value,s.uExcludeB.value].forEach((h,u)=>{const d=i[u];d?h.set(d.x,d.y,d.z,a):h.set(0,-1,0,2)});const c=e.getRenderTarget();e.setRenderTarget(this.target),e.render(this.scene,this.camera),e.setRenderTarget(c),this.reading=!0;const l=new Float32Array(12);e.readRenderTargetPixelsAsync(this.target,0,0,3,1,l).then(()=>n({up:[l[0],l[1],l[2]],down:[l[4],l[5],l[6]],logAverage:l[8]})).catch(()=>{}).finally(()=>{this.reading=!1})}dispose(){this.target.dispose(),this.material.dispose(),this.scene.children[0].geometry.dispose()}}const p5=[{name:"Sirius",raHours:6.7525,decDeg:-16.7161,mag:-1.44},{name:"Canopus",raHours:6.3992,decDeg:-52.6957,mag:-.62},{name:"Arcturus",raHours:14.261,decDeg:19.1824,mag:-.05},{name:"Rigil Kentaurus",raHours:14.6608,decDeg:-60.834,mag:-.01},{name:"Vega",raHours:18.6156,decDeg:38.7837,mag:.03},{name:"Capella",raHours:5.2782,decDeg:45.998,mag:.08},{name:"Rigel",raHours:5.2423,decDeg:-8.2016,mag:.18},{name:"Procyon",raHours:7.655,decDeg:5.225,mag:.4},{name:"Achernar",raHours:1.6286,decDeg:-57.2368,mag:.45},{name:"Betelgeuse",raHours:5.9195,decDeg:7.4071,mag:.45},{name:"Hadar",raHours:14.0637,decDeg:-60.373,mag:.61},{name:"Altair",raHours:19.8464,decDeg:8.8683,mag:.76},{name:"Acrux",raHours:12.4433,decDeg:-63.0991,mag:.77},{name:"Aldebaran",raHours:4.5987,decDeg:16.5093,mag:.87},{name:"Spica",raHours:13.4199,decDeg:-11.1613,mag:.98},{name:"Antares",raHours:16.4901,decDeg:-26.432,mag:1.06},{name:"Pollux",raHours:7.7553,decDeg:28.0262,mag:1.16},{name:"Fomalhaut",raHours:22.9608,decDeg:-29.6222,mag:1.17},{name:"Mimosa",raHours:12.7954,decDeg:-59.6888,mag:1.25},{name:"Deneb",raHours:20.6905,decDeg:45.2803,mag:1.25},{name:"Toliman",raHours:14.6603,decDeg:-60.8383,mag:1.35},{name:"Regulus",raHours:10.1395,decDeg:11.9672,mag:1.36},{name:"Adhara",raHours:6.9771,decDeg:-28.9721,mag:1.5},{name:"Castor",raHours:7.5766,decDeg:31.8883,mag:1.58},{name:"Gacrux",raHours:12.5194,decDeg:-57.1132,mag:1.59},{name:"Shaula",raHours:17.5601,decDeg:-37.1038,mag:1.62},{name:"Bellatrix",raHours:5.4189,decDeg:6.3497,mag:1.64},{name:"Elnath",raHours:5.4382,decDeg:28.6075,mag:1.65},{name:"Miaplacidus",raHours:9.22,decDeg:-69.7172,mag:1.67},{name:"Alnilam",raHours:5.6036,decDeg:-1.2019,mag:1.69},{name:"Alnair",raHours:22.1372,decDeg:-46.961,mag:1.73},{name:"Alnitak",raHours:5.6793,decDeg:-1.9426,mag:1.74},{name:"γ² Velorum",raHours:8.1589,decDeg:-47.3366,mag:1.75},{name:"Alioth",raHours:12.9005,decDeg:55.9598,mag:1.76},{name:"Mirfak",raHours:3.4054,decDeg:49.8612,mag:1.79},{name:"Kaus Australis",raHours:18.4029,decDeg:-34.3846,mag:1.79},{name:"Dubhe",raHours:11.0622,decDeg:61.751,mag:1.81},{name:"Wezen",raHours:7.1399,decDeg:-26.3932,mag:1.83},{name:"Alkaid",raHours:13.7924,decDeg:49.3133,mag:1.85},{name:"Avior",raHours:8.3752,decDeg:-59.5095,mag:1.86},{name:"Sargas",raHours:17.622,decDeg:-42.9978,mag:1.86},{name:"Menkalinan",raHours:5.9921,decDeg:44.9474,mag:1.9},{name:"Atria",raHours:16.8111,decDeg:-69.0277,mag:1.91},{name:"Alhena",raHours:6.6285,decDeg:16.3993,mag:1.93},{name:"Alsephina",raHours:8.7451,decDeg:-54.7088,mag:1.93},{name:"Peacock",raHours:20.4275,decDeg:-56.7351,mag:1.94},{name:"Polaris",raHours:2.5297,decDeg:89.2641,mag:1.97},{name:"Mirzam",raHours:6.3783,decDeg:-17.9559,mag:1.98},{name:"Alphard",raHours:9.4598,decDeg:-8.6586,mag:1.99},{name:"Hamal",raHours:2.1196,decDeg:23.4624,mag:2.01},{name:"Algieba",raHours:10.3329,decDeg:19.8415,mag:2.01},{name:"Diphda",raHours:.7265,decDeg:-17.9866,mag:2.04},{name:"Nunki",raHours:18.9211,decDeg:-26.2967,mag:2.05},{name:"Menkent",raHours:14.1114,decDeg:-36.37,mag:2.06},{name:"Alpheratz",raHours:.1398,decDeg:29.0904,mag:2.07},{name:"Mirach",raHours:1.1622,decDeg:35.6206,mag:2.07},{name:"Saiph",raHours:5.7959,decDeg:-9.6696,mag:2.07},{name:"Kochab",raHours:14.8451,decDeg:74.1555,mag:2.07},{name:"Tiaki",raHours:22.7111,decDeg:-46.8846,mag:2.07},{name:"Rasalhague",raHours:17.5822,decDeg:12.56,mag:2.08},{name:"Algol",raHours:3.1361,decDeg:40.9556,mag:2.09},{name:"Almach",raHours:2.065,decDeg:42.3297,mag:2.1},{name:"Denebola",raHours:11.8177,decDeg:14.5721,mag:2.14},{name:"Cih",raHours:.9451,decDeg:60.7167,mag:2.15},{name:"γ Centauri",raHours:12.692,decDeg:-48.9599,mag:2.2},{name:"Naos",raHours:8.0597,decDeg:-40.0031,mag:2.21},{name:"Aspidiske",raHours:9.2848,decDeg:-59.2752,mag:2.21},{name:"Alphecca",raHours:15.5781,decDeg:26.7147,mag:2.22},{name:"Suhail",raHours:9.1333,decDeg:-43.4326,mag:2.23},{name:"Mizar",raHours:13.3987,decDeg:54.9254,mag:2.23},{name:"Sadr",raHours:20.3705,decDeg:40.2567,mag:2.23},{name:"Schedar",raHours:.6751,decDeg:56.5373,mag:2.24},{name:"Eltanin",raHours:17.9434,decDeg:51.4889,mag:2.24},{name:"Mintaka",raHours:5.5334,decDeg:-.2991,mag:2.25},{name:"Caph",raHours:.1529,decDeg:59.1498,mag:2.28},{name:"ε Centauri",raHours:13.6648,decDeg:-53.4664,mag:2.29},{name:"Dschubba",raHours:16.0056,decDeg:-22.6217,mag:2.29},{name:"Larawag",raHours:16.8361,decDeg:-34.2932,mag:2.29},{name:"α Lupi",raHours:14.6988,decDeg:-47.3882,mag:2.3},{name:"η Centauri",raHours:14.5918,decDeg:-42.1578,mag:2.33},{name:"Merak",raHours:11.0307,decDeg:56.3824,mag:2.34},{name:"Izar",raHours:14.7498,decDeg:27.0742,mag:2.35},{name:"Enif",raHours:21.7364,decDeg:9.875,mag:2.38},{name:"κ Scorpii",raHours:17.7081,decDeg:-39.03,mag:2.39},{name:"Ankaa",raHours:.4381,decDeg:-42.306,mag:2.4},{name:"Phecda",raHours:11.8972,decDeg:53.6948,mag:2.41},{name:"Sabik",raHours:17.173,decDeg:-15.7249,mag:2.43},{name:"Scheat",raHours:23.0629,decDeg:28.0828,mag:2.44},{name:"Aludra",raHours:7.4016,decDeg:-29.3031,mag:2.45},{name:"Alderamin",raHours:21.3096,decDeg:62.5856,mag:2.45},{name:"Markeb",raHours:9.3686,decDeg:-55.0107,mag:2.47},{name:"Aljanah",raHours:20.7702,decDeg:33.9703,mag:2.48},{name:"Markab",raHours:23.0793,decDeg:15.2053,mag:2.49},{name:"Menkar",raHours:3.038,decDeg:4.0897,mag:2.54},{name:"ζ Ophiuchi",raHours:16.6193,decDeg:-10.5671,mag:2.54},{name:"ζ Centauri",raHours:13.9257,decDeg:-47.2884,mag:2.55},{name:"Zosma",raHours:11.2351,decDeg:20.5237,mag:2.56},{name:"Acrab",raHours:16.0906,decDeg:-19.8055,mag:2.56},{name:"Arneb",raHours:5.5455,decDeg:-17.8223,mag:2.58},{name:"δ Centauri",raHours:12.1393,decDeg:-50.7224,mag:2.58},{name:"Gienah",raHours:12.2634,decDeg:-17.5419,mag:2.58},{name:"Ascella",raHours:19.0435,decDeg:-29.8801,mag:2.6},{name:"Zubeneschamali",raHours:15.2834,decDeg:-9.3829,mag:2.61},{name:"Unukalhai",raHours:15.7378,decDeg:6.4256,mag:2.63},{name:"Sheratan",raHours:1.9107,decDeg:20.808,mag:2.64},{name:"Phact",raHours:5.6608,decDeg:-34.0741,mag:2.65},{name:"Mahasim",raHours:5.9954,decDeg:37.2126,mag:2.65},{name:"Kraz",raHours:12.5731,decDeg:-23.3968,mag:2.65},{name:"Ruchbah",raHours:1.4302,decDeg:60.2353,mag:2.66},{name:"Muphrid",raHours:13.9114,decDeg:18.3977,mag:2.68},{name:"β Lupi",raHours:14.9755,decDeg:-43.134,mag:2.68},{name:"Hassaleh",raHours:4.9499,decDeg:33.1661,mag:2.69},{name:"μ Velorum",raHours:10.7795,decDeg:-49.4203,mag:2.69},{name:"α Muscae",raHours:12.6197,decDeg:-69.1356,mag:2.69},{name:"Lesath",raHours:17.5127,decDeg:-37.2958,mag:2.7},{name:"π Puppis",raHours:7.2857,decDeg:-37.0975,mag:2.71},{name:"Kaus Media",raHours:18.3499,decDeg:-29.8281,mag:2.72},{name:"Tarazed",raHours:19.771,decDeg:10.6133,mag:2.72},{name:"Yed Prior",raHours:16.2391,decDeg:-3.6943,mag:2.73},{name:"Athebyne",raHours:16.3999,decDeg:61.5142,mag:2.73},{name:"θ Carinae",raHours:10.7159,decDeg:-64.3945,mag:2.74},{name:"Porrima",raHours:12.6943,decDeg:-1.4494,mag:2.74},{name:"Hatysa",raHours:5.5906,decDeg:-5.9099,mag:2.75},{name:"ι Centauri",raHours:13.3433,decDeg:-36.7123,mag:2.75},{name:"Zubenelgenubi",raHours:14.848,decDeg:-16.0418,mag:2.75},{name:"Cebalrai",raHours:17.7245,decDeg:4.5673,mag:2.76},{name:"Cursa",raHours:5.1308,decDeg:-5.0864,mag:2.78},{name:"Kornephoros",raHours:16.5037,decDeg:21.4896,mag:2.78},{name:"Rasalgethi",raHours:17.2441,decDeg:14.3903,mag:2.78},{name:"Imai",raHours:12.2524,decDeg:-58.7489,mag:2.79},{name:"Rastaban",raHours:17.5072,decDeg:52.3014,mag:2.79},{name:"γ Lupi",raHours:15.5857,decDeg:-41.1668,mag:2.8},{name:"Nihal",raHours:5.4708,decDeg:-20.7594,mag:2.81},{name:"ζ Herculis",raHours:16.6881,decDeg:31.6027,mag:2.81},{name:"β Hydri",raHours:.4279,decDeg:-77.2542,mag:2.82},{name:"Paikauhale",raHours:16.598,decDeg:-28.216,mag:2.82},{name:"Kaus Borealis",raHours:18.4662,decDeg:-25.4217,mag:2.82},{name:"Algenib",raHours:.2206,decDeg:15.1836,mag:2.83},{name:"Tureis",raHours:8.1257,decDeg:-24.3043,mag:2.83},{name:"β Trianguli Australis",raHours:15.9191,decDeg:-63.4307,mag:2.83},{name:"ζ Persei",raHours:3.9022,decDeg:31.8836,mag:2.84},{name:"β Arae",raHours:17.4217,decDeg:-55.5299,mag:2.84},{name:"α Arae",raHours:17.5307,decDeg:-49.8761,mag:2.84},{name:"Alcyone",raHours:3.7914,decDeg:24.1051,mag:2.85},{name:"Vindemiatrix",raHours:13.0363,decDeg:10.9591,mag:2.85},{name:"Deneb Algedi",raHours:21.784,decDeg:-16.1273,mag:2.85},{name:"Castor B",raHours:7.5768,decDeg:31.8905,mag:2.85},{name:"α Hydri",raHours:1.9795,decDeg:-61.5699,mag:2.86},{name:"Fawaris",raHours:19.7496,decDeg:45.1308,mag:2.86},{name:"Tejat",raHours:6.3827,decDeg:22.5136,mag:2.87},{name:"γ Trianguli Australis",raHours:15.3152,decDeg:-68.6795,mag:2.87},{name:"α Tucanae",raHours:22.3084,decDeg:-60.2596,mag:2.87},{name:"Acamar",raHours:2.971,decDeg:-40.3047,mag:2.88},{name:"Albaldah",raHours:19.1627,decDeg:-21.0236,mag:2.88},{name:"Gomeisa",raHours:7.4525,decDeg:8.2893,mag:2.89},{name:"Cor Caroli",raHours:12.9338,decDeg:38.3184,mag:2.89},{name:"Fang",raHours:15.9809,decDeg:-26.1141,mag:2.89},{name:"ε Persei",raHours:3.9642,decDeg:40.0102,mag:2.9},{name:"Alniyat",raHours:16.3531,decDeg:-25.5928,mag:2.9},{name:"Sadalsuud",raHours:21.526,decDeg:-5.5712,mag:2.9},{name:"γ Persei",raHours:3.0799,decDeg:53.5064,mag:2.91},{name:"υ Carinae",raHours:9.785,decDeg:-65.072,mag:2.92},{name:"Matar",raHours:22.7167,decDeg:30.2212,mag:2.93},{name:"τ Puppis",raHours:6.8323,decDeg:-50.6146,mag:2.94},{name:"Algorab",raHours:12.4977,decDeg:-16.5154,mag:2.94},{name:"Sadalmelik",raHours:22.0964,decDeg:-.3199,mag:2.95},{name:"Zaurak",raHours:3.9672,decDeg:-13.5085,mag:2.97},{name:"Tianguan",raHours:5.6274,decDeg:21.1425,mag:2.97},{name:"Ras Elased Australis",raHours:9.7642,decDeg:23.7743,mag:2.97},{name:"Alnasl",raHours:18.0968,decDeg:-30.4241,mag:2.98},{name:"γ Hydrae",raHours:13.3154,decDeg:-23.1715,mag:2.99},{name:"ι¹ Scorpii",raHours:17.7931,decDeg:-40.127,mag:2.99},{name:"Okab",raHours:19.0902,decDeg:13.8635,mag:2.99},{name:"β Trianguli",raHours:2.1591,decDeg:34.9873,mag:3},{name:"ψ Ursae Majoris",raHours:11.1611,decDeg:44.4985,mag:3},{name:"Pherkad",raHours:15.3455,decDeg:71.834,mag:3},{name:"Xamidimura",raHours:16.8645,decDeg:-38.0474,mag:3},{name:"Aldhanab",raHours:21.8988,decDeg:-37.3649,mag:3}],wo=64,Mi=wo+1,Mm=2048,m5=900,g5=700/900,v5=0,M5=.01;function Z1(r,e,t){return{north:_s(0,-t,r,e).lat,south:_s(0,t,r,e).lat,east:_s(t,0,r,e).lng,west:_s(-t,0,r,e).lng}}async function x5(r,e,t,i=m5){const n=i,s=i*g5,a=Z1(r,e,n),o={width:Mi,height:Mi},[c,l]=await Promise.all([t.elevation.getElevationGrid(a,o),t.imagery.getImageryTexture(a,{width:Mm,height:Mm})]),h=Math.floor(Mi/2),u=c.heights[h*Mi+h],d=new Float32Array(Mi*Mi*3),f=new Float32Array(Mi*Mi*2),p=new Float32Array(Mi*Mi*4);for(let S=0;S<Mi;S++){const w=S/(Mi-1),T=a.north+(a.south-a.north)*w;for(let x=0;x<Mi;x++){const A=x/(Mi-1),C=a.west+(a.east-a.west)*A,{x:I,z:P}=ni(T,C,r,e),V=c.heights[S*Mi+x],X=Math.max(Math.abs(I),Math.abs(P)),L=1-y5((X-s)/(n-s),0,1),B=v5+M5+(V-u),k=S*Mi+x;d[k*3]=I,d[k*3+1]=B,d[k*3+2]=P;const $=Og(l.bounds,C,T);f[k*2]=$.x,f[k*2+1]=$.y,p[k*4]=1,p[k*4+1]=1,p[k*4+2]=1,p[k*4+3]=L}}const v=new Uint16Array(wo*wo*6);let m=0;for(let S=0;S<wo;S++)for(let w=0;w<wo;w++){const T=S*Mi+w,x=T+1,A=T+Mi,C=A+1;v[m++]=T,v[m++]=A,v[m++]=x,v[m++]=x,v[m++]=A,v[m++]=C}const g=new ot;g.setAttribute("position",new tt(d,3)),g.setAttribute("uv",new tt(f,2)),g.setAttribute("color",new tt(p,4)),g.setIndex(new tt(v,1)),g.computeVertexNormals();const _=new Ls(l.source);_.flipY=!1,_.colorSpace=Vi,_.anisotropy=8;const b=new Vr({map:_,color:new se(1,1,1),vertexColors:!0,transparent:!0,fog:!0}),M=new De(g,b);return M.receiveShadow=!0,M.castShadow=!0,{mesh:M,attribution:t.imagery.attribution,originElevationM:Number.isFinite(u)?u:void 0}}function y5(r,e,t){return Math.max(e,Math.min(t,r))}class vn{static STEP_M=8;static LIFT_M=.06;static CONTEMPORARY_OPACITY=.45;static ALBEDO={paved:[.16,.16,.17],gravel:[.42,.38,.31],dirt:[.34,.28,.21]};group=new Dt;surveyed=new Dt;stated=new Dt;constructor(){this.group.name="roads",this.surveyed.name="roads surveyed",this.stated.name="roads stated",this.group.add(this.surveyed,this.stated)}set(e,t,i,n,s){vn.empty(this.surveyed);const a=new Map;for(const o of e){const c=a.get(o.surface)??{positions:[],indices:[]};a.set(o.surface,c),this.appendRibbon(o,t,i,n,c)}for(const[o,c]of a){const l=this.meshOf(o,c,s);l&&this.surveyed.add(l)}}setStated(e,t){vn.empty(this.stated);const i=new Map;for(const n of e){const s=i.get(n.surface)??{positions:[],indices:[]};i.set(n.surface,s),this.appendPath(n.path.map(a=>({x:a.eastM,z:-a.northM})),n.widthM,t,s)}for(const[n,s]of i){const a=this.meshOf(n,s,!1);a&&this.stated.add(a)}}clear(){vn.empty(this.surveyed)}static empty(e){for(const t of[...e.children]){e.remove(t);const i=t;i.geometry?.dispose(),i.material?.dispose()}}dispose(){vn.empty(this.surveyed),vn.empty(this.stated)}appendRibbon(e,t,i,n,s){this.appendPath(e.points.map(a=>ni(a.lat,a.lng,t,i)),e.widthM,n,s)}appendPath(e,t,i,n){const s=this.resample(e);if(s.length<2)return;const a=Math.max(.5,t/2),o=n.positions.length/3;for(let c=0;c<s.length;c++){const l=s[Math.max(0,c-1)],h=s[Math.min(s.length-1,c+1)];let u=h.x-l.x,d=h.z-l.z;const f=Math.hypot(u,d);f<1e-6?(u=1,d=0):(u/=f,d/=f);const p=-d*a,v=u*a,m={x:s[c].x+p,z:s[c].z+v},g={x:s[c].x-p,z:s[c].z-v};n.positions.push(m.x,i(m.x,m.z)+vn.LIFT_M,m.z,g.x,i(g.x,g.z)+vn.LIFT_M,g.z)}for(let c=0;c<s.length-1;c++){const l=o+c*2;n.indices.push(l,l+2,l+1,l+1,l+2,l+3)}}meshOf(e,t,i){if(t.indices.length===0)return;const n=new ot;n.setAttribute("position",new tt(new Float32Array(t.positions),3)),n.setIndex(new tt(new Uint32Array(t.indices),1)),n.computeVertexNormals();const s=vn.ALBEDO[e],a=new Vr({color:new se(s[0],s[1],s[2]),transparent:i,opacity:i?vn.CONTEMPORARY_OPACITY:1,fog:!0,polygonOffset:!0,polygonOffsetFactor:-2,polygonOffsetUnits:-2}),o=new De(n,a);return o.name=`roads ${e}`,o.receiveShadow=!0,o.castShadow=!1,o}resample(e){const t=[];for(let n=0;n<e.length-1;n++){const s=e[n],a=e[n+1],o=Math.hypot(a.x-s.x,a.z-s.z),c=Math.max(1,Math.ceil(o/vn.STEP_M));for(let l=0;l<c;l++){const h=l/c;t.push({x:s.x+(a.x-s.x)*h,z:s.z+(a.z-s.z)*h})}}const i=e[e.length-1];return i&&t.push({x:i.x,z:i.z}),t}}const b5=18,_5=.55,S5=.5,w5=.4,E5=2,A5=`
|
|
6246
6246
|
attribute float aSpeed;
|
|
6247
6247
|
uniform float uTime;
|
|
6248
6248
|
uniform float uOverallSpeed;
|
|
@@ -6922,7 +6922,7 @@ void main()
|
|
|
6922
6922
|
// stays what it always was for the optional artifacts.
|
|
6923
6923
|
gl_FragColor = vec4(dazzle + artifactsContribution * uOpacity, 1.0);
|
|
6924
6924
|
}
|
|
6925
|
-
`;let Yc;function O5(){if(Yc)return Yc;const r=256,e=document.createElement("canvas");e.width=r,e.height=r;const t=e.getContext("2d");t.fillStyle="rgba(60,60,60,1)",t.fillRect(0,0,r,r);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,a,o]of i){const c=t.createRadialGradient(n*r,s*r,0,n*r,s*r,a*r);c.addColorStop(0,`rgba(200,200,200,${o})`),c.addColorStop(1,"rgba(200,200,200,0)"),t.fillStyle=c,t.fillRect(0,0,r,r)}return Yc=new Ls(e),Yc}function N5(){const r={uTime:{value:0},uResolution:{value:new xe(1,1)},uLensPosition:{value:new xe(0,0)},uColorGain:{value:new se(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 se(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:O5()}},e=new ct({uniforms:r,vertexShader:P5,fragmentShader:L5,transparent:!0,depthWrite:!1,depthTest:!1,blending:Ni,fog:!1,name:"LensFlareShader"}),t=new De(new
|
|
6925
|
+
`;let Yc;function O5(){if(Yc)return Yc;const r=256,e=document.createElement("canvas");e.width=r,e.height=r;const t=e.getContext("2d");t.fillStyle="rgba(60,60,60,1)",t.fillRect(0,0,r,r);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,a,o]of i){const c=t.createRadialGradient(n*r,s*r,0,n*r,s*r,a*r);c.addColorStop(0,`rgba(200,200,200,${o})`),c.addColorStop(1,"rgba(200,200,200,0)"),t.fillStyle=c,t.fillRect(0,0,r,r)}return Yc=new Ls(e),Yc}function N5(){const r={uTime:{value:0},uResolution:{value:new xe(1,1)},uLensPosition:{value:new xe(0,0)},uColorGain:{value:new se(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 se(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:O5()}},e=new ct({uniforms:r,vertexShader:P5,fragmentShader:L5,transparent:!0,depthWrite:!1,depthTest:!1,blending:Ni,fog:!1,name:"LensFlareShader"}),t=new De(new Yi(2,2),e);return t.frustumCulled=!1,t.renderOrder=20,{mesh:t,uniforms:r}}class yi{static MAX_HALF_ANGLE_DEG=80;static MAX_CUBE_FACE=2048;static SAMPLES=4;cubeTarget;cubeCamera;cubeMaterial;cubeRotation=new Ye;target;overlayTarget;overlayCubeTarget;quadScene=new Is;quadCamera=new zn(-1,1,1,-1,0,1);material;width;height;constructor(e,t){this.width=Math.max(1,e),this.height=Math.max(1,t),this.target=new ai(this.width,this.height,{type:Wt,samples:yi.SAMPLES}),this.overlayTarget=new ai(this.width,this.height,{type:Wt,samples:yi.SAMPLES}),this.material=new ct({uniforms:{...Hi,uSource:{value:this.target.texture},uHalfFovRad:{value:.5236},uAspect:{value:this.width/this.height},uSrcTanHalfFovY:{value:1},uResolution:{value:new xe(this.width,this.height)},uOverlay:{value:this.overlayTarget.texture},uMode:{value:un.Finished}},vertexShader:`
|
|
6926
6926
|
varying vec2 vNdc;
|
|
6927
6927
|
void main() {
|
|
6928
6928
|
vNdc = position.xy;
|
|
@@ -6968,7 +6968,7 @@ void main()
|
|
|
6968
6968
|
// when the frame is on its way into a longer exposure, which has to add up light.
|
|
6969
6969
|
${Io}
|
|
6970
6970
|
}
|
|
6971
|
-
`,depthTest:!1,depthWrite:!1}),this.quadScene.add(new De(new
|
|
6971
|
+
`,depthTest:!1,depthWrite:!1}),this.quadScene.add(new De(new Yi(2,2),this.material))}directionFor(e,t,i){const n=this.width/this.height,s=i/2*Math.PI/180,a=e*n*s,o=t*s,c=Math.hypot(a,o);if(c<1e-6)return{x:0,y:0,z:-1};const l=Math.sin(c);return{x:a/c*l,y:o/c*l,z:-Math.cos(c)}}static ndcFor(e,t,i){const n=Math.hypot(e.x,e.y,e.z);if(n===0||e.z>=n)return;const s=t/2*Math.PI/180,a=Math.acos(Math.min(1,-e.z/n)),o=Math.sin(a),c=o<1e-9?1:a/o,l=e.x/n*c,h=e.y/n*c;return{ndcX:l/(i*s),ndcY:h/s}}static cornerHalfAngleDeg(e,t){return e/2*Math.hypot(t,1)}static supports(e,t){return this.cornerHalfAngleDeg(e,t)<=this.MAX_HALF_ANGLE_DEG}resize(e,t){this.width=Math.max(1,e),this.height=Math.max(1,t),this.target.setSize(this.width,this.height),this.overlayTarget.setSize(this.width,this.height),this.material.uniforms.uResolution.value.set(this.width,this.height),this.material.uniforms.uAspect.value=this.width/this.height}render(e,t,i,n,s,a,o,c,l){const h=this.width/this.height;if(!yi.supports(n,h)){o?.(!0),this.renderThroughCube(e,t,i,n,a,c,l),o?.(!1);return}this.material.uniforms.uHalfFovRad.value=n/2*Math.PI/180,this.material.uniforms.uSrcTanHalfFovY.value=this.sourceTanHalfFovY(n,h);const u=i.fov;i.fov=this.sourceFovDeg(n,h),i.updateProjectionMatrix(),s?.();const d=e.getRenderTarget();e.setRenderTarget(this.target),e.render(t,i),a&&(yi.clearTransparent(e,this.overlayTarget),a(i)),e.setRenderTarget(d),i.fov=u,i.updateProjectionMatrix(),this.resample(e,this.quadScene.children[0],this.material,d,l)}resample(e,t,i,n,s){const a=t.material;t.material=i,s?(i.uniforms.uMode.value=un.Scene,e.setRenderTarget(s.scene),e.render(this.quadScene,this.quadCamera),i.uniforms.uMode.value=un.Overlay,e.setRenderTarget(s.overlay),e.render(this.quadScene,this.quadCamera),e.setRenderTarget(n)):(i.uniforms.uMode.value=un.Finished,e.setRenderTarget(n),e.render(this.quadScene,this.quadCamera)),t.material=a}static clearTransparent(e,t,i){const n=e.getClearColor(yi.clearScratch),s=e.getClearAlpha(),a=e.autoClear;e.setRenderTarget(t,i),e.setClearColor(0,0),e.clear(!0,!0,!0),e.setClearColor(n,s),t.samples>0&&(e.autoClear=!1,e.render(yi.nothing,yi.nothingCamera),e.autoClear=a)}static nothing=new Is;static nothingCamera=new zn;static clearScratch=new se;renderThroughCube(e,t,i,n,s,a,o){const c=n*Math.PI/180,l=Math.min(yi.MAX_CUBE_FACE,e.capabilities.maxCubemapSize,Math.max(256,Math.ceil(this.height/c*Math.PI/2))),h={type:Wt,minFilter:rt,magFilter:rt,generateMipmaps:!1};!this.cubeTarget||!this.cubeCamera||!this.cubeMaterial||!this.overlayCubeTarget?(this.cubeTarget=new qo(l,h),this.overlayCubeTarget=new qo(l,h),this.cubeCamera=new P0(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),u.updateMatrixWorld(),u.coordinateSystem!==e.coordinateSystem&&(u.coordinateSystem=e.coordinateSystem,u.updateCoordinateSystem());const d=e.getRenderTarget(),f=e.shadowMap.autoUpdate,p=this.forwardScratch.set(0,0,-1).applyQuaternion(i.getWorldQuaternion(this.quaternionScratch)),v=yi.cornerHalfAngleDeg(n,this.width/this.height);u.children.forEach((_,b)=>{const M=_;yi.faceSeen(M,p,v)&&((M.near!==i.near||M.far!==i.far)&&(M.near=i.near,M.far=i.far,M.updateProjectionMatrix()),e.setRenderTarget(this.cubeTarget,b),e.render(t,M),s&&(yi.clearTransparent(e,this.overlayCubeTarget,b),s(M)),e.shadowMap.autoUpdate=!1)}),e.shadowMap.autoUpdate=f;const m=this.cubeMaterial.uniforms;m.uHalfFovRad.value=c/2,m.uAspect.value=this.width/this.height,m.uCameraRotation.value.setFromMatrix4(i.matrixWorld);const g=this.quadScene.children[0];this.resample(e,g,this.cubeMaterial,d,{scene:this.target,overlay:this.overlayTarget}),e.setRenderTarget(this.target),a?.(),this.resample(e,g,this.copyMaterial(),d,o)}copy;copyMaterial(){return this.copy??=new ct({uniforms:{...Hi,uSource:{value:this.target.texture},uOverlay:{value:this.overlayTarget.texture},uMode:{value:un.Finished}},vertexShader:`
|
|
6972
6972
|
varying vec2 vUv;
|
|
6973
6973
|
void main() {
|
|
6974
6974
|
vUv = position.xy * 0.5 + 0.5;
|
|
@@ -7101,7 +7101,7 @@ void main()
|
|
|
7101
7101
|
vec4 overlay = throughLens(uOverlay, uOverlayDepth);
|
|
7102
7102
|
${Io}
|
|
7103
7103
|
}
|
|
7104
|
-
`,depthTest:!1,depthWrite:!1}),this.quadScene.add(new De(new
|
|
7104
|
+
`,depthTest:!1,depthWrite:!1}),this.quadScene.add(new De(new Yi(2,2),this.material))}resize(e,t){this.width=Math.max(1,e),this.height=Math.max(1,t),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(e,t,i,n){const s=this.material.uniforms;s.uApertureMm2.value=e*e/Math.max(.1,t),s.uFocusDistance.value=Math.max(0,i),s.uFocalLengthMm.value=e,s.uPixelsPerMm.value=this.height/Math.max(.1,n)}render(e,t,i,n,s){const a=this.material.uniforms;a.uNear.value=i.near,a.uFar.value=i.far;const o=e.getRenderTarget();e.setRenderTarget(this.target),e.clear(),e.render(t,i),n&&(yi.clearTransparent(e,this.overlayTarget),n()),s?(a.uMode.value=un.Scene,e.setRenderTarget(s.scene),e.render(this.quadScene,this.quadCamera),a.uMode.value=un.Overlay,e.setRenderTarget(s.overlay),e.render(this.quadScene,this.quadCamera)):(a.uMode.value=un.Finished,e.setRenderTarget(o),e.render(this.quadScene,this.quadCamera)),e.setRenderTarget(o)}dispose(){this.target.depthTexture?.dispose(),this.target.dispose(),this.overlayTarget.depthTexture?.dispose(),this.overlayTarget.dispose(),this.material.dispose()}}class $0{static SAMPLES=4;scene;overlay;quadScene=new Is;quadCamera=new zn(-1,1,1,-1,0,1);material;constructor(e,t){const i={type:Wt,samples:$0.SAMPLES};this.scene=new ai(Math.max(1,e),Math.max(1,t),i),this.overlay=new ai(Math.max(1,e),Math.max(1,t),i),this.material=new ct({uniforms:{...Hi,uSource:{value:this.scene.texture},uOverlay:{value:this.overlay.texture},uMode:{value:un.Finished}},vertexShader:`
|
|
7105
7105
|
varying vec2 vUv;
|
|
7106
7106
|
void main() {
|
|
7107
7107
|
vUv = position.xy * 0.5 + 0.5;
|
|
@@ -7119,7 +7119,7 @@ void main()
|
|
|
7119
7119
|
vec4 overlay = texture2D(uOverlay, vUv);
|
|
7120
7120
|
${Io}
|
|
7121
7121
|
}
|
|
7122
|
-
`,depthTest:!1,depthWrite:!1}),this.quadScene.add(new De(new Xi(2,2),this.material))}render(e,t,i,n,s,a){const o=e.getRenderTarget(),c=a??{scene:this.scene,overlay:this.overlay};e.setRenderTarget(c.scene),e.render(t,i),s?.(),(n||a)&&(yi.clearTransparent(e,c.overlay),n?.()),e.setRenderTarget(o),!a&&(this.material.uniforms.uMode.value=un.Finished,e.render(this.quadScene,this.quadCamera))}resize(e,t){this.scene.setSize(Math.max(1,e),Math.max(1,t)),this.overlay.setSize(Math.max(1,e),Math.max(1,t))}dispose(){this.scene.dispose(),this.overlay.dispose(),this.material.dispose(),this.quadScene.children[0].geometry.dispose()}}class mt{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(e,t){this.maxRatio=mt.clamp(e),this.ratio=this.maxRatio,this.timer=t?zl.create(t):void 0}get pixelRatio(){return this.ratio}static SETTLE_MS=400;static SUSTAINED_MS=100;lastEditMs=-1/0;editStreakStartMs=-1/0;wasChanging=!1;noteChange(e){e-this.lastEditMs>mt.SETTLE_MS&&(this.editStreakStartMs=e),this.lastEditMs=e}changing(e){return e-this.lastEditMs<=mt.SETTLE_MS&&this.lastEditMs-this.editStreakStartMs>=mt.SUSTAINED_MS}ratioFor(e,t){return this.changing(e)?this.wasChanging?(this.update(e,t),this.ratio):(this.wasChanging=!0,this.reset(),this.ratio):(this.wasChanging=!1,this.maxRatio)}get timesGpu(){return this.timer!==void 0}set maximum(e){this.maxRatio=mt.clamp(e),this.ratio>this.maxRatio&&(this.ratio=this.maxRatio),this.ratio<this.minimum&&(this.ratio=Math.min(this.maxRatio,this.minimum))}get minimum(){const e=Math.floor(this.maxRatio*mt.MIN_SHARE_OF_DISPLAY/mt.STEP)*mt.STEP;return Math.max(mt.MIN_RATIO,e)}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(e,t){const i=this.timer?.poll();if(!(this.timer&&i===void 0))return i!==void 0?this.followGpu(e,i):this.followIntervals(e,t)}followGpu(e,t){if(t>mt.GPU_LATE_MS)return this.lower(e,mt.LOWER_COOLDOWN_MS);if(t<mt.GPU_ROOM_MS)return this.raise(e,mt.RAISE_COOLDOWN_MS)}followIntervals(e,t){if(!(t>0)||t>1e3)return;this.intervalMs=this.intervalMs===void 0?t:this.intervalMs*.9+t*.1;const i=this.intervalMs>mt.INTERVAL_LATE_MS;if(this.probe){if(i)return this.ratio=this.probe.ratioBefore,this.probe=void 0,this.lastChangeMs=e,this.nextProbeMs=e+mt.PROBE_BACKOFF_MS,this.ratio;e-this.probe.sinceMs>=mt.PROBE_WATCH_MS&&(this.probe=void 0,this.nextProbeMs=e+mt.PROBE_EVERY_MS);return}if(i){const n=this.lower(e,mt.LOWER_COOLDOWN_MS);return n!==void 0&&(this.nextProbeMs=e+mt.PROBE_EVERY_MS),n}if(this.ratio<this.maxRatio&&e>=this.nextProbeMs&&e-this.lastChangeMs>=mt.RAISE_COOLDOWN_MS){const n=this.ratio,s=this.raise(e,0);return s!==void 0&&(this.probe={sinceMs:e,ratioBefore:n}),s}}lower(e,t){if(!(this.ratio<=this.minimum||e-this.lastChangeMs<t))return this.ratio=Math.max(this.minimum,mt.clamp(this.ratio-mt.STEP)),this.lastChangeMs=e,this.ratio}raise(e,t){if(!(this.ratio>=this.maxRatio||e-this.lastChangeMs<t))return this.ratio=Math.min(this.maxRatio,mt.clamp(this.ratio+mt.STEP)),this.lastChangeMs=e,this.ratio}static clamp(e){return Number.isFinite(e)?Math.max(mt.MIN_RATIO,Math.round(e/mt.STEP)*mt.STEP):mt.MIN_RATIO}}class zl{constructor(e,t){this.gl=e,this.extension=t}static IN_FLIGHT_MAX=8;static create(e){if(!(e instanceof WebGL2RenderingContext))return;const t=e.getExtension("EXT_disjoint_timer_query_webgl2");return t?new zl(e,t):void 0}pending=[];active;smoothedMs;begin(){if(!(this.active||this.pending.length>=zl.IN_FLIGHT_MAX))try{const e=this.gl.createQuery();if(!e)return;this.gl.beginQuery(this.extension.TIME_ELAPSED_EXT,e),this.active=e}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 e=this.gl;try{for(let t=0;t<this.pending.length;t++){const i=this.pending[t];if(!e.getQueryParameter(i,e.QUERY_RESULT_AVAILABLE))continue;if(!e.getParameter(this.extension.GPU_DISJOINT_EXT)){const s=e.getQueryParameter(i,e.QUERY_RESULT)/1e6;this.smoothedMs=this.smoothedMs===void 0?s:this.smoothedMs*.8+s*.2}e.deleteQuery(i),this.pending.splice(t,1),t--}}catch{this.pending.length=0}return this.smoothedMs}reset(){this.smoothedMs=void 0}}class ft{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 e=ft.ICE_INDEX_RED,t=Math.sqrt((4-e*e)/3);return Math.asin(Math.min(1,t))*180/Math.PI}static minimumDeviationDeg(e,t){const i=e*Math.PI/180,n=t*Math.sin(i/2);return n>1?Number.NaN:(2*Math.asin(n)-i)*180/Math.PI}static effectiveIndex(e,t){const i=t*Math.PI/180,n=Math.cos(i);return n<=0?Number.POSITIVE_INFINITY:Math.sqrt(e*e-Math.sin(i)**2)/n}static parheliaAzimuthDeg(e,t=ft.ICE_INDEX_RED){const i=ft.minimumDeviationDeg(ft.SIDE_PRISM_ANGLE_DEG,ft.effectiveIndex(t,e));return Number.isFinite(i)?i:void 0}static parheliaDistanceDeg(e,t=ft.ICE_INDEX_RED){const i=ft.parheliaAzimuthDeg(e,t);if(i===void 0)return;const n=e*Math.PI/180,s=Math.sin(n)**2,a=Math.cos(n)**2*Math.cos(i*Math.PI/180);return Math.acos(Math.max(-1,Math.min(1,s+a)))*180/Math.PI}static get PLATE_END_FACE_LIMIT_DEG(){const e=ft.ICE_INDEX_RED;return Math.asin(Math.min(1,Math.sqrt(e*e-1)))*180/Math.PI}static circumzenithalAltitudeDeg(e,t=ft.ICE_INDEX_RED){if(e<0||e>90-ft.PLATE_END_FACE_LIMIT_DEG)return;const i=Math.cos(e*Math.PI/180),n=Math.sqrt(t*t-i*i);if(!(n>=1))return Math.asin(n)*180/Math.PI}static DECK_HEIGHT_M=8e3;static deckLitUntilDeg(e){return Math.acos(6371e3/(6371e3+Math.max(0,e)))*180/Math.PI}static halo22(){return ft.ringOf("halo22",ft.SIDE_PRISM_ANGLE_DEG)}static halo46(){return ft.ringOf("halo46",ft.END_PRISM_ANGLE_DEG)}static ringOf(e,t){const i=ft.minimumDeviationDeg(t,ft.ICE_INDEX_RED),n=ft.minimumDeviationDeg(t,ft.ICE_INDEX_BLUE);return{id:e,angleDeg:(i+n)/2,redAngleDeg:i,blueAngleDeg:n}}static strength(e,t,i=90,n=0){const s=Math.max(0,Math.min(1,e)),a=Math.max(0,1-Math.max(0,Math.min(1,t))),o=i>=0?1:n<=0?0:Math.max(0,1+i/n);return s*a*o}static formsAt(e,t=0){if(e<=-t)return[];const i=[ft.halo22(),ft.halo46()],n=e>0?ft.parheliaDistanceDeg(e):void 0;n!==void 0&&i.push({id:"parhelia",angleDeg:n,redAngleDeg:n,blueAngleDeg:ft.parheliaDistanceDeg(e,ft.ICE_INDEX_BLUE)}),i.push({id:"tangentArc",angleDeg:ft.halo22().angleDeg}),e>0&&i.push({id:"parhelicCircle",angleDeg:e});const s=ft.circumzenithalAltitudeDeg(e);return s!==void 0&&i.push({id:"circumzenithal",angleDeg:s}),e>ft.PLATE_END_FACE_LIMIT_DEG&&i.push({id:"circumhorizontal"}),e<ft.PILLAR_MAX_SOURCE_ALTITUDE_DEG&&i.push({id:"pillar"}),i}static PILLAR_MAX_SOURCE_ALTITUDE_DEG=20}class rn{static get WATER_INDEX_RED(){return bi.indexAt(bi.RED_NM)}static get WATER_INDEX_BLUE(){return bi.indexAt(bi.BLUE_NM)}static radiusDeg(e,t){const i=(t*t-1)/(e*e-1);if(i<0||i>1)return Number.NaN;const n=Math.acos(Math.sqrt(i)),s=Math.asin(Math.sin(n)/t),a=2*(n-s)+(e-1)*(Math.PI-2*s),o=2*Math.PI;let c=a%o;return c<0&&(c+=o),c>Math.PI&&(c=o-c),180-c*180/Math.PI}static primary(){return rn.bowOf("primary",2,0)}static secondary(){return rn.bowOf("secondary",3,0)}static bowOf(e,t,i){const n=rn.radiusDeg(t,rn.WATER_INDEX_RED),s=rn.radiusDeg(t,rn.WATER_INDEX_BLUE),a=(n+s)/2;return{id:e,radiusDeg:a,redRadiusDeg:n,violetRadiusDeg:s,topAltitudeDeg:a-i}}static alexandersBandDeg(){return{fromDeg:rn.primary().redRadiusDeg,toDeg:rn.secondary().redRadiusDeg}}static formsAt(e){return e<0?[]:[rn.bowOf("primary",2,e),rn.bowOf("secondary",3,e)].filter(t=>t.topAltitudeDeg>0)}static FULL_MOON_MAGNITUDE=-12.7;static moonlightShare(e){return Math.min(1,10**(-.4*(e-rn.FULL_MOON_MAGNITUDE)))}static strength(e,t,i){if(i<=0)return 0;const n=Math.max(0,Math.min(1,e)),s=Math.max(0,1-Math.max(0,Math.min(1,t)));return n*s}}class on{constructor(e){this.radius=e;const t=on.SEGMENTS*on.VERTICES_PER_SEGMENT;this.positions=new Float32Array(t*3),this.colors=new Float32Array(t*3);const i=new ot;i.setAttribute("position",new tt(this.positions,3)),i.setAttribute("color",new tt(this.colors,3)),i.setDrawRange(0,0),this.object=new De(i,new bn({vertexColors:!0,transparent:!0,blending:Ni,depthWrite:!1,fog:!1,side:Qi})),this.object.frustumCulled=!1}static POINTS=24;static SEGMENTS=on.POINTS-1;static ACROSS=3;static VERTICES_PER_SEGMENT=(on.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(e,t,i){this.head=e&&li(e.altitudeDeg,e.azimuthDeg,1),this.tip=t&&li(t.altitudeDeg,t.azimuthDeg,1),this.brightness=i,this.rebuild()}rebuild(){const e=this.object.geometry,t=this.head,i=this.tip;if(!t||!i||this.brightness<=0){e.setDrawRange(0,0);return}const n=this.angleBetween(t,i);if(n<=0){e.setDrawRange(0,0);return}const s=n*on.SPREAD_FRACTION*Math.PI/180,a=h=>this.scale(this.slerp(t,i,h),this.radius),o=h=>this.radius*(on.HEAD_HALF_WIDTH_DEG*Math.PI/180+s*h),c=h=>this.brightness*(1-h)**on.FADE_POWER;let l=0;for(let h=1;h<on.POINTS;h++){const u=(h-1)/on.SEGMENTS,d=h/on.SEGMENTS;l=this.pushBand(l,a(u),a(d),o(u),o(d),c(u),c(d))}e.setDrawRange(0,l),e.getAttribute("position").needsUpdate=!0,e.getAttribute("color").needsUpdate=!0}pushBand(e,t,i,n,s,a,o){const c=this.normalise(this.cross(this.normalise(t),this.normalise(this.subtract(i,t))));for(let l=0;l<on.ACROSS-1;l++){const h=l-1,u=l,d=this.across(t,c,n,h),f=this.across(i,c,s,h),p=this.across(t,c,n,u),v=this.across(i,c,s,u),m=(g,_)=>g===0?_:0;e=this.push(e,d,m(h,a)),e=this.push(e,f,m(h,o)),e=this.push(e,p,m(u,a)),e=this.push(e,f,m(h,o)),e=this.push(e,v,m(u,o)),e=this.push(e,p,m(u,a))}return e}across(e,t,i,n){return{x:e.x+t.x*i*n,y:e.y+t.y*i*n,z:e.z+t.z*i*n}}push(e,t,i){const n=e*3;this.positions[n]=t.x,this.positions[n+1]=t.y,this.positions[n+2]=t.z;const s=Ae.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,e+1}slerp(e,t,i){const n=this.angleBetweenRadians(e,t);if(n<1e-9)return e;const s=Math.sin(n),a=Math.sin((1-i)*n)/s,o=Math.sin(i*n)/s;return{x:e.x*a+t.x*o,y:e.y*a+t.y*o,z:e.z*a+t.z*o}}angleBetween(e,t){return this.angleBetweenRadians(e,t)*180/Math.PI}angleBetweenRadians(e,t){const i=e.x*t.x+e.y*t.y+e.z*t.z;return Math.acos(Math.min(1,Math.max(-1,i)))}scale(e,t){return{x:e.x*t,y:e.y*t,z:e.z*t}}subtract(e,t){return{x:e.x-t.x,y:e.y-t.y,z:e.z-t.z}}cross(e,t){return{x:e.y*t.z-e.z*t.y,y:e.z*t.x-e.x*t.z,z:e.x*t.y-e.y*t.x}}normalise(e){const t=Math.hypot(e.x,e.y,e.z)||1;return{x:e.x/t,y:e.y/t,z:e.z/t}}dispose(){this.object.geometry.dispose(),this.object.material.dispose()}}class F5{object=new Dt;radius;tiers;drawn=[];constructor(e){this.radius=e,this.object.name="satellites",this.tiers=Co.map(t=>{const i=new xs(new ot,st.material(t.size));return st.track(i),i.frustumCulled=!1,this.object.add(i),i})}set(e,t,i,n){const s=this.tiers.map(()=>[]);this.drawn=[];for(const a of e){if(a.magnitude>t)continue;const o=i(a.position);if(o<=0)continue;const c=a.magnitude-2.5*Math.log10(o);if(c>t)continue;const l=bo(c,t),h=I1(l),{x:u,y:d,z:f}=li(a.position.altitudeDeg,a.position.azimuthDeg,this.radius),[p,v,m]=n(a.position,c);s[h].push({x:u,y:d,z:f,r:p,g:v,b:m,seed:a.norad*.6180339887%1}),this.drawn.push({satellite:a,direction:new R(u,d,f).normalize()})}this.tiers.forEach((a,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}),a.geometry.dispose();const d=new ot;d.setAttribute("position",new tt(l,3)),d.setAttribute("color",new tt(h,3)),d.setAttribute("seed",new tt(u,1)),a.geometry=d})}get count(){return this.drawn.length}nearest(e,t){let i,n=t;for(const s of this.drawn){const a=s.direction.dot(e);a>n&&(n=a,i=s.satellite)}return i}dispose(){for(const e of this.tiers)e.geometry.dispose(),e.material.dispose();this.object.removeFromParent(),this.drawn=[]}}class sh{constructor(e){this.state=e}next(){this.state=this.state+1831565813|0;let e=this.state;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}between(e,t){return e+this.next()*(t-e)}}class Oa{static MIN_DURATION_MS=250;static MAX_DURATION_MS=1400;static schedule(e){const{ratePerHour:t,durationMs:i,velocityKmS:n,seed:s}=e;if(t<=0||i<=0)return[];const a=t*i/36e5,o=new sh(s),c=Math.floor(a),l=c+(o.next()<a-c?1:0),h=[];for(let u=0;u<l;u++){const d=Math.min(1,Math.max(0,(n-20)/52)),f=Oa.MAX_DURATION_MS-d*(Oa.MAX_DURATION_MS-Oa.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(e,t){return e.filter(i=>t>=i.t&&t<=i.t+i.durationMs).map(i=>({meteor:i,progress:(t-i.t)/i.durationMs}))}}class Ks{object=new Dt;radius;core;glow;flashKey;static CORE_WIDTH_DEG=.06;static GLOW_WIDTH_DEG=.5;static SEGMENTS=28;static CORE_RELATIVE=1e3;constructor(e){this.radius=e,this.object.name="lightning-bolt",this.core=new bn({color:15659775,transparent:!0,opacity:0,blending:Ni,depthWrite:!1,fog:!1}),this.glow=new bn({color:10466559,transparent:!0,opacity:0,blending:Ni,depthWrite:!1,fog:!1}),this.object.visible=!1,this.object.renderOrder=5.95}set(e,t,i){if(!e||!e.cloudToGround||t<=.01){this.object.visible=!1;return}const n=`${e.channelSeed}:${Math.round(i)}`;n!==this.flashKey&&this.build(e,i,n),this.core.color.setHex(15659775).multiplyScalar(Ks.CORE_RELATIVE*Math.min(1,t*1.4)),this.glow.color.setHex(10466559).multiplyScalar(.1*Ks.CORE_RELATIVE*t*.35),this.core.opacity=1,this.glow.opacity=1,this.object.visible=!0}build(e,t,i){this.flashKey=i;for(const l of[...this.object.children])l.geometry.dispose(),this.object.remove(l);const n=new sh(e.channelSeed),s=Math.atan2(t,e.distanceM)*180/Math.PI,a=this.channel(n,e.azimuthDeg,s,0,1),o=[a],c=1+Math.floor(n.next()*2);for(let l=0;l<c;l++){const h=a[Math.floor(n.between(.15,.5)*a.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 De(this.ribbon(l,Ks.GLOW_WIDTH_DEG),this.glow)),this.object.add(new De(this.ribbon(l,Ks.CORE_WIDTH_DEG),this.core))}channel(e,t,i,n,s){const a=[],o=i-n;let c=t;for(let l=0;l<=Ks.SEGMENTS;l++){const h=i-o*l/Ks.SEGMENTS;a.push({azimuthDeg:c,altitudeDeg:h}),c+=e.between(-1,1)*o*.06*s}return a}ribbon(e,t){const i=new Float32Array(e.length*2*3),n=[],s=this.radius*Math.tan(t*Math.PI/180)/2,a=e.map(c=>{const{x:l,y:h,z:u}=li(c.altitudeDeg,c.azimuthDeg,this.radius);return new R(l,h,u)});a.forEach((c,l)=>{const h=a[Math.min(l+1,a.length-1)],u=a[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<a.length-1){const p=l*2;n.push(p,p+1,p+2,p+1,p+3,p+2)}});const o=new ot;return o.setAttribute("position",new tt(i,3)),o.setIndex(n),o}dispose(){for(const e of this.object.children)e.geometry.dispose();this.core.dispose(),this.glow.dispose(),this.object.removeFromParent()}}class di{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(e){const t=new sh(e.seed),i=[],{minS:n,maxS:s}=di.intervalFor(e.intensity??.5);let a=t.between(0,s)*1e3;for(;a<e.durationMs;){const o=t.next()<di.CLOUD_TO_GROUND_FRACTION,c=di.MIN_DISTANCE_M,l=di.MAX_DISTANCE_M,h=Math.sqrt(t.between(c*c,l*l)),u=o?1+Math.floor(t.next()*4):1,d=[];let f=0;for(let p=0;p<u;p++)d.push({offsetMs:f,intensity:p===0?1:t.between(.4,.9)}),f+=di.INTERSTROKE_MS*t.between(.5,1.6);i.push({t:a,azimuthDeg:t.between(0,360),distanceM:h,cloudToGround:o,strokes:d,channelSeed:Math.floor(t.next()*2**31)}),a+=t.between(n,s)*1e3}return i}static intervalFor(e){const t=Math.min(1,Math.max(0,(e-.5)/.5));return{minS:di.MIN_INTERVAL_S-t*(di.MIN_INTERVAL_S-di.SEVERE_MIN_INTERVAL_S),maxS:di.MAX_INTERVAL_S-t*(di.MAX_INTERVAL_S-di.SEVERE_MAX_INTERVAL_S)}}static brightnessAt(e,t){let i=0;for(const n of e.strokes){const s=t-e.t-n.offsetMs;s<0||s>di.STROKE_DECAY_MS*6||(i+=n.intensity*Math.exp(-s/di.STROKE_DECAY_MS))}return Math.min(1,i)}static endOf(e){const t=e.strokes[e.strokes.length-1];return e.t+t.offsetMs+di.STROKE_DECAY_MS*6}static thunderDelayMs(e){return e.distanceM/di.SOUND_SPEED_M_S*1e3}}class $i{static RED_NM=656.3;static BLUE_NM=435.8;static ANCHOR_RED=1.3067;static ANCHOR_BLUE=1.317;static B=($i.ANCHOR_BLUE-$i.ANCHOR_RED)/(1/($i.BLUE_NM*$i.BLUE_NM)-1/($i.RED_NM*$i.RED_NM));static A=$i.ANCHOR_RED-$i.B/($i.RED_NM*$i.RED_NM);static indexAt(e){return $i.A+$i.B/(e*e)}}class $o{normals=new Float64Array(24);offsets=new Float64Array(8);radius=1;set(e,t,i,n,s,a){let o=0,c=0,l=0;Math.abs(i)<.9?(o=-t,c=e,l=0):(o=0,c=-i,l=t);const h=Math.hypot(o,c,l)||1;o/=h,c/=h,l/=h;const u=t*l-i*c,d=i*o-e*l,f=e*c-t*o,p=s/2,v=a/2;for(let m=0;m<6;m++){const g=n+m*Math.PI/3,_=Math.cos(g),b=Math.sin(g);this.normals[m*3]=o*_+u*b,this.normals[m*3+1]=c*_+d*b,this.normals[m*3+2]=l*_+f*b,this.offsets[m]=p}this.normals[18]=e,this.normals[19]=t,this.normals[20]=i,this.offsets[6]=v,this.normals[21]=-e,this.normals[22]=-t,this.normals[23]=-i,this.offsets[7]=v,this.radius=Math.hypot(p,v)}get aimRadius(){return this.radius}trace(e,t,i,n,s,a,o){let c=-t,l=e,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=t*h-i*l,f=i*c-e*h,p=e*l-t*c,v=c*n+d*s-e*this.radius*2,m=l*n+f*s-t*this.radius*2,g=h*n+p*s-i*this.radius*2;let _=-1,b=-1/0,M=1/0;for(let J=0;J<8;J++){const ie=this.normals[J*3],re=this.normals[J*3+1],Ve=this.normals[J*3+2],Je=ie*e+re*t+Ve*i,qe=this.offsets[J]-(ie*v+re*m+Ve*g);if(Je>1e-9){const q=qe/Je;q<M&&(M=q)}else if(Je<-1e-9){const q=qe/Je;q>b&&(b=q,_=J)}else if(qe<0)return 0}if(_<0||b>=M)return 0;let S=0;const w=this.normals[_*3],T=this.normals[_*3+1],x=this.normals[_*3+2],A=-(w*e+T*t+x*i),C=Ol.reflectance(A,1,a);o[S].x=e+2*A*w,o[S].y=t+2*A*T,o[S].z=i+2*A*x,o[S].weight=C,S++;const I=1/a,P=Math.sqrt(Math.max(0,1-I*I*(1-A*A)));let V=I*e+(I*A-P)*w,X=I*t+(I*A-P)*T,L=I*i+(I*A-P)*x,B=v+e*b,k=m+t*b,$=g+i*b,ee=1-C;for(let J=0;J<$o.MAX_BOUNCES&&ee>$o.MIN_WEIGHT;J++){let ie=-1,re=1/0;for(let z=0;z<8;z++){const Te=this.normals[z*3],Ne=this.normals[z*3+1],Ce=this.normals[z*3+2],be=Te*V+Ne*X+Ce*L;if(be<=1e-9)continue;const ke=(this.offsets[z]-(Te*B+Ne*k+Ce*$))/be;ke>1e-9&&ke<re&&(re=ke,ie=z)}if(ie<0)break;const Ve=this.normals[ie*3],Je=this.normals[ie*3+1],qe=this.normals[ie*3+2],q=Ve*V+Je*X+qe*L,ae=a*Math.sqrt(Math.max(0,1-q*q));if(B+=V*re,k+=X*re,$+=L*re,ae<1){const z=Math.sqrt(Math.max(0,1-ae*ae)),Te=Ol.reflectance(q,a,1);if(o[S].x=a*V-(a*q-z)*Ve,o[S].y=a*X-(a*q-z)*Je,o[S].z=a*L-(a*q-z)*qe,o[S].weight=ee*(1-Te),S++,S>=o.length)return S;ee*=Te}const ne=2*q;V-=ne*Ve,X-=ne*Je,L-=ne*qe}return S}static MAX_BOUNCES=6;static MIN_WEIGHT=1e-4}class Bt{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 $o;emergent=Array.from({length:$o.MAX_BOUNCES+2},()=>({x:0,y:0,z:0,weight:0}));tally=new Float32Array(Bt.AZIMUTH_BINS*Bt.ALTITUDE_BINS*3);radiance=new Float32Array(Bt.AZIMUTH_BINS*Bt.ALTITUDE_BINS*3);scratch=new Float32Array(Bt.AZIMUTH_BINS*Bt.ALTITUDE_BINS*3);seed=1;spare=0;hasSpare=!1;altitude=0;tilt=0;alignment=0;traced=0;begin(e,t,i=2654435769){this.seed=i>>>0||1,this.hasSpare=!1,this.tally.fill(0),this.traced=0,this.altitude=e*Math.PI/180,this.alignment=Math.min(1,Math.max(0,t));const n=Bt.WORST_TILT_DEG*(Bt.BEST_TILT_DEG/Bt.WORST_TILT_DEG)**this.alignment;this.tilt=n*Math.PI/180}trace(e){const t=Bt.AZIMUTH_BINS,i=Bt.ALTITUDE_BINS,n=this.tally,s=Bt.SOURCE_RADIUS_DEG*Math.PI/180,a=Math.cos(Bt.UNDEVIATED_DEG*Math.PI/180),o=this.altitude;for(let c=0;c<e;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,_=(this.random()*2-1)*g,b=(this.random()*2-1)*g,M=4*g*g,S=fi.SAMPLES[this.random()*fi.SAMPLES.length|0],w=this.crystal.trace(p,v,m,_,b,$i.indexAt(S.wavelengthNm),this.emergent);for(let T=0;T<w;T++){const x=this.emergent[T],A=Math.hypot(x.x,x.y,x.z);if(A<1e-9||x.weight<=0)continue;const C=x.x/A,I=x.y/A,P=x.z/A;if(C*p+I*v+P*m>a)continue;const V=Math.asin(Math.max(-1,Math.min(1,-P))),X=Math.abs(Math.atan2(-I,-C)),L=Math.min(t-1,X/Math.PI*t|0),k=(Math.min(i-1,(V+Math.PI/2)/Math.PI*i|0)*t+L)*3,$=x.weight*M*fi.SAMPLES.length;n[k]+=$*S.r,n[k+1]+=$*S.g,n[k+2]+=$*S.b}}this.traced+=e}get tracedRays(){return this.traced}harvest(){const e=Bt.AZIMUTH_BINS,t=Bt.ALTITUDE_BINS;return this.toRadiance(e,t),this.smooth(e,t),{width:e,height:t,data:this.radiance,sourceAltitudeDeg:this.altitude*180/Math.PI,alignment:this.alignment,rays:this.traced}}compute(e,t,i,n){return this.begin(e,t,n),this.trace(i),this.harvest()}toRadiance(e,t){const i=2*Math.PI/e,n=Math.max(1,this.traced),s=4*Bt.REFERENCE_MICRONS*Bt.REFERENCE_MICRONS;for(let a=0;a<t;a++){const o=Math.sin(a/t*Math.PI-Math.PI/2),c=Math.sin((a+1)/t*Math.PI-Math.PI/2),l=1/(i*(c-o)*n*s);for(let h=0;h<e;h++){const u=(a*e+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(e,t){const i=this.scratch,n=this.radiance;i.set(n);for(let a=0;a<t;a++){const o=a*e*3;for(let c=0;c<3;c++){let l=i[o+c];for(let h=0;h<e;h++){const u=o+h*3+c,d=h+1<e?i[u+3]:i[u];n[u]=(l+2*i[u]+d)/4,l=i[u]}}}i.set(n);const s=e*3;for(let a=0;a<t;a++){const o=a>0?-s:0,c=a+1<t?s:0,l=a*s;for(let h=l;h<l+s;h++)n[h]=(i[h+o]+2*i[h]+i[h+c])/4}}pickPopulation(){const e=this.random();let t=0;for(const i of Bt.POPULATIONS)if(t+=i.share,e<=t)return i;return Bt.POPULATIONS[Bt.POPULATIONS.length-1]}orient(e,t){const i=this.random()*2*Math.PI;let n=this.random()*2*Math.PI,s=0,a=0,o=1;switch(e.orientation){case"tumbling":{o=this.random()*2-1;const c=Math.sqrt(Math.max(0,1-o*o));s=c*Math.cos(i),a=c*Math.sin(i);break}case"plate":{o=this.spreadAboutAnAxis(t);const c=Math.sqrt(Math.max(0,1-o*o));s=c*Math.cos(i),a=c*Math.sin(i);break}case"column":case"parry":{o=this.spreadAboutAPlane(t);const c=Math.sqrt(Math.max(0,1-o*o));s=c*Math.cos(i),a=c*Math.sin(i),e.orientation==="parry"&&(n=Math.PI/2+this.gaussian()*t);break}}this.crystal.set(s,a,o,n,e.widthMicrons,e.lengthMicrons)}random(){this.seed=this.seed+1831565813>>>0;let e=this.seed;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}spreadAboutAnAxis(e){const t=1/Math.max(1e-6,e*e),i=Math.max(1e-12,this.random()),n=1+Math.log(i+(1-i)*Math.exp(-2*t))/t;return Math.max(-1,Math.min(1,n))}spreadAboutAPlane(e){for(let t=0;t<8;t++){const i=this.gaussian()*e;if(i>=-1&&i<=1)return i}return this.random()*2-1}gaussian(){if(this.hasSpare)return this.hasSpare=!1,this.spare;const e=Math.sqrt(-2*Math.log(Math.max(1e-12,this.random()))),t=2*Math.PI*this.random();return this.spare=e*Math.sin(t),this.hasSpare=!0,e*Math.cos(t)}}class Ci{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(e){this.material.uniforms.uFieldOffset.value.copy(e)}object;material;sky=new Bt;texture;texels;mappedAltitudeDeg=Number.NaN;mappedAlignment=Number.NaN;tracing=!1;everDisplayed=!1;urgent=!1;workHandle;onRepaint;constructor(){const e=Bt.AZIMUTH_BINS,t=Bt.ALTITUDE_BINS;this.texels=new Uint16Array(e*t*4),this.texture=new ca(this.texels,e,t,Ei,Wt),this.texture.minFilter=rt,this.texture.magFilter=rt,this.texture.wrapS=wi,this.texture.wrapT=wi,this.texture.needsUpdate=!0,this.material=new ct({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:Ci.GAIN}},vertexShader:`
|
|
7122
|
+
`,depthTest:!1,depthWrite:!1}),this.quadScene.add(new De(new Yi(2,2),this.material))}render(e,t,i,n,s,a){const o=e.getRenderTarget(),c=a??{scene:this.scene,overlay:this.overlay};e.setRenderTarget(c.scene),e.render(t,i),s?.(),(n||a)&&(yi.clearTransparent(e,c.overlay),n?.()),e.setRenderTarget(o),!a&&(this.material.uniforms.uMode.value=un.Finished,e.render(this.quadScene,this.quadCamera))}resize(e,t){this.scene.setSize(Math.max(1,e),Math.max(1,t)),this.overlay.setSize(Math.max(1,e),Math.max(1,t))}dispose(){this.scene.dispose(),this.overlay.dispose(),this.material.dispose(),this.quadScene.children[0].geometry.dispose()}}class mt{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(e,t){this.maxRatio=mt.clamp(e),this.ratio=this.maxRatio,this.timer=t?zl.create(t):void 0}get pixelRatio(){return this.ratio}static SETTLE_MS=400;static SUSTAINED_MS=100;lastEditMs=-1/0;editStreakStartMs=-1/0;wasChanging=!1;noteChange(e){e-this.lastEditMs>mt.SETTLE_MS&&(this.editStreakStartMs=e),this.lastEditMs=e}changing(e){return e-this.lastEditMs<=mt.SETTLE_MS&&this.lastEditMs-this.editStreakStartMs>=mt.SUSTAINED_MS}ratioFor(e,t){return this.changing(e)?this.wasChanging?(this.update(e,t),this.ratio):(this.wasChanging=!0,this.reset(),this.ratio):(this.wasChanging=!1,this.maxRatio)}get timesGpu(){return this.timer!==void 0}set maximum(e){this.maxRatio=mt.clamp(e),this.ratio>this.maxRatio&&(this.ratio=this.maxRatio),this.ratio<this.minimum&&(this.ratio=Math.min(this.maxRatio,this.minimum))}get minimum(){const e=Math.floor(this.maxRatio*mt.MIN_SHARE_OF_DISPLAY/mt.STEP)*mt.STEP;return Math.max(mt.MIN_RATIO,e)}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(e,t){const i=this.timer?.poll();if(!(this.timer&&i===void 0))return i!==void 0?this.followGpu(e,i):this.followIntervals(e,t)}followGpu(e,t){if(t>mt.GPU_LATE_MS)return this.lower(e,mt.LOWER_COOLDOWN_MS);if(t<mt.GPU_ROOM_MS)return this.raise(e,mt.RAISE_COOLDOWN_MS)}followIntervals(e,t){if(!(t>0)||t>1e3)return;this.intervalMs=this.intervalMs===void 0?t:this.intervalMs*.9+t*.1;const i=this.intervalMs>mt.INTERVAL_LATE_MS;if(this.probe){if(i)return this.ratio=this.probe.ratioBefore,this.probe=void 0,this.lastChangeMs=e,this.nextProbeMs=e+mt.PROBE_BACKOFF_MS,this.ratio;e-this.probe.sinceMs>=mt.PROBE_WATCH_MS&&(this.probe=void 0,this.nextProbeMs=e+mt.PROBE_EVERY_MS);return}if(i){const n=this.lower(e,mt.LOWER_COOLDOWN_MS);return n!==void 0&&(this.nextProbeMs=e+mt.PROBE_EVERY_MS),n}if(this.ratio<this.maxRatio&&e>=this.nextProbeMs&&e-this.lastChangeMs>=mt.RAISE_COOLDOWN_MS){const n=this.ratio,s=this.raise(e,0);return s!==void 0&&(this.probe={sinceMs:e,ratioBefore:n}),s}}lower(e,t){if(!(this.ratio<=this.minimum||e-this.lastChangeMs<t))return this.ratio=Math.max(this.minimum,mt.clamp(this.ratio-mt.STEP)),this.lastChangeMs=e,this.ratio}raise(e,t){if(!(this.ratio>=this.maxRatio||e-this.lastChangeMs<t))return this.ratio=Math.min(this.maxRatio,mt.clamp(this.ratio+mt.STEP)),this.lastChangeMs=e,this.ratio}static clamp(e){return Number.isFinite(e)?Math.max(mt.MIN_RATIO,Math.round(e/mt.STEP)*mt.STEP):mt.MIN_RATIO}}class zl{constructor(e,t){this.gl=e,this.extension=t}static IN_FLIGHT_MAX=8;static create(e){if(!(e instanceof WebGL2RenderingContext))return;const t=e.getExtension("EXT_disjoint_timer_query_webgl2");return t?new zl(e,t):void 0}pending=[];active;smoothedMs;begin(){if(!(this.active||this.pending.length>=zl.IN_FLIGHT_MAX))try{const e=this.gl.createQuery();if(!e)return;this.gl.beginQuery(this.extension.TIME_ELAPSED_EXT,e),this.active=e}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 e=this.gl;try{for(let t=0;t<this.pending.length;t++){const i=this.pending[t];if(!e.getQueryParameter(i,e.QUERY_RESULT_AVAILABLE))continue;if(!e.getParameter(this.extension.GPU_DISJOINT_EXT)){const s=e.getQueryParameter(i,e.QUERY_RESULT)/1e6;this.smoothedMs=this.smoothedMs===void 0?s:this.smoothedMs*.8+s*.2}e.deleteQuery(i),this.pending.splice(t,1),t--}}catch{this.pending.length=0}return this.smoothedMs}reset(){this.smoothedMs=void 0}}class ft{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 e=ft.ICE_INDEX_RED,t=Math.sqrt((4-e*e)/3);return Math.asin(Math.min(1,t))*180/Math.PI}static minimumDeviationDeg(e,t){const i=e*Math.PI/180,n=t*Math.sin(i/2);return n>1?Number.NaN:(2*Math.asin(n)-i)*180/Math.PI}static effectiveIndex(e,t){const i=t*Math.PI/180,n=Math.cos(i);return n<=0?Number.POSITIVE_INFINITY:Math.sqrt(e*e-Math.sin(i)**2)/n}static parheliaAzimuthDeg(e,t=ft.ICE_INDEX_RED){const i=ft.minimumDeviationDeg(ft.SIDE_PRISM_ANGLE_DEG,ft.effectiveIndex(t,e));return Number.isFinite(i)?i:void 0}static parheliaDistanceDeg(e,t=ft.ICE_INDEX_RED){const i=ft.parheliaAzimuthDeg(e,t);if(i===void 0)return;const n=e*Math.PI/180,s=Math.sin(n)**2,a=Math.cos(n)**2*Math.cos(i*Math.PI/180);return Math.acos(Math.max(-1,Math.min(1,s+a)))*180/Math.PI}static get PLATE_END_FACE_LIMIT_DEG(){const e=ft.ICE_INDEX_RED;return Math.asin(Math.min(1,Math.sqrt(e*e-1)))*180/Math.PI}static circumzenithalAltitudeDeg(e,t=ft.ICE_INDEX_RED){if(e<0||e>90-ft.PLATE_END_FACE_LIMIT_DEG)return;const i=Math.cos(e*Math.PI/180),n=Math.sqrt(t*t-i*i);if(!(n>=1))return Math.asin(n)*180/Math.PI}static DECK_HEIGHT_M=8e3;static deckLitUntilDeg(e){return Math.acos(6371e3/(6371e3+Math.max(0,e)))*180/Math.PI}static halo22(){return ft.ringOf("halo22",ft.SIDE_PRISM_ANGLE_DEG)}static halo46(){return ft.ringOf("halo46",ft.END_PRISM_ANGLE_DEG)}static ringOf(e,t){const i=ft.minimumDeviationDeg(t,ft.ICE_INDEX_RED),n=ft.minimumDeviationDeg(t,ft.ICE_INDEX_BLUE);return{id:e,angleDeg:(i+n)/2,redAngleDeg:i,blueAngleDeg:n}}static strength(e,t,i=90,n=0){const s=Math.max(0,Math.min(1,e)),a=Math.max(0,1-Math.max(0,Math.min(1,t))),o=i>=0?1:n<=0?0:Math.max(0,1+i/n);return s*a*o}static formsAt(e,t=0){if(e<=-t)return[];const i=[ft.halo22(),ft.halo46()],n=e>0?ft.parheliaDistanceDeg(e):void 0;n!==void 0&&i.push({id:"parhelia",angleDeg:n,redAngleDeg:n,blueAngleDeg:ft.parheliaDistanceDeg(e,ft.ICE_INDEX_BLUE)}),i.push({id:"tangentArc",angleDeg:ft.halo22().angleDeg}),e>0&&i.push({id:"parhelicCircle",angleDeg:e});const s=ft.circumzenithalAltitudeDeg(e);return s!==void 0&&i.push({id:"circumzenithal",angleDeg:s}),e>ft.PLATE_END_FACE_LIMIT_DEG&&i.push({id:"circumhorizontal"}),e<ft.PILLAR_MAX_SOURCE_ALTITUDE_DEG&&i.push({id:"pillar"}),i}static PILLAR_MAX_SOURCE_ALTITUDE_DEG=20}class rn{static get WATER_INDEX_RED(){return bi.indexAt(bi.RED_NM)}static get WATER_INDEX_BLUE(){return bi.indexAt(bi.BLUE_NM)}static radiusDeg(e,t){const i=(t*t-1)/(e*e-1);if(i<0||i>1)return Number.NaN;const n=Math.acos(Math.sqrt(i)),s=Math.asin(Math.sin(n)/t),a=2*(n-s)+(e-1)*(Math.PI-2*s),o=2*Math.PI;let c=a%o;return c<0&&(c+=o),c>Math.PI&&(c=o-c),180-c*180/Math.PI}static primary(){return rn.bowOf("primary",2,0)}static secondary(){return rn.bowOf("secondary",3,0)}static bowOf(e,t,i){const n=rn.radiusDeg(t,rn.WATER_INDEX_RED),s=rn.radiusDeg(t,rn.WATER_INDEX_BLUE),a=(n+s)/2;return{id:e,radiusDeg:a,redRadiusDeg:n,violetRadiusDeg:s,topAltitudeDeg:a-i}}static alexandersBandDeg(){return{fromDeg:rn.primary().redRadiusDeg,toDeg:rn.secondary().redRadiusDeg}}static formsAt(e){return e<0?[]:[rn.bowOf("primary",2,e),rn.bowOf("secondary",3,e)].filter(t=>t.topAltitudeDeg>0)}static FULL_MOON_MAGNITUDE=-12.7;static moonlightShare(e){return Math.min(1,10**(-.4*(e-rn.FULL_MOON_MAGNITUDE)))}static strength(e,t,i){if(i<=0)return 0;const n=Math.max(0,Math.min(1,e)),s=Math.max(0,1-Math.max(0,Math.min(1,t)));return n*s}}class on{constructor(e){this.radius=e;const t=on.SEGMENTS*on.VERTICES_PER_SEGMENT;this.positions=new Float32Array(t*3),this.colors=new Float32Array(t*3);const i=new ot;i.setAttribute("position",new tt(this.positions,3)),i.setAttribute("color",new tt(this.colors,3)),i.setDrawRange(0,0),this.object=new De(i,new bn({vertexColors:!0,transparent:!0,blending:Ni,depthWrite:!1,fog:!1,side:Qi})),this.object.frustumCulled=!1}static POINTS=24;static SEGMENTS=on.POINTS-1;static ACROSS=3;static VERTICES_PER_SEGMENT=(on.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(e,t,i){this.head=e&&li(e.altitudeDeg,e.azimuthDeg,1),this.tip=t&&li(t.altitudeDeg,t.azimuthDeg,1),this.brightness=i,this.rebuild()}rebuild(){const e=this.object.geometry,t=this.head,i=this.tip;if(!t||!i||this.brightness<=0){e.setDrawRange(0,0);return}const n=this.angleBetween(t,i);if(n<=0){e.setDrawRange(0,0);return}const s=n*on.SPREAD_FRACTION*Math.PI/180,a=h=>this.scale(this.slerp(t,i,h),this.radius),o=h=>this.radius*(on.HEAD_HALF_WIDTH_DEG*Math.PI/180+s*h),c=h=>this.brightness*(1-h)**on.FADE_POWER;let l=0;for(let h=1;h<on.POINTS;h++){const u=(h-1)/on.SEGMENTS,d=h/on.SEGMENTS;l=this.pushBand(l,a(u),a(d),o(u),o(d),c(u),c(d))}e.setDrawRange(0,l),e.getAttribute("position").needsUpdate=!0,e.getAttribute("color").needsUpdate=!0}pushBand(e,t,i,n,s,a,o){const c=this.normalise(this.cross(this.normalise(t),this.normalise(this.subtract(i,t))));for(let l=0;l<on.ACROSS-1;l++){const h=l-1,u=l,d=this.across(t,c,n,h),f=this.across(i,c,s,h),p=this.across(t,c,n,u),v=this.across(i,c,s,u),m=(g,_)=>g===0?_:0;e=this.push(e,d,m(h,a)),e=this.push(e,f,m(h,o)),e=this.push(e,p,m(u,a)),e=this.push(e,f,m(h,o)),e=this.push(e,v,m(u,o)),e=this.push(e,p,m(u,a))}return e}across(e,t,i,n){return{x:e.x+t.x*i*n,y:e.y+t.y*i*n,z:e.z+t.z*i*n}}push(e,t,i){const n=e*3;this.positions[n]=t.x,this.positions[n+1]=t.y,this.positions[n+2]=t.z;const s=Ae.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,e+1}slerp(e,t,i){const n=this.angleBetweenRadians(e,t);if(n<1e-9)return e;const s=Math.sin(n),a=Math.sin((1-i)*n)/s,o=Math.sin(i*n)/s;return{x:e.x*a+t.x*o,y:e.y*a+t.y*o,z:e.z*a+t.z*o}}angleBetween(e,t){return this.angleBetweenRadians(e,t)*180/Math.PI}angleBetweenRadians(e,t){const i=e.x*t.x+e.y*t.y+e.z*t.z;return Math.acos(Math.min(1,Math.max(-1,i)))}scale(e,t){return{x:e.x*t,y:e.y*t,z:e.z*t}}subtract(e,t){return{x:e.x-t.x,y:e.y-t.y,z:e.z-t.z}}cross(e,t){return{x:e.y*t.z-e.z*t.y,y:e.z*t.x-e.x*t.z,z:e.x*t.y-e.y*t.x}}normalise(e){const t=Math.hypot(e.x,e.y,e.z)||1;return{x:e.x/t,y:e.y/t,z:e.z/t}}dispose(){this.object.geometry.dispose(),this.object.material.dispose()}}class F5{object=new Dt;radius;tiers;drawn=[];constructor(e){this.radius=e,this.object.name="satellites",this.tiers=Co.map(t=>{const i=new xs(new ot,st.material(t.size));return st.track(i),i.frustumCulled=!1,this.object.add(i),i})}set(e,t,i,n){const s=this.tiers.map(()=>[]);this.drawn=[];for(const a of e){if(a.magnitude>t)continue;const o=i(a.position);if(o<=0)continue;const c=a.magnitude-2.5*Math.log10(o);if(c>t)continue;const l=bo(c,t),h=I1(l),{x:u,y:d,z:f}=li(a.position.altitudeDeg,a.position.azimuthDeg,this.radius),[p,v,m]=n(a.position,c);s[h].push({x:u,y:d,z:f,r:p,g:v,b:m,seed:a.norad*.6180339887%1}),this.drawn.push({satellite:a,direction:new R(u,d,f).normalize()})}this.tiers.forEach((a,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}),a.geometry.dispose();const d=new ot;d.setAttribute("position",new tt(l,3)),d.setAttribute("color",new tt(h,3)),d.setAttribute("seed",new tt(u,1)),a.geometry=d})}get count(){return this.drawn.length}nearest(e,t){let i,n=t;for(const s of this.drawn){const a=s.direction.dot(e);a>n&&(n=a,i=s.satellite)}return i}dispose(){for(const e of this.tiers)e.geometry.dispose(),e.material.dispose();this.object.removeFromParent(),this.drawn=[]}}class sh{constructor(e){this.state=e}next(){this.state=this.state+1831565813|0;let e=this.state;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}between(e,t){return e+this.next()*(t-e)}}class Oa{static MIN_DURATION_MS=250;static MAX_DURATION_MS=1400;static schedule(e){const{ratePerHour:t,durationMs:i,velocityKmS:n,seed:s}=e;if(t<=0||i<=0)return[];const a=t*i/36e5,o=new sh(s),c=Math.floor(a),l=c+(o.next()<a-c?1:0),h=[];for(let u=0;u<l;u++){const d=Math.min(1,Math.max(0,(n-20)/52)),f=Oa.MAX_DURATION_MS-d*(Oa.MAX_DURATION_MS-Oa.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(e,t){return e.filter(i=>t>=i.t&&t<=i.t+i.durationMs).map(i=>({meteor:i,progress:(t-i.t)/i.durationMs}))}}class Ks{object=new Dt;radius;core;glow;flashKey;static CORE_WIDTH_DEG=.06;static GLOW_WIDTH_DEG=.5;static SEGMENTS=28;static CORE_RELATIVE=1e3;constructor(e){this.radius=e,this.object.name="lightning-bolt",this.core=new bn({color:15659775,transparent:!0,opacity:0,blending:Ni,depthWrite:!1,fog:!1}),this.glow=new bn({color:10466559,transparent:!0,opacity:0,blending:Ni,depthWrite:!1,fog:!1}),this.object.visible=!1,this.object.renderOrder=5.95}set(e,t,i){if(!e||!e.cloudToGround||t<=.01){this.object.visible=!1;return}const n=`${e.channelSeed}:${Math.round(i)}`;n!==this.flashKey&&this.build(e,i,n),this.core.color.setHex(15659775).multiplyScalar(Ks.CORE_RELATIVE*Math.min(1,t*1.4)),this.glow.color.setHex(10466559).multiplyScalar(.1*Ks.CORE_RELATIVE*t*.35),this.core.opacity=1,this.glow.opacity=1,this.object.visible=!0}build(e,t,i){this.flashKey=i;for(const l of[...this.object.children])l.geometry.dispose(),this.object.remove(l);const n=new sh(e.channelSeed),s=Math.atan2(t,e.distanceM)*180/Math.PI,a=this.channel(n,e.azimuthDeg,s,0,1),o=[a],c=1+Math.floor(n.next()*2);for(let l=0;l<c;l++){const h=a[Math.floor(n.between(.15,.5)*a.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 De(this.ribbon(l,Ks.GLOW_WIDTH_DEG),this.glow)),this.object.add(new De(this.ribbon(l,Ks.CORE_WIDTH_DEG),this.core))}channel(e,t,i,n,s){const a=[],o=i-n;let c=t;for(let l=0;l<=Ks.SEGMENTS;l++){const h=i-o*l/Ks.SEGMENTS;a.push({azimuthDeg:c,altitudeDeg:h}),c+=e.between(-1,1)*o*.06*s}return a}ribbon(e,t){const i=new Float32Array(e.length*2*3),n=[],s=this.radius*Math.tan(t*Math.PI/180)/2,a=e.map(c=>{const{x:l,y:h,z:u}=li(c.altitudeDeg,c.azimuthDeg,this.radius);return new R(l,h,u)});a.forEach((c,l)=>{const h=a[Math.min(l+1,a.length-1)],u=a[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<a.length-1){const p=l*2;n.push(p,p+1,p+2,p+1,p+3,p+2)}});const o=new ot;return o.setAttribute("position",new tt(i,3)),o.setIndex(n),o}dispose(){for(const e of this.object.children)e.geometry.dispose();this.core.dispose(),this.glow.dispose(),this.object.removeFromParent()}}class di{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(e){const t=new sh(e.seed),i=[],{minS:n,maxS:s}=di.intervalFor(e.intensity??.5);let a=t.between(0,s)*1e3;for(;a<e.durationMs;){const o=t.next()<di.CLOUD_TO_GROUND_FRACTION,c=di.MIN_DISTANCE_M,l=di.MAX_DISTANCE_M,h=Math.sqrt(t.between(c*c,l*l)),u=o?1+Math.floor(t.next()*4):1,d=[];let f=0;for(let p=0;p<u;p++)d.push({offsetMs:f,intensity:p===0?1:t.between(.4,.9)}),f+=di.INTERSTROKE_MS*t.between(.5,1.6);i.push({t:a,azimuthDeg:t.between(0,360),distanceM:h,cloudToGround:o,strokes:d,channelSeed:Math.floor(t.next()*2**31)}),a+=t.between(n,s)*1e3}return i}static intervalFor(e){const t=Math.min(1,Math.max(0,(e-.5)/.5));return{minS:di.MIN_INTERVAL_S-t*(di.MIN_INTERVAL_S-di.SEVERE_MIN_INTERVAL_S),maxS:di.MAX_INTERVAL_S-t*(di.MAX_INTERVAL_S-di.SEVERE_MAX_INTERVAL_S)}}static brightnessAt(e,t){let i=0;for(const n of e.strokes){const s=t-e.t-n.offsetMs;s<0||s>di.STROKE_DECAY_MS*6||(i+=n.intensity*Math.exp(-s/di.STROKE_DECAY_MS))}return Math.min(1,i)}static endOf(e){const t=e.strokes[e.strokes.length-1];return e.t+t.offsetMs+di.STROKE_DECAY_MS*6}static thunderDelayMs(e){return e.distanceM/di.SOUND_SPEED_M_S*1e3}}class Ki{static RED_NM=656.3;static BLUE_NM=435.8;static ANCHOR_RED=1.3067;static ANCHOR_BLUE=1.317;static B=(Ki.ANCHOR_BLUE-Ki.ANCHOR_RED)/(1/(Ki.BLUE_NM*Ki.BLUE_NM)-1/(Ki.RED_NM*Ki.RED_NM));static A=Ki.ANCHOR_RED-Ki.B/(Ki.RED_NM*Ki.RED_NM);static indexAt(e){return Ki.A+Ki.B/(e*e)}}class $o{normals=new Float64Array(24);offsets=new Float64Array(8);radius=1;set(e,t,i,n,s,a){let o=0,c=0,l=0;Math.abs(i)<.9?(o=-t,c=e,l=0):(o=0,c=-i,l=t);const h=Math.hypot(o,c,l)||1;o/=h,c/=h,l/=h;const u=t*l-i*c,d=i*o-e*l,f=e*c-t*o,p=s/2,v=a/2;for(let m=0;m<6;m++){const g=n+m*Math.PI/3,_=Math.cos(g),b=Math.sin(g);this.normals[m*3]=o*_+u*b,this.normals[m*3+1]=c*_+d*b,this.normals[m*3+2]=l*_+f*b,this.offsets[m]=p}this.normals[18]=e,this.normals[19]=t,this.normals[20]=i,this.offsets[6]=v,this.normals[21]=-e,this.normals[22]=-t,this.normals[23]=-i,this.offsets[7]=v,this.radius=Math.hypot(p,v)}get aimRadius(){return this.radius}trace(e,t,i,n,s,a,o){let c=-t,l=e,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=t*h-i*l,f=i*c-e*h,p=e*l-t*c,v=c*n+d*s-e*this.radius*2,m=l*n+f*s-t*this.radius*2,g=h*n+p*s-i*this.radius*2;let _=-1,b=-1/0,M=1/0;for(let J=0;J<8;J++){const ie=this.normals[J*3],re=this.normals[J*3+1],Ve=this.normals[J*3+2],Je=ie*e+re*t+Ve*i,qe=this.offsets[J]-(ie*v+re*m+Ve*g);if(Je>1e-9){const q=qe/Je;q<M&&(M=q)}else if(Je<-1e-9){const q=qe/Je;q>b&&(b=q,_=J)}else if(qe<0)return 0}if(_<0||b>=M)return 0;let S=0;const w=this.normals[_*3],T=this.normals[_*3+1],x=this.normals[_*3+2],A=-(w*e+T*t+x*i),C=Ol.reflectance(A,1,a);o[S].x=e+2*A*w,o[S].y=t+2*A*T,o[S].z=i+2*A*x,o[S].weight=C,S++;const I=1/a,P=Math.sqrt(Math.max(0,1-I*I*(1-A*A)));let V=I*e+(I*A-P)*w,X=I*t+(I*A-P)*T,L=I*i+(I*A-P)*x,B=v+e*b,k=m+t*b,$=g+i*b,ee=1-C;for(let J=0;J<$o.MAX_BOUNCES&&ee>$o.MIN_WEIGHT;J++){let ie=-1,re=1/0;for(let z=0;z<8;z++){const Te=this.normals[z*3],Ne=this.normals[z*3+1],Ce=this.normals[z*3+2],be=Te*V+Ne*X+Ce*L;if(be<=1e-9)continue;const ke=(this.offsets[z]-(Te*B+Ne*k+Ce*$))/be;ke>1e-9&&ke<re&&(re=ke,ie=z)}if(ie<0)break;const Ve=this.normals[ie*3],Je=this.normals[ie*3+1],qe=this.normals[ie*3+2],q=Ve*V+Je*X+qe*L,ae=a*Math.sqrt(Math.max(0,1-q*q));if(B+=V*re,k+=X*re,$+=L*re,ae<1){const z=Math.sqrt(Math.max(0,1-ae*ae)),Te=Ol.reflectance(q,a,1);if(o[S].x=a*V-(a*q-z)*Ve,o[S].y=a*X-(a*q-z)*Je,o[S].z=a*L-(a*q-z)*qe,o[S].weight=ee*(1-Te),S++,S>=o.length)return S;ee*=Te}const ne=2*q;V-=ne*Ve,X-=ne*Je,L-=ne*qe}return S}static MAX_BOUNCES=6;static MIN_WEIGHT=1e-4}class Bt{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 $o;emergent=Array.from({length:$o.MAX_BOUNCES+2},()=>({x:0,y:0,z:0,weight:0}));tally=new Float32Array(Bt.AZIMUTH_BINS*Bt.ALTITUDE_BINS*3);radiance=new Float32Array(Bt.AZIMUTH_BINS*Bt.ALTITUDE_BINS*3);scratch=new Float32Array(Bt.AZIMUTH_BINS*Bt.ALTITUDE_BINS*3);seed=1;spare=0;hasSpare=!1;altitude=0;tilt=0;alignment=0;traced=0;begin(e,t,i=2654435769){this.seed=i>>>0||1,this.hasSpare=!1,this.tally.fill(0),this.traced=0,this.altitude=e*Math.PI/180,this.alignment=Math.min(1,Math.max(0,t));const n=Bt.WORST_TILT_DEG*(Bt.BEST_TILT_DEG/Bt.WORST_TILT_DEG)**this.alignment;this.tilt=n*Math.PI/180}trace(e){const t=Bt.AZIMUTH_BINS,i=Bt.ALTITUDE_BINS,n=this.tally,s=Bt.SOURCE_RADIUS_DEG*Math.PI/180,a=Math.cos(Bt.UNDEVIATED_DEG*Math.PI/180),o=this.altitude;for(let c=0;c<e;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,_=(this.random()*2-1)*g,b=(this.random()*2-1)*g,M=4*g*g,S=fi.SAMPLES[this.random()*fi.SAMPLES.length|0],w=this.crystal.trace(p,v,m,_,b,Ki.indexAt(S.wavelengthNm),this.emergent);for(let T=0;T<w;T++){const x=this.emergent[T],A=Math.hypot(x.x,x.y,x.z);if(A<1e-9||x.weight<=0)continue;const C=x.x/A,I=x.y/A,P=x.z/A;if(C*p+I*v+P*m>a)continue;const V=Math.asin(Math.max(-1,Math.min(1,-P))),X=Math.abs(Math.atan2(-I,-C)),L=Math.min(t-1,X/Math.PI*t|0),k=(Math.min(i-1,(V+Math.PI/2)/Math.PI*i|0)*t+L)*3,$=x.weight*M*fi.SAMPLES.length;n[k]+=$*S.r,n[k+1]+=$*S.g,n[k+2]+=$*S.b}}this.traced+=e}get tracedRays(){return this.traced}harvest(){const e=Bt.AZIMUTH_BINS,t=Bt.ALTITUDE_BINS;return this.toRadiance(e,t),this.smooth(e,t),{width:e,height:t,data:this.radiance,sourceAltitudeDeg:this.altitude*180/Math.PI,alignment:this.alignment,rays:this.traced}}compute(e,t,i,n){return this.begin(e,t,n),this.trace(i),this.harvest()}toRadiance(e,t){const i=2*Math.PI/e,n=Math.max(1,this.traced),s=4*Bt.REFERENCE_MICRONS*Bt.REFERENCE_MICRONS;for(let a=0;a<t;a++){const o=Math.sin(a/t*Math.PI-Math.PI/2),c=Math.sin((a+1)/t*Math.PI-Math.PI/2),l=1/(i*(c-o)*n*s);for(let h=0;h<e;h++){const u=(a*e+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(e,t){const i=this.scratch,n=this.radiance;i.set(n);for(let a=0;a<t;a++){const o=a*e*3;for(let c=0;c<3;c++){let l=i[o+c];for(let h=0;h<e;h++){const u=o+h*3+c,d=h+1<e?i[u+3]:i[u];n[u]=(l+2*i[u]+d)/4,l=i[u]}}}i.set(n);const s=e*3;for(let a=0;a<t;a++){const o=a>0?-s:0,c=a+1<t?s:0,l=a*s;for(let h=l;h<l+s;h++)n[h]=(i[h+o]+2*i[h]+i[h+c])/4}}pickPopulation(){const e=this.random();let t=0;for(const i of Bt.POPULATIONS)if(t+=i.share,e<=t)return i;return Bt.POPULATIONS[Bt.POPULATIONS.length-1]}orient(e,t){const i=this.random()*2*Math.PI;let n=this.random()*2*Math.PI,s=0,a=0,o=1;switch(e.orientation){case"tumbling":{o=this.random()*2-1;const c=Math.sqrt(Math.max(0,1-o*o));s=c*Math.cos(i),a=c*Math.sin(i);break}case"plate":{o=this.spreadAboutAnAxis(t);const c=Math.sqrt(Math.max(0,1-o*o));s=c*Math.cos(i),a=c*Math.sin(i);break}case"column":case"parry":{o=this.spreadAboutAPlane(t);const c=Math.sqrt(Math.max(0,1-o*o));s=c*Math.cos(i),a=c*Math.sin(i),e.orientation==="parry"&&(n=Math.PI/2+this.gaussian()*t);break}}this.crystal.set(s,a,o,n,e.widthMicrons,e.lengthMicrons)}random(){this.seed=this.seed+1831565813>>>0;let e=this.seed;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}spreadAboutAnAxis(e){const t=1/Math.max(1e-6,e*e),i=Math.max(1e-12,this.random()),n=1+Math.log(i+(1-i)*Math.exp(-2*t))/t;return Math.max(-1,Math.min(1,n))}spreadAboutAPlane(e){for(let t=0;t<8;t++){const i=this.gaussian()*e;if(i>=-1&&i<=1)return i}return this.random()*2-1}gaussian(){if(this.hasSpare)return this.hasSpare=!1,this.spare;const e=Math.sqrt(-2*Math.log(Math.max(1e-12,this.random()))),t=2*Math.PI*this.random();return this.spare=e*Math.sin(t),this.hasSpare=!0,e*Math.cos(t)}}class Ci{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(e){this.material.uniforms.uFieldOffset.value.copy(e)}object;material;sky=new Bt;texture;texels;mappedAltitudeDeg=Number.NaN;mappedAlignment=Number.NaN;tracing=!1;everDisplayed=!1;urgent=!1;workHandle;onRepaint;constructor(){const e=Bt.AZIMUTH_BINS,t=Bt.ALTITUDE_BINS;this.texels=new Uint16Array(e*t*4),this.texture=new ca(this.texels,e,t,Ei,Wt),this.texture.minFilter=rt,this.texture.magFilter=rt,this.texture.wrapS=wi,this.texture.wrapT=wi,this.texture.needsUpdate=!0,this.material=new ct({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:Ci.GAIN}},vertexShader:`
|
|
7123
7123
|
varying vec3 vDirection;
|
|
7124
7124
|
void main() {
|
|
7125
7125
|
vDirection = normalize((modelMatrix * vec4(position, 1.0)).xyz - cameraPosition);
|
|
@@ -7148,7 +7148,7 @@ void main()
|
|
|
7148
7148
|
if (ice <= 0.0) discard;
|
|
7149
7149
|
gl_FragColor = vec4(iceHaloLight(dir, ice), 1.0);
|
|
7150
7150
|
}
|
|
7151
|
-
`,transparent:!0,blending:Ni,depthWrite:!1,side:Ht,fog:!1}),this.object=new De(new ri(Ci.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(e){this.hostedByDeck=e,this.show(this.shown)}show(e){this.shown=e,this.object.visible=e&&!this.hostedByDeck,this.deckUniforms.uHaloShown.value=e?1:0}get awaitingFirstDisplay(){return this.tracing&&!this.everDisplayed}setUrgent(e){this.urgent=e}set onReady(e){this.onRepaint=e}update(e,t,i,n,s,a){const o=this.material.uniforms;if(i<=0){o.uStrength.value=0,this.show(!1),this.stopWork();return}o.uSource.value.set(e.x,e.y,e.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(t,a)}requestMap(e,t){if(!(!(Math.abs(e-this.mappedAltitudeDeg)<Ci.ALTITUDE_STEP_DEG)||!(Math.abs(t-this.mappedAlignment)<Ci.ALIGNMENT_STEP))){this.next=void 0;return}if(this.tracing){if(this.tracingFor(e,t)){this.next=void 0;return}if(!(!(Math.abs(e-this.pendingAltitudeDeg)<Ci.LEAP_ALTITUDE_DEG)||!(Math.abs(t-this.pendingAlignment)<Ci.LEAP_ALIGNMENT))){this.next={sourceAltitudeDeg:e,alignment:t};return}}this.next=void 0,this.pendingAltitudeDeg=e,this.pendingAlignment=t,this.sky.begin(e,t),this.tracing=!0,this.scheduleWork()}pendingAltitudeDeg=Number.NaN;pendingAlignment=Number.NaN;next;tracingFor(e,t){return this.tracing&&Math.abs(e-this.pendingAltitudeDeg)<Ci.ALTITUDE_STEP_DEG&&Math.abs(t-this.pendingAlignment)<Ci.ALIGNMENT_STEP}scheduleWork(){if(this.workHandle!==void 0)return;const e=()=>{if(this.workHandle=void 0,!this.tracing)return;const t=performance.now(),i=this.urgent?Ci.URGENT_BUDGET_MS:Ci.BUDGET_MS;do this.sky.trace(Ci.RAYS_PER_BATCH);while(this.sky.tracedRays<Ci.RAYS&&performance.now()-t<i);if(this.sky.tracedRays>=Ci.RAYS){this.publish(),this.tracing=!1,this.mappedAltitudeDeg=this.pendingAltitudeDeg,this.mappedAlignment=this.pendingAlignment;const s=this.next;s&&this.requestMap(s.sourceAltitudeDeg,s.alignment);return}this.workHandle=requestAnimationFrame(e)};this.workHandle=requestAnimationFrame(e)}stopWork(){this.workHandle!==void 0&&cancelAnimationFrame(this.workHandle),this.workHandle=void 0,this.tracing=!1,this.next=void 0}publish(){const t=this.sky.harvest().data;for(let i=0,n=0;n<t.length;i+=4,n+=3)this.texels[i]=kn.toHalfFloat(t[n]),this.texels[i+1]=kn.toHalfFloat(t[n+1]),this.texels[i+2]=kn.toHalfFloat(t[n+2]),this.texels[i+3]=1;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 xi{static MAX_CONCURRENT=24;static POINTS=8;static SEGMENTS=xi.POINTS-1;static ACROSS=3;static VERTICES_PER_SEGMENT=(xi.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 e=xi.MAX_CONCURRENT*xi.SEGMENTS*xi.VERTICES_PER_SEGMENT;this.positions=new Float32Array(e*3),this.colors=new Float32Array(e*3);const t=new ot;t.setAttribute("position",new tt(this.positions,3)),t.setAttribute("color",new tt(this.colors,3)),t.setDrawRange(0,0),this.object=new De(t,new bn({vertexColors:!0,transparent:!0,blending:Ni,depthWrite:!1,fog:!1,side:Qi})),this.object.frustumCulled=!1}get schedule(){return this.meteors}setShower(e,t,i){this.meteors=e,this.radiantAltitudeDeg=t,this.radiantAzimuthDeg=i}update(e){const t=this.object.geometry;if(this.meteors.length===0){t.setDrawRange(0,0);return}const i=Oa.aliveAt(this.meteors,e).slice(0,xi.MAX_CONCURRENT);let n=0;for(const{meteor:s,progress:a}of i){const o=this.radiantOf(s);if(!o)continue;const c=li(o.altitudeDeg,o.azimuthDeg,1),[l,h]=this.basisAround(c),u=s.fromRadiantDeg+a*s.lengthDeg,d=Math.max(s.fromRadiantDeg,u-s.lengthDeg*.6),f=Math.min(1,(1-a)*2.5),p=this.turn(l,h,s.bearingDeg),v=(.15+.85*s.brightness)*f,m=b=>v*b**1.6,g=b=>this.onSphere(c,p,d+(u-d)*b),_=b=>xi.RADIUS*((xi.MIN_HALF_WIDTH_DEG+xi.BRIGHT_HALF_WIDTH_DEG*s.brightness*b)*Math.PI/180);for(let b=1;b<xi.POINTS;b++){const M=(b-1)/xi.SEGMENTS,S=b/xi.SEGMENTS;n=this.pushRibbon(n,g(M),g(S),_(M),_(S),m(M),m(S))}}t.setDrawRange(0,n),t.getAttribute("position").needsUpdate=!0,t.getAttribute("color").needsUpdate=!0}midpointOf(e){const t=this.radiantOf(e);if(!t)return;const i=li(t.altitudeDeg,t.azimuthDeg,1),[n,s]=this.basisAround(i),a=this.turn(n,s,e.bearingDeg),o=this.onSphere(i,a,e.fromRadiantDeg+e.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(e){return e.radiant?e.radiant:this.radiantAltitudeDeg>0?{altitudeDeg:this.radiantAltitudeDeg,azimuthDeg:this.radiantAzimuthDeg}:void 0}pushRibbon(e,t,i,n,s,a,o){const c=this.normalise(this.cross(this.normalise(t),this.normalise(this.subtract(i,t))));for(let l=0;l<xi.ACROSS-1;l++){const h=l-1,u=l,d=this.across(t,c,n,h),f=this.across(i,c,s,h),p=this.across(t,c,n,u),v=this.across(i,c,s,u),m=(g,_)=>g===0?_:0;e=this.push(e,d,m(h,a)),e=this.push(e,f,m(h,o)),e=this.push(e,p,m(u,a)),e=this.push(e,f,m(h,o)),e=this.push(e,v,m(u,o)),e=this.push(e,p,m(u,a))}return e}across(e,t,i,n){return{x:e.x+t.x*i*n,y:e.y+t.y*i*n,z:e.z+t.z*i*n}}push(e,t,i){const n=e*3;this.positions[n]=t.x,this.positions[n+1]=t.y,this.positions[n+2]=t.z;const s=Ae.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,e+1}turn(e,t,i){const n=i*Math.PI/180,s=Math.cos(n),a=Math.sin(n);return{x:e.x*s+t.x*a,y:e.y*s+t.y*a,z:e.z*s+t.z*a}}onSphere(e,t,i){const n=i*Math.PI/180,s=Math.cos(n),a=Math.sin(n);return{x:(e.x*s+t.x*a)*xi.RADIUS,y:(e.y*s+t.y*a)*xi.RADIUS,z:(e.z*s+t.z*a)*xi.RADIUS}}basisAround(e){const t=Math.abs(e.y)<.9?{x:0,y:1,z:0}:{x:1,y:0,z:0},i=this.normalise(this.cross(e,t));return[i,this.normalise(this.cross(e,i))]}subtract(e,t){return{x:e.x-t.x,y:e.y-t.y,z:e.z-t.z}}cross(e,t){return{x:e.y*t.z-e.z*t.y,y:e.z*t.x-e.x*t.z,z:e.x*t.y-e.y*t.x}}normalise(e){const t=Math.hypot(e.x,e.y,e.z)||1;return{x:e.x/t,y:e.y/t,z:e.z/t}}dispose(){this.object.geometry.dispose(),this.object.material.dispose()}}class Pt{constructor(e,t={}){this.size=e,this.span=Math.min(e.lengthM,Math.max(0,t.spanM??e.lengthM)),this.bank=(e.lengthM-this.span)/2,this.deck=Math.min(e.heightM,t.deckThicknessM??Pt.DEFAULT_DECK_THICKNESS_M),this.railHeight=t.railing?.heightM??Pt.DEFAULT_RAILING_HEIGHT_M,this.postSpacing=Math.max(.3,t.railing?.postSpacingM??Pt.DEFAULT_POST_SPACING_M),this.rails=Math.max(0,Math.round(t.railing?.rails??Pt.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(e){const t=Math.abs(e)-this.span/2;return t<=0?this.size.heightM:this.bank<=0?0:Math.max(0,this.size.heightM*(1-t/this.bank))}build(){const{widthM:e,heightM:t}=this.size,i=this.span/2,n=[];if(this.span>0){n.push(Pt.box(e,this.deck,this.span,0,t-this.deck/2,0));for(const c of[-1,1]){const l=t-this.deck;l>0&&this.bank>0&&n.push(Pt.box(e+1,l,Pt.ABUTMENT_THICKNESS_M,0,l/2,c*(i-Pt.ABUTMENT_THICKNESS_M/2)))}}const s=[];this.span>0&&s.push(Pt.box(e,.04,this.span,0,t+.02,0));const a=[];for(const c of[-1,1])this.bank<=0||(a.push(this.embankment(c)),s.push(this.bankRoad(c)));const o=[];for(const c of[-1,1])o.push(...this.railing(c*(e/2-Pt.POST_SIDE_M)));return{concrete:Pt.merge(n),road:Pt.merge(s),earth:Pt.merge(a),railing:Pt.merge(o)}}embankment(e){const t=this.size.widthM/2,i=this.stations(e),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)},a=l=>{const h=this.roadAt(l),u=t+Pt.BANK_SLOPE*h;return{leftFoot:new R(-u,0,l),leftTop:new R(-t,h,l),rightTop:new R(t,h,l),rightFoot:new R(u,0,l)}};for(let l=1;l<i.length;l++){const h=a(i[l-1]),u=a(i[l]),d=e>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=a(i[0]);e>0?s(o.leftFoot,o.rightFoot,o.rightTop,o.leftTop):s(o.leftTop,o.rightTop,o.rightFoot,o.leftFoot);const c=new ot;return c.setAttribute("position",new ut(n,3)),c.computeVertexNormals(),c}bankRoad(e){const t=this.size.widthM/2,i=this.stations(e),n=[];for(let a=1;a<i.length;a++){const o=i[a-1],c=i[a],l=this.roadAt(o)+.02,h=this.roadAt(c)+.02,u=e>0?[[-t,l,o],[t,l,o],[t,h,c],[-t,h,c]]:[[-t,h,c],[t,h,c],[t,l,o],[-t,l,o]];for(const d of[0,2,1,0,3,2])n.push(...u[d])}const s=new ot;return s.setAttribute("position",new ut(n,3)),s.computeVertexNormals(),s}stations(e){const t=[];for(let i=0;i<=Pt.BANK_STATIONS;i++)t.push(e*(this.span/2+this.bank*i/Pt.BANK_STATIONS));return t}railing(e){const t=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(-t+this.size.lengthM*o/i);const s=[],a=Pt.POST_SIDE_M;for(const o of n)s.push(Pt.box(a,this.railHeight,a,e,this.roadAt(o)+this.railHeight/2,o));for(let o=1;o<=this.rails;o++){const c=this.railHeight*o/this.rails-Pt.RAIL_HEIGHT_M/2;for(let l=1;l<n.length;l++){const h=new R(e,this.roadAt(n[l-1])+c,n[l-1]),u=new R(e,this.roadAt(n[l])+c,n[l]);s.push(Pt.beam(h,u))}}return s}static box(e,t,i,n,s,a){return new Wi(e,t,i).translate(n,s,a)}static beam(e,t){const i=new R().subVectors(t,e),n=new Wi(Pt.RAIL_DEPTH_M,Pt.RAIL_HEIGHT_M,i.length()),s=new en().setFromUnitVectors(new R(0,0,1),i.clone().normalize()),a=new R().addVectors(e,t).multiplyScalar(.5);return n.applyMatrix4(new Ze().compose(a,s,new R(1,1,1)))}static merge(e){const t=e.map(c=>c.getIndex()?c.toNonIndexed():c),i=t.reduce((c,l)=>c+l.getAttribute("position").count,0),n=new Float32Array(i*3),s=new Float32Array(i*3);let a=0;for(const c of t){const l=c.getAttribute("position"),h=c.getAttribute("normal");n.set(l.array,a*3),h&&s.set(h.array,a*3),a+=l.count}const o=new ot;o.setAttribute("position",new ut(n,3)),o.setAttribute("normal",new ut(s,3));for(const c of e)c.dispose();for(const c of t)c.dispose();return o}}const tu=Math.PI/180;function Nt(r,e,t,i,n=!1){const s=n?new bn({color:new se(...t)}):new Vr({color:new se(...t)}),a=new De(e,s);return a.position.y=i,a.userData={emissive:n},a.castShadow=!n,a.receiveShadow=!n,r.add(a),a}const iu=.25,U5=.002,k5=100,z5=1500,B5=.25,H5=1e3,G5=.15;function V5(r){const e=/^#([0-9a-f]{6})$/i.exec(r);if(!e)return[1,1,1];const t=parseInt(e[1],16);return[(t>>16&255)/255,(t>>8&255)/255,(t&255)/255]}const W5=[.32,.32,.3],J1=[1,.85,.5],X5=[.25,.25,.25],j1=[1,.97,.85],Y5=[.55,.68,.72],jn=.03,Qn=.05,Q1={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 Bi(r,e){return r?.[e]}function es(r,e,t,i,n,s,a,o){if(o===void 0)return;const c=new Vr({color:new se(...Y5),transparent:!0,opacity:o/100}),l=new De(new Wi(e,t,i),c);l.position.set(n,s,a),r.add(l)}const Mn=.05,nu=[.6,.58,.53],ym=[.5,.5,.48];function _r(r,e,t,i,n,s,a,o){const c=new Vr({color:new se(...o),side:Ht}),l=new De(new Wi(e,t,i),c);l.position.set(n,s,a),r.add(l)}function q5(r,e,t,i,n,s,a,o,c){const l=(i-s)/2,h=(p,v,m,g)=>{p<=0||(e?_r(r,p,v,Mn,m,o+g,a,c):_r(r,Mn,v,p,a,o+g,m,c))};h(t,l,0,i/2-l/2),h(t,l,0,-(i/2-l/2));const u=[...n].sort((p,v)=>p.center-v.center);let d=-t/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=t/2-d;h(f,s,d+f/2,0)}function ev(r,e,t,i,n,s,a,o,c,l){const h=(i+n)/2,u=n-i,d=(f,p,v,m)=>{f.length===0?p?_r(r,v,u,Mn,0,h,m,nu):_r(r,Mn,u,v,m,h,0,nu):q5(r,p,v,u,f,s,m,h,nu)};d(a,!0,e*2,-t+Mn),d(o,!0,e*2,t-Mn),d(c,!1,t*2,-e+Mn),d(l,!1,t*2,e-Mn),_r(r,e*2,Mn,t*2,0,i+Mn,0,ym),_r(r,e*2,Mn,t*2,0,n-Mn,0,ym)}function jd(r,e,t,i){switch(r){case"front":return{x:0,z:-(t-i)};case"behind":return{x:0,z:t-i};case"left":return{x:-(e-i),z:0};case"right":return{x:e-i,z:0};case"front-left":return{x:-(e-i),z:-ts};case"front-right":return{x:e-i,z:-ts};case"behind-left":return{x:-(e-i),z:ts};case"behind-right":return{x:e-i,z:ts}}}function tv(r,e,t,i,n,s,a){const o=t0();o.scale.setScalar(i),o.rotation.y=Q1[e];const{x:c,z:l}=jd(e,n,s,a);o.position.set(c,t,l),r.add(o)}const Qd=6,e0=6,Zs=3,ho=1.4,uo=Zs*.5,iv=1.2,nv=.35,$5=.75,K5=1.6;function bm(r,e,t,i){const n=new Dt,s=Math.max(1,r+1),a=s*Zs;Nt(n,new Wi(Qd,a,e0),[.55,.54,.5],a/2);const o=Qd/2,c=e0/2;for(let l=0;l<s;l++){const h=l*Zs+Zs/2;es(n,ho,uo,Qn,0,h,-c-jn,Bi(e,"front")),es(n,ho,uo,Qn,0,h,c+jn,Bi(e,"behind")),es(n,Qn,uo,ho,-o-jn,h,0,Bi(e,"left")),es(n,Qn,uo,ho,o+jn,h,0,Bi(e,"right"))}if(t){const l=Math.min(Math.max(i??0,0),s-1);tv(n,t,l*Zs,.72,o,c,iv);const h=u=>Bi(e,u)!==void 0?[{main:ho,center:0}]:[];ev(n,o,c,l*Zs,(l+1)*Zs,uo,h("front"),h("behind"),h("left"),h("right"))}return n}function _m(){const r=new Dt,e=[[0,0,.55,.5],[.4,.1,.35,.4],[-.35,-.2,.4,.38],[.1,-.4,.35,.36],[-.15,.4,.3,.34]];for(const[t,i,n,s]of e){const a=new ri(n,10,7);a.scale(1,.85,1),a.translate(t,0,i),Nt(r,a,[.26,.28,.17],s)}return r}function Z5(r){const e=new Dt,t=new Pt(hi.sizeOf(r),r.bridge).build();Nt(e,t.concrete,[.6,.6,.58],0);const i=Nt(e,t.road,[.2,.2,.21],0),n=Nt(e,t.earth,[.3,.36,.22],0);for(const s of[i,n])s.material.side=Qi;return Nt(e,t.railing,[.5,.52,.55],0),e}function Sm(){const r=new Dt;return Nt(r,new cs(.15,.22,2,8),[.32,.22,.14],1),Nt(r,new Gr(1.4,3,8),[.16,.32,.14],3.5),r}const wm=.275,J5=.35,j5=.9,Q5=34,eE=8,tE=1.4;function Em(){const r=new Dt,e=new ri(wm,7,3,0,Math.PI*2,0,Math.PI/2);e.scale(1,J5/wm,1);const t=hi.repeatOnGrid(e,Q5,j5,eE,tE),i=Nt(r,t,[.26,.28,.22],0);return i.castShadow=!0,i.userData.cropBasePositions=t.getAttribute("position").array.slice(),i.userData.cropVerticesPerClump=e.getAttribute("position").count,e.dispose(),r}function Am(){const r=new Dt,e=new ri(1,7,3,0,Math.PI*2,0,Math.PI/2);return Nt(r,e,[.38,.36,.32],0),r}function Tm(r){const e=new Dt;return Nt(e,new cs(.05,.08,5,8),[.28,.28,.3],2.5),Nt(e,new ri(.25,12,8),r?J1:W5,5.1,!0),e}const iE=[.08,.08,.08],Ys=.8,gr=1,$n=1.7,su=.6,ma=.4,qc=1.2,fr=.7,ts=.5,nE=$n;function Rm(r,e,t){const i=new Dt;Nt(i,new Wi(1.8,1.4,4.2),[.45,.14,.14],.7),Nt(i,new Wi(Ys*2,su,gr*2),[.4,.12,.12],$n);for(const s of[-1.4,1.4])for(const a of[-.95,.95]){const o=Nt(i,new cs(.4,.4,.3,12),iE,.4);o.rotation.z=Math.PI/2,o.position.x=a,o.position.z=s}const n=r?j1:X5;for(const s of[-.7,.7])Nt(i,new ri(.15,8,6),n,.7,!0).position.set(s,.7,-2.1);if(es(i,qc,ma,Qn,0,$n,-gr-jn,Bi(e,"front")),es(i,qc,ma,Qn,0,$n,gr+jn,Bi(e,"behind")),es(i,Qn,ma,fr,-Ys-jn,$n,-ts,Bi(e,"front-left")),es(i,Qn,ma,fr,-Ys-jn,$n,ts,Bi(e,"behind-left")),es(i,Qn,ma,fr,Ys+jn,$n,-ts,Bi(e,"front-right")),es(i,Qn,ma,fr,Ys+jn,$n,ts,Bi(e,"behind-right")),t){tv(i,t,$5,.5,Ys,gr,nv);const s=(c,l)=>{const h=[];return Bi(e,c)!==void 0&&h.push({main:fr,center:-ts}),Bi(e,l)!==void 0&&h.push({main:fr,center:ts}),h},a=Bi(e,"front")!==void 0?[{main:qc,center:0}]:[],o=Bi(e,"behind")!==void 0?[{main:qc,center:0}]:[];ev(i,Ys,gr,$n-su/2,$n+su/2,ma,a,o,s("front-left","behind-left"),s("front-right","behind-right"))}return i}const Dm=new Map;function Im(r,e){if(!r)return;const t=[[r.lengthM,e.lengthM],[r.heightM,e.heightM],[r.widthM,e.widthM]];for(const[i,n]of t)if(i!==void 0&&n>1e-6)return i/n}function au(r,e){return e>1e-6?r/e:1}const sv=[.95,.9,.82],Cm=[.72,.74,.78];function Pm(){const r=new Dt;Nt(r,new cs(.25,.3,1.5,10),Cm,.75),Nt(r,new ri(.26,10,8),Cm,1.74);const e=Nt(r,new Gr(.07,.16,8),sv,1.74);return e.rotation.x=-Math.PI/2,e.position.z=-.22,r}function t0(){const r=new Dt;Nt(r,new cs(.25,.3,1.5,10),[.3,.3,.35],.75),Nt(r,new ri(.22,10,8),[.62,.52,.46],1.72);const e=Nt(r,new Gr(.07,.16,8),sv,1.72);return e.rotation.x=-Math.PI/2,e.position.z=-.2,r}const sE=17,Lm=18.5,ru=[.16,.16,.18];function Om(){const r=new Dt,e=Nt(r,new cs(1.8,1.8,Lm*2,10),ru,0);e.rotation.x=Math.PI/2,Nt(r,new Wi(sE*2,.5,4.5),ru,0);const t=Nt(r,new Wi(.4,5.5,4),ru,3);return t.position.z=-Lm+2,r}class hi{static GROWS_FROM_GROUND=new Set(["tree","shrub","crop","mound"]);static groundUnderFootprint(e,t,i,n,s,a=0){const o=hi.sizeOf(e);if(a>o.heightM)return s(t,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=hi.GROWS_FROM_GROUND.has(e.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=t+Math.sin(c)*p+Math.cos(c)*m,_=i-Math.cos(c)*p+Math.sin(c)*m;d=u?Math.min(d,s(g,_)):Math.max(d,s(g,_))}}return Number.isFinite(d)?d:s(t,i)}static occupantView(e){const t=e.observerSide;if(!t)throw new Error("occupantView requires object.observerSide to be set");const{x:i,z:n}=e.kind==="vehicle"?jd(t,Ys,gr,nv):jd(t,Qd/2,e0/2,iv),s=e.kind==="vehicle"?nE:(e.occupiedFloor??0)*Zs+K5,a=(e.headingDeg??0)-Q1[t]/tu,o=this.scaleFor(e);return{x:i*o.x,z:n*o.z,eyeY:s*o.y,headingDeg:a}}static BODY_NAME="decor-body";static bodyOf(e){return e.getObjectByName(hi.BODY_NAME)??e}static repeatOnGrid(e,t,i,n,s){const a=e.getAttribute("position"),o=e.getAttribute("normal"),c=e.getIndex();if(!c)throw new Error("repeatOnGrid needs an indexed geometry");const l=a.count,h=t*n,u=new Float32Array(l*h*3),d=new Float32Array(l*h*3),f=new Uint32Array(c.count*h),p=-((t-1)*i)/2,v=-((n-1)*s)/2;let m=0;for(let _=0;_<n;_++)for(let b=0;b<t;b++,m++){const M=v+_*s,S=p+b*i;for(let w=0;w<l;w++){const T=(m*l+w)*3;u[T]=a.getX(w)+M,u[T+1]=a.getY(w),u[T+2]=a.getZ(w)+S,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 ot;return g.setAttribute("position",new ut(u,3)),g.setAttribute("normal",new ut(d,3)),g.setIndex(new E0(f,1)),g}static fitCropToGround(e,t){e.updateMatrixWorld(!0);const i=new R;e.traverse(n=>{const s=n,a=s.userData.cropBasePositions,o=s.userData.cropVerticesPerClump;if(!s.isMesh||!a||!o)return;const c=s.geometry.getAttribute("position"),l=new Ze().copy(s.matrixWorld).invert();for(let h=0;h<c.count;h+=o){i.set(a[h*3],0,a[h*3+2]).applyMatrix4(s.matrixWorld),i.y=t(i.x,i.z),i.applyMatrix4(l);for(let u=h;u<h+o;u++)c.setY(u,a[u*3+1]+i.y)}c.needsUpdate=!0,s.geometry.computeBoundingBox(),s.geometry.computeBoundingSphere()})}static paint(e,t){e.traverse(i=>{const n=i,s=n.userData;if(!n.isMesh||s?.emissive)return;const a=n.material;a?.color&&a.color.set(t)})}static build(e,t){const i=e.kind==="building"?bm(e.floors??df,e.windows,e.observerSide,e.occupiedFloor):e.kind==="tree"?Sm():e.kind==="shrub"?_m():e.kind==="bridge"?Z5(e):e.kind==="crop"?Em():e.kind==="mound"?Am():e.kind==="streetlight"?Tm(t):e.kind==="vehicle"?Rm(t,e.windows,e.observerSide):e.kind==="aircraft"?Om():e.kind==="entity"?Pm():t0();e.color&&this.paint(i,e.color);const n=this.scaleFor(e),s=new Dt;return i.name=hi.BODY_NAME,i.scale.copy(n),s.add(i),e.headingDeg!==void 0&&(s.rotation.y=-e.headingDeg*tu),this.addLights(s,e.lights),s}static scaleFor(e){const t=e.sizeM;if(!t||e.kind==="bridge")return new R(1,1,1);const i=this.naturalSize(e.kind,e.floors);return new R(t.widthM===void 0?1:au(t.widthM,i.widthM),t.heightM===void 0?1:au(t.heightM,i.heightM),t.lengthM===void 0?1:au(t.lengthM,i.lengthM))}static naturalSize(e,t){const i=e==="building"?Math.max(1,(t??df)+1):0;if(e==="bridge")return Pt.NATURAL_SIZE;const n=`${e}:${i}`,s=Dm.get(n);if(s)return s;const a=e==="building"?bm(i-1,void 0,void 0,void 0):e==="tree"?Sm():e==="shrub"?_m():e==="crop"?Em():e==="mound"?Am():e==="streetlight"?Tm(!1):e==="vehicle"?Rm(!1,void 0,void 0):e==="aircraft"?Om():e==="entity"?Pm():t0(),o=new Vi().setFromObject(a),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(a),Dm.set(n,c),c}static usesModel(e){return e.model!==void 0&&!(e.observerSide!==void 0&&bg(e.kind))}static applyModel(e,t,i,n={}){const s=this.bodyOf(e),a=new Dt;a.name=hi.BODY_NAME,i.rotation.y=-(n.headingOffsetDeg??0)*tu,i.updateMatrixWorld(!0);const o=new Vi().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=Im(t.sizeM,c)??Im(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-=t.kind==="aircraft"?h.y:o.min.y*l,i.traverse(u=>{u instanceof De&&(u.castShadow=!0,u.receiveShadow=!0)}),a.add(i),s.parent?(s.parent.add(a),s.removeFromParent()):e.add(a),this.dispose(s)}static sizeOf(e){const t=this.naturalSize(e.kind,e.floors);return{widthM:e.sizeM?.widthM??t.widthM,lengthM:e.sizeM?.lengthM??t.lengthM,heightM:e.sizeM?.heightM??t.heightM}}static addLights(e,t){for(const i of t??[]){const n=V5(i.color),s=Nt(e,new ri(iu,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}}static setLights(e,t,i,n,s=0,a=1,o=U5){if(!t||t.length===0)return;const c=new Map(t.map(d=>[d.id,d])),l=Math.max(1,n*o/iu),h=iu*l,u=a/(Math.PI*h*h);for(const d of e.children){if(!(d instanceof De))continue;const f=d.userData.lightId;if(!f)continue;const p=c.get(f);if(!p)continue;const v=s>0?Sg(p,i,i+s):Bv(p,i)?1:0;d.visible=v>0;const m=d.material,g=d.userData.lightColor;if(g){const _=v*k5*(p.intensity??1)*u;m.color.setRGB(g[0]*_,g[1]*_,g[2]*_)}d.scale.setScalar(l)}}static setLit(e,t,i,n=1){const[s,a,o]=t==="streetlight"?[z5,B5,J1]:[H5,G5,j1],c=i?s*n/(Math.PI*a*a):0,l=[o[0]*c,o[1]*c,o[2]*c];e.traverse(h=>{const u=h.userData;!(h instanceof De)||!u.emissive||u.lightId||h.material.color.setRGB(...l)})}static dispose(e){e.traverse(t=>{if(!(t instanceof De))return;t.geometry.dispose();const i=t.material;for(const n of Array.isArray(i)?i:[i])n.dispose()})}}const ou="https://ufoathome.org/models/index.json";class aE{attribution="3D models re-hosted by UFO@home, each under its own author's licence";fetchImpl;indexUrls;loading;constructor(e={}){this.fetchImpl=e.fetchImpl??fetch.bind(globalThis),this.indexUrls=e.indexUrls??rE()}async entries(e){const t=await this.load();return e?t.filter(i=>i.kind===e):t}async entry(e){return(await this.load()).find(t=>t.id===e)}load(){return this.loading??=this.fetchFirstAvailable(),this.loading}async fetchFirstAvailable(){for(const e of this.indexUrls){const t=await this.fetchIndex(e);if(t)return t}return[]}async fetchIndex(e){try{const t=await this.fetchImpl(e);if(!t.ok)return;const i=await t.json();return Array.isArray(i?.models)?i.models.map(({file:n,...s})=>({...s,url:new URL(n,e).href})):void 0}catch{return}}}function rE(){const r=`?v=${encodeURIComponent("0.74.0")}`,e=typeof location>"u"?void 0:new URL("/models/index.json",location.href).href;return(e&&e!==ou?[e,ou]:[ou]).map(t=>t+r)}const oE=[{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 aE}];async function Nm(r){const{GLTFLoader:e}=await pi(async()=>{const{GLTFLoader:i}=await import("./GLTFLoader-D3g0zZHB.js");return{GLTFLoader:i}},[],import.meta.url),t=new e;return new Promise((i,n)=>{t.load(r,s=>i(Object.assign(s.scene,{animations:s.animations})),void 0,s=>n(new Error(`Could not load 3D model ${r}: ${s instanceof Error?s.message:String(s)}`)))})}const av=["ellipsoid","sphere","disc","cylinder","cone","box","torus","figure"];class hn{static MIN_ANGLE_RAD=.002;static FILL=(1-Math.exp(-4))/4;static MAX_SHARE=.3;mesh;constructor(e,t){this.mesh=new De(new Xi(2,2),new ct({uniforms:{uColor:{value:new se(0,0,0)},uRadius:{value:1}},vertexShader:hn.VERTEX,fragmentShader:hn.FRAGMENT,transparent:!0,depthWrite:!1,blending:Ni,toneMapped:!1})),this.mesh.name=e,this.mesh.frustumCulled=!1,this.mesh.renderOrder=t,this.mesh.visible=!1}shine(e,t,i){this.mesh.visible=!0,this.mesh.position.set(e.x,e.y,e.z),this.mesh.material.uniforms.uRadius.value=t,this.mesh.material.uniforms.uColor.value.setRGB(i[0],i[1],i[2])}hide(){this.mesh.visible=!1}dispose(){this.mesh.geometry.dispose(),this.mesh.material.dispose()}static spread(e,t,i,n){const s=Math.max(e,n*hn.MIN_ANGLE_RAD),a=hn.FILL*Math.PI*s*s;return{radiusM:s,luminanceCdM2:i*Math.min(hn.MAX_SHARE,t/a)}}static conserving(e){return Math.sqrt(e/(hn.MAX_SHARE*hn.FILL*Math.PI))}static VERTEX=`
|
|
7151
|
+
`,transparent:!0,blending:Ni,depthWrite:!1,side:Ht,fog:!1}),this.object=new De(new ri(Ci.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(e){this.hostedByDeck=e,this.show(this.shown)}show(e){this.shown=e,this.object.visible=e&&!this.hostedByDeck,this.deckUniforms.uHaloShown.value=e?1:0}get awaitingFirstDisplay(){return this.tracing&&!this.everDisplayed}setUrgent(e){this.urgent=e}set onReady(e){this.onRepaint=e}update(e,t,i,n,s,a){const o=this.material.uniforms;if(i<=0){o.uStrength.value=0,this.show(!1),this.stopWork();return}o.uSource.value.set(e.x,e.y,e.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(t,a)}requestMap(e,t){if(!(!(Math.abs(e-this.mappedAltitudeDeg)<Ci.ALTITUDE_STEP_DEG)||!(Math.abs(t-this.mappedAlignment)<Ci.ALIGNMENT_STEP))){this.next=void 0;return}if(this.tracing){if(this.tracingFor(e,t)){this.next=void 0;return}if(!(!(Math.abs(e-this.pendingAltitudeDeg)<Ci.LEAP_ALTITUDE_DEG)||!(Math.abs(t-this.pendingAlignment)<Ci.LEAP_ALIGNMENT))){this.next={sourceAltitudeDeg:e,alignment:t};return}}this.next=void 0,this.pendingAltitudeDeg=e,this.pendingAlignment=t,this.sky.begin(e,t),this.tracing=!0,this.scheduleWork()}pendingAltitudeDeg=Number.NaN;pendingAlignment=Number.NaN;next;tracingFor(e,t){return this.tracing&&Math.abs(e-this.pendingAltitudeDeg)<Ci.ALTITUDE_STEP_DEG&&Math.abs(t-this.pendingAlignment)<Ci.ALIGNMENT_STEP}scheduleWork(){if(this.workHandle!==void 0)return;const e=()=>{if(this.workHandle=void 0,!this.tracing)return;const t=performance.now(),i=this.urgent?Ci.URGENT_BUDGET_MS:Ci.BUDGET_MS;do this.sky.trace(Ci.RAYS_PER_BATCH);while(this.sky.tracedRays<Ci.RAYS&&performance.now()-t<i);if(this.sky.tracedRays>=Ci.RAYS){this.publish(),this.tracing=!1,this.mappedAltitudeDeg=this.pendingAltitudeDeg,this.mappedAlignment=this.pendingAlignment;const s=this.next;s&&this.requestMap(s.sourceAltitudeDeg,s.alignment);return}this.workHandle=requestAnimationFrame(e)};this.workHandle=requestAnimationFrame(e)}stopWork(){this.workHandle!==void 0&&cancelAnimationFrame(this.workHandle),this.workHandle=void 0,this.tracing=!1,this.next=void 0}publish(){const t=this.sky.harvest().data;for(let i=0,n=0;n<t.length;i+=4,n+=3)this.texels[i]=kn.toHalfFloat(t[n]),this.texels[i+1]=kn.toHalfFloat(t[n+1]),this.texels[i+2]=kn.toHalfFloat(t[n+2]),this.texels[i+3]=1;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 xi{static MAX_CONCURRENT=24;static POINTS=8;static SEGMENTS=xi.POINTS-1;static ACROSS=3;static VERTICES_PER_SEGMENT=(xi.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 e=xi.MAX_CONCURRENT*xi.SEGMENTS*xi.VERTICES_PER_SEGMENT;this.positions=new Float32Array(e*3),this.colors=new Float32Array(e*3);const t=new ot;t.setAttribute("position",new tt(this.positions,3)),t.setAttribute("color",new tt(this.colors,3)),t.setDrawRange(0,0),this.object=new De(t,new bn({vertexColors:!0,transparent:!0,blending:Ni,depthWrite:!1,fog:!1,side:Qi})),this.object.frustumCulled=!1}get schedule(){return this.meteors}setShower(e,t,i){this.meteors=e,this.radiantAltitudeDeg=t,this.radiantAzimuthDeg=i}update(e){const t=this.object.geometry;if(this.meteors.length===0){t.setDrawRange(0,0);return}const i=Oa.aliveAt(this.meteors,e).slice(0,xi.MAX_CONCURRENT);let n=0;for(const{meteor:s,progress:a}of i){const o=this.radiantOf(s);if(!o)continue;const c=li(o.altitudeDeg,o.azimuthDeg,1),[l,h]=this.basisAround(c),u=s.fromRadiantDeg+a*s.lengthDeg,d=Math.max(s.fromRadiantDeg,u-s.lengthDeg*.6),f=Math.min(1,(1-a)*2.5),p=this.turn(l,h,s.bearingDeg),v=(.15+.85*s.brightness)*f,m=b=>v*b**1.6,g=b=>this.onSphere(c,p,d+(u-d)*b),_=b=>xi.RADIUS*((xi.MIN_HALF_WIDTH_DEG+xi.BRIGHT_HALF_WIDTH_DEG*s.brightness*b)*Math.PI/180);for(let b=1;b<xi.POINTS;b++){const M=(b-1)/xi.SEGMENTS,S=b/xi.SEGMENTS;n=this.pushRibbon(n,g(M),g(S),_(M),_(S),m(M),m(S))}}t.setDrawRange(0,n),t.getAttribute("position").needsUpdate=!0,t.getAttribute("color").needsUpdate=!0}midpointOf(e){const t=this.radiantOf(e);if(!t)return;const i=li(t.altitudeDeg,t.azimuthDeg,1),[n,s]=this.basisAround(i),a=this.turn(n,s,e.bearingDeg),o=this.onSphere(i,a,e.fromRadiantDeg+e.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(e){return e.radiant?e.radiant:this.radiantAltitudeDeg>0?{altitudeDeg:this.radiantAltitudeDeg,azimuthDeg:this.radiantAzimuthDeg}:void 0}pushRibbon(e,t,i,n,s,a,o){const c=this.normalise(this.cross(this.normalise(t),this.normalise(this.subtract(i,t))));for(let l=0;l<xi.ACROSS-1;l++){const h=l-1,u=l,d=this.across(t,c,n,h),f=this.across(i,c,s,h),p=this.across(t,c,n,u),v=this.across(i,c,s,u),m=(g,_)=>g===0?_:0;e=this.push(e,d,m(h,a)),e=this.push(e,f,m(h,o)),e=this.push(e,p,m(u,a)),e=this.push(e,f,m(h,o)),e=this.push(e,v,m(u,o)),e=this.push(e,p,m(u,a))}return e}across(e,t,i,n){return{x:e.x+t.x*i*n,y:e.y+t.y*i*n,z:e.z+t.z*i*n}}push(e,t,i){const n=e*3;this.positions[n]=t.x,this.positions[n+1]=t.y,this.positions[n+2]=t.z;const s=Ae.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,e+1}turn(e,t,i){const n=i*Math.PI/180,s=Math.cos(n),a=Math.sin(n);return{x:e.x*s+t.x*a,y:e.y*s+t.y*a,z:e.z*s+t.z*a}}onSphere(e,t,i){const n=i*Math.PI/180,s=Math.cos(n),a=Math.sin(n);return{x:(e.x*s+t.x*a)*xi.RADIUS,y:(e.y*s+t.y*a)*xi.RADIUS,z:(e.z*s+t.z*a)*xi.RADIUS}}basisAround(e){const t=Math.abs(e.y)<.9?{x:0,y:1,z:0}:{x:1,y:0,z:0},i=this.normalise(this.cross(e,t));return[i,this.normalise(this.cross(e,i))]}subtract(e,t){return{x:e.x-t.x,y:e.y-t.y,z:e.z-t.z}}cross(e,t){return{x:e.y*t.z-e.z*t.y,y:e.z*t.x-e.x*t.z,z:e.x*t.y-e.y*t.x}}normalise(e){const t=Math.hypot(e.x,e.y,e.z)||1;return{x:e.x/t,y:e.y/t,z:e.z/t}}dispose(){this.object.geometry.dispose(),this.object.material.dispose()}}class Pt{constructor(e,t={}){this.size=e,this.span=Math.min(e.lengthM,Math.max(0,t.spanM??e.lengthM)),this.bank=(e.lengthM-this.span)/2,this.deck=Math.min(e.heightM,t.deckThicknessM??Pt.DEFAULT_DECK_THICKNESS_M),this.railHeight=t.railing?.heightM??Pt.DEFAULT_RAILING_HEIGHT_M,this.postSpacing=Math.max(.3,t.railing?.postSpacingM??Pt.DEFAULT_POST_SPACING_M),this.rails=Math.max(0,Math.round(t.railing?.rails??Pt.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(e){const t=Math.abs(e)-this.span/2;return t<=0?this.size.heightM:this.bank<=0?0:Math.max(0,this.size.heightM*(1-t/this.bank))}build(){const{widthM:e,heightM:t}=this.size,i=this.span/2,n=[];if(this.span>0){n.push(Pt.box(e,this.deck,this.span,0,t-this.deck/2,0));for(const c of[-1,1]){const l=t-this.deck;l>0&&this.bank>0&&n.push(Pt.box(e+1,l,Pt.ABUTMENT_THICKNESS_M,0,l/2,c*(i-Pt.ABUTMENT_THICKNESS_M/2)))}}const s=[];this.span>0&&s.push(Pt.box(e,.04,this.span,0,t+.02,0));const a=[];for(const c of[-1,1])this.bank<=0||(a.push(this.embankment(c)),s.push(this.bankRoad(c)));const o=[];for(const c of[-1,1])o.push(...this.railing(c*(e/2-Pt.POST_SIDE_M)));return{concrete:Pt.merge(n),road:Pt.merge(s),earth:Pt.merge(a),railing:Pt.merge(o)}}embankment(e){const t=this.size.widthM/2,i=this.stations(e),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)},a=l=>{const h=this.roadAt(l),u=t+Pt.BANK_SLOPE*h;return{leftFoot:new R(-u,0,l),leftTop:new R(-t,h,l),rightTop:new R(t,h,l),rightFoot:new R(u,0,l)}};for(let l=1;l<i.length;l++){const h=a(i[l-1]),u=a(i[l]),d=e>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=a(i[0]);e>0?s(o.leftFoot,o.rightFoot,o.rightTop,o.leftTop):s(o.leftTop,o.rightTop,o.rightFoot,o.leftFoot);const c=new ot;return c.setAttribute("position",new ut(n,3)),c.computeVertexNormals(),c}bankRoad(e){const t=this.size.widthM/2,i=this.stations(e),n=[];for(let a=1;a<i.length;a++){const o=i[a-1],c=i[a],l=this.roadAt(o)+.02,h=this.roadAt(c)+.02,u=e>0?[[-t,l,o],[t,l,o],[t,h,c],[-t,h,c]]:[[-t,h,c],[t,h,c],[t,l,o],[-t,l,o]];for(const d of[0,2,1,0,3,2])n.push(...u[d])}const s=new ot;return s.setAttribute("position",new ut(n,3)),s.computeVertexNormals(),s}stations(e){const t=[];for(let i=0;i<=Pt.BANK_STATIONS;i++)t.push(e*(this.span/2+this.bank*i/Pt.BANK_STATIONS));return t}railing(e){const t=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(-t+this.size.lengthM*o/i);const s=[],a=Pt.POST_SIDE_M;for(const o of n)s.push(Pt.box(a,this.railHeight,a,e,this.roadAt(o)+this.railHeight/2,o));for(let o=1;o<=this.rails;o++){const c=this.railHeight*o/this.rails-Pt.RAIL_HEIGHT_M/2;for(let l=1;l<n.length;l++){const h=new R(e,this.roadAt(n[l-1])+c,n[l-1]),u=new R(e,this.roadAt(n[l])+c,n[l]);s.push(Pt.beam(h,u))}}return s}static box(e,t,i,n,s,a){return new Xi(e,t,i).translate(n,s,a)}static beam(e,t){const i=new R().subVectors(t,e),n=new Xi(Pt.RAIL_DEPTH_M,Pt.RAIL_HEIGHT_M,i.length()),s=new en().setFromUnitVectors(new R(0,0,1),i.clone().normalize()),a=new R().addVectors(e,t).multiplyScalar(.5);return n.applyMatrix4(new Ze().compose(a,s,new R(1,1,1)))}static merge(e){const t=e.map(c=>c.getIndex()?c.toNonIndexed():c),i=t.reduce((c,l)=>c+l.getAttribute("position").count,0),n=new Float32Array(i*3),s=new Float32Array(i*3);let a=0;for(const c of t){const l=c.getAttribute("position"),h=c.getAttribute("normal");n.set(l.array,a*3),h&&s.set(h.array,a*3),a+=l.count}const o=new ot;o.setAttribute("position",new ut(n,3)),o.setAttribute("normal",new ut(s,3));for(const c of e)c.dispose();for(const c of t)c.dispose();return o}}const tu=Math.PI/180;function Nt(r,e,t,i,n=!1){const s=n?new bn({color:new se(...t)}):new Vr({color:new se(...t)}),a=new De(e,s);return a.position.y=i,a.userData={emissive:n},a.castShadow=!n,a.receiveShadow=!n,r.add(a),a}const iu=.25,U5=.002,k5=100,z5=1500,B5=.25,H5=1e3,G5=.15;function V5(r){const e=/^#([0-9a-f]{6})$/i.exec(r);if(!e)return[1,1,1];const t=parseInt(e[1],16);return[(t>>16&255)/255,(t>>8&255)/255,(t&255)/255]}const W5=[.32,.32,.3],J1=[1,.85,.5],X5=[.25,.25,.25],j1=[1,.97,.85],Y5=[.55,.68,.72],jn=.03,Qn=.05,Q1={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 Bi(r,e){return r?.[e]}function es(r,e,t,i,n,s,a,o){if(o===void 0)return;const c=new Vr({color:new se(...Y5),transparent:!0,opacity:o/100}),l=new De(new Xi(e,t,i),c);l.position.set(n,s,a),r.add(l)}const Mn=.05,nu=[.6,.58,.53],ym=[.5,.5,.48];function _r(r,e,t,i,n,s,a,o){const c=new Vr({color:new se(...o),side:Ht}),l=new De(new Xi(e,t,i),c);l.position.set(n,s,a),r.add(l)}function q5(r,e,t,i,n,s,a,o,c){const l=(i-s)/2,h=(p,v,m,g)=>{p<=0||(e?_r(r,p,v,Mn,m,o+g,a,c):_r(r,Mn,v,p,a,o+g,m,c))};h(t,l,0,i/2-l/2),h(t,l,0,-(i/2-l/2));const u=[...n].sort((p,v)=>p.center-v.center);let d=-t/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=t/2-d;h(f,s,d+f/2,0)}function ev(r,e,t,i,n,s,a,o,c,l){const h=(i+n)/2,u=n-i,d=(f,p,v,m)=>{f.length===0?p?_r(r,v,u,Mn,0,h,m,nu):_r(r,Mn,u,v,m,h,0,nu):q5(r,p,v,u,f,s,m,h,nu)};d(a,!0,e*2,-t+Mn),d(o,!0,e*2,t-Mn),d(c,!1,t*2,-e+Mn),d(l,!1,t*2,e-Mn),_r(r,e*2,Mn,t*2,0,i+Mn,0,ym),_r(r,e*2,Mn,t*2,0,n-Mn,0,ym)}function jd(r,e,t,i){switch(r){case"front":return{x:0,z:-(t-i)};case"behind":return{x:0,z:t-i};case"left":return{x:-(e-i),z:0};case"right":return{x:e-i,z:0};case"front-left":return{x:-(e-i),z:-ts};case"front-right":return{x:e-i,z:-ts};case"behind-left":return{x:-(e-i),z:ts};case"behind-right":return{x:e-i,z:ts}}}function tv(r,e,t,i,n,s,a){const o=t0();o.scale.setScalar(i),o.rotation.y=Q1[e];const{x:c,z:l}=jd(e,n,s,a);o.position.set(c,t,l),r.add(o)}const Qd=6,e0=6,Zs=3,ho=1.4,uo=Zs*.5,iv=1.2,nv=.35,$5=.75,K5=1.6;function bm(r,e,t,i){const n=new Dt,s=Math.max(1,r+1),a=s*Zs;Nt(n,new Xi(Qd,a,e0),[.55,.54,.5],a/2);const o=Qd/2,c=e0/2;for(let l=0;l<s;l++){const h=l*Zs+Zs/2;es(n,ho,uo,Qn,0,h,-c-jn,Bi(e,"front")),es(n,ho,uo,Qn,0,h,c+jn,Bi(e,"behind")),es(n,Qn,uo,ho,-o-jn,h,0,Bi(e,"left")),es(n,Qn,uo,ho,o+jn,h,0,Bi(e,"right"))}if(t){const l=Math.min(Math.max(i??0,0),s-1);tv(n,t,l*Zs,.72,o,c,iv);const h=u=>Bi(e,u)!==void 0?[{main:ho,center:0}]:[];ev(n,o,c,l*Zs,(l+1)*Zs,uo,h("front"),h("behind"),h("left"),h("right"))}return n}function _m(){const r=new Dt,e=[[0,0,.55,.5],[.4,.1,.35,.4],[-.35,-.2,.4,.38],[.1,-.4,.35,.36],[-.15,.4,.3,.34]];for(const[t,i,n,s]of e){const a=new ri(n,10,7);a.scale(1,.85,1),a.translate(t,0,i),Nt(r,a,[.26,.28,.17],s)}return r}function Z5(r){const e=new Dt,t=new Pt(hi.sizeOf(r),r.bridge).build();Nt(e,t.concrete,[.6,.6,.58],0);const i=Nt(e,t.road,[.2,.2,.21],0),n=Nt(e,t.earth,[.3,.36,.22],0);for(const s of[i,n])s.material.side=Qi;return Nt(e,t.railing,[.5,.52,.55],0),e}function Sm(){const r=new Dt;return Nt(r,new cs(.15,.22,2,8),[.32,.22,.14],1),Nt(r,new Gr(1.4,3,8),[.16,.32,.14],3.5),r}const wm=.275,J5=.35,j5=.9,Q5=34,eE=8,tE=1.4;function Em(){const r=new Dt,e=new ri(wm,7,3,0,Math.PI*2,0,Math.PI/2);e.scale(1,J5/wm,1);const t=hi.repeatOnGrid(e,Q5,j5,eE,tE),i=Nt(r,t,[.26,.28,.22],0);return i.castShadow=!0,i.userData.cropBasePositions=t.getAttribute("position").array.slice(),i.userData.cropVerticesPerClump=e.getAttribute("position").count,e.dispose(),r}function Am(){const r=new Dt,e=new ri(1,7,3,0,Math.PI*2,0,Math.PI/2);return Nt(r,e,[.38,.36,.32],0),r}function Tm(r){const e=new Dt;return Nt(e,new cs(.05,.08,5,8),[.28,.28,.3],2.5),Nt(e,new ri(.25,12,8),r?J1:W5,5.1,!0),e}const iE=[.08,.08,.08],Ys=.8,gr=1,$n=1.7,su=.6,ma=.4,qc=1.2,fr=.7,ts=.5,nE=$n;function Rm(r,e,t){const i=new Dt;Nt(i,new Xi(1.8,1.4,4.2),[.45,.14,.14],.7),Nt(i,new Xi(Ys*2,su,gr*2),[.4,.12,.12],$n);for(const s of[-1.4,1.4])for(const a of[-.95,.95]){const o=Nt(i,new cs(.4,.4,.3,12),iE,.4);o.rotation.z=Math.PI/2,o.position.x=a,o.position.z=s}const n=r?j1:X5;for(const s of[-.7,.7])Nt(i,new ri(.15,8,6),n,.7,!0).position.set(s,.7,-2.1);if(es(i,qc,ma,Qn,0,$n,-gr-jn,Bi(e,"front")),es(i,qc,ma,Qn,0,$n,gr+jn,Bi(e,"behind")),es(i,Qn,ma,fr,-Ys-jn,$n,-ts,Bi(e,"front-left")),es(i,Qn,ma,fr,-Ys-jn,$n,ts,Bi(e,"behind-left")),es(i,Qn,ma,fr,Ys+jn,$n,-ts,Bi(e,"front-right")),es(i,Qn,ma,fr,Ys+jn,$n,ts,Bi(e,"behind-right")),t){tv(i,t,$5,.5,Ys,gr,nv);const s=(c,l)=>{const h=[];return Bi(e,c)!==void 0&&h.push({main:fr,center:-ts}),Bi(e,l)!==void 0&&h.push({main:fr,center:ts}),h},a=Bi(e,"front")!==void 0?[{main:qc,center:0}]:[],o=Bi(e,"behind")!==void 0?[{main:qc,center:0}]:[];ev(i,Ys,gr,$n-su/2,$n+su/2,ma,a,o,s("front-left","behind-left"),s("front-right","behind-right"))}return i}const Dm=new Map;function Im(r,e){if(!r)return;const t=[[r.lengthM,e.lengthM],[r.heightM,e.heightM],[r.widthM,e.widthM]];for(const[i,n]of t)if(i!==void 0&&n>1e-6)return i/n}function au(r,e){return e>1e-6?r/e:1}const sv=[.95,.9,.82],Cm=[.72,.74,.78];function Pm(){const r=new Dt;Nt(r,new cs(.25,.3,1.5,10),Cm,.75),Nt(r,new ri(.26,10,8),Cm,1.74);const e=Nt(r,new Gr(.07,.16,8),sv,1.74);return e.rotation.x=-Math.PI/2,e.position.z=-.22,r}function t0(){const r=new Dt;Nt(r,new cs(.25,.3,1.5,10),[.3,.3,.35],.75),Nt(r,new ri(.22,10,8),[.62,.52,.46],1.72);const e=Nt(r,new Gr(.07,.16,8),sv,1.72);return e.rotation.x=-Math.PI/2,e.position.z=-.2,r}const sE=17,Lm=18.5,ru=[.16,.16,.18];function Om(){const r=new Dt,e=Nt(r,new cs(1.8,1.8,Lm*2,10),ru,0);e.rotation.x=Math.PI/2,Nt(r,new Xi(sE*2,.5,4.5),ru,0);const t=Nt(r,new Xi(.4,5.5,4),ru,3);return t.position.z=-Lm+2,r}class hi{static GROWS_FROM_GROUND=new Set(["tree","shrub","crop","mound"]);static groundUnderFootprint(e,t,i,n,s,a=0){const o=hi.sizeOf(e);if(a>o.heightM)return s(t,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=hi.GROWS_FROM_GROUND.has(e.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=t+Math.sin(c)*p+Math.cos(c)*m,_=i-Math.cos(c)*p+Math.sin(c)*m;d=u?Math.min(d,s(g,_)):Math.max(d,s(g,_))}}return Number.isFinite(d)?d:s(t,i)}static occupantView(e){const t=e.observerSide;if(!t)throw new Error("occupantView requires object.observerSide to be set");const{x:i,z:n}=e.kind==="vehicle"?jd(t,Ys,gr,nv):jd(t,Qd/2,e0/2,iv),s=e.kind==="vehicle"?nE:(e.occupiedFloor??0)*Zs+K5,a=(e.headingDeg??0)-Q1[t]/tu,o=this.scaleFor(e);return{x:i*o.x,z:n*o.z,eyeY:s*o.y,headingDeg:a}}static BODY_NAME="decor-body";static bodyOf(e){return e.getObjectByName(hi.BODY_NAME)??e}static repeatOnGrid(e,t,i,n,s){const a=e.getAttribute("position"),o=e.getAttribute("normal"),c=e.getIndex();if(!c)throw new Error("repeatOnGrid needs an indexed geometry");const l=a.count,h=t*n,u=new Float32Array(l*h*3),d=new Float32Array(l*h*3),f=new Uint32Array(c.count*h),p=-((t-1)*i)/2,v=-((n-1)*s)/2;let m=0;for(let _=0;_<n;_++)for(let b=0;b<t;b++,m++){const M=v+_*s,S=p+b*i;for(let w=0;w<l;w++){const T=(m*l+w)*3;u[T]=a.getX(w)+M,u[T+1]=a.getY(w),u[T+2]=a.getZ(w)+S,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 ot;return g.setAttribute("position",new ut(u,3)),g.setAttribute("normal",new ut(d,3)),g.setIndex(new E0(f,1)),g}static fitCropToGround(e,t){e.updateMatrixWorld(!0);const i=new R;e.traverse(n=>{const s=n,a=s.userData.cropBasePositions,o=s.userData.cropVerticesPerClump;if(!s.isMesh||!a||!o)return;const c=s.geometry.getAttribute("position"),l=new Ze().copy(s.matrixWorld).invert();for(let h=0;h<c.count;h+=o){i.set(a[h*3],0,a[h*3+2]).applyMatrix4(s.matrixWorld),i.y=t(i.x,i.z),i.applyMatrix4(l);for(let u=h;u<h+o;u++)c.setY(u,a[u*3+1]+i.y)}c.needsUpdate=!0,s.geometry.computeBoundingBox(),s.geometry.computeBoundingSphere()})}static paint(e,t){e.traverse(i=>{const n=i,s=n.userData;if(!n.isMesh||s?.emissive)return;const a=n.material;a?.color&&a.color.set(t)})}static build(e,t){const i=e.kind==="building"?bm(e.floors??df,e.windows,e.observerSide,e.occupiedFloor):e.kind==="tree"?Sm():e.kind==="shrub"?_m():e.kind==="bridge"?Z5(e):e.kind==="crop"?Em():e.kind==="mound"?Am():e.kind==="streetlight"?Tm(t):e.kind==="vehicle"?Rm(t,e.windows,e.observerSide):e.kind==="aircraft"?Om():e.kind==="entity"?Pm():t0();e.color&&this.paint(i,e.color);const n=this.scaleFor(e),s=new Dt;return i.name=hi.BODY_NAME,i.scale.copy(n),s.add(i),e.headingDeg!==void 0&&(s.rotation.y=-e.headingDeg*tu),this.addLights(s,e.lights),s}static scaleFor(e){const t=e.sizeM;if(!t||e.kind==="bridge")return new R(1,1,1);const i=this.naturalSize(e.kind,e.floors);return new R(t.widthM===void 0?1:au(t.widthM,i.widthM),t.heightM===void 0?1:au(t.heightM,i.heightM),t.lengthM===void 0?1:au(t.lengthM,i.lengthM))}static naturalSize(e,t){const i=e==="building"?Math.max(1,(t??df)+1):0;if(e==="bridge")return Pt.NATURAL_SIZE;const n=`${e}:${i}`,s=Dm.get(n);if(s)return s;const a=e==="building"?bm(i-1,void 0,void 0,void 0):e==="tree"?Sm():e==="shrub"?_m():e==="crop"?Em():e==="mound"?Am():e==="streetlight"?Tm(!1):e==="vehicle"?Rm(!1,void 0,void 0):e==="aircraft"?Om():e==="entity"?Pm():t0(),o=new Wi().setFromObject(a),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(a),Dm.set(n,c),c}static usesModel(e){return e.model!==void 0&&!(e.observerSide!==void 0&&bg(e.kind))}static applyModel(e,t,i,n={}){const s=this.bodyOf(e),a=new Dt;a.name=hi.BODY_NAME,i.rotation.y=-(n.headingOffsetDeg??0)*tu,i.updateMatrixWorld(!0);const o=new Wi().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=Im(t.sizeM,c)??Im(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-=t.kind==="aircraft"?h.y:o.min.y*l,i.traverse(u=>{u instanceof De&&(u.castShadow=!0,u.receiveShadow=!0)}),a.add(i),s.parent?(s.parent.add(a),s.removeFromParent()):e.add(a),this.dispose(s)}static sizeOf(e){const t=this.naturalSize(e.kind,e.floors);return{widthM:e.sizeM?.widthM??t.widthM,lengthM:e.sizeM?.lengthM??t.lengthM,heightM:e.sizeM?.heightM??t.heightM}}static addLights(e,t){for(const i of t??[]){const n=V5(i.color),s=Nt(e,new ri(iu,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}}static setLights(e,t,i,n,s=0,a=1,o=U5){if(!t||t.length===0)return;const c=new Map(t.map(d=>[d.id,d])),l=Math.max(1,n*o/iu),h=iu*l,u=a/(Math.PI*h*h);for(const d of e.children){if(!(d instanceof De))continue;const f=d.userData.lightId;if(!f)continue;const p=c.get(f);if(!p)continue;const v=s>0?Sg(p,i,i+s):Bv(p,i)?1:0;d.visible=v>0;const m=d.material,g=d.userData.lightColor;if(g){const _=v*k5*(p.intensity??1)*u;m.color.setRGB(g[0]*_,g[1]*_,g[2]*_)}d.scale.setScalar(l)}}static setLit(e,t,i,n=1){const[s,a,o]=t==="streetlight"?[z5,B5,J1]:[H5,G5,j1],c=i?s*n/(Math.PI*a*a):0,l=[o[0]*c,o[1]*c,o[2]*c];e.traverse(h=>{const u=h.userData;!(h instanceof De)||!u.emissive||u.lightId||h.material.color.setRGB(...l)})}static dispose(e){e.traverse(t=>{if(!(t instanceof De))return;t.geometry.dispose();const i=t.material;for(const n of Array.isArray(i)?i:[i])n.dispose()})}}const ou="https://ufoathome.org/models/index.json";class aE{attribution="3D models re-hosted by UFO@home, each under its own author's licence";fetchImpl;indexUrls;loading;constructor(e={}){this.fetchImpl=e.fetchImpl??fetch.bind(globalThis),this.indexUrls=e.indexUrls??rE()}async entries(e){const t=await this.load();return e?t.filter(i=>i.kind===e):t}async entry(e){return(await this.load()).find(t=>t.id===e)}load(){return this.loading??=this.fetchFirstAvailable(),this.loading}async fetchFirstAvailable(){for(const e of this.indexUrls){const t=await this.fetchIndex(e);if(t)return t}return[]}async fetchIndex(e){try{const t=await this.fetchImpl(e);if(!t.ok)return;const i=await t.json();return Array.isArray(i?.models)?i.models.map(({file:n,...s})=>({...s,url:new URL(n,e).href})):void 0}catch{return}}}function rE(){const r=`?v=${encodeURIComponent("0.74.1")}`,e=typeof location>"u"?void 0:new URL("/models/index.json",location.href).href;return(e&&e!==ou?[e,ou]:[ou]).map(t=>t+r)}const oE=[{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 aE}];async function Nm(r){const{GLTFLoader:e}=await pi(async()=>{const{GLTFLoader:i}=await import("./GLTFLoader-D3g0zZHB.js");return{GLTFLoader:i}},[],import.meta.url),t=new e;return new Promise((i,n)=>{t.load(r,s=>i(Object.assign(s.scene,{animations:s.animations})),void 0,s=>n(new Error(`Could not load 3D model ${r}: ${s instanceof Error?s.message:String(s)}`)))})}const av=["ellipsoid","sphere","disc","cylinder","cone","box","torus","figure"];class hn{static MIN_ANGLE_RAD=.002;static FILL=(1-Math.exp(-4))/4;static MAX_SHARE=.3;mesh;constructor(e,t){this.mesh=new De(new Yi(2,2),new ct({uniforms:{uColor:{value:new se(0,0,0)},uRadius:{value:1}},vertexShader:hn.VERTEX,fragmentShader:hn.FRAGMENT,transparent:!0,depthWrite:!1,blending:Ni,toneMapped:!1})),this.mesh.name=e,this.mesh.frustumCulled=!1,this.mesh.renderOrder=t,this.mesh.visible=!1}shine(e,t,i){this.mesh.visible=!0,this.mesh.position.set(e.x,e.y,e.z),this.mesh.material.uniforms.uRadius.value=t,this.mesh.material.uniforms.uColor.value.setRGB(i[0],i[1],i[2])}hide(){this.mesh.visible=!1}dispose(){this.mesh.geometry.dispose(),this.mesh.material.dispose()}static spread(e,t,i,n){const s=Math.max(e,n*hn.MIN_ANGLE_RAD),a=hn.FILL*Math.PI*s*s;return{radiusM:s,luminanceCdM2:i*Math.min(hn.MAX_SHARE,t/a)}}static conserving(e){return Math.sqrt(e/(hn.MAX_SHARE*hn.FILL*Math.PI))}static VERTEX=`
|
|
7152
7152
|
uniform float uRadius;
|
|
7153
7153
|
varying vec2 vOffset;
|
|
7154
7154
|
void main() {
|
|
@@ -7288,11 +7288,11 @@ void main()
|
|
|
7288
7288
|
vec3 around = textureCube(uSurroundings, reflect(view, normal)).rgb;
|
|
7289
7289
|
gl_FragColor = vec4(around * wall, wall + (1.0 - wall) * uAbsorption);
|
|
7290
7290
|
}
|
|
7291
|
-
`,transparent:!0,depthWrite:!1,side:Qi,fog:!1,blending:Xl,blendSrc:Bo,blendDst:Ho})}static wallReflectance(e,t,i){const n=i(e,1,t);return 2*n/(1+n)}setSurroundings(e){this.uniforms.uSurroundings.value=e}static reflectedResponse(e,t){return Ae.respond(t*Ae.relativeOfResponse(Math.max(e,1e-5)))}}const $c=Math.PI/180;class ht{constructor(e,t,i=()=>0){this.loadModel=e,this.onModelArrived=t,this.sceneUnitsPerLux=i,this.group.name="bodies"}group=new Dt;built=new Map;token=0;credits=new Map;flames=new Map;glares=new Map;lightVeils=new Map;lightRay=new dl;boxHit=new R;dust=new Map;smoke=[];scratch=new R;aim=new en;down=new R;frame;lastSet;get modelCredits(){return[...this.credits.values()]}set(e,t,i=0,n,s=e.map(a=>a.id)){this.frame=t,this.lastSet=[e,t,i,n,s];const a=new Set;for(const c of e){a.add(c.id);const l=ht.signatureOf(c.model);let h=this.built.get(c.id);(!h||h.signature!==l)&&(h&&this.remove(c.id),h=this.build(c),this.built.set(c.id,h),this.group.add(h.holder));const{holder:u,material:d,glowing:f}=h;u.visible=!0,u.position.set(t.originX+c.eastM,t.originGroundY+c.upM,t.originZ-c.northM),u.rotation.set(c.attitude.pitchDeg*$c,-c.attitude.headingDeg*$c,-c.attitude.rollDeg*$c,"YXZ"),u.scale.set(c.sizeM.widthM,c.sizeM.heightM,c.sizeM.lengthM),d&&ht.paint(d,c,n),f&&ht.light(f,c,n),h.motions&&ht.move(h.motions,c.motions??{}),this.shine(c,u,f,n,t.eye),this.shineLights(c,u,f,t),this.throwFlame(c,u,i,n,t.eye)}const o=new Set(s);for(const[c,{holder:l}]of[...this.built])a.has(c)||(o.has(c)?(l.visible=!1,this.flames.get(c)?.putOut(),this.glares.get(c)?.hide(),this.hideLights(c)):this.remove(c))}shine(e,t,i,n,s){const a=e.appearance.luminanceCdM2;let o=this.glares.get(e.id);if(!(a>0)||!s||i&&i.length>0){o?.hide();return}o||(o=new Pi(`body-veil:${e.id}`),this.glares.set(e.id,o),this.group.add(o.mesh));const c=Math.max(e.sizeM.widthM,e.sizeM.heightM)/2,l=Math.max(t.position.distanceTo(s),c*1.01),h=Math.asin(c/l),u=2*Math.PI*(1-Math.cos(h)),d=i?.find(p=>p.share>=1)?.hue??ht.rgbOf(e.appearance.color),f=this.throughAir(ht.shown(d,a,n),t.position);o.shine(t.position,[f[0]*u,f[1]*u,f[2]*u],h*180/Math.PI)}static glaze(e){e.traverse(t=>{if(!(t instanceof De))return;const i=t.material;!(i instanceof xx)||!(i.transmission>0)||(t.material=new Ko(i.ior),i.dispose(),t.castShadow=!1)})}throughAir(e,t){const i=this.frame?.transmittance?.(t.x,t.y,t.z)??[1,1,1];return[e[0]*i[0],e[1]*i[1],e[2]*i[2]]}static rgbOf(e){const t=new se(e);return[t.r,t.g,t.b]}throwFlame(e,t,i,n,s){let a=this.flames.get(e.id);if(!a&&e.throwsFlame&&(a=new Ca,this.flames.set(e.id,a),this.group.add(a.mesh,a.light,a.glow)),!a)return;const o=e.flame;if(!o){a.putOut(),this.dust.get(e.id)?.set(0,0,0,i,{x:0,z:0},0);return}t.updateMatrixWorld(!0);const c=t.getObjectByName(o.node??ht.EXHAUST_NODE);c?c.getWorldPosition(this.scratch):t.localToWorld(this.scratch.set(0,-.5,0)),a.place(this.scratch,c?ht.pointing(c,this.down,this.aim):t.quaternion,o.lengthM,o.widthM);const l=d=>{const f=new se(d);return this.throughAir(ht.shown([f.r,f.g,f.b],o.luminanceCdM2,n),this.scratch)};a.set(l(o.color),l(o.tipColor??o.color),i),a.illuminate(ht.luminousIntensityCd(o)*this.sceneUnitsPerLux(),ht.lightColourOf(o));const h=Ca.glowFor(o,s?a.mesh.position.distanceTo(s):0),u=new se(o.color).lerp(new se(o.tipColor??o.color),.5);a.shine(h.radiusM,this.throughAir(ht.shown([u.r,u.g,u.b],h.luminanceCdM2,n),this.scratch)),this.raiseDust(e.id,o,i)}raiseDust(e,t,i){const n=this.frame;if(!t.raisesDust||!n?.groundYAt){this.dust.get(e)?.set(0,0,0,i,{x:0,z:0},0);return}let s=this.dust.get(e);s||(s=new is(is.DUST),this.dust.set(e,s),this.group.add(s.points));const{x:a,y:o,z:c}=this.scratch,l=n.groundYAt(a,c),h=Math.max(0,Math.min(1,1-(o-l)/(t.lengthM+1)));s.set(a,l,c,i,n.wind??{x:0,z:0},h,n.light)}setSmoke(e,t){const i=this.frame;for(;this.smoke.length<e.length;){const n=new is(is.SMOKE);this.smoke.push(n),this.group.add(n.points)}this.smoke.forEach((n,s)=>{const a=e[s],o=t*1e3;if(!(a!==void 0&&i!==void 0&&o>=a.fromT&&(a.untilT===void 0||o<a.untilT))){n.set(0,0,0,t,{x:0,z:0},0);return}const l=i.originX+a.eastM,h=i.originZ-a.northM,u=(o-a.fromT)/1e3,d=Math.min(1,u/2)*(.1+.9*Math.pow(2,-u/(a.halfLifeS??20)));n.set(l,i.groundYAt?i.groundYAt(l,h):i.originGroundY,h,t,i.wind??{x:0,z:0},d,i.light)})}static luminousIntensityCd(e){return e.luminanceCdM2*.7*e.widthM*e.lengthM}static lightColourOf(e){const t=new se(e.color),i=new se(e.tipColor??e.color),n=[(t.r+i.r)/2,(t.g+i.g)/2,(t.b+i.b)/2],s=.2126*n[0]+.7152*n[1]+.0722*n[2];return s>0?[n[0]/s,n[1]/s,n[2]/s]:[1,1,1]}static pointing(e,t,i){return t.set(0,-1,0).transformDirection(e.matrixWorld).normalize(),i.setFromUnitVectors(ht.DOWN,t)}static DOWN=new R(0,-1,0);static EXHAUST_NODE="exhaust";shineLights(e,t,i,n){const s=n.eye,a=e.lights;if(!i||!a||!s){this.hideLights(e.id);return}t.updateMatrixWorld(!0);let o;for(const c of i){const l=`${e.id}\0${c.name}`,h=a[c.name];let u=this.lightVeils.get(l);if(!(h>0)||c.meshes.length===0){u?.hide();continue}const d=new Vi;for(const x of c.meshes)d.expandByObject(x);const f=d.getCenter(new R),p=d.getSize(new R),v=Math.max(p.x,p.y,p.z)/2,m=Math.max(f.distanceTo(s),v*1.01,.001);o??=[t,...n.occluders??[]].map(x=>({object:x,box:new Vi().setFromObject(x)}));const g=this.clearShare(s,d,f,c.meshes,o);if(g<=0){u?.hide();continue}u||(u=new Pi(`body-light:${e.id}:${c.name}`),this.lightVeils.set(l,u),this.group.add(u.mesh));const _=Math.asin(Math.min(1,v/m)),b=2*Math.PI*(1-Math.cos(_))*g,M=h*b*this.sceneUnitsPerLux(),S=Math.max(...c.hue)||1,w=[c.hue[0]/S,c.hue[1]/S,c.hue[2]/S],T=this.throughAir([w[0]*M,w[1]*M,w[2]*M],f);u.shine(f,T,_*180/Math.PI)}}clearShare(e,t,i,n,s){const a=[i];for(const[l,h]of[[.2,.2],[.8,.2],[.2,.8],[.8,.8]])a.push(new R(t.min.x+(t.max.x-t.min.x)*l,i.y+(l<.5?-1:1)*(t.max.y-t.min.y)*.3,t.min.z+(t.max.z-t.min.z)*h));const o=new R;let c=0;for(const l of a){o.subVectors(l,e);const h=o.length();this.lightRay.set(e,o.normalize()),this.lightRay.far=h;const u=s.filter(({box:f})=>{const p=this.lightRay.ray.intersectBox(f,this.boxHit);return p!==null&&p.distanceTo(e)<h}).map(({object:f})=>f);u.length>0&&this.lightRay.intersectObjects(u,!0).some(f=>f.object instanceof De&&!n.includes(f.object)&&f.distance<h-.05)||c++}return c/a.length}hideLights(e){const t=`${e}\0`;for(const[i,n]of this.lightVeils)i.startsWith(t)&&n.hide()}dropGlare(e){const t=this.glares.get(e);t&&(this.group.remove(t.mesh),t.dispose(),this.glares.delete(e))}dropFlame(e){const t=this.flames.get(e);if(!t)return;t.mesh.removeFromParent(),t.light.removeFromParent(),t.glow.removeFromParent(),t.dispose(),this.flames.delete(e);const i=this.dust.get(e);i&&(i.points.removeFromParent(),i.dispose(),this.dust.delete(e))}outlineOf(e,t){const i=this.built.get(e)?.holder,n=this.frame,s=i?.getObjectByName(t);if(!i||!n||!s)return;i.updateMatrixWorld(!0);const a=[];return s.traverse(o=>{if(!(o instanceof De))return;const c=o.geometry.getAttribute("position"),l=Math.max(1,Math.floor(c.count/400));for(let h=0;h<c.count;h+=l)this.scratch.fromBufferAttribute(c,h).applyMatrix4(o.matrixWorld),a.push({eastM:this.scratch.x-n.originX,northM:n.originZ-this.scratch.z,upM:this.scratch.y-n.originGroundY})}),a.length>0?a:void 0}boxOf(e,t){const i=this.built.get(e)?.holder;return i?.visible?t.setFromObject(i):void 0}pick(e){const t=[...this.built.entries()].filter(([,{holder:s}])=>s.visible),i=e.intersectObjects(t.map(([,{holder:s}])=>s),!0)[0];if(!i)return;let n=i.object;for(;n&&!t.some(([,{holder:s}])=>s===n);)n=n.parent;return t.find(([,{holder:s}])=>s===n)?.[0]}reachFrom(e){let t=0;for(const{holder:i}of this.built.values()){if(!i.visible)continue;const n=Math.hypot(i.position.x-e.x,i.position.z-e.z);t=Math.max(t,n+Math.max(i.scale.x,i.scale.y,i.scale.z)/2)}return t}furthestFrom(e){let t=0;for(const{holder:i}of this.built.values())i.visible&&(t=Math.max(t,i.position.distanceTo(e)));return t}get reflectors(){return[...this.built.entries()].filter(([,{holder:e}])=>e.visible).map(([e,{holder:t}])=>({id:e,holder:t,shiny:ht.isShiny(t)}))}static isShiny(e){let t=!1;return e.traverse(i=>{const n=i.material;for(const s of Array.isArray(n)?n:[n])(s instanceof Ko||s instanceof _a&&(s.roughness<ht.SHINY_ROUGHNESS||s.metalness>ht.SHINY_METALNESS))&&(t=!0)}),t}static SHINY_ROUGHNESS=.6;static SHINY_METALNESS=.3;get any(){return[...this.built.values()].some(({holder:e})=>e.visible)}clear(){this.token++;for(const e of[...this.built.keys()])this.remove(e)}build(e){const t=new Dt;t.name=`body:${e.id}`;const i=ht.signatureOf(e.model),n=ht.primitiveOf(e.model);if(n==="figure"){const c=new _a({roughness:.7,metalness:0});ht.paint(c,e);const l=hi.build({id:e.id,kind:"entity",eastM:0,northM:0},!1);return l.traverse(h=>{h instanceof De&&(h.material=c,h.castShadow=!0,h.receiveShadow=!0)}),t.add(ht.fit(l,0)),{holder:t,signature:i,material:c}}if(n){const c=new _a({roughness:.45,metalness:0});ht.paint(c,e);const l=new De(ht.unitGeometry(n),c);return l.castShadow=!0,l.receiveShadow=!0,t.add(l),{holder:t,signature:i,material:c}}const s=new _a({roughness:.45,metalness:0});ht.paint(s,e);const a=new De(ht.unitGeometry("ellipsoid"),s);a.castShadow=!0,a.receiveShadow=!0,t.add(a);const o=this.token;return this.loadModel(e.model).then(c=>{if(!c||o!==this.token||this.built.get(e.id)?.holder!==t)return;t.remove(a),a.geometry.dispose(),s.dispose(),ht.glaze(c.scene),t.add(ht.fit(c.scene,c.headingOffsetDeg??e.model.headingOffsetDeg??0)),this.credits.set(e.id,c.credit);const l=this.built.get(e.id);l&&(l.material=void 0,l.glowing=ht.glowingOf(c.scene),l.motions=ht.motionsOf(c.scene)),this.lastSet&&this.set(...this.lastSet),this.onModelArrived()}).catch(c=>console.warn(`Keeping the ellipsoid for body "${e.id}":`,c)),{holder:t,signature:i,material:s}}static fit(e,t){const i=new Dt;e.rotation.y=-t*$c,i.add(e),i.updateMatrixWorld(!0);const n=new Vi().setFromObject(i),s=n.getSize(new R),a=n.getCenter(new R),o=new Dt;return i.position.sub(a),o.add(i),o.scale.set(1/Math.max(s.x,1e-6),1/Math.max(s.y,1e-6),1/Math.max(s.z,1e-6)),e.traverse(c=>{c instanceof De&&(c.castShadow=!0,c.receiveShadow=!0)}),o}static paint(e,t,i){const n=new se(t.appearance.color),s=.2126*n.r+.7152*n.g+.0722*n.b;s>0&&n.multiplyScalar(t.appearance.albedo/s),n.r=Math.min(1,n.r),n.g=Math.min(1,n.g),n.b=Math.min(1,n.b),e.color.equals(n)||e.color.copy(n);const a=new se(t.appearance.color),o=Math.max(a.r,a.g,a.b);ht.glow(e,o>0?[a.r/o,a.g/o,a.b/o]:[1,1,1],t.appearance.luminanceCdM2,i)}static light(e,t,i){for(const{material:n,hue:s,share:a,name:o}of e)ht.glow(n,s,t.lights?.[o]??t.appearance.luminanceCdM2*a,i)}static glow(e,t,i,n){if(!(i>0)){(e.emissive.r!==0||e.emissive.g!==0||e.emissive.b!==0)&&e.emissive.setRGB(0,0,0);return}const s=ht.shown(t,i,n);e.emissive.setRGB(s[0],s[1],s[2])}static motionsOf(e){if(e.animations.length===0)return;const t=new Jx(e),i=new Map;for(const n of e.animations){const s=t.clipAction(n);s.setLoop(jg,1),s.clampWhenFinished=!0,s.play(),s.paused=!0,i.set(n.name,s)}return i}static move(e,t){let i;for(const[n,s]of e){const a=Math.max(0,t[n]??0),o=a-Math.floor(a),c=a>0&&o===0?1:o;s.time=c*s.getClip().duration,i=s.getMixer()}i?.update(0)}static shown(e,t,i){return Fn.shown(e,t,i)}static glowingOf(e){const t=[],i=new Map;e.traverse(a=>{if(a instanceof De)for(const o of Array.isArray(a.material)?a.material:[a.material]){if(!(o instanceof _a))continue;const c=i.get(o);if(c){c.push(a);continue}i.set(o,[a]),Math.max(o.emissive.r,o.emissive.g,o.emissive.b)>0&&t.push(o)}});const n=a=>Math.max(a.emissive.r,a.emissive.g,a.emissive.b),s=Math.max(...t.map(n),0);return s<=0?[]:t.map(a=>({material:a,hue:[a.emissive.r,a.emissive.g,a.emissive.b],share:n(a)/s,name:a.name,meshes:i.get(a)??[]}))}static primitiveOf(e){return e.url===void 0&&av.includes(e.id??"")?e.id:void 0}static signatureOf(e){return`${e.id??""}|${e.url??""}`}static unitGeometry(e){let t;switch(e){case"ellipsoid":case"sphere":t=new ri(.5,48,24);break;case"disc":{const a=[];for(let c=0;c<=24;c++){const l=.5*Math.sin(c/24*Math.PI),h=.5*Math.cos(c/24*Math.PI);a.push(new xe(l,Math.sign(h)*h*h*2))}t=new $l(a.reverse(),64);break}case"cylinder":t=new cs(.5,.5,1,48);break;case"cone":t=new Gr(.5,1,48);break;case"box":t=new Wi(1,1,1);break;case"torus":t=new R0(.35,.15,24,64),t.rotateX(Math.PI/2);break;case"figure":t=new ri(.5,24,12);break}t.computeBoundingBox();const i=t.boundingBox,n=i.getSize(new R),s=i.getCenter(new R);return t.translate(-s.x,-s.y,-s.z),t.scale(1/n.x,1/n.y,1/n.z),t.computeVertexNormals(),t}remove(e){const t=this.built.get(e);if(!t)return;t.holder.removeFromParent(),t.holder.traverse(n=>{if(!(n instanceof De))return;n.geometry.dispose();const s=Array.isArray(n.material)?n.material:[n.material];for(const a of s)a.dispose()}),this.built.delete(e),this.credits.delete(e),this.dropFlame(e),this.dropGlare(e);const i=`${e}\0`;for(const[n,s]of[...this.lightVeils])n.startsWith(i)&&(this.group.remove(s.mesh),s.dispose(),this.lightVeils.delete(n))}}const rv=2,cE=5,lE=2048;class Cn{constructor(e){this.scene=e}cloudLayers=[];cloudSignature="";setCloudLayers(e){const t=e.map(i=>i.mesh.uuid).join(",");if(t!==this.cloudSignature){this.cloudSignature=t,this.cloudLayers=e;for(const i of this.meshes.values())this.configureCloudMaterial(i.material)}}configureCloudMaterial(e){const t=this.cloudLayers,i=this.cloudSignature;e.customProgramCacheKey=()=>i,e.onBeforeCompile=n=>{if(!t.length)return;n.vertexShader=`varying vec3 cloudPoint;
|
|
7291
|
+
`,transparent:!0,depthWrite:!1,side:Qi,fog:!1,blending:Xl,blendSrc:Bo,blendDst:Ho})}static wallReflectance(e,t,i){const n=i(e,1,t);return 2*n/(1+n)}setSurroundings(e){this.uniforms.uSurroundings.value=e}static reflectedResponse(e,t){return Ae.respond(t*Ae.relativeOfResponse(Math.max(e,1e-5)))}}const $c=Math.PI/180;class ht{constructor(e,t,i=()=>0){this.loadModel=e,this.onModelArrived=t,this.sceneUnitsPerLux=i,this.group.name="bodies"}group=new Dt;built=new Map;token=0;credits=new Map;flames=new Map;glares=new Map;lightVeils=new Map;lightRay=new dl;boxHit=new R;dust=new Map;smoke=[];scratch=new R;aim=new en;down=new R;frame;lastSet;get modelCredits(){return[...this.credits.values()]}set(e,t,i=0,n,s=e.map(a=>a.id)){this.frame=t,this.lastSet=[e,t,i,n,s];const a=new Set;for(const c of e){a.add(c.id);const l=ht.signatureOf(c.model);let h=this.built.get(c.id);(!h||h.signature!==l)&&(h&&this.remove(c.id),h=this.build(c),this.built.set(c.id,h),this.group.add(h.holder));const{holder:u,material:d,glowing:f}=h;u.visible=!0,u.position.set(t.originX+c.eastM,t.originGroundY+c.upM,t.originZ-c.northM),u.rotation.set(c.attitude.pitchDeg*$c,-c.attitude.headingDeg*$c,-c.attitude.rollDeg*$c,"YXZ"),u.scale.set(c.sizeM.widthM,c.sizeM.heightM,c.sizeM.lengthM),d&&ht.paint(d,c,n),f&&ht.light(f,c,n),h.motions&&ht.move(h.motions,c.motions??{}),this.shine(c,u,f,n,t.eye),this.shineLights(c,u,f,t),this.throwFlame(c,u,i,n,t.eye)}const o=new Set(s);for(const[c,{holder:l}]of[...this.built])a.has(c)||(o.has(c)?(l.visible=!1,this.flames.get(c)?.putOut(),this.glares.get(c)?.hide(),this.hideLights(c)):this.remove(c))}shine(e,t,i,n,s){const a=e.appearance.luminanceCdM2;let o=this.glares.get(e.id);if(!(a>0)||!s||i&&i.length>0){o?.hide();return}o||(o=new Pi(`body-veil:${e.id}`),this.glares.set(e.id,o),this.group.add(o.mesh));const c=Math.max(e.sizeM.widthM,e.sizeM.heightM)/2,l=Math.max(t.position.distanceTo(s),c*1.01),h=Math.asin(c/l),u=2*Math.PI*(1-Math.cos(h)),d=i?.find(p=>p.share>=1)?.hue??ht.rgbOf(e.appearance.color),f=this.throughAir(ht.shown(d,a,n),t.position);o.shine(t.position,[f[0]*u,f[1]*u,f[2]*u],h*180/Math.PI)}static glaze(e){e.traverse(t=>{if(!(t instanceof De))return;const i=t.material;!(i instanceof xx)||!(i.transmission>0)||(t.material=new Ko(i.ior),i.dispose(),t.castShadow=!1)})}throughAir(e,t){const i=this.frame?.transmittance?.(t.x,t.y,t.z)??[1,1,1];return[e[0]*i[0],e[1]*i[1],e[2]*i[2]]}static rgbOf(e){const t=new se(e);return[t.r,t.g,t.b]}throwFlame(e,t,i,n,s){let a=this.flames.get(e.id);if(!a&&e.throwsFlame&&(a=new Ca,this.flames.set(e.id,a),this.group.add(a.mesh,a.light,a.glow)),!a)return;const o=e.flame;if(!o){a.putOut(),this.dust.get(e.id)?.set(0,0,0,i,{x:0,z:0},0);return}t.updateMatrixWorld(!0);const c=t.getObjectByName(o.node??ht.EXHAUST_NODE);c?c.getWorldPosition(this.scratch):t.localToWorld(this.scratch.set(0,-.5,0)),a.place(this.scratch,c?ht.pointing(c,this.down,this.aim):t.quaternion,o.lengthM,o.widthM);const l=d=>{const f=new se(d);return this.throughAir(ht.shown([f.r,f.g,f.b],o.luminanceCdM2,n),this.scratch)};a.set(l(o.color),l(o.tipColor??o.color),i),a.illuminate(ht.luminousIntensityCd(o)*this.sceneUnitsPerLux(),ht.lightColourOf(o));const h=Ca.glowFor(o,s?a.mesh.position.distanceTo(s):0),u=new se(o.color).lerp(new se(o.tipColor??o.color),.5);a.shine(h.radiusM,this.throughAir(ht.shown([u.r,u.g,u.b],h.luminanceCdM2,n),this.scratch)),this.raiseDust(e.id,o,i)}raiseDust(e,t,i){const n=this.frame;if(!t.raisesDust||!n?.groundYAt){this.dust.get(e)?.set(0,0,0,i,{x:0,z:0},0);return}let s=this.dust.get(e);s||(s=new is(is.DUST),this.dust.set(e,s),this.group.add(s.points));const{x:a,y:o,z:c}=this.scratch,l=n.groundYAt(a,c),h=Math.max(0,Math.min(1,1-(o-l)/(t.lengthM+1)));s.set(a,l,c,i,n.wind??{x:0,z:0},h,n.light)}setSmoke(e,t){const i=this.frame;for(;this.smoke.length<e.length;){const n=new is(is.SMOKE);this.smoke.push(n),this.group.add(n.points)}this.smoke.forEach((n,s)=>{const a=e[s],o=t*1e3;if(!(a!==void 0&&i!==void 0&&o>=a.fromT&&(a.untilT===void 0||o<a.untilT))){n.set(0,0,0,t,{x:0,z:0},0);return}const l=i.originX+a.eastM,h=i.originZ-a.northM,u=(o-a.fromT)/1e3,d=Math.min(1,u/2)*(.1+.9*Math.pow(2,-u/(a.halfLifeS??20)));n.set(l,i.groundYAt?i.groundYAt(l,h):i.originGroundY,h,t,i.wind??{x:0,z:0},d,i.light)})}static luminousIntensityCd(e){return e.luminanceCdM2*.7*e.widthM*e.lengthM}static lightColourOf(e){const t=new se(e.color),i=new se(e.tipColor??e.color),n=[(t.r+i.r)/2,(t.g+i.g)/2,(t.b+i.b)/2],s=.2126*n[0]+.7152*n[1]+.0722*n[2];return s>0?[n[0]/s,n[1]/s,n[2]/s]:[1,1,1]}static pointing(e,t,i){return t.set(0,-1,0).transformDirection(e.matrixWorld).normalize(),i.setFromUnitVectors(ht.DOWN,t)}static DOWN=new R(0,-1,0);static EXHAUST_NODE="exhaust";shineLights(e,t,i,n){const s=n.eye,a=e.lights;if(!i||!a||!s){this.hideLights(e.id);return}t.updateMatrixWorld(!0);let o;for(const c of i){const l=`${e.id}\0${c.name}`,h=a[c.name];let u=this.lightVeils.get(l);if(!(h>0)||c.meshes.length===0){u?.hide();continue}const d=new Wi;for(const x of c.meshes)d.expandByObject(x);const f=d.getCenter(new R),p=d.getSize(new R),v=Math.max(p.x,p.y,p.z)/2,m=Math.max(f.distanceTo(s),v*1.01,.001);o??=[t,...n.occluders??[]].map(x=>({object:x,box:new Wi().setFromObject(x)}));const g=this.clearShare(s,d,f,c.meshes,o);if(g<=0){u?.hide();continue}u||(u=new Pi(`body-light:${e.id}:${c.name}`),this.lightVeils.set(l,u),this.group.add(u.mesh));const _=Math.asin(Math.min(1,v/m)),b=2*Math.PI*(1-Math.cos(_))*g,M=h*b*this.sceneUnitsPerLux(),S=Math.max(...c.hue)||1,w=[c.hue[0]/S,c.hue[1]/S,c.hue[2]/S],T=this.throughAir([w[0]*M,w[1]*M,w[2]*M],f);u.shine(f,T,_*180/Math.PI)}}clearShare(e,t,i,n,s){const a=[i];for(const[l,h]of[[.2,.2],[.8,.2],[.2,.8],[.8,.8]])a.push(new R(t.min.x+(t.max.x-t.min.x)*l,i.y+(l<.5?-1:1)*(t.max.y-t.min.y)*.3,t.min.z+(t.max.z-t.min.z)*h));const o=new R;let c=0;for(const l of a){o.subVectors(l,e);const h=o.length();this.lightRay.set(e,o.normalize()),this.lightRay.far=h;const u=s.filter(({box:f})=>{const p=this.lightRay.ray.intersectBox(f,this.boxHit);return p!==null&&p.distanceTo(e)<h}).map(({object:f})=>f);u.length>0&&this.lightRay.intersectObjects(u,!0).some(f=>f.object instanceof De&&!n.includes(f.object)&&f.distance<h-.05)||c++}return c/a.length}hideLights(e){const t=`${e}\0`;for(const[i,n]of this.lightVeils)i.startsWith(t)&&n.hide()}dropGlare(e){const t=this.glares.get(e);t&&(this.group.remove(t.mesh),t.dispose(),this.glares.delete(e))}dropFlame(e){const t=this.flames.get(e);if(!t)return;t.mesh.removeFromParent(),t.light.removeFromParent(),t.glow.removeFromParent(),t.dispose(),this.flames.delete(e);const i=this.dust.get(e);i&&(i.points.removeFromParent(),i.dispose(),this.dust.delete(e))}outlineOf(e,t){const i=this.built.get(e)?.holder,n=this.frame,s=i?.getObjectByName(t);if(!i||!n||!s)return;i.updateMatrixWorld(!0);const a=[];return s.traverse(o=>{if(!(o instanceof De))return;const c=o.geometry.getAttribute("position"),l=Math.max(1,Math.floor(c.count/400));for(let h=0;h<c.count;h+=l)this.scratch.fromBufferAttribute(c,h).applyMatrix4(o.matrixWorld),a.push({eastM:this.scratch.x-n.originX,northM:n.originZ-this.scratch.z,upM:this.scratch.y-n.originGroundY})}),a.length>0?a:void 0}boxOf(e,t){const i=this.built.get(e)?.holder;return i?.visible?t.setFromObject(i):void 0}pick(e){const t=[...this.built.entries()].filter(([,{holder:s}])=>s.visible),i=e.intersectObjects(t.map(([,{holder:s}])=>s),!0)[0];if(!i)return;let n=i.object;for(;n&&!t.some(([,{holder:s}])=>s===n);)n=n.parent;return t.find(([,{holder:s}])=>s===n)?.[0]}reachFrom(e){let t=0;for(const{holder:i}of this.built.values()){if(!i.visible)continue;const n=Math.hypot(i.position.x-e.x,i.position.z-e.z);t=Math.max(t,n+Math.max(i.scale.x,i.scale.y,i.scale.z)/2)}return t}furthestFrom(e){let t=0;for(const{holder:i}of this.built.values())i.visible&&(t=Math.max(t,i.position.distanceTo(e)));return t}get reflectors(){return[...this.built.entries()].filter(([,{holder:e}])=>e.visible).map(([e,{holder:t}])=>({id:e,holder:t,shiny:ht.isShiny(t)}))}static isShiny(e){let t=!1;return e.traverse(i=>{const n=i.material;for(const s of Array.isArray(n)?n:[n])(s instanceof Ko||s instanceof _a&&(s.roughness<ht.SHINY_ROUGHNESS||s.metalness>ht.SHINY_METALNESS))&&(t=!0)}),t}static SHINY_ROUGHNESS=.6;static SHINY_METALNESS=.3;get any(){return[...this.built.values()].some(({holder:e})=>e.visible)}clear(){this.token++;for(const e of[...this.built.keys()])this.remove(e)}build(e){const t=new Dt;t.name=`body:${e.id}`;const i=ht.signatureOf(e.model),n=ht.primitiveOf(e.model);if(n==="figure"){const c=new _a({roughness:.7,metalness:0});ht.paint(c,e);const l=hi.build({id:e.id,kind:"entity",eastM:0,northM:0},!1);return l.traverse(h=>{h instanceof De&&(h.material=c,h.castShadow=!0,h.receiveShadow=!0)}),t.add(ht.fit(l,0)),{holder:t,signature:i,material:c}}if(n){const c=new _a({roughness:.45,metalness:0});ht.paint(c,e);const l=new De(ht.unitGeometry(n),c);return l.castShadow=!0,l.receiveShadow=!0,t.add(l),{holder:t,signature:i,material:c}}const s=new _a({roughness:.45,metalness:0});ht.paint(s,e);const a=new De(ht.unitGeometry("ellipsoid"),s);a.castShadow=!0,a.receiveShadow=!0,t.add(a);const o=this.token;return this.loadModel(e.model).then(c=>{if(!c||o!==this.token||this.built.get(e.id)?.holder!==t)return;t.remove(a),a.geometry.dispose(),s.dispose(),ht.glaze(c.scene),t.add(ht.fit(c.scene,c.headingOffsetDeg??e.model.headingOffsetDeg??0)),this.credits.set(e.id,c.credit);const l=this.built.get(e.id);l&&(l.material=void 0,l.glowing=ht.glowingOf(c.scene),l.motions=ht.motionsOf(c.scene)),this.lastSet&&this.set(...this.lastSet),this.onModelArrived()}).catch(c=>console.warn(`Keeping the ellipsoid for body "${e.id}":`,c)),{holder:t,signature:i,material:s}}static fit(e,t){const i=new Dt;e.rotation.y=-t*$c,i.add(e),i.updateMatrixWorld(!0);const n=new Wi().setFromObject(i),s=n.getSize(new R),a=n.getCenter(new R),o=new Dt;return i.position.sub(a),o.add(i),o.scale.set(1/Math.max(s.x,1e-6),1/Math.max(s.y,1e-6),1/Math.max(s.z,1e-6)),e.traverse(c=>{c instanceof De&&(c.castShadow=!0,c.receiveShadow=!0)}),o}static paint(e,t,i){const n=new se(t.appearance.color),s=.2126*n.r+.7152*n.g+.0722*n.b;s>0&&n.multiplyScalar(t.appearance.albedo/s),n.r=Math.min(1,n.r),n.g=Math.min(1,n.g),n.b=Math.min(1,n.b),e.color.equals(n)||e.color.copy(n);const a=new se(t.appearance.color),o=Math.max(a.r,a.g,a.b);ht.glow(e,o>0?[a.r/o,a.g/o,a.b/o]:[1,1,1],t.appearance.luminanceCdM2,i)}static light(e,t,i){for(const{material:n,hue:s,share:a,name:o}of e)ht.glow(n,s,t.lights?.[o]??t.appearance.luminanceCdM2*a,i)}static glow(e,t,i,n){if(!(i>0)){(e.emissive.r!==0||e.emissive.g!==0||e.emissive.b!==0)&&e.emissive.setRGB(0,0,0);return}const s=ht.shown(t,i,n);e.emissive.setRGB(s[0],s[1],s[2])}static motionsOf(e){if(e.animations.length===0)return;const t=new Jx(e),i=new Map;for(const n of e.animations){const s=t.clipAction(n);s.setLoop(jg,1),s.clampWhenFinished=!0,s.play(),s.paused=!0,i.set(n.name,s)}return i}static move(e,t){let i;for(const[n,s]of e){const a=Math.max(0,t[n]??0),o=a-Math.floor(a),c=a>0&&o===0?1:o;s.time=c*s.getClip().duration,i=s.getMixer()}i?.update(0)}static shown(e,t,i){return Fn.shown(e,t,i)}static glowingOf(e){const t=[],i=new Map;e.traverse(a=>{if(a instanceof De)for(const o of Array.isArray(a.material)?a.material:[a.material]){if(!(o instanceof _a))continue;const c=i.get(o);if(c){c.push(a);continue}i.set(o,[a]),Math.max(o.emissive.r,o.emissive.g,o.emissive.b)>0&&t.push(o)}});const n=a=>Math.max(a.emissive.r,a.emissive.g,a.emissive.b),s=Math.max(...t.map(n),0);return s<=0?[]:t.map(a=>({material:a,hue:[a.emissive.r,a.emissive.g,a.emissive.b],share:n(a)/s,name:a.name,meshes:i.get(a)??[]}))}static primitiveOf(e){return e.url===void 0&&av.includes(e.id??"")?e.id:void 0}static signatureOf(e){return`${e.id??""}|${e.url??""}`}static unitGeometry(e){let t;switch(e){case"ellipsoid":case"sphere":t=new ri(.5,48,24);break;case"disc":{const a=[];for(let c=0;c<=24;c++){const l=.5*Math.sin(c/24*Math.PI),h=.5*Math.cos(c/24*Math.PI);a.push(new xe(l,Math.sign(h)*h*h*2))}t=new $l(a.reverse(),64);break}case"cylinder":t=new cs(.5,.5,1,48);break;case"cone":t=new Gr(.5,1,48);break;case"box":t=new Xi(1,1,1);break;case"torus":t=new R0(.35,.15,24,64),t.rotateX(Math.PI/2);break;case"figure":t=new ri(.5,24,12);break}t.computeBoundingBox();const i=t.boundingBox,n=i.getSize(new R),s=i.getCenter(new R);return t.translate(-s.x,-s.y,-s.z),t.scale(1/n.x,1/n.y,1/n.z),t.computeVertexNormals(),t}remove(e){const t=this.built.get(e);if(!t)return;t.holder.removeFromParent(),t.holder.traverse(n=>{if(!(n instanceof De))return;n.geometry.dispose();const s=Array.isArray(n.material)?n.material:[n.material];for(const a of s)a.dispose()}),this.built.delete(e),this.credits.delete(e),this.dropFlame(e),this.dropGlare(e);const i=`${e}\0`;for(const[n,s]of[...this.lightVeils])n.startsWith(i)&&(this.group.remove(s.mesh),s.dispose(),this.lightVeils.delete(n))}}const rv=2,cE=5,lE=2048;class Cn{constructor(e){this.scene=e}cloudLayers=[];cloudSignature="";setCloudLayers(e){const t=e.map(i=>i.mesh.uuid).join(",");if(t!==this.cloudSignature){this.cloudSignature=t,this.cloudLayers=e;for(const i of this.meshes.values())this.configureCloudMaterial(i.material)}}configureCloudMaterial(e){const t=this.cloudLayers,i=this.cloudSignature;e.customProgramCacheKey=()=>i,e.onBeforeCompile=n=>{if(!t.length)return;n.vertexShader=`varying vec3 cloudPoint;
|
|
7292
7292
|
`+n.vertexShader,n.vertexShader=n.vertexShader.replace("#include <project_vertex>",`#include <project_vertex>
|
|
7293
7293
|
cloudPoint = (modelMatrix * vec4(transformed, 1.0)).xyz - cameraPosition;`);let s=`varying vec3 cloudPoint;
|
|
7294
7294
|
`,a="";t.forEach((o,c)=>{const l=`cloud${c}_`;for(const[h,u]of Object.entries(o.uniforms))n.uniforms[l+h]=u;s+=QS(l),a+=`diffuseColor.a *= ${l}transmissionAt(normalize(cloudPoint), length(cloudPoint));
|
|
7295
|
-
`}),n.fragmentShader=s+n.fragmentShader,n.fragmentShader=n.fragmentShader.replace("#include <opaque_fragment>",a+"#include <opaque_fragment>")},e.needsUpdate=!0}meshes=new Map;signatures=new Map;extents=new Map;placed=[];frame;direction=new R;up=new R;lookAt=new Ze;vertex=new R;centre=new R;right=new R;above=new R;set(e,t){this.placed=e,this.frame=t;const i=new Set(e.map(n=>n.sourceId));for(const[n,s]of this.meshes)i.has(n)||(this.dispose(s),this.meshes.delete(n),this.signatures.delete(n),this.extents.delete(n));for(const n of e){let s=this.meshes.get(n.sourceId);s||(s=new De(new Xi(1,1,Cn.SEGMENTS,Cn.SEGMENTS),new bn({transparent:!0,depthWrite:!1,depthTest:!0,fog:!1,toneMapped:!1})),this.configureCloudMaterial(s.material),s.frustumCulled=!1,s.layers.set(rv),this.scene.add(s),this.meshes.set(n.sourceId,s)),s.renderOrder=cE+n.renderOrder,s.visible=!n.hidden&&n.shape.transparency<1,s.visible&&this.paint(s,n,t)}}place(e,t,i){const n=this.frame;if(n)for(const s of this.placed){const a=this.meshes.get(s.sourceId);if(!a||!a.visible)continue;const o=this.extents.get(s.sourceId);if(!o)continue;const{bounds:c}=s.shape;let l=c.x+c.width/2,h=c.y+c.height/2,u=!0;if(s.aim){const d=i(Cn.directionOf(s.aim,this.direction));d&&Math.abs(d.ndcX)<Cn.FURTHEST_NDC&&Math.abs(d.ndcY)<Cn.FURTHEST_NDC?(l=(d.ndcX+1)/2*n.canvasWidthPx,h=(1-d.ndcY)/2*n.canvasHeightPx):u=!1}u?this.curve(a,e,t,n,o,l,h,s.distanceM):this.flat(a,e,n,o,s.distanceM)}}static FURTHEST_NDC=4;curve(e,t,i,n,s,a,o,c){const l=a-s.width/2,h=o-s.height/2,u=e.geometry.attributes.position,d=Cn.SEGMENTS;let f=0;for(let p=0;p<=d;p++){const v=h+p/d*s.height;for(let m=0;m<=d;m++){const g=l+m/d*s.width;i(g/n.canvasWidthPx*2-1,-(v/n.canvasHeightPx*2-1),this.direction),this.vertex.copy(t.position).addScaledVector(this.direction,c),u.setXYZ(f++,this.vertex.x,this.vertex.y,this.vertex.z)}}u.needsUpdate=!0,e.matrixAutoUpdate=!1,e.matrix.identity(),e.matrixWorldNeedsUpdate=!0,e.scale.set(Et.sizeMAt(c,n.projection.pxToDeg(s.width)),Et.sizeMAt(c,n.projection.pxToDeg(s.height)),1)}flat(e,t,i,n,s){const a=e.geometry.attributes.position,o=Cn.SEGMENTS,c=Et.sizeMAt(s,i.projection.pxToDeg(n.width)),l=Et.sizeMAt(s,i.projection.pxToDeg(n.height));this.up.set(0,1,0).applyQuaternion(t.quaternion),this.centre.copy(t.position).addScaledVector(this.direction,s),this.lookAt.lookAt(t.position,this.centre,this.up),this.right.setFromMatrixColumn(this.lookAt,0),this.above.setFromMatrixColumn(this.lookAt,1);let h=0;for(let u=0;u<=o;u++){const d=.5-u/o;for(let f=0;f<=o;f++){const p=f/o-.5;this.vertex.copy(this.centre).addScaledVector(this.right,p*c).addScaledVector(this.above,d*l),a.setXYZ(h++,this.vertex.x,this.vertex.y,this.vertex.z)}}a.needsUpdate=!0,e.matrixAutoUpdate=!1,e.matrix.identity(),e.matrixWorldNeedsUpdate=!0,e.scale.set(c,l,1)}static SEGMENTS=16;static directionOf(e,t){const i=e.azimuthDeg*Math.PI/180,n=e.altitudeDeg*Math.PI/180;return t.set(Math.sin(i)*Math.cos(n),Math.sin(n),-Math.cos(i)*Math.cos(n))}get any(){for(const e of this.meshes.values())if(e.visible)return!0;return!1}get furthestM(){return this.placed.reduce((e,t)=>Math.max(e,t.distanceM),0)}paint(e,t,i){const{shape:n}=t,s=zo.paintExtent(n),a=t.ghost?3:0,o={x:s.x-a,y:s.y-a,width:s.width+2*a,height:s.height+2*a};this.extents.set(t.sourceId,o);const c=`${Cn.signatureOf(n,i)}|${t.ghost?"ghost":""}`;if(this.signatures.get(t.sourceId)===c&&e.material.map)return;this.signatures.set(t.sourceId,c);const l=Math.min(i.scale,lE/Math.max(o.width,o.height,1)),h=Math.max(1,Math.ceil(o.width*l)),u=Math.max(1,Math.ceil(o.height*l)),d=e.material.map,f=d?.image??document.createElement("canvas"),p=f.width!==h||f.height!==u;p&&(f.width=h,f.height=u);const v=f.getContext("2d");if(!v)return;v.clearRect(0,0,h,u);const m=new zo(v);if(m.setStarPoints(i.starPoints),m.setRoll(i.rollRad),m.paintInto(n,o,l,t.ghost),d&&!p){d.needsUpdate=!0;return}d?.dispose();const g=new Ls(f);g.colorSpace=Gi,g.minFilter=rt,g.generateMipmaps=!1,e.material.map=g,e.material.needsUpdate=!0}static signatureOf(e,t){const{bounds:i}=e;return JSON.stringify([e.kind,Math.round(i.width*10),Math.round(i.height*10),e.color,e.angle,e.transparency,e.haloScale,e.blur??0,e.brightness??0,e.kind==="polygon"?e.points:void 0,t.scale,t.starPoints,t.rollRad])}dispose(e){e.removeFromParent(),e.geometry.dispose(),e.material.map?.dispose(),e.material.dispose()}clear(){for(const e of this.meshes.values())this.dispose(e);this.meshes.clear(),this.signatures.clear(),this.extents.clear(),this.placed=[]}}const ov=3,Kc=800,fo=Math.PI/180;class Rn{constructor(e,t,i=Rn.fetchImage){this.scene=e,this.onImageLoaded=t,this.loadImage=i}meshes=new Map;signatures=new Map;images=new Map;loading=new Map;failed=new Set;references=[];views=new Map;shown=!0;observerAt;static PRESENT_WITHIN_M=2;static GONE_BEYOND_M=20;static presenceAt(e,t){if(!e.from||!t)return 1;const i=ni(t.lat,t.lng,e.from.lat,e.from.lng),s=(Math.hypot(i.x,i.z)-Rn.PRESENT_WITHIN_M)/(Rn.GONE_BEYOND_M-Rn.PRESENT_WITHIN_M),a=Math.min(Math.max(s,0),1);return 1-a*a*(3-2*a)}set(e,t=this.views,i){this.references=e,this.observerAt=i,this.views=t;const n=new Set(e.map(s=>s.id));for(const[s,a]of this.meshes)n.has(s)||(this.dispose(a),this.meshes.delete(s),this.signatures.delete(s));for(const[s,a]of this.images){const o=e.find(c=>c.id===s);o&&o.src===a.texture.userData.src||(a.texture.dispose(),this.images.delete(s))}for(const s of e){const a=this.images.get(s.id);if(!a){this.load(s);continue}this.build(s,a)}}setShown(e){this.shown=e;for(const t of this.meshes.values())t.visible=e&&this.opacityOf(t.userData.id)>0}setView(e,t){this.views.set(e,t);const i=this.meshes.get(e);i&&this.applyOpacity(i,e)}get any(){for(const e of this.meshes.values())if(e.visible)return!0;return!1}place(e){for(const t of this.meshes.values())t.visible&&(t.position.copy(e.position),t.updateMatrixWorld())}get furthestM(){return this.meshes.size>0?Kc:0}directionOfPixel(e,t,i,n){const s=this.images.get(e.id),a=s?s.width/s.height:1,o=Math.tan(e.registration.fovDeg/2*fo),c=o*a;return n.set((t*2-1)*c,(1-i*2)*o,-1).normalize(),n.applyQuaternion(Rn.orientation(e))}aspectOf(e){const t=this.images.get(e);return t?t.width/t.height:void 0}failedToLoad(e){return this.failed.has(e)}load(e){const t=e.src;if(this.loading.has(e.id)||this.failed.has(t))return;const i=this.loadImage(t).then(n=>{this.loading.delete(e.id);const s=this.references.find(a=>a.id===e.id);if(!s||s.src!==t){n.texture.dispose();return}n.texture.userData.src=t,this.images.set(e.id,n),this.build(s,n),this.onImageLoaded()},()=>{this.loading.delete(e.id),this.failed.add(t)});this.loading.set(e.id,i)}static async fetchImage(e){const t=await fetch(e);if(!t.ok)throw new Error(`${e}: ${t.status}`);const i=await createImageBitmap(await t.blob(),{imageOrientation:"flipY"}),n=new Si(i);return n.flipY=!1,n.colorSpace=Gi,n.minFilter=rt,n.magFilter=rt,n.generateMipmaps=!1,n.needsUpdate=!0,{texture:n,width:i.width,height:i.height}}build(e,t){const i=Rn.signatureOf(e,t);let n=this.meshes.get(e.id);if(n&&this.signatures.get(e.id)===i){this.applyOpacity(n,e.id);return}n&&(this.dispose(n),this.meshes.delete(e.id)),n=new De(Rn.geometryOf(e,t),new bn({map:t.texture,transparent:!0,depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1})),e.kind==="panorama"&&(n.material.side=Ht),n.frustumCulled=!1,n.layers.set(ov),n.userData.id=e.id,n.quaternion.copy(Rn.orientation(e)),this.scene.add(n),this.meshes.set(e.id,n),this.signatures.set(e.id,i),this.applyOpacity(n,e.id)}static geometryOf(e,t){if(e.kind==="panorama"){const a=new ri(Kc,64,32,Math.PI/2,Math.PI*2),o=a.attributes.uv;for(let c=0;c<o.count;c++)o.setX(c,1-o.getX(c));return o.needsUpdate=!0,a}const i=2*Kc*Math.tan(e.registration.fovDeg/2*fo),n=i*(t.width/Math.max(t.height,1)),s=new Xi(n,i);return s.translate(0,0,-Kc),s}static orientation(e){const{headingDeg:t,pitchDeg:i,rollDeg:n}=e.registration,s=new Ut;return s.rotation.set(i*fo,-t*fo,-(n??0)*fo,"YXZ"),s.quaternion}opacityOf(e){const t=this.references.find(s=>s.id===e),i=this.views.get(e),n=t?Rn.presenceAt(t,this.observerAt):1;return(i?.opacity??t?.opacity??0)*n}applyOpacity(e,t){const i=this.opacityOf(t);e.material.opacity=i,e.visible=this.shown&&i>0}static signatureOf(e,t){const{headingDeg:i,pitchDeg:n,rollDeg:s,fovDeg:a}=e.registration;return[e.kind,e.src,t.width,t.height,i,n,s??0,a].join("|")}dispose(e){this.scene.remove(e),e.geometry.dispose(),e.material.dispose()}disposeAll(){for(const e of this.meshes.values())this.dispose(e);this.meshes.clear(),this.signatures.clear();for(const e of this.images.values())e.texture.dispose();this.images.clear()}}class Fe{static GROUND_RADIUS_M=636e4;static TOP_RADIUS_M=646e4;static WAVELENGTHS_NM=Array.from({length:15},(e,t)=>410+20*t);static WAVELENGTH_STEP_NM=20;static SOLAR_IRRADIANCE=[1.707,1.676,1.982,2.02,1.941,1.87,1.879,1.856,1.839,1.799,1.728,1.668,1.57,1.532,1.452];static OZONE_CROSS_SECTION=[.021,.069,.19,.418,.827,1.531,2.439,3.291,4.468,4.55,4.663,3.477,2.447,1.658,1.071];static RAYLEIGH_SCALE_HEIGHT_M=8e3;static AEROSOL_SCALE_HEIGHT_M=1200;static OZONE_PEAK_ALTITUDE_M=25e3;static OZONE_HALF_WIDTH_M=15e3;static DEFAULT_AEROSOL_OPTICAL_DEPTH=.1;static DEFAULT_OZONE_DOBSON=300;static AEROSOL_SINGLE_SCATTERING_ALBEDO=.9;static AEROSOL_ANGSTROM_EXPONENT=1.3;static AEROSOL_ASYMMETRY=.8;rayleighScattering;aerosolScattering;aerosolExtinction;ozoneAbsorption;constructor(e={}){const t=Fe.WAVELENGTHS_NM.length,i=e.aerosolOpticalDepth??Fe.DEFAULT_AEROSOL_OPTICAL_DEPTH,n=e.ozoneDobson??Fe.DEFAULT_OZONE_DOBSON;this.rayleighScattering=new Float64Array(t),this.aerosolScattering=new Float64Array(t),this.aerosolExtinction=new Float64Array(t),this.ozoneAbsorption=new Float64Array(t);const s=n*2687e17/Fe.OZONE_HALF_WIDTH_M;for(let a=0;a<t;a++){const o=Fe.WAVELENGTHS_NM[a];this.rayleighScattering[a]=Fe.rayleighAt(o);const c=i/Fe.AEROSOL_SCALE_HEIGHT_M*(o/550)**-1.3;this.aerosolExtinction[a]=c,this.aerosolScattering[a]=c*Fe.AEROSOL_SINGLE_SCATTERING_ALBEDO,this.ozoneAbsorption[a]=Fe.OZONE_CROSS_SECTION[a]*1e-25*s}}static rayleighAt(e){const t=e/1e3,i=1/(t*t),n=t*t;return(1.0455996-341.29061*i-.9023085*n)/(1+.0027059889*i-85.968563*n)*1e-28*1e-4*2546899e19}static rayleighDensity(e){return Math.exp(-Math.max(e,0)/Fe.RAYLEIGH_SCALE_HEIGHT_M)}static aerosolDensity(e){return Math.exp(-Math.max(e,0)/Fe.AEROSOL_SCALE_HEIGHT_M)}static ozoneDensity(e){return Math.max(0,1-Math.abs(e-Fe.OZONE_PEAK_ALTITUDE_M)/Fe.OZONE_HALF_WIDTH_M)}static rayleighPhase(e){return 3/(16*Math.PI)*(1+e*e)}static aerosolPhase(e,t=Fe.AEROSOL_ASYMMETRY){const i=t*t;return 3/(8*Math.PI)*(1-i)*(1+e*e)/((2+i)*Math.pow(Math.max(1+i-2*t*e,1e-6),1.5))}}class We{static TRANSMITTANCE_WIDTH=256;static TRANSMITTANCE_HEIGHT=64;static MULTIPLE_SIZE=64;static MULTIPLE_ROWS=16;static MULTIPLE_HEIGHT_POWER=2;static MULTIPLE_DIRECTIONS=16;static SKY_VIEW_WIDTH=192;static SKY_VIEW_HEIGHT=108;static STEPS=40;static MULTIPLE_STEPS=12;static GROUND_ALBEDO=.3;supported;renderer;transmittance;multiple;sunView;moonView;scene=new Is;camera=new zn(-1,1,1,-1,0,1);quad;transmittanceMaterial;multipleMaterial;skyViewMaterial;transmittanceReady=!1;multipleRows=0;multipleColumn=0;mediumKey="";static MULTIPLE_BLOCK=16;static shared=new Map;building=!1;adopted;tableUniforms;constructor(e){this.renderer=e,this.supported=e.capabilities.isWebGL2&&e.extensions.has("EXT_color_buffer_float"),this.transmittance=new ai(We.TRANSMITTANCE_WIDTH,We.TRANSMITTANCE_HEIGHT,{count:4,type:Wt,minFilter:rt,magFilter:rt,depthBuffer:!1}),this.multiple=new ai(We.MULTIPLE_SIZE,We.MULTIPLE_ROWS,{count:4,type:Oi,minFilter:At,magFilter:At,depthBuffer:!1});const t=()=>new ai(We.SKY_VIEW_WIDTH,We.SKY_VIEW_HEIGHT,{type:Oi,minFilter:At,magFilter:At,depthBuffer:!1});this.sunView=t(),this.moonView=t();const i=We.mediumUniforms(),n=this.tableUniforms={uT0:{value:this.transmittance.textures[0]},uT1:{value:this.transmittance.textures[1]},uT2:{value:this.transmittance.textures[2]},uT3:{value:this.transmittance.textures[3]},uM0:{value:this.multiple.textures[0]},uM1:{value:this.multiple.textures[1]},uM2:{value:this.multiple.textures[2]},uM3:{value:this.multiple.textures[3]}},s=(a,o={})=>new u1({glslVersion:Tl,uniforms:{...i,...n,...o},vertexShader:We.VERTEX,fragmentShader:a,depthTest:!1,depthWrite:!1});this.transmittanceMaterial=s(We.TRANSMITTANCE_FRAGMENT),this.multipleMaterial=s(We.MULTIPLE_FRAGMENT),this.skyViewMaterial=s(We.SKY_VIEW_FRAGMENT,{uObserverRadius:{value:Fe.GROUND_RADIUS_M+2},uSourceMu:{value:1}}),this.quad=new De(new Xi(2,2),this.transmittanceMaterial),this.quad.frustumCulled=!1,this.scene.add(this.quad)}get transmittanceTextures(){return this.transmittance.textures}get sunViewTexture(){return this.sunView.texture}get moonViewTexture(){return this.moonView.texture}get ready(){return this.supported&&(this.adopted!==void 0||this.transmittanceReady&&this.multipleRows>=We.MULTIPLE_ROWS)}setMedium(e){const t=[e.rayleighScattering,e.aerosolScattering,e.aerosolExtinction,e.ozoneAbsorption].map(n=>Array.from(n,s=>s.toPrecision(6)).join(",")).join("|");if(t===this.mediumKey)return;this.abandonBuilding(),this.releaseAdopted(),this.mediumKey=t;const i=(n,s)=>{const a=this.transmittanceMaterial.uniforms[n].value;for(let o=0;o<4;o++)a[o].set(s[o*4]??0,s[o*4+1]??0,s[o*4+2]??0,s[o*4+3]??0)};i("uRayleigh",e.rayleighScattering),i("uAerosolScattering",e.aerosolScattering),i("uAerosolExtinction",e.aerosolExtinction),i("uOzone",e.ozoneAbsorption),this.transmittanceReady=!1,this.multipleRows=0,this.multipleColumn=0}invalidate(){this.adopted||(this.abandonBuilding(),this.transmittanceReady=!1,this.multipleRows=0,this.multipleColumn=0)}advance(e){if(!this.supported||!this.mediumKey)return!1;if(this.ready)return!0;const t=We.shared.get(this.mediumKey);if(t&&t!=="building")return this.adopt(t),!0;if(t==="building"&&!this.building)return!1;t||(We.shared.set(this.mediumKey,"building"),this.building=!0);const i=this.renderer.getRenderTarget();let n=Math.max(1,e);this.transmittanceReady||(this.draw(this.transmittanceMaterial,this.transmittance),this.transmittanceReady=!0,n--);const s=We.MULTIPLE_SIZE,a=We.MULTIPLE_BLOCK;for(;n>0&&this.multipleRows<We.MULTIPLE_ROWS;n--)this.multiple.scissor.set(this.multipleColumn,this.multipleRows,a,1),this.multiple.scissorTest=!0,this.draw(this.multipleMaterial,this.multiple),this.multipleColumn+=a,this.multipleColumn>=s&&(this.multipleColumn=0,this.multipleRows++);return this.multiple.scissorTest=!1,this.renderer.setRenderTarget(i),this.ready&&this.building&&this.share(this.mediumKey),this.ready}async share(e){this.building=!1;try{const t=await Promise.all([0,1,2,3].map(n=>this.readRaw(this.transmittance,n,Uint16Array))),i=await Promise.all([0,1,2,3].map(n=>this.readRaw(this.multiple,n,Float32Array)));this.mediumKey===e?We.shared.set(e,{transmittance:t,multiple:i}):We.shared.delete(e)}catch{We.shared.delete(e)}}async readRaw(e,t,i){const n=new i(e.width*e.height*4);return await this.renderer.readRenderTargetPixelsAsync(e,0,0,e.width,e.height,n,void 0,t),n}adopt(e){const t=(s,a,o,c)=>{const l=new ca(s,a,o,Ei,c?Wt:Oi);return l.minFilter=l.magFilter=c?rt:At,l.needsUpdate=!0,l},i=e.transmittance.map(s=>t(s,We.TRANSMITTANCE_WIDTH,We.TRANSMITTANCE_HEIGHT,!0)),n=e.multiple.map(s=>t(s,We.MULTIPLE_SIZE,We.MULTIPLE_ROWS,!1));i.forEach((s,a)=>this.tableUniforms[`uT${a}`].value=s),n.forEach((s,a)=>this.tableUniforms[`uM${a}`].value=s),this.adopted=[...i,...n]}releaseAdopted(){if(this.adopted){for(const e of this.adopted)e.dispose();this.adopted=void 0;for(let e=0;e<4;e++)this.tableUniforms[`uT${e}`].value=this.transmittance.textures[e],this.tableUniforms[`uM${e}`].value=this.multiple.textures[e]}}abandonBuilding(){this.building&&(this.building=!1,We.shared.get(this.mediumKey)==="building"&&We.shared.delete(this.mediumKey))}renderSkyViews(e,t,i){if(!this.ready)return;const n=this.renderer.getRenderTarget(),s=this.skyViewMaterial.uniforms;s.uObserverRadius.value=Fe.GROUND_RADIUS_M+Math.max(e,2),s.uSourceMu.value=Math.sin(t*Math.PI/180),this.draw(this.skyViewMaterial,this.sunView),s.uSourceMu.value=Math.sin(i*Math.PI/180),this.draw(this.skyViewMaterial,this.moonView),this.renderer.setRenderTarget(n)}static skyViewUv(e,t,i){const n=Fe.GROUND_RADIUS_M+Math.max(e,2),s=Fe.GROUND_RADIUS_M,a=Math.acos(Math.min(Math.sqrt(Math.max(n*n-s*s,0))/n,1)),o=Math.PI-a,c=t<o?.5*(1-Math.sqrt(Math.max(1-t/o,0))):.5+.5*Math.sqrt(Math.min((t-o)/a,1));return{u:Math.min(Math.max(Math.abs(i)/Math.PI,0),1),v:c}}async readTable(e,t){if(e==="multiple"){const s=new Float32Array(this.multiple.width*this.multiple.height*4);return await this.renderer.readRenderTargetPixelsAsync(this.multiple,0,0,this.multiple.width,this.multiple.height,s,void 0,t),s}const i=this.transmittance,n=new Uint16Array(i.width*i.height*4);return await this.renderer.readRenderTargetPixelsAsync(i,0,0,i.width,i.height,n,void 0,t),Float32Array.from(n,s=>kn.fromHalfFloat(s))}readSkyViewNow(e){const t=e==="sun"?this.sunView:this.moonView,i=new Float32Array(t.width*t.height*4),n=this.renderer.getContext();return n.bindBuffer(n.PIXEL_PACK_BUFFER,null),this.renderer.readRenderTargetPixels(t,0,0,t.width,t.height,i),i}async readSkyView(e){const t=e==="sun"?this.sunView:this.moonView,i=new Float32Array(t.width*t.height*4);return await this.renderer.readRenderTargetPixelsAsync(t,0,0,t.width,t.height,i),i}dispose(){this.abandonBuilding(),this.releaseAdopted(),this.transmittance.dispose(),this.multiple.dispose(),this.sunView.dispose(),this.moonView.dispose(),this.transmittanceMaterial.dispose(),this.multipleMaterial.dispose(),this.skyViewMaterial.dispose(),this.quad.geometry.dispose()}draw(e,t){this.quad.material=e,this.renderer.setRenderTarget(t),this.renderer.render(this.scene,this.camera)}static mediumUniforms(){const e=()=>[new it,new it,new it,new it],t=(i,n)=>{const s=e();return Fe.WAVELENGTHS_NM.forEach((a,o)=>{s[Math.floor(o/4)].setComponent(o%4,i(a)*n*Fe.WAVELENGTH_STEP_NM*Fe.SOLAR_IRRADIANCE[o])}),s};return{uRayleigh:{value:e()},uAerosolScattering:{value:e()},uAerosolExtinction:{value:e()},uOzone:{value:e()},uCieX:{value:t(i=>fi.colourMatching(i)[0],683)},uCieY:{value:t(i=>fi.colourMatching(i)[1],683)},uCieZ:{value:t(i=>fi.colourMatching(i)[2],683)},uScotopic:{value:t(i=>fi.scotopic(i),1700)}}}static VERTEX=`
|
|
7295
|
+
`}),n.fragmentShader=s+n.fragmentShader,n.fragmentShader=n.fragmentShader.replace("#include <opaque_fragment>",a+"#include <opaque_fragment>")},e.needsUpdate=!0}meshes=new Map;signatures=new Map;extents=new Map;placed=[];frame;direction=new R;up=new R;lookAt=new Ze;vertex=new R;centre=new R;right=new R;above=new R;set(e,t){this.placed=e,this.frame=t;const i=new Set(e.map(n=>n.sourceId));for(const[n,s]of this.meshes)i.has(n)||(this.dispose(s),this.meshes.delete(n),this.signatures.delete(n),this.extents.delete(n));for(const n of e){let s=this.meshes.get(n.sourceId);s||(s=new De(new Yi(1,1,Cn.SEGMENTS,Cn.SEGMENTS),new bn({transparent:!0,depthWrite:!1,depthTest:!0,fog:!1,toneMapped:!1})),this.configureCloudMaterial(s.material),s.frustumCulled=!1,s.layers.set(rv),this.scene.add(s),this.meshes.set(n.sourceId,s)),s.renderOrder=cE+n.renderOrder,s.visible=!n.hidden&&n.shape.transparency<1,s.visible&&this.paint(s,n,t)}}place(e,t,i){const n=this.frame;if(n)for(const s of this.placed){const a=this.meshes.get(s.sourceId);if(!a||!a.visible)continue;const o=this.extents.get(s.sourceId);if(!o)continue;const{bounds:c}=s.shape;let l=c.x+c.width/2,h=c.y+c.height/2,u=!0;if(s.aim){const d=i(Cn.directionOf(s.aim,this.direction));d&&Math.abs(d.ndcX)<Cn.FURTHEST_NDC&&Math.abs(d.ndcY)<Cn.FURTHEST_NDC?(l=(d.ndcX+1)/2*n.canvasWidthPx,h=(1-d.ndcY)/2*n.canvasHeightPx):u=!1}u?this.curve(a,e,t,n,o,l,h,s.distanceM):this.flat(a,e,n,o,s.distanceM)}}static FURTHEST_NDC=4;curve(e,t,i,n,s,a,o,c){const l=a-s.width/2,h=o-s.height/2,u=e.geometry.attributes.position,d=Cn.SEGMENTS;let f=0;for(let p=0;p<=d;p++){const v=h+p/d*s.height;for(let m=0;m<=d;m++){const g=l+m/d*s.width;i(g/n.canvasWidthPx*2-1,-(v/n.canvasHeightPx*2-1),this.direction),this.vertex.copy(t.position).addScaledVector(this.direction,c),u.setXYZ(f++,this.vertex.x,this.vertex.y,this.vertex.z)}}u.needsUpdate=!0,e.matrixAutoUpdate=!1,e.matrix.identity(),e.matrixWorldNeedsUpdate=!0,e.scale.set(Et.sizeMAt(c,n.projection.pxToDeg(s.width)),Et.sizeMAt(c,n.projection.pxToDeg(s.height)),1)}flat(e,t,i,n,s){const a=e.geometry.attributes.position,o=Cn.SEGMENTS,c=Et.sizeMAt(s,i.projection.pxToDeg(n.width)),l=Et.sizeMAt(s,i.projection.pxToDeg(n.height));this.up.set(0,1,0).applyQuaternion(t.quaternion),this.centre.copy(t.position).addScaledVector(this.direction,s),this.lookAt.lookAt(t.position,this.centre,this.up),this.right.setFromMatrixColumn(this.lookAt,0),this.above.setFromMatrixColumn(this.lookAt,1);let h=0;for(let u=0;u<=o;u++){const d=.5-u/o;for(let f=0;f<=o;f++){const p=f/o-.5;this.vertex.copy(this.centre).addScaledVector(this.right,p*c).addScaledVector(this.above,d*l),a.setXYZ(h++,this.vertex.x,this.vertex.y,this.vertex.z)}}a.needsUpdate=!0,e.matrixAutoUpdate=!1,e.matrix.identity(),e.matrixWorldNeedsUpdate=!0,e.scale.set(c,l,1)}static SEGMENTS=16;static directionOf(e,t){const i=e.azimuthDeg*Math.PI/180,n=e.altitudeDeg*Math.PI/180;return t.set(Math.sin(i)*Math.cos(n),Math.sin(n),-Math.cos(i)*Math.cos(n))}get any(){for(const e of this.meshes.values())if(e.visible)return!0;return!1}get furthestM(){return this.placed.reduce((e,t)=>Math.max(e,t.distanceM),0)}paint(e,t,i){const{shape:n}=t,s=zo.paintExtent(n),a=t.ghost?3:0,o={x:s.x-a,y:s.y-a,width:s.width+2*a,height:s.height+2*a};this.extents.set(t.sourceId,o);const c=`${Cn.signatureOf(n,i)}|${t.ghost?"ghost":""}`;if(this.signatures.get(t.sourceId)===c&&e.material.map)return;this.signatures.set(t.sourceId,c);const l=Math.min(i.scale,lE/Math.max(o.width,o.height,1)),h=Math.max(1,Math.ceil(o.width*l)),u=Math.max(1,Math.ceil(o.height*l)),d=e.material.map,f=d?.image??document.createElement("canvas"),p=f.width!==h||f.height!==u;p&&(f.width=h,f.height=u);const v=f.getContext("2d");if(!v)return;v.clearRect(0,0,h,u);const m=new zo(v);if(m.setStarPoints(i.starPoints),m.setRoll(i.rollRad),m.paintInto(n,o,l,t.ghost),d&&!p){d.needsUpdate=!0;return}d?.dispose();const g=new Ls(f);g.colorSpace=Vi,g.minFilter=rt,g.generateMipmaps=!1,e.material.map=g,e.material.needsUpdate=!0}static signatureOf(e,t){const{bounds:i}=e;return JSON.stringify([e.kind,Math.round(i.width*10),Math.round(i.height*10),e.color,e.angle,e.transparency,e.haloScale,e.blur??0,e.brightness??0,e.kind==="polygon"?e.points:void 0,t.scale,t.starPoints,t.rollRad])}dispose(e){e.removeFromParent(),e.geometry.dispose(),e.material.map?.dispose(),e.material.dispose()}clear(){for(const e of this.meshes.values())this.dispose(e);this.meshes.clear(),this.signatures.clear(),this.extents.clear(),this.placed=[]}}const ov=3,Kc=800,fo=Math.PI/180;class Rn{constructor(e,t,i=Rn.fetchImage){this.scene=e,this.onImageLoaded=t,this.loadImage=i}meshes=new Map;signatures=new Map;images=new Map;loading=new Map;failed=new Set;references=[];views=new Map;shown=!0;observerAt;static PRESENT_WITHIN_M=2;static GONE_BEYOND_M=20;static presenceAt(e,t){if(!e.from||!t)return 1;const i=ni(t.lat,t.lng,e.from.lat,e.from.lng),s=(Math.hypot(i.x,i.z)-Rn.PRESENT_WITHIN_M)/(Rn.GONE_BEYOND_M-Rn.PRESENT_WITHIN_M),a=Math.min(Math.max(s,0),1);return 1-a*a*(3-2*a)}set(e,t=this.views,i){this.references=e,this.observerAt=i,this.views=t;const n=new Set(e.map(s=>s.id));for(const[s,a]of this.meshes)n.has(s)||(this.dispose(a),this.meshes.delete(s),this.signatures.delete(s));for(const[s,a]of this.images){const o=e.find(c=>c.id===s);o&&o.src===a.texture.userData.src||(a.texture.dispose(),this.images.delete(s))}for(const s of e){const a=this.images.get(s.id);if(!a){this.load(s);continue}this.build(s,a)}}setShown(e){this.shown=e;for(const t of this.meshes.values())t.visible=e&&this.opacityOf(t.userData.id)>0}setView(e,t){this.views.set(e,t);const i=this.meshes.get(e);i&&this.applyOpacity(i,e)}get any(){for(const e of this.meshes.values())if(e.visible)return!0;return!1}place(e){for(const t of this.meshes.values())t.visible&&(t.position.copy(e.position),t.updateMatrixWorld())}get furthestM(){return this.meshes.size>0?Kc:0}directionOfPixel(e,t,i,n){const s=this.images.get(e.id),a=s?s.width/s.height:1,o=Math.tan(e.registration.fovDeg/2*fo),c=o*a;return n.set((t*2-1)*c,(1-i*2)*o,-1).normalize(),n.applyQuaternion(Rn.orientation(e))}aspectOf(e){const t=this.images.get(e);return t?t.width/t.height:void 0}failedToLoad(e){return this.failed.has(e)}load(e){const t=e.src;if(this.loading.has(e.id)||this.failed.has(t))return;const i=this.loadImage(t).then(n=>{this.loading.delete(e.id);const s=this.references.find(a=>a.id===e.id);if(!s||s.src!==t){n.texture.dispose();return}n.texture.userData.src=t,this.images.set(e.id,n),this.build(s,n),this.onImageLoaded()},()=>{this.loading.delete(e.id),this.failed.add(t)});this.loading.set(e.id,i)}static async fetchImage(e){const t=await fetch(e);if(!t.ok)throw new Error(`${e}: ${t.status}`);const i=await createImageBitmap(await t.blob(),{imageOrientation:"flipY"}),n=new Si(i);return n.flipY=!1,n.colorSpace=Vi,n.minFilter=rt,n.magFilter=rt,n.generateMipmaps=!1,n.needsUpdate=!0,{texture:n,width:i.width,height:i.height}}build(e,t){const i=Rn.signatureOf(e,t);let n=this.meshes.get(e.id);if(n&&this.signatures.get(e.id)===i){this.applyOpacity(n,e.id);return}n&&(this.dispose(n),this.meshes.delete(e.id)),n=new De(Rn.geometryOf(e,t),new bn({map:t.texture,transparent:!0,depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1})),e.kind==="panorama"&&(n.material.side=Ht),n.frustumCulled=!1,n.layers.set(ov),n.userData.id=e.id,n.quaternion.copy(Rn.orientation(e)),this.scene.add(n),this.meshes.set(e.id,n),this.signatures.set(e.id,i),this.applyOpacity(n,e.id)}static geometryOf(e,t){if(e.kind==="panorama"){const a=new ri(Kc,64,32,Math.PI/2,Math.PI*2),o=a.attributes.uv;for(let c=0;c<o.count;c++)o.setX(c,1-o.getX(c));return o.needsUpdate=!0,a}const i=2*Kc*Math.tan(e.registration.fovDeg/2*fo),n=i*(t.width/Math.max(t.height,1)),s=new Yi(n,i);return s.translate(0,0,-Kc),s}static orientation(e){const{headingDeg:t,pitchDeg:i,rollDeg:n}=e.registration,s=new Ut;return s.rotation.set(i*fo,-t*fo,-(n??0)*fo,"YXZ"),s.quaternion}opacityOf(e){const t=this.references.find(s=>s.id===e),i=this.views.get(e),n=t?Rn.presenceAt(t,this.observerAt):1;return(i?.opacity??t?.opacity??0)*n}applyOpacity(e,t){const i=this.opacityOf(t);e.material.opacity=i,e.visible=this.shown&&i>0}static signatureOf(e,t){const{headingDeg:i,pitchDeg:n,rollDeg:s,fovDeg:a}=e.registration;return[e.kind,e.src,t.width,t.height,i,n,s??0,a].join("|")}dispose(e){this.scene.remove(e),e.geometry.dispose(),e.material.dispose()}disposeAll(){for(const e of this.meshes.values())this.dispose(e);this.meshes.clear(),this.signatures.clear();for(const e of this.images.values())e.texture.dispose();this.images.clear()}}class Fe{static GROUND_RADIUS_M=636e4;static TOP_RADIUS_M=646e4;static WAVELENGTHS_NM=Array.from({length:15},(e,t)=>410+20*t);static WAVELENGTH_STEP_NM=20;static SOLAR_IRRADIANCE=[1.707,1.676,1.982,2.02,1.941,1.87,1.879,1.856,1.839,1.799,1.728,1.668,1.57,1.532,1.452];static OZONE_CROSS_SECTION=[.021,.069,.19,.418,.827,1.531,2.439,3.291,4.468,4.55,4.663,3.477,2.447,1.658,1.071];static RAYLEIGH_SCALE_HEIGHT_M=8e3;static AEROSOL_SCALE_HEIGHT_M=1200;static OZONE_PEAK_ALTITUDE_M=25e3;static OZONE_HALF_WIDTH_M=15e3;static DEFAULT_AEROSOL_OPTICAL_DEPTH=.1;static DEFAULT_OZONE_DOBSON=300;static AEROSOL_SINGLE_SCATTERING_ALBEDO=.9;static AEROSOL_ANGSTROM_EXPONENT=1.3;static AEROSOL_ASYMMETRY=.8;rayleighScattering;aerosolScattering;aerosolExtinction;ozoneAbsorption;constructor(e={}){const t=Fe.WAVELENGTHS_NM.length,i=e.aerosolOpticalDepth??Fe.DEFAULT_AEROSOL_OPTICAL_DEPTH,n=e.ozoneDobson??Fe.DEFAULT_OZONE_DOBSON;this.rayleighScattering=new Float64Array(t),this.aerosolScattering=new Float64Array(t),this.aerosolExtinction=new Float64Array(t),this.ozoneAbsorption=new Float64Array(t);const s=n*2687e17/Fe.OZONE_HALF_WIDTH_M;for(let a=0;a<t;a++){const o=Fe.WAVELENGTHS_NM[a];this.rayleighScattering[a]=Fe.rayleighAt(o);const c=i/Fe.AEROSOL_SCALE_HEIGHT_M*(o/550)**-1.3;this.aerosolExtinction[a]=c,this.aerosolScattering[a]=c*Fe.AEROSOL_SINGLE_SCATTERING_ALBEDO,this.ozoneAbsorption[a]=Fe.OZONE_CROSS_SECTION[a]*1e-25*s}}static rayleighAt(e){const t=e/1e3,i=1/(t*t),n=t*t;return(1.0455996-341.29061*i-.9023085*n)/(1+.0027059889*i-85.968563*n)*1e-28*1e-4*2546899e19}static rayleighDensity(e){return Math.exp(-Math.max(e,0)/Fe.RAYLEIGH_SCALE_HEIGHT_M)}static aerosolDensity(e){return Math.exp(-Math.max(e,0)/Fe.AEROSOL_SCALE_HEIGHT_M)}static ozoneDensity(e){return Math.max(0,1-Math.abs(e-Fe.OZONE_PEAK_ALTITUDE_M)/Fe.OZONE_HALF_WIDTH_M)}static rayleighPhase(e){return 3/(16*Math.PI)*(1+e*e)}static aerosolPhase(e,t=Fe.AEROSOL_ASYMMETRY){const i=t*t;return 3/(8*Math.PI)*(1-i)*(1+e*e)/((2+i)*Math.pow(Math.max(1+i-2*t*e,1e-6),1.5))}}class We{static TRANSMITTANCE_WIDTH=256;static TRANSMITTANCE_HEIGHT=64;static MULTIPLE_SIZE=64;static MULTIPLE_ROWS=16;static MULTIPLE_HEIGHT_POWER=2;static MULTIPLE_DIRECTIONS=16;static SKY_VIEW_WIDTH=192;static SKY_VIEW_HEIGHT=108;static STEPS=40;static MULTIPLE_STEPS=12;static GROUND_ALBEDO=.3;supported;renderer;transmittance;multiple;sunView;moonView;scene=new Is;camera=new zn(-1,1,1,-1,0,1);quad;transmittanceMaterial;multipleMaterial;skyViewMaterial;transmittanceReady=!1;multipleRows=0;multipleColumn=0;mediumKey="";static MULTIPLE_BLOCK=16;static shared=new Map;building=!1;adopted;tableUniforms;constructor(e){this.renderer=e,this.supported=e.capabilities.isWebGL2&&e.extensions.has("EXT_color_buffer_float"),this.transmittance=new ai(We.TRANSMITTANCE_WIDTH,We.TRANSMITTANCE_HEIGHT,{count:4,type:Wt,minFilter:rt,magFilter:rt,depthBuffer:!1}),this.multiple=new ai(We.MULTIPLE_SIZE,We.MULTIPLE_ROWS,{count:4,type:Oi,minFilter:At,magFilter:At,depthBuffer:!1});const t=()=>new ai(We.SKY_VIEW_WIDTH,We.SKY_VIEW_HEIGHT,{type:Oi,minFilter:At,magFilter:At,depthBuffer:!1});this.sunView=t(),this.moonView=t();const i=We.mediumUniforms(),n=this.tableUniforms={uT0:{value:this.transmittance.textures[0]},uT1:{value:this.transmittance.textures[1]},uT2:{value:this.transmittance.textures[2]},uT3:{value:this.transmittance.textures[3]},uM0:{value:this.multiple.textures[0]},uM1:{value:this.multiple.textures[1]},uM2:{value:this.multiple.textures[2]},uM3:{value:this.multiple.textures[3]}},s=(a,o={})=>new u1({glslVersion:Tl,uniforms:{...i,...n,...o},vertexShader:We.VERTEX,fragmentShader:a,depthTest:!1,depthWrite:!1});this.transmittanceMaterial=s(We.TRANSMITTANCE_FRAGMENT),this.multipleMaterial=s(We.MULTIPLE_FRAGMENT),this.skyViewMaterial=s(We.SKY_VIEW_FRAGMENT,{uObserverRadius:{value:Fe.GROUND_RADIUS_M+2},uSourceMu:{value:1}}),this.quad=new De(new Yi(2,2),this.transmittanceMaterial),this.quad.frustumCulled=!1,this.scene.add(this.quad)}get transmittanceTextures(){return this.transmittance.textures}get sunViewTexture(){return this.sunView.texture}get moonViewTexture(){return this.moonView.texture}get ready(){return this.supported&&(this.adopted!==void 0||this.transmittanceReady&&this.multipleRows>=We.MULTIPLE_ROWS)}setMedium(e){const t=[e.rayleighScattering,e.aerosolScattering,e.aerosolExtinction,e.ozoneAbsorption].map(n=>Array.from(n,s=>s.toPrecision(6)).join(",")).join("|");if(t===this.mediumKey)return;this.abandonBuilding(),this.releaseAdopted(),this.mediumKey=t;const i=(n,s)=>{const a=this.transmittanceMaterial.uniforms[n].value;for(let o=0;o<4;o++)a[o].set(s[o*4]??0,s[o*4+1]??0,s[o*4+2]??0,s[o*4+3]??0)};i("uRayleigh",e.rayleighScattering),i("uAerosolScattering",e.aerosolScattering),i("uAerosolExtinction",e.aerosolExtinction),i("uOzone",e.ozoneAbsorption),this.transmittanceReady=!1,this.multipleRows=0,this.multipleColumn=0}invalidate(){this.adopted||(this.abandonBuilding(),this.transmittanceReady=!1,this.multipleRows=0,this.multipleColumn=0)}advance(e){if(!this.supported||!this.mediumKey)return!1;if(this.ready)return!0;const t=We.shared.get(this.mediumKey);if(t&&t!=="building")return this.adopt(t),!0;if(t==="building"&&!this.building)return!1;t||(We.shared.set(this.mediumKey,"building"),this.building=!0);const i=this.renderer.getRenderTarget();let n=Math.max(1,e);this.transmittanceReady||(this.draw(this.transmittanceMaterial,this.transmittance),this.transmittanceReady=!0,n--);const s=We.MULTIPLE_SIZE,a=We.MULTIPLE_BLOCK;for(;n>0&&this.multipleRows<We.MULTIPLE_ROWS;n--)this.multiple.scissor.set(this.multipleColumn,this.multipleRows,a,1),this.multiple.scissorTest=!0,this.draw(this.multipleMaterial,this.multiple),this.multipleColumn+=a,this.multipleColumn>=s&&(this.multipleColumn=0,this.multipleRows++);return this.multiple.scissorTest=!1,this.renderer.setRenderTarget(i),this.ready&&this.building&&this.share(this.mediumKey),this.ready}async share(e){this.building=!1;try{const t=await Promise.all([0,1,2,3].map(n=>this.readRaw(this.transmittance,n,Uint16Array))),i=await Promise.all([0,1,2,3].map(n=>this.readRaw(this.multiple,n,Float32Array)));this.mediumKey===e?We.shared.set(e,{transmittance:t,multiple:i}):We.shared.delete(e)}catch{We.shared.delete(e)}}async readRaw(e,t,i){const n=new i(e.width*e.height*4);return await this.renderer.readRenderTargetPixelsAsync(e,0,0,e.width,e.height,n,void 0,t),n}adopt(e){const t=(s,a,o,c)=>{const l=new ca(s,a,o,Ei,c?Wt:Oi);return l.minFilter=l.magFilter=c?rt:At,l.needsUpdate=!0,l},i=e.transmittance.map(s=>t(s,We.TRANSMITTANCE_WIDTH,We.TRANSMITTANCE_HEIGHT,!0)),n=e.multiple.map(s=>t(s,We.MULTIPLE_SIZE,We.MULTIPLE_ROWS,!1));i.forEach((s,a)=>this.tableUniforms[`uT${a}`].value=s),n.forEach((s,a)=>this.tableUniforms[`uM${a}`].value=s),this.adopted=[...i,...n]}releaseAdopted(){if(this.adopted){for(const e of this.adopted)e.dispose();this.adopted=void 0;for(let e=0;e<4;e++)this.tableUniforms[`uT${e}`].value=this.transmittance.textures[e],this.tableUniforms[`uM${e}`].value=this.multiple.textures[e]}}abandonBuilding(){this.building&&(this.building=!1,We.shared.get(this.mediumKey)==="building"&&We.shared.delete(this.mediumKey))}renderSkyViews(e,t,i){if(!this.ready)return;const n=this.renderer.getRenderTarget(),s=this.skyViewMaterial.uniforms;s.uObserverRadius.value=Fe.GROUND_RADIUS_M+Math.max(e,2),s.uSourceMu.value=Math.sin(t*Math.PI/180),this.draw(this.skyViewMaterial,this.sunView),s.uSourceMu.value=Math.sin(i*Math.PI/180),this.draw(this.skyViewMaterial,this.moonView),this.renderer.setRenderTarget(n)}static skyViewUv(e,t,i){const n=Fe.GROUND_RADIUS_M+Math.max(e,2),s=Fe.GROUND_RADIUS_M,a=Math.acos(Math.min(Math.sqrt(Math.max(n*n-s*s,0))/n,1)),o=Math.PI-a,c=t<o?.5*(1-Math.sqrt(Math.max(1-t/o,0))):.5+.5*Math.sqrt(Math.min((t-o)/a,1));return{u:Math.min(Math.max(Math.abs(i)/Math.PI,0),1),v:c}}async readTable(e,t){if(e==="multiple"){const s=new Float32Array(this.multiple.width*this.multiple.height*4);return await this.renderer.readRenderTargetPixelsAsync(this.multiple,0,0,this.multiple.width,this.multiple.height,s,void 0,t),s}const i=this.transmittance,n=new Uint16Array(i.width*i.height*4);return await this.renderer.readRenderTargetPixelsAsync(i,0,0,i.width,i.height,n,void 0,t),Float32Array.from(n,s=>kn.fromHalfFloat(s))}readSkyViewNow(e){const t=e==="sun"?this.sunView:this.moonView,i=new Float32Array(t.width*t.height*4),n=this.renderer.getContext();return n.bindBuffer(n.PIXEL_PACK_BUFFER,null),this.renderer.readRenderTargetPixels(t,0,0,t.width,t.height,i),i}async readSkyView(e){const t=e==="sun"?this.sunView:this.moonView,i=new Float32Array(t.width*t.height*4);return await this.renderer.readRenderTargetPixelsAsync(t,0,0,t.width,t.height,i),i}dispose(){this.abandonBuilding(),this.releaseAdopted(),this.transmittance.dispose(),this.multiple.dispose(),this.sunView.dispose(),this.moonView.dispose(),this.transmittanceMaterial.dispose(),this.multipleMaterial.dispose(),this.skyViewMaterial.dispose(),this.quad.geometry.dispose()}draw(e,t){this.quad.material=e,this.renderer.setRenderTarget(t),this.renderer.render(this.scene,this.camera)}static mediumUniforms(){const e=()=>[new it,new it,new it,new it],t=(i,n)=>{const s=e();return Fe.WAVELENGTHS_NM.forEach((a,o)=>{s[Math.floor(o/4)].setComponent(o%4,i(a)*n*Fe.WAVELENGTH_STEP_NM*Fe.SOLAR_IRRADIANCE[o])}),s};return{uRayleigh:{value:e()},uAerosolScattering:{value:e()},uAerosolExtinction:{value:e()},uOzone:{value:e()},uCieX:{value:t(i=>fi.colourMatching(i)[0],683)},uCieY:{value:t(i=>fi.colourMatching(i)[1],683)},uCieZ:{value:t(i=>fi.colourMatching(i)[2],683)},uScotopic:{value:t(i=>fi.scotopic(i),1700)}}}static VERTEX=`
|
|
7296
7296
|
in vec3 position;
|
|
7297
7297
|
void main() {
|
|
7298
7298
|
gl_Position = vec4(position.xy, 0.0, 1.0);
|
|
@@ -7711,7 +7711,7 @@ cloudPoint = (modelMatrix * vec4(transformed, 1.0)).xyz - cameraPosition;`);let
|
|
|
7711
7711
|
vec3 light = texture2D(uMap, vec2((along * (uSteps - 1.0) + 0.5) / uSteps, 0.5)).rgb;
|
|
7712
7712
|
gl_FragColor = vec4(light, 1.0);
|
|
7713
7713
|
}
|
|
7714
|
-
`,transparent:!0,blending:Ni,depthWrite:!1,side:Ht,fog:!1});this.object=new De(new ri(K0.RADIUS,128,32,0,Math.PI*2,0,dt.MAX_ANGLE_RAD),t),this.object.renderOrder=-1,this.object.frustumCulled=!1,this.object.visible=!1}show(e,t){if(!e||!t){this.object.visible=!1;return}this.towards.set(e.x,e.y,e.z).normalize(),this.object.quaternion.setFromUnitVectors(this.up,this.towards),this.object.material.uniforms.uSource.value.copy(this.towards);for(let i=0;i<dt.STEPS;i++){for(let n=0;n<3;n++)this.texels[i*4+n]=kn.toHalfFloat(Math.min(t[i*3+n],6e4));this.texels[i*4+3]=kn.toHalfFloat(1)}this.texture.needsUpdate=!0,this.object.visible=!0}dispose(){this.object.geometry.dispose(),this.object.material.dispose(),this.texture.dispose()}}class Bl{constructor(e){this.generator=e}static SIZE=128;target=new qo(Bl.SIZE,{type:Wt,generateMipmaps:!1,minFilter:rt,magFilter:rt});camera=new P0(.1,2e5,this.target);filteredTarget;capturedAtMs=-1/0;capturedVersion;get sharp(){return this.target.texture}get filtered(){return this.filteredTarget?.texture}capture(e,t,i,n=[]){const s=e.shadowMap.autoUpdate;e.shadowMap.autoUpdate=!1;const a=n.map(o=>o.visible);for(const o of n)o.visible=!1;this.camera.position.copy(i),this.camera.update(e,t),n.forEach((o,c)=>{o.visible=a[c]}),e.shadowMap.autoUpdate=s,this.filteredTarget=this.generator.fromCubemap(this.target.texture,this.filteredTarget),this.capturedAtMs=performance.now()}dispose(){this.target.dispose(),this.filteredTarget?.dispose()}}class cn{static REFRESH_MS=250;generator;eye;probes=new Map;constructor(e){cn.install(),this.generator=new Sd(e),this.eye=new Bl(this.generator)}static decor;refresh(e,t,i,n,s,a,o,c=[],l){for(const v of[...this.probes.keys()])n.some(m=>m.id===v&&m.shiny)||(this.probes.get(v).dispose(),this.probes.delete(v));const h=[{probe:this.eye}];for(const v of n){if(!v.shiny)continue;let m=this.probes.get(v.id);m||(m=new Bl(this.generator),this.probes.set(v.id,m)),h.push({probe:m,reflector:v})}const u=performance.now(),d=()=>h.filter(({probe:v})=>v.capturedVersion!==o),f=d().filter(({probe:v})=>u-v.capturedAtMs>=cn.REFRESH_MS);if(f.length>0){const v=f.reduce((m,g)=>g.probe.capturedAtMs<m.probe.capturedAtMs?g:m);if(v.reflector){const m=v.reflector.holder.getWorldPosition(this.scratch);v.probe.capture(e,t,m,[v.reflector.holder,...s]),cn.reflectOn(v.reflector.holder,v.probe)}else{v.probe.capture(e,t,i,[...s,...c]),l?.(v.probe.sharp),cn.decor=v.probe.filtered;for(const m of a)cn.reflectOn(m,v.probe);for(const m of n)m.shiny||cn.reflectOn(m.holder,v.probe)}v.probe.capturedVersion=o}const p=d();if(p.length!==0)return Math.max(16,Math.min(...p.map(({probe:v})=>cn.REFRESH_MS-(u-v.capturedAtMs))))}scratch=new R;static reflectOn(e,t={filtered:cn.decor}){e.traverse(i=>{const n=i.material;for(const s of Array.isArray(n)?n:n?[n]:[])s instanceof Ko?t.sharp&&s.setSurroundings(t.sharp):s instanceof _a&&t.filtered&&s.envMap!==t.filtered&&(s.envMap=t.filtered,s.needsUpdate=!0)})}dispose(){this.eye.dispose();for(const e of this.probes.values())e.dispose();this.generator.dispose()}static installed=!1;static install(){if(cn.installed)return;cn.installed=!0;const e="iblIrradiance += getIBLIrradiance( geometryNormal );";if(!Xe.lights_fragment_maps.includes(e)){console.warn("Reflections: three's lights_fragment_maps changed; the environment will light diffusely too");return}Xe.lights_fragment_maps=Xe.lights_fragment_maps.replace(e,"// The sky's diffuse light is the hemisphere light's (see Reflections).")}}function hE(r,e){return JSON.stringify(r.cloudLayers)===JSON.stringify(e.cloudLayers)&&r.cloudCover===e.cloudCover&&r.cloudDarkness===e.cloudDarkness&&r.cloudBaseM===e.cloudBaseM&&r.highCloudCover===e.highCloudCover&&r.iceCrystalAlignment===e.iceCrystalAlignment&&r.lowerCloudCover===e.lowerCloudCover&&r.relativeHumidity===e.relativeHumidity&&r.precipitationType===e.precipitationType&&r.precipitationIntensity===e.precipitationIntensity&&r.precipitationAmount===e.precipitationAmount&&r.windDirectionDeg===e.windDirectionDeg&&r.windSpeed===e.windSpeed&&r.storm===e.storm}const Zc=900,cu=1,Fm=4,Um=5,km=.5,Eo=900,uE=6371e3,dE=3e4;function zm(r){const e=Math.sqrt(2*uE*Math.max(r,0));return Math.max(Eo,Math.min(e,dE))}const lu=.5,hu=850,Bm=.03,an=850,po=300,Xs=120,fE=700,pE=.04,mo=4,uu=1.5,Hm=-1,mE=6,i0=-4,gE=2,vE=20,Jc=2600,ME=.97,xE=.38,jc=i0,Gm=1500,yE=400,bE=[0,45,90,135,180,225,270,315],_E=2,SE=16,Vm=2500,Wm=880,Qc=40,Xm=60,wE=10,EE=1,AE=150,TE=55,RE=.5,DE=17,Ym=.265,qm=[[0,0],...Array.from({length:8},(r,e)=>{const t=e*Math.PI/4;return[Math.cos(t)*Ym,Math.sin(t)*Ym]})],du=700,fu=250/s0,IE=12,$m=5,pu=6,ga=[.92,.92,.95],mu=[.15,.15,.19],gu={snow:{fallSpeedMPerS:2,size:.3,color:new se(1,1,1),driftSensitivity:1,radiusM:25,topYM:20,opacity:.75,poolSize:2400},hail:{fallSpeedMPerS:14,size:.5,color:new se(.95,.98,1),driftSensitivity:.25,radiusM:25,topYM:10,opacity:.95,poolSize:1200}},vr=0,vu=0,CE=150,Mu=3e3,go=20,PE=15,Km=vr,LE=40,Zm=1,OE=9;function xu(r){return Zm+(OE-Zm)*r}const Jm=new se(.75,.82,.92),NE=10,FE=.5;function jm(r){return Sr(r/NE,FE,1)}const va=200,Qm=.18,eg=.32,UE=.35,tg=new se(.85,.9,.98),ig=5,ng=.85,sg=.01;function kE(r,e,t=1){return Math.round(r*(sg+(1-sg)*e)*t)}function zE(r,e){return JSON.stringify(r.cloudLayers)===JSON.stringify(e.cloudLayers)&&r.cloudCover===e.cloudCover&&r.cloudDarkness===e.cloudDarkness&&r.cloudBaseM===e.cloudBaseM&&r.highCloudCover===e.highCloudCover&&r.iceCrystalAlignment===e.iceCrystalAlignment&&r.lowerCloudCover===e.lowerCloudCover}const ag=230,rg=.7,og=.05,BE=.6,HE=.7,GE=.15,cg=.35,VE=3,WE=1/12,XE=.5,qn=new se(.82,.86,1),YE=2500,qE=1.6,yu=15,$E={Venus:new se(1,.96,.85),Mars:new se(1,.55,.4),Jupiter:new se(.95,.87,.72),Saturn:new se(.92,.86,.68)};class zt{renderer;scene=new Is;phenomena=new Cn(this.scene);references=new Rn(this.scene,()=>this.render());camera;celestialGroup=new Dt;skyMesh;skyGradientMaterial;scatteredSky;lastAstronomy;skyColoursStale=!1;scatteredSkyFrameId=null;skyHoldUntilMs=void 0;onFirstFrameHold;firstFrameReady(){return(!this.scatteredSky||this.scatteredSky.ambient!==void 0)&&!this.iceHalos?.awaitingFirstDisplay}groundMesh;terrainMesh;terrainProviders;terrainOrigin;terrainBuildToken=0;terrainAttribution;roadSystem=new vn;roadAttribution;roadWays;statedRoads=[];decorModelProvider=oE[0].create();decorModelToken=0;decorModelCredits=new Map;bodySystem=new ht(e=>this.loadBodyModel(e),()=>this.render(),()=>this.relativeScale);bodyOrigin={x:0,z:0};starTiers=[];bodyMeshes=new Map;hitAreas=new Map;glareSprites=new Map;decorObjects=[];decorGroups=new Map;decorReferencePose;decorCurrentPose;decorTime=0;celestialLight=new Dp(16777215,0);celestialLightTarget=new Ut;skyLight=new Ox(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 dl;weather=a0;observerElevationM=0;siteElevationM=0;air=new xn;groundRadius=Eo;terrainRadius=Eo;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 xe;lightningArmed=!1;lightningFlashes=[];lightningLevel=0;lightningBolt;lightningLight=new Dp(16777215,0);baseFogColor=[0,0,0];lastSunPosition;lensFlare;sunUnhiddenFraction=1;lensFlareArtifactIntensity=0;sunWorldPosition=new R;sunVisible=!1;lensFlareScratch=new R;sunOcclusionRaycaster=new dl;sunOcclusionDirectionScratch=new R;sunOcclusionRightScratch=new R;sunOcclusionUpScratch=new R;ufoOcclusionRaycaster=new dl;projectionKind="rectilinear";starPoints=0;namedStars=[];equidistantPass;depthOfFieldPass;finishPass;exposureAccumulation;exposureInstants=1;get developingExposure(){return this.exposureInstants>1&&this.exposureInstantAt!==void 0}static EXPOSURE_BUDGET_MS=12;static exposureInstantsPerFrame(e){return Math.max(3,Math.round(6e6/Math.max(1,e)))}exposureFrameId=null;exposureInstantsDone=0;exposureInstantAt;restatingExposure=!1;lensOptics;instrumentMagnitudeGain=0;lightPollution;meteorSystem;cometTail;satelliteField;iceHalos;lunarDiffraction;lunarDiffractionKey="";rainbow;skyGlow;cometKey;novaKeys=new Set;constructor(e,t=O2()){this.renderer=new qS({canvas:e,antialias:!0}),this.resolution=new mt(Math.min(window.devicePixelRatio||1,2),this.renderer.getContext()),this.renderer.setPixelRatio(this.resolution.pixelRatio),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=To,this.camera=new Ji(60,e.width/Math.max(e.height,1),.1,Zc*1.2),this.camera.position.set(0,1.6,0),this.terrainProviders=t,this.celestialLight.shadow.mapSize.set(1024,1024),this.celestialLight.shadow.camera.left=-Xs,this.celestialLight.shadow.camera.right=Xs,this.celestialLight.shadow.camera.top=Xs,this.celestialLight.shadow.camera.bottom=-Xs,this.celestialLight.shadow.camera.near=an-po,this.celestialLight.shadow.camera.far=an+po,this.celestialLight.shadow.bias=-.03/(2*po),this.celestialLight.shadow.normalBias=pE,this.celestialLight.target=this.celestialLightTarget,this.lightningLight.color.copy(qn),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 Lt(this.renderer,()=>{this.skyColoursStale=!0,this.render()});i.supported?this.scatteredSky=i:i.dispose()}get currentTerrainAttribution(){return this.terrainAttribution}get currentRoadAttribution(){return this.roadAttribution}resize(e,t){this.cssSize.width=e,this.cssSize.height=t,this.renderer.setSize(e,t,!1),this.camera.aspect=e/Math.max(t,1),this.camera.updateProjectionMatrix(),this.render()}setCloudRendering(e){e!==this.cloudRendering&&(this.cloudTransmissionMemo.clear(),this.cloudRendering=e,this.layeredClouds?.dispose(),this.layeredClouds=void 0,this.buildClouds(),this.buildCirrus(),this.render())}setCloudOffset(e,t={}){this.cloudOffsetM.set(e.x,0,e.z),this.cloudLayerOffsetsM=t,this.layeredClouds?.setOffsets(e,t),this.cloudFieldOffset.set(e.x*fu,0,e.z*fu);for(const i of[this.cloudUniforms,this.cirrusUniforms])i?.fieldOffset.value.copy(this.cloudFieldOffset);this.iceHalos?.setCloudOffset(this.layeredClouds?.cirrusMask?.offset??this.cloudFieldOffset)}setObserverPose(e){const t=((e.rollDeg??0)+this.gaitOffset.rollDeg)*qi,i=(e.pitchDeg+this.lookPitchDeg+this.gaitOffset.pitchDeg)*qi;if(e.headingDeg!==void 0?this.camera.rotation.set(i,-(e.headingDeg+this.lookYawDeg+this.gaitOffset.yawDeg)*qi,t,"YXZ"):this.camera.rotation.set(i,this.camera.rotation.y,t,"YXZ"),e.elevationM!==this.observerElevationM&&(this.observerElevationM=e.elevationM,this.syncCloudLayer(),Math.abs(zm(e.elevationM)-this.groundRadius)>1&&(this.buildGround(),this.celestialGroup.scale.setScalar(this.groundRadius/Eo),this.camera.far=Math.max(Zc*1.2,this.groundRadius*2.5),this.camera.updateProjectionMatrix())),this.terrainMesh&&this.terrainOrigin&&e.lat!==void 0&&e.lng!==void 0){const n=ni(this.terrainOrigin.lat,this.terrainOrigin.lng,e.lat,e.lng);this.terrainMesh.position.x=n.x,this.terrainMesh.position.z=n.z}this.poseCameraY=this.groundYUnder(0,0)+1.6+e.elevationM,this.camera.position.y=this.poseCameraY,this.celestialGroup.position.y=this.camera.position.y,this.camera.fov!==e.fovDeg&&(this.camera.fov=e.fovDeg,this.camera.updateProjectionMatrix(),this.updateCompassScale())}setTerrainProviders(e){this.stopTerrainFade(),this.terrainProviders=e,this.disposeMesh(this.terrainMesh),this.terrainMesh=void 0,this.terrainOrigin=void 0,this.terrainAttribution=void 0,this.roadSystem.clear(),this.roadAttribution=void 0,this.roadWays=void 0,this.applyGroundDepthWrite(),this.terrainBuildToken++}setTerrainOrigin(e,t,i){if(e===void 0||t===void 0)return;const n=this.groundRadius;if(this.terrainOrigin&&Math.abs(this.terrainRadius-n)<n*.1){const{x:c,z:l}=ni(e,t,this.terrainOrigin.lat,this.terrainOrigin.lng);if(Math.sqrt(c*c+l*l)<AE*(n/Eo))return}const s=this.terrainOrigin,a=this.terrainRadius;(!s||s.lat!==e||s.lng!==t)&&(this.roadSystem.clear(),this.roadAttribution=void 0),this.terrainOrigin={lat:e,lng:t},this.terrainRadius=n;const o=++this.terrainBuildToken;x5(e,t,this.terrainProviders,n).then(({mesh:c,attribution:l,originElevationM:h})=>{if(o!==this.terrainBuildToken)return;this.setSiteElevation(h??0);const u=this.terrainMesh,d=s?ni(e,t,s.lat,s.lng):void 0;u&&d&&Math.hypot(d.x,d.z)<=a&&(c.position.y=u.position.y+this.groundYOfPatch(u,d.x,d.z)),u&&d&&Math.hypot(d.x,d.z)<=a?this.crossfadeTerrain(c,u):this.disposeMesh(this.terrainMesh),c.renderOrder=EE,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(e,t,n),this.drapeStatedRoads(),this.render(),i?.()}).catch(c=>{console.warn("Terrain build failed, keeping the flat ground fallback:",c),i?.()})}static TERRAIN_CROSSFADE_MS=1200;fadingTerrain;crossfadeTerrain(e,t){this.stopTerrainFade();const i=e.material;i.opacity=0,i.polygonOffset=!0,i.polygonOffsetFactor=-1,i.polygonOffsetUnits=-4;const n=performance.now(),s=()=>{const a=Math.min(1,(performance.now()-n)/zt.TERRAIN_CROSSFADE_MS);if(i.opacity=a*a*(3-2*a),this.render(),a<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:t,frameId:requestAnimationFrame(s)}}stopTerrainFade(){if(!this.fadingTerrain)return;cancelAnimationFrame(this.fadingTerrain.frameId),this.disposeMesh(this.fadingTerrain.mesh),this.fadingTerrain=void 0;const e=this.terrainMesh?.material;e&&(e.opacity=1,e.polygonOffset=!1)}static ROADS_MAX_RADIUS_M=5e3;buildRoads(e,t,i){const n=this.terrainProviders.roads;if(!n||i>zt.ROADS_MAX_RADIUS_M){this.roadSystem.clear(),this.roadAttribution=void 0;return}const s=this.roadWays;if(s&&s.lat===e&&s.lng===t&&s.radiusM===i){this.drapeRoads(s.ways,e,t,n.contemporary);return}n.getRoads(Z1(e,t,i)).then(a=>{this.terrainOrigin?.lat!==e||this.terrainOrigin?.lng!==t||(this.roadWays={lat:e,lng:t,radiusM:i,ways:a},this.drapeRoads(a,e,t,n.contemporary))}).catch(a=>{console.warn("Roads unavailable, drawing none:",a)})}setStatedRoads(e){e!==this.statedRoads&&(this.statedRoads=e,this.drapeStatedRoads(),this.render())}drapeStatedRoads(){const e=this.terrainMesh;e&&(this.roadSystem.group.position.copy(e.position),this.roadSystem.setStated(this.statedRoads,(t,i)=>this.groundYOfPatch(e,t,i)))}drapeRoads(e,t,i,n){const s=this.terrainMesh;s&&(this.roadSystem.group.position.copy(s.position),this.roadSystem.set(e,t,i,(a,o)=>this.groundYOfPatch(s,a,o),n),this.roadAttribution=e.length>0?this.terrainProviders.roads?.attribution:void 0,this.compileNextFrameOffThread(),this.render())}setShowCompass(e){this.showCompass!==e&&(this.showCompass=e,this.disposeCompassLabels(),e&&this.buildCompassLabels(),this.render())}setCompassPoints(e){this.compassPoints!==e&&(this.compassPoints=e,this.showCompass&&(this.disposeCompassLabels(),this.buildCompassLabels(),this.render()))}compassPoints;applyLensFlareTint(e){if(!this.lensFlare)return;const t=TE*(this.sunArriving[1]/DE);this.lensFlare.uniforms.uColorGain.value.setRGB(t*e[0],t*e[1],t*e[2]),this.applyDazzleStrength()}applyDazzleStrength(){if(!this.lensFlare)return;const[e,t,i]=this.sunArriving,n=Math.max(t,1e-30);this.lensFlare.uniforms.uDazzleColour.value.setRGB(e/n,1,i/n),this.lensFlare.uniforms.uVeilStrength.value=Pi.K*t*this.sunUnhiddenFraction}sunArriving=[0,0,0];setCompassHovered(e){this.compassHovered!==e&&(this.compassHovered=e,this.updateCompassVisibility())}setCompassForced(e){this.compassForced!==e&&(this.compassForced=e,this.updateCompassVisibility())}updateCompassVisibility(){const e=this.compassHovered||this.compassForced;if(this.compassSprites.some(t=>t.visible!==e)){for(const t of this.compassSprites)t.visible=e;this.developingExposure?this.exposureInstantsDone>0&&this.presentExposure():this.render()}}setWeather(e){if(hE(this.weather,e))return;this.cloudTransmissionMemo.clear();const t=this.weather;this.weather=e;const i=!zE(t,e),n=t.precipitationType!==e.precipitationType,s=t.precipitationIntensity!==e.precipitationIntensity||t.precipitationAmount!==e.precipitationAmount;(t.relativeHumidity!==e.relativeHumidity||n||s)&&(this.air=xn.of(e),this.applyAir(),this.scatteredSky?.setConditions({aerosolOpticalDepth:e.relativeHumidity===void 0?void 0:ta.steppedOpticalDepth(e.relativeHumidity)}),this.pumpScatteredSky()),i&&(this.buildClouds(),this.buildCirrus()),n?this.buildPrecipitation():s&&this.updatePrecipitationDensity(),this.lastAstronomy&&(i&&(this.buildIceHalos(this.lastAstronomy.sun,this.lastAstronomy.moon),this.buildLunarDiffraction(this.lastAstronomy.moon)),(i||n||s)&&this.buildRainbow(this.lastAstronomy.sun,this.lastAstronomy.moon)),this.lightningArmed=e.storm&&e.cloudDarkness>=XE,this.syncAnimationLoop(),this.render()}setDecor(e){if(this.decorObjects!==e){this.decorObjects=e,this.decorModelToken++,this.decorModelCredits.clear();for(const t of this.decorGroups.values())t.removeFromParent(),hi.dispose(t);this.decorGroups.clear(),this.streetlightLights.clear();for(const t of e){const i=hi.build(t,t.lit??!1);this.scene.add(i),this.decorGroups.set(t.id,i),t.kind==="streetlight"&&this.addStreetlightLight(t.id,i),this.loadDecorModel(t,this.decorModelToken)}this.celestialLight.castShadow=this.decorGroups.size>0||this.bodySystem.any}}setDecorModelProvider(e){this.decorModelProvider=e;const t=this.decorObjects;this.decorObjects=[],this.setDecor(t)}get currentDecorModelCredits(){return[...this.decorModelCredits.values(),...this.bodySystem.modelCredits]}get bodyGround(){const{x:e,z:t}=this.bodyOrigin,i=this.groundYUnder(e,t);return{heightAt:(n,s)=>this.groundYUnder(e+n,t-s)-i}}setBodies(e,t=0,i=e.map(a=>a.id),n=[],s){const{x:a,z:o}=this.bodyOrigin,c=this.scatteredSky;this.bodySystem.set(e,{originX:a,originZ:o,originGroundY:this.groundYUnder(a,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)},t,c?(h,u)=>c.relativeOfLuminance(h,u):void 0,i),this.bodySystem.setSmoke(n,t),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 e=this.celestialLight.color,t=this.celestialLight.intensity*.5,i=this.skyLight.color,n=this.skyLight.groundColor,s=this.skyLight.intensity,a=(o,c,l)=>(o*t+(c+l)/2*s)/Math.PI;return[a(e.r,i.r,n.r),a(e.g,i.g,n.g),a(e.b,i.b,n.b)]}bodyOutline(e,t){return this.bodySystem.outlineOf(e,t)}documentUrl;modelUrl(e){return e.url?this.documentRelative(e.url):void 0}documentRelative(e){if(e.startsWith("data:"))return e;const t=this.documentUrl??(typeof location>"u"?void 0:location.href);return t?new URL(e,t).href:e}async loadBodyModel(e){const t=e.url?void 0:e.id?await this.decorModelProvider.entry(e.id):void 0,i=this.modelUrl(e)??t?.url,n=e.credit??t?.credit;if(!(!i||!n))return{scene:await Nm(i),credit:n,headingOffsetDeg:e.headingOffsetDeg??t?.headingOffsetDeg}}async loadDecorModel(e,t){const i=e.model;if(!(!i||!hi.usesModel(e)))try{const n=i.url?void 0:i.id?await this.decorModelProvider.entry(i.id):void 0,s=this.modelUrl(i)??n?.url,a=i.credit??n?.credit;if(!s||!a)return;const o=await Nm(s);if(t!==this.decorModelToken)return;const c=this.decorGroups.get(e.id);if(!c)return;cn.reflectOn(o),hi.applyModel(c,e,o,{headingOffsetDeg:i.headingOffsetDeg??n?.headingOffsetDeg,depictedSizeM:n?.sizeM}),this.decorModelCredits.set(e.id,a),this.render()}catch(n){console.warn(`Keeping the built-in shape for decor "${e.id}":`,n)}}updateDecorAnchoring(e,t,i=0){this.decorReferencePose=e,this.decorCurrentPose=t,this.decorTime=i;const n=e?.lat!==void 0&&e.lng!==void 0&&t?.lat!==void 0&&t?.lng!==void 0?ni(e.lat,e.lng,t.lat,t.lng):{x:0,z:0},s=this.decorObjects.find(l=>l.observerSide!==void 0&&bg(l.kind));if(this.terrainMesh&&this.terrainOrigin&&t?.lat!==void 0&&t.lng!==void 0){const l=ni(this.terrainOrigin.lat,this.terrainOrigin.lng,t.lat,t.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)}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 a={x:0,z:0};let o=0;if(s){const l=hi.occupantView(s),h=-(s.headingDeg??0)*qi,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;a.x=-(f+u),a.z=-(p+d),this.camera.position.y=this.groundYUnder(f,p)+l.eyeY,this.camera.rotation.set(this.indoorLookPitchDeg*qi,-(l.headingDeg+this.indoorLookYawDeg)*qi,0,"YXZ")}this.bodyOrigin={x:n.x+a.x,z:n.z+a.z},this.placeShadowFrustum();for(const l of this.decorObjects){const h=this.decorGroups.get(l.id);if(!h)continue;const u=Or(l,i),d=u.eastM+n.x+a.x,f=-u.northM+n.z+a.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 m=Math.hypot(d,f);h.visible=m<=CE}if(u.headingDeg!==void 0&&(h.rotation.y=-u.headingDeg*qi),l.kind==="crop"&&h.visible){const m=this.terrainMesh,g=[m?.geometry.uuid,d-(m?.position.x??0),f-(m?.position.z??0),h.position.y-(m?.position.y??0),u.headingDeg,u.altitudeM].map(_=>typeof _=="number"?_.toFixed(4):_).join(":");h.userData.cropGroundKey!==g&&(hi.fitCropToGround(h,(_,b)=>this.groundYUnder(_,b)+u.altitudeM),h.userData.cropGroundKey=g)}o=Math.max(o,h.position.distanceTo(this.camera.position))}const c=Math.max(Zc*1.2,this.groundRadius*2.5,o*1.2);Math.abs(this.camera.far-c)>1&&(this.camera.far=c,this.camera.updateProjectionMatrix())}groundYUnder(e,t){const i=this.terrainMesh;return i?i.position.y+this.groundYOfPatch(i,e-i.position.x,t-i.position.z):vu}groundYOfPatch(e,t,i){const n=e.geometry.getAttribute("position"),s=Math.round(Math.sqrt(n.count));if(s<2||s*s!==n.count)return vu;const a=n.getX(0),o=n.getX(s-1),c=n.getZ(0),l=n.getZ((s-1)*s),h=Sr((t-a)/(o-a)*(s-1),0,s-1),u=Sr((i-c)/(l-c)*(s-1),0,s-1);if(!Number.isFinite(h)||!Number.isFinite(u))return vu;const d=Math.min(Math.floor(h),s-2),f=Math.min(Math.floor(u),s-2),p=h-d,v=u-f,m=(S,w)=>n.getY(S*s+w),g=m(f,d),_=m(f,d+1),b=m(f+1,d),M=m(f+1,d+1);return p+v<=1?g+(_-g)*p+(b-g)*v:M+(b-M)*(1-p)+(_-M)*(1-v)}groundUnderFootprint(e,t,i,n,s=0){return hi.groundUnderFootprint(e,t,i,n,(a,o)=>this.groundYUnder(a,o),s)}lookYawDeg=0;lookPitchDeg=0;poseCameraY=1.6;setGait(e){this.gaitOffset=e}gaitOffset={eastM:0,northM:0,upM:0,rollDeg:0,pitchDeg:0,yawDeg:0};setLookOffset(e,t){this.lookYawDeg=e,this.lookPitchDeg=t}indoorLookYawDeg=0;indoorLookPitchDeg=0;setIndoorLook(e,t){this.indoorLookYawDeg=e,this.indoorLookPitchDeg=t}medium;setMedium(e,t,i,n){const s=e&&t!==void 0&&t>0&&i!==void 0&&i>0?{kind:e.kind,iso:n??e.iso,autoExposure:e.autoExposure===!0,exposureSeconds:t,fNumber:i}:void 0;JSON.stringify(s)!==JSON.stringify(this.medium)&&(this.medium=s,this.render())}applyMedium(){const e=this.medium,t=Math.max(this.relativeScale,1e-30);if(!e){Hi.uMedium.value=0;return}Hi.uMedium.value=e.kind==="negative"?1:e.kind==="slide"?2:3;const i=e.autoExposure?this.scatteredSky?.sceneAdaptation:void 0;Hi.uMediumExposure.value=i!==void 0&&i>0?1/(t*i):.065*e.exposureSeconds*e.iso/(e.fNumber*e.fNumber*t)}grain;lampBloomRadiusRad(){if(!this.grain)return;const e=this.camera.fov*Math.PI/180,t=this.grain.frameHeightMm/(2*Math.tan(e/2)),i=Math.max(1,this.renderer.getDrawingBufferSize(this.bloomSize).y);return Math.max(this.grain.detailUm*.001/t,e/i)}bloomSize=new xe;updateDecorLitState(e,t=0){const i=this.lampBloomRadiusRad();for(const n of this.decorObjects){const s=this.decorGroups.get(n.id);if(s&&n.lights?.length&&hi.setLights(s,n.lights,e,s.position.distanceTo(this.camera.position),t,this.relativeScale,i),n.kind!=="streetlight"&&n.kind!=="vehicle")continue;const a=this.decorGroups.get(n.id);if(!a)continue;const o=_g(n,e);hi.setLit(a,n.kind,o,this.relativeScale);const c=this.streetlightLights.get(n.id);c&&(c.visible=o)}}addStreetlightLight(e,t){const i=hi.bodyOf(t),n=i.children.find(a=>a.userData.emissive);if(!n)return;const s=new g1(16764006,Gm*this.relativeScale,yE);s.position.copy(n.position).multiply(i.scale),s.castShadow=!0,s.shadow.mapSize.set(512,512),s.shadow.bias=-.002,t.add(s),this.streetlightLights.set(e,s)}setAstronomy(e){(!this.lastAstronomy||Math.abs(this.lastAstronomy.sun.altitudeDeg-e.sun.altitudeDeg)>2)&&(this.surroundings=void 0,this.scatteredSky?.resetSurroundings()),this.lastAstronomy=e,this.scatteredSky?.update(this.scatteredSkyState(e)),this.skyHoldUntilMs===void 0&&(this.skyHoldUntilMs=performance.now()+Vm,this.onFirstFrameHold?.(!0),setTimeout(()=>this.render(),Vm+20)),this.pumpScatteredSky(),this.lastSunPosition=e.sun,this.buildSky(e.sun),this.buildGround();const t=this.magnitudeLimitOf(e);this.buildStars(e.stars,t),this.placeBodies(e,t),this.buildIceHalos(e.sun,e.moon),this.buildRainbow(e.sun,e.moon),this.applySkyColours(e),this.syncAnimationLoop(),this.render()}static relativeSkyOf(e,t){const i=a=>{const o=Fn.luminanceOf(a);if(!(o>0))return[0,0,0];const c=Ae.relativeOfResponse(o)/o;return[a[0]*c,a[1]*c,a[2]*c]},n=i(e.zenith),s=i(e.horizon);return{zenith:n,horizon:s,airlight:s,skyIrradiance:[n[0]*Math.PI,n[1]*Math.PI,n[2]*Math.PI],scale:t}}placeBodies(e,t){this.bodiesScale=this.relativeScale,this.setBodyMesh("sun",e.sun,mo,new se(1,.96,.88),e.sun.magnitude),this.setMoonMesh(e.moon,t),this.buildPlanets(e.planets,t),this.buildComet(e.comet,t),this.buildNovae(e.novae??[],t)}bodiesScale=0;applySkyColours(e){this.skyColoursStale=!1,this.bodiesScale!==this.relativeScale&&(this.placeBodies(e,this.magnitudeLimitOf(e)),this.applyDazzleStrength(),this.buildIceHalos(e.sun,e.moon),this.buildRainbow(e.sun,e.moon));const t=this.scatteredSky?.ambient??zt.relativeSkyOf(Pd(e.sun.altitudeDeg),this.relativeScale),i=t,n=this.lightUnderClouds(e),s=a=>n?[0,1,2].map(o=>a[o]*n.through+n.radiance[o]*(1-n.through)):[a[0],a[1],a[2]];this.baseFogColor=[i.horizon[0],i.horizon[1],i.horizon[2]],this.airlight=s(i.airlight),this.skyMesh&&this.skyGradientMaterial&&(this.skyMesh.material=this.scatteredSky?.ready?this.scatteredSky.material:this.skyGradientMaterial),this.updateCelestialLight(e,t),this.updateCloudLighting(e.sun,this.baseFogColor),st.setEye(this.scatteredSky?.rodShare??0,this.relativeScale),this.updateTwinkle(this.twinkleSeconds);for(const a of this.streetlightLights.values())a.intensity=Gm*this.relativeScale;this.buildSkyGlow(e,i.zenith),this.applyAir(),this.buildLunarDiffraction(e.moon)}reflections;sceneVersion=0;reflectionTimer;buildLunarDiffraction(e){const t=this.scatteredSky?.ready?this.scatteredSky:void 0;if(e.altitudeDeg<-.5||!t){this.lunarDiffraction?.show(void 0),this.lunarDiffractionKey="";return}const i=this.weather.relativeHumidity,n=(i===void 0?Fe.DEFAULT_AEROSOL_OPTICAL_DEPTH:ta.opticalDepth(i))*Fe.aerosolDensity(this.siteElevationM+this.observerElevationM),s=this.cloudTransmission(e),a=-Math.log(Math.max(this.cloudTransmission(e,!0),1e-4)),o=dt.aureoleScale(n,dt.airMass(e.altitudeDeg))*s,c=dt.coronaScale(a),l=dt.illuminanceOf(e.magnitude),h=[e.altitudeDeg.toFixed(1),e.azimuthDeg.toFixed(1),e.magnitude.toFixed(2),o.toExponential(2),c.toExponential(2),Math.log10(Math.max(t.adaptation,1e-12)).toFixed(2)].join(":");if(h===this.lunarDiffractionKey)return;this.lunarDiffractionKey=h,this.lunarDiffraction||(this.lunarDiffraction=new K0,this.celestialGroup.add(this.lunarDiffraction.object));const u=dt.profile(dt.HAZE_COARSE_MODE),d=dt.profile(dt.CLOUD_DROPLETS),f=am(e.altitudeDeg),p=new Float32Array(dt.STEPS*3);let v=0;for(let b=0;b<dt.STEPS;b++){const M=b*3,S=[0,1,2].map(T=>l*f[T]*(o*u[M+T]+c*d[M+T])),w=Fn.shown(S,Fn.luminanceOf(S),(T,x)=>t.relativeOfLuminance(T,x));p.set(w,M),v=Math.max(v,Fn.response(w))}const{x:m,y:g,z:_}=li(e.altitudeDeg,e.azimuthDeg,1);this.lunarDiffraction.show(v>1/200?{x:m,y:g,z:_}:void 0,p)}applyAir(){this.scene.fog instanceof Na||(this.scene.fog=new Na),this.scene.fog.setAir(this.air,this.siteElevationM,this.airlight)}airlight=[0,0,0];transmittanceTo(e,t,i){const n=this.camera.position;return this.air.transmittance(this.siteElevationM+n.y,this.siteElevationM+t,Math.hypot(e-n.x,t-n.y,i-n.z))}setSiteElevation(e){Math.abs(e-this.siteElevationM)<1||(this.siteElevationM=e,this.applyAir(),this.lastAstronomy&&this.scatteredSky?.update(this.scatteredSkyState(this.lastAstronomy)))}scatteredSkyState(e){return{altitudeM:this.siteElevationM+this.observerElevationM+1.6,lightPollution:this.lightPollution,sun:{altitudeDeg:e.sun.altitudeDeg,azimuthDeg:e.sun.azimuthDeg,magnitude:e.sun.magnitude},moon:{altitudeDeg:e.moon.altitudeDeg,azimuthDeg:e.moon.azimuthDeg,magnitude:e.moon.magnitude,phaseAngleDeg:Me.phaseAngleOf(e.moon.phase.illuminatedFraction)}}}pumpScatteredSky(){const e=this.scatteredSky;!e||e.tables.ready||this.scatteredSkyFrameId!==null||this.contextReleased||(this.scatteredSkyFrameId=requestAnimationFrame(()=>{this.scatteredSkyFrameId=null,!this.contextReleased&&(e.advance(this.skyHoldUntilMs?SE:_E),this.pumpScatteredSky())}))}cancelScatteredSkyPump(){this.scatteredSkyFrameId!==null&&(cancelAnimationFrame(this.scatteredSkyFrameId),this.scatteredSkyFrameId=null)}setSatellites(e){if(e.length===0&&!this.satelliteField?.count)return;this.satelliteField||(this.satelliteField=new F5(hu),this.celestialGroup.add(this.satelliteField.object));const t=this.lastAstronomy?this.magnitudeLimitOf(this.lastAstronomy):Ld(-90,this.instrumentMagnitudeGain);this.satelliteField.set(e,t,i=>this.cloudTransmission(i),(i,n)=>this.arrivingIlluminance(i,n,1)),this.render()}pickSatelliteAt(e,t){if(!this.satelliteField?.count)return;this.aimAtScreenPoint(this.raycaster,e,t);const i=Math.cos(Bm*this.camera.fov*Math.PI/180),n=this.satelliteField.nearest(this.raycaster.ray.direction,i);return n&&this.groundHides(e,t)?void 0:n}updateCelestialLight(e,t){const i=this.relativeScale,n=e.sun.altitudeDeg>=jc,s=!n&&e.moon.altitudeDeg>=jc,a=n?e.sun:e.moon,o=[0,0,0],c=Math.max(0,Math.sin(Math.max(a.altitudeDeg,0)*qi)),l=n||s?this.cloudTransmission(a):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 _=dt.illuminanceOf(a.magnitude)*i,b=this.air.transmittanceFromSpace(this.siteElevationM+this.observerElevationM,a.altitudeDeg);for(let T=0;T<3;T++)o[T]=_*b[T]*l,d[T]=_*b[T]*u*c,this.cloudBeam[T]=_*b[T];const{x:M,y:S,z:w}=li(a.altitudeDeg,a.azimuthDeg,1);this.cloudBeamDirection.set(M,S,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 _=this.skyCloudTransmission(),b=t.skyIrradiance,M=[0,1,2].map(w=>b[w]*_+d[w]);this.skyLight.color.setRGB(M[0],M[1],M[2]);const S=We.GROUND_ALBEDO;this.skyLight.groundColor.setRGB(S*(M[0]+o[0]*c),S*(M[1]+o[1]*c),S*(M[2]+o[2]*c))}if(this.skyLight.intensity=1,!n&&!s){this.celestialLight.intensity=0;return}const{x:p,y:v,z:m}=li(a.altitudeDeg,a.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}lightDirection=new R(0,1,0);placeShadowFrustum(){const e=this.lightDirection,t=this.celestialLight.shadow.camera,i=(t.right-t.left)/this.celestialLight.shadow.mapSize.x,n=this.shadowAxisX.crossVectors(this.shadowUp,e);n.lengthSq()<1e-8&&n.set(1,0,0),n.normalize();const s=this.shadowAxisY.crossVectors(e,n).normalize(),a=this.shadowWorld.set(this.bodyOrigin.x,0,this.bodyOrigin.z),o=l=>{const h=a.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(e,this.shadowLightDistanceM)}fitShadowToBodies(){const e=this.bodySystem.reachFrom(this.camera.position),t=Math.min(fE,Math.max(Xs,Math.ceil(e*1.25/20)*20));if(t===this.shadowHalfExtentM)return;this.shadowHalfExtentM=t;const i=this.celestialLight.shadow,n=i.camera;n.left=-t,n.right=t,n.top=t,n.bottom=-t;const s=Math.max(po,t*(po/Xs));this.shadowLightDistanceM=Math.max(an,s+10),n.near=this.shadowLightDistanceM-s,n.far=this.shadowLightDistanceM+s,n.updateProjectionMatrix(),i.bias=-.03/(2*s);const a=t>2*Xs?2048:1024;i.mapSize.x!==a&&(i.mapSize.set(a,a),i.map?.dispose(),i.map=null),this.placeShadowFrustum()}shadowHalfExtentM=Xs;shadowLightDistanceM=an;shadowUp=new R(0,1,0);shadowAxisX=new R;shadowAxisY=new R;shadowWorld=new R;skyCloudTransmission(){let e=this.cloudTransmission({altitudeDeg:90,azimuthDeg:0}),t=1;for(const i of[20,45,70]){const n=i*qi,s=Math.sin(n)*Math.cos(n)*2;for(let a=0;a<360;a+=60)e+=s*this.cloudTransmission({altitudeDeg:i,azimuthDeg:a}),t+=s}return e/t}cloudBeam=[0,0,0];cloudBeamDirection=new R(0,1,0);get relativeScale(){return this.scatteredSky?.relativeScale??1/Ae.semiSaturation(Ae.DAYLIGHT_ANCHOR_CD_M2)}setMeteorShower(e,t,i){this.meteorSystem||(this.meteorSystem=new xi,this.celestialGroup.add(this.meteorSystem.object)),this.meteorSystem.setShower(e,t,i)}get meteorSchedule(){return this.meteorSystem?.schedule??[]}meteorMidpoint(e){return this.meteorSystem?.midpointOf(e)}updateMeteors(e){this.meteorSystem?.update(e)}setInstrument(e){this.projectionKind=e.projection,this.grain=e.detailUm!==void 0&&e.frame?{detailUm:e.detailUm,frameHeightMm:e.frame.heightMm}:void 0;const t=si.starPointsOf(e),i=si.flareArtifactsOf(e);t===this.starPoints&&i===this.lensFlareArtifactIntensity||(this.starPoints=t,this.lensFlareArtifactIntensity=i,this.lensFlare&&(this.lensFlare.uniforms.uStarPoints.value=t,this.lensFlare.uniforms.uFlareIntensity.value=i),this.render())}magnitudeLimitOf(e){const t=Me.starLossMagnitudes(e.sun.altitudeDeg,{phaseAngleDeg:Me.phaseAngleOf(e.moon.phase.illuminatedFraction),altitudeDeg:e.moon.altitudeDeg},this.lightPollution);return Ld(e.sun.altitudeDeg,this.instrumentMagnitudeGain,t)}setLightPollution(e){e!==this.lightPollution&&(this.lightPollution=e,this.lastAstronomy&&this.scatteredSky?.update(this.scatteredSkyState(this.lastAstronomy)))}setInstrumentGain(e,t=!1){this.instrumentMagnitudeGain=Number.isFinite(e)?e:0,this.scatteredSky?.setInstrument(t,this.instrumentMagnitudeGain)}render(){this.restatingExposure||(this.sceneVersion++,this.frameDirty=!0,this.resolution.noteChange(performance.now()),!(this.animationFrameId!==null||this.framesDriven||this.flushFrameId!==null)&&(this.flushFrameId=requestAnimationFrame(()=>{this.flushFrameId=null,this.drawIfDirty()})))}drawIfDirty(){if(!(!this.frameDirty||this.contextReleased)){if(this.skyHoldUntilMs){if(!this.firstFrameReady()&&performance.now()<this.skyHoldUntilMs)return;this.skyHoldUntilMs=null,this.iceHalos?.setUrgent(!1),this.onFirstFrameHold?.(!1)}if(this.skyColoursStale&&this.lastAstronomy&&this.applySkyColours(this.lastAstronomy),this.compileBeforeNextDraw){this.compileBeforeNextDraw=!1;const e=this.compileOffThread().then(()=>{this.compiling===e&&(this.compiling=void 0,this.render())});this.compiling=e;return}if(!this.compiling){this.frameDirty=!1,this.refreshReflections(),this.resolution.beginDrawing();try{this.renderOnce()}finally{this.resolution.endDrawing()}this.developingExposure&&this.startExposure()}}}compileBeforeNextDraw=!1;compiling;static COMPILE_WAIT_MS=1500;compileOffThread(){const e=this.renderer.compile(this.scene,this.camera);if(!this.renderer.extensions.get("KHR_parallel_shader_compile"))return Promise.resolve();const t=this.renderer.properties,i=performance.now()+zt.COMPILE_WAIT_MS;return new Promise(n=>{const s=()=>{if(this.contextReleased)return n();for(const a of e){const o=t.get(a)?.currentProgram;(!o||o.isReady())&&e.delete(a)}e.size===0||performance.now()>i?n():setTimeout(s,10)};s()})}compileNextFrameOffThread(){this.compileBeforeNextDraw=!0}contextReleased=!1;releaseContext(){this.contextReleased||(this.contextReleased=!0,this.stopTwinkle(),this.cancelFlush(),this.cancelExposure(),this.compiling=void 0,this.cancelScatteredSkyPump(),this.renderer.forceContextLoss())}restoreContext(){this.contextReleased&&(this.contextReleased=!1,this.renderer.forceContextRestore(),this.scatteredSky?.invalidate(),this.pumpScatteredSky(),this.compileNextFrameOffThread(),this.syncAnimationLoop(),this.render())}cancelFlush(){this.flushFrameId!==null&&(cancelAnimationFrame(this.flushFrameId),this.flushFrameId=null)}frame(e){if(this.animationsRunning){const t=this.lastFrameTimeMs===void 0?0:e-this.lastFrameTimeMs;this.lastFrameTimeMs=e,this.hasAnimations()&&this.animate(e,t);const i=this.resolution.ratioFor(e,t);i!==this.renderer.getPixelRatio()&&this.applyPixelRatio(i)}this.drawIfDirty()}refreshReflections(){this.reflections??=new cn(this.renderer);const e=[...this.compassSprites,...this.lensFlare?[this.lensFlare.mesh]:[],...[...this.glareSprites.values()].map(s=>s.mesh)],t=[...this.starTiers.map(s=>s.points),...[...this.bodyMeshes.values()].filter(s=>s instanceof xs),...[this.rainSystem?.points,this.precipitationPoints,this.rainSplashSystem?.points].filter(s=>s!==void 0)],i=this.relativeScale,n=this.reflections.refresh(this.renderer,this.scene,this.camera.position,this.bodySystem.reflectors,e,[...this.decorGroups.values()],this.sceneVersion,t,s=>this.measureSurroundings(s,i));n===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()}))},n))}measureSurroundings(e,t){const i=this.lastAstronomy;if(!i)return;this.probeIrradiance??=new Po;const n=[i.sun,i.moon].filter(s=>s.altitudeDeg>-2).map(s=>li(s.altitudeDeg,s.azimuthDeg,1));this.probeIrradiance.measure(this.renderer,e,n,s=>{const a=d=>d.map(f=>f/t),o=this.surroundings,c={up:a(s.up),down:a(s.down)},l=(d,f)=>d.some((p,v)=>Math.abs(p-f[v])>.03*Math.max(Math.abs(p),Math.abs(f[v]),1e-12)),h=!o||l(o.up,c.up)||l(o.down,c.down);h&&(this.surroundings=c);const u=this.scatteredSky?.adaptToSurroundings(Math.exp(s.logAverage)/t)??!1;!h&&!u||(this.skyColoursStale=!0,this.render())})}lightUnderClouds(e){const t=this.surroundings;if(!t)return;const i=e.sun.altitudeDeg>=jc?e.sun:e.moon.altitudeDeg>=jc?e.moon:void 0;if(!i)return;const n=this.relativeScale/Math.PI;return{through:this.cloudTransmission(i),radiance:[t.up[0]*n,t.up[1]*n,t.up[2]*n]}}probeIrradiance;surroundings;animate(e,t){const i=Math.min(t/1e3,WE);this.twinkleSeconds=e/1e3,this.updateTwinkle(this.twinkleSeconds),this.updatePrecipitation(e/1e3,i),this.updateRain(i),this.lensFlare&&(this.lensFlare.uniforms.uTime.value=e/1e3),this.developingExposure||(this.frameDirty=!0)}setMaxPixelRatio(e){this.resolution.maximum=e,this.renderer.getPixelRatio()>this.resolution.maximum&&this.applyPixelRatio(this.resolution.maximum)}applyPixelRatio(e){this.renderer.setPixelRatio(e),this.renderer.setSize(this.cssSize.width,this.cssSize.height,!1),this.frameDirty=!0}setExposure(e,t){const i=t?Math.max(1,Math.round(e)):1;if(i===this.exposureInstants&&(i===1||t===this.exposureInstantAt)){this.exposureInstantAt=t;return}this.exposureInstants=i,this.exposureInstantAt=t,i===1&&(this.cancelExposure(),this.exposureAccumulation?.dispose(),this.exposureAccumulation=void 0),this.render()}renderOnce(e){if(this.onMapSubjectBounds){const a=this.mapSubjectBounds();e?this.exposureSubjectBounds.push(...a):this.onMapSubjectBounds(a)}const t=this.usableEquidistantPass();this.phenomena.setCloudLayers(this.layeredClouds?.volumes??[]),this.phenomena.place(this.camera,(a,o,c)=>this.directionAtScreenPoint(a,o,c),a=>this.screenPointOf(a)),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()),Hi.uRodShare.value=this.scatteredSky?.rodShare??0,Hi.uRelativeScale.value=this.relativeScale,this.applyMedium();const n=this.references.any||this.phenomena.any||this.compassSprites.some(a=>a.visible);Hi.uHasOverlay.value=n?1:0;const s=n?a=>this.renderOverlayPasses(a):void 0;if(this.skyGlow?.setDestinationEncoded(!1),!t){this.updateLensFlarePosition();const a=this.usableDepthOfFieldPass();a?a.render(this.renderer,this.scene,this.camera,s,e):this.usableFinishPass().render(this.renderer,this.scene,this.camera,s,void 0,e);return}t.render(this.renderer,this.scene,this.camera,this.camera.fov,()=>this.updateLensFlarePosition(),s,a=>{this.lensFlare&&(this.lensFlare.mesh.visible=a?!1:this.sunVisible)},()=>this.renderDazzleOnResample(),e)}renderOverlayPasses(e=this.camera){this.renderReferencesPass(e),this.renderPhenomenaPass(e),this.renderHudPass(e)}renderHudPass(e){if(!this.compassSprites.some(n=>n.visible))return;const t=this.renderer.autoClear,i=this.renderer.shadowMap.autoUpdate;this.renderer.autoClear=!1,this.renderer.shadowMap.autoUpdate=!1,e.layers.set(Um),this.renderer.render(this.scene,e),e.layers.set(0),this.renderer.autoClear=t,this.renderer.shadowMap.autoUpdate=i}renderReferencesPass(e){if(!this.references.any)return;const t=this.renderer.autoClear,i=this.renderer.shadowMap.autoUpdate;this.renderer.autoClear=!1,this.renderer.shadowMap.autoUpdate=!1,e.layers.set(ov),this.renderer.render(this.scene,e),e.layers.set(0),this.renderer.autoClear=t,this.renderer.shadowMap.autoUpdate=i}setReferences(e,t){this.references.set(e.map(i=>{const n=this.documentRelative(i.src);return n===i.src?i:{...i,src:n}}),void 0,t)}referenceAspect(e){return this.references.aspectOf(e)}directionAt(e,t){return this.directionAtScreenPoint(e,t,new R)}referenceFailedToLoad(e){return this.references.failedToLoad(this.documentRelative(e))}setReferencesShown(e){this.references.setShown(e),this.render()}setReferenceView(e,t){this.references.setView(e,t),this.render()}renderPhenomenaPass(e){if(!this.phenomena.any)return;const t=this.renderer.autoClear,i=this.renderer.shadowMap.autoUpdate;this.renderer.autoClear=!1,this.renderer.shadowMap.autoUpdate=!1,this.renderer.clearDepth();for(const n of this.decorObjects){const s=this.decorGroups.get(n.id);s&&zt.markDecorDepth(s,n.kind!=="crop")}e.layers.set(cu),this.scene.overrideMaterial=this.decorDepthMaterial,this.renderer.render(this.scene,e),this.scene.overrideMaterial=null,e.layers.set(rv),this.renderer.render(this.scene,e),e.layers.set(0),this.renderer.autoClear=t,this.renderer.shadowMap.autoUpdate=i}decorDepthMaterial=new bn({colorWrite:!1});static markDecorDepth(e,t){e.traverse(i=>{if(!(i instanceof De))return;const n=Array.isArray(i.material)?i.material[0]:i.material;t&&n.depthWrite!==!1&&n.blending!==Ni?i.layers.enable(cu):i.layers.disable(cu)})}startExposure(){this.cancelExposure(),this.exposureSubjectBounds=[];const e=this.renderer.getDrawingBufferSize(new xe),t=Math.max(1,Math.round(e.x)),i=Math.max(1,Math.round(e.y));this.exposureAccumulation||(this.exposureAccumulation=new tw(t,i)),this.exposureAccumulation.resize(t,i),this.exposureAccumulation.open(this.renderer),this.exposureInstantsDone=0,this.exposureFrameId=requestAnimationFrame(()=>this.developExposure())}developExposure(){this.exposureFrameId=null;const e=this.exposureInstantAt,t=this.exposureAccumulation;if(!e||!t)return;const i=1/this.exposureInstants;this.resolution.beginDrawing();const n=performance.now()+zt.EXPOSURE_BUDGET_MS,s=zt.exposureInstantsPerFrame(t.instantTarget.scene.width*t.instantTarget.scene.height);let a=0;do{this.restateAt(e,this.exposureInstantsDone);const o=this.compassSprites.map(c=>c.visible);for(const c of this.compassSprites)c.visible=!1;try{this.renderOnce(t.instantTarget)}finally{this.compassSprites.forEach((c,l)=>{c.visible=o[l]})}t.add(this.renderer,i),this.exposureInstantsDone++,a++}while(this.exposureInstantsDone<this.exposureInstants&&performance.now()<n&&a<s);this.restateAt(e,0),this.presentExposure(),this.resolution.endDrawing(),this.exposureInstantsDone<this.exposureInstants&&(this.exposureFrameId=requestAnimationFrame(()=>this.developExposure()))}presentExposure(){if(Hi.uRodShare.value=this.scatteredSky?.rodShare??0,Hi.uHasOverlay.value=1,Hi.uRelativeScale.value=this.relativeScale,this.applyMedium(),this.exposureAccumulation?.develop(this.renderer,this.exposureInstants/this.exposureInstantsDone),this.onMapSubjectBounds?.(this.exposureSubjectBounds),!this.compassSprites.some(s=>s.visible))return;const e=new Is,t=new zn(-1,1,1,-1,0,2),i=Qc/(Wm*Math.tan(Xm*qi/2));for(const s of this.compassSprites){if(!s.visible)continue;const a=s.getWorldPosition(new R).sub(this.camera.position).normalize(),o=this.screenPointOf(a);if(!o)continue;const c=new to(s.material);c.position.set(o.ndcX,o.ndcY,-1),c.scale.set(i/this.camera.aspect,i,1),e.add(c)}const n=this.renderer.autoClear;this.renderer.autoClear=!1;try{this.renderer.render(e,t)}finally{this.renderer.autoClear=n}}onMapSubjectBounds;exposureSubjectBounds=[];static MAP_SUBJECT_NEAREST_M=8;mapSubjectBounds(){const e=[],t=new Vi,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)),a=this.bodySystem.reflectors.map(o=>o.holder);for(const o of[...s,...a]){if(!o?.visible||(t.setFromObject(o),t.isEmpty())||t.distanceToPoint(this.camera.position)<zt.MAP_SUBJECT_NEAREST_M)continue;let c=1/0,l=-1/0,h=1/0,u=-1/0;for(const d of[t.min.x,t.max.x])for(const f of[t.min.y,t.max.y])for(const p of[t.min.z,t.max.z]){if(i.set(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&&e.push({x:c,y:h,width:l-c,height:u-h})}return e}restateAt(e,t){this.restatingExposure=!0;try{e(t)}finally{this.restatingExposure=!1}}cancelExposure(){this.exposureFrameId!==null&&(cancelAnimationFrame(this.exposureFrameId),this.exposureFrameId=null)}setLensOptics(e){const t=this.lensOptics;this.lensOptics=e,(t===void 0!=(e===void 0)||t&&e&&(t.focalLengthMm!==e.focalLengthMm||t.fNumber!==e.fNumber||t.focusDistance!==e.focusDistance||t.frameHeightMm!==e.frameHeightMm))&&(e&&this.depthOfFieldPass&&this.depthOfFieldPass.setLens(e.focalLengthMm,e.fNumber,e.focusDistance,e.frameHeightMm),this.render())}usableDepthOfFieldPass(){const e=this.lensOptics;if(!e)return;const t=this.renderer.getDrawingBufferSize(new xe),i=Math.max(1,Math.round(t.x)),n=Math.max(1,Math.round(t.y));return this.depthOfFieldPass||(this.depthOfFieldPass=new Lo(i,n)),this.depthOfFieldPass.resize(i,n),this.depthOfFieldPass.setLens(e.focalLengthMm,e.fNumber,e.focusDistance,e.frameHeightMm),this.depthOfFieldPass}usableFinishPass(){const e=this.renderer.getDrawingBufferSize(new xe);return this.finishPass?this.finishPass.resize(e.x,e.y):this.finishPass=new $0(e.x,e.y),this.finishPass}usableEquidistantPass(){if(this.projectionKind!=="equidistant")return;const e=this.renderer.getDrawingBufferSize(new xe);return this.equidistantPass?this.equidistantPass.resize(e.x,e.y):this.equidistantPass=new yi(e.x,e.y),this.equidistantPass}aimAtScreenPoint(e,t,i){const n=this.projectionKind==="equidistant"?this.equidistantPass:void 0;if(!n){e.setFromCamera(new xe(t,i),this.camera);return}const s=n.directionFor(t,i,this.camera.fov);this.camera.updateMatrixWorld(),e.ray.origin.setFromMatrixPosition(this.camera.matrixWorld),e.ray.direction.set(s.x,s.y,s.z).applyQuaternion(this.camera.quaternion).normalize(),e.camera=this.camera}pickCloudAt(e,t){return this.layeredClouds?.pickInstance(this.cloudDirectionAt(e,t))}cloudDirectionAt(e,t){return this.directionAtScreenPoint(e,t,new R)}directionAtScreenPoint(e,t,i){return this.aimAtScreenPoint(this.ufoOcclusionRaycaster,e,t),i.copy(this.ufoOcclusionRaycaster.ray.direction)}screenPointOf(e){this.camera.updateMatrixWorld();const t=this.screenPointScratch.copy(e).applyQuaternion(this.screenPointQuaternion.copy(this.camera.quaternion).invert()),i=this.renderer.getDrawingBufferSize(this.screenPointSize),n=i.x/Math.max(i.y,1);if(this.projectionKind==="equidistant"&&this.equidistantPass)return yi.ndcFor(t,this.camera.fov,n);if(t.z>=0)return;const s=Math.tan(this.camera.fov/2*qi);return{ndcX:t.x/-t.z/(n*s),ndcY:t.y/-t.z/s}}screenPointScratch=new R;screenPointQuaternion=new en;screenPointSize=new xe;updateLensFlarePosition(){const e=this.lensFlare;if(!e)return;if(!this.sunVisible){e.mesh.visible=!1;return}if(this.camera.updateMatrixWorld(),this.lensFlareScratch.copy(this.sunWorldPosition).applyMatrix4(this.camera.matrixWorldInverse),this.lensFlareScratch.z>0){e.mesh.visible=!1;return}const t=this.sunVisibleFraction();if(t<=0){e.mesh.visible=!1;return}e.mesh.visible=!0,this.sunUnhiddenFraction=t,this.applyDazzleStrength();const i=this.lensFlareScratch.copy(this.sunWorldPosition).project(this.camera);e.uniforms.uLensPosition.value.set(i.x,i.y);const n=this.renderer.domElement.width,s=this.renderer.domElement.height;e.uniforms.uResolution.value.set(n,s),e.uniforms.uTanHalfFov.value=Math.tan(this.camera.fov*Math.PI/360)}renderDazzleOnResample(){const e=this.lensFlare;if(!e||!this.sunVisible)return;const t=this.sunVisibleFraction();if(t<=0)return;this.sunUnhiddenFraction=t,this.applyDazzleStrength();const i=this.screenPointOf(this.lensFlareScratch.copy(this.sunWorldPosition).sub(this.camera.position).normalize());if(!i)return;const n=this.renderer.getDrawingBufferSize(this.screenPointSize);e.uniforms.uLensPosition.value.set(i.ndcX,i.ndcY),e.uniforms.uResolution.value.set(n.x,n.y),e.uniforms.uEquidistant.value=1,e.uniforms.uHalfFovRad.value=this.camera.fov*Math.PI/360;const s=this.renderer.autoClear;this.renderer.autoClear=!1,e.mesh.visible=!0,e.mesh.layers.enable(Fm),this.camera.layers.set(Fm),this.renderer.render(this.scene,this.camera),this.camera.layers.set(0),e.mesh.visible=!1,e.uniforms.uEquidistant.value=0,this.renderer.autoClear=s}sunVisibleFraction(){this.raycastableDecor().length>0&&this.scene.updateMatrixWorld();let e=0;for(const t of qm)this.isSunOccluded(t[0],t[1])||e++;return e/qm.length}raycastableDecor(){const e=[];for(const t of this.decorObjects){if(t.kind==="crop")continue;const i=this.decorGroups.get(t.id);i&&e.push(i)}return e}isSunOccluded(e=0,t=0){const i=this.raycastableDecor();if(!this.groundMesh&&!this.terrainMesh&&i.length===0)return!1;const n=this.sunOcclusionDirectionScratch.copy(this.sunWorldPosition).sub(this.camera.position),s=n.length();if(n.normalize(),e!==0||t!==0){const 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,e*o).addScaledVector(l,t*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 a=this.sunOcclusionRaycaster.intersectObjects(i,!0)[0];return a!==void 0&&a.distance<s}groundBlocks(e,t,i,n=0){const s=this.groundMesh;if(s&&t.y<0){const m=(s.position.y-e.y)/t.y;if(m>n&&m<i){const g=e.x+t.x*m-s.position.x,_=e.z+t.z*m-s.position.z;if(Math.hypot(g,_)<=this.groundRadius)return!0}}const a=this.terrainMesh;if(!a)return!1;const o=a.geometry.getAttribute("position"),c=Math.round(Math.sqrt(o.count));if(c<2||c*c!==o.count)return!1;const l=[a.position.x+o.getX(0),a.position.x+o.getX(c-1)],h=[a.position.z+o.getZ(0),a.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,_]of[[e.x,t.x,l],[e.z,t.z,h]]){const b=Math.min(_[0],_[1]),M=Math.max(_[0],_[1]);if(Math.abs(g)<1e-12){if(m<b||m>M)return!1;continue}const S=(b-m)/g,w=(M-m)/g;d=Math.max(d,Math.min(S,w)),f=Math.min(f,Math.max(S,w))}if(!(f>d))return!1;const p=Math.hypot(t.x,t.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,_=e.x+t.x*g,b=e.y+t.y*g,M=e.z+t.z*g;if(b<=this.groundYUnder(_,M))return!0}return!1}setPhenomena(e,t){this.phenomena.set(e,t)}decorDistancesAt(e,t,i){this.aimAtScreenPoint(this.ufoOcclusionRaycaster,e,t),this.ufoOcclusionRaycaster.near=km;let n,s;for(const a of this.decorObjects){if(a.kind==="crop")continue;const o=this.decorGroups.get(a.id);if(!o)continue;const c=this.ufoOcclusionRaycaster.intersectObject(o,!0)[0];c&&(a.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(e,t){this.aimAtScreenPoint(this.raycaster,e,t);const i=[...this.hitAreas.entries()],n=this.raycaster.intersectObjects(i.map(([,s])=>s))[0];if(n&&!this.groundHides(e,t))return i.find(([,s])=>s===n.object)?.[0]}pickStarAt(e,t){if(this.namedStars.length===0)return;this.aimAtScreenPoint(this.raycaster,e,t);const i=this.raycaster.ray.direction,n=Math.cos(Bm*this.camera.fov*Math.PI/180);let s,a=n;for(const o of this.namedStars){const c=o.direction.dot(i);c>a&&(a=c,s={star:o.star,altitudeDeg:o.altitudeDeg})}return s&&this.groundHides(e,t)?void 0:s}groundHides(e,t){if(!this.terrainMesh&&!this.groundMesh)return!1;this.aimAtScreenPoint(this.ufoOcclusionRaycaster,e,t);const i=this.ufoOcclusionRaycaster.ray;return this.groundBlocks(i.origin,i.direction,1/0,km)}bodyScreenBox(e){const t=this.bodySystem.boxOf(e,this.bodyBoxScratch);if(!t)return;let i=1/0,n=1/0,s=-1/0,a=-1/0;for(let o=0;o<8;o++){const c=this.bodyCornerScratch.set(o&1?t.max.x:t.min.x,o&2?t.max.y:t.min.y,o&4?t.max.z:t.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),a=Math.max(a,l.ndcY)}return{minX:i,minY:n,maxX:s,maxY:a}}bodyBoxScratch=new Vi;bodyCornerScratch=new R;pickPlacedBodyAt(e,t){return this.aimAtScreenPoint(this.raycaster,e,t),this.bodySystem.pick(this.raycaster)}pickDecorAt(e,t){this.aimAtScreenPoint(this.raycaster,e,t);const i=[...this.decorGroups.entries()],n=this.raycaster.intersectObjects(i.map(([,a])=>a),!0)[0];if(!n)return;let s=n.object;for(;s&&!i.some(([,a])=>a===s);)s=s.parent;return i.find(([,a])=>a===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.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.lightningBolt?.dispose(),this.lightningBolt=void 0;for(const e of this.bodyMeshes.values())this.disposeMesh(e);this.bodyMeshes.clear(),this.novaKeys.clear();for(const e of[...this.hitAreas.keys()])this.disposeHitArea(e);for(const e of[...this.glareSprites.keys()])this.disposeGlare(e);this.disposeCompassLabels();for(const e of this.decorGroups.values())hi.dispose(e);this.decorGroups.clear(),this.streetlightLights.clear(),this.lensFlare&&(this.lensFlare.mesh.removeFromParent(),this.lensFlare.mesh.geometry.dispose(),this.lensFlare.mesh.material.dispose(),this.lensFlare=void 0),this.renderer.dispose()}animationsRunning=!1;startTwinkle(){if(this.animationFrameId!==null||!this.needsAnimationLoop())return;this.cancelFlush();const e=t=>{this.frame(t),this.animationFrameId=requestAnimationFrame(e)};this.animationFrameId=requestAnimationFrame(e)}setAnimationsRunning(e,t=!1){const i=e&&t;if(e===this.animationsRunning&&i===this.framesDriven)return;const n=this.animationsRunning;this.animationsRunning=e,this.framesDriven=i,e&&!n&&(this.lastFrameTimeMs=void 0,this.resolution.reset());const s=!e&&this.renderer.getPixelRatio()!==this.resolution.maximum;s&&this.applyPixelRatio(this.resolution.maximum),this.syncAnimationLoop(),(!e||this.frameDirty)&&this.render(),s&&this.drawIfDirty()}stopTwinkle(){this.animationFrameId!==null&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null)}needsAnimationLoop(){return this.animationsRunning&&!this.framesDriven&&this.hasAnimations()}hasAnimations(){return this.starTiers.length>0||this.precipitationPoints!==void 0||this.rainSystem!==void 0||this.lensFlare!==void 0&&this.sunVisible}syncAnimationLoop(){this.needsAnimationLoop()?this.startTwinkle():this.stopTwinkle()}buildSky(e){const t=this.skyMesh?.geometry??new ri(Zc,32,16),i=t.attributes.position,n=t.getAttribute("color")??new ut(new Float32Array(i.count*3),3);for(let a=0;a<i.count;a++){const{altitudeDeg:o,azimuthDeg:c}=sw(i.getX(a),i.getY(a),i.getZ(a)),l=dw(o,c,e.azimuthDeg,e.altitudeDeg);n.setXYZ(a,l[0],l[1],l[2])}if(n.needsUpdate=!0,this.skyMesh)return;t.setAttribute("color",n);const s=new bn({vertexColors:!0,side:Ht,fog:!1,depthWrite:!1});this.skyGradientMaterial=s,this.skyMesh=new De(t,s),this.skyMesh.renderOrder=-1,this.celestialGroup.add(this.skyMesh)}buildGround(){const e=zm(this.observerElevationM);if(this.groundMesh&&e===this.groundRadius)return;this.disposeMesh(this.groundMesh),this.groundRadius=e;const t=new T0(this.groundRadius,48),i=new Vr({color:new se(lu,lu,lu),fog:!0});Na.fadeRim(i,this.groundRadius*.75,this.groundRadius),this.groundMesh=new De(t,i),this.groundMesh.rotation.x=-Math.PI/2,this.groundMesh.position.y=0,this.groundMesh.receiveShadow=!0,this.scene.add(this.groundMesh),this.applyGroundDepthWrite()}applyGroundDepthWrite(){const e=this.groundMesh?.material;if(!e)return;const t=this.terrainMesh===void 0;e.depthWrite!==t&&(e.depthWrite=t,e.needsUpdate=!0)}cloudTransmission(e,t=!1){const i=`${e.altitudeDeg.toFixed(1)}:${e.azimuthDeg.toFixed(1)}:${Math.round(this.cloudOffsetM.x/10)}:${Math.round(this.cloudOffsetM.z/10)}:${Math.round(this.observerElevationM)}:`+Object.entries(this.cloudLayerOffsetsM).map(([a,o])=>`${a}=${Math.round(o.x/10)},${Math.round(o.z/10)}`).join(";")+(t?":water":""),n=this.cloudTransmissionMemo.get(i);if(n!==void 0)return n;this.cloudTransmissionMemo.size>256&&this.cloudTransmissionMemo.clear();const s=this.computeCloudTransmission(e,t);return this.cloudTransmissionMemo.set(i,s),s}cloudTransmissionMemo=new Map;computeCloudTransmission(e,t=!1){const i=li(e.altitudeDeg,e.azimuthDeg,1);if(this.layeredClouds)return this.layeredClouds.transmissionAt(i,t);let n=1;const s=this.lowerCloudCover();s>0&&(n*=1-pt.alphaAt(i,Math.abs(this.cloudLayerOffset()),s,this.cloudFieldOffset)*ME);const a=t?0:this.weather.highCloudCover??0;return a>0&&(n*=1-pt.iceAlphaAt(i,Jc,a,this.cloudFieldOffset)*xE),Math.max(0,Math.min(1,n))}setBodyMesh(e,t,i,n,s){if(t.altitudeDeg<i0){this.disposeMesh(this.bodyMeshes.get(e)),this.bodyMeshes.delete(e),this.disposeHitArea(e),this.disposeGlare(e),e==="sun"&&(this.sunVisible=!1);return}const{x:a,y:o,z:c}=li(t.altitudeDeg,t.azimuthDeg,an),l=am(t.altitudeDeg),h=this.cloudTransmission(t),u=this.arrivingIlluminance(t,s,h),d=zt.unitLuminance(n);let f=this.bodyMeshes.get(e);if(e==="sun"){const p=Math.PI*(i/an)**2,v=[0,1,2].map(m=>Math.min(zt.BRIGHTEST_RELATIVE,d[m]*u[m]/p));f instanceof De||(this.disposeMesh(f),f=new De(new ri(1,16,16),new bn({fog:!1})),this.celestialGroup.add(f),this.bodyMeshes.set(e,f)),f.material.color.setRGB(v[0],v[1],v[2]),f.scale.setScalar(i)}else{if(!(f instanceof xs)){this.disposeMesh(f);const m=new ot;m.setAttribute("position",new tt(new Float32Array(3),3)),m.setAttribute("color",new tt(new Float32Array(3),3)),f=new xs(m,st.material(Co[Co.length-1].size,!1)),st.track(f),this.celestialGroup.add(f),this.bodyMeshes.set(e,f)}const p=f.geometry.getAttribute("color"),v=e.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(a,o,c),this.setHitArea(e,a,o,c,i),e==="sun"&&(this.sunArriving=u),e.startsWith("comet:")?this.disposeGlare(e):e!=="sun"&&this.setGlare(e,a,o,c,u,i/an*(180/Math.PI),zt.POINT_VEIL_HOLD_DEG),e==="sun"){this.sunVisible=!0;const p=this.celestialGroup.scale.x;this.sunWorldPosition.set(a*p,o*p+this.celestialGroup.position.y,c*p),this.lensFlare||(this.lensFlare=N5(),this.lensFlare.uniforms.uOpacity.value=RE,this.lensFlare.uniforms.uFlareIntensity.value=this.lensFlareArtifactIntensity,this.lensFlare.uniforms.uStarPoints.value=this.starPoints,this.scene.add(this.lensFlare.mesh)),this.applyLensFlareTint(l)}}setMoonMesh(e,t){const i="moon";if(e.magnitude>t||e.altitudeDeg<i0){this.disposeMesh(this.bodyMeshes.get(i)),this.bodyMeshes.delete(i),this.disposeHitArea(i),this.disposeGlare(i);return}const{x:n,y:s,z:a}=li(e.altitudeDeg,e.azimuthDeg,an),o=this.cloudTransmission(e),c=this.arrivingIlluminance(e,e.magnitude,o),l=Math.max(Sr(e.phase.illuminatedFraction,0,1),.01)*Math.PI*(mo/an)**2,h=new se(...c.map(f=>Math.min(zt.BRIGHTEST_RELATIVE,f/l))),u=`${e.phase.phaseFraction<.5}:${Math.round(Sr(e.phase.illuminatedFraction,0,1)*500)}`;let d=this.bodyMeshes.get(i);if(d instanceof to)d.userData.phaseKey!==u&&(d.material.map?.dispose(),d.material.map=hg(e.phase),d.userData.phaseKey=u),d.material.color.copy(h);else{this.disposeMesh(d),d=new to(new ul({map:hg(e.phase),color:h,fog:!1})),d.userData.phaseKey=u;const f=mo*2;d.scale.set(f,f,1),this.celestialGroup.add(d),this.bodyMeshes.set(i,d)}d.position.set(n,s,a),this.setHitArea(i,n,s,a,mo),this.setGlare(i,n,s,a,c,mo/an*(180/Math.PI))}bentLight(e,t,i=gE){const[n,s,a]=this.arrivingIlluminance(e,t,1),o=Math.max(s,1e-30);return{scale:s/i,tint:[n/o,1,a/o]}}static litBySky(e,t){return zt.litScratch.setRGB(e.r*t[0],e.g*t[1],e.b*t[2])}static litScratch=new se;pointToPixel(){const e=Math.max(1,this.renderer.getDrawingBufferSize(this.pointScratch).y),t=(this.camera.fov*Math.PI/180/e)**2;return Math.min(1,st.CONE_SOLID_ANGLE/t)}pointScratch=new xe;static POINT_VEIL_HOLD_DEG=.25;static BRIGHTEST_RELATIVE=6e4;arrivingIlluminance(e,t,i){const n=this.air.transmittanceFromSpace(this.siteElevationM+this.observerElevationM,e.altitudeDeg),s=dt.illuminanceOf(t)*i*this.relativeScale;return[n[0]*s,n[1]*s,n[2]*s]}static unitLuminance(e){const t=Fn.luminanceOf([e.r,e.g,e.b]);return t>0?[e.r/t,e.g/t,e.b/t]:[1,1,1]}setHitArea(e,t,i,n,s){let a=this.hitAreas.get(e);if(!a){const c=new ul({transparent:!0,opacity:0,depthTest:!1,depthWrite:!1,fog:!1});a=new to(c),this.celestialGroup.add(a),this.hitAreas.set(e,a)}a.position.set(t,i,n);const o=s*mE;a.scale.set(o,o,1)}disposeHitArea(e){const t=this.hitAreas.get(e);t&&(t.removeFromParent(),t.material.dispose(),this.hitAreas.delete(e))}setGlare(e,t,i,n,s,a,o=0){if(Pi.radiusDeg(Pi.K*Math.max(...s))<=Math.max(a,o)){this.disposeGlare(e);return}let c=this.glareSprites.get(e);c||(c=new Pi(`veil:${e}`),this.celestialGroup.add(c.mesh),this.glareSprites.set(e,c)),c.shine({x:t,y:i,z:n},s,a,o)}disposeGlare(e){const t=this.glareSprites.get(e);t&&(t.mesh.removeFromParent(),t.dispose(),this.glareSprites.delete(e))}buildComet(e,t){const i=e&&`comet:${e.id}`;if(!e||!i||e.magnitude>t){this.disposeComet();return}this.cometKey&&this.cometKey!==i&&this.disposeComet();const n=bo(e.magnitude,t),s=Zh(n);this.cometKey=i,this.setBodyMesh(i,e.position,uu*(.5+.5*n),new se(s,s,s),e.magnitude),this.cometTail||(this.cometTail=new on(an),this.celestialGroup.add(this.cometTail.object)),this.cometTail.set(e.position,e.tailEnd,n)}buildIceHalos(e,t){this.iceHalos||(this.iceHalos=new Ci,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:Jc},0);return}const s=this.lowerCloudCover(),a=ft.deckLitUntilDeg(ft.DECK_HEIGHT_M),o=e.altitudeDeg>-a?e:t,c=this.bentLight(o,o===e?Lt.SUN_MAGNITUDE:t.magnitude),l=ft.strength(i,s,o.altitudeDeg,a)*c.scale,{x:h,y:u,z:d}=li(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??Jc},n?.iceCrystalAlignment??this.weather.iceCrystalAlignment??Dv)}buildRainbow(e,t){this.rainbow||(this.rainbow=new Da,this.celestialGroup.add(this.rainbow.object));const i=this.weather.precipitationType==="rain"?this.weather.precipitationIntensity*(this.weather.precipitationAmount??1):0,n=e.altitudeDeg>0,s=n?e:t,a=this.lowerCloudCover(),o=this.bentLight(s,n?Lt.SUN_MAGNITUDE:t.magnitude,vE),c=rn.strength(i,a,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}=li(s.altitudeDeg,s.azimuthDeg,1);this.rainbow.update({x:l,y:h,z:u},c,o.tint,n)}buildSkyGlow(e,t){if(!e.frame){this.skyGlow?.hide();return}this.skyGlow||(this.skyGlow=new $s,this.skyGlow.onReady=()=>this.render(),this.celestialGroup.add(this.skyGlow.object));const{date:i,observer:n}=e.frame,s=In.galactic(i,n),a=zt.directionOf(s.centre),o=zt.directionOf(s.rotation),c=zt.directionOf(s.pole),l=new Ye().set(a.x,a.y,a.z,o.x,o.y,o.z,c.x,c.y,c.z),h=zt.directionOf(In.eclipticPole(i,n)),u=zt.directionOf(e.sun),d=u.clone().addScaledVector(h,-u.dot(h)).normalize();this.skyGlow.update({galactic:l,eclipticPole:h,sunLongitude:d,sunDirection:u,sunAltitudeDeg:e.sun.altitudeDeg,moon:{direction:zt.directionOf(e.moon),altitudeDeg:e.moon.altitudeDeg,phaseAngleDeg:Me.phaseAngleOf(e.moon.phase.illuminatedFraction)},lightPollution:this.lightPollution,skyColor:new R(t[0],t[1],t[2])})}static directionOf(e){const{x:t,y:i,z:n}=li(e.altitudeDeg,e.azimuthDeg,1);return new R(t,i,n).normalize()}buildNovae(e,t){const i=new Set;for(const n of e){if(n.magnitude>t)continue;const s=`nova:${n.id}`;i.add(s);const a=bo(n.magnitude,t),o=Zh(a);this.setBodyMesh(s,n.position,uu*(.5+.5*a),new se(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(e,t){const i=new Set(["sun","moon",...this.cometKey?[this.cometKey]:[],...this.novaKeys]);for(const n of e){if(n.magnitude>t)continue;i.add(n.body);const s=bo(n.magnitude,t),a=Zh(s),o=$E[n.body]??new se(1,1,1),c=new se(o.r*a,o.g*a,o.b*a),l=uu*(.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(e,t){if(this.namedStars=[],!e||e.catalog.count===0){this.disposeStarTiers(),this.syncAnimationLoop();return}const{catalog:i,date:n,observer:s}=e,a=new Ln(n,s),o=bu(1337),c=[],l=this.siteElevationM+this.observerElevationM;for(let h=0;h<i.count;h++){const u=i.mag[h];if(u>t)break;const{altitudeDeg:d,azimuthDeg:f}=a.position(i.ra[h],i.dec[h]);if(d<Hm)continue;const{x:p,y:v,z:m}=li(d,f,hu);c.push({x:p,y:v,z:m,brightness:bo(u,t),illuminance:this.air.transmittanceFromSpace(l,d).map(g=>g*dt.illuminanceOf(u)),phase:o()*Math.PI*2,speedFactor:.7+o()*.6})}for(const h of p5){if(h.mag>t)continue;const{altitudeDeg:u,azimuthDeg:d}=a.position(h.raHours,h.decDeg);if(u<Hm)continue;const{x:f,y:p,z:v}=li(u,d,hu);this.namedStars.push({star:h,direction:new R(f,p,v).normalize(),altitudeDeg:u})}this.starTiers=Co.map((h,u)=>{const d=c.filter(S=>I1(S.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((S,w)=>{f[w*3]=S.x,f[w*3+1]=S.y,f[w*3+2]=S.z,p[w]=S.brightness,v.set(S.illuminance,w*3),m[w]=S.phase,g[w]=S.speedFactor});const _=new ot;_.setAttribute("position",new tt(f,3)),_.setAttribute("seed",new tt(m.map(S=>S/(2*Math.PI)),1));const b=new tt(new Float32Array(d.length*3),3);_.setAttribute("color",b);let M=this.starTiers[u]?.points;return M?(M.geometry.dispose(),M.geometry=_):(M=new xs(_,st.material(h.size)),st.track(M),this.celestialGroup.add(M)),{points:M,colorAttribute:b,brightness:p,illuminance:v,phase:m,speedFactor:g}}),this.starColoursRelative=Number.NaN,this.updateTwinkle(this.twinkleSeconds),this.startTwinkle()}twinkleSeconds=0;starColoursRelative=Number.NaN;updateTwinkle(e){st.setTime(e);const t=this.relativeScale;if(t!==this.starColoursRelative){this.starColoursRelative=t;for(const i of this.starTiers){const n=i.colorAttribute.array;for(let s=0;s<i.brightness.length;s++)n[s*3]=i.illuminance[s*3]*t,n[s*3+1]=i.illuminance[s*3+1]*t,n[s*3+2]=i.illuminance[s*3+2]*t;i.colorAttribute.needsUpdate=!0}}}buildClouds(){if(this.cloudRendering==="volume"||this.weather.cloudLayers!==void 0){this.layeredClouds||(this.disposeCloudSystem(),this.layeredClouds=new Rr(this.celestialGroup,du,this.cloudRendering)),this.disposeCirrus(),this.layeredClouds.hostHalo(this.iceHalos),this.layeredClouds.update(this.weather,this.observerElevationM+1.6),this.layeredClouds.setOffsets(this.cloudOffsetM,this.cloudLayerOffsetsM),this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor);return}const e=this.lowerCloudCover();if(e<=0){this.disposeCloudSystem();return}const t=this.weather.cloudDarkness,i=new se(ga[0]+(mu[0]-ga[0])*t,ga[1]+(mu[1]-ga[1])*t,ga[2]+(mu[2]-ga[2])*t);if(this.cloudMesh&&this.cloudUniforms){this.cloudUniforms.coverage.value=e,this.cloudUniforms.baseColor.value.copy(i),this.syncCloudLayer(),this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor);return}this.disposeCloudSystem();const{material:n,uniforms:s}=Td(i,e,Math.abs(this.cloudLayerOffset()));this.cloudMaterial=n,this.cloudUniforms=s,s.fieldOffset.value.copy(this.cloudFieldOffset),this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor);const a=Rd(du);this.cloudMesh=new De(a,n),this.faceCloudDeck(this.cloudMesh,this.cloudLayerOffset()),this.celestialGroup.add(this.cloudMesh)}lowerCloudCover(){return this.weather.cloudLayers?1-this.weather.cloudLayers.filter(e=>e.type!=="cirrus").reduce((e,t)=>e*(1-t.coverage),1):this.weather.lowerCloudCover??this.weather.cloudCover}highCloudCover(){return this.weather.cloudLayers?1-this.weather.cloudLayers.filter(e=>e.type==="cirrus").reduce((e,t)=>e*(1-t.coverage),1):this.weather.highCloudCover}buildCirrus(){const e=this.weather.highCloudCover??0;if(this.layeredClouds||e<=0){this.disposeCirrus();return}if(this.cirrusMesh&&this.cirrusUniforms){this.cirrusUniforms.coverage.value=e,this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor);return}const{material:t,uniforms:i}=Td(new se(...ga),e,Jc,1);this.cirrusMaterial=t,this.cirrusUniforms=i,i.fieldOffset.value.copy(this.cloudFieldOffset),this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor),this.cirrusMesh=new De(Rd(du*1.04),t),this.cirrusMesh.renderOrder=$m-1,this.celestialGroup.add(this.cirrusMesh)}disposeCirrus(){this.cirrusMesh&&(this.cirrusMesh.removeFromParent(),this.cirrusMesh.geometry.dispose()),this.cirrusMaterial?.dispose(),this.cirrusMesh=void 0,this.cirrusMaterial=void 0,this.cirrusUniforms=void 0}syncCloudLayer(){this.layeredClouds?.update(this.weather,this.observerElevationM+1.6);const e=this.cloudLayerOffset();this.cloudUniforms&&(this.cloudUniforms.layerHeight.value=Math.abs(e)),this.cloudMesh&&this.faceCloudDeck(this.cloudMesh,e)}faceCloudDeck(e,t){const i=t<0;e.scale.y=i?-1:1,e.renderOrder=i?Rr.deckOrder(!0,0,1):$m}cloudLayerOffset(){const t=((this.weather.cloudBaseM??s0)-this.observerElevationM)*fu;return Math.sign(t||1)*Math.max(Math.abs(t),IE)}updateCloudLighting(e,t){const i=[this.cloudUniforms,this.cirrusUniforms].filter(u=>u!==void 0);if(i.length===0&&!this.layeredClouds)return;const n=this.cloudBeamDirection,[s,a,o]=this.cloudBeam.map(u=>u/Math.PI),c=this.lightningLevel*yu*this.relativeScale/Math.PI,l=new se(t[0]+qn.r*c,t[1]+qn.g*c,t[2]+qn.b*c);this.layeredClouds?.setLighting(n.clone(),new se(s,a,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,a*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(e){return kE(e,this.weather.precipitationIntensity,this.weather.precipitationAmount??1)}updatePrecipitationDensity(){const e=[[this.rainSystem?.points,Mu],[this.rainSplashSystem?.points,va],[this.precipitationPoints,this.weather.precipitationType==="none"||this.weather.precipitationType==="rain"?void 0:gu[this.weather.precipitationType].poolSize]];for(const[t,i]of e)t&&i!==void 0&&t.geometry.setDrawRange(0,this.precipitationCount(i));this.rainSystem&&(this.rainSystem.uniforms.uSpeedStreak.value=jm(xu(this.weather.precipitationIntensity)))}buildPrecipitation(){this.disposePrecipitationPoints(),this.disposeRain();const e=this.weather.precipitationType;if(e==="none")return;if(e==="rain"){this.buildRain();return}const t=gu[e],i=t.poolSize,n=bu(9001),s=new Float32Array(i*3),a=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 b=0;b<i;b++){const M=n()*Math.PI*2,S=n()*t.radiusM;s[b*3]=Math.cos(M)*S,s[b*3+1]=vr+n()*(t.topYM-vr),s[b*3+2]=Math.sin(M)*S,a[b]=n()*Math.PI*2,o[b]=.7+n()*.6,c[b]=.6+n()*.8,l[b]=.4+n()*1.2}const v=new ot;v.setAttribute("position",new tt(s,3)),v.setDrawRange(0,this.precipitationCount(i));const m={uSize:{value:t.size},uScale:{value:.5*this.renderer.domElement.height},uOpacity:{value:t.opacity},uColor:{value:t.color.clone()},uHazeColor:{value:new se(...this.baseFogColor)},uTexture:{value:KE(e)},uNearFocusDistance:{value:ig},uHazeDistance:{value:t.radiusM*ng}},g=new ct({uniforms:m,vertexShader:tA,fragmentShader:iA,transparent:!0,depthWrite:!1});this.precipitationUniforms=m;const _=new xs(v,g);_.renderOrder=pu,this.scene.add(_),this.precipitationPoints=_,this.precipitationPositions=s,this.precipitationPhase=a,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(e,t){if(!this.precipitationPoints||!this.precipitationPositions||!this.precipitationPhase||!this.precipitationSpeedJitter)return;this.precipitationUniforms?.uHazeColor.value.setRGB(...this.baseFogColor);const i=this.weather.precipitationType;if(i==="none"||i==="rain")return;const n=gu[i];if(this.precipitationUniforms?.uColor.value.copy(zt.litBySky(n.color,this.baseFogColor)),t<=0)return;const s=this.weather.windDirectionDeg*qi,a=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,_=i==="snow"&&u&&d,b=i==="hail"&&f&&p&&v&&m&&g;for(let M=0,S=0;M<c.length;M+=3,S++){if(b&&f[S]>0){if(f[S]-=t,f[S]<=0){const x=Math.random()*Math.PI*2,A=Math.sqrt(Math.random())*n.radiusM;c[M]=Math.cos(x)*A,c[M+1]=n.topYM,c[M+2]=Math.sin(x)*A,f[S]=0}else{const x=1-f[S]/v[S];c[M+1]=vr+Math.sin(Math.PI*x)*p[S],c[M]=el(c[M]+(a+m[S])*t,n.radiusM),c[M+2]=el(c[M+2]+(o+g[S])*t,n.radiusM)}continue}let w=0,T=0;if(_){const x=BE*u[S],A=HE*d[S];w=Math.sin(e*x*Math.PI*2+l[S])*A,T=Math.sin(e*x*Math.PI*2+l[S]+Math.PI/2)*A}if(c[M]+=(a+w)*t,c[M+1]-=n.fallSpeedMPerS*h[S]*t,c[M+2]+=(o+T)*t,c[M]=el(c[M],n.radiusM),c[M+2]=el(c[M+2],n.radiusM),c[M+1]<vr){if(b){p[S]=cg*(.2+Math.random()*1.6),v[S]=GE*(.5+Math.random()),f[S]=v[S];const C=Math.random()*Math.PI*2,I=VE*(p[S]/cg);m[S]=Math.cos(C)*I,g[S]=Math.sin(C)*I,c[M+1]=vr;continue}const x=Math.random()*Math.PI*2,A=Math.sqrt(Math.random())*n.radiusM;c[M]=Math.cos(x)*A,c[M+1]=n.topYM,c[M+2]=Math.sin(x)*A}}this.precipitationPoints.geometry.attributes.position.needsUpdate=!0}buildRain(){const e=xu(this.weather.precipitationIntensity);this.rainSystem=C5({count:Mu,radiusM:go,heightM:PE,bottomYM:Km,overallSpeed:LE,color:Jm.clone(),opacity:.85,visibleCount:this.precipitationCount(Mu),speedStreak:jm(e),pixelSize:ag,seed:9001,nearFocusDistanceM:ig,hazeDistanceM:go*ng,hazeColor:new se(...this.baseFogColor)}),this.rainLastVerticalFacing=-1,this.syncRainSlant(),this.rainSystem.points.renderOrder=pu,this.scene.add(this.rainSystem.points),this.buildRainSplashes()}buildRainSplashes(){const e=bu(4242),t=new Float32Array(va*3),i=new Float32Array(va),n=new Float32Array(va),s=new Float32Array(va);for(let h=0;h<va;h++){const u=e()*Math.PI*2,d=Math.sqrt(e())*go;t[h*3]=Math.cos(u)*d,t[h*3+1]=Km,t[h*3+2]=Math.sin(u)*d,n[h]=lg(Qm,eg),i[h]=e()*n[h],s[h]=i[h]/n[h]}const a=new ot;a.setAttribute("position",new tt(t,3));const o=new tt(s,1);a.setAttribute("aLife",o),a.setDrawRange(0,this.precipitationCount(va));const c=new ct({uniforms:{uMaxSize:{value:UE},uScale:{value:.5*this.renderer.domElement.height},uColor:{value:tg.clone()},uTexture:{value:jE()}},vertexShader:QE,fragmentShader:eA,transparent:!0,depthWrite:!1}),l=new xs(a,c);l.renderOrder=pu,this.scene.add(l),this.rainSplashSystem={points:l,positions:t,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 e=this.rainSystem;if(!e)return;const t=this.weather.windDirectionDeg*qi;e.uniforms.uDropVelocity.value.set(Math.sin(t)*this.weather.windSpeed,-xu(this.weather.precipitationIntensity),-Math.cos(t)*this.weather.windSpeed);const i=this.renderer.getSize(this.rainViewportSize);e.uniforms.uAspect.value=i.x/Math.max(i.y,1)}updateRain(e){const t=this.rainSystem;if(!t)return;t.uniforms.uTime.value+=e,t.uniforms.uHazeColor.value.setRGB(...this.baseFogColor),t.uniforms.uColor.value.copy(zt.litBySky(Jm,this.baseFogColor));const i=this.rainSplashSystem?.points.material?.uniforms?.uColor;i&&i.value.copy(zt.litBySky(tg,this.baseFogColor));const n=this.weather.windDirectionDeg*qi,s=Math.sin(n)*this.weather.windSpeed,a=-Math.cos(n)*this.weather.windSpeed,o=go,c=h=>(h%(o*2)+o*3)%(o*2)-o;t.uniforms.uWindOffset.value.set(c(t.uniforms.uWindOffset.value.x+s*e),c(t.uniforms.uWindOffset.value.y+a*e)),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=rg+(1-rg)*(1-l),u=og+(1-og)*(1-l);t.uniforms.uUvSquash.value=u,t.uniforms.uPixelSize.value=ag*h*(.5+.5*u)}this.updateRainSplashes(e)}updateRainSplashes(e){const t=this.rainSplashSystem;if(!t||e<=0)return;const{positions:i,life:n,duration:s,lifeAttribute:a}=t,o=a.array;for(let c=0,l=0;c<i.length;c+=3,l++){if(n[l]+=e,n[l]>=s[l]){const h=Math.random()*Math.PI*2,u=Math.sqrt(Math.random())*go;i[c]=Math.cos(h)*u,i[c+2]=Math.sin(h)*u,s[l]=lg(Qm,eg),n[l]=0}o[l]=n[l]/s[l]}t.points.geometry.attributes.position.needsUpdate=!0,a.needsUpdate=!0}setLightning(e){this.lightningFlashes=e}updateLightning(e){let t,i=0;if(this.lightningArmed)for(const c of this.lightningFlashes){if(c.t>e)break;const l=di.brightnessAt(c,e);l>i&&(t=c,i=l)}const n=t?Math.min(1,Math.max(.1,(YE/t.distanceM)**2)):0,s=i*n*(t?.cloudToGround?1:.6);if(s===this.lightningLevel&&!t?.cloudToGround)return;if(this.lightningLevel=s,this.scene.fog){const c=this.scene.fog,l=s*yu*this.relativeScale/Math.PI;c.color.setRGB(this.airlight[0]+qn.r*l,this.airlight[1]+qn.g*l,this.airlight[2]+qn.b*l)}const a=this.skyMesh?.material?.color;if(a){const c=s*qE;a.setRGB(1+c*qn.r,1+c*qn.g,1+c*qn.b)}if(this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor),this.lightningLight.intensity=s*yu*this.relativeScale,t){const{x:c,y:l,z:h}=li(25,t.azimuthDeg,an);this.lightningLight.position.set(c,l,h)}this.lightningBolt||(this.lightningBolt=new Ks(an*.95),this.celestialGroup.add(this.lightningBolt.object));const o=this.weather.cloudBaseM??1500;this.lightningBolt.set(t,i,o),this.render()}buildCompassLabels(){this.compassSprites=bE.map(e=>{const t=La.point(e,this.compassPoints),i=new ul({map:nA(t),depthTest:!1,fog:!1}),n=new to(i),{x:s,y:a,z:o}=li(0,e,Wm);return n.position.set(s,a,o),n.scale.set(Qc,Qc,1),n.renderOrder=wE,n.layers.set(Um),n.visible=this.compassHovered||this.compassForced,this.celestialGroup.add(n),n}),this.updateCompassScale()}updateCompassScale(){const e=this.camera.fov*Math.PI/360,t=Xm*Math.PI/360,i=Qc*Math.tan(e)/Math.tan(t);for(const n of this.compassSprites)n.scale.set(i,i,1)}disposeCompassLabels(){for(const e of this.compassSprites)e.removeFromParent(),e.material.map?.dispose(),e.material.dispose();this.compassSprites=[]}disposeStarTiers(){for(const e of this.starTiers)this.disposeMesh(e.points);this.starTiers=[]}disposeMesh(e){if(!e)return;e.removeFromParent(),"geometry"in e&&e.geometry.dispose();const t=e.material;for(const i of Array.isArray(t)?t:[t]){const n=i.map;n&&n.dispose(),i.dispose()}}}const qi=Math.PI/180;function Sr(r,e,t){return Math.max(e,Math.min(t,r))}function lg(r,e){return r+Math.random()*(e-r)}function el(r,e){return(r%(e*2)+e*3)%(e*2)-e}let tl,il;function KE(r){switch(r){case"snow":return ZE();case"hail":return JE()}}function ZE(){if(tl)return tl;const r=64,e=document.createElement("canvas");e.width=r,e.height=r;const t=e.getContext("2d"),i=t.createRadialGradient(r/2,r/2,0,r/2,r/2,r/2);return i.addColorStop(0,"rgba(255,255,255,0.95)"),i.addColorStop(.5,"rgba(255,255,255,0.55)"),i.addColorStop(1,"rgba(255,255,255,0)"),t.fillStyle=i,t.fillRect(0,0,r,r),tl=new Ls(e),tl}function JE(){if(il)return il;const r=64,e=document.createElement("canvas");e.width=r,e.height=r;const t=e.getContext("2d"),i=t.createRadialGradient(r/2,r/2,0,r/2,r/2,r/2);return i.addColorStop(0,"rgba(255,255,255,1)"),i.addColorStop(.55,"rgba(255,255,255,0.95)"),i.addColorStop(.8,"rgba(255,255,255,0.4)"),i.addColorStop(1,"rgba(255,255,255,0)"),t.fillStyle=i,t.fillRect(0,0,r,r),il=new Ls(e),il}let nl;function jE(){if(nl)return nl;const r=64,e=document.createElement("canvas");e.width=r,e.height=r;const t=e.getContext("2d"),i=t.createRadialGradient(r/2,r/2,0,r/2,r/2,r/2);return i.addColorStop(0,"rgba(255,255,255,0)"),i.addColorStop(.4,"rgba(255,255,255,0)"),i.addColorStop(.6,"rgba(255,255,255,0.9)"),i.addColorStop(.8,"rgba(255,255,255,0.25)"),i.addColorStop(1,"rgba(255,255,255,0)"),t.fillStyle=i,t.fillRect(0,0,r,r),nl=new Ls(e),nl}const QE=`
|
|
7714
|
+
`,transparent:!0,blending:Ni,depthWrite:!1,side:Ht,fog:!1});this.object=new De(new ri(K0.RADIUS,128,32,0,Math.PI*2,0,dt.MAX_ANGLE_RAD),t),this.object.renderOrder=-1,this.object.frustumCulled=!1,this.object.visible=!1}show(e,t){if(!e||!t){this.object.visible=!1;return}this.towards.set(e.x,e.y,e.z).normalize(),this.object.quaternion.setFromUnitVectors(this.up,this.towards),this.object.material.uniforms.uSource.value.copy(this.towards);for(let i=0;i<dt.STEPS;i++){for(let n=0;n<3;n++)this.texels[i*4+n]=kn.toHalfFloat(Math.min(t[i*3+n],6e4));this.texels[i*4+3]=kn.toHalfFloat(1)}this.texture.needsUpdate=!0,this.object.visible=!0}dispose(){this.object.geometry.dispose(),this.object.material.dispose(),this.texture.dispose()}}class Bl{constructor(e){this.generator=e}static SIZE=128;target=new qo(Bl.SIZE,{type:Wt,generateMipmaps:!1,minFilter:rt,magFilter:rt});camera=new P0(.1,2e5,this.target);filteredTarget;capturedAtMs=-1/0;capturedVersion;get sharp(){return this.target.texture}get filtered(){return this.filteredTarget?.texture}capture(e,t,i,n=[]){const s=e.shadowMap.autoUpdate;e.shadowMap.autoUpdate=!1;const a=n.map(o=>o.visible);for(const o of n)o.visible=!1;this.camera.position.copy(i),this.camera.update(e,t),n.forEach((o,c)=>{o.visible=a[c]}),e.shadowMap.autoUpdate=s,this.filteredTarget=this.generator.fromCubemap(this.target.texture,this.filteredTarget),this.capturedAtMs=performance.now()}dispose(){this.target.dispose(),this.filteredTarget?.dispose()}}class cn{static REFRESH_MS=250;generator;eye;probes=new Map;constructor(e){cn.install(),this.generator=new Sd(e),this.eye=new Bl(this.generator)}static decor;refresh(e,t,i,n,s,a,o,c=[],l){for(const v of[...this.probes.keys()])n.some(m=>m.id===v&&m.shiny)||(this.probes.get(v).dispose(),this.probes.delete(v));const h=[{probe:this.eye}];for(const v of n){if(!v.shiny)continue;let m=this.probes.get(v.id);m||(m=new Bl(this.generator),this.probes.set(v.id,m)),h.push({probe:m,reflector:v})}const u=performance.now(),d=()=>h.filter(({probe:v})=>v.capturedVersion!==o),f=d().filter(({probe:v})=>u-v.capturedAtMs>=cn.REFRESH_MS);if(f.length>0){const v=f.reduce((m,g)=>g.probe.capturedAtMs<m.probe.capturedAtMs?g:m);if(v.reflector){const m=v.reflector.holder.getWorldPosition(this.scratch);v.probe.capture(e,t,m,[v.reflector.holder,...s]),cn.reflectOn(v.reflector.holder,v.probe)}else{v.probe.capture(e,t,i,[...s,...c]),l?.(v.probe.sharp),cn.decor=v.probe.filtered;for(const m of a)cn.reflectOn(m,v.probe);for(const m of n)m.shiny||cn.reflectOn(m.holder,v.probe)}v.probe.capturedVersion=o}const p=d();if(p.length!==0)return Math.max(16,Math.min(...p.map(({probe:v})=>cn.REFRESH_MS-(u-v.capturedAtMs))))}scratch=new R;static reflectOn(e,t={filtered:cn.decor}){e.traverse(i=>{const n=i.material;for(const s of Array.isArray(n)?n:n?[n]:[])s instanceof Ko?t.sharp&&s.setSurroundings(t.sharp):s instanceof _a&&t.filtered&&s.envMap!==t.filtered&&(s.envMap=t.filtered,s.needsUpdate=!0)})}dispose(){this.eye.dispose();for(const e of this.probes.values())e.dispose();this.generator.dispose()}static installed=!1;static install(){if(cn.installed)return;cn.installed=!0;const e="iblIrradiance += getIBLIrradiance( geometryNormal );";if(!Xe.lights_fragment_maps.includes(e)){console.warn("Reflections: three's lights_fragment_maps changed; the environment will light diffusely too");return}Xe.lights_fragment_maps=Xe.lights_fragment_maps.replace(e,"// The sky's diffuse light is the hemisphere light's (see Reflections).")}}function hE(r,e){return JSON.stringify(r.cloudLayers)===JSON.stringify(e.cloudLayers)&&r.cloudCover===e.cloudCover&&r.cloudDarkness===e.cloudDarkness&&r.cloudBaseM===e.cloudBaseM&&r.highCloudCover===e.highCloudCover&&r.iceCrystalAlignment===e.iceCrystalAlignment&&r.lowerCloudCover===e.lowerCloudCover&&r.relativeHumidity===e.relativeHumidity&&r.precipitationType===e.precipitationType&&r.precipitationIntensity===e.precipitationIntensity&&r.precipitationAmount===e.precipitationAmount&&r.windDirectionDeg===e.windDirectionDeg&&r.windSpeed===e.windSpeed&&r.storm===e.storm}const Zc=900,cu=1,Fm=4,Um=5,km=.5,Eo=900,uE=6371e3,dE=3e4;function zm(r){const e=Math.sqrt(2*uE*Math.max(r,0));return Math.max(Eo,Math.min(e,dE))}const lu=.5,hu=850,Bm=.03,an=850,po=300,Xs=120,fE=700,pE=.04,mo=4,uu=1.5,Hm=-1,mE=6,i0=-4,gE=2,vE=20,Jc=2600,ME=.97,xE=.38,jc=i0,Gm=1500,yE=400,bE=[0,45,90,135,180,225,270,315],_E=2,SE=16,Vm=2500,Wm=880,Qc=40,Xm=60,wE=10,EE=1,AE=150,TE=55,RE=.5,DE=17,Ym=.265,qm=[[0,0],...Array.from({length:8},(r,e)=>{const t=e*Math.PI/4;return[Math.cos(t)*Ym,Math.sin(t)*Ym]})],du=700,fu=250/s0,IE=12,$m=5,pu=6,ga=[.92,.92,.95],mu=[.15,.15,.19],gu={snow:{fallSpeedMPerS:2,size:.3,color:new se(1,1,1),driftSensitivity:1,radiusM:25,topYM:20,opacity:.75,poolSize:2400},hail:{fallSpeedMPerS:14,size:.5,color:new se(.95,.98,1),driftSensitivity:.25,radiusM:25,topYM:10,opacity:.95,poolSize:1200}},vr=0,vu=0,CE=150,Mu=3e3,go=20,PE=15,Km=vr,LE=40,Zm=1,OE=9;function xu(r){return Zm+(OE-Zm)*r}const Jm=new se(.75,.82,.92),NE=10,FE=.5;function jm(r){return Sr(r/NE,FE,1)}const va=200,Qm=.18,eg=.32,UE=.35,tg=new se(.85,.9,.98),ig=5,ng=.85,sg=.01;function kE(r,e,t=1){return Math.round(r*(sg+(1-sg)*e)*t)}function zE(r,e){return JSON.stringify(r.cloudLayers)===JSON.stringify(e.cloudLayers)&&r.cloudCover===e.cloudCover&&r.cloudDarkness===e.cloudDarkness&&r.cloudBaseM===e.cloudBaseM&&r.highCloudCover===e.highCloudCover&&r.iceCrystalAlignment===e.iceCrystalAlignment&&r.lowerCloudCover===e.lowerCloudCover}const ag=230,rg=.7,og=.05,BE=.6,HE=.7,GE=.15,cg=.35,VE=3,WE=1/12,XE=.5,qn=new se(.82,.86,1),YE=2500,qE=1.6,yu=15,$E={Venus:new se(1,.96,.85),Mars:new se(1,.55,.4),Jupiter:new se(.95,.87,.72),Saturn:new se(.92,.86,.68)};class zt{renderer;scene=new Is;phenomena=new Cn(this.scene);references=new Rn(this.scene,()=>this.render());camera;celestialGroup=new Dt;skyMesh;skyGradientMaterial;scatteredSky;lastAstronomy;skyColoursStale=!1;scatteredSkyFrameId=null;skyHoldUntilMs=void 0;onFirstFrameHold;firstFrameReady(){return(!this.scatteredSky||this.scatteredSky.ambient!==void 0)&&!this.iceHalos?.awaitingFirstDisplay}groundMesh;terrainMesh;terrainProviders;terrainOrigin;terrainBuildToken=0;terrainAttribution;roadSystem=new vn;roadAttribution;roadWays;statedRoads=[];decorModelProvider=oE[0].create();decorModelToken=0;decorModelCredits=new Map;bodySystem=new ht(e=>this.loadBodyModel(e),()=>this.render(),()=>this.relativeScale);bodyOrigin={x:0,z:0};starTiers=[];bodyMeshes=new Map;hitAreas=new Map;glareSprites=new Map;decorObjects=[];decorGroups=new Map;decorReferencePose;decorCurrentPose;decorTime=0;celestialLight=new Dp(16777215,0);celestialLightTarget=new Ut;skyLight=new Ox(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 dl;weather=a0;observerElevationM=0;siteElevationM=0;air=new xn;groundRadius=Eo;terrainRadius=Eo;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 xe;lightningArmed=!1;lightningFlashes=[];lightningLevel=0;lightningBolt;lightningLight=new Dp(16777215,0);baseFogColor=[0,0,0];lastSunPosition;lensFlare;sunUnhiddenFraction=1;lensFlareArtifactIntensity=0;sunWorldPosition=new R;sunVisible=!1;lensFlareScratch=new R;sunOcclusionRaycaster=new dl;sunOcclusionDirectionScratch=new R;sunOcclusionRightScratch=new R;sunOcclusionUpScratch=new R;ufoOcclusionRaycaster=new dl;projectionKind="rectilinear";starPoints=0;namedStars=[];equidistantPass;depthOfFieldPass;finishPass;exposureAccumulation;exposureInstants=1;get developingExposure(){return this.exposureInstants>1&&this.exposureInstantAt!==void 0}static EXPOSURE_BUDGET_MS=12;static exposureInstantsPerFrame(e){return Math.max(3,Math.round(6e6/Math.max(1,e)))}exposureFrameId=null;exposureInstantsDone=0;exposureInstantAt;restatingExposure=!1;lensOptics;instrumentMagnitudeGain=0;lightPollution;meteorSystem;cometTail;satelliteField;iceHalos;lunarDiffraction;lunarDiffractionKey="";rainbow;skyGlow;cometKey;novaKeys=new Set;constructor(e,t=O2()){this.renderer=new qS({canvas:e,antialias:!0}),this.resolution=new mt(Math.min(window.devicePixelRatio||1,2),this.renderer.getContext()),this.renderer.setPixelRatio(this.resolution.pixelRatio),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=To,this.camera=new Ji(60,e.width/Math.max(e.height,1),.1,Zc*1.2),this.camera.position.set(0,1.6,0),this.terrainProviders=t,this.celestialLight.shadow.mapSize.set(1024,1024),this.celestialLight.shadow.camera.left=-Xs,this.celestialLight.shadow.camera.right=Xs,this.celestialLight.shadow.camera.top=Xs,this.celestialLight.shadow.camera.bottom=-Xs,this.celestialLight.shadow.camera.near=an-po,this.celestialLight.shadow.camera.far=an+po,this.celestialLight.shadow.bias=-.03/(2*po),this.celestialLight.shadow.normalBias=pE,this.celestialLight.target=this.celestialLightTarget,this.lightningLight.color.copy(qn),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 Lt(this.renderer,()=>{this.skyColoursStale=!0,this.render()});i.supported?this.scatteredSky=i:i.dispose()}get currentTerrainAttribution(){return this.terrainAttribution}get currentRoadAttribution(){return this.roadAttribution}resize(e,t){this.cssSize.width=e,this.cssSize.height=t,this.renderer.setSize(e,t,!1),this.camera.aspect=e/Math.max(t,1),this.camera.updateProjectionMatrix(),this.render()}setCloudRendering(e){e!==this.cloudRendering&&(this.cloudTransmissionMemo.clear(),this.cloudRendering=e,this.layeredClouds?.dispose(),this.layeredClouds=void 0,this.buildClouds(),this.buildCirrus(),this.render())}setCloudOffset(e,t={}){this.cloudOffsetM.set(e.x,0,e.z),this.cloudLayerOffsetsM=t,this.layeredClouds?.setOffsets(e,t),this.cloudFieldOffset.set(e.x*fu,0,e.z*fu);for(const i of[this.cloudUniforms,this.cirrusUniforms])i?.fieldOffset.value.copy(this.cloudFieldOffset);this.iceHalos?.setCloudOffset(this.layeredClouds?.cirrusMask?.offset??this.cloudFieldOffset)}setObserverPose(e){const t=((e.rollDeg??0)+this.gaitOffset.rollDeg)*$i,i=(e.pitchDeg+this.lookPitchDeg+this.gaitOffset.pitchDeg)*$i;if(e.headingDeg!==void 0?this.camera.rotation.set(i,-(e.headingDeg+this.lookYawDeg+this.gaitOffset.yawDeg)*$i,t,"YXZ"):this.camera.rotation.set(i,this.camera.rotation.y,t,"YXZ"),e.elevationM!==this.observerElevationM&&(this.observerElevationM=e.elevationM,this.syncCloudLayer(),Math.abs(zm(e.elevationM)-this.groundRadius)>1&&(this.buildGround(),this.celestialGroup.scale.setScalar(this.groundRadius/Eo),this.camera.far=Math.max(Zc*1.2,this.groundRadius*2.5),this.camera.updateProjectionMatrix())),this.terrainMesh&&this.terrainOrigin&&e.lat!==void 0&&e.lng!==void 0){const n=ni(this.terrainOrigin.lat,this.terrainOrigin.lng,e.lat,e.lng);this.terrainMesh.position.x=n.x,this.terrainMesh.position.z=n.z}this.poseCameraY=this.groundYUnder(0,0)+1.6+e.elevationM,this.camera.position.y=this.poseCameraY,this.celestialGroup.position.y=this.camera.position.y,this.camera.fov!==e.fovDeg&&(this.camera.fov=e.fovDeg,this.camera.updateProjectionMatrix(),this.updateCompassScale())}setTerrainProviders(e){this.stopTerrainFade(),this.terrainProviders=e,this.disposeMesh(this.terrainMesh),this.terrainMesh=void 0,this.terrainOrigin=void 0,this.terrainAttribution=void 0,this.roadSystem.clear(),this.roadAttribution=void 0,this.roadWays=void 0,this.applyGroundDepthWrite(),this.terrainBuildToken++}setTerrainOrigin(e,t,i){if(e===void 0||t===void 0)return;const n=this.groundRadius;if(this.terrainOrigin&&Math.abs(this.terrainRadius-n)<n*.1){const{x:c,z:l}=ni(e,t,this.terrainOrigin.lat,this.terrainOrigin.lng);if(Math.sqrt(c*c+l*l)<AE*(n/Eo))return}const s=this.terrainOrigin,a=this.terrainRadius;(!s||s.lat!==e||s.lng!==t)&&(this.roadSystem.clear(),this.roadAttribution=void 0),this.terrainOrigin={lat:e,lng:t},this.terrainRadius=n;const o=++this.terrainBuildToken;x5(e,t,this.terrainProviders,n).then(({mesh:c,attribution:l,originElevationM:h})=>{if(o!==this.terrainBuildToken)return;this.setSiteElevation(h??0);const u=this.terrainMesh,d=s?ni(e,t,s.lat,s.lng):void 0;u&&d&&Math.hypot(d.x,d.z)<=a&&(c.position.y=u.position.y+this.groundYOfPatch(u,d.x,d.z)),u&&d&&Math.hypot(d.x,d.z)<=a?this.crossfadeTerrain(c,u):this.disposeMesh(this.terrainMesh),c.renderOrder=EE,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(e,t,n),this.drapeStatedRoads(),this.render(),i?.()}).catch(c=>{console.warn("Terrain build failed, keeping the flat ground fallback:",c),i?.()})}static TERRAIN_CROSSFADE_MS=1200;fadingTerrain;crossfadeTerrain(e,t){this.stopTerrainFade();const i=e.material;i.opacity=0,i.polygonOffset=!0,i.polygonOffsetFactor=-1,i.polygonOffsetUnits=-4;const n=performance.now(),s=()=>{const a=Math.min(1,(performance.now()-n)/zt.TERRAIN_CROSSFADE_MS);if(i.opacity=a*a*(3-2*a),this.render(),a<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:t,frameId:requestAnimationFrame(s)}}stopTerrainFade(){if(!this.fadingTerrain)return;cancelAnimationFrame(this.fadingTerrain.frameId),this.disposeMesh(this.fadingTerrain.mesh),this.fadingTerrain=void 0;const e=this.terrainMesh?.material;e&&(e.opacity=1,e.polygonOffset=!1)}static ROADS_MAX_RADIUS_M=5e3;buildRoads(e,t,i){const n=this.terrainProviders.roads;if(!n||i>zt.ROADS_MAX_RADIUS_M){this.roadSystem.clear(),this.roadAttribution=void 0;return}const s=this.roadWays;if(s&&s.lat===e&&s.lng===t&&s.radiusM===i){this.drapeRoads(s.ways,e,t,n.contemporary);return}n.getRoads(Z1(e,t,i)).then(a=>{this.terrainOrigin?.lat!==e||this.terrainOrigin?.lng!==t||(this.roadWays={lat:e,lng:t,radiusM:i,ways:a},this.drapeRoads(a,e,t,n.contemporary))}).catch(a=>{console.warn("Roads unavailable, drawing none:",a)})}setStatedRoads(e){e!==this.statedRoads&&(this.statedRoads=e,this.drapeStatedRoads(),this.render())}drapeStatedRoads(){const e=this.terrainMesh;e&&(this.roadSystem.group.position.copy(e.position),this.roadSystem.setStated(this.statedRoads,(t,i)=>this.groundYOfPatch(e,t,i)))}drapeRoads(e,t,i,n){const s=this.terrainMesh;s&&(this.roadSystem.group.position.copy(s.position),this.roadSystem.set(e,t,i,(a,o)=>this.groundYOfPatch(s,a,o),n),this.roadAttribution=e.length>0?this.terrainProviders.roads?.attribution:void 0,this.compileNextFrameOffThread(),this.render())}setShowCompass(e){this.showCompass!==e&&(this.showCompass=e,this.disposeCompassLabels(),e&&this.buildCompassLabels(),this.render())}setCompassPoints(e){this.compassPoints!==e&&(this.compassPoints=e,this.showCompass&&(this.disposeCompassLabels(),this.buildCompassLabels(),this.render()))}compassPoints;applyLensFlareTint(e){if(!this.lensFlare)return;const t=TE*(this.sunArriving[1]/DE);this.lensFlare.uniforms.uColorGain.value.setRGB(t*e[0],t*e[1],t*e[2]),this.applyDazzleStrength()}applyDazzleStrength(){if(!this.lensFlare)return;const[e,t,i]=this.sunArriving,n=Math.max(t,1e-30);this.lensFlare.uniforms.uDazzleColour.value.setRGB(e/n,1,i/n),this.lensFlare.uniforms.uVeilStrength.value=Pi.K*t*this.sunUnhiddenFraction}sunArriving=[0,0,0];setCompassHovered(e){this.compassHovered!==e&&(this.compassHovered=e,this.updateCompassVisibility())}setCompassForced(e){this.compassForced!==e&&(this.compassForced=e,this.updateCompassVisibility())}updateCompassVisibility(){const e=this.compassHovered||this.compassForced;if(this.compassSprites.some(t=>t.visible!==e)){for(const t of this.compassSprites)t.visible=e;this.developingExposure?this.exposureInstantsDone>0&&this.presentExposure():this.render()}}setWeather(e){if(hE(this.weather,e))return;this.cloudTransmissionMemo.clear();const t=this.weather;this.weather=e;const i=!zE(t,e),n=t.precipitationType!==e.precipitationType,s=t.precipitationIntensity!==e.precipitationIntensity||t.precipitationAmount!==e.precipitationAmount;(t.relativeHumidity!==e.relativeHumidity||n||s)&&(this.air=xn.of(e),this.applyAir(),this.scatteredSky?.setConditions({aerosolOpticalDepth:e.relativeHumidity===void 0?void 0:ta.steppedOpticalDepth(e.relativeHumidity)}),this.pumpScatteredSky()),i&&(this.buildClouds(),this.buildCirrus()),n?this.buildPrecipitation():s&&this.updatePrecipitationDensity(),this.lastAstronomy&&(i&&(this.buildIceHalos(this.lastAstronomy.sun,this.lastAstronomy.moon),this.buildLunarDiffraction(this.lastAstronomy.moon)),(i||n||s)&&this.buildRainbow(this.lastAstronomy.sun,this.lastAstronomy.moon)),this.lightningArmed=e.storm&&e.cloudDarkness>=XE,this.syncAnimationLoop(),this.render()}setDecor(e){if(this.decorObjects!==e){this.decorObjects=e,this.decorModelToken++,this.decorModelCredits.clear();for(const t of this.decorGroups.values())t.removeFromParent(),hi.dispose(t);this.decorGroups.clear(),this.streetlightLights.clear();for(const t of e){const i=hi.build(t,t.lit??!1);this.scene.add(i),this.decorGroups.set(t.id,i),t.kind==="streetlight"&&this.addStreetlightLight(t.id,i),this.loadDecorModel(t,this.decorModelToken)}this.celestialLight.castShadow=this.decorGroups.size>0||this.bodySystem.any}}setDecorModelProvider(e){this.decorModelProvider=e;const t=this.decorObjects;this.decorObjects=[],this.setDecor(t)}get currentDecorModelCredits(){return[...this.decorModelCredits.values(),...this.bodySystem.modelCredits]}get bodyGround(){const{x:e,z:t}=this.bodyOrigin,i=this.groundYUnder(e,t);return{heightAt:(n,s)=>this.groundYUnder(e+n,t-s)-i}}setBodies(e,t=0,i=e.map(a=>a.id),n=[],s){const{x:a,z:o}=this.bodyOrigin,c=this.scatteredSky;this.bodySystem.set(e,{originX:a,originZ:o,originGroundY:this.groundYUnder(a,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)},t,c?(h,u)=>c.relativeOfLuminance(h,u):void 0,i),this.bodySystem.setSmoke(n,t),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 e=this.celestialLight.color,t=this.celestialLight.intensity*.5,i=this.skyLight.color,n=this.skyLight.groundColor,s=this.skyLight.intensity,a=(o,c,l)=>(o*t+(c+l)/2*s)/Math.PI;return[a(e.r,i.r,n.r),a(e.g,i.g,n.g),a(e.b,i.b,n.b)]}bodyOutline(e,t){return this.bodySystem.outlineOf(e,t)}documentUrl;modelUrl(e){return e.url?this.documentRelative(e.url):void 0}documentRelative(e){if(e.startsWith("data:"))return e;const t=this.documentUrl??(typeof location>"u"?void 0:location.href);return t?new URL(e,t).href:e}async loadBodyModel(e){const t=e.url?void 0:e.id?await this.decorModelProvider.entry(e.id):void 0,i=this.modelUrl(e)??t?.url,n=e.credit??t?.credit;if(!(!i||!n))return{scene:await Nm(i),credit:n,headingOffsetDeg:e.headingOffsetDeg??t?.headingOffsetDeg}}async loadDecorModel(e,t){const i=e.model;if(!(!i||!hi.usesModel(e)))try{const n=i.url?void 0:i.id?await this.decorModelProvider.entry(i.id):void 0,s=this.modelUrl(i)??n?.url,a=i.credit??n?.credit;if(!s||!a)return;const o=await Nm(s);if(t!==this.decorModelToken)return;const c=this.decorGroups.get(e.id);if(!c)return;cn.reflectOn(o),hi.applyModel(c,e,o,{headingOffsetDeg:i.headingOffsetDeg??n?.headingOffsetDeg,depictedSizeM:n?.sizeM}),this.decorModelCredits.set(e.id,a),this.render()}catch(n){console.warn(`Keeping the built-in shape for decor "${e.id}":`,n)}}updateDecorAnchoring(e,t,i=0){this.decorReferencePose=e,this.decorCurrentPose=t,this.decorTime=i;const n=e?.lat!==void 0&&e.lng!==void 0&&t?.lat!==void 0&&t?.lng!==void 0?ni(e.lat,e.lng,t.lat,t.lng):{x:0,z:0},s=this.decorObjects.find(l=>l.observerSide!==void 0&&bg(l.kind));if(this.terrainMesh&&this.terrainOrigin&&t?.lat!==void 0&&t.lng!==void 0){const l=ni(this.terrainOrigin.lat,this.terrainOrigin.lng,t.lat,t.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)}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 a={x:0,z:0};let o=0;if(s){const l=hi.occupantView(s),h=-(s.headingDeg??0)*$i,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;a.x=-(f+u),a.z=-(p+d),this.camera.position.y=this.groundYUnder(f,p)+l.eyeY,this.camera.rotation.set(this.indoorLookPitchDeg*$i,-(l.headingDeg+this.indoorLookYawDeg)*$i,0,"YXZ")}this.bodyOrigin={x:n.x+a.x,z:n.z+a.z},this.placeShadowFrustum();for(const l of this.decorObjects){const h=this.decorGroups.get(l.id);if(!h)continue;const u=Or(l,i),d=u.eastM+n.x+a.x,f=-u.northM+n.z+a.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 m=Math.hypot(d,f);h.visible=m<=CE}if(u.headingDeg!==void 0&&(h.rotation.y=-u.headingDeg*$i),l.kind==="crop"&&h.visible){const m=this.terrainMesh,g=[m?.geometry.uuid,d-(m?.position.x??0),f-(m?.position.z??0),h.position.y-(m?.position.y??0),u.headingDeg,u.altitudeM].map(_=>typeof _=="number"?_.toFixed(4):_).join(":");h.userData.cropGroundKey!==g&&(hi.fitCropToGround(h,(_,b)=>this.groundYUnder(_,b)+u.altitudeM),h.userData.cropGroundKey=g)}o=Math.max(o,h.position.distanceTo(this.camera.position))}const c=Math.max(Zc*1.2,this.groundRadius*2.5,o*1.2);Math.abs(this.camera.far-c)>1&&(this.camera.far=c,this.camera.updateProjectionMatrix())}groundYUnder(e,t){const i=this.terrainMesh;return i?i.position.y+this.groundYOfPatch(i,e-i.position.x,t-i.position.z):vu}groundYOfPatch(e,t,i){const n=e.geometry.getAttribute("position"),s=Math.round(Math.sqrt(n.count));if(s<2||s*s!==n.count)return vu;const a=n.getX(0),o=n.getX(s-1),c=n.getZ(0),l=n.getZ((s-1)*s),h=Sr((t-a)/(o-a)*(s-1),0,s-1),u=Sr((i-c)/(l-c)*(s-1),0,s-1);if(!Number.isFinite(h)||!Number.isFinite(u))return vu;const d=Math.min(Math.floor(h),s-2),f=Math.min(Math.floor(u),s-2),p=h-d,v=u-f,m=(S,w)=>n.getY(S*s+w),g=m(f,d),_=m(f,d+1),b=m(f+1,d),M=m(f+1,d+1);return p+v<=1?g+(_-g)*p+(b-g)*v:M+(b-M)*(1-p)+(_-M)*(1-v)}groundUnderFootprint(e,t,i,n,s=0){return hi.groundUnderFootprint(e,t,i,n,(a,o)=>this.groundYUnder(a,o),s)}lookYawDeg=0;lookPitchDeg=0;poseCameraY=1.6;setGait(e){this.gaitOffset=e}gaitOffset={eastM:0,northM:0,upM:0,rollDeg:0,pitchDeg:0,yawDeg:0};setLookOffset(e,t){this.lookYawDeg=e,this.lookPitchDeg=t}indoorLookYawDeg=0;indoorLookPitchDeg=0;setIndoorLook(e,t){this.indoorLookYawDeg=e,this.indoorLookPitchDeg=t}medium;setMedium(e,t,i,n){const s=e&&t!==void 0&&t>0&&i!==void 0&&i>0?{kind:e.kind,iso:n??e.iso,autoExposure:e.autoExposure===!0,exposureSeconds:t,fNumber:i}:void 0;JSON.stringify(s)!==JSON.stringify(this.medium)&&(this.medium=s,this.render())}applyMedium(){const e=this.medium,t=Math.max(this.relativeScale,1e-30);if(!e){Hi.uMedium.value=0;return}Hi.uMedium.value=e.kind==="negative"?1:e.kind==="slide"?2:3;const i=e.autoExposure?this.scatteredSky?.sceneAdaptation:void 0;Hi.uMediumExposure.value=i!==void 0&&i>0?1/(t*i):.065*e.exposureSeconds*e.iso/(e.fNumber*e.fNumber*t)}grain;lampBloomRadiusRad(){if(!this.grain)return;const e=this.camera.fov*Math.PI/180,t=this.grain.frameHeightMm/(2*Math.tan(e/2)),i=Math.max(1,this.renderer.getDrawingBufferSize(this.bloomSize).y);return Math.max(this.grain.detailUm*.001/t,e/i)}bloomSize=new xe;updateDecorLitState(e,t=0){const i=this.lampBloomRadiusRad();for(const n of this.decorObjects){const s=this.decorGroups.get(n.id);if(s&&n.lights?.length&&hi.setLights(s,n.lights,e,s.position.distanceTo(this.camera.position),t,this.relativeScale,i),n.kind!=="streetlight"&&n.kind!=="vehicle")continue;const a=this.decorGroups.get(n.id);if(!a)continue;const o=_g(n,e);hi.setLit(a,n.kind,o,this.relativeScale);const c=this.streetlightLights.get(n.id);c&&(c.visible=o)}}addStreetlightLight(e,t){const i=hi.bodyOf(t),n=i.children.find(a=>a.userData.emissive);if(!n)return;const s=new g1(16764006,Gm*this.relativeScale,yE);s.position.copy(n.position).multiply(i.scale),s.castShadow=!0,s.shadow.mapSize.set(512,512),s.shadow.bias=-.002,t.add(s),this.streetlightLights.set(e,s)}setAstronomy(e){(!this.lastAstronomy||Math.abs(this.lastAstronomy.sun.altitudeDeg-e.sun.altitudeDeg)>2)&&(this.surroundings=void 0,this.scatteredSky?.resetSurroundings()),this.lastAstronomy=e,this.scatteredSky?.update(this.scatteredSkyState(e)),this.skyHoldUntilMs===void 0&&(this.skyHoldUntilMs=performance.now()+Vm,this.onFirstFrameHold?.(!0),setTimeout(()=>this.render(),Vm+20)),this.pumpScatteredSky(),this.lastSunPosition=e.sun,this.buildSky(e.sun),this.buildGround();const t=this.magnitudeLimitOf(e);this.buildStars(e.stars,t),this.placeBodies(e,t),this.buildIceHalos(e.sun,e.moon),this.buildRainbow(e.sun,e.moon),this.applySkyColours(e),this.syncAnimationLoop(),this.render()}static relativeSkyOf(e,t){const i=a=>{const o=Fn.luminanceOf(a);if(!(o>0))return[0,0,0];const c=Ae.relativeOfResponse(o)/o;return[a[0]*c,a[1]*c,a[2]*c]},n=i(e.zenith),s=i(e.horizon);return{zenith:n,horizon:s,airlight:s,skyIrradiance:[n[0]*Math.PI,n[1]*Math.PI,n[2]*Math.PI],scale:t}}placeBodies(e,t){this.bodiesScale=this.relativeScale,this.setBodyMesh("sun",e.sun,mo,new se(1,.96,.88),e.sun.magnitude),this.setMoonMesh(e.moon,t),this.buildPlanets(e.planets,t),this.buildComet(e.comet,t),this.buildNovae(e.novae??[],t)}bodiesScale=0;applySkyColours(e){this.skyColoursStale=!1,this.bodiesScale!==this.relativeScale&&(this.placeBodies(e,this.magnitudeLimitOf(e)),this.applyDazzleStrength(),this.buildIceHalos(e.sun,e.moon),this.buildRainbow(e.sun,e.moon));const t=this.scatteredSky?.ambient??zt.relativeSkyOf(Pd(e.sun.altitudeDeg),this.relativeScale),i=t,n=this.lightUnderClouds(e),s=a=>n?[0,1,2].map(o=>a[o]*n.through+n.radiance[o]*(1-n.through)):[a[0],a[1],a[2]];this.baseFogColor=[i.horizon[0],i.horizon[1],i.horizon[2]],this.airlight=s(i.airlight),this.skyMesh&&this.skyGradientMaterial&&(this.skyMesh.material=this.scatteredSky?.ready?this.scatteredSky.material:this.skyGradientMaterial),this.updateCelestialLight(e,t),this.updateCloudLighting(e.sun,this.baseFogColor),st.setEye(this.scatteredSky?.rodShare??0,this.relativeScale),this.updateTwinkle(this.twinkleSeconds);for(const a of this.streetlightLights.values())a.intensity=Gm*this.relativeScale;this.buildSkyGlow(e,i.zenith),this.applyAir(),this.buildLunarDiffraction(e.moon)}reflections;sceneVersion=0;reflectionTimer;buildLunarDiffraction(e){const t=this.scatteredSky?.ready?this.scatteredSky:void 0;if(e.altitudeDeg<-.5||!t){this.lunarDiffraction?.show(void 0),this.lunarDiffractionKey="";return}const i=this.weather.relativeHumidity,n=(i===void 0?Fe.DEFAULT_AEROSOL_OPTICAL_DEPTH:ta.opticalDepth(i))*Fe.aerosolDensity(this.siteElevationM+this.observerElevationM),s=this.cloudTransmission(e),a=-Math.log(Math.max(this.cloudTransmission(e,!0),1e-4)),o=dt.aureoleScale(n,dt.airMass(e.altitudeDeg))*s,c=dt.coronaScale(a),l=dt.illuminanceOf(e.magnitude),h=[e.altitudeDeg.toFixed(1),e.azimuthDeg.toFixed(1),e.magnitude.toFixed(2),o.toExponential(2),c.toExponential(2),Math.log10(Math.max(t.adaptation,1e-12)).toFixed(2)].join(":");if(h===this.lunarDiffractionKey)return;this.lunarDiffractionKey=h,this.lunarDiffraction||(this.lunarDiffraction=new K0,this.celestialGroup.add(this.lunarDiffraction.object));const u=dt.profile(dt.HAZE_COARSE_MODE),d=dt.profile(dt.CLOUD_DROPLETS),f=am(e.altitudeDeg),p=new Float32Array(dt.STEPS*3);let v=0;for(let b=0;b<dt.STEPS;b++){const M=b*3,S=[0,1,2].map(T=>l*f[T]*(o*u[M+T]+c*d[M+T])),w=Fn.shown(S,Fn.luminanceOf(S),(T,x)=>t.relativeOfLuminance(T,x));p.set(w,M),v=Math.max(v,Fn.response(w))}const{x:m,y:g,z:_}=li(e.altitudeDeg,e.azimuthDeg,1);this.lunarDiffraction.show(v>1/200?{x:m,y:g,z:_}:void 0,p)}applyAir(){this.scene.fog instanceof Na||(this.scene.fog=new Na),this.scene.fog.setAir(this.air,this.siteElevationM,this.airlight)}airlight=[0,0,0];transmittanceTo(e,t,i){const n=this.camera.position;return this.air.transmittance(this.siteElevationM+n.y,this.siteElevationM+t,Math.hypot(e-n.x,t-n.y,i-n.z))}setSiteElevation(e){Math.abs(e-this.siteElevationM)<1||(this.siteElevationM=e,this.applyAir(),this.lastAstronomy&&this.scatteredSky?.update(this.scatteredSkyState(this.lastAstronomy)))}scatteredSkyState(e){return{altitudeM:this.siteElevationM+this.observerElevationM+1.6,lightPollution:this.lightPollution,sun:{altitudeDeg:e.sun.altitudeDeg,azimuthDeg:e.sun.azimuthDeg,magnitude:e.sun.magnitude},moon:{altitudeDeg:e.moon.altitudeDeg,azimuthDeg:e.moon.azimuthDeg,magnitude:e.moon.magnitude,phaseAngleDeg:Me.phaseAngleOf(e.moon.phase.illuminatedFraction)}}}pumpScatteredSky(){const e=this.scatteredSky;!e||e.tables.ready||this.scatteredSkyFrameId!==null||this.contextReleased||(this.scatteredSkyFrameId=requestAnimationFrame(()=>{this.scatteredSkyFrameId=null,!this.contextReleased&&(e.advance(this.skyHoldUntilMs?SE:_E),this.pumpScatteredSky())}))}cancelScatteredSkyPump(){this.scatteredSkyFrameId!==null&&(cancelAnimationFrame(this.scatteredSkyFrameId),this.scatteredSkyFrameId=null)}setSatellites(e){if(e.length===0&&!this.satelliteField?.count)return;this.satelliteField||(this.satelliteField=new F5(hu),this.celestialGroup.add(this.satelliteField.object));const t=this.lastAstronomy?this.magnitudeLimitOf(this.lastAstronomy):Ld(-90,this.instrumentMagnitudeGain);this.satelliteField.set(e,t,i=>this.cloudTransmission(i),(i,n)=>this.arrivingIlluminance(i,n,1)),this.render()}pickSatelliteAt(e,t){if(!this.satelliteField?.count)return;this.aimAtScreenPoint(this.raycaster,e,t);const i=Math.cos(Bm*this.camera.fov*Math.PI/180),n=this.satelliteField.nearest(this.raycaster.ray.direction,i);return n&&this.groundHides(e,t)?void 0:n}updateCelestialLight(e,t){const i=this.relativeScale,n=e.sun.altitudeDeg>=jc,s=!n&&e.moon.altitudeDeg>=jc,a=n?e.sun:e.moon,o=[0,0,0],c=Math.max(0,Math.sin(Math.max(a.altitudeDeg,0)*$i)),l=n||s?this.cloudTransmission(a):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 _=dt.illuminanceOf(a.magnitude)*i,b=this.air.transmittanceFromSpace(this.siteElevationM+this.observerElevationM,a.altitudeDeg);for(let T=0;T<3;T++)o[T]=_*b[T]*l,d[T]=_*b[T]*u*c,this.cloudBeam[T]=_*b[T];const{x:M,y:S,z:w}=li(a.altitudeDeg,a.azimuthDeg,1);this.cloudBeamDirection.set(M,S,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 _=this.skyCloudTransmission(),b=t.skyIrradiance,M=[0,1,2].map(w=>b[w]*_+d[w]);this.skyLight.color.setRGB(M[0],M[1],M[2]);const S=We.GROUND_ALBEDO;this.skyLight.groundColor.setRGB(S*(M[0]+o[0]*c),S*(M[1]+o[1]*c),S*(M[2]+o[2]*c))}if(this.skyLight.intensity=1,!n&&!s){this.celestialLight.intensity=0;return}const{x:p,y:v,z:m}=li(a.altitudeDeg,a.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}lightDirection=new R(0,1,0);placeShadowFrustum(){const e=this.lightDirection,t=this.celestialLight.shadow.camera,i=(t.right-t.left)/this.celestialLight.shadow.mapSize.x,n=this.shadowAxisX.crossVectors(this.shadowUp,e);n.lengthSq()<1e-8&&n.set(1,0,0),n.normalize();const s=this.shadowAxisY.crossVectors(e,n).normalize(),a=this.shadowWorld.set(this.bodyOrigin.x,0,this.bodyOrigin.z),o=l=>{const h=a.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(e,this.shadowLightDistanceM)}fitShadowToBodies(){const e=this.bodySystem.reachFrom(this.camera.position),t=Math.min(fE,Math.max(Xs,Math.ceil(e*1.25/20)*20));if(t===this.shadowHalfExtentM)return;this.shadowHalfExtentM=t;const i=this.celestialLight.shadow,n=i.camera;n.left=-t,n.right=t,n.top=t,n.bottom=-t;const s=Math.max(po,t*(po/Xs));this.shadowLightDistanceM=Math.max(an,s+10),n.near=this.shadowLightDistanceM-s,n.far=this.shadowLightDistanceM+s,n.updateProjectionMatrix(),i.bias=-.03/(2*s);const a=t>2*Xs?2048:1024;i.mapSize.x!==a&&(i.mapSize.set(a,a),i.map?.dispose(),i.map=null),this.placeShadowFrustum()}shadowHalfExtentM=Xs;shadowLightDistanceM=an;shadowUp=new R(0,1,0);shadowAxisX=new R;shadowAxisY=new R;shadowWorld=new R;skyCloudTransmission(){let e=this.cloudTransmission({altitudeDeg:90,azimuthDeg:0}),t=1;for(const i of[20,45,70]){const n=i*$i,s=Math.sin(n)*Math.cos(n)*2;for(let a=0;a<360;a+=60)e+=s*this.cloudTransmission({altitudeDeg:i,azimuthDeg:a}),t+=s}return e/t}cloudBeam=[0,0,0];cloudBeamDirection=new R(0,1,0);get relativeScale(){return this.scatteredSky?.relativeScale??1/Ae.semiSaturation(Ae.DAYLIGHT_ANCHOR_CD_M2)}setMeteorShower(e,t,i){this.meteorSystem||(this.meteorSystem=new xi,this.celestialGroup.add(this.meteorSystem.object)),this.meteorSystem.setShower(e,t,i)}get meteorSchedule(){return this.meteorSystem?.schedule??[]}meteorMidpoint(e){return this.meteorSystem?.midpointOf(e)}updateMeteors(e){this.meteorSystem?.update(e)}setInstrument(e){this.projectionKind=e.projection,this.grain=e.detailUm!==void 0&&e.frame?{detailUm:e.detailUm,frameHeightMm:e.frame.heightMm}:void 0;const t=si.starPointsOf(e),i=si.flareArtifactsOf(e);t===this.starPoints&&i===this.lensFlareArtifactIntensity||(this.starPoints=t,this.lensFlareArtifactIntensity=i,this.lensFlare&&(this.lensFlare.uniforms.uStarPoints.value=t,this.lensFlare.uniforms.uFlareIntensity.value=i),this.render())}magnitudeLimitOf(e){const t=Me.starLossMagnitudes(e.sun.altitudeDeg,{phaseAngleDeg:Me.phaseAngleOf(e.moon.phase.illuminatedFraction),altitudeDeg:e.moon.altitudeDeg},this.lightPollution);return Ld(e.sun.altitudeDeg,this.instrumentMagnitudeGain,t)}setLightPollution(e){e!==this.lightPollution&&(this.lightPollution=e,this.lastAstronomy&&this.scatteredSky?.update(this.scatteredSkyState(this.lastAstronomy)))}setInstrumentGain(e,t=!1){this.instrumentMagnitudeGain=Number.isFinite(e)?e:0,this.scatteredSky?.setInstrument(t,this.instrumentMagnitudeGain)}render(){this.restatingExposure||(this.sceneVersion++,this.frameDirty=!0,this.resolution.noteChange(performance.now()),!(this.animationFrameId!==null||this.framesDriven||this.flushFrameId!==null)&&(this.flushFrameId=requestAnimationFrame(()=>{this.flushFrameId=null,this.drawIfDirty()})))}drawIfDirty(){if(!(!this.frameDirty||this.contextReleased)){if(this.skyHoldUntilMs){if(!this.firstFrameReady()&&performance.now()<this.skyHoldUntilMs)return;this.skyHoldUntilMs=null,this.iceHalos?.setUrgent(!1),this.onFirstFrameHold?.(!1)}if(this.skyColoursStale&&this.lastAstronomy&&this.applySkyColours(this.lastAstronomy),this.compileBeforeNextDraw){this.compileBeforeNextDraw=!1;const e=this.compileOffThread().then(()=>{this.compiling===e&&(this.compiling=void 0,this.render())});this.compiling=e;return}if(!this.compiling){this.frameDirty=!1,this.refreshReflections(),this.resolution.beginDrawing();try{this.renderOnce()}finally{this.resolution.endDrawing()}this.developingExposure&&this.startExposure()}}}compileBeforeNextDraw=!1;compiling;static COMPILE_WAIT_MS=1500;compileOffThread(){const e=this.renderer.compile(this.scene,this.camera);if(!this.renderer.extensions.get("KHR_parallel_shader_compile"))return Promise.resolve();const t=this.renderer.properties,i=performance.now()+zt.COMPILE_WAIT_MS;return new Promise(n=>{const s=()=>{if(this.contextReleased)return n();for(const a of e){const o=t.get(a)?.currentProgram;(!o||o.isReady())&&e.delete(a)}e.size===0||performance.now()>i?n():setTimeout(s,10)};s()})}compileNextFrameOffThread(){this.compileBeforeNextDraw=!0}contextReleased=!1;releaseContext(){this.contextReleased||(this.contextReleased=!0,this.stopTwinkle(),this.cancelFlush(),this.cancelExposure(),this.compiling=void 0,this.cancelScatteredSkyPump(),this.renderer.forceContextLoss())}restoreContext(){this.contextReleased&&(this.contextReleased=!1,this.renderer.forceContextRestore(),this.scatteredSky?.invalidate(),this.pumpScatteredSky(),this.compileNextFrameOffThread(),this.syncAnimationLoop(),this.render())}cancelFlush(){this.flushFrameId!==null&&(cancelAnimationFrame(this.flushFrameId),this.flushFrameId=null)}frame(e){if(this.animationsRunning){const t=this.lastFrameTimeMs===void 0?0:e-this.lastFrameTimeMs;this.lastFrameTimeMs=e,this.hasAnimations()&&this.animate(e,t);const i=this.resolution.ratioFor(e,t);i!==this.renderer.getPixelRatio()&&this.applyPixelRatio(i)}this.drawIfDirty()}refreshReflections(){this.reflections??=new cn(this.renderer);const e=[...this.compassSprites,...this.lensFlare?[this.lensFlare.mesh]:[],...[...this.glareSprites.values()].map(s=>s.mesh)],t=[...this.starTiers.map(s=>s.points),...[...this.bodyMeshes.values()].filter(s=>s instanceof xs),...[this.rainSystem?.points,this.precipitationPoints,this.rainSplashSystem?.points].filter(s=>s!==void 0)],i=this.relativeScale,n=this.reflections.refresh(this.renderer,this.scene,this.camera.position,this.bodySystem.reflectors,e,[...this.decorGroups.values()],this.sceneVersion,t,s=>this.measureSurroundings(s,i));n===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()}))},n))}measureSurroundings(e,t){const i=this.lastAstronomy;if(!i)return;this.probeIrradiance??=new Po;const n=[i.sun,i.moon].filter(s=>s.altitudeDeg>-2).map(s=>li(s.altitudeDeg,s.azimuthDeg,1));this.probeIrradiance.measure(this.renderer,e,n,s=>{const a=d=>d.map(f=>f/t),o=this.surroundings,c={up:a(s.up),down:a(s.down)},l=(d,f)=>d.some((p,v)=>Math.abs(p-f[v])>.03*Math.max(Math.abs(p),Math.abs(f[v]),1e-12)),h=!o||l(o.up,c.up)||l(o.down,c.down);h&&(this.surroundings=c);const u=this.scatteredSky?.adaptToSurroundings(Math.exp(s.logAverage)/t)??!1;!h&&!u||(this.skyColoursStale=!0,this.render())})}lightUnderClouds(e){const t=this.surroundings;if(!t)return;const i=e.sun.altitudeDeg>=jc?e.sun:e.moon.altitudeDeg>=jc?e.moon:void 0;if(!i)return;const n=this.relativeScale/Math.PI;return{through:this.cloudTransmission(i),radiance:[t.up[0]*n,t.up[1]*n,t.up[2]*n]}}probeIrradiance;surroundings;animate(e,t){const i=Math.min(t/1e3,WE);this.twinkleSeconds=e/1e3,this.updateTwinkle(this.twinkleSeconds),this.updatePrecipitation(e/1e3,i),this.updateRain(i),this.lensFlare&&(this.lensFlare.uniforms.uTime.value=e/1e3),this.developingExposure||(this.frameDirty=!0)}setMaxPixelRatio(e){this.resolution.maximum=e,this.renderer.getPixelRatio()>this.resolution.maximum&&this.applyPixelRatio(this.resolution.maximum)}applyPixelRatio(e){this.renderer.setPixelRatio(e),this.renderer.setSize(this.cssSize.width,this.cssSize.height,!1),this.frameDirty=!0}setExposure(e,t){const i=t?Math.max(1,Math.round(e)):1;if(i===this.exposureInstants&&(i===1||t===this.exposureInstantAt)){this.exposureInstantAt=t;return}this.exposureInstants=i,this.exposureInstantAt=t,i===1&&(this.cancelExposure(),this.exposureAccumulation?.dispose(),this.exposureAccumulation=void 0),this.render()}renderOnce(e){if(this.onMapSubjectBounds){const a=this.mapSubjectBounds();e?this.exposureSubjectBounds.push(...a):this.onMapSubjectBounds(a)}const t=this.usableEquidistantPass();this.phenomena.setCloudLayers(this.layeredClouds?.volumes??[]),this.phenomena.place(this.camera,(a,o,c)=>this.directionAtScreenPoint(a,o,c),a=>this.screenPointOf(a)),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()),Hi.uRodShare.value=this.scatteredSky?.rodShare??0,Hi.uRelativeScale.value=this.relativeScale,this.applyMedium();const n=this.references.any||this.phenomena.any||this.compassSprites.some(a=>a.visible);Hi.uHasOverlay.value=n?1:0;const s=n?a=>this.renderOverlayPasses(a):void 0;if(this.skyGlow?.setDestinationEncoded(!1),!t){this.updateLensFlarePosition();const a=this.usableDepthOfFieldPass();a?a.render(this.renderer,this.scene,this.camera,s,e):this.usableFinishPass().render(this.renderer,this.scene,this.camera,s,void 0,e);return}t.render(this.renderer,this.scene,this.camera,this.camera.fov,()=>this.updateLensFlarePosition(),s,a=>{this.lensFlare&&(this.lensFlare.mesh.visible=a?!1:this.sunVisible)},()=>this.renderDazzleOnResample(),e)}renderOverlayPasses(e=this.camera){this.renderReferencesPass(e),this.renderPhenomenaPass(e),this.renderHudPass(e)}renderHudPass(e){if(!this.compassSprites.some(n=>n.visible))return;const t=this.renderer.autoClear,i=this.renderer.shadowMap.autoUpdate;this.renderer.autoClear=!1,this.renderer.shadowMap.autoUpdate=!1,e.layers.set(Um),this.renderer.render(this.scene,e),e.layers.set(0),this.renderer.autoClear=t,this.renderer.shadowMap.autoUpdate=i}renderReferencesPass(e){if(!this.references.any)return;const t=this.renderer.autoClear,i=this.renderer.shadowMap.autoUpdate;this.renderer.autoClear=!1,this.renderer.shadowMap.autoUpdate=!1,e.layers.set(ov),this.renderer.render(this.scene,e),e.layers.set(0),this.renderer.autoClear=t,this.renderer.shadowMap.autoUpdate=i}setReferences(e,t){this.references.set(e.map(i=>{const n=this.documentRelative(i.src);return n===i.src?i:{...i,src:n}}),void 0,t)}referenceAspect(e){return this.references.aspectOf(e)}directionAt(e,t){return this.directionAtScreenPoint(e,t,new R)}referenceFailedToLoad(e){return this.references.failedToLoad(this.documentRelative(e))}setReferencesShown(e){this.references.setShown(e),this.render()}setReferenceView(e,t){this.references.setView(e,t),this.render()}renderPhenomenaPass(e){if(!this.phenomena.any)return;const t=this.renderer.autoClear,i=this.renderer.shadowMap.autoUpdate;this.renderer.autoClear=!1,this.renderer.shadowMap.autoUpdate=!1,this.renderer.clearDepth();for(const n of this.decorObjects){const s=this.decorGroups.get(n.id);s&&zt.markDecorDepth(s,n.kind!=="crop")}e.layers.set(cu),this.scene.overrideMaterial=this.decorDepthMaterial,this.renderer.render(this.scene,e),this.scene.overrideMaterial=null,e.layers.set(rv),this.renderer.render(this.scene,e),e.layers.set(0),this.renderer.autoClear=t,this.renderer.shadowMap.autoUpdate=i}decorDepthMaterial=new bn({colorWrite:!1});static markDecorDepth(e,t){e.traverse(i=>{if(!(i instanceof De))return;const n=Array.isArray(i.material)?i.material[0]:i.material;t&&n.depthWrite!==!1&&n.blending!==Ni?i.layers.enable(cu):i.layers.disable(cu)})}startExposure(){this.cancelExposure(),this.exposureSubjectBounds=[];const e=this.renderer.getDrawingBufferSize(new xe),t=Math.max(1,Math.round(e.x)),i=Math.max(1,Math.round(e.y));this.exposureAccumulation||(this.exposureAccumulation=new tw(t,i)),this.exposureAccumulation.resize(t,i),this.exposureAccumulation.open(this.renderer),this.exposureInstantsDone=0,this.exposureFrameId=requestAnimationFrame(()=>this.developExposure())}developExposure(){this.exposureFrameId=null;const e=this.exposureInstantAt,t=this.exposureAccumulation;if(!e||!t)return;const i=1/this.exposureInstants;this.resolution.beginDrawing();const n=performance.now()+zt.EXPOSURE_BUDGET_MS,s=zt.exposureInstantsPerFrame(t.instantTarget.scene.width*t.instantTarget.scene.height);let a=0;do{this.restateAt(e,this.exposureInstantsDone);const o=this.compassSprites.map(c=>c.visible);for(const c of this.compassSprites)c.visible=!1;try{this.renderOnce(t.instantTarget)}finally{this.compassSprites.forEach((c,l)=>{c.visible=o[l]})}t.add(this.renderer,i),this.exposureInstantsDone++,a++}while(this.exposureInstantsDone<this.exposureInstants&&performance.now()<n&&a<s);this.restateAt(e,0),this.presentExposure(),this.resolution.endDrawing(),this.exposureInstantsDone<this.exposureInstants&&(this.exposureFrameId=requestAnimationFrame(()=>this.developExposure()))}presentExposure(){if(Hi.uRodShare.value=this.scatteredSky?.rodShare??0,Hi.uHasOverlay.value=1,Hi.uRelativeScale.value=this.relativeScale,this.applyMedium(),this.exposureAccumulation?.develop(this.renderer,this.exposureInstants/this.exposureInstantsDone),this.onMapSubjectBounds?.(this.exposureSubjectBounds),!this.compassSprites.some(s=>s.visible))return;const e=new Is,t=new zn(-1,1,1,-1,0,2),i=Qc/(Wm*Math.tan(Xm*$i/2));for(const s of this.compassSprites){if(!s.visible)continue;const a=s.getWorldPosition(new R).sub(this.camera.position).normalize(),o=this.screenPointOf(a);if(!o)continue;const c=new to(s.material);c.position.set(o.ndcX,o.ndcY,-1),c.scale.set(i/this.camera.aspect,i,1),e.add(c)}const n=this.renderer.autoClear;this.renderer.autoClear=!1;try{this.renderer.render(e,t)}finally{this.renderer.autoClear=n}}onMapSubjectBounds;exposureSubjectBounds=[];static MAP_SUBJECT_NEAREST_M=8;mapSubjectBounds(){const e=[],t=new Wi,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)),a=this.bodySystem.reflectors.map(o=>o.holder);for(const o of[...s,...a]){if(!o?.visible||(t.setFromObject(o),t.isEmpty())||t.distanceToPoint(this.camera.position)<zt.MAP_SUBJECT_NEAREST_M)continue;let c=1/0,l=-1/0,h=1/0,u=-1/0;for(const d of[t.min.x,t.max.x])for(const f of[t.min.y,t.max.y])for(const p of[t.min.z,t.max.z]){if(i.set(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&&e.push({x:c,y:h,width:l-c,height:u-h})}return e}restateAt(e,t){this.restatingExposure=!0;try{e(t)}finally{this.restatingExposure=!1}}cancelExposure(){this.exposureFrameId!==null&&(cancelAnimationFrame(this.exposureFrameId),this.exposureFrameId=null)}setLensOptics(e){const t=this.lensOptics;this.lensOptics=e,(t===void 0!=(e===void 0)||t&&e&&(t.focalLengthMm!==e.focalLengthMm||t.fNumber!==e.fNumber||t.focusDistance!==e.focusDistance||t.frameHeightMm!==e.frameHeightMm))&&(e&&this.depthOfFieldPass&&this.depthOfFieldPass.setLens(e.focalLengthMm,e.fNumber,e.focusDistance,e.frameHeightMm),this.render())}usableDepthOfFieldPass(){const e=this.lensOptics;if(!e)return;const t=this.renderer.getDrawingBufferSize(new xe),i=Math.max(1,Math.round(t.x)),n=Math.max(1,Math.round(t.y));return this.depthOfFieldPass||(this.depthOfFieldPass=new Lo(i,n)),this.depthOfFieldPass.resize(i,n),this.depthOfFieldPass.setLens(e.focalLengthMm,e.fNumber,e.focusDistance,e.frameHeightMm),this.depthOfFieldPass}usableFinishPass(){const e=this.renderer.getDrawingBufferSize(new xe);return this.finishPass?this.finishPass.resize(e.x,e.y):this.finishPass=new $0(e.x,e.y),this.finishPass}usableEquidistantPass(){if(this.projectionKind!=="equidistant")return;const e=this.renderer.getDrawingBufferSize(new xe);return this.equidistantPass?this.equidistantPass.resize(e.x,e.y):this.equidistantPass=new yi(e.x,e.y),this.equidistantPass}aimAtScreenPoint(e,t,i){const n=this.projectionKind==="equidistant"?this.equidistantPass:void 0;if(!n){e.setFromCamera(new xe(t,i),this.camera);return}const s=n.directionFor(t,i,this.camera.fov);this.camera.updateMatrixWorld(),e.ray.origin.setFromMatrixPosition(this.camera.matrixWorld),e.ray.direction.set(s.x,s.y,s.z).applyQuaternion(this.camera.quaternion).normalize(),e.camera=this.camera}pickCloudAt(e,t){return this.layeredClouds?.pickInstance(this.cloudDirectionAt(e,t))}cloudDirectionAt(e,t){return this.directionAtScreenPoint(e,t,new R)}directionAtScreenPoint(e,t,i){return this.aimAtScreenPoint(this.ufoOcclusionRaycaster,e,t),i.copy(this.ufoOcclusionRaycaster.ray.direction)}screenPointOf(e){this.camera.updateMatrixWorld();const t=this.screenPointScratch.copy(e).applyQuaternion(this.screenPointQuaternion.copy(this.camera.quaternion).invert()),i=this.renderer.getDrawingBufferSize(this.screenPointSize),n=i.x/Math.max(i.y,1);if(this.projectionKind==="equidistant"&&this.equidistantPass)return yi.ndcFor(t,this.camera.fov,n);if(t.z>=0)return;const s=Math.tan(this.camera.fov/2*$i);return{ndcX:t.x/-t.z/(n*s),ndcY:t.y/-t.z/s}}screenPointScratch=new R;screenPointQuaternion=new en;screenPointSize=new xe;updateLensFlarePosition(){const e=this.lensFlare;if(!e)return;if(!this.sunVisible){e.mesh.visible=!1;return}if(this.camera.updateMatrixWorld(),this.lensFlareScratch.copy(this.sunWorldPosition).applyMatrix4(this.camera.matrixWorldInverse),this.lensFlareScratch.z>0){e.mesh.visible=!1;return}const t=this.sunVisibleFraction();if(t<=0){e.mesh.visible=!1;return}e.mesh.visible=!0,this.sunUnhiddenFraction=t,this.applyDazzleStrength();const i=this.lensFlareScratch.copy(this.sunWorldPosition).project(this.camera);e.uniforms.uLensPosition.value.set(i.x,i.y);const n=this.renderer.domElement.width,s=this.renderer.domElement.height;e.uniforms.uResolution.value.set(n,s),e.uniforms.uTanHalfFov.value=Math.tan(this.camera.fov*Math.PI/360)}renderDazzleOnResample(){const e=this.lensFlare;if(!e||!this.sunVisible)return;const t=this.sunVisibleFraction();if(t<=0)return;this.sunUnhiddenFraction=t,this.applyDazzleStrength();const i=this.screenPointOf(this.lensFlareScratch.copy(this.sunWorldPosition).sub(this.camera.position).normalize());if(!i)return;const n=this.renderer.getDrawingBufferSize(this.screenPointSize);e.uniforms.uLensPosition.value.set(i.ndcX,i.ndcY),e.uniforms.uResolution.value.set(n.x,n.y),e.uniforms.uEquidistant.value=1,e.uniforms.uHalfFovRad.value=this.camera.fov*Math.PI/360;const s=this.renderer.autoClear;this.renderer.autoClear=!1,e.mesh.visible=!0,e.mesh.layers.enable(Fm),this.camera.layers.set(Fm),this.renderer.render(this.scene,this.camera),this.camera.layers.set(0),e.mesh.visible=!1,e.uniforms.uEquidistant.value=0,this.renderer.autoClear=s}sunVisibleFraction(){this.raycastableDecor().length>0&&this.scene.updateMatrixWorld();let e=0;for(const t of qm)this.isSunOccluded(t[0],t[1])||e++;return e/qm.length}raycastableDecor(){const e=[];for(const t of this.decorObjects){if(t.kind==="crop")continue;const i=this.decorGroups.get(t.id);i&&e.push(i)}return e}isSunOccluded(e=0,t=0){const i=this.raycastableDecor();if(!this.groundMesh&&!this.terrainMesh&&i.length===0)return!1;const n=this.sunOcclusionDirectionScratch.copy(this.sunWorldPosition).sub(this.camera.position),s=n.length();if(n.normalize(),e!==0||t!==0){const 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,e*o).addScaledVector(l,t*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 a=this.sunOcclusionRaycaster.intersectObjects(i,!0)[0];return a!==void 0&&a.distance<s}groundBlocks(e,t,i,n=0){const s=this.groundMesh;if(s&&t.y<0){const m=(s.position.y-e.y)/t.y;if(m>n&&m<i){const g=e.x+t.x*m-s.position.x,_=e.z+t.z*m-s.position.z;if(Math.hypot(g,_)<=this.groundRadius)return!0}}const a=this.terrainMesh;if(!a)return!1;const o=a.geometry.getAttribute("position"),c=Math.round(Math.sqrt(o.count));if(c<2||c*c!==o.count)return!1;const l=[a.position.x+o.getX(0),a.position.x+o.getX(c-1)],h=[a.position.z+o.getZ(0),a.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,_]of[[e.x,t.x,l],[e.z,t.z,h]]){const b=Math.min(_[0],_[1]),M=Math.max(_[0],_[1]);if(Math.abs(g)<1e-12){if(m<b||m>M)return!1;continue}const S=(b-m)/g,w=(M-m)/g;d=Math.max(d,Math.min(S,w)),f=Math.min(f,Math.max(S,w))}if(!(f>d))return!1;const p=Math.hypot(t.x,t.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,_=e.x+t.x*g,b=e.y+t.y*g,M=e.z+t.z*g;if(b<=this.groundYUnder(_,M))return!0}return!1}setPhenomena(e,t){this.phenomena.set(e,t)}decorDistancesAt(e,t,i){this.aimAtScreenPoint(this.ufoOcclusionRaycaster,e,t),this.ufoOcclusionRaycaster.near=km;let n,s;for(const a of this.decorObjects){if(a.kind==="crop")continue;const o=this.decorGroups.get(a.id);if(!o)continue;const c=this.ufoOcclusionRaycaster.intersectObject(o,!0)[0];c&&(a.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(e,t){this.aimAtScreenPoint(this.raycaster,e,t);const i=[...this.hitAreas.entries()],n=this.raycaster.intersectObjects(i.map(([,s])=>s))[0];if(n&&!this.groundHides(e,t))return i.find(([,s])=>s===n.object)?.[0]}pickStarAt(e,t){if(this.namedStars.length===0)return;this.aimAtScreenPoint(this.raycaster,e,t);const i=this.raycaster.ray.direction,n=Math.cos(Bm*this.camera.fov*Math.PI/180);let s,a=n;for(const o of this.namedStars){const c=o.direction.dot(i);c>a&&(a=c,s={star:o.star,altitudeDeg:o.altitudeDeg})}return s&&this.groundHides(e,t)?void 0:s}groundHides(e,t){if(!this.terrainMesh&&!this.groundMesh)return!1;this.aimAtScreenPoint(this.ufoOcclusionRaycaster,e,t);const i=this.ufoOcclusionRaycaster.ray;return this.groundBlocks(i.origin,i.direction,1/0,km)}bodyScreenBox(e){const t=this.bodySystem.boxOf(e,this.bodyBoxScratch);if(!t)return;let i=1/0,n=1/0,s=-1/0,a=-1/0;for(let o=0;o<8;o++){const c=this.bodyCornerScratch.set(o&1?t.max.x:t.min.x,o&2?t.max.y:t.min.y,o&4?t.max.z:t.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),a=Math.max(a,l.ndcY)}return{minX:i,minY:n,maxX:s,maxY:a}}bodyBoxScratch=new Wi;bodyCornerScratch=new R;pickPlacedBodyAt(e,t){return this.aimAtScreenPoint(this.raycaster,e,t),this.bodySystem.pick(this.raycaster)}pickDecorAt(e,t){this.aimAtScreenPoint(this.raycaster,e,t);const i=[...this.decorGroups.entries()],n=this.raycaster.intersectObjects(i.map(([,a])=>a),!0)[0];if(!n)return;let s=n.object;for(;s&&!i.some(([,a])=>a===s);)s=s.parent;return i.find(([,a])=>a===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.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.lightningBolt?.dispose(),this.lightningBolt=void 0;for(const e of this.bodyMeshes.values())this.disposeMesh(e);this.bodyMeshes.clear(),this.novaKeys.clear();for(const e of[...this.hitAreas.keys()])this.disposeHitArea(e);for(const e of[...this.glareSprites.keys()])this.disposeGlare(e);this.disposeCompassLabels();for(const e of this.decorGroups.values())hi.dispose(e);this.decorGroups.clear(),this.streetlightLights.clear(),this.lensFlare&&(this.lensFlare.mesh.removeFromParent(),this.lensFlare.mesh.geometry.dispose(),this.lensFlare.mesh.material.dispose(),this.lensFlare=void 0),this.renderer.dispose()}animationsRunning=!1;startTwinkle(){if(this.animationFrameId!==null||!this.needsAnimationLoop())return;this.cancelFlush();const e=t=>{this.frame(t),this.animationFrameId=requestAnimationFrame(e)};this.animationFrameId=requestAnimationFrame(e)}setAnimationsRunning(e,t=!1){const i=e&&t;if(e===this.animationsRunning&&i===this.framesDriven)return;const n=this.animationsRunning;this.animationsRunning=e,this.framesDriven=i,e&&!n&&(this.lastFrameTimeMs=void 0,this.resolution.reset());const s=!e&&this.renderer.getPixelRatio()!==this.resolution.maximum;s&&this.applyPixelRatio(this.resolution.maximum),this.syncAnimationLoop(),(!e||this.frameDirty)&&this.render(),s&&this.drawIfDirty()}stopTwinkle(){this.animationFrameId!==null&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null)}needsAnimationLoop(){return this.animationsRunning&&!this.framesDriven&&this.hasAnimations()}hasAnimations(){return this.starTiers.length>0||this.precipitationPoints!==void 0||this.rainSystem!==void 0||this.lensFlare!==void 0&&this.sunVisible}syncAnimationLoop(){this.needsAnimationLoop()?this.startTwinkle():this.stopTwinkle()}buildSky(e){const t=this.skyMesh?.geometry??new ri(Zc,32,16),i=t.attributes.position,n=t.getAttribute("color")??new ut(new Float32Array(i.count*3),3);for(let a=0;a<i.count;a++){const{altitudeDeg:o,azimuthDeg:c}=sw(i.getX(a),i.getY(a),i.getZ(a)),l=dw(o,c,e.azimuthDeg,e.altitudeDeg);n.setXYZ(a,l[0],l[1],l[2])}if(n.needsUpdate=!0,this.skyMesh)return;t.setAttribute("color",n);const s=new bn({vertexColors:!0,side:Ht,fog:!1,depthWrite:!1});this.skyGradientMaterial=s,this.skyMesh=new De(t,s),this.skyMesh.renderOrder=-1,this.celestialGroup.add(this.skyMesh)}buildGround(){const e=zm(this.observerElevationM);if(this.groundMesh&&e===this.groundRadius)return;this.disposeMesh(this.groundMesh),this.groundRadius=e;const t=new T0(this.groundRadius,48),i=new Vr({color:new se(lu,lu,lu),fog:!0});Na.fadeRim(i,this.groundRadius*.75,this.groundRadius),this.groundMesh=new De(t,i),this.groundMesh.rotation.x=-Math.PI/2,this.groundMesh.position.y=0,this.groundMesh.receiveShadow=!0,this.scene.add(this.groundMesh),this.applyGroundDepthWrite()}applyGroundDepthWrite(){const e=this.groundMesh?.material;if(!e)return;const t=this.terrainMesh===void 0;e.depthWrite!==t&&(e.depthWrite=t,e.needsUpdate=!0)}cloudTransmission(e,t=!1){const i=`${e.altitudeDeg.toFixed(1)}:${e.azimuthDeg.toFixed(1)}:${Math.round(this.cloudOffsetM.x/10)}:${Math.round(this.cloudOffsetM.z/10)}:${Math.round(this.observerElevationM)}:`+Object.entries(this.cloudLayerOffsetsM).map(([a,o])=>`${a}=${Math.round(o.x/10)},${Math.round(o.z/10)}`).join(";")+(t?":water":""),n=this.cloudTransmissionMemo.get(i);if(n!==void 0)return n;this.cloudTransmissionMemo.size>256&&this.cloudTransmissionMemo.clear();const s=this.computeCloudTransmission(e,t);return this.cloudTransmissionMemo.set(i,s),s}cloudTransmissionMemo=new Map;computeCloudTransmission(e,t=!1){const i=li(e.altitudeDeg,e.azimuthDeg,1);if(this.layeredClouds)return this.layeredClouds.transmissionAt(i,t);let n=1;const s=this.lowerCloudCover();s>0&&(n*=1-pt.alphaAt(i,Math.abs(this.cloudLayerOffset()),s,this.cloudFieldOffset)*ME);const a=t?0:this.weather.highCloudCover??0;return a>0&&(n*=1-pt.iceAlphaAt(i,Jc,a,this.cloudFieldOffset)*xE),Math.max(0,Math.min(1,n))}setBodyMesh(e,t,i,n,s){if(t.altitudeDeg<i0){this.disposeMesh(this.bodyMeshes.get(e)),this.bodyMeshes.delete(e),this.disposeHitArea(e),this.disposeGlare(e),e==="sun"&&(this.sunVisible=!1);return}const{x:a,y:o,z:c}=li(t.altitudeDeg,t.azimuthDeg,an),l=am(t.altitudeDeg),h=this.cloudTransmission(t),u=this.arrivingIlluminance(t,s,h),d=zt.unitLuminance(n);let f=this.bodyMeshes.get(e);if(e==="sun"){const p=Math.PI*(i/an)**2,v=[0,1,2].map(m=>Math.min(zt.BRIGHTEST_RELATIVE,d[m]*u[m]/p));f instanceof De||(this.disposeMesh(f),f=new De(new ri(1,16,16),new bn({fog:!1})),this.celestialGroup.add(f),this.bodyMeshes.set(e,f)),f.material.color.setRGB(v[0],v[1],v[2]),f.scale.setScalar(i)}else{if(!(f instanceof xs)){this.disposeMesh(f);const m=new ot;m.setAttribute("position",new tt(new Float32Array(3),3)),m.setAttribute("color",new tt(new Float32Array(3),3)),f=new xs(m,st.material(Co[Co.length-1].size,!1)),st.track(f),this.celestialGroup.add(f),this.bodyMeshes.set(e,f)}const p=f.geometry.getAttribute("color"),v=e.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(a,o,c),this.setHitArea(e,a,o,c,i),e==="sun"&&(this.sunArriving=u),e.startsWith("comet:")?this.disposeGlare(e):e!=="sun"&&this.setGlare(e,a,o,c,u,i/an*(180/Math.PI),zt.POINT_VEIL_HOLD_DEG),e==="sun"){this.sunVisible=!0;const p=this.celestialGroup.scale.x;this.sunWorldPosition.set(a*p,o*p+this.celestialGroup.position.y,c*p),this.lensFlare||(this.lensFlare=N5(),this.lensFlare.uniforms.uOpacity.value=RE,this.lensFlare.uniforms.uFlareIntensity.value=this.lensFlareArtifactIntensity,this.lensFlare.uniforms.uStarPoints.value=this.starPoints,this.scene.add(this.lensFlare.mesh)),this.applyLensFlareTint(l)}}setMoonMesh(e,t){const i="moon";if(e.magnitude>t||e.altitudeDeg<i0){this.disposeMesh(this.bodyMeshes.get(i)),this.bodyMeshes.delete(i),this.disposeHitArea(i),this.disposeGlare(i);return}const{x:n,y:s,z:a}=li(e.altitudeDeg,e.azimuthDeg,an),o=this.cloudTransmission(e),c=this.arrivingIlluminance(e,e.magnitude,o),l=Math.max(Sr(e.phase.illuminatedFraction,0,1),.01)*Math.PI*(mo/an)**2,h=new se(...c.map(f=>Math.min(zt.BRIGHTEST_RELATIVE,f/l))),u=`${e.phase.phaseFraction<.5}:${Math.round(Sr(e.phase.illuminatedFraction,0,1)*500)}`;let d=this.bodyMeshes.get(i);if(d instanceof to)d.userData.phaseKey!==u&&(d.material.map?.dispose(),d.material.map=hg(e.phase),d.userData.phaseKey=u),d.material.color.copy(h);else{this.disposeMesh(d),d=new to(new ul({map:hg(e.phase),color:h,fog:!1})),d.userData.phaseKey=u;const f=mo*2;d.scale.set(f,f,1),this.celestialGroup.add(d),this.bodyMeshes.set(i,d)}d.position.set(n,s,a),this.setHitArea(i,n,s,a,mo),this.setGlare(i,n,s,a,c,mo/an*(180/Math.PI))}bentLight(e,t,i=gE){const[n,s,a]=this.arrivingIlluminance(e,t,1),o=Math.max(s,1e-30);return{scale:s/i,tint:[n/o,1,a/o]}}static litBySky(e,t){return zt.litScratch.setRGB(e.r*t[0],e.g*t[1],e.b*t[2])}static litScratch=new se;pointToPixel(){const e=Math.max(1,this.renderer.getDrawingBufferSize(this.pointScratch).y),t=(this.camera.fov*Math.PI/180/e)**2;return Math.min(1,st.CONE_SOLID_ANGLE/t)}pointScratch=new xe;static POINT_VEIL_HOLD_DEG=.25;static BRIGHTEST_RELATIVE=6e4;arrivingIlluminance(e,t,i){const n=this.air.transmittanceFromSpace(this.siteElevationM+this.observerElevationM,e.altitudeDeg),s=dt.illuminanceOf(t)*i*this.relativeScale;return[n[0]*s,n[1]*s,n[2]*s]}static unitLuminance(e){const t=Fn.luminanceOf([e.r,e.g,e.b]);return t>0?[e.r/t,e.g/t,e.b/t]:[1,1,1]}setHitArea(e,t,i,n,s){let a=this.hitAreas.get(e);if(!a){const c=new ul({transparent:!0,opacity:0,depthTest:!1,depthWrite:!1,fog:!1});a=new to(c),this.celestialGroup.add(a),this.hitAreas.set(e,a)}a.position.set(t,i,n);const o=s*mE;a.scale.set(o,o,1)}disposeHitArea(e){const t=this.hitAreas.get(e);t&&(t.removeFromParent(),t.material.dispose(),this.hitAreas.delete(e))}setGlare(e,t,i,n,s,a,o=0){if(Pi.radiusDeg(Pi.K*Math.max(...s))<=Math.max(a,o)){this.disposeGlare(e);return}let c=this.glareSprites.get(e);c||(c=new Pi(`veil:${e}`),this.celestialGroup.add(c.mesh),this.glareSprites.set(e,c)),c.shine({x:t,y:i,z:n},s,a,o)}disposeGlare(e){const t=this.glareSprites.get(e);t&&(t.mesh.removeFromParent(),t.dispose(),this.glareSprites.delete(e))}buildComet(e,t){const i=e&&`comet:${e.id}`;if(!e||!i||e.magnitude>t){this.disposeComet();return}this.cometKey&&this.cometKey!==i&&this.disposeComet();const n=bo(e.magnitude,t),s=Zh(n);this.cometKey=i,this.setBodyMesh(i,e.position,uu*(.5+.5*n),new se(s,s,s),e.magnitude),this.cometTail||(this.cometTail=new on(an),this.celestialGroup.add(this.cometTail.object)),this.cometTail.set(e.position,e.tailEnd,n)}buildIceHalos(e,t){this.iceHalos||(this.iceHalos=new Ci,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:Jc},0);return}const s=this.lowerCloudCover(),a=ft.deckLitUntilDeg(ft.DECK_HEIGHT_M),o=e.altitudeDeg>-a?e:t,c=this.bentLight(o,o===e?Lt.SUN_MAGNITUDE:t.magnitude),l=ft.strength(i,s,o.altitudeDeg,a)*c.scale,{x:h,y:u,z:d}=li(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??Jc},n?.iceCrystalAlignment??this.weather.iceCrystalAlignment??Dv)}buildRainbow(e,t){this.rainbow||(this.rainbow=new Da,this.celestialGroup.add(this.rainbow.object));const i=this.weather.precipitationType==="rain"?this.weather.precipitationIntensity*(this.weather.precipitationAmount??1):0,n=e.altitudeDeg>0,s=n?e:t,a=this.lowerCloudCover(),o=this.bentLight(s,n?Lt.SUN_MAGNITUDE:t.magnitude,vE),c=rn.strength(i,a,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}=li(s.altitudeDeg,s.azimuthDeg,1);this.rainbow.update({x:l,y:h,z:u},c,o.tint,n)}buildSkyGlow(e,t){if(!e.frame){this.skyGlow?.hide();return}this.skyGlow||(this.skyGlow=new $s,this.skyGlow.onReady=()=>this.render(),this.celestialGroup.add(this.skyGlow.object));const{date:i,observer:n}=e.frame,s=In.galactic(i,n),a=zt.directionOf(s.centre),o=zt.directionOf(s.rotation),c=zt.directionOf(s.pole),l=new Ye().set(a.x,a.y,a.z,o.x,o.y,o.z,c.x,c.y,c.z),h=zt.directionOf(In.eclipticPole(i,n)),u=zt.directionOf(e.sun),d=u.clone().addScaledVector(h,-u.dot(h)).normalize();this.skyGlow.update({galactic:l,eclipticPole:h,sunLongitude:d,sunDirection:u,sunAltitudeDeg:e.sun.altitudeDeg,moon:{direction:zt.directionOf(e.moon),altitudeDeg:e.moon.altitudeDeg,phaseAngleDeg:Me.phaseAngleOf(e.moon.phase.illuminatedFraction)},lightPollution:this.lightPollution,skyColor:new R(t[0],t[1],t[2])})}static directionOf(e){const{x:t,y:i,z:n}=li(e.altitudeDeg,e.azimuthDeg,1);return new R(t,i,n).normalize()}buildNovae(e,t){const i=new Set;for(const n of e){if(n.magnitude>t)continue;const s=`nova:${n.id}`;i.add(s);const a=bo(n.magnitude,t),o=Zh(a);this.setBodyMesh(s,n.position,uu*(.5+.5*a),new se(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(e,t){const i=new Set(["sun","moon",...this.cometKey?[this.cometKey]:[],...this.novaKeys]);for(const n of e){if(n.magnitude>t)continue;i.add(n.body);const s=bo(n.magnitude,t),a=Zh(s),o=$E[n.body]??new se(1,1,1),c=new se(o.r*a,o.g*a,o.b*a),l=uu*(.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(e,t){if(this.namedStars=[],!e||e.catalog.count===0){this.disposeStarTiers(),this.syncAnimationLoop();return}const{catalog:i,date:n,observer:s}=e,a=new Ln(n,s),o=bu(1337),c=[],l=this.siteElevationM+this.observerElevationM;for(let h=0;h<i.count;h++){const u=i.mag[h];if(u>t)break;const{altitudeDeg:d,azimuthDeg:f}=a.position(i.ra[h],i.dec[h]);if(d<Hm)continue;const{x:p,y:v,z:m}=li(d,f,hu);c.push({x:p,y:v,z:m,brightness:bo(u,t),illuminance:this.air.transmittanceFromSpace(l,d).map(g=>g*dt.illuminanceOf(u)),phase:o()*Math.PI*2,speedFactor:.7+o()*.6})}for(const h of p5){if(h.mag>t)continue;const{altitudeDeg:u,azimuthDeg:d}=a.position(h.raHours,h.decDeg);if(u<Hm)continue;const{x:f,y:p,z:v}=li(u,d,hu);this.namedStars.push({star:h,direction:new R(f,p,v).normalize(),altitudeDeg:u})}this.starTiers=Co.map((h,u)=>{const d=c.filter(S=>I1(S.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((S,w)=>{f[w*3]=S.x,f[w*3+1]=S.y,f[w*3+2]=S.z,p[w]=S.brightness,v.set(S.illuminance,w*3),m[w]=S.phase,g[w]=S.speedFactor});const _=new ot;_.setAttribute("position",new tt(f,3)),_.setAttribute("seed",new tt(m.map(S=>S/(2*Math.PI)),1));const b=new tt(new Float32Array(d.length*3),3);_.setAttribute("color",b);let M=this.starTiers[u]?.points;return M?(M.geometry.dispose(),M.geometry=_):(M=new xs(_,st.material(h.size)),st.track(M),this.celestialGroup.add(M)),{points:M,colorAttribute:b,brightness:p,illuminance:v,phase:m,speedFactor:g}}),this.starColoursRelative=Number.NaN,this.updateTwinkle(this.twinkleSeconds),this.startTwinkle()}twinkleSeconds=0;starColoursRelative=Number.NaN;updateTwinkle(e){st.setTime(e);const t=this.relativeScale;if(t!==this.starColoursRelative){this.starColoursRelative=t;for(const i of this.starTiers){const n=i.colorAttribute.array;for(let s=0;s<i.brightness.length;s++)n[s*3]=i.illuminance[s*3]*t,n[s*3+1]=i.illuminance[s*3+1]*t,n[s*3+2]=i.illuminance[s*3+2]*t;i.colorAttribute.needsUpdate=!0}}}buildClouds(){if(this.cloudRendering==="volume"||this.weather.cloudLayers!==void 0){this.layeredClouds||(this.disposeCloudSystem(),this.layeredClouds=new Rr(this.celestialGroup,du,this.cloudRendering)),this.disposeCirrus(),this.layeredClouds.hostHalo(this.iceHalos),this.layeredClouds.update(this.weather,this.observerElevationM+1.6),this.layeredClouds.setOffsets(this.cloudOffsetM,this.cloudLayerOffsetsM),this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor);return}const e=this.lowerCloudCover();if(e<=0){this.disposeCloudSystem();return}const t=this.weather.cloudDarkness,i=new se(ga[0]+(mu[0]-ga[0])*t,ga[1]+(mu[1]-ga[1])*t,ga[2]+(mu[2]-ga[2])*t);if(this.cloudMesh&&this.cloudUniforms){this.cloudUniforms.coverage.value=e,this.cloudUniforms.baseColor.value.copy(i),this.syncCloudLayer(),this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor);return}this.disposeCloudSystem();const{material:n,uniforms:s}=Td(i,e,Math.abs(this.cloudLayerOffset()));this.cloudMaterial=n,this.cloudUniforms=s,s.fieldOffset.value.copy(this.cloudFieldOffset),this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor);const a=Rd(du);this.cloudMesh=new De(a,n),this.faceCloudDeck(this.cloudMesh,this.cloudLayerOffset()),this.celestialGroup.add(this.cloudMesh)}lowerCloudCover(){return this.weather.cloudLayers?1-this.weather.cloudLayers.filter(e=>e.type!=="cirrus").reduce((e,t)=>e*(1-t.coverage),1):this.weather.lowerCloudCover??this.weather.cloudCover}highCloudCover(){return this.weather.cloudLayers?1-this.weather.cloudLayers.filter(e=>e.type==="cirrus").reduce((e,t)=>e*(1-t.coverage),1):this.weather.highCloudCover}buildCirrus(){const e=this.weather.highCloudCover??0;if(this.layeredClouds||e<=0){this.disposeCirrus();return}if(this.cirrusMesh&&this.cirrusUniforms){this.cirrusUniforms.coverage.value=e,this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor);return}const{material:t,uniforms:i}=Td(new se(...ga),e,Jc,1);this.cirrusMaterial=t,this.cirrusUniforms=i,i.fieldOffset.value.copy(this.cloudFieldOffset),this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor),this.cirrusMesh=new De(Rd(du*1.04),t),this.cirrusMesh.renderOrder=$m-1,this.celestialGroup.add(this.cirrusMesh)}disposeCirrus(){this.cirrusMesh&&(this.cirrusMesh.removeFromParent(),this.cirrusMesh.geometry.dispose()),this.cirrusMaterial?.dispose(),this.cirrusMesh=void 0,this.cirrusMaterial=void 0,this.cirrusUniforms=void 0}syncCloudLayer(){this.layeredClouds?.update(this.weather,this.observerElevationM+1.6);const e=this.cloudLayerOffset();this.cloudUniforms&&(this.cloudUniforms.layerHeight.value=Math.abs(e)),this.cloudMesh&&this.faceCloudDeck(this.cloudMesh,e)}faceCloudDeck(e,t){const i=t<0;e.scale.y=i?-1:1,e.renderOrder=i?Rr.deckOrder(!0,0,1):$m}cloudLayerOffset(){const t=((this.weather.cloudBaseM??s0)-this.observerElevationM)*fu;return Math.sign(t||1)*Math.max(Math.abs(t),IE)}updateCloudLighting(e,t){const i=[this.cloudUniforms,this.cirrusUniforms].filter(u=>u!==void 0);if(i.length===0&&!this.layeredClouds)return;const n=this.cloudBeamDirection,[s,a,o]=this.cloudBeam.map(u=>u/Math.PI),c=this.lightningLevel*yu*this.relativeScale/Math.PI,l=new se(t[0]+qn.r*c,t[1]+qn.g*c,t[2]+qn.b*c);this.layeredClouds?.setLighting(n.clone(),new se(s,a,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,a*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(e){return kE(e,this.weather.precipitationIntensity,this.weather.precipitationAmount??1)}updatePrecipitationDensity(){const e=[[this.rainSystem?.points,Mu],[this.rainSplashSystem?.points,va],[this.precipitationPoints,this.weather.precipitationType==="none"||this.weather.precipitationType==="rain"?void 0:gu[this.weather.precipitationType].poolSize]];for(const[t,i]of e)t&&i!==void 0&&t.geometry.setDrawRange(0,this.precipitationCount(i));this.rainSystem&&(this.rainSystem.uniforms.uSpeedStreak.value=jm(xu(this.weather.precipitationIntensity)))}buildPrecipitation(){this.disposePrecipitationPoints(),this.disposeRain();const e=this.weather.precipitationType;if(e==="none")return;if(e==="rain"){this.buildRain();return}const t=gu[e],i=t.poolSize,n=bu(9001),s=new Float32Array(i*3),a=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 b=0;b<i;b++){const M=n()*Math.PI*2,S=n()*t.radiusM;s[b*3]=Math.cos(M)*S,s[b*3+1]=vr+n()*(t.topYM-vr),s[b*3+2]=Math.sin(M)*S,a[b]=n()*Math.PI*2,o[b]=.7+n()*.6,c[b]=.6+n()*.8,l[b]=.4+n()*1.2}const v=new ot;v.setAttribute("position",new tt(s,3)),v.setDrawRange(0,this.precipitationCount(i));const m={uSize:{value:t.size},uScale:{value:.5*this.renderer.domElement.height},uOpacity:{value:t.opacity},uColor:{value:t.color.clone()},uHazeColor:{value:new se(...this.baseFogColor)},uTexture:{value:KE(e)},uNearFocusDistance:{value:ig},uHazeDistance:{value:t.radiusM*ng}},g=new ct({uniforms:m,vertexShader:tA,fragmentShader:iA,transparent:!0,depthWrite:!1});this.precipitationUniforms=m;const _=new xs(v,g);_.renderOrder=pu,this.scene.add(_),this.precipitationPoints=_,this.precipitationPositions=s,this.precipitationPhase=a,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(e,t){if(!this.precipitationPoints||!this.precipitationPositions||!this.precipitationPhase||!this.precipitationSpeedJitter)return;this.precipitationUniforms?.uHazeColor.value.setRGB(...this.baseFogColor);const i=this.weather.precipitationType;if(i==="none"||i==="rain")return;const n=gu[i];if(this.precipitationUniforms?.uColor.value.copy(zt.litBySky(n.color,this.baseFogColor)),t<=0)return;const s=this.weather.windDirectionDeg*$i,a=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,_=i==="snow"&&u&&d,b=i==="hail"&&f&&p&&v&&m&&g;for(let M=0,S=0;M<c.length;M+=3,S++){if(b&&f[S]>0){if(f[S]-=t,f[S]<=0){const x=Math.random()*Math.PI*2,A=Math.sqrt(Math.random())*n.radiusM;c[M]=Math.cos(x)*A,c[M+1]=n.topYM,c[M+2]=Math.sin(x)*A,f[S]=0}else{const x=1-f[S]/v[S];c[M+1]=vr+Math.sin(Math.PI*x)*p[S],c[M]=el(c[M]+(a+m[S])*t,n.radiusM),c[M+2]=el(c[M+2]+(o+g[S])*t,n.radiusM)}continue}let w=0,T=0;if(_){const x=BE*u[S],A=HE*d[S];w=Math.sin(e*x*Math.PI*2+l[S])*A,T=Math.sin(e*x*Math.PI*2+l[S]+Math.PI/2)*A}if(c[M]+=(a+w)*t,c[M+1]-=n.fallSpeedMPerS*h[S]*t,c[M+2]+=(o+T)*t,c[M]=el(c[M],n.radiusM),c[M+2]=el(c[M+2],n.radiusM),c[M+1]<vr){if(b){p[S]=cg*(.2+Math.random()*1.6),v[S]=GE*(.5+Math.random()),f[S]=v[S];const C=Math.random()*Math.PI*2,I=VE*(p[S]/cg);m[S]=Math.cos(C)*I,g[S]=Math.sin(C)*I,c[M+1]=vr;continue}const x=Math.random()*Math.PI*2,A=Math.sqrt(Math.random())*n.radiusM;c[M]=Math.cos(x)*A,c[M+1]=n.topYM,c[M+2]=Math.sin(x)*A}}this.precipitationPoints.geometry.attributes.position.needsUpdate=!0}buildRain(){const e=xu(this.weather.precipitationIntensity);this.rainSystem=C5({count:Mu,radiusM:go,heightM:PE,bottomYM:Km,overallSpeed:LE,color:Jm.clone(),opacity:.85,visibleCount:this.precipitationCount(Mu),speedStreak:jm(e),pixelSize:ag,seed:9001,nearFocusDistanceM:ig,hazeDistanceM:go*ng,hazeColor:new se(...this.baseFogColor)}),this.rainLastVerticalFacing=-1,this.syncRainSlant(),this.rainSystem.points.renderOrder=pu,this.scene.add(this.rainSystem.points),this.buildRainSplashes()}buildRainSplashes(){const e=bu(4242),t=new Float32Array(va*3),i=new Float32Array(va),n=new Float32Array(va),s=new Float32Array(va);for(let h=0;h<va;h++){const u=e()*Math.PI*2,d=Math.sqrt(e())*go;t[h*3]=Math.cos(u)*d,t[h*3+1]=Km,t[h*3+2]=Math.sin(u)*d,n[h]=lg(Qm,eg),i[h]=e()*n[h],s[h]=i[h]/n[h]}const a=new ot;a.setAttribute("position",new tt(t,3));const o=new tt(s,1);a.setAttribute("aLife",o),a.setDrawRange(0,this.precipitationCount(va));const c=new ct({uniforms:{uMaxSize:{value:UE},uScale:{value:.5*this.renderer.domElement.height},uColor:{value:tg.clone()},uTexture:{value:jE()}},vertexShader:QE,fragmentShader:eA,transparent:!0,depthWrite:!1}),l=new xs(a,c);l.renderOrder=pu,this.scene.add(l),this.rainSplashSystem={points:l,positions:t,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 e=this.rainSystem;if(!e)return;const t=this.weather.windDirectionDeg*$i;e.uniforms.uDropVelocity.value.set(Math.sin(t)*this.weather.windSpeed,-xu(this.weather.precipitationIntensity),-Math.cos(t)*this.weather.windSpeed);const i=this.renderer.getSize(this.rainViewportSize);e.uniforms.uAspect.value=i.x/Math.max(i.y,1)}updateRain(e){const t=this.rainSystem;if(!t)return;t.uniforms.uTime.value+=e,t.uniforms.uHazeColor.value.setRGB(...this.baseFogColor),t.uniforms.uColor.value.copy(zt.litBySky(Jm,this.baseFogColor));const i=this.rainSplashSystem?.points.material?.uniforms?.uColor;i&&i.value.copy(zt.litBySky(tg,this.baseFogColor));const n=this.weather.windDirectionDeg*$i,s=Math.sin(n)*this.weather.windSpeed,a=-Math.cos(n)*this.weather.windSpeed,o=go,c=h=>(h%(o*2)+o*3)%(o*2)-o;t.uniforms.uWindOffset.value.set(c(t.uniforms.uWindOffset.value.x+s*e),c(t.uniforms.uWindOffset.value.y+a*e)),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=rg+(1-rg)*(1-l),u=og+(1-og)*(1-l);t.uniforms.uUvSquash.value=u,t.uniforms.uPixelSize.value=ag*h*(.5+.5*u)}this.updateRainSplashes(e)}updateRainSplashes(e){const t=this.rainSplashSystem;if(!t||e<=0)return;const{positions:i,life:n,duration:s,lifeAttribute:a}=t,o=a.array;for(let c=0,l=0;c<i.length;c+=3,l++){if(n[l]+=e,n[l]>=s[l]){const h=Math.random()*Math.PI*2,u=Math.sqrt(Math.random())*go;i[c]=Math.cos(h)*u,i[c+2]=Math.sin(h)*u,s[l]=lg(Qm,eg),n[l]=0}o[l]=n[l]/s[l]}t.points.geometry.attributes.position.needsUpdate=!0,a.needsUpdate=!0}setLightning(e){this.lightningFlashes=e}updateLightning(e){let t,i=0;if(this.lightningArmed)for(const c of this.lightningFlashes){if(c.t>e)break;const l=di.brightnessAt(c,e);l>i&&(t=c,i=l)}const n=t?Math.min(1,Math.max(.1,(YE/t.distanceM)**2)):0,s=i*n*(t?.cloudToGround?1:.6);if(s===this.lightningLevel&&!t?.cloudToGround)return;if(this.lightningLevel=s,this.scene.fog){const c=this.scene.fog,l=s*yu*this.relativeScale/Math.PI;c.color.setRGB(this.airlight[0]+qn.r*l,this.airlight[1]+qn.g*l,this.airlight[2]+qn.b*l)}const a=this.skyMesh?.material?.color;if(a){const c=s*qE;a.setRGB(1+c*qn.r,1+c*qn.g,1+c*qn.b)}if(this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor),this.lightningLight.intensity=s*yu*this.relativeScale,t){const{x:c,y:l,z:h}=li(25,t.azimuthDeg,an);this.lightningLight.position.set(c,l,h)}this.lightningBolt||(this.lightningBolt=new Ks(an*.95),this.celestialGroup.add(this.lightningBolt.object));const o=this.weather.cloudBaseM??1500;this.lightningBolt.set(t,i,o),this.render()}buildCompassLabels(){this.compassSprites=bE.map(e=>{const t=La.point(e,this.compassPoints),i=new ul({map:nA(t),depthTest:!1,fog:!1}),n=new to(i),{x:s,y:a,z:o}=li(0,e,Wm);return n.position.set(s,a,o),n.scale.set(Qc,Qc,1),n.renderOrder=wE,n.layers.set(Um),n.visible=this.compassHovered||this.compassForced,this.celestialGroup.add(n),n}),this.updateCompassScale()}updateCompassScale(){const e=this.camera.fov*Math.PI/360,t=Xm*Math.PI/360,i=Qc*Math.tan(e)/Math.tan(t);for(const n of this.compassSprites)n.scale.set(i,i,1)}disposeCompassLabels(){for(const e of this.compassSprites)e.removeFromParent(),e.material.map?.dispose(),e.material.dispose();this.compassSprites=[]}disposeStarTiers(){for(const e of this.starTiers)this.disposeMesh(e.points);this.starTiers=[]}disposeMesh(e){if(!e)return;e.removeFromParent(),"geometry"in e&&e.geometry.dispose();const t=e.material;for(const i of Array.isArray(t)?t:[t]){const n=i.map;n&&n.dispose(),i.dispose()}}}const $i=Math.PI/180;function Sr(r,e,t){return Math.max(e,Math.min(t,r))}function lg(r,e){return r+Math.random()*(e-r)}function el(r,e){return(r%(e*2)+e*3)%(e*2)-e}let tl,il;function KE(r){switch(r){case"snow":return ZE();case"hail":return JE()}}function ZE(){if(tl)return tl;const r=64,e=document.createElement("canvas");e.width=r,e.height=r;const t=e.getContext("2d"),i=t.createRadialGradient(r/2,r/2,0,r/2,r/2,r/2);return i.addColorStop(0,"rgba(255,255,255,0.95)"),i.addColorStop(.5,"rgba(255,255,255,0.55)"),i.addColorStop(1,"rgba(255,255,255,0)"),t.fillStyle=i,t.fillRect(0,0,r,r),tl=new Ls(e),tl}function JE(){if(il)return il;const r=64,e=document.createElement("canvas");e.width=r,e.height=r;const t=e.getContext("2d"),i=t.createRadialGradient(r/2,r/2,0,r/2,r/2,r/2);return i.addColorStop(0,"rgba(255,255,255,1)"),i.addColorStop(.55,"rgba(255,255,255,0.95)"),i.addColorStop(.8,"rgba(255,255,255,0.4)"),i.addColorStop(1,"rgba(255,255,255,0)"),t.fillStyle=i,t.fillRect(0,0,r,r),il=new Ls(e),il}let nl;function jE(){if(nl)return nl;const r=64,e=document.createElement("canvas");e.width=r,e.height=r;const t=e.getContext("2d"),i=t.createRadialGradient(r/2,r/2,0,r/2,r/2,r/2);return i.addColorStop(0,"rgba(255,255,255,0)"),i.addColorStop(.4,"rgba(255,255,255,0)"),i.addColorStop(.6,"rgba(255,255,255,0.9)"),i.addColorStop(.8,"rgba(255,255,255,0.25)"),i.addColorStop(1,"rgba(255,255,255,0)"),t.fillStyle=i,t.fillRect(0,0,r,r),nl=new Ls(e),nl}const QE=`
|
|
7715
7715
|
uniform float uMaxSize;
|
|
7716
7716
|
uniform float uScale;
|
|
7717
7717
|
attribute float aLife;
|
|
@@ -7777,5 +7777,5 @@ void main() {
|
|
|
7777
7777
|
gl_FragColor = vec4(color, tex.a * uOpacity * (1.0 - blur * 0.5));
|
|
7778
7778
|
}
|
|
7779
7779
|
`;function hg(r){const t=document.createElement("canvas");t.width=128,t.height=128;const i=t.getContext("2d"),n=128/2-2,s=128/2,a=128/2,o="#010101",c="#f4f1e2";i.fillStyle=o,i.beginPath(),i.arc(s,a,n,0,Math.PI*2),i.fill();const l=Sr(r.illuminatedFraction,0,1),h=r.phaseFraction<.5,u=n*Math.abs(1-2*l),d=l<.5;return i.save(),i.beginPath(),i.arc(s,a,n,0,Math.PI*2),i.clip(),i.fillStyle=c,i.beginPath(),h?(i.arc(s,a,n,-Math.PI/2,Math.PI/2,!1),i.ellipse(s,a,u,n,0,Math.PI/2,-Math.PI/2,d)):(i.arc(s,a,n,Math.PI/2,-Math.PI/2,!1),i.ellipse(s,a,u,n,0,-Math.PI/2,Math.PI/2,d)),i.fill(),i.restore(),new Ls(t)}function nA(r){const e=document.createElement("canvas");e.width=128,e.height=128;const t=e.getContext("2d");return t.fillStyle="rgba(0, 0, 0, 0.55)",t.beginPath(),t.arc(64,64,60,0,Math.PI*2),t.fill(),t.fillStyle="#ffffff",t.font="bold 52px sans-serif",t.textAlign="center",t.textBaseline="middle",t.fillText(r,64,68),new Ls(e)}function bu(r){let e=r;return function(){e|=0,e=e+1831565813|0;let i=Math.imul(e^e>>>15,1|e);return i=i+Math.imul(i^i>>>7,61|i)^i,((i^i>>>14)>>>0)/4294967296}}const _u=7.5,Su=9;class Kn{static cache=new Map;static load(e){let t=Kn.cache.get(e);return t||(t=fetch(e).then(i=>i.arrayBuffer()).then(i=>Kn.parse(i)),Kn.cache.set(e,t)),t}static upTo(e,t){const i=e.filter((a,o)=>o===0||e[o-1].magnitudeLimit<t);if(i.length<=1)return Kn.load(e[0].url);const n=i.map(a=>a.url).join(`
|
|
7780
|
-
`);let s=Kn.cache.get(n);return s||(s=Promise.all(i.map(a=>Kn.load(a.url))).then(a=>a.reduce((o,c)=>Kn.concat(o,c))),Kn.cache.set(n,s)),s}static parse(e){const t=e.byteLength/(4*Float32Array.BYTES_PER_ELEMENT),i=t*Float32Array.BYTES_PER_ELEMENT;return{count:t,ra:new Float32Array(e,0*i,t),dec:new Float32Array(e,1*i,t),mag:new Float32Array(e,2*i,t),ci:new Float32Array(e,3*i,t)}}static concat(e,t){const i=(n,s)=>{const a=new Float32Array(n.length+s.length);return a.set(n,0),a.set(s,n.length),a};return{count:e.count+t.count,ra:i(e.ra,t.ra),dec:i(e.dec,t.dec),mag:i(e.mag,t.mag),ci:i(e.ci,t.ci)}}}class Hl{constructor(e){this.names=e}body(e,t){return this.names?.bodies[e]??t}star(e){return this.names?.stars[e.name]??e.name}comet(e){return this.names?.comets[e.id]??e.name}nova(e){return this.names?.novae[e.id]??e.name}satelliteClass(e){return this.names?.satelliteClasses[e.id]??e.name}shower(e){return this.names?.showers[e.id]??e.name}lightRig(e){return this.names?.lightRigs[e.id]??e.name}instrument(e){return this.names?.instruments[e.id]??e.name}decorKind(e,t){return this.names?.decorKinds[e]??t}point(e){return La.point(e,this.names?.compassPoints)}towards(e){return La.towards(e,this.names)}}const sA=new URL(""+new URL("rain-BvWZrB9h.ogg",import.meta.url).href,import.meta.url).href,aA=new URL(""+new URL("wind-BjklexY7.ogg",import.meta.url).href,import.meta.url).href,rA=new URL(""+new URL("thunder-DA48qs_v.wav",import.meta.url).href,import.meta.url).href,oA=20,cA=1;class lA{context;buffers=new Map;ambientSource;ambientGain;ambientKey="none";ambientToken=0;ambientVolume=0;windSource;windGain;windActive=!1;windToken=0;windVolume=0;paused=!0;requested={type:"none",intensity:0,windSpeed:0};resume(){if(!this.context){if(typeof AudioContext>"u")return;try{this.context=new AudioContext}catch(e){console.warn("WeatherAudio: Web Audio unavailable, weather sounds disabled:",e);return}}this.context.state==="suspended"&&this.context.resume()}setAmbient(e,t,i){if(this.requested={type:e,intensity:t,windSpeed:i},!this.context)return;this.paused&&(e="none",t=0,i=0);const n=e==="rain"||e==="hail"?e:"none";if(this.ambientVolume=n==="hail"?Math.min(1,t*1.3+.2):n==="rain"?t:0,n!==this.ambientKey){this.ambientKey=n;const a=++this.ambientToken;this.stopSource(this.ambientSource,this.ambientGain),this.ambientSource=void 0,this.ambientGain=void 0,n!=="none"&&this.startLoop(sA,this.ambientVolume).then(o=>this.applyIfCurrent(o,a,()=>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/oA,1);const s=i>cA;if(s!==this.windActive){this.windActive=s;const a=++this.windToken;this.stopSource(this.windSource,this.windGain),this.windSource=void 0,this.windGain=void 0,s&&this.startLoop(aA,this.windVolume).then(o=>this.applyIfCurrent(o,a,()=>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(e){if(e===this.paused)return;this.paused=e;const{type:t,intensity:i,windSpeed:n}=this.requested;this.setAmbient(t,i,n)}playThunder(){!this.context||this.paused||this.playOneShot(rA,.9)}dispose(){this.ambientToken++,this.windToken++,this.stopSource(this.ambientSource,this.ambientGain),this.stopSource(this.windSource,this.windGain),this.ambientSource=void 0,this.ambientGain=void 0,this.windSource=void 0,this.windGain=void 0,this.context?.close(),this.context=void 0,this.buffers.clear()}applyIfCurrent(e,t,i,n){if(t!==i()){e?.source.stop();return}n(e)}async startLoop(e,t){const i=this.context;if(i)try{const n=await this.getBuffer(e),s=i.createBufferSource();s.buffer=n,s.loop=!0;const a=i.createGain();return a.gain.value=t,s.connect(a).connect(i.destination),s.start(),{source:s,gain:a}}catch(n){console.warn("Weather ambient sound failed to load, staying silent:",n);return}}async playOneShot(e,t){const i=this.context;if(i)try{const n=await this.getBuffer(e),s=i.createBufferSource();s.buffer=n;const a=i.createGain();a.gain.value=t,s.connect(a).connect(i.destination),s.start()}catch(n){console.warn("Thunder sound failed to load:",n)}}async getBuffer(e){const t=this.context;if(!t)throw new Error("WeatherAudio: AudioContext not ready — resume() must be called first");let i=this.buffers.get(e);return i||(i=fetch(e).then(n=>{if(!n.ok)throw new Error(`Audio fetch failed (${n.status}): ${e}`);return n.arrayBuffer()}).then(n=>t.decodeAudioData(n)),this.buffers.set(e,i)),i}stopSource(e,t){try{e?.stop()}catch{}e?.disconnect(),t?.disconnect()}}class Ms{constructor(e){this.elements=e;const{eccentricity:t,perihelionAu:i}=e,[n,s]=this.perifocalAxes(),a=Math.sqrt(Ms.SUN_GM_AU3_PER_DAY2*(1+t)/i);this.perihelionPosition=this.scale(n,i),this.perihelionVelocity=this.scale(s,a),this.inverseSemiMajorAxis=(1-t)/i}static SUN_GM_AU3_PER_DAY2=.0002959122082855911;static MAX_ITERATIONS=200;perihelionPosition;perihelionVelocity;inverseSemiMajorAxis;positionAt(e){const t=e-this.elements.perihelionJd,i=this.universalAnomaly(t),n=this.inverseSemiMajorAxis*i*i,s=this.elements.perihelionAu,a=1-i*i/s*Ms.stumpffC(n),o=t-i*i*i/Math.sqrt(Ms.SUN_GM_AU3_PER_DAY2)*Ms.stumpffS(n);return{x:a*this.perihelionPosition.x+o*this.perihelionVelocity.x,y:a*this.perihelionPosition.y+o*this.perihelionVelocity.y,z:a*this.perihelionPosition.z+o*this.perihelionVelocity.z}}heliocentricDistanceAt(e){const t=this.positionAt(e);return Math.hypot(t.x,t.y,t.z)}universalAnomaly(e){if(e===0)return 0;const t=Math.sign(e),i=Math.sqrt(Ms.SUN_GM_AU3_PER_DAY2)*Math.abs(e),n=o=>{const c=this.inverseSemiMajorAxis*o*o,l=this.elements.perihelionAu;return(1-this.inverseSemiMajorAxis*l)*o*o*o*Ms.stumpffS(c)+l*o};let s=Math.max(1,i/this.elements.perihelionAu);for(;n(s)<i;)s*=2;let a=0;for(let o=0;o<Ms.MAX_ITERATIONS&&s-a>1e-13*Math.max(1,s);o++){const c=(a+s)/2;n(c)<i?a=c:s=c}return t*(a+s)/2}perifocalAxes(){const e=this.elements.ascendingNodeDeg*Math.PI/180,t=this.elements.argumentOfPerihelionDeg*Math.PI/180,i=this.elements.inclinationDeg*Math.PI/180,n=Math.cos(e),s=Math.sin(e),a=Math.cos(t),o=Math.sin(t),c=Math.cos(i),l=Math.sin(i);return[{x:n*a-s*o*c,y:s*a+n*o*c,z:o*l},{x:-n*o-s*a*c,y:-s*o+n*a*c,z:a*l}]}scale(e,t){return{x:e.x*t,y:e.y*t,z:e.z*t}}static stumpffC(e){if(Math.abs(e)<1e-6)return 1/2-e/24+e*e/720;if(e>0)return(1-Math.cos(Math.sqrt(e)))/e;const t=Math.sqrt(-e);return(Math.cosh(t)-1)/-e}static stumpffS(e){if(Math.abs(e)<1e-6)return 1/6-e/120+e*e/5040;if(e>0){const i=Math.sqrt(e);return(i-Math.sin(i))/(i*i*i)}const t=Math.sqrt(-e);return(Math.sinh(t)-t)/(t*t*t)}}const cv=[{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 hA{static WINDOW_DAYS=200;static TWILIGHT_ELONGATION_DEG=15;static LIGHT_SPEED_AU_PER_DAY=173.144632674;static orbits=new Map;static aroundDate(e){const t=this.julianDayOf(e);return cv.filter(i=>Math.abs(t-i.orbit.perihelionJd)<=this.WINDOW_DAYS)}static brightestAt(e,t){return this.aroundDate(e).map(i=>this.appearanceOf(i,e,t)).sort((i,n)=>i.magnitude-n.magnitude)[0]}static appearanceOf(e,t,i){const n=Xt(t),s=this.earthPositionAt(n),a=this.apparentPositionOf(e,2451545+n.tt,s),o=this.subtract(a,s),c=this.length(a),l=this.length(o),h=this.tailEndAt(e,a,s,c,n,t,i),u=this.horizontalOf(o,n,t,i);return{apparition:e,position:u,...h,heliocentricDistanceAu:c,earthDistanceAu:l,elongationDeg:this.angleBetween(o,this.subtract({x:0,y:0,z:0},s)),magnitude:this.magnitudeAt(e,c,l)}}static magnitudeAt(e,t,i){const n=e.absoluteMagnitude+5*Math.log10(i)+2.5*e.activityExponent*Math.log10(t);return Math.max(n,e.peakMagnitude)}static tailEndAt(e,t,i,n,s,a,o){if(e.tailLengthAu===void 0)return{};const c=1+e.tailLengthAu/n,l=this.subtract({x:t.x*c,y:t.y*c,z:t.z*c},i),h=this.subtract(t,i);return{tailEnd:this.horizontalOf(l,s,a,o),tailLengthDeg:this.angleBetween(h,l)}}static apparentPositionOf(e,t,i){const n=this.orbitOf(e);let s=n.positionAt(t);for(let a=0;a<2;a++){const o=this.length(this.subtract(s,i))/this.LIGHT_SPEED_AU_PER_DAY;s=n.positionAt(t-o)}return s}static horizontalOf(e,t,i,n){const s=Lr(r5(),new Ot(e.x,e.y,e.z,t)),a=Lr($1(t),s),o=zw(t,new W0(n.lat,n.lng,n.elevationM)),c=new Ot(a.x-o.x,a.y-o.y,a.z-o.z,t),l=Y0(c);return q0(l.ra,l.dec,i,n)}static earthPositionAt(e){return Lr(a5(),na(we.Earth,e))}static julianDayOf(e){return 2451545+Xt(e).tt}static orbitOf(e){const t=this.orbits.get(e.id);if(t)return t;const i=new Ms(e.orbit);return this.orbits.set(e.id,i),i}static subtract(e,t){return{x:e.x-t.x,y:e.y-t.y,z:e.z-t.z}}static length(e){return Math.hypot(e.x,e.y,e.z)}static angleBetween(e,t){const i=(e.x*t.x+e.y*t.y+e.z*t.z)/(this.length(e)*this.length(t)||1);return Math.acos(Math.min(1,Math.max(-1,i)))*180/Math.PI}}const wu=[{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 ug{static UNIX_EPOCH_JD=24405875e-1;static aroundDate(e){const t=this.julianDayOf(e);return wu.filter(i=>this.magnitudeAt(i,t)!==void 0)}static appearancesAt(e,t){const i=this.julianDayOf(e),n=[];for(const s of wu){const a=this.magnitudeAt(s,i);a!==void 0&&n.push({outburst:s,position:Ln.ofJ2000(s.raHours,s.decDeg,e,t),magnitude:a})}return n.sort((s,a)=>s.magnitude-a.magnitude)}static brightestAt(e,t){return this.appearancesAt(e,t)[0]}static byId(e){return wu.find(t=>t.id===e)}static magnitudeAt(e,t){const i=e.lightCurve,n=t-e.startJd;if(i.length===0||n<i[0][0]||n>i[i.length-1][0])return;let s=1;for(;s<i.length-1&&i[s][0]<n;)s++;const[a,o]=i[s-1]??i[0],[c,l]=i[s]??i[0];if(c===a)return o;const h=Math.min(1,Math.max(0,(n-a)/(c-a)));return o+h*(l-o)}static julianDayOf(e){return e.getTime()/864e5+this.UNIX_EPOCH_JD}}const uA=[{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}],Gl=6.5;class Eu{static activeAt(e){return uA.flatMap(t=>{const i=this.nearness(t,e);return i<=0?[]:[{shower:t,zhr:t.peakZhr*i,nearness:i}]})}static nearness(e,t){const i=this.dayOfYear(t),n=this.dayOfYear(this.asDate(e.start)),s=this.dayOfYear(this.asDate(e.peak)),a=this.dayOfYear(this.asDate(e.end)),o=this.wrappedDelta(i,s),c=this.wrappedDelta(s,n),l=this.wrappedDelta(a,s);return o<0?o<-c?0:1+o/c:o>0?o>l?0:1-o/l:1}static observedRatePerHour(e,t,i,n=Gl){if(t<=0)return 0;const s=Gl-n;return e*Math.sin(t*Math.PI/180)/Math.pow(i,s)}static radiantPosition(e,t,i){return Ln.ofJ2000(e.radiantRaHours,e.radiantDecDeg,t,i)}static dayOfYear(e){const t=Date.UTC(e.getUTCFullYear(),0,1);return Math.floor((Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate())-t)/864e5)+1}static asDate(e){return new Date(Date.UTC(2001,e.month-1,e.day))}static wrappedDelta(e,t){const i=e-t;return i>182?i-365:i<-182?i+365:i}}class Jt{static QUIET_RATE_PER_HOUR=2;static APEX_RATE_PER_HOUR=8;static POPULATION_INDEX=3;static apexPosition(e,t){const i=Xt(e),n=new th(0,Uw(e).elon-90,1),s=Lr(c5(i),X0(n,i)),a=Y0(s);return q0(a.ra,a.dec,e,t)}static observedRatePerHour(e,t=Gl){const i=Jt.APEX_RATE_PER_HOUR*Math.max(0,Math.sin(e*Math.PI/180)),n=Gl-t;return(Jt.QUIET_RATE_PER_HOUR+i)/Math.pow(Jt.POPULATION_INDEX,n)}static schedule(e){const t=new sh(e.seed^1542469173);return Oa.schedule(e).map(i=>{const n=Jt.toCartesian({altitudeDeg:Math.asin(t.next())*180/Math.PI,azimuthDeg:t.between(0,360)}),s=i.fromRadiantDeg*Math.PI/180,a=Jt.turnAround(n,t.between(0,360)),o={x:n.x*Math.cos(s)+a.x*Math.sin(s),y:n.y*Math.cos(s)+a.y*Math.sin(s),z:n.z*Math.cos(s)+a.z*Math.sin(s)};return{...i,radiant:Jt.toHorizontal(o),bearingDeg:Jt.bearingFrom(o,n)}})}static turnAround(e,t){const[i,n]=Jt.basisAround(e),s=t*Math.PI/180;return{x:i.x*Math.cos(s)+n.x*Math.sin(s),y:i.y*Math.cos(s)+n.y*Math.sin(s),z:i.z*Math.cos(s)+n.z*Math.sin(s)}}static bearingFrom(e,t){const[i,n]=Jt.basisAround(e),s=e.x*t.x+e.y*t.y+e.z*t.z,a=Jt.normalise({x:t.x-e.x*s,y:t.y-e.y*s,z:t.z-e.z*s});return(Math.atan2(a.x*n.x+a.y*n.y+a.z*n.z,a.x*i.x+a.y*i.y+a.z*i.z)*180/Math.PI%360+360)%360}static basisAround(e){const t=Math.abs(e.y)<.9?{x:0,y:1,z:0}:{x:1,y:0,z:0},i=Jt.normalise(Jt.cross(e,t));return[i,Jt.normalise(Jt.cross(e,i))]}static toHorizontal(e){const t=Math.hypot(e.x,e.y,e.z)||1;return{altitudeDeg:Math.asin(Math.min(1,Math.max(-1,e.y/t)))*180/Math.PI,azimuthDeg:(Math.atan2(e.x,-e.z)*180/Math.PI%360+360)%360}}static appearanceOf(e){const t=Jt.toCartesian(e.radiant??{altitudeDeg:90,azimuthDeg:0}),i=Jt.turnAround(t,e.bearingDeg),n=e.fromRadiantDeg*Math.PI/180;return Jt.toHorizontal({x:t.x*Math.cos(n)+i.x*Math.sin(n),y:t.y*Math.cos(n)+i.y*Math.sin(n),z:t.z*Math.cos(n)+i.z*Math.sin(n)})}static toCartesian(e){const t=e.altitudeDeg*Math.PI/180,i=e.azimuthDeg*Math.PI/180,n=Math.cos(t);return{x:n*Math.sin(i),y:Math.sin(t),z:-n*Math.cos(i)}}static cross(e,t){return{x:e.y*t.z-e.z*t.y,y:e.z*t.x-e.x*t.z,z:e.x*t.y-e.y*t.x}}static normalise(e){const t=Math.hypot(e.x,e.y,e.z)||1;return{x:e.x/t,y:e.y/t,z:e.z/t}}static TYPICAL_VELOCITY_KM_S=40}const dg="https://ufoathome.org/tle/index.json";class Ii{static MAX_ELEMENT_AGE_DAYS=7;static DAY_MS=864e5;fetchImpl;indexUrls;index;files=new Map;constructor(e={}){this.fetchImpl=e.fetchImpl??fetch.bind(globalThis),this.indexUrls=e.indexUrls??Ii.defaultIndexUrls()}static defaultIndexUrls(){const e=[];return typeof location<"u"&&/^https?:$/.test(location.protocol)&&e.push(new URL("/tle/index.json",location.href).href),e.includes(dg)||e.push(dg),e}static FIRST_SNAPSHOT="2021-02-22";async covers(e){const t=Date.parse(`${Ii.FIRST_SNAPSHOT}T00:00:00Z`)-Ii.MAX_ELEMENT_AGE_DAYS*Ii.DAY_MS;if(e.getTime()<t)return!1;const i=await this.loadIndex();return i?Object.values(i.index.kinds).some(n=>e.getTime()>=Date.parse(n.from)-Ii.MAX_ELEMENT_AGE_DAYS*Ii.DAY_MS&&e.getTime()<=Date.parse(n.to)+Ii.MAX_ELEMENT_AGE_DAYS*Ii.DAY_MS):!1}async at(e){const t=await this.loadIndex();if(!t)return;const{index:i,base:n}=t,s=[],a=[];for(const o of Object.keys(i.kinds)){const c=await this.kindAt(o,e,i,n);s.push(...c),a.push(this.coverageOf(o,e,i,c.length>0))}return{objects:s,coverage:a,credit:i.credit,creditUrl:i.source}}async kindAt(e,t,i,n){const s=t.getTime(),a=i.binDays*Ii.DAY_MS,o=Math.floor(s/a),c=s-o*a<a/2?o-1:o+1,l=new Set(i.kinds[e].bins),h=[o,c].map(v=>new Date(v*a).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-${e}.json`,n).href),...h.map(v=>this.binary(new URL(`${e}/${v}.bin`,n).href))]),f=new Map;for(const v of d)for(const m of Ii.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)/Ii.DAY_MS;if(m>Ii.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:e,launch:g.launch,stdMag:g.stdMag,elements:v,ageDays:m})}return p}coverageOf(e,t,i,n){const{from:s,to:a}=i.kinds[e],o=t.getTime(),c=Ii.MAX_ELEMENT_AGE_DAYS*Ii.DAY_MS,l=n?"covered":o<Date.parse(s)-c?"before":o>Date.parse(a)+c?"after":"gap";return{kind:e,status:l,from:s,to:a}}static decode(e,t){const i=new DataView(e),n=[];for(let s=0;s+t<=e.byteLength;s+=t)n.push({norad:i.getUint32(s,!0),epochMs:i.getFloat64(s+4,!0),bstar:i.getFloat32(s+12,!0),inclinationDeg:i.getFloat32(s+16,!0),raanDeg:i.getFloat32(s+20,!0),eccentricity:i.getFloat32(s+24,!0),argOfPerigeeDeg:i.getFloat32(s+28,!0),meanAnomalyDeg:i.getFloat32(s+32,!0),meanMotion:i.getFloat64(s+36,!0)});return n}loadIndex(){return this.index??=(async()=>{for(const e of this.indexUrls)try{const t=await this.fetchImpl(e);if(!t.ok)continue;return{index:await t.json(),base:e}}catch{}})(),this.index}json(e){return this.cached(e,async t=>t.json())}binary(e){return this.cached(e,async t=>t.arrayBuffer())}cached(e,t){let i=this.files.get(e);return i||(i=this.fetchImpl(e).then(n=>{if(!n.ok)throw new Error(`${e}: ${n.status}`);return t(n)}),i.catch(()=>this.files.delete(e)),this.files.set(e,i)),i}}class dA{lowerM;upperM;add(e,t){if(!(e<=0)){if(t.behindM!==void 0){const i=Et.sizeMAt(t.behindM,e);this.lowerM=this.lowerM===void 0?i:Math.max(this.lowerM,i)}if(t.inFrontM!==void 0){const i=Et.sizeMAt(t.inFrontM,e);this.upperM=this.upperM===void 0?i:Math.min(this.upperM,i)}}}get sizeRange(){return{minM:this.lowerM,maxM:this.upperM}}get empty(){return this.lowerM===void 0&&this.upperM===void 0}get contradictory(){return this.lowerM!==void 0&&this.upperM!==void 0&&this.lowerM>this.upperM}distanceRangeAt(e){return e<=0?{}:{minM:this.lowerM===void 0?void 0:Et.distanceMAt(this.lowerM,e),maxM:this.upperM===void 0?void 0:Et.distanceMAt(this.upperM,e)}}clear(){this.lowerM=void 0,this.upperM=void 0}}class Fa{static DEG_PER_SECOND=360/86164.0905;static degOver(e){return Math.max(0,e)*Fa.DEG_PER_SECOND}static instants(e,t){if(!(t>0))return 1;const i=Fa.degOver(e)/t;return i<1?1:Math.min(Fa.MAX_INSTANTS,Math.max(2,Math.ceil(i)))}static MAX_INSTANTS=64}class zi{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 Fa.DEG_PER_SECOND*3600}static graspOf(e,t={}){const i=t.exposureSeconds??e.exposureSeconds,n=t.fNumber??e.fNumber;if(i===void 0||n===void 0||!(i>0)||!(n>0))return zi.EYE;const s=t.focalLengthMm??e.frame?.focalLengthMm??zi.UNKNOWN_CAMERA_FOCAL_MM,a=s/n,o=zi.resolutionArcsec(e,s,a);return{apertureMm:a,exposureSeconds:Math.min(i,zi.trailLimitedSeconds(o)),resolutionArcsec:o}}static resolutionArcsec(e,t,i){const s=(e.detailUm??zi.UNKNOWN_CAMERA_DETAIL_UM)/1e3/t*zi.ARCSEC_PER_RADIAN,a=1.22*zi.WAVELENGTH_M/(i/1e3)*zi.ARCSEC_PER_RADIAN;return Math.max(s,a)}static trailLimitedSeconds(e){return e/zi.skyDriftArcsecPerSecond}static gainOverEye(e,t={}){const i=zi.graspOf(e,t),n=zi.EYE,s=(i.apertureMm/n.apertureMm)**2,a=i.exposureSeconds/n.exposureSeconds,o=(n.resolutionArcsec/i.resolutionArcsec)**2;return 1.25*Math.log10(s*a*o)}static gainFor(e,t){const i=t.fieldOfViewDeg===void 0?void 0:si.focalLengthMmFor(e,t.fieldOfViewDeg);return zi.gainOverEye(e,{fNumber:t.fNumber,focalLengthMm:i,exposureSeconds:t.exposureSeconds})}}const fg=111320,vo=Math.PI/180,fA=1.02,pA=1;class Oo{static of(e,t){const i=Oo.sightings(e,t);if(i.length<2)return;const n=Oo.baseline(i);if(!n)return;const{near:s,far:a,closedM:o}=n,c=Math.tan(a.widthDeg/2*vo)===0?0:Math.tan(s.widthDeg/2*vo)/Math.tan(a.widthDeg/2*vo);if(c<fA)return;const l=o/(c-1),h=Et.sizeMAt(l,s.widthDeg),u=i.map(d=>({t:d.t,m:Et.distanceMAt(h,d.widthDeg)}));return{widthM:h,distanceM:u,nearestM:Math.min(...u.map(d=>d.m)),fromT:a.t,toT:s.t,closedM:o}}static sightings(e,t){return e.timeline.allKeyframes.flatMap(i=>{const n=i.shapes.find(o=>o.sourceId===t)?.shape,s=n?.angular?.widthDeg,a=jt(e,i.t);return s===void 0||s<=0||a?.lat===void 0||a.lng===void 0?[]:[{t:i.t,widthDeg:s,lat:a.lat,lng:a.lng,sightAzimuthDeg:n?.aim?.azimuthDeg??a.headingDeg}]}).sort((i,n)=>i.t-n.t)}static baseline(e){let t;for(const i of e)for(const n of e){if(i.t>=n.t)continue;const s=Oo.closedAlongSight(i,n),[a,o,c]=s>=0?[n,i,s]:[i,n,-s];c<pA||a.widthDeg<=o.widthDeg||(!t||c>t.closedM)&&(t={near:a,far:o,closedM:c})}return t}static closedAlongSight(e,t){const i=(t.lat-e.lat)*fg,n=(t.lng-e.lng)*fg*Math.cos(e.lat*vo),s=(e.sightAzimuthDeg??0)*vo;return i*Math.cos(s)+n*Math.sin(s)}}class ki{static CONVENTIONAL_M=5;static NEAREST_M=.2;static MARGIN=1.1;static resolve(e){if(e.statedM!==void 0&&e.statedM>0)return{distanceM:ki.atLeastNearest(e.statedM),basis:"stated"};if(e.hypothesisM!==void 0&&e.hypothesisM>0)return{distanceM:ki.atLeastNearest(e.hypothesisM),basis:"hypothesis"};if(e.derivedM!==void 0&&e.derivedM>0)return{distanceM:ki.atLeastNearest(e.derivedM),basis:"derived"};const t=ki.largest(e.range?.minM,e.crossing?.behindM),i=ki.smallest(e.range?.maxM,e.crossing?.inFrontM),n=t===void 0?void 0:t*ki.MARGIN,s=i===void 0?void 0:i/ki.MARGIN;return n!==void 0&&s!==void 0?{distanceM:ki.atLeastNearest(n<=s?Math.sqrt(n*s):n),basis:"bounded"}:n!==void 0?{distanceM:ki.atLeastNearest(n),basis:"bounded"}:s!==void 0&&s<ki.CONVENTIONAL_M?{distanceM:ki.atLeastNearest(s),basis:"bounded"}:{distanceM:ki.CONVENTIONAL_M,basis:"conventional"}}static atLeastNearest(e){return Math.max(ki.NEAREST_M,e)}static largest(...e){const t=e.filter(i=>i!==void 0&&i>0);return t.length===0?void 0:Math.max(...t)}static smallest(...e){const t=e.filter(i=>i!==void 0&&i>0);return t.length===0?void 0:Math.min(...t)}}const Au=Math.PI/180;class Qe{constructor(e,t,i){this.body=e,this.ground=t;const n=[...e.track].sort((s,a)=>s.t-a.t);this.keys=this.place(n,i);for(const s of n)Qe.collect(this.motionKeys,s.t,s.motions),Qe.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(e,t,i){for(const[n,s]of Object.entries(i??{})){const a=e.get(n)??[];a.push({t,value:s}),e.set(n,a)}}motionsAt(e){return Qe.channelsAt(this.motionKeys,e,0)}lightsAt(e){return this.lightKeys.size>0?Qe.channelsAt(this.lightKeys,e,void 0):void 0}static channelsAt(e,t,i){const n={};for(const[s,a]of e){let o=a.length-1;for(;o>=0&&a[o].t>t;)o--;if(o<0){i!==void 0&&(n[s]=i);continue}const c=a[o],l=a[Math.min(o+1,a.length-1)],h=l===c||l.t===c.t?0:Math.min(1,(t-c.t)/(l.t-c.t));n[s]=Qe.lerp(c.value,l.value,h)}return n}static eyeOf(e,t,i){const n=jt(e,0),s=jt(e,t),o=n?.lat!==void 0&&n.lng!==void 0&&s?.lat!==void 0&&s.lng!==void 0?ni(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)+Qe.EYE_HEIGHT_M+(s?.elevationM??0),headingDeg:s?.headingDeg}}static lineOfSightMeetsGround(e,t,i,n){const s=Qe.directionOf(t,i),a=l=>e.upM+s.upM*l-n.heightAt(e.eastM+s.eastM*l,e.northM+s.northM*l);let o=0,c=0;for(;c<Qe.MAX_RANGE_M;){if(c=o+Math.max(.5,o*.01),a(c)<=0){for(let l=0;l<30;l++){const h=(o+c)/2;a(h)<=0?c=h:o=h}return c}o=c}}static directionOf(e,t){const i=e*Au,n=t*Au;return{eastM:Math.sin(i)*Math.cos(n),northM:Math.cos(i)*Math.cos(n),upM:Math.sin(n)}}at(e){const t=this.keys;if(t.length===0||e<t[0].t)return;let i=t.length-1;for(;i>0&&t[i].t>e;)i--;const n=t[i];if(!n.present)return;const s=t[Math.min(i+1,t.length-1)],a=s===n||s.t===n.t?0:Math.min(1,(e-n.t)/(s.t-n.t)),o=Qe.lerp(n.eastM,s.eastM,a),c=Qe.lerp(n.northM,s.northM,a),l={widthM:Qe.lerp(n.sizeM.widthM,s.sizeM.widthM,a),lengthM:Qe.lerp(n.sizeM.lengthM,s.sizeM.lengthM,a),heightM:Qe.lerp(n.sizeM.heightM,s.sizeM.heightM,a)},h={headingDeg:Qe.lerpAngle(n.attitude.headingDeg,s.attitude.headingDeg,a),pitchDeg:Qe.lerp(n.attitude.pitchDeg,s.attitude.pitchDeg,a),rollDeg:Qe.lerp(n.attitude.rollDeg,s.attitude.rollDeg,a)};let u;if("aboveGroundM"in n.vertical&&"aboveGroundM"in s.vertical){const d=Qe.lerp(n.vertical.aboveGroundM,s.vertical.aboveGroundM,a);u=this.groundUnderFootprint(o,c,l,h.headingDeg)+d+l.heightM/2}else u=Qe.lerp(this.centreUpOf(n),this.centreUpOf(s),a);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:(a<1?n:s).appearance.color,albedo:Qe.lerp(n.appearance.albedo,s.appearance.albedo,a),luminanceCdM2:Qe.lerp(n.appearance.luminanceCdM2,s.appearance.luminanceCdM2,a)},flame:Qe.flameBetween(n.flame,s.flame,a),motions:this.motionsAt(e),lights:this.lightsAt(e),throwsFlame:this.body.track.some(d=>d.flame!==void 0&&d.flame.luminanceCdM2>0)}}static flameBetween(e,t,i){if(!e||e.luminanceCdM2<=0)return i>=1&&t&&t.luminanceCdM2>0?t:void 0;const n=e,s=t??e,a={...i<1?n:s,lengthM:Qe.lerp(n.lengthM,s.lengthM,i),widthM:Qe.lerp(n.widthM,s.widthM,i),luminanceCdM2:Qe.lerp(n.luminanceCdM2,s.luminanceCdM2,i)};return a.luminanceCdM2>0?a:void 0}centreUpOf(e){return"upM"in e.vertical?e.vertical.upM:this.groundUnderFootprint(e.eastM,e.northM,e.sizeM,e.attitude.headingDeg)+e.vertical.aboveGroundM+e.sizeM.heightM/2}groundUnderFootprint(e,t,i,n){const s=n*Au,a={eastM:Math.cos(s),northM:-Math.sin(s)},o={eastM:Math.sin(s),northM:Math.cos(s)};let c=this.ground.heightAt(e,t);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(e+a.eastM*u+o.eastM*d,t+a.northM*u+o.northM*d))}return c}place(e,t){const i=[];let n;for(const s of e){const a=s.sizeM??n?.sizeM??Qe.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??Qe.DEFAULT_APPEARANCE.color,albedo:s.appearance?.albedo??n?.appearance.albedo??Qe.DEFAULT_APPEARANCE.albedo,luminanceCdM2:s.appearance?.luminanceCdM2??n?.appearance.luminanceCdM2??Qe.DEFAULT_APPEARANCE.luminanceCdM2},l=this.positionOf(s,t)??(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:a,attitude:o,appearance:c,flame:h,present:u},i.push(n)}return i}verticalOf(e){if(e.onGround)return{aboveGroundM:0};if(e.altitudeAboveGroundM!==void 0)return{aboveGroundM:e.altitudeAboveGroundM}}positionOf(e,t){if(e.eastM!==void 0&&e.northM!==void 0)return{eastM:e.eastM,northM:e.northM,vertical:this.verticalOf(e)??{aboveGroundM:0}};if(e.azimuthDeg===void 0||e.altitudeDeg===void 0)return;const i=t(e.t);if(!i)return;const n=e.distanceM??(e.onGround?Qe.lineOfSightMeetsGround(i,e.azimuthDeg,e.altitudeDeg,this.ground):void 0);if(n===void 0)return;const s=Qe.directionOf(e.azimuthDeg,e.altitudeDeg),a=i.eastM+s.eastM*n,o=i.northM+s.northM*n;return{eastM:a,northM:o,vertical:this.verticalOf(e)??{upM:i.upM+s.upM*n}}}static lerp(e,t,i){return e+(t-e)*i}static lerpAngle(e,t,i){const n=((t-e)%360+540)%360-180;return((e+n*i)%360+360)%360}}const pr=Math.PI/180,Mo=180/Math.PI;class Zt{constructor(e){this.timeline=e}static DIRECTION_TOLERANCE_DEG=1;static SIZE_TOLERANCE=1.5;static RINGS=12;static SEGMENTS=24;at(e,t,i,n){const s=[];for(const a of t){const o=Zt.projectionOf(a,i,n?.(a));if(o)for(const c of a.explains){const l=this.timeline.getInterpolatedShapeAt(e,c);!l||l.transparency>=1||s.push({...Zt.compare(c,a.id,{aim:l.aim,angular:l.angular},o),title:l.title})}}return s}static compare(e,t,i,n){const s=[],a=i.aim?Zt.separationDeg(i.aim,n.aim):void 0;if(a!==void 0){const l=Math.max(i.angular?.widthDeg??0,n.angular.widthDeg)/2;a>Math.max(Zt.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&&!Zt.withinSize(o)&&s.push("width"),c!==void 0&&!Zt.withinSize(c)&&s.push("height"),{sourceId:e,bodyId:t,stated:i,predicted:n,separationDeg:a,widthRatio:o,heightRatio:c,disagreements:s}}static projectionOf(e,t,i){const n=i&&i.length>0?i:Zt.outlineOf(e),s=i&&i.length>0?Zt.centreOf(i):e,a=Zt.normalized({eastM:s.eastM-t.eastM,northM:s.northM-t.northM,upM:s.upM-t.upM});if(!a)return;const o=Zt.normalized({eastM:a.northM,northM:-a.eastM,upM:0})??{eastM:1,northM:0,upM:0},c=Zt.cross(o,a);let l=1/0,h=-1/0,u=1/0,d=-1/0;for(const f of n){const p={eastM:f.eastM-t.eastM,northM:f.northM-t.northM,upM:f.upM-t.upM},v=Zt.dot(p,a);if(v<=0)return;const m=Math.atan2(Zt.dot(p,o),v),g=Math.atan2(Zt.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(a.eastM,a.northM)*Mo+360)%360,altitudeDeg:Math.asin(Math.max(-1,Math.min(1,a.upM)))*Mo},angular:{widthDeg:(h-l)*Mo,heightDeg:(d-u)*Mo}}}static centreOf(e){const t=i=>(Math.min(...e.map(n=>n[i]))+Math.max(...e.map(n=>n[i])))/2;return{eastM:t("eastM"),northM:t("northM"),upM:t("upM")}}static separationDeg(e,t){const i=e.altitudeDeg*pr,n=t.altitudeDeg*pr,s=Math.sin(i)*Math.sin(n)+Math.cos(i)*Math.cos(n)*Math.cos((e.azimuthDeg-t.azimuthDeg)*pr);return Math.acos(Math.max(-1,Math.min(1,s)))*Mo}static withinSize(e){return e<=Zt.SIZE_TOLERANCE&&e>=1/Zt.SIZE_TOLERANCE}static outlineOf(e){const t=e.sizeM.widthM/2,i=e.sizeM.lengthM/2,n=e.sizeM.heightM/2,s=[],a=e.model.url===void 0?e.model.id:void 0;if(a!==void 0&&a!=="box"&&av.includes(a))for(let u=0;u<=Zt.RINGS;u++){const d=u/Zt.RINGS*Math.PI;for(let f=0;f<Zt.SEGMENTS;f++){const p=f/Zt.SEGMENTS*2*Math.PI;s.push([t*Math.sin(d)*Math.cos(p),i*Math.sin(d)*Math.sin(p),n*Math.cos(d)])}}else for(const u of[-t,t])for(const d of[-i,i])for(const f of[-n,n])s.push([u,d,f]);const c=e.attitude.headingDeg*pr,l=e.attitude.pitchDeg*pr,h=e.attitude.rollDeg*pr;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:e.eastM+p*Math.cos(c)+m*Math.sin(c),northM:e.northM-p*Math.sin(c)+m*Math.cos(c),upM:e.upM+g}})}static dot(e,t){return e.eastM*t.eastM+e.northM*t.northM+e.upM*t.upM}static cross(e,t){return{eastM:e.northM*t.upM-e.upM*t.northM,northM:e.upM*t.eastM-e.eastM*t.upM,upM:e.eastM*t.northM-e.northM*t.eastM}}static normalized(e){const t=Math.hypot(e.eastM,e.northM,e.upM);return t>1e-9?{eastM:e.eastM/t,northM:e.northM/t,upM:e.upM/t}:void 0}}Ug();const mA={sun:"Sun",moon:"Moon",Venus:"Venus",Mars:"Mars",Jupiter:"Jupiter",Saturn:"Saturn"},gA="{name} — mag {mag}, {alt}° above the horizon",vA="{name} — satellite, mag {mag}, {height} km up",MA="satellites-change",lv="rr0-confrontation",xA="{name} — mag {mag}, {alt}° below the horizontal",Tu="Credits",pg="comet:",mg="nova:",yA={building:"Building",tree:"Tree",shrub:"Shrub",bridge:"Bridge",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,_A=new URL(""+new URL("stars-mag7.5-9-BLV2tFmZ.bin",import.meta.url).href,import.meta.url).href,SA=-18,wA={sun:{altitudeDeg:-3,azimuthDeg:180,magnitude:-26.7},moon:{altitudeDeg:-90,azimuthDeg:0,phase:{phaseFraction:0,illuminatedFraction:0},magnitude:-12.7},planets:[]},Ru={lat:0,lng:0,elevationM:0,headingDeg:void 0,pitchDeg:0,fovDeg:60};class Z0 extends HTMLElement{creditsButton;set ownCredits(e){this.creditsButton.hidden=!e}static get observedAttributes(){return["src","star-catalog-src","deep-star-catalog-src","show-compass","max-pixel-ratio",Es,As]}shadow;stageElement;frameElement;sceneCanvas;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 Ii;satellitesFor;satelliteRequest=0;satelliteStatus="none";satellites;satellitePassesMemo;starCatalogDepth=0;weatherAudio=new lA;vehicleAudio=new jv;vehicleHearing=new Ml;animateWhilePausedValue=!1;set animateWhilePaused(e){e!==this.animateWhilePausedValue&&(this.animateWhilePausedValue=e,this.syncAnimationsToPlayback())}get animateWhilePaused(){return this.animateWhilePausedValue}thunderTimeoutId;handleFullscreenChange=()=>this.resizeToStage();handlePointerMove=e=>{this.sceneRenderer.setCompassHovered(!0);const t=this.ufoElement.canvasElement,i=t.getBoundingClientRect();if(i.width===0||i.height===0)return;const n=(e.clientX-i.left)/i.width*t.width,s=(e.clientY-i.top)/i.height*t.height;if(this.ufoElement.hasVisibleShapeAt(n,s)){this.hoverTooltip.hidden=!0;return}const a=(e.clientX-i.left)/i.width*2-1,o=-((e.clientY-i.top)/i.height*2-1),c=this.naming,l=c.names,h=this.sceneRenderer.pickBodyAt(a,o);if(h){this.showHoverTooltip(e,this.bodyName(h));return}const u=this.sceneRenderer.pickDecorAt(a,o),d=u?this.ufoElement.sighting.decor.find(v=>v.id===u):void 0;if(d){this.showHoverTooltip(e,this.said.read(d.title)||c.decorKind(d.kind,yA[d.kind]));return}const f=this.sceneRenderer.pickSatelliteAt(a,o);if(f){this.showHoverTooltip(e,(l?.satelliteTooltip??vA).replace("{name}",f.name).replace("{mag}",f.magnitude.toLocaleString(void 0,{maximumFractionDigits:1})).replace("{height}",Math.round(f.heightKm).toLocaleString()));return}const p=this.sceneRenderer.pickStarAt(a,o);if(p){const v=p.star.mag,m=p.altitudeDeg,g=m<0?l?.starTooltipBelow??xA:l?.starTooltip??gA;this.showHoverTooltip(e,g.replace("{name}",c.star(p.star)).replace("{mag}",v.toLocaleString(void 0,{maximumFractionDigits:Math.abs(v)<1?2:1})).replace("{alt}",String(Math.round(Math.abs(m)))));return}this.hoverTooltip.hidden=!0};bodyName(e){const t=e.startsWith(pg)?e.slice(pg.length):void 0,i=t?cv.find(a=>a.id===t):void 0;if(i)return this.naming.comet(i);const n=e.startsWith(mg)?ug.byId(e.slice(mg.length)):void 0;if(n)return this.naming.nova(n);const s=mA[e];return s===void 0?e:this.naming.body(e,s)}get naming(){return this.sceneNaming}sceneNaming=new Hl;namesLanguage="en";async loadSceneNames(){const e=o0(Fr.preferencesFor(this),c0);if(e===this.namesLanguage)return;this.namesLanguage=e;const t=await Ag(e);e===this.namesLanguage&&this.applySceneNaming(new Hl(t))}applySceneNaming(e){this.sceneNaming=e;const t=e.names?.credits??Tu;this.creditsButton.title=t,this.creditsButton.setAttribute("aria-label",t),this.sceneRenderer.setCompassPoints(e.names?.compassPoints)}showHoverTooltip(e,t){this.hoverTooltip.textContent=t,this.hoverTooltip.hidden=!1;const i=this.stageElement.getBoundingClientRect();this.hoverTooltip.style.left=`${e.clientX-i.left+12}px`,this.hoverTooltip.style.top=`${e.clientY-i.top+12}px`}handlePointerLeave=()=>{this.hoverTooltip.hidden=!0,this.sceneRenderer.setCompassHovered(!1)};handleLightningFlash(e){clearTimeout(this.thunderTimeoutId),this.thunderTimeoutId=window.setTimeout(()=>this.weatherAudio.playThunder(),di.thunderDelayMs(e))}handleFirstInteraction=()=>{this.removeEventListener("pointerdown",this.handleFirstInteraction,!0),this.removeEventListener("keydown",this.handleFirstInteraction,!0),this.weatherAudio.resume(),this.vehicleAudio.resume(),this.setWeather(uf(this.ufoElement.sighting,this.lastTimeMs))};handleTimeUpdate=e=>{this.lastTimeMs=e.detail.time,this.syncAnimationsToPlayback(),this.updateAstronomy(this.lastTimeMs),this.ufoElement.playbackState==="playing"&&this.sceneRenderer.frame(performance.now())};syncAnimationsToPlayback(){const e=this.ufoElement.playbackState==="playing",t=e||this.animateWhilePaused;this.sceneRenderer.setAnimationsRunning(t,e),this.weatherAudio.setPaused(!t),this.vehicleAudio.setPaused(!t),t||clearTimeout(this.thunderTimeoutId)}constructor(){super(),this.shadow=this.attachShadow({mode:"open"});const e=document.createElement("template");e.innerHTML=`<style>${e2}</style>${Qv}`,this.shadow.appendChild(e.content.cloneNode(!0)),this.stageElement=this.shadow.getElementById("stage"),this.frameElement=this.shadow.getElementById("frame"),this.sceneCanvas=this.shadow.getElementById("scene-canvas"),this.sceneRenderer=new zt(this.sceneCanvas);const t=this.shadow.getElementById("scene-loader");this.sceneRenderer.onFirstFrameHold=s=>{t.hidden=!s},this.hoverTooltip=this.shadow.getElementById("hover-tooltip"),this.ufoElement=document.createElement(Lu),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"&&Dn.fill(n,this)}),this.creditsButton.title=Tu,this.creditsButton.setAttribute("aria-label",Tu),this.sceneRenderer.onMapSubjectBounds=s=>this.ufoElement.setMapSubjectBounds(s),this.ufoElement.addEventListener("timeupdate",this.handleTimeUpdate),this.ufoElement.addEventListener("referenceview",s=>this.applyReferenceView(s.detail)),this.ufoElement.canvasElement.addEventListener("pointermove",this.handlePointerMove),this.ufoElement.canvasElement.addEventListener("pointerleave",this.handlePointerLeave),this.addEventListener("pointerdown",this.handleFirstInteraction,!0),this.addEventListener("keydown",this.handleFirstInteraction,!0)}get said(){return this.saidTexts??=new On(Fr.preferencesFor(this))}saidTexts;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),document.addEventListener("fullscreenchange",this.handleFullscreenChange);const e=this.getAttribute("src");e&&this.loadFromSrc(e)}disconnectedCallback(){this.resizeObserver?.disconnect(),document.removeEventListener("fullscreenchange",this.handleFullscreenChange),this.sceneRenderer.stopTwinkle(),clearTimeout(this.thunderTimeoutId),this.weatherAudio.dispose(),this.vehicleAudio.dispose(),queueMicrotask(()=>{this.isConnected||this.sceneRenderer.releaseContext()})}attributeChangedCallback(e,t,i){if(e==="src"&&i&&i!==t&&this.isConnected&&this.loadFromSrc(i),(e==="star-catalog-src"||e==="deep-star-catalog-src")&&i!==t&&this.isConnected&&this.loadStars(),e==="show-compass"&&i!==t&&this.sceneRenderer.setShowCompass(this.hasAttribute("show-compass")),e==="max-pixel-ratio"&&i!==t){const n=Number(i);this.sceneRenderer.setMaxPixelRatio(Number.isFinite(n)&&n>0?n:Math.min(window.devicePixelRatio||1,2))}(e===Es||e===As)&&i!==t&&this.forwardPlayerAttributes()}forwardPlayerAttributes(){for(const e of[Es,As]){const t=this.getAttribute(e);t===null?this.ufoElement.removeAttribute(e):this.ufoElement.setAttribute(e,t)}}setCompassForced(e){this.sceneRenderer.setCompassForced(e)}lookToward(e){const t=jt(this.ufoElement.sighting,this.lastTimeMs);if(e.kind==="observer"||t?.lat===void 0||t.lng===void 0||t.headingDeg===void 0){this.setLookOffset(0,0);return}const{x:i,z:n}=ni(e.lat,e.lng,t.lat,t.lng);if(Math.hypot(i,n)<1)return this.setLookOffset(0,0);const s=(Math.atan2(i,-n)*180/Math.PI+360)%360;this.setLookOffset(((s-t.headingDeg)%360+540)%360-180,-t.pitchDeg)}setLookOffset(e,t){this.sceneRenderer.setLookOffset(e,t),this.ufoElement.setLookOffset(e,t),this.updateAstronomy(this.lastTimeMs)}setIndoorLook(e,t){this.sceneRenderer.setIndoorLook(e,t)}setCloudRendering(e){this.sceneRenderer.setCloudRendering(e)}setWeather(e){this.sceneRenderer.setWeather(e),this.weatherAudio.setAmbient(e.precipitationType,e.precipitationIntensity*(e.precipitationAmount??1),e.windSpeed)}pickCloudAt(e,t){return this.sceneRenderer.pickCloudAt(e,t)}cloudDirectionAt(e,t){return this.sceneRenderer.cloudDirectionAt(e,t)}pickDecorAt(e,t){return this.sceneRenderer.pickDecorAt(e,t)}bodyScreenBox(e){return this.sceneRenderer.bodyScreenBox(e)}pickPlacedBodyAt(e,t){return this.sceneRenderer.pickPlacedBodyAt(e,t)}resumeWeatherAudio(){this.weatherAudio.resume(),this.vehicleAudio.resume()}async loadFromSrc(e){const t=await Ao.json(e);this.documentUrl=new URL(e,location.href).href,this.sightingData=t}get documentUrl(){return this.sceneRenderer.documentUrl}set documentUrl(e){this.sceneRenderer.documentUrl=e}get sightingData(){return this.ufoElement.sightingData}set sightingData(e){this.ufoElement.sightingData=e,this.interpretationShown=this.inTheRound?this.ufoElement.sighting.interpretation:void 0,this.applyFrameFormat(),this.lastTimeMs=0,this.sceneRenderer.compileNextFrameOffThread(),this.updateAstronomy(0)}referenceAspect(e){return this.sceneRenderer.referenceAspect(e)}screenPointOf(e){return this.sceneRenderer.screenPointOf(e)}directionAt(e,t){return this.sceneRenderer.directionAt(e,t)}referenceFailedToLoad(e){return this.sceneRenderer.referenceFailedToLoad(e)}applyReferenceView(e){this.sceneRenderer.setReferencesShown(e.shown);for(const t of this.ufoElement.sighting.references)this.sceneRenderer.setReferenceView(t.id,{opacity:e.opacity})}get currentTerrainAttribution(){return this.sceneRenderer.currentTerrainAttribution}get currentRoadAttribution(){return this.sceneRenderer.currentRoadAttribution}setTerrainProviders(e){this.sceneRenderer.setTerrainProviders(e)}setDecorModelProvider(e){this.sceneRenderer.setDecorModelProvider(e)}get decorModelCredits(){return this.sceneRenderer.currentDecorModelCredits}applyFrameFormat(){const e=this.ufoElement.sighting.instrument,t=Et.CANVAS_HEIGHT_PX,i=si.frameWidthPx(e,t);this.frameElement.style.setProperty("--frame-aspect",`${i} / ${t}`)}resizeToStage(){const e=this.frameElement.getBoundingClientRect(),t=Math.max(1,Math.round(e.width)),i=Math.max(1,Math.round(e.height));this.sceneCanvas.width=t,this.sceneCanvas.height=i,this.sceneRenderer.resize(t,i)}async loadStars(){const e=[{magnitudeLimit:_u,url:this.getAttribute("star-catalog-src")??bA},{magnitudeLimit:Su,url:this.getAttribute("deep-star-catalog-src")??_A}],t=this.instrumentReach(),i=++this.starCatalogRequest;this.starCatalogDepth=t>_u?Su:_u;const n=await Kn.upTo(e,t);i===this.starCatalogRequest&&(this.starCatalog=n,this.sceneRenderer.compileNextFrameOffThread(),this.updateAstronomy(this.lastTimeMs))}ensureStarsDeepEnough(){!this.starCatalog||this.starCatalogDepth>=Su||this.instrumentReach()<=this.starCatalogDepth||this.loadStars()}instrumentReach(){const e=this.ufoElement.sighting,t=zi.gainFor(e.instrument,{fNumber:jt(e,0)?.fNumber,fieldOfViewDeg:ji.fovOf(e,0),exposureSeconds:e.exposure});return Ld(SA,t)}updateAstronomy(e){this.ensureStarsDeepEnough(),this.applySceneAt(e);const t=Pn.windowEndingAt(e,this.exposureSeconds()),i=t.seconds,n=this.degreesPerPixelAt(e),s=Fa.instants(i,n),a=Math.max(s,this.ufoElement.exposureTimes(e).length,Pn.instants(this.ufoElement.sighting.decor,jt(this.ufoElement.sighting,e)?.elevationM??0,t.fromMs,i,n));if(a<=1){this.sceneRenderer.setExposure(1);return}this.sceneRenderer.setExposure(a,o=>this.applySceneAt(t.fromMs+t.ms*o/(a-1),{sky:Math.floor(o*s/a)!==Math.floor((o-1)*s/a),stepMs:t.ms/a}))}exposureSeconds(){return this.ufoElement.sighting.exposure??0}degreesPerPixelAt(e){const t=this.sceneCanvas.height;return t<=0?0:ji.fovOf(this.ufoElement.sighting,e)/t}applySceneAt(e,t){const i=this.ufoElement.sighting;this.setWeather(uf(i,e)),this.sceneRenderer.setInstrument(i.instrument),this.sceneRenderer.setLightPollution(i.lightPollution),t||this.vehicleAudio.setVoices(this.vehicleHearing.at(i,e)),this.updateMeteorShower(i,e),this.updateLightning(i,e,t!==void 0),this.sceneRenderer.setDecor(i.decor);const n=jt(i,e);this.sceneRenderer.setReferences(i.references,n?.lat!==void 0&&n.lng!==void 0?{lat:n.lat,lng:n.lng}:void 0);const s=jt(i,0),a=mr(i,0),o=Object.fromEntries(gl(mr(i,e)).map(b=>[b.id,yf(e,i.weatherTrack,a,s,n,b.id)]));this.sceneRenderer.setCloudOffset(yf(e,i.weatherTrack,a,s,n),o),this.sceneRenderer.setObserverPose(n??Ru),this.sceneRenderer.setLensOptics(this.lensOpticsAt(e)),this.sceneRenderer.setInstrumentGain(zi.gainFor(i.instrument,{fNumber:n?.fNumber,fieldOfViewDeg:ji.fovOf(i,e),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(xt.bodyAt(i,e,this.ufoElement.steadyObserver)),this.sceneRenderer.updateDecorAnchoring(jt(i,0),n,e),this.placeBodiesAt(e,t===void 0),this.sceneRenderer.updateDecorLitState(e,t?.stepMs??0),this.sceneRenderer.setTerrainOrigin(n?.lat,n?.lng,()=>{this.placeBodiesAt(this.lastTimeMs,!0),this.sceneRenderer.render()}),this.sceneRenderer.setStatedRoads(i.roads),this.pushPhenomenaAt(e);const c=n?.lat??Ru.lat,l=n?.lng??Ru.lng,h=So(i.event.time??{},l,i.event.utcOffsetHours),u={lat:c,lng:l,elevationM:n?.elevationM??0};if(this.pushSatellitesAt(h,e,u),t&&!t.sky)return;if(!h){this.sceneRenderer.setAstronomy(wA);return}const d=new Date(h.getTime()+e),f=Math.max(1,Math.round(.25*this.degreesPerPixelAt(e)/Fa.DEG_PER_SECOND*1e3)),p=Math.max(1e-8,this.degreesPerPixelAt(e)*.1),v=`${Math.floor(d.getTime()/f)}|${Math.round(c/p)}|${Math.round(l/p)}|${Math.round(u.elevationM)}|${this.starCatalog?this.starCatalogDepth:0}`;if(v===this.lastSkyKey){this.sceneRenderer.render();return}this.lastSkyKey=v;const m={...Qh("Sun",d,u),magnitude:eu("Sun",d)},g={...Qh("Moon",d,u),phase:h5(d),magnitude:eu("Moon",d)},_=l5.map(b=>({body:b,position:Qh(b,d,u),magnitude:eu(b,d)}));this.sceneRenderer.setAstronomy({sun:m,moon:g,planets:_,comet:this.cometAt(d,u),novae:ug.appearancesAt(d,u).map(({outburst:b,position:M,magnitude:S})=>({id:b.id,position:M,magnitude:S})),stars:this.starCatalog?{catalog:this.starCatalog,date:d,observer:u}:void 0,frame:{date:d,observer:u}}),this.ufoElement.setSunAltitude(m.altitudeDeg)}pushSatellitesAt(e,t,i){if(this.ensureSatellites(e),!e||!this.satellites){this.sceneRenderer.setSatellites([]);return}const n=new Date(e.getTime()+t),s=[];for(const a of this.satellites.passes.positionsAt(n,i,-1))a.magnitude!==void 0&&s.push({norad:a.object.norad,name:a.object.name,position:{altitudeDeg:a.altitudeDeg,azimuthDeg:a.azimuthDeg},magnitude:a.magnitude,heightKm:a.heightKm});this.sceneRenderer.setSatellites(s)}ensureSatellites(e){const t=e?String(e.getTime()):"";if(t===this.satellitesFor)return;this.satellitesFor=t,this.satellites=void 0,this.satellitePassesMemo=void 0;const i=++this.satelliteRequest;if(!e){this.satelliteStatus="none";return}this.satelliteStatus="loading";const n=a=>{i===this.satelliteRequest&&(this.satelliteStatus=a,this.isConnected&&this.dispatchEvent(new CustomEvent(MA)))},s=Z0.tleArchive;(async()=>{if(!await s.covers(e))return n("outside");const[a,o]=await Promise.all([s.at(e),pi(()=>import("./SatellitePasses-Pfro2-0Z.js"),[],import.meta.url)]);if(i===this.satelliteRequest){if(!a)return n("unavailable");this.satellites={snapshot:a,passes:new o.SatellitePasses(a.objects)},n("ready"),this.isConnected&&this.updateAstronomy(this.lastTimeMs)}})().catch(()=>n("unavailable"))}get satelliteState(){const e=this.satellites?.snapshot;return{status:this.satelliteStatus,coverage:e?.coverage,credit:e?.credit,creditUrl:e?.creditUrl}}satellitePassesDuring(e){const t=this.satellites,i=this.ufoElement.sighting,n=jt(i,0),s=i.event.place?.[0],a=n?.lat??s?.lat,o=n?.lng??s?.lng;if(!t||a===void 0||o===void 0)return[];const c=So(i.event.time??{},o,i.event.utcOffsetHours);if(!c)return[];const l=Math.min(Math.max(e,0),4*36e5),h={lat:a,lng:o,elevationM:n?.elevationM??0},u=JSON.stringify([this.satellitesFor,c.getTime(),a,o,h.elevationM,l]);if(this.satellitePassesMemo?.key===u)return this.satellitePassesMemo.passes;const d=Math.max(10,Math.ceil(l/1e3/600)),f=t.passes.passesDuring(c,new Date(c.getTime()+l),h,d);return this.satellitePassesMemo={key:u,passes:f},f}cometAt(e,t){const i=hA.brightestAt(e,t);if(i)return{id:i.apparition.id,position:i.position,tailEnd:i.tailEnd,magnitude:i.magnitude}}pushPhenomenaAt(e){const t=this.ufoElement.sighting;t!==this.sizeEstimatesFor&&(this.sizeEstimates.clear(),this.distanceHypotheses.clear(),this.sizeEstimatesFor=t);const i=t.timeline,n=this.ufoElement.canvasElement,s=this.ufoElement.frameShiftPx,a=this.projectionAt(e),o=new Map,c=new Map,l=new Set;for(const p of i.sourceIds){const v=i.getInterpolatedShapeAt(e,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(Cn.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)},_=g!==void 0&&Math.abs(g.ndcX)<=1&&Math.abs(g.ndcY)<=1,b=_?this.sceneRenderer.decorDistancesAt(g.ndcX,g.ndcY,p):{};l.add(p),(_||v.aim)&&l.delete(p);const M=v.angular?.widthDeg??a.pxToDeg(v.bounds.width),S=this.sizeEstimateOf(p);S.add(M,b);const w=Oo.of(t,p);c.set(p,ki.resolve({hypothesisM:this.distanceHypotheses.get(p),derivedM:w&&M>0?Et.distanceMAt(w.widthM,M):void 0,range:S.distanceRangeAt(M),crossing:b}))}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 b=c.get(m);b&&c.set(p,{distanceM:b.distanceM*.999,basis:b.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=(jt(t,e)?.rollDeg??0)+xt.bodyAt(t,e,this.ufoElement.steadyObserver).rollDeg;this.sceneRenderer.setPhenomena(u,{projection:a,canvasWidthPx:n.width,canvasHeightPx:n.height,scale:Math.max(1,this.sceneCanvas.height/Math.max(1,n.height)),starPoints:si.starPointsOf(t.instrument),rollRad:f*Math.PI/180})}get interpretation(){return this.interpretationShown}set interpretation(e){this.interpretationShown=e,this.updateAstronomy(this.lastTimeMs)}get accountInTheRound(){return this.inTheRound}set accountInTheRound(e){this.inTheRound=e}get compareAccount(){return this.comparing}set compareAccount(e){this.comparing=e,this.updateAstronomy(this.lastTimeMs)}get confrontation(){return this.confrontationReadings}groundAlong(e,t,i){const n=this.sceneRenderer.bodyGround,s=Qe.eyeOf(this.ufoElement.sighting,i,n);return s?Qe.lineOfSightMeetsGround(s,e,t,n):void 0}bodyReading(e,t){const i=this.sceneRenderer.bodyGround,n=this.ufoElement.sighting,s=d=>Qe.eyeOf(n,d,i),a=new Qe(e,i,s).at(t),o=s(t);if(!a||!o)return;const c=a.eastM-o.eastM,l=a.northM-o.northM,h=a.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:a.eastM,northM:a.northM,aboveGroundM:a.upM-a.sizeM.heightM/2-i.heightAt(a.eastM,a.northM),sizeM:a.sizeM,attitude:a.attitude,appearance:a.appearance}}directionToBody(e,t){const i=this.sceneRenderer.bodyGround,n=this.ufoElement.sighting,s=p=>Qe.eyeOf(n,p,i),a=new Qe(e,i,s),o=a.at(t)?t:e.track[0]?.t,c=o===void 0?void 0:a.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(e,t){const i=this.interpretationShown,n=this.ufoElement.sighting;let s=[],a=[];const o=this.sceneRenderer.bodyGround,c=p=>Qe.eyeOf(n,p,o);i&&(s=i.bodies.map(p=>new Qe(p,o,c).at(e)).filter(p=>p!==void 0));const l=mr(n,e),h=l.windDirectionDeg*Math.PI/180,u={x:l.windSpeed*Math.sin(h),z:-l.windSpeed*Math.cos(h)};this.sceneRenderer.setBodies(s,e/1e3,i?.bodies.map(p=>p.id)??[],i?.smoke??[],u);const d=i&&this.comparing?c(e):void 0;if(d&&(a=new Zt(n.timeline).at(e,s,d,p=>p.outlineNode?this.sceneRenderer.bodyOutline?.(p.id,p.outlineNode):void 0)),this.confrontationReadings=a,!t)return;const f=JSON.stringify(a);f!==this.confrontationSignature&&(this.confrontationSignature=f,this.dispatchEvent(new CustomEvent(lv,{detail:a})))}setDistanceHypothesis(e,t){t===void 0||!(t>0)?this.distanceHypotheses.delete(e):this.distanceHypotheses.set(e,t),this.updateAstronomy(this.lastTimeMs)}depthOf(e){return this.depths.get(e)}sizeRangeOf(e){return this.sizeEstimateOf(e).sizeRange}distanceRangeAt(e,t){const i=this.ufoElement.sighting.timeline.getInterpolatedShapeAt(t,e);if(!i)return{};const n=i.angular?.widthDeg??this.projectionAt(t).pxToDeg(i.bounds.width);return this.sizeEstimateOf(e).distanceRangeAt(n)}sizeContradictory(e){return this.sizeEstimateOf(e).contradictory}updateMeteorShower(e,t){this.ensureMeteorSchedule(e),this.sceneRenderer.updateMeteors(t)}updateLightning(e,t,i){if(this.ensureLightningSchedule(e),this.sceneRenderer.updateLightning(t),i)return;const n=this.lastLightningT;if(this.lastLightningT=t,n===void 0||t<n||this.ufoElement.playbackState!=="playing")return;const s=this.lightningFlashes.filter(a=>a.t>n&&a.t<=t).pop();s&&mr(e,s.t).storm&&this.handleLightningFlash(s)}ensureLightningSchedule(e){const t=mr(e,0).precipitationIntensity,i=`${this.meteorInputsOf(e)}|${t}`;if(i===this.lightningScheduleFor)return;this.lightningScheduleFor=i;const n=e.event.time,s=e.event.place?.[0],a=n?.year!==void 0?So(n,s?.lng??0,e.event.utcOffsetHours):void 0,o=(e.event.durationSeconds??0)*1e3||e.timeline.duration||2e4,c=Math.round((a?.getTime()??0)/1e3)+Math.round((s?.lat??0)*1e3)+7;this.lightningFlashes=di.schedule({durationMs:o,seed:c,intensity:t}),this.sceneRenderer.setLightning(this.lightningFlashes)}ensureMeteorSchedule(e){const t=this.meteorInputsOf(e);t!==this.meteorScheduleFor&&(this.meteorScheduleFor=t,this.scheduleMeteors(e))}meteorInputsOf(e){const t=e.event.place?.[0],i=e.event.time;return JSON.stringify([t?.lat,t?.lng,i?.year,i?.month,i?.day,i?.hour,i?.minute,i?.second,e.event.utcOffsetHours,e.event.durationSeconds,e.timeline.duration])}scheduleMeteors(e){const t=e.event.place?.[0],i=e.event.time,n=t?.lat!==void 0&&t.lng!==void 0&&i?.year!==void 0?So(i,t.lng,e.event.utcOffsetHours):void 0;if(!n||t?.lat===void 0||t.lng===void 0){this.sceneRenderer.setMeteorShower([],0,0);return}const s={lat:t.lat,lng:t.lng,elevationM:0},a=(e.event.durationSeconds??0)*1e3||e.timeline.duration||2e4,o=Math.round(n.getTime()/1e3)+Math.round(t.lat*1e3),c=Jt.schedule({ratePerHour:Jt.observedRatePerHour(Jt.apexPosition(n,s).altitudeDeg),durationMs:a,velocityKmS:Jt.TYPICAL_VELOCITY_KM_S,seed:o}),l=Eu.activeAt(n).map(u=>{const d=Eu.radiantPosition(u.shower,n,s);return{entry:u,position:d,rate:Eu.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=Oa.schedule({ratePerHour:l.rate,durationMs:a,velocityKmS:l.entry.shower.velocityKmS,seed:o+1});this.sceneRenderer.setMeteorShower([...h,...c],l.position.altitudeDeg,l.position.azimuthDeg)}meteorByRank(e){this.ensureMeteorSchedule(this.ufoElement.sighting);const t=[...this.sceneRenderer.meteorSchedule].filter(s=>s.t+s.durationMs<=this.ufoElement.seekableDuration).sort((s,a)=>a.brightness-s.brightness);if(t.length===0)return;const i=t[e%t.length],n=this.sceneRenderer.meteorMidpoint(i);if(n)return{t:Math.round(i.t+i.durationMs*.45),...n}}lensOpticsAt(e){const t=this.ufoElement.sighting,i=t.instrument,n=i.frame,s=jt(t,e),a=s?.fNumber??i.fNumber;if(!n||a===void 0)return;const o=si.focalLengthMmFor(i,ji.fovOf(t,e));if(o!==void 0)return{focalLengthMm:o,fNumber:a,focusDistance:s?.focusDistanceM??0,frameHeightMm:n.heightMm}}projectionAt(e){const t=this.ufoElement.sighting;return Ss.of(t.instrument,Et.CANVAS_HEIGHT_PX,ji.fovOf(t,e))}sizeEstimateOf(e){let t=this.sizeEstimates.get(e);return t||(t=new dA,this.sizeEstimates.set(e,t)),t}}const n0="rr0-scene";function hv(){Ug(),customElements.get(n0)||customElements.define(n0,Z0)}const EA={color:"Color",transparency:"Transparency",halo:"Halo",blur:"Blur",brightness:"Brilliance",shapeTitle:"Name",utcOffset:"Time zone",cloudBase:"Cloud base",elevation:"Altitude",heightAboveGround:"Height above ground",duration:"Duration",placeName:"Place",latitude:"Latitude",longitude:"Longitude",heading:"Heading",pitch:"Tilt",roll:"Roll",sway:"Sway at rest",swayTitle:"How much the body holding the instrument moves the view when not walking: 1 for a person standing, 0 for a tripod. Blank: 1 (0 if the account says the observer was paralysed)",lightPollution:"Night sky",lightPollutionTitle:'The zenith of a moonless night at this place, in magnitudes per square arcsecond, as a Sky Quality Meter reads it or as the World Atlas of artificial sky brightness (Falchi et al. 2016, lightpollutionmap.info, "SQM") gives it. 22 is a natural sky; a suburb is about 19, a city centre 17. Blank: a natural sky',observationTime:"Observation start",observationEndTime:"Observation end",assessmentGroup:"Assessment",assessmentNames:{coverage:"Observer info"},assessmentVerdicts:{"hynek.nl":"NL — nocturnal light","hynek.dd":"DD — daylight disc","hynek.rv":"RV — radar-visual","hynek.ce1":"CE1 — close encounter","hynek.ce2":"CE2 — with a physical trace","hynek.ce3":"CE3 — with entities"},observerGroup:"Observer",observerId:"ID",observerTitle:"Title",observerLastName:"Last name",observerFirstNames:"First names",sightingId:"ID",tags:"Tags",cloudCover:"Cloud cover",highCloudCover:"Ice cloud (cirrus)",focalLength:"Focal length",fieldOfView:"Field of view",aperture:"Aperture",exposure:"Exposure",focusDistance:"Focused at",iceCrystalAlignment:"Crystal alignment",cloudDarkness:"Cloud darkness",precipitationType:"Precipitation",precipitationNone:"None",precipitationRain:"Rain",precipitationSnow:"Snow",precipitationHail:"Hail",precipitationIntensity:"Intensity",windDirection:"Wind direction",windSpeed:"Wind speed",storm:"Storm",cloudsGroup:"Clouds",precipitationGroup:"Precipitation",windGroup:"Wind",soundKind:"Sound",soundNone:"None (silent)",soundHum:"Hum",soundWhistle:"Whistle",soundRumble:"Rumble",soundCrackle:"Crackle",soundVolume:"Loudness",soundPitch:"Pitch",soundSrc:"Recording",instrument:"Observed through",decorAircraft:"Aircraft",decorEntity:"Being",decorAltitude:"Altitude",decorLights:"Lights",decorLightsNone:"none",decor:"Environment",decorBuilding:"Building",decorTree:"Tree",decorShrub:"Shrub",decorBridge:"Bridge",decorCrop:"Crop row",decorMound:"Stone heap",decorStreetlight:"Streetlight",decorVehicle:"Vehicle",decorObserver:"Other observer",decorEast:"Distance east",decorNorth:"Distance north",decorHeading:"Heading",decorColor:"Colour",decorLit:"Lit",decorTitle:"Name",milestones:"Moments",milestoneLabel:"Label",milestoneNote:"What happens",addMilestone:"Name this moment",deleteMilestone:"Delete moment",goToMilestone:"Go to this moment",confirmAccept:"Delete",confirmDecline:"Cancel",decorWidth:"Width",decorLength:"Length",decorHeight:"Height",decorModel:"3D model",decorModelNone:"Built-in shape",decorModelAdvanced:"Model from an address",decorModelFromCatalogue:"From the catalogue, which the recording names it by. Change a field and it becomes this recording's own address.",decorModelUrl:"glTF/GLB address",decorModelTitle:"Model name",decorModelAuthor:"Author",decorModelLicense:"Licence",decorModelSource:"Where it came from",decorFloors:"Floors",decorOccupiedFloor:"Occupied floor",decorObserverSide:"Observer location",decorObserverSideNone:"Not present",decorWindows:"Windows",decorSideFront:"Front",decorSideBehind:"Behind",decorSideLeft:"Left",decorSideRight:"Right",decorSideFrontLeft:"Front-left",decorSideFrontRight:"Front-right",decorSideBehindLeft:"Behind-left",decorSideBehindRight:"Behind-right"},ml={...EA,accountBy:"Account by",unnamedObserver:"Observer {n}",about:"About",close:"Close",observation:"Observation",date:"Date",location:"Location",case:"Case",description:"Description",source:"Source",accountSource:"Go to the source: {source}",credits:"Credits",editThisObservation:"Edit this observation",embed:"Embed",embedReplay:"Replay",embedEdit:"Editor",embedCopy:"Copy",embedCopied:"Copied",showLabels:"Show what it states",interpretation:"Interpretation",account:"Account",interpretationBy:"{title}, by {by}",confrontation:"Against the account",confrontationDirection:"{deg}° off",confrontationWidth:"width ×{ratio}",confrontationHeight:"height ×{ratio}",showComparison:"Compare with the account",hideComparison:"Stop comparing with the account",hideLabels:"Hide what it states"},AA=Object.freeze(Object.defineProperty({__proto__:null,sightingMessages_en:ml},Symbol.toStringTag,{value:"Module"}));hv();const uv="https://ufoathome.org",Du="compare-account",Iu="account",gg=`${uv}/edit/`;class ah extends HTMLElement{static get observedAttributes(){return["src","show-labels",Es,As,Du]}shadow;sceneElement;toolbarElement;accountElement;accountPrefix;observerText;observerSelect;infoButton;infoPanel;infoAppLink;editLink;accountSourceLink;infoObservationHeading;infoObservationList;infoCreditsToggle;infoCreditsList;infoCloseButton;infoEmbedToggle;infoEmbedPanel;embedReplayRadio;embedEditRadio;labelEmbedReplay;labelEmbedEdit;embedMarkup;embedCopyButton;labelsToggle;paramSummary;summaryBuilder=new gf(ml,new Hl,new On(["en"]),new sl({}));summarySignature="";assessmentEntries=[];assessmentToken=0;supportsPopover=typeof HTMLElement.prototype.showPopover=="function";entries=[];caseSource;interpretationChoice;interpretationLabel;interpretationSelect;confrontationElement;confrontationHeading;confrontationList;compareButton;interpretationLoaders=new Map;interpretationToken=0;offeredFor;currentSrc;infoOpen=!1;creditsOpen=!1;embedOpen=!1;labelsShown=!1;language="en";messages=ml;constructor(){super(),this.shadow=this.attachShadow({mode:"open"});const e=document.createElement("template");e.innerHTML=`<style>${yv}</style>${xv}`,this.shadow.appendChild(e.content.cloneNode(!0)),this.sceneElement=document.createElement(n0),this.forwardPlayerAttributes(),this.sceneElement.ufoElement.creditShownExternally=!0,this.sceneElement.ownCredits=!1,this.sceneElement.ufoElement.hostControls(this.shadow.getElementById("scene-controls")),this.shadow.getElementById("ufo-slot").replaceWith(this.sceneElement),this.toolbarElement=this.shadow.getElementById("toolbar"),this.accountElement=this.shadow.getElementById("account"),this.accountPrefix=this.shadow.getElementById("account-prefix"),this.observerText=this.shadow.getElementById("observer-text"),this.observerSelect=this.shadow.getElementById("observer"),this.infoButton=this.shadow.getElementById("info-button"),this.infoPanel=this.shadow.getElementById("info-panel"),this.infoAppLink=this.shadow.getElementById("info-app-link"),this.editLink=this.shadow.getElementById("edit-link"),this.accountSourceLink=this.shadow.getElementById("account-source"),this.infoObservationHeading=this.shadow.getElementById("info-observation-heading"),this.infoObservationList=this.shadow.getElementById("info-observation-list"),this.infoCreditsToggle=this.shadow.getElementById("info-credits-toggle"),this.infoCreditsList=this.shadow.getElementById("info-credits-list"),this.infoCloseButton=this.shadow.getElementById("info-close"),this.labelsToggle=this.shadow.getElementById("info-labels-toggle"),this.paramSummary=this.shadow.getElementById("param-summary"),this.labelsToggle.addEventListener("click",()=>{this.showLabels=!this.showLabels}),this.infoEmbedToggle=this.shadow.getElementById("info-embed-toggle"),this.infoEmbedPanel=this.shadow.getElementById("info-embed"),this.embedReplayRadio=this.shadow.getElementById("embed-kind-replay"),this.embedEditRadio=this.shadow.getElementById("embed-kind-edit"),this.labelEmbedReplay=this.shadow.getElementById("label-embed-replay"),this.labelEmbedEdit=this.shadow.getElementById("label-embed-edit"),this.embedMarkup=this.shadow.getElementById("embed-markup"),this.embedCopyButton=this.shadow.getElementById("embed-copy"),this.interpretationChoice=this.shadow.getElementById("interpretation-choice"),this.interpretationLabel=this.shadow.getElementById("interpretation-label"),this.interpretationSelect=this.shadow.getElementById("interpretation"),this.confrontationElement=this.shadow.getElementById("confrontation"),this.confrontationHeading=this.shadow.getElementById("confrontation-heading"),this.confrontationList=this.shadow.getElementById("confrontation-list"),this.compareButton=this.shadow.getElementById("compare-account"),this.compareButton.addEventListener("click",()=>this.setComparing(!this.sceneElement.compareAccount)),this.observerSelect.addEventListener("change",()=>this.selectObserver(this.observerSelect.value)),this.interpretationSelect.addEventListener("change",()=>void this.chooseInterpretation(this.interpretationSelect.value)),this.sceneElement.addEventListener(lv,t=>this.showConfrontation(t.detail)),this.sceneElement.ufoElement.addEventListener("timeupdate",()=>this.refreshParamSummary()),this.supportsPopover?(this.infoPanel.setAttribute("popover","auto"),this.infoPanel.removeAttribute("hidden"),this.infoButton.setAttribute("popovertarget","info-panel"),this.infoPanel.addEventListener("beforetoggle",t=>{t.newState==="open"&&(this.populateInfoPanel(),this.bringInfoButtonIntoView())}),this.infoPanel.addEventListener("toggle",t=>this.syncInfoOpen(t.newState==="open"))):this.infoButton.addEventListener("click",()=>this.toggleInfoPanel()),this.infoCloseButton.addEventListener("click",()=>this.toggleInfoPanel()),this.infoCreditsToggle.addEventListener("click",()=>this.toggleCredits()),this.infoEmbedToggle.addEventListener("click",()=>this.toggleEmbed());for(const t of[this.embedReplayRadio,this.embedEditRadio])t.addEventListener("change",()=>this.refreshEmbedMarkup());this.embedCopyButton.addEventListener("click",()=>void this.copyEmbedMarkup()),this.isConnected&&this.loadLocaleMessages()}get scene(){return this.sceneElement}async loadLocaleMessages(){const e=++this.localeToken,t=Fr.preferencesFor(this);this.preferences=t;const i=o0(t,c0),[n,s,a]=i==="en"?[ml,{},void 0]:await Promise.all([M2(i),x2(i),Ag(i)]);if(e!==this.localeToken)return;const o=i!==this.language;this.language=i,this.messages=n,this.tags=new sl(s),this.said=new On(t),this.summaryBuilder=new gf(this.messages,new Hl(a),this.said,this.tags),this.accountPrefix.textContent=this.messages.accountBy,this.interpretationLabel.textContent=this.messages.interpretation,this.confrontationHeading.textContent=this.messages.confrontation;const c=this.entries.find(l=>l.src===this.currentSrc);c&&this.offerInterpretations(c),this.updateCompareButton(),this.infoButton.title=this.messages.about,this.infoButton.setAttribute("aria-label",this.messages.about),this.editLink.title=this.messages.editThisObservation,this.editLink.setAttribute("aria-label",this.messages.editThisObservation),this.infoCloseButton.setAttribute("aria-label",this.messages.close),this.infoObservationHeading.textContent=this.messages.observation,this.infoCreditsToggle.textContent=this.messages.credits,this.syncLabelsToggle(),this.refreshParamSummary(),o&&this.currentSrc&&this.runAssessments(),this.infoEmbedToggle.textContent=this.messages.embed,this.labelEmbedReplay.textContent=this.messages.embedReplay,this.labelEmbedEdit.textContent=this.messages.embedEdit,this.embedCopyButton.textContent=this.messages.embedCopy,this.infoOpen&&this.populateInfoPanel(),this.updateAccountLine()}preferences=[];localeToken=0;said=new On(["en"]);tags=new sl({});connectedCallback(){Fr.preferencesFor(this).join()!==this.preferences.join()&&this.loadLocaleMessages();const e=this.getAttribute("src");e&&this.loadFromSrc(e)}disconnectedCallback(){document.removeEventListener("click",this.handleOutsideClick)}attributeChangedCallback(e,t,i){e==="src"&&i&&i!==t&&this.isConnected&&this.loadFromSrc(i),e==="show-labels"&&this.applyLabels(this.hasAttribute("show-labels")),(e===Es||e===As)&&this.forwardPlayerAttributes(),e===Du&&this.setComparing(this.hasAttribute(Du))}forwardPlayerAttributes(){for(const e of[Es,As]){const t=this.getAttribute(e);t===null?this.sceneElement.removeAttribute(e):this.sceneElement.setAttribute(e,t)}}async loadFromSrc(e){const t=await Ao.json(e);if(Array.isArray(t))throw new Error(`${e} is a bare list of recordings, which is no longer read: list them as the sighting events of a case.json`);if(bs.isCase(t)){const i=bs.sightingUrls(t,new URL(e,location.href).href);if(i.length===0)throw new Error(`${e} is a case with no sighting event: no recording to show`);await this.loadObserverUrls(i,{json:t,url:new URL(e,location.href).href})}else this.setEntries([{src:e,sighting:t}],void 0)}get sightingData(){return this.entries.find(e=>e.src===this.currentSrc)?.sighting}set sightingData(e){this.currentSrc="",this.setEntries([{src:"",sighting:e}],void 0)}get observerUrls(){return this.entries.map(e=>e.src)}set observerUrls(e){this.loadObserverUrls(e)}async loadObserverUrls(e,t){const i=await Promise.all(e.map(async n=>({src:n,sighting:await Ao.json(n)})));this.setEntries(i,t)}setEntries(e,t){this.entries=e,this.caseSource=t,this.toolbarElement.hidden=e.length===0;const i=e.length>1;this.observerSelect.hidden=!i,this.observerText.hidden=i,this.observerSelect.innerHTML="";for(const s of e){const a=document.createElement("option");a.value=s.src,a.textContent=this.observerDisplayName(s.sighting.observer)??this.messages.unnamedObserver.replace("{n}",String(e.indexOf(s)+1)),this.observerSelect.appendChild(a)}const n=e.find(s=>s.src===this.currentSrc)??e[0];n?this.selectObserver(n.src):this.updateAccountLine()}editorUrl(){if(!this.currentSrc)return gg;const e=new URL(this.currentSrc,location.href);return`${gg}?sighting=${encodeURIComponent(e.href)}`}embedMarkupFor(e){const t=e==="edit"?"rr0-sighting-editor":"rr0-sighting",i=new URL(`${t}.mjs`,import.meta.url).href,n=this.currentSrc?new URL(this.currentSrc,location.href).href:"";return`<script type="module" src="${i}"><\/script>
|
|
7781
|
-
<${t} src="${n}"></${t}>`}refreshEmbedMarkup(){this.embedMarkup.value=this.embedMarkupFor(this.embedEditRadio.checked?"edit":"replay")}async copyEmbedMarkup(){try{await navigator.clipboard.writeText(this.embedMarkup.value),this.embedCopyButton.textContent=this.messages.embedCopied,window.setTimeout(()=>this.embedCopyButton.textContent=this.messages.embedCopy,1500)}catch{this.embedMarkup.select()}}offerInterpretations(e){const t=this.offeredFor===e.sighting,i=this.interpretationSelect.value;this.offeredFor=e.sighting,this.interpretationToken++,this.interpretationLoaders=new Map,this.interpretationSelect.innerHTML="";const n=(l,h,u)=>{const d=document.createElement("option");d.value=l,d.textContent=h,this.interpretationSelect.appendChild(d),this.interpretationLoaders.set(l,u)},s=e===this.entries.find(l=>l.src===this.currentSrc)?this.sceneElement.ufoElement.sighting.interpretation:void 0;n(Iu,this.messages.account,()=>Promise.resolve(s));const a=this.caseSource;a&&bs.interpretationEvents(a.json,e.sighting.id).forEach((l,h)=>{const u=this.said.read(l.title)??`#${h+1}`,d=(l.by??[]).map(f=>this.agentName(f)).filter(Boolean).join(", ");n(`case-${h}`,d?this.messages.interpretationBy.replace("{title}",u).replace("{by}",d):u,()=>bs.interpretationOf(l,a.url,f=>Ao.json(f)))});const c=t&&[...this.interpretationSelect.options].some(l=>l.value===i)?i:Iu;this.interpretationSelect.value=c,c===Iu?this.sceneElement.interpretation!==s&&(this.sceneElement.interpretation=s):this.sceneElement.interpretation||this.chooseInterpretation(c),this.interpretationChoice.hidden=this.interpretationSelect.options.length<2,this.showConfrontation(this.sceneElement.confrontation),this.updateCompareButton()}setComparing(e){this.sceneElement.compareAccount=e,this.updateCompareButton(),this.showConfrontation(this.sceneElement.confrontation)}updateCompareButton(){const e=this.sceneElement.compareAccount;this.compareButton.hidden=!this.sceneElement.interpretation,this.compareButton.setAttribute("aria-pressed",String(e));const t=e?this.messages.hideComparison:this.messages.showComparison;this.compareButton.title=t,this.compareButton.setAttribute("aria-label",t)}static DATE_LOCALES={en:"en-US",fr:"fr-FR",es:"es-ES",it:"it-IT"};get colon(){return this.language==="fr"?" : ":": "}async chooseInterpretation(e){const t=++this.interpretationToken,i=this.interpretationLoaders.get(e),n=i?await i().catch(s=>{console.warn(`<rr0-sighting>: could not read interpretation "${e}":`,s)}):void 0;t===this.interpretationToken&&(this.sceneElement.interpretation=n,this.updateCompareButton(),this.showConfrontation(this.sceneElement.confrontation))}agentName(e){if("people"in e){const[t,...i]=e.people.replace(/([a-z])([A-Z])/g,"$1 $2").split(" ");return[...i,t].join(" ")}return"org"in e?e.org.replace(/([a-z])([A-Z])/g,"$1 $2"):this.observerDisplayName(e)??""}showConfrontation(e){this.confrontationList.innerHTML="",this.confrontationElement.hidden=!this.sceneElement.interpretation||!this.sceneElement.compareAccount;const t=new Intl.NumberFormat(this.language,{maximumFractionDigits:1,minimumFractionDigits:1}),i=new Intl.NumberFormat(this.language,{maximumFractionDigits:2,minimumFractionDigits:2});for(const n of e){const s=document.createElement("li");s.append(`${this.said.read(n.title)??n.sourceId}${this.colon}`);const a=[];n.separationDeg!==void 0&&a.push([this.messages.confrontationDirection.replace("{deg}",t.format(n.separationDeg)),n.disagreements.includes("direction")]),n.widthRatio!==void 0&&a.push([this.messages.confrontationWidth.replace("{ratio}",i.format(n.widthRatio)),n.disagreements.includes("width")]),n.heightRatio!==void 0&&a.push([this.messages.confrontationHeight.replace("{ratio}",i.format(n.heightRatio)),n.disagreements.includes("height")]),a.forEach(([o,c],l)=>{l>0&&s.append(" · ");const h=document.createElement("span");h.textContent=o,c&&(h.className="disagrees"),s.append(h)}),this.confrontationList.appendChild(s)}}selectObserver(e){const t=this.entries.find(i=>i.src===e);t&&(this.currentSrc=e,this.observerSelect.value=e,this.sceneElement.documentUrl=t.src?new URL(t.src,location.href).href:void 0,this.sceneElement.sightingData=t.sighting,this.offerInterpretations(t),this.updateAccountLine(),this.refreshParamSummary(),this.runAssessments(),this.infoOpen&&this.populateInfoPanel(),this.dispatchEvent(new CustomEvent(TA,{detail:{src:e}})))}async runAssessments(){const e=++this.assessmentToken,t=await new Kv(this.messages).read(this.sceneElement.ufoElement.sighting);e===this.assessmentToken&&(this.assessmentEntries=t.entries,this.refreshParamSummary())}updateAccountLine(){const e=this.entries.find(s=>s.src===this.currentSrc),t=e?this.observerDisplayName(e.sighting.observer):void 0,i=t!==void 0||this.entries.length>1;this.accountElement.hidden=!i,this.observerText.textContent=t??"";const n=e?.sighting.sources?.find(s=>/^https?:\/\//i.test(s.url??""));if(this.accountSourceLink.hidden=!n,n){this.accountSourceLink.href=n.url;const s=this.messages.accountSource.replace("{source}",n.title??n.url);this.accountSourceLink.title=s,this.accountSourceLink.setAttribute("aria-label",s)}this.editLink.hidden=!this.currentSrc,this.editLink.href=this.editorUrl(),this.editLink.title=this.messages.editThisObservation,this.editLink.setAttribute("aria-label",this.messages.editThisObservation)}observerDisplayName(e){if(!e)return;const t=[...e.firstNames??[],e.lastName].filter(Boolean).join(" ");return e.title||t||e.id}formatDate(e){const t=e.place?.[0],i=So(e.time??{},t?.lng??0,e.utcOffsetHours);if(!i)return;const n=i.getTime()+this.utcOffsetHoursOf(e,t?.lng??0)*36e5;return new Intl.DateTimeFormat(ah.DATE_LOCALES[this.language],{dateStyle:"long",timeStyle:"short",timeZone:"UTC"}).format(new Date(n))}utcOffsetHoursOf(e,t){return e.utcOffsetHours??Math.round(t/15)}formatLocation(e){const t=e.place?.[0];if(t)return`${t.lat.toFixed(4)}, ${t.lng.toFixed(4)}`}toggleInfoPanel(){const e=!this.infoOpen;if(this.supportsPopover){const t=this.infoPanel.matches(":popover-open");e&&!t?this.infoPanel.showPopover():!e&&t&&this.infoPanel.hidePopover();return}e&&this.bringInfoButtonIntoView(),this.syncInfoOpen(e),this.infoPanel.hidden=!e,e?document.addEventListener("click",this.handleOutsideClick):document.removeEventListener("click",this.handleOutsideClick)}bringInfoButtonIntoView(){const e=this.infoButton.getBoundingClientRect(),t=window.innerHeight||document.documentElement.clientHeight;e.top>=0&&e.bottom<=t||this.infoButton.scrollIntoView({block:"center"})}syncInfoOpen(e){e!==this.infoOpen&&(this.infoOpen=e,this.infoButton.setAttribute("aria-expanded",String(e)),e?this.supportsPopover||this.populateInfoPanel():(this.creditsOpen=!1,this.infoCreditsList.hidden=!0,this.infoCreditsToggle.setAttribute("aria-expanded","false"),this.embedOpen=!1,this.infoEmbedPanel.hidden=!0,this.infoEmbedToggle.setAttribute("aria-expanded","false")))}handleOutsideClick=e=>{const t=e.composedPath();!t.includes(this.infoPanel)&&!t.includes(this.infoButton)&&this.toggleInfoPanel()};toggleCredits(){this.creditsOpen=!this.creditsOpen,this.infoCreditsList.hidden=!this.creditsOpen,this.infoCreditsToggle.setAttribute("aria-expanded",String(this.creditsOpen)),this.creditsOpen&&this.revealInPanel(this.infoCreditsList)}toggleEmbed(){this.embedOpen=!this.embedOpen,this.infoEmbedPanel.hidden=!this.embedOpen,this.infoEmbedToggle.setAttribute("aria-expanded",String(this.embedOpen)),this.embedOpen&&(this.refreshEmbedMarkup(),this.revealInPanel(this.infoEmbedPanel))}revealInPanel(e){e.scrollIntoView?.({block:"nearest"})}get showLabels(){return this.labelsShown}set showLabels(e){this.toggleAttribute("show-labels",e)}applyLabels(e){this.labelsShown=e,this.syncLabelsToggle(),this.refreshParamSummary(),this.populateInfoPanel()}syncLabelsToggle(){this.labelsToggle.textContent=this.labelsShown?this.messages.hideLabels:this.messages.showLabels,this.labelsToggle.setAttribute("aria-pressed",String(this.labelsShown))}refreshParamSummary(){if(this.paramSummary.hidden=!this.labelsShown,!this.labelsShown){this.paramSummary.replaceChildren(),this.summarySignature="";return}const e=this.sceneElement.ufoElement.sighting,t=[...this.summaryBuilder.entriesFor(e,this.sceneElement.ufoElement.currentTime),...this.assessmentEntries],i=t.map(a=>`${a.field}=${a.label}=${a.value}${a.unit}${a.fromSource?"*":""}`).join("|");if(i===this.summarySignature)return;this.summarySignature=i;const n=[];let s;for(const a of t){s&&s.group!==a.group&&(s=void 0);const o=a.group==="observer"?this.messages.observerGroup:a.group==="assessment"?this.messages.assessmentGroup:void 0;if(o!==void 0&&!s){const l=document.createElement("span");l.className="param-nest";const h=document.createElement("span");h.className="param-nest-label",h.textContent=o,l.append(h),s={group:a.group,element:l},n.push(l)}const c=this.paramItem(a);s?s.element.append(c):n.push(c)}this.paramSummary.replaceChildren(...n)}paramItem(e){const t=document.createElement("span");t.className=e.fromSource?"param-label from-source":"param-label";const i=document.createElement("span");if(i.className="param-label-label",i.textContent=`${e.label} `,t.append(i),e.color!==void 0){const s=document.createElement("span");s.className="param-label-swatch",s.style.background=e.color,t.append(s)}const n=document.createElement("span");return n.className="param-label-value",n.textContent=e.unit===""?e.value:`${e.value} ${e.unit}`,t.append(n),t}populateInfoPanel(){const e=this.entries.find(t=>t.src===this.currentSrc);if(this.infoObservationList.innerHTML="",e){const t=this.caseSource&&(this.caseSource.json.title??this.caseSource.json.id);if(t&&this.appendInfoRow(this.infoObservationList,this.messages.case,t),!this.labelsShown){const n=this.formatDate(e.sighting);n&&this.appendInfoRow(this.infoObservationList,this.messages.date,n);const s=this.formatLocation(e.sighting);s&&this.appendInfoRow(this.infoObservationList,this.messages.location,s)}const i=this.said.read(e.sighting.description);i&&this.appendInfoRow(this.infoObservationList,this.messages.description,i);for(const n of e.sighting.sources??[])this.appendInfoSource(this.infoObservationList,this.messages.source,n);!this.labelsShown&&e.sighting.tags&&e.sighting.tags.length>0&&this.appendInfoRow(this.infoObservationList,this.messages.tags,e.sighting.tags.map(n=>this.tags.name(n)).join(", "))}this.refreshEmbedMarkup(),this.infoAppLink.href=uv,this.infoAppLink.textContent="UFO@home v0.74.0",Dn.fill(this.infoCreditsList,this.sceneElement)}appendInfoSource(e,t,i){const n=document.createElement("dt");n.textContent=t;const s=document.createElement("dd"),a=i.title??i.url??"";if(i.url&&/^https?:\/\//i.test(i.url)){const c=document.createElement("a");c.href=i.url,c.target="_blank",c.rel="noopener noreferrer",c.textContent=a,s.appendChild(c)}else s.append(a);const o=[i.authors?.join(", "),i.publication?.publisher,i.publication?.time,i.index].filter(Boolean);o.length>0&&s.append(`, ${o.join(", ")}`),e.append(n,s)}appendInfoRow(e,t,i){const n=document.createElement("dt");n.textContent=t;const s=document.createElement("dd");s.textContent=i,e.appendChild(n),e.appendChild(s)}}const vg="rr0-sighting",TA="observerchange",Mg="rr0-eyeobserver";class RA extends ah{}function DA(){hv(),customElements.get(vg)||customElements.define(vg,ah),customElements.get(Mg)||customElements.define(Mg,RA)}DA();export{LA as $,Qi as A,tt as B,se as C,Dp as D,bn as E,kA as F,_t as G,ot as H,NA as I,OA as J,De as K,jo as L,xx as M,lc as N,Ut as O,g1 as P,en as Q,Go as R,Oo as S,IA as T,FA as U,xe as V,r1 as W,UA as X,xs as Y,Dt as Z,Ji as _,PA as a,zn as a0,a1,Sp as a2,ox as a3,_l as a4,xd as a5,Dl as a6,Si as a7,p1 as a8,D0 as a9,I0 as aa,at as ab,sa as ac,Jo as ad,Vi as ae,Cs as af,CA as b,Qh as c,HA as d,El as e,Gi as f,BA as g,Ze as h,R as i,dp as j,zA as k,GA as l,nx as m,Ta as n,dh as o,d2 as p,rM as q,rt as r,So as s,At as t,Gu as u,wi as v,o1 as w,Ps as x,fx as y,_a as z};
|
|
7780
|
+
`);let s=Kn.cache.get(n);return s||(s=Promise.all(i.map(a=>Kn.load(a.url))).then(a=>a.reduce((o,c)=>Kn.concat(o,c))),Kn.cache.set(n,s)),s}static parse(e){const t=e.byteLength/(4*Float32Array.BYTES_PER_ELEMENT),i=t*Float32Array.BYTES_PER_ELEMENT;return{count:t,ra:new Float32Array(e,0*i,t),dec:new Float32Array(e,1*i,t),mag:new Float32Array(e,2*i,t),ci:new Float32Array(e,3*i,t)}}static concat(e,t){const i=(n,s)=>{const a=new Float32Array(n.length+s.length);return a.set(n,0),a.set(s,n.length),a};return{count:e.count+t.count,ra:i(e.ra,t.ra),dec:i(e.dec,t.dec),mag:i(e.mag,t.mag),ci:i(e.ci,t.ci)}}}class Hl{constructor(e){this.names=e}body(e,t){return this.names?.bodies[e]??t}star(e){return this.names?.stars[e.name]??e.name}comet(e){return this.names?.comets[e.id]??e.name}nova(e){return this.names?.novae[e.id]??e.name}satelliteClass(e){return this.names?.satelliteClasses[e.id]??e.name}shower(e){return this.names?.showers[e.id]??e.name}lightRig(e){return this.names?.lightRigs[e.id]??e.name}instrument(e){return this.names?.instruments[e.id]??e.name}decorKind(e,t){return this.names?.decorKinds[e]??t}point(e){return La.point(e,this.names?.compassPoints)}towards(e){return La.towards(e,this.names)}}const sA=new URL(""+new URL("rain-BvWZrB9h.ogg",import.meta.url).href,import.meta.url).href,aA=new URL(""+new URL("wind-BjklexY7.ogg",import.meta.url).href,import.meta.url).href,rA=new URL(""+new URL("thunder-DA48qs_v.wav",import.meta.url).href,import.meta.url).href,oA=20,cA=1;class lA{context;buffers=new Map;ambientSource;ambientGain;ambientKey="none";ambientToken=0;ambientVolume=0;windSource;windGain;windActive=!1;windToken=0;windVolume=0;paused=!0;requested={type:"none",intensity:0,windSpeed:0};resume(){if(!this.context){if(typeof AudioContext>"u")return;try{this.context=new AudioContext}catch(e){console.warn("WeatherAudio: Web Audio unavailable, weather sounds disabled:",e);return}}this.context.state==="suspended"&&this.context.resume()}setAmbient(e,t,i){if(this.requested={type:e,intensity:t,windSpeed:i},!this.context)return;this.paused&&(e="none",t=0,i=0);const n=e==="rain"||e==="hail"?e:"none";if(this.ambientVolume=n==="hail"?Math.min(1,t*1.3+.2):n==="rain"?t:0,n!==this.ambientKey){this.ambientKey=n;const a=++this.ambientToken;this.stopSource(this.ambientSource,this.ambientGain),this.ambientSource=void 0,this.ambientGain=void 0,n!=="none"&&this.startLoop(sA,this.ambientVolume).then(o=>this.applyIfCurrent(o,a,()=>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/oA,1);const s=i>cA;if(s!==this.windActive){this.windActive=s;const a=++this.windToken;this.stopSource(this.windSource,this.windGain),this.windSource=void 0,this.windGain=void 0,s&&this.startLoop(aA,this.windVolume).then(o=>this.applyIfCurrent(o,a,()=>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(e){if(e===this.paused)return;this.paused=e;const{type:t,intensity:i,windSpeed:n}=this.requested;this.setAmbient(t,i,n)}playThunder(){!this.context||this.paused||this.playOneShot(rA,.9)}dispose(){this.ambientToken++,this.windToken++,this.stopSource(this.ambientSource,this.ambientGain),this.stopSource(this.windSource,this.windGain),this.ambientSource=void 0,this.ambientGain=void 0,this.windSource=void 0,this.windGain=void 0,this.context?.close(),this.context=void 0,this.buffers.clear()}applyIfCurrent(e,t,i,n){if(t!==i()){e?.source.stop();return}n(e)}async startLoop(e,t){const i=this.context;if(i)try{const n=await this.getBuffer(e),s=i.createBufferSource();s.buffer=n,s.loop=!0;const a=i.createGain();return a.gain.value=t,s.connect(a).connect(i.destination),s.start(),{source:s,gain:a}}catch(n){console.warn("Weather ambient sound failed to load, staying silent:",n);return}}async playOneShot(e,t){const i=this.context;if(i)try{const n=await this.getBuffer(e),s=i.createBufferSource();s.buffer=n;const a=i.createGain();a.gain.value=t,s.connect(a).connect(i.destination),s.start()}catch(n){console.warn("Thunder sound failed to load:",n)}}async getBuffer(e){const t=this.context;if(!t)throw new Error("WeatherAudio: AudioContext not ready — resume() must be called first");let i=this.buffers.get(e);return i||(i=fetch(e).then(n=>{if(!n.ok)throw new Error(`Audio fetch failed (${n.status}): ${e}`);return n.arrayBuffer()}).then(n=>t.decodeAudioData(n)),this.buffers.set(e,i)),i}stopSource(e,t){try{e?.stop()}catch{}e?.disconnect(),t?.disconnect()}}class Ms{constructor(e){this.elements=e;const{eccentricity:t,perihelionAu:i}=e,[n,s]=this.perifocalAxes(),a=Math.sqrt(Ms.SUN_GM_AU3_PER_DAY2*(1+t)/i);this.perihelionPosition=this.scale(n,i),this.perihelionVelocity=this.scale(s,a),this.inverseSemiMajorAxis=(1-t)/i}static SUN_GM_AU3_PER_DAY2=.0002959122082855911;static MAX_ITERATIONS=200;perihelionPosition;perihelionVelocity;inverseSemiMajorAxis;positionAt(e){const t=e-this.elements.perihelionJd,i=this.universalAnomaly(t),n=this.inverseSemiMajorAxis*i*i,s=this.elements.perihelionAu,a=1-i*i/s*Ms.stumpffC(n),o=t-i*i*i/Math.sqrt(Ms.SUN_GM_AU3_PER_DAY2)*Ms.stumpffS(n);return{x:a*this.perihelionPosition.x+o*this.perihelionVelocity.x,y:a*this.perihelionPosition.y+o*this.perihelionVelocity.y,z:a*this.perihelionPosition.z+o*this.perihelionVelocity.z}}heliocentricDistanceAt(e){const t=this.positionAt(e);return Math.hypot(t.x,t.y,t.z)}universalAnomaly(e){if(e===0)return 0;const t=Math.sign(e),i=Math.sqrt(Ms.SUN_GM_AU3_PER_DAY2)*Math.abs(e),n=o=>{const c=this.inverseSemiMajorAxis*o*o,l=this.elements.perihelionAu;return(1-this.inverseSemiMajorAxis*l)*o*o*o*Ms.stumpffS(c)+l*o};let s=Math.max(1,i/this.elements.perihelionAu);for(;n(s)<i;)s*=2;let a=0;for(let o=0;o<Ms.MAX_ITERATIONS&&s-a>1e-13*Math.max(1,s);o++){const c=(a+s)/2;n(c)<i?a=c:s=c}return t*(a+s)/2}perifocalAxes(){const e=this.elements.ascendingNodeDeg*Math.PI/180,t=this.elements.argumentOfPerihelionDeg*Math.PI/180,i=this.elements.inclinationDeg*Math.PI/180,n=Math.cos(e),s=Math.sin(e),a=Math.cos(t),o=Math.sin(t),c=Math.cos(i),l=Math.sin(i);return[{x:n*a-s*o*c,y:s*a+n*o*c,z:o*l},{x:-n*o-s*a*c,y:-s*o+n*a*c,z:a*l}]}scale(e,t){return{x:e.x*t,y:e.y*t,z:e.z*t}}static stumpffC(e){if(Math.abs(e)<1e-6)return 1/2-e/24+e*e/720;if(e>0)return(1-Math.cos(Math.sqrt(e)))/e;const t=Math.sqrt(-e);return(Math.cosh(t)-1)/-e}static stumpffS(e){if(Math.abs(e)<1e-6)return 1/6-e/120+e*e/5040;if(e>0){const i=Math.sqrt(e);return(i-Math.sin(i))/(i*i*i)}const t=Math.sqrt(-e);return(Math.sinh(t)-t)/(t*t*t)}}const cv=[{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 hA{static WINDOW_DAYS=200;static TWILIGHT_ELONGATION_DEG=15;static LIGHT_SPEED_AU_PER_DAY=173.144632674;static orbits=new Map;static aroundDate(e){const t=this.julianDayOf(e);return cv.filter(i=>Math.abs(t-i.orbit.perihelionJd)<=this.WINDOW_DAYS)}static brightestAt(e,t){return this.aroundDate(e).map(i=>this.appearanceOf(i,e,t)).sort((i,n)=>i.magnitude-n.magnitude)[0]}static appearanceOf(e,t,i){const n=Xt(t),s=this.earthPositionAt(n),a=this.apparentPositionOf(e,2451545+n.tt,s),o=this.subtract(a,s),c=this.length(a),l=this.length(o),h=this.tailEndAt(e,a,s,c,n,t,i),u=this.horizontalOf(o,n,t,i);return{apparition:e,position:u,...h,heliocentricDistanceAu:c,earthDistanceAu:l,elongationDeg:this.angleBetween(o,this.subtract({x:0,y:0,z:0},s)),magnitude:this.magnitudeAt(e,c,l)}}static magnitudeAt(e,t,i){const n=e.absoluteMagnitude+5*Math.log10(i)+2.5*e.activityExponent*Math.log10(t);return Math.max(n,e.peakMagnitude)}static tailEndAt(e,t,i,n,s,a,o){if(e.tailLengthAu===void 0)return{};const c=1+e.tailLengthAu/n,l=this.subtract({x:t.x*c,y:t.y*c,z:t.z*c},i),h=this.subtract(t,i);return{tailEnd:this.horizontalOf(l,s,a,o),tailLengthDeg:this.angleBetween(h,l)}}static apparentPositionOf(e,t,i){const n=this.orbitOf(e);let s=n.positionAt(t);for(let a=0;a<2;a++){const o=this.length(this.subtract(s,i))/this.LIGHT_SPEED_AU_PER_DAY;s=n.positionAt(t-o)}return s}static horizontalOf(e,t,i,n){const s=Lr(r5(),new Ot(e.x,e.y,e.z,t)),a=Lr($1(t),s),o=zw(t,new W0(n.lat,n.lng,n.elevationM)),c=new Ot(a.x-o.x,a.y-o.y,a.z-o.z,t),l=Y0(c);return q0(l.ra,l.dec,i,n)}static earthPositionAt(e){return Lr(a5(),na(we.Earth,e))}static julianDayOf(e){return 2451545+Xt(e).tt}static orbitOf(e){const t=this.orbits.get(e.id);if(t)return t;const i=new Ms(e.orbit);return this.orbits.set(e.id,i),i}static subtract(e,t){return{x:e.x-t.x,y:e.y-t.y,z:e.z-t.z}}static length(e){return Math.hypot(e.x,e.y,e.z)}static angleBetween(e,t){const i=(e.x*t.x+e.y*t.y+e.z*t.z)/(this.length(e)*this.length(t)||1);return Math.acos(Math.min(1,Math.max(-1,i)))*180/Math.PI}}const wu=[{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 ug{static UNIX_EPOCH_JD=24405875e-1;static aroundDate(e){const t=this.julianDayOf(e);return wu.filter(i=>this.magnitudeAt(i,t)!==void 0)}static appearancesAt(e,t){const i=this.julianDayOf(e),n=[];for(const s of wu){const a=this.magnitudeAt(s,i);a!==void 0&&n.push({outburst:s,position:Ln.ofJ2000(s.raHours,s.decDeg,e,t),magnitude:a})}return n.sort((s,a)=>s.magnitude-a.magnitude)}static brightestAt(e,t){return this.appearancesAt(e,t)[0]}static byId(e){return wu.find(t=>t.id===e)}static magnitudeAt(e,t){const i=e.lightCurve,n=t-e.startJd;if(i.length===0||n<i[0][0]||n>i[i.length-1][0])return;let s=1;for(;s<i.length-1&&i[s][0]<n;)s++;const[a,o]=i[s-1]??i[0],[c,l]=i[s]??i[0];if(c===a)return o;const h=Math.min(1,Math.max(0,(n-a)/(c-a)));return o+h*(l-o)}static julianDayOf(e){return e.getTime()/864e5+this.UNIX_EPOCH_JD}}const uA=[{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}],Gl=6.5;class Eu{static activeAt(e){return uA.flatMap(t=>{const i=this.nearness(t,e);return i<=0?[]:[{shower:t,zhr:t.peakZhr*i,nearness:i}]})}static nearness(e,t){const i=this.dayOfYear(t),n=this.dayOfYear(this.asDate(e.start)),s=this.dayOfYear(this.asDate(e.peak)),a=this.dayOfYear(this.asDate(e.end)),o=this.wrappedDelta(i,s),c=this.wrappedDelta(s,n),l=this.wrappedDelta(a,s);return o<0?o<-c?0:1+o/c:o>0?o>l?0:1-o/l:1}static observedRatePerHour(e,t,i,n=Gl){if(t<=0)return 0;const s=Gl-n;return e*Math.sin(t*Math.PI/180)/Math.pow(i,s)}static radiantPosition(e,t,i){return Ln.ofJ2000(e.radiantRaHours,e.radiantDecDeg,t,i)}static dayOfYear(e){const t=Date.UTC(e.getUTCFullYear(),0,1);return Math.floor((Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate())-t)/864e5)+1}static asDate(e){return new Date(Date.UTC(2001,e.month-1,e.day))}static wrappedDelta(e,t){const i=e-t;return i>182?i-365:i<-182?i+365:i}}class Jt{static QUIET_RATE_PER_HOUR=2;static APEX_RATE_PER_HOUR=8;static POPULATION_INDEX=3;static apexPosition(e,t){const i=Xt(e),n=new th(0,Uw(e).elon-90,1),s=Lr(c5(i),X0(n,i)),a=Y0(s);return q0(a.ra,a.dec,e,t)}static observedRatePerHour(e,t=Gl){const i=Jt.APEX_RATE_PER_HOUR*Math.max(0,Math.sin(e*Math.PI/180)),n=Gl-t;return(Jt.QUIET_RATE_PER_HOUR+i)/Math.pow(Jt.POPULATION_INDEX,n)}static schedule(e){const t=new sh(e.seed^1542469173);return Oa.schedule(e).map(i=>{const n=Jt.toCartesian({altitudeDeg:Math.asin(t.next())*180/Math.PI,azimuthDeg:t.between(0,360)}),s=i.fromRadiantDeg*Math.PI/180,a=Jt.turnAround(n,t.between(0,360)),o={x:n.x*Math.cos(s)+a.x*Math.sin(s),y:n.y*Math.cos(s)+a.y*Math.sin(s),z:n.z*Math.cos(s)+a.z*Math.sin(s)};return{...i,radiant:Jt.toHorizontal(o),bearingDeg:Jt.bearingFrom(o,n)}})}static turnAround(e,t){const[i,n]=Jt.basisAround(e),s=t*Math.PI/180;return{x:i.x*Math.cos(s)+n.x*Math.sin(s),y:i.y*Math.cos(s)+n.y*Math.sin(s),z:i.z*Math.cos(s)+n.z*Math.sin(s)}}static bearingFrom(e,t){const[i,n]=Jt.basisAround(e),s=e.x*t.x+e.y*t.y+e.z*t.z,a=Jt.normalise({x:t.x-e.x*s,y:t.y-e.y*s,z:t.z-e.z*s});return(Math.atan2(a.x*n.x+a.y*n.y+a.z*n.z,a.x*i.x+a.y*i.y+a.z*i.z)*180/Math.PI%360+360)%360}static basisAround(e){const t=Math.abs(e.y)<.9?{x:0,y:1,z:0}:{x:1,y:0,z:0},i=Jt.normalise(Jt.cross(e,t));return[i,Jt.normalise(Jt.cross(e,i))]}static toHorizontal(e){const t=Math.hypot(e.x,e.y,e.z)||1;return{altitudeDeg:Math.asin(Math.min(1,Math.max(-1,e.y/t)))*180/Math.PI,azimuthDeg:(Math.atan2(e.x,-e.z)*180/Math.PI%360+360)%360}}static appearanceOf(e){const t=Jt.toCartesian(e.radiant??{altitudeDeg:90,azimuthDeg:0}),i=Jt.turnAround(t,e.bearingDeg),n=e.fromRadiantDeg*Math.PI/180;return Jt.toHorizontal({x:t.x*Math.cos(n)+i.x*Math.sin(n),y:t.y*Math.cos(n)+i.y*Math.sin(n),z:t.z*Math.cos(n)+i.z*Math.sin(n)})}static toCartesian(e){const t=e.altitudeDeg*Math.PI/180,i=e.azimuthDeg*Math.PI/180,n=Math.cos(t);return{x:n*Math.sin(i),y:Math.sin(t),z:-n*Math.cos(i)}}static cross(e,t){return{x:e.y*t.z-e.z*t.y,y:e.z*t.x-e.x*t.z,z:e.x*t.y-e.y*t.x}}static normalise(e){const t=Math.hypot(e.x,e.y,e.z)||1;return{x:e.x/t,y:e.y/t,z:e.z/t}}static TYPICAL_VELOCITY_KM_S=40}const dg="https://ufoathome.org/tle/index.json";class Ii{static MAX_ELEMENT_AGE_DAYS=7;static DAY_MS=864e5;fetchImpl;indexUrls;index;files=new Map;constructor(e={}){this.fetchImpl=e.fetchImpl??fetch.bind(globalThis),this.indexUrls=e.indexUrls??Ii.defaultIndexUrls()}static defaultIndexUrls(){const e=[];return typeof location<"u"&&/^https?:$/.test(location.protocol)&&e.push(new URL("/tle/index.json",location.href).href),e.includes(dg)||e.push(dg),e}static FIRST_SNAPSHOT="2021-02-22";async covers(e){const t=Date.parse(`${Ii.FIRST_SNAPSHOT}T00:00:00Z`)-Ii.MAX_ELEMENT_AGE_DAYS*Ii.DAY_MS;if(e.getTime()<t)return!1;const i=await this.loadIndex();return i?Object.values(i.index.kinds).some(n=>e.getTime()>=Date.parse(n.from)-Ii.MAX_ELEMENT_AGE_DAYS*Ii.DAY_MS&&e.getTime()<=Date.parse(n.to)+Ii.MAX_ELEMENT_AGE_DAYS*Ii.DAY_MS):!1}async at(e){const t=await this.loadIndex();if(!t)return;const{index:i,base:n}=t,s=[],a=[];for(const o of Object.keys(i.kinds)){const c=await this.kindAt(o,e,i,n);s.push(...c),a.push(this.coverageOf(o,e,i,c.length>0))}return{objects:s,coverage:a,credit:i.credit,creditUrl:i.source}}async kindAt(e,t,i,n){const s=t.getTime(),a=i.binDays*Ii.DAY_MS,o=Math.floor(s/a),c=s-o*a<a/2?o-1:o+1,l=new Set(i.kinds[e].bins),h=[o,c].map(v=>new Date(v*a).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-${e}.json`,n).href),...h.map(v=>this.binary(new URL(`${e}/${v}.bin`,n).href))]),f=new Map;for(const v of d)for(const m of Ii.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)/Ii.DAY_MS;if(m>Ii.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:e,launch:g.launch,stdMag:g.stdMag,elements:v,ageDays:m})}return p}coverageOf(e,t,i,n){const{from:s,to:a}=i.kinds[e],o=t.getTime(),c=Ii.MAX_ELEMENT_AGE_DAYS*Ii.DAY_MS,l=n?"covered":o<Date.parse(s)-c?"before":o>Date.parse(a)+c?"after":"gap";return{kind:e,status:l,from:s,to:a}}static decode(e,t){const i=new DataView(e),n=[];for(let s=0;s+t<=e.byteLength;s+=t)n.push({norad:i.getUint32(s,!0),epochMs:i.getFloat64(s+4,!0),bstar:i.getFloat32(s+12,!0),inclinationDeg:i.getFloat32(s+16,!0),raanDeg:i.getFloat32(s+20,!0),eccentricity:i.getFloat32(s+24,!0),argOfPerigeeDeg:i.getFloat32(s+28,!0),meanAnomalyDeg:i.getFloat32(s+32,!0),meanMotion:i.getFloat64(s+36,!0)});return n}loadIndex(){return this.index??=(async()=>{for(const e of this.indexUrls)try{const t=await this.fetchImpl(e);if(!t.ok)continue;return{index:await t.json(),base:e}}catch{}})(),this.index}json(e){return this.cached(e,async t=>t.json())}binary(e){return this.cached(e,async t=>t.arrayBuffer())}cached(e,t){let i=this.files.get(e);return i||(i=this.fetchImpl(e).then(n=>{if(!n.ok)throw new Error(`${e}: ${n.status}`);return t(n)}),i.catch(()=>this.files.delete(e)),this.files.set(e,i)),i}}class dA{lowerM;upperM;add(e,t){if(!(e<=0)){if(t.behindM!==void 0){const i=Et.sizeMAt(t.behindM,e);this.lowerM=this.lowerM===void 0?i:Math.max(this.lowerM,i)}if(t.inFrontM!==void 0){const i=Et.sizeMAt(t.inFrontM,e);this.upperM=this.upperM===void 0?i:Math.min(this.upperM,i)}}}get sizeRange(){return{minM:this.lowerM,maxM:this.upperM}}get empty(){return this.lowerM===void 0&&this.upperM===void 0}get contradictory(){return this.lowerM!==void 0&&this.upperM!==void 0&&this.lowerM>this.upperM}distanceRangeAt(e){return e<=0?{}:{minM:this.lowerM===void 0?void 0:Et.distanceMAt(this.lowerM,e),maxM:this.upperM===void 0?void 0:Et.distanceMAt(this.upperM,e)}}clear(){this.lowerM=void 0,this.upperM=void 0}}class Fa{static DEG_PER_SECOND=360/86164.0905;static degOver(e){return Math.max(0,e)*Fa.DEG_PER_SECOND}static instants(e,t){if(!(t>0))return 1;const i=Fa.degOver(e)/t;return i<1?1:Math.min(Fa.MAX_INSTANTS,Math.max(2,Math.ceil(i)))}static MAX_INSTANTS=64}class zi{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 Fa.DEG_PER_SECOND*3600}static graspOf(e,t={}){const i=t.exposureSeconds??e.exposureSeconds,n=t.fNumber??e.fNumber;if(i===void 0||n===void 0||!(i>0)||!(n>0))return zi.EYE;const s=t.focalLengthMm??e.frame?.focalLengthMm??zi.UNKNOWN_CAMERA_FOCAL_MM,a=s/n,o=zi.resolutionArcsec(e,s,a);return{apertureMm:a,exposureSeconds:Math.min(i,zi.trailLimitedSeconds(o)),resolutionArcsec:o}}static resolutionArcsec(e,t,i){const s=(e.detailUm??zi.UNKNOWN_CAMERA_DETAIL_UM)/1e3/t*zi.ARCSEC_PER_RADIAN,a=1.22*zi.WAVELENGTH_M/(i/1e3)*zi.ARCSEC_PER_RADIAN;return Math.max(s,a)}static trailLimitedSeconds(e){return e/zi.skyDriftArcsecPerSecond}static gainOverEye(e,t={}){const i=zi.graspOf(e,t),n=zi.EYE,s=(i.apertureMm/n.apertureMm)**2,a=i.exposureSeconds/n.exposureSeconds,o=(n.resolutionArcsec/i.resolutionArcsec)**2;return 1.25*Math.log10(s*a*o)}static gainFor(e,t){const i=t.fieldOfViewDeg===void 0?void 0:si.focalLengthMmFor(e,t.fieldOfViewDeg);return zi.gainOverEye(e,{fNumber:t.fNumber,focalLengthMm:i,exposureSeconds:t.exposureSeconds})}}const fg=111320,vo=Math.PI/180,fA=1.02,pA=1;class Oo{static of(e,t){const i=Oo.sightings(e,t);if(i.length<2)return;const n=Oo.baseline(i);if(!n)return;const{near:s,far:a,closedM:o}=n,c=Math.tan(a.widthDeg/2*vo)===0?0:Math.tan(s.widthDeg/2*vo)/Math.tan(a.widthDeg/2*vo);if(c<fA)return;const l=o/(c-1),h=Et.sizeMAt(l,s.widthDeg),u=i.map(d=>({t:d.t,m:Et.distanceMAt(h,d.widthDeg)}));return{widthM:h,distanceM:u,nearestM:Math.min(...u.map(d=>d.m)),fromT:a.t,toT:s.t,closedM:o}}static sightings(e,t){return e.timeline.allKeyframes.flatMap(i=>{const n=i.shapes.find(o=>o.sourceId===t)?.shape,s=n?.angular?.widthDeg,a=jt(e,i.t);return s===void 0||s<=0||a?.lat===void 0||a.lng===void 0?[]:[{t:i.t,widthDeg:s,lat:a.lat,lng:a.lng,sightAzimuthDeg:n?.aim?.azimuthDeg??a.headingDeg}]}).sort((i,n)=>i.t-n.t)}static baseline(e){let t;for(const i of e)for(const n of e){if(i.t>=n.t)continue;const s=Oo.closedAlongSight(i,n),[a,o,c]=s>=0?[n,i,s]:[i,n,-s];c<pA||a.widthDeg<=o.widthDeg||(!t||c>t.closedM)&&(t={near:a,far:o,closedM:c})}return t}static closedAlongSight(e,t){const i=(t.lat-e.lat)*fg,n=(t.lng-e.lng)*fg*Math.cos(e.lat*vo),s=(e.sightAzimuthDeg??0)*vo;return i*Math.cos(s)+n*Math.sin(s)}}class ki{static CONVENTIONAL_M=5;static NEAREST_M=.2;static MARGIN=1.1;static resolve(e){if(e.statedM!==void 0&&e.statedM>0)return{distanceM:ki.atLeastNearest(e.statedM),basis:"stated"};if(e.hypothesisM!==void 0&&e.hypothesisM>0)return{distanceM:ki.atLeastNearest(e.hypothesisM),basis:"hypothesis"};if(e.derivedM!==void 0&&e.derivedM>0)return{distanceM:ki.atLeastNearest(e.derivedM),basis:"derived"};const t=ki.largest(e.range?.minM,e.crossing?.behindM),i=ki.smallest(e.range?.maxM,e.crossing?.inFrontM),n=t===void 0?void 0:t*ki.MARGIN,s=i===void 0?void 0:i/ki.MARGIN;return n!==void 0&&s!==void 0?{distanceM:ki.atLeastNearest(n<=s?Math.sqrt(n*s):n),basis:"bounded"}:n!==void 0?{distanceM:ki.atLeastNearest(n),basis:"bounded"}:s!==void 0&&s<ki.CONVENTIONAL_M?{distanceM:ki.atLeastNearest(s),basis:"bounded"}:{distanceM:ki.CONVENTIONAL_M,basis:"conventional"}}static atLeastNearest(e){return Math.max(ki.NEAREST_M,e)}static largest(...e){const t=e.filter(i=>i!==void 0&&i>0);return t.length===0?void 0:Math.max(...t)}static smallest(...e){const t=e.filter(i=>i!==void 0&&i>0);return t.length===0?void 0:Math.min(...t)}}const Au=Math.PI/180;class Qe{constructor(e,t,i){this.body=e,this.ground=t;const n=[...e.track].sort((s,a)=>s.t-a.t);this.keys=this.place(n,i);for(const s of n)Qe.collect(this.motionKeys,s.t,s.motions),Qe.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(e,t,i){for(const[n,s]of Object.entries(i??{})){const a=e.get(n)??[];a.push({t,value:s}),e.set(n,a)}}motionsAt(e){return Qe.channelsAt(this.motionKeys,e,0)}lightsAt(e){return this.lightKeys.size>0?Qe.channelsAt(this.lightKeys,e,void 0):void 0}static channelsAt(e,t,i){const n={};for(const[s,a]of e){let o=a.length-1;for(;o>=0&&a[o].t>t;)o--;if(o<0){i!==void 0&&(n[s]=i);continue}const c=a[o],l=a[Math.min(o+1,a.length-1)],h=l===c||l.t===c.t?0:Math.min(1,(t-c.t)/(l.t-c.t));n[s]=Qe.lerp(c.value,l.value,h)}return n}static eyeOf(e,t,i){const n=jt(e,0),s=jt(e,t),o=n?.lat!==void 0&&n.lng!==void 0&&s?.lat!==void 0&&s.lng!==void 0?ni(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)+Qe.EYE_HEIGHT_M+(s?.elevationM??0),headingDeg:s?.headingDeg}}static lineOfSightMeetsGround(e,t,i,n){const s=Qe.directionOf(t,i),a=l=>e.upM+s.upM*l-n.heightAt(e.eastM+s.eastM*l,e.northM+s.northM*l);let o=0,c=0;for(;c<Qe.MAX_RANGE_M;){if(c=o+Math.max(.5,o*.01),a(c)<=0){for(let l=0;l<30;l++){const h=(o+c)/2;a(h)<=0?c=h:o=h}return c}o=c}}static directionOf(e,t){const i=e*Au,n=t*Au;return{eastM:Math.sin(i)*Math.cos(n),northM:Math.cos(i)*Math.cos(n),upM:Math.sin(n)}}at(e){const t=this.keys;if(t.length===0||e<t[0].t)return;let i=t.length-1;for(;i>0&&t[i].t>e;)i--;const n=t[i];if(!n.present)return;const s=t[Math.min(i+1,t.length-1)],a=s===n||s.t===n.t?0:Math.min(1,(e-n.t)/(s.t-n.t)),o=Qe.lerp(n.eastM,s.eastM,a),c=Qe.lerp(n.northM,s.northM,a),l={widthM:Qe.lerp(n.sizeM.widthM,s.sizeM.widthM,a),lengthM:Qe.lerp(n.sizeM.lengthM,s.sizeM.lengthM,a),heightM:Qe.lerp(n.sizeM.heightM,s.sizeM.heightM,a)},h={headingDeg:Qe.lerpAngle(n.attitude.headingDeg,s.attitude.headingDeg,a),pitchDeg:Qe.lerp(n.attitude.pitchDeg,s.attitude.pitchDeg,a),rollDeg:Qe.lerp(n.attitude.rollDeg,s.attitude.rollDeg,a)};let u;if("aboveGroundM"in n.vertical&&"aboveGroundM"in s.vertical){const d=Qe.lerp(n.vertical.aboveGroundM,s.vertical.aboveGroundM,a);u=this.groundUnderFootprint(o,c,l,h.headingDeg)+d+l.heightM/2}else u=Qe.lerp(this.centreUpOf(n),this.centreUpOf(s),a);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:(a<1?n:s).appearance.color,albedo:Qe.lerp(n.appearance.albedo,s.appearance.albedo,a),luminanceCdM2:Qe.lerp(n.appearance.luminanceCdM2,s.appearance.luminanceCdM2,a)},flame:Qe.flameBetween(n.flame,s.flame,a),motions:this.motionsAt(e),lights:this.lightsAt(e),throwsFlame:this.body.track.some(d=>d.flame!==void 0&&d.flame.luminanceCdM2>0)}}static flameBetween(e,t,i){if(!e||e.luminanceCdM2<=0)return i>=1&&t&&t.luminanceCdM2>0?t:void 0;const n=e,s=t??e,a={...i<1?n:s,lengthM:Qe.lerp(n.lengthM,s.lengthM,i),widthM:Qe.lerp(n.widthM,s.widthM,i),luminanceCdM2:Qe.lerp(n.luminanceCdM2,s.luminanceCdM2,i)};return a.luminanceCdM2>0?a:void 0}centreUpOf(e){return"upM"in e.vertical?e.vertical.upM:this.groundUnderFootprint(e.eastM,e.northM,e.sizeM,e.attitude.headingDeg)+e.vertical.aboveGroundM+e.sizeM.heightM/2}groundUnderFootprint(e,t,i,n){const s=n*Au,a={eastM:Math.cos(s),northM:-Math.sin(s)},o={eastM:Math.sin(s),northM:Math.cos(s)};let c=this.ground.heightAt(e,t);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(e+a.eastM*u+o.eastM*d,t+a.northM*u+o.northM*d))}return c}place(e,t){const i=[];let n;for(const s of e){const a=s.sizeM??n?.sizeM??Qe.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??Qe.DEFAULT_APPEARANCE.color,albedo:s.appearance?.albedo??n?.appearance.albedo??Qe.DEFAULT_APPEARANCE.albedo,luminanceCdM2:s.appearance?.luminanceCdM2??n?.appearance.luminanceCdM2??Qe.DEFAULT_APPEARANCE.luminanceCdM2},l=this.positionOf(s,t)??(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:a,attitude:o,appearance:c,flame:h,present:u},i.push(n)}return i}verticalOf(e){if(e.onGround)return{aboveGroundM:0};if(e.altitudeAboveGroundM!==void 0)return{aboveGroundM:e.altitudeAboveGroundM}}positionOf(e,t){if(e.eastM!==void 0&&e.northM!==void 0)return{eastM:e.eastM,northM:e.northM,vertical:this.verticalOf(e)??{aboveGroundM:0}};if(e.azimuthDeg===void 0||e.altitudeDeg===void 0)return;const i=t(e.t);if(!i)return;const n=e.distanceM??(e.onGround?Qe.lineOfSightMeetsGround(i,e.azimuthDeg,e.altitudeDeg,this.ground):void 0);if(n===void 0)return;const s=Qe.directionOf(e.azimuthDeg,e.altitudeDeg),a=i.eastM+s.eastM*n,o=i.northM+s.northM*n;return{eastM:a,northM:o,vertical:this.verticalOf(e)??{upM:i.upM+s.upM*n}}}static lerp(e,t,i){return e+(t-e)*i}static lerpAngle(e,t,i){const n=((t-e)%360+540)%360-180;return((e+n*i)%360+360)%360}}const pr=Math.PI/180,Mo=180/Math.PI;class Zt{constructor(e){this.timeline=e}static DIRECTION_TOLERANCE_DEG=1;static SIZE_TOLERANCE=1.5;static RINGS=12;static SEGMENTS=24;at(e,t,i,n){const s=[];for(const a of t){const o=Zt.projectionOf(a,i,n?.(a));if(o)for(const c of a.explains){const l=this.timeline.getInterpolatedShapeAt(e,c);!l||l.transparency>=1||s.push({...Zt.compare(c,a.id,{aim:l.aim,angular:l.angular},o),title:l.title})}}return s}static compare(e,t,i,n){const s=[],a=i.aim?Zt.separationDeg(i.aim,n.aim):void 0;if(a!==void 0){const l=Math.max(i.angular?.widthDeg??0,n.angular.widthDeg)/2;a>Math.max(Zt.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&&!Zt.withinSize(o)&&s.push("width"),c!==void 0&&!Zt.withinSize(c)&&s.push("height"),{sourceId:e,bodyId:t,stated:i,predicted:n,separationDeg:a,widthRatio:o,heightRatio:c,disagreements:s}}static projectionOf(e,t,i){const n=i&&i.length>0?i:Zt.outlineOf(e),s=i&&i.length>0?Zt.centreOf(i):e,a=Zt.normalized({eastM:s.eastM-t.eastM,northM:s.northM-t.northM,upM:s.upM-t.upM});if(!a)return;const o=Zt.normalized({eastM:a.northM,northM:-a.eastM,upM:0})??{eastM:1,northM:0,upM:0},c=Zt.cross(o,a);let l=1/0,h=-1/0,u=1/0,d=-1/0;for(const f of n){const p={eastM:f.eastM-t.eastM,northM:f.northM-t.northM,upM:f.upM-t.upM},v=Zt.dot(p,a);if(v<=0)return;const m=Math.atan2(Zt.dot(p,o),v),g=Math.atan2(Zt.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(a.eastM,a.northM)*Mo+360)%360,altitudeDeg:Math.asin(Math.max(-1,Math.min(1,a.upM)))*Mo},angular:{widthDeg:(h-l)*Mo,heightDeg:(d-u)*Mo}}}static centreOf(e){const t=i=>(Math.min(...e.map(n=>n[i]))+Math.max(...e.map(n=>n[i])))/2;return{eastM:t("eastM"),northM:t("northM"),upM:t("upM")}}static separationDeg(e,t){const i=e.altitudeDeg*pr,n=t.altitudeDeg*pr,s=Math.sin(i)*Math.sin(n)+Math.cos(i)*Math.cos(n)*Math.cos((e.azimuthDeg-t.azimuthDeg)*pr);return Math.acos(Math.max(-1,Math.min(1,s)))*Mo}static withinSize(e){return e<=Zt.SIZE_TOLERANCE&&e>=1/Zt.SIZE_TOLERANCE}static outlineOf(e){const t=e.sizeM.widthM/2,i=e.sizeM.lengthM/2,n=e.sizeM.heightM/2,s=[],a=e.model.url===void 0?e.model.id:void 0;if(a!==void 0&&a!=="box"&&av.includes(a))for(let u=0;u<=Zt.RINGS;u++){const d=u/Zt.RINGS*Math.PI;for(let f=0;f<Zt.SEGMENTS;f++){const p=f/Zt.SEGMENTS*2*Math.PI;s.push([t*Math.sin(d)*Math.cos(p),i*Math.sin(d)*Math.sin(p),n*Math.cos(d)])}}else for(const u of[-t,t])for(const d of[-i,i])for(const f of[-n,n])s.push([u,d,f]);const c=e.attitude.headingDeg*pr,l=e.attitude.pitchDeg*pr,h=e.attitude.rollDeg*pr;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:e.eastM+p*Math.cos(c)+m*Math.sin(c),northM:e.northM-p*Math.sin(c)+m*Math.cos(c),upM:e.upM+g}})}static dot(e,t){return e.eastM*t.eastM+e.northM*t.northM+e.upM*t.upM}static cross(e,t){return{eastM:e.northM*t.upM-e.upM*t.northM,northM:e.upM*t.eastM-e.eastM*t.upM,upM:e.eastM*t.northM-e.northM*t.eastM}}static normalized(e){const t=Math.hypot(e.eastM,e.northM,e.upM);return t>1e-9?{eastM:e.eastM/t,northM:e.northM/t,upM:e.upM/t}:void 0}}Ug();const mA={sun:"Sun",moon:"Moon",Venus:"Venus",Mars:"Mars",Jupiter:"Jupiter",Saturn:"Saturn"},gA="{name} — mag {mag}, {alt}° above the horizon",vA="{name} — satellite, mag {mag}, {height} km up",MA="satellites-change",lv="rr0-confrontation",xA="{name} — mag {mag}, {alt}° below the horizontal",Tu="Credits",pg="comet:",mg="nova:",yA={building:"Building",tree:"Tree",shrub:"Shrub",bridge:"Bridge",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,_A=new URL(""+new URL("stars-mag7.5-9-BLV2tFmZ.bin",import.meta.url).href,import.meta.url).href,SA=-18,wA={sun:{altitudeDeg:-3,azimuthDeg:180,magnitude:-26.7},moon:{altitudeDeg:-90,azimuthDeg:0,phase:{phaseFraction:0,illuminatedFraction:0},magnitude:-12.7},planets:[]},Ru={lat:0,lng:0,elevationM:0,headingDeg:void 0,pitchDeg:0,fovDeg:60};class Z0 extends HTMLElement{creditsButton;set ownCredits(e){this.creditsButton.hidden=!e}static get observedAttributes(){return["src","star-catalog-src","deep-star-catalog-src","show-compass","max-pixel-ratio",Es,As]}shadow;stageElement;frameElement;sceneCanvas;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 Ii;satellitesFor;satelliteRequest=0;satelliteStatus="none";satellites;satellitePassesMemo;starCatalogDepth=0;weatherAudio=new lA;vehicleAudio=new jv;vehicleHearing=new Ml;animateWhilePausedValue=!1;set animateWhilePaused(e){e!==this.animateWhilePausedValue&&(this.animateWhilePausedValue=e,this.syncAnimationsToPlayback())}get animateWhilePaused(){return this.animateWhilePausedValue}thunderTimeoutId;handleFullscreenChange=()=>this.resizeToStage();handlePointerMove=e=>{this.sceneRenderer.setCompassHovered(!0);const t=this.ufoElement.canvasElement,i=t.getBoundingClientRect();if(i.width===0||i.height===0)return;const n=(e.clientX-i.left)/i.width*t.width,s=(e.clientY-i.top)/i.height*t.height;if(this.ufoElement.hasVisibleShapeAt(n,s)){this.hoverTooltip.hidden=!0;return}const a=(e.clientX-i.left)/i.width*2-1,o=-((e.clientY-i.top)/i.height*2-1),c=this.naming,l=c.names,h=this.sceneRenderer.pickBodyAt(a,o);if(h){this.showHoverTooltip(e,this.bodyName(h));return}const u=this.sceneRenderer.pickDecorAt(a,o),d=u?this.ufoElement.sighting.decor.find(v=>v.id===u):void 0;if(d){this.showHoverTooltip(e,this.said.read(d.title)||c.decorKind(d.kind,yA[d.kind]));return}const f=this.sceneRenderer.pickSatelliteAt(a,o);if(f){this.showHoverTooltip(e,(l?.satelliteTooltip??vA).replace("{name}",f.name).replace("{mag}",f.magnitude.toLocaleString(void 0,{maximumFractionDigits:1})).replace("{height}",Math.round(f.heightKm).toLocaleString()));return}const p=this.sceneRenderer.pickStarAt(a,o);if(p){const v=p.star.mag,m=p.altitudeDeg,g=m<0?l?.starTooltipBelow??xA:l?.starTooltip??gA;this.showHoverTooltip(e,g.replace("{name}",c.star(p.star)).replace("{mag}",v.toLocaleString(void 0,{maximumFractionDigits:Math.abs(v)<1?2:1})).replace("{alt}",String(Math.round(Math.abs(m)))));return}this.hoverTooltip.hidden=!0};bodyName(e){const t=e.startsWith(pg)?e.slice(pg.length):void 0,i=t?cv.find(a=>a.id===t):void 0;if(i)return this.naming.comet(i);const n=e.startsWith(mg)?ug.byId(e.slice(mg.length)):void 0;if(n)return this.naming.nova(n);const s=mA[e];return s===void 0?e:this.naming.body(e,s)}get naming(){return this.sceneNaming}sceneNaming=new Hl;namesLanguage="en";async loadSceneNames(){const e=o0(Fr.preferencesFor(this),c0);if(e===this.namesLanguage)return;this.namesLanguage=e;const t=await Ag(e);e===this.namesLanguage&&this.applySceneNaming(new Hl(t))}applySceneNaming(e){this.sceneNaming=e;const t=e.names?.credits??Tu;this.creditsButton.title=t,this.creditsButton.setAttribute("aria-label",t),this.sceneRenderer.setCompassPoints(e.names?.compassPoints)}showHoverTooltip(e,t){this.hoverTooltip.textContent=t,this.hoverTooltip.hidden=!1;const i=this.stageElement.getBoundingClientRect();this.hoverTooltip.style.left=`${e.clientX-i.left+12}px`,this.hoverTooltip.style.top=`${e.clientY-i.top+12}px`}handlePointerLeave=()=>{this.hoverTooltip.hidden=!0,this.sceneRenderer.setCompassHovered(!1)};handleLightningFlash(e){clearTimeout(this.thunderTimeoutId),this.thunderTimeoutId=window.setTimeout(()=>this.weatherAudio.playThunder(),di.thunderDelayMs(e))}handleFirstInteraction=()=>{this.removeEventListener("pointerdown",this.handleFirstInteraction,!0),this.removeEventListener("keydown",this.handleFirstInteraction,!0),this.weatherAudio.resume(),this.vehicleAudio.resume(),this.setWeather(uf(this.ufoElement.sighting,this.lastTimeMs))};handleTimeUpdate=e=>{this.lastTimeMs=e.detail.time,this.syncAnimationsToPlayback(),this.updateAstronomy(this.lastTimeMs),this.ufoElement.playbackState==="playing"&&this.sceneRenderer.frame(performance.now())};syncAnimationsToPlayback(){const e=this.ufoElement.playbackState==="playing",t=e||this.animateWhilePaused;this.sceneRenderer.setAnimationsRunning(t,e),this.weatherAudio.setPaused(!t),this.vehicleAudio.setPaused(!t),t||clearTimeout(this.thunderTimeoutId)}constructor(){super(),this.shadow=this.attachShadow({mode:"open"});const e=document.createElement("template");e.innerHTML=`<style>${e2}</style>${Qv}`,this.shadow.appendChild(e.content.cloneNode(!0)),this.stageElement=this.shadow.getElementById("stage"),this.frameElement=this.shadow.getElementById("frame"),this.sceneCanvas=this.shadow.getElementById("scene-canvas"),this.sceneRenderer=new zt(this.sceneCanvas);const t=this.shadow.getElementById("scene-loader");this.sceneRenderer.onFirstFrameHold=s=>{t.hidden=!s},this.hoverTooltip=this.shadow.getElementById("hover-tooltip"),this.ufoElement=document.createElement(Lu),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"&&Dn.fill(n,this)}),this.creditsButton.title=Tu,this.creditsButton.setAttribute("aria-label",Tu),this.sceneRenderer.onMapSubjectBounds=s=>this.ufoElement.setMapSubjectBounds(s),this.ufoElement.addEventListener("timeupdate",this.handleTimeUpdate),this.ufoElement.addEventListener("referenceview",s=>this.applyReferenceView(s.detail)),this.ufoElement.canvasElement.addEventListener("pointermove",this.handlePointerMove),this.ufoElement.canvasElement.addEventListener("pointerleave",this.handlePointerLeave),this.addEventListener("pointerdown",this.handleFirstInteraction,!0),this.addEventListener("keydown",this.handleFirstInteraction,!0)}get said(){return this.saidTexts??=new On(Fr.preferencesFor(this))}saidTexts;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),document.addEventListener("fullscreenchange",this.handleFullscreenChange);const e=this.getAttribute("src");e&&this.loadFromSrc(e)}disconnectedCallback(){this.resizeObserver?.disconnect(),document.removeEventListener("fullscreenchange",this.handleFullscreenChange),this.sceneRenderer.stopTwinkle(),clearTimeout(this.thunderTimeoutId),this.weatherAudio.dispose(),this.vehicleAudio.dispose(),queueMicrotask(()=>{this.isConnected||this.sceneRenderer.releaseContext()})}attributeChangedCallback(e,t,i){if(e==="src"&&i&&i!==t&&this.isConnected&&this.loadFromSrc(i),(e==="star-catalog-src"||e==="deep-star-catalog-src")&&i!==t&&this.isConnected&&this.loadStars(),e==="show-compass"&&i!==t&&this.sceneRenderer.setShowCompass(this.hasAttribute("show-compass")),e==="max-pixel-ratio"&&i!==t){const n=Number(i);this.sceneRenderer.setMaxPixelRatio(Number.isFinite(n)&&n>0?n:Math.min(window.devicePixelRatio||1,2))}(e===Es||e===As)&&i!==t&&this.forwardPlayerAttributes()}forwardPlayerAttributes(){for(const e of[Es,As]){const t=this.getAttribute(e);t===null?this.ufoElement.removeAttribute(e):this.ufoElement.setAttribute(e,t)}}setCompassForced(e){this.sceneRenderer.setCompassForced(e)}lookToward(e){const t=jt(this.ufoElement.sighting,this.lastTimeMs);if(e.kind==="observer"||t?.lat===void 0||t.lng===void 0||t.headingDeg===void 0){this.setLookOffset(0,0);return}const{x:i,z:n}=ni(e.lat,e.lng,t.lat,t.lng);if(Math.hypot(i,n)<1)return this.setLookOffset(0,0);const s=(Math.atan2(i,-n)*180/Math.PI+360)%360;this.setLookOffset(((s-t.headingDeg)%360+540)%360-180,-t.pitchDeg)}setLookOffset(e,t){this.sceneRenderer.setLookOffset(e,t),this.ufoElement.setLookOffset(e,t),this.updateAstronomy(this.lastTimeMs)}setIndoorLook(e,t){this.sceneRenderer.setIndoorLook(e,t)}setCloudRendering(e){this.sceneRenderer.setCloudRendering(e)}setWeather(e){this.sceneRenderer.setWeather(e),this.weatherAudio.setAmbient(e.precipitationType,e.precipitationIntensity*(e.precipitationAmount??1),e.windSpeed)}pickCloudAt(e,t){return this.sceneRenderer.pickCloudAt(e,t)}cloudDirectionAt(e,t){return this.sceneRenderer.cloudDirectionAt(e,t)}pickDecorAt(e,t){return this.sceneRenderer.pickDecorAt(e,t)}bodyScreenBox(e){return this.sceneRenderer.bodyScreenBox(e)}pickPlacedBodyAt(e,t){return this.sceneRenderer.pickPlacedBodyAt(e,t)}resumeWeatherAudio(){this.weatherAudio.resume(),this.vehicleAudio.resume()}async loadFromSrc(e){const t=await Ao.json(e);this.documentUrl=new URL(e,location.href).href,this.sightingData=t}get documentUrl(){return this.sceneRenderer.documentUrl}set documentUrl(e){this.sceneRenderer.documentUrl=e}get sightingData(){return this.ufoElement.sightingData}set sightingData(e){this.ufoElement.sightingData=e,this.interpretationShown=this.inTheRound?this.ufoElement.sighting.interpretation:void 0,this.applyFrameFormat(),this.lastTimeMs=0,this.sceneRenderer.compileNextFrameOffThread(),this.updateAstronomy(0)}referenceAspect(e){return this.sceneRenderer.referenceAspect(e)}screenPointOf(e){return this.sceneRenderer.screenPointOf(e)}directionAt(e,t){return this.sceneRenderer.directionAt(e,t)}referenceFailedToLoad(e){return this.sceneRenderer.referenceFailedToLoad(e)}applyReferenceView(e){this.sceneRenderer.setReferencesShown(e.shown);for(const t of this.ufoElement.sighting.references)this.sceneRenderer.setReferenceView(t.id,{opacity:e.opacity})}get currentTerrainAttribution(){return this.sceneRenderer.currentTerrainAttribution}get currentRoadAttribution(){return this.sceneRenderer.currentRoadAttribution}setTerrainProviders(e){this.sceneRenderer.setTerrainProviders(e)}setDecorModelProvider(e){this.sceneRenderer.setDecorModelProvider(e)}get decorModelCredits(){return this.sceneRenderer.currentDecorModelCredits}applyFrameFormat(){const e=this.ufoElement.sighting.instrument,t=Et.CANVAS_HEIGHT_PX,i=si.frameWidthPx(e,t);this.frameElement.style.setProperty("--frame-aspect",`${i} / ${t}`)}resizeToStage(){const e=this.frameElement.getBoundingClientRect(),t=Math.max(1,Math.round(e.width)),i=Math.max(1,Math.round(e.height));this.sceneCanvas.width=t,this.sceneCanvas.height=i,this.sceneRenderer.resize(t,i)}async loadStars(){const e=[{magnitudeLimit:_u,url:this.getAttribute("star-catalog-src")??bA},{magnitudeLimit:Su,url:this.getAttribute("deep-star-catalog-src")??_A}],t=this.instrumentReach(),i=++this.starCatalogRequest;this.starCatalogDepth=t>_u?Su:_u;const n=await Kn.upTo(e,t);i===this.starCatalogRequest&&(this.starCatalog=n,this.sceneRenderer.compileNextFrameOffThread(),this.updateAstronomy(this.lastTimeMs))}ensureStarsDeepEnough(){!this.starCatalog||this.starCatalogDepth>=Su||this.instrumentReach()<=this.starCatalogDepth||this.loadStars()}instrumentReach(){const e=this.ufoElement.sighting,t=zi.gainFor(e.instrument,{fNumber:jt(e,0)?.fNumber,fieldOfViewDeg:ji.fovOf(e,0),exposureSeconds:e.exposure});return Ld(SA,t)}updateAstronomy(e){this.ensureStarsDeepEnough(),this.applySceneAt(e);const t=Pn.windowEndingAt(e,this.exposureSeconds()),i=t.seconds,n=this.degreesPerPixelAt(e),s=Fa.instants(i,n),a=Math.max(s,this.ufoElement.exposureTimes(e).length,Pn.instants(this.ufoElement.sighting.decor,jt(this.ufoElement.sighting,e)?.elevationM??0,t.fromMs,i,n));if(a<=1){this.sceneRenderer.setExposure(1);return}this.sceneRenderer.setExposure(a,o=>this.applySceneAt(t.fromMs+t.ms*o/(a-1),{sky:Math.floor(o*s/a)!==Math.floor((o-1)*s/a),stepMs:t.ms/a}))}exposureSeconds(){return this.ufoElement.sighting.exposure??0}degreesPerPixelAt(e){const t=this.sceneCanvas.height;return t<=0?0:ji.fovOf(this.ufoElement.sighting,e)/t}applySceneAt(e,t){const i=this.ufoElement.sighting;this.setWeather(uf(i,e)),this.sceneRenderer.setInstrument(i.instrument),this.sceneRenderer.setLightPollution(i.lightPollution),t||this.vehicleAudio.setVoices(this.vehicleHearing.at(i,e)),this.updateMeteorShower(i,e),this.updateLightning(i,e,t!==void 0),this.sceneRenderer.setDecor(i.decor);const n=jt(i,e);this.sceneRenderer.setReferences(i.references,n?.lat!==void 0&&n.lng!==void 0?{lat:n.lat,lng:n.lng}:void 0);const s=jt(i,0),a=mr(i,0),o=Object.fromEntries(gl(mr(i,e)).map(b=>[b.id,yf(e,i.weatherTrack,a,s,n,b.id)]));this.sceneRenderer.setCloudOffset(yf(e,i.weatherTrack,a,s,n),o),this.sceneRenderer.setObserverPose(n??Ru),this.sceneRenderer.setLensOptics(this.lensOpticsAt(e)),this.sceneRenderer.setInstrumentGain(zi.gainFor(i.instrument,{fNumber:n?.fNumber,fieldOfViewDeg:ji.fovOf(i,e),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(xt.bodyAt(i,e,this.ufoElement.steadyObserver)),this.sceneRenderer.updateDecorAnchoring(jt(i,0),n,e),this.placeBodiesAt(e,t===void 0),this.sceneRenderer.updateDecorLitState(e,t?.stepMs??0),this.sceneRenderer.setTerrainOrigin(n?.lat,n?.lng,()=>{this.placeBodiesAt(this.lastTimeMs,!0),this.sceneRenderer.render()}),this.sceneRenderer.setStatedRoads(i.roads),this.pushPhenomenaAt(e);const c=n?.lat??Ru.lat,l=n?.lng??Ru.lng,h=So(i.event.time??{},l,i.event.utcOffsetHours),u={lat:c,lng:l,elevationM:n?.elevationM??0};if(this.pushSatellitesAt(h,e,u),t&&!t.sky)return;if(!h){this.sceneRenderer.setAstronomy(wA);return}const d=new Date(h.getTime()+e),f=Math.max(1,Math.round(.25*this.degreesPerPixelAt(e)/Fa.DEG_PER_SECOND*1e3)),p=Math.max(1e-8,this.degreesPerPixelAt(e)*.1),v=`${Math.floor(d.getTime()/f)}|${Math.round(c/p)}|${Math.round(l/p)}|${Math.round(u.elevationM)}|${this.starCatalog?this.starCatalogDepth:0}`;if(v===this.lastSkyKey){this.sceneRenderer.render();return}this.lastSkyKey=v;const m={...Qh("Sun",d,u),magnitude:eu("Sun",d)},g={...Qh("Moon",d,u),phase:h5(d),magnitude:eu("Moon",d)},_=l5.map(b=>({body:b,position:Qh(b,d,u),magnitude:eu(b,d)}));this.sceneRenderer.setAstronomy({sun:m,moon:g,planets:_,comet:this.cometAt(d,u),novae:ug.appearancesAt(d,u).map(({outburst:b,position:M,magnitude:S})=>({id:b.id,position:M,magnitude:S})),stars:this.starCatalog?{catalog:this.starCatalog,date:d,observer:u}:void 0,frame:{date:d,observer:u}}),this.ufoElement.setSunAltitude(m.altitudeDeg)}pushSatellitesAt(e,t,i){if(this.ensureSatellites(e),!e||!this.satellites){this.sceneRenderer.setSatellites([]);return}const n=new Date(e.getTime()+t),s=[];for(const a of this.satellites.passes.positionsAt(n,i,-1))a.magnitude!==void 0&&s.push({norad:a.object.norad,name:a.object.name,position:{altitudeDeg:a.altitudeDeg,azimuthDeg:a.azimuthDeg},magnitude:a.magnitude,heightKm:a.heightKm});this.sceneRenderer.setSatellites(s)}ensureSatellites(e){const t=e?String(e.getTime()):"";if(t===this.satellitesFor)return;this.satellitesFor=t,this.satellites=void 0,this.satellitePassesMemo=void 0;const i=++this.satelliteRequest;if(!e){this.satelliteStatus="none";return}this.satelliteStatus="loading";const n=a=>{i===this.satelliteRequest&&(this.satelliteStatus=a,this.isConnected&&this.dispatchEvent(new CustomEvent(MA)))},s=Z0.tleArchive;(async()=>{if(!await s.covers(e))return n("outside");const[a,o]=await Promise.all([s.at(e),pi(()=>import("./SatellitePasses-Pfro2-0Z.js"),[],import.meta.url)]);if(i===this.satelliteRequest){if(!a)return n("unavailable");this.satellites={snapshot:a,passes:new o.SatellitePasses(a.objects)},n("ready"),this.isConnected&&this.updateAstronomy(this.lastTimeMs)}})().catch(()=>n("unavailable"))}get satelliteState(){const e=this.satellites?.snapshot;return{status:this.satelliteStatus,coverage:e?.coverage,credit:e?.credit,creditUrl:e?.creditUrl}}satellitePassesDuring(e){const t=this.satellites,i=this.ufoElement.sighting,n=jt(i,0),s=i.event.place?.[0],a=n?.lat??s?.lat,o=n?.lng??s?.lng;if(!t||a===void 0||o===void 0)return[];const c=So(i.event.time??{},o,i.event.utcOffsetHours);if(!c)return[];const l=Math.min(Math.max(e,0),4*36e5),h={lat:a,lng:o,elevationM:n?.elevationM??0},u=JSON.stringify([this.satellitesFor,c.getTime(),a,o,h.elevationM,l]);if(this.satellitePassesMemo?.key===u)return this.satellitePassesMemo.passes;const d=Math.max(10,Math.ceil(l/1e3/600)),f=t.passes.passesDuring(c,new Date(c.getTime()+l),h,d);return this.satellitePassesMemo={key:u,passes:f},f}cometAt(e,t){const i=hA.brightestAt(e,t);if(i)return{id:i.apparition.id,position:i.position,tailEnd:i.tailEnd,magnitude:i.magnitude}}pushPhenomenaAt(e){const t=this.ufoElement.sighting;t!==this.sizeEstimatesFor&&(this.sizeEstimates.clear(),this.distanceHypotheses.clear(),this.sizeEstimatesFor=t);const i=t.timeline,n=this.ufoElement.canvasElement,s=this.ufoElement.frameShiftPx,a=this.projectionAt(e),o=new Map,c=new Map,l=new Set;for(const p of i.sourceIds){const v=i.getInterpolatedShapeAt(e,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(Cn.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)},_=g!==void 0&&Math.abs(g.ndcX)<=1&&Math.abs(g.ndcY)<=1,b=_?this.sceneRenderer.decorDistancesAt(g.ndcX,g.ndcY,p):{};l.add(p),(_||v.aim)&&l.delete(p);const M=v.angular?.widthDeg??a.pxToDeg(v.bounds.width),S=this.sizeEstimateOf(p);S.add(M,b);const w=Oo.of(t,p);c.set(p,ki.resolve({hypothesisM:this.distanceHypotheses.get(p),derivedM:w&&M>0?Et.distanceMAt(w.widthM,M):void 0,range:S.distanceRangeAt(M),crossing:b}))}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 b=c.get(m);b&&c.set(p,{distanceM:b.distanceM*.999,basis:b.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=(jt(t,e)?.rollDeg??0)+xt.bodyAt(t,e,this.ufoElement.steadyObserver).rollDeg;this.sceneRenderer.setPhenomena(u,{projection:a,canvasWidthPx:n.width,canvasHeightPx:n.height,scale:Math.max(1,this.sceneCanvas.height/Math.max(1,n.height)),starPoints:si.starPointsOf(t.instrument),rollRad:f*Math.PI/180})}get interpretation(){return this.interpretationShown}set interpretation(e){this.interpretationShown=e,this.updateAstronomy(this.lastTimeMs)}get accountInTheRound(){return this.inTheRound}set accountInTheRound(e){this.inTheRound=e}get compareAccount(){return this.comparing}set compareAccount(e){this.comparing=e,this.updateAstronomy(this.lastTimeMs)}get confrontation(){return this.confrontationReadings}groundAlong(e,t,i){const n=this.sceneRenderer.bodyGround,s=Qe.eyeOf(this.ufoElement.sighting,i,n);return s?Qe.lineOfSightMeetsGround(s,e,t,n):void 0}bodyReading(e,t){const i=this.sceneRenderer.bodyGround,n=this.ufoElement.sighting,s=d=>Qe.eyeOf(n,d,i),a=new Qe(e,i,s).at(t),o=s(t);if(!a||!o)return;const c=a.eastM-o.eastM,l=a.northM-o.northM,h=a.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:a.eastM,northM:a.northM,aboveGroundM:a.upM-a.sizeM.heightM/2-i.heightAt(a.eastM,a.northM),sizeM:a.sizeM,attitude:a.attitude,appearance:a.appearance}}directionToBody(e,t){const i=this.sceneRenderer.bodyGround,n=this.ufoElement.sighting,s=p=>Qe.eyeOf(n,p,i),a=new Qe(e,i,s),o=a.at(t)?t:e.track[0]?.t,c=o===void 0?void 0:a.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(e,t){const i=this.interpretationShown,n=this.ufoElement.sighting;let s=[],a=[];const o=this.sceneRenderer.bodyGround,c=p=>Qe.eyeOf(n,p,o);i&&(s=i.bodies.map(p=>new Qe(p,o,c).at(e)).filter(p=>p!==void 0));const l=mr(n,e),h=l.windDirectionDeg*Math.PI/180,u={x:l.windSpeed*Math.sin(h),z:-l.windSpeed*Math.cos(h)};this.sceneRenderer.setBodies(s,e/1e3,i?.bodies.map(p=>p.id)??[],i?.smoke??[],u);const d=i&&this.comparing?c(e):void 0;if(d&&(a=new Zt(n.timeline).at(e,s,d,p=>p.outlineNode?this.sceneRenderer.bodyOutline?.(p.id,p.outlineNode):void 0)),this.confrontationReadings=a,!t)return;const f=JSON.stringify(a);f!==this.confrontationSignature&&(this.confrontationSignature=f,this.dispatchEvent(new CustomEvent(lv,{detail:a})))}setDistanceHypothesis(e,t){t===void 0||!(t>0)?this.distanceHypotheses.delete(e):this.distanceHypotheses.set(e,t),this.updateAstronomy(this.lastTimeMs)}depthOf(e){return this.depths.get(e)}sizeRangeOf(e){return this.sizeEstimateOf(e).sizeRange}distanceRangeAt(e,t){const i=this.ufoElement.sighting.timeline.getInterpolatedShapeAt(t,e);if(!i)return{};const n=i.angular?.widthDeg??this.projectionAt(t).pxToDeg(i.bounds.width);return this.sizeEstimateOf(e).distanceRangeAt(n)}sizeContradictory(e){return this.sizeEstimateOf(e).contradictory}updateMeteorShower(e,t){this.ensureMeteorSchedule(e),this.sceneRenderer.updateMeteors(t)}updateLightning(e,t,i){if(this.ensureLightningSchedule(e),this.sceneRenderer.updateLightning(t),i)return;const n=this.lastLightningT;if(this.lastLightningT=t,n===void 0||t<n||this.ufoElement.playbackState!=="playing")return;const s=this.lightningFlashes.filter(a=>a.t>n&&a.t<=t).pop();s&&mr(e,s.t).storm&&this.handleLightningFlash(s)}ensureLightningSchedule(e){const t=mr(e,0).precipitationIntensity,i=`${this.meteorInputsOf(e)}|${t}`;if(i===this.lightningScheduleFor)return;this.lightningScheduleFor=i;const n=e.event.time,s=e.event.place?.[0],a=n?.year!==void 0?So(n,s?.lng??0,e.event.utcOffsetHours):void 0,o=(e.event.durationSeconds??0)*1e3||e.timeline.duration||2e4,c=Math.round((a?.getTime()??0)/1e3)+Math.round((s?.lat??0)*1e3)+7;this.lightningFlashes=di.schedule({durationMs:o,seed:c,intensity:t}),this.sceneRenderer.setLightning(this.lightningFlashes)}ensureMeteorSchedule(e){const t=this.meteorInputsOf(e);t!==this.meteorScheduleFor&&(this.meteorScheduleFor=t,this.scheduleMeteors(e))}meteorInputsOf(e){const t=e.event.place?.[0],i=e.event.time;return JSON.stringify([t?.lat,t?.lng,i?.year,i?.month,i?.day,i?.hour,i?.minute,i?.second,e.event.utcOffsetHours,e.event.durationSeconds,e.timeline.duration])}scheduleMeteors(e){const t=e.event.place?.[0],i=e.event.time,n=t?.lat!==void 0&&t.lng!==void 0&&i?.year!==void 0?So(i,t.lng,e.event.utcOffsetHours):void 0;if(!n||t?.lat===void 0||t.lng===void 0){this.sceneRenderer.setMeteorShower([],0,0);return}const s={lat:t.lat,lng:t.lng,elevationM:0},a=(e.event.durationSeconds??0)*1e3||e.timeline.duration||2e4,o=Math.round(n.getTime()/1e3)+Math.round(t.lat*1e3),c=Jt.schedule({ratePerHour:Jt.observedRatePerHour(Jt.apexPosition(n,s).altitudeDeg),durationMs:a,velocityKmS:Jt.TYPICAL_VELOCITY_KM_S,seed:o}),l=Eu.activeAt(n).map(u=>{const d=Eu.radiantPosition(u.shower,n,s);return{entry:u,position:d,rate:Eu.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=Oa.schedule({ratePerHour:l.rate,durationMs:a,velocityKmS:l.entry.shower.velocityKmS,seed:o+1});this.sceneRenderer.setMeteorShower([...h,...c],l.position.altitudeDeg,l.position.azimuthDeg)}meteorByRank(e){this.ensureMeteorSchedule(this.ufoElement.sighting);const t=[...this.sceneRenderer.meteorSchedule].filter(s=>s.t+s.durationMs<=this.ufoElement.seekableDuration).sort((s,a)=>a.brightness-s.brightness);if(t.length===0)return;const i=t[e%t.length],n=this.sceneRenderer.meteorMidpoint(i);if(n)return{t:Math.round(i.t+i.durationMs*.45),...n}}lensOpticsAt(e){const t=this.ufoElement.sighting,i=t.instrument,n=i.frame,s=jt(t,e),a=s?.fNumber??i.fNumber;if(!n||a===void 0)return;const o=si.focalLengthMmFor(i,ji.fovOf(t,e));if(o!==void 0)return{focalLengthMm:o,fNumber:a,focusDistance:s?.focusDistanceM??0,frameHeightMm:n.heightMm}}projectionAt(e){const t=this.ufoElement.sighting;return Ss.of(t.instrument,Et.CANVAS_HEIGHT_PX,ji.fovOf(t,e))}sizeEstimateOf(e){let t=this.sizeEstimates.get(e);return t||(t=new dA,this.sizeEstimates.set(e,t)),t}}const n0="rr0-scene";function hv(){Ug(),customElements.get(n0)||customElements.define(n0,Z0)}const EA={color:"Color",transparency:"Transparency",halo:"Halo",blur:"Blur",brightness:"Brilliance",shapeTitle:"Name",utcOffset:"Time zone",cloudBase:"Cloud base",elevation:"Altitude",heightAboveGround:"Height above ground",duration:"Duration",placeName:"Place",latitude:"Latitude",longitude:"Longitude",heading:"Heading",pitch:"Tilt",roll:"Roll",sway:"Sway at rest",swayTitle:"How much the body holding the instrument moves the view when not walking: 1 for a person standing, 0 for a tripod. Blank: 1 (0 if the account says the observer was paralysed)",lightPollution:"Night sky",lightPollutionTitle:'The zenith of a moonless night at this place, in magnitudes per square arcsecond, as a Sky Quality Meter reads it or as the World Atlas of artificial sky brightness (Falchi et al. 2016, lightpollutionmap.info, "SQM") gives it. 22 is a natural sky; a suburb is about 19, a city centre 17. Blank: a natural sky',observationTime:"Observation start",observationEndTime:"Observation end",assessmentGroup:"Assessment",assessmentNames:{coverage:"Observer info"},assessmentVerdicts:{"hynek.nl":"NL — nocturnal light","hynek.dd":"DD — daylight disc","hynek.rv":"RV — radar-visual","hynek.ce1":"CE1 — close encounter","hynek.ce2":"CE2 — with a physical trace","hynek.ce3":"CE3 — with entities"},observerGroup:"Observer",observerId:"ID",observerTitle:"Title",observerLastName:"Last name",observerFirstNames:"First names",sightingId:"ID",tags:"Tags",cloudCover:"Cloud cover",highCloudCover:"Ice cloud (cirrus)",focalLength:"Focal length",fieldOfView:"Field of view",aperture:"Aperture",exposure:"Exposure",focusDistance:"Focused at",iceCrystalAlignment:"Crystal alignment",cloudDarkness:"Cloud darkness",precipitationType:"Precipitation",precipitationNone:"None",precipitationRain:"Rain",precipitationSnow:"Snow",precipitationHail:"Hail",precipitationIntensity:"Intensity",windDirection:"Wind direction",windSpeed:"Wind speed",storm:"Storm",cloudsGroup:"Clouds",precipitationGroup:"Precipitation",windGroup:"Wind",soundKind:"Sound",soundNone:"None (silent)",soundHum:"Hum",soundWhistle:"Whistle",soundRumble:"Rumble",soundCrackle:"Crackle",soundVolume:"Loudness",soundPitch:"Pitch",soundSrc:"Recording",instrument:"Observed through",decorAircraft:"Aircraft",decorEntity:"Being",decorAltitude:"Altitude",decorLights:"Lights",decorLightsNone:"none",decor:"Environment",decorBuilding:"Building",decorTree:"Tree",decorShrub:"Shrub",decorBridge:"Bridge",decorCrop:"Crop row",decorMound:"Stone heap",decorStreetlight:"Streetlight",decorVehicle:"Vehicle",decorObserver:"Other observer",decorEast:"Distance east",decorNorth:"Distance north",decorHeading:"Heading",decorColor:"Colour",decorLit:"Lit",decorTitle:"Name",milestones:"Moments",milestoneLabel:"Label",milestoneNote:"What happens",addMilestone:"Name this moment",deleteMilestone:"Delete moment",goToMilestone:"Go to this moment",confirmAccept:"Delete",confirmDecline:"Cancel",decorWidth:"Width",decorLength:"Length",decorHeight:"Height",decorModel:"3D model",decorModelNone:"Built-in shape",decorModelAdvanced:"Model from an address",decorModelFromCatalogue:"From the catalogue, which the recording names it by. Change a field and it becomes this recording's own address.",decorModelUrl:"glTF/GLB address",decorModelTitle:"Model name",decorModelAuthor:"Author",decorModelLicense:"Licence",decorModelSource:"Where it came from",decorFloors:"Floors",decorOccupiedFloor:"Occupied floor",decorObserverSide:"Observer location",decorObserverSideNone:"Not present",decorWindows:"Windows",decorSideFront:"Front",decorSideBehind:"Behind",decorSideLeft:"Left",decorSideRight:"Right",decorSideFrontLeft:"Front-left",decorSideFrontRight:"Front-right",decorSideBehindLeft:"Behind-left",decorSideBehindRight:"Behind-right"},ml={...EA,accountBy:"Account by",unnamedObserver:"Observer {n}",about:"About",close:"Close",observation:"Observation",date:"Date",location:"Location",case:"Case",description:"Description",source:"Source",accountSource:"Go to the source: {source}",credits:"Credits",editThisObservation:"Edit this observation",embed:"Embed",embedReplay:"Replay",embedEdit:"Editor",embedCopy:"Copy",embedCopied:"Copied",showLabels:"Show what it states",interpretation:"Interpretation",account:"Account",interpretationBy:"{title}, by {by}",confrontation:"Against the account",confrontationDirection:"{deg}° off",confrontationWidth:"width ×{ratio}",confrontationHeight:"height ×{ratio}",showComparison:"Compare with the account",hideComparison:"Stop comparing with the account",hideLabels:"Hide what it states"},AA=Object.freeze(Object.defineProperty({__proto__:null,sightingMessages_en:ml},Symbol.toStringTag,{value:"Module"}));hv();const uv="https://ufoathome.org",Du="compare-account",Iu="account",gg=`${uv}/edit/`;class ah extends HTMLElement{static get observedAttributes(){return["src","show-labels",Es,As,Du]}shadow;sceneElement;toolbarElement;accountElement;accountPrefix;observerText;observerSelect;infoButton;infoPanel;infoAppLink;editLink;accountSourceLink;infoObservationHeading;infoObservationList;infoCreditsToggle;infoCreditsList;infoCloseButton;infoEmbedToggle;infoEmbedPanel;embedReplayRadio;embedEditRadio;labelEmbedReplay;labelEmbedEdit;embedMarkup;embedCopyButton;labelsToggle;paramSummary;summaryBuilder=new gf(ml,new Hl,new On(["en"]),new sl({}));summarySignature="";assessmentEntries=[];assessmentToken=0;supportsPopover=typeof HTMLElement.prototype.showPopover=="function";entries=[];caseSource;interpretationChoice;interpretationLabel;interpretationSelect;confrontationElement;confrontationHeading;confrontationList;compareButton;interpretationLoaders=new Map;interpretationToken=0;offeredFor;currentSrc;infoOpen=!1;creditsOpen=!1;embedOpen=!1;labelsShown=!1;language="en";messages=ml;constructor(){super(),this.shadow=this.attachShadow({mode:"open"});const e=document.createElement("template");e.innerHTML=`<style>${yv}</style>${xv}`,this.shadow.appendChild(e.content.cloneNode(!0)),this.sceneElement=document.createElement(n0),this.forwardPlayerAttributes(),this.sceneElement.ufoElement.creditShownExternally=!0,this.sceneElement.ownCredits=!1,this.sceneElement.ufoElement.hostControls(this.shadow.getElementById("scene-controls")),this.shadow.getElementById("ufo-slot").replaceWith(this.sceneElement),this.toolbarElement=this.shadow.getElementById("toolbar"),this.accountElement=this.shadow.getElementById("account"),this.accountPrefix=this.shadow.getElementById("account-prefix"),this.observerText=this.shadow.getElementById("observer-text"),this.observerSelect=this.shadow.getElementById("observer"),this.infoButton=this.shadow.getElementById("info-button"),this.infoPanel=this.shadow.getElementById("info-panel"),this.infoAppLink=this.shadow.getElementById("info-app-link"),this.editLink=this.shadow.getElementById("edit-link"),this.accountSourceLink=this.shadow.getElementById("account-source"),this.infoObservationHeading=this.shadow.getElementById("info-observation-heading"),this.infoObservationList=this.shadow.getElementById("info-observation-list"),this.infoCreditsToggle=this.shadow.getElementById("info-credits-toggle"),this.infoCreditsList=this.shadow.getElementById("info-credits-list"),this.infoCloseButton=this.shadow.getElementById("info-close"),this.labelsToggle=this.shadow.getElementById("info-labels-toggle"),this.paramSummary=this.shadow.getElementById("param-summary"),this.labelsToggle.addEventListener("click",()=>{this.showLabels=!this.showLabels}),this.infoEmbedToggle=this.shadow.getElementById("info-embed-toggle"),this.infoEmbedPanel=this.shadow.getElementById("info-embed"),this.embedReplayRadio=this.shadow.getElementById("embed-kind-replay"),this.embedEditRadio=this.shadow.getElementById("embed-kind-edit"),this.labelEmbedReplay=this.shadow.getElementById("label-embed-replay"),this.labelEmbedEdit=this.shadow.getElementById("label-embed-edit"),this.embedMarkup=this.shadow.getElementById("embed-markup"),this.embedCopyButton=this.shadow.getElementById("embed-copy"),this.interpretationChoice=this.shadow.getElementById("interpretation-choice"),this.interpretationLabel=this.shadow.getElementById("interpretation-label"),this.interpretationSelect=this.shadow.getElementById("interpretation"),this.confrontationElement=this.shadow.getElementById("confrontation"),this.confrontationHeading=this.shadow.getElementById("confrontation-heading"),this.confrontationList=this.shadow.getElementById("confrontation-list"),this.compareButton=this.shadow.getElementById("compare-account"),this.compareButton.addEventListener("click",()=>this.setComparing(!this.sceneElement.compareAccount)),this.observerSelect.addEventListener("change",()=>this.selectObserver(this.observerSelect.value)),this.interpretationSelect.addEventListener("change",()=>void this.chooseInterpretation(this.interpretationSelect.value)),this.sceneElement.addEventListener(lv,t=>this.showConfrontation(t.detail)),this.sceneElement.ufoElement.addEventListener("timeupdate",()=>this.refreshParamSummary()),this.supportsPopover?(this.infoPanel.setAttribute("popover","auto"),this.infoPanel.removeAttribute("hidden"),this.infoButton.setAttribute("popovertarget","info-panel"),this.infoPanel.addEventListener("beforetoggle",t=>{t.newState==="open"&&(this.populateInfoPanel(),this.bringInfoButtonIntoView())}),this.infoPanel.addEventListener("toggle",t=>this.syncInfoOpen(t.newState==="open"))):this.infoButton.addEventListener("click",()=>this.toggleInfoPanel()),this.infoCloseButton.addEventListener("click",()=>this.toggleInfoPanel()),this.infoCreditsToggle.addEventListener("click",()=>this.toggleCredits()),this.infoEmbedToggle.addEventListener("click",()=>this.toggleEmbed());for(const t of[this.embedReplayRadio,this.embedEditRadio])t.addEventListener("change",()=>this.refreshEmbedMarkup());this.embedCopyButton.addEventListener("click",()=>void this.copyEmbedMarkup()),this.isConnected&&this.loadLocaleMessages()}get scene(){return this.sceneElement}async loadLocaleMessages(){const e=++this.localeToken,t=Fr.preferencesFor(this);this.preferences=t;const i=o0(t,c0),[n,s,a]=i==="en"?[ml,{},void 0]:await Promise.all([M2(i),x2(i),Ag(i)]);if(e!==this.localeToken)return;const o=i!==this.language;this.language=i,this.messages=n,this.tags=new sl(s),this.said=new On(t),this.summaryBuilder=new gf(this.messages,new Hl(a),this.said,this.tags),this.accountPrefix.textContent=this.messages.accountBy,this.interpretationLabel.textContent=this.messages.interpretation,this.confrontationHeading.textContent=this.messages.confrontation;const c=this.entries.find(l=>l.src===this.currentSrc);c&&this.offerInterpretations(c),this.updateCompareButton(),this.infoButton.title=this.messages.about,this.infoButton.setAttribute("aria-label",this.messages.about),this.editLink.title=this.messages.editThisObservation,this.editLink.setAttribute("aria-label",this.messages.editThisObservation),this.infoCloseButton.setAttribute("aria-label",this.messages.close),this.infoObservationHeading.textContent=this.messages.observation,this.infoCreditsToggle.textContent=this.messages.credits,this.syncLabelsToggle(),this.refreshParamSummary(),o&&this.currentSrc&&this.runAssessments(),this.infoEmbedToggle.textContent=this.messages.embed,this.labelEmbedReplay.textContent=this.messages.embedReplay,this.labelEmbedEdit.textContent=this.messages.embedEdit,this.embedCopyButton.textContent=this.messages.embedCopy,this.infoOpen&&this.populateInfoPanel(),this.updateAccountLine()}preferences=[];localeToken=0;said=new On(["en"]);tags=new sl({});connectedCallback(){Fr.preferencesFor(this).join()!==this.preferences.join()&&this.loadLocaleMessages();const e=this.getAttribute("src");e&&this.loadFromSrc(e)}disconnectedCallback(){document.removeEventListener("click",this.handleOutsideClick)}attributeChangedCallback(e,t,i){e==="src"&&i&&i!==t&&this.isConnected&&this.loadFromSrc(i),e==="show-labels"&&this.applyLabels(this.hasAttribute("show-labels")),(e===Es||e===As)&&this.forwardPlayerAttributes(),e===Du&&this.setComparing(this.hasAttribute(Du))}forwardPlayerAttributes(){for(const e of[Es,As]){const t=this.getAttribute(e);t===null?this.sceneElement.removeAttribute(e):this.sceneElement.setAttribute(e,t)}}async loadFromSrc(e){const t=await Ao.json(e);if(Array.isArray(t))throw new Error(`${e} is a bare list of recordings, which is no longer read: list them as the sighting events of a case.json`);if(bs.isCase(t)){const i=bs.sightingUrls(t,new URL(e,location.href).href);if(i.length===0)throw new Error(`${e} is a case with no sighting event: no recording to show`);await this.loadObserverUrls(i,{json:t,url:new URL(e,location.href).href})}else this.setEntries([{src:e,sighting:t}],void 0)}get sightingData(){return this.entries.find(e=>e.src===this.currentSrc)?.sighting}set sightingData(e){this.currentSrc="",this.setEntries([{src:"",sighting:e}],void 0)}get observerUrls(){return this.entries.map(e=>e.src)}set observerUrls(e){this.loadObserverUrls(e)}async loadObserverUrls(e,t){const i=await Promise.all(e.map(async n=>({src:n,sighting:await Ao.json(n)})));this.setEntries(i,t)}setEntries(e,t){this.entries=e,this.caseSource=t,this.toolbarElement.hidden=e.length===0;const i=e.length>1;this.observerSelect.hidden=!i,this.observerText.hidden=i,this.observerSelect.innerHTML="";for(const s of e){const a=document.createElement("option");a.value=s.src,a.textContent=this.observerDisplayName(this.plain(s).observer)??this.messages.unnamedObserver.replace("{n}",String(e.indexOf(s)+1)),this.observerSelect.appendChild(a)}const n=e.find(s=>s.src===this.currentSrc)??e[0];n?this.selectObserver(n.src):this.updateAccountLine()}editorUrl(){if(!this.currentSrc)return gg;const e=new URL(this.currentSrc,location.href);return`${gg}?sighting=${encodeURIComponent(e.href)}`}embedMarkupFor(e){const t=e==="edit"?"rr0-sighting-editor":"rr0-sighting",i=new URL(`${t}.mjs`,import.meta.url).href,n=this.currentSrc?new URL(this.currentSrc,location.href).href:"";return`<script type="module" src="${i}"><\/script>
|
|
7781
|
+
<${t} src="${n}"></${t}>`}refreshEmbedMarkup(){this.embedMarkup.value=this.embedMarkupFor(this.embedEditRadio.checked?"edit":"replay")}async copyEmbedMarkup(){try{await navigator.clipboard.writeText(this.embedMarkup.value),this.embedCopyButton.textContent=this.messages.embedCopied,window.setTimeout(()=>this.embedCopyButton.textContent=this.messages.embedCopy,1500)}catch{this.embedMarkup.select()}}offerInterpretations(e){const t=this.offeredFor===e.sighting,i=this.interpretationSelect.value;this.offeredFor=e.sighting,this.interpretationToken++,this.interpretationLoaders=new Map,this.interpretationSelect.innerHTML="";const n=(l,h,u)=>{const d=document.createElement("option");d.value=l,d.textContent=h,this.interpretationSelect.appendChild(d),this.interpretationLoaders.set(l,u)},s=e===this.entries.find(l=>l.src===this.currentSrc)?this.sceneElement.ufoElement.sighting.interpretation:void 0;n(Iu,this.messages.account,()=>Promise.resolve(s));const a=this.caseSource;a&&bs.interpretationEvents(a.json,this.plain(e).id).forEach((l,h)=>{const u=this.said.read(l.title)??`#${h+1}`,d=(l.by??[]).map(f=>this.agentName(f)).filter(Boolean).join(", ");n(`case-${h}`,d?this.messages.interpretationBy.replace("{title}",u).replace("{by}",d):u,()=>bs.interpretationOf(l,a.url,f=>Ao.json(f)))});const c=t&&[...this.interpretationSelect.options].some(l=>l.value===i)?i:Iu;this.interpretationSelect.value=c,c===Iu?this.sceneElement.interpretation!==s&&(this.sceneElement.interpretation=s):this.sceneElement.interpretation||this.chooseInterpretation(c),this.interpretationChoice.hidden=this.interpretationSelect.options.length<2,this.showConfrontation(this.sceneElement.confrontation),this.updateCompareButton()}setComparing(e){this.sceneElement.compareAccount=e,this.updateCompareButton(),this.showConfrontation(this.sceneElement.confrontation)}updateCompareButton(){const e=this.sceneElement.compareAccount;this.compareButton.hidden=!this.sceneElement.interpretation,this.compareButton.setAttribute("aria-pressed",String(e));const t=e?this.messages.hideComparison:this.messages.showComparison;this.compareButton.title=t,this.compareButton.setAttribute("aria-label",t)}static DATE_LOCALES={en:"en-US",fr:"fr-FR",es:"es-ES",it:"it-IT"};get colon(){return this.language==="fr"?" : ":": "}async chooseInterpretation(e){const t=++this.interpretationToken,i=this.interpretationLoaders.get(e),n=i?await i().catch(s=>{console.warn(`<rr0-sighting>: could not read interpretation "${e}":`,s)}):void 0;t===this.interpretationToken&&(this.sceneElement.interpretation=n,this.updateCompareButton(),this.showConfrontation(this.sceneElement.confrontation))}agentName(e){if("people"in e){const[t,...i]=e.people.replace(/([a-z])([A-Z])/g,"$1 $2").split(" ");return[...i,t].join(" ")}return"org"in e?e.org.replace(/([a-z])([A-Z])/g,"$1 $2"):this.observerDisplayName(e)??""}showConfrontation(e){this.confrontationList.innerHTML="",this.confrontationElement.hidden=!this.sceneElement.interpretation||!this.sceneElement.compareAccount;const t=new Intl.NumberFormat(this.language,{maximumFractionDigits:1,minimumFractionDigits:1}),i=new Intl.NumberFormat(this.language,{maximumFractionDigits:2,minimumFractionDigits:2});for(const n of e){const s=document.createElement("li");s.append(`${this.said.read(n.title)??n.sourceId}${this.colon}`);const a=[];n.separationDeg!==void 0&&a.push([this.messages.confrontationDirection.replace("{deg}",t.format(n.separationDeg)),n.disagreements.includes("direction")]),n.widthRatio!==void 0&&a.push([this.messages.confrontationWidth.replace("{ratio}",i.format(n.widthRatio)),n.disagreements.includes("width")]),n.heightRatio!==void 0&&a.push([this.messages.confrontationHeight.replace("{ratio}",i.format(n.heightRatio)),n.disagreements.includes("height")]),a.forEach(([o,c],l)=>{l>0&&s.append(" · ");const h=document.createElement("span");h.textContent=o,c&&(h.className="disagrees"),s.append(h)}),this.confrontationList.appendChild(s)}}selectObserver(e){const t=this.entries.find(i=>i.src===e);t&&(this.currentSrc=e,this.observerSelect.value=e,this.sceneElement.documentUrl=t.src?new URL(t.src,location.href).href:void 0,this.sceneElement.sightingData=t.sighting,this.offerInterpretations(t),this.updateAccountLine(),this.refreshParamSummary(),this.runAssessments(),this.infoOpen&&this.populateInfoPanel(),this.dispatchEvent(new CustomEvent(TA,{detail:{src:e}})))}async runAssessments(){const e=++this.assessmentToken,t=await new Kv(this.messages).read(this.sceneElement.ufoElement.sighting);e===this.assessmentToken&&(this.assessmentEntries=t.entries,this.refreshParamSummary())}updateAccountLine(){const e=this.entries.find(s=>s.src===this.currentSrc),t=e?this.observerDisplayName(this.plain(e).observer):void 0,i=t!==void 0||this.entries.length>1;this.accountElement.hidden=!i,this.observerText.textContent=t??"";const n=e&&this.plain(e).sources?.find(s=>/^https?:\/\//i.test(s.url??""));if(this.accountSourceLink.hidden=!n,n){this.accountSourceLink.href=n.url;const s=this.messages.accountSource.replace("{source}",n.title??n.url);this.accountSourceLink.title=s,this.accountSourceLink.setAttribute("aria-label",s)}this.editLink.hidden=!this.currentSrc,this.editLink.href=this.editorUrl(),this.editLink.title=this.messages.editThisObservation,this.editLink.setAttribute("aria-label",this.messages.editThisObservation)}observerDisplayName(e){if(!e)return;const t=[...e.firstNames??[],e.lastName].filter(Boolean).join(" ");return e.title||t||e.id}plainRecordings=new WeakMap;plain(e){let t=this.plainRecordings.get(e.sighting);return t||(t=Gi.strip(e.sighting).recording,this.plainRecordings.set(e.sighting,t)),t}formatDate(e){const t=e.place?.[0],i=So(e.time??{},t?.lng??0,e.utcOffsetHours);if(!i)return;const n=i.getTime()+this.utcOffsetHoursOf(e,t?.lng??0)*36e5;if(Number.isFinite(n))return new Intl.DateTimeFormat(ah.DATE_LOCALES[this.language],{dateStyle:"long",timeStyle:"short",timeZone:"UTC"}).format(new Date(n))}utcOffsetHoursOf(e,t){return e.utcOffsetHours??Math.round(t/15)}formatLocation(e){const t=e.place?.[0];if(t)return`${t.lat.toFixed(4)}, ${t.lng.toFixed(4)}`}toggleInfoPanel(){const e=!this.infoOpen;if(this.supportsPopover){const t=this.infoPanel.matches(":popover-open");e&&!t?this.infoPanel.showPopover():!e&&t&&this.infoPanel.hidePopover();return}e&&this.bringInfoButtonIntoView(),this.syncInfoOpen(e),this.infoPanel.hidden=!e,e?document.addEventListener("click",this.handleOutsideClick):document.removeEventListener("click",this.handleOutsideClick)}bringInfoButtonIntoView(){const e=this.infoButton.getBoundingClientRect(),t=window.innerHeight||document.documentElement.clientHeight;e.top>=0&&e.bottom<=t||this.infoButton.scrollIntoView({block:"center"})}syncInfoOpen(e){e!==this.infoOpen&&(this.infoOpen=e,this.infoButton.setAttribute("aria-expanded",String(e)),e?this.supportsPopover||this.populateInfoPanel():(this.creditsOpen=!1,this.infoCreditsList.hidden=!0,this.infoCreditsToggle.setAttribute("aria-expanded","false"),this.embedOpen=!1,this.infoEmbedPanel.hidden=!0,this.infoEmbedToggle.setAttribute("aria-expanded","false")))}handleOutsideClick=e=>{const t=e.composedPath();!t.includes(this.infoPanel)&&!t.includes(this.infoButton)&&this.toggleInfoPanel()};toggleCredits(){this.creditsOpen=!this.creditsOpen,this.infoCreditsList.hidden=!this.creditsOpen,this.infoCreditsToggle.setAttribute("aria-expanded",String(this.creditsOpen)),this.creditsOpen&&this.revealInPanel(this.infoCreditsList)}toggleEmbed(){this.embedOpen=!this.embedOpen,this.infoEmbedPanel.hidden=!this.embedOpen,this.infoEmbedToggle.setAttribute("aria-expanded",String(this.embedOpen)),this.embedOpen&&(this.refreshEmbedMarkup(),this.revealInPanel(this.infoEmbedPanel))}revealInPanel(e){e.scrollIntoView?.({block:"nearest"})}get showLabels(){return this.labelsShown}set showLabels(e){this.toggleAttribute("show-labels",e)}applyLabels(e){this.labelsShown=e,this.syncLabelsToggle(),this.refreshParamSummary(),this.populateInfoPanel()}syncLabelsToggle(){this.labelsToggle.textContent=this.labelsShown?this.messages.hideLabels:this.messages.showLabels,this.labelsToggle.setAttribute("aria-pressed",String(this.labelsShown))}refreshParamSummary(){if(this.paramSummary.hidden=!this.labelsShown,!this.labelsShown){this.paramSummary.replaceChildren(),this.summarySignature="";return}const e=this.sceneElement.ufoElement.sighting,t=[...this.summaryBuilder.entriesFor(e,this.sceneElement.ufoElement.currentTime),...this.assessmentEntries],i=t.map(a=>`${a.field}=${a.label}=${a.value}${a.unit}${a.fromSource?"*":""}`).join("|");if(i===this.summarySignature)return;this.summarySignature=i;const n=[];let s;for(const a of t){s&&s.group!==a.group&&(s=void 0);const o=a.group==="observer"?this.messages.observerGroup:a.group==="assessment"?this.messages.assessmentGroup:void 0;if(o!==void 0&&!s){const l=document.createElement("span");l.className="param-nest";const h=document.createElement("span");h.className="param-nest-label",h.textContent=o,l.append(h),s={group:a.group,element:l},n.push(l)}const c=this.paramItem(a);s?s.element.append(c):n.push(c)}this.paramSummary.replaceChildren(...n)}paramItem(e){const t=document.createElement("span");t.className=e.fromSource?"param-label from-source":"param-label";const i=document.createElement("span");if(i.className="param-label-label",i.textContent=`${e.label} `,t.append(i),e.color!==void 0){const s=document.createElement("span");s.className="param-label-swatch",s.style.background=e.color,t.append(s)}const n=document.createElement("span");return n.className="param-label-value",n.textContent=e.unit===""?e.value:`${e.value} ${e.unit}`,t.append(n),t}populateInfoPanel(){const e=this.entries.find(t=>t.src===this.currentSrc);if(this.infoObservationList.innerHTML="",e){const t=this.caseSource&&(this.caseSource.json.title??this.caseSource.json.id);if(t&&this.appendInfoRow(this.infoObservationList,this.messages.case,t),!this.labelsShown){const s=this.formatDate(this.plain(e));s&&this.appendInfoRow(this.infoObservationList,this.messages.date,s);const a=this.formatLocation(this.plain(e));a&&this.appendInfoRow(this.infoObservationList,this.messages.location,a)}const i=this.said.read(this.plain(e).description);i&&this.appendInfoRow(this.infoObservationList,this.messages.description,i);for(const s of this.plain(e).sources??[])this.appendInfoSource(this.infoObservationList,this.messages.source,s);const n=this.plain(e).tags;!this.labelsShown&&n&&n.length>0&&this.appendInfoRow(this.infoObservationList,this.messages.tags,n.map(s=>this.tags.name(s)).join(", "))}this.refreshEmbedMarkup(),this.infoAppLink.href=uv,this.infoAppLink.textContent="UFO@home v0.74.1",Dn.fill(this.infoCreditsList,this.sceneElement)}appendInfoSource(e,t,i){const n=document.createElement("dt");n.textContent=t;const s=document.createElement("dd"),a=i.title??i.url??"";if(i.url&&/^https?:\/\//i.test(i.url)){const c=document.createElement("a");c.href=i.url,c.target="_blank",c.rel="noopener noreferrer",c.textContent=a,s.appendChild(c)}else s.append(a);const o=[i.authors?.join(", "),i.publication?.publisher,i.publication?.time,i.index].filter(Boolean);o.length>0&&s.append(`, ${o.join(", ")}`),e.append(n,s)}appendInfoRow(e,t,i){const n=document.createElement("dt");n.textContent=t;const s=document.createElement("dd");s.textContent=i,e.appendChild(n),e.appendChild(s)}}const vg="rr0-sighting",TA="observerchange",Mg="rr0-eyeobserver";class RA extends ah{}function DA(){hv(),customElements.get(vg)||customElements.define(vg,ah),customElements.get(Mg)||customElements.define(Mg,RA)}DA();export{LA as $,Qi as A,tt as B,se as C,Dp as D,bn as E,kA as F,_t as G,ot as H,NA as I,OA as J,De as K,jo as L,xx as M,lc as N,Ut as O,g1 as P,en as Q,Go as R,Oo as S,IA as T,FA as U,xe as V,r1 as W,UA as X,xs as Y,Dt as Z,Ji as _,PA as a,zn as a0,a1,Sp as a2,ox as a3,_l as a4,xd as a5,Dl as a6,Si as a7,p1 as a8,D0 as a9,I0 as aa,at as ab,sa as ac,Jo as ad,Wi as ae,Cs as af,CA as b,Qh as c,HA as d,El as e,Vi as f,BA as g,Ze as h,R as i,dp as j,zA as k,GA as l,nx as m,Ta as n,dh as o,d2 as p,rM as q,rt as r,So as s,At as t,Gu as u,wi as v,o1 as w,Ps as x,fx as y,_a as z};
|