ocearo-ui
Version:
Ocean Robot UI: Sailing made smarter
114 lines (101 loc) • 150 kB
JavaScript
"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[226],{5550:function(e,t,r){let n;r.d(t,{qA:function(){return eJ}});var a=r(1119),i=r(2265),s=r(21276),o=r(72079),l=r(49074);let A=e=>e&&e.isCubeTexture;class c extends o.Kj0{constructor(e,t){var r,n;let a=A(e),i=Math.floor(Math.log2((null!=(n=a?null==(r=e.image[0])?void 0:r.width:e.image.width)?n:1024)/4)),s=Math.pow(2,i),c=`
varying vec3 vWorldPosition;
void main()
{
vec4 worldPosition = ( modelMatrix * vec4( position, 1.0 ) );
vWorldPosition = worldPosition.xyz;
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
}
`,u=[a?"#define ENVMAP_TYPE_CUBE":"",`#define CUBEUV_TEXEL_WIDTH ${1/(3*Math.max(s,112))}`,`#define CUBEUV_TEXEL_HEIGHT ${1/(4*s)}`,`#define CUBEUV_MAX_MIP ${i}.0`].join("\n")+`
#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 <${l.i>=154?"colorspace_fragment":"encodings_fragment"}>
}
`;super(new o.cJO(1,16),new o.jyz({uniforms:{map:{value:e},height:{value:(null==t?void 0:t.height)||15},radius:{value:(null==t?void 0:t.radius)||100}},fragmentShader:u,vertexShader:c,side:o.ehD}))}set radius(e){this.material.uniforms.radius.value=e}get radius(){return this.material.uniforms.radius.value}set height(e){this.material.uniforms.height.value=e}get height(){return this.material.uniforms.height.value}}class u extends o.yxD{constructor(e){super(e),this.type=o.cLu}parse(e){let t,r,n;let a=function(e,t){switch(e){case 1:throw Error("THREE.RGBELoader: Read Error: "+(t||""));case 2:throw Error("THREE.RGBELoader: Write Error: "+(t||""));case 3:throw Error("THREE.RGBELoader: Bad File Format: "+(t||""));default:throw Error("THREE.RGBELoader: Memory Error: "+(t||""))}},i=function(e,t,r){t=t||1024;let n=e.pos,a=-1,i=0,s="",o=String.fromCharCode.apply(null,new Uint16Array(e.subarray(n,n+128)));for(;0>(a=o.indexOf("\n"))&&i<t&&n<e.byteLength;)s+=o,i+=o.length,n+=128,o+=String.fromCharCode.apply(null,new Uint16Array(e.subarray(n,n+128)));return -1<a&&(!1!==r&&(e.pos+=i+a+1),s+o.slice(0,a))},s=new Uint8Array(e);s.pos=0;let l=function(e){let t,r;let n=/^\s*GAMMA\s*=\s*(\d+(\.\d+)?)\s*$/,s=/^\s*EXPOSURE\s*=\s*(\d+(\.\d+)?)\s*$/,o=/^\s*FORMAT=(\S+)\s*$/,l=/^\s*\-Y\s+(\d+)\s+\+X\s+(\d+)\s*$/,A={valid:0,string:"",comments:"",programtype:"RGBE",format:"",gamma:1,exposure:1,width:0,height:0};for(!(e.pos>=e.byteLength)&&(t=i(e))||a(1,"no header found"),(r=t.match(/^#\?(\S+)/))||a(3,"bad initial token"),A.valid|=1,A.programtype=r[1],A.string+=t+"\n";!1!==(t=i(e));){if(A.string+=t+"\n","#"===t.charAt(0)){A.comments+=t+"\n";continue}if((r=t.match(n))&&(A.gamma=parseFloat(r[1])),(r=t.match(s))&&(A.exposure=parseFloat(r[1])),(r=t.match(o))&&(A.valid|=2,A.format=r[1]),(r=t.match(l))&&(A.valid|=4,A.height=parseInt(r[1],10),A.width=parseInt(r[2],10)),2&A.valid&&4&A.valid)break}return 2&A.valid||a(3,"missing format specifier"),4&A.valid||a(3,"missing image size specifier"),A}(s),A=l.width,c=l.height,u=function(e,t,r){if(t<8||t>32767||2!==e[0]||2!==e[1]||128&e[2])return new Uint8Array(e);t!==(e[2]<<8|e[3])&&a(3,"wrong scanline width");let n=new Uint8Array(4*t*r);n.length||a(4,"unable to allocate buffer space");let i=0,s=0,o=4*t,l=new Uint8Array(4),A=new Uint8Array(o),c=r;for(;c>0&&s<e.byteLength;){s+4>e.byteLength&&a(1),l[0]=e[s++],l[1]=e[s++],l[2]=e[s++],l[3]=e[s++],(2!=l[0]||2!=l[1]||(l[2]<<8|l[3])!=t)&&a(3,"bad rgbe scanline format");let r=0,u;for(;r<o&&s<e.byteLength;){let t=(u=e[s++])>128;if(t&&(u-=128),(0===u||r+u>o)&&a(3,"bad scanline data"),t){let t=e[s++];for(let e=0;e<u;e++)A[r++]=t}else A.set(e.subarray(s,s+u),r),r+=u,s+=u}for(let e=0;e<t;e++){let r=0;n[i]=A[e+r],r+=t,n[i+1]=A[e+r],r+=t,n[i+2]=A[e+r],r+=t,n[i+3]=A[e+r],i+=4}c--}return n}(s.subarray(s.pos),A,c);switch(this.type){case o.VzW:let d=new Float32Array(4*(n=u.length/4));for(let e=0;e<n;e++)!function(e,t,r,n){let a=Math.pow(2,e[t+3]-128)/255;r[n+0]=e[t+0]*a,r[n+1]=e[t+1]*a,r[n+2]=e[t+2]*a,r[n+3]=1}(u,4*e,d,4*e);t=d,r=o.VzW;break;case o.cLu:let h=new Uint16Array(4*(n=u.length/4));for(let e=0;e<n;e++)!function(e,t,r,n){let a=Math.pow(2,e[t+3]-128)/255;r[n+0]=o.A5E.toHalfFloat(Math.min(e[t+0]*a,65504)),r[n+1]=o.A5E.toHalfFloat(Math.min(e[t+1]*a,65504)),r[n+2]=o.A5E.toHalfFloat(Math.min(e[t+2]*a,65504)),r[n+3]=o.A5E.toHalfFloat(1)}(u,4*e,h,4*e);t=h,r=o.cLu;break;default:throw Error("THREE.RGBELoader: Unsupported type: "+this.type)}return{width:A,height:c,data:t,header:l.string,gamma:l.gamma,exposure:l.exposure,type:r}}setDataType(e){return this.type=e,this}load(e,t,r,n){return super.load(e,function(e,r){switch(e.type){case o.VzW:case o.cLu:"colorSpace"in e?e.colorSpace="srgb-linear":e.encoding=3e3,e.minFilter=o.wem,e.magFilter=o.wem,e.generateMipmaps=!1,e.flipY=!0}t&&t(e,r)},r,n)}}var d={},h=Uint8Array,B=Uint16Array,f=Uint32Array,m=new h([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]),p=new h([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]),C=new h([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),g=function(e,t){for(var r=new B(31),n=0;n<31;++n)r[n]=t+=1<<e[n-1];for(var a=new f(r[30]),n=1;n<30;++n)for(var i=r[n];i<r[n+1];++i)a[i]=i-r[n]<<5|n;return[r,a]},E=g(m,2),M=E[0],v=E[1];M[28]=258,v[258]=28;for(var F=g(p,0),b=F[0],I=F[1],y=new B(32768),R=0;R<32768;++R){var G=(43690&R)>>>1|(21845&R)<<1;G=(61680&(G=(52428&G)>>>2|(13107&G)<<2))>>>4|(3855&G)<<4,y[R]=((65280&G)>>>8|(255&G)<<8)>>>1}for(var D=function(e,t,r){for(var n,a=e.length,i=0,s=new B(t);i<a;++i)++s[e[i]-1];var o=new B(t);for(i=0;i<t;++i)o[i]=o[i-1]+s[i-1]<<1;if(r){n=new B(1<<t);var l=15-t;for(i=0;i<a;++i)if(e[i])for(var A=i<<4|e[i],c=t-e[i],u=o[e[i]-1]++<<c,d=u|(1<<c)-1;u<=d;++u)n[y[u]>>>l]=A}else for(i=0,n=new B(a);i<a;++i)e[i]&&(n[i]=y[o[e[i]-1]++]>>>15-e[i]);return n},w=new h(288),R=0;R<144;++R)w[R]=8;for(var R=144;R<256;++R)w[R]=9;for(var R=256;R<280;++R)w[R]=7;for(var R=280;R<288;++R)w[R]=8;for(var T=new h(32),R=0;R<32;++R)T[R]=5;var H=D(w,9,1),x=D(T,5,1),P=function(e){for(var t=e[0],r=1;r<e.length;++r)e[r]>t&&(t=e[r]);return t},J=function(e,t,r){var n=t/8|0;return(e[n]|e[n+1]<<8)>>(7&t)&r},O=function(e,t){var r=t/8|0;return(e[r]|e[r+1]<<8|e[r+2]<<16)>>(7&t)},L=function(e){return(e/8|0)+(7&e&&1)},S=function(e,t,r){(null==t||t<0)&&(t=0),(null==r||r>e.length)&&(r=e.length);var n=new(e instanceof B?B:e instanceof f?f:h)(r-t);return n.set(e.subarray(t,r)),n},U=function(e,t,r){var n=e.length;if(!n||r&&!r.l&&n<5)return t||new h(0);var a=!t||r,i=!r||r.i;r||(r={}),t||(t=new h(3*n));var s=function(e){var r=t.length;if(e>r){var n=new h(Math.max(2*r,e));n.set(t),t=n}},o=r.f||0,l=r.p||0,A=r.b||0,c=r.l,u=r.d,d=r.m,B=r.n,f=8*n;do{if(!c){r.f=o=J(e,l,1);var g=J(e,l+1,3);if(l+=3,g){if(1==g)c=H,u=x,d=9,B=5;else if(2==g){var E=J(e,l,31)+257,v=J(e,l+10,15)+4,F=E+J(e,l+5,31)+1;l+=14;for(var I=new h(F),y=new h(19),R=0;R<v;++R)y[C[R]]=J(e,l+3*R,7);l+=3*v;for(var G=P(y),w=(1<<G)-1,T=D(y,G,1),R=0;R<F;){var U=T[J(e,l,w)];l+=15&U;var _=U>>>4;if(_<16)I[R++]=_;else{var K=0,N=0;for(16==_?(N=3+J(e,l,3),l+=2,K=I[R-1]):17==_?(N=3+J(e,l,7),l+=3):18==_&&(N=11+J(e,l,127),l+=7);N--;)I[R++]=K}}var k=I.subarray(0,E),Q=I.subarray(E);d=P(k),B=P(Q),c=D(k,d,1),u=D(Q,B,1)}else throw"invalid block type"}else{var _=L(l)+4,j=e[_-4]|e[_-3]<<8,X=_+j;if(X>n){if(i)throw"unexpected EOF";break}a&&s(A+j),t.set(e.subarray(_,X),A),r.b=A+=j,r.p=l=8*X;continue}if(l>f){if(i)throw"unexpected EOF";break}}a&&s(A+131072);for(var Y=(1<<d)-1,W=(1<<B)-1,Z=l;;Z=l){var K=c[O(e,l)&Y],z=K>>>4;if((l+=15&K)>f){if(i)throw"unexpected EOF";break}if(!K)throw"invalid length/literal";if(z<256)t[A++]=z;else if(256==z){Z=l,c=null;break}else{var V=z-254;if(z>264){var R=z-257,q=m[R];V=J(e,l,(1<<q)-1)+M[R],l+=q}var $=u[O(e,l)&W],ee=$>>>4;if(!$)throw"invalid distance";l+=15&$;var Q=b[ee];if(ee>3){var q=p[ee];Q+=O(e,l)&(1<<q)-1,l+=q}if(l>f){if(i)throw"unexpected EOF";break}a&&s(A+131072);for(var et=A+V;A<et;A+=4)t[A]=t[A-Q],t[A+1]=t[A+1-Q],t[A+2]=t[A+2-Q],t[A+3]=t[A+3-Q];A=et}}r.l=c,r.p=Z,r.b=A,c&&(o=1,r.m=d,r.d=u,r.n=B)}while(!o);return A==t.length?t:S(t,0,A)},_=function(e,t,r){r<<=7&t;var n=t/8|0;e[n]|=r,e[n+1]|=r>>>8},K=function(e,t,r){r<<=7&t;var n=t/8|0;e[n]|=r,e[n+1]|=r>>>8,e[n+2]|=r>>>16},N=function(e,t){for(var r=[],n=0;n<e.length;++n)e[n]&&r.push({s:n,f:e[n]});var a=r.length,i=r.slice();if(!a)return[Z,0];if(1==a){var s=new h(r[0].s+1);return s[r[0].s]=1,[s,1]}r.sort(function(e,t){return e.f-t.f}),r.push({s:-1,f:25001});var o=r[0],l=r[1],A=0,c=1,u=2;for(r[0]={s:-1,f:o.f+l.f,l:o,r:l};c!=a-1;)o=r[r[A].f<r[u].f?A++:u++],l=r[A!=c&&r[A].f<r[u].f?A++:u++],r[c++]={s:-1,f:o.f+l.f,l:o,r:l};for(var d=i[0].s,n=1;n<a;++n)i[n].s>d&&(d=i[n].s);var f=new B(d+1),m=k(r[c-1],f,0);if(m>t){var n=0,p=0,C=m-t,g=1<<C;for(i.sort(function(e,t){return f[t.s]-f[e.s]||e.f-t.f});n<a;++n){var E=i[n].s;if(f[E]>t)p+=g-(1<<m-f[E]),f[E]=t;else break}for(p>>>=C;p>0;){var M=i[n].s;f[M]<t?p-=1<<t-f[M]++-1:++n}for(;n>=0&&p;--n){var v=i[n].s;f[v]==t&&(--f[v],++p)}m=t}return[new h(f),m]},k=function(e,t,r){return -1==e.s?Math.max(k(e.l,t,r+1),k(e.r,t,r+1)):t[e.s]=r},Q=function(e){for(var t=e.length;t&&!e[--t];);for(var r=new B(++t),n=0,a=e[0],i=1,s=function(e){r[n++]=e},o=1;o<=t;++o)if(e[o]==a&&o!=t)++i;else{if(!a&&i>2){for(;i>138;i-=138)s(32754);i>2&&(s(i>10?i-11<<5|28690:i-3<<5|12305),i=0)}else if(i>3){for(s(a),--i;i>6;i-=6)s(8304);i>2&&(s(i-3<<5|8208),i=0)}for(;i--;)s(a);i=1,a=e[o]}return[r.subarray(0,n),t]},j=function(e,t){for(var r=0,n=0;n<t.length;++n)r+=e[n]*t[n];return r},X=function(e,t,r){var n=r.length,a=L(t+2);e[a]=255&n,e[a+1]=n>>>8,e[a+2]=255^e[a],e[a+3]=255^e[a+1];for(var i=0;i<n;++i)e[a+i+4]=r[i];return(a+4+n)*8},Y=function(e,t,r,n,a,i,s,o,l,A,c){_(t,c++,r),++a[256];for(var u,d,h,f,g=N(a,15),E=g[0],M=g[1],v=N(i,15),F=v[0],b=v[1],I=Q(E),y=I[0],R=I[1],G=Q(F),H=G[0],x=G[1],P=new B(19),J=0;J<y.length;++J)P[31&y[J]]++;for(var J=0;J<H.length;++J)P[31&H[J]]++;for(var O=N(P,7),L=O[0],S=O[1],U=19;U>4&&!L[C[U-1]];--U);var k=A+5<<3,Y=j(a,w)+j(i,T)+s,W=j(a,E)+j(i,F)+s+14+3*U+j(P,L)+(2*P[16]+3*P[17]+7*P[18]);if(k<=Y&&k<=W)return X(t,c,e.subarray(l,l+A));if(_(t,c,1+(W<Y)),c+=2,W<Y){u=D(E,M,0),d=E,h=D(F,b,0),f=F;var Z=D(L,S,0);_(t,c,R-257),_(t,c+5,x-1),_(t,c+10,U-4),c+=14;for(var J=0;J<U;++J)_(t,c+3*J,L[C[J]]);c+=3*U;for(var z=[y,H],V=0;V<2;++V)for(var q=z[V],J=0;J<q.length;++J){var $=31&q[J];_(t,c,Z[$]),c+=L[$],$>15&&(_(t,c,q[J]>>>5&127),c+=q[J]>>>12)}}else u=null,d=w,h=null,f=T;for(var J=0;J<o;++J)if(n[J]>255){var $=n[J]>>>18&31;K(t,c,u[$+257]),c+=d[$+257],$>7&&(_(t,c,n[J]>>>23&31),c+=m[$]);var ee=31&n[J];K(t,c,h[ee]),c+=f[ee],ee>3&&(K(t,c,n[J]>>>5&8191),c+=p[ee])}else K(t,c,u[n[J]]),c+=d[n[J]];return K(t,c,u[256]),c+d[256]},W=new f([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),Z=new h(0),z=function(e){if((15&e[0])!=8||e[0]>>>4>7||(e[0]<<8|e[1])%31)throw"invalid zlib data";if(32&e[1])throw"invalid zlib data: preset dictionaries not supported"};function V(e,t){return U((z(e),e.subarray(2,-4)),t)}var q="undefined"!=typeof TextDecoder&&new TextDecoder;try{q.decode(Z,{stream:!0})}catch(e){}let $=l.i>=152;class ee extends o.yxD{constructor(e){super(e),this.type=o.cLu}parse(e){let t={l:0,c:0,lc:0};function r(e,r,n,a,i){for(;n<e;)r=r<<8|y(a,i),n+=8;n-=e,t.l=r>>n&(1<<e)-1,t.c=r,t.lc=n}let n=Array(59),a={c:0,lc:0};function i(e,t,r,n){e=e<<8|y(r,n),t+=8,a.c=e,a.lc=t}let s={c:0,lc:0};function l(e,t,r,n,o,l,A,c,u,d){if(e==t){n<8&&(i(r,n,o,A),r=a.c,n=a.lc);var h=r>>(n-=8),h=new Uint8Array([h])[0];if(u.value+h>d)return!1;for(var B=c[u.value-1];h-- >0;)c[u.value++]=B}else{if(!(u.value<d))return!1;c[u.value++]=e}s.c=r,s.lc=n}function A(e){var t=65535&e;return t>32767?t-65536:t}let c={a:0,b:0};function u(e,t){var r=A(e),n=A(t),a=r+(1&n)+(n>>1),i=a-n;c.a=a,c.b=i}function d(e,t){var r=65535&t,n=(65535&e)-(r>>1)&65535;c.a=r+n-32768&65535,c.b=n}function h(e,o,A,c,u,d){var h=A.value,B=I(o,A),f=I(o,A);A.value+=4;var m=I(o,A);if(A.value+=4,B<0||B>=65537||f<0||f>=65537)throw"Something wrong with HUF_ENCSIZE";var p=Array(65537),C=Array(16384);!function(e){for(var t=0;t<16384;t++)e[t]={},e[t].len=0,e[t].lit=0,e[t].p=null}(C);var g=c-(A.value-h);if(!function(e,a,i,s,o,l,A){for(var c=0,u=0;o<=l;o++){if(i.value-i.value>s)return!1;r(6,c,u,e,i);var d=t.l;if(c=t.c,u=t.lc,A[o]=d,63==d){if(i.value-i.value>s)throw"Something wrong with hufUnpackEncTable";r(8,c,u,e,i);var h=t.l+6;if(c=t.c,u=t.lc,o+h>l+1)throw"Something wrong with hufUnpackEncTable";for(;h--;)A[o++]=0;o--}else if(d>=59){var h=d-59+2;if(o+h>l+1)throw"Something wrong with hufUnpackEncTable";for(;h--;)A[o++]=0;o--}}!function(e){for(var t=0;t<=58;++t)n[t]=0;for(var t=0;t<65537;++t)n[e[t]]+=1;for(var r=0,t=58;t>0;--t){var a=r+n[t]>>1;n[t]=r,r=a}for(var t=0;t<65537;++t){var i=e[t];i>0&&(e[t]=i|n[i]++<<6)}}(A)}(e,0,A,g,B,f,p),m>8*(c-(A.value-h)))throw"Something wrong with hufUncompress";!function(e,t,r,n){for(;t<=r;t++){var a=e[t]>>6,i=63&e[t];if(a>>i)throw"Invalid table entry";if(i>14){var s=n[a>>i-14];if(s.len)throw"Invalid table entry";if(s.lit++,s.p){var o=s.p;s.p=Array(s.lit);for(var l=0;l<s.lit-1;++l)s.p[l]=o[l]}else s.p=[,];s.p[s.lit-1]=t}else if(i)for(var A=0,l=1<<14-i;l>0;l--){var s=n[(a<<14-i)+A];if(s.len||s.p)throw"Invalid table entry";s.len=i,s.lit=t,A++}}}(p,B,f,C),function(e,t,r,n,o,A,c,u,d,h){for(var B=0,f=0,m=Math.trunc(o.value+(A+7)/8);o.value<m;)for(i(B,f,r,o),B=a.c,f=a.lc;f>=14;){var p=t[B>>f-14&16383];if(p.len)f-=p.len,l(p.lit,c,B,f,r,n,o,d,h,u),B=s.c,f=s.lc;else{if(!p.p)throw"hufDecode issues";for(C=0;C<p.lit;C++){for(var C,g=63&e[p.p[C]];f<g&&o.value<m;)i(B,f,r,o),B=a.c,f=a.lc;if(f>=g&&e[p.p[C]]>>6==(B>>f-g&(1<<g)-1)){f-=g,l(p.p[C],c,B,f,r,n,o,d,h,u),B=s.c,f=s.lc;break}}if(C==p.lit)throw"hufDecode issues"}}var E=8-A&7;for(B>>=E,f-=E;f>0;){var p=t[B<<14-f&16383];if(p.len)f-=p.len,l(p.lit,c,B,f,r,n,o,d,h,u),B=s.c,f=s.lc;else throw"hufDecode issues"}}(p,C,e,o,A,m,f,d,u,{value:0})}function B(e){for(var t=1;t<e.length;t++){var r=e[t-1]+e[t]-128;e[t]=r}}function f(e,t){for(var r=0,n=Math.floor((e.length+1)/2),a=0,i=e.length-1;!(a>i)&&(t[a++]=e[r++],!(a>i));)t[a++]=e[n++]}function m(e){for(var t=e.byteLength,r=[],n=0,a=new DataView(e);t>0;){var i=a.getInt8(n++);if(i<0){var s=-i;t-=s+1;for(var o=0;o<s;o++)r.push(a.getUint8(n++))}else{var s=i;t-=2;for(var l=a.getUint8(n++),o=0;o<s+1;o++)r.push(l)}}return r}function p(e){return new DataView(e.array.buffer,e.offset.value,e.size)}function C(e){var t=new Uint8Array(m(e.viewer.buffer.slice(e.offset.value,e.offset.value+e.size))),r=new Uint8Array(t.length);return B(t),f(t,r),new DataView(r.buffer)}function g(e){var t=V(e.array.slice(e.offset.value,e.offset.value+e.size)),r=new Uint8Array(t.length);return B(t),f(t,r),new DataView(r.buffer)}function E(e){for(var t=e.viewer,r={value:e.offset.value},n=new Uint16Array(e.width*e.scanlineBlockSize*(e.channels*e.type)),a=new Uint8Array(8192),i=0,s=Array(e.channels),o=0;o<e.channels;o++)s[o]={},s[o].start=i,s[o].end=s[o].start,s[o].nx=e.width,s[o].ny=e.lines,s[o].size=e.type,i+=s[o].nx*s[o].ny*s[o].size;var l=H(t,r),A=H(t,r);if(A>=8192)throw"Something is wrong with PIZ_COMPRESSION BITMAP_SIZE";if(l<=A)for(var o=0;o<A-l+1;o++)a[o+l]=R(t,r);var B=new Uint16Array(65536),f=function(e,t){for(var r=0,n=0;n<65536;++n)(0==n||e[n>>3]&1<<(7&n))&&(t[r++]=n);for(var a=r-1;r<65536;)t[r++]=0;return a}(a,B),m=I(t,r);h(e.array,t,r,m,n,i);for(var o=0;o<e.channels;++o)for(var p=s[o],C=0;C<s[o].size;++C)!function(e,t,r,n,a,i,s){for(var o=s<16384,l=r>a?a:r,A=1;A<=l;)A<<=1;for(A>>=1,h=A,A>>=1;A>=1;){for(var h,B,f,m,p,C=0,g=0+i*(a-h),E=i*A,M=i*h,v=n*A,F=n*h;C<=g;C+=M){for(var b=C,I=C+n*(r-h);b<=I;b+=F){var y=b+v,R=b+E,G=R+v;o?(u(e[b+t],e[R+t]),B=c.a,m=c.b,u(e[y+t],e[G+t]),f=c.a,p=c.b,u(B,f),e[b+t]=c.a,e[y+t]=c.b,u(m,p)):(d(e[b+t],e[R+t]),B=c.a,m=c.b,d(e[y+t],e[G+t]),f=c.a,p=c.b,d(B,f),e[b+t]=c.a,e[y+t]=c.b,d(m,p)),e[R+t]=c.a,e[G+t]=c.b}if(r&A){var R=b+E;o?u(e[b+t],e[R+t]):d(e[b+t],e[R+t]),B=c.a,e[R+t]=c.b,e[b+t]=B}}if(a&A)for(var b=C,I=C+n*(r-h);b<=I;b+=F){var y=b+v;o?u(e[b+t],e[y+t]):d(e[b+t],e[y+t]),B=c.a,e[y+t]=c.b,e[b+t]=B}h=A,A>>=1}}(n,p.start+C,p.nx,p.size,p.ny,p.nx*p.size,f);!function(e,t,r){for(var n=0;n<r;++n)t[n]=e[t[n]]}(B,n,i);for(var g=0,E=new Uint8Array(n.buffer.byteLength),M=0;M<e.lines;M++)for(var v=0;v<e.channels;v++){var p=s[v],F=p.nx*p.size,b=new Uint8Array(n.buffer,2*p.end,2*F);E.set(b,g),g+=2*F,p.end+=F}return new DataView(E.buffer)}function M(e){var t=V(e.array.slice(e.offset.value,e.offset.value+e.size));let r=e.lines*e.channels*e.width,n=1==e.type?new Uint16Array(r):new Uint32Array(r),a=0,i=0,s=[,,,,];for(let r=0;r<e.lines;r++)for(let r=0;r<e.channels;r++){let r=0;switch(e.type){case 1:s[0]=a,s[1]=s[0]+e.width,a=s[1]+e.width;for(let a=0;a<e.width;++a)r+=t[s[0]++]<<8|t[s[1]++],n[i]=r,i++;break;case 2:s[0]=a,s[1]=s[0]+e.width,s[2]=s[1]+e.width,a=s[2]+e.width;for(let a=0;a<e.width;++a)r+=t[s[0]++]<<24|t[s[1]++]<<16|t[s[2]++]<<8,n[i]=r,i++}}return new DataView(n.buffer)}function v(e){var t=e.viewer,r={value:e.offset.value},n=new Uint8Array(e.width*e.lines*(e.channels*e.type*2)),a={version:G(t,r),unknownUncompressedSize:G(t,r),unknownCompressedSize:G(t,r),acCompressedSize:G(t,r),dcCompressedSize:G(t,r),rleCompressedSize:G(t,r),rleUncompressedSize:G(t,r),rleRawSize:G(t,r),totalAcUncompressedCount:G(t,r),totalDcUncompressedCount:G(t,r),acCompression:G(t,r)};if(a.version<2)throw"EXRLoader.parse: "+L.compression+" version "+a.version+" is unsupported";for(var i=[],s=H(t,r)-2;s>0;){var l=F(t.buffer,r),A=R(t,r),c=A>>2&3,u=new Int8Array([(A>>4)-1])[0],d=R(t,r);i.push({name:l,index:u,type:d,compression:c}),s-=l.length+3}for(var B=L.channels,f=Array(e.channels),p=0;p<e.channels;++p){var C=f[p]={},E=B[p];C.name=E.name,C.compression=0,C.decoded=!1,C.type=E.pixelType,C.pLinear=E.pLinear,C.width=e.width,C.height=e.lines}for(var M={idx:[,,,]},v=0;v<e.channels;++v)for(var C=f[v],p=0;p<i.length;++p){var b=i[p];C.name==b.name&&(C.compression=b.compression,b.index>=0&&(M.idx[b.index]=v),C.offset=v)}if(a.acCompressedSize>0)switch(a.acCompression){case 0:var I=new Uint16Array(a.totalAcUncompressedCount);h(e.array,t,r,a.acCompressedSize,I,a.totalAcUncompressedCount);break;case 1:var y=e.array.slice(r.value,r.value+a.totalAcUncompressedCount),D=V(y),I=new Uint16Array(D.buffer);r.value+=a.totalAcUncompressedCount}if(a.dcCompressedSize>0){var w=new Uint16Array(g({array:e.array,offset:r,size:a.dcCompressedSize}).buffer);r.value+=a.dcCompressedSize}if(a.rleRawSize>0){var y=e.array.slice(r.value,r.value+a.rleCompressedSize),D=V(y),x=m(D.buffer);r.value+=a.rleCompressedSize}for(var P=0,J=Array(f.length),p=0;p<J.length;++p)J[p]=[];for(var O=0;O<e.lines;++O)for(var S=0;S<f.length;++S)J[S].push(P),P+=f[S].width*e.type*2;!function(e,t,r,n,a,i){var s=new DataView(i.buffer),l=r[e.idx[0]].width,A=r[e.idx[0]].height,c=Math.floor(l/8),u=Math.ceil(l/8),d=Math.ceil(A/8),h=l-(u-1)*8,B=A-(d-1)*8,f={value:0},m=[,,,],p=[,,,],C=[,,,],g=[,,,],E=[,,,];for(let r=0;r<3;++r)E[r]=t[e.idx[r]],m[r]=r<1?0:m[r-1]+u*d,p[r]=new Float32Array(64),C[r]=new Uint16Array(64),g[r]=new Uint16Array(64*u);for(let t=0;t<d;++t){var M,v,F=8;t==d-1&&(F=B);var b=8;for(let e=0;e<u;++e){e==u-1&&(b=h);for(let e=0;e<3;++e)C[e].fill(0),C[e][0]=a[m[e]++],function(e,t,r){for(var n,a=1;a<64;)65280==(n=t[e.value])?a=64:n>>8==255?a+=255&n:(r[a]=n,a++),e.value++}(f,n,C[e]),M=C[e],(v=p[e])[0]=T(M[0]),v[1]=T(M[1]),v[2]=T(M[5]),v[3]=T(M[6]),v[4]=T(M[14]),v[5]=T(M[15]),v[6]=T(M[27]),v[7]=T(M[28]),v[8]=T(M[2]),v[9]=T(M[4]),v[10]=T(M[7]),v[11]=T(M[13]),v[12]=T(M[16]),v[13]=T(M[26]),v[14]=T(M[29]),v[15]=T(M[42]),v[16]=T(M[3]),v[17]=T(M[8]),v[18]=T(M[12]),v[19]=T(M[17]),v[20]=T(M[25]),v[21]=T(M[30]),v[22]=T(M[41]),v[23]=T(M[43]),v[24]=T(M[9]),v[25]=T(M[11]),v[26]=T(M[18]),v[27]=T(M[24]),v[28]=T(M[31]),v[29]=T(M[40]),v[30]=T(M[44]),v[31]=T(M[53]),v[32]=T(M[10]),v[33]=T(M[19]),v[34]=T(M[23]),v[35]=T(M[32]),v[36]=T(M[39]),v[37]=T(M[45]),v[38]=T(M[52]),v[39]=T(M[54]),v[40]=T(M[20]),v[41]=T(M[22]),v[42]=T(M[33]),v[43]=T(M[38]),v[44]=T(M[46]),v[45]=T(M[51]),v[46]=T(M[55]),v[47]=T(M[60]),v[48]=T(M[21]),v[49]=T(M[34]),v[50]=T(M[37]),v[51]=T(M[47]),v[52]=T(M[50]),v[53]=T(M[56]),v[54]=T(M[59]),v[55]=T(M[61]),v[56]=T(M[35]),v[57]=T(M[36]),v[58]=T(M[48]),v[59]=T(M[49]),v[60]=T(M[57]),v[61]=T(M[58]),v[62]=T(M[62]),v[63]=T(M[63]),function(e){let t=.5*Math.cos(3.14159/16),r=.5*Math.cos(3.14159/8),n=.5*Math.cos(3*3.14159/16),a=.5*Math.cos(3*3.14159/8);for(var i=[,,,,],s=[,,,,],o=[,,,,],l=[,,,,],A=0;A<8;++A){var c=8*A;i[0]=r*e[c+2],i[1]=a*e[c+2],i[2]=r*e[c+6],i[3]=a*e[c+6],s[0]=t*e[c+1]+n*e[c+3]+.2777854612564676*e[c+5]+.09754573032714427*e[c+7],s[1]=n*e[c+1]-.09754573032714427*e[c+3]-t*e[c+5]-.2777854612564676*e[c+7],s[2]=.2777854612564676*e[c+1]-t*e[c+3]+.09754573032714427*e[c+5]+n*e[c+7],s[3]=.09754573032714427*e[c+1]-.2777854612564676*e[c+3]+n*e[c+5]-t*e[c+7],o[0]=.35355362513961314*(e[c+0]+e[c+4]),o[3]=.35355362513961314*(e[c+0]-e[c+4]),o[1]=i[0]+i[3],o[2]=i[1]-i[2],l[0]=o[0]+o[1],l[1]=o[3]+o[2],l[2]=o[3]-o[2],l[3]=o[0]-o[1],e[c+0]=l[0]+s[0],e[c+1]=l[1]+s[1],e[c+2]=l[2]+s[2],e[c+3]=l[3]+s[3],e[c+4]=l[3]-s[3],e[c+5]=l[2]-s[2],e[c+6]=l[1]-s[1],e[c+7]=l[0]-s[0]}for(var u=0;u<8;++u)i[0]=r*e[16+u],i[1]=a*e[16+u],i[2]=r*e[48+u],i[3]=a*e[48+u],s[0]=t*e[8+u]+n*e[24+u]+.2777854612564676*e[40+u]+.09754573032714427*e[56+u],s[1]=n*e[8+u]-.09754573032714427*e[24+u]-t*e[40+u]-.2777854612564676*e[56+u],s[2]=.2777854612564676*e[8+u]-t*e[24+u]+.09754573032714427*e[40+u]+n*e[56+u],s[3]=.09754573032714427*e[8+u]-.2777854612564676*e[24+u]+n*e[40+u]-t*e[56+u],o[0]=.35355362513961314*(e[u]+e[32+u]),o[3]=.35355362513961314*(e[u]-e[32+u]),o[1]=i[0]+i[3],o[2]=i[1]-i[2],l[0]=o[0]+o[1],l[1]=o[3]+o[2],l[2]=o[3]-o[2],l[3]=o[0]-o[1],e[0+u]=l[0]+s[0],e[8+u]=l[1]+s[1],e[16+u]=l[2]+s[2],e[24+u]=l[3]+s[3],e[32+u]=l[3]-s[3],e[40+u]=l[2]-s[2],e[48+u]=l[1]-s[1],e[56+u]=l[0]-s[0]}(p[e]);!function(e){for(var t=0;t<64;++t){var r=e[0][t],n=e[1][t],a=e[2][t];e[0][t]=r+1.5747*a,e[1][t]=r-.1873*n-.4682*a,e[2][t]=r+1.8556*n}}(p);for(let t=0;t<3;++t)!function(e,t,r){for(var n,a=0;a<64;++a)t[r+a]=o.A5E.toHalfFloat((n=e[a])<=1?Math.sign(n)*Math.pow(Math.abs(n),2.2):Math.sign(n)*Math.pow(9.025013291561939,Math.abs(n)-1))}(p[t],g[t],64*e)}let i=0;for(let n=0;n<3;++n){let a=r[e.idx[n]].type;for(let e=8*t;e<8*t+F;++e){i=E[n][e];for(let t=0;t<c;++t){let r=64*t+(7&e)*8;s.setUint16(i+0*a,g[n][r+0],!0),s.setUint16(i+2*a,g[n][r+1],!0),s.setUint16(i+4*a,g[n][r+2],!0),s.setUint16(i+6*a,g[n][r+3],!0),s.setUint16(i+8*a,g[n][r+4],!0),s.setUint16(i+10*a,g[n][r+5],!0),s.setUint16(i+12*a,g[n][r+6],!0),s.setUint16(i+14*a,g[n][r+7],!0),i+=16*a}}if(c!=u)for(let e=8*t;e<8*t+F;++e){let t=E[n][e]+8*c*2*a,r=64*c+(7&e)*8;for(let e=0;e<b;++e)s.setUint16(t+2*e*a,g[n][r+e],!0)}}}for(var I=new Uint16Array(l),s=new DataView(i.buffer),y=0;y<3;++y){r[e.idx[y]].decoded=!0;var R=r[e.idx[y]].type;if(2==r[y].type)for(var G=0;G<A;++G){let e=E[y][G];for(var D=0;D<l;++D)I[D]=s.getUint16(e+2*D*R,!0);for(var D=0;D<l;++D)s.setFloat32(e+2*D*R,T(I[D]),!0)}}}(M,J,f,I,w,n);for(var p=0;p<f.length;++p){var C=f[p];if(!C.decoded){if(2===C.compression)for(var U=0,_=0,O=0;O<e.lines;++O){for(var K=J[p][U],N=0;N<C.width;++N){for(var k=0;k<2*C.type;++k)n[K++]=x[_+k*C.width*C.height];_++}U++}else throw"EXRLoader.parse: unsupported channel compression"}}return new DataView(n.buffer)}function F(e,t){for(var r=new Uint8Array(e),n=0;0!=r[t.value+n];)n+=1;var a=new TextDecoder().decode(r.slice(t.value,t.value+n));return t.value=t.value+n+1,a}function b(e,t){var r=e.getInt32(t.value,!0);return t.value=t.value+4,r}function I(e,t){var r=e.getUint32(t.value,!0);return t.value=t.value+4,r}function y(e,t){var r=e[t.value];return t.value=t.value+1,r}function R(e,t){var r=e.getUint8(t.value);return t.value=t.value+1,r}let G=function(e,t){let r;return"getBigInt64"in DataView.prototype?r=Number(e.getBigInt64(t.value,!0)):r=e.getUint32(t.value+4,!0)+Number(e.getUint32(t.value,!0)<<32),t.value+=8,r};function D(e,t){var r=e.getFloat32(t.value,!0);return t.value+=4,r}function w(e,t){return o.A5E.toHalfFloat(D(e,t))}function T(e){var t=(31744&e)>>10,r=1023&e;return(e>>15?-1:1)*(t?31===t?r?NaN:1/0:Math.pow(2,t-15)*(1+r/1024):r/1024*6103515625e-14)}function H(e,t){var r=e.getUint16(t.value,!0);return t.value+=2,r}function x(e,t){return T(H(e,t))}let P=new DataView(e),J=new Uint8Array(e),O={value:0},L=function(e,t,r){let n={};if(20000630!=e.getUint32(0,!0))throw"THREE.EXRLoader: provided file doesn't appear to be in OpenEXR format.";n.version=e.getUint8(4);let a=e.getUint8(5);n.spec={singleTile:!!(2&a),longName:!!(4&a),deepFormat:!!(8&a),multiPart:!!(16&a)},r.value=8;for(var i=!0;i;){var s=F(t,r);if(0==s)i=!1;else{var o=F(t,r),l=I(e,r),A=function(e,t,r,n,a){var i,s,o,l,A;if("string"===n||"stringvector"===n||"iccProfile"===n)return i=new TextDecoder().decode(new Uint8Array(t).slice(r.value,r.value+a)),r.value=r.value+a,i;if("chlist"===n)return function(e,t,r,n){for(var a=r.value,i=[];r.value<a+n-1;){var s=F(t,r),o=b(e,r),l=R(e,r);r.value+=3;var A=b(e,r),c=b(e,r);i.push({name:s,pixelType:o,pLinear:l,xSampling:A,ySampling:c})}return r.value+=1,i}(e,t,r,a);if("chromaticities"===n)return s=D(e,r),o=D(e,r),l=D(e,r),A=D(e,r),{redX:s,redY:o,greenX:l,greenY:A,blueX:D(e,r),blueY:D(e,r),whiteX:D(e,r),whiteY:D(e,r)};if("compression"===n)return["NO_COMPRESSION","RLE_COMPRESSION","ZIPS_COMPRESSION","ZIP_COMPRESSION","PIZ_COMPRESSION","PXR24_COMPRESSION","B44_COMPRESSION","B44A_COMPRESSION","DWAA_COMPRESSION","DWAB_COMPRESSION"][R(e,r)];if("box2i"===n)return{xMin:I(e,r),yMin:I(e,r),xMax:I(e,r),yMax:I(e,r)};if("lineOrder"===n)return["INCREASING_Y"][R(e,r)];if("float"===n)return D(e,r);else if("v2f"===n)return[D(e,r),D(e,r)];else if("v3f"===n)return[D(e,r),D(e,r),D(e,r)];else if("int"===n)return b(e,r);else if("rational"===n)return[b(e,r),I(e,r)];else if("timecode"===n)return[I(e,r),I(e,r)];else return"preview"===n?(r.value+=a,"skipped"):void(r.value+=a)}(e,t,r,o,l);void 0===A?console.warn(`EXRLoader.parse: skipped unknown header attribute type '${o}'.`):n[s]=A}}if((-5&a)!=0)throw console.error("EXRHeader:",n),"THREE.EXRLoader: provided file is currently unsupported.";return n}(P,e,O),S=function(e,t,r,n,a){let i={size:0,viewer:t,array:r,offset:n,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,[$?"colorSpace":"encoding"]:null};switch(e.compression){case"NO_COMPRESSION":i.lines=1,i.uncompress=p;break;case"RLE_COMPRESSION":i.lines=1,i.uncompress=C;break;case"ZIPS_COMPRESSION":i.lines=1,i.uncompress=g;break;case"ZIP_COMPRESSION":i.lines=16,i.uncompress=g;break;case"PIZ_COMPRESSION":i.lines=32,i.uncompress=E;break;case"PXR24_COMPRESSION":i.lines=16,i.uncompress=M;break;case"DWAA_COMPRESSION":i.lines=32,i.uncompress=v;break;case"DWAB_COMPRESSION":i.lines=256,i.uncompress=v;break;default:throw"EXRLoader.parse: "+e.compression+" is unsupported"}if(i.scanlineBlockSize=i.lines,1==i.type)switch(a){case o.VzW:i.getter=x,i.inputSize=2;break;case o.cLu:i.getter=H,i.inputSize=2}else if(2==i.type)switch(a){case o.VzW:i.getter=D,i.inputSize=4;break;case o.cLu:i.getter=w,i.inputSize=4}else throw"EXRLoader.parse: unsupported pixelType "+i.type+" for "+e.compression+".";i.blockCount=(e.dataWindow.yMax+1)/i.scanlineBlockSize;for(var s=0;s<i.blockCount;s++)G(t,n);i.outputChannels=3==i.channels?4:i.channels;let l=i.width*i.height*i.outputChannels;switch(a){case o.VzW:i.byteArray=new Float32Array(l),i.channels<i.outputChannels&&i.byteArray.fill(1,0,l);break;case o.cLu:i.byteArray=new Uint16Array(l),i.channels<i.outputChannels&&i.byteArray.fill(15360,0,l);break;default:console.error("THREE.EXRLoader: unsupported type: ",a)}return i.bytesPerLine=i.width*i.inputSize*i.channels,4==i.outputChannels?i.format=o.wk1:i.format=o.hEm,$?i.colorSpace="srgb-linear":i.encoding=3e3,i}(L,P,J,O,this.type),U={value:0},_={R:0,G:1,B:2,A:3,Y:0};for(let e=0;e<S.height/S.scanlineBlockSize;e++){let t=I(P,O);S.size=I(P,O),S.lines=t+S.scanlineBlockSize>S.height?S.height-t:S.scanlineBlockSize;let r=S.size<S.lines*S.bytesPerLine?S.uncompress(S):p(S);O.value+=S.size;for(let t=0;t<S.scanlineBlockSize;t++){let n=t+e*S.scanlineBlockSize;if(n>=S.height)break;for(let e=0;e<S.channels;e++){let a=_[L.channels[e].name];for(let i=0;i<S.width;i++){U.value=(S.channels*S.width*t+e*S.width+i)*S.inputSize;let s=(S.height-1-n)*(S.width*S.outputChannels)+i*S.outputChannels+a;S.byteArray[s]=S.getter(r,U)}}}}return{header:L,width:S.width,height:S.height,data:S.byteArray,format:S.format,[$?"colorSpace":"encoding"]:S[$?"colorSpace":"encoding"],type:this.type}}setDataType(e){return this.type=e,this}load(e,t,r,n){return super.load(e,function(e,r){$?e.colorSpace=r.colorSpace:e.encoding=r.encoding,e.minFilter=o.wem,e.magFilter=o.wem,e.generateMipmaps=!1,e.flipY=!1,t&&t(e,r)},r,n)}}var et=r(51448);let er=(e,t,r)=>{let n;switch(e){case o.ywz:n=new Uint8ClampedArray(t*r*4);break;case o.cLu:n=new Uint16Array(t*r*4);break;case o.JQ4:n=new Uint32Array(t*r*4);break;case o.T95:n=new Int8Array(t*r*4);break;case o.iAb:n=new Int16Array(t*r*4);break;case o.Kz5:n=new Int32Array(t*r*4);break;case o.VzW:n=new Float32Array(t*r*4);break;default:throw Error("Unsupported data type")}return n},en=(e,t,r,a)=>{if(void 0!==n)return n;let i=new o.dd2(1,1,a);t.setRenderTarget(i);let s=new o.Kj0(new o._12,new o.vBJ({color:16777215}));t.render(s,r),t.setRenderTarget(null);let l=er(e,i.width,i.height);return t.readRenderTargetPixels(i,0,0,i.width,i.height,l),i.dispose(),s.geometry.dispose(),s.material.dispose(),n=0!==l[0]};class ea{constructor(e){var t,r,n,a,i,s,l,A,c,u,d,h,B,f,m,p;this._rendererIsDisposable=!1,this._supportsReadPixels=!0,this.render=()=>{this._renderer.setRenderTarget(this._renderTarget);try{this._renderer.render(this._scene,this._camera)}catch(e){throw this._renderer.setRenderTarget(null),e}this._renderer.setRenderTarget(null)},this._width=e.width,this._height=e.height,this._type=e.type,this._colorSpace=e.colorSpace;let C={format:o.wk1,depthBuffer:!1,stencilBuffer:!1,type:this._type,colorSpace:this._colorSpace,anisotropy:(null===(t=e.renderTargetOptions)||void 0===t?void 0:t.anisotropy)!==void 0?null===(r=e.renderTargetOptions)||void 0===r?void 0:r.anisotropy:1,generateMipmaps:(null===(n=e.renderTargetOptions)||void 0===n?void 0:n.generateMipmaps)!==void 0&&(null===(a=e.renderTargetOptions)||void 0===a?void 0:a.generateMipmaps),magFilter:(null===(i=e.renderTargetOptions)||void 0===i?void 0:i.magFilter)!==void 0?null===(s=e.renderTargetOptions)||void 0===s?void 0:s.magFilter:o.wem,minFilter:(null===(l=e.renderTargetOptions)||void 0===l?void 0:l.minFilter)!==void 0?null===(A=e.renderTargetOptions)||void 0===A?void 0:A.minFilter:o.wem,samples:(null===(c=e.renderTargetOptions)||void 0===c?void 0:c.samples)!==void 0?null===(u=e.renderTargetOptions)||void 0===u?void 0:u.samples:void 0,wrapS:(null===(d=e.renderTargetOptions)||void 0===d?void 0:d.wrapS)!==void 0?null===(h=e.renderTargetOptions)||void 0===h?void 0:h.wrapS:o.uWy,wrapT:(null===(B=e.renderTargetOptions)||void 0===B?void 0:B.wrapT)!==void 0?null===(f=e.renderTargetOptions)||void 0===f?void 0:f.wrapT:o.uWy};if(this._material=e.material,e.renderer?this._renderer=e.renderer:(this._renderer=ea.instantiateRenderer(),this._rendererIsDisposable=!0),this._scene=new o.xsS,this._camera=new o.iKG,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(),!en(this._type,this._renderer,this._camera,C)){let e;this._type===o.cLu&&(e=this._renderer.extensions.has("EXT_color_buffer_float")?o.VzW:void 0),void 0!==e?(console.warn(`This browser does not support reading pixels from ${this._type} RenderTargets, switching to ${o.VzW}`),this._type=e):(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 o.Kj0(new o._12,this._material),this._quad.geometry.computeBoundingBox(),this._scene.add(this._quad),this._renderTarget=new o.dd2(this.width,this.height,C),this._renderTarget.texture.mapping=(null===(m=e.renderTargetOptions)||void 0===m?void 0:m.mapping)!==void 0?null===(p=e.renderTargetOptions)||void 0===p?void 0:p.mapping:o.xfE}static instantiateRenderer(){let e=new et.WebGLRenderer;return e.setSize(128,128),e}toArray(){if(!this._supportsReadPixels)throw Error("Can't read pixels in this browser");let e=er(this._type,this._width,this._height);return this._renderer.readRenderTargetPixels(this._renderTarget,0,0,this._width,this._height,e),e}toDataTexture(e){let t=new o.IEO(this.toArray(),this.width,this.height,o.wk1,this._type,(null==e?void 0:e.mapping)||o.xfE,(null==e?void 0:e.wrapS)||o.uWy,(null==e?void 0:e.wrapT)||o.uWy,(null==e?void 0:e.magFilter)||o.wem,(null==e?void 0:e.minFilter)||o.wem,(null==e?void 0:e.anisotropy)||1,o.GUF);return t.generateMipmaps=(null==e?void 0:e.generateMipmaps)!==void 0&&(null==e?void 0:e.generateMipmaps),t}disposeOnDemandRenderer(){this._renderer.setRenderTarget(null),this._rendererIsDisposable&&(this._renderer.dispose(),this._renderer.forceContextLoss())}dispose(e){this.disposeOnDemandRenderer(),e&&this.renderTarget.dispose(),this.material instanceof o.jyz&&Object.values(this.material.uniforms).forEach(e=>{e.value instanceof o.xEZ&&e.value.dispose()}),Object.values(this.material).forEach(e=>{e instanceof o.xEZ&&e.dispose()}),this.material.dispose(),this._quad.geometry.dispose()}get width(){return this._width}set width(e){this._width=e,this._renderTarget.setSize(this._width,this._height)}get height(){return this._height}set height(e){this._height=e,this._renderTarget.setSize(this._width,this._height)}get renderer(){return this._renderer}get renderTarget(){return this._renderTarget}set renderTarget(e){this._renderTarget=e,this._width=e.width,this._height=e.height}get material(){return this._material}get type(){return this._type}get colorSpace(){return this._colorSpace}}let ei=`
varying vec2 vUv;
void main() {
vUv = uv;
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
`,es=`
// 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 eo extends o.jyz{constructor({gamma:e,offsetHdr:t,offsetSdr:r,gainMapMin:n,gainMapMax:a,maxDisplayBoost:i,hdrCapacityMin:s,hdrCapacityMax:l,sdr:A,gainMap:c}){super({name:"GainMapDecoderMaterial",vertexShader:ei,fragmentShader:es,uniforms:{sdr:{value:A},gainMap:{value:c},gamma:{value:new o.Pa4(1/e[0],1/e[1],1/e[2])},offsetHdr:{value:new o.Pa4().fromArray(t)},offsetSdr:{value:new o.Pa4().fromArray(r)},gainMapMin:{value:new o.Pa4().fromArray(n)},gainMapMax:{value:new o.Pa4().fromArray(a)},weightFactor:{value:(Math.log2(i)-s)/(l-s)}},blending:o.jFi,depthTest:!1,depthWrite:!1}),this._maxDisplayBoost=i,this._hdrCapacityMin=s,this._hdrCapacityMax=l,this.needsUpdate=!0,this.uniformsNeedUpdate=!0}get sdr(){return this.uniforms.sdr.value}set sdr(e){this.uniforms.sdr.value=e}get gainMap(){return this.uniforms.gainMap.value}set gainMap(e){this.uniforms.gainMap.value=e}get offsetHdr(){return this.uniforms.offsetHdr.value.toArray()}set offsetHdr(e){this.uniforms.offsetHdr.value.fromArray(e)}get offsetSdr(){return this.uniforms.offsetSdr.value.toArray()}set offsetSdr(e){this.uniforms.offsetSdr.value.fromArray(e)}get gainMapMin(){return this.uniforms.gainMapMin.value.toArray()}set gainMapMin(e){this.uniforms.gainMapMin.value.fromArray(e)}get gainMapMax(){return this.uniforms.gainMapMax.value.toArray()}set gainMapMax(e){this.uniforms.gainMapMax.value.fromArray(e)}get gamma(){let e=this.uniforms.gamma.value;return[1/e.x,1/e.y,1/e.z]}set gamma(e){let t=this.uniforms.gamma.value;t.x=1/e[0],t.y=1/e[1],t.z=1/e[2]}get hdrCapacityMin(){return this._hdrCapacityMin}set hdrCapacityMin(e){this._hdrCapacityMin=e,this.calculateWeight()}get hdrCapacityMax(){return this._hdrCapacityMax}set hdrCapacityMax(e){this._hdrCapacityMax=e,this.calculateWeight()}get maxDisplayBoost(){return this._maxDisplayBoost}set maxDisplayBoost(e){this._maxDisplayBoost=Math.max(1,Math.min(65504,e)),this.calculateWeight()}calculateWeight(){let e=(Math.log2(this._maxDisplayBoost)-this._hdrCapacityMin)/(this._hdrCapacityMax-this._hdrCapacityMin);this.uniforms.weightFactor.value=Math.max(0,Math.min(1,e))}}class el extends Error{}class eA extends Error{}let ec=(e,t,r)=>{let n=RegExp(`${t}="([^"]*)"`,"i").exec(e);if(n)return n[1];let a=RegExp(`<${t}[^>]*>([\\s\\S]*?)</${t}>`,"i").exec(e);if(a){let e=a[1].match(/<rdf:li>([^<]*)<\/rdf:li>/g);return e&&3===e.length?e.map(e=>e.replace(/<\/?rdf:li>/g,"")):a[1].trim()}if(void 0!==r)return r;throw Error(`Can't find ${t} in gainmap metadata`)},eu=e=>{let t;"undefined"!=typeof TextDecoder?t=new TextDecoder().decode(e):t=e.toString();let r=t.indexOf("<x:xmpmeta");for(;-1!==r;){let e=t.indexOf("x:xmpmeta>",r),n=t.slice(r,e+10);try{let e=ec(n,"hdrgm:GainMapMin","0"),t=ec(n,"hdrgm:GainMapMax"),r=ec(n,"hdrgm:Gamma","1"),a=ec(n,"hdrgm:OffsetSDR","0.015625"),i=ec(n,"hdrgm:OffsetHDR","0.015625"),s=/hdrgm:HDRCapacityMin="([^"]*)"/.exec(n),o=s?s[1]:"0",l=/hdrgm:HDRCapacityMax="([^"]*)"/.exec(n);if(!l)throw Error("Incomplete gainmap metadata");let A=l[1];return{gainMapMin:Array.isArray(e)?e.map(e=>parseFloat(e)):[parseFloat(e),parseFloat(e),parseFloat(e)],gainMapMax:Array.isArray(t)?t.map(e=>parseFloat(e)):[parseFloat(t),parseFloat(t),parseFloat(t)],gamma:Array.isArray(r)?r.map(e=>parseFloat(e)):[parseFloat(r),parseFloat(r),parseFloat(r)],offsetSdr:Array.isArray(a)?a.map(e=>parseFloat(e)):[parseFloat(a),parseFloat(a),parseFloat(a)],offsetHdr:Array.isArray(i)?i.map(e=>parseFloat(e)):[parseFloat(i),parseFloat(i),parseFloat(i)],hdrCapacityMin:parseFloat(o),hdrCapacityMax:parseFloat(A)}}catch(e){}r=t.indexOf("<x:xmpmeta",e)}};class ed{constructor(e){this.options={debug:!!e&&void 0!==e.debug&&e.debug,extractFII:!e||void 0===e.extractFII||e.extractFII,extractNonFII:!e||void 0===e.extractNonFII||e.extractNonFII}}extract(e){return new Promise((t,r)=>{let n;let a=this.options.debug,i=new DataView(e.buffer);if(65496!==i.getUint16(0)){r(Error("Not a valid jpeg"));return}let s=i.byteLength,o=2,l=0;for(;o<s;){if(++l>250){r(Error(`Found no marker after ${l} loops 😵`));return}if(255!==i.getUint8(o)){r(Error(`Not a valid marker at offset 0x${o.toString(16)}, found: 0x${i.getUint8(o).toString(16)}`));return}if(n=i.getUint8(o+1),a&&console.log(`Marker: ${n.toString(16)}`),226===n){a&&console.log("Found APP2 marker (0xffe2)");let e=o+4;if(1297106432===i.getUint32(e)){let n;let a=e+4;if(18761===i.getUint16(a))n=!1;else if(19789===i.getUint16(a))n=!0;else{r(Error("No valid endianness marker found in TIFF header"));return}if(42!==i.getUint16(a+2,!n)){r(Error("Not valid TIFF data! (no 0x002A marker)"));return}let s=i.getUint32(a+4,!n);if(s<8){r(Error("Not valid TIFF data! (First offset less than 8)"));return}let o=a+s,l=i.getUint16(o,!n),A=o+2,c=0;for(let e=A;e<A+12*l;e+=12)45057===i.getUint16(e,!n)&&(c=i.getUint32(e+8,!n));let u=o+2+12*l+4,d=[];for(let e=u;e<u+16*c;e+=16){let t={MPType:i.getUint32(e,!n),size:i.getUint32(e+4,!n),dataOffset:i.getUint32(e+8,!n),dependantImages:i.getUint32(e+12,!n),start:-1,end:-1,isFII:!1};t.dataOffset?(t.start=a+t.dataOffset,t.isFII=!1):(t.start=0,t.isFII=!0),t.end=t.start+t.size,d.push(t)}if(this.options.extractNonFII&&d.length){let e=new Blob([i]),r=[];for(let t of d){if(t.isFII&&!this.options.extractFII)continue;let n=e.slice(t.start,t.end+1,"image/jpeg");r.push(n)}t(r)}}}o+=2+i.getUint16(o+2)}})}}let eh=async e=>{let t=eu(e);if(!t)throw new eA("Gain map XMP metadata not found");let r=new ed({extractFII:!0,extractNonFII:!0}),n=await r.extract(e);if(2!==n.length)throw new el("Gain map recovery image not found");return{sdr:new Uint8Array(await n[0].arrayBuffer()),gainMap:new Uint8Array(await n[1].arrayBuffer()),metadata:t}},eB=e=>new Promise((t,r)=>{let n=document.createElement("img");n.onload=()=>{t(n)},n.onerror=e=>{r(e)},n.src=URL.createObjectURL(e)});class ef extends o.aNw{constructor(e,t){super(t),e&&(this._renderer=e),this._internalLoadingManager=new o.lLk}setRenderer(e){return this._renderer=e,this}setRenderTargetOptions(e){return this._renderTargetOptions=e,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.");let e=new eo({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 o.xEZ,sdr:new o.xEZ});return new ea({width:16,height:16,type:o.cLu,colorSpace:o.GUF,material:e,renderer:this._renderer,renderTargetOptions:this._renderTargetOptions})}async render(e,t,r,n){let a,i;let s=n?new Blob([n],{type:"image/jpeg"}):void 0,l=new Blob([r],{type:"image/jpeg"}),A=!1;if("undefined"==typeof createImageBitmap){let e=await Promise.all([s?eB(s):Promise.resolve(void 0),eB(l)]);i=e[0],a=e[1],A=!0}else{let e=await Promise.all([s?createImageBitmap(s,{imageOrientation:"flipY"}):Promise.resolve(void 0),createImageBitmap(l,{imageOrientation:"flipY"})]);i=e[0],a=e[1]}let c=new o.xEZ(i||new ImageData(2,2),o.xfE,o.uWy,o.uWy,o.wem,o.FDw,o.wk1,o.ywz,1,o.GUF);c.flipY=A,c.needsUpdate=!0;let u=new o.xEZ(a,o.xfE,o.uWy,o.uWy,o.wem,o.FDw,o.wk1,o.ywz,1,o.KI_);u.flipY=A,u.needsUpdate=!0,e.width=a.width,e.height=a.height,e.material.gainMap=c,e.material.sdr=u,e.material.gainMapMin=t.gainMapMin,e.material.gainMapMax=t.gainMapMax,e.material.offsetHdr=t.offsetHdr,e.material.offsetSdr=t.offsetSdr,e.material.gamma=t.gamma,e.material.hdrCapacityMin=t.hdrCapacityMin,e.material.hdrCapacityMax=t.hdrCapacityMax,e.material.maxDisplayBoost=Math.pow(2,t.hdrCapacityMax),e.material.needsUpdate=!0,e.render()}}class em extends ef{load([e,t,r],n,a,i){let s,l,A;let c=this.prepareQuadRenderer(),u=async()=>{if(s&&l&&A){try{await this.render(c,A,s,l)}catch(n){this.manager.itemError(e),this.manager.itemError(t),this.manager.itemError(r),"function"==typeof i&&i(n),c.disposeOnDemandRenderer();return}"function"==typeof n&&n(c),this.manager.itemEnd(e),this.manager.itemEnd(t),this.manager.itemEnd(r),c.disposeOnDemandRenderer()}},d=!0,h=0,B=0,f=!0,m=0,p=0,C=!0,g=0,E=0,M=()=>{"function"==typeof a&&a(new ProgressEvent("progress",{lengthComputable:d&&f&&C,loaded:B+p+E,total:h+m+g}))};this.manager.itemStart(e),this.manager.itemStart(t),this.manager.itemStart(r);let v=new o.hH6(this._internalLoadingManager);v.setResponseType("arraybuffer"),v.setRequestHeader(this.requestHeader),v.setPath(this.path),v.setWithCredentials(this.withCredentials),v.load(e,async e=>{if("string"==typeof e)throw Error("Invalid sdr buffer");s=e,await u()},e=>{d=e.lengthComputable,B=e.loaded,h=e.total,M()},t=>{this.manager.itemError(e),"function"==typeof i&&i(t)});let F=new o.hH6(this._internalLoadingManager);F.setResponseType("arraybuffer"),F.setRequestHeader(this.requestHeader),F.setPath(this.path),F.setWithCredentials(this.withCredentials),F.load(t,async e=>{if("string"==typeof e)throw Error("Invalid gainmap buffer");l=e,await u()},e=>{f=e.lengthComputable,p=e.loaded,m=e.total,M()},e=>{this.manager.itemError(t),"function"==typeof i&&i(e)});let b=new o.hH6(this._internalLoadingManager);return b.setRequestHeader(this.requestHeader),b.setPath(this.path),b.setWithCredentials(this.withCredentials),b.load(r,async e=>{if("string"!=typeof e)throw Error("Invalid metadata string");A=JSON.parse(e),await u()},e=>{C=e.lengthComputable,E=e.loaded,g=e.total,M()},e=>{this.manager.itemError(r),"function"==typeof i&&i(e)}),c}}class ep extends ef{load(e,t,r,n){let a=this.prepareQuadRenderer(),i=new o.hH6(this._internalLoadingManager);return i.setResponseType("arraybuffer"),i.setRequestHeader(this.requestHeader),i.setPath(this.path),i.setWithCredentials(this.withCredentials),this.manager.itemStart(e),i.load(e,async r=>{let i,s,o;if("string"==typeof r)throw Error("Invalid buffer, received [string], was expecting [ArrayBuffer]");let l=new Uint8Array(r);try{let e=await eh(l);i=e.sdr,s=e.gainMap,o=e.metadata}catch(t){if(t instanceof eA||t instanceof el)console.warn(`Failure to reconstruct an HDR image from ${e}: Gain map metadata not found in the file, HDRJPGLoader will render the SDR jpeg`),o={gainMapMin:[0,0,0],gainMapMax:[1,1,1],gamma:[1,1,1],hdrCapacityMin:0,hdrCapacityMax:1,offsetHdr:[0,0,0],offsetSdr:[0,0,0]},i=l;else throw t}try{await this.render(a,o,i,s)}catch(t){this.manager.itemError(e),"function"==typeof n&&n(t),a.disposeOnDemandRenderer();return}"function"==typeof t&&t(a),this.manager.itemEnd(e),a.disposeOnDemandRenderer()},r,t=>{this.manager.itemError(e),"function"==typeof n&&n(t)}),a}}let eC={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"},eg="https://raw.githack.com/pmndrs/drei-assets/456060a26bbeb8fdf79326f224b6d99b8bcce736/hdri/",eE=e=>Array.isArray(e),eM=["/px.png","/nx.png","/py.png","/ny.png","/pz.png","/nz.png"];function ev({files:e=eM,path:t="",preset:r,encoding:n,extensions:a}={}){let l=null,A=!1;r&&(eI(r),e=eC[r],t=eg),A=eE(e);let{extension:c,isCubemap:u}=ey(e);if(!(l=eR(c)))throw Error("useEnvironment: Unrecognized file extension: "+e);let d=(0,s.D)(e=>e.gl);(0,i.useLayoutEffect)(()=>{("webp"===c||"jpg"===c||"jpeg"===c)&&d.domElement.addEventListener("webglcontextlost",function(){s.H.clear(l,A?[e]:e)},{once:!0})},[e,d.domElement]);let h=(0,s.H)(l,A?[e]:e,e=>{("webp"===c||"jpg"===c||"jpeg"===c)&&e.setRenderer(d),null==e.setPath||e.setPath(t),a&&a(e)}),B=A?h[0]:h;if("jpg"===c||"jpeg"===c||"webp"===c){var f;B=null==(f=B.renderTarget)?void 0:f.texture}return B.mapping=u?o.fY$:o.dSO,"colorSpace"in B?B.colorSpace=(null!=n?n:u)?"srgb":"srgb-linear":B.encoding=(null!=n?n:u)?3001:3e3,B}let eF={files:eM,path:"",preset:void 0,extensions:void 0};ev.preload=e=>{let t={...eF,...e},{files:r,path:n=""}=t,{preset:a,extensions:i}=t;a&&(eI(a),r=eC[a],n=eg);let{extension:o}=ey(r);if("webp"===o||"jpg"===o||"jpeg"===o)throw Error("useEnvironment: Preloading gainmaps is not supported");let l=eR(o);if(!l)throw Error("useEnvironment: Unrecognized file extension: "+r);s.H.preload(l,eE(r)?[r]:r,e=>{null==e.setPath||e.setPath(n),i&&i(e)})};let eb={files:eM,preset:void 0};function eI(e){if(!(e in eC))throw Error("Preset must be one of: "+Object.keys(eC).join(", "))}function ey(e){var t;let r=eE(e)&&6===e.length,n=eE(e)&&3===e.length&&e.some(e=>e.endsWith("json")),a=eE(e)?e[0]:e;return{extension:r?"cube":n?"webp":a.startsWith("data:application/exr")?"exr":a.startsWith("data:application/hdr")?"hdr":a.startsWith("data:image/jpeg")?"jpg":null==(t=a.split(".").pop())||null==(t=t.split("?"))||null==(t=t.shift())