import{M as Xt,I as tn,S as $t,D as rn,v as Pr,V as ve,a as lt,T as ct,b as br,Q as Mr,O as zt,c as Be,P as ar,R as nn,d as Fr,e as Nr,H as Ne,F as We,f as ut,L as Ge,g as bt,h as an,U as on,i as sn,k as ln,l as cn,r as U,u as Ae,m as hr,_ as Zt,n as Dr,B as un,C as Wt,o as $e,p as kr,q as Lr,s as Ur,t as Yt,w as dn,x as hn,y as sr,z as dt,A as pn,E as fn,G as mn,J as vn,K as gn,N as lr,X as Ht,Y as wn,Z as _n,$ as Sr,a0 as yn,a1 as En,a2 as Mt,a3 as bn,a4 as Mn,a5 as Sn,a6 as xn,a7 as Tn,a8 as xr,j as V,a9 as In,aa as Cn,ab as An,ac as Rn,ad as Tr,ae as On,af as Ir}from"./main-dbbhfJHr.js";import"./index-BZRVbyem.js";var Fe=Uint8Array,Ve=Uint16Array,cr=Uint32Array,Br=new Fe([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),jr=new Fe([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),Pn=new Fe([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),zr=function(i,r){for(var o=new Ve(31),t=0;t<31;++t)o[t]=r+=1<<i[t-1];for(var c=new cr(o[30]),t=1;t<30;++t)for(var d=o[t];d<o[t+1];++d)c[d]=d-o[t]<<5|t;return[o,c]},Hr=zr(Br,2),Gr=Hr[0],Fn=Hr[1];Gr[28]=258,Fn[258]=28;var Nn=zr(jr,0),Dn=Nn[0],ur=new Ve(32768);for(var pe=0;pe<32768;++pe){var Xe=(pe&43690)>>>1|(pe&21845)<<1;Xe=(Xe&52428)>>>2|(Xe&13107)<<2,Xe=(Xe&61680)>>>4|(Xe&3855)<<4,ur[pe]=((Xe&65280)>>>8|(Xe&255)<<8)>>>1}var Et=function(i,r,o){for(var t=i.length,c=0,d=new Ve(r);c<t;++c)++d[i[c]-1];var u=new Ve(r);for(c=0;c<r;++c)u[c]=u[c-1]+d[c-1]<<1;var f;if(o){f=new Ve(1<<r);var m=15-r;for(c=0;c<t;++c)if(i[c])for(var g=c<<4|i[c],M=r-i[c],C=u[i[c]-1]++<<M,E=C|(1<<M)-1;C<=E;++C)f[ur[C]>>>m]=g}else for(f=new Ve(t),c=0;c<t;++c)i[c]&&(f[c]=ur[u[i[c]-1]++]>>>15-i[c]);return f},xt=new Fe(288);for(var pe=0;pe<144;++pe)xt[pe]=8;for(var pe=144;pe<256;++pe)xt[pe]=9;for(var pe=256;pe<280;++pe)xt[pe]=7;for(var pe=280;pe<288;++pe)xt[pe]=8;var Zr=new Fe(32);for(var pe=0;pe<32;++pe)Zr[pe]=5;var kn=Et(xt,9,1),Ln=Et(Zr,5,1),ir=function(i){for(var r=i[0],o=1;o<i.length;++o)i[o]>r&&(r=i[o]);return r},je=function(i,r,o){var t=r/8|0;return(i[t]|i[t+1]<<8)>>(r&7)&o},or=function(i,r){var o=r/8|0;return(i[o]|i[o+1]<<8|i[o+2]<<16)>>(r&7)},Un=function(i){return(i/8|0)+(i&7&&1)},Bn=function(i,r,o){(o==null||o>i.length)&&(o=i.length);var t=new(i instanceof Ve?Ve:i instanceof cr?cr:Fe)(o-r);return t.set(i.subarray(r,o)),t},jn=function(i,r,o){var t=i.length;if(!t||o&&!o.l&&t<5)return r||new Fe(0);var c=!r||o,d=!o||o.i;o||(o={}),r||(r=new Fe(t*3));var u=function(ae){var De=r.length;if(ae>De){var ke=new Fe(Math.max(De*2,ae));ke.set(r),r=ke}},f=o.f||0,m=o.p||0,g=o.b||0,M=o.l,C=o.d,E=o.m,j=o.n,z=t*8;do{if(!M){o.f=f=je(i,m,1);var R=je(i,m+1,3);if(m+=3,R)if(R==1)M=kn,C=Ln,E=9,j=5;else if(R==2){var q=je(i,m,31)+257,te=je(i,m+10,15)+4,N=q+je(i,m+5,31)+1;m+=14;for(var O=new Fe(N),re=new Fe(19),_=0;_<te;++_)re[Pn[_]]=je(i,m+_*3,7);m+=te*3;for(var A=ir(re),F=(1<<A)-1,Q=Et(re,A,1),_=0;_<N;){var J=Q[je(i,m,F)];m+=J&15;var k=J>>>4;if(k<16)O[_++]=k;else{var X=0,G=0;for(k==16?(G=3+je(i,m,3),m+=2,X=O[_-1]):k==17?(G=3+je(i,m,7),m+=3):k==18&&(G=11+je(i,m,127),m+=7);G--;)O[_++]=X}}var oe=O.subarray(0,q),W=O.subarray(q);E=ir(oe),j=ir(W),M=Et(oe,E,1),C=Et(W,j,1)}else throw"invalid block type";else{var k=Un(m)+4,H=i[k-4]|i[k-3]<<8,Y=k+H;if(Y>t){if(d)throw"unexpected EOF";break}c&&u(g+H),r.set(i.subarray(k,Y),g),o.b=g+=H,o.p=m=Y*8;continue}if(m>z){if(d)throw"unexpected EOF";break}}c&&u(g+131072);for(var xe=(1<<E)-1,Te=(1<<j)-1,be=m;;be=m){var X=M[or(i,m)&xe],ne=X>>>4;if(m+=X&15,m>z){if(d)throw"unexpected EOF";break}if(!X)throw"invalid length/literal";if(ne<256)r[g++]=ne;else if(ne==256){be=m,M=null;break}else{var Re=ne-254;if(ne>264){var _=ne-257,se=Br[_];Re=je(i,m,(1<<se)-1)+Gr[_],m+=se}var ge=C[or(i,m)&Te],Ie=ge>>>4;if(!ge)throw"invalid distance";m+=ge&15;var W=Dn[Ie];if(Ie>3){var se=jr[Ie];W+=or(i,m)&(1<<se)-1,m+=se}if(m>z){if(d)throw"unexpected EOF";break}c&&u(g+131072);for(var Ke=g+Re;g<Ke;g+=4)r[g]=r[g-W],r[g+1]=r[g+1-W],r[g+2]=r[g+2-W],r[g+3]=r[g+3-W];g=Ke}}o.l=M,o.p=be,o.b=g,M&&(f=1,o.m=E,o.d=C,o.n=j)}while(!f);return g==r.length?r:Bn(r,0,g)},zn=new Fe(0),Hn=function(i){if((i[0]&15)!=8||i[0]>>>4>7||(i[0]<<8|i[1])%31)throw"invalid zlib data";if(i[1]&32)throw"invalid zlib data: preset dictionaries not supported"};function Lt(i,r){return jn((Hn(i),i.subarray(2,-4)),r)}var Gn=typeof TextDecoder<"u"&&new TextDecoder,Zn=0;try{Gn.decode(zn,{stream:!0}),Zn=1}catch{}const Wn=i=>i&&i.isCubeTexture;class Yn extends Xt{constructor(r,o){var t,c;const d=Wn(r),f=((c=d?(t=r.image[0])==null?void 0:t.width:r.image.width)!=null?c:1024)/4,m=Math.floor(Math.log2(f)),g=Math.pow(2,m),M=3*Math.max(g,16*7),C=4*g,E=[d?"#define ENVMAP_TYPE_CUBE":"",`#define CUBEUV_TEXEL_WIDTH ${1/M}`,`#define CUBEUV_TEXEL_HEIGHT ${1/C}`,`#define CUBEUV_MAX_MIP ${m}.0`],j=`
        varying vec3 vWorldPosition;
        void main() 
        {
            vec4 worldPosition = ( modelMatrix * vec4( position, 1.0 ) );
            vWorldPosition = worldPosition.xyz;
            
            gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
        }
        `,z=E.join(`
`)+`
        #define ENVMAP_TYPE_CUBE_UV
        varying vec3 vWorldPosition;
        uniform float radius;
        uniform float height;
        uniform float angle;
        #ifdef ENVMAP_TYPE_CUBE
            uniform samplerCube map;
        #else
            uniform sampler2D map;
        #endif
        // From: https://www.shadertoy.com/view/4tsBD7
        float diskIntersectWithBackFaceCulling( vec3 ro, vec3 rd, vec3 c, vec3 n, float r ) 
        {
            float d = dot ( rd, n );
            
            if( d > 0.0 ) { return 1e6; }
            
            vec3  o = ro - c;
            float t = - dot( n, o ) / d;
            vec3  q = o + rd * t;
            
            return ( dot( q, q ) < r * r ) ? t : 1e6;
        }
        // From: https://www.iquilezles.org/www/articles/intersectors/intersectors.htm
        float sphereIntersect( vec3 ro, vec3 rd, vec3 ce, float ra ) 
        {
            vec3 oc = ro - ce;
            float b = dot( oc, rd );
            float c = dot( oc, oc ) - ra * ra;
            float h = b * b - c;
            
            if( h < 0.0 ) { return -1.0; }
            
            h = sqrt( h );
            
            return - b + h;
        }
        vec3 project() 
        {
            vec3 p = normalize( vWorldPosition );
            vec3 camPos = cameraPosition;
            camPos.y -= height;
            float intersection = sphereIntersect( camPos, p, vec3( 0.0 ), radius );
            if( intersection > 0.0 ) {
                
                vec3 h = vec3( 0.0, - height, 0.0 );
                float intersection2 = diskIntersectWithBackFaceCulling( camPos, p, h, vec3( 0.0, 1.0, 0.0 ), radius );
                p = ( camPos + min( intersection, intersection2 ) * p ) / radius;
            } else {
                p = vec3( 0.0, 1.0, 0.0 );
            }
            return p;
        }
        #include <common>
        #include <cube_uv_reflection_fragment>
        void main() 
        {
            vec3 projectedWorldPosition = project();
            
            #ifdef ENVMAP_TYPE_CUBE
                vec3 outcolor = textureCube( map, projectedWorldPosition ).rgb;
            #else
                vec3 direction = normalize( projectedWorldPosition );
                vec2 uv = equirectUv( direction );
                vec3 outcolor = texture2D( map, uv ).rgb;
            #endif
            gl_FragColor = vec4( outcolor, 1.0 );
            #include <tonemapping_fragment>
            #include <${Pr>=154?"colorspace_fragment":"encodings_fragment"}>
        }
        `,R={map:{value:r},height:{value:(o==null?void 0:o.height)||15},radius:{value:(o==null?void 0:o.radius)||100}},k=new tn(1,16),H=new $t({uniforms:R,fragmentShader:z,vertexShader:j,side:rn});super(k,H)}set radius(r){this.material.uniforms.radius.value=r}get radius(){return this.material.uniforms.radius.value}set height(r){this.material.uniforms.height.value=r}get height(){return this.material.uniforms.height.value}}var Xn=Object.defineProperty,$n=(i,r,o)=>r in i?Xn(i,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):i[r]=o,Vn=(i,r,o)=>($n(i,r+"",o),o);class Kn{constructor(){Vn(this,"_listeners")}addEventListener(r,o){this._listeners===void 0&&(this._listeners={});const t=this._listeners;t[r]===void 0&&(t[r]=[]),t[r].indexOf(o)===-1&&t[r].push(o)}hasEventListener(r,o){if(this._listeners===void 0)return!1;const t=this._listeners;return t[r]!==void 0&&t[r].indexOf(o)!==-1}removeEventListener(r,o){if(this._listeners===void 0)return;const c=this._listeners[r];if(c!==void 0){const d=c.indexOf(o);d!==-1&&c.splice(d,1)}}dispatchEvent(r){if(this._listeners===void 0)return;const t=this._listeners[r.type];if(t!==void 0){r.target=this;const c=t.slice(0);for(let d=0,u=c.length;d<u;d++)c[d].call(this,r);r.target=null}}}var qn=Object.defineProperty,Jn=(i,r,o)=>r in i?qn(i,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):i[r]=o,B=(i,r,o)=>(Jn(i,typeof r!="symbol"?r+"":r,o),o);const Ut=new nn,Cr=new Fr,Qn=Math.cos(70*(Math.PI/180)),Ar=(i,r)=>(i%r+r)%r;let ea=class extends Kn{constructor(r,o){super(),B(this,"object"),B(this,"domElement"),B(this,"enabled",!0),B(this,"target",new ve),B(this,"minDistance",0),B(this,"maxDistance",1/0),B(this,"minZoom",0),B(this,"maxZoom",1/0),B(this,"minPolarAngle",0),B(this,"maxPolarAngle",Math.PI),B(this,"minAzimuthAngle",-1/0),B(this,"maxAzimuthAngle",1/0),B(this,"enableDamping",!1),B(this,"dampingFactor",.05),B(this,"enableZoom",!0),B(this,"zoomSpeed",1),B(this,"enableRotate",!0),B(this,"rotateSpeed",1),B(this,"enablePan",!0),B(this,"panSpeed",1),B(this,"screenSpacePanning",!0),B(this,"keyPanSpeed",7),B(this,"zoomToCursor",!1),B(this,"autoRotate",!1),B(this,"autoRotateSpeed",2),B(this,"reverseOrbit",!1),B(this,"reverseHorizontalOrbit",!1),B(this,"reverseVerticalOrbit",!1),B(this,"keys",{LEFT:"ArrowLeft",UP:"ArrowUp",RIGHT:"ArrowRight",BOTTOM:"ArrowDown"}),B(this,"mouseButtons",{LEFT:lt.ROTATE,MIDDLE:lt.DOLLY,RIGHT:lt.PAN}),B(this,"touches",{ONE:ct.ROTATE,TWO:ct.DOLLY_PAN}),B(this,"target0"),B(this,"position0"),B(this,"zoom0"),B(this,"_domElementKeyEvents",null),B(this,"getPolarAngle"),B(this,"getAzimuthalAngle"),B(this,"setPolarAngle"),B(this,"setAzimuthalAngle"),B(this,"getDistance"),B(this,"getZoomScale"),B(this,"listenToKeyEvents"),B(this,"stopListenToKeyEvents"),B(this,"saveState"),B(this,"reset"),B(this,"update"),B(this,"connect"),B(this,"dispose"),B(this,"dollyIn"),B(this,"dollyOut"),B(this,"getScale"),B(this,"setScale"),this.object=r,this.domElement=o,this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this.getPolarAngle=()=>M.phi,this.getAzimuthalAngle=()=>M.theta,this.setPolarAngle=s=>{let w=Ar(s,2*Math.PI),P=M.phi;P<0&&(P+=2*Math.PI),w<0&&(w+=2*Math.PI);let ee=Math.abs(w-P);2*Math.PI-ee<ee&&(w<P?w+=2*Math.PI:P+=2*Math.PI),C.phi=w-P,t.update()},this.setAzimuthalAngle=s=>{let w=Ar(s,2*Math.PI),P=M.theta;P<0&&(P+=2*Math.PI),w<0&&(w+=2*Math.PI);let ee=Math.abs(w-P);2*Math.PI-ee<ee&&(w<P?w+=2*Math.PI:P+=2*Math.PI),C.theta=w-P,t.update()},this.getDistance=()=>t.object.position.distanceTo(t.target),this.listenToKeyEvents=s=>{s.addEventListener("keydown",at),this._domElementKeyEvents=s},this.stopListenToKeyEvents=()=>{this._domElementKeyEvents.removeEventListener("keydown",at),this._domElementKeyEvents=null},this.saveState=()=>{t.target0.copy(t.target),t.position0.copy(t.object.position),t.zoom0=t.object.zoom},this.reset=()=>{t.target.copy(t.target0),t.object.position.copy(t.position0),t.object.zoom=t.zoom0,t.object.updateProjectionMatrix(),t.dispatchEvent(c),t.update(),m=f.NONE},this.update=(()=>{const s=new ve,w=new ve(0,1,0),P=new Mr().setFromUnitVectors(r.up,w),ee=P.clone().invert(),b=new ve,Me=new Mr,ze=2*Math.PI;return function(){const Dt=t.object.position;P.setFromUnitVectors(r.up,w),ee.copy(P).invert(),s.copy(Dt).sub(t.target),s.applyQuaternion(P),M.setFromVector3(s),t.autoRotate&&m===f.NONE&&G(J()),t.enableDamping?(M.theta+=C.theta*t.dampingFactor,M.phi+=C.phi*t.dampingFactor):(M.theta+=C.theta,M.phi+=C.phi);let Le=t.minAzimuthAngle,Ue=t.maxAzimuthAngle;isFinite(Le)&&isFinite(Ue)&&(Le<-Math.PI?Le+=ze:Le>Math.PI&&(Le-=ze),Ue<-Math.PI?Ue+=ze:Ue>Math.PI&&(Ue-=ze),Le<=Ue?M.theta=Math.max(Le,Math.min(Ue,M.theta)):M.theta=M.theta>(Le+Ue)/2?Math.max(Le,M.theta):Math.min(Ue,M.theta)),M.phi=Math.max(t.minPolarAngle,Math.min(t.maxPolarAngle,M.phi)),M.makeSafe(),t.enableDamping===!0?t.target.addScaledVector(j,t.dampingFactor):t.target.add(j),t.zoomToCursor&&A||t.object.isOrthographicCamera?M.radius=ge(M.radius):M.radius=ge(M.radius*E),s.setFromSpherical(M),s.applyQuaternion(ee),Dt.copy(t.target).add(s),t.object.matrixAutoUpdate||t.object.updateMatrix(),t.object.lookAt(t.target),t.enableDamping===!0?(C.theta*=1-t.dampingFactor,C.phi*=1-t.dampingFactor,j.multiplyScalar(1-t.dampingFactor)):(C.set(0,0,0),j.set(0,0,0));let Qe=!1;if(t.zoomToCursor&&A){let et=null;if(t.object instanceof ar&&t.object.isPerspectiveCamera){const tt=s.length();et=ge(tt*E);const st=tt-et;t.object.position.addScaledVector(re,st),t.object.updateMatrixWorld()}else if(t.object.isOrthographicCamera){const tt=new ve(_.x,_.y,0);tt.unproject(t.object),t.object.zoom=Math.max(t.minZoom,Math.min(t.maxZoom,t.object.zoom/E)),t.object.updateProjectionMatrix(),Qe=!0;const st=new ve(_.x,_.y,0);st.unproject(t.object),t.object.position.sub(st).add(tt),t.object.updateMatrixWorld(),et=s.length()}else console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled."),t.zoomToCursor=!1;et!==null&&(t.screenSpacePanning?t.target.set(0,0,-1).transformDirection(t.object.matrix).multiplyScalar(et).add(t.object.position):(Ut.origin.copy(t.object.position),Ut.direction.set(0,0,-1).transformDirection(t.object.matrix),Math.abs(t.object.up.dot(Ut.direction))<Qn?r.lookAt(t.target):(Cr.setFromNormalAndCoplanarPoint(t.object.up,t.target),Ut.intersectPlane(Cr,t.target))))}else t.object instanceof zt&&t.object.isOrthographicCamera&&(Qe=E!==1,Qe&&(t.object.zoom=Math.max(t.minZoom,Math.min(t.maxZoom,t.object.zoom/E)),t.object.updateProjectionMatrix()));return E=1,A=!1,Qe||b.distanceToSquared(t.object.position)>g||8*(1-Me.dot(t.object.quaternion))>g?(t.dispatchEvent(c),b.copy(t.object.position),Me.copy(t.object.quaternion),Qe=!1,!0):!1}})(),this.connect=s=>{t.domElement=s,t.domElement.style.touchAction="none",t.domElement.addEventListener("contextmenu",Nt),t.domElement.addEventListener("pointerdown",Pt),t.domElement.addEventListener("pointercancel",qe),t.domElement.addEventListener("wheel",Ft)},this.dispose=()=>{var s,w,P,ee,b,Me;t.domElement&&(t.domElement.style.touchAction="auto"),(s=t.domElement)==null||s.removeEventListener("contextmenu",Nt),(w=t.domElement)==null||w.removeEventListener("pointerdown",Pt),(P=t.domElement)==null||P.removeEventListener("pointercancel",qe),(ee=t.domElement)==null||ee.removeEventListener("wheel",Ft),(b=t.domElement)==null||b.ownerDocument.removeEventListener("pointermove",nt),(Me=t.domElement)==null||Me.ownerDocument.removeEventListener("pointerup",qe),t._domElementKeyEvents!==null&&t._domElementKeyEvents.removeEventListener("keydown",at)};const t=this,c={type:"change"},d={type:"start"},u={type:"end"},f={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6};let m=f.NONE;const g=1e-6,M=new br,C=new br;let E=1;const j=new ve,z=new Be,R=new Be,k=new Be,H=new Be,Y=new Be,q=new Be,te=new Be,N=new Be,O=new Be,re=new ve,_=new Be;let A=!1;const F=[],Q={};function J(){return 2*Math.PI/60/60*t.autoRotateSpeed}function X(){return Math.pow(.95,t.zoomSpeed)}function G(s){t.reverseOrbit||t.reverseHorizontalOrbit?C.theta+=s:C.theta-=s}function oe(s){t.reverseOrbit||t.reverseVerticalOrbit?C.phi+=s:C.phi-=s}const W=(()=>{const s=new ve;return function(P,ee){s.setFromMatrixColumn(ee,0),s.multiplyScalar(-P),j.add(s)}})(),xe=(()=>{const s=new ve;return function(P,ee){t.screenSpacePanning===!0?s.setFromMatrixColumn(ee,1):(s.setFromMatrixColumn(ee,0),s.crossVectors(t.object.up,s)),s.multiplyScalar(P),j.add(s)}})(),Te=(()=>{const s=new ve;return function(P,ee){const b=t.domElement;if(b&&t.object instanceof ar&&t.object.isPerspectiveCamera){const Me=t.object.position;s.copy(Me).sub(t.target);let ze=s.length();ze*=Math.tan(t.object.fov/2*Math.PI/180),W(2*P*ze/b.clientHeight,t.object.matrix),xe(2*ee*ze/b.clientHeight,t.object.matrix)}else b&&t.object instanceof zt&&t.object.isOrthographicCamera?(W(P*(t.object.right-t.object.left)/t.object.zoom/b.clientWidth,t.object.matrix),xe(ee*(t.object.top-t.object.bottom)/t.object.zoom/b.clientHeight,t.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),t.enablePan=!1)}})();function be(s){t.object instanceof ar&&t.object.isPerspectiveCamera||t.object instanceof zt&&t.object.isOrthographicCamera?E=s:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),t.enableZoom=!1)}function ne(s){be(E/s)}function Re(s){be(E*s)}function se(s){if(!t.zoomToCursor||!t.domElement)return;A=!0;const w=t.domElement.getBoundingClientRect(),P=s.clientX-w.left,ee=s.clientY-w.top,b=w.width,Me=w.height;_.x=P/b*2-1,_.y=-(ee/Me)*2+1,re.set(_.x,_.y,1).unproject(t.object).sub(t.object.position).normalize()}function ge(s){return Math.max(t.minDistance,Math.min(t.maxDistance,s))}function Ie(s){z.set(s.clientX,s.clientY)}function Ke(s){se(s),te.set(s.clientX,s.clientY)}function ae(s){H.set(s.clientX,s.clientY)}function De(s){R.set(s.clientX,s.clientY),k.subVectors(R,z).multiplyScalar(t.rotateSpeed);const w=t.domElement;w&&(G(2*Math.PI*k.x/w.clientHeight),oe(2*Math.PI*k.y/w.clientHeight)),z.copy(R),t.update()}function ke(s){N.set(s.clientX,s.clientY),O.subVectors(N,te),O.y>0?ne(X()):O.y<0&&Re(X()),te.copy(N),t.update()}function Kt(s){Y.set(s.clientX,s.clientY),q.subVectors(Y,H).multiplyScalar(t.panSpeed),Te(q.x,q.y),H.copy(Y),t.update()}function qt(s){se(s),s.deltaY<0?Re(X()):s.deltaY>0&&ne(X()),t.update()}function Tt(s){let w=!1;switch(s.code){case t.keys.UP:Te(0,t.keyPanSpeed),w=!0;break;case t.keys.BOTTOM:Te(0,-t.keyPanSpeed),w=!0;break;case t.keys.LEFT:Te(t.keyPanSpeed,0),w=!0;break;case t.keys.RIGHT:Te(-t.keyPanSpeed,0),w=!0;break}w&&(s.preventDefault(),t.update())}function It(){if(F.length==1)z.set(F[0].pageX,F[0].pageY);else{const s=.5*(F[0].pageX+F[1].pageX),w=.5*(F[0].pageY+F[1].pageY);z.set(s,w)}}function pt(){if(F.length==1)H.set(F[0].pageX,F[0].pageY);else{const s=.5*(F[0].pageX+F[1].pageX),w=.5*(F[0].pageY+F[1].pageY);H.set(s,w)}}function ft(){const s=F[0].pageX-F[1].pageX,w=F[0].pageY-F[1].pageY,P=Math.sqrt(s*s+w*w);te.set(0,P)}function Ct(){t.enableZoom&&ft(),t.enablePan&&pt()}function Jt(){t.enableZoom&&ft(),t.enableRotate&&It()}function At(s){if(F.length==1)R.set(s.pageX,s.pageY);else{const P=ot(s),ee=.5*(s.pageX+P.x),b=.5*(s.pageY+P.y);R.set(ee,b)}k.subVectors(R,z).multiplyScalar(t.rotateSpeed);const w=t.domElement;w&&(G(2*Math.PI*k.x/w.clientHeight),oe(2*Math.PI*k.y/w.clientHeight)),z.copy(R)}function Rt(s){if(F.length==1)Y.set(s.pageX,s.pageY);else{const w=ot(s),P=.5*(s.pageX+w.x),ee=.5*(s.pageY+w.y);Y.set(P,ee)}q.subVectors(Y,H).multiplyScalar(t.panSpeed),Te(q.x,q.y),H.copy(Y)}function Ot(s){const w=ot(s),P=s.pageX-w.x,ee=s.pageY-w.y,b=Math.sqrt(P*P+ee*ee);N.set(0,b),O.set(0,Math.pow(N.y/te.y,t.zoomSpeed)),ne(O.y),te.copy(N)}function Qt(s){t.enableZoom&&Ot(s),t.enablePan&&Rt(s)}function er(s){t.enableZoom&&Ot(s),t.enableRotate&&At(s)}function Pt(s){var w,P;t.enabled!==!1&&(F.length===0&&((w=t.domElement)==null||w.ownerDocument.addEventListener("pointermove",nt),(P=t.domElement)==null||P.ownerDocument.addEventListener("pointerup",qe)),nr(s),s.pointerType==="touch"?it(s):mt(s))}function nt(s){t.enabled!==!1&&(s.pointerType==="touch"?rr(s):tr(s))}function qe(s){var w,P,ee;Je(s),F.length===0&&((w=t.domElement)==null||w.releasePointerCapture(s.pointerId),(P=t.domElement)==null||P.ownerDocument.removeEventListener("pointermove",nt),(ee=t.domElement)==null||ee.ownerDocument.removeEventListener("pointerup",qe)),t.dispatchEvent(u),m=f.NONE}function mt(s){let w;switch(s.button){case 0:w=t.mouseButtons.LEFT;break;case 1:w=t.mouseButtons.MIDDLE;break;case 2:w=t.mouseButtons.RIGHT;break;default:w=-1}switch(w){case lt.DOLLY:if(t.enableZoom===!1)return;Ke(s),m=f.DOLLY;break;case lt.ROTATE:if(s.ctrlKey||s.metaKey||s.shiftKey){if(t.enablePan===!1)return;ae(s),m=f.PAN}else{if(t.enableRotate===!1)return;Ie(s),m=f.ROTATE}break;case lt.PAN:if(s.ctrlKey||s.metaKey||s.shiftKey){if(t.enableRotate===!1)return;Ie(s),m=f.ROTATE}else{if(t.enablePan===!1)return;ae(s),m=f.PAN}break;default:m=f.NONE}m!==f.NONE&&t.dispatchEvent(d)}function tr(s){if(t.enabled!==!1)switch(m){case f.ROTATE:if(t.enableRotate===!1)return;De(s);break;case f.DOLLY:if(t.enableZoom===!1)return;ke(s);break;case f.PAN:if(t.enablePan===!1)return;Kt(s);break}}function Ft(s){t.enabled===!1||t.enableZoom===!1||m!==f.NONE&&m!==f.ROTATE||(s.preventDefault(),t.dispatchEvent(d),qt(s),t.dispatchEvent(u))}function at(s){t.enabled===!1||t.enablePan===!1||Tt(s)}function it(s){switch(ye(s),F.length){case 1:switch(t.touches.ONE){case ct.ROTATE:if(t.enableRotate===!1)return;It(),m=f.TOUCH_ROTATE;break;case ct.PAN:if(t.enablePan===!1)return;pt(),m=f.TOUCH_PAN;break;default:m=f.NONE}break;case 2:switch(t.touches.TWO){case ct.DOLLY_PAN:if(t.enableZoom===!1&&t.enablePan===!1)return;Ct(),m=f.TOUCH_DOLLY_PAN;break;case ct.DOLLY_ROTATE:if(t.enableZoom===!1&&t.enableRotate===!1)return;Jt(),m=f.TOUCH_DOLLY_ROTATE;break;default:m=f.NONE}break;default:m=f.NONE}m!==f.NONE&&t.dispatchEvent(d)}function rr(s){switch(ye(s),m){case f.TOUCH_ROTATE:if(t.enableRotate===!1)return;At(s),t.update();break;case f.TOUCH_PAN:if(t.enablePan===!1)return;Rt(s),t.update();break;case f.TOUCH_DOLLY_PAN:if(t.enableZoom===!1&&t.enablePan===!1)return;Qt(s),t.update();break;case f.TOUCH_DOLLY_ROTATE:if(t.enableZoom===!1&&t.enableRotate===!1)return;er(s),t.update();break;default:m=f.NONE}}function Nt(s){t.enabled!==!1&&s.preventDefault()}function nr(s){F.push(s)}function Je(s){delete Q[s.pointerId];for(let w=0;w<F.length;w++)if(F[w].pointerId==s.pointerId){F.splice(w,1);return}}function ye(s){let w=Q[s.pointerId];w===void 0&&(w=new Be,Q[s.pointerId]=w),w.set(s.pageX,s.pageY)}function ot(s){const w=s.pointerId===F[0].pointerId?F[1]:F[0];return Q[w.pointerId]}this.dollyIn=(s=X())=>{Re(s),t.update()},this.dollyOut=(s=X())=>{ne(s),t.update()},this.getScale=()=>E,this.setScale=s=>{be(s),t.update()},this.getZoomScale=()=>X(),o!==void 0&&this.connect(o),this.update()}};class ta extends Nr{constructor(r){super(r),this.type=Ne}parse(r){const u=function(_,A){switch(_){case 1:throw new Error("THREE.RGBELoader: Read Error: "+(A||""));case 2:throw new Error("THREE.RGBELoader: Write Error: "+(A||""));case 3:throw new Error("THREE.RGBELoader: Bad File Format: "+(A||""));default:case 4:throw new Error("THREE.RGBELoader: Memory Error: "+(A||""))}},M=`
`,C=function(_,A,F){A=A||1024;let J=_.pos,X=-1,G=0,oe="",W=String.fromCharCode.apply(null,new Uint16Array(_.subarray(J,J+128)));for(;0>(X=W.indexOf(M))&&G<A&&J<_.byteLength;)oe+=W,G+=W.length,J+=128,W+=String.fromCharCode.apply(null,new Uint16Array(_.subarray(J,J+128)));return-1<X?(_.pos+=G+X+1,oe+W.slice(0,X)):!1},E=function(_){const A=/^#\?(\S+)/,F=/^\s*GAMMA\s*=\s*(\d+(\.\d+)?)\s*$/,Q=/^\s*EXPOSURE\s*=\s*(\d+(\.\d+)?)\s*$/,J=/^\s*FORMAT=(\S+)\s*$/,X=/^\s*\-Y\s+(\d+)\s+\+X\s+(\d+)\s*$/,G={valid:0,string:"",comments:"",programtype:"RGBE",format:"",gamma:1,exposure:1,width:0,height:0};let oe,W;for((_.pos>=_.byteLength||!(oe=C(_)))&&u(1,"no header found"),(W=oe.match(A))||u(3,"bad initial token"),G.valid|=1,G.programtype=W[1],G.string+=oe+`
`;oe=C(_),oe!==!1;){if(G.string+=oe+`
`,oe.charAt(0)==="#"){G.comments+=oe+`
`;continue}if((W=oe.match(F))&&(G.gamma=parseFloat(W[1])),(W=oe.match(Q))&&(G.exposure=parseFloat(W[1])),(W=oe.match(J))&&(G.valid|=2,G.format=W[1]),(W=oe.match(X))&&(G.valid|=4,G.height=parseInt(W[1],10),G.width=parseInt(W[2],10)),G.valid&2&&G.valid&4)break}return G.valid&2||u(3,"missing format specifier"),G.valid&4||u(3,"missing image size specifier"),G},j=function(_,A,F){const Q=A;if(Q<8||Q>32767||_[0]!==2||_[1]!==2||_[2]&128)return new Uint8Array(_);Q!==(_[2]<<8|_[3])&&u(3,"wrong scanline width");const J=new Uint8Array(4*A*F);J.length||u(4,"unable to allocate buffer space");let X=0,G=0;const oe=4*Q,W=new Uint8Array(4),xe=new Uint8Array(oe);let Te=F;for(;Te>0&&G<_.byteLength;){G+4>_.byteLength&&u(1),W[0]=_[G++],W[1]=_[G++],W[2]=_[G++],W[3]=_[G++],(W[0]!=2||W[1]!=2||(W[2]<<8|W[3])!=Q)&&u(3,"bad rgbe scanline format");let be=0,ne;for(;be<oe&&G<_.byteLength;){ne=_[G++];const se=ne>128;if(se&&(ne-=128),(ne===0||be+ne>oe)&&u(3,"bad scanline data"),se){const ge=_[G++];for(let Ie=0;Ie<ne;Ie++)xe[be++]=ge}else xe.set(_.subarray(G,G+ne),be),be+=ne,G+=ne}const Re=Q;for(let se=0;se<Re;se++){let ge=0;J[X]=xe[se+ge],ge+=Q,J[X+1]=xe[se+ge],ge+=Q,J[X+2]=xe[se+ge],ge+=Q,J[X+3]=xe[se+ge],X+=4}Te--}return J},z=function(_,A,F,Q){const J=_[A+3],X=Math.pow(2,J-128)/255;F[Q+0]=_[A+0]*X,F[Q+1]=_[A+1]*X,F[Q+2]=_[A+2]*X,F[Q+3]=1},R=function(_,A,F,Q){const J=_[A+3],X=Math.pow(2,J-128)/255;F[Q+0]=ut.toHalfFloat(Math.min(_[A+0]*X,65504)),F[Q+1]=ut.toHalfFloat(Math.min(_[A+1]*X,65504)),F[Q+2]=ut.toHalfFloat(Math.min(_[A+2]*X,65504)),F[Q+3]=ut.toHalfFloat(1)},k=new Uint8Array(r);k.pos=0;const H=E(k),Y=H.width,q=H.height,te=j(k.subarray(k.pos),Y,q);let N,O,re;switch(this.type){case We:re=te.length/4;const _=new Float32Array(re*4);for(let F=0;F<re;F++)z(te,F*4,_,F*4);N=_,O=We;break;case Ne:re=te.length/4;const A=new Uint16Array(re*4);for(let F=0;F<re;F++)R(te,F*4,A,F*4);N=A,O=Ne;break;default:throw new Error("THREE.RGBELoader: Unsupported type: "+this.type)}return{width:Y,height:q,data:N,header:H.string,gamma:H.gamma,exposure:H.exposure,type:O}}setDataType(r){return this.type=r,this}load(r,o,t,c){function d(u,f){switch(u.type){case We:case Ne:"colorSpace"in u?u.colorSpace="srgb-linear":u.encoding=3e3,u.minFilter=Ge,u.magFilter=Ge,u.generateMipmaps=!1,u.flipY=!0;break}o&&o(u,f)}return super.load(r,d,t,c)}}const _t=Pr>=152;class ra extends Nr{constructor(r){super(r),this.type=Ne}parse(r){const A=Math.pow(2.7182818,2.2);function F(e,n){for(var a=0,l=0;l<65536;++l)(l==0||e[l>>3]&1<<(l&7))&&(n[a++]=l);for(var h=a-1;a<65536;)n[a++]=0;return h}function Q(e){for(var n=0;n<16384;n++)e[n]={},e[n].len=0,e[n].lit=0,e[n].p=null}const J={l:0,c:0,lc:0};function X(e,n,a,l,h){for(;a<e;)n=n<<8|ot(l,h),a+=8;a-=e,J.l=n>>a&(1<<e)-1,J.c=n,J.lc=a}const G=new Array(59);function oe(e){for(var n=0;n<=58;++n)G[n]=0;for(var n=0;n<65537;++n)G[e[n]]+=1;for(var a=0,n=58;n>0;--n){var l=a+G[n]>>1;G[n]=a,a=l}for(var n=0;n<65537;++n){var h=e[n];h>0&&(e[n]=h|G[h]++<<6)}}function W(e,n,a,l,h,p,y){for(var v=a,T=0,x=0;h<=p;h++){if(v.value-a.value>l)return!1;X(6,T,x,e,v);var I=J.l;if(T=J.c,x=J.lc,y[h]=I,I==63){if(v.value-a.value>l)throw"Something wrong with hufUnpackEncTable";X(8,T,x,e,v);var S=J.l+6;if(T=J.c,x=J.lc,h+S>p+1)throw"Something wrong with hufUnpackEncTable";for(;S--;)y[h++]=0;h--}else if(I>=59){var S=I-59+2;if(h+S>p+1)throw"Something wrong with hufUnpackEncTable";for(;S--;)y[h++]=0;h--}}oe(y)}function xe(e){return e&63}function Te(e){return e>>6}function be(e,n,a,l){for(;n<=a;n++){var h=Te(e[n]),p=xe(e[n]);if(h>>p)throw"Invalid table entry";if(p>14){var y=l[h>>p-14];if(y.len)throw"Invalid table entry";if(y.lit++,y.p){var v=y.p;y.p=new Array(y.lit);for(var T=0;T<y.lit-1;++T)y.p[T]=v[T]}else y.p=new Array(1);y.p[y.lit-1]=n}else if(p)for(var x=0,T=1<<14-p;T>0;T--){var y=l[(h<<14-p)+x];if(y.len||y.p)throw"Invalid table entry";y.len=p,y.lit=n,x++}}return!0}const ne={c:0,lc:0};function Re(e,n,a,l){e=e<<8|ot(a,l),n+=8,ne.c=e,ne.lc=n}const se={c:0,lc:0};function ge(e,n,a,l,h,p,y,v,T,x){if(e==n){l<8&&(Re(a,l,h,y),a=ne.c,l=ne.lc),l-=8;var I=a>>l,I=new Uint8Array([I])[0];if(T.value+I>x)return!1;for(var S=v[T.value-1];I-- >0;)v[T.value++]=S}else if(T.value<x)v[T.value++]=e;else return!1;se.c=a,se.lc=l}function Ie(e){return e&65535}function Ke(e){var n=Ie(e);return n>32767?n-65536:n}const ae={a:0,b:0};function De(e,n){var a=Ke(e),l=Ke(n),h=l,p=a+(h&1)+(h>>1),y=p,v=p-h;ae.a=y,ae.b=v}function ke(e,n){var a=Ie(e),l=Ie(n),h=a-(l>>1)&65535,p=l+h-32768&65535;ae.a=p,ae.b=h}function Kt(e,n,a,l,h,p,y){for(var v=y<16384,T=a>h?h:a,x=1,I;x<=T;)x<<=1;for(x>>=1,I=x,x>>=1;x>=1;){for(var S=0,me=S+p*(h-I),D=p*x,L=p*I,Z=l*x,$=l*I,le,ue,we,Se;S<=me;S+=L){for(var de=S,He=S+l*(a-I);de<=He;de+=$){var he=de+Z,_e=de+D,Ze=_e+Z;v?(De(e[de+n],e[_e+n]),le=ae.a,we=ae.b,De(e[he+n],e[Ze+n]),ue=ae.a,Se=ae.b,De(le,ue),e[de+n]=ae.a,e[he+n]=ae.b,De(we,Se),e[_e+n]=ae.a,e[Ze+n]=ae.b):(ke(e[de+n],e[_e+n]),le=ae.a,we=ae.b,ke(e[he+n],e[Ze+n]),ue=ae.a,Se=ae.b,ke(le,ue),e[de+n]=ae.a,e[he+n]=ae.b,ke(we,Se),e[_e+n]=ae.a,e[Ze+n]=ae.b)}if(a&x){var _e=de+D;v?De(e[de+n],e[_e+n]):ke(e[de+n],e[_e+n]),le=ae.a,e[_e+n]=ae.b,e[de+n]=le}}if(h&x)for(var de=S,He=S+l*(a-I);de<=He;de+=$){var he=de+Z;v?De(e[de+n],e[he+n]):ke(e[de+n],e[he+n]),le=ae.a,e[he+n]=ae.b,e[de+n]=le}I=x,x>>=1}return S}function qt(e,n,a,l,h,p,y,v,T,x){for(var I=0,S=0,me=v,D=Math.trunc(h.value+(p+7)/8);h.value<D;)for(Re(I,S,a,h),I=ne.c,S=ne.lc;S>=14;){var L=I>>S-14&16383,Z=n[L];if(Z.len)S-=Z.len,ge(Z.lit,y,I,S,a,l,h,T,x,me),I=se.c,S=se.lc;else{if(!Z.p)throw"hufDecode issues";var $;for($=0;$<Z.lit;$++){for(var le=xe(e[Z.p[$]]);S<le&&h.value<D;)Re(I,S,a,h),I=ne.c,S=ne.lc;if(S>=le&&Te(e[Z.p[$]])==(I>>S-le&(1<<le)-1)){S-=le,ge(Z.p[$],y,I,S,a,l,h,T,x,me),I=se.c,S=se.lc;break}}if($==Z.lit)throw"hufDecode issues"}}var ue=8-p&7;for(I>>=ue,S-=ue;S>0;){var Z=n[I<<14-S&16383];if(Z.len)S-=Z.len,ge(Z.lit,y,I,S,a,l,h,T,x,me),I=se.c,S=se.lc;else throw"hufDecode issues"}return!0}function Tt(e,n,a,l,h,p){var y={value:0},v=a.value,T=ye(n,a),x=ye(n,a);a.value+=4;var I=ye(n,a);if(a.value+=4,T<0||T>=65537||x<0||x>=65537)throw"Something wrong with HUF_ENCSIZE";var S=new Array(65537),me=new Array(16384);Q(me);var D=l-(a.value-v);if(W(e,n,a,D,T,x,S),I>8*(l-(a.value-v)))throw"Something wrong with hufUncompress";be(S,T,x,me),qt(S,me,e,n,a,I,x,p,h,y)}function It(e,n,a){for(var l=0;l<a;++l)n[l]=e[n[l]]}function pt(e){for(var n=1;n<e.length;n++){var a=e[n-1]+e[n]-128;e[n]=a}}function ft(e,n){for(var a=0,l=Math.floor((e.length+1)/2),h=0,p=e.length-1;!(h>p||(n[h++]=e[a++],h>p));)n[h++]=e[l++]}function Ct(e){for(var n=e.byteLength,a=new Array,l=0,h=new DataView(e);n>0;){var p=h.getInt8(l++);if(p<0){var y=-p;n-=y+1;for(var v=0;v<y;v++)a.push(h.getUint8(l++))}else{var y=p;n-=2;for(var T=h.getUint8(l++),v=0;v<y+1;v++)a.push(T)}}return a}function Jt(e,n,a,l,h,p){var he=new DataView(p.buffer),y=a[e.idx[0]].width,v=a[e.idx[0]].height,T=3,x=Math.floor(y/8),I=Math.ceil(y/8),S=Math.ceil(v/8),me=y-(I-1)*8,D=v-(S-1)*8,L={value:0},Z=new Array(T),$=new Array(T),le=new Array(T),ue=new Array(T),we=new Array(T);for(let ce=0;ce<T;++ce)we[ce]=n[e.idx[ce]],Z[ce]=ce<1?0:Z[ce-1]+I*S,$[ce]=new Float32Array(64),le[ce]=new Uint16Array(64),ue[ce]=new Uint16Array(I*64);for(let ce=0;ce<S;++ce){var Se=8;ce==S-1&&(Se=D);var de=8;for(let fe=0;fe<I;++fe){fe==I-1&&(de=me);for(let ie=0;ie<T;++ie)le[ie].fill(0),le[ie][0]=h[Z[ie]++],At(L,l,le[ie]),Rt(le[ie],$[ie]),Ot($[ie]);Qt($);for(let ie=0;ie<T;++ie)er($[ie],ue[ie],fe*64)}let Ee=0;for(let fe=0;fe<T;++fe){const ie=a[e.idx[fe]].type;for(let Pe=8*ce;Pe<8*ce+Se;++Pe){Ee=we[fe][Pe];for(let rt=0;rt<x;++rt){const Ce=rt*64+(Pe&7)*8;he.setUint16(Ee+0*2*ie,ue[fe][Ce+0],!0),he.setUint16(Ee+1*2*ie,ue[fe][Ce+1],!0),he.setUint16(Ee+2*2*ie,ue[fe][Ce+2],!0),he.setUint16(Ee+3*2*ie,ue[fe][Ce+3],!0),he.setUint16(Ee+4*2*ie,ue[fe][Ce+4],!0),he.setUint16(Ee+5*2*ie,ue[fe][Ce+5],!0),he.setUint16(Ee+6*2*ie,ue[fe][Ce+6],!0),he.setUint16(Ee+7*2*ie,ue[fe][Ce+7],!0),Ee+=8*2*ie}}if(x!=I)for(let Pe=8*ce;Pe<8*ce+Se;++Pe){const rt=we[fe][Pe]+8*x*2*ie,Ce=x*64+(Pe&7)*8;for(let Ye=0;Ye<de;++Ye)he.setUint16(rt+Ye*2*ie,ue[fe][Ce+Ye],!0)}}}for(var He=new Uint16Array(y),he=new DataView(p.buffer),_e=0;_e<T;++_e){a[e.idx[_e]].decoded=!0;var Ze=a[e.idx[_e]].type;if(a[_e].type==2)for(var wt=0;wt<v;++wt){const ce=we[_e][wt];for(var Oe=0;Oe<y;++Oe)He[Oe]=he.getUint16(ce+Oe*2*Ze,!0);for(var Oe=0;Oe<y;++Oe)he.setFloat32(ce+Oe*2*Ze,b(He[Oe]),!0)}}}function At(e,n,a){for(var l,h=1;h<64;)l=n[e.value],l==65280?h=64:l>>8==255?h+=l&255:(a[h]=l,h++),e.value++}function Rt(e,n){n[0]=b(e[0]),n[1]=b(e[1]),n[2]=b(e[5]),n[3]=b(e[6]),n[4]=b(e[14]),n[5]=b(e[15]),n[6]=b(e[27]),n[7]=b(e[28]),n[8]=b(e[2]),n[9]=b(e[4]),n[10]=b(e[7]),n[11]=b(e[13]),n[12]=b(e[16]),n[13]=b(e[26]),n[14]=b(e[29]),n[15]=b(e[42]),n[16]=b(e[3]),n[17]=b(e[8]),n[18]=b(e[12]),n[19]=b(e[17]),n[20]=b(e[25]),n[21]=b(e[30]),n[22]=b(e[41]),n[23]=b(e[43]),n[24]=b(e[9]),n[25]=b(e[11]),n[26]=b(e[18]),n[27]=b(e[24]),n[28]=b(e[31]),n[29]=b(e[40]),n[30]=b(e[44]),n[31]=b(e[53]),n[32]=b(e[10]),n[33]=b(e[19]),n[34]=b(e[23]),n[35]=b(e[32]),n[36]=b(e[39]),n[37]=b(e[45]),n[38]=b(e[52]),n[39]=b(e[54]),n[40]=b(e[20]),n[41]=b(e[22]),n[42]=b(e[33]),n[43]=b(e[38]),n[44]=b(e[46]),n[45]=b(e[51]),n[46]=b(e[55]),n[47]=b(e[60]),n[48]=b(e[21]),n[49]=b(e[34]),n[50]=b(e[37]),n[51]=b(e[47]),n[52]=b(e[50]),n[53]=b(e[56]),n[54]=b(e[59]),n[55]=b(e[61]),n[56]=b(e[35]),n[57]=b(e[36]),n[58]=b(e[48]),n[59]=b(e[49]),n[60]=b(e[57]),n[61]=b(e[58]),n[62]=b(e[62]),n[63]=b(e[63])}function Ot(e){const n=.5*Math.cos(.7853975),a=.5*Math.cos(3.14159/16),l=.5*Math.cos(3.14159/8),h=.5*Math.cos(3*3.14159/16),p=.5*Math.cos(5*3.14159/16),y=.5*Math.cos(3*3.14159/8),v=.5*Math.cos(7*3.14159/16);for(var T=new Array(4),x=new Array(4),I=new Array(4),S=new Array(4),me=0;me<8;++me){var D=me*8;T[0]=l*e[D+2],T[1]=y*e[D+2],T[2]=l*e[D+6],T[3]=y*e[D+6],x[0]=a*e[D+1]+h*e[D+3]+p*e[D+5]+v*e[D+7],x[1]=h*e[D+1]-v*e[D+3]-a*e[D+5]-p*e[D+7],x[2]=p*e[D+1]-a*e[D+3]+v*e[D+5]+h*e[D+7],x[3]=v*e[D+1]-p*e[D+3]+h*e[D+5]-a*e[D+7],I[0]=n*(e[D+0]+e[D+4]),I[3]=n*(e[D+0]-e[D+4]),I[1]=T[0]+T[3],I[2]=T[1]-T[2],S[0]=I[0]+I[1],S[1]=I[3]+I[2],S[2]=I[3]-I[2],S[3]=I[0]-I[1],e[D+0]=S[0]+x[0],e[D+1]=S[1]+x[1],e[D+2]=S[2]+x[2],e[D+3]=S[3]+x[3],e[D+4]=S[3]-x[3],e[D+5]=S[2]-x[2],e[D+6]=S[1]-x[1],e[D+7]=S[0]-x[0]}for(var L=0;L<8;++L)T[0]=l*e[16+L],T[1]=y*e[16+L],T[2]=l*e[48+L],T[3]=y*e[48+L],x[0]=a*e[8+L]+h*e[24+L]+p*e[40+L]+v*e[56+L],x[1]=h*e[8+L]-v*e[24+L]-a*e[40+L]-p*e[56+L],x[2]=p*e[8+L]-a*e[24+L]+v*e[40+L]+h*e[56+L],x[3]=v*e[8+L]-p*e[24+L]+h*e[40+L]-a*e[56+L],I[0]=n*(e[L]+e[32+L]),I[3]=n*(e[L]-e[32+L]),I[1]=T[0]+T[3],I[2]=T[1]-T[2],S[0]=I[0]+I[1],S[1]=I[3]+I[2],S[2]=I[3]-I[2],S[3]=I[0]-I[1],e[0+L]=S[0]+x[0],e[8+L]=S[1]+x[1],e[16+L]=S[2]+x[2],e[24+L]=S[3]+x[3],e[32+L]=S[3]-x[3],e[40+L]=S[2]-x[2],e[48+L]=S[1]-x[1],e[56+L]=S[0]-x[0]}function Qt(e){for(var n=0;n<64;++n){var a=e[0][n],l=e[1][n],h=e[2][n];e[0][n]=a+1.5747*h,e[1][n]=a-.1873*l-.4682*h,e[2][n]=a+1.8556*l}}function er(e,n,a){for(var l=0;l<64;++l)n[a+l]=ut.toHalfFloat(Pt(e[l]))}function Pt(e){return e<=1?Math.sign(e)*Math.pow(Math.abs(e),2.2):Math.sign(e)*Math.pow(A,Math.abs(e)-1)}function nt(e){return new DataView(e.array.buffer,e.offset.value,e.size)}function qe(e){var n=e.viewer.buffer.slice(e.offset.value,e.offset.value+e.size),a=new Uint8Array(Ct(n)),l=new Uint8Array(a.length);return pt(a),ft(a,l),new DataView(l.buffer)}function mt(e){var n=e.array.slice(e.offset.value,e.offset.value+e.size),a=Lt(n),l=new Uint8Array(a.length);return pt(a),ft(a,l),new DataView(l.buffer)}function tr(e){for(var n=e.viewer,a={value:e.offset.value},l=new Uint16Array(e.width*e.scanlineBlockSize*(e.channels*e.type)),h=new Uint8Array(8192),p=0,y=new Array(e.channels),v=0;v<e.channels;v++)y[v]={},y[v].start=p,y[v].end=y[v].start,y[v].nx=e.width,y[v].ny=e.lines,y[v].size=e.type,p+=y[v].nx*y[v].ny*y[v].size;var T=Me(n,a),x=Me(n,a);if(x>=8192)throw"Something is wrong with PIZ_COMPRESSION BITMAP_SIZE";if(T<=x)for(var v=0;v<x-T+1;v++)h[v+T]=s(n,a);var I=new Uint16Array(65536),S=F(h,I),me=ye(n,a);Tt(e.array,n,a,me,l,p);for(var v=0;v<e.channels;++v)for(var D=y[v],L=0;L<y[v].size;++L)Kt(l,D.start+L,D.nx,D.size,D.ny,D.nx*D.size,S);It(I,l,p);for(var Z=0,$=new Uint8Array(l.buffer.byteLength),le=0;le<e.lines;le++)for(var ue=0;ue<e.channels;ue++){var D=y[ue],we=D.nx*D.size,Se=new Uint8Array(l.buffer,D.end*2,we*2);$.set(Se,Z),Z+=we*2,D.end+=we}return new DataView($.buffer)}function Ft(e){var n=e.array.slice(e.offset.value,e.offset.value+e.size),a=Lt(n);const l=e.lines*e.channels*e.width,h=e.type==1?new Uint16Array(l):new Uint32Array(l);let p=0,y=0;const v=new Array(4);for(let T=0;T<e.lines;T++)for(let x=0;x<e.channels;x++){let I=0;switch(e.type){case 1:v[0]=p,v[1]=v[0]+e.width,p=v[1]+e.width;for(let S=0;S<e.width;++S){const me=a[v[0]++]<<8|a[v[1]++];I+=me,h[y]=I,y++}break;case 2:v[0]=p,v[1]=v[0]+e.width,v[2]=v[1]+e.width,p=v[2]+e.width;for(let S=0;S<e.width;++S){const me=a[v[0]++]<<24|a[v[1]++]<<16|a[v[2]++]<<8;I+=me,h[y]=I,y++}break}}return new DataView(h.buffer)}function at(e){var n=e.viewer,a={value:e.offset.value},l=new Uint8Array(e.width*e.lines*(e.channels*e.type*2)),h={version:w(n,a),unknownUncompressedSize:w(n,a),unknownCompressedSize:w(n,a),acCompressedSize:w(n,a),dcCompressedSize:w(n,a),rleCompressedSize:w(n,a),rleUncompressedSize:w(n,a),rleRawSize:w(n,a),totalAcUncompressedCount:w(n,a),totalDcUncompressedCount:w(n,a),acCompression:w(n,a)};if(h.version<2)throw"EXRLoader.parse: "+gt.compression+" version "+h.version+" is unsupported";for(var p=new Array,y=Me(n,a)-2;y>0;){var v=it(n.buffer,a),T=s(n,a),x=T>>2&3,I=(T>>4)-1,S=new Int8Array([I])[0],me=s(n,a);p.push({name:v,index:S,type:me,compression:x}),y-=v.length+3}for(var D=gt.channels,L=new Array(e.channels),Z=0;Z<e.channels;++Z){var $=L[Z]={},le=D[Z];$.name=le.name,$.compression=0,$.decoded=!1,$.type=le.pixelType,$.pLinear=le.pLinear,$.width=e.width,$.height=e.lines}for(var ue={idx:new Array(3)},we=0;we<e.channels;++we)for(var $=L[we],Z=0;Z<p.length;++Z){var Se=p[Z];$.name==Se.name&&($.compression=Se.compression,Se.index>=0&&(ue.idx[Se.index]=we),$.offset=we)}if(h.acCompressedSize>0)switch(h.acCompression){case 0:var he=new Uint16Array(h.totalAcUncompressedCount);Tt(e.array,n,a,h.acCompressedSize,he,h.totalAcUncompressedCount);break;case 1:var de=e.array.slice(a.value,a.value+h.totalAcUncompressedCount),He=Lt(de),he=new Uint16Array(He.buffer);a.value+=h.totalAcUncompressedCount;break}if(h.dcCompressedSize>0){var _e={array:e.array,offset:a,size:h.dcCompressedSize},Ze=new Uint16Array(mt(_e).buffer);a.value+=h.dcCompressedSize}if(h.rleRawSize>0){var de=e.array.slice(a.value,a.value+h.rleCompressedSize),He=Lt(de),wt=Ct(He.buffer);a.value+=h.rleCompressedSize}for(var Oe=0,ce=new Array(L.length),Z=0;Z<ce.length;++Z)ce[Z]=new Array;for(var Ee=0;Ee<e.lines;++Ee)for(var fe=0;fe<L.length;++fe)ce[fe].push(Oe),Oe+=L[fe].width*e.type*2;Jt(ue,ce,L,he,Ze,l);for(var Z=0;Z<L.length;++Z){var $=L[Z];if(!$.decoded)switch($.compression){case 2:for(var ie=0,Pe=0,Ee=0;Ee<e.lines;++Ee){for(var rt=ce[Z][ie],Ce=0;Ce<$.width;++Ce){for(var Ye=0;Ye<2*$.type;++Ye)l[rt++]=wt[Pe+Ye*$.width*$.height];Pe++}ie++}break;case 1:default:throw"EXRLoader.parse: unsupported channel compression"}}return new DataView(l.buffer)}function it(e,n){for(var a=new Uint8Array(e),l=0;a[n.value+l]!=0;)l+=1;var h=new TextDecoder().decode(a.slice(n.value,n.value+l));return n.value=n.value+l+1,h}function rr(e,n,a){var l=new TextDecoder().decode(new Uint8Array(e).slice(n.value,n.value+a));return n.value=n.value+a,l}function Nt(e,n){var a=Je(e,n),l=ye(e,n);return[a,l]}function nr(e,n){var a=ye(e,n),l=ye(e,n);return[a,l]}function Je(e,n){var a=e.getInt32(n.value,!0);return n.value=n.value+4,a}function ye(e,n){var a=e.getUint32(n.value,!0);return n.value=n.value+4,a}function ot(e,n){var a=e[n.value];return n.value=n.value+1,a}function s(e,n){var a=e.getUint8(n.value);return n.value=n.value+1,a}const w=function(e,n){let a;return"getBigInt64"in DataView.prototype?a=Number(e.getBigInt64(n.value,!0)):a=e.getUint32(n.value+4,!0)+Number(e.getUint32(n.value,!0)<<32),n.value+=8,a};function P(e,n){var a=e.getFloat32(n.value,!0);return n.value+=4,a}function ee(e,n){return ut.toHalfFloat(P(e,n))}function b(e){var n=(e&31744)>>10,a=e&1023;return(e>>15?-1:1)*(n?n===31?a?NaN:1/0:Math.pow(2,n-15)*(1+a/1024):6103515625e-14*(a/1024))}function Me(e,n){var a=e.getUint16(n.value,!0);return n.value+=2,a}function ze(e,n){return b(Me(e,n))}function yr(e,n,a,l){for(var h=a.value,p=[];a.value<h+l-1;){var y=it(n,a),v=Je(e,a),T=s(e,a);a.value+=3;var x=Je(e,a),I=Je(e,a);p.push({name:y,pixelType:v,pLinear:T,xSampling:x,ySampling:I})}return a.value+=1,p}function Dt(e,n){var a=P(e,n),l=P(e,n),h=P(e,n),p=P(e,n),y=P(e,n),v=P(e,n),T=P(e,n),x=P(e,n);return{redX:a,redY:l,greenX:h,greenY:p,blueX:y,blueY:v,whiteX:T,whiteY:x}}function Le(e,n){var a=["NO_COMPRESSION","RLE_COMPRESSION","ZIPS_COMPRESSION","ZIP_COMPRESSION","PIZ_COMPRESSION","PXR24_COMPRESSION","B44_COMPRESSION","B44A_COMPRESSION","DWAA_COMPRESSION","DWAB_COMPRESSION"],l=s(e,n);return a[l]}function Ue(e,n){var a=ye(e,n),l=ye(e,n),h=ye(e,n),p=ye(e,n);return{xMin:a,yMin:l,xMax:h,yMax:p}}function Qe(e,n){var a=["INCREASING_Y"],l=s(e,n);return a[l]}function et(e,n){var a=P(e,n),l=P(e,n);return[a,l]}function tt(e,n){var a=P(e,n),l=P(e,n),h=P(e,n);return[a,l,h]}function st(e,n,a,l,h){if(l==="string"||l==="stringvector"||l==="iccProfile")return rr(n,a,h);if(l==="chlist")return yr(e,n,a,h);if(l==="chromaticities")return Dt(e,a);if(l==="compression")return Le(e,a);if(l==="box2i")return Ue(e,a);if(l==="lineOrder")return Qe(e,a);if(l==="float")return P(e,a);if(l==="v2f")return et(e,a);if(l==="v3f")return tt(e,a);if(l==="int")return Je(e,a);if(l==="rational")return Nt(e,a);if(l==="timecode")return nr(e,a);if(l==="preview")return a.value+=h,"skipped";a.value+=h}function qr(e,n,a){const l={};if(e.getUint32(0,!0)!=20000630)throw"THREE.EXRLoader: provided file doesn't appear to be in OpenEXR format.";l.version=e.getUint8(4);const h=e.getUint8(5);l.spec={singleTile:!!(h&2),longName:!!(h&4),deepFormat:!!(h&8),multiPart:!!(h&16)},a.value=8;for(var p=!0;p;){var y=it(n,a);if(y==0)p=!1;else{var v=it(n,a),T=ye(e,a),x=st(e,n,a,v,T);x===void 0?console.warn(`EXRLoader.parse: skipped unknown header attribute type '${v}'.`):l[y]=x}}if(h&-5)throw console.error("EXRHeader:",l),"THREE.EXRLoader: provided file is currently unsupported.";return l}function Jr(e,n,a,l,h){const p={size:0,viewer:n,array:a,offset:l,width:e.dataWindow.xMax-e.dataWindow.xMin+1,height:e.dataWindow.yMax-e.dataWindow.yMin+1,channels:e.channels.length,bytesPerLine:null,lines:null,inputSize:null,type:e.channels[0].pixelType,uncompress:null,getter:null,format:null,[_t?"colorSpace":"encoding"]:null};switch(e.compression){case"NO_COMPRESSION":p.lines=1,p.uncompress=nt;break;case"RLE_COMPRESSION":p.lines=1,p.uncompress=qe;break;case"ZIPS_COMPRESSION":p.lines=1,p.uncompress=mt;break;case"ZIP_COMPRESSION":p.lines=16,p.uncompress=mt;break;case"PIZ_COMPRESSION":p.lines=32,p.uncompress=tr;break;case"PXR24_COMPRESSION":p.lines=16,p.uncompress=Ft;break;case"DWAA_COMPRESSION":p.lines=32,p.uncompress=at;break;case"DWAB_COMPRESSION":p.lines=256,p.uncompress=at;break;default:throw"EXRLoader.parse: "+e.compression+" is unsupported"}if(p.scanlineBlockSize=p.lines,p.type==1)switch(h){case We:p.getter=ze,p.inputSize=2;break;case Ne:p.getter=Me,p.inputSize=2;break}else if(p.type==2)switch(h){case We:p.getter=P,p.inputSize=4;break;case Ne:p.getter=ee,p.inputSize=4}else throw"EXRLoader.parse: unsupported pixelType "+p.type+" for "+e.compression+".";p.blockCount=(e.dataWindow.yMax+1)/p.scanlineBlockSize;for(var y=0;y<p.blockCount;y++)w(n,l);p.outputChannels=p.channels==3?4:p.channels;const v=p.width*p.height*p.outputChannels;switch(h){case We:p.byteArray=new Float32Array(v),p.channels<p.outputChannels&&p.byteArray.fill(1,0,v);break;case Ne:p.byteArray=new Uint16Array(v),p.channels<p.outputChannels&&p.byteArray.fill(15360,0,v);break;default:console.error("THREE.EXRLoader: unsupported type: ",h);break}return p.bytesPerLine=p.width*p.inputSize*p.channels,p.outputChannels==4?p.format=bt:p.format=an,_t?p.colorSpace="srgb-linear":p.encoding=3e3,p}const kt=new DataView(r),Qr=new Uint8Array(r),vt={value:0},gt=qr(kt,r,vt),K=Jr(gt,kt,Qr,vt,this.type),Er={value:0},en={R:0,G:1,B:2,A:3,Y:0};for(let e=0;e<K.height/K.scanlineBlockSize;e++){const n=ye(kt,vt);K.size=ye(kt,vt),K.lines=n+K.scanlineBlockSize>K.height?K.height-n:K.scanlineBlockSize;const l=K.size<K.lines*K.bytesPerLine?K.uncompress(K):nt(K);vt.value+=K.size;for(let h=0;h<K.scanlineBlockSize;h++){const p=h+e*K.scanlineBlockSize;if(p>=K.height)break;for(let y=0;y<K.channels;y++){const v=en[gt.channels[y].name];for(let T=0;T<K.width;T++){Er.value=(h*(K.channels*K.width)+y*K.width+T)*K.inputSize;const x=(K.height-1-p)*(K.width*K.outputChannels)+T*K.outputChannels+v;K.byteArray[x]=K.getter(l,Er)}}}}return{header:gt,width:K.width,height:K.height,data:K.byteArray,format:K.format,[_t?"colorSpace":"encoding"]:K[_t?"colorSpace":"encoding"],type:this.type}}setDataType(r){return this.type=r,this}load(r,o,t,c){function d(u,f){_t?u.colorSpace=f.colorSpace:u.encoding=f.encoding,u.minFilter=Ge,u.magFilter=Ge,u.generateMipmaps=!1,u.flipY=!1,o&&o(u,f)}return super.load(r,d,t,c)}}function na(i,r,o,t){var c;return c=class extends $t{constructor(d){super({vertexShader:r,fragmentShader:o,...d});for(const u in i)this.uniforms[u]=new on(i[u]),Object.defineProperty(this,u,{get(){return this.uniforms[u].value},set(f){this.uniforms[u].value=f}});this.uniforms=sn.clone(this.uniforms)}},c.key=ln.generateUUID(),c}const aa=()=>parseInt(cn.replace(/\D+/g,"")),ia=aa(),oa=U.forwardRef(({makeDefault:i,camera:r,regress:o,domElement:t,enableDamping:c=!0,keyEvents:d=!1,onChange:u,onStart:f,onEnd:m,...g},M)=>{const C=Ae(O=>O.invalidate),E=Ae(O=>O.camera),j=Ae(O=>O.gl),z=Ae(O=>O.events),R=Ae(O=>O.setEvents),k=Ae(O=>O.set),H=Ae(O=>O.get),Y=Ae(O=>O.performance),q=r||E,te=t||z.connected||j.domElement,N=U.useMemo(()=>new ea(q),[q]);return hr(()=>{N.enabled&&N.update()},-1),U.useEffect(()=>(d&&N.connect(d===!0?te:d),N.connect(te),()=>void N.dispose()),[d,te,o,N,C]),U.useEffect(()=>{const O=A=>{C(),o&&Y.regress(),u&&u(A)},re=A=>{f&&f(A)},_=A=>{m&&m(A)};return N.addEventListener("change",O),N.addEventListener("start",re),N.addEventListener("end",_),()=>{N.removeEventListener("start",re),N.removeEventListener("end",_),N.removeEventListener("change",O)}},[u,f,m,N,C,R]),U.useEffect(()=>{if(i){const O=H().controls;return k({controls:N}),()=>k({controls:O})}},[i,N]),U.createElement("primitive",Zt({ref:M,object:N,enableDamping:c},g))}),sa=na({cellSize:.5,sectionSize:1,fadeDistance:100,fadeStrength:1,fadeFrom:1,cellThickness:.5,sectionThickness:1,cellColor:new Wt,sectionColor:new Wt,infiniteGrid:!1,followCamera:!1,worldCamProjPosition:new ve,worldPlanePosition:new ve},`
    varying vec3 localPosition;
    varying vec4 worldPosition;

    uniform vec3 worldCamProjPosition;
    uniform vec3 worldPlanePosition;
    uniform float fadeDistance;
    uniform bool infiniteGrid;
    uniform bool followCamera;

    void main() {
      localPosition = position.xzy;
      if (infiniteGrid) localPosition *= 1.0 + fadeDistance;
      
      worldPosition = modelMatrix * vec4(localPosition, 1.0);
      if (followCamera) {
        worldPosition.xyz += (worldCamProjPosition - worldPlanePosition);
        localPosition = (inverse(modelMatrix) * worldPosition).xyz;
      }

      gl_Position = projectionMatrix * viewMatrix * worldPosition;
    }
  `,`
    varying vec3 localPosition;
    varying vec4 worldPosition;

    uniform vec3 worldCamProjPosition;
    uniform float cellSize;
    uniform float sectionSize;
    uniform vec3 cellColor;
    uniform vec3 sectionColor;
    uniform float fadeDistance;
    uniform float fadeStrength;
    uniform float fadeFrom;
    uniform float cellThickness;
    uniform float sectionThickness;

    float getGrid(float size, float thickness) {
      vec2 r = localPosition.xz / size;
      vec2 grid = abs(fract(r - 0.5) - 0.5) / fwidth(r);
      float line = min(grid.x, grid.y) + 1.0 - thickness;
      return 1.0 - min(line, 1.0);
    }

    void main() {
      float g1 = getGrid(cellSize, cellThickness);
      float g2 = getGrid(sectionSize, sectionThickness);

      vec3 from = worldCamProjPosition*vec3(fadeFrom);
      float dist = distance(from, worldPosition.xyz);
      float d = 1.0 - min(dist / fadeDistance, 1.0);
      vec3 color = mix(cellColor, sectionColor, min(1.0, sectionThickness * g2));

      gl_FragColor = vec4(color, (g1 + g2) * pow(d, fadeStrength));
      gl_FragColor.a = mix(0.75 * gl_FragColor.a, gl_FragColor.a, g2);
      if (gl_FragColor.a <= 0.0) discard;

      #include <tonemapping_fragment>
      #include <${ia>=154?"colorspace_fragment":"encodings_fragment"}>
    }
  `),la=U.forwardRef(({args:i,cellColor:r="#000000",sectionColor:o="#2080ff",cellSize:t=.5,sectionSize:c=1,followCamera:d=!1,infiniteGrid:u=!1,fadeDistance:f=100,fadeStrength:m=1,fadeFrom:g=1,cellThickness:M=.5,sectionThickness:C=1,side:E=un,...j},z)=>{Dr({GridMaterial:sa});const R=U.useRef(null);U.useImperativeHandle(z,()=>R.current,[]);const k=new Fr,H=new ve(0,1,0),Y=new ve(0,0,0);hr(N=>{k.setFromNormalAndCoplanarPoint(H,Y).applyMatrix4(R.current.matrixWorld);const O=R.current.material,re=O.uniforms.worldCamProjPosition,_=O.uniforms.worldPlanePosition;k.projectPoint(N.camera.position,re.value),_.value.set(0,0,0).applyMatrix4(R.current.matrixWorld)});const q={cellSize:t,sectionSize:c,cellColor:r,sectionColor:o,cellThickness:M,sectionThickness:C},te={fadeDistance:f,fadeStrength:m,fadeFrom:g,infiniteGrid:u,followCamera:d};return U.createElement("mesh",Zt({ref:R,frustumCulled:!1},j),U.createElement("gridMaterial",Zt({transparent:!0,"extensions-derivatives":!0,side:E},q,te)),U.createElement("planeGeometry",{args:i}))}),Wr=(i,r,o)=>{let t;switch(i){case lr:t=new Uint8ClampedArray(r*o*4);break;case Ne:t=new Uint16Array(r*o*4);break;case gn:t=new Uint32Array(r*o*4);break;case vn:t=new Int8Array(r*o*4);break;case mn:t=new Int16Array(r*o*4);break;case fn:t=new Int32Array(r*o*4);break;case We:t=new Float32Array(r*o*4);break;default:throw new Error("Unsupported data type")}return t};let Bt;const ca=(i,r,o,t)=>{if(Bt!==void 0)return Bt;const c=new Ur(1,1,t);r.setRenderTarget(c);const d=new Xt(new Lr,new pn({color:16777215}));r.render(d,o),r.setRenderTarget(null);const u=Wr(i,c.width,c.height);return r.readRenderTargetPixels(c,0,0,c.width,c.height,u),c.dispose(),d.geometry.dispose(),d.material.dispose(),Bt=u[0]!==0,Bt};class pr{constructor(r){var o,t,c,d,u,f,m,g,M,C,E,j,z,R,k,H;this._rendererIsDisposable=!1,this._supportsReadPixels=!0,this.render=()=>{this._renderer.setRenderTarget(this._renderTarget);try{this._renderer.render(this._scene,this._camera)}catch(q){throw this._renderer.setRenderTarget(null),q}this._renderer.setRenderTarget(null)},this._width=r.width,this._height=r.height,this._type=r.type,this._colorSpace=r.colorSpace;const Y={format:bt,depthBuffer:!1,stencilBuffer:!1,type:this._type,colorSpace:this._colorSpace,anisotropy:((o=r.renderTargetOptions)===null||o===void 0?void 0:o.anisotropy)!==void 0?(t=r.renderTargetOptions)===null||t===void 0?void 0:t.anisotropy:1,generateMipmaps:((c=r.renderTargetOptions)===null||c===void 0?void 0:c.generateMipmaps)!==void 0?(d=r.renderTargetOptions)===null||d===void 0?void 0:d.generateMipmaps:!1,magFilter:((u=r.renderTargetOptions)===null||u===void 0?void 0:u.magFilter)!==void 0?(f=r.renderTargetOptions)===null||f===void 0?void 0:f.magFilter:Ge,minFilter:((m=r.renderTargetOptions)===null||m===void 0?void 0:m.minFilter)!==void 0?(g=r.renderTargetOptions)===null||g===void 0?void 0:g.minFilter:Ge,samples:((M=r.renderTargetOptions)===null||M===void 0?void 0:M.samples)!==void 0?(C=r.renderTargetOptions)===null||C===void 0?void 0:C.samples:void 0,wrapS:((E=r.renderTargetOptions)===null||E===void 0?void 0:E.wrapS)!==void 0?(j=r.renderTargetOptions)===null||j===void 0?void 0:j.wrapS:$e,wrapT:((z=r.renderTargetOptions)===null||z===void 0?void 0:z.wrapT)!==void 0?(R=r.renderTargetOptions)===null||R===void 0?void 0:R.wrapT:$e};if(this._material=r.material,r.renderer?this._renderer=r.renderer:(this._renderer=pr.instantiateRenderer(),this._rendererIsDisposable=!0),this._scene=new kr,this._camera=new zt,this._camera.position.set(0,0,10),this._camera.left=-.5,this._camera.right=.5,this._camera.top=.5,this._camera.bottom=-.5,this._camera.updateProjectionMatrix(),!ca(this._type,this._renderer,this._camera,Y)){let q;switch(this._type){case Ne:q=this._renderer.extensions.has("EXT_color_buffer_float")?We:void 0;break}q!==void 0?(console.warn(`This browser does not support reading pixels from ${this._type} RenderTargets, switching to ${We}`),this._type=q):(this._supportsReadPixels=!1,console.warn("This browser dos not support toArray or toDataTexture, calls to those methods will result in an error thrown"))}this._quad=new Xt(new Lr,this._material),this._quad.geometry.computeBoundingBox(),this._scene.add(this._quad),this._renderTarget=new Ur(this.width,this.height,Y),this._renderTarget.texture.mapping=((k=r.renderTargetOptions)===null||k===void 0?void 0:k.mapping)!==void 0?(H=r.renderTargetOptions)===null||H===void 0?void 0:H.mapping:Yt}static instantiateRenderer(){const r=new dn;return r.setSize(128,128),r}toArray(){if(!this._supportsReadPixels)throw new Error("Can't read pixels in this browser");const r=Wr(this._type,this._width,this._height);return this._renderer.readRenderTargetPixels(this._renderTarget,0,0,this._width,this._height,r),r}toDataTexture(r){const o=new hn(this.toArray(),this.width,this.height,bt,this._type,(r==null?void 0:r.mapping)||Yt,(r==null?void 0:r.wrapS)||$e,(r==null?void 0:r.wrapT)||$e,(r==null?void 0:r.magFilter)||Ge,(r==null?void 0:r.minFilter)||Ge,(r==null?void 0:r.anisotropy)||1,sr);return o.generateMipmaps=(r==null?void 0:r.generateMipmaps)!==void 0?r==null?void 0:r.generateMipmaps:!1,o}disposeOnDemandRenderer(){this._renderer.setRenderTarget(null),this._rendererIsDisposable&&(this._renderer.dispose(),this._renderer.forceContextLoss())}dispose(r){this.disposeOnDemandRenderer(),r&&this.renderTarget.dispose(),this.material instanceof $t&&Object.values(this.material.uniforms).forEach(o=>{o.value instanceof dt&&o.value.dispose()}),Object.values(this.material).forEach(o=>{o instanceof dt&&o.dispose()}),this.material.dispose(),this._quad.geometry.dispose()}get width(){return this._width}set width(r){this._width=r,this._renderTarget.setSize(this._width,this._height)}get height(){return this._height}set height(r){this._height=r,this._renderTarget.setSize(this._width,this._height)}get renderer(){return this._renderer}get renderTarget(){return this._renderTarget}set renderTarget(r){this._renderTarget=r,this._width=r.width,this._height=r.height}get material(){return this._material}get type(){return this._type}get colorSpace(){return this._colorSpace}}const ua=`
varying vec2 vUv;

void main() {
  vUv = uv;
  gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
`,da=`
// min half float value
#define HALF_FLOAT_MIN vec3( -65504, -65504, -65504 )
// max half float value
#define HALF_FLOAT_MAX vec3( 65504, 65504, 65504 )

uniform sampler2D sdr;
uniform sampler2D gainMap;
uniform vec3 gamma;
uniform vec3 offsetHdr;
uniform vec3 offsetSdr;
uniform vec3 gainMapMin;
uniform vec3 gainMapMax;
uniform float weightFactor;

varying vec2 vUv;

void main() {
  vec3 rgb = texture2D( sdr, vUv ).rgb;
  vec3 recovery = texture2D( gainMap, vUv ).rgb;
  vec3 logRecovery = pow( recovery, gamma );
  vec3 logBoost = gainMapMin * ( 1.0 - logRecovery ) + gainMapMax * logRecovery;
  vec3 hdrColor = (rgb + offsetSdr) * exp2( logBoost * weightFactor ) - offsetHdr;
  vec3 clampedHdrColor = max( HALF_FLOAT_MIN, min( HALF_FLOAT_MAX, hdrColor ));
  gl_FragColor = vec4( clampedHdrColor , 1.0 );
}
`;class ha extends $t{constructor({gamma:r,offsetHdr:o,offsetSdr:t,gainMapMin:c,gainMapMax:d,maxDisplayBoost:u,hdrCapacityMin:f,hdrCapacityMax:m,sdr:g,gainMap:M}){super({name:"GainMapDecoderMaterial",vertexShader:ua,fragmentShader:da,uniforms:{sdr:{value:g},gainMap:{value:M},gamma:{value:new ve(1/r[0],1/r[1],1/r[2])},offsetHdr:{value:new ve().fromArray(o)},offsetSdr:{value:new ve().fromArray(t)},gainMapMin:{value:new ve().fromArray(c)},gainMapMax:{value:new ve().fromArray(d)},weightFactor:{value:(Math.log2(u)-f)/(m-f)}},blending:En,depthTest:!1,depthWrite:!1}),this._maxDisplayBoost=u,this._hdrCapacityMin=f,this._hdrCapacityMax=m,this.needsUpdate=!0,this.uniformsNeedUpdate=!0}get sdr(){return this.uniforms.sdr.value}set sdr(r){this.uniforms.sdr.value=r}get gainMap(){return this.uniforms.gainMap.value}set gainMap(r){this.uniforms.gainMap.value=r}get offsetHdr(){return this.uniforms.offsetHdr.value.toArray()}set offsetHdr(r){this.uniforms.offsetHdr.value.fromArray(r)}get offsetSdr(){return this.uniforms.offsetSdr.value.toArray()}set offsetSdr(r){this.uniforms.offsetSdr.value.fromArray(r)}get gainMapMin(){return this.uniforms.gainMapMin.value.toArray()}set gainMapMin(r){this.uniforms.gainMapMin.value.fromArray(r)}get gainMapMax(){return this.uniforms.gainMapMax.value.toArray()}set gainMapMax(r){this.uniforms.gainMapMax.value.fromArray(r)}get gamma(){const r=this.uniforms.gamma.value;return[1/r.x,1/r.y,1/r.z]}set gamma(r){const o=this.uniforms.gamma.value;o.x=1/r[0],o.y=1/r[1],o.z=1/r[2]}get hdrCapacityMin(){return this._hdrCapacityMin}set hdrCapacityMin(r){this._hdrCapacityMin=r,this.calculateWeight()}get hdrCapacityMax(){return this._hdrCapacityMax}set hdrCapacityMax(r){this._hdrCapacityMax=r,this.calculateWeight()}get maxDisplayBoost(){return this._maxDisplayBoost}set maxDisplayBoost(r){this._maxDisplayBoost=Math.max(1,Math.min(65504,r)),this.calculateWeight()}calculateWeight(){const r=(Math.log2(this._maxDisplayBoost)-this._hdrCapacityMin)/(this._hdrCapacityMax-this._hdrCapacityMin);this.uniforms.weightFactor.value=Math.max(0,Math.min(1,r))}}class Yr extends Error{}class Xr extends Error{}const yt=(i,r,o)=>{const t=new RegExp(`${r}="([^"]*)"`,"i").exec(i);if(t)return t[1];const c=new RegExp(`<${r}[^>]*>([\\s\\S]*?)</${r}>`,"i").exec(i);if(c){const d=c[1].match(/<rdf:li>([^<]*)<\/rdf:li>/g);return d&&d.length===3?d.map(u=>u.replace(/<\/?rdf:li>/g,"")):c[1].trim()}if(o!==void 0)return o;throw new Error(`Can't find ${r} in gainmap metadata`)},pa=i=>{let r;typeof TextDecoder<"u"?r=new TextDecoder().decode(i):r=i.toString();let o=r.indexOf("<x:xmpmeta");for(;o!==-1;){const t=r.indexOf("x:xmpmeta>",o),c=r.slice(o,t+10);try{const d=yt(c,"hdrgm:GainMapMin","0"),u=yt(c,"hdrgm:GainMapMax"),f=yt(c,"hdrgm:Gamma","1"),m=yt(c,"hdrgm:OffsetSDR","0.015625"),g=yt(c,"hdrgm:OffsetHDR","0.015625"),M=/hdrgm:HDRCapacityMin="([^"]*)"/.exec(c),C=M?M[1]:"0",E=/hdrgm:HDRCapacityMax="([^"]*)"/.exec(c);if(!E)throw new Error("Incomplete gainmap metadata");const j=E[1];return{gainMapMin:Array.isArray(d)?d.map(z=>parseFloat(z)):[parseFloat(d),parseFloat(d),parseFloat(d)],gainMapMax:Array.isArray(u)?u.map(z=>parseFloat(z)):[parseFloat(u),parseFloat(u),parseFloat(u)],gamma:Array.isArray(f)?f.map(z=>parseFloat(z)):[parseFloat(f),parseFloat(f),parseFloat(f)],offsetSdr:Array.isArray(m)?m.map(z=>parseFloat(z)):[parseFloat(m),parseFloat(m),parseFloat(m)],offsetHdr:Array.isArray(g)?g.map(z=>parseFloat(z)):[parseFloat(g),parseFloat(g),parseFloat(g)],hdrCapacityMin:parseFloat(C),hdrCapacityMax:parseFloat(j)}}catch{}o=r.indexOf("<x:xmpmeta",t)}};class fa{constructor(r){this.options={debug:r&&r.debug!==void 0?r.debug:!1,extractFII:r&&r.extractFII!==void 0?r.extractFII:!0,extractNonFII:r&&r.extractNonFII!==void 0?r.extractNonFII:!0}}extract(r){return new Promise((o,t)=>{const c=this.options.debug,d=new DataView(r.buffer);if(d.getUint16(0)!==65496){t(new Error("Not a valid jpeg"));return}const u=d.byteLength;let f=2,m=0,g;for(;f<u;){if(++m>250){t(new Error(`Found no marker after ${m} loops 😵`));return}if(d.getUint8(f)!==255){t(new Error(`Not a valid marker at offset 0x${f.toString(16)}, found: 0x${d.getUint8(f).toString(16)}`));return}if(g=d.getUint8(f+1),c&&console.log(`Marker: ${g.toString(16)}`),g===226){c&&console.log("Found APP2 marker (0xffe2)");const M=f+4;if(d.getUint32(M)===1297106432){const C=M+4;let E;if(d.getUint16(C)===18761)E=!1;else if(d.getUint16(C)===19789)E=!0;else{t(new Error("No valid endianness marker found in TIFF header"));return}if(d.getUint16(C+2,!E)!==42){t(new Error("Not valid TIFF data! (no 0x002A marker)"));return}const j=d.getUint32(C+4,!E);if(j<8){t(new Error("Not valid TIFF data! (First offset less than 8)"));return}const z=C+j,R=d.getUint16(z,!E),k=z+2;let H=0;for(let N=k;N<k+12*R;N+=12)d.getUint16(N,!E)===45057&&(H=d.getUint32(N+8,!E));const q=z+2+R*12+4,te=[];for(let N=q;N<q+H*16;N+=16){const O={MPType:d.getUint32(N,!E),size:d.getUint32(N+4,!E),dataOffset:d.getUint32(N+8,!E),dependantImages:d.getUint32(N+12,!E),start:-1,end:-1,isFII:!1};O.dataOffset?(O.start=C+O.dataOffset,O.isFII=!1):(O.start=0,O.isFII=!0),O.end=O.start+O.size,te.push(O)}if(this.options.extractNonFII&&te.length){const N=new Blob([d]),O=[];for(const re of te){if(re.isFII&&!this.options.extractFII)continue;const _=N.slice(re.start,re.end+1,"image/jpeg");O.push(_)}o(O)}}}f+=2+d.getUint16(f+2)}})}}const ma=async i=>{const r=pa(i);if(!r)throw new Xr("Gain map XMP metadata not found");const t=await new fa({extractFII:!0,extractNonFII:!0}).extract(i);if(t.length!==2)throw new Yr("Gain map recovery image not found");return{sdr:new Uint8Array(await t[0].arrayBuffer()),gainMap:new Uint8Array(await t[1].arrayBuffer()),metadata:r}},Rr=i=>new Promise((r,o)=>{const t=document.createElement("img");t.onload=()=>{r(t)},t.onerror=c=>{o(c)},t.src=URL.createObjectURL(i)});class $r extends wn{constructor(r,o){super(o),r&&(this._renderer=r),this._internalLoadingManager=new _n}setRenderer(r){return this._renderer=r,this}setRenderTargetOptions(r){return this._renderTargetOptions=r,this}prepareQuadRenderer(){this._renderer||console.warn("WARNING: An existing WebGL Renderer was not passed to this Loader constructor or in setRenderer, the result of this Loader will need to be converted to a Data Texture with toDataTexture() before you can use it in your renderer.");const r=new ha({gainMapMax:[1,1,1],gainMapMin:[0,0,0],gamma:[1,1,1],offsetHdr:[1,1,1],offsetSdr:[1,1,1],hdrCapacityMax:1,hdrCapacityMin:0,maxDisplayBoost:1,gainMap:new dt,sdr:new dt});return new pr({width:16,height:16,type:Ne,colorSpace:sr,material:r,renderer:this._renderer,renderTargetOptions:this._renderTargetOptions})}async render(r,o,t,c){const d=c?new Blob([c],{type:"image/jpeg"}):void 0,u=new Blob([t],{type:"image/jpeg"});let f,m,g=!1;if(typeof createImageBitmap>"u"){const E=await Promise.all([d?Rr(d):Promise.resolve(void 0),Rr(u)]);m=E[0],f=E[1],g=!0}else{const E=await Promise.all([d?createImageBitmap(d,{imageOrientation:"flipY"}):Promise.resolve(void 0),createImageBitmap(u,{imageOrientation:"flipY"})]);m=E[0],f=E[1]}const M=new dt(m||new ImageData(2,2),Yt,$e,$e,Ge,Sr,bt,lr,1,sr);M.flipY=g,M.needsUpdate=!0;const C=new dt(f,Yt,$e,$e,Ge,Sr,bt,lr,1,yn);C.flipY=g,C.needsUpdate=!0,r.width=f.width,r.height=f.height,r.material.gainMap=M,r.material.sdr=C,r.material.gainMapMin=o.gainMapMin,r.material.gainMapMax=o.gainMapMax,r.material.offsetHdr=o.offsetHdr,r.material.offsetSdr=o.offsetSdr,r.material.gamma=o.gamma,r.material.hdrCapacityMin=o.hdrCapacityMin,r.material.hdrCapacityMax=o.hdrCapacityMax,r.material.maxDisplayBoost=Math.pow(2,o.hdrCapacityMax),r.material.needsUpdate=!0,r.render()}}class va extends $r{load([r,o,t],c,d,u){const f=this.prepareQuadRenderer();let m,g,M;const C=async()=>{if(m&&g&&M){try{await this.render(f,M,m,g)}catch(A){this.manager.itemError(r),this.manager.itemError(o),this.manager.itemError(t),typeof u=="function"&&u(A),f.disposeOnDemandRenderer();return}typeof c=="function"&&c(f),this.manager.itemEnd(r),this.manager.itemEnd(o),this.manager.itemEnd(t),f.disposeOnDemandRenderer()}};let E=!0,j=0,z=0,R=!0,k=0,H=0,Y=!0,q=0,te=0;const N=()=>{if(typeof d=="function"){const A=j+k+q,F=z+H+te,Q=E&&R&&Y;d(new ProgressEvent("progress",{lengthComputable:Q,loaded:F,total:A}))}};this.manager.itemStart(r),this.manager.itemStart(o),this.manager.itemStart(t);const O=new Ht(this._internalLoadingManager);O.setResponseType("arraybuffer"),O.setRequestHeader(this.requestHeader),O.setPath(this.path),O.setWithCredentials(this.withCredentials),O.load(r,async A=>{if(typeof A=="string")throw new Error("Invalid sdr buffer");m=A,await C()},A=>{E=A.lengthComputable,z=A.loaded,j=A.total,N()},A=>{this.manager.itemError(r),typeof u=="function"&&u(A)});const re=new Ht(this._internalLoadingManager);re.setResponseType("arraybuffer"),re.setRequestHeader(this.requestHeader),re.setPath(this.path),re.setWithCredentials(this.withCredentials),re.load(o,async A=>{if(typeof A=="string")throw new Error("Invalid gainmap buffer");g=A,await C()},A=>{R=A.lengthComputable,H=A.loaded,k=A.total,N()},A=>{this.manager.itemError(o),typeof u=="function"&&u(A)});const _=new Ht(this._internalLoadingManager);return _.setRequestHeader(this.requestHeader),_.setPath(this.path),_.setWithCredentials(this.withCredentials),_.load(t,async A=>{if(typeof A!="string")throw new Error("Invalid metadata string");M=JSON.parse(A),await C()},A=>{Y=A.lengthComputable,te=A.loaded,q=A.total,N()},A=>{this.manager.itemError(t),typeof u=="function"&&u(A)}),f}}class ga extends $r{load(r,o,t,c){const d=this.prepareQuadRenderer(),u=new Ht(this._internalLoadingManager);return u.setResponseType("arraybuffer"),u.setRequestHeader(this.requestHeader),u.setPath(this.path),u.setWithCredentials(this.withCredentials),this.manager.itemStart(r),u.load(r,async f=>{if(typeof f=="string")throw new Error("Invalid buffer, received [string], was expecting [ArrayBuffer]");const m=new Uint8Array(f);let g,M,C;try{const E=await ma(m);g=E.sdr,M=E.gainMap,C=E.metadata}catch(E){if(E instanceof Xr||E instanceof Yr)console.warn(`Failure to reconstruct an HDR image from ${r}: Gain map metadata not found in the file, HDRJPGLoader will render the SDR jpeg`),C={gainMapMin:[0,0,0],gainMapMax:[1,1,1],gamma:[1,1,1],hdrCapacityMin:0,hdrCapacityMax:1,offsetHdr:[0,0,0],offsetSdr:[0,0,0]},g=m;else throw E}try{await this.render(d,C,g,M)}catch(E){this.manager.itemError(r),typeof c=="function"&&c(E),d.disposeOnDemandRenderer();return}typeof o=="function"&&o(d),this.manager.itemEnd(r),d.disposeOnDemandRenderer()},t,f=>{this.manager.itemError(r),typeof c=="function"&&c(f)}),d}}const St={apartment:"lebombo_1k.hdr",city:"potsdamer_platz_1k.hdr",dawn:"kiara_1_dawn_1k.hdr",forest:"forest_slope_1k.hdr",lobby:"st_fagans_interior_1k.hdr",night:"dikhololo_night_1k.hdr",park:"rooitou_park_1k.hdr",studio:"studio_small_03_1k.hdr",sunset:"venice_sunset_1k.hdr",warehouse:"empty_warehouse_01_1k.hdr"},Vr="https://raw.githack.com/pmndrs/drei-assets/456060a26bbeb8fdf79326f224b6d99b8bcce736/hdri/",ht=i=>Array.isArray(i),fr=["/px.png","/nx.png","/py.png","/ny.png","/pz.png","/nz.png"];function Vt({files:i=fr,path:r="",preset:o=void 0,colorSpace:t=void 0,extensions:c}={}){o&&(mr(o),i=St[o],r=Vr);const d=ht(i),{extension:u,isCubemap:f}=vr(i),m=gr(u);if(!m)throw new Error("useEnvironment: Unrecognized file extension: "+i);const g=Ae(j=>j.gl);U.useLayoutEffect(()=>{if(u!=="webp"&&u!=="jpg"&&u!=="jpeg")return;function j(){Mt.clear(m,d?[i]:i)}g.domElement.addEventListener("webglcontextlost",j,{once:!0})},[i,g.domElement]);const M=Mt(m,d?[i]:i,j=>{(u==="webp"||u==="jpg"||u==="jpeg")&&j.setRenderer(g),j.setPath==null||j.setPath(r),c&&c(j)});let C=d?M[0]:M;if(u==="jpg"||u==="jpeg"||u==="webp"){var E;C=(E=C.renderTarget)==null?void 0:E.texture}return C.mapping=f?bn:Mn,C.colorSpace=t??(f?"srgb":"srgb-linear"),C}const wa={files:fr,path:"",preset:void 0,extensions:void 0};Vt.preload=i=>{const r={...wa,...i};let{files:o,path:t=""}=r;const{preset:c,extensions:d}=r;c&&(mr(c),o=St[c],t=Vr);const{extension:u}=vr(o);if(u==="webp"||u==="jpg"||u==="jpeg")throw new Error("useEnvironment: Preloading gainmaps is not supported");const f=gr(u);if(!f)throw new Error("useEnvironment: Unrecognized file extension: "+o);Mt.preload(f,ht(o)?[o]:o,m=>{m.setPath==null||m.setPath(t),d&&d(m)})};const _a={files:fr,preset:void 0};Vt.clear=i=>{const r={..._a,...i};let{files:o}=r;const{preset:t}=r;t&&(mr(t),o=St[t]);const{extension:c}=vr(o),d=gr(c);if(!d)throw new Error("useEnvironment: Unrecognized file extension: "+o);Mt.clear(d,ht(o)?[o]:o)};function mr(i){if(!(i in St))throw new Error("Preset must be one of: "+Object.keys(St).join(", "))}function vr(i){var r;const o=ht(i)&&i.length===6,t=ht(i)&&i.length===3&&i.some(u=>u.endsWith("json")),c=ht(i)?i[0]:i;return{extension:o?"cube":t?"webp":c.startsWith("data:application/exr")?"exr":c.startsWith("data:application/hdr")?"hdr":c.startsWith("data:image/jpeg")?"jpg":(r=c.split(".").pop())==null||(r=r.split("?"))==null||(r=r.shift())==null?void 0:r.toLowerCase(),isCubemap:o,isGainmap:t}}function gr(i){return i==="cube"?Sn:i==="hdr"?ta:i==="exr"?ra:i==="jpg"||i==="jpeg"?ga:i==="webp"?va:null}const ya=i=>i.current&&i.current.isScene,Ea=i=>ya(i)?i.current:i;function wr(i,r,o,t,c={}){var d,u,f,m;c={backgroundBlurriness:0,backgroundIntensity:1,backgroundRotation:[0,0,0],environmentIntensity:1,environmentRotation:[0,0,0],...c};const g=Ea(r||o),M=g.background,C=g.environment,E={backgroundBlurriness:g.backgroundBlurriness,backgroundIntensity:g.backgroundIntensity,backgroundRotation:(d=(u=g.backgroundRotation)==null||u.clone==null?void 0:u.clone())!==null&&d!==void 0?d:[0,0,0],environmentIntensity:g.environmentIntensity,environmentRotation:(f=(m=g.environmentRotation)==null||m.clone==null?void 0:m.clone())!==null&&f!==void 0?f:[0,0,0]};return i!=="only"&&(g.environment=t),i&&(g.background=t),xr(g,c),()=>{i!=="only"&&(g.environment=C),i&&(g.background=M),xr(g,E)}}function _r({scene:i,background:r=!1,map:o,...t}){const c=Ae(d=>d.scene);return U.useLayoutEffect(()=>{if(o)return wr(r,i,c,o,t)}),null}function Kr({background:i=!1,scene:r,blur:o,backgroundBlurriness:t,backgroundIntensity:c,backgroundRotation:d,environmentIntensity:u,environmentRotation:f,...m}){const g=Vt(m),M=Ae(C=>C.scene);return U.useLayoutEffect(()=>wr(i,r,M,g,{backgroundBlurriness:o??t,backgroundIntensity:c,backgroundRotation:d,environmentIntensity:u,environmentRotation:f})),U.useEffect(()=>()=>{g.dispose()},[g]),null}function ba({children:i,near:r=.1,far:o=1e3,resolution:t=256,frames:c=1,map:d,background:u=!1,blur:f,backgroundBlurriness:m,backgroundIntensity:g,backgroundRotation:M,environmentIntensity:C,environmentRotation:E,scene:j,files:z,path:R,preset:k=void 0,extensions:H}){const Y=Ae(_=>_.gl),q=Ae(_=>_.scene),te=U.useRef(null),[N]=U.useState(()=>new kr),O=U.useMemo(()=>{const _=new xn(t);return _.texture.type=Ne,_},[t]);U.useEffect(()=>()=>{O.dispose()},[O]),U.useLayoutEffect(()=>{if(c===1){const _=Y.autoClear;Y.autoClear=!0,te.current.update(Y,N),Y.autoClear=_}return wr(u,j,q,O.texture,{backgroundBlurriness:f??m,backgroundIntensity:g,backgroundRotation:M,environmentIntensity:C,environmentRotation:E})},[i,N,O.texture,j,q,u,c,Y]);let re=1;return hr(()=>{if(c===1/0||re<c){const _=Y.autoClear;Y.autoClear=!0,te.current.update(Y,N),Y.autoClear=_,re++}}),U.createElement(U.Fragment,null,Tn(U.createElement(U.Fragment,null,i,U.createElement("cubeCamera",{ref:te,args:[r,o,O]}),z||k?U.createElement(Kr,{background:!0,files:z,preset:k,path:R,extensions:H}):d?U.createElement(_r,{background:!0,map:d,extensions:H}):null),N))}function Ma(i){var r,o,t,c;const d=Vt(i),u=i.map||d;U.useMemo(()=>Dr({GroundProjectedEnvImpl:Yn}),[]),U.useEffect(()=>()=>{d.dispose()},[d]);const f=U.useMemo(()=>[u],[u]),m=(r=i.ground)==null?void 0:r.height,g=(o=i.ground)==null?void 0:o.radius,M=(t=(c=i.ground)==null?void 0:c.scale)!==null&&t!==void 0?t:1e3;return U.createElement(U.Fragment,null,U.createElement(_r,Zt({},i,{map:u})),U.createElement("groundProjectedEnvImpl",{args:f,scale:M,height:m,radius:g}))}function Sa(i){return i.ground?U.createElement(Ma,i):i.map?U.createElement(_r,i):i.children?U.createElement(ba,i):U.createElement(Kr,i)}const xa="/Users/khalidgarner/Dev/zentara-platform",Ta=`${xa}/ShipStlObjFile/USC_OBJ`,Gt=[{name:"AstroEagle",prefix:"AstroEagle",count:20,pad:2,modules:"AstroEagleModules.obj"},{name:"CosmicShark",prefix:"CosmicShark",count:20,pad:2,modules:"CosmicSharkModules.obj"},{name:"CraizanStar",prefix:"CraizanStar",count:20,pad:2},{name:"FlyingInsects",prefix:"FlyingInsect",count:5,pad:2},{name:"ForceBadger",prefix:"ForceBadger",count:20,pad:2,modules:"ForceBadgerModules.obj"},{name:"GalacticLeopard",prefix:"GalacticLeopard",count:20,pad:2,modules:"GalacticLeopardModules.obj"},{name:"GalaxyRaptor",prefix:"GalaxyRaptor",count:20,pad:2,modules:"GalaxyRaptorModules.obj"},{name:"GenericSpaceships",prefix:"GenericSpaceships",count:8,pad:2},{name:"HyperFalcon",prefix:"HyperFalcon",count:20,pad:2,modules:"HyperFalconModules.obj"},{name:"LightFox",prefix:"LightFox",count:20,pad:2,modules:"LightFoxModules.obj"},{name:"MeteorMantis",prefix:"MeteorMantis",count:20,pad:2,modules:"MeteorMantisModules.obj"},{name:"NightAye",prefix:"NightAye",count:20,pad:2,modules:"NightAyeModules.obj"},{name:"ProtonLegacy",prefix:"ProtonLegacy",count:20,pad:2,modules:"ProtonLegacyModules.obj"},{name:"SpaceExcalibur",prefix:"SpaceExcalibur",count:20,pad:2,modules:"SpaceExcaliburModules.obj"},{name:"SpaceSphinx",prefix:"SpaceSphinx",count:8,pad:2,modules:"SpaceSphinxModules.obj"},{name:"StarSparrow",prefix:"StarSparrow",count:20,pad:2,modules:"StarSparrowModules.obj"},{name:"StriderOx",prefix:"StriderOx",count:20,pad:2,modules:"StriderOxModules.obj"},{name:"VoidWhale",prefix:"VoidWhale",count:9,pad:2,modules:"VoidWhaleModules.obj"}];function Or(i,r){return`/@fs/${Ta}/${i}/${r}`}function dr(i){const r=Array.from({length:i.count},(o,t)=>{const c=String(t+1).padStart(i.pad??2,"0"),d=`${i.prefix}${c}.obj`;return{pack:i.name,name:d.replace(/\.obj$/i,""),file:d,url:Or(i.name,d)}});return i.modules&&r.push({pack:i.name,name:i.modules.replace(/\.obj$/i,""),file:i.modules,url:Or(i.name,i.modules)}),r}const jt=Gt.flatMap(dr),Ia=4.2;function Ca({model:i,color:r,wireframe:o}){const t=Mt(An,i.url),c=U.useMemo(()=>{const d=t.clone(!0),u=new Rn,f=new Wt(r),m=f.clone().lerp(new Wt("#ffffff"),.22);let g=0;if(d.traverse(k=>{const H=k;H.isMesh&&(g++,H.castShadow=!0,H.receiveShadow=!0,H.geometry&&(H.geometry.computeBoundingBox(),H.geometry.computeBoundingSphere(),H.geometry.computeVertexNormals()),H.material=new Tr({color:f,emissive:m,emissiveIntensity:.08,metalness:.7,roughness:.38,wireframe:o}))}),g===0){const k=new Xt(new On(1,1,1),new Tr({color:f,wireframe:o}));return u.add(k),u}d.updateMatrixWorld(!0);const M=new Ir().setFromObject(d),C=M.getCenter(new ve),E=M.getSize(new ve),j=Math.max(E.x,E.y,E.z),z=Number.isFinite(j)&&j>0?Ia/j:1;d.position.sub(C),u.add(d),u.scale.setScalar(z),u.updateMatrixWorld(!0);const R=new Ir().setFromObject(u);return u.position.y-=R.min.y,u},[t,r,o]);return V.jsx("primitive",{object:c},i.url)}function Aa(i){return V.jsxs(In,{className:"ship-pack-preview__canvas",camera:{position:[0,4.5,9],fov:42,near:.01,far:5e3},gl:{antialias:!0,toneMapping:Cn},shadows:!0,children:[V.jsx("color",{attach:"background",args:[329485]}),V.jsx("fog",{attach:"fog",args:[329485,80,260]}),V.jsx("ambientLight",{intensity:.42}),V.jsx("directionalLight",{position:[6,10,6],intensity:2.2,castShadow:!0}),V.jsx("directionalLight",{position:[-7,4,-8],intensity:.65,color:9353471}),V.jsx("pointLight",{position:[0,-2,-3],intensity:1.2,color:i.color,distance:16}),V.jsxs(U.Suspense,{fallback:null,children:[V.jsx(Ca,{model:i.model,color:i.color,wireframe:i.wireframe}),V.jsx(Sa,{preset:"city"})]}),V.jsx(la,{args:[80,80],cellSize:1,cellThickness:.4,cellColor:2504786,sectionSize:5,sectionThickness:1,sectionColor:4284808,fadeDistance:80,fadeStrength:1.4,infiniteGrid:!0,position:[0,-1.2,0]}),V.jsx(oa,{makeDefault:!0,enableDamping:!0,dampingFactor:.08,autoRotate:i.autoRotate,autoRotateSpeed:.85,target:[0,1.7,0],minDistance:3,maxDistance:28})]})}function Fa(){const[i,r]=U.useState(Gt[0].name),[o,t]=U.useState(dr(Gt[0])[0].name),[c,d]=U.useState(""),[u,f]=U.useState("#33ccff"),[m,g]=U.useState(!1),[M,C]=U.useState(!0),E=U.useMemo(()=>jt.filter(R=>R.pack===i),[i]),j=U.useMemo(()=>{const R=c.trim().toLowerCase();return R?E.filter(k=>k.name.toLowerCase().includes(R)):E},[E,c]),z=U.useMemo(()=>E.find(R=>R.name===o)??E[0]??jt[0],[o,E]);return U.useEffect(()=>{const R=E[0];R&&!E.some(k=>k.name===o)&&t(R.name)},[o,E]),U.useEffect(()=>{const R=document.body.style.background;return document.body.style.background="#05070d",()=>{document.body.style.background=R}},[]),V.jsxs("main",{className:"ship-pack-preview",children:[V.jsx(U.Suspense,{fallback:V.jsx("div",{className:"ship-pack-preview__loading",children:"Loading ship..."}),children:V.jsx(Aa,{model:z,color:u,wireframe:m,autoRotate:M},z.url)}),V.jsxs("aside",{className:"ship-pack-preview__panel",children:[V.jsxs("header",{className:"ship-pack-preview__header",children:[V.jsx("h1",{className:"ship-pack-preview__title",children:"Ship Pack Preview"}),V.jsxs("div",{className:"ship-pack-preview__meta",children:[jt.length," OBJ models from ShipStlObjFile/USC_OBJ"]})]}),V.jsxs("div",{className:"ship-pack-preview__controls",children:[V.jsxs("label",{className:"ship-pack-preview__label",children:["Pack",V.jsx("select",{className:"ship-pack-preview__select",value:i,onChange:R=>{var H;const k=R.target.value;r(k),d(""),t(((H=jt.find(Y=>Y.pack===k))==null?void 0:H.name)??o)},children:Gt.map(R=>V.jsxs("option",{value:R.name,children:[R.name," (",dr(R).length,")"]},R.name))})]}),V.jsxs("label",{className:"ship-pack-preview__label",children:["Search Models",V.jsx("input",{className:"ship-pack-preview__search",value:c,onChange:R=>d(R.target.value),placeholder:"Filter current pack"})]}),V.jsx("div",{className:"ship-pack-preview__grid",children:j.map(R=>V.jsx("button",{type:"button",className:`ship-pack-preview__model-button${R.name===z.name?" ship-pack-preview__model-button--active":""}`,onClick:()=>t(R.name),title:R.file,children:R.name.replace(R.pack,"")||R.name},R.name))}),V.jsxs("label",{className:"ship-pack-preview__row",children:[V.jsx("input",{type:"color",value:u,onChange:R=>f(R.target.value)}),"Tint"]}),V.jsxs("label",{className:"ship-pack-preview__row",children:[V.jsx("input",{type:"checkbox",checked:m,onChange:R=>g(R.target.checked)}),"Wireframe"]}),V.jsxs("label",{className:"ship-pack-preview__row",children:[V.jsx("input",{type:"checkbox",checked:M,onChange:R=>C(R.target.checked)}),"Auto-rotate"]})]})]}),V.jsx("div",{className:"ship-pack-preview__path",children:z.url})]})}export{Fa as default};
