/* Frost: three@0.185.1 (MIT) + three-mesh-bvh@0.9.14 (MIT). Generated by build.mjs; edit src/ and rebuild. */ var Frost=(()=>{var cD=Object.create,Nf=Object.defineProperty,pD=Object.getOwnPropertyDescriptor,mD=Object.getOwnPropertyNames,fD=Object.getPrototypeOf,gD=Object.prototype.hasOwnProperty,pM=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),mM=(e,t)=>{for(var r in t)Nf(e,r,{get:t[r],enumerable:!0})},fM=(e,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of mD(t))!gD.call(e,s)&&s!==r&&Nf(e,s,{get:()=>t[s],enumerable:!(i=pD(t,s))||i.enumerable});return e},yD=(e,t,r)=>(r=e!=null?cD(fD(e)):{},fM(t||!e||!e.__esModule?Nf(r,"default",{value:e,enumerable:!0}):r,e)),xD=e=>fM(Nf({},"__esModule",{value:!0}),e),vD=pM((e,t)=>{(function(){"use strict";var r={};r.version="6.4.2.2",r.use_lines=!0,r.use_xyz=!1;var i=!1;typeof t<"u"&&t.exports?(t.exports=r,i=!0):(typeof define=="function"&&define.amd&&define(r),typeof document<"u"?window.ClipperLib=r:self.ClipperLib=r);var s;if(i){var a="chrome";s="Netscape"}else{var a=navigator.userAgent.toString().toLowerCase();s=navigator.appName}var n={};a.indexOf("chrome")!=-1&&a.indexOf("chromium")==-1?n.chrome=1:n.chrome=0,a.indexOf("chromium")!=-1?n.chromium=1:n.chromium=0,a.indexOf("safari")!=-1&&a.indexOf("chrome")==-1&&a.indexOf("chromium")==-1?n.safari=1:n.safari=0,a.indexOf("firefox")!=-1?n.firefox=1:n.firefox=0,a.indexOf("firefox/17")!=-1?n.firefox17=1:n.firefox17=0,a.indexOf("firefox/15")!=-1?n.firefox15=1:n.firefox15=0,a.indexOf("firefox/3")!=-1?n.firefox3=1:n.firefox3=0,a.indexOf("opera")!=-1?n.opera=1:n.opera=0,a.indexOf("msie 10")!=-1?n.msie10=1:n.msie10=0,a.indexOf("msie 9")!=-1?n.msie9=1:n.msie9=0,a.indexOf("msie 8")!=-1?n.msie8=1:n.msie8=0,a.indexOf("msie 7")!=-1?n.msie7=1:n.msie7=0,a.indexOf("msie ")!=-1?n.msie=1:n.msie=0,r.biginteger_used=null;var o,l=0xdeadbeefcafe,u=(l&16777215)==15715070;function h(p,f,x){r.biginteger_used=1,p!=null&&(typeof p=="number"&&typeof f>"u"?this.fromInt(p):typeof p=="number"?this.fromNumber(p,f,x):f==null&&typeof p!="string"?this.fromString(p,256):this.fromString(p,f))}function d(){return new h(null,void 0,void 0)}function c(p,f,x,_,A,B){for(;--B>=0;){var k=f*this[p++]+x[_]+A;A=Math.floor(k/67108864),x[_++]=k&67108863}return A}function m(p,f,x,_,A,B){for(var k=f&32767,ee=f>>15;--B>=0;){var te=this[p]&32767,me=this[p++]>>15,Le=ee*te+me*k;te=k*te+((Le&32767)<<15)+x[_]+(A&1073741823),A=(te>>>30)+(Le>>>15)+ee*me+(A>>>30),x[_++]=te&1073741823}return A}function g(p,f,x,_,A,B){for(var k=f&16383,ee=f>>14;--B>=0;){var te=this[p]&16383,me=this[p++]>>14,Le=ee*te+me*k;te=k*te+((Le&16383)<<14)+x[_]+A,A=(te>>28)+(Le>>14)+ee*me,x[_++]=te&268435455}return A}u&&s=="Microsoft Internet Explorer"?(h.prototype.am=m,o=30):u&&s!="Netscape"?(h.prototype.am=c,o=26):(h.prototype.am=g,o=28),h.prototype.DB=o,h.prototype.DM=(1<=0;--f)p[f]=this[f];p.t=this.t,p.s=this.s}function R(p){this.t=1,this.s=p<0?-1:0,p>0?this[0]=p:p<-1?this[0]=p+this.DV:this.t=0}function E(p){var f=d();return f.fromInt(p),f}function P(p,f){var x;if(f==16)x=4;else if(f==8)x=3;else if(f==256)x=8;else if(f==2)x=1;else if(f==32)x=5;else if(f==4)x=2;else{this.fromRadix(p,f);return}this.t=0,this.s=0;for(var _=p.length,A=!1,B=0;--_>=0;){var k=x==8?p[_]&255:N(p,_);if(k<0){p.charAt(_)=="-"&&(A=!0);continue}A=!1,B==0?this[this.t++]=k:B+x>this.DB?(this[this.t-1]|=(k&(1<>this.DB-B):this[this.t-1]|=k<=this.DB&&(B-=this.DB)}x==8&&(p[0]&128)!=0&&(this.s=-1,B>0&&(this[this.t-1]|=(1<0&&this[this.t-1]==p;)--this.t}function O(p){if(this.s<0)return"-"+this.negate().toString(p);var f;if(p==16)f=4;else if(p==8)f=3;else if(p==2)f=1;else if(p==32)f=5;else if(p==4)f=2;else return this.toRadix(p);var x=(1<0)for(ee>ee)>0&&(A=!0,B=w(_));k>=0;)ee>(ee+=this.DB-f)):(_=this[k]>>(ee-=f)&x,ee<=0&&(ee+=this.DB,--k)),_>0&&(A=!0),A&&(B+=w(_));return A?B:"0"}function L(){var p=d();return h.ZERO.subTo(this,p),p}function X(){return this.s<0?this.negate():this}function z(p){var f=this.s-p.s;if(f!=0)return f;var x=this.t;if(f=x-p.t,f!=0)return this.s<0?-f:f;for(;--x>=0;)if((f=this[x]-p[x])!=0)return f;return 0}function H(p){var f=1,x;return(x=p>>>16)!=0&&(p=x,f+=16),(x=p>>8)!=0&&(p=x,f+=8),(x=p>>4)!=0&&(p=x,f+=4),(x=p>>2)!=0&&(p=x,f+=2),(x=p>>1)!=0&&(p=x,f+=1),f}function ue(){return this.t<=0?0:this.DB*(this.t-1)+H(this[this.t-1]^this.s&this.DM)}function ne(p,f){var x;for(x=this.t-1;x>=0;--x)f[x+p]=this[x];for(x=p-1;x>=0;--x)f[x]=0;f.t=this.t+p,f.s=this.s}function re(p,f){for(var x=p;x=0;--ee)f[ee+B+1]=this[ee]>>_|k,k=(this[ee]&A)<=0;--ee)f[ee]=0;f[B]=k,f.t=this.t+B+1,f.s=this.s,f.clamp()}function ge(p,f){f.s=this.s;var x=Math.floor(p/this.DB);if(x>=this.t){f.t=0;return}var _=p%this.DB,A=this.DB-_,B=(1<<_)-1;f[0]=this[x]>>_;for(var k=x+1;k>_;_>0&&(f[this.t-x-1]|=(this.s&B)<>=this.DB;if(p.t>=this.DB;_+=this.s}else{for(_+=this.s;x>=this.DB;_-=p.s}f.s=_<0?-1:0,_<-1?f[x++]=this.DV+_:_>0&&(f[x++]=_),f.t=x,f.clamp()}function oe(p,f){var x=this.abs(),_=p.abs(),A=x.t;for(f.t=A+_.t;--A>=0;)f[A]=0;for(A=0;A<_.t;++A)f[A+x.t]=x.am(0,_[A],f,A,0,x.t);f.s=0,f.clamp(),this.s!=p.s&&h.ZERO.subTo(f,f)}function Ae(p){for(var f=this.abs(),x=p.t=2*f.t;--x>=0;)p[x]=0;for(x=0;x=f.DV&&(p[x+f.t]-=f.DV,p[x+f.t+1]=1)}p.t>0&&(p[p.t-1]+=f.am(x,f[x],p,2*x,0,1)),p.s=0,p.clamp()}function Ie(p,f,x){var _=p.abs();if(!(_.t<=0)){var A=this.abs();if(A.t<_.t){f?.fromInt(0),x!=null&&this.copyTo(x);return}x==null&&(x=d());var B=d(),k=this.s,ee=p.s,te=this.DB-H(_[_.t-1]);te>0?(_.lShiftTo(te,B),A.lShiftTo(te,x)):(_.copyTo(B),A.copyTo(x));var me=B.t,Le=B[me-1];if(Le!=0){var Me=Le*(1<1?B[me-2]>>this.F2:0),Ge=this.FV/Me,xt=(1<=0&&(x[x.t++]=1,x.subTo(ks,x)),h.ONE.dlShiftTo(me,ks),ks.subTo(B,B);B.t=0;){var Qn=x[--Vt]==Le?this.DM:Math.floor(x[Vt]*Ge+(x[Vt-1]+kt)*xt);if((x[Vt]+=B.am(0,Qn,x,fr,0,me))0&&x.rShiftTo(te,x),k<0&&h.ZERO.subTo(x,x)}}}function Xe(p){var f=d();return this.abs().divRemTo(p,null,f),this.s<0&&f.compareTo(h.ZERO)>0&&p.subTo(f,f),f}function at(p){this.m=p}function W(p){return p.s<0||p.compareTo(this.m)>=0?p.mod(this.m):p}function j(p){return p}function G(p){p.divRemTo(this.m,null,p)}function ae(p,f,x){p.multiplyTo(f,x),this.reduce(x)}function be(p,f){p.squareTo(f),this.reduce(f)}at.prototype.convert=W,at.prototype.revert=j,at.prototype.reduce=G,at.prototype.mulTo=ae,at.prototype.sqrTo=be;function Be(){if(this.t<1)return 0;var p=this[0];if((p&1)==0)return 0;var f=p&3;return f=f*(2-(p&15)*f)&15,f=f*(2-(p&255)*f)&255,f=f*(2-((p&65535)*f&65535))&65535,f=f*(2-p*f%this.DV)%this.DV,f>0?this.DV-f:-f}function $(p){this.m=p,this.mp=p.invDigit(),this.mpl=this.mp&32767,this.mph=this.mp>>15,this.um=(1<0&&this.m.subTo(f,f),f}function J(p){var f=d();return p.copyTo(f),this.reduce(f),f}function q(p){for(;p.t<=this.mt2;)p[p.t++]=0;for(var f=0;f>15)*this.mpl&this.um)<<15)&p.DM;for(x=f+this.m.t,p[x]+=this.m.am(0,_,p,f,0,this.m.t);p[x]>=p.DV;)p[x]-=p.DV,p[++x]++}p.clamp(),p.drShiftTo(this.m.t,p),p.compareTo(this.m)>=0&&p.subTo(this.m,p)}function se(p,f){p.squareTo(f),this.reduce(f)}function pe(p,f,x){p.multiplyTo(f,x),this.reduce(x)}$.prototype.convert=U,$.prototype.revert=J,$.prototype.reduce=q,$.prototype.mulTo=pe,$.prototype.sqrTo=se;function Te(){return(this.t>0?this[0]&1:this.s)==0}function we(p,f){if(p>4294967295||p<1)return h.ONE;var x=d(),_=d(),A=f.convert(this),B=H(p)-1;for(A.copyTo(x);--B>=0;)if(f.sqrTo(x,_),(p&1<0)f.mulTo(_,A,x);else{var k=x;x=_,_=k}return f.revert(x)}function ie(p,f){var x;return p<256||f.isEven()?x=new at(f):x=new $(f),this.exp(p,x)}h.prototype.copyTo=C,h.prototype.fromInt=R,h.prototype.fromString=P,h.prototype.clamp=I,h.prototype.dlShiftTo=ne,h.prototype.drShiftTo=re,h.prototype.lShiftTo=ce,h.prototype.rShiftTo=ge,h.prototype.subTo=ye,h.prototype.multiplyTo=oe,h.prototype.squareTo=Ae,h.prototype.divRemTo=Ie,h.prototype.invDigit=Be,h.prototype.isEven=Te,h.prototype.exp=we,h.prototype.toString=O,h.prototype.negate=L,h.prototype.abs=X,h.prototype.compareTo=z,h.prototype.bitLength=ue,h.prototype.mod=Xe,h.prototype.modPowInt=ie,h.ZERO=E(0),h.ONE=E(1);function V(){var p=d();return this.copyTo(p),p}function Oe(){if(this.s<0){if(this.t==1)return this[0]-this.DV;if(this.t==0)return-1}else{if(this.t==1)return this[0];if(this.t==0)return 0}return(this[1]&(1<<32-this.DB)-1)<>24}function Je(){return this.t==0?this.s:this[0]<<16>>16}function ct(p){return Math.floor(Math.LN2*this.DB/Math.log(p))}function _e(){return this.s<0?-1:this.t<=0||this.t==1&&this[0]<=0?0:1}function nt(p){if(p==null&&(p=10),this.signum()==0||p<2||p>36)return"0";var f=this.chunkSize(p),x=Math.pow(p,f),_=E(x),A=d(),B=d(),k="";for(this.divRemTo(_,A,B);A.signum()>0;)k=(x+B.intValue()).toString(p).substr(1)+k,A.divRemTo(_,A,B);return B.intValue().toString(p)+k}function dt(p,f){this.fromInt(0),f==null&&(f=10);for(var x=this.chunkSize(f),_=Math.pow(f,x),A=!1,B=0,k=0,ee=0;ee=x&&(this.dMultiply(_),this.dAddOffset(k,0),B=0,k=0)}B>0&&(this.dMultiply(Math.pow(f,B)),this.dAddOffset(k,0)),A&&h.ZERO.subTo(this,this)}function ft(p,f,x){if(typeof f=="number")if(p<2)this.fromInt(1);else for(this.fromNumber(p,x),this.testBit(p-1)||this.bitwiseTo(h.ONE.shiftLeft(p-1),Tr,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(f);)this.dAddOffset(2,0),this.bitLength()>p&&this.subTo(h.ONE.shiftLeft(p-1),this);else{var _=new Array,A=p&7;_.length=(p>>3)+1,f.nextBytes(_),A>0?_[0]&=(1<0)for(x>x)!=(this.s&this.DM)>>x&&(f[A++]=_|this.s<=0;)x<8?(_=(this[p]&(1<>(x+=this.DB-8)):(_=this[p]>>(x-=8)&255,x<=0&&(x+=this.DB,--p)),(_&128)!=0&&(_|=-256),A==0&&(this.s&128)!=(_&128)&&++A,(A>0||_!=this.s)&&(f[A++]=_);return f}function it(p){return this.compareTo(p)==0}function Rt(p){return this.compareTo(p)<0?this:p}function Ft(p){return this.compareTo(p)>0?this:p}function Ze(p,f,x){var _,A,B=Math.min(p.t,this.t);for(_=0;_>=16,f+=16),(p&255)==0&&(p>>=8,f+=8),(p&15)==0&&(p>>=4,f+=4),(p&3)==0&&(p>>=2,f+=2),(p&1)==0&&++f,f}function xf(){for(var p=0;p=this.t?this.s!=0:(this[f]&1<>=this.DB;if(p.t>=this.DB;_+=this.s}else{for(_+=this.s;x>=this.DB;_+=p.s}f.s=_<0?-1:0,_>0?f[x++]=_:_<-1&&(f[x++]=this.DV+_),f.t=x,f.clamp()}function Wx(p){var f=d();return this.addTo(p,f),f}function Z2(p){var f=d();return this.subTo(p,f),f}function zc(p){var f=d();return this.multiplyTo(p,f),f}function jx(){var p=d();return this.squareTo(p),p}function Tf(p){var f=d();return this.divRemTo(p,f,null),f}function Hx(p){var f=d();return this.divRemTo(p,null,f),f}function J2(p){var f=d(),x=d();return this.divRemTo(p,f,x),new Array(f,x)}function Xx(p){this[this.t]=this.am(0,p-1,this,0,0,this.t),++this.t,this.clamp()}function $x(p,f){if(p!=0){for(;this.t<=f;)this[this.t++]=0;for(this[f]+=p;this[f]>=this.DV;)this[f]-=this.DV,++f>=this.t&&(this[this.t++]=0),++this[f]}}function hu(){}function Bh(p){return p}function Q2(p,f,x){p.multiplyTo(f,x)}function K2(p,f){p.squareTo(f)}hu.prototype.convert=Bh,hu.prototype.revert=Bh,hu.prototype.mulTo=Q2,hu.prototype.sqrTo=K2;function eM(p){return this.exp(p,new hu)}function Vc(p,f,x){var _=Math.min(this.t+p.t,f);for(x.s=0,x.t=_;_>0;)x[--_]=0;var A;for(A=x.t-this.t;_=0;)x[_]=0;for(_=Math.max(f-this.t,0);_2*this.m.t)return p.mod(this.m);if(p.compareTo(this.m)<0)return p;var f=d();return p.copyTo(f),this.reduce(f),f}function rM(p){return p}function iM(p){for(p.drShiftTo(this.m.t-1,this.r2),p.t>this.m.t+1&&(p.t=this.m.t+1,p.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);p.compareTo(this.r2)<0;)p.dAddOffset(1,this.m.t+1);for(p.subTo(this.r2,p);p.compareTo(this.m)>=0;)p.subTo(this.m,p)}function qx(p,f){p.squareTo(f),this.reduce(f)}function sM(p,f,x){p.multiplyTo(f,x),this.reduce(x)}du.prototype.convert=Sf,du.prototype.revert=rM,du.prototype.reduce=iM,du.prototype.mulTo=sM,du.prototype.sqrTo=qx;function _f(p,f){var x=p.bitLength(),_,A=E(1),B;if(x<=0)return A;x<18?_=1:x<48?_=3:x<144?_=4:x<768?_=5:_=6,x<8?B=new at(f):f.isEven()?B=new du(f):B=new $(f);var k=new Array,ee=3,te=_-1,me=(1<<_)-1;if(k[1]=B.convert(this),_>1){var Le=d();for(B.sqrTo(k[1],Le);ee<=me;)k[ee]=d(),B.mulTo(Le,k[ee-2],k[ee]),ee+=2}var Me=p.t-1,Ge,xt=!0,kt=d(),Vt;for(x=H(p[Me])-1;Me>=0;){for(x>=te?Ge=p[Me]>>x-te&me:(Ge=(p[Me]&(1<0&&(Ge|=p[Me-1]>>this.DB+x-te)),ee=_;(Ge&1)==0;)Ge>>=1,--ee;if((x-=ee)<0&&(x+=this.DB,--Me),xt)k[Ge].copyTo(A),xt=!1;else{for(;ee>1;)B.sqrTo(A,kt),B.sqrTo(kt,A),ee-=2;ee>0?B.sqrTo(A,kt):(Vt=A,A=kt,kt=Vt),B.mulTo(kt,k[Ge],A)}for(;Me>=0&&(p[Me]&1<0&&(f.rShiftTo(B,f),x.rShiftTo(B,x));f.signum()>0;)(A=f.getLowestSetBit())>0&&f.rShiftTo(A,f),(A=x.getLowestSetBit())>0&&x.rShiftTo(A,x),f.compareTo(x)>=0?(f.subTo(x,f),f.rShiftTo(1,f)):(x.subTo(f,x),x.rShiftTo(1,x));return B>0&&x.lShiftTo(B,x),x}function aM(p){if(p<=0)return 0;var f=this.DV%p,x=this.s<0?p-1:0;if(this.t>0)if(f==0)x=this[0]%p;else for(var _=this.t-1;_>=0;--_)x=(f*x+this[_])%p;return x}function wf(p){var f=p.isEven();if(this.isEven()&&f||p.signum()==0)return h.ZERO;for(var x=p.clone(),_=this.clone(),A=E(1),B=E(0),k=E(0),ee=E(1);x.signum()!=0;){for(;x.isEven();)x.rShiftTo(1,x),f?((!A.isEven()||!B.isEven())&&(A.addTo(this,A),B.subTo(p,B)),A.rShiftTo(1,A)):B.isEven()||B.subTo(p,B),B.rShiftTo(1,B);for(;_.isEven();)_.rShiftTo(1,_),f?((!k.isEven()||!ee.isEven())&&(k.addTo(this,k),ee.subTo(p,ee)),k.rShiftTo(1,k)):ee.isEven()||ee.subTo(p,ee),ee.rShiftTo(1,ee);x.compareTo(_)>=0?(x.subTo(_,x),f&&A.subTo(k,A),B.subTo(ee,B)):(_.subTo(x,_),f&&k.subTo(A,k),ee.subTo(B,ee))}if(_.compareTo(h.ONE)!=0)return h.ZERO;if(ee.compareTo(p)>=0)return ee.subtract(p);if(ee.signum()<0)ee.addTo(p,ee);else return ee;return ee.signum()<0?ee.add(p):ee}var vi=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997],nM=(1<<26)/vi[vi.length-1];function f0e(p){var f,x=this.abs();if(x.t==1&&x[0]<=vi[vi.length-1]){for(f=0;f>1,p>vi.length&&(p=vi.length);for(var A=d(),B=0;B0},Lt.op_LessThan=function(p,f){return p.compareTo(f)<0},Lt.op_Addition=function(p,f){return new Lt(p,void 0,void 0).add(new Lt(f,void 0,void 0))},Lt.op_Subtraction=function(p,f){return new Lt(p,void 0,void 0).subtract(new Lt(f,void 0,void 0))},Lt.Int128Mul=function(p,f){return new Lt(p,void 0,void 0).multiply(new Lt(f,void 0,void 0))},Lt.op_Division=function(p,f){return p.divide(f)},Lt.prototype.ToDouble=function(){return parseFloat(this.toString())};var Lk=function(p,f){var x;if(typeof Object.getOwnPropertyNames>"u"){for(x in f.prototype)(typeof p.prototype[x]>"u"||p.prototype[x]===Object.prototype[x])&&(p.prototype[x]=f.prototype[x]);for(x in f)typeof p[x]>"u"&&(p[x]=f[x]);p.$baseCtor=f}else{for(var _=Object.getOwnPropertyNames(f.prototype),A=0;A<_.length;A++)typeof Object.getOwnPropertyDescriptor(p.prototype,_[A])>"u"&&Object.defineProperty(p.prototype,_[A],Object.getOwnPropertyDescriptor(f.prototype,_[A]));for(x in f)typeof p[x]>"u"&&(p[x]=f[x]);p.$baseCtor=f}};r.Path=function(){return[]},r.Path.prototype.push=Array.prototype.push,r.Paths=function(){return[]},r.Paths.prototype.push=Array.prototype.push,r.DoublePoint=function(){var p=arguments;this.X=0,this.Y=0,p.length===1?(this.X=p[0].X,this.Y=p[0].Y):p.length===2&&(this.X=p[0],this.Y=p[1])},r.DoublePoint0=function(){this.X=0,this.Y=0},r.DoublePoint0.prototype=r.DoublePoint.prototype,r.DoublePoint1=function(p){this.X=p.X,this.Y=p.Y},r.DoublePoint1.prototype=r.DoublePoint.prototype,r.DoublePoint2=function(p,f){this.X=p,this.Y=f},r.DoublePoint2.prototype=r.DoublePoint.prototype,r.PolyNode=function(){this.m_Parent=null,this.m_polygon=new r.Path,this.m_Index=0,this.m_jointype=0,this.m_endtype=0,this.m_Childs=[],this.IsOpen=!1},r.PolyNode.prototype.IsHoleNode=function(){for(var p=!0,f=this.m_Parent;f!==null;)p=!p,f=f.m_Parent;return p},r.PolyNode.prototype.ChildCount=function(){return this.m_Childs.length},r.PolyNode.prototype.Contour=function(){return this.m_polygon},r.PolyNode.prototype.AddChild=function(p){var f=this.m_Childs.length;this.m_Childs.push(p),p.m_Parent=this,p.m_Index=f},r.PolyNode.prototype.GetNext=function(){return this.m_Childs.length>0?this.m_Childs[0]:this.GetNextSiblingUp()},r.PolyNode.prototype.GetNextSiblingUp=function(){return this.m_Parent===null?null:this.m_Index===this.m_Parent.m_Childs.length-1?this.m_Parent.GetNextSiblingUp():this.m_Parent.m_Childs[this.m_Index+1]},r.PolyNode.prototype.Childs=function(){return this.m_Childs},r.PolyNode.prototype.Parent=function(){return this.m_Parent},r.PolyNode.prototype.IsHole=function(){return this.IsHoleNode()},r.PolyTree=function(){this.m_AllPolys=[],r.PolyNode.call(this)},r.PolyTree.prototype.Clear=function(){for(var p=0,f=this.m_AllPolys.length;p0?this.m_Childs[0]:null},r.PolyTree.prototype.Total=function(){var p=this.m_AllPolys.length;return p>0&&this.m_Childs[0]!==this.m_AllPolys[0]&&p--,p},Lk(r.PolyTree,r.PolyNode),r.Math_Abs_Int64=r.Math_Abs_Int32=r.Math_Abs_Double=function(p){return Math.abs(p)},r.Math_Max_Int32_Int32=function(p,f){return Math.max(p,f)},n.msie||n.opera||n.safari?r.Cast_Int32=function(p){return p|0}:r.Cast_Int32=function(p){return~~p},typeof Number.toInteger>"u"&&(Number.toInteger=null),n.chrome?r.Cast_Int64=function(p){return p<-2147483648||p>2147483647?p<0?Math.ceil(p):Math.floor(p):~~p}:n.firefox&&typeof Number.toInteger=="function"?r.Cast_Int64=function(p){return Number.toInteger(p)}:n.msie7||n.msie8?r.Cast_Int64=function(p){return parseInt(p,10)}:n.msie?r.Cast_Int64=function(p){return p<-2147483648||p>2147483647?p<0?Math.ceil(p):Math.floor(p):p|0}:r.Cast_Int64=function(p){return p<0?Math.ceil(p):Math.floor(p)},r.Clear=function(p){p.length=0},r.PI=3.141592653589793,r.PI2=2*3.141592653589793,r.IntPoint=function(){var p=arguments,f=p.length;if(this.X=0,this.Y=0,r.use_xyz)if(this.Z=0,f===3)this.X=p[0],this.Y=p[1],this.Z=p[2];else if(f===2)this.X=p[0],this.Y=p[1],this.Z=0;else if(f===1)if(p[0]instanceof r.DoublePoint){var x=p[0];this.X=r.Clipper.Round(x.X),this.Y=r.Clipper.Round(x.Y),this.Z=0}else{var _=p[0];typeof _.Z>"u"&&(_.Z=0),this.X=_.X,this.Y=_.Y,this.Z=_.Z}else this.X=0,this.Y=0,this.Z=0;else if(f===2)this.X=p[0],this.Y=p[1];else if(f===1)if(p[0]instanceof r.DoublePoint){var x=p[0];this.X=r.Clipper.Round(x.X),this.Y=r.Clipper.Round(x.Y)}else{var _=p[0];this.X=_.X,this.Y=_.Y}else this.X=0,this.Y=0},r.IntPoint.op_Equality=function(p,f){return p.X===f.X&&p.Y===f.Y},r.IntPoint.op_Inequality=function(p,f){return p.X!==f.X||p.Y!==f.Y},r.IntPoint0=function(){this.X=0,this.Y=0,r.use_xyz&&(this.Z=0)},r.IntPoint0.prototype=r.IntPoint.prototype,r.IntPoint1=function(p){this.X=p.X,this.Y=p.Y,r.use_xyz&&(typeof p.Z>"u"?this.Z=0:this.Z=p.Z)},r.IntPoint1.prototype=r.IntPoint.prototype,r.IntPoint1dp=function(p){this.X=r.Clipper.Round(p.X),this.Y=r.Clipper.Round(p.Y),r.use_xyz&&(this.Z=0)},r.IntPoint1dp.prototype=r.IntPoint.prototype,r.IntPoint2=function(p,f,x){this.X=p,this.Y=f,r.use_xyz&&(typeof x>"u"?this.Z=0:this.Z=x)},r.IntPoint2.prototype=r.IntPoint.prototype,r.IntRect=function(){var p=arguments,f=p.length;if(f===4)this.left=p[0],this.top=p[1],this.right=p[2],this.bottom=p[3];else if(f===1){var x=p[0];this.left=x.left,this.top=x.top,this.right=x.right,this.bottom=x.bottom}else this.left=0,this.top=0,this.right=0,this.bottom=0},r.IntRect0=function(){this.left=0,this.top=0,this.right=0,this.bottom=0},r.IntRect0.prototype=r.IntRect.prototype,r.IntRect1=function(p){this.left=p.left,this.top=p.top,this.right=p.right,this.bottom=p.bottom},r.IntRect1.prototype=r.IntRect.prototype,r.IntRect4=function(p,f,x,_){this.left=p,this.top=f,this.right=x,this.bottom=_},r.IntRect4.prototype=r.IntRect.prototype,r.ClipType={ctIntersection:0,ctUnion:1,ctDifference:2,ctXor:3},r.PolyType={ptSubject:0,ptClip:1},r.PolyFillType={pftEvenOdd:0,pftNonZero:1,pftPositive:2,pftNegative:3},r.JoinType={jtSquare:0,jtRound:1,jtMiter:2},r.EndType={etOpenSquare:0,etOpenRound:1,etOpenButt:2,etClosedLine:3,etClosedPolygon:4},r.EdgeSide={esLeft:0,esRight:1},r.Direction={dRightToLeft:0,dLeftToRight:1},r.TEdge=function(){this.Bot=new r.IntPoint0,this.Curr=new r.IntPoint0,this.Top=new r.IntPoint0,this.Delta=new r.IntPoint0,this.Dx=0,this.PolyTyp=r.PolyType.ptSubject,this.Side=r.EdgeSide.esLeft,this.WindDelta=0,this.WindCnt=0,this.WindCnt2=0,this.OutIdx=0,this.Next=null,this.Prev=null,this.NextInLML=null,this.NextInAEL=null,this.PrevInAEL=null,this.NextInSEL=null,this.PrevInSEL=null},r.IntersectNode=function(){this.Edge1=null,this.Edge2=null,this.Pt=new r.IntPoint0},r.MyIntersectNodeSort=function(){},r.MyIntersectNodeSort.Compare=function(p,f){var x=f.Pt.Y-p.Pt.Y;return x>0?1:x<0?-1:0},r.LocalMinima=function(){this.Y=0,this.LeftBound=null,this.RightBound=null,this.Next=null},r.Scanbeam=function(){this.Y=0,this.Next=null},r.Maxima=function(){this.X=0,this.Next=null,this.Prev=null},r.OutRec=function(){this.Idx=0,this.IsHole=!1,this.IsOpen=!1,this.FirstLeft=null,this.Pts=null,this.BottomPt=null,this.PolyNode=null},r.OutPt=function(){this.Idx=0,this.Pt=new r.IntPoint0,this.Next=null,this.Prev=null},r.Join=function(){this.OutPt1=null,this.OutPt2=null,this.OffPt=new r.IntPoint0},r.ClipperBase=function(){this.m_MinimaList=null,this.m_CurrentLM=null,this.m_edges=new Array,this.m_UseFullRange=!1,this.m_HasOpenPaths=!1,this.PreserveCollinear=!1,this.m_Scanbeam=null,this.m_PolyOuts=null,this.m_ActiveEdges=null},r.ClipperBase.horizontal=-9007199254740992,r.ClipperBase.Skip=-2,r.ClipperBase.Unassigned=-1,r.ClipperBase.tolerance=1e-20,r.ClipperBase.loRange=47453132,r.ClipperBase.hiRange=0xfffffffffffff,r.ClipperBase.near_zero=function(p){return p>-r.ClipperBase.tolerance&&pf.X==p.Xf.Y==p.Yf.X==p.Xf.Y==p.Yr.ClipperBase.hiRange||p.Y>r.ClipperBase.hiRange||-p.X>r.ClipperBase.hiRange||-p.Y>r.ClipperBase.hiRange)&&r.Error("Coordinate outside allowed range in RangeTest()."):(p.X>r.ClipperBase.loRange||p.Y>r.ClipperBase.loRange||-p.X>r.ClipperBase.loRange||-p.Y>r.ClipperBase.loRange)&&(f.Value=!0,this.RangeTest(p,f))},r.ClipperBase.prototype.InitEdge=function(p,f,x,_){p.Next=f,p.Prev=x,p.Curr.X=_.X,p.Curr.Y=_.Y,r.use_xyz&&(p.Curr.Z=_.Z),p.OutIdx=-1},r.ClipperBase.prototype.InitEdge2=function(p,f){p.Curr.Y>=p.Next.Curr.Y?(p.Bot.X=p.Curr.X,p.Bot.Y=p.Curr.Y,r.use_xyz&&(p.Bot.Z=p.Curr.Z),p.Top.X=p.Next.Curr.X,p.Top.Y=p.Next.Curr.Y,r.use_xyz&&(p.Top.Z=p.Next.Curr.Z)):(p.Top.X=p.Curr.X,p.Top.Y=p.Curr.Y,r.use_xyz&&(p.Top.Z=p.Curr.Z),p.Bot.X=p.Next.Curr.X,p.Bot.Y=p.Next.Curr.Y,r.use_xyz&&(p.Bot.Z=p.Next.Curr.Z)),this.SetDx(p),p.PolyTyp=f},r.ClipperBase.prototype.FindNextLocMin=function(p){for(var f;;){for(;r.IntPoint.op_Inequality(p.Bot,p.Prev.Bot)||r.IntPoint.op_Equality(p.Curr,p.Top);)p=p.Next;if(p.Dx!==r.ClipperBase.horizontal&&p.Prev.Dx!==r.ClipperBase.horizontal)break;for(;p.Prev.Dx===r.ClipperBase.horizontal;)p=p.Prev;for(f=p;p.Dx===r.ClipperBase.horizontal;)p=p.Next;if(p.Top.Y!==p.Prev.Bot.Y){f.Prev.Bot.X_.Next.Top.X&&(_=A.Prev)}for(;p!==_;)p.NextInLML=p.Next,p.Dx===r.ClipperBase.horizontal&&p!==x&&p.Bot.X!==p.Prev.Top.X&&this.ReverseHorizontal(p),p=p.Next;p.Dx===r.ClipperBase.horizontal&&p!==x&&p.Bot.X!==p.Prev.Top.X&&this.ReverseHorizontal(p),_=_.Next}else{for(;_.Top.Y===_.Prev.Bot.Y&&_.Prev.OutIdx!==r.ClipperBase.Skip;)_=_.Prev;if(_.Dx===r.ClipperBase.horizontal&&_.Prev.OutIdx!==r.ClipperBase.Skip){for(A=_;A.Next.Dx===r.ClipperBase.horizontal;)A=A.Next;(A.Next.Top.X===_.Prev.Top.X||A.Next.Top.X>_.Prev.Top.X)&&(_=A.Next)}for(;p!==_;)p.NextInLML=p.Prev,p.Dx===r.ClipperBase.horizontal&&p!==x&&p.Bot.X!==p.Next.Top.X&&this.ReverseHorizontal(p),p=p.Prev;p.Dx===r.ClipperBase.horizontal&&p!==x&&p.Bot.X!==p.Next.Top.X&&this.ReverseHorizontal(p),_=_.Prev}return _},r.ClipperBase.prototype.AddPath=function(p,f,x){r.use_lines?!x&&f===r.PolyType.ptClip&&r.Error("AddPath: Open paths must be subject."):x||r.Error("AddPath: Open paths have been disabled.");var _=p.length-1;if(x)for(;_>0&&r.IntPoint.op_Equality(p[_],p[0]);)--_;for(;_>0&&r.IntPoint.op_Equality(p[_],p[_-1]);)--_;if(x&&_<2||!x&&_<1)return!1;for(var A=new Array,B=0;B<=_;B++)A.push(new r.TEdge);var k=!0;A[1].Curr.X=p[1].X,A[1].Curr.Y=p[1].Y,r.use_xyz&&(A[1].Curr.Z=p[1].Z);var ee={Value:this.m_UseFullRange};this.RangeTest(p[0],ee),this.m_UseFullRange=ee.Value,ee.Value=this.m_UseFullRange,this.RangeTest(p[_],ee),this.m_UseFullRange=ee.Value,this.InitEdge(A[0],A[1],A[_],p[0]),this.InitEdge(A[_],A[0],A[_-1],p[_]);for(var B=_-1;B>=1;--B)ee.Value=this.m_UseFullRange,this.RangeTest(p[B],ee),this.m_UseFullRange=ee.Value,this.InitEdge(A[B],A[B+1],A[B-1],p[B]);for(var te=A[0],me=te,Le=te;;){if(me.Curr===me.Next.Curr&&(x||me.Next!==te)){if(me===me.Next)break;me===te&&(te=me.Next),me=this.RemoveEdge(me),Le=me;continue}if(me.Prev===me.Next)break;if(x&&r.ClipperBase.SlopesEqual4(me.Prev.Curr,me.Curr,me.Next.Curr,this.m_UseFullRange)&&(!this.PreserveCollinear||!this.Pt2IsBetweenPt1AndPt3(me.Prev.Curr,me.Curr,me.Next.Curr))){me===te&&(te=me.Next),me=this.RemoveEdge(me),me=me.Prev,Le=me;continue}if(me=me.Next,me===Le||!x&&me.Next===te)break}if(!x&&me===me.Next||x&&me.Prev===me.Next)return!1;x||(this.m_HasOpenPaths=!0,te.Prev.OutIdx=r.ClipperBase.Skip),me=te;do this.InitEdge2(me,f),me=me.Next,k&&me.Curr.Y!==te.Curr.Y&&(k=!1);while(me!==te);if(k){if(x)return!1;me.Prev.OutIdx=r.ClipperBase.Skip;var Me=new r.LocalMinima;for(Me.Next=null,Me.Y=me.Bot.Y,Me.LeftBound=null,Me.RightBound=me,Me.RightBound.Side=r.EdgeSide.esRight,Me.RightBound.WindDelta=0;me.Bot.X!==me.Prev.Top.X&&this.ReverseHorizontal(me),me.Next.OutIdx!==r.ClipperBase.Skip;)me.NextInLML=me.Next,me=me.Next;return this.InsertLocalMinima(Me),this.m_edges.push(A),!0}this.m_edges.push(A);var Ge,xt=null;for(r.IntPoint.op_Equality(me.Prev.Bot,me.Prev.Top)&&(me=me.Next);me=this.FindNextLocMin(me),me!==xt;){xt===null&&(xt=me);var Me=new r.LocalMinima;Me.Next=null,Me.Y=me.Bot.Y,me.Dxp.X==f.Xp.Y==f.Y=this.m_MinimaList.Y)p.Next=this.m_MinimaList,this.m_MinimaList=p;else{for(var f=this.m_MinimaList;f.Next!==null&&p.Ythis.m_Scanbeam.Y){var f=new r.Scanbeam;f.Y=p,f.Next=this.m_Scanbeam,this.m_Scanbeam=f}else{for(var x=this.m_Scanbeam;x.Next!==null&&p<=x.Next.Y;)x=x.Next;if(p===x.Y)return;var _=new r.Scanbeam;_.Y=p,_.Next=x.Next,x.Next=_}},r.ClipperBase.prototype.PopScanbeam=function(p){return this.m_Scanbeam===null?(p.v=0,!1):(p.v=this.m_Scanbeam.Y,this.m_Scanbeam=this.m_Scanbeam.Next,!0)},r.ClipperBase.prototype.LocalMinimaPending=function(){return this.m_CurrentLM!==null},r.ClipperBase.prototype.CreateOutRec=function(){var p=new r.OutRec;return p.Idx=r.ClipperBase.Unassigned,p.IsHole=!1,p.IsOpen=!1,p.FirstLeft=null,p.Pts=null,p.BottomPt=null,p.PolyNode=null,this.m_PolyOuts.push(p),p.Idx=this.m_PolyOuts.length-1,p},r.ClipperBase.prototype.DisposeOutRec=function(p){var f=this.m_PolyOuts[p];f.Pts=null,f=null,this.m_PolyOuts[p]=null},r.ClipperBase.prototype.UpdateEdgeIntoAEL=function(p){p.NextInLML===null&&r.Error("UpdateEdgeIntoAEL: invalid call");var f=p.PrevInAEL,x=p.NextInAEL;return p.NextInLML.OutIdx=p.OutIdx,f!==null?f.NextInAEL=p.NextInLML:this.m_ActiveEdges=p.NextInLML,x!==null&&(x.PrevInAEL=p.NextInLML),p.NextInLML.Side=p.Side,p.NextInLML.WindDelta=p.WindDelta,p.NextInLML.WindCnt=p.WindCnt,p.NextInLML.WindCnt2=p.WindCnt2,p=p.NextInLML,p.Curr.X=p.Bot.X,p.Curr.Y=p.Bot.Y,p.PrevInAEL=f,p.NextInAEL=x,r.ClipperBase.IsHorizontal(p)||this.InsertScanbeam(p.Top.Y),p},r.ClipperBase.prototype.SwapPositionsInAEL=function(p,f){if(!(p.NextInAEL===p.PrevInAEL||f.NextInAEL===f.PrevInAEL)){if(p.NextInAEL===f){var x=f.NextInAEL;x!==null&&(x.PrevInAEL=p);var _=p.PrevInAEL;_!==null&&(_.NextInAEL=f),f.PrevInAEL=_,f.NextInAEL=p,p.PrevInAEL=f,p.NextInAEL=x}else if(f.NextInAEL===p){var A=p.NextInAEL;A!==null&&(A.PrevInAEL=f);var B=f.PrevInAEL;B!==null&&(B.NextInAEL=p),p.PrevInAEL=B,p.NextInAEL=f,f.PrevInAEL=p,f.NextInAEL=A}else{var k=p.NextInAEL,ee=p.PrevInAEL;p.NextInAEL=f.NextInAEL,p.NextInAEL!==null&&(p.NextInAEL.PrevInAEL=p),p.PrevInAEL=f.PrevInAEL,p.PrevInAEL!==null&&(p.PrevInAEL.NextInAEL=p),f.NextInAEL=k,f.NextInAEL!==null&&(f.NextInAEL.PrevInAEL=f),f.PrevInAEL=ee,f.PrevInAEL!==null&&(f.PrevInAEL.NextInAEL=f)}p.PrevInAEL===null?this.m_ActiveEdges=p:f.PrevInAEL===null&&(this.m_ActiveEdges=f)}},r.ClipperBase.prototype.DeleteFromAEL=function(p){var f=p.PrevInAEL,x=p.NextInAEL;f===null&&x===null&&p!==this.m_ActiveEdges||(f!==null?f.NextInAEL=x:this.m_ActiveEdges=x,x!==null&&(x.PrevInAEL=f),p.NextInAEL=null,p.PrevInAEL=null)},r.Clipper=function(p){typeof p>"u"&&(p=0),this.m_PolyOuts=null,this.m_ClipType=r.ClipType.ctIntersection,this.m_Scanbeam=null,this.m_Maxima=null,this.m_ActiveEdges=null,this.m_SortedEdges=null,this.m_IntersectList=null,this.m_IntersectNodeComparer=null,this.m_ExecuteLocked=!1,this.m_ClipFillType=r.PolyFillType.pftEvenOdd,this.m_SubjFillType=r.PolyFillType.pftEvenOdd,this.m_Joins=null,this.m_GhostJoins=null,this.m_UsingPolyTree=!1,this.ReverseSolution=!1,this.StrictlySimple=!1,r.ClipperBase.call(this),this.m_Scanbeam=null,this.m_Maxima=null,this.m_ActiveEdges=null,this.m_SortedEdges=null,this.m_IntersectList=new Array,this.m_IntersectNodeComparer=r.MyIntersectNodeSort.Compare,this.m_ExecuteLocked=!1,this.m_UsingPolyTree=!1,this.m_PolyOuts=new Array,this.m_Joins=new Array,this.m_GhostJoins=new Array,this.ReverseSolution=(1&p)!==0,this.StrictlySimple=(2&p)!==0,this.PreserveCollinear=(4&p)!==0,r.use_xyz&&(this.ZFillFunction=null)},r.Clipper.ioReverseSolution=1,r.Clipper.ioStrictlySimple=2,r.Clipper.ioPreserveCollinear=4,r.Clipper.prototype.Clear=function(){this.m_edges.length!==0&&(this.DisposeAllPolyPts(),r.ClipperBase.prototype.Clear.call(this))},r.Clipper.prototype.InsertMaxima=function(p){var f=new r.Maxima;if(f.X=p,this.m_Maxima===null)this.m_Maxima=f,this.m_Maxima.Next=null,this.m_Maxima.Prev=null;else if(p=x.Next.X;)x=x.Next;if(p===x.X)return;f.Next=x.Next,f.Prev=x,x.Next!==null&&(x.Next.Prev=f),x.Next=f}},r.Clipper.prototype.Execute=function(){var p=arguments,f=p.length,x=p[1]instanceof r.PolyTree;if(f===4&&!x){var _=p[0],A=p[1],B=p[2],k=p[3];if(this.m_ExecuteLocked)return!1;this.m_HasOpenPaths&&r.Error("Error: PolyTree struct is needed for open path clipping."),this.m_ExecuteLocked=!0,r.Clear(A),this.m_SubjFillType=B,this.m_ClipFillType=k,this.m_ClipType=_,this.m_UsingPolyTree=!1;try{var ee=this.ExecuteInternal();ee&&this.BuildResult(A)}finally{this.DisposeAllPolyPts(),this.m_ExecuteLocked=!1}return ee}else if(f===4&&x){var _=p[0],te=p[1],B=p[2],k=p[3];if(this.m_ExecuteLocked)return!1;this.m_ExecuteLocked=!0,this.m_SubjFillType=B,this.m_ClipFillType=k,this.m_ClipType=_,this.m_UsingPolyTree=!0;try{var ee=this.ExecuteInternal();ee&&this.BuildResult2(te)}finally{this.DisposeAllPolyPts(),this.m_ExecuteLocked=!1}return ee}else if(f===2&&!x){var _=p[0],A=p[1];return this.Execute(_,A,r.PolyFillType.pftEvenOdd,r.PolyFillType.pftEvenOdd)}else if(f===2&&x){var _=p[0],te=p[1];return this.Execute(_,te,r.PolyFillType.pftEvenOdd,r.PolyFillType.pftEvenOdd)}},r.Clipper.prototype.FixHoleLinkage=function(p){if(!(p.FirstLeft===null||p.IsHole!==p.FirstLeft.IsHole&&p.FirstLeft.Pts!==null)){for(var f=p.FirstLeft;f!==null&&(f.IsHole===p.IsHole||f.Pts===null);)f=f.FirstLeft;p.FirstLeft=f}},r.Clipper.prototype.ExecuteInternal=function(){try{this.Reset(),this.m_SortedEdges=null,this.m_Maxima=null;var p={},f={};if(!this.PopScanbeam(p))return!1;for(this.InsertLocalMinimaIntoAEL(p.v);this.PopScanbeam(f)||this.LocalMinimaPending();){if(this.ProcessHorizontals(),this.m_GhostJoins.length=0,!this.ProcessIntersections(f.v))return!1;this.ProcessEdgesAtTopOfScanbeam(f.v),p.v=f.v,this.InsertLocalMinimaIntoAEL(p.v)}var x,_,A;for(_=0,A=this.m_PolyOuts.length;_0&&this.ReversePolyPtLinks(x.Pts);for(this.JoinCommonEdges(),_=0,A=this.m_PolyOuts.length;_0&&_.WindDelta!==0)for(var B=0,k=this.m_GhostJoins.length;B=0&&x.PrevInAEL!==null&&x.PrevInAEL.Curr.X===x.Bot.X&&x.PrevInAEL.OutIdx>=0&&r.ClipperBase.SlopesEqual5(x.PrevInAEL.Curr,x.PrevInAEL.Top,x.Curr,x.Top,this.m_UseFullRange)&&x.WindDelta!==0&&x.PrevInAEL.WindDelta!==0){var te=this.AddOutPt(x.PrevInAEL,x.Bot);this.AddJoin(A,te,x.Top)}if(x.NextInAEL!==_){if(_.OutIdx>=0&&_.PrevInAEL.OutIdx>=0&&r.ClipperBase.SlopesEqual5(_.PrevInAEL.Curr,_.PrevInAEL.Top,_.Curr,_.Top,this.m_UseFullRange)&&_.WindDelta!==0&&_.PrevInAEL.WindDelta!==0){var te=this.AddOutPt(_.PrevInAEL,_.Bot);this.AddJoin(A,te,_.Top)}var me=x.NextInAEL;if(me!==null)for(;me!==_;)this.IntersectEdges(_,me,x.Curr),me=me.NextInAEL}}}},r.Clipper.prototype.InsertEdgeIntoAEL=function(p,f){if(this.m_ActiveEdges===null)p.PrevInAEL=null,p.NextInAEL=null,this.m_ActiveEdges=p;else if(f===null&&this.E2InsertsBeforeE1(this.m_ActiveEdges,p))p.PrevInAEL=null,p.NextInAEL=this.m_ActiveEdges,this.m_ActiveEdges.PrevInAEL=p,this.m_ActiveEdges=p;else{for(f===null&&(f=this.m_ActiveEdges);f.NextInAEL!==null&&!this.E2InsertsBeforeE1(f.NextInAEL,p);)f=f.NextInAEL;p.NextInAEL=f.NextInAEL,f.NextInAEL!==null&&(f.NextInAEL.PrevInAEL=p),p.PrevInAEL=f,f.NextInAEL=p}},r.Clipper.prototype.E2InsertsBeforeE1=function(p,f){return f.Curr.X===p.Curr.X?f.Top.Y>p.Top.Y?f.Top.Xr.Clipper.TopX(f,p.Top.Y):f.Curr.X0;default:return p.WindCnt2<0}case r.ClipType.ctUnion:switch(x){case r.PolyFillType.pftEvenOdd:case r.PolyFillType.pftNonZero:return p.WindCnt2===0;case r.PolyFillType.pftPositive:return p.WindCnt2<=0;default:return p.WindCnt2>=0}case r.ClipType.ctDifference:if(p.PolyTyp===r.PolyType.ptSubject)switch(x){case r.PolyFillType.pftEvenOdd:case r.PolyFillType.pftNonZero:return p.WindCnt2===0;case r.PolyFillType.pftPositive:return p.WindCnt2<=0;default:return p.WindCnt2>=0}else switch(x){case r.PolyFillType.pftEvenOdd:case r.PolyFillType.pftNonZero:return p.WindCnt2!==0;case r.PolyFillType.pftPositive:return p.WindCnt2>0;default:return p.WindCnt2<0}case r.ClipType.ctXor:if(p.WindDelta===0)switch(x){case r.PolyFillType.pftEvenOdd:case r.PolyFillType.pftNonZero:return p.WindCnt2===0;case r.PolyFillType.pftPositive:return p.WindCnt2<=0;default:return p.WindCnt2>=0}else return!0}return!0},r.Clipper.prototype.SetWindingCount=function(p){for(var f=p.PrevInAEL;f!==null&&(f.PolyTyp!==p.PolyTyp||f.WindDelta===0);)f=f.PrevInAEL;if(f===null){var x=p.PolyTyp===r.PolyType.ptSubject?this.m_SubjFillType:this.m_ClipFillType;p.WindDelta===0?p.WindCnt=x===r.PolyFillType.pftNegative?-1:1:p.WindCnt=p.WindDelta,p.WindCnt2=0,f=this.m_ActiveEdges}else if(p.WindDelta===0&&this.m_ClipType!==r.ClipType.ctUnion)p.WindCnt=1,p.WindCnt2=f.WindCnt2,f=f.NextInAEL;else if(this.IsEvenOddFillType(p)){if(p.WindDelta===0){for(var _=!0,A=f.PrevInAEL;A!==null;)A.PolyTyp===f.PolyTyp&&A.WindDelta!==0&&(_=!_),A=A.PrevInAEL;p.WindCnt=_?0:1}else p.WindCnt=p.WindDelta;p.WindCnt2=f.WindCnt2,f=f.NextInAEL}else f.WindCnt*f.WindDelta<0?Math.abs(f.WindCnt)>1?f.WindDelta*p.WindDelta<0?p.WindCnt=f.WindCnt:p.WindCnt=f.WindCnt+p.WindDelta:p.WindCnt=p.WindDelta===0?1:p.WindDelta:p.WindDelta===0?p.WindCnt=f.WindCnt<0?f.WindCnt-1:f.WindCnt+1:f.WindDelta*p.WindDelta<0?p.WindCnt=f.WindCnt:p.WindCnt=f.WindCnt+p.WindDelta,p.WindCnt2=f.WindCnt2,f=f.NextInAEL;if(this.IsEvenOddAltFillType(p))for(;f!==p;)f.WindDelta!==0&&(p.WindCnt2=p.WindCnt2===0?1:0),f=f.NextInAEL;else for(;f!==p;)p.WindCnt2+=f.WindDelta,f=f.NextInAEL},r.Clipper.prototype.AddEdgeToSEL=function(p){this.m_SortedEdges===null?(this.m_SortedEdges=p,p.PrevInSEL=null,p.NextInSEL=null):(p.NextInSEL=this.m_SortedEdges,p.PrevInSEL=null,this.m_SortedEdges.PrevInSEL=p,this.m_SortedEdges=p)},r.Clipper.prototype.PopEdgeFromSEL=function(p){if(p.v=this.m_SortedEdges,p.v===null)return!1;var f=p.v;return this.m_SortedEdges=p.v.NextInSEL,this.m_SortedEdges!==null&&(this.m_SortedEdges.PrevInSEL=null),f.NextInSEL=null,f.PrevInSEL=null,!0},r.Clipper.prototype.CopyAELToSEL=function(){var p=this.m_ActiveEdges;for(this.m_SortedEdges=p;p!==null;)p.PrevInSEL=p.PrevInAEL,p.NextInSEL=p.NextInAEL,p=p.NextInAEL},r.Clipper.prototype.SwapPositionsInSEL=function(p,f){if(!(p.NextInSEL===null&&p.PrevInSEL===null)&&!(f.NextInSEL===null&&f.PrevInSEL===null)){if(p.NextInSEL===f){var x=f.NextInSEL;x!==null&&(x.PrevInSEL=p);var _=p.PrevInSEL;_!==null&&(_.NextInSEL=f),f.PrevInSEL=_,f.NextInSEL=p,p.PrevInSEL=f,p.NextInSEL=x}else if(f.NextInSEL===p){var x=p.NextInSEL;x!==null&&(x.PrevInSEL=f);var _=f.PrevInSEL;_!==null&&(_.NextInSEL=p),p.PrevInSEL=_,p.NextInSEL=f,f.PrevInSEL=p,f.NextInSEL=x}else{var x=p.NextInSEL,_=p.PrevInSEL;p.NextInSEL=f.NextInSEL,p.NextInSEL!==null&&(p.NextInSEL.PrevInSEL=p),p.PrevInSEL=f.PrevInSEL,p.PrevInSEL!==null&&(p.PrevInSEL.NextInSEL=p),f.NextInSEL=x,f.NextInSEL!==null&&(f.NextInSEL.PrevInSEL=f),f.PrevInSEL=_,f.PrevInSEL!==null&&(f.PrevInSEL.NextInSEL=f)}p.PrevInSEL===null?this.m_SortedEdges=p:f.PrevInSEL===null&&(this.m_SortedEdges=f)}},r.Clipper.prototype.AddLocalMaxPoly=function(p,f,x){this.AddOutPt(p,x),f.WindDelta===0&&this.AddOutPt(f,x),p.OutIdx===f.OutIdx?(p.OutIdx=-1,f.OutIdx=-1):p.OutIdxf.Dx?(_=this.AddOutPt(p,x),f.OutIdx=p.OutIdx,p.Side=r.EdgeSide.esLeft,f.Side=r.EdgeSide.esRight,A=p,A.PrevInAEL===f?B=f.PrevInAEL:B=A.PrevInAEL):(_=this.AddOutPt(f,x),p.OutIdx=f.OutIdx,p.Side=r.EdgeSide.esRight,f.Side=r.EdgeSide.esLeft,A=f,A.PrevInAEL===p?B=p.PrevInAEL:B=A.PrevInAEL),B!==null&&B.OutIdx>=0&&B.Top.Yf&&(A=p,p=f,f=A),x>_&&(A=x,x=_,_=A),p<_&&x=0&&x.WindDelta!==0&&(_===null?_=x:_.OutIdx===x.OutIdx&&(_=null)),x=x.PrevInAEL;_===null?(f.FirstLeft=null,f.IsHole=!1):(f.FirstLeft=this.m_PolyOuts[_.OutIdx],f.IsHole=!f.FirstLeft.IsHole)},r.Clipper.prototype.GetDx=function(p,f){return p.Y===f.Y?r.ClipperBase.horizontal:(f.X-p.X)/(f.Y-p.Y)},r.Clipper.prototype.FirstIsBottomPt=function(p,f){for(var x=p.Prev;r.IntPoint.op_Equality(x.Pt,p.Pt)&&x!==p;)x=x.Prev;var _=Math.abs(this.GetDx(p.Pt,x.Pt));for(x=p.Next;r.IntPoint.op_Equality(x.Pt,p.Pt)&&x!==p;)x=x.Next;var A=Math.abs(this.GetDx(p.Pt,x.Pt));for(x=f.Prev;r.IntPoint.op_Equality(x.Pt,f.Pt)&&x!==f;)x=x.Prev;var B=Math.abs(this.GetDx(f.Pt,x.Pt));for(x=f.Next;r.IntPoint.op_Equality(x.Pt,f.Pt)&&x!==f;)x=x.Next;var k=Math.abs(this.GetDx(f.Pt,x.Pt));return Math.max(_,A)===Math.max(B,k)&&Math.min(_,A)===Math.min(B,k)?this.Area(p)>0:_>=B&&_>=k||A>=B&&A>=k},r.Clipper.prototype.GetBottomPt=function(p){for(var f=null,x=p.Next;x!==p;)x.Pt.Y>p.Pt.Y?(p=x,f=null):x.Pt.Y===p.Pt.Y&&x.Pt.X<=p.Pt.X&&(x.Pt.X_.Pt.Y?p:x.Pt.Y<_.Pt.Y?f:x.Pt.X<_.Pt.X?p:x.Pt.X>_.Pt.X||x.Next===x?f:_.Next===_||this.FirstIsBottomPt(x,_)?p:f},r.Clipper.prototype.OutRec1RightOfOutRec2=function(p,f){do if(p=p.FirstLeft,p===f)return!0;while(p!==null);return!1},r.Clipper.prototype.GetOutRec=function(p){for(var f=this.m_PolyOuts[p];f!==this.m_PolyOuts[f.Idx];)f=this.m_PolyOuts[f.Idx];return f},r.Clipper.prototype.AppendPolygon=function(p,f){var x=this.m_PolyOuts[p.OutIdx],_=this.m_PolyOuts[f.OutIdx],A;this.OutRec1RightOfOutRec2(x,_)?A=_:this.OutRec1RightOfOutRec2(_,x)?A=x:A=this.GetLowermostRec(x,_);var B=x.Pts,k=B.Prev,ee=_.Pts,te=ee.Prev;p.Side===r.EdgeSide.esLeft?f.Side===r.EdgeSide.esLeft?(this.ReversePolyPtLinks(ee),ee.Next=B,B.Prev=ee,k.Next=te,te.Prev=k,x.Pts=te):(te.Next=B,B.Prev=te,ee.Prev=k,k.Next=ee,x.Pts=ee):f.Side===r.EdgeSide.esRight?(this.ReversePolyPtLinks(ee),k.Next=te,te.Prev=k,ee.Next=B,B.Prev=ee):(k.Next=ee,ee.Prev=k,B.Prev=te,te.Next=B),x.BottomPt=null,A===_&&(_.FirstLeft!==x&&(x.FirstLeft=_.FirstLeft),x.IsHole=_.IsHole),_.Pts=null,_.BottomPt=null,_.FirstLeft=x;var me=p.OutIdx,Le=f.OutIdx;p.OutIdx=-1,f.OutIdx=-1;for(var Me=this.m_ActiveEdges;Me!==null;){if(Me.OutIdx===Le){Me.OutIdx=me,Me.Side=p.Side;break}Me=Me.NextInAEL}_.Idx=x.Idx},r.Clipper.prototype.ReversePolyPtLinks=function(p){if(p!==null){var f,x;f=p;do x=f.Next,f.Next=f.Prev,f.Prev=x,f=x;while(f!==p)}},r.Clipper.SwapSides=function(p,f){var x=p.Side;p.Side=f.Side,f.Side=x},r.Clipper.SwapPolyIndexes=function(p,f){var x=p.OutIdx;p.OutIdx=f.OutIdx,f.OutIdx=x},r.Clipper.prototype.IntersectEdges=function(p,f,x){var _=p.OutIdx>=0,A=f.OutIdx>=0;if(r.use_xyz&&this.SetZ(x,p,f),r.use_lines&&(p.WindDelta===0||f.WindDelta===0)){if(p.WindDelta===0&&f.WindDelta===0)return;p.PolyTyp===f.PolyTyp&&p.WindDelta!==f.WindDelta&&this.m_ClipType===r.ClipType.ctUnion?p.WindDelta===0?A&&(this.AddOutPt(p,x),_&&(p.OutIdx=-1)):_&&(this.AddOutPt(f,x),A&&(f.OutIdx=-1)):p.PolyTyp!==f.PolyTyp&&(p.WindDelta===0&&Math.abs(f.WindCnt)===1&&(this.m_ClipType!==r.ClipType.ctUnion||f.WindCnt2===0)?(this.AddOutPt(p,x),_&&(p.OutIdx=-1)):f.WindDelta===0&&Math.abs(p.WindCnt)===1&&(this.m_ClipType!==r.ClipType.ctUnion||p.WindCnt2===0)&&(this.AddOutPt(f,x),A&&(f.OutIdx=-1)));return}if(p.PolyTyp===f.PolyTyp)if(this.IsEvenOddFillType(p)){var B=p.WindCnt;p.WindCnt=f.WindCnt,f.WindCnt=B}else p.WindCnt+f.WindDelta===0?p.WindCnt=-p.WindCnt:p.WindCnt+=f.WindDelta,f.WindCnt-p.WindDelta===0?f.WindCnt=-f.WindCnt:f.WindCnt-=p.WindDelta;else this.IsEvenOddFillType(f)?p.WindCnt2=p.WindCnt2===0?1:0:p.WindCnt2+=f.WindDelta,this.IsEvenOddFillType(p)?f.WindCnt2=f.WindCnt2===0?1:0:f.WindCnt2-=p.WindDelta;var k,ee,te,me;p.PolyTyp===r.PolyType.ptSubject?(k=this.m_SubjFillType,te=this.m_ClipFillType):(k=this.m_ClipFillType,te=this.m_SubjFillType),f.PolyTyp===r.PolyType.ptSubject?(ee=this.m_SubjFillType,me=this.m_ClipFillType):(ee=this.m_ClipFillType,me=this.m_SubjFillType);var Le,Me;switch(k){case r.PolyFillType.pftPositive:Le=p.WindCnt;break;case r.PolyFillType.pftNegative:Le=-p.WindCnt;break;default:Le=Math.abs(p.WindCnt);break}switch(ee){case r.PolyFillType.pftPositive:Me=f.WindCnt;break;case r.PolyFillType.pftNegative:Me=-f.WindCnt;break;default:Me=Math.abs(f.WindCnt);break}if(_&&A)Le!==0&&Le!==1||Me!==0&&Me!==1||p.PolyTyp!==f.PolyTyp&&this.m_ClipType!==r.ClipType.ctXor?this.AddLocalMaxPoly(p,f,x):(this.AddOutPt(p,x),this.AddOutPt(f,x),r.Clipper.SwapSides(p,f),r.Clipper.SwapPolyIndexes(p,f));else if(_)(Me===0||Me===1)&&(this.AddOutPt(p,x),r.Clipper.SwapSides(p,f),r.Clipper.SwapPolyIndexes(p,f));else if(A)(Le===0||Le===1)&&(this.AddOutPt(f,x),r.Clipper.SwapSides(p,f),r.Clipper.SwapPolyIndexes(p,f));else if((Le===0||Le===1)&&(Me===0||Me===1)){var Ge,xt;switch(te){case r.PolyFillType.pftPositive:Ge=p.WindCnt2;break;case r.PolyFillType.pftNegative:Ge=-p.WindCnt2;break;default:Ge=Math.abs(p.WindCnt2);break}switch(me){case r.PolyFillType.pftPositive:xt=f.WindCnt2;break;case r.PolyFillType.pftNegative:xt=-f.WindCnt2;break;default:xt=Math.abs(f.WindCnt2);break}if(p.PolyTyp!==f.PolyTyp)this.AddLocalMinPoly(p,f,x);else if(Le===1&&Me===1)switch(this.m_ClipType){case r.ClipType.ctIntersection:Ge>0&&xt>0&&this.AddLocalMinPoly(p,f,x);break;case r.ClipType.ctUnion:Ge<=0&&xt<=0&&this.AddLocalMinPoly(p,f,x);break;case r.ClipType.ctDifference:(p.PolyTyp===r.PolyType.ptClip&&Ge>0&&xt>0||p.PolyTyp===r.PolyType.ptSubject&&Ge<=0&&xt<=0)&&this.AddLocalMinPoly(p,f,x);break;case r.ClipType.ctXor:this.AddLocalMinPoly(p,f,x);break}else r.Clipper.SwapSides(p,f)}},r.Clipper.prototype.DeleteFromSEL=function(p){var f=p.PrevInSEL,x=p.NextInSEL;f===null&&x===null&&p!==this.m_SortedEdges||(f!==null?f.NextInSEL=x:this.m_SortedEdges=x,x!==null&&(x.PrevInSEL=f),p.NextInSEL=null,p.PrevInSEL=null)},r.Clipper.prototype.ProcessHorizontals=function(){for(var p={};this.PopEdgeFromSEL(p);)this.ProcessHorizontal(p.v)},r.Clipper.prototype.GetHorzDirection=function(p,f){p.Bot.X=k.Top.X&&(te=null)}else{for(;te.Next!==null&&te.Next.X=0&&!B&&this.AddOutPt(p,new r.IntPoint2(te.X,p.Bot.Y)),te=te.Next;else for(;te!==null&&te.X>Me.Curr.X;)p.OutIdx>=0&&!B&&this.AddOutPt(p,new r.IntPoint2(te.X,p.Bot.Y)),te=te.Prev;if(x===r.Direction.dLeftToRight&&Me.Curr.X>A||x===r.Direction.dRightToLeft&&Me.Curr.X<_||Me.Curr.X===p.Top.X&&p.NextInLML!==null&&Me.Dx=0&&!B){r.use_xyz&&(x===r.Direction.dLeftToRight?this.SetZ(Me.Curr,p,Me):this.SetZ(Me.Curr,Me,p)),me=this.AddOutPt(p,Me.Curr);for(var Ge=this.m_SortedEdges;Ge!==null;){if(Ge.OutIdx>=0&&this.HorzSegmentsOverlap(p.Bot.X,p.Top.X,Ge.Bot.X,Ge.Top.X)){var xt=this.GetLastOutPt(Ge);this.AddJoin(xt,me,Ge.Top)}Ge=Ge.NextInSEL}this.AddGhostJoin(me,p.Bot)}if(Me===ee&&Le){p.OutIdx>=0&&this.AddLocalMaxPoly(p,ee,p.Top),this.DeleteFromAEL(p),this.DeleteFromAEL(ee);return}if(x===r.Direction.dLeftToRight){var kt=new r.IntPoint2(Me.Curr.X,p.Curr.Y);this.IntersectEdges(p,Me,kt)}else{var kt=new r.IntPoint2(Me.Curr.X,p.Curr.Y);this.IntersectEdges(Me,p,kt)}var Vt=this.GetNextInAEL(Me,x);this.SwapPositionsInAEL(p,Me),Me=Vt}if(p.NextInLML===null||!r.ClipperBase.IsHorizontal(p.NextInLML))break;p=this.UpdateEdgeIntoAEL(p),p.OutIdx>=0&&this.AddOutPt(p,p.Bot),f={Dir:x,Left:_,Right:A},this.GetHorzDirection(p,f),x=f.Dir,_=f.Left,A=f.Right}if(p.OutIdx>=0&&me===null){me=this.GetLastOutPt(p);for(var Ge=this.m_SortedEdges;Ge!==null;){if(Ge.OutIdx>=0&&this.HorzSegmentsOverlap(p.Bot.X,p.Top.X,Ge.Bot.X,Ge.Top.X)){var xt=this.GetLastOutPt(Ge);this.AddJoin(xt,me,Ge.Top)}Ge=Ge.NextInSEL}this.AddGhostJoin(me,p.Top)}if(p.NextInLML!==null)if(p.OutIdx>=0){if(me=this.AddOutPt(p,p.Top),p=this.UpdateEdgeIntoAEL(p),p.WindDelta===0)return;var fr=p.PrevInAEL,Vt=p.NextInAEL;if(fr!==null&&fr.Curr.X===p.Bot.X&&fr.Curr.Y===p.Bot.Y&&fr.WindDelta===0&&fr.OutIdx>=0&&fr.Curr.Y>fr.Top.Y&&r.ClipperBase.SlopesEqual3(p,fr,this.m_UseFullRange)){var xt=this.AddOutPt(fr,p.Bot);this.AddJoin(me,xt,p.Top)}else if(Vt!==null&&Vt.Curr.X===p.Bot.X&&Vt.Curr.Y===p.Bot.Y&&Vt.WindDelta!==0&&Vt.OutIdx>=0&&Vt.Curr.Y>Vt.Top.Y&&r.ClipperBase.SlopesEqual3(p,Vt,this.m_UseFullRange)){var xt=this.AddOutPt(Vt,p.Bot);this.AddJoin(me,xt,p.Top)}}else p=this.UpdateEdgeIntoAEL(p);else p.OutIdx>=0&&this.AddOutPt(p,p.Top),this.DeleteFromAEL(p)},r.Clipper.prototype.GetNextInAEL=function(p,f){return f===r.Direction.dLeftToRight?p.NextInAEL:p.PrevInAEL},r.Clipper.prototype.IsMinima=function(p){return p!==null&&p.Prev.NextInLML!==p&&p.Next.NextInLML!==p},r.Clipper.prototype.IsMaxima=function(p,f){return p!==null&&p.Top.Y===f&&p.NextInLML===null},r.Clipper.prototype.IsIntermediate=function(p,f){return p.Top.Y===f&&p.NextInLML!==null},r.Clipper.prototype.GetMaximaPair=function(p){return r.IntPoint.op_Equality(p.Next.Top,p.Top)&&p.Next.NextInLML===null?p.Next:r.IntPoint.op_Equality(p.Prev.Top,p.Top)&&p.Prev.NextInLML===null?p.Prev:null},r.Clipper.prototype.GetMaximaPairEx=function(p){var f=this.GetMaximaPair(p);return f===null||f.OutIdx===r.ClipperBase.Skip||f.NextInAEL===f.PrevInAEL&&!r.ClipperBase.IsHorizontal(f)?null:f},r.Clipper.prototype.ProcessIntersections=function(p){if(this.m_ActiveEdges===null)return!0;try{if(this.BuildIntersectList(p),this.m_IntersectList.length===0)return!0;if(this.m_IntersectList.length===1||this.FixupIntersectionOrder())this.ProcessIntersectList();else return!1}catch{this.m_SortedEdges=null,this.m_IntersectList.length=0,r.Error("ProcessIntersections error")}return this.m_SortedEdges=null,!0},r.Clipper.prototype.BuildIntersectList=function(p){if(this.m_ActiveEdges!==null){var f=this.m_ActiveEdges;for(this.m_SortedEdges=f;f!==null;)f.PrevInSEL=f.PrevInAEL,f.NextInSEL=f.NextInAEL,f.Curr.X=r.Clipper.TopX(f,p),f=f.NextInAEL;for(var x=!0;x&&this.m_SortedEdges!==null;){for(x=!1,f=this.m_SortedEdges;f.NextInSEL!==null;){var _=f.NextInSEL,A=new r.IntPoint0;if(f.Curr.X>_.Curr.X){this.IntersectPoint(f,_,A),A.Y2147483647?Math.floor(p):p|0)};n.msie?r.Clipper.Round=y0e:n.chromium?r.Clipper.Round=v0e:n.safari?r.Clipper.Round=b0e:r.Clipper.Round=x0e,r.Clipper.TopX=function(p,f){return f===p.Top.Y?p.Top.X:p.Bot.X+r.Clipper.Round(p.Dx*(f-p.Bot.Y))},r.Clipper.prototype.IntersectPoint=function(p,f,x){x.X=0,x.Y=0;var _,A;if(p.Dx===f.Dx){x.Y=p.Curr.Y,x.X=r.Clipper.TopX(p,x.Y);return}if(p.Delta.X===0)x.X=p.Bot.X,r.ClipperBase.IsHorizontal(f)?x.Y=f.Bot.Y:(A=f.Bot.Y-f.Bot.X/f.Dx,x.Y=r.Clipper.Round(x.X/f.Dx+A));else if(f.Delta.X===0)x.X=f.Bot.X,r.ClipperBase.IsHorizontal(p)?x.Y=p.Bot.Y:(_=p.Bot.Y-p.Bot.X/p.Dx,x.Y=r.Clipper.Round(x.X/p.Dx+_));else{_=p.Bot.X-p.Bot.Y*p.Dx,A=f.Bot.X-f.Bot.Y*f.Dx;var B=(A-_)/(p.Dx-f.Dx);x.Y=r.Clipper.Round(B),Math.abs(p.Dx)f.Top.Y)return x.Y=p.Top.Y,x.X=r.Clipper.TopX(f,p.Top.Y),x.Xp.Curr.Y&&(x.Y=p.Curr.Y,Math.abs(p.Dx)>Math.abs(f.Dx)?x.X=r.Clipper.TopX(f,x.Y):x.X=r.Clipper.TopX(p,x.Y))},r.Clipper.prototype.ProcessEdgesAtTopOfScanbeam=function(p){for(var f=this.m_ActiveEdges;f!==null;){var x=this.IsMaxima(f,p);if(x){var _=this.GetMaximaPairEx(f);x=_===null||!r.ClipperBase.IsHorizontal(_)}if(x){this.StrictlySimple&&this.InsertMaxima(f.Top.X);var A=f.PrevInAEL;this.DoMaxima(f),A===null?f=this.m_ActiveEdges:f=A.NextInAEL}else{if(this.IsIntermediate(f,p)&&r.ClipperBase.IsHorizontal(f.NextInLML)?(f=this.UpdateEdgeIntoAEL(f),f.OutIdx>=0&&this.AddOutPt(f,f.Bot),this.AddEdgeToSEL(f)):(f.Curr.X=r.Clipper.TopX(f,p),f.Curr.Y=p),r.use_xyz&&(f.Top.Y===p?f.Curr.Z=f.Top.Z:f.Bot.Y===p?f.Curr.Z=f.Bot.Z:f.Curr.Z=0),this.StrictlySimple){var A=f.PrevInAEL;if(f.OutIdx>=0&&f.WindDelta!==0&&A!==null&&A.OutIdx>=0&&A.Curr.X===f.Curr.X&&A.WindDelta!==0){var B=new r.IntPoint1(f.Curr);r.use_xyz&&this.SetZ(B,A,f);var k=this.AddOutPt(A,B),ee=this.AddOutPt(f,B);this.AddJoin(k,ee,B)}}f=f.NextInAEL}}for(this.ProcessHorizontals(),this.m_Maxima=null,f=this.m_ActiveEdges;f!==null;){if(this.IsIntermediate(f,p)){var k=null;f.OutIdx>=0&&(k=this.AddOutPt(f,f.Top)),f=this.UpdateEdgeIntoAEL(f);var A=f.PrevInAEL,te=f.NextInAEL;if(A!==null&&A.Curr.X===f.Bot.X&&A.Curr.Y===f.Bot.Y&&k!==null&&A.OutIdx>=0&&A.Curr.Y===A.Top.Y&&r.ClipperBase.SlopesEqual5(f.Curr,f.Top,A.Curr,A.Top,this.m_UseFullRange)&&f.WindDelta!==0&&A.WindDelta!==0){var ee=this.AddOutPt(ePrev2,f.Bot);this.AddJoin(k,ee,f.Top)}else if(te!==null&&te.Curr.X===f.Bot.X&&te.Curr.Y===f.Bot.Y&&k!==null&&te.OutIdx>=0&&te.Curr.Y===te.Top.Y&&r.ClipperBase.SlopesEqual5(f.Curr,f.Top,te.Curr,te.Top,this.m_UseFullRange)&&f.WindDelta!==0&&te.WindDelta!==0){var ee=this.AddOutPt(te,f.Bot);this.AddJoin(k,ee,f.Top)}}f=f.NextInAEL}},r.Clipper.prototype.DoMaxima=function(p){var f=this.GetMaximaPairEx(p);if(f===null){p.OutIdx>=0&&this.AddOutPt(p,p.Top),this.DeleteFromAEL(p);return}for(var x=p.NextInAEL;x!==null&&x!==f;)this.IntersectEdges(p,x,p.Top),this.SwapPositionsInAEL(p,x),x=p.NextInAEL;p.OutIdx===-1&&f.OutIdx===-1?(this.DeleteFromAEL(p),this.DeleteFromAEL(f)):p.OutIdx>=0&&f.OutIdx>=0?(p.OutIdx>=0&&this.AddLocalMaxPoly(p,f,p.Top),this.DeleteFromAEL(p),this.DeleteFromAEL(f)):r.use_lines&&p.WindDelta===0?(p.OutIdx>=0&&(this.AddOutPt(p,p.Top),p.OutIdx=r.ClipperBase.Unassigned),this.DeleteFromAEL(p),f.OutIdx>=0&&(this.AddOutPt(f,p.Top),f.OutIdx=r.ClipperBase.Unassigned),this.DeleteFromAEL(f)):r.Error("DoMaxima error")},r.Clipper.ReversePaths=function(p){for(var f=0,x=p.length;f=0},r.Clipper.prototype.PointCount=function(p){if(p===null)return 0;var f=0,x=p;do f++,x=x.Next;while(x!==p);return f},r.Clipper.prototype.BuildResult=function(p){r.Clear(p);for(var f=0,x=this.m_PolyOuts.length;ff.Pt.X?r.Direction.dRightToLeft:r.Direction.dLeftToRight,ee=x.Pt.X>_.Pt.X?r.Direction.dRightToLeft:r.Direction.dLeftToRight;if(k===ee)return!1;if(k===r.Direction.dLeftToRight){for(;p.Next.Pt.X<=A.X&&p.Next.Pt.X>=p.Pt.X&&p.Next.Pt.Y===A.Y;)p=p.Next;B&&p.Pt.X!==A.X&&(p=p.Next),f=this.DupOutPt(p,!B),r.IntPoint.op_Inequality(f.Pt,A)&&(p=f,p.Pt.X=A.X,p.Pt.Y=A.Y,r.use_xyz&&(p.Pt.Z=A.Z),f=this.DupOutPt(p,!B))}else{for(;p.Next.Pt.X>=A.X&&p.Next.Pt.X<=p.Pt.X&&p.Next.Pt.Y===A.Y;)p=p.Next;!B&&p.Pt.X!==A.X&&(p=p.Next),f=this.DupOutPt(p,B),r.IntPoint.op_Inequality(f.Pt,A)&&(p=f,p.Pt.X=A.X,p.Pt.Y=A.Y,r.use_xyz&&(p.Pt.Z=A.Z),f=this.DupOutPt(p,B))}if(ee===r.Direction.dLeftToRight){for(;x.Next.Pt.X<=A.X&&x.Next.Pt.X>=x.Pt.X&&x.Next.Pt.Y===A.Y;)x=x.Next;B&&x.Pt.X!==A.X&&(x=x.Next),_=this.DupOutPt(x,!B),r.IntPoint.op_Inequality(_.Pt,A)&&(x=_,x.Pt.X=A.X,x.Pt.Y=A.Y,r.use_xyz&&(x.Pt.Z=A.Z),_=this.DupOutPt(x,!B))}else{for(;x.Next.Pt.X>=A.X&&x.Next.Pt.X<=x.Pt.X&&x.Next.Pt.Y===A.Y;)x=x.Next;!B&&x.Pt.X!==A.X&&(x=x.Next),_=this.DupOutPt(x,B),r.IntPoint.op_Inequality(_.Pt,A)&&(x=_,x.Pt.X=A.X,x.Pt.Y=A.Y,r.use_xyz&&(x.Pt.Z=A.Z),_=this.DupOutPt(x,B))}return k===r.Direction.dLeftToRight===B?(p.Prev=x,x.Next=p,f.Next=_,_.Prev=f):(p.Next=x,x.Prev=p,f.Prev=_,_.Next=f),!0},r.Clipper.prototype.JoinPoints=function(p,f,x){var _=p.OutPt1,A=new r.OutPt,B=p.OutPt2,k=new r.OutPt,ee=p.OutPt1.Pt.Y===p.OffPt.Y;if(ee&&r.IntPoint.op_Equality(p.OffPt,p.OutPt1.Pt)&&r.IntPoint.op_Equality(p.OffPt,p.OutPt2.Pt)){if(f!==x)return!1;for(A=p.OutPt1.Next;A!==_&&r.IntPoint.op_Equality(A.Pt,p.OffPt);)A=A.Next;var te=A.Pt.Y>p.OffPt.Y;for(k=p.OutPt2.Next;k!==B&&r.IntPoint.op_Equality(k.Pt,p.OffPt);)k=k.Next;var me=k.Pt.Y>p.OffPt.Y;return te===me?!1:te?(A=this.DupOutPt(_,!1),k=this.DupOutPt(B,!0),_.Prev=B,B.Next=_,A.Next=k,k.Prev=A,p.OutPt1=_,p.OutPt2=A,!0):(A=this.DupOutPt(_,!0),k=this.DupOutPt(B,!1),_.Next=B,B.Prev=_,A.Prev=k,k.Next=A,p.OutPt1=_,p.OutPt2=A,!0)}else if(ee){for(A=_;_.Prev.Pt.Y===_.Pt.Y&&_.Prev!==A&&_.Prev!==B;)_=_.Prev;for(;A.Next.Pt.Y===A.Pt.Y&&A.Next!==_&&A.Next!==B;)A=A.Next;if(A.Next===_||A.Next===B)return!1;for(k=B;B.Prev.Pt.Y===B.Pt.Y&&B.Prev!==k&&B.Prev!==A;)B=B.Prev;for(;k.Next.Pt.Y===k.Pt.Y&&k.Next!==B&&k.Next!==_;)k=k.Next;if(k.Next===B||k.Next===_)return!1;var Le={Left:null,Right:null};if(!this.GetOverlap(_.Pt.X,A.Pt.X,B.Pt.X,k.Pt.X,Le))return!1;var Me=Le.Left,Ge=Le.Right,xt=new r.IntPoint0,kt;return _.Pt.X>=Me&&_.Pt.X<=Ge?(xt.X=_.Pt.X,xt.Y=_.Pt.Y,r.use_xyz&&(xt.Z=_.Pt.Z),kt=_.Pt.X>A.Pt.X):B.Pt.X>=Me&&B.Pt.X<=Ge?(xt.X=B.Pt.X,xt.Y=B.Pt.Y,r.use_xyz&&(xt.Z=B.Pt.Z),kt=B.Pt.X>k.Pt.X):A.Pt.X>=Me&&A.Pt.X<=Ge?(xt.X=A.Pt.X,xt.Y=A.Pt.Y,r.use_xyz&&(xt.Z=A.Pt.Z),kt=A.Pt.X>_.Pt.X):(xt.X=k.Pt.X,xt.Y=k.Pt.Y,r.use_xyz&&(xt.Z=k.Pt.Z),kt=k.Pt.X>B.Pt.X),p.OutPt1=_,p.OutPt2=B,this.JoinHorz(_,A,B,k,xt,kt)}else{for(A=_.Next;r.IntPoint.op_Equality(A.Pt,_.Pt)&&A!==_;)A=A.Next;var Vt=A.Pt.Y>_.Pt.Y||!r.ClipperBase.SlopesEqual4(_.Pt,A.Pt,p.OffPt,this.m_UseFullRange);if(Vt){for(A=_.Prev;r.IntPoint.op_Equality(A.Pt,_.Pt)&&A!==_;)A=A.Prev;if(A.Pt.Y>_.Pt.Y||!r.ClipperBase.SlopesEqual4(_.Pt,A.Pt,p.OffPt,this.m_UseFullRange))return!1}for(k=B.Next;r.IntPoint.op_Equality(k.Pt,B.Pt)&&k!==B;)k=k.Next;var fr=k.Pt.Y>B.Pt.Y||!r.ClipperBase.SlopesEqual4(B.Pt,k.Pt,p.OffPt,this.m_UseFullRange);if(fr){for(k=B.Prev;r.IntPoint.op_Equality(k.Pt,B.Pt)&&k!==B;)k=k.Prev;if(k.Pt.Y>B.Pt.Y||!r.ClipperBase.SlopesEqual4(B.Pt,k.Pt,p.OffPt,this.m_UseFullRange))return!1}return A===_||k===B||A===k||f===x&&Vt===fr?!1:Vt?(A=this.DupOutPt(_,!1),k=this.DupOutPt(B,!0),_.Prev=B,B.Next=_,A.Next=k,k.Prev=A,p.OutPt1=_,p.OutPt2=A,!0):(A=this.DupOutPt(_,!0),k=this.DupOutPt(B,!1),_.Next=B,B.Prev=_,A.Prev=k,k.Next=A,p.OutPt1=_,p.OutPt2=A,!0)}},r.Clipper.GetBounds=function(p){for(var f=0,x=p.length;f_.right&&(_.right=p[f][A].X),p[f][A].Y<_.top?_.top=p[f][A].Y:p[f][A].Y>_.bottom&&(_.bottom=p[f][A].Y);return _},r.Clipper.prototype.GetBounds2=function(p){var f=p,x=new r.IntRect;for(x.left=p.Pt.X,x.right=p.Pt.X,x.top=p.Pt.Y,x.bottom=p.Pt.Y,p=p.Next;p!==f;)p.Pt.Xx.right&&(x.right=p.Pt.X),p.Pt.Yx.bottom&&(x.bottom=p.Pt.Y),p=p.Next;return x},r.Clipper.PointInPolygon=function(p,f){var x=0,_=f.length;if(_<3)return 0;for(var A=f[0],B=1;B<=_;++B){var k=B===_?f[0]:f[B];if(k.Y===p.Y&&(k.X===p.X||A.Y===p.Y&&k.X>p.X==A.X=p.X)if(k.X>p.X)x=1-x;else{var ee=(A.X-p.X)*(k.Y-p.Y)-(k.X-p.X)*(A.Y-p.Y);if(ee===0)return-1;ee>0==k.Y>A.Y&&(x=1-x)}else if(k.X>p.X){var ee=(A.X-p.X)*(k.Y-p.Y)-(k.X-p.X)*(A.Y-p.Y);if(ee===0)return-1;ee>0==k.Y>A.Y&&(x=1-x)}}A=k}return x},r.Clipper.prototype.PointInPolygon=function(p,f){var x=0,_=f,A=p.X,B=p.Y,k=f.Pt.X,ee=f.Pt.Y;do{f=f.Next;var te=f.Pt.X,me=f.Pt.Y;if(me===B&&(te===A||ee===B&&te>A==k=A)if(te>A)x=1-x;else{var Le=(k-A)*(me-B)-(te-A)*(ee-B);if(Le===0)return-1;Le>0==me>ee&&(x=1-x)}else if(te>A){var Le=(k-A)*(me-B)-(te-A)*(ee-B);if(Le===0)return-1;Le>0==me>ee&&(x=1-x)}}k=te,ee=me}while(_!==f);return x},r.Clipper.prototype.Poly2ContainsPoly1=function(p,f){var x=p;do{var _=this.PointInPolygon(x.Pt,f);if(_>=0)return _>0;x=x.Next}while(x!==p);return!0},r.Clipper.prototype.FixupFirstLefts1=function(p,f){for(var x,_,A=0,B=this.m_PolyOuts.length;A0&&this.ReversePolyPtLinks(A.Pts)):this.Poly2ContainsPoly1(_.Pts,A.Pts)?(A.IsHole=_.IsHole,_.IsHole=!A.IsHole,A.FirstLeft=_.FirstLeft,_.FirstLeft=A,this.m_UsingPolyTree&&this.FixupFirstLefts2(_,A),(_.IsHole^this.ReverseSolution)==this.Area$1(_)>0&&this.ReversePolyPtLinks(_.Pts)):(A.IsHole=_.IsHole,A.FirstLeft=_.FirstLeft,this.m_UsingPolyTree&&this.FixupFirstLefts1(_,A))):(A.Pts=null,A.BottomPt=null,A.Idx=_.Idx,_.IsHole=B.IsHole,B===A&&(_.FirstLeft=A.FirstLeft),A.FirstLeft=_,this.m_UsingPolyTree&&this.FixupFirstLefts3(A,_)))}}},r.Clipper.prototype.UpdateOutPtIdxs=function(p){var f=p.Pts;do f.Idx=p.Idx,f=f.Prev;while(f!==p.Pts)},r.Clipper.prototype.DoSimplePolygons=function(){for(var p=0;p"u"&&(f=r.PolyFillType.pftEvenOdd);var x=new Array,_=new r.Clipper(0);return _.StrictlySimple=!0,_.AddPaths(p,r.PolyType.ptSubject,!0),_.Execute(r.ClipType.ctUnion,x,f,f),x},r.Clipper.DistanceSqrd=function(p,f){var x=p.X-f.X,_=p.Y-f.Y;return x*x+_*_},r.Clipper.DistanceFromLineSqrd=function(p,f,x){var _=f.Y-x.Y,A=x.X-f.X,B=_*f.X+A*f.Y;return B=_*p.X+A*p.Y-B,B*B/(_*_+A*A)},r.Clipper.SlopesNearCollinear=function(p,f,x,_){return Math.abs(p.X-f.X)>Math.abs(p.Y-f.Y)?p.X>f.X==p.Xp.X==f.Xf.Y==p.Yp.Y==f.Y"u"&&(f=1.415);var x=p.length;if(x===0)return new Array;for(var _=new Array(x),A=0;A0&&_&&x.push(p.m_polygon);for(var A=0,B=p.Childs(),k=B.length,ee=B[A];A"u"&&(p=2),typeof f>"u"&&(f=r.ClipperOffset.def_arc_tolerance),this.m_destPolys=new r.Paths,this.m_srcPoly=new r.Path,this.m_destPoly=new r.Path,this.m_normals=new Array,this.m_delta=0,this.m_sinA=0,this.m_sin=0,this.m_cos=0,this.m_miterLim=0,this.m_StepsPerRad=0,this.m_lowest=new r.IntPoint0,this.m_polyNodes=new r.PolyNode,this.MiterLimit=p,this.ArcTolerance=f,this.m_lowest.X=-1},r.ClipperOffset.two_pi=6.28318530717959,r.ClipperOffset.def_arc_tolerance=.25,r.ClipperOffset.prototype.Clear=function(){r.Clear(this.m_polyNodes.Childs()),this.m_lowest.X=-1},r.ClipperOffset.Round=r.Clipper.Round,r.ClipperOffset.prototype.AddPath=function(p,f,x){var _=p.length-1;if(!(_<0)){var A=new r.PolyNode;if(A.m_jointype=f,A.m_endtype=x,x===r.EndType.etClosedLine||x===r.EndType.etClosedPolygon)for(;_>0&&r.IntPoint.op_Equality(p[0],p[_]);)_--;A.m_polygon.push(p[0]);for(var B=0,k=0,ee=1;ee<=_;ee++)r.IntPoint.op_Inequality(A.m_polygon[B],p[ee])&&(B++,A.m_polygon.push(p[ee]),(p[ee].Y>A.m_polygon[k].Y||p[ee].Y===A.m_polygon[k].Y&&p[ee].Xte.Y||A.m_polygon[k].Y===te.Y&&A.m_polygon[k].X=0&&!r.Clipper.Orientation(this.m_polyNodes.Childs()[this.m_lowest.X].m_polygon))for(var p=0;p2?this.m_miterLim=2/(this.MiterLimit*this.MiterLimit):this.m_miterLim=.5;var _;this.ArcTolerance<=0?_=r.ClipperOffset.def_arc_tolerance:this.ArcTolerance>Math.abs(p)*r.ClipperOffset.def_arc_tolerance?_=Math.abs(p)*r.ClipperOffset.def_arc_tolerance:_=this.ArcTolerance;var A=3.14159265358979/Math.acos(1-_/Math.abs(p));this.m_sin=Math.sin(r.ClipperOffset.two_pi/A),this.m_cos=Math.cos(r.ClipperOffset.two_pi/A),this.m_StepsPerRad=A/r.ClipperOffset.two_pi,p<0&&(this.m_sin=-this.m_sin);for(var f=0;f0;te--)this.m_normals[te]=new r.DoublePoint2(-this.m_normals[te-1].X,-this.m_normals[te-1].Y);this.m_normals[0]=new r.DoublePoint2(-Me.X,-Me.Y),Le=0;for(var te=B-1;te>=0;te--)Le=this.OffsetPoint(te,Le,x.m_jointype);this.m_destPolys.push(this.m_destPoly)}else{for(var Le=0,te=1;te0;te--)this.m_normals[te]=new r.DoublePoint2(-this.m_normals[te-1].X,-this.m_normals[te-1].Y);this.m_normals[0]=new r.DoublePoint2(-this.m_normals[1].X,-this.m_normals[1].Y),Le=B-1;for(var te=Le-1;te>0;--te)Le=this.OffsetPoint(te,Le,x.m_jointype);x.m_endtype===r.EndType.etOpenButt?(Ge=new r.IntPoint2(r.ClipperOffset.Round(this.m_srcPoly[0].X-this.m_normals[0].X*p),r.ClipperOffset.Round(this.m_srcPoly[0].Y-this.m_normals[0].Y*p)),this.m_destPoly.push(Ge),Ge=new r.IntPoint2(r.ClipperOffset.Round(this.m_srcPoly[0].X+this.m_normals[0].X*p),r.ClipperOffset.Round(this.m_srcPoly[0].Y+this.m_normals[0].Y*p)),this.m_destPoly.push(Ge)):(Le=1,this.m_sinA=0,x.m_endtype===r.EndType.etOpenSquare?this.DoSquare(0,1):this.DoRound(0,1)),this.m_destPolys.push(this.m_destPoly)}}}},r.ClipperOffset.prototype.Execute=function(){var p=arguments,f=p[0]instanceof r.PolyTree;if(f){var x=p[0],_=p[1];x.Clear(),this.FixOrientations(),this.DoOffset(_);var A=new r.Clipper(0);if(A.AddPaths(this.m_destPolys,r.PolyType.ptSubject,!0),_>0)A.Execute(r.ClipType.ctUnion,x,r.PolyFillType.pftPositive,r.PolyFillType.pftPositive);else{var B=r.Clipper.GetBounds(this.m_destPolys),k=new r.Path;if(k.push(new r.IntPoint2(B.left-10,B.bottom+10)),k.push(new r.IntPoint2(B.right+10,B.bottom+10)),k.push(new r.IntPoint2(B.right+10,B.top-10)),k.push(new r.IntPoint2(B.left-10,B.top-10)),A.AddPath(k,r.PolyType.ptSubject,!0),A.ReverseSolution=!0,A.Execute(r.ClipType.ctUnion,x,r.PolyFillType.pftNegative,r.PolyFillType.pftNegative),x.ChildCount()===1&&x.Childs()[0].ChildCount()>0){var ee=x.Childs()[0];x.Childs()[0]=ee.Childs()[0],x.Childs()[0].m_Parent=x;for(var te=1;te0)A.Execute(r.ClipType.ctUnion,x,r.PolyFillType.pftPositive,r.PolyFillType.pftPositive);else{var B=r.Clipper.GetBounds(this.m_destPolys),k=new r.Path;k.push(new r.IntPoint2(B.left-10,B.bottom+10)),k.push(new r.IntPoint2(B.right+10,B.bottom+10)),k.push(new r.IntPoint2(B.right+10,B.top-10)),k.push(new r.IntPoint2(B.left-10,B.top-10)),A.AddPath(k,r.PolyType.ptSubject,!0),A.ReverseSolution=!0,A.Execute(r.ClipType.ctUnion,x,r.PolyFillType.pftNegative,r.PolyFillType.pftNegative),x.length>0&&x.splice(0,1)}}},r.ClipperOffset.prototype.OffsetPoint=function(p,f,x){if(this.m_sinA=this.m_normals[f].X*this.m_normals[p].Y-this.m_normals[p].X*this.m_normals[f].Y,Math.abs(this.m_sinA*this.m_delta)<1){var _=this.m_normals[f].X*this.m_normals[p].X+this.m_normals[p].Y*this.m_normals[f].Y;if(_>0)return this.m_destPoly.push(new r.IntPoint2(r.ClipperOffset.Round(this.m_srcPoly[p].X+this.m_normals[f].X*this.m_delta),r.ClipperOffset.Round(this.m_srcPoly[p].Y+this.m_normals[f].Y*this.m_delta))),f}else this.m_sinA>1?this.m_sinA=1:this.m_sinA<-1&&(this.m_sinA=-1);if(this.m_sinA*this.m_delta<0)this.m_destPoly.push(new r.IntPoint2(r.ClipperOffset.Round(this.m_srcPoly[p].X+this.m_normals[f].X*this.m_delta),r.ClipperOffset.Round(this.m_srcPoly[p].Y+this.m_normals[f].Y*this.m_delta))),this.m_destPoly.push(new r.IntPoint1(this.m_srcPoly[p])),this.m_destPoly.push(new r.IntPoint2(r.ClipperOffset.Round(this.m_srcPoly[p].X+this.m_normals[p].X*this.m_delta),r.ClipperOffset.Round(this.m_srcPoly[p].Y+this.m_normals[p].Y*this.m_delta)));else switch(x){case r.JoinType.jtMiter:{var A=1+(this.m_normals[p].X*this.m_normals[f].X+this.m_normals[p].Y*this.m_normals[f].Y);A>=this.m_miterLim?this.DoMiter(p,f,A):this.DoSquare(p,f);break}case r.JoinType.jtSquare:this.DoSquare(p,f);break;case r.JoinType.jtRound:this.DoRound(p,f);break}return f=p,f},r.ClipperOffset.prototype.DoSquare=function(p,f){var x=Math.tan(Math.atan2(this.m_sinA,this.m_normals[f].X*this.m_normals[p].X+this.m_normals[f].Y*this.m_normals[p].Y)/4);this.m_destPoly.push(new r.IntPoint2(r.ClipperOffset.Round(this.m_srcPoly[p].X+this.m_delta*(this.m_normals[f].X-this.m_normals[f].Y*x)),r.ClipperOffset.Round(this.m_srcPoly[p].Y+this.m_delta*(this.m_normals[f].Y+this.m_normals[f].X*x)))),this.m_destPoly.push(new r.IntPoint2(r.ClipperOffset.Round(this.m_srcPoly[p].X+this.m_delta*(this.m_normals[p].X+this.m_normals[p].Y*x)),r.ClipperOffset.Round(this.m_srcPoly[p].Y+this.m_delta*(this.m_normals[p].Y-this.m_normals[p].X*x))))},r.ClipperOffset.prototype.DoMiter=function(p,f,x){var _=this.m_delta/x;this.m_destPoly.push(new r.IntPoint2(r.ClipperOffset.Round(this.m_srcPoly[p].X+(this.m_normals[f].X+this.m_normals[p].X)*_),r.ClipperOffset.Round(this.m_srcPoly[p].Y+(this.m_normals[f].Y+this.m_normals[p].Y)*_)))},r.ClipperOffset.prototype.DoRound=function(p,f){for(var x=Math.atan2(this.m_sinA,this.m_normals[f].X*this.m_normals[p].X+this.m_normals[f].Y*this.m_normals[p].Y),_=Math.max(r.Cast_Int32(r.ClipperOffset.Round(this.m_StepsPerRad*Math.abs(x))),1),A=this.m_normals[f].X,B=this.m_normals[f].Y,k,ee=0;ee<_;++ee)this.m_destPoly.push(new r.IntPoint2(r.ClipperOffset.Round(this.m_srcPoly[p].X+A*this.m_delta),r.ClipperOffset.Round(this.m_srcPoly[p].Y+B*this.m_delta))),k=A,A=A*this.m_cos-this.m_sin*B,B=k*this.m_sin+B*this.m_cos;this.m_destPoly.push(new r.IntPoint2(r.ClipperOffset.Round(this.m_srcPoly[p].X+this.m_normals[p].X*this.m_delta),r.ClipperOffset.Round(this.m_srcPoly[p].Y+this.m_normals[p].Y*this.m_delta)))},r.Error=function(p){try{throw new Error(p)}catch(f){alert(f.message)}},r.JS={},r.JS.AreaOfPolygon=function(p,f){return f||(f=1),r.Clipper.Area(p)/(f*f)},r.JS.AreaOfPolygons=function(p,f){f||(f=1);for(var x=0,_=0;_1?(Qn=Le.X,Wc=Le.Y):ks>0&&(Qn+=Vt*ks,Wc+=fr*ks)),Vt=Me.X-Qn,fr=Me.Y-Wc,Ge=Vt*Vt+fr*fr,Ge<=S0e&&(xt[A+1]=1,A++);for(ee.push({X:B[0].X,Y:B[0].Y}),A=1;A2&&jc.push(ee)}return x||(jc=jc[0]),typeof jc>"u"&&(jc=[]),jc},r.JS.PerimeterOfPath=function(p,f,x){if(typeof p>"u")return 0;var _=Math.sqrt,A=0,B,k,ee=0,te=0,me=0,Le=0,Me=p.length;if(Me<2)return 0;for(f&&(p[Me]=p[0],Me++);--Me;)B=p[Me],ee=B.X,te=B.Y,k=p[Me-1],me=k.X,Le=k.Y,A+=_((ee-me)*(ee-me)+(te-Le)*(te-Le));return f&&p.pop(),A/x},r.JS.PerimeterOfPaths=function(p,f,x){x||(x=1);for(var _=0,A=0;A{}),gM={};mM(gM,{APPEARANCE_DEFAULTS:()=>q2,DURATION:()=>c0e,REVIEW_BUILD:()=>p0e,SIM_STEP:()=>Ah,TUNABLES:()=>Gx,cameraAt:()=>YF,create:()=>m0e,durationOf:()=>y2,parseTrack:()=>c2,resolveSchedule:()=>Fce,setRendererProfile:()=>Sse,structuralKeyOf:()=>Fk,validateDeformationScale:()=>JF});var yM={};mM(yM,{BRDF_GGX:()=>ZX,BRDF_Lambert:()=>JX,BasicPointShadowFilter:()=>QX,BasicShadowFilter:()=>KX,Break:()=>e$,Const:()=>t$,Continue:()=>r$,DFGLUT:()=>i$,D_GGX:()=>s$,Discard:()=>a$,EPSILON:()=>n$,F_Schlick:()=>o$,Fn:()=>Ir,HALF_PI:()=>x$,INFINITY:()=>l$,If:()=>pm,Loop:()=>Gy,NodeAccess:()=>u$,NodeShaderStage:()=>h$,NodeType:()=>d$,NodeUpdateType:()=>c$,OnBeforeMaterialUpdate:()=>iee,OnBeforeObjectUpdate:()=>ree,OnMaterialUpdate:()=>aee,OnObjectUpdate:()=>see,PCFShadowFilter:()=>p$,PCFSoftShadowFilter:()=>m$,PI:()=>f$,PI2:()=>g$,PointShadowFilter:()=>v$,Return:()=>b$,Schlick_to_F0:()=>T$,ShaderNode:()=>S$,Stack:()=>_$,Switch:()=>w$,TBNViewMatrix:()=>M$,TWO_PI:()=>y$,VSMShadowFilter:()=>N$,V_GGX_SmithCorrelated:()=>A$,Var:()=>C$,VarIntent:()=>R$,abs:()=>$a,acesFilmicToneMapping:()=>E$,acos:()=>P$,acosh:()=>B$,add:()=>Wy,addMethodChaining:()=>I$,addNodeElement:()=>F$,agxToneMapping:()=>L$,all:()=>k$,alphaT:()=>D$,ambientOcclusion:()=>O$,and:()=>U$,anisotropy:()=>z$,anisotropyB:()=>V$,anisotropyT:()=>G$,any:()=>W$,append:()=>j$,array:()=>H$,asin:()=>X$,asinh:()=>$$,assign:()=>q$,atan:()=>Y$,atanh:()=>Z$,atomicAdd:()=>J$,atomicAnd:()=>Q$,atomicFunc:()=>K$,atomicLoad:()=>eq,atomicMax:()=>tq,atomicMin:()=>rq,atomicOr:()=>iq,atomicStore:()=>sq,atomicSub:()=>aq,atomicXor:()=>nq,attenuationColor:()=>oq,attenuationDistance:()=>lq,attribute:()=>uq,attributeArray:()=>hq,backgroundBlurriness:()=>dq,backgroundIntensity:()=>cq,backgroundRotation:()=>pq,batch:()=>mq,bentNormalView:()=>fq,billboarding:()=>gq,bitAnd:()=>yq,bitNot:()=>xq,bitOr:()=>vq,bitXor:()=>bq,bitangentGeometry:()=>Tq,bitangentLocal:()=>Sq,bitangentView:()=>_q,bitangentWorld:()=>wq,bitcast:()=>Mq,blendBurn:()=>Nq,blendColor:()=>Aq,blendDodge:()=>Cq,blendOverlay:()=>Rq,blendScreen:()=>Eq,blur:()=>Pq,bool:()=>Bq,buffer:()=>Iq,bufferAttribute:()=>Fq,builtin:()=>kq,builtinAOContext:()=>Dq,builtinShadowContext:()=>Oq,bumpMap:()=>Lq,bvec2:()=>Uq,bvec3:()=>zq,bvec4:()=>Vq,bypass:()=>Gq,cache:()=>Wq,call:()=>jq,cameraFar:()=>Hq,cameraIndex:()=>Xq,cameraNear:()=>$q,cameraNormalMatrix:()=>qq,cameraPosition:()=>Yq,cameraProjectionMatrix:()=>Zq,cameraProjectionMatrixInverse:()=>Jq,cameraViewMatrix:()=>Qq,cameraViewport:()=>Kq,cameraWorldMatrix:()=>eY,cbrt:()=>tY,cdl:()=>rY,ceil:()=>iY,checker:()=>sY,cineonToneMapping:()=>aY,clamp:()=>SB,clearcoat:()=>nY,clearcoatNormalView:()=>oY,clearcoatRoughness:()=>lY,clipSpace:()=>uY,code:()=>hY,color:()=>dY,colorSpaceToWorking:()=>cY,colorToDirection:()=>pY,compute:()=>mY,computeKernel:()=>fY,computeSkinning:()=>gY,context:()=>yY,convert:()=>xY,convertColorSpace:()=>vY,convertToTexture:()=>Ju,cos:()=>_Y,cosh:()=>wY,countLeadingZeros:()=>bY,countOneBits:()=>TY,countTrailingZeros:()=>SY,cross:()=>MY,cubeTexture:()=>NY,cubeTextureBase:()=>AY,dFdx:()=>CY,dFdy:()=>RY,dashSize:()=>EY,debug:()=>PY,decrement:()=>BY,decrementBefore:()=>IY,defaultBuildStages:()=>FY,defaultShaderStages:()=>LY,defined:()=>kY,degrees:()=>DY,deltaTime:()=>OY,densityFog:()=>UY,densityFogFactor:()=>zY,depth:()=>VY,depthPass:()=>GY,determinant:()=>WY,difference:()=>jY,diffuseColor:()=>HY,directPointLight:()=>XY,directionToColor:()=>$Y,directionToFaceDirection:()=>qY,dispersion:()=>YY,distance:()=>ZY,div:()=>JY,dot:()=>QY,drawIndex:()=>KY,dynamicBufferAttribute:()=>eZ,element:()=>tZ,emissive:()=>rZ,equal:()=>iZ,equirectDirection:()=>sZ,equirectUV:()=>aZ,exp:()=>_B,exp2:()=>c_,exponentialHeightFogFactor:()=>nZ,expression:()=>oZ,faceDirection:()=>lZ,faceForward:()=>uZ,faceforward:()=>hZ,float:()=>yt,floatBitsToInt:()=>dZ,floatBitsToUint:()=>cZ,floor:()=>Zd,fog:()=>pZ,fract:()=>wB,frameGroup:()=>mZ,frameId:()=>fZ,frontFacing:()=>gZ,fwidth:()=>yZ,gain:()=>xZ,gapSize:()=>vZ,getConstNodeType:()=>bZ,getCurrentStack:()=>TZ,getDirection:()=>SZ,getDistanceAttenuation:()=>_Z,getGeometryRoughness:()=>wZ,getNormalFromDepth:()=>MZ,getParallaxCorrectNormal:()=>CZ,getRoughness:()=>RZ,getScreenPosition:()=>EZ,getShIrradianceAt:()=>PZ,getShadowMaterial:()=>BZ,getShadowRenderObjectFunction:()=>IZ,getTextureIndex:()=>FZ,getViewPosition:()=>p_,globalId:()=>LZ,glsl:()=>kZ,glslFn:()=>DZ,grayscale:()=>OZ,greaterThan:()=>UZ,greaterThanEqual:()=>zZ,hash:()=>VZ,highpModelNormalViewMatrix:()=>GZ,highpModelViewMatrix:()=>WZ,hue:()=>jZ,increment:()=>HZ,incrementBefore:()=>XZ,instance:()=>$Z,instanceIndex:()=>qZ,instancedArray:()=>YZ,instancedBufferAttribute:()=>ZZ,instancedDynamicBufferAttribute:()=>JZ,instancedMesh:()=>QZ,int:()=>Eo,intBitsToFloat:()=>KZ,interleavedGradientNoise:()=>NZ,inverse:()=>eJ,inverseSqrt:()=>tJ,inversesqrt:()=>rJ,invocationLocalIndex:()=>iJ,invocationSubgroupIndex:()=>sJ,ior:()=>aJ,iridescence:()=>nJ,iridescenceIOR:()=>oJ,iridescenceThickness:()=>lJ,ivec2:()=>ss,ivec3:()=>uJ,ivec4:()=>hJ,js:()=>dJ,label:()=>cJ,length:()=>pJ,lengthSq:()=>mJ,lessThan:()=>fJ,lessThanEqual:()=>gJ,lightPosition:()=>yJ,lightProjectionUV:()=>xJ,lightShadowMatrix:()=>vJ,lightTargetDirection:()=>bJ,lightTargetPosition:()=>TJ,lightViewPosition:()=>SJ,lightingContext:()=>_J,lights:()=>wJ,linearDepth:()=>MJ,linearToneMapping:()=>NJ,localId:()=>AJ,log:()=>CJ,log2:()=>RJ,logarithmicDepthToViewZ:()=>MB,luminance:()=>kl,mat2:()=>EJ,mat3:()=>PJ,mat4:()=>NB,matcapUV:()=>BJ,materialAO:()=>IJ,materialAlphaTest:()=>FJ,materialAnisotropy:()=>LJ,materialAnisotropyVector:()=>kJ,materialAttenuationColor:()=>DJ,materialAttenuationDistance:()=>OJ,materialClearcoat:()=>UJ,materialClearcoatNormal:()=>zJ,materialClearcoatRoughness:()=>VJ,materialColor:()=>GJ,materialDispersion:()=>WJ,materialEmissive:()=>jJ,materialEnvIntensity:()=>HJ,materialEnvRotation:()=>XJ,materialIOR:()=>$J,materialIridescence:()=>qJ,materialIridescenceIOR:()=>YJ,materialIridescenceThickness:()=>ZJ,materialLightMap:()=>JJ,materialLineDashOffset:()=>QJ,materialLineDashSize:()=>KJ,materialLineGapSize:()=>eQ,materialLineScale:()=>tQ,materialLineWidth:()=>rQ,materialMetalness:()=>iQ,materialNormal:()=>sQ,materialOpacity:()=>aQ,materialPointSize:()=>nQ,materialReference:()=>oQ,materialReflectivity:()=>lQ,materialRefractionRatio:()=>uQ,materialRotation:()=>hQ,materialRoughness:()=>dQ,materialSheen:()=>cQ,materialSheenRoughness:()=>pQ,materialShininess:()=>mQ,materialSpecular:()=>fQ,materialSpecularColor:()=>gQ,materialSpecularIntensity:()=>yQ,materialSpecularStrength:()=>xQ,materialThickness:()=>vQ,materialTransmission:()=>bQ,max:()=>_t,maxMipLevel:()=>TQ,mediumpModelViewMatrix:()=>SQ,metalness:()=>_Q,min:()=>Ar,mix:()=>Dl,mixElement:()=>wQ,mod:()=>MQ,modelDirection:()=>NQ,modelNormalMatrix:()=>AQ,modelPosition:()=>CQ,modelRadius:()=>RQ,modelScale:()=>EQ,modelViewMatrix:()=>PQ,modelViewPosition:()=>BQ,modelViewProjection:()=>IQ,modelWorldMatrix:()=>FQ,modelWorldMatrixInverse:()=>LQ,morphReference:()=>kQ,mrt:()=>DQ,mul:()=>OQ,mx_aastep:()=>UQ,mx_add:()=>zQ,mx_atan2:()=>VQ,mx_cell_noise_float:()=>GQ,mx_contrast:()=>WQ,mx_divide:()=>jQ,mx_fractal_noise_float:()=>HQ,mx_fractal_noise_vec2:()=>XQ,mx_fractal_noise_vec3:()=>$Q,mx_fractal_noise_vec4:()=>qQ,mx_frame:()=>YQ,mx_heighttonormal:()=>ZQ,mx_hsvtorgb:()=>JQ,mx_ifequal:()=>QQ,mx_ifgreater:()=>KQ,mx_ifgreatereq:()=>eK,mx_invert:()=>tK,mx_modulo:()=>rK,mx_multiply:()=>iK,mx_noise_float:()=>sK,mx_noise_vec3:()=>aK,mx_noise_vec4:()=>nK,mx_place2d:()=>oK,mx_power:()=>lK,mx_ramp4:()=>uK,mx_ramplr:()=>hK,mx_ramptb:()=>dK,mx_rgbtohsv:()=>cK,mx_rotate2d:()=>pK,mx_rotate3d:()=>mK,mx_safepower:()=>fK,mx_separate:()=>gK,mx_splitlr:()=>yK,mx_splittb:()=>xK,mx_srgb_texture_to_lin_rec709:()=>vK,mx_subtract:()=>bK,mx_timer:()=>TK,mx_transform_uv:()=>SK,mx_unifiednoise2d:()=>_K,mx_unifiednoise3d:()=>wK,mx_worley_noise_float:()=>MK,mx_worley_noise_vec2:()=>NK,mx_worley_noise_vec3:()=>AK,negate:()=>CK,negateOnBackSide:()=>RK,neutralToneMapping:()=>EK,nodeArray:()=>PK,nodeImmutable:()=>BK,nodeObject:()=>Un,nodeObjectIntent:()=>IK,nodeObjects:()=>FK,nodeProxy:()=>LK,nodeProxyIntent:()=>kK,normalFlat:()=>DK,normalGeometry:()=>OK,normalLocal:()=>UK,normalMap:()=>zK,normalView:()=>VK,normalViewGeometry:()=>GK,normalWorld:()=>WK,normalWorldGeometry:()=>jK,normalize:()=>HK,not:()=>XK,notEqual:()=>$K,numWorkgroups:()=>qK,objectDirection:()=>YK,objectGroup:()=>ZK,objectPosition:()=>JK,objectRadius:()=>QK,objectScale:()=>KK,objectViewPosition:()=>eee,objectWorldMatrix:()=>tee,oneMinus:()=>nee,or:()=>oee,orthographicDepthToViewZ:()=>lee,oscSawtooth:()=>uee,oscSine:()=>hee,oscSquare:()=>dee,oscTriangle:()=>cee,output:()=>pee,outputStruct:()=>m_,overloadingFn:()=>mee,overrideNode:()=>fee,overrideNodes:()=>gee,packHalf2x16:()=>yee,packNormalToRGB:()=>bee,packSnorm2x16:()=>xee,packUnorm2x16:()=>vee,parabola:()=>Tee,parallaxDirection:()=>See,parallaxUV:()=>_ee,parameter:()=>wee,pass:()=>Mee,passTexture:()=>Qu,pcurve:()=>Nee,perspectiveDepthToViewZ:()=>Aee,pmremTexture:()=>Cee,pointShadow:()=>Ree,pointUV:()=>Eee,pointWidth:()=>Pee,positionGeometry:()=>Bee,positionLocal:()=>Iee,positionPrevious:()=>Fee,positionView:()=>Lee,positionViewDirection:()=>kee,positionWorld:()=>Dee,positionWorldDirection:()=>Oee,posterize:()=>Uee,pow:()=>zee,pow2:()=>Vee,pow3:()=>Gee,pow4:()=>Wee,premultiplyAlpha:()=>AB,property:()=>mm,radians:()=>jee,rand:()=>Hee,range:()=>Xee,rangeFog:()=>$ee,rangeFogFactor:()=>qee,reciprocal:()=>Yee,reference:()=>Zee,referenceBuffer:()=>Jee,reflect:()=>Qee,reflectVector:()=>Kee,reflectView:()=>ete,reflector:()=>tte,refract:()=>rte,refractVector:()=>ite,refractView:()=>ste,reinhardToneMapping:()=>ate,remap:()=>nte,remapClamp:()=>ote,renderGroup:()=>lte,renderOutput:()=>ute,rendererReference:()=>hte,replaceDefaultUV:()=>dte,rotate:()=>cte,rotateUV:()=>pte,roughness:()=>mte,round:()=>fte,rtt:()=>gte,sRGBTransferEOTF:()=>yte,sRGBTransferOETF:()=>xte,sample:()=>vte,sampler:()=>bte,samplerComparison:()=>Tte,saturate:()=>f_,saturation:()=>Ste,screen:()=>_te,screenCoordinate:()=>wte,screenDPR:()=>Mte,screenSize:()=>Nte,screenUV:()=>Ate,select:()=>g_,setCurrentStack:()=>Cte,setName:()=>Rte,shaderStages:()=>Ete,shadow:()=>Pte,shadowPositionWorld:()=>Bte,shapeCircle:()=>Ite,sharedUniformGroup:()=>Fte,sheen:()=>Lte,sheenRoughness:()=>kte,shiftLeft:()=>Dte,shiftRight:()=>Ote,shininess:()=>Ute,sign:()=>zte,sin:()=>Vte,sinc:()=>Wte,sinh:()=>Gte,skinning:()=>jte,smoothstep:()=>y_,smoothstepElement:()=>Hte,specularColor:()=>Xte,specularF90:()=>$te,spherizeUV:()=>qte,split:()=>Yte,spritesheetUV:()=>Zte,sqrt:()=>CB,stack:()=>Jte,step:()=>x_,stepElement:()=>Qte,storage:()=>fm,storageBarrier:()=>Kte,storageTexture:()=>ere,storageTexture3D:()=>tre,struct:()=>v_,sub:()=>rre,subBuild:()=>hre,subgroupAdd:()=>ire,subgroupAll:()=>sre,subgroupAnd:()=>are,subgroupAny:()=>nre,subgroupBallot:()=>ore,subgroupBroadcast:()=>lre,subgroupBroadcastFirst:()=>ure,subgroupElect:()=>dre,subgroupExclusiveAdd:()=>cre,subgroupExclusiveMul:()=>pre,subgroupInclusiveAdd:()=>mre,subgroupInclusiveMul:()=>fre,subgroupIndex:()=>gre,subgroupMax:()=>yre,subgroupMin:()=>xre,subgroupMul:()=>vre,subgroupOr:()=>bre,subgroupShuffle:()=>Tre,subgroupShuffleDown:()=>Sre,subgroupShuffleUp:()=>_re,subgroupShuffleXor:()=>wre,subgroupSize:()=>Mre,subgroupXor:()=>Nre,tan:()=>Are,tangentGeometry:()=>Rre,tangentLocal:()=>Ere,tangentView:()=>Pre,tangentWorld:()=>Bre,tanh:()=>Cre,texture:()=>Ri,texture3D:()=>Ire,textureBarrier:()=>Fre,textureBicubic:()=>Lre,textureBicubicLevel:()=>kre,textureCubeUV:()=>Dre,textureLevel:()=>Ore,textureLoad:()=>Ps,textureSize:()=>jy,textureStore:()=>Ure,thickness:()=>zre,time:()=>Vre,toneMapping:()=>Gre,toneMappingExposure:()=>Wre,toonOutlinePass:()=>jre,transformDirection:()=>Hre,transformNormal:()=>Xre,transformNormalByInverseViewMatrix:()=>$re,transformNormalByViewMatrix:()=>qre,transformNormalToView:()=>Yre,transformedClearcoatNormalView:()=>Zre,transformedNormalView:()=>Jre,transformedNormalWorld:()=>Qre,transmission:()=>Kre,transpose:()=>eie,triNoise3D:()=>tie,triplanarTexture:()=>rie,triplanarTextures:()=>iie,trunc:()=>sie,uint:()=>RB,uintBitsToFloat:()=>aie,uniform:()=>Fr,uniformArray:()=>Jd,uniformCubeTexture:()=>nie,uniformFlow:()=>lie,uniformGroup:()=>oie,uniformTexture:()=>uie,unpackHalf2x16:()=>hie,unpackRGBToNormal:()=>pie,unpackSnorm2x16:()=>die,unpackUnorm2x16:()=>cie,unpremultiplyAlpha:()=>EB,userData:()=>mie,uv:()=>_a,uvec2:()=>fie,uvec3:()=>gie,uvec4:()=>yie,varying:()=>xie,varyingProperty:()=>vie,vec2:()=>nr,vec3:()=>Hy,vec4:()=>hr,vectorComponents:()=>bie,velocity:()=>Xy,vertexColor:()=>Tie,vertexIndex:()=>Sie,vertexStage:()=>_ie,vibrance:()=>wie,viewZToLogarithmicDepth:()=>Mie,viewZToOrthographicDepth:()=>PB,viewZToPerspectiveDepth:()=>$y,viewZToReversedOrthographicDepth:()=>Nie,viewZToReversedPerspectiveDepth:()=>Aie,viewport:()=>Cie,viewportCoordinate:()=>Rie,viewportDepthTexture:()=>Eie,viewportLinearDepth:()=>Pie,viewportMipTexture:()=>Bie,viewportOpaqueMipTexture:()=>Iie,viewportResolution:()=>Fie,viewportSafeUV:()=>Lie,viewportSharedTexture:()=>kie,viewportSize:()=>Die,viewportTexture:()=>Oie,viewportUV:()=>Uie,vogelDiskSample:()=>AZ,wgsl:()=>zie,wgslFn:()=>Vie,workgroupArray:()=>Gie,workgroupBarrier:()=>Wie,workgroupId:()=>jie,workingToColorSpace:()=>Hie,xor:()=>Xie});var bD=0,TD=1,SD=2,_D=0,xM=1,wD=2,Lh=3,Cs=0,ii=1,hs=2,Kn=0,oa=1,kh=2,Dh=3,Oh=4,Uh=5,tv=6,la=100,vM=101,bM=102,MD=103,ND=104,Jo=200,TM=201,SM=202,_M=203,$c=204,qc=205,wM=206,MM=207,NM=208,AM=209,CM=210,Af=0,Cf=1,Rf=2,zh=3,Ef=4,Pf=5,Bf=6,If=7,Ff=0,AD=1,CD=2,eo=0,RD=1,ED=2,PD=3,BD=4,ID=6,FD=7,rv=300,Vh=301,Lf=302,kf=303,iv=304,Df=306,to=1e3,Ti=1001,Qo=1002,or=1003,RM=1004,Gh=1005,lr=1006,sv=1007,Ia=1008,LD=1008,Si=1009,cu=1010,pu=1011,Ko=1012,ci=1013,gr=1014,Er=1015,Dt=1016,av=1017,nv=1018,ro=1020,Of=35902,Uf=35899,ov=1021,Wh=1022,pi=1023,ua=1026,ln=1027,io=1028,jh=1029,ha=1030,Hh=1031,lv=1032,zf=1033,Yc=33776,Zc=33777,Jc=33778,Qc=33779,uv=35840,hv=35841,dv=35842,cv=35843,Vf=36196,Gf=37492,Wf=37496,jf=37488,Hf=37489,Kc=37490,Xf=37491,$f=37808,qf=37809,Yf=37810,Zf=37811,Jf=37812,Qf=37813,Kf=37814,eg=37815,tg=37816,rg=37817,ig=37818,sg=37819,ag=37820,ng=37821,og=36492,lg=36494,ug=36495,hg=36283,dg=36284,ep=36285,cg=36286,pg=2300,pv=2301,mv=2302,EM=2303,PM=2400,BM=2401,IM=2402,so=0,kD=1,Fa="",ds="srgb",Xh="srgb-linear",mg="linear",Tt="srgb",fv="",FM="rg",DD="ga",OD=0,mu=7680,UD=7681,zD=7682,VD=7683,GD=34055,WD=34056,jD=5386,HD=512,XD=513,$D=514,qD=515,YD=516,ZD=517,JD=518,gv=519,LM=512,yv=513,kM=514,tp=515,fg=516,DM=517,$h=518,OM=519,qh=35044,rp=35048,Ds=2e3,da=2001,un={COMPUTE:"compute",RENDER:"render"},fu={TEXTURE_COMPARE:"depthTextureCompare"};function QD(e){for(let t=e.length-1;t>=0;--t)if(e[t]>=65535)return!0;return!1}function ip(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function gg(e){return document.createElementNS("http://www.w3.org/1999/xhtml",e)}function KD(){let e=gg("canvas");return e.style.display="block",e}var UM={},Yh=null;function xv(...e){let t="THREE."+e.shift();Yh?Yh("log",t,...e):console.log(t,...e)}function zM(e){let t=e[0];if(typeof t=="string"&&t.startsWith("TSL:")){let r=e[1];r&&r.isStackTrace?e[0]+=" "+r.getLocation():e[1]='Stack trace not available. Enable "THREE.Node.captureStackTrace" to capture stack traces.'}return e}function Ue(...e){e=zM(e);let t="THREE."+e.shift();if(Yh)Yh("warn",t,...e);else{let r=e[0];r&&r.isStackTrace?console.warn(r.getError(t)):console.warn(t,...e)}}function Ce(...e){e=zM(e);let t="THREE."+e.shift();if(Yh)Yh("error",t,...e);else{let r=e[0];r&&r.isStackTrace?console.error(r.getError(t)):console.error(t,...e)}}function Et(...e){let t=e.join(" ");t in UM||(UM[t]=!0,Ue(...e))}function VM(){return typeof self<"u"&&typeof self.scheduler<"u"&&typeof self.scheduler.yield<"u"?self.scheduler.yield():new Promise(e=>{requestAnimationFrame(e)})}var GM={[Af]:Cf,[Rf]:Bf,[Ef]:If,[zh]:Pf,[Cf]:Af,[Bf]:Rf,[If]:Ef,[Pf]:zh},hn=class{addEventListener(e,t){this._listeners===void 0&&(this._listeners={});let r=this._listeners;r[e]===void 0&&(r[e]=[]),r[e].indexOf(t)===-1&&r[e].push(t)}hasEventListener(e,t){let r=this._listeners;return r===void 0?!1:r[e]!==void 0&&r[e].indexOf(t)!==-1}removeEventListener(e,t){let r=this._listeners;if(r===void 0)return;let i=r[e];if(i!==void 0){let s=i.indexOf(t);s!==-1&&i.splice(s,1)}}dispatchEvent(e){let t=this._listeners;if(t===void 0)return;let r=t[e.type];if(r!==void 0){e.target=this;let i=r.slice(0);for(let s=0,a=i.length;s>8&255]+Wi[e>>16&255]+Wi[e>>24&255]+"-"+Wi[t&255]+Wi[t>>8&255]+"-"+Wi[t>>16&15|64]+Wi[t>>24&255]+"-"+Wi[r&63|128]+Wi[r>>8&255]+"-"+Wi[r>>16&255]+Wi[r>>24&255]+Wi[i&255]+Wi[i>>8&255]+Wi[i>>16&255]+Wi[i>>24&255]).toLowerCase()}function St(e,t,r){return Math.max(t,Math.min(r,e))}function vv(e,t){return(e%t+t)%t}function e4(e,t,r,i,s){return i+(e-t)*(s-i)/(r-t)}function t4(e,t,r){return e!==t?(r-e)/(t-e):0}function ap(e,t,r){return(1-r)*e+r*t}function r4(e,t,r,i){return ap(e,t,1-Math.exp(-r*i))}function i4(e,t=1){return t-Math.abs(vv(e,t*2)-t)}function s4(e,t,r){return e<=t?0:e>=r?1:(e=(e-t)/(r-t),e*e*(3-2*e))}function a4(e,t,r){return e<=t?0:e>=r?1:(e=(e-t)/(r-t),e*e*e*(e*(e*6-15)+10))}function n4(e,t){return e+Math.floor(Math.random()*(t-e+1))}function o4(e,t){return e+Math.random()*(t-e)}function l4(e){return e*(.5-Math.random())}function u4(e){e!==void 0&&(WM=e);let t=WM+=1831565813;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}function h4(e){return e*sp}function d4(e){return e*Zh}function c4(e){return(e&e-1)===0&&e!==0}function p4(e){return Math.pow(2,Math.ceil(Math.log(e)/Math.LN2))}function m4(e){return Math.pow(2,Math.floor(Math.log(e)/Math.LN2))}function f4(e,t,r,i,s){let a=Math.cos,n=Math.sin,o=a(r/2),l=n(r/2),u=a((t+i)/2),h=n((t+i)/2),d=a((t-i)/2),c=n((t-i)/2),m=a((i-t)/2),g=n((i-t)/2);switch(s){case"XYX":e.set(o*h,l*d,l*c,o*u);break;case"YZY":e.set(l*c,o*h,l*d,o*u);break;case"ZXZ":e.set(l*d,l*c,o*h,o*u);break;case"XZX":e.set(o*h,l*g,l*m,o*u);break;case"YXY":e.set(l*m,o*h,l*g,o*u);break;case"ZYZ":e.set(l*g,l*m,o*h,o*u);break;default:Ue("MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+s)}}function cs(e,t){switch(t.constructor){case Float32Array:return e;case Uint32Array:return e/4294967295;case Uint16Array:return e/65535;case Uint8Array:return e/255;case Int32Array:return Math.max(e/2147483647,-1);case Int16Array:return Math.max(e/32767,-1);case Int8Array:return Math.max(e/127,-1);default:throw new Error("THREE.MathUtils: Invalid component type.")}}function At(e,t){switch(t.constructor){case Float32Array:return e;case Uint32Array:return Math.round(e*4294967295);case Uint16Array:return Math.round(e*65535);case Uint8Array:return Math.round(e*255);case Int32Array:return Math.round(e*2147483647);case Int16Array:return Math.round(e*32767);case Int8Array:return Math.round(e*127);default:throw new Error("THREE.MathUtils: Invalid component type.")}}var Bt={DEG2RAD:sp,RAD2DEG:Zh,generateUUID:dn,clamp:St,euclideanModulo:vv,mapLinear:e4,inverseLerp:t4,lerp:ap,damp:r4,pingpong:i4,smoothstep:s4,smootherstep:a4,randInt:n4,randFloat:o4,randFloatSpread:l4,seededRandom:u4,degToRad:h4,radToDeg:d4,isPowerOfTwo:c4,ceilPowerOfTwo:p4,floorPowerOfTwo:m4,setQuaternionFromProperEuler:f4,normalize:At,denormalize:cs},fe=class kk{static{kk.prototype.isVector2=!0}constructor(t=0,r=0){this.x=t,this.y=r}get width(){return this.x}set width(t){this.x=t}get height(){return this.y}set height(t){this.y=t}set(t,r){return this.x=t,this.y=r,this}setScalar(t){return this.x=t,this.y=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setComponent(t,r){switch(t){case 0:this.x=r;break;case 1:this.y=r;break;default:throw new Error("THREE.Vector2: index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;default:throw new Error("THREE.Vector2: index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y)}copy(t){return this.x=t.x,this.y=t.y,this}add(t){return this.x+=t.x,this.y+=t.y,this}addScalar(t){return this.x+=t,this.y+=t,this}addVectors(t,r){return this.x=t.x+r.x,this.y=t.y+r.y,this}addScaledVector(t,r){return this.x+=t.x*r,this.y+=t.y*r,this}sub(t){return this.x-=t.x,this.y-=t.y,this}subScalar(t){return this.x-=t,this.y-=t,this}subVectors(t,r){return this.x=t.x-r.x,this.y=t.y-r.y,this}multiply(t){return this.x*=t.x,this.y*=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divide(t){return this.x/=t.x,this.y/=t.y,this}divideScalar(t){return this.multiplyScalar(1/t)}applyMatrix3(t){let r=this.x,i=this.y,s=t.elements;return this.x=s[0]*r+s[3]*i+s[6],this.y=s[1]*r+s[4]*i+s[7],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this}clamp(t,r){return this.x=St(this.x,t.x,r.x),this.y=St(this.y,t.y,r.y),this}clampScalar(t,r){return this.x=St(this.x,t,r),this.y=St(this.y,t,r),this}clampLength(t,r){let i=this.length();return this.divideScalar(i||1).multiplyScalar(St(i,t,r))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(t){let r=Math.sqrt(this.lengthSq()*t.lengthSq());if(r===0)return Math.PI/2;let i=this.dot(t)/r;return Math.acos(St(i,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){let r=this.x-t.x,i=this.y-t.y;return r*r+i*i}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,r){return this.x+=(t.x-this.x)*r,this.y+=(t.y-this.y)*r,this}lerpVectors(t,r,i){return this.x=t.x+(r.x-t.x)*i,this.y=t.y+(r.y-t.y)*i,this}equals(t){return t.x===this.x&&t.y===this.y}fromArray(t,r=0){return this.x=t[r],this.y=t[r+1],this}toArray(t=[],r=0){return t[r]=this.x,t[r+1]=this.y,t}fromBufferAttribute(t,r){return this.x=t.getX(r),this.y=t.getY(r),this}rotateAround(t,r){let i=Math.cos(r),s=Math.sin(r),a=this.x-t.x,n=this.y-t.y;return this.x=a*i-n*s+t.x,this.y=a*s+n*i+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}},si=class{constructor(e=0,t=0,r=0,i=1){this.isQuaternion=!0,this._x=e,this._y=t,this._z=r,this._w=i}static slerpFlat(e,t,r,i,s,a,n){let o=r[i+0],l=r[i+1],u=r[i+2],h=r[i+3],d=s[a+0],c=s[a+1],m=s[a+2],g=s[a+3];if(h!==g||o!==d||l!==c||u!==m){let y=o*d+l*c+u*m+h*g;y<0&&(d=-d,c=-c,m=-m,g=-g,y=-y);let b=1-n;if(y<.9995){let v=Math.acos(y),S=Math.sin(v);b=Math.sin(b*v)/S,n=Math.sin(n*v)/S,o=o*b+d*n,l=l*b+c*n,u=u*b+m*n,h=h*b+g*n}else{o=o*b+d*n,l=l*b+c*n,u=u*b+m*n,h=h*b+g*n;let v=1/Math.sqrt(o*o+l*l+u*u+h*h);o*=v,l*=v,u*=v,h*=v}}e[t]=o,e[t+1]=l,e[t+2]=u,e[t+3]=h}static multiplyQuaternionsFlat(e,t,r,i,s,a){let n=r[i],o=r[i+1],l=r[i+2],u=r[i+3],h=s[a],d=s[a+1],c=s[a+2],m=s[a+3];return e[t]=n*m+u*h+o*c-l*d,e[t+1]=o*m+u*d+l*h-n*c,e[t+2]=l*m+u*c+n*d-o*h,e[t+3]=u*m-n*h-o*d-l*c,e}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get w(){return this._w}set w(e){this._w=e,this._onChangeCallback()}set(e,t,r,i){return this._x=e,this._y=t,this._z=r,this._w=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback(),this}setFromEuler(e,t=!0){let r=e._x,i=e._y,s=e._z,a=e._order,n=Math.cos,o=Math.sin,l=n(r/2),u=n(i/2),h=n(s/2),d=o(r/2),c=o(i/2),m=o(s/2);switch(a){case"XYZ":this._x=d*u*h+l*c*m,this._y=l*c*h-d*u*m,this._z=l*u*m+d*c*h,this._w=l*u*h-d*c*m;break;case"YXZ":this._x=d*u*h+l*c*m,this._y=l*c*h-d*u*m,this._z=l*u*m-d*c*h,this._w=l*u*h+d*c*m;break;case"ZXY":this._x=d*u*h-l*c*m,this._y=l*c*h+d*u*m,this._z=l*u*m+d*c*h,this._w=l*u*h-d*c*m;break;case"ZYX":this._x=d*u*h-l*c*m,this._y=l*c*h+d*u*m,this._z=l*u*m-d*c*h,this._w=l*u*h+d*c*m;break;case"YZX":this._x=d*u*h+l*c*m,this._y=l*c*h+d*u*m,this._z=l*u*m-d*c*h,this._w=l*u*h-d*c*m;break;case"XZY":this._x=d*u*h-l*c*m,this._y=l*c*h-d*u*m,this._z=l*u*m+d*c*h,this._w=l*u*h+d*c*m;break;default:Ue("Quaternion: .setFromEuler() encountered an unknown order: "+a)}return t===!0&&this._onChangeCallback(),this}setFromAxisAngle(e,t){let r=t/2,i=Math.sin(r);return this._x=e.x*i,this._y=e.y*i,this._z=e.z*i,this._w=Math.cos(r),this._onChangeCallback(),this}setFromRotationMatrix(e){let t=e.elements,r=t[0],i=t[4],s=t[8],a=t[1],n=t[5],o=t[9],l=t[2],u=t[6],h=t[10],d=r+n+h;if(d>0){let c=.5/Math.sqrt(d+1);this._w=.25/c,this._x=(u-o)*c,this._y=(s-l)*c,this._z=(a-i)*c}else if(r>n&&r>h){let c=2*Math.sqrt(1+r-n-h);this._w=(u-o)/c,this._x=.25*c,this._y=(i+a)/c,this._z=(s+l)/c}else if(n>h){let c=2*Math.sqrt(1+n-r-h);this._w=(s-l)/c,this._x=(i+a)/c,this._y=.25*c,this._z=(o+u)/c}else{let c=2*Math.sqrt(1+h-r-n);this._w=(a-i)/c,this._x=(s+l)/c,this._y=(o+u)/c,this._z=.25*c}return this._onChangeCallback(),this}setFromUnitVectors(e,t){let r=e.dot(t)+1;return r<1e-8?(r=0,Math.abs(e.x)>Math.abs(e.z)?(this._x=-e.y,this._y=e.x,this._z=0,this._w=r):(this._x=0,this._y=-e.z,this._z=e.y,this._w=r)):(this._x=e.y*t.z-e.z*t.y,this._y=e.z*t.x-e.x*t.z,this._z=e.x*t.y-e.y*t.x,this._w=r),this.normalize()}angleTo(e){return 2*Math.acos(Math.abs(St(this.dot(e),-1,1)))}rotateTowards(e,t){let r=this.angleTo(e);if(r===0)return this;let i=Math.min(1,t/r);return this.slerp(e,i),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(e){return this._x*e._x+this._y*e._y+this._z*e._z+this._w*e._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let e=this.length();return e===0?(this._x=0,this._y=0,this._z=0,this._w=1):(e=1/e,this._x=this._x*e,this._y=this._y*e,this._z=this._z*e,this._w=this._w*e),this._onChangeCallback(),this}multiply(e){return this.multiplyQuaternions(this,e)}premultiply(e){return this.multiplyQuaternions(e,this)}multiplyQuaternions(e,t){let r=e._x,i=e._y,s=e._z,a=e._w,n=t._x,o=t._y,l=t._z,u=t._w;return this._x=r*u+a*n+i*l-s*o,this._y=i*u+a*o+s*n-r*l,this._z=s*u+a*l+r*o-i*n,this._w=a*u-r*n-i*o-s*l,this._onChangeCallback(),this}slerp(e,t){let r=e._x,i=e._y,s=e._z,a=e._w,n=this.dot(e);n<0&&(r=-r,i=-i,s=-s,a=-a,n=-n);let o=1-t;if(n<.9995){let l=Math.acos(n),u=Math.sin(l);o=Math.sin(o*l)/u,t=Math.sin(t*l)/u,this._x=this._x*o+r*t,this._y=this._y*o+i*t,this._z=this._z*o+s*t,this._w=this._w*o+a*t,this._onChangeCallback()}else this._x=this._x*o+r*t,this._y=this._y*o+i*t,this._z=this._z*o+s*t,this._w=this._w*o+a*t,this.normalize();return this}slerpQuaternions(e,t,r){return this.copy(e).slerp(t,r)}random(){let e=2*Math.PI*Math.random(),t=2*Math.PI*Math.random(),r=Math.random(),i=Math.sqrt(1-r),s=Math.sqrt(r);return this.set(i*Math.sin(e),i*Math.cos(e),s*Math.sin(t),s*Math.cos(t))}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._w===this._w}fromArray(e,t=0){return this._x=e[t],this._y=e[t+1],this._z=e[t+2],this._w=e[t+3],this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._w,e}fromBufferAttribute(e,t){return this._x=e.getX(t),this._y=e.getY(t),this._z=e.getZ(t),this._w=e.getW(t),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}},F=class Dk{static{Dk.prototype.isVector3=!0}constructor(t=0,r=0,i=0){this.x=t,this.y=r,this.z=i}set(t,r,i){return i===void 0&&(i=this.z),this.x=t,this.y=r,this.z=i,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setComponent(t,r){switch(t){case 0:this.x=r;break;case 1:this.y=r;break;case 2:this.z=r;break;default:throw new Error("THREE.Vector3: index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("THREE.Vector3: index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this}addVectors(t,r){return this.x=t.x+r.x,this.y=t.y+r.y,this.z=t.z+r.z,this}addScaledVector(t,r){return this.x+=t.x*r,this.y+=t.y*r,this.z+=t.z*r,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this}subVectors(t,r){return this.x=t.x-r.x,this.y=t.y-r.y,this.z=t.z-r.z,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}multiplyVectors(t,r){return this.x=t.x*r.x,this.y=t.y*r.y,this.z=t.z*r.z,this}applyEuler(t){return this.applyQuaternion(jM.setFromEuler(t))}applyAxisAngle(t,r){return this.applyQuaternion(jM.setFromAxisAngle(t,r))}applyMatrix3(t){let r=this.x,i=this.y,s=this.z,a=t.elements;return this.x=a[0]*r+a[3]*i+a[6]*s,this.y=a[1]*r+a[4]*i+a[7]*s,this.z=a[2]*r+a[5]*i+a[8]*s,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){let r=this.x,i=this.y,s=this.z,a=t.elements,n=1/(a[3]*r+a[7]*i+a[11]*s+a[15]);return this.x=(a[0]*r+a[4]*i+a[8]*s+a[12])*n,this.y=(a[1]*r+a[5]*i+a[9]*s+a[13])*n,this.z=(a[2]*r+a[6]*i+a[10]*s+a[14])*n,this}applyQuaternion(t){let r=this.x,i=this.y,s=this.z,a=t.x,n=t.y,o=t.z,l=t.w,u=2*(n*s-o*i),h=2*(o*r-a*s),d=2*(a*i-n*r);return this.x=r+l*u+n*d-o*h,this.y=i+l*h+o*u-a*d,this.z=s+l*d+a*h-n*u,this}project(t){return this.applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix)}unproject(t){return this.applyMatrix4(t.projectionMatrixInverse).applyMatrix4(t.matrixWorld)}transformDirection(t){let r=this.x,i=this.y,s=this.z,a=t.elements;return this.x=a[0]*r+a[4]*i+a[8]*s,this.y=a[1]*r+a[5]*i+a[9]*s,this.z=a[2]*r+a[6]*i+a[10]*s,this.normalize()}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this}divideScalar(t){return this.multiplyScalar(1/t)}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this}clamp(t,r){return this.x=St(this.x,t.x,r.x),this.y=St(this.y,t.y,r.y),this.z=St(this.z,t.z,r.z),this}clampScalar(t,r){return this.x=St(this.x,t,r),this.y=St(this.y,t,r),this.z=St(this.z,t,r),this}clampLength(t,r){let i=this.length();return this.divideScalar(i||1).multiplyScalar(St(i,t,r))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,r){return this.x+=(t.x-this.x)*r,this.y+=(t.y-this.y)*r,this.z+=(t.z-this.z)*r,this}lerpVectors(t,r,i){return this.x=t.x+(r.x-t.x)*i,this.y=t.y+(r.y-t.y)*i,this.z=t.z+(r.z-t.z)*i,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,r){let i=t.x,s=t.y,a=t.z,n=r.x,o=r.y,l=r.z;return this.x=s*l-a*o,this.y=a*n-i*l,this.z=i*o-s*n,this}projectOnVector(t){let r=t.lengthSq();if(r===0)return this.set(0,0,0);let i=t.dot(this)/r;return this.copy(t).multiplyScalar(i)}projectOnPlane(t){return bv.copy(this).projectOnVector(t),this.sub(bv)}reflect(t){return this.sub(bv.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){let r=Math.sqrt(this.lengthSq()*t.lengthSq());if(r===0)return Math.PI/2;let i=this.dot(t)/r;return Math.acos(St(i,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){let r=this.x-t.x,i=this.y-t.y,s=this.z-t.z;return r*r+i*i+s*s}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)}setFromSpherical(t){return this.setFromSphericalCoords(t.radius,t.phi,t.theta)}setFromSphericalCoords(t,r,i){let s=Math.sin(r)*t;return this.x=s*Math.sin(i),this.y=Math.cos(r)*t,this.z=s*Math.cos(i),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,r,i){return this.x=t*Math.sin(r),this.y=i,this.z=t*Math.cos(r),this}setFromMatrixPosition(t){let r=t.elements;return this.x=r[12],this.y=r[13],this.z=r[14],this}setFromMatrixScale(t){let r=this.setFromMatrixColumn(t,0).length(),i=this.setFromMatrixColumn(t,1).length(),s=this.setFromMatrixColumn(t,2).length();return this.x=r,this.y=i,this.z=s,this}setFromMatrixColumn(t,r){return this.fromArray(t.elements,r*4)}setFromMatrix3Column(t,r){return this.fromArray(t.elements,r*3)}setFromEuler(t){return this.x=t._x,this.y=t._y,this.z=t._z,this}setFromColor(t){return this.x=t.r,this.y=t.g,this.z=t.b,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z}fromArray(t,r=0){return this.x=t[r],this.y=t[r+1],this.z=t[r+2],this}toArray(t=[],r=0){return t[r]=this.x,t[r+1]=this.y,t[r+2]=this.z,t}fromBufferAttribute(t,r){return this.x=t.getX(r),this.y=t.getY(r),this.z=t.getZ(r),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){let t=Math.random()*Math.PI*2,r=Math.random()*2-1,i=Math.sqrt(1-r*r);return this.x=i*Math.cos(t),this.y=r,this.z=i*Math.sin(t),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}},bv=new F,jM=new si,Dr=class Ok{static{Ok.prototype.isMatrix3=!0}constructor(t,r,i,s,a,n,o,l,u){this.elements=[1,0,0,0,1,0,0,0,1],t!==void 0&&this.set(t,r,i,s,a,n,o,l,u)}set(t,r,i,s,a,n,o,l,u){let h=this.elements;return h[0]=t,h[1]=s,h[2]=o,h[3]=r,h[4]=a,h[5]=l,h[6]=i,h[7]=n,h[8]=u,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){let r=this.elements,i=t.elements;return r[0]=i[0],r[1]=i[1],r[2]=i[2],r[3]=i[3],r[4]=i[4],r[5]=i[5],r[6]=i[6],r[7]=i[7],r[8]=i[8],this}extractBasis(t,r,i){return t.setFromMatrix3Column(this,0),r.setFromMatrix3Column(this,1),i.setFromMatrix3Column(this,2),this}setFromMatrix4(t){let r=t.elements;return this.set(r[0],r[4],r[8],r[1],r[5],r[9],r[2],r[6],r[10]),this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,r){let i=t.elements,s=r.elements,a=this.elements,n=i[0],o=i[3],l=i[6],u=i[1],h=i[4],d=i[7],c=i[2],m=i[5],g=i[8],y=s[0],b=s[3],v=s[6],S=s[1],T=s[4],w=s[7],N=s[2],C=s[5],R=s[8];return a[0]=n*y+o*S+l*N,a[3]=n*b+o*T+l*C,a[6]=n*v+o*w+l*R,a[1]=u*y+h*S+d*N,a[4]=u*b+h*T+d*C,a[7]=u*v+h*w+d*R,a[2]=c*y+m*S+g*N,a[5]=c*b+m*T+g*C,a[8]=c*v+m*w+g*R,this}multiplyScalar(t){let r=this.elements;return r[0]*=t,r[3]*=t,r[6]*=t,r[1]*=t,r[4]*=t,r[7]*=t,r[2]*=t,r[5]*=t,r[8]*=t,this}determinant(){let t=this.elements,r=t[0],i=t[1],s=t[2],a=t[3],n=t[4],o=t[5],l=t[6],u=t[7],h=t[8];return r*n*h-r*o*u-i*a*h+i*o*l+s*a*u-s*n*l}invert(){let t=this.elements,r=t[0],i=t[1],s=t[2],a=t[3],n=t[4],o=t[5],l=t[6],u=t[7],h=t[8],d=h*n-o*u,c=o*l-h*a,m=u*a-n*l,g=r*d+i*c+s*m;if(g===0)return this.set(0,0,0,0,0,0,0,0,0);let y=1/g;return t[0]=d*y,t[1]=(s*u-h*i)*y,t[2]=(o*i-s*n)*y,t[3]=c*y,t[4]=(h*r-s*l)*y,t[5]=(s*a-o*r)*y,t[6]=m*y,t[7]=(i*l-u*r)*y,t[8]=(n*r-i*a)*y,this}transpose(){let t,r=this.elements;return t=r[1],r[1]=r[3],r[3]=t,t=r[2],r[2]=r[6],r[6]=t,t=r[5],r[5]=r[7],r[7]=t,this}getNormalMatrix(t){return this.setFromMatrix4(t).invert().transpose()}transposeIntoArray(t){let r=this.elements;return t[0]=r[0],t[1]=r[3],t[2]=r[6],t[3]=r[1],t[4]=r[4],t[5]=r[7],t[6]=r[2],t[7]=r[5],t[8]=r[8],this}setUvTransform(t,r,i,s,a,n,o){let l=Math.cos(a),u=Math.sin(a);return this.set(i*l,i*u,-i*(l*n+u*o)+n+t,-s*u,s*l,-s*(-u*n+l*o)+o+r,0,0,1),this}scale(t,r){return Et("Matrix3: .scale() is deprecated. Use .makeScale() instead."),this.premultiply(Tv.makeScale(t,r)),this}rotate(t){return Et("Matrix3: .rotate() is deprecated. Use .makeRotation() instead."),this.premultiply(Tv.makeRotation(-t)),this}translate(t,r){return Et("Matrix3: .translate() is deprecated. Use .makeTranslation() instead."),this.premultiply(Tv.makeTranslation(t,r)),this}makeTranslation(t,r){return t.isVector2?this.set(1,0,t.x,0,1,t.y,0,0,1):this.set(1,0,t,0,1,r,0,0,1),this}makeRotation(t){let r=Math.cos(t),i=Math.sin(t);return this.set(r,-i,0,i,r,0,0,0,1),this}makeScale(t,r){return this.set(t,0,0,0,r,0,0,0,1),this}equals(t){let r=this.elements,i=t.elements;for(let s=0;s<9;s++)if(r[s]!==i[s])return!1;return!0}fromArray(t,r=0){for(let i=0;i<9;i++)this.elements[i]=t[i+r];return this}toArray(t=[],r=0){let i=this.elements;return t[r]=i[0],t[r+1]=i[1],t[r+2]=i[2],t[r+3]=i[3],t[r+4]=i[4],t[r+5]=i[5],t[r+6]=i[6],t[r+7]=i[7],t[r+8]=i[8],t}clone(){return new this.constructor().fromArray(this.elements)}},Tv=new Dr,HM=new Dr().set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),XM=new Dr().set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);function g4(){let e={enabled:!0,workingColorSpace:Xh,spaces:{},convert:function(s,a,n){return this.enabled===!1||a===n||!a||!n||(this.spaces[a].transfer===Tt&&(s.r=ao(s.r),s.g=ao(s.g),s.b=ao(s.b)),this.spaces[a].primaries!==this.spaces[n].primaries&&(s.applyMatrix3(this.spaces[a].toXYZ),s.applyMatrix3(this.spaces[n].fromXYZ)),this.spaces[n].transfer===Tt&&(s.r=Jh(s.r),s.g=Jh(s.g),s.b=Jh(s.b))),s},workingToColorSpace:function(s,a){return this.convert(s,this.workingColorSpace,a)},colorSpaceToWorking:function(s,a){return this.convert(s,a,this.workingColorSpace)},getPrimaries:function(s){return this.spaces[s].primaries},getTransfer:function(s){return s===Fa?mg:this.spaces[s].transfer},getToneMappingMode:function(s){return this.spaces[s].outputColorSpaceConfig.toneMappingMode||"standard"},getLuminanceCoefficients:function(s,a=this.workingColorSpace){return s.fromArray(this.spaces[a].luminanceCoefficients)},define:function(s){Object.assign(this.spaces,s)},_getMatrix:function(s,a,n){return s.copy(this.spaces[a].toXYZ).multiply(this.spaces[n].fromXYZ)},_getDrawingBufferColorSpace:function(s){return this.spaces[s].outputColorSpaceConfig.drawingBufferColorSpace},_getUnpackColorSpace:function(s=this.workingColorSpace){return this.spaces[s].workingColorSpaceConfig.unpackColorSpace},fromWorkingColorSpace:function(s,a){return Et("ColorManagement: .fromWorkingColorSpace() has been renamed to .workingToColorSpace()."),e.workingToColorSpace(s,a)},toWorkingColorSpace:function(s,a){return Et("ColorManagement: .toWorkingColorSpace() has been renamed to .colorSpaceToWorking()."),e.colorSpaceToWorking(s,a)}},t=[.64,.33,.3,.6,.15,.06],r=[.2126,.7152,.0722],i=[.3127,.329];return e.define({[Xh]:{primaries:t,whitePoint:i,transfer:mg,toXYZ:HM,fromXYZ:XM,luminanceCoefficients:r,workingColorSpaceConfig:{unpackColorSpace:ds},outputColorSpaceConfig:{drawingBufferColorSpace:ds}},[ds]:{primaries:t,whitePoint:i,transfer:Tt,toXYZ:HM,fromXYZ:XM,luminanceCoefficients:r,outputColorSpaceConfig:{drawingBufferColorSpace:ds}}}),e}var Gt=g4();function ao(e){return e<.04045?e*.0773993808:Math.pow(e*.9478672986+.0521327014,2.4)}function Jh(e){return e<.0031308?e*12.92:1.055*Math.pow(e,.41666)-.055}var Qh,y4=class{static getDataURL(e,t="image/png"){if(/^data:/i.test(e.src)||typeof HTMLCanvasElement>"u")return e.src;let r;if(e instanceof HTMLCanvasElement)r=e;else{Qh===void 0&&(Qh=gg("canvas")),Qh.width=e.width,Qh.height=e.height;let i=Qh.getContext("2d");e instanceof ImageData?i.putImageData(e,0,0):i.drawImage(e,0,0,e.width,e.height),r=Qh}return r.toDataURL(t)}static sRGBToLinear(e){if(typeof HTMLImageElement<"u"&&e instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&e instanceof ImageBitmap){let t=gg("canvas");t.width=e.width,t.height=e.height;let r=t.getContext("2d");r.drawImage(e,0,0,e.width,e.height);let i=r.getImageData(0,0,e.width,e.height),s=i.data;for(let a=0;a1),this.pmremVersion=0,this.normalized=!1}get width(){return this.source.getSize(wv).x}get height(){return this.source.getSize(wv).y}get depth(){return this.source.getSize(wv).z}get image(){return this.source.data}set image(t){this.source.data=t}updateMatrix(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y)}addUpdateRange(t,r){this.updateRanges.push({start:t,count:r})}clearUpdateRanges(){this.updateRanges.length=0}clone(){return new this.constructor().copy(this)}copy(t){return this.name=t.name,this.source=t.source,this.mipmaps=t.mipmaps.slice(0),this.mapping=t.mapping,this.channel=t.channel,this.wrapS=t.wrapS,this.wrapT=t.wrapT,this.magFilter=t.magFilter,this.minFilter=t.minFilter,this.anisotropy=t.anisotropy,this.format=t.format,this.internalFormat=t.internalFormat,this.type=t.type,this.normalized=t.normalized,this.offset.copy(t.offset),this.repeat.copy(t.repeat),this.center.copy(t.center),this.rotation=t.rotation,this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrix.copy(t.matrix),this.generateMipmaps=t.generateMipmaps,this.premultiplyAlpha=t.premultiplyAlpha,this.flipY=t.flipY,this.unpackAlignment=t.unpackAlignment,this.colorSpace=t.colorSpace,this.renderTarget=t.renderTarget,this.isRenderTargetTexture=t.isRenderTargetTexture,this.isArrayTexture=t.isArrayTexture,this.userData=JSON.parse(JSON.stringify(t.userData)),this.needsUpdate=!0,this}setValues(t){for(let r in t){let i=t[r];if(i===void 0){Ue(`Texture.setValues(): parameter '${r}' has value of undefined.`);continue}let s=this[r];if(s===void 0){Ue(`Texture.setValues(): property '${r}' does not exist.`);continue}s&&i&&s.isVector2&&i.isVector2||s&&i&&s.isVector3&&i.isVector3||s&&i&&s.isMatrix3&&i.isMatrix3?s.copy(i):this[r]=i}}toJSON(t){let r=t===void 0||typeof t=="string";if(!r&&t.textures[this.uuid]!==void 0)return t.textures[this.uuid];let i={metadata:{version:4.7,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,image:this.source.toJSON(t).uuid,mapping:this.mapping,channel:this.channel,repeat:[this.repeat.x,this.repeat.y],offset:[this.offset.x,this.offset.y],center:[this.center.x,this.center.y],rotation:this.rotation,wrap:[this.wrapS,this.wrapT],format:this.format,internalFormat:this.internalFormat,type:this.type,normalized:this.normalized,colorSpace:this.colorSpace,minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy,flipY:this.flipY,generateMipmaps:this.generateMipmaps,premultiplyAlpha:this.premultiplyAlpha,unpackAlignment:this.unpackAlignment};return Object.keys(this.userData).length>0&&(i.userData=this.userData),r||(t.textures[this.uuid]=i),i}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(t){if(this.mapping!==rv)return t;if(t.applyMatrix3(this.matrix),t.x<0||t.x>1)switch(this.wrapS){case to:t.x=t.x-Math.floor(t.x);break;case Ti:t.x=t.x<0?0:1;break;case Qo:Math.abs(Math.floor(t.x)%2)===1?t.x=Math.ceil(t.x)-t.x:t.x=t.x-Math.floor(t.x);break}if(t.y<0||t.y>1)switch(this.wrapT){case to:t.y=t.y-Math.floor(t.y);break;case Ti:t.y=t.y<0?0:1;break;case Qo:Math.abs(Math.floor(t.y)%2)===1?t.y=Math.ceil(t.y)-t.y:t.y=t.y-Math.floor(t.y);break}return this.flipY&&(t.y=1-t.y),t}set needsUpdate(t){t===!0&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(t){t===!0&&this.pmremVersion++}};ji.DEFAULT_IMAGE=null,ji.DEFAULT_MAPPING=rv,ji.DEFAULT_ANISOTROPY=1;var Wt=class Uk{static{Uk.prototype.isVector4=!0}constructor(t=0,r=0,i=0,s=1){this.x=t,this.y=r,this.z=i,this.w=s}get width(){return this.z}set width(t){this.z=t}get height(){return this.w}set height(t){this.w=t}set(t,r,i,s){return this.x=t,this.y=r,this.z=i,this.w=s,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this.w=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setW(t){return this.w=t,this}setComponent(t,r){switch(t){case 0:this.x=r;break;case 1:this.y=r;break;case 2:this.z=r;break;case 3:this.w=r;break;default:throw new Error("THREE.Vector4: index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("THREE.Vector4: index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w!==void 0?t.w:1,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this.w+=t,this}addVectors(t,r){return this.x=t.x+r.x,this.y=t.y+r.y,this.z=t.z+r.z,this.w=t.w+r.w,this}addScaledVector(t,r){return this.x+=t.x*r,this.y+=t.y*r,this.z+=t.z*r,this.w+=t.w*r,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this.w-=t,this}subVectors(t,r){return this.x=t.x-r.x,this.y=t.y-r.y,this.z=t.z-r.z,this.w=t.w-r.w,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this.w*=t.w,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this}applyMatrix4(t){let r=this.x,i=this.y,s=this.z,a=this.w,n=t.elements;return this.x=n[0]*r+n[4]*i+n[8]*s+n[12]*a,this.y=n[1]*r+n[5]*i+n[9]*s+n[13]*a,this.z=n[2]*r+n[6]*i+n[10]*s+n[14]*a,this.w=n[3]*r+n[7]*i+n[11]*s+n[15]*a,this}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this.w/=t.w,this}divideScalar(t){return this.multiplyScalar(1/t)}setAxisAngleFromQuaternion(t){this.w=2*Math.acos(t.w);let r=Math.sqrt(1-t.w*t.w);return r<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=t.x/r,this.y=t.y/r,this.z=t.z/r),this}setAxisAngleFromRotationMatrix(t){let r,i,s,a,n=t.elements,o=n[0],l=n[4],u=n[8],h=n[1],d=n[5],c=n[9],m=n[2],g=n[6],y=n[10];if(Math.abs(l-h)<.01&&Math.abs(u-m)<.01&&Math.abs(c-g)<.01){if(Math.abs(l+h)<.1&&Math.abs(u+m)<.1&&Math.abs(c+g)<.1&&Math.abs(o+d+y-3)<.1)return this.set(1,0,0,0),this;r=Math.PI;let v=(o+1)/2,S=(d+1)/2,T=(y+1)/2,w=(l+h)/4,N=(u+m)/4,C=(c+g)/4;return v>S&&v>T?v<.01?(i=0,s=.707106781,a=.707106781):(i=Math.sqrt(v),s=w/i,a=N/i):S>T?S<.01?(i=.707106781,s=0,a=.707106781):(s=Math.sqrt(S),i=w/s,a=C/s):T<.01?(i=.707106781,s=.707106781,a=0):(a=Math.sqrt(T),i=N/a,s=C/a),this.set(i,s,a,r),this}let b=Math.sqrt((g-c)*(g-c)+(u-m)*(u-m)+(h-l)*(h-l));return Math.abs(b)<.001&&(b=1),this.x=(g-c)/b,this.y=(u-m)/b,this.z=(h-l)/b,this.w=Math.acos((o+d+y-1)/2),this}setFromMatrixPosition(t){let r=t.elements;return this.x=r[12],this.y=r[13],this.z=r[14],this.w=r[15],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this.w=Math.min(this.w,t.w),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this.w=Math.max(this.w,t.w),this}clamp(t,r){return this.x=St(this.x,t.x,r.x),this.y=St(this.y,t.y,r.y),this.z=St(this.z,t.z,r.z),this.w=St(this.w,t.w,r.w),this}clampScalar(t,r){return this.x=St(this.x,t,r),this.y=St(this.y,t,r),this.z=St(this.z,t,r),this.w=St(this.w,t,r),this}clampLength(t,r){let i=this.length();return this.divideScalar(i||1).multiplyScalar(St(i,t,r))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z+this.w*t.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,r){return this.x+=(t.x-this.x)*r,this.y+=(t.y-this.y)*r,this.z+=(t.z-this.z)*r,this.w+=(t.w-this.w)*r,this}lerpVectors(t,r,i){return this.x=t.x+(r.x-t.x)*i,this.y=t.y+(r.y-t.y)*i,this.z=t.z+(r.z-t.z)*i,this.w=t.w+(r.w-t.w)*i,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z&&t.w===this.w}fromArray(t,r=0){return this.x=t[r],this.y=t[r+1],this.z=t[r+2],this.w=t[r+3],this}toArray(t=[],r=0){return t[r]=this.x,t[r+1]=this.y,t[r+2]=this.z,t[r+3]=this.w,t}fromBufferAttribute(t,r){return this.x=t.getX(r),this.y=t.getY(r),this.z=t.getZ(r),this.w=t.getW(r),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}},er=class extends hn{constructor(e=1,t=1,r={}){super(),r=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:lr,depthBuffer:!0,stencilBuffer:!1,resolveDepthBuffer:!0,resolveStencilBuffer:!0,depthTexture:null,samples:0,count:1,depth:1,multiview:!1,useArrayDepthTexture:!1},r),this.isRenderTarget=!0,this.width=e,this.height=t,this.depth=r.depth,this.scissor=new Wt(0,0,e,t),this.scissorTest=!1,this.viewport=new Wt(0,0,e,t),this.textures=[];let i={width:e,height:t,depth:r.depth},s=new ji(i),a=r.count;for(let n=0;n1);this.dispose()}this.viewport.set(0,0,e,t),this.scissor.set(0,0,e,t)}clone(){return new this.constructor().copy(this)}copy(e){this.width=e.width,this.height=e.height,this.depth=e.depth,this.scissor.copy(e.scissor),this.scissorTest=e.scissorTest,this.viewport.copy(e.viewport),this.textures.length=0;for(let t=0,r=e.textures.length;t>>0}enable(e){this.mask|=1<1){for(let r=0;r1){for(let i=0;i0&&(s.userData=this.userData),s.layers=this.layers.mask,s.matrix=this.matrix.toArray(),s.up=this.up.toArray(),this.pivot!==null&&(s.pivot=this.pivot.toArray()),this.matrixAutoUpdate===!1&&(s.matrixAutoUpdate=!1),this.morphTargetDictionary!==void 0&&(s.morphTargetDictionary=Object.assign({},this.morphTargetDictionary)),this.morphTargetInfluences!==void 0&&(s.morphTargetInfluences=this.morphTargetInfluences.slice()),this.isInstancedMesh&&(s.type="InstancedMesh",s.count=this.count,s.instanceMatrix=this.instanceMatrix.toJSON(),this.instanceColor!==null&&(s.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(s.type="BatchedMesh",s.perObjectFrustumCulled=this.perObjectFrustumCulled,s.sortObjects=this.sortObjects,s.drawRanges=this._drawRanges,s.reservedRanges=this._reservedRanges,s.geometryInfo=this._geometryInfo.map(o=>({...o,boundingBox:o.boundingBox?o.boundingBox.toJSON():void 0,boundingSphere:o.boundingSphere?o.boundingSphere.toJSON():void 0})),s.instanceInfo=this._instanceInfo.map(o=>({...o})),s.availableInstanceIds=this._availableInstanceIds.slice(),s.availableGeometryIds=this._availableGeometryIds.slice(),s.nextIndexStart=this._nextIndexStart,s.nextVertexStart=this._nextVertexStart,s.geometryCount=this._geometryCount,s.maxInstanceCount=this._maxInstanceCount,s.maxVertexCount=this._maxVertexCount,s.maxIndexCount=this._maxIndexCount,s.geometryInitialized=this._geometryInitialized,s.matricesTexture=this._matricesTexture.toJSON(t),s.indirectTexture=this._indirectTexture.toJSON(t),this._colorsTexture!==null&&(s.colorsTexture=this._colorsTexture.toJSON(t)),this.boundingSphere!==null&&(s.boundingSphere=this.boundingSphere.toJSON()),this.boundingBox!==null&&(s.boundingBox=this.boundingBox.toJSON()));function a(o,l){return o[l.uuid]===void 0&&(o[l.uuid]=l.toJSON(t)),l.uuid}if(this.isScene)this.background&&(this.background.isColor?s.background=this.background.toJSON():this.background.isTexture&&(s.background=this.background.toJSON(t).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(s.environment=this.environment.toJSON(t).uuid);else if(this.isMesh||this.isLine||this.isPoints){s.geometry=a(t.geometries,this.geometry);let o=this.geometry.parameters;if(o!==void 0&&o.shapes!==void 0){let l=o.shapes;if(Array.isArray(l))for(let u=0,h=l.length;u0){s.children=[];for(let o=0;o0){s.animations=[];for(let o=0;o0&&(i.geometries=o),l.length>0&&(i.materials=l),u.length>0&&(i.textures=u),h.length>0&&(i.images=h),d.length>0&&(i.shapes=d),c.length>0&&(i.skeletons=c),m.length>0&&(i.animations=m),g.length>0&&(i.nodes=g)}return i.object=s,i;function n(o){let l=[];for(let u in o){let h=o[u];delete h.metadata,l.push(h)}return l}}clone(t){return new this.constructor().copy(this,t)}copy(t,r=!0){if(this.name=t.name,this.up.copy(t.up),this.position.copy(t.position),this.rotation.order=t.rotation.order,this.quaternion.copy(t.quaternion),this.scale.copy(t.scale),this.pivot=t.pivot!==null?t.pivot.clone():null,this.matrix.copy(t.matrix),this.matrixWorld.copy(t.matrixWorld),this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrixWorldAutoUpdate=t.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=t.matrixWorldNeedsUpdate,this.layers.mask=t.layers.mask,this.visible=t.visible,this.castShadow=t.castShadow,this.receiveShadow=t.receiveShadow,this.frustumCulled=t.frustumCulled,this.renderOrder=t.renderOrder,this.static=t.static,this.animations=t.animations.slice(),this.userData=JSON.parse(JSON.stringify(t.userData)),r===!0)for(let i=0;ic+m?(l.inputState.pinching=!1,this.dispatchEvent({type:"pinchend",handedness:e.handedness,target:this})):!l.inputState.pinching&&d<=c-m&&(l.inputState.pinching=!0,this.dispatchEvent({type:"pinchstart",handedness:e.handedness,target:this}))}else o!==null&&e.gripSpace&&(s=t.getPose(e.gripSpace,r),s!==null&&(o.matrix.fromArray(s.transform.matrix),o.matrix.decompose(o.position,o.rotation,o.scale),o.matrixWorldNeedsUpdate=!0,s.linearVelocity?(o.hasLinearVelocity=!0,o.linearVelocity.copy(s.linearVelocity)):o.hasLinearVelocity=!1,s.angularVelocity?(o.hasAngularVelocity=!0,o.angularVelocity.copy(s.angularVelocity)):o.hasAngularVelocity=!1,o.eventsEnabled&&o.dispatchEvent({type:"gripUpdated",data:e,target:this})));n!==null&&(i=t.getPose(e.targetRaySpace,r),i===null&&s!==null&&(i=s),i!==null&&(n.matrix.fromArray(i.transform.matrix),n.matrix.decompose(n.position,n.rotation,n.scale),n.matrixWorldNeedsUpdate=!0,i.linearVelocity?(n.hasLinearVelocity=!0,n.linearVelocity.copy(i.linearVelocity)):n.hasLinearVelocity=!1,i.angularVelocity?(n.hasAngularVelocity=!0,n.angularVelocity.copy(i.angularVelocity)):n.hasAngularVelocity=!1,this.dispatchEvent(R4)))}return n!==null&&(n.visible=i!==null),o!==null&&(o.visible=s!==null),l!==null&&(l.visible=a!==null),this}_getHandJoint(e,t){if(e.joints[t.jointName]===void 0){let r=new pn;r.matrixAutoUpdate=!1,r.visible=!1,e.joints[t.jointName]=r,e.add(r)}return e.joints[t.jointName]}},eN={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074},tl={h:0,s:0,l:0},vg={h:0,s:0,l:0};function Nv(e,t,r){return r<0&&(r+=1),r>1&&(r-=1),r<.16666666666666666?e+(t-e)*6*r:r<.5?t:r<.6666666666666666?e+(t-e)*6*(.6666666666666666-r):e}var gt=class{constructor(e,t,r){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(e,t,r)}set(e,t,r){if(t===void 0&&r===void 0){let i=e;i&&i.isColor?this.copy(i):typeof i=="number"?this.setHex(i):typeof i=="string"&&this.setStyle(i)}else this.setRGB(e,t,r);return this}setScalar(e){return this.r=e,this.g=e,this.b=e,this}setHex(e,t=ds){return e=Math.floor(e),this.r=(e>>16&255)/255,this.g=(e>>8&255)/255,this.b=(e&255)/255,Gt.colorSpaceToWorking(this,t),this}setRGB(e,t,r,i=Gt.workingColorSpace){return this.r=e,this.g=t,this.b=r,Gt.colorSpaceToWorking(this,i),this}setHSL(e,t,r,i=Gt.workingColorSpace){if(e=vv(e,1),t=St(t,0,1),r=St(r,0,1),t===0)this.r=this.g=this.b=r;else{let s=r<=.5?r*(1+t):r+t-r*t,a=2*r-s;this.r=Nv(a,s,e+1/3),this.g=Nv(a,s,e),this.b=Nv(a,s,e-1/3)}return Gt.colorSpaceToWorking(this,i),this}setStyle(e,t=ds){function r(s){s!==void 0&&parseFloat(s)<1&&Ue("Color: Alpha component of "+e+" will be ignored.")}let i;if(i=/^(\w+)\(([^\)]*)\)/.exec(e)){let s,a=i[1],n=i[2];switch(a){case"rgb":case"rgba":if(s=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(n))return r(s[4]),this.setRGB(Math.min(255,parseInt(s[1],10))/255,Math.min(255,parseInt(s[2],10))/255,Math.min(255,parseInt(s[3],10))/255,t);if(s=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(n))return r(s[4]),this.setRGB(Math.min(100,parseInt(s[1],10))/100,Math.min(100,parseInt(s[2],10))/100,Math.min(100,parseInt(s[3],10))/100,t);break;case"hsl":case"hsla":if(s=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(n))return r(s[4]),this.setHSL(parseFloat(s[1])/360,parseFloat(s[2])/100,parseFloat(s[3])/100,t);break;default:Ue("Color: Unknown color model "+e)}}else if(i=/^\#([A-Fa-f\d]+)$/.exec(e)){let s=i[1],a=s.length;if(a===3)return this.setRGB(parseInt(s.charAt(0),16)/15,parseInt(s.charAt(1),16)/15,parseInt(s.charAt(2),16)/15,t);if(a===6)return this.setHex(parseInt(s,16),t);Ue("Color: Invalid hex color "+e)}else if(e&&e.length>0)return this.setColorName(e,t);return this}setColorName(e,t=ds){let r=eN[e.toLowerCase()];return r!==void 0?this.setHex(r,t):Ue("Color: Unknown color "+e),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(e){return this.r=e.r,this.g=e.g,this.b=e.b,this}copySRGBToLinear(e){return this.r=ao(e.r),this.g=ao(e.g),this.b=ao(e.b),this}copyLinearToSRGB(e){return this.r=Jh(e.r),this.g=Jh(e.g),this.b=Jh(e.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(e=ds){return Gt.workingToColorSpace(Xi.copy(this),e),Math.round(St(Xi.r*255,0,255))*65536+Math.round(St(Xi.g*255,0,255))*256+Math.round(St(Xi.b*255,0,255))}getHexString(e=ds){return("000000"+this.getHex(e).toString(16)).slice(-6)}getHSL(e,t=Gt.workingColorSpace){Gt.workingToColorSpace(Xi.copy(this),t);let r=Xi.r,i=Xi.g,s=Xi.b,a=Math.max(r,i,s),n=Math.min(r,i,s),o,l,u=(n+a)/2;if(n===a)o=0,l=0;else{let h=a-n;switch(l=u<=.5?h/(a+n):h/(2-a-n),a){case r:o=(i-s)/h+(i0&&(t.object.backgroundBlurriness=this.backgroundBlurriness),this.backgroundIntensity!==1&&(t.object.backgroundIntensity=this.backgroundIntensity),t.object.backgroundRotation=this.backgroundRotation.toArray(),this.environmentIntensity!==1&&(t.object.environmentIntensity=this.environmentIntensity),t.object.environmentRotation=this.environmentRotation.toArray(),t}},ka=new F,oo=new F,Av=new F,lo=new F,rd=new F,id=new F,tN=new F,Cv=new F,Rv=new F,Ev=new F,Pv=new Wt,Bv=new Wt,Iv=new Wt,$i=class Hc{constructor(t=new F,r=new F,i=new F){this.a=t,this.b=r,this.c=i}static getNormal(t,r,i,s){s.subVectors(i,r),ka.subVectors(t,r),s.cross(ka);let a=s.lengthSq();return a>0?s.multiplyScalar(1/Math.sqrt(a)):s.set(0,0,0)}static getBarycoord(t,r,i,s,a){ka.subVectors(s,r),oo.subVectors(i,r),Av.subVectors(t,r);let n=ka.dot(ka),o=ka.dot(oo),l=ka.dot(Av),u=oo.dot(oo),h=oo.dot(Av),d=n*u-o*o;if(d===0)return a.set(0,0,0),null;let c=1/d,m=(u*l-o*h)*c,g=(n*h-o*l)*c;return a.set(1-m-g,g,m)}static containsPoint(t,r,i,s){return this.getBarycoord(t,r,i,s,lo)===null?!1:lo.x>=0&&lo.y>=0&&lo.x+lo.y<=1}static getInterpolation(t,r,i,s,a,n,o,l){return this.getBarycoord(t,r,i,s,lo)===null?(l.x=0,l.y=0,"z"in l&&(l.z=0),"w"in l&&(l.w=0),null):(l.setScalar(0),l.addScaledVector(a,lo.x),l.addScaledVector(n,lo.y),l.addScaledVector(o,lo.z),l)}static getInterpolatedAttribute(t,r,i,s,a,n){return Pv.setScalar(0),Bv.setScalar(0),Iv.setScalar(0),Pv.fromBufferAttribute(t,r),Bv.fromBufferAttribute(t,i),Iv.fromBufferAttribute(t,s),n.setScalar(0),n.addScaledVector(Pv,a.x),n.addScaledVector(Bv,a.y),n.addScaledVector(Iv,a.z),n}static isFrontFacing(t,r,i,s){return ka.subVectors(i,r),oo.subVectors(t,r),ka.cross(oo).dot(s)<0}set(t,r,i){return this.a.copy(t),this.b.copy(r),this.c.copy(i),this}setFromPointsAndIndices(t,r,i,s){return this.a.copy(t[r]),this.b.copy(t[i]),this.c.copy(t[s]),this}setFromAttributeAndIndices(t,r,i,s){return this.a.fromBufferAttribute(t,r),this.b.fromBufferAttribute(t,i),this.c.fromBufferAttribute(t,s),this}clone(){return new this.constructor().copy(this)}copy(t){return this.a.copy(t.a),this.b.copy(t.b),this.c.copy(t.c),this}getArea(){return ka.subVectors(this.c,this.b),oo.subVectors(this.a,this.b),ka.cross(oo).length()*.5}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return Hc.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,r){return Hc.getBarycoord(t,this.a,this.b,this.c,r)}getInterpolation(t,r,i,s,a){return Hc.getInterpolation(t,this.a,this.b,this.c,r,i,s,a)}containsPoint(t){return Hc.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return Hc.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(t){return t.intersectsTriangle(this)}closestPointToPoint(t,r){let i=this.a,s=this.b,a=this.c,n,o;rd.subVectors(s,i),id.subVectors(a,i),Cv.subVectors(t,i);let l=rd.dot(Cv),u=id.dot(Cv);if(l<=0&&u<=0)return r.copy(i);Rv.subVectors(t,s);let h=rd.dot(Rv),d=id.dot(Rv);if(h>=0&&d<=h)return r.copy(s);let c=l*d-h*u;if(c<=0&&l>=0&&h<=0)return n=l/(l-h),r.copy(i).addScaledVector(rd,n);Ev.subVectors(t,a);let m=rd.dot(Ev),g=id.dot(Ev);if(g>=0&&m<=g)return r.copy(a);let y=m*u-l*g;if(y<=0&&u>=0&&g<=0)return o=u/(u-g),r.copy(i).addScaledVector(id,o);let b=h*g-m*d;if(b<=0&&d-h>=0&&m-g>=0)return tN.subVectors(a,s),o=(d-h)/(d-h+(m-g)),r.copy(s).addScaledVector(tN,o);let v=1/(b+y+c);return n=y*v,o=c*v,r.copy(i).addScaledVector(rd,n).addScaledVector(id,o)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}},qi=class{constructor(e=new F(1/0,1/0,1/0),t=new F(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=e,this.max=t}set(e,t){return this.min.copy(e),this.max.copy(t),this}setFromArray(e){this.makeEmpty();for(let t=0,r=e.length;t=this.min.x&&e.x<=this.max.x&&e.y>=this.min.y&&e.y<=this.max.y&&e.z>=this.min.z&&e.z<=this.max.z}containsBox(e){return this.min.x<=e.min.x&&e.max.x<=this.max.x&&this.min.y<=e.min.y&&e.max.y<=this.max.y&&this.min.z<=e.min.z&&e.max.z<=this.max.z}getParameter(e,t){return t.set((e.x-this.min.x)/(this.max.x-this.min.x),(e.y-this.min.y)/(this.max.y-this.min.y),(e.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(e){return e.max.x>=this.min.x&&e.min.x<=this.max.x&&e.max.y>=this.min.y&&e.min.y<=this.max.y&&e.max.z>=this.min.z&&e.min.z<=this.max.z}intersectsSphere(e){return this.clampPoint(e.center,Da),Da.distanceToSquared(e.center)<=e.radius*e.radius}intersectsPlane(e){let t,r;return e.normal.x>0?(t=e.normal.x*this.min.x,r=e.normal.x*this.max.x):(t=e.normal.x*this.max.x,r=e.normal.x*this.min.x),e.normal.y>0?(t+=e.normal.y*this.min.y,r+=e.normal.y*this.max.y):(t+=e.normal.y*this.max.y,r+=e.normal.y*this.min.y),e.normal.z>0?(t+=e.normal.z*this.min.z,r+=e.normal.z*this.max.z):(t+=e.normal.z*this.max.z,r+=e.normal.z*this.min.z),t<=-e.constant&&r>=-e.constant}intersectsTriangle(e){if(this.isEmpty())return!1;this.getCenter(op),Sg.subVectors(this.max,op),sd.subVectors(e.a,op),ad.subVectors(e.b,op),nd.subVectors(e.c,op),rl.subVectors(ad,sd),il.subVectors(nd,ad),gu.subVectors(sd,nd);let t=[0,-rl.z,rl.y,0,-il.z,il.y,0,-gu.z,gu.y,rl.z,0,-rl.x,il.z,0,-il.x,gu.z,0,-gu.x,-rl.y,rl.x,0,-il.y,il.x,0,-gu.y,gu.x,0];return!Fv(t,sd,ad,nd,Sg)||(t=[1,0,0,0,1,0,0,0,1],!Fv(t,sd,ad,nd,Sg))?!1:(_g.crossVectors(rl,il),t=[_g.x,_g.y,_g.z],Fv(t,sd,ad,nd,Sg))}clampPoint(e,t){return t.copy(e).clamp(this.min,this.max)}distanceToPoint(e){return this.clampPoint(e,Da).distanceTo(e)}getBoundingSphere(e){return this.isEmpty()?e.makeEmpty():(this.getCenter(e.center),e.radius=this.getSize(Da).length()*.5),e}intersect(e){return this.min.max(e.min),this.max.min(e.max),this.isEmpty()&&this.makeEmpty(),this}union(e){return this.min.min(e.min),this.max.max(e.max),this}applyMatrix4(e){return this.isEmpty()?this:(uo[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(e),uo[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(e),uo[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(e),uo[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(e),uo[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(e),uo[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(e),uo[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(e),uo[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(e),this.setFromPoints(uo),this)}translate(e){return this.min.add(e),this.max.add(e),this}equals(e){return e.min.equals(this.min)&&e.max.equals(this.max)}toJSON(){return{min:this.min.toArray(),max:this.max.toArray()}}fromJSON(e){return this.min.fromArray(e.min),this.max.fromArray(e.max),this}},uo=[new F,new F,new F,new F,new F,new F,new F,new F],Da=new F,Tg=new qi,sd=new F,ad=new F,nd=new F,rl=new F,il=new F,gu=new F,op=new F,Sg=new F,_g=new F,yu=new F;function Fv(e,t,r,i,s){for(let a=0,n=e.length-3;a<=n;a+=3){yu.fromArray(e,a);let o=s.x*Math.abs(yu.x)+s.y*Math.abs(yu.y)+s.z*Math.abs(yu.z),l=t.dot(yu),u=r.dot(yu),h=i.dot(yu);if(Math.max(-Math.max(l,u,h),Math.min(l,u,h))>o)return!1}return!0}var ho=P4();function P4(){let e=new ArrayBuffer(4),t=new Float32Array(e),r=new Uint32Array(e),i=new Uint32Array(512),s=new Uint32Array(512);for(let l=0;l<256;++l){let u=l-127;u<-27?(i[l]=0,i[l|256]=32768,s[l]=24,s[l|256]=24):u<-14?(i[l]=1024>>-u-14,i[l|256]=1024>>-u-14|32768,s[l]=-u-1,s[l|256]=-u-1):u<=15?(i[l]=u+15<<10,i[l|256]=u+15<<10|32768,s[l]=13,s[l|256]=13):u<128?(i[l]=31744,i[l|256]=64512,s[l]=24,s[l|256]=24):(i[l]=31744,i[l|256]=64512,s[l]=13,s[l|256]=13)}let a=new Uint32Array(2048),n=new Uint32Array(64),o=new Uint32Array(64);for(let l=1;l<1024;++l){let u=l<<13,h=0;for(;(u&8388608)===0;)u<<=1,h-=8388608;u&=-8388609,h+=947912704,a[l]=u|h}for(let l=1024;l<2048;++l)a[l]=939524096+(l-1024<<13);for(let l=1;l<31;++l)n[l]=l<<23;n[31]=1199570944,n[32]=2147483648;for(let l=33;l<63;++l)n[l]=2147483648+(l-32<<23);n[63]=3347054592;for(let l=1;l<64;++l)l!==32&&(o[l]=1024);return{floatView:t,uint32View:r,baseTable:i,shiftTable:s,mantissaTable:a,exponentTable:n,offsetTable:o}}function Us(e){Math.abs(e)>65504&&Ue("DataUtils.toHalfFloat(): Value out of range."),e=St(e,-65504,65504),ho.floatView[0]=e;let t=ho.uint32View[0],r=t>>23&511;return ho.baseTable[r]+((t&8388607)>>ho.shiftTable[r])}function wg(e){let t=e>>10;return ho.uint32View[0]=ho.mantissaTable[ho.offsetTable[t]+(e&1023)]+ho.exponentTable[t],ho.floatView[0]}var ai=new F,Mg=new fe,B4=0,_i=class extends hn{constructor(e,t,r=!1){if(super(),Array.isArray(e))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,Object.defineProperty(this,"id",{value:B4++}),this.name="",this.array=e,this.itemSize=t,this.count=e!==void 0?e.length/t:0,this.normalized=r,this.usage=qh,this.updateRanges=[],this.gpuType=Er,this.version=0}onUploadCallback(){}set needsUpdate(e){e===!0&&this.version++}setUsage(e){return this.usage=e,this}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}copy(e){return this.name=e.name,this.array=new e.array.constructor(e.array),this.itemSize=e.itemSize,this.count=e.count,this.normalized=e.normalized,this.usage=e.usage,this.gpuType=e.gpuType,this}copyAt(e,t,r){e*=this.itemSize,r*=t.itemSize;for(let i=0,s=this.itemSize;ithis.radius*this.radius&&(t.sub(this.center).normalize(),t.multiplyScalar(this.radius).add(this.center)),t}getBoundingBox(e){return this.isEmpty()?(e.makeEmpty(),e):(e.set(this.center,this.center),e.expandByScalar(this.radius),e)}applyMatrix4(e){return this.center.applyMatrix4(e),this.radius=this.radius*e.getMaxScaleOnAxis(),this}translate(e){return this.center.add(e),this}expandByPoint(e){if(this.isEmpty())return this.center.copy(e),this.radius=0,this;lp.subVectors(e,this.center);let t=lp.lengthSq();if(t>this.radius*this.radius){let r=Math.sqrt(t),i=(r-this.radius)*.5;this.center.addScaledVector(lp,i/r),this.radius+=i}return this}union(e){return e.isEmpty()?this:this.isEmpty()?(this.copy(e),this):(this.center.equals(e.center)===!0?this.radius=Math.max(this.radius,e.radius):(Lv.subVectors(e.center,this.center).setLength(e.radius),this.expandByPoint(lp.copy(e.center).add(Lv)),this.expandByPoint(lp.copy(e.center).sub(Lv))),this)}equals(e){return e.center.equals(this.center)&&e.radius===this.radius}clone(){return new this.constructor().copy(this)}toJSON(){return{radius:this.radius,center:this.center.toArray()}}fromJSON(e){return this.radius=e.radius,this.center.fromArray(e.center),this}},F4=0,ca=new We,kv=new Hi,od=new F,zs=new qi,up=new qi,wi=new F,ps=class Vk extends hn{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:F4++}),this.uuid=dn(),this.name="",this.type="BufferGeometry",this.index=null,this.indirect=null,this.indirectOffset=0,this.attributes={},this.morphAttributes={},this.morphTargetsRelative=!1,this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.drawRange={start:0,count:1/0},this.userData={},this._transformed=!1}getIndex(){return this.index}setIndex(t){return Array.isArray(t)?this.index=new(QD(t)?iN:rN)(t,1):this.index=t,this}setIndirect(t,r=0){return this.indirect=t,this.indirectOffset=r,this}getIndirect(){return this.indirect}getAttribute(t){return this.attributes[t]}setAttribute(t,r){return this.attributes[t]=r,this}deleteAttribute(t){return delete this.attributes[t],this}hasAttribute(t){return this.attributes[t]!==void 0}addGroup(t,r,i=0){this.groups.push({start:t,count:r,materialIndex:i})}clearGroups(){this.groups=[]}setDrawRange(t,r){this.drawRange.start=t,this.drawRange.count=r}applyMatrix4(t){let r=this.attributes.position;r!==void 0&&(r.applyMatrix4(t),r.needsUpdate=!0);let i=this.attributes.normal;if(i!==void 0){let a=new Dr().getNormalMatrix(t);i.applyNormalMatrix(a),i.needsUpdate=!0}let s=this.attributes.tangent;return s!==void 0&&(s.transformDirection(t),s.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this._transformed=!0,this}applyQuaternion(t){return ca.makeRotationFromQuaternion(t),this.applyMatrix4(ca),this}rotateX(t){return ca.makeRotationX(t),this.applyMatrix4(ca),this}rotateY(t){return ca.makeRotationY(t),this.applyMatrix4(ca),this}rotateZ(t){return ca.makeRotationZ(t),this.applyMatrix4(ca),this}translate(t,r,i){return ca.makeTranslation(t,r,i),this.applyMatrix4(ca),this}scale(t,r,i){return ca.makeScale(t,r,i),this.applyMatrix4(ca),this}lookAt(t){return kv.lookAt(t),kv.updateMatrix(),this.applyMatrix4(kv.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(od).negate(),this.translate(od.x,od.y,od.z),this}setFromPoints(t){let r=this.getAttribute("position");if(r===void 0){let i=[];for(let s=0,a=t.length;sr.count&&Ue("BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry."),r.needsUpdate=!0}return this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new qi);let t=this.attributes.position,r=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){Ce("BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),this.boundingBox.set(new F(-1/0,-1/0,-1/0),new F(1/0,1/0,1/0));return}if(t!==void 0){if(this.boundingBox.setFromBufferAttribute(t),r)for(let i=0,s=r.length;i0&&(t.userData=this.userData),this.parameters!==void 0&&this._transformed!==!0){let l=this.parameters;for(let u in l)l[u]!==void 0&&(t[u]=l[u]);return t}t.data={attributes:{}};let r=this.index;r!==null&&(t.data.index={type:r.array.constructor.name,array:Array.prototype.slice.call(r.array)});let i=this.attributes;for(let l in i){let u=i[l];t.data.attributes[l]=u.toJSON(t.data)}let s={},a=!1;for(let l in this.morphAttributes){let u=this.morphAttributes[l],h=[];for(let d=0,c=u.length;d0&&(s[l]=h,a=!0)}a&&(t.data.morphAttributes=s,t.data.morphTargetsRelative=this.morphTargetsRelative);let n=this.groups;n.length>0&&(t.data.groups=JSON.parse(JSON.stringify(n)));let o=this.boundingSphere;return o!==null&&(t.data.boundingSphere=o.toJSON()),t}clone(){return new this.constructor().copy(this)}copy(t){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;let r={};this.name=t.name;let i=t.index;i!==null&&this.setIndex(i.clone());let s=t.attributes;for(let u in s){let h=s[u];this.setAttribute(u,h.clone(r))}let a=t.morphAttributes;for(let u in a){let h=[],d=a[u];for(let c=0,m=d.length;c0!=e>0&&this.version++,this._alphaTest=e}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(e){if(e!==void 0)for(let t in e){let r=e[t];if(r===void 0){Ue(`Material: parameter '${t}' has value of undefined.`);continue}let i=this[t];if(i===void 0){Ue(`Material: '${t}' is not a property of THREE.${this.type}.`);continue}i&&i.isColor?i.set(r):i&&i.isVector2&&r&&r.isVector2||i&&i.isEuler&&r&&r.isEuler||i&&i.isVector3&&r&&r.isVector3?i.copy(r):this[t]=r}}toJSON(e){let t=e===void 0||typeof e=="string";t&&(e={textures:{},images:{}});let r={metadata:{version:4.7,type:"Material",generator:"Material.toJSON"}};r.uuid=this.uuid,r.type=this.type,this.name!==""&&(r.name=this.name),this.color&&this.color.isColor&&(r.color=this.color.getHex()),this.roughness!==void 0&&(r.roughness=this.roughness),this.metalness!==void 0&&(r.metalness=this.metalness),this.sheen!==void 0&&(r.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(r.sheenColor=this.sheenColor.getHex()),this.sheenRoughness!==void 0&&(r.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(r.emissive=this.emissive.getHex()),this.emissiveIntensity!==void 0&&this.emissiveIntensity!==1&&(r.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(r.specular=this.specular.getHex()),this.specularIntensity!==void 0&&(r.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(r.specularColor=this.specularColor.getHex()),this.shininess!==void 0&&(r.shininess=this.shininess),this.clearcoat!==void 0&&(r.clearcoat=this.clearcoat),this.clearcoatRoughness!==void 0&&(r.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(r.clearcoatMap=this.clearcoatMap.toJSON(e).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(r.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(e).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(r.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(e).uuid,r.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),this.sheenColorMap&&this.sheenColorMap.isTexture&&(r.sheenColorMap=this.sheenColorMap.toJSON(e).uuid),this.sheenRoughnessMap&&this.sheenRoughnessMap.isTexture&&(r.sheenRoughnessMap=this.sheenRoughnessMap.toJSON(e).uuid),this.dispersion!==void 0&&(r.dispersion=this.dispersion),this.iridescence!==void 0&&(r.iridescence=this.iridescence),this.iridescenceIOR!==void 0&&(r.iridescenceIOR=this.iridescenceIOR),this.iridescenceThicknessRange!==void 0&&(r.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(r.iridescenceMap=this.iridescenceMap.toJSON(e).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(r.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(e).uuid),this.anisotropy!==void 0&&(r.anisotropy=this.anisotropy),this.anisotropyRotation!==void 0&&(r.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(r.anisotropyMap=this.anisotropyMap.toJSON(e).uuid),this.map&&this.map.isTexture&&(r.map=this.map.toJSON(e).uuid),this.matcap&&this.matcap.isTexture&&(r.matcap=this.matcap.toJSON(e).uuid),this.alphaMap&&this.alphaMap.isTexture&&(r.alphaMap=this.alphaMap.toJSON(e).uuid),this.lightMap&&this.lightMap.isTexture&&(r.lightMap=this.lightMap.toJSON(e).uuid,r.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(r.aoMap=this.aoMap.toJSON(e).uuid,r.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(r.bumpMap=this.bumpMap.toJSON(e).uuid,r.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(r.normalMap=this.normalMap.toJSON(e).uuid,r.normalMapType=this.normalMapType,r.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(r.displacementMap=this.displacementMap.toJSON(e).uuid,r.displacementScale=this.displacementScale,r.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(r.roughnessMap=this.roughnessMap.toJSON(e).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(r.metalnessMap=this.metalnessMap.toJSON(e).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(r.emissiveMap=this.emissiveMap.toJSON(e).uuid),this.specularMap&&this.specularMap.isTexture&&(r.specularMap=this.specularMap.toJSON(e).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(r.specularIntensityMap=this.specularIntensityMap.toJSON(e).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(r.specularColorMap=this.specularColorMap.toJSON(e).uuid),this.envMap&&this.envMap.isTexture&&(r.envMap=this.envMap.toJSON(e).uuid,this.combine!==void 0&&(r.combine=this.combine)),this.envMapRotation!==void 0&&(r.envMapRotation=this.envMapRotation.toArray()),this.envMapIntensity!==void 0&&(r.envMapIntensity=this.envMapIntensity),this.reflectivity!==void 0&&(r.reflectivity=this.reflectivity),this.refractionRatio!==void 0&&(r.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(r.gradientMap=this.gradientMap.toJSON(e).uuid),this.transmission!==void 0&&(r.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(r.transmissionMap=this.transmissionMap.toJSON(e).uuid),this.thickness!==void 0&&(r.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(r.thicknessMap=this.thicknessMap.toJSON(e).uuid),this.attenuationDistance!==void 0&&this.attenuationDistance!==1/0&&(r.attenuationDistance=this.attenuationDistance),this.attenuationColor!==void 0&&(r.attenuationColor=this.attenuationColor.getHex()),this.size!==void 0&&(r.size=this.size),this.shadowSide!==null&&(r.shadowSide=this.shadowSide),this.sizeAttenuation!==void 0&&(r.sizeAttenuation=this.sizeAttenuation),this.blending!==oa&&(r.blending=this.blending),this.side!==Cs&&(r.side=this.side),this.vertexColors===!0&&(r.vertexColors=!0),this.opacity<1&&(r.opacity=this.opacity),this.transparent===!0&&(r.transparent=!0),this.blendSrc!==$c&&(r.blendSrc=this.blendSrc),this.blendDst!==qc&&(r.blendDst=this.blendDst),this.blendEquation!==la&&(r.blendEquation=this.blendEquation),this.blendSrcAlpha!==null&&(r.blendSrcAlpha=this.blendSrcAlpha),this.blendDstAlpha!==null&&(r.blendDstAlpha=this.blendDstAlpha),this.blendEquationAlpha!==null&&(r.blendEquationAlpha=this.blendEquationAlpha),this.blendColor&&this.blendColor.isColor&&(r.blendColor=this.blendColor.getHex()),this.blendAlpha!==0&&(r.blendAlpha=this.blendAlpha),this.depthFunc!==zh&&(r.depthFunc=this.depthFunc),this.depthTest===!1&&(r.depthTest=this.depthTest),this.depthWrite===!1&&(r.depthWrite=this.depthWrite),this.colorWrite===!1&&(r.colorWrite=this.colorWrite),this.stencilWriteMask!==255&&(r.stencilWriteMask=this.stencilWriteMask),this.stencilFunc!==gv&&(r.stencilFunc=this.stencilFunc),this.stencilRef!==0&&(r.stencilRef=this.stencilRef),this.stencilFuncMask!==255&&(r.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==mu&&(r.stencilFail=this.stencilFail),this.stencilZFail!==mu&&(r.stencilZFail=this.stencilZFail),this.stencilZPass!==mu&&(r.stencilZPass=this.stencilZPass),this.stencilWrite===!0&&(r.stencilWrite=this.stencilWrite),this.rotation!==void 0&&this.rotation!==0&&(r.rotation=this.rotation),this.polygonOffset===!0&&(r.polygonOffset=!0),this.polygonOffsetFactor!==0&&(r.polygonOffsetFactor=this.polygonOffsetFactor),this.polygonOffsetUnits!==0&&(r.polygonOffsetUnits=this.polygonOffsetUnits),this.linewidth!==void 0&&this.linewidth!==1&&(r.linewidth=this.linewidth),this.dashSize!==void 0&&(r.dashSize=this.dashSize),this.gapSize!==void 0&&(r.gapSize=this.gapSize),this.scale!==void 0&&(r.scale=this.scale),this.dithering===!0&&(r.dithering=!0),this.alphaTest>0&&(r.alphaTest=this.alphaTest),this.alphaHash===!0&&(r.alphaHash=!0),this.alphaToCoverage===!0&&(r.alphaToCoverage=!0),this.premultipliedAlpha===!0&&(r.premultipliedAlpha=!0),this.forceSinglePass===!0&&(r.forceSinglePass=!0),this.allowOverride===!1&&(r.allowOverride=!1),this.wireframe===!0&&(r.wireframe=!0),this.wireframeLinewidth>1&&(r.wireframeLinewidth=this.wireframeLinewidth),this.wireframeLinecap!=="round"&&(r.wireframeLinecap=this.wireframeLinecap),this.wireframeLinejoin!=="round"&&(r.wireframeLinejoin=this.wireframeLinejoin),this.flatShading===!0&&(r.flatShading=!0),this.visible===!1&&(r.visible=!1),this.toneMapped===!1&&(r.toneMapped=!1),this.fog===!1&&(r.fog=!1),Object.keys(this.userData).length>0&&(r.userData=this.userData);function i(s){let a=[];for(let n in s){let o=s[n];delete o.metadata,a.push(o)}return a}if(t){let s=i(e.textures),a=i(e.images);s.length>0&&(r.textures=s),a.length>0&&(r.images=a)}return r}fromJSON(e,t){if(e.uuid!==void 0&&(this.uuid=e.uuid),e.name!==void 0&&(this.name=e.name),e.color!==void 0&&this.color!==void 0&&this.color.setHex(e.color),e.roughness!==void 0&&(this.roughness=e.roughness),e.metalness!==void 0&&(this.metalness=e.metalness),e.sheen!==void 0&&(this.sheen=e.sheen),e.sheenColor!==void 0&&(this.sheenColor=new gt().setHex(e.sheenColor)),e.sheenRoughness!==void 0&&(this.sheenRoughness=e.sheenRoughness),e.emissive!==void 0&&this.emissive!==void 0&&this.emissive.setHex(e.emissive),e.specular!==void 0&&this.specular!==void 0&&this.specular.setHex(e.specular),e.specularIntensity!==void 0&&(this.specularIntensity=e.specularIntensity),e.specularColor!==void 0&&this.specularColor!==void 0&&this.specularColor.setHex(e.specularColor),e.shininess!==void 0&&(this.shininess=e.shininess),e.clearcoat!==void 0&&(this.clearcoat=e.clearcoat),e.clearcoatRoughness!==void 0&&(this.clearcoatRoughness=e.clearcoatRoughness),e.dispersion!==void 0&&(this.dispersion=e.dispersion),e.iridescence!==void 0&&(this.iridescence=e.iridescence),e.iridescenceIOR!==void 0&&(this.iridescenceIOR=e.iridescenceIOR),e.iridescenceThicknessRange!==void 0&&(this.iridescenceThicknessRange=e.iridescenceThicknessRange),e.transmission!==void 0&&(this.transmission=e.transmission),e.thickness!==void 0&&(this.thickness=e.thickness),e.attenuationDistance!==void 0&&(this.attenuationDistance=e.attenuationDistance),e.attenuationColor!==void 0&&this.attenuationColor!==void 0&&this.attenuationColor.setHex(e.attenuationColor),e.anisotropy!==void 0&&(this.anisotropy=e.anisotropy),e.anisotropyRotation!==void 0&&(this.anisotropyRotation=e.anisotropyRotation),e.fog!==void 0&&(this.fog=e.fog),e.flatShading!==void 0&&(this.flatShading=e.flatShading),e.blending!==void 0&&(this.blending=e.blending),e.combine!==void 0&&(this.combine=e.combine),e.side!==void 0&&(this.side=e.side),e.shadowSide!==void 0&&(this.shadowSide=e.shadowSide),e.opacity!==void 0&&(this.opacity=e.opacity),e.transparent!==void 0&&(this.transparent=e.transparent),e.alphaTest!==void 0&&(this.alphaTest=e.alphaTest),e.alphaHash!==void 0&&(this.alphaHash=e.alphaHash),e.depthFunc!==void 0&&(this.depthFunc=e.depthFunc),e.depthTest!==void 0&&(this.depthTest=e.depthTest),e.depthWrite!==void 0&&(this.depthWrite=e.depthWrite),e.colorWrite!==void 0&&(this.colorWrite=e.colorWrite),e.blendSrc!==void 0&&(this.blendSrc=e.blendSrc),e.blendDst!==void 0&&(this.blendDst=e.blendDst),e.blendEquation!==void 0&&(this.blendEquation=e.blendEquation),e.blendSrcAlpha!==void 0&&(this.blendSrcAlpha=e.blendSrcAlpha),e.blendDstAlpha!==void 0&&(this.blendDstAlpha=e.blendDstAlpha),e.blendEquationAlpha!==void 0&&(this.blendEquationAlpha=e.blendEquationAlpha),e.blendColor!==void 0&&this.blendColor!==void 0&&this.blendColor.setHex(e.blendColor),e.blendAlpha!==void 0&&(this.blendAlpha=e.blendAlpha),e.stencilWriteMask!==void 0&&(this.stencilWriteMask=e.stencilWriteMask),e.stencilFunc!==void 0&&(this.stencilFunc=e.stencilFunc),e.stencilRef!==void 0&&(this.stencilRef=e.stencilRef),e.stencilFuncMask!==void 0&&(this.stencilFuncMask=e.stencilFuncMask),e.stencilFail!==void 0&&(this.stencilFail=e.stencilFail),e.stencilZFail!==void 0&&(this.stencilZFail=e.stencilZFail),e.stencilZPass!==void 0&&(this.stencilZPass=e.stencilZPass),e.stencilWrite!==void 0&&(this.stencilWrite=e.stencilWrite),e.wireframe!==void 0&&(this.wireframe=e.wireframe),e.wireframeLinewidth!==void 0&&(this.wireframeLinewidth=e.wireframeLinewidth),e.wireframeLinecap!==void 0&&(this.wireframeLinecap=e.wireframeLinecap),e.wireframeLinejoin!==void 0&&(this.wireframeLinejoin=e.wireframeLinejoin),e.rotation!==void 0&&(this.rotation=e.rotation),e.linewidth!==void 0&&(this.linewidth=e.linewidth),e.dashSize!==void 0&&(this.dashSize=e.dashSize),e.gapSize!==void 0&&(this.gapSize=e.gapSize),e.scale!==void 0&&(this.scale=e.scale),e.polygonOffset!==void 0&&(this.polygonOffset=e.polygonOffset),e.polygonOffsetFactor!==void 0&&(this.polygonOffsetFactor=e.polygonOffsetFactor),e.polygonOffsetUnits!==void 0&&(this.polygonOffsetUnits=e.polygonOffsetUnits),e.dithering!==void 0&&(this.dithering=e.dithering),e.alphaToCoverage!==void 0&&(this.alphaToCoverage=e.alphaToCoverage),e.premultipliedAlpha!==void 0&&(this.premultipliedAlpha=e.premultipliedAlpha),e.forceSinglePass!==void 0&&(this.forceSinglePass=e.forceSinglePass),e.allowOverride!==void 0&&(this.allowOverride=e.allowOverride),e.visible!==void 0&&(this.visible=e.visible),e.toneMapped!==void 0&&(this.toneMapped=e.toneMapped),e.userData!==void 0&&(this.userData=e.userData),e.vertexColors!==void 0&&(typeof e.vertexColors=="number"?this.vertexColors=e.vertexColors>0:this.vertexColors=e.vertexColors),e.size!==void 0&&(this.size=e.size),e.sizeAttenuation!==void 0&&(this.sizeAttenuation=e.sizeAttenuation),e.map!==void 0&&(this.map=t[e.map]||null),e.matcap!==void 0&&(this.matcap=t[e.matcap]||null),e.alphaMap!==void 0&&(this.alphaMap=t[e.alphaMap]||null),e.bumpMap!==void 0&&(this.bumpMap=t[e.bumpMap]||null),e.bumpScale!==void 0&&(this.bumpScale=e.bumpScale),e.normalMap!==void 0&&(this.normalMap=t[e.normalMap]||null),e.normalMapType!==void 0&&(this.normalMapType=e.normalMapType),e.normalScale!==void 0){let r=e.normalScale;Array.isArray(r)===!1&&(r=[r,r]),this.normalScale=new fe().fromArray(r)}return e.displacementMap!==void 0&&(this.displacementMap=t[e.displacementMap]||null),e.displacementScale!==void 0&&(this.displacementScale=e.displacementScale),e.displacementBias!==void 0&&(this.displacementBias=e.displacementBias),e.roughnessMap!==void 0&&(this.roughnessMap=t[e.roughnessMap]||null),e.metalnessMap!==void 0&&(this.metalnessMap=t[e.metalnessMap]||null),e.emissiveMap!==void 0&&(this.emissiveMap=t[e.emissiveMap]||null),e.emissiveIntensity!==void 0&&(this.emissiveIntensity=e.emissiveIntensity),e.specularMap!==void 0&&(this.specularMap=t[e.specularMap]||null),e.specularIntensityMap!==void 0&&(this.specularIntensityMap=t[e.specularIntensityMap]||null),e.specularColorMap!==void 0&&(this.specularColorMap=t[e.specularColorMap]||null),e.envMap!==void 0&&(this.envMap=t[e.envMap]||null),e.envMapRotation!==void 0&&this.envMapRotation.fromArray(e.envMapRotation),e.envMapIntensity!==void 0&&(this.envMapIntensity=e.envMapIntensity),e.reflectivity!==void 0&&(this.reflectivity=e.reflectivity),e.refractionRatio!==void 0&&(this.refractionRatio=e.refractionRatio),e.lightMap!==void 0&&(this.lightMap=t[e.lightMap]||null),e.lightMapIntensity!==void 0&&(this.lightMapIntensity=e.lightMapIntensity),e.aoMap!==void 0&&(this.aoMap=t[e.aoMap]||null),e.aoMapIntensity!==void 0&&(this.aoMapIntensity=e.aoMapIntensity),e.gradientMap!==void 0&&(this.gradientMap=t[e.gradientMap]||null),e.clearcoatMap!==void 0&&(this.clearcoatMap=t[e.clearcoatMap]||null),e.clearcoatRoughnessMap!==void 0&&(this.clearcoatRoughnessMap=t[e.clearcoatRoughnessMap]||null),e.clearcoatNormalMap!==void 0&&(this.clearcoatNormalMap=t[e.clearcoatNormalMap]||null),e.clearcoatNormalScale!==void 0&&(this.clearcoatNormalScale=new fe().fromArray(e.clearcoatNormalScale)),e.iridescenceMap!==void 0&&(this.iridescenceMap=t[e.iridescenceMap]||null),e.iridescenceThicknessMap!==void 0&&(this.iridescenceThicknessMap=t[e.iridescenceThicknessMap]||null),e.transmissionMap!==void 0&&(this.transmissionMap=t[e.transmissionMap]||null),e.thicknessMap!==void 0&&(this.thicknessMap=t[e.thicknessMap]||null),e.anisotropyMap!==void 0&&(this.anisotropyMap=t[e.anisotropyMap]||null),e.sheenColorMap!==void 0&&(this.sheenColorMap=t[e.sheenColorMap]||null),e.sheenRoughnessMap!==void 0&&(this.sheenRoughnessMap=t[e.sheenRoughnessMap]||null),this}clone(){return new this.constructor().copy(this)}copy(e){this.name=e.name,this.blending=e.blending,this.side=e.side,this.vertexColors=e.vertexColors,this.opacity=e.opacity,this.transparent=e.transparent,this.blendSrc=e.blendSrc,this.blendDst=e.blendDst,this.blendEquation=e.blendEquation,this.blendSrcAlpha=e.blendSrcAlpha,this.blendDstAlpha=e.blendDstAlpha,this.blendEquationAlpha=e.blendEquationAlpha,this.blendColor.copy(e.blendColor),this.blendAlpha=e.blendAlpha,this.depthFunc=e.depthFunc,this.depthTest=e.depthTest,this.depthWrite=e.depthWrite,this.stencilWriteMask=e.stencilWriteMask,this.stencilFunc=e.stencilFunc,this.stencilRef=e.stencilRef,this.stencilFuncMask=e.stencilFuncMask,this.stencilFail=e.stencilFail,this.stencilZFail=e.stencilZFail,this.stencilZPass=e.stencilZPass,this.stencilWrite=e.stencilWrite;let t=e.clippingPlanes,r=null;if(t!==null){let i=t.length;r=new Array(i);for(let s=0;s!==i;++s)r[s]=t[s].clone()}return this.clippingPlanes=r,this.clipIntersection=e.clipIntersection,this.clipShadows=e.clipShadows,this.shadowSide=e.shadowSide,this.colorWrite=e.colorWrite,this.precision=e.precision,this.polygonOffset=e.polygonOffset,this.polygonOffsetFactor=e.polygonOffsetFactor,this.polygonOffsetUnits=e.polygonOffsetUnits,this.dithering=e.dithering,this.alphaTest=e.alphaTest,this.alphaHash=e.alphaHash,this.alphaToCoverage=e.alphaToCoverage,this.premultipliedAlpha=e.premultipliedAlpha,this.forceSinglePass=e.forceSinglePass,this.allowOverride=e.allowOverride,this.visible=e.visible,this.toneMapped=e.toneMapped,this.userData=JSON.parse(JSON.stringify(e.userData)),this}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(e){e===!0&&this.version++}},D4=class extends Vs{constructor(e){super(),this.isSpriteMaterial=!0,this.type="SpriteMaterial",this.color=new gt(16777215),this.map=null,this.alphaMap=null,this.rotation=0,this.sizeAttenuation=!0,this.transparent=!0,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.alphaMap=e.alphaMap,this.rotation=e.rotation,this.sizeAttenuation=e.sizeAttenuation,this.fog=e.fog,this}},co=new F,Dv=new F,Ag=new F,sl=new F,Ov=new F,Cg=new F,Uv=new F,ld=class{constructor(e=new F,t=new F(0,0,-1)){this.origin=e,this.direction=t}set(e,t){return this.origin.copy(e),this.direction.copy(t),this}copy(e){return this.origin.copy(e.origin),this.direction.copy(e.direction),this}at(e,t){return t.copy(this.origin).addScaledVector(this.direction,e)}lookAt(e){return this.direction.copy(e).sub(this.origin).normalize(),this}recast(e){return this.origin.copy(this.at(e,co)),this}closestPointToPoint(e,t){t.subVectors(e,this.origin);let r=t.dot(this.direction);return r<0?t.copy(this.origin):t.copy(this.origin).addScaledVector(this.direction,r)}distanceToPoint(e){return Math.sqrt(this.distanceSqToPoint(e))}distanceSqToPoint(e){let t=co.subVectors(e,this.origin).dot(this.direction);return t<0?this.origin.distanceToSquared(e):(co.copy(this.origin).addScaledVector(this.direction,t),co.distanceToSquared(e))}distanceSqToSegment(e,t,r,i){Dv.copy(e).add(t).multiplyScalar(.5),Ag.copy(t).sub(e).normalize(),sl.copy(this.origin).sub(Dv);let s=e.distanceTo(t)*.5,a=-this.direction.dot(Ag),n=sl.dot(this.direction),o=-sl.dot(Ag),l=sl.lengthSq(),u=Math.abs(1-a*a),h,d,c,m;if(u>0)if(h=a*o-n,d=a*n-o,m=s*u,h>=0)if(d>=-m)if(d<=m){let g=1/u;h*=g,d*=g,c=h*(h+a*d+2*n)+d*(a*h+d+2*o)+l}else d=s,h=Math.max(0,-(a*d+n)),c=-h*h+d*(d+2*o)+l;else d=-s,h=Math.max(0,-(a*d+n)),c=-h*h+d*(d+2*o)+l;else d<=-m?(h=Math.max(0,-(-a*s+n)),d=h>0?-s:Math.min(Math.max(-s,-o),s),c=-h*h+d*(d+2*o)+l):d<=m?(h=0,d=Math.min(Math.max(-s,-o),s),c=d*(d+2*o)+l):(h=Math.max(0,-(a*s+n)),d=h>0?s:Math.min(Math.max(-s,-o),s),c=-h*h+d*(d+2*o)+l);else d=a>0?-s:s,h=Math.max(0,-(a*d+n)),c=-h*h+d*(d+2*o)+l;return r&&r.copy(this.origin).addScaledVector(this.direction,h),i&&i.copy(Dv).addScaledVector(Ag,d),c}intersectSphere(e,t){co.subVectors(e.center,this.origin);let r=co.dot(this.direction),i=co.dot(co)-r*r,s=e.radius*e.radius;if(i>s)return null;let a=Math.sqrt(s-i),n=r-a,o=r+a;return o<0?null:n<0?this.at(o,t):this.at(n,t)}intersectsSphere(e){return e.radius<0?!1:this.distanceSqToPoint(e.center)<=e.radius*e.radius}distanceToPlane(e){let t=e.normal.dot(this.direction);if(t===0)return e.distanceToPoint(this.origin)===0?0:null;let r=-(this.origin.dot(e.normal)+e.constant)/t;return r>=0?r:null}intersectPlane(e,t){let r=this.distanceToPlane(e);return r===null?null:this.at(r,t)}intersectsPlane(e){let t=e.distanceToPoint(this.origin);return t===0||e.normal.dot(this.direction)*t<0}intersectBox(e,t){let r,i,s,a,n,o,l=1/this.direction.x,u=1/this.direction.y,h=1/this.direction.z,d=this.origin;return l>=0?(r=(e.min.x-d.x)*l,i=(e.max.x-d.x)*l):(r=(e.max.x-d.x)*l,i=(e.min.x-d.x)*l),u>=0?(s=(e.min.y-d.y)*u,a=(e.max.y-d.y)*u):(s=(e.max.y-d.y)*u,a=(e.min.y-d.y)*u),r>a||s>i||((s>r||isNaN(r))&&(r=s),(a=0?(n=(e.min.z-d.z)*h,o=(e.max.z-d.z)*h):(n=(e.max.z-d.z)*h,o=(e.min.z-d.z)*h),r>o||n>i)||((n>r||r!==r)&&(r=n),(o=0?r:i,t)}intersectsBox(e){return this.intersectBox(e,co)!==null}intersectTriangle(e,t,r,i,s){Ov.subVectors(t,e),Cg.subVectors(r,e),Uv.crossVectors(Ov,Cg);let a=this.direction.dot(Uv),n;if(a>0){if(i)return null;n=1}else if(a<0)n=-1,a=-a;else return null;sl.subVectors(this.origin,e);let o=n*this.direction.dot(Cg.crossVectors(sl,Cg));if(o<0)return null;let l=n*this.direction.dot(Ov.cross(sl));if(l<0||o+l>a)return null;let u=-n*sl.dot(Uv);return u<0?null:this.at(u/a,s)}applyMatrix4(e){return this.origin.applyMatrix4(e),this.direction.transformDirection(e),this}equals(e){return e.origin.equals(this.origin)&&e.direction.equals(this.direction)}clone(){return new this.constructor().copy(this)}},mn=class extends Vs{constructor(e){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new gt(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new cn,this.combine=Ff,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.specularMap=e.specularMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.combine=e.combine,this.reflectivity=e.reflectivity,this.refractionRatio=e.refractionRatio,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.fog=e.fog,this}},nN=new We,xu=new ld,Rg=new Ng,oN=new F,Eg=new F,Pg=new F,Bg=new F,zv=new F,Ig=new F,lN=new F,Fg=new F,Mi=class extends Hi{constructor(e=new ps,t=new mn){super(),this.isMesh=!0,this.type="Mesh",this.geometry=e,this.material=t,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.count=1,this.updateMorphTargets()}copy(e,t){return super.copy(e,t),e.morphTargetInfluences!==void 0&&(this.morphTargetInfluences=e.morphTargetInfluences.slice()),e.morphTargetDictionary!==void 0&&(this.morphTargetDictionary=Object.assign({},e.morphTargetDictionary)),this.material=Array.isArray(e.material)?e.material.slice():e.material,this.geometry=e.geometry,this}updateMorphTargets(){let e=this.geometry.morphAttributes,t=Object.keys(e);if(t.length>0){let r=e[t[0]];if(r!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let i=0,s=r.length;i(e.far-e.near)**2))&&(nN.copy(s).invert(),xu.copy(e.ray).applyMatrix4(nN),!(r.boundingBox!==null&&xu.intersectsBox(r.boundingBox)===!1)&&this._computeIntersections(e,t,xu)))}_computeIntersections(e,t,r){let i,s=this.geometry,a=this.material,n=s.index,o=s.attributes.position,l=s.attributes.uv,u=s.attributes.uv1,h=s.attributes.normal,d=s.groups,c=s.drawRange;if(n!==null)if(Array.isArray(a))for(let m=0,g=d.length;mr.far?null:{distance:u,point:Fg.clone(),object:e}}function Lg(e,t,r,i,s,a,n,o,l,u){e.getVertexPosition(o,Eg),e.getVertexPosition(l,Pg),e.getVertexPosition(u,Bg);let h=O4(e,t,r,i,Eg,Pg,Bg,lN);if(h){let d=new F;$i.getBarycoord(lN,Eg,Pg,Bg,d),s&&(h.uv=$i.getInterpolatedAttribute(s,o,l,u,d,new fe)),a&&(h.uv1=$i.getInterpolatedAttribute(a,o,l,u,d,new fe)),n&&(h.normal=$i.getInterpolatedAttribute(n,o,l,u,d,new F),h.normal.dot(i.direction)>0&&h.normal.multiplyScalar(-1));let c={a:o,b:l,c:u,normal:new F,materialIndex:0};$i.getNormal(Eg,Pg,Bg,c.normal),h.face=c,h.barycoord=d}return h}var kg=class extends ji{constructor(e=null,t=1,r=1,i,s,a,n,o,l=or,u=or,h,d){super(null,a,n,o,l,u,i,s,h,d),this.isDataTexture=!0,this.image={data:e,width:t,height:r},this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}},ud=class extends _i{constructor(e,t,r,i=1){super(e,t,r),this.isInstancedBufferAttribute=!0,this.meshPerAttribute=i}copy(e){return super.copy(e),this.meshPerAttribute=e.meshPerAttribute,this}toJSON(){let e=super.toJSON();return e.meshPerAttribute=this.meshPerAttribute,e.isInstancedBufferAttribute=!0,e}},Vv=new F,U4=new F,z4=new Dr,fn=class{constructor(e=new F(1,0,0),t=0){this.isPlane=!0,this.normal=e,this.constant=t}set(e,t){return this.normal.copy(e),this.constant=t,this}setComponents(e,t,r,i){return this.normal.set(e,t,r),this.constant=i,this}setFromNormalAndCoplanarPoint(e,t){return this.normal.copy(e),this.constant=-t.dot(this.normal),this}setFromCoplanarPoints(e,t,r){let i=Vv.subVectors(r,t).cross(U4.subVectors(e,t)).normalize();return this.setFromNormalAndCoplanarPoint(i,e),this}copy(e){return this.normal.copy(e.normal),this.constant=e.constant,this}normalize(){let e=1/this.normal.length();return this.normal.multiplyScalar(e),this.constant*=e,this}negate(){return this.constant*=-1,this.normal.negate(),this}distanceToPoint(e){return this.normal.dot(e)+this.constant}distanceToSphere(e){return this.distanceToPoint(e.center)-e.radius}projectPoint(e,t){return t.copy(e).addScaledVector(this.normal,-this.distanceToPoint(e))}intersectLine(e,t,r=!0){let i=e.delta(Vv),s=this.normal.dot(i);if(s===0)return this.distanceToPoint(e.start)===0?t.copy(e.start):null;let a=-(e.start.dot(this.normal)+this.constant)/s;return r===!0&&(a<0||a>1)?null:t.copy(e.start).addScaledVector(i,a)}intersectsLine(e){let t=this.distanceToPoint(e.start),r=this.distanceToPoint(e.end);return t<0&&r>0||r<0&&t>0}intersectsBox(e){return e.intersectsPlane(this)}intersectsSphere(e){return e.intersectsPlane(this)}coplanarPoint(e){return e.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(e,t){let r=t||z4.getNormalMatrix(e),i=this.coplanarPoint(Vv).applyMatrix4(e),s=this.normal.applyMatrix3(r).normalize();return this.constant=-i.dot(s),this}translate(e){return this.constant-=e.dot(this.normal),this}equals(e){return e.normal.equals(this.normal)&&e.constant===this.constant}clone(){return new this.constructor().copy(this)}},vu=new Ng,V4=new fe(.5,.5),Dg=new F,Og=class{constructor(e=new fn,t=new fn,r=new fn,i=new fn,s=new fn,a=new fn){this.planes=[e,t,r,i,s,a]}set(e,t,r,i,s,a){let n=this.planes;return n[0].copy(e),n[1].copy(t),n[2].copy(r),n[3].copy(i),n[4].copy(s),n[5].copy(a),this}copy(e){let t=this.planes;for(let r=0;r<6;r++)t[r].copy(e.planes[r]);return this}setFromProjectionMatrix(e,t=Ds,r=!1){let i=this.planes,s=e.elements,a=s[0],n=s[1],o=s[2],l=s[3],u=s[4],h=s[5],d=s[6],c=s[7],m=s[8],g=s[9],y=s[10],b=s[11],v=s[12],S=s[13],T=s[14],w=s[15];if(i[0].setComponents(l-a,c-u,b-m,w-v).normalize(),i[1].setComponents(l+a,c+u,b+m,w+v).normalize(),i[2].setComponents(l+n,c+h,b+g,w+S).normalize(),i[3].setComponents(l-n,c-h,b-g,w-S).normalize(),r)i[4].setComponents(o,d,y,T).normalize(),i[5].setComponents(l-o,c-d,b-y,w-T).normalize();else if(i[4].setComponents(l-o,c-d,b-y,w-T).normalize(),t===Ds)i[5].setComponents(l+o,c+d,b+y,w+T).normalize();else if(t===da)i[5].setComponents(o,d,y,T).normalize();else throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: "+t);return this}intersectsObject(e){if(e.boundingSphere!==void 0)e.boundingSphere===null&&e.computeBoundingSphere(),vu.copy(e.boundingSphere).applyMatrix4(e.matrixWorld);else{let t=e.geometry;t.boundingSphere===null&&t.computeBoundingSphere(),vu.copy(t.boundingSphere).applyMatrix4(e.matrixWorld)}return this.intersectsSphere(vu)}intersectsSprite(e){vu.center.set(0,0,0);let t=V4.distanceTo(e.center);return vu.radius=.7071067811865476+t,vu.applyMatrix4(e.matrixWorld),this.intersectsSphere(vu)}intersectsSphere(e){let t=this.planes,r=e.center,i=-e.radius;for(let s=0;s<6;s++)if(t[s].distanceToPoint(r)0?e.max.x:e.min.x,Dg.y=i.normal.y>0?e.max.y:e.min.y,Dg.z=i.normal.z>0?e.max.z:e.min.z,i.distanceToPoint(Dg)<0)return!1}return!0}containsPoint(e){let t=this.planes;for(let r=0;r<6;r++)if(t[r].distanceToPoint(e)<0)return!1;return!0}clone(){return new this.constructor().copy(this)}},uN=new We,G4=class Wk{constructor(){this.coordinateSystem=Ds,this._frustums=[],this._count=0}setFromArrayCamera(t){let r=t.cameras,i=this._frustums;for(let s=0;s0?1:-1,h.push(ce.x,ce.y,ce.z),d.push(oe/R),d.push(1-ge/E),ne+=1}}for(let ge=0;ge0&&T(!0),r>0&&T(!1)),this.setIndex(h),this.setAttribute("position",new tr(d,3)),this.setAttribute("normal",new tr(c,3)),this.setAttribute("uv",new tr(m,2));function S(){let w=new F,N=new F,C=0,R=(r-t)/i;for(let E=0;E<=a;E++){let P=[],I=E/a,O=I*(r-t)+t;for(let L=0;L<=s;L++){let X=L/s,z=X*l+o,H=Math.sin(z),ue=Math.cos(z);N.x=O*H,N.y=-I*i+b,N.z=O*ue,d.push(N.x,N.y,N.z),w.set(H,R,ue).normalize(),c.push(w.x,w.y,w.z),m.push(X,1-I),P.push(g++)}y.push(P)}for(let E=0;E0||P!==0)&&(h.push(I,O,X),C+=3),(r>0||P!==a-1)&&(h.push(O,L,X),C+=3)}u.addGroup(v,C,0),v+=C}function T(w){let N=g,C=new fe,R=new F,E=0,P=w===!0?t:r,I=w===!0?1:-1;for(let L=1;L<=s;L++)d.push(0,b*I,0),c.push(0,I,0),m.push(.5,.5),g++;let O=g;for(let L=0;L<=s;L++){let X=L/s*l+o,z=Math.cos(X),H=Math.sin(X);R.x=P*H,R.y=b*I,R.z=P*z,d.push(R.x,R.y,R.z),c.push(0,I,0),C.x=z*.5+.5,C.y=H*.5*I+.5,m.push(C.x,C.y),g++}for(let L=0;L.9&&R<.1&&(T<.2&&(n[S+0]+=1),w<.2&&(n[S+2]+=1),N<.2&&(n[S+4]+=1))}}function c(S){a.push(S.x,S.y,S.z)}function m(S,T){let w=S*3;T.x=t[w+0],T.y=t[w+1],T.z=t[w+2]}function g(){let S=new F,T=new F,w=new F,N=new F,C=new fe,R=new fe,E=new fe;for(let P=0,I=0;P0)o=i-1;else{o=i;break}if(i=o,r[i]===a)return i/(s-1);let u=r[i],h=r[i+1]-u,d=(a-u)/h;return(i+d)/(s-1)}getTangent(e,t){let r=e-1e-4,i=e+1e-4;r<0&&(r=0),i>1&&(i=1);let s=this.getPoint(r),a=this.getPoint(i),n=t||(s.isVector2?new fe:new F);return n.copy(a).sub(s).normalize(),n}getTangentAt(e,t){let r=this.getUtoTmapping(e);return this.getTangent(r,t)}computeFrenetFrames(e,t=!1){let r=new F,i=[],s=[],a=[],n=new F,o=new We;for(let c=0;c<=e;c++){let m=c/e;i[c]=this.getTangentAt(m,new F)}s[0]=new F,a[0]=new F;let l=Number.MAX_VALUE,u=Math.abs(i[0].x),h=Math.abs(i[0].y),d=Math.abs(i[0].z);u<=l&&(l=u,r.set(1,0,0)),h<=l&&(l=h,r.set(0,1,0)),d<=l&&r.set(0,0,1),n.crossVectors(i[0],r).normalize(),s[0].crossVectors(i[0],n),a[0].crossVectors(i[0],s[0]);for(let c=1;c<=e;c++){if(s[c]=s[c-1].clone(),a[c]=a[c-1].clone(),n.crossVectors(i[c-1],i[c]),n.length()>Number.EPSILON){n.normalize();let m=Math.acos(St(i[c-1].dot(i[c]),-1,1));s[c].applyMatrix4(o.makeRotationAxis(n,m))}a[c].crossVectors(i[c],s[c])}if(t===!0){let c=Math.acos(St(s[0].dot(s[e]),-1,1));c/=e,i[0].dot(n.crossVectors(s[0],s[e]))>0&&(c=-c);for(let m=1;m<=e;m++)s[m].applyMatrix4(o.makeRotationAxis(i[m],c*m)),a[m].crossVectors(i[m],s[m])}return{tangents:i,normals:s,binormals:a}}clone(){return new this.constructor().copy(this)}copy(e){return this.arcLengthDivisions=e.arcLengthDivisions,this}toJSON(){let e={metadata:{version:4.7,type:"Curve",generator:"Curve.toJSON"}};return e.arcLengthDivisions=this.arcLengthDivisions,e.type=this.type,e}fromJSON(e){return this.arcLengthDivisions=e.arcLengthDivisions,this}},Hv=class extends gn{constructor(e=0,t=0,r=1,i=1,s=0,a=Math.PI*2,n=!1,o=0){super(),this.isEllipseCurve=!0,this.type="EllipseCurve",this.aX=e,this.aY=t,this.xRadius=r,this.yRadius=i,this.aStartAngle=s,this.aEndAngle=a,this.aClockwise=n,this.aRotation=o}getPoint(e,t=new fe){let r=t,i=Math.PI*2,s=this.aEndAngle-this.aStartAngle,a=Math.abs(s)i;)s-=i;s0?0:(Math.floor(Math.abs(n)/s)+1)*s:o===0&&n===s-1&&(n=s-2,o=1);let l,u;this.closed||n>0?l=i[(n-1)%s]:(cN.subVectors(i[0],i[1]).add(i[0]),l=cN);let h=i[n%s],d=i[(n+1)%s];if(this.closed||n+2i.length-2?i.length-1:a+1],h=i[a>i.length-3?i.length-1:a+2];return r.set(pN(n,o.x,l.x,u.x,h.x),pN(n,o.y,l.y,u.y,h.y)),r}copy(e){super.copy(e),this.points=[];for(let t=0,r=e.points.length;t=r){let a=i[s]-r,n=this.curves[s],o=n.getLength(),l=o===0?0:1-a/o;return n.getPointAt(l,t)}s++}return null}getLength(){let e=this.getCurveLengths();return e[e.length-1]}updateArcLengths(){this.needsUpdate=!0,this.cacheLengths=null,this.getCurveLengths()}getCurveLengths(){if(this.cacheLengths&&this.cacheLengths.length===this.curves.length)return this.cacheLengths;let e=[],t=0;for(let r=0,i=this.curves.length;r1&&!t[t.length-1].equals(t[0])&&t.push(t[0]),t}copy(e){super.copy(e),this.curves=[];for(let t=0,r=e.curves.length;t0){let h=l.getPoint(0);h.equals(this.currentPoint)||this.lineTo(h.x,h.y)}this.curves.push(l);let u=l.getPoint(1);return this.currentPoint.copy(u),this}copy(e){return super.copy(e),this.currentPoint.copy(e.currentPoint),this}toJSON(){let e=super.toJSON();return e.currentPoint=this.currentPoint.toArray(),e}fromJSON(e){return super.fromJSON(e),this.currentPoint.fromArray(e.currentPoint),this}},cp=class extends po{constructor(e){super(e),this.uuid=dn(),this.type="Shape",this.holes=[]}getPointsHoles(e){let t=[];for(let r=0,i=this.holes.length;r80*r){o=e[0],l=e[1];let h=o,d=l;for(let c=r;ch&&(h=m),g>d&&(d=g)}u=Math.max(h-o,d-l),u=u!==0?32767/u:0}return pp(a,n,r,o,l,u,0),n}function xN(e,t,r,i,s){let a;if(s===SO(e,t,r,i)>0)for(let n=t;n=t;n-=i)a=SN(n/i|0,e[n],e[n+1],a);return a&&hd(a,a.next)&&(gp(a),a=a.next),a}function bu(e,t){if(!e)return e;t||(t=e);let r=e,i;do if(i=!1,!r.steiner&&(hd(r,r.next)||Or(r.prev,r,r.next)===0)){if(gp(r),r=t=r.prev,r===r.next)break;i=!0}else r=r.next;while(i||r!==t);return t}function pp(e,t,r,i,s,a,n){if(!e)return;!n&&a&&gO(e,i,s,a);let o=e;for(;e.prev!==e.next;){let l=e.prev,u=e.next;if(a?lO(e,i,s,a):oO(e)){t.push(l.i,e.i,u.i),gp(e),e=u.next,o=u.next;continue}if(e=u,e===o){n?n===1?(e=uO(bu(e),t),pp(e,t,r,i,s,a,2)):n===2&&hO(e,t,r,i,s,a):pp(bu(e),t,r,i,s,a,1);break}}}function oO(e){let t=e.prev,r=e,i=e.next;if(Or(t,r,i)>=0)return!1;let s=t.x,a=r.x,n=i.x,o=t.y,l=r.y,u=i.y,h=Math.min(s,a,n),d=Math.min(o,l,u),c=Math.max(s,a,n),m=Math.max(o,l,u),g=i.next;for(;g!==t;){if(g.x>=h&&g.x<=c&&g.y>=d&&g.y<=m&&mp(s,o,a,l,n,u,g.x,g.y)&&Or(g.prev,g,g.next)>=0)return!1;g=g.next}return!0}function lO(e,t,r,i){let s=e.prev,a=e,n=e.next;if(Or(s,a,n)>=0)return!1;let o=s.x,l=a.x,u=n.x,h=s.y,d=a.y,c=n.y,m=Math.min(o,l,u),g=Math.min(h,d,c),y=Math.max(o,l,u),b=Math.max(h,d,c),v=Jv(m,g,t,r,i),S=Jv(y,b,t,r,i),T=e.prevZ,w=e.nextZ;for(;T&&T.z>=v&&w&&w.z<=S;){if(T.x>=m&&T.x<=y&&T.y>=g&&T.y<=b&&T!==s&&T!==n&&mp(o,h,l,d,u,c,T.x,T.y)&&Or(T.prev,T,T.next)>=0||(T=T.prevZ,w.x>=m&&w.x<=y&&w.y>=g&&w.y<=b&&w!==s&&w!==n&&mp(o,h,l,d,u,c,w.x,w.y)&&Or(w.prev,w,w.next)>=0))return!1;w=w.nextZ}for(;T&&T.z>=v;){if(T.x>=m&&T.x<=y&&T.y>=g&&T.y<=b&&T!==s&&T!==n&&mp(o,h,l,d,u,c,T.x,T.y)&&Or(T.prev,T,T.next)>=0)return!1;T=T.prevZ}for(;w&&w.z<=S;){if(w.x>=m&&w.x<=y&&w.y>=g&&w.y<=b&&w!==s&&w!==n&&mp(o,h,l,d,u,c,w.x,w.y)&&Or(w.prev,w,w.next)>=0)return!1;w=w.nextZ}return!0}function uO(e,t){let r=e;do{let i=r.prev,s=r.next.next;!hd(i,s)&&bN(i,r,r.next,s)&&fp(i,s)&&fp(s,i)&&(t.push(i.i,r.i,s.i),gp(r),gp(r.next),r=e=s),r=r.next}while(r!==e);return bu(r)}function hO(e,t,r,i,s,a){let n=e;do{let o=n.next.next;for(;o!==n.prev;){if(n.i!==o.i&&vO(n,o)){let l=TN(n,o);n=bu(n,n.next),l=bu(l,l.next),pp(n,t,r,i,s,a,0),pp(l,t,r,i,s,a,0);return}o=o.next}n=n.next}while(n!==e)}function dO(e,t,r,i){let s=[];for(let a=0,n=t.length;a=r.next.y&&r.next.y!==r.y){let d=r.x+(s-r.y)*(r.next.x-r.x)/(r.next.y-r.y);if(d<=i&&d>a&&(a=d,n=r.x=r.x&&r.x>=l&&i!==r.x&&vN(sn.x||r.x===n.x&&fO(n,r)))&&(n=r,h=d)}r=r.next}while(r!==o);return n}function fO(e,t){return Or(e.prev,e,t.prev)<0&&Or(t.next,e,e.next)<0}function gO(e,t,r,i){let s=e;do s.z===0&&(s.z=Jv(s.x,s.y,t,r,i)),s.prevZ=s.prev,s.nextZ=s.next,s=s.next;while(s!==e);s.prevZ.nextZ=null,s.prevZ=null,yO(s)}function yO(e){let t,r=1;do{let i=e,s;e=null;let a=null;for(t=0;i;){t++;let n=i,o=0;for(let u=0;u0||l>0&&n;)o!==0&&(l===0||!n||i.z<=n.z)?(s=i,i=i.nextZ,o--):(s=n,n=n.nextZ,l--),a?a.nextZ=s:e=s,s.prevZ=a,a=s;i=n}a.nextZ=null,r*=2}while(t>1);return e}function Jv(e,t,r,i,s){return e=(e-r)*s|0,t=(t-i)*s|0,e=(e|e<<8)&16711935,e=(e|e<<4)&252645135,e=(e|e<<2)&858993459,e=(e|e<<1)&1431655765,t=(t|t<<8)&16711935,t=(t|t<<4)&252645135,t=(t|t<<2)&858993459,t=(t|t<<1)&1431655765,e|t<<1}function xO(e){let t=e,r=e;do(t.x=(e-n)*(a-o)&&(e-n)*(i-o)>=(r-n)*(t-o)&&(r-n)*(a-o)>=(s-n)*(i-o)}function mp(e,t,r,i,s,a,n,o){return!(e===n&&t===o)&&vN(e,t,r,i,s,a,n,o)}function vO(e,t){return e.next.i!==t.i&&e.prev.i!==t.i&&!bO(e,t)&&(fp(e,t)&&fp(t,e)&&TO(e,t)&&(Or(e.prev,e,t.prev)||Or(e,t.prev,t))||hd(e,t)&&Or(e.prev,e,e.next)>0&&Or(t.prev,t,t.next)>0)}function Or(e,t,r){return(t.y-e.y)*(r.x-t.x)-(t.x-e.x)*(r.y-t.y)}function hd(e,t){return e.x===t.x&&e.y===t.y}function bN(e,t,r,i){let s=Vg(Or(e,t,r)),a=Vg(Or(e,t,i)),n=Vg(Or(r,i,e)),o=Vg(Or(r,i,t));return!!(s!==a&&n!==o||s===0&&zg(e,r,t)||a===0&&zg(e,i,t)||n===0&&zg(r,e,i)||o===0&&zg(r,t,i))}function zg(e,t,r){return t.x<=Math.max(e.x,r.x)&&t.x>=Math.min(e.x,r.x)&&t.y<=Math.max(e.y,r.y)&&t.y>=Math.min(e.y,r.y)}function Vg(e){return e>0?1:e<0?-1:0}function bO(e,t){let r=e;do{if(r.i!==e.i&&r.next.i!==e.i&&r.i!==t.i&&r.next.i!==t.i&&bN(r,r.next,e,t))return!0;r=r.next}while(r!==e);return!1}function fp(e,t){return Or(e.prev,e,e.next)<0?Or(e,t,e.next)>=0&&Or(e,e.prev,t)>=0:Or(e,t,e.prev)<0||Or(e,e.next,t)<0}function TO(e,t){let r=e,i=!1,s=(e.x+t.x)/2,a=(e.y+t.y)/2;do r.y>a!=r.next.y>a&&r.next.y!==r.y&&s<(r.next.x-r.x)*(a-r.y)/(r.next.y-r.y)+r.x&&(i=!i),r=r.next;while(r!==e);return i}function TN(e,t){let r=Qv(e.i,e.x,e.y),i=Qv(t.i,t.x,t.y),s=e.next,a=t.prev;return e.next=t,t.prev=e,r.next=s,s.prev=r,i.next=r,r.prev=i,a.next=i,i.prev=a,i}function SN(e,t,r,i){let s=Qv(e,t,r);return i?(s.next=i.next,s.prev=i,i.next.prev=s,i.next=s):(s.prev=s,s.next=s),s}function gp(e){e.next.prev=e.prev,e.prev.next=e.next,e.prevZ&&(e.prevZ.nextZ=e.nextZ),e.nextZ&&(e.nextZ.prevZ=e.prevZ)}function Qv(e,t,r){return{i:e,x:t,y:r,prev:null,next:null,z:0,prevZ:null,nextZ:null,steiner:!1}}function SO(e,t,r,i){let s=0;for(let a=t,n=r-i;a2&&e[t-1].equals(e[0])&&e.pop()}function wN(e,t){for(let r=0;rNumber.EPSILON){let Je=Math.sqrt(Oe),ct=Math.sqrt(ie*ie+V*V),_e=U.x-we/Je,nt=U.y+Te/Je,dt=J.x-V/ct,ft=J.y+ie/ct,Fe=((dt-_e)*V-(ft-nt)*ie)/(Te*V-we*ie);q=_e+Te*Fe-$.x,se=nt+we*Fe-$.y;let it=q*q+se*se;if(it<=2)return new fe(q,se);pe=Math.sqrt(it/2)}else{let Je=!1;Te>Number.EPSILON?ie>Number.EPSILON&&(Je=!0):Te<-Number.EPSILON?ie<-Number.EPSILON&&(Je=!0):Math.sign(we)===Math.sign(V)&&(Je=!0),Je?(q=-we,se=Te,pe=Math.sqrt(Oe)):(q=Te,se=we,pe=Math.sqrt(Oe/2))}return new fe(q/pe,se/pe)}let re=[];for(let $=0,U=z.length,J=U-1,q=$+1;$=0;$--){let U=$/b,J=m*Math.cos(U*Math.PI/2),q=g*Math.sin(U*Math.PI/2)+y;for(let se=0,pe=z.length;se=0;){let q=J,se=J-1;se<0&&(se=$.length-1);for(let pe=0,Te=h+b*2;pe0)&&m.push(T,w,C),(v!==i-1||l0!=e>0&&this.version++,this._anisotropy=e}get clearcoat(){return this._clearcoat}set clearcoat(e){this._clearcoat>0!=e>0&&this.version++,this._clearcoat=e}get iridescence(){return this._iridescence}set iridescence(e){this._iridescence>0!=e>0&&this.version++,this._iridescence=e}get dispersion(){return this._dispersion}set dispersion(e){this._dispersion>0!=e>0&&this.version++,this._dispersion=e}get sheen(){return this._sheen}set sheen(e){this._sheen>0!=e>0&&this.version++,this._sheen=e}get transmission(){return this._transmission}set transmission(e){this._transmission>0!=e>0&&this.version++,this._transmission=e}copy(e){return super.copy(e),this.defines={STANDARD:"",PHYSICAL:""},this.anisotropy=e.anisotropy,this.anisotropyRotation=e.anisotropyRotation,this.anisotropyMap=e.anisotropyMap,this.clearcoat=e.clearcoat,this.clearcoatMap=e.clearcoatMap,this.clearcoatRoughness=e.clearcoatRoughness,this.clearcoatRoughnessMap=e.clearcoatRoughnessMap,this.clearcoatNormalMap=e.clearcoatNormalMap,this.clearcoatNormalScale.copy(e.clearcoatNormalScale),this.dispersion=e.dispersion,this.ior=e.ior,this.iridescence=e.iridescence,this.iridescenceMap=e.iridescenceMap,this.iridescenceIOR=e.iridescenceIOR,this.iridescenceThicknessRange=[...e.iridescenceThicknessRange],this.iridescenceThicknessMap=e.iridescenceThicknessMap,this.sheen=e.sheen,this.sheenColor.copy(e.sheenColor),this.sheenColorMap=e.sheenColorMap,this.sheenRoughness=e.sheenRoughness,this.sheenRoughnessMap=e.sheenRoughnessMap,this.transmission=e.transmission,this.transmissionMap=e.transmissionMap,this.thickness=e.thickness,this.thicknessMap=e.thicknessMap,this.attenuationDistance=e.attenuationDistance,this.attenuationColor.copy(e.attenuationColor),this.specularIntensity=e.specularIntensity,this.specularIntensityMap=e.specularIntensityMap,this.specularColor.copy(e.specularColor),this.specularColorMap=e.specularColorMap,this}},EO=class extends Vs{constructor(e){super(),this.isMeshPhongMaterial=!0,this.type="MeshPhongMaterial",this.color=new gt(16777215),this.specular=new gt(1118481),this.shininess=30,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new gt(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=so,this.normalScale=new fe(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new cn,this.combine=Ff,this.reflectivity=1,this.envMapIntensity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.specular.copy(e.specular),this.shininess=e.shininess,this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.emissive.copy(e.emissive),this.emissiveMap=e.emissiveMap,this.emissiveIntensity=e.emissiveIntensity,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.specularMap=e.specularMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.combine=e.combine,this.reflectivity=e.reflectivity,this.envMapIntensity=e.envMapIntensity,this.refractionRatio=e.refractionRatio,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.flatShading=e.flatShading,this.fog=e.fog,this}},PO=class extends Vs{constructor(e){super(),this.isMeshToonMaterial=!0,this.defines={TOON:""},this.type="MeshToonMaterial",this.color=new gt(16777215),this.map=null,this.gradientMap=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new gt(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=so,this.normalScale=new fe(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.alphaMap=null,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.gradientMap=e.gradientMap,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.emissive.copy(e.emissive),this.emissiveMap=e.emissiveMap,this.emissiveIntensity=e.emissiveIntensity,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.alphaMap=e.alphaMap,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.fog=e.fog,this}},BO=class extends Vs{constructor(e){super(),this.isMeshNormalMaterial=!0,this.type="MeshNormalMaterial",this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=so,this.normalScale=new fe(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.flatShading=!1,this.setValues(e)}copy(e){return super.copy(e),this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.flatShading=e.flatShading,this}},IO=class extends Vs{constructor(e){super(),this.isMeshLambertMaterial=!0,this.type="MeshLambertMaterial",this.color=new gt(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new gt(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=so,this.normalScale=new fe(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new cn,this.combine=Ff,this.reflectivity=1,this.envMapIntensity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.emissive.copy(e.emissive),this.emissiveMap=e.emissiveMap,this.emissiveIntensity=e.emissiveIntensity,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.specularMap=e.specularMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.combine=e.combine,this.reflectivity=e.reflectivity,this.envMapIntensity=e.envMapIntensity,this.refractionRatio=e.refractionRatio,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.flatShading=e.flatShading,this.fog=e.fog,this}},FO=class extends Vs{constructor(e){super(),this.isMeshMatcapMaterial=!0,this.defines={MATCAP:""},this.type="MeshMatcapMaterial",this.color=new gt(16777215),this.matcap=null,this.map=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=so,this.normalScale=new fe(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.alphaMap=null,this.wireframe=!1,this.wireframeLinewidth=1,this.flatShading=!1,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.defines={MATCAP:""},this.color.copy(e.color),this.matcap=e.matcap,this.map=e.map,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.alphaMap=e.alphaMap,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.flatShading=e.flatShading,this.fog=e.fog,this}},LO=class extends hN{constructor(e){super(),this.isLineDashedMaterial=!0,this.type="LineDashedMaterial",this.scale=1,this.dashSize=3,this.gapSize=1,this.setValues(e)}copy(e){return super.copy(e),this.scale=e.scale,this.dashSize=e.dashSize,this.gapSize=e.gapSize,this}};function Wg(e,t){return!e||e.constructor===t?e:typeof t.BYTES_PER_ELEMENT=="number"?new t(e):Array.prototype.slice.call(e)}var yp=class{constructor(e,t,r,i){this.parameterPositions=e,this._cachedIndex=0,this.resultBuffer=i!==void 0?i:new t.constructor(r),this.sampleValues=t,this.valueSize=r,this.settings=null,this.DefaultSettings_={}}evaluate(e){let t=this.parameterPositions,r=this._cachedIndex,i=t[r],s=t[r-1];e:{t:{let a;r:{i:if(!(e=s)){let n=t[1];e=s)break t}a=r,r=0;break r}break e}for(;r>>1;et;)--a;if(++a,s!==0||a!==i){s>=a&&(a=Math.max(a,1),s=a-1);let n=this.getValueSize();this.times=r.slice(s,a),this.values=this.values.slice(s*n,a*n)}return this}validate(){let e=!0,t=this.getValueSize();t-Math.floor(t)!==0&&(Ce("KeyframeTrack: Invalid value size in track.",this),e=!1);let r=this.times,i=this.values,s=r.length;s===0&&(Ce("KeyframeTrack: Track is empty.",this),e=!1);let a=null;for(let n=0;n!==s;n++){let o=r[n];if(typeof o=="number"&&isNaN(o)){Ce("KeyframeTrack: Time is not a valid number.",this,n,o),e=!1;break}if(a!==null&&a>o){Ce("KeyframeTrack: Out of order keys.",this,n,o,a),e=!1;break}a=o}if(i!==void 0&&ip(i))for(let n=0,o=i.length;n!==o;++n){let l=i[n];if(isNaN(l)){Ce("KeyframeTrack: Value is not a valid number.",this,n,l),e=!1;break}}return e}optimize(){let e=this.times.slice(),t=this.values.slice(),r=this.getValueSize(),i=this.getInterpolation()===mv,s=e.length-1,a=1;for(let n=1;n0){e[a]=e[s];for(let n=s*r,o=a*r,l=0;l!==r;++l)t[o+l]=t[n+l];++a}return a!==e.length?(this.times=e.slice(0,a),this.values=t.slice(0,a*r)):(this.times=e,this.values=t),this}clone(){let e=this.times.slice(),t=this.values.slice(),r=this.constructor,i=new r(this.name,e,t);return i.createInterpolant=this.createInterpolant,i}};yn.prototype.ValueTypeName="",yn.prototype.TimeBufferType=Float32Array,yn.prototype.ValueBufferType=Float32Array,yn.prototype.DefaultInterpolation=pv;var xp=class extends yn{constructor(e,t,r){super(e,t,r)}};xp.prototype.ValueTypeName="bool",xp.prototype.ValueBufferType=Array,xp.prototype.DefaultInterpolation=pg,xp.prototype.InterpolantFactoryMethodLinear=void 0,xp.prototype.InterpolantFactoryMethodSmooth=void 0;var zO=class extends yn{constructor(e,t,r,i){super(e,t,r,i)}};zO.prototype.ValueTypeName="color";var VO=class extends yn{constructor(e,t,r,i){super(e,t,r,i)}};VO.prototype.ValueTypeName="number";var GO=class extends yp{constructor(e,t,r,i){super(e,t,r,i)}interpolate_(e,t,r,i){let s=this.resultBuffer,a=this.sampleValues,n=this.valueSize,o=(r-t)/(i-t),l=e*n;for(let u=l+n;l!==u;l+=4)si.slerpFlat(s,0,a,l-n,a,l,o);return s}},CN=class extends yn{constructor(e,t,r,i){super(e,t,r,i)}InterpolantFactoryMethodLinear(e){return new GO(this.times,this.values,this.getValueSize(),e)}};CN.prototype.ValueTypeName="quaternion",CN.prototype.InterpolantFactoryMethodSmooth=void 0;var vp=class extends yn{constructor(e,t,r){super(e,t,r)}};vp.prototype.ValueTypeName="string",vp.prototype.ValueBufferType=Array,vp.prototype.DefaultInterpolation=pg,vp.prototype.InterpolantFactoryMethodLinear=void 0,vp.prototype.InterpolantFactoryMethodSmooth=void 0;var WO=class extends yn{constructor(e,t,r,i){super(e,t,r,i)}};WO.prototype.ValueTypeName="vector";var bp={enabled:!1,files:{},add:function(e,t){this.enabled!==!1&&(RN(e)||(this.files[e]=t))},get:function(e){if(this.enabled!==!1&&!RN(e))return this.files[e]},remove:function(e){delete this.files[e]},clear:function(){this.files={}}};function RN(e){try{let t=e.slice(e.indexOf(":")+1);return new URL(t).protocol==="blob:"}catch{return!1}}var jO=class{constructor(e,t,r){let i=this,s=!1,a=0,n=0,o,l=[];this.onStart=void 0,this.onLoad=e,this.onProgress=t,this.onError=r,this._abortController=null,this.itemStart=function(u){n++,s===!1&&i.onStart!==void 0&&i.onStart(u,a,n),s=!0},this.itemEnd=function(u){a++,i.onProgress!==void 0&&i.onProgress(u,a,n),a===n&&(s=!1,i.onLoad!==void 0&&i.onLoad())},this.itemError=function(u){i.onError!==void 0&&i.onError(u)},this.resolveURL=function(u){return u=u.normalize("NFC"),o?o(u):u},this.setURLModifier=function(u){return o=u,this},this.addHandler=function(u,h){return l.push(u,h),this},this.removeHandler=function(u){let h=l.indexOf(u);return h!==-1&&l.splice(h,2),this},this.getHandler=function(u){for(let h=0,d=l.length;h{t&&t(s),this.manager.itemEnd(e)},0);return}if(mo[e]!==void 0){mo[e].push({onLoad:t,onProgress:r,onError:i});return}mo[e]=[],mo[e].push({onLoad:t,onProgress:r,onError:i});let a=new Request(e,{headers:new Headers(this.requestHeader),credentials:this.withCredentials?"include":"same-origin",signal:typeof AbortSignal.any=="function"?AbortSignal.any([this._abortController.signal,this.manager.abortController.signal]):this._abortController.signal}),n=this.mimeType,o=this.responseType;fetch(a).then(l=>{if(l.status===200||l.status===0){if(l.status===0&&Ue("FileLoader: HTTP Status 0 received."),typeof ReadableStream>"u"||l.body===void 0||l.body.getReader===void 0)return l;let u=mo[e],h=l.body.getReader(),d=l.headers.get("X-File-Size")||l.headers.get("Content-Length"),c=d?parseInt(d):0,m=c!==0,g=0,y=new ReadableStream({start(b){v();function v(){h.read().then(({done:S,value:T})=>{if(S)b.close();else{g+=T.byteLength;let w=new ProgressEvent("progress",{lengthComputable:m,loaded:g,total:c});for(let N=0,C=u.length;N{b.error(S)})}}});return new Response(y)}else throw new XO(`fetch for "${l.url}" responded with ${l.status}: ${l.statusText}`,l)}).then(l=>{switch(o){case"arraybuffer":return l.arrayBuffer();case"blob":return l.blob();case"document":return l.text().then(u=>new DOMParser().parseFromString(u,n));case"json":return l.json();default:if(n==="")return l.text();{let u=/charset="?([^;"\s]*)"?/i.exec(n),h=u&&u[1]?u[1].toLowerCase():void 0,d=new TextDecoder(h);return l.arrayBuffer().then(c=>d.decode(c))}}}).then(l=>{bp.add(`file:${e}`,l);let u=mo[e];delete mo[e];for(let h=0,d=u.length;h{let u=mo[e];if(u===void 0)throw this.manager.itemError(e),l;delete mo[e];for(let h=0,d=u.length;h{this.manager.itemEnd(e)}),this.manager.itemStart(e)}setResponseType(e){return this.responseType=e,this}setMimeType(e){return this.mimeType=e,this}abort(){return this._abortController.abort(),this._abortController=new AbortController,this}},cd=new WeakMap,qO=class extends Tp{constructor(e){super(e)}load(e,t,r,i){this.path!==void 0&&(e=this.path+e),e=this.manager.resolveURL(e);let s=this,a=bp.get(`image:${e}`);if(a!==void 0){if(a.complete===!0)s.manager.itemStart(e),setTimeout(function(){t&&t(a),s.manager.itemEnd(e)},0);else{let h=cd.get(a);h===void 0&&(h=[],cd.set(a,h)),h.push({onLoad:t,onError:i})}return a}let n=gg("img");function o(){u(),t&&t(this);let h=cd.get(this)||[];for(let d=0;d=this.min.x&&e.x<=this.max.x&&e.y>=this.min.y&&e.y<=this.max.y}containsBox(e){return this.min.x<=e.min.x&&e.max.x<=this.max.x&&this.min.y<=e.min.y&&e.max.y<=this.max.y}getParameter(e,t){return t.set((e.x-this.min.x)/(this.max.x-this.min.x),(e.y-this.min.y)/(this.max.y-this.min.y))}intersectsBox(e){return e.max.x>=this.min.x&&e.min.x<=this.max.x&&e.max.y>=this.min.y&&e.min.y<=this.max.y}clampPoint(e,t){return t.copy(e).clamp(this.min,this.max)}distanceToPoint(e){return this.clampPoint(e,DN).distanceTo(e)}intersect(e){return this.min.max(e.min),this.max.min(e.max),this.isEmpty()&&this.makeEmpty(),this}union(e){return this.min.min(e.min),this.max.max(e.max),this}translate(e){return this.min.add(e),this.max.add(e),this}equals(e){return e.min.equals(this.min)&&e.max.equals(this.max)}},ON=new F,qg=new F,fd=new F,gd=new F,lb=new F,yU=new F,xU=new F,fo=class{constructor(e=new F,t=new F){this.start=e,this.end=t}set(e,t){return this.start.copy(e),this.end.copy(t),this}copy(e){return this.start.copy(e.start),this.end.copy(e.end),this}getCenter(e){return e.addVectors(this.start,this.end).multiplyScalar(.5)}delta(e){return e.subVectors(this.end,this.start)}distanceSq(){return this.start.distanceToSquared(this.end)}distance(){return this.start.distanceTo(this.end)}at(e,t){return this.delta(t).multiplyScalar(e).add(this.start)}closestPointToPointParameter(e,t){ON.subVectors(e,this.start),qg.subVectors(this.end,this.start);let r=qg.dot(qg);if(r===0)return 0;let i=qg.dot(ON)/r;return t&&(i=St(i,0,1)),i}closestPointToPoint(e,t,r){let i=this.closestPointToPointParameter(e,t);return this.delta(r).multiplyScalar(i).add(this.start)}distanceSqToLine3(e,t=yU,r=xU){let i=10000000000000001e-32,s,a,n=this.start,o=e.start,l=this.end,u=e.end;fd.subVectors(l,n),gd.subVectors(u,o),lb.subVectors(n,o);let h=fd.dot(fd),d=gd.dot(gd),c=gd.dot(lb);if(h<=i&&d<=i)return t.copy(n),r.copy(o),t.sub(r),t.dot(t);if(h<=i)s=0,a=c/d,a=St(a,0,1);else{let m=fd.dot(lb);if(d<=i)a=0,s=St(-m/h,0,1);else{let g=fd.dot(gd),y=h*d-g*g;y!==0?s=St((g*c-m*d)/y,0,1):s=0,a=(g*s+c)/d,a<0?(a=0,s=St(-m/h,0,1)):a>1&&(a=1,s=St((g-m)/h,0,1))}}return t.copy(n).addScaledVector(fd,s),r.copy(o).addScaledVector(gd,a),t.distanceToSquared(r)}applyMatrix4(e){return this.start.applyMatrix4(e),this.end.applyMatrix4(e),this}equals(e){return e.start.equals(this.start)&&e.end.equals(this.end)}clone(){return new this.constructor().copy(this)}},nl=class{constructor(){this.type="ShapePath",this.color=new gt,this.subPaths=[],this.currentPath=null,this.userData={}}moveTo(e,t){return this.currentPath=new po,this.subPaths.push(this.currentPath),this.currentPath.moveTo(e,t),this}lineTo(e,t){return this.currentPath.lineTo(e,t),this}quadraticCurveTo(e,t,r,i){return this.currentPath.quadraticCurveTo(e,t,r,i),this}bezierCurveTo(e,t,r,i,s,a){return this.currentPath.bezierCurveTo(e,t,r,i,s,a),this}splineThru(e){return this.currentPath.splineThru(e),this}toShapes(){function e(o,l){let u=!1,h=l.length;for(let d=0,c=h-1;do.y!=g.y>o.y&&o.x<(g.x-m.x)*(o.y-m.y)/(g.y-m.y)+m.x&&(u=!u)}return u}function t(o,l){let u=l.getCenter(new fe);if(e(u,o))return u;let h=u.y,d=[],c=o.length;for(let m=0;mh!=y.y>h){let b=g.x+(h-g.y)*(y.x-g.x)/(y.y-g.y);d.push(b)}}return d.length>1&&(d.sort((m,g)=>m-g),u.x=(d[0]+d[1])/2),u}let r=this.userData.style&&this.userData.style.fillRule||"nonzero";r!=="nonzero"&&r!=="evenodd"&&(Ue('Fill-rule "'+r+'" is not supported, falling back to "nonzero".'),r="nonzero");let i=r==="nonzero"?o=>o!==0:o=>(o&1)!==0,s=[];for(let o of this.subPaths){let l=o.getPoints();if(l.length<3)continue;let u=dd.area(l);if(u===0)continue;let h=new ob;for(let d=0;dl.absArea-o.absArea);for(let o=0;o=0;h--){let d=s[h];if(d.boundingBox.containsBox(l.boundingBox)&&e(l.interiorPoint,d.points)){l.container=d.exclude?d.container:d,u=d.winding,l.winding+=u;break}}i(l.winding)===i(u)&&(l.exclude=!0)}for(let o of s)o.exclude||(o.role=o.container===null||o.container.role==="hole"?"outer":"hole");let a=[],n=new Map;for(let o of s){if(o.exclude||o.role!=="outer")continue;let l=new cp;l.curves=o.subPath.curves,a.push(l),n.set(o,l)}for(let o of s){if(o.exclude||o.role!=="hole")continue;let l=n.get(o.container);if(!l)continue;let u=new po;u.curves=o.subPath.curves,l.holes.push(u)}return a}};function vU(e,t,r,i){let s=bU(i);switch(r){case ov:return e*t;case io:return e*t/s.components*s.byteLength;case jh:return e*t/s.components*s.byteLength;case ha:return e*t*2/s.components*s.byteLength;case Hh:return e*t*2/s.components*s.byteLength;case Wh:return e*t*3/s.components*s.byteLength;case pi:return e*t*4/s.components*s.byteLength;case zf:return e*t*4/s.components*s.byteLength;case Yc:case Zc:return Math.floor((e+3)/4)*Math.floor((t+3)/4)*8;case Jc:case Qc:return Math.floor((e+3)/4)*Math.floor((t+3)/4)*16;case hv:case cv:return Math.max(e,16)*Math.max(t,8)/4;case uv:case dv:return Math.max(e,8)*Math.max(t,8)/2;case Vf:case Gf:case jf:case Hf:return Math.floor((e+3)/4)*Math.floor((t+3)/4)*8;case Wf:case Kc:case Xf:return Math.floor((e+3)/4)*Math.floor((t+3)/4)*16;case $f:return Math.floor((e+3)/4)*Math.floor((t+3)/4)*16;case qf:return Math.floor((e+4)/5)*Math.floor((t+3)/4)*16;case Yf:return Math.floor((e+4)/5)*Math.floor((t+4)/5)*16;case Zf:return Math.floor((e+5)/6)*Math.floor((t+4)/5)*16;case Jf:return Math.floor((e+5)/6)*Math.floor((t+5)/6)*16;case Qf:return Math.floor((e+7)/8)*Math.floor((t+4)/5)*16;case Kf:return Math.floor((e+7)/8)*Math.floor((t+5)/6)*16;case eg:return Math.floor((e+7)/8)*Math.floor((t+7)/8)*16;case tg:return Math.floor((e+9)/10)*Math.floor((t+4)/5)*16;case rg:return Math.floor((e+9)/10)*Math.floor((t+5)/6)*16;case ig:return Math.floor((e+9)/10)*Math.floor((t+7)/8)*16;case sg:return Math.floor((e+9)/10)*Math.floor((t+9)/10)*16;case ag:return Math.floor((e+11)/12)*Math.floor((t+9)/10)*16;case ng:return Math.floor((e+11)/12)*Math.floor((t+11)/12)*16;case og:case lg:case ug:return Math.ceil(e/4)*Math.ceil(t/4)*16;case hg:case dg:return Math.ceil(e/4)*Math.ceil(t/4)*8;case ep:case cg:return Math.ceil(e/4)*Math.ceil(t/4)*16}throw new Error(`Unable to determine texture byte length for ${r} format.`)}function bU(e){switch(e){case Si:case cu:return{byteLength:1,components:1};case Ko:case pu:case Dt:return{byteLength:2,components:1};case av:case nv:return{byteLength:2,components:4};case gr:case ci:case Er:return{byteLength:4,components:1};case Of:case Uf:return{byteLength:4,components:3}}throw new Error(`THREE.TextureUtils: Unknown texture type ${e}.`)}typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:"185"}})),typeof window<"u"&&(window.__THREE__?Ue("WARNING: Multiple instances of Three.js being imported."):window.__THREE__="185");var TU=["alphaMap","alphaTest","anisotropy","anisotropyMap","anisotropyRotation","aoMap","aoMapIntensity","attenuationColor","attenuationDistance","bumpMap","clearcoat","clearcoatMap","clearcoatNormalMap","clearcoatNormalScale","clearcoatRoughness","color","dispersion","displacementMap","emissive","emissiveIntensity","emissiveMap","envMap","envMapIntensity","envMapRotation","gradientMap","ior","iridescence","iridescenceIOR","iridescenceMap","iridescenceThicknessMap","lightMap","lightMapIntensity","map","matcap","metalness","metalnessMap","normalMap","normalScale","opacity","roughness","roughnessMap","sheen","sheenColor","sheenColorMap","sheenRoughnessMap","shininess","specular","specularColor","specularColorMap","specularIntensity","specularIntensityMap","specularMap","thickness","transmission","transmissionMap"],UN=new WeakMap,zN=new WeakMap,VN=new WeakMap,SU=class{constructor(e){this.renderObjects=new WeakMap,this.hasNode=this.containsNode(e),this.hasAnimation=e.object.isSkinnedMesh===!0,this.refreshUniforms=TU,this.renderId=0}firstInitialization(e){return this.renderObjects.has(e)===!1?(this.getRenderObjectData(e),!0):!1}needsVelocity(e){let t=e.getMRT();return t!==null&&t.has("velocity")}getRenderObjectData(e){let t=this.renderObjects.get(e);if(t===void 0){let{geometry:r,object:i}=e;if(t={geometryId:r.id,worldMatrix:i.matrixWorld.clone()},i.center&&(t.center=i.center.clone()),i.morphTargetInfluences&&(t.morphTargetInfluences=i.morphTargetInfluences.slice()),e.bundle!==null&&(t.version=e.bundle.version),e.material.transmission>0){let{width:n,height:o}=e.context;t.bufferWidth=n,t.bufferHeight=o}let{environmentIntensity:s,environmentRotation:a}=e.scene;t.environmentIntensity=s,t.environmentRotation=a.clone(),t.lights=this.getLightsData(e.lightsNode.getLights(),[]),this.renderObjects.set(e,t)}return t}getAttributesData(e){let t={};for(let r in e){let i=e[r];t[r]={id:i.isInterleavedBufferAttribute?i.data.uuid:i.id,version:i.isInterleavedBufferAttribute?i.data.version:i.version}}return t}containsNode(e){let t=e.material;for(let r in t)if(t[r]&&t[r].isNode)return!0;return!!(e.context.modelViewMatrix||e.context.modelNormalViewMatrix||e.context.getAO||e.context.getShadow)}getGeometryData(e){let t=VN.get(e);return t===void 0&&(t={_renderId:-1,_equal:!1,attributes:this.getAttributesData(e.attributes),indexId:e.index?e.index.id:null,indexVersion:e.index?e.index.version:null,drawRange:{start:e.drawRange.start,count:e.drawRange.count}},VN.set(e,t)),t}getMaterialData(e){let t=zN.get(e);if(t===void 0){t={_renderId:-1,_equal:!1};for(let r of this.refreshUniforms){let i=e[r];i!=null&&(typeof i=="object"&&i.clone!==void 0?i.isTexture===!0?t[r]={id:i.id,version:0}:t[r]=i.clone():t[r]=i)}zN.set(e,t)}return t}equals(e,t,r){let{object:i,material:s,geometry:a}=e,n=this.getRenderObjectData(e);if(n.worldMatrix.equals(i.matrixWorld)!==!0)return n.worldMatrix.copy(i.matrixWorld),!1;let o=this.getMaterialData(e.material);if(o._renderId!==r){o._renderId=r;for(let h in o){let d=o[h],c=s[h];if(h!=="_renderId"&&h!=="_equal"){if(d.equals!==void 0){if(d.equals(c)===!1)return d.copy(c),o._equal=!1,!1}else if(c.isTexture===!0){if(d.id!==c.id||d.version!==c.version)return d.id=c.id,d.version=c.version,o._equal=!1,!1}else if(d!==c)return o[h]=c,o._equal=!1,!1}}if(o.transmission>0){let{width:h,height:d}=e.context;if(n.bufferWidth!==h||n.bufferHeight!==d)return n.bufferWidth=h,n.bufferHeight=d,o._equal=!1,!1}o._equal=!0}else if(o._equal===!1)return!1;if(n.geometryId!==a.id)return n.geometryId=a.id,!1;let l=this.getGeometryData(e.geometry);if(l._renderId!==r){l._renderId=r;let h=a.attributes,d=l.attributes,c=0,m=0;for(let T in h)c++;for(let T in d){m++;let w=d[T],N=h[T];if(N===void 0)return delete d[T],l._equal=!1,!1;let C=N.isInterleavedBufferAttribute?N.data.uuid:N.id,R=N.isInterleavedBufferAttribute?N.data.version:N.version;if(w.id!==C||w.version!==R)return w.id=C,w.version=R,l._equal=!1,!1}if(m!==c)return l.attributes=this.getAttributesData(h),l._equal=!1,!1;let g=a.index,y=l.indexId,b=l.indexVersion,v=g?g.id:null,S=g?g.version:null;if(y!==v||b!==S)return l.indexId=v,l.indexVersion=S,l._equal=!1,!1;if(l.drawRange.start!==a.drawRange.start||l.drawRange.count!==a.drawRange.count)return l.drawRange.start=a.drawRange.start,l.drawRange.count=a.drawRange.count,l._equal=!1,!1;l._equal=!0}else if(l._equal===!1)return!1;if(n.morphTargetInfluences){let h=!1;for(let d=0;d{let i=r.match(t);if(!i)return null;let s=i[1]||i[2]||"",a=i[3].split("?")[0],n=parseInt(i[4],10),o=parseInt(i[5],10),l=a.split("/").pop();return{fn:s,file:l,line:n,column:o}}).filter(r=>r&&!_U.some(i=>i.test(r.file)))}var $r=class{constructor(e=null){this.isStackTrace=!0,this.stack=wU(e||new Error().stack)}getLocation(){if(this.stack.length===0)return"[Unknown location]";let e=this.stack[0],t=e.fn;return`${t?`"${t}()" at `:""}"${e.file}:${e.line}"`}getError(e){if(this.stack.length===0)return e;let t=this.stack.map(r=>{let i=`${r.file}:${r.line}:${r.column}`;return r.fn?` at ${r.fn} (${i})`:` at ${i}`}).join(` `);return`${e} ${t}`}};function ub(e,t=0){let r=3735928559^t,i=1103547991^t;if(Array.isArray(e))for(let s=0,a;s>>16,2246822507),r^=Math.imul(i^i>>>13,3266489909),i=Math.imul(i^i>>>16,2246822507),i^=Math.imul(r^r>>>13,3266489909),4294967296*(2097151&i)+(r>>>0)}var yd=e=>ub(e),Sp=e=>ub(e),_p=(...e)=>ub(e),MU=new Map([[1,"float"],[2,"vec2"],[3,"vec3"],[4,"vec4"],[9,"mat3"],[16,"mat4"]]),GN=new WeakMap;function WN(e){return MU.get(e)}function Yg(e){if(/[iu]?vec\d/.test(e))return e.startsWith("ivec")?Int32Array:e.startsWith("uvec")?Uint32Array:Float32Array;if(/mat\d/.test(e)||/float/.test(e))return Float32Array;if(/uint/.test(e))return Uint32Array;if(/int/.test(e))return Int32Array;throw new Error(`THREE.NodeUtils: Unsupported type: ${e}`)}function jN(e){if(/float|int|uint|bool/.test(e))return 1;if(/vec2/.test(e))return 2;if(/vec3/.test(e))return 3;if(/vec4/.test(e)||/mat2/.test(e))return 4;if(/mat3/.test(e))return 9;if(/mat4/.test(e))return 16;Ce(`TSL: Unsupported type: ${e}`,new $r)}function NU(e){if(/float|int|uint|bool/.test(e))return 1;if(/vec2/.test(e))return 2;if(/vec3/.test(e))return 3;if(/vec4/.test(e)||/mat2/.test(e))return 4;if(/mat3/.test(e))return 12;if(/mat4/.test(e))return 16;Ce(`TSL: Unsupported type: ${e}`,new $r)}function AU(e){if(/float|int|uint|bool/.test(e))return 1;if(/vec2/.test(e))return 2;if(/vec3/.test(e)||/vec4/.test(e))return 4;if(/mat2/.test(e))return 2;if(/mat3/.test(e)||/mat4/.test(e))return 4;Ce(`TSL: Unsupported type: ${e}`,new $r)}function ol(e){if(e==null)return null;let t=typeof e;return e.isNode===!0?"node":t==="number"?"float":t==="boolean"?"bool":t==="string"?"string":t==="function"?"shader":e.isVector2===!0?"vec2":e.isVector3===!0?"vec3":e.isVector4===!0?"vec4":e.isMatrix2===!0?"mat2":e.isMatrix3===!0?"mat3":e.isMatrix4===!0?"mat4":e.isColor===!0?"color":e instanceof ArrayBuffer?"ArrayBuffer":null}function hb(e,...t){let r=e?e.slice(-4):void 0;return t.length===1&&(r==="vec2"?t=[t[0],t[0]]:r==="vec3"?t=[t[0],t[0],t[0]]:r==="vec4"&&(t=[t[0],t[0],t[0],t[0]])),e==="color"?new gt(...t):r==="vec2"?new fe(...t):r==="vec3"?new F(...t):r==="vec4"?new Wt(...t):r==="mat2"?new kN(...t):r==="mat3"?new Dr(...t):r==="mat4"?new We(...t):e==="bool"?t[0]||!1:e==="float"||e==="int"||e==="uint"?t[0]||0:e==="string"?t[0]||"":e==="ArrayBuffer"?RU(t[0]):null}function HN(e){let t=GN.get(e);return t===void 0&&(t={},GN.set(e,t)),t}function CU(e){let t="",r=new Uint8Array(e);for(let i=0;it.charCodeAt(0)).buffer}var xd={VERTEX:"vertex",FRAGMENT:"fragment"},ut={NONE:"none",FRAME:"frame",RENDER:"render",OBJECT:"object"},EU={BOOLEAN:"bool",INTEGER:"int",FLOAT:"float",VECTOR2:"vec2",VECTOR3:"vec3",VECTOR4:"vec4",MATRIX2:"mat2",MATRIX3:"mat3",MATRIX4:"mat4"},Fi={READ_ONLY:"readOnly",WRITE_ONLY:"writeOnly",READ_WRITE:"readWrite"},XN=["fragment","vertex"],Zg=["setup","analyze","generate"],Jg=[...XN,"compute"],Su=["x","y","z","w"],PU={analyze:"setup",generate:"analyze"},BU=0,Ke=class rD extends hn{static get type(){return"Node"}constructor(t=null){super(),this.nodeType=t,this.updateType=ut.NONE,this.updateBeforeType=ut.NONE,this.updateAfterType=ut.NONE,this.version=0,this.name="",this.global=!1,this.parents=!1,this.isNode=!0,this._beforeNodes=null,this._cacheKey=null,this._uuid=null,this._cacheKeyVersion=0,this.id=BU++,this.stackTrace=null,rD.captureStackTrace===!0&&(this.stackTrace=new $r)}set needsUpdate(t){t===!0&&this.version++}get uuid(){return this._uuid===null&&(this._uuid=Bt.generateUUID()),this._uuid}get type(){return this.constructor.type}onUpdate(t,r){return this.updateType=r,this.update=t.bind(this),this}onFrameUpdate(t){return this.onUpdate(t,ut.FRAME)}onRenderUpdate(t){return this.onUpdate(t,ut.RENDER)}onObjectUpdate(t){return this.onUpdate(t,ut.OBJECT)}onReference(t){return this.updateReference=t.bind(this),this}updateReference(){return this}isGlobal(){return this.global}*getChildren(){for(let{childNode:t}of this._getChildren())yield t}dispose(){this.dispatchEvent({type:"dispose"})}traverse(t){t(this);for(let r of this.getChildren())r.traverse(t)}_getChildren(t=new Set){let r=[];t.add(this);for(let i of Object.getOwnPropertyNames(this)){let s=this[i];if(!(i.startsWith("_")===!0||t.has(s))){if(Array.isArray(s)===!0)for(let a=0;a0&&(t.inputNodes=i)}deserialize(t){if(t.inputNodes!==void 0){let r=t.meta.nodes;for(let i in t.inputNodes)if(Array.isArray(t.inputNodes[i])){let s=[];for(let a of t.inputNodes[i])s.push(r[a]);this[i]=s}else if(typeof t.inputNodes[i]=="object"){let s={};for(let a in t.inputNodes[i]){let n=t.inputNodes[i][a];s[a]=r[n]}this[i]=s}else{let s=t.inputNodes[i];this[i]=r[s]}}}toJSON(t){let{uuid:r,type:i}=this,s=t===void 0||typeof t=="string";s&&(t={textures:{},images:{},nodes:{}});let a=t.nodes[r];a===void 0&&(a={uuid:r,type:i,meta:t,metadata:{version:4.7,type:"Node",generator:"Node.toJSON"}},s!==!0&&(t.nodes[a.uuid]=a),this.serialize(a),delete a.meta);function n(o){let l=[];for(let u in o){let h=o[u];delete h.metadata,l.push(h)}return l}if(s){let o=n(t.textures),l=n(t.images),u=n(t.nodes);o.length>0&&(a.textures=o),l.length>0&&(a.images=l),u.length>0&&(a.nodes=u)}return a}};Ke.captureStackTrace=!1;var _u=class extends Ke{static get type(){return"ArrayElementNode"}constructor(e,t){super(),this.node=e,this.indexNode=t,this.isArrayElementNode=!0}generateNodeType(e){return this.node.getElementType(e)}getMemberType(e,t){return this.node.getMemberType(e,t)}generate(e){let t=this.indexNode.getNodeType(e),r=this.node.build(e),i=this.indexNode.build(e,!e.isVector(t)&&e.isInteger(t)?t:"uint");return`${r}[ ${i} ]`}},$N=class extends Ke{static get type(){return"ConvertNode"}constructor(e,t){super(),this.node=e,this.convertTo=t}generateNodeType(e){let t=this.node.getNodeType(e),r=null;for(let i of this.convertTo.split("|"))(r===null||e.getTypeLength(t)===e.getTypeLength(i))&&(r=i);return r}serialize(e){super.serialize(e),e.convertTo=this.convertTo}deserialize(e){super.deserialize(e),this.convertTo=e.convertTo}generate(e,t){let r=this.node,i=this.getNodeType(e),s=r.build(e,i);return e.format(s,i,t)}},rr=class extends Ke{static get type(){return"TempNode"}constructor(e=null){super(e),this.isTempNode=!0}hasDependencies(e){return e.getDataFromNode(this).usageCount>1}build(e,t){if(e.getBuildStage()==="generate"){let r=e.getVectorType(this.getNodeType(e,t)),i=e.getDataFromNode(this);if(i.propertyName!==void 0)return e.format(i.propertyName,r,t);if(r!=="void"&&t!=="void"&&this.hasDependencies(e)){let s=super.build(e,r),a=e.getVarFromNode(this,null,r),n=e.getPropertyName(a);return e.addLineFlowCode(`${n} = ${s}`,this),i.snippet=s,i.propertyName=n,e.format(i.propertyName,r,t)}}return super.build(e,t)}},IU=class extends rr{static get type(){return"JoinNode"}constructor(e=[],t=null){super(t),this.nodes=e}generateNodeType(e){return this.nodeType!==null?e.getVectorType(this.nodeType):e.getTypeFromLength(this.nodes.reduce((t,r)=>t+e.getTypeLength(r.getNodeType(e)),0))}generate(e,t){let r=this.getNodeType(e),i=e.getTypeLength(r),s=this.nodes,a=e.getComponentType(r),n=[],o=0;for(let u of s){if(o>=i){Ce(`TSL: Length of parameters exceeds maximum length of function '${r}()' type.`,this.stackTrace);break}let h=u.getNodeType(e),d=e.getTypeLength(h),c;if(o+d>i&&(Ce(`TSL: Length of '${r}()' data exceeds maximum length of output type.`,this.stackTrace),d=i-o,h=e.getTypeFromLength(d)),o+=d,c=u.build(e,h),e.getComponentType(h)!==a){let m=e.getTypeFromLength(d,a);c=e.format(c,h,m)}n.push(c)}let l=`${e.getType(r)}( ${n.join(", ")} )`;return e.format(l,r,t)}},FU=Su.join(""),qN=class extends Ke{static get type(){return"SplitNode"}constructor(e,t="x"){super(),this.node=e,this.components=t,this.isSplitNode=!0}getVectorLength(){let e=this.components.length;for(let t of this.components)e=Math.max(Su.indexOf(t)+1,e);return e}getComponentType(e){return e.getComponentType(this.node.getNodeType(e))}generateNodeType(e){return e.getTypeFromLength(this.components.length,this.getComponentType(e))}getScope(){return this.node.getScope()}generate(e,t){let r=this.node,i=e.getTypeLength(r.getNodeType(e)),s=null;if(i>1){let a=null;this.getVectorLength()>=i&&(a=e.getTypeFromLength(this.getVectorLength(),this.getComponentType(e)));let n=r.build(e,a);this.components.length===i&&this.components===FU.slice(0,this.components.length)?s=e.format(n,a,t):s=e.format(`${n}.${this.components}`,this.getNodeType(e),t)}else s=r.build(e,t);return s}serialize(e){super.serialize(e),e.components=this.components}deserialize(e){super.deserialize(e),this.components=e.components}},LU=class extends rr{static get type(){return"SetNode"}constructor(e,t,r){super(),this.sourceNode=e,this.components=t,this.targetNode=r}generateNodeType(e){return this.sourceNode.getNodeType(e)}generate(e){let{sourceNode:t,components:r,targetNode:i}=this,s=this.getNodeType(e),a=e.getComponentType(i.getNodeType(e)),n=e.getTypeFromLength(r.length,a),o=i.build(e,n),l=t.build(e,s),u=e.getTypeLength(s),h=[];for(let d=0;de.replace(/r|s/g,"x").replace(/g|t/g,"y").replace(/b|p/g,"z").replace(/a|q/g,"w"),ZN=e=>OU(e).split("").sort().join("");Ke.prototype.assign=function(...e){if(this.isStackNode!==!0)return ll!==null?ll.assign(this,...e):Ce("TSL: No stack defined for assign operation. Make sure the assign is inside a Fn().",new $r),this;{let t=cb.get("assign");return this.addToStack(t(...e))}},Ke.prototype.toVarIntent=function(){return this},Ke.prototype.get=function(e){return new DU(this,e)};var wp={};function Qg(e,t,r){wp[e]=wp[t]=wp[r]={get(){this._cache=this._cache||{};let n=this._cache[e];return n===void 0&&(n=new qN(this,e),this._cache[e]=n),n},set(n){this[e].assign(Ye(n))}};let i=e.toUpperCase(),s=t.toUpperCase(),a=r.toUpperCase();Ke.prototype["set"+i]=Ke.prototype["set"+s]=Ke.prototype["set"+a]=function(n){let o=ZN(e);return new LU(this,o,Ye(n))},Ke.prototype["flip"+i]=Ke.prototype["flip"+s]=Ke.prototype["flip"+a]=function(){let n=ZN(e);return new kU(this,n)}}var bn=["x","y","z","w"],Tn=["r","g","b","a"],Sn=["s","t","p","q"];for(let e=0;e<4;e++){let t=bn[e],r=Tn[e],i=Sn[e];Qg(t,r,i);for(let s=0;s<4;s++){t=bn[e]+bn[s],r=Tn[e]+Tn[s],i=Sn[e]+Sn[s],Qg(t,r,i);for(let a=0;a<4;a++){t=bn[e]+bn[s]+bn[a],r=Tn[e]+Tn[s]+Tn[a],i=Sn[e]+Sn[s]+Sn[a],Qg(t,r,i);for(let n=0;n<4;n++)t=bn[e]+bn[s]+bn[a]+bn[n],r=Tn[e]+Tn[s]+Tn[a]+Tn[n],i=Sn[e]+Sn[s]+Sn[a]+Sn[n],Qg(t,r,i)}}}for(let e=0;e<32;e++)wp[e]={get(){this._cache=this._cache||{};let t=this._cache[e];return t===void 0&&(t=new _u(this,new vn(e,"uint")),this._cache[e]=t),t},set(t){this[e].assign(Ye(t))}};Object.defineProperties(Ke.prototype,wp);var UU=function(e,t=null){let r=ol(e);return r==="node"?e:t===null&&(r==="float"||r==="boolean")||r&&r!=="shader"&&r!=="string"?Ye(gb(e,t)):r==="shader"?e.isFn?e:Q(e):e},zU=function(e,t=null){for(let r in e)e[r]=Ye(e[r],t);return e},VU=function(e,t=null){let r=e.length;for(let i=0;il?(Ce(`TSL: "${d}" parameter length exceeds limit.`,new $r),h.slice(0,l)):h}return t===null?a=(...h)=>s(new e(...wu(u(h)))):r!==null?(r=Ye(r),a=(...h)=>s(new e(t,...wu(u(h)),r))):a=(...h)=>s(new e(t,...wu(u(h)))),a.setParameterLength=(...h)=>(h.length===1?o=l=h[0]:h.length===2&&([o,l]=h),a),a.setName=h=>(n=h,a),a},GU=function(e,...t){return new e(...wu(t))},WU=class extends Ke{constructor(e,t){super(),this.shaderNode=e,this.rawInputs=t,this.isShaderCallNodeInternal=!0}generateNodeType(e){return this.shaderNode.nodeType||this.getOutputNode(e).getNodeType(e)}getElementType(e){return this.getOutputNode(e).getElementType(e)}getMemberType(e,t){return this.getOutputNode(e).getMemberType(e,t)}call(e){let{shaderNode:t,rawInputs:r}=this,i=e.getNodeProperties(t),s=e.getClosestSubBuild(t.subBuilds)||"",a=s||"default";if(i[a])return i[a];let n=e.subBuildFn,o=e.fnCall;e.subBuildFn=s,e.fnCall=this;let l=null;if(t.layout){if(r){let d=t.layout.inputs;if(QN(r)){let c=r;for(let m=0;m{let v;return Symbol.iterator===y?v=function*(){yield void 0}:v=Reflect.get(g,y,b),v}}),h=r?HU(r):null,d=Array.isArray(r)?r.length>0:r!==null,c=t.jsFunc,m=d||c.length>1?c(h,u):c(u);l=Ye(m)}return e.subBuildFn=n,e.fnCall=o,t.once&&(i[a]=l),l}setupOutput(e){return e.addStack(),e.stack.outputNode=this.call(e),e.removeStack()}getOutputNode(e){let t=e.getNodeProperties(this),r=e.getSubBuildOutput(this);return t[r]=t[r]||this.setupOutput(e),t[r].subBuild=e.getClosestSubBuild(this),t[r]}build(e,t=null){let r=null,i=e.getBuildStage(),s=e.getNodeProperties(this),a=e.getSubBuildOutput(this),n=this.getOutputNode(e),o=e.fnCall;if(e.fnCall=this,i==="setup"){let l=e.getSubBuildProperty("initialized",this);if(s[l]!==!0&&(s[l]=!0,s[a]=this.getOutputNode(e),s[a].build(e),this.shaderNode.subBuilds))for(let u of e.chaining){let h=e.getDataFromNode(u,"any");h.subBuilds=h.subBuilds||new Set;for(let d of this.shaderNode.subBuilds)h.subBuilds.add(d)}r=s[a]}else i==="analyze"?n.build(e,t):i==="generate"&&(r=n.build(e,t)||"");return e.fnCall=o,r}};function QN(e){return e[0]&&(e[0].isNode||Object.getPrototypeOf(e[0])!==Object.prototype)}function jU(e){let t;return t0(e),QN(e)?t=[...e]:t=e[0],t}function HU(e){let t=0;return t0(e),new Proxy(e,{get:(r,i,s)=>{let a;if(i==="length")return a=e.length,a;if(Symbol.iterator===i)a=function*(){for(let n of e)yield Ye(n)};else{if(e.length>0)if(Object.getPrototypeOf(e[0])===Object.prototype){let n=e[0];n[i]===void 0?a=n[t++]:a=Reflect.get(n,i,s)}else e[0]instanceof Ke&&(e[i]===void 0?a=e[t++]:a=Reflect.get(e,i,s));else a=Reflect.get(r,i,s);a=Ye(a)}return a}})}var XU=class extends Ke{constructor(e,t){super(t),this.jsFunc=e,this.layout=null,this.global=!0,this.once=!1}setLayout(e){return this.layout=e,this}getLayout(){return this.layout}call(e=null){return new WU(this,e)}setup(){return this.call()}},$U=[!1,!0],qU=[0,1,2,3],YU=[-1,-2],KN=[.5,1.5,1/3,1e-6,1e6,Math.PI,Math.PI*2,1/Math.PI,2/Math.PI,1/(Math.PI*2),Math.PI/2],pb=new Map;for(let e of $U)pb.set(e,new vn(e));var mb=new Map;for(let e of qU)mb.set(e,new vn(e,"uint"));var fb=new Map([...mb].map(e=>new vn(e.value,"int")));for(let e of YU)fb.set(e,new vn(e,"int"));var Kg=new Map([...fb].map(e=>new vn(e.value)));for(let e of KN)Kg.set(e,new vn(e));for(let e of KN)Kg.set(-e,new vn(-e));var e0={bool:pb,uint:mb,ints:fb,float:Kg},eA=new Map([...pb,...Kg]),gb=(e,t)=>eA.has(e)?eA.get(e):e.isNode===!0?e:new vn(e,t),ni=function(e,t=null){return(...r)=>{for(let s of r)if(s===void 0)return Ce(`TSL: Invalid parameter for the type "${e}".`,new $r),new vn(0,e);if((r.length===0||!["bool","float","int","uint"].includes(e)&&r.every(s=>{let a=typeof s;return a!=="object"&&a!=="function"}))&&(r=[hb(e,...r)]),r.length===1&&t!==null&&t.has(r[0]))return Mp(t.get(r[0]));if(r.length===1){let s=gb(r[0],e);return s.nodeType===e?Mp(s):Mp(new $N(s,e))}let i=r.map(s=>gb(s));return Mp(new IU(i,e))}};function vd(e){return e&&e.isNode&&e.traverse(t=>{t.isConstNode&&(e=t.value)}),!!e}var tA=e=>e!=null?e.nodeType||e.convertTo||(typeof e=="string"?e:null):null;function bd(e,t){return new XU(e,t)}var Ye=(e,t=null)=>UU(e,t),Mp=(e,t=null)=>Ye(e,t).toVarIntent(),t0=(e,t=null)=>new zU(e,t),wu=(e,t=null)=>new VU(e,t),Mt=(e,t=null,r=null,i=null)=>new JN(e,t,r,i),ze=(e,...t)=>new GU(e,...t),Ee=(e,t=null,r=null,i={})=>new JN(e,t,r,{...i,intent:!0}),yb=(e,t)=>new Proxy(e,{get(r,i,s){return Reflect.get(t,i,s)},set(r,i,s){return Reflect.set(t,i,s)}}),ZU=0,JU=class extends Ke{constructor(e,t=null){super();let r=null;t!==null&&(typeof t=="object"?r=t.return:(typeof t=="string"?r=t:Ce("TSL: Invalid layout type.",new $r),t=null)),this.shaderNode=new bd(e,r),t!==null&&this.setLayout(t),this.isFn=!0}setLayout(e){let t=this.shaderNode.nodeType;if(typeof e.inputs!="object"){let r={name:"fn"+ZU++,type:t,inputs:[]};for(let i in e)i!=="return"&&r.inputs.push({name:i,type:e[i]});e=r}return this.shaderNode.setLayout(e),this}generateNodeType(e){return this.shaderNode.getNodeType(e)||"float"}call(...e){let t=this.shaderNode.call(e);return this.shaderNode.nodeType==="void"&&t.toStack(),t.toVarIntent()}once(e=null){return this.shaderNode.once=!0,this.shaderNode.subBuilds=e,this}generate(e){let t=this.getNodeType(e);return Ce('TSL: "Fn()" was declared but not invoked. Try calling it like "Fn()( ...params )".',this.stackTrace),e.generateConst(t)}};function Q(e,t=null){let r=new JU(e,t);return new Proxy(()=>{},{apply(i,s,a){return r.call(...a)},get(i,s,a){return Reflect.get(r,s,a)},set(i,s,a,n){return Reflect.set(r,s,a,n)}})}var Np=e=>{ll=e},xb=()=>ll,et=(...e)=>ll.If(...e),QU=(...e)=>ll.Switch(...e);function r0(e){return ll&&ll.addToStack(e),e}xe("toStack",r0);var rA=new ni("color"),D=new ni("float",e0.float),Y=new ni("int",e0.ints),Ne=new ni("uint",e0.uint),Gs=new ni("bool",e0.bool),ke=new ni("vec2"),Pr=new ni("ivec2"),vb=new ni("uvec2"),iA=new ni("bvec2"),K=new ni("vec3"),bb=new ni("ivec3"),Mu=new ni("uvec3"),Tb=new ni("bvec3"),Ve=new ni("vec4"),Sb=new ni("ivec4"),_b=new ni("uvec4"),sA=new ni("bvec4"),i0=new ni("mat2"),Ni=new ni("mat3"),ul=new ni("mat4");xe("toColor",rA),xe("toFloat",D),xe("toInt",Y),xe("toUint",Ne),xe("toBool",Gs),xe("toVec2",ke),xe("toIVec2",Pr),xe("toUVec2",vb),xe("toBVec2",iA),xe("toVec3",K),xe("toIVec3",bb),xe("toUVec3",Mu),xe("toBVec3",Tb),xe("toVec4",Ve),xe("toIVec4",Sb),xe("toUVec4",_b),xe("toBVec4",sA),xe("toMat2",i0),xe("toMat3",Ni),xe("toMat4",ul);var aA=Mt(_u).setParameterLength(2),nA=(e,t)=>new $N(Ye(e),t),KU=(e,t)=>new qN(Ye(e),t);xe("element",aA),xe("convert",nA);var e6=e=>(Ue("TSL: append() has been renamed to Stack().",new $r),r0(e));xe("append",e=>(Ue("TSL: .append() has been renamed to .toStack().",new $r),r0(e)));var jt=class extends Ke{static get type(){return"PropertyNode"}constructor(e,t=null,r=!1,i=null){super(e),this.name=t,this.varying=r,this.placeholderNode=Ye(i),this.isPropertyNode=!0,this.global=!0}getNodeType(e){let t=super.getNodeType(e);return t==="output"?e.getOutputType():t}customCacheKey(){return yd(this.type+":"+(this.name||"")+":"+(this.varying?"1":"0"))}getHash(e){return this.name||super.getHash(e)}generate(e){let t;if(this.varying===!0)t=e.getVaryingFromNode(this,this.name),t.needsInterpolation=!0;else if(t=e.getVarFromNode(this,this.name),this.placeholderNode!==null&&e.hasWriteUsage(this)===!1){let r=this.placeholderNode.build(e,this.getNodeType(e));e.addLineFlowCode(`${e.getPropertyName(t)} = ${r}`,this)}return e.getPropertyName(t)}},go=(e,t,r=null)=>new jt(e,t,!1,r),Nu=(e,t,r=null)=>new jt(e,t,!0,r),Zt=ze(jt,"vec4","DiffuseColor"),Au=ze(jt,"vec3","DiffuseContribution"),wb=ze(jt,"vec3","EmissiveColor"),_n=ze(jt,"float","Roughness"),yo=ze(jt,"float","Metalness"),s0=ze(jt,"float","Clearcoat"),Td=ze(jt,"float","ClearcoatRoughness"),Ws=ze(jt,"vec3","Sheen"),hl=ze(jt,"float","SheenRoughness"),a0=ze(jt,"float","Iridescence"),n0=ze(jt,"float","IridescenceIOR"),o0=ze(jt,"float","IridescenceThickness"),l0=ze(jt,"float","AlphaT"),dl=ze(jt,"float","Anisotropy"),Ap=ze(jt,"vec3","AnisotropyT"),Cu=ze(jt,"vec3","AnisotropyB"),cl=ze(jt,"color","SpecularColor"),Ru=ze(jt,"color","SpecularColorBlended"),Eu=ze(jt,"float","SpecularF90"),u0=ze(jt,"float","Shininess"),Sd=ze(jt,"output","Output"),Pu=ze(jt,"float","dashSize"),Cp=ze(jt,"float","gapSize"),t6=ze(jt,"float","pointWidth"),Rp=ze(jt,"float","IOR"),h0=ze(jt,"float","Transmission"),Mb=ze(jt,"float","Thickness"),Nb=ze(jt,"float","AttenuationDistance"),Ab=ze(jt,"color","AttenuationColor"),Cb=ze(jt,"float","Dispersion"),Rb=ze(jt,"float","AmbientOcclusion",!1,1),oA=class extends Ke{static get type(){return"UniformGroupNode"}constructor(e,t=!1,r=1,i=null){super("string"),this.name=e,this.shared=t,this.order=r,this.updateType=i,this.isUniformGroup=!0}update(){this.needsUpdate=!0}serialize(e){super.serialize(e),e.name=this.name,e.version=this.version,e.shared=this.shared}deserialize(e){super.deserialize(e),this.name=e.name,this.version=e.version,this.shared=e.shared}},lA=(e,t=1,r=null)=>new oA(e,!1,t,r),d0=(e,t=0,r=null)=>new oA(e,!0,t,r),r6=d0("frame",0,ut.FRAME),st=d0("render",0,ut.RENDER),uA=lA("object",1,ut.OBJECT),Ep=class extends db{static get type(){return"UniformNode"}constructor(e,t=null){super(e,t),this.isUniformNode=!0,this.name="",this.groupNode=uA}setName(e){return this.name=e,this}label(e){return Ue('TSL: "label()" has been deprecated. Use "setName()" instead.',new $r),this.setName(e)}setGroup(e){return this.groupNode=e,this}getGroup(){return this.groupNode}getUniformHash(e){return this.getHash(e)}onUpdate(e,t){return e=e.bind(this),super.onUpdate(r=>{let i=e(r,this);i!==void 0&&(this.value=i)},t)}getInputType(e){let t=super.getInputType(e);return t==="bool"&&(t="uint"),t}generate(e,t){let r=this.getNodeType(e),i=this.getUniformHash(e),s=e.getNodeFromHash(i);s===void 0&&(e.setHashNode(this,i),s=this);let a=s.getInputType(e),n=e.getUniformFromNode(s,a,e.shaderStage,this.name||e.context.nodeName),o=e.getPropertyName(n);e.context.nodeName!==void 0&&delete e.context.nodeName;let l=o;if(r==="bool"){let u=e.getDataFromNode(this),h=u.propertyName;if(h===void 0){let d=e.getVarFromNode(this,null,"bool");h=e.getPropertyName(d),u.propertyName=h,l=e.format(o,a,r),e.addLineFlowCode(`${h} = ${l}`,this)}l=h}return e.format(l,r,t)}},Qe=(e,t)=>{let r=tA(t||e);if(r===e&&(e=hb(r)),e&&e.isNode===!0){let i=e.value;e.traverse(s=>{s.isConstNode===!0&&(i=s.value)}),e=i}return new Ep(e,r)},hA=class extends rr{static get type(){return"ArrayNode"}constructor(e,t,r=null){super(e),this.count=t,this.values=r,this.isArrayNode=!0}getArrayCount(){return this.count}generateNodeType(e){return this.nodeType===null?this.values[0].getNodeType(e):this.nodeType}getElementType(e){return this.getNodeType(e)}getMemberType(e,t){return this.nodeType===null?this.values[0].getMemberType(e,t):super.getMemberType(e,t)}generate(e){let t=this.getNodeType(e);return e.generateArray(t,this.count,this.values)}},dA=(...e)=>{let t;if(e.length===1){let r=e[0];t=new hA(null,r.length,r)}else{let r=e[0],i=e[1];t=new hA(r,i)}return Ye(t)};xe("toArray",(e,t)=>dA(Array(t).fill(e)));var i6=class extends rr{static get type(){return"AssignNode"}constructor(e,t){super(),this.targetNode=e,this.sourceNode=t,this.isAssignNode=!0}hasDependencies(){return!1}generateNodeType(e,t){return t!=="void"?this.targetNode.getNodeType(e):"void"}needsSplitAssign(e){let{targetNode:t}=this;if(e.isAvailable("swizzleAssign")===!1&&t.isSplitNode&&t.components.length>1){let r=e.getTypeLength(t.node.getNodeType(e));return Su.join("").slice(0,r)!==t.components}return!1}setup(e){let{targetNode:t,sourceNode:r}=this,i=t.getScope(),s=e.getDataFromNode(i);s.assign=!0;let a=e.getNodeProperties(this);a.sourceNode=r,a.targetNode=t.context({assign:!0})}generate(e,t){let{targetNode:r,sourceNode:i}=e.getNodeProperties(this),s=this.needsSplitAssign(e),a=r.build(e),n=r.getNodeType(e),o=i.build(e,n),l=i.getNodeType(e),u=e.getDataFromNode(this),h;if(u.initialized===!0)t!=="void"&&(h=a);else if(s){let d=e.getVarFromNode(this,null,n),c=e.getPropertyName(d);e.addLineFlowCode(`${c} = ${o}`,this);let m=r.node,g=m.node.context({assign:!0}).build(e);for(let y=0;y{let l=o.type,u=l==="pointer",h;return u?h="&"+n.build(e):h=n.build(e,l),h};if(Array.isArray(s)){if(s.length>i.length)Ce("TSL: The number of provided parameters exceeds the expected number of inputs in 'Fn()'."),s.length=i.length;else if(s.length(t=t.length>1||t[0]&&t[0].isNode===!0?wu(t):t0(t[0]),new s6(Ye(e),t));xe("call",pA);var a6={"==":"equal","!=":"notEqual","<":"lessThan",">":"greaterThan","<=":"lessThanEqual",">=":"greaterThanEqual","%":"mod"},qr=class lM extends rr{static get type(){return"OperatorNode"}constructor(t,r,i,...s){if(super(),s.length>0){let a=new lM(t,r,i);for(let n=0;n>"||i==="<<")return t.getIntegerType(n);if(i==="&&"||i==="||"||i==="^^")return"bool";if(i==="!"){let l=t.getTypeLength(n);return l>1?`bvec${l}`:"bool"}else if(i==="=="||i==="!="||i==="<"||i===">"||i==="<="||i===">="){let l=Math.max(t.getTypeLength(n),t.getTypeLength(o));return l>1?`bvec${l}`:"bool"}else{if(t.isMatrix(n)){if(o==="float")return n;if(t.isVector(o))return t.getVectorFromMatrix(n);if(t.isMatrix(o))return n}else if(t.isMatrix(o)){if(n==="float")return o;if(t.isVector(n))return t.getVectorFromMatrix(o)}return t.getTypeLength(o)>t.getTypeLength(n)?o:n}}generate(t,r){let i=this.op,{aNode:s,bNode:a}=this,n=this.getNodeType(t,r),o=null,l=null;n!=="void"?(o=s.getNodeType(t),l=a?a.getNodeType(t):null,i==="<"||i===">"||i==="<="||i===">="||i==="=="||i==="!="?t.isVector(o)?l=o:t.isVector(l)?o=l:o!==l&&(o=l="float"):i===">>"||i==="<<"?(o=n,l=t.changeComponentType(l,"uint")):i==="%"?(o=n,l=t.isInteger(o)&&t.isInteger(l)?l:o):t.isMatrix(o)?l==="float"?l="float":t.isVector(l)?l=t.getVectorFromMatrix(o):t.isMatrix(l)||(o=l=n):t.isMatrix(l)?o==="float"?o="float":t.isVector(o)?o=t.getVectorFromMatrix(l):o=l=n:o=l=n):o=l=n;let u=s.build(t,o),h=a?a.build(t,l):null,d=t.getFunctionOperator(i);if(r!=="void"){let c=t.renderer.coordinateSystem===Ds;if(i==="=="||i==="!="||i==="<"||i===">"||i==="<="||i===">=")return c?t.isVector(o)?t.format(`${this.getOperatorMethod(t,r)}( ${u}, ${h} )`,n,r):t.format(`( ${u} ${i} ${h} )`,n,r):t.format(`( ${u} ${i} ${h} )`,n,r);if(i==="%")return t.isInteger(l)?t.format(`( ${u} % ${h} )`,n,r):t.format(`${this.getOperatorMethod(t,n)}( ${u}, ${h} )`,n,r);if(i==="!")return c&&t.isVector(o)?t.format(`not( ${u} )`,r):t.format(`( ${i} ${u} )`,o,r);if(i==="~")return t.format(`( ${i} ${u} )`,o,r);if(d)return t.format(`${d}( ${u}, ${h} )`,n,r);if(t.isMatrix(o)&&l==="float")return t.format(`( ${h} ${i} ${u} )`,n,r);if(o==="float"&&t.isMatrix(l))return t.format(`${u} ${i} ${h}`,n,r);{let m=`( ${u} ${i} ${h} )`;return!c&&n==="bool"&&t.isVector(o)&&t.isVector(l)&&(m=`all${m}`),t.format(m,n,r)}}else if(o!=="void")return d?t.format(`${d}( ${u}, ${h} )`,n,r):t.isMatrix(o)&&l==="float"?t.format(`${h} ${i} ${u}`,n,r):t.format(`${u} ${i} ${h}`,n,r)}serialize(t){super.serialize(t),t.op=this.op}deserialize(t){super.deserialize(t),this.op=t.op}},Yr=Ee(qr,"+").setParameterLength(2,1/0).setName("add"),It=Ee(qr,"-").setParameterLength(2,1/0).setName("sub"),mt=Ee(qr,"*").setParameterLength(2,1/0).setName("mul"),js=Ee(qr,"/").setParameterLength(2,1/0).setName("div"),c0=Ee(qr,"%").setParameterLength(2).setName("mod"),mA=Ee(qr,"==").setParameterLength(2).setName("equal"),fA=Ee(qr,"!=").setParameterLength(2).setName("notEqual"),gA=Ee(qr,"<").setParameterLength(2).setName("lessThan"),Eb=Ee(qr,">").setParameterLength(2).setName("greaterThan"),yA=Ee(qr,"<=").setParameterLength(2).setName("lessThanEqual"),xA=Ee(qr,">=").setParameterLength(2).setName("greaterThanEqual"),vA=Ee(qr,"&&").setParameterLength(2,1/0).setName("and"),bA=Ee(qr,"||").setParameterLength(2,1/0).setName("or"),TA=Ee(qr,"!").setParameterLength(1).setName("not"),SA=Ee(qr,"^^").setParameterLength(2).setName("xor"),_A=Ee(qr,"&").setParameterLength(2).setName("bitAnd"),wA=Ee(qr,"~").setParameterLength(1).setName("bitNot"),MA=Ee(qr,"|").setParameterLength(2).setName("bitOr"),NA=Ee(qr,"^").setParameterLength(2).setName("bitXor"),AA=Ee(qr,"<<").setParameterLength(2).setName("shiftLeft"),CA=Ee(qr,">>").setParameterLength(2).setName("shiftRight"),RA=Q(([e])=>(e.addAssign(1),e)),EA=Q(([e])=>(e.subAssign(1),e)),PA=Q(([e])=>{let t=Y(e).toConst();return e.addAssign(1),t}),BA=Q(([e])=>{let t=Y(e).toConst();return e.subAssign(1),t});xe("add",Yr),xe("sub",It),xe("mul",mt),xe("div",js),xe("mod",c0),xe("equal",mA),xe("notEqual",fA),xe("lessThan",gA),xe("greaterThan",Eb),xe("lessThanEqual",yA),xe("greaterThanEqual",xA),xe("and",vA),xe("or",bA),xe("not",TA),xe("xor",SA),xe("bitAnd",_A),xe("bitNot",wA),xe("bitOr",MA),xe("bitXor",NA),xe("shiftLeft",AA),xe("shiftRight",CA),xe("incrementBefore",RA),xe("decrementBefore",EA),xe("increment",PA),xe("decrement",BA);var he=class Sr extends rr{static get type(){return"MathNode"}constructor(t,r,i=null,s=null){if(super(),(t===Sr.MAX||t===Sr.MIN)&&arguments.length>3){let a=new Sr(t,r,i);for(let n=3;nn&&a>o?r:n>o?i:o>a?s:r}generateNodeType(t){let r=this.method;return r===Sr.LENGTH||r===Sr.DISTANCE||r===Sr.DOT?"float":r===Sr.CROSS?"vec3":r===Sr.ALL||r===Sr.ANY?"bool":r===Sr.EQUALS?t.changeComponentType(this.aNode.getNodeType(t),"bool"):this.getInputType(t)}setup(t){let{aNode:r,bNode:i,method:s}=this,a=null;if(s===Sr.ONE_MINUS)a=It(1,r);else if(s===Sr.RECIPROCAL)a=js(1,r);else if(s===Sr.DIFFERENCE)a=ur(It(r,i));else if(s===Sr.TRANSFORM_DIRECTION){let n,o;t.isMatrix(r.getNodeType(t))?(n=r,o=i):(n=i,o=r),a=Yi(mt(n,Ve(K(o),0)).xyz)}return a!==null?a:super.setup(t)}generate(t,r){if(t.getNodeProperties(this).outputNode)return super.generate(t,r);let i=this.method,s=this.getNodeType(t),a=this.getInputType(t),n=this.aNode,o=this.bNode,l=this.cNode,u=t.renderer.coordinateSystem;if(i===Sr.NEGATE)return t.format("( - "+n.build(t,a)+" )",s,r);{let h=[];return i===Sr.CROSS?h.push(n.build(t,s),o.build(t,s)):u===Ds&&i===Sr.STEP?h.push(n.build(t,t.getTypeLength(n.getNodeType(t))===1?"float":a),o.build(t,a)):u===Ds&&(i===Sr.MIN||i===Sr.MAX)?h.push(n.build(t,a),o.build(t,t.getTypeLength(o.getNodeType(t))===1?"float":a)):i===Sr.REFRACT?h.push(n.build(t,a),o.build(t,a),l.build(t,"float")):i===Sr.MIX?h.push(n.build(t,a),o.build(t,a),l.build(t,t.getTypeLength(l.getNodeType(t))===1?"float":a)):(u===da&&i===Sr.ATAN&&o!==null&&(i="atan2"),t.shaderStage!=="fragment"&&(i===Sr.DFDX||i===Sr.DFDY)&&(Ue(`TSL: '${i}' is not supported in the ${t.shaderStage} stage.`,this.stackTrace),i="/*"+i+"*/"),h.push(n.build(t,a)),o!==null&&h.push(o.build(t,a)),l!==null&&h.push(l.build(t,a))),t.format(`${t.getMethod(i,s)}( ${h.join(", ")} )`,s,r)}}serialize(t){super.serialize(t),t.method=this.method}deserialize(t){super.deserialize(t),this.method=t.method}};he.ALL="all",he.ANY="any",he.RADIANS="radians",he.DEGREES="degrees",he.EXP="exp",he.EXP2="exp2",he.LOG="log",he.LOG2="log2",he.SQRT="sqrt",he.INVERSE_SQRT="inversesqrt",he.FLOOR="floor",he.CEIL="ceil",he.NORMALIZE="normalize",he.FRACT="fract",he.SIN="sin",he.SINH="sinh",he.COS="cos",he.COSH="cosh",he.TAN="tan",he.TANH="tanh",he.ASIN="asin",he.ASINH="asinh",he.ACOS="acos",he.ACOSH="acosh",he.ATAN="atan",he.ATANH="atanh",he.ABS="abs",he.SIGN="sign",he.LENGTH="length",he.NEGATE="negate",he.ONE_MINUS="oneMinus",he.DFDX="dFdx",he.DFDY="dFdy",he.ROUND="round",he.RECIPROCAL="reciprocal",he.TRUNC="trunc",he.FWIDTH="fwidth",he.TRANSPOSE="transpose",he.DETERMINANT="determinant",he.INVERSE="inverse",he.EQUALS="equals",he.MIN="min",he.MAX="max",he.STEP="step",he.REFLECT="reflect",he.DISTANCE="distance",he.DIFFERENCE="difference",he.DOT="dot",he.CROSS="cross",he.POW="pow",he.TRANSFORM_DIRECTION="transformDirection",he.MIX="mix",he.CLAMP="clamp",he.REFRACT="refract",he.SMOOTHSTEP="smoothstep",he.FACEFORWARD="faceforward";var p0=D(1e-6),n6=D(1e6),m0=D(Math.PI),o6=D(Math.PI*2),l6=D(Math.PI*2),u6=D(Math.PI*.5),IA=Ee(he,he.ALL).setParameterLength(1),FA=Ee(he,he.ANY).setParameterLength(1),LA=Ee(he,he.RADIANS).setParameterLength(1),kA=Ee(he,he.DEGREES).setParameterLength(1),Pb=Ee(he,he.EXP).setParameterLength(1),_d=Ee(he,he.EXP2).setParameterLength(1),f0=Ee(he,he.LOG).setParameterLength(1),wn=Ee(he,he.LOG2).setParameterLength(1),ys=Ee(he,he.SQRT).setParameterLength(1),Bb=Ee(he,he.INVERSE_SQRT).setParameterLength(1),Mn=Ee(he,he.FLOOR).setParameterLength(1),g0=Ee(he,he.CEIL).setParameterLength(1),Yi=Ee(he,he.NORMALIZE).setParameterLength(1),Oa=Ee(he,he.FRACT).setParameterLength(1),xs=Ee(he,he.SIN).setParameterLength(1),DA=Ee(he,he.SINH).setParameterLength(1),Ua=Ee(he,he.COS).setParameterLength(1),OA=Ee(he,he.COSH).setParameterLength(1),UA=Ee(he,he.TAN).setParameterLength(1),zA=Ee(he,he.TANH).setParameterLength(1),VA=Ee(he,he.ASIN).setParameterLength(1),GA=Ee(he,he.ASINH).setParameterLength(1),Ib=Ee(he,he.ACOS).setParameterLength(1),WA=Ee(he,he.ACOSH).setParameterLength(1),Fb=Ee(he,he.ATAN).setParameterLength(1,2),jA=Ee(he,he.ATANH).setParameterLength(1),ur=Ee(he,he.ABS).setParameterLength(1),Lb=Ee(he,he.SIGN).setParameterLength(1),Nn=Ee(he,he.LENGTH).setParameterLength(1),kb=Ee(he,he.NEGATE).setParameterLength(1),HA=Ee(he,he.ONE_MINUS).setParameterLength(1),Db=Ee(he,he.DFDX).setParameterLength(1),Ob=Ee(he,he.DFDY).setParameterLength(1),XA=Ee(he,he.ROUND).setParameterLength(1),$A=Ee(he,he.RECIPROCAL).setParameterLength(1),Ub=Ee(he,he.TRUNC).setParameterLength(1),zb=Ee(he,he.FWIDTH).setParameterLength(1),qA=Ee(he,he.TRANSPOSE).setParameterLength(1),YA=Ee(he,he.DETERMINANT).setParameterLength(1),ZA=Ee(he,he.INVERSE).setParameterLength(1),Rs=Ee(he,he.MIN).setParameterLength(2,1/0),Br=Ee(he,he.MAX).setParameterLength(2,1/0),Bu=Ee(he,he.STEP).setParameterLength(2),JA=Ee(he,he.REFLECT).setParameterLength(2),QA=Ee(he,he.DISTANCE).setParameterLength(2),KA=Ee(he,he.DIFFERENCE).setParameterLength(2),pa=Ee(he,he.DOT).setParameterLength(2),xo=Ee(he,he.CROSS).setParameterLength(2),ma=Ee(he,he.POW).setParameterLength(2),Vb=e=>mt(e,e),eC=e=>mt(e,e,e),Gb=e=>mt(e,e,e,e),tC=Ee(he,he.TRANSFORM_DIRECTION).setParameterLength(2),rC=(e,t)=>Yi(mt(t,Ve(K(e),0)).xyz),iC=(e,t)=>Yi(Ve(K(e),0).mul(t).xyz),sC=e=>mt(Lb(e),ma(ur(e),1/3)),Wb=e=>pa(e,e),Ct=Ee(he,he.MIX).setParameterLength(3),za=(e,t=0,r=1)=>new he(he.CLAMP,Ye(e),Ye(t),Ye(r)),y0=e=>za(e),jb=Ee(he,he.REFRACT).setParameterLength(3),Hs=Ee(he,he.SMOOTHSTEP).setParameterLength(3),Hb=Ee(he,he.FACEFORWARD).setParameterLength(3),aC=Q(([e])=>{let t=43758.5453,r=pa(e.xy,ke(12.9898,78.233)),i=c0(r,m0);return Oa(xs(i).mul(t))}),nC=(e,t,r)=>Ct(t,r,e),oC=(e,t,r)=>Hs(t,r,e),lC=(e,t)=>Bu(t,e),h6=Hb,d6=Bb;xe("all",IA),xe("any",FA),xe("radians",LA),xe("degrees",kA),xe("exp",Pb),xe("exp2",_d),xe("log",f0),xe("log2",wn),xe("sqrt",ys),xe("inverseSqrt",Bb),xe("floor",Mn),xe("ceil",g0),xe("normalize",Yi),xe("fract",Oa),xe("sin",xs),xe("sinh",DA),xe("cos",Ua),xe("cosh",OA),xe("tan",UA),xe("tanh",zA),xe("asin",VA),xe("asinh",GA),xe("acos",Ib),xe("acosh",WA),xe("atan",Fb),xe("atanh",jA),xe("abs",ur),xe("sign",Lb),xe("length",Nn),xe("lengthSq",Wb),xe("negate",kb),xe("oneMinus",HA),xe("dFdx",Db),xe("dFdy",Ob),xe("round",XA),xe("reciprocal",$A),xe("trunc",Ub),xe("fwidth",zb),xe("min",Rs),xe("max",Br),xe("step",lC),xe("reflect",JA),xe("distance",QA),xe("dot",pa),xe("cross",xo),xe("pow",ma),xe("pow2",Vb),xe("pow3",eC),xe("pow4",Gb),xe("transformDirection",tC),xe("transformNormalByViewMatrix",rC),xe("transformNormalByInverseViewMatrix",iC),xe("mix",nC),xe("clamp",za),xe("refract",jb),xe("smoothstep",oC),xe("faceForward",Hb),xe("difference",KA),xe("saturate",y0),xe("cbrt",sC),xe("transpose",qA),xe("determinant",YA),xe("inverse",ZA),xe("rand",aC);var c6=class extends Ke{static get type(){return"ConditionalNode"}constructor(e,t,r=null){super(),this.condNode=e,this.ifNode=t,this.elseNode=r}generateNodeType(e){let{ifNode:t,elseNode:r}=e.getNodeProperties(this);if(t===void 0)return e.flowBuildStage(this,"setup"),this.getNodeType(e);let i=t.getNodeType(e);if(r!==null){let s=r.getNodeType(e);if(e.getTypeLength(s)>e.getTypeLength(i))return s}return i}setup(e){let t=this.condNode,r=this.ifNode.isolate(),i=this.elseNode?this.elseNode.isolate():null,s=e.context.nodeBlock;e.getDataFromNode(r).parentNodeBlock=s,i!==null&&(e.getDataFromNode(i).parentNodeBlock=s);let a=e.context.uniformFlow,n=e.getNodeProperties(this);n.condNode=t,n.ifNode=a?r:r.context({nodeBlock:r}),n.elseNode=i?a?i:i.context({nodeBlock:i}):null}generate(e,t){let r=this.getNodeType(e),i=e.getDataFromNode(this);if(i.nodeProperty!==void 0)return i.nodeProperty;let{condNode:s,ifNode:a,elseNode:n}=e.getNodeProperties(this),o=e.currentFunctionNode,l=t!=="void",u=l?go(r).build(e):"";i.nodeProperty=u;let h=s.build(e,"bool");if(e.context.uniformFlow&&n!==null){let c=a.build(e,r),m=n.build(e,r),g=e.getTernary(h,c,m);return e.format(g,r,t)}e.addFlowCode(` ${e.tab}if ( ${h} ) { `).addFlowTab();let d=a.build(e,r);if(d&&(l?d=u+" = "+d+";":(d="return "+d+";",o===null&&(Ue("TSL: Return statement used in an inline 'Fn()'. Define a layout struct to allow return values.",this.stackTrace),d="// "+d))),e.removeFlowTab().addFlowCode(e.tab+" "+d+` `+e.tab+"}"),n!==null){e.addFlowCode(` else { `).addFlowTab();let c=n.build(e,r);c&&(l?c=u+" = "+c+";":(c="return "+c+";",o===null&&(Ue("TSL: Return statement used in an inline 'Fn()'. Define a layout struct to allow return values.",this.stackTrace),c="// "+c))),e.removeFlowTab().addFlowCode(e.tab+" "+c+` `+e.tab+`} `)}else e.addFlowCode(` `);return e.format(u,r,t)}},Zi=Mt(c6).setParameterLength(2,3);xe("select",Zi);var Xb=class extends Ke{static get type(){return"ContextNode"}constructor(e=null,t={}){super(),this.isContextNode=!0,this.node=e,this.value=t}getScope(){return this.node.getScope()}generateNodeType(e){return this.node.getNodeType(e)}getFlowContextData(){let e=[];return this.traverse(t=>{t.isContextNode===!0&&e.push(t.value)}),Object.assign({},...e)}getMemberType(e,t){return this.node.getMemberType(e,t)}analyze(e){let t=e.addContext(this.value);this.node.build(e),e.setContext(t)}setup(e){let t=e.addContext(this.value);this.node.build(e),e.setContext(t)}generate(e,t){let r=e.addContext(this.value),i=this.node.build(e,t);return e.setContext(r),i}},vo=(e=null,t={})=>{let r=e;return(r===null||r.isNode!==!0)&&(t=r||t,r=null),new Xb(r,t)},uC=e=>vo(e,{uniformFlow:!0}),$b=(e,t)=>vo(e,{nodeName:t});function hC(e,t,r=null){return vo(r,{getShadow:({light:i,shadowColorNode:s})=>t===i?s.mul(e):s})}function dC(e,t=null){return vo(t,{getAO:(r,{material:i})=>i.transparent===!0?r:r!==null?r.mul(e):e})}function cC(e,t){return Ue('TSL: "label()" has been deprecated. Use "setName()" instead.'),$b(e,t)}xe("context",vo),xe("label",cC),xe("uniformFlow",uC),xe("setName",$b),xe("builtinShadowContext",(e,t,r)=>hC(t,r,e)),xe("builtinAOContext",(e,t)=>dC(t,e));var x0=class extends Ke{static get type(){return"VarNode"}constructor(e,t=null,r=!1){super(),this.node=e,this.name=t,this.global=!0,this.isVarNode=!0,this.readOnly=r,this.parents=!0,this.intent=!1}setIntent(e){return this.intent=e,this}isIntent(e){return e.getDataFromNode(this).forceDeclaration===!0?!1:this.intent}getIntent(){return this.intent}getMemberType(e,t){return this.node.getMemberType(e,t)}getElementType(e){return this.node.getElementType(e)}generateNodeType(e){return this.node.getNodeType(e)}getArrayCount(e){return this.node.getArrayCount(e)}isAssign(e){return e.getDataFromNode(this).assign}build(...e){let t=e[0],r=this.getShared(t);if(this!==r)return r.build(...e);if(this._hasStack(t)===!1&&t.buildStage==="setup"&&(t.context.nodeLoop||t.context.nodeBlock)){let i=!1;if(this.node.isShaderCallNodeInternal&&this.node.shaderNode.getLayout()===null&&t.fnCall&&t.fnCall.shaderNode&&t.getDataFromNode(this.node.shaderNode).hasLoop){let a=t.getDataFromNode(this);a.forceDeclaration=!0,i=!0}let s=t.getBaseStack();i?s.addToStackBefore(this):s.addToStack(this)}return this.isIntent(t)&&this.isAssign(t)!==!0?this.node.build(...e):super.build(...e)}generate(e){let{node:t,name:r,readOnly:i}=this,{renderer:s}=e,a=s.backend.isWebGPUBackend===!0,n=!1,o=!1;i&&(n=e.isDeterministic(t),o=a?i:n);let l=this.getNodeType(e);if(l=="void")return this.isIntent(e)!==!0&&Ce('TSL: ".toVar()" can not be used with void type.',this.stackTrace),t.build(e);let u=e.getVectorType(l),h=t.build(e,u),d=e.getVarFromNode(this,r,u,void 0,o),c=e.getPropertyName(d),m=c;if(o)if(a)m=n?`const ${c}`:`let ${c}`;else{let g=t.getArrayCount(e);m=`const ${e.getVar(d.type,c,g)}`}return e.addLineFlowCode(`${m} = ${h}`,this),c}_hasStack(e){return e.getDataFromNode(this).stack!==void 0}},qb=Mt(x0),pC=(e,t=null)=>qb(e,t).toStack(),mC=(e,t=null)=>qb(e,t,!0).toStack(),fC=e=>qb(e).setIntent(!0).toStack();xe("toVar",pC),xe("toConst",mC),xe("toVarIntent",fC);var p6=class extends Ke{static get type(){return"SubBuild"}constructor(e,t,r=null){super(r),this.node=e,this.name=t,this.isSubBuildNode=!0}generateNodeType(e){if(this.nodeType!==null)return this.nodeType;e.addSubBuild(this.name);let t=this.node.getNodeType(e);return e.removeSubBuild(),t}build(e,...t){e.addSubBuild(this.name);let r=this.node.build(e,...t);return e.removeSubBuild(),r}},Iu=(e,t,r=null)=>new p6(Ye(e),t,r),m6=class extends Ke{static get type(){return"VaryingNode"}constructor(e,t=null){super(),this.node=Iu(e,"VERTEX"),this.name=t,this.isVaryingNode=!0,this.interpolationType=null,this.interpolationSampling=null,this.global=!0}setInterpolation(e,t=null){return this.interpolationType=e,this.interpolationSampling=t,this}getHash(e){return this.name||super.getHash(e)}generateNodeType(e){return this.node.getNodeType(e)}setupVarying(e){let t=e.getNodeProperties(this),r=t.varying;if(r===void 0){let i=this.name,s=this.getNodeType(e),a=this.interpolationType,n=this.interpolationSampling;t.varying=r=e.getVaryingFromNode(this,i,s,a,n),t.node=Iu(this.node,"VERTEX")}return r.needsInterpolation||(r.needsInterpolation=e.shaderStage==="fragment"),r}setup(e){this.setupVarying(e),e.flowNodeFromShaderStage(xd.VERTEX,this.node)}analyze(e){this.setupVarying(e),e.flowNodeFromShaderStage(xd.VERTEX,this.node)}generate(e){let t=e.getSubBuildProperty("property",e.currentStack),r=e.getNodeProperties(this),i=this.setupVarying(e);if(r[t]===void 0){let s=this.getNodeType(e),a=e.getPropertyName(i,xd.VERTEX);if(e.shaderStage===xd.VERTEX){let n=r.node.build(e,s);e.addLineFlowCode(`${a} = ${n}`,this)}else e.flowNodeFromShaderStage(xd.VERTEX,r.node,s,a);r[t]=a}return e.getPropertyName(i)}},pl=Mt(m6).setParameterLength(1,2),gC=e=>pl(e);xe("toVarying",pl),xe("toVertexStage",gC);var yC=Q(([e])=>{let t=e.mul(.9478672986).add(.0521327014).pow(2.4),r=e.mul(.0773993808),i=e.lessThanEqual(.04045);return Ct(t,r,i)}).setLayout({name:"sRGBTransferEOTF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),xC=Q(([e])=>{let t=e.pow(.41666).mul(1.055).sub(.055),r=e.mul(12.92),i=e.lessThanEqual(.0031308);return Ct(t,r,i)}).setLayout({name:"sRGBTransferOETF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),Yb="WorkingColorSpace",f6="OutputColorSpace",Zb=class extends rr{static get type(){return"ColorSpaceNode"}constructor(e,t,r){super("vec4"),this.colorNode=e,this.source=t,this.target=r}resolveColorSpace(e,t){return t===Yb?Gt.workingColorSpace:t===f6?e.context.outputColorSpace||e.renderer.outputColorSpace:t}setup(e){let{colorNode:t}=this,r=this.resolveColorSpace(e,this.source),i=this.resolveColorSpace(e,this.target),s=t;return Gt.enabled===!1||r===i||!r||!i||(Gt.getTransfer(r)===Tt&&(s=Ve(yC(s.rgb),s.a)),Gt.getPrimaries(r)!==Gt.getPrimaries(i)&&(s=Ve(Ni(Gt._getMatrix(new Dr,r,i)).mul(s.rgb),s.a)),Gt.getTransfer(i)===Tt&&(s=Ve(xC(s.rgb),s.a))),s}},vC=(e,t)=>new Zb(Ye(e),Yb,t),v0=(e,t)=>new Zb(Ye(e),t,Yb),g6=(e,t,r)=>new Zb(Ye(e),t,r);xe("workingToColorSpace",vC),xe("colorSpaceToWorking",v0);var y6=class extends _u{static get type(){return"ReferenceElementNode"}constructor(e,t){super(e,t),this.referenceNode=e,this.isReferenceElementNode=!0}generateNodeType(){return this.referenceNode.uniformType}generate(e){let t=super.generate(e),r=this.referenceNode.getNodeType(),i=this.getNodeType();return e.format(t,r,i)}},bC=class extends Ke{static get type(){return"ReferenceBaseNode"}constructor(e,t,r=null,i=null){super(),this.property=e,this.uniformType=t,this.object=r,this.count=i,this.properties=e.split("."),this.reference=r,this.node=null,this.group=null,this.updateType=ut.OBJECT}setGroup(e){return this.group=e,this}element(e){return new y6(this,Ye(e))}setNodeType(e){let t=Qe(null,e);this.group!==null&&t.setGroup(this.group),this.node=t}generateNodeType(e){return this.node===null&&(this.updateReference(e),this.updateValue()),this.node.getNodeType(e)}getValueFromReference(e=this.reference){let{properties:t}=this,r=e[t[0]];for(let i=1;inew bC(e,t,r),v6=class extends bC{static get type(){return"RendererReferenceNode"}constructor(e,t,r=null){super(e,t,r),this.renderer=r,this.setGroup(st)}updateReference(e){return this.reference=this.renderer!==null?this.renderer:e.renderer,this.reference}},TC=(e,t,r=null)=>new v6(e,t,r),b6=class extends rr{static get type(){return"ToneMappingNode"}constructor(e,t=_C,r=null){super("vec3"),this._toneMapping=e,this.exposureNode=t,this.colorNode=r}customCacheKey(){return _p(this._toneMapping)}setToneMapping(e){return this._toneMapping=e,this}getToneMapping(){return this._toneMapping}setup(e){let t=this.colorNode||e.context.color,r=this._toneMapping;if(r===eo)return t;let i=null,s=e.renderer.library.getToneMappingFunction(r);return s!==null?i=Ve(s(t.rgb,this.exposureNode),t.a):(Ce("ToneMappingNode: Unsupported Tone Mapping configuration.",r),i=t),i}},SC=(e,t,r)=>new b6(e,Ye(t),Ye(r)),_C=TC("toneMappingExposure","float");xe("toneMapping",(e,t,r)=>SC(t,r,e));var wC=new WeakMap;function MC(e,t){let r=wC.get(e);return r===void 0&&(r=new aN(e,t),wC.set(e,r)),r}var ml=class extends db{static get type(){return"BufferAttributeNode"}constructor(e,t=null,r=0,i=0){super(e,t),this.isBufferNode=!0,this.bufferType=t,this.bufferStride=r,this.bufferOffset=i,this.usage=qh,this.instanced=!1,this.attribute=null,this.global=!0,e&&e.isBufferAttribute===!0&&e.itemSize<=4&&(this.attribute=e,this.usage=e.usage,this.instanced=e.isInstancedBufferAttribute)}getHash(e){let t;if(this.bufferStride===0&&this.bufferOffset===0){let r=e.globalCache.getData(this.value);r===void 0&&(r={node:this},e.globalCache.setData(this.value,r)),t=r.node.id}else t=this.id;return String(t)}generateNodeType(e){return this.bufferType===null&&(this.bufferType=e.getTypeFromAttribute(this.attribute)),this.bufferType}setup(e){if(this.attribute!==null)return;let t=this.getNodeType(e),r=e.getTypeLength(t),i=this.value,s=this.bufferStride||r,a=this.bufferOffset,n;i.isInterleavedBuffer===!0?n=i:i.isBufferAttribute===!0?n=MC(i.array,s):n=MC(i,s);let o=new L4(n,r,a);n.setUsage(this.usage),this.attribute=o,this.attribute.isInstancedBufferAttribute=this.instanced}generate(e){let t=this.getNodeType(e),r=e.context.nodeName;r!==void 0&&delete e.context.nodeName;let i=e.getBufferAttributeFromNode(this,t,r),s=e.getPropertyName(i),a=null;if(e.shaderStage==="vertex"||e.shaderStage==="compute")this.name=s,a=s;else{let n;r&&(n=r+"Varying"),a=pl(this,n).build(e,t)}return a}getInputType(){return"bufferAttribute"}setUsage(e){return this.usage=e,this.attribute&&this.attribute.isBufferAttribute===!0&&(this.attribute.usage=e),this}setInstanced(e){return this.instanced=e,this}};function b0(e,t=null,r=0,i=0,s=qh,a=!1){return t==="mat3"||t===null&&e.itemSize===9?Ni(new ml(e,"vec3",9,0).setUsage(s).setInstanced(a),new ml(e,"vec3",9,3).setUsage(s).setInstanced(a),new ml(e,"vec3",9,6).setUsage(s).setInstanced(a)):t==="mat4"||t===null&&e.itemSize===16?ul(new ml(e,"vec4",16,0).setUsage(s).setInstanced(a),new ml(e,"vec4",16,4).setUsage(s).setInstanced(a),new ml(e,"vec4",16,8).setUsage(s).setInstanced(a),new ml(e,"vec4",16,12).setUsage(s).setInstanced(a)):new ml(e,t,r,i).setUsage(s)}var Jb=(e,t=null,r=0,i=0)=>b0(e,t,r,i),T6=(e,t=null,r=0,i=0)=>b0(e,t,r,i,rp),T0=(e,t=null,r=0,i=0)=>b0(e,t,r,i,qh,!0),Qb=(e,t=null,r=0,i=0)=>b0(e,t,r,i,rp,!0);xe("toAttribute",e=>Jb(e.value));var Ai=class Ih extends Ke{static get type(){return"IndexNode"}constructor(t){super("uint"),this.scope=t,this.isIndexNode=!0}generate(t){let r=this.getNodeType(t),i=this.scope,s;if(i===Ih.VERTEX)s=t.getVertexIndex();else if(i===Ih.INSTANCE)s=t.getInstanceIndex();else if(i===Ih.DRAW)s=t.getDrawIndex();else if(i===Ih.INVOCATION_LOCAL)s=t.getInvocationLocalIndex();else if(i===Ih.INVOCATION_SUBGROUP)s=t.getInvocationSubgroupIndex();else if(i===Ih.SUBGROUP)s=t.getSubgroupIndex();else throw new Error("THREE.IndexNode: Unknown scope: "+i);let a;return t.shaderStage==="vertex"||t.shaderStage==="compute"?a=s:a=pl(this).build(t,r),a}};Ai.VERTEX="vertex",Ai.INSTANCE="instance",Ai.SUBGROUP="subgroup",Ai.INVOCATION_LOCAL="invocationLocal",Ai.INVOCATION_SUBGROUP="invocationSubgroup",Ai.DRAW="draw";var NC=ze(Ai,Ai.VERTEX),Va=ze(Ai,Ai.INSTANCE),S6=ze(Ai,Ai.SUBGROUP),_6=ze(Ai,Ai.INVOCATION_SUBGROUP),w6=ze(Ai,Ai.INVOCATION_LOCAL),AC=ze(Ai,Ai.DRAW),M6=class extends Ke{static get type(){return"ComputeNode"}constructor(e,t){super("void"),this.isComputeNode=!0,this.computeNode=e,this.workgroupSize=t,this.count=null,this.dispatchSize=null,this.version=1,this.name="",this.updateBeforeType=ut.OBJECT,this.onInitFunction=null,this.countNode=null}dispose(){this.dispatchEvent({type:"dispose"})}setName(e){return this.name=e,this}label(e){return Ue('TSL: "label()" has been deprecated. Use "setName()" instead.',new $r),this.setName(e)}onInit(e){return this.onInitFunction=e,this}updateBefore({renderer:e}){e.compute(this)}setup(e){this.count!==null&&this.countNode===null&&(this.countNode=Qe(this.count,"uint").onObjectUpdate(()=>this.count));let t=this.computeNode.build(e);if(t){let r=e.getNodeProperties(this);r.outputComputeNode=t.outputNode,t.outputNode=null}return t}generate(e,t){let{shaderStage:r}=e;if(r==="compute"){let i=this.computeNode.build(e,"void");if(i!==""&&e.addLineFlowCode(i,this),this.count!==null&&e.allowEarlyReturns===!0){let s=this.countNode.build(e,"uint"),a=Va.build(e,"uint");e.flow.code=`${e.tab}if ( ${a} >= ${s} ) { return; } ${e.flow.code}`}}else{let i=e.getNodeProperties(this).outputComputeNode;if(i)return i.build(e,t)}}},Kb=(e,t=[64])=>{(t.length===0||t.length>3)&&Ce("TSL: compute() workgroupSize must have 1, 2, or 3 elements",new $r);for(let r=0;r{let i=Kb(e,r);return typeof t=="number"?i.count=t:i.dispatchSize=t,i};xe("compute",CC),xe("computeKernel",Kb);var N6=class extends Ke{static get type(){return"IsolateNode"}constructor(e,t=!0){super(),this.node=e,this.parent=t,this.isIsolateNode=!0}generateNodeType(e){let t=e.getCache(),r=e.getCacheFromNode(this,this.parent);e.setCache(r);let i=this.node.getNodeType(e);return e.setCache(t),i}build(e,...t){let r=e.getCache(),i=e.getCacheFromNode(this,this.parent);e.setCache(i);let s=this.node.build(e,...t);return e.setCache(r),s}setParent(e){return this.parent=e,this}getParent(){return this.parent}},wd=e=>new N6(Ye(e));function RC(e,t=!0){return Ue('TSL: "cache()" has been deprecated. Use "isolate()" instead.'),wd(e).setParent(t)}xe("cache",RC),xe("isolate",wd);var A6=class extends Ke{static get type(){return"BypassNode"}constructor(e,t){super(),this.isBypassNode=!0,this.outputNode=e,this.callNode=t}generateNodeType(e){return this.outputNode.getNodeType(e)}generate(e){let t=this.callNode.build(e,"void");return t!==""&&e.addLineFlowCode(t,this),this.outputNode.build(e)}},EC=Mt(A6).setParameterLength(2);xe("bypass",EC);var eT=Q(([e,t,r,i=D(0),s=D(1),a=Gs(!1)])=>{let n=e.sub(t).div(r.sub(t));return vd(a)&&(n=n.clamp()),n.mul(s.sub(i)).add(i)});function PC(e,t,r,i=D(0),s=D(1)){return eT(e,t,r,i,s,!0)}xe("remap",eT),xe("remapClamp",PC);var S0=class extends Ke{static get type(){return"ExpressionNode"}constructor(e="",t="void"){super(t),this.snippet=e}generate(e,t){let r=this.getNodeType(e),i=this.snippet;if(r==="void")e.addLineFlowCode(i,this);else return e.format(i,r,t)}},Xs=Mt(S0).setParameterLength(1,2),BC=e=>(e?Zi(e,Xs("discard")):Xs("discard")).toStack(),C6=()=>Xs("return").toStack();xe("discard",BC);var tT=Q(([e])=>Ve(e.rgb.mul(e.a),e.a),{color:"vec4",return:"vec4"}),IC=Q(([e])=>e.a.equal(0).select(Ve(0),Ve(e.rgb.div(e.a),e.a)),{color:"vec4",return:"vec4"}),R6=class extends rr{static get type(){return"RenderOutputNode"}constructor(e,t,r){super("vec4"),this.colorNode=e,this._toneMapping=t,this.outputColorSpace=r,this.isRenderOutputNode=!0}setToneMapping(e){return this._toneMapping=e,this}getToneMapping(){return this._toneMapping}setup({context:e}){let t=this.colorNode||e.color;t=Ve(t.rgb,t.a.clamp(0,1)),t=IC(t);let r=(this._toneMapping!==null?this._toneMapping:e.toneMapping)||eo,i=(this.outputColorSpace!==null?this.outputColorSpace:e.outputColorSpace)||Fa;return r!==eo&&(t=t.toneMapping(r)),i!==Fa&&i!==Gt.workingColorSpace&&(t=t.workingToColorSpace(i)),t=tT(t),t}},_0=(e,t=null,r=null)=>new R6(Ye(e),t,r);xe("renderOutput",_0);var E6=class extends rr{static get type(){return"DebugNode"}constructor(e,t=null){super(),this.node=e,this.callback=t}generateNodeType(e){return this.node.getNodeType(e)}setup(e){return this.node.build(e)}analyze(e){return this.node.build(e)}generate(e){let t=this.callback,r=this.node.build(e);if(t!==null)t(e,r);else{let i="--- TSL debug - "+e.shaderStage+" shader ---",s="-".repeat(i.length),a="";a+="// #"+i+`# `,a+=e.flow.code.replace(/^\t/gm,"")+` `,a+="/* ... */ "+r+` /* ... */ `,a+="// #"+s+`# `,xv(a)}return r}},FC=(e,t=null)=>new E6(Ye(e),t).toStack();xe("debug",FC);var LC=class extends hn{constructor(){super(),this._renderer=null,this.currentFrame=null}get nodeFrame(){return this._renderer._nodes.nodeFrame}setRenderer(e){return this._renderer=e,this}getRenderer(){return this._renderer}init(){}begin(){}finish(){}inspect(){}computeAsync(){}beginCompute(){}finishCompute(){}beginRender(){}finishRender(){}copyTextureToTexture(){}copyFramebufferToTexture(){}},P6=class extends Ke{static get type(){return"InspectorNode"}constructor(e,t="",r=null){super(),this.node=e,this.name=t,this.callback=r,this.updateType=ut.FRAME,this.isInspectorNode=!0}getName(){return this.name||this.node.name}update(e){e.renderer.inspector.inspect(this)}generateNodeType(e){return this.node.getNodeType(e)}setup(e){let t=this.node;return e.context.inspector===!0&&this.callback!==null&&(t=this.callback(t)),e.renderer.backend.isWebGPUBackend!==!0&&e.renderer.inspector.constructor!==LC&&Et('TSL: ".toInspector()" is only available with WebGPU.'),t}};function kC(e,t="",r=null){return e=Ye(e),e.before(new P6(e,t,r))}xe("toInspector",kC);function B6(e){Ue("TSL: AddNodeElement has been removed in favor of tree-shaking. Trying add",e)}var DC=class extends Ke{static get type(){return"AttributeNode"}constructor(e,t=null){super(t),this.global=!0,this._attributeName=e}getHash(e){return this.getAttributeName(e)}generateNodeType(e){let t=this.nodeType;if(t===null){let r=this.getAttributeName(e);if(e.hasGeometryAttribute(r)){let i=e.geometry.getAttribute(r);t=e.getTypeFromAttribute(i)}else t="float"}return t}setAttributeName(e){return this._attributeName=e,this}getAttributeName(){return this._attributeName}generate(e){let t=this.getAttributeName(e),r=this.getNodeType(e);if(e.hasGeometryAttribute(t)===!0){let i=e.geometry.getAttribute(t),s=e.getTypeFromAttribute(i),a=e.getAttribute(t,s);return e.shaderStage==="vertex"?e.format(a.name,s,r):pl(this).build(e,r)}else return Ue(`AttributeNode: Vertex attribute "${t}" not found on geometry.`),e.generateConst(r)}serialize(e){super.serialize(e),e.global=this.global,e._attributeName=this._attributeName}deserialize(e){super.deserialize(e),this.global=e.global,this._attributeName=e._attributeName}},$s=(e,t=null)=>new DC(e,t),Jt=(e=0)=>$s("uv"+(e>0?e:""),"vec2"),I6=class extends Ke{static get type(){return"TextureSizeNode"}constructor(e,t=null){super("uvec2"),this.isTextureSizeNode=!0,this.textureNode=e,this.levelNode=t}generate(e,t){let r=this.textureNode.build(e,"property"),i=this.levelNode===null?"0":this.levelNode.build(e,"int");return e.format(`${e.getMethod("textureDimensions")}( ${r}, ${i} )`,this.getNodeType(e),t)}},Fu=Mt(I6).setParameterLength(1,2),F6=class extends Ep{static get type(){return"MaxMipLevelNode"}constructor(e){super(0),this._textureNode=e,this.updateType=ut.FRAME}get textureNode(){return this._textureNode}get texture(){return this._textureNode.value}update(){let e=this.texture,t=e.images,r=t&&t.length>0?t[0]&&t[0].image||t[0]:e.image;if(r&&r.width!==void 0){let{width:i,height:s}=r;this.value=Math.log2(Math.max(i,s))}}},rT=Mt(F6).setParameterLength(1),OC=class extends Error{constructor(e,t=null){super(e),this.name="NodeError",this.stackTrace=t}},iT=new ji,An=class extends Ep{static get type(){return"TextureNode"}constructor(e=iT,t=null,r=null,i=null){super(e),this.isTextureNode=!0,this.uvNode=t,this.levelNode=r,this.biasNode=i,this.compareNode=null,this.depthNode=null,this.gradNode=null,this.gatherNode=null,this.offsetNode=null,this.sampler=!0,this.updateMatrix=!1,this.updateType=ut.NONE,this.referenceNode=null,this._value=e,this._matrixUniform=null,this._flipYUniform=null,this.setUpdateMatrix(t===null)}set value(e){this.referenceNode?this.referenceNode.value=e:this._value=e}get value(){return this.referenceNode?this.referenceNode.value:this._value}getUniformHash(){return this.value.uuid}generateNodeType(){return this.value.isDepthTexture===!0?this.gatherNode===null?"float":"vec4":this.value.type===gr?"uvec4":this.value.type===ci?"ivec4":"vec4"}getInputType(){return"texture"}getDefaultUV(){return Jt(this.value.channel)}updateReference(){return this.value}getTransformedUV(e){return this._matrixUniform===null&&(this._matrixUniform=Qe(this.value.matrix)),this._matrixUniform.mul(K(e,1)).xy}setUpdateMatrix(e){return this.updateMatrix=e,this}setupUV(e,t){return e.isFlipY()&&(this._flipYUniform===null&&(this._flipYUniform=Qe(!1)),t=t.toVar(),this.sampler?t=this._flipYUniform.select(t.flipY(),t):t=this._flipYUniform.select(t.setY(Y(Fu(this,this.levelNode).y).sub(t.y).sub(1)),t)),t}setup(e){let t=e.getNodeProperties(this);t.referenceNode=this.referenceNode;let r=this.value;if(!r||r.isTexture!==!0)throw new OC("THREE.TSL: `texture( value )` function expects a valid instance of THREE.Texture().",this.stackTrace);let i=Q(()=>{let o=this.uvNode;return(o===null||e.context.forceUVContext===!0)&&e.context.getUV&&(o=e.context.getUV(this,e)),o||(o=this.getDefaultUV()),this.updateMatrix===!0&&(o=this.getTransformedUV(o)),o=this.setupUV(e,o),this.updateType=this._matrixUniform!==null||this._flipYUniform!==null?ut.OBJECT:ut.NONE,o})(),s=this.levelNode;s===null&&e.context.getTextureLevel&&(s=e.context.getTextureLevel(this));let a=null,n=null;if(this.compareNode!==null)if(e.renderer.hasCompatibility(fu.TEXTURE_COMPARE))a=this.compareNode;else{let o=r.compareFunction;o===null||o===yv||o===tp||o===fg||o===$h?n=this.compareNode:(a=this.compareNode,Et('TSL: Only "LessCompare", "LessEqualCompare", "GreaterCompare" and "GreaterEqualCompare" are supported for depth texture comparison fallback.'))}t.uvNode=i,t.levelNode=s,t.biasNode=this.biasNode,t.compareNode=a,t.compareStepNode=n,t.gradNode=this.gradNode,t.gatherNode=this.gatherNode,t.depthNode=this.depthNode,t.offsetNode=this.offsetNode}generateUV(e,t){return t.build(e,this.sampler===!0?"vec2":"ivec2")}generateOffset(e,t){return t.build(e,"ivec2")}generateSnippet(e,t,r,i,s,a,n,o,l,u,h){let d=this.value,c;return s?c=e.generateTextureBias(d,t,r,s,a,u):o?c=e.generateTextureGrad(d,t,r,o,a,u):l?n?c=e.generateTextureGatherCompare(d,t,r,n,a,u,h):c=e.generateTextureGather(d,t,r,l,a,u,h):n?c=e.generateTextureCompare(d,t,r,n,a,u):this.sampler===!1?c=e.generateTextureLoad(d,t,r,i,a,u):i?c=e.generateTextureLevel(d,t,r,i,a,u):c=e.generateTexture(d,t,r,a,u),c}generate(e,t){let r=this.value,i=e.getNodeProperties(this),s=super.generate(e,"property");if(/^sampler/.test(t))return s+"_sampler";if(e.isReference(t))return s;{let a=e.getDataFromNode(this),n=this.getNodeType(e),o=a.propertyName;if(o===void 0){let{uvNode:u,levelNode:h,biasNode:d,compareNode:c,compareStepNode:m,depthNode:g,gradNode:y,gatherNode:b,offsetNode:v}=i,S=this.generateUV(e,u),T=h?h.build(e,"float"):null,w=d?d.build(e,"float"):null,N=g?g.build(e,"int"):null,C=c?c.build(e,"float"):null,R=m?m.build(e,"float"):null,E=y?[y[0].build(e,"vec2"),y[1].build(e,"vec2")]:null,P=b?b.build(e,"int"):null,I=v?this.generateOffset(e,v):null,O=this._flipYUniform?this._flipYUniform.build(e,"bool"):null;P&&(n="vec4");let L=N;L===null&&r.isArrayTexture&&this.isTexture3DNode!==!0&&(L="0");let X=e.getVarFromNode(this);o=e.getPropertyName(X);let z=this.generateSnippet(e,s,S,T,w,L,C,E,P,I,O);if(R!==null){let H=r.compareFunction;H===fg||H===$h?z=Bu(Xs(z,n),Xs(R,"float")).build(e,n):z=Bu(Xs(R,"float"),Xs(z,n)).build(e,n)}e.addLineFlowCode(`${o} = ${z}`,this),a.snippet=z,a.propertyName=o}let l=o;return e.needsToWorkingColorSpace(r)&&(l=v0(Xs(l,n),r.colorSpace).setup(e).build(e,n)),e.format(l,n,t)}}setSampler(e){return this.sampler=e,this}getSampler(){return this.sampler}sample(e){let t=this.clone();return t.uvNode=Ye(e),t.referenceNode=this.getBase(),Ye(t)}load(e){return this.sample(e).setSampler(!1)}blur(e){let t=this.clone();t.biasNode=Ye(e).mul(rT(t)),t.referenceNode=this.getBase();let r=t.value;return t.generateMipmaps===!1&&(r&&r.generateMipmaps===!1||r.minFilter===or||r.magFilter===or)&&(Ue("TSL: texture().blur() requires mipmaps and sampling. Use .generateMipmaps=true and .minFilter/.magFilter=THREE.LinearFilter in the Texture."),t.biasNode=null),Ye(t)}level(e){let t=this.clone();return t.levelNode=Ye(e),t.referenceNode=this.getBase(),Ye(t)}size(e){return Fu(this,e)}bias(e){let t=this.clone();return t.biasNode=Ye(e),t.referenceNode=this.getBase(),Ye(t)}getBase(){return this.referenceNode?this.referenceNode.getBase():this}compare(e){let t=this.clone();return t.compareNode=Ye(e),t.referenceNode=this.getBase(),Ye(t)}grad(e,t){let r=this.clone();return r.gradNode=[Ye(e),Ye(t)],r.referenceNode=this.getBase(),Ye(r)}gather(e=0){let t=this.clone();return t.gatherNode=Ye(e),t.referenceNode=this.getBase(),Ye(t)}depth(e){let t=this.clone();return t.depthNode=Ye(e),t.referenceNode=this.getBase(),Ye(t)}offset(e){let t=this.clone();return t.offsetNode=Ye(e),t.referenceNode=this.getBase(),Ye(t)}serialize(e){super.serialize(e),e.value=this.value.toJSON(e.meta).uuid,e.sampler=this.sampler,e.updateMatrix=this.updateMatrix,e.updateType=this.updateType}deserialize(e){super.deserialize(e),this.value=e.meta.textures[e.value],this.sampler=e.sampler,this.updateMatrix=e.updateMatrix,this.updateType=e.updateType}update(){let e=this.value,t=this._matrixUniform;t!==null&&(t.value=e.matrix),e.matrixAutoUpdate===!0&&e.updateMatrix();let r=this._flipYUniform;r!==null&&(r.value=e.image instanceof ImageBitmap&&e.flipY===!0||e.isRenderTargetTexture===!0||e.isFramebufferTexture===!0||e.isDepthTexture===!0)}clone(){let e=new this.constructor(this.value,this.uvNode,this.levelNode,this.biasNode);return e.sampler=this.sampler,e.depthNode=this.depthNode,e.compareNode=this.compareNode,e.gradNode=this.gradNode,e.gatherNode=this.gatherNode,e.offsetNode=this.offsetNode,e}},L6=Mt(An).setParameterLength(1,4).setName("texture"),Ot=(e=iT,t=null,r=null,i=null)=>{let s;return e&&e.isTextureNode===!0?(s=Ye(e.clone()),s.referenceNode=e.getBase(),t!==null&&(s.uvNode=Ye(t)),r!==null&&(s.levelNode=Ye(r)),i!==null&&(s.biasNode=Ye(i))):s=L6(e,t,r,i),s},k6=(e=iT)=>Ot(e),Gr=(...e)=>Ot(...e).setSampler(!1),D6=(e,t,r)=>Ot(e,t).level(r),O6=e=>(e.isNode===!0?e:Ot(e)).convert("sampler"),U6=e=>(e.isNode===!0?e:Ot(e)).convert("samplerComparison"),sT=class extends Ep{static get type(){return"BufferNode"}constructor(e,t,r=0){super(e,t),this.isBufferNode=!0,this.bufferType=t,this.bufferCount=r,this.updateRanges=[]}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}getElementType(e){return this.getNodeType(e)}getInputType(){return"buffer"}},Md=(e,t,r)=>new sT(e,t,r),z6=class extends _u{static get type(){return"UniformArrayElementNode"}constructor(e,t){super(e,t),this.isArrayBufferElementNode=!0}generate(e){let t=super.generate(e),r=this.getNodeType(e),i=this.node.getPaddedType();return e.format(t,i,r)}},V6=class extends sT{static get type(){return"UniformArrayNode"}constructor(e,t=null){super(null),this.array=e,this.elementType=t===null?ol(e[0]):t,this.paddedType=this.getPaddedType(),this.updateType=ut.RENDER,this.isArrayBufferNode=!0}generateNodeType(){return this.paddedType}getElementType(){return this.elementType}getPaddedType(){let e=this.elementType,t="vec4";return e==="mat2"?t="mat2":/mat/.test(e)===!0?t="mat4":e.charAt(0)==="i"?t="ivec4":e.charAt(0)==="u"&&(t="uvec4"),t}update(){let{array:e,value:t}=this,r=this.elementType;if(r==="float"||r==="int"||r==="uint")for(let i=0;inew V6(e,t),G6=class extends Ke{constructor(e){super("float"),this.name=e,this.isBuiltinNode=!0}generate(){return this.name}},bo=Mt(G6).setParameterLength(1),Pp,Bp,vs=class Ba extends Ke{static get type(){return"ScreenNode"}constructor(t){super(),this.scope=t,this._output=null,this.isViewportNode=!0}generateNodeType(){return this.scope===Ba.DPR?"float":this.scope===Ba.VIEWPORT?"vec4":"vec2"}getUpdateType(){let t=ut.NONE;return(this.scope===Ba.SIZE||this.scope===Ba.VIEWPORT||this.scope===Ba.DPR)&&(t=ut.RENDER),this.updateType=t,t}update({renderer:t}){let r=t.getRenderTarget();this.scope===Ba.VIEWPORT?r!==null?Bp.copy(r.viewport):(t.getViewport(Bp),Bp.multiplyScalar(t.getPixelRatio())):this.scope===Ba.DPR?this._output.value=t.getPixelRatio():r!==null?(Pp.width=r.width,Pp.height=r.height):t.getDrawingBufferSize(Pp)}setup(){let t=this.scope,r=null;return t===Ba.SIZE?r=Qe(Pp||(Pp=new fe)):t===Ba.VIEWPORT?r=Qe(Bp||(Bp=new Wt)):t===Ba.DPR?r=Qe(1):r=ke(ku.div(Lu)),this._output=r,r}generate(t){if(this.scope===Ba.COORDINATE){let r=t.getFragCoord();if(t.isFlipY()){let i=t.getNodeProperties(Lu).outputNode.build(t);r=`${t.getType("vec2")}( ${r}.x, ${i}.y - ${r}.y )`}return r}return super.generate(t)}};vs.COORDINATE="coordinate",vs.VIEWPORT="viewport",vs.SIZE="size",vs.UV="uv",vs.DPR="dpr";var aT=ze(vs,vs.DPR),Ga=ze(vs,vs.UV),Lu=ze(vs,vs.SIZE),ku=ze(vs,vs.COORDINATE),Nd=ze(vs,vs.VIEWPORT),nT=Nd.zw,UC=ku.sub(Nd.xy),W6=UC.div(nT),j6=Q(()=>(Ue('TSL: "viewportResolution" is deprecated. Use "screenSize" instead.',new $r),Lu),"vec2").once()(),oT=null,w0=null,lT=null,M0=null,uT=null,N0=null,hT=null,A0=null,dT=null,C0=null,cT=null,R0=null,pT=null,E0=null,fl=Qe(0,"uint").setName("u_cameraIndex").setGroup(d0("cameraIndex")).toVarying("v_cameraIndex"),gl=Qe("float").setName("cameraNear").setGroup(st).onRenderUpdate(({camera:e})=>e.near),yl=Qe("float").setName("cameraFar").setGroup(st).onRenderUpdate(({camera:e})=>e.far),bs=Q(({camera:e})=>{let t;if(e.isArrayCamera&&e.cameras.length>0){let r=[];for(let i of e.cameras)r.push(i.projectionMatrix);w0===null?w0=Li(r).setGroup(st).setName("cameraProjectionMatrices"):w0.array=r,t=w0.element(e.isMultiViewCamera?bo("gl_ViewID_OVR"):fl)}else oT===null&&(oT=Qe(e.projectionMatrix).setName("cameraProjectionMatrix").setGroup(st).onRenderUpdate(({camera:r})=>r.projectionMatrix)),t=oT;return t}).once()(),zC=Q(({camera:e})=>{let t;if(e.isArrayCamera&&e.cameras.length>0){let r=[];for(let i of e.cameras)r.push(i.projectionMatrixInverse);M0===null?M0=Li(r).setGroup(st).setName("cameraProjectionMatricesInverse"):M0.array=r,t=M0.element(e.isMultiViewCamera?bo("gl_ViewID_OVR"):fl)}else lT===null&&(lT=Qe(e.projectionMatrixInverse).setName("cameraProjectionMatrixInverse").setGroup(st).onRenderUpdate(({camera:r})=>r.projectionMatrixInverse)),t=lT;return t}).once()(),xl=Q(({camera:e})=>{let t;if(e.isArrayCamera&&e.cameras.length>0){let r=[];for(let i of e.cameras)r.push(i.matrixWorldInverse);N0===null?N0=Li(r).setGroup(st).setName("cameraViewMatrices"):N0.array=r,t=N0.element(e.isMultiViewCamera?bo("gl_ViewID_OVR"):fl)}else uT===null&&(uT=Qe(e.matrixWorldInverse).setName("cameraViewMatrix").setGroup(st).onRenderUpdate(({camera:r})=>r.matrixWorldInverse)),t=uT;return t}).once()(),Ip=Q(({camera:e})=>{let t;if(e.isArrayCamera&&e.cameras.length>0){let r=[];for(let i of e.cameras)r.push(i.matrixWorld);A0===null?A0=Li(r).setGroup(st).setName("cameraWorldMatrices"):A0.array=r,t=A0.element(e.isMultiViewCamera?bo("gl_ViewID_OVR"):fl)}else hT===null&&(hT=Qe(e.matrixWorld).setName("cameraWorldMatrix").setGroup(st).onRenderUpdate(({camera:r})=>r.matrixWorld)),t=hT;return t}).once()(),H6=Q(({camera:e})=>{let t;if(e.isArrayCamera&&e.cameras.length>0){let r=[];for(let i of e.cameras)r.push(i.normalMatrix);C0===null?C0=Li(r).setGroup(st).setName("cameraNormalMatrices"):C0.array=r,t=C0.element(e.isMultiViewCamera?bo("gl_ViewID_OVR"):fl)}else dT===null&&(dT=Qe(e.normalMatrix).setName("cameraNormalMatrix").setGroup(st).onRenderUpdate(({camera:r})=>r.normalMatrix)),t=dT;return t}).once()(),VC=Q(({camera:e})=>{let t;if(e.isArrayCamera&&e.cameras.length>0){let r=[];for(let i=0,s=e.cameras.length;i{let a=i.cameras,n=s.array;for(let o=0,l=a.length;oi.value.setFromMatrixPosition(r.matrixWorld))),t=cT;return t}).once()(),X6=Q(({camera:e})=>{let t;if(e.isArrayCamera&&e.cameras.length>0){let r=[];for(let i of e.cameras)r.push(i.viewport);E0===null?E0=Li(r,"vec4").setGroup(st).setName("cameraViewports"):E0.array=r,t=E0.element(fl)}else pT===null&&(pT=Ve(0,0,Lu.x,Lu.y).toConst("cameraViewport")),t=pT;return t}).once()(),GC=new Ng,mi=class bi extends Ke{static get type(){return"Object3DNode"}constructor(t,r=null){super(),this.scope=t,this.object3d=r,this.updateType=ut.OBJECT,this.uniformNode=new Ep(null)}generateNodeType(){let t=this.scope;if(t===bi.WORLD_MATRIX)return"mat4";if(t===bi.POSITION||t===bi.VIEW_POSITION||t===bi.DIRECTION||t===bi.SCALE)return"vec3";if(t===bi.RADIUS)return"float"}update(t){let r=this.object3d,i=this.uniformNode,s=this.scope;if(s===bi.WORLD_MATRIX)i.value=r.matrixWorld;else if(s===bi.POSITION)i.value=i.value||new F,i.value.setFromMatrixPosition(r.matrixWorld);else if(s===bi.SCALE)i.value=i.value||new F,i.value.setFromMatrixScale(r.matrixWorld);else if(s===bi.DIRECTION)i.value=i.value||new F,r.getWorldDirection(i.value);else if(s===bi.VIEW_POSITION){let a=t.camera;i.value=i.value||new F,i.value.setFromMatrixPosition(r.matrixWorld),i.value.applyMatrix4(a.matrixWorldInverse)}else if(s===bi.RADIUS){let a=t.object.geometry;a.boundingSphere===null&&a.computeBoundingSphere(),GC.copy(a.boundingSphere).applyMatrix4(r.matrixWorld),i.value=GC.radius}}generate(t){let r=this.scope;return r===bi.WORLD_MATRIX?this.uniformNode.nodeType="mat4":r===bi.POSITION||r===bi.VIEW_POSITION||r===bi.DIRECTION||r===bi.SCALE?this.uniformNode.nodeType="vec3":r===bi.RADIUS&&(this.uniformNode.nodeType="float"),this.uniformNode.build(t)}serialize(t){super.serialize(t),t.scope=this.scope}deserialize(t){super.deserialize(t),this.scope=t.scope}};mi.WORLD_MATRIX="worldMatrix",mi.POSITION="position",mi.SCALE="scale",mi.VIEW_POSITION="viewPosition",mi.DIRECTION="direction",mi.RADIUS="radius";var $6=Mt(mi,mi.DIRECTION).setParameterLength(1),q6=Mt(mi,mi.WORLD_MATRIX).setParameterLength(1),Y6=Mt(mi,mi.POSITION).setParameterLength(1),Z6=Mt(mi,mi.SCALE).setParameterLength(1),J6=Mt(mi,mi.VIEW_POSITION).setParameterLength(1),Q6=Mt(mi,mi.RADIUS).setParameterLength(1),fa=class extends mi{static get type(){return"ModelNode"}constructor(e){super(e)}update(e){this.object3d=e.object,super.update(e)}},K6=ze(fa,fa.DIRECTION),ga=ze(fa,fa.WORLD_MATRIX),ez=ze(fa,fa.POSITION),tz=ze(fa,fa.SCALE),rz=ze(fa,fa.VIEW_POSITION),iz=ze(fa,fa.RADIUS),WC=Qe(new Dr).onObjectUpdate(({object:e},t)=>t.value.getNormalMatrix(e.matrixWorld)),sz=Qe(new We).onObjectUpdate(({object:e},t)=>t.value.copy(e.matrixWorld).invert()),Cn=Q(e=>e.context.modelViewMatrix||jC).once()().toVar("modelViewMatrix"),jC=xl.mul(ga),mT=Q(e=>(e.context.isHighPrecisionModelViewMatrix=!0,Qe("mat4").onObjectUpdate(({object:t,camera:r})=>t.modelViewMatrix.multiplyMatrices(r.matrixWorldInverse,t.matrixWorld)))).once()().toVar("highpModelViewMatrix"),fT=Q(e=>{let t=e.context.isHighPrecisionModelViewMatrix;return Qe("mat3").onObjectUpdate(({object:r,camera:i})=>(t!==!0&&r.modelViewMatrix.multiplyMatrices(i.matrixWorldInverse,r.matrixWorld),r.normalMatrix.getNormalMatrix(r.modelViewMatrix)))}).once()().toVar("highpModelNormalViewMatrix"),HC=Q(e=>e.shaderStage!=="fragment"?(Et("TSL: `clipSpace` is only available in fragment stage."),Ve()):e.context.clipSpace.toVarying("v_clipSpace")).once()(),Ji=$s("position","vec3"),wr=Ji.toVarying("positionLocal"),Du=Ji.toVarying("positionPrevious"),Rn=Q(e=>ga.mul(wr).xyz.toVarying(e.getSubBuildProperty("v_positionWorld")),"vec3").once(["POSITION"])(),gT=Q(()=>wr.transformDirection(ga).toVarying("v_positionWorldDirection").normalize().toVar("positionWorldDirection"),"vec3").once(["POSITION"])(),Wr=Q(e=>{if(e.shaderStage==="fragment"&&e.material.vertexNode){let t=zC.mul(HC);return t.xyz.div(t.w).toVar("positionView")}return e.context.setupPositionView().toVarying("v_positionView")},"vec3").once(["POSITION","VERTEX"])(),ar=Q(e=>{let t;return e.camera.isOrthographicCamera?t=K(0,0,1):t=Wr.negate().toVarying("v_positionViewDirection").normalize(),t.toVar("positionViewDirection")},"vec3").once(["POSITION"])(),az=class extends Ke{static get type(){return"FrontFacingNode"}constructor(){super("bool"),this.isFrontFacingNode=!0}generate(e){if(e.shaderStage!=="fragment")return"true";let{material:t}=e;return t.side===ii?"false":e.getFrontFacing()}},XC=ze(az),yT=D(XC).mul(2).sub(1),Ou=Q(([e],{material:t})=>{let r=t.side;return r===ii?e=e.mul(-1):r===hs&&(e=e.mul(yT)),e}),nz=e=>(Et('TSL: "directionToFaceDirection()" has been renamed to "negateOnBackSide()".'),Ou(e)),P0=$s("normal","vec3"),Qi=Q(e=>e.geometry.hasAttribute("normal")===!1?(Ue('TSL: Vertex attribute "normal" not found on geometry.'),K(0,1,0)):P0,"vec3").once()().toVar("normalLocal"),$C=Wr.dFdx().cross(Wr.dFdy()).normalize().toVar("normalFlat"),Ad=Q(e=>{let t;return e.isFlatShading()?t=$C:t=vT(Qi).toVarying("v_normalViewGeometry").normalize(),t},"vec3").once()().toVar("normalViewGeometry"),qC=Q(e=>{let t=Ad.transformNormalByInverseViewMatrix(xl);return e.isFlatShading()!==!0&&(t=t.toVarying("v_normalWorldGeometry")),t.normalize().toVar("normalWorldGeometry")},"vec3").once()(),Ut=Q(e=>{let t;return e.subBuildFn==="NORMAL"||e.subBuildFn==="VERTEX"?(t=Ad,e.isFlatShading()!==!0&&(t=Ou(t))):t=e.context.setupNormal().context({getUV:null,getTextureLevel:null}),t},"vec3").once(["NORMAL","VERTEX"])().toVar("normalView"),vl=Ut.transformNormalByInverseViewMatrix(xl).toVar("normalWorld"),bl=Q(({subBuildFn:e,context:t})=>{let r;return e==="NORMAL"||e==="VERTEX"?r=Ut:r=t.setupClearcoatNormal().context({getUV:null,getTextureLevel:null}),r},"vec3").once(["NORMAL","VERTEX"])().toVar("clearcoatNormalView"),xT=Q(([e,t=ga])=>Ni(t).inverse().transpose().mul(e).normalize());xe("transformNormal",xT);var vT=Q(([e],t)=>{let r=t.context.modelNormalViewMatrix;return r?e.transformNormalByViewMatrix(r):WC.mul(e).transformNormalByViewMatrix(xl)}),oz=Q(()=>(Ue('TSL: "transformedNormalView" is deprecated. Use "normalView" instead.'),Ut)).once(["NORMAL","VERTEX"])(),lz=Q(()=>(Ue('TSL: "transformedNormalWorld" is deprecated. Use "normalWorld" instead.'),vl)).once(["NORMAL","VERTEX"])(),uz=Q(()=>(Ue('TSL: "transformedClearcoatNormalView" is deprecated. Use "clearcoatNormalView" instead.'),bl)).once(["NORMAL","VERTEX"])(),bT=new We,YC=Qe(0).onReference(({material:e})=>e).onObjectUpdate(({material:e})=>e.refractionRatio),B0=Qe(1).onReference(({material:e})=>e).onObjectUpdate(function({material:e,scene:t}){return e.envMap?e.envMapIntensity:t.environmentIntensity}),I0=Qe(new We).onReference(function(e){return e.material}).onObjectUpdate(function({material:e,scene:t}){let r=(t.environment!==null||t.environmentNode&&t.environmentNode.isNode)&&e.envMap===null?t.environmentRotation:e.envMapRotation;return r?bT.makeRotationFromEuler(r).transpose():bT.identity(),bT}),ZC=ar.negate().reflect(Ut),JC=ar.negate().refract(Ut,YC),QC=ZC.transformDirection(Ip).toVar("reflectVector"),KC=JC.transformDirection(Ip).toVar("refractVector"),eR=new Ug,hz=class extends An{static get type(){return"CubeTextureNode"}constructor(e,t=null,r=null,i=null){super(e,t,r,i),this.isCubeTextureNode=!0}getInputType(){return this.value.isDepthTexture===!0?"cubeDepthTexture":"cubeTexture"}getDefaultUV(){let e=this.value;return e.mapping===Vh?QC:e.mapping===Lf?KC:(Ce('CubeTextureNode: Mapping "%s" not supported.',e.mapping),K(0,0,0))}setUpdateMatrix(){}setupUV(e,t){let r=this.value;return r.isDepthTexture===!0?e.renderer.coordinateSystem===da?K(t.x,t.y.negate(),t.z):t:(t=I0.mul(t),(e.renderer.coordinateSystem===da||!r.isRenderTargetTexture)&&(t=K(t.x.negate(),t.yz)),t)}generateUV(e,t){return t.build(e,this.sampler===!0?"vec3":"ivec3")}},TT=Mt(hz).setParameterLength(1,4).setName("cubeTexture"),Ts=(e=eR,t=null,r=null,i=null)=>{let s;return e&&e.isCubeTextureNode===!0?(s=Ye(e.clone()),s.referenceNode=e,t!==null&&(s.uvNode=Ye(t)),r!==null&&(s.levelNode=Ye(r)),i!==null&&(s.biasNode=Ye(i))):s=TT(e,t,r,i),s},dz=(e=eR)=>TT(e),cz=class extends _u{static get type(){return"ReferenceElementNode"}constructor(e,t){super(e,t),this.referenceNode=e,this.isReferenceElementNode=!0}generateNodeType(){return this.referenceNode.uniformType}generate(e){let t=super.generate(e),r=this.referenceNode.getNodeType(e),i=this.getNodeType(e);return e.format(t,r,i)}},F0=class extends Ke{static get type(){return"ReferenceNode"}constructor(e,t,r=null,i=null){super(),this.property=e,this.uniformType=t,this.object=r,this.count=i,this.properties=e.split("."),this.reference=r,this.node=null,this.group=null,this.name=null,this.updateType=ut.OBJECT}element(e){return new cz(this,Ye(e))}setGroup(e){return this.group=e,this}setName(e){return this.name=e,this}label(e){return Ue('TSL: "label()" has been deprecated. Use "setName()" instead.'),this.setName(e)}setNodeType(e){let t=null;this.count!==null?t=Md(null,e,this.count):Array.isArray(this.getValueFromReference())?(t=Li(null,e),t.updateType=ut.OBJECT):e==="texture"?t=Ot(null):e==="cubeTexture"?t=Ts(null):t=Qe(null,e),this.group!==null&&t.setGroup(this.group),this.name!==null&&t.setName(this.name),this.node=t}generateNodeType(e){return this.node===null&&(this.updateReference(e),this.updateValue()),this.node.getNodeType(e)}getValueFromReference(e=this.reference){let{properties:t}=this,r=e[t[0]];for(let i=1;inew F0(e,t,r),tR=(e,t,r,i)=>new F0(e,t,i,r),pz=class extends F0{static get type(){return"MaterialReferenceNode"}constructor(e,t,r=null){super(e,t,r),this.material=r,this.isMaterialReferenceNode=!0}updateReference(e){return this.reference=this.material!==null?this.material:e.material,this.reference}},To=(e,t,r=null)=>new pz(e,t,r),rR=Jt(),mz=Wr.dFdx(),fz=Wr.dFdy(),iR=rR.dFdx(),sR=rR.dFdy(),aR=Ut,nR=fz.cross(aR),oR=aR.cross(mz),ST=nR.mul(iR.x).add(oR.mul(sR.x)),_T=nR.mul(iR.y).add(oR.mul(sR.y)),lR=ST.dot(ST).max(_T.dot(_T)),uR=lR.equal(0).select(0,lR.inverseSqrt()),gz=ST.mul(uR).toVar("tangentViewFrame"),yz=_T.mul(uR).toVar("bitangentViewFrame"),L0=$s("tangent","vec4"),Tl=L0.xyz.toVar("tangentLocal"),k0=Q(e=>{let t;return e.subBuildFn==="VERTEX"||e.geometry.hasAttribute("tangent")?t=Cn.mul(Ve(Tl,0)).xyz.toVarying("v_tangentView").normalize():t=gz,e.isFlatShading()!==!0&&(t=Ou(t)),t},"vec3").once(["NORMAL","VERTEX"])().toVar("tangentView"),hR=k0.transformDirection(Ip).toVarying("v_tangentWorld").normalize().toVar("tangentWorld"),D0=Q(([e,t],r)=>{let i=e.mul(L0.w).xyz;return r.subBuildFn==="NORMAL"&&r.isFlatShading()!==!0&&(i=i.toVarying(t)),i}).once(["NORMAL"]),xz=D0(P0.cross(L0),"v_bitangentGeometry").normalize().toVar("bitangentGeometry"),vz=D0(Qi.cross(Tl),"v_bitangentLocal").normalize().toVar("bitangentLocal"),dR=Q(e=>{let t;return e.subBuildFn==="VERTEX"||e.geometry.hasAttribute("tangent")?t=D0(Ut.cross(k0),"v_bitangentView").normalize():t=yz,e.isFlatShading()!==!0&&(t=Ou(t)),t},"vec3").once(["NORMAL","VERTEX"])().toVar("bitangentView"),bz=D0(vl.cross(hR),"v_bitangentWorld").normalize().toVar("bitangentWorld"),Uu=Ni(k0,dR,Ut).toVar("TBNViewMatrix"),cR=ar.mul(Uu),Tz=(e,t)=>e.sub(cR.mul(t)),pR=Q(()=>{let e=Cu.cross(ar);return e=e.cross(Cu).normalize(),e=Ct(e,Ut,dl.mul(_n.oneMinus()).oneMinus().pow2().pow2()).normalize(),e}).once()(),wT=e=>Ye(e).mul(.5).add(.5),mR=e=>Ye(e).mul(2).sub(1),MT=e=>K(e,ys(y0(D(1).sub(pa(e,e))))),Sz=e=>(Et('TSL: "directionToColor()" has been renamed to "packNormalToRGB()".'),wT(e)),_z=e=>(Et('TSL: "colorToDirection()" has been renamed to "unpackRGBToNormal()".'),mR(e)),wz=class extends rr{static get type(){return"NormalMapNode"}constructor(e,t=null){super("vec3"),this.node=e,this.scaleNode=t,this.normalMapType=so,this.unpackNormalMode=fv}setup(e){let{normalMapType:t,scaleNode:r,unpackNormalMode:i}=this,s=this.node.mul(2).sub(1);if(t===so?i===FM?s=MT(s.xy):i===DD?s=MT(s.yw):i!==fv&&Ce(`THREE.NodeMaterial: Unexpected unpack normal mode: ${i}`):i!==fv&&Ce(`THREE.NodeMaterial: Normal map type '${t}' is not compatible with unpack normal mode '${i}'`),r!==null){let n=r;e.isFlatShading()===!0&&(n=Ou(n)),s=K(s.xy.mul(n),s.z)}let a=null;return t===kD?a=vT(s):t===so?a=Uu.mul(s).normalize():(Ce(`NodeMaterial: Unsupported normal map type: ${t}`),a=Ut),a}},NT=Mt(wz).setParameterLength(1,2),Mz=Q(({textureNode:e,bumpScale:t})=>{let r=s=>e.isolate().context({getUV:a=>s(a.uvNode||Jt()),forceUVContext:!0}),i=D(r(s=>s));return ke(D(r(s=>s.add(s.dFdx()))).sub(i),D(r(s=>s.add(s.dFdy()))).sub(i)).mul(t)}),Nz=Q(e=>{let{surf_pos:t,surf_norm:r,dHdxy:i}=e,s=t.dFdx().normalize(),a=t.dFdy().normalize(),n=r,o=a.cross(n),l=n.cross(s),u=s.dot(o).mul(yT),h=u.sign().mul(i.x.mul(o).add(i.y.mul(l)));return u.abs().mul(r).sub(h).normalize()}),Az=class extends rr{static get type(){return"BumpMapNode"}constructor(e,t=null){super("vec3"),this.textureNode=e,this.scaleNode=t}setup(e){if(e.material.wireframe===!0)return Ut;let t=this.scaleNode!==null?this.scaleNode:1,r=Mz({textureNode:this.textureNode,bumpScale:t});return Nz({surf_pos:Wr,surf_norm:Ut,dHdxy:r})}},AT=Mt(Az).setParameterLength(1,2),fR=new Map,Pe=class zr extends Ke{static get type(){return"MaterialNode"}constructor(t){super(),this.scope=t}getCache(t,r){let i=fR.get(t);return i===void 0&&(i=To(t,r),fR.set(t,i)),i}getFloat(t){return this.getCache(t,"float")}getColor(t){return this.getCache(t,"color")}getTexture(t){return this.getCache(t==="map"?"map":t+"Map","texture")}setup(t){let r=t.context.material,i=this.scope,s=null;if(i===zr.COLOR){let a=r.color!==void 0?this.getColor(i):K();r.map&&r.map.isTexture===!0?s=a.mul(this.getTexture("map")):s=a}else if(i===zr.OPACITY){let a=this.getFloat(i);r.alphaMap&&r.alphaMap.isTexture===!0?s=a.mul(this.getTexture("alpha")):s=a}else if(i===zr.SPECULAR_STRENGTH)r.specularMap&&r.specularMap.isTexture===!0?s=this.getTexture("specular").r:s=D(1);else if(i===zr.SPECULAR_INTENSITY){let a=this.getFloat(i);r.specularIntensityMap&&r.specularIntensityMap.isTexture===!0?s=a.mul(this.getTexture(i).a):s=a}else if(i===zr.SPECULAR_COLOR){let a=this.getColor(i);r.specularColorMap&&r.specularColorMap.isTexture===!0?s=a.mul(this.getTexture(i).rgb):s=a}else if(i===zr.ROUGHNESS){let a=this.getFloat(i);r.roughnessMap&&r.roughnessMap.isTexture===!0?s=a.mul(this.getTexture(i).g):s=a}else if(i===zr.METALNESS){let a=this.getFloat(i);r.metalnessMap&&r.metalnessMap.isTexture===!0?s=a.mul(this.getTexture(i).b):s=a}else if(i===zr.EMISSIVE){let a=this.getFloat("emissiveIntensity"),n=this.getColor(i).mul(a);r.emissiveMap&&r.emissiveMap.isTexture===!0?s=n.mul(this.getTexture(i)):s=n}else if(i===zr.NORMAL)r.normalMap?(s=NT(this.getTexture("normal"),this.getCache("normalScale","vec2")),s.normalMapType=r.normalMapType,(r.normalMap.format==ha||r.normalMap.format==ep||r.normalMap.format==Kc)&&(s.unpackNormalMode=FM)):r.bumpMap?s=AT(this.getTexture("bump").r,this.getFloat("bumpScale")):s=Ut;else if(i===zr.CLEARCOAT){let a=this.getFloat(i);r.clearcoatMap&&r.clearcoatMap.isTexture===!0?s=a.mul(this.getTexture(i).r):s=a}else if(i===zr.CLEARCOAT_ROUGHNESS){let a=this.getFloat(i);r.clearcoatRoughnessMap&&r.clearcoatRoughnessMap.isTexture===!0?s=a.mul(this.getTexture(i).r):s=a}else if(i===zr.CLEARCOAT_NORMAL)r.clearcoatNormalMap?s=NT(this.getTexture(i),this.getCache(i+"Scale","vec2")):s=Ut;else if(i===zr.SHEEN){let a=this.getColor("sheenColor").mul(this.getFloat("sheen"));r.sheenColorMap&&r.sheenColorMap.isTexture===!0?s=a.mul(this.getTexture("sheenColor").rgb):s=a}else if(i===zr.SHEEN_ROUGHNESS){let a=this.getFloat(i);r.sheenRoughnessMap&&r.sheenRoughnessMap.isTexture===!0?s=a.mul(this.getTexture(i).a):s=a,s=s.clamp(1e-4,1)}else if(i===zr.ANISOTROPY)if(r.anisotropyMap&&r.anisotropyMap.isTexture===!0){let a=this.getTexture(i);s=i0(Cd.x,Cd.y,Cd.y.negate(),Cd.x).mul(a.rg.mul(2).sub(ke(1)).normalize().mul(a.b))}else s=Cd;else if(i===zr.IRIDESCENCE_THICKNESS){let a=cr("1","float",r.iridescenceThicknessRange);if(r.iridescenceThicknessMap){let n=cr("0","float",r.iridescenceThicknessRange);s=a.sub(n).mul(this.getTexture(i).g).add(n)}else s=a}else if(i===zr.TRANSMISSION){let a=this.getFloat(i);r.transmissionMap?s=a.mul(this.getTexture(i).r):s=a}else if(i===zr.THICKNESS){let a=this.getFloat(i);r.thicknessMap?s=a.mul(this.getTexture(i).g):s=a}else if(i===zr.IOR)s=this.getFloat(i);else if(i===zr.LIGHT_MAP)r.lightMap?s=this.getTexture(i).rgb.mul(this.getFloat("lightMapIntensity")):s=K(0);else if(i===zr.AO)r.aoMap?s=this.getTexture(i).r.sub(1).mul(this.getFloat("aoMapIntensity")).add(1):s=D(1);else if(i===zr.LINE_DASH_OFFSET)s=r.dashOffset?this.getFloat(i):D(0);else{let a=this.getNodeType(t);s=this.getCache(i,a)}return s}};Pe.ALPHA_TEST="alphaTest",Pe.COLOR="color",Pe.OPACITY="opacity",Pe.SHININESS="shininess",Pe.SPECULAR="specular",Pe.SPECULAR_STRENGTH="specularStrength",Pe.SPECULAR_INTENSITY="specularIntensity",Pe.SPECULAR_COLOR="specularColor",Pe.REFLECTIVITY="reflectivity",Pe.ROUGHNESS="roughness",Pe.METALNESS="metalness",Pe.NORMAL="normal",Pe.CLEARCOAT="clearcoat",Pe.CLEARCOAT_ROUGHNESS="clearcoatRoughness",Pe.CLEARCOAT_NORMAL="clearcoatNormal",Pe.EMISSIVE="emissive",Pe.ROTATION="rotation",Pe.SHEEN="sheen",Pe.SHEEN_ROUGHNESS="sheenRoughness",Pe.ANISOTROPY="anisotropy",Pe.IRIDESCENCE="iridescence",Pe.IRIDESCENCE_IOR="iridescenceIOR",Pe.IRIDESCENCE_THICKNESS="iridescenceThickness",Pe.IOR="ior",Pe.TRANSMISSION="transmission",Pe.THICKNESS="thickness",Pe.ATTENUATION_DISTANCE="attenuationDistance",Pe.ATTENUATION_COLOR="attenuationColor",Pe.LINE_SCALE="scale",Pe.LINE_DASH_SIZE="dashSize",Pe.LINE_GAP_SIZE="gapSize",Pe.LINE_WIDTH="linewidth",Pe.LINE_DASH_OFFSET="dashOffset",Pe.POINT_SIZE="size",Pe.DISPERSION="dispersion",Pe.LIGHT_MAP="light",Pe.AO="ao";var gR=ze(Pe,Pe.ALPHA_TEST),yR=ze(Pe,Pe.COLOR),xR=ze(Pe,Pe.SHININESS),vR=ze(Pe,Pe.EMISSIVE),CT=ze(Pe,Pe.OPACITY),bR=ze(Pe,Pe.SPECULAR),RT=ze(Pe,Pe.SPECULAR_INTENSITY),TR=ze(Pe,Pe.SPECULAR_COLOR),Fp=ze(Pe,Pe.SPECULAR_STRENGTH),O0=ze(Pe,Pe.REFLECTIVITY),SR=ze(Pe,Pe.ROUGHNESS),_R=ze(Pe,Pe.METALNESS),wR=ze(Pe,Pe.NORMAL),MR=ze(Pe,Pe.CLEARCOAT),NR=ze(Pe,Pe.CLEARCOAT_ROUGHNESS),AR=ze(Pe,Pe.CLEARCOAT_NORMAL),CR=ze(Pe,Pe.ROTATION),RR=ze(Pe,Pe.SHEEN),ER=ze(Pe,Pe.SHEEN_ROUGHNESS),PR=ze(Pe,Pe.ANISOTROPY),BR=ze(Pe,Pe.IRIDESCENCE),IR=ze(Pe,Pe.IRIDESCENCE_IOR),FR=ze(Pe,Pe.IRIDESCENCE_THICKNESS),LR=ze(Pe,Pe.TRANSMISSION),kR=ze(Pe,Pe.THICKNESS),DR=ze(Pe,Pe.IOR),OR=ze(Pe,Pe.ATTENUATION_DISTANCE),UR=ze(Pe,Pe.ATTENUATION_COLOR),ET=ze(Pe,Pe.LINE_SCALE),PT=ze(Pe,Pe.LINE_DASH_SIZE),BT=ze(Pe,Pe.LINE_GAP_SIZE),U0=ze(Pe,Pe.LINE_WIDTH),IT=ze(Pe,Pe.LINE_DASH_OFFSET),zR=ze(Pe,Pe.POINT_SIZE),VR=ze(Pe,Pe.DISPERSION),FT=ze(Pe,Pe.LIGHT_MAP),GR=ze(Pe,Pe.AO),Cd=Qe(new fe).onReference(function(e){return e.material}).onRenderUpdate(function({material:e}){this.value.set(e.anisotropy*Math.cos(e.anisotropyRotation),e.anisotropy*Math.sin(e.anisotropyRotation))}),WR=Q(e=>e.context.setupModelViewProjection(),"vec4").once()().toVarying("v_modelViewProjection"),qs=class Fh extends Ke{static get type(){return"EventNode"}constructor(t,r){super("void"),this.eventType=t,this.callback=r,t===Fh.OBJECT?this.updateType=ut.OBJECT:t===Fh.MATERIAL?this.updateType=ut.RENDER:t===Fh.FRAME?this.updateType=ut.FRAME:t===Fh.BEFORE_OBJECT?this.updateBeforeType=ut.OBJECT:t===Fh.BEFORE_MATERIAL?this.updateBeforeType=ut.RENDER:t===Fh.BEFORE_FRAME&&(this.updateBeforeType=ut.FRAME)}update(t){this.callback(t)}updateBefore(t){this.callback(t)}};qs.OBJECT="object",qs.MATERIAL="material",qs.FRAME="frame",qs.BEFORE_OBJECT="beforeObject",qs.BEFORE_MATERIAL="beforeMaterial",qs.BEFORE_FRAME="beforeFrame";var Rd=(e,t)=>new qs(e,t).toStack(),Lp=e=>Rd(qs.OBJECT,e),Cz=e=>Rd(qs.MATERIAL,e),jR=e=>Rd(qs.FRAME,e),Rz=e=>Rd(qs.BEFORE_OBJECT,e),Ez=e=>Rd(qs.BEFORE_MATERIAL,e),Pz=e=>Rd(qs.BEFORE_FRAME,e),Bz=class extends _u{static get type(){return"StorageArrayElementNode"}constructor(e,t){super(e,t),this.isStorageArrayElementNode=!0}set storageBufferNode(e){this.node=e}get storageBufferNode(){return this.node}getMemberType(e,t){let r=this.storageBufferNode.structTypeNode;return r?r.getMemberType(e,t):"void"}setup(e){return e.isAvailable("storageBuffer")===!1&&this.node.isPBO===!0&&e.setupPBO(this.node),super.setup(e)}generate(e,t){let r,i=e.isContextAssign();if(e.isAvailable("storageBuffer")===!1?this.node.isPBO===!0&&i!==!0&&(this.node.value.isInstancedBufferAttribute||e.shaderStage!=="compute")?r=e.generatePBO(this):r=this.node.build(e):r=super.generate(e),i!==!0){let s=this.getNodeType(e);r=e.format(r,s,t)}return r}},Iz=Mt(Bz).setParameterLength(2),Fz=class extends sT{static get type(){return"StorageBufferNode"}constructor(e,t=null,r=0){let i,s=null;t&&t.isStructTypeNode?(i="struct",s=t,(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute)&&(r=e.count)):t===null&&(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute)?(i=WN(e.itemSize),r=e.count):i=t,super(e,i,r),this.isStorageBufferNode=!0,this.structTypeNode=s,this.access=Fi.READ_WRITE,this.isAtomic=!1,this.isPBO=!1,this._attribute=null,this._varying=null,this.global=!0,e.isStorageBufferAttribute!==!0&&e.isStorageInstancedBufferAttribute!==!0&&(e.isInstancedBufferAttribute?e.isStorageInstancedBufferAttribute=!0:e.isStorageBufferAttribute=!0)}getHash(e){let t;if(this.bufferCount===0){let r=e.globalCache.getData(this.value);r===void 0&&(r={node:this},e.globalCache.setData(this.value,r)),t=r.node.id}else t=this.id;return String(t)}getInputType(){return this.value.isIndirectStorageBufferAttribute?"indirectStorageBuffer":"storageBuffer"}element(e){return Iz(this,e)}setPBO(e){return this.isPBO=e,this}getPBO(){return this.isPBO}setAccess(e){return this.access=e,this}toReadOnly(){return this.setAccess(Fi.READ_ONLY)}setAtomic(e){return this.isAtomic=e,this}toAtomic(){return this.setAtomic(!0)}getAttributeData(){return this._attribute===null&&(this._attribute=Jb(this.value),this._varying=pl(this._attribute)),{attribute:this._attribute,varying:this._varying}}generateNodeType(e){if(this.structTypeNode!==null)return this.structTypeNode.getNodeType(e);if(e.isAvailable("storageBuffer")||e.isAvailable("indirectStorageBuffer"))return super.generateNodeType(e);let{attribute:t}=this.getAttributeData();return t.getNodeType(e)}getMemberType(e,t){return this.structTypeNode!==null?this.structTypeNode.getMemberType(e,t):"void"}generate(e){if(this.structTypeNode!==null&&this.structTypeNode.build(e),e.isAvailable("storageBuffer")||e.isAvailable("indirectStorageBuffer"))return super.generate(e);let{attribute:t,varying:r}=this.getAttributeData(),i=r.build(e);return e.registerTransform(i,t),i}},Sl=(e,t=null,r=0)=>new Fz(e,t,r),LT=new WeakMap,HR=new WeakMap,kT=new WeakMap;function XR(e,t){let r,i=Math.max(t.count,1);if(t.isStorageInstancedBufferAttribute===!0)r=Sl(t,"mat4",i).element(Va);else if(i*16*4<=e.getUniformBufferLimit())r=Md(t.array,"mat4",i).element(Va);else{let s=LT.get(t);s||(s=new fU(t.array,16,1),LT.set(t,s));let a=t.usage===rp?Qb:T0,n=[a(s,"vec4",16,0),a(s,"vec4",16,4),a(s,"vec4",16,8),a(s,"vec4",16,12)];r=ul(...n)}return r}function Lz(e,t,r){let i=kT.get(e);if(i===void 0){let s=t.clone();i={previousInstanceMatrix:s,node:XR(r,s)},kT.set(e,i)}return i.node}var DT=Nu("vec3","vInstanceColor"),$R=Q(([e,t=null],r)=>{let i=e.isStorageInstancedBufferAttribute===!0,s=t&&t.isStorageInstancedBufferAttribute===!0,a=XR(r,e),n=null;i||Math.max(e.count,1)*16*4>r.getUniformBufferLimit()&&(n=LT.get(e));let o=null,l=null;if(t)if(s)o=Sl(t,"vec3",Math.max(t.count,1)).element(Va);else{let h=HR.get(t);h||(h=new ud(t.array,3),HR.set(t,h)),l=h;let d=t.usage===rp?Qb:T0;o=K(d(h,"vec3",3,0))}(n!==null||l!==null)&&jR(()=>{n!==null&&(n.clearUpdateRanges(),n.updateRanges.push(...e.updateRanges),e.version!==n.version&&(n.version=e.version)),t&&l!==null&&(l.clearUpdateRanges(),l.updateRanges.push(...t.updateRanges),t.version!==l.version&&(l.version=t.version))});let u=a.mul(wr).xyz;if(wr.assign(u),r.needsPreviousData()){let h=r.object;Lp(({object:c})=>{kT.get(c).previousInstanceMatrix.array.set(e.array)});let d=Lz(h,e,r);Du.assign(d.mul(Du).xyz)}if(r.hasGeometryAttribute("normal")){let h=xT(Qi,a);Qi.assign(h)}o!==null&&DT.assign(o)},"void"),qR=Q(([e])=>{let{instanceMatrix:t,instanceColor:r}=e;$R(t,r)},"void"),kz=Q(([e,t])=>{let r=Y(Fu(Gr(e),0).x).toConst(),i=Y(t),s=i.mod(r).toConst(),a=i.div(r).toConst();return Gr(e,Pr(s,a))}),Dz=Q(([e,t])=>{let r=Y(Fu(Gr(e),0).x).toConst(),i=Y(t).mod(r).toConst(),s=Y(t).div(r).toConst();return Gr(e,Pr(i,s)).x}),OT=Nu("vec4","vBatchColor"),YR=Q(([e],t)=>{let r=t.getDrawIndex()===null?Va:AC,i=Dz(e._indirectTexture,Y(r)),s=e._matricesTexture,a=Y(Fu(Gr(s),0).x).toConst(),n=D(i).mul(4).toInt().toConst(),o=n.mod(a).toConst(),l=n.div(a).toConst(),u=ul(Gr(s,Pr(o,l)),Gr(s,Pr(o.add(1),l)),Gr(s,Pr(o.add(2),l)),Gr(s,Pr(o.add(3),l))),h=e._colorsTexture;if(h!==null){let g=kz(h,i);OT.assign(g)}let d=Ni(u);wr.assign(u.mul(wr));let c=Qi.div(K(d[0].dot(d[0]),d[1].dot(d[1]),d[2].dot(d[2]))),m=d.mul(c).xyz;Qi.assign(m),t.hasGeometryAttribute("tangent")&&Tl.mulAssign(d)},"void"),z0=new WeakMap,V0=new WeakMap;function UT(e,t,r,i,s,a){let n=e.element(s.x),o=e.element(s.y),l=e.element(s.z),u=e.element(s.w),h=r.mul(t),d=Yr(n.mul(a.x).mul(h),o.mul(a.y).mul(h),l.mul(a.z).mul(h),u.mul(a.w).mul(h));return i.mul(d).xyz}function ZR(e,t,r,i,s,a,n){let o=e.element(a.x),l=e.element(a.y),u=e.element(a.z),h=e.element(a.w),d=Yr(n.x.mul(o),n.y.mul(l),n.z.mul(u),n.w.mul(h));d=s.mul(d).mul(i);let c=d.transformDirection(t).xyz,m=d.transformDirection(r).xyz;return{skinNormal:c,skinTangent:m}}function JR(e,t,r,i,s){let a=e.skeleton,n=V0.get(a);if(n===void 0){a.update();let o=new Float32Array(a.boneMatrices);n={previousBoneMatrices:o,node:Md(o,"mat4",a.bones.length)},V0.set(a,n)}return UT(n.node,Du,t,r,i,s)}var QR=Q(([e],t)=>{let r=$s("skinIndex","uvec4"),i=$s("skinWeight","vec4"),s=cr("bindMatrix","mat4"),a=cr("bindMatrixInverse","mat4"),n=tR("skeleton.boneMatrices","mat4",e.skeleton.bones.length);if(Lp(({object:l,frameId:u})=>{let h=l.skeleton;if(z0.get(h)!==u){z0.set(h,u);let d=V0.get(h);d!==void 0&&d.previousBoneMatrices.set(h.boneMatrices),h.update()}}),t.needsPreviousData()){let l=JR(e,s,a,r,i);Du.assign(l)}let o=UT(n,wr,s,a,r,i);if(wr.assign(o),t.hasGeometryAttribute("normal")){let{skinNormal:l,skinTangent:u}=ZR(n,Qi,Tl,s,a,r,i);Qi.assign(l),t.hasGeometryAttribute("tangent")&&Tl.assign(u)}},"void"),Oz=Q(([e,t=null],r)=>{let i=Sl(new ud(e.geometry.getAttribute("position").array,3),"vec3").setPBO(!0).toReadOnly().element(Va).toVar(),s=Sl(new ud(new Uint32Array(e.geometry.getAttribute("skinIndex").array),4),"uvec4").setPBO(!0).toReadOnly().element(Va).toVar(),a=Sl(new ud(e.geometry.getAttribute("skinWeight").array,4),"vec4").setPBO(!0).toReadOnly().element(Va).toVar(),n=Qe(e.bindMatrix,"mat4"),o=Qe(e.bindMatrixInverse,"mat4"),l=Md(e.skeleton.boneMatrices,"mat4",e.skeleton.bones.length),u=e.skeleton;if(Lp(({frameId:d})=>{if(z0.get(u)!==d){z0.set(u,d);let c=V0.get(u);c!==void 0&&c.previousBoneMatrices.set(u.boneMatrices),u.update()}}),r.needsPreviousData()){let d=JR(e,n,o,s,a);Du.assign(d)}let h=UT(l,i,n,o,s,a);if(t!==null&&t.assign(h),r.hasGeometryAttribute("normal")){let{skinNormal:d,skinTangent:c}=ZR(l,Qi,Tl,n,o,s,a);Qi.assign(d),r.hasGeometryAttribute("tangent")&&Tl.assign(c)}return h}),Uz=class extends Ke{static get type(){return"LoopNode"}constructor(e=[]){super("void"),this.params=e}getVarName(e){return String.fromCharCode(105+e)}getProperties(e){let t=e.getNodeProperties(this);if(t.stackNode!==void 0)return t;let r={};for(let n=0,o=this.params.length-1;nNumber(h)?m=">=":m="<"));let y;if(l)y=`while ( ${h} )`;else{let b={start:u,end:h},v=b.start,S=b.end,T,w=()=>m.includes("<")?"+=":"-=";if(g!=null)switch(typeof g){case"function":T=e.flowStagesNode(t.updateNode,"void").code.replace(/\t|;/g,"");break;case"number":T=d+" "+w()+" "+e.generateConst(c,g);break;case"string":T=d+" "+g;break;default:g.isNode?T=d+" "+w()+" "+g.build(e):(Ce("TSL: 'Loop( { update: ... } )' is not a function, string or number.",this.stackTrace),T="break /* invalid update */")}else c==="int"||c==="uint"?g=m.includes("<")?"++":"--":g=w()+" 1.",T=d+" "+g;let N=e.getVar(c,d)+" = "+v,C=d+" "+m+" "+S;y=`for ( ${N}; ${C}; ${T} )`}e.addFlowCode((a===0?` `:"")+e.tab+y+` { `).addFlowTab()}let s=i.build(e,"void");t.returnsNode.build(e,"void"),e.removeFlowTab().addFlowCode(` `+e.tab+s);for(let a=0,n=this.params.length-1;anew Uz(wu(e,"int")).toStack(),zz=()=>Xs("continue").toStack(),KR=()=>Xs("break").toStack(),zT=new WeakMap,Ys=new Wt,eE=new WeakMap,tE=Q(({bufferMap:e,influence:t,stride:r,width:i,depth:s,offset:a})=>{let n=Y(NC).mul(r).add(a),o=n.div(i),l=n.sub(o.mul(i));return Gr(e,Pr(l,o)).depth(s).xyz.mul(t)});function Vz(e){let t=e.morphAttributes.position!==void 0,r=e.morphAttributes.normal!==void 0,i=e.morphAttributes.color!==void 0,s=e.morphAttributes.position||e.morphAttributes.normal||e.morphAttributes.color,a=s!==void 0?s.length:0,n=zT.get(e);if(n===void 0||n.count!==a){let o=function(){b.dispose(),zT.delete(e),e.removeEventListener("dispose",o)};n!==void 0&&n.texture.dispose();let l=e.morphAttributes.position||[],u=e.morphAttributes.normal||[],h=e.morphAttributes.color||[],d=0;t===!0&&(d=1),r===!0&&(d=2),i===!0&&(d=3);let c=e.attributes.position.count*d,m=1,g=4096;c>g&&(m=Math.ceil(c/g),c=g);let y=new Float32Array(c*m*4*a),b=new b4(y,c,m,a);b.type=Er,b.needsUpdate=!0;let v=d*4;for(let S=0;S{let{geometry:t}=e,r=t.morphAttributes.position!==void 0,i=t.hasAttribute("normal")&&t.morphAttributes.normal!==void 0,s=t.morphAttributes.position||t.morphAttributes.normal||t.morphAttributes.color,a=s!==void 0?s.length:0;if(a===0)return;let n=eE.get(e);(n===void 0||n.count!==a)&&(n={base:Qe(1),influences:e.morphTargetInfluences?Li(e.morphTargetInfluences,"float"):null,count:a},eE.set(e,n));let{base:o,influences:l}=n,{texture:u,stride:h,size:d}=Vz(t);r===!0&&wr.mulAssign(o),i===!0&&Qi.mulAssign(o);let c=Y(d.width);Qt(a,({i:m})=>{let g=D(0).toVar();e.count>1&&e.morphTexture!==null&&e.morphTexture!==void 0?g.assign(Gr(e.morphTexture,Pr(Y(m).add(1),Y(Va))).r):g.assign(l.element(m).toVar()),et(g.notEqual(0),()=>{r===!0&&wr.addAssign(tE({bufferMap:u,influence:g,stride:h,width:c,depth:m,offset:Y(0)})),i===!0&&Qi.addAssign(tE({bufferMap:u,influence:g,stride:h,width:c,depth:m,offset:Y(1)}))})}),Lp(({object:m})=>{let{base:g,influences:y}=n;m.geometry.morphTargetsRelative?g.value=1:g.value=1-m.morphTargetInfluences.reduce((b,v)=>b+v,0),y&&(y.array=m.morphTargetInfluences,y.update())})},"void"),Ed=class extends Ke{static get type(){return"LightingNode"}constructor(){super("vec3"),this.isLightingNode=!0}},Gz=class extends Ed{static get type(){return"AONode"}constructor(e=null){super(),this.aoNode=e}setup(e){e.context.ambientOcclusion.mulAssign(this.aoNode)}},Wz=class extends Xb{static get type(){return"LightingContextNode"}constructor(e,t=null,r=[],i=null,s=null){super(e),this.lightingModel=t,this.materialLightings=r,this.backdropNode=i,this.backdropAlphaNode=s,this._value=null}getContext(){let{materialLightings:e,backdropNode:t,backdropAlphaNode:r}=this,i=K().toVar("directDiffuse"),s=K().toVar("directSpecular"),a=K().toVar("indirectDiffuse"),n=K().toVar("indirectSpecular"),o={directDiffuse:i,directSpecular:s,indirectDiffuse:a,indirectSpecular:n};return{radiance:K().toVar("radiance"),irradiance:K().toVar("irradiance"),iblIrradiance:K().toVar("iblIrradiance"),ambientOcclusion:D(1).toVar("ambientOcclusion"),reflectedLight:o,materialLightings:e,backdrop:t,backdropAlpha:r}}setup(e){return this.value=this._value||(this._value=this.getContext()),this.value.lightingModel=this.lightingModel||e.context.lightingModel,super.setup(e)}},iE=Mt(Wz),jz=class extends Ed{static get type(){return"IrradianceNode"}constructor(e){super(),this.node=e}setup(e){e.context.irradiance.addAssign(this.node)}},zu=new fe,G0=class extends An{static get type(){return"ViewportTextureNode"}constructor(e=Ga,t=null,r=null){let i=null;r===null?(i=new Gv,i.minFilter=Ia,r=i):i=r,super(r,e,t),this.generateMipmaps=!1,this.defaultFramebuffer=i,this.isOutputTextureNode=!0,this.updateBeforeType=ut.RENDER,this._cacheTextures=new WeakMap}getTextureForReference(e=null){let t,r;if(this.referenceNode?(t=this.referenceNode.defaultFramebuffer,r=this.referenceNode._cacheTextures):(t=this.defaultFramebuffer,r=this._cacheTextures),e===null)return t;if(r.has(e)===!1){let i=t.clone();r.set(e,i)}return r.get(e)}updateReference(e){let t=e.renderer,r=t.getRenderTarget(),i=t.getCanvasTarget(),s=r||i;return this.value=this.getTextureForReference(s),this.value}updateBefore(e){let t=e.renderer,r=t.getRenderTarget(),i=t.getCanvasTarget(),s=r||i;s===null?t.getDrawingBufferSize(zu):s.getDrawingBufferSize?s.getDrawingBufferSize(zu):zu.set(s.width,s.height);let a=this.getTextureForReference(s);(a.image.width!==zu.width||a.image.height!==zu.height)&&(a.image.width=zu.width,a.image.height=zu.height,a.needsUpdate=!0);let n=a.generateMipmaps;a.generateMipmaps=this.generateMipmaps,t.copyFramebufferToTexture(a),a.generateMipmaps=n}clone(){let e=new this.constructor(this.uvNode,this.levelNode,this.value);return e.generateMipmaps=this.generateMipmaps,e}},Hz=Mt(G0).setParameterLength(0,3),VT=Mt(G0,null,null,{generateMipmaps:!0}).setParameterLength(0,3),Xz=VT(),sE=(e=Ga,t=null)=>Xz.sample(e,t),GT=null,$z=class extends G0{static get type(){return"ViewportDepthTextureNode"}constructor(e=Ga,t=null,r=null){r===null&&(GT===null&&(GT=new fs),r=GT),super(e,t,r)}},WT=Mt($z).setParameterLength(0,3),So=class Mf extends Ke{static get type(){return"ViewportDepthNode"}constructor(t,r=null){super("float"),this.scope=t,this.valueNode=r,this.isViewportDepthNode=!0}generate(t){let{scope:r}=this;return r===Mf.DEPTH_BASE?t.getFragDepth():super.generate(t)}setup({camera:t}){let{scope:r}=this,i=this.valueNode,s=null;if(r===Mf.DEPTH_BASE)i!==null&&(s=oE().assign(i));else if(r===Mf.DEPTH)t.isPerspectiveCamera?s=jT(Wr.z,gl,yl):s=Vu(Wr.z,gl,yl);else if(r===Mf.LINEAR_DEPTH)if(i!==null)if(t.isPerspectiveCamera){let a=W0(i,gl,yl);s=Vu(a,gl,yl)}else s=i;else s=Vu(Wr.z,gl,yl);return s}};So.DEPTH_BASE="depthBase",So.DEPTH="depth",So.LINEAR_DEPTH="linearDepth";var Vu=(e,t,r)=>e.add(t).div(t.sub(r)),qz=(e,t,r)=>e.add(r).div(r.sub(t)),aE=Q(([e,t,r],i)=>i.renderer.reversedDepthBuffer===!0?r.sub(t).mul(e).sub(r):t.sub(r).mul(e).sub(t)),jT=(e,t,r)=>t.add(e).mul(r).div(r.sub(t).mul(e)),nE=(e,t,r)=>t.mul(e.add(r)).div(e.mul(t.sub(r))),W0=Q(([e,t,r],i)=>i.renderer.reversedDepthBuffer===!0?t.mul(r).div(t.sub(r).mul(e).sub(t)):t.mul(r).div(r.sub(t).mul(e).sub(r))),j0=(e,t,r)=>{t=t.max(1e-6).toVar();let i=wn(e.negate().div(t)),s=wn(r.div(t));return i.div(s)},Yz=(e,t,r)=>{let i=e.mul(f0(r.div(t)));return D(Math.E).pow(i).mul(t).negate()},oE=Mt(So,So.DEPTH_BASE),HT=ze(So,So.DEPTH),H0=Mt(So,So.LINEAR_DEPTH).setParameterLength(0,1),Zz=H0(WT());HT.assign=e=>oE(e);var _l=class Jx extends Ke{static get type(){return"ClippingNode"}constructor(t=Jx.DEFAULT){super(),this.scope=t}setup(t){super.setup(t);let r=t.clippingContext,{intersectionPlanes:i,unionPlanes:s}=r;return this.hardwareClipping=t.hardwareClipping,this.scope===Jx.ALPHA_TO_COVERAGE?this.setupAlphaToCoverage(i,s):this.scope===Jx.HARDWARE?this.setupHardwareClipping(s,t):this.setupDefault(i,s)}setupAlphaToCoverage(t,r){return Q(()=>{let i=D().toVar("distanceToPlane"),s=D().toVar("distanceToGradient"),a=D(1).toVar("clipOpacity"),n=r.length;if(this.hardwareClipping===!1&&n>0){let l=Li(r).setGroup(st);Qt(n,({i:u})=>{let h=l.element(u);i.assign(Wr.dot(h.xyz).negate().add(h.w)),s.assign(i.fwidth().div(2)),a.mulAssign(Hs(s.negate(),s,i))})}let o=t.length;if(o>0){let l=Li(t).setGroup(st),u=D(1).toVar("intersectionClipOpacity");Qt(o,({i:h})=>{let d=l.element(h);i.assign(Wr.dot(d.xyz).negate().add(d.w)),s.assign(i.fwidth().div(2)),u.mulAssign(Hs(s.negate(),s,i).oneMinus())}),a.mulAssign(u.oneMinus())}Zt.a.mulAssign(a),Zt.a.equal(0).discard()})()}setupDefault(t,r){return Q(()=>{let i=r.length;if(this.hardwareClipping===!1&&i>0){let a=Li(r).setGroup(st);Qt(i,({i:n})=>{let o=a.element(n);Wr.dot(o.xyz).greaterThan(o.w).discard()})}let s=t.length;if(s>0){let a=Li(t).setGroup(st),n=Gs(!0).toVar("clipped");Qt(s,({i:o})=>{let l=a.element(o);n.assign(Wr.dot(l.xyz).greaterThan(l.w).and(n))}),n.discard()}})()}setupHardwareClipping(t,r){let i=t.length;return r.enableHardwareClipping(i),Q(()=>{let s=Li(t).setGroup(st),a=bo(r.getClipDistance());Qt(i,({i:n})=>{let o=s.element(n),l=Wr.dot(o.xyz).sub(o.w).negate();a.element(n).assign(l)})})()}};_l.ALPHA_TO_COVERAGE="alphaToCoverage",_l.DEFAULT="default",_l.HARDWARE="hardware";var Jz=()=>new _l,Qz=()=>new _l(_l.ALPHA_TO_COVERAGE),Kz=()=>new _l(_l.HARDWARE),eV=.05,lE=Q(([e])=>Oa(mt(1e4,xs(mt(17,e.x).add(mt(.1,e.y)))).mul(Yr(.1,ur(xs(mt(13,e.y).add(e.x))))))),uE=Q(([e])=>lE(ke(lE(e.xy),e.z))),tV=Q(([e])=>{let t=Br(Nn(Db(e.xyz)),Nn(Ob(e.xyz))),r=D(1).div(D(eV).mul(t)).toVar("pixScale"),i=ke(_d(Mn(wn(r))),_d(g0(wn(r)))),s=ke(uE(Mn(i.x.mul(e.xyz))),uE(Mn(i.y.mul(e.xyz)))),a=Oa(wn(r)),n=Yr(mt(a.oneMinus(),s.x),mt(a,s.y)),o=Rs(a,a.oneMinus()),l=K(n.mul(n).div(mt(2,o).mul(It(1,o))),n.sub(mt(.5,o)).div(It(1,o)),It(1,It(1,n).mul(It(1,n)).div(mt(2,o).mul(It(1,o))))),u=n.lessThan(o.oneMinus()).select(n.lessThan(o).select(l.x,l.y),l.z);return za(u,1e-6,1)}).setLayout({name:"getAlphaHashThreshold",type:"float",inputs:[{name:"position",type:"vec3"}]}),rV=class extends DC{static get type(){return"VertexColorNode"}constructor(e){super(null,"vec4"),this.isVertexColorNode=!0,this.index=e}getAttributeName(){let e=this.index;return"color"+(e>0?e:"")}generate(e){let t=this.getAttributeName(e),r=e.hasGeometryAttribute(t),i;return r===!0?i=super.generate(e):i=e.generateConst(this.nodeType,new Wt(1,1,1,1)),i}serialize(e){super.serialize(e),e.index=this.index}deserialize(e){super.deserialize(e),this.index=e.index}},hE=(e=0)=>new rV(e),Pt=class extends Vs{static get type(){return"NodeMaterial"}get type(){return this.constructor.type}set type(e){}constructor(){super(),this.isNodeMaterial=!0,this.fog=!0,this.lights=!1,this.lightsNode=null,this.envNode=null,this.aoNode=null,this.colorNode=null,this.normalNode=null,this.opacityNode=null,this.backdropNode=null,this.backdropAlphaNode=null,this.alphaTestNode=null,this.maskNode=null,this.maskShadowNode=null,this.positionNode=null,this.geometryNode=null,this.depthNode=null,this.receivedShadowPositionNode=null,this.castShadowPositionNode=null,this.receivedShadowNode=null,this.castShadowNode=null,this.outputNode=null,this.mrtNode=null,this.fragmentNode=null,this.vertexNode=null,this.contextNode=null}_getNodeChildren(){let e=[];for(let t of Object.getOwnPropertyNames(this)){if(t.startsWith("_")===!0)continue;let r=this[t];r&&r.isNode===!0&&e.push({property:t,childNode:r})}return e}customProgramCacheKey(){let e=[];for(let{property:t,childNode:r}of this._getNodeChildren())e.push(yd(t.slice(0,-4)),r.getCacheKey());return this.type+Sp(e)}build(e){this.setup(e)}setupObserver(e){return new SU(e)}setup(e){e.context.setupNormal=()=>Iu(this.setupNormal(e),"NORMAL","vec3"),e.context.setupPositionView=()=>this.setupPositionView(e),e.context.setupModelViewProjection=()=>this.setupModelViewProjection(e);let t=e.renderer,r=t.getRenderTarget();e.addStack();let i=this.setupVertex(e),s=Iu(this.vertexNode||i,"VERTEX");e.context.clipSpace=s,e.stack.outputNode=s,this.setupHardwareClipping(e),this.geometryNode!==null&&(e.stack.outputNode=e.stack.outputNode.bypass(this.geometryNode)),e.addFlow("vertex",e.removeStack()),e.addStack();let a,n=this.setupClipping(e);if((this.depthWrite===!0||this.depthTest===!0)&&(r!==null?r.depthBuffer===!0&&this.setupDepth(e):t.depth===!0&&this.setupDepth(e)),this.fragmentNode===null){this.setupDiffuseColor(e),this.setupAmbientOcclusion(e),this.setupVariants(e);let o=this.setupLighting(e);n!==null&&e.stack.addToStack(n);let l=Ve(o,Zt.a).max(0);a=this.setupOutput(e,l),Sd.assign(a);let u=this.outputNode!==null;if(u&&(a=this.outputNode),e.context.getOutput&&(a=e.context.getOutput(a,e)),r!==null){let h=t.getMRT(),d=this.mrtNode;h!==null?(u&&Sd.assign(a),a=h,d!==null&&(a=h.merge(d))):d!==null&&(a=d)}}else{let o=this.fragmentNode;o.isOutputStructNode!==!0&&(o=o.convert(e.getOutputType())),a=this.setupOutput(e,o)}e.stack.outputNode=a,e.addFlow("fragment",e.removeStack()),e.observer=this.setupObserver(e)}setupClipping(e){if(e.clippingContext===null)return null;let{unionPlanes:t,intersectionPlanes:r}=e.clippingContext,i=null;if(t.length>0||r.length>0){let s=e.renderer.currentSamples;this.alphaToCoverage&&s>1?i=Qz():e.stack.addToStack(Jz())}return i}setupHardwareClipping(e){if(e.hardwareClipping=!1,e.clippingContext===null)return;let t=e.clippingContext.unionPlanes.length;t>0&&t<=8&&e.isAvailable("clipDistance")&&(e.stack.addToStack(Kz()),e.hardwareClipping=!0)}setupDepth(e){let{renderer:t,camera:r}=e,i=this.depthNode;if(i===null){let s=t.getMRT();s&&s.has("depth")?i=s.get("depth"):t.logarithmicDepthBuffer===!0&&(r.isPerspectiveCamera?i=j0(Wr.z,gl,yl):i=Vu(Wr.z,gl,yl))}i!==null&&HT.assign(i).toStack()}setupPositionView(){return Cn.mul(wr).xyz}setupModelViewProjection(){return bs.mul(Wr)}setupVertex(e){return e.addStack(),this.setupPosition(e),e.context.position=e.removeStack(),WR}setupPosition(e){let{object:t,geometry:r}=e;if((r.morphAttributes.position||r.morphAttributes.normal||r.morphAttributes.color)&&rE(t),t.isSkinnedMesh===!0&&QR(t),this.displacementMap){let i=To("displacementMap","texture"),s=To("displacementScale","float"),a=To("displacementBias","float");wr.addAssign(Qi.normalize().mul(i.x.mul(s).add(a)))}return t.isBatchedMesh&&YR(t),t.isInstancedMesh&&t.instanceMatrix&&t.instanceMatrix.isInstancedBufferAttribute===!0&&qR(t),this.positionNode!==null&&wr.assign(Iu(this.positionNode,"POSITION","vec3")),wr}setupDiffuseColor(e){let{object:t,geometry:r}=e;this.maskNode!==null&&Gs(this.maskNode).not().discard();let i=this.colorNode?Ve(this.colorNode):yR;this.vertexColors===!0&&r.hasAttribute("color")&&(i=i.mul(hE())),t.instanceColor&&(i=DT.mul(i)),t.isBatchedMesh&&t._colorsTexture&&(i=OT.mul(i)),Zt.assign(i);let s=this.opacityNode?D(this.opacityNode):CT;Zt.a.assign(Zt.a.mul(s));let a=null;(this.alphaTestNode!==null||this.alphaTest>0)&&(a=this.alphaTestNode!==null?D(this.alphaTestNode):gR,this.alphaToCoverage===!0?(Zt.a=Hs(a,a.add(zb(Zt.a)),Zt.a),Zt.a.lessThanEqual(0).discard()):Zt.a.lessThanEqual(a).discard()),this.alphaHash===!0&&Zt.a.lessThan(tV(wr)).discard(),e.isOpaque()&&Zt.a.assign(1)}setupVariants(){}setupOutgoingLight(){return this.lights===!0?K(0):Zt.rgb}setupNormal(){return this.normalNode?K(this.normalNode):wR}setupEnvironment(){let e=null;return this.envNode?e=this.envNode:this.envMap&&(e=this.envMap.isCubeTexture?To("envMap","cubeTexture"):To("envMap","texture")),e}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new jz(FT)),t}setupMaterialLightings(e){let t=[];if(e.renderer.lighting.enabled===!1)return t;let r=this.setupEnvironment(e);r&&r.isLightingNode&&t.push(r);let i=this.setupLightMap(e);return i&&i.isLightingNode&&t.push(i),e.context.ambientOcclusion&&t.push(new Gz(e.context.ambientOcclusion)),t}setupAmbientOcclusion(e){let t=this.aoNode;t===null&&e.material.aoMap&&(t=GR),e.context.getAO&&(t=e.context.getAO(t,e)),t!==null&&(Rb.assign(t),e.context.ambientOcclusion=Rb)}setupLightingModel(){}setupLighting(e){let{material:t}=e,{backdropNode:r,backdropAlphaNode:i,emissiveNode:s}=this,a=this.lights===!0||this.lightsNode!==null,n=this.lights===!0?this.setupMaterialLightings(e):[],o=a?this.lightsNode||e.lightsNode:null,l=this.setupOutgoingLight(e);if(o&&(n.length>0||o.getScope().hasLights)){let u=this.setupLightingModel(e)||null;l=iE(o,u,n,r,i)}else r!==null&&(l=K(i!==null?Ct(l,r,i):r));return(s&&s.isNode===!0||t.emissive&&t.emissive.isColor===!0)&&(wb.assign(K(s||vR)),l=l.add(wb)),l}setupFog(e,t){let r=e.fogNode;return r&&(Sd.assign(t),t=Ve(r.toVar())),t}setupPremultipliedAlpha(e,t){return tT(t)}setupOutput(e,t){return this.fog===!0&&(t=this.setupFog(e,t)),this.premultipliedAlpha===!0&&(t=this.setupPremultipliedAlpha(e,t)),t}setDefaultValues(e){for(let r in e){let i=e[r];this[r]===void 0&&(this[r]=i,i&&i.clone&&(this[r]=i.clone()))}let t=Object.getOwnPropertyDescriptors(e.constructor.prototype);for(let r in t)Object.getOwnPropertyDescriptor(this.constructor.prototype,r)===void 0&&t[r].get!==void 0&&Object.defineProperty(this.constructor.prototype,r,t[r])}toJSON(e){let t=e===void 0||typeof e=="string";t&&(e={textures:{},images:{},nodes:{}});let r=Vs.prototype.toJSON.call(this,e);r.inputNodes={};for(let{property:s,childNode:a}of this._getNodeChildren())r.inputNodes[s]=a.toJSON(e).uuid;function i(s){let a=[];for(let n in s){let o=s[n];delete o.metadata,a.push(o)}return a}if(t){let s=i(e.textures),a=i(e.images),n=i(e.nodes);s.length>0&&(r.textures=s),a.length>0&&(r.images=a),n.length>0&&(r.nodes=n)}return r}copy(e){let t=Object.getOwnPropertyDescriptors(this.constructor.prototype);for(let r in t)if(t[r].set!==void 0&&e[r]!==void 0){let i=e[r];this[r]&&this[r].copy!==void 0?this[r].copy(i):this[r]=i}for(let r in this)if(!/^(?:is[A-Z]|_)|^(?:id|uuid|version|type|userData|clippingPlanes)$/.test(r)&&this[r]!==void 0&&e[r]!==void 0){let i=e[r];this[r]&&this[r].copy!==void 0?this[r].copy(i):this[r]=i}return this.clippingPlanes=e.clippingPlanes?e.clippingPlanes.map(r=>r.clone()):null,this.userData=JSON.parse(JSON.stringify(e.userData)),this}},iV=new hN,sV=class extends Pt{static get type(){return"LineBasicNodeMaterial"}constructor(e){super(),this.isLineBasicNodeMaterial=!0,this.setDefaultValues(iV),this.setValues(e)}},aV=new LO,nV=class extends Pt{static get type(){return"LineDashedNodeMaterial"}constructor(e){super(),this.isLineDashedNodeMaterial=!0,this.setDefaultValues(aV),this.dashOffset=0,this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(e)}setupVariants(){let e=this.offsetNode?D(this.offsetNode):IT,t=this.dashScaleNode?D(this.dashScaleNode):ET,r=this.dashSizeNode?D(this.dashSizeNode):PT,i=this.gapSizeNode?D(this.gapSizeNode):BT;Pu.assign(r),Cp.assign(i);let s=pl($s("lineDistance").mul(t));(e?s.add(e):s).mod(Pu.add(Cp)).greaterThan(Pu).discard()}},X0=Nu("vec3","worldStart"),XT=Nu("vec3","worldEnd"),dE=Nu("float","lineDistance"),Gu=Nu("vec4","worldPos"),cE=Q(({start:e,end:t})=>{let r=bs.element(2).element(2),i=bs.element(3).element(2);return r.greaterThan(0).select(i.negate().div(r.add(1)),i.mul(-.5).div(r)).sub(e.z).div(t.z.sub(e.z))},{start:"vec4",end:"vec4",return:"float"}),oV=Q(({p1:e,p2:t,p3:r,p4:i})=>{let s=e.sub(r),a=i.sub(r),n=t.sub(e),o=s.dot(a),l=a.dot(n),u=s.dot(n),h=a.dot(a),d=n.dot(n).mul(h).sub(l.mul(l)),c=o.mul(l).sub(u.mul(h)).div(d).clamp(),m=o.add(l.mul(c)).div(h).clamp();return ke(c,m)},{p1:"vec3",p2:"vec3",p3:"vec3",p4:"vec3",return:"vec2"}),w0e=Q(({material:e})=>{let t=e._useDash,r=e._useWorldUnits,i=$s("instanceStart"),s=$s("instanceEnd"),a=Ve(Cn.mul(Ve(i,1))).toVar("start"),n=Ve(Cn.mul(Ve(s,1))).toVar("end"),o,l;t&&(o=D($s("instanceDistanceStart")).toVar("distanceStart"),l=D($s("instanceDistanceEnd")).toVar("distanceEnd")),r&&(X0.assign(a.xyz),XT.assign(n.xyz));let u=Nd.z.div(Nd.w),h=bs.element(2).element(3).equal(-1);if(et(h,()=>{et(a.z.lessThan(0).and(n.z.greaterThan(0)),()=>{let v=cE({start:a,end:n});n.assign(Ve(Ct(a.xyz,n.xyz,v),n.w)),t&&l.assign(Ct(o,l,v))}).ElseIf(n.z.lessThan(0).and(a.z.greaterThanEqual(0)),()=>{let v=cE({start:n,end:a});a.assign(Ve(Ct(n.xyz,a.xyz,v),a.w)),t&&o.assign(Ct(l,o,v))})}),t){let v=e.dashScaleNode?D(e.dashScaleNode):ET,S=e.offsetNode?D(e.offsetNode):IT,T=Ji.y.lessThan(.5).select(v.mul(o),v.mul(l));T=T.add(S),dE.assign(T)}let d=bs.mul(a),c=bs.mul(n),m=d.xyz.div(d.w),g=c.xyz.div(c.w),y=g.xy.sub(m.xy).toVar();y.x.assign(y.x.mul(u)),y.assign(y.normalize());let b=Ve().toVar();if(r){let v=n.xyz.sub(a.xyz).normalize(),S=Ct(a.xyz,n.xyz,.5).normalize(),T=v.cross(S).normalize(),w=v.cross(T);Gu.assign(Ji.y.lessThan(.5).select(a,n));let N=U0.mul(.5);Gu.addAssign(Ve(Ji.x.lessThan(0).select(T.mul(N),T.mul(N).negate()),0)),t||(Gu.addAssign(Ve(Ji.y.lessThan(.5).select(v.mul(N).negate(),v.mul(N)),0)),Gu.addAssign(Ve(w.mul(N),0)),et(Ji.y.greaterThan(1).or(Ji.y.lessThan(0)),()=>{Gu.subAssign(Ve(w.mul(2).mul(N),0))})),b.assign(bs.mul(Gu));let C=K().toVar();C.assign(Ji.y.lessThan(.5).select(m,g)),b.z.assign(C.z.mul(b.w))}else{let v=ke(y.y,y.x.negate()).toVar("offset");y.x.assign(y.x.div(u)),v.x.assign(v.x.div(u)),v.assign(Ji.x.lessThan(0).select(v.negate(),v)),et(Ji.y.lessThan(0),()=>{v.assign(v.sub(y))}).ElseIf(Ji.y.greaterThan(1),()=>{v.assign(v.add(y))}),v.assign(v.mul(U0)),v.assign(v.div(Nd.w.div(aT))),b.assign(Ji.y.lessThan(.5).select(d,c)),v.assign(v.mul(b.w)),b.assign(b.add(Ve(v,0,0)))}return b})(),M0e=Q(({material:e,renderer:t})=>{let r=e._useAlphaToCoverage,i=e._useDash,s=e._useWorldUnits,a=Jt();if(i){let o=e.dashSizeNode?D(e.dashSizeNode):PT,l=e.gapSizeNode?D(e.gapSizeNode):BT;Pu.assign(o),Cp.assign(l),a.y.lessThan(-1).or(a.y.greaterThan(1)).discard(),dE.mod(Pu.add(Cp)).greaterThan(Pu).discard()}let n=D(1).toVar("alpha");if(s){let o=Gu.xyz.normalize().mul(1e5),l=XT.sub(X0),u=oV({p1:X0,p2:XT,p3:K(0,0,0),p4:o}),h=X0.add(l.mul(u.x)),d=o.mul(u.y),c=h.sub(d).length().div(U0);if(!i)if(r&&t.currentSamples>0){let m=c.fwidth();n.assign(Hs(m.negate().add(.5),m.add(.5),c).oneMinus())}else c.greaterThan(.5).discard()}else if(r&&t.currentSamples>0){let o=a.x,l=a.y.greaterThan(0).select(a.y.sub(1),a.y.add(1)),u=o.mul(o).add(l.mul(l)),h=D(u.fwidth()).toVar("dlen");et(a.y.abs().greaterThan(1),()=>{n.assign(Hs(h.oneMinus(),h.add(1),u).oneMinus())})}else et(a.y.abs().greaterThan(1),()=>{let o=a.x,l=a.y.greaterThan(0).select(a.y.sub(1),a.y.add(1));o.mul(o).add(l.mul(l)).greaterThan(1).discard()});return n})(),lV=new BO,uV=class extends Pt{static get type(){return"MeshNormalNodeMaterial"}constructor(e){super(),this.isMeshNormalNodeMaterial=!0,this.setDefaultValues(lV),this.setValues(e)}setupDiffuseColor(){let e=this.opacityNode?D(this.opacityNode):CT;Zt.assign(v0(Ve(wT(Ut),e),ds))}},$T=Q(([e=gT])=>{let t=e.z.atan(e.x).mul(1/(Math.PI*2)).add(.5),r=e.y.clamp(-1,1).asin().mul(1/Math.PI).add(.5);return ke(t,r)}),qT=Q(([e=Jt()])=>{let t=e.x.sub(.5).mul(Math.PI*2),r=e.y.sub(.5).mul(Math.PI),i=r.cos(),s=i.mul(t.cos()),a=r.sin(),n=i.mul(t.sin());return K(s,a,n)}),pE=class extends er{constructor(e=1,t={}){super(e,e,t),this.isCubeRenderTarget=!0;let r={width:e,height:e,depth:1},i=[r,r,r,r,r,r];this.texture=new Ug(i),this._setTextureOptions(t),this.texture.isRenderTargetTexture=!0}fromEquirectangularTexture(e,t){let r=t.minFilter,i=t.generateMipmaps;t.generateMipmaps=!0,this.texture.type=t.type,this.texture.colorSpace=t.colorSpace,this.texture.generateMipmaps=t.generateMipmaps,this.texture.minFilter=t.minFilter,this.texture.magFilter=t.magFilter;let s=new Wv(5,5,5),a=$T(gT),n=new Pt;n.colorNode=Ot(t,a,0),n.side=ii,n.blending=Kn;let o=new Mi(s,n),l=new bg;l.add(o),t.minFilter===Ia&&(t.minFilter=lr);let u=new sU(1,10,this),h=e.getMRT();return e.setMRT(null),u.update(e,l),e.setMRT(h),t.minFilter=r,t.generateMipmaps=i,o.geometry.dispose(),o.material.dispose(),this}clear(e,t=!0,r=!0,i=!0){let s=e.getRenderTarget();for(let a=0;a<6;a++)e.setRenderTarget(this,a),e.clear(t,r,i);e.setRenderTarget(s)}},kp=new WeakMap,hV=class extends rr{static get type(){return"CubeMapNode"}constructor(e){super("vec3"),this.envNode=e,this._cubeTexture=null,this._cubeTextureNode=Ts(null);let t=new Ug;t.isRenderTargetTexture=!0,this._defaultTexture=t,this.updateBeforeType=ut.RENDER}updateBefore(e){let{renderer:t,material:r}=e,i=this.envNode;if(i.isTextureNode||i.isMaterialReferenceNode){let s=i.isTextureNode?i.value:r[i.property];if(s&&s.isTexture){let a=s.mapping;if(a===kf||a===iv){if(kp.has(s)){let n=kp.get(s);fE(n,s.mapping),this._cubeTexture=n}else{let n=s.image;if(dV(n)){let o=new pE(n.height);o.fromEquirectangularTexture(t,s),fE(o.texture,s.mapping),this._cubeTexture=o.texture,kp.set(s,o.texture),s.addEventListener("dispose",mE)}else this._cubeTexture=this._defaultTexture}this._cubeTextureNode.value=this._cubeTexture}else this._cubeTextureNode=this.envNode}}}setup(e){return this.updateBefore(e),this._cubeTextureNode}};function dV(e){return e==null?!1:e.height>0}function mE(e){let t=e.target;t.removeEventListener("dispose",mE);let r=kp.get(t);r!==void 0&&(kp.delete(t),r.dispose())}function fE(e,t){t===kf?e.mapping=Vh:t===iv&&(e.mapping=Lf)}var gE=Mt(hV).setParameterLength(1),YT=class extends Ed{static get type(){return"BasicEnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){e.context.environment=gE(this.envNode)}},cV=class extends Ed{static get type(){return"BasicLightMapNode"}constructor(e=null){super(),this.lightMapNode=e}setup(e){let t=D(1/Math.PI);e.context.irradianceLightMap=this.lightMapNode.mul(t)}},$0=class{start(e){e.lightsNode.setupLights(e,e.lightsNode.getLightNodes(e)),this.indirect(e)}finish(){}direct(){}directRectArea(){}indirect(){}ambientOcclusion(){}},yE=class extends $0{constructor(){super()}indirect({context:e}){let t=e.ambientOcclusion,r=e.reflectedLight,i=e.irradianceLightMap;r.indirectDiffuse.assign(Ve(0)),i?r.indirectDiffuse.addAssign(i):r.indirectDiffuse.addAssign(Ve(1,1,1,0)),r.indirectDiffuse.mulAssign(t),r.indirectDiffuse.mulAssign(Zt.rgb)}finish(e){let{material:t,context:r}=e,i=r.outgoingLight,s=e.context.environment;if(s)switch(t.combine){case Ff:i.rgb.assign(Ct(i.rgb,i.rgb.mul(s.rgb),Fp.mul(O0)));break;case AD:i.rgb.assign(Ct(i.rgb,s.rgb,Fp.mul(O0)));break;case CD:i.rgb.addAssign(s.rgb.mul(Fp.mul(O0)));break;default:Ue("BasicLightingModel: Unsupported .combine value:",t.combine);break}}},pV=new mn,Pd=class extends Pt{static get type(){return"MeshBasicNodeMaterial"}constructor(e){super(),this.isMeshBasicNodeMaterial=!0,this.lights=!0,this.setDefaultValues(pV),this.setValues(e)}setupNormal(){return Ou(Ad)}setupEnvironment(e){let t=super.setupEnvironment(e);return t?new YT(t):null}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new cV(FT)),t}setupOutgoingLight(){return Zt.rgb}setupLightingModel(){return new yE}},Bd=Q(({f0:e,f90:t,dotVH:r})=>{let i=r.mul(-5.55473).sub(6.98316).mul(r).exp2();return e.mul(i.oneMinus()).add(t.mul(i))}),Wu=Q(e=>e.diffuseColor.mul(1/Math.PI)),mV=()=>D(.25),fV=Q(({dotNH:e})=>u0.mul(D(.5)).add(1).mul(D(1/Math.PI)).mul(e.pow(u0))),gV=Q(({lightDirection:e})=>{let t=e.add(ar).normalize(),r=Ut.dot(t).clamp(),i=ar.dot(t).clamp(),s=Bd({f0:cl,f90:1,dotVH:i}),a=mV(),n=fV({dotNH:r});return s.mul(a).mul(n)}),xE=class extends yE{constructor(e=!0){super(),this.specular=e}direct({lightDirection:e,lightColor:t,reflectedLight:r}){let i=Ut.dot(e).clamp().mul(t);r.directDiffuse.addAssign(i.mul(Wu({diffuseColor:Zt.rgb}))),this.specular===!0&&r.directSpecular.addAssign(i.mul(gV({lightDirection:e})).mul(Fp))}indirect(e){let{ambientOcclusion:t,irradiance:r,reflectedLight:i}=e.context;i.indirectDiffuse.addAssign(r.mul(Wu({diffuseColor:Zt}))),i.indirectDiffuse.mulAssign(t)}},yV=new IO,xV=class extends Pt{static get type(){return"MeshLambertNodeMaterial"}constructor(e){super(),this.isMeshLambertNodeMaterial=!0,this.lights=!0,this.setDefaultValues(yV),this.setValues(e)}setupEnvironment(e){let t=super.setupEnvironment(e);return t?new YT(t):null}setupLightingModel(){return new xE(!1)}},vV=new EO,bV=class extends Pt{static get type(){return"MeshPhongNodeMaterial"}constructor(e){super(),this.isMeshPhongNodeMaterial=!0,this.lights=!0,this.shininessNode=null,this.specularNode=null,this.setDefaultValues(vV),this.setValues(e)}setupEnvironment(e){let t=super.setupEnvironment(e);return t?new YT(t):null}setupLightingModel(){return new xE}setupVariants(){let e=(this.shininessNode?D(this.shininessNode):xR).max(1e-4);u0.assign(e);let t=this.specularNode||bR;cl.assign(t)}},vE=Q(e=>{if(e.geometry.hasAttribute("normal")===!1)return D(0);let t=Ad.dFdx().abs().max(Ad.dFdy().abs());return t.x.max(t.y).max(t.z)}),ZT=Q(e=>{let{roughness:t}=e,r=vE(),i=t.max(.0525);return i=i.add(r),i=i.min(1),i}),bE=Q(({alpha:e,dotNL:t,dotNV:r})=>{let i=e.pow2(),s=t.mul(i.add(i.oneMinus().mul(r.pow2())).sqrt()),a=r.mul(i.add(i.oneMinus().mul(t.pow2())).sqrt());return js(.5,s.add(a).max(p0))}).setLayout({name:"V_GGX_SmithCorrelated",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNL",type:"float"},{name:"dotNV",type:"float"}]}),TV=Q(({alphaT:e,alphaB:t,dotTV:r,dotBV:i,dotTL:s,dotBL:a,dotNV:n,dotNL:o})=>{let l=o.mul(K(e.mul(r),t.mul(i),n).length()),u=n.mul(K(e.mul(s),t.mul(a),o).length());return js(.5,l.add(u).max(p0))}).setLayout({name:"V_GGX_SmithCorrelated_Anisotropic",type:"float",inputs:[{name:"alphaT",type:"float",qualifier:"in"},{name:"alphaB",type:"float",qualifier:"in"},{name:"dotTV",type:"float",qualifier:"in"},{name:"dotBV",type:"float",qualifier:"in"},{name:"dotTL",type:"float",qualifier:"in"},{name:"dotBL",type:"float",qualifier:"in"},{name:"dotNV",type:"float",qualifier:"in"},{name:"dotNL",type:"float",qualifier:"in"}]}),TE=Q(({alpha:e,dotNH:t})=>{let r=e.pow2(),i=t.pow2().mul(r.oneMinus()).oneMinus();return r.div(i.pow2()).mul(1/Math.PI)}).setLayout({name:"D_GGX",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNH",type:"float"}]}),SV=D(1/Math.PI),_V=Q(({alphaT:e,alphaB:t,dotNH:r,dotTH:i,dotBH:s})=>{let a=e.mul(t),n=K(t.mul(i),e.mul(s),a.mul(r)),o=n.dot(n),l=a.div(o);return SV.mul(a.mul(l.pow2()))}).setLayout({name:"D_GGX_Anisotropic",type:"float",inputs:[{name:"alphaT",type:"float",qualifier:"in"},{name:"alphaB",type:"float",qualifier:"in"},{name:"dotNH",type:"float",qualifier:"in"},{name:"dotTH",type:"float",qualifier:"in"},{name:"dotBH",type:"float",qualifier:"in"}]}),JT=Q(({lightDirection:e,f0:t,f90:r,roughness:i,f:s,normalView:a=Ut,USE_IRIDESCENCE:n,USE_ANISOTROPY:o})=>{let l=i.pow2(),u=e.add(ar).normalize(),h=a.dot(e).clamp(),d=a.dot(ar).clamp(),c=a.dot(u).clamp(),m=ar.dot(u).clamp(),g=Bd({f0:t,f90:r,dotVH:m}),y,b;if(vd(n)&&(g=a0.mix(g,s)),vd(o)){let v=Ap.dot(e),S=Ap.dot(ar),T=Ap.dot(u),w=Cu.dot(e),N=Cu.dot(ar),C=Cu.dot(u);y=TV({alphaT:l0,alphaB:l,dotTV:S,dotBV:N,dotTL:v,dotBL:w,dotNV:d,dotNL:h}),b=_V({alphaT:l0,alphaB:l,dotNH:c,dotTH:T,dotBH:C})}else y=bE({alpha:l,dotNL:h,dotNV:d}),b=TE({alpha:l,dotNH:c});return g.mul(y).mul(b)}),wV=new Uint16Array([12469,15057,12620,14925,13266,14620,13807,14376,14323,13990,14545,13625,14713,13328,14840,12882,14931,12528,14996,12233,15039,11829,15066,11525,15080,11295,15085,10976,15082,10705,15073,10495,13880,14564,13898,14542,13977,14430,14158,14124,14393,13732,14556,13410,14702,12996,14814,12596,14891,12291,14937,11834,14957,11489,14958,11194,14943,10803,14921,10506,14893,10278,14858,9960,14484,14039,14487,14025,14499,13941,14524,13740,14574,13468,14654,13106,14743,12678,14818,12344,14867,11893,14889,11509,14893,11180,14881,10751,14852,10428,14812,10128,14765,9754,14712,9466,14764,13480,14764,13475,14766,13440,14766,13347,14769,13070,14786,12713,14816,12387,14844,11957,14860,11549,14868,11215,14855,10751,14825,10403,14782,10044,14729,9651,14666,9352,14599,9029,14967,12835,14966,12831,14963,12804,14954,12723,14936,12564,14917,12347,14900,11958,14886,11569,14878,11247,14859,10765,14828,10401,14784,10011,14727,9600,14660,9289,14586,8893,14508,8533,15111,12234,15110,12234,15104,12216,15092,12156,15067,12010,15028,11776,14981,11500,14942,11205,14902,10752,14861,10393,14812,9991,14752,9570,14682,9252,14603,8808,14519,8445,14431,8145,15209,11449,15208,11451,15202,11451,15190,11438,15163,11384,15117,11274,15055,10979,14994,10648,14932,10343,14871,9936,14803,9532,14729,9218,14645,8742,14556,8381,14461,8020,14365,7603,15273,10603,15272,10607,15267,10619,15256,10631,15231,10614,15182,10535,15118,10389,15042,10167,14963,9787,14883,9447,14800,9115,14710,8665,14615,8318,14514,7911,14411,7507,14279,7198,15314,9675,15313,9683,15309,9712,15298,9759,15277,9797,15229,9773,15166,9668,15084,9487,14995,9274,14898,8910,14800,8539,14697,8234,14590,7790,14479,7409,14367,7067,14178,6621,15337,8619,15337,8631,15333,8677,15325,8769,15305,8871,15264,8940,15202,8909,15119,8775,15022,8565,14916,8328,14804,8009,14688,7614,14569,7287,14448,6888,14321,6483,14088,6171,15350,7402,15350,7419,15347,7480,15340,7613,15322,7804,15287,7973,15229,8057,15148,8012,15046,7846,14933,7611,14810,7357,14682,7069,14552,6656,14421,6316,14251,5948,14007,5528,15356,5942,15356,5977,15353,6119,15348,6294,15332,6551,15302,6824,15249,7044,15171,7122,15070,7050,14949,6861,14818,6611,14679,6349,14538,6067,14398,5651,14189,5311,13935,4958,15359,4123,15359,4153,15356,4296,15353,4646,15338,5160,15311,5508,15263,5829,15188,6042,15088,6094,14966,6001,14826,5796,14678,5543,14527,5287,14377,4985,14133,4586,13869,4257,15360,1563,15360,1642,15358,2076,15354,2636,15341,3350,15317,4019,15273,4429,15203,4732,15105,4911,14981,4932,14836,4818,14679,4621,14517,4386,14359,4156,14083,3795,13808,3437,15360,122,15360,137,15358,285,15355,636,15344,1274,15322,2177,15281,2765,15215,3223,15120,3451,14995,3569,14846,3567,14681,3466,14511,3305,14344,3121,14037,2800,13753,2467,15360,0,15360,1,15359,21,15355,89,15346,253,15325,479,15287,796,15225,1148,15133,1492,15008,1749,14856,1882,14685,1886,14506,1783,14324,1608,13996,1398,13702,1183]),En=null,Dp=Q(({roughness:e,dotNV:t})=>{En===null&&(En=new kg(wV,16,16,ha,Dt),En.name="DFG_LUT",En.minFilter=lr,En.magFilter=lr,En.wrapS=Ti,En.wrapT=Ti,En.generateMipmaps=!1,En.needsUpdate=!0);let r=ke(e,t);return Ot(En,r).rg}),MV=Q(({lightDirection:e,f0:t,f90:r,roughness:i,f:s,USE_IRIDESCENCE:a,USE_ANISOTROPY:n})=>{let o=JT({lightDirection:e,f0:t,f90:r,roughness:i,f:s,USE_IRIDESCENCE:a,USE_ANISOTROPY:n}),l=Ut.dot(e).clamp(),u=Ut.dot(ar).clamp(),h=Dp({roughness:i,dotNV:u}),d=Dp({roughness:i,dotNV:l}),c=t.mul(h.x).add(r.mul(h.y)),m=t.mul(d.x).add(r.mul(d.y)),g=h.x.add(h.y),y=d.x.add(d.y),b=D(1).sub(g),v=D(1).sub(y),S=t.add(t.oneMinus().mul(.047619)),T=c.mul(m).mul(S).div(D(1).sub(b.mul(v).mul(S).mul(S)).add(p0)),w=b.mul(v),N=T.mul(w);return o.add(N)}),SE=Q(e=>{let{dotNV:t,specularColor:r,specularF90:i,roughness:s}=e,a=Dp({dotNV:t,roughness:s});return r.mul(a.x).add(i.mul(a.y))}),QT=Q(({f:e,f90:t,dotVH:r})=>{let i=r.oneMinus().saturate(),s=i.mul(i),a=i.mul(s,s).clamp(0,.9999);return e.sub(K(t).mul(a)).div(a.oneMinus())}).setLayout({name:"Schlick_to_F0",type:"vec3",inputs:[{name:"f",type:"vec3"},{name:"f90",type:"float"},{name:"dotVH",type:"float"}]}),NV=Q(({roughness:e,dotNH:t})=>{let r=e.pow2(),i=D(1).div(r),s=t.pow2().oneMinus().max(.0078125);return D(2).add(i).mul(s.pow(i.mul(.5))).div(2*Math.PI)}).setLayout({name:"D_Charlie",type:"float",inputs:[{name:"roughness",type:"float"},{name:"dotNH",type:"float"}]}),AV=Q(({dotNV:e,dotNL:t})=>D(1).div(D(4).mul(t.add(e).sub(t.mul(e))))).setLayout({name:"V_Neubelt",type:"float",inputs:[{name:"dotNV",type:"float"},{name:"dotNL",type:"float"}]}),CV=Q(({lightDirection:e})=>{let t=e.add(ar).normalize(),r=Ut.dot(e).clamp(),i=Ut.dot(ar).clamp(),s=Ut.dot(t).clamp(),a=NV({roughness:hl,dotNH:s}),n=AV({dotNV:i,dotNL:r});return Ws.mul(a).mul(n)}),_E=Q(({N:e,V:t,roughness:r})=>{let i=.0078125,s=e.dot(t).saturate(),a=ke(r,s.oneMinus().sqrt());return a.assign(a.mul(.984375).add(i)),a}).setLayout({name:"LTC_Uv",type:"vec2",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"roughness",type:"float"}]}),RV=Q(({f:e})=>{let t=e.length();return Br(t.mul(t).add(e.z).div(t.add(1)),0)}).setLayout({name:"LTC_ClippedSphereFormFactor",type:"float",inputs:[{name:"f",type:"vec3"}]}),q0=Q(({v1:e,v2:t})=>{let r=e.dot(t),i=r.abs().toVar(),s=i.mul(.0145206).add(.4965155).mul(i).add(.8543985).toVar(),a=i.add(4.1616724).mul(i).add(3.417594).toVar(),n=s.div(a),o=r.greaterThan(0).select(n,Br(r.mul(r).oneMinus(),1e-7).inverseSqrt().mul(.5).sub(n));return e.cross(t).mul(o)}).setLayout({name:"LTC_EdgeVectorFormFactor",type:"vec3",inputs:[{name:"v1",type:"vec3"},{name:"v2",type:"vec3"}]}),KT=Q(({N:e,V:t,P:r,mInv:i,p0:s,p1:a,p2:n,p3:o})=>{let l=a.sub(s).toVar(),u=o.sub(s).toVar(),h=l.cross(u),d=K().toVar();return et(h.dot(r.sub(s)).greaterThanEqual(0),()=>{let c=t.sub(e.mul(t.dot(e))).normalize(),m=e.cross(c).negate(),g=i.mul(Ni(c,m,e).transpose()).toVar(),y=g.mul(s.sub(r)).normalize().toVar(),b=g.mul(a.sub(r)).normalize().toVar(),v=g.mul(n.sub(r)).normalize().toVar(),S=g.mul(o.sub(r)).normalize().toVar(),T=K(0).toVar();T.addAssign(q0({v1:y,v2:b})),T.addAssign(q0({v1:b,v2:v})),T.addAssign(q0({v1:v,v2:S})),T.addAssign(q0({v1:S,v2:y})),d.assign(K(RV({f:T})))}),d}).setLayout({name:"LTC_Evaluate",type:"vec3",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"P",type:"vec3"},{name:"mInv",type:"mat3"},{name:"p0",type:"vec3"},{name:"p1",type:"vec3"},{name:"p2",type:"vec3"},{name:"p3",type:"vec3"}]}),Y0=1/6,wE=e=>mt(Y0,mt(e,mt(e,e.negate().add(3)).sub(3)).add(1)),eS=e=>mt(Y0,mt(e,mt(e,mt(3,e).sub(6))).add(4)),ME=e=>mt(Y0,mt(e,mt(e,mt(-3,e).add(3)).add(3)).add(1)),tS=e=>mt(Y0,ma(e,3)),NE=e=>wE(e).add(eS(e)),AE=e=>ME(e).add(tS(e)),CE=e=>Yr(-1,eS(e).div(wE(e).add(eS(e)))),RE=e=>Yr(1,tS(e).div(ME(e).add(tS(e)))),EE=(e,t,r)=>{let i=e.uvNode,s=mt(i,t.zw).add(.5),a=Mn(s),n=Oa(s),o=NE(n.x),l=AE(n.x),u=CE(n.x),h=RE(n.x),d=CE(n.y),c=RE(n.y),m=ke(a.x.add(u),a.y.add(d)).sub(.5).mul(t.xy),g=ke(a.x.add(h),a.y.add(d)).sub(.5).mul(t.xy),y=ke(a.x.add(u),a.y.add(c)).sub(.5).mul(t.xy),b=ke(a.x.add(h),a.y.add(c)).sub(.5).mul(t.xy),v=NE(n.y).mul(Yr(o.mul(e.sample(m).level(r)),l.mul(e.sample(g).level(r)))),S=AE(n.y).mul(Yr(o.mul(e.sample(y).level(r)),l.mul(e.sample(b).level(r))));return v.add(S)},rS=Q(([e,t])=>{let r=ke(e.size(Y(t))),i=ke(e.size(Y(t.add(1)))),s=js(1,r),a=js(1,i),n=EE(e,Ve(s,r),Mn(t)),o=EE(e,Ve(a,i),g0(t));return Oa(t).mix(n,o)}),EV=Q(([e,t])=>{let r=t.mul(rT(e));return rS(e,r)}),PE=Q(([e,t,r,i,s])=>{let a=K(jb(t.negate(),Yi(e),js(1,i))),n=K(Nn(s[0].xyz),Nn(s[1].xyz),Nn(s[2].xyz));return Yi(a).mul(r.mul(n))}).setLayout({name:"getVolumeTransmissionRay",type:"vec3",inputs:[{name:"n",type:"vec3"},{name:"v",type:"vec3"},{name:"thickness",type:"float"},{name:"ior",type:"float"},{name:"modelMatrix",type:"mat4"}]}),PV=Q(([e,t])=>e.mul(za(t.mul(2).sub(2),0,1))).setLayout({name:"applyIorToRoughness",type:"float",inputs:[{name:"roughness",type:"float"},{name:"ior",type:"float"}]}),BV=VT(),IV=sE(),BE=Q(([e,t,r],{material:i})=>{let s=(i.side===ii?BV:IV).sample(e),a=wn(Lu.x).mul(PV(t,r));return rS(s,a)}),IE=Q(([e,t,r])=>(et(r.notEqual(0),()=>{let i=f0(t).negate().div(r);return Pb(i.negate().mul(e))}),K(1))).setLayout({name:"volumeAttenuation",type:"vec3",inputs:[{name:"transmissionDistance",type:"float"},{name:"attenuationColor",type:"vec3"},{name:"attenuationDistance",type:"float"}]}),FV=Q(([e,t,r,i,s,a,n,o,l,u,h,d,c,m,g])=>{let y,b;if(g){y=Ve().toVar(),b=K().toVar();let N=h.sub(1).mul(g.mul(.025)),C=K(h.sub(N),h,h.add(N));Qt({start:0,end:3},({i:R})=>{let E=C.element(R),P=PE(e,t,d,E,o),I=n.add(P),O=u.mul(l.mul(Ve(I,1))),L=ke(O.xy.div(O.w)).toVar();L.addAssign(1),L.divAssign(2),L.assign(ke(L.x,L.y.oneMinus()));let X=BE(L,r,E);y.element(R).assign(X.element(R)),y.a.addAssign(X.a),b.element(R).assign(i.element(R).mul(IE(Nn(P),c,m).element(R)))}),y.a.divAssign(3)}else{let N=PE(e,t,d,h,o),C=n.add(N),R=u.mul(l.mul(Ve(C,1))),E=ke(R.xy.div(R.w)).toVar();E.addAssign(1),E.divAssign(2),E.assign(ke(E.x,E.y.oneMinus())),y=BE(E,r,h),b=i.mul(IE(Nn(N),c,m))}let v=b.rgb.mul(y.rgb),S=e.dot(t).clamp(),T=K(SE({dotNV:S,specularColor:s,specularF90:a,roughness:r})),w=b.r.add(b.g,b.b).div(3);return Ve(T.oneMinus().mul(v),y.a.oneMinus().mul(w).oneMinus())}),LV=Ni(3.2404542,-.969266,.0556434,-1.5371385,1.8760108,-.2040259,-.4985314,.041556,1.0572252),kV=e=>{let t=e.sqrt();return K(1).add(t).div(K(1).sub(t))},FE=(e,t)=>e.sub(t).div(e.add(t)).pow2(),DV=(e,t)=>{let r=e.mul(2*Math.PI*1e-9),i=K(54856e-17,44201e-17,52481e-17),s=K(1681e3,1795300,2208400),a=K(43278e5,93046e5,66121e5),n=D(9747e-17*Math.sqrt(2*Math.PI*45282e5)).mul(r.mul(2239900).add(t.x).cos()).mul(r.pow2().mul(-45282e5).exp()),o=i.mul(a.mul(2*Math.PI).sqrt()).mul(s.mul(r).add(t).cos()).mul(r.pow2().negate().mul(a).exp());return o=K(o.x.add(n),o.y,o.z).div(10685e-11),LV.mul(o)},LE=Q(({outsideIOR:e,eta2:t,cosTheta1:r,thinFilmThickness:i,baseF0:s})=>{let a=Ct(e,t,Hs(0,.03,i)),n=e.div(a).pow2().mul(r.pow2().oneMinus()).oneMinus();et(n.lessThan(0),()=>K(1));let o=n.sqrt(),l=FE(a,e),u=Bd({f0:l,f90:1,dotVH:r}),h=u.oneMinus(),d=a.lessThan(e).select(Math.PI,0),c=D(Math.PI).sub(d),m=kV(s.clamp(0,.9999)),g=FE(m,a.toVec3()),y=Bd({f0:g,f90:1,dotVH:o}),b=K(m.x.lessThan(a).select(Math.PI,0),m.y.lessThan(a).select(Math.PI,0),m.z.lessThan(a).select(Math.PI,0)),v=a.mul(i,o,2),S=K(c).add(b),T=u.mul(y).clamp(1e-5,.9999),w=T.sqrt(),N=h.pow2().mul(y).div(K(1).sub(T)),C=u.add(N).toVar(),R=N.sub(h).toVar();return Qt({start:1,end:2,condition:"<=",name:"m"},({m:E})=>{R.mulAssign(w);let P=DV(D(E).mul(v),D(E).mul(S)).mul(2);C.addAssign(R.mul(P))}),C.max(K(0))}).setLayout({name:"evalIridescence",type:"vec3",inputs:[{name:"outsideIOR",type:"float"},{name:"eta2",type:"float"},{name:"cosTheta1",type:"float"},{name:"thinFilmThickness",type:"float"},{name:"baseF0",type:"vec3"}]}),Op=Q(({normal:e,viewDir:t,roughness:r})=>{let i=e.dot(t).saturate(),s=r.mul(r),a=r.add(.1).reciprocal(),n=D(-1.9362).add(r.mul(1.0678)).add(s.mul(.4573)).sub(a.mul(.8469)),o=D(-.6014).add(r.mul(.5538)).sub(s.mul(.467)).sub(a.mul(.1255));return n.mul(i).add(o).exp().saturate()}),Up=K(.04),Z0=D(1),kE=class extends $0{constructor(e=!1,t=!1,r=!1,i=!1,s=!1,a=!1){super(),this.clearcoat=e,this.sheen=t,this.iridescence=r,this.anisotropy=i,this.transmission=s,this.dispersion=a,this.clearcoatRadiance=null,this.clearcoatSpecularDirect=null,this.clearcoatSpecularIndirect=null,this.sheenSpecularDirect=null,this.sheenSpecularIndirect=null,this.iridescenceFresnel=null,this.iridescenceF0=null,this.iridescenceF0Dielectric=null,this.iridescenceF0Metallic=null}start(e){if(this.clearcoat===!0&&(this.clearcoatRadiance=K().toVar("clearcoatRadiance"),this.clearcoatSpecularDirect=K().toVar("clearcoatSpecularDirect"),this.clearcoatSpecularIndirect=K().toVar("clearcoatSpecularIndirect")),this.sheen===!0&&(this.sheenSpecularDirect=K().toVar("sheenSpecularDirect"),this.sheenSpecularIndirect=K().toVar("sheenSpecularIndirect")),this.iridescence===!0){let t=Ut.dot(ar).clamp(),r=LE({outsideIOR:D(1),eta2:n0,cosTheta1:t,thinFilmThickness:o0,baseF0:cl}),i=LE({outsideIOR:D(1),eta2:n0,cosTheta1:t,thinFilmThickness:o0,baseF0:Zt.rgb});this.iridescenceFresnel=Ct(r,i,yo),this.iridescenceF0Dielectric=QT({f:r,f90:1,dotVH:t}),this.iridescenceF0Metallic=QT({f:i,f90:1,dotVH:t}),this.iridescenceF0=Ct(this.iridescenceF0Dielectric,this.iridescenceF0Metallic,yo)}if(this.transmission===!0){let t=Rn,r=VC.sub(Rn).normalize(),i=vl,s=e.context;s.backdrop=FV(i,r,_n,Au,Ru,Eu,t,ga,xl,bs,Rp,Mb,Ab,Nb,this.dispersion?Cb:null),s.backdropAlpha=h0,Zt.a.mulAssign(Ct(1,s.backdrop.a,h0))}super.start(e)}computeMultiscattering(e,t,r,i,s=null){let a=Ut.dot(ar).clamp(),n=Dp({roughness:_n,dotNV:a}),o=s?a0.mix(i,s):i,l=o.mul(n.x).add(r.mul(n.y)),u=n.x.add(n.y).oneMinus(),h=o.add(o.oneMinus().mul(.047619)),d=l.mul(h).div(u.mul(h).oneMinus());e.addAssign(l),t.addAssign(d.mul(u))}direct({lightDirection:e,lightColor:t,reflectedLight:r}){let i=Ut.dot(e).clamp().mul(t).toVar();if(this.sheen===!0){this.sheenSpecularDirect.addAssign(i.mul(CV({lightDirection:e})));let s=Op({normal:Ut,viewDir:ar,roughness:hl}),a=Op({normal:Ut,viewDir:e,roughness:hl}),n=Ws.r.max(Ws.g).max(Ws.b).mul(s.max(a)).oneMinus();i.mulAssign(n)}if(this.clearcoat===!0){let s=bl.dot(e).clamp().mul(t);this.clearcoatSpecularDirect.addAssign(s.mul(JT({lightDirection:e,f0:Up,f90:Z0,roughness:Td,normalView:bl})))}r.directDiffuse.addAssign(i.mul(Wu({diffuseColor:Au}))),r.directSpecular.addAssign(i.mul(MV({lightDirection:e,f0:Ru,f90:1,roughness:_n,f:this.iridescenceFresnel,USE_IRIDESCENCE:this.iridescence,USE_ANISOTROPY:this.anisotropy})))}directRectArea({lightColor:e,lightPosition:t,halfWidth:r,halfHeight:i,reflectedLight:s,ltc_1:a,ltc_2:n}){let o=t.add(r).sub(i),l=t.sub(r).sub(i),u=t.sub(r).add(i),h=t.add(r).add(i),d=Ut,c=ar,m=Wr.toVar(),g=_E({N:d,V:c,roughness:_n}),y=a.sample(g).toVar(),b=n.sample(g).toVar(),v=Ni(K(y.x,0,y.y),K(0,1,0),K(y.z,0,y.w)).toVar(),S=Ru.mul(b.x).add(Eu.sub(Ru).mul(b.y)).toVar();if(s.directSpecular.addAssign(e.mul(S).mul(KT({N:d,V:c,P:m,mInv:v,p0:o,p1:l,p2:u,p3:h}))),s.directDiffuse.addAssign(e.mul(Au).mul(KT({N:d,V:c,P:m,mInv:Ni(1,0,0,0,1,0,0,0,1),p0:o,p1:l,p2:u,p3:h}))),this.clearcoat===!0){let T=bl,w=_E({N:T,V:c,roughness:Td}),N=a.sample(w),C=n.sample(w),R=Ni(K(N.x,0,N.y),K(0,1,0),K(N.z,0,N.w)),E=Up.mul(C.x).add(Z0.sub(Up).mul(C.y));this.clearcoatSpecularDirect.addAssign(e.mul(E).mul(KT({N:T,V:c,P:m,mInv:R,p0:o,p1:l,p2:u,p3:h})))}}indirect(e){this.indirectDiffuse(e),this.indirectSpecular(e),this.ambientOcclusion(e)}indirectDiffuse(e){let{irradiance:t,reflectedLight:r}=e.context,i=t.mul(Wu({diffuseColor:Au})).toVar();if(this.sheen===!0){let s=Op({normal:Ut,viewDir:ar,roughness:hl}),a=Ws.r.max(Ws.g).max(Ws.b).mul(s).oneMinus();i.mulAssign(a)}r.indirectDiffuse.addAssign(i)}indirectSpecular(e){let{radiance:t,iblIrradiance:r,reflectedLight:i}=e.context;if(this.sheen===!0&&this.sheenSpecularIndirect.addAssign(r.mul(Ws,Op({normal:Ut,viewDir:ar,roughness:hl}))),this.clearcoat===!0){let y=bl.dot(ar).clamp(),b=SE({dotNV:y,specularColor:Up,specularF90:Z0,roughness:Td});this.clearcoatSpecularIndirect.addAssign(this.clearcoatRadiance.mul(b))}let s=K().toVar("singleScatteringDielectric"),a=K().toVar("multiScatteringDielectric"),n=K().toVar("singleScatteringMetallic"),o=K().toVar("multiScatteringMetallic");this.computeMultiscattering(s,a,Eu,cl,this.iridescenceF0Dielectric),this.computeMultiscattering(n,o,Eu,Zt.rgb,this.iridescenceF0Metallic);let l=Ct(s,n,yo),u=Ct(a,o,yo),h=s.add(a),d=Au.mul(h.oneMinus()),c=r.mul(1/Math.PI),m=t.mul(l).add(u.mul(c)).toVar(),g=d.mul(c).toVar();if(this.sheen===!0){let y=Op({normal:Ut,viewDir:ar,roughness:hl}),b=Ws.r.max(Ws.g).max(Ws.b).mul(y).oneMinus();m.mulAssign(b),g.mulAssign(b)}i.indirectSpecular.addAssign(m),i.indirectDiffuse.addAssign(g)}ambientOcclusion(e){let{ambientOcclusion:t,reflectedLight:r}=e.context,i=Ut.dot(ar).clamp().add(t),s=_n.mul(-16).oneMinus().negate().exp2(),a=t.sub(i.pow(s).oneMinus()).clamp();this.clearcoat===!0&&this.clearcoatSpecularIndirect.mulAssign(t),this.sheen===!0&&this.sheenSpecularIndirect.mulAssign(t),r.indirectDiffuse.mulAssign(t),r.indirectSpecular.mulAssign(a)}finish({context:e}){let{outgoingLight:t}=e;if(this.clearcoat===!0){let r=bl.dot(ar).clamp(),i=Bd({dotVH:r,f0:Up,f90:Z0}),s=t.mul(s0.mul(i).oneMinus()).add(this.clearcoatSpecularDirect.add(this.clearcoatSpecularIndirect).mul(s0));t.assign(s)}if(this.sheen===!0){let r=t.add(this.sheenSpecularDirect,this.sheenSpecularIndirect.mul(1/Math.PI));t.assign(r)}}},DE=D(1),iS=D(-2),J0=D(.8),sS=D(-1),Q0=D(.4),aS=D(2),K0=D(.305),nS=D(3),OE=D(.21),OV=D(4),UE=D(4),UV=D(16),zV=Q(([e])=>{let t=K(ur(e)).toVar(),r=D(-1).toVar();return et(t.x.greaterThan(t.z),()=>{et(t.x.greaterThan(t.y),()=>{r.assign(Zi(e.x.greaterThan(0),0,3))}).Else(()=>{r.assign(Zi(e.y.greaterThan(0),1,4))})}).Else(()=>{et(t.z.greaterThan(t.y),()=>{r.assign(Zi(e.z.greaterThan(0),2,5))}).Else(()=>{r.assign(Zi(e.y.greaterThan(0),1,4))})}),r}).setLayout({name:"getFace",type:"float",inputs:[{name:"direction",type:"vec3"}]}),VV=Q(([e,t])=>{let r=ke().toVar();return et(t.equal(0),()=>{r.assign(ke(e.z,e.y).div(ur(e.x)))}).ElseIf(t.equal(1),()=>{r.assign(ke(e.x.negate(),e.z.negate()).div(ur(e.y)))}).ElseIf(t.equal(2),()=>{r.assign(ke(e.x.negate(),e.y).div(ur(e.z)))}).ElseIf(t.equal(3),()=>{r.assign(ke(e.z.negate(),e.y).div(ur(e.x)))}).ElseIf(t.equal(4),()=>{r.assign(ke(e.x.negate(),e.z).div(ur(e.y)))}).Else(()=>{r.assign(ke(e.x,e.y).div(ur(e.z)))}),mt(.5,r.add(1))}).setLayout({name:"getUV",type:"vec2",inputs:[{name:"direction",type:"vec3"},{name:"face",type:"float"}]}),GV=Q(([e])=>{let t=D(0).toVar();return et(e.greaterThanEqual(J0),()=>{t.assign(DE.sub(e).mul(sS.sub(iS)).div(DE.sub(J0)).add(iS))}).ElseIf(e.greaterThanEqual(Q0),()=>{t.assign(J0.sub(e).mul(aS.sub(sS)).div(J0.sub(Q0)).add(sS))}).ElseIf(e.greaterThanEqual(K0),()=>{t.assign(Q0.sub(e).mul(nS.sub(aS)).div(Q0.sub(K0)).add(aS))}).ElseIf(e.greaterThanEqual(OE),()=>{t.assign(K0.sub(e).mul(OV.sub(nS)).div(K0.sub(OE)).add(nS))}).Else(()=>{t.assign(D(-2).mul(wn(mt(1.16,e))))}),t}).setLayout({name:"roughnessToMip",type:"float",inputs:[{name:"roughness",type:"float"}]}),zE=Q(([e,t])=>{let r=e.toVar();r.assign(mt(2,r).sub(1));let i=K(r,1).toVar();return et(t.equal(0),()=>{i.assign(i.zyx)}).ElseIf(t.equal(1),()=>{i.assign(i.xzy),i.xz.mulAssign(-1)}).ElseIf(t.equal(2),()=>{i.x.mulAssign(-1)}).ElseIf(t.equal(3),()=>{i.assign(i.zyx),i.xz.mulAssign(-1)}).ElseIf(t.equal(4),()=>{i.assign(i.xzy),i.xy.mulAssign(-1)}).ElseIf(t.equal(5),()=>{i.z.mulAssign(-1)}),i}).setLayout({name:"getDirection",type:"vec3",inputs:[{name:"uv",type:"vec2"},{name:"face",type:"float"}]}),VE=Q(([e,t,r,i,s,a])=>{let n=D(r),o=K(t),l=za(GV(n),iS,a),u=Oa(l),h=Mn(l),d=K(zp(e,o,h,i,s,a)).toVar();return et(u.notEqual(0),()=>{let c=K(zp(e,o,h.add(1),i,s,a)).toVar();d.assign(Ct(d,c,u))}),d}),zp=Q(([e,t,r,i,s,a])=>{let n=D(r).toVar(),o=K(t),l=D(zV(o)).toVar(),u=D(Br(UE.sub(n),0)).toVar();n.assign(Br(n,UE));let h=D(_d(n)).toVar(),d=ke(VV(o,l).mul(h.sub(2)).add(1)).toVar();return et(l.greaterThan(2),()=>{d.y.addAssign(h),l.subAssign(3)}),d.x.addAssign(l.mul(h)),d.x.addAssign(u.mul(mt(3,UV))),d.y.addAssign(mt(4,_d(a).sub(h))),d.x.mulAssign(i),d.y.mulAssign(s),e.sample(d).grad(ke(),ke())}),oS=Q(({envMap:e,mipInt:t,outputDirection:r,theta:i,axis:s,CUBEUV_TEXEL_WIDTH:a,CUBEUV_TEXEL_HEIGHT:n,CUBEUV_MAX_MIP:o})=>{let l=Ua(i),u=r.mul(l).add(s.cross(r).mul(xs(i))).add(s.mul(s.dot(r).mul(l.oneMinus())));return zp(e,u,t,a,n,o)}),GE=Q(({n:e,latitudinal:t,poleAxis:r,outputDirection:i,weights:s,samples:a,dTheta:n,mipInt:o,envMap:l,CUBEUV_TEXEL_WIDTH:u,CUBEUV_TEXEL_HEIGHT:h,CUBEUV_MAX_MIP:d})=>{let c=K(Zi(t,r,xo(r,i))).toVar();et(c.equal(K(0)),()=>{c.assign(K(i.z,0,i.x.negate()))}),c.assign(Yi(c));let m=K().toVar();return m.addAssign(s.element(0).mul(oS({theta:0,axis:c,outputDirection:i,mipInt:o,envMap:l,CUBEUV_TEXEL_WIDTH:u,CUBEUV_TEXEL_HEIGHT:h,CUBEUV_MAX_MIP:d}))),Qt({start:Y(1),end:e},({i:g})=>{et(g.greaterThanEqual(a),()=>{KR()});let y=D(n.mul(D(g))).toVar();m.addAssign(s.element(g).mul(oS({theta:y.mul(-1),axis:c,outputDirection:i,mipInt:o,envMap:l,CUBEUV_TEXEL_WIDTH:u,CUBEUV_TEXEL_HEIGHT:h,CUBEUV_MAX_MIP:d}))),m.addAssign(s.element(g).mul(oS({theta:y,axis:c,outputDirection:i,mipInt:o,envMap:l,CUBEUV_TEXEL_WIDTH:u,CUBEUV_TEXEL_HEIGHT:h,CUBEUV_MAX_MIP:d})))}),Ve(m,1)}),WV=Q(([e])=>{let t=Ne(e).toVar();return t.assign(t.shiftLeft(Ne(16)).bitOr(t.shiftRight(Ne(16)))),t.assign(t.bitAnd(Ne(1431655765)).shiftLeft(Ne(1)).bitOr(t.bitAnd(Ne(2863311530)).shiftRight(Ne(1)))),t.assign(t.bitAnd(Ne(858993459)).shiftLeft(Ne(2)).bitOr(t.bitAnd(Ne(3435973836)).shiftRight(Ne(2)))),t.assign(t.bitAnd(Ne(252645135)).shiftLeft(Ne(4)).bitOr(t.bitAnd(Ne(4042322160)).shiftRight(Ne(4)))),t.assign(t.bitAnd(Ne(16711935)).shiftLeft(Ne(8)).bitOr(t.bitAnd(Ne(4278255360)).shiftRight(Ne(8)))),D(t).mul(23283064365386963e-26)}),jV=Q(([e,t])=>ke(D(e).div(D(t)),WV(e))),HV=Q(([e,t,r])=>{let i=r.mul(r).toConst(),s=K(1,0,0).toConst(),a=xo(t,s).toConst(),n=ys(e.x).toConst(),o=mt(2,3.14159265359).mul(e.y).toConst(),l=n.mul(Ua(o)).toConst(),u=n.mul(xs(o)).toVar(),h=mt(.5,t.z.add(1)).toConst();u.assign(h.oneMinus().mul(ys(l.mul(l).oneMinus())).add(h.mul(u)));let d=s.mul(l).add(a.mul(u)).add(t.mul(ys(Br(0,l.mul(l).add(u.mul(u)).oneMinus()))));return Yi(K(i.mul(d.x),i.mul(d.y),Br(0,d.z)))}),WE=Q(({roughness:e,mipInt:t,envMap:r,N_immutable:i,GGX_SAMPLES:s,CUBEUV_TEXEL_WIDTH:a,CUBEUV_TEXEL_HEIGHT:n,CUBEUV_MAX_MIP:o})=>{let l=K(i).toVar(),u=K(0).toVar(),h=D(0).toVar();return et(e.lessThan(.001),()=>{u.assign(zp(r,l,t,a,n,o))}).Else(()=>{let d=Zi(ur(l.z).lessThan(.999),K(0,0,1),K(1,0,0)),c=Yi(xo(d,l)).toVar(),m=xo(l,c).toVar();Qt({start:Ne(0),end:s},({i:g})=>{let y=jV(g,s),b=HV(y,K(0,0,1),e),v=Yi(c.mul(b.x).add(m.mul(b.y)).add(l.mul(b.z))),S=Yi(v.mul(pa(l,v).mul(2)).sub(l)),T=Br(pa(l,S),0);et(T.greaterThan(0),()=>{let w=zp(r,S,t,a,n,o);u.addAssign(w.mul(T)),h.addAssign(T)})}),et(h.greaterThan(0),()=>{u.assign(u.div(h))})}),Ve(u,1)}),wl=4,jE=[.125,.215,.35,.446,.526,.582],ju=20,XV=512,Vp=new sb(-1,1,1,-1,0,1),$V=new gs(90,1),HE=new gt,lS=null,uS=0,hS=0,qV=new F,ey=new WeakMap,YV=[3,1,5,0,4,2],dS=zE(Jt(),$s("faceIndex")).normalize(),ty=K(dS.x,dS.y,dS.z),ZV=class{constructor(e){this._renderer=e,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._sizeLods=[],this._sigmas=[],this._lodMeshes=[],this._blurMaterial=null,this._ggxMaterial=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._backgroundBox=null}get _hasInitialized(){return this._renderer.hasInitialized()}fromScene(e,t=0,r=.1,i=100,s={}){let{size:a=256,position:n=qV,renderTarget:o=null}=s;if(this._setSize(a),this._hasInitialized===!1)throw new Error('THREE.PMREMGenerator: .fromScene() called before the backend is initialized. Use "await renderer.init();" before using this method.');lS=this._renderer.getRenderTarget(),uS=this._renderer.getActiveCubeFace(),hS=this._renderer.getActiveMipmapLevel();let l=o||this._allocateTarget(!0);return this._init(l),this._sceneToCubeUV(e,r,i,l,n),t>0&&this._blur(l,0,0,t),this._applyPMREM(l),this._cleanup(l),l}async fromSceneAsync(e,t=0,r=.1,i=100,s={}){return Et('PMREMGenerator: ".fromSceneAsync()" is deprecated. Use "await renderer.init()" instead.'),await this._renderer.init(),this.fromScene(e,t,r,i,s)}fromEquirectangular(e,t=null){if(this._hasInitialized===!1)throw new Error('THREE.PMREMGenerator: .fromEquirectangular() called before the backend is initialized. Use "await renderer.init();" before using this method.');return this._fromTexture(e,t)}async fromEquirectangularAsync(e,t=null){return Et('PMREMGenerator: ".fromEquirectangularAsync()" is deprecated. Use "await renderer.init()" instead.'),await this._renderer.init(),this._fromTexture(e,t)}fromCubemap(e,t=null){if(this._hasInitialized===!1)throw new Error('THREE.PMREMGenerator: .fromCubemap() called before the backend is initialized. Use "await renderer.init();" before using this method.');return this._fromTexture(e,t)}async fromCubemapAsync(e,t=null){return Et('PMREMGenerator: ".fromCubemapAsync()" is deprecated. Use "await renderer.init()" instead.'),await this._renderer.init(),this._fromTexture(e,t)}async compileCubemapShader(){this._cubemapMaterial===null&&(this._cubemapMaterial=$E(),await this._compileMaterial(this._cubemapMaterial))}async compileEquirectangularShader(){this._equirectMaterial===null&&(this._equirectMaterial=qE(),await this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),this._cubemapMaterial!==null&&this._cubemapMaterial.dispose(),this._equirectMaterial!==null&&this._equirectMaterial.dispose(),this._backgroundBox!==null&&(this._backgroundBox.geometry.dispose(),this._backgroundBox.material.dispose())}_setSizeFromTexture(e){e.mapping===Vh||e.mapping===Lf?this._setSize(e.image.length===0?16:e.image[0].width||e.image[0].image.width):this._setSize(e.image.width/4)}_setSize(e){this._lodMax=Math.floor(Math.log2(e)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){this._blurMaterial!==null&&this._blurMaterial.dispose(),this._ggxMaterial!==null&&this._ggxMaterial.dispose(),this._pingPongRenderTarget!==null&&this._pingPongRenderTarget.dispose();for(let e=0;e2?b:0,b,b),l.render(e,a)}l.autoClear=u,e.background=m}_textureToCubeUV(e,t){let r=this._renderer,i=e.mapping===Vh||e.mapping===Lf;i?this._cubemapMaterial===null&&(this._cubemapMaterial=$E(e)):this._equirectMaterial===null&&(this._equirectMaterial=qE(e));let s=i?this._cubemapMaterial:this._equirectMaterial;s.fragmentNode.value=e;let a=this._lodMeshes[0];a.material=s;let n=this._cubeSize;this._setViewport(t,0,0,3*n,2*n),r.setRenderTarget(t),r.render(a,Vp)}_applyPMREM(e){let t=this._renderer,r=t.autoClear;t.autoClear=!1;let i=this._lodMeshes.length;for(let s=1;sm-wl?r-m+wl:0),b=4*(this._cubeSize-g);e.texture.frame=(e.texture.frame||0)+1,o.envMap.value=e.texture,o.roughness.value=c,o.mipInt.value=m-t,this._setViewport(s,y,b,3*g,2*g),i.setRenderTarget(s),i.render(n,Vp),s.texture.frame=(s.texture.frame||0)+1,o.envMap.value=s.texture,o.roughness.value=0,o.mipInt.value=m-r,this._setViewport(e,y,b,3*g,2*g),i.setRenderTarget(e),i.render(n,Vp)}_blur(e,t,r,i,s){let a=this._pingPongRenderTarget;this._halfBlur(e,a,t,r,i,"latitudinal",s),this._halfBlur(a,e,r,r,i,"longitudinal",s)}_halfBlur(e,t,r,i,s,a,n){let o=this._renderer,l=this._blurMaterial;a!=="latitudinal"&&a!=="longitudinal"&&Ce("blur direction must be either latitudinal or longitudinal!");let u=3,h=this._lodMeshes[i];h.material=l;let d=ey.get(l),c=this._sizeLods[r]-1,m=isFinite(s)?Math.PI/(2*c):2*Math.PI/(2*ju-1),g=s/m,y=isFinite(s)?1+Math.floor(u*g):ju;y>ju&&Ue(`sigmaRadians, ${s}, is too large and will clip, as it requested ${y} samples when the maximum is set to ${ju}`);let b=[],v=0;for(let C=0;CS-wl?i-S+wl:0),N=4*(this._cubeSize-T);this._setViewport(t,w,N,3*T,2*T),o.setRenderTarget(t),o.render(h,Vp)}_setViewport(e,t,r,i,s){this._renderer.isWebGLRenderer?(e.viewport.set(t,e.height-s-r,i,s),e.scissor.set(t,e.height-s-r,i,s)):(e.viewport.set(t,r,i,s),e.scissor.set(t,r,i,s))}};function JV(e){let t=[],r=[],i=[],s=e,a=e-wl+1+jE.length;for(let n=0;ne-wl?l=jE[n-e+wl-1]:n===0&&(l=0),r.push(l);let u=1/(o-2),h=-u,d=1+u,c=[h,h,d,h,d,d,h,h,d,d,h,d],m=6,g=6,y=3,b=2,v=1,S=new Float32Array(y*g*m),T=new Float32Array(b*g*m),w=new Float32Array(v*g*m);for(let C=0;C2?0:-1,P=[R,E,0,R+2/3,E,0,R+2/3,E+1,0,R,E,0,R+2/3,E+1,0,R,E+1,0],I=YV[C];S.set(P,y*g*I),T.set(c,b*g*I);let O=[I,I,I,I,I,I];w.set(O,v*g*I)}let N=new ps;N.setAttribute("position",new _i(S,y)),N.setAttribute("uv",new _i(T,b)),N.setAttribute("faceIndex",new _i(w,v)),i.push(new Mi(N,null)),s>wl&&s--}return{lodMeshes:i,sizeLods:t,sigmas:r}}function XE(e,t,r){let i={magFilter:lr,minFilter:lr,generateMipmaps:!1,type:Dt,format:pi,colorSpace:Xh,depthBuffer:r},s=new er(e,t,i);return s.texture.mapping=Df,s.texture.name="PMREM.cubeUv",s.texture.isPMREMTexture=!0,s.scissorTest=!0,s}function ry(e){let t=new Pt;return t.depthTest=!1,t.depthWrite=!1,t.blending=Kn,t.name=`PMREM_${e}`,t}function QV(e,t,r){let i=Li(new Array(ju).fill(0)),s=Qe(new F(0,1,0)),a=Qe(0),n=D(ju),o=Qe(0),l=Qe(1),u=Ot(),h=Qe(0),d=D(1/t),c=D(1/r),m=D(e),g={n,latitudinal:o,weights:i,poleAxis:s,outputDirection:ty,dTheta:a,samples:l,envMap:u,mipInt:h,CUBEUV_TEXEL_WIDTH:d,CUBEUV_TEXEL_HEIGHT:c,CUBEUV_MAX_MIP:m},y=ry("blur");return y.fragmentNode=GE({...g,latitudinal:o.equal(1)}),ey.set(y,g),y}function KV(e,t,r){let i=Ot(),s=Qe(0),a=Qe(0),n=D(1/t),o=D(1/r),l=D(e),u={envMap:i,roughness:s,mipInt:a,CUBEUV_TEXEL_WIDTH:n,CUBEUV_TEXEL_HEIGHT:o,CUBEUV_MAX_MIP:l},h=ry("ggx");return h.fragmentNode=WE({...u,N_immutable:ty,GGX_SAMPLES:Ne(XV)}),ey.set(h,u),h}function $E(e){let t=ry("cubemap");return t.fragmentNode=Ts(e,ty),t}function qE(e){let t=ry("equirect");return t.fragmentNode=Ot(e,$T(ty),0),t}var YE=new WeakMap;function eG(e){let t=Math.log2(e)-2,r=1/e;return{texelWidth:1/(3*Math.max(Math.pow(2,t),112)),texelHeight:r,maxMip:t}}function tG(e,t,r){let i=rG(t),s=i.get(e);if((s!==void 0?s.pmremVersion:-1)!==e.pmremVersion){let a=e.image;if(e.isCubeTexture)if(sG(a))s=r.fromCubemap(e,s);else return null;else if(aG(a))s=r.fromEquirectangular(e,s);else return null;if(s.pmremVersion=e.pmremVersion,i.has(e)===!1){let n=()=>{e.removeEventListener("dispose",n);let o=i.get(e);o!==void 0&&(o.dispose(),i.delete(e))};e.addEventListener("dispose",n)}i.set(e,s)}return s.texture}function rG(e){let t=YE.get(e);return t===void 0&&(t=new WeakMap,YE.set(e,t)),t}var iG=class extends rr{static get type(){return"PMREMNode"}constructor(e,t=null,r=null){super("vec3"),this._value=e,this._pmrem=null,this.uvNode=t,this.levelNode=r,this._generator=null;let i=new ji;i.isRenderTargetTexture=!0,this._texture=Ot(i),this._width=Qe(0),this._height=Qe(0),this._maxMip=Qe(0),this.updateBeforeType=ut.RENDER}set value(e){this._value=e,this._pmrem=null}get value(){return this._value}updateFromTexture(e){let t=eG(e.image.height);this._texture.value=e,this._width.value=t.texelWidth,this._height.value=t.texelHeight,this._maxMip.value=t.maxMip}updateBefore(e){let t=this._pmrem,r=t?t.pmremVersion:-1,i=this._value;r!==i.pmremVersion&&(i.isPMREMTexture===!0||i.mapping===Df?t=i:t=tG(i,e.renderer,this._generator),t!==null&&(this._pmrem=t,this.updateFromTexture(t)))}setup(e){this._generator===null&&(this._generator=new ZV(e.renderer)),this.updateBefore(e);let t=this.uvNode;t===null&&e.context.getUV&&(t=e.context.getUV(this,e)),t=this._pmrem.isRenderTargetTexture?I0.mul(K(t.x,t.y.negate(),t.z)):I0.mul(t);let r=this.levelNode;return r===null&&e.context.getTextureLevel&&(r=e.context.getTextureLevel(this)),VE(this._texture,t,r,this._width,this._height,this._maxMip)}dispose(){super.dispose(),this._generator!==null&&this._generator.dispose()}};function sG(e){if(e==null)return!1;let t=0,r=6;for(let i=0;i0}var cS=Mt(iG).setParameterLength(1,3),ZE=new WeakMap,nG=class extends Ed{static get type(){return"EnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){let{material:t}=e,r=this.envNode;if(r.isTextureNode||r.isMaterialReferenceNode){let u=r.isTextureNode?r.value:t[r.property],h=this._getPMREMNodeCache(e.renderer),d=h.get(u);d===void 0&&(d=cS(u),h.set(u,d)),r=d}let i=t.useAnisotropy===!0||t.anisotropy>0?pR:Ut,s=r.context(JE(_n,i)).mul(B0),a=r.context(oG(vl)).mul(Math.PI).mul(B0),n=wd(s),o=wd(a);e.context.radiance.addAssign(n),e.context.iblIrradiance.addAssign(o);let l=e.context.lightingModel.clearcoatRadiance;if(l){let u=r.context(JE(Td,bl)).mul(B0),h=wd(u);l.addAssign(h)}}_getPMREMNodeCache(e){let t=ZE.get(e);return t===void 0&&(t=new WeakMap,ZE.set(e,t)),t}},JE=(e,t)=>{let r=null;return{getUV:()=>(r===null&&(r=ar.negate().reflect(t),r=Gb(e).mix(r,t).normalize(),r=r.transformDirection(Ip)),r),getTextureLevel:()=>e}},oG=e=>({getUV:()=>e,getTextureLevel:()=>D(1)}),lG=new AN,pS=class extends Pt{static get type(){return"MeshStandardNodeMaterial"}constructor(e){super(),this.isMeshStandardNodeMaterial=!0,this.lights=!0,this.emissiveNode=null,this.metalnessNode=null,this.roughnessNode=null,this.setDefaultValues(lG),this.setValues(e)}setupEnvironment(e){let t=super.setupEnvironment(e);return t===null&&e.environmentNode&&(t=e.environmentNode),t?new nG(t):null}setupLightingModel(){return new kE}setupSpecular(){let e=Ct(K(.04),Zt.rgb,yo);cl.assign(K(.04)),Ru.assign(e),Eu.assign(1)}setupVariants(){let e=this.metalnessNode?D(this.metalnessNode):_R;yo.assign(e);let t=this.roughnessNode?D(this.roughnessNode):SR;t=ZT({roughness:t}),_n.assign(t),this.setupSpecular(),Au.assign(Zt.rgb.mul(e.oneMinus()))}},uG=new RO,mS=class extends pS{static get type(){return"MeshPhysicalNodeMaterial"}constructor(e){super(),this.isMeshPhysicalNodeMaterial=!0,this.clearcoatNode=null,this.clearcoatRoughnessNode=null,this.clearcoatNormalNode=null,this.sheenNode=null,this.sheenRoughnessNode=null,this.iridescenceNode=null,this.iridescenceIORNode=null,this.iridescenceThicknessNode=null,this.specularIntensityNode=null,this.specularColorNode=null,this.iorNode=null,this.transmissionNode=null,this.thicknessNode=null,this.attenuationDistanceNode=null,this.attenuationColorNode=null,this.dispersionNode=null,this.anisotropyNode=null,this.setDefaultValues(uG),this.setValues(e)}get useClearcoat(){return this.clearcoat>0||this.clearcoatNode!==null}get useIridescence(){return this.iridescence>0||this.iridescenceNode!==null}get useSheen(){return this.sheen>0||this.sheenNode!==null}get useAnisotropy(){return this.anisotropy>0||this.anisotropyNode!==null}get useTransmission(){return this.transmission>0||this.transmissionNode!==null}get useDispersion(){return this.dispersion>0||this.dispersionNode!==null}setupSpecular(){let e=this.iorNode?D(this.iorNode):DR;Rp.assign(e),cl.assign(Rs(Vb(Rp.sub(1).div(Rp.add(1))).mul(TR),K(1)).mul(RT)),Ru.assign(Ct(cl,Zt.rgb,yo)),Eu.assign(Ct(RT,1,yo))}setupLightingModel(){return new kE(this.useClearcoat,this.useSheen,this.useIridescence,this.useAnisotropy,this.useTransmission,this.useDispersion)}setupVariants(e){if(super.setupVariants(e),this.useClearcoat){let t=this.clearcoatNode?D(this.clearcoatNode):MR,r=this.clearcoatRoughnessNode?D(this.clearcoatRoughnessNode):NR;s0.assign(t),Td.assign(ZT({roughness:r}))}if(this.useSheen){let t=this.sheenNode?K(this.sheenNode):RR,r=this.sheenRoughnessNode?D(this.sheenRoughnessNode):ER;Ws.assign(t),hl.assign(r)}if(this.useIridescence){let t=this.iridescenceNode?D(this.iridescenceNode):BR,r=this.iridescenceIORNode?D(this.iridescenceIORNode):IR,i=this.iridescenceThicknessNode?D(this.iridescenceThicknessNode):FR;a0.assign(t),n0.assign(r),o0.assign(i)}if(this.useAnisotropy){let t=(this.anisotropyNode?ke(this.anisotropyNode):PR).toVar();dl.assign(t.length()),et(dl.equal(0),()=>{t.assign(ke(1,0))}).Else(()=>{t.divAssign(ke(dl)),dl.assign(dl.saturate())}),l0.assign(dl.pow2().mix(_n.pow2(),1)),Ap.assign(Uu[0].mul(t.x).add(Uu[1].mul(t.y))),Cu.assign(Uu[1].mul(t.x).sub(Uu[0].mul(t.y)))}if(this.useTransmission){let t=this.transmissionNode?D(this.transmissionNode):LR,r=this.thicknessNode?D(this.thicknessNode):kR,i=this.attenuationDistanceNode?D(this.attenuationDistanceNode):OR,s=this.attenuationColorNode?K(this.attenuationColorNode):UR;if(h0.assign(t),Mb.assign(r),Nb.assign(i),Ab.assign(s),this.useDispersion){let a=this.dispersionNode?D(this.dispersionNode):VR;Cb.assign(a)}}}setupClearcoatNormal(){return this.clearcoatNormalNode?K(this.clearcoatNormalNode):AR}setup(e){e.context.setupClearcoatNormal=()=>Iu(this.setupClearcoatNormal(e),"NORMAL","vec3"),super.setup(e)}},hG=Q(({normal:e,lightDirection:t,builder:r})=>{let i=e.dot(t),s=ke(i.mul(.5).add(.5),0);if(r.material.gradientMap){let a=To("gradientMap","texture").context({getUV:()=>s});return K(a.r)}else{let a=s.fwidth().mul(.5);return Ct(K(.7),K(1),Hs(D(.7).sub(a.x),D(.7).add(a.x),s.x))}}),dG=class extends $0{direct({lightDirection:e,lightColor:t,reflectedLight:r},i){let s=hG({normal:P0,lightDirection:e,builder:i}).mul(t);r.directDiffuse.addAssign(s.mul(Wu({diffuseColor:Zt.rgb})))}indirect(e){let{ambientOcclusion:t,irradiance:r,reflectedLight:i}=e.context;i.indirectDiffuse.addAssign(r.mul(Wu({diffuseColor:Zt}))),i.indirectDiffuse.mulAssign(t)}},cG=new PO,pG=class extends Pt{static get type(){return"MeshToonNodeMaterial"}constructor(e){super(),this.isMeshToonNodeMaterial=!0,this.lights=!0,this.setDefaultValues(cG),this.setValues(e)}setupLightingModel(){return new dG}},QE=Q(()=>{let e=K(ar.z,0,ar.x.negate()).normalize(),t=ar.cross(e);return ke(e.dot(Ut),t.dot(Ut)).mul(.495).add(.5)}).once(["NORMAL","VERTEX"])().toVar("matcapUV"),mG=new FO,fG=class extends Pt{static get type(){return"MeshMatcapNodeMaterial"}constructor(e){super(),this.isMeshMatcapNodeMaterial=!0,this.setDefaultValues(mG),this.setValues(e)}setupVariants(e){let t=QE,r;e.material.matcap?r=To("matcap","texture").context({getUV:()=>t}):r=K(Ct(.2,.8,t.y)),Zt.rgb.mulAssign(r.rgb)}},gG=class extends rr{static get type(){return"RotateNode"}constructor(e,t){super(),this.positionNode=e,this.rotationNode=t}generateNodeType(e){return this.positionNode.getNodeType(e)}setup(e){let{rotationNode:t,positionNode:r}=this;if(this.getNodeType(e)==="vec2"){let i=t.cos(),s=t.sin();return i0(i,s,s.negate(),i).mul(r)}else{let i=t,s=ul(Ve(1,0,0,0),Ve(0,Ua(i.x),xs(i.x).negate(),0),Ve(0,xs(i.x),Ua(i.x),0),Ve(0,0,0,1)),a=ul(Ve(Ua(i.y),0,xs(i.y),0),Ve(0,1,0,0),Ve(xs(i.y).negate(),0,Ua(i.y),0),Ve(0,0,0,1)),n=ul(Ve(Ua(i.z),xs(i.z).negate(),0,0),Ve(xs(i.z),Ua(i.z),0,0),Ve(0,0,1,0),Ve(0,0,0,1));return s.mul(a).mul(n).mul(Ve(r,1)).xyz}}},Gp=Mt(gG).setParameterLength(2),yG=new D4,KE=class extends Pt{static get type(){return"SpriteNodeMaterial"}constructor(e){super(),this.isSpriteNodeMaterial=!0,this._useSizeAttenuation=!0,this.positionNode=null,this.rotationNode=null,this.scaleNode=null,this.transparent=!0,this.setDefaultValues(yG),this.setValues(e)}setupPositionView(e){let{object:t,camera:r}=e,{positionNode:i,rotationNode:s,scaleNode:a,sizeAttenuation:n}=this,o=Cn.mul(K(i||0)),l=ke(ga[0].xyz.length(),ga[1].xyz.length());a!==null&&(l=l.mul(ke(a))),r.isPerspectiveCamera&&n===!1&&(l=l.mul(o.z.negate()));let u=Ji.xy;if(t.center&&t.center.isVector2===!0){let c=x6("center","vec2",t);u=u.sub(c.sub(.5))}u=u.mul(l);let h=D(s||CR),d=Gp(u,h);return Ve(o.xy.add(d),o.zw)}get sizeAttenuation(){return this._useSizeAttenuation}set sizeAttenuation(e){this._useSizeAttenuation!==e&&(this._useSizeAttenuation=e,this.needsUpdate=!0)}},xG=new W4,vG=new fe,bG=class extends KE{static get type(){return"PointsNodeMaterial"}constructor(e){super(),this.sizeNode=null,this.isPointsNodeMaterial=!0,this.setDefaultValues(xG),this.setValues(e)}setupPositionView(){let{positionNode:e}=this;return Cn.mul(K(e||wr)).xyz}setupVertexSprite(e){let{material:t,camera:r}=e,{rotationNode:i,scaleNode:s,sizeNode:a,sizeAttenuation:n}=this,o=super.setupVertex(e);if(t.isNodeMaterial!==!0)return o;let l=a!==null?ke(a):zR;l=l.mul(aT),r.isPerspectiveCamera&&n===!0&&(l=l.mul(TG.div(Wr.z.negate()))),s&&s.isNode&&(l=l.mul(ke(s)));let u=Ji.xy;if(i&&i.isNode){let h=D(i);u=Gp(u,h)}return u=u.mul(l),u=u.div(nT.div(2)),u=u.mul(o.w),o=o.add(Ve(u,0,0)),o}setupVertex(e){return e.object.isPoints?super.setupVertex(e):this.setupVertexSprite(e)}get alphaToCoverage(){return this._useAlphaToCoverage}set alphaToCoverage(e){this._useAlphaToCoverage!==e&&(this._useAlphaToCoverage=e,this.needsUpdate=!0)}},TG=Qe(1).onFrameUpdate(function({renderer:e}){let t=e.getSize(vG);this.value=.5*t.y}),SG=class extends $0{constructor(){super(),this.shadowNode=D(1).toVar("shadowMask")}direct({lightNode:e}){e.shadowNode!==null&&this.shadowNode.mulAssign(e.shadowNode)}finish({context:e}){Zt.a.mulAssign(this.shadowNode.oneMinus()),e.outgoingLight.rgb.assign(Zt.rgb)}},_G=new CO,wG=class extends Pt{static get type(){return"ShadowNodeMaterial"}constructor(e){super(),this.isShadowNodeMaterial=!0,this.lights=!0,this.transparent=!0,this.setDefaultValues(_G),this.setValues(e)}setupLightingModel(){return new SG}},N0e=go("vec3"),A0e=go("vec3"),C0e=go("vec3"),MG=class{constructor(e,t,r){this.renderer=e,this.nodes=t,this.info=r,this._context=typeof self<"u"?self:null,this._animationLoop=null,this._requestId=null}start(){let e=(t,r)=>{this._requestId=this._context.requestAnimationFrame(e),this.info.autoReset===!0&&this.info.reset(),this.nodes.nodeFrame.update(),this.info.frame=this.nodes.nodeFrame.frameId,this.renderer._inspector.begin(),this._animationLoop!==null&&this._animationLoop(t,r),this.renderer._inspector.finish()};e()}stop(){this._context!==null&&this._context.cancelAnimationFrame(this._requestId),this._requestId=null}getAnimationLoop(){return this._animationLoop}setAnimationLoop(e){this._animationLoop=e}getContext(){return this._context}setContext(e){this._context=e}dispose(){this.stop()}},Ml=class{constructor(){this.weakMaps={}}_getWeakMap(e){let t=e.length,r=this.weakMaps[t];return r===void 0&&(r=new WeakMap,this.weakMaps[t]=r),r}get(e){let t=this._getWeakMap(e);for(let r=0;r{this.dispose()},this.onGeometryDispose=()=>{this.attributes=null,this.attributesId=null},this.material.addEventListener("dispose",this.onMaterialDispose),this.geometry.addEventListener("dispose",this.onGeometryDispose),this._sourceMaterial!==null&&this._sourceMaterial.addEventListener("dispose",this.onMaterialDispose)}updateClipping(e){this.clippingContext=e}get clippingNeedsUpdate(){return this.clippingContext===null||this.clippingContext.cacheKey===this.clippingContextCacheKey?!1:(this.clippingContextCacheKey=this.clippingContext.cacheKey,!0)}get hardwareClippingPlanes(){return this.getNodeBuilderState().hardwareClipping===!0?this.clippingContext.unionClippingCount:0}getNodeBuilderState(){return this._nodeBuilderState||(this._nodeBuilderState=this._nodes.getForRender(this))}getMonitor(){return this._monitor||(this._monitor=this.getNodeBuilderState().observer)}getBindings(){return this._bindings||(this._bindings=this.getNodeBuilderState().createBindings())}getBindingGroup(e){for(let t of this.getBindings())if(t.name===e)return t}getIndex(){return this._geometries.getIndex(this)}getIndirect(){return this._geometries.getIndirect(this)}getIndirectOffset(){return this._geometries.getIndirectOffset(this)}getChainArray(){return[this.object,this.material,this.context,this.lightsNode]}setGeometry(e){this.geometry=e,this.attributes=null,this.attributesId=null}getAttributes(){if(this.attributes!==null)return this.attributes;let e=this.getNodeBuilderState().nodeAttributes,t=this.geometry,r=[],i=new Set,s={};for(let a of e){let n;if(a.node&&a.node.attribute?n=a.node.attribute:(n=t.getAttribute(a.name),n!==void 0&&(n.isInterleavedBufferAttribute?s[a.name]=n.data.uuid:s[a.name]=n.id)),n===void 0)continue;r.push(n);let o=n.isInterleavedBufferAttribute?n.data:n;i.add(o)}return this.attributes=r,this.attributesId=s,this.vertexBuffers=Array.from(i.values()),r}getVertexBuffers(){return this.vertexBuffers===null&&this.getAttributes(),this.vertexBuffers}getDrawParameters(){let{object:e,material:t,geometry:r,group:i,drawRange:s}=this,a=this.drawParams||(this.drawParams={vertexCount:0,firstVertex:0,instanceCount:0,firstInstance:0}),n=this.getIndex(),o=n!==null,l=1;if(r.isInstancedBufferGeometry===!0?l=r.instanceCount:e.count!==void 0&&(l=Math.max(0,e.count)),l===0)return null;if(a.instanceCount=l,e.isBatchedMesh===!0)return a;let u=1;t.wireframe===!0&&!e.isPoints&&!e.isLineSegments&&!e.isLine&&!e.isLineLoop&&(u=2);let h=s.start*u,d=(s.start+s.count)*u;i!==null&&(h=Math.max(h,i.start*u),d=Math.min(d,(i.start+i.count)*u));let c=r.attributes.position,m=1/0;o?m=n.count:c!=null&&(m=c.count),h=Math.max(h,0),d=Math.min(d,m);let g=d-h;return g<0||g===1/0?null:(a.vertexCount=g,a.firstVertex=h,a)}getGeometryCacheKey(){let{geometry:e}=this,t="";for(let r of Object.keys(e.attributes).sort()){let i=e.attributes[r];t+=r+",",i.data&&(t+=i.data.stride+","),i.offset&&(t+=i.offset+","),i.itemSize&&(t+=i.itemSize+","),i.normalized&&(t+="n,")}for(let r of Object.keys(e.morphAttributes).sort()){let i=e.morphAttributes[r];t+="morph-"+r+",";for(let s=0,a=i.length;s1)&&(i+=e.uuid+","),i+=this.context.id+",",i+=e.receiveShadow+",",yd(i)}get needsGeometryUpdate(){if(this.geometry.id!==this.object.geometry.id)return!0;if(this.attributes!==null){let e=this.attributesId;for(let t in e){let r=this.geometry.getAttribute(t);if(r===void 0)return!0;let i=r.isInterleavedBufferAttribute?r.data.uuid:r.id;if(e[t]!==i)return!0}}return!1}get needsUpdate(){return this.initialNodesCacheKey!==this.getDynamicCacheKey()||this.clippingNeedsUpdate}getDynamicCacheKey(){let e=0;return this.material.isShadowPassMaterial!==!0&&(e=this._nodes.getCacheKey(this.scene,this.lightsNode)),this.camera.isArrayCamera&&(e=_p(e,this.camera.cameras.length)),this.object.receiveShadow&&(e=_p(e,1)),e=_p(e,this.renderer.contextNode.id,this.renderer.contextNode.version),e}getCacheKey(){return this.getMaterialCacheKey()+this.getDynamicCacheKey()}dispose(){this.material.removeEventListener("dispose",this.onMaterialDispose),this.geometry.removeEventListener("dispose",this.onGeometryDispose),this._sourceMaterial!==null&&this._sourceMaterial.removeEventListener("dispose",this.onMaterialDispose),this.onDispose()}},Pn=[],RG=class{constructor(e,t,r,i,s,a){this.renderer=e,this.nodes=t,this.geometries=r,this.pipelines=i,this.bindings=s,this.info=a,this.chainMaps={}}get(e,t,r,i,s,a,n,o){let l=this.getChainMap(o);Pn[0]=e,Pn[1]=t,Pn[2]=a,Pn[3]=s;let u=l.get(Pn);return u===void 0?(u=this.createRenderObject(this.nodes,this.geometries,this.renderer,e,t,r,i,s,a,n,o),l.set(Pn,u)):(u.camera=i,u.updateClipping(n),u.needsGeometryUpdate&&u.setGeometry(e.geometry),(u.version!==t.version||u.needsUpdate)&&(u.initialCacheKey!==u.getCacheKey()?(u.dispose(),u=this.get(e,t,r,i,s,a,n,o)):u.version=t.version)),Pn[0]=null,Pn[1]=null,Pn[2]=null,Pn[3]=null,u}getChainMap(e="default"){return this.chainMaps[e]||(this.chainMaps[e]=new Ml)}dispose(){this.chainMaps={}}createRenderObject(e,t,r,i,s,a,n,o,l,u,h){let d=this.getChainMap(h),c=new CG(e,t,r,i,s,a,n,o,l,u);return c.onDispose=()=>{this.pipelines.delete(c),this.bindings.deleteForRender(c),this.nodes.delete(c),d.delete(c.getChainArray())},c}},Nl=class{constructor(){this.data=new WeakMap}get(e){let t=this.data.get(e);return t===void 0&&(t={},this.data.set(e,t)),t}delete(e){let t=null;return this.data.has(e)&&(t=this.data.get(e),this.data.delete(e)),t}has(e){return this.data.has(e)}dispose(){this.data=new WeakMap}},ya={VERTEX:1,INDEX:2,STORAGE:3,INDIRECT:4},Al=16,EG=211,PG=212,BG=class extends Nl{constructor(e,t){super(),this.backend=e,this.info=t}delete(e){let t=super.delete(e);return t!==null&&(this.backend.destroyAttribute(e),this.info.destroyAttribute(e)),t}update(e,t){let r=this.get(e);if(r.version===void 0)t===ya.VERTEX?(this.backend.createAttribute(e),this.info.createAttribute(e)):t===ya.INDEX?(this.backend.createIndexAttribute(e),this.info.createIndexAttribute(e)):t===ya.STORAGE?(this.backend.createStorageAttribute(e),this.info.createStorageAttribute(e)):t===ya.INDIRECT&&(this.backend.createIndirectStorageAttribute(e),this.info.createIndirectStorageAttribute(e)),r.version=this._getBufferAttribute(e).version;else{let i=this._getBufferAttribute(e);(r.version=65535?iN:rN)(t,1);return s.version=tP(e),s.__id=rP(e),s}var IG=class extends Nl{constructor(e,t){super(),this.attributes=e,this.info=t,this.wireframes=new WeakMap,this.attributeCall=new WeakMap,this._geometryDisposeListeners=new Map}has(e){let t=e.geometry;return super.has(t)&&this.get(t).initialized===!0}updateForRender(e){this.has(e)===!1&&this.initGeometry(e),this.updateAttributes(e)}initGeometry(e){let t=e.geometry,r=this.get(t);r.initialized=!0,this.info.memory.geometries++;let i=()=>{this.info.memory.geometries--;let s=t.index,a=e.getAttributes();s!==null&&this.attributes.delete(s);for(let o of a)this.attributes.delete(o);let n=this.wireframes.get(t);n!==void 0&&this.attributes.delete(n),t.removeEventListener("dispose",i),this._geometryDisposeListeners.delete(t)};t.addEventListener("dispose",i),this._geometryDisposeListeners.set(t,i)}updateAttributes(e){let t=e.getAttributes();for(let s of t)s.isStorageBufferAttribute||s.isStorageInstancedBufferAttribute?this.updateAttribute(s,ya.STORAGE):this.updateAttribute(s,ya.VERTEX);let r=this.getIndex(e);r!==null&&this.updateAttribute(r,ya.INDEX);let i=e.geometry.indirect;i!==null&&this.updateAttribute(i,ya.INDIRECT)}updateAttribute(e,t){let r=this.info.render.calls;e.isInterleavedBufferAttribute?this.attributeCall.get(e)===void 0?(this.attributes.update(e,t),this.attributeCall.set(e,r)):this.attributeCall.get(e.data)!==r&&(this.attributes.update(e,t),this.attributeCall.set(e.data,r),this.attributeCall.set(e,r)):this.attributeCall.get(e)!==r&&(this.attributes.update(e,t),this.attributeCall.set(e,r))}getIndirect(e){return e.geometry.indirect}getIndirectOffset(e){return e.geometry.indirectOffset}getIndex(e){let{geometry:t,material:r}=e,i=t.index;if(r.wireframe===!0){let s=this.wireframes,a=s.get(t);a===void 0?(a=iP(t),s.set(t,a)):(a.version!==tP(t)||a.__id!==rP(t))&&(this.attributes.delete(a),a=iP(t),s.set(t,a)),i=a}return i}dispose(){for(let[e,t]of this._geometryDisposeListeners.entries())e.removeEventListener("dispose",t);this._geometryDisposeListeners.clear()}},FG=class{constructor(){this.autoReset=!0,this.frame=0,this.calls=0,this.render={calls:0,frameCalls:0,drawCalls:0,triangles:0,points:0,lines:0,timestamp:0},this.compute={calls:0,frameCalls:0,timestamp:0},this.memory={attributes:0,attributesSize:0,geometries:0,indexAttributes:0,indexAttributesSize:0,indirectStorageAttributes:0,indirectStorageAttributesSize:0,programs:0,programsSize:0,readbackBuffers:0,readbackBuffersSize:0,renderTargets:0,storageAttributes:0,storageAttributesSize:0,textures:0,texturesSize:0,uniformBuffers:0,uniformBuffersSize:0,total:0},this.memoryMap=new Map}update(e,t,r){this.render.drawCalls++,e.isMesh||e.isSprite?this.render.triangles+=r*(t/3):e.isPoints?this.render.points+=r*t:e.isLineSegments?this.render.lines+=r*(t/2):e.isLine?this.render.lines+=r*(t-1):Ce("WebGPUInfo: Unknown object type.")}reset(){this.render.drawCalls=0,this.render.frameCalls=0,this.compute.frameCalls=0,this.render.triangles=0,this.render.points=0,this.render.lines=0}dispose(){this.reset(),this.calls=0,this.render.calls=0,this.compute.calls=0,this.render.timestamp=0,this.compute.timestamp=0;for(let e in this.memory)this.memory[e]=0;this.memoryMap.clear()}createTexture(e){let t=this._getTextureMemorySize(e);this.memoryMap.set(e,t),this.memory.textures++,this.memory.total+=t,this.memory.texturesSize+=t}destroyTexture(e){let t=this.memoryMap.get(e)||0;this.memoryMap.delete(e),this.memory.textures--,this.memory.total-=t,this.memory.texturesSize-=t}_createAttribute(e,t){let r=this._getAttributeMemorySize(e);this.memoryMap.set(e,{size:r,type:t}),this.memory[t]++,this.memory.total+=r,this.memory[t+"Size"]+=r}createAttribute(e){this._createAttribute(e,"attributes")}createIndexAttribute(e){this._createAttribute(e,"indexAttributes")}createStorageAttribute(e){this._createAttribute(e,"storageAttributes")}createIndirectStorageAttribute(e){this._createAttribute(e,"indirectStorageAttributes")}destroyAttribute(e){let t=this.memoryMap.get(e);t&&(this.memoryMap.delete(e),this.memory[t.type]--,this.memory.total-=t.size,this.memory[t.type+"Size"]-=t.size)}createReadbackBuffer(e){let t=e.maxByteLength;this.memoryMap.set(e,{size:t,type:"readbackBuffers"}),this.memory.readbackBuffers++,this.memory.total+=t,this.memory.readbackBuffersSize+=t}destroyReadbackBuffer(e){let{size:t}=this.memoryMap.get(e);this.memoryMap.delete(e),this.memory.readbackBuffers--,this.memory.total-=t,this.memory.readbackBuffersSize-=t}createUniformBuffer(e){let t=e.byteLength;this.memoryMap.set(e,{size:t,type:"uniformBuffers"}),this.memory.uniformBuffers++,this.memory.total+=t,this.memory.uniformBuffersSize+=t}destroyUniformBuffer(e){let t=this.memoryMap.get(e);t&&(this.memoryMap.delete(e),this.memory.uniformBuffers--,this.memory.total-=t.size,this.memory.uniformBuffersSize-=t.size)}createProgram(e){let t=e.code.length;this.memoryMap.set(e,t),this.memory.programs++,this.memory.total+=t,this.memory.programsSize+=t}destroyProgram(e){let t=this.memoryMap.get(e)||0;this.memoryMap.delete(e),this.memory.programs--,this.memory.total-=t,this.memory.programsSize-=t}_getTextureMemorySize(e){if(e.isCompressedTexture)return 1;let t=1;e.type===cu||e.type===Si?t=1:e.type===pu||e.type===Ko||e.type===Dt?t=2:(e.type===ci||e.type===gr||e.type===Er)&&(t=4);let r=4;e.format===ov||e.format===io||e.format===jh||e.format===ua||e.format===ln?r=1:e.format===ha||e.format===Hh?r=2:(e.format===Wh||e.format===lv)&&(r=3);let i=t*r;e.type===av||e.type===nv?i=2:(e.type===ro||e.type===Of||e.type===Uf)&&(i=4);let s=e.width||1,a=e.height||1,n=e.isCubeTexture?6:e.depth||1,o=s*a*n*i,l=e.mipmaps;if(l&&l.length>0){let u=0;for(let h=0;h>h),m=d.height||Math.max(1,a>>h);u+=c*m*n*i}}o+=u}else e.generateMipmaps&&(o=o*1.333);return Math.round(o)}_getAttributeMemorySize(e){return e.isInterleavedBufferAttribute&&(e=e.data),e.array?e.array.byteLength:e.count&&e.itemSize?e.count*e.itemSize*4:0}},sP=class{constructor(e){this.cacheKey=e,this.usedTimes=0}},LG=class extends sP{constructor(e,t,r){super(e),this.vertexProgram=t,this.fragmentProgram=r}},kG=class extends sP{constructor(e,t){super(e),this.computeProgram=t,this.isComputePipeline=!0}},DG=0,fS=class{constructor(e,t,r,i=null,s=null){this.id=DG++,this.code=e,this.stage=t,this.name=r,this.transforms=i,this.attributes=s,this.usedTimes=0}},OG=class extends Nl{constructor(e,t,r){super(),this.backend=e,this.nodes=t,this.info=r,this.bindings=null,this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}getForCompute(e,t){let{backend:r}=this,i=this.get(e);if(this._needsComputeUpdate(e)){let s=i.pipeline;s&&(s.usedTimes--,s.computeProgram.usedTimes--);let a=this.nodes.getForCompute(e),n=this.programs.compute.get(a.computeShader);n===void 0&&(s&&s.computeProgram.usedTimes===0&&this._releaseProgram(s.computeProgram),n=new fS(a.computeShader,"compute",e.name,a.transforms,a.nodeAttributes),this.programs.compute.set(a.computeShader,n),r.createProgram(n),this.info.createProgram(n));let o=this._getComputeCacheKey(e,n),l=this.caches.get(o);l===void 0&&(s&&s.usedTimes===0&&this._releasePipeline(s),l=this._getComputePipeline(e,n,o,t)),l.usedTimes++,n.usedTimes++,i.version=e.version,i.pipeline=l}return i.pipeline}getForRender(e,t=null){let{backend:r}=this,i=this.get(e);if(this._needsRenderUpdate(e)){let s=i.pipeline;s&&(s.usedTimes--,s.vertexProgram.usedTimes--,s.fragmentProgram.usedTimes--);let a=e.getNodeBuilderState(),n=e.material?e.material.name:"",o=this.programs.vertex.get(a.vertexShader);o===void 0&&(s&&s.vertexProgram.usedTimes===0&&this._releaseProgram(s.vertexProgram),o=new fS(a.vertexShader,"vertex",n),this.programs.vertex.set(a.vertexShader,o),r.createProgram(o),this.info.createProgram(o));let l=this.programs.fragment.get(a.fragmentShader);l===void 0&&(s&&s.fragmentProgram.usedTimes===0&&this._releaseProgram(s.fragmentProgram),l=new fS(a.fragmentShader,"fragment",n),this.programs.fragment.set(a.fragmentShader,l),r.createProgram(l),this.info.createProgram(l));let u=this._getRenderCacheKey(e,o,l),h=this.caches.get(u);h===void 0?(s&&s.usedTimes===0&&this._releasePipeline(s),h=this._getRenderPipeline(e,o,l,u,t)):e.pipeline=h,h.usedTimes++,o.usedTimes++,l.usedTimes++,i.pipeline=h}return i.pipeline}isReady(e){let t=this.get(e).pipeline;if(t===void 0)return!1;let r=this.backend.get(t);return r.pipeline!==void 0&&r.pipeline!==null}delete(e){let t=this.get(e).pipeline;return t&&(t.usedTimes--,t.usedTimes===0&&this._releasePipeline(t),t.isComputePipeline?(t.computeProgram.usedTimes--,t.computeProgram.usedTimes===0&&this._releaseProgram(t.computeProgram)):(t.fragmentProgram.usedTimes--,t.vertexProgram.usedTimes--,t.vertexProgram.usedTimes===0&&this._releaseProgram(t.vertexProgram),t.fragmentProgram.usedTimes===0&&this._releaseProgram(t.fragmentProgram))),super.delete(e)}dispose(){super.dispose(),this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}updateForRender(e){this.getForRender(e)}_getComputePipeline(e,t,r,i){r=r||this._getComputeCacheKey(e,t);let s=this.caches.get(r);return s===void 0&&(s=new kG(r,t),this.caches.set(r,s),this.backend.createComputePipeline(s,i)),s}_getRenderPipeline(e,t,r,i,s){i=i||this._getRenderCacheKey(e,t,r);let a=this.caches.get(i);return a===void 0&&(a=new LG(i,t,r),this.caches.set(i,a),e.pipeline=a,this.backend.createRenderPipeline(e,s)),a}_getComputeCacheKey(e,t){return e.id+","+t.id}_getRenderCacheKey(e,t,r){return t.id+","+r.id+","+this.backend.getRenderCacheKey(e)}_releasePipeline(e){this.caches.delete(e.cacheKey)}_releaseProgram(e){let t=e.code,r=e.stage;this.programs[r].delete(t),this.info.destroyProgram(e)}_needsComputeUpdate(e){let t=this.get(e);return t.pipeline===void 0||t.version!==e.version}_needsRenderUpdate(e){return this.get(e).pipeline===void 0||this.backend.needsRenderUpdate(e)}},UG=class extends Nl{constructor(e,t,r,i,s,a){super(),this.backend=e,this.textures=r,this.pipelines=s,this.attributes=i,this.nodes=t,this.info=a,this.pipelines.bindings=this}getForRender(e){let t=e.getBindings(),r=this.get(e);return r.initialized!==!0&&(this._createBindings(t),r.initialized=!0),t}getForCompute(e){let t=this.nodes.getForCompute(e).bindings,r=this.get(e);return(r.initialized!==!0||r.bindings!==t)&&(r.bindings!==void 0&&this._destroyBindings(r.bindings),this._createBindings(t),r.initialized=!0,r.bindings=t),t}updateForCompute(e){this._updateBindings(this.getForCompute(e))}updateForRender(e){this._updateBindings(this.getForRender(e))}deleteForCompute(e){let t=this.get(e).bindings||this.nodes.getForCompute(e).bindings;this._destroyBindings(t),this.delete(e)}deleteForRender(e){let t=e.getBindings();this._destroyBindings(t),this.delete(e)}_createBindings(e){for(let t of e){let r=this.get(t);if(r.bindGroup===void 0){for(let i of t.bindings)if(i.isUniformBuffer)this.backend.createUniformBuffer(i),this.info.createUniformBuffer(i);else if(i.isSampledTexture)this.textures.updateTexture(i.texture);else if(i.isSampler)this.textures.updateSampler(i);else if(i.isStorageBuffer){let s=i.attribute,a=s.isIndirectStorageBufferAttribute?ya.INDIRECT:ya.STORAGE;this.attributes.update(s,a)}this.backend.createBindings(t,e,0),r.bindGroup=t,r.usedTimes=1}else r.usedTimes++}}_destroyBindings(e){for(let t of e){let r=this.get(t);if(r.usedTimes--,r.usedTimes===0){for(let i of t.bindings)i.isUniformBuffer?(this.backend.destroyUniformBuffer(i),this.info.destroyUniformBuffer(i),i.release()):i.isSampler&&(i.isSampledTexture!==!0&&this.backend.destroySampler(i),i.release());this.backend.deleteBindGroupData(t),this.delete(t)}}}_updateBindings(e){for(let t of e)this._update(t,e)}_update(e,t){let{backend:r}=this,i=!1,s=!0,a=0,n=0;for(let o of e.bindings)if(this.nodes.updateGroup(o)!==!1){if(o.isStorageBuffer){let l=o.attribute,u=l.isIndirectStorageBufferAttribute?ya.INDIRECT:ya.STORAGE,h=r.get(o);this.attributes.update(l,u),h.attribute!==l&&(h.attribute=l,i=!0)}if(o.isUniformBuffer)o.update()&&r.updateBinding(o);else if(o.isSampledTexture){let l=o.update(),u=o.texture,h=this.textures.get(u);if(l&&(this.textures.updateTexture(u),o.generation!==h.generation&&(o.generation=h.generation,i=!0),h.bindGroups.add(e)),r.get(u).externalTexture!==void 0||h.isDefaultTexture?s=!1:(a=a*10+u.id,n+=u.version),u.isStorageTexture===!0&&u.mipmapsAutoUpdate===!0){let d=this.get(u);o.store===!0?d.needsMipmap=!0:this.textures.needsMipmaps(u)&&d.needsMipmap===!0&&(this.backend.generateMipmaps(u),d.needsMipmap=!1)}}else if(o.isSampler&&o.update()){let l=this.textures.updateSampler(o);o.samplerKey!==l&&(o.samplerKey=l,i=!0)}o.isBuffer&&o.updateRanges.length>0&&o.clearUpdateRanges()}i===!0&&this.backend.updateBindings(e,t,s?a:0,n)}},zG=Object.freeze([]);function VG(e,t){return e.groupOrder!==t.groupOrder?e.groupOrder-t.groupOrder:e.renderOrder!==t.renderOrder?e.renderOrder-t.renderOrder:e.z!==t.z?e.z-t.z:e.id-t.id}function aP(e,t){return e.groupOrder!==t.groupOrder?e.groupOrder-t.groupOrder:e.renderOrder!==t.renderOrder?e.renderOrder-t.renderOrder:e.z!==t.z?t.z-e.z:e.id-t.id}function nP(e){return(e.transmission>0||e.transmissionNode&&e.transmissionNode.isNode)&&e.side===hs&&e.forceSinglePass===!1}var GG=class{constructor(e,t,r){this.renderItems=[],this.renderItemsIndex=0,this.opaque=[],this.transparentDoublePass=[],this.transparent=[],this.bundles=[],this.lighting=e,this.lightsNode=e.getNode(t),this.lightsArray=[],this.scene=t,this.camera=r,this.occlusionQueryCount=0,this._lastOcclusionObject=null}begin(){return this.renderItemsIndex=0,this.opaque.length=0,this.transparentDoublePass.length=0,this.transparent.length=0,this.bundles.length=0,this.lightsArray.length=0,this.occlusionQueryCount=0,this}getNextRenderItem(e,t,r,i,s,a,n){let o=this.renderItems[this.renderItemsIndex];return o===void 0?(o={id:e.id,object:e,geometry:t,material:r,groupOrder:i,renderOrder:e.renderOrder,z:s,group:a,clippingContext:n},this.renderItems[this.renderItemsIndex]=o):(o.id=e.id,o.object=e,o.geometry=t,o.material=r,o.groupOrder=i,o.renderOrder=e.renderOrder,o.z=s,o.group=a,o.clippingContext=n),this.renderItemsIndex++,o}push(e,t,r,i,s,a,n){let o=this.getNextRenderItem(e,t,r,i,s,a,n);e.occlusionTest===!0&&this._lastOcclusionObject!==e&&(this.occlusionQueryCount++,this._lastOcclusionObject=e),r.transparent===!0||r.transmission>0||r.transmissionNode&&r.transmissionNode.isNode||r.backdropNode&&r.backdropNode.isNode?(nP(r)&&this.transparentDoublePass.push(o),this.transparent.push(o)):this.opaque.push(o)}unshift(e,t,r,i,s,a,n){let o=this.getNextRenderItem(e,t,r,i,s,a,n);r.transparent===!0||r.transmission>0||r.transmissionNode&&r.transmissionNode.isNode||r.backdropNode&&r.backdropNode.isNode?(nP(r)&&this.transparentDoublePass.unshift(o),this.transparent.unshift(o)):this.opaque.unshift(o)}pushBundle(e){this.bundles.push(e)}pushLight(e){this.lightsArray.push(e)}sort(e,t,r){this.opaque.length>1&&this.opaque.sort(e||VG),this.transparentDoublePass.length>1&&this.transparentDoublePass.sort(t||aP),this.transparent.length>1&&this.transparent.sort(t||aP),r&&(this.opaque.reverse(),this.transparentDoublePass.reverse(),this.transparent.reverse())}finish(){this.lightsNode.setLights(this.lighting.enabled?this.lightsArray:zG);for(let e=this.renderItemsIndex,t=this.renderItems.length;e>t,l=n.height>>t,u=e.depthTexture||s[t],h=e.depthBuffer===!0||e.stencilBuffer===!0,d=!1,c=u!==void 0&&u.image!==void 0&&u.image.depth>1,m=n.depth>1&&(e.useArrayDepthTexture||e.multiview||c);u===void 0&&h&&(u=new fs,u.format=e.stencilBuffer?ln:ua,u.type=e.stencilBuffer?ro:gr,u.image.width=o,u.image.height=l,u.image.depth=n.depth,u.renderTarget=e,s[t]=u),u&&(u.isArrayTexture=m),(r.width!==n.width||n.height!==r.height)&&(d=!0,u&&(u.needsUpdate=!0,u.image.width=o,u.image.height=l,u.image.depth=m?n.depth:1)),r.width=n.width,r.height=n.height,r.textures=a,r.depthTexture=u||null,r.depth=e.depthBuffer,r.stencil=e.stencilBuffer,r.renderTarget=e,r.sampleCount!==i&&(d=!0,u&&(u.needsUpdate=!0),r.sampleCount=i);let g={sampleCount:i};if(e.isXRRenderTarget!==!0){for(let y=0;y{this._destroyRenderTarget(e)},e.addEventListener("dispose",r.onDispose))}updateTexture(e,t={}){let r=this.get(e);if(r.initialized===!0&&r.version===e.version)return;let i=e.isRenderTargetTexture||e.isDepthTexture||e.isFramebufferTexture,s=this.backend;if(i&&r.initialized===!0&&s.destroyTexture(e),e.isFramebufferTexture){let l=this.renderer.getRenderTarget();l?e.type=l.texture.type:e.type=Si}if(e.isHTMLTexture&&e.image){let l=this.renderer.domElement;if("requestPaint"in l){if(l.hasAttribute("layoutsubtree")||l.setAttribute("layoutsubtree","true"),e.image.parentNode!==l&&l.appendChild(e.image),this._htmlTextures.size===0){let u=this._htmlTextures;l.onpaint=h=>{let d=h&&h.changedElements;for(let c of u)(!d||d.includes(c.image))&&(c.needsUpdate=!0)}}this._htmlTextures.add(e)}}let{width:a,height:n,depth:o}=this.getSize(e);if(t.width=a,t.height=n,t.depth=o,t.needsMipmaps=this.needsMipmaps(e),t.levels=t.needsMipmaps?this.getMipLevels(e,a,n):1,e.isCubeTexture&&e.mipmaps.length>0&&t.levels++,i||e.isStorageTexture===!0||e.isExternalTexture===!0)s.createTexture(e,t),r.generation=e.version;else if(e.version>0){let l=e.image;if(l===void 0)Ue("Renderer: Texture marked for update but image is undefined.");else if(l.complete===!1)Ue("Renderer: Texture marked for update but image is incomplete.");else{if(e.images){let h=[];for(let d of e.images)h.push(d);t.images=h}else t.image=l;(r.isDefaultTexture===void 0||r.isDefaultTexture===!0)&&(s.createTexture(e,t),r.isDefaultTexture=!1,r.generation=e.version),e.source.dataReady===!0&&s.updateTexture(e,t);let u=e.isStorageTexture===!0&&e.mipmapsAutoUpdate===!1;t.needsMipmaps&&e.mipmaps.length===0&&!u&&s.generateMipmaps(e),e.onUpdate&&e.onUpdate(e)}}else s.createDefaultTexture(e),r.isDefaultTexture=!0,r.generation=e.version;r.initialized!==!0&&(r.initialized=!0,r.generation=e.version,r.bindGroups=new Set,this.info.createTexture(e),e.isVideoTexture&&Gt.enabled===!0&&Gt.getTransfer(e.colorSpace)!==Tt&&Ue("WebGPURenderer: Video textures must use a color space with a sRGB transfer function, e.g. SRGBColorSpace."),r.onDispose=()=>{this._destroyTexture(e)},e.addEventListener("dispose",r.onDispose)),r.version=e.version}updateSampler(e){return this.backend.updateSampler(e)}getSize(e,t=$G){let r=e.images?e.images[0]:e.image;return r?(r.image!==void 0&&(r=r.image),e.isHTMLTexture?(t.width=r.offsetWidth||1,t.height=r.offsetHeight||1,t.depth=1):typeof HTMLVideoElement<"u"&&r instanceof HTMLVideoElement?(t.width=r.videoWidth||1,t.height=r.videoHeight||1,t.depth=1):typeof VideoFrame<"u"&&r instanceof VideoFrame?(t.width=r.displayWidth||1,t.height=r.displayHeight||1,t.depth=1):(t.width=r.width||1,t.height=r.height||1,t.depth=e.isCubeTexture?6:r.depth||1)):t.width=t.height=t.depth=1,t}getMipLevels(e,t,r){let i;return e.mipmaps.length>0?i=e.mipmaps.length:e.isCompressedTexture===!0?i=1:i=Math.floor(Math.log2(Math.max(t,r)))+1,i}needsMipmaps(e){return e.generateMipmaps===!0||e.mipmaps.length>0}_destroyRenderTarget(e){if(this.has(e)===!0){let t=this.get(e),r=t.textures,i=t.depthTexture;e.removeEventListener("dispose",t.onDispose);for(let s=0;s{i.isOverrideContextNode===!0&&e.push(i.value.overrideNodes)});let t=new Map(e.flatMap(i=>Array.from(i.entries()))),r=super.getFlowContextData();return r.overrideNodes=t,r}};function uP(e,t=null,r=null){if(t&&t.isNode){let i=t;t=()=>i}return new lP(new Map([[e,t]]),r)}xe("overrideNode",(e,t,r)=>uP(t,r,e));function hP(e,t=null){let r=new Map;for(let[i,s]of e){let a=s!==null?typeof s=="function"?s:()=>s:null;r.set(i,a)}return new lP(r,t)}xe("overrideNodes",(e,t)=>hP(t,e));var dP=class extends jt{static get type(){return"ParameterNode"}constructor(e,t=null){super(e,t),this.isParameterNode=!0}getMemberType(e,t){let r=this.getNodeType(e),i=e.getStructTypeNode(r),s;return i!==null?s=i.getMemberType(e,t):(Ce(`TSL: Member "${t}" not found in struct "${r}".`,new $r),s="float"),s}getHash(){return String(this.id)}generate(){return this.name}},YG=(e,t)=>new dP(e,t),ZG=class extends Ke{static get type(){return"StackNode"}constructor(e=null){super(),this.nodes=[],this.outputNode=null,this.parent=e,this._currentCond=null,this._expressionNode=null,this._currentNode=null,this._nodeDataLibrary=new Map,this.isStackNode=!0}getElementType(e){return this.outputNode?this.outputNode.getElementType(e):"void"}generateNodeType(e){return this.outputNode?this.outputNode.getNodeType(e):"void"}getMemberType(e,t){return this.outputNode?this.outputNode.getMemberType(e,t):"void"}addToStack(e,t=-1){if(e.isNode!==!0)return Ce("TSL: Invalid node added to stack.",new $r),this;if(t===-1)if(this._currentNode){let r=this._nodeDataLibrary.get(this._currentNode);r===void 0&&(r={delta:0},this._nodeDataLibrary.set(this._currentNode,r)),r.delta++,t=this.nodes.indexOf(this._currentNode)+r.delta}else t=this.nodes.length;return this.nodes.splice(t,0,e),this}addToStackBefore(e){let t=this._currentNode?this.nodes.indexOf(this._currentNode):0;return this.addToStack(e,t)}If(e,t){let r=new bd(t);return this._currentCond=Zi(e,r),this.addToStack(this._currentCond)}ElseIf(e,t){let r=new bd(t),i=Zi(e,r);return this._currentCond.elseNode=i,this._currentCond=i,this}Else(e){return this._currentCond.elseNode=new bd(e),this}Switch(e){return this._expressionNode=Ye(e),this}Case(...e){let t=[];if(e.length>=2)for(let n=0;ntypeof r=="string"?{name:t,type:r,atomic:!1}:{name:t,type:r.type,atomic:r.atomic||!1})}var Cl=class extends Ke{static get type(){return"StructTypeNode"}constructor(e,t=null){super("struct"),this.membersLayout=JG(e),this.name=t,this.isStructTypeNode=!0}getLength(){let e=1,t=0;for(let r of this.membersLayout){let i=r.type,s=NU(i),a=AU(i);e=Math.max(e,a);let n=t%e%a;n!==0&&(t+=a-n),t+=s}return Math.ceil(t/e)*e}getMemberType(e,t){let r=this.membersLayout.find(i=>i.name===t);return r?r.type:"void"}generateNodeType(e){return e.getStructTypeFromNode(this,this.membersLayout,this.name).name}setup(e){e.getStructTypeFromNode(this,this.membersLayout,this.name),e.addInclude(this)}generate(e){return this.getNodeType(e)}},QG=class extends Ke{static get type(){return"StructNode"}constructor(e,t){super("vec3"),this.structTypeNode=e,this.values=t,this.isStructNode=!0}generateNodeType(e){return this.structTypeNode.getNodeType(e)}getMemberType(e,t){return this.structTypeNode.getMemberType(e,t)}_getChildren(){let e=super._getChildren(),t=e.find(r=>r.childNode===this.structTypeNode);return e.splice(e.indexOf(t),1),e.push(t),e}generate(e){let t=e.getVarFromNode(this),r=t.type,i=e.getPropertyName(t);return e.addLineFlowCode(`${i} = ${e.generateStruct(r,this.structTypeNode.membersLayout,this.values)}`,this),t.name}},KG=(e,t=null)=>{let r=new Cl(e,t);return yb((...i)=>{let s=null;if(i.length>0)if(i[0].isNode){s={};let a=Object.keys(e);for(let n=0;nnew Wp(e,"int","float"),yP=e=>new Wp(e,"uint","float"),a8=e=>new Wp(e,"float","int"),n8=e=>new Wp(e,"float","uint"),sy={},_o=class Qx extends he{static get type(){return"BitcountNode"}constructor(t,r){super(t,r),this.isBitcountNode=!0}_resolveElementType(t,r,i){i==="int"?r.assign(gP(t,"uint")):r.assign(t)}_returnDataNode(t){switch(t){case"uint":return Ne;case"int":return Y;case"uvec2":return vb;case"uvec3":return Mu;case"uvec4":return _b;case"ivec2":return Pr;case"ivec3":return bb;case"ivec4":return Sb}}_createTrailingZerosBaseLayout(t,r){let i=this._returnDataNode(r);return Q(([s])=>{let a=Ne(0);this._resolveElementType(s,a,r);let n=D(a.bitAnd(kb(a))),o=yP(n).shiftRight(23).sub(127);return i(o)}).setLayout({name:t,type:r,inputs:[{name:"value",type:r}]})}_createLeadingZerosBaseLayout(t,r){let i=this._returnDataNode(r);return Q(([s])=>{et(s.equal(Ne(0)),()=>Ne(32));let a=Ne(0),n=Ne(0);return this._resolveElementType(s,a,r),et(a.shiftRight(16).equal(0),()=>{n.addAssign(16),a.shiftLeftAssign(16)}),et(a.shiftRight(24).equal(0),()=>{n.addAssign(8),a.shiftLeftAssign(8)}),et(a.shiftRight(28).equal(0),()=>{n.addAssign(4),a.shiftLeftAssign(4)}),et(a.shiftRight(30).equal(0),()=>{n.addAssign(2),a.shiftLeftAssign(2)}),et(a.shiftRight(31).equal(0),()=>{n.addAssign(1)}),i(n)}).setLayout({name:t,type:r,inputs:[{name:"value",type:r}]})}_createOneBitsBaseLayout(t,r){let i=this._returnDataNode(r);return Q(([s])=>{let a=Ne(0);this._resolveElementType(s,a,r),a.assign(a.sub(a.shiftRight(Ne(1)).bitAnd(Ne(1431655765)))),a.assign(a.bitAnd(Ne(858993459)).add(a.shiftRight(Ne(2)).bitAnd(Ne(858993459))));let n=a.add(a.shiftRight(Ne(4))).bitAnd(Ne(252645135)).mul(Ne(16843009)).shiftRight(Ne(24));return i(n)}).setLayout({name:t,type:r,inputs:[{name:"value",type:r}]})}_createMainLayout(t,r,i,s){let a=this._returnDataNode(r);return Q(([n])=>{if(i===1)return a(s(n));{let o=a(0),l=["x","y","z","w"];for(let u=0;ud(i))()}};_o.COUNT_TRAILING_ZEROS="countTrailingZeros",_o.COUNT_LEADING_ZEROS="countLeadingZeros",_o.COUNT_ONE_BITS="countOneBits";var o8=Ee(_o,_o.COUNT_TRAILING_ZEROS).setParameterLength(1),l8=Ee(_o,_o.COUNT_LEADING_ZEROS).setParameterLength(1),u8=Ee(_o,_o.COUNT_ONE_BITS).setParameterLength(1),h8=Q(([e])=>{let t=e.toUint().mul(747796405).add(2891336453),r=t.shiftRight(t.shiftRight(28).add(4)).bitXor(t).mul(277803737);return r.shiftRight(22).bitXor(r).toFloat().mul(1/2**32)}),yS=(e,t)=>ma(mt(4,e.mul(It(1,e))),t),d8=(e,t)=>e.lessThan(.5)?yS(e.mul(2),t).div(2):It(1,yS(mt(It(1,e),2),t).div(2)),c8=(e,t,r)=>ma(js(ma(e,t),Yr(ma(e,t),ma(It(1,e),r))),1/t),p8=(e,t)=>xs(m0.mul(t.mul(e).sub(1))).div(m0.mul(t.mul(e).sub(1))),xS=class extends rr{static get type(){return"PackFloatNode"}constructor(e,t){super(),this.vectorNode=t,this.encoding=e,this.isPackFloatNode=!0}generateNodeType(){return"uint"}generate(e){let t=this.vectorNode.getNodeType(e);return`${e.getFloatPackingMethod(this.encoding)}(${this.vectorNode.build(e,t)})`}},m8=Ee(xS,"snorm").setParameterLength(1),f8=Ee(xS,"unorm").setParameterLength(1),g8=Ee(xS,"float16").setParameterLength(1),vS=class extends rr{static get type(){return"UnpackFloatNode"}constructor(e,t){super(),this.uintNode=t,this.encoding=e,this.isUnpackFloatNode=!0}generateNodeType(){return"vec2"}generate(e){let t=this.uintNode.getNodeType(e);return`${e.getFloatUnpackingMethod(this.encoding)}(${this.uintNode.build(e,t)})`}},y8=Ee(vS,"snorm").setParameterLength(1),x8=Ee(vS,"unorm").setParameterLength(1),v8=Ee(vS,"float16").setParameterLength(1),wo=Q(([e])=>e.fract().sub(.5).abs()).setLayout({name:"tri",type:"float",inputs:[{name:"x",type:"float"}]}),b8=Q(([e])=>K(wo(e.z.add(wo(e.y.mul(1)))),wo(e.z.add(wo(e.x.mul(1)))),wo(e.y.add(wo(e.x.mul(1)))))).setLayout({name:"tri3",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),T8=Q(([e,t,r])=>{let i=K(e).toVar(),s=D(1.4).toVar(),a=D(0).toVar(),n=K(i).toVar();return Qt({start:D(0),end:D(3),type:"float",condition:"<="},()=>{let o=K(b8(n.mul(2))).toVar();i.addAssign(o.add(r.mul(D(.1).mul(t)))),n.mulAssign(1.8),s.mulAssign(1.5),i.mulAssign(1.2);let l=D(wo(i.z.add(wo(i.x.add(wo(i.y)))))).toVar();a.addAssign(l.div(s)),n.addAssign(.14)}),a}).setLayout({name:"triNoise3D",type:"float",inputs:[{name:"position",type:"vec3"},{name:"speed",type:"float"},{name:"time",type:"float"}]}),S8=class extends Ke{static get type(){return"FunctionOverloadingNode"}constructor(e=[],...t){super(),this.functionNodes=e,this.parametersNodes=t,this._candidateFn=null,this.global=!0}generateNodeType(e){return this.getCandidateFn(e).shaderNode.layout.type}getCandidateFn(e){let t=this.parametersNodes,r=this._candidateFn;if(r===null){let i=null,s=-1;for(let a of this.functionNodes){let n=a.shaderNode.layout;if(n===null)throw new Error("THREE.FunctionOverloadingNode: FunctionNode must be a layout.");let o=n.inputs;if(t.length===o.length){let l=0;for(let u=0;us&&(i=a,s=l)}}this._candidateFn=r=i}return r}setup(e){return this.getCandidateFn(e)(...this.parametersNodes)}},_8=Mt(S8),ki=e=>(...t)=>_8(e,...t),Fd=Qe(0).setGroup(st).onRenderUpdate(e=>e.time),w8=Qe(0).setGroup(st).onRenderUpdate(e=>e.deltaTime),xP=Qe(0,"uint").setGroup(st).onRenderUpdate(e=>e.frameId),M8=(e=Fd)=>e.add(.75).mul(Math.PI*2).sin().mul(.5).add(.5),N8=(e=Fd)=>e.fract().round(),A8=(e=Fd)=>e.add(.5).fract().mul(2).sub(1).abs(),C8=(e=Fd)=>e.fract();function R8(e,t=null){return vo(t,{getUV:typeof e=="function"?e:()=>e})}var E8=Q(([e,t,r=ke(.5)])=>Gp(e.sub(r),t).add(r)),P8=Q(([e,t,r=ke(.5)])=>{let i=e.sub(r),s=i.dot(i),a=s.mul(s).mul(t);return e.add(i.mul(a))}),B8=Q(({position:e=null,horizontal:t=!0,vertical:r=!1})=>{let i;e!==null?(i=ga.toVar(),i[3][0]=e.x,i[3][1]=e.y,i[3][2]=e.z):i=ga;let s=xl.mul(i);return vd(t)&&(s[0][0]=ga[0].length(),s[0][1]=0,s[0][2]=0),vd(r)&&(s[1][0]=0,s[1][1]=ga[1].length(),s[1][2]=0),s[2][0]=0,s[2][1]=0,s[2][2]=1,bs.mul(s).mul(wr)}),I8=Q(([e=null])=>{let t=H0();return H0(WT(e)).sub(t).lessThan(0).select(Ga,e)}),F8=Q(([e,t=Jt(),r=D(0)])=>{let i=e.x,s=e.y,a=r.mod(i.mul(s)).floor(),n=a.mod(i),o=s.sub(a.add(1).div(i).ceil()),l=e.reciprocal(),u=ke(n,o);return t.add(u).mul(l)}),vP=Q(([e,t=null,r=null,i=D(1),s=wr,a=Qi])=>{let n=a.abs().normalize();n=n.div(n.dot(K(1)));let o=s.yz.mul(i),l=s.zx.mul(i),u=s.xy.mul(i),h=e.value,d=t!==null?t.value:h,c=r!==null?r.value:h,m=Ot(h,o).mul(n.x),g=Ot(d,l).mul(n.y),y=Ot(c,u).mul(n.z);return Yr(m,g,y)}),L8=(...e)=>vP(...e),Ld=new fn,Hu=new F,kd=new F,bS=new F,jp=new We,ay=new F(0,0,-1),Bn=new Wt,Hp=new F,ny=new F,Xp=new Wt,oy=new fe,ly=new er,k8=Ga.flipX();ly.depthTexture=new fs(1,1);var uy=!1,D8=class iD extends An{static get type(){return"ReflectorNode"}constructor(t={}){super(t.defaultTexture||ly.texture,k8),this._reflectorBaseNode=t.reflector||new O8(this,t),this._depthNode=null,this.setUpdateMatrix(!1)}get reflector(){return this._reflectorBaseNode}get target(){return this._reflectorBaseNode.target}getDepthNode(){if(this._depthNode===null){if(this._reflectorBaseNode.depth!==!0)throw new Error("THREE.ReflectorNode: Depth node can only be requested when the reflector is created with { depth: true }. ");this._depthNode=new iD({defaultTexture:ly.depthTexture,reflector:this._reflectorBaseNode})}return this._depthNode}setup(t){return t.object.isQuadMesh||this._reflectorBaseNode.build(t),super.setup(t)}clone(){let t=new this.constructor(this.reflectorNode);return t.uvNode=this.uvNode,t.levelNode=this.levelNode,t.biasNode=this.biasNode,t.sampler=this.sampler,t.depthNode=this.depthNode,t.compareNode=this.compareNode,t.gradNode=this.gradNode,t.gatherNode=this.gatherNode,t.offsetNode=this.offsetNode,t._reflectorBaseNode=this._reflectorBaseNode,t}dispose(){super.dispose(),this._reflectorBaseNode.dispose()}},O8=class extends Ke{static get type(){return"ReflectorBaseNode"}constructor(e,t={}){super();let{target:r=new Hi,resolutionScale:i=1,generateMipmaps:s=!1,bounces:a=!0,depth:n=!1,samples:o=0}=t;this.textureNode=e,this.target=r,this.resolutionScale=i,t.resolution!==void 0&&(Et('ReflectorNode: The "resolution" parameter has been renamed to "resolutionScale".'),this.resolutionScale=t.resolution),this.generateMipmaps=s,this.bounces=a,this.depth=n,this.samples=o,this.updateBeforeType=a?ut.RENDER:ut.FRAME,this.virtualCameras=new WeakMap,this.renderTargets=new Map,this.forceUpdate=!1,this.hasOutput=!1}_updateResolution(e,t){let r=this.resolutionScale;t.getDrawingBufferSize(oy),e.setSize(Math.round(oy.width*r),Math.round(oy.height*r))}setup(e){return this._updateResolution(ly,e.renderer),super.setup(e)}dispose(){super.dispose();for(let e of this.renderTargets.values())e.dispose()}getVirtualCamera(e){let t=this.virtualCameras.get(e);return t===void 0&&(t=e.clone(),this.virtualCameras.set(e,t)),t}getRenderTarget(e){let t=this.renderTargets.get(e);return t===void 0&&(t=new er(0,0,{type:Dt,samples:this.samples}),this.generateMipmaps===!0&&(t.texture.minFilter=LD,t.texture.generateMipmaps=!0),this.depth===!0&&(t.depthTexture=new fs),this.renderTargets.set(e,t)),t}updateBefore(e){if(this.bounces===!1&&uy)return!1;uy=!0;let{scene:t,camera:r,renderer:i,material:s}=e,{target:a}=this,n=this.getVirtualCamera(r),o=this.getRenderTarget(n);i.getDrawingBufferSize(oy),this._updateResolution(o,i),kd.setFromMatrixPosition(a.matrixWorld),bS.setFromMatrixPosition(r.matrixWorld),jp.extractRotation(a.matrixWorld),Hu.set(0,0,1),Hu.applyMatrix4(jp),Hp.subVectors(kd,bS);let l=Hp.dot(Hu)>0,u=!1;if(l===!0&&this.forceUpdate===!1){if(this.hasOutput===!1){uy=!1;return}u=!0}Hp.reflect(Hu).negate(),Hp.add(kd),jp.extractRotation(r.matrixWorld),ay.set(0,0,-1),ay.applyMatrix4(jp),ay.add(bS),ny.subVectors(kd,ay),ny.reflect(Hu).negate(),ny.add(kd),n.coordinateSystem=r.coordinateSystem,n.position.copy(Hp),n.up.set(0,1,0),n.up.applyMatrix4(jp),n.up.reflect(Hu),n.lookAt(ny),n.near=r.near,n.far=r.far,n.updateMatrixWorld(),n.projectionMatrix.copy(r.projectionMatrix),Ld.setFromNormalAndCoplanarPoint(Hu,kd),Ld.applyMatrix4(n.matrixWorldInverse),Bn.set(Ld.normal.x,Ld.normal.y,Ld.normal.z,Ld.constant);let h=n.projectionMatrix;Xp.x=(Math.sign(Bn.x)+h.elements[8])/h.elements[0],Xp.y=(Math.sign(Bn.y)+h.elements[9])/h.elements[5],Xp.z=-1,Xp.w=(1+h.elements[10])/h.elements[14],Bn.multiplyScalar(1/Bn.dot(Xp));let d=0;h.elements[2]=Bn.x,h.elements[6]=Bn.y,h.elements[10]=i.coordinateSystem===da?Bn.z-d:Bn.z+1-d,h.elements[14]=Bn.w,this.textureNode.value=o.texture,this.depth===!0&&(this.textureNode.getDepthNode().value=o.depthTexture),s.visible=!1;let c=i.getRenderTarget(),m=i.getMRT(),g=i.autoClear;i.setMRT(null),i.setRenderTarget(o),i.autoClear=!0;let y=t.name;t.name=(t.name||"Scene")+" [ Reflector ]",u?(i.clear(),this.hasOutput=!1):(i.render(t,n),this.hasOutput=!0),t.name=y,i.setMRT(m),i.setRenderTarget(c),i.autoClear=g,s.visible=!0,uy=!1,this.forceUpdate=!1}get resolution(){return Et('ReflectorNode: The "resolution" property has been renamed to "resolutionScale".'),this.resolutionScale}set resolution(e){Et('ReflectorNode: The "resolution" property has been renamed to "resolutionScale".'),this.resolutionScale=e}},U8=e=>new D8(e),TS=new sb(-1,1,1,-1,0,1),z8=class extends ps{constructor(e=!1){super();let t=e===!1?[0,-1,0,1,2,1]:[0,2,0,0,2,0];this.setAttribute("position",new tr([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new tr(t,2))}},V8=new z8,Wa=class extends Mi{constructor(e=null){super(V8,e),this.camera=TS,this.isQuadMesh=!0}async renderAsync(e){Et('QuadMesh: "renderAsync()" has been deprecated. Use "render()" and "await renderer.init();" when creating the renderer.'),await e.init(),e.render(this,TS)}render(e){e.render(this,TS)}},G8=new fe,W8=class extends An{static get type(){return"RTTNode"}constructor(e,t=null,r=null,i={type:Dt}){let s=new er(t,r,i);super(s.texture,Jt()),this.isRTTNode=!0,this.node=e,this.width=t,this.height=r,this.renderTarget=s,this.textureNeedsUpdate=!0,this.autoUpdate=!0,this._resolutionScale=1,this._rttNode=null,this._quadMesh=new Wa(new Pt),this.updateBeforeType=ut.RENDER}get autoResize(){return this.width===null}setup(e){return this._rttNode=this.node.context(e.getSharedContext()),this._quadMesh.material.name="RTT",this._quadMesh.material.needsUpdate=!0,super.setup(e)}setSize(e,t){let r=Math.floor(e*this._resolutionScale),i=Math.floor(t*this._resolutionScale);this.renderTarget.setSize(r,i),this.textureNeedsUpdate=!0}setResolutionScale(e){return this._resolutionScale=e,this.autoResize===!1&&this.setSize(this.width,this.height),this}getResolutionScale(){return this._resolutionScale}updateBefore({renderer:e}){if(this.textureNeedsUpdate===!1&&this.autoUpdate===!1)return;this.textureNeedsUpdate=!1;let t=e.getRenderTarget();if(this.autoResize===!0){let i=e.getDrawingBufferSize(G8),s=Math.floor(i.width*this._resolutionScale),a=Math.floor(i.height*this._resolutionScale);(s!==this.renderTarget.width||a!==this.renderTarget.height)&&(this.renderTarget.setSize(s,a),this.textureNeedsUpdate=!0)}let r="RTT";this.node.name&&(r=this.node.name+" [ "+r+" ]"),this._quadMesh.material.fragmentNode=this._rttNode,this._quadMesh.name=r,e.setRenderTarget(this.renderTarget),this._quadMesh.render(e),e.setRenderTarget(t)}clone(){let e=new An(this.value,this.uvNode,this.levelNode);return e.sampler=this.sampler,e.referenceNode=this,e}},bP=(e,...t)=>new W8(Ye(e),...t),j8=(e,...t)=>e.isSampleNode||e.isTextureNode?e:e.isPassNode?e.getTextureNode():bP(e,...t),Dd=Q(([e,t,r],i)=>{let s;i.renderer.coordinateSystem===da?(e=ke(e.x,e.y.oneMinus()).mul(2).sub(1),s=Ve(K(e,t),1)):s=Ve(K(e.x,e.y.oneMinus(),t).mul(2).sub(1),1);let a=Ve(r.mul(s));return a.xyz.div(a.w)}),H8=Q(([e,t])=>{let r=t.mul(Ve(e,1)),i=r.xy.div(r.w).mul(.5).add(.5).toVar();return ke(i.x,i.y.oneMinus())}),X8=Q(([e,t,r])=>{let i=Fu(Gr(t)),s=Pr(e.mul(i)).toVar(),a=Gr(t,s).toVar(),n=Gr(t,s.sub(Pr(2,0))).toVar(),o=Gr(t,s.sub(Pr(1,0))).toVar(),l=Gr(t,s.add(Pr(1,0))).toVar(),u=Gr(t,s.add(Pr(2,0))).toVar(),h=Gr(t,s.add(Pr(0,2))).toVar(),d=Gr(t,s.add(Pr(0,1))).toVar(),c=Gr(t,s.sub(Pr(0,1))).toVar(),m=Gr(t,s.sub(Pr(0,2))).toVar(),g=ur(It(D(2).mul(o).sub(n),a)).toVar(),y=ur(It(D(2).mul(l).sub(u),a)).toVar(),b=ur(It(D(2).mul(d).sub(h),a)).toVar(),v=ur(It(D(2).mul(c).sub(m),a)).toVar(),S=Dd(e,a,r).toVar(),T=g.lessThan(y).select(S.sub(Dd(e.sub(ke(D(1).div(i.x),0)),o,r)),S.negate().add(Dd(e.add(ke(D(1).div(i.x),0)),l,r))),w=b.lessThan(v).select(S.sub(Dd(e.add(ke(0,D(1).div(i.y))),d,r)),S.negate().add(Dd(e.sub(ke(0,D(1).div(i.y))),c,r)));return Yi(xo(T,w))}),SS=Q(([e])=>Oa(D(52.9829189).mul(Oa(pa(e,ke(.06711056,.00583715)))))).setLayout({name:"interleavedGradientNoise",type:"float",inputs:[{name:"position",type:"vec2"}]}),ja=Q(([e,t,r])=>{let i=D(2.399963229728653),s=ys(D(e).add(.5).div(D(t))),a=D(e).mul(i).add(r);return ke(Ua(a),xs(a)).mul(s)}).setLayout({name:"vogelDiskSample",type:"vec2",inputs:[{name:"sampleIndex",type:"int"},{name:"samplesCount",type:"int"},{name:"phi",type:"float"}]}),$8=class extends Ke{static get type(){return"SampleNode"}constructor(e,t=null){super(),this.callback=e,this.uvNode=t,this.isSampleNode=!0}setup(){return this.sample(Jt())}sample(e){return this.callback(e)}},q8=(e,t=null)=>new $8(e,Ye(t)),Y8=class extends ud{constructor(e,t,r=Float32Array){let i=ArrayBuffer.isView(e)?e:new r(e*t);super(i,t),this.isStorageInstancedBufferAttribute=!0}},$p=class extends _i{constructor(e,t,r=Float32Array){let i=ArrayBuffer.isView(e)?e:new r(e*t);super(i,t),this.isStorageBufferAttribute=!0}},Z8=(e,t="float")=>{let r,i;t.isStructTypeNode===!0?(r=t.getLength(),i=Yg("float")):(r=jN(t),i=Yg(t));let s=new $p(e,r,i);return Sl(s,t,e)},J8=(e,t="float")=>{let r,i;t.isStructTypeNode===!0?(r=t.getLength(),i=Yg("float")):(r=jN(t),i=Yg(t));let s=new Y8(e,r,i);return Sl(s,t,s.count)},Q8=class extends Ke{static get type(){return"PointUVNode"}constructor(){super("vec2"),this.isPointUVNode=!0}generate(){return"vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y )"}},K8=ze(Q8),_S=new We,TP=Qe(0).setGroup(st).onRenderUpdate(({scene:e})=>e.backgroundBlurriness),wS=Qe(1).setGroup(st).onRenderUpdate(({scene:e})=>e.backgroundIntensity),SP=Qe(new We).setGroup(st).onRenderUpdate(({scene:e})=>{let t=e.background;return t!==null&&t.isTexture&&t.mapping!==rv||e.backgroundNode&&e.backgroundNode.isNode?_S.makeRotationFromEuler(e.backgroundRotation).transpose():_S.identity(),_S}),_P=class extends An{static get type(){return"StorageTextureNode"}constructor(e,t,r=null){super(e,t),this.storeNode=r,this.mipLevel=0,this.isStorageTextureNode=!0,this.access=Fi.WRITE_ONLY}getInputType(){return"storageTexture"}getTransformedUV(e){return e}setup(e){super.setup(e);let t=e.getNodeProperties(this);return t.storeNode=this.storeNode,t}setAccess(e){return this.access=e,this}setMipLevel(e){return this.mipLevel=e,this}generate(e,t){return this.storeNode!==null?(this.generateStore(e),""):super.generate(e,t)}generateSnippet(e,t,r,i,s,a,n,o,l){let u=this.value;return e.generateStorageTextureLoad(u,t,r,i,a,l)}toReadWrite(){return this.setAccess(Fi.READ_WRITE)}toReadOnly(){return this.setAccess(Fi.READ_ONLY)}toWriteOnly(){return this.setAccess(Fi.WRITE_ONLY)}store(e,t){let r=this.clone();return r.referenceNode=this.getBase(),r.uvNode=e,r.storeNode=t,t!==null&&r.toStack(),r}generateStore(e){let t=e.getNodeProperties(this),{uvNode:r,storeNode:i,depthNode:s}=t,a=super.generate(e,"property"),n=r.build(e,this.value.is3DTexture===!0?"uvec3":"uvec2"),o=i.build(e,"vec4"),l=s?s.build(e,"int"):null,u=e.generateTextureStore(this.value,a,n,l,o);e.addLineFlowCode(u,this)}clone(){let e=super.clone();return e.storeNode=this.storeNode,e.mipLevel=this.mipLevel,e.access=this.access,e}},wP=Mt(_P).setParameterLength(1,3),e7=(e,t,r)=>{let i;return e.isStorageTextureNode===!0?i=e.store(t,r):(i=wP(e,t,r),r!==null&&i.toStack()),i},t7=class extends _P{static get type(){return"StorageTexture3DNode"}constructor(e,t,r=null){super(e,t,r),this.isStorageTexture3DNode=!0}getDefaultUV(){return K(.5,.5,.5)}setUpdateMatrix(){}generateUV(e,t){return t.build(e,this.sampler===!0?"vec3":"ivec3")}generateOffset(e,t){return t.build(e,"ivec3")}},r7=Mt(t7).setParameterLength(1,3),i7=Q(({texture:e,uv:t})=>{let r=K().toVar();return et(t.x.lessThan(1e-4),()=>{r.assign(K(1,0,0))}).ElseIf(t.y.lessThan(1e-4),()=>{r.assign(K(0,1,0))}).ElseIf(t.z.lessThan(1e-4),()=>{r.assign(K(0,0,1))}).ElseIf(t.x.greaterThan(1-1e-4),()=>{r.assign(K(-1,0,0))}).ElseIf(t.y.greaterThan(1-1e-4),()=>{r.assign(K(0,-1,0))}).ElseIf(t.z.greaterThan(1-1e-4),()=>{r.assign(K(0,0,-1))}).Else(()=>{let i=e.sample(t.add(K(-.01,0,0))).r.sub(e.sample(t.add(K(.01,0,0))).r),s=e.sample(t.add(K(0,-.01,0))).r.sub(e.sample(t.add(K(0,.01,0))).r),a=e.sample(t.add(K(0,0,-.01))).r.sub(e.sample(t.add(K(0,0,.01))).r);r.assign(K(i,s,a))}),r.normalize()}),s7=class extends An{static get type(){return"Texture3DNode"}constructor(e,t=null,r=null){super(e,t,r),this.isTexture3DNode=!0}getInputType(){return"texture3D"}getDefaultUV(){return K(.5,.5,.5)}setUpdateMatrix(){}generateUV(e,t){return t.build(e,this.sampler===!0?"vec3":"ivec3")}generateOffset(e,t){return t.build(e,"ivec3")}normal(e){return i7({texture:this,uv:e})}},MS=Mt(s7).setParameterLength(1,3),a7=(...e)=>MS(...e).setSampler(!1),n7=(e,t,r)=>MS(e,t).level(r),o7=class extends F0{static get type(){return"UserDataNode"}constructor(e,t,r=null){super(e,t,r),this.userData=r}updateReference(e){return this.reference=this.userData!==null?this.userData:e.object.userData,this.reference}},l7=(e,t,r)=>new o7(e,t,r),MP=new WeakMap,u7=class extends rr{static get type(){return"VelocityNode"}constructor(){super("vec2"),this.projectionMatrix=null,this.updateType=ut.OBJECT,this.updateAfterType=ut.OBJECT,this.previousModelWorldMatrix=Qe(new We),this.previousProjectionMatrix=Qe(new We).setGroup(st),this.previousCameraViewMatrix=Qe(new We)}setProjectionMatrix(e){this.projectionMatrix=e}update({frameId:e,camera:t,object:r}){let i=AP(r);this.previousModelWorldMatrix.value.copy(i);let s=NP(t);s.frameId!==e&&(s.frameId=e,s.previousProjectionMatrix===void 0?(s.previousProjectionMatrix=new We,s.previousCameraViewMatrix=new We,s.currentProjectionMatrix=new We,s.currentCameraViewMatrix=new We,s.previousProjectionMatrix.copy(this.projectionMatrix||t.projectionMatrix),s.previousCameraViewMatrix.copy(t.matrixWorldInverse)):(s.previousProjectionMatrix.copy(s.currentProjectionMatrix),s.previousCameraViewMatrix.copy(s.currentCameraViewMatrix)),s.currentProjectionMatrix.copy(this.projectionMatrix||t.projectionMatrix),s.currentCameraViewMatrix.copy(t.matrixWorldInverse),this.previousProjectionMatrix.value.copy(s.previousProjectionMatrix),this.previousCameraViewMatrix.value.copy(s.previousCameraViewMatrix))}updateAfter({object:e}){AP(e).copy(e.matrixWorld)}setup(){let e=this.projectionMatrix===null?bs:Qe(this.projectionMatrix),t=this.previousCameraViewMatrix.mul(this.previousModelWorldMatrix),r=e.mul(Cn).mul(wr),i=this.previousProjectionMatrix.mul(t).mul(Du),s=r.xy.div(r.w),a=i.xy.div(i.w);return It(s,a)}};function NP(e){let t=MP.get(e);return t===void 0&&(t={},MP.set(e,t)),t}function AP(e,t=0){let r=NP(e),i=r[t];return i===void 0&&(r[t]=i=new We,r[t].copy(e.matrixWorld)),i}var h7=ze(u7),d7=Q(([e,t])=>Rs(1,e.oneMinus().div(t)).oneMinus()).setLayout({name:"blendBurn",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),c7=Q(([e,t])=>Rs(e.div(t.oneMinus()),1)).setLayout({name:"blendDodge",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),p7=Q(([e,t])=>e.oneMinus().mul(t.oneMinus()).oneMinus()).setLayout({name:"blendScreen",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),m7=Q(([e,t])=>Ct(e.mul(2).mul(t),e.oneMinus().mul(2).mul(t.oneMinus()).oneMinus(),Bu(.5,e))).setLayout({name:"blendOverlay",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),f7=Q(([e,t])=>{let r=t.a.add(e.a.mul(t.a.oneMinus()));return Ve(t.rgb.mul(t.a).add(e.rgb.mul(e.a).mul(t.a.oneMinus())).div(r),r)}).setLayout({name:"blendColor",type:"vec4",inputs:[{name:"base",type:"vec4"},{name:"blend",type:"vec4"}]}),g7=Q(([e])=>NS(e.rgb)),y7=Q(([e,t=D(1)])=>t.mix(NS(e.rgb),e.rgb).max(0)),x7=Q(([e,t=D(0)])=>{let r=Yr(e.r,e.g,e.b).div(3),i=e.r.max(e.g.max(e.b)),s=i.sub(r).mul(t).mul(-3);return Ct(e.rgb,i,s).max(0)}),v7=Q(([e,t=D(1)])=>{let r=K(.57735,.57735,.57735),i=t.cos();return K(e.rgb.mul(i).add(r.cross(e.rgb).mul(t.sin()).add(r.mul(pa(r,e.rgb).mul(i.oneMinus()))))).max(0)}),NS=(e,t=K(Gt.getLuminanceCoefficients(new F)))=>pa(e,t),b7=Q(([e,t=K(1),r=K(0),i=K(1),s=D(1),a=K(Gt.getLuminanceCoefficients(new F,Xh))])=>{let n=e.rgb.dot(K(a)),o=Br(e.rgb.mul(t).add(r),0),l=o.pow(i);return et(o.r.greaterThan(0),()=>{o.r.assign(l.r)}),et(o.g.greaterThan(0),()=>{o.g.assign(l.g)}),et(o.b.greaterThan(0),()=>{o.b.assign(l.b)}),o.assign(n.add(o.sub(n).mul(s)).max(0)),Ve(o.rgb,e.a)}),T7=Q(([e,t])=>e.mul(t).floor().div(t)),hy=null,S7=class extends G0{static get type(){return"ViewportSharedTextureNode"}constructor(e=Ga,t=null){hy===null&&(hy=new Gv),super(e,t,hy)}getTextureForReference(){return hy}updateReference(){return this}},_7=Mt(S7).setParameterLength(0,2),dy=new fe,CP=class extends An{static get type(){return"PassTextureNode"}constructor(e,t){super(t),this.passNode=e,this.isPassTextureNode=!0,this.setUpdateMatrix(!1)}setup(e){let t=e.getNodeProperties(this);return t.passNode=this.passNode,super.setup(e)}clone(){return new this.constructor(this.passNode,this.value)}},RP=class extends CP{static get type(){return"PassMultipleTextureNode"}constructor(e,t,r=!1){super(e,null),this.textureName=t,this.previousTexture=r,this.isPassMultipleTextureNode=!0}updateTexture(){this.value=this.previousTexture?this.passNode.getPreviousTexture(this.textureName):this.passNode.getTexture(this.textureName)}setup(e){return this.updateTexture(),super.setup(e)}clone(){let e=new this.constructor(this.passNode,this.textureName,this.previousTexture);return e.uvNode=this.uvNode,e.levelNode=this.levelNode,e.biasNode=this.biasNode,e.sampler=this.sampler,e.depthNode=this.depthNode,e.compareNode=this.compareNode,e.gradNode=this.gradNode,e.gatherNode=this.gatherNode,e.offsetNode=this.offsetNode,e}},Rl=class uM extends rr{static get type(){return"PassNode"}constructor(t,r,i,s={}){super("vec4"),this.scope=t,this.scene=r,this.camera=i,this.options=s,this._width=1,this._height=1;let a=new er(this._width,this._height,{type:Dt,...s});a.texture.name="output";let n=null;(this.scope===uM.DEPTH||s.depthBuffer!==!1)&&(n=new fs,n.isRenderTargetTexture=!0,n.name="depth",a.depthTexture=n),this.renderTarget=a,this.overrideMaterial=null,this.transparent=!0,this.opaque=!0,this.contextNode=null,this._contextNodeCache=null,this._textures={output:a.texture},n!==null&&(this._textures.depth=n),this._textureNodes={},this._linearDepthNodes={},this._viewZNodes={},this._previousTextures={},this._previousTextureNodes={},this._cameraNear=Qe(0),this._cameraFar=Qe(0),this._mrt=null,this._layers=null,this._resolutionScale=1,this._viewport=null,this._scissor=null,this.isPassNode=!0,this.updateBeforeType=ut.FRAME,this.global=!0}setResolutionScale(t){return this._resolutionScale=t,this}getResolutionScale(){return this._resolutionScale}setResolution(t){return Ue("PassNode: .setResolution() is deprecated. Use .setResolutionScale() instead."),this.setResolutionScale(t)}getResolution(){return Ue("PassNode: .getResolution() is deprecated. Use .getResolutionScale() instead."),this.getResolutionScale()}setLayers(t){return this._layers=t,this}getLayers(){return this._layers}setMRT(t){return this._mrt=t,this}getMRT(){return this._mrt}getTexture(t){let r=this._textures[t];if(r===void 0){if(t==="depth")throw new Error("THREE.PassNode: Depth texture is not available for this pass.");r=this.renderTarget.texture.clone(),r.name=t,this._textures[t]=r,this.renderTarget.textures.push(r)}return r}getPreviousTexture(t){let r=this._previousTextures[t];return r===void 0&&(r=this.getTexture(t).clone(),this._previousTextures[t]=r),r}toggleTexture(t){let r=this._previousTextures[t];if(r!==void 0){let i=this._textures[t],s=this.renderTarget.textures.indexOf(i);this.renderTarget.textures[s]=r,this._textures[t]=r,this._previousTextures[t]=i,this._textureNodes[t].updateTexture(),this._previousTextureNodes[t].updateTexture()}}getTextureNode(t="output"){let r=this._textureNodes[t];return r===void 0&&(r=new RP(this,t),r.updateTexture(),this._textureNodes[t]=r),r}getPreviousTextureNode(t="output"){let r=this._previousTextureNodes[t];return r===void 0&&(this._textureNodes[t]===void 0&&this.getTextureNode(t),r=new RP(this,t,!0),r.updateTexture(),this._previousTextureNodes[t]=r),r}getViewZNode(t="depth"){let r=this._viewZNodes[t];if(r===void 0){let i=this._cameraNear,s=this._cameraFar;this._viewZNodes[t]=r=W0(this.getTextureNode(t),i,s)}return r}getLinearDepthNode(t="depth"){let r=this._linearDepthNodes[t];if(r===void 0){let i=this._cameraNear,s=this._cameraFar,a=this.getViewZNode(t);this._linearDepthNodes[t]=r=Vu(a,i,s)}return r}async compileAsync(t){let r=t.getRenderTarget(),i=t.getMRT();t.setRenderTarget(this.renderTarget),t.setMRT(this._mrt),await t.compileAsync(this.scene,this.camera),t.setRenderTarget(r),t.setMRT(i)}setup({renderer:t}){return this.renderTarget.samples=this.options.samples===void 0?t.samples:this.options.samples,this.renderTarget.texture.type=t.getOutputBufferType(),t.reversedDepthBuffer===!0&&this.renderTarget.depthTexture!==null&&(this.renderTarget.depthTexture.type=Er),this.scope===uM.COLOR?this.getTextureNode():this.getLinearDepthNode()}updateBefore(t){let{renderer:r}=t,{scene:i}=this,s,a=r.getOutputRenderTarget();a&&a.isXRRenderTarget===!0?(s=r.xr.getCamera(),r.xr.updateCamera(s),dy.set(a.width,a.height)):(s=this.camera,r.getDrawingBufferSize(dy)),this.setSize(dy.width,dy.height);let n=r.getRenderTarget(),o=r.getMRT(),l=r.autoClear,u=r.transparent,h=r.opaque,d=s.layers.mask,c=r.contextNode,m=i.overrideMaterial;this._cameraNear.value=s.near,this._cameraFar.value=s.far,this._layers!==null&&(s.layers.mask=this._layers.mask);for(let y in this._previousTextures)this.toggleTexture(y);this.overrideMaterial!==null&&(i.overrideMaterial=this.overrideMaterial),r.setRenderTarget(this.renderTarget),r.setMRT(this._mrt),r.autoClear=!0,r.transparent=this.transparent,r.opaque=this.opaque,this.contextNode!==null&&((this._contextNodeCache===null||this._contextNodeCache.version!==this.version)&&(this._contextNodeCache={version:this.version,context:vo({...r.contextNode.getFlowContextData(),...this.contextNode.getFlowContextData()})}),r.contextNode=this._contextNodeCache.context);let g=i.name;i.name=this.name?this.name:i.name,r.render(i,s),i.name=g,i.overrideMaterial=m,r.setRenderTarget(n),r.setMRT(o),r.autoClear=l,r.transparent=u,r.opaque=h,r.contextNode=c,s.layers.mask=d}setSize(t,r){this._width=t,this._height=r;let i=Math.floor(this._width*this._resolutionScale),s=Math.floor(this._height*this._resolutionScale);this.renderTarget.setSize(i,s),this._scissor!==null?(this.renderTarget.scissor.copy(this._scissor).multiplyScalar(this._resolutionScale).floor(),this.renderTarget.scissorTest=!0):this.renderTarget.scissorTest=!1,this._viewport!==null&&this.renderTarget.viewport.copy(this._viewport).multiplyScalar(this._resolutionScale).floor()}setScissor(t,r,i,s){t===null?this._scissor=null:(this._scissor===null&&(this._scissor=new Wt),t.isVector4?this._scissor.copy(t):this._scissor.set(t,r,i,s))}setViewport(t,r,i,s){t===null?this._viewport=null:(this._viewport===null&&(this._viewport=new Wt),t.isVector4?this._viewport.copy(t):this._viewport.set(t,r,i,s))}dispose(){this.renderTarget.dispose()}};Rl.COLOR="color",Rl.DEPTH="depth";var w7=(e,t,r)=>new Rl(Rl.COLOR,e,t,r),M7=(e,t)=>new CP(e,t),N7=(e,t,r)=>new Rl(Rl.DEPTH,e,t,r),A7=class extends Rl{static get type(){return"ToonOutlinePassNode"}constructor(e,t,r,i,s){super(Rl.COLOR,e,t),this.colorNode=r,this.thicknessNode=i,this.alphaNode=s,this._materialCache=new WeakMap,this.name="Outline Pass"}updateBefore(e){let{renderer:t}=e,r=t.getRenderObjectFunction();t.setRenderObjectFunction((i,s,a,n,o,l,u,h)=>{if((o.isMeshToonMaterial||o.isMeshToonNodeMaterial)&&o.wireframe===!1){let d=this._getOutlineMaterial(o);t.renderObject(i,s,a,n,d,l,u,h)}t.renderObject(i,s,a,n,o,l,u,h)}),super.updateBefore(e),t.setRenderObjectFunction(r)}_createMaterial(){let e=new Pt;e.isMeshToonOutlineMaterial=!0,e.name="Toon_Outline",e.side=ii;let t=Qi.negate(),r=bs.mul(Cn),i=D(1),s=r.mul(Ve(wr,1)),a=r.mul(Ve(wr.add(t),1)),n=Yi(s.sub(a));return e.vertexNode=s.add(n.mul(this.thicknessNode).mul(s.w).mul(i)),e.colorNode=Ve(this.colorNode,this.alphaNode),e}_getOutlineMaterial(e){let t=this._materialCache.get(e);return t===void 0&&(t=this._createMaterial(),this._materialCache.set(e,t)),t}},C7=(e,t,r=new gt(0,0,0),i=.003,s=1)=>new A7(e,t,Ye(r),Ye(i),Ye(s)),EP=Q(([e,t])=>e.mul(t).clamp()).setLayout({name:"linearToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),PP=Q(([e,t])=>(e=e.mul(t),e.div(e.add(1)).clamp())).setLayout({name:"reinhardToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),BP=Q(([e,t])=>{e=e.mul(t),e=e.sub(.004).max(0);let r=e.mul(e.mul(6.2).add(.5)),i=e.mul(e.mul(6.2).add(1.7)).add(.06);return r.div(i).pow(2.2)}).setLayout({name:"cineonToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),R7=Q(([e])=>{let t=e.mul(e.add(.0245786)).sub(90537e-9),r=e.mul(e.add(.432951).mul(.983729)).add(.238081);return t.div(r)}),IP=Q(([e,t])=>{let r=Ni(.59719,.35458,.04823,.076,.90834,.01566,.0284,.13383,.83777),i=Ni(1.60475,-.53108,-.07367,-.10208,1.10813,-.00605,-.00327,-.07276,1.07602);return e=e.mul(t).div(.6),e=r.mul(e),e=R7(e),e=i.mul(e),e.clamp()}).setLayout({name:"acesFilmicToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),E7=Ni(K(1.6605,-.1246,-.0182),K(-.5876,1.1329,-.1006),K(-.0728,-.0083,1.1187)),P7=Ni(K(.6274,.0691,.0164),K(.3293,.9195,.088),K(.0433,.0113,.8956)),B7=Q(([e])=>{let t=K(e).toVar(),r=K(t.mul(t)).toVar(),i=K(r.mul(r)).toVar();return D(15.5).mul(i.mul(r)).sub(mt(40.14,i.mul(t))).add(mt(31.96,i).sub(mt(6.868,r.mul(t))).add(mt(.4298,r).add(mt(.1191,t).sub(.00232))))}),FP=Q(([e,t])=>{let r=K(e).toVar(),i=Ni(K(.856627153315983,.137318972929847,.11189821299995),K(.0951212405381588,.761241990602591,.0767994186031903),K(.0482516061458583,.101439036467562,.811302368396859)),s=Ni(K(1.1271005818144368,-.1413297634984383,-.14132976349843826),K(-.11060664309660323,1.157823702216272,-.11060664309660294),K(-.016493938717834573,-.016493938717834257,1.2519364065950405)),a=D(-12.47393),n=D(4.026069);return r.mulAssign(t),r.assign(P7.mul(r)),r.assign(i.mul(r)),r.assign(Br(r,1e-10)),r.assign(wn(r)),r.assign(r.sub(a).div(n.sub(a))),r.assign(za(r,0,1)),r.assign(B7(r)),r.assign(s.mul(r)),r.assign(ma(Br(K(0),r),K(2.2))),r.assign(E7.mul(r)),r.assign(za(r,0,1)),r}).setLayout({name:"agxToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),LP=Q(([e,t])=>{let r=D(.76),i=D(.15);e=e.mul(t);let s=Rs(e.r,Rs(e.g,e.b)),a=Zi(s.lessThan(.08),s.sub(mt(6.25,s.mul(s))),.04);e.subAssign(a);let n=Br(e.r,Br(e.g,e.b));et(n.lessThan(r),()=>e);let o=It(1,r),l=It(1,o.mul(o).div(n.add(o.sub(r))));e.mulAssign(l.div(n));let u=It(1,js(1,i.mul(n.sub(l)).add(1)));return Ct(e,K(l),u)}).setLayout({name:"neutralToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),pr=class extends Ke{static get type(){return"CodeNode"}constructor(e="",t=[],r=""){super("code"),this.isCodeNode=!0,this.global=!0,this.code=e,this.includes=t,this.language=r}setIncludes(e){return this.includes=e,this}getIncludes(){return this.includes}generate(e){let t=this.getIncludes(e);for(let i of t)i.build(e);let r=e.getCodeFromNode(this,this.getNodeType(e));return r.code=this.code,r.code}serialize(e){super.serialize(e),e.code=this.code,e.language=this.language}deserialize(e){super.deserialize(e),this.code=e.code,this.language=e.language}},cy=Mt(pr).setParameterLength(1,3),I7=(e,t)=>cy(e,t,"js"),F7=(e,t)=>cy(e,t,"wgsl"),L7=(e,t)=>cy(e,t,"glsl"),AS=class extends pr{static get type(){return"FunctionNode"}constructor(e="",t=[],r=""){super(e,t,r)}generateNodeType(e){return this.getNodeFunction(e).type}getMemberType(e,t){let r=this.getNodeType(e);return e.getStructTypeNode(r).getMemberType(e,t)}getInputs(e){return this.getNodeFunction(e).inputs}getNodeFunction(e){let t=e.getDataFromNode(this),r=t.nodeFunction;return r===void 0&&(r=e.parser.parseFunction(this.code),t.nodeFunction=r),r}generate(e,t){super.generate(e);let r=this.getNodeFunction(e),i=r.name,s=r.type,a=e.getCodeFromNode(this,s);i!==""&&(a.name=i);let n=e.getPropertyName(a),o=this.getNodeFunction(e).getCode(n);return a.code=o+` `,t==="property"?n:e.format(`${n}()`,s,t)}},kP=(e,t=[],r="")=>{let i=new AS(e,t,r);return yb((...s)=>i.call(...s),i)},k7=(e,t)=>kP(e,t,"glsl"),D7=(e,t)=>kP(e,t,"wgsl");function CS(e){let t,r=e.context.getViewZ;return r!==void 0&&(t=r(this)),(t||Wr.z).negate()}var DP=Q(([e,t],r)=>{let i=CS(r);return Hs(e,t,i)}),OP=Q(([e],t)=>{let r=CS(t);return e.mul(e,r,r).negate().exp().oneMinus()}),O7=Q(([e,t],r)=>{let i=CS(r),s=t.sub(Rn.y).max(0).toConst().mul(i).toConst();return e.mul(e,s,s).negate().exp().oneMinus()}),RS=Q(([e,t])=>Ve(t.toFloat().mix(Sd.rgb,e.toVec3()),Sd.a)),Xu=null,$u=null,U7=class extends Ke{static get type(){return"RangeNode"}constructor(e=D(),t=D()){super(),this.minNode=e,this.maxNode=t}getVectorLength(e){let t=this.getConstNode(this.minNode),r=this.getConstNode(this.maxNode),i=e.getTypeLength(ol(t.value)),s=e.getTypeLength(ol(r.value));return i>s?i:s}generateNodeType(e){return e.object.count>1?e.getTypeFromLength(this.getVectorLength(e)):"float"}getConstNode(e){let t=null;if(e.traverse(r=>{r.isConstNode===!0&&(t=r)}),t===null)throw new OC('THREE.TSL: No "ConstNode" found in node graph.',this.stackTrace);return t}setup(e){let t=e.object,r=null;if(t.count>1){let i=this.getConstNode(this.minNode),s=this.getConstNode(this.maxNode),a=i.value,n=s.value,o=e.getTypeLength(ol(a)),l=e.getTypeLength(ol(n));Xu=Xu||new Wt,$u=$u||new Wt,Xu.setScalar(0),$u.setScalar(0),o===1?Xu.setScalar(a):a.isColor?Xu.set(a.r,a.g,a.b,1):Xu.set(a.x,a.y,a.z||0,a.w||0),l===1?$u.setScalar(n):n.isColor?$u.set(n.r,n.g,n.b,1):$u.set(n.x,n.y,n.z||0,n.w||0);let u=4,h=u*t.count,d=new Float32Array(h);for(let m=0;mnew V7(e,t),G7=qp("numWorkgroups","uvec3"),W7=qp("workgroupId","uvec3"),j7=qp("globalId","uvec3"),H7=qp("localId","uvec3"),X7=qp("subgroupSize","uint"),$7=class extends Ke{constructor(e){super(),this.scope=e,this.isBarrierNode=!0}setup(e){e.allowEarlyReturns=!1,e.allowGlobalVariables=!1}generate(e){let{scope:t}=this,{renderer:r}=e;r.backend.isWebGLBackend===!0?e.addFlowCode(` // ${t}Barrier `):e.addLineFlowCode(`${t}Barrier()`,this)}},ES=Mt($7),q7=()=>ES("workgroup").toStack(),Y7=()=>ES("storage").toStack(),Z7=()=>ES("texture").toStack(),J7=class extends _u{constructor(e,t){super(e,t),this.isWorkgroupInfoElementNode=!0}generate(e,t){let r,i=e.isContextAssign();if(r=super.generate(e),i!==!0){let s=this.getNodeType(e);r=e.format(r,s,t)}return r}},Q7=class extends Ke{constructor(e,t,r=0){super(t),this.bufferType=t,this.bufferCount=r,this.isWorkgroupInfoNode=!0,this.elementType=t,this.scope=e,this.name=""}setName(e){return this.name=e,this}label(e){return Ue('TSL: "label()" has been deprecated. Use "setName()" instead.',new $r),this.setName(e)}setScope(e){return this.scope=e,this}getElementType(){return this.elementType}getInputType(){return`${this.scope}Array`}element(e){return new J7(this,e)}generate(e){let t=this.name!==""?this.name:`${this.scope}Array_${this.id}`;return e.getScopedArray(t,this.scope.toLowerCase(),this.bufferType,this.bufferCount)}},K7=(e,t)=>new Q7("Workgroup",e,t),fi=class extends Ke{static get type(){return"AtomicFunctionNode"}constructor(e,t,r){super("uint"),this.method=e,this.pointerNode=t,this.valueNode=r,this.parents=!0}getInputType(e){return this.pointerNode.getNodeType(e)}generateNodeType(e){return this.getInputType(e)}generate(e){let t=e.getNodeProperties(this),r=t.parents,i=this.method,s=this.getNodeType(e),a=this.getInputType(e),n=this.pointerNode,o=this.valueNode,l=[];l.push(`&${n.build(e,a)}`),o!==null&&l.push(o.build(e,a));let u=`${e.getMethod(i,s)}( ${l.join(", ")} )`;if(r&&r.length===1&&r[0].isStackNode===!0)e.addLineFlowCode(u,this);else return t.constNode===void 0&&(t.constNode=Xs(u,s).toConst()),t.constNode.build(e)}};fi.ATOMIC_LOAD="atomicLoad",fi.ATOMIC_STORE="atomicStore",fi.ATOMIC_ADD="atomicAdd",fi.ATOMIC_SUB="atomicSub",fi.ATOMIC_MAX="atomicMax",fi.ATOMIC_MIN="atomicMin",fi.ATOMIC_AND="atomicAnd",fi.ATOMIC_OR="atomicOr",fi.ATOMIC_XOR="atomicXor";var e9=Mt(fi),In=(e,t,r)=>e9(e,t,r).toStack(),t9=e=>In(fi.ATOMIC_LOAD,e,null),r9=(e,t)=>In(fi.ATOMIC_STORE,e,t),i9=(e,t)=>In(fi.ATOMIC_ADD,e,t),s9=(e,t)=>In(fi.ATOMIC_SUB,e,t),a9=(e,t)=>In(fi.ATOMIC_MAX,e,t),n9=(e,t)=>In(fi.ATOMIC_MIN,e,t),o9=(e,t)=>In(fi.ATOMIC_AND,e,t),l9=(e,t)=>In(fi.ATOMIC_OR,e,t),u9=(e,t)=>In(fi.ATOMIC_XOR,e,t),$e=class Zo extends rr{static get type(){return"SubgroupFunctionNode"}constructor(t,r=null,i=null){super(),this.method=t,this.aNode=r,this.bNode=i}getInputType(t){let r=this.aNode?this.aNode.getNodeType(t):null,i=this.bNode?this.bNode.getNodeType(t):null,s=t.isMatrix(r)?0:t.getTypeLength(r),a=t.isMatrix(i)?0:t.getTypeLength(i);return s>a?r:i}generateNodeType(t){let r=this.method;return r===Zo.SUBGROUP_ELECT?"bool":r===Zo.SUBGROUP_BALLOT?"uvec4":this.getInputType(t)}generate(t,r){let i=this.method,s=this.getNodeType(t),a=this.getInputType(t),n=this.aNode,o=this.bNode,l=[];if(i===Zo.SUBGROUP_BROADCAST||i===Zo.SUBGROUP_SHUFFLE||i===Zo.QUAD_BROADCAST){let h=o.getNodeType(t);l.push(n.build(t,s),o.build(t,h==="float"?"int":s))}else i===Zo.SUBGROUP_SHUFFLE_XOR||i===Zo.SUBGROUP_SHUFFLE_DOWN||i===Zo.SUBGROUP_SHUFFLE_UP?l.push(n.build(t,s),o.build(t,"uint")):(n!==null&&l.push(n.build(t,a)),o!==null&&l.push(o.build(t,a)));let u=l.length===0?"()":`( ${l.join(", ")} )`;return t.format(`${t.getMethod(i,s)}${u}`,s,r)}serialize(t){super.serialize(t),t.method=this.method}deserialize(t){super.deserialize(t),this.method=t.method}};$e.SUBGROUP_ELECT="subgroupElect",$e.SUBGROUP_BALLOT="subgroupBallot",$e.SUBGROUP_ADD="subgroupAdd",$e.SUBGROUP_INCLUSIVE_ADD="subgroupInclusiveAdd",$e.SUBGROUP_EXCLUSIVE_AND="subgroupExclusiveAdd",$e.SUBGROUP_MUL="subgroupMul",$e.SUBGROUP_INCLUSIVE_MUL="subgroupInclusiveMul",$e.SUBGROUP_EXCLUSIVE_MUL="subgroupExclusiveMul",$e.SUBGROUP_AND="subgroupAnd",$e.SUBGROUP_OR="subgroupOr",$e.SUBGROUP_XOR="subgroupXor",$e.SUBGROUP_MIN="subgroupMin",$e.SUBGROUP_MAX="subgroupMax",$e.SUBGROUP_ALL="subgroupAll",$e.SUBGROUP_ANY="subgroupAny",$e.SUBGROUP_BROADCAST_FIRST="subgroupBroadcastFirst",$e.QUAD_SWAP_X="quadSwapX",$e.QUAD_SWAP_Y="quadSwapY",$e.QUAD_SWAP_DIAGONAL="quadSwapDiagonal",$e.SUBGROUP_BROADCAST="subgroupBroadcast",$e.SUBGROUP_SHUFFLE="subgroupShuffle",$e.SUBGROUP_SHUFFLE_XOR="subgroupShuffleXor",$e.SUBGROUP_SHUFFLE_UP="subgroupShuffleUp",$e.SUBGROUP_SHUFFLE_DOWN="subgroupShuffleDown",$e.QUAD_BROADCAST="quadBroadcast";var h9=Ee($e,$e.SUBGROUP_ELECT).setParameterLength(0),d9=Ee($e,$e.SUBGROUP_BALLOT).setParameterLength(1),c9=Ee($e,$e.SUBGROUP_ADD).setParameterLength(1),p9=Ee($e,$e.SUBGROUP_INCLUSIVE_ADD).setParameterLength(1),m9=Ee($e,$e.SUBGROUP_EXCLUSIVE_AND).setParameterLength(1),f9=Ee($e,$e.SUBGROUP_MUL).setParameterLength(1),g9=Ee($e,$e.SUBGROUP_INCLUSIVE_MUL).setParameterLength(1),y9=Ee($e,$e.SUBGROUP_EXCLUSIVE_MUL).setParameterLength(1),x9=Ee($e,$e.SUBGROUP_AND).setParameterLength(1),v9=Ee($e,$e.SUBGROUP_OR).setParameterLength(1),b9=Ee($e,$e.SUBGROUP_XOR).setParameterLength(1),T9=Ee($e,$e.SUBGROUP_MIN).setParameterLength(1),S9=Ee($e,$e.SUBGROUP_MAX).setParameterLength(1),_9=Ee($e,$e.SUBGROUP_ALL).setParameterLength(0),w9=Ee($e,$e.SUBGROUP_ANY).setParameterLength(0),M9=Ee($e,$e.SUBGROUP_BROADCAST_FIRST).setParameterLength(2),N9=Ee($e,$e.QUAD_SWAP_X).setParameterLength(1),A9=Ee($e,$e.QUAD_SWAP_Y).setParameterLength(1),C9=Ee($e,$e.QUAD_SWAP_DIAGONAL).setParameterLength(1),R9=Ee($e,$e.SUBGROUP_BROADCAST).setParameterLength(2),E9=Ee($e,$e.SUBGROUP_SHUFFLE).setParameterLength(2),P9=Ee($e,$e.SUBGROUP_SHUFFLE_XOR).setParameterLength(2),B9=Ee($e,$e.SUBGROUP_SHUFFLE_UP).setParameterLength(2),I9=Ee($e,$e.SUBGROUP_SHUFFLE_DOWN).setParameterLength(2),F9=Ee($e,$e.QUAD_BROADCAST).setParameterLength(1),py;function my(e){py=py||new WeakMap;let t=py.get(e);return t===void 0&&py.set(e,t={}),t}function fy(e){let t=my(e);return t.shadowMatrix||(t.shadowMatrix=Qe("mat4").setGroup(st).onRenderUpdate(r=>((e.castShadow!==!0||r.renderer.shadowMap.enabled===!1)&&(e.shadow.camera.coordinateSystem!==r.camera.coordinateSystem&&(e.shadow.camera.coordinateSystem=r.camera.coordinateSystem,e.shadow.camera.updateProjectionMatrix()),e.shadow.updateMatrices(e)),e.shadow.matrix)))}function UP(e,t=Rn){let r=fy(e).mul(t);return r.xyz.div(r.w)}function PS(e){let t=my(e);return t.position||(t.position=Qe(new F).setGroup(st).onRenderUpdate((r,i)=>i.value.setFromMatrixPosition(e.matrixWorld)))}function zP(e){let t=my(e);return t.targetPosition||(t.targetPosition=Qe(new F).setGroup(st).onRenderUpdate((r,i)=>i.value.setFromMatrixPosition(e.target.matrixWorld)))}function BS(e){let t=my(e);return t.viewPosition||(t.viewPosition=Qe(new F).setGroup(st).onRenderUpdate(({camera:r},i)=>{i.value=i.value||new F,i.value.setFromMatrixPosition(e.matrixWorld),i.value.applyMatrix4(r.matrixWorldInverse)}))}var IS=e=>xl.transformDirection(PS(e).sub(zP(e))),L9=go("vec3","totalDiffuse"),k9=go("vec3","totalSpecular"),D9=go("vec3","outgoingLight"),O9=e=>e.sort((t,r)=>t.id-r.id),U9=(e,t)=>{for(let r of t)if(r.isAnalyticLightNode&&r.light.id===e)return r;return null},FS=new WeakMap,Yp=[],LS=class extends Ke{static get type(){return"LightsNode"}constructor(){super("vec3"),this.totalDiffuseNode=L9,this.totalSpecularNode=k9,this.outgoingLightNode=D9,this._lights=[],this.global=!0}customCacheKey(){let e=this._lights;for(let r=0;r0}},z9=(e=[])=>new LS().setLights(e),V9=class extends Ke{static get type(){return"ShadowBaseNode"}constructor(e){super(),this.light=e,this.updateBeforeType=ut.RENDER,this.isShadowBaseNode=!0}setupShadowPosition({context:e,material:t}){kS.assign(t.receivedShadowPositionNode||e.shadowPositionWorld||Rn)}},kS=go("vec3","shadowPositionWorld");function DS(e,t={}){return t.toneMapping=e.toneMapping,t.toneMappingExposure=e.toneMappingExposure,t.outputColorSpace=e.outputColorSpace,t.renderTarget=e.getRenderTarget(),t.activeCubeFace=e.getActiveCubeFace(),t.activeMipmapLevel=e.getActiveMipmapLevel(),t.renderObjectFunction=e.getRenderObjectFunction(),t.pixelRatio=e.getPixelRatio(),t.mrt=e.getMRT(),t.clearColor=e.getClearColor(t.clearColor||new gt),t.clearAlpha=e.getClearAlpha(),t.autoClear=e.autoClear,t.scissorTest=e.getScissorTest(),t}function VP(e,t){return t=DS(e,t),e.setMRT(null),e.setRenderObjectFunction(null),e.setClearColor(0,1),e.autoClear=!0,t}function GP(e,t){e.toneMapping=t.toneMapping,e.toneMappingExposure=t.toneMappingExposure,e.outputColorSpace=t.outputColorSpace,e.setRenderTarget(t.renderTarget,t.activeCubeFace,t.activeMipmapLevel),e.setRenderObjectFunction(t.renderObjectFunction),e.setPixelRatio(t.pixelRatio),e.setMRT(t.mrt),e.setClearColor(t.clearColor,t.clearAlpha),e.autoClear=t.autoClear,e.setScissorTest(t.scissorTest)}function OS(e,t={}){return t.background=e.background,t.backgroundNode=e.backgroundNode,t.overrideMaterial=e.overrideMaterial,t}function WP(e,t){return t=OS(e,t),e.background=null,e.backgroundNode=null,e.overrideMaterial=null,t}function jP(e,t){e.background=t.background,e.backgroundNode=t.backgroundNode,e.overrideMaterial=t.overrideMaterial}function G9(e,t,r={}){return r=DS(e,r),r=OS(t,r),r}function HP(e,t,r){return r=VP(e,r),r=WP(t,r),r}function XP(e,t,r){GP(e,r),jP(t,r)}var Es=Object.freeze({__proto__:null,resetRendererAndSceneState:HP,resetRendererState:VP,resetSceneState:WP,restoreRendererAndSceneState:XP,restoreRendererState:GP,restoreSceneState:jP,saveRendererAndSceneState:G9,saveRendererState:DS,saveSceneState:OS}),gy=new WeakMap,$P=Q(({depthTexture:e,shadowCoord:t,depthLayer:r})=>{let i=Ot(e,t.xy).setName("t_basic");return e.isArrayTexture&&(i=i.depth(r)),i.compare(t.z)}),qP=Q(({depthTexture:e,shadowCoord:t,shadow:r,depthLayer:i})=>{let s=(h,d)=>{let c=Ot(e,h);return e.isArrayTexture&&(c=c.depth(i)),c.compare(d)},a=cr("mapSize","vec2",r).setGroup(st),n=cr("radius","float",r).setGroup(st),o=ke(1).div(a),l=n.mul(o.x),u=SS(ku.xy).mul(6.28318530718);return Yr(s(t.xy.add(ja(0,5,u).mul(l)),t.z),s(t.xy.add(ja(1,5,u).mul(l)),t.z),s(t.xy.add(ja(2,5,u).mul(l)),t.z),s(t.xy.add(ja(3,5,u).mul(l)),t.z),s(t.xy.add(ja(4,5,u).mul(l)),t.z)).mul(1/5)}),YP=Q(({depthTexture:e,shadowCoord:t,shadow:r,depthLayer:i})=>{let s=cr("mapSize","vec2",r).setGroup(st),a=ke(1).div(s),n=t.xy,o=Oa(n.mul(s).add(.5)).toConst();n.subAssign(o.sub(.5).mul(a));let l=m=>{let g=Ot(e,n).offset(m).gather();return e.isArrayTexture&&(g=g.depth(i)),g.compare(t.z)},u=l(Pr(-1,1)).toConst(),h=l(Pr(1,1)).toConst(),d=l(Pr(-1,-1)).toConst(),c=l(Pr(1,-1)).toConst();return Yr(Ct(u.x,h.y,o.x).add(u.y).add(h.x).mul(o.y),Ct(u.w,h.z,o.x).add(u.z).add(h.w),Ct(d.x,c.y,o.x).add(d.y).add(c.x),Ct(d.w,c.z,o.x).add(d.z).add(c.w).mul(o.y.oneMinus())).mul(1/9)}),ZP=Q(({depthTexture:e,shadowCoord:t,depthLayer:r},i)=>{let s=Ot(e).sample(t.xy);e.isArrayTexture&&(s=s.depth(r)),s=s.rg;let a=s.x,n=Br(1e-7,s.y.mul(s.y)),o=i.renderer.reversedDepthBuffer?Bu(a,t.z):Bu(t.z,a),l=D(1).toVar();return et(o.notEqual(1),()=>{let u=t.z.sub(a),h=n.div(n.add(u.mul(u)));h=za(It(h,.3).div(.65)),l.assign(Br(o,h))}),l}),JP=e=>{let t=gy.get(e);return t===void 0&&(t=new Pt,t.colorNode=Ve(0,0,0,1),t.isShadowPassMaterial=!0,t.name="ShadowMaterial",t.blending=Kn,t.fog=!1,gy.set(e,t)),t},QP=e=>{let t=gy.get(e);t!==void 0&&(t.dispose(),gy.delete(e))},KP=new Ml,Od=[],e3=(e,t,r,i)=>{Od[0]=e,Od[1]=t;let s=KP.get(Od);return(s===void 0||s.shadowType!==r||s.useVelocity!==i)&&(s=(a,n,o,l,u,h,d,c,m)=>{(a.castShadow===!0||a.receiveShadow&&r===Lh)&&(i&&(HN(a).useVelocity=!0),a.onBeforeShadow(e,a,o,t.camera,l,n.overrideMaterial,h),e.renderObject(a,n,o,l,u,h,d,c,m),a.onAfterShadow(e,a,o,t.camera,l,n.overrideMaterial,h))},s.shadowType=r,s.useVelocity=i,KP.set(Od,s)),Od[0]=null,Od[1]=null,s},W9=Q(({samples:e,radius:t,size:r,shadowPass:i,depthLayer:s})=>{let a=D(0).toVar("meanVertical"),n=D(0).toVar("squareMeanVertical"),o=e.lessThanEqual(D(1)).select(D(0),D(2).div(e.sub(1))),l=e.lessThanEqual(D(1)).select(D(0),D(-1));Qt({start:Y(0),end:Y(e),type:"int",condition:"<"},({i:h})=>{let d=l.add(D(h).mul(o)),c=i.sample(Yr(ku.xy,ke(0,d).mul(t)).div(r));i.value.isArrayTexture&&(c=c.depth(s)),c=c.x,a.addAssign(c),n.addAssign(c.mul(c))}),a.divAssign(e),n.divAssign(e);let u=ys(n.sub(a.mul(a)).max(0));return ke(a,u)}),j9=Q(({samples:e,radius:t,size:r,shadowPass:i,depthLayer:s})=>{let a=D(0).toVar("meanHorizontal"),n=D(0).toVar("squareMeanHorizontal"),o=e.lessThanEqual(D(1)).select(D(0),D(2).div(e.sub(1))),l=e.lessThanEqual(D(1)).select(D(0),D(-1));Qt({start:Y(0),end:Y(e),type:"int",condition:"<"},({i:h})=>{let d=l.add(D(h).mul(o)),c=i.sample(Yr(ku.xy,ke(d,0).mul(t)).div(r));i.value.isArrayTexture&&(c=c.depth(s)),a.addAssign(c.x),n.addAssign(Yr(c.y.mul(c.y),c.x.mul(c.x)))}),a.divAssign(e),n.divAssign(e);let u=ys(n.sub(a.mul(a)).max(0));return ke(a,u)}),H9=[$P,qP,YP,ZP],US,yy=new Wa,t3=class extends V9{static get type(){return"ShadowNode"}constructor(e,t=null){super(e),this.shadow=t||e.shadow,this.shadowMap=null,this.vsmShadowMapVertical=null,this.vsmShadowMapHorizontal=null,this.vsmMaterialVertical=null,this.vsmMaterialHorizontal=null,this._node=null,this._currentShadowType=null,this._cameraFrameId=new WeakMap,this.isShadowNode=!0,this.depthLayer=0}setupShadowFilter(e,{filterFn:t,depthTexture:r,shadowCoord:i,shadow:s,depthLayer:a}){let n=i.x.greaterThanEqual(0).and(i.x.lessThanEqual(1)).and(i.y.greaterThanEqual(0)).and(i.y.lessThanEqual(1)).and(i.z.lessThanEqual(1)),o=t({depthTexture:r,shadowCoord:i,shadow:s,depthLayer:a});return n.select(o,D(1))}setupShadowCoord(e,t){let{shadow:r}=this,{renderer:i}=e,s=r.biasNode||cr("bias","float",r).setGroup(st),a=t,n;if(r.camera.isOrthographicCamera||i.logarithmicDepthBuffer!==!0)a=a.xyz.div(a.w),n=a.z;else{let o=a.w;a=a.xy.div(o);let l=cr("near","float",r.camera).setGroup(st),u=cr("far","float",r.camera).setGroup(st);n=j0(o.negate(),l,u)}return a=K(a.x,a.y.oneMinus(),i.reversedDepthBuffer?n.sub(s):n.add(s)),a}getShadowFilterFn(e){return H9[e]}setupRenderTarget(e,t){let r=new fs(e.mapSize.width,e.mapSize.height);r.name="ShadowDepthTexture",r.compareFunction=t.renderer.reversedDepthBuffer?$h:tp;let i=t.createRenderTarget(e.mapSize.width,e.mapSize.height);return i.texture.name="ShadowMap",i.texture.type=e.mapType,i.depthTexture=r,{shadowMap:i,depthTexture:r}}setupShadow(e){let{renderer:t,camera:r}=e,{light:i,shadow:s}=this,{depthTexture:a,shadowMap:n}=this.setupRenderTarget(s,e),o=t.shadowMap.type,l=t.hasCompatibility(fu.TEXTURE_COMPARE);if((o===xM||o===wD)&&l?(a.minFilter=lr,a.magFilter=lr):(a.minFilter=or,a.magFilter=or),s.camera.coordinateSystem=r.coordinateSystem,s.camera.updateProjectionMatrix(),o===Lh&&s.isPointLightShadow!==!0){a.compareFunction=null,n.depth>1?(n._vsmShadowMapVertical||(n._vsmShadowMapVertical=e.createRenderTarget(s.mapSize.width,s.mapSize.height,{format:ha,type:Dt,depth:n.depth,depthBuffer:!1}),n._vsmShadowMapVertical.texture.name="VSMVertical"),this.vsmShadowMapVertical=n._vsmShadowMapVertical,n._vsmShadowMapHorizontal||(n._vsmShadowMapHorizontal=e.createRenderTarget(s.mapSize.width,s.mapSize.height,{format:ha,type:Dt,depth:n.depth,depthBuffer:!1}),n._vsmShadowMapHorizontal.texture.name="VSMHorizontal"),this.vsmShadowMapHorizontal=n._vsmShadowMapHorizontal):(this.vsmShadowMapVertical=e.createRenderTarget(s.mapSize.width,s.mapSize.height,{format:ha,type:Dt,depthBuffer:!1}),this.vsmShadowMapHorizontal=e.createRenderTarget(s.mapSize.width,s.mapSize.height,{format:ha,type:Dt,depthBuffer:!1}));let N=Ot(a);a.isArrayTexture&&(N=N.depth(this.depthLayer));let C=Ot(this.vsmShadowMapVertical.texture);a.isArrayTexture&&(C=C.depth(this.depthLayer));let R=cr("blurSamples","float",s).setGroup(st),E=cr("radius","float",s).setGroup(st),P=cr("mapSize","vec2",s).setGroup(st),I=this.vsmMaterialVertical||(this.vsmMaterialVertical=new Pt);I.fragmentNode=W9({samples:R,radius:E,size:P,shadowPass:N,depthLayer:this.depthLayer}).context(e.getSharedContext()),I.name="VSMVertical",I=this.vsmMaterialHorizontal||(this.vsmMaterialHorizontal=new Pt),I.fragmentNode=j9({samples:R,radius:E,size:P,shadowPass:C,depthLayer:this.depthLayer}).context(e.getSharedContext()),I.name="VSMHorizontal"}let u=cr("intensity","float",s).setGroup(st),h=cr("normalBias","float",s).setGroup(st),d=fy(i),c=vl.mul(h),m;!t.highPrecision||e.material.receivedShadowPositionNode||e.context.shadowPositionWorld?m=d.mul(kS.add(c)):m=Qe("mat4").onObjectUpdate(({object:N},C)=>C.value.multiplyMatrices(d.value,N.matrixWorld)).mul(wr).add(d.mul(Ve(c,0)));let g=this.setupShadowCoord(e,m),y=s.filterNode||this.getShadowFilterFn(t.shadowMap.type)||null;if(y===null)throw new Error("THREE.WebGPURenderer: Shadow map type not supported yet.");let b=o===Lh&&s.isPointLightShadow!==!0?this.vsmShadowMapHorizontal.texture:a,v=this.setupShadowFilter(e,{filterFn:y,shadowTexture:n.texture,depthTexture:b,shadowCoord:g,shadow:s,depthLayer:this.depthLayer}),S;t.shadowMap.transmitted===!0&&(n.texture.isCubeTexture?S=Ts(n.texture,g.xyz):(S=Ot(n.texture,g),a.isArrayTexture&&(S=S.depth(this.depthLayer))));let T;S?T=Ct(1,v.rgb.mix(S,1),u.mul(S.a)).toVar():T=Ct(1,v,u).toVar(),this.shadowMap=n,this.shadow.map=n;let w=`${this.light.type} Shadow [ ${this.light.name||"ID: "+this.light.id} ]`;return S&&T.toInspector(`${w} / Color`,()=>this.shadowMap.texture.isCubeTexture?Ts(this.shadowMap.texture,qT()):Ot(this.shadowMap.texture)),T.toInspector(`${w} / Depth`,()=>{let N=cr("near","float",this.shadow.camera),C=cr("far","float",this.shadow.camera),R;this.shadowMap.texture.isCubeTexture?R=Ts(this.shadowMap.depthTexture,qT()).r:R=Ot(this.shadowMap.depthTexture).r;let E;return this.shadow.camera.isPerspectiveCamera?E=W0(R,N,C):E=aE(R,N,C),E=Vu(E,N,C),E.oneMinus()})}setup(e){if(e.renderer.shadowMap.enabled!==!1)return Q(()=>{let t=e.renderer.shadowMap.type;this._currentShadowType!==t&&(this._reset(),this._node=null);let r=this._node;return this.setupShadowPosition(e),r===null&&(this._node=r=this.setupShadow(e),this._currentShadowType=t),e.material.receivedShadowNode&&(r=e.material.receivedShadowNode(r)),r})()}renderShadow(e){let{shadow:t,shadowMap:r,light:i}=this,{renderer:s,scene:a}=e;t.updateMatrices(i),r.setSize(t.mapSize.width,t.mapSize.height,r.depth);let n=a.name;a.name=`Shadow Map [ ${i.name||"ID: "+i.id} ]`,s.render(a,t.camera),a.name=n}updateShadow(e){let{shadowMap:t,light:r,shadow:i}=this,{renderer:s,scene:a,camera:n}=e,o=s.shadowMap.type,l=t.depthTexture.version;this._depthVersionCached=l;let u=i.camera.layers.mask;(i.camera.layers.mask&4294967294)===0&&(i.camera.layers.mask=n.layers.mask);let h=s.getRenderObjectFunction(),d=s.getMRT(),c=d?d.has("velocity"):!1;US=HP(s,a,US),a.overrideMaterial=JP(r),s.setRenderObjectFunction(e3(s,i,o,c)),s.setClearColor(0,0),s.setRenderTarget(t),this.renderShadow(e),s.setRenderObjectFunction(h),o===Lh&&i.isPointLightShadow!==!0&&this.vsmPass(s),i.camera.layers.mask=u,XP(s,a,US)}vsmPass(e){let{shadow:t}=this,r=this.shadowMap.depth;this.vsmShadowMapVertical.setSize(t.mapSize.width,t.mapSize.height,r),this.vsmShadowMapHorizontal.setSize(t.mapSize.width,t.mapSize.height,r),e.setRenderTarget(this.vsmShadowMapVertical),yy.material=this.vsmMaterialVertical,yy.render(e),e.setRenderTarget(this.vsmShadowMapHorizontal),yy.material=this.vsmMaterialHorizontal,yy.render(e)}dispose(){this._reset(),super.dispose()}_reset(){this._currentShadowType=null,QP(this.light),this.shadowMap&&(this.shadowMap.dispose(),this.shadowMap=null),this.vsmShadowMapVertical!==null&&(this.vsmShadowMapVertical.dispose(),this.vsmShadowMapVertical=null,this.vsmMaterialVertical.dispose(),this.vsmMaterialVertical=null),this.vsmShadowMapHorizontal!==null&&(this.vsmShadowMapHorizontal.dispose(),this.vsmShadowMapHorizontal=null,this.vsmMaterialHorizontal.dispose(),this.vsmMaterialHorizontal=null)}updateBefore(e){let{shadow:t}=this,r=t.needsUpdate||t.autoUpdate;r&&(this._cameraFrameId[e.camera]===e.frameId&&(r=!1),this._cameraFrameId[e.camera]=e.frameId),r&&(this.updateShadow(e),this.shadowMap.depthTexture.version===this._depthVersionCached&&(t.needsUpdate=!1))}},r3=(e,t)=>new t3(e,t),X9=new gt,i3=new We,Zp=new F,zS=new F,$9=[new F(1,0,0),new F(-1,0,0),new F(0,-1,0),new F(0,1,0),new F(0,0,1),new F(0,0,-1)],q9=[new F(0,-1,0),new F(0,-1,0),new F(0,0,-1),new F(0,0,1),new F(0,-1,0),new F(0,-1,0)],Y9=[new F(1,0,0),new F(-1,0,0),new F(0,1,0),new F(0,-1,0),new F(0,0,1),new F(0,0,-1)],Z9=[new F(0,-1,0),new F(0,-1,0),new F(0,0,1),new F(0,0,-1),new F(0,-1,0),new F(0,-1,0)],s3=Q(({depthTexture:e,bd3D:t,dp:r})=>Ts(e,t).compare(r)),a3=Q(({depthTexture:e,bd3D:t,dp:r,shadow:i})=>{let s=cr("radius","float",i).setGroup(st),a=cr("mapSize","vec2",i).setGroup(st),n=s.div(a.x),o=ur(t),l=Yi(xo(t,o.x.greaterThan(o.z).select(K(0,1,0),K(1,0,0)))),u=xo(t,l),h=SS(ku.xy).mul(6.28318530718),d=ja(0,5,h),c=ja(1,5,h),m=ja(2,5,h),g=ja(3,5,h),y=ja(4,5,h);return Ts(e,t.add(l.mul(d.x).add(u.mul(d.y)).mul(n))).compare(r).add(Ts(e,t.add(l.mul(c.x).add(u.mul(c.y)).mul(n))).compare(r)).add(Ts(e,t.add(l.mul(m.x).add(u.mul(m.y)).mul(n))).compare(r)).add(Ts(e,t.add(l.mul(g.x).add(u.mul(g.y)).mul(n))).compare(r)).add(Ts(e,t.add(l.mul(y.x).add(u.mul(y.y)).mul(n))).compare(r)).mul(1/5)}),J9=Q(({filterFn:e,depthTexture:t,shadowCoord:r,shadow:i},s)=>{let a=r.xyz.toConst(),n=a.abs().toConst(),o=n.x.max(n.y).max(n.z),l=Qe("float").setGroup(st).onRenderUpdate(()=>i.camera.near),u=Qe("float").setGroup(st).onRenderUpdate(()=>i.camera.far),h=cr("bias","float",i).setGroup(st),d=D(1).toVar();return et(o.sub(u).lessThanEqual(0).and(o.sub(l).greaterThanEqual(0)),()=>{let c;s.renderer.reversedDepthBuffer?(c=nE(o.negate(),l,u),c.subAssign(h)):s.renderer.logarithmicDepthBuffer?(c=j0(o.negate(),l,u),c.addAssign(h)):(c=jT(o.negate(),l,u),c.addAssign(h));let m=a.normalize();d.assign(e({depthTexture:t,bd3D:m,dp:c,shadow:i}))}),d}),Q9=class extends t3{static get type(){return"PointShadowNode"}constructor(e,t=null){super(e,t)}getShadowFilterFn(e){return e===_D?s3:a3}setupShadowCoord(e,t){return t}setupShadowFilter(e,{filterFn:t,depthTexture:r,shadowCoord:i,shadow:s}){return J9({filterFn:t,depthTexture:r,shadowCoord:i,shadow:s})}setupRenderTarget(e,t){let r=new H4(e.mapSize.width);r.name="PointShadowDepthTexture",r.compareFunction=t.renderer.reversedDepthBuffer?$h:tp;let i=t.createCubeRenderTarget(e.mapSize.width);return i.texture.name="PointShadowMap",i.depthTexture=r,{shadowMap:i,depthTexture:r}}renderShadow(e){let{shadow:t,shadowMap:r,light:i}=this,{renderer:s,scene:a}=e,n=t.camera,o=t.matrix,l=s.coordinateSystem===da,u=l?$9:Y9,h=l?q9:Z9;r.setSize(t.mapSize.width,t.mapSize.width);let d=s.autoClear,c=s.getClearColor(X9),m=s.getClearAlpha();s.autoClear=!1,s.setClearColor(t.clearColor,t.clearAlpha);for(let g=0;g<6;g++){s.setRenderTarget(r,g),s.clear();let y=i.distance||n.far;y!==n.far&&(n.far=y,n.updateProjectionMatrix()),Zp.setFromMatrixPosition(i.matrixWorld),n.position.copy(Zp),zS.copy(n.position),zS.add(u[g]),n.up.copy(h[g]),n.lookAt(zS),n.updateMatrixWorld(),o.makeTranslation(-Zp.x,-Zp.y,-Zp.z),i3.multiplyMatrices(n.projectionMatrix,n.matrixWorldInverse),t._frustum.setFromProjectionMatrix(i3,n.coordinateSystem,n.reversedDepth);let b=a.name;a.name=`Point Light Shadow [ ${i.name||"ID: "+i.id} ] - Face ${g+1}`,s.render(a,n),a.name=b}s.autoClear=d,s.setClearColor(c,m)}},n3=(e,t)=>new Q9(e,t),qu=class extends Ed{static get type(){return"AnalyticLightNode"}constructor(e=null){super(),this.light=e,this.color=new gt,this.colorNode=e&&e.colorNode||Qe(this.color).setGroup(st),this.baseColorNode=null,this.shadowNode=null,this.shadowColorNode=null,this.isAnalyticLightNode=!0,this.updateType=ut.FRAME,e&&e.shadow&&(this._shadowDisposeListener=()=>{this.disposeShadow()},e.addEventListener("dispose",this._shadowDisposeListener))}dispose(){this._shadowDisposeListener&&this.light.removeEventListener("dispose",this._shadowDisposeListener),super.dispose()}disposeShadow(){this.shadowNode!==null&&(this.shadowNode.dispose(),this.shadowNode=null),this.shadowColorNode=null,this.baseColorNode!==null&&(this.colorNode=this.baseColorNode,this.baseColorNode=null)}getHash(){return this.light.uuid}getLightVector(e){return BS(this.light).sub(e.context.positionView||Wr)}setupDirect(){}setupDirectRectArea(){}setupShadowNode(){return r3(this.light)}setupShadow(e){let{renderer:t}=e;if(t.shadowMap.enabled===!1)return;let r=this.shadowColorNode;if(r===null){let i=this.light.shadow.shadowNode,s;i!==void 0?s=Ye(i):s=this.setupShadowNode(),this.shadowNode=s,this.shadowColorNode=r=this.colorNode.mul(s),this.baseColorNode=this.colorNode}e.context.getShadow&&(r=e.context.getShadow(this,e)),this.colorNode=r}setup(e){this.colorNode=this.baseColorNode||this.colorNode,this.light.castShadow?e.object.receiveShadow&&this.setupShadow(e):this.shadowNode!==null&&(this.shadowNode.dispose(),this.shadowNode=null,this.shadowColorNode=null);let t=this.setupDirect(e),r=this.setupDirectRectArea(e);t&&e.lightsNode.setupDirectLight(e,this,t),r&&e.lightsNode.setupDirectRectAreaLight(e,this,r)}update(){let{light:e}=this;this.color.copy(e.color).multiplyScalar(e.intensity)}},VS=Q(({lightDistance:e,cutoffDistance:t,decayExponent:r})=>{let i=e.pow(r).max(.01).reciprocal();return t.greaterThan(0).select(i.mul(e.div(t).pow4().oneMinus().clamp().pow2()),i)}),o3=({color:e,lightVector:t,cutoffDistance:r,decayExponent:i})=>{let s=t.normalize(),a=t.length(),n=VS({lightDistance:a,cutoffDistance:r,decayExponent:i}),o=e.mul(n);return{lightDirection:s,lightColor:o}},K9=class extends qu{static get type(){return"PointLightNode"}constructor(e=null){super(e),this.cutoffDistanceNode=Qe(0).setGroup(st),this.decayExponentNode=Qe(2).setGroup(st)}update(e){let{light:t}=this;super.update(e),this.cutoffDistanceNode.value=t.distance,this.decayExponentNode.value=t.decay}setupShadowNode(){return n3(this.light)}setupDirect(e){return o3({color:this.colorNode,lightVector:this.getLightVector(e),cutoffDistance:this.cutoffDistanceNode,decayExponent:this.decayExponentNode})}},eW=Q(([e=Jt()])=>{let t=e.mul(2),r=t.x.floor(),i=t.y.floor();return r.add(i).mod(2).sign()}),tW=Q(([e=Jt()],{renderer:t,material:r})=>{let i=Wb(e.mul(2).sub(1)),s;if(r.alphaToCoverage&&t.currentSamples>0){let a=D(i.fwidth()).toVar();s=Hs(a.oneMinus(),a.add(1),i).oneMinus()}else s=Zi(i.greaterThan(1),0,1);return s}),Jp=Q(([e,t,r])=>{let i=D(r).toVar(),s=D(t).toVar(),a=Gs(e).toVar();return Zi(a,s,i).uniformFlow()}).setLayout({name:"mx_select",type:"float",inputs:[{name:"b",type:"bool"},{name:"t",type:"float"},{name:"f",type:"float"}]}),xy=Q(([e,t])=>{let r=Gs(t).toVar(),i=D(e).toVar();return Zi(r,i.negate(),i).uniformFlow()}).setLayout({name:"mx_negate_if",type:"float",inputs:[{name:"val",type:"float"},{name:"b",type:"bool"}]}),Zr=Q(([e])=>{let t=D(e).toVar();return Y(Mn(t))}).setLayout({name:"mx_floor",type:"int",inputs:[{name:"x",type:"float"}]}),Mr=Q(([e,t])=>{let r=D(e).toVar();return t.assign(Zr(r)),r.sub(D(t))}),rW=Q(([e,t,r,i,s,a])=>{let n=D(a).toVar(),o=D(s).toVar(),l=D(i).toVar(),u=D(r).toVar(),h=D(t).toVar(),d=D(e).toVar(),c=D(It(1,o)).toVar();return It(1,n).mul(d.mul(c).add(h.mul(o))).add(n.mul(u.mul(c).add(l.mul(o))))}).setLayout({name:"mx_bilerp_0",type:"float",inputs:[{name:"v0",type:"float"},{name:"v1",type:"float"},{name:"v2",type:"float"},{name:"v3",type:"float"},{name:"s",type:"float"},{name:"t",type:"float"}]}),iW=Q(([e,t,r,i,s,a])=>{let n=D(a).toVar(),o=D(s).toVar(),l=K(i).toVar(),u=K(r).toVar(),h=K(t).toVar(),d=K(e).toVar(),c=D(It(1,o)).toVar();return It(1,n).mul(d.mul(c).add(h.mul(o))).add(n.mul(u.mul(c).add(l.mul(o))))}).setLayout({name:"mx_bilerp_1",type:"vec3",inputs:[{name:"v0",type:"vec3"},{name:"v1",type:"vec3"},{name:"v2",type:"vec3"},{name:"v3",type:"vec3"},{name:"s",type:"float"},{name:"t",type:"float"}]}),l3=ki([rW,iW]),sW=Q(([e,t,r,i,s,a,n,o,l,u,h])=>{let d=D(h).toVar(),c=D(u).toVar(),m=D(l).toVar(),g=D(o).toVar(),y=D(n).toVar(),b=D(a).toVar(),v=D(s).toVar(),S=D(i).toVar(),T=D(r).toVar(),w=D(t).toVar(),N=D(e).toVar(),C=D(It(1,m)).toVar(),R=D(It(1,c)).toVar();return D(It(1,d)).toVar().mul(R.mul(N.mul(C).add(w.mul(m))).add(c.mul(T.mul(C).add(S.mul(m))))).add(d.mul(R.mul(v.mul(C).add(b.mul(m))).add(c.mul(y.mul(C).add(g.mul(m))))))}).setLayout({name:"mx_trilerp_0",type:"float",inputs:[{name:"v0",type:"float"},{name:"v1",type:"float"},{name:"v2",type:"float"},{name:"v3",type:"float"},{name:"v4",type:"float"},{name:"v5",type:"float"},{name:"v6",type:"float"},{name:"v7",type:"float"},{name:"s",type:"float"},{name:"t",type:"float"},{name:"r",type:"float"}]}),aW=Q(([e,t,r,i,s,a,n,o,l,u,h])=>{let d=D(h).toVar(),c=D(u).toVar(),m=D(l).toVar(),g=K(o).toVar(),y=K(n).toVar(),b=K(a).toVar(),v=K(s).toVar(),S=K(i).toVar(),T=K(r).toVar(),w=K(t).toVar(),N=K(e).toVar(),C=D(It(1,m)).toVar(),R=D(It(1,c)).toVar();return D(It(1,d)).toVar().mul(R.mul(N.mul(C).add(w.mul(m))).add(c.mul(T.mul(C).add(S.mul(m))))).add(d.mul(R.mul(v.mul(C).add(b.mul(m))).add(c.mul(y.mul(C).add(g.mul(m))))))}).setLayout({name:"mx_trilerp_1",type:"vec3",inputs:[{name:"v0",type:"vec3"},{name:"v1",type:"vec3"},{name:"v2",type:"vec3"},{name:"v3",type:"vec3"},{name:"v4",type:"vec3"},{name:"v5",type:"vec3"},{name:"v6",type:"vec3"},{name:"v7",type:"vec3"},{name:"s",type:"float"},{name:"t",type:"float"},{name:"r",type:"float"}]}),u3=ki([sW,aW]),nW=Q(([e,t,r])=>{let i=D(r).toVar(),s=D(t).toVar(),a=Ne(e).toVar(),n=Ne(a.bitAnd(Ne(7))).toVar(),o=D(Jp(n.lessThan(Ne(4)),s,i)).toVar(),l=D(mt(2,Jp(n.lessThan(Ne(4)),i,s))).toVar();return xy(o,Gs(n.bitAnd(Ne(1)))).add(xy(l,Gs(n.bitAnd(Ne(2)))))}).setLayout({name:"mx_gradient_float_0",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"}]}),oW=Q(([e,t,r,i])=>{let s=D(i).toVar(),a=D(r).toVar(),n=D(t).toVar(),o=Ne(e).toVar(),l=Ne(o.bitAnd(Ne(15))).toVar(),u=D(Jp(l.lessThan(Ne(8)),n,a)).toVar(),h=D(Jp(l.lessThan(Ne(4)),a,Jp(l.equal(Ne(12)).or(l.equal(Ne(14))),n,s))).toVar();return xy(u,Gs(l.bitAnd(Ne(1)))).add(xy(h,Gs(l.bitAnd(Ne(2)))))}).setLayout({name:"mx_gradient_float_1",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"},{name:"z",type:"float"}]}),Ci=ki([nW,oW]),lW=Q(([e,t,r])=>{let i=D(r).toVar(),s=D(t).toVar(),a=Mu(e).toVar();return K(Ci(a.x,s,i),Ci(a.y,s,i),Ci(a.z,s,i))}).setLayout({name:"mx_gradient_vec3_0",type:"vec3",inputs:[{name:"hash",type:"uvec3"},{name:"x",type:"float"},{name:"y",type:"float"}]}),uW=Q(([e,t,r,i])=>{let s=D(i).toVar(),a=D(r).toVar(),n=D(t).toVar(),o=Mu(e).toVar();return K(Ci(o.x,n,a,s),Ci(o.y,n,a,s),Ci(o.z,n,a,s))}).setLayout({name:"mx_gradient_vec3_1",type:"vec3",inputs:[{name:"hash",type:"uvec3"},{name:"x",type:"float"},{name:"y",type:"float"},{name:"z",type:"float"}]}),xa=ki([lW,uW]),hW=Q(([e])=>{let t=D(e).toVar();return mt(.6616,t)}).setLayout({name:"mx_gradient_scale2d_0",type:"float",inputs:[{name:"v",type:"float"}]}),dW=Q(([e])=>{let t=D(e).toVar();return mt(.982,t)}).setLayout({name:"mx_gradient_scale3d_0",type:"float",inputs:[{name:"v",type:"float"}]}),cW=Q(([e])=>{let t=K(e).toVar();return mt(.6616,t)}).setLayout({name:"mx_gradient_scale2d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]}),h3=ki([hW,cW]),pW=Q(([e])=>{let t=K(e).toVar();return mt(.982,t)}).setLayout({name:"mx_gradient_scale3d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]}),d3=ki([dW,pW]),Zs=Q(([e,t])=>{let r=Y(t).toVar(),i=Ne(e).toVar();return i.shiftLeft(r).bitOr(i.shiftRight(Y(32).sub(r)))}).setLayout({name:"mx_rotl32",type:"uint",inputs:[{name:"x",type:"uint"},{name:"k",type:"int"}]}),c3=Q(([e,t,r])=>{e.subAssign(r),e.bitXorAssign(Zs(r,Y(4))),r.addAssign(t),t.subAssign(e),t.bitXorAssign(Zs(e,Y(6))),e.addAssign(r),r.subAssign(t),r.bitXorAssign(Zs(t,Y(8))),t.addAssign(e),e.subAssign(r),e.bitXorAssign(Zs(r,Y(16))),r.addAssign(t),t.subAssign(e),t.bitXorAssign(Zs(e,Y(19))),e.addAssign(r),r.subAssign(t),r.bitXorAssign(Zs(t,Y(4))),t.addAssign(e)}),Qp=Q(([e,t,r])=>{let i=Ne(r).toVar(),s=Ne(t).toVar(),a=Ne(e).toVar();return i.bitXorAssign(s),i.subAssign(Zs(s,Y(14))),a.bitXorAssign(i),a.subAssign(Zs(i,Y(11))),s.bitXorAssign(a),s.subAssign(Zs(a,Y(25))),i.bitXorAssign(s),i.subAssign(Zs(s,Y(16))),a.bitXorAssign(i),a.subAssign(Zs(i,Y(4))),s.bitXorAssign(a),s.subAssign(Zs(a,Y(14))),i.bitXorAssign(s),i.subAssign(Zs(s,Y(24))),i}).setLayout({name:"mx_bjfinal",type:"uint",inputs:[{name:"a",type:"uint"},{name:"b",type:"uint"},{name:"c",type:"uint"}]}),Ki=Q(([e])=>{let t=Ne(e).toVar();return D(t).div(D(Ne(Y(4294967295))))}).setLayout({name:"mx_bits_to_01",type:"float",inputs:[{name:"bits",type:"uint"}]}),Fn=Q(([e])=>{let t=D(e).toVar();return t.mul(t).mul(t).mul(t.mul(t.mul(6).sub(15)).add(10))}).setLayout({name:"mx_fade",type:"float",inputs:[{name:"t",type:"float"}]}),mW=Q(([e])=>{let t=Y(e).toVar(),r=Ne(Ne(1)).toVar(),i=Ne(Ne(Y(3735928559)).add(r.shiftLeft(Ne(2))).add(Ne(13))).toVar();return Qp(i.add(Ne(t)),i,i)}).setLayout({name:"mx_hash_int_0",type:"uint",inputs:[{name:"x",type:"int"}]}),fW=Q(([e,t])=>{let r=Y(t).toVar(),i=Y(e).toVar(),s=Ne(Ne(2)).toVar(),a=Ne().toVar(),n=Ne().toVar(),o=Ne().toVar();return a.assign(n.assign(o.assign(Ne(Y(3735928559)).add(s.shiftLeft(Ne(2))).add(Ne(13))))),a.addAssign(Ne(i)),n.addAssign(Ne(r)),Qp(a,n,o)}).setLayout({name:"mx_hash_int_1",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),gW=Q(([e,t,r])=>{let i=Y(r).toVar(),s=Y(t).toVar(),a=Y(e).toVar(),n=Ne(Ne(3)).toVar(),o=Ne().toVar(),l=Ne().toVar(),u=Ne().toVar();return o.assign(l.assign(u.assign(Ne(Y(3735928559)).add(n.shiftLeft(Ne(2))).add(Ne(13))))),o.addAssign(Ne(a)),l.addAssign(Ne(s)),u.addAssign(Ne(i)),Qp(o,l,u)}).setLayout({name:"mx_hash_int_2",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]}),yW=Q(([e,t,r,i])=>{let s=Y(i).toVar(),a=Y(r).toVar(),n=Y(t).toVar(),o=Y(e).toVar(),l=Ne(Ne(4)).toVar(),u=Ne().toVar(),h=Ne().toVar(),d=Ne().toVar();return u.assign(h.assign(d.assign(Ne(Y(3735928559)).add(l.shiftLeft(Ne(2))).add(Ne(13))))),u.addAssign(Ne(o)),h.addAssign(Ne(n)),d.addAssign(Ne(a)),c3(u,h,d),u.addAssign(Ne(s)),Qp(u,h,d)}).setLayout({name:"mx_hash_int_3",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xx",type:"int"}]}),xW=Q(([e,t,r,i,s])=>{let a=Y(s).toVar(),n=Y(i).toVar(),o=Y(r).toVar(),l=Y(t).toVar(),u=Y(e).toVar(),h=Ne(Ne(5)).toVar(),d=Ne().toVar(),c=Ne().toVar(),m=Ne().toVar();return d.assign(c.assign(m.assign(Ne(Y(3735928559)).add(h.shiftLeft(Ne(2))).add(Ne(13))))),d.addAssign(Ne(u)),c.addAssign(Ne(l)),m.addAssign(Ne(o)),c3(d,c,m),d.addAssign(Ne(n)),c.addAssign(Ne(a)),Qp(d,c,m)}).setLayout({name:"mx_hash_int_4",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xx",type:"int"},{name:"yy",type:"int"}]}),ir=ki([mW,fW,gW,yW,xW]),vW=Q(([e,t])=>{let r=Y(t).toVar(),i=Y(e).toVar(),s=Ne(ir(i,r)).toVar(),a=Mu().toVar();return a.x.assign(s.bitAnd(Y(255))),a.y.assign(s.shiftRight(Y(8)).bitAnd(Y(255))),a.z.assign(s.shiftRight(Y(16)).bitAnd(Y(255))),a}).setLayout({name:"mx_hash_vec3_0",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),bW=Q(([e,t,r])=>{let i=Y(r).toVar(),s=Y(t).toVar(),a=Y(e).toVar(),n=Ne(ir(a,s,i)).toVar(),o=Mu().toVar();return o.x.assign(n.bitAnd(Y(255))),o.y.assign(n.shiftRight(Y(8)).bitAnd(Y(255))),o.z.assign(n.shiftRight(Y(16)).bitAnd(Y(255))),o}).setLayout({name:"mx_hash_vec3_1",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]}),va=ki([vW,bW]),TW=Q(([e])=>{let t=ke(e).toVar(),r=Y().toVar(),i=Y().toVar(),s=D(Mr(t.x,r)).toVar(),a=D(Mr(t.y,i)).toVar(),n=D(Fn(s)).toVar(),o=D(Fn(a)).toVar(),l=D(l3(Ci(ir(r,i),s,a),Ci(ir(r.add(Y(1)),i),s.sub(1),a),Ci(ir(r,i.add(Y(1))),s,a.sub(1)),Ci(ir(r.add(Y(1)),i.add(Y(1))),s.sub(1),a.sub(1)),n,o)).toVar();return h3(l)}).setLayout({name:"mx_perlin_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"}]}),SW=Q(([e])=>{let t=K(e).toVar(),r=Y().toVar(),i=Y().toVar(),s=Y().toVar(),a=D(Mr(t.x,r)).toVar(),n=D(Mr(t.y,i)).toVar(),o=D(Mr(t.z,s)).toVar(),l=D(Fn(a)).toVar(),u=D(Fn(n)).toVar(),h=D(Fn(o)).toVar(),d=D(u3(Ci(ir(r,i,s),a,n,o),Ci(ir(r.add(Y(1)),i,s),a.sub(1),n,o),Ci(ir(r,i.add(Y(1)),s),a,n.sub(1),o),Ci(ir(r.add(Y(1)),i.add(Y(1)),s),a.sub(1),n.sub(1),o),Ci(ir(r,i,s.add(Y(1))),a,n,o.sub(1)),Ci(ir(r.add(Y(1)),i,s.add(Y(1))),a.sub(1),n,o.sub(1)),Ci(ir(r,i.add(Y(1)),s.add(Y(1))),a,n.sub(1),o.sub(1)),Ci(ir(r.add(Y(1)),i.add(Y(1)),s.add(Y(1))),a.sub(1),n.sub(1),o.sub(1)),l,u,h)).toVar();return d3(d)}).setLayout({name:"mx_perlin_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"}]}),GS=ki([TW,SW]),_W=Q(([e])=>{let t=ke(e).toVar(),r=Y().toVar(),i=Y().toVar(),s=D(Mr(t.x,r)).toVar(),a=D(Mr(t.y,i)).toVar(),n=D(Fn(s)).toVar(),o=D(Fn(a)).toVar(),l=K(l3(xa(va(r,i),s,a),xa(va(r.add(Y(1)),i),s.sub(1),a),xa(va(r,i.add(Y(1))),s,a.sub(1)),xa(va(r.add(Y(1)),i.add(Y(1))),s.sub(1),a.sub(1)),n,o)).toVar();return h3(l)}).setLayout({name:"mx_perlin_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),wW=Q(([e])=>{let t=K(e).toVar(),r=Y().toVar(),i=Y().toVar(),s=Y().toVar(),a=D(Mr(t.x,r)).toVar(),n=D(Mr(t.y,i)).toVar(),o=D(Mr(t.z,s)).toVar(),l=D(Fn(a)).toVar(),u=D(Fn(n)).toVar(),h=D(Fn(o)).toVar(),d=K(u3(xa(va(r,i,s),a,n,o),xa(va(r.add(Y(1)),i,s),a.sub(1),n,o),xa(va(r,i.add(Y(1)),s),a,n.sub(1),o),xa(va(r.add(Y(1)),i.add(Y(1)),s),a.sub(1),n.sub(1),o),xa(va(r,i,s.add(Y(1))),a,n,o.sub(1)),xa(va(r.add(Y(1)),i,s.add(Y(1))),a.sub(1),n,o.sub(1)),xa(va(r,i.add(Y(1)),s.add(Y(1))),a,n.sub(1),o.sub(1)),xa(va(r.add(Y(1)),i.add(Y(1)),s.add(Y(1))),a.sub(1),n.sub(1),o.sub(1)),l,u,h)).toVar();return d3(d)}).setLayout({name:"mx_perlin_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),Kp=ki([_W,wW]),MW=Q(([e])=>{let t=D(e).toVar(),r=Y(Zr(t)).toVar();return Ki(ir(r))}).setLayout({name:"mx_cell_noise_float_0",type:"float",inputs:[{name:"p",type:"float"}]}),NW=Q(([e])=>{let t=ke(e).toVar(),r=Y(Zr(t.x)).toVar(),i=Y(Zr(t.y)).toVar();return Ki(ir(r,i))}).setLayout({name:"mx_cell_noise_float_1",type:"float",inputs:[{name:"p",type:"vec2"}]}),AW=Q(([e])=>{let t=K(e).toVar(),r=Y(Zr(t.x)).toVar(),i=Y(Zr(t.y)).toVar(),s=Y(Zr(t.z)).toVar();return Ki(ir(r,i,s))}).setLayout({name:"mx_cell_noise_float_2",type:"float",inputs:[{name:"p",type:"vec3"}]}),CW=Q(([e])=>{let t=Ve(e).toVar(),r=Y(Zr(t.x)).toVar(),i=Y(Zr(t.y)).toVar(),s=Y(Zr(t.z)).toVar(),a=Y(Zr(t.w)).toVar();return Ki(ir(r,i,s,a))}).setLayout({name:"mx_cell_noise_float_3",type:"float",inputs:[{name:"p",type:"vec4"}]}),RW=ki([MW,NW,AW,CW]),EW=Q(([e])=>{let t=D(e).toVar(),r=Y(Zr(t)).toVar();return K(Ki(ir(r,Y(0))),Ki(ir(r,Y(1))),Ki(ir(r,Y(2))))}).setLayout({name:"mx_cell_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"float"}]}),PW=Q(([e])=>{let t=ke(e).toVar(),r=Y(Zr(t.x)).toVar(),i=Y(Zr(t.y)).toVar();return K(Ki(ir(r,i,Y(0))),Ki(ir(r,i,Y(1))),Ki(ir(r,i,Y(2))))}).setLayout({name:"mx_cell_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),BW=Q(([e])=>{let t=K(e).toVar(),r=Y(Zr(t.x)).toVar(),i=Y(Zr(t.y)).toVar(),s=Y(Zr(t.z)).toVar();return K(Ki(ir(r,i,s,Y(0))),Ki(ir(r,i,s,Y(1))),Ki(ir(r,i,s,Y(2))))}).setLayout({name:"mx_cell_noise_vec3_2",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),IW=Q(([e])=>{let t=Ve(e).toVar(),r=Y(Zr(t.x)).toVar(),i=Y(Zr(t.y)).toVar(),s=Y(Zr(t.z)).toVar(),a=Y(Zr(t.w)).toVar();return K(Ki(ir(r,i,s,a,Y(0))),Ki(ir(r,i,s,a,Y(1))),Ki(ir(r,i,s,a,Y(2))))}).setLayout({name:"mx_cell_noise_vec3_3",type:"vec3",inputs:[{name:"p",type:"vec4"}]}),vy=ki([EW,PW,BW,IW]),by=Q(([e,t,r,i])=>{let s=D(i).toVar(),a=D(r).toVar(),n=Y(t).toVar(),o=K(e).toVar(),l=D(0).toVar(),u=D(1).toVar();return Qt(n,()=>{l.addAssign(u.mul(GS(o))),u.mulAssign(s),o.mulAssign(a)}),l}).setLayout({name:"mx_fractal_noise_float",type:"float",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),Ty=Q(([e,t,r,i])=>{let s=D(i).toVar(),a=D(r).toVar(),n=Y(t).toVar(),o=K(e).toVar(),l=K(0).toVar(),u=D(1).toVar();return Qt(n,()=>{l.addAssign(u.mul(Kp(o))),u.mulAssign(s),o.mulAssign(a)}),l}).setLayout({name:"mx_fractal_noise_vec3",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),FW=Q(([e,t,r,i])=>{let s=D(i).toVar(),a=D(r).toVar(),n=Y(t).toVar(),o=K(e).toVar();return ke(by(o,n,a,s),by(o.add(K(Y(19),Y(193),Y(17))),n,a,s))}).setLayout({name:"mx_fractal_noise_vec2",type:"vec2",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),LW=Q(([e,t,r,i])=>{let s=D(i).toVar(),a=D(r).toVar(),n=Y(t).toVar(),o=K(e).toVar(),l=K(Ty(o,n,a,s)).toVar(),u=D(by(o.add(K(Y(19),Y(193),Y(17))),n,a,s)).toVar();return Ve(l,u)}).setLayout({name:"mx_fractal_noise_vec4",type:"vec4",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),kW=Q(([e,t,r,i,s,a,n])=>{let o=Y(n).toVar(),l=D(a).toVar(),u=Y(s).toVar(),h=Y(i).toVar(),d=Y(r).toVar(),c=Y(t).toVar(),m=ke(e).toVar(),g=K(vy(ke(c.add(h),d.add(u)))).toVar(),y=ke(g.x,g.y).toVar();y.subAssign(.5),y.mulAssign(l),y.addAssign(.5);let b=ke(ke(D(c),D(d)).add(y)).toVar(),v=ke(b.sub(m)).toVar();return et(o.equal(Y(2)),()=>ur(v.x).add(ur(v.y))),et(o.equal(Y(3)),()=>Br(ur(v.x),ur(v.y))),pa(v,v)}).setLayout({name:"mx_worley_distance_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"x",type:"int"},{name:"y",type:"int"},{name:"xoff",type:"int"},{name:"yoff",type:"int"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),DW=Q(([e,t,r,i,s,a,n,o,l])=>{let u=Y(l).toVar(),h=D(o).toVar(),d=Y(n).toVar(),c=Y(a).toVar(),m=Y(s).toVar(),g=Y(i).toVar(),y=Y(r).toVar(),b=Y(t).toVar(),v=K(e).toVar(),S=K(vy(K(b.add(m),y.add(c),g.add(d)))).toVar();S.subAssign(.5),S.mulAssign(h),S.addAssign(.5);let T=K(K(D(b),D(y),D(g)).add(S)).toVar(),w=K(T.sub(v)).toVar();return et(u.equal(Y(2)),()=>ur(w.x).add(ur(w.y)).add(ur(w.z))),et(u.equal(Y(3)),()=>Br(ur(w.x),ur(w.y),ur(w.z))),pa(w,w)}).setLayout({name:"mx_worley_distance_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xoff",type:"int"},{name:"yoff",type:"int"},{name:"zoff",type:"int"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),Ud=ki([kW,DW]),OW=Q(([e,t,r])=>{let i=Y(r).toVar(),s=D(t).toVar(),a=ke(e).toVar(),n=Y().toVar(),o=Y().toVar(),l=ke(Mr(a.x,n),Mr(a.y,o)).toVar(),u=D(1e6).toVar();return Qt({start:-1,end:Y(1),name:"x",condition:"<="},({x:h})=>{Qt({start:-1,end:Y(1),name:"y",condition:"<="},({y:d})=>{let c=D(Ud(l,h,d,n,o,s,i)).toVar();u.assign(Rs(u,c))})}),et(i.equal(Y(0)),()=>{u.assign(ys(u))}),u}).setLayout({name:"mx_worley_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),UW=Q(([e,t,r])=>{let i=Y(r).toVar(),s=D(t).toVar(),a=ke(e).toVar(),n=Y().toVar(),o=Y().toVar(),l=ke(Mr(a.x,n),Mr(a.y,o)).toVar(),u=ke(1e6,1e6).toVar();return Qt({start:-1,end:Y(1),name:"x",condition:"<="},({x:h})=>{Qt({start:-1,end:Y(1),name:"y",condition:"<="},({y:d})=>{let c=D(Ud(l,h,d,n,o,s,i)).toVar();et(c.lessThan(u.x),()=>{u.y.assign(u.x),u.x.assign(c)}).ElseIf(c.lessThan(u.y),()=>{u.y.assign(c)})})}),et(i.equal(Y(0)),()=>{u.assign(ys(u))}),u}).setLayout({name:"mx_worley_noise_vec2_0",type:"vec2",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),zW=Q(([e,t,r])=>{let i=Y(r).toVar(),s=D(t).toVar(),a=ke(e).toVar(),n=Y().toVar(),o=Y().toVar(),l=ke(Mr(a.x,n),Mr(a.y,o)).toVar(),u=K(1e6,1e6,1e6).toVar();return Qt({start:-1,end:Y(1),name:"x",condition:"<="},({x:h})=>{Qt({start:-1,end:Y(1),name:"y",condition:"<="},({y:d})=>{let c=D(Ud(l,h,d,n,o,s,i)).toVar();et(c.lessThan(u.x),()=>{u.z.assign(u.y),u.y.assign(u.x),u.x.assign(c)}).ElseIf(c.lessThan(u.y),()=>{u.z.assign(u.y),u.y.assign(c)}).ElseIf(c.lessThan(u.z),()=>{u.z.assign(c)})})}),et(i.equal(Y(0)),()=>{u.assign(ys(u))}),u}).setLayout({name:"mx_worley_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),VW=Q(([e,t,r])=>{let i=Y(r).toVar(),s=D(t).toVar(),a=K(e).toVar(),n=Y().toVar(),o=Y().toVar(),l=Y().toVar(),u=K(Mr(a.x,n),Mr(a.y,o),Mr(a.z,l)).toVar(),h=D(1e6).toVar();return Qt({start:-1,end:Y(1),name:"x",condition:"<="},({x:d})=>{Qt({start:-1,end:Y(1),name:"y",condition:"<="},({y:c})=>{Qt({start:-1,end:Y(1),name:"z",condition:"<="},({z:m})=>{let g=D(Ud(u,d,c,m,n,o,l,s,i)).toVar();h.assign(Rs(h,g))})})}),et(i.equal(Y(0)),()=>{h.assign(ys(h))}),h}).setLayout({name:"mx_worley_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),GW=ki([OW,VW]),WW=Q(([e,t,r])=>{let i=Y(r).toVar(),s=D(t).toVar(),a=K(e).toVar(),n=Y().toVar(),o=Y().toVar(),l=Y().toVar(),u=K(Mr(a.x,n),Mr(a.y,o),Mr(a.z,l)).toVar(),h=ke(1e6,1e6).toVar();return Qt({start:-1,end:Y(1),name:"x",condition:"<="},({x:d})=>{Qt({start:-1,end:Y(1),name:"y",condition:"<="},({y:c})=>{Qt({start:-1,end:Y(1),name:"z",condition:"<="},({z:m})=>{let g=D(Ud(u,d,c,m,n,o,l,s,i)).toVar();et(g.lessThan(h.x),()=>{h.y.assign(h.x),h.x.assign(g)}).ElseIf(g.lessThan(h.y),()=>{h.y.assign(g)})})})}),et(i.equal(Y(0)),()=>{h.assign(ys(h))}),h}).setLayout({name:"mx_worley_noise_vec2_1",type:"vec2",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),jW=ki([UW,WW]),HW=Q(([e,t,r])=>{let i=Y(r).toVar(),s=D(t).toVar(),a=K(e).toVar(),n=Y().toVar(),o=Y().toVar(),l=Y().toVar(),u=K(Mr(a.x,n),Mr(a.y,o),Mr(a.z,l)).toVar(),h=K(1e6,1e6,1e6).toVar();return Qt({start:-1,end:Y(1),name:"x",condition:"<="},({x:d})=>{Qt({start:-1,end:Y(1),name:"y",condition:"<="},({y:c})=>{Qt({start:-1,end:Y(1),name:"z",condition:"<="},({z:m})=>{let g=D(Ud(u,d,c,m,n,o,l,s,i)).toVar();et(g.lessThan(h.x),()=>{h.z.assign(h.y),h.y.assign(h.x),h.x.assign(g)}).ElseIf(g.lessThan(h.y),()=>{h.z.assign(h.y),h.y.assign(g)}).ElseIf(g.lessThan(h.z),()=>{h.z.assign(g)})})})}),et(i.equal(Y(0)),()=>{h.assign(ys(h))}),h}).setLayout({name:"mx_worley_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),WS=ki([zW,HW]),XW=Q(([e,t,r,i,s,a,n,o,l,u,h])=>{let d=Y(e).toVar(),c=ke(t).toVar(),m=ke(r).toVar(),g=ke(i).toVar(),y=D(s).toVar(),b=D(a).toVar(),v=D(n).toVar(),S=Gs(o).toVar(),T=Y(l).toVar(),w=D(u).toVar(),N=D(h).toVar(),C=c.mul(m).add(g),R=D(0).toVar();return et(d.equal(Y(0)),()=>{R.assign(Kp(C))}),et(d.equal(Y(1)),()=>{R.assign(vy(C))}),et(d.equal(Y(2)),()=>{R.assign(WS(C,y,Y(0)))}),et(d.equal(Y(3)),()=>{R.assign(Ty(K(C,0),T,w,N))}),R.assign(R.mul(v.sub(b)).add(b)),et(S,()=>{R.assign(za(R,b,v))}),R}).setLayout({name:"mx_unifiednoise2d",type:"float",inputs:[{name:"noiseType",type:"int"},{name:"texcoord",type:"vec2"},{name:"freq",type:"vec2"},{name:"offset",type:"vec2"},{name:"jitter",type:"float"},{name:"outmin",type:"float"},{name:"outmax",type:"float"},{name:"clampoutput",type:"bool"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),$W=Q(([e,t,r,i,s,a,n,o,l,u,h])=>{let d=Y(e).toVar(),c=K(t).toVar(),m=K(r).toVar(),g=K(i).toVar(),y=D(s).toVar(),b=D(a).toVar(),v=D(n).toVar(),S=Gs(o).toVar(),T=Y(l).toVar(),w=D(u).toVar(),N=D(h).toVar(),C=c.mul(m).add(g),R=D(0).toVar();return et(d.equal(Y(0)),()=>{R.assign(Kp(C))}),et(d.equal(Y(1)),()=>{R.assign(vy(C))}),et(d.equal(Y(2)),()=>{R.assign(WS(C,y,Y(0)))}),et(d.equal(Y(3)),()=>{R.assign(Ty(C,T,w,N))}),R.assign(R.mul(v.sub(b)).add(b)),et(S,()=>{R.assign(za(R,b,v))}),R}).setLayout({name:"mx_unifiednoise3d",type:"float",inputs:[{name:"noiseType",type:"int"},{name:"position",type:"vec3"},{name:"freq",type:"vec3"},{name:"offset",type:"vec3"},{name:"jitter",type:"float"},{name:"outmin",type:"float"},{name:"outmax",type:"float"},{name:"clampoutput",type:"bool"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),qW=Q(([e])=>{let t=e.y,r=e.z,i=K().toVar();return et(t.lessThan(1e-4),()=>{i.assign(K(r,r,r))}).Else(()=>{let s=e.x;s=s.sub(Mn(s)).mul(6).toVar();let a=Y(Ub(s)),n=s.sub(D(a)),o=r.mul(t.oneMinus()),l=r.mul(t.mul(n).oneMinus()),u=r.mul(t.mul(n.oneMinus()).oneMinus());et(a.equal(Y(0)),()=>{i.assign(K(r,u,o))}).ElseIf(a.equal(Y(1)),()=>{i.assign(K(l,r,o))}).ElseIf(a.equal(Y(2)),()=>{i.assign(K(o,r,u))}).ElseIf(a.equal(Y(3)),()=>{i.assign(K(o,l,r))}).ElseIf(a.equal(Y(4)),()=>{i.assign(K(u,o,r))}).Else(()=>{i.assign(K(r,o,l))})}),i}).setLayout({name:"mx_hsvtorgb",type:"vec3",inputs:[{name:"hsv",type:"vec3"}]}),YW=Q(([e])=>{let t=K(e).toVar(),r=D(t.x).toVar(),i=D(t.y).toVar(),s=D(t.z).toVar(),a=D(Rs(r,Rs(i,s))).toVar(),n=D(Br(r,Br(i,s))).toVar(),o=D(n.sub(a)).toVar(),l=D().toVar(),u=D().toVar(),h=D().toVar();return h.assign(n),et(n.greaterThan(0),()=>{u.assign(o.div(n))}).Else(()=>{u.assign(0)}),et(u.lessThanEqual(0),()=>{l.assign(0)}).Else(()=>{et(r.greaterThanEqual(n),()=>{l.assign(i.sub(s).div(o))}).ElseIf(i.greaterThanEqual(n),()=>{l.assign(Yr(2,s.sub(r).div(o)))}).Else(()=>{l.assign(Yr(4,r.sub(i).div(o)))}),l.mulAssign(1/6),et(l.lessThan(0),()=>{l.addAssign(1)})}),K(l,u,h)}).setLayout({name:"mx_rgbtohsv",type:"vec3",inputs:[{name:"c",type:"vec3"}]}),ZW=Q(([e])=>{let t=K(e).toVar(),r=Tb(Eb(t,K(.04045))).toVar(),i=K(t.div(12.92)).toVar(),s=K(ma(Br(t.add(K(.055)),K(0)).div(1.055),K(2.4))).toVar();return Ct(i,s,r)}).setLayout({name:"mx_srgb_texture_to_lin_rec709",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),p3=(e,t)=>{e=D(e),t=D(t);let r=ke(t.dFdx(),t.dFdy()).length().mul(.7071067811865476);return Hs(e.sub(r),e.add(r),t)},m3=(e,t,r,i)=>Ct(e,t,r[i].clamp()),JW=(e,t,r=Jt())=>m3(e,t,r,"x"),QW=(e,t,r=Jt())=>m3(e,t,r,"y"),KW=(e,t,r,i,s=Jt())=>{let a=s.x.clamp(),n=s.y.clamp(),o=Ct(e,t,a),l=Ct(r,i,a);return Ct(o,l,n)},f3=(e,t,r,i,s)=>Ct(e,t,p3(r,i[s])),ej=(e,t,r,i=Jt())=>f3(e,t,r,i,"x"),tj=(e,t,r,i=Jt())=>f3(e,t,r,i,"y"),rj=(e=1,t=0,r=Jt())=>r.mul(e).add(t),ij=(e,t=1)=>(e=D(e),e.abs().pow(t).mul(e.sign())),sj=(e,t=1,r=.5)=>D(e).sub(r).mul(t).add(r),aj=(e=Jt(),t=1,r=0)=>GS(e.convert("vec2|vec3")).mul(t).add(r),nj=(e=Jt(),t=1,r=0)=>Kp(e.convert("vec2|vec3")).mul(t).add(r),oj=(e=Jt(),t=1,r=0)=>(e=e.convert("vec2|vec3"),Ve(Kp(e),GS(e.add(ke(19,73)))).mul(t).add(r)),lj=(e,t=Jt(),r=ke(1,1),i=ke(0,0),s=1,a=0,n=1,o=!1,l=1,u=2,h=.5)=>XW(e,t.convert("vec2|vec3"),r,i,s,a,n,o,l,u,h),uj=(e,t=Jt(),r=ke(1,1),i=ke(0,0),s=1,a=0,n=1,o=!1,l=1,u=2,h=.5)=>$W(e,t.convert("vec2|vec3"),r,i,s,a,n,o,l,u,h),hj=(e=Jt(),t=1)=>GW(e.convert("vec2|vec3"),t,Y(1)),dj=(e=Jt(),t=1)=>jW(e.convert("vec2|vec3"),t,Y(1)),cj=(e=Jt(),t=1)=>WS(e.convert("vec2|vec3"),t,Y(1)),pj=(e=Jt())=>RW(e.convert("vec2|vec3")),mj=(e=Jt(),t=3,r=2,i=.5,s=1)=>by(e,Y(t),r,i).mul(s),fj=(e=Jt(),t=3,r=2,i=.5,s=1)=>FW(e,Y(t),r,i).mul(s),gj=(e=Jt(),t=3,r=2,i=.5,s=1)=>Ty(e,Y(t),r,i).mul(s),yj=(e=Jt(),t=3,r=2,i=.5,s=1)=>LW(e,Y(t),r,i).mul(s),xj=(e,t=D(0))=>Yr(e,t),vj=(e,t=D(0))=>It(e,t),bj=(e,t=D(1))=>mt(e,t),Tj=(e,t=D(1))=>js(e,t),Sj=(e,t=D(1))=>c0(e,t),_j=(e,t=D(1))=>ma(e,t),wj=(e=D(0),t=D(1))=>Fb(e,t),Mj=()=>Fd,Nj=()=>xP,Aj=(e,t=D(1))=>It(t,e),Cj=(e,t,r,i)=>e.greaterThan(t).mix(r,i),Rj=(e,t,r,i)=>e.greaterThanEqual(t).mix(r,i),Ej=(e,t,r,i)=>e.equal(t).mix(r,i),Pj=(e,t=null)=>{if(typeof t=="string"){let r={x:0,r:0,y:1,g:1,z:2,b:2,w:3,a:3},i=t.replace(/^out/,"").toLowerCase();if(r[i]!==void 0)return e.element(r[i])}if(typeof t=="number")return e.element(t);if(typeof t=="string"&&t.length===1){let r={x:0,r:0,y:1,g:1,z:2,b:2,w:3,a:3};if(r[t]!==void 0)return e.element(r[t])}return e},Bj=(e,t=ke(.5,.5),r=ke(1,1),i=D(0),s=ke(0,0))=>{let a=e;if(t&&(a=a.sub(t)),r&&(a=a.mul(r)),i){let n=i.mul(Math.PI/180),o=n.cos(),l=n.sin();a=ke(a.x.mul(o).sub(a.y.mul(l)),a.x.mul(l).add(a.y.mul(o)))}return t&&(a=a.add(t)),s&&(a=a.add(s)),a},Ij=(e,t)=>{e=ke(e),t=D(t);let r=t.mul(Math.PI/180);return Gp(e,r)},Fj=(e,t,r)=>{e=K(e),t=D(t),r=K(r);let i=t.mul(Math.PI/180),s=r.normalize(),a=i.cos(),n=i.sin(),o=D(1).sub(a);return e.mul(a).add(s.cross(e).mul(n)).add(s.mul(s.dot(e)).mul(o))},Lj=(e,t)=>(e=K(e),t=D(t),AT(e,t)),kj=Q(([e,t,r])=>{let i=Yi(e).toVar(),s=It(D(.5).mul(t.sub(r)),Rn).div(i).toVar(),a=It(D(-.5).mul(t.sub(r)),Rn).div(i).toVar(),n=K().toVar();n.x=i.x.greaterThan(D(0)).select(s.x,a.x),n.y=i.y.greaterThan(D(0)).select(s.y,a.y),n.z=i.z.greaterThan(D(0)).select(s.z,a.z);let o=Rs(n.x,n.y,n.z).toVar();return Rn.add(i.mul(o)).toVar().sub(r)}),g3=Q(([e,t])=>{let r=e.x,i=e.y,s=e.z,a=t.element(0).mul(.886227);return a=a.add(t.element(1).mul(2*.511664).mul(i)),a=a.add(t.element(2).mul(2*.511664).mul(s)),a=a.add(t.element(3).mul(2*.511664).mul(r)),a=a.add(t.element(4).mul(2*.429043).mul(r).mul(i)),a=a.add(t.element(5).mul(2*.429043).mul(i).mul(s)),a=a.add(t.element(6).mul(s.mul(s).mul(.743125).sub(.247708))),a=a.add(t.element(7).mul(2*.429043).mul(r).mul(s)),a=a.add(t.element(8).mul(.429043).mul(mt(r,r).sub(mt(i,i)))),a}),M=Object.freeze({__proto__:null,BRDF_GGX:JT,BRDF_Lambert:Wu,BasicPointShadowFilter:s3,BasicShadowFilter:$P,Break:KR,Const:mC,Continue:zz,DFGLUT:Dp,D_GGX:TE,Discard:BC,EPSILON:p0,F_Schlick:Bd,Fn:Q,HALF_PI:u6,INFINITY:n6,If:et,Loop:Qt,NodeAccess:Fi,NodeShaderStage:xd,NodeType:EU,NodeUpdateType:ut,OnBeforeFrameUpdate:Pz,OnBeforeMaterialUpdate:Ez,OnBeforeObjectUpdate:Rz,OnFrameUpdate:jR,OnMaterialUpdate:Cz,OnObjectUpdate:Lp,PCFShadowFilter:qP,PCFSoftShadowFilter:YP,PI:m0,PI2:o6,PointShadowFilter:a3,Return:C6,Schlick_to_F0:QT,ShaderNode:bd,Stack:r0,Switch:QU,TBNViewMatrix:Uu,TWO_PI:l6,VSMShadowFilter:ZP,V_GGX_SmithCorrelated:bE,Var:pC,VarIntent:fC,abs:ur,acesFilmicToneMapping:IP,acos:Ib,acosh:WA,add:Yr,addMethodChaining:xe,addNodeElement:B6,agxToneMapping:FP,all:IA,alphaT:l0,ambientOcclusion:Rb,and:vA,anisotropy:dl,anisotropyB:Cu,anisotropyT:Ap,any:FA,append:e6,array:dA,asin:VA,asinh:GA,assign:cA,atan:Fb,atanh:jA,atomicAdd:i9,atomicAnd:o9,atomicFunc:In,atomicLoad:t9,atomicMax:a9,atomicMin:n9,atomicOr:l9,atomicStore:r9,atomicSub:s9,atomicXor:u9,attenuationColor:Ab,attenuationDistance:Nb,attribute:$s,attributeArray:Z8,backgroundBlurriness:TP,backgroundIntensity:wS,backgroundRotation:SP,batch:YR,batchColor:OT,bentNormalView:pR,billboarding:B8,bitAnd:_A,bitNot:wA,bitOr:MA,bitXor:NA,bitangentGeometry:xz,bitangentLocal:vz,bitangentView:dR,bitangentWorld:bz,bitcast:gP,blendBurn:d7,blendColor:f7,blendDodge:c7,blendOverlay:m7,blendScreen:p7,blur:GE,bool:Gs,buffer:Md,bufferAttribute:Jb,builtin:bo,builtinAOContext:dC,builtinShadowContext:hC,bumpMap:AT,bvec2:iA,bvec3:Tb,bvec4:sA,bypass:EC,cache:RC,call:pA,cameraFar:yl,cameraIndex:fl,cameraNear:gl,cameraNormalMatrix:H6,cameraPosition:VC,cameraProjectionMatrix:bs,cameraProjectionMatrixInverse:zC,cameraViewMatrix:xl,cameraViewport:X6,cameraWorldMatrix:Ip,cbrt:sC,cdl:b7,ceil:g0,checker:eW,cineonToneMapping:BP,clamp:za,clearcoat:s0,clearcoatNormalView:bl,clearcoatRoughness:Td,clipSpace:HC,code:cy,color:rA,colorSpaceToWorking:v0,colorToDirection:_z,compute:CC,computeKernel:Kb,computeSkinning:Oz,context:vo,convert:nA,convertColorSpace:g6,convertToTexture:j8,cos:Ua,cosh:OA,countLeadingZeros:l8,countOneBits:u8,countTrailingZeros:o8,cross:xo,cubeTexture:Ts,cubeTextureBase:TT,dFdx:Db,dFdy:Ob,dashSize:Pu,debug:FC,decrement:BA,decrementBefore:EA,defaultBuildStages:Zg,defaultShaderStages:XN,defined:vd,degrees:kA,deltaTime:w8,densityFogFactor:OP,depth:HT,depthPass:N7,determinant:YA,difference:KA,diffuseColor:Zt,diffuseContribution:Au,directPointLight:o3,directionToColor:Sz,directionToFaceDirection:nz,dispersion:Cb,disposeShadowMaterial:QP,distance:QA,div:js,dot:pa,drawIndex:AC,dynamicBufferAttribute:T6,element:aA,emissive:wb,equal:mA,equirectDirection:qT,equirectUV:$T,exp:Pb,exp2:_d,exponentialHeightFogFactor:O7,expression:Xs,faceDirection:yT,faceForward:Hb,faceforward:h6,float:D,floatBitsToInt:s8,floatBitsToUint:yP,floor:Mn,fog:RS,fract:Oa,frameGroup:r6,frameId:xP,frontFacing:XC,fwidth:zb,gain:d8,gapSize:Cp,getConstNodeType:tA,getCurrentStack:xb,getDirection:zE,getDistanceAttenuation:VS,getGeometryRoughness:vE,getNormalFromDepth:X8,getParallaxCorrectNormal:kj,getRoughness:ZT,getScreenPosition:H8,getShIrradianceAt:g3,getShadowMaterial:JP,getShadowRenderObjectFunction:e3,getTextureIndex:mP,getViewPosition:Dd,ggxConvolution:WE,globalId:j7,glsl:L7,glslFn:k7,grayscale:g7,greaterThan:Eb,greaterThanEqual:xA,hash:h8,highpModelNormalViewMatrix:fT,highpModelViewMatrix:mT,hue:v7,increment:PA,incrementBefore:RA,inspector:kC,instance:$R,instanceColor:DT,instanceIndex:Va,instancedArray:J8,instancedBufferAttribute:T0,instancedDynamicBufferAttribute:Qb,instancedMesh:qR,int:Y,intBitsToFloat:a8,interleavedGradientNoise:SS,inverse:ZA,inverseSqrt:Bb,inversesqrt:d6,invocationLocalIndex:w6,invocationSubgroupIndex:_6,ior:Rp,iridescence:a0,iridescenceIOR:n0,iridescenceThickness:o0,isolate:wd,ivec2:Pr,ivec3:bb,ivec4:Sb,js:I7,label:cC,length:Nn,lengthSq:Wb,lessThan:gA,lessThanEqual:yA,lightPosition:PS,lightProjectionUV:UP,lightShadowMatrix:fy,lightTargetDirection:IS,lightTargetPosition:zP,lightViewPosition:BS,lightingContext:iE,lights:z9,linearDepth:H0,linearToneMapping:EP,localId:H7,log:f0,log2:wn,logarithmicDepthToViewZ:Yz,luminance:NS,mat2:i0,mat3:Ni,mat4:ul,matcapUV:QE,materialAO:GR,materialAlphaTest:gR,materialAnisotropy:PR,materialAnisotropyVector:Cd,materialAttenuationColor:UR,materialAttenuationDistance:OR,materialClearcoat:MR,materialClearcoatNormal:AR,materialClearcoatRoughness:NR,materialColor:yR,materialDispersion:VR,materialEmissive:vR,materialEnvIntensity:B0,materialEnvRotation:I0,materialIOR:DR,materialIridescence:BR,materialIridescenceIOR:IR,materialIridescenceThickness:FR,materialLightMap:FT,materialLineDashOffset:IT,materialLineDashSize:PT,materialLineGapSize:BT,materialLineScale:ET,materialLineWidth:U0,materialMetalness:_R,materialNormal:wR,materialOpacity:CT,materialPointSize:zR,materialReference:To,materialReflectivity:O0,materialRefractionRatio:YC,materialRotation:CR,materialRoughness:SR,materialSheen:RR,materialSheenRoughness:ER,materialShininess:xR,materialSpecular:bR,materialSpecularColor:TR,materialSpecularIntensity:RT,materialSpecularStrength:Fp,materialThickness:kR,materialTransmission:LR,max:Br,maxMipLevel:rT,mediumpModelViewMatrix:jC,metalness:yo,min:Rs,mix:Ct,mixElement:nC,mod:c0,modelDirection:K6,modelNormalMatrix:WC,modelPosition:ez,modelRadius:iz,modelScale:tz,modelViewMatrix:Cn,modelViewPosition:rz,modelViewProjection:WR,modelWorldMatrix:ga,modelWorldMatrixInverse:sz,morphReference:rE,mrt:fP,mul:mt,mx_aastep:p3,mx_add:xj,mx_atan2:wj,mx_cell_noise_float:pj,mx_contrast:sj,mx_divide:Tj,mx_fractal_noise_float:mj,mx_fractal_noise_vec2:fj,mx_fractal_noise_vec3:gj,mx_fractal_noise_vec4:yj,mx_frame:Nj,mx_heighttonormal:Lj,mx_hsvtorgb:qW,mx_ifequal:Ej,mx_ifgreater:Cj,mx_ifgreatereq:Rj,mx_invert:Aj,mx_modulo:Sj,mx_multiply:bj,mx_noise_float:aj,mx_noise_vec3:nj,mx_noise_vec4:oj,mx_place2d:Bj,mx_power:_j,mx_ramp4:KW,mx_ramplr:JW,mx_ramptb:QW,mx_rgbtohsv:YW,mx_rotate2d:Ij,mx_rotate3d:Fj,mx_safepower:ij,mx_separate:Pj,mx_splitlr:ej,mx_splittb:tj,mx_srgb_texture_to_lin_rec709:ZW,mx_subtract:vj,mx_timer:Mj,mx_transform_uv:rj,mx_unifiednoise2d:lj,mx_unifiednoise3d:uj,mx_worley_noise_float:hj,mx_worley_noise_vec2:dj,mx_worley_noise_vec3:cj,negate:kb,negateOnBackSide:Ou,neutralToneMapping:LP,nodeArray:wu,nodeImmutable:ze,nodeObject:Ye,nodeObjectIntent:Mp,nodeObjects:t0,nodeProxy:Mt,nodeProxyConstructor:yb,nodeProxyIntent:Ee,normalFlat:$C,normalGeometry:P0,normalLocal:Qi,normalMap:NT,normalView:Ut,normalViewGeometry:Ad,normalWorld:vl,normalWorldGeometry:qC,normalize:Yi,not:TA,notEqual:fA,numWorkgroups:G7,objectDirection:$6,objectGroup:uA,objectPosition:Y6,objectRadius:Q6,objectScale:Z6,objectViewPosition:J6,objectWorldMatrix:q6,oneMinus:HA,or:bA,orthographicDepthToViewZ:aE,oscSawtooth:C8,oscSine:M8,oscSquare:N8,oscTriangle:A8,output:Sd,outputStruct:e8,overloadingFn:ki,overrideNode:uP,overrideNodes:hP,packHalf2x16:g8,packNormalToRGB:wT,packSnorm2x16:m8,packUnorm2x16:f8,parabola:yS,parallaxDirection:cR,parallaxUV:Tz,parameter:YG,pass:w7,passTexture:M7,pcurve:c8,perspectiveDepthToViewZ:W0,pmremTexture:cS,pointShadow:n3,pointUV:K8,pointWidth:t6,positionGeometry:Ji,positionLocal:wr,positionPrevious:Du,positionView:Wr,positionViewDirection:ar,positionWorld:Rn,positionWorldDirection:gT,posterize:T7,pow:ma,pow2:Vb,pow3:eC,pow4:Gb,premultiplyAlpha:tT,property:go,quadBroadcast:F9,quadSwapDiagonal:C9,quadSwapX:N9,quadSwapY:A9,radians:LA,rand:aC,range:z7,rangeFogFactor:DP,reciprocal:$A,reference:cr,referenceBuffer:tR,reflect:JA,reflectVector:QC,reflectView:ZC,reflector:U8,refract:jb,refractVector:KC,refractView:JC,reinhardToneMapping:PP,remap:eT,remapClamp:PC,renderGroup:st,renderOutput:_0,rendererReference:TC,replaceDefaultUV:R8,rotate:Gp,rotateUV:E8,roughness:_n,round:XA,rtt:bP,sRGBTransferEOTF:yC,sRGBTransferOETF:xC,sample:q8,sampler:O6,samplerComparison:U6,saturate:y0,saturation:y7,screenCoordinate:ku,screenDPR:aT,screenSize:Lu,screenUV:Ga,select:Zi,setCurrentStack:Np,setName:$b,shaderStages:Jg,shadow:r3,shadowPositionWorld:kS,shapeCircle:tW,sharedUniformGroup:d0,sheen:Ws,sheenRoughness:hl,shiftLeft:AA,shiftRight:CA,shininess:u0,sign:Lb,sin:xs,sinc:p8,sinh:DA,skinning:QR,smoothstep:Hs,smoothstepElement:oC,specularColor:cl,specularColorBlended:Ru,specularF90:Eu,spherizeUV:P8,split:KU,spritesheetUV:F8,sqrt:ys,stack:iy,step:Bu,stepElement:lC,storage:Sl,storageBarrier:Y7,storageTexture:wP,storageTexture3D:r7,struct:KG,sub:It,subBuild:Iu,subgroupAdd:c9,subgroupAll:_9,subgroupAnd:x9,subgroupAny:w9,subgroupBallot:d9,subgroupBroadcast:R9,subgroupBroadcastFirst:M9,subgroupElect:h9,subgroupExclusiveAdd:m9,subgroupExclusiveMul:y9,subgroupInclusiveAdd:p9,subgroupInclusiveMul:g9,subgroupIndex:S6,subgroupMax:S9,subgroupMin:T9,subgroupMul:f9,subgroupOr:v9,subgroupShuffle:E9,subgroupShuffleDown:I9,subgroupShuffleUp:B9,subgroupShuffleXor:P9,subgroupSize:X7,subgroupXor:b9,tan:UA,tangentGeometry:L0,tangentLocal:Tl,tangentView:k0,tangentWorld:hR,tanh:zA,texture:Ot,texture3D:MS,texture3DLevel:n7,texture3DLoad:a7,textureBarrier:Z7,textureBicubic:EV,textureBicubicLevel:rS,textureCubeUV:VE,textureLevel:D6,textureLoad:Gr,textureSize:Fu,textureStore:e7,thickness:Mb,time:Fd,toneMapping:SC,toneMappingExposure:_C,toonOutlinePass:C7,transformDirection:tC,transformNormal:xT,transformNormalByInverseViewMatrix:iC,transformNormalByViewMatrix:rC,transformNormalToView:vT,transformedClearcoatNormalView:uz,transformedNormalView:oz,transformedNormalWorld:lz,transmission:h0,transpose:qA,triNoise3D:T8,triplanarTexture:L8,triplanarTextures:vP,trunc:Ub,uint:Ne,uintBitsToFloat:n8,uniform:Qe,uniformArray:Li,uniformCubeTexture:dz,uniformFlow:uC,uniformGroup:lA,uniformTexture:k6,unpackHalf2x16:v8,unpackNormal:MT,unpackRGBToNormal:mR,unpackSnorm2x16:y8,unpackUnorm2x16:x8,unpremultiplyAlpha:IC,userData:l7,uv:Jt,uvec2:vb,uvec3:Mu,uvec4:_b,varying:pl,varyingProperty:Nu,vec2:ke,vec3:K,vec4:Ve,vectorComponents:Su,velocity:h7,vertexColor:hE,vertexIndex:NC,vertexStage:gC,vibrance:x7,viewZToLogarithmicDepth:j0,viewZToOrthographicDepth:Vu,viewZToPerspectiveDepth:jT,viewZToReversedOrthographicDepth:qz,viewZToReversedPerspectiveDepth:nE,viewport:Nd,viewportCoordinate:UC,viewportDepthTexture:WT,viewportLinearDepth:Zz,viewportMipTexture:VT,viewportOpaqueMipTexture:sE,viewportResolution:j6,viewportSafeUV:I8,viewportSharedTexture:_7,viewportSize:nT,viewportTexture:Hz,viewportUV:W6,vogelDiskSample:ja,wgsl:F7,wgslFn:D7,workgroupArray:K7,workgroupBarrier:q7,workgroupId:W7,workingToColorSpace:vC,xor:SA}),Ha=new gS,Dj=class extends Nl{constructor(e,t){super(),this.renderer=e,this.nodes=t}update(e,t,r){let i=this.renderer,s=this.nodes.getBackgroundNode(e)||e.background,a=!1;if(s===null)i._clearColor.getRGB(Ha),Ha.a=i._clearColor.a;else if(s.isColor===!0)s.getRGB(Ha),Ha.a=1,a=!0;else if(s.isNode===!0){let o=this.get(e),l=s;Ha.copy(i._clearColor);let u=o.backgroundMesh;if(u===void 0){let d=function(){s.removeEventListener("dispose",d),u.material.dispose(),u.geometry.dispose()},c=Ve(l).mul(wS).context({getUV:()=>SP.mul(qC),getTextureLevel:()=>TP}),m=bs.element(3).element(3).equal(1),g=js(1,bs.element(1).element(1)).mul(3),y=m.select(wr.mul(g),wr),b=Cn.mul(Ve(y,0)),v=bs.mul(Ve(b.xyz,1));v=v.setZ(v.w);let S=new Pt;S.name="Background.material",S.side=ii,S.depthTest=!1,S.depthWrite=!1,S.allowOverride=!1,S.fog=!1,S.lights=!1,S.vertexNode=v,S.colorNode=c,o.backgroundMeshNode=c,o.backgroundMesh=u=new Mi(new eb(1,32,32),S),u.frustumCulled=!1,u.name="Background.mesh",s.addEventListener("dispose",d)}let h=l.getCacheKey();o.backgroundCacheKey!==h&&(o.backgroundMeshNode.node=Ve(l).mul(wS),o.backgroundMeshNode.needsUpdate=!0,u.material.needsUpdate=!0,o.backgroundCacheKey=h),t.unshift(u,u.geometry,u.material,0,0,null,null)}else Ce("Renderer: Unsupported background configuration.",s);let n=i.xr.getEnvironmentBlendMode();if(n==="additive"?Ha.set(0,0,0,1):n==="alpha-blend"&&Ha.set(0,0,0,0),i.autoClear===!0||a===!0){let o=r.clearColorValue;o.r=Ha.r,o.g=Ha.g,o.b=Ha.b,o.a=Ha.a,(i.backend.isWebGLBackend===!0||i.alpha===!0)&&(o.r*=o.a,o.g*=o.a,o.b*=o.a),r.depthClearValue=i.getClearDepth(),r.stencilClearValue=i.getClearStencil(),r.clearColor=i.autoClearColor===!0,r.clearDepth=i.autoClearDepth===!0,r.clearStencil=i.autoClearStencil===!0}else r.clearColor=!1,r.clearDepth=!1,r.clearStencil=!1}},Oj=0,jS=class{constructor(e="",t=[]){this.name=e,this.bindings=t,this.id=Oj++}},Uj=class{constructor(e,t,r,i,s,a,n,o,l,u,h=[]){this.vertexShader=e,this.fragmentShader=t,this.computeShader=r,this.transforms=h,this.nodeAttributes=i,this.bindings=s,this.updateNodes=a,this.updateBeforeNodes=n,this.updateAfterNodes=o,this.observer=l,this.hardwareClipping=u,this.usedTimes=0}createBindings(){let e=[];for(let t of this.bindings)if(t.bindings[0].groupNode.shared!==!0){let r=new jS(t.name,[]);e.push(r);for(let i of t.bindings)r.bindings.push(i.clone())}else e.push(t);return e}},y3=class{constructor(e,t,r=null){this.isNodeAttribute=!0,this.name=e,this.type=t,this.node=r}},zj=class{constructor(e,t,r){this.isNodeUniform=!0,this.name=e,this.type=t,this.node=r}get value(){return this.node.value}set value(e){this.node.value=e}get id(){return this.node.id}get groupNode(){return this.node.groupNode}},x3=class{constructor(e,t,r=!1,i=null){this.isNodeVar=!0,this.name=e,this.type=t,this.readOnly=r,this.count=i}},Vj=class extends x3{constructor(e,t,r=null,i=null){super(e,t),this.needsInterpolation=!1,this.isNodeVarying=!0,this.interpolationType=r,this.interpolationSampling=i}},Gj=class{constructor(e,t,r=""){this.name=e,this.type=t,this.code=r,Object.defineProperty(this,"isNodeCode",{value:!0})}},Wj=0,HS=class{constructor(e=null){this.id=Wj++,this.nodesData=new WeakMap,this.parent=e}getData(e){let t=this.nodesData.get(e);return t===void 0&&this.parent!==null&&(t=this.parent.getData(e)),t}setData(e,t){this.nodesData.set(e,t)}},jj=class{constructor(e,t){this.name=e,this.members=t,this.output=!1}},El=class{constructor(e,t){this.name=e,this.value=t,this.boundary=0,this.itemSize=0,this.offset=0,this.index=-1}setValue(e){this.value=e}getValue(){return this.value}},Hj=class extends El{constructor(e,t=0){super(e,t),this.isNumberUniform=!0,this.boundary=4,this.itemSize=1}},Xj=class extends El{constructor(e,t=new fe){super(e,t),this.isVector2Uniform=!0,this.boundary=8,this.itemSize=2}},$j=class extends El{constructor(e,t=new F){super(e,t),this.isVector3Uniform=!0,this.boundary=16,this.itemSize=3}},qj=class extends El{constructor(e,t=new Wt){super(e,t),this.isVector4Uniform=!0,this.boundary=16,this.itemSize=4}},Yj=class extends El{constructor(e,t=new gt){super(e,t),this.isColorUniform=!0,this.boundary=16,this.itemSize=3}},Zj=class extends El{constructor(e,t=new kN){super(e,t),this.isMatrix2Uniform=!0,this.boundary=8,this.itemSize=4}},Jj=class extends El{constructor(e,t=new Dr){super(e,t),this.isMatrix3Uniform=!0,this.boundary=48,this.itemSize=12}},Qj=class extends El{constructor(e,t=new We){super(e,t),this.isMatrix4Uniform=!0,this.boundary=64,this.itemSize=16}},Kj=class extends Hj{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}},eH=class extends Xj{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}},tH=class extends $j{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}},rH=class extends qj{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}},iH=class extends Yj{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}},sH=class extends Zj{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}},aH=class extends Jj{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}},nH=class extends Qj{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}},oH=0,v3=new WeakMap,b3=new WeakMap,lH=new WeakMap,uH=new Map([[Int8Array,"int"],[Int16Array,"int"],[Int32Array,"int"],[Uint8Array,"uint"],[Uint16Array,"uint"],[Uint32Array,"uint"],[Float32Array,"float"]]),Sy=e=>/e/g.test(e)?String(e).replace(/\+/g,""):(e=Number(e),e+(e%1?"":".0")),T3=e=>{if(e.writeUsageCount>0)return!0;if(e.subBuildsCache!==void 0){for(let t in e.subBuildsCache)if(T3(e.subBuildsCache[t]))return!0}return!1},S3=class{constructor(e,t,r){this.object=e,this.material=e&&e.material||null,this.geometry=e&&e.geometry||null,this.renderer=t,this.parser=r,this.scene=null,this.camera=null,this.nodes=new Set,this.sequentialNodes=new Set,this.updateNodes=[],this.updateBeforeNodes=[],this.updateAfterNodes=[],this.hashNodes={},this.observer=null,this.lightsNode=null,this.environmentNode=null,this.fogNode=null,this.clippingContext=null,this.hardwareClipping=!1,this.vertexShader=null,this.fragmentShader=null,this.computeShader=null,this.flowNodes={vertex:[],fragment:[],compute:[]},this.flowCode={vertex:"",fragment:"",compute:""},this.uniforms={vertex:[],fragment:[],compute:[],index:0},this.structs={vertex:[],fragment:[],compute:[],index:0},this.types={vertex:[],fragment:[],compute:[],index:0},this.bindings={vertex:{},fragment:{},compute:{}},this.bindingsIndexes={},this.bindGroups=null,this.attributes=[],this.bufferAttributes=[],this.varyings=[],this.codes={},this.vars={},this.declarations={},this.flow={code:""},this.chaining=[],this.stack=iy(),this.stacks=[],this.tab=" ",this.currentFunctionNode=null,this.context={material:this.material},this.cache=new HS,this.globalCache=this.cache,this.flowsData=new WeakMap,this.shaderStage=null,this.buildStage=null,this.subBuildLayers=[],this.activeStacks=[],this.subBuildFn=null,this.fnCall=null,Object.defineProperty(this,"id",{value:oH++})}isFlatShading(){return this.material.flatShading===!0||this.geometry.hasAttribute("normal")===!1}isOpaque(){let e=this.material;return e.transparent===!1&&e.blending===oa&&e.alphaToCoverage===!1}createRenderTarget(e,t,r){return new er(e,t,r)}createCubeRenderTarget(e,t){return new pE(e,t)}includes(e){return this.nodes.has(e)}getOutputType(e=0){let t="vec4",r=this.renderer.getRenderTarget();if(r!==null){let i=r.textures[e].type,s=r.textures[e].format,a="vec";i===ci?a="ivec":i===gr&&(a="uvec"),s===io||s===jh?i===ci?t="int":i===gr?t="uint":t="float":s===ha||s===Hh?t=`${a}2`:s===Wh||s===lv?t=`${a}3`:t=`${a}4`}return t}getOutputStructName(){}_getBindGroup(e,t){let r=t[0].groupNode,i=r.shared;if(i)for(let a=1;ah.nodeUniform.node.id-d.nodeUniform.node.id);for(let h of u.uniforms)a+=h.nodeUniform.node.id}else a+=u.nodeUniform.id;let n=this.renderer._currentRenderContext||this.renderer,o=v3.get(n);o===void 0&&(o=new Map,v3.set(n,o));let l=yd(a);s=o.get(l),s===void 0&&(s=new jS(e,t),o.set(l,s))}else s=new jS(e,t);return s}getBindGroupArray(e,t){let r=this.bindings[t],i=r[e];return i===void 0&&(this.bindingsIndexes[e]===void 0&&(this.bindingsIndexes[e]={binding:0,group:Object.keys(this.bindingsIndexes).length}),r[e]=i=[]),i}getBindings(){let e=this.bindGroups;if(e===null){let t={},r=this.bindings;for(let i of Jg)for(let s in r[i]){let a=r[i][s],n=t[s]||(t[s]=[]);for(let o of a)n.includes(o)===!1&&n.push(o)}e=[];for(let i in t){let s=t[i],a=this._getBindGroup(i,s);e.push(a)}this.bindGroups=e}return e}sortBindingGroups(){let e=this.getBindings();e.sort((t,r)=>t.bindings[0].groupNode.order-r.bindings[0].groupNode.order);for(let t=0;t=0?`${Math.round(t)}u`:"0u";if(e==="bool")return t?"true":"false";if(e==="color")return`${this.getType("vec3")}( ${Sy(t.r)}, ${Sy(t.g)}, ${Sy(t.b)} )`;let r=this.getTypeLength(e),i=this.getComponentType(e),s=a=>this.generateConst(i,a);if(r===2)return`${this.getType(e)}( ${s(t.x)}, ${s(t.y)} )`;if(r===3)return`${this.getType(e)}( ${s(t.x)}, ${s(t.y)}, ${s(t.z)} )`;if(r===4&&e!=="mat2")return`${this.getType(e)}( ${s(t.x)}, ${s(t.y)}, ${s(t.z)}, ${s(t.w)} )`;if(r>=4&&t&&(t.isMatrix2||t.isMatrix3||t.isMatrix4))return`${this.getType(e)}( ${t.elements.map(s).join(", ")} )`;if(r>4)return`${this.getType(e)}()`;throw new Error(`THREE.NodeBuilder: Type '${e}' not found in generate constant attempt.`)}getType(e){return e==="color"?"vec3":e}hasGeometryAttribute(e){return this.geometry&&this.geometry.getAttribute(e)!==void 0}getAttribute(e,t){let r=this.attributes;for(let s of r)if(s.name===e)return s;let i=new y3(e,t);return this.registerDeclaration(i),r.push(i),i}getPropertyName(e){return e.name}isVector(e){return/vec\d/.test(e)}isMatrix(e){return/mat\d/.test(e)}isReference(e){return e==="void"||e==="property"||e==="sampler"||e==="samplerComparison"||e==="texture"||e==="cubeTexture"||e==="storageTexture"||e==="depthTexture"||e==="texture3D"}needsToWorkingColorSpace(){return!1}getComponentTypeFromTexture(e){let t=e.type;return e.isDepthTexture===!0?"float":t===ci?"int":t===gr?"uint":"float"}getElementType(e){return e==="mat2"?"vec2":e==="mat3"?"vec3":e==="mat4"?"vec4":this.getComponentType(e)}getComponentType(e){if(e=this.getVectorType(e),e==="float"||e==="bool"||e==="int"||e==="uint")return e;let t=/(b|i|u|)(vec|mat)([2-4])/.exec(e);return t===null?null:t[1]==="b"?"bool":t[1]==="i"?"int":t[1]==="u"?"uint":"float"}getVectorType(e){return e==="color"?"vec3":e==="texture"||e==="cubeTexture"||e==="storageTexture"||e==="texture3D"?"vec4":e}getTypeFromLength(e,t="float"){if(e===1)return t;let r=WN(e),i=t==="float"?"":t[0];return/mat2/.test(t)===!0&&(r=r.replace("vec","mat")),i+r}getTypeFromArray(e){return uH.get(e.constructor)}isInteger(e){return/int|uint|(i|u)vec/.test(e)}getTypeFromAttribute(e){let t=e;e.isInterleavedBufferAttribute&&(t=e.data);let r=t.array,i=e.itemSize,s=e.normalized,a;return!(e instanceof sN)&&s!==!0&&(a=this.getTypeFromArray(r)),this.getTypeFromLength(i,a)}getTypeLength(e){let t=this.getVectorType(e),r=/vec([2-4])/.exec(t);return r!==null?Number(r[1]):t==="float"||t==="bool"||t==="int"||t==="uint"?1:/mat2/.test(e)===!0?4:/mat3/.test(e)===!0?9:/mat4/.test(e)===!0?16:0}getVectorFromMatrix(e){return e.replace("mat","vec")}changeComponentType(e,t){return this.getTypeFromLength(this.getTypeLength(e),t)}getIntegerType(e){let t=this.getComponentType(e);return t==="int"||t==="uint"?e:this.changeComponentType(e,"int")}setActiveStack(e){this.activeStacks.push(e)}removeActiveStack(e){if(this.activeStacks[this.activeStacks.length-1]===e)this.activeStacks.pop();else throw new Error("THREE.NodeBuilder: Invalid active stack removal.")}getActiveStack(){return this.activeStacks[this.activeStacks.length-1]}getBaseStack(){return this.activeStacks[0]}addStack(){this.stack=iy(this.stack);let e=xb();return this.stacks.push(e),Np(this.stack),this.stack}removeStack(){let e=this.stack;for(let t of e.nodes){let r=this.getDataFromNode(t);r.stack=e}return this.stack=e.parent,Np(this.stacks.pop()),e}getDataFromNode(e,t=this.shaderStage,r=null){r=r===null?e.isGlobal(this)?this.globalCache:this.cache:r;let i=r.getData(e);i===void 0&&(i={},r.setData(e,i)),i[t]===void 0&&(i[t]={});let s=i[t];if(this.subBuildLayers.length===0)return s;let a=i.any?i.any.subBuilds:null,n=this.getClosestSubBuild(a);return n&&(s.subBuildsCache===void 0&&(s.subBuildsCache={}),s=s.subBuildsCache[n]||(s.subBuildsCache[n]={}),s.subBuilds=a),s}getNodeProperties(e,t="any"){let r=this.getDataFromNode(e,t);return r.properties||(r.properties={outputNode:null})}getBufferAttributeFromNode(e,t,r=null){let i=this.getDataFromNode(e,"vertex"),s=i.bufferAttribute;if(s===void 0){let a=this.uniforms.index++;r===null&&(r="nodeAttribute"+a),s=new y3(r,t,e),this.bufferAttributes.push(s),i.bufferAttribute=s}return s}getStructTypeNode(e,t=this.shaderStage){return this.types[t][e]||null}getStructTypeFromNode(e,t,r=null,i=this.shaderStage){let s=this.getDataFromNode(e,i,this.globalCache),a=s.structType;if(a===void 0){let n=this.structs.index++;r===null&&(r="StructType"+n),a=new jj(r,t),this.structs[i].push(a),this.types[i][r]=e,s.structType=a}return a}getOutputStructTypeFromNode(e,t){let r=this.getStructTypeFromNode(e,t,"OutputType","fragment");return r.output=!0,r}getUniformFromNode(e,t,r=this.shaderStage,i=null){let s=this.getDataFromNode(e,r,this.globalCache),a=s.uniform;if(a===void 0){let n=this.uniforms.index++;a=new zj(i||"nodeUniform"+n,t,e),this.uniforms[r].push(a),this.registerDeclaration(a),s.uniform=a}return a}getVarFromNode(e,t=null,r=e.getNodeType(this),i=this.shaderStage,s=!1){let a=this.getDataFromNode(e,i),n=this.getSubBuildProperty("variable",a.subBuilds),o=a[n];if(o===void 0){let l=s?"_const":"_var",u=this.vars[i]||(this.vars[i]=[]),h=this.vars[l]||(this.vars[l]=0);t===null&&(t=(s?"nodeConst":"nodeVar")+h,this.vars[l]++),n!=="variable"&&(t=this.getSubBuildProperty(t,a.subBuilds));let d=e.getArrayCount(this);o=new x3(t,r,s,d),s||u.push(o),this.registerDeclaration(o),a[n]=o}return o}isDeterministic(e){if(e.isMathNode)return this.isDeterministic(e.aNode)&&(e.bNode?this.isDeterministic(e.bNode):!0)&&(e.cNode?this.isDeterministic(e.cNode):!0);if(e.isOperatorNode)return this.isDeterministic(e.aNode)&&(e.bNode?this.isDeterministic(e.bNode):!0);if(e.isArrayNode){if(e.values!==null){for(let t of e.values)if(!this.isDeterministic(t))return!1}return!0}else if(e.isConstNode)return!0;return!1}getVaryingFromNode(e,t=null,r=e.getNodeType(this),i=null,s=null){let a=this.getDataFromNode(e,"any"),n=this.getSubBuildProperty("varying",a.subBuilds),o=a[n];if(o===void 0){let l=this.varyings,u=l.length;t===null&&(t="nodeVarying"+u),n!=="varying"&&(t=this.getSubBuildProperty(t,a.subBuilds)),o=new Vj(t,r,i,s),l.push(o),this.registerDeclaration(o),a[n]=o}return o}registerDeclaration(e){let t=this.shaderStage,r=this.declarations[t]||(this.declarations[t]={}),i=e.name,s=i,a=this.getPropertyName(e),n=1;for(;r[a]!==void 0;)s=i+"_"+n++,e.name=s,a=this.getPropertyName(e);s!==i&&Ue(`TSL: Declaration name '${i}' of '${e.type}' already in use. Renamed to '${s}'.`),r[a]=e}getCodeFromNode(e,t,r=this.shaderStage){let i=this.getDataFromNode(e),s=i.code;if(s===void 0){let a=this.codes[r]||(this.codes[r]=[]),n=a.length;s=new Gj("nodeCode"+n,t),a.push(s),i.code=s}return s}addFlowCodeHierarchy(e,t){let{flowCodes:r,flowCodeBlock:i}=this.getDataFromNode(e),s=!0,a=t;for(;a;){if(i.get(a)===!0){s=!1;break}a=this.getDataFromNode(a).parentNodeBlock}if(s)for(let n of r)this.addLineFlowCode(n)}addLineFlowCodeBlock(e,t,r){let i=this.getDataFromNode(e),s=i.flowCodes||(i.flowCodes=[]),a=i.flowCodeBlock||(i.flowCodeBlock=new WeakMap);s.push(t),a.set(r,!0)}addLineFlowCode(e,t=null){return e===""?this:(t!==null&&this.context.nodeBlock&&this.addLineFlowCodeBlock(t,e,this.context.nodeBlock),e=this.tab+e,/;\s*$/.test(e)||(e=e+`; `),this.flow.code+=e,this)}addFlowCode(e){return this.flow.code+=e,this}addFlowTab(){return this.tab+=" ",this}removeFlowTab(){return this.tab=this.tab.slice(0,-1),this}getFlowData(e){return this.flowsData.get(e)}flowNode(e){let t=e.getNodeType(this),r=this.flowChildNode(e,t);return this.flowsData.set(e,r),r}addInclude(e){this.currentFunctionNode!==null&&this.currentFunctionNode.includes.push(e)}buildFunctionNode(e){let t=this.renderer.backend,r=b3.get(t);r===void 0&&(r=new WeakMap,b3.set(t,r));let i=r.get(e);if(i===void 0){i=new AS;let s=this.currentFunctionNode;this.currentFunctionNode=i,i.code=this.buildFunctionCode(e),this.currentFunctionNode=s,r.set(e,i)}return i}flowShaderNode(e){let t=e.layout,r={[Symbol.iterator](){let a=0,n=Object.values(this);return{next:()=>({value:n[a],done:a++>=n.length})}}};for(let a of t.inputs)r[a.name]=new dP(a.type,a.name);e.layout=null;let i=e.call(r),s=this.flowStagesNode(i,t.type);return e.layout=t,s}flowBuildStage(e,t,r=null){let i=this.getBuildStage();this.setBuildStage(t);let s=e.build(this,r);return this.setBuildStage(i),s}flowStagesNode(e,t=null){let r=this.flow,i=this.vars,s=this.declarations,a=this.cache,n=this.buildStage,o=this.stack,l={code:""};this.flow=l,this.vars={},this.declarations={},this.cache=new HS,this.stack=iy();for(let u of Zg)this.setBuildStage(u),l.result=e.build(this,t);return l.vars=this.getVars(this.shaderStage),this.flow=r,this.vars=i,this.declarations=s,this.cache=a,this.stack=o,this.setBuildStage(n),l}getFunctionOperator(){return null}buildFunctionCode(){Ue("Abstract function.")}flowChildNode(e,t=null){let r=this.flow,i={code:""};return this.flow=i,i.result=e.build(this,t),this.flow=r,i}flowNodeFromShaderStage(e,t,r=null,i=null){let s=this.tab,a=this.cache,n=this.shaderStage,o=this.context;this.setShaderStage(e);let l={...this.context};delete l.nodeBlock,this.cache=this.globalCache,this.tab=" ",this.context=l;let u=null;if(this.buildStage==="generate"){let h=this.flowChildNode(t,r);i!==null&&(h.code+=`${this.tab+i} = ${h.result}; `),this.flowCode[e]=this.flowCode[e]+h.code,u=h}else u=t.build(this);return this.setShaderStage(n),this.cache=a,this.tab=s,this.context=o,u}getAttributesArray(){return this.attributes.concat(this.bufferAttributes)}getAttributes(){Ue("Abstract function.")}getVaryings(){Ue("Abstract function.")}getVar(e,t,r=null){return`${r!==null?this.generateArrayDeclaration(e,r):this.getType(e)} ${t}`}getVars(e,t=!1){let r=[],i=this.vars[e];if(i!==void 0)for(let s of i)r.push(`${this.getVar(s.type,s.name,s.count)};`);return r.join(t?` `:` `)}getUniforms(){Ue("Abstract function.")}getCodes(e){let t=this.codes[e],r="";if(t!==void 0)for(let i of t)r+=i.code+` `;return r}getHash(){return this.vertexShader+this.fragmentShader+this.computeShader}setShaderStage(e){this.shaderStage=e}getShaderStage(){return this.shaderStage}setBuildStage(e){this.buildStage=e}getBuildStage(){return this.buildStage}buildCode(){Ue("Abstract function.")}get subBuild(){return this.subBuildLayers[this.subBuildLayers.length-1]||null}addSubBuild(e){this.subBuildLayers.push(e)}removeSubBuild(){return this.subBuildLayers.pop()}getClosestSubBuild(e){let t;if(e&&e.isNode?e.isShaderCallNodeInternal?t=e.shaderNode.subBuilds:e.isStackNode?t=[e.subBuild]:t=this.getDataFromNode(e,"any").subBuilds:e instanceof Set?t=[...e]:t=e,!t)return null;let r=this.subBuildLayers;for(let i=t.length-1;i>=0;i--){let s=t[i];if(r.includes(s))return s}return null}getSubBuildOutput(e){return this.getSubBuildProperty("outputNode",e)}getSubBuildProperty(e="",t=null){let r;t!==null?r=this.getClosestSubBuild(t):r=this.subBuildFn;let i;return r?i=e?r+"_"+e:r:i=e,i}prebuild(){let{object:e,renderer:t,material:r}=this;if(t.contextNode.isContextNode===!0?this.context={...this.context,...t.contextNode.getFlowContextData()}:Ce('NodeBuilder: "renderer.contextNode" must be an instance of `context()`.'),r&&r.contextNode&&(r.contextNode.isContextNode===!0?this.context={...this.context,...r.contextNode.getFlowContextData()}:Ce('NodeBuilder: "material.contextNode" must be an instance of `context()`.')),r!==null){let i=t.library.fromMaterial(r);i===null&&(Ce(`NodeBuilder: Material "${r.type}" is not compatible.`),i=new Pt),i.build(this)}else this.addFlow("compute",e)}build(){this.prebuild();for(let e of Zg){this.setBuildStage(e),this.context.position&&this.context.position.isNode&&this.flowNodeFromShaderStage("vertex",this.context.position);for(let t of Jg){this.setShaderStage(t);let r=this.flowNodes[t];for(let i of r)e==="generate"?this.flowNode(i):i.build(this)}}return this.setBuildStage(null),this.setShaderStage(null),this.buildCode(),this.buildUpdateNodes(),this}async buildAsync(){this.prebuild();for(let e of Zg){this.setBuildStage(e),this.context.position&&this.context.position.isNode&&this.flowNodeFromShaderStage("vertex",this.context.position);for(let t of Jg){this.setShaderStage(t);let r=this.flowNodes[t];for(let i of r)e==="generate"?this.flowNode(i):i.build(this);await VM()}}return this.setBuildStage(null),this.setShaderStage(null),this.buildCode(),this.buildUpdateNodes(),this}getSharedDataFromNode(e){let t=lH.get(e);return t===void 0&&(t={}),t}getNodeUniform(e,t){let r=this.getSharedDataFromNode(e),i=r.cache;if(i===void 0){if(t==="float"||t==="int"||t==="uint")i=new Kj(e);else if(t==="vec2"||t==="ivec2"||t==="uvec2")i=new eH(e);else if(t==="vec3"||t==="ivec3"||t==="uvec3")i=new tH(e);else if(t==="vec4"||t==="ivec4"||t==="uvec4")i=new rH(e);else if(t==="color")i=new iH(e);else if(t==="mat2")i=new sH(e);else if(t==="mat3")i=new aH(e);else if(t==="mat4")i=new nH(e);else throw new Error(`THREE.NodeBuilder: Uniform "${t}" not implemented.`);r.cache=i}return i}format(e,t,r){if(t=this.getVectorType(t),r=this.getVectorType(r),t===r||r===null||this.isReference(r))return e;let i=this.getTypeLength(t),s=this.getTypeLength(r);return i===16&&s===9?`${this.getType(r)}( ${e}[ 0 ].xyz, ${e}[ 1 ].xyz, ${e}[ 2 ].xyz )`:i===9&&s===4?`${this.getType(r)}( ${e}[ 0 ].xy, ${e}[ 1 ].xy )`:i>4||s>4||s===0?e:i===s?`${this.getType(r)}( ${e} )`:i>s?(e=r==="bool"?`all( ${e} )`:`${e}.${"xyz".slice(0,s)}`,this.format(e,this.getTypeFromLength(s,this.getComponentType(t)),r)):s===4&&i>1?`${this.getType(r)}( ${this.format(e,t,"vec3")}, 1.0 )`:i===2?`${this.getType(r)}( ${this.format(e,t,"vec2")}, 0.0 )`:(i===1&&s>1&&t!==this.getComponentType(r)&&(e=`${this.getType(this.getComponentType(r))}( ${e} )`),`${this.getType(r)}( ${e} )`)}getSignature(){return`// Three.js r185 - Node System `}needsPreviousData(){let e=this.renderer.getMRT();return e&&e.has("velocity")||HN(this.object).useVelocity===!0}},_3=class{constructor(){this.time=0,this.deltaTime=0,this.frameId=0,this.renderId=0,this.updateMap=new WeakMap,this.updateBeforeMap=new WeakMap,this.updateAfterMap=new WeakMap,this.renderer=null,this.material=null,this.camera=null,this.object=null,this.scene=null}_getMaps(e,t){let r=e.get(t);return r===void 0&&(r={renderId:0,frameId:0},e.set(t,r)),r}updateBeforeNode(e){let t=e.getUpdateBeforeType(),r=e.updateReference(this);if(t===ut.FRAME){let i=this._getMaps(this.updateBeforeMap,r);if(i.frameId!==this.frameId){let s=i.frameId;i.frameId=this.frameId,e.updateBefore(this)===!1&&(i.frameId=s)}}else if(t===ut.RENDER){let i=this._getMaps(this.updateBeforeMap,r);if(i.renderId!==this.renderId){let s=i.renderId;i.renderId=this.renderId,e.updateBefore(this)===!1&&(i.renderId=s)}}else t===ut.OBJECT&&e.updateBefore(this)}updateAfterNode(e){let t=e.getUpdateAfterType(),r=e.updateReference(this);if(t===ut.FRAME){let i=this._getMaps(this.updateAfterMap,r);i.frameId!==this.frameId&&e.updateAfter(this)!==!1&&(i.frameId=this.frameId)}else if(t===ut.RENDER){let i=this._getMaps(this.updateAfterMap,r);i.renderId!==this.renderId&&e.updateAfter(this)!==!1&&(i.renderId=this.renderId)}else t===ut.OBJECT&&e.updateAfter(this)}updateNode(e){let t=e.getUpdateType(),r=e.updateReference(this);if(t===ut.FRAME){let i=this._getMaps(this.updateMap,r);i.frameId!==this.frameId&&e.update(this)!==!1&&(i.frameId=this.frameId)}else if(t===ut.RENDER){let i=this._getMaps(this.updateMap,r);i.renderId!==this.renderId&&e.update(this)!==!1&&(i.renderId=this.renderId)}else t===ut.OBJECT&&e.update(this)}update(){this.frameId++,this.lastTime===void 0&&(this.lastTime=performance.now()),this.deltaTime=(performance.now()-this.lastTime)/1e3,this.lastTime=performance.now(),this.time+=this.deltaTime}},XS=class{constructor(e,t,r=null,i="",s=!1){this.type=e,this.name=t,this.count=r,this.qualifier=i,this.isConst=s}};XS.isNodeFunctionInput=!0;var hH=class extends qu{static get type(){return"AmbientLightNode"}constructor(e=null){super(e)}setup({context:e}){e.irradiance.addAssign(this.colorNode)}},dH=class extends qu{static get type(){return"DirectionalLightNode"}constructor(e=null){super(e)}setupDirect(){let e=this.colorNode;return{lightDirection:IS(this.light),lightColor:e}}},cH=class extends qu{static get type(){return"HemisphereLightNode"}constructor(e=null){super(e),this.lightPositionNode=PS(e),this.lightDirectionNode=this.lightPositionNode.normalize(),this.groundColorNode=Qe(new gt).setGroup(st)}update(e){let{light:t}=this;super.update(e),this.lightPositionNode.object3d=t,this.groundColorNode.value.copy(t.groundColor).multiplyScalar(t.intensity)}setup(e){let{colorNode:t,groundColorNode:r,lightDirectionNode:i}=this,s=vl.dot(i).mul(.5).add(.5),a=Ct(r,t,s);e.context.irradiance.addAssign(a)}},$S=class extends qu{static get type(){return"SpotLightNode"}constructor(e=null){super(e),this.coneCosNode=Qe(0).setGroup(st),this.penumbraCosNode=Qe(0).setGroup(st),this.cutoffDistanceNode=Qe(0).setGroup(st),this.decayExponentNode=Qe(0).setGroup(st),this.colorNode=Qe(this.color).setGroup(st)}update(e){super.update(e);let{light:t}=this;this.coneCosNode.value=Math.cos(t.angle),this.penumbraCosNode.value=Math.cos(t.angle*(1-t.penumbra)),this.cutoffDistanceNode.value=t.distance,this.decayExponentNode.value=t.decay}getSpotAttenuation(e,t){let{coneCosNode:r,penumbraCosNode:i}=this;return Hs(r,i,t)}getLightCoord(e){let t=e.getNodeProperties(this),r=t.projectionUV;return r===void 0&&(r=UP(this.light,e.context.positionWorld),t.projectionUV=r),r}setupDirect(e){let{colorNode:t,cutoffDistanceNode:r,decayExponentNode:i,light:s}=this,a=this.getLightVector(e),n=a.normalize(),o=n.dot(IS(s)),l=this.getSpotAttenuation(e,o),u=a.length(),h=VS({lightDistance:u,cutoffDistance:r,decayExponent:i}),d=t.mul(l).mul(h),c,m;return s.colorNode?(m=this.getLightCoord(e),c=s.colorNode(m)):s.map&&(m=this.getLightCoord(e),c=Ot(s.map,m.xy).onRenderUpdate(()=>s.map)),c&&(d=m.mul(2).sub(1).abs().lessThan(1).all().select(d.mul(c),d)),{lightColor:d,lightDirection:n}}},pH=class extends $S{static get type(){return"IESSpotLightNode"}constructor(e=null){super(e),this._iesTextureNode=null}getSpotAttenuation(e,t){let r=this.light.iesMap,i=null;if(r&&r.isTexture===!0){let s=t.acos().mul(1/Math.PI);this._iesTextureNode=Ot(r,ke(s,0),0),i=this._iesTextureNode.r}else i=super.getSpotAttenuation(e,t);return i}update(e){super.update(e),this._iesTextureNode!==null&&this.light.iesMap&&(this._iesTextureNode.value=this.light.iesMap)}},mH=class extends qu{static get type(){return"LightProbeNode"}constructor(e=null){super(e);let t=[];for(let r=0;r<9;r++)t.push(new F);this.lightProbe=Li(t)}update(e){let{light:t}=this;super.update(e);for(let r=0;r<9;r++)this.lightProbe.array[r].copy(t.sh.coefficients[r]).multiplyScalar(t.intensity)}setup(e){let t=g3(vl,this.lightProbe);e.context.irradiance.addAssign(t)}},fH=Q(([e,t])=>{let r=e.abs().sub(t);return Nn(Br(r,0)).add(Rs(Br(r.x,r.y),0))}),gH=class extends $S{static get type(){return"ProjectorLightNode"}update(e){super.update(e);let t=this.light;if(this.penumbraCosNode.value=Math.min(Math.cos(t.angle*(1-t.penumbra)),.99999),t.aspect===null){let r=1;t.map!==null&&(r=t.map.width/t.map.height),t.shadow.aspect=r}else t.shadow.aspect=t.aspect}getSpotAttenuation(e){let t=D(0),r=this.penumbraCosNode,i=fy(this.light).mul(e.context.positionWorld||Rn);return et(i.w.greaterThan(0),()=>{let s=i.xyz.div(i.w),a=fH(s.xy.sub(ke(.5)),ke(.5)),n=js(-1,It(1,Ib(r)).sub(1));t.assign(y0(a.mul(-2).mul(n)))}),t}},qS=new We,_y=new We,em=null,yH=class extends qu{static get type(){return"RectAreaLightNode"}constructor(e=null){super(e),this.halfHeight=Qe(new F).setGroup(st),this.halfWidth=Qe(new F).setGroup(st),this.updateType=ut.RENDER}update(e){super.update(e);let{light:t}=this,r=e.camera.matrixWorldInverse;_y.identity(),qS.copy(t.matrixWorld),qS.premultiply(r),_y.extractRotation(qS),this.halfWidth.value.set(t.width*.5,0,0),this.halfHeight.value.set(0,t.height*.5,0),this.halfWidth.value.applyMatrix4(_y),this.halfHeight.value.applyMatrix4(_y)}setupDirectRectArea(e){let t,r;e.isAvailable("float32Filterable")?(t=Ot(em.LTC_FLOAT_1),r=Ot(em.LTC_FLOAT_2)):(t=Ot(em.LTC_HALF_1),r=Ot(em.LTC_HALF_2));let{colorNode:i,light:s}=this,a=BS(s);return{lightColor:i,lightPosition:a,halfWidth:this.halfWidth,halfHeight:this.halfHeight,ltc_1:t,ltc_2:r}}static setLTC(e){em=e}},w3=class{parseFunction(){Ue("Abstract function.")}},YS=class{constructor(e,t,r="",i=""){this.type=e,this.inputs=t,this.name=r,this.precision=i}getCode(){Ue("Abstract function.")}};YS.isNodeFunction=!0;var xH=/^\s*(highp|mediump|lowp)?\s*([a-z_0-9]+)\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)/i,vH=/[a-z_0-9]+/gi,M3="#pragma main",bH=e=>{e=e.trim();let t=e.indexOf(M3),r=t!==-1?e.slice(t+M3.length):e,i=r.match(xH);if(i!==null&&i.length===5){let s=i[4],a=[],n=null;for(;(n=vH.exec(s))!==null;)a.push(n);let o=[],l=0;for(;l{let o=this._createNodeBuilder(e,e.material);try{t?await o.buildAsync():o.build()}catch(l){o=this._createNodeBuilder(e,new Pt),t?await o.buildAsync():o.build(),Ce("TSL: "+l)}return o};if(t)return n().then(o=>(i=this._createNodeBuilderState(o),s.set(a,i),i.usedTimes++,r.nodeBuilderState=i,i));{let o=this._createNodeBuilder(e,e.material);try{o.build()}catch(l){o=this._createNodeBuilder(e,new Pt),o.build();let u=l.stackTrace;!u&&l.stack&&(u=new $r(l.stack)),Ce("TSL: "+l,u)}i=this._createNodeBuilderState(o),s.set(a,i)}}i.usedTimes++,r.nodeBuilderState=i}return i}getForRenderAsync(e){let t=this.getForRender(e,!0);return t.then?t:Promise.resolve(t)}getForRenderDeferred(e){let t=this.get(e);if(t.nodeBuilderState!==void 0)return t.nodeBuilderState;let r=this.getForRenderCacheKey(e),i=this.nodeBuilderCache.get(r);return i!==void 0?(i.usedTimes++,t.nodeBuilderState=i,i):(t.pendingBuild!==!0&&(t.pendingBuild=!0,this._buildQueue.push(()=>this.getForRenderAsync(e).then(()=>{t.pendingBuild=!1})),this._processBuildQueue()),null)}_processBuildQueue(){this._buildInProgress||this._buildQueue.length===0||(this._buildInProgress=!0,this._buildQueue.shift()().then(()=>{this._buildInProgress=!1,this._processBuildQueue()}))}delete(e){if(e.isRenderObject){let t=this.get(e).nodeBuilderState;t!==void 0&&(t.usedTimes--,t.usedTimes===0&&this.nodeBuilderCache.delete(this.getForRenderCacheKey(e)))}return super.delete(e)}getForCompute(e){let t=this.get(e),r=t.nodeBuilderState;if(r===void 0||t.version!==e.version){let i=this.backend.createNodeBuilder(e,this.renderer);i.build(),r=this._createNodeBuilderState(i),t.nodeBuilderState=r,t.version=e.version}return r}_createNodeBuilderState(e){return new Uj(e.vertexShader,e.fragmentShader,e.computeShader,e.getAttributesArray(),e.getBindings(),e.updateNodes,e.updateBeforeNodes,e.updateAfterNodes,e.observer,e.hardwareClipping,e.transforms)}getEnvironmentNode(e){if(this.renderer.lighting.enabled===!1)return null;this.updateEnvironment(e);let t=null;if(e.environmentNode&&e.environmentNode.isNode)t=e.environmentNode;else{let r=this.get(e);r.environmentNode&&(t=r.environmentNode)}return t}getBackgroundNode(e){this.updateBackground(e);let t=null;if(e.backgroundNode&&e.backgroundNode.isNode)t=e.backgroundNode;else{let r=this.get(e);r.backgroundNode&&(t=r.backgroundNode)}return t}getFogNode(e){return this.updateFog(e),e.fogNode||this.get(e).fogNode||null}getCacheKey(e,t){ba[0]=e,ba[1]=t;let r=this.renderer.info.calls,i=this.callHashCache.get(ba)||{};if(i.callId!==r){if(Mo.push(this.renderer.getOutputRenderTarget()&&this.renderer.getOutputRenderTarget().multiview?1:0),Mo.push(this.renderer.lighting.enabled?1:0),this.renderer.lighting.enabled){Mo.push(t.getCacheKey(!0)),Mo.push(this.renderer.shadowMap.enabled?1:0),Mo.push(this.renderer.shadowMap.type);let a=this.getEnvironmentNode(e);a&&Mo.push(a.getCacheKey())}let s=this.getFogNode(e);s&&Mo.push(s.getCacheKey()),i.callId=r,i.cacheKey=Sp(Mo),this.callHashCache.set(ba,i),Mo.length=0}return ba[0]=null,ba[1]=null,i.cacheKey}get isToneMappingState(){return!this.renderer.getRenderTarget()}updateBackground(e){let t=this.get(e),r=e.background;if(r){let i=e.backgroundBlurriness===0&&t.backgroundBlurriness>0||e.backgroundBlurriness>0&&t.backgroundBlurriness===0;if(t.background!==r||i){let s=this.getCacheNode("background",r,()=>{if(r.isCubeTexture===!0||r.mapping===kf||r.mapping===iv||r.mapping===Df){if(e.backgroundBlurriness>0||r.mapping===Df)return cS(r);{let a;return r.isCubeTexture===!0?a=Ts(r):a=Ot(r),gE(a)}}else{if(r.isTexture===!0)return Ot(r,Ga.flipY()).setUpdateMatrix(!0);r.isColor!==!0&&Ce("WebGPUNodes: Unsupported background configuration.",r)}},i);t.backgroundNode=s,t.background=r,t.backgroundBlurriness=e.backgroundBlurriness}}else t.backgroundNode&&(delete t.backgroundNode,delete t.background)}getCacheNode(e,t,r,i=!1){let s=this.cacheLib[e]||(this.cacheLib[e]=new WeakMap),a=s.get(t);return(a===void 0||i)&&(a=r(),s.set(t,a)),a}updateFog(e){let t=this.get(e),r=e.fog;if(r){if(t.fog!==r){let i=this.getCacheNode("fog",r,()=>{if(r.isFogExp2){let s=cr("color","color",r).setGroup(st),a=cr("density","float",r).setGroup(st);return RS(s,OP(a))}else if(r.isFog){let s=cr("color","color",r).setGroup(st),a=cr("near","float",r).setGroup(st),n=cr("far","float",r).setGroup(st);return RS(s,DP(a,n))}else Ce("Renderer: Unsupported fog configuration.",r)});t.fogNode=i,t.fog=r}}else delete t.fogNode,delete t.fog}updateEnvironment(e){let t=this.get(e),r=e.environment;if(r){if(t.environment!==r){let i=this.getCacheNode("environment",r,()=>{if(r.isCubeTexture===!0)return Ts(r);if(r.isTexture===!0)return Ot(r);Ce("Nodes: Unsupported environment configuration.",r)});t.environmentNode=i,t.environment=r}}else t.environmentNode&&(delete t.environmentNode,delete t.environment)}getNodeFrame(e=this.renderer,t=null,r=null,i=null,s=null){let a=this.nodeFrame;return a.renderer=e,a.scene=t,a.object=r,a.camera=i,a.material=s,a}getNodeFrameForRender(e){return this.getNodeFrame(e.renderer,e.scene,e.object,e.camera,e.material)}getOutputCacheKey(){let e=this.renderer;return e.toneMapping+","+e.currentColorSpace+","+e.xr.isPresenting}getOutputNode(e){let t=this.renderer,r;return e.isArrayTexture?this.backend.isWebGLBackend?r=Ot(e,Ga).depth(bo("gl_ViewID_OVR")).renderOutput(t.toneMapping,t.currentColorSpace):r=Ot(e,Ga).depth(N3).renderOutput(t.toneMapping,t.currentColorSpace):r=Ot(e,Ga).renderOutput(t.toneMapping,t.currentColorSpace),r}setOutputLayerIndex(e){N3.value=e}updateBefore(e){let t=e.getNodeBuilderState();for(let r of t.updateBeforeNodes)this.getNodeFrameForRender(e).updateBeforeNode(r)}updateAfter(e){let t=e.getNodeBuilderState();for(let r of t.updateAfterNodes)this.getNodeFrameForRender(e).updateAfterNode(r)}updateForCompute(e){let t=this.getNodeFrame(),r=this.getForCompute(e);for(let i of r.updateNodes)t.updateNode(i)}updateForRender(e){let t=this.getNodeFrameForRender(e),r=e.getNodeBuilderState();for(let i of r.updateNodes)t.updateNode(i)}needsRefresh(e){let t=this.getNodeFrameForRender(e);return e.getMonitor().needsRefresh(e,t)}dispose(){super.dispose(),this.nodeFrame=new _3,this.nodeBuilderCache=new Map,this.cacheLib={}}},ZS=new fn,A3=class sD{constructor(t=null){this.version=0,this.clipIntersection=null,this.cacheKey="",this.shadowPass=!1,this.viewMatrix=new We,this.viewNormalMatrix=new Dr,this.clippingGroupContexts=new WeakMap,this.intersectionPlanes=[],this.unionPlanes=[],this.parentVersion=null,t!==null&&(this.viewMatrix=t.viewMatrix,this.viewNormalMatrix=t.viewNormalMatrix,this.clippingGroupContexts=t.clippingGroupContexts,this.shadowPass=t.shadowPass)}projectPlanes(t,r,i){let s=t.length;for(let a=0;a0&&(Et("THREE.XRManager: WebGPU XR does not support MSAA yet. Disabling MSAA for this XR session."),this._currentSamples===null&&(this._currentSamples=e.samples),e._samples=0)}}async _initWebGPUSession(e){let t=this.getWebGPUBinding(),r=t.createProjectionLayer({colorFormat:t.getPreferredColorFormat(),depthStencilFormat:"depth24plus"});this._glProjLayer=r,e.updateRenderState({layers:[r]}),this._referenceSpace=await e.requestReferenceSpace(this.getReferenceSpaceType()),this._xrRenderTarget=new er(r.textureWidth,r.textureHeight,{depth:2,minFilter:lr,magFilter:lr,depthBuffer:!0,multiview:!1,useArrayDepthTexture:!0,samples:0}),this._xrRenderTarget.texture.isArrayTexture=!0,this._useMultiviewIfPossible===!0&&Et("THREE.XRManager: WebGPU XR does not support multiview yet. Disabling multiview for this XR session."),this._useMultiview=!1}_disposeWebGPUSession(){let e=this._renderer,t=this._xrRenderTarget;if(t===null||e.backend.isWebGPUBackend!==!0)return;let r=e.backend,i=e._textures,s=r.get?r.get(t):null;s&&(s.descriptors=void 0);let a=n=>{n!=null&&(r.delete&&r.delete(n),i.delete&&i.delete(n))};for(let n=0;n_0(h,r.toneMapping,r.outputColorSpace)}),B3.set(o,l))}else l=o;r.contextNode=l,r.setRenderTarget(n.renderTarget),n.rendercall(),r.contextNode=o}r.setRenderTarget(a),r._setXRLayerSize(s.x,s.y),this.isPresenting=i}getSession(){return this._session}async setSession(e){let t=this._renderer;t.initialized===!1&&await t.init(),this._gl=t.getContext();let r=this._gl;if(this._session=e,e!==null){if(e.addEventListener("select",this._onSessionEvent),e.addEventListener("selectstart",this._onSessionEvent),e.addEventListener("selectend",this._onSessionEvent),e.addEventListener("squeeze",this._onSessionEvent),e.addEventListener("squeezestart",this._onSessionEvent),e.addEventListener("squeezeend",this._onSessionEvent),e.addEventListener("end",this._onSessionEnd),e.addEventListener("inputsourceschange",this._onInputSourcesChange),this._validateWebGPUSession(),this._currentPixelRatio=t.getPixelRatio(),t.getSize(this._currentSize),this._currentAnimationContext=t._animation.getContext(),this._currentAnimationLoop=t._animation.getAnimationLoop(),t._animation.stop(),this._isWebGPUSession())await this._initWebGPUSession(e);else if(this._supportsLayers===!0){let i=null,s=null,a=null,n=r.getContextAttributes();await t.backend.makeXRCompatible(),this.setFoveation(this.getFoveation()),t.depth&&(a=t.stencil?r.DEPTH24_STENCIL8:r.DEPTH_COMPONENT24,i=t.stencil?ln:ua,s=t.stencil?ro:gr);let o={colorFormat:r.RGBA8,depthFormat:a,scaleFactor:this._framebufferScaleFactor,clearOnAccess:!1};this._useMultiviewIfPossible&&t.hasFeature("OVR_multiview2")&&(o.textureType="texture-array",this._useMultiview=!0),this._glBinding=this.getBinding();let l=this._glBinding.createProjectionLayer(o),u=[l];this._glProjLayer=l,t.setPixelRatio(1),t._setXRLayerSize(l.textureWidth,l.textureHeight);let h=this._useMultiview?2:1,d=new fs(l.textureWidth,l.textureHeight,s,void 0,void 0,void 0,void 0,void 0,void 0,i,h);if(this._xrRenderTarget=new tm(l.textureWidth,l.textureHeight,{format:pi,type:Si,colorSpace:t.outputColorSpace,depthTexture:d,stencilBuffer:t.stencil,samples:n.antialias?4:0,resolveDepthBuffer:l.ignoreDepthValues===!1,resolveStencilBuffer:l.ignoreDepthValues===!1,depth:this._useMultiview?2:1,multiview:this._useMultiview}),this._xrRenderTarget._hasExternalTextures=!0,this._xrRenderTarget.depth=this._useMultiview?2:1,this._sessionUsesLayers=e.enabledFeatures.includes("layers"),this._referenceSpace=await e.requestReferenceSpace(this.getReferenceSpaceType()),this._sessionUsesLayers)for(let c of this._layers)c.plane.material=new mn({color:16777215,side:c.type==="cylinder"?ii:Cs}),c.plane.material.blending=Uh,c.plane.material.blendEquation=la,c.plane.material.blendSrc=Jo,c.plane.material.blendDst=Jo,c.xrlayer=this._createXRLayer(c),u.unshift(c.xrlayer);e.updateRenderState({layers:u})}else{await t.backend.makeXRCompatible(),this.setFoveation(this.getFoveation());let i={antialias:t.currentSamples>0,alpha:!0,depth:t.depth,stencil:t.stencil,framebufferScaleFactor:this.getFramebufferScaleFactor()},s=new XRWebGLLayer(e,r,i);this._glBaseLayer=s,e.updateRenderState({baseLayer:s}),t.setPixelRatio(1),t._setXRLayerSize(s.framebufferWidth,s.framebufferHeight),this._xrRenderTarget=new tm(s.framebufferWidth,s.framebufferHeight,{format:pi,type:Si,colorSpace:t.outputColorSpace,stencilBuffer:t.stencil,resolveDepthBuffer:s.ignoreDepthValues===!1,resolveStencilBuffer:s.ignoreDepthValues===!1}),this._xrRenderTarget._isOpaqueFramebuffer=!0,this._referenceSpace=await e.requestReferenceSpace(this.getReferenceSpaceType())}t._animation.setAnimationLoop(this._onAnimationFrame),t._animation.setContext(e),t._animation.start(),this.isPresenting=!0,this.dispatchEvent({type:"sessionstart"})}}updateCamera(e){let t=this._session;if(t===null)return;let r=e.near,i=e.far,s=this._cameraXR,a=this._cameraL,n=this._cameraR;s.near=n.near=a.near=r,s.far=n.far=a.far=i,s.isMultiViewCamera=this._useMultiview,(this._currentDepthNear!==s.near||this._currentDepthFar!==s.far)&&(t.updateRenderState({depthNear:s.near,depthFar:s.far}),this._currentDepthNear=s.near,this._currentDepthFar=s.far),s.layers.mask=e.layers.mask|6,a.layers.mask=s.layers.mask&-5,n.layers.mask=s.layers.mask&-3;let o=e.parent,l=s.cameras;I3(s,o);for(let u=0;u=0&&(r[a]=null,t[a].disconnect(s))}for(let i=0;i=r.length){r.push(s),a=o;break}else if(r[o]===null){r[o]=s,a=o;break}if(a===-1)break}let n=t[a];n&&n.connect(s)}}function FH(e){return e.type==="quad"?this._glBinding.createQuadLayer({transform:new XRRigidTransform(e.translation,e.quaternion),width:e.width/2,height:e.height/2,space:this._referenceSpace,viewPixelWidth:e.pixelwidth,viewPixelHeight:e.pixelheight,clearOnAccess:!1}):this._glBinding.createCylinderLayer({transform:new XRRigidTransform(e.translation,e.quaternion),radius:e.radius,centralAngle:e.centralAngle,aspectRatio:e.aspectRatio,space:this._referenceSpace,viewPixelWidth:e.pixelwidth,viewPixelHeight:e.pixelheight,clearOnAccess:!1})}function LH(e,t){if(t===void 0)return;let r=this._cameraXR,i=this._renderer,s=i.backend,a=this._glBaseLayer,n=this.getReferenceSpace(),o=t.getViewerPose(n);if(this._xrFrame=t,o!==null){let l=o.views,u=this._isWebGPUSession()?this._getWebGPUViewData(l):null;this._glBaseLayer!==null&&u===null&&s.setXRTarget(a.framebuffer);let h=!1;l.length!==r.cameras.length&&(r.cameras.length=0,h=!0);for(let c=0;c{await this.compileAsync(y,g,m);let b=this.needsFrameBufferTarget&&this._renderTarget===null?this._getFrameBufferTarget():this._renderTarget||this._outputRenderTarget,v=this._renderLists.get(m,g),S=this._renderContexts.get(b,this._mrt),T=m.overrideMaterial||y.material,w=this._objects.get(y,T,m,g,v.lightsNode,S,S.clippingContext),{fragmentShader:N,vertexShader:C}=w.getNodeBuilderState();return{fragmentShader:N,vertexShader:C}}}}async init(){return this._initPromise!==null?this._initPromise:(this._initPromise=new Promise(async(e,t)=>{let r=this.backend;try{await r.init(this)}catch(i){if(this._getFallback!==null)try{this.backend=r=this._getFallback(i),await r.init(this)}catch(s){t(s);return}else{t(i);return}}this._nodes=new _H(this,r),this._animation=new MG(this,this._nodes,this.info),this._attributes=new BG(r,this.info),this._background=new Dj(this,this._nodes),this._geometries=new IG(this._attributes,this.info),this._textures=new qG(this,r,this.info),this._pipelines=new OG(r,this._nodes,this.info),this._bindings=new UG(r,this._nodes,this._textures,this._attributes,this._pipelines,this.info),this._objects=new RG(this,this._nodes,this._geometries,this._pipelines,this._bindings,this.info),this._renderLists=new WG(this.lighting),this._bundles=new MH,this._renderContexts=new XG(this),this._animation.start(),this._initialized=!0,this._inspector.init(),e(this)}),this._initPromise)}get domElement(){return this._canvasTarget.domElement}get coordinateSystem(){return this.backend.coordinateSystem}async compileAsync(e,t,r=null){if(this._isDeviceLost===!0)return;this._initialized===!1&&await this.init();let i=this._nodes.nodeFrame,s=i.renderId,a=this._currentRenderContext,n=this._currentRenderObjectFunction,o=this._handleObjectFunction,l=this._compilationPromises;r===null&&(r=e);let u=e.isScene===!0?e:r.isScene===!0?r:F3,h=this.needsFrameBufferTarget&&this._renderTarget===null?this._getFrameBufferTarget():this._renderTarget||this._outputRenderTarget,d=this._renderContexts.get(h,this._mrt),c=this._activeMipmapLevel,m=[];this._currentRenderContext=d,this._currentRenderObjectFunction=this.renderObject,this._handleObjectFunction=this._createObjectPipeline,this._compilationPromises=m,i.renderId++,i.update(),d.depth=this.depth,d.stencil=this.stencil,d.clippingContext||(d.clippingContext=new A3),d.clippingContext.updateGlobal(u,t),e.matrixWorldAutoUpdate===!0&&e.updateMatrixWorld(),t=this._updateCamera(t),u.onBeforeRender(this,e,t,h);let g=t.isArrayCamera?My:wy;t.isArrayCamera?g.setFromArrayCamera(t):(Vd.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),g.setFromProjectionMatrix(Vd,t.coordinateSystem,t.reversedDepth));let y=this._renderLists.get(u,t);if(y.begin(),this._projectObject(e,t,0,y,d.clippingContext),r!==e&&r.traverseVisible(function(w){w.isLight&&w.layers.test(t.layers)&&y.pushLight(w)}),y.finish(),h!==null){this._textures.updateRenderTarget(h,c);let w=this._textures.get(h);d.textures=w.textures,d.depthTexture=w.depthTexture}else d.textures=null,d.depthTexture=null;r!==e?this._background.update(r,y,d):this._background.update(u,y,d);let b=y.opaque,v=y.transparent,S=y.transparentDoublePass,T=y.lightsNode;this.opaque===!0&&b.length>0&&this._renderObjects(b,t,u,T),this.transparent===!0&&v.length>0&&this._renderTransparents(v,S,t,u,T),i.renderId=s,this._currentRenderContext=a,this._currentRenderObjectFunction=n,this._handleObjectFunction=o,this._compilationPromises=l;for(let w of m){let N=this._objects.get(w.object,w.material,w.scene,w.camera,w.lightsNode,w.renderContext,w.clippingContext,w.passId);N.drawRange=w.object.geometry.drawRange,N.group=w.group,await this._nodes.getForRenderAsync(N),this._nodes.updateBefore(N),this._geometries.updateForRender(N),this._nodes.updateForRender(N),this._bindings.updateForRender(N);let C=[];this._pipelines.getForRender(N,C),C.length>0&&await Promise.all(C),this._nodes.updateAfter(N),await VM()}}async renderAsync(e,t){Et('Renderer: "renderAsync()" has been deprecated. Use "render()" and "await renderer.init();" when creating the renderer.'),await this.init(),this.render(e,t)}async waitForGPU(){Ce("Renderer: waitForGPU() has been removed. Read https://github.com/mrdoob/three.js/issues/32012 for more information.")}set inspector(e){this._inspector!==null&&this._inspector.setRenderer(null),this._inspector=e,this._inspector.setRenderer(this)}get inspector(){return this._inspector}set highPrecision(e){let t=this.contextNode.value;e===!0?(t.modelViewMatrix=mT,t.modelNormalViewMatrix=fT):this.highPrecision&&(delete t.modelViewMatrix,delete t.modelNormalViewMatrix)}get highPrecision(){let e=this.contextNode.value;return e.modelViewMatrix===mT&&e.modelNormalViewMatrix===fT}setMRT(e){return this._mrt=e,this}getMRT(){return this._mrt}getOutputBufferType(){return this._outputBufferType}getColorBufferType(){return Et('Renderer: ".getColorBufferType()" has been renamed to ".getOutputBufferType()".'),this.getOutputBufferType()}_onDeviceLost(e){let t=`THREE.WebGPURenderer: ${e.api} Device Lost: Message: ${e.message}`;e.reason&&(t+=` Reason: ${e.reason}`),Ce(t),this._isDeviceLost=!0}_onError(e){let t=`WebGPURenderer: Uncaptured ${e.api} ${e.type}`;e.message&&(t+=`: ${e.message}`),Ce(t)}_bundleNeedsUpdate(e,t){return t.bundleGPU===void 0||e.version!==t.version}_renderBundle(e,t,r){let{bundleGroup:i,camera:s,renderList:a}=e,n=this._currentRenderContext,o=this._bundles.get(i,s,n),l=this.backend.get(o);if(this._bundleNeedsUpdate(i,l)){this.backend.beginBundle(n),this._currentRenderBundle=o;let{transparentDoublePass:u,transparent:h,opaque:d}=a;this.opaque===!0&&d.length>0&&this._renderObjects(d,s,t,r),this.transparent===!0&&h.length>0&&this._renderTransparents(h,u,s,t,r),this._currentRenderBundle=null,this.backend.finishBundle(n,o),l.version=i.version}else{let{renderObjects:u}=l;for(let h=0,d=u.length;h{l.removeEventListener("dispose",y),u.dispose(),this._frameBufferTargets.delete(l)};l.addEventListener("dispose",y),this._frameBufferTargets.set(l,u)}let h=this.getOutputRenderTarget();u.depthBuffer=n,u.stencilBuffer=o,h!==null?u.setSize(h.width,h.height,h.depth):u.setSize(s,a,1);let d=this._outputRenderTarget?this._outputRenderTarget.viewport:l._viewport,c=this._outputRenderTarget?this._outputRenderTarget.scissor:l._scissor,m=this._outputRenderTarget?1:l._pixelRatio,g=this._outputRenderTarget?this._outputRenderTarget.scissorTest:l._scissorTest;return u.viewport.copy(d),u.scissor.copy(c),u.viewport.multiplyScalar(m),u.scissor.multiplyScalar(m),u.scissorTest=g,u.multiview=h!==null?h.multiview:!1,u.useArrayDepthTexture=h!==null?h.useArrayDepthTexture:!1,u.resolveDepthBuffer=h!==null?h.resolveDepthBuffer:!0,u._autoAllocateDepthBuffer=h!==null?h._autoAllocateDepthBuffer:!1,u}_renderScene(e,t,r=!0){if(this._isDeviceLost===!0)return;let i=r?this._getFrameBufferTarget():null,s=this._nodes.nodeFrame,a=s.renderId,n=this._currentRenderContext,o=this._currentRenderObjectFunction,l=this._handleObjectFunction;this.lighting.beginRender(e),this._callDepth++;let u=e.isScene===!0?e:F3,h=this._renderTarget||this._outputRenderTarget,d=this._activeCubeFace,c=this._activeMipmapLevel,m;if(i!==null?(m=i,this.setRenderTarget(m)):m=h,m!==null&&m.depthBuffer===!0){let L=this._textures.get(m);L.depthInitialized!==!0&&((this.autoClear===!1||this.autoClear===!0&&this.autoClearDepth===!1)&&this.clearDepth(),L.depthInitialized=!0)}let g=this._renderContexts.get(m,this._mrt,this._callDepth);this._currentRenderContext=g,this._currentRenderObjectFunction=this._renderObjectFunction||this.renderObject,this._handleObjectFunction=this._renderObjectDirect,this.info.calls++,this.info.render.calls++,this.info.render.frameCalls++,s.renderId=this.info.calls,this.backend.updateTimeStampUID(g),this.inspector.beginRender(this.backend.getTimestampUID(g),e,t,m),e.matrixWorldAutoUpdate===!0&&e.updateMatrixWorld(),t=this._updateCamera(t);let y=this._canvasTarget,b=y._viewport,v=y._scissor,S=y._pixelRatio;m!==null&&(b=m.viewport,v=m.scissor,S=1),this.getDrawingBufferSize(zd),JS.set(0,0,zd.width,zd.height);let T=b.minDepth===void 0?0:b.minDepth,w=b.maxDepth===void 0?1:b.maxDepth;g.viewportValue.copy(b).multiplyScalar(S).floor(),g.viewportValue.width>>=c,g.viewportValue.height>>=c,g.viewportValue.minDepth=T,g.viewportValue.maxDepth=w,g.viewport=g.viewportValue.equals(JS)===!1,g.scissorValue.copy(v).multiplyScalar(S).floor(),g.scissor=y._scissorTest&&g.scissorValue.equals(JS)===!1,g.scissorValue.width>>=c,g.scissorValue.height>>=c,g.clippingContext||(g.clippingContext=new A3),g.clippingContext.updateGlobal(u,t),u.onBeforeRender(this,e,t,m);let N=t.isArrayCamera?My:wy;t.isArrayCamera?N.setFromArrayCamera(t):(Vd.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),N.setFromProjectionMatrix(Vd,t.coordinateSystem,t.reversedDepth));let C=this._renderLists.get(e,t);if(C.begin(),this._projectObject(e,t,0,C,g.clippingContext),C.finish(),this.sortObjects===!0&&C.sort(this._opaqueSort,this._transparentSort,t.reversedDepth),m!==null){this._textures.updateRenderTarget(m,c);let L=this._textures.get(m);g.textures=L.textures,g.depthTexture=L.depthTexture,g.width=L.width,g.height=L.height,g.renderTarget=m,g.depth=m.depthBuffer,g.stencil=m.stencilBuffer}else g.textures=null,g.depthTexture=null,g.width=zd.width,g.height=zd.height,g.depth=this.depth,g.stencil=this.stencil;g.width>>=c,g.height>>=c,g.activeCubeFace=d,g.activeMipmapLevel=c,g.occlusionQueryCount=C.occlusionQueryCount,g.scissorValue.max(No.set(0,0,0,0)),g.scissorValue.x+g.scissorValue.width>g.width&&(g.scissorValue.width=Math.max(g.width-g.scissorValue.x,0)),g.scissorValue.y+g.scissorValue.height>g.height&&(g.scissorValue.height=Math.max(g.height-g.scissorValue.y,0)),this._background.update(u,C,g),g.camera=t,this.backend.beginRender(g);let{bundles:R,lightsNode:E,transparentDoublePass:P,transparent:I,opaque:O}=C;return R.length>0&&this._renderBundles(R,u,E),this.opaque===!0&&O.length>0&&this._renderObjects(O,t,u,E),this.transparent===!0&&I.length>0&&this._renderTransparents(I,P,t,u,E),this.backend.finishRender(g),s.renderId=a,this._currentRenderContext=n,this._currentRenderObjectFunction=o,this._handleObjectFunction=l,this.lighting.finishRender(e),this._callDepth--,i!==null&&(this.setRenderTarget(h,d,c),this._renderOutput(m)),u.onAfterRender(this,e,t,m),this.inspector.finishRender(this.backend.getTimestampUID(g)),g}_setXRLayerSize(e,t){this._canvasTarget._width=e,this._canvasTarget._height=t,this.setViewport(0,0,e,t)}_renderOutput(e){let t=this._nodes.getOutputCacheKey(),r=this._quadCache.get(e.texture),i;if(r===void 0){i=new Wa(new Pt),i.name="Output Color Transform",i.material.name="outputColorTransform",i.material.fragmentNode=this._nodes.getOutputNode(e.texture),r={quad:i,cacheKey:t},this._quadCache.set(e.texture,r);let n=()=>{i.material.dispose(),this._quadCache.delete(e.texture),e.texture.removeEventListener("dispose",n)};e.texture.addEventListener("dispose",n)}else i=r.quad,r.cacheKey!==t&&(i.material.fragmentNode=this._nodes.getOutputNode(e.texture),i.material.needsUpdate=!0,r.cacheKey=t);let s=this.autoClear,a=this.xr.enabled;this.autoClear=!1,this.xr.enabled=!1,this._renderOutputLayers(i,e),this.autoClear=s,this.xr.enabled=a}getMaxAnisotropy(){return this.backend.capabilities.getMaxAnisotropy()}getActiveCubeFace(){return this._activeCubeFace}getActiveMipmapLevel(){return this._activeMipmapLevel}async setAnimationLoop(e){this._initialized===!1&&await this.init(),this._animation.setAnimationLoop(e)}getAnimationLoop(){return this._animation.getAnimationLoop()}async getArrayBufferAsync(e,t=null,r=0,i=-1){if(t!==null&&t.isReadbackBuffer&&this.info.memoryMap.has(t)===!1){this.info.createReadbackBuffer(t);let s=()=>{t.removeEventListener("dispose",s),this.info.destroyReadbackBuffer(t)};t.addEventListener("dispose",s)}if(r%4!==0||i>0&&i%4!==0)throw new Error('THREE.Renderer: "getArrayBufferAsync()" offset and count must be a multiple of 4.');return await this.backend.getArrayBufferAsync(e,t,r,i)}getContext(){return this.backend.getContext()}getPixelRatio(){return this._canvasTarget.getPixelRatio()}getDrawingBufferSize(e){return this._canvasTarget.getDrawingBufferSize(e)}getSize(e){return this._canvasTarget.getSize(e)}setPixelRatio(e=1){this._canvasTarget.setPixelRatio(e)}setDrawingBufferSize(e,t,r){this.xr&&this.xr.isPresenting||this._canvasTarget.setDrawingBufferSize(e,t,r)}setSize(e,t,r=!0){this.xr&&this.xr.isPresenting||this._canvasTarget.setSize(e,t,r)}setOpaqueSort(e){this._opaqueSort=e}setTransparentSort(e){this._transparentSort=e}getScissor(e){return this._canvasTarget.getScissor(e)}setScissor(e,t,r,i){this._canvasTarget.setScissor(e,t,r,i)}getScissorTest(){return this._canvasTarget.getScissorTest()}setScissorTest(e){this._canvasTarget.setScissorTest(e),this.backend.setScissorTest(e)}getViewport(e){return this._canvasTarget.getViewport(e)}setViewport(e,t,r,i,s=0,a=1){this._canvasTarget.setViewport(e,t,r,i,s,a)}getClearColor(e){return e.copy(this._clearColor)}setClearColor(e,t=1){this._clearColor.set(e),this._clearColor.a=t}getClearAlpha(){return this._clearColor.a}setClearAlpha(e){this._clearColor.a=e}getClearDepth(){return this.reversedDepthBuffer===!0?1-this._clearDepth:this._clearDepth}setClearDepth(e){this._clearDepth=e}getClearStencil(){return this._clearStencil}setClearStencil(e){this._clearStencil=e}isOccluded(e){let t=this._currentRenderContext;return t&&this.backend.isOccluded(t,e)}clear(e=!0,t=!0,r=!0){if(this._initialized===!1)throw new Error('THREE.Renderer: .clear() called before the backend is initialized. Use "await renderer.init();" before using this method.');let i=this._renderTarget||this._getFrameBufferTarget(),s=null;if(i!==null){this._textures.updateRenderTarget(i);let a=this._textures.get(i);s=this._renderContexts.get(i,null,-1),s.textures=a.textures,s.depthTexture=a.depthTexture,s.width=a.width,s.height=a.height,s.renderTarget=i,s.depth=i.depthBuffer,s.stencil=i.stencilBuffer;let n=this.backend.getClearColor();s.clearColorValue.r=n.r,s.clearColorValue.g=n.g,s.clearColorValue.b=n.b,s.clearColorValue.a=n.a,s.clearDepthValue=this.getClearDepth(),s.clearStencilValue=this.getClearStencil(),s.activeCubeFace=this.getActiveCubeFace(),s.activeMipmapLevel=this.getActiveMipmapLevel(),i.depthBuffer===!0&&(a.depthInitialized=!0)}this.backend.clear(e,t,r,s),i!==null&&this._renderTarget===null&&this._renderOutput(i)}clearColor(){this.clear(!0,!1,!1)}clearDepth(){this.clear(!1,!0,!1)}clearStencil(){this.clear(!1,!1,!0)}async clearAsync(e=!0,t=!0,r=!0){Et('Renderer: "clearAsync()" has been deprecated. Use "clear()" and "await renderer.init();" when creating the renderer.'),await this.init(),this.clear(e,t,r)}async clearColorAsync(){Et('Renderer: "clearColorAsync()" has been deprecated. Use "clearColor()" and "await renderer.init();" when creating the renderer.'),this.clear(!0,!1,!1)}async clearDepthAsync(){Et('Renderer: "clearDepthAsync()" has been deprecated. Use "clearDepth()" and "await renderer.init();" when creating the renderer.'),this.clear(!1,!0,!1)}async clearStencilAsync(){Et('Renderer: "clearStencilAsync()" has been deprecated. Use "clearStencil()" and "await renderer.init();" when creating the renderer.'),this.clear(!1,!1,!0)}get needsFrameBufferTarget(){let e=this.currentToneMapping!==eo,t=this.currentColorSpace!==Gt.workingColorSpace;return e||t}get samples(){return this._samples}get currentSamples(){let e=this._samples;return this._renderTarget!==null?e=this._renderTarget.samples:this.needsFrameBufferTarget&&(e=0),e}get currentToneMapping(){return this.isOutputTarget?this.toneMapping:eo}get currentColorSpace(){return this.isOutputTarget?this.outputColorSpace:Gt.workingColorSpace}get isOutputTarget(){return this._renderTarget===this._outputRenderTarget||this._renderTarget===null}dispose(){if(this._initialized===!0){this.info.dispose(),this.backend.dispose(),this._animation.dispose(),this._objects.dispose(),this._geometries.dispose(),this._pipelines.dispose(),this._nodes.dispose(),this._bindings.dispose(),this._renderLists.dispose(),this._renderContexts.dispose(),this._textures.dispose();for(let e of this._frameBufferTargets.keys())e.dispose();Object.values(this.backend.timestampQueryPool).forEach(e=>{e!==null&&e.dispose()})}this.setRenderTarget(null),this.setAnimationLoop(null)}setRenderTarget(e,t=0,r=0){this._renderTarget=e,this._activeCubeFace=t,this._activeMipmapLevel=r}getRenderTarget(){return this._renderTarget}setOutputRenderTarget(e){this._outputRenderTarget=e}getOutputRenderTarget(){return this._outputRenderTarget}setCanvasTarget(e){this._canvasTarget.removeEventListener("resize",this._onCanvasTargetResize),this._canvasTarget=e,this._canvasTarget.addEventListener("resize",this._onCanvasTargetResize)}getCanvasTarget(){return this._canvasTarget}_resetXRState(){this.backend.setXRTarget(null),this.setOutputRenderTarget(null),this.setRenderTarget(null);for(let e of this._frameBufferTargets.keys())e.dispose()}setRenderObjectFunction(e){this._renderObjectFunction=e}getRenderObjectFunction(){return this._renderObjectFunction}compute(e,t=null){if(this._isDeviceLost===!0)return;if(this._initialized===!1)return Ue("Renderer: .compute() called before the backend is initialized. Try using .computeAsync() instead."),this.computeAsync(e,t);let r=this._nodes.nodeFrame,i=r.renderId;this.info.calls++,this.info.compute.calls++,this.info.compute.frameCalls++,r.renderId=this.info.calls,this.backend.updateTimeStampUID(e),this.inspector.beginCompute(this.backend.getTimestampUID(e),e);let s=this.backend,a=this._pipelines,n=this._bindings,o=this._nodes,l=Array.isArray(e)?e:[e];if(l[0]===void 0||l[0].isComputeNode!==!0)throw new Error("THREE.Renderer: .compute() expects a ComputeNode.");s.beginCompute(e);for(let u of l){if(a.has(u)===!1){let c=()=>{u.removeEventListener("dispose",c),a.delete(u),n.deleteForCompute(u),o.delete(u)};u.addEventListener("dispose",c);let m=u.onInitFunction;m!==null&&m.call(u,{renderer:this})}o.updateForCompute(u),n.updateForCompute(u);let h=n.getForCompute(u),d=a.getForCompute(u,h);s.compute(e,u,h,d,t)}s.finishCompute(e),r.renderId=i,this.inspector.finishCompute(this.backend.getTimestampUID(e))}async computeAsync(e,t=null){this._initialized===!1&&await this.init(),this.compute(e,t)}async hasFeatureAsync(e){return Et('Renderer: "hasFeatureAsync()" has been deprecated. Use "hasFeature()" and "await renderer.init();" when creating the renderer.'),await this.init(),this.hasFeature(e)}async resolveTimestampsAsync(e="render"){return this._initialized===!1&&await this.init(),this.backend.resolveTimestampsAsync(e)}hasFeature(e){if(this._initialized===!1)throw new Error('THREE.Renderer: .hasFeature() called before the backend is initialized. Use "await renderer.init();" before using this method.');return this.backend.hasFeature(e)}hasInitialized(){return this._initialized}async initTextureAsync(e){Et('Renderer: "initTextureAsync()" has been deprecated. Use "initTexture()" and "await renderer.init();" when creating the renderer.'),await this.init(),this.initTexture(e)}initTexture(e){if(this._initialized===!1)throw new Error('THREE.Renderer: .initTexture() called before the backend is initialized. Use "await renderer.init();" before using this method.');this._textures.updateTexture(e)}initRenderTarget(e){if(this._initialized===!1)throw new Error('THREE.Renderer: .initRenderTarget() called before the backend is initialized. Use "await renderer.init();" before using this method.');this._textures.updateRenderTarget(e);let t=this._textures.get(e),r=this._renderContexts.get(e);r.textures=t.textures,r.depthTexture=t.depthTexture,r.width=t.width,r.height=t.height,r.renderTarget=e,r.depth=e.depthBuffer,r.stencil=e.stencilBuffer,this.backend.initRenderTarget(r)}copyFramebufferToTexture(e,t=null){if(t!==null)if(t.isVector2)t=No.set(t.x,t.y,e.image.width,e.image.height).floor();else if(t.isVector4)t=No.copy(t).floor();else{Ce("Renderer.copyFramebufferToTexture: Invalid rectangle.");return}else t=No.set(0,0,e.image.width,e.image.height);let r=this._currentRenderContext,i;r!==null?i=r.renderTarget:(i=this._renderTarget||this._getFrameBufferTarget(),i!==null&&(this._textures.updateRenderTarget(i),r=this._textures.get(i))),this._textures.updateTexture(e,{renderTarget:i}),this.backend.copyFramebufferToTexture(e,r,t),this._inspector.copyFramebufferToTexture(e)}copyTextureToTexture(e,t,r=null,i=null,s=0,a=0){this._textures.updateTexture(e),this._textures.updateTexture(t),this.backend.copyTextureToTexture(e,t,r,i,s,a),this._inspector.copyTextureToTexture(e,t)}async readRenderTargetPixelsAsync(e,t,r,i,s,a=0,n=0){return this.backend.copyTextureToBuffer(e.textures[a],t,r,i,s,n)}_projectObject(e,t,r,i,s){if(e.visible===!1)return;if(e.layers.test(t.layers)){if(e.isGroup)r=e.renderOrder,e.isClippingGroup&&e.enabled&&(s=s.getGroupContext(e));else if(e.isLOD)e.autoUpdate===!0&&e.update(t);else if(e.isLight)i.pushLight(e);else if(e.isSprite){let n=t.isArrayCamera?My:wy;if(!e.frustumCulled||n.intersectsSprite(e)){this.sortObjects===!0&&No.setFromMatrixPosition(e.matrixWorld).applyMatrix4(Vd);let{geometry:o,material:l}=e;l.visible&&i.push(e,o,l,r,No.z,null,s)}}else if(e.isLineLoop)Ce("Renderer: Objects of type THREE.LineLoop are not supported. Please use THREE.Line or THREE.LineSegments.");else if(e.isMesh||e.isLine||e.isPoints){let n=t.isArrayCamera?My:wy;if(!e.frustumCulled||n.intersectsObject(e)){let{geometry:o,material:l}=e;if(this.sortObjects===!0&&(o.boundingSphere===null&&o.computeBoundingSphere(),No.copy(o.boundingSphere.center).applyMatrix4(e.matrixWorld).applyMatrix4(Vd)),Array.isArray(l)){let u=o.groups;for(let h=0,d=u.length;h0){for(let{material:a}of t)a.side=ii;this._renderObjects(t,r,i,s,"backSide");for(let{material:a}of t)a.side=Cs;this._renderObjects(e,r,i,s);for(let{material:a}of t)a.side=hs}else this._renderObjects(e,r,i,s)}_renderObjects(e,t,r,i,s=null){for(let a=0,n=e.length;a(c.not().discard(),m))(l)}}e.depthNode&&e.depthNode.isNode&&(u=e.depthNode),e.castShadowPositionNode&&e.castShadowPositionNode.isNode?o=e.castShadowPositionNode:e.positionNode&&e.positionNode.isNode&&(o=e.positionNode),r={version:t,colorNode:l,depthNode:u,positionNode:o},this._cacheShadowNodes.set(e,r)}return r}_updateCamera(e){let t=this.xr;if(t.isPresenting===!1){let r=!1;if(this.reversedDepthBuffer===!0&&e.reversedDepth!==!0){if(e._reversedDepth=!0,e.isArrayCamera)for(let s of e.cameras)s._reversedDepth=!0;r=!0}let i=this.coordinateSystem;if(e.coordinateSystem!==i){if(e.coordinateSystem=i,e.isArrayCamera)for(let s of e.cameras)s.coordinateSystem=i;r=!0}if(r===!0&&(e.updateProjectionMatrix(),e.isArrayCamera))for(let s of e.cameras)s.updateProjectionMatrix()}return e.parent===null&&e.matrixWorldAutoUpdate===!0&&e.updateMatrixWorld(),t.enabled===!0&&t.isPresenting===!0&&(t.cameraAutoUpdate===!0&&t.updateCamera(e),e=t.getCamera()),e}renderObject(e,t,r,i,s,a,n,o=null,l=null){let u=!1,h,d,c,m,g,y,b,v=this._currentSourceMaterial;if(e.onBeforeRender(this,t,r,i,s,a),s.allowOverride===!0&&t.overrideMaterial!==null){this._currentSourceMaterial=s;let S=t.overrideMaterial;if(u=!0,h=S.isNodeMaterial?S.colorNode:null,d=S.isNodeMaterial?S.depthNode:null,c=S.isNodeMaterial?S.positionNode:null,m=t.overrideMaterial.side,g=S.displacementMap,y=S.displacementScale,b=S.displacementBias,s.positionNode&&s.positionNode.isNode&&(S.positionNode=s.positionNode),S.alphaTest=s.alphaTest,S.alphaMap=s.alphaMap,S.displacementMap=s.displacementMap,S.displacementScale=s.displacementScale,S.displacementBias=s.displacementBias,S.transparent=s.transparent||s.transmission>0||s.transmissionNode&&s.transmissionNode.isNode||s.backdropNode&&s.backdropNode.isNode,S.isShadowPassMaterial){let{colorNode:T,depthNode:w,positionNode:N}=this._getShadowNodes(s);this.shadowMap.type===Lh?S.side=s.shadowSide!==null?s.shadowSide:s.side:S.side=s.shadowSide!==null?s.shadowSide:DH[s.side],T!==null&&(S.colorNode=T),w!==null&&(S.depthNode=w),N!==null&&(S.positionNode=N)}s=S}s.transparent===!0&&s.side===hs&&s.forceSinglePass===!1?(s.side=ii,this._handleObjectFunction(e,s,t,r,n,a,o,"backSide"),s.side=Cs,this._handleObjectFunction(e,s,t,r,n,a,o,l),s.side=hs):this._handleObjectFunction(e,s,t,r,n,a,o,l),u&&(t.overrideMaterial.colorNode=h,t.overrideMaterial.depthNode=d,t.overrideMaterial.positionNode=c,t.overrideMaterial.side=m,t.overrideMaterial.displacementMap=g,t.overrideMaterial.displacementScale=y,t.overrideMaterial.displacementBias=b),this._currentSourceMaterial=v,e.onAfterRender(this,t,r,i,s,a)}hasCompatibility(e){if(this._initialized===!1)throw new Error('THREE.Renderer: .hasCompatibility() called before the backend is initialized. Use "await renderer.init();" before using this method.');return this.backend.hasCompatibility(e)}_renderObjectDirect(e,t,r,i,s,a,n,o){let l=this._objects.get(e,t,r,i,s,this._currentRenderContext,n,o);l.drawRange=e.geometry.drawRange,l.group=a,this._currentRenderBundle!==null&&(this.backend.get(this._currentRenderBundle).renderObjects.push(l),l.bundle=this._currentRenderBundle.bundleGroup);let u=this._nodes.needsRefresh(l);u&&(this._nodes.updateBefore(l),this._geometries.updateForRender(l),this._nodes.updateForRender(l),this._bindings.updateForRender(l)),this._pipelines.updateForRender(l),this._pipelines.isReady(l)&&(this.backend.draw(l,this.info),u&&this._nodes.updateAfter(l))}_createObjectPipeline(e,t,r,i,s,a,n,o){if(this._compilationPromises!==null){this._compilationPromises.push({object:e,material:t,scene:r,camera:i,lightsNode:s,group:a,clippingContext:n,passId:o,renderContext:this._currentRenderContext});return}let l=this._objects.get(e,t,r,i,s,this._currentRenderContext,n,o);l.drawRange=e.geometry.drawRange,l.group=a,this._nodes.updateBefore(l),this._geometries.updateForRender(l),this._nodes.updateForRender(l),this._bindings.updateForRender(l),this._pipelines.getForRender(l,this._compilationPromises),this._nodes.updateAfter(l)}_onCanvasTargetResize(){this._initialized&&this.backend.updateSize()}get compile(){return this.compileAsync}},L3=class{constructor(e=""){this.name=e,this.visibility=0}setVisibility(e){this.visibility|=e}getVisibility(){return this.visibility}clone(){return Object.assign(new this.constructor,this)}};function k3(e){return e+(Al-e%Al)%Al}var D3=class extends L3{constructor(e,t=null){super(e),this.isBuffer=!0,this.bytesPerElement=Float32Array.BYTES_PER_ELEMENT,this._buffer=t,this._updateRanges=[]}get updateRanges(){return this._updateRanges}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}get byteLength(){return k3(this._buffer.byteLength)}get buffer(){return this._buffer}update(){return!0}release(){this._buffer=null}},O3=class extends D3{constructor(e,t=null){super(e,t),this.isUniformBuffer=!0}},UH=0,U3=class extends O3{constructor(e,t){super("UniformBuffer_"+UH++,e?e.value:null),this.nodeUniform=e,this.groupNode=t,this.isNodeUniformBuffer=!0}set updateRanges(e){this.nodeUniform.updateRanges=e}get updateRanges(){return this.nodeUniform.updateRanges}addUpdateRange(e,t){this.nodeUniform.addUpdateRange(e,t)}clearUpdateRanges(){this.nodeUniform.clearUpdateRanges()}get byteLength(){return k3(this.buffer.byteLength)}get buffer(){return this.nodeUniform.value}},zH=class extends O3{constructor(e){super(e),this.isUniformsGroup=!0,this._values=null,this.uniforms=[],this._updateRangeCache=new Map,this._addedIndices=new Set}addUniformUpdateRange(e){let t=e.index;if(this._addedIndices.has(t))return;let r=this._updateRangeCache.get(t);r===void 0&&(r={start:0,count:0},this._updateRangeCache.set(t,r)),r.start=e.offset,r.count=e.itemSize,this._addedIndices.add(t),this.updateRanges.push(r)}clearUpdateRanges(){this._addedIndices.clear(),super.clearUpdateRanges()}addUniform(e){return this.uniforms.push(e),this}removeUniform(e){let t=this.uniforms.indexOf(e);return t!==-1&&this.uniforms.splice(t,1),this}get values(){return this._values===null&&(this._values=Array.from(this.buffer)),this._values}get buffer(){let e=this._buffer;if(e===null){let t=this.byteLength;e=new Float32Array(new ArrayBuffer(t)),this._buffer=e}return e}get byteLength(){let e=this.bytesPerElement,t=0;for(let r=0,i=this.uniforms.length;r0?h:"";n=`${l.name} { ${u} ${a.name}[${d}]; }; `}else{let l=a.groupNode.name;if(i[l]===void 0){let u=this.uniformGroups[l];if(u!==void 0){let h=[];for(let d of u.uniforms){let c=d.getType(),m=this.getVectorType(c),g=d.nodeUniform.node.precision,y=`${m} ${d.name};`;g!==null&&(y=j3[g]+" "+y),h.push(" "+y)}i[l]=h}}o=!0}if(!o){let l=a.node.precision;l!==null&&(n=j3[l]+" "+n),n="uniform "+n,r.push(n)}}let s="";for(let a in i){let n=i[a];s+=this._getGLSLUniformStruct(a,n.join(` `))+` `}return s+=r.join(` `),s}getTypeFromAttribute(e){let t=super.getTypeFromAttribute(e);if(/^[iu]/.test(t)&&e.gpuType!==ci){let r=e;e.isInterleavedBufferAttribute&&(r=e.data);let i=r.array;i instanceof Uint32Array||i instanceof Int32Array||(t=t.slice(1))}return t}getAttributes(e){let t="";if(e==="vertex"||e==="compute"){let r=this.getAttributesArray(),i=0;for(let s of r)t+=`layout( location = ${i++} ) in ${s.type} ${s.name}; `}return t}getStructMembers(e){let t=[];for(let r of e.members)t.push(` ${r.type} ${r.name};`);return t.join(` `)}getStructs(e){let t=[],r=this.structs[e],i=[];for(let s of r)if(s.output)for(let a of s.members)i.push(`layout( location = ${a.index} ) out ${a.type} ${a.name};`);else{let a="struct "+s.name+` { `;a+=this.getStructMembers(s),a+=` }; `,t.push(a)}return e==="fragment"&&i.length===0&&i.push(`layout( location = 0 ) out ${this.getOutputType()} fragColor;`),` `+i.join(` `)+` `+t.join(` `)}getVaryings(e){let t="",r=this.varyings;if(e==="vertex"||e==="compute")for(let i of r){e==="compute"&&(i.needsInterpolation=!0);let s=this.getType(i.type);if(i.needsInterpolation)if(i.interpolationType){let a=X3[i.interpolationType]||i.interpolationType,n=$3[i.interpolationSampling]||"";t+=`${a} ${n} out ${s} ${i.name}; `}else{let a=s.includes("int")||s.includes("uv")||s.includes("iv")?"flat ":"";t+=`${a}out ${s} ${i.name}; `}else t+=`${s} ${i.name}; `}else if(e==="fragment"){for(let i of r)if(i.needsInterpolation){let s=this.getType(i.type);if(i.interpolationType){let a=X3[i.interpolationType]||i.interpolationType,n=$3[i.interpolationSampling]||"";t+=`${a} ${n} in ${s} ${i.name}; `}else{let a=s.includes("int")||s.includes("uv")||s.includes("iv")?"flat ":"";t+=`${a}in ${s} ${i.name}; `}}}for(let i of this.builtins[e])t+=`${i}; `;return t}getVertexIndex(){return"uint( gl_VertexID )"}getInstanceIndex(){return"uint( gl_InstanceID )"}getInvocationLocalIndex(){return`uint( gl_InstanceID ) % ${this.object.workgroupSize.reduce((e,t)=>e*t,1)}u`}getSubgroupSize(){Ce("GLSLNodeBuilder: WebGLBackend does not support the subgroupSize node")}getInvocationSubgroupIndex(){Ce("GLSLNodeBuilder: WebGLBackend does not support the invocationSubgroupIndex node")}getSubgroupIndex(){Ce("GLSLNodeBuilder: WebGLBackend does not support the subgroupIndex node")}getDrawIndex(){return this.renderer.backend.extensions.has("WEBGL_multi_draw")?"uint( gl_DrawID )":"nodeUniformDrawId"}getFrontFacing(){return"gl_FrontFacing"}getFragCoord(){return"gl_FragCoord.xy"}getFragDepth(){return"gl_FragDepth"}enableExtension(e,t,r=this.shaderStage){let i=this.extensions[r]||(this.extensions[r]=new Map);i.has(e)===!1&&i.set(e,{name:e,behavior:t})}getExtensions(e){let t=[];if(e==="vertex"){let i=this.renderer.backend.extensions;this.object.isBatchedMesh&&i.has("WEBGL_multi_draw")&&this.enableExtension("GL_ANGLE_multi_draw","require",e)}let r=this.extensions[e];if(r!==void 0)for(let{name:i,behavior:s}of r.values())t.push(`#extension ${i} : ${s}`);return t.join(` `)}getClipDistance(){return"gl_ClipDistance"}isAvailable(e){let t=H3[e];if(t===void 0){let r;switch(t=!1,e){case"float32Filterable":r="OES_texture_float_linear";break;case"clipDistance":r="WEBGL_clip_cull_distance";break}if(r!==void 0){let i=this.renderer.backend.extensions;i.has(r)&&(i.get(r),t=!0)}H3[e]=t}return t}isFlipY(){return!0}enableHardwareClipping(e){this.enableExtension("GL_ANGLE_clip_cull_distance","require"),this.builtins.vertex.push(`out float gl_ClipDistance[ ${e} ]`)}enableMultiview(){this.enableExtension("GL_OVR_multiview2","require","fragment"),this.enableExtension("GL_OVR_multiview2","require","vertex"),this.builtins.vertex.push("layout(num_views = 2) in")}registerTransform(e,t){this.transforms.push({varyingName:e,attributeNode:t})}getTransforms(){let e=this.transforms,t="";for(let r=0;r0&&(r+=` `),r+=` // flow -> ${l} `),r+=`${o.code} `,n===s&&t!=="compute"&&(r+=`// result `,t==="vertex"?(r+="gl_Position = ",r+=`${this.format(o.result,s.getNodeType(this),"vec4")};`):t==="fragment"&&(n.outputNode.isOutputStructNode||(r+="fragColor = ",r+=`${this.format(o.result,s.getNodeType(this),this.getOutputType())};`)))}let a=e[t];if(a.extensions=this.getExtensions(t),a.uniforms=this.getUniforms(t),a.attributes=this.getAttributes(t),a.varyings=this.getVaryings(t),a.vars=this.getVars(t,!0),a.structs=this.getStructs(t),a.codes=this.getCodes(t),a.transforms=this.getTransforms(t),a.flow=r,t==="vertex"){let n=this.renderer.backend.extensions;this.object.isBatchedMesh&&n.has("WEBGL_multi_draw")===!1&&(a.uniforms+=` uniform uint nodeUniformDrawId; `)}}this.material!==null?(this.vertexShader=this._getGLSLVertexCode(e.vertex),this.fragmentShader=this._getGLSLFragmentCode(e.fragment)):this.computeShader=this._getGLSLVertexCode(e.compute)}getUniformFromNode(e,t,r,i=null){let s=super.getUniformFromNode(e,t,r,i),a=this.getDataFromNode(e,r,this.globalCache),n=a.uniformGPU;if(n===void 0){let o=e.groupNode,l=o.name,u=this.getBindGroupArray(l,r);if(t==="texture")n=new Ny(s.name,s.node,o),u.push(n);else if(t==="cubeTexture"||t==="cubeDepthTexture")n=new G3(s.name,s.node,o),u.push(n);else if(t==="texture3D")n=new QS(s.name,s.node,o),u.push(n);else if(t==="buffer"){s.name=`buffer${e.id}`;let h=this.getSharedDataFromNode(e),d=h.buffer;d===void 0&&(e.name=`NodeBuffer_${e.id}`,d=new U3(e,o),d.name=e.name,h.buffer=d),u.push(d),n=d}else{let h=this.uniformGroups[l];h===void 0?(h=new z3(l,o),this.uniformGroups[l]=h,u.push(h)):u.indexOf(h)===-1&&u.push(h),n=this.getNodeUniform(s,t);let d=n.name;h.uniforms.some(c=>c.name===d)||h.addUniform(n)}a.uniformGPU=n}return s}},KS=null,Gd=null,Y3=class{constructor(e={}){this.parameters=Object.assign({},e),this.data=new WeakMap,this.renderer=null,this.domElement=null,this.timestampQueryPool={[un.RENDER]:null,[un.COMPUTE]:null},this.trackTimestamp=e.trackTimestamp===!0}async init(e){this.renderer=e}get coordinateSystem(){}beginRender(){}finishRender(){}setXRTarget(){}beginCompute(){}finishCompute(){}draw(){}compute(){}createProgram(){}destroyProgram(){}createBindings(){}updateBindings(){}updateBinding(){}createRenderPipeline(){}createComputePipeline(){}needsRenderUpdate(){}getRenderCacheKey(){}createNodeBuilder(){}updateSampler(){}destroySampler(){}createDefaultTexture(){}createTexture(){}updateTexture(){}generateMipmaps(){}destroyTexture(){}async copyTextureToBuffer(){}copyTextureToTexture(){}copyFramebufferToTexture(){}createAttribute(){}createIndexAttribute(){}createStorageAttribute(){}createUniformBuffer(){}destroyUniformBuffer(){}updateAttribute(){}destroyAttribute(){}getContext(){}updateSize(){}updateViewport(){}updateTimeStampUID(e){let t=this.get(e),r=this.renderer.info.frame,i;e.isComputeNode===!0?i="c:"+this.renderer.info.compute.frameCalls:i="r:"+this.renderer.info.render.frameCalls,t.timestampUID=i+":"+e.id+":f"+r}getTimestampUID(e){return this.get(e).timestampUID}getTimestampFrames(e){let t=this.timestampQueryPool[e];return t?t.getTimestampFrames():[]}_getQueryPool(e){let t=e.startsWith("c:")?un.COMPUTE:un.RENDER;return this.timestampQueryPool[t]}getTimestamp(e){return this._getQueryPool(e).getTimestamp(e)}get hasTimestamp(){return!1}hasTimestampQuery(e){return this._getQueryPool(e).hasTimestampQuery(e)}isOccluded(){}async resolveTimestampsAsync(e="render"){if(!this.trackTimestamp){Et("WebGPURenderer: Timestamp tracking is disabled.");return}let t=this.timestampQueryPool[e];if(!t)return;let r=await t.resolveQueriesAsync();return this.renderer.info[e].timestamp=r,r}async getArrayBufferAsync(){}async hasFeatureAsync(){}hasFeature(){}getDrawingBufferSize(){return KS=KS||new fe,this.renderer.getDrawingBufferSize(KS)}setScissorTest(){}getClearColor(){let e=this.renderer;return Gd=Gd||new gS,e.getClearColor(Gd),Gd.getRGB(Gd),Gd}getDomElement(){let e=this.domElement;return e===null&&(e=this.parameters.canvas!==void 0?this.parameters.canvas:KD(),"setAttribute"in e&&e.setAttribute("data-engine","three.js r185 webgpu"),this.domElement=e),e}hasCompatibility(){return!1}initRenderTarget(){}set(e,t){this.data.set(e,t)}get(e){let t=this.data.get(e);return t===void 0&&(t={},this.data.set(e,t)),t}has(e){return this.data.has(e)}delete(e){this.data.delete(e)}deleteBindGroupData(){}dispose(){}},qH=0,YH=class{constructor(e,t){this.buffers=[e.bufferGPU,t],this.type=e.type,this.bufferType=e.bufferType,this.pbo=e.pbo,this.byteLength=e.byteLength,this.bytesPerElement=e.BYTES_PER_ELEMENT,this.version=e.version,this.isInteger=e.isInteger,this.activeBufferIndex=0,this.baseId=e.id}get id(){return`${this.baseId}|${this.activeBufferIndex}`}get bufferGPU(){return this.buffers[this.activeBufferIndex]}get transformBuffer(){return this.buffers[this.activeBufferIndex^1]}switchBuffers(){this.activeBufferIndex^=1}},ZH=class{constructor(e){this.backend=e}createAttribute(e,t){let r=this.backend,{gl:i}=r,s=e.array,a=e.usage||i.STATIC_DRAW,n=e.isInterleavedBufferAttribute?e.data:e,o=r.get(n),l=o.bufferGPU;l===void 0&&(l=this._createBuffer(i,t,s,a),o.bufferGPU=l,o.bufferType=t,o.version=n.version);let u;if(s instanceof Float32Array)u=i.FLOAT;else if(typeof Float16Array<"u"&&s instanceof Float16Array)u=i.HALF_FLOAT;else if(s instanceof Uint16Array)e.isFloat16BufferAttribute?u=i.HALF_FLOAT:u=i.UNSIGNED_SHORT;else if(s instanceof Int16Array)u=i.SHORT;else if(s instanceof Uint32Array)u=i.UNSIGNED_INT;else if(s instanceof Int32Array)u=i.INT;else if(s instanceof Int8Array)u=i.BYTE;else if(s instanceof Uint8Array)u=i.UNSIGNED_BYTE;else if(s instanceof Uint8ClampedArray)u=i.UNSIGNED_BYTE;else throw new Error("THREE.WebGLBackend: Unsupported buffer data format: "+s);let h={bufferGPU:l,bufferType:t,type:u,byteLength:s.byteLength,bytesPerElement:s.BYTES_PER_ELEMENT,version:e.version,pbo:e.pbo,isInteger:u===i.INT||u===i.UNSIGNED_INT||e.gpuType===ci,id:qH++};if(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute){let d=this._createBuffer(i,t,s,a);h=new YH(h,d)}r.set(e,h)}updateAttribute(e){let t=this.backend,{gl:r}=t,i=e.array,s=e.isInterleavedBufferAttribute?e.data:e,a=t.get(s),n=a.bufferType,o=e.isInterleavedBufferAttribute?e.data.updateRanges:e.updateRanges;if(r.bindBuffer(n,a.bufferGPU),o.length===0)r.bufferSubData(n,0,i);else{for(let l=0,u=o.length;l{t.buffer=null,t._mapped=!1,t.removeEventListener("release",d),t.removeEventListener("dispose",d)};t.addEventListener("release",d),t.addEventListener("dispose",d),h=new Uint8Array(new ArrayBuffer(u)),t.buffer=h.buffer}else h=new Uint8Array(t);return a.bindBuffer(a.COPY_READ_BUFFER,l),a.getBufferSubData(a.COPY_READ_BUFFER,r,h),a.bindBuffer(a.COPY_READ_BUFFER,null),a.bindBuffer(a.COPY_WRITE_BUFFER,null),t&&t.isReadbackBuffer?t:h.buffer}_createBuffer(e,t,r,i){let s=e.createBuffer();return e.bindBuffer(t,s),e.bufferData(t,r,i),e.bindBuffer(t,null),s}},rm,Ao,JH=class{constructor(e){this.backend=e,this.gl=this.backend.gl,this.enabled={},this.parameters={},this.currentFlipSided=null,this.currentCullFace=null,this.currentProgram=null,this.currentBlendingEnabled=!1,this.currentBlending=null,this.currentBlendSrc=null,this.currentBlendDst=null,this.currentBlendSrcAlpha=null,this.currentBlendDstAlpha=null,this.currentPremultipledAlpha=null,this.currentPolygonOffsetFactor=null,this.currentPolygonOffsetUnits=null,this.currentColorMask=null,this.currentDepthReversed=!1,this.currentDepthFunc=null,this.currentDepthMask=null,this.currentStencilFunc=null,this.currentStencilRef=null,this.currentStencilFuncMask=null,this.currentStencilFail=null,this.currentStencilZFail=null,this.currentStencilZPass=null,this.currentStencilMask=null,this.currentLineWidth=null,this.currentClippingPlanes=0,this.currentVAO=null,this.currentIndex=null,this.currentBoundFramebuffers={},this.currentDrawbuffers=new WeakMap,this.maxTextures=this.gl.getParameter(this.gl.MAX_TEXTURE_IMAGE_UNITS),this.currentTextureSlot=null,this.currentBoundTextures={},this.currentBoundBufferBases={},this._init()}_init(){let e=this.gl;rm={[la]:e.FUNC_ADD,[vM]:e.FUNC_SUBTRACT,[bM]:e.FUNC_REVERSE_SUBTRACT},Ao={[Jo]:e.ZERO,[TM]:e.ONE,[SM]:e.SRC_COLOR,[$c]:e.SRC_ALPHA,[CM]:e.SRC_ALPHA_SATURATE,[NM]:e.DST_COLOR,[wM]:e.DST_ALPHA,[_M]:e.ONE_MINUS_SRC_COLOR,[qc]:e.ONE_MINUS_SRC_ALPHA,[AM]:e.ONE_MINUS_DST_COLOR,[MM]:e.ONE_MINUS_DST_ALPHA};let t=e.getParameter(e.SCISSOR_BOX),r=e.getParameter(e.VIEWPORT);this.currentScissor=new Wt().fromArray(t),this.currentViewport=new Wt().fromArray(r),this._tempVec4=new Wt}enable(e){let{enabled:t}=this;t[e]!==!0&&(this.gl.enable(e),t[e]=!0)}disable(e){let{enabled:t}=this;t[e]!==!1&&(this.gl.disable(e),t[e]=!1)}setFlipSided(e){if(this.currentFlipSided!==e){let{gl:t}=this;e?t.frontFace(t.CW):t.frontFace(t.CCW),this.currentFlipSided=e}}setCullFace(e){let{gl:t}=this;e!==bD?(this.enable(t.CULL_FACE),e!==this.currentCullFace&&(e===TD?t.cullFace(t.BACK):e===SD?t.cullFace(t.FRONT):t.cullFace(t.FRONT_AND_BACK))):this.disable(t.CULL_FACE),this.currentCullFace=e}setLineWidth(e){let{currentLineWidth:t,gl:r}=this;e!==t&&(r.lineWidth(e),this.currentLineWidth=e)}setMRTBlending(e,t,r){let i=this.gl,s=this.backend.drawBuffersIndexedExt;if(!s){Et("WebGPURenderer: Multiple Render Targets (MRT) blending configuration is not fully supported in compatibility mode. The material blending will be used for all render targets.");return}for(let a=0;a0?this.enable(i.SAMPLE_ALPHA_TO_COVERAGE):this.disable(i.SAMPLE_ALPHA_TO_COVERAGE),r>0&&this.currentClippingPlanes!==r)for(let n=0;n<8;n++)n{function s(){let a=e.clientWaitSync(t,e.SYNC_FLUSH_COMMANDS_BIT,0);if(a===e.WAIT_FAILED){e.deleteSync(t),i();return}if(a===e.TIMEOUT_EXPIRED){requestAnimationFrame(s);return}e.deleteSync(t),r()}s()})}},Z3=!1,Ay,e_,J3,KH=class{constructor(e){this.backend=e,this.gl=e.gl,this.extensions=e.extensions,this.defaultTextures={},this._srcFramebuffer=null,this._dstFramebuffer=null,Z3===!1&&(this._init(),Z3=!0)}_init(){let e=this.gl;Ay={[to]:e.REPEAT,[Ti]:e.CLAMP_TO_EDGE,[Qo]:e.MIRRORED_REPEAT},e_={[or]:e.NEAREST,[RM]:e.NEAREST_MIPMAP_NEAREST,[Gh]:e.NEAREST_MIPMAP_LINEAR,[lr]:e.LINEAR,[sv]:e.LINEAR_MIPMAP_NEAREST,[Ia]:e.LINEAR_MIPMAP_LINEAR},J3={[LM]:e.NEVER,[OM]:e.ALWAYS,[yv]:e.LESS,[tp]:e.LEQUAL,[kM]:e.EQUAL,[$h]:e.GEQUAL,[fg]:e.GREATER,[DM]:e.NOTEQUAL}}getGLTextureType(e){let{gl:t}=this,r;return e.isCubeTexture===!0?r=t.TEXTURE_CUBE_MAP:e.isArrayTexture===!0||e.isDataArrayTexture===!0||e.isCompressedArrayTexture===!0?r=t.TEXTURE_2D_ARRAY:e.isData3DTexture===!0?r=t.TEXTURE_3D:r=t.TEXTURE_2D,r}getInternalFormat(e,t,r,i,s,a=!1){let{gl:n,extensions:o}=this;if(e!==null){if(n[e]!==void 0)return n[e];Ue("WebGLBackend: Attempt to use non-existing WebGL internal format '"+e+"'")}let l=null;i&&(l=o.get("EXT_texture_norm16"),l||Ue("WebGLRenderer: Unable to use normalized textures without EXT_texture_norm16 extension"));let u=t;if(t===n.RED&&(r===n.FLOAT&&(u=n.R32F),r===n.HALF_FLOAT&&(u=n.R16F),r===n.UNSIGNED_BYTE&&(u=n.R8),r===n.BYTE&&(u=n.R8_SNORM),r===n.UNSIGNED_SHORT&&l&&(u=l.R16_EXT),r===n.SHORT&&l&&(u=l.R16_SNORM_EXT)),t===n.RED_INTEGER&&(r===n.UNSIGNED_BYTE&&(u=n.R8UI),r===n.UNSIGNED_SHORT&&(u=n.R16UI),r===n.UNSIGNED_INT&&(u=n.R32UI),r===n.BYTE&&(u=n.R8I),r===n.SHORT&&(u=n.R16I),r===n.INT&&(u=n.R32I)),t===n.RG&&(r===n.FLOAT&&(u=n.RG32F),r===n.HALF_FLOAT&&(u=n.RG16F),r===n.UNSIGNED_BYTE&&(u=n.RG8),r===n.BYTE&&(u=n.RG8_SNORM),r===n.UNSIGNED_SHORT&&l&&(u=l.RG16_EXT),r===n.SHORT&&l&&(u=l.RG16_SNORM_EXT)),t===n.RG_INTEGER&&(r===n.UNSIGNED_BYTE&&(u=n.RG8UI),r===n.UNSIGNED_SHORT&&(u=n.RG16UI),r===n.UNSIGNED_INT&&(u=n.RG32UI),r===n.BYTE&&(u=n.RG8I),r===n.SHORT&&(u=n.RG16I),r===n.INT&&(u=n.RG32I)),t===n.RGB){let h=a?mg:Gt.getTransfer(s);r===n.FLOAT&&(u=n.RGB32F),r===n.HALF_FLOAT&&(u=n.RGB16F),r===n.UNSIGNED_BYTE&&(u=h===Tt?n.SRGB8:n.RGB8),r===n.BYTE&&(u=n.RGB8_SNORM),r===n.UNSIGNED_SHORT&&l&&(u=l.RGB16_EXT),r===n.SHORT&&l&&(u=l.RGB16_SNORM_EXT),r===n.UNSIGNED_SHORT_5_6_5&&(u=n.RGB565),r===n.UNSIGNED_SHORT_5_5_5_1&&(u=n.RGB5_A1),r===n.UNSIGNED_SHORT_4_4_4_4&&(u=n.RGB4),r===n.UNSIGNED_INT_5_9_9_9_REV&&(u=n.RGB9_E5),r===n.UNSIGNED_INT_10F_11F_11F_REV&&(u=n.R11F_G11F_B10F)}if(t===n.RGB_INTEGER&&(r===n.UNSIGNED_BYTE&&(u=n.RGB8UI),r===n.UNSIGNED_SHORT&&(u=n.RGB16UI),r===n.UNSIGNED_INT&&(u=n.RGB32UI),r===n.BYTE&&(u=n.RGB8I),r===n.SHORT&&(u=n.RGB16I),r===n.INT&&(u=n.RGB32I)),t===n.RGBA){let h=a?mg:Gt.getTransfer(s);r===n.FLOAT&&(u=n.RGBA32F),r===n.HALF_FLOAT&&(u=n.RGBA16F),r===n.UNSIGNED_BYTE&&(u=h===Tt?n.SRGB8_ALPHA8:n.RGBA8),r===n.BYTE&&(u=n.RGBA8_SNORM),r===n.UNSIGNED_SHORT&&l&&(u=l.RGBA16_EXT),r===n.SHORT&&l&&(u=l.RGBA16_SNORM_EXT),r===n.UNSIGNED_SHORT_4_4_4_4&&(u=n.RGBA4),r===n.UNSIGNED_SHORT_5_5_5_1&&(u=n.RGB5_A1)}return t===n.RGBA_INTEGER&&(r===n.UNSIGNED_BYTE&&(u=n.RGBA8UI),r===n.UNSIGNED_SHORT&&(u=n.RGBA16UI),r===n.UNSIGNED_INT&&(u=n.RGBA32UI),r===n.BYTE&&(u=n.RGBA8I),r===n.SHORT&&(u=n.RGBA16I),r===n.INT&&(u=n.RGBA32I)),t===n.DEPTH_COMPONENT&&(r===n.UNSIGNED_SHORT&&(u=n.DEPTH_COMPONENT16),r===n.UNSIGNED_INT&&(u=n.DEPTH_COMPONENT24),r===n.FLOAT&&(u=n.DEPTH_COMPONENT32F)),t===n.DEPTH_STENCIL&&r===n.UNSIGNED_INT_24_8&&(u=n.DEPTH24_STENCIL8),(u===n.R16F||u===n.R32F||u===n.RG16F||u===n.RG32F||u===n.RGBA16F||u===n.RGBA32F)&&o.get("EXT_color_buffer_float"),u}setTextureParameters(e,t){let{gl:r,extensions:i,backend:s}=this,{state:a}=this.backend,n=Gt.getPrimaries(Gt.workingColorSpace),o=t.colorSpace===Fa?null:Gt.getPrimaries(t.colorSpace),l=t.colorSpace===Fa||n===o?r.NONE:r.BROWSER_DEFAULT_WEBGL;a.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,t.flipY),a.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultiplyAlpha),a.pixelStorei(r.UNPACK_ALIGNMENT,t.unpackAlignment),a.pixelStorei(r.UNPACK_COLORSPACE_CONVERSION_WEBGL,l),r.texParameteri(e,r.TEXTURE_WRAP_S,Ay[t.wrapS]),r.texParameteri(e,r.TEXTURE_WRAP_T,Ay[t.wrapT]),(e===r.TEXTURE_3D||e===r.TEXTURE_2D_ARRAY)&&(t.isArrayTexture||r.texParameteri(e,r.TEXTURE_WRAP_R,Ay[t.wrapR])),r.texParameteri(e,r.TEXTURE_MAG_FILTER,e_[t.magFilter]);let u=t.mipmaps!==void 0&&t.mipmaps.length>0,h=t.minFilter===lr&&u?Ia:t.minFilter;if(r.texParameteri(e,r.TEXTURE_MIN_FILTER,e_[h]),t.compareFunction&&(r.texParameteri(e,r.TEXTURE_COMPARE_MODE,r.COMPARE_REF_TO_TEXTURE),r.texParameteri(e,r.TEXTURE_COMPARE_FUNC,J3[t.compareFunction])),i.has("EXT_texture_filter_anisotropic")===!0){if(t.magFilter===or||t.minFilter!==Gh&&t.minFilter!==Ia||t.type===Er&&i.has("OES_texture_float_linear")===!1)return;if(t.anisotropy>1){let d=i.get("EXT_texture_filter_anisotropic");r.texParameterf(e,d.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(t.anisotropy,s.capabilities.getMaxAnisotropy()))}}}createDefaultTexture(e){let{gl:t,backend:r,defaultTextures:i}=this,s=this.getGLTextureType(e),a=i[s];a===void 0&&(a=t.createTexture(),r.state.bindTexture(s,a),t.texParameteri(s,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(s,t.TEXTURE_MAG_FILTER,t.NEAREST),i[s]=a),r.set(e,{textureGPU:a,glTextureType:s})}createTexture(e,t){let{gl:r,backend:i}=this,s,a,n,o,l;if(e.isExternalTexture===!0)s=e.sourceTexture,a=this.getGLTextureType(e);else{let{levels:u,width:h,height:d,depth:c}=t;n=i.utils.convert(e.format,e.colorSpace),o=i.utils.convert(e.type),l=this.getInternalFormat(e.internalFormat,n,o,e.normalized,e.colorSpace,e.isVideoTexture),s=r.createTexture(),a=this.getGLTextureType(e),i.state.bindTexture(a,s),this.setTextureParameters(a,e),e.isArrayTexture||e.isDataArrayTexture||e.isCompressedArrayTexture?r.texStorage3D(r.TEXTURE_2D_ARRAY,u,l,h,d,c):e.isData3DTexture?r.texStorage3D(r.TEXTURE_3D,u,l,h,d,c):e.isVideoTexture||r.texStorage2D(a,u,l,h,d)}i.set(e,{textureGPU:s,glTextureType:a,glFormat:n,glType:o,glInternalFormat:l})}copyBufferToTexture(e,t){let{gl:r,backend:i}=this,{state:s}=i,{textureGPU:a,glTextureType:n,glFormat:o,glType:l}=i.get(t),{width:u,height:h}=t.source.data;r.bindBuffer(r.PIXEL_UNPACK_BUFFER,e),i.state.bindTexture(n,a),s.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,!1),s.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),r.texSubImage2D(n,0,0,0,u,h,o,l,0),r.bindBuffer(r.PIXEL_UNPACK_BUFFER,null),i.state.unbindTexture()}updateTexture(e,t){let{gl:r}=this,{width:i,height:s}=t,{textureGPU:a,glTextureType:n,glFormat:o,glType:l,glInternalFormat:u}=this.backend.get(e);if(!(e.isRenderTargetTexture||a===void 0))if(this.backend.state.bindTexture(n,a),this.setTextureParameters(n,e),e.isCompressedTexture){let h=e.mipmaps,d=t.image;for(let c=0;c0){let d=vU(h.width,h.height,e.format,e.type);for(let c of e.layerUpdates){let m=h.data.subarray(c*d/h.data.BYTES_PER_ELEMENT,(c+1)*d/h.data.BYTES_PER_ELEMENT);r.texSubImage3D(r.TEXTURE_2D_ARRAY,0,0,0,c,h.width,h.height,1,o,l,m)}e.clearLayerUpdates()}else r.texSubImage3D(r.TEXTURE_2D_ARRAY,0,0,0,0,h.width,h.height,h.depth,o,l,h.data)}else if(e.isData3DTexture){let h=t.image;r.texSubImage3D(r.TEXTURE_3D,0,0,0,0,h.width,h.height,h.depth,o,l,h.data)}else if(e.isVideoTexture)e.update(),r.texImage2D(n,0,u,o,l,t.image);else if(e.isHTMLTexture)typeof r.texElementImage2D=="function"&&(r.texElementImage2D.length===3?r.texElementImage2D(r.TEXTURE_2D,r.RGBA8,t.image):r.texElementImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,t.image));else{let h=e.mipmaps;if(h.length>0)for(let d=0,c=h.length;d0,d=t.renderTarget?t.renderTarget.height:this.backend.getDrawingBufferSize().y;if(h){let c=n!==0||o!==0,m,g;if(e.isDepthTexture===!0?(m=i.DEPTH_BUFFER_BIT,g=i.DEPTH_ATTACHMENT,t.stencil&&(m|=i.STENCIL_BUFFER_BIT)):(m=i.COLOR_BUFFER_BIT,g=i.COLOR_ATTACHMENT0),c){let y=this.backend.get(t.renderTarget),b=y.framebuffers[t.getCacheKey()],v=y.msaaFrameBuffer;s.bindFramebuffer(i.DRAW_FRAMEBUFFER,b),s.bindFramebuffer(i.READ_FRAMEBUFFER,v);let S=d-o-u;i.blitFramebuffer(n,S,n+l,S+u,n,S,n+l,S+u,m,i.NEAREST),s.bindFramebuffer(i.READ_FRAMEBUFFER,b),s.bindTexture(i.TEXTURE_2D,a),i.copyTexSubImage2D(i.TEXTURE_2D,0,0,0,n,S,l,u),s.unbindTexture()}else{let y=i.createFramebuffer();s.bindFramebuffer(i.DRAW_FRAMEBUFFER,y),i.framebufferTexture2D(i.DRAW_FRAMEBUFFER,g,i.TEXTURE_2D,a,0),i.blitFramebuffer(0,0,l,u,0,0,l,u,m,i.NEAREST),i.deleteFramebuffer(y)}}else s.bindTexture(i.TEXTURE_2D,a),i.copyTexSubImage2D(i.TEXTURE_2D,0,0,0,n,d-u-o,l,u),s.unbindTexture();e.generateMipmaps&&this.generateMipmaps(e),this.backend._setFramebuffer(t)}setupRenderBufferStorage(e,t,r,i=!1){let{gl:s}=this,a=t.renderTarget,{depthTexture:n,depthBuffer:o,stencilBuffer:l,width:u,height:h}=a;if(s.bindRenderbuffer(s.RENDERBUFFER,e),o&&!l){let d=s.DEPTH_COMPONENT24;i===!0?this.extensions.get("WEBGL_multisampled_render_to_texture").renderbufferStorageMultisampleEXT(s.RENDERBUFFER,a.samples,d,u,h):r>0?(n&&n.isDepthTexture&&n.type===s.FLOAT&&(d=s.DEPTH_COMPONENT32F),s.renderbufferStorageMultisample(s.RENDERBUFFER,r,d,u,h)):s.renderbufferStorage(s.RENDERBUFFER,d,u,h),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_ATTACHMENT,s.RENDERBUFFER,e)}else o&&l&&(r>0?s.renderbufferStorageMultisample(s.RENDERBUFFER,r,s.DEPTH24_STENCIL8,u,h):s.renderbufferStorage(s.RENDERBUFFER,s.DEPTH_STENCIL,u,h),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_STENCIL_ATTACHMENT,s.RENDERBUFFER,e));s.bindRenderbuffer(s.RENDERBUFFER,null)}async copyTextureToBuffer(e,t,r,i,s,a){let{backend:n,gl:o}=this,{textureGPU:l,glFormat:u,glType:h}=this.backend.get(e),d=o.createFramebuffer();n.state.bindFramebuffer(o.READ_FRAMEBUFFER,d);let c=e.isCubeTexture?o.TEXTURE_CUBE_MAP_POSITIVE_X+a:o.TEXTURE_2D;o.framebufferTexture2D(o.READ_FRAMEBUFFER,o.COLOR_ATTACHMENT0,c,l,0);let m=this._getTypedArrayType(h),g=this._getBytesPerTexel(h,u),y=i*s*g,b=o.createBuffer();o.bindBuffer(o.PIXEL_PACK_BUFFER,b),o.bufferData(o.PIXEL_PACK_BUFFER,y,o.STREAM_READ),o.readPixels(t,r,i,s,u,h,0),o.bindBuffer(o.PIXEL_PACK_BUFFER,null),await n.utils._clientWaitAsync();let v=new m(y/m.BYTES_PER_ELEMENT);return o.bindBuffer(o.PIXEL_PACK_BUFFER,b),o.getBufferSubData(o.PIXEL_PACK_BUFFER,0,v),o.bindBuffer(o.PIXEL_PACK_BUFFER,null),n.state.bindFramebuffer(o.READ_FRAMEBUFFER,null),o.deleteFramebuffer(d),v}_getTypedArrayType(e){let{gl:t}=this;if(e===t.UNSIGNED_BYTE)return Uint8Array;if(e===t.UNSIGNED_SHORT_4_4_4_4||e===t.UNSIGNED_SHORT_5_5_5_1||e===t.UNSIGNED_SHORT_5_6_5||e===t.UNSIGNED_SHORT)return Uint16Array;if(e===t.UNSIGNED_INT)return Uint32Array;if(e===t.HALF_FLOAT)return Uint16Array;if(e===t.FLOAT)return Float32Array;throw new Error(`THREE.WebGLTextureUtils: Unsupported WebGL type: ${e}`)}_getBytesPerTexel(e,t){let{gl:r}=this,i=0;if(e===r.UNSIGNED_BYTE&&(i=1),(e===r.UNSIGNED_SHORT_4_4_4_4||e===r.UNSIGNED_SHORT_5_5_5_1||e===r.UNSIGNED_SHORT_5_6_5||e===r.UNSIGNED_SHORT||e===r.HALF_FLOAT)&&(i=2),(e===r.UNSIGNED_INT||e===r.FLOAT)&&(i=4),t===r.RGBA)return i*4;if(t===r.RGB)return i*3;if(t===r.ALPHA)return i}dispose(){let{gl:e}=this;this._srcFramebuffer!==null&&e.deleteFramebuffer(this._srcFramebuffer),this._dstFramebuffer!==null&&e.deleteFramebuffer(this._dstFramebuffer)}};function Cy(e){return e.isDataTexture?e.image.data:typeof HTMLImageElement<"u"&&e instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&e instanceof ImageBitmap||typeof OffscreenCanvas<"u"&&e instanceof OffscreenCanvas?e:e.data}var eX=class{constructor(e){this.backend=e,this.gl=this.backend.gl,this.availableExtensions=this.gl.getSupportedExtensions(),this.extensions={}}get(e){let t=this.extensions[e];return t===void 0&&(t=this.gl.getExtension(e),this.extensions[e]=t),t}has(e){return this.availableExtensions.includes(e)}},tX=class{constructor(e){this.backend=e,this.maxAnisotropy=null,this.maxUniformBlockSize=null}getMaxAnisotropy(){if(this.maxAnisotropy!==null)return this.maxAnisotropy;let e=this.backend.gl,t=this.backend.extensions;if(t.has("EXT_texture_filter_anisotropic")===!0){let r=t.get("EXT_texture_filter_anisotropic");this.maxAnisotropy=e.getParameter(r.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else this.maxAnisotropy=0;return this.maxAnisotropy}getUniformBufferLimit(){if(this.maxUniformBlockSize!==null)return this.maxUniformBlockSize;let e=this.backend.gl;return this.maxUniformBlockSize=e.getParameter(e.MAX_UNIFORM_BLOCK_SIZE),this.maxUniformBlockSize}},Q3={WEBGL_multi_draw:"WEBGL_multi_draw",WEBGL_compressed_texture_astc:"texture-compression-astc",WEBGL_compressed_texture_etc:"texture-compression-etc2",WEBGL_compressed_texture_etc1:"texture-compression-etc1",WEBGL_compressed_texture_pvrtc:"texture-compression-pvrtc",WEBGL_compressed_texture_s3tc:"texture-compression-s3tc",EXT_texture_compression_bptc:"texture-compression-bc",EXT_disjoint_timer_query_webgl2:"timestamp-query",OVR_multiview2:"OVR_multiview2"},rX=class{constructor(e){this.gl=e.gl,this.extensions=e.extensions,this.info=e.renderer.info,this.mode=null,this.index=0,this.type=null,this.object=null}render(e,t){let{gl:r,mode:i,object:s,type:a,info:n,index:o}=this;o!==0?r.drawElements(i,t,a,e):r.drawArrays(i,e,t),n.update(s,t,1)}renderInstances(e,t,r){let{gl:i,mode:s,type:a,index:n,object:o,info:l}=this;r!==0&&(n!==0?i.drawElementsInstanced(s,t,a,e,r):i.drawArraysInstanced(s,e,t,r),l.update(o,t,r))}renderMultiDraw(e,t,r){let{extensions:i,mode:s,object:a,info:n}=this;if(r===0)return;let o=i.get("WEBGL_multi_draw");if(o===null)for(let l=0;lthis.maxQueries)return Et(`WebGLTimestampQueryPool [${this.type}]: Maximum number of queries exceeded, when using trackTimestamp it is necessary to resolves the queries via renderer.resolveTimestampsAsync( THREE.TimestampQuery.${this.type.toUpperCase()} ).`),null;let t=this.currentQueryIndex;return this.currentQueryIndex+=2,this.queryStates.set(t,"inactive"),this.queryOffsets.set(e,t),t}beginQuery(e){if(!this.trackTimestamp||this.isDisposed)return;let t=this.queryOffsets.get(e);if(t==null||this.activeQuery!==null)return;let r=this.queries[t];if(r)try{this.queryStates.get(t)==="inactive"&&(this.gl.beginQuery(this.ext.TIME_ELAPSED_EXT,r),this.activeQuery=t,this.queryStates.set(t,"started"))}catch(i){Ce("Error in beginQuery:",i),this.activeQuery=null,this.queryStates.set(t,"inactive")}}endQuery(e){if(!this.trackTimestamp||this.isDisposed)return;let t=this.queryOffsets.get(e);if(t!=null&&this.activeQuery===t)try{this.gl.endQuery(this.ext.TIME_ELAPSED_EXT),this.queryStates.set(t,"ended"),this.activeQuery=null}catch(r){Ce("Error in endQuery:",r),this.queryStates.set(t,"inactive"),this.activeQuery=null}}async resolveQueriesAsync(){if(!this.trackTimestamp||this.pendingResolve)return this.lastValue;this.pendingResolve=!0;try{let e=new Map;for(let[s,a]of this.queryOffsets)if(this.queryStates.get(a)==="ended"){let n=this.queries[a];e.set(s,this.resolveQuery(n))}if(e.size===0)return this.lastValue;let t={},r=[];for(let[s,a]of e){let n=s.match(/^(.*):f(\d+)$/),o=parseInt(n[2]);r.includes(o)===!1&&r.push(o),t[o]===void 0&&(t[o]=0);let l=await a;this.timestamps.set(s,l),t[o]+=l}let i=t[r[r.length-1]];return this.lastValue=i,this.frames=r,this.currentQueryIndex=0,this.queryOffsets.clear(),this.queryStates.clear(),this.activeQuery=null,i}catch(e){return Ce("Error resolving queries:",e),this.lastValue}finally{this.pendingResolve=!1}}async resolveQuery(e){return new Promise(t=>{if(this.isDisposed){t(this.lastValue);return}let r,i=!1,s=()=>{r&&(clearTimeout(r),r=null)},a=o=>{i||(i=!0,s(),t(o))},n=()=>{if(this.isDisposed){a(this.lastValue);return}try{if(this.gl.getParameter(this.ext.GPU_DISJOINT_EXT)){a(this.lastValue);return}if(!this.gl.getQueryParameter(e,this.gl.QUERY_RESULT_AVAILABLE)){r=setTimeout(n,1);return}let o=this.gl.getQueryParameter(e,this.gl.QUERY_RESULT);t(Number(o)/1e6)}catch(o){Ce("Error checking query:",o),t(this.lastValue)}};n()})}dispose(){if(!this.isDisposed&&(this.isDisposed=!0,!!this.trackTimestamp)){for(let e of this.queries)this.gl.deleteQuery(e);this.queries=[],this.queryStates.clear(),this.queryOffsets.clear(),this.lastValue=0,this.activeQuery=null}}},eB=class extends Y3{constructor(e={}){super(e),this.isWebGLBackend=!0,this.attributeUtils=null,this.extensions=null,this.capabilities=null,this.textureUtils=null,this.bufferRenderer=null,this.gl=null,this.state=null,this.utils=null,this.vaoCache={},this.transformFeedbackCache={},this.discard=!1,this.disjoint=null,this.parallel=null,this._currentContext=null,this._knownBindings=new WeakSet,this._supportsInvalidateFramebuffer=typeof navigator>"u"?!1:/OculusBrowser/g.test(navigator.userAgent),this._xrFramebuffer=null}init(e){super.init(e);let t=this.parameters,r={antialias:e.currentSamples>0,alpha:!0,depth:e.depth,stencil:e.stencil},i=t.context!==void 0?t.context:e.domElement.getContext("webgl2",r);function s(a){a.preventDefault();let n={api:"WebGL",message:a.statusMessage||"Unknown reason",reason:null,originalEvent:a};e.onDeviceLost(n)}this._onContextLost=s,e.domElement.addEventListener("webglcontextlost",s,!1),this.gl=i,this.extensions=new eX(this),this.capabilities=new tX(this),this.attributeUtils=new ZH(this),this.textureUtils=new KH(this),this.bufferRenderer=new rX(this),this.state=new JH(this),this.utils=new QH(this),this.extensions.get("EXT_color_buffer_float"),this.extensions.get("WEBGL_clip_cull_distance"),this.extensions.get("OES_texture_float_linear"),this.extensions.get("EXT_color_buffer_half_float"),this.extensions.get("WEBGL_multisampled_render_to_texture"),this.extensions.get("WEBGL_render_shared_exponent"),this.extensions.get("WEBGL_multi_draw"),this.extensions.get("OVR_multiview2"),this.extensions.get("EXT_clip_control"),this.disjoint=this.extensions.get("EXT_disjoint_timer_query_webgl2"),this.parallel=this.extensions.get("KHR_parallel_shader_compile"),this.drawBuffersIndexedExt=this.extensions.get("OES_draw_buffers_indexed"),t.reversedDepthBuffer&&(this.extensions.has("EXT_clip_control")?e.reversedDepthBuffer=!0:(Ue("WebGPURenderer: Unable to use reversed depth buffer due to missing EXT_clip_control extension. Fallback to default depth buffer."),e.reversedDepthBuffer=!1)),e.reversedDepthBuffer&&this.state.setReversedDepth(!0)}get coordinateSystem(){return Ds}get hasTimestamp(){return this.disjoint!==null}async getArrayBufferAsync(e,t=null,r=0,i=-1){return await this.attributeUtils.getArrayBufferAsync(e,t,r,i)}async makeXRCompatible(){this.gl.getContextAttributes().xrCompatible!==!0&&await this.gl.makeXRCompatible()}setXRTarget(e){this._xrFramebuffer=e}setXRRenderTargetTextures(e,t,r=null){let i=this.gl;if(this.set(e.texture,{textureGPU:t,glInternalFormat:i.RGBA8}),r!==null){let s=e.stencilBuffer?i.DEPTH24_STENCIL8:i.DEPTH_COMPONENT24;this.set(e.depthTexture,{textureGPU:r,glInternalFormat:s}),this.extensions.has("WEBGL_multisampled_render_to_texture")===!0&&e._autoAllocateDepthBuffer===!0&&e.multiview===!1&&Ue("WebGLBackend: Render-to-texture extension was disabled because an external texture was provided"),e._autoAllocateDepthBuffer=!1}}initTimestampQuery(e,t){if(!this.disjoint||!this.trackTimestamp)return;this.timestampQueryPool[e]||(this.timestampQueryPool[e]=new iX(this.gl,e,2048));let r=this.timestampQueryPool[e];r.allocateQueriesForContext(t)!==null&&r.beginQuery(t)}prepareTimestampBuffer(e,t){!this.disjoint||!this.trackTimestamp||this.timestampQueryPool[e].endQuery(t)}getContext(){return this.gl}beginRender(e){let{state:t}=this,r=this.get(e);if(e.viewport)this.updateViewport(e);else{let{width:s,height:a}=this.getDrawingBufferSize();t.viewport(0,0,s,a)}if(e.scissor)this.updateScissor(e);else{let{width:s,height:a}=this.getDrawingBufferSize();t.scissor(0,0,s,a)}this.initTimestampQuery(un.RENDER,this.getTimestampUID(e)),r.previousContext=this._currentContext,this._currentContext=e,this._setFramebuffer(e),this.clear(e.clearColor,e.clearDepth,e.clearStencil,e,!1);let i=e.occlusionQueryCount;i>0&&(r.currentOcclusionQueries=r.occlusionQueries,r.currentOcclusionQueryObjects=r.occlusionQueryObjects,r.lastOcclusionObject=null,r.occlusionQueries=new Array(i),r.occlusionQueryObjects=new Array(i),r.occlusionQueryIndex=0)}finishRender(e){let{gl:t,state:r}=this,i=this.get(e),s=i.previousContext;r.resetVertexState();let a=e.occlusionQueryCount;a>0&&(a>i.occlusionQueryIndex&&t.endQuery(t.ANY_SAMPLES_PASSED),this.resolveOccludedAsync(e));let n=e.textures;if(n!==null)for(let o=0;o{let o=0;for(let l=0;l1?t.renderInstances(r,i,s):t.render(r,i)}draw(e){let{object:t,pipeline:r,material:i,context:s,hardwareClippingPlanes:a}=e,{programGPU:n}=this.get(r),{gl:o,state:l}=this,u=this.get(s),h=e.getDrawParameters();if(h===null)return;this._bindUniforms(e.getBindings());let d=t.isMesh&&t.matrixWorld.determinantAffine()<0;l.setMaterial(i,d,a),s.mrt!==null&&s.textures!==null&&l.setMRTBlending(s.textures,s.mrt,i),l.useProgram(n);let c=e.getAttributes(),m=this.get(c),g=m.vaoGPU;if(g===void 0){let C=this._getVaoKey(c);g=this.vaoCache[C],g===void 0&&(g=this._createVao(c),this.vaoCache[C]=g,m.vaoGPU=g)}let y=e.getIndex(),b=y!==null?this.get(y).bufferGPU:null;l.setVertexState(g,b);let v=u.lastOcclusionObject;if(v!==t&&v!==void 0){if(v!==null&&v.occlusionTest===!0&&(o.endQuery(o.ANY_SAMPLES_PASSED),u.occlusionQueryIndex++),t.occlusionTest===!0){let C=o.createQuery();o.beginQuery(o.ANY_SAMPLES_PASSED,C),u.occlusionQueries[u.occlusionQueryIndex]=C,u.occlusionQueryObjects[u.occlusionQueryIndex]=t}u.lastOcclusionObject=t}let S=this.bufferRenderer;t.isPoints?S.mode=o.POINTS:t.isLineSegments?S.mode=o.LINES:t.isLine?S.mode=o.LINE_STRIP:t.isLineLoop?S.mode=o.LINE_LOOP:i.wireframe===!0?(l.setLineWidth(i.wireframeLinewidth*this.renderer.getPixelRatio()),S.mode=o.LINES):S.mode=o.TRIANGLES;let{vertexCount:T,instanceCount:w}=h,{firstVertex:N}=h;if(S.object=t,y!==null){N*=y.array.BYTES_PER_ELEMENT;let C=this.get(y);S.index=y.count,S.type=C.type}else S.index=0;if(e.camera.isArrayCamera===!0&&e.camera.cameras.length>0&&e.camera.isMultiViewCamera===!1){let C=this.get(e.camera),R=e.camera.cameras,E=e.getBindingGroup("cameraIndex").bindings[0];if(C.indexesGPU===void 0||C.indexesGPU.length!==R.length){let z=new Uint32Array([0,0,0,0]),H=[];for(let ue=0,ne=R.length;ue{let d=this.parallel,c=()=>{r.getProgramParameter(n,d.COMPLETION_STATUS_KHR)?(this._completeCompile(e,i),h()):requestAnimationFrame(c)};c()});t.push(u);return}this._completeCompile(e,i)}_handleSource(e,t){let r=e.split(` `),i=[],s=Math.max(t-6,0),a=Math.min(t+6,r.length);for(let n=s;n":" "} ${o}: ${r[n]}`)}return i.join(` `)}_getShaderErrors(e,t,r){let i=e.getShaderParameter(t,e.COMPILE_STATUS),s=(e.getShaderInfoLog(t)||"").trim();if(i&&s==="")return"";let a=/ERROR: 0:(\d+)/.exec(s);if(a){let n=parseInt(a[1]);return r.toUpperCase()+` `+s+` `+this._handleSource(e.getShaderSource(t),n)}else return s}_logProgramError(e,t,r){if(this.renderer.debug.checkShaderErrors){let i=this.gl,s=(i.getProgramInfoLog(e)||"").trim();if(i.getProgramParameter(e,i.LINK_STATUS)===!1)if(typeof this.renderer.debug.onShaderError=="function")this.renderer.debug.onShaderError(i,e,r,t);else{let a=this._getShaderErrors(i,r,"vertex"),n=this._getShaderErrors(i,t,"fragment");Ce("WebGLProgram: Shader Error "+i.getError()+" - VALIDATE_STATUS "+i.getProgramParameter(e,i.VALIDATE_STATUS)+` Program Info Log: `+s+` `+a+` `+n)}else s!==""&&Ue("WebGLProgram: Program Info Log:",s)}}_completeCompile(e,t){let{state:r,gl:i}=this,s=this.get(t),{programGPU:a,fragmentShader:n,vertexShader:o}=s;i.getProgramParameter(a,i.LINK_STATUS)===!1&&this._logProgramError(a,n,o),r.useProgram(a);let l=e.getBindings();this._setupBindings(l,a),this.set(t,{programGPU:a,pipeline:a})}createComputePipeline(e,t){let{state:r,gl:i}=this,s={stage:"fragment",code:`#version 300 es precision highp float; void main() {}`};this.createProgram(s);let{computeProgram:a}=e,n=i.createProgram(),o=this.get(s).shaderGPU,l=this.get(a).shaderGPU,u=a.transforms,h=[],d=[];for(let y=0;yQ3[i]===e),r=this.extensions;for(let i=0;i1,c=s.isXRRenderTarget===!0,m=c===!0&&s._hasExternalTextures===!0,g=a.msaaFrameBuffer,y=a.depthRenderbuffer,b=this.extensions.get("WEBGL_multisampled_render_to_texture"),v=this.extensions.get("OVR_multiview2"),S=this._useMultisampledExtension(s),T=oP(e),w;if(u?(a.cubeFramebuffers||(a.cubeFramebuffers={}),w=a.cubeFramebuffers[T]):c&&m===!1?w=this._xrFramebuffer:(a.framebuffers||(a.framebuffers={}),w=a.framebuffers[T]),w===void 0){w=t.createFramebuffer(),r.bindFramebuffer(t.FRAMEBUFFER,w);let N=e.textures,C=[];if(u){a.cubeFramebuffers[T]=w;let{textureGPU:E}=this.get(N[0]),P=this.renderer._activeCubeFace,I=this.renderer._activeMipmapLevel;t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_CUBE_MAP_POSITIVE_X+P,E,I)}else{a.framebuffers[T]=w;for(let E=0;E0&&S===!1&&!s.multiview){if(g===void 0){let N=[];g=t.createFramebuffer(),r.bindFramebuffer(t.FRAMEBUFFER,g);let C=[],R=e.textures;for(let E=0;E0&&this._useMultisampledExtension(i)===!1){let a=s.framebuffers[e.getCacheKey()],n=t.COLOR_BUFFER_BIT;i.resolveDepthBuffer&&(i.depthBuffer&&(n|=t.DEPTH_BUFFER_BIT),i.stencilBuffer&&i.resolveStencilBuffer&&(n|=t.STENCIL_BUFFER_BIT));let o=s.msaaFrameBuffer,l=s.msaaRenderbuffers,u=e.textures,h=u.length>1;if(r.bindFramebuffer(t.READ_FRAMEBUFFER,o),r.bindFramebuffer(t.DRAW_FRAMEBUFFER,a),h)for(let d=0;d0&&this.extensions.has("WEBGL_multisampled_render_to_texture")===!0&&e._autoAllocateDepthBuffer!==!1}dispose(){this.textureUtils!==null&&this.textureUtils.dispose();let e=this.extensions.get("WEBGL_lose_context");e&&e.loseContext(),this.renderer.domElement.removeEventListener("webglcontextlost",this._onContextLost)}},im={PointList:"point-list",LineList:"line-list",LineStrip:"line-strip",TriangleList:"triangle-list"},Ln=typeof self<"u"&&self.GPUShaderStage?self.GPUShaderStage:{VERTEX:1,FRAGMENT:2,COMPUTE:4},Di={Never:"never",Less:"less",Equal:"equal",LessEqual:"less-equal",Greater:"greater",NotEqual:"not-equal",GreaterEqual:"greater-equal",Always:"always"},Ss={Store:"store"},Kt={Load:"load",Clear:"clear"},tB={CCW:"ccw",CW:"cw"},rB={None:"none",Back:"back"},Ry={Uint16:"uint16",Uint32:"uint32"},Z={R8Unorm:"r8unorm",R8Snorm:"r8snorm",R8Uint:"r8uint",R8Sint:"r8sint",R16Uint:"r16uint",R16Sint:"r16sint",R16Float:"r16float",RG8Unorm:"rg8unorm",RG8Snorm:"rg8snorm",RG8Uint:"rg8uint",RG8Sint:"rg8sint",R16Unorm:"r16unorm",R16Snorm:"r16snorm",R32Uint:"r32uint",R32Sint:"r32sint",R32Float:"r32float",RG16Uint:"rg16uint",RG16Sint:"rg16sint",RG16Float:"rg16float",RGBA8Unorm:"rgba8unorm",RGBA8UnormSRGB:"rgba8unorm-srgb",RGBA8Snorm:"rgba8snorm",RGBA8Uint:"rgba8uint",RGBA8Sint:"rgba8sint",BGRA8Unorm:"bgra8unorm",BGRA8UnormSRGB:"bgra8unorm-srgb",RG16Unorm:"rg16unorm",RG16Snorm:"rg16snorm",RGB9E5UFloat:"rgb9e5ufloat",RGB10A2Unorm:"rgb10a2unorm",RG11B10UFloat:"rg11b10ufloat",RG32Uint:"rg32uint",RG32Sint:"rg32sint",RG32Float:"rg32float",RGBA16Uint:"rgba16uint",RGBA16Sint:"rgba16sint",RGBA16Float:"rgba16float",RGBA16Unorm:"rgba16unorm",RGBA16Snorm:"rgba16snorm",RGBA32Uint:"rgba32uint",RGBA32Sint:"rgba32sint",RGBA32Float:"rgba32float",Depth16Unorm:"depth16unorm",Depth24Plus:"depth24plus",Depth24PlusStencil8:"depth24plus-stencil8",Depth32Float:"depth32float",Depth32FloatStencil8:"depth32float-stencil8",BC1RGBAUnorm:"bc1-rgba-unorm",BC1RGBAUnormSRGB:"bc1-rgba-unorm-srgb",BC2RGBAUnorm:"bc2-rgba-unorm",BC2RGBAUnormSRGB:"bc2-rgba-unorm-srgb",BC3RGBAUnorm:"bc3-rgba-unorm",BC3RGBAUnormSRGB:"bc3-rgba-unorm-srgb",BC4RUnorm:"bc4-r-unorm",BC4RSnorm:"bc4-r-snorm",BC5RGUnorm:"bc5-rg-unorm",BC5RGSnorm:"bc5-rg-snorm",BC6HRGBUFloat:"bc6h-rgb-ufloat",BC6HRGBFloat:"bc6h-rgb-float",BC7RGBAUnorm:"bc7-rgba-unorm",BC7RGBAUnormSRGB:"bc7-rgba-unorm-srgb",ETC2RGB8Unorm:"etc2-rgb8unorm",ETC2RGB8UnormSRGB:"etc2-rgb8unorm-srgb",ETC2RGB8A1Unorm:"etc2-rgb8a1unorm",ETC2RGB8A1UnormSRGB:"etc2-rgb8a1unorm-srgb",ETC2RGBA8Unorm:"etc2-rgba8unorm",ETC2RGBA8UnormSRGB:"etc2-rgba8unorm-srgb",EACR11Unorm:"eac-r11unorm",EACR11Snorm:"eac-r11snorm",EACRG11Unorm:"eac-rg11unorm",EACRG11Snorm:"eac-rg11snorm",ASTC4x4Unorm:"astc-4x4-unorm",ASTC4x4UnormSRGB:"astc-4x4-unorm-srgb",ASTC5x4Unorm:"astc-5x4-unorm",ASTC5x4UnormSRGB:"astc-5x4-unorm-srgb",ASTC5x5Unorm:"astc-5x5-unorm",ASTC5x5UnormSRGB:"astc-5x5-unorm-srgb",ASTC6x5Unorm:"astc-6x5-unorm",ASTC6x5UnormSRGB:"astc-6x5-unorm-srgb",ASTC6x6Unorm:"astc-6x6-unorm",ASTC6x6UnormSRGB:"astc-6x6-unorm-srgb",ASTC8x5Unorm:"astc-8x5-unorm",ASTC8x5UnormSRGB:"astc-8x5-unorm-srgb",ASTC8x6Unorm:"astc-8x6-unorm",ASTC8x6UnormSRGB:"astc-8x6-unorm-srgb",ASTC8x8Unorm:"astc-8x8-unorm",ASTC8x8UnormSRGB:"astc-8x8-unorm-srgb",ASTC10x5Unorm:"astc-10x5-unorm",ASTC10x5UnormSRGB:"astc-10x5-unorm-srgb",ASTC10x6Unorm:"astc-10x6-unorm",ASTC10x6UnormSRGB:"astc-10x6-unorm-srgb",ASTC10x8Unorm:"astc-10x8-unorm",ASTC10x8UnormSRGB:"astc-10x8-unorm-srgb",ASTC10x10Unorm:"astc-10x10-unorm",ASTC10x10UnormSRGB:"astc-10x10-unorm-srgb",ASTC12x10Unorm:"astc-12x10-unorm",ASTC12x10UnormSRGB:"astc-12x10-unorm-srgb",ASTC12x12Unorm:"astc-12x12-unorm",ASTC12x12UnormSRGB:"astc-12x12-unorm-srgb"},t_={ClampToEdge:"clamp-to-edge",Repeat:"repeat",MirrorRepeat:"mirror-repeat"},Ta={Linear:"linear",Nearest:"nearest"},zt={Zero:"zero",One:"one",Src:"src",OneMinusSrc:"one-minus-src",SrcAlpha:"src-alpha",OneMinusSrcAlpha:"one-minus-src-alpha",Dst:"dst",OneMinusDst:"one-minus-dst",DstAlpha:"dst-alpha",OneMinusDstAlpha:"one-minus-dst-alpha",SrcAlphaSaturated:"src-alpha-saturated",Constant:"constant",OneMinusConstant:"one-minus-constant"},Yu={Add:"add",Subtract:"subtract",ReverseSubtract:"reverse-subtract",Min:"min",Max:"max"},iB={None:0,All:15},Bl={Keep:"keep",Zero:"zero",Replace:"replace",Invert:"invert",IncrementClamp:"increment-clamp",DecrementClamp:"decrement-clamp",IncrementWrap:"increment-wrap",DecrementWrap:"decrement-wrap"},sB={Storage:"storage",ReadOnlyStorage:"read-only-storage"},r_={WriteOnly:"write-only",ReadOnly:"read-only",ReadWrite:"read-write"},aB={NonFiltering:"non-filtering",Comparison:"comparison"},Zu={Float:"float",UnfilterableFloat:"unfilterable-float",Depth:"depth",SInt:"sint",UInt:"uint"},nB={TwoD:"2d",ThreeD:"3d"},Oi={TwoD:"2d",TwoDArray:"2d-array",Cube:"cube",ThreeD:"3d"},sX={All:"all"},Ey={Vertex:"vertex",Instance:"instance"},Py={CoreFeaturesAndLimits:"core-features-and-limits",DepthClipControl:"depth-clip-control",Depth32FloatStencil8:"depth32float-stencil8",TextureCompressionBC:"texture-compression-bc",TextureCompressionBCSliced3D:"texture-compression-bc-sliced-3d",TextureCompressionETC2:"texture-compression-etc2",TextureCompressionASTC:"texture-compression-astc",TextureCompressionASTCSliced3D:"texture-compression-astc-sliced-3d",TimestampQuery:"timestamp-query",IndirectFirstInstance:"indirect-first-instance",ShaderF16:"shader-f16",RG11B10UFloat:"rg11b10ufloat-renderable",BGRA8UNormStorage:"bgra8unorm-storage",Float32Filterable:"float32-filterable",Float32Blendable:"float32-blendable",ClipDistances:"clip-distances",DualSourceBlending:"dual-source-blending",Subgroups:"subgroups",TextureFormatsTier1:"texture-formats-tier1",TextureFormatsTier2:"texture-formats-tier2"},oB={"texture-compression-s3tc":"texture-compression-bc","texture-compression-etc1":"texture-compression-etc2"},aX=class extends V3{constructor(e,t,r){super(e,t?t.value:null),this.textureNode=t,this.groupNode=r}update(){let{textureNode:e}=this;return this.texture!==e.value?(this.texture=e.value,!0):super.update()}},nX=class extends D3{constructor(e,t){super(e,t?t.array:null),this._attribute=t,this.isStorageBuffer=!0}get attribute(){return this._attribute}},oX=0,lX=class extends nX{constructor(e,t){super("StorageBuffer_"+oX++,e?e.value:null),this.nodeUniform=e,this.access=e?e.access:Fi.READ_WRITE,this.groupNode=t}get attribute(){return this.nodeUniform.value}get buffer(){return this.nodeUniform.value.array}},i_=[null],uX=class{constructor(e){this.backend=e,this._preferredCanvasFormat=null}getCurrentDepthStencilFormat(e){let t;return e.depth&&(e.depthTexture!==null?t=this.getTextureFormatGPU(e.depthTexture):e.stencil?this.backend.renderer.reversedDepthBuffer===!0?t=Z.Depth32FloatStencil8:t=Z.Depth24PlusStencil8:this.backend.renderer.reversedDepthBuffer===!0?t=Z.Depth32Float:t=Z.Depth24Plus),t}getTextureFormatGPU(e){return this.backend.get(e).format}getTextureSampleData(e){let t;if(e.isFramebufferTexture)t=1;else if(e.isDepthTexture&&!e.renderTarget){let i=this.backend.renderer,s=i.getRenderTarget();t=s?s.samples:i.currentSamples}else e.renderTarget&&(t=e.renderTarget.samples);t=this.getSampleCount(t||1);let r=t>1&&e.renderTarget!==null&&e.isDepthTexture!==!0&&e.isFramebufferTexture!==!0;return{samples:t,primarySamples:r?1:t,isMSAA:r}}getCurrentColorFormat(e){let t;return e.textures!==null?t=this.getTextureFormatGPU(e.textures[0]):t=this.getPreferredCanvasFormat(),t}getCurrentColorFormats(e){return e.textures!==null?e.textures.map(t=>this.getTextureFormatGPU(t)):[this.getPreferredCanvasFormat()]}getCurrentColorSpace(e){return e.textures!==null?e.textures[0].colorSpace:this.backend.renderer.outputColorSpace}getPrimitiveTopology(e,t){if(e.isPoints)return im.PointList;if(e.isLineSegments||e.isMesh&&t.wireframe===!0)return im.LineList;if(e.isLine)return im.LineStrip;if(e.isMesh)return im.TriangleList}getSampleCount(e){return e>=4?4:1}getSampleCountRenderContext(e){return e.textures!==null?this.getSampleCount(e.sampleCount):this.getSampleCount(this.backend.renderer.currentSamples)}getPreferredCanvasFormat(){let e=this.backend.parameters.outputType;if(e===void 0)return this._preferredCanvasFormat===null&&(this._preferredCanvasFormat=navigator.gpu.getPreferredCanvasFormat()),this._preferredCanvasFormat;if(e===Si)return Z.BGRA8Unorm;if(e===Dt)return Z.RGBA16Float;throw new Error("THREE.WebGPUUtils: Unsupported output buffer type.")}};function kn(e,t){i_[0]=t,e.queue.submit(i_),i_[0]=null}var lB=class{constructor(){this.label="",this.layout=null,this.entries=[]}reset(){this.label="",this.layout=null,this.entries.length=0}},Wd=class{constructor(){this.label="",this.size=0,this.usage=0,this.mappedAtCreation=!1}reset(){this.label="",this.size=0,this.usage=0,this.mappedAtCreation=!1}},sm=class{constructor(){this.label=""}reset(){this.label=""}},uB=class{constructor(){this.label="",this.colorFormats=null,this.depthStencilFormat=void 0,this.sampleCount=1,this.depthReadOnly=!1,this.stencilReadOnly=!1}reset(){this.label="",this.colorFormats=null,this.depthStencilFormat=void 0,this.sampleCount=1,this.depthReadOnly=!1,this.stencilReadOnly=!1}},am=class{constructor(){this.view=null,this.depthSlice=void 0,this.resolveTarget=void 0,this.clearValue=void 0,this.loadOp=void 0,this.storeOp=void 0}reset(){this.view=null,this.depthSlice=void 0,this.resolveTarget=void 0,this.clearValue=void 0,this.loadOp=void 0,this.storeOp=void 0}},nm=class{constructor(){this.label="",this.colorAttachments=[],this.depthStencilAttachment=void 0,this.occlusionQuerySet=void 0,this.timestampWrites=void 0,this.maxDrawCount=5e7}reset(){this.label="",this.colorAttachments.length=0,this.depthStencilAttachment=void 0,this.occlusionQuerySet=void 0,this.timestampWrites=void 0,this.maxDrawCount=5e7}},hB=class{constructor(){this.label="",this.layout=null,this.vertex=null,this.primitive={},this.depthStencil=void 0,this.multisample=new hX,this.fragment=null}reset(){this.label="",this.layout=null,this.vertex=null,this.primitive={},this.depthStencil=void 0,this.multisample.reset(),this.fragment=null}},hX=class{constructor(){this.count=1,this.mask=4294967295,this.alphaToCoverageEnabled=!1}reset(){this.count=1,this.mask=4294967295,this.alphaToCoverageEnabled=!1}},dB=class{constructor(){this.label="",this.code="",this.compilationHints=[]}reset(){this.label="",this.code="",this.compilationHints.length=0}},s_=class{constructor(){this.label="",this.size={width:0,height:1,depthOrArrayLayers:1},this.mipLevelCount=1,this.sampleCount=1,this.dimension="2d",this.format=void 0,this.usage=void 0,this.viewFormats=[],this.textureBindingViewDimension=void 0}reset(){this.label="",this.size.width=0,this.size.height=1,this.size.depthOrArrayLayers=1,this.mipLevelCount=1,this.sampleCount=1,this.dimension="2d",this.format=void 0,this.usage=void 0,this.viewFormats.length=0,this.textureBindingViewDimension=void 0}},a_=class{constructor(){this.label="",this.format=void 0,this.dimension=void 0,this.usage=0,this.aspect="all",this.baseMipLevel=0,this.mipLevelCount=void 0,this.baseArrayLayer=0,this.arrayLayerCount=void 0,this.swizzle="rgba"}reset(){this.label="",this.format=void 0,this.dimension=void 0,this.usage=0,this.aspect="all",this.baseMipLevel=0,this.mipLevelCount=void 0,this.baseArrayLayer=0,this.arrayLayerCount=void 0,this.swizzle="rgba"}},Il=new lB,Fl=new Wd,By=new sm,n_=new uB,o_=new nm,jd=new hB,om=new am,Iy=new dB,Hd=new s_,jr=new a_,dX=class extends Nl{constructor(e){super(),this.device=e;let t=` struct VarysStruct { @builtin( position ) Position: vec4f, @location( 0 ) vTex : vec2f, @location( 1 ) @interpolate(flat, either) vBaseArrayLayer: u32, }; @group( 0 ) @binding ( 2 ) var flipY: u32; @vertex fn mainVS( @builtin( vertex_index ) vertexIndex : u32, @builtin( instance_index ) instanceIndex : u32 ) -> VarysStruct { var Varys : VarysStruct; var pos = array( vec2f( -1, -1 ), vec2f( -1, 3 ), vec2f( 3, -1 ), ); let p = pos[ vertexIndex ]; let mult = select( vec2f( 0.5, -0.5 ), vec2f( 0.5, 0.5 ), flipY != 0 ); Varys.vTex = p * mult + vec2f( 0.5 ); Varys.Position = vec4f( p, 0, 1 ); Varys.vBaseArrayLayer = instanceIndex; return Varys; } @group( 0 ) @binding( 0 ) var imgSampler : sampler; @group( 0 ) @binding( 1 ) var img2d : texture_2d; @fragment fn main_2d( Varys: VarysStruct ) -> @location( 0 ) vec4 { return textureSample( img2d, imgSampler, Varys.vTex ); } @group( 0 ) @binding( 1 ) var img2dArray : texture_2d_array; @fragment fn main_2d_array( Varys: VarysStruct ) -> @location( 0 ) vec4 { return textureSample( img2dArray, imgSampler, Varys.vTex, Varys.vBaseArrayLayer ); } const faceMat = array( mat3x3f( 0, 0, -2, 0, -2, 0, 1, 1, 1 ), // pos-x mat3x3f( 0, 0, 2, 0, -2, 0, -1, 1, -1 ), // neg-x mat3x3f( 2, 0, 0, 0, 0, 2, -1, 1, -1 ), // pos-y mat3x3f( 2, 0, 0, 0, 0, -2, -1, -1, 1 ), // neg-y mat3x3f( 2, 0, 0, 0, -2, 0, -1, 1, 1 ), // pos-z mat3x3f( -2, 0, 0, 0, -2, 0, 1, 1, -1 ), // neg-z ); @group( 0 ) @binding( 1 ) var imgCube : texture_cube; @fragment fn main_cube( Varys: VarysStruct ) -> @location( 0 ) vec4 { return textureSample( imgCube, imgSampler, faceMat[ Varys.vBaseArrayLayer ] * vec3f( fract( Varys.vTex ), 1 ) ); } `;this.mipmapSampler=e.createSampler({minFilter:Ta.Linear}),this.flipYSampler=e.createSampler({minFilter:Ta.Nearest}),Fl.size=4,Fl.usage=GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,this.flipUniformBuffer=e.createBuffer(Fl),Fl.reset(),e.queue.writeBuffer(this.flipUniformBuffer,0,new Uint32Array([1])),Fl.size=4,Fl.usage=GPUBufferUsage.UNIFORM,this.noFlipUniformBuffer=e.createBuffer(Fl),Fl.reset(),this.transferPipelines={},Iy.label="mipmap",Iy.code=t,this.mipmapShaderModule=e.createShaderModule(Iy),Iy.reset()}getTransferPipeline(e,t){t=t||"2d-array";let r=`${e}-${t}`,i=this.transferPipelines[r];return i===void 0&&(jd.label=`mipmap-${e}-${t}`,jd.vertex={module:this.mipmapShaderModule},jd.fragment={module:this.mipmapShaderModule,entryPoint:`main_${t.replace("-","_")}`,targets:[{format:e}]},jd.layout="auto",i=this.device.createRenderPipeline(jd),jd.reset(),this.transferPipelines[r]=i),i}flipY(e,t,r=0){let i=t.format,{width:s,height:a}=t.size;Hd.size.width=s,Hd.size.height=a,Hd.format=i,Hd.usage=GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING;let n=this.device.createTexture(Hd);Hd.reset();let o=this.getTransferPipeline(i,e.textureBindingViewDimension),l=this.getTransferPipeline(i,n.textureBindingViewDimension),u=this.device.createCommandEncoder(By),h=(d,c,m,g,y,b)=>{let v=d.getBindGroupLayout(0);jr.dimension=c.textureBindingViewDimension||"2d-array",jr.mipLevelCount=1;let S=c.createView(jr);jr.reset(),Il.layout=v,Il.entries.push({binding:0,resource:this.flipYSampler},{binding:1,resource:S},{binding:2,resource:{buffer:b?this.flipUniformBuffer:this.noFlipUniformBuffer}});let T=this.device.createBindGroup(Il);Il.reset(),jr.dimension="2d",jr.mipLevelCount=1,jr.baseArrayLayer=y,jr.arrayLayerCount=1;let w=g.createView(jr);jr.reset(),om.view=w,om.loadOp=Kt.Clear,om.storeOp=Ss.Store,o_.colorAttachments.push(om);let N=u.beginRenderPass(o_);o_.reset(),om.reset(),N.setPipeline(d),N.setBindGroup(0,T),N.draw(3,1,0,m),N.end()};h(o,e,r,n,0,!1),h(l,n,0,e,r,!0),kn(this.device,u.finish()),n.destroy()}generateMipmaps(e,t=null){let r=this.get(e),i=r.layers||this._mipmapCreateBundles(e),s=t;s===null&&(By.label="mipmapEncoder",s=this.device.createCommandEncoder(By),By.reset()),this._mipmapRunBundles(s,i),t===null&&kn(this.device,s.finish()),r.layers=i}_mipmapCreateBundles(e){let t=e.textureBindingViewDimension||"2d-array",r=this.getTransferPipeline(e.format,t),i=r.getBindGroupLayout(0),s=[];for(let a=1;a0)for(let a=0,n=i.length;a0){for(let a of e.layerUpdates)this._copyBufferToTexture(t.image,r.texture,s,a,e.flipY,a);e.clearLayerUpdates()}else for(let a=0;a0?(this._copyCompressedBufferToTexture(e.mipmaps,r.texture,s,e.layerUpdates),e.clearLayerUpdates()):this._copyCompressedBufferToTexture(e.mipmaps,r.texture,s);else if(e.isCubeTexture)this._copyCubeMapToTexture(e,r.texture,s);else if(e.isHTMLTexture){let a=this.backend.device,n=this.backend.renderer.domElement,o=e.image;if(typeof a.queue.copyElementImageToTexture!="function")return;if(!r.hasPaintCallback){r.hasPaintCallback=!0,n.requestPaint();return}let l=s.size.width,u=s.size.height;a.queue.copyElementImageToTexture.length===2?a.queue.copyElementImageToTexture({source:o},{destination:{texture:r.texture},width:l,height:u}):a.queue.copyElementImageToTexture(o,l,u,{texture:r.texture}),e.flipY&&this._flipY(r.texture,s)}else if(i.length>0)for(let a=0,n=i.length;a0?e.width:r.size.width,u=n>0?e.height:r.size.height;Dy.source=e,Dy.flipY=s,Xd.texture=t,Xd.mipLevel=n,Xd.origin.z=i,Xd.premultipliedAlpha=a,rs.width=l,rs.height=u;try{o.queue.copyExternalImageToTexture(Dy,Xd,rs)}catch{}finally{Dy.reset(),Xd.reset(),rs.reset()}}_getPassUtils(){let e=this._passUtils;return e===null&&(this._passUtils=e=new dX(this.backend.device)),e}_generateMipmaps(e,t=null){this._getPassUtils().generateMipmaps(e,t)}_flipY(e,t,r=0){this._getPassUtils().flipY(e,t,r)}_copyBufferToTexture(e,t,r,i,s,a=0,n=0){let o=this.backend.device,l=e.data,u=this._getBytesPerTexel(r.format),h=e.width*u;ts.texture=t,ts.mipLevel=n,ts.origin.z=i,Co.offset=e.width*e.height*u*a,Co.bytesPerRow=h,rs.width=e.width,rs.height=e.height,o.queue.writeTexture(ts,l,Co,rs),ts.reset(),Co.reset(),rs.reset(),s===!0&&this._flipY(t,r,i)}_copyCompressedBufferToTexture(e,t,r,i=null){let s=this.backend.device,a=this._getBlockData(r.format),n=r.size.depthOrArrayLayers>1,o=i&&i.size>0?i:null;for(let l=0;l]*\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/i,SX=/([a-z_0-9]+)\s*:\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/gi,mB={f32:"float",i32:"int",u32:"uint",bool:"bool","vec2":"vec2","vec2":"ivec2","vec2":"uvec2","vec2":"bvec2",vec2f:"vec2",vec2i:"ivec2",vec2u:"uvec2",vec2b:"bvec2","vec3":"vec3","vec3":"ivec3","vec3":"uvec3","vec3":"bvec3",vec3f:"vec3",vec3i:"ivec3",vec3u:"uvec3",vec3b:"bvec3","vec4":"vec4","vec4":"ivec4","vec4":"uvec4","vec4":"bvec4",vec4f:"vec4",vec4i:"ivec4",vec4u:"uvec4",vec4b:"bvec4","mat2x2":"mat2",mat2x2f:"mat2","mat3x3":"mat3",mat3x3f:"mat3","mat4x4":"mat4",mat4x4f:"mat4",sampler:"sampler",texture_1d:"texture",texture_2d:"texture",texture_2d_array:"texture",texture_multisampled_2d:"cubeTexture",texture_depth_2d:"depthTexture",texture_depth_2d_array:"depthTexture",texture_depth_multisampled_2d:"depthTexture",texture_depth_cube:"depthTexture",texture_depth_cube_array:"depthTexture",texture_3d:"texture3D",texture_cube:"cubeTexture",texture_cube_array:"cubeTexture",texture_storage_1d:"storageTexture",texture_storage_2d:"storageTexture",texture_storage_2d_array:"storageTexture",texture_storage_3d:"storageTexture"},_X=e=>{e=e.trim();let t=e.match(TX);if(t!==null&&t.length===4){let r=t[2],i=[],s=null;for(;(s=SX.exec(r))!==null;)i.push({name:s[1],type:s[2]});let a=[];for(let u=0;u "+this.outputType:"";return`fn ${e} ( ${this.inputsCode.trim()} ) ${t}`+this.blockCode}},MX=class extends w3{parseFunction(e){return new wX(e)}},NX={[Fi.READ_ONLY]:"read",[Fi.WRITE_ONLY]:"write",[Fi.READ_WRITE]:"read_write"},fB={[to]:"repeat",[Ti]:"clamp",[Qo]:"mirror"},u_={vertex:Ln.VERTEX,fragment:Ln.FRAGMENT,compute:Ln.COMPUTE},gB={instance:!0,swizzleAssign:!1,storageBuffer:!0},AX={"^^":"tsl_xor"},CX={float:"f32",int:"i32",uint:"u32",bool:"bool",color:"vec3",vec2:"vec2",ivec2:"vec2",uvec2:"vec2",bvec2:"vec2",vec3:"vec3",ivec3:"vec3",uvec3:"vec3",bvec3:"vec3",vec4:"vec4",ivec4:"vec4",uvec4:"vec4",bvec4:"vec4",mat2:"mat2x2",mat3:"mat3x3",mat4:"mat4x4"},yB={},lm={tsl_xor:new pr("fn tsl_xor( a : bool, b : bool ) -> bool { return ( a || b ) && !( a && b ); }"),mod_float:new pr("fn tsl_mod_float( x : f32, y : f32 ) -> f32 { return x - y * floor( x / y ); }"),mod_vec2:new pr("fn tsl_mod_vec2( x : vec2f, y : vec2f ) -> vec2f { return x - y * floor( x / y ); }"),mod_vec3:new pr("fn tsl_mod_vec3( x : vec3f, y : vec3f ) -> vec3f { return x - y * floor( x / y ); }"),mod_vec4:new pr("fn tsl_mod_vec4( x : vec4f, y : vec4f ) -> vec4f { return x - y * floor( x / y ); }"),equals_bool:new pr("fn tsl_equals_bool( a : bool, b : bool ) -> bool { return a == b; }"),equals_bvec2:new pr("fn tsl_equals_bvec2( a : vec2f, b : vec2f ) -> vec2 { return vec2( a.x == b.x, a.y == b.y ); }"),equals_bvec3:new pr("fn tsl_equals_bvec3( a : vec3f, b : vec3f ) -> vec3 { return vec3( a.x == b.x, a.y == b.y, a.z == b.z ); }"),equals_bvec4:new pr("fn tsl_equals_bvec4( a : vec4f, b : vec4f ) -> vec4 { return vec4( a.x == b.x, a.y == b.y, a.z == b.z, a.w == b.w ); }"),repeatWrapping_float:new pr("fn tsl_repeatWrapping_float( coord: f32 ) -> f32 { return fract( coord ); }"),mirrorWrapping_float:new pr("fn tsl_mirrorWrapping_float( coord: f32 ) -> f32 { let mirrored = fract( coord * 0.5 ) * 2.0; return 1.0 - abs( 1.0 - mirrored ); }"),clampWrapping_float:new pr("fn tsl_clampWrapping_float( coord: f32 ) -> f32 { return clamp( coord, 0.0, 1.0 ); }"),inverse_mat2:new pr(` fn tsl_inverse_mat2( m : mat2x2 ) -> mat2x2 { let det = m[ 0 ][ 0 ] * m[ 1 ][ 1 ] - m[ 0 ][ 1 ] * m[ 1 ][ 0 ]; return mat2x2( m[ 1 ][ 1 ], - m[ 0 ][ 1 ], - m[ 1 ][ 0 ], m[ 0 ][ 0 ] ) * ( 1.0 / det ); } `),inverse_mat3:new pr(` fn tsl_inverse_mat3( m : mat3x3 ) -> mat3x3 { let a00 = m[ 0 ][ 0 ]; let a01 = m[ 0 ][ 1 ]; let a02 = m[ 0 ][ 2 ]; let a10 = m[ 1 ][ 0 ]; let a11 = m[ 1 ][ 1 ]; let a12 = m[ 1 ][ 2 ]; let a20 = m[ 2 ][ 0 ]; let a21 = m[ 2 ][ 1 ]; let a22 = m[ 2 ][ 2 ]; let b01 = a22 * a11 - a12 * a21; let b11 = - a22 * a10 + a12 * a20; let b21 = a21 * a10 - a11 * a20; let det = a00 * b01 + a01 * b11 + a02 * b21; return mat3x3( b01, ( - a22 * a01 + a02 * a21 ), ( a12 * a01 - a02 * a11 ), b11, ( a22 * a00 - a02 * a20 ), ( - a12 * a00 + a02 * a10 ), b21, ( - a21 * a00 + a01 * a20 ), ( a11 * a00 - a01 * a10 ) ) * ( 1.0 / det ); } `),inverse_mat4:new pr(` fn tsl_inverse_mat4( m : mat4x4 ) -> mat4x4 { let a00 = m[ 0 ][ 0 ]; let a01 = m[ 0 ][ 1 ]; let a02 = m[ 0 ][ 2 ]; let a03 = m[ 0 ][ 3 ]; let a10 = m[ 1 ][ 0 ]; let a11 = m[ 1 ][ 1 ]; let a12 = m[ 1 ][ 2 ]; let a13 = m[ 1 ][ 3 ]; let a20 = m[ 2 ][ 0 ]; let a21 = m[ 2 ][ 1 ]; let a22 = m[ 2 ][ 2 ]; let a23 = m[ 2 ][ 3 ]; let a30 = m[ 3 ][ 0 ]; let a31 = m[ 3 ][ 1 ]; let a32 = m[ 3 ][ 2 ]; let a33 = m[ 3 ][ 3 ]; let b00 = a00 * a11 - a01 * a10; let b01 = a00 * a12 - a02 * a10; let b02 = a00 * a13 - a03 * a10; let b03 = a01 * a12 - a02 * a11; let b04 = a01 * a13 - a03 * a11; let b05 = a02 * a13 - a03 * a12; let b06 = a20 * a31 - a21 * a30; let b07 = a20 * a32 - a22 * a30; let b08 = a20 * a33 - a23 * a30; let b09 = a21 * a32 - a22 * a31; let b10 = a21 * a33 - a23 * a31; let b11 = a22 * a33 - a23 * a32; let det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06; return mat4x4( a11 * b11 - a12 * b10 + a13 * b09, a02 * b10 - a01 * b11 - a03 * b09, a31 * b05 - a32 * b04 + a33 * b03, a22 * b04 - a21 * b05 - a23 * b03, a12 * b08 - a10 * b11 - a13 * b07, a00 * b11 - a02 * b08 + a03 * b07, a32 * b02 - a30 * b05 - a33 * b01, a20 * b05 - a22 * b02 + a23 * b01, a10 * b10 - a11 * b08 + a13 * b06, a01 * b08 - a00 * b10 - a03 * b06, a30 * b04 - a31 * b02 + a33 * b00, a21 * b02 - a20 * b04 - a23 * b00, a11 * b07 - a10 * b09 - a12 * b06, a00 * b09 - a01 * b07 + a02 * b06, a31 * b01 - a30 * b03 - a32 * b00, a20 * b03 - a21 * b01 + a22 * b00 ) * ( 1.0 / det ); } `),biquadraticTexture:new pr(` fn tsl_biquadraticTexture( map : texture_2d, coord : vec2f, iRes : vec2u, level : u32 ) -> vec4f { let res = vec2f( iRes ); let uvScaled = coord * res; let uvWrapping = ( ( uvScaled % res ) + res ) % res; // https://www.shadertoy.com/view/WtyXRy let uv = uvWrapping - 0.5; let iuv = floor( uv ); let f = fract( uv ); let rg1 = textureLoad( map, vec2u( iuv + vec2( 0.5, 0.5 ) ) % iRes, level ); let rg2 = textureLoad( map, vec2u( iuv + vec2( 1.5, 0.5 ) ) % iRes, level ); let rg3 = textureLoad( map, vec2u( iuv + vec2( 0.5, 1.5 ) ) % iRes, level ); let rg4 = textureLoad( map, vec2u( iuv + vec2( 1.5, 1.5 ) ) % iRes, level ); return mix( mix( rg1, rg2, f.x ), mix( rg3, rg4, f.x ), f.y ); } `),biquadraticTextureArray:new pr(` fn tsl_biquadraticTexture_array( map : texture_2d_array, coord : vec2f, iRes : vec2u, layer : u32, level : u32 ) -> vec4f { let res = vec2f( iRes ); let uvScaled = coord * res; let uvWrapping = ( ( uvScaled % res ) + res ) % res; // https://www.shadertoy.com/view/WtyXRy let uv = uvWrapping - 0.5; let iuv = floor( uv ); let f = fract( uv ); let rg1 = textureLoad( map, vec2u( iuv + vec2( 0.5, 0.5 ) ) % iRes, layer, level ); let rg2 = textureLoad( map, vec2u( iuv + vec2( 1.5, 0.5 ) ) % iRes, layer, level ); let rg3 = textureLoad( map, vec2u( iuv + vec2( 0.5, 1.5 ) ) % iRes, layer, level ); let rg4 = textureLoad( map, vec2u( iuv + vec2( 1.5, 1.5 ) ) % iRes, layer, level ); return mix( mix( rg1, rg2, f.x ), mix( rg3, rg4, f.x ), f.y ); } `)},RX={dFdx:"dpdx",dFdy:"- dpdy",mod_float:"tsl_mod_float",mod_vec2:"tsl_mod_vec2",mod_vec3:"tsl_mod_vec3",mod_vec4:"tsl_mod_vec4",equals_bool:"tsl_equals_bool",equals_bvec2:"tsl_equals_bvec2",equals_bvec3:"tsl_equals_bvec3",equals_bvec4:"tsl_equals_bvec4",inverse_mat2:"tsl_inverse_mat2",inverse_mat3:"tsl_inverse_mat3",inverse_mat4:"tsl_inverse_mat4",inversesqrt:"inverseSqrt",bitcast:"bitcast",floatpack_snorm_2x16:"pack2x16snorm",floatpack_unorm_2x16:"pack2x16unorm",floatpack_float16_2x16:"pack2x16float",floatunpack_snorm_2x16:"unpack2x16snorm",floatunpack_unorm_2x16:"unpack2x16unorm",floatunpack_float16_2x16:"unpack2x16float"},xB="";(typeof navigator<"u"&&/Firefox|Deno/g.test(navigator.userAgent))!==!0&&(xB+=`diagnostic( off, derivative_uniformity ); `);var EX=class extends S3{constructor(e,t){super(e,t,new MX),this.uniformGroups={},this.uniformGroupsBindings={},this.builtins={},this.directives={},this.scopedArrays=new Map,this.allowEarlyReturns=!0,this.allowGlobalVariables=!0}_generateTextureSample(e,t,r,i,s,a=this.shaderStage){return a==="fragment"?i?s?`textureSample( ${t}, ${t}_sampler, ${r}, ${i}, ${s} )`:`textureSample( ${t}, ${t}_sampler, ${r}, ${i} )`:s?`textureSample( ${t}, ${t}_sampler, ${r}, ${s} )`:`textureSample( ${t}, ${t}_sampler, ${r} )`:this.generateTextureSampleLevel(e,t,r,"0",i)}generateTextureSampleLevel(e,t,r,i,s,a){return this.isUnfilterable(e)===!1?s?a?`textureSampleLevel( ${t}, ${t}_sampler, ${r}, ${s}, ${i}, ${a} )`:`textureSampleLevel( ${t}, ${t}_sampler, ${r}, ${s}, ${i} )`:a?`textureSampleLevel( ${t}, ${t}_sampler, ${r}, ${i}, ${a} )`:`textureSampleLevel( ${t}, ${t}_sampler, ${r}, ${i} )`:this.isFilteredTexture(e)?this.generateFilteredTexture(e,t,r,a,i,s):this.generateTextureLod(e,t,r,s,a,i)}generateWrapFunction(e){let t=`tsl_coord_${fB[e.wrapS]}S_${fB[e.wrapT]}T_${e.is3DTexture||e.isData3DTexture?"3d":"2d"}`,r=yB[t];if(r===void 0){let i=[],s=e.is3DTexture||e.isData3DTexture?"vec3f":"vec2f",a=`fn ${t}( coord : ${s} ) -> ${s} { return ${s}( `,n=(o,l)=>{o===to?(i.push(lm.repeatWrapping_float),a+=` tsl_repeatWrapping_float( coord.${l} )`):o===Ti?(i.push(lm.clampWrapping_float),a+=` tsl_clampWrapping_float( coord.${l} )`):o===Qo?(i.push(lm.mirrorWrapping_float),a+=` tsl_mirrorWrapping_float( coord.${l} )`):(a+=` coord.${l}`,Ue(`WebGPURenderer: Unsupported texture wrap type "${o}" for vertex shader.`))};n(e.wrapS,"x"),a+=`, `,n(e.wrapT,"y"),(e.is3DTexture||e.isData3DTexture)&&(a+=`, `,n(e.wrapR,"z")),a+=` ); } `,yB[t]=r=new pr(a,i)}return r.build(this),t}generateArrayDeclaration(e,t){return`array< ${this.getType(e)}, ${t} >`}generateTextureDimension(e,t,r){let i=this.getDataFromNode(e,this.shaderStage,this.cache);i.dimensionsSnippet===void 0&&(i.dimensionsSnippet={});let s=i.dimensionsSnippet[r];if(i.dimensionsSnippet[r]===void 0){let a,n,{primarySamples:o}=this.renderer.backend.utils.getTextureSampleData(e),l=o>1;e.is3DTexture||e.isData3DTexture?n="vec3":n="vec2",l||e.isStorageTexture?a=t:a=`${t}${r?`, u32( ${r} )`:""}`,s=new x0(new S0(`textureDimensions( ${a} )`,n)),i.dimensionsSnippet[r]=s,(e.isArrayTexture||e.isDataArrayTexture||e.is3DTexture||e.isData3DTexture)&&(i.arrayLayerCount=new x0(new S0(`textureNumLayers(${t})`,"u32"))),e.isTextureCube&&(i.cubeFaceCount=new x0(new S0("6u","u32")))}return s.build(this)}generateFilteredTexture(e,t,r,i,s="0u",a){let n=this.generateWrapFunction(e),o=this.generateTextureDimension(e,t,s);return i&&(r=`${r} + vec2(${i}) / ${o}`),a?(this._include("biquadraticTextureArray"),`tsl_biquadraticTexture_array( ${t}, ${n}( ${r} ), ${o}, u32( ${a} ), u32( ${s} ) )`):(this._include("biquadraticTexture"),`tsl_biquadraticTexture( ${t}, ${n}( ${r} ), ${o}, u32( ${s} ) )`)}generateTextureLod(e,t,r,i,s,a="0u"){if(e.isCubeTexture===!0){s&&(r=`${r} + vec3(${s})`);let c=e.isDepthTexture?"u32":"f32";return`textureSampleLevel( ${t}, ${t}_sampler, ${r}, ${c}( ${a} ) )`}let n=this.generateWrapFunction(e),o=this.generateTextureDimension(e,t,a),l=e.is3DTexture||e.isData3DTexture?"vec3":"vec2",u=l==="vec3"?"vec3( 1, 1, 1 )":"vec2( 1, 1 )";s&&(r=`${r} + ${l}(${s}) / ${l}( ${o} )`);let h=`${l}( 0 )`,d=`${l}( ${o} - ${u} )`;return r=`${l}( clamp( floor( ${n}( ${r} ) * ${l}( ${o} ) ), ${h}, ${d} ) )`,this.generateTextureLoad(e,t,r,a,i,null)}generateStorageTextureLoad(e,t,r,i,s,a){a&&(r=`${r} + ${a}`);let n;return s?n=`textureLoad( ${t}, ${r}, ${s} )`:n=`textureLoad( ${t}, ${r} )`,n}generateTextureLoad(e,t,r,i,s,a){i===null&&(i="0u"),a&&(r=`${r} + ${a}`);let n;return s?n=`textureLoad( ${t}, ${r}, ${s}, u32( ${i} ) )`:(n=`textureLoad( ${t}, ${r}, u32( ${i} ) )`,this.renderer.backend.compatibilityMode&&e.isDepthTexture&&(n+=".x")),n}generateTextureStore(e,t,r,i,s){let a;return i?a=`textureStore( ${t}, ${r}, ${i}, ${s} )`:a=`textureStore( ${t}, ${r}, ${s} )`,a}isSampleCompare(e){return e.isDepthTexture===!0&&e.compareFunction!==null&&this.renderer.hasCompatibility(fu.TEXTURE_COMPARE)}isUnfilterable(e){return this.getComponentTypeFromTexture(e)!=="float"||!this.isAvailable("float32Filterable")&&e.type===Er||this.isSampleCompare(e)===!1&&e.minFilter===or&&e.magFilter===or||this.renderer.backend.utils.getTextureSampleData(e).primarySamples>1}generateTexture(e,t,r,i,s,a=this.shaderStage){let n=null;return this.isUnfilterable(e)?n=this.generateTextureLod(e,t,r,i,s,"0",a):n=this._generateTextureSample(e,t,r,i,s,a),n}generateTextureGrad(e,t,r,i,s,a,n=this.shaderStage){if(n==="fragment")return s?a?`textureSampleGrad( ${t}, ${t}_sampler, ${r}, ${s}, ${i[0]}, ${i[1]}, ${a} )`:`textureSampleGrad( ${t}, ${t}_sampler, ${r}, ${s}, ${i[0]}, ${i[1]} )`:a?`textureSampleGrad( ${t}, ${t}_sampler, ${r}, ${i[0]}, ${i[1]}, ${a} )`:`textureSampleGrad( ${t}, ${t}_sampler, ${r}, ${i[0]}, ${i[1]} )`;Ce(`WebGPURenderer: THREE.TextureNode.gradient() does not support ${n} shader.`)}generateTextureCompare(e,t,r,i,s,a,n=this.shaderStage){if(n==="fragment")return e.isDepthTexture===!0&&e.isArrayTexture===!0?a?`textureSampleCompare( ${t}, ${t}_sampler, ${r}, ${s}, ${i}, ${a} )`:`textureSampleCompare( ${t}, ${t}_sampler, ${r}, ${s}, ${i} )`:a?`textureSampleCompare( ${t}, ${t}_sampler, ${r}, ${i}, ${a} )`:`textureSampleCompare( ${t}, ${t}_sampler, ${r}, ${i} )`;Ce(`WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${n} shader.`)}generateTextureGather(e,t,r,i,s,a){let n=e.isDepthTexture===!0?"":`${i}, `;return s?a?`textureGather( ${n}${t}, ${t}_sampler, ${r}, ${s}, ${a} )`:`textureGather( ${n}${t}, ${t}_sampler, ${r}, ${s} )`:a?`textureGather( ${n}${t}, ${t}_sampler, ${r}, ${a} )`:`textureGather( ${n}${t}, ${t}_sampler, ${r})`}generateTextureGatherCompare(e,t,r,i,s,a){return s?a?`textureGatherCompare( ${t}, ${t}_sampler, ${r}, ${s}, ${i}, ${a} )`:`textureGatherCompare( ${t}, ${t}_sampler, ${r}, ${s}, ${i})`:a?`textureGatherCompare( ${t}, ${t}_sampler, ${r}, ${i}, ${a} )`:`textureGatherCompare( ${t}, ${t}_sampler, ${r}, ${i})`}generateTextureLevel(e,t,r,i,s,a){return this.isUnfilterable(e)===!1?s?a?`textureSampleLevel( ${t}, ${t}_sampler, ${r}, ${s}, ${i}, ${a} )`:`textureSampleLevel( ${t}, ${t}_sampler, ${r}, ${s}, ${i} )`:a?`textureSampleLevel( ${t}, ${t}_sampler, ${r}, ${i}, ${a} )`:`textureSampleLevel( ${t}, ${t}_sampler, ${r}, ${i} )`:this.isFilteredTexture(e)?this.generateFilteredTexture(e,t,r,a,i,s):this.generateTextureLod(e,t,r,s,a,i)}generateTextureBias(e,t,r,i,s,a,n=this.shaderStage){if(n==="fragment")return s?a?`textureSampleBias( ${t}, ${t}_sampler, ${r}, ${s}, ${i}, ${a} )`:`textureSampleBias( ${t}, ${t}_sampler, ${r}, ${s}, ${i} )`:a?`textureSampleBias( ${t}, ${t}_sampler, ${r}, ${i}, ${a} )`:`textureSampleBias( ${t}, ${t}_sampler, ${r}, ${i} )`;Ce(`WebGPURenderer: THREE.TextureNode.biasNode does not support ${n} shader.`)}getPropertyName(e,t=this.shaderStage){if(e.isNodeVarying===!0&&e.needsInterpolation===!0){if(t==="vertex")return`varyings.${e.name}`}else if(e.isNodeUniform===!0){let r=e.name,i=e.type;return i==="texture"||i==="cubeTexture"||i==="cubeDepthTexture"||i==="storageTexture"||i==="texture3D"?r:i==="buffer"||i==="storageBuffer"||i==="indirectStorageBuffer"?this.isCustomStruct(e)?r:r+".value":e.groupNode.name+"."+r}return super.getPropertyName(e)}getOutputStructName(){return"output"}getFunctionOperator(e){let t=AX[e];return t!==void 0?(this._include(t),t):null}getNodeAccess(e,t){return t!=="compute"?e.isAtomic===!0?(Ue("WebGPURenderer: Atomic operations are only supported in compute shaders."),Fi.READ_WRITE):Fi.READ_ONLY:e.access}getStorageAccess(e,t){return NX[this.getNodeAccess(e,t)]}getUniformFromNode(e,t,r,i=null){let s=super.getUniformFromNode(e,t,r,i),a=this.getDataFromNode(e,r,this.globalCache);if(a.uniformGPU===void 0){let n,o=e.groupNode,l=o.name,u=this.getBindGroupArray(l,r);if(t==="texture"||t==="cubeTexture"||t==="cubeDepthTexture"||t==="storageTexture"||t==="texture3D"){let h=null,d=this.getNodeAccess(e,r);if(t==="texture"||t==="storageTexture"?e.value.is3DTexture===!0?h=new QS(s.name,s.node,o,d):h=new Ny(s.name,s.node,o,d):t==="cubeTexture"||t==="cubeDepthTexture"?h=new G3(s.name,s.node,o,d):t==="texture3D"&&(h=new QS(s.name,s.node,o,d)),h.store=e.isStorageTextureNode===!0,h.mipLevel=h.store?e.mipLevel:0,h.setVisibility(u_[r]),e.value.isCubeTexture===!0||this.isUnfilterable(e.value)===!1&&h.store===!1||e.gatherNode!==null){let c=new aX(`${s.name}_sampler`,s.node,o);c.setVisibility(u_[r]),u.push(c,h),n=[c,h]}else u.push(h),n=[h]}else if(t==="buffer"||t==="storageBuffer"||t==="indirectStorageBuffer"){let h=this.getSharedDataFromNode(e),d=h.buffer;if(d===void 0){let c=t==="buffer"?U3:lX;d=new c(e,o),h.buffer=d}d.setVisibility(d.getVisibility()|u_[r]),u.push(d),n=d,s.name=i||"NodeBuffer_"+s.id}else{let h=this.uniformGroups[l];h===void 0&&(h=new z3(l,o),h.setVisibility(Ln.VERTEX|Ln.FRAGMENT|Ln.COMPUTE),this.uniformGroups[l]=h),u.indexOf(h)===-1&&u.push(h),n=this.getNodeUniform(s,t);let d=n.name;h.uniforms.some(c=>c.name===d)||h.addUniform(n)}a.uniformGPU=n}return s}getBuiltin(e,t,r,i=this.shaderStage){let s=this.builtins[i]||(this.builtins[i]=new Map);return s.has(e)===!1&&s.set(e,{name:e,property:t,type:r}),t}hasBuiltin(e,t=this.shaderStage){return this.builtins[t]!==void 0&&this.builtins[t].has(e)}getVertexIndex(){return this.shaderStage==="vertex"?this.getBuiltin("vertex_index","vertexIndex","u32","attribute"):"vertexIndex"}buildFunctionCode(e){let t=e.layout,r=this.flowShaderNode(e),i=[];for(let a of t.inputs)i.push(a.name+" : "+this.getType(a.type));let s=`fn ${t.name}( ${i.join(", ")} ) -> ${this.getType(t.type)} { ${r.vars} ${r.code} `;return r.result&&(s+=` return ${r.result}; `),s+=` } `,s}getInstanceIndex(){return this.shaderStage==="vertex"?this.getBuiltin("instance_index","instanceIndex","u32","attribute"):"instanceIndex"}getInvocationLocalIndex(){return this.getBuiltin("local_invocation_index","invocationLocalIndex","u32","attribute")}getSubgroupSize(){return this.enableSubGroups(),this.getBuiltin("subgroup_size","subgroupSize","u32","attribute")}getInvocationSubgroupIndex(){return this.enableSubGroups(),this.getBuiltin("subgroup_invocation_id","invocationSubgroupIndex","u32","attribute")}getSubgroupIndex(){return this.enableSubGroups(),this.getBuiltin("subgroup_id","subgroupIndex","u32","attribute")}getDrawIndex(){return null}getFrontFacing(){return this.getBuiltin("front_facing","isFront","bool")}getFragCoord(){return this.getBuiltin("position","fragCoord","vec4")+".xy"}getFragDepth(){return"output."+this.getBuiltin("frag_depth","depth","f32","output")}getClipDistance(){return"varyings.hw_clip_distances"}isFlipY(){return!1}enableDirective(e,t=this.shaderStage){(this.directives[t]||(this.directives[t]=new Set)).add(e)}getDirectives(e){let t=[],r=this.directives[e];if(r!==void 0)for(let i of r)t.push(`enable ${i};`);return t.join(` `)}enableSubGroups(){this.enableDirective("subgroups")}enableSubgroupsF16(){this.enableDirective("subgroups-f16")}enableClipDistances(){this.enableDirective("clip_distances")}enableShaderF16(){this.enableDirective("f16")}enableDualSourceBlending(){this.enableDirective("dual_source_blending")}enableHardwareClipping(e){this.enableClipDistances(),this.getBuiltin("clip_distances","hw_clip_distances",`array`,"vertex")}getBuiltins(e){let t=[],r=this.builtins[e];if(r!==void 0)for(let{name:i,property:s,type:a}of r.values())t.push(`@builtin( ${i} ) ${s} : ${a}`);return t.join(`, `)}getScopedArray(e,t,r,i){return this.scopedArrays.has(e)===!1&&this.scopedArrays.set(e,{name:e,scope:t,bufferType:r,bufferCount:i}),e}getScopedArrays(e){if(e!=="compute")return;let t=[];for(let{name:r,scope:i,bufferType:s,bufferCount:a}of this.scopedArrays.values()){let n=this.getType(s);t.push(`var<${i}> ${r}: array< ${n}, ${a} >;`)}return t.join(` `)}getAttributes(e){let t=[];if(e==="compute"&&(this.getBuiltin("global_invocation_id","globalId","vec3","attribute"),this.getBuiltin("workgroup_id","workgroupId","vec3","attribute"),this.getBuiltin("local_invocation_id","localId","vec3","attribute"),this.getBuiltin("num_workgroups","numWorkgroups","vec3","attribute"),this.renderer.hasFeature("subgroups")&&(this.enableDirective("subgroups",e),this.getBuiltin("subgroup_size","subgroupSize","u32","attribute"))),e==="vertex"||e==="compute"){let r=this.getBuiltins("attribute");r&&t.push(r);let i=this.getAttributesArray();for(let s=0,a=i.length;s"),t.push(` ${i+r.name} : ${s}`)}return e.output&&t.push(` ${this.getBuiltins("output")}`),t.join(`, `)}getStructs(e){let t="",r=this.structs[e];if(r.length>0){let i=[];for(let s of r){let a=`struct ${s.name} { `;a+=this.getStructMembers(s),a+=` };`,i.push(a)}t=` `+i.join(` `)+` `}return t}getVar(e,t,r=null,i=""){let s=`var${i} ${t} : `;return r!==null?s+=this.generateArrayDeclaration(e,r):s+=this.getType(e),s}getVars(e,t=!1){let r="";t&&(r="");let i=[],s=this.vars[e];if(s!==void 0)for(let a of s)i.push(`${this.getVar(a.type,a.name,a.count,r)};`);return t?i.join(` `):` ${i.join(` `)} `}getVaryings(e){let t=[];if(e==="vertex"&&this.getBuiltin("position","builtinClipSpace","vec4","vertex"),e==="vertex"||e==="fragment"){let s=this.varyings,a=this.vars[e],n=0;for(let o=0;or.value.itemSize;return i&&!s}getUniforms(e){let t=this.renderer.backend,r=this.uniforms[e],i=[],s=[],a=[],n={};for(let o of r){let l=o.groupNode.name,u=this.bindingsIndexes[l];if(o.type==="texture"||o.type==="cubeTexture"||o.type==="cubeDepthTexture"||o.type==="storageTexture"||o.type==="texture3D"){let h=o.node,d=h.value;(d.isCubeTexture===!0||this.isUnfilterable(d)===!1&&h.isStorageTextureNode!==!0||h.gatherNode!==null)&&(this.isSampleCompare(d)&&h.compareNode!==null?i.push(`@binding( ${u.binding++} ) @group( ${u.group} ) var ${o.name}_sampler : sampler_comparison;`):i.push(`@binding( ${u.binding++} ) @group( ${u.group} ) var ${o.name}_sampler : sampler;`));let c,m="",{primarySamples:g}=t.utils.getTextureSampleData(d);if(g>1&&(m="_multisampled"),d.isCubeTexture===!0&&d.isDepthTexture===!0)c="texture_depth_cube";else if(d.isCubeTexture===!0)c="texture_cube";else if(d.isDepthTexture===!0)t.compatibilityMode&&d.compareFunction===null?c=`texture${m}_2d`:c=`texture_depth${m}_2d${d.isArrayTexture===!0?"_array":""}`;else if(o.node.isStorageTextureNode===!0){let y=l_(d,t.device),b=this.getStorageAccess(o.node,e),v=o.node.value.is3DTexture,S=o.node.value.isArrayTexture;c=`texture_storage_${v?"3d":`2d${S?"_array":""}`}<${y}, ${b}>`}else if(d.isArrayTexture===!0||d.isDataArrayTexture===!0||d.isCompressedArrayTexture===!0)c="texture_2d_array";else if(d.is3DTexture===!0||d.isData3DTexture===!0)c="texture_3d";else{let y=this.getComponentTypeFromTexture(d).charAt(0);c=`texture${m}_2d<${y}32>`}i.push(`@binding( ${u.binding++} ) @group( ${u.group} ) var ${o.name} : ${c};`)}else if(o.type==="buffer"||o.type==="storageBuffer"||o.type==="indirectStorageBuffer"){let h=o.node,d=this.getType(h.getNodeType(this)),c=h.bufferCount,m=c>0&&o.type==="buffer"?", "+c:"",g=h.isStorageBufferNode?`storage, ${this.getStorageAccess(h,e)}`:"uniform";if(this.isCustomStruct(o))s.push(`@binding( ${u.binding++} ) @group( ${u.group} ) var<${g}> ${o.name} : ${d};`);else{let y=` value : array< ${h.isAtomic?`atomic<${d}>`:`${d}`}${m} >`;s.push(this._getWGSLStructBinding(o.name,y,g,u.binding++,u.group))}}else{let h=o.groupNode.name;if(n[h]===void 0){let d=this.uniformGroups[h];if(d!==void 0){let c=[];for(let g of d.uniforms){let y=g.getType(),b=this.getType(this.getVectorType(y));c.push(` ${g.name} : ${b}`)}let m=this.uniformGroupsBindings[h];m===void 0&&(m={index:u.binding++,id:u.group},this.uniformGroupsBindings[h]=m),n[h]={index:m.index,id:m.id,snippets:c}}}}}for(let o in n){let l=n[o];a.push(this._getWGSLStructBinding(o,l.snippets.join(`, `),"uniform",l.index,l.id))}return[...i,...s,...a].join(` `)}buildCode(){let e=this.material!==null?{fragment:{},vertex:{}}:{compute:{}};this.sortBindingGroups();for(let t in e){this.shaderStage=t;let r=this.allowGlobalVariables,i=e[t];i.uniforms=this.getUniforms(t),i.attributes=this.getAttributes(t),i.varyings=this.getVaryings(t),i.structs=this.getStructs(t),i.vars=this.getVars(t,r),i.codes=this.getCodes(t),i.directives=this.getDirectives(t),i.scopedArrays=this.getScopedArrays(t);let s=`// code `;s+=this.flowCode[t];let a=this.flowNodes[t],n=a[a.length-1],o=n.outputNode,l=o!==void 0&&o.isOutputStructNode===!0;for(let u of a){let h=this.getFlowData(u),d=u.name;if(d&&(s.length>0&&(s+=` `),s+=` // flow -> ${d} `),s+=`${h.code} `,u===n&&t!=="compute"){if(s+=`// result `,t==="vertex")s+=`varyings.builtinClipSpace = ${h.result};`;else if(t==="fragment")if(l)i.returnType=o.getNodeType(this),i.structs+="var output : "+i.returnType+";",s+=`return ${h.result};`;else{let c=` @location( 0 ) color: ${this.getType(this.getOutputType())}`,m=this.getBuiltins("output");m&&(c+=`, `+m),i.returnType="OutputStruct",i.structs+=this._getWGSLStruct("OutputStruct",c),i.structs+=` var output : OutputStruct;`,s+=`output.color = ${this.format(h.result,n.getNodeType(this),this.getOutputType())}; return output;`}}}i.flow=s}if(this.shaderStage=null,this.material!==null)this.vertexShader=this._getWGSLVertexCode(e.vertex),this.fragmentShader=this._getWGSLFragmentCode(e.fragment);else{let t=this.object.workgroupSize;this.computeShader=this._getWGSLComputeCode(e.compute,t)}}getMethod(e,t=null){let r;return t!==null&&(r=this._getWGSLMethod(e+"_"+t)),r===void 0&&(r=this._getWGSLMethod(e)),r||e}getBitcastMethod(e){return`bitcast<${this.getType(e)}>`}getFloatPackingMethod(e){return this.getMethod(`floatpack_${e}_2x16`)}getFloatUnpackingMethod(e){return this.getMethod(`floatunpack_${e}_2x16`)}getTernary(e,t,r){return`select( ${r}, ${t}, ${e} )`}getType(e){return CX[e]||e}isAvailable(e){let t=gB[e];return t===void 0&&(e==="float32Filterable"?t=this.renderer.hasFeature("float32-filterable"):e==="clipDistance"&&(t=this.renderer.hasFeature("clip-distances")),gB[e]=t),t}_getWGSLMethod(e){return lm[e]!==void 0&&this._include(e),RX[e]}_include(e){let t=lm[e];return t.build(this),this.addInclude(t),t}_getWGSLVertexCode(e){return`${this.getSignature()} // directives ${e.directives} // structs ${e.structs} // uniforms ${e.uniforms} // varyings ${e.varyings} var varyings : VaryingsStruct; // vars ${e.vars} // codes ${e.codes} @vertex fn main( ${e.attributes} ) -> VaryingsStruct { // flow ${e.flow} return varyings; } `}_getWGSLFragmentCode(e){return`${this.getSignature()} // global ${xB} // structs ${e.structs} // uniforms ${e.uniforms} // vars ${e.vars} // codes ${e.codes} @fragment fn main( ${e.varyings} ) -> ${e.returnType} { // flow ${e.flow} } `}_getWGSLComputeCode(e,t){let[r,i,s]=t;return`${this.getSignature()} // directives ${e.directives} // system var instanceIndex : u32; // locals ${e.scopedArrays} // structs ${e.structs} // uniforms ${e.uniforms} // vars ${this.allowGlobalVariables?e.vars:""} // codes ${e.codes} @compute @workgroup_size( ${r}, ${i}, ${s} ) fn main( ${e.attributes} ) { // local vars ${this.allowGlobalVariables?"":e.vars} // system instanceIndex = globalId.x + globalId.y * ( ${r} * numWorkgroups.x ) + globalId.z * ( ${r} * numWorkgroups.x ) * ( ${i} * numWorkgroups.y ); // flow ${e.flow} } `}_getWGSLStruct(e,t){return` struct ${e} { ${t} };`}_getWGSLStructBinding(e,t,r,i=0,s=0){let a=e+"Struct";return`${this._getWGSLStruct(a,t)} @binding( ${i} ) @group( ${s} ) var<${r}> ${e} : ${a};`}},is=new Wd,h_=new sm,vB=new Map([[Int8Array,["sint8","snorm8"]],[Uint8Array,["uint8","unorm8"]],[Int16Array,["sint16","snorm16"]],[Uint16Array,["uint16","unorm16"]],[Int32Array,["sint32","snorm32"]],[Uint32Array,["uint32","unorm32"]],[Float32Array,["float32"]]]);typeof Float16Array<"u"&&vB.set(Float16Array,["float16"]);var PX=new Map([[sN,["float16"]]]),BX=new Map([[Int32Array,"sint32"],[Int16Array,"sint32"],[Uint32Array,"uint32"],[Uint16Array,"uint32"],[Float32Array,"float32"]]),IX=class{constructor(e){this.backend=e}createAttribute(e,t){let r=this._getBufferAttribute(e),i=this.backend,s=i.get(r),a=s.buffer;if(a===void 0){let n=i.device,o=r.array;if(e.normalized===!1){if(o.constructor===Int16Array||o.constructor===Int8Array)o=new Int32Array(o);else if((o.constructor===Uint16Array||o.constructor===Uint8Array)&&(o=new Uint32Array(o),t&GPUBufferUsage.INDEX))for(let d=0;d1&&r.itemSize*o.BYTES_PER_ELEMENT%4!==0){let d=r.itemSize*o.BYTES_PER_ELEMENT;l=Math.floor((d+3)/4)*4/o.BYTES_PER_ELEMENT}if(l!==void 0){let d=r.itemSize,c=new o.constructor(r.count*l);for(let m=0;m1&&h%4!==0&&(h=Math.floor((h+3)/4)*4)),s.normalized===!1&&(s.array.constructor===Int16Array||s.array.constructor===Uint16Array)&&(h=4),o={arrayStride:h,attributes:[],stepMode:d},r.set(n,o)}let l=this._getVertexFormat(s),u=s.isInterleavedBufferAttribute===!0?s.offset*a:0;o.attributes.push({shaderLocation:i,offset:u,format:l})}return Array.from(r.values())}destroyAttribute(e){let t=this.backend;t.get(this._getBufferAttribute(e)).buffer.destroy(),t.delete(e)}async getArrayBufferAsync(e,t=null,r=0,i=-1){let s=this.backend,a=s.device,n=s.get(this._getBufferAttribute(e)).buffer,o=i===-1?n.size-r:i,l;if(t!==null&&t.isReadbackBuffer){let d=s.get(t);if(t._mapped===!0)throw new Error("THREE.WebGPUAttributeUtils: ReadbackBuffer must be released before being used again.");if(t._mapped=!0,d.readBufferGPU===void 0){is.label=`${t.name}_readback`,is.size=t.maxByteLength,is.usage=GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ,l=a.createBuffer(is),is.reset();let c=()=>{t.buffer=null,t._mapped=!1,l.unmap()},m=()=>{t.buffer=null,t._mapped=!1,l.destroy(),s.delete(t),t.removeEventListener("release",c),t.removeEventListener("dispose",m)};t.addEventListener("release",c),t.addEventListener("dispose",m),d.readBufferGPU=l}else l=d.readBufferGPU}else is.label=`${e.name}_readback`,is.size=o,is.usage=GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ,l=a.createBuffer(is),is.reset();h_.label=`readback_encoder_${e.name}`;let u=a.createCommandEncoder(h_);h_.reset(),u.copyBufferToBuffer(n,r,l,0,o);let h=u.finish();if(kn(a,h),await l.mapAsync(GPUMapMode.READ,0,o),t===null){let d=l.getMappedRange(0,o).slice();return l.destroy(),d}else{if(t.isReadbackBuffer)return t.buffer=l.getMappedRange(0,o),t;{let d=l.getMappedRange(0,o);return new Uint8Array(t).set(new Uint8Array(d)),l.destroy(),t}}}_getVertexFormat(e){let{itemSize:t,normalized:r}=e,i=e.array.constructor,s=e.constructor,a;if(t===1)a=BX.get(i);else{let n=(PX.get(s)||vB.get(i))[r?1:0];if(n){let o=i.BYTES_PER_ELEMENT*t,l=Math.floor((o+3)/4)*4/i.BYTES_PER_ELEMENT;if(l%1)throw new Error("THREE.WebGPUAttributeUtils: Bad vertex format item size.");a=`${n}x${l}`}}return a||Ce("WebGPUAttributeUtils: Vertex format not supported yet."),a}_getBufferAttribute(e){return e.isInterleavedBufferAttribute&&(e=e.data),e}},Js=new lB,um=new Wd,$d=new a_,FX=class{constructor(e){this.layoutGPU=e,this.usedTimes=0}},LX=class{constructor(e){this.backend=e,this._bindGroupLayoutCache=new Map}createBindingsLayout(e){let t=this.backend,r=t.device,i=t.get(e);if(i.layout)return i.layout.layoutGPU;let s=this._createLayoutEntries(e),a=yd(JSON.stringify(s)),n=this._bindGroupLayoutCache.get(a);return n===void 0&&(n=new FX(r.createBindGroupLayout({entries:s})),this._bindGroupLayoutCache.set(a,n)),n.usedTimes++,i.layout=n,i.layoutKey=a,n.layoutGPU}createBindings(e,t,r,i=0){let{backend:s}=this,a=s.get(e),n=this.createBindingsLayout(e),o;r>0&&(a.groups===void 0&&(a.groups=[],a.versions=[]),a.versions[r]===i&&(o=a.groups[r])),o===void 0&&(o=this.createBindGroup(e,n),r>0&&(a.groups[r]=o,a.versions[r]=i)),a.group=o}updateBinding(e){let t=this.backend,r=t.device,i=e.buffer,s=t.get(e).buffer,a=e.updateRanges;if(a.length===0)r.queue.writeBuffer(s,0,i,0);else{let n=ip(i),o=n?1:i.BYTES_PER_ELEMENT,l=a[0].start;for(let u=0,h=a.length;u1&&(d+=`-${o.texture.depthOrArrayLayers}`),d+=`-${u}-${h}`,l=o[d],l===void 0){let c=sX.All,m;n.isSampledCubeTexture?m=Oi.Cube:n.texture.isArrayTexture||n.texture.isDataArrayTexture||n.texture.isCompressedArrayTexture?m=Oi.TwoDArray:n.isSampledTexture3D?m=Oi.ThreeD:m=Oi.TwoD,$d.aspect=c,$d.dimension=m,$d.mipLevelCount=u,$d.baseMipLevel=h,l=o[d]=o.texture.createView($d),$d.reset()}}Js.entries.push({binding:s,resource:l})}else if(n.isSampler){let o=r.get(n);Js.entries.push({binding:s,resource:o.sampler})}s++}let a=i.createBindGroup(Js);return Js.reset(),a}_createLayoutEntries(e){let t=[],r=0;for(let i of e.bindings){let s=this.backend,a={binding:r,visibility:i.visibility};if(i.isUniformBuffer||i.isStorageBuffer){let n={};i.isStorageBuffer&&(i.visibility&Ln.COMPUTE&&(i.access===Fi.READ_WRITE||i.access===Fi.WRITE_ONLY)?n.type=sB.Storage:n.type=sB.ReadOnlyStorage),a.buffer=n}else if(i.isSampledTexture&&i.store){let n={};n.format=this.backend.get(i.texture).texture.format;let o=i.access;o===Fi.READ_WRITE?n.access=r_.ReadWrite:o===Fi.WRITE_ONLY?n.access=r_.WriteOnly:n.access=r_.ReadOnly,i.texture.isArrayTexture?n.viewDimension=Oi.TwoDArray:i.texture.is3DTexture&&(n.viewDimension=Oi.ThreeD),a.storageTexture=n}else if(i.isSampledTexture){let n={},{primarySamples:o}=s.utils.getTextureSampleData(i.texture);if(o>1&&(n.multisampled=!0,i.texture.isDepthTexture||(n.sampleType=Zu.UnfilterableFloat)),i.texture.isDepthTexture)s.compatibilityMode&&i.texture.compareFunction===null?n.sampleType=Zu.UnfilterableFloat:n.sampleType=Zu.Depth;else{let l=i.texture.type;l===ci?n.sampleType=Zu.SInt:l===gr?n.sampleType=Zu.UInt:l===Er&&(this.backend.hasFeature("float32-filterable")?n.sampleType=Zu.Float:n.sampleType=Zu.UnfilterableFloat)}i.isSampledCubeTexture?n.viewDimension=Oi.Cube:i.texture.isArrayTexture||i.texture.isDataArrayTexture||i.texture.isCompressedArrayTexture?n.viewDimension=Oi.TwoDArray:i.isSampledTexture3D&&(n.viewDimension=Oi.ThreeD),a.texture=n}else if(i.isSampler){let n={};i.texture.isDepthTexture&&(i.texture.compareFunction!==null&&i.textureNode.compareNode!==null&&s.hasCompatibility(fu.TEXTURE_COMPARE)?n.type=aB.Comparison:n.type=aB.NonFiltering),a.sampler=n}else Ce(`WebGPUBindingUtils: Unsupported binding "${i}".`);t.push(a),r++}return t}deleteBindGroupData(e){let{backend:t}=this,r=t.get(e);r.layout&&(r.layout.usedTimes--,r.layout.usedTimes===0&&this._bindGroupLayoutCache.delete(r.layoutKey),r.layout=void 0,r.layoutKey=void 0)}dispose(){this._bindGroupLayoutCache.clear()}},kX=class{constructor(e){this.backend=e}getMaxAnisotropy(){return 16}getUniformBufferLimit(){return this.backend.device.limits.maxUniformBufferBindingSize}},DX=class{constructor(){this.label="",this.layout=null,this.compute=null}reset(){this.label="",this.layout=null,this.compute=null}},OX=class{constructor(){this.label="",this.bindGroupLayouts=null}reset(){this.label="",this.bindGroupLayouts=null}},hm=new DX,qd=new OX,Yd=new uB,Qs=new hB,UX=class{constructor(e){this.backend=e}_getSampleCount(e){return this.backend.utils.getSampleCountRenderContext(e)}createRenderPipeline(e,t){let{object:r,material:i,geometry:s,pipeline:a}=e,{vertexProgram:n,fragmentProgram:o}=a,l=this.backend,u=l.device,h=l.utils,d=l.get(a),c=[];for(let z of e.getBindings()){let H=l.get(z),{layoutGPU:ue}=H.layout;c.push(ue)}let m=l.attributeUtils.createShaderVertexBuffers(e),g;i.blending!==Kn&&(i.blending!==oa||i.transparent!==!1)&&(g=this._getBlending(i));let y={};i.stencilWrite===!0&&(y={compare:this._getStencilCompare(i),failOp:this._getStencilOperation(i.stencilFail),depthFailOp:this._getStencilOperation(i.stencilZFail),passOp:this._getStencilOperation(i.stencilZPass)});let b=this._getColorWriteMask(i),v=[];if(e.context.textures!==null){let z=e.context.textures,H=e.context.mrt;for(let ue=0;ue1,Qs.layout=E;let P={},I=e.context.depth,O=e.context.stencil;(I===!0||O===!0)&&(I===!0&&(P.format=C,P.depthWriteEnabled=i.depthWrite,P.depthCompare=N),O===!0&&(P.stencilFront=y,P.stencilBack=y,P.stencilReadMask=i.stencilFuncMask,P.stencilWriteMask=i.stencilWriteMask),i.polygonOffset===!0&&w.topology===im.TriangleList&&(P.depthBias=i.polygonOffsetUnits,P.depthBiasSlopeScale=i.polygonOffsetFactor,P.depthBiasClamp=0),Qs.depthStencil=P),u.pushErrorScope("validation");let L=[{program:n,module:S.module},{program:o,module:T.module}],X=Qs.label;if(t===null)d.pipeline=u.createRenderPipeline(Qs),Qs.reset(),u.popErrorScope().then(z=>{z!==null&&(d.error=!0,Ce(`WebGPURenderer: Render pipeline creation failed (${X}): ${z.message}`),this._reportShaderDiagnostics(L,X))});else{let z=new Promise(async H=>{try{let ue=null,ne=null;try{ne=u.createRenderPipelineAsync(Qs)}catch(ce){ue=ce}if(Qs.reset(),ne!==null)try{d.pipeline=await ne}catch(ce){ue=ce}let re=await u.popErrorScope();if(re!==null||ue!==null){d.error=!0;let ce=re&&re.message||ue&&ue.message||"unknown";Ce(`WebGPURenderer: Async render pipeline creation failed (${X}): ${ce}`),await this._reportShaderDiagnostics(L,X)}}finally{H()}});t.push(z)}}createBundleEncoder(e,t="renderBundleEncoder"){let r=this.backend,{utils:i,device:s}=r,a=i.getCurrentDepthStencilFormat(e),n=i.getCurrentColorFormats(e),o=this._getSampleCount(e);Yd.label=t,Yd.colorFormats=n,Yd.depthStencilFormat=a,Yd.sampleCount=o;let l=s.createRenderBundleEncoder(Yd);return Yd.reset(),l}createComputePipeline(e,t){let r=this.backend,i=r.device,s=r.get(e.computeProgram).module,a=r.get(e),n=[];for(let h of t){let d=r.get(h),{layoutGPU:c}=d.layout;n.push(c)}let o=e.computeProgram,l=`computePipeline_${o.stage}${o.name?`_${o.name}`:""}`;i.pushErrorScope("validation"),qd.bindGroupLayouts=n;let u=i.createPipelineLayout(qd);qd.reset(),hm.label=l,hm.compute=s,hm.layout=u,a.pipeline=i.createComputePipeline(hm),hm.reset(),i.popErrorScope().then(h=>{h!==null&&(a.error=!0,Ce(`WebGPURenderer: Compute pipeline creation failed (${l}): ${h.message}`),this._reportShaderDiagnostics([{program:o,module:s.module}],l))})}async _reportShaderDiagnostics(e,t){for(let{program:r,module:i}of e){let s=await i.getCompilationInfo();if(s.messages.length===0)continue;let a=r.code.split(` `);for(let n of s.messages){let o=n.lineNum>0?` at line ${n.lineNum}${n.linePos>0?`:${n.linePos}`:""}`:"",l=`WebGPURenderer [${t} / ${r.stage} ${n.type}]${o}: ${n.message}`,u="";n.lineNum>0&&n.lineNum<=a.length&&(u=` ${a[n.lineNum-1]}`,n.linePos>0&&(u+=` ${" ".repeat(n.linePos-1)}^`)),(n.type==="error"?Ce:Ue)(l+u)}}}_getBlending(e){let t,r,i=e.blending,s=e.blendSrc,a=e.blendDst,n=e.blendEquation;if(i===Uh){let o=e.blendSrcAlpha!==null?e.blendSrcAlpha:s,l=e.blendDstAlpha!==null?e.blendDstAlpha:a,u=e.blendEquationAlpha!==null?e.blendEquationAlpha:n;t={srcFactor:this._getBlendFactor(s),dstFactor:this._getBlendFactor(a),operation:this._getBlendOperation(n)},r={srcFactor:this._getBlendFactor(o),dstFactor:this._getBlendFactor(l),operation:this._getBlendOperation(u)}}else{let o=e.premultipliedAlpha,l=(u,h,d,c)=>{t={srcFactor:u,dstFactor:h,operation:Yu.Add},r={srcFactor:d,dstFactor:c,operation:Yu.Add}};if(o)switch(i){case oa:l(zt.One,zt.OneMinusSrcAlpha,zt.One,zt.OneMinusSrcAlpha);break;case kh:l(zt.One,zt.One,zt.One,zt.One);break;case Dh:l(zt.Zero,zt.OneMinusSrc,zt.Zero,zt.One);break;case Oh:l(zt.Dst,zt.OneMinusSrcAlpha,zt.Zero,zt.One);break}else switch(i){case oa:l(zt.SrcAlpha,zt.OneMinusSrcAlpha,zt.One,zt.OneMinusSrcAlpha);break;case kh:l(zt.SrcAlpha,zt.One,zt.One,zt.One);break;case Dh:Ce(`WebGPURenderer: "SubtractiveBlending" requires "${e.isMaterial?"material":"blendMode"}.premultipliedAlpha = true".`);break;case Oh:Ce(`WebGPURenderer: "MultiplyBlending" requires "${e.isMaterial?"material":"blendMode"}.premultipliedAlpha = true".`);break}}if(t!==void 0&&r!==void 0)return{color:t,alpha:r};Ce("WebGPURenderer: Invalid blending: ",i)}_getBlendFactor(e){let t;switch(e){case Jo:t=zt.Zero;break;case TM:t=zt.One;break;case SM:t=zt.Src;break;case _M:t=zt.OneMinusSrc;break;case $c:t=zt.SrcAlpha;break;case qc:t=zt.OneMinusSrcAlpha;break;case NM:t=zt.Dst;break;case AM:t=zt.OneMinusDst;break;case wM:t=zt.DstAlpha;break;case MM:t=zt.OneMinusDstAlpha;break;case CM:t=zt.SrcAlphaSaturated;break;case EG:t=zt.Constant;break;case PG:t=zt.OneMinusConstant;break;default:Ce("WebGPURenderer: Blend factor not supported.",e)}return t}_getStencilCompare(e){let t,r=e.stencilFunc;switch(r){case HD:t=Di.Never;break;case gv:t=Di.Always;break;case XD:t=Di.Less;break;case qD:t=Di.LessEqual;break;case $D:t=Di.Equal;break;case JD:t=Di.GreaterEqual;break;case YD:t=Di.Greater;break;case ZD:t=Di.NotEqual;break;default:Ce("WebGPURenderer: Invalid stencil function.",r)}return t}_getStencilOperation(e){let t;switch(e){case mu:t=Bl.Keep;break;case OD:t=Bl.Zero;break;case UD:t=Bl.Replace;break;case jD:t=Bl.Invert;break;case zD:t=Bl.IncrementClamp;break;case VD:t=Bl.DecrementClamp;break;case GD:t=Bl.IncrementWrap;break;case WD:t=Bl.DecrementWrap;break;default:Ce("WebGPURenderer: Invalid stencil operation.",t)}return t}_getBlendOperation(e){let t;switch(e){case la:t=Yu.Add;break;case vM:t=Yu.Subtract;break;case bM:t=Yu.ReverseSubtract;break;case MD:t=Yu.Min;break;case ND:t=Yu.Max;break;default:Ce("WebGPUPipelineUtils: Blend equation not supported.",e)}return t}_getPrimitiveState(e,t,r){let i={},s=this.backend.utils;i.topology=s.getPrimitiveTopology(e,r),t.index!==null&&e.isLine===!0&&e.isLineSegments!==!0&&(i.stripIndexFormat=t.index.array instanceof Uint16Array?Ry.Uint16:Ry.Uint32);let a=r.side===ii;return e.isMesh&&e.matrixWorld.determinantAffine()<0&&(a=!a),i.frontFace=a===!0?tB.CW:tB.CCW,i.cullMode=r.side===hs?rB.None:rB.Back,i}_getColorWriteMask(e){return e.colorWrite===!0?iB.All:iB.None}_getDepthCompare(e){let t;if(e.depthTest===!1)t=Di.Always;else{let r=this.backend.parameters.reversedDepthBuffer?GM[e.depthFunc]:e.depthFunc;switch(r){case Af:t=Di.Never;break;case Cf:t=Di.Always;break;case Rf:t=Di.Less;break;case zh:t=Di.LessEqual;break;case Ef:t=Di.Equal;break;case Pf:t=Di.GreaterEqual;break;case Bf:t=Di.Greater;break;case If:t=Di.NotEqual;break;default:Ce("WebGPUPipelineUtils: Invalid depth function.",r)}}return t}},bB=class{constructor(){this.label="",this.type=void 0,this.count=0}reset(){this.label="",this.type=void 0,this.count=0}},Dn=new Wd,zX=new sm,dm=new bB,VX=class extends K3{constructor(e,t,r=2048){super(r),this.device=e,this.type=t,dm.label=`queryset_global_timestamp_${t}`,dm.type="timestamp",dm.count=this.maxQueries,this.querySet=this.device.createQuerySet(dm),dm.reset();let i=this.maxQueries*8;Dn.label=`buffer_timestamp_resolve_${t}`,Dn.size=i,Dn.usage=GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC,this.resolveBuffer=this.device.createBuffer(Dn),Dn.reset(),Dn.label=`buffer_timestamp_result_${t}`,Dn.size=i,Dn.usage=GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ,this.resultBuffer=this.device.createBuffer(Dn),Dn.reset()}allocateQueriesForContext(e){if(!this.trackTimestamp||this.isDisposed)return null;if(this.currentQueryIndex+2>this.maxQueries)return Et(`WebGPUTimestampQueryPool [${this.type}]: Maximum number of queries exceeded, when using trackTimestamp it is necessary to resolves the queries via renderer.resolveTimestampsAsync( THREE.TimestampQuery.${this.type.toUpperCase()} ).`),null;let t=this.currentQueryIndex;return this.currentQueryIndex+=2,this.queryOffsets.set(e,t),t}async resolveQueriesAsync(){if(!this.trackTimestamp||this.currentQueryIndex===0||this.isDisposed)return this.lastValue;if(this.pendingResolve)return this.pendingResolve;this.pendingResolve=this._resolveQueries();try{return await this.pendingResolve}finally{this.pendingResolve=null}}async _resolveQueries(){if(this.isDisposed)return this.lastValue;try{if(this.resultBuffer.mapState!=="unmapped")return this.lastValue;let e=new Map(this.queryOffsets),t=this.currentQueryIndex,r=t*8;this.currentQueryIndex=0,this.queryOffsets.clear();let i=this.device.createCommandEncoder(zX);i.resolveQuerySet(this.querySet,0,t,this.resolveBuffer,0),i.copyBufferToBuffer(this.resolveBuffer,0,this.resultBuffer,0,r);let s=i.finish();if(kn(this.device,s),this.resultBuffer.mapState!=="unmapped")return this.lastValue;if(await this.resultBuffer.mapAsync(GPUMapMode.READ,0,r),this.isDisposed)return this.resultBuffer.mapState==="mapped"&&this.resultBuffer.unmap(),this.lastValue;let a=new BigUint64Array(this.resultBuffer.getMappedRange(0,r)),n={},o=[];for(let[u,h]of e){let d=u.match(/^(.*):f(\d+)$/),c=parseInt(d[2]);o.includes(c)===!1&&o.push(c),n[c]===void 0&&(n[c]=0);let m=a[h],g=a[h+1],y=Number(g-m)/1e6;this.timestamps.set(u,y),n[c]+=y}let l=n[o[o.length-1]];return this.resultBuffer.unmap(),this.lastValue=l,this.frames=o,l}catch(e){return Ce("Error resolving queries:",e),this.resultBuffer.mapState==="mapped"&&this.resultBuffer.unmap(),this.lastValue}}async dispose(){if(!this.isDisposed){if(this.isDisposed=!0,this.pendingResolve)try{await this.pendingResolve}catch(e){Ce("Error waiting for pending resolve:",e)}if(this.resultBuffer&&this.resultBuffer.mapState==="mapped")try{this.resultBuffer.unmap()}catch(e){Ce("Error unmapping buffer:",e)}this.querySet&&(this.querySet.destroy(),this.querySet=null),this.resolveBuffer&&(this.resolveBuffer.destroy(),this.resolveBuffer=null),this.resultBuffer&&(this.resultBuffer.destroy(),this.resultBuffer=null),this.queryOffsets.clear(),this.pendingResolve=null}}},GX=class{constructor(){this.label="",this.timestampWrites=void 0}reset(){this.label="",this.timestampWrites=void 0}},Oy=class{constructor(){this.view=null,this.depthLoadOp=void 0,this.depthStoreOp=void 0,this.depthClearValue=void 0,this.depthReadOnly=!1,this.stencilLoadOp=void 0,this.stencilStoreOp=void 0,this.stencilClearValue=0,this.stencilReadOnly=!1}reset(){this.view=null,this.depthLoadOp=void 0,this.depthStoreOp=void 0,this.depthClearValue=void 0,this.depthReadOnly=!1,this.stencilLoadOp=void 0,this.stencilStoreOp=void 0,this.stencilClearValue=0,this.stencilReadOnly=!1}},WX=class{constructor(){this.querySet=null,this.beginningOfPassWriteIndex=void 0,this.endOfPassWriteIndex=void 0}reset(){this.querySet=null,this.beginningOfPassWriteIndex=void 0,this.endOfPassWriteIndex=void 0}},Xa={r:0,g:0,b:0,a:1},Ks=new Wd,_s=new sm,Uy=new GX,cm=new bB,zy=new dB,Vy=new WX,Sa=new Fy,On=new Fy,Nr=new a_,Ro=new cB,jX=class extends Y3{constructor(e={}){super(e),this.isWebGPUBackend=!0,this.parameters.alpha=e.alpha===void 0?!0:e.alpha,this.parameters.requiredLimits=e.requiredLimits===void 0?{}:e.requiredLimits,this.compatibilityMode=null,this.device=null,this.defaultRenderPassdescriptor=null,this.utils=new uX(this),this.attributeUtils=new IX(this),this.bindingUtils=new LX(this),this.capabilities=new kX(this),this.pipelineUtils=new UX(this),this.textureUtils=new bX(this),this.occludedResolveCache=new Map;let t=typeof navigator>"u"?!0:/Android/.test(navigator.userAgent)===!1;this._compatibility={[fu.TEXTURE_COMPARE]:t}}async init(e){await super.init(e);let t=this.parameters,r;if(t.device===void 0){let i={powerPreference:t.powerPreference,featureLevel:"compatibility",xrCompatible:e.xr.enabled},s=typeof navigator<"u"?await navigator.gpu.requestAdapter(i):null;if(s===null)throw new Error("THREE.WebGPUBackend: Unable to create WebGPU adapter.");let a=Object.values(Py),n=[];for(let l of a)s.features.has(l)&&n.push(l);let o={requiredFeatures:n,requiredLimits:t.requiredLimits};r=await s.requestDevice(o)}else r=t.device;this.compatibilityMode=!r.features.has("core-features-and-limits"),this.compatibilityMode&&(e._samples=0),r.lost.then(i=>{if(i.reason==="destroyed")return;let s={api:"WebGPU",message:i.message||"Unknown reason",reason:i.reason||null,originalEvent:i};e.onDeviceLost(s)}),r.onuncapturederror=i=>{let s=i.error,a=s&&s.constructor?s.constructor.name:"GPUError",n=s&&s.message||"Unknown uncaptured GPU error";e.onError({api:"WebGPU",type:a,message:n,originalEvent:i})},this.device=r,this.trackTimestamp=this.trackTimestamp&&this.hasFeature(Py.TimestampQuery),this.updateSize()}setXRRenderTargetTextures(e,t,r=null){this.set(e.texture,{texture:t,format:t.format,externalTexture:!0,xrViewDescriptors:r,initialized:!0})}get context(){let e=this.renderer.getCanvasTarget(),t=this.get(e),r=t.context;if(r===void 0){let i=this.parameters;e.isDefaultCanvasTarget===!0&&i.context!==void 0?r=i.context:r=e.domElement.getContext("webgpu"),"setAttribute"in e.domElement&&e.domElement.setAttribute("data-engine","three.js r185 webgpu");let s=i.alpha?"premultiplied":"opaque",a=i.outputType===Dt?"extended":"standard";r.configure({device:this.device,format:this.utils.getPreferredCanvasFormat(),usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC,alphaMode:s,toneMapping:{mode:a}}),t.context=r}return r}get coordinateSystem(){return da}get hasTimestamp(){return!0}async getArrayBufferAsync(e,t=null,r=0,i=-1){return await this.attributeUtils.getArrayBufferAsync(e,t,r,i)}getContext(){return this.context}_getDefaultRenderPassDescriptor(){let e=this.renderer,t=e.getCanvasTarget(),r=this.get(t),i=e.currentSamples,s=r.descriptor;if(s===void 0||r.samples!==i){if(s=new nm,s.colorAttachments.push(new am),e.depth===!0||e.stencil===!0){let o=new Oy;o.view=this.textureUtils.getDepthBuffer(e.depth,e.stencil).createView(),s.depthStencilAttachment=o}let n=s.colorAttachments[0];i>0?n.view=this.textureUtils.getColorBuffer().createView():n.resolveTarget=void 0,r.descriptor=s,r.samples=i}let a=s.colorAttachments[0];return i>0?a.resolveTarget=this.context.getCurrentTexture().createView():a.view=this.context.getCurrentTexture().createView(),s}_isRenderCameraDepthArray(e){let t=e.camera;return e.depthTexture&&e.depthTexture.isArrayTexture===!0&&t!==null&&t.isArrayCamera===!0}_hasExternalTexture(e){let t=e.textures;if(t===null)return!1;for(let r=0;r1)if(c===!0){let b=e.camera.cameras;for(let v=0;v0&&(t.currentOcclusionQuerySet&&t.currentOcclusionQuerySet.destroy(),t.currentOcclusionQueryBuffer&&t.currentOcclusionQueryBuffer.destroy(),t.currentOcclusionQuerySet=t.occlusionQuerySet,t.currentOcclusionQueryBuffer=t.occlusionQueryBuffer,t.currentOcclusionQueryObjects=t.occlusionQueryObjects,cm.label=`occlusionQuerySet_${e.id}`,cm.type="occlusion",cm.count=i,s=r.createQuerySet(cm),cm.reset(),t.occlusionQuerySet=s,t.occlusionQueryIndex=0,t.occlusionQueryObjects=new Array(i),t.lastOcclusionObject=null);let a;e.textures===null?a=this._getDefaultRenderPassDescriptor():a=this._getRenderPassDescriptor(e,{loadOp:Kt.Load}),this.initTimestampQuery(un.RENDER,this.getTimestampUID(e),a),a.occlusionQuerySet=s;let n=a.depthStencilAttachment;if(e.textures!==null){let l=a.colorAttachments;for(let u=0;u0&&t.currentPass.executeBundles(t.renderBundles),r>t.occlusionQueryIndex&&t.currentPass.endOcclusionQuery();let i=t.encoder;if(this._isRenderCameraDepthArray(e)===!0){let s=[];for(let a=0;a0){let s=r*8,a=this.occludedResolveCache.get(s);a===void 0&&(Ks.size=s,Ks.usage=GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC,a=this.device.createBuffer(Ks),Ks.reset(),this.occludedResolveCache.set(s,a)),Ks.size=s,Ks.usage=GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ;let n=this.device.createBuffer(Ks);Ks.reset(),t.encoder.resolveQuerySet(t.occlusionQuerySet,0,r,a,0),t.encoder.copyBufferToBuffer(a,0,n,0,s),t.occlusionQueryBuffer=n,this.resolveOccludedAsync(e)}if(kn(this.device,t.encoder.finish()),e.textures!==null){let s=e.textures;for(let a=0;am&&(s[0]=Math.min(c,m),s[1]=Math.ceil(c/m)),a.dispatchSize=s}s=a.dispatchSize}o.dispatchWorkgroups(s[0],s[1]||1,s[2]||1)}finishCompute(e){let t=this.get(e);t.passEncoderGPU.end(),kn(this.device,t.cmdEncoderGPU.finish())}_draw(e,t,r,i,s,a,n,o,l){let{object:u,material:h,context:d}=e,c=e.getIndex(),m=c!==null;l.pipeline!==i&&(o.setPipeline(i),l.pipeline=i);let g=l.bindingGroups;for(let y=0,b=s.length;y65535?4:2);for(let T=0;T0){let d=this.get(e.camera),c=e.camera.cameras,m=e.getBindingGroup("cameraIndex");if(d.indexesGPU===void 0||d.indexesGPU.length!==c.length){let y=this.get(m),b=[],v=new Uint32Array([0,0,0,0]);for(let S=0,T=c.length;S(Ue("WebGPURenderer: WebGPU is not available, running under WebGL2 backend."),new eB(e)));let r=new t(e);super(r,e),this.library=new $X,this.isWebGPURenderer=!0,typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}},TB=class{constructor(e,t=Ve(0,0,1,1)){this.renderer=e,this.outputNode=t,this.outputColorTransform=!0,this.needsUpdate=!0;let r=new Pt;r.name="RenderPipeline",this._quadMesh=new Wa(r),this._quadMesh.name="Render Pipeline",this._context=null,this._toneMapping=e.toneMapping,this._outputColorSpace=e.outputColorSpace}render(){let e=this.renderer;this._update(),this._context.onBeforeRenderPipeline!==null&&this._context.onBeforeRenderPipeline();let t=e.toneMapping,r=e.outputColorSpace;e.toneMapping=eo,e.outputColorSpace=Gt.workingColorSpace;let i=e.xr.enabled;e.xr.enabled=!1,this._quadMesh.render(e),e.xr.enabled=i,e.toneMapping=t,e.outputColorSpace=r,this._context.onAfterRenderPipeline!==null&&this._context.onAfterRenderPipeline()}get context(){return this._context}dispose(){this._quadMesh.material.dispose()}_update(){if(this._toneMapping!==this.renderer.toneMapping&&(this._toneMapping=this.renderer.toneMapping,this.needsUpdate=!0),this._outputColorSpace!==this.renderer.outputColorSpace&&(this._outputColorSpace=this.renderer.outputColorSpace,this.needsUpdate=!0),this.needsUpdate===!0){let e=this._toneMapping,t=this._outputColorSpace,r={renderPipeline:this,onBeforeRenderPipeline:null,onAfterRenderPipeline:null},i=this.outputNode;this.outputColorTransform===!0?(i=i.context(r),i=_0(i,e,t)):(r.toneMapping=e,r.outputColorSpace=t,i=i.context(r)),this._context=r,this._quadMesh.material.fragmentNode=i,this._quadMesh.material.needsUpdate=!0,this.needsUpdate=!1}}async renderAsync(){Et('RenderPipeline: "renderAsync()" has been deprecated. Use "render()" and "await renderer.init();" when creating the renderer.'),await this.renderer.init(),this.render()}},YX=class extends TB{constructor(e,t){Et('PostProcessing: "PostProcessing" has been renamed to "RenderPipeline". Please update your code to use "THREE.RenderPipeline" instead.'),super(e,t)}},d_=class extends ji{constructor(e=1,t=1,r=1){super(),this.isArrayTexture=!1,this.image={width:e,height:t,depth:r},this.magFilter=lr,this.minFilter=lr,this.wrapR=Ti,this.isStorageTexture=!0,this.is3DTexture=!0}setSize(e,t,r){(this.image.width!==e||this.image.height!==t||this.image.depth!==r)&&(this.image.width=e,this.image.height=t,this.image.depth=r,this.dispose())}},ZX=M.BRDF_GGX,JX=M.BRDF_Lambert,QX=M.BasicPointShadowFilter,KX=M.BasicShadowFilter,e$=M.Break,t$=M.Const,r$=M.Continue,i$=M.DFGLUT,s$=M.D_GGX,a$=M.Discard,n$=M.EPSILON,o$=M.F_Schlick,Ir=M.Fn,l$=M.INFINITY,pm=M.If,Gy=M.Loop,u$=M.NodeAccess,h$=M.NodeShaderStage,d$=M.NodeType,c$=M.NodeUpdateType,p$=M.PCFShadowFilter,m$=M.PCFSoftShadowFilter,f$=M.PI,g$=M.PI2,y$=M.TWO_PI,x$=M.HALF_PI,v$=M.PointShadowFilter,b$=M.Return,T$=M.Schlick_to_F0,S$=M.ShaderNode,_$=M.Stack,w$=M.Switch,M$=M.TBNViewMatrix,N$=M.VSMShadowFilter,A$=M.V_GGX_SmithCorrelated,C$=M.Var,R$=M.VarIntent,$a=M.abs,E$=M.acesFilmicToneMapping,P$=M.acos,B$=M.acosh,Wy=M.add,I$=M.addMethodChaining,F$=M.addNodeElement,L$=M.agxToneMapping,k$=M.all,D$=M.alphaT,O$=M.ambientOcclusion,U$=M.and,z$=M.anisotropy,V$=M.anisotropyB,G$=M.anisotropyT,W$=M.any,j$=M.append,H$=M.array,X$=M.asin,$$=M.asinh,q$=M.assign,Y$=M.atan,Z$=M.atanh,J$=M.atomicAdd,Q$=M.atomicAnd,K$=M.atomicFunc,eq=M.atomicLoad,tq=M.atomicMax,rq=M.atomicMin,iq=M.atomicOr,sq=M.atomicStore,aq=M.atomicSub,nq=M.atomicXor,oq=M.attenuationColor,lq=M.attenuationDistance,uq=M.attribute,hq=M.attributeArray,dq=M.backgroundBlurriness,cq=M.backgroundIntensity,pq=M.backgroundRotation,mq=M.batch,fq=M.bentNormalView,gq=M.billboarding,yq=M.bitAnd,xq=M.bitNot,vq=M.bitOr,bq=M.bitXor,Tq=M.bitangentGeometry,Sq=M.bitangentLocal,_q=M.bitangentView,wq=M.bitangentWorld,Mq=M.bitcast,Nq=M.blendBurn,Aq=M.blendColor,Cq=M.blendDodge,Rq=M.blendOverlay,Eq=M.blendScreen,Pq=M.blur,Bq=M.bool,Iq=M.buffer,Fq=M.bufferAttribute,Lq=M.bumpMap,kq=M.builtin,Dq=M.builtinAOContext,Oq=M.builtinShadowContext,Uq=M.bvec2,zq=M.bvec3,Vq=M.bvec4,Gq=M.bypass,Wq=M.cache,jq=M.call,Hq=M.cameraFar,Xq=M.cameraIndex,$q=M.cameraNear,qq=M.cameraNormalMatrix,Yq=M.cameraPosition,Zq=M.cameraProjectionMatrix,Jq=M.cameraProjectionMatrixInverse,Qq=M.cameraViewMatrix,Kq=M.cameraViewport,eY=M.cameraWorldMatrix,tY=M.cbrt,rY=M.cdl,iY=M.ceil,sY=M.checker,aY=M.cineonToneMapping,SB=M.clamp,nY=M.clearcoat,oY=M.clearcoatNormalView,lY=M.clearcoatRoughness,uY=M.clipSpace,hY=M.code,dY=M.color,cY=M.colorSpaceToWorking,pY=M.colorToDirection,mY=M.compute,fY=M.computeKernel,gY=M.computeSkinning,yY=M.context,xY=M.convert,vY=M.convertColorSpace,Ju=M.convertToTexture,bY=M.countLeadingZeros,TY=M.countOneBits,SY=M.countTrailingZeros,_Y=M.cos,wY=M.cosh,MY=M.cross,NY=M.cubeTexture,AY=M.cubeTextureBase,CY=M.dFdx,RY=M.dFdy,EY=M.dashSize,PY=M.debug,BY=M.decrement,IY=M.decrementBefore,FY=M.defaultBuildStages,LY=M.defaultShaderStages,kY=M.defined,DY=M.degrees,OY=M.deltaTime,UY=M.densityFog,zY=M.densityFogFactor,VY=M.depth,GY=M.depthPass,WY=M.determinant,jY=M.difference,HY=M.diffuseColor,XY=M.directPointLight,$Y=M.directionToColor,qY=M.directionToFaceDirection,YY=M.dispersion,ZY=M.distance,JY=M.div,QY=M.dot,KY=M.drawIndex,eZ=M.dynamicBufferAttribute,tZ=M.element,rZ=M.emissive,iZ=M.equal,sZ=M.equirectDirection,aZ=M.equirectUV,_B=M.exp,c_=M.exp2,nZ=M.exponentialHeightFogFactor,oZ=M.expression,lZ=M.faceDirection,uZ=M.faceForward,hZ=M.faceforward,yt=M.float,dZ=M.floatBitsToInt,cZ=M.floatBitsToUint,Zd=M.floor,pZ=M.fog,wB=M.fract,mZ=M.frameGroup,fZ=M.frameId,gZ=M.frontFacing,yZ=M.fwidth,xZ=M.gain,vZ=M.gapSize,bZ=M.getConstNodeType,TZ=M.getCurrentStack,SZ=M.getDirection,_Z=M.getDistanceAttenuation,wZ=M.getGeometryRoughness,MZ=M.getNormalFromDepth,NZ=M.interleavedGradientNoise,AZ=M.vogelDiskSample,CZ=M.getParallaxCorrectNormal,RZ=M.getRoughness,EZ=M.getScreenPosition,PZ=M.getShIrradianceAt,BZ=M.getShadowMaterial,IZ=M.getShadowRenderObjectFunction,FZ=M.getTextureIndex,p_=M.getViewPosition,LZ=M.globalId,kZ=M.glsl,DZ=M.glslFn,OZ=M.grayscale,UZ=M.greaterThan,zZ=M.greaterThanEqual,VZ=M.hash,GZ=M.highpModelNormalViewMatrix,WZ=M.highpModelViewMatrix,jZ=M.hue,HZ=M.increment,XZ=M.incrementBefore,$Z=M.instance,qZ=M.instanceIndex,YZ=M.instancedArray,ZZ=M.instancedBufferAttribute,JZ=M.instancedDynamicBufferAttribute,QZ=M.instancedMesh,Eo=M.int,KZ=M.intBitsToFloat,eJ=M.inverse,tJ=M.inverseSqrt,rJ=M.inversesqrt,iJ=M.invocationLocalIndex,sJ=M.invocationSubgroupIndex,aJ=M.ior,nJ=M.iridescence,oJ=M.iridescenceIOR,lJ=M.iridescenceThickness,ss=M.ivec2,uJ=M.ivec3,hJ=M.ivec4,dJ=M.js,cJ=M.label,pJ=M.length,mJ=M.lengthSq,fJ=M.lessThan,gJ=M.lessThanEqual,yJ=M.lightPosition,xJ=M.lightProjectionUV,vJ=M.lightShadowMatrix,bJ=M.lightTargetDirection,TJ=M.lightTargetPosition,SJ=M.lightViewPosition,_J=M.lightingContext,wJ=M.lights,MJ=M.linearDepth,NJ=M.linearToneMapping,AJ=M.localId,CJ=M.log,RJ=M.log2,MB=M.logarithmicDepthToViewZ,kl=M.luminance,EJ=M.mat2,PJ=M.mat3,NB=M.mat4,BJ=M.matcapUV,IJ=M.materialAO,FJ=M.materialAlphaTest,LJ=M.materialAnisotropy,kJ=M.materialAnisotropyVector,DJ=M.materialAttenuationColor,OJ=M.materialAttenuationDistance,UJ=M.materialClearcoat,zJ=M.materialClearcoatNormal,VJ=M.materialClearcoatRoughness,GJ=M.materialColor,WJ=M.materialDispersion,jJ=M.materialEmissive,HJ=M.materialEnvIntensity,XJ=M.materialEnvRotation,$J=M.materialIOR,qJ=M.materialIridescence,YJ=M.materialIridescenceIOR,ZJ=M.materialIridescenceThickness,JJ=M.materialLightMap,QJ=M.materialLineDashOffset,KJ=M.materialLineDashSize,eQ=M.materialLineGapSize,tQ=M.materialLineScale,rQ=M.materialLineWidth,iQ=M.materialMetalness,sQ=M.materialNormal,aQ=M.materialOpacity,nQ=M.materialPointSize,oQ=M.materialReference,lQ=M.materialReflectivity,uQ=M.materialRefractionRatio,hQ=M.materialRotation,dQ=M.materialRoughness,cQ=M.materialSheen,pQ=M.materialSheenRoughness,mQ=M.materialShininess,fQ=M.materialSpecular,gQ=M.materialSpecularColor,yQ=M.materialSpecularIntensity,xQ=M.materialSpecularStrength,vQ=M.materialThickness,bQ=M.materialTransmission,_t=M.max,TQ=M.maxMipLevel,SQ=M.mediumpModelViewMatrix,_Q=M.metalness,Ar=M.min,Dl=M.mix,wQ=M.mixElement,MQ=M.mod,NQ=M.modelDirection,AQ=M.modelNormalMatrix,CQ=M.modelPosition,RQ=M.modelRadius,EQ=M.modelScale,PQ=M.modelViewMatrix,BQ=M.modelViewPosition,IQ=M.modelViewProjection,FQ=M.modelWorldMatrix,LQ=M.modelWorldMatrixInverse,kQ=M.morphReference,DQ=M.mrt,OQ=M.mul,UQ=M.mx_aastep,zQ=M.mx_add,VQ=M.mx_atan2,GQ=M.mx_cell_noise_float,WQ=M.mx_contrast,jQ=M.mx_divide,HQ=M.mx_fractal_noise_float,XQ=M.mx_fractal_noise_vec2,$Q=M.mx_fractal_noise_vec3,qQ=M.mx_fractal_noise_vec4,YQ=M.mx_frame,ZQ=M.mx_heighttonormal,JQ=M.mx_hsvtorgb,QQ=M.mx_ifequal,KQ=M.mx_ifgreater,eK=M.mx_ifgreatereq,tK=M.mx_invert,rK=M.mx_modulo,iK=M.mx_multiply,sK=M.mx_noise_float,aK=M.mx_noise_vec3,nK=M.mx_noise_vec4,oK=M.mx_place2d,lK=M.mx_power,uK=M.mx_ramp4,hK=M.mx_ramplr,dK=M.mx_ramptb,cK=M.mx_rgbtohsv,pK=M.mx_rotate2d,mK=M.mx_rotate3d,fK=M.mx_safepower,gK=M.mx_separate,yK=M.mx_splitlr,xK=M.mx_splittb,vK=M.mx_srgb_texture_to_lin_rec709,bK=M.mx_subtract,TK=M.mx_timer,SK=M.mx_transform_uv,_K=M.mx_unifiednoise2d,wK=M.mx_unifiednoise3d,MK=M.mx_worley_noise_float,NK=M.mx_worley_noise_vec2,AK=M.mx_worley_noise_vec3,CK=M.negate,RK=M.negateOnBackSide,EK=M.neutralToneMapping,PK=M.nodeArray,BK=M.nodeImmutable,Un=M.nodeObject,IK=M.nodeObjectIntent,FK=M.nodeObjects,LK=M.nodeProxy,kK=M.nodeProxyIntent,DK=M.normalFlat,OK=M.normalGeometry,UK=M.normalLocal,zK=M.normalMap,VK=M.normalView,GK=M.normalViewGeometry,WK=M.normalWorld,jK=M.normalWorldGeometry,HK=M.normalize,XK=M.not,$K=M.notEqual,qK=M.numWorkgroups,YK=M.objectDirection,ZK=M.objectGroup,JK=M.objectPosition,QK=M.objectRadius,KK=M.objectScale,eee=M.objectViewPosition,tee=M.objectWorldMatrix,ree=M.OnBeforeObjectUpdate,iee=M.OnBeforeMaterialUpdate,see=M.OnObjectUpdate,aee=M.OnMaterialUpdate,nee=M.oneMinus,oee=M.or,lee=M.orthographicDepthToViewZ,uee=M.oscSawtooth,hee=M.oscSine,dee=M.oscSquare,cee=M.oscTriangle,pee=M.output,m_=M.outputStruct,mee=M.overloadingFn,fee=M.overrideNode,gee=M.overrideNodes,yee=M.packHalf2x16,xee=M.packSnorm2x16,vee=M.packUnorm2x16,bee=M.packNormalToRGB,Tee=M.parabola,See=M.parallaxDirection,_ee=M.parallaxUV,wee=M.parameter,Mee=M.pass,Qu=M.passTexture,Nee=M.pcurve,Aee=M.perspectiveDepthToViewZ,Cee=M.pmremTexture,Ree=M.pointShadow,Eee=M.pointUV,Pee=M.pointWidth,Bee=M.positionGeometry,Iee=M.positionLocal,Fee=M.positionPrevious,Lee=M.positionView,kee=M.positionViewDirection,Dee=M.positionWorld,Oee=M.positionWorldDirection,Uee=M.posterize,zee=M.pow,Vee=M.pow2,Gee=M.pow3,Wee=M.pow4,AB=M.premultiplyAlpha,mm=M.property,jee=M.radians,Hee=M.rand,Xee=M.range,$ee=M.rangeFog,qee=M.rangeFogFactor,Yee=M.reciprocal,Zee=M.reference,Jee=M.referenceBuffer,Qee=M.reflect,Kee=M.reflectVector,ete=M.reflectView,tte=M.reflector,rte=M.refract,ite=M.refractVector,ste=M.refractView,ate=M.reinhardToneMapping,nte=M.remap,ote=M.remapClamp,lte=M.renderGroup,ute=M.renderOutput,hte=M.rendererReference,dte=M.replaceDefaultUV,cte=M.rotate,pte=M.rotateUV,mte=M.roughness,fte=M.round,gte=M.rtt,yte=M.sRGBTransferEOTF,xte=M.sRGBTransferOETF,vte=M.sample,bte=M.sampler,Tte=M.samplerComparison,f_=M.saturate,Ste=M.saturation,_te=M.screen,wte=M.screenCoordinate,Mte=M.screenDPR,Nte=M.screenSize,Ate=M.screenUV,g_=M.select,Cte=M.setCurrentStack,Rte=M.setName,Ete=M.shaderStages,Pte=M.shadow,Bte=M.shadowPositionWorld,Ite=M.shapeCircle,Fte=M.sharedUniformGroup,Lte=M.sheen,kte=M.sheenRoughness,Dte=M.shiftLeft,Ote=M.shiftRight,Ute=M.shininess,zte=M.sign,Vte=M.sin,Gte=M.sinh,Wte=M.sinc,jte=M.skinning,y_=M.smoothstep,Hte=M.smoothstepElement,Xte=M.specularColor,$te=M.specularF90,qte=M.spherizeUV,Yte=M.split,Zte=M.spritesheetUV,CB=M.sqrt,Jte=M.stack,x_=M.step,Qte=M.stepElement,fm=M.storage,Kte=M.storageBarrier,ere=M.storageTexture,tre=M.storageTexture3D,v_=M.struct,rre=M.sub,ire=M.subgroupAdd,sre=M.subgroupAll,are=M.subgroupAnd,nre=M.subgroupAny,ore=M.subgroupBallot,lre=M.subgroupBroadcast,ure=M.subgroupBroadcastFirst,hre=M.subBuild,dre=M.subgroupElect,cre=M.subgroupExclusiveAdd,pre=M.subgroupExclusiveMul,mre=M.subgroupInclusiveAdd,fre=M.subgroupInclusiveMul,gre=M.subgroupIndex,yre=M.subgroupMax,xre=M.subgroupMin,vre=M.subgroupMul,bre=M.subgroupOr,Tre=M.subgroupShuffle,Sre=M.subgroupShuffleDown,_re=M.subgroupShuffleUp,wre=M.subgroupShuffleXor,Mre=M.subgroupSize,Nre=M.subgroupXor,Are=M.tan,Cre=M.tanh,Rre=M.tangentGeometry,Ere=M.tangentLocal,Pre=M.tangentView,Bre=M.tangentWorld,Ri=M.texture,Ire=M.texture3D,Fre=M.textureBarrier,Lre=M.textureBicubic,kre=M.textureBicubicLevel,Dre=M.textureCubeUV,Ps=M.textureLoad,jy=M.textureSize,Ore=M.textureLevel,Ure=M.textureStore,zre=M.thickness,Vre=M.time,Gre=M.toneMapping,Wre=M.toneMappingExposure,jre=M.toonOutlinePass,Hre=M.transformDirection,Xre=M.transformNormal,$re=M.transformNormalByInverseViewMatrix,qre=M.transformNormalByViewMatrix,Yre=M.transformNormalToView,Zre=M.transformedClearcoatNormalView,Jre=M.transformedNormalView,Qre=M.transformedNormalWorld,Kre=M.transmission,eie=M.transpose,tie=M.triNoise3D,rie=M.triplanarTexture,iie=M.triplanarTextures,sie=M.trunc,RB=M.uint,aie=M.uintBitsToFloat,Fr=M.uniform,Jd=M.uniformArray,nie=M.uniformCubeTexture,oie=M.uniformGroup,lie=M.uniformFlow,uie=M.uniformTexture,hie=M.unpackHalf2x16,die=M.unpackSnorm2x16,cie=M.unpackUnorm2x16,pie=M.unpackRGBToNormal,EB=M.unpremultiplyAlpha,mie=M.userData,_a=M.uv,fie=M.uvec2,gie=M.uvec3,yie=M.uvec4,xie=M.varying,vie=M.varyingProperty,nr=M.vec2,Hy=M.vec3,hr=M.vec4,bie=M.vectorComponents,Xy=M.velocity,Tie=M.vertexColor,Sie=M.vertexIndex,_ie=M.vertexStage,wie=M.vibrance,Mie=M.viewZToLogarithmicDepth,PB=M.viewZToOrthographicDepth,$y=M.viewZToPerspectiveDepth,Nie=M.viewZToReversedOrthographicDepth,Aie=M.viewZToReversedPerspectiveDepth,Cie=M.viewport,Rie=M.viewportCoordinate,Eie=M.viewportDepthTexture,Pie=M.viewportLinearDepth,Bie=M.viewportMipTexture,Iie=M.viewportOpaqueMipTexture,Fie=M.viewportResolution,Lie=M.viewportSafeUV,kie=M.viewportSharedTexture,Die=M.viewportSize,Oie=M.viewportTexture,Uie=M.viewportUV,zie=M.wgsl,Vie=M.wgslFn,Gie=M.workgroupArray,Wie=M.workgroupBarrier,jie=M.workgroupId,Hie=M.workingToColorSpace,Xie=M.xor,Jr=yM,Qd=Object.freeze({transmission:!0,absorption:!0,dispersion:!0,reflections:!0,frost:!0,crystals:!0,grain:!0,cutNormals:!0,surfaceBumps:!0,smudges:!1,micro:!1,ripples:!1,cracks:!1,scatter:!0,clearcoat:!0,shardNormals:!0,shardFrost:!0,shardTransmission:!0,shardReflections:!0,shardSparkle:!0,shardEdges:!0}),$ie=e=>`material${e[0].toUpperCase()}${e.slice(1)}`,qie={shape:{shape:"logo",size:1,tubeRatio:.28,deformAmplitude:0,deformFrequency:.3,segments:512,seed:7,offsetX:0,offsetY:.48,offsetZ:0,logo:{width:2.6,depth:.22,bevelThickness:.06,bevelSize:.05,bevelOffset:0,bevelSegments:13,cornerRadius:.03,curveSegments:58,creaseAngle:40,sdfRes:128}},ice:{ior:1.61,dispersion:.17,thicknessScale:.1,attenuationDistance:3.64,attenuationColor:"#525252",baseRoughness:.095,frost:{scale:1.05,threshold:.61,softness:.36,roughness:.73,diffuse:.57,crystalBump:.62,crystalScale:44},cracks:{largeScale:1.15,warp:.37,warpScale:2.2,coverage:.84,regionScale:1.35,regionCoverage:.52,veinScale:20,veinContrast:1,width:.0175,brightness:.41,darkness:1,refraction:.077,surfaceStrength:.67,steps:21,fineCracks:!0,fineScale:20,fineAmount:.96,fineCoverage:.23,fineNearLarge:1},smudges:{amount:1,coverage:.29,maskScale:3.1,anisotropy:5.5,roughness:.91,whiteness:.5,scale:1.6},bumps:{microBump:1,microScale:70,microCoverage:.4,rippleBump:.45,rippleScale:2.5,maskScale:3.6},crumbleGlow:.16,edgeWhiteness:.5,clearcoat:.15,clearcoatRoughness:.415,envIntensity:1.45,specularIntensity:1.28,interiorScatter:.32},erosion:{resolution:"192",brushRadius:.465,brushSoftness:.23,brushStrength:5.6,brushSpeedRef:3.7,brushNoise:.4,brushNoiseScale:16,throughDepth:.84,cellSnap:1,breakCellScale:2.2,crumbleRate:5.35,crumbleCrackBias:5.7,crumbleDuration:.35,cutThreshold:.46,cutSoftness:.045,edgeWidth:.37,interiorSteps:64,interiorFrost:.1,edgeInset:.175,edgeBump:.48,edgeBumpScale:66},powder:{particleCount:"100k",amount:.09,grainSizeMultiplier:1.5,nearSurfaceFraction:1,nearSurfaceDepth:.5,grainSizes:{tinyDustRatio:.2,smallGrainRatio:.22,mediumClumpRatio:.07,tinyDustSize:.0055,smallGrainSize:.011,mediumClumpSize:.022,largeFragmentSize:.075,sizeJitter:1},grainVariants:6,facetedGrains:!1,minPixelSize:.65,ejectSpeed:.8,minEjectSpeed:.66,ejectSpread:0,ejectTurbulence:0,backwardRatio:.25,clumpSpeedJitter:1,drag:.8,gravity:.895,turbulence:2.4,turbulenceScale:5.85,turbulenceDecay:2.58,clumpCohesion:10,clumpCount:500,settleTime:2.65,settledDrift:.01,tumble:2.5,baseTone:"#999999",wrap:0,fragments:{translucency:1,throughTint:"#212121",fresnelPower:5.2,roughness:0,clearcoat:0,specular:.3,sparkle:.2,sparkleFraction:.6,sparkleSpread:1.08},sprites:{enabled:!0,sizeScale:1.4,tilt:30,normalStrength:.1,frostFromAtlas:1,frostBoost:.15,frostRoughness:.1,edgeLight:3,alphaCut:.6,seeThrough:1},repelFromObject:!0,repelStrength:24,repelRange:1.49,repelRadial:0,repelRadialRange:1.6,maxSpeed:8,lostRadius:30,densityShadowStrength:.6,densityAOStrength:0,densityGrid:"64",densityExtent:10,hazeIntensity:0,hazeSteps:8,inheritRotation:!0,inheritTime:400,strayCount:40,straySpeed:.06,fragmentShadowMap:!1},healing:{healDelay:0,returnAfter:3,waveTime:0,waveReach:1,waveJitter:.3,returnMode:"spring",returnSpring:40,returnDamping:.9,returnRamp:3,returnDrag:.85,returnMaxSpeed:13,landRadius:.2,returnDuration:1,returnCurve:.27,cellRestore:60,cellStragglers:1,growFromEdges:!0,breakup:1,breakupScale:40,alignToSurface:1,alignDistance:.52,landedFade:2,landShrink:.3,depositRadius:3,ghostReturnDistance:0,ghostFlightFraction:.45,healRate:3,healGap:.5,fallbackHeal:.275,refrostTime:4.9,refrostStrength:.17,resetFade:50},fracture:{chunks:600,seed:3,hitPadding:.5,eject:{speed:2.6,spread:.7,spin:5,jitter:.45,backwardRatio:.2},motion:{drag:1.3,angularDrag:1.6,gravity:.3,turbulence:1.2,turbulenceScale:1.4,maxSpeed:10},return:{returnAfter:1.4,returnJitter:.9,idleDelay:.6,spring:14,damping:1,ramp:.5,rotationRate:6,snapDistance:.015},caps:{frost:.85,roughness:.8,grain:.5,darken:.15}},lighting:{key:{color:"#ffffff",intensity:4.6,elevation:80.5,azimuth:72,size:.91,hoverBoost:.3},fill:.19,fillColor:"#ff0000",fillGroundColor:"#d11f1f",rim:3.35,rimColor:"#f0f8ff",rimElevation:89,shadow:{intensity:0,softness:6,samples:1,mapSize:"1024",bias:-6e-4},sway:{amplitude:.15,period:9.5},backdrop:{top:"#2a2a2a",mid:"#050505",bottom:"#030303",centerX:.5,centerY:1.5,radius:.78,falloff:4,noise:3},envSoftbox:.8,envRim:1.3,envFill:.12},camera:{fov:41,distance:9.05,height:1.2,lookAtY:-.15,parallaxRange:1.9,parallaxSmoothing:3,rotateYaw:16.5,rotatePitch:10,rotationLag:.63,baseYaw:0,basePitch:0,idleDelay:4,idleAmplitude:4,idlePeriod:24},post:{dof:{enabled:!1,focusBias:-.43,aperture:4,range:12},bloom:{threshold:3,intensity:.045,radius:.235},monochrome:.52,tonemap:"agx",exposure:1.08,contrast:1.285,blackLift:.01,vignette:{strength:.325,softness:1.175,radius:1.245},grain:{strength:0,size:1,speed:0,shadowWeight:.28},dither:!0,aaMode:"traa",pixelRatioCap:2},performance:{idleSkip:!0,adaptiveSteps:!0,voronoiCells:"27",hazeResolution:"quarter",turbulence:"fast",gpuTimers:!0},debug:{showErosionSlice:!1,erosionSliceZ:.5,showDensityGrid:!1,showHitPoints:!1,colorByState:!1,colorBySize:!1,colorByAge:!1,wireframe:!1,freeze:!1,stats:!0,forceStroke:!1},hero4:{frame:{sameAsMain:!1,distance:13.45,height:1.2,lookAtX:0,lookAtY:.05,fov:29.5,objectX:0,objectY:1.26,baseYaw:0,basePitch:0,rotateYaw:40,rotatePitch:45,parallaxRange:15},type:{line1:"Hard to break.",line2:"Easy to remember.",weight:500,letterSpacing:-.04,lineHeight:.92,lineFrac:.16,sx:0,sy:-.125,depth:1.3,align:"center",uppercase:!1,color:"#f2f2f2"},copy:{brand:"Frost",nav:"Manifesto, Work",cta:"Say hello",wordmark:"Frost",tagline:"A symbol that breaks and returns.",subtitle:"An identity system built to take pressure. Break it, watch it come back, and know exactly what holds.",cta1:"Start a project",cta2:"See the work",cue:"Scroll"},wordmark:{show:!1,wordmarkVw:2.4,weight:600,letterSpacing:.42,sy:-.34},subtitle:{show:!0,sy:-.56,size:15,maxWidth:42},ctas:{show:!0,sy:-.72,gap:14},trigger:{autoSweep:!1,first:2,interval:10,duration:.7,radius:.5,strength:14,cursorErodes:!0,clickResets:!0},style:{textColor:"#f2f2f2",mutedAlpha:.5,showStats:!1}}},wa=(e,t)=>({type:"select",options:t,default:e}),BB=typeof location<"u"&&new URLSearchParams(location.search).has("lite"),Yie=["torus","sphere","roundedBox","pyramid","icosahedron","logo"],b_={shape:wa("torus",Yie),size:[1,.5,1.6,.01],tubeRatio:[.45,.2,.7,.005],deformAmplitude:[.045,0,.2,.001],deformFrequency:[1.1,.3,4,.05],segments:[256,64,512,8],seed:[7,0,999,1],offsetX:[0,-5,5,.01],offsetY:[0,-4,4,.01],offsetZ:[0,-4,4,.01],logo:{_collapsed:!0,width:[2.6,.8,5,.05],depth:[.22,.02,1,.005],bevelThickness:[.06,0,.3,.002],bevelSize:[.05,0,.3,.002],bevelOffset:[0,-.1,.1,.002],bevelSegments:[5,1,16,1],cornerRadius:[.03,0,.15,.001],curveSegments:[24,2,64,1],creaseAngle:[40,0,180,1],sdfRes:[64,32,128,8]}},gm={ior:[1.36,1,2,.005],dispersion:[0,0,.3,.005],thicknessScale:[1,.1,3,.01],attenuationDistance:[.9,.05,5,.01],attenuationColor:"#cfd2d4",baseRoughness:[.05,0,.5,.005],frost:{scale:[1.6,.2,6,.05],threshold:[.5,0,1,.01],softness:[.28,.01,1,.01],roughness:[.65,0,1,.01],diffuse:[.55,0,1,.01],crystalBump:[.12,0,1,.01],crystalScale:[28,4,80,1]},cracks:{largeScale:[1.6,.3,8,.05],warp:[.45,0,1.5,.01],warpScale:[1.4,.2,6,.05],coverage:[.55,0,1,.01],regionScale:[.8,.1,4,.05],regionCoverage:[.7,0,1,.01],veinScale:[5,1,20,.25],veinContrast:[.7,0,1,.01],width:[.004,5e-4,.02,5e-4],brightness:[.4,0,3,.01],darkness:[.5,0,1,.01],refraction:[.02,0,.1,.001],surfaceStrength:[.35,0,1,.01],steps:[14,4,32,1],fineCracks:!0,fineScale:[5.5,2,20,.1],fineAmount:[.45,0,1,.01],fineCoverage:[.35,0,1,.01],fineNearLarge:[.75,0,1,.01]},smudges:{amount:[.6,0,1,.01],coverage:[.55,0,1,.01],maskScale:[1.2,.1,6,.05],anisotropy:[6,1,20,.5],roughness:[.35,0,1,.01],whiteness:[.08,0,.5,.005],scale:[3.2,.5,10,.1]},bumps:{microBump:[.25,0,1,.005],microScale:[60,10,200,1],microCoverage:[.6,0,1,.01],rippleBump:[.3,0,1,.01],rippleScale:[9,2,30,.5],maskScale:[1.5,.1,6,.05]},crumbleGlow:[.15,0,2,.01],edgeWhiteness:[.5,0,1,.01],clearcoat:[.3,0,1,.01],clearcoatRoughness:[.08,0,1,.005],envIntensity:[.55,0,3,.01],specularIntensity:[1,0,2,.01],interiorScatter:[.25,0,1,.01]},T_={resolution:wa("128",["64","96","128","192"]),brushRadius:[.28,.05,.8,.005],brushSoftness:[.5,0,1,.01],brushStrength:[2.2,.1,8,.05],brushSpeedRef:[3,.2,12,.1],brushNoise:[.55,0,1,.01],brushNoiseScale:[9,2,30,.5],throughDepth:[1,0,1,.01],cellSnap:[.85,0,1,.01],breakCellScale:[3,.5,8,.1],crumbleRate:[1.6,0,6,.05],crumbleCrackBias:[2.5,0,6,.05],crumbleDuration:[.5,0,2,.01],cutThreshold:[.7,.3,.98,.01],cutSoftness:[.04,.005,.3,.005],edgeWidth:[.35,.05,.8,.01],interiorSteps:[24,8,64,1],interiorFrost:[0,0,1,.01],edgeInset:[.06,0,.3,.005],edgeBump:[.6,0,2,.01],edgeBumpScale:[55,10,160,1]},ym={particleCount:wa("1M",["100k","250k","500k","1M","2M"]),amount:[.3,.02,1,.01],grainSizeMultiplier:[1,.2,4,.05],nearSurfaceFraction:[.6,0,1,.01],nearSurfaceDepth:[.2,.05,.5,.01],grainSizes:{tinyDustRatio:[.7,0,1,.01],smallGrainRatio:[.22,0,1,.01],mediumClumpRatio:[.07,0,1,.01],tinyDustSize:[.0055,.001,.03,5e-4],smallGrainSize:[.011,.002,.05,5e-4],mediumClumpSize:[.022,.005,.1,.001],largeFragmentSize:[.05,.01,.2,.001],sizeJitter:[.45,0,1,.01]},grainVariants:[5,1,6,1],facetedGrains:!1,minPixelSize:[1.5,0,4,.05],ejectSpeed:[1.1,0,4,.01],minEjectSpeed:[1,0,4,.01],ejectSpread:[.5,0,3,.01],ejectTurbulence:[.8,0,4,.01],backwardRatio:[.25,0,1,.01],clumpSpeedJitter:[.5,0,1,.01],drag:[1.4,0,8,.01],gravity:[.12,0,2,.005],turbulence:[.9,0,4,.01],turbulenceScale:[1.8,.2,8,.05],turbulenceDecay:[.6,.05,4,.01],clumpCohesion:[2.4,0,10,.05],clumpCount:[24e3,500,1e5,500],settleTime:[3.2,.3,12,.05],settledDrift:[.012,0,.1,.001],tumble:[2.5,0,12,.05],baseTone:"#dcdcdc",wrap:[.45,0,1,.01],fragments:{translucency:[.6,0,1,.01],throughTint:"#aeb6bb",fresnelPower:[3,.5,8,.1],roughness:[.32,0,1,.01],clearcoat:[.6,0,1,.01],specular:[1,0,3,.01],sparkle:[.6,0,3,.01],sparkleFraction:[.35,0,1,.01],sparkleSpread:[.5,0,1.5,.01]},sprites:{enabled:!0,sizeScale:[1.4,.3,4,.05],tilt:[30,0,70,1],normalStrength:[1,0,2.5,.05],frostFromAtlas:[1,0,1,.01],frostBoost:[.35,0,1.5,.01],frostRoughness:[.7,0,1,.01],edgeLight:[.6,0,3,.01],alphaCut:[.2,.05,.6,.01],seeThrough:[0,0,1,.01]},repelFromObject:!1,repelStrength:[6,0,30,.1],repelRange:[.35,.02,2,.01],repelRadial:[12,0,60,.5],repelRadialRange:[1.6,1,4,.05],maxSpeed:[8,1,40,.1],lostRadius:[30,5,100,1],densityShadowStrength:[.75,0,2,.01],densityAOStrength:[.55,0,2,.01],densityGrid:wa("64",["32","48","64"]),densityExtent:[4.2,2,10,.1],hazeIntensity:[.22,0,1.5,.005],hazeSteps:[28,8,64,1],inheritRotation:!0,inheritTime:[220,0,1500,10],strayCount:[40,0,200,1],straySpeed:[.06,0,.5,.005],fragmentShadowMap:!0},IB={healDelay:[3.5,0,12,.1],returnAfter:[3,0,20,.1],waveTime:[2,0,8,.05],waveReach:[3,.2,10,.1],waveJitter:[.6,0,3,.05],returnMode:wa("spring",["spring","path"]),returnSpring:[6,.5,40,.1],returnDamping:[.9,.2,2,.01],returnRamp:[.6,0,3,.05],returnDrag:[.25,0,1,.01],returnMaxSpeed:[12,1,60,.5],landRadius:[.03,.005,.2,.005],returnDuration:[2.4,.2,8,.05],returnCurve:[.35,0,1.5,.01],cellRestore:[30,0,60,.5],cellStragglers:[0,0,20,1],growFromEdges:!0,breakup:[.7,0,1,.01],breakupScale:[10,1,40,.5],alignToSurface:[1,0,1,.01],alignDistance:[.6,.05,3,.01],alignCurve:[1,.2,4,.05],landedFade:[.25,0,2,.01],landShrink:[0,0,.3,.005],depositRadius:[.5,0,3,.25],ghostReturnDistance:[0,0,1.5,.01],ghostFlightFraction:[.45,.1,1,.01],healRate:[.6,.02,3,.01],healGap:[.04,0,.5,.01],fallbackHeal:[.15,0,.5,.005],refrostTime:[4,.2,12,.1],refrostStrength:[.3,0,1,.01],resetFade:[400,50,2e3,10]},FB={key:{color:"#ffffff",intensity:[3.2,0,12,.05],elevation:[62,10,89,.5],azimuth:[18,-90,90,.5],size:[1,.2,3,.01],hoverBoost:[.06,0,.3,.005]},fill:[.18,0,1.5,.005],fillColor:"#ffffff",fillGroundColor:"#262626",rim:[.9,0,5,.01],rimColor:"#ffffff",rimElevation:[55,0,89,.5],shadow:{intensity:[1,0,1,.01],softness:[6,0,24,.25],samples:[12,1,32,1],mapSize:wa("2048",["1024","2048","4096"]),bias:[-6e-4,-.005,.005,1e-4]},sway:{amplitude:[.03,0,.15,.001],period:[12,2,40,.5]},backdrop:{top:"#2a2a2a",mid:"#050505",bottom:"#030303",centerX:[.5,0,1,.005],centerY:[1.02,.5,1.5,.005],radius:[.55,.1,1.5,.005],falloff:[1.6,.5,4,.01],noise:[1,0,3,.05]},envSoftbox:[1,0,3,.01],envRim:[.5,0,3,.01],envFill:[.12,0,1,.005]},LB={fov:[30,15,60,.5],distance:[13.5,4,24,.05],height:[1.2,-3,6,.01],lookAtY:[-.15,-2,2,.01],parallaxRange:[3,0,10,.1],parallaxSmoothing:[.8,.05,3,.01],rotateYaw:[35,0,90,.5],rotatePitch:[10,0,45,.5],rotationLag:[1.2,.05,4,.01],baseYaw:[0,-180,180,.5],basePitch:[0,-90,90,.5],idleDelay:[4,0,15,.1],idleAmplitude:[4,0,15,.1],idlePeriod:[24,4,80,.5]},kB={dof:{enabled:!0,focusBias:[0,-3,3,.01],aperture:[.9,0,4,.01],range:[3,.2,12,.05]},bloom:{threshold:[1.2,0,3,.01],intensity:[.15,0,1.5,.005],radius:[.15,0,1,.005]},monochrome:[1,0,1,.01],tonemap:wa("agx",["agx","aces","neutral","linear"]),exposure:[1,.1,4,.01],contrast:[1.08,.6,1.6,.005],blackLift:[.02,0,.1,.001],vignette:{strength:[.2,0,1,.005],softness:[.7,.1,1.5,.005],radius:[.85,.2,1.6,.005]},grain:{strength:[.03,0,.15,.001],size:[1,1,4,1],speed:[1,0,3,.05],shadowWeight:[.8,0,1,.01],backgroundStrength:[0,0,.25,.001],backgroundSize:[2,1,8,1],backgroundSpeed:[0,0,3,.05]},dither:!0,aaMode:wa("traa",["traa","none"]),pixelRatioCap:[2,.5,2,.25]},S_={chunks:[600,40,3e3,10],seed:[3,0,999,1],hitPadding:[.5,0,2,.05],eject:{speed:[2.6,0,10,.05],spread:[.7,0,4,.05],spin:[5,0,20,.1],jitter:[.45,0,1,.01],backwardRatio:[.2,0,1,.01]},motion:{drag:[1.3,0,8,.01],angularDrag:[1.6,0,8,.01],gravity:[.3,0,3,.01],turbulence:[1.2,0,6,.05],turbulenceScale:[1.4,.2,6,.05],maxSpeed:[10,1,40,.1]},return:{returnAfter:[1.4,0,20,.05],returnJitter:[.9,0,5,.05],idleDelay:[.6,0,10,.05],spring:[14,.5,60,.1],damping:[1,.2,2,.01],ramp:[.5,0,3,.05],rotationRate:[6,.5,30,.1],snapDistance:[.015,.002,.2,.001]},caps:{frost:[.85,0,1,.01],roughness:[.8,0,1,.01],grain:[.5,0,2,.01],darken:[.15,0,1,.01]}},__={adaptiveResolution:!0,targetFps:[60,30,120,1],minPixelRatio:[.75,.5,2,.05],sceneResolutionScale:[1,.5,1,.05],dynamicSceneResolution:!0,minSceneResolutionScale:[.35,.25,1,.05],upscaler:wa("taau",["taau","fsr1","bilinear","native"]),upscaleSharpness:[.2,0,1,.05],nativePostEffects:!0,idleSkip:!1,adaptiveSteps:!1,voronoiCells:wa("27",["27","8"]),hazeResolution:wa("full",["full","half","quarter"]),turbulence:wa("full",["full","fast"]),gpuTimers:!0},DB={_collapsed:!0,showErosionSlice:!1,erosionSliceZ:[.5,0,1,.01],showDensityGrid:!1,showHitPoints:!1,colorByState:!1,colorBySize:!1,colorByAge:!1,wireframe:!1,freeze:!1,stepOnce:{type:"action",label:"Step one frame"},stats:!0,forceStroke:!1};function OB(e,t){if(!(!t||typeof t!="object"))for(let[r,i]of Object.entries(t)){let s=e[r];s===void 0||r.startsWith("_")||(Array.isArray(s)?typeof i=="number"&&(s[0]=i):s&&typeof s=="object"&&"type"in s?s.type!=="action"&&(s.default=i):s&&typeof s=="object"?OB(s,i):e[r]=i)}}var Zie={shape:b_,ice:gm,erosion:T_,powder:ym,healing:IB,fracture:S_,lighting:FB,camera:LB,post:kB,performance:__,debug:DB};for(let[e,t]of Object.entries(Zie))OB(t,qie[e]);typeof location<"u"&&new URLSearchParams(location.search).has("idleskip")&&(__.idleSkip=!0),BB&&(S_.chunks[0]=120),BB&&(b_.segments[0]=96,gm.cracks.steps[0]=6,gm.cracks.fineCracks=!1,gm.dispersion[0]=0,T_.resolution.default="64",ym.particleCount.default="100k",ym.densityGrid.default="32",ym.hazeSteps[0]=8);function Ma(e){let t={};for(let[r,i]of Object.entries(e))if(!r.startsWith("_"))if(Array.isArray(i))t[r]=i[0];else if(typeof i=="object"&&i!==null&&"type"in i){if(i.type==="action")continue;t[r]=i.default??(i.options?i.options[0]:void 0)}else typeof i=="object"&&i!==null?t[r]=Ma(i):t[r]=i;return t}var le={shape:Ma(b_),ice:{...Ma(gm),features:{...Qd}},erosion:Ma(T_),powder:Ma(ym),healing:Ma(IB),lighting:Ma(FB),camera:Ma(LB),post:Ma(kB),performance:Ma(__),fracture:Ma(S_),debug:Ma(DB),version:0},R0e=new EventTarget,{Fn:Ku,vec3:yr,vec4:w_,float:xr,floor:M_,fract:Ol,dot:Ul,mix:E0e,abs:P0e,max:Jie,min:Qie,sqrt:UB,normalize:Kie,cross:ese,sin:tse,cos:rse,int:zl,If:xm,Loop:qy,mx_noise_float:vm,mx_noise_vec3:B0e,smoothstep:ise,select:I0e}=Jr,Po=Ku(([e])=>{let t=Ol(yr(e).mul(yr(.1031,.103,.0973))).toVar();return t.addAssign(Ul(t,t.yxz.add(33.33))),Ol(t.x.add(t.y).mul(t.z))}),Yy=Ku(([e])=>{let t=Ol(yr(e).mul(yr(.1031,.103,.0973))).toVar();return t.addAssign(Ul(t,t.yxz.add(33.33))),Ol(t.xxy.add(t.yxx).mul(t.zyx))}),N_=Ku(([e])=>{let t=Ol(xr(e).mul(.1031)).toVar();return t.mulAssign(t.add(33.33)),t.mulAssign(t.add(t)),Ol(t)}),ea=(e,t)=>Po(yr(xr(e).mul(1024.7).add(t*3.1),xr(e).mul(2047.3).add(t*7.7+1.3),xr(e).mul(511.1).add(t*13.9+2.9))),ws=e=>vm(e),Na=e=>yr(vm(e),vm(yr(e).yzx.add(yr(17.1,9.7,3.3))),vm(yr(e).zxy.add(yr(31.7,5.9,21.3))));function Bo(e,t,r=2,i=.5){let s=xr(0),a=1,n=0,o=yr(e);for(let l=0;l{let t=xr(.02),r=yr(t,0,0),i=yr(0,t,0),s=yr(0,0,t),a=Na(e.sub(r)),n=Na(e.add(r)),o=Na(e.sub(i)),l=Na(e.add(i)),u=Na(e.sub(s)),h=Na(e.add(s)),d=l.z.sub(o.z).sub(h.y.sub(u.y)),c=h.x.sub(u.x).sub(n.z.sub(a.z)),m=n.y.sub(a.y).sub(l.x.sub(o.x));return yr(d,c,m).div(t.mul(2))}),A_=Ku(([e,t])=>{let r=M_(e).toVar(),i=Ol(e).toVar(),s=xr(8).toVar(),a=yr(0).toVar(),n={start:zl(-1),end:zl(1),condition:"<="};return qy(n,n,n,({i:o,j:l,k:u})=>{let h=yr(xr(o),xr(l),xr(u)),d=r.add(h),c=Yy(d.add(t)),m=h.add(c).sub(i),g=Ul(m,m);xm(g.lessThan(s),()=>{s.assign(g),a.assign(d.add(c))})}),w_(a,UB(s))}),ase=Ku(([e,t])=>{let r=M_(yr(e).sub(.5)).toVar(),i=xr(8).toVar(),s=yr(0).toVar(),a={start:zl(0),end:zl(1),condition:"<="};return qy(a,a,a,({i:n,j:o,k:l})=>{let u=r.add(yr(xr(n),xr(o),xr(l))),h=u.add(Yy(u.add(t))),d=h.sub(e),c=Ul(d,d);xm(c.lessThan(i),()=>{i.assign(c),s.assign(h)})}),w_(s,UB(i))}),bm=Ku(([e,t,r])=>{let i=M_(e).toVar(),s=Ol(e).toVar(),a=xr(8).toVar(),n=yr(0).toVar(),o=yr(0).toVar(),l={start:zl(-1),end:zl(1),condition:"<="};qy(l,l,l,({i:d,j:c,k:m})=>{let g=yr(xr(d),xr(c),xr(m)),y=i.add(g),b=Yy(y.add(t)),v=g.add(b).sub(s),S=Ul(v,v);xm(S.lessThan(a),()=>{a.assign(S),n.assign(v),o.assign(y)})}),a.assign(8);let u=yr(0,0,1).toVar(),h={start:zl(-2),end:zl(2),condition:"<="};return qy(h,h,h,({i:d,j:c,k:m})=>{let g=yr(xr(d),xr(c),xr(m)),y=i.add(g),b=Yy(y.add(t)),v=g.add(b).sub(s),S=v.sub(n),T=Po(y.add(o).mul(.731).add(t)).lessThan(r);xm(Ul(S,S).greaterThan(1e-5).and(T),()=>{let w=Kie(S),N=Ul(n.add(v).mul(.5),w);xm(N.lessThan(a),()=>{a.assign(N),u.assign(w)})})}),w_(u,a)}),Zy=(e,t,r)=>ise(xr(t).sub(xr(r).mul(.5)),xr(t).add(xr(r).mul(.5)),e),Jy=(e,t,r)=>{let i=rse(r),s=tse(r);return e.mul(i).add(ese(t,e).mul(s)).add(t.mul(Ul(t,e)).mul(xr(1).sub(i)))},gi=e=>Qie(Jie(e,0),1),Io={headline1:"Hard to|break.",headline2:"Easy to|remember.",textWidth:6.5,fontWeight:"600",letterSpacing:.01,textLineHeight:.95,textDepth:.16,textBevel:.04,textCorner:.008,textMeshDetail:4,logoBreakAt:1.5,formHeadline1At:3.8,headline1BreakAt:10.375,formHeadline2At:12.675,headline2BreakAt:18.5,fadeOutAt:22,turnYaw:180,turnPitch:-41,approach:7,turnYaw2:160,turnPitch2:35,retreat:3.5,zoomIn:5,finalYaw:40,finalPitch:-20,driftYaw:2,driftSway:4,idleYaw:6,shardAmount:.44,strayDust:24,sliceRadius:.6,sliceStrength:21.5,breakDuration:2,finalEjectBoost:2.5,shatterRadius:.45,shatterStrength:32.5,cutThreshold:.3,cutSoftness:.19,edgeWidth:.19,edgeInset:0,brushSoftness:.15,brushNoise:.4,crumbleRate:4.3,crumbleCrackBias:5.1,crumbleDuration:.35,ejectSpeed:.91,ejectSpread:.48,ejectTurbulence:4,drag:0,gravity:0,turbulence:4,turbulenceScale:2.65,turbulenceDecay:3.65,clumpCohesion:.9,followObject:30,settleTime:2.2,settledDrift:1,maxSpeed:26.3,repelStrength:30,repelRange:.97,repelRadial:17.5,repelRadialRange:3.3,tumble:1.05,minPixelSize:.25,grainSizeMultiplier:1.05,spriteSize:1.9,returnGroupStagger:1.35,returnGroupScale:2.55,returnGroupSeed:60765,formSpread:0,waveReach:10,formJitter:2.8,formFill:3,returnSpring:29.9,returnDamping:1.34,returnRamp:.45,returnMaxSpeed:60,alignToSurface:1,alignCurve:3.75,healRate:3,cellRestore:60,landedFade:1.65,refrostTime:10.6,keyColor:"#f0f7ff",keyIntensity:5.05,keyElevation:42,keyAzimuth:-38,keySize:1.25,fill:.18,fillColor:"#cadde9",fillGroundColor:"#172635",rim:2.5,rimColor:"#d9f1ff",rimElevation:20,swayAmplitude:0,swayPeriod:35,envSoftbox:1.1,envRim:1.4,envFill:.22,backdropTop:"#050505",backdropMid:"#050505",backdropBottom:"#050505",backdropCenterX:.73,backdropCenterY:.22,backdropRadius:.8,backdropFalloff:.85,backdropNoise:0,ior:1.675,dispersion:.12,thicknessScale:2.04,attenuationDistance:6.54,attenuationColor:"#d5f4ff",baseRoughness:.31,clearcoat:0,clearcoatRoughness:0,envIntensity:2.04,specularIntensity:1.44,interiorScatter:.09,crumbleGlow:.16,edgeWhiteness:.09,frostScale:.7,frostThreshold:.62,frostSoftness:.24,frostRoughness:.73,frostDiffuse:.11,crystalBump:.01,crystalScale:4,crackLargeScale:2.45,crackWarp:.22,crackWarpScale:2.2,crackCoverage:.19,crackRegionScale:1.8,crackRegionCoverage:.6,veinScale:8,veinContrast:.55,crackWidth:.0025,crackBrightness:.65,crackDarkness:.69,crackRefraction:.076,crackSurfaceStrength:.16,fineScale:18.4,fineAmount:.52,fineCoverage:1,smudgeAmount:.78,smudgeCoverage:.58,smudgeMaskScale:1.85,smudgeAnisotropy:16.5,smudgeRoughness:.75,smudgeWhiteness:.035,smudgeScale:1.3,microBump:.445,microScale:10,microCoverage:.25,rippleBump:.22,rippleScale:23,bumpMaskScale:1.45,baseTone:"#f3fbff",wrap:.47,fragTranslucency:.96,fragThroughTint:"#dff4ff",fragFresnelPower:5,fragRoughness:.09,fragClearcoat:0,fragSpecular:1,sparkle:.4,sparkleFraction:.18,spriteTilt:12,spriteNormal:.15,spriteFrost:.23,spriteFrostBoost:.15,spriteFrostRoughness:.42,spriteEdgeLight:.85,spriteAlphaCut:.6,spriteSeeThrough:1,bloomThreshold:3,bloomIntensity:.04,bloomRadius:1,monochrome:.04,tonemap:"aces",exposure:1,contrast:1.03,blackLift:0,vignetteStrength:.14,vignetteSoftness:1.2,vignetteRadius:1.2,grainStrength:0,quality:"full",upscaler:"fsr1",renderScale:1,erosionResolution:"96",particleCount:"100k",logoUrl:"assets/logo.svg",deformStrength:0,deformScale:.41,deformSeed:7,logoMeshDetail:2,rimAzimuth:-146,rimAngle:26,rimSize:.45,fillReflectionStrength:.3,accentCoolIntensity:3.71,accentCoolReflection:2.31,accentCoolElevation:63,accentCoolAzimuth:22,accentCoolSize:2.65,accentCoolColor:"#ff5900",accentWarmIntensity:2.99,accentWarmReflection:.34,accentWarmElevation:30,accentWarmAzimuth:-30,accentWarmSize:1.2,accentWarmColor:"#75aaff",cameraMode:"original",cameraTrack:"",materialBaseColor:"#ffffff",materialTransmission:!0,materialAbsorption:!0,materialDispersion:!1,materialReflections:!0,materialFrost:!0,materialInteriorFrost:0,materialCrystals:!0,materialGrain:!0,materialGrainAmount:.47,materialGrainScale:150,materialCutNormals:!0,materialMicro:!0,materialRipples:!0,materialSmudges:!0,materialCracks:!0,materialScatter:!0,materialClearcoat:!0,materialShardNormals:!0,materialShardFrost:!0,materialShardTransmission:!0,materialShardReflections:!0,materialShardSparkle:!0,materialShardEdges:!0,materialBacklight:.27,materialInclusionAmount:2,materialInclusionScale:.05,returnNoiseAmount:"2",assemblyFrontDuration:3.2,assemblyOriginX:-.65,assemblyOriginY:.55,assemblyAngle:-35,assemblySpread:.65,assemblyFrontNoise:.35,assemblySpeedVariation:.65,assemblyBend:1.2,assemblySwirl:1.1,assemblyLandingVariation:.8,materialSurfaceBumps:!1,shapeResolution:"256",rendererProfile:"studio"},{max:Aa,float:zB,length:F0e,sqrt:nse,log:ose,select:lse,smoothstep:use,vec3:Qy,dot:VB,abs:hse,cos:GB,sin:WB,clamp:dse,mix:cse}=Jr,Bs={returnGroupStagger:Io.returnGroupStagger,returnGroupScale:Io.returnGroupScale,returnGroupSeed:Io.returnGroupSeed,returnNoiseAmount:2,assemblyFrontDuration:3.2,assemblyOriginX:-.65,assemblyOriginY:.55,assemblyAngle:-35,assemblySpread:.65,assemblyFrontNoise:.35,assemblySpeedVariation:.65,assemblyBend:1.2,assemblySwirl:1.1,assemblyLandingVariation:.8};function pse(e,t,r,i=zB(0)){let s=A_(e.div(Aa(t,.1)),r),a=e.div(Aa(t,.1)).add(Qy(r.mul(.173),r.mul(.317),r.mul(.571))),n=use(.18,.82,ws(a).mul(.5).add(.5));return lse(i.greaterThan(.5),n,Po(s.xyz.add(11.7)))}function mse(e,t,r){let i=nse(Aa(r.springK,.5)),s=e.add(t.div(i)).add(.03);return Aa(zB(2.8),r.springRamp.add(e.div(Aa(r.returnMaxSpeed,1))).add(ose(Aa(s.div(Aa(r.landRadius,.001)),1)).div(Aa(i.mul(r.springDamp),.5))).add(.35))}function C_(e,t){let r=e.div(Aa(t.bound,.001)).sub(Qy(t.frontX,t.frontY,0)),i=t.frontAngle.mul(Math.PI/180),s=VB(r.xy,Qy(GB(i),WB(i),0).xy),a=hse(VB(r.xy,Qy(WB(i).negate(),GB(i),0).xy)),n=Aa(s,0).add(Aa(s.negate(),0).mul(1.4)).div(1.5),o=a.div(1.5),l=ws(e.div(Aa(t.groupScale,.1)).add(t.groupSeed.mul(.173))).mul(.5).add(.5);return dse(cse(n,o,t.frontSpread).add(l.mul(t.frontNoise).mul(.35)),0,1)}var Ui={x:0,y:0,px:0,py:0,inside:!1,lastMoveT:0,moved:!1,clicked:!1,uiHidden:!1,overUi:!1},pt={strokeActive:!1,overObject:!1,lastStrokeT:-1e9,healing:!1,resetRequestedAt:-1,fade:1,sceneFade:1,hoverAmount:0,fps:0,frameMs:0,pixelRatio:1,outputPixelRatio:1,sceneResolutionScale:1,gpuFrames:0,gpuRenderMs:0,gpuComputeMs:0,fieldActive:!0,powderActive:!0,computeMs:0,counts:{active:0,healing:0,dormant:0,total:0},erosion:{max:0,over50:0,over90:0,refrost:0}},Ht={enabled:!1,clickResets:!0,framing:!0,distance:13.5,height:1.2,lookAtX:0,lookAtY:-.15,fov:27,baseYaw:0,basePitch:0,rotateYaw:35,rotatePitch:10,parallaxRange:3,objectX:0,objectY:0,objectZ:0,backdrop:null,shape:null,healSuspended:!1,cursorErodes:!0,hud:!1,cameraOverride:null,cameraProgress:0,logoParams:null},{Fn:R_,uniform:Ky,instancedArray:E_,instanceIndex:fse,uint:e1,ivec3:gse,vec3:P_,vec4:t1,float:r1,If:eh,texture3D:jB,textureStore:yse,clamp:HB,abs:xse,max:i1,min:XB,length:B_,mix:vse,smoothstep:bse,sin:$B}=Jr,Tse=class{constructor(e,t){this.world=e,this.options=t;let r=e.erosion,i=e.powder,s=i.buffers,a=i.u,n=r.res,o=fse;this.start=E_(i.count,"vec4"),this.captureProgress=E_(i.count,"float"),this.returnRadius=E_(i.count,"vec2");let l=jB(r.tex),u=jB(r.cellTex);this.fracture=R_(()=>{let h=gse(o.mod(e1(n)),o.div(e1(n)).mod(e1(n)),o.div(e1(n*n))),d=u.load(h).level(0).toVar(),c=l.load(h).level(0).toVar(),m=HB(xse(d.y.add(d.x.mul(.3))).div(r.bound*1.3).add(d.w.mul(.07)),1e-5,.99999),g=m.greaterThan(this.from).and(m.lessThanEqual(this.to));eh(g,()=>{c.assign(t1(1,0,0,1))}).Else(()=>{c.a.assign(c.a.mul(.5))}),yse(r.scratch,h,c).toWriteOnly()})().compute(n**3,[64]),this.capture=R_(()=>{this.start.element(o).assign(s.pos.element(o)),this.captureProgress.element(o).assign(this.progress),this.returnRadius.element(o).assign(B_(s.pos.element(o).xyz.sub(a.model.mul(t1(s.rest.element(o).xyz,1)).xyz)))})().compute(i.count,[64]),this.guide=R_(()=>{let h=s.pos.element(o),d=s.vel.element(o),c=s.meta.element(o),m=a.model.mul(t1(s.rest.element(o).xyz,1)).xyz,g=c.x;eh(g.greaterThan(4.5),()=>{h.xyz.assign(m),h.w.assign(0),d.xyz.assign(P_(0))}),eh(g.greaterThan(.5).and(g.lessThan(2.5)),()=>{eh(g.lessThan(1.5),()=>{this.start.element(o).assign(h),this.captureProgress.element(o).assign(this.progress),s.heal.element(o).assign(t1(h.xyz,a.time)),this.returnRadius.element(o).assign(B_(h.xyz.sub(m)))});let y=i1(this.captureProgress.element(o),C_(s.rest.element(o).xyz,a).mul(.22)),b=HB(this.progress.sub(y).div(i1(1e-6,r1(1).sub(y))),0,1).toVar();eh(this.progress.greaterThanEqual(.99999),()=>{b.assign(1)});let v=b.mul(b).mul(r1(3).sub(b.mul(2))),S=this.start.element(o).xyz,T=$B(b.mul(Math.PI)).mul(.35),w=vse(S,m,v).add(P_(T.mul($B(c.y.mul(12))),T.mul(.5),T));eh(this.mode.greaterThan(.5),()=>{h.xyz.assign(w)}).Else(()=>{let N=this.returnRadius.element(o),C=h.xyz.sub(m).toVar(),R=B_(C),E=XB(N.y,N.x.mul(r1(1).sub(v))),P=XB(R,E);h.xyz.assign(m.add(C.mul(P.div(i1(R,1e-6))))),N.y.assign(P)}),c.x.assign(2),h.w.assign(i1(h.w,this.start.element(o).w.mul(r1(1).sub(bse(.9,1,b))))),eh(b.greaterThanEqual(.99999),()=>{h.xyz.assign(m),h.w.assign(0),d.xyz.assign(P_(0)),c.x.assign(5)})})})().compute(i.count,[64]),i.beforeIntegrate=()=>{a.strokeDir.value.set(1,-.3,0).normalize(),a.strokeSpeed.value=3,a.rigStrength.value=this.options.mode==="physical"?this.progress.value:this.progress.value>0?1:0,a.returnAfter.value=0,a.heal.value=this.progress.value>0?1:0,a.repel.value=this.progress.value>0?0:1},i.beforeAssembly=()=>{this.capturePending&&(e.renderer.compute(this.capture),this.capturePending=!1),this.assembling&&this.options.mode!=="physical"&&e.renderer.compute(this.guide),this.assembling&&this.newCut&&i.prepareAssembly(e.renderer)},i.assemblyEnabled=!1,a.rigEnabled.value=1,e.onBeforeSimulation=(h,d)=>this.update(h,d)}previousBreak=0;previousAssembly=0;assembling=!1;capturePending=!1;from=Ky(0);to=Ky(0);progress=Ky(0);mode=Ky(0);start;captureProgress;returnRadius;newCut=!1;fracture;capture;guide;sample;target=0;breakLatch=!1;pose(e){let t=this.options.sample(e);this.sample=t,this.world.motionGroup.position.set(t.x,t.y+.05,t.z),this.world.motionGroup.rotation.set(t.rx*Math.PI/180,t.ry*Math.PI/180,t.rz*Math.PI/180,"YXZ"),this.world.objectGroup.quaternion.identity();let r=t.target??0;r!==this.target&&(this.target=r,this.options.retarget?.(r),this.previousBreak=0,this.previousAssembly=0,this.breakLatch=!1,this.assembling=!1,this.capturePending=!1,this.progress.value=0)}reset(){this.target=0,this.breakLatch=!1,this.previousBreak=0,this.previousAssembly=0,this.assembling=!1,this.capturePending=!1,this.world.powder.assemblyEnabled=!1,this.progress.value=0,this.world.powder.restoreThresholds(this.world.renderer)}update(e,t){if(t<=0)return;let r=this.sample||this.options.sample(e),i=this.world,s=i.powder,a=Math.max(0,Math.min(1,r.breakup/100)),n=Math.max(0,Math.min(1,r.assembly/100));le.performance.idleSkip=!1,i.erosion.u.reconstruct.value=1,this.newCut=a>this.previousBreak,this.options.sequence&&this.newCut&&(this.breakLatch||s.restoreThresholds(i.renderer),this.breakLatch=!0),this.options.sequence&&a===0&&n===0&&(this.breakLatch=!1),this.from.value=this.previousBreak,this.to.value=a,i.renderer.compute(this.fracture),i.erosion.commitAssembly(i.renderer),n>0&&this.previousAssembly<=0&&!this.breakLatch&&(this.options.sequence||(s.retarget(i.renderer,s.restInit),s.restoreThresholds(i.renderer)),s.assemblyEnabled=!0,this.assembling=!0,this.capturePending=!0,s.u.assemblyEnd.value=1e6,pt.lastStrokeT=e),(n===0||this.breakLatch)&&(this.assembling=!1,s.assemblyEnabled=!1);let o=n>0&&!this.breakLatch;pt.healing=o,this.progress.value=o?n:0,this.mode.value=this.options.mode==="directed"?1:0,s.u.repel.value=o?0:1,this.previousBreak=a,this.previousAssembly=n}dispose(){this.start.value.dispose?.(),this.captureProgress.value.dispose?.(),this.returnRadius.value.dispose?.()}},qB={original:"gpu",lookup:"gpu,materials",mesh:"gpu,mesh,materials",studio:"gpu,fast,environment,materials,aa",matcap:"gpu,matcap,materials,aa"},YB=typeof location>"u"?new URLSearchParams:new URLSearchParams(location.search);function ZB(e){let t=new Set((YB.has("rewrite")?YB.get("rewrite"):qB[e]||qB.studio).split(","));return{gpu:t.has("gpu"),environment:t.has("environment"),materials:t.has("materials"),matcap:t.has("matcap"),fast:t.has("fast"),aa:t.has("aa"),mesh:t.has("mesh")||t.has("matcap")||t.has("fast")}}var qa=ZB(typeof window>"u"?"original":"studio"),th={flags:qa,stages:[],sdf:[],start:performance.now()};typeof window<"u"&&(window.__rewrite=th);function Sse(e="studio"){Object.assign(qa,ZB(e)),th.profile=e}var s1=Math.pow(2,-24),Tm=Symbol("SKIP_GENERATION"),JB={strategy:0,maxDepth:40,targetLeafSize:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null,[Tm]:!1};function Ur(e,t,r){return r.min.x=t[e],r.min.y=t[e+1],r.min.z=t[e+2],r.max.x=t[e+3],r.max.y=t[e+4],r.max.z=t[e+5],r}function I_(e){let t=-1,r=-1/0;for(let i=0;i<3;i++){let s=e[i+3]-e[i];s>r&&(r=s,t=i)}return t}function QB(e,t){t.set(e)}function KB(e,t,r){let i,s;for(let a=0;a<3;a++){let n=a+3;i=e[a],s=t[a],r[a]=is?i:s}}function a1(e,t,r){for(let i=0;i<3;i++){let s=t[e+2*i],a=t[e+2*i+1],n=s-a,o=s+a;nr[i+3]&&(r[i+3]=o)}}function Sm(e){let t=e[3]-e[0],r=e[4]-e[1],i=e[5]-e[2];return 2*(t*r+r*i+i*t)}function Cr(e,t){return t[e+15]===65535}function Ei(e,t){return t[e+6]}function as(e,t){return t[e+14]}function oi(e){return e+8}function li(e,t){let r=t[e+6];return e+r*8}function F_(e,t){return t[e+7]}function L_(e,t,r,i,s){let a=1/0,n=1/0,o=1/0,l=-1/0,u=-1/0,h=-1/0,d=1/0,c=1/0,m=1/0,g=-1/0,y=-1/0,b=-1/0,v=e.offset||0;for(let S=(t-v)*6,T=(t+r-v)*6;Sl&&(l=R),wg&&(g=w);let E=e[S+2],P=e[S+3],I=E-P,O=E+P;Iu&&(u=O),Ey&&(y=E);let L=e[S+4],X=e[S+5],z=L-X,H=L+X;zh&&(h=H),Lb&&(b=L)}i[0]=a,i[1]=n,i[2]=o,i[3]=l,i[4]=u,i[5]=h,s[0]=d,s[1]=c,s[2]=m,s[3]=g,s[4]=y,s[5]=b}var Fo=32,_se=(e,t)=>e.candidate-t.candidate,Vl=new Array(Fo).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),n1=new Float32Array(6);function wse(e,t,r,i,s,a){let n=-1,o=0;if(a===0)n=I_(t),n!==-1&&(o=(t[n]+t[n+3])/2);else if(a===1)n=I_(e),n!==-1&&(o=Mse(r,i,s,n));else if(a===2){let l=Sm(e),u=1.25*s,h=r.offset||0,d=(i-h)*6,c=(i+s-h)*6;for(let m=0;m<3;m++){let g=t[m],y=(t[m+3]-g)/Fo;if(s=C.candidate?a1(T,r,C.rightCacheBounds):(a1(T,r,C.leftCacheBounds),C.count++)}}for(let T=0;T=Fo&&(T=Fo-1);let w=Vl[T];w.count++,a1(S,r,w.bounds)}let b=Vl[Fo-1];QB(b.bounds,b.rightCacheBounds);for(let S=Fo-2;S>=0;S--){let T=Vl[S],w=Vl[S+1];KB(T.bounds,w.rightCacheBounds,T.rightCacheBounds)}let v=0;for(let S=0;S=l;)o--;if(nAse)throw new Error("MeshBVH: Cannot store relative child node offset greater than 32 bits.");return o1[r+6]=c,o1[r+7]=l,U_(h,o)}}function Rse(e,t,r,i,s,a){let{maxDepth:n,verbose:o,targetLeafSize:l,_strictLeafSize:u=1/0,strategy:h,onProgress:d}=s,c=e.primitiveBuffer,m=e.primitiveBufferStride,g=new Float32Array(6),y=!1,b=new k_;return L_(t,r,i,b.boundingData,g),S(b,r,i,g),b;function v(T){d&&d((T-a.offset)/a.count)}function S(T,w,N,C=null,R=0){!y&&R>=n&&(y=!0,o&&console.warn(`BVH: Max depth of ${n} reached when generating BVH. Consider increasing maxDepth.`));let E=N>u;if(N<=l&&!E||R>=n)return v(w+N),T.offset=w,T.count=N,T;let P=wse(T.boundingData,C,t,w,N,h),I=P.axis===-1?-1:Nse(c,m,t,w,N,P);if(P.axis===-1||I===w||I===w+N){if(!E)return v(w+N),T.offset=w,T.count=N,T;P.axis=Math.max(0,I_(T.boundingData)),I=w+Math.max(1,Math.floor(N/2))}T.splitAxis=P.axis;let O=new k_,L=w,X=I-w;T.left=O,L_(t,L,X,O.boundingData,g),S(O,L,X,g,R+1);let z=new k_,H=I,ue=N-X;return T.right=z,L_(t,H,ue,z.boundingData,g),S(z,H,ue,g,R+1),T}}function Ese(e,t){let r=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,i=e.getRootRanges(t.range),s=i[0],a=i[i.length-1],n={offset:s.offset,count:a.offset+a.count-s.offset},o=new Float32Array(6*n.count);o.offset=n.offset,e.computePrimitiveBounds(n.offset,n.count,o),e._roots=i.map(l=>{let u=Rse(e,o,l.offset,l.count,t,n),h=O_(u),d=new r(32*h);return Cse(0,u,d),d})}var z_=class{constructor(e){this._getNewPrimitive=e,this._primitives=[]}getPrimitive(){let e=this._primitives;return e.length===0?this._getNewPrimitive():e.pop()}releasePrimitive(e){this._primitives.push(e)}},Pse=class{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;let e=[],t=null;this.setBuffer=r=>{t&&e.push(t),t=r,this.float32Array=new Float32Array(r),this.uint16Array=new Uint16Array(r),this.uint32Array=new Uint32Array(r)},this.clearBuffer=()=>{t=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,e.length!==0&&this.setBuffer(e.pop())}}},Rr=new Pse,Gl,Kd,ec=[],l1=new z_(()=>new qi);function Bse(e,t,r,i,s,a){Gl=l1.getPrimitive(),Kd=l1.getPrimitive(),ec.push(Gl,Kd),Rr.setBuffer(e._roots[t]);let n=V_(0,e.geometry,r,i,s,a);Rr.clearBuffer(),l1.releasePrimitive(Gl),l1.releasePrimitive(Kd),ec.pop(),ec.pop();let o=ec.length;return o>0&&(Kd=ec[o-1],Gl=ec[o-2]),n}function V_(e,t,r,i,s=null,a=0,n=0){let{float32Array:o,uint16Array:l,uint32Array:u}=Rr,h=e*2;if(Cr(h,l)){let d=Ei(e,u),c=as(h,l);return Ur(e,o,Gl),i(d,c,!1,n,a+e/8,Gl)}else{let d=function(O){let{uint16Array:L,uint32Array:X}=Rr,z=O*2;for(;!Cr(z,L);)O=oi(O),z=O*2;return Ei(O,X)},c=function(O){let{uint16Array:L,uint32Array:X}=Rr,z=O*2;for(;!Cr(z,L);)O=li(O,X),z=O*2;return Ei(O,X)+as(z,L)},m=oi(e),g=li(e,u),y=m,b=g,v,S,T,w;if(s&&(T=Gl,w=Kd,Ur(y,o,T),Ur(b,o,w),v=s(T),S=s(w),Snew qi),tc=new qi,rc=new qi,G_=new qi,W_=new qi,j_=!1;function Ise(e,t,r,i){if(j_)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");j_=!0;let s=e._roots,a=t._roots,n,o=0,l=0,u=new We().copy(r).invert();for(let h=0,d=s.length;h{if(i)throw new Error("BVHTraversalHelper: cannot call setBVH during an active traversal.");this.root=n,this.buffer=e=a._roots[n],this.uint16Array=r=new Uint16Array(e),this.uint32Array=t=new Uint32Array(e)},this.reset=()=>{this.root=null,this.buffer=e=null,this.uint16Array=r=null,this.uint32Array=t=null},this.getRangeStart=a=>{let n=a*2;for(;!Cr(n,r);)a=oi(a),n=a*2;return Ei(a,t)},this.getRangeEnd=a=>{let n=a*2;for(;!Cr(n,r);)a=li(a,t),n=a*2;return Ei(a,t)+as(n,r)};let s=(a,n,o)=>{let l=n*2,u=Cr(l,r);if(!a(o,u,n)&&!u){let h=oi(n),d=li(n,t);s(a,h,o+1),s(a,d,o+1)}};this.traverseBuffer=a=>{if(i)throw new Error("BVHTraversalHelper: cannot start a traversal during an active traversal.");i=!0;try{s(a,0,0)}finally{i=!1}},this.traverse=a=>{this.traverseBuffer((n,o,l)=>{if(o){let u=l*2,h=t[l+6],d=r[u+14];return a(n,o,new Float32Array(e,l*4,6),h,d)}else{let u=F_(l,t);return a(n,o,new Float32Array(e,l*4,6),u)}})}}},r5=new qi,ic=new Float32Array(6),i5=class{constructor(){this._roots=null,this.primitiveBuffer=null,this.primitiveBufferStride=null}init(e){e={...JB,...e},"maxLeafSize"in e&&(console.warn('BVH: "maxLeafSize" option has been deprecated. Use "targetLeafSize", instead.'),e={...e,targetLeafSize:e.maxLeafSize}),Ese(this,e)}getRootRanges(){throw new Error("BVH: getRootRanges() not implemented")}writePrimitiveBounds(){throw new Error("BVH: writePrimitiveBounds() not implemented")}writePrimitiveRangeBounds(e,t,r,i){let s=1/0,a=1/0,n=1/0,o=-1/0,l=-1/0,u=-1/0;for(let h=e,d=e+t;ho&&(o=y),ml&&(l=b),gu&&(u=v)}return r[i+0]=s,r[i+1]=a,r[i+2]=n,r[i+3]=o,r[i+4]=l,r[i+5]=u,r}computePrimitiveBounds(e,t,r){let i=r.offset||0;for(let s=e,a=e+t;s=0;l--){let u=l*8,h=u*2;if(Cr(h,a)){let d=Ei(u,s),c=as(h,a);this.writePrimitiveRangeBounds(d,c,ic,0),n.set(ic,u)}else{let d=oi(u),c=li(u,s);for(let m=0;m<3;m++){let g=n[d+m],y=n[d+m+3],b=n[c+m],v=n[c+m+3];n[u+m]=gv?y:v}}}}}getBoundingBox(e){return e.makeEmpty(),this._roots.forEach(t=>{Ur(0,new Float32Array(t),r5),e.union(r5)}),e}shapecast(e){let{boundsTraverseOrder:t,intersectsBounds:r,intersectsRange:i,intersectsPrimitive:s,scratchPrimitive:a,iterate:n}=e;if(i&&s){let h=i;i=(d,c,m,g,y)=>h(d,c,m,g,y)?!0:n(d,c,this,s,m,g,a)}else i||(s?i=(h,d,c,m)=>n(h,d,this,s,c,m,a):i=(h,d,c)=>c);let o=!1,l=0,u=this._roots;for(let h=0,d=u.length;h65535?new Uint32Array(new t(4*e)):new Uint16Array(new t(2*e))}function kse(e,t){if(!e.index){let r=e.attributes.position.count,i=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,s=Lse(r,i);e.setIndex(new _i(s,1));for(let a=0;a({offset:r.start/t,count:r.count/t}))}function s5(e,t,r){let i=Dse(e,t,r),s=Ose(e,r);if(!s.length)return[i];let a=[],n=i.offset,o=i.offset+i.count,l=H_(e)/r,u=[];for(let c of s){let{offset:m,count:g}=c,y=m,b=isFinite(g)?g:l-m,v=m+b;yn&&(u.push({pos:Math.max(n,y),isStart:!0}),u.push({pos:Math.min(o,v),isStart:!1}))}u.sort((c,m)=>c.pos!==m.pos?c.pos-m.pos:c.type==="end"?-1:1);let h=0,d=null;for(let c of u){let m=c.pos;h!==0&&m!==d&&a.push({offset:d,count:m-d}),h+=c.isStart?1:-1,d=m}return a}function Use(e,t){let r=e[e.length-1],i=r.offset+r.count>2**16,s=e.reduce((u,h)=>u+h.count,0),a=i?4:2,n=t?new SharedArrayBuffer(s*a):new ArrayBuffer(s*a),o=i?new Uint32Array(n):new Uint16Array(n),l=0;for(let u=0;uthis._indirectBuffer[r]:r=>r,this.primitiveBuffer=null,this.primitiveBufferStride=null,this._indirectBuffer=null,t={...JB,...t},t[Tm]||this.init(t)}init(e){let{geometry:t,primitiveStride:r}=this;if(e.indirect){let i=s5(t,e.range,r),s=Use(i,e.useSharedArrayBuffer);this._indirectBuffer=s}else kse(t,e);super.init(e),!t.boundingBox&&e.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new qi))}getRootRanges(e){return this.indirect?[{offset:0,count:this._indirectBuffer.length}]:s5(this.geometry,e,this.primitiveStride)}raycastObject3D(){throw new Error("BVH: raycastObject3D() not implemented")}},Lo=class{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(e,t){let r=1/0,i=-1/0;for(let s=0,a=e.length;si?n:i}this.min=r,this.max=i}setFromPoints(e,t){let r=1/0,i=-1/0;for(let s=0,a=t.length;si?o:i}this.min=r,this.max=i}isSeparated(e){return this.min>e.max||e.min>this.max}};Lo.prototype.setFromBox=(function(){let e=new F;return function(t,r){let i=r.min,s=r.max,a=1/0,n=-1/0;for(let o=0;o<=1;o++)for(let l=0;l<=1;l++)for(let u=0;u<=1;u++){e.x=i.x*o+s.x*(1-o),e.y=i.y*l+s.y*(1-l),e.z=i.z*u+s.z*(1-u);let h=t.dot(e);a=Math.min(h,a),n=Math.max(h,n)}this.min=a,this.max=n}})();var zse=(function(){let e=new F,t=new F,r=new F;return function(i,s,a){let n=i.start,o=e,l=s.start,u=t;r.subVectors(n,l),e.subVectors(i.end,i.start),t.subVectors(s.end,s.start);let h=r.dot(u),d=u.dot(o),c=u.dot(u),m=r.dot(o),g=o.dot(o)*c-d*d,y,b;g!==0?y=(h*d-m*c)/g:y=0,b=(h+y*d)/c,a.x=y,a.y=b}})(),X_=(function(){let e=new fe,t=new F,r=new F;return function(i,s,a,n){zse(i,s,e);let o=e.x,l=e.y;if(o>=0&&o<=1&&l>=0&&l<=1){i.at(o,a),s.at(l,n);return}else if(o>=0&&o<=1){l<0?s.at(0,n):s.at(1,n),i.closestPointToPoint(n,!0,a);return}else if(l>=0&&l<=1){o<0?i.at(0,a):i.at(1,a),s.closestPointToPoint(a,!0,n);return}else{let u;o<0?u=i.start:u=i.end;let h;l<0?h=s.start:h=s.end;let d=t,c=r;if(i.closestPointToPoint(h,!0,t),s.closestPointToPoint(u,!0,r),d.distanceToSquared(h)<=c.distanceToSquared(u)){a.copy(d),n.copy(h);return}else{a.copy(u),n.copy(c);return}}}})(),Vse=(function(){let e=new F,t=new F,r=new fn,i=new fo;return function(s,a){let{radius:n,center:o}=s,{a:l,b:u,c:h}=a;if(i.start=l,i.end=u,i.closestPointToPoint(o,!0,e).distanceTo(o)<=n||(i.start=l,i.end=h,i.closestPointToPoint(o,!0,e).distanceTo(o)<=n)||(i.start=u,i.end=h,i.closestPointToPoint(o,!0,e).distanceTo(o)<=n))return!0;let d=a.getPlane(r);if(Math.abs(d.distanceToPoint(o))<=n){let c=d.projectPoint(o,t);if(a.containsPoint(c))return!0}return!1}})(),Gse=["x","y","z"],ko=1e-15,a5=ko*ko;function Ca(e){return Math.abs(e)new F),this.satBounds=new Array(4).fill().map(()=>new Lo),this.points=[this.a,this.b,this.c],this.plane=new fn,this.isDegenerateIntoSegment=!1,this.isDegenerateIntoPoint=!1,this.degenerateSegment=new fo,this.needsUpdate=!0}intersectsSphere(e){return Vse(e,this)}update(){let e=this.a,t=this.b,r=this.c,i=this.points,s=this.satAxes,a=this.satBounds,n=s[0],o=a[0];this.getNormal(n),o.setFromPoints(n,i);let l=s[1],u=a[1];l.subVectors(e,t),u.setFromPoints(l,i);let h=s[2],d=a[2];h.subVectors(t,r),d.setFromPoints(h,i);let c=s[3],m=a[3];c.subVectors(r,e),m.setFromPoints(c,i);let g=l.length(),y=h.length(),b=c.length();this.isDegenerateIntoPoint=!1,this.isDegenerateIntoSegment=!1,g0)m(T.c,T.a,T.b,C,w,N,O,P,I,L,X);else if(E>0)m(T.b,T.a,T.c,N,w,C,I,P,O,L,X);else if(I*O>0||P!=0)m(T.a,T.b,T.c,w,N,C,P,I,O,L,X);else if(I!=0)m(T.b,T.a,T.c,N,w,C,I,P,O,L,X);else if(O!=0)m(T.c,T.a,T.b,C,w,N,O,P,I,L,X);else return!0;return!1}function y(T,w,N,C){let R=w.degenerateSegment,E=T.plane.distanceToPoint(R.start),P=T.plane.distanceToPoint(R.end);return Ca(E)?Ca(P)?c(T,w,N,C):(N&&(N.start.copy(R.start),N.end.copy(R.start)),T.containsPoint(R.start)):Ca(P)?(N&&(N.start.copy(R.end),N.end.copy(R.end)),T.containsPoint(R.end)):T.plane.intersectLine(R,i)!=null?(N&&(N.start.copy(i),N.end.copy(i)),T.containsPoint(i)):!1}function b(T,w,N){let C=w.a;return Ca(T.plane.distanceToPoint(C))&&T.containsPoint(C)?(N&&(N.start.copy(C),N.end.copy(C)),!0):!1}function v(T,w,N){let C=T.degenerateSegment,R=w.a;return C.closestPointToPoint(R,!0,i),R.distanceToSquared(i)1||z<0||z>1)return!1;let H=R.start.z+P.z*X,ue=E.start.z+I.z*z;return Ca(H-ue)?(N&&(N.start.copy(R.start).addScaledVector(P,X),N.end.copy(R.start).addScaledVector(P,X)),!0):!1}else return w.isDegenerateIntoPoint?v(T,w,N):y(w,T,N,C);else{if(T.isDegenerateIntoPoint)return w.isDegenerateIntoPoint?w.a.distanceToSquared(T.a)0&&X>0)return!1;let z=R.distanceToPoint(T.a),H=R.distanceToPoint(T.b),ue=R.distanceToPoint(T.c);Ca(z)&&(z=0),Ca(H)&&(H=0),Ca(ue)&&(ue=0);let ne=z*H,re=z*ue;if(ne>0&&re>0)return!1;s.copy(R.normal),a.copy(E.normal);let ce=s.cross(a),ge=0,ye=Math.abs(ce.x),oe=Math.abs(ce.y);oe>ye&&(ye=oe,ge=1),Math.abs(ce.z)>ye&&(ge=2);let Ae=Gse[ge],Ie=this.a[Ae],Xe=this.b[Ae],at=this.c[Ae],W=T.a[Ae],j=T.b[Ae],G=T.c[Ae];if(g(this,Ie,Xe,at,L,X,P,I,O,h,o))return c(this,T,w,N);if(g(T,W,j,G,ne,re,z,H,ue,d,l))return c(this,T,w,N);if(h.yh.x?w.start.copy(l.start):w.start.copy(o.start),d.ynew F),this.satAxes=new Array(3).fill().map(()=>new F),this.satBounds=new Array(3).fill().map(()=>new Lo),this.alignedSatBounds=new Array(3).fill().map(()=>new Lo),this.needsUpdate=!1,e&&this.min.copy(e),t&&this.max.copy(t),r&&this.matrix.copy(r)}set(e,t,r){this.min.copy(e),this.max.copy(t),this.matrix.copy(r),this.needsUpdate=!0}copy(e){this.min.copy(e.min),this.max.copy(e.max),this.matrix.copy(e.matrix),this.needsUpdate=!0}};Ms.prototype.update=(function(){return function(){let e=this.matrix,t=this.min,r=this.max,i=this.points;for(let l=0;l<=1;l++)for(let u=0;u<=1;u++)for(let h=0;h<=1;h++){let d=1*l|2*u|4*h,c=i[d];c.x=l?r.x:t.x,c.y=u?r.y:t.y,c.z=h?r.z:t.z,c.applyMatrix4(e)}let s=this.satBounds,a=this.satAxes,n=i[0];for(let l=0;l<3;l++){let u=a[l],h=s[l],d=1<new fo),r=new Array(12).fill().map(()=>new fo),i=new F,s=new F;return function(a,n=0,o=null,l=null){if(this.needsUpdate&&this.update(),this.intersectsBox(a))return(o||l)&&(a.getCenter(s),this.closestPointToPoint(s,i),a.closestPointToPoint(i,s),o&&o.copy(i),l&&l.copy(s)),0;let u=n*n,h=a.min,d=a.max,c=this.points,m=1/0;for(let y=0;y<8;y++){let b=c[y];s.copy(b).clamp(h,d);let v=b.distanceToSquared(s);if(vnew Ra)}},Ea=new Wse,wm=new F,$_=new F;function jse(e,t,r={},i=0,s=1/0){let a=i*i,n=s*s,o=1/0,l=null;if(e.shapecast({boundsTraverseOrder:h=>(wm.copy(t).clamp(h.min,h.max),wm.distanceToSquared(t)),intersectsBounds:(h,d,c)=>c{h.closestPointToPoint(t,wm);let c=t.distanceToSquared(wm);return c=169,Hse=parseInt("185")<=161,rh=new F,ih=new F,sh=new F,p1=new fe,m1=new fe,f1=new fe,n5=new F,o5=new F,l5=new F,Mm=new F;function Xse(e,t,r,i,s,a,n,o){let l;if(a===ii?l=e.intersectTriangle(i,r,t,!0,s):l=e.intersectTriangle(t,r,i,a!==hs,s),l===null)return null;let u=e.origin.distanceTo(s);return uo?null:{distance:u,point:s.clone()}}function u5(e,t,r,i,s,a,n,o,l,u,h){rh.fromBufferAttribute(t,a),ih.fromBufferAttribute(t,n),sh.fromBufferAttribute(t,o);let d=Xse(e,rh,ih,sh,Mm,l,u,h);if(d){if(i){p1.fromBufferAttribute(i,a),m1.fromBufferAttribute(i,n),f1.fromBufferAttribute(i,o),d.uv=new fe;let m=$i.getInterpolation(Mm,rh,ih,sh,p1,m1,f1,d.uv);c1||(d.uv=m)}if(s){p1.fromBufferAttribute(s,a),m1.fromBufferAttribute(s,n),f1.fromBufferAttribute(s,o),d.uv1=new fe;let m=$i.getInterpolation(Mm,rh,ih,sh,p1,m1,f1,d.uv1);c1||(d.uv1=m),Hse&&(d.uv2=d.uv1)}if(r){n5.fromBufferAttribute(r,a),o5.fromBufferAttribute(r,n),l5.fromBufferAttribute(r,o),d.normal=new F;let m=$i.getInterpolation(Mm,rh,ih,sh,n5,o5,l5,d.normal);d.normal.dot(e.direction)>0&&d.normal.multiplyScalar(-1),c1||(d.normal=m)}let c={a,b:n,c:o,normal:new F,materialIndex:0};if($i.getNormal(rh,ih,sh,c.normal),d.face=c,d.faceIndex=a,c1){let m=new F;$i.getBarycoord(Mm,rh,ih,sh,m),d.barycoord=m}}return d}function h5(e){return e&&e.isMaterial?e.side:e}function g1(e,t,r,i,s,a,n){let o=i*3,l=o+0,u=o+1,h=o+2,{index:d,groups:c}=e;e.index&&(l=d.getX(l),u=d.getX(u),h=d.getX(h));let{position:m,normal:g,uv:y,uv1:b}=e.attributes;if(Array.isArray(t)){let v=i*3;for(let S=0,T=c.length;S=w&&vN&&(N=O),LC&&(C=L),XR&&(R=X)}return l[c+0]!==S||l[c+1]!==T||l[c+2]!==w||l[c+3]!==N||l[c+4]!==C||l[c+5]!==R?(l[c+0]=S,l[c+1]=T,l[c+2]=w,l[c+3]=N,l[c+4]=C,l[c+5]=R,!0):!1}else{let b=oi(c),v=li(c,n),S=g,T=!1,w=!1;if(t){if(!S){let I=b/8+m/32,O=v/8+m/32;T=t.has(I),w=t.has(O),S=!T&&!w}}else T=!0,w=!0;let N=S||T,C=S||w,R=!1;N&&(R=d(b,m,S));let E=!1;C&&(E=d(v,m,S));let P=R||E;if(P)for(let I=0;I<3;I++){let O=b+I,L=v+I,X=l[O],z=l[O+3],H=l[L],ue=l[L+3];l[c+I]=Xue?z:ue}return P}}}function Hl(e,t,r,i,s){let a,n,o,l,u,h,d=1/r.direction.x,c=1/r.direction.y,m=1/r.direction.z,g=r.origin.x,y=r.origin.y,b=r.origin.z,v=t[e],S=t[e+3],T=t[e+1],w=t[e+3+1],N=t[e+2],C=t[e+3+2];return d>=0?(a=(v-g)*d,n=(S-g)*d):(a=(S-g)*d,n=(v-g)*d),c>=0?(o=(T-y)*c,l=(w-y)*c):(o=(w-y)*c,l=(T-y)*c),a>l||o>n||((o>a||isNaN(a))&&(a=o),(l=0?(u=(N-b)*m,h=(C-b)*m):(u=(C-b)*m,h=(N-b)*m),a>h||u>n)?!1:((u>a||a!==a)&&(a=u),(h=i)}function Jse(e,t,r,i,s,a,n,o){let{geometry:l,_indirectBuffer:u}=e;for(let h=i,d=i+s;h=0,m,g;c?(m=oi(e),g=li(e,l)):(m=li(e,l),g=oi(e));let y=Hl(m,n,i,s,a)?Y_(m,t,r,i,s,a):null;if(y){let v=y.point[d];if(c?v<=n[g+h]:v>=n[g+h+3])return y}let b=Hl(g,n,i,s,a)?Y_(g,t,r,i,s,a):null;return y&&b?y.distance<=b.distance?y:b:y||b||null}}var y1=new qi,sc=new Ra,ac=new Ra,Nm=new We,d5=new Ms,x1=new Ms;function iae(e,t,r,i){Rr.setBuffer(e._roots[t]);let s=Z_(0,e,r,i);return Rr.clearBuffer(),s}function Z_(e,t,r,i,s=null){let{float32Array:a,uint16Array:n,uint32Array:o}=Rr,l=e*2;if(s===null&&(r.boundingBox||r.computeBoundingBox(),d5.set(r.boundingBox.min,r.boundingBox.max,i),s=d5),Cr(l,n)){let u=t.geometry,h=u.index,d=u.attributes.position,c=r.index,m=r.attributes.position,g=Ei(e,o),y=as(l,n);if(Nm.copy(i).invert(),r.boundsTree)return Ur(e,a,x1),x1.matrix.copy(Nm),x1.needsUpdate=!0,r.boundsTree.shapecast({intersectsBounds:b=>x1.intersectsBox(b),intersectsTriangle:b=>{b.a.applyMatrix4(i),b.b.applyMatrix4(i),b.c.applyMatrix4(i),b.needsUpdate=!0;for(let v=g*3,S=(y+g)*3;vJ_.distanceToBox(N),intersectsBounds:(N,C,R)=>R{if(t.boundsTree)return t.boundsTree.shapecast({boundsTraverseOrder:R=>Am.distanceToBox(R),intersectsBounds:(R,E,P)=>P{for(let P=R,I=R+E;PN&&(N=X),zC&&(C=z),HR&&(R=H)}}return l[c+0]!==S||l[c+1]!==T||l[c+2]!==w||l[c+3]!==N||l[c+4]!==C||l[c+5]!==R?(l[c+0]=S,l[c+1]=T,l[c+2]=w,l[c+3]=N,l[c+4]=C,l[c+5]=R,!0):!1}else{let b=oi(c),v=li(c,n),S=g,T=!1,w=!1;if(t){if(!S){let I=b/8+m/32,O=v/8+m/32;T=t.has(I),w=t.has(O),S=!T&&!w}}else T=!0,w=!0;let N=S||T,C=S||w,R=!1;N&&(R=d(b,m,S));let E=!1;C&&(E=d(v,m,S));let P=R||E;if(P)for(let I=0;I<3;I++){let O=b+I,L=v+I,X=l[O],z=l[O+3],H=l[L],ue=l[L+3];l[c+I]=Xue?z:ue}return P}}}function hae(e,t,r,i,s,a,n){Rr.setBuffer(e._roots[t]),Q_(0,e,r,i,s,a,n),Rr.clearBuffer()}function Q_(e,t,r,i,s,a,n){let{float32Array:o,uint16Array:l,uint32Array:u}=Rr,h=e*2;if(Cr(h,l)){let d=Ei(e,u),c=as(h,l);Jse(t,r,i,d,c,s,a,n)}else{let d=oi(e);Hl(d,o,i,a,n)&&Q_(d,t,r,i,s,a,n);let c=li(e,u);Hl(c,o,i,a,n)&&Q_(c,t,r,i,s,a,n)}}var dae=["x","y","z"];function cae(e,t,r,i,s,a){Rr.setBuffer(e._roots[t]);let n=K_(0,e,r,i,s,a);return Rr.clearBuffer(),n}function K_(e,t,r,i,s,a){let{float32Array:n,uint16Array:o,uint32Array:l}=Rr,u=e*2;if(Cr(u,o)){let h=Ei(e,l),d=as(u,o);return Qse(t,r,i,h,d,s,a)}else{let h=F_(e,l),d=dae[h],c=i.direction[d]>=0,m,g;c?(m=oi(e),g=li(e,l)):(m=li(e,l),g=oi(e));let y=Hl(m,n,i,s,a)?K_(m,t,r,i,s,a):null;if(y){let v=y.point[d];if(c?v<=n[g+h]:v>=n[g+h+3])return y}let b=Hl(g,n,i,s,a)?K_(g,t,r,i,s,a):null;return y&&b?y.distance<=b.distance?y:b:y||b||null}}var b1=new qi,nc=new Ra,oc=new Ra,Cm=new We,c5=new Ms,T1=new Ms;function pae(e,t,r,i){Rr.setBuffer(e._roots[t]);let s=ew(0,e,r,i);return Rr.clearBuffer(),s}function ew(e,t,r,i,s=null){let{float32Array:a,uint16Array:n,uint32Array:o}=Rr,l=e*2;if(s===null&&(r.boundingBox||r.computeBoundingBox(),c5.set(r.boundingBox.min,r.boundingBox.max,i),s=c5),Cr(l,n)){let u=t.geometry,h=u.index,d=u.attributes.position,c=r.index,m=r.attributes.position,g=Ei(e,o),y=as(l,n);if(Cm.copy(i).invert(),r.boundsTree)return Ur(e,a,T1),T1.matrix.copy(Cm),T1.needsUpdate=!0,r.boundsTree.shapecast({intersectsBounds:b=>T1.intersectsBox(b),intersectsTriangle:b=>{b.a.applyMatrix4(i),b.b.applyMatrix4(i),b.c.applyMatrix4(i),b.needsUpdate=!0;for(let v=g,S=y+g;vtw.distanceToBox(N),intersectsBounds:(N,C,R)=>R{if(t.boundsTree){let R=t.boundsTree;return R.shapecast({boundsTraverseOrder:E=>Rm.distanceToBox(E),intersectsBounds:(E,P,I)=>I{for(let I=E,O=E+P;Il.slice()),o.index=n?n.array.slice():null,o.indirectBuffer=a?a.slice():null):(o.roots=s,o.index=n?n.array:null,o.indirectBuffer=a),o}static deserialize(t,r,i={}){i={setIndex:!0,indirect:!!t.indirectBuffer,...i};let{index:s,roots:a,indirectBuffer:n}=t;t.version||(console.warn("MeshBVH.deserialize: Serialization format has been changed and will be fixed up. It is recommended to regenerate any stored serialized data."),l(a));let o=new hM(r,{...i,[Tm]:!0});if(o._roots=a,o._indirectBuffer=n||null,i.setIndex){let u=r.getIndex();if(u===null){let h=new _i(t.index,1,!1);r.setIndex(h)}else u.array!==s&&(u.array.set(s),u.needsUpdate=!0)}return o;function l(u){for(let h=0;hv&&(v=g),y>v&&(v=y),r[i+c]=b,r[i+c+3]=v}return r}computePrimitiveBounds(t,r,i){let s=this.geometry,a=this._indirectBuffer,n=s.attributes.position,o=s.index?s.index.array:null,l=n.normalized;if(t<0||r+t-i.offset>i.length/6)throw new Error("MeshBVH: compute triangle bounds range is invalid.");let u=n.array,h=n.offset||0,d=3;n.isInterleavedBufferAttribute&&(d=n.data.stride);let c=["getX","getY","getZ"],m=i.offset;for(let g=t,y=t+r;gI&&(I=R),E>I&&(I=E);let O=(I-P)/2,L=N*2;i[v+L+0]=P+O,i[v+L+1]=O+(Math.abs(P)+O)*s1}}return i}raycastObject3D(t,r,i=[]){let{material:s}=t;if(s===void 0)return;f5.copy(t.matrixWorld).invert(),w1.copy(r.ray).applyMatrix4(f5),g5.setFromMatrixScale(t.matrixWorld),m5.copy(w1.direction).multiply(g5);let a=m5.length(),n=r.near/a,o=r.far/a;if(r.firstHitOnly===!0){let l=this.raycastFirst(w1,s,n,o);l=p5(l,t,r),l&&i.push(l)}else{let l=this.raycast(w1,s,n,o);for(let u=0,h=l.length;u{let y=this.resolveTriangleIndex(g);ui(n,y*3,o,l)}:g=>{ui(n,g*3,o,l)},h=Ea.getPrimitive(),d=t.geometry.index,c=t.geometry.attributes.position,m=t.indirect?g=>{let y=t.resolveTriangleIndex(g);ui(h,y*3,d,c)}:g=>{ui(h,g*3,d,c)};if(a){if(!(t instanceof hM))throw new Error('MeshBVH: "intersectsTriangles" callback can only be used with another MeshBVH.');let g=(y,b,v,S,T,w,N,C)=>{for(let R=v,E=v+S;R_1.intersectsBox(i),intersectsTriangle:i=>_1.intersectsTriangle(i)})}intersectsSphere(t){return this.shapecast({intersectsBounds:r=>t.intersectsBox(r),intersectsTriangle:r=>r.intersectsSphere(t)})}closestPointToGeometry(t,r,i={},s={},a=0,n=1/0){return(this.indirect?xae:lae)(this,t,r,i,s,a,n)}closestPointToPoint(t,r={},i=0,s=1/0){return jse(this,t,r,i,s)}},y5=new F,x5=new F,v5=new F,Do=new ld,b5=new We,ah=new F,iw=new F,vae=["x","y","z"],N1=parseInt("185")>=169,bae=parseInt("185")<=161,A1=new fe,C1=new fe,R1=new fe,T5=new F,S5=new F,_5=new F,Tae=class extends d1{get primitiveStride(){return 3}constructor(e,t={}){if(!e.isMesh)throw new Error("SkinnedMeshBVH: First argument must be a Mesh.");super(e.geometry,{...t,[Tm]:!0}),this.mesh=e,t[Tm]||this.init(t)}writePrimitiveBounds(e,t,r){let{mesh:i,geometry:s}=this,a=this._indirectBuffer,n=s.index?s.index.array:null,o=(a?a[e]:e)*3,l=o+0,u=o+1,h=o+2;n&&(l=n[l],u=n[u],h=n[h]),i.getVertexPosition(l,y5),i.getVertexPosition(u,x5),i.getVertexPosition(h,v5);for(let d=0;d<3;d++){let c=vae[d],m=y5[c],g=x5[c],y=v5[c],b=m;gv&&(v=g),y>v&&(v=y),t[r+d]=b,t[r+d+3]=v}return t}shapecast(e){let t=new Ra;return super.shapecast({...e,intersectsPrimitive:e.intersectsTriangle,scratchPrimitive:t,iterate:Sae})}raycastObject3D(e,t,r=[]){let{material:i}=e;if(i===void 0)return;let{matrixWorld:s}=e,{firstHitOnly:a}=t;b5.copy(s).invert(),Do.copy(t.ray).applyMatrix4(b5);let n=null,o=1/0;return this.shapecast({boundsTraverseOrder:l=>l.distanceToPoint(Do.origin),intersectsBounds:l=>{if(a){if(!Do.intersectBox(l,iw))return 0;let u;return l.containsPoint(Do.origin)?u=0:(iw.applyMatrix4(s),u=t.ray.origin.distanceTo(iw)),u{let h=null;if(i.side===Cs?h=Do.intersectTriangle(l.a,l.b,l.c,!0,ah):i.side===ii?h=Do.intersectTriangle(l.c,l.b,l.a,!0,ah):h=Do.intersectTriangle(l.a,l.b,l.c,!1,ah),!h)return;h=h.clone().applyMatrix4(s);let d=t.ray.origin.distanceTo(h);if(d>=t.near&&d<=t.far){if(a&&d>=o)return;let{geometry:c}=this,{index:m}=c,g=this.resolvePrimitiveIndex(u),y=g*3,b=y+0,v=y+1,S=y+2;m&&(b=m.array[b],v=m.array[v],S=m.array[S]);let T={distance:d,point:h.clone(),object:e,uv:null,uv1:null,normal:null,face:{a:b,b:v,c:S,normal:$i.getNormal(l.a,l.b,l.c,new F),materialIndex:0},faceIndex:g};if(N1){let R=new F;$i.getBarycoord(ah,l.a,l.b,l.c,R),T.barycoord=R}let w=c.attributes.uv,N=c.attributes.uv1,C=c.attributes.normal;if(w){A1.fromBufferAttribute(w,b),C1.fromBufferAttribute(w,v),R1.fromBufferAttribute(w,S),T.uv=new fe;let R=$i.getInterpolation(ah,l.a,l.b,l.c,A1,C1,R1,T.uv);N1||(T.uv=R)}if(N){A1.fromBufferAttribute(N,b),C1.fromBufferAttribute(N,v),R1.fromBufferAttribute(N,S),T.uv1=new fe;let R=$i.getInterpolation(ah,l.a,l.b,l.c,A1,C1,R1,T.uv1);N1||(T.uv1=R),bae&&(T.uv2=T.uv1)}if(C){T5.fromBufferAttribute(C,b),S5.fromBufferAttribute(C,v),_5.fromBufferAttribute(C,S),T.normal=new F;let R=$i.getInterpolation(ah,l.a,l.b,l.c,T5,S5,_5,T.normal);T.normal.dot(Do.direction)>0&&T.normal.multiplyScalar(-1),N1||(T.normal=R)}o=T.distance,n=T,a||r.push(T)}}}),a&&n&&r.push(n),r}};function Sae(e,t,r,i,s,a,n){let{mesh:o,geometry:l}=r,u=l.index?l.index.array:null;for(let h=e,d=t+e;h",max:"array"},"BVHBoundingBox");E1.getLength=()=>6;var P1=new Cl({bounds:"BVHBoundingBox",rightChildOrTriangleOffset:"uint",splitAxisOrTriangleCount:"uint"},"BVHNode");P1.getLength=()=>E1.getLength()+2;var _ae=new Cl({matrixWorld:"mat4x4f",inverseMatrixWorld:"mat4x4f",visible:"uint",_alignment0:"uint",_alignment1:"uint",_alignment2:"uint"},"TransformStruct"),Xl=new Cl({origin:"vec3f",direction:"vec3f"},"Ray"),lc=new Cl({indices:"vec4u",normal:"vec3f",didHit:"bool",barycoord:"vec3f",objectIndex:"uint",side:"float",dist:"float"},"IntersectionResult"),Em=new Cl({faceIndices:"vec4u",closestPoint:"vec3f",found:"bool",barycoord:"vec3f",objectIndex:"uint",faceNormal:"vec3f",side:"float",distanceSq:"float"},"PointQueryResult"),wae=class extends Ke{static get type(){return"ProxyCallNode"}constructor(e,t){super(),this.proxyNode=e,this.params=t}setup(){return this.proxyNode.proxyNode.call(...this.params)}},w5=class{get isNode(){return!0}get proxyNode(){let{proxyObject:e,proxyProperty:t}=this,r=t.split("."),i=e;for(let s=0,a=r.length;snew w5(...e),Nae=(...e)=>{let t=new w5(...e),r=(...i)=>new wae(t,i);return M.nodeProxyConstructor(r,t)},$l=new Wt,zn=new Wt;function Aae(e,t){let r=e?e.array:null,i=new Uint32Array(t.length*3);for(let s=0,a=t.length;s{let o=new Uint16Array(n),l=new Uint32Array(n);for(let u=0,h=n.byteLength/32;uv?(a[m+y+0]=1,a[m+y+3]=-1):(a[m+y+0]=b,a[m+y+3]=v)}else a.set(g,m);if(t===null){r++;continue}if(Cr(c,o)){let y=l[d+6],b=o[c+14],{transformSlot:v,nodeOffset:S}=b===0?{transformSlot:0,nodeOffset:0}:t[y];if(v>16777215)throw new Error(`packBVHBufferUtils: transform slot ${v} exceeds the 24-bit TLAS leaf limit.`);s[m+6]=S,s[m+7]=4278190080|v&16777215}else s[m+6]=l[d+6],s[m+7]=l[d+7];r++}})}function Cae(e,t){return N5(new Uint16Array(e),new Uint32Array(e),t)}function N5(e,t,r){if(Cr(r*8*2,e))return 1;let i=t[r*8+6];return i+N5(e,t,r+i)}function A5(e,t=0){let r=new Uint16Array(e),i=new Uint32Array(e),s=0;return a(t*8,1),s;function a(n,o){let l=n,u=n*2;if(Cr(u,r))s=Math.max(o,s);else{let h=li(l,i),d=oi(l);a(d,o+1),a(h,o+1)}}}function Rae(e,t,r,i,s,a){let n=new Uint16Array(a),o=new Uint32Array(a),l=new Float32Array(a),u=new Uint16Array(e),h=new Uint32Array(e);for(let d=0;dw?(l[y+S+0]=1,l[y+S+3]=-1):(l[y+S+0]=T,l[y+S+3]=w)}else l.set(v,y);Cr(g,u)?(o[y+6]=h[m+6]+i,n[b+14]=u[g+14],n[b+15]=65535):(o[y+6]=h[m+6],o[y+7]=h[m+7]),s++}}function Eae(e,t,r,i,s){let{geometry:a}=e,{start:n,count:o,vertexStart:l}=t;if(e.indirect){let u=Aae(a.index,e._indirectBuffer);for(let h=0;h{let g=n.attributes[c];a.getDefaultAttributeValue(c,$l);for(let y=0;y(r&&!r.isNode&&r instanceof Function&&(r=r(t)),r&&r.isNode?(r.setup(t),r.isWGSLTagCodeNode?new sw(r,"inline"):new sw(r)):r))}function aw(e,t,r){let i="";for(let s=0,a=e.length;s\s*void/,"").trim(),r}},Lae=class extends pr{static get type(){return"WGSLTagCodeNode"}constructor(e,t,r="wgsl"){super("",C5(t),r),this.isWGSLTagCodeNode=!0,this.tokens=e,this.args=t}setup(e){super.setup(e),this._normalizedArgs=R5(this.args,e)}build(e,t){return t==="inline"?aw(this.tokens,this._normalizedArgs,e):super.build(e,t)}generate(e){super.generate(e);let t=e.getCodeFromNode(this,this.getNodeType(e));return t.code=aw(this.tokens,this._normalizedArgs,e),t.code}},kae=e=>{let t=(...r)=>{if(r.length===1&&r[0]&&typeof r[0]=="object"&&!r[0].isNode){let i=r[0];for(let s in i)typeof i[s]=="string"&&(i[s]=new Bae(i[s]))}return e.call(...r)};return M.nodeProxyConstructor(t,e)},Pi=(e,...t)=>kae(new Fae(e,t)),uc=(e,...t)=>new Lae(e,t),nw=RB(60);function Dae(e,t){let{name:r=`bvh_shapecast_fn_${Math.random().toString(36).substring(2,7)}`,shapeStruct:i,resultStruct:s=null,prefixFn:a=null,boundsOrderFn:n=null,intersectsBoundsFn:o,intersectRangeFn:l,transformShapeFn:u=null,transformResultFn:h=null,resetShapeFn:d=null}=t,{nodes:c,transforms:m}=e.storage,g="";a&&(g=uc`${a}();`);let y="";h&&(y=uc`${h}( result, objectIndex );`);let b="";u&&(b=uc`${u}( &localShape, objectIndex );`);let v="";d&&(v=uc`${d}( objectIndex );`);let S="";n&&(S=uc` let leftToRight = ${n}( localShape, splitAxis, node ); c1 = select( rightIndex, leftIndex, leftToRight ); c2 = select( leftIndex, rightIndex, leftToRight ); `);let T=s?uc`result: ptr`:"",w=s?"result":"",N=Pi` // fn fn ${r}( shape: ${i}, ${T} ) -> bool { ${g} var didHit = false; var isTLAS = true; var pointer: i32 = 0; var stack: array; stack[ 0 ] = 0u; var blasDidHit: bool = false; var objectIndex: u32 = 0; var localShape: ${i} = shape; // the stack depth the current cluster's BLAS drains back down to once it is complete var tlasReset: i32 = 0; loop { // The cluster's BLAS has drained back to its TLAS leaf. Finalize the cluster that // was just traversed and resume the TLAS. if ( ! isTLAS && tlasReset == pointer ) { if ( blasDidHit ) { blasDidHit = false; didHit = true; ${y} } ${v} objectIndex = 0; isTLAS = true; localShape = shape; } // check if we've finished all nodes on the stack (or overrun the stack) if ( pointer < 0 || pointer >= i32( ${nw} ) ) { break; } let nodeIndex = stack[ pointer ]; let node = ${c}[ nodeIndex ]; pointer = pointer - 1; // skip the node if we don't intersect the bounds if ( ${o}( localShape, node.bounds, ${w} ) == 0u ) { continue; } let infoX = node.splitAxisOrTriangleCount; let infoY = node.rightChildOrTriangleOffset; let isLeaf = ( infoX & 0xffff0000u ) != 0u; if ( isLeaf ) { if ( isTLAS ) { // the leaf encodes the placement / transform slot in the low 24 bits of infoX // and the cluster subtree's absolute node offset in infoY, which is pushed // directly as the BLAS entry node. Each TLAS leaf references one cluster. objectIndex = infoX & 0x00ffffffu; let transform = ${m}[ objectIndex ]; if ( transform.visible != 0u ) { tlasReset = pointer; isTLAS = false; blasDidHit = false; // Transform shape into object local space localShape = shape; ${b} pointer = pointer + 1; stack[ pointer ] = infoY; } } else { let count = infoX & 0x0000ffffu; let offset = infoY; blasDidHit = ${l}( localShape, offset, count, ${w} ) || blasDidHit; } } else { let leftIndex = nodeIndex + 1u; let splitAxis = infoX & 0x0000ffffu; let rightIndex = nodeIndex + infoY; var c1 = rightIndex; var c2 = leftIndex; ${S} pointer = pointer + 1; stack[ pointer ] = c2; pointer = pointer + 1; stack[ pointer ] = c1; } } return didHit; } `;return N.outputType=s,N.functionName=r,N}var Oae=Pi` // fn fn closestPointToTriangle( p: vec3f, v0: vec3f, v1: vec3f, v2: vec3f ) -> vec3f { let v10 = v1 - v0; let v21 = v2 - v1; let v02 = v0 - v2; let p0 = p - v0; let p1 = p - v1; let p2 = p - v2; let nor = cross( v10, v02 ); let q = cross( nor, p0 ); let d = 1.0 / dot( nor, nor ); var u = d * dot( q, v02 ); var v = d * dot( q, v10 ); var w = 1.0 - u - v; if ( u < 0.0 ) { w = clamp( dot( p2, v02 ) / dot( v02, v02 ), 0.0, 1.0 ); u = 0.0; v = 1.0 - w; } else if ( v < 0.0 ) { u = clamp( dot( p0, v10 ) / dot( v10, v10 ), 0.0, 1.0 ); v = 0.0; w = 1.0 - u; } else if ( w < 0.0 ) { v = clamp( dot( p1, v21 ) / dot( v21, v21 ), 0.0, 1.0 ); w = 0.0; u = 1.0 - v; } return vec3f( w, u, v ); } `,Uae=Pi` // fn fn intersectRayTriangle( ray: ${Xl}, a: vec3f, b: vec3f, c: vec3f, threshold: f32 ) -> ${lc} { const DET_EPSILON = 1e-15; var result: ${lc}; result.didHit = false; let edge1 = b - a; let edge2 = c - a; let n = cross( edge1, edge2 ); let det = - dot( ray.direction, n ); if ( abs( det ) < DET_EPSILON ) { return result; } let invdet = 1.0 / det; let AO = ray.origin - a; let DAO = cross( AO, ray.direction ); let u = dot( edge2, DAO ) * invdet; if ( u < 0.0 || u > 1.0 ) { return result; } let v = - dot( edge1, DAO ) * invdet; if ( v < 0.0 || u + v > 1.0 ) { return result; } let t = dot( AO, n ) * invdet; let w = 1.0 - u - v; if ( t < threshold ) { return result; } result.didHit = true; result.barycoord = vec3f( w, u, v ); result.dist = t; result.side = sign( det ); result.normal = result.side * normalize( n ); return result; } `,L0e=Pi` // fn fn ndcToCameraRay( ndc: vec2f, inverseModelViewProjection: mat4x4f ) -> ${Xl} { var homogeneous = vec4f(); var ray: ${Xl}; homogeneous = inverseModelViewProjection * vec4f( ndc, 0.0, 1.0 ); ray.origin = homogeneous.xyz / homogeneous.w; homogeneous = inverseModelViewProjection * vec4f( ndc, 1.0, 1.0 ); ray.direction = ( homogeneous.xyz / homogeneous.w ) - ray.origin; return ray; } `;function zae(e){let{index:t,attributes:r,transforms:i}=e.storage,s=yt(1).toVar(`bvh_rayScalar_${Math.random().toString(36).substring(2,7)}`);return e.getShapecastFn({name:"bvh_RaycastFirstHit",shapeStruct:Xl,resultStruct:lc,boundsOrderFn:Pi` fn getBoundsOrder( ray: ${Xl}, splitAxis: u32, node: ${P1} ) -> bool { return ray.direction[ splitAxis ] >= 0.0; } `,intersectsBoundsFn:Pi` fn rayIntersectsBounds( ray: ${Xl}, bounds: ${E1}, result: ptr ) -> u32 { let boundsMin = vec3( bounds.min[0], bounds.min[1], bounds.min[2] ); let boundsMax = vec3( bounds.max[0], bounds.max[1], bounds.max[2] ); let invDir = 1.0 / ray.direction; let tMinPlane = ( boundsMin - ray.origin ) * invDir; let tMaxPlane = ( boundsMax - ray.origin ) * invDir; let tMinHit = vec3f( min( tMinPlane.x, tMaxPlane.x ), min( tMinPlane.y, tMaxPlane.y ), min( tMinPlane.z, tMaxPlane.z ) ); let tMaxHit = vec3f( max( tMinPlane.x, tMaxPlane.x ), max( tMinPlane.y, tMaxPlane.y ), max( tMinPlane.z, tMaxPlane.z ) ); let t0 = max( max( tMinHit.x, tMinHit.y ), tMinHit.z ); let t1 = min( min( tMaxHit.x, tMaxHit.y ), tMaxHit.z ); let dist = max( t0, 0.0 ); if ( t1 < dist ) { return 0u; } else if ( result.didHit && dist * ${s} >= result.dist ) { return 0u; } else { return 1u; } } `,intersectRangeFn:Pi` fn intersectRange( ray: ${Xl}, offset: u32, count: u32, result: ptr ) -> bool { var didHit = false; for ( var ti = offset; ti < offset + count; ti = ti + 1u ) { let i0 = ${t}[ ti * 3u ]; let i1 = ${t}[ ti * 3u + 1u ]; let i2 = ${t}[ ti * 3u + 2u ]; let a = ${r}[ i0 ].position.xyz; let b = ${r}[ i1 ].position.xyz; let c = ${r}[ i2 ].position.xyz; var triResult = ${Uae}( ray, a, b, c, 0.0 ); triResult.dist *= ${s}; if ( triResult.didHit && ( ! result.didHit || triResult.dist < result.dist ) ) { result.didHit = true; result.dist = triResult.dist; result.normal = triResult.normal; result.side = triResult.side; result.barycoord = triResult.barycoord; result.indices = vec4u( i0, i1, i2, ti ); didHit = true; } } return didHit; } `,transformShapeFn:Pi` fn transformRay( ray: ptr, objectIndex: u32 ) -> void { let toLocal = ${i}[ objectIndex ].inverseMatrixWorld; ray.origin = ( toLocal * vec4f( ray.origin, 1.0 ) ).xyz; ray.direction = ( toLocal * vec4f( ray.direction, 0.0 ) ).xyz; let len = length( ray.direction ); ray.direction /= len; ${s} = 1.0 / len; } `,transformResultFn:Pi` fn transformResult( hit: ptr, objectIndex: u32 ) -> void { let toLocal = ${i}[ objectIndex ].inverseMatrixWorld; hit.normal = normalize( ( transpose( toLocal ) * vec4f( hit.normal, 0.0 ) ).xyz ); hit.objectIndex = objectIndex; } `,resetShapeFn:Pi` fn resetRayScalar( objectIndex: u32 ) -> void { ${s} = 1.0; } `})}function Vae(e){let{storage:t,structs:r}=e,i=r.attributes.membersLayout.map(({name:s})=>`result.${s} = a0.${s} * barycoord.x + a1.${s} * barycoord.y + a2.${s} * barycoord.z;`).join(` `);return Pi` // fn fn bvh_sampleTrianglePoint( barycoord: vec3f, indices: vec3u ) -> ${r.attributes} { var result: ${r.attributes}; var a0 = ${t.attributes}[ indices.x ]; var a1 = ${t.attributes}[ indices.y ]; var a2 = ${t.attributes}[ indices.z ]; ${i} return result; } `}function Gae(e){let{index:t,attributes:r,transforms:i}=e.storage,s=NB().toVar("bvh_toWorldMat");return e.getShapecastFn({name:"bvh_ClosestPointToPoint",shapeStruct:"vec3f",resultStruct:Em,boundsOrderFn:Pi` fn cppBoundsOrder( shape: vec3f, splitAxis: u32, node: ${P1} ) -> bool { let toWorld = ${s}; // get center let bMin = vec3f( node.bounds.min[ 0 ], node.bounds.min[ 1 ], node.bounds.min[ 2 ] ); let bMax = vec3f( node.bounds.max[ 0 ], node.bounds.max[ 1 ], node.bounds.max[ 2 ] ); let center = bMin * 0.5 + bMax * 0.5; // determine the order in world space let worldCenter = ( toWorld * vec4f( center, 1.0 ) ).xyz; let worldAxis = normalize( toWorld[ splitAxis ].xyz ); return dot( shape - worldCenter, worldAxis ) <= 0.0; } `,intersectsBoundsFn:Pi` fn cppIntersectsBounds( shape: vec3f, bounds: ${E1}, result: ptr ) -> u32 { // return 1u; // we need to check this no matter what if the result has not been found yet if ( ! result.found ) { return 1u; } let toWorld = ${s}; // transform to world space let bMin = vec3f( bounds.min[ 0 ], bounds.min[ 1 ], bounds.min[ 2 ] ); let bMax = vec3f( bounds.max[ 0 ], bounds.max[ 1 ], bounds.max[ 2 ] ); let center = ( bMin + bMax ) * 0.5; let halfExtent = ( bMax - bMin ) * 0.5; let worldCenter = ( toWorld * vec4f( center, 1.0 ) ).xyz; let worldHalfExtent = abs( toWorld[ 0 ].xyz ) * halfExtent.x + abs( toWorld[ 1 ].xyz ) * halfExtent.y + abs( toWorld[ 2 ].xyz ) * halfExtent.z; let worldMin = worldCenter - worldHalfExtent; let worldMax = worldCenter + worldHalfExtent; // intersect if the distance to the bounds is not bigger than the already found let d = shape - clamp( shape, worldMin, worldMax ); return select( 0u, 1u, dot( d, d ) < result.distanceSq ); } `,intersectRangeFn:Pi` fn cppIntersectsRange( shape: vec3f, offset: u32, count: u32, result: ptr ) -> bool { var didHit = false; let toWorld = ${s}; for ( var i = offset; i < offset + count; i ++ ) { // transform the triangle to world space let i0 = ${t}[ i * 3u + 0u ]; let i1 = ${t}[ i * 3u + 1u ]; let i2 = ${t}[ i * 3u + 2u ]; let a = ( toWorld * vec4f( ${r}[ i0 ].position.xyz, 1.0 ) ).xyz; let b = ( toWorld * vec4f( ${r}[ i1 ].position.xyz, 1.0 ) ).xyz; let c = ( toWorld * vec4f( ${r}[ i2 ].position.xyz, 1.0 ) ).xyz; let barycoord = ${Oae}( shape, a, b, c ); let closestPoint = barycoord.x * a + barycoord.y * b + barycoord.z * c; let delta = shape - closestPoint; let distSq = dot( delta, delta ); // copy the content over if ( ! result.found || distSq < result.distanceSq ) { let normal = normalize( cross( a - b, b - c ) ); result.closestPoint = closestPoint; result.barycoord = barycoord; result.distanceSq = distSq; result.faceNormal = normal; result.side = sign( dot( normal, delta ) ); result.faceIndices = vec4u( i0, i1, i2, i ); result.found = true; didHit = true; } } return didHit; } `,resetShapeFn:Pi` fn cppResetShape( objectIndex: u32 ) -> void { // node bounds are transformed by "toWorld" during the bounds tests. Only the // object-local BLAS bounds need the object's world matrix - the top-level bounds // are already in world space - so restore identity before top-level traversal resumes. ${s} = mat4x4f( 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ); } `,transformShapeFn:Pi` fn cppTransformShape( shape: ptr, objectIndex: u32 ) -> void { ${s} = ${i}[ objectIndex ].matrixWorld; } `,transformResultFn:Pi` fn cppTransformResult( result: ptr, objectIndex: u32 ) -> void { result.objectIndex = objectIndex; } `})}var Pm=24,ow=(1<{throw new Error("ClusteredBVH: getBVH callback must be provided ")},shouldCluster:a=>a.isSkinnedMesh||a.isInstancedMesh||a.isBatchedMesh,primitiveLimit:64,matrixWorld:Array.isArray(e)?new We:e.matrixWorld,includeInstances:!0,_strictLeafSize:1,...t};let r=Array.from(B5(e)),i=Math.ceil(Math.log2(r.length)),s=(1<{let n=[];for(let o=0,l=this._getInstanceCount(a);o>>r}getObjectId(e){let{idMask:t}=this;return e&t}getBVHRootIndex(e){return e>>>Pm}getBVHNodeIndex(e){return(e&ow)*8}_getInstanceCount(e){let{includeInstances:t}=this;return e.isInstancedMesh&&t?e.count:e.isBatchedMesh&&t?e.instanceCount:1}_fillPrimitiveBuffer(e){let{objects:t,bvhMap:r,idBits:i,primitiveLimit:s}=this,a=0,n=(o,l,u,h)=>{if(h>ow)throw new Error(`ClusteredBVH: cluster node index ${h} exceeds the ${Pm}-bit packing limit and cannot be represented.`);if(u>Wae)throw new Error(`ClusteredBVH: bvh root index ${u} exceeds the ${E5}-bit packing limit and cannot be represented.`);e[2*a+0]=o<{r.get(o).forEach((u,h)=>{if(u)if(this.shouldCluster(o))for(let d=0,c=u._roots.length;d{n(h,l,d,c/8)})})})}_countRelevantLeafNodes(e){let{primitiveLimit:t}=this,r=0;return P5(e,t,(i,s,a,n)=>{r++,n&&a>=t&&console.warn(`ClusteredBVH: a leaf node with ${a} primitives exceeds the cluster primitive limit of ${t} and cannot be subdivided further.`)}),r}};function P5(e,t,r){let i=e._roots.length;for(let s=0;s{let l=jl.getRangeStart(o),u=jl.getRangeEnd(o)-l;return uB5(r,t)):e.traverse(r=>{r.isMesh&&t.add(r)}),t}var nh=new We,B1=new We,Hae={start:0,count:0,vertexStart:0,vertexCount:0};function Xae(e){let t=e;for(;t;){if(t.visible===!1)return!1;t=t.parent}return!0}function I5(e){return e._roots.reduce((t,r)=>t+r.byteLength,0)}function F5(e,t){return`${e}_${t}`}var $ae=class{constructor(e,t={}){let{attributes:r={position:"vec4f"},autogenerateBvh:i=!0}=t;Array.isArray(e)||(e=[e]),e=e.map(s=>{if(s.isObject3D)return s;if(s.isBufferGeometry)return new Mi(s);if(s instanceof d1){let a=new Mi;return a.geometry.boundsTree=s,a}}),this._bvhCache=new Map,this.autogenerateBvh=i,this.attributes=r,this.objects=e,this.bvh=null,this.storage=new hw,this.structs=new hw({transform:_ae}),this.fns=new hw({raycastFirstHit:zae(this),closestPointToPoint:Gae(this),sampleTrianglePoint:null},Nae)}getRootObject(){let{objects:e}=this;if(e.isObject3D)return e;Array.isArray(e)||(e=[e]),e=e.map(r=>{if(r.isObject3D)return r;if(r.isBufferGeometry)return new Mi(r);if(r instanceof d1){let i=new Mi;return i.geometry.boundsTree=r,i}});let t=new pn;return t.children=e,t}getShapecastFn(e){return Dae(this,e)}update(){let e=this.getRootObject(),t=0;e.traverse(z=>{z.isMesh&&t++}),this.bvh=new jae(e,{strategy:2,getBVH:(z,H)=>this.getBVH(z,H,Hae),primitiveLimit:t<3?1/0:64}),this.dispose();let{attributes:r,structs:i,bvh:s}=this,a=[],n=[],o=new Map,l=I5(s),u=0,h=0,d=[],c=0,m=this._getTransformMap(s),{primitiveBuffer:g,primitiveBufferStride:y}=s;for(let z=0,H=g.length;zW.bvh===ye);oe||(oe={index:a.length,bvh:ye,range:ge,geometryOffset:0},u+=oe.range.count,h+=oe.range.vertexCount,a.push(oe));let Ae=s.getBVHRootIndex(ne),Ie=s.getBVHNodeIndex(ne)/8,Xe=`${oe.index}_${Ae}_${Ie}`,at=o.get(Xe);if(at===void 0){let W=Cae(ye._roots[Ae],Ie);at={data:oe,root:Ae,node:Ie,size:W,base:0},o.set(Xe,at),n.push(at),l+=W*32,c=Math.max(c,A5(ye._roots[Ae],Ie))}d.push({transformSlot:m.get(F5(ue,Ae)).slot,subtree:at})}if(A5(s._roots[0])+c-1>nw.value)throw new Error("BVHComputeData: BVH depth overruns the compute stack depth.");let b=Math.max(m.size,2);u=Math.max(u,2),h=Math.max(h,2);let v=new Cl(r,"bvh_GeometryStruct"),S=0,T=0,w=new Uint32Array(u),N=new ArrayBuffer(h*v.getLength()*4),C=new ArrayBuffer(l);a.forEach(z=>{z.geometryOffset=T/3,z.bvh.indirect||(z.geometryOffset-=z.range.start/3),Eae(z.bvh,z.range,S,T,w),Pae(z.bvh,z.range,S,N,v,this),T+=z.range.count,S+=z.range.vertexCount});let R=I5(s)/32;n.forEach(z=>{z.base=R,Rae(z.data.bvh._roots[z.root],z.node,z.size,z.data.geometryOffset,R,C),R+=z.size}),d.forEach(z=>z.nodeOffset=z.subtree.base),M5(s,d,0,C);let E=new ArrayBuffer(i.transform.getLength()*b*4),P=fm(new $p(new Uint32Array(C),1),P1).toReadOnly().setName("bvh_nodes"),I=new $p(new Uint32Array(E),1),O=fm(I,i.transform).toReadOnly().setName("bvh_transforms"),L=fm(new $p(w,1),"uint").toReadOnly().setName("bvh_index"),X=fm(new $p(new Uint32Array(N),v.getLength()),v).toReadOnly().setName("bvh_attributes");this.storage.transforms=O,this.storage.nodes=P,this.storage.index=L,this.storage.attributes=X,this.structs.attributes=v,B1.copy(s.matrixWorld).invert(),m.forEach(z=>{this.writeTransformData(z,B1,z.slot,E)}),this.fns.sampleTrianglePoint=Vae(this),this._bvhCache.clear()}updateTransforms(){let{bvh:e,storage:t}=this;e.refit();let r=t.nodes.proxyNode.value;M5(e,null,0,r.array.buffer),r.needsUpdate=!0;let i=t.transforms.proxyNode.value,s=i.array.buffer;B1.copy(e.matrixWorld).invert(),this._getTransformMap(e).forEach(a=>{this.writeTransformData(a,B1,a.slot,s)}),i.needsUpdate=!0}writeTransformData(e,t,r,i){let{structs:s}=this,a=new Float32Array(i),n=new Uint32Array(i),{object:o,instanceId:l}=e;o.isInstancedMesh||o.isBatchedMesh?(o.getMatrixAt(l,nh),nh.premultiply(o.matrixWorld)):nh.copy(o.matrixWorld),nh.premultiply(t),nh.toArray(a,r*s.transform.getLength()),nh.invert(),nh.toArray(a,r*s.transform.getLength()+16);let u=Xae(o);o.isBatchedMesh&&(u=u&&o.getVisibleAt(l)),n[r*s.transform.getLength()+32]=u?1:0}getBVH(e,t,r){let{autogenerateBvh:i,_bvhCache:s}=this,a=null;if(e.boundsTree||e.isSkinnedMesh){let n=e.geometry;if(r.count=n.index?n.index.count:n.attributes.position.count,r.vertexCount=n.attributes.position.count,a=e.boundsTree||null,a===null&&i){let o=e.uuid;a=s.get(o)||new Tae(e),s.set(o,a)}}else if(e.isBatchedMesh){let n=e.getGeometryIdAt(t),o=e.getGeometryRangeAt(n);if(Object.assign(r,o),a=e.boundsTrees[n]||null,a===null&&i){let l=`batched_${e.geometry.uuid}_${o.start}_${o.count}`;a=s.get(l)||new M1(e.geometry,{range:{...r}}),s.set(l,a)}}else{let n=e.geometry;if(r.count=n.index?n.index.count:n.attributes.position.count,r.vertexCount=n.attributes.position.count,a=e.geometry.boundsTree||null,a===null&&i){let o=n.uuid;a=s.get(o)||new M1(n),s.set(o,a)}}return a}getDefaultAttributeValue(e,t){switch(e){case"position":case"color":t.set(1,1,1,1);break;default:t.set(0,0,0,0)}return t}dispose(){let{storage:e}=this;for(let t in e)e[t].value?.dispose()}_getTransformMap(e){let{primitiveBuffer:t,primitiveBufferStride:r}=e,i=new Map;for(let s=0,a=t.length;s({X:Math.round(c.x*I1),Y:Math.round(c.y*I1)}));d.length<3||(oh.Clipper.Orientation(d)!==(u===0)&&d.reverse(),r.push(d))}let i=new oh.Clipper;i.StrictlySimple=!0,i.AddPaths(r,oh.PolyType.ptSubject,!0);let s=new oh.PolyTree;i.Execute(oh.ClipType.ctUnion,s,oh.PolyFillType.pftNonZero,oh.PolyFillType.pftNonZero);let a=[],n=l=>l.Contour().map(u=>new fe(u.X/I1,u.Y/I1)),o=l=>{for(let u of l.Childs()){if(!u.IsHole()){let h=new cp(n(u));h.holes=u.Childs().filter(d=>d.IsHole()).map(d=>new po(n(d))),a.push(h)}o(u)}};return o(s),a}var Im=ds,k5=class aD extends Tp{constructor(t){super(t),this.defaultDPI=90,this.defaultUnit="px"}load(t,r,i,s){let a=this,n=new $O(a.manager);n.setPath(a.path),n.setRequestHeader(a.requestHeader),n.setWithCredentials(a.withCredentials),n.load(t,function(o){try{r(a.parse(o))}catch(l){s?s(l):console.error(l),a.manager.itemError(t)}},i,s)}parse(t){let r=this;function i(W,j){if(W.nodeType!==1)return;W.hasAttribute("filter")&&console.warn("THREE.SVGLoader: Filters are not supported.");let G=N(W),ae=!1,be=null;switch(W.nodeName){case"svg":j=y(W,j);break;case"style":a(W);break;case"g":j=y(W,j);break;case"path":j=y(W,j),W.hasAttribute("d")&&(be=s(W));break;case"rect":j=y(W,j),be=l(W);break;case"polygon":j=y(W,j),be=u(W);break;case"polyline":j=y(W,j),be=h(W);break;case"circle":j=y(W,j),be=d(W);break;case"ellipse":j=y(W,j),be=c(W);break;case"line":j=y(W,j),be=m(W);break;case"defs":ae=!0;break;case"use":j=y(W,j);let $=(W.getAttributeNS("http://www.w3.org/1999/xlink","href")||"").substring(1),U=W.viewportElement.getElementById($);U?i(U,j):console.warn("SVGLoader: 'use node' references non-existent node id: "+$);break;default:}if(be){j.fill!==void 0&&j.fill!=="none"&&!j.fill.startsWith("url")&&be.color.setStyle(j.fill,Im),E(be,Xe),H.push(be);let $=Object.assign({},j);$.strokeWidth=j.strokeWidth*X(Xe),be.userData={node:W,style:$,transform:Xe.clone(),gradients:ne}}let Be=W.childNodes;for(let $=0;$0?Xe.copy(re[re.length-1]):Xe.identity())}function s(W){let j=new nl,G=new fe,ae=new fe,be=new fe,Be=!0,$=!1,U=W.getAttribute("d");if(U===""||U==="none")return null;let J=U.match(/[a-df-z][^a-df-z]*/gi);for(let q=0,se=J.length;q0&&(G.copy(be),j.currentPath.currentPoint.copy(G),Be=!0);break;default:console.warn(pe)}$=!1}return j}function a(W){if(!(!W.sheet||!W.sheet.cssRules||!W.sheet.cssRules.length))for(let j=0;jbe.trim());for(let be=0;be$!==""));ue[ae[be]]=Object.assign(ue[ae[be]]||{},Be)}}}function n(W,j,G,ae,be,Be,$,U){if(j==0||G==0){W.lineTo(U.x,U.y);return}ae=ae*Math.PI/180,j=Math.abs(j),G=Math.abs(G);let J=($.x-U.x)/2,q=($.y-U.y)/2,se=Math.cos(ae)*J+Math.sin(ae)*q,pe=-Math.sin(ae)*J+Math.cos(ae)*q,Te=j*j,we=G*G,ie=se*se,V=pe*pe,Oe=ie/Te+V/we;if(Oe>1){let Rt=Math.sqrt(Oe);j=Rt*j,G=Rt*G,Te=j*j,we=G*G}let tt=Te*V+we*ie,Je=(Te*we-tt)/tt,ct=Math.sqrt(Math.max(0,Je));be===Be&&(ct=-ct);let _e=ct*j*pe/G,nt=-ct*G*se/j,dt=Math.cos(ae)*_e-Math.sin(ae)*nt+($.x+U.x)/2,ft=Math.sin(ae)*_e+Math.cos(ae)*nt+($.y+U.y)/2,Fe=o(1,0,(se-_e)/j,(pe-nt)/G),it=o((se-_e)/j,(pe-nt)/G,(-se-_e)/j,(-pe-nt)/G)%(Math.PI*2);W.currentPath.absellipse(dt,ft,j,G,Fe,Fe+it,Be===0,ae)}function o(W,j,G,ae){let be=W*G+j*ae,Be=Math.sqrt(W*W+j*j)*Math.sqrt(G*G+ae*ae),$=Math.acos(Math.max(-1,Math.min(1,be/Be)));return W*ae-j*G<0&&($=-$),$}function l(W){let j=w(W.getAttribute("x")||0),G=w(W.getAttribute("y")||0),ae=w(W.getAttribute("rx")||W.getAttribute("ry")||0),be=w(W.getAttribute("ry")||W.getAttribute("rx")||0),Be=w(W.getAttribute("width")),$=w(W.getAttribute("height")),U=1-.551915024494,J=new nl;return J.moveTo(j+ae,G),J.lineTo(j+Be-ae,G),(ae!==0||be!==0)&&J.bezierCurveTo(j+Be-ae*U,G,j+Be,G+be*U,j+Be,G+be),J.lineTo(j+Be,G+$-be),(ae!==0||be!==0)&&J.bezierCurveTo(j+Be,G+$-be*U,j+Be-ae*U,G+$,j+Be-ae,G+$),J.lineTo(j+ae,G+$),(ae!==0||be!==0)&&J.bezierCurveTo(j+ae*U,G+$,j,G+$-be*U,j,G+$-be),J.lineTo(j,G+be),(ae!==0||be!==0)&&J.bezierCurveTo(j,G+be*U,j+ae*U,G,j+ae,G),J}function u(W){function j(Be,$,U){let J=w($),q=w(U);be===0?ae.moveTo(J,q):ae.lineTo(J,q),be++}let G=/([+-]?\d*\.?\d+(?:e[+-]?\d+)?)(?:,|\s)([+-]?\d*\.?\d+(?:e[+-]?\d+)?)/g,ae=new nl,be=0;return W.getAttribute("points").replace(G,j),ae.currentPath.autoClose=!0,ae}function h(W){function j(Be,$,U){let J=w($),q=w(U);be===0?ae.moveTo(J,q):ae.lineTo(J,q),be++}let G=/([+-]?\d*\.?\d+(?:e[+-]?\d+)?)(?:,|\s)([+-]?\d*\.?\d+(?:e[+-]?\d+)?)/g,ae=new nl,be=0;return W.getAttribute("points").replace(G,j),ae.currentPath.autoClose=!1,ae}function d(W){let j=w(W.getAttribute("cx")||0),G=w(W.getAttribute("cy")||0),ae=w(W.getAttribute("r")||0),be=new po;be.absarc(j,G,ae,0,Math.PI*2);let Be=new nl;return Be.subPaths.push(be),Be}function c(W){let j=w(W.getAttribute("cx")||0),G=w(W.getAttribute("cy")||0),ae=w(W.getAttribute("rx")||0),be=w(W.getAttribute("ry")||0),Be=new po;Be.absellipse(j,G,ae,be,0,Math.PI*2);let $=new nl;return $.subPaths.push(Be),$}function m(W){let j=w(W.getAttribute("x1")||0),G=w(W.getAttribute("y1")||0),ae=w(W.getAttribute("x2")||0),be=w(W.getAttribute("y2")||0),Be=new nl;return Be.moveTo(j,G),Be.lineTo(ae,be),Be.currentPath.autoClose=!1,Be}function g(W){let j="http://www.w3.org/1999/xlink",G=W.querySelectorAll("linearGradient, radialGradient"),ae=["x1","y1","x2","y2","cx","cy","r","fx","fy","gradientUnits","gradientTransform","spreadMethod"],be={};for(let $ of G){let U=$.getAttribute("id");if(!U)continue;let J={type:$.nodeName==="radialGradient"?"radialGradient":"linearGradient",attrs:{},stops:null,href:null},q=$.getAttributeNS(j,"href")||$.getAttribute("href")||"";q.startsWith("#")&&(J.href=q.substring(1));for(let pe of ae)$.hasAttribute(pe)&&(J.attrs[pe]=$.getAttribute(pe));let se=$.querySelectorAll("stop");if(se.length>0){J.stops=[];for(let pe of se){let Te=pe.getAttribute("stop-color");!Te&&pe.style&&(Te=pe.style["stop-color"]),Te||(Te="#000");let we=pe.getAttribute("stop-opacity");(we===null||we==="")&&pe.style&&(we=pe.style["stop-opacity"]),we=we===null||we===""||we===void 0?1:Math.max(0,Math.min(1,parseFloat(we)));let ie=Math.max(0,Math.min(1,parseFloat(pe.getAttribute("offset")||"0")));J.stops.push({offset:ie,color:Te,opacity:we})}}be[U]=J}function Be($,U){let J=be[$];if(!J||U.has($))return J;if(U.add($),J.href&&be[J.href]){let q=Be(J.href,U);if(q){J.stops||(J.stops=q.stops);for(let se in q.attrs)se in J.attrs||(J.attrs[se]=q.attrs[se])}}return J}for(let $ in be)Be($,new Set);for(let $ in be){let U=function(Te){return typeof Te!="string"?0:Te.endsWith("%")?parseFloat(Te)/100:w(Te)},J=be[$],q=J.attrs,se=q.gradientUnits==="userSpaceOnUse"?"userSpaceOnUse":"objectBoundingBox",pe={type:J.type,gradientUnits:se,spreadMethod:q.spreadMethod==="reflect"||q.spreadMethod==="repeat"?q.spreadMethod:"pad",gradientTransform:null,stops:(J.stops||[]).slice().sort((Te,we)=>Te.offset-we.offset)};if(q.gradientTransform&&(pe.gradientTransform=new Dr,R(q.gradientTransform,pe.gradientTransform)),J.type==="linearGradient")pe.x1=q.x1!==void 0?U(q.x1):0,pe.y1=q.y1!==void 0?U(q.y1):0,pe.x2=q.x2!==void 0?U(q.x2):se==="objectBoundingBox"?1:0,pe.y2=q.y2!==void 0?U(q.y2):0;else{let Te=se==="objectBoundingBox"?.5:0,we=se==="objectBoundingBox"?.5:0;pe.cx=q.cx!==void 0?U(q.cx):Te,pe.cy=q.cy!==void 0?U(q.cy):Te,pe.r=q.r!==void 0?U(q.r):we,pe.fx=q.fx!==void 0?U(q.fx):pe.cx,pe.fy=q.fy!==void 0?U(q.fy):pe.cy}ne[$]=pe}}function y(W,j){j=Object.assign({},j);let G={};if(W.hasAttribute("class")){let $=W.getAttribute("class").split(/\s/).filter(Boolean).map(U=>U.trim());for(let U=0;U<$.length;U++)G=Object.assign(G,ue["."+$[U]])}W.hasAttribute("id")&&(G=Object.assign(G,ue["#"+W.getAttribute("id")]));function ae($,U,J){J===void 0&&(J=function(q){return q}),W.hasAttribute($)&&(j[U]=J(W.getAttribute($))),G[U]&&(j[U]=J(G[U])),W.style&&W.style[$]!==""&&(j[U]=J(W.style[$]))}function be($){return Math.max(0,Math.min(1,w($)))}function Be($){return Math.max(0,w($))}return ae("fill","fill"),ae("fill-opacity","fillOpacity",be),ae("fill-rule","fillRule"),ae("opacity","opacity",be),ae("stroke","stroke"),ae("stroke-opacity","strokeOpacity",be),ae("stroke-width","strokeWidth",Be),ae("stroke-linejoin","strokeLineJoin"),ae("stroke-linecap","strokeLineCap"),ae("stroke-miterlimit","strokeMiterLimit",Be),ae("visibility","visibility"),j}function b(W,j){return W-(j-W)}function v(W,j,G){if(typeof W!="string")throw new TypeError("Invalid input: "+typeof W);let ae={SEPARATOR:/[ \t\r\n\,.\-+]/,WHITESPACE:/[ \t\r\n]/,DIGIT:/[\d]/,SIGN:/[-+]/,POINT:/\./,COMMA:/,/,EXP:/e/i,FLAGS:/[01]/},be=0,Be=1,$=2,U=3,J=be,q=!0,se="",pe="",Te=[];function we(tt,Je,ct){let _e=new SyntaxError('Unexpected character "'+tt+'" at index '+Je+".");throw _e.partial=ct,_e}function ie(){se!==""&&(pe===""?Te.push(Number(se)):Te.push(Number(se)*Math.pow(10,Number(pe)))),se="",pe=""}let V,Oe=W.length;for(let tt=0;tt0&&j.premultiply(re[re.length-1]),Xe.copy(j),re.push(j),j}function C(W){let j=new Dr;if(W.nodeName==="use"&&(W.hasAttribute("x")||W.hasAttribute("y"))){let G=w(W.getAttribute("x")||0),ae=w(W.getAttribute("y")||0);j.makeTranslation(G,ae)}return W.hasAttribute("transform")&&R(W.getAttribute("transform"),j),j}function R(W,j){let G=ce,ae=W.split(")");for(let be=ae.length-1;be>=0;be--){let Be=ae[be].trim();if(Be==="")continue;let $=Be.indexOf("("),U=Be.length;if($>0&&$=1){let se=q[0],pe=0;q.length>=2&&(pe=q[1]),G.makeTranslation(se,pe)}break;case"rotate":if(q.length>=1){let se=0,pe=0,Te=0;se=q[0]*Math.PI/180,q.length>=3&&(pe=q[1],Te=q[2]),ge.makeTranslation(-pe,-Te),ye.makeRotation(se),oe.multiplyMatrices(ye,ge),ge.makeTranslation(pe,Te),G.multiplyMatrices(ge,oe)}break;case"scale":if(q.length>=1){let se=q[0],pe=se;q.length>=2&&(pe=q[1]),G.makeScale(se,pe)}break;case"skewX":q.length===1&&G.set(1,Math.tan(q[0]*Math.PI/180),0,0,1,0,0,0,1);break;case"skewY":q.length===1&&G.set(1,0,0,Math.tan(q[0]*Math.PI/180),1,0,0,0,1);break;case"matrix":q.length===6&&G.set(q[0],q[2],q[4],q[1],q[3],q[5],0,0,1);break}j.premultiply(G)}}return j}function E(W,j){function G($){Ie.set($.x,$.y,1).applyMatrix3(j),$.set(Ie.x,Ie.y)}function ae($){let U=$.xRadius,J=$.yRadius,q=Math.cos($.aRotation),se=Math.sin($.aRotation),pe=new F(U*q,U*se,0),Te=new F(-J*se,J*q,0),we=pe.applyMatrix3(j),ie=Te.applyMatrix3(j),V=ce.set(we.x,ie.x,0,we.y,ie.y,0,0,0,1),Oe=ge.copy(V).invert(),tt=ye.copy(Oe).transpose().multiply(Oe).elements,Je=z(tt[0],tt[1],tt[4]),ct=Math.sqrt(Je.rt1),_e=Math.sqrt(Je.rt2);if($.xRadius=1/ct,$.yRadius=1/_e,$.aRotation=Math.atan2(Je.sn,Je.cs),!(($.aEndAngle-$.aStartAngle)%(2*Math.PI){let{x:Rt,y:Ft}=new F(Math.cos(it),Math.sin(it),0).applyMatrix3(ft);return Math.atan2(Ft,Rt)};$.aStartAngle=Fe($.aStartAngle),$.aEndAngle=Fe($.aEndAngle),P(j)&&($.aClockwise=!$.aClockwise)}}function be($){let U=O(j),J=L(j);$.xRadius*=U,$.yRadius*=J;let q=U>Number.EPSILON?Math.atan2(j.elements[1],j.elements[0]):Math.atan2(-j.elements[3],j.elements[4]);$.aRotation+=q,P(j)&&($.aStartAngle*=-1,$.aEndAngle*=-1,$.aClockwise=!$.aClockwise)}let Be=W.subPaths;for(let $=0,U=Be.length;$Number.EPSILON}function O(W){let j=W.elements;return Math.sqrt(j[0]*j[0]+j[1]*j[1])}function L(W){let j=W.elements;return Math.sqrt(j[3]*j[3]+j[4]*j[4])}function X(W){let j=W.elements,G=j[0]*j[4]-j[1]*j[3];return Math.sqrt(Math.abs(G))}function z(W,j,G){let ae,be,Be,$,U,J=W+G,q=W-G,se=Math.sqrt(q*q+4*j*j);return J>0?(ae=.5*(J+se),U=1/ae,be=W*U*G-j*U*j):J<0?be=.5*(J-se):(ae=.5*se,be=-.5*se),q>0?Be=q+se:Be=q-se,Math.abs(Be)>2*Math.abs(j)?(U=-2*j/Be,$=1/Math.sqrt(1+U*U),Be=U*$):Math.abs(j)===0?(Be=1,$=0):(U=-.5*Be/j,Be=1/Math.sqrt(1+U*U),$=U*Be),q>0&&(U=Be,Be=-$,$=U),{rt1:ae,rt2:be,cs:Be,sn:$}}let H=[],ue={},ne={},re=[],ce=new Dr,ge=new Dr,ye=new Dr,oe=new Dr,Ae=new fe,Ie=new F,Xe=new Dr,at=new DOMParser().parseFromString(t,"image/svg+xml");return g(at),i(at.documentElement,{fill:"#000",fillOpacity:1,strokeOpacity:1,strokeWidth:1,strokeLineJoin:"miter",strokeLineCap:"butt",strokeMiterLimit:4}),{paths:H,gradients:ne,xml:at.documentElement}}static createFillMaterial(t){let r=t.userData.style;if(r.fill===void 0||r.fill==="none")return null;let i=t.color,s=null,a=D5.exec(r.fill);if(a){let o=t.userData.gradients&&t.userData.gradients[a[1]];s=Yae(o,t)}let n=new mn({opacity:r.fillOpacity*(r.opacity||1),transparent:!0,side:hs,depthWrite:!1});return s!==null?n.map=s:n.color=i,n}static createStrokeMaterial(t){let r=t.userData.style;return r.stroke===void 0||r.stroke==="none"?null:(D5.test(r.stroke)&&console.warn("THREE.SVGLoader: Gradient strokes are not supported."),new mn({color:new gt().setStyle(r.stroke,Im),opacity:r.strokeOpacity*(r.opacity||1),transparent:!0,side:hs,depthWrite:!1}))}static createShapes(t){return console.warn("SVGLoader: createShapes() is deprecated. Use shapePath.toShapes() instead."),t.toShapes()}static getStrokeStyle(t,r,i,s,a){return t=t!==void 0?t:1,r=r!==void 0?r:"#000",i=i!==void 0?i:"miter",s=s!==void 0?s:"butt",a=a!==void 0?a:4,{strokeColor:r,strokeWidth:t,strokeLineJoin:i,strokeLineCap:s,strokeMiterLimit:a}}static pointsToStroke(t,r,i,s){let a=[],n=[],o=[];if(aD.pointsToStrokeWithBuffers(t,r,i,s,a,n,o)===0)return null;let l=new ps;return l.setAttribute("position",new tr(a,3)),l.setAttribute("normal",new tr(n,3)),l.setAttribute("uv",new tr(o,2)),l}static pointsToStrokeWithBuffers(t,r,i,s,a,n,o,l){let u=new fe,h=new fe,d=new fe,c=new fe,m=new fe,g=new fe,y=new fe,b=new fe,v=new fe,S=new fe,T=new fe,w=new fe,N=new fe,C=new fe,R=new fe,E=new fe,P=new fe;i=i!==void 0?i:12,s=s!==void 0?s:.001,l=l!==void 0?l:0,t=$(t);let I=t.length;if(I<2)return 0;let O=t[0].equals(t[I-1]),L,X=t[0],z,H=r.strokeWidth/2,ue=1/(I-1),ne=0,re,ce,ge,ye,oe=!1,Ae=0,Ie=l*3,Xe=l*2;at(t[0],t[1],u).multiplyScalar(H),b.copy(t[0]).sub(u),v.copy(t[0]).add(u),S.copy(b),T.copy(v);for(let U=1;UNumber.EPSILON){let se=H/q;d.multiplyScalar(-se),c.subVectors(L,X),m.copy(c).setLength(se).add(d),E.copy(m).negate();let pe=m.length(),Te=c.length();c.divideScalar(Te),g.subVectors(z,L);let we=g.length();if(g.divideScalar(we),c.dot(E)0)&&E.copy(ie)}switch(ye=!1,ce?ge?(R.copy(E),N.copy(E)):(C.copy(E),w.copy(E)):G(),r.strokeLineJoin){case"bevel":ae(ge,ce,re);break;case"round":be(ge,ce),ge?j(L,w,C,re,0):j(L,R,N,re,1);break;default:let ie=H*r.strokeMiterLimit/pe;if(ie<1)if(r.strokeLineJoin!=="miter-clip"){ae(ge,ce,re);break}else be(ge,ce),ge?(g.subVectors(P,w).multiplyScalar(ie).add(w),y.subVectors(P,C).multiplyScalar(ie).add(C),W(w,re,0),W(g,re,0),W(L,re,.5),W(L,re,.5),W(g,re,0),W(y,re,0),W(L,re,.5),W(y,re,0),W(C,re,0)):(g.subVectors(P,N).multiplyScalar(ie).add(N),y.subVectors(P,R).multiplyScalar(ie).add(R),W(N,re,1),W(g,re,1),W(L,re,.5),W(L,re,.5),W(g,re,1),W(y,re,1),W(L,re,.5),W(y,re,1),W(R,re,1));else ce?(ge?(W(v,ne,1),W(b,ne,0),W(P,re,0),W(v,ne,1),W(P,re,0),W(E,re,1)):(W(v,ne,1),W(b,ne,0),W(P,re,1),W(b,ne,0),W(E,re,0),W(P,re,1)),ge?C.copy(P):R.copy(P)):ge?(W(w,re,0),W(P,re,0),W(L,re,.5),W(L,re,.5),W(P,re,0),W(C,re,0)):(W(N,re,1),W(P,re,1),W(L,re,.5),W(L,re,.5),W(P,re,1),W(R,re,1)),ye=!0;break}}else G()}else G();!O&&U===I-1&&Be(t[0],S,T,ge,!0,ne),ne=re,X=L,b.copy(C),v.copy(R)}if(!O)Be(L,w,N,ge,!1,re);else if(ce&&a){let U=P,J=E;oe!==ge&&(U=E,J=P),ge?(ye||oe)&&(J.toArray(a,0),J.toArray(a,9),ye&&U.toArray(a,3)):(ye||!oe)&&(J.toArray(a,3),J.toArray(a,9),ye&&U.toArray(a,0))}if(a){let U=[new fe,new fe,new fe],J=l*3;for(let q=J;q=s&&q.push(U[se]);return q.push(U[U.length-1]),q}}},D5=/^\s*url\(\s*(?:["']\s*)?#([^)'"\s]+)(?:\s*["'])?\s*\)\s*$/;function Yae(e,t,r=256){if(!e||!Array.isArray(e.stops)||e.stops.length===0)return null;let i=t.userData.transform,s=e.gradientUnits==="objectBoundingBox",a=null;if(s&&(a=Zae(t,i),a===null))return null;function n(d,c,m){m.set(d,c,1),e.gradientTransform&&m.applyMatrix3(e.gradientTransform),s&&m.set(a.minX+m.x*a.width,a.minY+m.y*a.height,1),i&&m.applyMatrix3(i)}let o=document.createElement("canvas"),l;if(e.type==="linearGradient"){o.width=r,o.height=1;let d=o.getContext("2d"),c=d.createLinearGradient(0,0,r,0);O5(c,e.stops),d.fillStyle=c,d.fillRect(0,0,r,1);let m=new F,g=new F;n(e.x1,e.y1,m),n(e.x2,e.y2,g);let y=g.x-m.x,b=g.y-m.y,v=y*y+b*b||1e-20,S=y/v,T=b/v,w=-(S*m.x+T*m.y);l=new Dr().set(S,T,w,0,0,.5,0,0,1)}else{let d=e.cx,c=e.cy,m=e.fx,g=e.fy,y=e.r;if(e.gradientTransform){let R=new F;R.set(d,c,1).applyMatrix3(e.gradientTransform),d=R.x,c=R.y,R.set(m,g,1).applyMatrix3(e.gradientTransform),m=R.x,g=R.y}if(s&&(d=a.minX+d*a.width,c=a.minY+c*a.height,m=a.minX+m*a.width,g=a.minY+g*a.height,y=y*Math.sqrt((a.width*a.width+a.height*a.height)/2)),y<=0)return null;o.width=r,o.height=r;let b=o.getContext("2d"),v=d-y,S=c-y,T=2*y,w=r/T;b.setTransform(w,0,0,w,-v*w,-S*w);let N=b.createRadialGradient(m,g,0,d,c,y);O5(N,e.stops),b.fillStyle=N,b.fillRect(v,S,T,T);let C=i?i.clone().invert():new Dr;l=new Dr().set(1/T,0,-v/T,0,1/T,-S/T,0,0,1).multiply(C)}let u=new j4(o);u.colorSpace=Im,u.flipY=!1,u.matrixAutoUpdate=!1,u.matrix=l;let h=e.spreadMethod==="reflect"?Qo:e.spreadMethod==="repeat"?to:Ti;return u.wrapS=h,u.wrapT=h,u}function Zae(e,t){let r=t?t.clone().invert():null,i=new fe,s=new ob;for(let a of e.subPaths)for(let n of a.getPoints())i.copy(n),r&&i.applyMatrix3(r),s.expandByPoint(i);return s.isEmpty()?null:{minX:s.min.x,minY:s.min.y,width:s.max.x-s.min.x,height:s.max.y-s.min.y}}function O5(e,t){let r=new gt;for(let i of t){let s=i.color;if(i.opacity<1){r.setStyle(i.color,Im);let a=/rgb\(([^)]+)\)/.exec(r.getStyle(Im));a&&(s=`rgba(${a[1]},${i.opacity})`)}e.addColorStop(Math.max(0,Math.min(1,i.offset)),s)}}function U5(e,t=1e-4){t=Math.max(t,Number.EPSILON);let r={},i=e.getIndex(),s=e.getAttribute("position"),a=i?i.count:s.count,n=0,o=Object.keys(e.attributes),l={},u={},h=[],d=["getX","getY","getZ","getW"],c=["setX","setY","setZ","setW"];for(let S=0,T=o.length;S{let P=new R.array.constructor(R.count*R.itemSize);u[w][E]=new R.constructor(P,R.itemSize,R.normalized)}))}let m=t*.5,g=Math.log10(1/t),y=Math.pow(10,g),b=m*y;for(let S=0;Sn&&(L+=ce,X+=ge,z+=ye)}let H=1/(Math.sqrt(L*L+X*X+z*z)||1);T[3*I+0]=L*H,T[3*I+1]=X*H,T[3*I+2]=z*H}}return r.setAttribute("normal",new _i(T,3,!1)),r}var Jae={width:2.6,depth:.22,bevelThickness:.06,bevelSize:.05,bevelOffset:0,bevelSegments:5,curveSegments:24,cornerRadius:.03,creaseAngle:40,sdfRes:64};function V5(e,t){e=e.filter((a,n)=>n===0||a.distanceToSquared(e[n-1])>1e-18),e.length>1&&e[0].distanceToSquared(e[e.length-1])<1e-18&&(e=e.slice(0,-1));let r=e.length,i=new po;if(t<=0||r<3){i.moveTo(e[0].x,e[0].y);for(let a=1;a{n===0?i.moveTo(a.a.x,a.a.y):i.lineTo(a.a.x,a.a.y),a.sharp&&i.quadraticCurveTo(a.c.x,a.c.y,a.b.x,a.b.y)}),i.closePath(),i}async function Qae(e,t={}){let r={...Jae,...t},i=await fetch(e).then(d=>d.ok?d.text():Promise.reject(new Error("no logo"))),s=new k5().parse(i),a=[];for(let d of s.paths)a.push(...d.toShapes(!0));if(!a.length)return[];let n=new ob;for(let d of a)for(let c of d.getPoints(8))n.expandByPoint(c);let o=n.getSize(new fe),l=n.getCenter(new fe),u=r.width/Math.max(o.x,o.y),h=d=>new fe((d.x-l.x)*u,-(d.y-l.y)*u);return a.map(d=>{let c=new cp(d.getPoints(r.curveSegments).map(h));return c.holes=d.holes.map(m=>new po(m.getPoints(r.curveSegments).map(h))),c})}function G5(e,t,r){let i=t.cornerRadius*r,s=L5(e,t.curveSegments).map(l=>{let u=V5(l.getPoints(t.curveSegments),i),h=new cp(u.getPoints(t.curveSegments));return h.holes=l.holes.map(d=>V5(d.getPoints(t.curveSegments),i)),h}),a=L5(s,t.curveSegments),n=t.bevelThickness>0||t.bevelSize>0,o=new wO(a,{depth:t.depth*r,bevelEnabled:n,bevelThickness:t.bevelThickness*r,bevelSize:t.bevelSize*r,bevelOffset:t.bevelOffset*r,bevelSegments:Math.max(1,Math.round(t.bevelSegments)),curveSegments:Math.max(2,Math.round(t.curveSegments))});if(o.center(),o=U5(o,1e-5),o=z5(o,Bt.degToRad(t.creaseAngle)),o.computeBoundingBox(),t.bevelThickness>0&&t.bevelSize>0){let l=o.getAttribute("position"),u=o.getAttribute("normal"),{min:h,max:d}=o.boundingBox,c=Math.max((d.z-h.z)*1e-6,1e-8);for(let m=0;m{let d=n.value,c=(l/(2*d)+.5)*t-.5,m=(u/(2*d)+.5)*t-.5,g=(h/(2*d)+.5)*t-.5,y=Math.max(0,Math.min(t-2,Math.floor(c))),b=Math.max(0,Math.min(t-2,Math.floor(m))),v=Math.max(0,Math.min(t-2,Math.floor(g))),S=Math.max(0,Math.min(1,c-y)),T=Math.max(0,Math.min(1,m-b)),w=Math.max(0,Math.min(1,g-v)),N=(z,H,ue)=>e[z+H*t+ue*t*t],C=N(y,b,v)*(1-S)+N(y+1,b,v)*S,R=N(y,b+1,v)*(1-S)+N(y+1,b+1,v)*S,E=N(y,b,v+1)*(1-S)+N(y+1,b,v+1)*S,P=N(y,b+1,v+1)*(1-S)+N(y+1,b+1,v+1)*S,I=C*(1-T)+R*T,O=E*(1-T)+P*T,L=Math.abs(l)>d||Math.abs(u)>d||Math.abs(h)>d,X=(I*(1-w)+O*w)*2*a-a;return L?Math.max(X,Math.hypot(Math.max(Math.abs(l)-d,0),Math.max(Math.abs(u)-d,0),Math.max(Math.abs(h)-d,0))):X},sampleDomain:n}}function Kae(e,t,r,i=t){let s=Fm(e),a=Math.min(s.x,s.y,s.z),n=new M1(e),o=Math.max(16,Math.round(r)),l=new Float32Array(o*o*o),u=new F,h=t,d=2*i/o,c=Math.min(h,Math.max(a*2.5,d*14)),m=e.boundingBox,g=c*c,y={},b=new ld(new F,new F(0,0,1)),v=new Uint8Array(o);for(let S=0;S({z:P.distance-i-1,delta:P.face.normal.z<0?1:-1})).sort((P,I)=>P.z-I.z),R=0,E=0;for(let P=0;Pg?null:n.closestPointToPoint(u,y,0,c),z=X?X.distance:h;v[P]&&(z=-z),l[T+S*o+P*o*o]=Math.min(1,Math.max(0,(z+h)/(2*h)))}}return F1(l,o,t,a,i)}var{Fn:ene,instanceIndex:tne,uint:L1,vec3:k1,float:W5,If:rne,dot:ine,max:j5,instancedArray:sne,uniform:ane}=Jr;async function nne(e,t,r,i,s){let a=performance.now(),n=Fm(t),o=Math.min(n.x,n.y,n.z),l=Math.max(16,Math.round(i)),u=r,h=2*s/l,d=Math.min(u,Math.max(o*2.5,h*14)),c=new M1(t);t.boundsTree=c;let m=new $ae(t);m.update();let g=performance.now(),y=Pi` fn frostClosest(p:vec3f,cap:f32)->f32 { var hit:${Em}; hit.found=true; hit.distanceSq=cap*cap; let found=${m.fns.closestPointToPoint}(p,&hit); return select(-1.0,sqrt(hit.distanceSq),found); }`,b=sne(l*l*l,"float"),v=ane(0,"uint"),S=t.boundingBox,T=k1(S.min.x,S.min.y,S.min.z),w=k1(S.max.x,S.max.y,S.max.z),N=8,C=l*l*N,R=ene(()=>{let re=tne.add(v),ce=re.mod(L1(l)),ge=re.div(L1(l)).mod(L1(l)),ye=re.div(L1(l*l)),oe=k1(ce,ge,ye).add(.5).div(l).sub(.5).mul(2*s).toVar(),Ae=j5(j5(T.sub(oe),oe.sub(w)),k1(0)),Ie=W5(-1).toVar();rne(ine(Ae,Ae).lessThanEqual(d*d),()=>{Ie.assign(y(oe,W5(d)))}),b.element(re).assign(Ie)})().compute(C,[64]);for(let re=0;re>>0;let ce=z%(l*l*l),ge=ce%l,ye=Math.floor(ce/l)%l,oe=Math.floor(ce/(l*l));H.set(((ge+.5)/l-.5)*2*s,((ye+.5)/l-.5)*2*s,((oe+.5)/l-.5)*2*s);let Ae=c.closestPointToPoint(H,{},0,d);if(Ae&&Ae.distance<=d&&E[ce]>=0){let Ie=Math.abs(Ae.distance-E[ce]);I=Math.max(I,Ie),O+=Ie*Ie,L++}else!!(Ae&&Ae.distance<=d)!=E[ce]>=0&&X++}let ue=new ld(new F,new F(0,0,1));for(let re=0;re({z:Xe.distance-s-1,delta:Xe.face.normal.z<0?1:-1})).sort((Xe,at)=>Xe.z-at.z),Ae=0,Ie=0;for(let Xe=0;Xe=0?E[W]:u;Ie!==0&&(j=-j),E[W]=Math.min(1,Math.max(0,(j+u)/(2*u)))}}let ne=performance.now();return th.sdf.push({n:l,triangles:t.index.count/3,packMs:g-a,gpuMs:P-g,signMs:ne-P,totalMs:ne-a,audit:{samples:2048,compared:L,maxDistanceError:I,rmsDistanceError:Math.sqrt(O/Math.max(1,L)),missing:X}}),m.dispose(),b.value.dispose(),R.dispose(),F1(E,l,r,o,s)}var{Fn:one,vec3:lne,vec4:H5,float:k0e,uint:D1,uniform:O1,instanceIndex:une,uvec3:hne,ivec3:D0e,texture3D:dne,textureStore:cne,dot:X5,abs:pne}=Jr,mne=class{constructor(e,t,r,i=128){this.renderer=e,this.bound=t,this.seed=r,this.res=i;for(let s=0;s<2;s++){let a=new d_(i,i,i);a.type=Er,a.format=pi,a.minFilter=a.magFilter=or;let n=O1(new F),o=O1(1),l=O1(.5),u=O1(r+s*7),h=one(()=>{let d=une,c=hne(d.mod(D1(i)),d.div(D1(i)).mod(D1(i)),d.div(D1(i*i))),m=lne(c).add(.5).div(i).sub(.5).mul(o.mul(2)).add(n).toVar(),g=bm(m,u,l).toVar();cne(a,c,H5(g.xyz,X5(g.xyz,m).add(g.w))).toWriteOnly()})().compute(i**3,[64]);this.entries.push({tex:a,center:n,extent:o,coverage:l,s:u,kernel:h})}this.update()}signature="";entries=[];update(){let e=le.ice.cracks,t=JSON.stringify([e.largeScale,e.fineScale,e.warp,e.coverage,e.fineCoverage,this.seed]);if(t===this.signature)return;this.signature=t;let r=new F(this.seed*.731,this.seed*.137,this.seed*.529),i=e.fineScale/e.largeScale,s=this.entries[0],a=this.entries[1];s.center.value.copy(r).multiplyScalar(.37),s.extent.value=this.bound*e.largeScale+Math.abs(e.warp)*2+.1,s.coverage.value=e.coverage,a.center.value.copy(s.center.value).multiplyScalar(i).add(r),a.extent.value=s.extent.value*i,a.coverage.value=e.fineCoverage;for(let n of this.entries)this.renderer.compute(n.kernel);th.materialPlanes={res:this.res,bytes:2*this.res**3*16,builds:(th.materialPlanes?.builds||0)+1}}sample(e,t=!1){let r=this.entries[+t],i=e.sub(r.center).div(r.extent.mul(2)).add(.5),s=dne(r.tex).sample(i).level(0).toVar();return H5(s.xyz,pne(s.w.sub(X5(s.xyz,e))))}dispose(){for(let e of this.entries)e.tex.dispose(),e.kernel.dispose()}},{pass:fne,mrt:gne,vec4:$5,positionLocal:yne,normalLocal:xne}=Jr;function vne(e,t){let r=new bg,i=new Pd;i.side=Cs,i.toneMapped=!1;let s=new Mi(e,i);s.frustumCulled=!1,s.matrixAutoUpdate=!1,r.add(s);let a=fne(r,t,{type:Er,samples:0});a.setMRT(gne({output:$5(yne,1),normal:$5(xne,0)}));let n=a.getTextureNode("output"),o=a.getTextureNode("normal"),l=a.getTextureNode("depth");for(let u of["output","normal"]){let h=a.getTexture(u);h.minFilter=h.magFilter=or,h.generateMipmaps=!1}return{surfacePass:a,position:n,normal:o,depth:l,mesh:s,material:i,update(u,h){s.geometry=u.geometry,s.matrix.copy(u.matrixWorld),s.matrixWorld.copy(u.matrixWorld),s.visible=u.visible,a.setResolutionScale(h)},dispose(){a.dispose(),i.dispose()}}}function bne(e,t=1024){let r=new Float32Array(t*t*4),i=e.image.data,s=e.image.width,a=e.image.height,n=le.ice,o=n.ior,l=((o-1)/(o+1))**2,u=new gt(n.attenuationColor),h=[u.r,u.g,u.b],d=(m,g,y,b)=>{let v=((Math.atan2(y,m)/(2*Math.PI)+.5)%1+1)%1,S=Math.asin(Math.max(-1,Math.min(1,g)))/Math.PI+.5,T=v*s-.5,w=S*a-.5,N=Math.floor(T),C=Math.floor(w),R=T-N,E=w-C,P=(I,O)=>i[(Math.max(0,Math.min(a-1,O))*s+(I+s)%s)*4+b];return(P(N,C)*(1-R)+P(N+1,C)*R)*(1-E)+(P(N,C+1)*(1-R)+P(N+1,C+1)*R)*E};for(let m=0;m=1){let ce=.99999/Math.sqrt(v);y*=ce,b*=ce}let S=Math.sqrt(Math.max(1e-8,1-y*y-b*b)),T=1/o,w=T*S-Math.sqrt(1-T*T*(1-S*S)),N=w*y,C=w*b,R=-T+w*S,E=-2*(y*N+b*C+S*R),P=y+N*E,I=b+C*E,O=S+R*E,L=N*P+C*I+R*O,X=1-o*o*(1-L*L),z=l+(1-l)*(1-S)**5,H=o*L-Math.sqrt(Math.max(0,X)),ue=o*N-H*P,ne=o*C-H*I,re=o*R-H*O;for(let ce=0;ce<3;ce++){let ge=Math.pow(h[ce],E*n.thicknessScale/Math.max(n.attenuationDistance,.01));r[(g+m*t)*4+ce]=d(2*S*y,2*S*b,2*S*S-1,ce)*z+d(ue,ne,re,ce)*(1-z)*(n.backlight??.4)*ge}r[(g+m*t)*4+3]=1}let c=new kg(r,t,t,pi,Er);return c.colorSpace=Xh,c.minFilter=c.magFilter=lr,c.needsUpdate=!0,c}var ta={t:0,dt:.016666666666666666,frame:0,paused:!1,stepRequested:!1,_last:performance.now()/1e3,tick(e=performance.now()/1e3){let t=Math.min(.05,Math.max(0,e-this._last));if(this._last=e,this.paused&&!this.stepRequested){this.dt=0;return}this.stepRequested=!1,this.dt=this.paused?.016666666666666666:t,this.t+=this.dt,this.frame++}},Oo=(e,t,r,i)=>r<=0?t:e+(t-e)*(1-Math.exp(-i/r));function Lm(e){let t=e*1664525+1013904223>>>0;return()=>{t=t+1831565813>>>0;let r=t;return r=Math.imul(r^r>>>15,r|1),r^=r+Math.imul(r^r>>>7,r|61),((r^r>>>14)>>>0)/4294967296}}var{Fn:Tne,vec2:U1,vec3:q5,vec4:Sne,float:O0e,uniform:ql,screenUV:Y5,screenSize:Z5,mix:J5,pow:_ne,smoothstep:dw,fract:U0e,sin:wne,dot:Mne,length:Q5,max:Nne}=Jr;function z1(e,t){let r=Z5.x.div(Z5.y),i=U1(t.x.sub(e.uCenter.x).mul(r),t.y.sub(e.uCenter.y)),s=Q5(i).div(e.uRadius),a=_ne(dw(0,1,s),e.uFalloff),n=dw(0,1,t.y.oneMinus().mul(1.15)),o=dw(.35,1.3,Q5(U1(t.x.sub(.5).mul(r),t.y.sub(.5)))),l=J5(e.uTop,e.uMid,a);return J5(l,e.uBottom,n.mul(o).mul(.85))}function Ane(){let e=ql(new gt("#2a2a2a")),t=ql(new gt("#050505")),r=ql(new gt("#030303")),i=ql(new fe(.5,1.02)),s=ql(.55),a=ql(1.6),n=ql(1),o=ql(0),l={uTop:e,uMid:t,uBottom:r,uCenter:i,uRadius:s,uFalloff:a,uNoise:n,uTime:o};return{node:Tne(()=>{let u=z1(l,Y5).toVar(),h=Y5,d=Po(q5(h.mul(U1(37,21)),o.mul(.37))),c=wne(Mne(h,U1(5.3,7.1)).add(o.mul(.05))).mul(.5).add(.5).sub(.5).mul(1/255).mul(n).add(d.sub(.5).mul(1/255).mul(n));return Sne(Nne(u.add(q5(c)),0),1)})(),uniforms:l}}function Cne(e=1024,t=512){let r=new Float32Array(e*t*4),i=new kg(r,e,t,pi,Er);i.mapping=kf,i.colorSpace=Xh,i.wrapS=to,i.wrapT=Ti,i.minFilter=i.magFilter=lr;let s=(o,l,u)=>{let h=Math.max(0,Math.min(1,(u-o)/(l-o)));return h*h*(3-2*h)},a=Array.from({length:e*t},(o,l)=>{let u=(l%e+.5)/e,h=(Math.floor(l/e)+.5)/t,d=(u-.5)*Math.PI*2,c=(h-.5)*Math.PI;return new F(Math.cos(c)*Math.cos(d),Math.sin(c),Math.cos(c)*Math.sin(d))});function n(o){let l=(c,m,g,y,b,v)=>{let S=Bt.degToRad(g),T=Bt.degToRad(y),w=new F(Math.cos(S)*Math.sin(T),Math.sin(S),Math.cos(S)*Math.cos(T)),N=new F().crossVectors(new F(0,1,0),w).normalize(),C=new F().crossVectors(w,N);return{color:new gt(c),power:m,normal:w,right:N,up:C,w:b,h:v}},u=[l(o.key.color,o.envSoftbox*5,o.key.elevation,o.key.azimuth,.42*o.key.size,.65*o.key.size),l(o.rimColor,o.envRim*6,o.rimElevation,o.rimAzimuth,.1*o.rimSize,.9*o.rimSize),l(o.accentCool.color,o.accentCool.reflection*4,o.accentCool.elevation,o.accentCool.azimuth,.13*o.accentCool.size,.75*o.accentCool.size),l(o.accentWarm.color,o.accentWarm.reflection*4,o.accentWarm.elevation,o.accentWarm.azimuth,.2*o.accentWarm.size,.7*o.accentWarm.size)],h=new gt(o.fillColor),d=new gt(o.fillGroundColor);a.forEach((c,m)=>{let g=s(-.3,.8,c.y),y=o.envFill*.055,b=(d.r*(1-g)+h.r*g)*y,v=(d.g*(1-g)+h.g*g)*y,S=(d.b*(1-g)+h.b*g)*y;for(let T of u){let w=c.dot(T.normal);if(w<=0)continue;let N=Math.abs(c.dot(T.right)/w),C=Math.abs(c.dot(T.up)/w),R=(1-s(T.w*.45,T.w,N))*(1-s(T.h*.45,T.h,C)),E=T.power*R;b+=T.color.r*E,v+=T.color.g*E,S+=T.color.b*E}r.set([b,v,S,1],m*4)}),i.needsUpdate=!0,i.needsPMREMUpdate=!0}return{texture:i,update:n}}var Rne=class{key=new $g(16777215,3);fill=new EN(16777215,0,.2);rim=new Xg(16777215,1,0,Math.PI/3,1,0);accentCool=new $g(13098495,.35);accentWarm=new $g(16768964,.22);group=new pn;mapSize=0;settingsVersion=-1;constructor(){this.key.castShadow=!0,this.key.shadow.camera.left=-5.5,this.key.shadow.camera.right=5.5,this.key.shadow.camera.top=5.5,this.key.shadow.camera.bottom=-5.5,this.key.shadow.camera.near=2,this.key.shadow.camera.far=30,this.key.target.position.set(0,0,0),this.rim.target.position.set(0,0,0),this.group.add(this.key,this.key.target,this.fill,this.rim,this.rim.target,this.accentCool,this.accentCool.target,this.accentWarm,this.accentWarm.target)}update(e,t){let r=le.lighting,i=Math.sin(e*2*Math.PI/Math.max(1,r.sway.period))*r.sway.amplitude,s=Math.sin(e*2*Math.PI/Math.max(1,r.sway.period)*.61+.8)*r.sway.amplitude,a=Bt.degToRad(r.key.elevation+s*40),n=Bt.degToRad(r.key.azimuth+i*60),o=12;this.key.position.set(Math.cos(a)*Math.sin(n)*o,Math.sin(a)*o,Math.cos(a)*Math.cos(n)*o),this.key.intensity=r.key.intensity*(1+r.key.hoverBoost*t);let l=Bt.degToRad(r.rimElevation),u=Bt.degToRad(r.rimAzimuth??180);this.rim.position.set(Math.cos(l)*Math.sin(u)*10,Math.sin(l)*10,Math.cos(l)*Math.cos(u)*10);for(let[h,d]of[[this.accentCool,r.accentCool],[this.accentWarm,r.accentWarm]]){if(!d)continue;let c=Bt.degToRad(d.elevation),m=Bt.degToRad(d.azimuth);h.position.set(Math.cos(c)*Math.sin(m)*12,Math.sin(c)*12,Math.cos(c)*Math.cos(m)*12),h.color.set(d.color),h.intensity=d.intensity}if(le.version!==this.settingsVersion){this.settingsVersion=le.version,this.key.color.set(r.key.color),this.fill.intensity=r.fill,this.fill.color.set(r.fillColor),this.fill.groundColor.set(r.fillGroundColor),this.rim.color.set(r.rimColor),this.rim.intensity=r.rim*40,this.rim.angle=Bt.degToRad(r.rimAngle??65),this.rim.penumbra=1,this.rim.decay=1.2,this.rim.distance=60;let h=this.key.shadow;h.radius=r.shadow.softness,h.blurSamples=Math.round(r.shadow.samples),h.bias=r.shadow.bias,h.intensity=r.shadow.intensity;let d=parseInt(r.shadow.mapSize,10);d!==this.mapSize&&(this.mapSize=d,h.mapSize.set(d,d),h.map&&(h.map.dispose(),h.map=null),h.needsUpdate=!0)}}},K5=class{yaw=0;pitch=0;parYaw=0;parPitch=0;idleBlend=0;lookAt=new F;base=new F;spherical=new gU;update(e,t,r,i){let s=Ht.enabled&&Ht.framing,a=le.camera,n=s?Ht:a,o=r-Ui.lastMoveT>a.idleDelay;this.idleBlend=Oo(this.idleBlend,o?1:0,o?1.5:.6,i);let l=Ui.inside?Ui.x:0,u=Ui.inside?Ui.y:0,h=2*Math.PI/Math.max(1,a.idlePeriod),d=Math.sin(r*h)*a.idleAmplitude,c=Math.sin(r*h*1.37+1.1)*a.idleAmplitude*.5,m=Bt.degToRad(n.baseYaw+Bt.lerp(l*n.rotateYaw,d,this.idleBlend)),g=Bt.degToRad(n.basePitch+Bt.lerp(-u*n.rotatePitch,c,this.idleBlend));this.yaw=Oo(this.yaw,m,a.rotationLag*.35,i),this.pitch=Oo(this.pitch,g,a.rotationLag*.35,i),t.rotation.set(this.pitch,this.yaw,0,"YXZ");let y=Bt.degToRad(n.parallaxRange);if(this.parYaw=Oo(this.parYaw,-l*y,a.parallaxSmoothing*.35,i),this.parPitch=Oo(this.parPitch,u*y*.6,a.parallaxSmoothing*.35,i),this.lookAt.set(s?Ht.lookAtX:0,n.lookAtY,0),Ht.cameraOverride){Ht.cameraOverride(e);return}let b=this.base.set(0,n.height,n.distance).sub(this.lookAt),v=this.spherical.setFromVector3(b);v.theta+=this.parYaw,v.phi=Bt.clamp(v.phi+this.parPitch,.1,Math.PI-.1),e.position.setFromSpherical(v).add(this.lookAt),e.lookAt(this.lookAt),e.fov!==n.fov&&(e.fov=n.fov,e.updateProjectionMatrix())}},{Fn:z0e,vec2:Ene,vec3:lh,float:Pne,length:hc,max:Za,min:Bne,abs:V1,dot:Ine,sqrt:V0e,clamp:G0e,sign:W0e,select:Fne,texture3D:Lne}=Jr,eI=(()=>{let e=(1+Math.sqrt(5))/2,t=[],r=(i,s,a)=>{let n=Math.hypot(i,s,a);t.push([i/n,s/n,a/n])};for(let i of[-1,1])for(let s of[-1,1])for(let a of[-1,1])r(i,s,a);for(let i of[-1,1])for(let s of[-1,1])r(0,i/e,s*e),r(i/e,s*e,0),r(i*e,0,s/e);return t})();function cw(e,t,r,i){let s=t,a=t*r;switch(e){case"torus":return{name:e,size:t,tubeRatio:r,bound:(s+a)*1.12,thickness:a,sdf:(n,o,l)=>{let u=Math.hypot(n,o)-s;return Math.hypot(u,l)-a},sdfNode:n=>hc(Ene(hc(n.xy).sub(s),n.z)).sub(a)};case"sphere":{let n=t*1.15;return{name:e,size:t,tubeRatio:r,bound:n*1.15,thickness:n,sdf:(o,l,u)=>Math.hypot(o,l,u)-n,sdfNode:o=>hc(o).sub(n)}}case"roundedBox":{let n=t*.92,o=t*.22;return{name:e,size:t,tubeRatio:r,bound:(n+o)*1.12,thickness:n,sdf:(l,u,h)=>{let d=Math.abs(l)-n+o,c=Math.abs(u)-n+o,m=Math.abs(h)-n*.55+o,g=Math.max(d,0),y=Math.max(c,0),b=Math.max(m,0);return Math.hypot(g,y,b)+Math.min(Math.max(d,c,m),0)-o},sdfNode:l=>{let u=V1(l).sub(lh(n-o,n-o,n*.55-o));return hc(Za(u,0)).add(Bne(Za(u.x,Za(u.y,u.z)),0)).sub(o)}}}case"pyramid":{let n=t*1.05,o=t*1.5,l=t*.06,u=n/Math.hypot(n,o),h=o/Math.hypot(n,o),d=-o*.4;return{name:e,size:t,tubeRatio:r,bound:Math.max(n,o)*1.25,thickness:n*.6,sdf:(c,m,g)=>{m-=d;let y=Math.abs(c),b=Math.abs(g),v=Math.max(y*h+m*u-o*u,b*h+m*u-o*u),S=-m;return Math.max(v,S)-l},sdfNode:c=>{let m=lh(c.x,c.y.sub(d),c.z),g=V1(m.x),y=V1(m.z),b=Za(g.mul(h).add(m.y.mul(u)).sub(o*u),y.mul(h).add(m.y.mul(u)).sub(o*u));return Za(b,m.y.negate()).sub(l)}}}case"icosahedron":{let n=t*1.05,o=t*.05;return{name:e,size:t,tubeRatio:r,bound:n*1.3,thickness:n*.8,sdf:(l,u,h)=>{let d=-1/0;for(let c of eI)d=Math.max(d,l*c[0]+u*c[1]+h*c[2]);return d-n-o},sdfNode:l=>{let u=Pne(-100);for(let h of eI)u=Za(u,Ine(l,lh(h[0],h[1],h[2])));return u.sub(n+o)}}}case"logo":{let n=i,o=t,l=n.sampleBoundNode??=Jr.uniform(n.sampleDomain.value);return{name:e,size:t,tubeRatio:r,bound:n.bound*o,thickness:n.thickness*o,voxelSize:l.mul(2*o/n.res),sdf:(u,h,d)=>n.sample(u/o,h/o,d/o)*o,sdfNode:u=>{let h=l.mul(o),d=u.div(h.mul(2)).add(.5),c=Lne(n.texture,d).r.mul(n.range*2).sub(n.range).mul(o),m=Za(V1(u).sub(h),0);return Fne(Za(m.x,Za(m.y,m.z)).greaterThan(0),Za(c,hc(m)),c)}}}}}function tI(e,t,r,i,s=.001){let a=e.sdf(t+s,r,i)-e.sdf(t-s,r,i),n=e.sdf(t,r+s,i)-e.sdf(t,r-s,i),o=e.sdf(t,r,i+s)-e.sdf(t,r,i-s),l=Math.hypot(a,n,o)||1;return[a/l,n/l,o/l]}var G1=(e,t,r=.002)=>{let i=lh(r,0,0),s=lh(0,r,0),a=lh(0,0,r),n=lh(e.sdfNode(t.add(i)).sub(e.sdfNode(t.sub(i))),e.sdfNode(t.add(s)).sub(e.sdfNode(t.sub(s))),e.sdfNode(t.add(a)).sub(e.sdfNode(t.sub(a))));return n.div(Za(hc(n),1e-6))};function kne(e,t,r,i=60,s){let a=0,n=t.x,o=t.y,l=t.z,u=!1;for(let m=0;m<160;m++){n=r.x*a+t.x,o=r.y*a+t.y,l=r.z*a+t.z;let g=e.sdf(n,o,l);if(g<.0015){u=!0;break}if(a+=Math.max(g,.002),a>i)break}if(!u)return null;let h=a,d=s??{entry:new F,exit:new F,tEntry:0,tExit:0};d.entry.set(n,o,l);let c=a+.004;for(let m=0;m<200;m++){n=r.x*c+t.x,o=r.y*c+t.y,l=r.z*c+t.z;let g=e.sdf(n,o,l);if(g>.0015||(c+=Math.max(-g,.004),c-a>e.bound*4))break}return d.exit.set(r.x*c+t.x,r.y*c+t.y,r.z*c+t.z),d.tEntry=h,d.tExit=c,d}function rI(e,t,r,i,s,a){let n=new Float32Array(t*3),o=new Float32Array(t),l=a?a[0]:e.bound,u=a?a[1]:e.bound,h=a?a[2]:e.bound,d=e.bound,c=e.thickness*i,m=Math.round(t*r),g=0,y=0;for(;g=0)continue;let w=-T,N=gc||!N&&w<=c)||(n[g*3]=b,n[g*3+1]=v,n[g*3+2]=S,o[g]=Math.min(1,w/e.thickness),g++)}if(g!==t)throw new Error(`Frost: sampled only ${g}/${t} interior homes; check shape bounds and SDF`);return{positions:n,depths:o,count:g}}function W1(e,t,r=4){let i=e.attributes.position,s=new Float32Array(i.count*3);for(let a=0;a{let c=e.renderer.getDrawingBufferSize(iI);this.setViewOffset(c.width,c.height)},t.context.onAfterRenderPipeline=()=>{this.clearViewOffset()}),e.renderer.reversedDepthBuffer===!0&&(this._historyRenderTarget.depthTexture.type=Er),e.context.velocity!==void 0?this._velocityNode=e.context.velocity:this._velocityNode=Xy;let r=c=>{let{x:m,y:g}=this._cameraNearFar,y=MB(c,m,g);return $y(y,m,g)},i=v_({closestDepth:"float",closestPositionTexel:"vec2",farthestDepth:"float"}),s=Ir(([c])=>{let m=yt(2).toVar(),g=nr(0).toVar(),y=yt(-1).toVar();for(let b=-1;b<=1;++b)for(let v=-1;v<=1;++v){let S=c.add(nr(b,v)).toVar(),T=this.depthNode.load(S).r;e.renderer.reversedDepthBuffer&&(T=T.oneMinus()),e.renderer.logarithmicDepthBuffer&&(T=r(T)),T=T.toVar(),pm(T.lessThan(m),()=>{m.assign(T),g.assign(S)}),pm(T.greaterThan(y),()=>{y.assign(T)})}return i(m,g,y)}),a=c=>{let m=this._previousDepthNode.sample(c).r;e.renderer.logarithmicDepthBuffer&&(m=r(m));let g=p_(c,m,this._previousCameraProjectionMatrixInverse),y=this._previousCameraWorldMatrix.mul(hr(g,1)).xyz,b=this._cameraWorldMatrixInverse.mul(hr(y,1)).z;return this.camera.isOrthographicCamera?PB(b,this._cameraNearFar.x,this._cameraNearFar.y):$y(b,this._cameraNearFar.x,this._cameraNearFar.y)},n=Ir(([c,m,g,y])=>{let b=y.rgb.add(g.rgb).mul(.5),v=y.rgb.sub(g.rgb).mul(.5).add(1e-7),S=m.sub(hr(b,c.a)),T=S.xyz.div(v).abs(),w=_t(T.x,T.y,T.z);return w.greaterThan(1).select(hr(b,c.a).add(S.div(w)),m)}).setLayout({name:"clipAABB",type:"vec4",inputs:[{name:"currentColor",type:"vec4"},{name:"historyColor",type:"vec4"},{name:"minColor",type:"vec4"},{name:"maxColor",type:"vec4"}]}),o=Ir(([c,m,g,y])=>{let b=[[-1,-1],[-1,1],[1,-1],[1,1],[1,0],[0,-1],[0,1],[-1,0]],v=m.toVar(),S=m.pow2().toVar();for(let[E,P]of b){let I=this.beautyNode.offset(ss(E,P)).load(c).max(0);v.addAssign(I),S.addAssign(I.pow2())}let T=yt(b.length+1),w=v.div(T),N=S.div(T).sub(w.pow2()).max(0).sqrt().mul(y),C=w.sub(N),R=w.add(N);return n(w.clamp(C,R),g,C,R)}),l=Ir(([c,m])=>{let g=c.mul(m).fract().abs(),y=_t(g,g.oneMinus());return y.x.mul(y.y).oneMinus().div(.75)}).setLayout({name:"subpixelCorrection",type:"float",inputs:[{name:"velocityUV",type:"vec2"},{name:"textureSize",type:"ivec2"}]}),u=Ir(([c,m,g])=>{let y=g.oneMinus(),b=c.mul(yt(1).div(_t(c.r,c.g,c.b).add(1))),v=m.mul(yt(1).div(_t(m.r,m.g,m.b).add(1))),S=kl(b.rgb),T=kl(v.rgb);return g.mulAssign(yt(1).div(S.add(1))),y.mulAssign(yt(1).div(T.add(1))),Wy(c.mul(g),m.mul(y)).div(_t(g.add(y),1e-5)).toVar()}),h=Ri(this._historyRenderTarget.texture),d=Ir(()=>{let c=_a(),m=this.beautyNode.size(),g=c.mul(m),y=s(g),b=y.get("closestDepth"),v=y.get("closestPositionTexel"),S=y.get("farthestDepth"),T=this.velocityNode.load(v).xy.mul(nr(.5,-.5)),w=c.sub(T),N=a(w),C=w.greaterThanEqual(0).all().and(w.lessThanEqual(1).all()),R=S.sub(b).greaterThan(this.edgeDepthDiff),E=b.sub(N).greaterThan(this.depthThreshold),P=C.and(R.or(E.not())),I=this.beautyNode.sample(c),O=h.sample(c.sub(T)),L=c.sub(w).mul(m).length().div(this.maxVelocityLength).saturate(),X=yt(.05).toVar();this.useSubpixelCorrection&&X.addAssign(l(T,m).mul(.25)),X.assign(P.select(X.add(L).saturate(),1));let z=Dl(.5,1,L.oneMinus().pow2()),H=o(g,I,O,z);return u(I,H,X)});return this._resolveMaterial.colorNode=d(),this._textureNode}dispose(){this._historyRenderTarget.dispose(),this._resolveRenderTarget.dispose(),this._resolveMaterial.dispose()}};function sI(e,t){let r=1,i=0;for(;e>0;)r/=t,i+=r*(e%t),e=Math.floor(e/t);return i}var aI=Array.from({length:32},(e,t)=>[sI(t+1,2),sI(t+1,3)]),Vne=(e,t,r,i)=>new zne(Ju(e),t,r,i),dc=new Wa,Gne=new fe,fw,Wne=class extends rr{static get type(){return"TAAUNode"}constructor(e,t,r,i){super("vec4"),this.isTAAUNode=!0,this.updateBeforeType=ut.FRAME,this.beautyNode=e,this.depthNode=t,this.velocityNode=r,this.camera=i,this.depthThreshold=5e-4,this.edgeDepthDiff=.001,this.maxVelocityLength=128,this.currentFrameWeight=.025,this._jitterIndex=0,this._jitterOffset=Fr(new fe),this._historyRenderTarget=new er(1,1,{depthBuffer:!1,type:Dt,count:2}),this._historyRenderTarget.textures[0].name="TAAUNode.history.color",this._historyRenderTarget.textures[1].name="TAAUNode.history.lock",this._resolveRenderTarget=new er(1,1,{depthBuffer:!1,type:Dt}),this._resolveRenderTarget.texture.name="TAAUNode.resolve",this._previousDepthRenderTarget=new er(1,1,{depthBuffer:!1,depthTexture:new fs}),this._previousDepthRenderTarget.depthTexture.name="TAAUNode.previousDepth",this._resolveMaterial=new Pt,this._resolveMaterial.name="TAAU.resolve",this._seedMaterial=new Pt,this._seedMaterial.name="TAAU.seed",this._textureNode=Qu(this,this._resolveRenderTarget.texture),this._originalProjectionMatrix=new We,this._cameraNearFar=Fr(new fe),this._cameraWorldMatrix=Fr(new We),this._cameraWorldMatrixInverse=Fr(new We),this._cameraProjectionMatrixInverse=Fr(new We),this._previousCameraWorldMatrix=Fr(new We),this._previousCameraProjectionMatrixInverse=Fr(new We),this._previousDepthNode=Ri(this._previousDepthRenderTarget.depthTexture),this._needsPostProcessingSync=!1}getTextureNode(){return this._textureNode}setSize(e,t){this._historyRenderTarget.setSize(e,t),this._resolveRenderTarget.setSize(e,t)}setViewOffset(e,t){this.camera.updateProjectionMatrix(),this._originalProjectionMatrix.copy(this.camera.projectionMatrix),Xy.setProjectionMatrix(this._originalProjectionMatrix);let r=oI[this._jitterIndex],i=r[0]-.5,s=r[1]-.5;this._jitterOffset.value.set(i,s),this.camera.setViewOffset(e,t,i,s,e,t)}clearViewOffset(){this.camera.clearViewOffset(),Xy.setProjectionMatrix(null),this._jitterIndex++,this._jitterIndex=this._jitterIndex%(oI.length-1)}updateBefore(e){let{renderer:t}=e;this._previousCameraWorldMatrix.value.copy(this._cameraWorldMatrix.value),this._previousCameraProjectionMatrixInverse.value.copy(this._cameraProjectionMatrixInverse.value),this._cameraNearFar.value.set(this.camera.near,this.camera.far),this._cameraWorldMatrix.value.copy(this.camera.matrixWorld),this._cameraWorldMatrixInverse.value.copy(this.camera.matrixWorldInverse),this._cameraProjectionMatrixInverse.value.copy(this.camera.projectionMatrixInverse);let r=this.beautyNode.isRTTNode?this.beautyNode.renderTarget:this.beautyNode.passNode.renderTarget,i=r.texture.width,s=r.texture.height,a=t.getDrawingBufferSize(Gne),n=a.width,o=a.height;fw=Es.resetRendererState(t,fw);let l=this._historyRenderTarget.width!==n||this._historyRenderTarget.height!==o;this.setSize(n,o),l===!0&&(t.initRenderTarget(this._historyRenderTarget),t.initRenderTarget(this._resolveRenderTarget),t.setRenderTarget(this._historyRenderTarget),dc.material=this._seedMaterial,dc.name="TAAU.seed",dc.render(t),t.setRenderTarget(null)),this._needsPostProcessingSync===!0&&(this.setViewOffset(i,s),this._needsPostProcessingSync=!1),t.setRenderTarget(this._resolveRenderTarget),dc.material=this._resolveMaterial,dc.name="TAAU",dc.render(t),t.setRenderTarget(null),t.copyTextureToTexture(this._resolveRenderTarget.texture,this._historyRenderTarget.texture);let u=this.depthNode.value,h=u.image!==null&&u.image!==void 0?u.image.width:0,d=u.image!==null&&u.image!==void 0?u.image.height:0;if(h>0&&d>0){(this._previousDepthRenderTarget.width!==h||this._previousDepthRenderTarget.height!==d)&&(this._previousDepthRenderTarget.setSize(h,d),t.initRenderTarget(this._previousDepthRenderTarget));let c=this._previousDepthRenderTarget.depthTexture;t.copyTextureToTexture(u,c),this._previousDepthNode.value=c}Es.restoreRendererState(t,fw)}setup(e){let t=e.context.renderPipeline;t&&(this._needsPostProcessingSync=!0,t.context.onBeforeRenderPipeline=()=>{let m=this.beautyNode.isRTTNode?this.beautyNode.renderTarget:this.beautyNode.passNode.renderTarget,g=m.texture.width,y=m.texture.height;this.setViewOffset(g,y)},t.context.onAfterRenderPipeline=()=>{this.clearViewOffset()});let r=v_({closestDepth:"float",closestPositionTexel:"vec2",farthestDepth:"float"}),i=Ir(([m])=>{let g=yt(2).toVar(),y=nr(0).toVar(),b=yt(-1).toVar();for(let v=-1;v<=1;++v)for(let S=-1;S<=1;++S){let T=m.add(nr(v,S)).toVar(),w=this.depthNode.load(T).r.toVar();pm(w.lessThan(g),()=>{g.assign(w),y.assign(T)}),pm(w.greaterThan(b),()=>{b.assign(w)})}return r(g,y,b)}),s=m=>{let g=this._previousDepthNode.sample(m).r,y=p_(m,g,this._previousCameraProjectionMatrixInverse),b=this._previousCameraWorldMatrix.mul(hr(y,1)).xyz,v=this._cameraWorldMatrixInverse.mul(hr(b,1)).z;return $y(v,this._cameraNearFar.x,this._cameraNearFar.y)},a=Ir(([m,g,y,b])=>{let v=b.rgb.add(y.rgb).mul(.5),S=b.rgb.sub(y.rgb).mul(.5).add(1e-7),T=g.sub(hr(v,m.a)),w=T.xyz.div(S).abs(),N=_t(w.x,w.y,w.z);return N.greaterThan(1).select(hr(v,m.a).add(T.div(N)),g)}).setLayout({name:"clipAABB",type:"vec4",inputs:[{name:"currentColor",type:"vec4"},{name:"historyColor",type:"vec4"},{name:"minColor",type:"vec4"},{name:"maxColor",type:"vec4"}]}),n=Ir(([m,g,y])=>{let b=y.oneMinus(),v=m.mul(yt(1).div(_t(m.r,m.g,m.b).add(1))),S=g.mul(yt(1).div(_t(g.r,g.g,g.b).add(1))),T=kl(v.rgb),w=kl(S.rgb);return y.mulAssign(yt(1).div(T.add(1))),b.mulAssign(yt(1).div(w.add(1))),Wy(m.mul(y),g.mul(b)).div(_t(y.add(b),1e-5)).toVar()}),o=Ri(this._historyRenderTarget.textures[0]),l=Ri(this._historyRenderTarget.textures[1]),u=mm("vec4"),h=mm("vec4"),d=m_(u,h),c=Ir(()=>{let m=_a(),g=this.beautyNode.size(),y=nr(g),b=m.mul(y),v=b.sub(nr(.5).add(this._jitterOffset)).round(),S=ss(v),T=i(v),w=T.get("closestDepth"),N=T.get("closestPositionTexel"),C=T.get("farthestDepth"),R=this.velocityNode.load(N).xy.mul(nr(.5,-.5)),E=m.sub(R),P=s(E),I=E.greaterThanEqual(0).all().and(E.lessThanEqual(1).all()),O=C.sub(w).greaterThan(this.edgeDepthDiff),L=w.sub(P).greaterThan(this.depthThreshold),X=I.and(O.or(L.not())),z=hr(0).toVar(),H=yt(0).toVar(),ue=hr(0).toVar(),ne=hr(0).toVar(),re=[[-1,-1],[0,-1],[1,-1],[-1,0],[0,0],[1,0],[-1,1],[0,1],[1,1]];for(let[Te,we]of re){let ie=S.add(ss(Te,we)),V=nr(ie).add(nr(.5).add(this._jitterOffset)),Oe=b.sub(V),tt=Oe.dot(Oe),Je=_B(tt.mul(-2.29)),ct=this.beautyNode.load(ie).max(0);z.addAssign(ct.mul(Je)),H.addAssign(Je),ue.addAssign(ct),ne.addAssign(ct.pow2())}let ce=z.div(H.max(1e-5)),ge=yt(re.length),ye=ue.div(ge),oe=m.sub(E).mul(y).length().div(this.maxVelocityLength).saturate(),Ae=Dl(.5,1,oe.oneMinus().pow2()),Ie=ne.div(ge).sub(ye.pow2()).max(0).sqrt().mul(Ae),Xe=ye.sub(Ie),at=ye.add(Ie),W=o.sample(E),j=a(ye.clamp(Xe,at),W,Xe,at),G=kl(ce.rgb),ae=kl(ye.rgb).toConst(),be=G.sub(ae).abs().div(ae).smoothstep(0,.2),Be=w.sub(P).abs().greaterThan(this.depthThreshold),$=I.and(Be.not()).select(be,yt(0)),U=L.select(0,.5),J=_t($,l.r.mul(U)).saturate(),q=Dl(j,W,J),se=yt(this.currentFrameWeight).toVar();se.assign(X.select(se.add(oe).saturate(),1));let pe=n(ce,q,se);return u.assign(pe),h.assign(J),hr(0)});return this._resolveMaterial.colorNode=c(),this._resolveMaterial.outputNode=d,this._seedMaterial.colorNode=Ir(()=>(u.assign(this.beautyNode.sample(_a())),h.assign(0),hr(0)))(),this._seedMaterial.outputNode=d,this._textureNode}dispose(){this._historyRenderTarget.dispose(),this._resolveRenderTarget.dispose(),this._previousDepthRenderTarget.dispose(),this._resolveMaterial.dispose(),this._seedMaterial.dispose()}};function nI(e,t){let r=1,i=0;for(;e>0;)r/=t,i+=r*(e%t),e=Math.floor(e/t);return i}var oI=Array.from({length:32},(e,t)=>[nI(t+1,2),nI(t+1,3)]),jne=(e,t,r,i)=>new Wne(Ju(e),t,r,i),cc=new Wa,gw=new fe,yw,Hne=class extends rr{static get type(){return"FSR1Node"}constructor(e,t=.2,r=!1){super("vec4"),this.textureNode=e,this.sharpness=Un(t),this.denoise=Un(r),this._easuRT=new er(1,1,{depthBuffer:!1,type:Dt}),this._easuRT.texture.name="FSR1Node.easu",this._rcasRT=new er(1,1,{depthBuffer:!1,type:Dt}),this._rcasRT.texture.name="FSR1Node.rcas",this._textureNode=Qu(this,this._rcasRT.texture),this._easuMaterial=null,this._rcasMaterial=null,this.updateBeforeType=ut.FRAME}setSize(e,t){this._easuRT.setSize(e,t),this._rcasRT.setSize(e,t)}updateBefore(e){let{renderer:t}=e;yw=Es.resetRendererState(t,yw),t.getDrawingBufferSize(gw),this.setSize(gw.x,gw.y),t.setRenderTarget(this._easuRT),cc.material=this._easuMaterial,cc.name="FSR1 [ EASU Pass ]",cc.render(t),t.setRenderTarget(this._rcasRT),cc.material=this._rcasMaterial,cc.name="FSR1 [ RCAS Pass ]",cc.render(t),Es.restoreRendererState(t,yw)}getTextureNode(){return this._textureNode}setup(e){let t=this.textureNode,r=t.value,i=(c,m,g,y,b,v,S,T)=>{let w=S.sub(v).toConst(),N=v.sub(b).toConst(),C=S.sub(b).toConst(),R=_t($a(w),$a(N)).toConst(),E=f_($a(C).div(_t(R,yt(1/65536)))).toConst();c.x.addAssign(C.mul(g)),m.addAssign(E.mul(E).mul(g));let P=T.sub(v).toConst(),I=v.sub(y).toConst(),O=T.sub(y).toConst(),L=_t($a(P),$a(I)).toConst(),X=f_($a(O).div(_t(L,yt(1/65536)))).toConst();c.y.addAssign(O.mul(g)),m.addAssign(X.mul(X).mul(g))},s=(c,m,g,y,b,v,S,T)=>{let w=g.x.mul(y.x).add(g.y.mul(y.y)).toConst(),N=g.x.mul(y.y).negate().add(g.y.mul(y.x)).toConst(),C=w.mul(b.x).toConst(),R=N.mul(b.y).toConst(),E=Ar(C.mul(C).add(R.mul(R)),S).toConst(),P=E.mul(2/5).sub(1).toConst(),I=E.mul(v).sub(1).toConst(),O=P.mul(P).mul(25/16).sub(25/16-1).mul(I.mul(I)).toConst();c.addAssign(T.mul(O)),m.addAssign(O)},a=Ir(()=>{let c=_a(),m=nr(jy(t)),g=c.mul(m).sub(.5).toConst(),y=Zd(g).toConst(),b=wB(g).toConst(),v=ss(Eo(y.x),Eo(y.y)).toConst(),S=(Je,ct)=>Ps(r,v.add(ss(Je,ct))),T=S(0,-1),w=S(1,-1),N=S(-1,0),C=S(0,0),R=S(1,0),E=S(2,0),P=S(-1,1),I=S(0,1),O=S(1,1),L=S(2,1),X=S(0,2),z=S(1,2),H=Je=>Je.r.mul(.5).add(Je.g).add(Je.b.mul(.5)),ue=H(T),ne=H(w),re=H(N),ce=H(C),ge=H(R),ye=H(E),oe=H(P),Ae=H(I),Ie=H(O),Xe=H(L),at=H(X),W=H(z),j=nr(0).toVar(),G=yt(0).toVar(),ae=yt(1).sub(b.x).mul(yt(1).sub(b.y)).toConst(),be=b.x.mul(yt(1).sub(b.y)).toConst(),Be=yt(1).sub(b.x).mul(b.y).toConst(),$=b.x.mul(b.y).toConst();i(j,G,ae,ue,re,ce,ge,Ae),i(j,G,be,ne,ce,ge,ye,Ie),i(j,G,Be,ce,oe,Ae,Ie,at),i(j,G,$,ge,Ae,Ie,Xe,W);let U=j.x.mul(j.x).add(j.y.mul(j.y)).toConst(),J=U.lessThan(1/32768).toConst(),q=yt(1).div(CB(_t(U,yt(1/32768)))).toConst();j.x.assign(g_(J,yt(1),j.x)),j.mulAssign(g_(J,yt(1),q)),G.assign(G.mul(.5)),G.mulAssign(G);let se=j.x.mul(j.x).add(j.y.mul(j.y)).div(_t($a(j.x),$a(j.y))).toConst(),pe=nr(yt(1).add(se.sub(1).mul(G)),yt(1).sub(G.mul(.5))).toConst(),Te=yt(.5).add(yt(1/4-.04-.5).mul(G)).toConst(),we=yt(1).div(Te).toConst(),ie=hr(0).toVar(),V=yt(0).toVar();s(ie,V,nr(0,-1).sub(b),j,pe,Te,we,T),s(ie,V,nr(1,-1).sub(b),j,pe,Te,we,w),s(ie,V,nr(-1,0).sub(b),j,pe,Te,we,N),s(ie,V,nr(0,0).sub(b),j,pe,Te,we,C),s(ie,V,nr(1,0).sub(b),j,pe,Te,we,R),s(ie,V,nr(2,0).sub(b),j,pe,Te,we,E),s(ie,V,nr(-1,1).sub(b),j,pe,Te,we,P),s(ie,V,nr(0,1).sub(b),j,pe,Te,we,I),s(ie,V,nr(1,1).sub(b),j,pe,Te,we,O),s(ie,V,nr(2,1).sub(b),j,pe,Te,we,L),s(ie,V,nr(0,2).sub(b),j,pe,Te,we,X),s(ie,V,nr(1,2).sub(b),j,pe,Te,we,z),ie.divAssign(V);let Oe=Ar(Ar(C,R),Ar(I,O)).toConst(),tt=_t(_t(C,R),_t(I,O)).toConst();return SB(ie,Oe,tt)}),n=this._easuRT.texture,o=Ir(()=>{let c=_a(),m=nr(jy(Ps(n))),g=ss(Eo(Zd(c.x.mul(m.x))),Eo(Zd(c.y.mul(m.y)))).toConst(),y=Ps(n,g),b=Ps(n,g.add(ss(0,-1))),v=Ps(n,g.add(ss(-1,0))),S=Ps(n,g.add(ss(1,0))),T=Ps(n,g.add(ss(0,1))),w=Ae=>Ae.g.add(Ae.b.add(Ae.r).mul(.5)),N=w(b),C=w(v),R=w(y),E=w(S),P=w(T),I=c_(this.sharpness.negate()).toConst(),O=Ar(Ar(b.rgb,v.rgb),Ar(S.rgb,T.rgb)).toConst(),L=_t(_t(b.rgb,v.rgb),_t(S.rgb,T.rgb)).toConst(),X=yt(.25-1/16).toConst(),z=Ar(O,y.rgb).div(L.mul(4)).toConst(),H=Hy(1).sub(_t(L,y.rgb)).div(O.mul(4).sub(4)).toConst(),ue=_t(z.negate(),H).toConst(),ne=_t(X.negate(),Ar(_t(ue.r,_t(ue.g,ue.b)),yt(0))).mul(I).toConst(),re=N.add(C).add(E).add(P).mul(.25).sub(R).toConst(),ce=_t(_t(N,C),_t(R,_t(E,P))).sub(Ar(Ar(N,C),Ar(R,Ar(E,P)))).toConst(),ge=yt(1).sub($a(re).div(_t(ce,yt(1/65536))).saturate().mul(.5)).toConst(),ye=this.denoise.equal(!0).select(ne.mul(ge),ne).toConst(),oe=b.rgb.add(v.rgb).add(S.rgb).add(T.rgb).mul(ye).add(y.rgb).div(ye.mul(4).add(1)).toConst();return hr(oe,y.a)}),l=e.getSharedContext(),u=this._easuMaterial||(this._easuMaterial=new Pt);u.fragmentNode=a().context(l),u.name="FSR1_EASU",u.needsUpdate=!0;let h=this._rcasMaterial||(this._rcasMaterial=new Pt);h.fragmentNode=o().context(l),h.name="FSR1_RCAS",h.needsUpdate=!0;let d=e.getNodeProperties(this);return d.textureNode=t,this._textureNode}dispose(){this._easuRT.dispose(),this._rcasRT.dispose(),this._easuMaterial!==null&&this._easuMaterial.dispose(),this._rcasMaterial!==null&&this._rcasMaterial.dispose()}},Xne=(e,t,r)=>new Hne(Ju(e),t,r),xw=new Wa,vw=new fe,bw,$ne=class extends rr{static get type(){return"SharpenNode"}constructor(e,t=.2,r=!1){super("vec4"),this.isSharpenNode=!0,this.textureNode=e,this.sharpness=Un(t),this.denoise=Un(r),this._renderTarget=new er(1,1,{depthBuffer:!1,type:Dt}),this._renderTarget.texture.name="SharpenNode.output",this._textureNode=Qu(this,this._renderTarget.texture),this._material=null,this.updateBeforeType=ut.FRAME}setSize(e,t){this._renderTarget.setSize(e,t)}updateBefore(e){let{renderer:t}=e;bw=Es.resetRendererState(t,bw),t.getDrawingBufferSize(vw),this.setSize(vw.x,vw.y),t.setRenderTarget(this._renderTarget),xw.material=this._material,xw.name="Sharpen [ RCAS ]",xw.render(t),Es.restoreRendererState(t,bw)}getTextureNode(){return this._textureNode}setup(e){let t=this.textureNode,r=t.value,i=Ir(()=>{let o=_a(),l=jy(Ps(r)),u=ss(Eo(Zd(o.x.mul(l.x))),Eo(Zd(o.y.mul(l.y)))).toConst(),h=Ps(r,u),d=Ps(r,u.add(ss(0,-1))),c=Ps(r,u.add(ss(-1,0))),m=Ps(r,u.add(ss(1,0))),g=Ps(r,u.add(ss(0,1))),y=re=>re.g.add(re.b.add(re.r).mul(.5)),b=y(d),v=y(c),S=y(h),T=y(m),w=y(g),N=c_(this.sharpness.negate()).toConst(),C=Ar(Ar(d.rgb,c.rgb),Ar(m.rgb,g.rgb)).toConst(),R=_t(_t(d.rgb,c.rgb),_t(m.rgb,g.rgb)).toConst(),E=yt(.25-1/16).toConst(),P=Ar(C,h.rgb).div(R.mul(4)).toConst(),I=Hy(1).sub(_t(R,h.rgb)).div(C.mul(4).sub(4)).toConst(),O=_t(P.negate(),I).toConst(),L=_t(E.negate(),Ar(_t(O.r,_t(O.g,O.b)),yt(0))).mul(N).toConst(),X=b.add(v).add(T).add(w).mul(.25).sub(S).toConst(),z=_t(_t(b,v),_t(S,_t(T,w))).sub(Ar(Ar(b,v),Ar(S,Ar(T,w)))).toConst(),H=yt(1).sub($a(X).div(_t(z,yt(1/65536))).saturate().mul(.5)).toConst(),ue=this.denoise.equal(!0).select(L.mul(H),L).toConst(),ne=d.rgb.add(c.rgb).add(m.rgb).add(g.rgb).mul(ue).add(h.rgb).div(ue.mul(4).add(1)).toConst();return hr(ne,h.a)}),s=e.getSharedContext(),a=this._material||(this._material=new Pt);a.fragmentNode=i().context(s),a.name="Sharpen_RCAS",a.needsUpdate=!0;let n=e.getNodeProperties(this);return n.textureNode=t,this._textureNode}dispose(){this._renderTarget.dispose(),this._material!==null&&this._material.dispose()}},qne=(e,t,r)=>new $ne(Ju(e),t,r),km=new Wa,Tw,Yne=class extends rr{static get type(){return"GaussianBlurNode"}constructor(e,t=null,r=4,i={}){super("vec4"),this.textureNode=e,this.directionNode=t,this.sigma=r,this._invSize=Fr(new fe),this._passDirection=Fr(new fe),this._horizontalRT=new er(1,1,{depthBuffer:!1}),this._horizontalRT.texture.name="GaussianBlurNode.horizontal",this._verticalRT=new er(1,1,{depthBuffer:!1}),this._verticalRT.texture.name="GaussianBlurNode.vertical",this._textureNode=Qu(this,this._verticalRT.texture),this._textureNode.uvNode=e.uvNode,this._material=null,this.updateBeforeType=ut.FRAME,this.resolutionScale=i.resolutionScale||1,this.premultipliedAlpha=i.premultipliedAlpha||!1,this.isGaussianBlurNode=!0}setSize(e,t){e=Math.max(Math.round(e*this.resolutionScale),1),t=Math.max(Math.round(t*this.resolutionScale),1),this._invSize.value.set(1/e,1/t),this._horizontalRT.setSize(e,t),this._verticalRT.setSize(e,t)}updateBefore(e){let{renderer:t}=e;Tw=Es.resetRendererState(t,Tw);let r=this.textureNode,i=r.value,s=r.value;km.material=this._material,this.setSize(i.image.width,i.image.height);let a=i.type;this._horizontalRT.texture.type=a,this._verticalRT.texture.type=a,t.setRenderTarget(this._horizontalRT),this._passDirection.value.set(1,0),km.name="Gaussian Blur [ Horizontal Pass ]",km.render(t),r.value=this._horizontalRT.texture,t.setRenderTarget(this._verticalRT),this._passDirection.value.set(0,1),km.name="Gaussian Blur [ Vertical Pass ]",km.render(t),r.value=s,Es.restoreRendererState(t,Tw)}getTextureNode(){return this._textureNode}setup(e){let t=this.textureNode,r=_a(),i=nr(this.directionNode||1),s,a;this.premultipliedAlpha?(s=u=>AB(t.sample(u)),a=u=>EB(u)):(s=u=>t.sample(u),a=u=>u);let n=Ir(()=>{let u=3+2*this.sigma,h=this._getCoefficients(u),d=this._invSize,c=i.mul(this._passDirection),m=hr(s(r).mul(h[0])).toVar();for(let g=1;gnew Yne(Ju(e),t,r,i),Qr=new Wa,Sw,Jne=class extends rr{static get type(){return"DepthOfFieldNode"}constructor(e,t,r,i,s){super("vec4"),this.textureNode=e,this.viewZNode=t,this.focusDistanceNode=r,this.focalLengthNode=i,this.bokehScaleNode=s,this._invSize=Fr(new fe),this._CoCRT=new er(1,1,{depthBuffer:!1,type:Dt,format:io,count:2}),this._CoCRT.textures[0].name="DepthOfField.NearField",this._CoCRT.textures[1].name="DepthOfField.FarField",this._CoCBlurredRT=new er(1,1,{depthBuffer:!1,type:Dt,format:io}),this._CoCBlurredRT.texture.name="DepthOfField.NearFieldBlurred",this._blur64RT=new er(1,1,{depthBuffer:!1,type:Dt}),this._blur64RT.texture.name="DepthOfField.Blur64",this._blur16NearRT=new er(1,1,{depthBuffer:!1,type:Dt}),this._blur16NearRT.texture.name="DepthOfField.Blur16Near",this._blur16FarRT=new er(1,1,{depthBuffer:!1,type:Dt}),this._blur16FarRT.texture.name="DepthOfField.Blur16Far",this._compositeRT=new er(1,1,{depthBuffer:!1,type:Dt}),this._compositeRT.texture.name="DepthOfField.Composite",this._CoCMaterial=new Pt,this._CoCBlurredMaterial=new Pt,this._blur64Material=new Pt,this._blur16Material=new Pt,this._compositeMaterial=new Pt,this._textureNode=Ri(this._compositeRT.texture),this._CoCTextureNode=Ri(this._CoCRT.texture),this._blur64TextureNode=Ri(this._blur64RT.texture),this._blur16NearTextureNode=Ri(this._blur16NearRT.texture),this._blur16FarTextureNode=Ri(this._blur16FarRT.texture),this.updateBeforeType=ut.FRAME}setSize(e,t){this._invSize.value.set(1/e,1/t),this._CoCRT.setSize(e,t),this._compositeRT.setSize(e,t);let r=Math.round(e/2),i=Math.round(t/2);this._CoCBlurredRT.setSize(r,i),this._blur64RT.setSize(r,i),this._blur16NearRT.setSize(r,i),this._blur16FarRT.setSize(r,i)}getTextureNode(){return this._textureNode}updateBefore(e){let{renderer:t}=e,r=this.textureNode.value;this.setSize(r.image.width,r.image.height),Sw=Es.resetRendererState(t,Sw),t.setClearColor(0,0),Qr.material=this._CoCMaterial,t.setRenderTarget(this._CoCRT),Qr.name="DoF [ CoC ]",Qr.render(t),this._CoCTextureNode.value=this._CoCRT.textures[0],Qr.material=this._CoCBlurredMaterial,t.setRenderTarget(this._CoCBlurredRT),Qr.name="DoF [ CoC Blur ]",Qr.render(t),this._CoCTextureNode.value=this._CoCBlurredRT.texture,Qr.material=this._blur64Material,t.setRenderTarget(this._blur64RT),Qr.name="DoF [ Blur64 Near ]",Qr.render(t),Qr.material=this._blur16Material,t.setRenderTarget(this._blur16NearRT),Qr.name="DoF [ Blur16 Near ]",Qr.render(t),this._CoCTextureNode.value=this._CoCRT.textures[1],Qr.material=this._blur64Material,t.setRenderTarget(this._blur64RT),Qr.name="DoF [ Blur64 Far ]",Qr.render(t),Qr.material=this._blur16Material,t.setRenderTarget(this._blur16FarRT),Qr.name="DoF [ Blur16 Far ]",Qr.render(t),Qr.material=this._compositeMaterial,t.setRenderTarget(this._compositeRT),Qr.name="DoF [ Composite ]",Qr.render(t),Es.restoreRendererState(t,Sw)}setup(e){let t=this._generateKernels(),r=mm("float"),i=mm("float"),s=m_(r,i),a=Ir(()=>{let d=this.viewZNode.negate().sub(this.focusDistanceNode),c=y_(0,this.focalLengthNode,d.abs());return r.assign(x_(d,0).mul(c)),i.assign(x_(0,d).mul(c)),yt(0)});this._CoCMaterial.colorNode=a().context(e.getSharedContext()),this._CoCMaterial.outputNode=s,this._CoCMaterial.needsUpdate=!0,this._CoCBlurredMaterial.colorNode=Zne(this._CoCTextureNode,1,2),this._CoCBlurredMaterial.needsUpdate=!0;let n=Jd(t.points64),o=Ir(()=>{let d=Hy(),c=_a(),m=this._CoCTextureNode.sample(c).r,g=this._invSize.mul(this.bokehScaleNode).mul(m);return Gy(64,({i:y})=>{let b=c.add(g.mul(n.element(y))),v=this.textureNode.sample(b);d.addAssign(v.rgb)}),d.divAssign(64),hr(d,m)});this._blur64Material.fragmentNode=o().context(e.getSharedContext()),this._blur64Material.needsUpdate=!0;let l=Jd(t.points16),u=Ir(()=>{let d=_a(),c=this._blur64TextureNode.sample(d).toVar(),m=c.rgb,g=c.a,y=this._invSize.mul(this.bokehScaleNode).mul(g);return Gy(16,({i:b})=>{let v=d.add(y.mul(l.element(b))),S=this._blur64TextureNode.sample(v);m.assign(_t(S.rgb,m))}),hr(m,g)});this._blur16Material.fragmentNode=u().context(e.getSharedContext()),this._blur16Material.needsUpdate=!0;let h=Ir(()=>{let d=_a(),c=this._blur16NearTextureNode.sample(d),m=this._blur16FarTextureNode.sample(d),g=this.textureNode.sample(d),y=Ar(c.a,.5).mul(2),b=Ar(m.a,.5).mul(2),v=hr(0,0,0,1).toVar();return v.rgb=Dl(g.rgb,m.rgb,b),v.rgb=Dl(v.rgb,c.rgb,y),v});return this._compositeMaterial.fragmentNode=h().context(e.getSharedContext()),this._compositeMaterial.needsUpdate=!0,this._textureNode}_generateKernels(){let e=2.39996323,t=80,r=[],i=[],s=0,a=0;for(let n=0;nnew Jne(Ju(e),Un(t),Un(r),Un(i),Un(s)),Ja=new Wa,Kne=new fe,eoe=new fe(1,0),toe=new fe(0,1),_w,roe=Ir(({input:e,threshold:t,smoothWidth:r})=>{let i=kl(e.rgb),s=y_(t,t.add(r),i);return Dl(hr(0),e,s)}),ioe=class extends rr{static get type(){return"BloomNode"}constructor(e,t=1,r=0,i=0){super("vec4"),this.inputNode=e,this.strength=t.isNode?t:Fr(t),this.radius=r.isNode?r:Fr(r),this.threshold=i.isNode?i:Fr(i),this.smoothWidth=Fr(.01),this._resolutionScale=.5,this.highPassFn=roe,this._renderTargetsHorizontal=[],this._renderTargetsVertical=[],this._nMips=5,this._renderTargetBright=new er(1,1,{depthBuffer:!1,type:Dt}),this._renderTargetBright.texture.name="UnrealBloomPass.bright",this._renderTargetBright.texture.generateMipmaps=!1;for(let s=0;s{let l=yt(1.2).sub(n);return Dl(n,l,o)}).setLayout({name:"lerpBloomFactor",type:"float",inputs:[{name:"factor",type:"float"},{name:"radius",type:"float"}]}),a=Ir(()=>{let n=s(r.element(0),this.radius).mul(hr(i.element(0),1)).mul(this._textureNodeBlur0),o=s(r.element(1),this.radius).mul(hr(i.element(1),1)).mul(this._textureNodeBlur1),l=s(r.element(2),this.radius).mul(hr(i.element(2),1)).mul(this._textureNodeBlur2),u=s(r.element(3),this.radius).mul(hr(i.element(3),1)).mul(this._textureNodeBlur3),h=s(r.element(4),this.radius).mul(hr(i.element(4),1)).mul(this._textureNodeBlur4);return n.add(o).add(l).add(u).add(h).mul(this.strength)});return this._compositeMaterial=this._compositeMaterial||new Pt,this._compositeMaterial.fragmentNode=a().context(e.getSharedContext()),this._compositeMaterial.name="Bloom_comp",this._compositeMaterial.needsUpdate=!0,this._textureOutput}dispose(){for(let e=0;es.sample(c),h=Ir(()=>{let c=u(l).rgb.mul(a.element(0)).toVar();return Gy({start:Eo(1),end:Eo(t),type:"int",condition:"<"},({i:m})=>{let g=yt(m),y=a.element(m),b=o.mul(n).mul(g),v=u(l.add(b)).rgb,S=u(l.sub(b)).rgb;c.addAssign(Wy(v,S).mul(y))}),hr(c,1)}),d=new Pt;return d.fragmentNode=h().context(e.getSharedContext()),d.name="Bloom_separable",d.needsUpdate=!0,d.colorTexture=s,d.direction=o,d.invSize=n,d}},soe=(e,t,r,i)=>new ioe(Un(e),t,r,i),pc={NONE:"none",FRAME:"frame",RENDER:"render",OBJECT:"object"},aoe=["fragment","vertex"],j0e=[...aoe,"compute"],j1=["x","y","z","w"],lI=0,uI=1,hI=2,dI=3,cI=4,pI=5,mI=6,fI=7,noe="",Qa="srgb",gI="srgb-linear",yI="linear",ww="srgb",uh=2e3,Mw=2001,xI={},H1=null;function vI(e){let t=e[0];if(typeof t=="string"&&t.startsWith("TSL:")){let r=e[1];r&&r.isStackTrace?e[0]+=" "+r.getLocation():e[1]='Stack trace not available. Enable "THREE.Node.captureStackTrace" to capture stack traces.'}return e}function ns(...e){e=vI(e);let t="THREE."+e.shift();if(H1)H1("warn",t,...e);else{let r=e[0];r&&r.isStackTrace?console.warn(r.getError(t)):console.warn(t,...e)}}function Uo(...e){e=vI(e);let t="THREE."+e.shift();if(H1)H1("error",t,...e);else{let r=e[0];r&&r.isStackTrace?console.error(r.getError(t)):console.error(t,...e)}}function Dm(...e){let t=e.join(" ");t in xI||(xI[t]=!0,ns(...e))}var H0e={[lI]:uI,[hI]:mI,[cI]:fI,[dI]:pI,[uI]:lI,[mI]:hI,[fI]:cI,[pI]:dI},os=["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"],bI=1234567,TI=Math.PI/180,SI=180/Math.PI;function ooe(){let e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,r=Math.random()*4294967295|0,i=Math.random()*4294967295|0;return(os[e&255]+os[e>>8&255]+os[e>>16&255]+os[e>>24&255]+"-"+os[t&255]+os[t>>8&255]+"-"+os[t>>16&15|64]+os[t>>24&255]+"-"+os[r&63|128]+os[r>>8&255]+"-"+os[r>>16&255]+os[r>>24&255]+os[i&255]+os[i>>8&255]+os[i>>16&255]+os[i>>24&255]).toLowerCase()}function sr(e,t,r){return Math.max(t,Math.min(r,e))}function Nw(e,t){return(e%t+t)%t}function loe(e,t,r,i,s){return i+(e-t)*(s-i)/(r-t)}function uoe(e,t,r){return e!==t?(r-e)/(t-e):0}function Om(e,t,r){return(1-r)*e+r*t}function hoe(e,t,r,i){return Om(e,t,1-Math.exp(-r*i))}function doe(e,t=1){return t-Math.abs(Nw(e,t*2)-t)}function coe(e,t,r){return e<=t?0:e>=r?1:(e=(e-t)/(r-t),e*e*(3-2*e))}function poe(e,t,r){return e<=t?0:e>=r?1:(e=(e-t)/(r-t),e*e*e*(e*(e*6-15)+10))}function moe(e,t){return e+Math.floor(Math.random()*(t-e+1))}function foe(e,t){return e+Math.random()*(t-e)}function goe(e){return e*(.5-Math.random())}function yoe(e){e!==void 0&&(bI=e);let t=bI+=1831565813;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}function xoe(e){return e*TI}function voe(e){return e*SI}function boe(e){return(e&e-1)===0&&e!==0}function Toe(e){return Math.pow(2,Math.ceil(Math.log(e)/Math.LN2))}function Soe(e){return Math.pow(2,Math.floor(Math.log(e)/Math.LN2))}function _oe(e,t,r,i,s){let a=Math.cos,n=Math.sin,o=a(r/2),l=n(r/2),u=a((t+i)/2),h=n((t+i)/2),d=a((t-i)/2),c=n((t-i)/2),m=a((i-t)/2),g=n((i-t)/2);switch(s){case"XYX":e.set(o*h,l*d,l*c,o*u);break;case"YZY":e.set(l*c,o*h,l*d,o*u);break;case"ZXZ":e.set(l*d,l*c,o*h,o*u);break;case"XZX":e.set(o*h,l*g,l*m,o*u);break;case"YXY":e.set(l*m,o*h,l*g,o*u);break;case"ZYZ":e.set(l*g,l*m,o*h,o*u);break;default:ns("MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+s)}}function woe(e,t){switch(t.constructor){case Float32Array:return e;case Uint32Array:return e/4294967295;case Uint16Array:return e/65535;case Uint8Array:return e/255;case Int32Array:return Math.max(e/2147483647,-1);case Int16Array:return Math.max(e/32767,-1);case Int8Array:return Math.max(e/127,-1);default:throw new Error("THREE.MathUtils: Invalid component type.")}}function Moe(e,t){switch(t.constructor){case Float32Array:return e;case Uint32Array:return Math.round(e*4294967295);case Uint16Array:return Math.round(e*65535);case Uint8Array:return Math.round(e*255);case Int32Array:return Math.round(e*2147483647);case Int16Array:return Math.round(e*32767);case Int8Array:return Math.round(e*127);default:throw new Error("THREE.MathUtils: Invalid component type.")}}var Noe={DEG2RAD:TI,RAD2DEG:SI,generateUUID:ooe,clamp:sr,euclideanModulo:Nw,mapLinear:loe,inverseLerp:uoe,lerp:Om,damp:hoe,pingpong:doe,smoothstep:coe,smootherstep:poe,randInt:moe,randFloat:foe,randFloatSpread:goe,seededRandom:yoe,degToRad:xoe,radToDeg:voe,isPowerOfTwo:boe,ceilPowerOfTwo:Toe,floorPowerOfTwo:Soe,setQuaternionFromProperEuler:_oe,normalize:Moe,denormalize:woe},X1=class nD{static{nD.prototype.isMatrix3=!0}constructor(t,r,i,s,a,n,o,l,u){this.elements=[1,0,0,0,1,0,0,0,1],t!==void 0&&this.set(t,r,i,s,a,n,o,l,u)}set(t,r,i,s,a,n,o,l,u){let h=this.elements;return h[0]=t,h[1]=s,h[2]=o,h[3]=r,h[4]=a,h[5]=l,h[6]=i,h[7]=n,h[8]=u,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){let r=this.elements,i=t.elements;return r[0]=i[0],r[1]=i[1],r[2]=i[2],r[3]=i[3],r[4]=i[4],r[5]=i[5],r[6]=i[6],r[7]=i[7],r[8]=i[8],this}extractBasis(t,r,i){return t.setFromMatrix3Column(this,0),r.setFromMatrix3Column(this,1),i.setFromMatrix3Column(this,2),this}setFromMatrix4(t){let r=t.elements;return this.set(r[0],r[4],r[8],r[1],r[5],r[9],r[2],r[6],r[10]),this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,r){let i=t.elements,s=r.elements,a=this.elements,n=i[0],o=i[3],l=i[6],u=i[1],h=i[4],d=i[7],c=i[2],m=i[5],g=i[8],y=s[0],b=s[3],v=s[6],S=s[1],T=s[4],w=s[7],N=s[2],C=s[5],R=s[8];return a[0]=n*y+o*S+l*N,a[3]=n*b+o*T+l*C,a[6]=n*v+o*w+l*R,a[1]=u*y+h*S+d*N,a[4]=u*b+h*T+d*C,a[7]=u*v+h*w+d*R,a[2]=c*y+m*S+g*N,a[5]=c*b+m*T+g*C,a[8]=c*v+m*w+g*R,this}multiplyScalar(t){let r=this.elements;return r[0]*=t,r[3]*=t,r[6]*=t,r[1]*=t,r[4]*=t,r[7]*=t,r[2]*=t,r[5]*=t,r[8]*=t,this}determinant(){let t=this.elements,r=t[0],i=t[1],s=t[2],a=t[3],n=t[4],o=t[5],l=t[6],u=t[7],h=t[8];return r*n*h-r*o*u-i*a*h+i*o*l+s*a*u-s*n*l}invert(){let t=this.elements,r=t[0],i=t[1],s=t[2],a=t[3],n=t[4],o=t[5],l=t[6],u=t[7],h=t[8],d=h*n-o*u,c=o*l-h*a,m=u*a-n*l,g=r*d+i*c+s*m;if(g===0)return this.set(0,0,0,0,0,0,0,0,0);let y=1/g;return t[0]=d*y,t[1]=(s*u-h*i)*y,t[2]=(o*i-s*n)*y,t[3]=c*y,t[4]=(h*r-s*l)*y,t[5]=(s*a-o*r)*y,t[6]=m*y,t[7]=(i*l-u*r)*y,t[8]=(n*r-i*a)*y,this}transpose(){let t,r=this.elements;return t=r[1],r[1]=r[3],r[3]=t,t=r[2],r[2]=r[6],r[6]=t,t=r[5],r[5]=r[7],r[7]=t,this}getNormalMatrix(t){return this.setFromMatrix4(t).invert().transpose()}transposeIntoArray(t){let r=this.elements;return t[0]=r[0],t[1]=r[3],t[2]=r[6],t[3]=r[1],t[4]=r[4],t[5]=r[7],t[6]=r[2],t[7]=r[5],t[8]=r[8],this}setUvTransform(t,r,i,s,a,n,o){let l=Math.cos(a),u=Math.sin(a);return this.set(i*l,i*u,-i*(l*n+u*o)+n+t,-s*u,s*l,-s*(-u*n+l*o)+o+r,0,0,1),this}scale(t,r){return Dm("Matrix3: .scale() is deprecated. Use .makeScale() instead."),this.premultiply(Aw.makeScale(t,r)),this}rotate(t){return Dm("Matrix3: .rotate() is deprecated. Use .makeRotation() instead."),this.premultiply(Aw.makeRotation(-t)),this}translate(t,r){return Dm("Matrix3: .translate() is deprecated. Use .makeTranslation() instead."),this.premultiply(Aw.makeTranslation(t,r)),this}makeTranslation(t,r){return t.isVector2?this.set(1,0,t.x,0,1,t.y,0,0,1):this.set(1,0,t,0,1,r,0,0,1),this}makeRotation(t){let r=Math.cos(t),i=Math.sin(t);return this.set(r,-i,0,i,r,0,0,0,1),this}makeScale(t,r){return this.set(t,0,0,0,r,0,0,0,1),this}equals(t){let r=this.elements,i=t.elements;for(let s=0;s<9;s++)if(r[s]!==i[s])return!1;return!0}fromArray(t,r=0){for(let i=0;i<9;i++)this.elements[i]=t[i+r];return this}toArray(t=[],r=0){let i=this.elements;return t[r]=i[0],t[r+1]=i[1],t[r+2]=i[2],t[r+3]=i[3],t[r+4]=i[4],t[r+5]=i[5],t[r+6]=i[6],t[r+7]=i[7],t[r+8]=i[8],t}clone(){return new this.constructor().fromArray(this.elements)}},Aw=new X1,_I=new X1().set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),wI=new X1().set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);function Aoe(){let e={enabled:!0,workingColorSpace:gI,spaces:{},convert:function(s,a,n){return this.enabled===!1||a===n||!a||!n||(this.spaces[a].transfer===ww&&(s.r=mc(s.r),s.g=mc(s.g),s.b=mc(s.b)),this.spaces[a].primaries!==this.spaces[n].primaries&&(s.applyMatrix3(this.spaces[a].toXYZ),s.applyMatrix3(this.spaces[n].fromXYZ)),this.spaces[n].transfer===ww&&(s.r=fc(s.r),s.g=fc(s.g),s.b=fc(s.b))),s},workingToColorSpace:function(s,a){return this.convert(s,this.workingColorSpace,a)},colorSpaceToWorking:function(s,a){return this.convert(s,a,this.workingColorSpace)},getPrimaries:function(s){return this.spaces[s].primaries},getTransfer:function(s){return s===noe?yI:this.spaces[s].transfer},getToneMappingMode:function(s){return this.spaces[s].outputColorSpaceConfig.toneMappingMode||"standard"},getLuminanceCoefficients:function(s,a=this.workingColorSpace){return s.fromArray(this.spaces[a].luminanceCoefficients)},define:function(s){Object.assign(this.spaces,s)},_getMatrix:function(s,a,n){return s.copy(this.spaces[a].toXYZ).multiply(this.spaces[n].fromXYZ)},_getDrawingBufferColorSpace:function(s){return this.spaces[s].outputColorSpaceConfig.drawingBufferColorSpace},_getUnpackColorSpace:function(s=this.workingColorSpace){return this.spaces[s].workingColorSpaceConfig.unpackColorSpace},fromWorkingColorSpace:function(s,a){return Dm("ColorManagement: .fromWorkingColorSpace() has been renamed to .workingToColorSpace()."),e.workingToColorSpace(s,a)},toWorkingColorSpace:function(s,a){return Dm("ColorManagement: .toWorkingColorSpace() has been renamed to .colorSpaceToWorking()."),e.colorSpaceToWorking(s,a)}},t=[.64,.33,.3,.6,.15,.06],r=[.2126,.7152,.0722],i=[.3127,.329];return e.define({[gI]:{primaries:t,whitePoint:i,transfer:yI,toXYZ:_I,fromXYZ:wI,luminanceCoefficients:r,workingColorSpaceConfig:{unpackColorSpace:Qa},outputColorSpaceConfig:{drawingBufferColorSpace:Qa}},[Qa]:{primaries:t,whitePoint:i,transfer:ww,toXYZ:_I,fromXYZ:wI,luminanceCoefficients:r,outputColorSpaceConfig:{drawingBufferColorSpace:Qa}}}),e}var Ka=Aoe();function mc(e){return e<.04045?e*.0773993808:Math.pow(e*.9478672986+.0521327014,2.4)}function fc(e){return e<.0031308?e*12.92:1.055*Math.pow(e,.41666)-.055}var MI={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074},Yl={h:0,s:0,l:0},$1={h:0,s:0,l:0};function Cw(e,t,r){return r<0&&(r+=1),r>1&&(r-=1),r<.16666666666666666?e+(t-e)*6*r:r<.5?t:r<.6666666666666666?e+(t-e)*6*(.6666666666666666-r):e}var Rw=class{constructor(e,t,r){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(e,t,r)}set(e,t,r){if(t===void 0&&r===void 0){let i=e;i&&i.isColor?this.copy(i):typeof i=="number"?this.setHex(i):typeof i=="string"&&this.setStyle(i)}else this.setRGB(e,t,r);return this}setScalar(e){return this.r=e,this.g=e,this.b=e,this}setHex(e,t=Qa){return e=Math.floor(e),this.r=(e>>16&255)/255,this.g=(e>>8&255)/255,this.b=(e&255)/255,Ka.colorSpaceToWorking(this,t),this}setRGB(e,t,r,i=Ka.workingColorSpace){return this.r=e,this.g=t,this.b=r,Ka.colorSpaceToWorking(this,i),this}setHSL(e,t,r,i=Ka.workingColorSpace){if(e=Nw(e,1),t=sr(t,0,1),r=sr(r,0,1),t===0)this.r=this.g=this.b=r;else{let s=r<=.5?r*(1+t):r+t-r*t,a=2*r-s;this.r=Cw(a,s,e+1/3),this.g=Cw(a,s,e),this.b=Cw(a,s,e-1/3)}return Ka.colorSpaceToWorking(this,i),this}setStyle(e,t=Qa){function r(s){s!==void 0&&parseFloat(s)<1&&ns("Color: Alpha component of "+e+" will be ignored.")}let i;if(i=/^(\w+)\(([^\)]*)\)/.exec(e)){let s,a=i[1],n=i[2];switch(a){case"rgb":case"rgba":if(s=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(n))return r(s[4]),this.setRGB(Math.min(255,parseInt(s[1],10))/255,Math.min(255,parseInt(s[2],10))/255,Math.min(255,parseInt(s[3],10))/255,t);if(s=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(n))return r(s[4]),this.setRGB(Math.min(100,parseInt(s[1],10))/100,Math.min(100,parseInt(s[2],10))/100,Math.min(100,parseInt(s[3],10))/100,t);break;case"hsl":case"hsla":if(s=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(n))return r(s[4]),this.setHSL(parseFloat(s[1])/360,parseFloat(s[2])/100,parseFloat(s[3])/100,t);break;default:ns("Color: Unknown color model "+e)}}else if(i=/^\#([A-Fa-f\d]+)$/.exec(e)){let s=i[1],a=s.length;if(a===3)return this.setRGB(parseInt(s.charAt(0),16)/15,parseInt(s.charAt(1),16)/15,parseInt(s.charAt(2),16)/15,t);if(a===6)return this.setHex(parseInt(s,16),t);ns("Color: Invalid hex color "+e)}else if(e&&e.length>0)return this.setColorName(e,t);return this}setColorName(e,t=Qa){let r=MI[e.toLowerCase()];return r!==void 0?this.setHex(r,t):ns("Color: Unknown color "+e),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(e){return this.r=e.r,this.g=e.g,this.b=e.b,this}copySRGBToLinear(e){return this.r=mc(e.r),this.g=mc(e.g),this.b=mc(e.b),this}copyLinearToSRGB(e){return this.r=fc(e.r),this.g=fc(e.g),this.b=fc(e.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(e=Qa){return Ka.workingToColorSpace(ls.copy(this),e),Math.round(sr(ls.r*255,0,255))*65536+Math.round(sr(ls.g*255,0,255))*256+Math.round(sr(ls.b*255,0,255))}getHexString(e=Qa){return("000000"+this.getHex(e).toString(16)).slice(-6)}getHSL(e,t=Ka.workingColorSpace){Ka.workingToColorSpace(ls.copy(this),t);let r=ls.r,i=ls.g,s=ls.b,a=Math.max(r,i,s),n=Math.min(r,i,s),o,l,u=(n+a)/2;if(n===a)o=0,l=0;else{let h=a-n;switch(l=u<=.5?h/(a+n):h/(2-a-n),a){case r:o=(i-s)/h+(i0){let c=.5/Math.sqrt(d+1);this._w=.25/c,this._x=(u-o)*c,this._y=(s-l)*c,this._z=(a-i)*c}else if(r>n&&r>h){let c=2*Math.sqrt(1+r-n-h);this._w=(u-o)/c,this._x=.25*c,this._y=(i+a)/c,this._z=(s+l)/c}else if(n>h){let c=2*Math.sqrt(1+n-r-h);this._w=(s-l)/c,this._x=(i+a)/c,this._y=.25*c,this._z=(o+u)/c}else{let c=2*Math.sqrt(1+h-r-n);this._w=(a-i)/c,this._x=(s+l)/c,this._y=(o+u)/c,this._z=.25*c}return this._onChangeCallback(),this}setFromUnitVectors(e,t){let r=e.dot(t)+1;return r<1e-8?(r=0,Math.abs(e.x)>Math.abs(e.z)?(this._x=-e.y,this._y=e.x,this._z=0,this._w=r):(this._x=0,this._y=-e.z,this._z=e.y,this._w=r)):(this._x=e.y*t.z-e.z*t.y,this._y=e.z*t.x-e.x*t.z,this._z=e.x*t.y-e.y*t.x,this._w=r),this.normalize()}angleTo(e){return 2*Math.acos(Math.abs(sr(this.dot(e),-1,1)))}rotateTowards(e,t){let r=this.angleTo(e);if(r===0)return this;let i=Math.min(1,t/r);return this.slerp(e,i),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(e){return this._x*e._x+this._y*e._y+this._z*e._z+this._w*e._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let e=this.length();return e===0?(this._x=0,this._y=0,this._z=0,this._w=1):(e=1/e,this._x=this._x*e,this._y=this._y*e,this._z=this._z*e,this._w=this._w*e),this._onChangeCallback(),this}multiply(e){return this.multiplyQuaternions(this,e)}premultiply(e){return this.multiplyQuaternions(e,this)}multiplyQuaternions(e,t){let r=e._x,i=e._y,s=e._z,a=e._w,n=t._x,o=t._y,l=t._z,u=t._w;return this._x=r*u+a*n+i*l-s*o,this._y=i*u+a*o+s*n-r*l,this._z=s*u+a*l+r*o-i*n,this._w=a*u-r*n-i*o-s*l,this._onChangeCallback(),this}slerp(e,t){let r=e._x,i=e._y,s=e._z,a=e._w,n=this.dot(e);n<0&&(r=-r,i=-i,s=-s,a=-a,n=-n);let o=1-t;if(n<.9995){let l=Math.acos(n),u=Math.sin(l);o=Math.sin(o*l)/u,t=Math.sin(t*l)/u,this._x=this._x*o+r*t,this._y=this._y*o+i*t,this._z=this._z*o+s*t,this._w=this._w*o+a*t,this._onChangeCallback()}else this._x=this._x*o+r*t,this._y=this._y*o+i*t,this._z=this._z*o+s*t,this._w=this._w*o+a*t,this.normalize();return this}slerpQuaternions(e,t,r){return this.copy(e).slerp(t,r)}random(){let e=2*Math.PI*Math.random(),t=2*Math.PI*Math.random(),r=Math.random(),i=Math.sqrt(1-r),s=Math.sqrt(r);return this.set(i*Math.sin(e),i*Math.cos(e),s*Math.sin(t),s*Math.cos(t))}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._w===this._w}fromArray(e,t=0){return this._x=e[t],this._y=e[t+1],this._z=e[t+2],this._w=e[t+3],this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._w,e}fromBufferAttribute(e,t){return this._x=e.getX(t),this._y=e.getY(t),this._z=e.getZ(t),this._w=e.getW(t),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}},Zl=class lD{static{lD.prototype.isVector3=!0}constructor(t=0,r=0,i=0){this.x=t,this.y=r,this.z=i}set(t,r,i){return i===void 0&&(i=this.z),this.x=t,this.y=r,this.z=i,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setComponent(t,r){switch(t){case 0:this.x=r;break;case 1:this.y=r;break;case 2:this.z=r;break;default:throw new Error("THREE.Vector3: index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("THREE.Vector3: index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this}addVectors(t,r){return this.x=t.x+r.x,this.y=t.y+r.y,this.z=t.z+r.z,this}addScaledVector(t,r){return this.x+=t.x*r,this.y+=t.y*r,this.z+=t.z*r,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this}subVectors(t,r){return this.x=t.x-r.x,this.y=t.y-r.y,this.z=t.z-r.z,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}multiplyVectors(t,r){return this.x=t.x*r.x,this.y=t.y*r.y,this.z=t.z*r.z,this}applyEuler(t){return this.applyQuaternion(NI.setFromEuler(t))}applyAxisAngle(t,r){return this.applyQuaternion(NI.setFromAxisAngle(t,r))}applyMatrix3(t){let r=this.x,i=this.y,s=this.z,a=t.elements;return this.x=a[0]*r+a[3]*i+a[6]*s,this.y=a[1]*r+a[4]*i+a[7]*s,this.z=a[2]*r+a[5]*i+a[8]*s,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){let r=this.x,i=this.y,s=this.z,a=t.elements,n=1/(a[3]*r+a[7]*i+a[11]*s+a[15]);return this.x=(a[0]*r+a[4]*i+a[8]*s+a[12])*n,this.y=(a[1]*r+a[5]*i+a[9]*s+a[13])*n,this.z=(a[2]*r+a[6]*i+a[10]*s+a[14])*n,this}applyQuaternion(t){let r=this.x,i=this.y,s=this.z,a=t.x,n=t.y,o=t.z,l=t.w,u=2*(n*s-o*i),h=2*(o*r-a*s),d=2*(a*i-n*r);return this.x=r+l*u+n*d-o*h,this.y=i+l*h+o*u-a*d,this.z=s+l*d+a*h-n*u,this}project(t){return this.applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix)}unproject(t){return this.applyMatrix4(t.projectionMatrixInverse).applyMatrix4(t.matrixWorld)}transformDirection(t){let r=this.x,i=this.y,s=this.z,a=t.elements;return this.x=a[0]*r+a[4]*i+a[8]*s,this.y=a[1]*r+a[5]*i+a[9]*s,this.z=a[2]*r+a[6]*i+a[10]*s,this.normalize()}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this}divideScalar(t){return this.multiplyScalar(1/t)}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this}clamp(t,r){return this.x=sr(this.x,t.x,r.x),this.y=sr(this.y,t.y,r.y),this.z=sr(this.z,t.z,r.z),this}clampScalar(t,r){return this.x=sr(this.x,t,r),this.y=sr(this.y,t,r),this.z=sr(this.z,t,r),this}clampLength(t,r){let i=this.length();return this.divideScalar(i||1).multiplyScalar(sr(i,t,r))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,r){return this.x+=(t.x-this.x)*r,this.y+=(t.y-this.y)*r,this.z+=(t.z-this.z)*r,this}lerpVectors(t,r,i){return this.x=t.x+(r.x-t.x)*i,this.y=t.y+(r.y-t.y)*i,this.z=t.z+(r.z-t.z)*i,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,r){let i=t.x,s=t.y,a=t.z,n=r.x,o=r.y,l=r.z;return this.x=s*l-a*o,this.y=a*n-i*l,this.z=i*o-s*n,this}projectOnVector(t){let r=t.lengthSq();if(r===0)return this.set(0,0,0);let i=t.dot(this)/r;return this.copy(t).multiplyScalar(i)}projectOnPlane(t){return Ew.copy(this).projectOnVector(t),this.sub(Ew)}reflect(t){return this.sub(Ew.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){let r=Math.sqrt(this.lengthSq()*t.lengthSq());if(r===0)return Math.PI/2;let i=this.dot(t)/r;return Math.acos(sr(i,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){let r=this.x-t.x,i=this.y-t.y,s=this.z-t.z;return r*r+i*i+s*s}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)}setFromSpherical(t){return this.setFromSphericalCoords(t.radius,t.phi,t.theta)}setFromSphericalCoords(t,r,i){let s=Math.sin(r)*t;return this.x=s*Math.sin(i),this.y=Math.cos(r)*t,this.z=s*Math.cos(i),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,r,i){return this.x=t*Math.sin(r),this.y=i,this.z=t*Math.cos(r),this}setFromMatrixPosition(t){let r=t.elements;return this.x=r[12],this.y=r[13],this.z=r[14],this}setFromMatrixScale(t){let r=this.setFromMatrixColumn(t,0).length(),i=this.setFromMatrixColumn(t,1).length(),s=this.setFromMatrixColumn(t,2).length();return this.x=r,this.y=i,this.z=s,this}setFromMatrixColumn(t,r){return this.fromArray(t.elements,r*4)}setFromMatrix3Column(t,r){return this.fromArray(t.elements,r*3)}setFromEuler(t){return this.x=t._x,this.y=t._y,this.z=t._z,this}setFromColor(t){return this.x=t.r,this.y=t.g,this.z=t.b,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z}fromArray(t,r=0){return this.x=t[r],this.y=t[r+1],this.z=t[r+2],this}toArray(t=[],r=0){return t[r]=this.x,t[r+1]=this.y,t[r+2]=this.z,t}fromBufferAttribute(t,r){return this.x=t.getX(r),this.y=t.getY(r),this.z=t.getZ(r),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){let t=Math.random()*Math.PI*2,r=Math.random()*2-1,i=Math.sqrt(1-r*r);return this.x=i*Math.cos(t),this.y=r,this.z=i*Math.sin(t),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}},Ew=new Zl,NI=new Roe,AI=class dM{static{dM.prototype.isMatrix4=!0}constructor(t,r,i,s,a,n,o,l,u,h,d,c,m,g,y,b){this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],t!==void 0&&this.set(t,r,i,s,a,n,o,l,u,h,d,c,m,g,y,b)}set(t,r,i,s,a,n,o,l,u,h,d,c,m,g,y,b){let v=this.elements;return v[0]=t,v[4]=r,v[8]=i,v[12]=s,v[1]=a,v[5]=n,v[9]=o,v[13]=l,v[2]=u,v[6]=h,v[10]=d,v[14]=c,v[3]=m,v[7]=g,v[11]=y,v[15]=b,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return new dM().fromArray(this.elements)}copy(t){let r=this.elements,i=t.elements;return r[0]=i[0],r[1]=i[1],r[2]=i[2],r[3]=i[3],r[4]=i[4],r[5]=i[5],r[6]=i[6],r[7]=i[7],r[8]=i[8],r[9]=i[9],r[10]=i[10],r[11]=i[11],r[12]=i[12],r[13]=i[13],r[14]=i[14],r[15]=i[15],this}copyPosition(t){let r=this.elements,i=t.elements;return r[12]=i[12],r[13]=i[13],r[14]=i[14],this}setFromMatrix3(t){let r=t.elements;return this.set(r[0],r[3],r[6],0,r[1],r[4],r[7],0,r[2],r[5],r[8],0,0,0,0,1),this}extractBasis(t,r,i){return this.determinantAffine()===0?(t.set(1,0,0),r.set(0,1,0),i.set(0,0,1),this):(t.setFromMatrixColumn(this,0),r.setFromMatrixColumn(this,1),i.setFromMatrixColumn(this,2),this)}makeBasis(t,r,i){return this.set(t.x,r.x,i.x,0,t.y,r.y,i.y,0,t.z,r.z,i.z,0,0,0,0,1),this}extractRotation(t){if(t.determinantAffine()===0)return this.identity();let r=this.elements,i=t.elements,s=1/gc.setFromMatrixColumn(t,0).length(),a=1/gc.setFromMatrixColumn(t,1).length(),n=1/gc.setFromMatrixColumn(t,2).length();return r[0]=i[0]*s,r[1]=i[1]*s,r[2]=i[2]*s,r[3]=0,r[4]=i[4]*a,r[5]=i[5]*a,r[6]=i[6]*a,r[7]=0,r[8]=i[8]*n,r[9]=i[9]*n,r[10]=i[10]*n,r[11]=0,r[12]=0,r[13]=0,r[14]=0,r[15]=1,this}makeRotationFromEuler(t){let r=this.elements,i=t.x,s=t.y,a=t.z,n=Math.cos(i),o=Math.sin(i),l=Math.cos(s),u=Math.sin(s),h=Math.cos(a),d=Math.sin(a);if(t.order==="XYZ"){let c=n*h,m=n*d,g=o*h,y=o*d;r[0]=l*h,r[4]=-l*d,r[8]=u,r[1]=m+g*u,r[5]=c-y*u,r[9]=-o*l,r[2]=y-c*u,r[6]=g+m*u,r[10]=n*l}else if(t.order==="YXZ"){let c=l*h,m=l*d,g=u*h,y=u*d;r[0]=c+y*o,r[4]=g*o-m,r[8]=n*u,r[1]=n*d,r[5]=n*h,r[9]=-o,r[2]=m*o-g,r[6]=y+c*o,r[10]=n*l}else if(t.order==="ZXY"){let c=l*h,m=l*d,g=u*h,y=u*d;r[0]=c-y*o,r[4]=-n*d,r[8]=g+m*o,r[1]=m+g*o,r[5]=n*h,r[9]=y-c*o,r[2]=-n*u,r[6]=o,r[10]=n*l}else if(t.order==="ZYX"){let c=n*h,m=n*d,g=o*h,y=o*d;r[0]=l*h,r[4]=g*u-m,r[8]=c*u+y,r[1]=l*d,r[5]=y*u+c,r[9]=m*u-g,r[2]=-u,r[6]=o*l,r[10]=n*l}else if(t.order==="YZX"){let c=n*l,m=n*u,g=o*l,y=o*u;r[0]=l*h,r[4]=y-c*d,r[8]=g*d+m,r[1]=d,r[5]=n*h,r[9]=-o*h,r[2]=-u*h,r[6]=m*d+g,r[10]=c-y*d}else if(t.order==="XZY"){let c=n*l,m=n*u,g=o*l,y=o*u;r[0]=l*h,r[4]=-d,r[8]=u*h,r[1]=c*d+y,r[5]=n*h,r[9]=m*d-g,r[2]=g*d-m,r[6]=o*h,r[10]=y*d+c}return r[3]=0,r[7]=0,r[11]=0,r[12]=0,r[13]=0,r[14]=0,r[15]=1,this}makeRotationFromQuaternion(t){return this.compose(Eoe,t,Poe)}lookAt(t,r,i){let s=this.elements;return ra.subVectors(t,r),ra.lengthSq()===0&&(ra.z=1),ra.normalize(),Jl.crossVectors(i,ra),Jl.lengthSq()===0&&(Math.abs(i.z)===1?ra.x+=1e-4:ra.z+=1e-4,ra.normalize(),Jl.crossVectors(i,ra)),Jl.normalize(),q1.crossVectors(ra,Jl),s[0]=Jl.x,s[4]=q1.x,s[8]=ra.x,s[1]=Jl.y,s[5]=q1.y,s[9]=ra.y,s[2]=Jl.z,s[6]=q1.z,s[10]=ra.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,r){let i=t.elements,s=r.elements,a=this.elements,n=i[0],o=i[4],l=i[8],u=i[12],h=i[1],d=i[5],c=i[9],m=i[13],g=i[2],y=i[6],b=i[10],v=i[14],S=i[3],T=i[7],w=i[11],N=i[15],C=s[0],R=s[4],E=s[8],P=s[12],I=s[1],O=s[5],L=s[9],X=s[13],z=s[2],H=s[6],ue=s[10],ne=s[14],re=s[3],ce=s[7],ge=s[11],ye=s[15];return a[0]=n*C+o*I+l*z+u*re,a[4]=n*R+o*O+l*H+u*ce,a[8]=n*E+o*L+l*ue+u*ge,a[12]=n*P+o*X+l*ne+u*ye,a[1]=h*C+d*I+c*z+m*re,a[5]=h*R+d*O+c*H+m*ce,a[9]=h*E+d*L+c*ue+m*ge,a[13]=h*P+d*X+c*ne+m*ye,a[2]=g*C+y*I+b*z+v*re,a[6]=g*R+y*O+b*H+v*ce,a[10]=g*E+y*L+b*ue+v*ge,a[14]=g*P+y*X+b*ne+v*ye,a[3]=S*C+T*I+w*z+N*re,a[7]=S*R+T*O+w*H+N*ce,a[11]=S*E+T*L+w*ue+N*ge,a[15]=S*P+T*X+w*ne+N*ye,this}multiplyScalar(t){let r=this.elements;return r[0]*=t,r[4]*=t,r[8]*=t,r[12]*=t,r[1]*=t,r[5]*=t,r[9]*=t,r[13]*=t,r[2]*=t,r[6]*=t,r[10]*=t,r[14]*=t,r[3]*=t,r[7]*=t,r[11]*=t,r[15]*=t,this}determinant(){let t=this.elements,r=t[0],i=t[4],s=t[8],a=t[12],n=t[1],o=t[5],l=t[9],u=t[13],h=t[2],d=t[6],c=t[10],m=t[14],g=t[3],y=t[7],b=t[11],v=t[15],S=l*m-u*c,T=o*m-u*d,w=o*c-l*d,N=n*m-u*h,C=n*c-l*h,R=n*d-o*h;return r*(y*S-b*T+v*w)-i*(g*S-b*N+v*C)+s*(g*T-y*N+v*R)-a*(g*w-y*C+b*R)}determinantAffine(){let t=this.elements,r=t[0],i=t[4],s=t[8],a=t[1],n=t[5],o=t[9],l=t[2],u=t[6],h=t[10];return r*(n*h-o*u)-i*(a*h-o*l)+s*(a*u-n*l)}transpose(){let t=this.elements,r;return r=t[1],t[1]=t[4],t[4]=r,r=t[2],t[2]=t[8],t[8]=r,r=t[6],t[6]=t[9],t[9]=r,r=t[3],t[3]=t[12],t[12]=r,r=t[7],t[7]=t[13],t[13]=r,r=t[11],t[11]=t[14],t[14]=r,this}setPosition(t,r,i){let s=this.elements;return t.isVector3?(s[12]=t.x,s[13]=t.y,s[14]=t.z):(s[12]=t,s[13]=r,s[14]=i),this}invert(){let t=this.elements,r=t[0],i=t[1],s=t[2],a=t[3],n=t[4],o=t[5],l=t[6],u=t[7],h=t[8],d=t[9],c=t[10],m=t[11],g=t[12],y=t[13],b=t[14],v=t[15],S=r*o-i*n,T=r*l-s*n,w=r*u-a*n,N=i*l-s*o,C=i*u-a*o,R=s*u-a*l,E=h*y-d*g,P=h*b-c*g,I=h*v-m*g,O=d*b-c*y,L=d*v-m*y,X=c*v-m*b,z=S*X-T*L+w*O+N*I-C*P+R*E;if(z===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);let H=1/z;return t[0]=(o*X-l*L+u*O)*H,t[1]=(s*L-i*X-a*O)*H,t[2]=(y*R-b*C+v*N)*H,t[3]=(c*C-d*R-m*N)*H,t[4]=(l*I-n*X-u*P)*H,t[5]=(r*X-s*I+a*P)*H,t[6]=(b*w-g*R-v*T)*H,t[7]=(h*R-c*w+m*T)*H,t[8]=(n*L-o*I+u*E)*H,t[9]=(i*I-r*L-a*E)*H,t[10]=(g*C-y*w+v*S)*H,t[11]=(d*w-h*C-m*S)*H,t[12]=(o*P-n*O-l*E)*H,t[13]=(r*O-i*P+s*E)*H,t[14]=(y*T-g*N-b*S)*H,t[15]=(h*N-d*T+c*S)*H,this}scale(t){let r=this.elements,i=t.x,s=t.y,a=t.z;return r[0]*=i,r[4]*=s,r[8]*=a,r[1]*=i,r[5]*=s,r[9]*=a,r[2]*=i,r[6]*=s,r[10]*=a,r[3]*=i,r[7]*=s,r[11]*=a,this}getMaxScaleOnAxis(){let t=this.elements,r=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],i=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],s=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(r,i,s))}makeTranslation(t,r,i){return t.isVector3?this.set(1,0,0,t.x,0,1,0,t.y,0,0,1,t.z,0,0,0,1):this.set(1,0,0,t,0,1,0,r,0,0,1,i,0,0,0,1),this}makeRotationX(t){let r=Math.cos(t),i=Math.sin(t);return this.set(1,0,0,0,0,r,-i,0,0,i,r,0,0,0,0,1),this}makeRotationY(t){let r=Math.cos(t),i=Math.sin(t);return this.set(r,0,i,0,0,1,0,0,-i,0,r,0,0,0,0,1),this}makeRotationZ(t){let r=Math.cos(t),i=Math.sin(t);return this.set(r,-i,0,0,i,r,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,r){let i=Math.cos(r),s=Math.sin(r),a=1-i,n=t.x,o=t.y,l=t.z,u=a*n,h=a*o;return this.set(u*n+i,u*o-s*l,u*l+s*o,0,u*o+s*l,h*o+i,h*l-s*n,0,u*l-s*o,h*l+s*n,a*l*l+i,0,0,0,0,1),this}makeScale(t,r,i){return this.set(t,0,0,0,0,r,0,0,0,0,i,0,0,0,0,1),this}makeShear(t,r,i,s,a,n){return this.set(1,i,a,0,t,1,n,0,r,s,1,0,0,0,0,1),this}compose(t,r,i){let s=this.elements,a=r._x,n=r._y,o=r._z,l=r._w,u=a+a,h=n+n,d=o+o,c=a*u,m=a*h,g=a*d,y=n*h,b=n*d,v=o*d,S=l*u,T=l*h,w=l*d,N=i.x,C=i.y,R=i.z;return s[0]=(1-(y+v))*N,s[1]=(m+w)*N,s[2]=(g-T)*N,s[3]=0,s[4]=(m-w)*C,s[5]=(1-(c+v))*C,s[6]=(b+S)*C,s[7]=0,s[8]=(g+T)*R,s[9]=(b-S)*R,s[10]=(1-(c+y))*R,s[11]=0,s[12]=t.x,s[13]=t.y,s[14]=t.z,s[15]=1,this}decompose(t,r,i){let s=this.elements;t.x=s[12],t.y=s[13],t.z=s[14];let a=this.determinantAffine();if(a===0)return i.set(1,1,1),r.identity(),this;let n=gc.set(s[0],s[1],s[2]).length(),o=gc.set(s[4],s[5],s[6]).length(),l=gc.set(s[8],s[9],s[10]).length();a<0&&(n=-n),en.copy(this);let u=1/n,h=1/o,d=1/l;return en.elements[0]*=u,en.elements[1]*=u,en.elements[2]*=u,en.elements[4]*=h,en.elements[5]*=h,en.elements[6]*=h,en.elements[8]*=d,en.elements[9]*=d,en.elements[10]*=d,r.setFromRotationMatrix(en),i.x=n,i.y=o,i.z=l,this}makePerspective(t,r,i,s,a,n,o=uh,l=!1){let u=this.elements,h=2*a/(r-t),d=2*a/(i-s),c=(r+t)/(r-t),m=(i+s)/(i-s),g,y;if(l)g=a/(n-a),y=n*a/(n-a);else if(o===uh)g=-(n+a)/(n-a),y=-2*n*a/(n-a);else if(o===Mw)g=-n/(n-a),y=-n*a/(n-a);else throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+o);return u[0]=h,u[4]=0,u[8]=c,u[12]=0,u[1]=0,u[5]=d,u[9]=m,u[13]=0,u[2]=0,u[6]=0,u[10]=g,u[14]=y,u[3]=0,u[7]=0,u[11]=-1,u[15]=0,this}makeOrthographic(t,r,i,s,a,n,o=uh,l=!1){let u=this.elements,h=2/(r-t),d=2/(i-s),c=-(r+t)/(r-t),m=-(i+s)/(i-s),g,y;if(l)g=1/(n-a),y=n/(n-a);else if(o===uh)g=-2/(n-a),y=-(n+a)/(n-a);else if(o===Mw)g=-1/(n-a),y=-a/(n-a);else throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+o);return u[0]=h,u[4]=0,u[8]=0,u[12]=c,u[1]=0,u[5]=d,u[9]=0,u[13]=m,u[2]=0,u[6]=0,u[10]=g,u[14]=y,u[3]=0,u[7]=0,u[11]=0,u[15]=1,this}equals(t){let r=this.elements,i=t.elements;for(let s=0;s<16;s++)if(r[s]!==i[s])return!1;return!0}fromArray(t,r=0){for(let i=0;i<16;i++)this.elements[i]=t[i+r];return this}toArray(t=[],r=0){let i=this.elements;return t[r]=i[0],t[r+1]=i[1],t[r+2]=i[2],t[r+3]=i[3],t[r+4]=i[4],t[r+5]=i[5],t[r+6]=i[6],t[r+7]=i[7],t[r+8]=i[8],t[r+9]=i[9],t[r+10]=i[10],t[r+11]=i[11],t[r+12]=i[12],t[r+13]=i[13],t[r+14]=i[14],t[r+15]=i[15],t}},gc=new Zl,en=new AI,Eoe=new Zl(0,0,0),Poe=new Zl(1,1,1),Jl=new Zl,q1=new Zl,ra=new Zl,Boe=class uD{static{uD.prototype.isVector2=!0}constructor(t=0,r=0){this.x=t,this.y=r}get width(){return this.x}set width(t){this.x=t}get height(){return this.y}set height(t){this.y=t}set(t,r){return this.x=t,this.y=r,this}setScalar(t){return this.x=t,this.y=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setComponent(t,r){switch(t){case 0:this.x=r;break;case 1:this.y=r;break;default:throw new Error("THREE.Vector2: index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;default:throw new Error("THREE.Vector2: index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y)}copy(t){return this.x=t.x,this.y=t.y,this}add(t){return this.x+=t.x,this.y+=t.y,this}addScalar(t){return this.x+=t,this.y+=t,this}addVectors(t,r){return this.x=t.x+r.x,this.y=t.y+r.y,this}addScaledVector(t,r){return this.x+=t.x*r,this.y+=t.y*r,this}sub(t){return this.x-=t.x,this.y-=t.y,this}subScalar(t){return this.x-=t,this.y-=t,this}subVectors(t,r){return this.x=t.x-r.x,this.y=t.y-r.y,this}multiply(t){return this.x*=t.x,this.y*=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divide(t){return this.x/=t.x,this.y/=t.y,this}divideScalar(t){return this.multiplyScalar(1/t)}applyMatrix3(t){let r=this.x,i=this.y,s=t.elements;return this.x=s[0]*r+s[3]*i+s[6],this.y=s[1]*r+s[4]*i+s[7],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this}clamp(t,r){return this.x=sr(this.x,t.x,r.x),this.y=sr(this.y,t.y,r.y),this}clampScalar(t,r){return this.x=sr(this.x,t,r),this.y=sr(this.y,t,r),this}clampLength(t,r){let i=this.length();return this.divideScalar(i||1).multiplyScalar(sr(i,t,r))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(t){let r=Math.sqrt(this.lengthSq()*t.lengthSq());if(r===0)return Math.PI/2;let i=this.dot(t)/r;return Math.acos(sr(i,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){let r=this.x-t.x,i=this.y-t.y;return r*r+i*i}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,r){return this.x+=(t.x-this.x)*r,this.y+=(t.y-this.y)*r,this}lerpVectors(t,r,i){return this.x=t.x+(r.x-t.x)*i,this.y=t.y+(r.y-t.y)*i,this}equals(t){return t.x===this.x&&t.y===this.y}fromArray(t,r=0){return this.x=t[r],this.y=t[r+1],this}toArray(t=[],r=0){return t[r]=this.x,t[r+1]=this.y,t}fromBufferAttribute(t,r){return this.x=t.getX(r),this.y=t.getY(r),this}rotateAround(t,r){let i=Math.cos(r),s=Math.sin(r),a=this.x-t.x,n=this.y-t.y;return this.x=a*i-n*s+t.x,this.y=a*s+n*i+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}},Ioe=class hD{static{hD.prototype.isVector4=!0}constructor(t=0,r=0,i=0,s=1){this.x=t,this.y=r,this.z=i,this.w=s}get width(){return this.z}set width(t){this.z=t}get height(){return this.w}set height(t){this.w=t}set(t,r,i,s){return this.x=t,this.y=r,this.z=i,this.w=s,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this.w=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setW(t){return this.w=t,this}setComponent(t,r){switch(t){case 0:this.x=r;break;case 1:this.y=r;break;case 2:this.z=r;break;case 3:this.w=r;break;default:throw new Error("THREE.Vector4: index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("THREE.Vector4: index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w!==void 0?t.w:1,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this.w+=t,this}addVectors(t,r){return this.x=t.x+r.x,this.y=t.y+r.y,this.z=t.z+r.z,this.w=t.w+r.w,this}addScaledVector(t,r){return this.x+=t.x*r,this.y+=t.y*r,this.z+=t.z*r,this.w+=t.w*r,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this.w-=t,this}subVectors(t,r){return this.x=t.x-r.x,this.y=t.y-r.y,this.z=t.z-r.z,this.w=t.w-r.w,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this.w*=t.w,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this}applyMatrix4(t){let r=this.x,i=this.y,s=this.z,a=this.w,n=t.elements;return this.x=n[0]*r+n[4]*i+n[8]*s+n[12]*a,this.y=n[1]*r+n[5]*i+n[9]*s+n[13]*a,this.z=n[2]*r+n[6]*i+n[10]*s+n[14]*a,this.w=n[3]*r+n[7]*i+n[11]*s+n[15]*a,this}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this.w/=t.w,this}divideScalar(t){return this.multiplyScalar(1/t)}setAxisAngleFromQuaternion(t){this.w=2*Math.acos(t.w);let r=Math.sqrt(1-t.w*t.w);return r<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=t.x/r,this.y=t.y/r,this.z=t.z/r),this}setAxisAngleFromRotationMatrix(t){let r,i,s,a,n=t.elements,o=n[0],l=n[4],u=n[8],h=n[1],d=n[5],c=n[9],m=n[2],g=n[6],y=n[10];if(Math.abs(l-h)<.01&&Math.abs(u-m)<.01&&Math.abs(c-g)<.01){if(Math.abs(l+h)<.1&&Math.abs(u+m)<.1&&Math.abs(c+g)<.1&&Math.abs(o+d+y-3)<.1)return this.set(1,0,0,0),this;r=Math.PI;let v=(o+1)/2,S=(d+1)/2,T=(y+1)/2,w=(l+h)/4,N=(u+m)/4,C=(c+g)/4;return v>S&&v>T?v<.01?(i=0,s=.707106781,a=.707106781):(i=Math.sqrt(v),s=w/i,a=N/i):S>T?S<.01?(i=.707106781,s=0,a=.707106781):(s=Math.sqrt(S),i=w/s,a=C/s):T<.01?(i=.707106781,s=.707106781,a=0):(a=Math.sqrt(T),i=N/a,s=C/a),this.set(i,s,a,r),this}let b=Math.sqrt((g-c)*(g-c)+(u-m)*(u-m)+(h-l)*(h-l));return Math.abs(b)<.001&&(b=1),this.x=(g-c)/b,this.y=(u-m)/b,this.z=(h-l)/b,this.w=Math.acos((o+d+y-1)/2),this}setFromMatrixPosition(t){let r=t.elements;return this.x=r[12],this.y=r[13],this.z=r[14],this.w=r[15],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this.w=Math.min(this.w,t.w),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this.w=Math.max(this.w,t.w),this}clamp(t,r){return this.x=sr(this.x,t.x,r.x),this.y=sr(this.y,t.y,r.y),this.z=sr(this.z,t.z,r.z),this.w=sr(this.w,t.w,r.w),this}clampScalar(t,r){return this.x=sr(this.x,t,r),this.y=sr(this.y,t,r),this.z=sr(this.z,t,r),this.w=sr(this.w,t,r),this}clampLength(t,r){let i=this.length();return this.divideScalar(i||1).multiplyScalar(sr(i,t,r))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z+this.w*t.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,r){return this.x+=(t.x-this.x)*r,this.y+=(t.y-this.y)*r,this.z+=(t.z-this.z)*r,this.w+=(t.w-this.w)*r,this}lerpVectors(t,r,i){return this.x=t.x+(r.x-t.x)*i,this.y=t.y+(r.y-t.y)*i,this.z=t.z+(r.z-t.z)*i,this.w=t.w+(r.w-t.w)*i,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z&&t.w===this.w}fromArray(t,r=0){return this.x=t[r],this.y=t[r+1],this.z=t[r+2],this.w=t[r+3],this}toArray(t=[],r=0){return t[r]=this.x,t[r+1]=this.y,t[r+2]=this.z,t[r+3]=this.w,t}fromBufferAttribute(t,r){return this.x=t.getX(r),this.y=t.getY(r),this.z=t.getZ(r),this.w=t.getW(r),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}},Foe=[/^StackTrace\.js$/,/^TSLCore\.js$/,/^.*Node\.js$/,/^three\.webgpu.*\.js$/];function Loe(e){let t=/(?:at\s+(.+?)\s+\()?(?:(.+?)@)?([^@\s()]+):(\d+):(\d+)/;return e.split(` `).map(r=>{let i=r.match(t);if(!i)return null;let s=i[1]||i[2]||"",a=i[3].split("?")[0],n=parseInt(i[4],10),o=parseInt(i[5],10),l=a.split("/").pop();return{fn:s,file:l,line:n,column:o}}).filter(r=>r&&!Foe.some(i=>i.test(r.file)))}var koe=class{constructor(e=null){this.isStackTrace=!0,this.stack=Loe(e||new Error().stack)}getLocation(){if(this.stack.length===0)return"[Unknown location]";let e=this.stack[0],t=e.fn;return`${t?`"${t}()" at `:""}"${e.file}:${e.line}"`}getError(e){if(this.stack.length===0)return e;let t=this.stack.map(r=>{let i=`${r.file}:${r.line}:${r.column}`;return r.fn?` at ${r.fn} (${i})`:` at ${i}`}).join(` `);return`${e} ${t}`}},hh=koe;function Pw(e,t=0){let r=3735928559^t,i=1103547991^t;if(Array.isArray(e))for(let s=0,a;s>>16,2246822507),r^=Math.imul(i^i>>>13,3266489909),i=Math.imul(i^i>>>16,2246822507),i^=Math.imul(r^r>>>13,3266489909),4294967296*(2097151&i)+(r>>>0)}var Doe=e=>Pw(e),Ooe=e=>Pw(e),Uoe=(...e)=>Pw(e);function Bw(e){if(e==null)return null;let t=typeof e;return e.isNode===!0?"node":t==="number"?"float":t==="boolean"?"bool":t==="string"?"string":t==="function"?"shader":e.isVector2===!0?"vec2":e.isVector3===!0?"vec3":e.isVector4===!0?"vec4":e.isMatrix2===!0?"mat2":e.isMatrix3===!0?"mat3":e.isMatrix4===!0?"mat4":e.isColor===!0?"color":e instanceof ArrayBuffer?"ArrayBuffer":null}function CI(e,...t){let r=e?e.slice(-4):void 0;return t.length===1&&(r==="vec2"?t=[t[0],t[0]]:r==="vec3"?t=[t[0],t[0],t[0]]:r==="vec4"&&(t=[t[0],t[0],t[0],t[0]])),e==="color"?new Rw(...t):r==="vec2"?new Boe(...t):r==="vec3"?new Zl(...t):r==="vec4"?new Ioe(...t):r==="mat2"?new Coe(...t):r==="mat3"?new X1(...t):r==="mat4"?new AI(...t):e==="bool"?t[0]||!1:e==="float"||e==="int"||e==="uint"?t[0]||0:e==="string"?t[0]||"":e==="ArrayBuffer"?Voe(t[0]):null}function zoe(e){let t="",r=new Uint8Array(e);for(let i=0;it.charCodeAt(0)).buffer}var Goe=class{addEventListener(e,t){this._listeners===void 0&&(this._listeners={});let r=this._listeners;r[e]===void 0&&(r[e]=[]),r[e].indexOf(t)===-1&&r[e].push(t)}hasEventListener(e,t){let r=this._listeners;return r===void 0?!1:r[e]!==void 0&&r[e].indexOf(t)!==-1}removeEventListener(e,t){let r=this._listeners;if(r===void 0)return;let i=r[e];if(i!==void 0){let s=i.indexOf(t);s!==-1&&i.splice(s,1)}}dispatchEvent(e){let t=this._listeners;if(t===void 0)return;let r=t[e.type];if(r!==void 0){e.target=this;let i=r.slice(0);for(let s=0,a=i.length;s0&&(t.inputNodes=i)}deserialize(t){if(t.inputNodes!==void 0){let r=t.meta.nodes;for(let i in t.inputNodes)if(Array.isArray(t.inputNodes[i])){let s=[];for(let a of t.inputNodes[i])s.push(r[a]);this[i]=s}else if(typeof t.inputNodes[i]=="object"){let s={};for(let a in t.inputNodes[i]){let n=t.inputNodes[i][a];s[a]=r[n]}this[i]=s}else{let s=t.inputNodes[i];this[i]=r[s]}}}toJSON(t){let{uuid:r,type:i}=this,s=t===void 0||typeof t=="string";s&&(t={textures:{},images:{},nodes:{}});let a=t.nodes[r];a===void 0&&(a={uuid:r,type:i,meta:t,metadata:{version:4.7,type:"Node",generator:"Node.toJSON"}},s!==!0&&(t.nodes[a.uuid]=a),this.serialize(a),delete a.meta);function n(o){let l=[];for(let u in o){let h=o[u];delete h.metadata,l.push(h)}return l}if(s){let o=n(t.textures),l=n(t.images),u=n(t.nodes);o.length>0&&(a.textures=o),l.length>0&&(a.images=l),u.length>0&&(a.nodes=u)}return a}};RI.captureStackTrace=!1;var Hr=RI,Hoe=class extends Hr{static get type(){return"TempNode"}constructor(e=null){super(e),this.isTempNode=!0}hasDependencies(e){return e.getDataFromNode(this).usageCount>1}build(e,t){if(e.getBuildStage()==="generate"){let r=e.getVectorType(this.getNodeType(e,t)),i=e.getDataFromNode(this);if(i.propertyName!==void 0)return e.format(i.propertyName,r,t);if(r!=="void"&&t!=="void"&&this.hasDependencies(e)){let s=super.build(e,r),a=e.getVarFromNode(this,null,r),n=e.getPropertyName(a);return e.addLineFlowCode(`${n} = ${s}`,this),i.snippet=s,i.propertyName=n,e.format(i.propertyName,r,t)}}return super.build(e,t)}},Um=Hoe,Xoe=class extends Hr{static get type(){return"ArrayElementNode"}constructor(e,t){super(),this.node=e,this.indexNode=t,this.isArrayElementNode=!0}generateNodeType(e){return this.node.getElementType(e)}getMemberType(e,t){return this.node.getMemberType(e,t)}generate(e){let t=this.indexNode.getNodeType(e),r=this.node.build(e),i=this.indexNode.build(e,!e.isVector(t)&&e.isInteger(t)?t:"uint");return`${r}[ ${i} ]`}},EI=Xoe,$oe=class extends Hr{static get type(){return"ConvertNode"}constructor(e,t){super(),this.node=e,this.convertTo=t}generateNodeType(e){let t=this.node.getNodeType(e),r=null;for(let i of this.convertTo.split("|"))(r===null||e.getTypeLength(t)===e.getTypeLength(i))&&(r=i);return r}serialize(e){super.serialize(e),e.convertTo=this.convertTo}deserialize(e){super.deserialize(e),this.convertTo=e.convertTo}generate(e,t){let r=this.node,i=this.getNodeType(e),s=r.build(e,i);return e.format(s,i,t)}},PI=$oe,qoe=class extends Um{static get type(){return"JoinNode"}constructor(e=[],t=null){super(t),this.nodes=e}generateNodeType(e){return this.nodeType!==null?e.getVectorType(this.nodeType):e.getTypeFromLength(this.nodes.reduce((t,r)=>t+e.getTypeLength(r.getNodeType(e)),0))}generate(e,t){let r=this.getNodeType(e),i=e.getTypeLength(r),s=this.nodes,a=e.getComponentType(r),n=[],o=0;for(let u of s){if(o>=i){Uo(`TSL: Length of parameters exceeds maximum length of function '${r}()' type.`,this.stackTrace);break}let h=u.getNodeType(e),d=e.getTypeLength(h),c;if(o+d>i&&(Uo(`TSL: Length of '${r}()' data exceeds maximum length of output type.`,this.stackTrace),d=i-o,h=e.getTypeFromLength(d)),o+=d,c=u.build(e,h),e.getComponentType(h)!==a){let m=e.getTypeFromLength(d,a);c=e.format(c,h,m)}n.push(c)}let l=`${e.getType(r)}( ${n.join(", ")} )`;return e.format(l,r,t)}},Yoe=qoe,Zoe=j1.join(""),Joe=class extends Hr{static get type(){return"SplitNode"}constructor(e,t="x"){super(),this.node=e,this.components=t,this.isSplitNode=!0}getVectorLength(){let e=this.components.length;for(let t of this.components)e=Math.max(j1.indexOf(t)+1,e);return e}getComponentType(e){return e.getComponentType(this.node.getNodeType(e))}generateNodeType(e){return e.getTypeFromLength(this.components.length,this.getComponentType(e))}getScope(){return this.node.getScope()}generate(e,t){let r=this.node,i=e.getTypeLength(r.getNodeType(e)),s=null;if(i>1){let a=null;this.getVectorLength()>=i&&(a=e.getTypeFromLength(this.getVectorLength(),this.getComponentType(e)));let n=r.build(e,a);this.components.length===i&&this.components===Zoe.slice(0,this.components.length)?s=e.format(n,a,t):s=e.format(`${n}.${this.components}`,this.getNodeType(e),t)}else s=r.build(e,t);return s}serialize(e){super.serialize(e),e.components=this.components}deserialize(e){super.deserialize(e),this.components=e.components}},Qoe=Joe,Koe=class extends Um{static get type(){return"SetNode"}constructor(e,t,r){super(),this.sourceNode=e,this.components=t,this.targetNode=r}generateNodeType(e){return this.sourceNode.getNodeType(e)}generate(e){let{sourceNode:t,components:r,targetNode:i}=this,s=this.getNodeType(e),a=e.getComponentType(i.getNodeType(e)),n=e.getTypeFromLength(r.length,a),o=i.build(e,n),l=t.build(e,s),u=e.getTypeLength(s),h=[];for(let d=0;de.replace(/r|s/g,"x").replace(/g|t/g,"y").replace(/b|p/g,"z").replace(/a|q/g,"w"),II=e=>lle(e).split("").sort().join("");Hr.prototype.assign=function(...e){if(this.isStackNode!==!0)return Y1!==null?Y1.assign(this,...e):Uo("TSL: No stack defined for assign operation. Make sure the assign is inside a Fn().",new hh),this;{let t=Iw.get("assign");return this.addToStack(t(...e))}},Hr.prototype.toVarIntent=function(){return this},Hr.prototype.get=function(e){return new ole(this,e)};var zm={};function Z1(e,t,r){zm[e]=zm[t]=zm[r]={get(){this._cache=this._cache||{};let n=this._cache[e];return n===void 0&&(n=new Qoe(this,e),this._cache[e]=n),n},set(n){this[e].assign(zi(n))}};let i=e.toUpperCase(),s=t.toUpperCase(),a=r.toUpperCase();Hr.prototype["set"+i]=Hr.prototype["set"+s]=Hr.prototype["set"+a]=function(n){let o=II(e);return new ele(this,o,zi(n))},Hr.prototype["flip"+i]=Hr.prototype["flip"+s]=Hr.prototype["flip"+a]=function(){let n=II(e);return new rle(this,n)}}var Gn=["x","y","z","w"],Wn=["r","g","b","a"],jn=["s","t","p","q"];for(let e=0;e<4;e++){let t=Gn[e],r=Wn[e],i=jn[e];Z1(t,r,i);for(let s=0;s<4;s++){t=Gn[e]+Gn[s],r=Wn[e]+Wn[s],i=jn[e]+jn[s],Z1(t,r,i);for(let a=0;a<4;a++){t=Gn[e]+Gn[s]+Gn[a],r=Wn[e]+Wn[s]+Wn[a],i=jn[e]+jn[s]+jn[a],Z1(t,r,i);for(let n=0;n<4;n++)t=Gn[e]+Gn[s]+Gn[a]+Gn[n],r=Wn[e]+Wn[s]+Wn[a]+Wn[n],i=jn[e]+jn[s]+jn[a]+jn[n],Z1(t,r,i)}}}for(let e=0;e<32;e++)zm[e]={get(){this._cache=this._cache||{};let t=this._cache[e];return t===void 0&&(t=new EI(this,new Vn(e,"uint")),this._cache[e]=t),t},set(t){this[e].assign(zi(t))}};Object.defineProperties(Hr.prototype,zm);var ule=function(e,t=null){let r=Bw(e);return r==="node"?e:t===null&&(r==="float"||r==="boolean")||r&&r!=="shader"&&r!=="string"?zi(Dw(e,t)):r==="shader"?e.isFn?e:dh(e):e},hle=function(e,t=null){for(let r in e)e[r]=zi(e[r],t);return e},dle=function(e,t=null){let r=e.length;for(let i=0;il?(Uo(`TSL: "${d}" parameter length exceeds limit.`,new hh),h.slice(0,l)):h}return t===null?a=(...h)=>s(new e(...Ow(u(h)))):r!==null?(r=zi(r),a=(...h)=>s(new e(t,...Ow(u(h)),r))):a=(...h)=>s(new e(t,...Ow(u(h)))),a.setParameterLength=(...h)=>(h.length===1?o=l=h[0]:h.length===2&&([o,l]=h),a),a.setName=h=>(n=h,a),a},cle=class extends Hr{constructor(e,t){super(),this.shaderNode=e,this.rawInputs=t,this.isShaderCallNodeInternal=!0}generateNodeType(e){return this.shaderNode.nodeType||this.getOutputNode(e).getNodeType(e)}getElementType(e){return this.getOutputNode(e).getElementType(e)}getMemberType(e,t){return this.getOutputNode(e).getMemberType(e,t)}call(e){let{shaderNode:t,rawInputs:r}=this,i=e.getNodeProperties(t),s=e.getClosestSubBuild(t.subBuilds)||"",a=s||"default";if(i[a])return i[a];let n=e.subBuildFn,o=e.fnCall;e.subBuildFn=s,e.fnCall=this;let l=null;if(t.layout){if(r){let d=t.layout.inputs;if(LI(r)){let c=r;for(let m=0;m{let v;return Symbol.iterator===y?v=function*(){yield void 0}:v=Reflect.get(g,y,b),v}}),h=r?mle(r):null,d=Array.isArray(r)?r.length>0:r!==null,c=t.jsFunc,m=d||c.length>1?c(h,u):c(u);l=zi(m)}return e.subBuildFn=n,e.fnCall=o,t.once&&(i[a]=l),l}setupOutput(e){return e.addStack(),e.stack.outputNode=this.call(e),e.removeStack()}getOutputNode(e){let t=e.getNodeProperties(this),r=e.getSubBuildOutput(this);return t[r]=t[r]||this.setupOutput(e),t[r].subBuild=e.getClosestSubBuild(this),t[r]}build(e,t=null){let r=null,i=e.getBuildStage(),s=e.getNodeProperties(this),a=e.getSubBuildOutput(this),n=this.getOutputNode(e),o=e.fnCall;if(e.fnCall=this,i==="setup"){let l=e.getSubBuildProperty("initialized",this);if(s[l]!==!0&&(s[l]=!0,s[a]=this.getOutputNode(e),s[a].build(e),this.shaderNode.subBuilds))for(let u of e.chaining){let h=e.getDataFromNode(u,"any");h.subBuilds=h.subBuilds||new Set;for(let d of this.shaderNode.subBuilds)h.subBuilds.add(d)}r=s[a]}else i==="analyze"?n.build(e,t):i==="generate"&&(r=n.build(e,t)||"");return e.fnCall=o,r}};function LI(e){return e[0]&&(e[0].isNode||Object.getPrototypeOf(e[0])!==Object.prototype)}function ple(e){let t;return OI(e),LI(e)?t=[...e]:t=e[0],t}function mle(e){let t=0;return OI(e),new Proxy(e,{get:(r,i,s)=>{let a;if(i==="length")return a=e.length,a;if(Symbol.iterator===i)a=function*(){for(let n of e)yield zi(n)};else{if(e.length>0)if(Object.getPrototypeOf(e[0])===Object.prototype){let n=e[0];n[i]===void 0?a=n[t++]:a=Reflect.get(n,i,s)}else e[0]instanceof Hr&&(e[i]===void 0?a=e[t++]:a=Reflect.get(e,i,s));else a=Reflect.get(r,i,s);a=zi(a)}return a}})}var fle=class extends Hr{constructor(e,t){super(t),this.jsFunc=e,this.layout=null,this.global=!0,this.once=!1}setLayout(e){return this.layout=e,this}getLayout(){return this.layout}call(e=null){return new cle(this,e)}setup(){return this.call()}},gle=[!1,!0],yle=[0,1,2,3],xle=[-1,-2],kI=[.5,1.5,1/3,1e-6,1e6,Math.PI,Math.PI*2,1/Math.PI,2/Math.PI,1/(Math.PI*2),Math.PI/2],Fw=new Map;for(let e of gle)Fw.set(e,new Vn(e));var Lw=new Map;for(let e of yle)Lw.set(e,new Vn(e,"uint"));var kw=new Map([...Lw].map(e=>new Vn(e.value,"int")));for(let e of xle)kw.set(e,new Vn(e,"int"));var J1=new Map([...kw].map(e=>new Vn(e.value)));for(let e of kI)J1.set(e,new Vn(e));for(let e of kI)J1.set(-e,new Vn(-e));var Q1={bool:Fw,uint:Lw,ints:kw,float:J1},DI=new Map([...Fw,...J1]),Dw=(e,t)=>DI.has(e)?DI.get(e):e.isNode===!0?e:new Vn(e,t),hi=function(e,t=null){return(...r)=>{for(let s of r)if(s===void 0)return Uo(`TSL: Invalid parameter for the type "${e}".`,new hh),new Vn(0,e);if((r.length===0||!["bool","float","int","uint"].includes(e)&&r.every(s=>{let a=typeof s;return a!=="object"&&a!=="function"}))&&(r=[CI(e,...r)]),r.length===1&&t!==null&&t.has(r[0]))return K1(t.get(r[0]));if(r.length===1){let s=Dw(r[0],e);return s.nodeType===e?K1(s):K1(new PI(s,e))}let i=r.map(s=>Dw(s));return K1(new Yoe(i,e))}};function vle(e,t){return new fle(e,t)}var zi=(e,t=null)=>ule(e,t),K1=(e,t=null)=>zi(e,t).toVarIntent(),OI=(e,t=null)=>new hle(e,t),Ow=(e,t=null)=>new dle(e,t),ble=(e,t=null,r=null,i=null)=>new FI(e,t,r,i),qe=(e,t=null,r=null,i={})=>new FI(e,t,r,{...i,intent:!0}),Tle=0,Sle=class extends Hr{constructor(e,t=null){super();let r=null;t!==null&&(typeof t=="object"?r=t.return:(typeof t=="string"?r=t:Uo("TSL: Invalid layout type.",new hh),t=null)),this.shaderNode=new vle(e,r),t!==null&&this.setLayout(t),this.isFn=!0}setLayout(e){let t=this.shaderNode.nodeType;if(typeof e.inputs!="object"){let r={name:"fn"+Tle++,type:t,inputs:[]};for(let i in e)i!=="return"&&r.inputs.push({name:i,type:e[i]});e=r}return this.shaderNode.setLayout(e),this}generateNodeType(e){return this.shaderNode.getNodeType(e)||"float"}call(...e){let t=this.shaderNode.call(e);return this.shaderNode.nodeType==="void"&&t.toStack(),t.toVarIntent()}once(e=null){return this.shaderNode.once=!0,this.shaderNode.subBuilds=e,this}generate(e){let t=this.getNodeType(e);return Uo('TSL: "Fn()" was declared but not invoked. Try calling it like "Fn()( ...params )".',this.stackTrace),e.generateConst(t)}};function dh(e,t=null){let r=new Sle(e,t);return new Proxy(()=>{},{apply(i,s,a){return r.call(...a)},get(i,s,a){return Reflect.get(r,s,a)},set(i,s,a,n){return Reflect.set(r,s,a,n)}})}function UI(e){return Y1&&Y1.addToStack(e),e}Re("toStack",UI);var _le=new hi("color"),Vm=new hi("float",Q1.float),Uw=new hi("int",Q1.ints),wle=new hi("uint",Q1.uint),Mle=new hi("bool",Q1.bool),zI=new hi("vec2"),Nle=new hi("ivec2"),Ale=new hi("uvec2"),Cle=new hi("bvec2"),ex=new hi("vec3"),Rle=new hi("ivec3"),Ele=new hi("uvec3"),Ple=new hi("bvec3"),tx=new hi("vec4"),Ble=new hi("ivec4"),Ile=new hi("uvec4"),Fle=new hi("bvec4"),Lle=new hi("mat2"),kle=new hi("mat3"),Dle=new hi("mat4");Re("toColor",_le),Re("toFloat",Vm),Re("toInt",Uw),Re("toUint",wle),Re("toBool",Mle),Re("toVec2",zI),Re("toIVec2",Nle),Re("toUVec2",Ale),Re("toBVec2",Cle),Re("toVec3",ex),Re("toIVec3",Rle),Re("toUVec3",Ele),Re("toBVec3",Ple),Re("toVec4",tx),Re("toIVec4",Ble),Re("toUVec4",Ile),Re("toBVec4",Fle),Re("toMat2",Lle),Re("toMat3",kle),Re("toMat4",Dle);var Ole=ble(EI).setParameterLength(2),Ule=(e,t)=>new PI(zi(e),t);Re("element",Ole),Re("convert",Ule),Re("append",e=>(ns("TSL: .append() has been renamed to .toStack().",new hh),UI(e)));var zle={"==":"equal","!=":"notEqual","<":"lessThan",">":"greaterThan","<=":"lessThanEqual",">=":"greaterThanEqual","%":"mod"},Kr=class cM extends Um{static get type(){return"OperatorNode"}constructor(t,r,i,...s){if(super(),s.length>0){let a=new cM(t,r,i);for(let n=0;n>"||i==="<<")return t.getIntegerType(n);if(i==="&&"||i==="||"||i==="^^")return"bool";if(i==="!"){let l=t.getTypeLength(n);return l>1?`bvec${l}`:"bool"}else if(i==="=="||i==="!="||i==="<"||i===">"||i==="<="||i===">="){let l=Math.max(t.getTypeLength(n),t.getTypeLength(o));return l>1?`bvec${l}`:"bool"}else{if(t.isMatrix(n)){if(o==="float")return n;if(t.isVector(o))return t.getVectorFromMatrix(n);if(t.isMatrix(o))return n}else if(t.isMatrix(o)){if(n==="float")return o;if(t.isVector(n))return t.getVectorFromMatrix(o)}return t.getTypeLength(o)>t.getTypeLength(n)?o:n}}generate(t,r){let i=this.op,{aNode:s,bNode:a}=this,n=this.getNodeType(t,r),o=null,l=null;n!=="void"?(o=s.getNodeType(t),l=a?a.getNodeType(t):null,i==="<"||i===">"||i==="<="||i===">="||i==="=="||i==="!="?t.isVector(o)?l=o:t.isVector(l)?o=l:o!==l&&(o=l="float"):i===">>"||i==="<<"?(o=n,l=t.changeComponentType(l,"uint")):i==="%"?(o=n,l=t.isInteger(o)&&t.isInteger(l)?l:o):t.isMatrix(o)?l==="float"?l="float":t.isVector(l)?l=t.getVectorFromMatrix(o):t.isMatrix(l)||(o=l=n):t.isMatrix(l)?o==="float"?o="float":t.isVector(o)?o=t.getVectorFromMatrix(l):o=l=n:o=l=n):o=l=n;let u=s.build(t,o),h=a?a.build(t,l):null,d=t.getFunctionOperator(i);if(r!=="void"){let c=t.renderer.coordinateSystem===uh;if(i==="=="||i==="!="||i==="<"||i===">"||i==="<="||i===">=")return c?t.isVector(o)?t.format(`${this.getOperatorMethod(t,r)}( ${u}, ${h} )`,n,r):t.format(`( ${u} ${i} ${h} )`,n,r):t.format(`( ${u} ${i} ${h} )`,n,r);if(i==="%")return t.isInteger(l)?t.format(`( ${u} % ${h} )`,n,r):t.format(`${this.getOperatorMethod(t,n)}( ${u}, ${h} )`,n,r);if(i==="!")return c&&t.isVector(o)?t.format(`not( ${u} )`,r):t.format(`( ${i} ${u} )`,o,r);if(i==="~")return t.format(`( ${i} ${u} )`,o,r);if(d)return t.format(`${d}( ${u}, ${h} )`,n,r);if(t.isMatrix(o)&&l==="float")return t.format(`( ${h} ${i} ${u} )`,n,r);if(o==="float"&&t.isMatrix(l))return t.format(`${u} ${i} ${h}`,n,r);{let m=`( ${u} ${i} ${h} )`;return!c&&n==="bool"&&t.isVector(o)&&t.isVector(l)&&(m=`all${m}`),t.format(m,n,r)}}else if(o!=="void")return d?t.format(`${d}( ${u}, ${h} )`,n,r):t.isMatrix(o)&&l==="float"?t.format(`${h} ${i} ${u}`,n,r):t.format(`${u} ${i} ${h}`,n,r)}serialize(t){super.serialize(t),t.op=this.op}deserialize(t){super.deserialize(t),this.op=t.op}},Vle=qe(Kr,"+").setParameterLength(2,1/0).setName("add"),zw=qe(Kr,"-").setParameterLength(2,1/0).setName("sub"),ch=qe(Kr,"*").setParameterLength(2,1/0).setName("mul"),VI=qe(Kr,"/").setParameterLength(2,1/0).setName("div"),GI=qe(Kr,"%").setParameterLength(2).setName("mod"),Gle=qe(Kr,"==").setParameterLength(2).setName("equal"),Wle=qe(Kr,"!=").setParameterLength(2).setName("notEqual"),jle=qe(Kr,"<").setParameterLength(2).setName("lessThan"),Hle=qe(Kr,">").setParameterLength(2).setName("greaterThan"),Xle=qe(Kr,"<=").setParameterLength(2).setName("lessThanEqual"),$le=qe(Kr,">=").setParameterLength(2).setName("greaterThanEqual"),qle=qe(Kr,"&&").setParameterLength(2,1/0).setName("and"),Yle=qe(Kr,"||").setParameterLength(2,1/0).setName("or"),Zle=qe(Kr,"!").setParameterLength(1).setName("not"),Jle=qe(Kr,"^^").setParameterLength(2).setName("xor"),Qle=qe(Kr,"&").setParameterLength(2).setName("bitAnd"),Kle=qe(Kr,"~").setParameterLength(1).setName("bitNot"),eue=qe(Kr,"|").setParameterLength(2).setName("bitOr"),tue=qe(Kr,"^").setParameterLength(2).setName("bitXor"),rue=qe(Kr,"<<").setParameterLength(2).setName("shiftLeft"),iue=qe(Kr,">>").setParameterLength(2).setName("shiftRight"),sue=dh(([e])=>(e.addAssign(1),e)),aue=dh(([e])=>(e.subAssign(1),e)),nue=dh(([e])=>{let t=Uw(e).toConst();return e.addAssign(1),t}),oue=dh(([e])=>{let t=Uw(e).toConst();return e.subAssign(1),t});Re("add",Vle),Re("sub",zw),Re("mul",ch),Re("div",VI),Re("mod",GI),Re("equal",Gle),Re("notEqual",Wle),Re("lessThan",jle),Re("greaterThan",Hle),Re("lessThanEqual",Xle),Re("greaterThanEqual",$le),Re("and",qle),Re("or",Yle),Re("not",Zle),Re("xor",Jle),Re("bitAnd",Qle),Re("bitNot",Kle),Re("bitOr",eue),Re("bitXor",tue),Re("shiftLeft",rue),Re("shiftRight",iue),Re("incrementBefore",sue),Re("decrementBefore",aue),Re("increment",nue),Re("decrement",oue);var de=class _r extends Um{static get type(){return"MathNode"}constructor(t,r,i=null,s=null){if(super(),(t===_r.MAX||t===_r.MIN)&&arguments.length>3){let a=new _r(t,r,i);for(let n=3;nn&&a>o?r:n>o?i:o>a?s:r}generateNodeType(t){let r=this.method;return r===_r.LENGTH||r===_r.DISTANCE||r===_r.DOT?"float":r===_r.CROSS?"vec3":r===_r.ALL||r===_r.ANY?"bool":r===_r.EQUALS?t.changeComponentType(this.aNode.getNodeType(t),"bool"):this.getInputType(t)}setup(t){let{aNode:r,bNode:i,method:s}=this,a=null;if(s===_r.ONE_MINUS)a=zw(1,r);else if(s===_r.RECIPROCAL)a=VI(1,r);else if(s===_r.DIFFERENCE)a=Vw(zw(r,i));else if(s===_r.TRANSFORM_DIRECTION){let n,o;t.isMatrix(r.getNodeType(t))?(n=r,o=i):(n=i,o=r),a=rx(ch(n,tx(ex(o),0)).xyz)}return a!==null?a:super.setup(t)}generate(t,r){if(t.getNodeProperties(this).outputNode)return super.generate(t,r);let i=this.method,s=this.getNodeType(t),a=this.getInputType(t),n=this.aNode,o=this.bNode,l=this.cNode,u=t.renderer.coordinateSystem;if(i===_r.NEGATE)return t.format("( - "+n.build(t,a)+" )",s,r);{let h=[];return i===_r.CROSS?h.push(n.build(t,s),o.build(t,s)):u===uh&&i===_r.STEP?h.push(n.build(t,t.getTypeLength(n.getNodeType(t))===1?"float":a),o.build(t,a)):u===uh&&(i===_r.MIN||i===_r.MAX)?h.push(n.build(t,a),o.build(t,t.getTypeLength(o.getNodeType(t))===1?"float":a)):i===_r.REFRACT?h.push(n.build(t,a),o.build(t,a),l.build(t,"float")):i===_r.MIX?h.push(n.build(t,a),o.build(t,a),l.build(t,t.getTypeLength(l.getNodeType(t))===1?"float":a)):(u===Mw&&i===_r.ATAN&&o!==null&&(i="atan2"),t.shaderStage!=="fragment"&&(i===_r.DFDX||i===_r.DFDY)&&(ns(`TSL: '${i}' is not supported in the ${t.shaderStage} stage.`,this.stackTrace),i="/*"+i+"*/"),h.push(n.build(t,a)),o!==null&&h.push(o.build(t,a)),l!==null&&h.push(l.build(t,a))),t.format(`${t.getMethod(i,s)}( ${h.join(", ")} )`,s,r)}}serialize(t){super.serialize(t),t.method=this.method}deserialize(t){super.deserialize(t),this.method=t.method}};de.ALL="all",de.ANY="any",de.RADIANS="radians",de.DEGREES="degrees",de.EXP="exp",de.EXP2="exp2",de.LOG="log",de.LOG2="log2",de.SQRT="sqrt",de.INVERSE_SQRT="inversesqrt",de.FLOOR="floor",de.CEIL="ceil",de.NORMALIZE="normalize",de.FRACT="fract",de.SIN="sin",de.SINH="sinh",de.COS="cos",de.COSH="cosh",de.TAN="tan",de.TANH="tanh",de.ASIN="asin",de.ASINH="asinh",de.ACOS="acos",de.ACOSH="acosh",de.ATAN="atan",de.ATANH="atanh",de.ABS="abs",de.SIGN="sign",de.LENGTH="length",de.NEGATE="negate",de.ONE_MINUS="oneMinus",de.DFDX="dFdx",de.DFDY="dFdy",de.ROUND="round",de.RECIPROCAL="reciprocal",de.TRUNC="trunc",de.FWIDTH="fwidth",de.TRANSPOSE="transpose",de.DETERMINANT="determinant",de.INVERSE="inverse",de.EQUALS="equals",de.MIN="min",de.MAX="max",de.STEP="step",de.REFLECT="reflect",de.DISTANCE="distance",de.DIFFERENCE="difference",de.DOT="dot",de.CROSS="cross",de.POW="pow",de.TRANSFORM_DIRECTION="transformDirection",de.MIX="mix",de.CLAMP="clamp",de.REFRACT="refract",de.SMOOTHSTEP="smoothstep",de.FACEFORWARD="faceforward";var lue=Vm(Math.PI),X0e=Vm(Math.PI*2),$0e=Vm(Math.PI*2),q0e=Vm(Math.PI*.5),uue=qe(de,de.ALL).setParameterLength(1),hue=qe(de,de.ANY).setParameterLength(1),due=qe(de,de.RADIANS).setParameterLength(1),cue=qe(de,de.DEGREES).setParameterLength(1),pue=qe(de,de.EXP).setParameterLength(1),mue=qe(de,de.EXP2).setParameterLength(1),fue=qe(de,de.LOG).setParameterLength(1),gue=qe(de,de.LOG2).setParameterLength(1),yue=qe(de,de.SQRT).setParameterLength(1),xue=qe(de,de.INVERSE_SQRT).setParameterLength(1),vue=qe(de,de.FLOOR).setParameterLength(1),bue=qe(de,de.CEIL).setParameterLength(1),rx=qe(de,de.NORMALIZE).setParameterLength(1),WI=qe(de,de.FRACT).setParameterLength(1),jI=qe(de,de.SIN).setParameterLength(1),Tue=qe(de,de.SINH).setParameterLength(1),Sue=qe(de,de.COS).setParameterLength(1),_ue=qe(de,de.COSH).setParameterLength(1),wue=qe(de,de.TAN).setParameterLength(1),Mue=qe(de,de.TANH).setParameterLength(1),Nue=qe(de,de.ASIN).setParameterLength(1),Aue=qe(de,de.ASINH).setParameterLength(1),Cue=qe(de,de.ACOS).setParameterLength(1),Rue=qe(de,de.ACOSH).setParameterLength(1),Eue=qe(de,de.ATAN).setParameterLength(1,2),Pue=qe(de,de.ATANH).setParameterLength(1),Vw=qe(de,de.ABS).setParameterLength(1),HI=qe(de,de.SIGN).setParameterLength(1),Bue=qe(de,de.LENGTH).setParameterLength(1),Iue=qe(de,de.NEGATE).setParameterLength(1),Fue=qe(de,de.ONE_MINUS).setParameterLength(1),Lue=qe(de,de.DFDX).setParameterLength(1),kue=qe(de,de.DFDY).setParameterLength(1),Due=qe(de,de.ROUND).setParameterLength(1),Oue=qe(de,de.RECIPROCAL).setParameterLength(1),Uue=qe(de,de.TRUNC).setParameterLength(1),zue=qe(de,de.FWIDTH).setParameterLength(1),Vue=qe(de,de.TRANSPOSE).setParameterLength(1),Gue=qe(de,de.DETERMINANT).setParameterLength(1),Wue=qe(de,de.INVERSE).setParameterLength(1),jue=qe(de,de.MIN).setParameterLength(2,1/0),Hue=qe(de,de.MAX).setParameterLength(2,1/0),Xue=qe(de,de.STEP).setParameterLength(2),$ue=qe(de,de.REFLECT).setParameterLength(2),que=qe(de,de.DISTANCE).setParameterLength(2),Yue=qe(de,de.DIFFERENCE).setParameterLength(2),Gw=qe(de,de.DOT).setParameterLength(2),Zue=qe(de,de.CROSS).setParameterLength(2),XI=qe(de,de.POW).setParameterLength(2),Jue=e=>ch(e,e),Que=e=>ch(e,e,e),Kue=e=>ch(e,e,e,e),ehe=qe(de,de.TRANSFORM_DIRECTION).setParameterLength(2),the=(e,t)=>rx(ch(t,tx(ex(e),0)).xyz),rhe=(e,t)=>rx(tx(ex(e),0).mul(t).xyz),ihe=e=>ch(HI(e),XI(Vw(e),1/3)),she=e=>Gw(e,e),$I=qe(de,de.MIX).setParameterLength(3),qI=(e,t=0,r=1)=>new de(de.CLAMP,zi(e),zi(t),zi(r)),ahe=e=>qI(e),nhe=qe(de,de.REFRACT).setParameterLength(3),ohe=qe(de,de.SMOOTHSTEP).setParameterLength(3),lhe=qe(de,de.FACEFORWARD).setParameterLength(3),uhe=dh(([e])=>{let t=43758.5453,r=Gw(e.xy,zI(12.9898,78.233)),i=GI(r,lue);return WI(jI(i).mul(t))}),hhe=(e,t,r)=>$I(t,r,e),dhe=(e,t,r)=>ohe(t,r,e),che=(e,t)=>Xue(t,e);Re("all",uue),Re("any",hue),Re("radians",due),Re("degrees",cue),Re("exp",pue),Re("exp2",mue),Re("log",fue),Re("log2",gue),Re("sqrt",yue),Re("inverseSqrt",xue),Re("floor",vue),Re("ceil",bue),Re("normalize",rx),Re("fract",WI),Re("sin",jI),Re("sinh",Tue),Re("cos",Sue),Re("cosh",_ue),Re("tan",wue),Re("tanh",Mue),Re("asin",Nue),Re("asinh",Aue),Re("acos",Cue),Re("acosh",Rue),Re("atan",Eue),Re("atanh",Pue),Re("abs",Vw),Re("sign",HI),Re("length",Bue),Re("lengthSq",she),Re("negate",Iue),Re("oneMinus",Fue),Re("dFdx",Lue),Re("dFdy",kue),Re("round",Due),Re("reciprocal",Oue),Re("trunc",Uue),Re("fwidth",zue),Re("min",jue),Re("max",Hue),Re("step",che),Re("reflect",$ue),Re("distance",que),Re("dot",Gw),Re("cross",Zue),Re("pow",XI),Re("pow2",Jue),Re("pow3",Que),Re("pow4",Kue),Re("transformDirection",ehe),Re("transformNormalByViewMatrix",the),Re("transformNormalByInverseViewMatrix",rhe),Re("mix",hhe),Re("clamp",qI),Re("refract",nhe),Re("smoothstep",dhe),Re("faceForward",lhe),Re("difference",Yue),Re("saturate",ahe),Re("cbrt",ihe),Re("transpose",Vue),Re("determinant",Gue),Re("inverse",Wue),Re("rand",uhe);var phe=dh(([e])=>{let t=e.pow(.41666).mul(1.055).sub(.055),r=e.mul(12.92),i=e.lessThanEqual(.0031308);return $I(t,r,i)}).setLayout({name:"sRGBTransferOETF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),{rtt:YI,Fn:mhe,pass:fhe,mrt:ghe,output:yhe,velocity:xhe,vec2:ix,vec3:zo,vec4:vhe,float:yc,uniform:Lr,texture:sx,screenUV:ZI,screenCoordinate:ax,screenSize:JI,mix:Ww,luminance:QI,smoothstep:jw,length:bhe,max:KI,clamp:Hw,agxToneMapping:The,acesFilmicToneMapping:She,neutralToneMapping:_he,linearToneMapping:whe,floor:eF,step:Mhe}=Jr;function Nhe(e){let t={exposure:Lr(1),contrast:Lr(1.08),blackLift:Lr(.02),monochrome:Lr(1),vignette:Lr(.2),vignetteSoft:Lr(.7),vignetteRadius:Lr(.85),grain:Lr(.03),grainSize:Lr(1),grainSeed:Lr(new fe),grainShadow:Lr(.8),bgGrain:Lr(0),bgGrainSize:Lr(2),bgGrainSeed:Lr(new fe),dither:Lr(1),focus:Lr(12.4),focusRange:Lr(3),aperture:Lr(.9),bloomStrength:Lr(.15),bloomRadius:Lr(.15),bloomThreshold:Lr(1.2),sceneFade:Lr(1),hazeIntensity:Lr(.22),upscaleSharpness:Lr(.2)},r=new(TB??YX)(e.renderer);r.outputColorTransform=!1;let i={aa:"",tonemap:"",dof:!0,haze:!1,upscaler:"",sharpen:!1},s=null,a=null,n=-1,o=null,l=1,u=-1,h=[];function d(v){i={...v};let S=h,T=[],w=L=>(L&&typeof L.dispose=="function"&&T.push(L),L);s=w(fhe(e.scene,e.camera,{type:Dt,samples:0})),s.setMRT(ghe({output:yhe,velocity:xhe}));let N=s.getTextureNode("output"),C=s.getTextureNode("depth"),R=s.getTextureNode("velocity"),E=s.getViewZNode(),P;a=null,v.upscaler==="taau"?P=a=w(jne(N,C,R,e.camera)):(P=v.aa==="traa"?a=w(Vne(N,C,R,e.camera)):N,v.upscaler==="fsr1"?P=w(Xne(P,yc(2).sub(t.upscaleSharpness.mul(2)),!0)):v.upscaler==="bilinear"&&(P=w(YI(P)))),v.sharpen&&(v.upscaler==="taau"||v.upscaler==="bilinear")&&(P=w(qne(P,yc(2).sub(t.upscaleSharpness.mul(2)),!0))),o=null,e.haze&&v.haze&&(o=w(YI(e.haze(C,E))),o.setResolutionScale(l),P=P.add(o.mul(t.hazeIntensity))),v.dof&&(P=w(Qne(P,E,t.focus,t.focusRange,t.aperture)));let I=w(soe(P,t.bloomStrength,t.bloomRadius,t.bloomThreshold));I.smoothWidth.value=.35,P=P.add(I);let O=mhe(()=>{let L=zo(P).mul(t.sceneFade).toVar(),X=QI(L);L.assign(Ww(L,zo(X),t.monochrome));let z=v.tonemap==="aces"?She(L,t.exposure):v.tonemap==="neutral"?_he(L,t.exposure):v.tonemap==="linear"?whe(L,t.exposure):The(L,t.exposure),H=Hw(zo(z),0,1).toVar(),ue=yc(.18);H.assign(Hw(ue.add(H.sub(ue).mul(t.contrast)),0,1));let ne=H.mul(H).mul(yc(3).sub(H.mul(2)));H.assign(Ww(H,ne,Hw(t.contrast.sub(1).mul(1.5),0,.6))),H.assign(H.mul(t.blackLift.oneMinus()).add(t.blackLift));let re=JI.x.div(JI.y),ce=ix(ZI.x.sub(.5).mul(re),ZI.y.sub(.5)),ge=bhe(ce).div(t.vignetteRadius),ye=jw(yc(1).sub(t.vignetteSoft),1.0001,ge).mul(t.vignette);H.assign(H.mul(ye.oneMinus()));let oe=zo(phe(H)).toVar(),Ae=eF(ax.xy.div(t.grainSize)).div(64).add(t.grainSeed),Ie=sx(e.blueNoise,Ae).r.sub(.5),Xe=sx(e.blueNoise,Ae.add(ix(.37,.61))).r.sub(.5),at=Ie.add(Xe),W=QI(oe),j=Ww(yc(1),jw(1,.05,W),t.grainShadow),G=t.grain.mul(j).mul(jw(0,.08,W).mul(.85).add(.15));oe.addAssign(zo(at.mul(G)));let ae=Mhe(.9999995,C.r),be=eF(ax.xy.div(KI(t.bgGrainSize,1))),Be=Po(zo(be,t.bgGrainSeed.x.mul(97))),$=Po(zo(be.add(ix(17.3,5.1)),t.bgGrainSeed.y.mul(53)));oe.addAssign(zo(Be.add($).sub(1).mul(t.bgGrain).mul(ae)));let U=sx(e.blueNoise,ax.xy.div(64).add(t.grainSeed.yx)).r.sub(.5),J=sx(e.blueNoise,ax.xy.div(64).add(ix(.5,.25)).add(t.grainSeed)).r.sub(.5);return oe.addAssign(zo(U.add(J).mul(t.dither).div(255))),vhe(KI(oe,0),1)})();r.outputNode=O,r.needsUpdate=!0,h=T;for(let L of S)L.dispose()}d({aa:e.initial?.aaMode??"traa",tonemap:e.initial?.tonemap??"agx",dof:e.initial?.dof.enabled??!0,haze:!!e.haze&&(e.initialHaze??!0),upscaler:e.initialPerformance?.nativePostEffects?e.initialPerformance.upscaler:"native",sharpen:!!e.initialPerformance?.nativePostEffects&&!!e.initialPerformance.upscaleSharpness&&(e.initialPerformance.upscaler==="taau"||e.initialPerformance.upscaler==="bilinear")});function c(v,S,T,w,N,C,R){let E=!!e.haze&&N!==0,P=S.nativePostEffects?S.upscaler:"native",I=S.nativePostEffects&&S.upscaleSharpness>0&&(P==="taau"||P==="bilinear");(R!==u||E!==i.haze)&&(u=R,(v.aaMode!==i.aa||v.tonemap!==i.tonemap||v.dof.enabled!==i.dof||E!==i.haze||P!==i.upscaler||I!==i.sharpen)&&d({aa:v.aaMode,tonemap:v.tonemap,dof:v.dof.enabled,haze:E,upscaler:P,sharpen:I}),t.exposure.value=v.exposure,t.contrast.value=v.contrast,t.blackLift.value=v.blackLift,t.monochrome.value=v.monochrome,t.vignette.value=v.vignette.strength,t.vignetteSoft.value=v.vignette.softness,t.vignetteRadius.value=v.vignette.radius,t.grain.value=v.grain.strength,t.grainSize.value=v.grain.size,t.grainShadow.value=v.grain.shadowWeight,t.bgGrain.value=v.grain.backgroundStrength,t.bgGrainSize.value=v.grain.backgroundSize,t.dither.value=v.dither?1:0,t.focusRange.value=v.dof.range,t.aperture.value=v.dof.aperture,t.bloomStrength.value=v.bloom.intensity,t.bloomRadius.value=v.bloom.radius,t.bloomThreshold.value=v.bloom.threshold,t.upscaleSharpness.value=S.upscaleSharpness);let O=v.grain.backgroundSpeed>0?Math.floor(C*24*v.grain.backgroundSpeed):0;t.bgGrainSeed.value.set(O*.7548776662%1+.1,O*.5698402909%1+.1);let L=v.grain.speed>0?Math.floor(C*24*v.grain.speed):0;t.grainSeed.value.set(L*.7548776662%1,L*.5698402909%1),t.focus.value=T+v.dof.focusBias,t.sceneFade.value=w,t.hazeIntensity.value=N}function m(v){v!==l&&(l=v,o&&o.setResolutionScale(v))}function g(v){s&&s.setResolutionScale(v)}function y(v){a&&(a._jitterIndex=(v%31+31)%31,v!==n+1&&a._historyRenderTarget.setSize(1,1)),n=v}function b(){for(let v of h)v.dispose();h=[],r.dispose()}return{post:r,uniforms:t,update:c,setHazeResolution:m,setSceneResolution:g,setFrame:y,dispose:b,get scenePass(){return s}}}var{normalize:Xw,cross:tF,select:Ahe,abs:Che,vec3:rF,texture:Rhe,equirectUV:Ehe,pmremTexture:Phe}=Jr;function $w(e,t,r,i){if(qa.environment)return Phe(e,r,i).rgb.mul(t);let s=Xw(r),a=Xw(tF(s,Ahe(Che(s.y).lessThan(.95),rF(0,1,0),rF(1,0,0)))),n=tF(s,a),o=i.mul(i).mul(.32),l=u=>Rhe(e,Ehe(Xw(u))).level(0).rgb;return l(s).mul(.4).add(l(s.add(a.mul(o))).mul(.15)).add(l(s.sub(a.mul(o))).mul(.15)).add(l(s.add(n.mul(o))).mul(.15)).add(l(s.sub(n.mul(o))).mul(.15)).mul(t)}var{normalize:iF,mat3:Bhe,vec3:Ihe,float:nx,dot:sF,select:Fhe,pow:aF,clamp:Lhe,reflect:khe,refract:Dhe,exp:Ohe,log:Uhe,max:qw}=Jr;function zhe({ray:e,normal:t,environment:r,u:i,f:s,roughness:a,path:n}){let o=Fhe(sF(t,e).greaterThan(0),t.negate(),t),l=qw(i.ior,1.001),u=g=>iF(Bhe(i.model).mul(g)),h=g=>$w(r,i.envStrength,u(g),a),d=aF(l.sub(1).div(l.add(1)),2),c=d.add(nx(1).sub(d).mul(aF(nx(1).sub(Lhe(sF(o,e.negate()),0,1)),5))),m=Ohe(Uhe(qw(i.attColor,Ihe(.001))).mul(n.mul(i.thicknessScale).div(qw(i.attDist,.01))).mul(s.absorption));return{reflected:h(khe(e,o)).mul(c).mul(s.reflections),transmitted:h(iF(Dhe(e,o,nx(1).div(l)))).mul(nx(1).sub(c)).mul(i.backlight).mul(m)}}var{Fn:Hn,vec3:tn,vec4:Gm,float:Ns,uniform:mr,uniformArray:Vhe,instanceIndex:ox,texture3D:xc,textureStore:vc,uvec3:Ghe,ivec3:$t,int:nF,uint:kr,If:Vi,Loop:oF,max:Vo,min:ph,length:Whe,dot:lF,clamp:bc,smoothstep:lx,mix:uF,abs:Y0e,select:Wm,instancedArray:jhe,atomicAdd:hF,atomicMax:dF,atomicStore:jm,atomicLoad:ux}=Jr,Tc=12,hx=class Kx{constructor(t,r,i,s,a,n,o,l){if(this.renderer=t,this.shape=r,this.cellOffset=o,this.flightOffset=l,this.atomics=a,this.healOffset=n,!Number.isInteger(n))throw new Error("ErosionField: healOffset must be an integer");this.res=i,this.bound=r.bound,this.u.seed.value=s;let u=()=>{let h=new d_(i,i,i);return h.type=Dt,h.format=pi,h.minFilter=lr,h.magFilter=lr,h.wrapS=h.wrapT=h.wrapR=Ti,h.generateMipmaps=!1,h};this.tex=u(),this.scratch=u(),this.crackTex=u(),this.cellTex=u(),this.texNode=xc(this.tex),this.buildComputes()}static extraShell=0;res;bound;tex;scratch;crackTex;cellTex;u={reconstruct:mr(0),dt:mr(0),time:mr(0),heal:mr(0),healRate:mr(.6),healGap:mr(.12),fallbackHeal:mr(.04),fallbackOn:mr(0),refrostTime:mr(4),cellRestore:mr(30),growEdges:mr(1),breakup:mr(.7),breakupScale:mr(10),crumbleRate:mr(1.6),crumbleCrackBias:mr(2.5),crumbleUntil:mr(-1),brushNoise:mr(.55),brushNoiseScale:mr(9),brushSoftness:mr(.5),segCount:mr(0),seed:mr(0),crackScale:mr(2.2),crackWarp:mr(.45),crackWarpScale:mr(1.4),crackCoverage:mr(.55),breakScale:mr(3),cellSnap:mr(.85)};segments=Vhe(Array.from({length:Tc*2},()=>new Wt));stepNode;copyNode;cellClearNode;flightClearNode;clearNode;fillNode;healClearNode;bakeNode;statsNode;statsClearNode;statsBuf;statsPending=!1;stats={max:0,over50:0,over90:0,refrost:0};statsReadT=-1;statsIssuedT=-1;baked=!1;skipBake=!1;texNode;lastCrackSig="";settingsVersion=-1;atomics;healOffset;cellOffset;flightOffset;uvw(t){return tn(t).div(this.bound*2).add(.5)}sample(t){return this.texNode.sample(this.uvw(t)).level(0)}sampleCrack(t){return xc(this.crackTex).sample(this.uvw(t)).level(0)}static warpDomain(t,r,i,s){return tn(t).mul(i).add(tn(r).mul(s))}buildComputes(){let t=this.res,r=t*t*t,i=this.bound,s=this.u,a=i*2/t,n=Math.max(a*1.5,Kx.extraShell),o=ox,l=()=>{let g=o.mod(kr(t)),y=o.div(kr(t)).mod(kr(t)),b=o.div(kr(t*t));return Ghe(g,y,b)},u=g=>tn(g).add(.5).div(t).sub(.5).mul(i*2),h=xc(this.tex),d=xc(this.scratch),c=xc(this.crackTex),m=xc(this.cellTex);this.stepNode=Hn(()=>{let g=l(),y=u(g).toVar(),b=this.shape.sdfNode(y).toVar(),v=h.load($t(g)).level(0).toVar(),S=v.r.toVar(),T=v.g.toVar(),w=v.b.toVar(),N=Vo(0,v.a.sub(s.dt.div(.2))).toVar(),C=c.load($t(g)).level(0).w,R=ws(y.mul(s.breakupScale).add(s.seed.mul(1.7).add(11))).mul(.5).add(.5),E=uF(Ns(1),Ns(.15).add(gi(R).mul(1.7)),s.breakup).toVar();Vi(s.time.lessThan(s.crumbleUntil),()=>{let ne=Ns(0).toVar(),re=[$t(1,0,0),$t(-1,0,0),$t(0,1,0),$t(0,-1,0),$t(0,0,1),$t(0,0,-1)];for(let oe of re){let Ae=bc($t(g).add(oe),$t(0),$t(t-1));ne.assign(Vo(ne,h.load(Ae).level(0).r))}let ce=lx(.02,-.02,b),ge=s.crumbleRate.mul(Ns(1).add(C.mul(s.crumbleCrackBias))).mul(ce),ye=ne.mul(.92).sub(.06);Vi(ye.greaterThan(S),()=>{S.assign(ph(ye,S.add(ye.sub(S).mul(gi(ge.mul(s.dt))))))})});let P=m.load($t(g)).level(0).toVar();oF({start:nF(0),end:nF(s.segCount),type:"int",condition:"<"},({i:ne})=>{let re=this.segments.element(ne.mul(2)),ce=this.segments.element(ne.mul(2).add(1)),ge=re.xyz,ye=ce.xyz,oe=re.w,Ae=ce.w,Ie=ye.sub(ge),Xe=$=>{let U=bc(lF($.sub(ge),Ie).div(Vo(lF(Ie,Ie),1e-6)),0,1);return Whe($.sub(ge.add(Ie.mul(U))))},at=ws(y.mul(s.brushNoiseScale).add(s.seed)).mul(.5).add(ws(y.mul(s.brushNoiseScale.mul(2.7)).add(s.seed.add(3.1))).mul(.25)),W=oe.mul(Ns(1).add(at.mul(s.brushNoise))),j=W.mul(Ns(1).sub(s.brushSoftness)),G=lx(W,j,Xe(y)),ae=oe.mul(Ns(1).add(P.w.sub(.5).mul(s.brushNoise).mul(.6))),be=lx(ae,ae.mul(Ns(1).sub(s.brushSoftness)),Xe(P.xyz)),Be=uF(G,be,s.cellSnap);S.assign(ph(1,S.add(Be.mul(Ae).mul(s.dt)))),Vi(Be.greaterThan(.02),()=>{N.assign(1)})});let I=kr(this.healOffset).add(o),O=Ns(ux(this.atomics.element(I))).toVar(),L=kr(bc(P.w.mul(65535),0,65535)),X=ux(this.atomics.element(kr(this.flightOffset).add(L))).equal(kr(0));Vi(O.greaterThan(.5).and(X.or(s.reconstruct.greaterThan(.5))),()=>{jm(this.atomics.element(I),kr(0)),T.assign(ph(1,T.add(S.mul(2.5)))),S.assign(0),w.assign(1)});let z=kr(bc(P.w.mul(65535),0,65535)),H=Ns(ux(this.atomics.element(kr(this.cellOffset).add(z)))),ue=ux(this.atomics.element(kr(this.flightOffset).add(z))).equal(kr(0));Vi(H.greaterThan(.5).and(S.greaterThan(0)),()=>{w.assign(2)}),Vi(w.greaterThan(1.5).and(S.greaterThan(0)).and(ue).and(s.reconstruct.lessThan(.5)),()=>{let ne=Ns(1).toVar();Vi(s.growEdges.greaterThan(.5),()=>{ne.assign(0);let re=[$t(1,0,0),$t(-1,0,0),$t(0,1,0),$t(0,-1,0),$t(0,0,1),$t(0,0,-1)];for(let ce of re){let ge=bc($t(g).add(ce),$t(0),$t(t-1));Vi(h.load(ge).level(0).r.lessThan(.5),()=>{ne.assign(1)})}}),Vi(ne.greaterThan(.5),()=>{let re=S,ce=Vo(0,S.sub(s.cellRestore.mul(E).mul(s.dt)));T.assign(ph(1,T.add(re.sub(ce).mul(2.5)))),S.assign(ce)})}),Vi(s.heal.greaterThan(.5).and(ue.or(s.reconstruct.greaterThan(.5))),()=>{let ne=Ns(8).toVar(),re=Ns(0).toVar(),ce=[$t(1,0,0),$t(-1,0,0),$t(0,1,0),$t(0,-1,0),$t(0,0,1),$t(0,0,-1)];for(let oe of ce){let Ae=bc($t(g).add(oe),$t(0),$t(t-1)),Ie=h.load(Ae).level(0);Vi(Ie.b.greaterThan(.5),()=>{ne.assign(ph(ne,Ie.r)),re.assign(1)})}let ge=s.reconstruct.greaterThan(.5),ye=Wm(ge,Wm(ne.lessThan(.05),Ns(0),Ns(1)),ne.add(s.healGap));Vi(re.greaterThan(.5).and(ye.lessThan(S)),()=>{let oe=Wm(ge,Vo(s.cellRestore.mul(s.fallbackHeal),s.healRate),s.healRate),Ae=Vo(ye,S.sub(oe.mul(E).mul(s.dt)));T.assign(ph(1,T.add(S.sub(Ae).mul(3)))),S.assign(Ae),Vi(Ae.lessThanEqual(ye.add(.001)),()=>{w.assign(1)})}),Vi(s.fallbackOn.greaterThan(.5).and(ge.not()),()=>{let oe=Vo(0,S.sub(s.fallbackHeal.mul(E).mul(s.dt)));T.assign(ph(1,T.add(S.sub(oe).mul(3)))),S.assign(oe)})}),Vi(S.greaterThan(v.r.add(5e-4)),()=>{w.assign(0)}),T.assign(Vo(0,T.sub(s.dt.mul(E).div(Vo(s.refrostTime,.01))))),S.assign(Wm(b.greaterThan(n),0,S)),vc(this.scratch,g,Gm(S,T,w,N)).toWriteOnly()})().compute(r,[64]),this.cellClearNode=Hn(()=>{jm(this.atomics.element(kr(this.cellOffset).add(ox)),kr(0))})().compute(65536,[64]),this.flightClearNode=Hn(()=>{jm(this.atomics.element(kr(this.flightOffset).add(ox)),kr(0))})().compute(65536,[64]),this.copyNode=Hn(()=>{let g=l(),y=d.load($t(g)).level(0);vc(this.tex,g,y).toWriteOnly()})().compute(r,[64]),this.statsBuf=jhe(4,"uint").toAtomic(),this.statsClearNode=Hn(()=>{oF(4,({i:g})=>{jm(this.statsBuf.element(g),kr(0))})})().compute(1,[1]),this.statsNode=Hn(()=>{let g=l(),y=h.load($t(g)).level(0),b=y.r;dF(this.statsBuf.element(0),kr(b.mul(65535))),dF(this.statsBuf.element(3),kr(y.g.mul(65535))),Vi(b.greaterThan(.5),()=>{hF(this.statsBuf.element(1),kr(1))}),Vi(b.greaterThan(.9),()=>{hF(this.statsBuf.element(2),kr(1))})})().compute(r,[64]),this.clearNode=Hn(()=>{let g=l();vc(this.tex,g,Gm(0)).toWriteOnly()})().compute(r,[64]),this.fillNode=Hn(()=>{let g=l(),y=this.shape.sdfNode(u(g));vc(this.tex,g,Gm(Wm(y.greaterThan(n),0,1),0,0,0)).toWriteOnly()})().compute(r,[64]),this.healClearNode=Hn(()=>{jm(this.atomics.element(kr(this.healOffset).add(ox)),kr(0))})().compute(r,[64]),this.bakeNode=Hn(()=>{let g=l(),y=u(g).toVar(),b=y.mul(s.crackWarpScale).add(s.seed.mul(.11)),v=tn(ws(b).mul(.6).add(ws(b.mul(2.1).add(tn(7.3,1.9,4.4))).mul(.4)),ws(b.add(tn(13.7,5.1,9.9))).mul(.6).add(ws(b.mul(2.1).add(tn(2.2,8.8,6.1))).mul(.4)),ws(b.add(tn(3.3,17.1,12.5))).mul(.6).add(ws(b.mul(2.1).add(tn(9.7,4.4,1.1))).mul(.4))),S=Kx.warpDomain(y,v,s.crackScale,s.crackWarp),T=bm(S,s.seed,s.crackCoverage).w.div(s.crackScale),w=lx(a*2.5,0,T),N=Po(tn(g)).mul(.15);vc(this.crackTex,g,Gm(v,gi(w.add(N.mul(w))))).toWriteOnly();let C=Kx.warpDomain(y,v,s.breakScale,s.crackWarp),R=A_(C,s.seed.add(3)),E=R.xyz.sub(v.mul(s.crackWarp)).div(s.breakScale);vc(this.cellTex,g,Gm(E,Po(R.xyz.add(s.seed)))).toWriteOnly()})().compute(r,[64])}clear(t){t.compute(this.clearNode),t.compute(this.cellClearNode),t.compute(this.flightClearNode)}rebake(t,r){let i=this.u,s=le.erosion,a=le.ice.cracks;i.crackScale.value=a.largeScale,i.crackWarp.value=a.warp,i.crackWarpScale.value=a.warpScale,i.crackCoverage.value=a.coverage,i.breakScale.value=s.breakCellScale;let n=`${a.largeScale}|${a.warp}|${a.warpScale}|${a.coverage}|${s.breakCellScale}`;(!this.baked||n!==this.lastCrackSig)&&!this.skipBake&&t.compute(this.bakeNode),this.lastCrackSig=n,this.baked=!0,i.reconstruct.value=r?1:0,t.compute(r?this.fillNode:this.clearNode),t.compute(this.cellClearNode),t.compute(this.flightClearNode),t.compute(this.healClearNode),this.crumbleUntil=-1,i.crumbleUntil.value=-1}readStats(t,r=0){this.statsPending||(this.statsPending=!0,this.statsIssuedT=r,t.compute(this.statsClearNode),t.compute(this.statsNode),t.getArrayBufferAsync(this.statsBuf.value).then(i=>{let s=new Uint32Array(i);this.stats.max=s[0]/65535,this.stats.over50=s[1],this.stats.over90=s[2],this.stats.refrost=s[3]/65535,this.statsReadT=this.statsIssuedT,this.statsPending=!1}).catch(()=>{this.statsPending=!1}))}crumbleUntil=-1;step(t,r,i,s,a,n=!0){let o=le.erosion,l=le.healing,u=this.u;if(u.dt.value=Math.min(i,1/30),u.time.value=r,le.version!==this.settingsVersion){this.settingsVersion=le.version;let d=le.ice.cracks,c=`${d.largeScale}|${d.warp}|${d.warpScale}|${d.coverage}|${o.breakCellScale}`;(!this.baked||c!==this.lastCrackSig)&&(u.crackScale.value=d.largeScale,u.crackWarp.value=d.warp,u.crackWarpScale.value=d.warpScale,u.crackCoverage.value=d.coverage,u.breakScale.value=o.breakCellScale,this.skipBake||t.compute(this.bakeNode),this.baked||t.compute(this.clearNode),this.baked=!0,this.lastCrackSig=c),u.healRate.value=l.healRate,u.healGap.value=l.healGap,u.fallbackHeal.value=l.fallbackHeal,u.refrostTime.value=l.refrostTime,u.cellRestore.value=l.cellRestore,u.growEdges.value=l.growFromEdges?1:0,u.breakup.value=l.breakup,u.breakupScale.value=l.breakupScale,u.crumbleRate.value=o.crumbleRate,u.crumbleCrackBias.value=o.crumbleCrackBias,u.brushNoise.value=o.brushNoise,u.brushNoiseScale.value=o.brushNoiseScale,u.cellSnap.value=o.cellSnap,u.brushSoftness.value=Math.max(o.brushSoftness,.02)}a>0&&(pt.lastStrokeT=r,u.crumbleUntil.value=r+o.crumbleDuration,this.crumbleUntil=r+o.crumbleDuration);let h=r-pt.lastStrokeT>l.healDelay;if(pt.healing=h,u.heal.value=h?1:0,u.fallbackOn.value=r-pt.lastStrokeT>l.healDelay+l.waveTime+l.waveJitter+Math.max(l.returnDuration,l.returnAfter)+1?1:0,u.segCount.value=a,a>0){let d=this.segments.array;for(let c=0;c.5||(t.compute(this.stepNode),t.compute(this.cellClearNode),t.compute(this.copyNode))}commitAssembly(t){t.compute(this.copyNode)}dispose(){this.tex.dispose(),this.scratch.dispose(),this.crackTex.dispose(),this.cellTex.dispose()}},Hm="photographic",{Fn:Hhe,vec2:Xhe,vec3:Xn,vec4:dx,float:Pa,int:Z0e,Loop:cF,If:Yw,Break:pF,normalize:Xm,length:mF,max:Sc,min:$he,abs:fF,dot:cx,pow:Zw,exp:qhe,log:Yhe,mix:J0e,clamp:px,refract:gF,reflect:Jw,select:mx,mat3:yF,texture:Q0e,equirectUV:K0e,cameraViewMatrix:xF,cameraProjectionMatrix:Zhe,cross:Jhe}=Jr;function Qhe(e){let{shape:t,erosion:r,p:i,ray:s,normal:a,environment:n,backdrop:o,u:l,f:u,roughness:h}=e,d=t.bound,c=Math.max(.001,d/1500),m=oe=>Xm(yF(l.model).mul(oe)),g=(oe,Ae)=>$w(n,l.envStrength,oe,Ae),y=oe=>{let Ae=t.voxelSize?t.voxelSize.mul(.75):Pa(d/240),Ie=Xn(t.sdfNode(oe.add(Xn(Ae,0,0))).sub(t.sdfNode(oe.sub(Xn(Ae,0,0)))),t.sdfNode(oe.add(Xn(0,Ae,0))).sub(t.sdfNode(oe.sub(Xn(0,Ae,0)))),t.sdfNode(oe.add(Xn(0,0,Ae))).sub(t.sdfNode(oe.sub(Xn(0,0,Ae)))));return Ie.div(Sc(mF(Ie),1e-5))},b=Sc(l.ior,1.001),v=mx(cx(a,s).greaterThan(0),a.negate(),a),S=Xm(gF(s,v,Pa(1).div(b))),T=Hhe(()=>{let oe=Pa(c*2).toVar(),Ae=Pa(0).toVar();return cF(64,()=>{let Ie=i.add(S.mul(oe)),Xe=t.sdfNode(Ie),at=r.sample(Ie).r;Yw(oe.greaterThan(c*4).and(Xe.greaterThan(0).or(at.greaterThan(l.cutThreshold))),()=>{pF()}),Ae.assign(oe),oe.addAssign(px(fF(Xe).mul(.7),c,d/12)),Yw(oe.greaterThan(d*2),()=>{pF()})}),cF(5,()=>{let Ie=Ae.add(oe).mul(.5),Xe=i.add(S.mul(Ie));Yw(t.sdfNode(Xe).lessThan(0).and(r.sample(Xe).r.lessThan(l.cutThreshold)),()=>{Ae.assign(Ie)}).Else(()=>{oe.assign(Ie)})}),dx(i.add(S.mul(oe)),oe)})(),w=y(T.xyz),N=mx(cx(w,S).lessThan(0),w.negate(),w),C=gF(S,N.negate(),b),R=mF(C).lessThan(1e-4),E=mx(R,Jw(S,N),C),P=l.model.mul(dx(T.xyz,1)).xyz,I=oe=>{let Ae=m(oe),Ie=xF.mul(dx(P,1)).xyz,Xe=yF(xF).mul(Ae),at=Pa(-35).sub(Ie.z).div($he(Xe.z,-.001)),W=Ie.add(Xe.mul(px(at,0,150))),j=Zhe.mul(dx(W,1)),G=Xhe(j.x.div(Sc(j.w,.001)).mul(.5).add(.5),j.y.div(Sc(j.w,.001)).mul(-.5).add(.5));return z1(o,px(G,0,1)).add(g(Ae,h).mul(l.backlight))},O=l.dispersion.mul(u.dispersion).mul(.025),L=Xm(Jhe(S,N).add(Xn(1e-5,0,0))),X=Xn(I(Xm(E.add(L.mul(O)))).r,I(E).g,I(Xm(E.sub(L.mul(O)))).b),z=Zw(b.sub(1).div(b.add(1)),2),H=z.add(Pa(1).sub(z).mul(Zw(Pa(1).sub(px(cx(v,s.negate()),0,1)),5))).mul(u.reflections),ue=mx(R,Pa(1),z.add(Pa(1).sub(z).mul(Zw(Pa(1).sub(fF(cx(N,S))),5)))),ne=T.w.mul(l.thicknessScale),re=qhe(Yhe(Sc(l.attColor,Xn(.001))).mul(ne.div(Sc(l.attDist,.01))).mul(u.absorption)),ce=g(m(Jw(s,v)),h),ge=g(m(Jw(S,N)),h),ye=X.mul(Pa(1).sub(ue)).add(ge.mul(ue)).mul(re);return{reflected:ce.mul(H),transmitted:ye.mul(Pa(1).sub(H)),distance:ne}}var{Fn:Khe,Loop:ede,int:vF,exp:tde,clamp:rde,vec2:$m,vec3:ide,float:fx,texture:Qw,abs:sde,pow:Kw,max:ade,smoothstep:nde}=Jr;function e2(e,t,r,i,s=fx(0)){if(!e)return fx(0);let a=Kw(sde(r),ide(6)),n=a.div(ade(a.x.add(a.y).add(a.z),.001)),o=(l,u)=>$m(l.x.mul(.932).sub(l.y.mul(.362)),l.x.mul(.362).add(l.y.mul(.932))).mul(i).add(u).add($m(s.mul(.217),s.mul(.371)));return Qw(e,o(t.yz,$m(.317,.173))).r.mul(n.x).add(Qw(e,o(t.zx,$m(.619,.431))).r.mul(n.y)).add(Qw(e,o(t.xy,$m(0))).r.mul(n.z))}function ode(e,t,r,i,s){let a=Zy(Bo(e.mul(r).add(t.mul(2)),3).mul(.5).add(.5),i,s),n=Bo(e.mul(r.mul(32)).add(t.mul(3.1)),3).mul(.5).add(.5);return Kw(a,1.5).mul(nde(.3,.69,n))}function bF(e,t,r,i,s,a,n){return Khe(()=>{let o=fx(0).toVar();return ede({start:vF(0),end:vF(3),type:"int",condition:"<"},({i:l})=>{let u=fx(l).add(.5).div(3),h=t.add(i.mul(s).mul(u));o.addAssign(Kw(e2(e,h,r,a,u),1.6).mul(tde(u.mul(-.7))))}),rde(o.div(3).mul(n),0,.45)})()}var{Fn:lde,If:ude,vec3:TF,vec4:SF,float:Ql,dot:hde,smoothstep:_c,normalize:dde,clamp:cde,dFdx:pde,dFdy:mde,length:_F,max:fde}=Jr;function wF(e){let t=Lm(e+11);return[0,1,2].map(()=>{let r=new F(t()*2-1,t()*2-1,t()*2-1).normalize();return TF(r.x,r.y,r.z)})}function MF(e,t,r,i,s,a,n,o=!1){let l=ne=>o?Ql(1).sub(_c(.35,1.25,fde(_F(pde(e.mul(ne))),_F(mde(e.mul(ne)))))):Ql(1),u=ode(e,r,a.frostScale,a.frostThreshold,a.frostSoftness),h=gi(u.add(a.interiorFrost)).mul(n.frost),d=(ne,re)=>ne.sub(re.mul(hde(ne,re)).mul(Ql(1).sub(Ql(1).div(a.smudgeAniso)))),c=SF(ws(d(e.mul(a.smudgeScale),i[0]).add(r.mul(3))),ws(d(e.mul(a.smudgeScale),i[1]).add(r.mul(4))),ws(d(e.mul(a.smudgeScale),i[2]).add(r.mul(5))),ws(e.mul(a.smudgeScale.mul(1.7)).add(r.mul(7)))),m=_c(.45,.85,c.x.mul(.5).add(.5)).add(_c(.45,.85,c.y.mul(.5).add(.5))).add(_c(.45,.85,c.z.mul(.5).add(.5))),g=_c(.6,.72,c.w.mul(.5).add(.5)),y=TF(Bo(e.mul(a.smudgeMaskScale).add(r.mul(21)),2).mul(.5).add(.5),Bo(e.mul(a.bumpMaskScale).add(r.mul(27)),2).mul(.5).add(.5),Bo(e.mul(a.regionScale).add(r.mul(33)),2).mul(.5).add(.5)),b=Zy(y.x,Ql(1).sub(a.smudgeCoverage),.35),v=Zy(y.y,Ql(1).sub(a.microCoverage),.35),S=Zy(y.z,Ql(1).sub(a.regionCoverage),.45),T=gi(m.div(3).add(g.mul(.6)).mul(a.smudgeAmount).mul(b)).mul(n.smudges),w=s.sampleCrack(e),N=hx.warpDomain(e,w.xyz,a.crackLarge,a.crackWarp).add(r.mul(.37)),C=lde(()=>{let ne=SF(0,0,1,1).toVar();return ude(n.cracks.greaterThan(.5),()=>{ne.assign(s.materialPlanes?s.materialPlanes.sample(N):bm(N,a.seed,a.crackCoverage))}),ne})(),R=C.w.div(a.crackLarge),E=Ql(1).sub(a.veinContrast.mul(Bo(e.mul(a.veinScale).add(r.mul(41)),2).mul(.5).add(.5))),P=_c(a.crackWidth.mul(5),0,R).mul(a.surfaceCrack).mul(S).mul(E).mul(n.cracks),I=gi(t.y.mul(.5).add(.5)),O=Na(e.mul(a.crystalScale).add(r)).mul(a.crystalBump).mul(.6).mul(n.crystals).mul(l(a.crystalScale)),L=Na(e.mul(a.edgeBumpScale).add(r.mul(13))).mul(a.edgeBump).mul(.5).mul(n.grain).mul(l(a.edgeBumpScale)),X=Na(e.mul(a.microScale).add(r.mul(5))).mul(a.microBump).mul(v).mul(n.micro).mul(l(a.microScale)),z=Na(e.mul(a.rippleScale).add(r.mul(9))).mul(a.rippleBump).mul(I).mul(n.ripples).mul(l(a.rippleScale)),H=O.add(L).sub(X).sub(z).sub(C.xyz.mul(P).mul(.6)),ue=dde(t.add(H.mul(n.surfaceBumps)));return{frost:h,smudge:T,surfCrack:P,nSurface:ue,regionMask:S,roughness:cde(a.baseRough.add(h.mul(a.frostRough)).add(T.mul(a.smudgeRough)).add(P.mul(.12)),.015,.8)}}var{Fn:Kl,vec3:ei,vec4:$n,float:yi,uniform:je,varying:gde,texture:yde,vec2:gx,positionLocal:xde,normalLocal:NF,cameraPosition:vde,transformNormalToView:AF,normalize:yx,dot:bde,length:wc,max:As,min:xx,abs:CF,pow:eye,exp:Tde,mix:vx,smoothstep:mh,clamp:qm,reflect:tye,select:RF,If:fh,Loop:EF,Break:PF,int:BF,output:t2,screenUV:r2}=Jr,Sde=0,i2=-1;function s2(e){i2=e}function _de({shape:e,erosion:t,seed:r,environment:i,fractureDetail:s,backdrop:a,meshEntry:n,glassMatcap:o,voronoiCells:l="27"}){let u=l==="8"?ase:A_,h=Lm(r+11),d={model:je(new We),envStrength:je(1),backlight:je(.4),inclusionAmount:je(.3),inclusionScale:je(.4),baseColor:je(new gt("#f8f8f8")),ior:je(1.36),dispersion:je(.02),thicknessScale:je(1),attDist:je(.9),attColor:je(new gt("#cfd2d4")),baseRough:je(.05),frostScale:je(1.6),frostThreshold:je(.5),frostSoftness:je(.28),frostRough:je(.65),frostDiffuse:je(.55),crystalBump:je(.12),crystalScale:je(28),crackLarge:je(1.6),crackWarp:je(.45),crackCoverage:je(.55),regionScale:je(.8),regionCoverage:je(.7),veinScale:je(5),veinContrast:je(.7),crackFine:je(5.5),crackFineAmount:je(.45),fineCoverage:je(.35),fineNearLarge:je(.75),crackWidth:je(.004),crackBright:je(.4),crackDark:je(.5),crackRefr:je(.02),surfaceCrack:je(.35),crackSteps:je(14),smudgeAmount:je(.6),smudgeCoverage:je(.55),smudgeMaskScale:je(1.2),smudgeAniso:je(6),smudgeRough:je(.35),smudgeWhite:je(.08),smudgeScale:je(3.2),microBump:je(.25),microScale:je(60),microCoverage:je(.6),rippleBump:je(.3),rippleScale:je(9),bumpMaskScale:je(1.5),clearcoat:je(.3),clearcoatRough:je(.08),specularIntensity:je(1),interiorScatter:je(.25),deformAmp:je(.045),deformFreq:je(1.1),seed:je(r),edgeWidth:je(.35),edgeInset:je(.06),edgeBump:je(.6),edgeBumpScale:je(55),refrostStrength:je(1),cutThreshold:je(.7),cutSoft:je(.04),interiorSteps:je(24),interiorFrost:je(0),crumbleGlow:je(.15),edgeWhite:je(.5),lightDir:je(new F(0,1,0)),modelInv:je(new We),jitter:je(new fe),adaptiveSteps:je(0),powderTone:je(new gt("#dcdcdc")),keyIntensity:je(3.2),keyColor:je(new gt("#ffffff")),hover:je(0)},c=Object.fromEntries(Object.keys(Qd).map(V=>[V,je(Number(Qd[V]))])),m=ei(r*.731,r*.137,r*.529),g=wF(r),y=qa.matcap?new Pd:new mS,b=new F,v=new si,S=-1;y.side=ii,y.transparent=!1,y.metalness=0,y.transmission=1;let T=V=>Bo(V.mul(d.deformFreq).add(m),3).mul(d.deformAmp),w=V=>mh(d.cutThreshold.sub(d.edgeWidth),d.cutThreshold.sub(d.edgeWidth.mul(.15)),V),N=Kl(()=>{let V=xde,Oe=NF,tt=T(V),Je=t.sample(V).r,ct=w(Je),_e=t.sampleCrack(V).w.mul(d.surfaceCrack).mul(c.cracks).mul(c.surfaceBumps).mul(.012);return V.add(Oe.mul(tt.sub(ct.mul(d.edgeInset)).sub(_e)))})();y.positionNode=N;let C=gde(N),R=d.modelInv.mul($n(vde,1)).xyz,E=yx(C.sub(R)),P=d.lightDir,I=n?.position.sample(r2),O=n?.normal.sample(r2).xyz,L=n?n.depth.sample(r2).r.lessThan(.999999).and(t.sample(I.xyz).r.lessThan(d.cutThreshold)):null,X=Kl(()=>{let V=R,Oe=it=>RF(it.greaterThanEqual(0),yi(1),yi(-1)).div(As(CF(it),1e-6)),tt=ei(Oe(E.x),Oe(E.y),Oe(E.z)),Je=ei(-e.bound).sub(V).mul(tt),ct=ei(e.bound).sub(V).mul(tt),_e=xx(Je,ct),nt=As(Je,ct),dt=As(As(_e.x,As(_e.y,_e.z)),0),ft=xx(xx(nt.x,xx(nt.y,nt.z)),wc(C.sub(R))),Fe=$n(C,-1).toVar();return n&&fh(L,()=>{Fe.assign($n(I.xyz,wc(I.xyz.sub(R))))}),fh(ft.greaterThan(dt).and(Fe.w.lessThan(0)),()=>{let it=yi(2*t.bound/t.res),Rt=e.voxelSize??it,Ft=Rt.mul(.4),Ze=dt.toVar();EF(192,()=>{fh(Ze.greaterThan(ft),()=>{PF()});let ht=V.add(E.mul(Ze)),Yt=e.sdfNode(ht);fh(Yt.lessThanEqual(.001).and(t.sample(ht).r.lessThan(d.cutThreshold)),()=>{Fe.assign($n(ht,Ze)),PF()}),Ze.addAssign(As(Yt.sub(Ft).mul(.7),Rt.mul(.35)))}),fh(Fe.w.lessThan(0).and(t.sample(C).r.lessThan(d.cutThreshold)),()=>{Fe.assign($n(C,ft))})}),Fe})(),z=X.w,H=X.xyz,ue=.02,ne=ei(t.sample(H.add(ei(ue,0,0))).r.sub(t.sample(H.sub(ei(ue,0,0))).r),t.sample(H.add(ei(0,ue,0))).r.sub(t.sample(H.sub(ei(0,ue,0))).r),t.sample(H.add(ei(0,0,ue))).r.sub(t.sample(H.sub(ei(0,0,ue))).r)),re=wc(ne),ce=e.voxelSize?e.voxelSize.mul(.75):yi(ue),ge=ei(e.sdfNode(H.add(ei(ce,0,0))).sub(e.sdfNode(H.sub(ei(ce,0,0)))),e.sdfNode(H.add(ei(0,ce,0))).sub(e.sdfNode(H.sub(ei(0,ce,0)))),e.sdfNode(H.add(ei(0,0,ce))).sub(e.sdfNode(H.sub(ei(0,0,ce))))),ye=()=>RF(wc(ge).greaterThan(1e-5),ge.div(As(wc(ge),1e-5)),NF.negate()),oe=n?Kl(()=>{let V=ei(0).toVar();return fh(L,()=>V.assign(yx(O))).Else(()=>V.assign(ye())),V})():ye(),Ae=yx(vx(oe,ne.div(As(re,1e-5)),mh(.02,.15,re).mul(c.cutNormals))),Ie=H,{frost:Xe,smudge:at,surfCrack:W,nSurface:j,regionMask:G,roughness:ae}=MF(Ie,Ae,m,g,t,d,c,qa.aa);y.normalNode=AF(j.negate());let be=wc(C.sub(H)),Be=Kl(()=>{let V=yi(0).toVar(),Oe=qm(d.crackSteps.div(4).floor(),2,6).toVar();EF({start:BF(0),end:BF(Oe),type:"int",condition:"<"},({i:Je})=>{let ct=yi(Je).add(.5).div(Oe),_e=H.add(E.mul(be).mul(ct)).toVar(),nt=t.sampleCrack(_e),dt=hx.warpDomain(_e,nt.xyz,d.crackLarge,d.crackWarp).add(m.mul(.37)),ft=t.materialPlanes?t.materialPlanes.sample(dt):bm(dt,d.seed,d.crackCoverage),Fe=As(d.crackWidth.mul(d.crackLarge),.001),it=yi(1).sub(mh(Fe,Fe.mul(2.5),ft.w)),Rt=yi(1).sub(d.veinContrast.mul(Bo(_e.mul(d.veinScale).add(m.mul(41)),2).mul(.5).add(.5))),Ft=t.materialPlanes?t.materialPlanes.sample(dt.mul(d.crackFine.div(d.crackLarge)).add(m),!0):bm(dt.mul(d.crackFine.div(d.crackLarge)).add(m),d.seed.add(7),d.fineCoverage),Ze=As(d.crackWidth.mul(d.crackFine).mul(.35),.001),ht=yi(1).sub(mh(Ze,Ze.mul(2.5),Ft.w)),Yt=vx(yi(1),yi(1).sub(mh(.03,.25,ft.w)),d.fineNearLarge),Tr=mh(.24,.68,Bo(_e.mul(38).add(m),2).mul(.5).add(.5)),Gi=it.mul(Tr).add(ht.mul(d.crackFineAmount).mul(Yt)),na=mh(.85,.35,t.sample(_e).r),lu=CF(bde(ft.xyz,P)).mul(.6).add(.4);V.addAssign(Gi.mul(Rt).mul(G).mul(na).mul(lu).mul(Tde(ct.mul(be).div(As(d.attDist,.01)).negate())))});let tt=qm(V.div(Oe),0,1);return $n(tt.mul(d.crackBright),yi(1).sub(tt.mul(d.crackDark).mul(.15)),0,0)})(),$=Kl(()=>{let V=$n(0,1,0,0).toVar();return fh(c.cracks.greaterThan(.5),()=>{V.assign(Be)}),V})(),U=As(be.mul(d.thicknessScale),.001),J=(V,Oe)=>e2(s,V,Ae,d.inclusionScale,Oe),q=Hm==="photographic"?bF(s,Ie,Ae,E,be,d.inclusionScale,d.inclusionAmount).mul(c.scatter):yi(0),se=qm(Xe.mul(d.frostDiffuse).add(at.mul(d.smudgeWhite)).add(q.mul(.65)),0,.65),pe=Hm==="photographic"?J(Ie,yi(0)).mul(c.frost):yi(0);y.roughnessNode=qm(ae.add(pe.mul(.22)),.015,.8),y.iorNode=d.ior,y.dispersionNode=d.dispersion.mul(c.dispersion),y.thicknessNode=U,y.attenuationDistanceNode=As(d.attDist,.01),y.attenuationColorNode=vx(ei(1),d.attColor,c.absorption),y.colorNode=d.baseColor,y.clearcoatNode=d.clearcoat.mul(c.clearcoat),y.clearcoatRoughnessNode=d.clearcoatRough,y.specularIntensityNode=d.specularIntensity.mul(c.reflections);let Te=$.x.add(W.mul(.3)).mul(d.keyIntensity).mul(.3),we=se.mul(d.interiorScatter).mul(c.scatter);if(y.emissiveNode=d.keyColor.mul(Te.add(we.mul(.3))),qa.matcap){let V=yx(AF(j)),Oe=V.xy.mul(.495).add(.5),tt=ae.mul(ae).mul(.06),Je=_e=>yde(o,qm(_e,.002,.998)).rgb,ct=Je(Oe).mul(.4).add(Je(Oe.add(gx(tt,0))).mul(.15)).add(Je(Oe.sub(gx(tt,0))).mul(.15)).add(Je(Oe.add(gx(0,tt))).mul(.15)).add(Je(Oe.sub(gx(0,tt))).mul(.15)).mul(d.envStrength);y.outputNode=Kl(()=>{z.lessThan(0).discard();let _e=As(se,yi(1).sub(c.transmission)),nt=d.baseColor.mul(ct.mul(.5).add(ei(.2)).mul(d.keyIntensity));return $n(vx(ct.mul($.y),nt,_e).add(d.keyColor.mul(Te)).add(d.keyColor.mul(q.mul(d.backlight).mul(.8))),1)})()}else if(Hm==="physical")y.transmissionNode=c.transmission.mul(yi(1).sub(se)),y.outputNode=Kl(()=>(z.lessThan(0).discard(),$n(t2.rgb.mul($.y),t2.a)))();else{let V=qa.fast?zhe({ray:E,normal:j,environment:i,u:d,f:c,roughness:ae,path:be}):Qhe({shape:e,erosion:t,p:Ie,ray:E,normal:j,environment:i,backdrop:a,u:d,f:c,roughness:ae});y.transmission=0,y.transmissionNode=null,y.outputNode=Kl(()=>{z.lessThan(0).discard();let Oe=V.reflected.add(V.transmitted.mul($.y)),tt=As(se,yi(1).sub(c.transmission)),Je=Oe.mul(yi(1).sub(tt)).add(t2.rgb.mul(tt)),ct=d.keyColor.mul(q.mul(d.backlight).mul(.8));return $n(Je.add(ct).add(d.keyColor.mul(Te)),1)})()}function ie(V,Oe,tt,Je){if(le.version!==S){S=le.version;let _e=le.ice,nt=le.erosion,dt=le.shape,ft=le.healing;for(let it of Object.keys(c))c[it].value=Number(_e.features?.[it]??Qd[it]);d.baseColor.value.set(_e.baseColor??"#ffffff"),d.envStrength.value=_e.envIntensity,d.backlight.value=_e.backlight??.4,d.inclusionAmount.value=_e.inclusionAmount??.3,d.inclusionScale.value=_e.inclusionScale??.4,d.ior.value=_e.ior,d.dispersion.value=_e.dispersion,d.thicknessScale.value=_e.thicknessScale,d.attDist.value=_e.attenuationDistance,d.attColor.value.set(_e.attenuationColor),d.baseRough.value=_e.baseRoughness,d.frostScale.value=_e.frost.scale,d.frostThreshold.value=_e.frost.threshold,d.frostSoftness.value=_e.frost.softness,d.frostRough.value=_e.frost.roughness,d.frostDiffuse.value=_e.frost.diffuse,d.crystalBump.value=_e.frost.crystalBump,d.crystalScale.value=_e.frost.crystalScale;let Fe=_e.cracks;d.crackLarge.value=Fe.largeScale,d.crackWarp.value=Fe.warp,d.crackCoverage.value=Fe.coverage,d.regionScale.value=Fe.regionScale,d.regionCoverage.value=Fe.regionCoverage,d.veinScale.value=Fe.veinScale,d.veinContrast.value=Fe.veinContrast,d.crackFine.value=Fe.fineScale,d.crackFineAmount.value=Fe.fineAmount,d.fineCoverage.value=Fe.fineCoverage,d.fineNearLarge.value=Fe.fineNearLarge,d.crackWidth.value=Fe.width,d.crackBright.value=Fe.brightness,d.crackDark.value=Fe.darkness,d.crackRefr.value=Fe.refraction,d.surfaceCrack.value=Fe.surfaceStrength,d.crackSteps.value=Fe.steps,d.adaptiveSteps.value=le.performance.adaptiveSteps?1:0,d.smudgeAmount.value=_e.smudges.amount,d.smudgeCoverage.value=_e.smudges.coverage,d.smudgeMaskScale.value=_e.smudges.maskScale,d.smudgeAniso.value=_e.smudges.anisotropy,d.smudgeRough.value=_e.smudges.roughness,d.smudgeWhite.value=_e.smudges.whiteness,d.smudgeScale.value=_e.smudges.scale,d.microBump.value=_e.bumps.microBump,d.microScale.value=_e.bumps.microScale,d.microCoverage.value=_e.bumps.microCoverage,d.rippleBump.value=_e.bumps.rippleBump,d.rippleScale.value=_e.bumps.rippleScale,d.bumpMaskScale.value=_e.bumps.maskScale,d.clearcoat.value=_e.clearcoat,d.clearcoatRough.value=_e.clearcoatRoughness,d.specularIntensity.value=_e.specularIntensity,d.interiorScatter.value=_e.interiorScatter,d.deformAmp.value=dt.deformAmplitude,d.deformFreq.value=dt.deformFrequency,d.edgeWidth.value=nt.edgeWidth,d.cutThreshold.value=nt.cutThreshold,d.cutSoft.value=nt.cutSoftness,d.edgeInset.value=nt.edgeInset,d.interiorSteps.value=nt.interiorSteps,d.interiorFrost.value=nt.interiorFrost,d.crumbleGlow.value=_e.crumbleGlow,d.edgeWhite.value=_e.edgeWhiteness,d.edgeBump.value=nt.edgeBump,d.edgeBumpScale.value=nt.edgeBumpScale,d.refrostStrength.value=ft.refrostStrength,d.powderTone.value.set(le.powder.baseTone),d.keyIntensity.value=le.lighting.key.intensity,d.keyColor.value.set(le.lighting.key.color)}b.copy(tt.position).sub(tt.target.position).normalize(),Je.getWorldQuaternion(v).invert(),d.lightDir.value.copy(b.applyQuaternion(v)),d.model.value.copy(Je.matrixWorld),d.modelInv.value.copy(Je.matrixWorld).invert();let ct=i2>=0?i2:++Sde;d.jitter.value.set(ct*.7548776662%1,ct*.5698402909%1)}return{material:y,uniforms:d,features:c,update:ie}}var wde=typeof window<"u"&&window.__frostAssetBase||"assets/",a2=e=>wde+e,Mde=a2("shards-atlas.png"),Ym=4,Nde=[[.8035,.94],[.94,.8055],[.7254,.94],[.94,.8764],[.94,.9233],[.7478,.94],[.94,.8079],[.6781,.94],[.94,.8965],[.94,.8612],[.7025,.94],[.8094,.94],[.94,.903],[.8238,.94],[.94,.7249],[.8374,.94]],{Fn:Zm,instancedArray:n2,instanceIndex:Ade,uint:Is,int:IF,float:Jm,ivec3:gh,vec3:FF,vec4:LF,If:Qm,Loop:Cde,atomicStore:Rde,atomicLoad:Ede,atomicMin:Pde,clamp:kF,floor:Bde,length:DF,dot:Ide,select:Fde,texture3D:Lde,textureStore:kde}=Jr,Km=32,OF=e=>4*e/Km,bx=4294967295,Dde=class{constructor(e,t,r,i){this.erosion=e;let s=Km,a=s**3,n=Ade,o=e.bound,l=(T,w)=>gh(T.mod(Is(w)),T.div(Is(w)).mod(Is(w)),T.div(Is(w*w))),u=T=>Is(T.x).add(Is(T.y).mul(Is(s))).add(Is(T.z).mul(Is(s*s))),h=T=>kF(gh(Bde(T.div(2*o).add(.5).mul(s))),gh(0),gh(s-1)),d=T=>FF(T).add(.5).div(s).sub(.5).mul(2*o),c=Zm(()=>{Rde(this.seeds.element(n),Is(bx))})().compute(a,[64]),m=Zm(()=>{let T=r.meta.element(n).x;Qm(T.greaterThan(.5).and(T.lessThan(2.5)),()=>{Pde(this.seeds.element(u(h(r.rest.element(n).xyz))),Is(n))})})().compute(t,[64]),g=Zm(()=>{this.owners[0].element(n).assign(Ede(this.seeds.element(n)))})().compute(a,[64]);this.prepareNodes=[c,m,g];let y=0;for(let T of[16,8,4,2,1,1]){let w=this.owners[y],N=this.owners[1-y];this.prepareNodes.push(Zm(()=>{let C=l(n,s).toVar(),R=d(C).toVar(),E=Is(bx).toVar(),P=Jm(1e30).toVar(),I={start:IF(-1),end:IF(1),condition:"<="};Cde(I,I,I,({i:O,j:L,k:X})=>{let z=kF(C.add(gh(O,L,X).mul(T)),gh(0),gh(s-1)),H=w.element(u(z)).toVar();Qm(H.notEqual(Is(bx)),()=>{let ue=r.rest.element(H).xyz.sub(R),ne=Ide(ue,ue).toVar();Qm(ne.lessThan(P).or(ne.equal(P).and(H.lessThan(E))),()=>{E.assign(H),P.assign(ne)})})}),N.element(n).assign(E)})().compute(a,[64])),y=1-y}let b=this.owners[y],v=e.res,S=Lde(e.tex);this.updateNode=Zm(()=>{let T=l(n,v).toVar(),w=FF(T).add(.5).div(v).sub(.5).mul(2*o).toVar(),N=b.element(u(h(w))).toVar(),C=S.load(T).level(0).toVar().r.toVar();Qm(N.notEqual(Is(bx)),()=>{let R=r.rest.element(N).xyz.toVar(),E=i.model.mul(LF(R,1)).xyz,P=DF(r.pos.element(N).xyz.sub(E)),I=r.meta.element(N).x,O=DF(w.sub(R)),L=i.landRadius.add(Jm(OF(o)).div(Jm(1).add(O.div(2*o/s)))),X=I.greaterThan(1.5).and(I.lessThan(2.5)).or(I.greaterThan(4.5)).or(I.lessThan(.5));Qm(X.and(P.lessThanEqual(L)),()=>{C.assign(0)})}),kde(e.scratch,T,LF(C,0,Fde(C.lessThan(.5),Jm(1),Jm(0)),0)).toWriteOnly()})().compute(v**3,[64])}seeds=n2(Km**3,"uint").toAtomic();owners=[n2(Km**3,"uint"),n2(Km**3,"uint")];prepareNodes;updateNode;prepare(e){for(let t of this.prepareNodes)e.compute(t)}update(e){e.compute(this.updateNode),this.erosion.commitAssembly(e)}dispose(){for(let e of[this.seeds,...this.owners])e.value.dispose?.()}},{refract:Ode,log:Ude,output:o2,attribute:zde,positionView:Vde,reflect:Gde,vec2:UF,Fn:Go,vec3:vr,vec4:xi,float:De,uniform:Se,instancedArray:Mc,storage:ef,instanceIndex:Tx,If:Nt,Loop:Sx,int:yh,uint:vt,uvec3:Wde,ivec3:br,atomicAdd:Nc,atomicSub:jde,atomicLoad:Hde,atomicStore:zF,max:Xt,min:Wo,abs:Ac,dot:xh,length:Bi,normalize:Fs,exp:vh,mix:ti,smoothstep:jo,clamp:Ls,select:qt,floor:bh,fract:rye,sin:tf,cos:l2,sqrt:VF,texture3D:u2,textureStore:Xde,positionLocal:h2,normalLocal:$de,transformNormalToView:GF,varying:eu,cameraPosition:qde,screenUV:_x,mat3:Cc,mat4:iye,pow:Th,Break:sye,Continue:aye,cross:rf,step:WF,negate:nye,uv:Yde,texture:Zde,uniformArray:Jde,cameraViewMatrix:Qde}=Jr,d2=null;function Kde(){if(!d2){let e=new tb().load(Mde);e.flipY=!1,e.colorSpace=Fa,e.wrapS=e.wrapT=Ti,e.minFilter=Ia,e.magFilter=lr,e.generateMipmaps=!0,e.anisotropy=4,d2=e}return d2}var Ho=0,ece=1,jF=2,tce=3,rce=4,HF=5,ice=class{constructor(e){this.o=e;let{count:t,strays:r,rand:i,shape:s}=e;this.total=t+r;let a=this.total,n=le.powder,o=rI(s,t,n.nearSurfaceFraction,n.nearSurfaceDepth,i),l=new Float32Array(a*4),u=new Float32Array(a*4),h=new Float32Array(a*4),d=new Float32Array(a*4),c=new Float32Array(a*4),m=[n.grainSizes.tinyDustRatio,n.grainSizes.smallGrainRatio,n.grainSizes.mediumClumpRatio,.01],g=m.reduce((R,E)=>R+E,0),y=[m[0]/g,(m[0]+m[1])/g,(m[0]+m[1]+m[2])/g],b=Math.cbrt(8*s.bound**3/Math.max(100,e.clumpCount)),v=Math.ceil(s.bound/b)+1,S=v*2+1,T=new Map;for(let R=0;R.2&&(H=2);let ue=Math.floor(I/b)+v,ne=Math.floor(O/b)+v,re=Math.floor(L/b)+v,ce=ue+ne*S+re*S*S,ge=T.get(ce);ge===void 0&&(ge=R,T.set(ce,R)),h[P]=I,h[P+1]=O,h[P+2]=L,h[P+3]=.35+i()*.4,l[P]=I,l[P+1]=O,l[P+2]=L,d[P]=Ho,d[P+1]=i(),d[P+2]=H,d[P+3]=ge}for(let R=0;Rn.atomics.element(vt(u).add(vt(I))),b=I=>n.atomics.element(I),v=I=>n.atomics.element(vt(h).add(I)),S=I=>qt(I.lessThan(.5),a.dustScale,qt(I.lessThan(1.5),a.grainScale,qt(I.lessThan(2.5),a.clumpScale,a.fragmentScale))),T=I=>qt(I.lessThan(.5),vt(1),qt(I.lessThan(1.5),vt(2),qt(I.lessThan(2.5),vt(5),vt(12))));this.nodes.snapshotLeaders=Go(()=>{n.leaders.element(l).assign(xi(n.pos.element(l).xyz,n.meta.element(l).x))})().compute(s,[64]);let w=I=>{let O=Ls(I,0,1);return qt(O.lessThan(.5),Th(2,O.mul(20).sub(10)).div(2),De(2).sub(Th(2,O.mul(-20).add(10))).div(2))};this.nodes.resetCounters=Go(()=>{Sx(8,({i:I})=>{zF(y(I),vt(0))})})().compute(1,[1]);let N=this.o.turbulence==="fast"?I=>rf(Na(I),Na(I.add(vr(31.7,11.3,57.9)))).mul(1.6):I=>sse(I),C=I=>I.div(Xt(Bi(I),1e-6)),R=(I,O)=>Go(()=>{let L=I,X=n.pos.element(L),z=n.vel.element(L),H=n.rest.element(L),ue=n.meta.element(L),ne=n.heal.element(L),re=ue.x.toVar(),ce=ue.y.toVar(),ge=ue.z.toVar(),ye=ue.w.toVar(),oe=X.xyz.toVar(),Ae=X.w.toVar(),Ie=z.xyz.toVar(),Xe=z.w.toVar(),at=H.xyz.toVar(),W=H.w.toVar(),j=ea(ce,1).toVar(),G=ea(ce,2).toVar(),ae=ea(ce,3).toVar(),be=S(ge).mul(De(1).sub(a.sizeJitter.mul(.5)).add(a.sizeJitter.mul(j))).mul(a.sizeMul).toVar(),Be=a.model.mul(xi(at,1)).xyz.toVar(),$=C(a.normalMat.mul(G1(t,at,.004))).toVar(),U=a.model.mul(xi(0,0,0,1)).xyz.toVar(),J=r.sample(at).toVar(),q=J.r.toVar(),se=J.a.greaterThan(.01),pe=N_(ce.mul(211.7).add(5)).lessThan(a.amount),Te=ne.w.greaterThan(.5),we=()=>{let _e=br(bh(r.uvw(at).mul(De(m)))),nt=g.load(Ls(_e,br(0),br(m-1))).level(0).w;return vt(Ls(nt.mul(65535),0,65535))},ie=()=>{Nc(n.atomics.element(vt(c).add(we())),vt(1))},V=_e=>{let nt=we().toVar(),dt=jde(n.atomics.element(vt(c).add(nt)),vt(1)).toVar();Nt(_e.and(dt.lessThanEqual(vt(1).add(vt(a.stragglers)))),()=>{Nc(n.atomics.element(vt(d).add(nt)),vt(1))})},Oe=()=>{let _e=at.add(this.o.erosion.bound).div(this.o.erosion.bound*2).mul(De(m)),nt=br(bh(_e)).toVar(),dt=a.depositRadius.toVar(),ft=yh(dt.ceil()).toVar(),Fe={start:ft.negate(),end:ft,condition:"<="};Sx(Fe,Fe,Fe,({i:it,j:Rt,k:Ft})=>{let Ze=nt.add(br(it,Rt,Ft)),ht=De(it.mul(it).add(Rt.mul(Rt)).add(Ft.mul(Ft))).lessThanEqual(dt.mul(dt).add(.01));Nt(ht.and(Ze.x.greaterThanEqual(0)).and(Ze.y.greaterThanEqual(0)).and(Ze.z.greaterThanEqual(0)).and(Ze.x.lessThan(m)).and(Ze.y.lessThan(m)).and(Ze.z.lessThan(m)),()=>{let Yt=vt(Ze.x).add(vt(Ze.y).mul(vt(m))).add(vt(Ze.z).mul(vt(m*m)));Nc(v(Yt),vt(1))})})},tt=()=>{let _e=Bi(oe.sub(Be)),nt=Ls(_e.div(a.waveReach),0,1).mul(a.waveTime),dt=r.u.reconstruct.greaterThan(.5).and(a.groupNoise.greaterThan(.5)),ft=qt(dt,ae.mul(a.waveJitter).mul(.04),ae.mul(a.waveJitter)),Fe=nt.add(ft),it=a.groupNoise.greaterThan(1.5),Rt=De(0).toVar();return Nt(r.u.reconstruct.greaterThan(.5).and(a.groupStagger.greaterThan(0).or(it)),()=>{let Ft=qt(a.returnMode.greaterThan(.5),mse(_e,Bi(Ie),a),a.returnDuration.add(.2)),Ze=Xt(0,a.assemblyEnd.sub(a.time).sub(Fe).sub(Ft));Rt.assign(Wo(qt(it,a.frontDuration,a.groupStagger),Ze).mul(qt(a.rigEnabled.greaterThan(.5),C_(at,a),Xt(0,W.sub(2)))))}),a.time.add(nt).add(ft).add(Rt)},Je=()=>a.time.add(j.mul(a.waveTime)).add(ae.mul(a.waveJitter)),ct=()=>{let _e=Be,nt=$,dt=n.meta.element(vt(ye)).y,ft=De(1).sub(a.clumpJitter.mul(.5)).add(a.clumpJitter.mul(N_(dt.mul(77.7)))),Fe=qt(N_(dt.mul(31.3).add(1)).lessThan(a.backwardRatio),De(-1),De(1)),it=Xt(a.strokeSpeed,a.minEject),Rt=a.strokeDir.mul(Fe),Ft=N(_e.mul(a.turbScale).add(a.time.mul(.2))),Ze=Rt.mul(it.mul(a.ejectSpeed).mul(ft)).add(nt.mul(a.ejectSpread).mul(De(.5).add(G)).mul(it.mul(.4))).add(Ft.mul(a.ejectTurb).mul(it.mul(.25)).mul(ae.add(.5))),ht=qt(ge.greaterThan(2.5),De(.35),De(1));Ie.assign(Ze.mul(ht)),oe.assign(_e.add(nt.mul(.002))),Xe.assign(0),Ae.assign(be),re.assign(ece),ne.w.assign(0),ie()};Nt(re.lessThan(.5),()=>{Nt(a.fieldActive.greaterThan(.5),()=>{Nt(q.greaterThan(W),()=>{Nt(pe,()=>{ct()}).Else(()=>{re.assign(rce),ne.w.assign(0)})})})}).ElseIf(re.lessThan(1.5),()=>{Xe.addAssign(a.dt);let _e=jo(a.settleTime.mul(.45),a.settleTime,Xe),nt=N(oe.mul(a.turbScale).add(a.time.mul(.15))).mul(a.turbulence).mul(vh(Xe.mul(a.turbDecay).negate())),dt=n.leaders.element(vt(ye)),ft=dt.w,Fe=qt(ft.greaterThan(.5).and(ft.lessThan(1.5)),dt.xyz.sub(oe).mul(a.cohesion).mul(De(1).sub(_e)),vr(0)),it=vr(0).toVar();Nt(a.repel.greaterThan(.5),()=>{let Ze=a.modelInv.mul(xi(oe,1)).xyz.toVar(),ht=t.sdfNode(Ze).toVar();Nt(ht.lessThan(a.repelRange),()=>{let Gi=gi(De(1).sub(ht.div(a.repelRange))),na=C(a.normalMat.mul(G1(t,Ze,.004)));it.assign(na.mul(a.repelStrength).mul(Gi.mul(Gi)))});let Yt=oe.sub(U),Tr=Bi(Yt).div(a.bound.mul(a.repelRadialRange));Nt(Tr.lessThan(1),()=>{let Gi=De(1).sub(Tr.mul(Tr)),na=C(Yt.add(vr(j.sub(.5),G.sub(.5),ae.sub(.5)).mul(.05)));it.addAssign(na.mul(a.repelRadial).mul(Gi.mul(Gi)))})}),Ie.addAssign(nt.add(Fe).add(it).add(vr(0,a.gravity.negate(),0)).mul(a.dt)),Ie.mulAssign(vh(a.drag.mul(a.dt).negate())),Ie.mulAssign(De(1).sub(_e.mul(Wo(1,a.dt.mul(3))))),oe.addAssign(Ie.mul(a.dt)),oe.addAssign(N(oe.mul(.9).add(a.time.mul(.05))).mul(a.settledDrift).mul(_e).mul(a.dt)),Nt(a.inherit.greaterThan(.5).and(Xe.lessThan(a.inheritTime)),()=>{let Ze=De(1).sub(jo(a.inheritTime.mul(.75),Xt(a.inheritTime,.001),Xe));oe.assign(ti(oe,a.modelDelta.mul(xi(oe,1)).xyz,Ze)),Ie.assign(ti(Ie,Cc(a.modelDelta).mul(Ie),Ze))});let Rt=Bi(Ie);Nt(Rt.greaterThan(a.maxSpeed),()=>{Ie.mulAssign(a.maxSpeed.div(Rt))});let Ft=a.returnAfter.greaterThan(.001).and(Xe.greaterThan(a.returnAfter));Nt(a.heal.greaterThan(.5).or(Ft),()=>{Nt(Te.not(),()=>{ne.w.assign(tt())}),Nt(ne.w.greaterThan(.5).and(a.time.greaterThanEqual(ne.w)),()=>{re.assign(jF),ne.xyz.assign(oe),ne.w.assign(a.time)})}).Else(()=>{ne.w.assign(0)})}).ElseIf(re.lessThan(2.5),()=>{let _e=ne.w.lessThan(-.5),nt=qt(_e,Xe,ne.w).toVar();Nt(_e.not(),()=>{Xe.addAssign(a.dt)});let dt=ne.xyz,ft=Be,Fe=$;Nt(a.returnMode.greaterThan(.5),()=>{let it=a.time.sub(nt),Rt=jo(0,Xt(a.springRamp,.001),it),Ft=a.inherit.mul(De(1).sub(Rt)).mul(De(1).sub(jo(a.inheritTime.mul(.75),Xt(a.inheritTime,.001),Xe)));oe.assign(ti(oe,a.modelDelta.mul(xi(oe,1)).xyz,Ft)),Ie.assign(ti(Ie,Cc(a.modelDelta).mul(Ie),Ft));let Ze=ft.sub(oe),ht=Bi(Ze).toVar(),Yt=qt(r.u.reconstruct.greaterThan(.5).and(a.groupNoise.greaterThan(1.5)),De(1),De(0)),Tr=ti(De(1),ti(De(.55),De(1.8),j),a.speedVariation.mul(Yt)),Gi=a.springK.mul(a.rigStrength).mul(Tr.mul(Tr)).mul(Rt),na=VF(a.springK.mul(a.rigStrength)).mul(Tr).mul(2).mul(a.springDamp).mul(Rt),lu=Bi(ft.sub(dt)),uu=Ls(ht.div(Xt(lu,.05)),0,1),Ch=De(1).sub(jo(.5,2.4,it.mul(Tr))),Fc=C(rf(Fe,vr(G,ae,j).sub(.5)).add(.001)),Lc=rf(Fe,Fc),Rh=it.mul(a.pathSwirl).mul(G.mul(2).sub(1)).add(ae.mul(6.283185)),kc=Fc.mul(l2(Rh)).add(Lc.mul(tf(Rh))).add(Fe.mul(G.sub(.5))).mul(Wo(lu,3)).mul(a.pathBend).mul(.5).mul(uu.mul(.3).add(tf(uu.mul(Math.PI)).mul(.7))).mul(Ch).mul(Yt),xf=a.previousModel.mul(xi(at,1)).xyz,Eh=ft.sub(xf).div(Xt(a.dt,1e-5)),Ph=Ze.add(kc).mul(Gi).sub(Ie.sub(Eh).mul(na)).add(vr(0,a.gravity.negate().mul(De(1).sub(Rt)),0));Ie.addAssign(Ph.mul(a.dt)),Ie.mulAssign(vh(a.drag.mul(a.returnDrag).mul(a.dt).negate()));let Dc=Bi(Ie),Oc=a.returnMaxSpeed.mul(Tr);Nt(Dc.greaterThan(Oc),()=>{Ie.mulAssign(Oc.div(Dc))});let Uc=Ie.mul(a.dt),vf=Bi(Uc);oe.addAssign(qt(vf.greaterThan(ht),Ze,Uc)),Ae.assign(be.mul(qt(a.landShrink.greaterThan(.001),gi(ht.div(Xt(a.landShrink,.001))),De(1))).mul(qt(_e,jo(0,.25,it),De(1))));let bf=ht.lessThan(a.landRadius);Nt(bf,()=>{Nt(_e.not(),()=>{V(se.not().and(r.u.reconstruct.lessThan(.5))),Nt(se.not().and(r.u.reconstruct.lessThan(.5)),()=>{Oe()})}),re.assign(qt(_e,De(Ho),De(HF))),oe.assign(ft),Ie.assign(vr(0)),ne.w.assign(0),Ae.assign(qt(_e.or(r.u.reconstruct.greaterThan(.5)),De(0),be))})}).Else(()=>{let it=Ls(a.time.sub(nt).div(Xt(a.returnDuration,.05)),0,1).toVar(),Rt=Ls(a.time.sub(a.dt).sub(nt).div(Xt(a.returnDuration,.05)),0,1),Ft=w(it),Ze=ti(dt,ft,.5).add(Fe.mul(a.returnCurve).mul(Bi(ft.sub(dt))).mul(.5)).add(vr(G,ae,j).sub(.5).mul(a.returnCurve).mul(.4)),ht=ti(dt,Ze,Ft),Yt=ti(Ze,ft,Ft);oe.assign(ti(ht,Yt,Ft));let Tr=qt(_e,jo(De(1).sub(a.ghostFrac),De(1).sub(a.ghostFrac).add(.08),it),De(1));Ae.assign(be.mul(De(1).sub(jo(.82,1,it))).mul(Tr)),Nt(Rt.lessThan(.85).and(it.greaterThanEqual(.85)).and(_e.not()),()=>{V(se.not().and(r.u.reconstruct.lessThan(.5))),Nt(se.not().and(r.u.reconstruct.lessThan(.5)),()=>{Oe()})}),Nt(it.greaterThanEqual(1),()=>{re.assign(qt(_e,De(Ho),De(HF))),oe.assign(ft),ne.w.assign(0)})}),Nt(r.u.reconstruct.greaterThan(.5).and(_e.not()),()=>{let it=qt(a.groupNoise.greaterThan(1.5),a.landingVariation,De(0)),Rt=De(OF(r.bound)).mul(ti(De(1),ti(De(.35),De(1.65),G),it)),Ft=jo(a.landRadius,Xt(a.landRadius.add(.001),Rt),Bi(ft.sub(oe)));Ae.assign(be.mul(Th(Ft,ti(De(1),ti(De(.45),De(2.2),ae),it)))),Nt(re.greaterThan(4.5),()=>{H.w.assign(2)})})}).ElseIf(re.lessThan(3.5),()=>{let _e=a.time.mul(a.straySpeed).mul(De(.5).add(j)).add(ce.mul(6.2831)),nt=Bi(at.xy),dt=at.z.add(tf(a.time.mul(.3).add(ce.mul(12))).mul(.05)),ft=vr(l2(_e).mul(nt),tf(_e).mul(nt),dt);oe.assign(a.model.mul(xi(ft,1)).xyz),Ae.assign(S(ge).mul(.9).mul(a.sizeMul)),Xe.assign(Xe.add(a.dt))}).ElseIf(re.lessThan(4.5),()=>{Nt(a.heal.greaterThan(.5),()=>{Nt(Te.not(),()=>{ne.w.assign(Je().add(a.returnDuration.mul(De(1).sub(a.ghostFrac))))}),Nt(ne.w.greaterThan(.5).and(a.time.greaterThanEqual(ne.w)),()=>{Nt(a.ghostDist.greaterThan(.001),()=>{let _e=$,nt=C(rf(_e,vr(j.sub(.5),G.sub(.5),ae.sub(.5)).add(.001))),dt=Be.add(_e.mul(a.ghostDist).mul(De(.4).add(j.mul(.6)))).add(nt.mul(a.ghostDist).mul(G.sub(.5)).mul(.8));ne.xyz.assign(dt),ne.w.assign(-1),oe.assign(dt),Xe.assign(a.time.sub(a.returnDuration.mul(De(1).sub(a.ghostFrac)))),Ae.assign(0),re.assign(jF)}).Else(()=>{re.assign(Ho),ne.w.assign(0)})})}).Else(()=>{ne.w.assign(0)})}).Else(()=>{oe.assign(Be),Nt(r.u.reconstruct.greaterThan(.5),()=>{re.assign(Ho),ne.w.assign(0),Ae.assign(0)}).ElseIf(q.lessThan(W),()=>{Nt(ne.w.lessThan(.5),()=>{ne.w.assign(a.time)});let _e=gi(a.time.sub(ne.w).div(Xt(a.landedFade,.01)));Ae.assign(be.mul(De(1).sub(_e))),Nt(_e.greaterThanEqual(1),()=>{re.assign(Ho),ne.w.assign(0),Ae.assign(0)})}).Else(()=>{Ae.assign(be),ne.w.assign(0),Nt(se.and(a.fieldActive.greaterThan(.5)),()=>{ct()})})}),Nt(re.greaterThan(.5).and(re.lessThan(2.5)),()=>{let _e=Ac(oe.x).lessThan(1e30).and(Ac(oe.y).lessThan(1e30)).and(Ac(oe.z).lessThan(1e30)).and(Ac(Ie.x).lessThan(1e30)).and(Ac(Ie.y).lessThan(1e30)).and(Ac(Ie.z).lessThan(1e30)),nt=Bi(oe.sub(U)).greaterThan(a.lostRadius);Nt(_e.not().or(nt),()=>{oe.assign(Be.add($.mul(.05))),Ie.assign(vr(0))})}),X.xyz.assign(oe),X.w.assign(Ae),z.xyz.assign(Ie),z.w.assign(Xe),ue.x.assign(re),Nt(re.greaterThan(.5).and(re.lessThan(3.5)).or(re.greaterThan(4.5)),()=>{let _e=vt(bh(ce.mul(1e3))).mod(vt(i));Nc(y(_e),vt(1));let nt=oe.add(a.densityExtent).div(a.densityExtent.mul(2)).mul(De(o)),dt=br(bh(nt));Nt(dt.x.greaterThanEqual(0).and(dt.y.greaterThanEqual(0)).and(dt.z.greaterThanEqual(0)).and(dt.x.lessThan(o)).and(dt.y.lessThan(o)).and(dt.z.lessThan(o)),()=>{let ft=vt(dt.x).add(vt(dt.y).mul(vt(o))).add(vt(dt.z).mul(vt(o*o)));Nc(b(ft),T(ge))})})})().compute(O,[64]);this.nodes.update=R(Tx,s),this.nodes.updateStrays=this.o.strays>0?R(Tx.add(vt(e)),this.o.strays):null;let E=()=>Wde(l.mod(vt(o)),l.div(vt(o)).mod(vt(o)),l.div(vt(o*o))),P=I=>{let O=Ls(br(I),br(0),br(o-1)),L=vt(O.x).add(vt(O.y).mul(vt(o))).add(vt(O.z).mul(vt(o*o)));return De(Hde(b(L))).mul(a.densityScale)};this.nodes.resolve=Go(()=>{let I=E(),O=P(br(I)).toVar(),L=De(1).sub(vh(O.negate())),X=a.lightDir.mul(De(o)).div(a.densityExtent.mul(2)).toVar(),z=De(0).toVar(),H=vr(I).add(.5).toVar();Sx(6,()=>{H.addAssign(X.mul(.9)),z.addAssign(P(br(bh(H))))});let ue=vh(z.mul(.9).negate()),ne=P(br(I).add(br(1,0,0))).add(P(br(I).add(br(-1,0,0)))).add(P(br(I).add(br(0,1,0)))).add(P(br(I).add(br(0,-1,0)))).add(P(br(I).add(br(0,0,1)))).add(P(br(I).add(br(0,0,-1)))),re=De(1).sub(vh(ne.div(6).add(O).mul(1.2).negate()));Xde(this.densityTex,I,xi(L,ue,re,1)).toWriteOnly()})().compute(o*o*o,[64]),this.nodes.clearDensity=Go(()=>{zF(b(l),vt(0))})().compute(o*o*o,[64]),this.nodes.retargetCount=Go(()=>{let I=n.meta.element(l),O=n.rest.element(l),L=n.pos.element(l),X=I.x.toVar();Nt(X.greaterThan(4.5),()=>{I.x.assign(Ho),L.w.assign(0),n.heal.element(l).assign(xi(0)),X.assign(Ho)}),Nt(X.greaterThan(.5).and(X.lessThan(2.5)),()=>{Nt(r.u.reconstruct.greaterThan(.5).and(a.groupStagger.greaterThan(0).or(a.groupNoise.greaterThan(1.5))),()=>{O.w.assign(De(2).add(qt(a.groupNoise.greaterThan(1.5),C_(O.xyz,a),pse(O.xyz,a.groupScale,a.groupSeed,a.groupNoise))))});let z=br(bh(r.uvw(O.xyz).mul(De(m)))),H=g.load(Ls(z,br(0),br(m-1))).level(0).w;Nc(n.atomics.element(vt(c).add(vt(Ls(H.mul(65535),0,65535)))),vt(1))}).ElseIf(X.lessThan(.5).or(X.greaterThan(3.5).and(X.lessThan(4.5))),()=>{O.w.assign(2)})})().compute(s,[64]),this.nodes.reset=Go(()=>{let I=n.meta.element(l),O=n.vel.element(l),L=n.pos.element(l),X=n.rest.element(l);Nt(I.x.lessThan(2.5).or(I.x.greaterThan(3.5)),()=>{I.x.assign(Ho),O.assign(xi(0)),L.assign(xi(X.xyz,0)),n.heal.element(l).assign(xi(0))})})().compute(s,[64])}buildMeshes(){let{variants:e,rand:t}=this.o,r=this.total,i=this.u,s=this.buffers,a=le.powder.sprites,n=!!a.enabled,o=n?Array.from({length:e},()=>new Kv(2,2)):One(e,t,le.powder.facetedGrains),l=n?Kde():null,u=n?Jde(Nde.map(b=>new fe(b[0],b[1]))):null,h=ef(s.pos.value,"vec4",r).toReadOnly(),d=ef(s.vel.value,"vec4",r).toReadOnly(),c=ef(s.meta.value,"vec4",r).toReadOnly(),m=ef(s.rest.value,"vec4",r).toReadOnly(),g=ef(s.heal.value,"vec4",r).toReadOnly(),y=u2(this.densityTex);for(let b=0;bJy(Jy(vi,vr(0,0,1),L),lu,Gi),Ch=uu(vr(Yt,0,0)),Fc=uu(vr(0,0,1)),Lc=m.element(T),Rh=i.model.mul(xi(Lc.xyz,1)).xyz,kc=i.normalMat.mul(G1(this.o.shape,Lc.xyz,.004)),xf=kc.div(Xt(Bi(kc),1e-6)),Eh=Fs(Cc(Qde).mul(xf).add(vr(0,0,1e-4))),Ph=qt(Eh.z.lessThan(0),Eh.negate(),Eh),Dc=P.greaterThan(1.5).and(P.lessThan(2.5)),Oc=P.greaterThan(4.5),Uc=Bi(Rh.sub(w.xyz)),vf=g.element(T),bf=Xt(Bi(Rh.sub(vf.xyz)),.05),Y2=gi(De(1).sub(Uc.div(bf))),Wx=qt(Oc,De(1),qt(Dc,Th(Y2,i.alignCurve),De(0))).mul(i.alignAmt),Z2=Fs(Ch.sub(Ph.mul(xh(Ch,Ph))).add(vr(1e-4,0,0))),zc=Fs(ti(Fc,Ph,Wx)),jx=Fs(ti(Ch,Z2,Wx)),Tf=Fs(jx.sub(zc.mul(xh(jx,zc)))),Hx=rf(zc,Tf).mul(Yt.mul(Tr)),J2=Tf.mul(h2.x.mul(ht.x).mul(Yt)).add(Hx.mul(h2.y.mul(ht.y).mul(Tr))).mul(H).mul(i.spriteSize);S.positionNode=w.xyz.add(Cc(i.camWorld).mul(J2));let Xx=eu(Tf),$x=eu(Hx),hu=eu(zc),Bh=eu(xi(De(Ze),Yt,Tr,R)),Q2=Bh.x,K2=Bh.y,eM=Bh.z;ge=Bh.w;let Vc=Yde(),tM=ti(Vc.x,De(1).sub(Vc.x),WF(K2,0)),du=ti(Vc.y,De(1).sub(Vc.y),WF(eM,0)),Sf=yh(Q2.add(.5)),rM=De(Sf.mod(yh(Ym))),iM=De(Sf.div(yh(Ym))),qx=u.element(Sf),sM=UF(rM.add(.5).add(tM.sub(.5).mul(qx.x)),iM.add(.5).add(du.sub(.5).mul(qx.y))).div(Ym),_f=Zde(l,sM),Gc=_f.rg.mul(2).sub(1).mul(i.spriteNormal),aM=VF(gi(De(1).sub(xh(Gc,Gc))));$=Fs(Xx.mul(Gc.x).add($x.mul(Gc.y)).add(hu.mul(aM)));let wf=G.nSurface.sub(at);if($=Fs($.add(Xx.mul(wf.x)).add($x.mul(wf.y)).add(hu.mul(wf.z))),S.normalNode=$,S.maskNode=_f.a.greaterThan(i.spriteCut),J=Ls(ae.mul(ye.frostDiffuse).add(G.smudge.mul(ye.smudgeWhite)).add(be.mul(.65)),0,.65),q=gi(_f.a.sub(.35).div(.65)),a.seeThrough>0){S.transparent=!0,S.depthWrite=!1;let vi=Th(gi(De(1).sub(gi(xh($,Be)))),i.fresnelPower),nM=ti(De(.42),De(.85),J).add(vi.mul(.45)).add(De(1).sub(q).mul(.18));S.opacityNode=ti(De(1),gi(nM),i.spriteSee.mul(oe.transmission).mul(oe.shardTransmission))}U=gi(xh($,i.lightDirView).add(i.wrap).div(De(1).add(i.wrap)))}else{ge=eu(R);let Ze=Jy(h2.mul(H),O,L);S.positionNode=w.xyz.add(Ze);let ht=Jy($de,O,L);S.normalNode=GF(ht),$=Fs(GF(ht)),U=gi(xh(Fs(ht),i.lightDir).add(i.wrap).div(De(1).add(i.wrap)))}n||(J=Ls(ae.mul(ye.frostDiffuse).add(G.smudge.mul(ye.smudgeWhite)).add(be.mul(.65)),0,.65));let se=Th(ye.ior.sub(1).div(ye.ior.add(1)),2),pe=se.add(De(1).sub(se).mul(Th(gi(De(1).sub(gi(xh($,Be)))),5))),Te=Hm==="photographic"?e2(this.o.fractureDetail,W,at,ye.inclusionScale).mul(Ae.frost):De(0),we=Ls(G.roughness.add(Te.mul(.22)),.015,.8);S.roughnessNode=we,S.iorNode=ye.ior,S.clearcoatNode=ye.clearcoat.mul(oe.clearcoat).mul(oe.shardReflections),S.clearcoatRoughnessNode=ye.clearcoatRough,S.specularIntensityNode=ye.specularIntensity.mul(oe.reflections).mul(oe.shardReflections);let ie=oe.reflections.mul(oe.shardReflections),V=oe.transmission.mul(oe.shardTransmission),Oe=Ze=>Fs(Cc(i.camWorld).mul(Ze)),tt=Ze=>$w(this.o.environment,ye.envStrength,Ze,we),Je=Be.negate(),ct=Ode(Je,$,De(1).div(Xt(ye.ior,1.001))),_e=Xt(Xe.w.mul(q).mul(ye.thicknessScale),.001),nt=vh(Ude(Xt(ye.attColor,vr(.001))).mul(_e.div(Xt(ye.attDist,.01))).mul(oe.absorption)),dt=Ls(_x.add(ct.xy.sub(Je.xy).mul(_e).mul(.08)),0,1),ft=z1(this.o.backdrop,dt).add(tt(Oe(ct)).mul(ye.backlight)).mul(nt),Fe=tt(Oe(Gde(Je,$))).mul(pe).mul(ie).mul(ye.specularIntensity),it=Xt(J,De(1).sub(V)),Rt=ye.keyColor.mul(G.surfCrack.mul(ye.crackBright).mul(.3).add(be.mul(ye.backlight).mul(.8))).mul(oe.scatter);S.colorNode=ye.baseColor,S.emissiveNode=ye.keyColor.mul(it.mul(ye.interiorScatter).mul(.3)).mul(oe.scatter),S.outputNode=Go(()=>{let Ze=Fe.add(ft.mul(De(1).sub(pe.mul(ie)))).mul(De(1).sub(it)).add(o2.rgb.mul(it)).add(Rt),ht=Xt(o2.a,.001),Yt=z1(this.o.backdrop,_x);return xi(Xt(Ze.sub(Yt.mul(De(1).sub(ht))),vr(0)).div(ht),o2.a)})();let Ft=new Mi(v,S);Ft.frustumCulled=!1,Ft.castShadow=!0,Ft.receiveShadow=!0,this.meshes.push(Ft),this.group.add(Ft),b===0&&(this.material=S)}}hazeNode(e,t,r){let i=this.u,s=u2(this.densityTex);return Go(()=>{let a=_x.mul(2).sub(1),n=UF(a.x,a.y.negate()),o=i.invProj.mul(xi(n.x,n.y,1,1)),l=o.xyz.div(o.w),u=Fs(l),h=Fs(Cc(i.camWorld).mul(u)),d=i.camPos,c=i.densityExtent,m=vr(1).div(h),g=c.negate().sub(d).mul(m),y=c.sub(d).mul(m),b=Xt(Xt(Wo(g.x,y.x),Wo(g.y,y.y)),Wo(g.z,y.z)),v=Wo(Wo(Xt(g.x,y.x),Xt(g.y,y.y)),Xt(g.z,y.z)),S=De(1).div(Xt(u.z.negate(),1e-4)),T=t.negate().mul(S),w=Wo(v,T),N=De(0).toVar();Nt(w.greaterThan(Xt(b,0)).and(i.hazeOn.greaterThan(.5)),()=>{let R=Xt(b,0),E=Xt(i.hazeSteps,4),P=w.sub(R).div(E),I=Po(vr(_x.mul(1234),i.time)).mul(P),O=R.add(I).toVar();Sx({start:yh(0),end:yh(E),type:"int",condition:"<"},()=>{let L=d.add(h.mul(O)).add(c).div(c.mul(2)),X=s.sample(L).level(0);N.addAssign(X.r.mul(X.g).mul(P)),O.addAssign(P)})});let C=i.tone.mul(i.keyColor).mul(i.keyIntensity).mul(N).mul(.35);return xi(C,0)})()}step(e,t,r,i,s,a){let n=le.powder,o=le.healing,l=this.u;l.fieldActive.value=a.fieldActive?1:0,l.hazeOn.value=a.powderActive?1:0,l.dt.value=Math.min(r,1/30),l.time.value=t;let u=this.o.objectGroup.matrixWorld;if(l.model.value.copy(u),l.previousModel.value.copy(this.prevModel),l.normalMat.value.getNormalMatrix(u),l.modelDelta.value.copy(u).multiply(this.inversePrevModel.copy(this.prevModel).invert()),this.prevModel.copy(u),l.strokeDir.value.copy(i.strokeDir),l.strokeSpeed.value=i.strokeSpeed,l.heal.value=pt.healing?1:0,l.fade.value=pt.fade,l.lightDir.value.copy(s.position).sub(s.target.position).normalize(),l.modelInv.value.copy(u).invert(),le.version!==this.settingsVersion){this.settingsVersion=le.version,l.ejectSpeed.value=n.ejectSpeed,l.ejectSpread.value=n.ejectSpread,l.ejectTurb.value=n.ejectTurbulence,l.backwardRatio.value=n.backwardRatio,l.clumpJitter.value=n.clumpSpeedJitter,l.drag.value=n.drag,l.gravity.value=n.gravity,l.turbulence.value=n.turbulence,l.turbScale.value=n.turbulenceScale,l.turbDecay.value=n.turbulenceDecay,l.cohesion.value=n.clumpCohesion,l.settleTime.value=n.settleTime,l.settledDrift.value=n.settledDrift,l.tumble.value=n.tumble,l.returnDuration.value=o.returnDuration,l.returnCurve.value=o.returnCurve,l.inherit.value=n.inheritRotation?1:0,l.inheritTime.value=n.inheritTime/1e3,l.straySpeed.value=n.straySpeed,l.dustScale.value=n.grainSizes.tinyDustSize,l.grainScale.value=n.grainSizes.smallGrainSize,l.clumpScale.value=n.grainSizes.mediumClumpSize,l.fragmentScale.value=n.grainSizes.largeFragmentSize,l.sizeJitter.value=n.grainSizes.sizeJitter,l.sizeMul.value=n.grainSizeMultiplier,l.amount.value=n.amount,l.minEject.value=n.minEjectSpeed,l.minPixel.value=n.minPixelSize,l.waveTime.value=o.waveTime,l.waveJitter.value=o.waveJitter,l.ghostDist.value=o.ghostReturnDistance,l.ghostFrac.value=o.ghostFlightFraction,l.waveReach.value=o.waveReach,l.depositRadius.value=o.depositRadius,l.returnMode.value=o.returnMode==="spring"?1:0,l.springK.value=o.returnSpring,l.springDamp.value=o.returnDamping,l.springRamp.value=o.returnRamp,l.landRadius.value=o.landRadius,l.returnAfter.value=o.returnAfter,l.maxSpeed.value=n.maxSpeed,l.returnDrag.value=o.returnDrag,l.returnMaxSpeed.value=o.returnMaxSpeed,l.lostRadius.value=n.lostRadius,l.stragglers.value=o.cellStragglers,l.spriteSee.value=n.sprites.seeThrough,l.alignAmt.value=o.alignToSurface,l.alignDist.value=o.alignDistance,l.alignCurve.value=o.alignCurve??1,l.landedFade.value=o.landedFade,l.landShrink.value=o.landShrink,l.densityExtent.value=n.densityExtent,l.shadowStrength.value=n.densityShadowStrength,l.aoStrength.value=n.densityAOStrength,l.densityScale.value=.02*(this.o.densityRes/64)**3*(1e6/this.total)**.5,l.tone.value.set(n.baseTone),l.wrap.value=n.wrap,l.keyIntensity.value=le.lighting.key.intensity,l.keyColor.value.set(le.lighting.key.color);let h=n.fragments;l.translucency.value=h.translucency,l.throughTint.value.set(h.throughTint),l.fresnelPower.value=h.fresnelPower,l.fragRough.value=h.roughness,l.fragClearcoat.value=h.clearcoat,l.fragSpecular.value=h.specular,l.sparkle.value=h.sparkle,l.sparkleFraction.value=h.sparkleFraction,l.sparkleSpread.value=h.sparkleSpread;let d=n.sprites;l.spriteSize.value=d.sizeScale,l.spriteTilt.value=Bt.degToRad(d.tilt),l.spriteNormal.value=d.normalStrength,l.spriteFrost.value=d.frostFromAtlas,l.spriteFrostBoost.value=d.frostBoost,l.spriteFrostRough.value=d.frostRoughness,l.spriteEdge.value=d.edgeLight,l.spriteCut.value=d.alphaCut;let c=le.ice.features;if(l.surfaceFrost.value=Number(c.shardFrost&&c.frost),l.surfaceDetail.value=Number(c.shardFrost&&c.scatter),c.shardNormals||(l.spriteNormal.value=0),c.shardFrost||(l.spriteFrost.value=0,l.spriteFrostBoost.value=0),c.shardTransmission||(l.translucency.value=0,l.spriteSee.value=0),c.shardReflections||(l.fragSpecular.value=0,l.fragClearcoat.value=0),c.shardSparkle||(l.sparkle.value=0),c.shardEdges||(l.spriteEdge.value=0),l.repel.value=n.repelFromObject?1:0,l.repelStrength.value=n.repelStrength,l.repelRange.value=n.repelRange,l.repelRadial.value=n.repelRadial,l.repelRadialRange.value=n.repelRadialRange,l.colorByState.value=le.debug.colorByState?1:0,l.colorBySize.value=le.debug.colorBySize?1:0,l.colorByAge.value=le.debug.colorByAge?1:0,l.hazeSteps.value=n.hazeSteps,n.fragmentShadowMap!==this.fragmentShadowMap){this.fragmentShadowMap=n.fragmentShadowMap;for(let m of this.meshes)m.castShadow=n.fragmentShadowMap}}if(this.beforeIntegrate?.(),!(r<=0)&&(e.compute(this.nodes.resetCounters),a.powderActive||a.fieldActive||!this.nodes.updateStrays?(e.compute(this.nodes.snapshotLeaders),e.compute(this.nodes.update),e.compute(this.nodes.resolve),e.compute(this.nodes.clearDensity),this.densityDirty=!0):(e.compute(this.nodes.updateStrays),this.densityDirty&&(e.compute(this.nodes.resolve),e.compute(this.nodes.clearDensity),this.densityDirty=!1)),this.beforeAssembly?.(),this.assemblyEnabled&&this.o.erosion.u.reconstruct.value>.5&&a.fieldActive&&this.assembly?.update(e),this.statsTimer+=r,this.statsTimer>.5&&(le.debug.stats||le.performance.idleSkip))){this.statsTimer=0;let h=this.o.countersOffset;e.getArrayBufferAsync(this.buffers.atomics.value,null,h*4,64).then(d=>{let c=new Uint32Array(d),m=0;for(let g=0;g{})}}updateCamera(e,t){this.u.pixelWorld.value=2*Math.tan(Bt.degToRad(e.fov/2))/Math.max(1,t),this.u.lightDirView.value.copy(this.u.lightDir.value).transformDirection(e.matrixWorldInverse),this.u.camPos.value.copy(e.position),this.u.invProj.value.copy(e.projectionMatrixInverse),this.u.camWorld.value.copy(e.matrixWorld)}reset(e){e.compute(this.nodes.reset)}syncModel(){this.prevModel.copy(this.o.objectGroup.matrixWorld)}retarget(e,t){let r=this.buffers.rest.value;r.array.set(t),this.upload(e,r),this.u.groupNoise.value=Number(le.healing.returnNoiseAmount??2),this.u.frontDuration.value=Number(le.healing.assemblyFrontDuration??Bs.assemblyFrontDuration),this.u.frontX.value=Number(le.healing.assemblyOriginX??Bs.assemblyOriginX),this.u.frontY.value=Number(le.healing.assemblyOriginY??Bs.assemblyOriginY),this.u.frontAngle.value=Number(le.healing.assemblyAngle??Bs.assemblyAngle),this.u.frontSpread.value=Number(le.healing.assemblySpread??Bs.assemblySpread),this.u.frontNoise.value=Number(le.healing.assemblyFrontNoise??Bs.assemblyFrontNoise),this.u.speedVariation.value=Number(le.healing.assemblySpeedVariation??Bs.assemblySpeedVariation),this.u.pathBend.value=Number(le.healing.assemblyBend??Bs.assemblyBend),this.u.pathSwirl.value=Number(le.healing.assemblySwirl??Bs.assemblySwirl),this.u.landingVariation.value=Number(le.healing.assemblyLandingVariation??Bs.assemblyLandingVariation),this.u.groupStagger.value=le.healing.returnGroupStagger??Bs.returnGroupStagger,this.u.groupScale.value=le.healing.returnGroupScale??Bs.returnGroupScale,this.u.groupSeed.value=le.healing.returnGroupSeed??Bs.returnGroupSeed,e.compute(this.nodes.retargetCount),this.o.erosion.u.reconstruct.value>.5&&this.assembly?.prepare(e)}prepareAssembly(e){this.assembly?.prepare(e)}restoreThresholds(e){let t=this.buffers.rest.value,r=t.array;for(let i=3;inew Wt);strokeCount=0;strokeVel=new F;strokeDir=new F(1,.4,0).normalize();strokeSpeed=0;hitEntry=new F;hitExit=new F;hasHit=!1;prevEntry=new F;prevExit=new F;prevEntryWorld=new F;prevHit=!1;prevX=0;prevY=0;scripted=[];scrollP=-1;scrollPath={from:new F(-1,-.6,0),to:new F(1,.6,0)};ray=new ld;inv=new We;tmp=new F;objectRayOrigin=new F;objectRayDirection=new F;workA=new F;workB=new F;workDirection=new F;velocity=new F;rayHit={entry:new F,exit:new F,tEntry:0,tExit:0};resetDone=!0;sweep(e={}){let t=this.shape.bound,r=e.from??[-1,-.55,0],i=e.to??[1,.55,0];this.scripted.push({kind:"sweep",from:new F(r[0]*t,r[1]*t,r[2]*t),to:new F(i[0]*t,i[1]*t,i[2]*t),t0:-1,delay:e.delay??0,duration:e.duration??.7,radius:e.radius??le.erosion.brushRadius,strength:e.strength??le.erosion.brushStrength*1.5,through:e.through??!0,prevT:0})}front(e){let t=this.shape.bound,[r,i]=e.from,[s,a]=e.to,n=s-r,o=a-i,l=Math.hypot(n,o)||1,u=n/l*.5,h=o/l*.5;this.scripted.push({kind:"front",from:new F((r-u)*t,(i-h)*t,0),to:new F((s+u)*t,(a+h)*t,0),normal:new F(-o/l,n/l,0),reach:(e.reach??1.3)*t,t0:-1,delay:e.delay??0,duration:e.duration??1.5,radius:e.radius??le.erosion.brushRadius,strength:e.strength??le.erosion.brushStrength*1.5,through:!0,prevT:0})}clearScripted(){this.scripted.length=0}burst(e,t,r,i=.18){let s=new We().copy(this.objectGroup.matrixWorld).invert(),a=e.clone().applyMatrix4(s);this.scripted.push({from:a,to:a.clone(),t0:-1,delay:0,duration:i,radius:t,strength:r,through:!1,prevT:0});let n=new F().setFromMatrixPosition(this.objectGroup.matrixWorld),o=e.clone().sub(n);o.lengthSq()<1e-6&&o.set(0,1,0),this.strokeDir.copy(o.normalize()),this.strokeSpeed=le.erosion.brushSpeedRef*1.5}sweepTo(e){this.scrollP=Math.max(0,Math.min(1,e))}pushScripted(e,t){if(this.scripted.length===0)return!1;let r=!1;for(let i of this.scripted){if(i.t0<0&&(i.t0=e+i.delay),e1-(1-y)*(1-y),h=i.reach*u(i.prevT),d=i.reach*u(s),c=Math.max(i.radius,(d-h)*1.5),m=this.shape.thickness,g=m<=c*.9?[0]:[-m,0,m];if(this.strokeCount+g.length*2>Tc)break;for(let y of[1,-1]){let b=this.workA.copy(i.from).addScaledVector(i.normal,y*d),v=this.workB.copy(i.to).addScaledVector(i.normal,y*d);for(let S of g)this.strokeSegments[this.strokeCount*2].set(b.x,b.y,S,c),this.strokeSegments[this.strokeCount*2+1].set(v.x,v.y,S,i.strength),this.strokeCount++}this.strokeSpeed=Math.max(this.strokeSpeed,i.reach/i.duration*.6),i.prevT=s,r=!0;continue}let n=this.workA.copy(i.from).lerp(i.to,i.prevT),o=this.workB.copy(i.from).lerp(i.to,s),l=i.through?3:1;if(this.strokeCount+l>Tc)break;for(let u=0;u1e-6){let u=this.workDirection.copy(i.to).sub(i.from).transformDirection(this.objectGroup.matrixWorld);this.strokeDir.copy(u.normalize()),this.strokeSpeed=Math.max(this.strokeSpeed,i.from.distanceTo(i.to)/i.duration*.6)}i.prevT=s,r=!0}return this.scripted=this.scripted.filter(i=>i.prevT<1),r}pushScroll(e){if(this.scrollP<0)return!1;let t=this.scrollP;if(this.prevScrollP<0)return this.prevScrollP=t,!1;let r=t-this.prevScrollP;if(Math.abs(r)<5e-4)return!1;let i=this.shape.bound,s=this.workA.copy(this.scrollPath.from).lerp(this.scrollPath.to,this.prevScrollP).multiplyScalar(i),a=this.workB.copy(this.scrollPath.from).lerp(this.scrollPath.to,t).multiplyScalar(i);if(r>0){for(let o=0;o<3&&this.strokeCount1e-8&&this.strokeDir.copy(n.normalize()),this.strokeSpeed=Math.max(this.strokeSpeed,Math.min(6,Math.abs(r)*2*i/Math.max(e,1/120)))}return this.prevScrollP=t,r>0}prevScrollP=-1;update(e,t){this.strokeCount=0;let r=le.erosion;if(pt.resetRequestedAt>=0){let n=(e-pt.resetRequestedAt)/Math.max(.05,le.healing.resetFade/1e3);pt.fade=Math.max(0,1-n),n>=1&&(this.erosion&&this.erosion.clear(this.erosion.renderer),this.powder&&this.erosion&&this.powder.reset(this.erosion.renderer),this.onReset?.(),pt.resetRequestedAt=-1,pt.lastStrokeT=-1e9,pt.fade=1)}else pt.fade=Oo(pt.fade,1,.15,t);let i=Ui.x!==this.prevX||Ui.y!==this.prevY,s=null;if(Ui.inside){this.tmp.set(Ui.x,Ui.y,.5).unproject(this.camera),this.ray.origin.copy(this.camera.position),this.ray.direction.copy(this.tmp).sub(this.camera.position).normalize(),this.inv.copy(this.objectGroup.matrixWorld).invert();let n=this.objectRayOrigin.copy(this.ray.origin).applyMatrix4(this.inv),o=this.objectRayDirection.copy(this.ray.direction).transformDirection(this.inv);s=kne(this.shape,n,o,60,this.rayHit)}pt.overObject=!!s,this.hasHit=!!s,s&&(this.hitEntry.copy(s.entry).applyMatrix4(this.objectGroup.matrixWorld),this.hitExit.copy(s.exit).applyMatrix4(this.objectGroup.matrixWorld));let a=!1;if(t>0&&this.pushScripted(e,t)&&(a=!0),t>0&&this.pushScroll(t)&&(a=!0),(!Ht.enabled||Ht.cursorErodes)&&s&&this.prevHit&&i&&t>0&&this.strokeCount+wx<=Tc){let n=this.hitEntry,o=this.velocity.copy(n).sub(this.prevEntryWorld).divideScalar(t),l=o.length();if(l>.02){a=!0,this.strokeVel.lerp(o,.5),this.strokeSpeed=Oo(this.strokeSpeed,Math.min(l,r.brushSpeedRef*3),.08,t),this.strokeVel.lengthSq()>1e-6&&this.strokeDir.copy(this.strokeVel).normalize();let u=Bt.clamp(l/r.brushSpeedRef,.12,2.5),h=r.brushStrength*u,d=r.brushRadius*(.72+.28*Math.min(1,u));for(let c=0;c=nce&&ta.frame0){let n=e*.25%1,o=this.shape.bound*.9,l=-o+n*2*o,u=-o*.7+n*1.4*o,h=l+.15,d=u+.1;this.strokeSegments[0].set(l,u,-o,r.brushRadius),this.strokeSegments[1].set(h,d,o,r.brushStrength),this.strokeCount=1,this.strokeDir.set(1,.7,0).normalize(),this.strokeSpeed=r.brushSpeedRef,a=!0}a||(this.strokeSpeed=Oo(this.strokeSpeed,0,1.2,t)),pt.strokeActive=a,Ht.enabled&&Ht.healSuspended&&(pt.lastStrokeT=e),s&&(this.prevEntry.copy(s.entry),this.prevExit.copy(s.exit),this.prevEntryWorld.copy(this.hitEntry)),this.prevHit=!!s,this.prevX=Ui.x,this.prevY=Ui.y,this.resetDone}},{vec3:oce,vec4:$F,uniform:lce,uv:uce,texture3D:hce,float:oye}=Jr,dce=class{constructor(e,t,r){this.camera=e;let i=(a,n)=>{let o=new Pd,l=hce(a).sample(oce(uce(),this.uSlice)).level(0);o.colorNode=n==="erosion"?$F(l.r,l.r.mul(.6).add(l.g.mul(.8)),l.r.mul(.6),1):$F(l.r.mul(2),l.g,l.b,1),o.depthTest=!1,o.depthWrite=!1,o.transparent=!1;let u=new Mi(new Kv(1,1),o);return u.renderOrder=1e3,u.frustumCulled=!1,u};this.erosionQuad=i(t.tex,"erosion"),this.densityQuad=i(r.densityTex,"density");let s=new eb(.03,12,8);this.hitEntry=new Mi(s,new Pd({color:"#ff4040"})),this.hitExit=new Mi(s,new Pd({color:"#40a0ff"})),this.group.add(this.hitEntry,this.hitExit),e.add(this.erosionQuad,this.densityQuad)}group=new pn;erosionQuad;densityQuad;hitEntry;hitExit;uSlice=lce(.5);update(e){let t=le.debug;this.uSlice.value=t.erosionSliceZ;let r=this.camera,i=3,s=2*i*Math.tan(Bt.degToRad(r.fov/2)),a=s*r.aspect,n=s*.28;this.erosionQuad.visible=t.showErosionSlice,this.erosionQuad.scale.set(n,n,1),this.erosionQuad.position.set(-a/2+n*.6,-s/2+n*.6,-i),this.densityQuad.visible=t.showDensityGrid,this.densityQuad.scale.set(n,n,1),this.densityQuad.position.set(-a/2+n*(t.showErosionSlice?1.75:.6),-s/2+n*.6,-i);let o=t.showHitPoints&&e.hasHit;this.hitEntry.visible=o,this.hitExit.visible=o,o&&(this.hitEntry.position.copy(e.hitEntry),this.hitExit.position.copy(e.hitExit))}dispose(){this.camera.remove(this.erosionQuad,this.densityQuad),this.erosionQuad.geometry.dispose(),this.densityQuad.geometry.dispose(),this.erosionQuad.material.dispose(),this.densityQuad.material.dispose()}},cce=class{ratio=0;frameMs=0;frames=0;lastAdjust=0;update(e,t,r,i,s,a,n){let o=Math.max(.5,Math.min(r||1,i)),l=Math.min(o,Math.max(.5,n));(!this.ratio||!s)&&(this.ratio=o),this.ratio=Math.min(o,Math.max(l,this.ratio));let u=Math.min(50,Math.max(1,t));if(this.frameMs=this.frames===0?u:this.frameMs+(u-this.frameMs)*.08,this.frames++,!s||this.frames<45||e-this.lastAdjust<.5)return this.ratio;let h=1e3/Math.max(30,a),d=this.ratio;if(this.frameMs>h*1.08&&this.ratio>l){let c=this.ratio*Math.sqrt(h/this.frameMs)*.98;d=Math.min(this.ratio-.05,c),d=Math.floor(d*20)/20}else this.frameMs({logoId:mce,shape:Ht.enabled&&Ht.shape?Ht.shape:le.shape.shape,seed:le.shape.seed,particleCount:le.powder.particleCount,resolution:le.erosion.resolution,densityGrid:le.powder.densityGrid,size:le.shape.size,tubeRatio:le.shape.tubeRatio,segments:le.shape.segments,variants:le.powder.grainVariants,faceted:le.powder.facetedGrains,sprites:le.powder.sprites.enabled,spriteBlend:le.powder.sprites.seeThrough>0,strays:le.powder.strayCount,clumps:le.powder.clumpCount,dispersion:!0,voronoiCells:le.performance.voronoiCells,turbulence:le.performance.turbulence}),mce=0,Xo=new Set(typeof location<"u"?[...new URLSearchParams(location.search).keys()]:[]),qF=65536,fce={"100k":1e5,"250k":25e4,"500k":5e5,"1M":1e6,"2M":2e6},gce=class{constructor(e,t,r,i,s,a){this.renderer=e,this.scene=t,this.camera=r,this.blueNoise=i,this.logo=s,this.fractureDetail=a,this.motionGroup.add(this.objectGroup),t.add(this.motionGroup,this.lights.group,r),t.backgroundNode=this.backdrop.node,t.environment=this.env.texture,this.build(),this.post=Nhe({scene:t,camera:r,renderer:e,blueNoise:i,haze:(n,o)=>this.powder.hazeNode(n,o,r),initial:le.post,initialPerformance:le.performance,initialHaze:le.powder.hazeIntensity!==0})}motionGroup=new pn;objectGroup=new pn;backdrop=Ane();env=Cne();lights=new Rne;rig=new K5;post;shape;mesh;meshEntry;glassMatcap;materialPlanes;ice;erosion;powder;interaction;debugViews;pixelRatio=0;frozenByDial=!1;statsTimer=0;buildCount=0;timersPending=!1;fieldMaybeNonZero=!0;lastActivityT=0;idleState(e){let t=this.interaction.strokeCount>0;t&&(this.fieldMaybeNonZero=!0,this.lastActivityT=e);let r=this.erosion.stats;this.fieldMaybeNonZero&&this.erosion.statsReadT>pt.lastStrokeT+.6&&r.max<.002&&r.refrost<.002&&(this.fieldMaybeNonZero=!1);let i=pt.healing&&this.fieldMaybeNonZero,s=this.fieldMaybeNonZero&&r.refrost>.002,a=!le.performance.idleSkip||t||e0||e-this.lastActivityT<1.5||pt.resetRequestedAt>=0;return pt.fieldActive=a,pt.powderActive=n,{fieldActive:a,powderActive:n}}envSig="";backdropSig="";frameTimes=new Float64Array(30);frameTimeSum=0;frameTimeCount=0;frameTimeIndex=0;lastFrameStart=0;gpuPending=!1;gpuTimerLast=-1/0;renderSize=new fe;adaptiveResolution=new cce;offscreenRT=Xo.has("offscreen")?new er(16,16,{depthBuffer:!1,type:Si,format:pi}):null;build(){this.buildCount++;let e=pce(),t=Lm(e.seed+1),r=Ht.enabled&&Ht.shape?Ht.shape:le.shape.shape,i=r==="logo"&&!this.logo?"torus":r;this.shape=cw(i,e.size,e.tubeRatio,this.logo?.sdf);let s=Dne(this.shape,e.segments,this.logo?.geometry),a=parseInt(e.densityGrid,10),n=parseInt(e.resolution,10),o=a*a*a,l=o+16,u=l+n*n*n,h=u+qF,d=Jr.instancedArray(h+qF,"uint").toAtomic();if(this.erosion=new hx(this.renderer,this.shape,n,e.seed,d,l,u,h),qa.materials&&(this.materialPlanes=new mne(this.renderer,this.shape.bound,e.seed),this.erosion.materialPlanes=this.materialPlanes),this.erosion.skipBake=Xo.has("nobake"),qa.mesh&&(this.meshEntry=vne(s,this.camera)),qa.matcap&&(this.env.update(le.lighting),this.glassMatcap=bne(this.env.texture)),this.ice=_de({meshEntry:this.meshEntry,glassMatcap:this.glassMatcap,shape:this.shape,erosion:this.erosion,seed:e.seed,blueNoise:this.blueNoise,environment:this.env.texture,fractureDetail:this.fractureDetail,backdrop:this.backdrop.uniforms,dispersion:e.dispersion,voronoiCells:e.voronoiCells}),Xo.has("noice")){let c=new pS;c.roughness=.3,c.color.set("#bbbbbb"),this.ice.material=c}this.meshEntry&&(this.meshEntry.material.positionNode=this.ice.material.positionNode),this.mesh=new Mi(s,this.ice.material),this.mesh.castShadow=!0,this.mesh.receiveShadow=!0,this.mesh.frustumCulled=!1,this.objectGroup.add(this.mesh),this.powder=new ice({enabled:!Xo.has("nopowder"),renderer:this.renderer,scene:this.scene,shape:this.shape,erosion:this.erosion,seed:e.seed,rand:t,count:fce[e.particleCount]??1e6,variants:e.variants,strays:e.strays,densityRes:a,clumpCount:e.clumps,objectGroup:this.objectGroup,turbulence:e.turbulence,atomics:d,countersOffset:o,healOffset:l,cellOffset:u,flightOffset:h,fieldRes:n,backdrop:this.backdrop.uniforms,fractureDetail:this.fractureDetail,iceUniforms:this.ice.uniforms,iceFeatures:this.ice.features,environment:this.env.texture}),this.interaction=new XF(this.shape,this.objectGroup,this.camera,this.erosion,this.powder),this.debugViews=new dce(this.camera,this.erosion,this.powder),this.scene.add(this.debugViews.group)}disposeBuilt(){this.materialPlanes?.dispose(),this.materialPlanes=void 0,this.meshEntry?.dispose(),this.meshEntry=void 0,this.glassMatcap?.dispose(),this.glassMatcap=void 0,this.debugViews.dispose(),this.scene.remove(this.debugViews.group),this.objectGroup.remove(this.mesh),this.mesh.geometry.dispose(),this.ice.material.dispose(),this.erosion.dispose(),this.powder.dispose()}rebuild(){this.disposeBuilt(),this.build(),this.post.post.needsUpdate=!0}updateEnvironment(){let e=le.lighting,t=JSON.stringify([e.envSoftbox,e.envRim,e.envFill,e.key,e.fill,e.fillColor,e.fillGroundColor,e.fillReflectionStrength,e.rimColor,e.rimElevation,e.rimAzimuth,e.rimSize,e.accentCool,e.accentWarm]);t!==this.envSig&&(this.envSig=t,this.env.update(e)),this.scene.environmentIntensity=le.ice.envIntensity}updateBackdrop(e){let t=le.lighting.backdrop,r=Ht.enabled?Ht.backdrop:null,i=this.backdrop.uniforms,s=r?.top??t.top,a=r?.mid??t.mid,n=r?.bottom??t.bottom,o=r?.centerX??t.centerX,l=r?.centerY??t.centerY,u=r?.radius??t.radius,h=r?.falloff??t.falloff,d=`${s}|${a}|${n}|${o}|${l}|${u}|${h}|${t.noise}`;d!==this.backdropSig&&(this.backdropSig=d,i.uTop.value.set(s),i.uMid.value.set(a),i.uBottom.value.set(n),i.uCenter.value.set(o,l),i.uRadius.value=u,i.uFalloff.value=h,i.uNoise.value=t.noise),i.uTime.value=e}onBeforeRender=null;onBeforeSimulation=null;onObjectTransform=null;onCameraTransform=null;frame(e,t,r=!0){ta.t=e,ta.dt=t,ta.frame++;let i=e*1e3,s=1e3/le.performance.targetFps,a=!Xo.has("nopost")&&le.performance.nativePostEffects&&le.performance.upscaler!=="native",n=this.adaptiveResolution.updateScene(e,s,window.devicePixelRatio||1,le.post.pixelRatioCap,le.performance.adaptiveResolution&&le.performance.dynamicSceneResolution,le.performance.targetFps,le.performance.minPixelRatio,le.performance.sceneResolutionScale,le.performance.minSceneResolutionScale,a);if(pt.pixelRatio=n.sourceRatio,pt.outputPixelRatio=n.outputRatio,pt.sceneResolutionScale=n.sceneScale,n.outputRatio!==this.pixelRatio||this.renderer.getPixelRatio()!==n.outputRatio){this.pixelRatio=n.outputRatio,this.renderer.setPixelRatio(n.outputRatio);let h=this.renderer.getSize(this.renderSize);this.renderer.setSize(h.x,h.y,!1)}this.onCameraTransform||this.rig.update(this.camera,this.objectGroup,e,t),Ht.enabled&&Ht.framing?this.motionGroup.position.set(Ht.objectX,Ht.objectY,Ht.objectZ):this.motionGroup.position.set(le.shape.offsetX,le.shape.offsetY,le.shape.offsetZ),this.objectGroup.position.set(0,0,0),this.onObjectTransform&&this.onObjectTransform(e),this.motionGroup.updateMatrixWorld(!0),this.onCameraTransform?.(e),this.updateEnvironment(),this.updateBackdrop(e),pt.hoverAmount=Oo(pt.hoverAmount,pt.overObject?1:0,.4/3,t),this.lights.update(e,pt.hoverAmount),this.interaction.update(e,t),this.onBeforeSimulation?.(e,t),this.debugViews.update(this.interaction),Xo.has("noice")||(this.ice.update(e,t,this.lights.key,this.objectGroup),this.ice.uniforms.hover.value=pt.hoverAmount);let o=performance.now(),l=this.idleState(e);if(t>0&&(Xo.has("noerosion")||this.erosion.step(this.renderer,e,t,this.interaction.strokeSegments,this.interaction.strokeCount,l.fieldActive)),Xo.has("nopowder")||this.powder.step(this.renderer,e,t,this.interaction,this.lights.key,l),pt.computeMs=performance.now()-o,le.debug.stats||le.performance.idleSkip){this.statsTimer+=Math.max(t,1/120);let h=this.fieldMaybeNonZero?.25:.4;(this.statsTimer>h||this.offscreenRT)&&(this.statsTimer=0,this.erosion.readStats(this.renderer,e),pt.erosion=this.erosion.stats)}this.camera.updateMatrixWorld(),this.onBeforeRender&&this.onBeforeRender(e),this.powder.updateCamera(this.camera,this.renderer.getSize(this.renderSize).y*n.sourceRatio);let u=this.camera.position.distanceTo(this.rig.lookAt);if(this.post.update(le.post,le.performance,u,pt.sceneFade,le.powder.hazeIntensity,e,le.version),this.materialPlanes?.update(),this.post.setSceneResolution(n.sceneScale),this.meshEntry?.update(this.mesh,n.sceneScale),this.mesh.material.wireframe=le.debug.wireframe,this.offscreenRT){let h=this.renderer.getSize(this.renderSize),d=this.renderer.getPixelRatio(),c=Math.max(1,Math.floor(h.x*d)),m=Math.max(1,Math.floor(h.y*d));(this.offscreenRT.width!==c||this.offscreenRT.height!==m)&&this.offscreenRT.setSize(c,m),this.renderer.setRenderTarget(this.offscreenRT)}if(this.post.setHazeResolution(le.performance.hazeResolution==="quarter"?.25:le.performance.hazeResolution==="half"?.5:1),r&&(this.renderer._nodes.nodeFrame.update(),this.post.setFrame(Math.round(e*60)),Xo.has("nopost")?this.renderer.render(this.scene,this.camera):this.post.post.render()),this.offscreenRT&&this.renderer.setRenderTarget(null),le.performance.gpuTimers&&!this.timersPending&&e-this.gpuTimerLast>=.25){let h=this.renderer;h.backend?.trackTimestamp&&(this.timersPending=!0,this.gpuTimerLast=e,Promise.all([h.resolveTimestampsAsync("render"),h.resolveTimestampsAsync("compute")]).then(()=>{pt.gpuRenderMs=h.info.render.timestamp||0,pt.gpuComputeMs=h.info.compute.timestamp||0,this.timersPending=!1}).catch(()=>{this.timersPending=!1}))}if(this.offscreenRT&&!this.gpuPending){let h=this.renderer.backend?.device?.queue;h?.onSubmittedWorkDone&&(this.gpuPending=!0,h.onSubmittedWorkDone().then(()=>{pt.gpuFrames++,this.gpuPending=!1}).catch(()=>{this.gpuPending=!1}))}}resetSim(){this.erosion.clear(this.renderer),this.erosion.crumbleUntil=-1,this.erosion.u.crumbleUntil.value=-1,this.powder.reset(this.renderer),this.interaction=new XF(this.shape,this.objectGroup,this.camera,this.erosion,this.powder),this.rig=new K5,this.mesh.visible=!0,pt.strokeActive=!1,pt.overObject=!1,pt.lastStrokeT=-1e9,pt.healing=!1,pt.resetRequestedAt=-1,pt.fade=1,pt.sceneFade=1,pt.hoverAmount=0,pt.fieldActive=!0,pt.powderActive=!0,this.fieldMaybeNonZero=!0,this.lastActivityT=0,this.statsTimer=0,ta.t=0,ta.dt=1/60,ta.frame=0,ta.paused=!1}async dumpShader(){return this.renderer.debug.getShaderAsync(this.scene,this.camera,this.mesh)}async readback(){if(!this.offscreenRT)return null;let e=this.offscreenRT,t=e.width,r=e.height,i=await this.renderer.readRenderTargetPixelsAsync(e,0,0,t,r),s=i.length>=Math.ceil(t*4/256)*256*r?Math.ceil(t*4/256)*256:t*4,a=0,n=0,o=document.createElement("canvas");o.width=t,o.height=r;let l=o.getContext("2d"),u=l.createImageData(t,r);for(let h=0;hn&&(n=g)}return l.putImageData(u,0,0),{mean:a/(t*r),max:n,png:o.toDataURL("image/png"),w:t,h:r}}dispose(){this.disposeBuilt(),this.post.dispose(),this.scene.remove(this.motionGroup,this.lights.group),this.scene.backgroundNode=null,this.scene.environment=null,this.env.texture.dispose(),this.fractureDetail?.dispose()}},Mx={ice:{ior:1.445,dispersion:.155,thicknessScale:2.41,attenuationDistance:4.47,attenuationColor:"#524c4c",baseRoughness:.5,frost:{scale:.2,threshold:1,softness:.36,roughness:0,diffuse:.56,crystalBump:.37,crystalScale:67},cracks:{largeScale:8,warp:0,warpScale:2.2,coverage:.01,regionScale:1.35,regionCoverage:0,veinScale:20,veinContrast:.57,width:.0175,brightness:.25,darkness:1,refraction:.008,surfaceStrength:0,steps:21,fineCracks:!0,fineScale:10.4,fineAmount:0,fineCoverage:.45,fineNearLarge:1},smudges:{amount:0,coverage:.29,maskScale:3.1,anisotropy:5.5,roughness:.02,whiteness:.035,scale:.5},bumps:{microBump:.32,microScale:121,microCoverage:.76,rippleBump:.45,rippleScale:2.5,maskScale:3.6},crumbleGlow:.16,edgeWhiteness:.09,clearcoat:0,clearcoatRoughness:.085,envIntensity:.28,specularIntensity:.65,interiorScatter:.05},performance:{adaptiveResolution:!0,targetFps:60,minPixelRatio:.75,sceneResolutionScale:1,dynamicSceneResolution:!0,minSceneResolutionScale:.35,upscaler:"taau",upscaleSharpness:.2,nativePostEffects:!0,idleSkip:!0,adaptiveSteps:!0,voronoiCells:"27",hazeResolution:"quarter",turbulence:"fast",gpuTimers:!0},lighting:{key:{color:"#ffffff",intensity:12,elevation:62,azimuth:-10.5,size:3,hoverBoost:.3},fill:1.5,fillColor:"#ffffff",fillGroundColor:"#07a4a6",rim:5,rimColor:"#0b82ea",rimElevation:9.5,shadow:{intensity:0,softness:6,samples:1,mapSize:"1024",bias:-6e-4},sway:{amplitude:.118,period:35},backdrop:{top:"#212121",mid:"#171717",bottom:"#030303",centerX:.19,centerY:1.5,radius:.78,falloff:4,noise:0},envSoftbox:1.22,envRim:2.43,envFill:1,rimAzimuth:-180,rimAngle:81,rimSize:2.05,fillReflectionStrength:2,accentCool:{intensity:4,reflection:3,elevation:25,azimuth:-65,size:2.85,color:"#c7ddff"},accentWarm:{intensity:3.64,reflection:3,elevation:34,azimuth:127,size:3,color:"#ff0000"}},post:{dof:{enabled:!1,focusBias:-.43,aperture:4,range:12},bloom:{threshold:.28,intensity:0,radius:.11},monochrome:0,tonemap:"aces",exposure:1.3,contrast:1.15,blackLift:0,vignette:{strength:.325,softness:1.175,radius:1.11},grain:{strength:0,size:1,speed:0,shadowWeight:.28,backgroundStrength:.035,backgroundSize:2,backgroundSpeed:0},dither:!0,aaMode:"traa",pixelRatioCap:2}},yce=()=>({version:1,name:"Untitled shot",orientation:"target",anchorSpace:"local",objectMotion:"existing",keys:[]});function c2(e){if(e==null||e==="")return yce();let t=typeof e=="string"?JSON.parse(e):e;if(t?.version!==1||!Array.isArray(t.keys)||t.keys.length>64)throw Error("Camera track must be version 1 with at most 64 keys.");let r=(o,l,u)=>{if(!l.includes(o))throw Error("Invalid "+u);return o},i=(o,l,u,h)=>{if(typeof o!="number"||!Number.isFinite(o)||ou)throw Error("Invalid "+h);return o},s=(o,l,u)=>{if(!Array.isArray(o)||o.length!==l)throw Error("Invalid "+u);return o.map(h=>i(h,-1e4,1e4,u))},a={version:1,name:String(t.name||"Untitled shot").slice(0,100),orientation:r(t.orientation,["target","free"],"orientation"),anchorSpace:r(t.anchorSpace,["world","local"],"anchor space"),objectMotion:r(t.objectMotion,["existing","stationary"],"object motion"),keys:t.keys.map(o=>{let l=s(o.quaternion,4,"quaternion");if(Math.abs(Math.hypot(...l)-1)>.001)throw Error("Camera quaternion must be normalized.");return{id:String(o.id).slice(0,100),time:i(o.time,0,120,"key time"),position:s(o.position,3,"position"),target:s(o.target,3,"target"),quaternion:l,fov:i(o.fov,5,120,"FOV"),zoom:i(o.zoom,.1,10,"zoom"),roll:i(o.roll,-720,720,"roll"),ease:r(o.ease,["flow","linear","ease-in-out"],"ease")}}).sort((o,l)=>o.time-l.time)},n=new Set;for(let o=0;o0?(t-a.time)/o:0,u=a.ease==="ease-in-out"?l*l*(3-2*l):l,h=g=>{if(!o)return g(a);if(a.ease!=="flow")return Bt.lerp(g(a),g(n),u);let y=i[Math.max(0,s-1)],b=i[Math.min(i.length-1,s+2)],v=(g(n)-g(y))/Math.max(n.time-y.time,1e-6),S=(g(b)-g(a))/Math.max(b.time-a.time,1e-6);return(2*u**3-3*u*u+1)*g(a)+(u**3-2*u*u+u)*o*v+(-2*u**3+3*u*u)*g(n)+(u**3-u*u)*o*S},d=new F(...[0,1,2].map(g=>h(y=>y.position[g]))),c=new F(...[0,1,2].map(g=>h(y=>y.target[g])));e.anchorSpace==="local"&&c.applyMatrix4(r);let m=e.orientation==="target"?new si().setFromRotationMatrix(new We().lookAt(d,c,new F(0,1,0))):new si(...a.quaternion).slerp(new si(...n.quaternion),u);return m.multiply(new si().setFromAxisAngle(new F(0,0,1),Bt.degToRad(h(g=>g.roll)))),{position:d,quaternion:m,target:c,roll:h(g=>g.roll),fov:Bt.clamp(h(g=>g.fov),5,120),zoom:Bt.clamp(h(g=>g.zoom),.1,10)}}function vce(e,t,r,i,s){let a=YF(t,r,i);return e.position.copy(a.position),e.quaternion.copy(a.quaternion),e.fov=a.fov,e.zoom=a.zoom,e.updateProjectionMatrix(),e.updateMatrixWorld(!0),s.copy(a.target),a}var bce=e=>Math.max(0,Math.min(1,e));function p2(e,t){let r=l=>(l=bce(l),l*l*l*(l*(l*6-15)+10)),i=(l,u)=>l<=u?r(l/Math.max(u,1e-6)):1-r((l-u)/Math.max(1-u,1e-6)),s=[{t0:e.logoBreak-.65,tBreakEnd:e.form1,t1:e.form1+2.8,yaw:t.turnYaw,pitch:t.turnPitch,z:t.approach,keep:!1},{t0:e.break1-.65,tBreakEnd:e.form2,t1:e.form2+2.8,yaw:t.turnYaw2,pitch:t.turnPitch2,z:-t.retreat,keep:!1},{t0:e.break2-.65,tBreakEnd:e.fadeOut+1.5,t1:e.fadeOut+1.5,yaw:t.finalYaw,pitch:t.finalPitch,z:t.approach+t.zoomIn,keep:!0}];function a(l){let u=0,h=0,d=0;for(let c of s){let m=(l-c.t0)/Math.max(c.t1-c.t0,1e-6);if(m<=0)continue;u+=c.yaw*r(m);let g=(c.tBreakEnd-c.t0)/Math.max(c.t1-c.t0,1e-6),y=c.keep?r(m):i(m,g);h+=c.pitch*y,d+=c.z*y}return{yaw:u,pitch:h,z:d}}let n=l=>t.driftYaw*l,o=l=>t.idleYaw*Math.sin(2*Math.PI*l/9);return function(l){let u=a(l),h=t.driftSway*Math.sin(2*Math.PI*l/11);return{yaw:u.yaw+n(l)+o(l),pitch:u.pitch+h,z:u.z+.0875*t.driftSway*Math.sin(2*Math.PI*l/11)}}}var Tce=(e,t)=>e{let c=a(d);return new si().setFromEuler(new cn(c.pitch*Math.PI/180,c.yaw*Math.PI/180,0,"YXZ"))},l=s?new si:o(e),u=s||i===0?new si:o((i===1?t.form1:t.form2)+2.8).invert(),h=new F(0,.05,s?0:n.z);return{rotation:l,facing:u,position:h,matrix:new We().compose(h,l.clone().multiply(u),new F(1,1,1))}}var{lerp:Sh}=Bt,us=[151,160,137,91,90,15,131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,190,6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,88,237,149,56,87,174,20,125,136,171,168,68,175,74,165,71,134,139,48,27,166,77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244,102,143,54,65,25,63,161,1,216,80,73,209,76,132,187,208,89,18,169,200,196,135,130,116,188,159,86,164,100,109,198,173,186,3,64,52,217,226,250,124,123,5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42,223,183,170,213,119,248,152,2,44,154,163,70,221,153,101,155,167,43,172,9,129,22,39,253,19,98,108,110,79,113,224,232,178,185,112,104,218,246,97,228,251,34,242,193,238,210,144,12,191,179,162,241,81,51,145,235,249,14,239,107,49,192,214,31,181,199,106,157,184,84,204,176,115,121,50,45,127,4,150,254,138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180];for(let e=0;e<256;e++)us[256+e]=us[e];function m2(e){return e*e*e*(e*(e*6-15)+10)}function tu(e,t,r,i){let s=e&15,a=s<8?t:r,n=s<4?r:s==12||s==14?t:i;return((s&1)==0?a:-a)+((s&2)==0?n:-n)}var _ce=class{noise(e,t,r){let i=Math.floor(e),s=Math.floor(t),a=Math.floor(r),n=i&255,o=s&255,l=a&255;e-=i,t-=s,r-=a;let u=e-1,h=t-1,d=r-1,c=m2(e),m=m2(t),g=m2(r),y=us[n]+o,b=us[y]+l,v=us[y+1]+l,S=us[n+1]+o,T=us[S]+l,w=us[S+1]+l;return Sh(Sh(Sh(tu(us[b],e,t,r),tu(us[T],u,t,r),c),Sh(tu(us[v],e,h,r),tu(us[w],u,h,r),c),m),Sh(Sh(tu(us[b+1],e,t,d),tu(us[T+1],u,t,d),c),Sh(tu(us[v+1],e,h,d),tu(us[w+1],u,h,d),c),m),g)}},wce=Io.textMeshDetail;function f2(e){return typeof e=="number"&&Number.isFinite(e)?Math.max(1,Math.min(4,Math.round(e))):wce}function Mce(e,t){let r=f2(t);return{maxEdge:e/(2*r),extraTriangles:16e4*r}}function Nce(e,t,r,i){let s=[],a=new Map,n=[],o=r*r,l=t.length/3+i,u=t.length/3,h=(v,S)=>vv.length2>S.length2||v.length2===S.length2&&(v.a0;){let T=S-1>>1;if(!d(v,n[T]))break;n[S]=n[T],S=T}n[S]=v}function m(){let v=n[0],S=n.pop();if(n.length){let T=0;for(;T*2+1o&&c(E)}E.faces.add(w)}}function y(v){let S=s[v];s[v]=null;for(let T=0;T<3;T++){let w=h(S[T],S[(T+1)%3]),N=a.get(w);N.faces.delete(v),N.faces.size||a.delete(w)}}for(let v=0;vl)continue;let T=e.length/3;e.push((e[v.a*3]+e[v.b*3])/2,(e[v.a*3+1]+e[v.b*3+1])/2,(e[v.a*3+2]+e[v.b*3+2])/2);let w=S.map(N=>s[N]);for(let N of S)y(N);for(let N of w){let C=N.findIndex((I,O)=>h(I,N[(O+1)%3])===h(v.a,v.b)),R=N[C],E=N[(C+1)%3],P=N[(C+2)%3];g(R,T,P),g(T,E,P)}u+=S.length}let b=[];for(let v of s)v&&b.push(v[0],v[1],v[2]);return b}function Ace(e,t){let r=[];for(let u=0;uh-d)){let h=e[u*3],d=e[u*3+1],c=e[u*3+2],m=Math.floor(h/a),g=Math.floor(d/a),y=Math.floor(c/a),b=u;for(let v=-1;v<=1;v++)for(let S=-1;S<=1;S++)for(let T=-1;T<=1;T++)for(let w of n.get(`${m+v}:${g+S}:${y+T}`)||[])Math.hypot(h-e[w*3],d-e[w*3+1],c-e[w*3+2])<=a&&(b=Math.min(b,w));if(o.set(u,b),b===u){let v=`${m}:${g}:${y}`,S=n.get(v)||[];S.push(u),n.set(v,S)}}let l=[];for(let u=0;uo.get(m)??m);h!==d&&d!==c&&c!==h&&l.push(h,d,c)}return l}var Cce=Io.logoMeshDetail;function g2(e){return typeof e=="number"&&Number.isFinite(e)?Math.max(1,Math.min(4,Math.round(e))):Cce}function Rce(e,t){e.computeBoundingBox();let r=e.boundingBox,i=Math.max(r.max.x-r.min.x,r.max.y-r.min.y,r.max.z-r.min.z,.001),s=g2(t);return{maxEdge:i/(32*s),extraTriangles:16e4*s}}var ZF=Object.freeze({strength:Io.deformStrength,scale:Io.deformScale,seed:Io.deformSeed});function JF(e){if(!Number.isFinite(e)||e<.001||e>.5)throw new RangeError(`Noise feature size ${e} is outside 0.001\u20130.5. Edit this value to load the preset; other settings have not been changed.`);return e}function Nx(e){let t=(r,i,s)=>{let a=e?.[r];return typeof a=="number"&&Number.isFinite(a)?Math.max(i,Math.min(s,a)):ZF[r]};return{strength:t("strength",0,.08),scale:JF(e?.scale??ZF.scale),seed:Math.round(t("seed",0,65535))}}function Ece(e){let{strength:t,scale:r,seed:i}=Nx(e),s=new _ce,a=Lm(i),n=Array.from({length:3},()=>[a()*256,a()*256,a()*256]);function o(l,u,h){let d=n[h],c=l/r+d[0],m=u/r+d[1],g=d[2],y=0,b=1;for(let v=0;v<3;v++)y+=b*s.noise(c,m,g),c=c*2+17.3,m=m*2+9.1,g=g*2+31.7,b*=.5;return y/1.75}return(l,u,h)=>t===0?[l,u,h]:(l+=t*o(u,h,0),u+=t*o(h,l,1),h+=t*o(l,u,2),[l,u,h])}function Pce(e,t,r){let i=t,s=t.length/3+6e3,a=r*r,n=(o,l)=>oa&&(l.set(n(y,b),-1),u++)}}if(!l.size||i.length/3+u>s)break;for(let[d]of l){let[c,m]=d.split(":").map(Number),g=e.length/3;e.push((e[c*3]+e[m*3])/2,(e[c*3+1]+e[m*3+1])/2,(e[c*3+2]+e[m*3+2])/2),l.set(d,g)}let h=[];for(let d=0;de.fadeOut+QF;function Fce(e,t){let r=.3+t+.6,i=e.logoBreak,s=Math.max(e.form1,i+r),a=Math.max(e.break1,s+2.8+.65),n=Math.max(e.form2,a+r),o=Math.max(e.break2,n+2.8+.65),l=Math.max(e.fadeOut,o+r);return{logoBreak:i,form1:s,break1:a,form2:n,break2:o,fadeOut:l}}String.prototype.codePointAt||(function(){var e=(function(){try{var r={},i=Object.defineProperty,s=i(r,r,r)&&i}catch{}return s})(),t=function(r){if(this==null)throw TypeError();var i=String(this),s=i.length,a=r?Number(r):0;if(a!=a&&(a=0),!(a<0||a>=s)){var n=i.charCodeAt(a),o;return n>=55296&&n<=56319&&s>a+1&&(o=i.charCodeAt(a+1),o>=56320&&o<=57343)?(n-55296)*1024+o-56320+65536:n}};e?e(String.prototype,"codePointAt",{value:t,configurable:!0,writable:!0}):String.prototype.codePointAt=t})();var x2=0,KF=-3;function sf(){this.table=new Uint16Array(16),this.trans=new Uint16Array(288)}function Lce(e,t){this.source=e,this.sourceIndex=0,this.tag=0,this.bitcount=0,this.dest=t,this.destLen=0,this.ltree=new sf,this.dtree=new sf}var eL=new sf,tL=new sf,v2=new Uint8Array(30),b2=new Uint16Array(30),rL=new Uint8Array(30),iL=new Uint16Array(30),kce=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),sL=new sf,qn=new Uint8Array(320);function aL(e,t,r,i){var s,a;for(s=0;s>>=1,t}function Yn(e,t,r){if(!t)return r;for(;e.bitcount<24;)e.tag|=e.source[e.sourceIndex++]<>>16-t;return e.tag>>>=t,e.bitcount-=t,i+r}function S2(e,t){for(;e.bitcount<24;)e.tag|=e.source[e.sourceIndex++]<>>=1,++s,r+=t.table[s],i-=t.table[s];while(i>=0);return e.tag=a,e.bitcount-=s,t.trans[r+i]}function Uce(e,t,r){var i,s,a,n,o,l;for(i=Yn(e,5,257),s=Yn(e,5,1),a=Yn(e,4,4),n=0;n<19;++n)qn[n]=0;for(n=0;n8;)e.sourceIndex--,e.bitcount-=8;if(t=e.source[e.sourceIndex+1],t=256*t+e.source[e.sourceIndex],r=e.source[e.sourceIndex+3],r=256*r+e.source[e.sourceIndex+2],t!==(~r&65535))return KF;for(e.sourceIndex+=4,i=t;i;--i)e.dest[e.destLen++]=e.source[e.sourceIndex++];return e.bitcount=0,x2}function Vce(e,t){var r=new Lce(e,t),i,s,a;do{switch(i=Oce(r),s=Yn(r,2,0),s){case 0:a=zce(r);break;case 1:a=oL(r,eL,tL);break;case 2:Uce(r,r.ltree,r.dtree),a=oL(r,r.ltree,r.dtree);break;default:a=KF}if(a!==x2)throw new Error("Data error")}while(!i);return r.destLenthis.x2&&(this.x2=e)),typeof t=="number"&&((isNaN(this.y1)||isNaN(this.y2))&&(this.y1=t,this.y2=t),tthis.y2&&(this.y2=t))},$o.prototype.addX=function(e){this.addPoint(e,null)},$o.prototype.addY=function(e){this.addPoint(null,e)},$o.prototype.addBezier=function(e,t,r,i,s,a,n,o){var l=[e,t],u=[r,i],h=[s,a],d=[n,o];this.addPoint(e,t),this.addPoint(n,o);for(var c=0;c<=1;c++){var m=6*l[c]-12*u[c]+6*h[c],g=-3*l[c]+9*u[c]-9*h[c]+3*d[c],y=3*u[c]-3*l[c];if(g===0){if(m===0)continue;var b=-y/m;0=0&&l>0&&(o+=" "),o+=t(u)}return o}for(var i="",s=0;s=0&&e<=255,"Byte value should be between 0 and 255."),[e]},wt.BYTE=rn(1),He.CHAR=function(e){return[e.charCodeAt(0)]},wt.CHAR=rn(1),He.CHARARRAY=function(e){typeof e>"u"&&(e="",console.warn("Undefined CHARARRAY encountered and treated as an empty string. This is probably caused by a missing glyph name."));for(var t=[],r=0;r"u"?0:e.length},He.USHORT=function(e){return[e>>8&255,e&255]},wt.USHORT=rn(2),He.SHORT=function(e){return e>=hL&&(e=-(2*hL-e)),[e>>8&255,e&255]},wt.SHORT=rn(2),He.UINT24=function(e){return[e>>16&255,e>>8&255,e&255]},wt.UINT24=rn(3),He.ULONG=function(e){return[e>>24&255,e>>16&255,e>>8&255,e&255]},wt.ULONG=rn(4),He.LONG=function(e){return e>=dL&&(e=-(2*dL-e)),[e>>24&255,e>>16&255,e>>8&255,e&255]},wt.LONG=rn(4),He.FIXED=He.ULONG,wt.FIXED=wt.ULONG,He.FWORD=He.SHORT,wt.FWORD=wt.SHORT,He.UFWORD=He.USHORT,wt.UFWORD=wt.USHORT,He.LONGDATETIME=function(e){return[0,0,0,0,e>>24&255,e>>16&255,e>>8&255,e&255]},wt.LONGDATETIME=rn(8),He.TAG=function(e){return bt.argument(e.length===4,"Tag should be exactly 4 ASCII characters."),[e.charCodeAt(0),e.charCodeAt(1),e.charCodeAt(2),e.charCodeAt(3)]},wt.TAG=rn(4),He.Card8=He.BYTE,wt.Card8=wt.BYTE,He.Card16=He.USHORT,wt.Card16=wt.USHORT,He.OffSize=He.BYTE,wt.OffSize=wt.BYTE,He.SID=He.USHORT,wt.SID=wt.USHORT,He.NUMBER=function(e){return e>=-107&&e<=107?[e+139]:e>=108&&e<=1131?(e=e-108,[(e>>8)+247,e&255]):e>=-1131&&e<=-108?(e=-e-108,[(e>>8)+251,e&255]):e>=-32768&&e<=32767?He.NUMBER16(e):He.NUMBER32(e)},wt.NUMBER=function(e){return He.NUMBER(e).length},He.NUMBER16=function(e){return[28,e>>8&255,e&255]},wt.NUMBER16=rn(3),He.NUMBER32=function(e){return[29,e>>24&255,e>>16&255,e>>8&255,e&255]},wt.NUMBER32=rn(5),He.REAL=function(e){var t=e.toString(),r=/\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(t);if(r){var i=parseFloat("1e"+((r[2]?+r[2]:0)+r[1].length));t=(Math.round(e*i)/i).toString()}for(var s="",a=0,n=t.length;a>8&255,t[t.length]=i&255}return t},wt.UTF16=function(e){return e.length*2};var _2={"x-mac-croatian":"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\u2020\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\u0160\u2122\xB4\xA8\u2260\u017D\xD8\u221E\xB1\u2264\u2265\u2206\xB5\u2202\u2211\u220F\u0161\u222B\xAA\xBA\u03A9\u017E\xF8\xBF\xA1\xAC\u221A\u0192\u2248\u0106\xAB\u010C\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u0110\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\uF8FF\xA9\u2044\u20AC\u2039\u203A\xC6\xBB\u2013\xB7\u201A\u201E\u2030\xC2\u0107\xC1\u010D\xC8\xCD\xCE\xCF\xCC\xD3\xD4\u0111\xD2\xDA\xDB\xD9\u0131\u02C6\u02DC\xAF\u03C0\xCB\u02DA\xB8\xCA\xE6\u02C7","x-mac-cyrillic":"\u0410\u0411\u0412\u0413\u0414\u0415\u0416\u0417\u0418\u0419\u041A\u041B\u041C\u041D\u041E\u041F\u0420\u0421\u0422\u0423\u0424\u0425\u0426\u0427\u0428\u0429\u042A\u042B\u042C\u042D\u042E\u042F\u2020\xB0\u0490\xA3\xA7\u2022\xB6\u0406\xAE\xA9\u2122\u0402\u0452\u2260\u0403\u0453\u221E\xB1\u2264\u2265\u0456\xB5\u0491\u0408\u0404\u0454\u0407\u0457\u0409\u0459\u040A\u045A\u0458\u0405\xAC\u221A\u0192\u2248\u2206\xAB\xBB\u2026\xA0\u040B\u045B\u040C\u045C\u0455\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u201E\u040E\u045E\u040F\u045F\u2116\u0401\u0451\u044F\u0430\u0431\u0432\u0433\u0434\u0435\u0436\u0437\u0438\u0439\u043A\u043B\u043C\u043D\u043E\u043F\u0440\u0441\u0442\u0443\u0444\u0445\u0446\u0447\u0448\u0449\u044A\u044B\u044C\u044D\u044E","x-mac-gaelic":"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\u2020\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\xB4\xA8\u2260\xC6\xD8\u1E02\xB1\u2264\u2265\u1E03\u010A\u010B\u1E0A\u1E0B\u1E1E\u1E1F\u0120\u0121\u1E40\xE6\xF8\u1E41\u1E56\u1E57\u027C\u0192\u017F\u1E60\xAB\xBB\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u2013\u2014\u201C\u201D\u2018\u2019\u1E61\u1E9B\xFF\u0178\u1E6A\u20AC\u2039\u203A\u0176\u0177\u1E6B\xB7\u1EF2\u1EF3\u204A\xC2\xCA\xC1\xCB\xC8\xCD\xCE\xCF\xCC\xD3\xD4\u2663\xD2\xDA\xDB\xD9\u0131\xDD\xFD\u0174\u0175\u1E84\u1E85\u1E80\u1E81\u1E82\u1E83","x-mac-greek":"\xC4\xB9\xB2\xC9\xB3\xD6\xDC\u0385\xE0\xE2\xE4\u0384\xA8\xE7\xE9\xE8\xEA\xEB\xA3\u2122\xEE\xEF\u2022\xBD\u2030\xF4\xF6\xA6\u20AC\xF9\xFB\xFC\u2020\u0393\u0394\u0398\u039B\u039E\u03A0\xDF\xAE\xA9\u03A3\u03AA\xA7\u2260\xB0\xB7\u0391\xB1\u2264\u2265\xA5\u0392\u0395\u0396\u0397\u0399\u039A\u039C\u03A6\u03AB\u03A8\u03A9\u03AC\u039D\xAC\u039F\u03A1\u2248\u03A4\xAB\xBB\u2026\xA0\u03A5\u03A7\u0386\u0388\u0153\u2013\u2015\u201C\u201D\u2018\u2019\xF7\u0389\u038A\u038C\u038E\u03AD\u03AE\u03AF\u03CC\u038F\u03CD\u03B1\u03B2\u03C8\u03B4\u03B5\u03C6\u03B3\u03B7\u03B9\u03BE\u03BA\u03BB\u03BC\u03BD\u03BF\u03C0\u03CE\u03C1\u03C3\u03C4\u03B8\u03C9\u03C2\u03C7\u03C5\u03B6\u03CA\u03CB\u0390\u03B0\xAD","x-mac-icelandic":"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\xDD\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\xB4\xA8\u2260\xC6\xD8\u221E\xB1\u2264\u2265\xA5\xB5\u2202\u2211\u220F\u03C0\u222B\xAA\xBA\u03A9\xE6\xF8\xBF\xA1\xAC\u221A\u0192\u2248\u2206\xAB\xBB\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\xFF\u0178\u2044\u20AC\xD0\xF0\xDE\xFE\xFD\xB7\u201A\u201E\u2030\xC2\xCA\xC1\xCB\xC8\xCD\xCE\xCF\xCC\xD3\xD4\uF8FF\xD2\xDA\xDB\xD9\u0131\u02C6\u02DC\xAF\u02D8\u02D9\u02DA\xB8\u02DD\u02DB\u02C7","x-mac-inuit":"\u1403\u1404\u1405\u1406\u140A\u140B\u1431\u1432\u1433\u1434\u1438\u1439\u1449\u144E\u144F\u1450\u1451\u1455\u1456\u1466\u146D\u146E\u146F\u1470\u1472\u1473\u1483\u148B\u148C\u148D\u148E\u1490\u1491\xB0\u14A1\u14A5\u14A6\u2022\xB6\u14A7\xAE\xA9\u2122\u14A8\u14AA\u14AB\u14BB\u14C2\u14C3\u14C4\u14C5\u14C7\u14C8\u14D0\u14EF\u14F0\u14F1\u14F2\u14F4\u14F5\u1505\u14D5\u14D6\u14D7\u14D8\u14DA\u14DB\u14EA\u1528\u1529\u152A\u152B\u152D\u2026\xA0\u152E\u153E\u1555\u1556\u1557\u2013\u2014\u201C\u201D\u2018\u2019\u1558\u1559\u155A\u155D\u1546\u1547\u1548\u1549\u154B\u154C\u1550\u157F\u1580\u1581\u1582\u1583\u1584\u1585\u158F\u1590\u1591\u1592\u1593\u1594\u1595\u1671\u1672\u1673\u1674\u1675\u1676\u1596\u15A0\u15A1\u15A2\u15A3\u15A4\u15A5\u15A6\u157C\u0141\u0142","x-mac-ce":"\xC4\u0100\u0101\xC9\u0104\xD6\xDC\xE1\u0105\u010C\xE4\u010D\u0106\u0107\xE9\u0179\u017A\u010E\xED\u010F\u0112\u0113\u0116\xF3\u0117\xF4\xF6\xF5\xFA\u011A\u011B\xFC\u2020\xB0\u0118\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\u0119\xA8\u2260\u0123\u012E\u012F\u012A\u2264\u2265\u012B\u0136\u2202\u2211\u0142\u013B\u013C\u013D\u013E\u0139\u013A\u0145\u0146\u0143\xAC\u221A\u0144\u0147\u2206\xAB\xBB\u2026\xA0\u0148\u0150\xD5\u0151\u014C\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\u014D\u0154\u0155\u0158\u2039\u203A\u0159\u0156\u0157\u0160\u201A\u201E\u0161\u015A\u015B\xC1\u0164\u0165\xCD\u017D\u017E\u016A\xD3\xD4\u016B\u016E\xDA\u016F\u0170\u0171\u0172\u0173\xDD\xFD\u0137\u017B\u0141\u017C\u0122\u02C7",macintosh:"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\u2020\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\xB4\xA8\u2260\xC6\xD8\u221E\xB1\u2264\u2265\xA5\xB5\u2202\u2211\u220F\u03C0\u222B\xAA\xBA\u03A9\xE6\xF8\xBF\xA1\xAC\u221A\u0192\u2248\u2206\xAB\xBB\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\xFF\u0178\u2044\u20AC\u2039\u203A\uFB01\uFB02\u2021\xB7\u201A\u201E\u2030\xC2\xCA\xC1\xCB\xC8\xCD\xCE\xCF\xCC\xD3\xD4\uF8FF\xD2\xDA\xDB\xD9\u0131\u02C6\u02DC\xAF\u02D8\u02D9\u02DA\xB8\u02DD\u02DB\u02C7","x-mac-romanian":"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\u2020\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\xB4\xA8\u2260\u0102\u0218\u221E\xB1\u2264\u2265\xA5\xB5\u2202\u2211\u220F\u03C0\u222B\xAA\xBA\u03A9\u0103\u0219\xBF\xA1\xAC\u221A\u0192\u2248\u2206\xAB\xBB\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\xFF\u0178\u2044\u20AC\u2039\u203A\u021A\u021B\u2021\xB7\u201A\u201E\u2030\xC2\xCA\xC1\xCB\xC8\xCD\xCE\xCF\xCC\xD3\xD4\uF8FF\xD2\xDA\xDB\xD9\u0131\u02C6\u02DC\xAF\u02D8\u02D9\u02DA\xB8\u02DD\u02DB\u02C7","x-mac-turkish":"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\u2020\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\xB4\xA8\u2260\xC6\xD8\u221E\xB1\u2264\u2265\xA5\xB5\u2202\u2211\u220F\u03C0\u222B\xAA\xBA\u03A9\xE6\xF8\xBF\xA1\xAC\u221A\u0192\u2248\u2206\xAB\xBB\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\xFF\u0178\u011E\u011F\u0130\u0131\u015E\u015F\u2021\xB7\u201A\u201E\u2030\xC2\xCA\xC1\xCB\xC8\xCD\xCE\xCF\xCC\xD3\xD4\uF8FF\xD2\xDA\xDB\xD9\uF8A0\u02C6\u02DC\xAF\u02D8\u02D9\u02DA\xB8\u02DD\u02DB\u02C7"};Ec.MACSTRING=function(e,t,r,i){var s=_2[i];if(s!==void 0){for(var a="",n=0;n=128&&(a=r[a],a===void 0))return;i[s]=a}return i}},wt.MACSTRING=function(e,t){var r=He.MACSTRING(e,t);return r!==void 0?r.length:0};function w2(e){return e>=-128&&e<=127}function jce(e,t,r){for(var i=0,s=e.length;t>8&255,l+256&255)}return a}He.VARDELTAS=function(e){for(var t=0,r=[];t=-128&&i<=127?t=Hce(e,t,r):t=Xce(e,t,r)}return r},He.INDEX=function(e){for(var t=1,r=[t],i=[],s=0;s>8,t[d+1]=c&255,t=t.concat(i[h])}return t},wt.TABLE=function(e){for(var t=0,r=e.fields.length,i=0;i0)return new ve(this.data,this.offset+t).parseStruct(e)},ve.prototype.parsePointer32=function(e){var t=this.parseOffset32();if(t>0)return new ve(this.data,this.offset+t).parseStruct(e)},ve.prototype.parseListOfLists=function(e){for(var t=this.parseOffset16List(),r=t.length,i=this.relativeOffset,s=new Array(r),a=0;a>1,t.skip("uShort",3),e.glyphIndexMap={};for(var n=new ot.Parser(r,i+s+14),o=new ot.Parser(r,i+s+16+a*2),l=new ot.Parser(r,i+s+16+a*4),u=new ot.Parser(r,i+s+16+a*6),h=i+s+16+a*8,d=0;d=0;s-=1){var a=ot.getUShort(e,t+4+s*8),n=ot.getUShort(e,t+4+s*8+2);if(a===3&&(n===0||n===1||n===10)||a===0&&(n===0||n===1||n===2||n===3||n===4)){i=ot.getULong(e,t+4+s*8+4);break}}if(i===-1)throw new Error("No valid cmap sub-tables found.");var o=new ot.Parser(e,t+i);if(r.format=o.parseUShort(),r.format===12)Kce(r,o);else if(r.format===4)epe(r,o,e,t,i);else throw new Error("Only format 4 and 12 cmap tables are supported (found format "+r.format+").");return r}function rpe(e,t,r){e.segments.push({end:t,start:t,delta:-(t-r),offset:0,glyphIndex:r})}function ipe(e){e.segments.push({end:65535,start:65535,delta:1,offset:0})}function spe(e){var t=!0,r;for(r=e.length-1;r>0;r-=1){var i=e.get(r);if(i.unicode>65535){console.log("Adding CMAP format 12 (needed!)"),t=!1;break}}var s=[{name:"version",type:"USHORT",value:0},{name:"numTables",type:"USHORT",value:t?1:2},{name:"platformID",type:"USHORT",value:3},{name:"encodingID",type:"USHORT",value:1},{name:"offset",type:"ULONG",value:t?12:20}];t||(s=s.concat([{name:"cmap12PlatformID",type:"USHORT",value:3},{name:"cmap12EncodingID",type:"USHORT",value:10},{name:"cmap12Offset",type:"ULONG",value:0}])),s=s.concat([{name:"format",type:"USHORT",value:4},{name:"cmap4Length",type:"USHORT",value:0},{name:"language",type:"USHORT",value:0},{name:"segCountX2",type:"USHORT",value:0},{name:"searchRange",type:"USHORT",value:0},{name:"entrySelector",type:"USHORT",value:0},{name:"rangeShift",type:"USHORT",value:0}]);var a=new rt.Table("cmap",s);for(a.segments=[],r=0;r>4,n=s&15;if(a===r||(t+=i[a],n===r))break;t+=i[n]}return parseFloat(t)}function xpe(e,t){var r,i,s,a;if(t===28)return r=e.parseByte(),i=e.parseByte(),r<<8|i;if(t===29)return r=e.parseByte(),i=e.parseByte(),s=e.parseByte(),a=e.parseByte(),r<<24|i<<16|s<<8|a;if(t===30)return ype(e);if(t>=32&&t<=246)return t-139;if(t>=247&&t<=250)return r=e.parseByte(),(t-247)*256+r+108;if(t>=251&&t<=254)return r=e.parseByte(),-(t-251)*256-r-108;throw new Error("Invalid b0 "+t)}function vpe(e){for(var t={},r=0;r>1,l.length=0,h=!0}function R(E){for(var P,I,O,L,X,z,H,ue,ne,re,ce,ge,ye=0;ye1&&!h&&(w=l.shift()+v,h=!0),m+=l.pop(),N(c,m);break;case 5:for(;l.length>0;)c+=l.shift(),m+=l.shift(),o.lineTo(c,m);break;case 6:for(;l.length>0&&(c+=l.shift(),o.lineTo(c,m),l.length!==0);)m+=l.shift(),o.lineTo(c,m);break;case 7:for(;l.length>0&&(m+=l.shift(),o.lineTo(c,m),l.length!==0);)c+=l.shift(),o.lineTo(c,m);break;case 8:for(;l.length>0;)i=c+l.shift(),s=m+l.shift(),a=i+l.shift(),n=s+l.shift(),c=a+l.shift(),m=n+l.shift(),o.curveTo(i,s,a,n,c,m);break;case 10:X=l.pop()+y,z=g[X],z&&R(z);break;case 11:return;case 12:switch(oe=E[ye],ye+=1,oe){case 35:i=c+l.shift(),s=m+l.shift(),a=i+l.shift(),n=s+l.shift(),H=a+l.shift(),ue=n+l.shift(),ne=H+l.shift(),re=ue+l.shift(),ce=ne+l.shift(),ge=re+l.shift(),c=ce+l.shift(),m=ge+l.shift(),l.shift(),o.curveTo(i,s,a,n,H,ue),o.curveTo(ne,re,ce,ge,c,m);break;case 34:i=c+l.shift(),s=m,a=i+l.shift(),n=s+l.shift(),H=a+l.shift(),ue=n,ne=H+l.shift(),re=n,ce=ne+l.shift(),ge=m,c=ce+l.shift(),o.curveTo(i,s,a,n,H,ue),o.curveTo(ne,re,ce,ge,c,m);break;case 36:i=c+l.shift(),s=m+l.shift(),a=i+l.shift(),n=s+l.shift(),H=a+l.shift(),ue=n,ne=H+l.shift(),re=n,ce=ne+l.shift(),ge=re+l.shift(),c=ce+l.shift(),o.curveTo(i,s,a,n,H,ue),o.curveTo(ne,re,ce,ge,c,m);break;case 37:i=c+l.shift(),s=m+l.shift(),a=i+l.shift(),n=s+l.shift(),H=a+l.shift(),ue=n+l.shift(),ne=H+l.shift(),re=ue+l.shift(),ce=ne+l.shift(),ge=re+l.shift(),Math.abs(ce-c)>Math.abs(ge-m)?c=ce+l.shift():m=ge+l.shift(),o.curveTo(i,s,a,n,H,ue),o.curveTo(ne,re,ce,ge,c,m);break;default:console.log("Glyph "+t.index+": unknown operator 1200"+oe),l.length=0}break;case 14:l.length>0&&!h&&(w=l.shift()+v,h=!0),d&&(o.closePath(),d=!1);break;case 18:C();break;case 19:case 20:C(),ye+=u+7>>3;break;case 21:l.length>2&&!h&&(w=l.shift()+v,h=!0),m+=l.pop(),c+=l.pop(),N(c,m);break;case 22:l.length>1&&!h&&(w=l.shift()+v,h=!0),c+=l.pop(),N(c,m);break;case 23:C();break;case 24:for(;l.length>2;)i=c+l.shift(),s=m+l.shift(),a=i+l.shift(),n=s+l.shift(),c=a+l.shift(),m=n+l.shift(),o.curveTo(i,s,a,n,c,m);c+=l.shift(),m+=l.shift(),o.lineTo(c,m);break;case 25:for(;l.length>6;)c+=l.shift(),m+=l.shift(),o.lineTo(c,m);i=c+l.shift(),s=m+l.shift(),a=i+l.shift(),n=s+l.shift(),c=a+l.shift(),m=n+l.shift(),o.curveTo(i,s,a,n,c,m);break;case 26:for(l.length%2&&(c+=l.shift());l.length>0;)i=c,s=m+l.shift(),a=i+l.shift(),n=s+l.shift(),c=a,m=n+l.shift(),o.curveTo(i,s,a,n,c,m);break;case 27:for(l.length%2&&(m+=l.shift());l.length>0;)i=c+l.shift(),s=m,a=i+l.shift(),n=s+l.shift(),c=a+l.shift(),m=n,o.curveTo(i,s,a,n,c,m);break;case 28:P=E[ye],I=E[ye+1],l.push((P<<24|I<<16)>>16),ye+=2;break;case 29:X=l.pop()+e.gsubrsBias,z=e.gsubrs[X],z&&R(z);break;case 30:for(;l.length>0&&(i=c,s=m+l.shift(),a=i+l.shift(),n=s+l.shift(),c=a+l.shift(),m=n+(l.length===1?l.shift():0),o.curveTo(i,s,a,n,c,m),l.length!==0);)i=c+l.shift(),s=m,a=i+l.shift(),n=s+l.shift(),m=n+l.shift(),c=a+(l.length===1?l.shift():0),o.curveTo(i,s,a,n,c,m);break;case 31:for(;l.length>0&&(i=c+l.shift(),s=m,a=i+l.shift(),n=s+l.shift(),m=n+l.shift(),c=a+(l.length===1?l.shift():0),o.curveTo(i,s,a,n,c,m),l.length!==0);)i=c,s=m+l.shift(),a=i+l.shift(),n=s+l.shift(),c=a+l.shift(),m=n+(l.length===1?l.shift():0),o.curveTo(i,s,a,n,c,m);break;default:oe<32?console.log("Glyph "+t.index+": unknown operator "+oe):oe<247?l.push(oe-139):oe<251?(P=E[ye],ye+=1,l.push((oe-247)*256+P+108)):oe<255?(P=E[ye],ye+=1,l.push(-(oe-251)*256-P-108)):(P=E[ye],I=E[ye+1],O=E[ye+2],L=E[ye+3],ye+=4,l.push((P<<24|I<<16|O<<8|L)/65536))}}}return R(r),t.advanceWidth=w,o}function wpe(e,t,r,i){var s=[],a,n=new ot.Parser(e,t),o=n.parseCard8();if(o===0)for(var l=0;l=i)throw new Error("CFF table CID Font FDSelect has bad FD index value "+a+" (FD count "+i+")");s.push(a)}else if(o===3){var u=n.parseCard16(),h=n.parseCard16();if(h!==0)throw new Error("CFF Table CID Font FDSelect format 3 range has bad initial GID "+h);for(var d,c=0;c=i)throw new Error("CFF table CID Font FDSelect has bad FD index value "+a+" (FD count "+i+")");if(d>r)throw new Error("CFF Table CID Font FDSelect format 3 range has bad GID "+d);for(;h=0&&(r=i),i=t.indexOf(e),i>=0?r=i+Lx.length:(r=Lx.length+t.length,t.push(e)),r}function Npe(){return new rt.Record("Header",[{name:"major",type:"Card8",value:1},{name:"minor",type:"Card8",value:0},{name:"hdrSize",type:"Card8",value:4},{name:"major",type:"Card8",value:1}])}function Ape(e){var t=new rt.Record("Name INDEX",[{name:"names",type:"INDEX",value:[]}]);t.names=[];for(var r=0;r=r.begin&&e=1&&(r.ulCodePageRange1=i.parseULong(),r.ulCodePageRange2=i.parseULong()),r.version>=2&&(r.sxHeight=i.parseShort(),r.sCapHeight=i.parseShort(),r.usDefaultChar=i.parseUShort(),r.usBreakChar=i.parseUShort(),r.usMaxContent=i.parseUShort()),r}function rme(e){return new rt.Table("OS/2",[{name:"version",type:"USHORT",value:3},{name:"xAvgCharWidth",type:"SHORT",value:0},{name:"usWeightClass",type:"USHORT",value:0},{name:"usWidthClass",type:"USHORT",value:0},{name:"fsType",type:"USHORT",value:0},{name:"ySubscriptXSize",type:"SHORT",value:650},{name:"ySubscriptYSize",type:"SHORT",value:699},{name:"ySubscriptXOffset",type:"SHORT",value:0},{name:"ySubscriptYOffset",type:"SHORT",value:140},{name:"ySuperscriptXSize",type:"SHORT",value:650},{name:"ySuperscriptYSize",type:"SHORT",value:699},{name:"ySuperscriptXOffset",type:"SHORT",value:0},{name:"ySuperscriptYOffset",type:"SHORT",value:479},{name:"yStrikeoutSize",type:"SHORT",value:49},{name:"yStrikeoutPosition",type:"SHORT",value:258},{name:"sFamilyClass",type:"SHORT",value:0},{name:"bFamilyType",type:"BYTE",value:0},{name:"bSerifStyle",type:"BYTE",value:0},{name:"bWeight",type:"BYTE",value:0},{name:"bProportion",type:"BYTE",value:0},{name:"bContrast",type:"BYTE",value:0},{name:"bStrokeVariation",type:"BYTE",value:0},{name:"bArmStyle",type:"BYTE",value:0},{name:"bLetterform",type:"BYTE",value:0},{name:"bMidline",type:"BYTE",value:0},{name:"bXHeight",type:"BYTE",value:0},{name:"ulUnicodeRange1",type:"ULONG",value:0},{name:"ulUnicodeRange2",type:"ULONG",value:0},{name:"ulUnicodeRange3",type:"ULONG",value:0},{name:"ulUnicodeRange4",type:"ULONG",value:0},{name:"achVendID",type:"CHARARRAY",value:"XXXX"},{name:"fsSelection",type:"USHORT",value:0},{name:"usFirstCharIndex",type:"USHORT",value:0},{name:"usLastCharIndex",type:"USHORT",value:0},{name:"sTypoAscender",type:"SHORT",value:0},{name:"sTypoDescender",type:"SHORT",value:0},{name:"sTypoLineGap",type:"SHORT",value:0},{name:"usWinAscent",type:"USHORT",value:0},{name:"usWinDescent",type:"USHORT",value:0},{name:"ulCodePageRange1",type:"ULONG",value:0},{name:"ulCodePageRange2",type:"ULONG",value:0},{name:"sxHeight",type:"SHORT",value:0},{name:"sCapHeight",type:"SHORT",value:0},{name:"usDefaultChar",type:"USHORT",value:0},{name:"usBreakChar",type:"USHORT",value:0},{name:"usMaxContext",type:"USHORT",value:0}],e)}var I2={parse:tme,make:rme,unicodeRanges:B2,getUnicodeRange:eme};function ime(e,t){var r={},i=new ot.Parser(e,t);switch(r.version=i.parseVersion(),r.italicAngle=i.parseFixed(),r.underlinePosition=i.parseShort(),r.underlineThickness=i.parseShort(),r.isFixedPitch=i.parseULong(),r.minMemType42=i.parseULong(),r.maxMemType42=i.parseULong(),r.minMemType1=i.parseULong(),r.maxMemType1=i.parseULong(),r.version){case 1:r.names=_h.slice();break;case 2:r.numberOfGlyphs=i.parseUShort(),r.glyphNameIndex=new Array(r.numberOfGlyphs);for(var s=0;s=_h.length){var n=i.parseChar();r.names.push(i.parseString(n))}break;case 2.5:r.numberOfGlyphs=i.parseUShort(),r.offset=new Array(r.numberOfGlyphs);for(var o=0;od.value.tag?1:-1}),t.fields=t.fields.concat(i),t.fields=t.fields.concat(s),t}function YL(e,t,r){for(var i=0;i0){var a=e.glyphs.get(s);return a.getMetrics()}}return r}function ume(e){for(var t=0,r=0;rb||l===void 0)&&b>0&&(l=b),u 123 are reserved for internal usage");if(y.name!==".notdef"){var S=y.getMetrics();t.push(S.xMin),r.push(S.yMin),i.push(S.xMax),s.push(S.yMax),n.push(S.leftSideBearing),o.push(S.rightSideBearing),a.push(y.advanceWidth)}}var T={xMin:Math.min.apply(null,t),yMin:Math.min.apply(null,r),xMax:Math.max.apply(null,i),yMax:Math.max.apply(null,s),advanceWidthMax:Math.max.apply(null,a),advanceWidthAvg:ume(a),minLeftSideBearing:Math.min.apply(null,n),maxLeftSideBearing:Math.max.apply(null,n),minRightSideBearing:Math.min.apply(null,o)};T.ascender=e.ascender,T.descender=e.descender;var w=PL.make({flags:3,unitsPerEm:e.unitsPerEm,xMin:T.xMin,yMin:T.yMin,xMax:T.xMax,yMax:T.yMax,lowestRecPPEM:3,createdTimestamp:e.createdTimestamp}),N=BL.make({ascender:T.ascender,descender:T.descender,advanceWidthMax:T.advanceWidthMax,minLeftSideBearing:T.minLeftSideBearing,minRightSideBearing:T.minRightSideBearing,xMaxExtent:T.maxLeftSideBearing+(T.xMax-T.xMin),numberOfHMetrics:e.glyphs.length}),C=LL.make(e.glyphs.length),R=I2.make(Object.assign({xAvgCharWidth:Math.round(T.advanceWidthAvg),usFirstCharIndex:l,usLastCharIndex:u,ulUnicodeRange1:h,ulUnicodeRange2:d,ulUnicodeRange3:c,ulUnicodeRange4:m,sTypoAscender:T.ascender,sTypoDescender:T.descender,sTypoLineGap:0,usWinAscent:T.yMax,usWinDescent:Math.abs(T.yMin),ulCodePageRange1:1,sxHeight:YL(e,"xyvw",{yMax:Math.round(T.ascender/2)}).yMax,sCapHeight:YL(e,"HIKLEFJMNTZBDPRAGOQSUVWXY",T).yMax,usDefaultChar:e.hasChar(" ")?32:0,usBreakChar:e.hasChar(" ")?32:0},e.tables.os2)),E=IL.make(e.glyphs),P=fL.make(e.glyphs),I=e.getEnglishName("fontFamily"),O=e.getEnglishName("fontSubfamily"),L=I+" "+O,X=e.getEnglishName("postScriptName");X||(X=I.replace(/\s/g,"")+"-"+O);var z={};for(var H in e.names)z[H]=e.names[H];z.uniqueID||(z.uniqueID={en:e.getEnglishName("manufacturer")+":"+L}),z.postScriptName||(z.postScriptName={en:X}),z.preferredFamily||(z.preferredFamily=e.names.fontFamily),z.preferredSubfamily||(z.preferredSubfamily=e.names.fontSubfamily);var ue=[],ne=GL.make(z,ue),re=ue.length>0?FL.make(ue):void 0,ce=WL.make(),ge=EL.make(e.glyphs,{version:e.getEnglishName("version"),fullName:L,familyName:I,weightName:O,postScriptName:X,unitsPerEm:e.unitsPerEm,fontBBox:[0,T.yMin,T.ascender,T.advanceWidthMax]}),ye=e.metas&&Object.keys(e.metas).length>0?HL.make(e.metas):void 0,oe=[w,N,C,R,ne,P,ce,ge,E];re&&oe.push(re),e.tables.gsub&&oe.push(jL.make(e.tables.gsub)),ye&&oe.push(ye);for(var Ae=qL(oe),Ie=Ae.encode(),Xe=F2(Ie),at=Ae.fields,W=!1,j=0;j>>1,a=e[s].tag;if(a===t)return s;a>>1,a=e[s];if(a===t)return s;a>>1;r=e[a];var n=r.start;if(n===t)return r;n0)return r=e[i-1],t>r.end?0:r}function lf(e,t){this.font=e,this.tableName=t}lf.prototype={searchTag:L2,binSearch:ZL,getTable:function(e){var t=this.font.tables[this.tableName];return!t&&e&&(t=this.font.tables[this.tableName]=this.createDefaultTable()),t},getScriptNames:function(){var e=this.getTable();return e?e.scripts.map(function(t){return t.tag}):[]},getDefaultScriptName:function(){var e=this.getTable();if(e){for(var t=!1,r=0;r=0)return i[s].script;if(t){var a={tag:e,script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}};return i.splice(-1-s,0,a),a.script}}},getLangSysTable:function(e,t,r){var i=this.getScriptTable(e,r);if(i){if(!t||t==="dflt"||t==="DFLT")return i.defaultLangSys;var s=L2(i.langSysRecords,t);if(s>=0)return i.langSysRecords[s].langSys;if(r){var a={tag:t,langSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]}};return i.langSysRecords.splice(-1-s,0,a),a.langSys}}},getFeatureTable:function(e,t,r,i){var s=this.getLangSysTable(e,t,i);if(s){for(var a,n=s.featureIndexes,o=this.font.tables[this.tableName].features,l=0;l=o[u-1].tag,"Features must be added in alphabetical order."),a={tag:r,feature:{params:0,lookupListIndexes:[]}},o.push(a),n.push(u),a.feature}}},getLookupTables:function(e,t,r,i,s){var a=this.getFeatureTable(e,t,r,s),n=[];if(a){for(var o,l=a.lookupListIndexes,u=this.font.tables[this.tableName].lookups,h=0;h=0?r:-1;case 2:var i=JL(e.ranges,t);return i?i.index+t-i.start:-1}},expandCoverage:function(e){if(e.format===1)return e.glyphs;for(var t=[],r=e.ranges,i=0;i1,'Multiple: "by" must be an array of two or more ids');var s=this.getLookupTables(r,i,e,2,!0)[0],a=k2(s,1,{substFormat:1,coverage:{format:1,glyphs:[]},sequences:[]});bt.assert(a.coverage.format===1,"Multiple: unable to modify coverage table format "+a.coverage.format);var n=t.sub,o=this.binSearch(a.coverage.glyphs,n);o<0&&(o=-1-o,a.coverage.glyphs.splice(o,0,n),a.sequences.splice(o,0,0)),a.sequences[o]=t.by},sa.prototype.addAlternate=function(e,t,r,i){var s=this.getLookupTables(r,i,e,3,!0)[0],a=k2(s,1,{substFormat:1,coverage:{format:1,glyphs:[]},alternateSets:[]});bt.assert(a.coverage.format===1,"Alternate: unable to modify coverage table format "+a.coverage.format);var n=t.sub,o=this.binSearch(a.coverage.glyphs,n);o<0&&(o=-1-o,a.coverage.glyphs.splice(o,0,n),a.alternateSets.splice(o,0,0)),a.alternateSets[o]=t.by},sa.prototype.addLigature=function(e,t,r,i){var s=this.getLookupTables(r,i,e,4,!0)[0],a=s.subtables[0];a||(a={substFormat:1,coverage:{format:1,glyphs:[]},ligatureSets:[]},s.subtables[0]=a),bt.assert(a.coverage.format===1,"Ligature: unable to modify coverage table format "+a.coverage.format);var n=t.sub[0],o=t.sub.slice(1),l={ligGlyph:t.by,components:o},u=this.binSearch(a.coverage.glyphs,n);if(u>=0){for(var h=a.ligatureSets[u],d=0;d0?(a=e.parseByte(),(t&s)===0&&(a=-a),a=r+a):(t&s)>0?a=r:a=r+e.parseShort(),a}function ek(e,t,r){var i=new ot.Parser(t,r);e.numberOfContours=i.parseShort(),e._xMin=i.parseShort(),e._yMin=i.parseShort(),e._xMax=i.parseShort(),e._yMax=i.parseShort();var s,a;if(e.numberOfContours>0){for(var n=e.endPointIndices=[],o=0;o0)for(var d=i.parseByte(),c=0;c0){var m=[],g;if(u>0){for(var y=0;y=0,m.push(g);for(var b=0,v=0;v0?(s&2)>0?(N.dx=i.parseShort(),N.dy=i.parseShort()):N.matchedPoints=[i.parseUShort(),i.parseUShort()]:(s&2)>0?(N.dx=i.parseChar(),N.dy=i.parseChar()):N.matchedPoints=[i.parseByte(),i.parseByte()],(s&8)>0?N.xScale=N.yScale=i.parseF2Dot14():(s&64)>0?(N.xScale=i.parseF2Dot14(),N.yScale=i.parseF2Dot14()):(s&128)>0&&(N.xScale=i.parseF2Dot14(),N.scale01=i.parseF2Dot14(),N.scale10=i.parseF2Dot14(),N.yScale=i.parseF2Dot14()),e.components.push(N),w=!!(s&32)}if(s&256){e.instructionLength=i.parseUShort(),e.instructions=[];for(var C=0;Ct.points.length-1||i.matchedPoints[1]>s.points.length-1)throw Error("Matched points out of range in "+t.name);var n=t.points[i.matchedPoints[0]],o=s.points[i.matchedPoints[1]],l={xScale:i.xScale,scale01:i.scale01,scale10:i.scale10,yScale:i.yScale,dx:0,dy:0};o=D2([o],l)[0],l.dx=n.x-o.x,l.dy=n.y-o.y,a=D2(s.points,l)}t.points=t.points.concat(a)}}return tk(t.points)}function gme(e,t,r,i){for(var s=new Zn.GlyphSet(i),a=0;a2)){var r=this.font,i=this._prepState;if(!i||i.ppem!==t){var s=this._fpgmState;if(!s){iu.prototype=wme,s=this._fpgmState=new iu("fpgm",r.tables.fpgm),s.funcs=[],s.font=r,exports.DEBUG&&(console.log("---EXEC FPGM---"),s.step=-1);try{Mh(s)}catch(u){console.log("Hinting error in FPGM:"+u),this._errorState=3;return}}iu.prototype=s,i=this._prepState=new iu("prep",r.tables.prep),i.ppem=t;var a=r.tables.cvt;if(a)for(var n=i.cvt=new Array(a.length),o=t/r.unitsPerEm,l=0;l1))try{return ak(e,i)}catch(u){this._errorState<1&&(console.log("Hinting error:"+u),console.log("Note: further hinting errors are silenced")),this._errorState=1;return}}},ak=function(e,t){var r=t.ppem/t.font.unitsPerEm,i=r,s=e.components,a,n,o;if(iu.prototype=t,!s)o=new iu("glyf",e.instructions),exports.DEBUG&&(console.log("---EXEC GLYPH---"),o.step=-1),O2(e,o,r,i),n=o.gZone;else{var l=t.font;n=[],a=[];for(var u=0;u=176&&a<=183)i+=a-176+1;else if(a>=184&&a<=191)i+=(a-184+1)*2;else if(t&&s===1&&a===27)break;while(s>0);e.ip=i}function hk(e,t){exports.DEBUG&&console.log(t.step,"SVTCA["+e.axis+"]"),t.fv=t.pv=t.dpv=e}function dk(e,t){exports.DEBUG&&console.log(t.step,"SPVTCA["+e.axis+"]"),t.pv=t.dpv=e}function ck(e,t){exports.DEBUG&&console.log(t.step,"SFVTCA["+e.axis+"]"),t.fv=e}function pk(e,t){var r=t.stack,i=r.pop(),s=r.pop(),a=t.z2[i],n=t.z1[s];exports.DEBUG&&console.log("SPVTL["+e+"]",i,s);var o,l;e?(o=a.y-n.y,l=n.x-a.x):(o=n.x-a.x,l=n.y-a.y),t.pv=t.dpv=cf(o,l)}function mk(e,t){var r=t.stack,i=r.pop(),s=r.pop(),a=t.z2[i],n=t.z1[s];exports.DEBUG&&console.log("SFVTL["+e+"]",i,s);var o,l;e?(o=a.y-n.y,l=n.x-a.x):(o=n.x-a.x,l=n.y-a.y),t.fv=cf(o,l)}function Mme(e){var t=e.stack,r=t.pop(),i=t.pop();exports.DEBUG&&console.log(e.step,"SPVFS[]",r,i),e.pv=e.dpv=cf(i,r)}function Nme(e){var t=e.stack,r=t.pop(),i=t.pop();exports.DEBUG&&console.log(e.step,"SPVFS[]",r,i),e.fv=cf(i,r)}function Ame(e){var t=e.stack,r=e.pv;exports.DEBUG&&console.log(e.step,"GPV[]"),t.push(r.x*16384),t.push(r.y*16384)}function Cme(e){var t=e.stack,r=e.fv;exports.DEBUG&&console.log(e.step,"GFV[]"),t.push(r.x*16384),t.push(r.y*16384)}function Rme(e){e.fv=e.pv,exports.DEBUG&&console.log(e.step,"SFVTPV[]")}function Eme(e){var t=e.stack,r=t.pop(),i=t.pop(),s=t.pop(),a=t.pop(),n=t.pop(),o=e.z0,l=e.z1,u=o[r],h=o[i],d=l[s],c=l[a],m=e.z2[n];exports.DEBUG&&console.log("ISECT[], ",r,i,s,a,n);var g=u.x,y=u.y,b=h.x,v=h.y,S=d.x,T=d.y,w=c.x,N=c.y,C=(g-b)*(T-N)-(y-v)*(S-w),R=g*v-y*b,E=S*N-T*w;m.x=(R*(S-w)-E*(g-b))/C,m.y=(R*(T-N)-E*(y-v))/C}function Pme(e){e.rp0=e.stack.pop(),exports.DEBUG&&console.log(e.step,"SRP0[]",e.rp0)}function Bme(e){e.rp1=e.stack.pop(),exports.DEBUG&&console.log(e.step,"SRP1[]",e.rp1)}function Ime(e){e.rp2=e.stack.pop(),exports.DEBUG&&console.log(e.step,"SRP2[]",e.rp2)}function Fme(e){var t=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,"SZP0[]",t),e.zp0=t,t){case 0:e.tZone||Ox(e),e.z0=e.tZone;break;case 1:e.z0=e.gZone;break;default:throw new Error("Invalid zone pointer")}}function Lme(e){var t=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,"SZP1[]",t),e.zp1=t,t){case 0:e.tZone||Ox(e),e.z1=e.tZone;break;case 1:e.z1=e.gZone;break;default:throw new Error("Invalid zone pointer")}}function kme(e){var t=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,"SZP2[]",t),e.zp2=t,t){case 0:e.tZone||Ox(e),e.z2=e.tZone;break;case 1:e.z2=e.gZone;break;default:throw new Error("Invalid zone pointer")}}function Dme(e){var t=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,"SZPS[]",t),e.zp0=e.zp1=e.zp2=t,t){case 0:e.tZone||Ox(e),e.z0=e.z1=e.z2=e.tZone;break;case 1:e.z0=e.z1=e.z2=e.gZone;break;default:throw new Error("Invalid zone pointer")}}function Ome(e){e.loop=e.stack.pop(),exports.DEBUG&&console.log(e.step,"SLOOP[]",e.loop)}function Ume(e){exports.DEBUG&&console.log(e.step,"RTG[]"),e.round=ok}function zme(e){exports.DEBUG&&console.log(e.step,"RTHG[]"),e.round=Tme}function Vme(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,"SMD[]",t),e.minDis=t/64}function Gme(e){exports.DEBUG&&console.log(e.step,"ELSE[]"),uk(e,!1)}function Wme(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,"JMPR[]",t),e.ip+=t-1}function jme(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,"SCVTCI[]",t),e.cvCutIn=t/64}function Hme(e){var t=e.stack;exports.DEBUG&&console.log(e.step,"DUP[]"),t.push(t[t.length-1])}function U2(e){exports.DEBUG&&console.log(e.step,"POP[]"),e.stack.pop()}function Xme(e){exports.DEBUG&&console.log(e.step,"CLEAR[]"),e.stack.length=0}function $me(e){var t=e.stack,r=t.pop(),i=t.pop();exports.DEBUG&&console.log(e.step,"SWAP[]"),t.push(r),t.push(i)}function qme(e){var t=e.stack;exports.DEBUG&&console.log(e.step,"DEPTH[]"),t.push(t.length)}function Yme(e){var t=e.stack,r=t.pop(),i=t.pop();exports.DEBUG&&console.log(e.step,"LOOPCALL[]",r,i);var s=e.ip,a=e.prog;e.prog=e.funcs[r];for(var n=0;n1?"loop "+(t.loop-o)+": ":"")+"SHP["+(e?"rp1":"rp2")+"]",u)}t.loop=1}function xk(e,t){var r=t.stack,i=e?t.rp1:t.rp2,s=(e?t.z0:t.z1)[i],a=t.fv,n=t.pv,o=r.pop(),l=t.z2[t.contours[o]],u=l;exports.DEBUG&&console.log(t.step,"SHC["+e+"]",o);var h=n.distance(s,s,!1,!0);do u!==s&&a.setRelative(u,u,h,n),u=u.nextPointOnContour;while(u!==l)}function vk(e,t){var r=t.stack,i=e?t.rp1:t.rp2,s=(e?t.z0:t.z1)[i],a=t.fv,n=t.pv,o=r.pop();exports.DEBUG&&console.log(t.step,"SHZ["+e+"]",o);var l;switch(o){case 0:l=t.tZone;break;case 1:l=t.gZone;break;default:throw new Error("Invalid zone")}for(var u,h=n.distance(s,s,!1,!0),d=l.length-2,c=0;c1?"loop "+(e.loop-r)+": ":"")+"SHPIX[]",n,s),i.setRelative(o,o,s),i.touch(o)}e.loop=1}function tfe(e){for(var t=e.stack,r=e.rp1,i=e.rp2,s=e.loop,a=e.z0[r],n=e.z1[i],o=e.fv,l=e.dpv,u=e.z2;s--;){var h=t.pop(),d=u[h];exports.DEBUG&&console.log(e.step,(e.loop>1?"loop "+(e.loop-s)+": ":"")+"IP[]",h,r,"<->",i),o.interpolate(d,a,n,l),o.touch(d)}e.loop=1}function bk(e,t){var r=t.stack,i=r.pop()/64,s=r.pop(),a=t.z1[s],n=t.z0[t.rp0],o=t.fv,l=t.pv;o.setRelative(a,n,i,l),o.touch(a),exports.DEBUG&&console.log(t.step,"MSIRP["+e+"]",i,s),t.rp1=t.rp0,t.rp2=s,e&&(t.rp0=s)}function rfe(e){for(var t=e.stack,r=e.rp0,i=e.z0[r],s=e.loop,a=e.fv,n=e.pv,o=e.z1;s--;){var l=t.pop(),u=o[l];exports.DEBUG&&console.log(e.step,(e.loop>1?"loop "+(e.loop-s)+": ":"")+"ALIGNRP[]",l),a.setRelative(u,i,0,n),a.touch(u)}e.loop=1}function ife(e){exports.DEBUG&&console.log(e.step,"RTDG[]"),e.round=bme}function Tk(e,t){var r=t.stack,i=r.pop(),s=r.pop(),a=t.z0[s],n=t.fv,o=t.pv,l=t.cvt[i];exports.DEBUG&&console.log(t.step,"MIAP["+e+"]",i,"(",l,")",s);var u=o.distance(a,pf);e&&(Math.abs(u-l)",o),t.stack.push(Math.round(o*64))}function hfe(e){exports.DEBUG&&console.log(e.step,"MPPEM[]"),e.stack.push(e.ppem)}function dfe(e){exports.DEBUG&&console.log(e.step,"FLIPON[]"),e.autoFlip=!0}function cfe(e){var t=e.stack,r=t.pop(),i=t.pop();exports.DEBUG&&console.log(e.step,"LT[]",r,i),t.push(ir?1:0)}function ffe(e){var t=e.stack,r=t.pop(),i=t.pop();exports.DEBUG&&console.log(e.step,"GTEQ[]",r,i),t.push(i>=r?1:0)}function gfe(e){var t=e.stack,r=t.pop(),i=t.pop();exports.DEBUG&&console.log(e.step,"EQ[]",r,i),t.push(r===i?1:0)}function yfe(e){var t=e.stack,r=t.pop(),i=t.pop();exports.DEBUG&&console.log(e.step,"NEQ[]",r,i),t.push(r!==i?1:0)}function xfe(e){var t=e.stack,r=t.pop();exports.DEBUG&&console.log(e.step,"ODD[]",r),t.push(Math.trunc(r)%2?1:0)}function vfe(e){var t=e.stack,r=t.pop();exports.DEBUG&&console.log(e.step,"EVEN[]",r),t.push(Math.trunc(r)%2?0:1)}function bfe(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,"IF[]",t),t||(uk(e,!0),exports.DEBUG&&console.log(e.step,"EIF[]"))}function Tfe(e){exports.DEBUG&&console.log(e.step,"EIF[]")}function Sfe(e){var t=e.stack,r=t.pop(),i=t.pop();exports.DEBUG&&console.log(e.step,"AND[]",r,i),t.push(r&&i?1:0)}function _fe(e){var t=e.stack,r=t.pop(),i=t.pop();exports.DEBUG&&console.log(e.step,"OR[]",r,i),t.push(r||i?1:0)}function wfe(e){var t=e.stack,r=t.pop();exports.DEBUG&&console.log(e.step,"NOT[]",r),t.push(r?0:1)}function z2(e,t){var r=t.stack,i=r.pop(),s=t.fv,a=t.pv,n=t.ppem,o=t.deltaBase+(e-1)*16,l=t.deltaShift,u=t.z0;exports.DEBUG&&console.log(t.step,"DELTAP["+e+"]",i,r);for(var h=0;h>4);if(m===n){var g=(c&15)-8;g>=0&&g++,exports.DEBUG&&console.log(t.step,"DELTAPFIX",d,"by",g*l);var y=u[d];s.setRelative(y,y,g*l,a)}}}function Mfe(e){var t=e.stack,r=t.pop();exports.DEBUG&&console.log(e.step,"SDB[]",r),e.deltaBase=r}function Nfe(e){var t=e.stack,r=t.pop();exports.DEBUG&&console.log(e.step,"SDS[]",r),e.deltaShift=Math.pow(.5,r)}function Afe(e){var t=e.stack,r=t.pop(),i=t.pop();exports.DEBUG&&console.log(e.step,"ADD[]",r,i),t.push(i+r)}function Cfe(e){var t=e.stack,r=t.pop(),i=t.pop();exports.DEBUG&&console.log(e.step,"SUB[]",r,i),t.push(i-r)}function Rfe(e){var t=e.stack,r=t.pop(),i=t.pop();exports.DEBUG&&console.log(e.step,"DIV[]",r,i),t.push(i*64/r)}function Efe(e){var t=e.stack,r=t.pop(),i=t.pop();exports.DEBUG&&console.log(e.step,"MUL[]",r,i),t.push(i*r/64)}function Pfe(e){var t=e.stack,r=t.pop();exports.DEBUG&&console.log(e.step,"ABS[]",r),t.push(Math.abs(r))}function Bfe(e){var t=e.stack,r=t.pop();exports.DEBUG&&console.log(e.step,"NEG[]",r),t.push(-r)}function Ife(e){var t=e.stack,r=t.pop();exports.DEBUG&&console.log(e.step,"FLOOR[]",r),t.push(Math.floor(r/64)*64)}function Ffe(e){var t=e.stack,r=t.pop();exports.DEBUG&&console.log(e.step,"CEILING[]",r),t.push(Math.ceil(r/64)*64)}function Ux(e,t){var r=t.stack,i=r.pop();exports.DEBUG&&console.log(t.step,"ROUND[]"),r.push(t.round(i/64)*64)}function Lfe(e){var t=e.stack,r=t.pop(),i=t.pop();exports.DEBUG&&console.log(e.step,"WCVTF[]",r,i),e.cvt[i]=r*e.ppem/e.font.unitsPerEm}function V2(e,t){var r=t.stack,i=r.pop(),s=t.ppem,a=t.deltaBase+(e-1)*16,n=t.deltaShift;exports.DEBUG&&console.log(t.step,"DELTAC["+e+"]",i,r);for(var o=0;o>4);if(h===s){var d=(u&15)-8;d>=0&&d++;var c=d*n;exports.DEBUG&&console.log(t.step,"DELTACFIX",l,"by",c),t.cvt[l]+=c}}}function kfe(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,"SROUND[]",t),e.round=lk;var r;switch(t&192){case 0:r=.5;break;case 64:r=1;break;case 128:r=2;break;default:throw new Error("invalid SROUND value")}switch(e.srPeriod=r,t&48){case 0:e.srPhase=0;break;case 16:e.srPhase=.25*r;break;case 32:e.srPhase=.5*r;break;case 48:e.srPhase=.75*r;break;default:throw new Error("invalid SROUND value")}t&=15,t===0?e.srThreshold=0:e.srThreshold=(t/8-.5)*r}function Dfe(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,"S45ROUND[]",t),e.round=lk;var r;switch(t&192){case 0:r=Math.sqrt(2)/2;break;case 64:r=Math.sqrt(2);break;case 128:r=2*Math.sqrt(2);break;default:throw new Error("invalid S45ROUND value")}switch(e.srPeriod=r,t&48){case 0:e.srPhase=0;break;case 16:e.srPhase=.25*r;break;case 32:e.srPhase=.5*r;break;case 48:e.srPhase=.75*r;break;default:throw new Error("invalid S45ROUND value")}t&=15,t===0?e.srThreshold=0:e.srThreshold=(t/8-.5)*r}function Ofe(e){exports.DEBUG&&console.log(e.step,"ROFF[]"),e.round=vme}function Ufe(e){exports.DEBUG&&console.log(e.step,"RUTG[]"),e.round=Sme}function zfe(e){exports.DEBUG&&console.log(e.step,"RDTG[]"),e.round=_me}function Vfe(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,"SCANCTRL[]",t)}function wk(e,t){var r=t.stack,i=r.pop(),s=r.pop(),a=t.z2[i],n=t.z1[s];exports.DEBUG&&console.log(t.step,"SDPVTL["+e+"]",i,s);var o,l;e?(o=a.y-n.y,l=n.x-a.x):(o=n.x-a.x,l=n.y-a.y),t.dpv=cf(o,l)}function Gfe(e){var t=e.stack,r=t.pop(),i=0;exports.DEBUG&&console.log(e.step,"GETINFO[]",r),r&1&&(i=35),r&32&&(i|=4096),t.push(i)}function Wfe(e){var t=e.stack,r=t.pop(),i=t.pop(),s=t.pop();exports.DEBUG&&console.log(e.step,"ROLL[]"),t.push(i),t.push(r),t.push(s)}function jfe(e){var t=e.stack,r=t.pop(),i=t.pop();exports.DEBUG&&console.log(e.step,"MAX[]",r,i),t.push(Math.max(i,r))}function Hfe(e){var t=e.stack,r=t.pop(),i=t.pop();exports.DEBUG&&console.log(e.step,"MIN[]",r,i),t.push(Math.min(i,r))}function Xfe(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,"SCANTYPE[]",t)}function $fe(e){var t=e.stack.pop(),r=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,"INSTCTRL[]",t,r),t){case 1:e.inhibitGridFit=!!r;return;case 2:e.ignoreCvt=!!r;return;default:throw new Error("invalid INSTCTRL[] selector")}}function su(e,t){var r=t.stack,i=t.prog,s=t.ip;exports.DEBUG&&console.log(t.step,"PUSHB["+e+"]");for(var a=0;a=0?1:-1,b=Math.abs(b),e&&(S=a.cvt[o],i&&Math.abs(b-S)":"_")+(i?"R":"_")+(s===0?"Gr":s===1?"Bl":s===2?"Wh":"")+"]",e?o+"("+a.cvt[o]+","+S+")":"",l,"(d =",y,"->",v*b,")"),a.rp1=a.rp0,a.rp2=l,t&&(a.rp0=l)}sk=[hk.bind(void 0,qo),hk.bind(void 0,Jn),dk.bind(void 0,qo),dk.bind(void 0,Jn),ck.bind(void 0,qo),ck.bind(void 0,Jn),pk.bind(void 0,0),pk.bind(void 0,1),mk.bind(void 0,0),mk.bind(void 0,1),Mme,Nme,Ame,Cme,Rme,Eme,Pme,Bme,Ime,Fme,Lme,kme,Dme,Ome,Ume,zme,Vme,Gme,Wme,jme,void 0,void 0,Hme,U2,Xme,$me,qme,Jme,Qme,void 0,void 0,void 0,Yme,Zme,Kme,void 0,fk.bind(void 0,0),fk.bind(void 0,1),gk.bind(void 0,qo),gk.bind(void 0,Jn),yk.bind(void 0,0),yk.bind(void 0,1),xk.bind(void 0,0),xk.bind(void 0,1),vk.bind(void 0,0),vk.bind(void 0,1),efe,tfe,bk.bind(void 0,0),bk.bind(void 0,1),rfe,ife,Tk.bind(void 0,0),Tk.bind(void 0,1),sfe,afe,nfe,ofe,lfe,ufe,Sk.bind(void 0,0),Sk.bind(void 0,1),void 0,_k.bind(void 0,0),_k.bind(void 0,1),hfe,void 0,dfe,void 0,void 0,cfe,pfe,mfe,ffe,gfe,yfe,xfe,vfe,bfe,Tfe,Sfe,_fe,wfe,z2.bind(void 0,1),Mfe,Nfe,Afe,Cfe,Rfe,Efe,Pfe,Bfe,Ife,Ffe,Ux.bind(void 0,0),Ux.bind(void 0,1),Ux.bind(void 0,2),Ux.bind(void 0,3),void 0,void 0,void 0,void 0,Lfe,z2.bind(void 0,2),z2.bind(void 0,3),V2.bind(void 0,1),V2.bind(void 0,2),V2.bind(void 0,3),kfe,Dfe,void 0,void 0,Ofe,void 0,Ufe,zfe,U2,U2,void 0,void 0,void 0,void 0,void 0,Vfe,wk.bind(void 0,0),wk.bind(void 0,1),Gfe,void 0,Wfe,jfe,Hfe,Xfe,$fe,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,su.bind(void 0,1),su.bind(void 0,2),su.bind(void 0,3),su.bind(void 0,4),su.bind(void 0,5),su.bind(void 0,6),su.bind(void 0,7),su.bind(void 0,8),au.bind(void 0,1),au.bind(void 0,2),au.bind(void 0,3),au.bind(void 0,4),au.bind(void 0,5),au.bind(void 0,6),au.bind(void 0,7),au.bind(void 0,8),lt.bind(void 0,0,0,0,0,0),lt.bind(void 0,0,0,0,0,1),lt.bind(void 0,0,0,0,0,2),lt.bind(void 0,0,0,0,0,3),lt.bind(void 0,0,0,0,1,0),lt.bind(void 0,0,0,0,1,1),lt.bind(void 0,0,0,0,1,2),lt.bind(void 0,0,0,0,1,3),lt.bind(void 0,0,0,1,0,0),lt.bind(void 0,0,0,1,0,1),lt.bind(void 0,0,0,1,0,2),lt.bind(void 0,0,0,1,0,3),lt.bind(void 0,0,0,1,1,0),lt.bind(void 0,0,0,1,1,1),lt.bind(void 0,0,0,1,1,2),lt.bind(void 0,0,0,1,1,3),lt.bind(void 0,0,1,0,0,0),lt.bind(void 0,0,1,0,0,1),lt.bind(void 0,0,1,0,0,2),lt.bind(void 0,0,1,0,0,3),lt.bind(void 0,0,1,0,1,0),lt.bind(void 0,0,1,0,1,1),lt.bind(void 0,0,1,0,1,2),lt.bind(void 0,0,1,0,1,3),lt.bind(void 0,0,1,1,0,0),lt.bind(void 0,0,1,1,0,1),lt.bind(void 0,0,1,1,0,2),lt.bind(void 0,0,1,1,0,3),lt.bind(void 0,0,1,1,1,0),lt.bind(void 0,0,1,1,1,1),lt.bind(void 0,0,1,1,1,2),lt.bind(void 0,0,1,1,1,3),lt.bind(void 0,1,0,0,0,0),lt.bind(void 0,1,0,0,0,1),lt.bind(void 0,1,0,0,0,2),lt.bind(void 0,1,0,0,0,3),lt.bind(void 0,1,0,0,1,0),lt.bind(void 0,1,0,0,1,1),lt.bind(void 0,1,0,0,1,2),lt.bind(void 0,1,0,0,1,3),lt.bind(void 0,1,0,1,0,0),lt.bind(void 0,1,0,1,0,1),lt.bind(void 0,1,0,1,0,2),lt.bind(void 0,1,0,1,0,3),lt.bind(void 0,1,0,1,1,0),lt.bind(void 0,1,0,1,1,1),lt.bind(void 0,1,0,1,1,2),lt.bind(void 0,1,0,1,1,3),lt.bind(void 0,1,1,0,0,0),lt.bind(void 0,1,1,0,0,1),lt.bind(void 0,1,1,0,0,2),lt.bind(void 0,1,1,0,0,3),lt.bind(void 0,1,1,0,1,0),lt.bind(void 0,1,1,0,1,1),lt.bind(void 0,1,1,0,1,2),lt.bind(void 0,1,1,0,1,3),lt.bind(void 0,1,1,1,0,0),lt.bind(void 0,1,1,1,0,1),lt.bind(void 0,1,1,1,0,2),lt.bind(void 0,1,1,1,0,3),lt.bind(void 0,1,1,1,1,0),lt.bind(void 0,1,1,1,1,1),lt.bind(void 0,1,1,1,1,2),lt.bind(void 0,1,1,1,1,3)];function Ic(e){this.char=e,this.state={},this.activeState=null}function G2(e,t,r){this.contextName=r,this.startIndex=e,this.endOffset=t}function qfe(e,t,r){this.contextName=e,this.openRange=null,this.ranges=[],this.checkStart=t,this.checkEnd=r}function an(e,t){this.context=e,this.index=t,this.length=e.length,this.current=e[t],this.backtrack=e.slice(0,t),this.lookahead=e.slice(t+1)}function zx(e){this.eventId=e,this.subscribers=[]}function Yfe(e){var t=this,r=["start","end","next","newToken","contextStart","contextEnd","insertToken","removeToken","removeRange","replaceToken","replaceRange","composeRUD","updateContextsRanges"];r.forEach(function(s){Object.defineProperty(t.events,s,{value:new zx(s)})}),e&&r.forEach(function(s){var a=e[s];typeof a=="function"&&t.events[s].subscribe(a)});var i=["insertToken","removeToken","removeRange","replaceToken","replaceRange","composeRUD"];i.forEach(function(s){t.events[s].subscribe(t.updateContextsRanges)})}function Xr(e){this.tokens=[],this.registeredContexts={},this.contextCheckers=[],this.events={},this.registeredModifiers=[],Yfe.call(this,e)}Ic.prototype.setState=function(e,t){return this.state[e]=t,this.activeState={key:e,value:this.state[e]},this.activeState},Ic.prototype.getState=function(e){return this.state[e]||null},Xr.prototype.inboundIndex=function(e){return e>=0&&e0&&e<=this.lookahead.length):return this.lookahead[e-1];default:return null}},Xr.prototype.rangeToText=function(e){if(e instanceof G2)return this.getRangeTokens(e).map(function(t){return t.char}).join("")},Xr.prototype.getText=function(){return this.tokens.map(function(e){return e.char}).join("")},Xr.prototype.getContext=function(e){var t=this.registeredContexts[e];return t||null},Xr.prototype.on=function(e,t){var r=this.events[e];return r?r.subscribe(t):null},Xr.prototype.dispatch=function(e,t){var r=this,i=this.events[e];i instanceof zx&&i.subscribers.forEach(function(s){s.apply(r,t||[])})},Xr.prototype.registerContextChecker=function(e,t,r){if(this.getContext(e))return{FAIL:"context name '"+e+"' is already registered."};if(typeof t!="function")return{FAIL:"missing context start check."};if(typeof r!="function")return{FAIL:"missing context end check."};var i=new qfe(e,t,r);return this.registeredContexts[e]=i,this.contextCheckers.push(i),i},Xr.prototype.getRangeTokens=function(e){var t=e.startIndex+e.endOffset;return[].concat(this.tokens.slice(e.startIndex,t))},Xr.prototype.getContextRanges=function(e){var t=this.getContext(e);return t?t.ranges:{FAIL:"context checker '"+e+"' is not registered."}},Xr.prototype.resetContextsRanges=function(){var e=this.registeredContexts;for(var t in e)if(e.hasOwnProperty(t)){var r=e[t];r.ranges=[]}},Xr.prototype.updateContextsRanges=function(){this.resetContextsRanges();for(var e=this.tokens.map(function(i){return i.char}),t=0;t=s.start&&e<=s.end){var a=e-s.start;return s.index+a}}break;default:return-1}return-1}function Jfe(e,t){var r=mf(e,t.coverage);return r===-1?null:e+t.deltaGlyphId}function Qfe(e,t){var r=mf(e,t.coverage);return r===-1?null:t.substitute[r]}function W2(e,t){for(var r=[],i=0;i=0;r--){var i=t[r],s=Mk(i),a=ou(i);if(!s&&!a)return!0;if(s)return!1}return!1}function pge(e){if(Mk(e.current))return!1;for(var t=0;t0}r("fontFamily"),r("weightName"),r("manufacturer"),r("copyright"),r("version"),this.unitsPerEm>0},dr.prototype.toTables=function(){return dme.fontToTable(this)},dr.prototype.toBuffer=function(){return console.warn("Font.toBuffer is deprecated. Use Font.toArrayBuffer instead."),this.toArrayBuffer()},dr.prototype.toArrayBuffer=function(){for(var e=this.toTables(),t=e.encode(),r=new ArrayBuffer(t.length),i=new Uint8Array(r),s=0;s=1.2&&(s.markGlyphSets=r.parsePointer(kge)),s}var Oge={parse:Dge},on=new Array(10);on[1]=function(){var e=this.offset+this.relativeOffset,t=this.parseUShort();if(t===1)return{posFormat:1,coverage:this.parsePointer(ve.coverage),value:this.parseValueRecord()};if(t===2)return{posFormat:2,coverage:this.parsePointer(ve.coverage),values:this.parseValueRecordList()};bt.assert(!1,"0x"+e.toString(16)+": GPOS lookup type 1 format must be 1 or 2.")},on[2]=function(){var e=this.offset+this.relativeOffset,t=this.parseUShort();bt.assert(t===1||t===2,"0x"+e.toString(16)+": GPOS lookup type 2 format must be 1 or 2.");var r=this.parsePointer(ve.coverage),i=this.parseUShort(),s=this.parseUShort();if(t===1)return{posFormat:t,coverage:r,valueFormat1:i,valueFormat2:s,pairSets:this.parseList(ve.pointer(ve.list(function(){return{secondGlyph:this.parseUShort(),value1:this.parseValueRecord(i),value2:this.parseValueRecord(s)}})))};if(t===2){var a=this.parsePointer(ve.classDef),n=this.parsePointer(ve.classDef),o=this.parseUShort(),l=this.parseUShort();return{posFormat:t,coverage:r,valueFormat1:i,valueFormat2:s,classDef1:a,classDef2:n,class1Count:o,class2Count:l,classRecords:this.parseList(o,ve.list(l,function(){return{value1:this.parseValueRecord(i),value2:this.parseValueRecord(s)}}))}}},on[3]=function(){return{error:"GPOS Lookup 3 not supported"}},on[4]=function(){return{error:"GPOS Lookup 4 not supported"}},on[5]=function(){return{error:"GPOS Lookup 5 not supported"}},on[6]=function(){return{error:"GPOS Lookup 6 not supported"}},on[7]=function(){return{error:"GPOS Lookup 7 not supported"}},on[8]=function(){return{error:"GPOS Lookup 8 not supported"}},on[9]=function(){return{error:"GPOS Lookup 9 not supported"}};function Uge(e,t){t=t||0;var r=new ve(e,t),i=r.parseVersion(1);return bt.argument(i===1||i===1.1,"Unsupported GPOS table version "+i),i===1?{version:i,scripts:r.parseScriptList(),features:r.parseFeatureList(),lookups:r.parseLookupList(on)}:{version:i,scripts:r.parseScriptList(),features:r.parseFeatureList(),lookups:r.parseLookupList(on),variations:r.parseFeatureVariationsList()}}var zge=new Array(10);function Vge(e){return new rt.Table("GPOS",[{name:"version",type:"ULONG",value:65536},{name:"scripts",type:"TABLE",value:new rt.ScriptList(e.scripts)},{name:"features",type:"TABLE",value:new rt.FeatureList(e.features)},{name:"lookups",type:"TABLE",value:new rt.LookupList(e.lookups,zge)}])}var Gge={parse:Uge,make:Vge};function Wge(e){var t={};e.skip("uShort");var r=e.parseUShort();bt.argument(r===0,"Unsupported kern sub-table version."),e.skip("uShort",2);var i=e.parseUShort();e.skip("uShort",3);for(var s=0;s1&&console.warn("Only the first kern subtable is supported."),e.skip("uLong");var i=e.parseUShort(),s=i&255;if(e.skip("uShort"),s===0){var a=e.parseUShort();e.skip("uShort",3);for(var n=0;n"u",s=i&&!r.isUrl?Yge:Zge;return new Promise(function(a,n){s(e,function(o,l){if(o){if(t)return t(o);n(o)}var u;try{u=$2(l,r)}catch(h){if(t)return t(h,null);n(h)}if(t)return t(null,u);a(u)})})}function Kge(e,t){var r=ev(),i=r.readFileSync(e);return $2(QL(i),t)}var e0e=Object.freeze({__proto__:null,Font:dr,Glyph:ia,Path:di,BoundingBox:$o,_parse:ot,parse:$2,load:Qge,loadSync:Kge}),t0e=e0e,Pk=new Map;function r0e(e){let t=Pk.get(e);return t||(t=fetch(e).then(r=>{if(!r.ok)throw new Error(`typeface: ${r.status}`);return r.arrayBuffer()}).then(r=>t0e.parse(r)),Pk.set(e,t)),t}function i0e(e,t,r=0){return e.getAdvanceWidth(t,1,{kerning:!0,letterSpacing:r})}function s0e(e,t,r,i,s=0){let a=r/e.unitsPerEm,n=(e.tables?.os2?.sCapHeight??e.ascender*.72)*a,o=i*r,l=o*(t.length-1)+n,u=[];return t.forEach((h,d)=>{let c=e.getAdvanceWidth(h,r,{kerning:!0,letterSpacing:s}),m=l/2-n-d*o,g=e.getPath(h,-c/2,0,r,{kerning:!0,letterSpacing:s}),y=new nl,b=v=>m-v;for(let v of g.commands)v.type==="M"?y.moveTo(v.x,b(v.y)):v.type==="L"?y.lineTo(v.x,b(v.y)):v.type==="Q"?y.quadraticCurveTo(v.x1,b(v.y1),v.x,b(v.y)):v.type==="C"?y.bezierCurveTo(v.x1,b(v.y1),v.x2,b(v.y2),v.x,b(v.y)):v.type==="Z"&&y.currentPath?.closePath();u.push(...k5.createShapes(y))}),u}var a0e="frost-build-cache",ff="builds",n0e=1,o0e="frost-build-10-planar-cap-normals";function Bk(){return new Promise(e=>{try{if(typeof indexedDB>"u")return e(null);let t=indexedDB.open(a0e,n0e);t.onupgradeneeded=()=>{t.result.createObjectStore(ff)},t.onsuccess=()=>e(t.result),t.onerror=()=>e(null)}catch{e(null)}})}async function l0e(e){let t=await Bk();return t?new Promise(r=>{try{let i=t.transaction(ff,"readonly").objectStore(ff).get(e);i.onsuccess=()=>r(i.result??null),i.onerror=()=>r(null)}catch{r(null)}}):null}async function u0e(e,t){let r=await Bk();r&&await new Promise(i=>{try{let s=r.transaction(ff,"readwrite"),a=s.objectStore(ff);a.clear(),a.put(t,e),s.oncomplete=()=>i(),s.onerror=()=>i()}catch{i()}})}function h0e(e){let t=r=>e.attributes[r]?e.attributes[r].array:null;return{position:t("position"),normal:t("normal"),uv:t("uv"),index:e.index?new Uint32Array(e.index.array):null}}function d0e(e){let t=new ps;return t.setAttribute("position",new tr(e.position,3)),t.setAttribute("normal",new tr(e.normal,3)),e.uv&&t.setAttribute("uv",new tr(e.uv,2)),e.index&&t.setIndex(new _i(e.index,1)),t.computeBoundingBox(),t}var Ah=1/60,c0e=y2(Ice),p0e="frost-ice-textured-r1-reference-optics",Ik=12,Gx={turbulenceScale:{path:["powder","turbulenceScale"],replay:!0},clumpCohesion:{path:["powder","clumpCohesion"],replay:!0},repelStrength:{path:["powder","repelStrength"],replay:!0},repelRange:{path:["powder","repelRange"],replay:!0},repelRadial:{path:["powder","repelRadial"],replay:!0},repelRadialRange:{path:["powder","repelRadialRange"],replay:!0},wrap:{path:["powder","wrap"],replay:!1},turbulenceDecay:{path:["powder","turbulenceDecay"],replay:!0},settledDrift:{path:["powder","settledDrift"],replay:!0},tumble:{path:["powder","tumble"],replay:!1},assemblyFrontDuration:{path:["healing","assemblyFrontDuration"],replay:!0},assemblyOriginX:{path:["healing","assemblyOriginX"],replay:!0},assemblyOriginY:{path:["healing","assemblyOriginY"],replay:!0},assemblyAngle:{path:["healing","assemblyAngle"],replay:!0},assemblySpread:{path:["healing","assemblySpread"],replay:!0},assemblyFrontNoise:{path:["healing","assemblyFrontNoise"],replay:!0},assemblySpeedVariation:{path:["healing","assemblySpeedVariation"],replay:!0},assemblyBend:{path:["healing","assemblyBend"],replay:!0},assemblySwirl:{path:["healing","assemblySwirl"],replay:!0},assemblyLandingVariation:{path:["healing","assemblyLandingVariation"],replay:!0},returnNoiseAmount:{path:["healing","returnNoiseAmount"],replay:!0},returnGroupStagger:{path:["healing","returnGroupStagger"],replay:!0},returnGroupScale:{path:["healing","returnGroupScale"],replay:!0},returnGroupSeed:{path:["healing","returnGroupSeed"],replay:!0},formJitter:{path:["healing","waveJitter"],replay:!0},waveReach:{path:["healing","waveReach"],replay:!0},alignToSurface:{path:["healing","alignToSurface"],replay:!1},alignCurve:{path:["healing","alignCurve"],replay:!1},rimAzimuth:{path:["lighting","rimAzimuth"],replay:!1},rimAngle:{path:["lighting","rimAngle"],replay:!1},rimSize:{path:["lighting","rimSize"],replay:!1},fillReflectionStrength:{path:["lighting","fillReflectionStrength"],replay:!1},accentCoolIntensity:{path:["lighting","accentCool","intensity"],replay:!1},accentCoolReflection:{path:["lighting","accentCool","reflection"],replay:!1},accentCoolElevation:{path:["lighting","accentCool","elevation"],replay:!1},accentCoolAzimuth:{path:["lighting","accentCool","azimuth"],replay:!1},accentCoolSize:{path:["lighting","accentCool","size"],replay:!1},accentCoolColor:{path:["lighting","accentCool","color"],replay:!1},accentWarmIntensity:{path:["lighting","accentWarm","intensity"],replay:!1},accentWarmReflection:{path:["lighting","accentWarm","reflection"],replay:!1},accentWarmElevation:{path:["lighting","accentWarm","elevation"],replay:!1},accentWarmAzimuth:{path:["lighting","accentWarm","azimuth"],replay:!1},accentWarmSize:{path:["lighting","accentWarm","size"],replay:!1},accentWarmColor:{path:["lighting","accentWarm","color"],replay:!1},keyColor:{path:["lighting","key","color"],replay:!1},keyIntensity:{path:["lighting","key","intensity"],replay:!1},keyElevation:{path:["lighting","key","elevation"],replay:!1},keyAzimuth:{path:["lighting","key","azimuth"],replay:!1},keySize:{path:["lighting","key","size"],replay:!1},fill:{path:["lighting","fill"],replay:!1},fillColor:{path:["lighting","fillColor"],replay:!1},fillGroundColor:{path:["lighting","fillGroundColor"],replay:!1},rim:{path:["lighting","rim"],replay:!1},rimColor:{path:["lighting","rimColor"],replay:!1},rimElevation:{path:["lighting","rimElevation"],replay:!1},swayAmplitude:{path:["lighting","sway","amplitude"],replay:!1},swayPeriod:{path:["lighting","sway","period"],replay:!1},envSoftbox:{path:["lighting","envSoftbox"],replay:!1},envRim:{path:["lighting","envRim"],replay:!1},envFill:{path:["lighting","envFill"],replay:!1},backdropTop:{path:["lighting","backdrop","top"],replay:!1},backdropMid:{path:["lighting","backdrop","mid"],replay:!1},backdropBottom:{path:["lighting","backdrop","bottom"],replay:!1},backdropCenterX:{path:["lighting","backdrop","centerX"],replay:!1},backdropCenterY:{path:["lighting","backdrop","centerY"],replay:!1},backdropRadius:{path:["lighting","backdrop","radius"],replay:!1},backdropFalloff:{path:["lighting","backdrop","falloff"],replay:!1},backdropNoise:{path:["lighting","backdrop","noise"],replay:!1},...Object.fromEntries(Object.keys(Qd).map(e=>[$ie(e),{path:["ice","features",e],replay:!1}])),materialBacklight:{path:["ice","backlight"],replay:!1},materialInclusionAmount:{path:["ice","inclusionAmount"],replay:!1},materialInclusionScale:{path:["ice","inclusionScale"],replay:!1},materialBaseColor:{path:["ice","baseColor"],replay:!1},materialInteriorFrost:{path:["erosion","interiorFrost"],replay:!1},materialGrainAmount:{path:["erosion","edgeBump"],replay:!1},materialGrainScale:{path:["erosion","edgeBumpScale"],replay:!1},ior:{path:["ice","ior"],replay:!1},dispersion:{path:["ice","dispersion"],replay:!1},thicknessScale:{path:["ice","thicknessScale"],replay:!1},attenuationDistance:{path:["ice","attenuationDistance"],replay:!1},attenuationColor:{path:["ice","attenuationColor"],replay:!1},baseRoughness:{path:["ice","baseRoughness"],replay:!1},crumbleGlow:{path:["ice","crumbleGlow"],replay:!1},edgeWhiteness:{path:["ice","edgeWhiteness"],replay:!1},clearcoat:{path:["ice","clearcoat"],replay:!1},clearcoatRoughness:{path:["ice","clearcoatRoughness"],replay:!1},envIntensity:{path:["ice","envIntensity"],replay:!1},specularIntensity:{path:["ice","specularIntensity"],replay:!1},interiorScatter:{path:["ice","interiorScatter"],replay:!1},frostScale:{path:["ice","frost","scale"],replay:!1},frostThreshold:{path:["ice","frost","threshold"],replay:!1},frostSoftness:{path:["ice","frost","softness"],replay:!1},frostRoughness:{path:["ice","frost","roughness"],replay:!1},frostDiffuse:{path:["ice","frost","diffuse"],replay:!1},crystalBump:{path:["ice","frost","crystalBump"],replay:!1},crystalScale:{path:["ice","frost","crystalScale"],replay:!1},crackLargeScale:{path:["ice","cracks","largeScale"],replay:!1},crackWarp:{path:["ice","cracks","warp"],replay:!1},crackWarpScale:{path:["ice","cracks","warpScale"],replay:!1},crackCoverage:{path:["ice","cracks","coverage"],replay:!1},crackRegionScale:{path:["ice","cracks","regionScale"],replay:!1},crackRegionCoverage:{path:["ice","cracks","regionCoverage"],replay:!1},veinScale:{path:["ice","cracks","veinScale"],replay:!1},veinContrast:{path:["ice","cracks","veinContrast"],replay:!1},crackWidth:{path:["ice","cracks","width"],replay:!1},crackBrightness:{path:["ice","cracks","brightness"],replay:!1},crackDarkness:{path:["ice","cracks","darkness"],replay:!1},crackRefraction:{path:["ice","cracks","refraction"],replay:!1},crackSurfaceStrength:{path:["ice","cracks","surfaceStrength"],replay:!1},fineScale:{path:["ice","cracks","fineScale"],replay:!1},fineAmount:{path:["ice","cracks","fineAmount"],replay:!1},fineCoverage:{path:["ice","cracks","fineCoverage"],replay:!1},smudgeAmount:{path:["ice","smudges","amount"],replay:!1},smudgeCoverage:{path:["ice","smudges","coverage"],replay:!1},smudgeMaskScale:{path:["ice","smudges","maskScale"],replay:!1},smudgeAnisotropy:{path:["ice","smudges","anisotropy"],replay:!1},smudgeRoughness:{path:["ice","smudges","roughness"],replay:!1},smudgeWhiteness:{path:["ice","smudges","whiteness"],replay:!1},smudgeScale:{path:["ice","smudges","scale"],replay:!1},microBump:{path:["ice","bumps","microBump"],replay:!1},microScale:{path:["ice","bumps","microScale"],replay:!1},microCoverage:{path:["ice","bumps","microCoverage"],replay:!1},rippleBump:{path:["ice","bumps","rippleBump"],replay:!1},rippleScale:{path:["ice","bumps","rippleScale"],replay:!1},bumpMaskScale:{path:["ice","bumps","maskScale"],replay:!1},baseTone:{path:["powder","baseTone"],replay:!1},fragTranslucency:{path:["powder","fragments","translucency"],replay:!1},fragThroughTint:{path:["powder","fragments","throughTint"],replay:!1},fragFresnelPower:{path:["powder","fragments","fresnelPower"],replay:!1},fragRoughness:{path:["powder","fragments","roughness"],replay:!1},fragClearcoat:{path:["powder","fragments","clearcoat"],replay:!1},fragSpecular:{path:["powder","fragments","specular"],replay:!1},sparkle:{path:["powder","fragments","sparkle"],replay:!1},sparkleFraction:{path:["powder","fragments","sparkleFraction"],replay:!1},spriteTilt:{path:["powder","sprites","tilt"],replay:!1},spriteNormal:{path:["powder","sprites","normalStrength"],replay:!1},spriteFrost:{path:["powder","sprites","frostFromAtlas"],replay:!1},spriteFrostBoost:{path:["powder","sprites","frostBoost"],replay:!1},spriteFrostRoughness:{path:["powder","sprites","frostRoughness"],replay:!1},spriteEdgeLight:{path:["powder","sprites","edgeLight"],replay:!1},spriteAlphaCut:{path:["powder","sprites","alphaCut"],replay:!1},spriteSeeThrough:{path:["powder","sprites","seeThrough"],replay:!1},bloomThreshold:{path:["post","bloom","threshold"],replay:!1},bloomIntensity:{path:["post","bloom","intensity"],replay:!1},bloomRadius:{path:["post","bloom","radius"],replay:!1},monochrome:{path:["post","monochrome"],replay:!1},tonemap:{path:["post","tonemap"],replay:!1},exposure:{path:["post","exposure"],replay:!1},contrast:{path:["post","contrast"],replay:!1},blackLift:{path:["post","blackLift"],replay:!1},vignetteStrength:{path:["post","vignette","strength"],replay:!1},vignetteSoftness:{path:["post","vignette","softness"],replay:!1},vignetteRadius:{path:["post","vignette","radius"],replay:!1},grainStrength:{path:["post","grain","strength"],replay:!1},cutThreshold:{path:["erosion","cutThreshold"],replay:!1},cutSoftness:{path:["erosion","cutSoftness"],replay:!1},edgeWidth:{path:["erosion","edgeWidth"],replay:!1},edgeInset:{path:["erosion","edgeInset"],replay:!1},brushSoftness:{path:["erosion","brushSoftness"],replay:!0},brushNoise:{path:["erosion","brushNoise"],replay:!0},crumbleRate:{path:["erosion","crumbleRate"],replay:!0},crumbleCrackBias:{path:["erosion","crumbleCrackBias"],replay:!0},crumbleDuration:{path:["erosion","crumbleDuration"],replay:!0},ejectSpeed:{path:["powder","ejectSpeed"],replay:!0},ejectSpread:{path:["powder","ejectSpread"],replay:!0},ejectTurbulence:{path:["powder","ejectTurbulence"],replay:!0},drag:{path:["powder","drag"],replay:!0},gravity:{path:["powder","gravity"],replay:!0},turbulence:{path:["powder","turbulence"],replay:!0},settleTime:{path:["powder","settleTime"],replay:!0},maxSpeed:{path:["powder","maxSpeed"],replay:!0},minPixelSize:{path:["powder","minPixelSize"],replay:!1},grainSizeMultiplier:{path:["powder","grainSizeMultiplier"],replay:!1},spriteSize:{path:["powder","sprites","sizeScale"],replay:!1},returnSpring:{path:["healing","returnSpring"],replay:!0},returnDamping:{path:["healing","returnDamping"],replay:!0},returnRamp:{path:["healing","returnRamp"],replay:!0},returnMaxSpeed:{path:["healing","returnMaxSpeed"],replay:!0},healRate:{path:["healing","healRate"],replay:!0},cellRestore:{path:["healing","cellRestore"],replay:!0},landedFade:{path:["healing","landedFade"],replay:!0},refrostTime:{path:["healing","refrostTime"],replay:!0}},q2=Object.freeze(Object.fromEntries(Object.entries(Gx).filter(([e,t])=>e.startsWith("material")||["ice","lighting","post"].includes(t.path[0])||["baseTone","wrap","sparkle","sparkleFraction"].includes(e)||e.startsWith("frag")||e.startsWith("sprite")).map(([e])=>[e,Io[e]]))),gf=[-1,.3,0],yf=[1,-.3,0];function Fk(e){return JSON.stringify([e.headlines,{...e.text,meshDetail:f2(e.text.meshDetail)},Nx(e.deformation),e.quality,e.upscaler,e.renderScale,e.shapeResolution??"256",e.erosionResolution,e.particleCount,e.logoUrl,g2(e.logoMeshDetail),e.shards.strayDust,Number(e.tune.spriteSeeThrough??q2.spriteSeeThrough)>0])}function m0e(e){e={...e,logoMeshDetail:g2(e.logoMeshDetail),text:{...e.text,meshDetail:f2(e.text.meshDetail)}};let t=null,r=null,i=!1,s=-1,a=-1,n=0,o=null,l=0,u=null,h=U=>{th.stages.push([U,performance.now()-th.start]),e.onProgress?.(U)},d=e.schedule,c=e.pose,m=e.shards,g=c2(e.cameraTrack),y=()=>e.cameraMode==="authored"&&g.keys.length>0,b=()=>y()&&g.objectMotion==="stationary";function v(){t&&(t.onCameraTransform=y()?U=>{t&&vce(t.camera,g,U,t.objectGroup.matrixWorld,t.rig.lookAt)}:null,y()||(t.camera.zoom=1,t.camera.updateProjectionMatrix()))}let S=Fk(e),T=[],w=[],N=[],C=null,R=-1,E=null,P=(U,J)=>{let q=le;for(let se=0;se{if(await new Promise(Fe=>setTimeout(Fe,250)),i)return;let U=navigator;if(!U.gpu)throw new Error("Frost: navigator.gpu is unavailable (WebGPU required)");if(!await U.gpu.requestAdapter().catch(()=>null))throw new Error("Frost: no WebGPU adapter");h("webgpu adapter"),O();let J=new qX({canvas:e.canvas,antialias:!1,forceWebGL:!1,powerPreference:"high-performance",trackTimestamp:!1});if(await J.init(),J.backend?.isWebGLBackend)throw new Error("Frost: WebGPU backend unavailable, WebGL fallback is not supported");J.toneMapping=eo,J.outputColorSpace=ds,J.shadowMap.enabled=le.lighting.shadow.intensity>0,J.shadowMap.type=Lh,J.setPixelRatio(1),J.setSize(e.width,e.height,!1),r=J,h("renderer");let q=new bg,se=new gs(30,e.width/e.height,.5,80);se.position.set(0,1.2,13.5);let pe=le.shape.logo,Te=le.powder,we={"100k":1e5,"250k":25e4,"500k":5e5,"1M":1e6}[Te.particleCount]??1e5,ie=Nx(e.deformation),V=!!e.rig&&!e.rig.sequence,Oe=JSON.stringify([o0e,V,ie,e.headlines,e.text,e.logoUrl,e.logoMeshDetail,pe,we,Te.nearSurfaceFraction,Te.nearSurfaceDepth,le.shape.seed,le.shape.size]),tt=await new tb().loadAsync(a2("textures/bluenoise64.png")).then(Fe=>(Fe.wrapS=Fe.wrapT=to,Fe.minFilter=Fe.magFilter=or,Fe.generateMipmaps=!1,Fe.colorSpace=Fa,Fe)),Je=await new tb().loadAsync(a2("textures/ice-inclusions-generated.png")).then(Fe=>(Fe.wrapS=Fe.wrapT=Qo,Fe.minFilter=Ia,Fe.magFilter=lr,Fe.generateMipmaps=!0,Fe.colorSpace=Fa,Fe)),ct=0,_e=new URLSearchParams(location.search).has("fresh")?null:await l0e(Oe).catch(()=>null);if(_e&&_e.geometries.length===(V?1:3)&&_e.sdfs.length===(V?1:3)&&_e.rests.length===(V?0:2)){for(let Fe of _e.geometries)T.push(d0e(Fe));for(let Fe of _e.sdfs)w.push(F1(Fe.data,Fe.res,Fe.bound,Fe.thickness,Fe.sampleBound));ct=_e.sdfs[0].bound,h("shapes (cached)")}else{let Fe=e.fontUrl.replace(/Geist-[A-Za-z]+\.ttf$/,`Geist-${e.text.weight===400?"Regular":e.text.weight===600?"SemiBold":"Bold"}.ttf`),[it,Rt]=await Promise.all([Qae(e.logoUrl,pe),V?Promise.resolve(null):r0e(Fe)]);if(i)return;if(!it.length)throw new Error("Frost: the logo SVG produced no shapes");h("assets"),T.push(G5(it,pe,pe.width));let Ft={...pe,depth:e.text.depth,bevelThickness:e.text.bevel,bevelSize:e.text.bevel*.8,bevelOffset:0,cornerRadius:e.text.corner,curveSegments:10,bevelSegments:4};for(let Ze of V?[]:e.headlines){let ht=Ze.map(Gi=>Gi.trim()).filter(Boolean);ht.length||ht.push(" ");let Yt=Math.max(.001,...ht.map(Gi=>i0e(Rt,Gi,e.text.letterSpacing))),Tr=e.text.width/Yt;T.push(G5(s0e(Rt,ht,Tr,e.text.lineHeight,e.text.letterSpacing),Ft,Tr))}for(let Ze=0;ZesetTimeout(Yt,0)),i)return;T[Ze]=Bce(ht,ie,pe.creaseAngle,Ze===0?void 0:e.text.meshDetail,Ze===0?e.logoMeshDetail:void 0),Ze>0&&h(`text mesh ${Ze}/2 \xB7 ${T[Ze].getAttribute("position").count/3} triangles`),await new Promise(Yt=>setTimeout(Yt,0)),T[Ze]!==ht&&ht.dispose()}for(let Ze of T){let ht=Fm(Ze);ct=Math.max(ct,ht.x,ht.y,ht.z)}ct*=1.15;for(let Ze of T){let ht=Fm(Ze),Yt=Math.max(ht.x,ht.y,ht.z)*1.15;w.push(qa.gpu?await nne(J,Ze,ct,pe.sdfRes,Yt):Kae(Ze,ct,pe.sdfRes,Yt)),await new Promise(Tr=>setTimeout(Tr,0))}if(i)return;h("shapes")}C=F1(w[0].data.slice(),w[0].res,ct,w[0].thickness,w[0].sampleDomain.value),hx.extraShell=2*ct/pe.sdfRes*2;let nt=le.shape.size,dt=T.slice();for(let Fe=0;Fe{if(!t)return;if(E){E.pose(Fe);return}let it=Sce(Fe,d,c,R,b());t.motionGroup.quaternion.copy(it.rotation),t.motionGroup.position.copy(it.position),t.objectGroup.quaternion.copy(it.facing)},R=0,v();let ft=t.powder;if(N.push(ft.restInit.slice()),_e&&_e.rests.length===2)for(let Fe of _e.rests){let it=ft.restInit.slice();it.set(Fe.subarray(0,ft.count*4)),N.push(it)}else{for(let Fe=1;FesetTimeout(ht,0))}new URLSearchParams(location.search).has("fresh")||u0e(Oe,{geometries:dt.map(h0e),sdfs:w.map(Fe=>({data:Fe.data,res:Fe.res,bound:Fe.bound,thickness:Fe.thickness,sampleBound:Fe.sampleDomain.value})),rests:N.slice(1).map(Fe=>Fe.slice(0,ft.count*4))}).catch(()=>{})}e.rig&&(E=new Tse(t,{...e.rig,retarget:Fe=>ge(Fe,!0)})),window.__fb={world:t,renderer:J,D:le,sim:pt,clock:ta};for(const Fe of[.25,.5,.75,0])G(Fe*y2(d)),await(async()=>{for(;o;)await o})();h("world")})(),H=p2(d,c);function ue(){H=p2(d,c)}let ne=U=>{let J=H(U);return new si().setFromEuler(new cn(Bt.degToRad(J.pitch),Bt.degToRad(J.yaw),0,"YXZ"))},re=new si;function ce(U){if(U===0||b())return new si;let J=U===1?d.form1+2.8:d.form2+2.8;return ne(J).invert()}function ge(U,J){if(!t||!r||!C)return;let q=w[U];U!==R&&(C.data.set(q.data),C.sampleDomain.value=q.sampleDomain.value,C.sampleBoundNode&&(C.sampleBoundNode.value=q.sampleDomain.value),C.texture.needsUpdate=!0,C.thickness=q.thickness,t.shape=cw("logo",le.shape.size,le.shape.tubeRatio,C),t.mesh.geometry=T[U],R=U),re.copy(e.rig?new si:ce(U)),t.objectGroup.quaternion.copy(re),t.motionGroup.updateMatrixWorld(!0),t.powder.syncModel(),t.erosion.rebake(r,J),t.powder.retarget(r,N[U])}function ye(U=!1){if(!t||!r)return;L(),t.erosion.u.reconstruct.value=0,le.powder.repelFromObject=!0;let J=U?m.finalEjectBoost:1;le.powder.ejectSpeed=Number(e.tune.ejectSpeed)*J,le.powder.maxSpeed=Number(e.tune.maxSpeed)*J,le.powder.minEjectSpeed=.66*J,le.version++,t.powder.restoreThresholds(r),t.interaction.sweep({from:gf,to:yf,duration:.7,radius:m.sliceRadius,strength:m.sliceStrength})}function oe(){if(!t)return;let U=t.shape.bound,J=yf[0]-gf[0],q=yf[1]-gf[1],se=Math.hypot(J,q),pe=-q/se,Te=J/se,we=Math.max(.15,m.shatterRadius*1.7)/U,ie=Math.max(1,Math.ceil(1.25/we)),V=m.breakDuration/(ie*2),Oe=0;for(let tt=1;tt<=ie;tt++)for(let Je of[1,-1]){let ct=Je*tt*we;t.interaction.sweep({from:[gf[0]+pe*ct,gf[1]+Te*ct,0],to:[yf[0]+pe*ct,yf[1]+Te*ct,0],duration:.5,delay:Oe*V,radius:m.shatterRadius,strength:m.shatterStrength}),Oe++}}function Ae(){!t||!r||(r.compute(t.erosion.fillNode),le.powder.repelFromObject=!1,le.version++)}function Ie(U){t&&(t.powder.u.assemblyEnd.value=(U===1?d.break1:d.break2)-.65,ge(U,!0),pt.lastStrokeT=ta.t,X())}function Xe(){t&&(L(),t.mesh.visible=!1,le.healing.resetFade=QF*1e3,pt.resetRequestedAt=ta.t)}function at(){t&&(a=-1,le.powder.repelFromObject=!0,t.resetSim(),t.interaction.clearScripted(),re.identity(),ge(0,!1),e.rig?.sequence&&r&&t.powder.reset(r),L(),le.healing.resetFade=50,Ui.inside=!1,Ui.x=0,Ui.y=0,Ui.lastMoveT=0,Ui.moved=!1,E?.reset(),s=0)}function W(U,J){if(!t)return;let q=U*Ah;if(E){s2(U),t.frame(q,Ah,J);return}ta.t=q;let se=pe=>Math.round(pe/Ah)===U;for(let pe of[d.logoBreak,d.break1,d.break2])se(pe)&&ye(pe===d.break2),se(pe+.3)&&oe(),se(pe+.3+m.breakDuration+.5)&&Ae();se(d.form1)&&Ie(1),se(d.form2)&&Ie(2),se(d.fadeOut)&&Xe(),s2(U),t.frame(q,Ah,J)}async function j(){let U=-1,J=0;for(;!i&&t&&r;){let q=l;(s<0||q60?q-Ik:q,U=q);let se=Math.min(q,s+8);if(q===s&&a!==q){s2(q);let Te=e.rig&&q===0&&a<0?Ik:1;for(let we=0;weJ;W(s,Te),Te&&(a=s)}let pe=r.backend?.device?.queue;if(pe?.onSubmittedWorkDone&&await pe.onSubmittedWorkDone(),i||s===l&&a===l)return;await new Promise(Te=>setTimeout(Te,0))}}function G(U){i||(n=Number.isFinite(U)?Math.max(0,Math.min(e.rig?.duration??y2(d),U)):0,l=Math.round(n/Ah),!(!t||!r||o)&&(u=null,o=Promise.resolve().then(j).catch(J=>{u=J,console.error("Frost seek failed",J)}).finally(()=>{o=null})))}function ae(){a=-1,G(n)}function be(U,J){if(J!==S)return"rebuild";let q=!1,se=(Te,we)=>JSON.stringify(Te)===JSON.stringify(we);(!se(U.schedule,d)||!se(U.pose,c))&&(q=!0);let pe=b();g=c2(U.cameraTrack),e.cameraTrack=g,e.cameraMode=U.cameraMode,pe!==b()&&(q=!0),v(),se(U.shards,m)||(q=!0);for(let[Te,we]of Object.entries(U.tune))if(e.tune[Te]!==we){let ie=Gx[Te];ie&&(P(ie.path,we),ie.replay&&(q=!0))}return e.schedule=d=U.schedule,e.pose=c=U.pose,e.shards=m=U.shards,e.tune={...U.tune},le.powder.amount=m.amount,le.powder.inheritTime=m.followObject*1e3,le.version++,ue(),t&&(q?(s=-1,a=-1,G(n)):ae()),"live"}async function Be(){for(await z;o;)await o;if(u)throw u}function $(){i=!0,t?.dispose(),t=null,E?.dispose();for(let U of w)U.texture.dispose();C?.texture.dispose(),C=null;for(let U of T)U.dispose();r&&(r.dispose(),r=null),Ht.enabled=!1,Ht.shape=null,Ht.cameraOverride=null,delete window.__fb}return{ready:z,renderAt:G,redraw:ae,invalidate:()=>{s=-1,a=-1},waitForGpu:Be,poseAt:U=>H(U),applyOptions:be,structuralKey:S,get world(){return t},get shape(){return R},dispose:$}}return xD(gM)})();