/** * @license * Copyright 2010-2024 Three.js Authors * SPDX-License-Identifier: MIT */ const t="169",e={LEFT:0,MIDDLE:1,RIGHT:2,ROTATE:0,DOLLY:1,PAN:2},n={ROTATE:0,PAN:1,DOLLY_PAN:2,DOLLY_ROTATE:3},i=0,s=1,r=2,a=3,o=0,l=1,c=2,u=3,h=0,d=1,p=2,m=0,f=1,g=2,v=3,y=4,_=5,x=100,M=101,b=102,T=103,S=104,w=200,E=201,A=202,N=203,C=204,R=205,I=206,L=207,P=208,U=209,D=210,O=211,z=212,V=213,F=214,B=0,k=1,H=2,G=3,W=4,j=5,X=6,q=7,Y=0,Z=1,$=2,J=0,K=1,Q=2,tt=3,et=4,nt=5,it=6,st=7,rt="attached",at="detached",ot=300,lt=301,ct=302,ut=303,ht=304,dt=306,pt=1e3,mt=1001,ft=1002,gt=1003,vt=1004,yt=1004,_t=1005,xt=1005,Mt=1006,bt=1007,Tt=1007,St=1008,wt=1008,Et=1009,At=1010,Nt=1011,Ct=1012,Rt=1013,It=1014,Lt=1015,Pt=1016,Ut=1017,Dt=1018,Ot=1020,zt=35902,Vt=1021,Ft=1022,Bt=1023,kt=1024,Ht=1025,Gt=1026,Wt=1027,jt=1028,Xt=1029,qt=1030,Yt=1031,Zt=1032,$t=1033,Jt=33776,Kt=33777,Qt=33778,te=33779,ee=35840,ne=35841,ie=35842,se=35843,re=36196,ae=37492,oe=37496,le=37808,ce=37809,ue=37810,he=37811,de=37812,pe=37813,me=37814,fe=37815,ge=37816,ve=37817,ye=37818,_e=37819,xe=37820,Me=37821,be=36492,Te=36494,Se=36495,we=36283,Ee=36284,Ae=36285,Ne=36286,Ce=2200,Re=2201,Ie=2202,Le=2300,Pe=2301,Ue=2302,De=2400,Oe=2401,ze=2402,Ve=2500,Fe=2501,Be=0,ke=1,He=2,Ge=3200,We=3201,je=3202,Xe=3203,qe=0,Ye=1,Ze="",$e="srgb",Je="srgb-linear",Ke="display-p3",Qe="display-p3-linear",tn="linear",en="srgb",nn="rec709",sn="p3",rn=0,an=7680,on=7681,ln=7682,cn=7683,un=34055,hn=34056,dn=5386,pn=512,mn=513,fn=514,gn=515,vn=516,yn=517,_n=518,xn=519,Mn=512,bn=513,Tn=514,Sn=515,wn=516,En=517,An=518,Nn=519,Cn=35044,Rn=35048,In=35040,Ln=35045,Pn=35049,Un=35041,Dn=35046,On=35050,zn=35042,Vn="100",Fn="300 es",Bn=2e3,kn=2001;class Hn{addEventListener(t,e){void 0===this._listeners&&(this._listeners={});const n=this._listeners;void 0===n[t]&&(n[t]=[]),-1===n[t].indexOf(e)&&n[t].push(e)}hasEventListener(t,e){if(void 0===this._listeners)return!1;const n=this._listeners;return void 0!==n[t]&&-1!==n[t].indexOf(e)}removeEventListener(t,e){if(void 0===this._listeners)return;const n=this._listeners[t];if(void 0!==n){const t=n.indexOf(e);-1!==t&&n.splice(t,1)}}dispatchEvent(t){if(void 0===this._listeners)return;const e=this._listeners[t.type];if(void 0!==e){t.target=this;const n=e.slice(0);for(let e=0,i=n.length;e>8&255]+Gn[t>>16&255]+Gn[t>>24&255]+"-"+Gn[255&e]+Gn[e>>8&255]+"-"+Gn[e>>16&15|64]+Gn[e>>24&255]+"-"+Gn[63&n|128]+Gn[n>>8&255]+"-"+Gn[n>>16&255]+Gn[n>>24&255]+Gn[255&i]+Gn[i>>8&255]+Gn[i>>16&255]+Gn[i>>24&255]).toLowerCase()}function Yn(t,e,n){return Math.max(e,Math.min(n,t))}function Zn(t,e){return(t%e+e)%e}function $n(t,e,n){return(1-n)*t+n*e}function Jn(t,e){switch(e.constructor){case Float32Array:return t;case Uint32Array:return t/4294967295;case Uint16Array:return t/65535;case Uint8Array:return t/255;case Int32Array:return Math.max(t/2147483647,-1);case Int16Array:return Math.max(t/32767,-1);case Int8Array:return Math.max(t/127,-1);default:throw new Error("Invalid component type.")}}function Kn(t,e){switch(e.constructor){case Float32Array:return t;case Uint32Array:return Math.round(4294967295*t);case Uint16Array:return Math.round(65535*t);case Uint8Array:return Math.round(255*t);case Int32Array:return Math.round(2147483647*t);case Int16Array:return Math.round(32767*t);case Int8Array:return Math.round(127*t);default:throw new Error("Invalid component type.")}}const Qn={DEG2RAD:jn,RAD2DEG:Xn,generateUUID:qn,clamp:Yn,euclideanModulo:Zn,mapLinear:function(t,e,n,i,s){return i+(t-e)*(s-i)/(n-e)},inverseLerp:function(t,e,n){return t!==e?(n-t)/(e-t):0},lerp:$n,damp:function(t,e,n,i){return $n(t,e,1-Math.exp(-n*i))},pingpong:function(t,e=1){return e-Math.abs(Zn(t,2*e)-e)},smoothstep:function(t,e,n){return t<=e?0:t>=n?1:(t=(t-e)/(n-e))*t*(3-2*t)},smootherstep:function(t,e,n){return t<=e?0:t>=n?1:(t=(t-e)/(n-e))*t*t*(t*(6*t-15)+10)},randInt:function(t,e){return t+Math.floor(Math.random()*(e-t+1))},randFloat:function(t,e){return t+Math.random()*(e-t)},randFloatSpread:function(t){return t*(.5-Math.random())},seededRandom:function(t){void 0!==t&&(Wn=t);let e=Wn+=1831565813;return e=Math.imul(e^e>>>15,1|e),e^=e+Math.imul(e^e>>>7,61|e),((e^e>>>14)>>>0)/4294967296},degToRad:function(t){return t*jn},radToDeg:function(t){return t*Xn},isPowerOfTwo:function(t){return!(t&t-1)&&0!==t},ceilPowerOfTwo:function(t){return Math.pow(2,Math.ceil(Math.log(t)/Math.LN2))},floorPowerOfTwo:function(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))},setQuaternionFromProperEuler:function(t,e,n,i,s){const r=Math.cos,a=Math.sin,o=r(n/2),l=a(n/2),c=r((e+i)/2),u=a((e+i)/2),h=r((e-i)/2),d=a((e-i)/2),p=r((i-e)/2),m=a((i-e)/2);switch(s){case"XYX":t.set(o*u,l*h,l*d,o*c);break;case"YZY":t.set(l*d,o*u,l*h,o*c);break;case"ZXZ":t.set(l*h,l*d,o*u,o*c);break;case"XZX":t.set(o*u,l*m,l*p,o*c);break;case"YXY":t.set(l*p,o*u,l*m,o*c);break;case"ZYZ":t.set(l*m,l*p,o*u,o*c);break;default:console.warn("THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+s)}},normalize:Kn,denormalize:Jn};class ti{constructor(t=0,e=0){ti.prototype.isVector2=!0,this.x=t,this.y=e}get width(){return this.x}set width(t){this.x=t}get height(){return this.y}set height(t){this.y=t}set(t,e){return this.x=t,this.y=e,this}setScalar(t){return this.x=t,this.y=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;default:throw new Error("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("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y)}copy(t){return this.x=t.x,this.y=t.y,this}add(t){return this.x+=t.x,this.y+=t.y,this}addScalar(t){return this.x+=t,this.y+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this}subScalar(t){return this.x-=t,this.y-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this}multiply(t){return this.x*=t.x,this.y*=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divide(t){return this.x/=t.x,this.y/=t.y,this}divideScalar(t){return this.multiplyScalar(1/t)}applyMatrix3(t){const e=this.x,n=this.y,i=t.elements;return this.x=i[0]*e+i[3]*n+i[6],this.y=i[1]*e+i[4]*n+i[7],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this}clampLength(t,e){const n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(t,Math.min(e,n)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(0===e)return Math.PI/2;const n=this.dot(t)/e;return Math.acos(Yn(n,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,n=this.y-t.y;return e*e+n*n}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this}lerpVectors(t,e,n){return this.x=t.x+(e.x-t.x)*n,this.y=t.y+(e.y-t.y)*n,this}equals(t){return t.x===this.x&&t.y===this.y}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this}rotateAround(t,e){const n=Math.cos(e),i=Math.sin(e),s=this.x-t.x,r=this.y-t.y;return this.x=s*n-r*i+t.x,this.y=s*i+r*n+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class ei{constructor(t,e,n,i,s,r,a,o,l){ei.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],void 0!==t&&this.set(t,e,n,i,s,r,a,o,l)}set(t,e,n,i,s,r,a,o,l){const c=this.elements;return c[0]=t,c[1]=i,c[2]=a,c[3]=e,c[4]=s,c[5]=o,c[6]=n,c[7]=r,c[8]=l,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){const e=this.elements,n=t.elements;return e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=n[3],e[4]=n[4],e[5]=n[5],e[6]=n[6],e[7]=n[7],e[8]=n[8],this}extractBasis(t,e,n){return t.setFromMatrix3Column(this,0),e.setFromMatrix3Column(this,1),n.setFromMatrix3Column(this,2),this}setFromMatrix4(t){const e=t.elements;return this.set(e[0],e[4],e[8],e[1],e[5],e[9],e[2],e[6],e[10]),this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const n=t.elements,i=e.elements,s=this.elements,r=n[0],a=n[3],o=n[6],l=n[1],c=n[4],u=n[7],h=n[2],d=n[5],p=n[8],m=i[0],f=i[3],g=i[6],v=i[1],y=i[4],_=i[7],x=i[2],M=i[5],b=i[8];return s[0]=r*m+a*v+o*x,s[3]=r*f+a*y+o*M,s[6]=r*g+a*_+o*b,s[1]=l*m+c*v+u*x,s[4]=l*f+c*y+u*M,s[7]=l*g+c*_+u*b,s[2]=h*m+d*v+p*x,s[5]=h*f+d*y+p*M,s[8]=h*g+d*_+p*b,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[3]*=t,e[6]*=t,e[1]*=t,e[4]*=t,e[7]*=t,e[2]*=t,e[5]*=t,e[8]*=t,this}determinant(){const t=this.elements,e=t[0],n=t[1],i=t[2],s=t[3],r=t[4],a=t[5],o=t[6],l=t[7],c=t[8];return e*r*c-e*a*l-n*s*c+n*a*o+i*s*l-i*r*o}invert(){const t=this.elements,e=t[0],n=t[1],i=t[2],s=t[3],r=t[4],a=t[5],o=t[6],l=t[7],c=t[8],u=c*r-a*l,h=a*o-c*s,d=l*s-r*o,p=e*u+n*h+i*d;if(0===p)return this.set(0,0,0,0,0,0,0,0,0);const m=1/p;return t[0]=u*m,t[1]=(i*l-c*n)*m,t[2]=(a*n-i*r)*m,t[3]=h*m,t[4]=(c*e-i*o)*m,t[5]=(i*s-a*e)*m,t[6]=d*m,t[7]=(n*o-l*e)*m,t[8]=(r*e-n*s)*m,this}transpose(){let t;const e=this.elements;return t=e[1],e[1]=e[3],e[3]=t,t=e[2],e[2]=e[6],e[6]=t,t=e[5],e[5]=e[7],e[7]=t,this}getNormalMatrix(t){return this.setFromMatrix4(t).invert().transpose()}transposeIntoArray(t){const e=this.elements;return t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8],this}setUvTransform(t,e,n,i,s,r,a){const o=Math.cos(s),l=Math.sin(s);return this.set(n*o,n*l,-n*(o*r+l*a)+r+t,-i*l,i*o,-i*(-l*r+o*a)+a+e,0,0,1),this}scale(t,e){return this.premultiply(ni.makeScale(t,e)),this}rotate(t){return this.premultiply(ni.makeRotation(-t)),this}translate(t,e){return this.premultiply(ni.makeTranslation(t,e)),this}makeTranslation(t,e){return t.isVector2?this.set(1,0,t.x,0,1,t.y,0,0,1):this.set(1,0,t,0,1,e,0,0,1),this}makeRotation(t){const e=Math.cos(t),n=Math.sin(t);return this.set(e,-n,0,n,e,0,0,0,1),this}makeScale(t,e){return this.set(t,0,0,0,e,0,0,0,1),this}equals(t){const e=this.elements,n=t.elements;for(let t=0;t<9;t++)if(e[t]!==n[t])return!1;return!0}fromArray(t,e=0){for(let n=0;n<9;n++)this.elements[n]=t[n+e];return this}toArray(t=[],e=0){const n=this.elements;return t[e]=n[0],t[e+1]=n[1],t[e+2]=n[2],t[e+3]=n[3],t[e+4]=n[4],t[e+5]=n[5],t[e+6]=n[6],t[e+7]=n[7],t[e+8]=n[8],t}clone(){return(new this.constructor).fromArray(this.elements)}}const ni=new ei;function ii(t){for(let e=t.length-1;e>=0;--e)if(t[e]>=65535)return!0;return!1}const si={Int8Array:Int8Array,Uint8Array:Uint8Array,Uint8ClampedArray:Uint8ClampedArray,Int16Array:Int16Array,Uint16Array:Uint16Array,Int32Array:Int32Array,Uint32Array:Uint32Array,Float32Array:Float32Array,Float64Array:Float64Array};function ri(t,e){return new si[t](e)}function ai(t){return document.createElementNS("http://www.w3.org/1999/xhtml",t)}function oi(){const t=ai("canvas");return t.style.display="block",t}const li={};function ci(t){t in li||(li[t]=!0,console.warn(t))}const ui=(new ei).set(.8224621,.177538,0,.0331941,.9668058,0,.0170827,.0723974,.9105199),hi=(new ei).set(1.2249401,-.2249404,0,-.0420569,1.0420571,0,-.0196376,-.0786361,1.0982735),di={[Je]:{transfer:tn,primaries:nn,luminanceCoefficients:[.2126,.7152,.0722],toReference:t=>t,fromReference:t=>t},[$e]:{transfer:en,primaries:nn,luminanceCoefficients:[.2126,.7152,.0722],toReference:t=>t.convertSRGBToLinear(),fromReference:t=>t.convertLinearToSRGB()},[Qe]:{transfer:tn,primaries:sn,luminanceCoefficients:[.2289,.6917,.0793],toReference:t=>t.applyMatrix3(hi),fromReference:t=>t.applyMatrix3(ui)},[Ke]:{transfer:en,primaries:sn,luminanceCoefficients:[.2289,.6917,.0793],toReference:t=>t.convertSRGBToLinear().applyMatrix3(hi),fromReference:t=>t.applyMatrix3(ui).convertLinearToSRGB()}},pi=new Set([Je,Qe]),mi={enabled:!0,_workingColorSpace:Je,get workingColorSpace(){return this._workingColorSpace},set workingColorSpace(t){if(!pi.has(t))throw new Error(`Unsupported working color space, "${t}".`);this._workingColorSpace=t},convert:function(t,e,n){if(!1===this.enabled||e===n||!e||!n)return t;const i=di[e].toReference;return(0,di[n].fromReference)(i(t))},fromWorkingColorSpace:function(t,e){return this.convert(t,this._workingColorSpace,e)},toWorkingColorSpace:function(t,e){return this.convert(t,e,this._workingColorSpace)},getPrimaries:function(t){return di[t].primaries},getTransfer:function(t){return t===Ze?tn:di[t].transfer},getLuminanceCoefficients:function(t,e=this._workingColorSpace){return t.fromArray(di[e].luminanceCoefficients)}};function fi(t){return t<.04045?.0773993808*t:Math.pow(.9478672986*t+.0521327014,2.4)}function gi(t){return t<.0031308?12.92*t:1.055*Math.pow(t,.41666)-.055}let vi;class yi{static getDataURL(t){if(/^data:/i.test(t.src))return t.src;if("undefined"==typeof HTMLCanvasElement)return t.src;let e;if(t instanceof HTMLCanvasElement)e=t;else{void 0===vi&&(vi=ai("canvas")),vi.width=t.width,vi.height=t.height;const n=vi.getContext("2d");t instanceof ImageData?n.putImageData(t,0,0):n.drawImage(t,0,0,t.width,t.height),e=vi}return e.width>2048||e.height>2048?(console.warn("THREE.ImageUtils.getDataURL: Image converted to jpg for performance reasons",t),e.toDataURL("image/jpeg",.6)):e.toDataURL("image/png")}static sRGBToLinear(t){if("undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap){const e=ai("canvas");e.width=t.width,e.height=t.height;const n=e.getContext("2d");n.drawImage(t,0,0,t.width,t.height);const i=n.getImageData(0,0,t.width,t.height),s=i.data;for(let t=0;t0&&(n.userData=this.userData),e||(t.textures[this.uuid]=n),n}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(t){if(this.mapping!==ot)return t;if(t.applyMatrix3(this.matrix),t.x<0||t.x>1)switch(this.wrapS){case pt:t.x=t.x-Math.floor(t.x);break;case mt:t.x=t.x<0?0:1;break;case ft:1===Math.abs(Math.floor(t.x)%2)?t.x=Math.ceil(t.x)-t.x:t.x=t.x-Math.floor(t.x)}if(t.y<0||t.y>1)switch(this.wrapT){case pt:t.y=t.y-Math.floor(t.y);break;case mt:t.y=t.y<0?0:1;break;case ft:1===Math.abs(Math.floor(t.y)%2)?t.y=Math.ceil(t.y)-t.y:t.y=t.y-Math.floor(t.y)}return this.flipY&&(t.y=1-t.y),t}set needsUpdate(t){!0===t&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(t){!0===t&&this.pmremVersion++}}Ti.DEFAULT_IMAGE=null,Ti.DEFAULT_MAPPING=ot,Ti.DEFAULT_ANISOTROPY=4;class Si{constructor(t=0,e=0,n=0,i=1){Si.prototype.isVector4=!0,this.x=t,this.y=e,this.z=n,this.w=i}get width(){return this.z}set width(t){this.z=t}get height(){return this.w}set height(t){this.w=t}set(t,e,n,i){return this.x=t,this.y=e,this.z=n,this.w=i,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this.w=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setW(t){return this.w=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;case 3:this.w=e;break;default:throw new Error("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("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=void 0!==t.w?t.w:1,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this.w+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this.w=t.w+e.w,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this.w+=t.w*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this.w-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this.w=t.w-e.w,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this.w*=t.w,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this}applyMatrix4(t){const e=this.x,n=this.y,i=this.z,s=this.w,r=t.elements;return this.x=r[0]*e+r[4]*n+r[8]*i+r[12]*s,this.y=r[1]*e+r[5]*n+r[9]*i+r[13]*s,this.z=r[2]*e+r[6]*n+r[10]*i+r[14]*s,this.w=r[3]*e+r[7]*n+r[11]*i+r[15]*s,this}divideScalar(t){return this.multiplyScalar(1/t)}setAxisAngleFromQuaternion(t){this.w=2*Math.acos(t.w);const e=Math.sqrt(1-t.w*t.w);return e<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=t.x/e,this.y=t.y/e,this.z=t.z/e),this}setAxisAngleFromRotationMatrix(t){let e,n,i,s;const r=.01,a=.1,o=t.elements,l=o[0],c=o[4],u=o[8],h=o[1],d=o[5],p=o[9],m=o[2],f=o[6],g=o[10];if(Math.abs(c-h)o&&t>v?tv?o=0?1:-1,i=1-e*e;if(i>Number.EPSILON){const s=Math.sqrt(i),r=Math.atan2(s,e*n);t=Math.sin(t*r)/s,a=Math.sin(a*r)/s}const s=a*n;if(o=o*t+h*s,l=l*t+d*s,c=c*t+p*s,u=u*t+m*s,t===1-a){const t=1/Math.sqrt(o*o+l*l+c*c+u*u);o*=t,l*=t,c*=t,u*=t}}t[e]=o,t[e+1]=l,t[e+2]=c,t[e+3]=u}static multiplyQuaternionsFlat(t,e,n,i,s,r){const a=n[i],o=n[i+1],l=n[i+2],c=n[i+3],u=s[r],h=s[r+1],d=s[r+2],p=s[r+3];return t[e]=a*p+c*u+o*d-l*h,t[e+1]=o*p+c*h+l*u-a*d,t[e+2]=l*p+c*d+a*h-o*u,t[e+3]=c*p-a*u-o*h-l*d,t}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get w(){return this._w}set w(t){this._w=t,this._onChangeCallback()}set(t,e,n,i){return this._x=t,this._y=e,this._z=n,this._w=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback(),this}setFromEuler(t,e=!0){const n=t._x,i=t._y,s=t._z,r=t._order,a=Math.cos,o=Math.sin,l=a(n/2),c=a(i/2),u=a(s/2),h=o(n/2),d=o(i/2),p=o(s/2);switch(r){case"XYZ":this._x=h*c*u+l*d*p,this._y=l*d*u-h*c*p,this._z=l*c*p+h*d*u,this._w=l*c*u-h*d*p;break;case"YXZ":this._x=h*c*u+l*d*p,this._y=l*d*u-h*c*p,this._z=l*c*p-h*d*u,this._w=l*c*u+h*d*p;break;case"ZXY":this._x=h*c*u-l*d*p,this._y=l*d*u+h*c*p,this._z=l*c*p+h*d*u,this._w=l*c*u-h*d*p;break;case"ZYX":this._x=h*c*u-l*d*p,this._y=l*d*u+h*c*p,this._z=l*c*p-h*d*u,this._w=l*c*u+h*d*p;break;case"YZX":this._x=h*c*u+l*d*p,this._y=l*d*u+h*c*p,this._z=l*c*p-h*d*u,this._w=l*c*u-h*d*p;break;case"XZY":this._x=h*c*u-l*d*p,this._y=l*d*u-h*c*p,this._z=l*c*p+h*d*u,this._w=l*c*u+h*d*p;break;default:console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: "+r)}return!0===e&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const n=e/2,i=Math.sin(n);return this._x=t.x*i,this._y=t.y*i,this._z=t.z*i,this._w=Math.cos(n),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,n=e[0],i=e[4],s=e[8],r=e[1],a=e[5],o=e[9],l=e[2],c=e[6],u=e[10],h=n+a+u;if(h>0){const t=.5/Math.sqrt(h+1);this._w=.25/t,this._x=(c-o)*t,this._y=(s-l)*t,this._z=(r-i)*t}else if(n>a&&n>u){const t=2*Math.sqrt(1+n-a-u);this._w=(c-o)/t,this._x=.25*t,this._y=(i+r)/t,this._z=(s+l)/t}else if(a>u){const t=2*Math.sqrt(1+a-n-u);this._w=(s-l)/t,this._x=(i+r)/t,this._y=.25*t,this._z=(o+c)/t}else{const t=2*Math.sqrt(1+u-n-a);this._w=(r-i)/t,this._x=(s+l)/t,this._y=(o+c)/t,this._z=.25*t}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let n=t.dot(e)+1;return nMath.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=n):(this._x=0,this._y=-t.z,this._z=t.y,this._w=n)):(this._x=t.y*e.z-t.z*e.y,this._y=t.z*e.x-t.x*e.z,this._z=t.x*e.y-t.y*e.x,this._w=n),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(Yn(this.dot(t),-1,1)))}rotateTowards(t,e){const n=this.angleTo(t);if(0===n)return this;const i=Math.min(1,e/n);return this.slerp(t,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(t){return this._x*t._x+this._y*t._y+this._z*t._z+this._w*t._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let t=this.length();return 0===t?(this._x=0,this._y=0,this._z=0,this._w=1):(t=1/t,this._x=this._x*t,this._y=this._y*t,this._z=this._z*t,this._w=this._w*t),this._onChangeCallback(),this}multiply(t){return this.multiplyQuaternions(this,t)}premultiply(t){return this.multiplyQuaternions(t,this)}multiplyQuaternions(t,e){const n=t._x,i=t._y,s=t._z,r=t._w,a=e._x,o=e._y,l=e._z,c=e._w;return this._x=n*c+r*a+i*l-s*o,this._y=i*c+r*o+s*a-n*l,this._z=s*c+r*l+n*o-i*a,this._w=r*c-n*a-i*o-s*l,this._onChangeCallback(),this}slerp(t,e){if(0===e)return this;if(1===e)return this.copy(t);const n=this._x,i=this._y,s=this._z,r=this._w;let a=r*t._w+n*t._x+i*t._y+s*t._z;if(a<0?(this._w=-t._w,this._x=-t._x,this._y=-t._y,this._z=-t._z,a=-a):this.copy(t),a>=1)return this._w=r,this._x=n,this._y=i,this._z=s,this;const o=1-a*a;if(o<=Number.EPSILON){const t=1-e;return this._w=t*r+e*this._w,this._x=t*n+e*this._x,this._y=t*i+e*this._y,this._z=t*s+e*this._z,this.normalize(),this}const l=Math.sqrt(o),c=Math.atan2(l,a),u=Math.sin((1-e)*c)/l,h=Math.sin(e*c)/l;return this._w=r*u+this._w*h,this._x=n*u+this._x*h,this._y=i*u+this._y*h,this._z=s*u+this._z*h,this._onChangeCallback(),this}slerpQuaternions(t,e,n){return this.copy(t).slerp(e,n)}random(){const t=2*Math.PI*Math.random(),e=2*Math.PI*Math.random(),n=Math.random(),i=Math.sqrt(1-n),s=Math.sqrt(n);return this.set(i*Math.sin(t),i*Math.cos(t),s*Math.sin(e),s*Math.cos(e))}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._w===this._w}fromArray(t,e=0){return this._x=t[e],this._y=t[e+1],this._z=t[e+2],this._w=t[e+3],this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._w,t}fromBufferAttribute(t,e){return this._x=t.getX(e),this._y=t.getY(e),this._z=t.getZ(e),this._w=t.getW(e),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class Li{constructor(t=0,e=0,n=0){Li.prototype.isVector3=!0,this.x=t,this.y=e,this.z=n}set(t,e,n){return void 0===n&&(n=this.z),this.x=t,this.y=e,this.z=n,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;default:throw new Error("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("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}multiplyVectors(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this.z=t.z*e.z,this}applyEuler(t){return this.applyQuaternion(Ui.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(Ui.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,n=this.y,i=this.z,s=t.elements;return this.x=s[0]*e+s[3]*n+s[6]*i,this.y=s[1]*e+s[4]*n+s[7]*i,this.z=s[2]*e+s[5]*n+s[8]*i,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,n=this.y,i=this.z,s=t.elements,r=1/(s[3]*e+s[7]*n+s[11]*i+s[15]);return this.x=(s[0]*e+s[4]*n+s[8]*i+s[12])*r,this.y=(s[1]*e+s[5]*n+s[9]*i+s[13])*r,this.z=(s[2]*e+s[6]*n+s[10]*i+s[14])*r,this}applyQuaternion(t){const e=this.x,n=this.y,i=this.z,s=t.x,r=t.y,a=t.z,o=t.w,l=2*(r*i-a*n),c=2*(a*e-s*i),u=2*(s*n-r*e);return this.x=e+o*l+r*u-a*c,this.y=n+o*c+a*l-s*u,this.z=i+o*u+s*c-r*l,this}project(t){return this.applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix)}unproject(t){return this.applyMatrix4(t.projectionMatrixInverse).applyMatrix4(t.matrixWorld)}transformDirection(t){const e=this.x,n=this.y,i=this.z,s=t.elements;return this.x=s[0]*e+s[4]*n+s[8]*i,this.y=s[1]*e+s[5]*n+s[9]*i,this.z=s[2]*e+s[6]*n+s[10]*i,this.normalize()}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this}divideScalar(t){return this.multiplyScalar(1/t)}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this.z=Math.max(t.z,Math.min(e.z,this.z)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this.z=Math.max(t,Math.min(e,this.z)),this}clampLength(t,e){const n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(t,Math.min(e,n)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this}lerpVectors(t,e,n){return this.x=t.x+(e.x-t.x)*n,this.y=t.y+(e.y-t.y)*n,this.z=t.z+(e.z-t.z)*n,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){const n=t.x,i=t.y,s=t.z,r=e.x,a=e.y,o=e.z;return this.x=i*o-s*a,this.y=s*r-n*o,this.z=n*a-i*r,this}projectOnVector(t){const e=t.lengthSq();if(0===e)return this.set(0,0,0);const n=t.dot(this)/e;return this.copy(t).multiplyScalar(n)}projectOnPlane(t){return Pi.copy(this).projectOnVector(t),this.sub(Pi)}reflect(t){return this.sub(Pi.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(0===e)return Math.PI/2;const n=this.dot(t)/e;return Math.acos(Yn(n,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,n=this.y-t.y,i=this.z-t.z;return e*e+n*n+i*i}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)}setFromSpherical(t){return this.setFromSphericalCoords(t.radius,t.phi,t.theta)}setFromSphericalCoords(t,e,n){const i=Math.sin(e)*t;return this.x=i*Math.sin(n),this.y=Math.cos(e)*t,this.z=i*Math.cos(n),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,n){return this.x=t*Math.sin(e),this.y=n,this.z=t*Math.cos(e),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this}setFromMatrixScale(t){const e=this.setFromMatrixColumn(t,0).length(),n=this.setFromMatrixColumn(t,1).length(),i=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=n,this.z=i,this}setFromMatrixColumn(t,e){return this.fromArray(t.elements,4*e)}setFromMatrix3Column(t,e){return this.fromArray(t.elements,3*e)}setFromEuler(t){return this.x=t._x,this.y=t._y,this.z=t._z,this}setFromColor(t){return this.x=t.r,this.y=t.g,this.z=t.b,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const t=Math.random()*Math.PI*2,e=2*Math.random()-1,n=Math.sqrt(1-e*e);return this.x=n*Math.cos(t),this.y=e,this.z=n*Math.sin(t),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const Pi=new Li,Ui=new Ii;class Di{constructor(t=new Li(1/0,1/0,1/0),e=new Li(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=t,this.max=e}set(t,e){return this.min.copy(t),this.max.copy(e),this}setFromArray(t){this.makeEmpty();for(let e=0,n=t.length;e=this.min.x&&t.x<=this.max.x&&t.y>=this.min.y&&t.y<=this.max.y&&t.z>=this.min.z&&t.z<=this.max.z}containsBox(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y&&this.min.z<=t.min.z&&t.max.z<=this.max.z}getParameter(t,e){return e.set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y),(t.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(t){return t.max.x>=this.min.x&&t.min.x<=this.max.x&&t.max.y>=this.min.y&&t.min.y<=this.max.y&&t.max.z>=this.min.z&&t.min.z<=this.max.z}intersectsSphere(t){return this.clampPoint(t.center,zi),zi.distanceToSquared(t.center)<=t.radius*t.radius}intersectsPlane(t){let e,n;return t.normal.x>0?(e=t.normal.x*this.min.x,n=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,n=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,n+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,n+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,n+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,n+=t.normal.z*this.min.z),e<=-t.constant&&n>=-t.constant}intersectsTriangle(t){if(this.isEmpty())return!1;this.getCenter(ji),Xi.subVectors(this.max,ji),Fi.subVectors(t.a,ji),Bi.subVectors(t.b,ji),ki.subVectors(t.c,ji),Hi.subVectors(Bi,Fi),Gi.subVectors(ki,Bi),Wi.subVectors(Fi,ki);let e=[0,-Hi.z,Hi.y,0,-Gi.z,Gi.y,0,-Wi.z,Wi.y,Hi.z,0,-Hi.x,Gi.z,0,-Gi.x,Wi.z,0,-Wi.x,-Hi.y,Hi.x,0,-Gi.y,Gi.x,0,-Wi.y,Wi.x,0];return!!Zi(e,Fi,Bi,ki,Xi)&&(e=[1,0,0,0,1,0,0,0,1],!!Zi(e,Fi,Bi,ki,Xi)&&(qi.crossVectors(Hi,Gi),e=[qi.x,qi.y,qi.z],Zi(e,Fi,Bi,ki,Xi)))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,zi).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=.5*this.getSize(zi).length()),t}intersect(t){return this.min.max(t.min),this.max.min(t.max),this.isEmpty()&&this.makeEmpty(),this}union(t){return this.min.min(t.min),this.max.max(t.max),this}applyMatrix4(t){return this.isEmpty()||(Oi[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),Oi[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),Oi[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),Oi[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),Oi[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),Oi[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),Oi[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),Oi[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(Oi)),this}translate(t){return this.min.add(t),this.max.add(t),this}equals(t){return t.min.equals(this.min)&&t.max.equals(this.max)}}const Oi=[new Li,new Li,new Li,new Li,new Li,new Li,new Li,new Li],zi=new Li,Vi=new Di,Fi=new Li,Bi=new Li,ki=new Li,Hi=new Li,Gi=new Li,Wi=new Li,ji=new Li,Xi=new Li,qi=new Li,Yi=new Li;function Zi(t,e,n,i,s){for(let r=0,a=t.length-3;r<=a;r+=3){Yi.fromArray(t,r);const a=s.x*Math.abs(Yi.x)+s.y*Math.abs(Yi.y)+s.z*Math.abs(Yi.z),o=e.dot(Yi),l=n.dot(Yi),c=i.dot(Yi);if(Math.max(-Math.max(o,l,c),Math.min(o,l,c))>a)return!1}return!0}const $i=new Di,Ji=new Li,Ki=new Li;class Qi{constructor(t=new Li,e=-1){this.isSphere=!0,this.center=t,this.radius=e}set(t,e){return this.center.copy(t),this.radius=e,this}setFromPoints(t,e){const n=this.center;void 0!==e?n.copy(e):$i.setFromPoints(t).getCenter(n);let i=0;for(let e=0,s=t.length;ethis.radius*this.radius&&(e.sub(this.center).normalize(),e.multiplyScalar(this.radius).add(this.center)),e}getBoundingBox(t){return this.isEmpty()?(t.makeEmpty(),t):(t.set(this.center,this.center),t.expandByScalar(this.radius),t)}applyMatrix4(t){return this.center.applyMatrix4(t),this.radius=this.radius*t.getMaxScaleOnAxis(),this}translate(t){return this.center.add(t),this}expandByPoint(t){if(this.isEmpty())return this.center.copy(t),this.radius=0,this;Ji.subVectors(t,this.center);const e=Ji.lengthSq();if(e>this.radius*this.radius){const t=Math.sqrt(e),n=.5*(t-this.radius);this.center.addScaledVector(Ji,n/t),this.radius+=n}return this}union(t){return t.isEmpty()?this:this.isEmpty()?(this.copy(t),this):(!0===this.center.equals(t.center)?this.radius=Math.max(this.radius,t.radius):(Ki.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint(Ji.copy(t.center).add(Ki)),this.expandByPoint(Ji.copy(t.center).sub(Ki))),this)}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return(new this.constructor).copy(this)}}const ts=new Li,es=new Li,ns=new Li,is=new Li,ss=new Li,rs=new Li,as=new Li;class os{constructor(t=new Li,e=new Li(0,0,-1)){this.origin=t,this.direction=e}set(t,e){return this.origin.copy(t),this.direction.copy(e),this}copy(t){return this.origin.copy(t.origin),this.direction.copy(t.direction),this}at(t,e){return e.copy(this.origin).addScaledVector(this.direction,t)}lookAt(t){return this.direction.copy(t).sub(this.origin).normalize(),this}recast(t){return this.origin.copy(this.at(t,ts)),this}closestPointToPoint(t,e){e.subVectors(t,this.origin);const n=e.dot(this.direction);return n<0?e.copy(this.origin):e.copy(this.origin).addScaledVector(this.direction,n)}distanceToPoint(t){return Math.sqrt(this.distanceSqToPoint(t))}distanceSqToPoint(t){const e=ts.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):(ts.copy(this.origin).addScaledVector(this.direction,e),ts.distanceToSquared(t))}distanceSqToSegment(t,e,n,i){es.copy(t).add(e).multiplyScalar(.5),ns.copy(e).sub(t).normalize(),is.copy(this.origin).sub(es);const s=.5*t.distanceTo(e),r=-this.direction.dot(ns),a=is.dot(this.direction),o=-is.dot(ns),l=is.lengthSq(),c=Math.abs(1-r*r);let u,h,d,p;if(c>0)if(u=r*o-a,h=r*a-o,p=s*c,u>=0)if(h>=-p)if(h<=p){const t=1/c;u*=t,h*=t,d=u*(u+r*h+2*a)+h*(r*u+h+2*o)+l}else h=s,u=Math.max(0,-(r*h+a)),d=-u*u+h*(h+2*o)+l;else h=-s,u=Math.max(0,-(r*h+a)),d=-u*u+h*(h+2*o)+l;else h<=-p?(u=Math.max(0,-(-r*s+a)),h=u>0?-s:Math.min(Math.max(-s,-o),s),d=-u*u+h*(h+2*o)+l):h<=p?(u=0,h=Math.min(Math.max(-s,-o),s),d=h*(h+2*o)+l):(u=Math.max(0,-(r*s+a)),h=u>0?s:Math.min(Math.max(-s,-o),s),d=-u*u+h*(h+2*o)+l);else h=r>0?-s:s,u=Math.max(0,-(r*h+a)),d=-u*u+h*(h+2*o)+l;return n&&n.copy(this.origin).addScaledVector(this.direction,u),i&&i.copy(es).addScaledVector(ns,h),d}intersectSphere(t,e){ts.subVectors(t.center,this.origin);const n=ts.dot(this.direction),i=ts.dot(ts)-n*n,s=t.radius*t.radius;if(i>s)return null;const r=Math.sqrt(s-i),a=n-r,o=n+r;return o<0?null:a<0?this.at(o,e):this.at(a,e)}intersectsSphere(t){return this.distanceSqToPoint(t.center)<=t.radius*t.radius}distanceToPlane(t){const e=t.normal.dot(this.direction);if(0===e)return 0===t.distanceToPoint(this.origin)?0:null;const n=-(this.origin.dot(t.normal)+t.constant)/e;return n>=0?n:null}intersectPlane(t,e){const n=this.distanceToPlane(t);return null===n?null:this.at(n,e)}intersectsPlane(t){const e=t.distanceToPoint(this.origin);if(0===e)return!0;return t.normal.dot(this.direction)*e<0}intersectBox(t,e){let n,i,s,r,a,o;const l=1/this.direction.x,c=1/this.direction.y,u=1/this.direction.z,h=this.origin;return l>=0?(n=(t.min.x-h.x)*l,i=(t.max.x-h.x)*l):(n=(t.max.x-h.x)*l,i=(t.min.x-h.x)*l),c>=0?(s=(t.min.y-h.y)*c,r=(t.max.y-h.y)*c):(s=(t.max.y-h.y)*c,r=(t.min.y-h.y)*c),n>r||s>i?null:((s>n||isNaN(n))&&(n=s),(r=0?(a=(t.min.z-h.z)*u,o=(t.max.z-h.z)*u):(a=(t.max.z-h.z)*u,o=(t.min.z-h.z)*u),n>o||a>i?null:((a>n||n!=n)&&(n=a),(o=0?n:i,e)))}intersectsBox(t){return null!==this.intersectBox(t,ts)}intersectTriangle(t,e,n,i,s){ss.subVectors(e,t),rs.subVectors(n,t),as.crossVectors(ss,rs);let r,a=this.direction.dot(as);if(a>0){if(i)return null;r=1}else{if(!(a<0))return null;r=-1,a=-a}is.subVectors(this.origin,t);const o=r*this.direction.dot(rs.crossVectors(is,rs));if(o<0)return null;const l=r*this.direction.dot(ss.cross(is));if(l<0)return null;if(o+l>a)return null;const c=-r*is.dot(as);return c<0?null:this.at(c/a,s)}applyMatrix4(t){return this.origin.applyMatrix4(t),this.direction.transformDirection(t),this}equals(t){return t.origin.equals(this.origin)&&t.direction.equals(this.direction)}clone(){return(new this.constructor).copy(this)}}class ls{constructor(t,e,n,i,s,r,a,o,l,c,u,h,d,p,m,f){ls.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],void 0!==t&&this.set(t,e,n,i,s,r,a,o,l,c,u,h,d,p,m,f)}set(t,e,n,i,s,r,a,o,l,c,u,h,d,p,m,f){const g=this.elements;return g[0]=t,g[4]=e,g[8]=n,g[12]=i,g[1]=s,g[5]=r,g[9]=a,g[13]=o,g[2]=l,g[6]=c,g[10]=u,g[14]=h,g[3]=d,g[7]=p,g[11]=m,g[15]=f,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 ls).fromArray(this.elements)}copy(t){const e=this.elements,n=t.elements;return e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=n[3],e[4]=n[4],e[5]=n[5],e[6]=n[6],e[7]=n[7],e[8]=n[8],e[9]=n[9],e[10]=n[10],e[11]=n[11],e[12]=n[12],e[13]=n[13],e[14]=n[14],e[15]=n[15],this}copyPosition(t){const e=this.elements,n=t.elements;return e[12]=n[12],e[13]=n[13],e[14]=n[14],this}setFromMatrix3(t){const e=t.elements;return this.set(e[0],e[3],e[6],0,e[1],e[4],e[7],0,e[2],e[5],e[8],0,0,0,0,1),this}extractBasis(t,e,n){return t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),n.setFromMatrixColumn(this,2),this}makeBasis(t,e,n){return this.set(t.x,e.x,n.x,0,t.y,e.y,n.y,0,t.z,e.z,n.z,0,0,0,0,1),this}extractRotation(t){const e=this.elements,n=t.elements,i=1/cs.setFromMatrixColumn(t,0).length(),s=1/cs.setFromMatrixColumn(t,1).length(),r=1/cs.setFromMatrixColumn(t,2).length();return e[0]=n[0]*i,e[1]=n[1]*i,e[2]=n[2]*i,e[3]=0,e[4]=n[4]*s,e[5]=n[5]*s,e[6]=n[6]*s,e[7]=0,e[8]=n[8]*r,e[9]=n[9]*r,e[10]=n[10]*r,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){const e=this.elements,n=t.x,i=t.y,s=t.z,r=Math.cos(n),a=Math.sin(n),o=Math.cos(i),l=Math.sin(i),c=Math.cos(s),u=Math.sin(s);if("XYZ"===t.order){const t=r*c,n=r*u,i=a*c,s=a*u;e[0]=o*c,e[4]=-o*u,e[8]=l,e[1]=n+i*l,e[5]=t-s*l,e[9]=-a*o,e[2]=s-t*l,e[6]=i+n*l,e[10]=r*o}else if("YXZ"===t.order){const t=o*c,n=o*u,i=l*c,s=l*u;e[0]=t+s*a,e[4]=i*a-n,e[8]=r*l,e[1]=r*u,e[5]=r*c,e[9]=-a,e[2]=n*a-i,e[6]=s+t*a,e[10]=r*o}else if("ZXY"===t.order){const t=o*c,n=o*u,i=l*c,s=l*u;e[0]=t-s*a,e[4]=-r*u,e[8]=i+n*a,e[1]=n+i*a,e[5]=r*c,e[9]=s-t*a,e[2]=-r*l,e[6]=a,e[10]=r*o}else if("ZYX"===t.order){const t=r*c,n=r*u,i=a*c,s=a*u;e[0]=o*c,e[4]=i*l-n,e[8]=t*l+s,e[1]=o*u,e[5]=s*l+t,e[9]=n*l-i,e[2]=-l,e[6]=a*o,e[10]=r*o}else if("YZX"===t.order){const t=r*o,n=r*l,i=a*o,s=a*l;e[0]=o*c,e[4]=s-t*u,e[8]=i*u+n,e[1]=u,e[5]=r*c,e[9]=-a*c,e[2]=-l*c,e[6]=n*u+i,e[10]=t-s*u}else if("XZY"===t.order){const t=r*o,n=r*l,i=a*o,s=a*l;e[0]=o*c,e[4]=-u,e[8]=l*c,e[1]=t*u+s,e[5]=r*c,e[9]=n*u-i,e[2]=i*u-n,e[6]=a*c,e[10]=s*u+t}return e[3]=0,e[7]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromQuaternion(t){return this.compose(hs,t,ds)}lookAt(t,e,n){const i=this.elements;return fs.subVectors(t,e),0===fs.lengthSq()&&(fs.z=1),fs.normalize(),ps.crossVectors(n,fs),0===ps.lengthSq()&&(1===Math.abs(n.z)?fs.x+=1e-4:fs.z+=1e-4,fs.normalize(),ps.crossVectors(n,fs)),ps.normalize(),ms.crossVectors(fs,ps),i[0]=ps.x,i[4]=ms.x,i[8]=fs.x,i[1]=ps.y,i[5]=ms.y,i[9]=fs.y,i[2]=ps.z,i[6]=ms.z,i[10]=fs.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const n=t.elements,i=e.elements,s=this.elements,r=n[0],a=n[4],o=n[8],l=n[12],c=n[1],u=n[5],h=n[9],d=n[13],p=n[2],m=n[6],f=n[10],g=n[14],v=n[3],y=n[7],_=n[11],x=n[15],M=i[0],b=i[4],T=i[8],S=i[12],w=i[1],E=i[5],A=i[9],N=i[13],C=i[2],R=i[6],I=i[10],L=i[14],P=i[3],U=i[7],D=i[11],O=i[15];return s[0]=r*M+a*w+o*C+l*P,s[4]=r*b+a*E+o*R+l*U,s[8]=r*T+a*A+o*I+l*D,s[12]=r*S+a*N+o*L+l*O,s[1]=c*M+u*w+h*C+d*P,s[5]=c*b+u*E+h*R+d*U,s[9]=c*T+u*A+h*I+d*D,s[13]=c*S+u*N+h*L+d*O,s[2]=p*M+m*w+f*C+g*P,s[6]=p*b+m*E+f*R+g*U,s[10]=p*T+m*A+f*I+g*D,s[14]=p*S+m*N+f*L+g*O,s[3]=v*M+y*w+_*C+x*P,s[7]=v*b+y*E+_*R+x*U,s[11]=v*T+y*A+_*I+x*D,s[15]=v*S+y*N+_*L+x*O,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[4]*=t,e[8]*=t,e[12]*=t,e[1]*=t,e[5]*=t,e[9]*=t,e[13]*=t,e[2]*=t,e[6]*=t,e[10]*=t,e[14]*=t,e[3]*=t,e[7]*=t,e[11]*=t,e[15]*=t,this}determinant(){const t=this.elements,e=t[0],n=t[4],i=t[8],s=t[12],r=t[1],a=t[5],o=t[9],l=t[13],c=t[2],u=t[6],h=t[10],d=t[14];return t[3]*(+s*o*u-i*l*u-s*a*h+n*l*h+i*a*d-n*o*d)+t[7]*(+e*o*d-e*l*h+s*r*h-i*r*d+i*l*c-s*o*c)+t[11]*(+e*l*u-e*a*d-s*r*u+n*r*d+s*a*c-n*l*c)+t[15]*(-i*a*c-e*o*u+e*a*h+i*r*u-n*r*h+n*o*c)}transpose(){const t=this.elements;let e;return e=t[1],t[1]=t[4],t[4]=e,e=t[2],t[2]=t[8],t[8]=e,e=t[6],t[6]=t[9],t[9]=e,e=t[3],t[3]=t[12],t[12]=e,e=t[7],t[7]=t[13],t[13]=e,e=t[11],t[11]=t[14],t[14]=e,this}setPosition(t,e,n){const i=this.elements;return t.isVector3?(i[12]=t.x,i[13]=t.y,i[14]=t.z):(i[12]=t,i[13]=e,i[14]=n),this}invert(){const t=this.elements,e=t[0],n=t[1],i=t[2],s=t[3],r=t[4],a=t[5],o=t[6],l=t[7],c=t[8],u=t[9],h=t[10],d=t[11],p=t[12],m=t[13],f=t[14],g=t[15],v=u*f*l-m*h*l+m*o*d-a*f*d-u*o*g+a*h*g,y=p*h*l-c*f*l-p*o*d+r*f*d+c*o*g-r*h*g,_=c*m*l-p*u*l+p*a*d-r*m*d-c*a*g+r*u*g,x=p*u*o-c*m*o-p*a*h+r*m*h+c*a*f-r*u*f,M=e*v+n*y+i*_+s*x;if(0===M)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const b=1/M;return t[0]=v*b,t[1]=(m*h*s-u*f*s-m*i*d+n*f*d+u*i*g-n*h*g)*b,t[2]=(a*f*s-m*o*s+m*i*l-n*f*l-a*i*g+n*o*g)*b,t[3]=(u*o*s-a*h*s-u*i*l+n*h*l+a*i*d-n*o*d)*b,t[4]=y*b,t[5]=(c*f*s-p*h*s+p*i*d-e*f*d-c*i*g+e*h*g)*b,t[6]=(p*o*s-r*f*s-p*i*l+e*f*l+r*i*g-e*o*g)*b,t[7]=(r*h*s-c*o*s+c*i*l-e*h*l-r*i*d+e*o*d)*b,t[8]=_*b,t[9]=(p*u*s-c*m*s-p*n*d+e*m*d+c*n*g-e*u*g)*b,t[10]=(r*m*s-p*a*s+p*n*l-e*m*l-r*n*g+e*a*g)*b,t[11]=(c*a*s-r*u*s-c*n*l+e*u*l+r*n*d-e*a*d)*b,t[12]=x*b,t[13]=(c*m*i-p*u*i+p*n*h-e*m*h-c*n*f+e*u*f)*b,t[14]=(p*a*i-r*m*i-p*n*o+e*m*o+r*n*f-e*a*f)*b,t[15]=(r*u*i-c*a*i+c*n*o-e*u*o-r*n*h+e*a*h)*b,this}scale(t){const e=this.elements,n=t.x,i=t.y,s=t.z;return e[0]*=n,e[4]*=i,e[8]*=s,e[1]*=n,e[5]*=i,e[9]*=s,e[2]*=n,e[6]*=i,e[10]*=s,e[3]*=n,e[7]*=i,e[11]*=s,this}getMaxScaleOnAxis(){const t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],n=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],i=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,n,i))}makeTranslation(t,e,n){return t.isVector3?this.set(1,0,0,t.x,0,1,0,t.y,0,0,1,t.z,0,0,0,1):this.set(1,0,0,t,0,1,0,e,0,0,1,n,0,0,0,1),this}makeRotationX(t){const e=Math.cos(t),n=Math.sin(t);return this.set(1,0,0,0,0,e,-n,0,0,n,e,0,0,0,0,1),this}makeRotationY(t){const e=Math.cos(t),n=Math.sin(t);return this.set(e,0,n,0,0,1,0,0,-n,0,e,0,0,0,0,1),this}makeRotationZ(t){const e=Math.cos(t),n=Math.sin(t);return this.set(e,-n,0,0,n,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){const n=Math.cos(e),i=Math.sin(e),s=1-n,r=t.x,a=t.y,o=t.z,l=s*r,c=s*a;return this.set(l*r+n,l*a-i*o,l*o+i*a,0,l*a+i*o,c*a+n,c*o-i*r,0,l*o-i*a,c*o+i*r,s*o*o+n,0,0,0,0,1),this}makeScale(t,e,n){return this.set(t,0,0,0,0,e,0,0,0,0,n,0,0,0,0,1),this}makeShear(t,e,n,i,s,r){return this.set(1,n,s,0,t,1,r,0,e,i,1,0,0,0,0,1),this}compose(t,e,n){const i=this.elements,s=e._x,r=e._y,a=e._z,o=e._w,l=s+s,c=r+r,u=a+a,h=s*l,d=s*c,p=s*u,m=r*c,f=r*u,g=a*u,v=o*l,y=o*c,_=o*u,x=n.x,M=n.y,b=n.z;return i[0]=(1-(m+g))*x,i[1]=(d+_)*x,i[2]=(p-y)*x,i[3]=0,i[4]=(d-_)*M,i[5]=(1-(h+g))*M,i[6]=(f+v)*M,i[7]=0,i[8]=(p+y)*b,i[9]=(f-v)*b,i[10]=(1-(h+m))*b,i[11]=0,i[12]=t.x,i[13]=t.y,i[14]=t.z,i[15]=1,this}decompose(t,e,n){const i=this.elements;let s=cs.set(i[0],i[1],i[2]).length();const r=cs.set(i[4],i[5],i[6]).length(),a=cs.set(i[8],i[9],i[10]).length();this.determinant()<0&&(s=-s),t.x=i[12],t.y=i[13],t.z=i[14],us.copy(this);const o=1/s,l=1/r,c=1/a;return us.elements[0]*=o,us.elements[1]*=o,us.elements[2]*=o,us.elements[4]*=l,us.elements[5]*=l,us.elements[6]*=l,us.elements[8]*=c,us.elements[9]*=c,us.elements[10]*=c,e.setFromRotationMatrix(us),n.x=s,n.y=r,n.z=a,this}makePerspective(t,e,n,i,s,r,a=2e3){const o=this.elements,l=2*s/(e-t),c=2*s/(n-i),u=(e+t)/(e-t),h=(n+i)/(n-i);let d,p;if(a===Bn)d=-(r+s)/(r-s),p=-2*r*s/(r-s);else{if(a!==kn)throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+a);d=-r/(r-s),p=-r*s/(r-s)}return o[0]=l,o[4]=0,o[8]=u,o[12]=0,o[1]=0,o[5]=c,o[9]=h,o[13]=0,o[2]=0,o[6]=0,o[10]=d,o[14]=p,o[3]=0,o[7]=0,o[11]=-1,o[15]=0,this}makeOrthographic(t,e,n,i,s,r,a=2e3){const o=this.elements,l=1/(e-t),c=1/(n-i),u=1/(r-s),h=(e+t)*l,d=(n+i)*c;let p,m;if(a===Bn)p=(r+s)*u,m=-2*u;else{if(a!==kn)throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+a);p=s*u,m=-1*u}return o[0]=2*l,o[4]=0,o[8]=0,o[12]=-h,o[1]=0,o[5]=2*c,o[9]=0,o[13]=-d,o[2]=0,o[6]=0,o[10]=m,o[14]=-p,o[3]=0,o[7]=0,o[11]=0,o[15]=1,this}equals(t){const e=this.elements,n=t.elements;for(let t=0;t<16;t++)if(e[t]!==n[t])return!1;return!0}fromArray(t,e=0){for(let n=0;n<16;n++)this.elements[n]=t[n+e];return this}toArray(t=[],e=0){const n=this.elements;return t[e]=n[0],t[e+1]=n[1],t[e+2]=n[2],t[e+3]=n[3],t[e+4]=n[4],t[e+5]=n[5],t[e+6]=n[6],t[e+7]=n[7],t[e+8]=n[8],t[e+9]=n[9],t[e+10]=n[10],t[e+11]=n[11],t[e+12]=n[12],t[e+13]=n[13],t[e+14]=n[14],t[e+15]=n[15],t}}const cs=new Li,us=new ls,hs=new Li(0,0,0),ds=new Li(1,1,1),ps=new Li,ms=new Li,fs=new Li,gs=new ls,vs=new Ii;class ys{constructor(t=0,e=0,n=0,i=ys.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=e,this._z=n,this._order=i}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get order(){return this._order}set order(t){this._order=t,this._onChangeCallback()}set(t,e,n,i=this._order){return this._x=t,this._y=e,this._z=n,this._order=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(t){return this._x=t._x,this._y=t._y,this._z=t._z,this._order=t._order,this._onChangeCallback(),this}setFromRotationMatrix(t,e=this._order,n=!0){const i=t.elements,s=i[0],r=i[4],a=i[8],o=i[1],l=i[5],c=i[9],u=i[2],h=i[6],d=i[10];switch(e){case"XYZ":this._y=Math.asin(Yn(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-c,d),this._z=Math.atan2(-r,s)):(this._x=Math.atan2(h,l),this._z=0);break;case"YXZ":this._x=Math.asin(-Yn(c,-1,1)),Math.abs(c)<.9999999?(this._y=Math.atan2(a,d),this._z=Math.atan2(o,l)):(this._y=Math.atan2(-u,s),this._z=0);break;case"ZXY":this._x=Math.asin(Yn(h,-1,1)),Math.abs(h)<.9999999?(this._y=Math.atan2(-u,d),this._z=Math.atan2(-r,l)):(this._y=0,this._z=Math.atan2(o,s));break;case"ZYX":this._y=Math.asin(-Yn(u,-1,1)),Math.abs(u)<.9999999?(this._x=Math.atan2(h,d),this._z=Math.atan2(o,s)):(this._x=0,this._z=Math.atan2(-r,l));break;case"YZX":this._z=Math.asin(Yn(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-c,l),this._y=Math.atan2(-u,s)):(this._x=0,this._y=Math.atan2(a,d));break;case"XZY":this._z=Math.asin(-Yn(r,-1,1)),Math.abs(r)<.9999999?(this._x=Math.atan2(h,l),this._y=Math.atan2(a,s)):(this._x=Math.atan2(-c,d),this._y=0);break;default:console.warn("THREE.Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,!0===n&&this._onChangeCallback(),this}setFromQuaternion(t,e,n){return gs.makeRotationFromQuaternion(t),this.setFromRotationMatrix(gs,e,n)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return vs.setFromEuler(this),this.setFromQuaternion(vs,t)}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._order===this._order}fromArray(t){return this._x=t[0],this._y=t[1],this._z=t[2],void 0!==t[3]&&(this._order=t[3]),this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._order,t}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}ys.DEFAULT_ORDER="XYZ";class _s{constructor(){this.mask=1}set(t){this.mask=1<>>0}enable(t){this.mask|=1<1){for(let t=0;t1){for(let t=0;t0&&(i.userData=this.userData),i.layers=this.layers.mask,i.matrix=this.matrix.toArray(),i.up=this.up.toArray(),!1===this.matrixAutoUpdate&&(i.matrixAutoUpdate=!1),this.isInstancedMesh&&(i.type="InstancedMesh",i.count=this.count,i.instanceMatrix=this.instanceMatrix.toJSON(),null!==this.instanceColor&&(i.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(i.type="BatchedMesh",i.perObjectFrustumCulled=this.perObjectFrustumCulled,i.sortObjects=this.sortObjects,i.drawRanges=this._drawRanges,i.reservedRanges=this._reservedRanges,i.visibility=this._visibility,i.active=this._active,i.bounds=this._bounds.map((t=>({boxInitialized:t.boxInitialized,boxMin:t.box.min.toArray(),boxMax:t.box.max.toArray(),sphereInitialized:t.sphereInitialized,sphereRadius:t.sphere.radius,sphereCenter:t.sphere.center.toArray()}))),i.maxInstanceCount=this._maxInstanceCount,i.maxVertexCount=this._maxVertexCount,i.maxIndexCount=this._maxIndexCount,i.geometryInitialized=this._geometryInitialized,i.geometryCount=this._geometryCount,i.matricesTexture=this._matricesTexture.toJSON(t),null!==this._colorsTexture&&(i.colorsTexture=this._colorsTexture.toJSON(t)),null!==this.boundingSphere&&(i.boundingSphere={center:i.boundingSphere.center.toArray(),radius:i.boundingSphere.radius}),null!==this.boundingBox&&(i.boundingBox={min:i.boundingBox.min.toArray(),max:i.boundingBox.max.toArray()})),this.isScene)this.background&&(this.background.isColor?i.background=this.background.toJSON():this.background.isTexture&&(i.background=this.background.toJSON(t).uuid)),this.environment&&this.environment.isTexture&&!0!==this.environment.isRenderTargetTexture&&(i.environment=this.environment.toJSON(t).uuid);else if(this.isMesh||this.isLine||this.isPoints){i.geometry=s(t.geometries,this.geometry);const e=this.geometry.parameters;if(void 0!==e&&void 0!==e.shapes){const n=e.shapes;if(Array.isArray(n))for(let e=0,i=n.length;e0){i.children=[];for(let e=0;e0){i.animations=[];for(let e=0;e0&&(n.geometries=e),i.length>0&&(n.materials=i),s.length>0&&(n.textures=s),a.length>0&&(n.images=a),o.length>0&&(n.shapes=o),l.length>0&&(n.skeletons=l),c.length>0&&(n.animations=c),u.length>0&&(n.nodes=u)}return n.object=i,n;function r(t){const e=[];for(const n in t){const i=t[n];delete i.metadata,e.push(i)}return e}}clone(t){return(new this.constructor).copy(this,t)}copy(t,e=!0){if(this.name=t.name,this.up.copy(t.up),this.position.copy(t.position),this.rotation.order=t.rotation.order,this.quaternion.copy(t.quaternion),this.scale.copy(t.scale),this.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.animations=t.animations.slice(),this.userData=JSON.parse(JSON.stringify(t.userData)),!0===e)for(let e=0;e0?i.multiplyScalar(1/Math.sqrt(s)):i.set(0,0,0)}static getBarycoord(t,e,n,i,s){Os.subVectors(i,e),zs.subVectors(n,e),Vs.subVectors(t,e);const r=Os.dot(Os),a=Os.dot(zs),o=Os.dot(Vs),l=zs.dot(zs),c=zs.dot(Vs),u=r*l-a*a;if(0===u)return s.set(0,0,0),null;const h=1/u,d=(l*o-a*c)*h,p=(r*c-a*o)*h;return s.set(1-d-p,p,d)}static containsPoint(t,e,n,i){return null!==this.getBarycoord(t,e,n,i,Fs)&&(Fs.x>=0&&Fs.y>=0&&Fs.x+Fs.y<=1)}static getInterpolation(t,e,n,i,s,r,a,o){return null===this.getBarycoord(t,e,n,i,Fs)?(o.x=0,o.y=0,"z"in o&&(o.z=0),"w"in o&&(o.w=0),null):(o.setScalar(0),o.addScaledVector(s,Fs.x),o.addScaledVector(r,Fs.y),o.addScaledVector(a,Fs.z),o)}static getInterpolatedAttribute(t,e,n,i,s,r){return Xs.setScalar(0),qs.setScalar(0),Ys.setScalar(0),Xs.fromBufferAttribute(t,e),qs.fromBufferAttribute(t,n),Ys.fromBufferAttribute(t,i),r.setScalar(0),r.addScaledVector(Xs,s.x),r.addScaledVector(qs,s.y),r.addScaledVector(Ys,s.z),r}static isFrontFacing(t,e,n,i){return Os.subVectors(n,e),zs.subVectors(t,e),Os.cross(zs).dot(i)<0}set(t,e,n){return this.a.copy(t),this.b.copy(e),this.c.copy(n),this}setFromPointsAndIndices(t,e,n,i){return this.a.copy(t[e]),this.b.copy(t[n]),this.c.copy(t[i]),this}setFromAttributeAndIndices(t,e,n,i){return this.a.fromBufferAttribute(t,e),this.b.fromBufferAttribute(t,n),this.c.fromBufferAttribute(t,i),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 Os.subVectors(this.c,this.b),zs.subVectors(this.a,this.b),.5*Os.cross(zs).length()}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return Zs.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return Zs.getBarycoord(t,this.a,this.b,this.c,e)}getInterpolation(t,e,n,i,s){return Zs.getInterpolation(t,this.a,this.b,this.c,e,n,i,s)}containsPoint(t){return Zs.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return Zs.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(t){return t.intersectsTriangle(this)}closestPointToPoint(t,e){const n=this.a,i=this.b,s=this.c;let r,a;Bs.subVectors(i,n),ks.subVectors(s,n),Gs.subVectors(t,n);const o=Bs.dot(Gs),l=ks.dot(Gs);if(o<=0&&l<=0)return e.copy(n);Ws.subVectors(t,i);const c=Bs.dot(Ws),u=ks.dot(Ws);if(c>=0&&u<=c)return e.copy(i);const h=o*u-c*l;if(h<=0&&o>=0&&c<=0)return r=o/(o-c),e.copy(n).addScaledVector(Bs,r);js.subVectors(t,s);const d=Bs.dot(js),p=ks.dot(js);if(p>=0&&d<=p)return e.copy(s);const m=d*l-o*p;if(m<=0&&l>=0&&p<=0)return a=l/(l-p),e.copy(n).addScaledVector(ks,a);const f=c*p-d*u;if(f<=0&&u-c>=0&&d-p>=0)return Hs.subVectors(s,i),a=(u-c)/(u-c+(d-p)),e.copy(i).addScaledVector(Hs,a);const g=1/(f+m+h);return r=m*g,a=h*g,e.copy(n).addScaledVector(Bs,r).addScaledVector(ks,a)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}}const $s={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},Js={h:0,s:0,l:0},Ks={h:0,s:0,l:0};function Qs(t,e,n){return n<0&&(n+=1),n>1&&(n-=1),n<1/6?t+6*(e-t)*n:n<.5?e:n<2/3?t+6*(e-t)*(2/3-n):t}class tr{constructor(t,e,n){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(t,e,n)}set(t,e,n){if(void 0===e&&void 0===n){const e=t;e&&e.isColor?this.copy(e):"number"==typeof e?this.setHex(e):"string"==typeof e&&this.setStyle(e)}else this.setRGB(t,e,n);return this}setScalar(t){return this.r=t,this.g=t,this.b=t,this}setHex(t,e=$e){return t=Math.floor(t),this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(255&t)/255,mi.toWorkingColorSpace(this,e),this}setRGB(t,e,n,i=mi.workingColorSpace){return this.r=t,this.g=e,this.b=n,mi.toWorkingColorSpace(this,i),this}setHSL(t,e,n,i=mi.workingColorSpace){if(t=Zn(t,1),e=Yn(e,0,1),n=Yn(n,0,1),0===e)this.r=this.g=this.b=n;else{const i=n<=.5?n*(1+e):n+e-n*e,s=2*n-i;this.r=Qs(s,i,t+1/3),this.g=Qs(s,i,t),this.b=Qs(s,i,t-1/3)}return mi.toWorkingColorSpace(this,i),this}setStyle(t,e=$e){function n(e){void 0!==e&&parseFloat(e)<1&&console.warn("THREE.Color: Alpha component of "+t+" will be ignored.")}let i;if(i=/^(\w+)\(([^\)]*)\)/.exec(t)){let s;const r=i[1],a=i[2];switch(r){case"rgb":case"rgba":if(s=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return n(s[4]),this.setRGB(Math.min(255,parseInt(s[1],10))/255,Math.min(255,parseInt(s[2],10))/255,Math.min(255,parseInt(s[3],10))/255,e);if(s=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return n(s[4]),this.setRGB(Math.min(100,parseInt(s[1],10))/100,Math.min(100,parseInt(s[2],10))/100,Math.min(100,parseInt(s[3],10))/100,e);break;case"hsl":case"hsla":if(s=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return n(s[4]),this.setHSL(parseFloat(s[1])/360,parseFloat(s[2])/100,parseFloat(s[3])/100,e);break;default:console.warn("THREE.Color: Unknown color model "+t)}}else if(i=/^\#([A-Fa-f\d]+)$/.exec(t)){const n=i[1],s=n.length;if(3===s)return this.setRGB(parseInt(n.charAt(0),16)/15,parseInt(n.charAt(1),16)/15,parseInt(n.charAt(2),16)/15,e);if(6===s)return this.setHex(parseInt(n,16),e);console.warn("THREE.Color: Invalid hex color "+t)}else if(t&&t.length>0)return this.setColorName(t,e);return this}setColorName(t,e=$e){const n=$s[t.toLowerCase()];return void 0!==n?this.setHex(n,e):console.warn("THREE.Color: Unknown color "+t),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(t){return this.r=t.r,this.g=t.g,this.b=t.b,this}copySRGBToLinear(t){return this.r=fi(t.r),this.g=fi(t.g),this.b=fi(t.b),this}copyLinearToSRGB(t){return this.r=gi(t.r),this.g=gi(t.g),this.b=gi(t.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(t=$e){return mi.fromWorkingColorSpace(er.copy(this),t),65536*Math.round(Yn(255*er.r,0,255))+256*Math.round(Yn(255*er.g,0,255))+Math.round(Yn(255*er.b,0,255))}getHexString(t=$e){return("000000"+this.getHex(t).toString(16)).slice(-6)}getHSL(t,e=mi.workingColorSpace){mi.fromWorkingColorSpace(er.copy(this),e);const n=er.r,i=er.g,s=er.b,r=Math.max(n,i,s),a=Math.min(n,i,s);let o,l;const c=(a+r)/2;if(a===r)o=0,l=0;else{const t=r-a;switch(l=c<=.5?t/(r+a):t/(2-r-a),r){case n:o=(i-s)/t+(i0!=t>0&&this.version++,this._alphaTest=t}onBuild(){}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(t){if(void 0!==t)for(const e in t){const n=t[e];if(void 0===n){console.warn(`THREE.Material: parameter '${e}' has value of undefined.`);continue}const i=this[e];void 0!==i?i&&i.isColor?i.set(n):i&&i.isVector3&&n&&n.isVector3?i.copy(n):this[e]=n:console.warn(`THREE.Material: '${e}' is not a property of THREE.${this.type}.`)}}toJSON(t){const e=void 0===t||"string"==typeof t;e&&(t={textures:{},images:{}});const n={metadata:{version:4.6,type:"Material",generator:"Material.toJSON"}};function i(t){const e=[];for(const n in t){const i=t[n];delete i.metadata,e.push(i)}return e}if(n.uuid=this.uuid,n.type=this.type,""!==this.name&&(n.name=this.name),this.color&&this.color.isColor&&(n.color=this.color.getHex()),void 0!==this.roughness&&(n.roughness=this.roughness),void 0!==this.metalness&&(n.metalness=this.metalness),void 0!==this.sheen&&(n.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(n.sheenColor=this.sheenColor.getHex()),void 0!==this.sheenRoughness&&(n.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(n.emissive=this.emissive.getHex()),void 0!==this.emissiveIntensity&&1!==this.emissiveIntensity&&(n.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(n.specular=this.specular.getHex()),void 0!==this.specularIntensity&&(n.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(n.specularColor=this.specularColor.getHex()),void 0!==this.shininess&&(n.shininess=this.shininess),void 0!==this.clearcoat&&(n.clearcoat=this.clearcoat),void 0!==this.clearcoatRoughness&&(n.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(n.clearcoatMap=this.clearcoatMap.toJSON(t).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(n.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(t).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(n.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(t).uuid,n.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),void 0!==this.dispersion&&(n.dispersion=this.dispersion),void 0!==this.iridescence&&(n.iridescence=this.iridescence),void 0!==this.iridescenceIOR&&(n.iridescenceIOR=this.iridescenceIOR),void 0!==this.iridescenceThicknessRange&&(n.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(n.iridescenceMap=this.iridescenceMap.toJSON(t).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(n.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(t).uuid),void 0!==this.anisotropy&&(n.anisotropy=this.anisotropy),void 0!==this.anisotropyRotation&&(n.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(n.anisotropyMap=this.anisotropyMap.toJSON(t).uuid),this.map&&this.map.isTexture&&(n.map=this.map.toJSON(t).uuid),this.matcap&&this.matcap.isTexture&&(n.matcap=this.matcap.toJSON(t).uuid),this.alphaMap&&this.alphaMap.isTexture&&(n.alphaMap=this.alphaMap.toJSON(t).uuid),this.lightMap&&this.lightMap.isTexture&&(n.lightMap=this.lightMap.toJSON(t).uuid,n.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(n.aoMap=this.aoMap.toJSON(t).uuid,n.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(n.bumpMap=this.bumpMap.toJSON(t).uuid,n.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(n.normalMap=this.normalMap.toJSON(t).uuid,n.normalMapType=this.normalMapType,n.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(n.displacementMap=this.displacementMap.toJSON(t).uuid,n.displacementScale=this.displacementScale,n.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(n.roughnessMap=this.roughnessMap.toJSON(t).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(n.metalnessMap=this.metalnessMap.toJSON(t).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(n.emissiveMap=this.emissiveMap.toJSON(t).uuid),this.specularMap&&this.specularMap.isTexture&&(n.specularMap=this.specularMap.toJSON(t).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(n.specularIntensityMap=this.specularIntensityMap.toJSON(t).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(n.specularColorMap=this.specularColorMap.toJSON(t).uuid),this.envMap&&this.envMap.isTexture&&(n.envMap=this.envMap.toJSON(t).uuid,void 0!==this.combine&&(n.combine=this.combine)),void 0!==this.envMapRotation&&(n.envMapRotation=this.envMapRotation.toArray()),void 0!==this.envMapIntensity&&(n.envMapIntensity=this.envMapIntensity),void 0!==this.reflectivity&&(n.reflectivity=this.reflectivity),void 0!==this.refractionRatio&&(n.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(n.gradientMap=this.gradientMap.toJSON(t).uuid),void 0!==this.transmission&&(n.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(n.transmissionMap=this.transmissionMap.toJSON(t).uuid),void 0!==this.thickness&&(n.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(n.thicknessMap=this.thicknessMap.toJSON(t).uuid),void 0!==this.attenuationDistance&&this.attenuationDistance!==1/0&&(n.attenuationDistance=this.attenuationDistance),void 0!==this.attenuationColor&&(n.attenuationColor=this.attenuationColor.getHex()),void 0!==this.size&&(n.size=this.size),null!==this.shadowSide&&(n.shadowSide=this.shadowSide),void 0!==this.sizeAttenuation&&(n.sizeAttenuation=this.sizeAttenuation),1!==this.blending&&(n.blending=this.blending),0!==this.side&&(n.side=this.side),!0===this.vertexColors&&(n.vertexColors=!0),this.opacity<1&&(n.opacity=this.opacity),!0===this.transparent&&(n.transparent=!0),this.blendSrc!==C&&(n.blendSrc=this.blendSrc),this.blendDst!==R&&(n.blendDst=this.blendDst),this.blendEquation!==x&&(n.blendEquation=this.blendEquation),null!==this.blendSrcAlpha&&(n.blendSrcAlpha=this.blendSrcAlpha),null!==this.blendDstAlpha&&(n.blendDstAlpha=this.blendDstAlpha),null!==this.blendEquationAlpha&&(n.blendEquationAlpha=this.blendEquationAlpha),this.blendColor&&this.blendColor.isColor&&(n.blendColor=this.blendColor.getHex()),0!==this.blendAlpha&&(n.blendAlpha=this.blendAlpha),3!==this.depthFunc&&(n.depthFunc=this.depthFunc),!1===this.depthTest&&(n.depthTest=this.depthTest),!1===this.depthWrite&&(n.depthWrite=this.depthWrite),!1===this.colorWrite&&(n.colorWrite=this.colorWrite),255!==this.stencilWriteMask&&(n.stencilWriteMask=this.stencilWriteMask),519!==this.stencilFunc&&(n.stencilFunc=this.stencilFunc),0!==this.stencilRef&&(n.stencilRef=this.stencilRef),255!==this.stencilFuncMask&&(n.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==an&&(n.stencilFail=this.stencilFail),this.stencilZFail!==an&&(n.stencilZFail=this.stencilZFail),this.stencilZPass!==an&&(n.stencilZPass=this.stencilZPass),!0===this.stencilWrite&&(n.stencilWrite=this.stencilWrite),void 0!==this.rotation&&0!==this.rotation&&(n.rotation=this.rotation),!0===this.polygonOffset&&(n.polygonOffset=!0),0!==this.polygonOffsetFactor&&(n.polygonOffsetFactor=this.polygonOffsetFactor),0!==this.polygonOffsetUnits&&(n.polygonOffsetUnits=this.polygonOffsetUnits),void 0!==this.linewidth&&1!==this.linewidth&&(n.linewidth=this.linewidth),void 0!==this.dashSize&&(n.dashSize=this.dashSize),void 0!==this.gapSize&&(n.gapSize=this.gapSize),void 0!==this.scale&&(n.scale=this.scale),!0===this.dithering&&(n.dithering=!0),this.alphaTest>0&&(n.alphaTest=this.alphaTest),!0===this.alphaHash&&(n.alphaHash=!0),!0===this.alphaToCoverage&&(n.alphaToCoverage=!0),!0===this.premultipliedAlpha&&(n.premultipliedAlpha=!0),!0===this.forceSinglePass&&(n.forceSinglePass=!0),!0===this.wireframe&&(n.wireframe=!0),this.wireframeLinewidth>1&&(n.wireframeLinewidth=this.wireframeLinewidth),"round"!==this.wireframeLinecap&&(n.wireframeLinecap=this.wireframeLinecap),"round"!==this.wireframeLinejoin&&(n.wireframeLinejoin=this.wireframeLinejoin),!0===this.flatShading&&(n.flatShading=!0),!1===this.visible&&(n.visible=!1),!1===this.toneMapped&&(n.toneMapped=!1),!1===this.fog&&(n.fog=!1),Object.keys(this.userData).length>0&&(n.userData=this.userData),e){const e=i(t.textures),s=i(t.images);e.length>0&&(n.textures=e),s.length>0&&(n.images=s)}return n}clone(){return(new this.constructor).copy(this)}copy(t){this.name=t.name,this.blending=t.blending,this.side=t.side,this.vertexColors=t.vertexColors,this.opacity=t.opacity,this.transparent=t.transparent,this.blendSrc=t.blendSrc,this.blendDst=t.blendDst,this.blendEquation=t.blendEquation,this.blendSrcAlpha=t.blendSrcAlpha,this.blendDstAlpha=t.blendDstAlpha,this.blendEquationAlpha=t.blendEquationAlpha,this.blendColor.copy(t.blendColor),this.blendAlpha=t.blendAlpha,this.depthFunc=t.depthFunc,this.depthTest=t.depthTest,this.depthWrite=t.depthWrite,this.stencilWriteMask=t.stencilWriteMask,this.stencilFunc=t.stencilFunc,this.stencilRef=t.stencilRef,this.stencilFuncMask=t.stencilFuncMask,this.stencilFail=t.stencilFail,this.stencilZFail=t.stencilZFail,this.stencilZPass=t.stencilZPass,this.stencilWrite=t.stencilWrite;const e=t.clippingPlanes;let n=null;if(null!==e){const t=e.length;n=new Array(t);for(let i=0;i!==t;++i)n[i]=e[i].clone()}return this.clippingPlanes=n,this.clipIntersection=t.clipIntersection,this.clipShadows=t.clipShadows,this.shadowSide=t.shadowSide,this.colorWrite=t.colorWrite,this.precision=t.precision,this.polygonOffset=t.polygonOffset,this.polygonOffsetFactor=t.polygonOffsetFactor,this.polygonOffsetUnits=t.polygonOffsetUnits,this.dithering=t.dithering,this.alphaTest=t.alphaTest,this.alphaHash=t.alphaHash,this.alphaToCoverage=t.alphaToCoverage,this.premultipliedAlpha=t.premultipliedAlpha,this.forceSinglePass=t.forceSinglePass,this.visible=t.visible,this.toneMapped=t.toneMapped,this.userData=JSON.parse(JSON.stringify(t.userData)),this}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(t){!0===t&&this.version++}}class sr extends ir{constructor(t){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new tr(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 ys,this.combine=0,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapRotation.copy(t.envMapRotation),this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.fog=t.fog,this}}const rr=ar();function ar(){const t=new ArrayBuffer(4),e=new Float32Array(t),n=new Uint32Array(t),i=new Uint32Array(512),s=new Uint32Array(512);for(let t=0;t<256;++t){const e=t-127;e<-27?(i[t]=0,i[256|t]=32768,s[t]=24,s[256|t]=24):e<-14?(i[t]=1024>>-e-14,i[256|t]=1024>>-e-14|32768,s[t]=-e-1,s[256|t]=-e-1):e<=15?(i[t]=e+15<<10,i[256|t]=e+15<<10|32768,s[t]=13,s[256|t]=13):e<128?(i[t]=31744,i[256|t]=64512,s[t]=24,s[256|t]=24):(i[t]=31744,i[256|t]=64512,s[t]=13,s[256|t]=13)}const r=new Uint32Array(2048),a=new Uint32Array(64),o=new Uint32Array(64);for(let t=1;t<1024;++t){let e=t<<13,n=0;for(;!(8388608&e);)e<<=1,n-=8388608;e&=-8388609,n+=947912704,r[t]=e|n}for(let t=1024;t<2048;++t)r[t]=939524096+(t-1024<<13);for(let t=1;t<31;++t)a[t]=t<<23;a[31]=1199570944,a[32]=2147483648;for(let t=33;t<63;++t)a[t]=2147483648+(t-32<<23);a[63]=3347054592;for(let t=1;t<64;++t)32!==t&&(o[t]=1024);return{floatView:e,uint32View:n,baseTable:i,shiftTable:s,mantissaTable:r,exponentTable:a,offsetTable:o}}function or(t){Math.abs(t)>65504&&console.warn("THREE.DataUtils.toHalfFloat(): Value out of range."),t=Yn(t,-65504,65504),rr.floatView[0]=t;const e=rr.uint32View[0],n=e>>23&511;return rr.baseTable[n]+((8388607&e)>>rr.shiftTable[n])}function lr(t){const e=t>>10;return rr.uint32View[0]=rr.mantissaTable[rr.offsetTable[e]+(1023&t)]+rr.exponentTable[e],rr.floatView[0]}const cr={toHalfFloat:or,fromHalfFloat:lr},ur=new Li,hr=new ti;class dr{constructor(t,e,n=!1){if(Array.isArray(t))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,this.name="",this.array=t,this.itemSize=e,this.count=void 0!==t?t.length/e:0,this.normalized=n,this.usage=Cn,this.updateRanges=[],this.gpuType=Lt,this.version=0}onUploadCallback(){}set needsUpdate(t){!0===t&&this.version++}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.name=t.name,this.array=new t.array.constructor(t.array),this.itemSize=t.itemSize,this.count=t.count,this.normalized=t.normalized,this.usage=t.usage,this.gpuType=t.gpuType,this}copyAt(t,e,n){t*=this.itemSize,n*=e.itemSize;for(let i=0,s=this.itemSize;i0&&(t.userData=this.userData),void 0!==this.parameters){const e=this.parameters;for(const n in e)void 0!==e[n]&&(t[n]=e[n]);return t}t.data={attributes:{}};const e=this.index;null!==e&&(t.data.index={type:e.array.constructor.name,array:Array.prototype.slice.call(e.array)});const n=this.attributes;for(const e in n){const i=n[e];t.data.attributes[e]=i.toJSON(t.data)}const i={};let s=!1;for(const e in this.morphAttributes){const n=this.morphAttributes[e],r=[];for(let e=0,i=n.length;e0&&(i[e]=r,s=!0)}s&&(t.data.morphAttributes=i,t.data.morphTargetsRelative=this.morphTargetsRelative);const r=this.groups;r.length>0&&(t.data.groups=JSON.parse(JSON.stringify(r)));const a=this.boundingSphere;return null!==a&&(t.data.boundingSphere={center:a.center.toArray(),radius:a.radius}),t}clone(){return(new this.constructor).copy(this)}copy(t){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const e={};this.name=t.name;const n=t.index;null!==n&&this.setIndex(n.clone(e));const i=t.attributes;for(const t in i){const n=i[t];this.setAttribute(t,n.clone(e))}const s=t.morphAttributes;for(const t in s){const n=[],i=s[t];for(let t=0,s=i.length;t0){const n=t[e[0]];if(void 0!==n){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let t=0,e=n.length;t(t.far-t.near)**2)return}Rr.copy(s).invert(),Ir.copy(t.ray).applyMatrix4(Rr),null!==n.boundingBox&&!1===Ir.intersectsBox(n.boundingBox)||this._computeIntersections(t,e,Ir)}}_computeIntersections(t,e,n){let i;const s=this.geometry,r=this.material,a=s.index,o=s.attributes.position,l=s.attributes.uv,c=s.attributes.uv1,u=s.attributes.normal,h=s.groups,d=s.drawRange;if(null!==a)if(Array.isArray(r))for(let s=0,o=h.length;sn.far?null:{distance:c,point:Br.clone(),object:t}}(t,e,n,i,Ur,Dr,Or,Fr);if(u){const t=new Li;Zs.getBarycoord(Fr,Ur,Dr,Or,t),s&&(u.uv=Zs.getInterpolatedAttribute(s,o,l,c,t,new ti)),r&&(u.uv1=Zs.getInterpolatedAttribute(r,o,l,c,t,new ti)),a&&(u.normal=Zs.getInterpolatedAttribute(a,o,l,c,t,new Li),u.normal.dot(i.direction)>0&&u.normal.multiplyScalar(-1));const e={a:o,b:l,c:c,normal:new Li,materialIndex:0};Zs.getNormal(Ur,Dr,Or,e.normal),u.face=e,u.barycoord=t}return u}class Gr extends Cr{constructor(t=1,e=1,n=1,i=1,s=1,r=1){super(),this.type="BoxGeometry",this.parameters={width:t,height:e,depth:n,widthSegments:i,heightSegments:s,depthSegments:r};const a=this;i=Math.floor(i),s=Math.floor(s),r=Math.floor(r);const o=[],l=[],c=[],u=[];let h=0,d=0;function p(t,e,n,i,s,r,p,m,f,g,v){const y=r/f,_=p/g,x=r/2,M=p/2,b=m/2,T=f+1,S=g+1;let w=0,E=0;const A=new Li;for(let r=0;r0?1:-1,c.push(A.x,A.y,A.z),u.push(o/f),u.push(1-r/g),w+=1}}for(let t=0;t0&&(e.defines=this.defines),e.vertexShader=this.vertexShader,e.fragmentShader=this.fragmentShader,e.lights=this.lights,e.clipping=this.clipping;const n={};for(const t in this.extensions)!0===this.extensions[t]&&(n[t]=!0);return Object.keys(n).length>0&&(e.extensions=n),e}}class Zr extends Ds{constructor(){super(),this.isCamera=!0,this.type="Camera",this.matrixWorldInverse=new ls,this.projectionMatrix=new ls,this.projectionMatrixInverse=new ls,this.coordinateSystem=Bn}copy(t,e){return super.copy(t,e),this.matrixWorldInverse.copy(t.matrixWorldInverse),this.projectionMatrix.copy(t.projectionMatrix),this.projectionMatrixInverse.copy(t.projectionMatrixInverse),this.coordinateSystem=t.coordinateSystem,this}getWorldDirection(t){return super.getWorldDirection(t).negate()}updateMatrixWorld(t){super.updateMatrixWorld(t),this.matrixWorldInverse.copy(this.matrixWorld).invert()}updateWorldMatrix(t,e){super.updateWorldMatrix(t,e),this.matrixWorldInverse.copy(this.matrixWorld).invert()}clone(){return(new this.constructor).copy(this)}}const $r=new Li,Jr=new ti,Kr=new ti;class Qr extends Zr{constructor(t=50,e=1,n=.1,i=2e3){super(),this.isPerspectiveCamera=!0,this.type="PerspectiveCamera",this.fov=t,this.zoom=1,this.near=n,this.far=i,this.focus=10,this.aspect=e,this.view=null,this.filmGauge=35,this.filmOffset=0,this.updateProjectionMatrix()}copy(t,e){return super.copy(t,e),this.fov=t.fov,this.zoom=t.zoom,this.near=t.near,this.far=t.far,this.focus=t.focus,this.aspect=t.aspect,this.view=null===t.view?null:Object.assign({},t.view),this.filmGauge=t.filmGauge,this.filmOffset=t.filmOffset,this}setFocalLength(t){const e=.5*this.getFilmHeight()/t;this.fov=2*Xn*Math.atan(e),this.updateProjectionMatrix()}getFocalLength(){const t=Math.tan(.5*jn*this.fov);return.5*this.getFilmHeight()/t}getEffectiveFOV(){return 2*Xn*Math.atan(Math.tan(.5*jn*this.fov)/this.zoom)}getFilmWidth(){return this.filmGauge*Math.min(this.aspect,1)}getFilmHeight(){return this.filmGauge/Math.max(this.aspect,1)}getViewBounds(t,e,n){$r.set(-1,-1,.5).applyMatrix4(this.projectionMatrixInverse),e.set($r.x,$r.y).multiplyScalar(-t/$r.z),$r.set(1,1,.5).applyMatrix4(this.projectionMatrixInverse),n.set($r.x,$r.y).multiplyScalar(-t/$r.z)}getViewSize(t,e){return this.getViewBounds(t,Jr,Kr),e.subVectors(Kr,Jr)}setViewOffset(t,e,n,i,s,r){this.aspect=t/e,null===this.view&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=t,this.view.fullHeight=e,this.view.offsetX=n,this.view.offsetY=i,this.view.width=s,this.view.height=r,this.updateProjectionMatrix()}clearViewOffset(){null!==this.view&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const t=this.near;let e=t*Math.tan(.5*jn*this.fov)/this.zoom,n=2*e,i=this.aspect*n,s=-.5*i;const r=this.view;if(null!==this.view&&this.view.enabled){const t=r.fullWidth,a=r.fullHeight;s+=r.offsetX*i/t,e-=r.offsetY*n/a,i*=r.width/t,n*=r.height/a}const a=this.filmOffset;0!==a&&(s+=t*a/this.getFilmWidth()),this.projectionMatrix.makePerspective(s,s+i,e,e-n,t,this.far,this.coordinateSystem),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(t){const e=super.toJSON(t);return e.object.fov=this.fov,e.object.zoom=this.zoom,e.object.near=this.near,e.object.far=this.far,e.object.focus=this.focus,e.object.aspect=this.aspect,null!==this.view&&(e.object.view=Object.assign({},this.view)),e.object.filmGauge=this.filmGauge,e.object.filmOffset=this.filmOffset,e}}const ta=-90;class ea extends Ds{constructor(t,e,n){super(),this.type="CubeCamera",this.renderTarget=n,this.coordinateSystem=null,this.activeMipmapLevel=0;const i=new Qr(ta,1,t,e);i.layers=this.layers,this.add(i);const s=new Qr(ta,1,t,e);s.layers=this.layers,this.add(s);const r=new Qr(ta,1,t,e);r.layers=this.layers,this.add(r);const a=new Qr(ta,1,t,e);a.layers=this.layers,this.add(a);const o=new Qr(ta,1,t,e);o.layers=this.layers,this.add(o);const l=new Qr(ta,1,t,e);l.layers=this.layers,this.add(l)}updateCoordinateSystem(){const t=this.coordinateSystem,e=this.children.concat(),[n,i,s,r,a,o]=e;for(const t of e)this.remove(t);if(t===Bn)n.up.set(0,1,0),n.lookAt(1,0,0),i.up.set(0,1,0),i.lookAt(-1,0,0),s.up.set(0,0,-1),s.lookAt(0,1,0),r.up.set(0,0,1),r.lookAt(0,-1,0),a.up.set(0,1,0),a.lookAt(0,0,1),o.up.set(0,1,0),o.lookAt(0,0,-1);else{if(t!==kn)throw new Error("THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: "+t);n.up.set(0,-1,0),n.lookAt(-1,0,0),i.up.set(0,-1,0),i.lookAt(1,0,0),s.up.set(0,0,1),s.lookAt(0,1,0),r.up.set(0,0,-1),r.lookAt(0,-1,0),a.up.set(0,-1,0),a.lookAt(0,0,1),o.up.set(0,-1,0),o.lookAt(0,0,-1)}for(const t of e)this.add(t),t.updateMatrixWorld()}update(t,e){null===this.parent&&this.updateMatrixWorld();const{renderTarget:n,activeMipmapLevel:i}=this;this.coordinateSystem!==t.coordinateSystem&&(this.coordinateSystem=t.coordinateSystem,this.updateCoordinateSystem());const[s,r,a,o,l,c]=this.children,u=t.getRenderTarget(),h=t.getActiveCubeFace(),d=t.getActiveMipmapLevel(),p=t.xr.enabled;t.xr.enabled=!1;const m=n.texture.generateMipmaps;n.texture.generateMipmaps=!1,t.setRenderTarget(n,0,i),t.render(e,s),t.setRenderTarget(n,1,i),t.render(e,r),t.setRenderTarget(n,2,i),t.render(e,a),t.setRenderTarget(n,3,i),t.render(e,o),t.setRenderTarget(n,4,i),t.render(e,l),n.texture.generateMipmaps=m,t.setRenderTarget(n,5,i),t.render(e,c),t.setRenderTarget(u,h,d),t.xr.enabled=p,n.texture.needsPMREMUpdate=!0}}class na extends Ti{constructor(t,e,n,i,s,r,a,o,l,c){super(t=void 0!==t?t:[],e=void 0!==e?e:lt,n,i,s,r,a,o,l,c),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(t){this.image=t}}class ia extends Ei{constructor(t=1,e={}){super(t,t,e),this.isWebGLCubeRenderTarget=!0;const n={width:t,height:t,depth:1},i=[n,n,n,n,n,n];this.texture=new na(i,e.mapping,e.wrapS,e.wrapT,e.magFilter,e.minFilter,e.format,e.type,e.anisotropy,e.colorSpace),this.texture.isRenderTargetTexture=!0,this.texture.generateMipmaps=void 0!==e.generateMipmaps&&e.generateMipmaps,this.texture.minFilter=void 0!==e.minFilter?e.minFilter:Mt}fromEquirectangularTexture(t,e){this.texture.type=e.type,this.texture.colorSpace=e.colorSpace,this.texture.generateMipmaps=e.generateMipmaps,this.texture.minFilter=e.minFilter,this.texture.magFilter=e.magFilter;const n={uniforms:{tEquirect:{value:null}},vertexShader:"\n\n\t\t\t\tvarying vec3 vWorldDirection;\n\n\t\t\t\tvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\n\t\t\t\t\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n\n\t\t\t\t}\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tvWorldDirection = transformDirection( position, modelMatrix );\n\n\t\t\t\t\t#include \n\t\t\t\t\t#include \n\n\t\t\t\t}\n\t\t\t",fragmentShader:"\n\n\t\t\t\tuniform sampler2D tEquirect;\n\n\t\t\t\tvarying vec3 vWorldDirection;\n\n\t\t\t\t#include \n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tvec3 direction = normalize( vWorldDirection );\n\n\t\t\t\t\tvec2 sampleUV = equirectUv( direction );\n\n\t\t\t\t\tgl_FragColor = texture2D( tEquirect, sampleUV );\n\n\t\t\t\t}\n\t\t\t"},i=new Gr(5,5,5),s=new Yr({name:"CubemapFromEquirect",uniforms:Wr(n.uniforms),vertexShader:n.vertexShader,fragmentShader:n.fragmentShader,side:1,blending:0});s.uniforms.tEquirect.value=e;const r=new kr(i,s),a=e.minFilter;e.minFilter===St&&(e.minFilter=Mt);return new ea(1,10,this).update(t,r),e.minFilter=a,r.geometry.dispose(),r.material.dispose(),this}clear(t,e,n,i){const s=t.getRenderTarget();for(let s=0;s<6;s++)t.setRenderTarget(this,s),t.clear(e,n,i);t.setRenderTarget(s)}}const sa=new Li,ra=new Li,aa=new ei;class oa{constructor(t=new Li(1,0,0),e=0){this.isPlane=!0,this.normal=t,this.constant=e}set(t,e){return this.normal.copy(t),this.constant=e,this}setComponents(t,e,n,i){return this.normal.set(t,e,n),this.constant=i,this}setFromNormalAndCoplanarPoint(t,e){return this.normal.copy(t),this.constant=-e.dot(this.normal),this}setFromCoplanarPoints(t,e,n){const i=sa.subVectors(n,e).cross(ra.subVectors(t,e)).normalize();return this.setFromNormalAndCoplanarPoint(i,t),this}copy(t){return this.normal.copy(t.normal),this.constant=t.constant,this}normalize(){const t=1/this.normal.length();return this.normal.multiplyScalar(t),this.constant*=t,this}negate(){return this.constant*=-1,this.normal.negate(),this}distanceToPoint(t){return this.normal.dot(t)+this.constant}distanceToSphere(t){return this.distanceToPoint(t.center)-t.radius}projectPoint(t,e){return e.copy(t).addScaledVector(this.normal,-this.distanceToPoint(t))}intersectLine(t,e){const n=t.delta(sa),i=this.normal.dot(n);if(0===i)return 0===this.distanceToPoint(t.start)?e.copy(t.start):null;const s=-(t.start.dot(this.normal)+this.constant)/i;return s<0||s>1?null:e.copy(t.start).addScaledVector(n,s)}intersectsLine(t){const e=this.distanceToPoint(t.start),n=this.distanceToPoint(t.end);return e<0&&n>0||n<0&&e>0}intersectsBox(t){return t.intersectsPlane(this)}intersectsSphere(t){return t.intersectsPlane(this)}coplanarPoint(t){return t.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(t,e){const n=e||aa.getNormalMatrix(t),i=this.coplanarPoint(sa).applyMatrix4(t),s=this.normal.applyMatrix3(n).normalize();return this.constant=-i.dot(s),this}translate(t){return this.constant-=t.dot(this.normal),this}equals(t){return t.normal.equals(this.normal)&&t.constant===this.constant}clone(){return(new this.constructor).copy(this)}}const la=new Qi,ca=new Li;class ua{constructor(t=new oa,e=new oa,n=new oa,i=new oa,s=new oa,r=new oa){this.planes=[t,e,n,i,s,r]}set(t,e,n,i,s,r){const a=this.planes;return a[0].copy(t),a[1].copy(e),a[2].copy(n),a[3].copy(i),a[4].copy(s),a[5].copy(r),this}copy(t){const e=this.planes;for(let n=0;n<6;n++)e[n].copy(t.planes[n]);return this}setFromProjectionMatrix(t,e=2e3){const n=this.planes,i=t.elements,s=i[0],r=i[1],a=i[2],o=i[3],l=i[4],c=i[5],u=i[6],h=i[7],d=i[8],p=i[9],m=i[10],f=i[11],g=i[12],v=i[13],y=i[14],_=i[15];if(n[0].setComponents(o-s,h-l,f-d,_-g).normalize(),n[1].setComponents(o+s,h+l,f+d,_+g).normalize(),n[2].setComponents(o+r,h+c,f+p,_+v).normalize(),n[3].setComponents(o-r,h-c,f-p,_-v).normalize(),n[4].setComponents(o-a,h-u,f-m,_-y).normalize(),e===Bn)n[5].setComponents(o+a,h+u,f+m,_+y).normalize();else{if(e!==kn)throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: "+e);n[5].setComponents(a,u,m,y).normalize()}return this}intersectsObject(t){if(void 0!==t.boundingSphere)null===t.boundingSphere&&t.computeBoundingSphere(),la.copy(t.boundingSphere).applyMatrix4(t.matrixWorld);else{const e=t.geometry;null===e.boundingSphere&&e.computeBoundingSphere(),la.copy(e.boundingSphere).applyMatrix4(t.matrixWorld)}return this.intersectsSphere(la)}intersectsSprite(t){return la.center.set(0,0,0),la.radius=.7071067811865476,la.applyMatrix4(t.matrixWorld),this.intersectsSphere(la)}intersectsSphere(t){const e=this.planes,n=t.center,i=-t.radius;for(let t=0;t<6;t++){if(e[t].distanceToPoint(n)0?t.max.x:t.min.x,ca.y=i.normal.y>0?t.max.y:t.min.y,ca.z=i.normal.z>0?t.max.z:t.min.z,i.distanceToPoint(ca)<0)return!1}return!0}containsPoint(t){const e=this.planes;for(let n=0;n<6;n++)if(e[n].distanceToPoint(t)<0)return!1;return!0}clone(){return(new this.constructor).copy(this)}}function ha(){let t=null,e=!1,n=null,i=null;function s(e,r){n(e,r),i=t.requestAnimationFrame(s)}return{start:function(){!0!==e&&null!==n&&(i=t.requestAnimationFrame(s),e=!0)},stop:function(){t.cancelAnimationFrame(i),e=!1},setAnimationLoop:function(t){n=t},setContext:function(e){t=e}}}function da(t){const e=new WeakMap;return{get:function(t){return t.isInterleavedBufferAttribute&&(t=t.data),e.get(t)},remove:function(n){n.isInterleavedBufferAttribute&&(n=n.data);const i=e.get(n);i&&(t.deleteBuffer(i.buffer),e.delete(n))},update:function(n,i){if(n.isInterleavedBufferAttribute&&(n=n.data),n.isGLBufferAttribute){const t=e.get(n);return void((!t||t.versiont.start-e.start));let e=0;for(let t=1;t 0\n\tvec4 plane;\n\t#ifdef ALPHA_TO_COVERAGE\n\t\tfloat distanceToPlane, distanceGradient;\n\t\tfloat clipOpacity = 1.0;\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {\n\t\t\tplane = clippingPlanes[ i ];\n\t\t\tdistanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w;\n\t\t\tdistanceGradient = fwidth( distanceToPlane ) / 2.0;\n\t\t\tclipOpacity *= smoothstep( - distanceGradient, distanceGradient, distanceToPlane );\n\t\t\tif ( clipOpacity == 0.0 ) discard;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t\t#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n\t\t\tfloat unionClipOpacity = 1.0;\n\t\t\t#pragma unroll_loop_start\n\t\t\tfor ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n\t\t\t\tplane = clippingPlanes[ i ];\n\t\t\t\tdistanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w;\n\t\t\t\tdistanceGradient = fwidth( distanceToPlane ) / 2.0;\n\t\t\t\tunionClipOpacity *= 1.0 - smoothstep( - distanceGradient, distanceGradient, distanceToPlane );\n\t\t\t}\n\t\t\t#pragma unroll_loop_end\n\t\t\tclipOpacity *= 1.0 - unionClipOpacity;\n\t\t#endif\n\t\tdiffuseColor.a *= clipOpacity;\n\t\tif ( diffuseColor.a == 0.0 ) discard;\n\t#else\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {\n\t\t\tplane = clippingPlanes[ i ];\n\t\t\tif ( dot( vClipPosition, plane.xyz ) > plane.w ) discard;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t\t#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n\t\t\tbool clipped = true;\n\t\t\t#pragma unroll_loop_start\n\t\t\tfor ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n\t\t\t\tplane = clippingPlanes[ i ];\n\t\t\t\tclipped = ( dot( vClipPosition, plane.xyz ) > plane.w ) && clipped;\n\t\t\t}\n\t\t\t#pragma unroll_loop_end\n\t\t\tif ( clipped ) discard;\n\t\t#endif\n\t#endif\n#endif",clipping_planes_pars_fragment:"#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif",clipping_planes_pars_vertex:"#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif",clipping_planes_vertex:"#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif",color_fragment:"#if defined( USE_COLOR_ALPHA )\n\tdiffuseColor *= vColor;\n#elif defined( USE_COLOR )\n\tdiffuseColor.rgb *= vColor;\n#endif",color_pars_fragment:"#if defined( USE_COLOR_ALPHA )\n\tvarying vec4 vColor;\n#elif defined( USE_COLOR )\n\tvarying vec3 vColor;\n#endif",color_pars_vertex:"#if defined( USE_COLOR_ALPHA )\n\tvarying vec4 vColor;\n#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )\n\tvarying vec3 vColor;\n#endif",color_vertex:"#if defined( USE_COLOR_ALPHA )\n\tvColor = vec4( 1.0 );\n#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )\n\tvColor = vec3( 1.0 );\n#endif\n#ifdef USE_COLOR\n\tvColor *= color;\n#endif\n#ifdef USE_INSTANCING_COLOR\n\tvColor.xyz *= instanceColor.xyz;\n#endif\n#ifdef USE_BATCHING_COLOR\n\tvec3 batchingColor = getBatchingColor( getIndirectIndex( gl_DrawID ) );\n\tvColor.xyz *= batchingColor.xyz;\n#endif",common:"#define PI 3.141592653589793\n#define PI2 6.283185307179586\n#define PI_HALF 1.5707963267948966\n#define RECIPROCAL_PI 0.3183098861837907\n#define RECIPROCAL_PI2 0.15915494309189535\n#define EPSILON 1e-6\n#ifndef saturate\n#define saturate( a ) clamp( a, 0.0, 1.0 )\n#endif\n#define whiteComplement( a ) ( 1.0 - saturate( a ) )\nfloat pow2( const in float x ) { return x*x; }\nvec3 pow2( const in vec3 x ) { return x*x; }\nfloat pow3( const in float x ) { return x*x*x; }\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\nfloat max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); }\nfloat average( const in vec3 v ) { return dot( v, vec3( 0.3333333 ) ); }\nhighp float rand( const in vec2 uv ) {\n\tconst highp float a = 12.9898, b = 78.233, c = 43758.5453;\n\thighp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n\treturn fract( sin( sn ) * c );\n}\n#ifdef HIGH_PRECISION\n\tfloat precisionSafeLength( vec3 v ) { return length( v ); }\n#else\n\tfloat precisionSafeLength( vec3 v ) {\n\t\tfloat maxComponent = max3( abs( v ) );\n\t\treturn length( v / maxComponent ) * maxComponent;\n\t}\n#endif\nstruct IncidentLight {\n\tvec3 color;\n\tvec3 direction;\n\tbool visible;\n};\nstruct ReflectedLight {\n\tvec3 directDiffuse;\n\tvec3 directSpecular;\n\tvec3 indirectDiffuse;\n\tvec3 indirectSpecular;\n};\n#ifdef USE_ALPHAHASH\n\tvarying vec3 vPosition;\n#endif\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n}\nvec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n}\nmat3 transposeMat3( const in mat3 m ) {\n\tmat3 tmp;\n\ttmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x );\n\ttmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y );\n\ttmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z );\n\treturn tmp;\n}\nbool isPerspectiveMatrix( mat4 m ) {\n\treturn m[ 2 ][ 3 ] == - 1.0;\n}\nvec2 equirectUv( in vec3 dir ) {\n\tfloat u = atan( dir.z, dir.x ) * RECIPROCAL_PI2 + 0.5;\n\tfloat v = asin( clamp( dir.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n\treturn vec2( u, v );\n}\nvec3 BRDF_Lambert( const in vec3 diffuseColor ) {\n\treturn RECIPROCAL_PI * diffuseColor;\n}\nvec3 F_Schlick( const in vec3 f0, const in float f90, const in float dotVH ) {\n\tfloat fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );\n\treturn f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );\n}\nfloat F_Schlick( const in float f0, const in float f90, const in float dotVH ) {\n\tfloat fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );\n\treturn f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );\n} // validated",cube_uv_reflection_fragment:"#ifdef ENVMAP_TYPE_CUBE_UV\n\t#define cubeUV_minMipLevel 4.0\n\t#define cubeUV_minTileSize 16.0\n\tfloat getFace( vec3 direction ) {\n\t\tvec3 absDirection = abs( direction );\n\t\tfloat face = - 1.0;\n\t\tif ( absDirection.x > absDirection.z ) {\n\t\t\tif ( absDirection.x > absDirection.y )\n\t\t\t\tface = direction.x > 0.0 ? 0.0 : 3.0;\n\t\t\telse\n\t\t\t\tface = direction.y > 0.0 ? 1.0 : 4.0;\n\t\t} else {\n\t\t\tif ( absDirection.z > absDirection.y )\n\t\t\t\tface = direction.z > 0.0 ? 2.0 : 5.0;\n\t\t\telse\n\t\t\t\tface = direction.y > 0.0 ? 1.0 : 4.0;\n\t\t}\n\t\treturn face;\n\t}\n\tvec2 getUV( vec3 direction, float face ) {\n\t\tvec2 uv;\n\t\tif ( face == 0.0 ) {\n\t\t\tuv = vec2( direction.z, direction.y ) / abs( direction.x );\n\t\t} else if ( face == 1.0 ) {\n\t\t\tuv = vec2( - direction.x, - direction.z ) / abs( direction.y );\n\t\t} else if ( face == 2.0 ) {\n\t\t\tuv = vec2( - direction.x, direction.y ) / abs( direction.z );\n\t\t} else if ( face == 3.0 ) {\n\t\t\tuv = vec2( - direction.z, direction.y ) / abs( direction.x );\n\t\t} else if ( face == 4.0 ) {\n\t\t\tuv = vec2( - direction.x, direction.z ) / abs( direction.y );\n\t\t} else {\n\t\t\tuv = vec2( direction.x, direction.y ) / abs( direction.z );\n\t\t}\n\t\treturn 0.5 * ( uv + 1.0 );\n\t}\n\tvec3 bilinearCubeUV( sampler2D envMap, vec3 direction, float mipInt ) {\n\t\tfloat face = getFace( direction );\n\t\tfloat filterInt = max( cubeUV_minMipLevel - mipInt, 0.0 );\n\t\tmipInt = max( mipInt, cubeUV_minMipLevel );\n\t\tfloat faceSize = exp2( mipInt );\n\t\thighp vec2 uv = getUV( direction, face ) * ( faceSize - 2.0 ) + 1.0;\n\t\tif ( face > 2.0 ) {\n\t\t\tuv.y += faceSize;\n\t\t\tface -= 3.0;\n\t\t}\n\t\tuv.x += face * faceSize;\n\t\tuv.x += filterInt * 3.0 * cubeUV_minTileSize;\n\t\tuv.y += 4.0 * ( exp2( CUBEUV_MAX_MIP ) - faceSize );\n\t\tuv.x *= CUBEUV_TEXEL_WIDTH;\n\t\tuv.y *= CUBEUV_TEXEL_HEIGHT;\n\t\t#ifdef texture2DGradEXT\n\t\t\treturn texture2DGradEXT( envMap, uv, vec2( 0.0 ), vec2( 0.0 ) ).rgb;\n\t\t#else\n\t\t\treturn texture2D( envMap, uv ).rgb;\n\t\t#endif\n\t}\n\t#define cubeUV_r0 1.0\n\t#define cubeUV_m0 - 2.0\n\t#define cubeUV_r1 0.8\n\t#define cubeUV_m1 - 1.0\n\t#define cubeUV_r4 0.4\n\t#define cubeUV_m4 2.0\n\t#define cubeUV_r5 0.305\n\t#define cubeUV_m5 3.0\n\t#define cubeUV_r6 0.21\n\t#define cubeUV_m6 4.0\n\tfloat roughnessToMip( float roughness ) {\n\t\tfloat mip = 0.0;\n\t\tif ( roughness >= cubeUV_r1 ) {\n\t\t\tmip = ( cubeUV_r0 - roughness ) * ( cubeUV_m1 - cubeUV_m0 ) / ( cubeUV_r0 - cubeUV_r1 ) + cubeUV_m0;\n\t\t} else if ( roughness >= cubeUV_r4 ) {\n\t\t\tmip = ( cubeUV_r1 - roughness ) * ( cubeUV_m4 - cubeUV_m1 ) / ( cubeUV_r1 - cubeUV_r4 ) + cubeUV_m1;\n\t\t} else if ( roughness >= cubeUV_r5 ) {\n\t\t\tmip = ( cubeUV_r4 - roughness ) * ( cubeUV_m5 - cubeUV_m4 ) / ( cubeUV_r4 - cubeUV_r5 ) + cubeUV_m4;\n\t\t} else if ( roughness >= cubeUV_r6 ) {\n\t\t\tmip = ( cubeUV_r5 - roughness ) * ( cubeUV_m6 - cubeUV_m5 ) / ( cubeUV_r5 - cubeUV_r6 ) + cubeUV_m5;\n\t\t} else {\n\t\t\tmip = - 2.0 * log2( 1.16 * roughness );\t\t}\n\t\treturn mip;\n\t}\n\tvec4 textureCubeUV( sampler2D envMap, vec3 sampleDir, float roughness ) {\n\t\tfloat mip = clamp( roughnessToMip( roughness ), cubeUV_m0, CUBEUV_MAX_MIP );\n\t\tfloat mipF = fract( mip );\n\t\tfloat mipInt = floor( mip );\n\t\tvec3 color0 = bilinearCubeUV( envMap, sampleDir, mipInt );\n\t\tif ( mipF == 0.0 ) {\n\t\t\treturn vec4( color0, 1.0 );\n\t\t} else {\n\t\t\tvec3 color1 = bilinearCubeUV( envMap, sampleDir, mipInt + 1.0 );\n\t\t\treturn vec4( mix( color0, color1, mipF ), 1.0 );\n\t\t}\n\t}\n#endif",defaultnormal_vertex:"vec3 transformedNormal = objectNormal;\n#ifdef USE_TANGENT\n\tvec3 transformedTangent = objectTangent;\n#endif\n#ifdef USE_BATCHING\n\tmat3 bm = mat3( batchingMatrix );\n\ttransformedNormal /= vec3( dot( bm[ 0 ], bm[ 0 ] ), dot( bm[ 1 ], bm[ 1 ] ), dot( bm[ 2 ], bm[ 2 ] ) );\n\ttransformedNormal = bm * transformedNormal;\n\t#ifdef USE_TANGENT\n\t\ttransformedTangent = bm * transformedTangent;\n\t#endif\n#endif\n#ifdef USE_INSTANCING\n\tmat3 im = mat3( instanceMatrix );\n\ttransformedNormal /= vec3( dot( im[ 0 ], im[ 0 ] ), dot( im[ 1 ], im[ 1 ] ), dot( im[ 2 ], im[ 2 ] ) );\n\ttransformedNormal = im * transformedNormal;\n\t#ifdef USE_TANGENT\n\t\ttransformedTangent = im * transformedTangent;\n\t#endif\n#endif\ntransformedNormal = normalMatrix * transformedNormal;\n#ifdef FLIP_SIDED\n\ttransformedNormal = - transformedNormal;\n#endif\n#ifdef USE_TANGENT\n\ttransformedTangent = ( modelViewMatrix * vec4( transformedTangent, 0.0 ) ).xyz;\n\t#ifdef FLIP_SIDED\n\t\ttransformedTangent = - transformedTangent;\n\t#endif\n#endif",displacementmap_pars_vertex:"#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif",displacementmap_vertex:"#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vDisplacementMapUv ).x * displacementScale + displacementBias );\n#endif",emissivemap_fragment:"#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vEmissiveMapUv );\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif",emissivemap_pars_fragment:"#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif",colorspace_fragment:"gl_FragColor = linearToOutputTexel( gl_FragColor );",colorspace_pars_fragment:"\nconst mat3 LINEAR_SRGB_TO_LINEAR_DISPLAY_P3 = mat3(\n\tvec3( 0.8224621, 0.177538, 0.0 ),\n\tvec3( 0.0331941, 0.9668058, 0.0 ),\n\tvec3( 0.0170827, 0.0723974, 0.9105199 )\n);\nconst mat3 LINEAR_DISPLAY_P3_TO_LINEAR_SRGB = mat3(\n\tvec3( 1.2249401, - 0.2249404, 0.0 ),\n\tvec3( - 0.0420569, 1.0420571, 0.0 ),\n\tvec3( - 0.0196376, - 0.0786361, 1.0982735 )\n);\nvec4 LinearSRGBToLinearDisplayP3( in vec4 value ) {\n\treturn vec4( value.rgb * LINEAR_SRGB_TO_LINEAR_DISPLAY_P3, value.a );\n}\nvec4 LinearDisplayP3ToLinearSRGB( in vec4 value ) {\n\treturn vec4( value.rgb * LINEAR_DISPLAY_P3_TO_LINEAR_SRGB, value.a );\n}\nvec4 LinearTransferOETF( in vec4 value ) {\n\treturn value;\n}\nvec4 sRGBTransferOETF( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a );\n}",envmap_fragment:"#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvec3 cameraToFrag;\n\t\tif ( isOrthographic ) {\n\t\t\tcameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\t\t} else {\n\t\t\tcameraToFrag = normalize( vWorldPosition - cameraPosition );\n\t\t}\n\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( cameraToFrag, worldNormal );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio );\n\t\t#endif\n\t#else\n\t\tvec3 reflectVec = vReflect;\n\t#endif\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tvec4 envColor = textureCube( envMap, envMapRotation * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\n\t#else\n\t\tvec4 envColor = vec4( 0.0 );\n\t#endif\n\t#ifdef ENVMAP_BLENDING_MULTIPLY\n\t\toutgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_MIX )\n\t\toutgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_ADD )\n\t\toutgoingLight += envColor.xyz * specularStrength * reflectivity;\n\t#endif\n#endif",envmap_common_pars_fragment:"#ifdef USE_ENVMAP\n\tuniform float envMapIntensity;\n\tuniform float flipEnvMap;\n\tuniform mat3 envMapRotation;\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tuniform samplerCube envMap;\n\t#else\n\t\tuniform sampler2D envMap;\n\t#endif\n\t\n#endif",envmap_pars_fragment:"#ifdef USE_ENVMAP\n\tuniform float reflectivity;\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )\n\t\t#define ENV_WORLDPOS\n\t#endif\n\t#ifdef ENV_WORLDPOS\n\t\tvarying vec3 vWorldPosition;\n\t\tuniform float refractionRatio;\n\t#else\n\t\tvarying vec3 vReflect;\n\t#endif\n#endif",envmap_pars_vertex:"#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )\n\t\t#define ENV_WORLDPOS\n\t#endif\n\t#ifdef ENV_WORLDPOS\n\t\t\n\t\tvarying vec3 vWorldPosition;\n\t#else\n\t\tvarying vec3 vReflect;\n\t\tuniform float refractionRatio;\n\t#endif\n#endif",envmap_physical_pars_fragment:"#ifdef USE_ENVMAP\n\tvec3 getIBLIrradiance( const in vec3 normal ) {\n\t\t#ifdef ENVMAP_TYPE_CUBE_UV\n\t\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, envMapRotation * worldNormal, 1.0 );\n\t\t\treturn PI * envMapColor.rgb * envMapIntensity;\n\t\t#else\n\t\t\treturn vec3( 0.0 );\n\t\t#endif\n\t}\n\tvec3 getIBLRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness ) {\n\t\t#ifdef ENVMAP_TYPE_CUBE_UV\n\t\t\tvec3 reflectVec = reflect( - viewDir, normal );\n\t\t\treflectVec = normalize( mix( reflectVec, normal, roughness * roughness) );\n\t\t\treflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, envMapRotation * reflectVec, roughness );\n\t\t\treturn envMapColor.rgb * envMapIntensity;\n\t\t#else\n\t\t\treturn vec3( 0.0 );\n\t\t#endif\n\t}\n\t#ifdef USE_ANISOTROPY\n\t\tvec3 getIBLAnisotropyRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in vec3 bitangent, const in float anisotropy ) {\n\t\t\t#ifdef ENVMAP_TYPE_CUBE_UV\n\t\t\t\tvec3 bentNormal = cross( bitangent, viewDir );\n\t\t\t\tbentNormal = normalize( cross( bentNormal, bitangent ) );\n\t\t\t\tbentNormal = normalize( mix( bentNormal, normal, pow2( pow2( 1.0 - anisotropy * ( 1.0 - roughness ) ) ) ) );\n\t\t\t\treturn getIBLRadiance( viewDir, bentNormal, roughness );\n\t\t\t#else\n\t\t\t\treturn vec3( 0.0 );\n\t\t\t#endif\n\t\t}\n\t#endif\n#endif",envmap_vertex:"#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvWorldPosition = worldPosition.xyz;\n\t#else\n\t\tvec3 cameraToVertex;\n\t\tif ( isOrthographic ) {\n\t\t\tcameraToVertex = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\t\t} else {\n\t\t\tcameraToVertex = normalize( worldPosition.xyz - cameraPosition );\n\t\t}\n\t\tvec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvReflect = reflect( cameraToVertex, worldNormal );\n\t\t#else\n\t\t\tvReflect = refract( cameraToVertex, worldNormal, refractionRatio );\n\t\t#endif\n\t#endif\n#endif",fog_vertex:"#ifdef USE_FOG\n\tvFogDepth = - mvPosition.z;\n#endif",fog_pars_vertex:"#ifdef USE_FOG\n\tvarying float vFogDepth;\n#endif",fog_fragment:"#ifdef USE_FOG\n\t#ifdef FOG_EXP2\n\t\tfloat fogFactor = 1.0 - exp( - fogDensity * fogDensity * vFogDepth * vFogDepth );\n\t#else\n\t\tfloat fogFactor = smoothstep( fogNear, fogFar, vFogDepth );\n\t#endif\n\tgl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );\n#endif",fog_pars_fragment:"#ifdef USE_FOG\n\tuniform vec3 fogColor;\n\tvarying float vFogDepth;\n\t#ifdef FOG_EXP2\n\t\tuniform float fogDensity;\n\t#else\n\t\tuniform float fogNear;\n\t\tuniform float fogFar;\n\t#endif\n#endif",gradientmap_pars_fragment:"#ifdef USE_GRADIENTMAP\n\tuniform sampler2D gradientMap;\n#endif\nvec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {\n\tfloat dotNL = dot( normal, lightDirection );\n\tvec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 );\n\t#ifdef USE_GRADIENTMAP\n\t\treturn vec3( texture2D( gradientMap, coord ).r );\n\t#else\n\t\tvec2 fw = fwidth( coord ) * 0.5;\n\t\treturn mix( vec3( 0.7 ), vec3( 1.0 ), smoothstep( 0.7 - fw.x, 0.7 + fw.x, coord.x ) );\n\t#endif\n}",lightmap_pars_fragment:"#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif",lights_lambert_fragment:"LambertMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularStrength = specularStrength;",lights_lambert_pars_fragment:"varying vec3 vViewPosition;\nstruct LambertMaterial {\n\tvec3 diffuseColor;\n\tfloat specularStrength;\n};\nvoid RE_Direct_Lambert( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometryNormal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Lambert( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_Lambert\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Lambert",lights_pars_begin:"uniform bool receiveShadow;\nuniform vec3 ambientLightColor;\n#if defined( USE_LIGHT_PROBES )\n\tuniform vec3 lightProbe[ 9 ];\n#endif\nvec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {\n\tfloat x = normal.x, y = normal.y, z = normal.z;\n\tvec3 result = shCoefficients[ 0 ] * 0.886227;\n\tresult += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;\n\tresult += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;\n\tresult += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;\n\tresult += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;\n\tresult += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;\n\tresult += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );\n\tresult += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;\n\tresult += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );\n\treturn result;\n}\nvec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in vec3 normal ) {\n\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\tvec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );\n\treturn irradiance;\n}\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\n\tvec3 irradiance = ambientLightColor;\n\treturn irradiance;\n}\nfloat getDistanceAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n\tfloat distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n\tif ( cutoffDistance > 0.0 ) {\n\t\tdistanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n\t}\n\treturn distanceFalloff;\n}\nfloat getSpotAttenuation( const in float coneCosine, const in float penumbraCosine, const in float angleCosine ) {\n\treturn smoothstep( coneCosine, penumbraCosine, angleCosine );\n}\n#if NUM_DIR_LIGHTS > 0\n\tstruct DirectionalLight {\n\t\tvec3 direction;\n\t\tvec3 color;\n\t};\n\tuniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n\tvoid getDirectionalLightInfo( const in DirectionalLight directionalLight, out IncidentLight light ) {\n\t\tlight.color = directionalLight.color;\n\t\tlight.direction = directionalLight.direction;\n\t\tlight.visible = true;\n\t}\n#endif\n#if NUM_POINT_LIGHTS > 0\n\tstruct PointLight {\n\t\tvec3 position;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t};\n\tuniform PointLight pointLights[ NUM_POINT_LIGHTS ];\n\tvoid getPointLightInfo( const in PointLight pointLight, const in vec3 geometryPosition, out IncidentLight light ) {\n\t\tvec3 lVector = pointLight.position - geometryPosition;\n\t\tlight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tlight.color = pointLight.color;\n\t\tlight.color *= getDistanceAttenuation( lightDistance, pointLight.distance, pointLight.decay );\n\t\tlight.visible = ( light.color != vec3( 0.0 ) );\n\t}\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\tstruct SpotLight {\n\t\tvec3 position;\n\t\tvec3 direction;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t\tfloat coneCos;\n\t\tfloat penumbraCos;\n\t};\n\tuniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];\n\tvoid getSpotLightInfo( const in SpotLight spotLight, const in vec3 geometryPosition, out IncidentLight light ) {\n\t\tvec3 lVector = spotLight.position - geometryPosition;\n\t\tlight.direction = normalize( lVector );\n\t\tfloat angleCos = dot( light.direction, spotLight.direction );\n\t\tfloat spotAttenuation = getSpotAttenuation( spotLight.coneCos, spotLight.penumbraCos, angleCos );\n\t\tif ( spotAttenuation > 0.0 ) {\n\t\t\tfloat lightDistance = length( lVector );\n\t\t\tlight.color = spotLight.color * spotAttenuation;\n\t\t\tlight.color *= getDistanceAttenuation( lightDistance, spotLight.distance, spotLight.decay );\n\t\t\tlight.visible = ( light.color != vec3( 0.0 ) );\n\t\t} else {\n\t\t\tlight.color = vec3( 0.0 );\n\t\t\tlight.visible = false;\n\t\t}\n\t}\n#endif\n#if NUM_RECT_AREA_LIGHTS > 0\n\tstruct RectAreaLight {\n\t\tvec3 color;\n\t\tvec3 position;\n\t\tvec3 halfWidth;\n\t\tvec3 halfHeight;\n\t};\n\tuniform sampler2D ltc_1;\tuniform sampler2D ltc_2;\n\tuniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\tstruct HemisphereLight {\n\t\tvec3 direction;\n\t\tvec3 skyColor;\n\t\tvec3 groundColor;\n\t};\n\tuniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];\n\tvec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in vec3 normal ) {\n\t\tfloat dotNL = dot( normal, hemiLight.direction );\n\t\tfloat hemiDiffuseWeight = 0.5 * dotNL + 0.5;\n\t\tvec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\n\t\treturn irradiance;\n\t}\n#endif",lights_toon_fragment:"ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;",lights_toon_pars_fragment:"varying vec3 vViewPosition;\nstruct ToonMaterial {\n\tvec3 diffuseColor;\n};\nvoid RE_Direct_Toon( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\n\tvec3 irradiance = getGradientIrradiance( geometryNormal, directLight.direction ) * directLight.color;\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Toon( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_Toon\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Toon",lights_phong_fragment:"BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;",lights_phong_pars_fragment:"varying vec3 vViewPosition;\nstruct BlinnPhongMaterial {\n\tvec3 diffuseColor;\n\tvec3 specularColor;\n\tfloat specularShininess;\n\tfloat specularStrength;\n};\nvoid RE_Direct_BlinnPhong( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometryNormal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n\treflectedLight.directSpecular += irradiance * BRDF_BlinnPhong( directLight.direction, geometryViewDir, geometryNormal, material.specularColor, material.specularShininess ) * material.specularStrength;\n}\nvoid RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_BlinnPhong\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_BlinnPhong",lights_physical_fragment:"PhysicalMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );\nvec3 dxy = max( abs( dFdx( nonPerturbedNormal ) ), abs( dFdy( nonPerturbedNormal ) ) );\nfloat geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );\nmaterial.roughness = max( roughnessFactor, 0.0525 );material.roughness += geometryRoughness;\nmaterial.roughness = min( material.roughness, 1.0 );\n#ifdef IOR\n\tmaterial.ior = ior;\n\t#ifdef USE_SPECULAR\n\t\tfloat specularIntensityFactor = specularIntensity;\n\t\tvec3 specularColorFactor = specularColor;\n\t\t#ifdef USE_SPECULAR_COLORMAP\n\t\t\tspecularColorFactor *= texture2D( specularColorMap, vSpecularColorMapUv ).rgb;\n\t\t#endif\n\t\t#ifdef USE_SPECULAR_INTENSITYMAP\n\t\t\tspecularIntensityFactor *= texture2D( specularIntensityMap, vSpecularIntensityMapUv ).a;\n\t\t#endif\n\t\tmaterial.specularF90 = mix( specularIntensityFactor, 1.0, metalnessFactor );\n\t#else\n\t\tfloat specularIntensityFactor = 1.0;\n\t\tvec3 specularColorFactor = vec3( 1.0 );\n\t\tmaterial.specularF90 = 1.0;\n\t#endif\n\tmaterial.specularColor = mix( min( pow2( ( material.ior - 1.0 ) / ( material.ior + 1.0 ) ) * specularColorFactor, vec3( 1.0 ) ) * specularIntensityFactor, diffuseColor.rgb, metalnessFactor );\n#else\n\tmaterial.specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );\n\tmaterial.specularF90 = 1.0;\n#endif\n#ifdef USE_CLEARCOAT\n\tmaterial.clearcoat = clearcoat;\n\tmaterial.clearcoatRoughness = clearcoatRoughness;\n\tmaterial.clearcoatF0 = vec3( 0.04 );\n\tmaterial.clearcoatF90 = 1.0;\n\t#ifdef USE_CLEARCOATMAP\n\t\tmaterial.clearcoat *= texture2D( clearcoatMap, vClearcoatMapUv ).x;\n\t#endif\n\t#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\t\tmaterial.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vClearcoatRoughnessMapUv ).y;\n\t#endif\n\tmaterial.clearcoat = saturate( material.clearcoat );\tmaterial.clearcoatRoughness = max( material.clearcoatRoughness, 0.0525 );\n\tmaterial.clearcoatRoughness += geometryRoughness;\n\tmaterial.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 );\n#endif\n#ifdef USE_DISPERSION\n\tmaterial.dispersion = dispersion;\n#endif\n#ifdef USE_IRIDESCENCE\n\tmaterial.iridescence = iridescence;\n\tmaterial.iridescenceIOR = iridescenceIOR;\n\t#ifdef USE_IRIDESCENCEMAP\n\t\tmaterial.iridescence *= texture2D( iridescenceMap, vIridescenceMapUv ).r;\n\t#endif\n\t#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\t\tmaterial.iridescenceThickness = (iridescenceThicknessMaximum - iridescenceThicknessMinimum) * texture2D( iridescenceThicknessMap, vIridescenceThicknessMapUv ).g + iridescenceThicknessMinimum;\n\t#else\n\t\tmaterial.iridescenceThickness = iridescenceThicknessMaximum;\n\t#endif\n#endif\n#ifdef USE_SHEEN\n\tmaterial.sheenColor = sheenColor;\n\t#ifdef USE_SHEEN_COLORMAP\n\t\tmaterial.sheenColor *= texture2D( sheenColorMap, vSheenColorMapUv ).rgb;\n\t#endif\n\tmaterial.sheenRoughness = clamp( sheenRoughness, 0.07, 1.0 );\n\t#ifdef USE_SHEEN_ROUGHNESSMAP\n\t\tmaterial.sheenRoughness *= texture2D( sheenRoughnessMap, vSheenRoughnessMapUv ).a;\n\t#endif\n#endif\n#ifdef USE_ANISOTROPY\n\t#ifdef USE_ANISOTROPYMAP\n\t\tmat2 anisotropyMat = mat2( anisotropyVector.x, anisotropyVector.y, - anisotropyVector.y, anisotropyVector.x );\n\t\tvec3 anisotropyPolar = texture2D( anisotropyMap, vAnisotropyMapUv ).rgb;\n\t\tvec2 anisotropyV = anisotropyMat * normalize( 2.0 * anisotropyPolar.rg - vec2( 1.0 ) ) * anisotropyPolar.b;\n\t#else\n\t\tvec2 anisotropyV = anisotropyVector;\n\t#endif\n\tmaterial.anisotropy = length( anisotropyV );\n\tif( material.anisotropy == 0.0 ) {\n\t\tanisotropyV = vec2( 1.0, 0.0 );\n\t} else {\n\t\tanisotropyV /= material.anisotropy;\n\t\tmaterial.anisotropy = saturate( material.anisotropy );\n\t}\n\tmaterial.alphaT = mix( pow2( material.roughness ), 1.0, pow2( material.anisotropy ) );\n\tmaterial.anisotropyT = tbn[ 0 ] * anisotropyV.x + tbn[ 1 ] * anisotropyV.y;\n\tmaterial.anisotropyB = tbn[ 1 ] * anisotropyV.x - tbn[ 0 ] * anisotropyV.y;\n#endif",lights_physical_pars_fragment:"struct PhysicalMaterial {\n\tvec3 diffuseColor;\n\tfloat roughness;\n\tvec3 specularColor;\n\tfloat specularF90;\n\tfloat dispersion;\n\t#ifdef USE_CLEARCOAT\n\t\tfloat clearcoat;\n\t\tfloat clearcoatRoughness;\n\t\tvec3 clearcoatF0;\n\t\tfloat clearcoatF90;\n\t#endif\n\t#ifdef USE_IRIDESCENCE\n\t\tfloat iridescence;\n\t\tfloat iridescenceIOR;\n\t\tfloat iridescenceThickness;\n\t\tvec3 iridescenceFresnel;\n\t\tvec3 iridescenceF0;\n\t#endif\n\t#ifdef USE_SHEEN\n\t\tvec3 sheenColor;\n\t\tfloat sheenRoughness;\n\t#endif\n\t#ifdef IOR\n\t\tfloat ior;\n\t#endif\n\t#ifdef USE_TRANSMISSION\n\t\tfloat transmission;\n\t\tfloat transmissionAlpha;\n\t\tfloat thickness;\n\t\tfloat attenuationDistance;\n\t\tvec3 attenuationColor;\n\t#endif\n\t#ifdef USE_ANISOTROPY\n\t\tfloat anisotropy;\n\t\tfloat alphaT;\n\t\tvec3 anisotropyT;\n\t\tvec3 anisotropyB;\n\t#endif\n};\nvec3 clearcoatSpecularDirect = vec3( 0.0 );\nvec3 clearcoatSpecularIndirect = vec3( 0.0 );\nvec3 sheenSpecularDirect = vec3( 0.0 );\nvec3 sheenSpecularIndirect = vec3(0.0 );\nvec3 Schlick_to_F0( const in vec3 f, const in float f90, const in float dotVH ) {\n float x = clamp( 1.0 - dotVH, 0.0, 1.0 );\n float x2 = x * x;\n float x5 = clamp( x * x2 * x2, 0.0, 0.9999 );\n return ( f - vec3( f90 ) * x5 ) / ( 1.0 - x5 );\n}\nfloat V_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\tfloat gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\treturn 0.5 / max( gv + gl, EPSILON );\n}\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n\tfloat a2 = pow2( alpha );\n\tfloat denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;\n\treturn RECIPROCAL_PI * a2 / pow2( denom );\n}\n#ifdef USE_ANISOTROPY\n\tfloat V_GGX_SmithCorrelated_Anisotropic( const in float alphaT, const in float alphaB, const in float dotTV, const in float dotBV, const in float dotTL, const in float dotBL, const in float dotNV, const in float dotNL ) {\n\t\tfloat gv = dotNL * length( vec3( alphaT * dotTV, alphaB * dotBV, dotNV ) );\n\t\tfloat gl = dotNV * length( vec3( alphaT * dotTL, alphaB * dotBL, dotNL ) );\n\t\tfloat v = 0.5 / ( gv + gl );\n\t\treturn saturate(v);\n\t}\n\tfloat D_GGX_Anisotropic( const in float alphaT, const in float alphaB, const in float dotNH, const in float dotTH, const in float dotBH ) {\n\t\tfloat a2 = alphaT * alphaB;\n\t\thighp vec3 v = vec3( alphaB * dotTH, alphaT * dotBH, a2 * dotNH );\n\t\thighp float v2 = dot( v, v );\n\t\tfloat w2 = a2 / v2;\n\t\treturn RECIPROCAL_PI * a2 * pow2 ( w2 );\n\t}\n#endif\n#ifdef USE_CLEARCOAT\n\tvec3 BRDF_GGX_Clearcoat( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material) {\n\t\tvec3 f0 = material.clearcoatF0;\n\t\tfloat f90 = material.clearcoatF90;\n\t\tfloat roughness = material.clearcoatRoughness;\n\t\tfloat alpha = pow2( roughness );\n\t\tvec3 halfDir = normalize( lightDir + viewDir );\n\t\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\t\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\t\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\t\tfloat dotVH = saturate( dot( viewDir, halfDir ) );\n\t\tvec3 F = F_Schlick( f0, f90, dotVH );\n\t\tfloat V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\t\tfloat D = D_GGX( alpha, dotNH );\n\t\treturn F * ( V * D );\n\t}\n#endif\nvec3 BRDF_GGX( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material ) {\n\tvec3 f0 = material.specularColor;\n\tfloat f90 = material.specularF90;\n\tfloat roughness = material.roughness;\n\tfloat alpha = pow2( roughness );\n\tvec3 halfDir = normalize( lightDir + viewDir );\n\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat dotVH = saturate( dot( viewDir, halfDir ) );\n\tvec3 F = F_Schlick( f0, f90, dotVH );\n\t#ifdef USE_IRIDESCENCE\n\t\tF = mix( F, material.iridescenceFresnel, material.iridescence );\n\t#endif\n\t#ifdef USE_ANISOTROPY\n\t\tfloat dotTL = dot( material.anisotropyT, lightDir );\n\t\tfloat dotTV = dot( material.anisotropyT, viewDir );\n\t\tfloat dotTH = dot( material.anisotropyT, halfDir );\n\t\tfloat dotBL = dot( material.anisotropyB, lightDir );\n\t\tfloat dotBV = dot( material.anisotropyB, viewDir );\n\t\tfloat dotBH = dot( material.anisotropyB, halfDir );\n\t\tfloat V = V_GGX_SmithCorrelated_Anisotropic( material.alphaT, alpha, dotTV, dotBV, dotTL, dotBL, dotNV, dotNL );\n\t\tfloat D = D_GGX_Anisotropic( material.alphaT, alpha, dotNH, dotTH, dotBH );\n\t#else\n\t\tfloat V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\t\tfloat D = D_GGX( alpha, dotNH );\n\t#endif\n\treturn F * ( V * D );\n}\nvec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {\n\tconst float LUT_SIZE = 64.0;\n\tconst float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n\tconst float LUT_BIAS = 0.5 / LUT_SIZE;\n\tfloat dotNV = saturate( dot( N, V ) );\n\tvec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );\n\tuv = uv * LUT_SCALE + LUT_BIAS;\n\treturn uv;\n}\nfloat LTC_ClippedSphereFormFactor( const in vec3 f ) {\n\tfloat l = length( f );\n\treturn max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );\n}\nvec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {\n\tfloat x = dot( v1, v2 );\n\tfloat y = abs( x );\n\tfloat a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;\n\tfloat b = 3.4175940 + ( 4.1616724 + y ) * y;\n\tfloat v = a / b;\n\tfloat theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;\n\treturn cross( v1, v2 ) * theta_sintheta;\n}\nvec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {\n\tvec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];\n\tvec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];\n\tvec3 lightNormal = cross( v1, v2 );\n\tif( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );\n\tvec3 T1, T2;\n\tT1 = normalize( V - N * dot( V, N ) );\n\tT2 = - cross( N, T1 );\n\tmat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) );\n\tvec3 coords[ 4 ];\n\tcoords[ 0 ] = mat * ( rectCoords[ 0 ] - P );\n\tcoords[ 1 ] = mat * ( rectCoords[ 1 ] - P );\n\tcoords[ 2 ] = mat * ( rectCoords[ 2 ] - P );\n\tcoords[ 3 ] = mat * ( rectCoords[ 3 ] - P );\n\tcoords[ 0 ] = normalize( coords[ 0 ] );\n\tcoords[ 1 ] = normalize( coords[ 1 ] );\n\tcoords[ 2 ] = normalize( coords[ 2 ] );\n\tcoords[ 3 ] = normalize( coords[ 3 ] );\n\tvec3 vectorFormFactor = vec3( 0.0 );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );\n\tfloat result = LTC_ClippedSphereFormFactor( vectorFormFactor );\n\treturn vec3( result );\n}\n#if defined( USE_SHEEN )\nfloat D_Charlie( float roughness, float dotNH ) {\n\tfloat alpha = pow2( roughness );\n\tfloat invAlpha = 1.0 / alpha;\n\tfloat cos2h = dotNH * dotNH;\n\tfloat sin2h = max( 1.0 - cos2h, 0.0078125 );\n\treturn ( 2.0 + invAlpha ) * pow( sin2h, invAlpha * 0.5 ) / ( 2.0 * PI );\n}\nfloat V_Neubelt( float dotNV, float dotNL ) {\n\treturn saturate( 1.0 / ( 4.0 * ( dotNL + dotNV - dotNL * dotNV ) ) );\n}\nvec3 BRDF_Sheen( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, vec3 sheenColor, const in float sheenRoughness ) {\n\tvec3 halfDir = normalize( lightDir + viewDir );\n\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat D = D_Charlie( sheenRoughness, dotNH );\n\tfloat V = V_Neubelt( dotNV, dotNL );\n\treturn sheenColor * ( D * V );\n}\n#endif\nfloat IBLSheenBRDF( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat r2 = roughness * roughness;\n\tfloat a = roughness < 0.25 ? -339.2 * r2 + 161.4 * roughness - 25.9 : -8.48 * r2 + 14.3 * roughness - 9.95;\n\tfloat b = roughness < 0.25 ? 44.0 * r2 - 23.7 * roughness + 3.26 : 1.97 * r2 - 3.27 * roughness + 0.72;\n\tfloat DG = exp( a * dotNV + b ) + ( roughness < 0.25 ? 0.0 : 0.1 * ( roughness - 0.25 ) );\n\treturn saturate( DG * RECIPROCAL_PI );\n}\nvec2 DFGApprox( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tconst vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n\tconst vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n\tvec4 r = roughness * c0 + c1;\n\tfloat a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n\tvec2 fab = vec2( - 1.04, 1.04 ) * a004 + r.zw;\n\treturn fab;\n}\nvec3 EnvironmentBRDF( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness ) {\n\tvec2 fab = DFGApprox( normal, viewDir, roughness );\n\treturn specularColor * fab.x + specularF90 * fab.y;\n}\n#ifdef USE_IRIDESCENCE\nvoid computeMultiscatteringIridescence( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float iridescence, const in vec3 iridescenceF0, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n#else\nvoid computeMultiscattering( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n#endif\n\tvec2 fab = DFGApprox( normal, viewDir, roughness );\n\t#ifdef USE_IRIDESCENCE\n\t\tvec3 Fr = mix( specularColor, iridescenceF0, iridescence );\n\t#else\n\t\tvec3 Fr = specularColor;\n\t#endif\n\tvec3 FssEss = Fr * fab.x + specularF90 * fab.y;\n\tfloat Ess = fab.x + fab.y;\n\tfloat Ems = 1.0 - Ess;\n\tvec3 Favg = Fr + ( 1.0 - Fr ) * 0.047619;\tvec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );\n\tsingleScatter += FssEss;\n\tmultiScatter += Fms * Ems;\n}\n#if NUM_RECT_AREA_LIGHTS > 0\n\tvoid RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\t\tvec3 normal = geometryNormal;\n\t\tvec3 viewDir = geometryViewDir;\n\t\tvec3 position = geometryPosition;\n\t\tvec3 lightPos = rectAreaLight.position;\n\t\tvec3 halfWidth = rectAreaLight.halfWidth;\n\t\tvec3 halfHeight = rectAreaLight.halfHeight;\n\t\tvec3 lightColor = rectAreaLight.color;\n\t\tfloat roughness = material.roughness;\n\t\tvec3 rectCoords[ 4 ];\n\t\trectCoords[ 0 ] = lightPos + halfWidth - halfHeight;\t\trectCoords[ 1 ] = lightPos - halfWidth - halfHeight;\n\t\trectCoords[ 2 ] = lightPos - halfWidth + halfHeight;\n\t\trectCoords[ 3 ] = lightPos + halfWidth + halfHeight;\n\t\tvec2 uv = LTC_Uv( normal, viewDir, roughness );\n\t\tvec4 t1 = texture2D( ltc_1, uv );\n\t\tvec4 t2 = texture2D( ltc_2, uv );\n\t\tmat3 mInv = mat3(\n\t\t\tvec3( t1.x, 0, t1.y ),\n\t\t\tvec3( 0, 1, 0 ),\n\t\t\tvec3( t1.z, 0, t1.w )\n\t\t);\n\t\tvec3 fresnel = ( material.specularColor * t2.x + ( vec3( 1.0 ) - material.specularColor ) * t2.y );\n\t\treflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );\n\t\treflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );\n\t}\n#endif\nvoid RE_Direct_Physical( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometryNormal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\t#ifdef USE_CLEARCOAT\n\t\tfloat dotNLcc = saturate( dot( geometryClearcoatNormal, directLight.direction ) );\n\t\tvec3 ccIrradiance = dotNLcc * directLight.color;\n\t\tclearcoatSpecularDirect += ccIrradiance * BRDF_GGX_Clearcoat( directLight.direction, geometryViewDir, geometryClearcoatNormal, material );\n\t#endif\n\t#ifdef USE_SHEEN\n\t\tsheenSpecularDirect += irradiance * BRDF_Sheen( directLight.direction, geometryViewDir, geometryNormal, material.sheenColor, material.sheenRoughness );\n\t#endif\n\treflectedLight.directSpecular += irradiance * BRDF_GGX( directLight.direction, geometryViewDir, geometryNormal, material );\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearcoatRadiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) {\n\t#ifdef USE_CLEARCOAT\n\t\tclearcoatSpecularIndirect += clearcoatRadiance * EnvironmentBRDF( geometryClearcoatNormal, geometryViewDir, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness );\n\t#endif\n\t#ifdef USE_SHEEN\n\t\tsheenSpecularIndirect += irradiance * material.sheenColor * IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness );\n\t#endif\n\tvec3 singleScattering = vec3( 0.0 );\n\tvec3 multiScattering = vec3( 0.0 );\n\tvec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;\n\t#ifdef USE_IRIDESCENCE\n\t\tcomputeMultiscatteringIridescence( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.iridescence, material.iridescenceFresnel, material.roughness, singleScattering, multiScattering );\n\t#else\n\t\tcomputeMultiscattering( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.roughness, singleScattering, multiScattering );\n\t#endif\n\tvec3 totalScattering = singleScattering + multiScattering;\n\tvec3 diffuse = material.diffuseColor * ( 1.0 - max( max( totalScattering.r, totalScattering.g ), totalScattering.b ) );\n\treflectedLight.indirectSpecular += radiance * singleScattering;\n\treflectedLight.indirectSpecular += multiScattering * cosineWeightedIrradiance;\n\treflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance;\n}\n#define RE_Direct\t\t\t\tRE_Direct_Physical\n#define RE_Direct_RectArea\t\tRE_Direct_RectArea_Physical\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Physical\n#define RE_IndirectSpecular\t\tRE_IndirectSpecular_Physical\nfloat computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {\n\treturn saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );\n}",lights_fragment_begin:"\nvec3 geometryPosition = - vViewPosition;\nvec3 geometryNormal = normal;\nvec3 geometryViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );\nvec3 geometryClearcoatNormal = vec3( 0.0 );\n#ifdef USE_CLEARCOAT\n\tgeometryClearcoatNormal = clearcoatNormal;\n#endif\n#ifdef USE_IRIDESCENCE\n\tfloat dotNVi = saturate( dot( normal, geometryViewDir ) );\n\tif ( material.iridescenceThickness == 0.0 ) {\n\t\tmaterial.iridescence = 0.0;\n\t} else {\n\t\tmaterial.iridescence = saturate( material.iridescence );\n\t}\n\tif ( material.iridescence > 0.0 ) {\n\t\tmaterial.iridescenceFresnel = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.specularColor );\n\t\tmaterial.iridescenceF0 = Schlick_to_F0( material.iridescenceFresnel, 1.0, dotNVi );\n\t}\n#endif\nIncidentLight directLight;\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n\tPointLight pointLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tpointLight = pointLights[ i ];\n\t\tgetPointLightInfo( pointLight, geometryPosition, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )\n\t\tpointLightShadow = pointLightShadows[ i ];\n\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowIntensity, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n\tSpotLight spotLight;\n\tvec4 spotColor;\n\tvec3 spotLightCoord;\n\tbool inSpotLightMap;\n\t#if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tspotLight = spotLights[ i ];\n\t\tgetSpotLightInfo( spotLight, geometryPosition, directLight );\n\t\t#if ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )\n\t\t#define SPOT_LIGHT_MAP_INDEX UNROLLED_LOOP_INDEX\n\t\t#elif ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\t#define SPOT_LIGHT_MAP_INDEX NUM_SPOT_LIGHT_MAPS\n\t\t#else\n\t\t#define SPOT_LIGHT_MAP_INDEX ( UNROLLED_LOOP_INDEX - NUM_SPOT_LIGHT_SHADOWS + NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )\n\t\t#endif\n\t\t#if ( SPOT_LIGHT_MAP_INDEX < NUM_SPOT_LIGHT_MAPS )\n\t\t\tspotLightCoord = vSpotLightCoord[ i ].xyz / vSpotLightCoord[ i ].w;\n\t\t\tinSpotLightMap = all( lessThan( abs( spotLightCoord * 2. - 1. ), vec3( 1.0 ) ) );\n\t\t\tspotColor = texture2D( spotLightMap[ SPOT_LIGHT_MAP_INDEX ], spotLightCoord.xy );\n\t\t\tdirectLight.color = inSpotLightMap ? directLight.color * spotColor.rgb : directLight.color;\n\t\t#endif\n\t\t#undef SPOT_LIGHT_MAP_INDEX\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\tspotLightShadow = spotLightShadows[ i ];\n\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowIntensity, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n\tDirectionalLight directionalLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tdirectionalLight = directionalLights[ i ];\n\t\tgetDirectionalLightInfo( directionalLight, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n\t\tdirectionalLightShadow = directionalLightShadows[ i ];\n\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n\tRectAreaLight rectAreaLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\n\t\trectAreaLight = rectAreaLights[ i ];\n\t\tRE_Direct_RectArea( rectAreaLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if defined( RE_IndirectDiffuse )\n\tvec3 iblIrradiance = vec3( 0.0 );\n\tvec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n\t#if defined( USE_LIGHT_PROBES )\n\t\tirradiance += getLightProbeIrradiance( lightProbe, geometryNormal );\n\t#endif\n\t#if ( NUM_HEMI_LIGHTS > 0 )\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\t\tirradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometryNormal );\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n#endif\n#if defined( RE_IndirectSpecular )\n\tvec3 radiance = vec3( 0.0 );\n\tvec3 clearcoatRadiance = vec3( 0.0 );\n#endif",lights_fragment_maps:"#if defined( RE_IndirectDiffuse )\n\t#ifdef USE_LIGHTMAP\n\t\tvec4 lightMapTexel = texture2D( lightMap, vLightMapUv );\n\t\tvec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;\n\t\tirradiance += lightMapIrradiance;\n\t#endif\n\t#if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )\n\t\tiblIrradiance += getIBLIrradiance( geometryNormal );\n\t#endif\n#endif\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n\t#ifdef USE_ANISOTROPY\n\t\tradiance += getIBLAnisotropyRadiance( geometryViewDir, geometryNormal, material.roughness, material.anisotropyB, material.anisotropy );\n\t#else\n\t\tradiance += getIBLRadiance( geometryViewDir, geometryNormal, material.roughness );\n\t#endif\n\t#ifdef USE_CLEARCOAT\n\t\tclearcoatRadiance += getIBLRadiance( geometryViewDir, geometryClearcoatNormal, material.clearcoatRoughness );\n\t#endif\n#endif",lights_fragment_end:"#if defined( RE_IndirectDiffuse )\n\tRE_IndirectDiffuse( irradiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n#endif\n#if defined( RE_IndirectSpecular )\n\tRE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n#endif",logdepthbuf_fragment:"#if defined( USE_LOGDEPTHBUF )\n\tgl_FragDepth = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;\n#endif",logdepthbuf_pars_fragment:"#if defined( USE_LOGDEPTHBUF )\n\tuniform float logDepthBufFC;\n\tvarying float vFragDepth;\n\tvarying float vIsPerspective;\n#endif",logdepthbuf_pars_vertex:"#ifdef USE_LOGDEPTHBUF\n\tvarying float vFragDepth;\n\tvarying float vIsPerspective;\n#endif",logdepthbuf_vertex:"#ifdef USE_LOGDEPTHBUF\n\tvFragDepth = 1.0 + gl_Position.w;\n\tvIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) );\n#endif",map_fragment:"#ifdef USE_MAP\n#ifdef USE_MIPMAP_BIAS\n vec4 sampledDiffuseColor = texture2D( map, vMapUv, mipmapBias );\n#else\n\tvec4 sampledDiffuseColor = texture2D( map, vMapUv );\n#endif\n\t#ifdef DECODE_VIDEO_TEXTURE\n\t\tsampledDiffuseColor = vec4( mix( pow( sampledDiffuseColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), sampledDiffuseColor.rgb * 0.0773993808, vec3( lessThanEqual( sampledDiffuseColor.rgb, vec3( 0.04045 ) ) ) ), sampledDiffuseColor.w );\n\t\n\t#endif\n\tdiffuseColor *= sampledDiffuseColor;\n#endif",map_pars_fragment:"#ifdef USE_MAP\n\tuniform sampler2D map;\n \n#ifdef USE_MIPMAP_BIAS\n uniform float mipmapBias;\n#endif\n#endif",map_particle_fragment:"#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n\t#if defined( USE_POINTS_UV )\n\t\tvec2 uv = vUv;\n\t#else\n\t\tvec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;\n\t#endif\n#endif\n#ifdef USE_MAP\n\tdiffuseColor *= texture2D( map, uv );\n#endif\n#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, uv ).g;\n#endif",map_particle_pars_fragment:"#if defined( USE_POINTS_UV )\n\tvarying vec2 vUv;\n#else\n\t#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n\t\tuniform mat3 uvTransform;\n\t#endif\n#endif\n#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif\n#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif",metalnessmap_fragment:"float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vMetalnessMapUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif",metalnessmap_pars_fragment:"#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif",morphinstance_vertex:"#ifdef USE_INSTANCING_MORPH\n\tfloat morphTargetInfluences[ MORPHTARGETS_COUNT ];\n\tfloat morphTargetBaseInfluence = texelFetch( morphTexture, ivec2( 0, gl_InstanceID ), 0 ).r;\n\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\tmorphTargetInfluences[i] = texelFetch( morphTexture, ivec2( i + 1, gl_InstanceID ), 0 ).r;\n\t}\n#endif",morphcolor_vertex:"#if defined( USE_MORPHCOLORS )\n\tvColor *= morphTargetBaseInfluence;\n\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\t#if defined( USE_COLOR_ALPHA )\n\t\t\tif ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ) * morphTargetInfluences[ i ];\n\t\t#elif defined( USE_COLOR )\n\t\t\tif ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ).rgb * morphTargetInfluences[ i ];\n\t\t#endif\n\t}\n#endif",morphnormal_vertex:"#ifdef USE_MORPHNORMALS\n\tobjectNormal *= morphTargetBaseInfluence;\n\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\tif ( morphTargetInfluences[ i ] != 0.0 ) objectNormal += getMorph( gl_VertexID, i, 1 ).xyz * morphTargetInfluences[ i ];\n\t}\n#endif",morphtarget_pars_vertex:"#ifdef USE_MORPHTARGETS\n\t#ifndef USE_INSTANCING_MORPH\n\t\tuniform float morphTargetBaseInfluence;\n\t\tuniform float morphTargetInfluences[ MORPHTARGETS_COUNT ];\n\t#endif\n\tuniform sampler2DArray morphTargetsTexture;\n\tuniform ivec2 morphTargetsTextureSize;\n\tvec4 getMorph( const in int vertexIndex, const in int morphTargetIndex, const in int offset ) {\n\t\tint texelIndex = vertexIndex * MORPHTARGETS_TEXTURE_STRIDE + offset;\n\t\tint y = texelIndex / morphTargetsTextureSize.x;\n\t\tint x = texelIndex - y * morphTargetsTextureSize.x;\n\t\tivec3 morphUV = ivec3( x, y, morphTargetIndex );\n\t\treturn texelFetch( morphTargetsTexture, morphUV, 0 );\n\t}\n#endif",morphtarget_vertex:"#ifdef USE_MORPHTARGETS\n\ttransformed *= morphTargetBaseInfluence;\n\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\tif ( morphTargetInfluences[ i ] != 0.0 ) transformed += getMorph( gl_VertexID, i, 0 ).xyz * morphTargetInfluences[ i ];\n\t}\n#endif",normal_fragment_begin:"float faceDirection = gl_FrontFacing ? 1.0 : - 1.0;\n#ifdef FLAT_SHADED\n\tvec3 fdx = dFdx( vViewPosition );\n\tvec3 fdy = dFdy( vViewPosition );\n\tvec3 normal = normalize( cross( fdx, fdy ) );\n#else\n\tvec3 normal = normalize( vNormal );\n\t#ifdef DOUBLE_SIDED\n\t\tnormal *= faceDirection;\n\t#endif\n#endif\n#if defined( USE_NORMALMAP_TANGENTSPACE ) || defined( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY )\n\t#ifdef USE_TANGENT\n\t\tmat3 tbn = mat3( normalize( vTangent ), normalize( vBitangent ), normal );\n\t#else\n\t\tmat3 tbn = getTangentFrame( - vViewPosition, normal,\n\t\t#if defined( USE_NORMALMAP )\n\t\t\tvNormalMapUv\n\t\t#elif defined( USE_CLEARCOAT_NORMALMAP )\n\t\t\tvClearcoatNormalMapUv\n\t\t#else\n\t\t\tvUv\n\t\t#endif\n\t\t);\n\t#endif\n\t#if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED )\n\t\ttbn[0] *= faceDirection;\n\t\ttbn[1] *= faceDirection;\n\t#endif\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\t#ifdef USE_TANGENT\n\t\tmat3 tbn2 = mat3( normalize( vTangent ), normalize( vBitangent ), normal );\n\t#else\n\t\tmat3 tbn2 = getTangentFrame( - vViewPosition, normal, vClearcoatNormalMapUv );\n\t#endif\n\t#if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED )\n\t\ttbn2[0] *= faceDirection;\n\t\ttbn2[1] *= faceDirection;\n\t#endif\n#endif\nvec3 nonPerturbedNormal = normal;",normal_fragment_maps:"#ifdef USE_NORMALMAP_OBJECTSPACE\n\tnormal = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;\n\t#ifdef FLIP_SIDED\n\t\tnormal = - normal;\n\t#endif\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * faceDirection;\n\t#endif\n\tnormal = normalize( normalMatrix * normal );\n#elif defined( USE_NORMALMAP_TANGENTSPACE )\n\tvec3 mapN = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;\n\tmapN.xy *= normalScale;\n\tnormal = normalize( tbn * mapN );\n#elif defined( USE_BUMPMAP )\n\tnormal = perturbNormalArb( - vViewPosition, normal, dHdxy_fwd(), faceDirection );\n#endif",normal_pars_fragment:"#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif",normal_pars_vertex:"#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif",normal_vertex:"#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n\t#ifdef USE_TANGENT\n\t\tvTangent = normalize( transformedTangent );\n\t\tvBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );\n\t#endif\n#endif",normalmap_pars_fragment:"#ifdef USE_NORMALMAP\n\tuniform sampler2D normalMap;\n\tuniform vec2 normalScale;\n#endif\n#ifdef USE_NORMALMAP_OBJECTSPACE\n\tuniform mat3 normalMatrix;\n#endif\n#if ! defined ( USE_TANGENT ) && ( defined ( USE_NORMALMAP_TANGENTSPACE ) || defined ( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY ) )\n\tmat3 getTangentFrame( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {\n\t\tvec3 q0 = dFdx( eye_pos.xyz );\n\t\tvec3 q1 = dFdy( eye_pos.xyz );\n\t\tvec2 st0 = dFdx( uv.st );\n\t\tvec2 st1 = dFdy( uv.st );\n\t\tvec3 N = surf_norm;\n\t\tvec3 q1perp = cross( q1, N );\n\t\tvec3 q0perp = cross( N, q0 );\n\t\tvec3 T = q1perp * st0.x + q0perp * st1.x;\n\t\tvec3 B = q1perp * st0.y + q0perp * st1.y;\n\t\tfloat det = max( dot( T, T ), dot( B, B ) );\n\t\tfloat scale = ( det == 0.0 ) ? 0.0 : inversesqrt( det );\n\t\treturn mat3( T * scale, B * scale, N );\n\t}\n#endif",clearcoat_normal_fragment_begin:"#ifdef USE_CLEARCOAT\n\tvec3 clearcoatNormal = nonPerturbedNormal;\n#endif",clearcoat_normal_fragment_maps:"#ifdef USE_CLEARCOAT_NORMALMAP\n\tvec3 clearcoatMapN = texture2D( clearcoatNormalMap, vClearcoatNormalMapUv ).xyz * 2.0 - 1.0;\n\tclearcoatMapN.xy *= clearcoatNormalScale;\n\tclearcoatNormal = normalize( tbn2 * clearcoatMapN );\n#endif",clearcoat_pars_fragment:"#ifdef USE_CLEARCOATMAP\n\tuniform sampler2D clearcoatMap;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tuniform sampler2D clearcoatNormalMap;\n\tuniform vec2 clearcoatNormalScale;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tuniform sampler2D clearcoatRoughnessMap;\n#endif",iridescence_pars_fragment:"#ifdef USE_IRIDESCENCEMAP\n\tuniform sampler2D iridescenceMap;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\tuniform sampler2D iridescenceThicknessMap;\n#endif",opaque_fragment:"#ifdef OPAQUE\ndiffuseColor.a = 1.0;\n#endif\n#ifdef USE_TRANSMISSION\ndiffuseColor.a *= material.transmissionAlpha;\n#endif\ngl_FragColor = vec4( outgoingLight, diffuseColor.a );",packing:"vec3 packNormalToRGB( const in vec3 normal ) {\n\treturn normalize( normal ) * 0.5 + 0.5;\n}\nvec3 unpackRGBToNormal( const in vec3 rgb ) {\n\treturn 2.0 * rgb.xyz - 1.0;\n}\nconst float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;const float ShiftRight8 = 1. / 256.;\nconst float Inv255 = 1. / 255.;\nconst vec4 PackFactors = vec4( 1.0, 256.0, 256.0 * 256.0, 256.0 * 256.0 * 256.0 );\nconst vec2 UnpackFactors2 = vec2( UnpackDownscale, 1.0 / PackFactors.g );\nconst vec3 UnpackFactors3 = vec3( UnpackDownscale / PackFactors.rg, 1.0 / PackFactors.b );\nconst vec4 UnpackFactors4 = vec4( UnpackDownscale / PackFactors.rgb, 1.0 / PackFactors.a );\nvec4 packDepthToRGBA( const in float v ) {\n\tif( v <= 0.0 )\n\t\treturn vec4( 0., 0., 0., 0. );\n\tif( v >= 1.0 )\n\t\treturn vec4( 1., 1., 1., 1. );\n\tfloat vuf;\n\tfloat af = modf( v * PackFactors.a, vuf );\n\tfloat bf = modf( vuf * ShiftRight8, vuf );\n\tfloat gf = modf( vuf * ShiftRight8, vuf );\n\treturn vec4( vuf * Inv255, gf * PackUpscale, bf * PackUpscale, af );\n}\nvec3 packDepthToRGB( const in float v ) {\n\tif( v <= 0.0 )\n\t\treturn vec3( 0., 0., 0. );\n\tif( v >= 1.0 )\n\t\treturn vec3( 1., 1., 1. );\n\tfloat vuf;\n\tfloat bf = modf( v * PackFactors.b, vuf );\n\tfloat gf = modf( vuf * ShiftRight8, vuf );\n\treturn vec3( vuf * Inv255, gf * PackUpscale, bf );\n}\nvec2 packDepthToRG( const in float v ) {\n\tif( v <= 0.0 )\n\t\treturn vec2( 0., 0. );\n\tif( v >= 1.0 )\n\t\treturn vec2( 1., 1. );\n\tfloat vuf;\n\tfloat gf = modf( v * 256., vuf );\n\treturn vec2( vuf * Inv255, gf );\n}\nfloat unpackRGBAToDepth( const in vec4 v ) {\n\treturn dot( v, UnpackFactors4 );\n}\nfloat unpackRGBToDepth( const in vec3 v ) {\n\treturn dot( v, UnpackFactors3 );\n}\nfloat unpackRGToDepth( const in vec2 v ) {\n\treturn v.r * UnpackFactors2.r + v.g * UnpackFactors2.g;\n}\nvec4 pack2HalfToRGBA( const in vec2 v ) {\n\tvec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ) );\n\treturn vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w );\n}\nvec2 unpackRGBATo2Half( const in vec4 v ) {\n\treturn vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) );\n}\nfloat viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn ( viewZ + near ) / ( near - far );\n}\nfloat orthographicDepthToViewZ( const in float depth, const in float near, const in float far ) {\n\treturn depth * ( near - far ) - near;\n}\nfloat viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn ( ( near + viewZ ) * far ) / ( ( far - near ) * viewZ );\n}\nfloat perspectiveDepthToViewZ( const in float depth, const in float near, const in float far ) {\n\treturn ( near * far ) / ( ( far - near ) * depth - far );\n}",premultiplied_alpha_fragment:"#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif",project_vertex:"vec4 mvPosition = vec4( transformed, 1.0 );\n#ifdef USE_BATCHING\n\tmvPosition = batchingMatrix * mvPosition;\n#endif\n#ifdef USE_INSTANCING\n\tmvPosition = instanceMatrix * mvPosition;\n#endif\nmvPosition = modelViewMatrix * mvPosition;\ngl_Position = projectionMatrix * mvPosition;",dithering_fragment:"#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif",dithering_pars_fragment:"#ifdef DITHERING\n\tvec3 dithering( vec3 color ) {\n\t\tfloat grid_position = rand( gl_FragCoord.xy );\n\t\tvec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );\n\t\tdither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );\n\t\treturn color + dither_shift_RGB;\n\t}\n#endif",roughnessmap_fragment:"float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vRoughnessMapUv );\n\troughnessFactor *= texelRoughness.g;\n#endif",roughnessmap_pars_fragment:"#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif",shadowmap_pars_fragment:"#if NUM_SPOT_LIGHT_COORDS > 0\n\tvarying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];\n#endif\n#if NUM_SPOT_LIGHT_MAPS > 0\n\tuniform sampler2D spotLightMap[ NUM_SPOT_LIGHT_MAPS ];\n#endif\n#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tstruct DirectionalLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tstruct SpotLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tstruct PointLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t\tfloat shadowCameraNear;\n\t\t\tfloat shadowCameraFar;\n\t\t};\n\t\tuniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n\tfloat texture2DCompare( sampler2D depths, vec2 uv, float compare ) {\n\t\treturn step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) );\n\t}\n\tvec2 texture2DDistribution( sampler2D shadow, vec2 uv ) {\n\t\treturn unpackRGBATo2Half( texture2D( shadow, uv ) );\n\t}\n\tfloat VSMShadow (sampler2D shadow, vec2 uv, float compare ){\n\t\tfloat occlusion = 1.0;\n\t\tvec2 distribution = texture2DDistribution( shadow, uv );\n\t\tfloat hard_shadow = step( compare , distribution.x );\n\t\tif (hard_shadow != 1.0 ) {\n\t\t\tfloat distance = compare - distribution.x ;\n\t\t\tfloat variance = max( 0.00000, distribution.y * distribution.y );\n\t\t\tfloat softness_probability = variance / (variance + distance * distance );\t\t\tsoftness_probability = clamp( ( softness_probability - 0.3 ) / ( 0.95 - 0.3 ), 0.0, 1.0 );\t\t\tocclusion = clamp( max( hard_shadow, softness_probability ), 0.0, 1.0 );\n\t\t}\n\t\treturn occlusion;\n\t}\n\tfloat getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n\t\tfloat shadow = 1.0;\n\t\tshadowCoord.xyz /= shadowCoord.w;\n\t\tshadowCoord.z += shadowBias;\n\t\tbool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;\n\t\tbool frustumTest = inFrustum && shadowCoord.z <= 1.0;\n\t\tif ( frustumTest ) {\n\t\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx0 = - texelSize.x * shadowRadius;\n\t\t\tfloat dy0 = - texelSize.y * shadowRadius;\n\t\t\tfloat dx1 = + texelSize.x * shadowRadius;\n\t\t\tfloat dy1 = + texelSize.y * shadowRadius;\n\t\t\tfloat dx2 = dx0 / 2.0;\n\t\t\tfloat dy2 = dy0 / 2.0;\n\t\t\tfloat dx3 = dx1 / 2.0;\n\t\t\tfloat dy3 = dy1 / 2.0;\n\t\t\tshadow = (\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n\t\t\t) * ( 1.0 / 17.0 );\n\t\t#elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx = texelSize.x;\n\t\t\tfloat dy = texelSize.y;\n\t\t\tvec2 uv = shadowCoord.xy;\n\t\t\tvec2 f = fract( uv * shadowMapSize + 0.5 );\n\t\t\tuv -= f * texelSize;\n\t\t\tshadow = (\n\t\t\t\ttexture2DCompare( shadowMap, uv, shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + vec2( dx, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + vec2( 0.0, dy ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + texelSize, shadowCoord.z ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( -dx, 0.0 ), shadowCoord.z ),\n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 0.0 ), shadowCoord.z ),\n\t\t\t\t\t f.x ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( -dx, dy ), shadowCoord.z ),\n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, dy ), shadowCoord.z ),\n\t\t\t\t\t f.x ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( 0.0, -dy ), shadowCoord.z ),\n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 0.0, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t f.y ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( dx, -dy ), shadowCoord.z ),\n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( dx, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t f.y ) +\n\t\t\t\tmix( mix( texture2DCompare( shadowMap, uv + vec2( -dx, -dy ), shadowCoord.z ),\n\t\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, -dy ), shadowCoord.z ),\n\t\t\t\t\t\t f.x ),\n\t\t\t\t\t mix( texture2DCompare( shadowMap, uv + vec2( -dx, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t\t f.x ),\n\t\t\t\t\t f.y )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#elif defined( SHADOWMAP_TYPE_VSM )\n\t\t\tshadow = VSMShadow( shadowMap, shadowCoord.xy, shadowCoord.z );\n\t\t#else\n\t\t\tshadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );\n\t\t#endif\n\t\t}\n\t\treturn mix( 1.0, shadow, shadowIntensity );\n\t}\n\tvec2 cubeToUV( vec3 v, float texelSizeY ) {\n\t\tvec3 absV = abs( v );\n\t\tfloat scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );\n\t\tabsV *= scaleToCube;\n\t\tv *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );\n\t\tvec2 planar = v.xy;\n\t\tfloat almostATexel = 1.5 * texelSizeY;\n\t\tfloat almostOne = 1.0 - almostATexel;\n\t\tif ( absV.z >= almostOne ) {\n\t\t\tif ( v.z > 0.0 )\n\t\t\t\tplanar.x = 4.0 - v.x;\n\t\t} else if ( absV.x >= almostOne ) {\n\t\t\tfloat signX = sign( v.x );\n\t\t\tplanar.x = v.z * signX + 2.0 * signX;\n\t\t} else if ( absV.y >= almostOne ) {\n\t\t\tfloat signY = sign( v.y );\n\t\t\tplanar.x = v.x + 2.0 * signY + 2.0;\n\t\t\tplanar.y = v.z * signY - 2.0;\n\t\t}\n\t\treturn vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );\n\t}\n\tfloat getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {\n\t\tfloat shadow = 1.0;\n\t\tvec3 lightToPosition = shadowCoord.xyz;\n\t\t\n\t\tfloat lightToPositionLength = length( lightToPosition );\n\t\tif ( lightToPositionLength - shadowCameraFar <= 0.0 && lightToPositionLength - shadowCameraNear >= 0.0 ) {\n\t\t\tfloat dp = ( lightToPositionLength - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear );\t\t\tdp += shadowBias;\n\t\t\tvec3 bd3D = normalize( lightToPosition );\n\t\t\tvec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );\n\t\t\t#if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT ) || defined( SHADOWMAP_TYPE_VSM )\n\t\t\t\tvec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;\n\t\t\t\tshadow = (\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )\n\t\t\t\t) * ( 1.0 / 9.0 );\n\t\t\t#else\n\t\t\t\tshadow = texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );\n\t\t\t#endif\n\t\t}\n\t\treturn mix( 1.0, shadow, shadowIntensity );\n\t}\n#endif",shadowmap_pars_vertex:"#if NUM_SPOT_LIGHT_COORDS > 0\n\tuniform mat4 spotLightMatrix[ NUM_SPOT_LIGHT_COORDS ];\n\tvarying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];\n#endif\n#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\tuniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tstruct DirectionalLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t\tstruct SpotLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\tuniform mat4 pointShadowMatrix[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tstruct PointLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t\tfloat shadowCameraNear;\n\t\t\tfloat shadowCameraFar;\n\t\t};\n\t\tuniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n#endif",shadowmap_vertex:"#if ( defined( USE_SHADOWMAP ) && ( NUM_DIR_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0 ) ) || ( NUM_SPOT_LIGHT_COORDS > 0 )\n\tvec3 shadowWorldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\tvec4 shadowWorldPosition;\n#endif\n#if defined( USE_SHADOWMAP )\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 );\n\t\t\tvDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * shadowWorldPosition;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * pointLightShadows[ i ].shadowNormalBias, 0 );\n\t\t\tvPointShadowCoord[ i ] = pointShadowMatrix[ i ] * shadowWorldPosition;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n#endif\n#if NUM_SPOT_LIGHT_COORDS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_COORDS; i ++ ) {\n\t\tshadowWorldPosition = worldPosition;\n\t\t#if ( defined( USE_SHADOWMAP ) && UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\t\tshadowWorldPosition.xyz += shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias;\n\t\t#endif\n\t\tvSpotLightCoord[ i ] = spotLightMatrix[ i ] * shadowWorldPosition;\n\t}\n\t#pragma unroll_loop_end\n#endif",shadowmask_pars_fragment:"float getShadowMask() {\n\tfloat shadow = 1.0;\n\t#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\tdirectionalLight = directionalLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowIntensity, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {\n\t\tspotLight = spotLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowIntensity, spotLight.shadowBias, spotLight.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\tpointLight = pointLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowIntensity, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#endif\n\treturn shadow;\n}",skinbase_vertex:"#ifdef USE_SKINNING\n\tmat4 boneMatX = getBoneMatrix( skinIndex.x );\n\tmat4 boneMatY = getBoneMatrix( skinIndex.y );\n\tmat4 boneMatZ = getBoneMatrix( skinIndex.z );\n\tmat4 boneMatW = getBoneMatrix( skinIndex.w );\n#endif",skinning_pars_vertex:"#ifdef USE_SKINNING\n\tuniform mat4 bindMatrix;\n\tuniform mat4 bindMatrixInverse;\n\tuniform highp sampler2D boneTexture;\n\tmat4 getBoneMatrix( const in float i ) {\n\t\tint size = textureSize( boneTexture, 0 ).x;\n\t\tint j = int( i ) * 4;\n\t\tint x = j % size;\n\t\tint y = j / size;\n\t\tvec4 v1 = texelFetch( boneTexture, ivec2( x, y ), 0 );\n\t\tvec4 v2 = texelFetch( boneTexture, ivec2( x + 1, y ), 0 );\n\t\tvec4 v3 = texelFetch( boneTexture, ivec2( x + 2, y ), 0 );\n\t\tvec4 v4 = texelFetch( boneTexture, ivec2( x + 3, y ), 0 );\n\t\treturn mat4( v1, v2, v3, v4 );\n\t}\n#endif",skinning_vertex:"#ifdef USE_SKINNING\n\tvec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );\n\tvec4 skinned = vec4( 0.0 );\n\tskinned += boneMatX * skinVertex * skinWeight.x;\n\tskinned += boneMatY * skinVertex * skinWeight.y;\n\tskinned += boneMatZ * skinVertex * skinWeight.z;\n\tskinned += boneMatW * skinVertex * skinWeight.w;\n\ttransformed = ( bindMatrixInverse * skinned ).xyz;\n#endif",skinnormal_vertex:"#ifdef USE_SKINNING\n\tmat4 skinMatrix = mat4( 0.0 );\n\tskinMatrix += skinWeight.x * boneMatX;\n\tskinMatrix += skinWeight.y * boneMatY;\n\tskinMatrix += skinWeight.z * boneMatZ;\n\tskinMatrix += skinWeight.w * boneMatW;\n\tskinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;\n\tobjectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;\n\t#ifdef USE_TANGENT\n\t\tobjectTangent = vec4( skinMatrix * vec4( objectTangent, 0.0 ) ).xyz;\n\t#endif\n#endif",specularmap_fragment:"float specularStrength;\n#ifdef USE_SPECULARMAP\n\tvec4 texelSpecular = texture2D( specularMap, vSpecularMapUv );\n\tspecularStrength = texelSpecular.r;\n#else\n\tspecularStrength = 1.0;\n#endif",specularmap_pars_fragment:"#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif",tonemapping_fragment:"#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif",tonemapping_pars_fragment:"#ifndef saturate\n#define saturate( a ) clamp( a, 0.0, 1.0 )\n#endif\nuniform float toneMappingExposure;\nvec3 LinearToneMapping( vec3 color ) {\n\treturn saturate( toneMappingExposure * color );\n}\nvec3 ReinhardToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( color / ( vec3( 1.0 ) + color ) );\n}\nvec3 CineonToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\tcolor = max( vec3( 0.0 ), color - 0.004 );\n\treturn pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );\n}\nvec3 RRTAndODTFit( vec3 v ) {\n\tvec3 a = v * ( v + 0.0245786 ) - 0.000090537;\n\tvec3 b = v * ( 0.983729 * v + 0.4329510 ) + 0.238081;\n\treturn a / b;\n}\nvec3 ACESFilmicToneMapping( vec3 color ) {\n\tconst mat3 ACESInputMat = mat3(\n\t\tvec3( 0.59719, 0.07600, 0.02840 ),\t\tvec3( 0.35458, 0.90834, 0.13383 ),\n\t\tvec3( 0.04823, 0.01566, 0.83777 )\n\t);\n\tconst mat3 ACESOutputMat = mat3(\n\t\tvec3( 1.60475, -0.10208, -0.00327 ),\t\tvec3( -0.53108, 1.10813, -0.07276 ),\n\t\tvec3( -0.07367, -0.00605, 1.07602 )\n\t);\n\tcolor *= toneMappingExposure / 0.6;\n\tcolor = ACESInputMat * color;\n\tcolor = RRTAndODTFit( color );\n\tcolor = ACESOutputMat * color;\n\treturn saturate( color );\n}\nconst mat3 LINEAR_REC2020_TO_LINEAR_SRGB = mat3(\n\tvec3( 1.6605, - 0.1246, - 0.0182 ),\n\tvec3( - 0.5876, 1.1329, - 0.1006 ),\n\tvec3( - 0.0728, - 0.0083, 1.1187 )\n);\nconst mat3 LINEAR_SRGB_TO_LINEAR_REC2020 = mat3(\n\tvec3( 0.6274, 0.0691, 0.0164 ),\n\tvec3( 0.3293, 0.9195, 0.0880 ),\n\tvec3( 0.0433, 0.0113, 0.8956 )\n);\nvec3 agxDefaultContrastApprox( vec3 x ) {\n\tvec3 x2 = x * x;\n\tvec3 x4 = x2 * x2;\n\treturn + 15.5 * x4 * x2\n\t\t- 40.14 * x4 * x\n\t\t+ 31.96 * x4\n\t\t- 6.868 * x2 * x\n\t\t+ 0.4298 * x2\n\t\t+ 0.1191 * x\n\t\t- 0.00232;\n}\nvec3 AgXToneMapping( vec3 color ) {\n\tconst mat3 AgXInsetMatrix = mat3(\n\t\tvec3( 0.856627153315983, 0.137318972929847, 0.11189821299995 ),\n\t\tvec3( 0.0951212405381588, 0.761241990602591, 0.0767994186031903 ),\n\t\tvec3( 0.0482516061458583, 0.101439036467562, 0.811302368396859 )\n\t);\n\tconst mat3 AgXOutsetMatrix = mat3(\n\t\tvec3( 1.1271005818144368, - 0.1413297634984383, - 0.14132976349843826 ),\n\t\tvec3( - 0.11060664309660323, 1.157823702216272, - 0.11060664309660294 ),\n\t\tvec3( - 0.016493938717834573, - 0.016493938717834257, 1.2519364065950405 )\n\t);\n\tconst float AgxMinEv = - 12.47393;\tconst float AgxMaxEv = 4.026069;\n\tcolor *= toneMappingExposure;\n\tcolor = LINEAR_SRGB_TO_LINEAR_REC2020 * color;\n\tcolor = AgXInsetMatrix * color;\n\tcolor = max( color, 1e-10 );\tcolor = log2( color );\n\tcolor = ( color - AgxMinEv ) / ( AgxMaxEv - AgxMinEv );\n\tcolor = clamp( color, 0.0, 1.0 );\n\tcolor = agxDefaultContrastApprox( color );\n\tcolor = AgXOutsetMatrix * color;\n\tcolor = pow( max( vec3( 0.0 ), color ), vec3( 2.2 ) );\n\tcolor = LINEAR_REC2020_TO_LINEAR_SRGB * color;\n\tcolor = clamp( color, 0.0, 1.0 );\n\treturn color;\n}\nvec3 NeutralToneMapping( vec3 color ) {\n\tconst float StartCompression = 0.8 - 0.04;\n\tconst float Desaturation = 0.15;\n\tcolor *= toneMappingExposure;\n\tfloat x = min( color.r, min( color.g, color.b ) );\n\tfloat offset = x < 0.08 ? x - 6.25 * x * x : 0.04;\n\tcolor -= offset;\n\tfloat peak = max( color.r, max( color.g, color.b ) );\n\tif ( peak < StartCompression ) return color;\n\tfloat d = 1. - StartCompression;\n\tfloat newPeak = 1. - d * d / ( peak + d - StartCompression );\n\tcolor *= newPeak / peak;\n\tfloat g = 1. - 1. / ( Desaturation * ( peak - newPeak ) + 1. );\n\treturn mix( color, vec3( newPeak ), g );\n}\nvec3 CustomToneMapping( vec3 color ) { return color; }",transmission_fragment:"#ifdef USE_TRANSMISSION\n\tmaterial.transmission = transmission;\n\tmaterial.transmissionAlpha = 1.0;\n\tmaterial.thickness = thickness;\n\tmaterial.attenuationDistance = attenuationDistance;\n\tmaterial.attenuationColor = attenuationColor;\n\t#ifdef USE_TRANSMISSIONMAP\n\t\tmaterial.transmission *= texture2D( transmissionMap, vTransmissionMapUv ).r;\n\t#endif\n\t#ifdef USE_THICKNESSMAP\n\t\tmaterial.thickness *= texture2D( thicknessMap, vThicknessMapUv ).g;\n\t#endif\n\tvec3 pos = vWorldPosition;\n\tvec3 v = normalize( cameraPosition - pos );\n\tvec3 n = inverseTransformDirection( normal, viewMatrix );\n\tvec4 transmitted = getIBLVolumeRefraction(\n\t\tn, v, material.roughness, material.diffuseColor, material.specularColor, material.specularF90,\n\t\tpos, modelMatrix, viewMatrix, projectionMatrix, material.dispersion, material.ior, material.thickness,\n\t\tmaterial.attenuationColor, material.attenuationDistance );\n\tmaterial.transmissionAlpha = mix( material.transmissionAlpha, transmitted.a, material.transmission );\n\ttotalDiffuse = mix( totalDiffuse, transmitted.rgb, material.transmission );\n#endif",transmission_pars_fragment:"#ifdef USE_TRANSMISSION\n\tuniform float transmission;\n\tuniform float thickness;\n\tuniform float attenuationDistance;\n\tuniform vec3 attenuationColor;\n\t#ifdef USE_TRANSMISSIONMAP\n\t\tuniform sampler2D transmissionMap;\n\t#endif\n\t#ifdef USE_THICKNESSMAP\n\t\tuniform sampler2D thicknessMap;\n\t#endif\n\tuniform vec2 transmissionSamplerSize;\n\tuniform sampler2D transmissionSamplerMap;\n\tuniform mat4 modelMatrix;\n\tuniform mat4 projectionMatrix;\n\tvarying vec3 vWorldPosition;\n\tfloat w0( float a ) {\n\t\treturn ( 1.0 / 6.0 ) * ( a * ( a * ( - a + 3.0 ) - 3.0 ) + 1.0 );\n\t}\n\tfloat w1( float a ) {\n\t\treturn ( 1.0 / 6.0 ) * ( a * a * ( 3.0 * a - 6.0 ) + 4.0 );\n\t}\n\tfloat w2( float a ){\n\t\treturn ( 1.0 / 6.0 ) * ( a * ( a * ( - 3.0 * a + 3.0 ) + 3.0 ) + 1.0 );\n\t}\n\tfloat w3( float a ) {\n\t\treturn ( 1.0 / 6.0 ) * ( a * a * a );\n\t}\n\tfloat g0( float a ) {\n\t\treturn w0( a ) + w1( a );\n\t}\n\tfloat g1( float a ) {\n\t\treturn w2( a ) + w3( a );\n\t}\n\tfloat h0( float a ) {\n\t\treturn - 1.0 + w1( a ) / ( w0( a ) + w1( a ) );\n\t}\n\tfloat h1( float a ) {\n\t\treturn 1.0 + w3( a ) / ( w2( a ) + w3( a ) );\n\t}\n\tvec4 bicubic( sampler2D tex, vec2 uv, vec4 texelSize, float lod ) {\n\t\tuv = uv * texelSize.zw + 0.5;\n\t\tvec2 iuv = floor( uv );\n\t\tvec2 fuv = fract( uv );\n\t\tfloat g0x = g0( fuv.x );\n\t\tfloat g1x = g1( fuv.x );\n\t\tfloat h0x = h0( fuv.x );\n\t\tfloat h1x = h1( fuv.x );\n\t\tfloat h0y = h0( fuv.y );\n\t\tfloat h1y = h1( fuv.y );\n\t\tvec2 p0 = ( vec2( iuv.x + h0x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;\n\t\tvec2 p1 = ( vec2( iuv.x + h1x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;\n\t\tvec2 p2 = ( vec2( iuv.x + h0x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;\n\t\tvec2 p3 = ( vec2( iuv.x + h1x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;\n\t\treturn g0( fuv.y ) * ( g0x * textureLod( tex, p0, lod ) + g1x * textureLod( tex, p1, lod ) ) +\n\t\t\tg1( fuv.y ) * ( g0x * textureLod( tex, p2, lod ) + g1x * textureLod( tex, p3, lod ) );\n\t}\n\tvec4 textureBicubic( sampler2D sampler, vec2 uv, float lod ) {\n\t\tvec2 fLodSize = vec2( textureSize( sampler, int( lod ) ) );\n\t\tvec2 cLodSize = vec2( textureSize( sampler, int( lod + 1.0 ) ) );\n\t\tvec2 fLodSizeInv = 1.0 / fLodSize;\n\t\tvec2 cLodSizeInv = 1.0 / cLodSize;\n\t\tvec4 fSample = bicubic( sampler, uv, vec4( fLodSizeInv, fLodSize ), floor( lod ) );\n\t\tvec4 cSample = bicubic( sampler, uv, vec4( cLodSizeInv, cLodSize ), ceil( lod ) );\n\t\treturn mix( fSample, cSample, fract( lod ) );\n\t}\n\tvec3 getVolumeTransmissionRay( const in vec3 n, const in vec3 v, const in float thickness, const in float ior, const in mat4 modelMatrix ) {\n\t\tvec3 refractionVector = refract( - v, normalize( n ), 1.0 / ior );\n\t\tvec3 modelScale;\n\t\tmodelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) );\n\t\tmodelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) );\n\t\tmodelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) );\n\t\treturn normalize( refractionVector ) * thickness * modelScale;\n\t}\n\tfloat applyIorToRoughness( const in float roughness, const in float ior ) {\n\t\treturn roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 );\n\t}\n\tvec4 getTransmissionSample( const in vec2 fragCoord, const in float roughness, const in float ior ) {\n\t\tfloat lod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior );\n\t\treturn textureBicubic( transmissionSamplerMap, fragCoord.xy, lod );\n\t}\n\tvec3 volumeAttenuation( const in float transmissionDistance, const in vec3 attenuationColor, const in float attenuationDistance ) {\n\t\tif ( isinf( attenuationDistance ) ) {\n\t\t\treturn vec3( 1.0 );\n\t\t} else {\n\t\t\tvec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance;\n\t\t\tvec3 transmittance = exp( - attenuationCoefficient * transmissionDistance );\t\t\treturn transmittance;\n\t\t}\n\t}\n\tvec4 getIBLVolumeRefraction( const in vec3 n, const in vec3 v, const in float roughness, const in vec3 diffuseColor,\n\t\tconst in vec3 specularColor, const in float specularF90, const in vec3 position, const in mat4 modelMatrix,\n\t\tconst in mat4 viewMatrix, const in mat4 projMatrix, const in float dispersion, const in float ior, const in float thickness,\n\t\tconst in vec3 attenuationColor, const in float attenuationDistance ) {\n\t\tvec4 transmittedLight;\n\t\tvec3 transmittance;\n\t\t#ifdef USE_DISPERSION\n\t\t\tfloat halfSpread = ( ior - 1.0 ) * 0.025 * dispersion;\n\t\t\tvec3 iors = vec3( ior - halfSpread, ior, ior + halfSpread );\n\t\t\tfor ( int i = 0; i < 3; i ++ ) {\n\t\t\t\tvec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, iors[ i ], modelMatrix );\n\t\t\t\tvec3 refractedRayExit = position + transmissionRay;\n\t\t\n\t\t\t\tvec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );\n\t\t\t\tvec2 refractionCoords = ndcPos.xy / ndcPos.w;\n\t\t\t\trefractionCoords += 1.0;\n\t\t\t\trefractionCoords /= 2.0;\n\t\t\n\t\t\t\tvec4 transmissionSample = getTransmissionSample( refractionCoords, roughness, iors[ i ] );\n\t\t\t\ttransmittedLight[ i ] = transmissionSample[ i ];\n\t\t\t\ttransmittedLight.a += transmissionSample.a;\n\t\t\t\ttransmittance[ i ] = diffuseColor[ i ] * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance )[ i ];\n\t\t\t}\n\t\t\ttransmittedLight.a /= 3.0;\n\t\t\n\t\t#else\n\t\t\n\t\t\tvec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );\n\t\t\tvec3 refractedRayExit = position + transmissionRay;\n\t\t\tvec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );\n\t\t\tvec2 refractionCoords = ndcPos.xy / ndcPos.w;\n\t\t\trefractionCoords += 1.0;\n\t\t\trefractionCoords /= 2.0;\n\t\t\ttransmittedLight = getTransmissionSample( refractionCoords, roughness, ior );\n\t\t\ttransmittance = diffuseColor * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance );\n\t\t\n\t\t#endif\n\t\tvec3 attenuatedColor = transmittance * transmittedLight.rgb;\n\t\tvec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness );\n\t\tfloat transmittanceFactor = ( transmittance.r + transmittance.g + transmittance.b ) / 3.0;\n\t\treturn vec4( ( 1.0 - F ) * attenuatedColor, 1.0 - ( 1.0 - transmittedLight.a ) * transmittanceFactor );\n\t}\n#endif",uv_pars_fragment:"#if defined( USE_UV ) || defined( USE_ANISOTROPY )\n\tvarying vec2 vUv;\n#endif\n#ifdef USE_MAP\n\tvarying vec2 vMapUv;\n#endif\n#ifdef USE_ALPHAMAP\n\tvarying vec2 vAlphaMapUv;\n#endif\n#ifdef USE_LIGHTMAP\n\tvarying vec2 vLightMapUv;\n#endif\n#ifdef USE_AOMAP\n\tvarying vec2 vAoMapUv;\n#endif\n#ifdef USE_BUMPMAP\n\tvarying vec2 vBumpMapUv;\n#endif\n#ifdef USE_NORMALMAP\n\tvarying vec2 vNormalMapUv;\n#endif\n#ifdef USE_EMISSIVEMAP\n\tvarying vec2 vEmissiveMapUv;\n#endif\n#ifdef USE_METALNESSMAP\n\tvarying vec2 vMetalnessMapUv;\n#endif\n#ifdef USE_ROUGHNESSMAP\n\tvarying vec2 vRoughnessMapUv;\n#endif\n#ifdef USE_ANISOTROPYMAP\n\tvarying vec2 vAnisotropyMapUv;\n#endif\n#ifdef USE_CLEARCOATMAP\n\tvarying vec2 vClearcoatMapUv;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tvarying vec2 vClearcoatNormalMapUv;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tvarying vec2 vClearcoatRoughnessMapUv;\n#endif\n#ifdef USE_IRIDESCENCEMAP\n\tvarying vec2 vIridescenceMapUv;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\tvarying vec2 vIridescenceThicknessMapUv;\n#endif\n#ifdef USE_SHEEN_COLORMAP\n\tvarying vec2 vSheenColorMapUv;\n#endif\n#ifdef USE_SHEEN_ROUGHNESSMAP\n\tvarying vec2 vSheenRoughnessMapUv;\n#endif\n#ifdef USE_SPECULARMAP\n\tvarying vec2 vSpecularMapUv;\n#endif\n#ifdef USE_SPECULAR_COLORMAP\n\tvarying vec2 vSpecularColorMapUv;\n#endif\n#ifdef USE_SPECULAR_INTENSITYMAP\n\tvarying vec2 vSpecularIntensityMapUv;\n#endif\n#ifdef USE_TRANSMISSIONMAP\n\tuniform mat3 transmissionMapTransform;\n\tvarying vec2 vTransmissionMapUv;\n#endif\n#ifdef USE_THICKNESSMAP\n\tuniform mat3 thicknessMapTransform;\n\tvarying vec2 vThicknessMapUv;\n#endif",uv_pars_vertex:"#if defined( USE_UV ) || defined( USE_ANISOTROPY )\n\tvarying vec2 vUv;\n#endif\n#ifdef USE_MAP\n\tuniform mat3 mapTransform;\n\tvarying vec2 vMapUv;\n#endif\n#ifdef USE_ALPHAMAP\n\tuniform mat3 alphaMapTransform;\n\tvarying vec2 vAlphaMapUv;\n#endif\n#ifdef USE_LIGHTMAP\n\tuniform mat3 lightMapTransform;\n\tvarying vec2 vLightMapUv;\n#endif\n#ifdef USE_AOMAP\n\tuniform mat3 aoMapTransform;\n\tvarying vec2 vAoMapUv;\n#endif\n#ifdef USE_BUMPMAP\n\tuniform mat3 bumpMapTransform;\n\tvarying vec2 vBumpMapUv;\n#endif\n#ifdef USE_NORMALMAP\n\tuniform mat3 normalMapTransform;\n\tvarying vec2 vNormalMapUv;\n#endif\n#ifdef USE_DISPLACEMENTMAP\n\tuniform mat3 displacementMapTransform;\n\tvarying vec2 vDisplacementMapUv;\n#endif\n#ifdef USE_EMISSIVEMAP\n\tuniform mat3 emissiveMapTransform;\n\tvarying vec2 vEmissiveMapUv;\n#endif\n#ifdef USE_METALNESSMAP\n\tuniform mat3 metalnessMapTransform;\n\tvarying vec2 vMetalnessMapUv;\n#endif\n#ifdef USE_ROUGHNESSMAP\n\tuniform mat3 roughnessMapTransform;\n\tvarying vec2 vRoughnessMapUv;\n#endif\n#ifdef USE_ANISOTROPYMAP\n\tuniform mat3 anisotropyMapTransform;\n\tvarying vec2 vAnisotropyMapUv;\n#endif\n#ifdef USE_CLEARCOATMAP\n\tuniform mat3 clearcoatMapTransform;\n\tvarying vec2 vClearcoatMapUv;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tuniform mat3 clearcoatNormalMapTransform;\n\tvarying vec2 vClearcoatNormalMapUv;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tuniform mat3 clearcoatRoughnessMapTransform;\n\tvarying vec2 vClearcoatRoughnessMapUv;\n#endif\n#ifdef USE_SHEEN_COLORMAP\n\tuniform mat3 sheenColorMapTransform;\n\tvarying vec2 vSheenColorMapUv;\n#endif\n#ifdef USE_SHEEN_ROUGHNESSMAP\n\tuniform mat3 sheenRoughnessMapTransform;\n\tvarying vec2 vSheenRoughnessMapUv;\n#endif\n#ifdef USE_IRIDESCENCEMAP\n\tuniform mat3 iridescenceMapTransform;\n\tvarying vec2 vIridescenceMapUv;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\tuniform mat3 iridescenceThicknessMapTransform;\n\tvarying vec2 vIridescenceThicknessMapUv;\n#endif\n#ifdef USE_SPECULARMAP\n\tuniform mat3 specularMapTransform;\n\tvarying vec2 vSpecularMapUv;\n#endif\n#ifdef USE_SPECULAR_COLORMAP\n\tuniform mat3 specularColorMapTransform;\n\tvarying vec2 vSpecularColorMapUv;\n#endif\n#ifdef USE_SPECULAR_INTENSITYMAP\n\tuniform mat3 specularIntensityMapTransform;\n\tvarying vec2 vSpecularIntensityMapUv;\n#endif\n#ifdef USE_TRANSMISSIONMAP\n\tuniform mat3 transmissionMapTransform;\n\tvarying vec2 vTransmissionMapUv;\n#endif\n#ifdef USE_THICKNESSMAP\n\tuniform mat3 thicknessMapTransform;\n\tvarying vec2 vThicknessMapUv;\n#endif",uv_vertex:"#if defined( USE_UV ) || defined( USE_ANISOTROPY )\n\tvUv = vec3( uv, 1 ).xy;\n#endif\n#ifdef USE_MAP\n\tvMapUv = ( mapTransform * vec3( MAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_ALPHAMAP\n\tvAlphaMapUv = ( alphaMapTransform * vec3( ALPHAMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_LIGHTMAP\n\tvLightMapUv = ( lightMapTransform * vec3( LIGHTMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_AOMAP\n\tvAoMapUv = ( aoMapTransform * vec3( AOMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_BUMPMAP\n\tvBumpMapUv = ( bumpMapTransform * vec3( BUMPMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_NORMALMAP\n\tvNormalMapUv = ( normalMapTransform * vec3( NORMALMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_DISPLACEMENTMAP\n\tvDisplacementMapUv = ( displacementMapTransform * vec3( DISPLACEMENTMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_EMISSIVEMAP\n\tvEmissiveMapUv = ( emissiveMapTransform * vec3( EMISSIVEMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_METALNESSMAP\n\tvMetalnessMapUv = ( metalnessMapTransform * vec3( METALNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_ROUGHNESSMAP\n\tvRoughnessMapUv = ( roughnessMapTransform * vec3( ROUGHNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_ANISOTROPYMAP\n\tvAnisotropyMapUv = ( anisotropyMapTransform * vec3( ANISOTROPYMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_CLEARCOATMAP\n\tvClearcoatMapUv = ( clearcoatMapTransform * vec3( CLEARCOATMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tvClearcoatNormalMapUv = ( clearcoatNormalMapTransform * vec3( CLEARCOAT_NORMALMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tvClearcoatRoughnessMapUv = ( clearcoatRoughnessMapTransform * vec3( CLEARCOAT_ROUGHNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_IRIDESCENCEMAP\n\tvIridescenceMapUv = ( iridescenceMapTransform * vec3( IRIDESCENCEMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\tvIridescenceThicknessMapUv = ( iridescenceThicknessMapTransform * vec3( IRIDESCENCE_THICKNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SHEEN_COLORMAP\n\tvSheenColorMapUv = ( sheenColorMapTransform * vec3( SHEEN_COLORMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SHEEN_ROUGHNESSMAP\n\tvSheenRoughnessMapUv = ( sheenRoughnessMapTransform * vec3( SHEEN_ROUGHNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SPECULARMAP\n\tvSpecularMapUv = ( specularMapTransform * vec3( SPECULARMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SPECULAR_COLORMAP\n\tvSpecularColorMapUv = ( specularColorMapTransform * vec3( SPECULAR_COLORMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SPECULAR_INTENSITYMAP\n\tvSpecularIntensityMapUv = ( specularIntensityMapTransform * vec3( SPECULAR_INTENSITYMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_TRANSMISSIONMAP\n\tvTransmissionMapUv = ( transmissionMapTransform * vec3( TRANSMISSIONMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_THICKNESSMAP\n\tvThicknessMapUv = ( thicknessMapTransform * vec3( THICKNESSMAP_UV, 1 ) ).xy;\n#endif",worldpos_vertex:"#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP ) || defined ( USE_TRANSMISSION ) || NUM_SPOT_LIGHT_COORDS > 0\n\tvec4 worldPosition = vec4( transformed, 1.0 );\n\t#ifdef USE_BATCHING\n\t\tworldPosition = batchingMatrix * worldPosition;\n\t#endif\n\t#ifdef USE_INSTANCING\n\t\tworldPosition = instanceMatrix * worldPosition;\n\t#endif\n\tworldPosition = modelMatrix * worldPosition;\n#endif",background_vert:"varying vec2 vUv;\nuniform mat3 uvTransform;\nvoid main() {\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n\tgl_Position = vec4( position.xy, 1.0, 1.0 );\n}",background_frag:"uniform sampler2D t2D;\nuniform float backgroundIntensity;\nvarying vec2 vUv;\nvoid main() {\n\tvec4 texColor = texture2D( t2D, vUv );\n\t#ifdef DECODE_VIDEO_TEXTURE\n\t\ttexColor = vec4( mix( pow( texColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), texColor.rgb * 0.0773993808, vec3( lessThanEqual( texColor.rgb, vec3( 0.04045 ) ) ) ), texColor.w );\n\t#endif\n\ttexColor.rgb *= backgroundIntensity;\n\tgl_FragColor = texColor;\n\t#include \n\t#include \n}",backgroundCube_vert:"varying vec3 vWorldDirection;\n#include \nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include \n\t#include \n\tgl_Position.z = gl_Position.w;\n}",backgroundCube_frag:"#ifdef ENVMAP_TYPE_CUBE\n\tuniform samplerCube envMap;\n#elif defined( ENVMAP_TYPE_CUBE_UV )\n\tuniform sampler2D envMap;\n#endif\nuniform float flipEnvMap;\nuniform float backgroundBlurriness;\nuniform float backgroundIntensity;\nuniform mat3 backgroundRotation;\nvarying vec3 vWorldDirection;\n#include \nvoid main() {\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tvec4 texColor = textureCube( envMap, backgroundRotation * vec3( flipEnvMap * vWorldDirection.x, vWorldDirection.yz ) );\n\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\tvec4 texColor = textureCubeUV( envMap, backgroundRotation * vWorldDirection, backgroundBlurriness );\n\t#else\n\t\tvec4 texColor = vec4( 0.0, 0.0, 0.0, 1.0 );\n\t#endif\n\ttexColor.rgb *= backgroundIntensity;\n\tgl_FragColor = texColor;\n\t#include \n\t#include \n}",cube_vert:"varying vec3 vWorldDirection;\n#include \nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include \n\t#include \n\tgl_Position.z = gl_Position.w;\n}",cube_frag:"uniform samplerCube tCube;\nuniform float tFlip;\nuniform float opacity;\nvarying vec3 vWorldDirection;\nvoid main() {\n\tvec4 texColor = textureCube( tCube, vec3( tFlip * vWorldDirection.x, vWorldDirection.yz ) );\n\tgl_FragColor = texColor;\n\tgl_FragColor.a *= opacity;\n\t#include \n\t#include \n}",depth_vert:"#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvarying vec2 vHighPrecisionZW;\nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include \n\t\t#include \n\t\t#include \n\t#endif\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvHighPrecisionZW = gl_Position.zw;\n}",depth_frag:"#if DEPTH_PACKING == 3200\n\tuniform float opacity;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvarying vec2 vHighPrecisionZW;\nvoid main() {\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#include \n\t#if DEPTH_PACKING == 3200\n\t\tdiffuseColor.a = opacity;\n\t#endif\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tfloat fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;\n\t#if DEPTH_PACKING == 3200\n\t\tgl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );\n\t#elif DEPTH_PACKING == 3201\n\t\tgl_FragColor = packDepthToRGBA( fragCoordZ );\n\t#elif DEPTH_PACKING == 3202\n\t\tgl_FragColor = vec4( packDepthToRGB( fragCoordZ ), 1.0 );\n\t#elif DEPTH_PACKING == 3203\n\t\tgl_FragColor = vec4( packDepthToRG( fragCoordZ ), 0.0, 1.0 );\n\t#endif\n}",distanceRGBA_vert:"#define DISTANCE\nvarying vec3 vWorldPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include \n\t\t#include \n\t\t#include \n\t#endif\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvWorldPosition = worldPosition.xyz;\n}",distanceRGBA_frag:"#define DISTANCE\nuniform vec3 referencePosition;\nuniform float nearDistance;\nuniform float farDistance;\nvarying vec3 vWorldPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main () {\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tfloat dist = length( vWorldPosition - referencePosition );\n\tdist = ( dist - nearDistance ) / ( farDistance - nearDistance );\n\tdist = saturate( dist );\n\tgl_FragColor = packDepthToRGBA( dist );\n}",equirect_vert:"varying vec3 vWorldDirection;\n#include \nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include \n\t#include \n}",equirect_frag:"uniform sampler2D tEquirect;\nvarying vec3 vWorldDirection;\n#include \nvoid main() {\n\tvec3 direction = normalize( vWorldDirection );\n\tvec2 sampleUV = equirectUv( direction );\n\tgl_FragColor = texture2D( tEquirect, sampleUV );\n\t#include \n\t#include \n}",linedashed_vert:"uniform float scale;\nattribute float lineDistance;\nvarying float vLineDistance;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvLineDistance = scale * lineDistance;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",linedashed_frag:"uniform vec3 diffuse;\nuniform float opacity;\nuniform float dashSize;\nuniform float totalSize;\nvarying float vLineDistance;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\tif ( mod( vLineDistance, totalSize ) > dashSize ) {\n\t\tdiscard;\n\t}\n\tvec3 outgoingLight = vec3( 0.0 );\n\t#include \n\t#include \n\t#include \n\toutgoingLight = diffuseColor.rgb;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",meshbasic_vert:"#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#if defined ( USE_ENVMAP ) || defined ( USE_SKINNING )\n\t\t#include \n\t\t#include \n\t\t#include \n\t\t#include \n\t\t#include \n\t#endif\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",meshbasic_frag:"uniform vec3 diffuse;\nuniform float opacity;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\t#ifdef USE_LIGHTMAP\n\t\tvec4 lightMapTexel = texture2D( lightMap, vLightMapUv );\n\t\treflectedLight.indirectDiffuse += lightMapTexel.rgb * lightMapIntensity * RECIPROCAL_PI;\n\t#else\n\t\treflectedLight.indirectDiffuse += vec3( 1.0 );\n\t#endif\n\t#include \n\treflectedLight.indirectDiffuse *= diffuseColor.rgb;\n\tvec3 outgoingLight = reflectedLight.indirectDiffuse;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",meshlambert_vert:"#define LAMBERT\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvViewPosition = - mvPosition.xyz;\n\t#include \n\t#include \n\t#include \n\t#include \n}",meshlambert_frag:"#define LAMBERT\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",meshmatcap_vert:"#define MATCAP\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvViewPosition = - mvPosition.xyz;\n}",meshmatcap_frag:"#define MATCAP\nuniform vec3 diffuse;\nuniform float opacity;\nuniform sampler2D matcap;\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvec3 viewDir = normalize( vViewPosition );\n\tvec3 x = normalize( vec3( viewDir.z, 0.0, - viewDir.x ) );\n\tvec3 y = cross( viewDir, x );\n\tvec2 uv = vec2( dot( x, normal ), dot( y, normal ) ) * 0.495 + 0.5;\n\t#ifdef USE_MATCAP\n\t\tvec4 matcapColor = texture2D( matcap, uv );\n\t#else\n\t\tvec4 matcapColor = vec4( vec3( mix( 0.2, 0.8, uv.y ) ), 1.0 );\n\t#endif\n\tvec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",meshnormal_vert:"#define NORMAL\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )\n\tvarying vec3 vViewPosition;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n}",meshnormal_frag:"#define NORMAL\nuniform float opacity;\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )\n\tvarying vec3 vViewPosition;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvec4 diffuseColor = vec4( 0.0, 0.0, 0.0, opacity );\n\t#include \n\t#include \n\t#include \n\t#include \n\tgl_FragColor = vec4( packNormalToRGB( normal ), diffuseColor.a );\n\t#ifdef OPAQUE\n\t\tgl_FragColor.a = 1.0;\n\t#endif\n}",meshphong_vert:"#define PHONG\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvViewPosition = - mvPosition.xyz;\n\t#include \n\t#include \n\t#include \n\t#include \n}",meshphong_frag:"#define PHONG\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform vec3 specular;\nuniform float shininess;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",meshphysical_vert:"#define STANDARD\nvarying vec3 vViewPosition;\n#ifdef USE_TRANSMISSION\n\tvarying vec3 vWorldPosition;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvViewPosition = - mvPosition.xyz;\n\t#include \n\t#include \n\t#include \n#ifdef USE_TRANSMISSION\n\tvWorldPosition = worldPosition.xyz;\n#endif\n}",meshphysical_frag:"#define STANDARD\n#ifdef PHYSICAL\n\t#define IOR\n\t#define USE_SPECULAR\n#endif\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\n#ifdef IOR\n\tuniform float ior;\n#endif\n#ifdef USE_SPECULAR\n\tuniform float specularIntensity;\n\tuniform vec3 specularColor;\n\t#ifdef USE_SPECULAR_COLORMAP\n\t\tuniform sampler2D specularColorMap;\n\t#endif\n\t#ifdef USE_SPECULAR_INTENSITYMAP\n\t\tuniform sampler2D specularIntensityMap;\n\t#endif\n#endif\n#ifdef USE_CLEARCOAT\n\tuniform float clearcoat;\n\tuniform float clearcoatRoughness;\n#endif\n#ifdef USE_DISPERSION\n\tuniform float dispersion;\n#endif\n#ifdef USE_IRIDESCENCE\n\tuniform float iridescence;\n\tuniform float iridescenceIOR;\n\tuniform float iridescenceThicknessMinimum;\n\tuniform float iridescenceThicknessMaximum;\n#endif\n#ifdef USE_SHEEN\n\tuniform vec3 sheenColor;\n\tuniform float sheenRoughness;\n\t#ifdef USE_SHEEN_COLORMAP\n\t\tuniform sampler2D sheenColorMap;\n\t#endif\n\t#ifdef USE_SHEEN_ROUGHNESSMAP\n\t\tuniform sampler2D sheenRoughnessMap;\n\t#endif\n#endif\n#ifdef USE_ANISOTROPY\n\tuniform vec2 anisotropyVector;\n\t#ifdef USE_ANISOTROPYMAP\n\t\tuniform sampler2D anisotropyMap;\n\t#endif\n#endif\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;\n\tvec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular;\n\t#include \n\tvec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;\n\t#ifdef USE_SHEEN\n\t\tfloat sheenEnergyComp = 1.0 - 0.157 * max3( material.sheenColor );\n\t\toutgoingLight = outgoingLight * sheenEnergyComp + sheenSpecularDirect + sheenSpecularIndirect;\n\t#endif\n\t#ifdef USE_CLEARCOAT\n\t\tfloat dotNVcc = saturate( dot( geometryClearcoatNormal, geometryViewDir ) );\n\t\tvec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc );\n\t\toutgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + ( clearcoatSpecularDirect + clearcoatSpecularIndirect ) * material.clearcoat;\n\t#endif\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",meshtoon_vert:"#define TOON\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvViewPosition = - mvPosition.xyz;\n\t#include \n\t#include \n\t#include \n}",meshtoon_frag:"#define TOON\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",points_vert:"uniform float size;\nuniform float scale;\n#include \n#include \n#include \n#include \n#include \n#include \n#ifdef USE_POINTS_UV\n\tvarying vec2 vUv;\n\tuniform mat3 uvTransform;\n#endif\nvoid main() {\n\t#ifdef USE_POINTS_UV\n\t\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n\t#endif\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tgl_PointSize = size;\n\t#ifdef USE_SIZEATTENUATION\n\t\tbool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\t\tif ( isPerspective ) gl_PointSize *= ( scale / - mvPosition.z );\n\t#endif\n\t#include \n\t#include \n\t#include \n\t#include \n}",points_frag:"uniform vec3 diffuse;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\tvec3 outgoingLight = vec3( 0.0 );\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\toutgoingLight = diffuseColor.rgb;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",shadow_vert:"#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",shadow_frag:"uniform vec3 color;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\tgl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );\n\t#include \n\t#include \n\t#include \n}",sprite_vert:"uniform float rotation;\nuniform vec2 center;\n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\tvec4 mvPosition = modelViewMatrix[ 3 ];\n\tvec2 scale = vec2( length( modelMatrix[ 0 ].xyz ), length( modelMatrix[ 1 ].xyz ) );\n\t#ifndef USE_SIZEATTENUATION\n\t\tbool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\t\tif ( isPerspective ) scale *= - mvPosition.z;\n\t#endif\n\tvec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale;\n\tvec2 rotatedPosition;\n\trotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;\n\trotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;\n\tmvPosition.xy += rotatedPosition;\n\tgl_Position = projectionMatrix * mvPosition;\n\t#include \n\t#include \n\t#include \n}",sprite_frag:"uniform vec3 diffuse;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\tvec3 outgoingLight = vec3( 0.0 );\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\toutgoingLight = diffuseColor.rgb;\n\t#include \n\t#include \n\t#include \n\t#include \n}"},fa={common:{diffuse:{value:new tr(16777215)},opacity:{value:1},map:{value:null},mapTransform:{value:new ei},alphaMap:{value:null},alphaMapTransform:{value:new ei},alphaTest:{value:0}},specularmap:{specularMap:{value:null},specularMapTransform:{value:new ei}},envmap:{envMap:{value:null},envMapRotation:{value:new ei},flipEnvMap:{value:-1},reflectivity:{value:1},ior:{value:1.5},refractionRatio:{value:.98}},aomap:{aoMap:{value:null},aoMapIntensity:{value:1},aoMapTransform:{value:new ei}},lightmap:{lightMap:{value:null},lightMapIntensity:{value:1},lightMapTransform:{value:new ei}},bumpmap:{bumpMap:{value:null},bumpMapTransform:{value:new ei},bumpScale:{value:1}},normalmap:{normalMap:{value:null},normalMapTransform:{value:new ei},normalScale:{value:new ti(1,1)}},displacementmap:{displacementMap:{value:null},displacementMapTransform:{value:new ei},displacementScale:{value:1},displacementBias:{value:0}},emissivemap:{emissiveMap:{value:null},emissiveMapTransform:{value:new ei}},metalnessmap:{metalnessMap:{value:null},metalnessMapTransform:{value:new ei}},roughnessmap:{roughnessMap:{value:null},roughnessMapTransform:{value:new ei}},gradientmap:{gradientMap:{value:null}},fog:{fogDensity:{value:25e-5},fogNear:{value:1},fogFar:{value:2e3},fogColor:{value:new tr(16777215)}},lights:{ambientLightColor:{value:[]},lightProbe:{value:[]},directionalLights:{value:[],properties:{direction:{},color:{}}},directionalLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},directionalShadowMap:{value:[]},directionalShadowMatrix:{value:[]},spotLights:{value:[],properties:{color:{},position:{},direction:{},distance:{},coneCos:{},penumbraCos:{},decay:{}}},spotLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},spotLightMap:{value:[]},spotShadowMap:{value:[]},spotLightMatrix:{value:[]},pointLights:{value:[],properties:{color:{},position:{},decay:{},distance:{}}},pointLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{},shadowCameraNear:{},shadowCameraFar:{}}},pointShadowMap:{value:[]},pointShadowMatrix:{value:[]},hemisphereLights:{value:[],properties:{direction:{},skyColor:{},groundColor:{}}},rectAreaLights:{value:[],properties:{color:{},position:{},width:{},height:{}}},ltc_1:{value:null},ltc_2:{value:null}},points:{diffuse:{value:new tr(16777215)},opacity:{value:1},size:{value:1},scale:{value:1},map:{value:null},alphaMap:{value:null},alphaMapTransform:{value:new ei},alphaTest:{value:0},uvTransform:{value:new ei}},sprite:{diffuse:{value:new tr(16777215)},opacity:{value:1},center:{value:new ti(.5,.5)},rotation:{value:0},map:{value:null},mapTransform:{value:new ei},alphaMap:{value:null},alphaMapTransform:{value:new ei},alphaTest:{value:0}}},ga={basic:{uniforms:jr([fa.common,fa.specularmap,fa.envmap,fa.aomap,fa.lightmap,fa.fog]),vertexShader:ma.meshbasic_vert,fragmentShader:ma.meshbasic_frag},lambert:{uniforms:jr([fa.common,fa.specularmap,fa.envmap,fa.aomap,fa.lightmap,fa.emissivemap,fa.bumpmap,fa.normalmap,fa.displacementmap,fa.fog,fa.lights,{emissive:{value:new tr(0)}}]),vertexShader:ma.meshlambert_vert,fragmentShader:ma.meshlambert_frag},phong:{uniforms:jr([fa.common,fa.specularmap,fa.envmap,fa.aomap,fa.lightmap,fa.emissivemap,fa.bumpmap,fa.normalmap,fa.displacementmap,fa.fog,fa.lights,{emissive:{value:new tr(0)},specular:{value:new tr(1118481)},shininess:{value:30}}]),vertexShader:ma.meshphong_vert,fragmentShader:ma.meshphong_frag},standard:{uniforms:jr([fa.common,fa.envmap,fa.aomap,fa.lightmap,fa.emissivemap,fa.bumpmap,fa.normalmap,fa.displacementmap,fa.roughnessmap,fa.metalnessmap,fa.fog,fa.lights,{emissive:{value:new tr(0)},roughness:{value:1},metalness:{value:0},envMapIntensity:{value:1}}]),vertexShader:ma.meshphysical_vert,fragmentShader:ma.meshphysical_frag},toon:{uniforms:jr([fa.common,fa.aomap,fa.lightmap,fa.emissivemap,fa.bumpmap,fa.normalmap,fa.displacementmap,fa.gradientmap,fa.fog,fa.lights,{emissive:{value:new tr(0)}}]),vertexShader:ma.meshtoon_vert,fragmentShader:ma.meshtoon_frag},matcap:{uniforms:jr([fa.common,fa.bumpmap,fa.normalmap,fa.displacementmap,fa.fog,{matcap:{value:null}}]),vertexShader:ma.meshmatcap_vert,fragmentShader:ma.meshmatcap_frag},points:{uniforms:jr([fa.points,fa.fog]),vertexShader:ma.points_vert,fragmentShader:ma.points_frag},dashed:{uniforms:jr([fa.common,fa.fog,{scale:{value:1},dashSize:{value:1},totalSize:{value:2}}]),vertexShader:ma.linedashed_vert,fragmentShader:ma.linedashed_frag},depth:{uniforms:jr([fa.common,fa.displacementmap]),vertexShader:ma.depth_vert,fragmentShader:ma.depth_frag},normal:{uniforms:jr([fa.common,fa.bumpmap,fa.normalmap,fa.displacementmap,{opacity:{value:1}}]),vertexShader:ma.meshnormal_vert,fragmentShader:ma.meshnormal_frag},sprite:{uniforms:jr([fa.sprite,fa.fog]),vertexShader:ma.sprite_vert,fragmentShader:ma.sprite_frag},background:{uniforms:{uvTransform:{value:new ei},t2D:{value:null},backgroundIntensity:{value:1}},vertexShader:ma.background_vert,fragmentShader:ma.background_frag},backgroundCube:{uniforms:{envMap:{value:null},flipEnvMap:{value:-1},backgroundBlurriness:{value:0},backgroundIntensity:{value:1},backgroundRotation:{value:new ei}},vertexShader:ma.backgroundCube_vert,fragmentShader:ma.backgroundCube_frag},cube:{uniforms:{tCube:{value:null},tFlip:{value:-1},opacity:{value:1}},vertexShader:ma.cube_vert,fragmentShader:ma.cube_frag},equirect:{uniforms:{tEquirect:{value:null}},vertexShader:ma.equirect_vert,fragmentShader:ma.equirect_frag},distanceRGBA:{uniforms:jr([fa.common,fa.displacementmap,{referencePosition:{value:new Li},nearDistance:{value:1},farDistance:{value:1e3}}]),vertexShader:ma.distanceRGBA_vert,fragmentShader:ma.distanceRGBA_frag},shadow:{uniforms:jr([fa.lights,fa.fog,{color:{value:new tr(0)},opacity:{value:1}}]),vertexShader:ma.shadow_vert,fragmentShader:ma.shadow_frag}};ga.physical={uniforms:jr([ga.standard.uniforms,{clearcoat:{value:0},clearcoatMap:{value:null},clearcoatMapTransform:{value:new ei},clearcoatNormalMap:{value:null},clearcoatNormalMapTransform:{value:new ei},clearcoatNormalScale:{value:new ti(1,1)},clearcoatRoughness:{value:0},clearcoatRoughnessMap:{value:null},clearcoatRoughnessMapTransform:{value:new ei},dispersion:{value:0},iridescence:{value:0},iridescenceMap:{value:null},iridescenceMapTransform:{value:new ei},iridescenceIOR:{value:1.3},iridescenceThicknessMinimum:{value:100},iridescenceThicknessMaximum:{value:400},iridescenceThicknessMap:{value:null},iridescenceThicknessMapTransform:{value:new ei},sheen:{value:0},sheenColor:{value:new tr(0)},sheenColorMap:{value:null},sheenColorMapTransform:{value:new ei},sheenRoughness:{value:1},sheenRoughnessMap:{value:null},sheenRoughnessMapTransform:{value:new ei},transmission:{value:0},transmissionMap:{value:null},transmissionMapTransform:{value:new ei},transmissionSamplerSize:{value:new ti},transmissionSamplerMap:{value:null},thickness:{value:0},thicknessMap:{value:null},thicknessMapTransform:{value:new ei},attenuationDistance:{value:0},attenuationColor:{value:new tr(0)},specularColor:{value:new tr(1,1,1)},specularColorMap:{value:null},specularColorMapTransform:{value:new ei},specularIntensity:{value:1},specularIntensityMap:{value:null},specularIntensityMapTransform:{value:new ei},anisotropyVector:{value:new ti},anisotropyMap:{value:null},anisotropyMapTransform:{value:new ei}}]),vertexShader:ma.meshphysical_vert,fragmentShader:ma.meshphysical_frag};const va={r:0,b:0,g:0},ya=new ys,_a=new ls;function xa(t,e,n,i,s,r,a){const o=new tr(0);let l,c,u=!0===r?0:1,h=null,d=0,p=null;function m(t){let i=!0===t.isScene?t.background:null;if(i&&i.isTexture){i=(t.backgroundBlurriness>0?n:e).get(i)}return i}function f(e,n){e.getRGB(va,Xr(t)),i.buffers.color.setClear(va.r,va.g,va.b,n,a)}return{getClearColor:function(){return o},setClearColor:function(t,e=1){o.set(t),u=e,f(o,u)},getClearAlpha:function(){return u},setClearAlpha:function(t){u=t,f(o,u)},render:function(e){let n=!1;const s=m(e);null===s?f(o,u):s&&s.isColor&&(f(s,1),n=!0);const r=t.xr.getEnvironmentBlendMode();"additive"===r?i.buffers.color.setClear(0,0,0,1,a):"alpha-blend"===r&&i.buffers.color.setClear(0,0,0,0,a),(t.autoClear||n)&&(i.buffers.depth.setTest(!0),i.buffers.depth.setMask(!0),i.buffers.color.setMask(!0),t.clear(t.autoClearColor,t.autoClearDepth,t.autoClearStencil))},addToRenderList:function(e,n){const i=m(n);i&&(i.isCubeTexture||i.mapping===dt)?(void 0===c&&(c=new kr(new Gr(1,1,1),new Yr({name:"BackgroundCubeMaterial",uniforms:Wr(ga.backgroundCube.uniforms),vertexShader:ga.backgroundCube.vertexShader,fragmentShader:ga.backgroundCube.fragmentShader,side:1,depthTest:!1,depthWrite:!1,fog:!1})),c.geometry.deleteAttribute("normal"),c.geometry.deleteAttribute("uv"),c.onBeforeRender=function(t,e,n){this.matrixWorld.copyPosition(n.matrixWorld)},Object.defineProperty(c.material,"envMap",{get:function(){return this.uniforms.envMap.value}}),s.update(c)),ya.copy(n.backgroundRotation),ya.x*=-1,ya.y*=-1,ya.z*=-1,i.isCubeTexture&&!1===i.isRenderTargetTexture&&(ya.y*=-1,ya.z*=-1),c.material.uniforms.envMap.value=i,c.material.uniforms.flipEnvMap.value=i.isCubeTexture&&!1===i.isRenderTargetTexture?-1:1,c.material.uniforms.backgroundBlurriness.value=n.backgroundBlurriness,c.material.uniforms.backgroundIntensity.value=n.backgroundIntensity,c.material.uniforms.backgroundRotation.value.setFromMatrix4(_a.makeRotationFromEuler(ya)),c.material.toneMapped=mi.getTransfer(i.colorSpace)!==en,h===i&&d===i.version&&p===t.toneMapping||(c.material.needsUpdate=!0,h=i,d=i.version,p=t.toneMapping),c.layers.enableAll(),e.unshift(c,c.geometry,c.material,0,0,null)):i&&i.isTexture&&(void 0===l&&(l=new kr(new pa(2,2),new Yr({name:"BackgroundMaterial",uniforms:Wr(ga.background.uniforms),vertexShader:ga.background.vertexShader,fragmentShader:ga.background.fragmentShader,side:0,depthTest:!1,depthWrite:!1,fog:!1})),l.geometry.deleteAttribute("normal"),Object.defineProperty(l.material,"map",{get:function(){return this.uniforms.t2D.value}}),s.update(l)),l.material.uniforms.t2D.value=i,l.material.uniforms.backgroundIntensity.value=n.backgroundIntensity,l.material.toneMapped=mi.getTransfer(i.colorSpace)!==en,!0===i.matrixAutoUpdate&&i.updateMatrix(),l.material.uniforms.uvTransform.value.copy(i.matrix),h===i&&d===i.version&&p===t.toneMapping||(l.material.needsUpdate=!0,h=i,d=i.version,p=t.toneMapping),l.layers.enableAll(),e.unshift(l,l.geometry,l.material,0,0,null))}}}function Ma(t,e){const n=t.getParameter(t.MAX_VERTEX_ATTRIBS),i={},s=c(null);let r=s,a=!1;function o(e){return t.bindVertexArray(e)}function l(e){return t.deleteVertexArray(e)}function c(t){const e=[],i=[],s=[];for(let t=0;t=0){const n=s[e];let i=a[e];if(void 0===i&&("instanceMatrix"===e&&t.instanceMatrix&&(i=t.instanceMatrix),"instanceColor"===e&&t.instanceColor&&(i=t.instanceColor)),void 0===n)return!0;if(n.attribute!==i)return!0;if(i&&n.data!==i.data)return!0;o++}}return r.attributesNum!==o||r.index!==i}(n,f,l,g),v&&function(t,e,n,i){const s={},a=e.attributes;let o=0;const l=n.getAttributes();for(const e in l){if(l[e].location>=0){let n=a[e];void 0===n&&("instanceMatrix"===e&&t.instanceMatrix&&(n=t.instanceMatrix),"instanceColor"===e&&t.instanceColor&&(n=t.instanceColor));const i={};i.attribute=n,n&&n.data&&(i.data=n.data),s[e]=i,o++}}r.attributes=s,r.attributesNum=o,r.index=i}(n,f,l,g),null!==g&&e.update(g,t.ELEMENT_ARRAY_BUFFER),(v||a)&&(a=!1,function(n,i,s,r){u();const a=r.attributes,o=s.getAttributes(),l=i.defaultAttributeValues;for(const i in o){const s=o[i];if(s.location>=0){let o=a[i];if(void 0===o&&("instanceMatrix"===i&&n.instanceMatrix&&(o=n.instanceMatrix),"instanceColor"===i&&n.instanceColor&&(o=n.instanceColor)),void 0!==o){const i=o.normalized,a=o.itemSize,l=e.get(o);if(void 0===l)continue;const c=l.buffer,u=l.type,p=l.bytesPerElement,f=u===t.INT||u===t.UNSIGNED_INT||o.gpuType===Rt;if(o.isInterleavedBufferAttribute){const e=o.data,l=e.stride,g=o.offset;if(e.isInstancedInterleavedBuffer){for(let t=0;t0&&t.getShaderPrecisionFormat(t.FRAGMENT_SHADER,t.HIGH_FLOAT).precision>0)return"highp";e="mediump"}return"mediump"===e&&t.getShaderPrecisionFormat(t.VERTEX_SHADER,t.MEDIUM_FLOAT).precision>0&&t.getShaderPrecisionFormat(t.FRAGMENT_SHADER,t.MEDIUM_FLOAT).precision>0?"mediump":"lowp"}let a=void 0!==n.precision?n.precision:"highp";const o=r(a);o!==a&&(console.warn("THREE.WebGLRenderer:",a,"not supported, using",o,"instead."),a=o);const l=!0===n.logarithmicDepthBuffer,c=!0===n.reverseDepthBuffer&&e.has("EXT_clip_control");if(!0===c){const t=e.get("EXT_clip_control");t.clipControlEXT(t.LOWER_LEFT_EXT,t.ZERO_TO_ONE_EXT)}const u=t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS),h=t.getParameter(t.MAX_VERTEX_TEXTURE_IMAGE_UNITS);return{isWebGL2:!0,getMaxAnisotropy:function(){if(void 0!==s)return s;if(!0===e.has("EXT_texture_filter_anisotropic")){const n=e.get("EXT_texture_filter_anisotropic");s=t.getParameter(n.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else s=0;return s},getMaxPrecision:r,textureFormatReadable:function(e){return e===Bt||i.convert(e)===t.getParameter(t.IMPLEMENTATION_COLOR_READ_FORMAT)},textureTypeReadable:function(n){const s=n===Pt&&(e.has("EXT_color_buffer_half_float")||e.has("EXT_color_buffer_float"));return!(n!==Et&&i.convert(n)!==t.getParameter(t.IMPLEMENTATION_COLOR_READ_TYPE)&&n!==Lt&&!s)},precision:a,logarithmicDepthBuffer:l,reverseDepthBuffer:c,maxTextures:u,maxVertexTextures:h,maxTextureSize:t.getParameter(t.MAX_TEXTURE_SIZE),maxCubemapSize:t.getParameter(t.MAX_CUBE_MAP_TEXTURE_SIZE),maxAttributes:t.getParameter(t.MAX_VERTEX_ATTRIBS),maxVertexUniforms:t.getParameter(t.MAX_VERTEX_UNIFORM_VECTORS),maxVaryings:t.getParameter(t.MAX_VARYING_VECTORS),maxFragmentUniforms:t.getParameter(t.MAX_FRAGMENT_UNIFORM_VECTORS),vertexTextures:h>0,maxSamples:t.getParameter(t.MAX_SAMPLES)}}function Sa(t){const e=this;let n=null,i=0,s=!1,r=!1;const a=new oa,o=new ei,l={value:null,needsUpdate:!1};function c(t,n,i,s){const r=null!==t?t.length:0;let c=null;if(0!==r){if(c=l.value,!0!==s||null===c){const e=i+4*r,s=n.matrixWorldInverse;o.getNormalMatrix(s),(null===c||c.length0);e.numPlanes=i,e.numIntersection=0}();else{const t=r?0:i,e=4*t;let s=m.clippingState||null;l.value=s,s=c(h,o,e,u);for(let t=0;t!==e;++t)s[t]=n[t];m.clippingState=s,this.numIntersection=d?this.numPlanes:0,this.numPlanes+=t}}}function wa(t){let e=new WeakMap;function n(t,e){return e===ut?t.mapping=lt:e===ht&&(t.mapping=ct),t}function i(t){const n=t.target;n.removeEventListener("dispose",i);const s=e.get(n);void 0!==s&&(e.delete(n),s.dispose())}return{get:function(s){if(s&&s.isTexture){const r=s.mapping;if(r===ut||r===ht){if(e.has(s)){return n(e.get(s).texture,s.mapping)}{const r=s.image;if(r&&r.height>0){const a=new ia(r.height);return a.fromEquirectangularTexture(t,s),e.set(s,a),s.addEventListener("dispose",i),n(a.texture,s.mapping)}return null}}}return s},dispose:function(){e=new WeakMap}}}class Ea extends Zr{constructor(t=-1,e=1,n=1,i=-1,s=.1,r=2e3){super(),this.isOrthographicCamera=!0,this.type="OrthographicCamera",this.zoom=1,this.view=null,this.left=t,this.right=e,this.top=n,this.bottom=i,this.near=s,this.far=r,this.updateProjectionMatrix()}copy(t,e){return super.copy(t,e),this.left=t.left,this.right=t.right,this.top=t.top,this.bottom=t.bottom,this.near=t.near,this.far=t.far,this.zoom=t.zoom,this.view=null===t.view?null:Object.assign({},t.view),this}setViewOffset(t,e,n,i,s,r){null===this.view&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=t,this.view.fullHeight=e,this.view.offsetX=n,this.view.offsetY=i,this.view.width=s,this.view.height=r,this.updateProjectionMatrix()}clearViewOffset(){null!==this.view&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const t=(this.right-this.left)/(2*this.zoom),e=(this.top-this.bottom)/(2*this.zoom),n=(this.right+this.left)/2,i=(this.top+this.bottom)/2;let s=n-t,r=n+t,a=i+e,o=i-e;if(null!==this.view&&this.view.enabled){const t=(this.right-this.left)/this.view.fullWidth/this.zoom,e=(this.top-this.bottom)/this.view.fullHeight/this.zoom;s+=t*this.view.offsetX,r=s+t*this.view.width,a-=e*this.view.offsetY,o=a-e*this.view.height}this.projectionMatrix.makeOrthographic(s,r,a,o,this.near,this.far,this.coordinateSystem),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(t){const e=super.toJSON(t);return e.object.zoom=this.zoom,e.object.left=this.left,e.object.right=this.right,e.object.top=this.top,e.object.bottom=this.bottom,e.object.near=this.near,e.object.far=this.far,null!==this.view&&(e.object.view=Object.assign({},this.view)),e}}const Aa=[.125,.215,.35,.446,.526,.582],Na=20,Ca=new Ea,Ra=new tr;let Ia=null,La=0,Pa=0,Ua=!1;const Da=(1+Math.sqrt(5))/2,Oa=1/Da,za=[new Li(-Da,Oa,0),new Li(Da,Oa,0),new Li(-Oa,0,Da),new Li(Oa,0,Da),new Li(0,Da,-Oa),new Li(0,Da,Oa),new Li(-1,1,-1),new Li(1,1,-1),new Li(-1,1,1),new Li(1,1,1)];let Va=class{constructor(t){this._renderer=t,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._lodPlanes=[],this._sizeLods=[],this._sigmas=[],this._blurMaterial=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._compileMaterial(this._blurMaterial)}fromScene(t,e=0,n=.1,i=100){Ia=this._renderer.getRenderTarget(),La=this._renderer.getActiveCubeFace(),Pa=this._renderer.getActiveMipmapLevel(),Ua=this._renderer.xr.enabled,this._renderer.xr.enabled=!1,this._setSize(256);const s=this._allocateTargets();return s.depthBuffer=!0,this._sceneToCubeUV(t,n,i,s),e>0&&this._blur(s,0,0,e),this._applyPMREM(s),this._cleanup(s),s}fromEquirectangular(t,e=null){return this._fromTexture(t,e)}fromCubemap(t,e=null){return this._fromTexture(t,e)}compileCubemapShader(){null===this._cubemapMaterial&&(this._cubemapMaterial=Ga(),this._compileMaterial(this._cubemapMaterial))}compileEquirectangularShader(){null===this._equirectMaterial&&(this._equirectMaterial=Ha(),this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),null!==this._cubemapMaterial&&this._cubemapMaterial.dispose(),null!==this._equirectMaterial&&this._equirectMaterial.dispose()}_setSize(t){this._lodMax=Math.floor(Math.log2(t)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){null!==this._blurMaterial&&this._blurMaterial.dispose(),null!==this._pingPongRenderTarget&&this._pingPongRenderTarget.dispose();for(let t=0;t\n\n\t\t\tvec3 getSample( float theta, vec3 axis ) {\n\n\t\t\t\tfloat cosTheta = cos( theta );\n\t\t\t\t// Rodrigues' axis-angle rotation\n\t\t\t\tvec3 sampleDirection = vOutputDirection * cosTheta\n\t\t\t\t\t+ cross( axis, vOutputDirection ) * sin( theta )\n\t\t\t\t\t+ axis * dot( axis, vOutputDirection ) * ( 1.0 - cosTheta );\n\n\t\t\t\treturn bilinearCubeUV( envMap, sampleDirection, mipInt );\n\n\t\t\t}\n\n\t\t\tvoid main() {\n\n\t\t\t\tvec3 axis = latitudinal ? poleAxis : cross( poleAxis, vOutputDirection );\n\n\t\t\t\tif ( all( equal( axis, vec3( 0.0 ) ) ) ) {\n\n\t\t\t\t\taxis = vec3( vOutputDirection.z, 0.0, - vOutputDirection.x );\n\n\t\t\t\t}\n\n\t\t\t\taxis = normalize( axis );\n\n\t\t\t\tgl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );\n\t\t\t\tgl_FragColor.rgb += weights[ 0 ] * getSample( 0.0, axis );\n\n\t\t\t\tfor ( int i = 1; i < n; i++ ) {\n\n\t\t\t\t\tif ( i >= samples ) {\n\n\t\t\t\t\t\tbreak;\n\n\t\t\t\t\t}\n\n\t\t\t\t\tfloat theta = dTheta * float( i );\n\t\t\t\t\tgl_FragColor.rgb += weights[ i ] * getSample( -1.0 * theta, axis );\n\t\t\t\t\tgl_FragColor.rgb += weights[ i ] * getSample( theta, axis );\n\n\t\t\t\t}\n\n\t\t\t}\n\t\t",blending:0,depthTest:!1,depthWrite:!1});return r}(i,t,e)}return i}_compileMaterial(t){const e=new kr(this._lodPlanes[0],t);this._renderer.compile(e,Ca)}_sceneToCubeUV(t,e,n,i){const s=new Qr(90,1,e,n),r=[1,-1,1,1,1,1],a=[1,1,1,-1,-1,-1],o=this._renderer,l=o.autoClear,c=o.toneMapping;o.getClearColor(Ra),o.toneMapping=0,o.autoClear=!1;const u=new sr({name:"PMREM.Background",side:1,depthWrite:!1,depthTest:!1}),h=new kr(new Gr,u);let d=!1;const p=t.background;p?p.isColor&&(u.color.copy(p),t.background=null,d=!0):(u.color.copy(Ra),d=!0);for(let e=0;e<6;e++){const n=e%3;0===n?(s.up.set(0,r[e],0),s.lookAt(a[e],0,0)):1===n?(s.up.set(0,0,r[e]),s.lookAt(0,a[e],0)):(s.up.set(0,r[e],0),s.lookAt(0,0,a[e]));const l=this._cubeSize;ka(i,n*l,e>2?l:0,l,l),o.setRenderTarget(i),d&&o.render(h,s),o.render(t,s)}h.geometry.dispose(),h.material.dispose(),o.toneMapping=c,o.autoClear=l,t.background=p}_textureToCubeUV(t,e){const n=this._renderer,i=t.mapping===lt||t.mapping===ct;i?(null===this._cubemapMaterial&&(this._cubemapMaterial=Ga()),this._cubemapMaterial.uniforms.flipEnvMap.value=!1===t.isRenderTargetTexture?-1:1):null===this._equirectMaterial&&(this._equirectMaterial=Ha());const s=i?this._cubemapMaterial:this._equirectMaterial,r=new kr(this._lodPlanes[0],s);s.uniforms.envMap.value=t;const a=this._cubeSize;ka(e,0,0,3*a,2*a),n.setRenderTarget(e),n.render(r,Ca)}_applyPMREM(t){const e=this._renderer,n=e.autoClear;e.autoClear=!1;const i=this._lodPlanes.length;for(let e=1;eNa&&console.warn(`sigmaRadians, ${s}, is too large and will clip, as it requested ${m} samples when the maximum is set to 20`);const f=[];let g=0;for(let t=0;tv-4?i-v+4:0),4*(this._cubeSize-y),3*y,2*y),o.setRenderTarget(e),o.render(c,Ca)}};function Fa(t){const e=[],n=[],i=[];let s=t;const r=t-4+1+Aa.length;for(let a=0;at-4?o=Aa[a-t+4-1]:0===a&&(o=0),i.push(o);const l=1/(r-2),c=-l,u=1+l,h=[c,c,u,c,u,u,c,c,u,u,c,u],d=6,p=6,m=3,f=2,g=1,v=new Float32Array(m*p*d),y=new Float32Array(f*p*d),_=new Float32Array(g*p*d);for(let t=0;t2?0:-1,i=[e,n,0,e+2/3,n,0,e+2/3,n+1,0,e,n,0,e+2/3,n+1,0,e,n+1,0];v.set(i,m*p*t),y.set(h,f*p*t);const s=[t,t,t,t,t,t];_.set(s,g*p*t)}const x=new Cr;x.setAttribute("position",new dr(v,m)),x.setAttribute("uv",new dr(y,f)),x.setAttribute("faceIndex",new dr(_,g)),e.push(x),s>4&&s--}return{lodPlanes:e,sizeLods:n,sigmas:i}}function Ba(t,e,n){const i=new Ei(t,e,n);return i.texture.mapping=dt,i.texture.name="PMREM.cubeUv",i.scissorTest=!0,i}function ka(t,e,n,i,s){t.viewport.set(e,n,i,s),t.scissor.set(e,n,i,s)}function Ha(){return new Yr({name:"EquirectangularToCubeUV",uniforms:{envMap:{value:null}},vertexShader:Wa(),fragmentShader:"\n\n\t\t\tprecision mediump float;\n\t\t\tprecision mediump int;\n\n\t\t\tvarying vec3 vOutputDirection;\n\n\t\t\tuniform sampler2D envMap;\n\n\t\t\t#include \n\n\t\t\tvoid main() {\n\n\t\t\t\tvec3 outputDirection = normalize( vOutputDirection );\n\t\t\t\tvec2 uv = equirectUv( outputDirection );\n\n\t\t\t\tgl_FragColor = vec4( texture2D ( envMap, uv ).rgb, 1.0 );\n\n\t\t\t}\n\t\t",blending:0,depthTest:!1,depthWrite:!1})}function Ga(){return new Yr({name:"CubemapToCubeUV",uniforms:{envMap:{value:null},flipEnvMap:{value:-1}},vertexShader:Wa(),fragmentShader:"\n\n\t\t\tprecision mediump float;\n\t\t\tprecision mediump int;\n\n\t\t\tuniform float flipEnvMap;\n\n\t\t\tvarying vec3 vOutputDirection;\n\n\t\t\tuniform samplerCube envMap;\n\n\t\t\tvoid main() {\n\n\t\t\t\tgl_FragColor = textureCube( envMap, vec3( flipEnvMap * vOutputDirection.x, vOutputDirection.yz ) );\n\n\t\t\t}\n\t\t",blending:0,depthTest:!1,depthWrite:!1})}function Wa(){return"\n\n\t\tprecision mediump float;\n\t\tprecision mediump int;\n\n\t\tattribute float faceIndex;\n\n\t\tvarying vec3 vOutputDirection;\n\n\t\t// RH coordinate system; PMREM face-indexing convention\n\t\tvec3 getDirection( vec2 uv, float face ) {\n\n\t\t\tuv = 2.0 * uv - 1.0;\n\n\t\t\tvec3 direction = vec3( uv, 1.0 );\n\n\t\t\tif ( face == 0.0 ) {\n\n\t\t\t\tdirection = direction.zyx; // ( 1, v, u ) pos x\n\n\t\t\t} else if ( face == 1.0 ) {\n\n\t\t\t\tdirection = direction.xzy;\n\t\t\t\tdirection.xz *= -1.0; // ( -u, 1, -v ) pos y\n\n\t\t\t} else if ( face == 2.0 ) {\n\n\t\t\t\tdirection.x *= -1.0; // ( -u, v, 1 ) pos z\n\n\t\t\t} else if ( face == 3.0 ) {\n\n\t\t\t\tdirection = direction.zyx;\n\t\t\t\tdirection.xz *= -1.0; // ( -1, v, -u ) neg x\n\n\t\t\t} else if ( face == 4.0 ) {\n\n\t\t\t\tdirection = direction.xzy;\n\t\t\t\tdirection.xy *= -1.0; // ( -u, -1, v ) neg y\n\n\t\t\t} else if ( face == 5.0 ) {\n\n\t\t\t\tdirection.z *= -1.0; // ( u, v, -1 ) neg z\n\n\t\t\t}\n\n\t\t\treturn direction;\n\n\t\t}\n\n\t\tvoid main() {\n\n\t\t\tvOutputDirection = getDirection( uv, faceIndex );\n\t\t\tgl_Position = vec4( position, 1.0 );\n\n\t\t}\n\t"}function ja(t){let e=new WeakMap,n=null;function i(t){const n=t.target;n.removeEventListener("dispose",i);const s=e.get(n);void 0!==s&&(e.delete(n),s.dispose())}return{get:function(s){if(s&&s.isTexture){const r=s.mapping,a=r===ut||r===ht,o=r===lt||r===ct;if(a||o){let r=e.get(s);const l=void 0!==r?r.texture.pmremVersion:0;if(s.isRenderTargetTexture&&s.pmremVersion!==l)return null===n&&(n=new Va(t)),r=a?n.fromEquirectangular(s,r):n.fromCubemap(s,r),r.texture.pmremVersion=s.pmremVersion,e.set(s,r),r.texture;if(void 0!==r)return r.texture;{const l=s.image;return a&&l&&l.height>0||o&&l&&function(t){let e=0;const n=6;for(let i=0;ie.maxTextureSize&&(x=Math.ceil(_/e.maxTextureSize),_=e.maxTextureSize);const M=new Float32Array(_*x*4*u),b=new Ai(M,_,x,u);b.type=Lt,b.needsUpdate=!0;const T=4*y;for(let w=0;w0)return t;const s=e*n;let r=so[s];if(void 0===r&&(r=new Float32Array(s),so[s]=r),0!==e){i.toArray(r,0);for(let i=1,s=0;i!==e;++i)s+=n,t[i].toArray(r,s)}return r}function uo(t,e){if(t.length!==e.length)return!1;for(let n=0,i=t.length;n":" "} ${s}: ${n[t]}`)}return i.join("\n")}(t.getShaderSource(e),i)}return s}function ll(t,e){const n=function(t){const e=mi.getPrimaries(mi.workingColorSpace),n=mi.getPrimaries(t);let i;switch(e===n?i="":e===sn&&n===nn?i="LinearDisplayP3ToLinearSRGB":e===nn&&n===sn&&(i="LinearSRGBToLinearDisplayP3"),t){case Je:case Qe:return[i,"LinearTransferOETF"];case $e:case Ke:return[i,"sRGBTransferOETF"];default:return console.warn("THREE.WebGLProgram: Unsupported color space:",t),[i,"LinearTransferOETF"]}}(e);return`vec4 ${t}( vec4 value ) { return ${n[0]}( ${n[1]}( value ) ); }`}function cl(t,e){let n;switch(e){case 1:n="Linear";break;case 2:n="Reinhard";break;case 3:n="Cineon";break;case 4:n="ACESFilmic";break;case 6:n="AgX";break;case 7:n="Neutral";break;case 5:n="Custom";break;default:console.warn("THREE.WebGLProgram: Unsupported toneMapping:",e),n="Linear"}return"vec3 "+t+"( vec3 color ) { return "+n+"ToneMapping( color ); }"}const ul=new Li;function hl(){mi.getLuminanceCoefficients(ul);return["float luminance( const in vec3 rgb ) {",`\tconst vec3 weights = vec3( ${ul.x.toFixed(4)}, ${ul.y.toFixed(4)}, ${ul.z.toFixed(4)} );`,"\treturn dot( weights, rgb );","}"].join("\n")}function dl(t){return""!==t}function pl(t,e){const n=e.numSpotLightShadows+e.numSpotLightMaps-e.numSpotLightShadowsWithMaps;return t.replace(/NUM_DIR_LIGHTS/g,e.numDirLights).replace(/NUM_SPOT_LIGHTS/g,e.numSpotLights).replace(/NUM_SPOT_LIGHT_MAPS/g,e.numSpotLightMaps).replace(/NUM_SPOT_LIGHT_COORDS/g,n).replace(/NUM_RECT_AREA_LIGHTS/g,e.numRectAreaLights).replace(/NUM_POINT_LIGHTS/g,e.numPointLights).replace(/NUM_HEMI_LIGHTS/g,e.numHemiLights).replace(/NUM_DIR_LIGHT_SHADOWS/g,e.numDirLightShadows).replace(/NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS/g,e.numSpotLightShadowsWithMaps).replace(/NUM_SPOT_LIGHT_SHADOWS/g,e.numSpotLightShadows).replace(/NUM_POINT_LIGHT_SHADOWS/g,e.numPointLightShadows)}function ml(t,e){return t.replace(/NUM_CLIPPING_PLANES/g,e.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g,e.numClippingPlanes-e.numClipIntersection)}const fl=/^[ \t]*#include +<([\w\d./]+)>/gm;function gl(t){return t.replace(fl,yl)}const vl=new Map;function yl(t,e){let n=ma[e];if(void 0===n){const t=vl.get(e);if(void 0===t)throw new Error("Can not resolve #include <"+e+">");n=ma[t],console.warn('THREE.WebGLRenderer: Shader chunk "%s" has been deprecated. Use "%s" instead.',e,t)}return gl(n)}const _l=/#pragma unroll_loop_start\s+for\s*\(\s*int\s+i\s*=\s*(\d+)\s*;\s*i\s*<\s*(\d+)\s*;\s*i\s*\+\+\s*\)\s*{([\s\S]+?)}\s+#pragma unroll_loop_end/g;function xl(t){return t.replace(_l,Ml)}function Ml(t,e,n,i){let s="";for(let t=parseInt(e);t0&&(g+="\n"),v=["#define SHADER_TYPE "+n.shaderType,"#define SHADER_NAME "+n.shaderName,m].filter(dl).join("\n"),v.length>0&&(v+="\n")):(g=[bl(n),"#define SHADER_TYPE "+n.shaderType,"#define SHADER_NAME "+n.shaderName,m,n.extensionClipCullDistance?"#define USE_CLIP_DISTANCE":"",n.batching?"#define USE_BATCHING":"",n.batchingColor?"#define USE_BATCHING_COLOR":"",n.instancing?"#define USE_INSTANCING":"",n.instancingColor?"#define USE_INSTANCING_COLOR":"",n.instancingMorph?"#define USE_INSTANCING_MORPH":"",n.useFog&&n.fog?"#define USE_FOG":"",n.useFog&&n.fogExp2?"#define FOG_EXP2":"",n.map?"#define USE_MAP":"",n.envMap?"#define USE_ENVMAP":"",n.envMap?"#define "+u:"",n.lightMap?"#define USE_LIGHTMAP":"",n.aoMap?"#define USE_AOMAP":"",n.bumpMap?"#define USE_BUMPMAP":"",n.normalMap?"#define USE_NORMALMAP":"",n.normalMapObjectSpace?"#define USE_NORMALMAP_OBJECTSPACE":"",n.normalMapTangentSpace?"#define USE_NORMALMAP_TANGENTSPACE":"",n.displacementMap?"#define USE_DISPLACEMENTMAP":"",n.emissiveMap?"#define USE_EMISSIVEMAP":"",n.anisotropy?"#define USE_ANISOTROPY":"",n.anisotropyMap?"#define USE_ANISOTROPYMAP":"",n.clearcoatMap?"#define USE_CLEARCOATMAP":"",n.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",n.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",n.iridescenceMap?"#define USE_IRIDESCENCEMAP":"",n.iridescenceThicknessMap?"#define USE_IRIDESCENCE_THICKNESSMAP":"",n.specularMap?"#define USE_SPECULARMAP":"",n.specularColorMap?"#define USE_SPECULAR_COLORMAP":"",n.specularIntensityMap?"#define USE_SPECULAR_INTENSITYMAP":"",n.roughnessMap?"#define USE_ROUGHNESSMAP":"",n.metalnessMap?"#define USE_METALNESSMAP":"",n.alphaMap?"#define USE_ALPHAMAP":"",n.alphaHash?"#define USE_ALPHAHASH":"",n.transmission?"#define USE_TRANSMISSION":"",n.transmissionMap?"#define USE_TRANSMISSIONMAP":"",n.thicknessMap?"#define USE_THICKNESSMAP":"",n.sheenColorMap?"#define USE_SHEEN_COLORMAP":"",n.sheenRoughnessMap?"#define USE_SHEEN_ROUGHNESSMAP":"",n.mapUv?"#define MAP_UV "+n.mapUv:"",n.alphaMapUv?"#define ALPHAMAP_UV "+n.alphaMapUv:"",n.lightMapUv?"#define LIGHTMAP_UV "+n.lightMapUv:"",n.aoMapUv?"#define AOMAP_UV "+n.aoMapUv:"",n.emissiveMapUv?"#define EMISSIVEMAP_UV "+n.emissiveMapUv:"",n.bumpMapUv?"#define BUMPMAP_UV "+n.bumpMapUv:"",n.normalMapUv?"#define NORMALMAP_UV "+n.normalMapUv:"",n.displacementMapUv?"#define DISPLACEMENTMAP_UV "+n.displacementMapUv:"",n.metalnessMapUv?"#define METALNESSMAP_UV "+n.metalnessMapUv:"",n.roughnessMapUv?"#define ROUGHNESSMAP_UV "+n.roughnessMapUv:"",n.anisotropyMapUv?"#define ANISOTROPYMAP_UV "+n.anisotropyMapUv:"",n.clearcoatMapUv?"#define CLEARCOATMAP_UV "+n.clearcoatMapUv:"",n.clearcoatNormalMapUv?"#define CLEARCOAT_NORMALMAP_UV "+n.clearcoatNormalMapUv:"",n.clearcoatRoughnessMapUv?"#define CLEARCOAT_ROUGHNESSMAP_UV "+n.clearcoatRoughnessMapUv:"",n.iridescenceMapUv?"#define IRIDESCENCEMAP_UV "+n.iridescenceMapUv:"",n.iridescenceThicknessMapUv?"#define IRIDESCENCE_THICKNESSMAP_UV "+n.iridescenceThicknessMapUv:"",n.sheenColorMapUv?"#define SHEEN_COLORMAP_UV "+n.sheenColorMapUv:"",n.sheenRoughnessMapUv?"#define SHEEN_ROUGHNESSMAP_UV "+n.sheenRoughnessMapUv:"",n.specularMapUv?"#define SPECULARMAP_UV "+n.specularMapUv:"",n.specularColorMapUv?"#define SPECULAR_COLORMAP_UV "+n.specularColorMapUv:"",n.specularIntensityMapUv?"#define SPECULAR_INTENSITYMAP_UV "+n.specularIntensityMapUv:"",n.transmissionMapUv?"#define TRANSMISSIONMAP_UV "+n.transmissionMapUv:"",n.thicknessMapUv?"#define THICKNESSMAP_UV "+n.thicknessMapUv:"",n.vertexTangents&&!1===n.flatShading?"#define USE_TANGENT":"",n.vertexColors?"#define USE_COLOR":"",n.vertexAlphas?"#define USE_COLOR_ALPHA":"",n.vertexUv1s?"#define USE_UV1":"",n.vertexUv2s?"#define USE_UV2":"",n.vertexUv3s?"#define USE_UV3":"",n.pointsUvs?"#define USE_POINTS_UV":"",n.flatShading?"#define FLAT_SHADED":"",n.skinning?"#define USE_SKINNING":"",n.morphTargets?"#define USE_MORPHTARGETS":"",n.morphNormals&&!1===n.flatShading?"#define USE_MORPHNORMALS":"",n.morphColors?"#define USE_MORPHCOLORS":"",n.morphTargetsCount>0?"#define MORPHTARGETS_TEXTURE_STRIDE "+n.morphTextureStride:"",n.morphTargetsCount>0?"#define MORPHTARGETS_COUNT "+n.morphTargetsCount:"",n.doubleSided?"#define DOUBLE_SIDED":"",n.flipSided?"#define FLIP_SIDED":"",n.shadowMapEnabled?"#define USE_SHADOWMAP":"",n.shadowMapEnabled?"#define "+l:"",n.sizeAttenuation?"#define USE_SIZEATTENUATION":"",n.numLightProbes>0?"#define USE_LIGHT_PROBES":"",n.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"",n.reverseDepthBuffer?"#define USE_REVERSEDEPTHBUF":"","uniform mat4 modelMatrix;","uniform mat4 modelViewMatrix;","uniform mat4 projectionMatrix;","uniform mat4 viewMatrix;","uniform mat3 normalMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;","#ifdef USE_INSTANCING","\tattribute mat4 instanceMatrix;","#endif","#ifdef USE_INSTANCING_COLOR","\tattribute vec3 instanceColor;","#endif","#ifdef USE_INSTANCING_MORPH","\tuniform sampler2D morphTexture;","#endif","attribute vec3 position;","attribute vec3 normal;","attribute vec2 uv;","#ifdef USE_UV1","\tattribute vec2 uv1;","#endif","#ifdef USE_UV2","\tattribute vec2 uv2;","#endif","#ifdef USE_UV3","\tattribute vec2 uv3;","#endif","#ifdef USE_TANGENT","\tattribute vec4 tangent;","#endif","#if defined( USE_COLOR_ALPHA )","\tattribute vec4 color;","#elif defined( USE_COLOR )","\tattribute vec3 color;","#endif","#ifdef USE_SKINNING","\tattribute vec4 skinIndex;","\tattribute vec4 skinWeight;","#endif","\n"].filter(dl).join("\n"),v=[bl(n),"#define SHADER_TYPE "+n.shaderType,"#define SHADER_NAME "+n.shaderName,m,n.useFog&&n.fog?"#define USE_FOG":"",n.useFog&&n.fogExp2?"#define FOG_EXP2":"",n.alphaToCoverage?"#define ALPHA_TO_COVERAGE":"",n.map?"#define USE_MAP":"",n.matcap?"#define USE_MATCAP":"",n.envMap?"#define USE_ENVMAP":"",n.envMap?"#define "+c:"",n.envMap?"#define "+u:"",n.envMap?"#define "+h:"",d?"#define CUBEUV_TEXEL_WIDTH "+d.texelWidth:"",d?"#define CUBEUV_TEXEL_HEIGHT "+d.texelHeight:"",d?"#define CUBEUV_MAX_MIP "+d.maxMip+".0":"",n.lightMap?"#define USE_LIGHTMAP":"",n.aoMap?"#define USE_AOMAP":"",n.bumpMap?"#define USE_BUMPMAP":"",n.normalMap?"#define USE_NORMALMAP":"",n.normalMapObjectSpace?"#define USE_NORMALMAP_OBJECTSPACE":"",n.normalMapTangentSpace?"#define USE_NORMALMAP_TANGENTSPACE":"",n.emissiveMap?"#define USE_EMISSIVEMAP":"",n.anisotropy?"#define USE_ANISOTROPY":"",n.anisotropyMap?"#define USE_ANISOTROPYMAP":"",n.clearcoat?"#define USE_CLEARCOAT":"",n.clearcoatMap?"#define USE_CLEARCOATMAP":"",n.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",n.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",n.dispersion?"#define USE_DISPERSION":"",n.iridescence?"#define USE_IRIDESCENCE":"",n.iridescenceMap?"#define USE_IRIDESCENCEMAP":"",n.iridescenceThicknessMap?"#define USE_IRIDESCENCE_THICKNESSMAP":"",n.specularMap?"#define USE_SPECULARMAP":"",n.specularColorMap?"#define USE_SPECULAR_COLORMAP":"",n.specularIntensityMap?"#define USE_SPECULAR_INTENSITYMAP":"",n.roughnessMap?"#define USE_ROUGHNESSMAP":"",n.metalnessMap?"#define USE_METALNESSMAP":"",n.alphaMap?"#define USE_ALPHAMAP":"",n.alphaTest?"#define USE_ALPHATEST":"",n.alphaHash?"#define USE_ALPHAHASH":"",n.sheen?"#define USE_SHEEN":"",n.sheenColorMap?"#define USE_SHEEN_COLORMAP":"",n.sheenRoughnessMap?"#define USE_SHEEN_ROUGHNESSMAP":"",n.transmission?"#define USE_TRANSMISSION":"",n.transmissionMap?"#define USE_TRANSMISSIONMAP":"",n.thicknessMap?"#define USE_THICKNESSMAP":"",n.vertexTangents&&!1===n.flatShading?"#define USE_TANGENT":"",n.vertexColors||n.instancingColor||n.batchingColor?"#define USE_COLOR":"",n.vertexAlphas?"#define USE_COLOR_ALPHA":"",n.vertexUv1s?"#define USE_UV1":"",n.vertexUv2s?"#define USE_UV2":"",n.vertexUv3s?"#define USE_UV3":"",n.pointsUvs?"#define USE_POINTS_UV":"",n.gradientMap?"#define USE_GRADIENTMAP":"",n.flatShading?"#define FLAT_SHADED":"",n.doubleSided?"#define DOUBLE_SIDED":"",n.flipSided?"#define FLIP_SIDED":"",n.shadowMapEnabled?"#define USE_SHADOWMAP":"",n.shadowMapEnabled?"#define "+l:"",n.premultipliedAlpha?"#define PREMULTIPLIED_ALPHA":"",n.numLightProbes>0?"#define USE_LIGHT_PROBES":"",n.decodeVideoTexture?"#define DECODE_VIDEO_TEXTURE":"",n.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"",n.reverseDepthBuffer?"#define USE_REVERSEDEPTHBUF":"","uniform mat4 viewMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;",0!==n.toneMapping?"#define TONE_MAPPING":"",0!==n.toneMapping?ma.tonemapping_pars_fragment:"",0!==n.toneMapping?cl("toneMapping",n.toneMapping):"",n.dithering?"#define DITHERING":"",n.opaque?"#define OPAQUE":"",ma.colorspace_pars_fragment,ll("linearToOutputTexel",n.outputColorSpace),hl(),n.useDepthPacking?"#define DEPTH_PACKING "+n.depthPacking:"","\n"].filter(dl).join("\n")),a=gl(a),a=pl(a,n),a=ml(a,n),o=gl(o),o=pl(o,n),o=ml(o,n),a=xl(a),o=xl(o),!0!==n.isRawShaderMaterial&&(y="#version 300 es\n",g=[p,"#define attribute in","#define varying out","#define texture2D texture"].join("\n")+"\n"+g,v=["#define varying in",n.glslVersion===Fn?"":"layout(location = 0) out highp vec4 pc_fragColor;",n.glslVersion===Fn?"":"#define gl_FragColor pc_fragColor","#define gl_FragDepthEXT gl_FragDepth","#define texture2D texture","#define textureCube texture","#define texture2DProj textureProj","#define texture2DLodEXT textureLod","#define texture2DProjLodEXT textureProjLod","#define textureCubeLodEXT textureLod","#define texture2DGradEXT textureGrad","#define texture2DProjGradEXT textureProjGrad","#define textureCubeGradEXT textureGrad"].join("\n")+"\n"+v);const _=y+g+a,x=y+v+o,M=rl(s,s.VERTEX_SHADER,_),b=rl(s,s.FRAGMENT_SHADER,x);function T(e){if(t.debug.checkShaderErrors){const n=s.getProgramInfoLog(f).trim(),i=s.getShaderInfoLog(M).trim(),r=s.getShaderInfoLog(b).trim();let a=!0,o=!0;if(!1===s.getProgramParameter(f,s.LINK_STATUS))if(a=!1,"function"==typeof t.debug.onShaderError)t.debug.onShaderError(s,f,M,b);else{const t=ol(s,M,"vertex"),i=ol(s,b,"fragment");console.error("THREE.WebGLProgram: Shader Error "+s.getError()+" - VALIDATE_STATUS "+s.getProgramParameter(f,s.VALIDATE_STATUS)+"\n\nMaterial Name: "+e.name+"\nMaterial Type: "+e.type+"\n\nProgram Info Log: "+n+"\n"+t+"\n"+i)}else""!==n?console.warn("THREE.WebGLProgram: Program Info Log:",n):""!==i&&""!==r||(o=!1);o&&(e.diagnostics={runnable:a,programLog:n,vertexShader:{log:i,prefix:g},fragmentShader:{log:r,prefix:v}})}s.deleteShader(M),s.deleteShader(b),S=new sl(s,f),w=function(t,e){const n={},i=t.getProgramParameter(e,t.ACTIVE_ATTRIBUTES);for(let s=0;s0,q=r.clearcoat>0,Y=r.dispersion>0,Z=r.iridescence>0,$=r.sheen>0,J=r.transmission>0,K=X&&!!r.anisotropyMap,Q=q&&!!r.clearcoatMap,tt=q&&!!r.clearcoatNormalMap,et=q&&!!r.clearcoatRoughnessMap,nt=Z&&!!r.iridescenceMap,it=Z&&!!r.iridescenceThicknessMap,st=$&&!!r.sheenColorMap,rt=$&&!!r.sheenRoughnessMap,at=!!r.specularMap,ot=!!r.specularColorMap,lt=!!r.specularIntensityMap,ct=J&&!!r.transmissionMap,ut=J&&!!r.thicknessMap,ht=!!r.gradientMap,pt=!!r.alphaMap,mt=r.alphaTest>0,ft=!!r.alphaHash,gt=!!r.extensions;let vt=0;r.toneMapped&&(null!==L&&!0!==L.isXRRenderTarget||(vt=t.toneMapping));const yt={shaderID:S,shaderType:r.type,shaderName:r.name,vertexShader:A,fragmentShader:N,defines:r.defines,customVertexShaderID:C,customFragmentShaderID:R,isRawShaderMaterial:!0===r.isRawShaderMaterial,glslVersion:r.glslVersion,precision:m,batching:U,batchingColor:U&&null!==y._colorsTexture,instancing:P,instancingColor:P&&null!==y.instanceColor,instancingMorph:P&&null!==y.morphTexture,supportsVertexTextures:p,outputColorSpace:null===L?t.outputColorSpace:!0===L.isXRRenderTarget?L.texture.colorSpace:Je,alphaToCoverage:!!r.alphaToCoverage,map:D,matcap:O,envMap:z,envMapMode:z&&b.mapping,envMapCubeUVHeight:T,aoMap:V,lightMap:F,bumpMap:B,normalMap:k,displacementMap:p&&H,emissiveMap:G,normalMapObjectSpace:k&&1===r.normalMapType,normalMapTangentSpace:k&&0===r.normalMapType,metalnessMap:W,roughnessMap:j,anisotropy:X,anisotropyMap:K,clearcoat:q,clearcoatMap:Q,clearcoatNormalMap:tt,clearcoatRoughnessMap:et,dispersion:Y,iridescence:Z,iridescenceMap:nt,iridescenceThicknessMap:it,sheen:$,sheenColorMap:st,sheenRoughnessMap:rt,specularMap:at,specularColorMap:ot,specularIntensityMap:lt,transmission:J,transmissionMap:ct,thicknessMap:ut,gradientMap:ht,opaque:!1===r.transparent&&1===r.blending&&!1===r.alphaToCoverage,alphaMap:pt,alphaTest:mt,alphaHash:ft,combine:r.combine,mapUv:D&&g(r.map.channel),aoMapUv:V&&g(r.aoMap.channel),lightMapUv:F&&g(r.lightMap.channel),bumpMapUv:B&&g(r.bumpMap.channel),normalMapUv:k&&g(r.normalMap.channel),displacementMapUv:H&&g(r.displacementMap.channel),emissiveMapUv:G&&g(r.emissiveMap.channel),metalnessMapUv:W&&g(r.metalnessMap.channel),roughnessMapUv:j&&g(r.roughnessMap.channel),anisotropyMapUv:K&&g(r.anisotropyMap.channel),clearcoatMapUv:Q&&g(r.clearcoatMap.channel),clearcoatNormalMapUv:tt&&g(r.clearcoatNormalMap.channel),clearcoatRoughnessMapUv:et&&g(r.clearcoatRoughnessMap.channel),iridescenceMapUv:nt&&g(r.iridescenceMap.channel),iridescenceThicknessMapUv:it&&g(r.iridescenceThicknessMap.channel),sheenColorMapUv:st&&g(r.sheenColorMap.channel),sheenRoughnessMapUv:rt&&g(r.sheenRoughnessMap.channel),specularMapUv:at&&g(r.specularMap.channel),specularColorMapUv:ot&&g(r.specularColorMap.channel),specularIntensityMapUv:lt&&g(r.specularIntensityMap.channel),transmissionMapUv:ct&&g(r.transmissionMap.channel),thicknessMapUv:ut&&g(r.thicknessMap.channel),alphaMapUv:pt&&g(r.alphaMap.channel),vertexTangents:!!x.attributes.tangent&&(k||X),vertexColors:r.vertexColors,vertexAlphas:!0===r.vertexColors&&!!x.attributes.color&&4===x.attributes.color.itemSize,pointsUvs:!0===y.isPoints&&!!x.attributes.uv&&(D||pt),fog:!!_,useFog:!0===r.fog,fogExp2:!!_&&_.isFogExp2,flatShading:!0===r.flatShading,sizeAttenuation:!0===r.sizeAttenuation,logarithmicDepthBuffer:h,reverseDepthBuffer:d,skinning:!0===y.isSkinnedMesh,morphTargets:void 0!==x.morphAttributes.position,morphNormals:void 0!==x.morphAttributes.normal,morphColors:void 0!==x.morphAttributes.color,morphTargetsCount:E,morphTextureStride:I,numDirLights:o.directional.length,numPointLights:o.point.length,numSpotLights:o.spot.length,numSpotLightMaps:o.spotLightMap.length,numRectAreaLights:o.rectArea.length,numHemiLights:o.hemi.length,numDirLightShadows:o.directionalShadowMap.length,numPointLightShadows:o.pointShadowMap.length,numSpotLightShadows:o.spotShadowMap.length,numSpotLightShadowsWithMaps:o.numSpotLightShadowsWithMaps,numLightProbes:o.numLightProbes,numClippingPlanes:a.numPlanes,numClipIntersection:a.numIntersection,dithering:r.dithering,shadowMapEnabled:t.shadowMap.enabled&&u.length>0,shadowMapType:t.shadowMap.type,toneMapping:vt,decodeVideoTexture:D&&!0===r.map.isVideoTexture&&mi.getTransfer(r.map.colorSpace)===en,premultipliedAlpha:r.premultipliedAlpha,doubleSided:2===r.side,flipSided:1===r.side,useDepthPacking:r.depthPacking>=0,depthPacking:r.depthPacking||0,index0AttributeName:r.index0AttributeName,extensionClipCullDistance:gt&&!0===r.extensions.clipCullDistance&&i.has("WEBGL_clip_cull_distance"),extensionMultiDraw:(gt&&!0===r.extensions.multiDraw||U)&&i.has("WEBGL_multi_draw"),rendererExtensionParallelShaderCompile:i.has("KHR_parallel_shader_compile"),customProgramCacheKey:r.customProgramCacheKey()};return yt.vertexUv1s=c.has(1),yt.vertexUv2s=c.has(2),yt.vertexUv3s=c.has(3),c.clear(),yt},getProgramCacheKey:function(e){const n=[];if(e.shaderID?n.push(e.shaderID):(n.push(e.customVertexShaderID),n.push(e.customFragmentShaderID)),void 0!==e.defines)for(const t in e.defines)n.push(t),n.push(e.defines[t]);return!1===e.isRawShaderMaterial&&(!function(t,e){t.push(e.precision),t.push(e.outputColorSpace),t.push(e.envMapMode),t.push(e.envMapCubeUVHeight),t.push(e.mapUv),t.push(e.alphaMapUv),t.push(e.lightMapUv),t.push(e.aoMapUv),t.push(e.bumpMapUv),t.push(e.normalMapUv),t.push(e.displacementMapUv),t.push(e.emissiveMapUv),t.push(e.metalnessMapUv),t.push(e.roughnessMapUv),t.push(e.anisotropyMapUv),t.push(e.clearcoatMapUv),t.push(e.clearcoatNormalMapUv),t.push(e.clearcoatRoughnessMapUv),t.push(e.iridescenceMapUv),t.push(e.iridescenceThicknessMapUv),t.push(e.sheenColorMapUv),t.push(e.sheenRoughnessMapUv),t.push(e.specularMapUv),t.push(e.specularColorMapUv),t.push(e.specularIntensityMapUv),t.push(e.transmissionMapUv),t.push(e.thicknessMapUv),t.push(e.combine),t.push(e.fogExp2),t.push(e.sizeAttenuation),t.push(e.morphTargetsCount),t.push(e.morphAttributeCount),t.push(e.numDirLights),t.push(e.numPointLights),t.push(e.numSpotLights),t.push(e.numSpotLightMaps),t.push(e.numHemiLights),t.push(e.numRectAreaLights),t.push(e.numDirLightShadows),t.push(e.numPointLightShadows),t.push(e.numSpotLightShadows),t.push(e.numSpotLightShadowsWithMaps),t.push(e.numLightProbes),t.push(e.shadowMapType),t.push(e.toneMapping),t.push(e.numClippingPlanes),t.push(e.numClipIntersection),t.push(e.depthPacking)}(n,e),function(t,e){o.disableAll(),e.supportsVertexTextures&&o.enable(0);e.instancing&&o.enable(1);e.instancingColor&&o.enable(2);e.instancingMorph&&o.enable(3);e.matcap&&o.enable(4);e.envMap&&o.enable(5);e.normalMapObjectSpace&&o.enable(6);e.normalMapTangentSpace&&o.enable(7);e.clearcoat&&o.enable(8);e.iridescence&&o.enable(9);e.alphaTest&&o.enable(10);e.vertexColors&&o.enable(11);e.vertexAlphas&&o.enable(12);e.vertexUv1s&&o.enable(13);e.vertexUv2s&&o.enable(14);e.vertexUv3s&&o.enable(15);e.vertexTangents&&o.enable(16);e.anisotropy&&o.enable(17);e.alphaHash&&o.enable(18);e.batching&&o.enable(19);e.dispersion&&o.enable(20);e.batchingColor&&o.enable(21);t.push(o.mask),o.disableAll(),e.fog&&o.enable(0);e.useFog&&o.enable(1);e.flatShading&&o.enable(2);e.logarithmicDepthBuffer&&o.enable(3);e.reverseDepthBuffer&&o.enable(4);e.skinning&&o.enable(5);e.morphTargets&&o.enable(6);e.morphNormals&&o.enable(7);e.morphColors&&o.enable(8);e.premultipliedAlpha&&o.enable(9);e.shadowMapEnabled&&o.enable(10);e.doubleSided&&o.enable(11);e.flipSided&&o.enable(12);e.useDepthPacking&&o.enable(13);e.dithering&&o.enable(14);e.transmission&&o.enable(15);e.sheen&&o.enable(16);e.opaque&&o.enable(17);e.pointsUvs&&o.enable(18);e.decodeVideoTexture&&o.enable(19);e.alphaToCoverage&&o.enable(20);t.push(o.mask)}(n,e),n.push(t.outputColorSpace)),n.push(e.customProgramCacheKey),n.join()},getUniforms:function(t){const e=f[t.type];let n;if(e){const t=ga[e];n=qr.clone(t.uniforms)}else n=t.uniforms;return n},acquireProgram:function(e,n){let i;for(let t=0,e=u.length;t0?i.push(u):!0===a.transparent?s.push(u):n.push(u)},unshift:function(t,e,a,o,l,c){const u=r(t,e,a,o,l,c);a.transmission>0?i.unshift(u):!0===a.transparent?s.unshift(u):n.unshift(u)},finish:function(){for(let n=e,i=t.length;n1&&n.sort(t||Cl),i.length>1&&i.sort(e||Rl),s.length>1&&s.sort(e||Rl)}}}function Ll(){let t=new WeakMap;return{get:function(e,n){const i=t.get(e);let s;return void 0===i?(s=new Il,t.set(e,[s])):n>=i.length?(s=new Il,i.push(s)):s=i[n],s},dispose:function(){t=new WeakMap}}}function Pl(){const t={};return{get:function(e){if(void 0!==t[e.id])return t[e.id];let n;switch(e.type){case"DirectionalLight":n={direction:new Li,color:new tr};break;case"SpotLight":n={position:new Li,direction:new Li,color:new tr,distance:0,coneCos:0,penumbraCos:0,decay:0};break;case"PointLight":n={position:new Li,color:new tr,distance:0,decay:0};break;case"HemisphereLight":n={direction:new Li,skyColor:new tr,groundColor:new tr};break;case"RectAreaLight":n={color:new tr,position:new Li,halfWidth:new Li,halfHeight:new Li}}return t[e.id]=n,n}}}let Ul=0;function Dl(t,e){return(e.castShadow?2:0)-(t.castShadow?2:0)+(e.map?1:0)-(t.map?1:0)}function Ol(t){const e=new Pl,n=function(){const t={};return{get:function(e){if(void 0!==t[e.id])return t[e.id];let n;switch(e.type){case"DirectionalLight":case"SpotLight":n={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new ti};break;case"PointLight":n={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new ti,shadowCameraNear:1,shadowCameraFar:1e3}}return t[e.id]=n,n}}}(),i={version:0,hash:{directionalLength:-1,pointLength:-1,spotLength:-1,rectAreaLength:-1,hemiLength:-1,numDirectionalShadows:-1,numPointShadows:-1,numSpotShadows:-1,numSpotMaps:-1,numLightProbes:-1},ambient:[0,0,0],probe:[],directional:[],directionalShadow:[],directionalShadowMap:[],directionalShadowMatrix:[],spot:[],spotLightMap:[],spotShadow:[],spotShadowMap:[],spotLightMatrix:[],rectArea:[],rectAreaLTC1:null,rectAreaLTC2:null,point:[],pointShadow:[],pointShadowMap:[],pointShadowMatrix:[],hemi:[],numSpotLightShadowsWithMaps:0,numLightProbes:0};for(let t=0;t<9;t++)i.probe.push(new Li);const s=new Li,r=new ls,a=new ls;return{setup:function(s){let r=0,a=0,o=0;for(let t=0;t<9;t++)i.probe[t].set(0,0,0);let l=0,c=0,u=0,h=0,d=0,p=0,m=0,f=0,g=0,v=0,y=0;s.sort(Dl);for(let t=0,_=s.length;t<_;t++){const _=s[t],x=_.color,M=_.intensity,b=_.distance,T=_.shadow&&_.shadow.map?_.shadow.map.texture:null;if(_.isAmbientLight)r+=x.r*M,a+=x.g*M,o+=x.b*M;else if(_.isLightProbe){for(let t=0;t<9;t++)i.probe[t].addScaledVector(_.sh.coefficients[t],M);y++}else if(_.isDirectionalLight){const t=e.get(_);if(t.color.copy(_.color).multiplyScalar(_.intensity),_.castShadow){const t=_.shadow,e=n.get(_);e.shadowIntensity=t.intensity,e.shadowBias=t.bias,e.shadowNormalBias=t.normalBias,e.shadowRadius=t.radius,e.shadowMapSize=t.mapSize,i.directionalShadow[l]=e,i.directionalShadowMap[l]=T,i.directionalShadowMatrix[l]=_.shadow.matrix,p++}i.directional[l]=t,l++}else if(_.isSpotLight){const t=e.get(_);t.position.setFromMatrixPosition(_.matrixWorld),t.color.copy(x).multiplyScalar(M),t.distance=b,t.coneCos=Math.cos(_.angle),t.penumbraCos=Math.cos(_.angle*(1-_.penumbra)),t.decay=_.decay,i.spot[u]=t;const s=_.shadow;if(_.map&&(i.spotLightMap[g]=_.map,g++,s.updateMatrices(_),_.castShadow&&v++),i.spotLightMatrix[u]=s.matrix,_.castShadow){const t=n.get(_);t.shadowIntensity=s.intensity,t.shadowBias=s.bias,t.shadowNormalBias=s.normalBias,t.shadowRadius=s.radius,t.shadowMapSize=s.mapSize,i.spotShadow[u]=t,i.spotShadowMap[u]=T,f++}u++}else if(_.isRectAreaLight){const t=e.get(_);t.color.copy(x).multiplyScalar(M),t.halfWidth.set(.5*_.width,0,0),t.halfHeight.set(0,.5*_.height,0),i.rectArea[h]=t,h++}else if(_.isPointLight){const t=e.get(_);if(t.color.copy(_.color).multiplyScalar(_.intensity),t.distance=_.distance,t.decay=_.decay,_.castShadow){const t=_.shadow,e=n.get(_);e.shadowIntensity=t.intensity,e.shadowBias=t.bias,e.shadowNormalBias=t.normalBias,e.shadowRadius=t.radius,e.shadowMapSize=t.mapSize,e.shadowCameraNear=t.camera.near,e.shadowCameraFar=t.camera.far,i.pointShadow[c]=e,i.pointShadowMap[c]=T,i.pointShadowMatrix[c]=_.shadow.matrix,m++}i.point[c]=t,c++}else if(_.isHemisphereLight){const t=e.get(_);t.skyColor.copy(_.color).multiplyScalar(M),t.groundColor.copy(_.groundColor).multiplyScalar(M),i.hemi[d]=t,d++}}h>0&&(!0===t.has("OES_texture_float_linear")?(i.rectAreaLTC1=fa.LTC_FLOAT_1,i.rectAreaLTC2=fa.LTC_FLOAT_2):(i.rectAreaLTC1=fa.LTC_HALF_1,i.rectAreaLTC2=fa.LTC_HALF_2)),i.ambient[0]=r,i.ambient[1]=a,i.ambient[2]=o;const _=i.hash;_.directionalLength===l&&_.pointLength===c&&_.spotLength===u&&_.rectAreaLength===h&&_.hemiLength===d&&_.numDirectionalShadows===p&&_.numPointShadows===m&&_.numSpotShadows===f&&_.numSpotMaps===g&&_.numLightProbes===y||(i.directional.length=l,i.spot.length=u,i.rectArea.length=h,i.point.length=c,i.hemi.length=d,i.directionalShadow.length=p,i.directionalShadowMap.length=p,i.pointShadow.length=m,i.pointShadowMap.length=m,i.spotShadow.length=f,i.spotShadowMap.length=f,i.directionalShadowMatrix.length=p,i.pointShadowMatrix.length=m,i.spotLightMatrix.length=f+g-v,i.spotLightMap.length=g,i.numSpotLightShadowsWithMaps=v,i.numLightProbes=y,_.directionalLength=l,_.pointLength=c,_.spotLength=u,_.rectAreaLength=h,_.hemiLength=d,_.numDirectionalShadows=p,_.numPointShadows=m,_.numSpotShadows=f,_.numSpotMaps=g,_.numLightProbes=y,i.version=Ul++)},setupView:function(t,e){let n=0,o=0,l=0,c=0,u=0;const h=e.matrixWorldInverse;for(let e=0,d=t.length;e=s.length?(r=new zl(t),s.push(r)):r=s[i],r},dispose:function(){e=new WeakMap}}}class Fl extends ir{constructor(t){super(),this.isMeshDepthMaterial=!0,this.type="MeshDepthMaterial",this.depthPacking=3200,this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.setValues(t)}copy(t){return super.copy(t),this.depthPacking=t.depthPacking,this.map=t.map,this.alphaMap=t.alphaMap,this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this}}class Bl extends ir{constructor(t){super(),this.isMeshDistanceMaterial=!0,this.type="MeshDistanceMaterial",this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.setValues(t)}copy(t){return super.copy(t),this.map=t.map,this.alphaMap=t.alphaMap,this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this}}function kl(t,e,n){let i=new ua;const s=new ti,r=new ti,a=new Si,o=new Fl({depthPacking:3201}),l=new Bl,c={},u=n.maxTextureSize,m={[h]:1,[d]:0,[p]:2},f=new Yr({defines:{VSM_SAMPLES:8},uniforms:{shadow_pass:{value:null},resolution:{value:new ti},radius:{value:4}},vertexShader:"void main() {\n\tgl_Position = vec4( position, 1.0 );\n}",fragmentShader:"uniform sampler2D shadow_pass;\nuniform vec2 resolution;\nuniform float radius;\n#include \nvoid main() {\n\tconst float samples = float( VSM_SAMPLES );\n\tfloat mean = 0.0;\n\tfloat squared_mean = 0.0;\n\tfloat uvStride = samples <= 1.0 ? 0.0 : 2.0 / ( samples - 1.0 );\n\tfloat uvStart = samples <= 1.0 ? 0.0 : - 1.0;\n\tfor ( float i = 0.0; i < samples; i ++ ) {\n\t\tfloat uvOffset = uvStart + i * uvStride;\n\t\t#ifdef HORIZONTAL_PASS\n\t\t\tvec2 distribution = unpackRGBATo2Half( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( uvOffset, 0.0 ) * radius ) / resolution ) );\n\t\t\tmean += distribution.x;\n\t\t\tsquared_mean += distribution.y * distribution.y + distribution.x * distribution.x;\n\t\t#else\n\t\t\tfloat depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, uvOffset ) * radius ) / resolution ) );\n\t\t\tmean += depth;\n\t\t\tsquared_mean += depth * depth;\n\t\t#endif\n\t}\n\tmean = mean / samples;\n\tsquared_mean = squared_mean / samples;\n\tfloat std_dev = sqrt( squared_mean - mean * mean );\n\tgl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) );\n}"}),g=f.clone();g.defines.HORIZONTAL_PASS=1;const v=new Cr;v.setAttribute("position",new dr(new Float32Array([-1,-1,.5,3,-1,.5,-1,3,.5]),3));const y=new kr(v,f),_=this;this.enabled=!1,this.autoUpdate=!0,this.needsUpdate=!1,this.type=1;let x=this.type;function M(n,i){const r=e.update(y);f.defines.VSM_SAMPLES!==n.blurSamples&&(f.defines.VSM_SAMPLES=n.blurSamples,g.defines.VSM_SAMPLES=n.blurSamples,f.needsUpdate=!0,g.needsUpdate=!0),null===n.mapPass&&(n.mapPass=new Ei(s.x,s.y)),f.uniforms.shadow_pass.value=n.map.texture,f.uniforms.resolution.value=n.mapSize,f.uniforms.radius.value=n.radius,t.setRenderTarget(n.mapPass),t.clear(),t.renderBufferDirect(i,null,r,f,y,null),g.uniforms.shadow_pass.value=n.mapPass.texture,g.uniforms.resolution.value=n.mapSize,g.uniforms.radius.value=n.radius,t.setRenderTarget(n.map),t.clear(),t.renderBufferDirect(i,null,r,g,y,null)}function b(e,n,i,s){let r=null;const a=!0===i.isPointLight?e.customDistanceMaterial:e.customDepthMaterial;if(void 0!==a)r=a;else if(r=!0===i.isPointLight?l:o,t.localClippingEnabled&&!0===n.clipShadows&&Array.isArray(n.clippingPlanes)&&0!==n.clippingPlanes.length||n.displacementMap&&0!==n.displacementScale||n.alphaMap&&n.alphaTest>0||n.map&&n.alphaTest>0){const t=r.uuid,e=n.uuid;let i=c[t];void 0===i&&(i={},c[t]=i);let s=i[e];void 0===s&&(s=r.clone(),i[e]=s,n.addEventListener("dispose",S)),r=s}if(r.visible=n.visible,r.wireframe=n.wireframe,r.side=3===s?null!==n.shadowSide?n.shadowSide:n.side:null!==n.shadowSide?n.shadowSide:m[n.side],r.alphaMap=n.alphaMap,r.alphaTest=n.alphaTest,r.map=n.map,r.clipShadows=n.clipShadows,r.clippingPlanes=n.clippingPlanes,r.clipIntersection=n.clipIntersection,r.displacementMap=n.displacementMap,r.displacementScale=n.displacementScale,r.displacementBias=n.displacementBias,r.wireframeLinewidth=n.wireframeLinewidth,r.linewidth=n.linewidth,!0===i.isPointLight&&!0===r.isMeshDistanceMaterial){t.properties.get(r).light=i}return r}function T(n,s,r,a,o){if(!1===n.visible)return;if(n.layers.test(s.layers)&&(n.isMesh||n.isLine||n.isPoints)&&(n.castShadow||n.receiveShadow&&3===o)&&(!n.frustumCulled||i.intersectsObject(n))){n.modelViewMatrix.multiplyMatrices(r.matrixWorldInverse,n.matrixWorld);const i=e.update(n),l=n.material;if(Array.isArray(l)){const e=i.groups;for(let c=0,u=e.length;cu||s.y>u)&&(s.x>u&&(r.x=Math.floor(u/f.x),s.x=r.x*f.x,h.mapSize.x=r.x),s.y>u&&(r.y=Math.floor(u/f.y),s.y=r.y*f.y,h.mapSize.y=r.y)),null===h.map||!0===p||!0===m){const t=3!==this.type?{minFilter:gt,magFilter:gt}:{};null!==h.map&&h.map.dispose(),h.map=new Ei(s.x,s.y,t),h.map.texture.name=c.name+".shadowMap",h.camera.updateProjectionMatrix()}t.setRenderTarget(h.map),t.clear();const g=h.getViewportCount();for(let t=0;t=1):-1!==Y.indexOf("OpenGL ES")&&(q=parseFloat(/^OpenGL ES (\d)/.exec(Y)[1]),X=q>=2);let Z=null,$={};const J=t.getParameter(t.SCISSOR_BOX),K=t.getParameter(t.VIEWPORT),Q=(new Si).fromArray(J),tt=(new Si).fromArray(K);function et(e,n,i,s){const r=new Uint8Array(4),a=t.createTexture();t.bindTexture(e,a),t.texParameteri(e,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(e,t.TEXTURE_MAG_FILTER,t.NEAREST);for(let a=0;ae?(t.repeat.x=1,t.repeat.y=n/e,t.offset.x=0,t.offset.y=(1-t.repeat.y)/2):(t.repeat.x=e/n,t.repeat.y=1,t.offset.x=(1-t.repeat.x)/2,t.offset.y=0),t},cover:function(t,e){const n=t.image&&t.image.width?t.image.width/t.image.height:1;return n>e?(t.repeat.x=e/n,t.repeat.y=1,t.offset.x=(1-t.repeat.x)/2,t.offset.y=0):(t.repeat.x=1,t.repeat.y=n/e,t.offset.x=0,t.offset.y=(1-t.repeat.y)/2),t},fill:function(t){return t.repeat.x=1,t.repeat.y=1,t.offset.x=0,t.offset.y=0,t},getByteLength:Wl};function Xl(t,e,n,i,s,r,a){const o=e.has("WEBGL_multisampled_render_to_texture")?e.get("WEBGL_multisampled_render_to_texture"):null,l="undefined"!=typeof navigator&&/OculusBrowser/g.test(navigator.userAgent),c=new ti,u=new WeakMap;let h;const d=new WeakMap;let p=!1;try{p="undefined"!=typeof OffscreenCanvas&&null!==new OffscreenCanvas(1,1).getContext("2d")}catch(t){}function m(t,e){return p?new OffscreenCanvas(t,e):ai("canvas")}function f(t,e,n){let i=1;const s=B(t);if((s.width>n||s.height>n)&&(i=n/Math.max(s.width,s.height)),i<1){if("undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap||"undefined"!=typeof VideoFrame&&t instanceof VideoFrame){const n=Math.floor(i*s.width),r=Math.floor(i*s.height);void 0===h&&(h=m(n,r));const a=e?m(n,r):h;a.width=n,a.height=r;return a.getContext("2d").drawImage(t,0,0,n,r),console.warn("THREE.WebGLRenderer: Texture has been resized from ("+s.width+"x"+s.height+") to ("+n+"x"+r+")."),a}return"data"in t&&console.warn("THREE.WebGLRenderer: Image in DataTexture is too big ("+s.width+"x"+s.height+")."),t}return t}function g(t){return t.generateMipmaps&&t.minFilter!==gt&&t.minFilter!==Mt}function v(e){t.generateMipmap(e)}function y(n,i,s,r,a=!1){if(null!==n){if(void 0!==t[n])return t[n];console.warn("THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format '"+n+"'")}let o=i;if(i===t.RED&&(s===t.FLOAT&&(o=t.R32F),s===t.HALF_FLOAT&&(o=t.R16F),s===t.UNSIGNED_BYTE&&(o=t.R8)),i===t.RED_INTEGER&&(s===t.UNSIGNED_BYTE&&(o=t.R8UI),s===t.UNSIGNED_SHORT&&(o=t.R16UI),s===t.UNSIGNED_INT&&(o=t.R32UI),s===t.BYTE&&(o=t.R8I),s===t.SHORT&&(o=t.R16I),s===t.INT&&(o=t.R32I)),i===t.RG&&(s===t.FLOAT&&(o=t.RG32F),s===t.HALF_FLOAT&&(o=t.RG16F),s===t.UNSIGNED_BYTE&&(o=t.RG8)),i===t.RG_INTEGER&&(s===t.UNSIGNED_BYTE&&(o=t.RG8UI),s===t.UNSIGNED_SHORT&&(o=t.RG16UI),s===t.UNSIGNED_INT&&(o=t.RG32UI),s===t.BYTE&&(o=t.RG8I),s===t.SHORT&&(o=t.RG16I),s===t.INT&&(o=t.RG32I)),i===t.RGB_INTEGER&&(s===t.UNSIGNED_BYTE&&(o=t.RGB8UI),s===t.UNSIGNED_SHORT&&(o=t.RGB16UI),s===t.UNSIGNED_INT&&(o=t.RGB32UI),s===t.BYTE&&(o=t.RGB8I),s===t.SHORT&&(o=t.RGB16I),s===t.INT&&(o=t.RGB32I)),i===t.RGBA_INTEGER&&(s===t.UNSIGNED_BYTE&&(o=t.RGBA8UI),s===t.UNSIGNED_SHORT&&(o=t.RGBA16UI),s===t.UNSIGNED_INT&&(o=t.RGBA32UI),s===t.BYTE&&(o=t.RGBA8I),s===t.SHORT&&(o=t.RGBA16I),s===t.INT&&(o=t.RGBA32I)),i===t.RGB&&s===t.UNSIGNED_INT_5_9_9_9_REV&&(o=t.RGB9_E5),i===t.RGBA){const e=a?tn:mi.getTransfer(r);s===t.FLOAT&&(o=t.RGBA32F),s===t.HALF_FLOAT&&(o=t.RGBA16F),s===t.UNSIGNED_BYTE&&(o=e===en?t.SRGB8_ALPHA8:t.RGBA8),s===t.UNSIGNED_SHORT_4_4_4_4&&(o=t.RGBA4),s===t.UNSIGNED_SHORT_5_5_5_1&&(o=t.RGB5_A1)}return o!==t.R16F&&o!==t.R32F&&o!==t.RG16F&&o!==t.RG32F&&o!==t.RGBA16F&&o!==t.RGBA32F||e.get("EXT_color_buffer_float"),o}function _(e,n){let i;return e?null===n||n===It||n===Ot?i=t.DEPTH24_STENCIL8:n===Lt?i=t.DEPTH32F_STENCIL8:n===Ct&&(i=t.DEPTH24_STENCIL8,console.warn("DepthTexture: 16 bit depth attachment is not supported with stencil. Using 24-bit attachment.")):null===n||n===It||n===Ot?i=t.DEPTH_COMPONENT24:n===Lt?i=t.DEPTH_COMPONENT32F:n===Ct&&(i=t.DEPTH_COMPONENT16),i}function x(t,e){return!0===g(t)||t.isFramebufferTexture&&t.minFilter!==gt&&t.minFilter!==Mt?Math.log2(Math.max(e.width,e.height))+1:void 0!==t.mipmaps&&t.mipmaps.length>0?t.mipmaps.length:t.isCompressedTexture&&Array.isArray(t.image)?e.mipmaps.length:1}function M(t){const e=t.target;e.removeEventListener("dispose",M),function(t){const e=i.get(t);if(void 0===e.__webglInit)return;const n=t.source,s=d.get(n);if(s){const i=s[e.__cacheKey];i.usedTimes--,0===i.usedTimes&&T(t),0===Object.keys(s).length&&d.delete(n)}i.remove(t)}(e),e.isVideoTexture&&u.delete(e)}function b(e){const n=e.target;n.removeEventListener("dispose",b),function(e){const n=i.get(e);e.depthTexture&&e.depthTexture.dispose();if(e.isWebGLCubeRenderTarget)for(let e=0;e<6;e++){if(Array.isArray(n.__webglFramebuffer[e]))for(let i=0;i0&&r.__version!==e.version){const t=e.image;if(null===t)console.warn("THREE.WebGLRenderer: Texture marked for update but no image data found.");else{if(!1!==t.complete)return void I(r,e,s);console.warn("THREE.WebGLRenderer: Texture marked for update but image is incomplete")}}n.bindTexture(t.TEXTURE_2D,r.__webglTexture,t.TEXTURE0+s)}const E={[pt]:t.REPEAT,[mt]:t.CLAMP_TO_EDGE,[ft]:t.MIRRORED_REPEAT},A={[gt]:t.NEAREST,[vt]:t.NEAREST_MIPMAP_NEAREST,[_t]:t.NEAREST_MIPMAP_LINEAR,[Mt]:t.LINEAR,[bt]:t.LINEAR_MIPMAP_NEAREST,[St]:t.LINEAR_MIPMAP_LINEAR},N={[Mn]:t.NEVER,[Nn]:t.ALWAYS,[bn]:t.LESS,[Sn]:t.LEQUAL,[Tn]:t.EQUAL,[An]:t.GEQUAL,[wn]:t.GREATER,[En]:t.NOTEQUAL};function C(n,r){if(r.type!==Lt||!1!==e.has("OES_texture_float_linear")||r.magFilter!==Mt&&r.magFilter!==bt&&r.magFilter!==_t&&r.magFilter!==St&&r.minFilter!==Mt&&r.minFilter!==bt&&r.minFilter!==_t&&r.minFilter!==St||console.warn("THREE.WebGLRenderer: Unable to use linear filtering with floating point textures. OES_texture_float_linear not supported on this device."),t.texParameteri(n,t.TEXTURE_WRAP_S,E[r.wrapS]),t.texParameteri(n,t.TEXTURE_WRAP_T,E[r.wrapT]),n!==t.TEXTURE_3D&&n!==t.TEXTURE_2D_ARRAY||t.texParameteri(n,t.TEXTURE_WRAP_R,E[r.wrapR]),t.texParameteri(n,t.TEXTURE_MAG_FILTER,A[r.magFilter]),t.texParameteri(n,t.TEXTURE_MIN_FILTER,A[r.minFilter]),r.compareFunction&&(t.texParameteri(n,t.TEXTURE_COMPARE_MODE,t.COMPARE_REF_TO_TEXTURE),t.texParameteri(n,t.TEXTURE_COMPARE_FUNC,N[r.compareFunction])),!0===e.has("EXT_texture_filter_anisotropic")){if(r.magFilter===gt)return;if(r.minFilter!==_t&&r.minFilter!==St)return;if(r.type===Lt&&!1===e.has("OES_texture_float_linear"))return;if(r.anisotropy>1||i.get(r).__currentAnisotropy){const a=e.get("EXT_texture_filter_anisotropic");t.texParameterf(n,a.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(r.anisotropy,s.getMaxAnisotropy())),i.get(r).__currentAnisotropy=r.anisotropy}}}function R(e,n){let i=!1;void 0===e.__webglInit&&(e.__webglInit=!0,n.addEventListener("dispose",M));const s=n.source;let r=d.get(s);void 0===r&&(r={},d.set(s,r));const o=function(t){const e=[];return e.push(t.wrapS),e.push(t.wrapT),e.push(t.wrapR||0),e.push(t.magFilter),e.push(t.minFilter),e.push(t.anisotropy),e.push(t.internalFormat),e.push(t.format),e.push(t.type),e.push(t.generateMipmaps),e.push(t.premultiplyAlpha),e.push(t.flipY),e.push(t.unpackAlignment),e.push(t.colorSpace),e.join()}(n);if(o!==e.__cacheKey){void 0===r[o]&&(r[o]={texture:t.createTexture(),usedTimes:0},a.memory.textures++,i=!0),r[o].usedTimes++;const s=r[e.__cacheKey];void 0!==s&&(r[e.__cacheKey].usedTimes--,0===s.usedTimes&&T(n)),e.__cacheKey=o,e.__webglTexture=r[o].texture}return i}function I(e,a,o){let l=t.TEXTURE_2D;(a.isDataArrayTexture||a.isCompressedArrayTexture)&&(l=t.TEXTURE_2D_ARRAY),a.isData3DTexture&&(l=t.TEXTURE_3D);const c=R(e,a),u=a.source;n.bindTexture(l,e.__webglTexture,t.TEXTURE0+o);const h=i.get(u);if(u.version!==h.__version||!0===c){n.activeTexture(t.TEXTURE0+o);const e=mi.getPrimaries(mi.workingColorSpace),i=a.colorSpace===Ze?null:mi.getPrimaries(a.colorSpace),d=a.colorSpace===Ze||e===i?t.NONE:t.BROWSER_DEFAULT_WEBGL;t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,a.flipY),t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,a.premultiplyAlpha),t.pixelStorei(t.UNPACK_ALIGNMENT,a.unpackAlignment),t.pixelStorei(t.UNPACK_COLORSPACE_CONVERSION_WEBGL,d);let p=f(a.image,!1,s.maxTextureSize);p=F(a,p);const m=r.convert(a.format,a.colorSpace),M=r.convert(a.type);let b,T=y(a.internalFormat,m,M,a.colorSpace,a.isVideoTexture);C(l,a);const S=a.mipmaps,w=!0!==a.isVideoTexture,E=void 0===h.__version||!0===c,A=u.dataReady,N=x(a,p);if(a.isDepthTexture)T=_(a.format===Wt,a.type),E&&(w?n.texStorage2D(t.TEXTURE_2D,1,T,p.width,p.height):n.texImage2D(t.TEXTURE_2D,0,T,p.width,p.height,0,m,M,null));else if(a.isDataTexture)if(S.length>0){w&&E&&n.texStorage2D(t.TEXTURE_2D,N,T,S[0].width,S[0].height);for(let e=0,i=S.length;e0){const i=Wl(b.width,b.height,a.format,a.type);for(const s of a.layerUpdates){const r=b.data.subarray(s*i/b.data.BYTES_PER_ELEMENT,(s+1)*i/b.data.BYTES_PER_ELEMENT);n.compressedTexSubImage3D(t.TEXTURE_2D_ARRAY,e,0,0,s,b.width,b.height,1,m,r,0,0)}a.clearLayerUpdates()}else n.compressedTexSubImage3D(t.TEXTURE_2D_ARRAY,e,0,0,0,b.width,b.height,p.depth,m,b.data,0,0)}else n.compressedTexImage3D(t.TEXTURE_2D_ARRAY,e,T,b.width,b.height,p.depth,0,b.data,0,0);else console.warn("THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()");else w?A&&n.texSubImage3D(t.TEXTURE_2D_ARRAY,e,0,0,0,b.width,b.height,p.depth,m,M,b.data):n.texImage3D(t.TEXTURE_2D_ARRAY,e,T,b.width,b.height,p.depth,0,m,M,b.data)}else{w&&E&&n.texStorage2D(t.TEXTURE_2D,N,T,S[0].width,S[0].height);for(let e=0,i=S.length;e0){const e=Wl(p.width,p.height,a.format,a.type);for(const i of a.layerUpdates){const s=p.data.subarray(i*e/p.data.BYTES_PER_ELEMENT,(i+1)*e/p.data.BYTES_PER_ELEMENT);n.texSubImage3D(t.TEXTURE_2D_ARRAY,0,0,0,i,p.width,p.height,1,m,M,s)}a.clearLayerUpdates()}else n.texSubImage3D(t.TEXTURE_2D_ARRAY,0,0,0,0,p.width,p.height,p.depth,m,M,p.data)}else n.texImage3D(t.TEXTURE_2D_ARRAY,0,T,p.width,p.height,p.depth,0,m,M,p.data);else if(a.isData3DTexture)w?(E&&n.texStorage3D(t.TEXTURE_3D,N,T,p.width,p.height,p.depth),A&&n.texSubImage3D(t.TEXTURE_3D,0,0,0,0,p.width,p.height,p.depth,m,M,p.data)):n.texImage3D(t.TEXTURE_3D,0,T,p.width,p.height,p.depth,0,m,M,p.data);else if(a.isFramebufferTexture){if(E)if(w)n.texStorage2D(t.TEXTURE_2D,N,T,p.width,p.height);else{let e=p.width,i=p.height;for(let s=0;s>=1,i>>=1}}else if(S.length>0){if(w&&E){const e=B(S[0]);n.texStorage2D(t.TEXTURE_2D,N,T,e.width,e.height)}for(let e=0,i=S.length;e>u),i=Math.max(1,s.height>>u);c===t.TEXTURE_3D||c===t.TEXTURE_2D_ARRAY?n.texImage3D(c,u,p,e,i,s.depth,0,h,d,null):n.texImage2D(c,u,p,e,i,0,h,d,null)}n.bindFramebuffer(t.FRAMEBUFFER,e),V(s)?o.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,l,c,i.get(a).__webglTexture,0,z(s)):(c===t.TEXTURE_2D||c>=t.TEXTURE_CUBE_MAP_POSITIVE_X&&c<=t.TEXTURE_CUBE_MAP_NEGATIVE_Z)&&t.framebufferTexture2D(t.FRAMEBUFFER,l,c,i.get(a).__webglTexture,u),n.bindFramebuffer(t.FRAMEBUFFER,null)}function P(e,n,i){if(t.bindRenderbuffer(t.RENDERBUFFER,e),n.depthBuffer){const s=n.depthTexture,r=s&&s.isDepthTexture?s.type:null,a=_(n.stencilBuffer,r),l=n.stencilBuffer?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT,c=z(n);V(n)?o.renderbufferStorageMultisampleEXT(t.RENDERBUFFER,c,a,n.width,n.height):i?t.renderbufferStorageMultisample(t.RENDERBUFFER,c,a,n.width,n.height):t.renderbufferStorage(t.RENDERBUFFER,a,n.width,n.height),t.framebufferRenderbuffer(t.FRAMEBUFFER,l,t.RENDERBUFFER,e)}else{const e=n.textures;for(let s=0;s{delete s.__boundDepthTexture,delete s.__depthDisposeCallback,t.removeEventListener("dispose",e)};t.addEventListener("dispose",e),s.__depthDisposeCallback=e}s.__boundDepthTexture=t}if(e.depthTexture&&!s.__autoAllocateDepthBuffer){if(r)throw new Error("target.depthTexture not supported in Cube render targets");!function(e,s){if(s&&s.isWebGLCubeRenderTarget)throw new Error("Depth Texture with cube render targets is not supported");if(n.bindFramebuffer(t.FRAMEBUFFER,e),!s.depthTexture||!s.depthTexture.isDepthTexture)throw new Error("renderTarget.depthTexture must be an instance of THREE.DepthTexture");i.get(s.depthTexture).__webglTexture&&s.depthTexture.image.width===s.width&&s.depthTexture.image.height===s.height||(s.depthTexture.image.width=s.width,s.depthTexture.image.height=s.height,s.depthTexture.needsUpdate=!0),w(s.depthTexture,0);const r=i.get(s.depthTexture).__webglTexture,a=z(s);if(s.depthTexture.format===Gt)V(s)?o.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,t.DEPTH_ATTACHMENT,t.TEXTURE_2D,r,0,a):t.framebufferTexture2D(t.FRAMEBUFFER,t.DEPTH_ATTACHMENT,t.TEXTURE_2D,r,0);else{if(s.depthTexture.format!==Wt)throw new Error("Unknown depthTexture format");V(s)?o.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,t.DEPTH_STENCIL_ATTACHMENT,t.TEXTURE_2D,r,0,a):t.framebufferTexture2D(t.FRAMEBUFFER,t.DEPTH_STENCIL_ATTACHMENT,t.TEXTURE_2D,r,0)}}(s.__webglFramebuffer,e)}else if(r){s.__webglDepthbuffer=[];for(let i=0;i<6;i++)if(n.bindFramebuffer(t.FRAMEBUFFER,s.__webglFramebuffer[i]),void 0===s.__webglDepthbuffer[i])s.__webglDepthbuffer[i]=t.createRenderbuffer(),P(s.__webglDepthbuffer[i],e,!1);else{const n=e.stencilBuffer?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT,r=s.__webglDepthbuffer[i];t.bindRenderbuffer(t.RENDERBUFFER,r),t.framebufferRenderbuffer(t.FRAMEBUFFER,n,t.RENDERBUFFER,r)}}else if(n.bindFramebuffer(t.FRAMEBUFFER,s.__webglFramebuffer),void 0===s.__webglDepthbuffer)s.__webglDepthbuffer=t.createRenderbuffer(),P(s.__webglDepthbuffer,e,!1);else{const n=e.stencilBuffer?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT,i=s.__webglDepthbuffer;t.bindRenderbuffer(t.RENDERBUFFER,i),t.framebufferRenderbuffer(t.FRAMEBUFFER,n,t.RENDERBUFFER,i)}n.bindFramebuffer(t.FRAMEBUFFER,null)}const D=[],O=[];function z(t){return Math.min(s.maxSamples,t.samples)}function V(t){const n=i.get(t);return t.samples>0&&!0===e.has("WEBGL_multisampled_render_to_texture")&&!1!==n.__useRenderToTexture}function F(t,e){const n=t.colorSpace,i=t.format,s=t.type;return!0===t.isCompressedTexture||!0===t.isVideoTexture||n!==Je&&n!==Ze&&(mi.getTransfer(n)===en?i===Bt&&s===Et||console.warn("THREE.WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType."):console.error("THREE.WebGLTextures: Unsupported texture color space:",n)),e}function B(t){return"undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement?(c.width=t.naturalWidth||t.width,c.height=t.naturalHeight||t.height):"undefined"!=typeof VideoFrame&&t instanceof VideoFrame?(c.width=t.displayWidth,c.height=t.displayHeight):(c.width=t.width,c.height=t.height),c}this.allocateTextureUnit=function(){const t=S;return t>=s.maxTextures&&console.warn("THREE.WebGLTextures: Trying to use "+t+" texture units while this GPU supports only "+s.maxTextures),S+=1,t},this.resetTextureUnits=function(){S=0},this.setTexture2D=w,this.setTexture2DArray=function(e,s){const r=i.get(e);e.version>0&&r.__version!==e.version?I(r,e,s):n.bindTexture(t.TEXTURE_2D_ARRAY,r.__webglTexture,t.TEXTURE0+s)},this.setTexture3D=function(e,s){const r=i.get(e);e.version>0&&r.__version!==e.version?I(r,e,s):n.bindTexture(t.TEXTURE_3D,r.__webglTexture,t.TEXTURE0+s)},this.setTextureCube=function(e,a){const o=i.get(e);e.version>0&&o.__version!==e.version?function(e,a,o){if(6!==a.image.length)return;const l=R(e,a),c=a.source;n.bindTexture(t.TEXTURE_CUBE_MAP,e.__webglTexture,t.TEXTURE0+o);const u=i.get(c);if(c.version!==u.__version||!0===l){n.activeTexture(t.TEXTURE0+o);const e=mi.getPrimaries(mi.workingColorSpace),i=a.colorSpace===Ze?null:mi.getPrimaries(a.colorSpace),h=a.colorSpace===Ze||e===i?t.NONE:t.BROWSER_DEFAULT_WEBGL;t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,a.flipY),t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,a.premultiplyAlpha),t.pixelStorei(t.UNPACK_ALIGNMENT,a.unpackAlignment),t.pixelStorei(t.UNPACK_COLORSPACE_CONVERSION_WEBGL,h);const d=a.isCompressedTexture||a.image[0].isCompressedTexture,p=a.image[0]&&a.image[0].isDataTexture,m=[];for(let t=0;t<6;t++)m[t]=d||p?p?a.image[t].image:a.image[t]:f(a.image[t],!0,s.maxCubemapSize),m[t]=F(a,m[t]);const _=m[0],M=r.convert(a.format,a.colorSpace),b=r.convert(a.type),T=y(a.internalFormat,M,b,a.colorSpace),S=!0!==a.isVideoTexture,w=void 0===u.__version||!0===l,E=c.dataReady;let A,N=x(a,_);if(C(t.TEXTURE_CUBE_MAP,a),d){S&&w&&n.texStorage2D(t.TEXTURE_CUBE_MAP,N,T,_.width,_.height);for(let e=0;e<6;e++){A=m[e].mipmaps;for(let i=0;i0&&N++;const e=B(m[0]);n.texStorage2D(t.TEXTURE_CUBE_MAP,N,T,e.width,e.height)}for(let e=0;e<6;e++)if(p){S?E&&n.texSubImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,0,0,m[e].width,m[e].height,M,b,m[e].data):n.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,T,m[e].width,m[e].height,0,M,b,m[e].data);for(let i=0;i1;if(h||(void 0===l.__webglTexture&&(l.__webglTexture=t.createTexture()),l.__version=s.version,a.memory.textures++),u){o.__webglFramebuffer=[];for(let e=0;e<6;e++)if(s.mipmaps&&s.mipmaps.length>0){o.__webglFramebuffer[e]=[];for(let n=0;n0){o.__webglFramebuffer=[];for(let e=0;e0&&!1===V(e)){o.__webglMultisampledFramebuffer=t.createFramebuffer(),o.__webglColorRenderbuffer=[],n.bindFramebuffer(t.FRAMEBUFFER,o.__webglMultisampledFramebuffer);for(let n=0;n0)for(let i=0;i0)for(let n=0;n0)if(!1===V(e)){const s=e.textures,r=e.width,a=e.height;let o=t.COLOR_BUFFER_BIT;const c=e.stencilBuffer?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT,u=i.get(e),h=s.length>1;if(h)for(let e=0;eo+c?(l.inputState.pinching=!1,this.dispatchEvent({type:"pinchend",handedness:t.handedness,target:this})):!l.inputState.pinching&&a<=o-c&&(l.inputState.pinching=!0,this.dispatchEvent({type:"pinchstart",handedness:t.handedness,target:this}))}else null!==o&&t.gripSpace&&(s=e.getPose(t.gripSpace,n),null!==s&&(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));null!==a&&(i=e.getPose(t.targetRaySpace,n),null===i&&null!==s&&(i=s),null!==i&&(a.matrix.fromArray(i.transform.matrix),a.matrix.decompose(a.position,a.rotation,a.scale),a.matrixWorldNeedsUpdate=!0,i.linearVelocity?(a.hasLinearVelocity=!0,a.linearVelocity.copy(i.linearVelocity)):a.hasLinearVelocity=!1,i.angularVelocity?(a.hasAngularVelocity=!0,a.angularVelocity.copy(i.angularVelocity)):a.hasAngularVelocity=!1,this.dispatchEvent($l)))}return null!==a&&(a.visible=null!==i),null!==o&&(o.visible=null!==s),null!==l&&(l.visible=null!==r),this}_getHandJoint(t,e){if(void 0===t.joints[e.jointName]){const n=new Zl;n.matrixAutoUpdate=!1,n.visible=!1,t.joints[e.jointName]=n,t.add(n)}return t.joints[e.jointName]}}class Kl{constructor(){this.texture=null,this.mesh=null,this.depthNear=0,this.depthFar=0}init(t,e,n){if(null===this.texture){const i=new Ti;t.properties.get(i).__webglTexture=e.texture,e.depthNear==n.depthNear&&e.depthFar==n.depthFar||(this.depthNear=e.depthNear,this.depthFar=e.depthFar),this.texture=i}}getMesh(t){if(null!==this.texture&&null===this.mesh){const e=t.cameras[0].viewport,n=new Yr({vertexShader:"\nvoid main() {\n\n\tgl_Position = vec4( position, 1.0 );\n\n}",fragmentShader:"\nuniform sampler2DArray depthColor;\nuniform float depthWidth;\nuniform float depthHeight;\n\nvoid main() {\n\n\tvec2 coord = vec2( gl_FragCoord.x / depthWidth, gl_FragCoord.y / depthHeight );\n\n\tif ( coord.x >= 1.0 ) {\n\n\t\tgl_FragDepth = texture( depthColor, vec3( coord.x - 1.0, coord.y, 1 ) ).r;\n\n\t} else {\n\n\t\tgl_FragDepth = texture( depthColor, vec3( coord.x, coord.y, 0 ) ).r;\n\n\t}\n\n}",uniforms:{depthColor:{value:this.texture},depthWidth:{value:e.z},depthHeight:{value:e.w}}});this.mesh=new kr(new pa(20,20),n)}return this.mesh}reset(){this.texture=null,this.mesh=null}getDepthTexture(){return this.texture}}class Ql extends Hn{constructor(t,e){super();const n=this;let i=null,s=1,r=null,a="local-floor",o=1,l=null,c=null,u=null,h=null,d=null,p=null;const m=new Kl,f=e.getContextAttributes();let g=null,v=null;const y=[],_=[],x=new ti;let M=null;const b=new Qr;b.layers.enable(1),b.viewport=new Si;const T=new Qr;T.layers.enable(2),T.viewport=new Si;const S=[b,T],w=new Yl;w.layers.enable(1),w.layers.enable(2);let E=null,A=null;function N(t){const e=_.indexOf(t.inputSource);if(-1===e)return;const n=y[e];void 0!==n&&(n.update(t.inputSource,t.frame,l||r),n.dispatchEvent({type:t.type,data:t.inputSource}))}function C(){i.removeEventListener("select",N),i.removeEventListener("selectstart",N),i.removeEventListener("selectend",N),i.removeEventListener("squeeze",N),i.removeEventListener("squeezestart",N),i.removeEventListener("squeezeend",N),i.removeEventListener("end",C),i.removeEventListener("inputsourceschange",R);for(let t=0;t=0&&(_[i]=null,y[i]&&y[i].disconnect(n))}for(let e=0;e=_.length){_.push(n),i=t;break}if(null===_[t]){_[t]=n,i=t;break}}if(-1===i)break}const s=y[i];s&&s.connect(n)}}this.cameraAutoUpdate=!0,this.enabled=!1,this.isPresenting=!1,this.controllerAutoUpdate=!0,this.getController=function(t){let e=y[t];return void 0===e&&(e=new Jl,y[t]=e),e.getTargetRaySpace()},this.getControllerGrip=function(t){let e=y[t];return void 0===e&&(e=new Jl,y[t]=e),e.getGripSpace()},this.getHand=function(t){let e=y[t];return void 0===e&&(e=new Jl,y[t]=e),e.getHandSpace()},this.setFramebufferScaleFactor=function(t){s=t,!0===n.isPresenting&&console.warn("THREE.WebXRManager: Cannot change framebuffer scale while presenting.")},this.setReferenceSpaceType=function(t){a=t,!0===n.isPresenting&&console.warn("THREE.WebXRManager: Cannot change reference space type while presenting.")},this.getReferenceSpace=function(){return l||r},this.setReferenceSpace=function(t){l=t},this.getBaseLayer=function(){return null!==h?h:d},this.getBinding=function(){return u},this.getFrame=function(){return p},this.getSession=function(){return i},this.setSession=async function(c){if(i=c,null!==i){g=t.getRenderTarget(),i.addEventListener("select",N),i.addEventListener("selectstart",N),i.addEventListener("selectend",N),i.addEventListener("squeeze",N),i.addEventListener("squeezestart",N),i.addEventListener("squeezeend",N),i.addEventListener("end",C),i.addEventListener("inputsourceschange",R),!0!==f.xrCompatible&&await e.makeXRCompatible(),M=t.getPixelRatio(),t.getSize(x);if("undefined"!=typeof XRWebGLBinding&&"createProjectionLayer"in XRWebGLBinding.prototype){let n=null,r=null,a=null;f.depth&&(a=f.stencil?e.DEPTH24_STENCIL8:e.DEPTH_COMPONENT24,n=f.stencil?Wt:Gt,r=f.stencil?Ot:It);const o={colorFormat:e.RGBA8,depthFormat:a,scaleFactor:s};u=new XRWebGLBinding(i,e),h=u.createProjectionLayer(o),i.updateRenderState({layers:[h]}),t.setPixelRatio(1),t.setSize(h.textureWidth,h.textureHeight,!1),v=new Ei(h.textureWidth,h.textureHeight,{format:Bt,type:Et,depthTexture:new Ka(h.textureWidth,h.textureHeight,r,void 0,void 0,void 0,void 0,void 0,void 0,n),stencilBuffer:f.stencil,colorSpace:t.outputColorSpace,samples:f.antialias?4:0,resolveDepthBuffer:!1===h.ignoreDepthValues})}else{const n={antialias:f.antialias,alpha:!0,depth:f.depth,stencil:f.stencil,framebufferScaleFactor:s};d=new XRWebGLLayer(i,e,n),i.updateRenderState({baseLayer:d}),t.setPixelRatio(1),t.setSize(d.framebufferWidth,d.framebufferHeight,!1),v=new Ei(d.framebufferWidth,d.framebufferHeight,{format:Bt,type:Et,colorSpace:t.outputColorSpace,stencilBuffer:f.stencil})}v.isXRRenderTarget=!0,this.setFoveation(o),l=null,r=await i.requestReferenceSpace(a),D.setContext(i),D.start(),n.isPresenting=!0,n.dispatchEvent({type:"sessionstart"})}},this.getEnvironmentBlendMode=function(){if(null!==i)return i.environmentBlendMode},this.getDepthTexture=function(){return m.getDepthTexture()};const I=new Li,L=new Li;function P(t,e){null===e?t.matrixWorld.copy(t.matrix):t.matrixWorld.multiplyMatrices(e.matrixWorld,t.matrix),t.matrixWorldInverse.copy(t.matrixWorld).invert()}this.updateCamera=function(t){if(null===i)return;let e=t.near,n=t.far;null!==m.texture&&(m.depthNear>0&&(e=m.depthNear),m.depthFar>0&&(n=m.depthFar)),w.near=T.near=b.near=e,w.far=T.far=b.far=n,E===w.near&&A===w.far||(i.updateRenderState({depthNear:w.near,depthFar:w.far}),E=w.near,A=w.far);const s=t.parent,r=w.cameras;P(w,s);for(let t=0;t0&&(t.alphaTest.value=i.alphaTest);const s=e.get(i),r=s.envMap,a=s.envMapRotation;r&&(t.envMap.value=r,tc.copy(a),tc.x*=-1,tc.y*=-1,tc.z*=-1,r.isCubeTexture&&!1===r.isRenderTargetTexture&&(tc.y*=-1,tc.z*=-1),t.envMapRotation.value.setFromMatrix4(ec.makeRotationFromEuler(tc)),t.flipEnvMap.value=r.isCubeTexture&&!1===r.isRenderTargetTexture?-1:1,t.reflectivity.value=i.reflectivity,t.ior.value=i.ior,t.refractionRatio.value=i.refractionRatio),i.lightMap&&(t.lightMap.value=i.lightMap,t.lightMapIntensity.value=i.lightMapIntensity,n(i.lightMap,t.lightMapTransform)),i.aoMap&&(t.aoMap.value=i.aoMap,t.aoMapIntensity.value=i.aoMapIntensity,n(i.aoMap,t.aoMapTransform))}return{refreshFogUniforms:function(e,n){n.color.getRGB(e.fogColor.value,Xr(t)),n.isFog?(e.fogNear.value=n.near,e.fogFar.value=n.far):n.isFogExp2&&(e.fogDensity.value=n.density)},refreshMaterialUniforms:function(t,s,r,a,o){s.isMeshBasicMaterial||s.isMeshLambertMaterial?i(t,s):s.isMeshToonMaterial?(i(t,s),function(t,e){e.gradientMap&&(t.gradientMap.value=e.gradientMap)}(t,s)):s.isMeshPhongMaterial?(i(t,s),function(t,e){t.specular.value.copy(e.specular),t.shininess.value=Math.max(e.shininess,1e-4)}(t,s)):s.isMeshStandardMaterial?(i(t,s),function(t,e){t.metalness.value=e.metalness,e.metalnessMap&&(t.metalnessMap.value=e.metalnessMap,n(e.metalnessMap,t.metalnessMapTransform));t.roughness.value=e.roughness,e.roughnessMap&&(t.roughnessMap.value=e.roughnessMap,n(e.roughnessMap,t.roughnessMapTransform));e.envMap&&(t.envMapIntensity.value=e.envMapIntensity)}(t,s),s.isMeshPhysicalMaterial&&function(t,e,i){t.ior.value=e.ior,e.sheen>0&&(t.sheenColor.value.copy(e.sheenColor).multiplyScalar(e.sheen),t.sheenRoughness.value=e.sheenRoughness,e.sheenColorMap&&(t.sheenColorMap.value=e.sheenColorMap,n(e.sheenColorMap,t.sheenColorMapTransform)),e.sheenRoughnessMap&&(t.sheenRoughnessMap.value=e.sheenRoughnessMap,n(e.sheenRoughnessMap,t.sheenRoughnessMapTransform)));e.clearcoat>0&&(t.clearcoat.value=e.clearcoat,t.clearcoatRoughness.value=e.clearcoatRoughness,e.clearcoatMap&&(t.clearcoatMap.value=e.clearcoatMap,n(e.clearcoatMap,t.clearcoatMapTransform)),e.clearcoatRoughnessMap&&(t.clearcoatRoughnessMap.value=e.clearcoatRoughnessMap,n(e.clearcoatRoughnessMap,t.clearcoatRoughnessMapTransform)),e.clearcoatNormalMap&&(t.clearcoatNormalMap.value=e.clearcoatNormalMap,n(e.clearcoatNormalMap,t.clearcoatNormalMapTransform),t.clearcoatNormalScale.value.copy(e.clearcoatNormalScale),1===e.side&&t.clearcoatNormalScale.value.negate()));e.dispersion>0&&(t.dispersion.value=e.dispersion);e.iridescence>0&&(t.iridescence.value=e.iridescence,t.iridescenceIOR.value=e.iridescenceIOR,t.iridescenceThicknessMinimum.value=e.iridescenceThicknessRange[0],t.iridescenceThicknessMaximum.value=e.iridescenceThicknessRange[1],e.iridescenceMap&&(t.iridescenceMap.value=e.iridescenceMap,n(e.iridescenceMap,t.iridescenceMapTransform)),e.iridescenceThicknessMap&&(t.iridescenceThicknessMap.value=e.iridescenceThicknessMap,n(e.iridescenceThicknessMap,t.iridescenceThicknessMapTransform)));e.transmission>0&&(t.transmission.value=e.transmission,t.transmissionSamplerMap.value=i.texture,t.transmissionSamplerSize.value.set(i.width,i.height),e.transmissionMap&&(t.transmissionMap.value=e.transmissionMap,n(e.transmissionMap,t.transmissionMapTransform)),t.thickness.value=e.thickness,e.thicknessMap&&(t.thicknessMap.value=e.thicknessMap,n(e.thicknessMap,t.thicknessMapTransform)),t.attenuationDistance.value=e.attenuationDistance,t.attenuationColor.value.copy(e.attenuationColor));e.anisotropy>0&&(t.anisotropyVector.value.set(e.anisotropy*Math.cos(e.anisotropyRotation),e.anisotropy*Math.sin(e.anisotropyRotation)),e.anisotropyMap&&(t.anisotropyMap.value=e.anisotropyMap,n(e.anisotropyMap,t.anisotropyMapTransform)));t.specularIntensity.value=e.specularIntensity,t.specularColor.value.copy(e.specularColor),e.specularColorMap&&(t.specularColorMap.value=e.specularColorMap,n(e.specularColorMap,t.specularColorMapTransform));e.specularIntensityMap&&(t.specularIntensityMap.value=e.specularIntensityMap,n(e.specularIntensityMap,t.specularIntensityMapTransform))}(t,s,o)):s.isMeshMatcapMaterial?(i(t,s),function(t,e){e.matcap&&(t.matcap.value=e.matcap)}(t,s)):s.isMeshDepthMaterial?i(t,s):s.isMeshDistanceMaterial?(i(t,s),function(t,n){const i=e.get(n).light;t.referencePosition.value.setFromMatrixPosition(i.matrixWorld),t.nearDistance.value=i.shadow.camera.near,t.farDistance.value=i.shadow.camera.far}(t,s)):s.isMeshNormalMaterial?i(t,s):s.isLineBasicMaterial?(function(t,e){t.diffuse.value.copy(e.color),t.opacity.value=e.opacity,e.map&&(t.map.value=e.map,n(e.map,t.mapTransform))}(t,s),s.isLineDashedMaterial&&function(t,e){t.dashSize.value=e.dashSize,t.totalSize.value=e.dashSize+e.gapSize,t.scale.value=e.scale}(t,s)):s.isPointsMaterial?function(t,e,i,s){t.diffuse.value.copy(e.color),t.opacity.value=e.opacity,t.size.value=e.size*i,t.scale.value=.5*s,e.map&&(t.map.value=e.map,n(e.map,t.uvTransform));e.alphaMap&&(t.alphaMap.value=e.alphaMap,n(e.alphaMap,t.alphaMapTransform));e.alphaTest>0&&(t.alphaTest.value=e.alphaTest)}(t,s,r,a):s.isSpriteMaterial?function(t,e){t.diffuse.value.copy(e.color),t.opacity.value=e.opacity,t.rotation.value=e.rotation,e.map&&(t.map.value=e.map,n(e.map,t.mapTransform));e.alphaMap&&(t.alphaMap.value=e.alphaMap,n(e.alphaMap,t.alphaMapTransform));e.alphaTest>0&&(t.alphaTest.value=e.alphaTest)}(t,s):s.isShadowMaterial?(t.color.value.copy(s.color),t.opacity.value=s.opacity):s.isShaderMaterial&&(s.uniformsNeedUpdate=!1)}}}function ic(t,e,n,i){let s={},r={},a=[];const o=t.getParameter(t.MAX_UNIFORM_BUFFER_BINDINGS);function l(t,e,n,i){const s=t.value,r=e+"_"+n;if(void 0===i[r])return i[r]="number"==typeof s||"boolean"==typeof s?s:s.clone(),!0;{const t=i[r];if("number"==typeof s||"boolean"==typeof s){if(t!==s)return i[r]=s,!0}else if(!1===t.equals(s))return t.copy(s),!0}return!1}function c(t){const e={boundary:0,storage:0};return"number"==typeof t||"boolean"==typeof t?(e.boundary=4,e.storage=4):t.isVector2?(e.boundary=8,e.storage=8):t.isVector3||t.isColor?(e.boundary=16,e.storage=12):t.isVector4?(e.boundary=16,e.storage=16):t.isMatrix3?(e.boundary=48,e.storage=48):t.isMatrix4?(e.boundary=64,e.storage=64):t.isTexture?console.warn("THREE.WebGLRenderer: Texture samplers can not be part of an uniforms group."):console.warn("THREE.WebGLRenderer: Unsupported uniform value type.",t),e}function u(e){const n=e.target;n.removeEventListener("dispose",u);const i=a.indexOf(n.__bindingPointIndex);a.splice(i,1),t.deleteBuffer(s[n.id]),delete s[n.id],delete r[n.id]}return{bind:function(t,e){const n=e.program;i.uniformBlockBinding(t,n)},update:function(n,h){let d=s[n.id];void 0===d&&(!function(t){const e=t.uniforms;let n=0;const i=16;for(let t=0,s=e.length;t0&&(n+=i-s);t.__size=n,t.__cache={}}(n),d=function(e){const n=function(){for(let t=0;t0),h=!!n.morphAttributes.position,d=!!n.morphAttributes.normal,p=!!n.morphAttributes.color;let m=0;i.toneMapped&&(null!==T&&!0!==T.isXRRenderTarget||(m=_.toneMapping));const f=n.morphAttributes.position||n.morphAttributes.normal||n.morphAttributes.color,v=void 0!==f?f.length:0,y=Q.get(i),x=g.state.lights;if(!0===B&&(!0===k||t!==w)){const e=t===w&&i.id===S;ut.setState(i,t,e)}let M=!1;i.version===y.__version?y.needsLights&&y.lightsStateVersion!==x.state.version||y.outputColorSpace!==o||s.isBatchedMesh&&!1===y.batching?M=!0:s.isBatchedMesh||!0!==y.batching?s.isBatchedMesh&&!0===y.batchingColor&&null===s.colorTexture||s.isBatchedMesh&&!1===y.batchingColor&&null!==s.colorTexture||s.isInstancedMesh&&!1===y.instancing?M=!0:s.isInstancedMesh||!0!==y.instancing?s.isSkinnedMesh&&!1===y.skinning?M=!0:s.isSkinnedMesh||!0!==y.skinning?s.isInstancedMesh&&!0===y.instancingColor&&null===s.instanceColor||s.isInstancedMesh&&!1===y.instancingColor&&null!==s.instanceColor||s.isInstancedMesh&&!0===y.instancingMorph&&null===s.morphTexture||s.isInstancedMesh&&!1===y.instancingMorph&&null!==s.morphTexture||y.envMap!==l||!0===i.fog&&y.fog!==r?M=!0:void 0===y.numClippingPlanes||y.numClippingPlanes===ut.numPlanes&&y.numIntersection===ut.numIntersection?(y.vertexAlphas!==c||y.vertexTangents!==u||y.morphTargets!==h||y.morphNormals!==d||y.morphColors!==p||y.toneMapping!==m||y.morphTargetsCount!==v)&&(M=!0):M=!0:M=!0:M=!0:M=!0:(M=!0,y.__version=i.version);let b=y.currentProgram;!0===M&&(b=jt(i,e,s));let E=!1,A=!1,N=!1;const C=b.getUniforms(),R=y.uniforms;J.useProgram(b.program)&&(E=!0,A=!0,N=!0);i.id!==S&&(S=i.id,A=!0);if(E||w!==t){$.reverseDepthBuffer?(H.copy(t.projectionMatrix),function(t){const e=t.elements;e[2]=.5*e[2]+.5*e[3],e[6]=.5*e[6]+.5*e[7],e[10]=.5*e[10]+.5*e[11],e[14]=.5*e[14]+.5*e[15]}(H),function(t){const e=t.elements;-1===e[11]?(e[10]=-e[10]-1,e[14]=-e[14]):(e[10]=-e[10],e[14]=1-e[14])}(H),C.setValue(_t,"projectionMatrix",H)):C.setValue(_t,"projectionMatrix",t.projectionMatrix),C.setValue(_t,"viewMatrix",t.matrixWorldInverse);const e=C.map.cameraPosition;void 0!==e&&e.setValue(_t,W.setFromMatrixPosition(t.matrixWorld)),$.logarithmicDepthBuffer&&C.setValue(_t,"logDepthBufFC",2/(Math.log(t.far+1)/Math.LN2)),(i.isMeshPhongMaterial||i.isMeshToonMaterial||i.isMeshLambertMaterial||i.isMeshBasicMaterial||i.isMeshStandardMaterial||i.isShaderMaterial)&&C.setValue(_t,"isOrthographic",!0===t.isOrthographicCamera),w!==t&&(w=t,A=!0,N=!0)}if(s.isSkinnedMesh){C.setOptional(_t,s,"bindMatrix"),C.setOptional(_t,s,"bindMatrixInverse");const t=s.skeleton;t&&(null===t.boneTexture&&t.computeBoneTexture(),C.setValue(_t,"boneTexture",t.boneTexture,tt))}s.isBatchedMesh&&(C.setOptional(_t,s,"batchingTexture"),C.setValue(_t,"batchingTexture",s._matricesTexture,tt),C.setOptional(_t,s,"batchingIdTexture"),C.setValue(_t,"batchingIdTexture",s._indirectTexture,tt),C.setOptional(_t,s,"batchingColorTexture"),null!==s._colorsTexture&&C.setValue(_t,"batchingColorTexture",s._colorsTexture,tt));const I=n.morphAttributes;void 0===I.position&&void 0===I.normal&&void 0===I.color||pt.update(s,n,b);(A||y.receiveShadow!==s.receiveShadow)&&(y.receiveShadow=s.receiveShadow,C.setValue(_t,"receiveShadow",s.receiveShadow));i.isMeshGouraudMaterial&&null!==i.envMap&&(R.envMap.value=l,R.flipEnvMap.value=l.isCubeTexture&&!1===l.isRenderTargetTexture?-1:1);i.isMeshStandardMaterial&&null===i.envMap&&null!==e.environment&&(R.envMapIntensity.value=e.environmentIntensity);A&&(C.setValue(_t,"toneMappingExposure",_.toneMappingExposure),y.needsLights&&function(t,e){t.ambientLightColor.needsUpdate=e,t.lightProbe.needsUpdate=e,t.directionalLights.needsUpdate=e,t.directionalLightShadows.needsUpdate=e,t.pointLights.needsUpdate=e,t.pointLightShadows.needsUpdate=e,t.spotLights.needsUpdate=e,t.spotLightShadows.needsUpdate=e,t.rectAreaLights.needsUpdate=e,t.hemisphereLights.needsUpdate=e}(R,N),r&&!0===i.fog&&ot.refreshFogUniforms(R,r),ot.refreshMaterialUniforms(R,i,P,L,g.state.transmissionRenderTarget[t.id]),sl.upload(_t,qt(y),R,tt));i.isShaderMaterial&&!0===i.uniformsNeedUpdate&&(sl.upload(_t,qt(y),R,tt),i.uniformsNeedUpdate=!1);i.isSpriteMaterial&&C.setValue(_t,"center",s.center);if(C.setValue(_t,"modelViewMatrix",s.modelViewMatrix),C.setValue(_t,"normalMatrix",s.normalMatrix),C.setValue(_t,"modelMatrix",s.matrixWorld),i.isShaderMaterial||i.isRawShaderMaterial){const t=i.uniformsGroups;for(let e=0,n=t.length;e{function n(){i.forEach((function(t){Q.get(t).currentProgram.isReady()&&i.delete(t)})),0!==i.size?setTimeout(n,10):e(t)}null!==Z.get("KHR_parallel_shader_compile")?n():setTimeout(n,10)}))};let Lt=null;function zt(){Ft.stop()}function Vt(){Ft.start()}const Ft=new ha;function Bt(t,e,n,i){if(!1===t.visible)return;if(t.layers.test(e.layers))if(t.isGroup)n=t.renderOrder;else if(t.isLOD)!0===t.autoUpdate&&t.update(e);else if(t.isLight)g.pushLight(t),t.castShadow&&g.pushShadow(t);else if(t.isSprite){if(!t.frustumCulled||F.intersectsSprite(t)){i&&j.setFromMatrixPosition(t.matrixWorld).applyMatrix4(G);const e=rt.update(t),s=t.material;s.visible&&f.push(t,e,s,n,j.z,null)}}else if((t.isMesh||t.isLine||t.isPoints)&&(!t.frustumCulled||F.intersectsObject(t))){const e=rt.update(t),s=t.material;if(i&&(void 0!==t.boundingSphere?(null===t.boundingSphere&&t.computeBoundingSphere(),j.copy(t.boundingSphere.center)):(null===e.boundingSphere&&e.computeBoundingSphere(),j.copy(e.boundingSphere.center)),j.applyMatrix4(t.matrixWorld).applyMatrix4(G)),Array.isArray(s)){const i=e.groups;for(let r=0,a=i.length;r0&&Gt(s,e,n),r.length>0&&Gt(r,e,n),a.length>0&&Gt(a,e,n),J.buffers.depth.setTest(!0),J.buffers.depth.setMask(!0),J.buffers.color.setMask(!0),J.setPolygonOffset(!1)}function Ht(t,e,n,i){if(null!==(!0===n.isScene?n.overrideMaterial:null))return;void 0===g.state.transmissionRenderTarget[i.id]&&(g.state.transmissionRenderTarget[i.id]=new Ei(1,1,{generateMipmaps:!0,type:Z.has("EXT_color_buffer_half_float")||Z.has("EXT_color_buffer_float")?Pt:Et,minFilter:St,samples:4,stencilBuffer:r,resolveDepthBuffer:!1,resolveStencilBuffer:!1,colorSpace:mi.workingColorSpace}));const s=g.state.transmissionRenderTarget[i.id],a=i.viewport||E;s.setSize(a.z,a.w);const o=_.getRenderTarget();_.setRenderTarget(s),_.getClearColor(C),R=_.getClearAlpha(),R<1&&_.setClearColor(16777215,.5),_.clear(),q&&dt.render(n);const l=_.toneMapping;_.toneMapping=0;const c=i.viewport;if(void 0!==i.viewport&&(i.viewport=void 0),g.setupLightsView(i),!0===B&&ut.setGlobalState(_.clippingPlanes,i),Gt(t,n,i),tt.updateMultisampleRenderTarget(s),tt.updateRenderTargetMipmap(s),!1===Z.has("WEBGL_multisampled_render_to_texture")){let t=!1;for(let s=0,r=e.length;s0)for(let e=0,r=n.length;e0&&Ht(i,s,t,e),q&&dt.render(t),kt(f,t,e);null!==T&&(tt.updateMultisampleRenderTarget(T),tt.updateRenderTargetMipmap(T)),!0===t.isScene&&t.onAfterRender(_,t,e),vt.resetDefaultState(),S=-1,w=null,y.pop(),y.length>0?(g=y[y.length-1],!0===B&&ut.setGlobalState(_.clippingPlanes,g.state.camera)):g=null,v.pop(),f=v.length>0?v[v.length-1]:null},this.getActiveCubeFace=function(){return M},this.getActiveMipmapLevel=function(){return b},this.getRenderTarget=function(){return T},this.setRenderTargetTextures=function(t,e,n){Q.get(t.texture).__webglTexture=e,Q.get(t.depthTexture).__webglTexture=n;const i=Q.get(t);i.__hasExternalTextures=!0,i.__autoAllocateDepthBuffer=void 0===n,i.__autoAllocateDepthBuffer||!0===Z.has("WEBGL_multisampled_render_to_texture")&&(console.warn("THREE.WebGLRenderer: Render-to-texture extension was disabled because an external texture was provided"),i.__useRenderToTexture=!1)},this.setRenderTargetFramebuffer=function(t,e){const n=Q.get(t);n.__webglFramebuffer=e,n.__useDefaultFramebuffer=void 0===e},this.setRenderTarget=function(t,e=0,n=0){T=t,M=e,b=n;let i=!0,s=null,r=!1,a=!1;if(t){const o=Q.get(t);if(void 0!==o.__useDefaultFramebuffer)J.bindFramebuffer(_t.FRAMEBUFFER,null),i=!1;else if(void 0===o.__webglFramebuffer)tt.setupRenderTarget(t);else if(o.__hasExternalTextures)tt.rebindTextures(t,Q.get(t.texture).__webglTexture,Q.get(t.depthTexture).__webglTexture);else if(t.depthBuffer){const e=t.depthTexture;if(o.__boundDepthTexture!==e){if(null!==e&&Q.has(e)&&(t.width!==e.image.width||t.height!==e.image.height))throw new Error("WebGLRenderTarget: Attached DepthTexture is initialized to the incorrect size.");tt.setupDepthRenderbuffer(t)}}const l=t.texture;(l.isData3DTexture||l.isDataArrayTexture||l.isCompressedArrayTexture)&&(a=!0);const c=Q.get(t).__webglFramebuffer;t.isWebGLCubeRenderTarget?(s=Array.isArray(c[e])?c[e][n]:c[e],r=!0):s=t.samples>0&&!1===tt.useMultisampledRTT(t)?Q.get(t).__webglMultisampledFramebuffer:Array.isArray(c)?c[n]:c,E.copy(t.viewport),A.copy(t.scissor),N=t.scissorTest}else E.copy(O).multiplyScalar(P).floor(),A.copy(z).multiplyScalar(P).floor(),N=V;if(J.bindFramebuffer(_t.FRAMEBUFFER,s)&&i&&J.drawBuffers(t,s),J.viewport(E),J.scissor(A),J.setScissorTest(N),r){const i=Q.get(t.texture);_t.framebufferTexture2D(_t.FRAMEBUFFER,_t.COLOR_ATTACHMENT0,_t.TEXTURE_CUBE_MAP_POSITIVE_X+e,i.__webglTexture,n)}else if(a){const i=Q.get(t.texture),s=e||0;_t.framebufferTextureLayer(_t.FRAMEBUFFER,_t.COLOR_ATTACHMENT0,i.__webglTexture,n||0,s)}S=-1},this.readRenderTargetPixels=function(t,e,n,i,s,r,a){if(!t||!t.isWebGLRenderTarget)return void console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");let o=Q.get(t).__webglFramebuffer;if(t.isWebGLCubeRenderTarget&&void 0!==a&&(o=o[a]),o){J.bindFramebuffer(_t.FRAMEBUFFER,o);try{const a=t.texture,o=a.format,l=a.type;if(!$.textureFormatReadable(o))return void console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.");if(!$.textureTypeReadable(l))return void console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.");e>=0&&e<=t.width-i&&n>=0&&n<=t.height-s&&_t.readPixels(e,n,i,s,gt.convert(o),gt.convert(l),r)}finally{const t=null!==T?Q.get(T).__webglFramebuffer:null;J.bindFramebuffer(_t.FRAMEBUFFER,t)}}},this.readRenderTargetPixelsAsync=async function(t,e,n,i,s,r,a){if(!t||!t.isWebGLRenderTarget)throw new Error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");let o=Q.get(t).__webglFramebuffer;if(t.isWebGLCubeRenderTarget&&void 0!==a&&(o=o[a]),o){const a=t.texture,l=a.format,c=a.type;if(!$.textureFormatReadable(l))throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.");if(!$.textureTypeReadable(c))throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.");if(e>=0&&e<=t.width-i&&n>=0&&n<=t.height-s){J.bindFramebuffer(_t.FRAMEBUFFER,o);const t=_t.createBuffer();_t.bindBuffer(_t.PIXEL_PACK_BUFFER,t),_t.bufferData(_t.PIXEL_PACK_BUFFER,r.byteLength,_t.STREAM_READ),_t.readPixels(e,n,i,s,gt.convert(l),gt.convert(c),0);const a=null!==T?Q.get(T).__webglFramebuffer:null;J.bindFramebuffer(_t.FRAMEBUFFER,a);const u=_t.fenceSync(_t.SYNC_GPU_COMMANDS_COMPLETE,0);return _t.flush(),await function(t,e,n){return new Promise((function(i,s){setTimeout((function r(){switch(t.clientWaitSync(e,t.SYNC_FLUSH_COMMANDS_BIT,0)){case t.WAIT_FAILED:s();break;case t.TIMEOUT_EXPIRED:setTimeout(r,n);break;default:i()}}),n)}))}(_t,u,4),_t.bindBuffer(_t.PIXEL_PACK_BUFFER,t),_t.getBufferSubData(_t.PIXEL_PACK_BUFFER,0,r),_t.deleteBuffer(t),_t.deleteSync(u),r}throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: requested read bounds are out of range.")}},this.copyFramebufferToTexture=function(t,e=null,n=0){!0!==t.isTexture&&(ci("WebGLRenderer: copyFramebufferToTexture function signature has changed."),e=arguments[0]||null,t=arguments[1]);const i=Math.pow(2,-n),s=Math.floor(t.image.width*i),r=Math.floor(t.image.height*i),a=null!==e?e.x:0,o=null!==e?e.y:0;tt.setTexture2D(t,0),_t.copyTexSubImage2D(_t.TEXTURE_2D,n,0,0,a,o,s,r),J.unbindTexture()},this.copyTextureToTexture=function(t,e,n=null,i=null,s=0){let r,a,o,l,c,u;!0!==t.isTexture&&(ci("WebGLRenderer: copyTextureToTexture function signature has changed."),i=arguments[0]||null,t=arguments[1],e=arguments[2],s=arguments[3]||0,n=null),null!==n?(r=n.max.x-n.min.x,a=n.max.y-n.min.y,o=n.min.x,l=n.min.y):(r=t.image.width,a=t.image.height,o=0,l=0),null!==i?(c=i.x,u=i.y):(c=0,u=0);const h=gt.convert(e.format),d=gt.convert(e.type);tt.setTexture2D(e,0),_t.pixelStorei(_t.UNPACK_FLIP_Y_WEBGL,e.flipY),_t.pixelStorei(_t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,e.premultiplyAlpha),_t.pixelStorei(_t.UNPACK_ALIGNMENT,e.unpackAlignment);const p=_t.getParameter(_t.UNPACK_ROW_LENGTH),m=_t.getParameter(_t.UNPACK_IMAGE_HEIGHT),f=_t.getParameter(_t.UNPACK_SKIP_PIXELS),g=_t.getParameter(_t.UNPACK_SKIP_ROWS),v=_t.getParameter(_t.UNPACK_SKIP_IMAGES),y=t.isCompressedTexture?t.mipmaps[s]:t.image;_t.pixelStorei(_t.UNPACK_ROW_LENGTH,y.width),_t.pixelStorei(_t.UNPACK_IMAGE_HEIGHT,y.height),_t.pixelStorei(_t.UNPACK_SKIP_PIXELS,o),_t.pixelStorei(_t.UNPACK_SKIP_ROWS,l),t.isDataTexture?_t.texSubImage2D(_t.TEXTURE_2D,s,c,u,r,a,h,d,y.data):t.isCompressedTexture?_t.compressedTexSubImage2D(_t.TEXTURE_2D,s,c,u,y.width,y.height,h,y.data):_t.texSubImage2D(_t.TEXTURE_2D,s,c,u,r,a,h,d,y),_t.pixelStorei(_t.UNPACK_ROW_LENGTH,p),_t.pixelStorei(_t.UNPACK_IMAGE_HEIGHT,m),_t.pixelStorei(_t.UNPACK_SKIP_PIXELS,f),_t.pixelStorei(_t.UNPACK_SKIP_ROWS,g),_t.pixelStorei(_t.UNPACK_SKIP_IMAGES,v),0===s&&e.generateMipmaps&&_t.generateMipmap(_t.TEXTURE_2D),J.unbindTexture()},this.copyTextureToTexture3D=function(t,e,n=null,i=null,s=0){let r,a,o,l,c,u,h,d,p;!0!==t.isTexture&&(ci("WebGLRenderer: copyTextureToTexture3D function signature has changed."),n=arguments[0]||null,i=arguments[1]||null,t=arguments[2],e=arguments[3],s=arguments[4]||0);const m=t.isCompressedTexture?t.mipmaps[s]:t.image;null!==n?(r=n.max.x-n.min.x,a=n.max.y-n.min.y,o=n.max.z-n.min.z,l=n.min.x,c=n.min.y,u=n.min.z):(r=m.width,a=m.height,o=m.depth,l=0,c=0,u=0),null!==i?(h=i.x,d=i.y,p=i.z):(h=0,d=0,p=0);const f=gt.convert(e.format),g=gt.convert(e.type);let v;if(e.isData3DTexture)tt.setTexture3D(e,0),v=_t.TEXTURE_3D;else{if(!e.isDataArrayTexture&&!e.isCompressedArrayTexture)return void console.warn("THREE.WebGLRenderer.copyTextureToTexture3D: only supports THREE.DataTexture3D and THREE.DataTexture2DArray.");tt.setTexture2DArray(e,0),v=_t.TEXTURE_2D_ARRAY}_t.pixelStorei(_t.UNPACK_FLIP_Y_WEBGL,e.flipY),_t.pixelStorei(_t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,e.premultiplyAlpha),_t.pixelStorei(_t.UNPACK_ALIGNMENT,e.unpackAlignment);const y=_t.getParameter(_t.UNPACK_ROW_LENGTH),_=_t.getParameter(_t.UNPACK_IMAGE_HEIGHT),x=_t.getParameter(_t.UNPACK_SKIP_PIXELS),M=_t.getParameter(_t.UNPACK_SKIP_ROWS),b=_t.getParameter(_t.UNPACK_SKIP_IMAGES);_t.pixelStorei(_t.UNPACK_ROW_LENGTH,m.width),_t.pixelStorei(_t.UNPACK_IMAGE_HEIGHT,m.height),_t.pixelStorei(_t.UNPACK_SKIP_PIXELS,l),_t.pixelStorei(_t.UNPACK_SKIP_ROWS,c),_t.pixelStorei(_t.UNPACK_SKIP_IMAGES,u),t.isDataTexture||t.isData3DTexture?_t.texSubImage3D(v,s,h,d,p,r,a,o,f,g,m.data):e.isCompressedArrayTexture?_t.compressedTexSubImage3D(v,s,h,d,p,r,a,o,f,m.data):_t.texSubImage3D(v,s,h,d,p,r,a,o,f,g,m),_t.pixelStorei(_t.UNPACK_ROW_LENGTH,y),_t.pixelStorei(_t.UNPACK_IMAGE_HEIGHT,_),_t.pixelStorei(_t.UNPACK_SKIP_PIXELS,x),_t.pixelStorei(_t.UNPACK_SKIP_ROWS,M),_t.pixelStorei(_t.UNPACK_SKIP_IMAGES,b),0===s&&e.generateMipmaps&&_t.generateMipmap(v),J.unbindTexture()},this.initRenderTarget=function(t){void 0===Q.get(t).__webglFramebuffer&&tt.setupRenderTarget(t)},this.initTexture=function(t){t.isCubeTexture?tt.setTextureCube(t,0):t.isData3DTexture?tt.setTexture3D(t,0):t.isDataArrayTexture||t.isCompressedArrayTexture?tt.setTexture2DArray(t,0):tt.setTexture2D(t,0),J.unbindTexture()},this.resetState=function(){M=0,b=0,T=null,J.reset(),vt.reset()},"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}get coordinateSystem(){return Bn}get outputColorSpace(){return this._outputColorSpace}set outputColorSpace(t){this._outputColorSpace=t;const e=this.getContext();e.drawingBufferColorSpace=t===Ke?"display-p3":"srgb",e.unpackColorSpace=mi.workingColorSpace===Qe?"display-p3":"srgb"}}class rc{constructor(t,e=25e-5){this.isFogExp2=!0,this.name="",this.color=new tr(t),this.density=e}clone(){return new rc(this.color,this.density)}toJSON(){return{type:"FogExp2",name:this.name,color:this.color.getHex(),density:this.density}}}class ac{constructor(t,e=1,n=1e3){this.isFog=!0,this.name="",this.color=new tr(t),this.near=e,this.far=n}clone(){return new ac(this.color,this.near,this.far)}toJSON(){return{type:"Fog",name:this.name,color:this.color.getHex(),near:this.near,far:this.far}}}class oc extends Ds{constructor(){super(),this.isScene=!0,this.type="Scene",this.background=null,this.environment=null,this.fog=null,this.backgroundBlurriness=0,this.backgroundIntensity=1,this.backgroundRotation=new ys,this.environmentIntensity=1,this.environmentRotation=new ys,this.overrideMaterial=null,"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}copy(t,e){return super.copy(t,e),null!==t.background&&(this.background=t.background.clone()),null!==t.environment&&(this.environment=t.environment.clone()),null!==t.fog&&(this.fog=t.fog.clone()),this.backgroundBlurriness=t.backgroundBlurriness,this.backgroundIntensity=t.backgroundIntensity,this.backgroundRotation.copy(t.backgroundRotation),this.environmentIntensity=t.environmentIntensity,this.environmentRotation.copy(t.environmentRotation),null!==t.overrideMaterial&&(this.overrideMaterial=t.overrideMaterial.clone()),this.matrixAutoUpdate=t.matrixAutoUpdate,this}toJSON(t){const e=super.toJSON(t);return null!==this.fog&&(e.object.fog=this.fog.toJSON()),this.backgroundBlurriness>0&&(e.object.backgroundBlurriness=this.backgroundBlurriness),1!==this.backgroundIntensity&&(e.object.backgroundIntensity=this.backgroundIntensity),e.object.backgroundRotation=this.backgroundRotation.toArray(),1!==this.environmentIntensity&&(e.object.environmentIntensity=this.environmentIntensity),e.object.environmentRotation=this.environmentRotation.toArray(),e}}class lc{constructor(t,e){this.isInterleavedBuffer=!0,this.array=t,this.stride=e,this.count=void 0!==t?t.length/e:0,this.usage=Cn,this.updateRanges=[],this.version=0,this.uuid=qn()}onUploadCallback(){}set needsUpdate(t){!0===t&&this.version++}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.array=new t.array.constructor(t.array),this.count=t.count,this.stride=t.stride,this.usage=t.usage,this}copyAt(t,e,n){t*=this.stride,n*=e.stride;for(let i=0,s=this.stride;it.far||e.push({distance:o,point:pc.clone(),uv:Zs.getInterpolation(pc,_c,xc,Mc,bc,Tc,Sc,new ti),face:null,object:this})}copy(t,e){return super.copy(t,e),void 0!==t.center&&this.center.copy(t.center),this.material=t.material,this}}function Ec(t,e,n,i,s,r){gc.subVectors(t,n).addScalar(.5).multiply(i),void 0!==s?(vc.x=r*gc.x-s*gc.y,vc.y=s*gc.x+r*gc.y):vc.copy(gc),t.copy(e),t.x+=vc.x,t.y+=vc.y,t.applyMatrix4(yc)}const Ac=new Li,Nc=new Li;class Cc extends Ds{constructor(){super(),this._currentLevel=0,this.type="LOD",Object.defineProperties(this,{levels:{enumerable:!0,value:[]},isLOD:{value:!0}}),this.autoUpdate=!0}copy(t){super.copy(t,!1);const e=t.levels;for(let t=0,n=e.length;t0){let n,i;for(n=1,i=e.length;n0){Ac.setFromMatrixPosition(this.matrixWorld);const n=t.ray.origin.distanceTo(Ac);this.getObjectForDistance(n).raycast(t,e)}}update(t){const e=this.levels;if(e.length>1){Ac.setFromMatrixPosition(t.matrixWorld),Nc.setFromMatrixPosition(this.matrixWorld);const n=Ac.distanceTo(Nc)/t.zoom;let i,s;for(e[0].object.visible=!0,i=1,s=e.length;i=t))break;e[i-1].object.visible=!1,e[i].object.visible=!0}for(this._currentLevel=i-1;i=i.length&&i.push({start:-1,count:-1,z:-1,index:-1});const r=i[this.index];s.push(r),this.index++,r.start=t.start,r.count=t.count,r.z=e,r.index=n}reset(){this.list.length=0,this.index=0}}const iu=new ls,su=new ls,ru=new ls,au=new tr(1,1,1),ou=new ls,lu=new ua,cu=new Di,uu=new Qi,hu=new Li,du=new Li,pu=new Li,mu=new nu,fu=new kr,gu=[];function vu(t,e,n=0){const i=e.itemSize;if(t.isInterleavedBufferAttribute||t.array.constructor!==e.array.constructor){const s=t.count;for(let r=0;r65535?new Uint32Array(i):new Uint16Array(i);e.setIndex(new dr(t,1))}this._geometryInitialized=!0}}_validateGeometry(t){const e=this.geometry;if(Boolean(t.getIndex())!==Boolean(e.getIndex()))throw new Error('BatchedMesh: All geometries must consistently have "index".');for(const n in e.attributes){if(!t.hasAttribute(n))throw new Error(`BatchedMesh: Added geometry missing "${n}". All geometries must have consistent attributes.`);const i=t.getAttribute(n),s=e.getAttribute(n);if(i.itemSize!==s.itemSize||i.normalized!==s.normalized)throw new Error("BatchedMesh: All attributes must have a consistent itemSize and normalized value.")}}setCustomSort(t){return this.customSort=t,this}computeBoundingBox(){null===this.boundingBox&&(this.boundingBox=new Di);const t=this.boundingBox,e=this._drawInfo;t.makeEmpty();for(let n=0,i=e.length;n=this.maxInstanceCount&&0===this._availableInstanceIds.length)throw new Error("BatchedMesh: Maximum item count reached.");const e={visible:!0,active:!0,geometryIndex:t};let n=null;this._availableInstanceIds.length>0?(n=this._availableInstanceIds.pop(),this._drawInfo[n]=e):(n=this._drawInfo.length,this._drawInfo.push(e));const i=this._matricesTexture,s=i.image.data;ru.toArray(s,16*n),i.needsUpdate=!0;const r=this._colorsTexture;return r&&(au.toArray(r.image.data,4*n),r.needsUpdate=!0),n}addGeometry(t,e=-1,n=-1){if(this._initializeGeometry(t),this._validateGeometry(t),this._drawInfo.length>=this._maxInstanceCount)throw new Error("BatchedMesh: Maximum item count reached.");const i={vertexStart:-1,vertexCount:-1,indexStart:-1,indexCount:-1};let s=null;const r=this._reservedRanges,a=this._drawRanges,o=this._bounds;0!==this._geometryCount&&(s=r[r.length-1]),i.vertexCount=-1===e?t.getAttribute("position").count:e,i.vertexStart=null===s?0:s.vertexStart+s.vertexCount;const l=t.getIndex(),c=null!==l;if(c&&(i.indexCount=-1===n?l.count:n,i.indexStart=null===s?0:s.indexStart+s.indexCount),-1!==i.indexStart&&i.indexStart+i.indexCount>this._maxIndexCount||i.vertexStart+i.vertexCount>this._maxVertexCount)throw new Error("BatchedMesh: Reserved space request exceeds the maximum buffer size.");const u=this._geometryCount;return this._geometryCount++,r.push(i),a.push({start:c?i.indexStart:i.vertexStart,count:-1}),o.push({boxInitialized:!1,box:new Di,sphereInitialized:!1,sphere:new Qi}),this.setGeometryAt(u,t),u}setGeometryAt(t,e){if(t>=this._geometryCount)throw new Error("BatchedMesh: Maximum geometry count reached.");this._validateGeometry(e);const n=this.geometry,i=null!==n.getIndex(),s=n.getIndex(),r=e.getIndex(),a=this._reservedRanges[t];if(i&&r.count>a.indexCount||e.attributes.position.count>a.vertexCount)throw new Error("BatchedMesh: Reserved space not large enough for provided geometry.");const o=a.vertexStart,l=a.vertexCount;for(const t in n.attributes){const i=e.getAttribute(t),s=n.getAttribute(t);vu(i,s,o);const r=i.itemSize;for(let t=i.count,e=l;t=e.length||!1===e[t].active||(e[t].active=!1,this._availableInstanceIds.push(t),this._visibilityChanged=!0),this}getBoundingBoxAt(t,e){if(t>=this._geometryCount)return null;const n=this._bounds[t],i=n.box,s=this.geometry;if(!1===n.boxInitialized){i.makeEmpty();const e=s.index,r=s.attributes.position,a=this._drawRanges[t];for(let t=a.start,n=a.start+a.count;t=this._geometryCount)return null;const n=this._bounds[t],i=n.sphere,s=this.geometry;if(!1===n.sphereInitialized){i.makeEmpty(),this.getBoundingBoxAt(t,cu),cu.getCenter(i.center);const e=s.index,r=s.attributes.position,a=this._drawRanges[t];let o=0;for(let t=a.start,n=a.start+a.count;t=n.length||!1===n[t].active||(e.toArray(s,16*t),i.needsUpdate=!0),this}getMatrixAt(t,e){const n=this._drawInfo,i=this._matricesTexture.image.data;return t>=n.length||!1===n[t].active?null:e.fromArray(i,16*t)}setColorAt(t,e){null===this._colorsTexture&&this._initColorsTexture();const n=this._colorsTexture,i=this._colorsTexture.image.data,s=this._drawInfo;return t>=s.length||!1===s[t].active||(e.toArray(i,4*t),n.needsUpdate=!0),this}getColorAt(t,e){const n=this._colorsTexture.image.data,i=this._drawInfo;return t>=i.length||!1===i[t].active?null:e.fromArray(n,4*t)}setVisibleAt(t,e){const n=this._drawInfo;return t>=n.length||!1===n[t].active||n[t].visible===e||(n[t].visible=e,this._visibilityChanged=!0),this}getVisibleAt(t){const e=this._drawInfo;return!(t>=e.length||!1===e[t].active)&&e[t].visible}setGeometryIdAt(t,e){const n=this._drawInfo;return t>=n.length||!1===n[t].active||e<0||e>=this._geometryCount?null:(n[t].geometryIndex=e,this)}getGeometryIdAt(t){const e=this._drawInfo;return t>=e.length||!1===e[t].active?-1:e[t].geometryIndex}getGeometryRangeAt(t,e={}){if(t<0||t>=this._geometryCount)return null;const n=this._drawRanges[t];return e.start=n.start,e.count=n.count,e}raycast(t,e){const n=this._drawInfo,i=this._drawRanges,s=this.matrixWorld,r=this.geometry;fu.material=this.material,fu.geometry.index=r.index,fu.geometry.attributes=r.attributes,null===fu.geometry.boundingBox&&(fu.geometry.boundingBox=new Di),null===fu.geometry.boundingSphere&&(fu.geometry.boundingSphere=new Qi);for(let r=0,a=n.length;r({...t}))),this._reservedRanges=t._reservedRanges.map((t=>({...t}))),this._drawInfo=t._drawInfo.map((t=>({...t}))),this._bounds=t._bounds.map((t=>({boxInitialized:t.boxInitialized,box:t.box.clone(),sphereInitialized:t.sphereInitialized,sphere:t.sphere.clone()}))),this._maxInstanceCount=t._maxInstanceCount,this._maxVertexCount=t._maxVertexCount,this._maxIndexCount=t._maxIndexCount,this._geometryInitialized=t._geometryInitialized,this._geometryCount=t._geometryCount,this._multiDrawCounts=t._multiDrawCounts.slice(),this._multiDrawStarts=t._multiDrawStarts.slice(),this._matricesTexture=t._matricesTexture.clone(),this._matricesTexture.image.data=this._matricesTexture.image.data.slice(),null!==this._colorsTexture&&(this._colorsTexture=t._colorsTexture.clone(),this._colorsTexture.image.data=this._colorsTexture.image.data.slice()),this}dispose(){return this.geometry.dispose(),this._matricesTexture.dispose(),this._matricesTexture=null,this._indirectTexture.dispose(),this._indirectTexture=null,null!==this._colorsTexture&&(this._colorsTexture.dispose(),this._colorsTexture=null),this}onBeforeRender(t,e,n,i,s){if(!this._visibilityChanged&&!this.perObjectFrustumCulled&&!this.sortObjects)return;const r=i.getIndex(),a=null===r?1:r.array.BYTES_PER_ELEMENT,o=this._drawInfo,l=this._multiDrawStarts,c=this._multiDrawCounts,u=this._drawRanges,h=this.perObjectFrustumCulled,d=this._indirectTexture,p=d.image.data;h&&(ou.multiplyMatrices(n.projectionMatrix,n.matrixWorldInverse).multiply(this.matrixWorld),lu.setFromProjectionMatrix(ou,t.coordinateSystem));let m=0;if(this.sortObjects){su.copy(this.matrixWorld).invert(),hu.setFromMatrixPosition(n.matrixWorld).applyMatrix4(su),du.set(0,0,-1).transformDirection(n.matrixWorld).transformDirection(su);for(let t=0,e=o.length;t0){const n=t[e[0]];if(void 0!==n){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let t=0,e=n.length;ti)return;wu.applyMatrix4(t.matrixWorld);const o=e.ray.origin.distanceTo(wu);return oe.far?void 0:{distance:o,point:Eu.clone().applyMatrix4(t.matrixWorld),index:s,face:null,faceIndex:null,barycoord:null,object:t}}const Cu=new Li,Ru=new Li;class Iu extends Au{constructor(t,e){super(t,e),this.isLineSegments=!0,this.type="LineSegments"}computeLineDistances(){const t=this.geometry;if(null===t.index){const e=t.attributes.position,n=[];for(let t=0,i=e.count;t0){const n=t[e[0]];if(void 0!==n){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let t=0,e=n.length;ts.far)return;r.push({distance:l,distanceToRay:Math.sqrt(o),point:n,index:e,face:null,faceIndex:null,barycoord:null,object:a})}}class Bu extends Ti{constructor(t,e,n,i,s,r,a,o,l){super(t,e,n,i,s,r,a,o,l),this.isVideoTexture=!0,this.minFilter=void 0!==r?r:Mt,this.magFilter=void 0!==s?s:Mt,this.generateMipmaps=!1;const c=this;"requestVideoFrameCallback"in t&&t.requestVideoFrameCallback((function e(){c.needsUpdate=!0,t.requestVideoFrameCallback(e)}))}clone(){return new this.constructor(this.image).copy(this)}update(){const t=this.image;!1==="requestVideoFrameCallback"in t&&t.readyState>=t.HAVE_CURRENT_DATA&&(this.needsUpdate=!0)}}class ku extends Ti{constructor(t,e){super({width:t,height:e}),this.isFramebufferTexture=!0,this.magFilter=gt,this.minFilter=gt,this.generateMipmaps=!1,this.needsUpdate=!0}}class Hu extends Ti{constructor(t,e,n,i,s,r,a,o,l,c,u,h){super(null,r,a,o,l,c,i,s,u,h),this.isCompressedTexture=!0,this.image={width:e,height:n},this.mipmaps=t,this.flipY=!1,this.generateMipmaps=!1}}class Gu extends Hu{constructor(t,e,n,i,s,r){super(t,e,n,s,r),this.isCompressedArrayTexture=!0,this.image.depth=i,this.wrapR=mt,this.layerUpdates=new Set}addLayerUpdate(t){this.layerUpdates.add(t)}clearLayerUpdates(){this.layerUpdates.clear()}}class Wu extends Hu{constructor(t,e,n){super(void 0,t[0].width,t[0].height,e,n,lt),this.isCompressedCubeTexture=!0,this.isCubeTexture=!0,this.image=t}}class ju extends Ti{constructor(t,e,n,i,s,r,a,o,l){super(t,e,n,i,s,r,a,o,l),this.isCanvasTexture=!0,this.needsUpdate=!0}}class Xu{constructor(){this.type="Curve",this.arcLengthDivisions=200}getPoint(){return console.warn("THREE.Curve: .getPoint() not implemented."),null}getPointAt(t,e){const n=this.getUtoTmapping(t);return this.getPoint(n,e)}getPoints(t=5){const e=[];for(let n=0;n<=t;n++)e.push(this.getPoint(n/t));return e}getSpacedPoints(t=5){const e=[];for(let n=0;n<=t;n++)e.push(this.getPointAt(n/t));return e}getLength(){const t=this.getLengths();return t[t.length-1]}getLengths(t=this.arcLengthDivisions){if(this.cacheArcLengths&&this.cacheArcLengths.length===t+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;const e=[];let n,i=this.getPoint(0),s=0;e.push(0);for(let r=1;r<=t;r++)n=this.getPoint(r/t),s+=n.distanceTo(i),e.push(s),i=n;return this.cacheArcLengths=e,e}updateArcLengths(){this.needsUpdate=!0,this.getLengths()}getUtoTmapping(t,e){const n=this.getLengths();let i=0;const s=n.length;let r;r=e||t*n[s-1];let a,o=0,l=s-1;for(;o<=l;)if(i=Math.floor(o+(l-o)/2),a=n[i]-r,a<0)o=i+1;else{if(!(a>0)){l=i;break}l=i-1}if(i=l,n[i]===r)return i/(s-1);const c=n[i];return(i+(r-c)/(n[i+1]-c))/(s-1)}getTangent(t,e){const n=1e-4;let i=t-n,s=t+n;i<0&&(i=0),s>1&&(s=1);const r=this.getPoint(i),a=this.getPoint(s),o=e||(r.isVector2?new ti:new Li);return o.copy(a).sub(r).normalize(),o}getTangentAt(t,e){const n=this.getUtoTmapping(t);return this.getTangent(n,e)}computeFrenetFrames(t,e){const n=new Li,i=[],s=[],r=[],a=new Li,o=new ls;for(let e=0;e<=t;e++){const n=e/t;i[e]=this.getTangentAt(n,new Li)}s[0]=new Li,r[0]=new Li;let l=Number.MAX_VALUE;const c=Math.abs(i[0].x),u=Math.abs(i[0].y),h=Math.abs(i[0].z);c<=l&&(l=c,n.set(1,0,0)),u<=l&&(l=u,n.set(0,1,0)),h<=l&&n.set(0,0,1),a.crossVectors(i[0],n).normalize(),s[0].crossVectors(i[0],a),r[0].crossVectors(i[0],s[0]);for(let e=1;e<=t;e++){if(s[e]=s[e-1].clone(),r[e]=r[e-1].clone(),a.crossVectors(i[e-1],i[e]),a.length()>Number.EPSILON){a.normalize();const t=Math.acos(Yn(i[e-1].dot(i[e]),-1,1));s[e].applyMatrix4(o.makeRotationAxis(a,t))}r[e].crossVectors(i[e],s[e])}if(!0===e){let e=Math.acos(Yn(s[0].dot(s[t]),-1,1));e/=t,i[0].dot(a.crossVectors(s[0],s[t]))>0&&(e=-e);for(let n=1;n<=t;n++)s[n].applyMatrix4(o.makeRotationAxis(i[n],e*n)),r[n].crossVectors(i[n],s[n])}return{tangents:i,normals:s,binormals:r}}clone(){return(new this.constructor).copy(this)}copy(t){return this.arcLengthDivisions=t.arcLengthDivisions,this}toJSON(){const t={metadata:{version:4.6,type:"Curve",generator:"Curve.toJSON"}};return t.arcLengthDivisions=this.arcLengthDivisions,t.type=this.type,t}fromJSON(t){return this.arcLengthDivisions=t.arcLengthDivisions,this}}class qu extends Xu{constructor(t=0,e=0,n=1,i=1,s=0,r=2*Math.PI,a=!1,o=0){super(),this.isEllipseCurve=!0,this.type="EllipseCurve",this.aX=t,this.aY=e,this.xRadius=n,this.yRadius=i,this.aStartAngle=s,this.aEndAngle=r,this.aClockwise=a,this.aRotation=o}getPoint(t,e=new ti){const n=e,i=2*Math.PI;let s=this.aEndAngle-this.aStartAngle;const r=Math.abs(s)i;)s-=i;s0?0:(Math.floor(Math.abs(l)/s)+1)*s:0===c&&l===s-1&&(l=s-2,c=1),this.closed||l>0?a=i[(l-1)%s]:($u.subVectors(i[0],i[1]).add(i[0]),a=$u);const u=i[l%s],h=i[(l+1)%s];if(this.closed||l+2i.length-2?i.length-1:r+1],u=i[r>i.length-3?i.length-1:r+2];return n.set(eh(a,o.x,l.x,c.x,u.x),eh(a,o.y,l.y,c.y,u.y)),n}copy(t){super.copy(t),this.points=[];for(let e=0,n=t.points.length;e=n){const t=i[s]-n,r=this.curves[s],a=r.getLength(),o=0===a?0:1-t/a;return r.getPointAt(o,e)}s++}return null}getLength(){const t=this.getCurveLengths();return t[t.length-1]}updateArcLengths(){this.needsUpdate=!0,this.cacheLengths=null,this.getCurveLengths()}getCurveLengths(){if(this.cacheLengths&&this.cacheLengths.length===this.curves.length)return this.cacheLengths;const t=[];let e=0;for(let n=0,i=this.curves.length;n1&&!e[e.length-1].equals(e[0])&&e.push(e[0]),e}copy(t){super.copy(t),this.curves=[];for(let e=0,n=t.curves.length;e0){const t=l.getPoint(0);t.equals(this.currentPoint)||this.lineTo(t.x,t.y)}this.curves.push(l);const c=l.getPoint(1);return this.currentPoint.copy(c),this}copy(t){return super.copy(t),this.currentPoint.copy(t.currentPoint),this}toJSON(){const t=super.toJSON();return t.currentPoint=this.currentPoint.toArray(),t}fromJSON(t){return super.fromJSON(t),this.currentPoint.fromArray(t.currentPoint),this}}class mh extends Cr{constructor(t=[new ti(0,-.5),new ti(.5,0),new ti(0,.5)],e=12,n=0,i=2*Math.PI){super(),this.type="LatheGeometry",this.parameters={points:t,segments:e,phiStart:n,phiLength:i},e=Math.floor(e),i=Yn(i,0,2*Math.PI);const s=[],r=[],a=[],o=[],l=[],c=1/e,u=new Li,h=new ti,d=new Li,p=new Li,m=new Li;let f=0,g=0;for(let e=0;e<=t.length-1;e++)switch(e){case 0:f=t[e+1].x-t[e].x,g=t[e+1].y-t[e].y,d.x=1*g,d.y=-f,d.z=0*g,m.copy(d),d.normalize(),o.push(d.x,d.y,d.z);break;case t.length-1:o.push(m.x,m.y,m.z);break;default:f=t[e+1].x-t[e].x,g=t[e+1].y-t[e].y,d.x=1*g,d.y=-f,d.z=0*g,p.copy(d),d.x+=m.x,d.y+=m.y,d.z+=m.z,d.normalize(),o.push(d.x,d.y,d.z),m.copy(p)}for(let s=0;s<=e;s++){const d=n+s*c*i,p=Math.sin(d),m=Math.cos(d);for(let n=0;n<=t.length-1;n++){u.x=t[n].x*p,u.y=t[n].y,u.z=t[n].x*m,r.push(u.x,u.y,u.z),h.x=s/e,h.y=n/(t.length-1),a.push(h.x,h.y);const i=o[3*n+0]*p,c=o[3*n+1],d=o[3*n+0]*m;l.push(i,c,d)}}for(let n=0;n0&&(c.push(s,r,o),y+=3),e>0&&(c.push(r,a,o),y+=3)}l.addGroup(g,y,0),g+=y}(),!1===r&&(t>0&&v(!0),e>0&&v(!1)),this.setIndex(c),this.setAttribute("position",new Mr(u,3)),this.setAttribute("normal",new Mr(h,3)),this.setAttribute("uv",new Mr(d,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new vh(t.radiusTop,t.radiusBottom,t.height,t.radialSegments,t.heightSegments,t.openEnded,t.thetaStart,t.thetaLength)}}class yh extends vh{constructor(t=1,e=1,n=32,i=1,s=!1,r=0,a=2*Math.PI){super(0,t,e,n,i,s,r,a),this.type="ConeGeometry",this.parameters={radius:t,height:e,radialSegments:n,heightSegments:i,openEnded:s,thetaStart:r,thetaLength:a}}static fromJSON(t){return new yh(t.radius,t.height,t.radialSegments,t.heightSegments,t.openEnded,t.thetaStart,t.thetaLength)}}class _h extends Cr{constructor(t=[],e=[],n=1,i=0){super(),this.type="PolyhedronGeometry",this.parameters={vertices:t,indices:e,radius:n,detail:i};const s=[],r=[];function a(t,e,n,i){const s=i+1,r=[];for(let i=0;i<=s;i++){r[i]=[];const a=t.clone().lerp(n,i/s),o=e.clone().lerp(n,i/s),l=s-i;for(let t=0;t<=l;t++)r[i][t]=0===t&&i===s?a:a.clone().lerp(o,t/l)}for(let t=0;t.9&&a<.1&&(e<.2&&(r[t+0]+=1),n<.2&&(r[t+2]+=1),i<.2&&(r[t+4]+=1))}}()}(),this.setAttribute("position",new Mr(s,3)),this.setAttribute("normal",new Mr(s.slice(),3)),this.setAttribute("uv",new Mr(r,2)),0===i?this.computeVertexNormals():this.normalizeNormals()}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new _h(t.vertices,t.indices,t.radius,t.details)}}class xh extends _h{constructor(t=1,e=0){const n=(1+Math.sqrt(5))/2,i=1/n;super([-1,-1,-1,-1,-1,1,-1,1,-1,-1,1,1,1,-1,-1,1,-1,1,1,1,-1,1,1,1,0,-i,-n,0,-i,n,0,i,-n,0,i,n,-i,-n,0,-i,n,0,i,-n,0,i,n,0,-n,0,-i,n,0,-i,-n,0,i,n,0,i],[3,11,7,3,7,15,3,15,13,7,19,17,7,17,6,7,6,15,17,4,8,17,8,10,17,10,6,8,0,16,8,16,2,8,2,10,0,12,1,0,1,18,0,18,16,6,10,2,6,2,13,6,13,15,2,16,18,2,18,3,2,3,13,18,1,9,18,9,11,18,11,3,4,14,12,4,12,0,4,0,8,11,9,5,11,5,19,11,19,7,19,5,14,19,14,4,19,4,17,1,12,14,1,14,5,1,5,9],t,e),this.type="DodecahedronGeometry",this.parameters={radius:t,detail:e}}static fromJSON(t){return new xh(t.radius,t.detail)}}const Mh=new Li,bh=new Li,Th=new Li,Sh=new Zs;class wh extends Cr{constructor(t=null,e=1){if(super(),this.type="EdgesGeometry",this.parameters={geometry:t,thresholdAngle:e},null!==t){const n=4,i=Math.pow(10,n),s=Math.cos(jn*e),r=t.getIndex(),a=t.getAttribute("position"),o=r?r.count:a.count,l=[0,0,0],c=["a","b","c"],u=new Array(3),h={},d=[];for(let t=0;t80*n){o=c=t[0],l=u=t[1];for(let e=n;ec&&(c=h),d>u&&(u=d);p=Math.max(c-o,u-l),p=0!==p?32767/p:0}return Rh(r,a,n,o,l,p,0),a};function Nh(t,e,n,i,s){let r,a;if(s===function(t,e,n,i){let s=0;for(let r=e,a=n-i;r0)for(r=e;r=e;r-=i)a=Zh(r,t[r],t[r+1],a);return a&&Gh(a,a.next)&&($h(a),a=a.next),a}function Ch(t,e){if(!t)return t;e||(e=t);let n,i=t;do{if(n=!1,i.steiner||!Gh(i,i.next)&&0!==Hh(i.prev,i,i.next))i=i.next;else{if($h(i),i=e=i.prev,i===i.next)break;n=!0}}while(n||i!==e);return e}function Rh(t,e,n,i,s,r,a){if(!t)return;!a&&r&&function(t,e,n,i){let s=t;do{0===s.z&&(s.z=Vh(s.x,s.y,e,n,i)),s.prevZ=s.prev,s.nextZ=s.next,s=s.next}while(s!==t);s.prevZ.nextZ=null,s.prevZ=null,function(t){let e,n,i,s,r,a,o,l,c=1;do{for(n=t,t=null,r=null,a=0;n;){for(a++,i=n,o=0,e=0;e0||l>0&&i;)0!==o&&(0===l||!i||n.z<=i.z)?(s=n,n=n.nextZ,o--):(s=i,i=i.nextZ,l--),r?r.nextZ=s:t=s,s.prevZ=r,r=s;n=i}r.nextZ=null,c*=2}while(a>1)}(s)}(t,i,s,r);let o,l,c=t;for(;t.prev!==t.next;)if(o=t.prev,l=t.next,r?Lh(t,i,s,r):Ih(t))e.push(o.i/n|0),e.push(t.i/n|0),e.push(l.i/n|0),$h(t),t=l.next,c=l.next;else if((t=l)===c){a?1===a?Rh(t=Ph(Ch(t),e,n),e,n,i,s,r,2):2===a&&Uh(t,e,n,i,s,r):Rh(Ch(t),e,n,i,s,r,1);break}}function Ih(t){const e=t.prev,n=t,i=t.next;if(Hh(e,n,i)>=0)return!1;const s=e.x,r=n.x,a=i.x,o=e.y,l=n.y,c=i.y,u=sr?s>a?s:a:r>a?r:a,p=o>l?o>c?o:c:l>c?l:c;let m=i.next;for(;m!==e;){if(m.x>=u&&m.x<=d&&m.y>=h&&m.y<=p&&Bh(s,o,r,l,a,c,m.x,m.y)&&Hh(m.prev,m,m.next)>=0)return!1;m=m.next}return!0}function Lh(t,e,n,i){const s=t.prev,r=t,a=t.next;if(Hh(s,r,a)>=0)return!1;const o=s.x,l=r.x,c=a.x,u=s.y,h=r.y,d=a.y,p=ol?o>c?o:c:l>c?l:c,g=u>h?u>d?u:d:h>d?h:d,v=Vh(p,m,e,n,i),y=Vh(f,g,e,n,i);let _=t.prevZ,x=t.nextZ;for(;_&&_.z>=v&&x&&x.z<=y;){if(_.x>=p&&_.x<=f&&_.y>=m&&_.y<=g&&_!==s&&_!==a&&Bh(o,u,l,h,c,d,_.x,_.y)&&Hh(_.prev,_,_.next)>=0)return!1;if(_=_.prevZ,x.x>=p&&x.x<=f&&x.y>=m&&x.y<=g&&x!==s&&x!==a&&Bh(o,u,l,h,c,d,x.x,x.y)&&Hh(x.prev,x,x.next)>=0)return!1;x=x.nextZ}for(;_&&_.z>=v;){if(_.x>=p&&_.x<=f&&_.y>=m&&_.y<=g&&_!==s&&_!==a&&Bh(o,u,l,h,c,d,_.x,_.y)&&Hh(_.prev,_,_.next)>=0)return!1;_=_.prevZ}for(;x&&x.z<=y;){if(x.x>=p&&x.x<=f&&x.y>=m&&x.y<=g&&x!==s&&x!==a&&Bh(o,u,l,h,c,d,x.x,x.y)&&Hh(x.prev,x,x.next)>=0)return!1;x=x.nextZ}return!0}function Ph(t,e,n){let i=t;do{const s=i.prev,r=i.next.next;!Gh(s,r)&&Wh(s,i,i.next,r)&&qh(s,r)&&qh(r,s)&&(e.push(s.i/n|0),e.push(i.i/n|0),e.push(r.i/n|0),$h(i),$h(i.next),i=t=r),i=i.next}while(i!==t);return Ch(i)}function Uh(t,e,n,i,s,r){let a=t;do{let t=a.next.next;for(;t!==a.prev;){if(a.i!==t.i&&kh(a,t)){let o=Yh(a,t);return a=Ch(a,a.next),o=Ch(o,o.next),Rh(a,e,n,i,s,r,0),void Rh(o,e,n,i,s,r,0)}t=t.next}a=a.next}while(a!==t)}function Dh(t,e){return t.x-e.x}function Oh(t,e){const n=function(t,e){let n,i=e,s=-1/0;const r=t.x,a=t.y;do{if(a<=i.y&&a>=i.next.y&&i.next.y!==i.y){const t=i.x+(a-i.y)*(i.next.x-i.x)/(i.next.y-i.y);if(t<=r&&t>s&&(s=t,n=i.x=i.x&&i.x>=l&&r!==i.x&&Bh(an.x||i.x===n.x&&zh(n,i)))&&(n=i,h=u)),i=i.next}while(i!==o);return n}(t,e);if(!n)return e;const i=Yh(n,t);return Ch(i,i.next),Ch(n,n.next)}function zh(t,e){return Hh(t.prev,t,e.prev)<0&&Hh(e.next,t,t.next)<0}function Vh(t,e,n,i,s){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-n)*s|0)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=(e-i)*s|0)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function Fh(t){let e=t,n=t;do{(e.x=(t-a)*(r-o)&&(t-a)*(i-o)>=(n-a)*(e-o)&&(n-a)*(r-o)>=(s-a)*(i-o)}function kh(t,e){return t.next.i!==e.i&&t.prev.i!==e.i&&!function(t,e){let n=t;do{if(n.i!==t.i&&n.next.i!==t.i&&n.i!==e.i&&n.next.i!==e.i&&Wh(n,n.next,t,e))return!0;n=n.next}while(n!==t);return!1}(t,e)&&(qh(t,e)&&qh(e,t)&&function(t,e){let n=t,i=!1;const s=(t.x+e.x)/2,r=(t.y+e.y)/2;do{n.y>r!=n.next.y>r&&n.next.y!==n.y&&s<(n.next.x-n.x)*(r-n.y)/(n.next.y-n.y)+n.x&&(i=!i),n=n.next}while(n!==t);return i}(t,e)&&(Hh(t.prev,t,e.prev)||Hh(t,e.prev,e))||Gh(t,e)&&Hh(t.prev,t,t.next)>0&&Hh(e.prev,e,e.next)>0)}function Hh(t,e,n){return(e.y-t.y)*(n.x-e.x)-(e.x-t.x)*(n.y-e.y)}function Gh(t,e){return t.x===e.x&&t.y===e.y}function Wh(t,e,n,i){const s=Xh(Hh(t,e,n)),r=Xh(Hh(t,e,i)),a=Xh(Hh(n,i,t)),o=Xh(Hh(n,i,e));return s!==r&&a!==o||(!(0!==s||!jh(t,n,e))||(!(0!==r||!jh(t,i,e))||(!(0!==a||!jh(n,t,i))||!(0!==o||!jh(n,e,i)))))}function jh(t,e,n){return e.x<=Math.max(t.x,n.x)&&e.x>=Math.min(t.x,n.x)&&e.y<=Math.max(t.y,n.y)&&e.y>=Math.min(t.y,n.y)}function Xh(t){return t>0?1:t<0?-1:0}function qh(t,e){return Hh(t.prev,t,t.next)<0?Hh(t,e,t.next)>=0&&Hh(t,t.prev,e)>=0:Hh(t,e,t.prev)<0||Hh(t,t.next,e)<0}function Yh(t,e){const n=new Jh(t.i,t.x,t.y),i=new Jh(e.i,e.x,e.y),s=t.next,r=e.prev;return t.next=e,e.prev=t,n.next=s,s.prev=n,i.next=n,n.prev=i,r.next=i,i.prev=r,i}function Zh(t,e,n,i){const s=new Jh(t,e,n);return i?(s.next=i.next,s.prev=i,i.next.prev=s,i.next=s):(s.prev=s,s.next=s),s}function $h(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function Jh(t,e,n){this.i=t,this.x=e,this.y=n,this.prev=null,this.next=null,this.z=0,this.prevZ=null,this.nextZ=null,this.steiner=!1}class Kh{static area(t){const e=t.length;let n=0;for(let i=e-1,s=0;s2&&t[e-1].equals(t[0])&&t.pop()}function td(t,e){for(let n=0;nNumber.EPSILON){const h=Math.sqrt(u),d=Math.sqrt(l*l+c*c),p=e.x-o/h,m=e.y+a/h,f=((n.x-c/d-p)*c-(n.y+l/d-m)*l)/(a*c-o*l);i=p+a*f-t.x,s=m+o*f-t.y;const g=i*i+s*s;if(g<=2)return new ti(i,s);r=Math.sqrt(g/2)}else{let t=!1;a>Number.EPSILON?l>Number.EPSILON&&(t=!0):a<-Number.EPSILON?l<-Number.EPSILON&&(t=!0):Math.sign(o)===Math.sign(c)&&(t=!0),t?(i=-o,s=a,r=Math.sqrt(u)):(i=a,s=o,r=Math.sqrt(u/2))}return new ti(i/r,s/r)}const I=[];for(let t=0,e=E.length,n=e-1,i=t+1;t=0;t--){const e=t/p,n=u*Math.cos(e*Math.PI/2),i=h*Math.sin(e*Math.PI/2)+d;for(let t=0,e=E.length;t=0;){const i=n;let s=n-1;s<0&&(s=t.length-1);for(let t=0,n=o+2*p;t0)&&d.push(e,s,l),(t!==n-1||o0!=t>0&&this.version++,this._anisotropy=t}get clearcoat(){return this._clearcoat}set clearcoat(t){this._clearcoat>0!=t>0&&this.version++,this._clearcoat=t}get iridescence(){return this._iridescence}set iridescence(t){this._iridescence>0!=t>0&&this.version++,this._iridescence=t}get dispersion(){return this._dispersion}set dispersion(t){this._dispersion>0!=t>0&&this.version++,this._dispersion=t}get sheen(){return this._sheen}set sheen(t){this._sheen>0!=t>0&&this.version++,this._sheen=t}get transmission(){return this._transmission}set transmission(t){this._transmission>0!=t>0&&this.version++,this._transmission=t}copy(t){return super.copy(t),this.defines={STANDARD:"",PHYSICAL:""},this.anisotropy=t.anisotropy,this.anisotropyRotation=t.anisotropyRotation,this.anisotropyMap=t.anisotropyMap,this.clearcoat=t.clearcoat,this.clearcoatMap=t.clearcoatMap,this.clearcoatRoughness=t.clearcoatRoughness,this.clearcoatRoughnessMap=t.clearcoatRoughnessMap,this.clearcoatNormalMap=t.clearcoatNormalMap,this.clearcoatNormalScale.copy(t.clearcoatNormalScale),this.dispersion=t.dispersion,this.ior=t.ior,this.iridescence=t.iridescence,this.iridescenceMap=t.iridescenceMap,this.iridescenceIOR=t.iridescenceIOR,this.iridescenceThicknessRange=[...t.iridescenceThicknessRange],this.iridescenceThicknessMap=t.iridescenceThicknessMap,this.sheen=t.sheen,this.sheenColor.copy(t.sheenColor),this.sheenColorMap=t.sheenColorMap,this.sheenRoughness=t.sheenRoughness,this.sheenRoughnessMap=t.sheenRoughnessMap,this.transmission=t.transmission,this.transmissionMap=t.transmissionMap,this.thickness=t.thickness,this.thicknessMap=t.thicknessMap,this.attenuationDistance=t.attenuationDistance,this.attenuationColor.copy(t.attenuationColor),this.specularIntensity=t.specularIntensity,this.specularIntensityMap=t.specularIntensityMap,this.specularColor.copy(t.specularColor),this.specularColorMap=t.specularColorMap,this}}class _d extends ir{constructor(t){super(),this.isMeshPhongMaterial=!0,this.type="MeshPhongMaterial",this.color=new tr(16777215),this.specular=new tr(1118481),this.shininess=30,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new tr(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new ti(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new ys,this.combine=0,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.specular.copy(t.specular),this.shininess=t.shininess,this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapRotation.copy(t.envMapRotation),this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.flatShading=t.flatShading,this.fog=t.fog,this}}class xd extends ir{constructor(t){super(),this.isMeshToonMaterial=!0,this.defines={TOON:""},this.type="MeshToonMaterial",this.color=new tr(16777215),this.map=null,this.gradientMap=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new tr(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new ti(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(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.gradientMap=t.gradientMap,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.alphaMap=t.alphaMap,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.fog=t.fog,this}}class Md extends ir{constructor(t){super(),this.isMeshNormalMaterial=!0,this.type="MeshNormalMaterial",this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new ti(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.flatShading=!1,this.setValues(t)}copy(t){return super.copy(t),this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.flatShading=t.flatShading,this}}class bd extends ir{constructor(t){super(),this.isMeshLambertMaterial=!0,this.type="MeshLambertMaterial",this.color=new tr(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new tr(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new ti(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new ys,this.combine=0,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapRotation.copy(t.envMapRotation),this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.flatShading=t.flatShading,this.fog=t.fog,this}}class Td extends ir{constructor(t){super(),this.isMeshMatcapMaterial=!0,this.defines={MATCAP:""},this.type="MeshMatcapMaterial",this.color=new tr(16777215),this.matcap=null,this.map=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new ti(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.alphaMap=null,this.flatShading=!1,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.defines={MATCAP:""},this.color.copy(t.color),this.matcap=t.matcap,this.map=t.map,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.alphaMap=t.alphaMap,this.flatShading=t.flatShading,this.fog=t.fog,this}}class Sd extends _u{constructor(t){super(),this.isLineDashedMaterial=!0,this.type="LineDashedMaterial",this.scale=1,this.dashSize=3,this.gapSize=1,this.setValues(t)}copy(t){return super.copy(t),this.scale=t.scale,this.dashSize=t.dashSize,this.gapSize=t.gapSize,this}}function wd(t,e,n){return!t||!n&&t.constructor===e?t:"number"==typeof e.BYTES_PER_ELEMENT?new e(t):Array.prototype.slice.call(t)}function Ed(t){return ArrayBuffer.isView(t)&&!(t instanceof DataView)}function Ad(t){const e=t.length,n=new Array(e);for(let t=0;t!==e;++t)n[t]=t;return n.sort((function(e,n){return t[e]-t[n]})),n}function Nd(t,e,n){const i=t.length,s=new t.constructor(i);for(let r=0,a=0;a!==i;++r){const i=n[r]*e;for(let n=0;n!==e;++n)s[a++]=t[i+n]}return s}function Cd(t,e,n,i){let s=1,r=t[0];for(;void 0!==r&&void 0===r[i];)r=t[s++];if(void 0===r)return;let a=r[i];if(void 0!==a)if(Array.isArray(a))do{a=r[i],void 0!==a&&(e.push(r.time),n.push.apply(n,a)),r=t[s++]}while(void 0!==r);else if(void 0!==a.toArray)do{a=r[i],void 0!==a&&(e.push(r.time),a.toArray(n,n.length)),r=t[s++]}while(void 0!==r);else do{a=r[i],void 0!==a&&(e.push(r.time),n.push(a)),r=t[s++]}while(void 0!==r)}const Rd={convertArray:wd,isTypedArray:Ed,getKeyframeOrder:Ad,sortedArray:Nd,flattenJSON:Cd,subclip:function(t,e,n,i,s=30){const r=t.clone();r.name=e;const a=[];for(let t=0;t=i)){l.push(e.times[t]);for(let n=0;nr.tracks[t].times[0]&&(o=r.tracks[t].times[0]);for(let t=0;t=i.times[h]){const t=h*l+o,e=t+l-o;d=i.values.slice(t,e)}else{const t=i.createInterpolant(),e=o,n=l-o;t.evaluate(r),d=t.resultBuffer.slice(e,n)}if("quaternion"===s){(new Ii).fromArray(d).normalize().conjugate().toArray(d)}const p=a.times.length;for(let t=0;t=s)break t;{const a=e[1];t=s)break e}r=n,n=0}}for(;n>>1;te;)--r;if(++r,0!==s||r!==i){s>=r&&(r=Math.max(r,1),s=r-1);const t=this.getValueSize();this.times=n.slice(s,r),this.values=this.values.slice(s*t,r*t)}return this}validate(){let t=!0;const e=this.getValueSize();e-Math.floor(e)!=0&&(console.error("THREE.KeyframeTrack: Invalid value size in track.",this),t=!1);const n=this.times,i=this.values,s=n.length;0===s&&(console.error("THREE.KeyframeTrack: Track is empty.",this),t=!1);let r=null;for(let e=0;e!==s;e++){const i=n[e];if("number"==typeof i&&isNaN(i)){console.error("THREE.KeyframeTrack: Time is not a valid number.",this,e,i),t=!1;break}if(null!==r&&r>i){console.error("THREE.KeyframeTrack: Out of order keys.",this,e,i,r),t=!1;break}r=i}if(void 0!==i&&Ed(i))for(let e=0,n=i.length;e!==n;++e){const n=i[e];if(isNaN(n)){console.error("THREE.KeyframeTrack: Value is not a valid number.",this,e,n),t=!1;break}}return t}optimize(){const t=this.times.slice(),e=this.values.slice(),n=this.getValueSize(),i=this.getInterpolation()===Ue,s=t.length-1;let r=1;for(let a=1;a0){t[r]=t[s];for(let t=s*n,i=r*n,a=0;a!==n;++a)e[i+a]=e[t+a];++r}return r!==t.length?(this.times=t.slice(0,r),this.values=e.slice(0,r*n)):(this.times=t,this.values=e),this}clone(){const t=this.times.slice(),e=this.values.slice(),n=new(0,this.constructor)(this.name,t,e);return n.createInterpolant=this.createInterpolant,n}}Dd.prototype.TimeBufferType=Float32Array,Dd.prototype.ValueBufferType=Float32Array,Dd.prototype.DefaultInterpolation=Pe;class Od extends Dd{constructor(t,e,n){super(t,e,n)}}Od.prototype.ValueTypeName="bool",Od.prototype.ValueBufferType=Array,Od.prototype.DefaultInterpolation=Le,Od.prototype.InterpolantFactoryMethodLinear=void 0,Od.prototype.InterpolantFactoryMethodSmooth=void 0;class zd extends Dd{}zd.prototype.ValueTypeName="color";class Vd extends Dd{}Vd.prototype.ValueTypeName="number";class Fd extends Id{constructor(t,e,n,i){super(t,e,n,i)}interpolate_(t,e,n,i){const s=this.resultBuffer,r=this.sampleValues,a=this.valueSize,o=(n-e)/(i-e);let l=t*a;for(let t=l+a;l!==t;l+=4)Ii.slerpFlat(s,0,r,l-a,r,l,o);return s}}class Bd extends Dd{InterpolantFactoryMethodLinear(t){return new Fd(this.times,this.values,this.getValueSize(),t)}}Bd.prototype.ValueTypeName="quaternion",Bd.prototype.InterpolantFactoryMethodSmooth=void 0;class kd extends Dd{constructor(t,e,n){super(t,e,n)}}kd.prototype.ValueTypeName="string",kd.prototype.ValueBufferType=Array,kd.prototype.DefaultInterpolation=Le,kd.prototype.InterpolantFactoryMethodLinear=void 0,kd.prototype.InterpolantFactoryMethodSmooth=void 0;class Hd extends Dd{}Hd.prototype.ValueTypeName="vector";class Gd{constructor(t="",e=-1,n=[],i=2500){this.name=t,this.tracks=n,this.duration=e,this.blendMode=i,this.uuid=qn(),this.duration<0&&this.resetDuration()}static parse(t){const e=[],n=t.tracks,i=1/(t.fps||1);for(let t=0,s=n.length;t!==s;++t)e.push(Wd(n[t]).scale(i));const s=new this(t.name,t.duration,e,t.blendMode);return s.uuid=t.uuid,s}static toJSON(t){const e=[],n=t.tracks,i={name:t.name,duration:t.duration,tracks:e,uuid:t.uuid,blendMode:t.blendMode};for(let t=0,i=n.length;t!==i;++t)e.push(Dd.toJSON(n[t]));return i}static CreateFromMorphTargetSequence(t,e,n,i){const s=e.length,r=[];for(let t=0;t1){const t=r[1];let e=i[t];e||(i[t]=e=[]),e.push(n)}}const r=[];for(const t in i)r.push(this.CreateFromMorphTargetSequence(t,i[t],e,n));return r}static parseAnimation(t,e){if(!t)return console.error("THREE.AnimationClip: No animation in JSONLoader data."),null;const n=function(t,e,n,i,s){if(0!==n.length){const r=[],a=[];Cd(n,r,a,i),0!==r.length&&s.push(new t(e,r,a))}},i=[],s=t.name||"default",r=t.fps||30,a=t.blendMode;let o=t.length||-1;const l=t.hierarchy||[];for(let t=0;t{e&&e(s),this.manager.itemEnd(t)}),0),s;if(void 0!==Zd[t])return void Zd[t].push({onLoad:e,onProgress:n,onError:i});Zd[t]=[],Zd[t].push({onLoad:e,onProgress:n,onError:i});const r=new Request(t,{headers:new Headers(this.requestHeader),credentials:this.withCredentials?"include":"same-origin"}),a=this.mimeType,o=this.responseType;fetch(r).then((e=>{if(200===e.status||0===e.status){if(0===e.status&&console.warn("THREE.FileLoader: HTTP Status 0 received."),"undefined"==typeof ReadableStream||void 0===e.body||void 0===e.body.getReader)return e;const n=Zd[t],i=e.body.getReader(),s=e.headers.get("X-File-Size")||e.headers.get("Content-Length"),r=s?parseInt(s):0,a=0!==r;let o=0;const l=new ReadableStream({start(t){!function e(){i.read().then((({done:i,value:s})=>{if(i)t.close();else{o+=s.byteLength;const i=new ProgressEvent("progress",{lengthComputable:a,loaded:o,total:r});for(let t=0,e=n.length;t{t.error(e)}))}()}});return new Response(l)}throw new $d(`fetch for "${e.url}" responded with ${e.status}: ${e.statusText}`,e)})).then((t=>{switch(o){case"arraybuffer":return t.arrayBuffer();case"blob":return t.blob();case"document":return t.text().then((t=>(new DOMParser).parseFromString(t,a)));case"json":return t.json();default:if(void 0===a)return t.text();{const e=/charset="?([^;"\s]*)"?/i.exec(a),n=e&&e[1]?e[1].toLowerCase():void 0,i=new TextDecoder(n);return t.arrayBuffer().then((t=>i.decode(t)))}}})).then((e=>{jd.add(t,e);const n=Zd[t];delete Zd[t];for(let t=0,i=n.length;t{const n=Zd[t];if(void 0===n)throw this.manager.itemError(t),e;delete Zd[t];for(let t=0,i=n.length;t{this.manager.itemEnd(t)})),this.manager.itemStart(t)}setResponseType(t){return this.responseType=t,this}setMimeType(t){return this.mimeType=t,this}}class Kd extends Yd{constructor(t){super(t)}load(t,e,n,i){const s=this,r=new Jd(this.manager);r.setPath(this.path),r.setRequestHeader(this.requestHeader),r.setWithCredentials(this.withCredentials),r.load(t,(function(n){try{e(s.parse(JSON.parse(n)))}catch(e){i?i(e):console.error(e),s.manager.itemError(t)}}),n,i)}parse(t){const e=[];for(let n=0;n0:i.vertexColors=t.vertexColors),void 0!==t.uniforms)for(const e in t.uniforms){const s=t.uniforms[e];switch(i.uniforms[e]={},s.type){case"t":i.uniforms[e].value=n(s.value);break;case"c":i.uniforms[e].value=(new tr).setHex(s.value);break;case"v2":i.uniforms[e].value=(new ti).fromArray(s.value);break;case"v3":i.uniforms[e].value=(new Li).fromArray(s.value);break;case"v4":i.uniforms[e].value=(new Si).fromArray(s.value);break;case"m3":i.uniforms[e].value=(new ei).fromArray(s.value);break;case"m4":i.uniforms[e].value=(new ls).fromArray(s.value);break;default:i.uniforms[e].value=s.value}}if(void 0!==t.defines&&(i.defines=t.defines),void 0!==t.vertexShader&&(i.vertexShader=t.vertexShader),void 0!==t.fragmentShader&&(i.fragmentShader=t.fragmentShader),void 0!==t.glslVersion&&(i.glslVersion=t.glslVersion),void 0!==t.extensions)for(const e in t.extensions)i.extensions[e]=t.extensions[e];if(void 0!==t.lights&&(i.lights=t.lights),void 0!==t.clipping&&(i.clipping=t.clipping),void 0!==t.size&&(i.size=t.size),void 0!==t.sizeAttenuation&&(i.sizeAttenuation=t.sizeAttenuation),void 0!==t.map&&(i.map=n(t.map)),void 0!==t.matcap&&(i.matcap=n(t.matcap)),void 0!==t.alphaMap&&(i.alphaMap=n(t.alphaMap)),void 0!==t.bumpMap&&(i.bumpMap=n(t.bumpMap)),void 0!==t.bumpScale&&(i.bumpScale=t.bumpScale),void 0!==t.normalMap&&(i.normalMap=n(t.normalMap)),void 0!==t.normalMapType&&(i.normalMapType=t.normalMapType),void 0!==t.normalScale){let e=t.normalScale;!1===Array.isArray(e)&&(e=[e,e]),i.normalScale=(new ti).fromArray(e)}return void 0!==t.displacementMap&&(i.displacementMap=n(t.displacementMap)),void 0!==t.displacementScale&&(i.displacementScale=t.displacementScale),void 0!==t.displacementBias&&(i.displacementBias=t.displacementBias),void 0!==t.roughnessMap&&(i.roughnessMap=n(t.roughnessMap)),void 0!==t.metalnessMap&&(i.metalnessMap=n(t.metalnessMap)),void 0!==t.emissiveMap&&(i.emissiveMap=n(t.emissiveMap)),void 0!==t.emissiveIntensity&&(i.emissiveIntensity=t.emissiveIntensity),void 0!==t.specularMap&&(i.specularMap=n(t.specularMap)),void 0!==t.specularIntensityMap&&(i.specularIntensityMap=n(t.specularIntensityMap)),void 0!==t.specularColorMap&&(i.specularColorMap=n(t.specularColorMap)),void 0!==t.envMap&&(i.envMap=n(t.envMap)),void 0!==t.envMapRotation&&i.envMapRotation.fromArray(t.envMapRotation),void 0!==t.envMapIntensity&&(i.envMapIntensity=t.envMapIntensity),void 0!==t.reflectivity&&(i.reflectivity=t.reflectivity),void 0!==t.refractionRatio&&(i.refractionRatio=t.refractionRatio),void 0!==t.lightMap&&(i.lightMap=n(t.lightMap)),void 0!==t.lightMapIntensity&&(i.lightMapIntensity=t.lightMapIntensity),void 0!==t.aoMap&&(i.aoMap=n(t.aoMap)),void 0!==t.aoMapIntensity&&(i.aoMapIntensity=t.aoMapIntensity),void 0!==t.gradientMap&&(i.gradientMap=n(t.gradientMap)),void 0!==t.clearcoatMap&&(i.clearcoatMap=n(t.clearcoatMap)),void 0!==t.clearcoatRoughnessMap&&(i.clearcoatRoughnessMap=n(t.clearcoatRoughnessMap)),void 0!==t.clearcoatNormalMap&&(i.clearcoatNormalMap=n(t.clearcoatNormalMap)),void 0!==t.clearcoatNormalScale&&(i.clearcoatNormalScale=(new ti).fromArray(t.clearcoatNormalScale)),void 0!==t.iridescenceMap&&(i.iridescenceMap=n(t.iridescenceMap)),void 0!==t.iridescenceThicknessMap&&(i.iridescenceThicknessMap=n(t.iridescenceThicknessMap)),void 0!==t.transmissionMap&&(i.transmissionMap=n(t.transmissionMap)),void 0!==t.thicknessMap&&(i.thicknessMap=n(t.thicknessMap)),void 0!==t.anisotropyMap&&(i.anisotropyMap=n(t.anisotropyMap)),void 0!==t.sheenColorMap&&(i.sheenColorMap=n(t.sheenColorMap)),void 0!==t.sheenRoughnessMap&&(i.sheenRoughnessMap=n(t.sheenRoughnessMap)),i}setTextures(t){return this.textures=t,this}createMaterialFromType(t){return Tp.createMaterialFromType(t)}static createMaterialFromType(t){return new{ShadowMaterial:fd,SpriteMaterial:hc,RawShaderMaterial:gd,ShaderMaterial:Yr,PointsMaterial:Pu,MeshPhysicalMaterial:yd,MeshStandardMaterial:vd,MeshPhongMaterial:_d,MeshToonMaterial:xd,MeshNormalMaterial:Md,MeshLambertMaterial:bd,MeshDepthMaterial:Fl,MeshDistanceMaterial:Bl,MeshBasicMaterial:sr,MeshMatcapMaterial:Td,LineDashedMaterial:Sd,LineBasicMaterial:_u,Material:ir}[t]}}class Sp{static decodeText(t){if(console.warn("THREE.LoaderUtils: decodeText() has been deprecated with r165 and will be removed with r175. Use TextDecoder instead."),"undefined"!=typeof TextDecoder)return(new TextDecoder).decode(t);let e="";for(let n=0,i=t.length;n0){const n=new Xd(e);s=new tp(n),s.setCrossOrigin(this.crossOrigin);for(let e=0,n=t.length;e0){i=new tp(this.manager),i.setCrossOrigin(this.crossOrigin);for(let e=0,i=t.length;e{const e=new Di;e.min.fromArray(t.boxMin),e.max.fromArray(t.boxMax);const n=new Qi;return n.radius=t.sphereRadius,n.center.fromArray(t.sphereCenter),{boxInitialized:t.boxInitialized,box:e,sphereInitialized:t.sphereInitialized,sphere:n}})),r._maxInstanceCount=t.maxInstanceCount,r._maxVertexCount=t.maxVertexCount,r._maxIndexCount=t.maxIndexCount,r._geometryInitialized=t.geometryInitialized,r._geometryCount=t.geometryCount,r._matricesTexture=u(t.matricesTexture.uuid),void 0!==t.colorsTexture&&(r._colorsTexture=u(t.colorsTexture.uuid));break;case"LOD":r=new Cc;break;case"Line":r=new Au(l(t.geometry),c(t.material));break;case"LineLoop":r=new Lu(l(t.geometry),c(t.material));break;case"LineSegments":r=new Iu(l(t.geometry),c(t.material));break;case"PointCloud":case"Points":r=new Vu(l(t.geometry),c(t.material));break;case"Sprite":r=new wc(c(t.material));break;case"Group":r=new Zl;break;case"Bone":r=new Bc;break;default:r=new Ds}if(r.uuid=t.uuid,void 0!==t.name&&(r.name=t.name),void 0!==t.matrix?(r.matrix.fromArray(t.matrix),void 0!==t.matrixAutoUpdate&&(r.matrixAutoUpdate=t.matrixAutoUpdate),r.matrixAutoUpdate&&r.matrix.decompose(r.position,r.quaternion,r.scale)):(void 0!==t.position&&r.position.fromArray(t.position),void 0!==t.rotation&&r.rotation.fromArray(t.rotation),void 0!==t.quaternion&&r.quaternion.fromArray(t.quaternion),void 0!==t.scale&&r.scale.fromArray(t.scale)),void 0!==t.up&&r.up.fromArray(t.up),void 0!==t.castShadow&&(r.castShadow=t.castShadow),void 0!==t.receiveShadow&&(r.receiveShadow=t.receiveShadow),t.shadow&&(void 0!==t.shadow.intensity&&(r.shadow.intensity=t.shadow.intensity),void 0!==t.shadow.bias&&(r.shadow.bias=t.shadow.bias),void 0!==t.shadow.normalBias&&(r.shadow.normalBias=t.shadow.normalBias),void 0!==t.shadow.radius&&(r.shadow.radius=t.shadow.radius),void 0!==t.shadow.mapSize&&r.shadow.mapSize.fromArray(t.shadow.mapSize),void 0!==t.shadow.camera&&(r.shadow.camera=this.parseObject(t.shadow.camera))),void 0!==t.visible&&(r.visible=t.visible),void 0!==t.frustumCulled&&(r.frustumCulled=t.frustumCulled),void 0!==t.renderOrder&&(r.renderOrder=t.renderOrder),void 0!==t.userData&&(r.userData=t.userData),void 0!==t.layers&&(r.layers.mask=t.layers),void 0!==t.children){const a=t.children;for(let t=0;t{e&&e(n),s.manager.itemEnd(t)})).catch((t=>{i&&i(t)})):(setTimeout((function(){e&&e(r),s.manager.itemEnd(t)}),0),r);const a={};a.credentials="anonymous"===this.crossOrigin?"same-origin":"include",a.headers=this.requestHeader;const o=fetch(t,a).then((function(t){return t.blob()})).then((function(t){return createImageBitmap(t,Object.assign(s.options,{colorSpaceConversion:"none"}))})).then((function(n){return jd.add(t,n),e&&e(n),s.manager.itemEnd(t),n})).catch((function(e){i&&i(e),jd.remove(t),s.manager.itemError(t),s.manager.itemEnd(t)}));jd.add(t,o),s.manager.itemStart(t)}}let Lp;class Pp{static getContext(){return void 0===Lp&&(Lp=new(window.AudioContext||window.webkitAudioContext)),Lp}static setContext(t){Lp=t}}class Up extends Yd{constructor(t){super(t)}load(t,e,n,i){const s=this,r=new Jd(this.manager);function a(e){i?i(e):console.error(e),s.manager.itemError(t)}r.setResponseType("arraybuffer"),r.setPath(this.path),r.setRequestHeader(this.requestHeader),r.setWithCredentials(this.withCredentials),r.load(t,(function(t){try{const n=t.slice(0);Pp.getContext().decodeAudioData(n,(function(t){e(t)})).catch(a)}catch(t){a(t)}}),n,i)}}const Dp=new ls,Op=new ls,zp=new ls;class Vp{constructor(){this.type="StereoCamera",this.aspect=1,this.eyeSep=.064,this.cameraL=new Qr,this.cameraL.layers.enable(1),this.cameraL.matrixAutoUpdate=!1,this.cameraR=new Qr,this.cameraR.layers.enable(2),this.cameraR.matrixAutoUpdate=!1,this._cache={focus:null,fov:null,aspect:null,near:null,far:null,zoom:null,eyeSep:null}}update(t){const e=this._cache;if(e.focus!==t.focus||e.fov!==t.fov||e.aspect!==t.aspect*this.aspect||e.near!==t.near||e.far!==t.far||e.zoom!==t.zoom||e.eyeSep!==this.eyeSep){e.focus=t.focus,e.fov=t.fov,e.aspect=t.aspect*this.aspect,e.near=t.near,e.far=t.far,e.zoom=t.zoom,e.eyeSep=this.eyeSep,zp.copy(t.projectionMatrix);const n=e.eyeSep/2,i=n*e.near/e.focus,s=e.near*Math.tan(jn*e.fov*.5)/e.zoom;let r,a;Op.elements[12]=-n,Dp.elements[12]=n,r=-s*e.aspect+i,a=s*e.aspect+i,zp.elements[0]=2*e.near/(a-r),zp.elements[8]=(a+r)/(a-r),this.cameraL.projectionMatrix.copy(zp),r=-s*e.aspect-i,a=s*e.aspect-i,zp.elements[0]=2*e.near/(a-r),zp.elements[8]=(a+r)/(a-r),this.cameraR.projectionMatrix.copy(zp)}this.cameraL.matrixWorld.copy(t.matrixWorld).multiply(Op),this.cameraR.matrixWorld.copy(t.matrixWorld).multiply(Dp)}}class Fp{constructor(t=!0){this.autoStart=t,this.startTime=0,this.oldTime=0,this.elapsedTime=0,this.running=!1}start(){this.startTime=Bp(),this.oldTime=this.startTime,this.elapsedTime=0,this.running=!0}stop(){this.getElapsedTime(),this.running=!1,this.autoStart=!1}getElapsedTime(){return this.getDelta(),this.elapsedTime}getDelta(){let t=0;if(this.autoStart&&!this.running)return this.start(),0;if(this.running){const e=Bp();t=(e-this.oldTime)/1e3,this.oldTime=e,this.elapsedTime+=t}return t}}function Bp(){return performance.now()}const kp=new Li,Hp=new Ii,Gp=new Li,Wp=new Li;class jp extends Ds{constructor(){super(),this.type="AudioListener",this.context=Pp.getContext(),this.gain=this.context.createGain(),this.gain.connect(this.context.destination),this.filter=null,this.timeDelta=0,this._clock=new Fp}getInput(){return this.gain}removeFilter(){return null!==this.filter&&(this.gain.disconnect(this.filter),this.filter.disconnect(this.context.destination),this.gain.connect(this.context.destination),this.filter=null),this}getFilter(){return this.filter}setFilter(t){return null!==this.filter?(this.gain.disconnect(this.filter),this.filter.disconnect(this.context.destination)):this.gain.disconnect(this.context.destination),this.filter=t,this.gain.connect(this.filter),this.filter.connect(this.context.destination),this}getMasterVolume(){return this.gain.gain.value}setMasterVolume(t){return this.gain.gain.setTargetAtTime(t,this.context.currentTime,.01),this}updateMatrixWorld(t){super.updateMatrixWorld(t);const e=this.context.listener,n=this.up;if(this.timeDelta=this._clock.getDelta(),this.matrixWorld.decompose(kp,Hp,Gp),Number.isFinite(kp.x)&&Number.isFinite(kp.y)&&Number.isFinite(kp.z))if(Wp.set(0,0,-1).applyQuaternion(Hp),e.positionX){const t=this.context.currentTime+this.timeDelta;e.positionX.linearRampToValueAtTime(kp.x,t),e.positionY.linearRampToValueAtTime(kp.y,t),e.positionZ.linearRampToValueAtTime(kp.z,t),e.forwardX.linearRampToValueAtTime(Wp.x,t),e.forwardY.linearRampToValueAtTime(Wp.y,t),e.forwardZ.linearRampToValueAtTime(Wp.z,t),e.upX.linearRampToValueAtTime(n.x,t),e.upY.linearRampToValueAtTime(n.y,t),e.upZ.linearRampToValueAtTime(n.z,t)}else e.setPosition(kp.x,kp.y,kp.z),e.setOrientation(Wp.x,Wp.y,Wp.z,n.x,n.y,n.z)}}class Xp extends Ds{constructor(t){super(),this.type="Audio",this.listener=t,this.context=t.context,this.gain=this.context.createGain(),this.gain.connect(t.getInput()),this.autoplay=!1,this.buffer=null,this.detune=0,this.loop=!1,this.loopStart=0,this.loopEnd=0,this.offset=0,this.duration=void 0,this.playbackRate=1,this.isPlaying=!1,this.hasPlaybackControl=!0,this.source=null,this.sourceType="empty",this._startedAt=0,this._progress=0,this._connected=!1,this.filters=[]}getOutput(){return this.gain}setNodeSource(t){return this.hasPlaybackControl=!1,this.sourceType="audioNode",this.source=t,this.connect(),this}setMediaElementSource(t){return this.hasPlaybackControl=!1,this.sourceType="mediaNode",this.source=this.context.createMediaElementSource(t),this.connect(),this}setMediaStreamSource(t){return this.hasPlaybackControl=!1,this.sourceType="mediaStreamNode",this.source=this.context.createMediaStreamSource(t),this.connect(),this}setBuffer(t){return this.buffer=t,this.sourceType="buffer",this.autoplay&&this.play(),this}play(t=0){if(!0===this.isPlaying)return void console.warn("THREE.Audio: Audio is already playing.");if(!1===this.hasPlaybackControl)return void console.warn("THREE.Audio: this Audio has no playback control.");this._startedAt=this.context.currentTime+t;const e=this.context.createBufferSource();return e.buffer=this.buffer,e.loop=this.loop,e.loopStart=this.loopStart,e.loopEnd=this.loopEnd,e.onended=this.onEnded.bind(this),e.start(this._startedAt,this._progress+this.offset,this.duration),this.isPlaying=!0,this.source=e,this.setDetune(this.detune),this.setPlaybackRate(this.playbackRate),this.connect()}pause(){if(!1!==this.hasPlaybackControl)return!0===this.isPlaying&&(this._progress+=Math.max(this.context.currentTime-this._startedAt,0)*this.playbackRate,!0===this.loop&&(this._progress=this._progress%(this.duration||(this.buffer?this.buffer.duration:Number.MAX_VALUE))),this.source.stop(),this.source.onended=null,this.isPlaying=!1),this;console.warn("THREE.Audio: this Audio has no playback control.")}stop(t=0){if(!1!==this.hasPlaybackControl)return this._progress=0,null!==this.source&&(this.source.stop(this.context.currentTime+t),this.source.onended=null),this.isPlaying=!1,this;console.warn("THREE.Audio: this Audio has no playback control.")}connect(){if(this.filters.length>0){this.source.connect(this.filters[0]);for(let t=1,e=this.filters.length;t0){this.source.disconnect(this.filters[0]);for(let t=1,e=this.filters.length;t0&&this._mixBufferRegionAdditive(n,i,this._addIndex*e,1,e);for(let t=e,s=e+e;t!==s;++t)if(n[t]!==n[t+e]){a.setValue(n,i);break}}saveOriginalState(){const t=this.binding,e=this.buffer,n=this.valueSize,i=n*this._origIndex;t.getValue(e,i);for(let t=n,s=i;t!==s;++t)e[t]=e[i+t%n];this._setIdentity(),this.cumulativeWeight=0,this.cumulativeWeightAdditive=0}restoreOriginalState(){const t=3*this.valueSize;this.binding.setValue(this.buffer,t)}_setAdditiveIdentityNumeric(){const t=this._addIndex*this.valueSize,e=t+this.valueSize;for(let n=t;n=.5)for(let i=0;i!==s;++i)t[e+i]=t[n+i]}_slerp(t,e,n,i){Ii.slerpFlat(t,e,t,e,t,n,i)}_slerpAdditive(t,e,n,i,s){const r=this._workIndex*s;Ii.multiplyQuaternionsFlat(t,r,t,e,t,n),Ii.slerpFlat(t,e,t,e,t,r,i)}_lerp(t,e,n,i,s){const r=1-i;for(let a=0;a!==s;++a){const s=e+a;t[s]=t[s]*r+t[n+a]*i}}_lerpAdditive(t,e,n,i,s){for(let r=0;r!==s;++r){const s=e+r;t[s]=t[s]+t[n+r]*i}}}const tm="\\[\\]\\.:\\/",em=new RegExp("["+tm+"]","g"),nm="[^"+tm+"]",im="[^"+tm.replace("\\.","")+"]",sm=new RegExp("^"+/((?:WC+[\/:])*)/.source.replace("WC",nm)+/(WCOD+)?/.source.replace("WCOD",im)+/(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace("WC",nm)+/\.(WC+)(?:\[(.+)\])?/.source.replace("WC",nm)+"$"),rm=["material","materials","bones","map"];class am{constructor(t,e,n){this.path=e,this.parsedPath=n||am.parseTrackName(e),this.node=am.findNode(t,this.parsedPath.nodeName),this.rootNode=t,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}static create(t,e,n){return t&&t.isAnimationObjectGroup?new am.Composite(t,e,n):new am(t,e,n)}static sanitizeNodeName(t){return t.replace(/\s/g,"_").replace(em,"")}static parseTrackName(t){const e=sm.exec(t);if(null===e)throw new Error("PropertyBinding: Cannot parse trackName: "+t);const n={nodeName:e[2],objectName:e[3],objectIndex:e[4],propertyName:e[5],propertyIndex:e[6]},i=n.nodeName&&n.nodeName.lastIndexOf(".");if(void 0!==i&&-1!==i){const t=n.nodeName.substring(i+1);-1!==rm.indexOf(t)&&(n.nodeName=n.nodeName.substring(0,i),n.objectName=t)}if(null===n.propertyName||0===n.propertyName.length)throw new Error("PropertyBinding: can not parse propertyName from trackName: "+t);return n}static findNode(t,e){if(void 0===e||""===e||"."===e||-1===e||e===t.name||e===t.uuid)return t;if(t.skeleton){const n=t.skeleton.getBoneByName(e);if(void 0!==n)return n}if(t.children){const n=function(t,i){for(let s=0;s=s){const r=s++,c=t[r];e[c.uuid]=l,t[l]=c,e[o]=r,t[r]=a;for(let t=0,e=i;t!==e;++t){const e=n[t],i=e[r],s=e[l];e[l]=i,e[r]=s}}}this.nCachedObjects_=s}uncache(){const t=this._objects,e=this._indicesByUUID,n=this._bindings,i=n.length;let s=this.nCachedObjects_,r=t.length;for(let a=0,o=arguments.length;a!==o;++a){const o=arguments[a].uuid,l=e[o];if(void 0!==l)if(delete e[o],l0&&(e[a.uuid]=l),t[l]=a,t.pop();for(let t=0,e=i;t!==e;++t){const e=n[t];e[l]=e[s],e.pop()}}}this.nCachedObjects_=s}subscribe_(t,e){const n=this._bindingsIndicesByPath;let i=n[t];const s=this._bindings;if(void 0!==i)return s[i];const r=this._paths,a=this._parsedPaths,o=this._objects,l=o.length,c=this.nCachedObjects_,u=new Array(l);i=s.length,n[t]=i,r.push(t),a.push(e),s.push(u);for(let n=c,i=o.length;n!==i;++n){const i=o[n];u[n]=new am(i,t,e)}return u}unsubscribe_(t){const e=this._bindingsIndicesByPath,n=e[t];if(void 0!==n){const i=this._paths,s=this._parsedPaths,r=this._bindings,a=r.length-1,o=r[a];e[t[a]]=n,r[n]=o,r.pop(),s[n]=s[a],s.pop(),i[n]=i[a],i.pop()}}}class lm{constructor(t,e,n=null,i=e.blendMode){this._mixer=t,this._clip=e,this._localRoot=n,this.blendMode=i;const s=e.tracks,r=s.length,a=new Array(r),o={endingStart:De,endingEnd:De};for(let t=0;t!==r;++t){const e=s[t].createInterpolant(null);a[t]=e,e.settings=o}this._interpolantSettings=o,this._interpolants=a,this._propertyBindings=new Array(r),this._cacheIndex=null,this._byClipCacheIndex=null,this._timeScaleInterpolant=null,this._weightInterpolant=null,this.loop=2201,this._loopCount=-1,this._startTime=null,this.time=0,this.timeScale=1,this._effectiveTimeScale=1,this.weight=1,this._effectiveWeight=1,this.repetitions=1/0,this.paused=!1,this.enabled=!0,this.clampWhenFinished=!1,this.zeroSlopeAtStart=!0,this.zeroSlopeAtEnd=!0}play(){return this._mixer._activateAction(this),this}stop(){return this._mixer._deactivateAction(this),this.reset()}reset(){return this.paused=!1,this.enabled=!0,this.time=0,this._loopCount=-1,this._startTime=null,this.stopFading().stopWarping()}isRunning(){return this.enabled&&!this.paused&&0!==this.timeScale&&null===this._startTime&&this._mixer._isActiveAction(this)}isScheduled(){return this._mixer._isActiveAction(this)}startAt(t){return this._startTime=t,this}setLoop(t,e){return this.loop=t,this.repetitions=e,this}setEffectiveWeight(t){return this.weight=t,this._effectiveWeight=this.enabled?t:0,this.stopFading()}getEffectiveWeight(){return this._effectiveWeight}fadeIn(t){return this._scheduleFading(t,0,1)}fadeOut(t){return this._scheduleFading(t,1,0)}crossFadeFrom(t,e,n){if(t.fadeOut(e),this.fadeIn(e),n){const n=this._clip.duration,i=t._clip.duration,s=i/n,r=n/i;t.warp(1,s,e),this.warp(r,1,e)}return this}crossFadeTo(t,e,n){return t.crossFadeFrom(this,e,n)}stopFading(){const t=this._weightInterpolant;return null!==t&&(this._weightInterpolant=null,this._mixer._takeBackControlInterpolant(t)),this}setEffectiveTimeScale(t){return this.timeScale=t,this._effectiveTimeScale=this.paused?0:t,this.stopWarping()}getEffectiveTimeScale(){return this._effectiveTimeScale}setDuration(t){return this.timeScale=this._clip.duration/t,this.stopWarping()}syncWith(t){return this.time=t.time,this.timeScale=t.timeScale,this.stopWarping()}halt(t){return this.warp(this._effectiveTimeScale,0,t)}warp(t,e,n){const i=this._mixer,s=i.time,r=this.timeScale;let a=this._timeScaleInterpolant;null===a&&(a=i._lendControlInterpolant(),this._timeScaleInterpolant=a);const o=a.parameterPositions,l=a.sampleValues;return o[0]=s,o[1]=s+n,l[0]=t/r,l[1]=e/r,this}stopWarping(){const t=this._timeScaleInterpolant;return null!==t&&(this._timeScaleInterpolant=null,this._mixer._takeBackControlInterpolant(t)),this}getMixer(){return this._mixer}getClip(){return this._clip}getRoot(){return this._localRoot||this._mixer._root}_update(t,e,n,i){if(!this.enabled)return void this._updateWeight(t);const s=this._startTime;if(null!==s){const i=(t-s)*n;i<0||0===n?e=0:(this._startTime=null,e=n*i)}e*=this._updateTimeScale(t);const r=this._updateTime(e),a=this._updateWeight(t);if(a>0){const t=this._interpolants,e=this._propertyBindings;if(this.blendMode===Fe)for(let n=0,i=t.length;n!==i;++n)t[n].evaluate(r),e[n].accumulateAdditive(a);else for(let n=0,s=t.length;n!==s;++n)t[n].evaluate(r),e[n].accumulate(i,a)}}_updateWeight(t){let e=0;if(this.enabled){e=this.weight;const n=this._weightInterpolant;if(null!==n){const i=n.evaluate(t)[0];e*=i,t>n.parameterPositions[1]&&(this.stopFading(),0===i&&(this.enabled=!1))}}return this._effectiveWeight=e,e}_updateTimeScale(t){let e=0;if(!this.paused){e=this.timeScale;const n=this._timeScaleInterpolant;if(null!==n){e*=n.evaluate(t)[0],t>n.parameterPositions[1]&&(this.stopWarping(),0===e?this.paused=!0:this.timeScale=e)}}return this._effectiveTimeScale=e,e}_updateTime(t){const e=this._clip.duration,n=this.loop;let i=this.time+t,s=this._loopCount;const r=2202===n;if(0===t)return-1===s||!r||1&~s?i:e-i;if(2200===n){-1===s&&(this._loopCount=0,this._setEndings(!0,!0,!1));t:{if(i>=e)i=e;else{if(!(i<0)){this.time=i;break t}i=0}this.clampWhenFinished?this.paused=!0:this.enabled=!1,this.time=i,this._mixer.dispatchEvent({type:"finished",action:this,direction:t<0?-1:1})}}else{if(-1===s&&(t>=0?(s=0,this._setEndings(!0,0===this.repetitions,r)):this._setEndings(0===this.repetitions,!0,r)),i>=e||i<0){const n=Math.floor(i/e);i-=e*n,s+=Math.abs(n);const a=this.repetitions-s;if(a<=0)this.clampWhenFinished?this.paused=!0:this.enabled=!1,i=t>0?e:0,this.time=i,this._mixer.dispatchEvent({type:"finished",action:this,direction:t>0?1:-1});else{if(1===a){const e=t<0;this._setEndings(e,!e,r)}else this._setEndings(!1,!1,r);this._loopCount=s,this.time=i,this._mixer.dispatchEvent({type:"loop",action:this,loopDelta:n})}}else this.time=i;if(r&&!(1&~s))return e-i}return i}_setEndings(t,e,n){const i=this._interpolantSettings;n?(i.endingStart=Oe,i.endingEnd=Oe):(i.endingStart=t?this.zeroSlopeAtStart?Oe:De:ze,i.endingEnd=e?this.zeroSlopeAtEnd?Oe:De:ze)}_scheduleFading(t,e,n){const i=this._mixer,s=i.time;let r=this._weightInterpolant;null===r&&(r=i._lendControlInterpolant(),this._weightInterpolant=r);const a=r.parameterPositions,o=r.sampleValues;return a[0]=s,o[0]=e,a[1]=s+t,o[1]=n,this}}const cm=new Float32Array(1);class um extends Hn{constructor(t){super(),this._root=t,this._initMemoryManager(),this._accuIndex=0,this.time=0,this.timeScale=1}_bindAction(t,e){const n=t._localRoot||this._root,i=t._clip.tracks,s=i.length,r=t._propertyBindings,a=t._interpolants,o=n.uuid,l=this._bindingsByRootAndName;let c=l[o];void 0===c&&(c={},l[o]=c);for(let t=0;t!==s;++t){const s=i[t],l=s.name;let u=c[l];if(void 0!==u)++u.referenceCount,r[t]=u;else{if(u=r[t],void 0!==u){null===u._cacheIndex&&(++u.referenceCount,this._addInactiveBinding(u,o,l));continue}const i=e&&e._propertyBindings[t].binding.parsedPath;u=new Qp(am.create(n,l,i),s.ValueTypeName,s.getValueSize()),++u.referenceCount,this._addInactiveBinding(u,o,l),r[t]=u}a[t].resultBuffer=u.buffer}}_activateAction(t){if(!this._isActiveAction(t)){if(null===t._cacheIndex){const e=(t._localRoot||this._root).uuid,n=t._clip.uuid,i=this._actionsByClip[n];this._bindAction(t,i&&i.knownActions[0]),this._addInactiveAction(t,n,e)}const e=t._propertyBindings;for(let t=0,n=e.length;t!==n;++t){const n=e[t];0==n.useCount++&&(this._lendBinding(n),n.saveOriginalState())}this._lendAction(t)}}_deactivateAction(t){if(this._isActiveAction(t)){const e=t._propertyBindings;for(let t=0,n=e.length;t!==n;++t){const n=e[t];0==--n.useCount&&(n.restoreOriginalState(),this._takeBackBinding(n))}this._takeBackAction(t)}}_initMemoryManager(){this._actions=[],this._nActiveActions=0,this._actionsByClip={},this._bindings=[],this._nActiveBindings=0,this._bindingsByRootAndName={},this._controlInterpolants=[],this._nActiveControlInterpolants=0;const t=this;this.stats={actions:{get total(){return t._actions.length},get inUse(){return t._nActiveActions}},bindings:{get total(){return t._bindings.length},get inUse(){return t._nActiveBindings}},controlInterpolants:{get total(){return t._controlInterpolants.length},get inUse(){return t._nActiveControlInterpolants}}}}_isActiveAction(t){const e=t._cacheIndex;return null!==e&&e=0;--e)t[e].stop();return this}update(t){t*=this.timeScale;const e=this._actions,n=this._nActiveActions,i=this.time+=t,s=Math.sign(t),r=this._accuIndex^=1;for(let a=0;a!==n;++a){e[a]._update(i,t,s,r)}const a=this._bindings,o=this._nActiveBindings;for(let t=0;t!==o;++t)a[t].apply(r);return this}setTime(t){this.time=0;for(let t=0;t=this.min.x&&t.x<=this.max.x&&t.y>=this.min.y&&t.y<=this.max.y}containsBox(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y}getParameter(t,e){return e.set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y))}intersectsBox(t){return t.max.x>=this.min.x&&t.min.x<=this.max.x&&t.max.y>=this.min.y&&t.min.y<=this.max.y}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,Tm).distanceTo(t)}intersect(t){return this.min.max(t.min),this.max.min(t.max),this.isEmpty()&&this.makeEmpty(),this}union(t){return this.min.min(t.min),this.max.max(t.max),this}translate(t){return this.min.add(t),this.max.add(t),this}equals(t){return t.min.equals(this.min)&&t.max.equals(this.max)}}const wm=new Li,Em=new Li;class Am{constructor(t=new Li,e=new Li){this.start=t,this.end=e}set(t,e){return this.start.copy(t),this.end.copy(e),this}copy(t){return this.start.copy(t.start),this.end.copy(t.end),this}getCenter(t){return t.addVectors(this.start,this.end).multiplyScalar(.5)}delta(t){return t.subVectors(this.end,this.start)}distanceSq(){return this.start.distanceToSquared(this.end)}distance(){return this.start.distanceTo(this.end)}at(t,e){return this.delta(e).multiplyScalar(t).add(this.start)}closestPointToPointParameter(t,e){wm.subVectors(t,this.start),Em.subVectors(this.end,this.start);const n=Em.dot(Em);let i=Em.dot(wm)/n;return e&&(i=Yn(i,0,1)),i}closestPointToPoint(t,e,n){const i=this.closestPointToPointParameter(t,e);return this.delta(n).multiplyScalar(i).add(this.start)}applyMatrix4(t){return this.start.applyMatrix4(t),this.end.applyMatrix4(t),this}equals(t){return t.start.equals(this.start)&&t.end.equals(this.end)}clone(){return(new this.constructor).copy(this)}}const Nm=new Li;class Cm extends Ds{constructor(t,e){super(),this.light=t,this.matrixAutoUpdate=!1,this.color=e,this.type="SpotLightHelper";const n=new Cr,i=[0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,-1,0,1,0,0,0,0,1,1,0,0,0,0,-1,1];for(let t=0,e=1,n=32;t1)for(let n=0;n.99999)this.quaternion.set(0,0,0,1);else if(t.y<-.99999)this.quaternion.set(1,0,0,0);else{tf.set(t.z,0,-t.x).normalize();const e=Math.acos(t.y);this.quaternion.setFromAxisAngle(tf,e)}}setLength(t,e=.2*t,n=.2*e){this.line.scale.set(1,Math.max(1e-4,t-e),1),this.line.updateMatrix(),this.cone.scale.set(n,e,n),this.cone.position.y=t,this.cone.updateMatrix()}setColor(t){this.line.material.color.set(t),this.cone.material.color.set(t)}copy(t){return super.copy(t,!1),this.line.copy(t.line),this.cone.copy(t.cone),this}dispose(){this.line.geometry.dispose(),this.line.material.dispose(),this.cone.geometry.dispose(),this.cone.material.dispose()}}class rf extends Iu{constructor(t=1){const e=[0,0,0,t,0,0,0,0,0,0,t,0,0,0,0,0,0,t],n=new Cr;n.setAttribute("position",new Mr(e,3)),n.setAttribute("color",new Mr([1,0,0,1,.6,0,0,1,0,.6,1,0,0,0,1,0,.6,1],3));super(n,new _u({vertexColors:!0,toneMapped:!1})),this.type="AxesHelper"}setColors(t,e,n){const i=new tr,s=this.geometry.attributes.color.array;return i.set(t),i.toArray(s,0),i.toArray(s,3),i.set(e),i.toArray(s,6),i.toArray(s,9),i.set(n),i.toArray(s,12),i.toArray(s,15),this.geometry.attributes.color.needsUpdate=!0,this}dispose(){this.geometry.dispose(),this.material.dispose()}}class af{constructor(){this.type="ShapePath",this.color=new tr,this.subPaths=[],this.currentPath=null}moveTo(t,e){return this.currentPath=new ph,this.subPaths.push(this.currentPath),this.currentPath.moveTo(t,e),this}lineTo(t,e){return this.currentPath.lineTo(t,e),this}quadraticCurveTo(t,e,n,i){return this.currentPath.quadraticCurveTo(t,e,n,i),this}bezierCurveTo(t,e,n,i,s,r){return this.currentPath.bezierCurveTo(t,e,n,i,s,r),this}splineThru(t){return this.currentPath.splineThru(t),this}toShapes(t){function e(t,e){const n=e.length;let i=!1;for(let s=n-1,r=0;rNumber.EPSILON){if(l<0&&(n=e[r],o=-o,a=e[s],l=-l),t.ya.y)continue;if(t.y===n.y){if(t.x===n.x)return!0}else{const e=l*(t.x-n.x)-o*(t.y-n.y);if(0===e)return!0;if(e<0)continue;i=!i}}else{if(t.y!==n.y)continue;if(a.x<=t.x&&t.x<=n.x||n.x<=t.x&&t.x<=a.x)return!0}}return i}const n=Kh.isClockWise,i=this.subPaths;if(0===i.length)return[];let s,r,a;const o=[];if(1===i.length)return r=i[0],a=new Eh,a.curves=r.curves,o.push(a),o;let l=!n(i[0].getPoints());l=t?!l:l;const c=[],u=[];let h,d,p=[],m=0;u[m]=void 0,p[m]=[];for(let e=0,a=i.length;e1){let t=!1,n=0;for(let t=0,e=u.length;t0&&!1===t&&(p=c)}for(let t=0,e=u.length;t>>16,2246822507),n^=Math.imul(i^i>>>13,3266489909),i=Math.imul(i^i>>>16,2246822507),i^=Math.imul(n^n>>>13,3266489909),4294967296*(2097151&i)+(n>>>0)}const df=t=>hf(t),pf=t=>hf(t),mf=(...t)=>hf(t);function ff(t,e=!1){const n=[];!0===t.isNode&&(n.push(t.id),t=t.getSelf());for(const{property:i,childNode:s}of gf(t))n.push(n,hf(i.slice(0,-4)),s.getCacheKey(e));return hf(n)}function*gf(t,e=!1){for(const n in t){if(!0===n.startsWith("_"))continue;const i=t[n];if(!0===Array.isArray(i))for(let t=0;tt.charCodeAt(0))).buffer}var Mf=Object.freeze({__proto__:null,arrayBufferToBase64:_f,base64ToArrayBuffer:xf,getCacheKey:ff,getNodeChildren:gf,getValueFromType:yf,getValueType:vf,hash:mf,hashArray:pf,hashString:df});const bf={VERTEX:"vertex",FRAGMENT:"fragment"},Tf={NONE:"none",FRAME:"frame",RENDER:"render",OBJECT:"object"},Sf={BOOLEAN:"bool",INTEGER:"int",FLOAT:"float",VECTOR2:"vec2",VECTOR3:"vec3",VECTOR4:"vec4",MATRIX2:"mat2",MATRIX3:"mat3",MATRIX4:"mat4"},wf=["fragment","vertex"],Ef=["setup","analyze","generate"],Af=[...wf,"compute"],Nf=["x","y","z","w"];let Cf=0;class Rf extends Hn{static get type(){return"Node"}constructor(t=null){super(),this.nodeType=t,this.updateType=Tf.NONE,this.updateBeforeType=Tf.NONE,this.updateAfterType=Tf.NONE,this.uuid=Qn.generateUUID(),this.version=0,this._cacheKey=null,this._cacheKeyVersion=0,this.global=!1,this.isNode=!0,Object.defineProperty(this,"id",{value:Cf++})}set needsUpdate(t){!0===t&&this.version++}get type(){return this.constructor.type}onUpdate(t,e){return this.updateType=e,this.update=t.bind(this.getSelf()),this}onFrameUpdate(t){return this.onUpdate(t,Tf.FRAME)}onRenderUpdate(t){return this.onUpdate(t,Tf.RENDER)}onObjectUpdate(t){return this.onUpdate(t,Tf.OBJECT)}onReference(t){return this.updateReference=t.bind(this.getSelf()),this}getSelf(){return this.self||this}updateReference(){return this}isGlobal(){return this.global}*getChildren(){for(const{childNode:t}of gf(this))yield t}dispose(){this.dispatchEvent({type:"dispose"})}traverse(t){t(this);for(const e of this.getChildren())e.traverse(t)}getCacheKey(t=!1){return!0!==(t=t||this.version!==this._cacheKeyVersion)&&null!==this._cacheKey||(this._cacheKey=ff(this,t),this._cacheKeyVersion=this.version),this._cacheKey}getScope(){return this}getHash(){return this.uuid}getUpdateType(){return this.updateType}getUpdateBeforeType(){return this.updateBeforeType}getUpdateAfterType(){return this.updateAfterType}getElementType(t){const e=this.getNodeType(t);return t.getElementType(e)}getNodeType(t){const e=t.getNodeProperties(this);return e.outputNode?e.outputNode.getNodeType(t):this.nodeType}getShared(t){const e=this.getHash(t);return t.getNodeFromHash(e)||this}setup(t){const e=t.getNodeProperties(this);let n=0;for(const t of this.getChildren())e["node"+n++]=t;return null}analyze(t){if(1===t.increaseUsage(this)){const e=t.getNodeProperties(this);for(const n of Object.values(e))n&&!0===n.isNode&&n.build(t)}}generate(t,e){const{outputNode:n}=t.getNodeProperties(this);if(n&&!0===n.isNode)return n.build(t,e)}updateBefore(){console.warn("Abstract function.")}updateAfter(){console.warn("Abstract function.")}update(){console.warn("Abstract function.")}build(t,e=null){const n=this.getShared(t);if(this!==n)return n.build(t,e);t.addNode(this),t.addChain(this);let i=null;const s=t.getBuildStage();if("setup"===s){this.updateReference(t);const e=t.getNodeProperties(this);if(!0!==e.initialized){t.stack.nodes.length;e.initialized=!0,e.outputNode=this.setup(t),null!==e.outputNode&&t.stack.nodes.length;for(const n of Object.values(e))n&&!0===n.isNode&&n.build(t)}}else if("analyze"===s)this.analyze(t);else if("generate"===s){if(1===this.generate.length){const n=this.getNodeType(t),s=t.getDataFromNode(this);i=s.snippet,void 0===i?(i=this.generate(t)||"",s.snippet=i):void 0!==s.flowCodes&&void 0!==t.context.nodeBlock&&t.addFlowCodeHierarchy(this,t.context.nodeBlock),i=t.format(i,n,e)}else i=this.generate(t,e)||""}return t.removeChain(this),i}getSerializeChildren(){return gf(this)}serialize(t){const e=this.getSerializeChildren(),n={};for(const{property:i,index:s,childNode:r}of e)void 0!==s?(void 0===n[i]&&(n[i]=Number.isInteger(s)?[]:{}),n[i][s]=r.toJSON(t.meta).uuid):n[i]=r.toJSON(t.meta).uuid;Object.keys(n).length>0&&(t.inputNodes=n)}deserialize(t){if(void 0!==t.inputNodes){const e=t.meta.nodes;for(const n in t.inputNodes)if(Array.isArray(t.inputNodes[n])){const i=[];for(const s of t.inputNodes[n])i.push(e[s]);this[n]=i}else if("object"==typeof t.inputNodes[n]){const i={};for(const s in t.inputNodes[n]){const r=t.inputNodes[n][s];i[s]=e[r]}this[n]=i}else{const i=t.inputNodes[n];this[n]=e[i]}}}toJSON(t){const{uuid:e,type:n}=this,i=void 0===t||"string"==typeof t;i&&(t={textures:{},images:{},nodes:{}});let s=t.nodes[e];function r(t){const e=[];for(const n in t){const i=t[n];delete i.metadata,e.push(i)}return e}if(void 0===s&&(s={uuid:e,type:n,meta:t,metadata:{version:4.6,type:"Node",generator:"Node.toJSON"}},!0!==i&&(t.nodes[s.uuid]=s),this.serialize(s),delete s.meta),i){const e=r(t.textures),n=r(t.images),i=r(t.nodes);e.length>0&&(s.textures=e),n.length>0&&(s.images=n),i.length>0&&(s.nodes=i)}return s}}class If extends Rf{static get type(){return"ArrayElementNode"}constructor(t,e){super(),this.node=t,this.indexNode=e,this.isArrayElementNode=!0}getNodeType(t){return this.node.getElementType(t)}generate(t){return`${this.node.build(t)}[ ${this.indexNode.build(t,"uint")} ]`}}class Lf extends Rf{static get type(){return"ConvertNode"}constructor(t,e){super(),this.node=t,this.convertTo=e}getNodeType(t){const e=this.node.getNodeType(t);let n=null;for(const i of this.convertTo.split("|"))null!==n&&t.getTypeLength(e)!==t.getTypeLength(i)||(n=i);return n}serialize(t){super.serialize(t),t.convertTo=this.convertTo}deserialize(t){super.deserialize(t),this.convertTo=t.convertTo}generate(t,e){const n=this.node,i=this.getNodeType(t),s=n.build(t,i);return t.format(s,i,e)}}class Pf extends Rf{static get type(){return"TempNode"}constructor(t){super(t),this.isTempNode=!0}hasDependencies(t){return t.getDataFromNode(this).usageCount>1}build(t,e){if("generate"===t.getBuildStage()){const n=t.getVectorType(this.getNodeType(t,e)),i=t.getDataFromNode(this);if(void 0!==i.propertyName)return t.format(i.propertyName,n,e);if("void"!==n&&"void"!==e&&this.hasDependencies(t)){const s=super.build(t,n),r=t.getVarFromNode(this,null,n),a=t.getPropertyName(r);return t.addLineFlowCode(`${a} = ${s}`,this),i.snippet=s,i.propertyName=a,t.format(i.propertyName,n,e)}}return super.build(t,e)}}class Uf extends Pf{static get type(){return"JoinNode"}constructor(t=[],e=null){super(e),this.nodes=t}getNodeType(t){return null!==this.nodeType?t.getVectorType(this.nodeType):t.getTypeFromLength(this.nodes.reduce(((e,n)=>e+t.getTypeLength(n.getNodeType(t))),0))}generate(t,e){const n=this.getNodeType(t),i=this.nodes,s=t.getComponentType(n),r=[];for(const e of i){let n=e.build(t);const i=t.getComponentType(e.getNodeType(t));i!==s&&(n=t.format(n,i,s)),r.push(n)}const a=`${t.getType(n)}( ${r.join(", ")} )`;return t.format(a,n,e)}}const Df=Nf.join("");class Of extends Rf{static get type(){return"SplitNode"}constructor(t,e="x"){super(),this.node=t,this.components=e,this.isSplitNode=!0}getVectorLength(){let t=this.components.length;for(const e of this.components)t=Math.max(Nf.indexOf(e)+1,t);return t}getComponentType(t){return t.getComponentType(this.node.getNodeType(t))}getNodeType(t){return t.getTypeFromLength(this.components.length,this.getComponentType(t))}generate(t,e){const n=this.node,i=t.getTypeLength(n.getNodeType(t));let s=null;if(i>1){let r=null;this.getVectorLength()>=i&&(r=t.getTypeFromLength(this.getVectorLength(),this.getComponentType(t)));const a=n.build(t,r);s=this.components.length===i&&this.components===Df.slice(0,this.components.length)?t.format(a,r,e):t.format(`${a}.${this.components}`,this.getNodeType(t),e)}else s=n.build(t,e);return s}serialize(t){super.serialize(t),t.components=this.components}deserialize(t){super.deserialize(t),this.components=t.components}}class zf extends Pf{static get type(){return"SetNode"}constructor(t,e,n){super(),this.sourceNode=t,this.components=e,this.targetNode=n}getNodeType(t){return this.sourceNode.getNodeType(t)}generate(t){const{sourceNode:e,components:n,targetNode:i}=this,s=this.getNodeType(t),r=t.getTypeFromLength(n.length,i.getNodeType(t)),a=i.build(t,r),o=e.build(t,s),l=t.getTypeLength(s),c=[];for(let t=0;tt.replace(/r|s/g,"x").replace(/g|t/g,"y").replace(/b|p/g,"z").replace(/a|q/g,"w"),jf=t=>Wf(t).split("").sort().join(""),Xf={setup(t,e){const n=e.shift();return t(vg(n),...e)},get(t,e,n){if("string"==typeof e&&void 0===t[e]){if(!0!==t.isStackNode&&"assign"===e)return(...t)=>(kf.assign(n,...t),n);if(Hf.has(e)){const i=Hf.get(e);return t.isStackNode?(...t)=>n.add(i(...t)):(...t)=>i(n,...t)}if("self"===e)return t;if(e.endsWith("Assign")&&Hf.has(e.slice(0,e.length-6))){const i=Hf.get(e.slice(0,e.length-6));return t.isStackNode?(...t)=>n.assign(t[0],i(...t)):(...t)=>n.assign(i(n,...t))}if(!0===/^[xyzwrgbastpq]{1,4}$/.test(e))return e=Wf(e),gg(new Of(n,e));if(!0===/^set[XYZWRGBASTPQ]{1,4}$/.test(e))return e=jf(e.slice(3).toLowerCase()),n=>gg(new zf(t,e,n));if(!0===/^flip[XYZWRGBASTPQ]{1,4}$/.test(e))return e=jf(e.slice(4).toLowerCase()),()=>gg(new Vf(gg(t),e));if("width"===e||"height"===e||"depth"===e)return"width"===e?e="x":"height"===e?e="y":"depth"===e&&(e="z"),gg(new Of(t,e));if(!0===/^\d+$/.test(e))return gg(new If(n,new Bf(Number(e),"uint")))}return Reflect.get(t,e,n)},set:(t,e,n,i)=>"string"!=typeof e||void 0!==t[e]||!0!==/^[xyzwrgbastpq]{1,4}$/.test(e)&&"width"!==e&&"height"!==e&&"depth"!==e&&!0!==/^\d+$/.test(e)?Reflect.set(t,e,n,i):(i[e].assign(n),!0)},qf=new WeakMap,Yf=new WeakMap,Zf=function(t,e=null){for(const n in t)t[n]=gg(t[n],e);return t},$f=function(t,e=null){const n=t.length;for(let i=0;igg(null!==i?Object.assign(t,i):t);return null===e?(...e)=>s(new t(...yg(e))):null!==n?(n=gg(n),(...i)=>s(new t(e,...yg(i),n))):(...n)=>s(new t(e,...yg(n)))},Kf=function(t,...e){return gg(new t(...yg(e)))};class Qf extends Rf{constructor(t,e){super(),this.shaderNode=t,this.inputNodes=e}getNodeType(t){return this.shaderNode.nodeType||this.getOutputNode(t).getNodeType(t)}call(t){const{shaderNode:e,inputNodes:n}=this,i=t.getNodeProperties(e);if(i.onceOutput)return i.onceOutput;let s=null;if(e.layout){let i=Yf.get(t.constructor);void 0===i&&(i=new WeakMap,Yf.set(t.constructor,i));let r=i.get(e);void 0===r&&(r=gg(t.buildFunctionNode(e)),i.set(e,r)),null!==t.currentFunctionNode&&t.currentFunctionNode.includes.push(r),s=gg(r.call(n))}else{const i=e.jsFunc,r=null!==n?i(n,t):i(t);s=gg(r)}return e.once&&(i.onceOutput=s),s}getOutputNode(t){const e=t.getNodeProperties(this);return null===e.outputNode&&(e.outputNode=this.setupOutput(t)),e.outputNode}setup(t){return this.getOutputNode(t)}setupOutput(t){return t.addStack(),t.stack.outputNode=this.call(t),t.removeStack()}generate(t,e){return this.getOutputNode(t).build(t,e)}}class tg extends Rf{constructor(t,e){super(e),this.jsFunc=t,this.layout=null,this.global=!0,this.once=!1}setLayout(t){return this.layout=t,this}call(t=null){return vg(t),gg(new Qf(this,t))}setup(){return this.call()}}const eg=[!1,!0],ng=[0,1,2,3],ig=[-1,-2],sg=[.5,1.5,1/3,1e-6,1e6,Math.PI,2*Math.PI,1/Math.PI,2/Math.PI,1/(2*Math.PI),Math.PI/2],rg=new Map;for(const t of eg)rg.set(t,new Bf(t));const ag=new Map;for(const t of ng)ag.set(t,new Bf(t,"uint"));const og=new Map([...ag].map((t=>new Bf(t.value,"int"))));for(const t of ig)og.set(t,new Bf(t,"int"));const lg=new Map([...og].map((t=>new Bf(t.value))));for(const t of sg)lg.set(t,new Bf(t));for(const t of sg)lg.set(-t,new Bf(-t));const cg={bool:rg,uint:ag,ints:og,float:lg},ug=new Map([...rg,...lg]),hg=(t,e)=>ug.has(t)?ug.get(t):!0===t.isNode?t:new Bf(t,e),dg=function(t,e=null){return(...n)=>{if((0===n.length||!["bool","float","int","uint"].includes(t)&&n.every((t=>"object"!=typeof t)))&&(n=[yf(t,...n)]),1===n.length&&null!==e&&e.has(n[0]))return gg(e.get(n[0]));if(1===n.length){const e=hg(n[0],t);return(t=>{try{return t.getNodeType()}catch(t){return}})(e)===t?gg(e):gg(new Lf(e,t))}const i=n.map((t=>hg(t)));return gg(new Uf(i,t))}},pg=t=>"object"==typeof t&&null!==t?t.value:t,mg=t=>null!=t?t.nodeType||t.convertTo||("string"==typeof t?t:null):null;function fg(t,e){return new Proxy(new tg(t,e),Xf)}const gg=(t,e=null)=>function(t,e=null){const n=vf(t);if("node"===n){let e=qf.get(t);return void 0===e&&(e=new Proxy(t,Xf),qf.set(t,e),qf.set(e,e)),e}return null===e&&("float"===n||"boolean"===n)||n&&"shader"!==n&&"string"!==n?gg(hg(t,e)):"shader"===n?Mg(t):t}(t,e),vg=(t,e=null)=>new Zf(t,e),yg=(t,e=null)=>new $f(t,e),_g=(...t)=>new Jf(...t),xg=(...t)=>new Kf(...t),Mg=(t,e)=>{const n=new fg(t,e),i=(...t)=>{let e;return vg(t),e=t[0]&&t[0].isNode?[...t]:t[0],n.call(e)};return i.shaderNode=n,i.setLayout=t=>(n.setLayout(t),i),i.once=()=>(n.once=!0,i),i},bg=(...t)=>(console.warn("TSL.ShaderNode: tslFn() has been renamed to Fn()."),Mg(...t));Gf("toGlobal",(t=>(t.global=!0,t)));const Tg=t=>{kf=t},Sg=()=>kf,wg=(...t)=>kf.If(...t);function Eg(t){return kf&&kf.add(t),t}Gf("append",Eg);const Ag=new dg("color"),Ng=new dg("float",cg.float),Cg=new dg("int",cg.ints),Rg=new dg("uint",cg.uint),Ig=new dg("bool",cg.bool),Lg=new dg("vec2"),Pg=new dg("ivec2"),Ug=new dg("uvec2"),Dg=new dg("bvec2"),Og=new dg("vec3"),zg=new dg("ivec3"),Vg=new dg("uvec3"),Fg=new dg("bvec3"),Bg=new dg("vec4"),kg=new dg("ivec4"),Hg=new dg("uvec4"),Gg=new dg("bvec4"),Wg=new dg("mat2"),jg=new dg("mat3"),Xg=new dg("mat4"),qg=(t="")=>gg(new Bf(t,"string")),Yg=t=>gg(new Bf(t,"ArrayBuffer"));Gf("toColor",Ag),Gf("toFloat",Ng),Gf("toInt",Cg),Gf("toUint",Rg),Gf("toBool",Ig),Gf("toVec2",Lg),Gf("toIVec2",Pg),Gf("toUVec2",Ug),Gf("toBVec2",Dg),Gf("toVec3",Og),Gf("toIVec3",zg),Gf("toUVec3",Vg),Gf("toBVec3",Fg),Gf("toVec4",Bg),Gf("toIVec4",kg),Gf("toUVec4",Hg),Gf("toBVec4",Gg),Gf("toMat2",Wg),Gf("toMat3",jg),Gf("toMat4",Xg);const Zg=_g(If),$g=(t,e)=>gg(new Lf(gg(t),e)),Jg=(t,e)=>gg(new Of(gg(t),e));Gf("element",Zg),Gf("convert",$g);class Kg extends Rf{static get type(){return"UniformGroupNode"}constructor(t,e=!1,n=1){super("string"),this.name=t,this.version=0,this.shared=e,this.order=n,this.isUniformGroup=!0}set needsUpdate(t){!0===t&&this.version++}serialize(t){super.serialize(t),t.name=this.name,t.version=this.version,t.shared=this.shared}deserialize(t){super.deserialize(t),this.name=t.name,this.version=t.version,this.shared=t.shared}}const Qg=t=>new Kg(t),tv=(t,e=0)=>new Kg(t,!0,e),ev=tv("frame"),nv=tv("render"),iv=Qg("object");class sv extends Ff{static get type(){return"UniformNode"}constructor(t,e=null){super(t,e),this.isUniformNode=!0,this.name="",this.groupNode=iv}label(t){return this.name=t,this}setGroup(t){return this.groupNode=t,this}getGroup(){return this.groupNode}getUniformHash(t){return this.getHash(t)}onUpdate(t,e){const n=this.getSelf();return t=t.bind(n),super.onUpdate((e=>{const i=t(e,n);void 0!==i&&(this.value=i)}),e)}generate(t,e){const n=this.getNodeType(t),i=this.getUniformHash(t);let s=t.getNodeFromHash(i);void 0===s&&(t.setHashNode(this,i),s=this);const r=s.getInputType(t),a=t.getUniformFromNode(s,r,t.shaderStage,this.name||t.context.label),o=t.getPropertyName(a);return void 0!==t.context.label&&delete t.context.label,t.format(o,n,e)}}const rv=(t,e)=>{const n=mg(e||t),i=t&&!0===t.isNode?t.node&&t.node.value||t.value:t;return gg(new sv(i,n))};class av extends Rf{static get type(){return"PropertyNode"}constructor(t,e=null,n=!1){super(t),this.name=e,this.varying=n,this.isPropertyNode=!0}getHash(t){return this.name||super.getHash(t)}isGlobal(){return!0}generate(t){let e;return!0===this.varying?(e=t.getVaryingFromNode(this,this.name),e.needsInterpolation=!0):e=t.getVarFromNode(this,this.name),t.getPropertyName(e)}}const ov=(t,e)=>gg(new av(t,e)),lv=(t,e)=>gg(new av(t,e,!0)),cv=xg(av,"vec4","DiffuseColor"),uv=xg(av,"vec3","EmissiveColor"),hv=xg(av,"float","Roughness"),dv=xg(av,"float","Metalness"),pv=xg(av,"float","Clearcoat"),mv=xg(av,"float","ClearcoatRoughness"),fv=xg(av,"vec3","Sheen"),gv=xg(av,"float","SheenRoughness"),vv=xg(av,"float","Iridescence"),yv=xg(av,"float","IridescenceIOR"),_v=xg(av,"float","IridescenceThickness"),xv=xg(av,"float","AlphaT"),Mv=xg(av,"float","Anisotropy"),bv=xg(av,"vec3","AnisotropyT"),Tv=xg(av,"vec3","AnisotropyB"),Sv=xg(av,"color","SpecularColor"),wv=xg(av,"float","SpecularF90"),Ev=xg(av,"float","Shininess"),Av=xg(av,"vec4","Output"),Nv=xg(av,"float","dashSize"),Cv=xg(av,"float","gapSize"),Rv=xg(av,"float","pointWidth"),Iv=xg(av,"float","IOR"),Lv=xg(av,"float","Transmission"),Pv=xg(av,"float","Thickness"),Uv=xg(av,"float","AttenuationDistance"),Dv=xg(av,"color","AttenuationColor"),Ov=xg(av,"float","Dispersion");class zv extends Pf{static get type(){return"AssignNode"}constructor(t,e){super(),this.targetNode=t,this.sourceNode=e}hasDependencies(){return!1}getNodeType(t,e){return"void"!==e?this.targetNode.getNodeType(t):"void"}needsSplitAssign(t){const{targetNode:e}=this;if(!1===t.isAvailable("swizzleAssign")&&e.isSplitNode&&e.components.length>1){const n=t.getTypeLength(e.node.getNodeType(t));return Nf.join("").slice(0,n)!==e.components}return!1}generate(t,e){const{targetNode:n,sourceNode:i}=this,s=this.needsSplitAssign(t),r=n.getNodeType(t),a=n.context({assign:!0}).build(t),o=i.build(t,r),l=i.getNodeType(t),c=t.getDataFromNode(this);let u;if(!0===c.initialized)"void"!==e&&(u=a);else if(s){const i=t.getVarFromNode(this,null,r),s=t.getPropertyName(i);t.addLineFlowCode(`${s} = ${o}`,this);const l=n.node.context({assign:!0}).build(t);for(let e=0;e(e=e.length>1||e[0]&&!0===e[0].isNode?yg(e):vg(e[0]),gg(new Fv(gg(t),e)));Gf("call",Bv);class kv extends Pf{static get type(){return"OperatorNode"}constructor(t,e,n,...i){if(super(),i.length>0){let s=new kv(t,e,n);for(let e=0;e>"===n||"<<"===n)return t.getIntegerType(r);if("!"===n||"=="===n||"&&"===n||"||"===n||"^^"===n)return"bool";if("<"===n||">"===n||"<="===n||">="===n){const n=e?t.getTypeLength(e):Math.max(t.getTypeLength(r),t.getTypeLength(a));return n>1?`bvec${n}`:"bool"}return"float"===r&&t.isMatrix(a)?a:t.isMatrix(r)&&t.isVector(a)?t.getVectorFromMatrix(r):t.isVector(r)&&t.isMatrix(a)?t.getVectorFromMatrix(a):t.getTypeLength(a)>t.getTypeLength(r)?a:r}generate(t,e){const n=this.op,i=this.aNode,s=this.bNode,r=this.getNodeType(t,e);let a=null,o=null;"void"!==r?(a=i.getNodeType(t),o=void 0!==s?s.getNodeType(t):null,"<"===n||">"===n||"<="===n||">="===n||"=="===n?t.isVector(a)?o=a:a!==o&&(a=o="float"):">>"===n||"<<"===n?(a=r,o=t.changeComponentType(o,"uint")):t.isMatrix(a)&&t.isVector(o)?o=t.getVectorFromMatrix(a):a=t.isVector(a)&&t.isMatrix(o)?t.getVectorFromMatrix(o):o=r):a=o=r;const l=i.build(t,a),c=void 0!==s?s.build(t,o):null,u=t.getTypeLength(e),h=t.getFunctionOperator(n);return"void"!==e?"<"===n&&u>1?t.useComparisonMethod?t.format(`${t.getMethod("lessThan",e)}( ${l}, ${c} )`,r,e):t.format(`( ${l} < ${c} )`,r,e):"<="===n&&u>1?t.useComparisonMethod?t.format(`${t.getMethod("lessThanEqual",e)}( ${l}, ${c} )`,r,e):t.format(`( ${l} <= ${c} )`,r,e):">"===n&&u>1?t.useComparisonMethod?t.format(`${t.getMethod("greaterThan",e)}( ${l}, ${c} )`,r,e):t.format(`( ${l} > ${c} )`,r,e):">="===n&&u>1?t.useComparisonMethod?t.format(`${t.getMethod("greaterThanEqual",e)}( ${l}, ${c} )`,r,e):t.format(`( ${l} >= ${c} )`,r,e):"!"===n||"~"===n?t.format(`(${n}${l})`,a,e):h?t.format(`${h}( ${l}, ${c} )`,r,e):t.format(`( ${l} ${n} ${c} )`,r,e):"void"!==a?h?t.format(`${h}( ${l}, ${c} )`,r,e):t.format(`${l} ${n} ${c}`,r,e):void 0}serialize(t){super.serialize(t),t.op=this.op}deserialize(t){super.deserialize(t),this.op=t.op}}const Hv=_g(kv,"+"),Gv=_g(kv,"-"),Wv=_g(kv,"*"),jv=_g(kv,"/"),Xv=_g(kv,"%"),qv=_g(kv,"=="),Yv=_g(kv,"!="),Zv=_g(kv,"<"),$v=_g(kv,">"),Jv=_g(kv,"<="),Kv=_g(kv,">="),Qv=_g(kv,"&&"),ty=_g(kv,"||"),ey=_g(kv,"!"),ny=_g(kv,"^^"),iy=_g(kv,"&"),sy=_g(kv,"~"),ry=_g(kv,"|"),ay=_g(kv,"^"),oy=_g(kv,"<<"),ly=_g(kv,">>");Gf("add",Hv),Gf("sub",Gv),Gf("mul",Wv),Gf("div",jv),Gf("modInt",Xv),Gf("equal",qv),Gf("notEqual",Yv),Gf("lessThan",Zv),Gf("greaterThan",$v),Gf("lessThanEqual",Jv),Gf("greaterThanEqual",Kv),Gf("and",Qv),Gf("or",ty),Gf("not",ey),Gf("xor",ny),Gf("bitAnd",iy),Gf("bitNot",sy),Gf("bitOr",ry),Gf("bitXor",ay),Gf("shiftLeft",oy),Gf("shiftRight",ly);const cy=(...t)=>(console.warn("TSL.OperatorNode: .remainder() has been renamed to .modInt()."),Xv(...t));Gf("remainder",cy);class uy extends Pf{static get type(){return"MathNode"}constructor(t,e,n=null,i=null){super(),this.method=t,this.aNode=e,this.bNode=n,this.cNode=i}getInputType(t){const e=this.aNode.getNodeType(t),n=this.bNode?this.bNode.getNodeType(t):null,i=this.cNode?this.cNode.getNodeType(t):null,s=t.isMatrix(e)?0:t.getTypeLength(e),r=t.isMatrix(n)?0:t.getTypeLength(n),a=t.isMatrix(i)?0:t.getTypeLength(i);return s>r&&s>a?e:r>a?n:a>s?i:e}getNodeType(t){const e=this.method;return e===uy.LENGTH||e===uy.DISTANCE||e===uy.DOT?"float":e===uy.CROSS?"vec3":e===uy.ALL?"bool":e===uy.EQUALS?t.changeComponentType(this.aNode.getNodeType(t),"bool"):e===uy.MOD?this.aNode.getNodeType(t):this.getInputType(t)}generate(t,e){const n=this.method,i=this.getNodeType(t),s=this.getInputType(t),r=this.aNode,a=this.bNode,o=this.cNode,l=!0===t.renderer.isWebGLRenderer;if(n===uy.TRANSFORM_DIRECTION){let n=r,i=a;t.isMatrix(n.getNodeType(t))?i=Bg(Og(i),0):n=Bg(Og(n),0);const s=Wv(n,i).xyz;return Ny(s).build(t,e)}if(n===uy.NEGATE)return t.format("( - "+r.build(t,s)+" )",i,e);if(n===uy.ONE_MINUS)return Gv(1,r).build(t,e);if(n===uy.RECIPROCAL)return jv(1,r).build(t,e);if(n===uy.DIFFERENCE)return Oy(Gv(r,a)).build(t,e);{const c=[];return n===uy.CROSS||n===uy.MOD?c.push(r.build(t,i),a.build(t,i)):l&&n===uy.STEP?c.push(r.build(t,1===t.getTypeLength(r.getNodeType(t))?"float":s),a.build(t,s)):l&&(n===uy.MIN||n===uy.MAX)||n===uy.MOD?c.push(r.build(t,s),a.build(t,1===t.getTypeLength(a.getNodeType(t))?"float":s)):n===uy.REFRACT?c.push(r.build(t,s),a.build(t,s),o.build(t,"float")):n===uy.MIX?c.push(r.build(t,s),a.build(t,s),o.build(t,1===t.getTypeLength(o.getNodeType(t))?"float":s)):(c.push(r.build(t,s)),null!==a&&c.push(a.build(t,s)),null!==o&&c.push(o.build(t,s))),t.format(`${t.getMethod(n,i)}( ${c.join(", ")} )`,i,e)}}serialize(t){super.serialize(t),t.method=this.method}deserialize(t){super.deserialize(t),this.method=t.method}}uy.ALL="all",uy.ANY="any",uy.EQUALS="equals",uy.RADIANS="radians",uy.DEGREES="degrees",uy.EXP="exp",uy.EXP2="exp2",uy.LOG="log",uy.LOG2="log2",uy.SQRT="sqrt",uy.INVERSE_SQRT="inversesqrt",uy.FLOOR="floor",uy.CEIL="ceil",uy.NORMALIZE="normalize",uy.FRACT="fract",uy.SIN="sin",uy.COS="cos",uy.TAN="tan",uy.ASIN="asin",uy.ACOS="acos",uy.ATAN="atan",uy.ABS="abs",uy.SIGN="sign",uy.LENGTH="length",uy.NEGATE="negate",uy.ONE_MINUS="oneMinus",uy.DFDX="dFdx",uy.DFDY="dFdy",uy.ROUND="round",uy.RECIPROCAL="reciprocal",uy.TRUNC="trunc",uy.FWIDTH="fwidth",uy.BITCAST="bitcast",uy.TRANSPOSE="transpose",uy.ATAN2="atan2",uy.MIN="min",uy.MAX="max",uy.MOD="mod",uy.STEP="step",uy.REFLECT="reflect",uy.DISTANCE="distance",uy.DIFFERENCE="difference",uy.DOT="dot",uy.CROSS="cross",uy.POW="pow",uy.TRANSFORM_DIRECTION="transformDirection",uy.MIX="mix",uy.CLAMP="clamp",uy.REFRACT="refract",uy.SMOOTHSTEP="smoothstep",uy.FACEFORWARD="faceforward";const hy=Ng(1e-6),dy=Ng(1e6),py=Ng(Math.PI),my=Ng(2*Math.PI),fy=_g(uy,uy.ALL),gy=_g(uy,uy.ANY),vy=_g(uy,uy.EQUALS),yy=_g(uy,uy.RADIANS),_y=_g(uy,uy.DEGREES),xy=_g(uy,uy.EXP),My=_g(uy,uy.EXP2),by=_g(uy,uy.LOG),Ty=_g(uy,uy.LOG2),Sy=_g(uy,uy.SQRT),wy=_g(uy,uy.INVERSE_SQRT),Ey=_g(uy,uy.FLOOR),Ay=_g(uy,uy.CEIL),Ny=_g(uy,uy.NORMALIZE),Cy=_g(uy,uy.FRACT),Ry=_g(uy,uy.SIN),Iy=_g(uy,uy.COS),Ly=_g(uy,uy.TAN),Py=_g(uy,uy.ASIN),Uy=_g(uy,uy.ACOS),Dy=_g(uy,uy.ATAN),Oy=_g(uy,uy.ABS),zy=_g(uy,uy.SIGN),Vy=_g(uy,uy.LENGTH),Fy=_g(uy,uy.NEGATE),By=_g(uy,uy.ONE_MINUS),ky=_g(uy,uy.DFDX),Hy=_g(uy,uy.DFDY),Gy=_g(uy,uy.ROUND),Wy=_g(uy,uy.RECIPROCAL),jy=_g(uy,uy.TRUNC),Xy=_g(uy,uy.FWIDTH),qy=_g(uy,uy.BITCAST),Yy=_g(uy,uy.TRANSPOSE),Zy=_g(uy,uy.ATAN2),$y=_g(uy,uy.MIN),Jy=_g(uy,uy.MAX),Ky=_g(uy,uy.MOD),Qy=_g(uy,uy.STEP),t_=_g(uy,uy.REFLECT),e_=_g(uy,uy.DISTANCE),n_=_g(uy,uy.DIFFERENCE),i_=_g(uy,uy.DOT),s_=_g(uy,uy.CROSS),r_=_g(uy,uy.POW),a_=_g(uy,uy.POW,2),o_=_g(uy,uy.POW,3),l_=_g(uy,uy.POW,4),c_=_g(uy,uy.TRANSFORM_DIRECTION),u_=t=>Wv(zy(t),r_(Oy(t),1/3)),h_=t=>i_(t,t),d_=_g(uy,uy.MIX),p_=(t,e=0,n=1)=>gg(new uy(uy.CLAMP,gg(t),gg(e),gg(n))),m_=t=>p_(t),f_=_g(uy,uy.REFRACT),g_=_g(uy,uy.SMOOTHSTEP),v_=_g(uy,uy.FACEFORWARD),y_=Mg((([t])=>{const e=i_(t.xy,Lg(12.9898,78.233)),n=Ky(e,py);return Cy(Ry(n).mul(43758.5453))})),__=(t,e,n)=>d_(e,n,t),x_=(t,e,n)=>g_(e,n,t);Gf("all",fy),Gf("any",gy),Gf("equals",vy),Gf("radians",yy),Gf("degrees",_y),Gf("exp",xy),Gf("exp2",My),Gf("log",by),Gf("log2",Ty),Gf("sqrt",Sy),Gf("inverseSqrt",wy),Gf("floor",Ey),Gf("ceil",Ay),Gf("normalize",Ny),Gf("fract",Cy),Gf("sin",Ry),Gf("cos",Iy),Gf("tan",Ly),Gf("asin",Py),Gf("acos",Uy),Gf("atan",Dy),Gf("abs",Oy),Gf("sign",zy),Gf("length",Vy),Gf("lengthSq",h_),Gf("negate",Fy),Gf("oneMinus",By),Gf("dFdx",ky),Gf("dFdy",Hy),Gf("round",Gy),Gf("reciprocal",Wy),Gf("trunc",jy),Gf("fwidth",Xy),Gf("atan2",Zy),Gf("min",$y),Gf("max",Jy),Gf("mod",Ky),Gf("step",Qy),Gf("reflect",t_),Gf("distance",e_),Gf("dot",i_),Gf("cross",s_),Gf("pow",r_),Gf("pow2",a_),Gf("pow3",o_),Gf("pow4",l_),Gf("transformDirection",c_),Gf("mix",__),Gf("clamp",p_),Gf("refract",f_),Gf("smoothstep",x_),Gf("faceForward",v_),Gf("difference",n_),Gf("saturate",m_),Gf("cbrt",u_),Gf("transpose",Yy),Gf("rand",y_);class M_ extends Rf{static get type(){return"ConditionalNode"}constructor(t,e,n=null){super(),this.condNode=t,this.ifNode=e,this.elseNode=n}getNodeType(t){const e=this.ifNode.getNodeType(t);if(null!==this.elseNode){const n=this.elseNode.getNodeType(t);if(t.getTypeLength(n)>t.getTypeLength(e))return n}return e}setup(t){const e=this.condNode.cache(),n=this.ifNode.cache(),i=this.elseNode?this.elseNode.cache():null,s=t.context.nodeBlock;t.getDataFromNode(n).parentNodeBlock=s,null!==i&&(t.getDataFromNode(i).parentNodeBlock=s);const r=t.getNodeProperties(this);r.condNode=e,r.ifNode=n.context({nodeBlock:n}),r.elseNode=i?i.context({nodeBlock:i}):null}generate(t,e){const n=this.getNodeType(t),i=t.getDataFromNode(this);if(void 0!==i.nodeProperty)return i.nodeProperty;const{condNode:s,ifNode:r,elseNode:a}=t.getNodeProperties(this),o="void"!==e,l=o?ov(n).build(t):"";i.nodeProperty=l;const c=s.build(t,"bool");t.addFlowCode(`\n${t.tab}if ( ${c} ) {\n\n`).addFlowTab();let u=r.build(t,n);if(u&&(u=o?l+" = "+u+";":"return "+u+";"),t.removeFlowTab().addFlowCode(t.tab+"\t"+u+"\n\n"+t.tab+"}"),null!==a){t.addFlowCode(" else {\n\n").addFlowTab();let e=a.build(t,n);e&&(e=o?l+" = "+e+";":"return "+e+";"),t.removeFlowTab().addFlowCode(t.tab+"\t"+e+"\n\n"+t.tab+"}\n\n")}else t.addFlowCode("\n\n");return t.format(l,n,e)}}const b_=_g(M_);Gf("select",b_);const T_=(...t)=>(console.warn("TSL.ConditionalNode: cond() has been renamed to select()."),b_(...t));Gf("cond",T_);class S_ extends Rf{static get type(){return"ContextNode"}constructor(t,e={}){super(),this.isContextNode=!0,this.node=t,this.value=e}getScope(){return this.node.getScope()}getNodeType(t){return this.node.getNodeType(t)}analyze(t){this.node.build(t)}setup(t){const e=t.getContext();t.setContext({...t.context,...this.value});const n=this.node.build(t);return t.setContext(e),n}generate(t,e){const n=t.getContext();t.setContext({...t.context,...this.value});const i=this.node.build(t,e);return t.setContext(n),i}}const w_=_g(S_),E_=(t,e)=>w_(t,{label:e});Gf("context",w_),Gf("label",E_);class A_ extends Rf{static get type(){return"VarNode"}constructor(t,e=null){super(),this.node=t,this.name=e,this.global=!0,this.isVarNode=!0}getHash(t){return this.name||super.getHash(t)}getNodeType(t){return this.node.getNodeType(t)}generate(t){const{node:e,name:n}=this,i=t.getVarFromNode(this,n,t.getVectorType(this.getNodeType(t))),s=t.getPropertyName(i),r=e.build(t,i.type);return t.addLineFlowCode(`${s} = ${r}`,this),s}}const N_=_g(A_);Gf("temp",N_),Gf("toVar",((...t)=>N_(...t).append()));class C_ extends Rf{static get type(){return"VaryingNode"}constructor(t,e=null){super(),this.node=t,this.name=e,this.isVaryingNode=!0}isGlobal(){return!0}getHash(t){return this.name||super.getHash(t)}getNodeType(t){return this.node.getNodeType(t)}setupVarying(t){const e=t.getNodeProperties(this);let n=e.varying;if(void 0===n){const i=this.name,s=this.getNodeType(t);e.varying=n=t.getVaryingFromNode(this,i,s),e.node=this.node}return n.needsInterpolation||(n.needsInterpolation="fragment"===t.shaderStage),n}setup(t){this.setupVarying(t)}analyze(t){return this.setupVarying(t),this.node.analyze(t)}generate(t){const e=t.getNodeProperties(this),n=this.setupVarying(t);if(void 0===e.propertyName){const i=this.getNodeType(t),s=t.getPropertyName(n,bf.VERTEX);t.flowNodeFromShaderStage(bf.VERTEX,this.node,i,s),e.propertyName=s}return t.getPropertyName(n)}}const R_=_g(C_);Gf("varying",R_);const I_="WorkingColorSpace",L_="OutputColorSpace";function P_(t){let e=null;return t===Je?e="Linear":t===$e&&(e="sRGB"),e}function U_(t,e){return P_(t)+"To"+P_(e)}class D_ extends Pf{static get type(){return"ColorSpaceNode"}constructor(t,e,n){super("vec4"),this.colorNode=t,this.source=e,this.target=n}getColorSpace(t,e){return e===I_?mi.workingColorSpace:e===L_?t.context.outputColorSpace||t.renderer.outputColorSpace:e}setup(t){const{renderer:e}=t,{colorNode:n}=this,i=this.getColorSpace(t,this.source),s=this.getColorSpace(t,this.target);if(i===s)return n;const r=U_(i,s);let a=null;const o=e.nodes.library.getColorSpaceFunction(r);return null!==o?a=Bg(o(n.rgb),n.a):(console.error("ColorSpaceNode: Unsupported Color Space configuration.",r),a=n),a}}const O_=t=>gg(new D_(gg(t),I_,L_)),z_=t=>gg(new D_(gg(t),L_,I_)),V_=(t,e)=>gg(new D_(gg(t),I_,e)),F_=(t,e)=>gg(new D_(gg(t),e,I_));Gf("toOutputColorSpace",O_),Gf("toWorkingColorSpace",z_),Gf("workingToColorSpace",V_),Gf("colorSpaceToWorking",F_);let B_=class extends If{static get type(){return"ReferenceElementNode"}constructor(t,e){super(t,e),this.referenceNode=t,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(t){const e=super.generate(t),n=this.referenceNode.getNodeType(),i=this.getNodeType();return t.format(e,n,i)}};class k_ extends Rf{static get type(){return"ReferenceBaseNode"}constructor(t,e,n=null,i=null){super(),this.property=t,this.uniformType=e,this.object=n,this.count=i,this.properties=t.split("."),this.reference=n,this.node=null,this.group=null,this.updateType=Tf.OBJECT}setGroup(t){return this.group=t,this}element(t){return gg(new B_(this,gg(t)))}setNodeType(t){const e=rv(null,t).getSelf();null!==this.group&&e.setGroup(this.group),this.node=e}getNodeType(t){return null===this.node&&(this.updateReference(t),this.updateValue()),this.node.getNodeType(t)}getValueFromReference(t=this.reference){const{properties:e}=this;let n=t[e[0]];for(let t=1;tgg(new H_(t,e,n));class W_ extends Pf{static get type(){return"ToneMappingNode"}constructor(t,e=X_,n=null){super("vec3"),this.toneMapping=t,this.exposureNode=e,this.colorNode=n}getCacheKey(){return mf(super.getCacheKey(),this.toneMapping)}setup(t){const e=this.colorNode||t.context.color,n=this.toneMapping;if(0===n)return e;let i=null;const s=t.renderer.nodes.library.getToneMappingFunction(n);return null!==s?i=Bg(s(e.rgb,this.exposureNode),e.a):(console.error("ToneMappingNode: Unsupported Tone Mapping configuration.",n),i=e),i}}const j_=(t,e,n)=>gg(new W_(t,gg(e),gg(n))),X_=G_("toneMappingExposure","float");Gf("toneMapping",((t,e,n)=>j_(e,n,t)));class q_ extends Ff{static get type(){return"BufferAttributeNode"}constructor(t,e=null,n=0,i=0){super(t,e),this.isBufferNode=!0,this.bufferType=e,this.bufferStride=n,this.bufferOffset=i,this.usage=Cn,this.instanced=!1,this.attribute=null,this.global=!0,t&&!0===t.isBufferAttribute&&(this.attribute=t,this.usage=t.usage,this.instanced=t.isInstancedBufferAttribute)}getHash(t){if(0===this.bufferStride&&0===this.bufferOffset){let e=t.globalCache.getData(this.value);return void 0===e&&(e={node:this},t.globalCache.setData(this.value,e)),e.node.uuid}return this.uuid}getNodeType(t){return null===this.bufferType&&(this.bufferType=t.getTypeFromAttribute(this.attribute)),this.bufferType}setup(t){if(null!==this.attribute)return;const e=this.getNodeType(t),n=this.value,i=t.getTypeLength(e),s=this.bufferStride||i,r=this.bufferOffset,a=!0===n.isInterleavedBuffer?n:new lc(n,s),o=new uc(a,i,r);a.setUsage(this.usage),this.attribute=o,this.attribute.isInstancedBufferAttribute=this.instanced}generate(t){const e=this.getNodeType(t),n=t.getBufferAttributeFromNode(this,e),i=t.getPropertyName(n);let s=null;if("vertex"===t.shaderStage||"compute"===t.shaderStage)this.name=i,s=i;else{s=R_(this).build(t,e)}return s}getInputType(){return"bufferAttribute"}setUsage(t){return this.usage=t,this.attribute&&!0===this.attribute.isBufferAttribute&&(this.attribute.usage=t),this}setInstanced(t){return this.instanced=t,this}}const Y_=(t,e,n,i)=>gg(new q_(t,e,n,i)),Z_=(t,e,n,i)=>Y_(t,e,n,i).setUsage(Rn),$_=(t,e,n,i)=>Y_(t,e,n,i).setInstanced(!0),J_=(t,e,n,i)=>Z_(t,e,n,i).setInstanced(!0);Gf("toAttribute",(t=>Y_(t.value)));class K_ extends Rf{static get type(){return"ComputeNode"}constructor(t,e,n=[64]){super("void"),this.isComputeNode=!0,this.computeNode=t,this.count=e,this.workgroupSize=n,this.dispatchCount=0,this.version=1,this.updateBeforeType=Tf.OBJECT,this.updateDispatchCount()}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(t){!0===t&&this.version++}updateDispatchCount(){const{count:t,workgroupSize:e}=this;let n=e[0];for(let t=1;tgg(new K_(gg(t),e,n));Gf("compute",Q_);class tx extends Rf{static get type(){return"CacheNode"}constructor(t,e=!0){super(),this.node=t,this.parent=e,this.isCacheNode=!0}getNodeType(t){return this.node.getNodeType(t)}build(t,...e){const n=t.getCache(),i=t.getCacheFromNode(this,this.parent);t.setCache(i);const s=this.node.build(t,...e);return t.setCache(n),s}}const ex=(t,...e)=>gg(new tx(gg(t),...e));Gf("cache",ex);class nx extends Rf{static get type(){return"BypassNode"}constructor(t,e){super(),this.isBypassNode=!0,this.outputNode=t,this.callNode=e}getNodeType(t){return this.outputNode.getNodeType(t)}generate(t){const e=this.callNode.build(t,"void");return""!==e&&t.addLineFlowCode(e,this),this.outputNode.build(t)}}const ix=_g(nx);Gf("bypass",ix);class sx extends Rf{static get type(){return"RemapNode"}constructor(t,e,n,i=Ng(0),s=Ng(1)){super(),this.node=t,this.inLowNode=e,this.inHighNode=n,this.outLowNode=i,this.outHighNode=s,this.doClamp=!0}setup(){const{node:t,inLowNode:e,inHighNode:n,outLowNode:i,outHighNode:s,doClamp:r}=this;let a=t.sub(e).div(n.sub(e));return!0===r&&(a=a.clamp()),a.mul(s.sub(i)).add(i)}}const rx=_g(sx,null,null,{doClamp:!1}),ax=_g(sx);Gf("remap",rx),Gf("remapClamp",ax);class ox extends Rf{static get type(){return"ExpressionNode"}constructor(t="",e="void"){super(e),this.snippet=t}generate(t,e){const n=this.getNodeType(t),i=this.snippet;if("void"!==n)return t.format(`( ${i} )`,n,e);t.addLineFlowCode(i,this)}}const lx=_g(ox),cx=t=>(t?b_(t,lx("discard")):lx("discard")).append(),ux=()=>lx("return").append();Gf("discard",cx);class hx extends Pf{static get type(){return"RenderOutputNode"}constructor(t,e,n){super("vec4"),this.colorNode=t,this.toneMapping=e,this.outputColorSpace=n,this.isRenderOutput=!0}setup({context:t}){let e=this.colorNode||t.color;const n=(null!==this.toneMapping?this.toneMapping:t.toneMapping)||0,i=(null!==this.outputColorSpace?this.outputColorSpace:t.outputColorSpace)||Ze;return 0!==n&&(e=e.toneMapping(n)),i!==Ze&&i!==mi.workingColorSpace&&(e=e.workingToColorSpace(i)),e}}const dx=(t,e=null,n=null)=>gg(new hx(gg(t),e,n));function px(t){console.warn("THREE.TSLBase: AddNodeElement has been removed in favor of tree-shaking. Trying add",t)}Gf("renderOutput",dx);class mx extends Rf{static get type(){return"AttributeNode"}constructor(t,e=null){super(e),this.global=!0,this._attributeName=t}getHash(t){return this.getAttributeName(t)}getNodeType(t){let e=this.nodeType;if(null===e){const n=this.getAttributeName(t);if(t.hasGeometryAttribute(n)){const i=t.geometry.getAttribute(n);e=t.getTypeFromAttribute(i)}else e="float"}return e}setAttributeName(t){return this._attributeName=t,this}getAttributeName(){return this._attributeName}generate(t){const e=this.getAttributeName(t),n=this.getNodeType(t);if(!0===t.hasGeometryAttribute(e)){const i=t.geometry.getAttribute(e),s=t.getTypeFromAttribute(i),r=t.getAttribute(e,s);if("vertex"===t.shaderStage)return t.format(r.name,s,n);return R_(this).build(t,n)}return console.warn(`AttributeNode: Vertex attribute "${e}" not found on geometry.`),t.generateConst(n)}serialize(t){super.serialize(t),t.global=this.global,t._attributeName=this._attributeName}deserialize(t){super.deserialize(t),this.global=t.global,this._attributeName=t._attributeName}}const fx=(t,e)=>gg(new mx(t,e)),gx=t=>fx("uv"+(t>0?t:""),"vec2");class vx extends Rf{static get type(){return"TextureSizeNode"}constructor(t,e=null){super("uvec2"),this.isTextureSizeNode=!0,this.textureNode=t,this.levelNode=e}generate(t,e){const n=this.textureNode.build(t,"property"),i=null===this.levelNode?"0":this.levelNode.build(t,"int");return t.format(`${t.getMethod("textureDimensions")}( ${n}, ${i} )`,this.getNodeType(t),e)}}const yx=_g(vx);class _x extends sv{static get type(){return"MaxMipLevelNode"}constructor(t){super(0),this._textureNode=t,this.updateType=Tf.FRAME}get textureNode(){return this._textureNode}get texture(){return this._textureNode.value}update(){const t=this.texture,e=t.images,n=e&&e.length>0?e[0]&&e[0].image||e[0]:t.image;if(n&&void 0!==n.width){const{width:t,height:e}=n;this.value=Math.log2(Math.max(t,e))}}}const xx=_g(_x);class Mx extends sv{static get type(){return"TextureNode"}constructor(t,e=null,n=null,i=null){super(t),this.isTextureNode=!0,this.uvNode=e,this.levelNode=n,this.biasNode=i,this.compareNode=null,this.depthNode=null,this.gradNode=null,this.sampler=!0,this.updateMatrix=!1,this.updateType=Tf.NONE,this.referenceNode=null,this._value=t,this._matrixUniform=null,this.setUpdateMatrix(null===e)}set value(t){this.referenceNode?this.referenceNode.value=t:this._value=t}get value(){return this.referenceNode?this.referenceNode.value:this._value}getUniformHash(){return this.value.uuid}getNodeType(){return!0===this.value.isDepthTexture?"float":this.value.type===It?"uvec4":this.value.type===Rt?"ivec4":"vec4"}getInputType(){return"texture"}getDefaultUV(){return gx(this.value.channel)}updateReference(){return this.value}getTransformedUV(t){return null===this._matrixUniform&&(this._matrixUniform=rv(this.value.matrix)),this._matrixUniform.mul(Og(t,1)).xy}setUpdateMatrix(t){return this.updateMatrix=t,this.updateType=t?Tf.FRAME:Tf.NONE,this}setupUV(t,e){const n=this.value;return!t.isFlipY()||!0!==n.isRenderTargetTexture&&!0!==n.isFramebufferTexture&&!0!==n.isDepthTexture||(e=this.sampler?e.flipY():e.setY(Cg(yx(this,this.levelNode).y).sub(e.y).sub(1))),e}setup(t){const e=t.getNodeProperties(this);e.referenceNode=this.referenceNode;let n=this.uvNode;null!==n&&!0!==t.context.forceUVContext||!t.context.getUV||(n=t.context.getUV(this)),n||(n=this.getDefaultUV()),!0===this.updateMatrix&&(n=this.getTransformedUV(n)),n=this.setupUV(t,n);let i=this.levelNode;null===i&&t.context.getTextureLevel&&(i=t.context.getTextureLevel(this)),e.uvNode=n,e.levelNode=i,e.biasNode=this.biasNode,e.compareNode=this.compareNode,e.gradNode=this.gradNode,e.depthNode=this.depthNode}generateUV(t,e){return e.build(t,!0===this.sampler?"vec2":"ivec2")}generateSnippet(t,e,n,i,s,r,a,o){const l=this.value;let c;return c=i?t.generateTextureLevel(l,e,n,i,r):s?t.generateTextureBias(l,e,n,s,r):o?t.generateTextureGrad(l,e,n,o,r):a?t.generateTextureCompare(l,e,n,a,r):!1===this.sampler?t.generateTextureLoad(l,e,n,r):t.generateTexture(l,e,n,r),c}generate(t,e){const n=t.getNodeProperties(this),i=this.value;if(!i||!0!==i.isTexture)throw new Error("TextureNode: Need a three.js texture.");const s=super.generate(t,"property");if("sampler"===e)return s+"_sampler";if(t.isReference(e))return s;{const r=t.getDataFromNode(this);let a=r.propertyName;if(void 0===a){const{uvNode:e,levelNode:i,biasNode:o,compareNode:l,depthNode:c,gradNode:u}=n,h=this.generateUV(t,e),d=i?i.build(t,"float"):null,p=o?o.build(t,"float"):null,m=c?c.build(t,"int"):null,f=l?l.build(t,"float"):null,g=u?[u[0].build(t,"vec2"),u[1].build(t,"vec2")]:null,v=t.getVarFromNode(this);a=t.getPropertyName(v);const y=this.generateSnippet(t,s,h,d,p,m,f,g);t.addLineFlowCode(`${a} = ${y}`,this),r.snippet=y,r.propertyName=a}let o=a;const l=this.getNodeType(t);return t.needsToWorkingColorSpace(i)&&(o=F_(lx(o,l),i.colorSpace).setup(t).build(t,l)),t.format(o,l,e)}}setSampler(t){return this.sampler=t,this}getSampler(){return this.sampler}uv(t){const e=this.clone();return e.uvNode=gg(t),e.referenceNode=this.getSelf(),gg(e)}blur(t){const e=this.clone();return e.biasNode=gg(t).mul(xx(e)),e.referenceNode=this.getSelf(),gg(e)}level(t){const e=this.clone();return e.levelNode=gg(t),e.referenceNode=this.getSelf(),gg(e)}size(t){return yx(this,t)}bias(t){const e=this.clone();return e.biasNode=gg(t),e.referenceNode=this.getSelf(),gg(e)}compare(t){const e=this.clone();return e.compareNode=gg(t),e.referenceNode=this.getSelf(),gg(e)}grad(t,e){const n=this.clone();return n.gradNode=[gg(t),gg(e)],n.referenceNode=this.getSelf(),gg(n)}depth(t){const e=this.clone();return e.depthNode=gg(t),e.referenceNode=this.getSelf(),gg(e)}serialize(t){super.serialize(t),t.value=this.value.toJSON(t.meta).uuid,t.sampler=this.sampler,t.updateMatrix=this.updateMatrix,t.updateType=this.updateType}deserialize(t){super.deserialize(t),this.value=t.meta.textures[t.value],this.sampler=t.sampler,this.updateMatrix=t.updateMatrix,this.updateType=t.updateType}update(){const t=this.value,e=this._matrixUniform;null!==e&&(e.value=t.matrix),!0===t.matrixAutoUpdate&&t.updateMatrix()}clone(){const t=new this.constructor(this.value,this.uvNode,this.levelNode,this.biasNode);return t.sampler=this.sampler,t}}const bx=_g(Mx),Tx=(...t)=>bx(...t).setSampler(!1),Sx=t=>(!0===t.isNode?t:bx(t)).convert("sampler"),wx=rv("float").label("cameraNear").setGroup(nv).onRenderUpdate((({camera:t})=>t.near)),Ex=rv("float").label("cameraFar").setGroup(nv).onRenderUpdate((({camera:t})=>t.far)),Ax=rv("float").label("cameraLogDepth").setGroup(nv).onRenderUpdate((({camera:t})=>2/(Math.log(t.far+1)/Math.LN2))),Nx=rv("mat4").label("cameraProjectionMatrix").setGroup(nv).onRenderUpdate((({camera:t})=>t.projectionMatrix)),Cx=rv("mat4").label("cameraProjectionMatrixInverse").setGroup(nv).onRenderUpdate((({camera:t})=>t.projectionMatrixInverse)),Rx=rv("mat4").label("cameraViewMatrix").setGroup(nv).onRenderUpdate((({camera:t})=>t.matrixWorldInverse)),Ix=rv("mat4").label("cameraWorldMatrix").setGroup(nv).onRenderUpdate((({camera:t})=>t.matrixWorld)),Lx=rv("mat3").label("cameraNormalMatrix").setGroup(nv).onRenderUpdate((({camera:t})=>t.normalMatrix)),Px=rv(new Li).label("cameraPosition").setGroup(nv).onRenderUpdate((({camera:t},e)=>e.value.setFromMatrixPosition(t.matrixWorld)));class Ux extends Rf{static get type(){return"Object3DNode"}constructor(t,e=null){super(),this.scope=t,this.object3d=e,this.updateType=Tf.OBJECT,this._uniformNode=new sv(null)}getNodeType(){const t=this.scope;return t===Ux.WORLD_MATRIX?"mat4":t===Ux.POSITION||t===Ux.VIEW_POSITION||t===Ux.DIRECTION||t===Ux.SCALE?"vec3":void 0}update(t){const e=this.object3d,n=this._uniformNode,i=this.scope;if(i===Ux.WORLD_MATRIX)n.value=e.matrixWorld;else if(i===Ux.POSITION)n.value=n.value||new Li,n.value.setFromMatrixPosition(e.matrixWorld);else if(i===Ux.SCALE)n.value=n.value||new Li,n.value.setFromMatrixScale(e.matrixWorld);else if(i===Ux.DIRECTION)n.value=n.value||new Li,e.getWorldDirection(n.value);else if(i===Ux.VIEW_POSITION){const i=t.camera;n.value=n.value||new Li,n.value.setFromMatrixPosition(e.matrixWorld),n.value.applyMatrix4(i.matrixWorldInverse)}}generate(t){const e=this.scope;return e===Ux.WORLD_MATRIX?this._uniformNode.nodeType="mat4":e!==Ux.POSITION&&e!==Ux.VIEW_POSITION&&e!==Ux.DIRECTION&&e!==Ux.SCALE||(this._uniformNode.nodeType="vec3"),this._uniformNode.build(t)}serialize(t){super.serialize(t),t.scope=this.scope}deserialize(t){super.deserialize(t),this.scope=t.scope}}Ux.WORLD_MATRIX="worldMatrix",Ux.POSITION="position",Ux.SCALE="scale",Ux.VIEW_POSITION="viewPosition",Ux.DIRECTION="direction";const Dx=_g(Ux,Ux.DIRECTION),Ox=_g(Ux,Ux.WORLD_MATRIX),zx=_g(Ux,Ux.POSITION),Vx=_g(Ux,Ux.SCALE),Fx=_g(Ux,Ux.VIEW_POSITION);class Bx extends Ux{static get type(){return"ModelNode"}constructor(t){super(t)}update(t){this.object3d=t.object,super.update(t)}}const kx=xg(Bx,Bx.DIRECTION),Hx=xg(Bx,Bx.WORLD_MATRIX),Gx=xg(Bx,Bx.POSITION),Wx=xg(Bx,Bx.SCALE),jx=xg(Bx,Bx.VIEW_POSITION),Xx=rv(new ei).onObjectUpdate((({object:t},e)=>e.value.getNormalMatrix(t.matrixWorld))),qx=rv(new ls).onObjectUpdate((({object:t},e)=>e.value.copy(t.matrixWorld).invert())),Yx=Rx.mul(Hx).toVar("modelViewMatrix_2"),Zx=Mg((t=>(t.context.isHighPrecisionModelViewMatrix=!0,rv("mat4").onObjectUpdate((({object:t,camera:e})=>t.modelViewMatrix.multiplyMatrices(e.matrixWorldInverse,t.matrixWorld)))))).once()().toVar("highPrecisionModelViewMatrix"),$x=Mg((t=>{const e=t.context.isHighPrecisionModelViewMatrix;return rv("mat3").onObjectUpdate((({object:t,camera:n})=>(!0!==e&&t.modelViewMatrix.multiplyMatrices(n.matrixWorldInverse,t.matrixWorld),t.normalMatrix.getNormalMatrix(t.modelViewMatrix))))})).once()().toVar("highPrecisionModelNormalMatrix"),Jx=fx("position","vec3"),Kx=Jx.varying("positionLocal"),Qx=Jx.varying("positionPrevious"),tM=Hx.mul(Kx).xyz.varying("v_positionWorld"),eM=Kx.transformDirection(Hx).varying("v_positionWorldDirection").normalize().toVar("positionWorldDirection"),nM=Yx.mul(Kx).xyz.varying("v_positionView"),iM=nM.negate().varying("v_positionViewDirection").normalize().toVar("positionViewDirection");class sM extends Rf{static get type(){return"FrontFacingNode"}constructor(){super("bool"),this.isFrontFacingNode=!0}generate(t){const{renderer:e,material:n}=t;return e.coordinateSystem===Bn&&1===n.side?"false":t.getFrontFacing()}}const rM=xg(sM),aM=Ng(rM).mul(2).sub(1),oM=fx("normal","vec3"),lM=Mg((t=>!1===t.geometry.hasAttribute("normal")?(console.warn('TSL.NormalNode: Vertex attribute "normal" not found on geometry.'),Og(0,1,0)):oM),"vec3").once()().toVar("normalLocal"),cM=nM.dFdx().cross(nM.dFdy()).normalize().toVar("normalFlat"),uM=Mg((t=>{let e;return e=!0===t.material.flatShading?cM:R_(gM(lM),"v_normalView").normalize(),e}),"vec3").once()().toVar("normalView"),hM=R_(uM.transformDirection(Rx),"v_normalWorld").normalize().toVar("normalWorld"),dM=Mg((t=>t.context.setupNormal()),"vec3").once()().mul(aM).toVar("transformedNormalView"),pM=dM.transformDirection(Rx).toVar("transformedNormalWorld"),mM=Mg((t=>t.context.setupClearcoatNormal()),"vec3").once()().mul(aM).toVar("transformedClearcoatNormalView"),fM=Mg((([t,e=Hx])=>{const n=jg(e),i=t.div(Og(n[0].dot(n[0]),n[1].dot(n[1]),n[2].dot(n[2])));return n.mul(i).xyz})),gM=Mg((([t],e)=>{const n=e.renderer.nodes.modelNormalViewMatrix;if(null!==n)return n.transformDirection(t);const i=Xx.mul(t);return Rx.transformDirection(i)})),vM=rv(0).onReference((({material:t})=>t)).onRenderUpdate((({material:t})=>t.refractionRatio)),yM=iM.negate().reflect(dM),_M=iM.negate().refract(dM,vM),xM=yM.transformDirection(Rx).toVar("reflectVector"),MM=_M.transformDirection(Rx).toVar("reflectVector");class bM extends Mx{static get type(){return"CubeTextureNode"}constructor(t,e=null,n=null,i=null){super(t,e,n,i),this.isCubeTextureNode=!0}getInputType(){return"cubeTexture"}getDefaultUV(){const t=this.value;return t.mapping===lt?xM:t.mapping===ct?MM:(console.error('THREE.CubeTextureNode: Mapping "%s" not supported.',t.mapping),Og(0,0,0))}setUpdateMatrix(){}setupUV(t,e){const n=this.value;return t.renderer.coordinateSystem!==kn&&n.isRenderTargetTexture?e:Og(e.x.negate(),e.yz)}generateUV(t,e){return e.build(t,"vec3")}}const TM=_g(bM);class SM extends sv{static get type(){return"BufferNode"}constructor(t,e,n=0){super(t,e),this.isBufferNode=!0,this.bufferType=e,this.bufferCount=n}getElementType(t){return this.getNodeType(t)}getInputType(){return"buffer"}}const wM=(t,e,n)=>gg(new SM(t,e,n));class EM extends If{static get type(){return"UniformArrayElementNode"}constructor(t,e){super(t,e),this.isArrayBufferElementNode=!0}generate(t){const e=super.generate(t),n=this.getNodeType();return t.format(e,"vec4",n)}}class AM extends SM{static get type(){return"UniformArrayNode"}constructor(t,e=null){super(null,"vec4"),this.array=t,this.elementType=e,this._elementType=null,this._elementLength=0,this.updateType=Tf.RENDER,this.isArrayBufferNode=!0}getElementType(){return this.elementType||this._elementType}getElementLength(){return this._elementLength}update(){const{array:t,value:e}=this,n=this.getElementLength(),i=this.getElementType();if(1===n)for(let n=0;ngg(new AM(t,e)),CM=(t,e)=>(console.warn("TSL.UniformArrayNode: uniforms() has been renamed to uniformArray()."),gg(new AM(t,e)));class RM extends If{static get type(){return"ReferenceElementNode"}constructor(t,e){super(t,e),this.referenceNode=t,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(t){const e=super.generate(t),n=this.referenceNode.getNodeType(),i=this.getNodeType();return t.format(e,n,i)}}class IM extends Rf{static get type(){return"ReferenceNode"}constructor(t,e,n=null,i=null){super(),this.property=t,this.uniformType=e,this.object=n,this.count=i,this.properties=t.split("."),this.reference=n,this.node=null,this.group=null,this.name=null,this.updateType=Tf.OBJECT}element(t){return gg(new RM(this,gg(t)))}setGroup(t){return this.group=t,this}label(t){return this.name=t,this}setNodeType(t){let e=null;e=null!==this.count?wM(null,t,this.count):Array.isArray(this.getValueFromReference())?NM(null,t):"texture"===t?bx(null):"cubeTexture"===t?TM(null):rv(null,t),null!==this.group&&e.setGroup(this.group),null!==this.name&&e.label(this.name),this.node=e.getSelf()}getNodeType(t){return null===this.node&&(this.updateReference(t),this.updateValue()),this.node.getNodeType(t)}getValueFromReference(t=this.reference){const{properties:e}=this;let n=t[e[0]];for(let t=1;tgg(new IM(t,e,n)),PM=(t,e,n,i)=>gg(new IM(t,e,i,n));class UM extends IM{static get type(){return"MaterialReferenceNode"}constructor(t,e,n=null){super(t,e,n),this.material=n,this.isMaterialReferenceNode=!0}updateReference(t){return this.reference=null!==this.material?this.material:t.material,this.reference}}const DM=(t,e,n)=>gg(new UM(t,e,n)),OM=Mg((t=>(!1===t.geometry.hasAttribute("tangent")&&t.geometry.computeTangents(),fx("tangent","vec4"))))(),zM=OM.xyz.toVar("tangentLocal"),VM=Yx.mul(Bg(zM,0)).xyz.varying("v_tangentView").normalize().toVar("tangentView"),FM=VM.transformDirection(Rx).varying("v_tangentWorld").normalize().toVar("tangentWorld"),BM=VM.toVar("transformedTangentView"),kM=BM.transformDirection(Rx).normalize().toVar("transformedTangentWorld"),HM=t=>t.mul(OM.w).xyz,GM=R_(HM(oM.cross(OM)),"v_bitangentGeometry").normalize().toVar("bitangentGeometry"),WM=R_(HM(lM.cross(zM)),"v_bitangentLocal").normalize().toVar("bitangentLocal"),jM=R_(HM(uM.cross(VM)),"v_bitangentView").normalize().toVar("bitangentView"),XM=R_(HM(hM.cross(FM)),"v_bitangentWorld").normalize().toVar("bitangentWorld"),qM=HM(dM.cross(BM)).normalize().toVar("transformedBitangentView"),YM=qM.transformDirection(Rx).normalize().toVar("transformedBitangentWorld"),ZM=jg(VM,jM,uM),$M=iM.mul(ZM),JM=(t,e)=>t.sub($M.mul(e)),KM=(()=>{let t=Tv.cross(iM);return t=t.cross(Tv).normalize(),t=d_(t,dM,Mv.mul(hv.oneMinus()).oneMinus().pow2().pow2()).normalize(),t})(),QM=Mg((t=>{const{eye_pos:e,surf_norm:n,mapN:i,uv:s}=t,r=e.dFdx(),a=e.dFdy(),o=s.dFdx(),l=s.dFdy(),c=n,u=a.cross(c),h=c.cross(r),d=u.mul(o.x).add(h.mul(l.x)),p=u.mul(o.y).add(h.mul(l.y)),m=d.dot(d).max(p.dot(p)),f=aM.mul(m.inverseSqrt());return Hv(d.mul(i.x,f),p.mul(i.y,f),c.mul(i.z)).normalize()}));class tb extends Pf{static get type(){return"NormalMapNode"}constructor(t,e=null){super("vec3"),this.node=t,this.scaleNode=e,this.normalMapType=0}setup(t){const{normalMapType:e,scaleNode:n}=this;let i=this.node.mul(2).sub(1);null!==n&&(i=Og(i.xy.mul(n),i.z));let s=null;if(1===e)s=gM(i);else if(0===e){s=!0===t.hasGeometryAttribute("tangent")?ZM.mul(i).normalize():QM({eye_pos:nM,surf_norm:uM,mapN:i,uv:gx()})}return s}}const eb=_g(tb),nb=Mg((({textureNode:t,bumpScale:e})=>{const n=e=>t.cache().context({getUV:t=>e(t.uvNode||gx()),forceUVContext:!0}),i=Ng(n((t=>t)));return Lg(Ng(n((t=>t.add(t.dFdx())))).sub(i),Ng(n((t=>t.add(t.dFdy())))).sub(i)).mul(e)})),ib=Mg((t=>{const{surf_pos:e,surf_norm:n,dHdxy:i}=t,s=e.dFdx().normalize(),r=n,a=e.dFdy().normalize().cross(r),o=r.cross(s),l=s.dot(a).mul(aM),c=l.sign().mul(i.x.mul(a).add(i.y.mul(o)));return l.abs().mul(n).sub(c).normalize()}));class sb extends Pf{static get type(){return"BumpMapNode"}constructor(t,e=null){super("vec3"),this.textureNode=t,this.scaleNode=e}setup(){const t=null!==this.scaleNode?this.scaleNode:1,e=nb({textureNode:this.textureNode,bumpScale:t});return ib({surf_pos:nM,surf_norm:uM,dHdxy:e})}}const rb=_g(sb),ab=new Map;class ob extends Rf{static get type(){return"MaterialNode"}constructor(t){super(),this.scope=t}getCache(t,e){let n=ab.get(t);return void 0===n&&(n=DM(t,e),ab.set(t,n)),n}getFloat(t){return this.getCache(t,"float")}getColor(t){return this.getCache(t,"color")}getTexture(t){return this.getCache("map"===t?"map":t+"Map","texture")}setup(t){const e=t.context.material,n=this.scope;let i=null;if(n===ob.COLOR){const t=void 0!==e.color?this.getColor(n):Og();i=e.map&&!0===e.map.isTexture?t.mul(this.getTexture("map")):t}else if(n===ob.OPACITY){const t=this.getFloat(n);i=e.alphaMap&&!0===e.alphaMap.isTexture?t.mul(this.getTexture("alpha")):t}else if(n===ob.SPECULAR_STRENGTH)i=e.specularMap&&!0===e.specularMap.isTexture?this.getTexture("specular").r:Ng(1);else if(n===ob.SPECULAR_INTENSITY){const t=this.getFloat(n);i=e.specularMap?t.mul(this.getTexture(n).a):t}else if(n===ob.SPECULAR_COLOR){const t=this.getColor(n);i=e.specularColorMap&&!0===e.specularColorMap.isTexture?t.mul(this.getTexture(n).rgb):t}else if(n===ob.ROUGHNESS){const t=this.getFloat(n);i=e.roughnessMap&&!0===e.roughnessMap.isTexture?t.mul(this.getTexture(n).g):t}else if(n===ob.METALNESS){const t=this.getFloat(n);i=e.metalnessMap&&!0===e.metalnessMap.isTexture?t.mul(this.getTexture(n).b):t}else if(n===ob.EMISSIVE){const t=this.getFloat("emissiveIntensity"),s=this.getColor(n).mul(t);i=e.emissiveMap&&!0===e.emissiveMap.isTexture?s.mul(this.getTexture(n)):s}else if(n===ob.NORMAL)e.normalMap?(i=eb(this.getTexture("normal"),this.getCache("normalScale","vec2")),i.normalMapType=e.normalMapType):i=e.bumpMap?rb(this.getTexture("bump").r,this.getFloat("bumpScale")):uM;else if(n===ob.CLEARCOAT){const t=this.getFloat(n);i=e.clearcoatMap&&!0===e.clearcoatMap.isTexture?t.mul(this.getTexture(n).r):t}else if(n===ob.CLEARCOAT_ROUGHNESS){const t=this.getFloat(n);i=e.clearcoatRoughnessMap&&!0===e.clearcoatRoughnessMap.isTexture?t.mul(this.getTexture(n).r):t}else if(n===ob.CLEARCOAT_NORMAL)i=e.clearcoatNormalMap?eb(this.getTexture(n),this.getCache(n+"Scale","vec2")):uM;else if(n===ob.SHEEN){const t=this.getColor("sheenColor").mul(this.getFloat("sheen"));i=e.sheenColorMap&&!0===e.sheenColorMap.isTexture?t.mul(this.getTexture("sheenColor").rgb):t}else if(n===ob.SHEEN_ROUGHNESS){const t=this.getFloat(n);i=e.sheenRoughnessMap&&!0===e.sheenRoughnessMap.isTexture?t.mul(this.getTexture(n).a):t,i=i.clamp(.07,1)}else if(n===ob.ANISOTROPY)if(e.anisotropyMap&&!0===e.anisotropyMap.isTexture){const t=this.getTexture(n);i=Wg(jb.x,jb.y,jb.y.negate(),jb.x).mul(t.rg.mul(2).sub(Lg(1)).normalize().mul(t.b))}else i=jb;else if(n===ob.IRIDESCENCE_THICKNESS){const t=LM("1","float",e.iridescenceThicknessRange);if(e.iridescenceThicknessMap){const s=LM("0","float",e.iridescenceThicknessRange);i=t.sub(s).mul(this.getTexture(n).g).add(s)}else i=t}else if(n===ob.TRANSMISSION){const t=this.getFloat(n);i=e.transmissionMap?t.mul(this.getTexture(n).r):t}else if(n===ob.THICKNESS){const t=this.getFloat(n);i=e.thicknessMap?t.mul(this.getTexture(n).g):t}else if(n===ob.IOR)i=this.getFloat(n);else if(n===ob.LIGHT_MAP)i=this.getTexture(n).rgb.mul(this.getFloat("lightMapIntensity"));else if(n===ob.AO_MAP)i=this.getTexture(n).r.sub(1).mul(this.getFloat("aoMapIntensity")).add(1);else{const e=this.getNodeType(t);i=this.getCache(n,e)}return i}}ob.ALPHA_TEST="alphaTest",ob.COLOR="color",ob.OPACITY="opacity",ob.SHININESS="shininess",ob.SPECULAR="specular",ob.SPECULAR_STRENGTH="specularStrength",ob.SPECULAR_INTENSITY="specularIntensity",ob.SPECULAR_COLOR="specularColor",ob.REFLECTIVITY="reflectivity",ob.ROUGHNESS="roughness",ob.METALNESS="metalness",ob.NORMAL="normal",ob.CLEARCOAT="clearcoat",ob.CLEARCOAT_ROUGHNESS="clearcoatRoughness",ob.CLEARCOAT_NORMAL="clearcoatNormal",ob.EMISSIVE="emissive",ob.ROTATION="rotation",ob.SHEEN="sheen",ob.SHEEN_ROUGHNESS="sheenRoughness",ob.ANISOTROPY="anisotropy",ob.IRIDESCENCE="iridescence",ob.IRIDESCENCE_IOR="iridescenceIOR",ob.IRIDESCENCE_THICKNESS="iridescenceThickness",ob.IOR="ior",ob.TRANSMISSION="transmission",ob.THICKNESS="thickness",ob.ATTENUATION_DISTANCE="attenuationDistance",ob.ATTENUATION_COLOR="attenuationColor",ob.LINE_SCALE="scale",ob.LINE_DASH_SIZE="dashSize",ob.LINE_GAP_SIZE="gapSize",ob.LINE_WIDTH="linewidth",ob.LINE_DASH_OFFSET="dashOffset",ob.POINT_WIDTH="pointWidth",ob.DISPERSION="dispersion",ob.LIGHT_MAP="light",ob.AO_MAP="ao";const lb=xg(ob,ob.ALPHA_TEST),cb=xg(ob,ob.COLOR),ub=xg(ob,ob.SHININESS),hb=xg(ob,ob.EMISSIVE),db=xg(ob,ob.OPACITY),pb=xg(ob,ob.SPECULAR),mb=xg(ob,ob.SPECULAR_INTENSITY),fb=xg(ob,ob.SPECULAR_COLOR),gb=xg(ob,ob.SPECULAR_STRENGTH),vb=xg(ob,ob.REFLECTIVITY),yb=xg(ob,ob.ROUGHNESS),_b=xg(ob,ob.METALNESS),xb=xg(ob,ob.NORMAL).context({getUV:null}),Mb=xg(ob,ob.CLEARCOAT),bb=xg(ob,ob.CLEARCOAT_ROUGHNESS),Tb=xg(ob,ob.CLEARCOAT_NORMAL).context({getUV:null}),Sb=xg(ob,ob.ROTATION),wb=xg(ob,ob.SHEEN),Eb=xg(ob,ob.SHEEN_ROUGHNESS),Ab=xg(ob,ob.ANISOTROPY),Nb=xg(ob,ob.IRIDESCENCE),Cb=xg(ob,ob.IRIDESCENCE_IOR),Rb=xg(ob,ob.IRIDESCENCE_THICKNESS),Ib=xg(ob,ob.TRANSMISSION),Lb=xg(ob,ob.THICKNESS),Pb=xg(ob,ob.IOR),Ub=xg(ob,ob.ATTENUATION_DISTANCE),Db=xg(ob,ob.ATTENUATION_COLOR),Ob=xg(ob,ob.LINE_SCALE),zb=xg(ob,ob.LINE_DASH_SIZE),Vb=xg(ob,ob.LINE_GAP_SIZE),Fb=xg(ob,ob.LINE_WIDTH),Bb=xg(ob,ob.LINE_DASH_OFFSET),kb=xg(ob,ob.POINT_WIDTH),Hb=xg(ob,ob.DISPERSION),Gb=xg(ob,ob.LIGHT_MAP),Wb=xg(ob,ob.AO_MAP),jb=rv(new ti).onReference((function(t){return t.material})).onRenderUpdate((function({material:t}){this.value.set(t.anisotropy*Math.cos(t.anisotropyRotation),t.anisotropy*Math.sin(t.anisotropyRotation))}));class Xb extends Pf{static get type(){return"ModelViewProjectionNode"}constructor(t=null){super("vec4"),this.positionNode=t}setup(t){if("fragment"===t.shaderStage)return R_(t.context.mvp);const e=this.positionNode||Kx,n=t.renderer.nodes.modelViewMatrix||Yx;return Nx.mul(n).mul(e)}}const qb=_g(Xb);class Yb extends Rf{static get type(){return"IndexNode"}constructor(t){super("uint"),this.scope=t,this.isInstanceIndexNode=!0}generate(t){const e=this.getNodeType(t),n=this.scope;let i,s;if(n===Yb.VERTEX)i=t.getVertexIndex();else if(n===Yb.INSTANCE)i=t.getInstanceIndex();else if(n===Yb.DRAW)i=t.getDrawIndex();else if(n===Yb.INVOCATION_LOCAL)i=t.getInvocationLocalIndex();else if(n===Yb.INVOCATION_SUBGROUP)i=t.getInvocationSubgroupIndex();else{if(n!==Yb.SUBGROUP)throw new Error("THREE.IndexNode: Unknown scope: "+n);i=t.getSubgroupIndex()}if("vertex"===t.shaderStage||"compute"===t.shaderStage)s=i;else{s=R_(this).build(t,e)}return s}}Yb.VERTEX="vertex",Yb.INSTANCE="instance",Yb.SUBGROUP="subgroup",Yb.INVOCATION_LOCAL="invocationLocal",Yb.INVOCATION_SUBGROUP="invocationSubgroup",Yb.DRAW="draw";const Zb=xg(Yb,Yb.VERTEX),$b=xg(Yb,Yb.INSTANCE),Jb=xg(Yb,Yb.SUBGROUP),Kb=xg(Yb,Yb.INVOCATION_SUBGROUP),Qb=xg(Yb,Yb.INVOCATION_LOCAL),tT=xg(Yb,Yb.DRAW);class eT extends Rf{static get type(){return"InstanceNode"}constructor(t){super("void"),this.instanceMesh=t,this.instanceMatrixNode=null,this.instanceColorNode=null,this.updateType=Tf.FRAME,this.buffer=null,this.bufferColor=null}setup(t){let e=this.instanceMatrixNode,n=this.instanceColorNode;const i=this.instanceMesh;if(null===e){const t=i.instanceMatrix;if(i.count<=1e3)e=wM(t.array,"mat4",Math.max(i.count,1)).element($b);else{const n=new mm(t.array,16,1);this.buffer=n;const i=t.usage===Rn?J_:$_,s=[i(n,"vec4",16,0),i(n,"vec4",16,4),i(n,"vec4",16,8),i(n,"vec4",16,12)];e=Xg(...s)}this.instanceMatrixNode=e}const s=i.instanceColor;if(s&&null===n){const t=new jc(s.array,3),e=s.usage===Rn?J_:$_;this.bufferColor=t,n=Og(e(t,"vec3",3,0)),this.instanceColorNode=n}const r=e.mul(Kx).xyz;if(Kx.assign(r),t.hasGeometryAttribute("normal")){const t=fM(lM,e);lM.assign(t)}null!==this.instanceColorNode&&lv("vec3","vInstanceColor").assign(this.instanceColorNode)}update(){this.instanceMesh.instanceMatrix.usage!==Rn&&null!=this.buffer&&this.instanceMesh.instanceMatrix.version!==this.buffer.version&&(this.buffer.version=this.instanceMesh.instanceMatrix.version),this.instanceMesh.instanceColor&&this.instanceMesh.instanceColor.usage!==Rn&&null!=this.bufferColor&&this.instanceMesh.instanceColor.version!==this.bufferColor.version&&(this.bufferColor.version=this.instanceMesh.instanceColor.version)}}const nT=_g(eT);class iT extends Rf{static get type(){return"BatchNode"}constructor(t){super("void"),this.batchMesh=t,this.batchingIdNode=null}setup(t){null===this.batchingIdNode&&(null===t.getDrawIndex()?this.batchingIdNode=$b:this.batchingIdNode=tT);const e=Mg((([t])=>{const e=yx(Tx(this.batchMesh._indirectTexture),0),n=Cg(t).modInt(Cg(e)),i=Cg(t).div(Cg(e));return Tx(this.batchMesh._indirectTexture,Pg(n,i)).x})).setLayout({name:"getIndirectIndex",type:"uint",inputs:[{name:"id",type:"int"}]}),n=e(Cg(this.batchingIdNode)),i=this.batchMesh._matricesTexture,s=yx(Tx(i),0),r=Ng(n).mul(4).toInt().toVar(),a=r.modInt(s),o=r.div(Cg(s)),l=Xg(Tx(i,Pg(a,o)),Tx(i,Pg(a.add(1),o)),Tx(i,Pg(a.add(2),o)),Tx(i,Pg(a.add(3),o))),c=this.batchMesh._colorsTexture;if(null!==c){const t=Mg((([t])=>{const e=yx(Tx(c),0).x,n=t,i=n.modInt(e),s=n.div(e);return Tx(c,Pg(i,s)).rgb})).setLayout({name:"getBatchingColor",type:"vec3",inputs:[{name:"id",type:"int"}]}),e=t(n);lv("vec3","vBatchColor").assign(e)}const u=jg(l);Kx.assign(l.mul(Kx));const h=lM.div(Og(u[0].dot(u[0]),u[1].dot(u[1]),u[2].dot(u[2]))),d=u.mul(h).xyz;lM.assign(d),t.hasGeometryAttribute("tangent")&&zM.mulAssign(u)}}const sT=_g(iT),rT=new WeakMap;class aT extends Rf{static get type(){return"SkinningNode"}constructor(t,e=!1){let n,i,s;super("void"),this.skinnedMesh=t,this.useReference=e,this.updateType=Tf.OBJECT,this.skinIndexNode=fx("skinIndex","uvec4"),this.skinWeightNode=fx("skinWeight","vec4"),e?(n=LM("bindMatrix","mat4"),i=LM("bindMatrixInverse","mat4"),s=PM("skeleton.boneMatrices","mat4",t.skeleton.bones.length)):(n=rv(t.bindMatrix,"mat4"),i=rv(t.bindMatrixInverse,"mat4"),s=wM(t.skeleton.boneMatrices,"mat4",t.skeleton.bones.length)),this.bindMatrixNode=n,this.bindMatrixInverseNode=i,this.boneMatricesNode=s,this.previousBoneMatricesNode=null}getSkinnedPosition(t=this.boneMatricesNode,e=Kx){const{skinIndexNode:n,skinWeightNode:i,bindMatrixNode:s,bindMatrixInverseNode:r}=this,a=t.element(n.x),o=t.element(n.y),l=t.element(n.z),c=t.element(n.w),u=s.mul(e),h=Hv(a.mul(i.x).mul(u),o.mul(i.y).mul(u),l.mul(i.z).mul(u),c.mul(i.w).mul(u));return r.mul(h).xyz}getSkinnedNormal(t=this.boneMatricesNode,e=lM){const{skinIndexNode:n,skinWeightNode:i,bindMatrixNode:s,bindMatrixInverseNode:r}=this,a=t.element(n.x),o=t.element(n.y),l=t.element(n.z),c=t.element(n.w);let u=Hv(i.x.mul(a),i.y.mul(o),i.z.mul(l),i.w.mul(c));return u=r.mul(u).mul(s),u.transformDirection(e).xyz}getPreviousSkinnedPosition(t){const e=t.object;return null===this.previousBoneMatricesNode&&(e.skeleton.previousBoneMatrices=new Float32Array(e.skeleton.boneMatrices),this.previousBoneMatricesNode=PM("skeleton.previousBoneMatrices","mat4",e.skeleton.bones.length)),this.getSkinnedPosition(this.previousBoneMatricesNode,Qx)}needsPreviousBoneMatrices(t){const e=t.renderer.getMRT();return e&&e.has("velocity")}setup(t){this.needsPreviousBoneMatrices(t)&&Qx.assign(this.getPreviousSkinnedPosition(t));const e=this.getSkinnedPosition();if(Kx.assign(e),t.hasGeometryAttribute("normal")){const e=this.getSkinnedNormal();lM.assign(e),t.hasGeometryAttribute("tangent")&&zM.assign(e)}}generate(t,e){if("void"!==e)return Kx.build(t,e)}update(t){const e=(this.useReference?t.object:this.skinnedMesh).skeleton;rT.get(e)!==t.frameId&&(rT.set(e,t.frameId),null!==this.previousBoneMatricesNode&&e.previousBoneMatrices.set(e.boneMatrices),e.update())}}const oT=t=>gg(new aT(t)),lT=t=>gg(new aT(t,!0));class cT extends Rf{static get type(){return"LoopNode"}constructor(t=[]){super(),this.params=t}getVarName(t){return String.fromCharCode("i".charCodeAt()+t)}getProperties(t){const e=t.getNodeProperties(this);if(void 0!==e.stackNode)return e;const n={};for(let t=0,e=this.params.length-1;tNumber(r)?">=":"<"));const u={start:s,end:r,condition:l},h=u.start,d=u.end;let p="",m="",f="";c||(c="int"===o||"uint"===o?l.includes("<")?"++":"--":l.includes("<")?"+= 1.":"-= 1."),p+=t.getVar(o,a)+" = "+h,m+=a+" "+l+" "+d,f+=a+" "+c;const g=`for ( ${p}; ${m}; ${f} )`;t.addFlowCode((0===e?"\n":"")+t.tab+g+" {\n\n").addFlowTab()}const s=i.build(t,"void"),r=e.returnsNode?e.returnsNode.build(t):"";t.removeFlowTab().addFlowCode("\n"+t.tab+s);for(let e=0,n=this.params.length-1;egg(new cT(yg(t,"int"))).append(),hT=()=>lx("continue").append(),dT=()=>lx("break").append(),pT=(...t)=>(console.warn("TSL.LoopNode: loop() has been renamed to Loop()."),uT(...t)),mT=new WeakMap,fT=new Si,gT=Mg((({bufferMap:t,influence:e,stride:n,width:i,depth:s,offset:r})=>{const a=Cg(Zb).mul(n).add(r),o=a.div(i),l=a.sub(o.mul(i));return Tx(t,Pg(l,o)).depth(s).mul(e)}));class vT extends Rf{static get type(){return"MorphNode"}constructor(t){super("void"),this.mesh=t,this.morphBaseInfluence=rv(1),this.updateType=Tf.OBJECT}setup(t){const{geometry:e}=t,n=void 0!==e.morphAttributes.position,i=e.hasAttribute("normal")&&void 0!==e.morphAttributes.normal,s=e.morphAttributes.position||e.morphAttributes.normal||e.morphAttributes.color,r=void 0!==s?s.length:0,{texture:a,stride:o,size:l}=function(t){const e=void 0!==t.morphAttributes.position,n=void 0!==t.morphAttributes.normal,i=void 0!==t.morphAttributes.color,s=t.morphAttributes.position||t.morphAttributes.normal||t.morphAttributes.color,r=void 0!==s?s.length:0;let a=mT.get(t);if(void 0===a||a.count!==r){void 0!==a&&a.texture.dispose();const o=t.morphAttributes.position||[],l=t.morphAttributes.normal||[],c=t.morphAttributes.color||[];let u=0;!0===e&&(u=1),!0===n&&(u=2),!0===i&&(u=3);let h=t.attributes.position.count*u,d=1;const p=4096;h>p&&(d=Math.ceil(h/p),h=p);const m=new Float32Array(h*d*4*r),f=new Ai(m,h,d,r);f.type=Lt,f.needsUpdate=!0;const g=4*u;for(let y=0;y{const e=Ng(0).toVar();this.mesh.count>1&&null!==this.mesh.morphTexture&&void 0!==this.mesh.morphTexture?e.assign(Tx(this.mesh.morphTexture,Pg(Cg(t).add(1),Cg($b))).r):e.assign(LM("morphTargetInfluences","float").element(t).toVar()),!0===n&&Kx.addAssign(gT({bufferMap:a,influence:e,stride:o,width:c,depth:t,offset:Cg(0)})),!0===i&&lM.addAssign(gT({bufferMap:a,influence:e,stride:o,width:c,depth:t,offset:Cg(1)}))}))}update(){const t=this.morphBaseInfluence;this.mesh.geometry.morphTargetsRelative?t.value=1:t.value=1-this.mesh.morphTargetInfluences.reduce(((t,e)=>t+e),0)}}const yT=_g(vT),_T=(t,e)=>{for(const n of e)if(n.isAnalyticLightNode&&n.light.id===t)return n;return null},xT=new WeakMap;class MT extends Rf{static get type(){return"LightsNode"}constructor(t=[]){super("vec3"),this.totalDiffuseNode=Og().toVar("totalDiffuse"),this.totalSpecularNode=Og().toVar("totalSpecular"),this.outgoingLightNode=Og().toVar("outgoingLight"),this._lights=t,this._lightNodes=null,this._lightNodesHash=null,this.global=!0}getHash(t){if(null===this._lightNodesHash){null===this._lightNodes&&this.setupLightsNode(t);const e=[];for(const t of this._lightNodes)e.push(t.getHash());this._lightNodesHash="lights-"+e.join(",")}return this._lightNodesHash}analyze(t){const e=t.getDataFromNode(this);for(const n of e.nodes)n.build(t)}setupLightsNode(t){const e=[],n=this._lightNodes,i=(t=>t.sort(((t,e)=>t.id-e.id)))(this._lights),s=t.renderer.nodes.library;for(const t of i)if(t.isNode)e.push(gg(t));else{let i=null;if(null!==n&&(i=_T(t.id,n)),null===i){const n=s.getLightNodeClass(t.constructor);if(null===n){console.warn(`LightsNode.setupNodeLights: Light node not found for ${t.constructor.name}`);continue}let i=null;xT.has(t)?i=xT.get(t):(i=new n(t),xT.set(t,i)),e.push(i)}}this._lightNodes=e}setup(t){null===this._lightNodes&&this.setupLightsNode(t);const e=t.context,n=e.lightingModel;let i=this.outgoingLightNode;if(n){const{_lightNodes:s,totalDiffuseNode:r,totalSpecularNode:a}=this;e.outgoingLight=i;const o=t.addStack();t.getDataFromNode(this).nodes=o.nodes,n.start(e,o,t);for(const e of s)e.build(t);n.indirect(e,o,t);const{backdrop:l,backdropAlpha:c}=e,{directDiffuse:u,directSpecular:h,indirectDiffuse:d,indirectSpecular:p}=e.reflectedLight;let m=u.add(d);null!==l&&(m=Og(null!==c?c.mix(m,l):l),e.material.transparent=!0),r.assign(m),a.assign(h.add(p)),i.assign(r.add(a)),n.finish(e,o,t),i=i.bypass(t.removeStack())}return i}setLights(t){return this._lights=t,this._lightNodes=null,this._lightNodesHash=null,this}getLights(){return this._lights}}const bT=_g(MT);class TT extends Rf{static get type(){return"LightingNode"}constructor(){super("vec3"),this.isLightingNode=!0}generate(){console.warn("Abstract function.")}}class ST extends TT{static get type(){return"AONode"}constructor(t=null){super(),this.aoNode=t}setup(t){t.context.ambientOcclusion.mulAssign(this.aoNode)}}class wT extends S_{static get type(){return"LightingContextNode"}constructor(t,e=null,n=null,i=null){super(t),this.lightingModel=e,this.backdropNode=n,this.backdropAlphaNode=i,this._value=null}getContext(){const{backdropNode:t,backdropAlphaNode:e}=this,n={directDiffuse:Og().toVar("directDiffuse"),directSpecular:Og().toVar("directSpecular"),indirectDiffuse:Og().toVar("indirectDiffuse"),indirectSpecular:Og().toVar("indirectSpecular")};return{radiance:Og().toVar("radiance"),irradiance:Og().toVar("irradiance"),iblIrradiance:Og().toVar("iblIrradiance"),ambientOcclusion:Ng(1).toVar("ambientOcclusion"),reflectedLight:n,backdrop:t,backdropAlpha:e}}setup(t){return this.value=this._value||(this._value=this.getContext()),this.value.lightingModel=this.lightingModel||t.context.lightingModel,super.setup(t)}}const ET=_g(wT);class AT extends TT{static get type(){return"IrradianceNode"}constructor(t){super(),this.node=t}setup(t){t.context.irradiance.addAssign(this.node)}}let NT,CT;class RT extends Rf{static get type(){return"ScreenNode"}constructor(t){super(),this.scope=t,this.isViewportNode=!0}getNodeType(){return this.scope===RT.VIEWPORT?"vec4":"vec2"}getUpdateType(){let t=Tf.NONE;return this.scope!==RT.SIZE&&this.scope!==RT.VIEWPORT||(t=Tf.RENDER),this.updateType=t,t}update({renderer:t}){const e=t.getRenderTarget();this.scope===RT.VIEWPORT?null!==e?CT.copy(e.viewport):(t.getViewport(CT),CT.multiplyScalar(t.getPixelRatio())):null!==e?(NT.width=e.width,NT.height=e.height):t.getDrawingBufferSize(NT)}setup(){const t=this.scope;let e=null;return e=t===RT.SIZE?rv(NT||(NT=new ti)):t===RT.VIEWPORT?rv(CT||(CT=new Si)):Lg(PT.div(LT)),e}generate(t){if(this.scope===RT.COORDINATE){let e=t.getFragCoord();if(t.isFlipY()){const n=t.getNodeProperties(LT).outputNode.build(t);e=`${t.getType("vec2")}( ${e}.x, ${n}.y - ${e}.y )`}return e}return super.generate(t)}}RT.COORDINATE="coordinate",RT.VIEWPORT="viewport",RT.SIZE="size",RT.UV="uv";const IT=xg(RT,RT.UV),LT=xg(RT,RT.SIZE),PT=xg(RT,RT.COORDINATE),UT=xg(RT,RT.VIEWPORT),DT=UT.zw,OT=PT.sub(UT.xy),zT=OT.div(DT),VT=Mg((()=>(console.warn('TSL.ViewportNode: "viewportResolution" is deprecated. Use "screenSize" instead.'),LT)),"vec2").once()(),FT=Mg((()=>(console.warn('TSL.ViewportNode: "viewportTopLeft" is deprecated. Use "screenUV" instead.'),IT)),"vec2").once()(),BT=Mg((()=>(console.warn('TSL.ViewportNode: "viewportBottomLeft" is deprecated. Use "screenUV.flipY()" instead.'),IT.flipY())),"vec2").once()(),kT=new ti;class HT extends Mx{static get type(){return"ViewportTextureNode"}constructor(t=IT,e=null,n=null){null===n&&((n=new ku).minFilter=St),super(n,t,e),this.generateMipmaps=!1,this.isOutputTextureNode=!0,this.updateBeforeType=Tf.FRAME}updateBefore(t){const e=t.renderer;e.getDrawingBufferSize(kT);const n=this.value;n.image.width===kT.width&&n.image.height===kT.height||(n.image.width=kT.width,n.image.height=kT.height,n.needsUpdate=!0);const i=n.generateMipmaps;n.generateMipmaps=this.generateMipmaps,e.copyFramebufferToTexture(n),n.generateMipmaps=i}clone(){const t=new this.constructor(this.uvNode,this.levelNode,this.value);return t.generateMipmaps=this.generateMipmaps,t}}const GT=_g(HT),WT=_g(HT,null,null,{generateMipmaps:!0});let jT=null;class XT extends HT{static get type(){return"ViewportDepthTextureNode"}constructor(t=IT,e=null){null===jT&&(jT=new Ka),super(t,e,jT)}}const qT=_g(XT);class YT extends Rf{static get type(){return"ViewportDepthNode"}constructor(t,e=null){super("float"),this.scope=t,this.valueNode=e,this.isViewportDepthNode=!0}generate(t){const{scope:e}=this;return e===YT.DEPTH_BASE?t.getFragDepth():super.generate(t)}setup({camera:t}){const{scope:e}=this,n=this.valueNode;let i=null;if(e===YT.DEPTH_BASE)null!==n&&(i=QT().assign(n));else if(e===YT.DEPTH)i=t.isPerspectiveCamera?JT(nM.z,wx,Ex):ZT(nM.z,wx,Ex);else if(e===YT.LINEAR_DEPTH)if(null!==n)if(t.isPerspectiveCamera){const t=KT(n,wx,Ex);i=ZT(t,wx,Ex)}else i=n;else i=ZT(nM.z,wx,Ex);return i}}YT.DEPTH_BASE="depthBase",YT.DEPTH="depth",YT.LINEAR_DEPTH="linearDepth";const ZT=(t,e,n)=>t.add(e).div(e.sub(n)),$T=(t,e,n)=>e.sub(n).mul(t).sub(e),JT=(t,e,n)=>e.add(t).mul(n).div(n.sub(e).mul(t)),KT=(t,e,n)=>e.mul(n).div(n.sub(e).mul(t).sub(n)),QT=_g(YT,YT.DEPTH_BASE),tS=xg(YT,YT.DEPTH),eS=_g(YT,YT.LINEAR_DEPTH),nS=eS(qT());tS.assign=t=>QT(t);class iS extends Rf{static get type(){return"ClippingNode"}constructor(t=iS.DEFAULT){super(),this.scope=t}setup(t){super.setup(t);const e=t.clippingContext,{localClipIntersection:n,localClippingCount:i,globalClippingCount:s}=e,r=s+i,a=n?r-i:r;return this.scope===iS.ALPHA_TO_COVERAGE?this.setupAlphaToCoverage(e.planes,r,a):this.setupDefault(e.planes,r,a)}setupAlphaToCoverage(t,e,n){return Mg((()=>{const i=NM(t),s=ov("float","distanceToPlane"),r=ov("float","distanceToGradient"),a=ov("float","clipOpacity");let o;if(a.assign(1),uT(n,(({i:t})=>{o=i.element(t),s.assign(nM.dot(o.xyz).negate().add(o.w)),r.assign(s.fwidth().div(2)),a.mulAssign(g_(r.negate(),r,s)),a.equal(0).discard()})),n{o=i.element(e),s.assign(nM.dot(o.xyz).negate().add(o.w)),r.assign(s.fwidth().div(2)),t.mulAssign(g_(r.negate(),r,s).oneMinus())})),a.mulAssign(t.oneMinus())}cv.a.mulAssign(a),cv.a.equal(0).discard()}))()}setupDefault(t,e,n){return Mg((()=>{const i=NM(t);let s;if(uT(n,(({i:t})=>{s=i.element(t),nM.dot(s.xyz).greaterThan(s.w).discard()})),n{s=i.element(e),t.assign(nM.dot(s.xyz).greaterThan(s.w).and(t))})),t.discard()}}))()}}iS.ALPHA_TO_COVERAGE="alphaToCoverage",iS.DEFAULT="default";class sS extends ir{static get type(){return"NodeMaterial"}constructor(){super(),this.isNodeMaterial=!0,this.type=this.constructor.type,this.forceSinglePass=!1,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.positionNode=null,this.depthNode=null,this.shadowNode=null,this.shadowPositionNode=null,this.outputNode=null,this.mrtNode=null,this.fragmentNode=null,this.vertexNode=null}customProgramCacheKey(){return this.type+ff(this)}build(t){this.setup(t)}setupObserver(t){return new uf(t)}setup(t){let e;t.context.setupNormal=()=>this.setupNormal(t),t.addStack(),t.stack.outputNode=this.vertexNode||this.setupPosition(t),t.addFlow("vertex",t.removeStack()),t.addStack();const n=this.setupClipping(t);if(!0===this.depthWrite&&this.setupDepth(t),null===this.fragmentNode){this.setupDiffuseColor(t),this.setupVariants(t);const i=this.setupLighting(t);null!==n&&t.stack.add(n);const s=Bg(i,cv.a).max(0);e=this.setupOutput(t,s),Av.assign(e),null!==this.outputNode&&(e=this.outputNode);if(null!==t.renderer.getRenderTarget()){const n=t.renderer.getMRT(),i=this.mrtNode;null!==n?(e=n,null!==i&&(e=n.merge(i))):null!==i&&(e=i)}}else{let n=this.fragmentNode;!0!==n.isOutputStructNode&&(n=Bg(n)),e=this.setupOutput(t,n)}t.stack.outputNode=e,t.addFlow("fragment",t.removeStack()),t.monitor=this.setupObserver(t)}setupClipping(t){if(null===t.clippingContext)return null;const{globalClippingCount:e,localClippingCount:n}=t.clippingContext;let i=null;if(e||n){const e=t.renderer.samples;this.alphaToCoverage&&e>1?i=gg(new iS(iS.ALPHA_TO_COVERAGE)):t.stack.add(gg(new iS))}return i}setupDepth(t){const{renderer:e}=t;let n=this.depthNode;if(null===n){const t="getMRT"in e&&e.getMRT();if(t&&t.has("depth"))n=t.get("depth");else if(!0===e.logarithmicDepthBuffer){n=qb().w.add(1).log2().mul(Ax).mul(.5)}}null!==n&&tS.assign(n).append()}setupPosition(t){const{object:e}=t,n=e.geometry;if(t.addStack(),(n.morphAttributes.position||n.morphAttributes.normal||n.morphAttributes.color)&&yT(e).append(),!0===e.isSkinnedMesh&&lT(e).append(),this.displacementMap){const t=DM("displacementMap","texture"),e=DM("displacementScale","float"),n=DM("displacementBias","float");Kx.addAssign(lM.normalize().mul(t.x.mul(e).add(n)))}e.isBatchedMesh&&sT(e).append(),e.instanceMatrix&&!0===e.instanceMatrix.isInstancedBufferAttribute&&nT(e).append(),null!==this.positionNode&&Kx.assign(this.positionNode);const i=qb();return t.context.vertex=t.removeStack(),t.context.mvp=i,i}setupDiffuseColor({object:t,geometry:e}){let n=this.colorNode?Bg(this.colorNode):cb;if(!0===this.vertexColors&&e.hasAttribute("color")&&(n=Bg(n.xyz.mul(fx("color","vec3")),n.a)),t.instanceColor){n=lv("vec3","vInstanceColor").mul(n)}if(t.isBatchedMesh&&t._colorsTexture){n=lv("vec3","vBatchColor").mul(n)}cv.assign(n);const i=this.opacityNode?Ng(this.opacityNode):db;if(cv.a.assign(cv.a.mul(i)),null!==this.alphaTestNode||this.alphaTest>0){const t=null!==this.alphaTestNode?Ng(this.alphaTestNode):lb;cv.a.lessThanEqual(t).discard()}!1===this.transparent&&1===this.blending&&!1===this.alphaToCoverage&&cv.a.assign(1)}setupVariants(){}setupOutgoingLight(){return!0===this.lights?Og(0):cv.rgb}setupNormal(){return this.normalNode?Og(this.normalNode):xb}setupEnvironment(){let t=null;return this.envNode?t=this.envNode:this.envMap&&(t=this.envMap.isCubeTexture?DM("envMap","cubeTexture"):DM("envMap","texture")),t}setupLightMap(t){let e=null;return t.material.lightMap&&(e=new AT(Gb)),e}setupLights(t){const e=[],n=this.setupEnvironment(t);n&&n.isLightingNode&&e.push(n);const i=this.setupLightMap(t);if(i&&i.isLightingNode&&e.push(i),null!==this.aoNode||t.material.aoMap){const t=null!==this.aoNode?this.aoNode:Wb;e.push(new ST(t))}let s=this.lightsNode||t.lightsNode;return e.length>0&&(s=bT([...s.getLights(),...e])),s}setupLightingModel(){}setupLighting(t){const{material:e}=t,{backdropNode:n,backdropAlphaNode:i,emissiveNode:s}=this,r=!0===this.lights||null!==this.lightsNode?this.setupLights(t):null;let a=this.setupOutgoingLight(t);if(r&&r.getScope().getLights().length>0){const e=this.setupLightingModel(t);a=ET(r,e,n,i)}else null!==n&&(a=Og(null!==i?d_(a,n,i):n));return(s&&!0===s.isNode||e.emissive&&!0===e.emissive.isColor)&&(uv.assign(Og(s||hb)),a=a.add(uv)),a}setupOutput(t,e){if(!0===this.fog){const n=t.fogNode;n&&(e=Bg(n.mix(e.rgb,n.colorNode),e.a))}return e}setDefaultValues(t){for(const e in t){const n=t[e];void 0===this[e]&&(this[e]=n,n&&n.clone&&(this[e]=n.clone()))}const e=Object.getOwnPropertyDescriptors(t.constructor.prototype);for(const t in e)void 0===Object.getOwnPropertyDescriptor(this.constructor.prototype,t)&&void 0!==e[t].get&&Object.defineProperty(this.constructor.prototype,t,e[t])}toJSON(t){const e=void 0===t||"string"==typeof t;e&&(t={textures:{},images:{},nodes:{}});const n=ir.prototype.toJSON.call(this,t),i=gf(this);n.inputNodes={};for(const{property:e,childNode:s}of i)n.inputNodes[e]=s.toJSON(t).uuid;function s(t){const e=[];for(const n in t){const i=t[n];delete i.metadata,e.push(i)}return e}if(e){const e=s(t.textures),i=s(t.images),r=s(t.nodes);e.length>0&&(n.textures=e),i.length>0&&(n.images=i),r.length>0&&(n.nodes=r)}return n}copy(t){return this.lightsNode=t.lightsNode,this.envNode=t.envNode,this.colorNode=t.colorNode,this.normalNode=t.normalNode,this.opacityNode=t.opacityNode,this.backdropNode=t.backdropNode,this.backdropAlphaNode=t.backdropAlphaNode,this.alphaTestNode=t.alphaTestNode,this.positionNode=t.positionNode,this.depthNode=t.depthNode,this.shadowNode=t.shadowNode,this.shadowPositionNode=t.shadowPositionNode,this.outputNode=t.outputNode,this.mrtNode=t.mrtNode,this.fragmentNode=t.fragmentNode,this.vertexNode=t.vertexNode,super.copy(t)}}const rS=new Pu;class aS extends sS{static get type(){return"InstancedPointsNodeMaterial"}constructor(t={}){super(),this.lights=!1,this.useAlphaToCoverage=!0,this.useColor=t.vertexColors,this.pointWidth=1,this.pointColorNode=null,this.pointWidthNode=null,this.setDefaultValues(rS),this.setValues(t)}setup(t){this.setupShaders(t),super.setup(t)}setupShaders({renderer:t}){const e=this.alphaToCoverage,n=this.useColor;this.vertexNode=Mg((()=>{const t=fx("instancePosition").xyz,e=Bg(Yx.mul(Bg(t,1))),n=UT.z.div(UT.w),i=Nx.mul(e),s=Jx.xy.toVar();return s.mulAssign(this.pointWidthNode?this.pointWidthNode:kb),s.assign(s.div(UT.z)),s.y.assign(s.y.mul(n)),s.assign(s.mul(i.w)),i.addAssign(Bg(s,0,0)),i}))(),this.fragmentNode=Mg((()=>{const i=Ng(1).toVar(),s=h_(gx().mul(2).sub(1));if(e&&t.samples>1){const t=Ng(s.fwidth()).toVar();i.assign(g_(t.oneMinus(),t.add(1),s).oneMinus())}else s.greaterThan(1).discard();let r;if(this.pointColorNode)r=this.pointColorNode;else if(n){r=fx("instanceColor").mul(cb)}else r=cb;return i.mulAssign(db),Bg(r,i)}))()}get alphaToCoverage(){return this.useAlphaToCoverage}set alphaToCoverage(t){this.useAlphaToCoverage!==t&&(this.useAlphaToCoverage=t,this.needsUpdate=!0)}}const oS=new _u;class lS extends sS{static get type(){return"LineBasicNodeMaterial"}constructor(t){super(),this.isLineBasicNodeMaterial=!0,this.lights=!1,this.setDefaultValues(oS),this.setValues(t)}}const cS=new Sd;class uS extends sS{static get type(){return"LineDashedNodeMaterial"}constructor(t){super(),this.isLineDashedNodeMaterial=!0,this.lights=!1,this.setDefaultValues(cS),this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(t)}setupVariants(){const t=this.offsetNode,e=this.dashScaleNode?Ng(this.dashScaleNode):Ob,n=this.dashSizeNode?Ng(this.dashSizeNode):zb,i=this.dashSizeNode?Ng(this.dashGapNode):Vb;Nv.assign(n),Cv.assign(i);const s=R_(fx("lineDistance").mul(e));(t?s.add(t):s).mod(Nv.add(Cv)).greaterThan(Nv).discard()}}const hS=new Sd;class dS extends sS{static get type(){return"Line2NodeMaterial"}constructor(t={}){super(),this.lights=!1,this.setDefaultValues(hS),this.useAlphaToCoverage=!0,this.useColor=t.vertexColors,this.useDash=t.dashed,this.useWorldUnits=!1,this.dashOffset=0,this.lineWidth=1,this.lineColorNode=null,this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(t)}setup(t){this.setupShaders(t),super.setup(t)}setupShaders({renderer:t}){const e=this.alphaToCoverage,n=this.useColor,i=this.dashed,s=this.worldUnits,r=Mg((({start:t,end:e})=>{const n=Nx.element(2).element(2),i=Nx.element(3).element(2).mul(-.5).div(n).sub(t.z).div(e.z.sub(t.z));return Bg(d_(t.xyz,e.xyz,i),e.w)})).setLayout({name:"trimSegment",type:"vec4",inputs:[{name:"start",type:"vec4"},{name:"end",type:"vec4"}]});this.vertexNode=Mg((()=>{const t=fx("instanceStart"),e=fx("instanceEnd"),n=Bg(Yx.mul(Bg(t,1))).toVar("start"),a=Bg(Yx.mul(Bg(e,1))).toVar("end");s&&(lv("vec3","worldStart").assign(n.xyz),lv("vec3","worldEnd").assign(a.xyz));const o=UT.z.div(UT.w),l=Nx.element(2).element(3).equal(-1);wg(l,(()=>{wg(n.z.lessThan(0).and(a.z.greaterThan(0)),(()=>{a.assign(r({start:n,end:a}))})).ElseIf(a.z.lessThan(0).and(n.z.greaterThanEqual(0)),(()=>{n.assign(r({start:a,end:n}))}))}));const c=Nx.mul(n),u=Nx.mul(a),h=c.xyz.div(c.w),d=u.xyz.div(u.w),p=d.xy.sub(h.xy).toVar();p.x.assign(p.x.mul(o)),p.assign(p.normalize());const m=Bg().toVar();if(s){const t=a.xyz.sub(n.xyz).normalize(),e=d_(n.xyz,a.xyz,.5).normalize(),s=t.cross(e).normalize(),r=t.cross(s),o=lv("vec4","worldPos");o.assign(Jx.y.lessThan(.5).select(n,a));const l=Fb.mul(.5);o.addAssign(Bg(Jx.x.lessThan(0).select(s.mul(l),s.mul(l).negate()),0)),i||(o.addAssign(Bg(Jx.y.lessThan(.5).select(t.mul(l).negate(),t.mul(l)),0)),o.addAssign(Bg(r.mul(l),0)),wg(Jx.y.greaterThan(1).or(Jx.y.lessThan(0)),(()=>{o.subAssign(Bg(r.mul(2).mul(l),0))}))),m.assign(Nx.mul(o));const c=Og().toVar();c.assign(Jx.y.lessThan(.5).select(h,d)),m.z.assign(c.z.mul(m.w))}else{const t=Lg(p.y,p.x.negate()).toVar("offset");p.x.assign(p.x.div(o)),t.x.assign(t.x.div(o)),t.assign(Jx.x.lessThan(0).select(t.negate(),t)),wg(Jx.y.lessThan(0),(()=>{t.assign(t.sub(p))})).ElseIf(Jx.y.greaterThan(1),(()=>{t.assign(t.add(p))})),t.assign(t.mul(Fb)),t.assign(t.div(UT.w)),m.assign(Jx.y.lessThan(.5).select(c,u)),t.assign(t.mul(m.w)),m.assign(m.add(Bg(t,0,0)))}return m}))();const a=Mg((({p1:t,p2:e,p3:n,p4:i})=>{const s=t.sub(n),r=i.sub(n),a=e.sub(t),o=s.dot(r),l=r.dot(a),c=s.dot(a),u=r.dot(r),h=a.dot(a).mul(u).sub(l.mul(l)),d=o.mul(l).sub(c.mul(u)).div(h).clamp(),p=o.add(l.mul(d)).div(u).clamp();return Lg(d,p)}));this.fragmentNode=Mg((()=>{const r=gx();if(i){const t=this.offsetNode?Ng(this.offsetNodeNode):Bb,e=this.dashScaleNode?Ng(this.dashScaleNode):Ob,n=this.dashSizeNode?Ng(this.dashSizeNode):zb,i=this.dashSizeNode?Ng(this.dashGapNode):Vb;Nv.assign(n),Cv.assign(i);const s=fx("instanceDistanceStart"),a=fx("instanceDistanceEnd"),o=Jx.y.lessThan(.5).select(e.mul(s),Ob.mul(a)),l=R_(o.add(Bb)),c=t?l.add(t):l;r.y.lessThan(-1).or(r.y.greaterThan(1)).discard(),c.mod(Nv.add(Cv)).greaterThan(Nv).discard()}const o=Ng(1).toVar("alpha");if(s){const n=lv("vec3","worldStart"),s=lv("vec3","worldEnd"),r=lv("vec4","worldPos").xyz.normalize().mul(1e5),l=s.sub(n),c=a({p1:n,p2:s,p3:Og(0,0,0),p4:r}),u=n.add(l.mul(c.x)),h=r.mul(c.y),d=u.sub(h).length().div(Fb);if(!i)if(e&&t.samples>1){const t=d.fwidth();o.assign(g_(t.negate().add(.5),t.add(.5),d).oneMinus())}else d.greaterThan(.5).discard()}else if(e&&t.samples>1){const t=r.x,e=r.y.greaterThan(0).select(r.y.sub(1),r.y.add(1)),n=t.mul(t).add(e.mul(e)),i=Ng(n.fwidth()).toVar("dlen");wg(r.y.abs().greaterThan(1),(()=>{o.assign(g_(i.oneMinus(),i.add(1),n).oneMinus())}))}else wg(r.y.abs().greaterThan(1),(()=>{const t=r.x,e=r.y.greaterThan(0).select(r.y.sub(1),r.y.add(1));t.mul(t).add(e.mul(e)).greaterThan(1).discard()}));let l;if(this.lineColorNode)l=this.lineColorNode;else if(n){const t=fx("instanceColorStart"),e=fx("instanceColorEnd");l=Jx.y.lessThan(.5).select(t,e).mul(cb)}else l=cb;return Bg(l,o)}))()}get worldUnits(){return this.useWorldUnits}set worldUnits(t){this.useWorldUnits!==t&&(this.useWorldUnits=t,this.needsUpdate=!0)}get dashed(){return this.useDash}set dashed(t){this.useDash!==t&&(this.useDash=t,this.needsUpdate=!0)}get alphaToCoverage(){return this.useAlphaToCoverage}set alphaToCoverage(t){this.useAlphaToCoverage!==t&&(this.useAlphaToCoverage=t,this.needsUpdate=!0)}}const pS=t=>gg(t).mul(.5).add(.5),mS=t=>gg(t).mul(2).sub(1),fS=new Md;class gS extends sS{static get type(){return"MeshNormalNodeMaterial"}constructor(t){super(),this.lights=!1,this.isMeshNormalNodeMaterial=!0,this.setDefaultValues(fS),this.setValues(t)}setupDiffuseColor(){const t=this.opacityNode?Ng(this.opacityNode):db;cv.assign(Bg(pS(dM),t))}}class vS extends Pf{static get type(){return"EquirectUVNode"}constructor(t=eM){super("vec2"),this.dirNode=t}setup(){const t=this.dirNode,e=t.z.atan2(t.x).mul(1/(2*Math.PI)).add(.5),n=t.y.clamp(-1,1).asin().mul(1/Math.PI).add(.5);return Lg(e,n)}}const yS=_g(vS);class _S extends ia{constructor(t=1,e={}){super(t,e),this.isCubeRenderTarget=!0}fromEquirectangularTexture(t,e){const n=e.minFilter,i=e.generateMipmaps;e.generateMipmaps=!0,this.texture.type=e.type,this.texture.colorSpace=e.colorSpace,this.texture.generateMipmaps=e.generateMipmaps,this.texture.minFilter=e.minFilter,this.texture.magFilter=e.magFilter;const s=new Gr(5,5,5),r=yS(eM),a=new sS;a.colorNode=bx(e,r,0),a.side=1,a.blending=0;const o=new kr(s,a),l=new oc;l.add(o),e.minFilter===St&&(e.minFilter=Mt);const c=new ea(1,10,this),u=t.getMRT();return t.setMRT(null),c.update(t,l),t.setMRT(u),e.minFilter=n,e.currentGenerateMipmaps=i,o.geometry.dispose(),o.material.dispose(),this}}const xS=new WeakMap;class MS extends Pf{static get type(){return"CubeMapNode"}constructor(t){super("vec3"),this.envNode=t,this._cubeTexture=null,this._cubeTextureNode=TM();const e=new na;e.isRenderTargetTexture=!0,this._defaultTexture=e,this.updateBeforeType=Tf.RENDER}updateBefore(t){const{renderer:e,material:n}=t,i=this.envNode;if(i.isTextureNode||i.isMaterialReferenceNode){const t=i.isTextureNode?i.value:n[i.property];if(t&&t.isTexture){const n=t.mapping;if(n===ut||n===ht){if(xS.has(t)){const e=xS.get(t);TS(e,t.mapping),this._cubeTexture=e}else{const n=t.image;if(function(t){return null!=t&&t.height>0}(n)){const i=new _S(n.height);i.fromEquirectangularTexture(e,t),TS(i.texture,t.mapping),this._cubeTexture=i.texture,xS.set(t,i.texture),t.addEventListener("dispose",bS)}else this._cubeTexture=this._defaultTexture}this._cubeTextureNode.value=this._cubeTexture}else this._cubeTextureNode=this.envNode}}}setup(t){return this.updateBefore(t),this._cubeTextureNode}}function bS(t){const e=t.target;e.removeEventListener("dispose",bS);const n=xS.get(e);void 0!==n&&(xS.delete(e),n.dispose())}function TS(t,e){e===ut?t.mapping=lt:e===ht&&(t.mapping=ct)}const SS=_g(MS);class wS extends TT{static get type(){return"BasicEnvironmentNode"}constructor(t=null){super(),this.envNode=t}setup(t){t.context.environment=SS(this.envNode)}}class ES extends TT{static get type(){return"BasicLightMapNode"}constructor(t=null){super(),this.lightMapNode=t}setup(t){const e=Ng(1/Math.PI);t.context.irradianceLightMap=this.lightMapNode.mul(e)}}class AS{start(){}finish(){}direct(){}directRectArea(){}indirect(){}ambientOcclusion(){}}class NS extends AS{constructor(){super()}indirect(t,e,n){const i=t.ambientOcclusion,s=t.reflectedLight,r=n.context.irradianceLightMap;s.indirectDiffuse.assign(Bg(0)),r?s.indirectDiffuse.addAssign(r):s.indirectDiffuse.addAssign(Bg(1,1,1,0)),s.indirectDiffuse.mulAssign(i),s.indirectDiffuse.mulAssign(cv.rgb)}finish(t,e,n){const i=n.material,s=t.outgoingLight,r=n.context.environment;if(r)switch(i.combine){case 0:s.rgb.assign(d_(s.rgb,s.rgb.mul(r.rgb),gb.mul(vb)));break;case 1:s.rgb.assign(d_(s.rgb,r.rgb,gb.mul(vb)));break;case 2:s.rgb.addAssign(r.rgb.mul(gb.mul(vb)));break;default:console.warn("THREE.BasicLightingModel: Unsupported .combine value:",i.combine)}}}const CS=new sr;class RS extends sS{static get type(){return"MeshBasicNodeMaterial"}constructor(t){super(),this.isMeshBasicNodeMaterial=!0,this.lights=!0,this.setDefaultValues(CS),this.setValues(t)}setupNormal(){return uM}setupEnvironment(t){const e=super.setupEnvironment(t);return e?new wS(e):null}setupLightMap(t){let e=null;return t.material.lightMap&&(e=new ES(Gb)),e}setupOutgoingLight(){return cv.rgb}setupLightingModel(){return new NS}}const IS=Mg((({f0:t,f90:e,dotVH:n})=>{const i=n.mul(-5.55473).sub(6.98316).mul(n).exp2();return t.mul(i.oneMinus()).add(e.mul(i))})),LS=Mg((t=>t.diffuseColor.mul(1/Math.PI))),PS=Mg((({dotNH:t})=>Ev.mul(Ng(.5)).add(1).mul(Ng(1/Math.PI)).mul(t.pow(Ev)))),US=Mg((({lightDirection:t})=>{const e=t.add(iM).normalize(),n=dM.dot(e).clamp(),i=iM.dot(e).clamp(),s=IS({f0:Sv,f90:1,dotVH:i}),r=Ng(.25),a=PS({dotNH:n});return s.mul(r).mul(a)}));class DS extends NS{constructor(t=!0){super(),this.specular=t}direct({lightDirection:t,lightColor:e,reflectedLight:n}){const i=dM.dot(t).clamp().mul(e);n.directDiffuse.addAssign(i.mul(LS({diffuseColor:cv.rgb}))),!0===this.specular&&n.directSpecular.addAssign(i.mul(US({lightDirection:t})).mul(gb))}indirect({ambientOcclusion:t,irradiance:e,reflectedLight:n}){n.indirectDiffuse.addAssign(e.mul(LS({diffuseColor:cv}))),n.indirectDiffuse.mulAssign(t)}}const OS=new bd;class zS extends sS{static get type(){return"MeshLambertNodeMaterial"}constructor(t){super(),this.isMeshLambertNodeMaterial=!0,this.lights=!0,this.setDefaultValues(OS),this.setValues(t)}setupEnvironment(t){const e=super.setupEnvironment(t);return e?new wS(e):null}setupLightingModel(){return new DS(!1)}}const VS=new _d;class FS extends sS{static get type(){return"MeshPhongNodeMaterial"}constructor(t){super(),this.isMeshPhongNodeMaterial=!0,this.lights=!0,this.shininessNode=null,this.specularNode=null,this.setDefaultValues(VS),this.setValues(t)}setupEnvironment(t){const e=super.setupEnvironment(t);return e?new wS(e):null}setupLightingModel(){return new DS}setupVariants(){const t=(this.shininessNode?Ng(this.shininessNode):ub).max(1e-4);Ev.assign(t);const e=this.specularNode||pb;Sv.assign(e)}copy(t){return this.shininessNode=t.shininessNode,this.specularNode=t.specularNode,super.copy(t)}}const BS=Mg((()=>{const t=uM.dFdx().abs().max(uM.dFdy().abs());return t.x.max(t.y).max(t.z)})),kS=Mg((t=>{const{roughness:e}=t,n=BS();let i=e.max(.0525);return i=i.add(n),i=i.min(1),i})),HS=Mg((({alpha:t,dotNL:e,dotNV:n})=>{const i=t.pow2(),s=e.mul(i.add(i.oneMinus().mul(n.pow2())).sqrt()),r=n.mul(i.add(i.oneMinus().mul(e.pow2())).sqrt());return jv(.5,s.add(r).max(hy))})).setLayout({name:"V_GGX_SmithCorrelated",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNL",type:"float"},{name:"dotNV",type:"float"}]}),GS=Mg((({alphaT:t,alphaB:e,dotTV:n,dotBV:i,dotTL:s,dotBL:r,dotNV:a,dotNL:o})=>{const l=o.mul(Og(t.mul(n),e.mul(i),a).length()),c=a.mul(Og(t.mul(s),e.mul(r),o).length());return jv(.5,l.add(c)).saturate()})).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"}]}),WS=Mg((({alpha:t,dotNH:e})=>{const n=t.pow2(),i=e.pow2().mul(n.oneMinus()).oneMinus();return n.div(i.pow2()).mul(1/Math.PI)})).setLayout({name:"D_GGX",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNH",type:"float"}]}),jS=Ng(1/Math.PI),XS=Mg((({alphaT:t,alphaB:e,dotNH:n,dotTH:i,dotBH:s})=>{const r=t.mul(e),a=Og(e.mul(i),t.mul(s),r.mul(n)),o=a.dot(a),l=r.div(o);return jS.mul(r.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"}]}),qS=Mg((t=>{const{lightDirection:e,f0:n,f90:i,roughness:s,f:r,USE_IRIDESCENCE:a,USE_ANISOTROPY:o}=t,l=t.normalView||dM,c=s.pow2(),u=e.add(iM).normalize(),h=l.dot(e).clamp(),d=l.dot(iM).clamp(),p=l.dot(u).clamp(),m=iM.dot(u).clamp();let f,g,v=IS({f0:n,f90:i,dotVH:m});if(pg(a)&&(v=vv.mix(v,r)),pg(o)){const t=bv.dot(e),n=bv.dot(iM),i=bv.dot(u),s=Tv.dot(e),r=Tv.dot(iM),a=Tv.dot(u);f=GS({alphaT:xv,alphaB:c,dotTV:n,dotBV:r,dotTL:t,dotBL:s,dotNV:d,dotNL:h}),g=XS({alphaT:xv,alphaB:c,dotNH:p,dotTH:i,dotBH:a})}else f=HS({alpha:c,dotNL:h,dotNV:d}),g=WS({alpha:c,dotNH:p});return v.mul(f).mul(g)})),YS=Mg((({roughness:t,dotNV:e})=>{const n=Bg(-1,-.0275,-.572,.022),i=Bg(1,.0425,1.04,-.04),s=t.mul(n).add(i),r=s.x.mul(s.x).min(e.mul(-9.28).exp2()).mul(s.x).add(s.y);return Lg(-1.04,1.04).mul(r).add(s.zw)})).setLayout({name:"DFGApprox",type:"vec2",inputs:[{name:"roughness",type:"float"},{name:"dotNV",type:"vec3"}]}),ZS=Mg((t=>{const{dotNV:e,specularColor:n,specularF90:i,roughness:s}=t,r=YS({dotNV:e,roughness:s});return n.mul(r.x).add(i.mul(r.y))})),$S=Mg((({f:t,f90:e,dotVH:n})=>{const i=n.oneMinus().saturate(),s=i.mul(i),r=i.mul(s,s).clamp(0,.9999);return t.sub(Og(e).mul(r)).div(r.oneMinus())})).setLayout({name:"Schlick_to_F0",type:"vec3",inputs:[{name:"f",type:"vec3"},{name:"f90",type:"float"},{name:"dotVH",type:"float"}]}),JS=Mg((({roughness:t,dotNH:e})=>{const n=t.pow2(),i=Ng(1).div(n),s=e.pow2().oneMinus().max(.0078125);return Ng(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"}]}),KS=Mg((({dotNV:t,dotNL:e})=>Ng(1).div(Ng(4).mul(e.add(t).sub(e.mul(t)))))).setLayout({name:"V_Neubelt",type:"float",inputs:[{name:"dotNV",type:"float"},{name:"dotNL",type:"float"}]}),QS=Mg((({lightDirection:t})=>{const e=t.add(iM).normalize(),n=dM.dot(t).clamp(),i=dM.dot(iM).clamp(),s=dM.dot(e).clamp(),r=JS({roughness:gv,dotNH:s}),a=KS({dotNV:i,dotNL:n});return fv.mul(r).mul(a)})),tw=Mg((({N:t,V:e,roughness:n})=>{const i=t.dot(e).saturate(),s=Lg(n,i.oneMinus().sqrt());return s.assign(s.mul(.984375).add(.0078125)),s})).setLayout({name:"LTC_Uv",type:"vec2",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"roughness",type:"float"}]}),ew=Mg((({f:t})=>{const e=t.length();return Jy(e.mul(e).add(t.z).div(e.add(1)),0)})).setLayout({name:"LTC_ClippedSphereFormFactor",type:"float",inputs:[{name:"f",type:"vec3"}]}),nw=Mg((({v1:t,v2:e})=>{const n=t.dot(e),i=n.abs().toVar(),s=i.mul(.0145206).add(.4965155).mul(i).add(.8543985).toVar(),r=i.add(4.1616724).mul(i).add(3.417594).toVar(),a=s.div(r),o=n.greaterThan(0).select(a,Jy(n.mul(n).oneMinus(),1e-7).inverseSqrt().mul(.5).sub(a));return t.cross(e).mul(o)})).setLayout({name:"LTC_EdgeVectorFormFactor",type:"vec3",inputs:[{name:"v1",type:"vec3"},{name:"v2",type:"vec3"}]}),iw=Mg((({N:t,V:e,P:n,mInv:i,p0:s,p1:r,p2:a,p3:o})=>{const l=r.sub(s).toVar(),c=o.sub(s).toVar(),u=l.cross(c),h=Og().toVar();return wg(u.dot(n.sub(s)).greaterThanEqual(0),(()=>{const l=e.sub(t.mul(e.dot(t))).normalize(),c=t.cross(l).negate(),u=i.mul(jg(l,c,t).transpose()).toVar(),d=u.mul(s.sub(n)).normalize().toVar(),p=u.mul(r.sub(n)).normalize().toVar(),m=u.mul(a.sub(n)).normalize().toVar(),f=u.mul(o.sub(n)).normalize().toVar(),g=Og(0).toVar();g.addAssign(nw({v1:d,v2:p})),g.addAssign(nw({v1:p,v2:m})),g.addAssign(nw({v1:m,v2:f})),g.addAssign(nw({v1:f,v2:d})),h.assign(Og(ew({f:g})))})),h})).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"}]}),sw=1/6,rw=t=>Wv(sw,Wv(t,Wv(t,t.negate().add(3)).sub(3)).add(1)),aw=t=>Wv(sw,Wv(t,Wv(t,Wv(3,t).sub(6))).add(4)),ow=t=>Wv(sw,Wv(t,Wv(t,Wv(-3,t).add(3)).add(3)).add(1)),lw=t=>Wv(sw,r_(t,3)),cw=t=>rw(t).add(aw(t)),uw=t=>ow(t).add(lw(t)),hw=t=>Hv(-1,aw(t).div(rw(t).add(aw(t)))),dw=t=>Hv(1,lw(t).div(ow(t).add(lw(t)))),pw=(t,e,n)=>{const i=t.uvNode,s=Wv(i,e.zw).add(.5),r=Ey(s),a=Cy(s),o=cw(a.x),l=uw(a.x),c=hw(a.x),u=dw(a.x),h=hw(a.y),d=dw(a.y),p=Lg(r.x.add(c),r.y.add(h)).sub(.5).mul(e.xy),m=Lg(r.x.add(u),r.y.add(h)).sub(.5).mul(e.xy),f=Lg(r.x.add(c),r.y.add(d)).sub(.5).mul(e.xy),g=Lg(r.x.add(u),r.y.add(d)).sub(.5).mul(e.xy),v=cw(a.y).mul(Hv(o.mul(t.uv(p).level(n)),l.mul(t.uv(m).level(n)))),y=uw(a.y).mul(Hv(o.mul(t.uv(f).level(n)),l.mul(t.uv(g).level(n))));return v.add(y)},mw=Mg((([t,e=Ng(3)])=>{const n=Lg(t.size(Cg(e))),i=Lg(t.size(Cg(e.add(1)))),s=jv(1,n),r=jv(1,i),a=pw(t,Bg(s,n),Ey(e)),o=pw(t,Bg(r,i),Ay(e));return Cy(e).mix(a,o)})),fw=Mg((([t,e,n,i,s])=>{const r=Og(f_(e.negate(),Ny(t),jv(1,i))),a=Og(Vy(s[0].xyz),Vy(s[1].xyz),Vy(s[2].xyz));return Ny(r).mul(n.mul(a))})).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"}]}),gw=Mg((([t,e])=>t.mul(p_(e.mul(2).sub(2),0,1)))).setLayout({name:"applyIorToRoughness",type:"float",inputs:[{name:"roughness",type:"float"},{name:"ior",type:"float"}]}),vw=WT(),yw=Mg((([t,e,n])=>{const i=vw.uv(t),s=Ty(Ng(LT.x)).mul(gw(e,n));return mw(i,s)})),_w=Mg((([t,e,n])=>(wg(n.notEqual(0),(()=>{const i=by(e).negate().div(n);return xy(i.negate().mul(t))})),Og(1)))).setLayout({name:"volumeAttenuation",type:"vec3",inputs:[{name:"transmissionDistance",type:"float"},{name:"attenuationColor",type:"vec3"},{name:"attenuationDistance",type:"float"}]}),xw=Mg((([t,e,n,i,s,r,a,o,l,c,u,h,d,p,m])=>{let f,g;if(m){f=Bg().toVar(),g=Og().toVar();const s=u.sub(1).mul(m.mul(.025)),r=Og(u.sub(s),u,u.add(s));uT({start:0,end:3},(({i:s})=>{const u=r.element(s),m=fw(t,e,h,u,o),v=a.add(m),y=c.mul(l.mul(Bg(v,1))),_=Lg(y.xy.div(y.w)).toVar();_.addAssign(1),_.divAssign(2),_.assign(Lg(_.x,_.y.oneMinus()));const x=yw(_,n,u);f.element(s).assign(x.element(s)),f.a.addAssign(x.a),g.element(s).assign(i.element(s).mul(_w(Vy(m),d,p).element(s)))})),f.a.divAssign(3)}else{const s=fw(t,e,h,u,o),r=a.add(s),m=c.mul(l.mul(Bg(r,1))),v=Lg(m.xy.div(m.w)).toVar();v.addAssign(1),v.divAssign(2),v.assign(Lg(v.x,v.y.oneMinus())),f=yw(v,n,u),g=i.mul(_w(Vy(s),d,p))}const v=g.rgb.mul(f.rgb),y=t.dot(e).clamp(),_=Og(ZS({dotNV:y,specularColor:s,specularF90:r,roughness:n})),x=g.r.add(g.g,g.b).div(3);return Bg(_.oneMinus().mul(v),f.a.oneMinus().mul(x).oneMinus())})),Mw=jg(3.2404542,-.969266,.0556434,-1.5371385,1.8760108,-.2040259,-.4985314,.041556,1.0572252),bw=(t,e)=>t.sub(e).div(t.add(e)).pow2(),Tw=(t,e)=>{const n=t.mul(2*Math.PI*1e-9),i=Og(54856e-17,44201e-17,52481e-17),s=Og(1681e3,1795300,2208400),r=Og(43278e5,93046e5,66121e5),a=Ng(9747e-17*Math.sqrt(2*Math.PI*45282e5)).mul(n.mul(2239900).add(e.x).cos()).mul(n.pow2().mul(-45282e5).exp());let o=i.mul(r.mul(2*Math.PI).sqrt()).mul(s.mul(n).add(e).cos()).mul(n.pow2().negate().mul(r).exp());o=Og(o.x.add(a),o.y,o.z).div(1.0685e-7);return Mw.mul(o)},Sw=Mg((({outsideIOR:t,eta2:e,cosTheta1:n,thinFilmThickness:i,baseF0:s})=>{const r=d_(t,e,g_(0,.03,i)),a=t.div(r).pow2().mul(Ng(1).sub(n.pow2())),o=Ng(1).sub(a).sqrt(),l=bw(r,t),c=IS({f0:l,f90:1,dotVH:n}),u=c.oneMinus(),h=r.lessThan(t).select(Math.PI,0),d=Ng(Math.PI).sub(h),p=(t=>{const e=t.sqrt();return Og(1).add(e).div(Og(1).sub(e))})(s.clamp(0,.9999)),m=bw(p,r.toVec3()),f=IS({f0:m,f90:1,dotVH:o}),g=Og(p.x.lessThan(r).select(Math.PI,0),p.y.lessThan(r).select(Math.PI,0),p.z.lessThan(r).select(Math.PI,0)),v=r.mul(i,o,2),y=Og(d).add(g),_=c.mul(f).clamp(1e-5,.9999),x=_.sqrt(),M=u.pow2().mul(f).div(Og(1).sub(_));let b=c.add(M),T=M.sub(u);for(let t=1;t<=2;++t){T=T.mul(x);const e=Tw(Ng(t).mul(v),Ng(t).mul(y)).mul(2);b=b.add(T.mul(e))}return b.max(Og(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"}]}),ww=Mg((({normal:t,viewDir:e,roughness:n})=>{const i=t.dot(e).saturate(),s=n.pow2(),r=b_(n.lessThan(.25),Ng(-339.2).mul(s).add(Ng(161.4).mul(n)).sub(25.9),Ng(-8.48).mul(s).add(Ng(14.3).mul(n)).sub(9.95)),a=b_(n.lessThan(.25),Ng(44).mul(s).sub(Ng(23.7).mul(n)).add(3.26),Ng(1.97).mul(s).sub(Ng(3.27).mul(n)).add(.72));return b_(n.lessThan(.25),0,Ng(.1).mul(n).sub(.025)).add(r.mul(i).add(a).exp()).mul(1/Math.PI).saturate()})),Ew=Og(.04),Aw=Ng(1);class Nw extends AS{constructor(t=!1,e=!1,n=!1,i=!1,s=!1,r=!1){super(),this.clearcoat=t,this.sheen=e,this.iridescence=n,this.anisotropy=i,this.transmission=s,this.dispersion=r,this.clearcoatRadiance=null,this.clearcoatSpecularDirect=null,this.clearcoatSpecularIndirect=null,this.sheenSpecularDirect=null,this.sheenSpecularIndirect=null,this.iridescenceFresnel=null,this.iridescenceF0=null}start(t){if(!0===this.clearcoat&&(this.clearcoatRadiance=Og().toVar("clearcoatRadiance"),this.clearcoatSpecularDirect=Og().toVar("clearcoatSpecularDirect"),this.clearcoatSpecularIndirect=Og().toVar("clearcoatSpecularIndirect")),!0===this.sheen&&(this.sheenSpecularDirect=Og().toVar("sheenSpecularDirect"),this.sheenSpecularIndirect=Og().toVar("sheenSpecularIndirect")),!0===this.iridescence){const t=dM.dot(iM).clamp();this.iridescenceFresnel=Sw({outsideIOR:Ng(1),eta2:yv,cosTheta1:t,thinFilmThickness:_v,baseF0:Sv}),this.iridescenceF0=$S({f:this.iridescenceFresnel,f90:1,dotVH:t})}if(!0===this.transmission){const e=tM,n=Px.sub(tM).normalize(),i=pM;t.backdrop=xw(i,n,hv,cv,Sv,wv,e,Hx,Rx,Nx,Iv,Pv,Dv,Uv,this.dispersion?Ov:null),t.backdropAlpha=Lv,cv.a.mulAssign(d_(1,t.backdrop.a,Lv))}}computeMultiscattering(t,e,n){const i=dM.dot(iM).clamp(),s=YS({roughness:hv,dotNV:i}),r=(this.iridescenceF0?vv.mix(Sv,this.iridescenceF0):Sv).mul(s.x).add(n.mul(s.y)),a=s.x.add(s.y).oneMinus(),o=Sv.add(Sv.oneMinus().mul(.047619)),l=r.mul(o).div(a.mul(o).oneMinus());t.addAssign(r),e.addAssign(l.mul(a))}direct({lightDirection:t,lightColor:e,reflectedLight:n}){const i=dM.dot(t).clamp().mul(e);if(!0===this.sheen&&this.sheenSpecularDirect.addAssign(i.mul(QS({lightDirection:t}))),!0===this.clearcoat){const n=mM.dot(t).clamp().mul(e);this.clearcoatSpecularDirect.addAssign(n.mul(qS({lightDirection:t,f0:Ew,f90:Aw,roughness:mv,normalView:mM})))}n.directDiffuse.addAssign(i.mul(LS({diffuseColor:cv.rgb}))),n.directSpecular.addAssign(i.mul(qS({lightDirection:t,f0:Sv,f90:1,roughness:hv,iridescence:this.iridescence,f:this.iridescenceFresnel,USE_IRIDESCENCE:this.iridescence,USE_ANISOTROPY:this.anisotropy})))}directRectArea({lightColor:t,lightPosition:e,halfWidth:n,halfHeight:i,reflectedLight:s,ltc_1:r,ltc_2:a}){const o=e.add(n).sub(i),l=e.sub(n).sub(i),c=e.sub(n).add(i),u=e.add(n).add(i),h=dM,d=iM,p=nM.toVar(),m=tw({N:h,V:d,roughness:hv}),f=r.uv(m).toVar(),g=a.uv(m).toVar(),v=jg(Og(f.x,0,f.y),Og(0,1,0),Og(f.z,0,f.w)).toVar(),y=Sv.mul(g.x).add(Sv.oneMinus().mul(g.y)).toVar();s.directSpecular.addAssign(t.mul(y).mul(iw({N:h,V:d,P:p,mInv:v,p0:o,p1:l,p2:c,p3:u}))),s.directDiffuse.addAssign(t.mul(cv).mul(iw({N:h,V:d,P:p,mInv:jg(1,0,0,0,1,0,0,0,1),p0:o,p1:l,p2:c,p3:u})))}indirect(t,e,n){this.indirectDiffuse(t,e,n),this.indirectSpecular(t,e,n),this.ambientOcclusion(t,e,n)}indirectDiffuse({irradiance:t,reflectedLight:e}){e.indirectDiffuse.addAssign(t.mul(LS({diffuseColor:cv})))}indirectSpecular({radiance:t,iblIrradiance:e,reflectedLight:n}){if(!0===this.sheen&&this.sheenSpecularIndirect.addAssign(e.mul(fv,ww({normal:dM,viewDir:iM,roughness:gv}))),!0===this.clearcoat){const t=mM.dot(iM).clamp(),e=ZS({dotNV:t,specularColor:Ew,specularF90:Aw,roughness:mv});this.clearcoatSpecularIndirect.addAssign(this.clearcoatRadiance.mul(e))}const i=Og().toVar("singleScattering"),s=Og().toVar("multiScattering"),r=e.mul(1/Math.PI);this.computeMultiscattering(i,s,wv);const a=i.add(s),o=cv.mul(a.r.max(a.g).max(a.b).oneMinus());n.indirectSpecular.addAssign(t.mul(i)),n.indirectSpecular.addAssign(s.mul(r)),n.indirectDiffuse.addAssign(o.mul(r))}ambientOcclusion({ambientOcclusion:t,reflectedLight:e}){const n=dM.dot(iM).clamp().add(t),i=hv.mul(-16).oneMinus().negate().exp2(),s=t.sub(n.pow(i).oneMinus()).clamp();!0===this.clearcoat&&this.clearcoatSpecularIndirect.mulAssign(t),!0===this.sheen&&this.sheenSpecularIndirect.mulAssign(t),e.indirectDiffuse.mulAssign(t),e.indirectSpecular.mulAssign(s)}finish(t){const{outgoingLight:e}=t;if(!0===this.clearcoat){const t=mM.dot(iM).clamp(),n=IS({dotVH:t,f0:Ew,f90:Aw}),i=e.mul(pv.mul(n).oneMinus()).add(this.clearcoatSpecularDirect.add(this.clearcoatSpecularIndirect).mul(pv));e.assign(i)}if(!0===this.sheen){const t=fv.r.max(fv.g).max(fv.b).mul(.157).oneMinus(),n=e.mul(t).add(this.sheenSpecularDirect,this.sheenSpecularIndirect);e.assign(n)}}}const Cw=Ng(1),Rw=Ng(-2),Iw=Ng(.8),Lw=Ng(-1),Pw=Ng(.4),Uw=Ng(2),Dw=Ng(.305),Ow=Ng(3),zw=Ng(.21),Vw=Ng(4),Fw=Ng(4),Bw=Ng(16),kw=Mg((([t])=>{const e=Og(Oy(t)).toVar(),n=Ng(-1).toVar();return wg(e.x.greaterThan(e.z),(()=>{wg(e.x.greaterThan(e.y),(()=>{n.assign(b_(t.x.greaterThan(0),0,3))})).Else((()=>{n.assign(b_(t.y.greaterThan(0),1,4))}))})).Else((()=>{wg(e.z.greaterThan(e.y),(()=>{n.assign(b_(t.z.greaterThan(0),2,5))})).Else((()=>{n.assign(b_(t.y.greaterThan(0),1,4))}))})),n})).setLayout({name:"getFace",type:"float",inputs:[{name:"direction",type:"vec3"}]}),Hw=Mg((([t,e])=>{const n=Lg().toVar();return wg(e.equal(0),(()=>{n.assign(Lg(t.z,t.y).div(Oy(t.x)))})).ElseIf(e.equal(1),(()=>{n.assign(Lg(t.x.negate(),t.z.negate()).div(Oy(t.y)))})).ElseIf(e.equal(2),(()=>{n.assign(Lg(t.x.negate(),t.y).div(Oy(t.z)))})).ElseIf(e.equal(3),(()=>{n.assign(Lg(t.z.negate(),t.y).div(Oy(t.x)))})).ElseIf(e.equal(4),(()=>{n.assign(Lg(t.x.negate(),t.z).div(Oy(t.y)))})).Else((()=>{n.assign(Lg(t.x,t.y).div(Oy(t.z)))})),Wv(.5,n.add(1))})).setLayout({name:"getUV",type:"vec2",inputs:[{name:"direction",type:"vec3"},{name:"face",type:"float"}]}),Gw=Mg((([t])=>{const e=Ng(0).toVar();return wg(t.greaterThanEqual(Iw),(()=>{e.assign(Cw.sub(t).mul(Lw.sub(Rw)).div(Cw.sub(Iw)).add(Rw))})).ElseIf(t.greaterThanEqual(Pw),(()=>{e.assign(Iw.sub(t).mul(Uw.sub(Lw)).div(Iw.sub(Pw)).add(Lw))})).ElseIf(t.greaterThanEqual(Dw),(()=>{e.assign(Pw.sub(t).mul(Ow.sub(Uw)).div(Pw.sub(Dw)).add(Uw))})).ElseIf(t.greaterThanEqual(zw),(()=>{e.assign(Dw.sub(t).mul(Vw.sub(Ow)).div(Dw.sub(zw)).add(Ow))})).Else((()=>{e.assign(Ng(-2).mul(Ty(Wv(1.16,t))))})),e})).setLayout({name:"roughnessToMip",type:"float",inputs:[{name:"roughness",type:"float"}]}),Ww=Mg((([t,e])=>{const n=t.toVar();n.assign(Wv(2,n).sub(1));const i=Og(n,1).toVar();return wg(e.equal(0),(()=>{i.assign(i.zyx)})).ElseIf(e.equal(1),(()=>{i.assign(i.xzy),i.xz.mulAssign(-1)})).ElseIf(e.equal(2),(()=>{i.x.mulAssign(-1)})).ElseIf(e.equal(3),(()=>{i.assign(i.zyx),i.xz.mulAssign(-1)})).ElseIf(e.equal(4),(()=>{i.assign(i.xzy),i.xy.mulAssign(-1)})).ElseIf(e.equal(5),(()=>{i.z.mulAssign(-1)})),i})).setLayout({name:"getDirection",type:"vec3",inputs:[{name:"uv",type:"vec2"},{name:"face",type:"float"}]}),jw=Mg((([t,e,n,i,s,r])=>{const a=Ng(n),o=Og(e),l=p_(Gw(a),Rw,r),c=Cy(l),u=Ey(l),h=Og(Xw(t,o,u,i,s,r)).toVar();return wg(c.notEqual(0),(()=>{const e=Og(Xw(t,o,u.add(1),i,s,r)).toVar();h.assign(d_(h,e,c))})),h})),Xw=Mg((([t,e,n,i,s,r])=>{const a=Ng(n).toVar(),o=Og(e),l=Ng(kw(o)).toVar(),c=Ng(Jy(Fw.sub(a),0)).toVar();a.assign(Jy(a,Fw));const u=Ng(My(a)).toVar(),h=Lg(Hw(o,l).mul(u.sub(2)).add(1)).toVar();return wg(l.greaterThan(2),(()=>{h.y.addAssign(u),l.subAssign(3)})),h.x.addAssign(l.mul(u)),h.x.addAssign(c.mul(Wv(3,Bw))),h.y.addAssign(Wv(4,My(r).sub(u))),h.x.mulAssign(i),h.y.mulAssign(s),t.uv(h).grad(Lg(),Lg())})),qw=Mg((({envMap:t,mipInt:e,outputDirection:n,theta:i,axis:s,CUBEUV_TEXEL_WIDTH:r,CUBEUV_TEXEL_HEIGHT:a,CUBEUV_MAX_MIP:o})=>{const l=Iy(i),c=n.mul(l).add(s.cross(n).mul(Ry(i))).add(s.mul(s.dot(n).mul(l.oneMinus())));return Xw(t,c,e,r,a,o)})),Yw=Mg((({n:t,latitudinal:e,poleAxis:n,outputDirection:i,weights:s,samples:r,dTheta:a,mipInt:o,envMap:l,CUBEUV_TEXEL_WIDTH:c,CUBEUV_TEXEL_HEIGHT:u,CUBEUV_MAX_MIP:h})=>{const d=Og(b_(e,n,s_(n,i))).toVar();wg(fy(d.equals(Og(0))),(()=>{d.assign(Og(i.z,0,i.x.negate()))})),d.assign(Ny(d));const p=Og().toVar();return p.addAssign(s.element(Cg(0)).mul(qw({theta:0,axis:d,outputDirection:i,mipInt:o,envMap:l,CUBEUV_TEXEL_WIDTH:c,CUBEUV_TEXEL_HEIGHT:u,CUBEUV_MAX_MIP:h}))),uT({start:Cg(1),end:t},(({i:t})=>{wg(t.greaterThanEqual(r),(()=>{dT()}));const e=Ng(a.mul(Ng(t))).toVar();p.addAssign(s.element(t).mul(qw({theta:e.mul(-1),axis:d,outputDirection:i,mipInt:o,envMap:l,CUBEUV_TEXEL_WIDTH:c,CUBEUV_TEXEL_HEIGHT:u,CUBEUV_MAX_MIP:h}))),p.addAssign(s.element(t).mul(qw({theta:e,axis:d,outputDirection:i,mipInt:o,envMap:l,CUBEUV_TEXEL_WIDTH:c,CUBEUV_TEXEL_HEIGHT:u,CUBEUV_MAX_MIP:h})))})),Bg(p,1)}));let Zw=null;const $w=new WeakMap;function Jw(t){let e=$w.get(t);if((void 0!==e?e.pmremVersion:-1)!==t.pmremVersion){const n=t.image;if(t.isCubeTexture){if(!function(t){if(null==t)return!1;let e=0;const n=6;for(let i=0;i0}(n))return null;e=Zw.fromEquirectangular(t,e)}e.pmremVersion=t.pmremVersion,$w.set(t,e)}return e.texture}class Kw extends Pf{static get type(){return"PMREMNode"}constructor(t,e=null,n=null){super("vec3"),this._value=t,this._pmrem=null,this.uvNode=e,this.levelNode=n,this._generator=null;const i=new Ti;i.isRenderTargetTexture=!0,this._texture=bx(i),this._width=rv(0),this._height=rv(0),this._maxMip=rv(0),this.updateBeforeType=Tf.RENDER}set value(t){this._value=t,this._pmrem=null}get value(){return this._value}updateFromTexture(t){const e=function(t){const e=Math.log2(t)-2,n=1/t;return{texelWidth:1/(3*Math.max(Math.pow(2,e),112)),texelHeight:n,maxMip:e}}(t.image.height);this._texture.value=t,this._width.value=e.texelWidth,this._height.value=e.texelHeight,this._maxMip.value=e.maxMip}updateBefore(){let t=this._pmrem;const e=t?t.pmremVersion:-1,n=this._value;e!==n.pmremVersion&&(t=!0===n.isPMREMTexture?n:Jw(n),null!==t&&(this._pmrem=t,this.updateFromTexture(t)))}setup(t){null===Zw&&(Zw=t.createPMREMGenerator()),this.updateBefore(t);let e=this.uvNode;null===e&&t.context.getUV&&(e=t.context.getUV(this));const n=this.value;t.renderer.coordinateSystem===Bn&&!0!==n.isPMREMTexture&&!0===n.isRenderTargetTexture&&(e=Og(e.x.negate(),e.yz));let i=this.levelNode;return null===i&&t.context.getTextureLevel&&(i=t.context.getTextureLevel(this)),jw(this._texture,e,i,this._width,this._height,this._maxMip)}}const Qw=_g(Kw),tE=new WeakMap;class eE extends TT{static get type(){return"EnvironmentNode"}constructor(t=null){super(),this.envNode=t}setup(t){const{material:e}=t;let n=this.envNode;if(n.isTextureNode||n.isMaterialReferenceNode){const t=n.isTextureNode?n.value:e[n.property];let i=tE.get(t);void 0===i&&(i=Qw(t),tE.set(t,i)),n=i}const i=e.envMap?LM("envMapIntensity","float",t.material):LM("environmentIntensity","float",t.scene),s=!0===e.useAnisotropy||e.anisotropy>0?KM:dM,r=n.context(nE(hv,s)).mul(i),a=n.context(iE(pM)).mul(Math.PI).mul(i),o=ex(r),l=ex(a);t.context.radiance.addAssign(o),t.context.iblIrradiance.addAssign(l);const c=t.context.lightingModel.clearcoatRadiance;if(c){const t=n.context(nE(mv,mM)).mul(i),e=ex(t);c.addAssign(e)}}}const nE=(t,e)=>{let n=null;return{getUV:()=>(null===n&&(n=iM.negate().reflect(e),n=t.mul(t).mix(n,e).normalize(),n=n.transformDirection(Rx)),n),getTextureLevel:()=>t}},iE=t=>({getUV:()=>t,getTextureLevel:()=>Ng(1)}),sE=new vd;class rE extends sS{static get type(){return"MeshStandardNodeMaterial"}constructor(t){super(),this.isMeshStandardNodeMaterial=!0,this.lights=!0,this.emissiveNode=null,this.metalnessNode=null,this.roughnessNode=null,this.setDefaultValues(sE),this.setValues(t)}setupEnvironment(t){let e=super.setupEnvironment(t);return null===e&&t.environmentNode&&(e=t.environmentNode),e?new eE(e):null}setupLightingModel(){return new Nw}setupSpecular(){const t=d_(Og(.04),cv.rgb,dv);Sv.assign(t),wv.assign(1)}setupVariants(){const t=this.metalnessNode?Ng(this.metalnessNode):_b;dv.assign(t);let e=this.roughnessNode?Ng(this.roughnessNode):yb;e=kS({roughness:e}),hv.assign(e),this.setupSpecular(),cv.assign(Bg(cv.rgb.mul(t.oneMinus()),cv.a))}copy(t){return this.emissiveNode=t.emissiveNode,this.metalnessNode=t.metalnessNode,this.roughnessNode=t.roughnessNode,super.copy(t)}}const aE=new yd;class oE extends rE{static get type(){return"MeshPhysicalNodeMaterial"}constructor(t){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(aE),this.setValues(t)}get useClearcoat(){return this.clearcoat>0||null!==this.clearcoatNode}get useIridescence(){return this.iridescence>0||null!==this.iridescenceNode}get useSheen(){return this.sheen>0||null!==this.sheenNode}get useAnisotropy(){return this.anisotropy>0||null!==this.anisotropyNode}get useTransmission(){return this.transmission>0||null!==this.transmissionNode}get useDispersion(){return this.dispersion>0||null!==this.dispersionNode}setupSpecular(){const t=this.iorNode?Ng(this.iorNode):Pb;Iv.assign(t),Sv.assign(d_($y(a_(Iv.sub(1).div(Iv.add(1))).mul(fb),Og(1)).mul(mb),cv.rgb,dv)),wv.assign(d_(mb,1,dv))}setupLightingModel(){return new Nw(this.useClearcoat,this.useSheen,this.useIridescence,this.useAnisotropy,this.useTransmission,this.useDispersion)}setupVariants(t){if(super.setupVariants(t),this.useClearcoat){const t=this.clearcoatNode?Ng(this.clearcoatNode):Mb,e=this.clearcoatRoughnessNode?Ng(this.clearcoatRoughnessNode):bb;pv.assign(t),mv.assign(kS({roughness:e}))}if(this.useSheen){const t=this.sheenNode?Og(this.sheenNode):wb,e=this.sheenRoughnessNode?Ng(this.sheenRoughnessNode):Eb;fv.assign(t),gv.assign(e)}if(this.useIridescence){const t=this.iridescenceNode?Ng(this.iridescenceNode):Nb,e=this.iridescenceIORNode?Ng(this.iridescenceIORNode):Cb,n=this.iridescenceThicknessNode?Ng(this.iridescenceThicknessNode):Rb;vv.assign(t),yv.assign(e),_v.assign(n)}if(this.useAnisotropy){const t=(this.anisotropyNode?Lg(this.anisotropyNode):Ab).toVar();Mv.assign(t.length()),wg(Mv.equal(0),(()=>{t.assign(Lg(1,0))})).Else((()=>{t.divAssign(Lg(Mv)),Mv.assign(Mv.saturate())})),xv.assign(Mv.pow2().mix(hv.pow2(),1)),bv.assign(ZM[0].mul(t.x).add(ZM[1].mul(t.y))),Tv.assign(ZM[1].mul(t.x).sub(ZM[0].mul(t.y)))}if(this.useTransmission){const t=this.transmissionNode?Ng(this.transmissionNode):Ib,e=this.thicknessNode?Ng(this.thicknessNode):Lb,n=this.attenuationDistanceNode?Ng(this.attenuationDistanceNode):Ub,i=this.attenuationColorNode?Og(this.attenuationColorNode):Db;if(Lv.assign(t),Pv.assign(e),Uv.assign(n),Dv.assign(i),this.useDispersion){const t=this.dispersionNode?Ng(this.dispersionNode):Hb;Ov.assign(t)}}}setupClearcoatNormal(){return this.clearcoatNormalNode?Og(this.clearcoatNormalNode):Tb}setup(t){t.context.setupClearcoatNormal=()=>this.setupClearcoatNormal(t),super.setup(t)}copy(t){return this.clearcoatNode=t.clearcoatNode,this.clearcoatRoughnessNode=t.clearcoatRoughnessNode,this.clearcoatNormalNode=t.clearcoatNormalNode,this.sheenNode=t.sheenNode,this.sheenRoughnessNode=t.sheenRoughnessNode,this.iridescenceNode=t.iridescenceNode,this.iridescenceIORNode=t.iridescenceIORNode,this.iridescenceThicknessNode=t.iridescenceThicknessNode,this.specularIntensityNode=t.specularIntensityNode,this.specularColorNode=t.specularColorNode,this.transmissionNode=t.transmissionNode,this.thicknessNode=t.thicknessNode,this.attenuationDistanceNode=t.attenuationDistanceNode,this.attenuationColorNode=t.attenuationColorNode,this.dispersionNode=t.dispersionNode,this.anisotropyNode=t.anisotropyNode,super.copy(t)}}class lE extends Nw{constructor(t,e,n,i){super(t,e,n),this.useSSS=i}direct({lightDirection:t,lightColor:e,reflectedLight:n},i,s){if(!0===this.useSSS){const i=s.material,{thicknessColorNode:r,thicknessDistortionNode:a,thicknessAmbientNode:o,thicknessAttenuationNode:l,thicknessPowerNode:c,thicknessScaleNode:u}=i,h=t.add(dM.mul(a)).normalize(),d=Ng(iM.dot(h.negate()).saturate().pow(c).mul(u)),p=Og(d.add(o).mul(r));n.directDiffuse.addAssign(p.mul(l.mul(e)))}super.direct({lightDirection:t,lightColor:e,reflectedLight:n},i,s)}}class cE extends oE{static get type(){return"MeshSSSNodeMaterial"}constructor(t){super(t),this.thicknessColorNode=null,this.thicknessDistortionNode=Ng(.1),this.thicknessAmbientNode=Ng(0),this.thicknessAttenuationNode=Ng(.1),this.thicknessPowerNode=Ng(2),this.thicknessScaleNode=Ng(10)}get useSSS(){return null!==this.thicknessColorNode}setupLightingModel(){return new lE(this.useClearcoat,this.useSheen,this.useIridescence,this.useSSS)}copy(t){return this.thicknessColorNode=t.thicknessColorNode,this.thicknessDistortionNode=t.thicknessDistortionNode,this.thicknessAmbientNode=t.thicknessAmbientNode,this.thicknessAttenuationNode=t.thicknessAttenuationNode,this.thicknessPowerNode=t.thicknessPowerNode,this.thicknessScaleNode=t.thicknessScaleNode,super.copy(t)}}const uE=Mg((({normal:t,lightDirection:e,builder:n})=>{const i=t.dot(e),s=Lg(i.mul(.5).add(.5),0);if(n.material.gradientMap){const t=DM("gradientMap","texture").context({getUV:()=>s});return Og(t.r)}{const t=s.fwidth().mul(.5);return d_(Og(.7),Og(1),g_(Ng(.7).sub(t.x),Ng(.7).add(t.x),s.x))}}));class hE extends AS{direct({lightDirection:t,lightColor:e,reflectedLight:n},i,s){const r=uE({normal:oM,lightDirection:t,builder:s}).mul(e);n.directDiffuse.addAssign(r.mul(LS({diffuseColor:cv.rgb})))}indirect({ambientOcclusion:t,irradiance:e,reflectedLight:n}){n.indirectDiffuse.addAssign(e.mul(LS({diffuseColor:cv}))),n.indirectDiffuse.mulAssign(t)}}const dE=new xd;class pE extends sS{static get type(){return"MeshToonNodeMaterial"}constructor(t){super(),this.isMeshToonNodeMaterial=!0,this.lights=!0,this.setDefaultValues(dE),this.setValues(t)}setupLightingModel(){return new hE}}class mE extends Pf{static get type(){return"MatcapUVNode"}constructor(){super("vec2")}setup(){const t=Og(iM.z,0,iM.x.negate()).normalize(),e=iM.cross(t);return Lg(t.dot(dM),e.dot(dM)).mul(.495).add(.5)}}const fE=xg(mE),gE=new Td;class vE extends sS{static get type(){return"MeshMatcapNodeMaterial"}constructor(t){super(),this.lights=!1,this.isMeshMatcapNodeMaterial=!0,this.setDefaultValues(gE),this.setValues(t)}setupVariants(t){const e=fE;let n;n=t.material.matcap?DM("matcap","texture").context({getUV:()=>e}):Og(d_(.2,.8,e.y)),cv.rgb.mulAssign(n.rgb)}}const yE=new Pu;class _E extends sS{static get type(){return"PointsNodeMaterial"}constructor(t){super(),this.isPointsNodeMaterial=!0,this.lights=!1,this.transparent=!0,this.sizeNode=null,this.setDefaultValues(yE),this.setValues(t)}copy(t){return this.sizeNode=t.sizeNode,super.copy(t)}}class xE extends Pf{static get type(){return"RotateNode"}constructor(t,e){super(),this.positionNode=t,this.rotationNode=e}getNodeType(t){return this.positionNode.getNodeType(t)}setup(t){const{rotationNode:e,positionNode:n}=this;if("vec2"===this.getNodeType(t)){const t=e.cos(),i=e.sin();return Wg(t,i,i.negate(),t).mul(n)}{const t=e,i=Xg(Bg(1,0,0,0),Bg(0,Iy(t.x),Ry(t.x).negate(),0),Bg(0,Ry(t.x),Iy(t.x),0),Bg(0,0,0,1)),s=Xg(Bg(Iy(t.y),0,Ry(t.y),0),Bg(0,1,0,0),Bg(Ry(t.y).negate(),0,Iy(t.y),0),Bg(0,0,0,1)),r=Xg(Bg(Iy(t.z),Ry(t.z).negate(),0,0),Bg(Ry(t.z),Iy(t.z),0,0),Bg(0,0,1,0),Bg(0,0,0,1));return i.mul(s).mul(r).mul(Bg(n,1)).xyz}}}const ME=_g(xE),bE=new hc;class TE extends sS{static get type(){return"SpriteNodeMaterial"}constructor(t){super(),this.isSpriteNodeMaterial=!0,this.lights=!1,this._useSizeAttenuation=!0,this.positionNode=null,this.rotationNode=null,this.scaleNode=null,this.setDefaultValues(bE),this.setValues(t)}setupPosition({object:t,camera:e,context:n}){const i=this.sizeAttenuation,{positionNode:s,rotationNode:r,scaleNode:a}=this,o=Kx;let l=Yx.mul(Og(s||0)),c=Lg(Hx[0].xyz.length(),Hx[1].xyz.length());null!==a&&(c=c.mul(a)),!i&&e.isPerspectiveCamera&&(c=c.mul(l.z.negate()));let u=o.xy;if(t.center&&!0===t.center.isVector2){const t=((t,e,n)=>gg(new k_(t,e,n)))("center","vec2");u=u.sub(t.sub(.5))}u=u.mul(c);const h=Ng(r||Sb),d=ME(u,h);l=Bg(l.xy.add(d),l.zw);const p=Nx.mul(l);return n.vertex=o,p}copy(t){return this.positionNode=t.positionNode,this.rotationNode=t.rotationNode,this.scaleNode=t.scaleNode,super.copy(t)}get sizeAttenuation(){return this._useSizeAttenuation}set sizeAttenuation(t){this._useSizeAttenuation!==t&&(this._useSizeAttenuation=t,this.needsUpdate=!0)}}class SE extends AS{constructor(){super(),this.shadowNode=Ng(1).toVar("shadowMask")}direct({shadowMask:t}){this.shadowNode.mulAssign(t)}finish(t){cv.a.mulAssign(this.shadowNode.oneMinus()),t.outgoingLight.rgb.assign(cv.rgb)}}const wE=new fd;class EE extends sS{static get type(){return"ShadowNodeMaterial"}constructor(t){super(),this.isShadowNodeMaterial=!0,this.lights=!0,this.setDefaultValues(wE),this.setValues(t)}setupLightingModel(){return new SE}}const AE=Mg((({texture:t,uv:e})=>{const n=1e-4,i=Og().toVar();return wg(e.x.lessThan(n),(()=>{i.assign(Og(1,0,0))})).ElseIf(e.y.lessThan(n),(()=>{i.assign(Og(0,1,0))})).ElseIf(e.z.lessThan(n),(()=>{i.assign(Og(0,0,1))})).ElseIf(e.x.greaterThan(.9999),(()=>{i.assign(Og(-1,0,0))})).ElseIf(e.y.greaterThan(.9999),(()=>{i.assign(Og(0,-1,0))})).ElseIf(e.z.greaterThan(.9999),(()=>{i.assign(Og(0,0,-1))})).Else((()=>{const n=.01,s=t.uv(e.add(Og(-.01,0,0))).r.sub(t.uv(e.add(Og(n,0,0))).r),r=t.uv(e.add(Og(0,-.01,0))).r.sub(t.uv(e.add(Og(0,n,0))).r),a=t.uv(e.add(Og(0,0,-.01))).r.sub(t.uv(e.add(Og(0,0,n))).r);i.assign(Og(s,r,a))})),i.normalize()}));class NE extends Mx{static get type(){return"Texture3DNode"}constructor(t,e=null,n=null){super(t,e,n),this.isTexture3DNode=!0}getInputType(){return"texture3D"}getDefaultUV(){return Og(.5,.5,.5)}setUpdateMatrix(){}setupUV(t,e){return e}generateUV(t,e){return e.build(t,"vec3")}normal(t){return AE({texture:this,uv:t})}}const CE=_g(NE);class RE extends sS{static get type(){return"VolumeNodeMaterial"}constructor(t={}){super(),this.lights=!1,this.isVolumeNodeMaterial=!0,this.testNode=null,this.setValues(t)}setup(t){const e=CE(this.map,null,0),n=Mg((({orig:t,dir:e})=>{const n=Og(-.5),i=Og(.5),s=e.reciprocal(),r=n.sub(t).mul(s),a=i.sub(t).mul(s),o=$y(r,a),l=Jy(r,a),c=Jy(o.x,Jy(o.y,o.z)),u=$y(l.x,$y(l.y,l.z));return Lg(c,u)}));this.fragmentNode=Mg((()=>{const t=R_(Og(qx.mul(Bg(Px,1)))),i=R_(Jx.sub(t)).normalize(),s=Lg(n({orig:t,dir:i})).toVar();s.x.greaterThan(s.y).discard(),s.assign(Lg(Jy(s.x,0),s.y));const r=Og(t.add(s.x.mul(i))).toVar(),a=Og(i.abs().reciprocal()).toVar(),o=Ng($y(a.x,$y(a.y,a.z))).toVar("delta");o.divAssign(DM("steps","float"));const l=Bg(DM("base","color"),0).toVar();return uT({type:"float",start:s.x,end:s.y,update:"+= delta"},(()=>{const t=ov("float","d").assign(e.uv(r.add(.5)).r);null!==this.testNode?this.testNode({map:e,mapValue:t,probe:r,finalColor:l}).append():(l.a.assign(1),dT()),r.addAssign(i.mul(o))})),l.a.equal(0).discard(),Bg(l)}))(),super.setup(t)}}class IE extends Yd{constructor(t){super(t),this.textures={},this.nodes={}}load(t,e,n,i){const s=new Jd(this.manager);s.setPath(this.path),s.setRequestHeader(this.requestHeader),s.setWithCredentials(this.withCredentials),s.load(t,(n=>{try{e(this.parse(JSON.parse(n)))}catch(e){i?i(e):console.error(e),this.manager.itemError(t)}}),n,i)}parseNodes(t){const e={};if(void 0!==t){for(const n of t){const{uuid:t,type:i}=n;e[t]=this.createNodeFromType(i),e[t].uuid=t}const n={nodes:e,textures:this.textures};for(const i of t){i.meta=n;e[i.uuid].deserialize(i),delete i.meta}}return e}parse(t){const e=this.createNodeFromType(t.type);e.uuid=t.uuid;const n={nodes:this.parseNodes(t.nodes),textures:this.textures};return t.meta=n,e.deserialize(t),delete t.meta,e}setTextures(t){return this.textures=t,this}setNodes(t){return this.nodes=t,this}createNodeFromType(t){return void 0===this.nodes[t]?(console.error("THREE.NodeLoader: Node type not found:",t),Ng()):gg(new this.nodes[t])}}class LE extends Tp{constructor(t){super(t),this.nodes={},this.nodeMaterials={}}parse(t){const e=super.parse(t),n=this.nodes,i=t.inputNodes;for(const t in i){const s=i[t];e[t]=n[s]}return e}setNodes(t){return this.nodes=t,this}setNodeMaterials(t){return this.nodeMaterials=t,this}createMaterialFromType(t){const e=this.nodeMaterials[t];return void 0!==e?new e:super.createMaterialFromType(t)}}class PE extends Ap{constructor(t){super(t),this.nodes={},this.nodeMaterials={},this._nodesJSON=null}setNodes(t){return this.nodes=t,this}setNodeMaterials(t){return this.nodeMaterials=t,this}parse(t,e){this._nodesJSON=t.nodes;const n=super.parse(t,e);return this._nodesJSON=null,n}parseNodes(t,e){if(void 0!==t){const n=new IE;return n.setNodes(this.nodes),n.setTextures(e),n.parseNodes(t)}return{}}parseMaterials(t,e){const n={};if(void 0!==t){const i=this.parseNodes(this._nodesJSON,e),s=new LE;s.setTextures(e),s.setNodes(i),s.setNodeMaterials(this.nodeMaterials);for(let e=0,i=t.length;egg(new kE(t,e));class GE extends Rf{static get type(){return"CodeNode"}constructor(t="",e=[],n=""){super("code"),this.isCodeNode=!0,this.code=t,this.language=n,this.includes=e}isGlobal(){return!0}setIncludes(t){return this.includes=t,this}getIncludes(){return this.includes}generate(t){const e=this.getIncludes(t);for(const n of e)n.build(t);const n=t.getCodeFromNode(this,this.getNodeType(t));return n.code=this.code,n.code}serialize(t){super.serialize(t),t.code=this.code,t.language=this.language}deserialize(t){super.deserialize(t),this.code=t.code,this.language=t.language}}const WE=_g(GE),jE=(t,e)=>WE(t,e,"js"),XE=(t,e)=>WE(t,e,"wgsl"),qE=(t,e)=>WE(t,e,"glsl");class YE extends GE{static get type(){return"FunctionNode"}constructor(t="",e=[],n=""){super(t,e,n)}getNodeType(t){return this.getNodeFunction(t).type}getInputs(t){return this.getNodeFunction(t).inputs}getNodeFunction(t){const e=t.getDataFromNode(this);let n=e.nodeFunction;return void 0===n&&(n=t.parser.parseFunction(this.code),e.nodeFunction=n),n}generate(t,e){super.generate(t);const n=this.getNodeFunction(t),i=n.name,s=n.type,r=t.getCodeFromNode(this,s);""!==i&&(r.name=i);const a=t.getPropertyName(r),o=this.getNodeFunction(t).getCode(a);return r.code=o+"\n","property"===e?a:t.format(`${a}()`,s,e)}}const ZE=(t,e=[],n="")=>{for(let t=0;ti.call(...t);return s.functionNode=i,s},$E=(t,e)=>ZE(t,e,"glsl"),JE=(t,e)=>ZE(t,e,"wgsl");class KE{constructor(t,e){this.name=t,this.value=e,this.boundary=0,this.itemSize=0,this.offset=0}setValue(t){this.value=t}getValue(){return this.value}}class QE extends KE{constructor(t,e=0){super(t,e),this.isNumberUniform=!0,this.boundary=4,this.itemSize=1}}class tA extends KE{constructor(t,e=new ti){super(t,e),this.isVector2Uniform=!0,this.boundary=8,this.itemSize=2}}class eA extends KE{constructor(t,e=new Li){super(t,e),this.isVector3Uniform=!0,this.boundary=16,this.itemSize=3}}class nA extends KE{constructor(t,e=new Si){super(t,e),this.isVector4Uniform=!0,this.boundary=16,this.itemSize=4}}class iA extends KE{constructor(t,e=new tr){super(t,e),this.isColorUniform=!0,this.boundary=16,this.itemSize=3}}class sA extends KE{constructor(t,e=new ei){super(t,e),this.isMatrix3Uniform=!0,this.boundary=48,this.itemSize=12}}class rA extends KE{constructor(t,e=new ls){super(t,e),this.isMatrix4Uniform=!0,this.boundary=64,this.itemSize=16}}class aA extends QE{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class oA extends tA{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class lA extends eA{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class cA extends nA{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class uA extends iA{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class hA extends sA{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class dA extends rA{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class pA extends Rf{static get type(){return"StackNode"}constructor(t=null){super(),this.nodes=[],this.outputNode=null,this.parent=t,this._currentCond=null,this.isStackNode=!0}getNodeType(t){return this.outputNode?this.outputNode.getNodeType(t):"void"}add(t){return this.nodes.push(t),this}If(t,e){const n=new fg(e);return this._currentCond=b_(t,n),this.add(this._currentCond)}ElseIf(t,e){const n=new fg(e),i=b_(t,n);return this._currentCond.elseNode=i,this._currentCond=i,this}Else(t){return this._currentCond.elseNode=new fg(t),this}build(t,...e){const n=Sg();Tg(this);for(const e of this.nodes)e.build(t,"void");return Tg(n),this.outputNode?this.outputNode.build(t,...e):super.build(t,...e)}else(...t){return console.warn("TSL.StackNode: .else() has been renamed to .Else()."),this.Else(...t)}elseif(...t){return console.warn("TSL.StackNode: .elseif() has been renamed to .ElseIf()."),this.ElseIf(...t)}}const mA=_g(pA);class fA{constructor(){this.weakMap=new WeakMap}get(t){let e=this.weakMap;for(let n=0;n0&&this._blur(s,0,0,e),this._applyPMREM(s),this._cleanup(s),s}fromEquirectangular(t,e=null){return this._fromTexture(t,e)}fromCubemap(t,e=null){return this._fromTexture(t,e)}async compileCubemapShader(){null===this._cubemapMaterial&&(this._cubemapMaterial=UA(),await this._compileMaterial(this._cubemapMaterial))}async compileEquirectangularShader(){null===this._equirectMaterial&&(this._equirectMaterial=DA(),await this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),null!==this._cubemapMaterial&&this._cubemapMaterial.dispose(),null!==this._equirectMaterial&&this._equirectMaterial.dispose(),null!==this._backgroundBox&&(this._backgroundBox.geometry.dispose(),this._backgroundBox.material.dispose())}_setSize(t){this._lodMax=Math.floor(Math.log2(t)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){null!==this._blurMaterial&&this._blurMaterial.dispose(),null!==this._pingPongRenderTarget&&this._pingPongRenderTarget.dispose();for(let t=0;tt-4?l=gA[o-t+4-1]:0===o&&(l=0),i.push(l);const c=1/(a-2),u=-c,h=1+c,d=[u,u,h,u,h,h,u,u,h,h,u,h],p=6,m=6,f=3,g=2,v=1,y=new Float32Array(f*m*p),_=new Float32Array(g*m*p),x=new Float32Array(v*m*p);for(let t=0;t2?0:-1,i=[e,n,0,e+2/3,n,0,e+2/3,n+1,0,e,n,0,e+2/3,n+1,0,e,n+1,0],s=AA[t];y.set(i,f*m*s),_.set(d,g*m*s);const r=[s,s,s,s,s,s];x.set(r,v*m*s)}const M=new Cr;M.setAttribute("position",new dr(y,f)),M.setAttribute("uv",new dr(_,g)),M.setAttribute("faceIndex",new dr(x,v)),e.push(M),s.push(new kr(M,null)),r>4&&r--}return{lodPlanes:e,sizeLods:n,sigmas:i,lodMeshes:s}}(i)),this._blurMaterial=function(t,e,n){const i=NM(new Array(vA).fill(0)),s=rv(new Li(0,1,0)),r=rv(0),a=Ng(vA),o=rv(0),l=rv(1),c=bx(null),u=rv(0),h=Ng(1/e),d=Ng(1/n),p=Ng(t),m={n:a,latitudinal:o,weights:i,poleAxis:s,outputDirection:CA,dTheta:r,samples:l,envMap:c,mipInt:u,CUBEUV_TEXEL_WIDTH:h,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:p},f=PA("blur");return f.uniforms=m,f.fragmentNode=Yw({...m,latitudinal:o.equal(1)}),f}(i,t,e)}return i}async _compileMaterial(t){const e=new kr(this._lodPlanes[0],t);await this._renderer.compile(e,yA)}_sceneToCubeUV(t,e,n,i){const s=_A;s.near=e,s.far=n;const r=[-1,1,-1,-1,-1,-1],a=[1,1,1,-1,-1,-1],o=this._renderer,l=o.autoClear;o.getClearColor(xA),o.autoClear=!1;let c=this._backgroundBox;if(null===c){const t=new sr({name:"PMREM.Background",side:1,depthWrite:!1,depthTest:!1});c=new kr(new Gr,t)}let u=!1;const h=t.background;h?h.isColor&&(c.material.color.copy(h),t.background=null,u=!0):(c.material.color.copy(xA),u=!0),o.setRenderTarget(i),o.clear(),u&&o.render(c,s);for(let e=0;e<6;e++){const n=e%3;0===n?(s.up.set(0,r[e],0),s.lookAt(a[e],0,0)):1===n?(s.up.set(0,0,r[e]),s.lookAt(0,a[e],0)):(s.up.set(0,r[e],0),s.lookAt(0,0,a[e]));const l=this._cubeSize;LA(i,n*l,e>2?l:0,l,l),o.render(t,s)}o.autoClear=l,t.background=h}_textureToCubeUV(t,e){const n=this._renderer,i=t.mapping===lt||t.mapping===ct;i?null===this._cubemapMaterial&&(this._cubemapMaterial=UA(t)):null===this._equirectMaterial&&(this._equirectMaterial=DA(t));const s=i?this._cubemapMaterial:this._equirectMaterial;s.fragmentNode.value=t;const r=this._lodMeshes[0];r.material=s;const a=this._cubeSize;LA(e,0,0,3*a,2*a),n.setRenderTarget(e),n.render(r,yA)}_applyPMREM(t){const e=this._renderer,n=e.autoClear;e.autoClear=!1;const i=this._lodPlanes.length;for(let e=1;evA&&console.warn(`sigmaRadians, ${s}, is too large and will clip, as it requested ${m} samples when the maximum is set to 20`);const f=[];let g=0;for(let t=0;tv-4?i-v+4:0),4*(this._cubeSize-y),3*y,2*y),o.setRenderTarget(e),o.render(c,yA)}}function IA(t,e,n){const i=new wi(t,e,n);return i.texture.mapping=dt,i.texture.name="PMREM.cubeUv",i.texture.isPMREMTexture=!0,i.scissorTest=!0,i}function LA(t,e,n,i,s){t.viewport.set(e,n,i,s),t.scissor.set(e,n,i,s)}function PA(t){const e=new sS;return e.depthTest=!1,e.depthWrite=!1,e.blending=0,e.name=`PMREM_${t}`,e}function UA(t){const e=PA("cubemap");return e.fragmentNode=TM(t,CA),e}function DA(t){const e=PA("equirect");return e.fragmentNode=bx(t,yS(CA),0),e}let OA=0;class zA{constructor(t="",e=[],n=0,i=[]){this.name=t,this.bindings=e,this.index=n,this.bindingsReference=i,this.id=OA++}}const VA=new WeakMap,FA=new Map([[2,"vec2"],[3,"vec3"],[4,"vec4"],[9,"mat3"],[16,"mat4"]]),BA=new Map([[Int8Array,"int"],[Int16Array,"int"],[Int32Array,"int"],[Uint8Array,"uint"],[Uint16Array,"uint"],[Uint32Array,"uint"],[Float32Array,"float"]]),kA=t=>(t=Number(t))+(t%1?"":".0");class HA{constructor(t,e,n){this.object=t,this.material=t&&t.material||null,this.geometry=t&&t.geometry||null,this.renderer=e,this.parser=n,this.scene=null,this.camera=null,this.nodes=[],this.updateNodes=[],this.updateBeforeNodes=[],this.updateAfterNodes=[],this.hashNodes={},this.monitor=null,this.lightsNode=null,this.environmentNode=null,this.fogNode=null,this.clippingContext=null,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.bindings={vertex:{},fragment:{},compute:{}},this.bindingsIndexes={},this.bindGroups=null,this.attributes=[],this.bufferAttributes=[],this.varyings=[],this.codes={},this.vars={},this.flow={code:""},this.chaining=[],this.stack=mA(),this.stacks=[],this.tab="\t",this.currentFunctionNode=null,this.context={material:this.material},this.cache=new BE,this.globalCache=this.cache,this.flowsData=new WeakMap,this.shaderStage=null,this.buildStage=null,this.useComparisonMethod=!1}getBindGroupsCache(){let t=VA.get(this.renderer);return void 0===t&&(t=new fA,VA.set(this.renderer,t)),t}createRenderTarget(t,e,n){return new wi(t,e,n)}createCubeRenderTarget(t,e){return new _S(t,e)}createPMREMGenerator(){return new RA(this.renderer)}includes(t){return this.nodes.includes(t)}_getBindGroup(t,e){const n=this.getBindGroupsCache(),i=[];let s,r=!0;for(const t of e)i.push(t),r=r&&!0!==t.groupNode.shared;return r?(s=n.get(i),void 0===s&&(s=new zA(t,i,this.bindingsIndexes[t].group,i),n.set(i,s))):s=new zA(t,i,this.bindingsIndexes[t].group,i),s}getBindGroupArray(t,e){const n=this.bindings[e];let i=n[t];return void 0===i&&(void 0===this.bindingsIndexes[t]&&(this.bindingsIndexes[t]={binding:0,group:Object.keys(this.bindingsIndexes).length}),n[t]=i=[]),i}getBindings(){let t=this.bindGroups;if(null===t){const e={},n=this.bindings;for(const t of Af)for(const i in n[t]){const s=n[t][i];(e[i]||(e[i]=[])).push(...s)}t=[];for(const n in e){const i=e[n],s=this._getBindGroup(n,i);t.push(s)}this.bindGroups=t}return t}sortBindingGroups(){const t=this.getBindings();t.sort(((t,e)=>t.bindings[0].groupNode.order-e.bindings[0].groupNode.order));for(let e=0;e=0?`${Math.round(e)}u`:"0u";if("bool"===t)return e?"true":"false";if("color"===t)return`${this.getType("vec3")}( ${kA(e.r)}, ${kA(e.g)}, ${kA(e.b)} )`;const n=this.getTypeLength(t),i=this.getComponentType(t),s=t=>this.generateConst(i,t);if(2===n)return`${this.getType(t)}( ${s(e.x)}, ${s(e.y)} )`;if(3===n)return`${this.getType(t)}( ${s(e.x)}, ${s(e.y)}, ${s(e.z)} )`;if(4===n)return`${this.getType(t)}( ${s(e.x)}, ${s(e.y)}, ${s(e.z)}, ${s(e.w)} )`;if(n>4&&e&&(e.isMatrix3||e.isMatrix4))return`${this.getType(t)}( ${e.elements.map(s).join(", ")} )`;if(n>4)return`${this.getType(t)}()`;throw new Error(`NodeBuilder: Type '${t}' not found in generate constant attempt.`)}getType(t){return"color"===t?"vec3":t}hasGeometryAttribute(t){return this.geometry&&void 0!==this.geometry.getAttribute(t)}getAttribute(t,e){const n=this.attributes;for(const e of n)if(e.name===t)return e;const i=new UE(t,e);return n.push(i),i}getPropertyName(t){return t.name}isVector(t){return/vec\d/.test(t)}isMatrix(t){return/mat\d/.test(t)}isReference(t){return"void"===t||"property"===t||"sampler"===t||"texture"===t||"cubeTexture"===t||"storageTexture"===t||"depthTexture"===t||"texture3D"===t}needsToWorkingColorSpace(){return!1}getComponentTypeFromTexture(t){const e=t.type;if(t.isDataTexture){if(e===Rt)return"int";if(e===It)return"uint"}return"float"}getElementType(t){return"mat2"===t?"vec2":"mat3"===t?"vec3":"mat4"===t?"vec4":this.getComponentType(t)}getComponentType(t){if("float"===(t=this.getVectorType(t))||"bool"===t||"int"===t||"uint"===t)return t;const e=/(b|i|u|)(vec|mat)([2-4])/.exec(t);return null===e?null:"b"===e[1]?"bool":"i"===e[1]?"int":"u"===e[1]?"uint":"float"}getVectorType(t){return"color"===t?"vec3":"texture"===t||"cubeTexture"===t||"storageTexture"===t||"texture3D"===t?"vec4":t}getTypeFromLength(t,e="float"){if(1===t)return e;const n=FA.get(t);return("float"===e?"":e[0])+n}getTypeFromArray(t){return BA.get(t.constructor)}getTypeFromAttribute(t){let e=t;t.isInterleavedBufferAttribute&&(e=t.data);const n=e.array,i=t.itemSize,s=t.normalized;let r;return t instanceof xr||!0===s||(r=this.getTypeFromArray(n)),this.getTypeFromLength(i,r)}getTypeLength(t){const e=this.getVectorType(t),n=/vec([2-4])/.exec(e);return null!==n?Number(n[1]):"float"===e||"bool"===e||"int"===e||"uint"===e?1:!0===/mat2/.test(t)?4:!0===/mat3/.test(t)?9:!0===/mat4/.test(t)?16:0}getVectorFromMatrix(t){return t.replace("mat","vec")}changeComponentType(t,e){return this.getTypeFromLength(this.getTypeLength(t),e)}getIntegerType(t){const e=this.getComponentType(t);return"int"===e||"uint"===e?t:this.changeComponentType(t,"int")}addStack(){return this.stack=mA(this.stack),this.stacks.push(Sg()||this.stack),Tg(this.stack),this.stack}removeStack(){const t=this.stack;return this.stack=t.parent,Tg(this.stacks.pop()),t}getDataFromNode(t,e=this.shaderStage,n=null){let i=(n=null===n?t.isGlobal(this)?this.globalCache:this.cache:n).getData(t);return void 0===i&&(i={},n.setData(t,i)),void 0===i[e]&&(i[e]={}),i[e]}getNodeProperties(t,e="any"){const n=this.getDataFromNode(t,e);return n.properties||(n.properties={outputNode:null})}getBufferAttributeFromNode(t,e){const n=this.getDataFromNode(t);let i=n.bufferAttribute;if(void 0===i){const s=this.uniforms.index++;i=new UE("nodeAttribute"+s,e,t),this.bufferAttributes.push(i),n.bufferAttribute=i}return i}getStructTypeFromNode(t,e=this.shaderStage){const n=this.getDataFromNode(t,e);if(void 0===n.structType){const i=this.structs.index++;t.name=`StructType${i}`,this.structs[e].push(t),n.structType=t}return t}getUniformFromNode(t,e,n=this.shaderStage,i=null){"in"===i&&(console.warn('NodeBuilder: "in" is a reserved word, using "inValue" instead.',t,i),t.name="inValue",i=t.name);const s=this.getDataFromNode(t,n,this.globalCache);let r=s.uniform;if(void 0===r){const a=this.uniforms.index++;r=new DE(i||"nodeUniform"+a,e,t),this.uniforms[n].push(r),s.uniform=r}return r}getVarFromNode(t,e=null,n=t.getNodeType(this),i=this.shaderStage){const s=this.getDataFromNode(t,i);let r=s.variable;if(void 0===r){const t=this.vars[i]||(this.vars[i]=[]);null===e&&(e="nodeVar"+t.length),r=new OE(e,n),t.push(r),s.variable=r}return r}getVaryingFromNode(t,e=null,n=t.getNodeType(this)){const i=this.getDataFromNode(t,"any");let s=i.varying;if(void 0===s){const t=this.varyings,r=t.length;null===e&&(e="nodeVarying"+r),s=new zE(e,n),t.push(s),i.varying=s}return s}getCodeFromNode(t,e,n=this.shaderStage){const i=this.getDataFromNode(t);let s=i.code;if(void 0===s){const t=this.codes[n]||(this.codes[n]=[]),r=t.length;s=new VE("nodeCode"+r,e),t.push(s),i.code=s}return s}addFlowCodeHierarchy(t,e){const{flowCodes:n,flowCodeBlock:i}=this.getDataFromNode(t);let s=!0,r=e;for(;r;){if(!0===i.get(r)){s=!1;break}r=this.getDataFromNode(r).parentNodeBlock}if(s)for(const t of n)this.addLineFlowCode(t)}addLineFlowCodeBlock(t,e,n){const i=this.getDataFromNode(t),s=i.flowCodes||(i.flowCodes=[]),r=i.flowCodeBlock||(i.flowCodeBlock=new WeakMap);s.push(e),r.set(n,!0)}addLineFlowCode(t,e=null){return""===t||(null!==e&&this.context.nodeBlock&&this.addLineFlowCodeBlock(e,t,this.context.nodeBlock),t=this.tab+t,/;\s*$/.test(t)||(t+=";\n"),this.flow.code+=t),this}addFlowCode(t){return this.flow.code+=t,this}addFlowTab(){return this.tab+="\t",this}removeFlowTab(){return this.tab=this.tab.slice(0,-1),this}getFlowData(t){return this.flowsData.get(t)}flowNode(t){const e=t.getNodeType(this),n=this.flowChildNode(t,e);return this.flowsData.set(t,n),n}buildFunctionNode(t){const e=new YE,n=this.currentFunctionNode;return this.currentFunctionNode=e,e.code=this.buildFunctionCode(t),this.currentFunctionNode=n,e}flowShaderNode(t){const e=t.layout,n={[Symbol.iterator](){let t=0;const e=Object.values(this);return{next:()=>({value:e[t],done:t++>=e.length})}}};for(const t of e.inputs)n[t.name]=new kE(t.type,t.name);t.layout=null;const i=t.call(n),s=this.flowStagesNode(i,e.type);return t.layout=e,s}flowStagesNode(t,e=null){const n=this.flow,i=this.vars,s=this.cache,r=this.buildStage,a=this.stack,o={code:""};this.flow=o,this.vars={},this.cache=new BE,this.stack=mA();for(const n of Ef)this.setBuildStage(n),o.result=t.build(this,e);return o.vars=this.getVars(this.shaderStage),this.flow=n,this.vars=i,this.cache=s,this.stack=a,this.setBuildStage(r),o}getFunctionOperator(){return null}flowChildNode(t,e=null){const n=this.flow,i={code:""};return this.flow=i,i.result=t.build(this,e),this.flow=n,i}flowNodeFromShaderStage(t,e,n=null,i=null){const s=this.shaderStage;this.setShaderStage(t);const r=this.flowChildNode(e,n);return null!==i&&(r.code+=`${this.tab+i} = ${r.result};\n`),this.flowCode[t]=this.flowCode[t]+r.code,this.setShaderStage(s),r}getAttributesArray(){return this.attributes.concat(this.bufferAttributes)}getAttributes(){console.warn("Abstract function.")}getVaryings(){console.warn("Abstract function.")}getVar(t,e){return`${this.getType(t)} ${e}`}getVars(t){let e="";const n=this.vars[t];if(void 0!==n)for(const t of n)e+=`${this.getVar(t.type,t.name)}; `;return e}getUniforms(){console.warn("Abstract function.")}getCodes(t){const e=this.codes[t];let n="";if(void 0!==e)for(const t of e)n+=t.code+"\n";return n}getHash(){return this.vertexShader+this.fragmentShader+this.computeShader}setShaderStage(t){this.shaderStage=t}getShaderStage(){return this.shaderStage}setBuildStage(t){this.buildStage=t}getBuildStage(){return this.buildStage}buildCode(){console.warn("Abstract function.")}build(){const{object:t,material:e,renderer:n}=this;if(null!==e){let t=n.nodes.library.fromMaterial(e);null===t&&(console.error(`NodeMaterial: Material "${e.type}" is not compatible.`),t=new sS),t.build(this)}else this.addFlow("compute",t);for(const t of Ef){this.setBuildStage(t),this.context.vertex&&this.context.vertex.isNode&&this.flowNodeFromShaderStage("vertex",this.context.vertex);for(const e of Af){this.setShaderStage(e);const n=this.flowNodes[e];for(const e of n)"generate"===t?this.flowNode(e):e.build(this)}}return this.setBuildStage(null),this.setShaderStage(null),this.buildCode(),this.buildUpdateNodes(),this}getNodeUniform(t,e){if("float"===e||"int"===e||"uint"===e)return new aA(t);if("vec2"===e||"ivec2"===e||"uvec2"===e)return new oA(t);if("vec3"===e||"ivec3"===e||"uvec3"===e)return new lA(t);if("vec4"===e||"ivec4"===e||"uvec4"===e)return new cA(t);if("color"===e)return new uA(t);if("mat3"===e)return new hA(t);if("mat4"===e)return new dA(t);throw new Error(`Uniform "${e}" not declared.`)}createNodeMaterial(t="NodeMaterial"){throw new Error(`THREE.NodeBuilder: createNodeMaterial() was deprecated. Use new ${t}() instead.`)}format(t,e,n){if((e=this.getVectorType(e))===(n=this.getVectorType(n))||null===n||this.isReference(n))return t;const i=this.getTypeLength(e),s=this.getTypeLength(n);return 16===i&&9===s?`${this.getType(n)}(${t}[0].xyz, ${t}[1].xyz, ${t}[2].xyz)`:9===i&&4===s?`${this.getType(n)}(${t}[0].xy, ${t}[1].xy)`:i>4||s>4||0===s?t:i===s?`${this.getType(n)}( ${t} )`:i>s?this.format(`${t}.${"xyz".slice(0,s)}`,this.getTypeFromLength(s,this.getComponentType(e)),n):4===s&&i>1?`${this.getType(n)}( ${this.format(t,e,"vec3")}, 1.0 )`:2===i?`${this.getType(n)}( ${this.format(t,e,"vec2")}, 0.0 )`:(1===i&&s>1&&e!==this.getComponentType(n)&&(t=`${this.getType(this.getComponentType(n))}( ${t} )`),`${this.getType(n)}( ${t} )`)}getSignature(){return`// Three.js r${t} - Node System\n`}}class GA{constructor(){this.time=0,this.deltaTime=0,this.frameId=0,this.renderId=0,this.startTime=null,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(t,e){let n=t.get(e);return void 0===n&&(n={renderMap:new WeakMap,frameMap:new WeakMap},t.set(e,n)),n}updateBeforeNode(t){const e=t.getUpdateBeforeType(),n=t.updateReference(this);if(e===Tf.FRAME){const{frameMap:e}=this._getMaps(this.updateBeforeMap,n);e.get(n)!==this.frameId&&!1!==t.updateBefore(this)&&e.set(n,this.frameId)}else if(e===Tf.RENDER){const{renderMap:e}=this._getMaps(this.updateBeforeMap,n);e.get(n)!==this.renderId&&!1!==t.updateBefore(this)&&e.set(n,this.renderId)}else e===Tf.OBJECT&&t.updateBefore(this)}updateAfterNode(t){const e=t.getUpdateAfterType(),n=t.updateReference(this);if(e===Tf.FRAME){const{frameMap:e}=this._getMaps(this.updateAfterMap,n);e.get(n)!==this.frameId&&!1!==t.updateAfter(this)&&e.set(n,this.frameId)}else if(e===Tf.RENDER){const{renderMap:e}=this._getMaps(this.updateAfterMap,n);e.get(n)!==this.renderId&&!1!==t.updateAfter(this)&&e.set(n,this.renderId)}else e===Tf.OBJECT&&t.updateAfter(this)}updateNode(t){const e=t.getUpdateType(),n=t.updateReference(this);if(e===Tf.FRAME){const{frameMap:e}=this._getMaps(this.updateMap,n);e.get(n)!==this.frameId&&!1!==t.update(this)&&e.set(n,this.frameId)}else if(e===Tf.RENDER){const{renderMap:e}=this._getMaps(this.updateMap,n);e.get(n)!==this.renderId&&!1!==t.update(this)&&e.set(n,this.renderId)}else e===Tf.OBJECT&&t.update(this)}update(){this.frameId++,void 0===this.lastTime&&(this.lastTime=performance.now()),this.deltaTime=(performance.now()-this.lastTime)/1e3,this.lastTime=performance.now(),this.time+=this.deltaTime}}class WA{constructor(t,e,n=null,i="",s=!1){this.type=t,this.name=e,this.count=n,this.qualifier=i,this.isConst=s}}WA.isNodeFunctionInput=!0;class jA extends Rf{static get type(){return"StructTypeNode"}constructor(t){super(),this.types=t,this.isStructTypeNode=!0}getMemberTypes(){return this.types}}class XA extends Rf{static get type(){return"OutputStructNode"}constructor(...t){super(),this.members=t,this.isOutputStructNode=!0}setup(t){super.setup(t);const e=this.members,n=[];for(let i=0;is&&(i=n,s=r)}}this._candidateFnCall=n=i(...e)}return n}}const KA=_g(JA),QA=t=>(...e)=>KA(t,...e);class tN extends sv{static get type(){return"TimerNode"}constructor(t=tN.LOCAL,e=1,n=0){super(n),this.scope=t,this.scale=e,this.updateType=Tf.FRAME}update(t){const e=this.scope,n=this.scale;e===tN.LOCAL?this.value+=t.deltaTime*n:e===tN.DELTA?this.value=t.deltaTime*n:e===tN.FRAME?this.value=t.frameId:this.value=t.time*n}serialize(t){super.serialize(t),t.scope=this.scope,t.scale=this.scale}deserialize(t){super.deserialize(t),this.scope=t.scope,this.scale=t.scale}}tN.LOCAL="local",tN.GLOBAL="global",tN.DELTA="delta",tN.FRAME="frame";const eN=(t,e=0)=>gg(new tN(tN.LOCAL,t,e)),nN=(t,e=0)=>gg(new tN(tN.GLOBAL,t,e)),iN=(t,e=0)=>gg(new tN(tN.DELTA,t,e)),sN=xg(tN,tN.FRAME).toUint();class rN extends Rf{static get type(){return"OscNode"}constructor(t=rN.SINE,e=eN()){super(),this.method=t,this.timeNode=e}getNodeType(t){return this.timeNode.getNodeType(t)}setup(){const t=this.method,e=gg(this.timeNode);let n=null;return t===rN.SINE?n=e.add(.75).mul(2*Math.PI).sin().mul(.5).add(.5):t===rN.SQUARE?n=e.fract().round():t===rN.TRIANGLE?n=e.add(.5).fract().mul(2).sub(1).abs():t===rN.SAWTOOTH&&(n=e.fract()),n}serialize(t){super.serialize(t),t.method=this.method}deserialize(t){super.deserialize(t),this.method=t.method}}rN.SINE="sine",rN.SQUARE="square",rN.TRIANGLE="triangle",rN.SAWTOOTH="sawtooth";const aN=_g(rN,rN.SINE),oN=_g(rN,rN.SQUARE),lN=_g(rN,rN.TRIANGLE),cN=_g(rN,rN.SAWTOOTH);class uN extends Rf{static get type(){return"SpriteSheetUVNode"}constructor(t,e=gx(),n=Ng(0)){super("vec2"),this.countNode=t,this.uvNode=e,this.frameNode=n}setup(){const{frameNode:t,uvNode:e,countNode:n}=this,{width:i,height:s}=n,r=t.mod(i.mul(s)).floor(),a=r.mod(i),o=s.sub(r.add(1).div(i).ceil()),l=n.reciprocal(),c=Lg(a,o);return e.add(c).mul(l)}}const hN=_g(uN);class dN extends If{static get type(){return"StorageArrayElementNode"}constructor(t,e){super(t,e),this.isStorageArrayElementNode=!0}set storageBufferNode(t){this.node=t}get storageBufferNode(){return this.node}setup(t){return!1===t.isAvailable("storageBuffer")&&!0===this.node.bufferObject&&t.setupPBO(this.node),super.setup(t)}generate(t,e){let n;const i=t.context.assign;if(n=!1===t.isAvailable("storageBuffer")?!0===this.node.bufferObject&&!0!==i?t.generatePBO(this):this.node.build(t):super.generate(t),!0!==i){const i=this.getNodeType(t);n=t.format(n,i,e)}return n}}const pN=_g(dN);class mN extends Rf{static get type(){return"TriplanarTexturesNode"}constructor(t,e=null,n=null,i=Ng(1),s=Kx,r=lM){super("vec4"),this.textureXNode=t,this.textureYNode=e,this.textureZNode=n,this.scaleNode=i,this.positionNode=s,this.normalNode=r}setup(){const{textureXNode:t,textureYNode:e,textureZNode:n,scaleNode:i,positionNode:s,normalNode:r}=this;let a=r.abs().normalize();a=a.div(a.dot(Og(1)));const o=s.yz.mul(i),l=s.zx.mul(i),c=s.xy.mul(i),u=t.value,h=null!==e?e.value:u,d=null!==n?n.value:u,p=bx(u,o).mul(a.x),m=bx(h,l).mul(a.y),f=bx(d,c).mul(a.z);return Hv(p,m,f)}}const fN=_g(mN),gN=(...t)=>fN(...t),vN=new oa,yN=new Li,_N=new Li,xN=new Li,MN=new ls,bN=new Li(0,0,-1),TN=new Si,SN=new Li,wN=new Li,EN=new Si,AN=new ti,NN=new wi,CN=IT.flipX();let RN=!1;class IN extends Mx{static get type(){return"ReflectorNode"}constructor(t={}){super(NN.texture,CN);const{target:e=new Ds,resolution:n=1,generateMipmaps:i=!1,bounces:s=!0}=t;this.target=e,this.resolution=n,this.generateMipmaps=i,this.bounces=s,this.updateBeforeType=s?Tf.RENDER:Tf.FRAME,this.virtualCameras=new WeakMap,this.renderTargets=new WeakMap}_updateResolution(t,e){const n=this.resolution;e.getDrawingBufferSize(AN),t.setSize(Math.round(AN.width*n),Math.round(AN.height*n))}setup(t){return this._updateResolution(NN,t.renderer),super.setup(t)}getTextureNode(){return this.textureNode}getVirtualCamera(t){let e=this.virtualCameras.get(t);return void 0===e&&(e=t.clone(),this.virtualCameras.set(t,e)),e}getRenderTarget(t){let e=this.renderTargets.get(t);return void 0===e&&(e=new wi(0,0,{type:Pt}),!0===this.generateMipmaps&&(e.texture.minFilter=1008,e.texture.generateMipmaps=!0),this.renderTargets.set(t,e)),e}updateBefore(t){if(!1===this.bounces&&RN)return!1;RN=!0;const{scene:e,camera:n,renderer:i,material:s}=t,{target:r}=this,a=this.getVirtualCamera(n),o=this.getRenderTarget(a);if(i.getDrawingBufferSize(AN),this._updateResolution(o,i),_N.setFromMatrixPosition(r.matrixWorld),xN.setFromMatrixPosition(n.matrixWorld),MN.extractRotation(r.matrixWorld),yN.set(0,0,1),yN.applyMatrix4(MN),SN.subVectors(_N,xN),SN.dot(yN)>0)return;SN.reflect(yN).negate(),SN.add(_N),MN.extractRotation(n.matrixWorld),bN.set(0,0,-1),bN.applyMatrix4(MN),bN.add(xN),wN.subVectors(_N,bN),wN.reflect(yN).negate(),wN.add(_N),a.coordinateSystem=n.coordinateSystem,a.position.copy(SN),a.up.set(0,1,0),a.up.applyMatrix4(MN),a.up.reflect(yN),a.lookAt(wN),a.near=n.near,a.far=n.far,a.updateMatrixWorld(),a.projectionMatrix.copy(n.projectionMatrix),vN.setFromNormalAndCoplanarPoint(yN,_N),vN.applyMatrix4(a.matrixWorldInverse),TN.set(vN.normal.x,vN.normal.y,vN.normal.z,vN.constant);const l=a.projectionMatrix;EN.x=(Math.sign(TN.x)+l.elements[8])/l.elements[0],EN.y=(Math.sign(TN.y)+l.elements[9])/l.elements[5],EN.z=-1,EN.w=(1+l.elements[10])/l.elements[14],TN.multiplyScalar(1/TN.dot(EN));l.elements[2]=TN.x,l.elements[6]=TN.y,l.elements[10]=TN.z-0,l.elements[14]=TN.w,this.value=o.texture,s.visible=!1;const c=i.getRenderTarget(),u=i.getMRT();i.setMRT(null),i.setRenderTarget(o),i.render(e,a),i.setMRT(u),i.setRenderTarget(c),s.visible=!0,RN=!1}}const LN=t=>gg(new IN(t)),PN=new Ea(-1,1,1,-1,0,1);class UN extends Cr{constructor(t=!1){super();const e=!1===t?[0,-1,0,1,2,1]:[0,2,0,0,2,0];this.setAttribute("position",new Mr([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new Mr(e,2))}}const DN=new UN;class ON extends kr{constructor(t=null){super(DN,t),this.camera=PN,this.isQuadMesh=!0}renderAsync(t){return t.renderAsync(this,PN)}render(t){t.render(this,PN)}}const zN=new ti;class VN extends Mx{static get type(){return"RTTNode"}constructor(t,e=null,n=null,i={type:Pt}){const s=new wi(e,n,i);super(s.texture,gx()),this.node=t,this.width=e,this.height=n,this.renderTarget=s,this.textureNeedsUpdate=!0,this.autoUpdate=!0,this.updateMap=new WeakMap,this._rttNode=null,this._quadMesh=new ON(new sS),this.updateBeforeType=Tf.RENDER}get autoSize(){return null===this.width}setup(t){return this._rttNode=this.node.context(t.getSharedContext()),this._quadMesh.material.name="RTT",this._quadMesh.material.needsUpdate=!0,super.setup(t)}setSize(t,e){this.width=t,this.height=e;const n=t*this.pixelRatio,i=e*this.pixelRatio;this.renderTarget.setSize(n,i),this.textureNeedsUpdate=!0}setPixelRatio(t){this.pixelRatio=t,this.setSize(this.width,this.height)}updateBefore({renderer:t}){if(!1===this.textureNeedsUpdate&&!1===this.autoUpdate)return;if(this.textureNeedsUpdate=!1,!0===this.autoSize){this.pixelRatio=t.getPixelRatio();const e=t.getSize(zN);this.setSize(e.width,e.height)}this._quadMesh.material.fragmentNode=this._rttNode;const e=t.getRenderTarget();t.setRenderTarget(this.renderTarget),this._quadMesh.render(t),t.setRenderTarget(e)}clone(){const t=new Mx(this.value,this.uvNode,this.levelNode);return t.sampler=this.sampler,t.referenceNode=this,t}}const FN=(t,...e)=>gg(new VN(gg(t),...e)),BN=(t,...e)=>t.isTextureNode?t:FN(t,...e);class kN extends mx{static get type(){return"VertexColorNode"}constructor(t=0){super(null,"vec4"),this.isVertexColorNode=!0,this.index=t}getAttributeName(){const t=this.index;return"color"+(t>0?t:"")}generate(t){const e=this.getAttributeName(t);let n;return n=!0===t.hasGeometryAttribute(e)?super.generate(t):t.generateConst(this.nodeType,new Si(1,1,1,1)),n}serialize(t){super.serialize(t),t.index=this.index}deserialize(t){super.deserialize(t),this.index=t.index}}const HN=(...t)=>gg(new kN(...t));class GN extends Rf{static get type(){return"PointUVNode"}constructor(){super("vec2"),this.isPointUVNode=!0}generate(){return"vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y )"}}const WN=xg(GN);class jN extends Rf{static get type(){return"SceneNode"}constructor(t=jN.BACKGROUND_BLURRINESS,e=null){super(),this.scope=t,this.scene=e}setup(t){const e=this.scope,n=null!==this.scene?this.scene:t.scene;let i;return e===jN.BACKGROUND_BLURRINESS?i=LM("backgroundBlurriness","float",n):e===jN.BACKGROUND_INTENSITY?i=LM("backgroundIntensity","float",n):console.error("THREE.SceneNode: Unknown scope:",e),i}}jN.BACKGROUND_BLURRINESS="backgroundBlurriness",jN.BACKGROUND_INTENSITY="backgroundIntensity";const XN=xg(jN,jN.BACKGROUND_BLURRINESS),qN=xg(jN,jN.BACKGROUND_INTENSITY),YN="storage",ZN="read-only-storage",$N="write-only",JN="read-only";class KN extends SM{static get type(){return"StorageBufferNode"}constructor(t,e,n=0){super(t,e,n),this.isStorageBufferNode=!0,this.access=YN,this.isAtomic=!1,this.bufferObject=!1,this.bufferCount=n,this._attribute=null,this._varying=null,this.global=!0,!0!==t.isStorageBufferAttribute&&!0!==t.isStorageInstancedBufferAttribute&&(t.isInstancedBufferAttribute?t.isStorageInstancedBufferAttribute=!0:t.isStorageBufferAttribute=!0)}getHash(t){if(0===this.bufferCount){let e=t.globalCache.getData(this.value);return void 0===e&&(e={node:this},t.globalCache.setData(this.value,e)),e.node.uuid}return this.uuid}getInputType(){return"storageBuffer"}element(t){return pN(this,t)}setBufferObject(t){return this.bufferObject=t,this}setAccess(t){return this.access=t,this}toReadOnly(){return this.setAccess(ZN)}setAtomic(t){return this.isAtomic=t,this}toAtomic(){return this.setAtomic(!0)}generate(t){if(t.isAvailable("storageBuffer"))return super.generate(t);const e=this.getNodeType(t);null===this._attribute&&(this._attribute=Y_(this.value),this._varying=R_(this._attribute));const n=this._varying.build(t,e);return t.registerTransform(n,this._attribute),n}}const QN=(t,e,n)=>gg(new KN(t,e,n)),tC=(t,e,n)=>gg(new KN(t,e,n).setBufferObject(!0));class eC extends Mx{static get type(){return"StorageTextureNode"}constructor(t,e,n=null){super(t,e),this.storeNode=n,this.isStorageTextureNode=!0,this.access=$N}getInputType(){return"storageTexture"}setup(t){super.setup(t);t.getNodeProperties(this).storeNode=this.storeNode}setAccess(t){return this.access=t,this}generate(t,e){let n;return n=null!==this.storeNode?this.generateStore(t):super.generate(t,e),n}toReadOnly(){return this.setAccess(JN)}toWriteOnly(){return this.setAccess($N)}generateStore(t){const e=t.getNodeProperties(this),{uvNode:n,storeNode:i}=e,s=super.generate(t,"property"),r=n.build(t,"uvec2"),a=i.build(t,"vec4"),o=t.generateTextureStore(t,s,r,a);t.addLineFlowCode(o,this)}}const nC=_g(eC),iC=(t,e,n)=>{const i=nC(t,e,n);return null!==n&&i.append(),i};class sC extends IM{static get type(){return"UserDataNode"}constructor(t,e,n=null){super(t,e,n),this.userData=n}updateReference(t){return this.reference=null!==this.userData?this.userData:t.object.userData,this.reference}}const rC=(t,e,n)=>gg(new sC(t,e,n));class aC extends Pf{static get type(){return"PosterizeNode"}constructor(t,e){super(),this.sourceNode=t,this.stepsNode=e}setup(){const{sourceNode:t,stepsNode:e}=this;return t.mul(e).floor().div(e)}}const oC=_g(aC);let lC=null;class cC extends HT{static get type(){return"ViewportSharedTextureNode"}constructor(t=IT,e=null){null===lC&&(lC=new ku),super(t,e,lC)}updateReference(){return this}}const uC=_g(cC),hC=new ti;class dC extends Mx{static get type(){return"PassTextureNode"}constructor(t,e){super(e),this.passNode=t,this.setUpdateMatrix(!1)}setup(t){return t.object.isQuadMesh&&this.passNode.build(t),super.setup(t)}clone(){return new this.constructor(this.passNode,this.value)}}class pC extends dC{static get type(){return"PassMultipleTextureNode"}constructor(t,e,n=!1){super(t,null),this.textureName=e,this.previousTexture=n}updateTexture(){this.value=this.previousTexture?this.passNode.getPreviousTexture(this.textureName):this.passNode.getTexture(this.textureName)}setup(t){return this.updateTexture(),super.setup(t)}clone(){return new this.constructor(this.passNode,this.textureName,this.previousTexture)}}class mC extends Pf{static get type(){return"PassNode"}constructor(t,e,n,i={}){super("vec4"),this.scope=t,this.scene=e,this.camera=n,this.options=i,this._pixelRatio=1,this._width=1,this._height=1;const s=new Ka;s.isRenderTargetTexture=!0,s.name="depth";const r=new wi(this._width*this._pixelRatio,this._height*this._pixelRatio,{type:Pt,...i});r.texture.name="output",r.depthTexture=s,this.renderTarget=r,this.updateBeforeType=Tf.FRAME,this._textures={output:r.texture,depth:s},this._textureNodes={},this._linearDepthNodes={},this._viewZNodes={},this._previousTextures={},this._previousTextureNodes={},this._cameraNear=rv(0),this._cameraFar=rv(0),this._mrt=null,this.isPassNode=!0}setMRT(t){return this._mrt=t,this}getMRT(){return this._mrt}isGlobal(){return!0}getTexture(t){let e=this._textures[t];if(void 0===e){e=this.renderTarget.texture.clone(),e.isRenderTargetTexture=!0,e.name=t,this._textures[t]=e,this.renderTarget.textures.push(e)}return e}getPreviousTexture(t){let e=this._previousTextures[t];return void 0===e&&(e=this.getTexture(t).clone(),e.isRenderTargetTexture=!0,this._previousTextures[t]=e),e}toggleTexture(t){const e=this._previousTextures[t];if(void 0!==e){const n=this._textures[t],i=this.renderTarget.textures.indexOf(n);this.renderTarget.textures[i]=e,this._textures[t]=e,this._previousTextures[t]=n,this._textureNodes[t].updateTexture(),this._previousTextureNodes[t].updateTexture()}}getTextureNode(t="output"){let e=this._textureNodes[t];return void 0===e&&(this._textureNodes[t]=e=gg(new pC(this,t)),this._textureNodes[t].updateTexture()),e}getPreviousTextureNode(t="output"){let e=this._previousTextureNodes[t];return void 0===e&&(void 0===this._textureNodes[t]&&this.getTextureNode(t),this._previousTextureNodes[t]=e=gg(new pC(this,t,!0)),this._previousTextureNodes[t].updateTexture()),e}getViewZNode(t="depth"){let e=this._viewZNodes[t];if(void 0===e){const n=this._cameraNear,i=this._cameraFar;this._viewZNodes[t]=e=KT(this.getTextureNode(t),n,i)}return e}getLinearDepthNode(t="depth"){let e=this._linearDepthNodes[t];if(void 0===e){const n=this._cameraNear,i=this._cameraFar,s=this.getViewZNode(t);this._linearDepthNodes[t]=e=ZT(s,n,i)}return e}setup({renderer:t}){return this.renderTarget.samples=void 0===this.options.samples?t.samples:this.options.samples,!0===t.backend.isWebGLBackend&&(this.renderTarget.samples=0),this.renderTarget.depthTexture.isMultisampleRenderTargetTexture=this.renderTarget.samples>1,this.scope===mC.COLOR?this.getTextureNode():this.getLinearDepthNode()}updateBefore(t){const{renderer:e}=t,{scene:n,camera:i}=this;this._pixelRatio=e.getPixelRatio();const s=e.getSize(hC);this.setSize(s.width,s.height);const r=e.getRenderTarget(),a=e.getMRT();this._cameraNear.value=i.near,this._cameraFar.value=i.far;for(const t in this._previousTextures)this.toggleTexture(t);e.setRenderTarget(this.renderTarget),e.setMRT(this._mrt),e.render(n,i),e.setRenderTarget(r),e.setMRT(a)}setSize(t,e){this._width=t,this._height=e;const n=this._width*this._pixelRatio,i=this._height*this._pixelRatio;this.renderTarget.setSize(n,i)}setPixelRatio(t){this._pixelRatio=t,this.setSize(this._width,this._height)}dispose(){this.renderTarget.dispose()}}mC.COLOR="color",mC.DEPTH="depth";const fC=(t,e,n)=>gg(new mC(mC.COLOR,t,e,n)),gC=(t,e)=>gg(new dC(t,e)),vC=(t,e)=>gg(new mC(mC.DEPTH,t,e)),yC=new ON,_C=new ON;class xC extends Pf{static get type(){return"GaussianBlurNode"}constructor(t,e=null,n=2){super("vec4"),this.textureNode=t,this.directionNode=e,this.sigma=n,this._invSize=rv(new ti),this._passDirection=rv(new ti),this._horizontalRT=new wi,this._horizontalRT.texture.name="GaussianBlurNode.horizontal",this._verticalRT=new wi,this._verticalRT.texture.name="GaussianBlurNode.vertical",this._textureNode=gC(this,this._verticalRT.texture),this.updateBeforeType=Tf.RENDER,this.resolution=new ti(1,1)}setSize(t,e){t=Math.max(Math.round(t*this.resolution.x),1),e=Math.max(Math.round(e*this.resolution.y),1),this._invSize.value.set(1/t,1/e),this._horizontalRT.setSize(t,e),this._verticalRT.setSize(t,e)}updateBefore(t){const{renderer:e}=t,n=this.textureNode,i=n.value,s=e.getRenderTarget(),r=e.getMRT(),a=n.value;yC.material=this._material,_C.material=this._material,this.setSize(i.image.width,i.image.height);const o=i.type;this._horizontalRT.texture.type=o,this._verticalRT.texture.type=o,e.setMRT(null),e.setRenderTarget(this._horizontalRT),this._passDirection.value.set(1,0),yC.render(e),n.value=this._horizontalRT.texture,e.setRenderTarget(this._verticalRT),this._passDirection.value.set(0,1),_C.render(e),e.setRenderTarget(s),e.setMRT(r),n.value=a}getTextureNode(){return this._textureNode}setup(t){const e=this.textureNode;if(!0!==e.isTextureNode)return console.error("GaussianBlurNode requires a TextureNode."),Bg();const n=e.uvNode||gx(),i=Lg(this.directionNode||1),s=t=>e.uv(t),r=Mg((()=>{const t=3+2*this.sigma,e=this._getCoefficients(t),r=this._invSize,a=i.mul(this._passDirection),o=Ng(e[0]).toVar(),l=Bg(s(n).mul(o)).toVar();for(let i=1;igg(new xC(BN(t),e,n)),bC=new ti,TC=new ON;class SC extends Pf{static get type(){return"AfterImageNode"}constructor(t,e=.96){super(t),this.textureNode=t,this.textureNodeOld=bx(),this.damp=rv(e),this._compRT=new wi,this._compRT.texture.name="AfterImageNode.comp",this._oldRT=new wi,this._oldRT.texture.name="AfterImageNode.old",this._textureNode=gC(this,this._compRT.texture),this.updateBeforeType=Tf.RENDER}getTextureNode(){return this._textureNode}setSize(t,e){this._compRT.setSize(t,e),this._oldRT.setSize(t,e)}updateBefore(t){const{renderer:e}=t,n=this.textureNode,i=n.value.type;this._compRT.texture.type=i,this._oldRT.texture.type=i,e.getDrawingBufferSize(bC),this.setSize(bC.x,bC.y);const s=e.getRenderTarget(),r=n.value;this.textureNodeOld.value=this._oldRT.texture,e.setRenderTarget(this._compRT),TC.render(e);const a=this._oldRT;this._oldRT=this._compRT,this._compRT=a,e.setRenderTarget(s),n.value=r}setup(t){const e=this.textureNode,n=this.textureNodeOld,i=e.uvNode||gx();n.uvNode=i;const s=Mg((([t,e])=>{const n=Ng(e).toVar(),i=Bg(t).toVar();return Jy(zy(i.sub(n)),0)})),r=Mg((()=>{const t=Bg(n),r=Bg((t=>e.uv(t))(i));return t.mulAssign(this.damp.mul(s(t,.1))),Jy(r,t)})),a=this._materialComposed||(this._materialComposed=new sS);a.name="AfterImage",a.fragmentNode=r(),TC.material=a;return t.getNodeProperties(this).textureNode=e,this._textureNode}dispose(){this._compRT.dispose(),this._oldRT.dispose()}}const wC=(t,e)=>gg(new SC(BN(t),e)),EC=Mg((([t])=>IC(t.rgb))),AC=Mg((([t,e=Ng(1)])=>e.mix(IC(t.rgb),t.rgb))),NC=Mg((([t,e=Ng(1)])=>{const n=Hv(t.r,t.g,t.b).div(3),i=t.r.max(t.g.max(t.b)),s=i.sub(n).mul(e).mul(-3);return d_(t.rgb,i,s)})),CC=Mg((([t,e=Ng(1)])=>{const n=Og(.57735,.57735,.57735),i=e.cos();return Og(t.rgb.mul(i).add(n.cross(t.rgb).mul(e.sin()).add(n.mul(i_(n,t.rgb).mul(i.oneMinus())))))})),RC=new Li,IC=(t,e=Og(...mi.getLuminanceCoefficients(RC)))=>i_(t,e),LC=(t,e)=>d_(Og(0),t,IC(t).sub(e).max(0)),PC=new ON;class UC extends Pf{static get type(){return"AnamorphicNode"}constructor(t,e,n,i){super("vec4"),this.textureNode=t,this.tresholdNode=e,this.scaleNode=n,this.colorNode=Og(.1,0,1),this.samples=i,this.resolution=new ti(1,1),this._renderTarget=new wi,this._renderTarget.texture.name="anamorphic",this._invSize=rv(new ti),this._textureNode=gC(this,this._renderTarget.texture),this.updateBeforeType=Tf.RENDER}getTextureNode(){return this._textureNode}setSize(t,e){this._invSize.value.set(1/t,1/e),t=Math.max(Math.round(t*this.resolution.x),1),e=Math.max(Math.round(e*this.resolution.y),1),this._renderTarget.setSize(t,e)}updateBefore(t){const{renderer:e}=t,n=this.textureNode,i=n.value;this._renderTarget.texture.type=i.type;const s=e.getRenderTarget(),r=n.value;PC.material=this._material,this.setSize(i.image.width,i.image.height),e.setRenderTarget(this._renderTarget),PC.render(e),e.setRenderTarget(s),n.value=r}setup(t){const e=this.textureNode,n=e.uvNode||gx(),i=Mg((()=>{const t=this.samples,i=Math.floor(t/2),s=Og(0).toVar();return uT({start:-i,end:i},(({i:t})=>{const r=Ng(t).abs().div(i).oneMinus(),a=(t=>e.uv(t))(Lg(n.x.add(this._invSize.x.mul(t).mul(this.scaleNode)),n.y)),o=LC(a,this.tresholdNode).mul(r);s.addAssign(o)})),s.mul(this.colorNode)})),s=this._material||(this._material=new sS);s.name="Anamorphic",s.fragmentNode=i();return t.getNodeProperties(this).textureNode=e,this._textureNode}dispose(){this._renderTarget.dispose()}}const DC=(t,e=.9,n=3,i=32)=>gg(new UC(BN(t),gg(e),gg(n),i));class OC extends Pf{static get type(){return"SobelOperatorNode"}constructor(t){super(),this.textureNode=t,this.updateBeforeType=Tf.RENDER,this._invSize=rv(new ti)}updateBefore(){const t=this.textureNode.value;this._invSize.value.set(1/t.image.width,1/t.image.height)}setup(){const{textureNode:t}=this,e=t.uvNode||gx(),n=e=>t.uv(e);return Mg((()=>{const t=this._invSize,i=jg(-1,-2,-1,0,0,0,1,2,1),s=jg(-1,0,1,-2,0,2,-1,0,1),r=IC(n(e.add(t.mul(Lg(-1,-1)))).xyz),a=IC(n(e.add(t.mul(Lg(-1,0)))).xyz),o=IC(n(e.add(t.mul(Lg(-1,1)))).xyz),l=IC(n(e.add(t.mul(Lg(0,-1)))).xyz),c=IC(n(e.add(t.mul(Lg(0,0)))).xyz),u=IC(n(e.add(t.mul(Lg(0,1)))).xyz),h=IC(n(e.add(t.mul(Lg(1,-1)))).xyz),d=IC(n(e.add(t.mul(Lg(1,0)))).xyz),p=IC(n(e.add(t.mul(Lg(1,1)))).xyz),m=Hv(i[0][0].mul(r),i[1][0].mul(l),i[2][0].mul(h),i[0][1].mul(a),i[1][1].mul(c),i[2][1].mul(d),i[0][2].mul(o),i[1][2].mul(u),i[2][2].mul(p)),f=Hv(s[0][0].mul(r),s[1][0].mul(l),s[2][0].mul(h),s[0][1].mul(a),s[1][1].mul(c),s[2][1].mul(d),s[0][2].mul(o),s[1][2].mul(u),s[2][2].mul(p)),g=m.mul(m).add(f.mul(f)).sqrt();return Bg(Og(g),1)}))()}}const zC=t=>gg(new OC(BN(t)));class VC extends Pf{static get type(){return"DepthOfFieldNode"}constructor(t,e,n,i,s){super(),this.textureNode=t,this.viewZNode=e,this.focusNode=n,this.apertureNode=i,this.maxblurNode=s,this._aspect=rv(0),this.updateBeforeType=Tf.RENDER}updateBefore(){const t=this.textureNode.value;this._aspect.value=t.image.width/t.image.height}setup(){const t=this.textureNode,e=t.uvNode||gx(),n=e=>t.uv(e);return Mg((()=>{const t=Lg(1,this._aspect),i=this.focusNode.add(this.viewZNode),s=Lg(p_(i.mul(this.apertureNode),this.maxblurNode.negate(),this.maxblurNode)),r=s.mul(.9),a=s.mul(.7),o=s.mul(.4);let l=Bg(0);return l=l.add(n(e)),l=l.add(n(e.add(Lg(0,.4).mul(t).mul(s)))),l=l.add(n(e.add(Lg(.15,.37).mul(t).mul(s)))),l=l.add(n(e.add(Lg(.29,.29).mul(t).mul(s)))),l=l.add(n(e.add(Lg(-.37,.15).mul(t).mul(s)))),l=l.add(n(e.add(Lg(.4,0).mul(t).mul(s)))),l=l.add(n(e.add(Lg(.37,-.15).mul(t).mul(s)))),l=l.add(n(e.add(Lg(.29,-.29).mul(t).mul(s)))),l=l.add(n(e.add(Lg(-.15,-.37).mul(t).mul(s)))),l=l.add(n(e.add(Lg(0,-.4).mul(t).mul(s)))),l=l.add(n(e.add(Lg(-.15,.37).mul(t).mul(s)))),l=l.add(n(e.add(Lg(-.29,.29).mul(t).mul(s)))),l=l.add(n(e.add(Lg(.37,.15).mul(t).mul(s)))),l=l.add(n(e.add(Lg(-.4,0).mul(t).mul(s)))),l=l.add(n(e.add(Lg(-.37,-.15).mul(t).mul(s)))),l=l.add(n(e.add(Lg(-.29,-.29).mul(t).mul(s)))),l=l.add(n(e.add(Lg(.15,-.37).mul(t).mul(s)))),l=l.add(n(e.add(Lg(.15,.37).mul(t).mul(r)))),l=l.add(n(e.add(Lg(-.37,.15).mul(t).mul(r)))),l=l.add(n(e.add(Lg(.37,-.15).mul(t).mul(r)))),l=l.add(n(e.add(Lg(-.15,-.37).mul(t).mul(r)))),l=l.add(n(e.add(Lg(-.15,.37).mul(t).mul(r)))),l=l.add(n(e.add(Lg(.37,.15).mul(t).mul(r)))),l=l.add(n(e.add(Lg(-.37,-.15).mul(t).mul(r)))),l=l.add(n(e.add(Lg(.15,-.37).mul(t).mul(r)))),l=l.add(n(e.add(Lg(.29,.29).mul(t).mul(a)))),l=l.add(n(e.add(Lg(.4,0).mul(t).mul(a)))),l=l.add(n(e.add(Lg(.29,-.29).mul(t).mul(a)))),l=l.add(n(e.add(Lg(0,-.4).mul(t).mul(a)))),l=l.add(n(e.add(Lg(-.29,.29).mul(t).mul(a)))),l=l.add(n(e.add(Lg(-.4,0).mul(t).mul(a)))),l=l.add(n(e.add(Lg(-.29,-.29).mul(t).mul(a)))),l=l.add(n(e.add(Lg(0,.4).mul(t).mul(a)))),l=l.add(n(e.add(Lg(.29,.29).mul(t).mul(o)))),l=l.add(n(e.add(Lg(.4,0).mul(t).mul(o)))),l=l.add(n(e.add(Lg(.29,-.29).mul(t).mul(o)))),l=l.add(n(e.add(Lg(0,-.4).mul(t).mul(o)))),l=l.add(n(e.add(Lg(-.29,.29).mul(t).mul(o)))),l=l.add(n(e.add(Lg(-.4,0).mul(t).mul(o)))),l=l.add(n(e.add(Lg(-.29,-.29).mul(t).mul(o)))),l=l.add(n(e.add(Lg(0,.4).mul(t).mul(o)))),l=l.div(41),l.a=1,Bg(l)}))()}}const FC=(t,e,n=1,i=.025,s=1)=>gg(new VC(BN(t),gg(e),gg(n),gg(i),gg(s)));class BC extends Pf{static get type(){return"DotScreenNode"}constructor(t,e=new ti(.5,.5),n=1.57,i=1){super("vec4"),this.inputNode=t,this.center=rv(e),this.angle=rv(n),this.scale=rv(i)}setup(){const t=this.inputNode,e=Mg((()=>{const t=Ry(this.angle),e=Iy(this.angle),n=gx().mul(LT).sub(this.center),i=Lg(e.mul(n.x).sub(t.mul(n.y)),t.mul(n.x).add(e.mul(n.y))).mul(this.scale);return Ry(i.x).mul(Ry(i.y)).mul(4)})),n=Mg((()=>{const n=t,i=Hv(n.r,n.g,n.b).div(3);return Bg(Og(i.mul(10).sub(5).add(e())),n.a)}));return n()}}const kC=(t,e,n,i)=>gg(new BC(gg(t),e,n,i));class HC extends Pf{static get type(){return"RGBShiftNode"}constructor(t,e=.005,n=0){super("vec4"),this.textureNode=t,this.amount=rv(e),this.angle=rv(n)}setup(){const{textureNode:t}=this,e=t.uvNode||gx(),n=e=>t.uv(e);return Mg((()=>{const t=Lg(Iy(this.angle),Ry(this.angle)).mul(this.amount),i=n(e.add(t)),s=n(e),r=n(e.sub(t));return Bg(i.r,s.g,r.b,s.a)}))()}}const GC=(t,e,n)=>gg(new HC(BN(t),e,n));class WC extends Pf{static get type(){return"FilmNode"}constructor(t,e=null,n=null){super(),this.inputNode=t,this.intensityNode=e,this.uvNode=n}setup(){const t=this.uvNode||gx(),e=Mg((()=>{const e=this.inputNode.rgb,n=y_(Cy(t.add(eN())));let i=e.add(e.mul(p_(n.add(.1),0,1)));return null!==this.intensityNode&&(i=d_(e,i,this.intensityNode)),Bg(i,this.inputNode.a)}));return e()}}const jC=_g(WC);class XC extends Pf{static get type(){return"Lut3DNode"}constructor(t,e,n,i){super(),this.inputNode=t,this.lutNode=e,this.size=rv(n),this.intensityNode=i}setup(){const{inputNode:t,lutNode:e}=this,n=Mg((()=>{const n=t,i=Ng(1).div(this.size),s=Ng(.5).div(this.size),r=Og(s).add(n.rgb.mul(Ng(1).sub(i))),a=Bg((t=>e.uv(t))(r).rgb,n.a);return Bg(d_(n,a,this.intensityNode))}));return n()}}const qC=(t,e,n,i)=>gg(new XC(gg(t),gg(e),n,gg(i))),YC=new ON,ZC=new tr,$C=new ti;class JC extends Pf{static get type(){return"GTAONode"}constructor(t,e,n){super(),this.depthNode=t,this.normalNode=e,this.radius=rv(.25),this.resolution=rv(new ti),this.thickness=rv(1),this.distanceExponent=rv(1),this.distanceFallOff=rv(1),this.scale=rv(1),this.noiseNode=bx(function(t=5){const e=Math.floor(t)%2==0?Math.floor(t)+1:Math.floor(t),n=function(t){const e=Math.floor(t)%2==0?Math.floor(t)+1:Math.floor(t),n=e*e,i=Array(n).fill(0);let s=Math.floor(e/2),r=e-1;for(let t=1;t<=n;)-1===s&&r===e?(r=e-2,s=0):(r===e&&(r=0),s<0&&(s=e-1)),0===i[s*e+r]?(i[s*e+r]=t++,r++,s--):(r-=2,s++);return i}(e),i=n.length,s=new Uint8Array(4*i);for(let t=0;tthis.depthNode.uv(t).x,i=t=>this.noiseNode.uv(t),s=Mg((([t])=>{const e=this.cameraProjectionMatrix.mul(Bg(t,1));let i=e.xy.div(e.w).mul(.5).add(.5).toVar();i=Lg(i.x,i.y.oneMinus());const s=n(i);return Og(i,s)})),r=Mg((([t,e])=>{t=Lg(t.x,t.y.oneMinus()).mul(2).sub(1);const n=Bg(Og(t,e),1),i=Bg(this.cameraProjectionMatrixInverse.mul(n));return i.xyz.div(i.w)})),a=Mg((()=>{const t=n(e);t.greaterThanEqual(1).discard();const a=r(e,t),o=this.normalNode.rgb.normalize(),l=this.radius,c=yx(this.noiseNode,0);let u=Lg(e.x,e.y.oneMinus());u=u.mul(this.resolution.div(c));const h=i(u),d=h.xyz.mul(2).sub(1),p=Og(d.xy,0).normalize(),m=Og(p.y.mul(-1),p.x,0),f=jg(p,m,Og(0,0,1)),g=this.SAMPLES.lessThan(30).select(3,5),v=Hv(this.SAMPLES,g.sub(1)).div(g),y=Ng(0).toVar();return uT({start:Cg(0),end:g,type:"int",condition:"<"},(({i:t})=>{const e=Ng(t).div(Ng(g)).mul(py),n=Bg(Iy(e),Ry(e),0,Hv(.5,Wv(.5,h.w)));n.xyz=Ny(f.mul(n.xyz));const i=Ny(a.xyz.negate()),c=Ny(s_(n.xyz,i)),u=s_(c,i),d=Ny(o.sub(c.mul(i_(o,c)))),p=s_(d,c),m=Lg(i_(i,p),i_(i,p.negate())).toVar();uT({end:v,type:"int",name:"j",condition:"<"},(({j:t})=>{const e=n.xyz.mul(l).mul(n.w).mul(r_(jv(Ng(t).add(1),Ng(v)),this.distanceExponent)),o=s(a.add(e)),c=r(o.xy,o.z).sub(a);wg(Oy(c.z).lessThan(this.thickness),(()=>{const e=i_(i,Ny(c));m.x.addAssign(Jy(0,Wv(e.sub(m.x),d_(1,Ng(2).div(Ng(t).add(2)),this.distanceFallOff))))}));const u=s(a.sub(e)),h=r(u.xy,u.z).sub(a);wg(Oy(h.z).lessThan(this.thickness),(()=>{const e=i_(i,Ny(h));m.y.addAssign(Jy(0,Wv(e.sub(m.y),d_(1,Ng(2).div(Ng(t).add(2)),this.distanceFallOff))))}))}));const _=Sy(Gv(1,m.mul(m))),x=i_(d,u),M=i_(d,i),b=Wv(.5,Uy(m.y).sub(Uy(m.x)).add(_.x.mul(m.x).sub(_.y.mul(m.y)))),T=Wv(.5,Gv(2,m.x.mul(m.x)).sub(m.y.mul(m.y))),S=x.mul(b).add(M.mul(T));y.addAssign(S)})),y.assign(p_(y.div(g),0,1)),y.assign(r_(y,this.scale)),Bg(Og(y),1)})),o=this._material||(this._material=new sS);return o.fragmentNode=a().context(t.getSharedContext()),o.name="GTAO",o.needsUpdate=!0,this._textureNode}dispose(){this._aoRenderTarget.dispose()}}const KC=(t,e,n)=>gg(new JC(gg(t),gg(e),n));class QC extends Pf{static get type(){return"DenoiseNode"}constructor(t,e,n,i,s){super(),this.textureNode=t,this.depthNode=e,this.normalNode=n,this.noiseNode=i,this.cameraProjectionMatrixInverse=rv(s.projectionMatrixInverse),this.lumaPhi=rv(5),this.depthPhi=rv(5),this.normalPhi=rv(5),this.radius=rv(5),this.index=rv(0),this._resolution=rv(new ti),this._sampleVectors=NM(function(t,e,n){const i=function(t,e,n){const i=[];for(let s=0;sthis.textureNode.uv(t),n=t=>this.depthNode.uv(t).x,i=t=>this.normalNode.uv(t),s=t=>this.noiseNode.uv(t),r=Mg((([t,e])=>{t=Lg(t.x,t.y.oneMinus()).mul(2).sub(1);const n=Bg(Og(t,e),1),i=Bg(this.cameraProjectionMatrixInverse.mul(n));return i.xyz.div(i.w)})),a=Mg((([t,s,a,o])=>{const l=e(o),c=n(o),u=i(o).rgb.normalize(),h=l.rgb,d=r(o,c),p=i_(s,u).toVar(),m=r_(Jy(p,0),this.normalPhi).toVar(),f=Oy(IC(h).sub(IC(t))).toVar(),g=Jy(Ng(1).sub(f.div(this.lumaPhi)),0).toVar(),v=Oy(i_(a.sub(d),s)).toVar(),y=Jy(Ng(1).sub(v.div(this.depthPhi)),0),_=g.mul(y).mul(m);return Bg(h.mul(_),_)})),o=Mg((([t])=>{const o=n(t),l=i(t).rgb.normalize(),c=e(t);wg(o.greaterThanEqual(1).or(i_(l,l).equal(0)),(()=>c));const u=Og(c.rgb),h=r(t,o),d=yx(this.noiseNode,0);let p=Lg(t.x,t.y.oneMinus());p=p.mul(this._resolution.div(d));const m=s(p),f=Ry(m.element(this.index.mod(4).mul(2).mul(py))),g=Iy(m.element(this.index.mod(4).mul(2).mul(py))),v=Lg(f,g),y=Wg(v.x,v.y.negate(),v.x,v.y),_=Ng(1).toVar(),x=Og(c.rgb).toVar();return uT({start:Cg(0),end:Cg(16),type:"int",condition:"<"},(({i:e})=>{const n=this._sampleVectors.element(e).toVar(),i=y.mul(n.xy.mul(Ng(1).add(n.z.mul(this.radius.sub(1))))).div(this._resolution).toVar(),s=t.add(i).toVar(),r=a(u,l,h,s);x.addAssign(r.xyz),_.addAssign(r.w)})),wg(_.greaterThan(Ng(0)),(()=>{x.divAssign(_)})),Bg(x,c.a)})).setLayout({name:"denoise",type:"vec4",inputs:[{name:"uv",type:"vec2"}]});return Mg((()=>o(t)))()}}const tR=(t,e,n,i,s)=>gg(new QC(BN(t),gg(e),gg(n),gg(i),s));class eR extends Pf{static get type(){return"FXAANode"}constructor(t){super(),this.textureNode=t,this.updateBeforeType=Tf.RENDER,this._invSize=rv(new ti)}updateBefore(){const t=this.textureNode.value;this._invSize.value.set(1/t.image.width,1/t.image.height)}setup(){const t=this.textureNode.bias(-100),e=t.uvNode||gx(),n=e=>t.uv(e),i=(e,n,i)=>t.uv(e.add(n.mul(i))),s=Cg(5),r=Mg((([t,e])=>{const n=Bg(e).toVar(),i=Bg(t).toVar(),s=Bg(Oy(i.sub(n))).toVar();return Jy(Jy(Jy(s.r,s.g),s.b),s.a)})),a=Mg((([t,e,a,o])=>{const l=n(t).toVar(),c=i(t,Lg(0,-1),e.xy).toVar(),u=i(t,Lg(1,0),e.xy).toVar(),h=i(t,Lg(0,1),e.xy).toVar(),d=i(t,Lg(-1,0),e.xy).toVar(),p=r(l,h).toVar(),m=r(l,c).toVar(),f=r(l,u).toVar(),g=r(l,d).toVar(),v=Jy(p,Jy(m,Jy(f,g))).toVar();wg(v.lessThan(a),(()=>l));const y=Gv(p.add(m),f.add(g)).toVar();y.mulAssign(o),wg(Oy(y).lessThan(.3),(()=>{const n=f.greaterThan(g).select(1,-1).toVar(),s=m.greaterThan(p).select(1,-1).toVar(),a=Lg(n,s).toVar(),v=i(t,Lg(a.x,a.y),e.xy),_=r(l,v).toVar(),x=i(t,Lg(a.x.negate(),a.y.negate()),e.xy),M=r(l,x).toVar();y.assign(M.sub(_)),y.mulAssign(o),wg(Oy(y).lessThan(.3),(()=>{const t=h.add(c).add(u).add(d);return d_(l,t.mul(.25),.4)}))}));const _=Lg().toVar();wg(y.lessThanEqual(0),(()=>{h.assign(d),c.assign(u),_.x.assign(0),_.y.assign(e.y)})).Else((()=>{_.x.assign(e.x),_.y.assign(0)}));const x=r(l,h).toVar(),M=r(l,c).toVar();wg(x.lessThanEqual(M),(()=>{h.assign(c)}));const b=Cg(0).toVar(),T=Cg(0).toVar(),S=Ng(0).toVar(),w=Ng(0).toVar(),E=Lg(t).toVar(),A=Lg(t).toVar(),N=Cg(0).toVar(),C=Cg(0).toVar();uT(s,(({i:e})=>{const i=e.add(1).toVar();wg(b.equal(0),(()=>{S.addAssign(i),E.assign(t.add(_.mul(S)));const s=n(E.xy),a=r(s,l).toVar(),o=r(s,h).toVar();wg(a.greaterThan(o),(()=>{b.assign(1)})),N.assign(e)})),wg(T.equal(0),(()=>{w.addAssign(i),A.assign(t.sub(_.mul(w)));const s=n(A.xy),a=r(s,l).toVar(),o=r(s,h).toVar();wg(a.greaterThan(o),(()=>{T.assign(1)})),C.assign(e)})),wg(b.equal(1).or(T.equal(1)),(()=>{dT()}))})),wg(b.equal(0).and(T.equal(0)),(()=>l));const R=Ng(1).toVar(),I=Ng(1).toVar();wg(b.equal(1),(()=>{R.assign(Ng(N).div(Ng(s.sub(1))))})),wg(T.equal(1),(()=>{I.assign(Ng(C).div(Ng(s.sub(1))))}));const L=$y(R,I);return L.assign(r_(L,.5)),L.assign(Ng(1).sub(L)),d_(l,h,L.mul(.5))})).setLayout({name:"FxaaPixelShader",type:"vec4",inputs:[{name:"uv",type:"vec2"},{name:"fxaaQualityRcpFrame",type:"vec2"},{name:"fxaaQualityEdgeThreshold",type:"float"},{name:"fxaaQualityinvEdgeThreshold",type:"float"}]});return Mg((()=>{const t=Ng(.2),n=Ng(1).div(t);return a(e,this._invSize,t,n)}))()}}const nR=t=>gg(new eR(BN(t))),iR=new ON,sR=new tr(0,0,0),rR=new tr,aR=new ti,oR=new ti(1,0),lR=new ti(0,1);class cR extends Pf{static get type(){return"BloomNode"}constructor(t,e=1,n=0,i=0){super(),this.inputNode=t,this.strength=rv(e),this.radius=rv(n),this.threshold=rv(i),this.smoothWidth=rv(.01),this._renderTargetsHorizontal=[],this._renderTargetsVertical=[],this._nMips=5,this._renderTargetBright=new wi(1,1,{type:Pt}),this._renderTargetBright.texture.name="UnrealBloomPass.bright",this._renderTargetBright.texture.generateMipmaps=!1;for(let t=0;t{const t=this.inputNode,e=IC(t.rgb),n=g_(this.threshold,this.threshold.add(this.smoothWidth),e);return d_(Bg(0),t,n)}));this._highPassFilterMaterial=this._highPassFilterMaterial||new sS,this._highPassFilterMaterial.fragmentNode=e().context(t.getSharedContext()),this._highPassFilterMaterial.name="Bloom_highPass",this._highPassFilterMaterial.needsUpdate=!0;const n=[3,5,7,9,11];for(let e=0;e{const n=Ng(1.2).sub(t);return d_(t,n,e)})).setLayout({name:"lerpBloomFactor",type:"float",inputs:[{name:"factor",type:"float"},{name:"radius",type:"float"}]}),a=Mg((()=>{const t=r(i.element(0),this.radius).mul(Bg(s.element(0),1)).mul(this._textureNodeBlur0),e=r(i.element(1),this.radius).mul(Bg(s.element(1),1)).mul(this._textureNodeBlur1),n=r(i.element(2),this.radius).mul(Bg(s.element(2),1)).mul(this._textureNodeBlur2),a=r(i.element(3),this.radius).mul(Bg(s.element(3),1)).mul(this._textureNodeBlur3),o=r(i.element(4),this.radius).mul(Bg(s.element(4),1)).mul(this._textureNodeBlur4);return t.add(e).add(n).add(a).add(o).mul(this.strength)}));return this._compositeMaterial=this._compositeMaterial||new sS,this._compositeMaterial.fragmentNode=a().context(t.getSharedContext()),this._compositeMaterial.name="Bloom_comp",this._compositeMaterial.needsUpdate=!0,this._textureOutput}dispose(){for(let t=0;ti.uv(t),c=Mg((()=>{const t=s.element(0).toVar(),n=l(o).rgb.mul(t).toVar();return uT({start:Cg(1),end:Cg(e),type:"int",condition:"<"},(({i:e})=>{const i=Ng(e),c=s.element(e),u=a.mul(r).mul(i),h=l(o.add(u)).rgb,d=l(o.sub(u)).rgb;n.addAssign(Hv(h,d).mul(c)),t.addAssign(Ng(2).mul(c))})),Bg(n.div(t),1)})),u=new sS;return u.fragmentNode=c().context(t.getSharedContext()),u.name="Bloom_seperable",u.needsUpdate=!0,u.colorTexture=i,u.direction=a,u.invSize=r,u}}const uR=(t,e,n,i)=>gg(new cR(gg(t),e,n,i));class hR extends Pf{static get type(){return"TransitionNode"}constructor(t,e,n,i,s,r){super(),this.textureNodeA=t,this.textureNodeB=e,this.mixTextureNode=n,this.mixRatioNode=i,this.thresholdNode=s,this.useTextureNode=r}setup(){const{textureNodeA:t,textureNodeB:e,mixTextureNode:n,mixRatioNode:i,thresholdNode:s,useTextureNode:r}=this,a=t=>{const e=t.uvNode||gx();return t.uv(e)},o=Mg((()=>{const o=a(t),l=a(e),c=Bg().toVar();return wg(r.equal(Cg(1)),(()=>{const t=a(n),e=i.mul(s.mul(2).add(1)).sub(s),r=p_(Gv(t.r,e).mul(Ng(1).div(s)),0,1);c.assign(d_(o,l,r))})).Else((()=>{c.assign(d_(l,o,i))})),c}));return o()}}const dR=(t,e,n,i=0,s=.1,r=0)=>gg(new hR(BN(t),BN(e),BN(n),gg(i),gg(s),gg(r)));class pR extends Pf{static get type(){return"PixelationNode"}constructor(t,e,n,i,s,r){super(),this.textureNode=t,this.depthNode=e,this.normalNode=n,this.pixelSize=i,this.normalEdgeStrength=s,this.depthEdgeStrength=r,this._resolution=rv(new Si),this.updateBeforeType=Tf.RENDER}updateBefore(){const t=this.textureNode.value,e=t.image.width,n=t.image.height;this._resolution.value.set(e,n,1/e,1/n)}setup(){const{textureNode:t,depthNode:e,normalNode:n}=this,i=t.uvNode||gx(),s=e.uvNode||gx(),r=n.uvNode||gx(),a=(t,n)=>e.uv(s.add(Lg(t,n).mul(this._resolution.zw))).r,o=(t,e)=>n.uv(r.add(Lg(t,e).mul(this._resolution.zw))).rgb.normalize(),l=(t,e,n,i)=>{const s=a(t,e).sub(n),r=o(t,e),l=Og(1,1,1),c=i_(i.sub(r),l),u=p_(g_(-.01,.01,c),0,1),h=p_(zy(s.mul(.25).add(.0025)),0,1);return Ng(1).sub(i_(i,r)).mul(h).mul(u)},c=Mg((()=>{const e=t.uv(i),n=ov("float","depth"),s=ov("vec3","normal");wg(this.depthEdgeStrength.greaterThan(0).or(this.normalEdgeStrength.greaterThan(0)),(()=>{n.assign(a(0,0)),s.assign(o(0,0))}));const r=ov("float","dei");wg(this.depthEdgeStrength.greaterThan(0),(()=>{r.assign((t=>{const e=ov("float","diff");return e.addAssign(p_(a(1,0).sub(t))),e.addAssign(p_(a(-1,0).sub(t))),e.addAssign(p_(a(0,1).sub(t))),e.addAssign(p_(a(0,-1).sub(t))),Ey(g_(.01,.02,e).mul(2)).div(2)})(n))}));const c=ov("float","nei");wg(this.normalEdgeStrength.greaterThan(0),(()=>{c.assign(((t,e)=>{const n=ov("float","indicator");return n.addAssign(l(0,-1,t,e)),n.addAssign(l(0,1,t,e)),n.addAssign(l(-1,0,t,e)),n.addAssign(l(1,0,t,e)),Qy(.1,n)})(n,s))}));const u=r.greaterThan(0).select(Ng(1).sub(r.mul(this.depthEdgeStrength)),c.mul(this.normalEdgeStrength).add(1));return e.mul(u)}));return c()}}class mR extends mC{static get type(){return"PixelationPassNode"}constructor(t,e,n=6,i=.3,s=.4){super("color",t,e,{minFilter:gt,magFilter:gt}),this.pixelSize=n,this.normalEdgeStrength=i,this.depthEdgeStrength=s,this.isPixelationPassNode=!0,this._mrt=$A({output:Av,normal:uM})}setSize(t,e){const n=this.pixelSize.value?this.pixelSize.value:this.pixelSize,i=Math.floor(t/n),s=Math.floor(e/n);super.setSize(i,s)}setup(){return((t,e,n,i=6,s=.3,r=.4)=>gg(new pR(BN(t),BN(e),BN(n),gg(i),gg(s),gg(r))))(super.getTextureNode("output"),super.getTextureNode("depth"),super.getTextureNode("normal"),this.pixelSize,this.normalEdgeStrength,this.depthEdgeStrength)}}const fR=(t,e,n,i,s)=>gg(new mR(t,e,n,i,s)),gR=new ti;class vR extends mC{static get type(){return"SSAAPassNode"}constructor(t,e){super(mC.COLOR,t,e),this.isSSAAPassNode=!0,this.sampleLevel=4,this.unbiased=!0,this.clearColor=new tr(0),this.clearAlpha=0,this._currentClearColor=new tr,this.sampleWeight=rv(1),this.sampleRenderTarget=null,this._quadMesh=new ON}updateBefore(t){const{renderer:e}=t,{scene:n,camera:i}=this;this._pixelRatio=e.getPixelRatio();const s=e.getSize(gR);this.setSize(s.width,s.height),this.sampleRenderTarget.setSize(this.renderTarget.width,this.renderTarget.height),e.getClearColor(this._currentClearColor);const r=e.getClearAlpha(),a=e.getRenderTarget(),o=e.getMRT(),l=e.autoClear;this._cameraNear.value=i.near,this._cameraFar.value=i.far,e.setMRT(this.getMRT()),e.autoClear=!1;const c=yR[Math.max(0,Math.min(this.sampleLevel,5))],u=1/c.length,h={fullWidth:this.renderTarget.width,fullHeight:this.renderTarget.height,offsetX:0,offsetY:0,width:this.renderTarget.width,height:this.renderTarget.height},d=Object.assign({},i.view);d.enabled&&Object.assign(h,d);for(let t=0;t=0&&(t[e]=bx(this.sampleRenderTarget.textures[n]).mul(this.sampleWeight))}e=$A(t)}else e=bx(this.sampleRenderTarget.texture).mul(this.sampleWeight);return this._quadMesh.material=new sS,this._quadMesh.material.fragmentNode=e,this._quadMesh.material.transparent=!0,this._quadMesh.material.depthTest=!1,this._quadMesh.material.depthWrite=!1,this._quadMesh.material.premultipliedAlpha=!0,this._quadMesh.material.blending=2,this._quadMesh.material.normals=!1,this._quadMesh.material.name="SSAA",super.setup(t)}dispose(){super.dispose(),null!==this.sampleRenderTarget&&this.sampleRenderTarget.dispose()}}const yR=[[[0,0]],[[4,4],[-4,-4]],[[-2,-6],[6,-2],[-6,2],[2,6]],[[1,-3],[-1,3],[5,1],[-3,-5],[-5,5],[-7,-1],[3,7],[7,-7]],[[1,1],[-1,-3],[-3,2],[4,-1],[-5,-2],[2,5],[5,3],[3,-5],[-2,6],[0,-7],[-4,-6],[-6,4],[-8,0],[7,-4],[6,7],[-7,-8]],[[-4,-7],[-7,-5],[-3,-5],[-5,-4],[-1,-4],[-2,-2],[-6,-1],[-4,0],[-7,1],[-1,2],[-6,3],[-3,3],[-7,6],[-3,6],[-5,7],[-1,7],[5,-7],[1,-6],[6,-5],[4,-4],[2,-3],[7,-2],[1,-1],[4,-1],[2,1],[6,2],[0,4],[4,4],[2,5],[7,5],[5,6],[3,7]]],_R=(t,e)=>gg(new vR(t,e)),xR=new ti;class MR extends mC{static get type(){return"StereoPassNode"}constructor(t,e){super(mC.COLOR,t,e),this.isStereoPassNode=!0,this.stereo=new Vp,this.stereo.aspect=.5}updateBefore(t){const{renderer:e}=t,{scene:n,camera:i,stereo:s,renderTarget:r}=this;this._pixelRatio=e.getPixelRatio(),s.cameraL.coordinateSystem=e.coordinateSystem,s.cameraR.coordinateSystem=e.coordinateSystem,s.update(i);const a=e.getSize(xR);this.setSize(a.width,a.height);const o=e.autoClear;e.autoClear=!1;const l=e.getRenderTarget(),c=e.getMRT();this._cameraNear.value=i.near,this._cameraFar.value=i.far;for(const t in this._previousTextures)this.toggleTexture(t);e.setRenderTarget(r),e.setMRT(this._mrt),e.clear(),r.scissorTest=!0,r.scissor.set(0,0,r.width/2,r.height),r.viewport.set(0,0,r.width/2,r.height),e.render(n,s.cameraL),r.scissor.set(r.width/2,0,r.width/2,r.height),r.viewport.set(r.width/2,0,r.width/2,r.height),e.render(n,s.cameraR),r.scissorTest=!1,e.setRenderTarget(l),e.setMRT(c),e.autoClear=o}}const bR=(t,e)=>gg(new MR(t,e)),TR=new ti,SR=new ON;class wR extends mC{static get type(){return"StereoCompositePassNode"}constructor(t,e){super(mC.COLOR,t,e),this.isStereoCompositePassNode=!0,this.stereo=new Vp;const n={minFilter:Mt,magFilter:gt,type:Pt};this._renderTargetL=new wi(1,1,n),this._renderTargetR=new wi(1,1,n),this._mapLeft=bx(this._renderTargetL.texture),this._mapRight=bx(this._renderTargetR.texture),this._material=null}updateStereoCamera(t){this.stereo.cameraL.coordinateSystem=t,this.stereo.cameraR.coordinateSystem=t,this.stereo.update(this.camera)}setSize(t,e){super.setSize(t,e),this._renderTargetL.setSize(this.renderTarget.width,this.renderTarget.height),this._renderTargetR.setSize(this.renderTarget.width,this.renderTarget.height)}updateBefore(t){const{renderer:e}=t,{scene:n,stereo:i,renderTarget:s}=this;this._pixelRatio=e.getPixelRatio(),this.updateStereoCamera(e.coordinateSystem);const r=e.getSize(TR);this.setSize(r.width,r.height);const a=e.getRenderTarget();e.setRenderTarget(this._renderTargetL),e.render(n,i.cameraL),e.setRenderTarget(this._renderTargetR),e.render(n,i.cameraR),e.setRenderTarget(s),SR.material=this._material,SR.render(e),e.setRenderTarget(a)}dispose(){super.dispose(),this._renderTargetL.dispose(),this._renderTargetR.dispose(),null!==this._material&&this._material.dispose()}}class ER extends wR{static get type(){return"AnaglyphPassNode"}constructor(t,e){super(t,e),this.isAnaglyphPassNode=!0,this._colorMatrixLeft=rv((new ei).fromArray([.4561,-.0400822,-.0152161,.500484,-.0378246,-.0205971,.176381,-.0157589,-.00546856])),this._colorMatrixRight=rv((new ei).fromArray([-.0434706,.378476,-.0721527,-.0879388,.73364,-.112961,-.00155529,-.0184503,1.2264]))}setup(t){const e=gx(),n=Mg((()=>{const t=this._mapLeft.uv(e),n=this._mapRight.uv(e),i=p_(this._colorMatrixLeft.mul(t.rgb).add(this._colorMatrixRight.mul(n.rgb)));return Bg(i.rgb,Jy(t.a,n.a))})),i=this._material||(this._material=new sS);return i.fragmentNode=n().context(t.getSharedContext()),i.name="Anaglyph",i.needsUpdate=!0,super.setup(t)}}const AR=(t,e)=>gg(new ER(t,e));class NR extends wR{static get type(){return"ParallaxBarrierPassNode"}constructor(t,e){super(t,e),this.isParallaxBarrierPassNode=!0}setup(t){const e=gx(),n=Mg((()=>{const t=Bg().toVar();return wg(Ky(PT.y,2).greaterThan(1),(()=>{t.assign(this._mapLeft.uv(e))})).Else((()=>{t.assign(this._mapRight.uv(e))})),t})),i=this._material||(this._material=new sS);return i.fragmentNode=n().context(t.getSharedContext()),i.needsUpdate=!0,super.setup(t)}}const CR=(t,e)=>gg(new NR(t,e));class RR extends mC{static get type(){return"ToonOutlinePassNode"}constructor(t,e,n,i,s){super(mC.COLOR,t,e),this.colorNode=n,this.thicknessNode=i,this.alphaNode=s,this._materialCache=new WeakMap}updateBefore(t){const{renderer:e}=t,n=e.getRenderObjectFunction();e.setRenderObjectFunction(((t,n,i,s,r,a,o)=>{if((r.isMeshToonMaterial||r.isMeshToonNodeMaterial)&&!1===r.wireframe){const l=this._getOutlineMaterial(r);e.renderObject(t,n,i,s,l,a,o)}e.renderObject(t,n,i,s,r,a,o)})),super.updateBefore(t),e.setRenderObjectFunction(n)}_createMaterial(){const t=new sS;t.isMeshToonOutlineMaterial=!0,t.name="Toon_Outline",t.side=1;const e=lM.negate(),n=Nx.mul(Yx),i=Ng(1),s=n.mul(Bg(Kx,1)),r=n.mul(Bg(Kx.add(e),1)),a=Ny(s.sub(r));return t.vertexNode=s.add(a.mul(this.thicknessNode).mul(s.w).mul(i)),t.colorNode=Bg(this.colorNode,this.alphaNode),t}_getOutlineMaterial(t){let e=this._materialCache.get(t);return void 0===e&&(e=this._createMaterial(),this._materialCache.set(t,e)),e}}const IR=(t,e,n=new tr(0,0,0),i=.003,s=1)=>gg(new RR(t,e,gg(n),gg(i),gg(s)));class LR extends Rf{static get type(){return"ScriptableValueNode"}constructor(t=null){super(),this._value=t,this._cache=null,this.inputType=null,this.outpuType=null,this.events=new Hn,this.isScriptableValueNode=!0}get isScriptableOutputNode(){return null!==this.outputType}set value(t){this._value!==t&&(this._cache&&"URL"===this.inputType&&this.value.value instanceof ArrayBuffer&&(URL.revokeObjectURL(this._cache),this._cache=null),this._value=t,this.events.dispatchEvent({type:"change"}),this.refresh())}get value(){return this._value}refresh(){this.events.dispatchEvent({type:"refresh"})}getValue(){const t=this.value;if(t&&null===this._cache&&"URL"===this.inputType&&t.value instanceof ArrayBuffer)this._cache=URL.createObjectURL(new Blob([t.value]));else if(t&&null!==t.value&&void 0!==t.value&&(("URL"===this.inputType||"String"===this.inputType)&&"string"==typeof t.value||"Number"===this.inputType&&"number"==typeof t.value||"Vector2"===this.inputType&&t.value.isVector2||"Vector3"===this.inputType&&t.value.isVector3||"Vector4"===this.inputType&&t.value.isVector4||"Color"===this.inputType&&t.value.isColor||"Matrix3"===this.inputType&&t.value.isMatrix3||"Matrix4"===this.inputType&&t.value.isMatrix4))return t.value;return this._cache||t}getNodeType(t){return this.value&&this.value.isNode?this.value.getNodeType(t):"float"}setup(){return this.value&&this.value.isNode?this.value:Ng()}serialize(t){super.serialize(t),null!==this.value?"ArrayBuffer"===this.inputType?t.value=_f(this.value):t.value=this.value?this.value.toJSON(t.meta).uuid:null:t.value=null,t.inputType=this.inputType,t.outputType=this.outputType}deserialize(t){super.deserialize(t);let e=null;null!==t.value&&(e="ArrayBuffer"===t.inputType?xf(t.value):"Texture"===t.inputType?t.meta.textures[t.value]:t.meta.nodes[t.value]||null),this.value=e,this.inputType=t.inputType,this.outputType=t.outputType}}const PR=_g(LR);class UR extends Map{get(t,e=null,...n){if(this.has(t))return super.get(t);if(null!==e){const i=e(...n);return this.set(t,i),i}}}class DR{constructor(t){this.scriptableNode=t}get parameters(){return this.scriptableNode.parameters}get layout(){return this.scriptableNode.getLayout()}getInputLayout(t){return this.scriptableNode.getInputLayout(t)}get(t){const e=this.parameters[t];return e?e.getValue():null}}const OR=new UR;class zR extends Rf{static get type(){return"ScriptableNode"}constructor(t=null,e={}){super(),this.codeNode=t,this.parameters=e,this._local=new UR,this._output=PR(),this._outputs={},this._source=this.source,this._method=null,this._object=null,this._value=null,this._needsOutputUpdate=!0,this.onRefresh=this.onRefresh.bind(this),this.isScriptableNode=!0}get source(){return this.codeNode?this.codeNode.code:""}setLocal(t,e){return this._local.set(t,e)}getLocal(t){return this._local.get(t)}onRefresh(){this._refresh()}getInputLayout(t){for(const e of this.getLayout())if(e.inputType&&(e.id===t||e.name===t))return e}getOutputLayout(t){for(const e of this.getLayout())if(e.outputType&&(e.id===t||e.name===t))return e}setOutput(t,e){const n=this._outputs;return void 0===n[t]?n[t]=PR(e):n[t].value=e,this}getOutput(t){return this._outputs[t]}getParameter(t){return this.parameters[t]}setParameter(t,e){const n=this.parameters;return e&&e.isScriptableNode?(this.deleteParameter(t),n[t]=e,n[t].getDefaultOutput().events.addEventListener("refresh",this.onRefresh)):e&&e.isScriptableValueNode?(this.deleteParameter(t),n[t]=e,n[t].events.addEventListener("refresh",this.onRefresh)):void 0===n[t]?(n[t]=PR(e),n[t].events.addEventListener("refresh",this.onRefresh)):n[t].value=e,this}getValue(){return this.getDefaultOutput().getValue()}deleteParameter(t){let e=this.parameters[t];return e&&(e.isScriptableNode&&(e=e.getDefaultOutput()),e.events.removeEventListener("refresh",this.onRefresh)),this}clearParameters(){for(const t of Object.keys(this.parameters))this.deleteParameter(t);return this.needsUpdate=!0,this}call(t,...e){const n=this.getObject()[t];if("function"==typeof n)return n(...e)}async callAsync(t,...e){const n=this.getObject()[t];if("function"==typeof n)return"AsyncFunction"===n.constructor.name?await n(...e):n(...e)}getNodeType(t){return this.getDefaultOutputNode().getNodeType(t)}refresh(t=null){null!==t?this.getOutput(t).refresh():this._refresh()}getObject(){if(this.needsUpdate&&this.dispose(),null!==this._object)return this._object;const t=new DR(this),e=OR.get("THREE"),n=OR.get("TSL"),i=this.getMethod(this.codeNode),s=[t,this._local,OR,()=>this.refresh(),(t,e)=>this.setOutput(t,e),e,n];this._object=i(...s);const r=this._object.layout;if(r&&(!1===r.cache&&this._local.clear(),this._output.outputType=r.outputType||null,Array.isArray(r.elements)))for(const t of r.elements){const e=t.id||t.name;t.inputType&&(void 0===this.getParameter(e)&&this.setParameter(e,null),this.getParameter(e).inputType=t.inputType),t.outputType&&(void 0===this.getOutput(e)&&this.setOutput(e,null),this.getOutput(e).outputType=t.outputType)}return this._object}deserialize(t){super.deserialize(t);for(const t in this.parameters){let e=this.parameters[t];e.isScriptableNode&&(e=e.getDefaultOutput()),e.events.addEventListener("refresh",this.onRefresh)}}getLayout(){return this.getObject().layout}getDefaultOutputNode(){const t=this.getDefaultOutput().value;return t&&t.isNode?t:Ng()}getDefaultOutput(){return this._exec()._output}getMethod(){if(this.needsUpdate&&this.dispose(),null!==this._method)return this._method;const t=["layout","init","main","dispose"].join(", "),e="\nreturn { ...output, "+t+" };",n="var "+t+"; var output = {};\n"+this.codeNode.code+e;return this._method=new Function(...["parameters","local","global","refresh","setOutput","THREE","TSL"],n),this._method}dispose(){null!==this._method&&(this._object&&"function"==typeof this._object.dispose&&this._object.dispose(),this._method=null,this._object=null,this._source=null,this._value=null,this._needsOutputUpdate=!0,this._output.value=null,this._outputs={})}setup(){return this.getDefaultOutputNode()}getCacheKey(t){const e=[df(this.source),this.getDefaultOutputNode().getCacheKey(t)];for(const n in this.parameters)e.push(this.parameters[n].getCacheKey(t));return pf(e)}set needsUpdate(t){!0===t&&this.dispose()}get needsUpdate(){return this.source!==this._source}_exec(){return null===this.codeNode||(!0===this._needsOutputUpdate&&(this._value=this.call("main"),this._needsOutputUpdate=!1),this._output.value=this._value),this}_refresh(){this.needsUpdate=!0,this._exec(),this._output.refresh()}}const VR=_g(zR);class FR extends Rf{static get type(){return"FogNode"}constructor(t,e){super("float"),this.isFogNode=!0,this.colorNode=t,this.factorNode=e}getViewZNode(t){let e;const n=t.context.getViewZ;return void 0!==n&&(e=n(this)),(e||nM.z).negate()}setup(){return this.factorNode}}const BR=_g(FR);class kR extends FR{static get type(){return"FogRangeNode"}constructor(t,e,n){super(t),this.isFogRangeNode=!0,this.nearNode=e,this.farNode=n}setup(t){const e=this.getViewZNode(t);return g_(this.nearNode,this.farNode,e)}}const HR=_g(kR);class GR extends FR{static get type(){return"FogExp2Node"}constructor(t,e){super(t),this.isFogExp2Node=!0,this.densityNode=e}setup(t){const e=this.getViewZNode(t),n=this.densityNode;return n.mul(n,e,e).negate().exp().oneMinus()}}const WR=_g(GR);let jR=null,XR=null;class qR extends Rf{static get type(){return"RangeNode"}constructor(t=Ng(),e=Ng()){super(),this.minNode=t,this.maxNode=e}getVectorLength(t){const e=t.getTypeLength(vf(this.minNode.value)),n=t.getTypeLength(vf(this.maxNode.value));return e>n?e:n}getNodeType(t){return t.object.count>1?t.getTypeFromLength(this.getVectorLength(t)):"float"}setup(t){const e=t.object;let n=null;if(e.count>1){const i=this.minNode.value,s=this.maxNode.value,r=t.getTypeLength(vf(i)),a=t.getTypeLength(vf(s));jR=jR||new Si,XR=XR||new Si,jR.setScalar(0),XR.setScalar(0),1===r?jR.setScalar(i):i.isColor?jR.set(i.r,i.g,i.b):jR.set(i.x,i.y,i.z||0,i.w||0),1===a?XR.setScalar(s):s.isColor?XR.set(s.r,s.g,s.b):XR.set(s.x,s.y,s.z||0,s.w||0);const o=4,l=o*e.count,c=new Float32Array(l);for(let t=0;tbx(t,e.xy).compare(e.z))),$R=Mg((({depthTexture:t,shadowCoord:e,shadow:n})=>{const i=(e,n)=>bx(t,e).compare(n),s=LM("mapSize","vec2",n).setGroup(nv),r=LM("radius","float",n).setGroup(nv),a=Lg(1).div(s),o=a.x.negate().mul(r),l=a.y.negate().mul(r),c=a.x.mul(r),u=a.y.mul(r),h=o.div(2),d=l.div(2),p=c.div(2),m=u.div(2);return Hv(i(e.xy.add(Lg(o,l)),e.z),i(e.xy.add(Lg(0,l)),e.z),i(e.xy.add(Lg(c,l)),e.z),i(e.xy.add(Lg(h,d)),e.z),i(e.xy.add(Lg(0,d)),e.z),i(e.xy.add(Lg(p,d)),e.z),i(e.xy.add(Lg(o,0)),e.z),i(e.xy.add(Lg(h,0)),e.z),i(e.xy,e.z),i(e.xy.add(Lg(p,0)),e.z),i(e.xy.add(Lg(c,0)),e.z),i(e.xy.add(Lg(h,m)),e.z),i(e.xy.add(Lg(0,m)),e.z),i(e.xy.add(Lg(p,m)),e.z),i(e.xy.add(Lg(o,u)),e.z),i(e.xy.add(Lg(0,u)),e.z),i(e.xy.add(Lg(c,u)),e.z)).mul(1/17)})),JR=Mg((({depthTexture:t,shadowCoord:e,shadow:n})=>{const i=(e,n)=>bx(t,e).compare(n),s=LM("mapSize","vec2",n).setGroup(nv),r=Lg(1).div(s),a=r.x,o=r.y,l=e.xy,c=Cy(l.mul(s).add(.5));return l.subAssign(c.mul(r)),Hv(i(l,e.z),i(l.add(Lg(a,0)),e.z),i(l.add(Lg(0,o)),e.z),i(l.add(r),e.z),d_(i(l.add(Lg(a.negate(),0)),e.z),i(l.add(Lg(a.mul(2),0)),e.z),c.x),d_(i(l.add(Lg(a.negate(),o)),e.z),i(l.add(Lg(a.mul(2),o)),e.z),c.x),d_(i(l.add(Lg(0,o.negate())),e.z),i(l.add(Lg(0,o.mul(2))),e.z),c.y),d_(i(l.add(Lg(a,o.negate())),e.z),i(l.add(Lg(a,o.mul(2))),e.z),c.y),d_(d_(i(l.add(Lg(a.negate(),o.negate())),e.z),i(l.add(Lg(a.mul(2),o.negate())),e.z),c.x),d_(i(l.add(Lg(a.negate(),o.mul(2))),e.z),i(l.add(Lg(a.mul(2),o.mul(2))),e.z),c.x),c.y)).mul(1/9)})),KR=Mg((({depthTexture:t,shadowCoord:e})=>{const n=Ng(1).toVar(),i=bx(t).uv(e.xy).rg,s=Qy(e.z,i.x);return wg(s.notEqual(Ng(1)),(()=>{const t=e.z.sub(i.x),r=Jy(0,i.y.mul(i.y));let a=r.div(r.add(t.mul(t)));a=p_(Gv(a,.3).div(.95-.3)),n.assign(p_(Jy(s,a)))})),n})),QR=Mg((({samples:t,radius:e,size:n,shadowPass:i})=>{const s=Ng(0).toVar(),r=Ng(0).toVar(),a=t.lessThanEqual(Ng(1)).select(Ng(0),Ng(2).div(t.sub(1))),o=t.lessThanEqual(Ng(1)).select(Ng(0),Ng(-1));uT({start:Cg(0),end:Cg(t),type:"int",condition:"<"},(({i:t})=>{const l=o.add(Ng(t).mul(a)),c=i.uv(Hv(PT.xy,Lg(0,l).mul(e)).div(n)).x;s.addAssign(c),r.addAssign(c.mul(c))})),s.divAssign(t),r.divAssign(t);const l=Sy(r.sub(s.mul(s)));return Lg(s,l)})),tI=Mg((({samples:t,radius:e,size:n,shadowPass:i})=>{const s=Ng(0).toVar(),r=Ng(0).toVar(),a=t.lessThanEqual(Ng(1)).select(Ng(0),Ng(2).div(t.sub(1))),o=t.lessThanEqual(Ng(1)).select(Ng(0),Ng(-1));uT({start:Cg(0),end:Cg(t),type:"int",condition:"<"},(({i:t})=>{const l=o.add(Ng(t).mul(a)),c=i.uv(Hv(PT.xy,Lg(l,0).mul(e)).div(n));s.addAssign(c.x),r.addAssign(Hv(c.y.mul(c.y),c.x.mul(c.x)))})),s.divAssign(t),r.divAssign(t);const l=Sy(r.sub(s.mul(s)));return Lg(s,l)})),eI=[ZR,$R,JR,KR];let nI=null;const iI=new ON;class sI extends TT{static get type(){return"AnalyticLightNode"}constructor(t=null){super(),this.updateType=Tf.FRAME,this.light=t,this.color=new tr,this.colorNode=rv(this.color).setGroup(nv),this.baseColorNode=null,this.shadowMap=null,this.shadowNode=null,this.shadowColorNode=null,this.vsmShadowMapVertical=null,this.vsmShadowMapHorizontal=null,this.vsmMaterialVertical=null,this.vsmMaterialHorizontal=null,this.isAnalyticLightNode=!0}getCacheKey(){return mf(super.getCacheKey(),this.light.id,this.light.castShadow?1:0)}getHash(){return this.light.uuid}setupShadow(t){const{object:e,renderer:n}=t;if(!1===n.shadowMap.enabled)return;let i=this.shadowColorNode;if(null===i){null===nI&&(nI=new sS,nI.fragmentNode=Bg(0,0,0,1),nI.isShadowNodeMaterial=!0,nI.name="ShadowMaterial");const s=n.shadowMap.type,r=this.light.shadow,a=new Ka;a.compareFunction=513;const o=t.createRenderTarget(r.mapSize.width,r.mapSize.height);if(o.depthTexture=a,r.camera.updateProjectionMatrix(),3===s){a.compareFunction=null,this.vsmShadowMapVertical=t.createRenderTarget(r.mapSize.width,r.mapSize.height,{format:qt,type:Pt}),this.vsmShadowMapHorizontal=t.createRenderTarget(r.mapSize.width,r.mapSize.height,{format:qt,type:Pt});const e=bx(a),n=bx(this.vsmShadowMapVertical.texture),i=LM("blurSamples","float",r).setGroup(nv),s=LM("radius","float",r).setGroup(nv),o=LM("mapSize","vec2",r).setGroup(nv);let l=this.vsmMaterialVertical||(this.vsmMaterialVertical=new sS);l.fragmentNode=QR({samples:i,radius:s,size:o,shadowPass:e}).context(t.getSharedContext()),l.name="VSMVertical",l=this.vsmMaterialHorizontal||(this.vsmMaterialHorizontal=new sS),l.fragmentNode=tI({samples:i,radius:s,size:o,shadowPass:n}).context(t.getSharedContext()),l.name="VSMHorizontal"}const l=LM("intensity","float",r).setGroup(nv),c=LM("bias","float",r).setGroup(nv),u=LM("normalBias","float",r).setGroup(nv),h=e.material.shadowPositionNode||tM;let d=rv(r.matrix).setGroup(nv).mul(h.add(hM.mul(u)));d=d.xyz.div(d.w);let p=d.z.add(c);n.coordinateSystem===kn&&(p=p.mul(2).sub(1)),d=Og(d.x,d.y.oneMinus(),p);const m=d.x.greaterThanEqual(0).and(d.x.lessThanEqual(1)).and(d.y.greaterThanEqual(0)).and(d.y.lessThanEqual(1)).and(d.z.lessThanEqual(1)),f=r.filterNode||eI[n.shadowMap.type]||null;if(null===f)throw new Error("THREE.WebGPURenderer: Shadow map type not supported yet.");const g=bx(o.texture,d),v=m.select(f({depthTexture:3===s?this.vsmShadowMapHorizontal.texture:a,shadowCoord:d,shadow:r}),Ng(1));this.shadowMap=o,this.light.shadow.map=o,this.shadowNode=v,this.shadowColorNode=i=this.colorNode.mul(d_(1,v.rgb.mix(g,1),l.mul(g.a))),this.baseColorNode=this.colorNode}this.colorNode=i,this.updateBeforeType=Tf.RENDER}setup(t){this.colorNode=this.baseColorNode||this.colorNode,this.light.castShadow?t.object.receiveShadow&&this.setupShadow(t):null!==this.shadowNode&&this.disposeShadow()}updateShadow(t){const{shadowMap:e,light:n}=this,{renderer:i,scene:s,camera:r}=t,a=i.shadowMap.type,o=e.depthTexture.version;this._depthVersionCached=o;const l=s.overrideMaterial;s.overrideMaterial=nI,e.setSize(n.shadow.mapSize.width,n.shadow.mapSize.height),n.shadow.updateMatrices(n),n.shadow.camera.layers.mask=r.layers.mask;const c=i.getRenderTarget(),u=i.getRenderObjectFunction();i.setRenderObjectFunction(((t,...e)=>{(!0===t.castShadow||t.receiveShadow&&3===a)&&i.renderObject(t,...e)})),i.setRenderTarget(e),i.render(s,n.shadow.camera),i.setRenderObjectFunction(u),!0!==n.isPointLight&&3===a&&this.vsmPass(t,n),i.setRenderTarget(c),s.overrideMaterial=l}vsmPass(t,e){const{renderer:n}=t;this.vsmShadowMapVertical.setSize(e.shadow.mapSize.width,e.shadow.mapSize.height),this.vsmShadowMapHorizontal.setSize(e.shadow.mapSize.width,e.shadow.mapSize.height),n.setRenderTarget(this.vsmShadowMapVertical),iI.material=this.vsmMaterialVertical,iI.render(n),n.setRenderTarget(this.vsmShadowMapHorizontal),iI.material=this.vsmMaterialHorizontal,iI.render(n)}disposeShadow(){this.shadowMap.dispose(),this.shadowMap=null,null!==this.vsmShadowMapVertical&&(this.vsmShadowMapVertical.dispose(),this.vsmShadowMapVertical=null,this.vsmMaterialVertical.dispose(),this.vsmMaterialVertical=null),null!==this.vsmShadowMapHorizontal&&(this.vsmShadowMapHorizontal.dispose(),this.vsmShadowMapHorizontal=null,this.vsmMaterialHorizontal.dispose(),this.vsmMaterialHorizontal=null),this.shadowNode=null,this.shadowColorNode=null,this.baseColorNode=null,this.updateBeforeType=Tf.NONE}updateBefore(t){const e=this.light.shadow;(e.needsUpdate||e.autoUpdate)&&(this.updateShadow(t),this.shadowMap.depthTexture.version===this._depthVersionCached&&(e.needsUpdate=!1))}update(){const{light:t}=this;this.color.copy(t.color).multiplyScalar(t.intensity)}}const rI=Mg((t=>{const{lightDistance:e,cutoffDistance:n,decayExponent:i}=t,s=e.pow(i).max(.01).reciprocal();return n.greaterThan(0).select(s.mul(e.div(n).pow4().oneMinus().clamp().pow2()),s)}));let aI;function oI(t){aI=aI||new WeakMap;let e=aI.get(t);return void 0===e&&aI.set(t,e={}),e}function lI(t){const e=oI(t);return e.position||(e.position=rv(new Li).setGroup(nv).onRenderUpdate(((e,n)=>n.value.setFromMatrixPosition(t.matrixWorld))))}function cI(t){const e=oI(t);return e.targetPosition||(e.targetPosition=rv(new Li).setGroup(nv).onRenderUpdate(((e,n)=>n.value.setFromMatrixPosition(t.target.matrixWorld))))}function uI(t){const e=oI(t);return e.viewPosition||(e.viewPosition=rv(new Li).setGroup(nv).onRenderUpdate((({camera:e},n)=>{n.value=n.value||new Li,n.value.setFromMatrixPosition(t.matrixWorld),n.value.applyMatrix4(e.matrixWorldInverse)})))}const hI=t=>Rx.transformDirection(lI(t).sub(cI(t))),dI=Mg((([t])=>{const e=t.toUint().mul(747796405).add(2891336453),n=e.shiftRight(e.shiftRight(28).add(4)).bitXor(e).mul(277803737);return n.shiftRight(22).bitXor(n).toFloat().mul(1/2**32)})),pI=(t,e)=>r_(Wv(4,t.mul(Gv(1,t))),e),mI=(t,e)=>t.lessThan(.5)?pI(t.mul(2),e).div(2):Gv(1,pI(Wv(Gv(1,t),2),e).div(2)),fI=(t,e,n)=>r_(jv(r_(t,e),Hv(r_(t,e),r_(Gv(1,t),n))),1/e),gI=(t,e)=>Ry(py.mul(e.mul(t).sub(1))).div(py.mul(e.mul(t).sub(1))),vI=Mg((([t])=>t.fract().sub(.5).abs())).setLayout({name:"tri",type:"float",inputs:[{name:"x",type:"float"}]}),yI=Mg((([t])=>Og(vI(t.z.add(vI(t.y.mul(1)))),vI(t.z.add(vI(t.x.mul(1)))),vI(t.y.add(vI(t.x.mul(1))))))).setLayout({name:"tri3",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),_I=Mg((([t,e,n])=>{const i=Og(t).toVar(),s=Ng(1.4).toVar(),r=Ng(0).toVar(),a=Og(i).toVar();return uT({start:Ng(0),end:Ng(3),type:"float",condition:"<="},(()=>{const t=Og(yI(a.mul(2))).toVar();i.addAssign(t.add(n.mul(Ng(.1).mul(e)))),a.mulAssign(1.8),s.mulAssign(1.5),i.mulAssign(1.2);const o=Ng(vI(i.z.add(vI(i.x.add(vI(i.y)))))).toVar();r.addAssign(o.div(s)),a.addAssign(.14)})),r})).setLayout({name:"triNoise3D",type:"float",inputs:[{name:"p",type:"vec3"},{name:"spd",type:"float"},{name:"time",type:"float"}]}),xI=Mg((([t,e,n=Lg(.5)])=>ME(t.sub(n),e).add(n))),MI=Mg((([t,e,n=Lg(.5)])=>{const i=t.sub(n),s=i.dot(i),r=s.mul(s).mul(e);return t.add(i.mul(r))})),bI=Mg((({position:t=null,horizontal:e=!0,vertical:n=!1})=>{let i;null!==t?(i=Hx.toVar(),i[3][0]=t.x,i[3][1]=t.y,i[3][2]=t.z):i=Hx;const s=Rx.mul(i);return pg(e)&&(s[0][0]=Hx[0].length(),s[0][1]=0,s[0][2]=0),pg(n)&&(s[1][0]=0,s[1][1]=Hx[1].length(),s[1][2]=0),s[2][0]=0,s[2][1]=0,s[2][2]=1,Nx.mul(s).mul(Kx)})),TI=Mg((([t=null])=>{const e=eS();return eS(qT(t)).sub(e).lessThan(0).select(IT,t)})),SI=new WeakMap;class wI extends Pf{static get type(){return"VelocityNode"}constructor(){super("vec2"),this.updateType=Tf.OBJECT,this.updateAfterType=Tf.OBJECT,this.previousModelWorldMatrix=rv(new ls),this.previousProjectionMatrix=rv(new ls).setGroup(nv),this.previousCameraViewMatrix=rv(new ls)}update({frameId:t,camera:e,object:n}){const i=AI(n);this.previousModelWorldMatrix.value.copy(i);const s=EI(e);s.frameId!==t&&(s.frameId=t,void 0===s.previousProjectionMatrix?(s.previousProjectionMatrix=new ls,s.previousCameraViewMatrix=new ls,s.currentProjectionMatrix=new ls,s.currentCameraViewMatrix=new ls,s.previousProjectionMatrix.copy(e.projectionMatrix),s.previousCameraViewMatrix.copy(e.matrixWorldInverse)):(s.previousProjectionMatrix.copy(s.currentProjectionMatrix),s.previousCameraViewMatrix.copy(s.currentCameraViewMatrix)),s.currentProjectionMatrix.copy(e.projectionMatrix),s.currentCameraViewMatrix.copy(e.matrixWorldInverse),this.previousProjectionMatrix.value.copy(s.previousProjectionMatrix),this.previousCameraViewMatrix.value.copy(s.previousCameraViewMatrix))}updateAfter({object:t}){AI(t).copy(t.matrixWorld)}setup(){const t=this.previousCameraViewMatrix.mul(this.previousModelWorldMatrix),e=Nx.mul(Yx).mul(Kx),n=this.previousProjectionMatrix.mul(t).mul(Qx),i=e.xy.div(e.w),s=n.xy.div(n.w);return Gv(i,s)}}function EI(t){let e=SI.get(t);return void 0===e&&(e={},SI.set(t,e)),e}function AI(t,e=0){const n=EI(t);let i=n[e];return void 0===i&&(n[e]=i=new ls),i}const NI=xg(wI),CI=Mg((([t,e])=>$y(1,t.oneMinus().div(e)).oneMinus())).setLayout({name:"burnBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),RI=Mg((([t,e])=>$y(t.div(e.oneMinus()),1))).setLayout({name:"dodgeBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),II=Mg((([t,e])=>t.oneMinus().mul(e.oneMinus()).oneMinus())).setLayout({name:"screenBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),LI=Mg((([t,e])=>d_(t.mul(2).mul(e),t.oneMinus().mul(2).mul(e.oneMinus()).oneMinus(),Qy(.5,t)))).setLayout({name:"overlayBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),PI=Mg((([t,e,n=Cg(16)])=>{const i=e=>t.uv(e),s=gx(),r=i(s).toVar(),a=Ng(n);return uT({start:Cg(1),end:n,type:"int",condition:"<="},(({i:t})=>{const n=e.mul(Ng(t).div(a.sub(1)).sub(.5));r.addAssign(i(s.add(n)))})),r.divAssign(a),r})),UI=Mg((([t,e=1])=>{const n=t,i=IC(n.rgb),s=Og(i),r=$y(1,Jy(0,Ng(10).mul(i.sub(.45)))),a=s.mul(n.rgb).mul(2),o=Ng(2).mul(s.oneMinus()).mul(n.rgb.oneMinus()).oneMinus(),l=d_(a,o,r),c=n.a.mul(e),u=c.mul(l.rgb);return u.addAssign(n.rgb.mul(c.oneMinus())),Bg(u,n.a)})),DI=Mg((([t])=>{const e=Og(t);return Bg(i_(e,Og(.393,.769,.189)),i_(e,Og(.349,.686,.168)),i_(e,Og(.272,.534,.131)),t.a)})),OI=Mg((([t])=>{const e=t.mul(.9478672986).add(.0521327014).pow(2.4),n=t.mul(.0773993808),i=t.lessThanEqual(.04045);return d_(e,n,i)})).setLayout({name:"sRGBToLinearSRGB",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),zI=Mg((([t])=>{const e=t.pow(.41666).mul(1.055).sub(.055),n=t.mul(12.92),i=t.lessThanEqual(.0031308);return d_(e,n,i)})).setLayout({name:"linearSRGBTosRGB",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),VI=Mg((([t,e])=>t.mul(e).clamp())).setLayout({name:"linearToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),FI=Mg((([t,e])=>(t=t.mul(e)).div(t.add(1)).clamp())).setLayout({name:"reinhardToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),BI=Mg((([t,e])=>{const n=(t=(t=t.mul(e)).sub(.004).max(0)).mul(t.mul(6.2).add(.5)),i=t.mul(t.mul(6.2).add(1.7)).add(.06);return n.div(i).pow(2.2)})).setLayout({name:"cineonToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),kI=Mg((([t])=>{const e=t.mul(t.add(.0245786)).sub(90537e-9),n=t.mul(t.add(.432951).mul(.983729)).add(.238081);return e.div(n)})),HI=Mg((([t,e])=>{const n=jg(.59719,.35458,.04823,.076,.90834,.01566,.0284,.13383,.83777),i=jg(1.60475,-.53108,-.07367,-.10208,1.10813,-.00605,-.00327,-.07276,1.07602);return t=t.mul(e).div(.6),t=n.mul(t),t=kI(t),(t=i.mul(t)).clamp()})).setLayout({name:"acesFilmicToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),GI=jg(Og(1.6605,-.1246,-.0182),Og(-.5876,1.1329,-.1006),Og(-.0728,-.0083,1.1187)),WI=jg(Og(.6274,.0691,.0164),Og(.3293,.9195,.088),Og(.0433,.0113,.8956)),jI=Mg((([t])=>{const e=Og(t).toVar(),n=Og(e.mul(e)).toVar(),i=Og(n.mul(n)).toVar();return Ng(15.5).mul(i.mul(n)).sub(Wv(40.14,i.mul(e))).add(Wv(31.96,i).sub(Wv(6.868,n.mul(e))).add(Wv(.4298,n).add(Wv(.1191,e).sub(.00232))))})),XI=Mg((([t,e])=>{const n=Og(t).toVar(),i=jg(Og(.856627153315983,.137318972929847,.11189821299995),Og(.0951212405381588,.761241990602591,.0767994186031903),Og(.0482516061458583,.101439036467562,.811302368396859)),s=jg(Og(1.1271005818144368,-.1413297634984383,-.14132976349843826),Og(-.11060664309660323,1.157823702216272,-.11060664309660294),Og(-.016493938717834573,-.016493938717834257,1.2519364065950405)),r=Ng(-12.47393),a=Ng(4.026069);return n.mulAssign(e),n.assign(WI.mul(n)),n.assign(i.mul(n)),n.assign(Jy(n,1e-10)),n.assign(Ty(n)),n.assign(n.sub(r).div(a.sub(r))),n.assign(p_(n,0,1)),n.assign(jI(n)),n.assign(s.mul(n)),n.assign(r_(Jy(Og(0),n),Og(2.2))),n.assign(GI.mul(n)),n.assign(p_(n,0,1)),n})).setLayout({name:"agxToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),qI=Mg((([t,e])=>{const n=Ng(.76),i=Ng(.15);t=t.mul(e);const s=$y(t.r,$y(t.g,t.b)),r=b_(s.lessThan(.08),s.sub(Wv(6.25,s.mul(s))),.04);t.subAssign(r);const a=Jy(t.r,Jy(t.g,t.b));wg(a.lessThan(n),(()=>t));const o=Gv(1,n),l=Gv(1,o.mul(o).div(a.add(o.sub(n))));t.mulAssign(l.div(a));const c=Gv(1,jv(1,i.mul(a.sub(l)).add(1)));return d_(t,Og(l),c)})).setLayout({name:"neutralToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]});class YI extends Rf{static get type(){return"ComputeBuiltinNode"}constructor(t,e){super(e),this._builtinName=t}getHash(t){return this.getBuiltinName(t)}getNodeType(){return this.nodeType}setBuiltinName(t){return this._builtinName=t,this}getBuiltinName(){return this._builtinName}hasBuiltin(t){t.hasBuiltin(this._builtinName)}generate(t,e){const n=this.getBuiltinName(t),i=this.getNodeType(t);return"compute"===t.shaderStage?t.format(n,i,e):(console.warn(`ComputeBuiltinNode: Compute built-in value ${n} can not be accessed in the ${t.shaderStage} stage`),t.generateConst(i))}serialize(t){super.serialize(t),t.global=this.global,t._builtinName=this._builtinName}deserialize(t){super.deserialize(t),this.global=t.global,this._builtinName=t._builtinName}}const ZI=(t,e)=>gg(new YI(t,e)),$I=ZI("numWorkgroups","uvec3"),JI=ZI("workgroupId","uvec3"),KI=ZI("localId","uvec3"),QI=ZI("subgroupSize","uint");const tL=_g(class extends Rf{constructor(t){super(),this.scope=t}generate(t){const{scope:e}=this,{renderer:n}=t;!0===n.backend.isWebGLBackend?t.addFlowCode(`\t// ${e}Barrier \n`):t.addLineFlowCode(`${e}Barrier()`,this)}}),eL=()=>tL("workgroup").append(),nL=()=>tL("storage").append(),iL=()=>tL("texture").append();class sL extends If{constructor(t,e){super(t,e),this.isWorkgroupInfoElementNode=!0}generate(t,e){let n;const i=t.context.assign;if(n=super.generate(t),!0!==i){const i=this.getNodeType(t);n=t.format(n,i,e)}return n}}class rL extends Rf{constructor(t,e,n=0){super(e),this.bufferType=e,this.bufferCount=n,this.isWorkgroupInfoNode=!0,this.scope=t}label(t){return this.name=t,this}getHash(){return this.uuid}setScope(t){return this.scope=t,this}getInputType(){return`${this.scope}Array`}element(t){return gg(new sL(this,t))}generate(t){return t.getScopedArray(this.name||`${this.scope}Array_${this.id}`,this.scope.toLowerCase(),this.bufferType,this.bufferCount)}}const aL=(t,e)=>gg(new rL("Workgroup",t,e));class oL extends Pf{static get type(){return"AtomicFunctionNode"}constructor(t,e,n,i=null){super("uint"),this.method=t,this.pointerNode=e,this.valueNode=n,this.storeNode=i}getInputType(t){return this.pointerNode.getNodeType(t)}getNodeType(t){return this.getInputType(t)}generate(t){const e=this.method,n=this.getNodeType(t),i=this.getInputType(t),s=this.pointerNode,r=this.valueNode,a=[];a.push(`&${s.build(t,i)}`),a.push(r.build(t,i));const o=`${t.getMethod(e,n)}( ${a.join(", ")} )`;if(null!==this.storeNode){const e=this.storeNode.build(t,i);t.addLineFlowCode(`${e} = ${o}`,this)}else t.addLineFlowCode(o,this)}}oL.ATOMIC_LOAD="atomicLoad",oL.ATOMIC_STORE="atomicStore",oL.ATOMIC_ADD="atomicAdd",oL.ATOMIC_SUB="atomicSub",oL.ATOMIC_MAX="atomicMax",oL.ATOMIC_MIN="atomicMin",oL.ATOMIC_AND="atomicAnd",oL.ATOMIC_OR="atomicOr",oL.ATOMIC_XOR="atomicXor";const lL=_g(oL),cL=(t,e,n,i)=>{const s=lL(t,e,n,i);return s.append(),s},uL=(t,e,n=null)=>cL(oL.ATOMIC_STORE,t,e,n),hL=(t,e,n=null)=>cL(oL.ATOMIC_ADD,t,e,n),dL=(t,e,n=null)=>cL(oL.ATOMIC_SUB,t,e,n),pL=(t,e,n=null)=>cL(oL.ATOMIC_MAX,t,e,n),mL=(t,e,n=null)=>cL(oL.ATOMIC_MIN,t,e,n),fL=(t,e,n=null)=>cL(oL.ATOMIC_AND,t,e,n),gL=(t,e,n=null)=>cL(oL.ATOMIC_OR,t,e,n),vL=(t,e,n=null)=>cL(oL.ATOMIC_XOR,t,e,n),yL=Mg((([t=e()])=>{const e=t.mul(2),n=e.x.floor(),i=e.y.floor();return n.add(i).mod(2).sign()})),_L=Mg((([t,e,n])=>{const i=Ng(n).toVar(),s=Ng(e).toVar(),r=Ig(t).toVar();return b_(r,s,i)})).setLayout({name:"mx_select",type:"float",inputs:[{name:"b",type:"bool"},{name:"t",type:"float"},{name:"f",type:"float"}]}),xL=Mg((([t,e])=>{const n=Ig(e).toVar(),i=Ng(t).toVar();return b_(n,i.negate(),i)})).setLayout({name:"mx_negate_if",type:"float",inputs:[{name:"val",type:"float"},{name:"b",type:"bool"}]}),ML=Mg((([t])=>{const e=Ng(t).toVar();return Cg(Ey(e))})).setLayout({name:"mx_floor",type:"int",inputs:[{name:"x",type:"float"}]}),bL=Mg((([t,e])=>{const n=Ng(t).toVar();return e.assign(ML(n)),n.sub(Ng(e))})),TL=QA([Mg((([t,e,n,i,s,r])=>{const a=Ng(r).toVar(),o=Ng(s).toVar(),l=Ng(i).toVar(),c=Ng(n).toVar(),u=Ng(e).toVar(),h=Ng(t).toVar(),d=Ng(Gv(1,o)).toVar();return Gv(1,a).mul(h.mul(d).add(u.mul(o))).add(a.mul(c.mul(d).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"}]}),Mg((([t,e,n,i,s,r])=>{const a=Ng(r).toVar(),o=Ng(s).toVar(),l=Og(i).toVar(),c=Og(n).toVar(),u=Og(e).toVar(),h=Og(t).toVar(),d=Ng(Gv(1,o)).toVar();return Gv(1,a).mul(h.mul(d).add(u.mul(o))).add(a.mul(c.mul(d).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"}]})]),SL=QA([Mg((([t,e,n,i,s,r,a,o,l,c,u])=>{const h=Ng(u).toVar(),d=Ng(c).toVar(),p=Ng(l).toVar(),m=Ng(o).toVar(),f=Ng(a).toVar(),g=Ng(r).toVar(),v=Ng(s).toVar(),y=Ng(i).toVar(),_=Ng(n).toVar(),x=Ng(e).toVar(),M=Ng(t).toVar(),b=Ng(Gv(1,p)).toVar(),T=Ng(Gv(1,d)).toVar();return Ng(Gv(1,h)).toVar().mul(T.mul(M.mul(b).add(x.mul(p))).add(d.mul(_.mul(b).add(y.mul(p))))).add(h.mul(T.mul(v.mul(b).add(g.mul(p))).add(d.mul(f.mul(b).add(m.mul(p))))))})).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"}]}),Mg((([t,e,n,i,s,r,a,o,l,c,u])=>{const h=Ng(u).toVar(),d=Ng(c).toVar(),p=Ng(l).toVar(),m=Og(o).toVar(),f=Og(a).toVar(),g=Og(r).toVar(),v=Og(s).toVar(),y=Og(i).toVar(),_=Og(n).toVar(),x=Og(e).toVar(),M=Og(t).toVar(),b=Ng(Gv(1,p)).toVar(),T=Ng(Gv(1,d)).toVar();return Ng(Gv(1,h)).toVar().mul(T.mul(M.mul(b).add(x.mul(p))).add(d.mul(_.mul(b).add(y.mul(p))))).add(h.mul(T.mul(v.mul(b).add(g.mul(p))).add(d.mul(f.mul(b).add(m.mul(p))))))})).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"}]})]),wL=Mg((([t,e,n])=>{const i=Ng(n).toVar(),s=Ng(e).toVar(),r=Rg(t).toVar(),a=Rg(r.bitAnd(Rg(7))).toVar(),o=Ng(_L(a.lessThan(Rg(4)),s,i)).toVar(),l=Ng(Wv(2,_L(a.lessThan(Rg(4)),i,s))).toVar();return xL(o,Ig(a.bitAnd(Rg(1)))).add(xL(l,Ig(a.bitAnd(Rg(2)))))})).setLayout({name:"mx_gradient_float_0",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"}]}),EL=Mg((([t,e,n,i])=>{const s=Ng(i).toVar(),r=Ng(n).toVar(),a=Ng(e).toVar(),o=Rg(t).toVar(),l=Rg(o.bitAnd(Rg(15))).toVar(),c=Ng(_L(l.lessThan(Rg(8)),a,r)).toVar(),u=Ng(_L(l.lessThan(Rg(4)),r,_L(l.equal(Rg(12)).or(l.equal(Rg(14))),a,s))).toVar();return xL(c,Ig(l.bitAnd(Rg(1)))).add(xL(u,Ig(l.bitAnd(Rg(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"}]}),AL=QA([wL,EL]),NL=Mg((([t,e,n])=>{const i=Ng(n).toVar(),s=Ng(e).toVar(),r=Vg(t).toVar();return Og(AL(r.x,s,i),AL(r.y,s,i),AL(r.z,s,i))})).setLayout({name:"mx_gradient_vec3_0",type:"vec3",inputs:[{name:"hash",type:"uvec3"},{name:"x",type:"float"},{name:"y",type:"float"}]}),CL=Mg((([t,e,n,i])=>{const s=Ng(i).toVar(),r=Ng(n).toVar(),a=Ng(e).toVar(),o=Vg(t).toVar();return Og(AL(o.x,a,r,s),AL(o.y,a,r,s),AL(o.z,a,r,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"}]}),RL=QA([NL,CL]),IL=Mg((([t])=>{const e=Ng(t).toVar();return Wv(.6616,e)})).setLayout({name:"mx_gradient_scale2d_0",type:"float",inputs:[{name:"v",type:"float"}]}),LL=Mg((([t])=>{const e=Ng(t).toVar();return Wv(.982,e)})).setLayout({name:"mx_gradient_scale3d_0",type:"float",inputs:[{name:"v",type:"float"}]}),PL=QA([IL,Mg((([t])=>{const e=Og(t).toVar();return Wv(.6616,e)})).setLayout({name:"mx_gradient_scale2d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),UL=QA([LL,Mg((([t])=>{const e=Og(t).toVar();return Wv(.982,e)})).setLayout({name:"mx_gradient_scale3d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),DL=Mg((([t,e])=>{const n=Cg(e).toVar(),i=Rg(t).toVar();return i.shiftLeft(n).bitOr(i.shiftRight(Cg(32).sub(n)))})).setLayout({name:"mx_rotl32",type:"uint",inputs:[{name:"x",type:"uint"},{name:"k",type:"int"}]}),OL=Mg((([t,e,n])=>{t.subAssign(n),t.bitXorAssign(DL(n,Cg(4))),n.addAssign(e),e.subAssign(t),e.bitXorAssign(DL(t,Cg(6))),t.addAssign(n),n.subAssign(e),n.bitXorAssign(DL(e,Cg(8))),e.addAssign(t),t.subAssign(n),t.bitXorAssign(DL(n,Cg(16))),n.addAssign(e),e.subAssign(t),e.bitXorAssign(DL(t,Cg(19))),t.addAssign(n),n.subAssign(e),n.bitXorAssign(DL(e,Cg(4))),e.addAssign(t)})),zL=Mg((([t,e,n])=>{const i=Rg(n).toVar(),s=Rg(e).toVar(),r=Rg(t).toVar();return i.bitXorAssign(s),i.subAssign(DL(s,Cg(14))),r.bitXorAssign(i),r.subAssign(DL(i,Cg(11))),s.bitXorAssign(r),s.subAssign(DL(r,Cg(25))),i.bitXorAssign(s),i.subAssign(DL(s,Cg(16))),r.bitXorAssign(i),r.subAssign(DL(i,Cg(4))),s.bitXorAssign(r),s.subAssign(DL(r,Cg(14))),i.bitXorAssign(s),i.subAssign(DL(s,Cg(24))),i})).setLayout({name:"mx_bjfinal",type:"uint",inputs:[{name:"a",type:"uint"},{name:"b",type:"uint"},{name:"c",type:"uint"}]}),VL=Mg((([t])=>{const e=Rg(t).toVar();return Ng(e).div(Ng(Rg(Cg(4294967295))))})).setLayout({name:"mx_bits_to_01",type:"float",inputs:[{name:"bits",type:"uint"}]}),FL=Mg((([t])=>{const e=Ng(t).toVar();return e.mul(e).mul(e).mul(e.mul(e.mul(6).sub(15)).add(10))})).setLayout({name:"mx_fade",type:"float",inputs:[{name:"t",type:"float"}]}),BL=QA([Mg((([t])=>{const e=Cg(t).toVar(),n=Rg(Rg(1)).toVar(),i=Rg(Rg(Cg(3735928559)).add(n.shiftLeft(Rg(2))).add(Rg(13))).toVar();return zL(i.add(Rg(e)),i,i)})).setLayout({name:"mx_hash_int_0",type:"uint",inputs:[{name:"x",type:"int"}]}),Mg((([t,e])=>{const n=Cg(e).toVar(),i=Cg(t).toVar(),s=Rg(Rg(2)).toVar(),r=Rg().toVar(),a=Rg().toVar(),o=Rg().toVar();return r.assign(a.assign(o.assign(Rg(Cg(3735928559)).add(s.shiftLeft(Rg(2))).add(Rg(13))))),r.addAssign(Rg(i)),a.addAssign(Rg(n)),zL(r,a,o)})).setLayout({name:"mx_hash_int_1",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),Mg((([t,e,n])=>{const i=Cg(n).toVar(),s=Cg(e).toVar(),r=Cg(t).toVar(),a=Rg(Rg(3)).toVar(),o=Rg().toVar(),l=Rg().toVar(),c=Rg().toVar();return o.assign(l.assign(c.assign(Rg(Cg(3735928559)).add(a.shiftLeft(Rg(2))).add(Rg(13))))),o.addAssign(Rg(r)),l.addAssign(Rg(s)),c.addAssign(Rg(i)),zL(o,l,c)})).setLayout({name:"mx_hash_int_2",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]}),Mg((([t,e,n,i])=>{const s=Cg(i).toVar(),r=Cg(n).toVar(),a=Cg(e).toVar(),o=Cg(t).toVar(),l=Rg(Rg(4)).toVar(),c=Rg().toVar(),u=Rg().toVar(),h=Rg().toVar();return c.assign(u.assign(h.assign(Rg(Cg(3735928559)).add(l.shiftLeft(Rg(2))).add(Rg(13))))),c.addAssign(Rg(o)),u.addAssign(Rg(a)),h.addAssign(Rg(r)),OL(c,u,h),c.addAssign(Rg(s)),zL(c,u,h)})).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"}]}),Mg((([t,e,n,i,s])=>{const r=Cg(s).toVar(),a=Cg(i).toVar(),o=Cg(n).toVar(),l=Cg(e).toVar(),c=Cg(t).toVar(),u=Rg(Rg(5)).toVar(),h=Rg().toVar(),d=Rg().toVar(),p=Rg().toVar();return h.assign(d.assign(p.assign(Rg(Cg(3735928559)).add(u.shiftLeft(Rg(2))).add(Rg(13))))),h.addAssign(Rg(c)),d.addAssign(Rg(l)),p.addAssign(Rg(o)),OL(h,d,p),h.addAssign(Rg(a)),d.addAssign(Rg(r)),zL(h,d,p)})).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"}]})]),kL=QA([Mg((([t,e])=>{const n=Cg(e).toVar(),i=Cg(t).toVar(),s=Rg(BL(i,n)).toVar(),r=Vg().toVar();return r.x.assign(s.bitAnd(Cg(255))),r.y.assign(s.shiftRight(Cg(8)).bitAnd(Cg(255))),r.z.assign(s.shiftRight(Cg(16)).bitAnd(Cg(255))),r})).setLayout({name:"mx_hash_vec3_0",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),Mg((([t,e,n])=>{const i=Cg(n).toVar(),s=Cg(e).toVar(),r=Cg(t).toVar(),a=Rg(BL(r,s,i)).toVar(),o=Vg().toVar();return o.x.assign(a.bitAnd(Cg(255))),o.y.assign(a.shiftRight(Cg(8)).bitAnd(Cg(255))),o.z.assign(a.shiftRight(Cg(16)).bitAnd(Cg(255))),o})).setLayout({name:"mx_hash_vec3_1",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]})]),HL=QA([Mg((([t])=>{const e=Lg(t).toVar(),n=Cg().toVar(),i=Cg().toVar(),s=Ng(bL(e.x,n)).toVar(),r=Ng(bL(e.y,i)).toVar(),a=Ng(FL(s)).toVar(),o=Ng(FL(r)).toVar(),l=Ng(TL(AL(BL(n,i),s,r),AL(BL(n.add(Cg(1)),i),s.sub(1),r),AL(BL(n,i.add(Cg(1))),s,r.sub(1)),AL(BL(n.add(Cg(1)),i.add(Cg(1))),s.sub(1),r.sub(1)),a,o)).toVar();return PL(l)})).setLayout({name:"mx_perlin_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"}]}),Mg((([t])=>{const e=Og(t).toVar(),n=Cg().toVar(),i=Cg().toVar(),s=Cg().toVar(),r=Ng(bL(e.x,n)).toVar(),a=Ng(bL(e.y,i)).toVar(),o=Ng(bL(e.z,s)).toVar(),l=Ng(FL(r)).toVar(),c=Ng(FL(a)).toVar(),u=Ng(FL(o)).toVar(),h=Ng(SL(AL(BL(n,i,s),r,a,o),AL(BL(n.add(Cg(1)),i,s),r.sub(1),a,o),AL(BL(n,i.add(Cg(1)),s),r,a.sub(1),o),AL(BL(n.add(Cg(1)),i.add(Cg(1)),s),r.sub(1),a.sub(1),o),AL(BL(n,i,s.add(Cg(1))),r,a,o.sub(1)),AL(BL(n.add(Cg(1)),i,s.add(Cg(1))),r.sub(1),a,o.sub(1)),AL(BL(n,i.add(Cg(1)),s.add(Cg(1))),r,a.sub(1),o.sub(1)),AL(BL(n.add(Cg(1)),i.add(Cg(1)),s.add(Cg(1))),r.sub(1),a.sub(1),o.sub(1)),l,c,u)).toVar();return UL(h)})).setLayout({name:"mx_perlin_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"}]})]),GL=QA([Mg((([t])=>{const e=Lg(t).toVar(),n=Cg().toVar(),i=Cg().toVar(),s=Ng(bL(e.x,n)).toVar(),r=Ng(bL(e.y,i)).toVar(),a=Ng(FL(s)).toVar(),o=Ng(FL(r)).toVar(),l=Og(TL(RL(kL(n,i),s,r),RL(kL(n.add(Cg(1)),i),s.sub(1),r),RL(kL(n,i.add(Cg(1))),s,r.sub(1)),RL(kL(n.add(Cg(1)),i.add(Cg(1))),s.sub(1),r.sub(1)),a,o)).toVar();return PL(l)})).setLayout({name:"mx_perlin_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),Mg((([t])=>{const e=Og(t).toVar(),n=Cg().toVar(),i=Cg().toVar(),s=Cg().toVar(),r=Ng(bL(e.x,n)).toVar(),a=Ng(bL(e.y,i)).toVar(),o=Ng(bL(e.z,s)).toVar(),l=Ng(FL(r)).toVar(),c=Ng(FL(a)).toVar(),u=Ng(FL(o)).toVar(),h=Og(SL(RL(kL(n,i,s),r,a,o),RL(kL(n.add(Cg(1)),i,s),r.sub(1),a,o),RL(kL(n,i.add(Cg(1)),s),r,a.sub(1),o),RL(kL(n.add(Cg(1)),i.add(Cg(1)),s),r.sub(1),a.sub(1),o),RL(kL(n,i,s.add(Cg(1))),r,a,o.sub(1)),RL(kL(n.add(Cg(1)),i,s.add(Cg(1))),r.sub(1),a,o.sub(1)),RL(kL(n,i.add(Cg(1)),s.add(Cg(1))),r,a.sub(1),o.sub(1)),RL(kL(n.add(Cg(1)),i.add(Cg(1)),s.add(Cg(1))),r.sub(1),a.sub(1),o.sub(1)),l,c,u)).toVar();return UL(h)})).setLayout({name:"mx_perlin_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"}]})]),WL=QA([Mg((([t])=>{const e=Ng(t).toVar(),n=Cg(ML(e)).toVar();return VL(BL(n))})).setLayout({name:"mx_cell_noise_float_0",type:"float",inputs:[{name:"p",type:"float"}]}),Mg((([t])=>{const e=Lg(t).toVar(),n=Cg(ML(e.x)).toVar(),i=Cg(ML(e.y)).toVar();return VL(BL(n,i))})).setLayout({name:"mx_cell_noise_float_1",type:"float",inputs:[{name:"p",type:"vec2"}]}),Mg((([t])=>{const e=Og(t).toVar(),n=Cg(ML(e.x)).toVar(),i=Cg(ML(e.y)).toVar(),s=Cg(ML(e.z)).toVar();return VL(BL(n,i,s))})).setLayout({name:"mx_cell_noise_float_2",type:"float",inputs:[{name:"p",type:"vec3"}]}),Mg((([t])=>{const e=Bg(t).toVar(),n=Cg(ML(e.x)).toVar(),i=Cg(ML(e.y)).toVar(),s=Cg(ML(e.z)).toVar(),r=Cg(ML(e.w)).toVar();return VL(BL(n,i,s,r))})).setLayout({name:"mx_cell_noise_float_3",type:"float",inputs:[{name:"p",type:"vec4"}]})]),jL=QA([Mg((([t])=>{const e=Ng(t).toVar(),n=Cg(ML(e)).toVar();return Og(VL(BL(n,Cg(0))),VL(BL(n,Cg(1))),VL(BL(n,Cg(2))))})).setLayout({name:"mx_cell_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"float"}]}),Mg((([t])=>{const e=Lg(t).toVar(),n=Cg(ML(e.x)).toVar(),i=Cg(ML(e.y)).toVar();return Og(VL(BL(n,i,Cg(0))),VL(BL(n,i,Cg(1))),VL(BL(n,i,Cg(2))))})).setLayout({name:"mx_cell_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),Mg((([t])=>{const e=Og(t).toVar(),n=Cg(ML(e.x)).toVar(),i=Cg(ML(e.y)).toVar(),s=Cg(ML(e.z)).toVar();return Og(VL(BL(n,i,s,Cg(0))),VL(BL(n,i,s,Cg(1))),VL(BL(n,i,s,Cg(2))))})).setLayout({name:"mx_cell_noise_vec3_2",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),Mg((([t])=>{const e=Bg(t).toVar(),n=Cg(ML(e.x)).toVar(),i=Cg(ML(e.y)).toVar(),s=Cg(ML(e.z)).toVar(),r=Cg(ML(e.w)).toVar();return Og(VL(BL(n,i,s,r,Cg(0))),VL(BL(n,i,s,r,Cg(1))),VL(BL(n,i,s,r,Cg(2))))})).setLayout({name:"mx_cell_noise_vec3_3",type:"vec3",inputs:[{name:"p",type:"vec4"}]})]),XL=Mg((([t,e,n,i])=>{const s=Ng(i).toVar(),r=Ng(n).toVar(),a=Cg(e).toVar(),o=Og(t).toVar(),l=Ng(0).toVar(),c=Ng(1).toVar();return uT(a,(()=>{l.addAssign(c.mul(HL(o))),c.mulAssign(s),o.mulAssign(r)})),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"}]}),qL=Mg((([t,e,n,i])=>{const s=Ng(i).toVar(),r=Ng(n).toVar(),a=Cg(e).toVar(),o=Og(t).toVar(),l=Og(0).toVar(),c=Ng(1).toVar();return uT(a,(()=>{l.addAssign(c.mul(GL(o))),c.mulAssign(s),o.mulAssign(r)})),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"}]}),YL=Mg((([t,e,n,i])=>{const s=Ng(i).toVar(),r=Ng(n).toVar(),a=Cg(e).toVar(),o=Og(t).toVar();return Lg(XL(o,a,r,s),XL(o.add(Og(Cg(19),Cg(193),Cg(17))),a,r,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"}]}),ZL=Mg((([t,e,n,i])=>{const s=Ng(i).toVar(),r=Ng(n).toVar(),a=Cg(e).toVar(),o=Og(t).toVar(),l=Og(qL(o,a,r,s)).toVar(),c=Ng(XL(o.add(Og(Cg(19),Cg(193),Cg(17))),a,r,s)).toVar();return Bg(l,c)})).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"}]}),$L=Mg((([t,e,n,i,s,r,a])=>{const o=Cg(a).toVar(),l=Ng(r).toVar(),c=Cg(s).toVar(),u=Cg(i).toVar(),h=Cg(n).toVar(),d=Cg(e).toVar(),p=Lg(t).toVar(),m=Og(jL(Lg(d.add(u),h.add(c)))).toVar(),f=Lg(m.x,m.y).toVar();f.subAssign(.5),f.mulAssign(l),f.addAssign(.5);const g=Lg(Lg(Ng(d),Ng(h)).add(f)).toVar(),v=Lg(g.sub(p)).toVar();return wg(o.equal(Cg(2)),(()=>Oy(v.x).add(Oy(v.y)))),wg(o.equal(Cg(3)),(()=>Jy(Oy(v.x),Oy(v.y)))),i_(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"}]}),JL=QA([$L,Mg((([t,e,n,i,s,r,a,o,l])=>{const c=Cg(l).toVar(),u=Ng(o).toVar(),h=Cg(a).toVar(),d=Cg(r).toVar(),p=Cg(s).toVar(),m=Cg(i).toVar(),f=Cg(n).toVar(),g=Cg(e).toVar(),v=Og(t).toVar(),y=Og(jL(Og(g.add(p),f.add(d),m.add(h)))).toVar();y.subAssign(.5),y.mulAssign(u),y.addAssign(.5);const _=Og(Og(Ng(g),Ng(f),Ng(m)).add(y)).toVar(),x=Og(_.sub(v)).toVar();return wg(c.equal(Cg(2)),(()=>Oy(x.x).add(Oy(x.y)).add(Oy(x.z)))),wg(c.equal(Cg(3)),(()=>Jy(Jy(Oy(x.x),Oy(x.y)),Oy(x.z)))),i_(x,x)})).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"}]})]),KL=Mg((([t,e,n])=>{const i=Cg(n).toVar(),s=Ng(e).toVar(),r=Lg(t).toVar(),a=Cg().toVar(),o=Cg().toVar(),l=Lg(bL(r.x,a),bL(r.y,o)).toVar(),c=Ng(1e6).toVar();return uT({start:-1,end:Cg(1),name:"x",condition:"<="},(({x:t})=>{uT({start:-1,end:Cg(1),name:"y",condition:"<="},(({y:e})=>{const n=Ng(JL(l,t,e,a,o,s,i)).toVar();c.assign($y(c,n))}))})),wg(i.equal(Cg(0)),(()=>{c.assign(Sy(c))})),c})).setLayout({name:"mx_worley_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),QL=Mg((([t,e,n])=>{const i=Cg(n).toVar(),s=Ng(e).toVar(),r=Lg(t).toVar(),a=Cg().toVar(),o=Cg().toVar(),l=Lg(bL(r.x,a),bL(r.y,o)).toVar(),c=Lg(1e6,1e6).toVar();return uT({start:-1,end:Cg(1),name:"x",condition:"<="},(({x:t})=>{uT({start:-1,end:Cg(1),name:"y",condition:"<="},(({y:e})=>{const n=Ng(JL(l,t,e,a,o,s,i)).toVar();wg(n.lessThan(c.x),(()=>{c.y.assign(c.x),c.x.assign(n)})).ElseIf(n.lessThan(c.y),(()=>{c.y.assign(n)}))}))})),wg(i.equal(Cg(0)),(()=>{c.assign(Sy(c))})),c})).setLayout({name:"mx_worley_noise_vec2_0",type:"vec2",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),tP=Mg((([t,e,n])=>{const i=Cg(n).toVar(),s=Ng(e).toVar(),r=Lg(t).toVar(),a=Cg().toVar(),o=Cg().toVar(),l=Lg(bL(r.x,a),bL(r.y,o)).toVar(),c=Og(1e6,1e6,1e6).toVar();return uT({start:-1,end:Cg(1),name:"x",condition:"<="},(({x:t})=>{uT({start:-1,end:Cg(1),name:"y",condition:"<="},(({y:e})=>{const n=Ng(JL(l,t,e,a,o,s,i)).toVar();wg(n.lessThan(c.x),(()=>{c.z.assign(c.y),c.y.assign(c.x),c.x.assign(n)})).ElseIf(n.lessThan(c.y),(()=>{c.z.assign(c.y),c.y.assign(n)})).ElseIf(n.lessThan(c.z),(()=>{c.z.assign(n)}))}))})),wg(i.equal(Cg(0)),(()=>{c.assign(Sy(c))})),c})).setLayout({name:"mx_worley_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),eP=QA([KL,Mg((([t,e,n])=>{const i=Cg(n).toVar(),s=Ng(e).toVar(),r=Og(t).toVar(),a=Cg().toVar(),o=Cg().toVar(),l=Cg().toVar(),c=Og(bL(r.x,a),bL(r.y,o),bL(r.z,l)).toVar(),u=Ng(1e6).toVar();return uT({start:-1,end:Cg(1),name:"x",condition:"<="},(({x:t})=>{uT({start:-1,end:Cg(1),name:"y",condition:"<="},(({y:e})=>{uT({start:-1,end:Cg(1),name:"z",condition:"<="},(({z:n})=>{const r=Ng(JL(c,t,e,n,a,o,l,s,i)).toVar();u.assign($y(u,r))}))}))})),wg(i.equal(Cg(0)),(()=>{u.assign(Sy(u))})),u})).setLayout({name:"mx_worley_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),nP=QA([QL,Mg((([t,e,n])=>{const i=Cg(n).toVar(),s=Ng(e).toVar(),r=Og(t).toVar(),a=Cg().toVar(),o=Cg().toVar(),l=Cg().toVar(),c=Og(bL(r.x,a),bL(r.y,o),bL(r.z,l)).toVar(),u=Lg(1e6,1e6).toVar();return uT({start:-1,end:Cg(1),name:"x",condition:"<="},(({x:t})=>{uT({start:-1,end:Cg(1),name:"y",condition:"<="},(({y:e})=>{uT({start:-1,end:Cg(1),name:"z",condition:"<="},(({z:n})=>{const r=Ng(JL(c,t,e,n,a,o,l,s,i)).toVar();wg(r.lessThan(u.x),(()=>{u.y.assign(u.x),u.x.assign(r)})).ElseIf(r.lessThan(u.y),(()=>{u.y.assign(r)}))}))}))})),wg(i.equal(Cg(0)),(()=>{u.assign(Sy(u))})),u})).setLayout({name:"mx_worley_noise_vec2_1",type:"vec2",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),iP=QA([tP,Mg((([t,e,n])=>{const i=Cg(n).toVar(),s=Ng(e).toVar(),r=Og(t).toVar(),a=Cg().toVar(),o=Cg().toVar(),l=Cg().toVar(),c=Og(bL(r.x,a),bL(r.y,o),bL(r.z,l)).toVar(),u=Og(1e6,1e6,1e6).toVar();return uT({start:-1,end:Cg(1),name:"x",condition:"<="},(({x:t})=>{uT({start:-1,end:Cg(1),name:"y",condition:"<="},(({y:e})=>{uT({start:-1,end:Cg(1),name:"z",condition:"<="},(({z:n})=>{const r=Ng(JL(c,t,e,n,a,o,l,s,i)).toVar();wg(r.lessThan(u.x),(()=>{u.z.assign(u.y),u.y.assign(u.x),u.x.assign(r)})).ElseIf(r.lessThan(u.y),(()=>{u.z.assign(u.y),u.y.assign(r)})).ElseIf(r.lessThan(u.z),(()=>{u.z.assign(r)}))}))}))})),wg(i.equal(Cg(0)),(()=>{u.assign(Sy(u))})),u})).setLayout({name:"mx_worley_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),sP=Mg((([t])=>{const e=t.y,n=t.z,i=Og().toVar();return wg(e.lessThan(1e-4),(()=>{i.assign(Og(n,n,n))})).Else((()=>{let s=t.x;s=s.sub(Ey(s)).mul(6).toVar();const r=Cg(jy(s)),a=s.sub(Ng(r)),o=n.mul(e.oneMinus()),l=n.mul(e.mul(a).oneMinus()),c=n.mul(e.mul(a.oneMinus()).oneMinus());wg(r.equal(Cg(0)),(()=>{i.assign(Og(n,c,o))})).ElseIf(r.equal(Cg(1)),(()=>{i.assign(Og(l,n,o))})).ElseIf(r.equal(Cg(2)),(()=>{i.assign(Og(o,n,c))})).ElseIf(r.equal(Cg(3)),(()=>{i.assign(Og(o,l,n))})).ElseIf(r.equal(Cg(4)),(()=>{i.assign(Og(c,o,n))})).Else((()=>{i.assign(Og(n,o,l))}))})),i})).setLayout({name:"mx_hsvtorgb",type:"vec3",inputs:[{name:"hsv",type:"vec3"}]}),rP=Mg((([t])=>{const e=Og(t).toVar(),n=Ng(e.x).toVar(),i=Ng(e.y).toVar(),s=Ng(e.z).toVar(),r=Ng($y(n,$y(i,s))).toVar(),a=Ng(Jy(n,Jy(i,s))).toVar(),o=Ng(a.sub(r)).toVar(),l=Ng().toVar(),c=Ng().toVar(),u=Ng().toVar();return u.assign(a),wg(a.greaterThan(0),(()=>{c.assign(o.div(a))})).Else((()=>{c.assign(0)})),wg(c.lessThanEqual(0),(()=>{l.assign(0)})).Else((()=>{wg(n.greaterThanEqual(a),(()=>{l.assign(i.sub(s).div(o))})).ElseIf(i.greaterThanEqual(a),(()=>{l.assign(Hv(2,s.sub(n).div(o)))})).Else((()=>{l.assign(Hv(4,n.sub(i).div(o)))})),l.mulAssign(1/6),wg(l.lessThan(0),(()=>{l.addAssign(1)}))})),Og(l,c,u)})).setLayout({name:"mx_rgbtohsv",type:"vec3",inputs:[{name:"c",type:"vec3"}]}),aP=Mg((([t])=>{const e=Og(t).toVar(),n=Fg($v(e,Og(.04045))).toVar(),i=Og(e.div(12.92)).toVar(),s=Og(r_(Jy(e.add(Og(.055)),Og(0)).div(1.055),Og(2.4))).toVar();return d_(i,s,n)})).setLayout({name:"mx_srgb_texture_to_lin_rec709",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),oP=(t,e)=>{t=Ng(t),e=Ng(e);const n=Lg(e.dFdx(),e.dFdy()).length().mul(.7071067811865476);return g_(t.sub(n),t.add(n),e)},lP=(t,e,n,i)=>d_(t,e,n[i].clamp()),cP=(t,e,n=gx())=>lP(t,e,n,"x"),uP=(t,e,n=gx())=>lP(t,e,n,"y"),hP=(t,e,n,i,s)=>d_(t,e,oP(n,i[s])),dP=(t,e,n,i=gx())=>hP(t,e,n,i,"x"),pP=(t,e,n,i=gx())=>hP(t,e,n,i,"y"),mP=(t=1,e=0,n=gx())=>n.mul(t).add(e),fP=(t,e=1)=>(t=Ng(t)).abs().pow(e).mul(t.sign()),gP=(t,e=1,n=.5)=>Ng(t).sub(n).mul(e).add(n),vP=(t=gx(),e=1,n=0)=>HL(t.convert("vec2|vec3")).mul(e).add(n),yP=(t=gx(),e=1,n=0)=>GL(t.convert("vec2|vec3")).mul(e).add(n),_P=(t=gx(),e=1,n=0)=>{t=t.convert("vec2|vec3");return Bg(GL(t),HL(t.add(Lg(19,73)))).mul(e).add(n)},xP=(t=gx(),e=1)=>eP(t.convert("vec2|vec3"),e,Cg(1)),MP=(t=gx(),e=1)=>nP(t.convert("vec2|vec3"),e,Cg(1)),bP=(t=gx(),e=1)=>iP(t.convert("vec2|vec3"),e,Cg(1)),TP=(t=gx())=>WL(t.convert("vec2|vec3")),SP=(t=gx(),e=3,n=2,i=.5,s=1)=>XL(t,Cg(e),n,i).mul(s),wP=(t=gx(),e=3,n=2,i=.5,s=1)=>YL(t,Cg(e),n,i).mul(s),EP=(t=gx(),e=3,n=2,i=.5,s=1)=>qL(t,Cg(e),n,i).mul(s),AP=(t=gx(),e=3,n=2,i=.5,s=1)=>ZL(t,Cg(e),n,i).mul(s),NP=Mg((([t,e])=>{const n=t.x,i=t.y,s=t.z;let r=e.element(0).mul(.886227);return r=r.add(e.element(1).mul(1.023328).mul(i)),r=r.add(e.element(2).mul(1.023328).mul(s)),r=r.add(e.element(3).mul(1.023328).mul(n)),r=r.add(e.element(4).mul(.858086).mul(n).mul(i)),r=r.add(e.element(5).mul(.858086).mul(i).mul(s)),r=r.add(e.element(6).mul(s.mul(s).mul(.743125).sub(.247708))),r=r.add(e.element(7).mul(.858086).mul(n).mul(s)),r=r.add(e.element(8).mul(.429043).mul(Wv(n,n).sub(Wv(i,i)))),r}));class CP extends sI{static get type(){return"PointLightNode"}constructor(t=null){super(t),this.cutoffDistanceNode=rv(0).setGroup(nv),this.decayExponentNode=rv(0).setGroup(nv)}update(t){const{light:e}=this;super.update(t),this.cutoffDistanceNode.value=e.distance,this.decayExponentNode.value=e.decay}setup(t){const{colorNode:e,cutoffDistanceNode:n,decayExponentNode:i,light:s}=this,r=t.context.lightingModel,a=uI(s).sub(nM),o=a.normalize(),l=a.length(),c=rI({lightDistance:l,cutoffDistance:n,decayExponent:i}),u=e.mul(c),h=t.context.reflectedLight;r.direct({lightDirection:o,lightColor:u,reflectedLight:h},t.stack,t)}}class RP extends sI{static get type(){return"DirectionalLightNode"}constructor(t=null){super(t)}setup(t){super.setup(t);const e=t.context.lightingModel,n=this.colorNode,i=hI(this.light),s=t.context.reflectedLight;e.direct({lightDirection:i,lightColor:n,reflectedLight:s},t.stack,t)}}const IP=new ls,LP=new ls;let PP=null;class UP extends sI{static get type(){return"RectAreaLightNode"}constructor(t=null){super(t),this.halfHeight=rv(new Li).setGroup(nv),this.halfWidth=rv(new Li).setGroup(nv)}update(t){super.update(t);const{light:e}=this,n=t.camera.matrixWorldInverse;LP.identity(),IP.copy(e.matrixWorld),IP.premultiply(n),LP.extractRotation(IP),this.halfWidth.value.set(.5*e.width,0,0),this.halfHeight.value.set(0,.5*e.height,0),this.halfWidth.value.applyMatrix4(LP),this.halfHeight.value.applyMatrix4(LP)}setup(t){let e,n;super.setup(t),t.isAvailable("float32Filterable")?(e=bx(PP.LTC_FLOAT_1),n=bx(PP.LTC_FLOAT_2)):(e=bx(PP.LTC_HALF_1),n=bx(PP.LTC_HALF_2));const{colorNode:i,light:s}=this,r=t.context.lightingModel,a=uI(s),o=t.context.reflectedLight;r.directRectArea({lightColor:i,lightPosition:a,halfWidth:this.halfWidth,halfHeight:this.halfHeight,reflectedLight:o,ltc_1:e,ltc_2:n},t.stack,t)}static setLTC(t){PP=t}}class DP extends sI{static get type(){return"SpotLightNode"}constructor(t=null){super(t),this.coneCosNode=rv(0).setGroup(nv),this.penumbraCosNode=rv(0).setGroup(nv),this.cutoffDistanceNode=rv(0).setGroup(nv),this.decayExponentNode=rv(0).setGroup(nv)}update(t){super.update(t);const{light:e}=this;this.coneCosNode.value=Math.cos(e.angle),this.penumbraCosNode.value=Math.cos(e.angle*(1-e.penumbra)),this.cutoffDistanceNode.value=e.distance,this.decayExponentNode.value=e.decay}getSpotAttenuation(t){const{coneCosNode:e,penumbraCosNode:n}=this;return g_(e,n,t)}setup(t){super.setup(t);const e=t.context.lightingModel,{colorNode:n,cutoffDistanceNode:i,decayExponentNode:s,light:r}=this,a=uI(r).sub(nM),o=a.normalize(),l=o.dot(hI(r)),c=this.getSpotAttenuation(l),u=a.length(),h=rI({lightDistance:u,cutoffDistance:i,decayExponent:s}),d=n.mul(c).mul(h),p=t.context.reflectedLight;e.direct({lightDirection:o,lightColor:d,reflectedLight:p},t.stack,t)}}class OP extends DP{static get type(){return"IESSpotLightNode"}getSpotAttenuation(t){const e=this.light.iesMap;let n=null;if(e&&!0===e.isTexture){const i=t.acos().mul(1/Math.PI);n=bx(e,Lg(i,0),0).r}else n=super.getSpotAttenuation(t);return n}}class zP extends sI{static get type(){return"AmbientLightNode"}constructor(t=null){super(t)}setup({context:t}){t.irradiance.addAssign(this.colorNode)}}class VP extends sI{static get type(){return"HemisphereLightNode"}constructor(t=null){super(t),this.lightPositionNode=lI(t),this.lightDirectionNode=this.lightPositionNode.normalize(),this.groundColorNode=rv(new tr).setGroup(nv)}update(t){const{light:e}=this;super.update(t),this.lightPositionNode.object3d=e,this.groundColorNode.value.copy(e.groundColor).multiplyScalar(e.intensity)}setup(t){const{colorNode:e,groundColorNode:n,lightDirectionNode:i}=this,s=uM.dot(i).mul(.5).add(.5),r=d_(n,e,s);t.context.irradiance.addAssign(r)}}class FP extends sI{static get type(){return"LightProbeNode"}constructor(t=null){super(t);const e=[];for(let t=0;t<9;t++)e.push(new Li);this.lightProbe=NM(e)}update(t){const{light:e}=this;super.update(t);for(let t=0;t<9;t++)this.lightProbe.array[t].copy(e.sh.coefficients[t]).multiplyScalar(e.intensity)}setup(t){const e=NP(hM,this.lightProbe);t.context.irradiance.addAssign(e)}}class BP{parseFunction(){console.warn("Abstract function.")}}class kP{constructor(t,e,n="",i=""){this.type=t,this.inputs=e,this.name=n,this.precision=i}getCode(){console.warn("Abstract function.")}}kP.isNodeFunction=!0;const HP=/^\s*(highp|mediump|lowp)?\s*([a-z_0-9]+)\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)/i,GP=/[a-z_0-9]+/gi,WP="#pragma main";class jP extends kP{constructor(t){const{type:e,inputs:n,name:i,precision:s,inputsCode:r,blockCode:a,headerCode:o}=(t=>{const e=(t=t.trim()).indexOf(WP),n=-1!==e?t.slice(e+12):t,i=n.match(HP);if(null!==i&&5===i.length){const s=i[4],r=[];let a=null;for(;null!==(a=GP.exec(s));)r.push(a);const o=[];let l=0;for(;l